00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00031 class edit_media extends WebObject
00032 {
00033 function on_upload($event_args)
00034 {
00035
00036 $file = $event_args['file'];
00037
00038
00039 ereg('([^\\/]*)$', $file, $regs);
00040 $fname = $regs[1];
00041
00042 $media_path = $this->get_media_path();
00043 $file = $media_path.$fname;
00044
00045 while (!file_exists($file)) sleep(1);
00046
00047
00048 shell("svn add $file");
00049
00050
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
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
00085 set_node_status('modified');
00086 }
00087
00088 function onRender()
00089 {
00090 $media_path = $this->get_media_path();
00091
00092 WebApp::addVar('media_path', $media_path);
00093
00094
00095
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 ?>