Пример #1
0
 /**
  * Lists all files and folders for a given directory
  *
  * @return  void
  */
 public function listTask()
 {
     // Incoming directory (this should be a path built from a resource ID and its creation year/month)
     $this->view->listdir = Request::getVar('listdir', '');
     if (!$this->view->listdir) {
         echo '<p class="error">' . Lang::txt('COM_RESOURCES_ERROR_NO_LISTDIR') . '</p>';
         return;
     }
     // Incoming sub-directory
     $this->view->subdir = Request::getVar('subdir', '');
     // Build the path
     $path = Utilities::buildUploadPath($this->view->listdir, $this->view->subdir);
     $folders = array();
     $docs = array();
     if (is_dir($path)) {
         // Loop through all files and separate them into arrays of images, folders, and other
         $dirIterator = new \DirectoryIterator($path);
         foreach ($dirIterator as $file) {
             if ($file->isDot()) {
                 continue;
             }
             if ($file->isDir()) {
                 $name = $file->getFilename();
                 $folders[$path . DS . $name] = $name;
                 continue;
             }
             if ($file->isFile()) {
                 $name = $file->getFilename();
                 if ('cvs' == strtolower($name) || '.svn' == strtolower($name)) {
                     continue;
                 }
                 $docs[$path . DS . $name] = $name;
             }
         }
         ksort($folders);
         ksort($docs);
     }
     $this->view->docs = $docs;
     $this->view->folders = $folders;
     $this->view->config = $this->config;
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->display();
 }
Пример #2
0
 /**
  * Removes a resource
  * Redirects to main listing
  *
  * @return     void
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $ids = Request::getVar('id', array(0));
     // Ensure we have some IDs to work with
     if (count($ids) < 1) {
         $this->setMessage(Lang::txt('COM_RESOURCES_NO_ITEM_SELECTED'));
         return $this->cancelTask();
     }
     foreach ($ids as $id) {
         // Load resource info
         $row = new Resource($this->database);
         $row->load($id);
         // Get path and delete directories
         if ($row->path != '') {
             $listdir = $row->path;
         } else {
             // No stored path, derive from created date
             $listdir = Html::build_path($row->created, $id, '');
         }
         // Build the path
         $path = Utilities::buildUploadPath($listdir, '');
         $base = PATH_APP . '/' . trim($this->config->get('webpath', '/site/resources'), '/');
         $baseY = $base . '/' . Date::of($row->created)->format("Y");
         $baseM = $baseY . '/' . Date::of($row->created)->format("m");
         // Check if the folder even exists
         if (!is_dir($path) or !$path) {
             $this->setError(Lang::txt('COM_RESOURCES_ERROR_DIRECTORY_NOT_FOUND'));
         } else {
             if ($path == $base || $path == $baseY || $path == $baseM) {
                 $this->setError(Lang::txt('COM_RESOURCES_ERROR_DIRECTORY_NOT_FOUND'));
             } else {
                 // Attempt to delete the folder
                 if (!\Filesystem::deleteDirectory($path)) {
                     $this->setError(Lang::txt('COM_RESOURCES_ERROR_UNABLE_TO_DELETE_DIRECTORY'));
                 }
             }
         }
         // Delete associations to the resource
         $row->deleteExistence();
         // Delete the resource
         $row->delete();
     }
     $pid = Request::getInt('pid', 0);
     // Redirect
     App::redirect($this->buildRedirectURL($pid));
 }
Пример #3
0
 /**
  * Lists all files and folders for a given directory
  *
  * @return     void
  */
 public function listTask()
 {
     // Incoming directory (this should be a path built from a resource ID and its creation year/month)
     $this->view->resource = Request::getInt('resource', 0);
     if (!$this->view->resource) {
         echo '<p class="error">' . Lang::txt('COM_TOOLS_CONTRIBUTE_NO_ID') . '</p>';
         return;
     }
     /*$this->view->version = Request::getInt('version', 0);
     		if (!$this->view->version)
     		{
     			echo '<p class="error">' . Lang::txt('No tool version ID provided.') . '</p>';
     			return;
     		}*/
     // Incoming sub-directory
     $this->view->subdir = Request::getVar('subdir', '');
     // Build the path
     $row = new \Components\Resources\Tables\Resource($this->database);
     $row->load($this->view->resource);
     $path = \Components\Resources\Helpers\Html::dateToPath($row->created) . DS . \Components\Resources\Helpers\Html::niceidformat($this->view->resource);
     $path = \Components\Resources\Helpers\Utilities::buildUploadPath($path, $this->view->subdir) . DS . 'media';
     $folders = array();
     $docs = array();
     if (is_dir($path)) {
         // Loop through all files and separate them into arrays of images, folders, and other
         $dirIterator = new \DirectoryIterator($path);
         foreach ($dirIterator as $file) {
             if ($file->isDot()) {
                 continue;
             }
             if ($file->isDir()) {
                 $name = $file->getFilename();
                 $folders[$path . DS . $name] = $name;
                 continue;
             }
             if ($file->isFile()) {
                 $name = $file->getFilename();
                 if ('cvs' == strtolower($name) || '.svn' == strtolower($name)) {
                     continue;
                 }
                 $docs[$path . DS . $name] = $name;
             }
         }
         ksort($folders);
         ksort($docs);
     }
     $this->view->docs = $docs;
     $this->view->folders = $folders;
     $this->view->config = $this->config;
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->display();
 }