| 1 | <?php |
| 2 | if (empty($_REQUEST['dir'])) |
| 3 | exit; |
| 4 | |
| 5 | require_once 'diogenes.common.inc.php'; |
| 6 | require_once 'diogenes.admin.inc.php'; |
| 7 | require_once 'Barrel/Page.php'; |
| 8 | require_once 'Barrel/File.php'; |
| 9 | |
| 10 | $page = new DiogenesAdmin($_REQUEST['dir']); |
| 11 | $bbarrel =& $page->barrel; |
| 12 | |
| 13 | // retrieve all the barrel's pages |
| 14 | $fpages = $bbarrel->getPages(); |
| 15 | |
| 16 | $page->assign('post',$page->script_self()); |
| 17 | |
| 18 | // rcs handle |
| 19 | $rcs = $page->getRcs(); |
| 20 | |
| 21 | /* 5Mb limit */ |
| 22 | $maxsize=5000000; |
| 23 | |
| 24 | $action = (isset($_REQUEST["action"])) ? $_REQUEST["action"] : ""; |
| 25 | $target = isset($_REQUEST["target"]) ? $_REQUEST["target"] : ""; |
| 26 | $newname = isset($_REQUEST["newname"]) ? $_REQUEST["newname"] : ""; |
| 27 | $fileop_sfile = isset($_REQUEST['fileop_sfile']) ? $_REQUEST['fileop_sfile'] : ''; |
| 28 | $fileop_ddir = isset($_REQUEST['fileop_ddir']) ? $_REQUEST['fileop_ddir'] : ''; |
| 29 | |
| 30 | $fpage = $fpages[$_REQUEST['dir']]; |
| 31 | |
| 32 | // legacy |
| 33 | $canedit = $_SESSION['session']->hasPerms($fpage->props['wperms']); |
| 34 | $page->assign('canedit', $canedit); |
| 35 | |
| 36 | // translations |
| 37 | $page->assign('msg_import',__("Import file")); |
| 38 | $page->assign('msg_btn_fileop',__("Submit")); |
| 39 | $page->assign('msg_btn_send',__("Send")); |
| 40 | $page->assign('msg_create',__("Create an empty file")); |
| 41 | $page->assign('msg_copy_or_move', __("Copy or move a file")); |
| 42 | $page->assign('msg_btn_create',__("Create")); |
| 43 | $page->assign('msg_file',__("file")); |
| 44 | $page->assign('msg_log',__("log")); |
| 45 | $page->assign('msg_version',__("version")); |
| 46 | $page->assign('msg_date',__("date")); |
| 47 | $page->assign('msg_author',__("author")); |
| 48 | $page->assign('msg_size',__("size")); |
| 49 | $page->assign('msg_actions',__("actions")); |
| 50 | $page->assign('msg_fileop_to', __("to")); |
| 51 | // for pages |
| 52 | $page->assign('msg_location',__("location")); |
| 53 | $page->assign('msg_title',__("title")); |
| 54 | $page->assign('msg_page_template',__("page template")); |
| 55 | $page->assign('msg_status',__("status")); |
| 56 | $page->assign('msg_access',__("access")); |
| 57 | $page->assign('msg_read_perms',__("read access")); |
| 58 | $page->assign('msg_write_perms',__("write access")); |
| 59 | |
| 60 | // build navigation toolbar |
| 61 | $page->toolbar(__("Page"), $fpage->make_toolbar()); |
| 62 | |
| 63 | |
| 64 | switch ($action) { |
| 65 | case "file_create": |
| 66 | if (!$canedit) break; |
| 67 | $createfile = isset($_REQUEST['createfile']) ? $_REQUEST['createfile'] : ''; |
| 68 | if ($createfile) { |
| 69 | $page->info(__("Creating empty file") . " $createfile"); |
| 70 | if ($rcs->checkFile($fpage->props['PID'], $createfile)) { |
| 71 | $page->info(__("The specified file already exists!")); |
| 72 | } else { |
| 73 | $rcs->commit($fpage->props['PID'], $createfile, '', "empty file creation of $createfile"); |
| 74 | } |
| 75 | } |
| 76 | break; |
| 77 | |
| 78 | case "file_upload": |
| 79 | if (!$canedit) break; |
| 80 | $userfile = $_FILES['userfile']['name']; |
| 81 | if ( is_uploaded_file($_FILES['userfile']['tmp_name']) |
| 82 | && (filesize($_FILES['userfile']['tmp_name']) <= $maxsize) ) |
| 83 | { |
| 84 | $rcs->commit($fpage->props['PID'], $userfile, |
| 85 | file_get_contents($_FILES['userfile']['tmp_name']), |
| 86 | "file manager upload of $userfile" ); |
| 87 | } else { |
| 88 | $page->info(__("Error during file transfer!")); |
| 89 | } |
| 90 | break; |
| 91 | |
| 92 | case "file_delete": |
| 93 | if (!$canedit) break; |
| 94 | $page->info(__("Deleting file"). " ". $fpage->getLocation($target)); |
| 95 | $rcs->del($fpage->props['PID'],$target); |
| 96 | break; |
| 97 | |
| 98 | case "file_rename": |
| 99 | if (!$canedit) break; |
| 100 | $page->info("Renaming file '$target' to '$newname'"); |
| 101 | $rcs->move($fpage->props['PID'], $target, $fpage->props['PID'], $newname); |
| 102 | break; |
| 103 | |
| 104 | case "page_delete": |
| 105 | Diogenes_Barrel_Page::delete($bbarrel, $target, $page); |
| 106 | $fpages = $bbarrel->getPages(); |
| 107 | break; |
| 108 | |
| 109 | case "restore": |
| 110 | if (!$canedit) break; |
| 111 | $rev = $_REQUEST["rev"]; |
| 112 | $page->info("restore : $target,$rev"); |
| 113 | $path = $rcs->checkout($fpage->props['PID'],$target,$rev,System::mktemp("-d")); |
| 114 | $contents = file_get_contents($path); |
| 115 | $rcs->commit($fpage->props['PID'],$target,$contents,"restored revision $rev"); |
| 116 | break; |
| 117 | |
| 118 | case "diff": |
| 119 | $ffile = new Diogenes_Barrel_File($fpage, $target); |
| 120 | $page->assign('greeting', __("Revision differences"). " - ". $fpage->getLocation($target)); |
| 121 | $page->assign('diff',$rcs->dispDiff($fpage->props['PID'], $target, $_REQUEST["r1"],$_REQUEST["r2"])); |
| 122 | $page->toolbar(__("File"), $ffile->make_toolbar(true)); |
| 123 | $page->display('admin-revs.tpl'); |
| 124 | exit; |
| 125 | |
| 126 | case "revs": |
| 127 | $ffile = new Diogenes_Barrel_File($fpage, $target); |
| 128 | $page->assign('greeting', __("File revisions"). " - " . $fpage->getLocation($target)); |
| 129 | |
| 130 | // build urls |
| 131 | $urlPage = $page->urlSite($fpage->props['location']); |
| 132 | $urlFile = $page->urlSite($fpage->props['location'], $target); |
| 133 | |
| 134 | // parse log entries |
| 135 | $revs = $rcs->logParse($fpage->props['PID'], $target); |
| 136 | |
| 137 | // process log entries |
| 138 | $head = $revs[0]['rev']; |
| 139 | $rentries = array(); |
| 140 | |
| 141 | $sz = count($revs); |
| 142 | for ($i = 0; $i < $sz; $i++) { |
| 143 | $rev = $revs[$i]; |
| 144 | $actions = array(array(__("view"), "$urlFile?rev={$rev['rev']}")); |
| 145 | if ($target == $globals->htmlfile) { |
| 146 | array_push($actions, array(__("view page"),"$urlPage?rev={$rev['rev']}")); |
| 147 | } |
| 148 | if ($i != ($sz-1)) { |
| 149 | array_push($actions, array(__("diff to")." {$revs[$i+1]['rev']}", |
| 150 | "?action=diff&dir={$fpage->props['PID']}&target=$target&r1={$revs[$i+1]['rev']}&r2={$rev['rev']}&author={$rev['author']}")); |
| 151 | } |
| 152 | if (($i != 0) && $canedit) { |
| 153 | array_push($actions, array(__("restore"), |
| 154 | "javascript:restore('{$rev['rev']}');")); |
| 155 | } |
| 156 | array_push($rentries, array($rev['rev'],$rev['date'], |
| 157 | $rev['author'],$rev['log'], $actions)); |
| 158 | } |
| 159 | |
| 160 | $page->assign('entries', $rentries); |
| 161 | $page->toolbar(__("File"), $ffile->make_toolbar(true)); |
| 162 | $page->display('admin-revs.tpl'); |
| 163 | exit; |
| 164 | |
| 165 | case "fileop": |
| 166 | $fileop_dfile = $fileop_sfile; |
| 167 | $file_action = isset($_REQUEST['file_action']) ? $_REQUEST['file_action'] : ''; |
| 168 | $page->info("$file_action '$fileop_sfile' to '$fileop_ddir'"); |
| 169 | switch ($file_action) |
| 170 | { |
| 171 | case "file_copy": |
| 172 | $page->info("copying '$fileop_sfile' to '$fileop_ddir'"); |
| 173 | if ($rcs->checkFile($fileop_ddir, $fileop_dfile)) |
| 174 | { |
| 175 | $dfext = array_pop(explode('.', $fileop_dfile)); |
| 176 | $dfname = basename($fileop_dfile, '.'.$dfext); |
| 177 | $fileop_dfile = $dfname."_copy.$dfext"; |
| 178 | } |
| 179 | $rcs->copy($fpage->props['PID'], $fileop_sfile, $fileop_ddir, $fileop_dfile); |
| 180 | break; |
| 181 | |
| 182 | case "file_move": |
| 183 | $page->info("moving '$fileop_sfile' to '$fileop_ddir'"); |
| 184 | $rcs->move($fpage->props['PID'], $fileop_sfile, $fileop_ddir, $fileop_dfile); |
| 185 | break; |
| 186 | } |
| 187 | break; |
| 188 | |
| 189 | } |
| 190 | |
| 191 | // directory listing |
| 192 | $page->toolbar(__("Document"), $fpage->make_doc_toolbar($rcs)); |
| 193 | $pageloc = $bbarrel->getLocation($fpage->props['PID']); |
| 194 | $page->assign('greeting', __("File manager"). " - " .(strlen($pageloc) ? $pageloc : __("home"))); |
| 195 | $page->assign('maxsize',$maxsize); |
| 196 | |
| 197 | // retrieve child directories |
| 198 | foreach($fpages as $pkey => $pval) |
| 199 | { |
| 200 | if ($pval->props['parent'] == $fpage->props['PID']) |
| 201 | { |
| 202 | $arr = $pval->props; |
| 203 | $arr['actions'] = $pval->make_actions(); |
| 204 | $arr['click'] = "files?dir={$pkey}"; |
| 205 | $arr['icon'] = $globals->icons->get_icon('barrel', strlen($arr['location']) ? 'directory' : 'home'); |
| 206 | $arr['iperms'] = $globals->icons->get_icon('perm', $arr['perms']); |
| 207 | $arr['iwperms'] = $globals->icons->get_icon('perm', $arr['wperms']); |
| 208 | $page->append('childpages', $arr); |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // retrieve files in directory |
| 213 | $tfentries = $rcs->dispDir($fpage->props['PID'], $pageloc, $canedit); |
| 214 | $fentries = array(); |
| 215 | foreach ($tfentries as $fentry) |
| 216 | { |
| 217 | $tbfile = new Diogenes_Barrel_File($fpage, $fentry['file']); |
| 218 | $fentry['actions'] = $tbfile->make_actions($canedit); |
| 219 | array_push($fentries, $fentry); |
| 220 | } |
| 221 | $page->assign('childfiles', $fentries); |
| 222 | |
| 223 | |
| 224 | $page->assign('fileops', array("file_copy" => __("Copy"), "file_move" => __("Move"))); |
| 225 | $fileop_ddirs = array(); |
| 226 | foreach($fpages as $pkey => $ppage) |
| 227 | { |
| 228 | $pageloc = $bbarrel->getLocation($pkey); |
| 229 | $fileop_ddirs[$pkey] = ( strlen($pageloc) ? "<$pageloc> " : "") . $ppage->props['title']; |
| 230 | } |
| 231 | $page->assign('fileop_ddirs', $fileop_ddirs); |
| 232 | $page->display('admin-files.tpl'); |
| 233 | ?> |