edit_media.php

Go to the documentation of this file.
00001 <?php
00002   /*
00003    This file is part of DocBookWiki.  DocBookWiki is a web application
00004    that displays and edits DocBook documents.
00005 
00006    Copyright (C) 2004, 2005, 2006, 2007
00007    Dashamir Hoxha, dashohoxha@users.sourceforge.net
00008 
00009    DocBookWiki is free software; you can redistribute it and/or modify
00010    it under the  terms of the GNU General  Public License as published
00011    by the Free  Software Foundation; either version 2  of the License,
00012    or (at your option) any later version.
00013 
00014    DocBookWiki is distributed in the  hope that it will be useful, but
00015    WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
00016    MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
00017    General Public License for more details.
00018 
00019    You should have  received a copy of the  GNU General Public License
00020    along  with  DocBookWiki;  if  not,  write  to  the  Free  Software
00021    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00022    USA
00023   */
00024 
00031 class edit_media extends WebObject
00032 {
00033   function on_upload($event_args)
00034   {
00035     //get the filename of the uploaded file
00036     $file = $event_args['file'];
00037 
00038     //get the basename of the file
00039     ereg('([^\\/]*)$', $file, $regs);
00040     $fname = $regs[1];
00041 
00042     $media_path = $this->get_media_path();
00043     $file = $media_path.$fname;
00044     //wait until the file is uploaded
00045     while (!file_exists($file)) sleep(1);
00046 
00047     //add the file in the repository
00048     shell("svn add $file");
00049 
00050     //set the status of the node to modified
00051     set_node_status('modified');
00052   }
00053 
00054   function on_delete($event_args)
00055   {
00056     $media_path = $this->get_media_path();
00057     $item = $event_args['item'];
00058     $file = $media_path.$item;
00059     shell("svn delete --force $file");
00060 
00061     //set the status of the node to modified
00062     set_node_status('modified');
00063   }
00064 
00065   function on_rename($event_args)
00066   {
00067     $media_path = $this->get_media_path();
00068     $item = $event_args['item'];
00069     $new_item = $event_args['new_item'];
00070     $file = $media_path.$item;
00071     $new_file = $media_path.$new_item;
00072     $output = shell("svn status $file");
00073     if ($output[0]=='A')
00074       {
00075         shell("svn revert $file");
00076         shell("mv $file $new_file");
00077         shell("svn add $new_file");
00078       }
00079     else
00080       {
00081         $output = shell("svn move --force $file $new_file");
00082       }
00083 
00084     //set the status of the node to modified
00085     set_node_status('modified');
00086   }
00087 
00088   function onRender()
00089   {
00090     $media_path = $this->get_media_path();
00091     //add the variable {{media_path}}
00092     WebApp::addVar('media_path', $media_path);
00093 
00094     //build and add the recordset media_items
00095     //which contains the items of this section
00096     $rs = new EditableRS('media_items');
00097     if (file_exists($media_path)) $dir = opendir($media_path);
00098     if ($dir) 
00099       {
00100         while (($file=readdir($dir)) !== false)
00101           { 
00102             if ($file=='.' or $file=='..')  continue;
00103             if (ereg('\\.(xml|txt)$', $file))  continue;
00104             if (is_dir($file))  continue;
00105             
00106             $file_path = $media_path.$file;
00107             $output = shell("svn status $file_path");
00108             if ($output[0]=='?')
00109               {
00110                 shell("rm $file_path");
00111                 continue;
00112               }
00113 
00114             $rs->addRec(array('item'=>$file));
00115           }
00116         closedir($dir); 
00117       }
00118     global $webPage;
00119     $webPage->addRecordset($rs);
00120   }
00121 
00122   function get_media_path()
00123   {
00124     $book_id = WebApp::getSVar('docbook->book_id');
00125     $lng = WebApp::getSVar('docbook->lng');
00126     $node_path = WebApp::getSVar('docbook->node_path');
00127     $media_path = WS_BOOKS."$book_id/$lng/$node_path";
00128 
00129     return $media_path;
00130   }
00131 }
00132 ?>

Generated on Wed Jan 9 08:27:32 2008 for DokBookWiki by  doxygen 1.5.2