00001 <?php
00002
00015
00016
00017 import('pages.manager.ManagerHandler');
00018
00019 class FilesHandler extends ManagerHandler {
00023 function FilesHandler() {
00024 parent::ManagerHandler();
00025 }
00026
00030 function files($args) {
00031 $this->validate();
00032 $this->setupTemplate(true);
00033
00034 import('file.FileManager');
00035
00036 $templateMgr =& TemplateManager::getManager();
00037 $templateMgr->assign('pageHierarchy', array(array(Request::url(null, null, 'manager'), 'manager.conferenceSiteManagement')));
00038
00039 FilesHandler::parseDirArg($args, $currentDir, $parentDir);
00040 $currentPath = FilesHandler::getRealFilesDir($currentDir);
00041
00042 if (@is_file($currentPath)) {
00043 $fileMgr = new FileManager();
00044 if (Request::getUserVar('download')) {
00045 $fileMgr->downloadFile($currentPath);
00046 } else {
00047 $fileMgr->viewFile($currentPath, FilesHandler::fileMimeType($currentPath));
00048 }
00049
00050 } else {
00051 $files = array();
00052 if ($dh = @opendir($currentPath)) {
00053 while (($file = readdir($dh)) !== false) {
00054 if ($file != '.' && $file != '..') {
00055 $filePath = $currentPath . '/'. $file;
00056 $isDir = is_dir($filePath);
00057 $info = array(
00058 'name' => $file,
00059 'isDir' => $isDir,
00060 'mimetype' => $isDir ? '' : FilesHandler::fileMimeType($filePath),
00061 'mtime' => filemtime($filePath),
00062 'size' => $isDir ? '' : FileManager::getNiceFileSize(filesize($filePath)),
00063 );
00064 $files[$file] = $info;
00065 }
00066 }
00067 closedir($dh);
00068 }
00069 ksort($files);
00070 $templateMgr->assign_by_ref('files', $files);
00071 $templateMgr->assign('currentDir', $currentDir);
00072 $templateMgr->assign('parentDir', $parentDir);
00073 $templateMgr->assign('helpTopicId','conference.generalManagement.filesBrowser');
00074 $templateMgr->display('manager/files/index.tpl');
00075 }
00076 }
00077
00081 function fileUpload($args) {
00082 $this->validate();
00083
00084 FilesHandler::parseDirArg($args, $currentDir, $parentDir);
00085 $currentPath = FilesHandler::getRealFilesDir($currentDir);
00086
00087 import('file.FileManager');
00088 $fileMgr = new FileManager();
00089 if ($success = $fileMgr->uploadedFileExists('file')) {
00090 $destPath = $currentPath . '/' . FilesHandler::cleanFileName($fileMgr->getUploadedFileName('file'));
00091 $success = $fileMgr->uploadFile('file', $destPath);
00092 }
00093
00094 if (!$success) {
00095 $templateMgr =& TemplateManager::getManager();
00096 $this->setupTemplate(true);
00097 $templateMgr->assign('pageTitle', 'manager.filesBrowser');
00098 $templateMgr->assign('message', 'common.uploadFailed');
00099 $templateMgr->assign('backLink', Request::url(null, null, null, 'files', explode('/', $currentDir)));
00100 $templateMgr->assign('backLinkLabel', 'manager.filesBrowser');
00101 return $templateMgr->display('common/message.tpl');
00102 }
00103
00104 Request::redirect(null, null, null, 'files', explode('/', $currentDir));
00105
00106 }
00107
00111 function fileMakeDir($args) {
00112 $this->validate();
00113
00114 FilesHandler::parseDirArg($args, $currentDir, $parentDir);
00115
00116 if ($dirName = Request::getUserVar('dirName')) {
00117 $currentPath = FilesHandler::getRealFilesDir($currentDir);
00118 $newDir = $currentPath . '/' . FilesHandler::cleanFileName($dirName);
00119
00120 import('file.FileManager');
00121 $fileMgr = new FileManager();
00122 @$fileMgr->mkdir($newDir);
00123 }
00124
00125 Request::redirect(null, null, null, 'files', explode('/', $currentDir));
00126 }
00127
00128 function fileDelete($args) {
00129 $this->validate();
00130
00131 FilesHandler::parseDirArg($args, $currentDir, $parentDir);
00132 $currentPath = FilesHandler::getRealFilesDir($currentDir);
00133
00134 import('file.FileManager');
00135 $fileMgr = new FileManager();
00136
00137 if (@is_file($currentPath)) {
00138 $fileMgr->deleteFile($currentPath);
00139 } else {
00140
00141 @$fileMgr->rmdir($currentPath);
00142 }
00143
00144 Request::redirect(null, null, null, 'files', explode('/', $parentDir));
00145 }
00146
00147
00148
00149
00150
00151
00152
00153 function parseDirArg($args, &$currentDir, &$parentDir) {
00154 $pathArray = array_filter($args, array('FilesHandler', 'fileNameFilter'));
00155 $currentDir = join($pathArray, '/');
00156 array_pop($pathArray);
00157 $parentDir = join($pathArray, '/');
00158 }
00159
00160 function getRealFilesDir($currentDir) {
00161 $conference =& Request::getConference();
00162 $base = '/conferences/' . $conference->getId();
00163
00164 return Config::getVar('files', 'files_dir') . $base .'/' . $currentDir;
00165 }
00166
00167 function fileNameFilter($var) {
00168 return (!empty($var) && $var != '..' && $var != '.');
00169 }
00170
00171 function cleanFileName($var) {
00172 $var = String::regexp_replace('/[^\w\-\.]/', '', $var);
00173 if (!FilesHandler::fileNameFilter($var)) {
00174 $var = time() . '';
00175 }
00176 return $var;
00177 }
00178
00179 function fileMimeType($filePath) {
00180 return String::mime_content_type($filePath);
00181 }
00182
00183 }
00184 ?>