Example #1
0
 /**
  * Delete a contribution and associated content
  *
  * @param      integer $id Resource ID
  * @return     boolean False if errors, True on success
  */
 private function _deleteContribution($id)
 {
     // Make sure we have a record to pull
     if (!$id) {
         $this->setError(Lang::txt('COM_CONTRIBUTE_NO_ID'));
         return false;
     }
     // Load resource info
     $row = new Resource($this->database);
     $row->load($id);
     // Get the resource's children
     $helper = new Helper($id, $this->database);
     $helper->getChildren();
     $children = $helper->children;
     // Were there any children?
     if ($children) {
         // Loop through each child and delete its files and associations
         foreach ($children as $child) {
             // Skip standalone children
             if ($child->standalone == 1) {
                 continue;
             }
             // Get path and delete directories
             if ($child->path != '') {
                 $listdir = $child->path;
             } else {
                 // No stored path, derive from created date
                 $listdir = $this->_buildPathFromDate($child->created, $child->id, '');
             }
             // Build the path
             $path = $this->_buildUploadPath($listdir, '');
             $base = PATH_APP . '/' . trim($this->config->get('webpath', '/site/resources'), '/');
             $baseY = $base . '/' . Date::of($child->created)->format("Y");
             $baseM = $baseY . '/' . Date::of($child->created)->format("m");
             // Check if the folder even exists
             if (!is_dir($path) or !$path) {
                 $this->setError(Lang::txt('COM_CONTRIBUTE_DIRECTORY_NOT_FOUND'));
             } else {
                 if ($path == $base || $path == $baseY || $path == $baseM) {
                     $this->setError(Lang::txt('Invalid directory.'));
                 } else {
                     // Attempt to delete the folder
                     if (!\Filesystem::deleteDirectory($path)) {
                         $this->setError(Lang::txt('COM_CONTRIBUTE_UNABLE_TO_DELETE_DIRECTORY'));
                     }
                 }
             }
             // Delete associations to the resource
             $row->deleteExistence($child->id);
             // Delete the resource
             $row->delete($child->id);
         }
     }
     // Get path and delete directories
     if ($row->path != '') {
         $listdir = $row->path;
     } else {
         // No stored path, derive from created date
         $listdir = $this->_buildPathFromDate($row->created, $id, '');
     }
     // Build the path
     $path = $this->_buildUploadPath($listdir, '');
     // Check if the folder even exists
     if (!is_dir($path) or !$path) {
         $this->setError(Lang::txt('COM_CONTRIBUTE_DIRECTORY_NOT_FOUND'));
     } else {
         // Attempt to delete the folder
         if (!\Filesystem::deleteDirectory($path)) {
             $this->setError(Lang::txt('COM_CONTRIBUTE_UNABLE_TO_DELETE_DIRECTORY'));
         }
     }
     $row->id = $id;
     // Delete associations to the resource
     $row->deleteExistence();
     // Delete the resource
     $row->delete();
     // Return success (null)
     return true;
 }
Example #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));
 }
Example #3
0
 /**
  * Delete a file
  *
  * @return     void
  */
 public function deleteTask()
 {
     // Incoming parent ID
     $pid = Request::getInt('pid', 0);
     if (!$pid) {
         $this->setError(Lang::txt('CONTRIBUTE_NO_ID'));
         $this->displayTask($pid);
         return;
     }
     // Incoming child ID
     $id = Request::getInt('id', 0);
     if (!$id) {
         $this->setError(Lang::txt('CONTRIBUTE_NO_CHILD_ID'));
         $this->displayTask($pid);
         return;
     }
     // Load resource info
     $row = new Resource($this->database);
     $row->load($id);
     // Check for stored file
     if ($row->path != '') {
         $listdir = $row->path;
     } else {
         // No stored path, derive from created date
         $listdir = $this->_buildPathFromDate($row->created, $id, '');
     }
     // Build the path
     $path = $this->_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 (!file_exists($path) or !$path or substr($row->path, 0, strlen('http')) == 'http') {
         //$this->setError(Lang::txt('COM_CONTRIBUTE_FILE_NOT_FOUND'));
     } else {
         if ($path == $base || $path == $baseY || $path == $baseM) {
             $this->setError(Lang::txt('Invalid directory.'));
         } else {
             // Attempt to delete the folder
             if (!\Filesystem::delete($path)) {
                 $this->setError(Lang::txt('COM_CONTRIBUTE_UNABLE_TO_DELETE_FILE'));
             }
         }
     }
     if (!$this->getError()) {
         /*
         WTF? What is all this for? -- zooley 04/01/2014
         
         $uploadPath = DS . trim($this->config->get('uploadpath', '/site/resources'), DS);
         
         $year  = substr(trim($row->created), 0, 4);
         $month = substr(trim($row->created), 5, 2);
         
         $file  = basename($path);
         $path  = substr($path, 0, (strlen($path) - strlen($file)));
         $path  = str_replace(PATH_APP, '', $path);
         $path  = str_replace($uploadPath, '', $path);
         
         $bits  = explode('/', $path);
         $p = array();
         $b = '';
         $g = array_pop($bits);
         foreach ($bits as $bit)
         {
         	if ($bit == '/' || $bit == $year || $bit == $month || $bit == \Hubzero\Utility\String::pad($id))
         	{
         		$b .= ($bit != DS) ? DS . $bit : '';
         	}
         	else if ($bit != DS)
         	{
         		$p[] = $bit;
         	}
         }
         
         if (count($p) > 1)
         {
         	$p = array_reverse($p);
         	foreach ($p as $v)
         	{
         		if (!trim($v))
         		{
         			continue;
         		}
         
         		$npath = PATH_APP . $uploadPath . $b . DS . $v;
         
         		// Check if the folder even exists
         		if (!is_dir($npath)
         		 or !$npath
         		 or rtrim($npath, '/') == $base
         		 or rtrim($npath, '/') == $baseY
         		 or rtrim($npath, '/') == $baseM)
         		{
         			$this->setError(Lang::txt('COM_CONTRIBUTE_DIRECTORY_NOT_FOUND'));
         		}
         		else
         		{
         			// Attempt to delete the folder
         			if (!Filesystem::deleteDirectory($npath))
         			{
         				$this->setError(Lang::txt('COM_CONTRIBUTE_UNABLE_TO_DELETE_DIRECTORY'));
         			}
         		}
         	}
         }
         */
         // Delete associations to the resource
         $row->deleteExistence();
         // Delete resource
         $row->delete();
     }
     // Push through to the attachments view
     $this->displayTask($pid);
 }