Exemplo n.º 1
0
 /**
  * Clear all Cache
  *
  * @museDescription  Clears all cached items in document root cache directory
  *
  * @return  void
  */
 public function clear()
 {
     // Path to cache folder
     $cacheDir = PATH_APP . DS . 'cache' . DS . '*';
     // Remove recursively
     foreach (glob($cacheDir) as $cacheFileOrDir) {
         $readable = str_replace(PATH_APP . DS, '', $cacheFileOrDir);
         if (is_dir($cacheFileOrDir)) {
             if (!Filesystem::deleteDirectory($cacheFileOrDir)) {
                 $this->output->addLine('Unable to delete cache directory: ' . $readable, 'error');
             } else {
                 $this->output->addLine($readable . ' deleted', 'success');
             }
         } else {
             // Don't delete index.html
             if ($cacheFileOrDir != PATH_APP . DS . 'cache' . DS . 'index.html') {
                 if (!Filesystem::delete($cacheFileOrDir)) {
                     $this->output->addLine('Unable to delete cache file: ' . $readable, 'error');
                 } else {
                     $this->output->addLine($readable . ' deleted', 'success');
                 }
             }
         }
     }
     $this->output->addLine('Clear cache complete', 'success');
 }
Exemplo n.º 2
0
 /**
  * Run composer post-install script
  * 
  * @param  Event  $event
  * @return void
  */
 public static function postInstall(Event $event)
 {
     static::init();
     $event->getIO()->write('<info>Writing resources.lock file</info>');
     $installed = json_decode(file_get_contents(static::$vendorPath . '/composer/installed.json'));
     $data = [];
     $finder = (new Finder())->directories()->ignoreVCS(true)->in(static::$resourcesPath . '/packages');
     foreach ($installed as $package) {
         if (!property_exists($package, 'extra')) {
             continue;
         }
         $extra = $package->extra;
         if (!property_exists($extra, 'resources')) {
             continue;
         }
         $resources = $extra->resources;
         foreach ($resources as $resource => $namespaces) {
             foreach ($namespaces as $namespace => $path) {
                 $finder->exclude($namespace);
                 $data[$resource][$namespace] = $path;
             }
         }
     }
     // We turn the iterator to an array to
     // prevent an exception when we delete the directorys
     foreach (iterator_to_array($finder) as $file) {
         \Filesystem::deleteDirectory($file->getPathname());
     }
     file_put_contents(static::$resourcesPath . '/resources.lock', json_encode($data, JSON_PRETTY_PRINT));
 }
 /**
  * Execute the console command.
  *
  * @param ManagerRegistry $registry
  */
 public function fire()
 {
     $cachePath = config('jms.cache');
     if (count($filesystem->allFiles($cachePath))) {
         \Filesystem::deleteDirectory($cachePath);
         $this->info('JMS cache cleared!');
     }
 }
Exemplo n.º 4
0
 /**
  * Method to delete tmp folder
  *
  * @return	boolean   true if delete successful, false otherwise
  * @since	2.5
  */
 public function cleanup()
 {
     // Clear installation messages
     User::setState('com_installer.message', '');
     User::setState('com_installer.extension_message', '');
     // Delete temporary directory
     return Filesystem::deleteDirectory($this->getState('to_path'));
 }
Exemplo n.º 5
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));
 }
Exemplo n.º 6
0
 /**
  * Prep file directory (provisioned project)
  *
  * @param      boolean		$force
  *
  * @return     boolean
  */
 protected function _prepDir($force = true)
 {
     if (!$this->model->exists()) {
         $this->setError(Lang::txt('UNABLE_TO_CREATE_UPLOAD_PATH'));
         return;
     }
     // Get member files path
     $memberPath = $this->_getMemberPath();
     // Create and initialize local repo
     if (!$this->model->repo()->iniLocal()) {
         $this->setError(Lang::txt('UNABLE_TO_CREATE_UPLOAD_PATH'));
         return;
     }
     // Copy files from member directory
     if (!Filesystem::copyDirectory($memberPath, $this->model->repo()->get('path'))) {
         $this->setError(Lang::txt('COM_PROJECTS_FAILED_TO_COPY_FILES'));
         return false;
     }
     // Read copied files
     $get = Filesystem::files($this->model->repo()->get('path'));
     $num = count($get);
     $checkedin = 0;
     // Check-in copied files
     if ($get) {
         foreach ($get as $file) {
             $file = str_replace($this->model->repo()->get('path') . DS, '', $file);
             if (is_file($this->model->repo()->get('path') . DS . $file)) {
                 // Checkin into repo
                 $this->model->repo()->call('checkin', array('file' => $this->model->repo()->getMetadata($file, 'file', array())));
                 $checkedin++;
             }
         }
     }
     if ($num == $checkedin) {
         // Clean up member files
         Filesystem::deleteDirectory($memberPath);
         return true;
     }
     return false;
 }
Exemplo n.º 7
0
 /**
  * Delete all records based on ticket number
  *
  * @param   integer  $ticket  Ticket ID
  * @return  boolean  True on success
  */
 public function deleteAllForTicket($ticket)
 {
     $this->_db->setQuery("DELETE FROM {$this->_tbl} WHERE ticket=" . $this->_db->quote($ticket));
     if (!$this->_db->query()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     $config = Component::params('com_support');
     $path = PATH_APP . DS . trim($config->get('webpath', '/site/tickets'), DS) . DS . $ticket;
     if (is_dir($path)) {
         if (!\Filesystem::deleteDirectory($path)) {
             $this->setError(Lang::txt('Unable to delete path'));
             return false;
         }
     }
     return true;
 }
Exemplo n.º 8
0
 /**
  * Activate provisioned project
  *
  * @return     void
  */
 public function activateTask()
 {
     // Cannot proceed without project id/alias
     if (!$this->model->exists()) {
         throw new Exception(Lang::txt('COM_PROJECTS_PROJECT_NOT_FOUND'), 404);
         return;
     }
     // Must be project creator
     if (!$this->model->access('owner')) {
         throw new Exception(Lang::txt('ALERTNOTAUTH'), 403);
         return;
     }
     // Must be a provisioned project to be activated
     if (!$this->model->isProvisioned()) {
         // Redirect to project page
         App::redirect(Route::url($this->model->link()));
         return;
     }
     // Redirect to setup if activation not complete
     if ($this->model->inSetup()) {
         App::redirect(Route::url($this->model->link('setup')));
         return;
     }
     // Get publication of a provisioned project
     $pub = $this->model->getPublication();
     if (empty($pub)) {
         throw new Exception(Lang::txt('COM_PROJECTS_PROJECT_NOT_FOUND'), 404);
         return;
     }
     // Incoming
     $name = trim(Request::getVar('new-alias', '', 'post'));
     $title = trim(Request::getVar('title', '', 'post'));
     $confirm = trim(Request::getInt('confirm', 0, 'post'));
     $name = preg_replace('/ /', '', $name);
     $name = strtolower($name);
     // Check incoming data
     $verified = $this->model->check($name, $this->model->get('id'));
     if ($confirm && !$verified) {
         $error = $this->model->getError() ? $this->model->getError() : Lang::txt('COM_PROJECTS_ERROR_NAME_INVALID_OR_EMPTY');
         $this->setError($error);
     } elseif ($confirm && ($title == '' || strlen($title) < 3)) {
         $this->setError(Lang::txt('COM_PROJECTS_ERROR_TITLE_SHORT_OR_EMPTY'));
     }
     // Set the pathway
     $this->_buildPathway();
     // Set the page title
     $this->_buildTitle();
     // Display page
     if (!$confirm || $this->getError()) {
         $this->view->setLayout('provisioned');
         $this->view->model = $this->model;
         $this->view->team = $this->model->_tblOwner->getOwnerNames($this->model->get('alias'));
         // Output HTML
         $this->view->pub = isset($pub) ? $pub : '';
         $this->view->suggested = $name;
         $this->view->verified = $verified;
         $this->view->suggested = $verified ? $this->view->suggested : '';
         $this->view->title = $this->title;
         $this->view->active = $this->active;
         $this->view->task = $this->_task;
         $this->view->authorized = 1;
         $this->view->option = $this->_option;
         $this->view->msg = $this->_getNotifications('success');
         if ($this->getError()) {
             $this->view->setError($this->getError());
         }
         $this->view->display();
         return;
     }
     // Save new alias & title
     if (!$this->getError()) {
         $this->model->set('title', \Hubzero\Utility\String::truncate($title, 250));
         $this->model->set('alias', $name);
         $state = $this->_setupComplete == 3 ? 0 : 1;
         $this->model->set('state', $state);
         $this->model->set('setup_stage', 2);
         $this->model->set('provisioned', 0);
         $this->model->set('modified', Date::toSql());
         $this->model->set('modified_by', User::get('id'));
         // Save changes
         if (!$this->model->store()) {
             $this->setError($this->model->getError());
         }
     }
     // Get project parent directory
     $path = Helpers\Html::getProjectRepoPath($this->model->get('alias'));
     $newpath = Helpers\Html::getProjectRepoPath($name, 'files', true);
     // Rename project parent directory
     if ($path && is_dir($path)) {
         if (!Filesystem::copyDirectory($path, $newpath)) {
             $this->setError(Lang::txt('COM_PROJECTS_FAILED_TO_COPY_FILES'));
         } else {
             // Correct permissions to 0755
             Filesystem::setPermissions($newpath);
             // Delete original repo
             Filesystem::deleteDirectory($path);
         }
     }
     // Log activity
     $this->_logActivity($this->model->get('id'), 'provisioned', 'activate', 'save', 1);
     // Send to continue setup
     App::redirect(Route::url($this->model->link('setup')));
     return;
 }
Exemplo n.º 9
0
 /**
  * Delete dir
  *
  * @param      array	$params
  *
  * @return     array
  */
 public function deleteDirectory($params = array())
 {
     $file = isset($params['file']) ? $params['file'] : NULL;
     $author = isset($params['author']) ? $params['author'] : NULL;
     $date = isset($params['date']) ? $params['date'] : NULL;
     if (!$file instanceof Models\File || $file->get('type') != 'folder') {
         return false;
     }
     // Delete from Git
     $this->_git->gitDelete($file->get('localPath'), 'folder', $commitMsg);
     $this->_git->gitCommit($commitMsg, $author, $date);
     if (!$this->get('remote') && file_exists($file->get('fullPath'))) {
         // Remove directory that is not in Git
         if (!Filesystem::deleteDirectory($file->get('fullPath'))) {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 10
0
 /**
  * Save Child Resources
  *
  * @return void
  */
 private function _saveChildData()
 {
     // if we updating we want to completely replace
     if ($this->_mode == 'UPDATE' && isset($this->record->resource->id)) {
         // remove any existing files
         $children = $this->record->resource->getItemChildren(array('parent_id' => $this->record->resource->id));
         foreach ($children as $child) {
             $rconfig = \Component::params('com_resources');
             $base = PATH_APP . DS . trim($rconfig->get('uploadpath', '/site/resources'), DS);
             $file = $base . DS . $child->path;
             //get file info
             $info = pathinfo($file);
             $directory = $info['dirname'];
             if ($child->type == 13 && file_exists($file)) {
                 \Filesystem::delete($file);
             }
             if (is_dir($directory)) {
                 // get iterator on direcotry
                 $iterator = new \FilesystemIterator($directory);
                 $isDirEmpty = !$iterator->valid();
                 // remove directory if empty
                 if ($isDirEmpty) {
                     \Filesystem::deleteDirectory($directory);
                 }
             }
         }
         // delete all child resources
         $sql = "DELETE FROM `#__resources` WHERE `id` IN (\n\t\t\t\t\t\tSELECT child_id FROM `#__resource_assoc` WHERE `parent_id`=" . $this->_database->quote($this->record->resource->id) . ")";
         $this->_database->setQuery($sql);
         $this->_database->query();
         // delete all child resource associations
         $sql = "DELETE FROM `#__resource_assoc` WHERE `parent_id`=" . $this->_database->quote($this->record->resource->id);
         $this->_database->setQuery($sql);
         $this->_database->query();
     }
     // loop through each child
     foreach ($this->record->children as $child) {
         // save child
         if (!$child->store()) {
             throw new Exception(Lang::txt('COM_RESOURCES_IMPORT_RECORD_MODEL_UNABLE_SAVECHILD'));
         }
         // create parent - child association
         $assoc = new Tables\Assoc($this->_database);
         $assoc->ordering = $assoc->getLastOrder($this->record->resource->id);
         $assoc->ordering = $assoc->ordering ? $assoc->ordering : 0;
         $assoc->ordering++;
         $assoc->parent_id = $this->record->resource->id;
         $assoc->child_id = $child->id;
         $assoc->grouping = 0;
         if (!$assoc->store(true)) {
             throw new Exception(Lang::txt('COM_RESOURCES_IMPORT_RECORD_MODEL_UNABLE_SAVECHILDASSOC'));
         }
     }
 }
Exemplo n.º 11
0
 /**
  * Delete a folder and contents
  *
  * @return  void
  */
 public function deletefolderTask()
 {
     // Check for request forgeries
     Request::checkToken('get');
     // Incoming directory (this should be a path built from a resource ID and its creation year/month)
     $listdir = Request::getVar('listdir', '');
     if (!$listdir) {
         $this->setError(Lang::txt('COM_RESOURCES_ERROR_NO_LISTDIR'));
         $this->displayTask();
         return;
     }
     // Make sure the listdir follows YYYY/MM/#
     $parts = explode('/', $listdir);
     if (count($parts) < 3) {
         $this->setError(Lang::txt('COM_RESOURCES_ERROR_DIRECTORY_NOT_FOUND'));
         $this->displayTask();
         return;
     }
     // Incoming sub-directory
     $subdir = Request::getVar('subdir', '');
     // Build the path
     $path = Utilities::buildUploadPath($listdir, $subdir);
     // Incoming directory to delete
     $folder = Request::getVar('delFolder', '');
     if (!$folder) {
         $this->setError(Lang::txt('COM_RESOURCES_ERROR_NO_DIRECTORY'));
         $this->displayTask();
         return;
     }
     $folder = Utilities::normalizePath($folder);
     // Check if the folder even exists
     if (!is_dir($path . $folder) or !$folder) {
         $this->setError(Lang::txt('COM_RESOURCES_ERROR_DIRECTORY_NOT_FOUND'));
     } else {
         // Attempt to delete the file
         if (!\Filesystem::deleteDirectory($path . $folder)) {
             $this->setError(Lang::txt('COM_RESOURCES_ERROR_UNABLE_TO_DELETE_DIRECTORY'));
         }
     }
     // Push through to the media view
     $this->displayTask();
 }
Exemplo n.º 12
0
 /**
  * Add files to repo from extracted archive
  *
  * @return  boolean
  */
 protected function _addFromExtracted($extractPath, $zipName, $target, $params, &$available)
 {
     $reserved = isset($params['reserved']) ? $params['reserved'] : array();
     $dirPath = isset($params['subdir']) ? $params['subdir'] : NULL;
     $extracted = Filesystem::files($extractPath, '.', true, true, $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'));
     // check for viruses - scans the directory for efficency
     $command = "clamscan -i --no-summary --block-encrypted -r " . $extractPath;
     exec($command, $output, $virus_status);
     $virusChecked = FALSE;
     if ($virus_status == 0) {
         $virusChecked = TRUE;
     } else {
         Filesystem::deleteDirectory($extractPath);
         $this->setError('The antivirus software has rejected your files.');
         return false;
     }
     $z = 0;
     foreach ($extracted as $e) {
         $fileinfo = pathinfo($e);
         $a_dir = $fileinfo['dirname'];
         $a_dir = str_replace($extractPath . DS, '', $a_dir);
         // Skip certain system files
         if (preg_match("/__MACOSX/", $e) or preg_match("/.DS_Store/", $e)) {
             continue;
         }
         $file = $fileinfo['basename'];
         $size = filesize($e);
         // Run some checks, stop in case of a problem
         if (!$this->_check($file, $e, $size, $available, $virusChecked)) {
             return false;
         }
         // Clean up filename
         $safe_dir = $a_dir && $a_dir != '.' ? Filesystem::cleanPath($a_dir) : '';
         $safe_dir = trim($safe_dir, DS);
         $safe_file = Filesystem::clean($file);
         // Strips out temporary path
         if (strpos($safe_dir, 'tmp/') !== FALSE) {
             $parts = explode('/', $safe_dir);
             $safe_dir = str_replace($parts[0] . '/', '', $safe_dir);
             $safe_dir = str_replace($parts[1] . '/', '', $safe_dir);
         }
         $skipDir = false;
         if (is_array($reserved) && $safe_dir && in_array(strtolower($safe_dir), $reserved)) {
             $skipDir = true;
         }
         $safeName = $safe_dir && !$skipDir ? $safe_dir . DS . $safe_file : $safe_file;
         $localPath = $dirPath ? $dirPath . DS . $safeName : $safeName;
         $where = $target . DS . $safeName;
         $exists = is_file($where) ? true : false;
         // Provision directory
         if ($safe_dir && !$skipDir && !is_dir($target . DS . $safe_dir)) {
             if (Filesystem::makeDirectory($target . DS . $safe_dir, 0755, true, true)) {
                 // File object
                 $localDirPath = $dirPath ? $dirPath . DS . $safe_dir : $safe_dir;
                 $fileObject = new Models\File(trim($localDirPath), $this->get('path'));
                 $fileObject->set('type', 'folder');
                 $params['file'] = $fileObject;
                 $params['replace'] = false;
                 // Success - check in change
                 $this->call('checkin', $params);
                 $z++;
             }
         }
         // Strips out temporary path
         if (strpos($safeName, 'tmp/') !== FALSE) {
             $parts = explode('/', $safeName);
             $safeName = str_replace($parts[0] . '/', '', $safeName);
             $safeName = str_replace($parts[1] . '/', '', $safeName);
         }
         // Copy file into project
         if (Filesystem::copy($e, $target . DS . $safeName)) {
             // File object
             $fileObject = new Models\File(trim($localPath), $this->get('path'));
             $params['file'] = $fileObject;
             $params['replace'] = $exists;
             // Success - check in change
             $this->call('checkin', $params);
             $z++;
         }
     }
     return $z;
 }
Exemplo n.º 13
0
 /**
  * Delete a record
  *
  * @return  boolean True on success, false on error
  */
 public function delete()
 {
     // Remove authors
     foreach ($this->authors() as $author) {
         if (!$author->delete()) {
             $this->setError($author->getError());
             return false;
         }
     }
     // Remove comments
     foreach ($this->comments() as $comment) {
         if (!$comment->delete()) {
             $this->setError($comment->getError());
             return false;
         }
     }
     // Remove revisions
     foreach ($this->revisions() as $revision) {
         if (!$revision->delete()) {
             $this->setError($revision->getError());
             return false;
         }
     }
     // Remove tags
     $this->tag('');
     // Remove files
     $path = PATH_APP . DS . trim($this->config('filepath', '/site/wiki'), DS);
     if (is_dir($path . DS . $this->get('id'))) {
         if (!\Filesystem::deleteDirectory($path . DS . $this->get('id'))) {
             $this->setError(Lang::txt('COM_WIKI_UNABLE_TO_DELETE_FOLDER'));
         }
     }
     // Remove record from the database
     if (!$this->_tbl->delete()) {
         $this->setError($this->_tbl->getError());
         return false;
     }
     $this->log('page_deleted');
     // Clear cached data
     \Cache::clean('wiki');
     // Hey, no errors!
     return true;
 }
Exemplo n.º 14
0
 /**
  * Deletes assoc with pub version
  *
  * @param   integer  $vid
  * @param   integer  $pid
  * @return  void
  */
 public function deleteVersionExistence($vid, $pid)
 {
     // Delete authors
     $pa = new Tables\Author($this->database);
     $authors = $pa->deleteAssociations($vid);
     // Delete attachments
     $pContent = new Tables\Attachment($this->database);
     $pContent->deleteAttachments($vid);
     // Delete screenshots
     $pScreenshot = new Tables\Screenshot($this->database);
     $pScreenshot->deleteScreenshots($vid);
     // Delete access accosiations
     $pAccess = new Tables\Access($this->database);
     $pAccess->deleteGroups($vid);
     // Delete audience
     $pAudience = new Tables\Audience($this->database);
     $pAudience->deleteAudience($vid);
     // Build publication path
     $path = Helpers\Html::buildPubPath($pid, $vid, $this->config->get('webpath'), '', 1);
     // Delete all files
     if (is_dir($path)) {
         Filesystem::deleteDirectory($path);
     }
     return true;
 }
Exemplo n.º 15
0
 /**
  * Deletes paths from the current path
  *
  * @since 1.5
  */
 public function delete()
 {
     Session::checkToken(['get', 'post']);
     // Get some data from the request
     $tmpl = Request::getCmd('tmpl');
     $paths = Request::getVar('rm', array(), '', 'array');
     $folder = Request::getVar('folder', '', '', 'path');
     $redirect = 'index.php?option=com_media&folder=' . $folder;
     if ($tmpl == 'component') {
         // We are inside the iframe
         $redirect .= '&view=mediaList&tmpl=component';
     }
     $this->setRedirect($redirect);
     // Nothing to delete
     if (empty($paths)) {
         return true;
     }
     // Authorize the user
     if (!$this->authoriseUser('delete')) {
         return false;
     }
     // Set FTP credentials, if given
     JClientHelper::setCredentialsFromRequest('ftp');
     // Initialise variables.
     $ret = true;
     foreach ($paths as $path) {
         if ($path !== Filesystem::clean($path)) {
             // filename is not safe
             $filename = htmlspecialchars($path, ENT_COMPAT, 'UTF-8');
             Notify::warning(Lang::txt('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FILE_WARNFILENAME', substr($filename, strlen(COM_MEDIA_BASE))));
             continue;
         }
         $fullPath = Filesystem::cleanPath(implode(DIRECTORY_SEPARATOR, array(COM_MEDIA_BASE, $folder, $path)));
         $object_file = new \Hubzero\Base\Object(array('filepath' => $fullPath));
         if (is_file($fullPath)) {
             // Trigger the onContentBeforeDelete event.
             $result = Event::trigger('content.onContentBeforeDelete', array('com_media.file', &$object_file));
             if (in_array(false, $result, true)) {
                 // There are some errors in the plugins
                 Notify::warning(Lang::txts('COM_MEDIA_ERROR_BEFORE_DELETE', count($errors = $object_file->getErrors()), implode('<br />', $errors)));
                 continue;
             }
             $ret &= Filesystem::delete($fullPath);
             // Trigger the onContentAfterDelete event.
             Event::trigger('content.onContentAfterDelete', array('com_media.file', &$object_file));
             $this->setMessage(Lang::txt('COM_MEDIA_DELETE_COMPLETE', substr($fullPath, strlen(COM_MEDIA_BASE))));
         } elseif (is_dir($fullPath)) {
             $contents = Filesystem::files($fullPath, '.', true, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'index.html'));
             if (empty($contents)) {
                 // Trigger the onContentBeforeDelete event.
                 $result = Event::trigger('content.onContentBeforeDelete', array('com_media.folder', &$object_file));
                 if (in_array(false, $result, true)) {
                     // There are some errors in the plugins
                     Notify::warning(Lang::txts('COM_MEDIA_ERROR_BEFORE_DELETE', count($errors = $object_file->getErrors()), implode('<br />', $errors)));
                     continue;
                 }
                 $ret &= Filesystem::deleteDirectory($fullPath);
                 // Trigger the onContentAfterDelete event.
                 Event::trigger('content.onContentAfterDelete', array('com_media.folder', &$object_file));
                 $this->setMessage(Lang::txt('COM_MEDIA_DELETE_COMPLETE', substr($fullPath, strlen(COM_MEDIA_BASE))));
             } else {
                 // This makes no sense...
                 Notify::warning(Lang::txt('COM_MEDIA_ERROR_UNABLE_TO_DELETE_FOLDER_NOT_EMPTY', substr($fullPath, strlen(COM_MEDIA_BASE))));
             }
         }
     }
     return $ret;
 }
Exemplo n.º 16
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;
 }
Exemplo n.º 17
0
 /**
  * Check if all the chunks exist, and combine them into a final file
  *
  * @param   string  $temp_dir     The temporary directory holding all the parts of the file
  * @param   string  $fileName     The original file name
  * @param   string  $chunkSize    Each chunk size (in bytes)
  * @param   string  $totalSize    Original file size (in bytes)
  * @param   int     $total_files  The total number of chunks for this file
  * @param   int     $expand       Whether to automatically expand zip,tar,gz files
  *
  * @return  array
  */
 public function createFileFromChunks($temp_dir, $fileName, $chunkSize, $totalSize, $total_files, $expand)
 {
     // Count all the parts of this file
     $total_files_on_server_size = 0;
     $temp_total = 0;
     $results = [];
     foreach (scandir($temp_dir) as $file) {
         $temp_total = $total_files_on_server_size;
         $tempfilesize = filesize($temp_dir . DS . $file);
         $total_files_on_server_size = $temp_total + $tempfilesize;
     }
     // Check that all the parts are present
     // If the Size of all the chunks on the server is equal to the size of the file uploaded.
     if ($total_files_on_server_size >= $totalSize) {
         // Create a temporary file to combine all the chunks into
         $fp = tmpfile();
         for ($i = 1; $i <= $total_files; $i++) {
             fwrite($fp, file_get_contents($temp_dir . DS . $fileName . '.part' . $i));
             unlink($temp_dir . DS . $fileName . '.part' . $i);
         }
         fseek($fp, 0);
         $path = trim($this->subdir, DS) . DS . $fileName;
         // Final destination file
         $file = Entity::fromPath($path, $this->connection->adapter());
         $file->contents = $fp;
         $file->size = $totalSize;
         if ($file->save()) {
             $results['uploaded'][] = $file->getPath();
             if ($file->isExpandable() && $expand) {
                 if ($file->expand()) {
                     // Delete the archive itself
                     $file->delete();
                 }
             }
         } else {
             $results['failed'][] = $file->getPath();
         }
         if (is_resource($file)) {
             // Some (3rd party) adapters close the stream internally.
             fclose($file);
         }
         // Rename the temporary directory (to avoid access from other
         // Concurrent chunks uploads) and then delete it
         if (rename($temp_dir, $temp_dir . '_UNUSED')) {
             Filesystem::deleteDirectory($temp_dir . '_UNUSED');
         } else {
             Filesystem::deleteDirectory($temp_dir);
         }
     }
     return $results;
 }
Exemplo n.º 18
0
 /**
  * Delete a certificate
  * 
  * @return  boolean True on success, false on error
  */
 public function delete()
 {
     // Remove files
     $path = $this->path('system');
     if (is_dir($path)) {
         // Attempt to delete the file
         if (!\Filesystem::deleteDirectory($path)) {
             $this->setError(Lang::txt('Unable to remove upload directory and files for certificate.'));
             return false;
         }
     }
     // Remove this record from the database and log the event
     return parent::delete();
 }
Exemplo n.º 19
0
 /**
  * Create method for this handler
  *
  * @return array of assets created
  **/
 public function create()
 {
     // Include needed files
     require_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'asset.association.php';
     require_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'asset.php';
     require_once dirname(__DIR__) . DS . 'asset.php';
     // Get the file
     if (isset($_FILES['files'])) {
         $file = $_FILES['files']['name'][0];
         $size = (int) $_FILES['files']['size'];
         // Get the file extension
         $pathinfo = pathinfo($file);
         $filename = $pathinfo['filename'];
         $ext = $pathinfo['extension'];
     } else {
         return array('error' => 'No files provided');
     }
     // @FIXME: should these come from the global settings, or should they be courses specific
     // Get config
     $config = Component::params('com_media');
     // Max upload size
     $sizeLimit = (int) $config->get('upload_maxsize');
     $sizeLimit = $sizeLimit * 1024 * 1024;
     // Check to make sure we have a file and its not too big
     if ($size == 0) {
         return array('error' => 'File is empty');
     }
     if ($size > $sizeLimit) {
         $max = preg_replace('/<abbr \\w+=\\"\\w+\\">(\\w{1,3})<\\/abbr>/', '$1', \Hubzero\Utility\Number::formatBytes($sizeLimit));
         return array('error' => "File is too large. Max file upload size is {$max}");
     }
     // Create our asset table object
     $assetObj = new Tables\Asset($this->db);
     $this->asset['title'] = $filename;
     $this->asset['type'] = !empty($this->asset['type']) ? $this->asset['type'] : 'file';
     $this->asset['subtype'] = !empty($this->asset['subtype']) ? $this->asset['subtype'] : 'file';
     $this->asset['url'] = $file;
     $this->asset['created'] = Date::toSql();
     $this->asset['created_by'] = App::get('authn')['user_id'];
     $this->asset['course_id'] = Request::getInt('course_id', 0);
     // Save the asset
     if (!$assetObj->save($this->asset)) {
         return array('error' => 'Asset save failed');
     }
     // Create asset assoc object
     $assocObj = new Tables\AssetAssociation($this->db);
     $this->assoc['asset_id'] = $assetObj->get('id');
     $this->assoc['scope'] = Request::getCmd('scope', 'asset_group');
     $this->assoc['scope_id'] = Request::getInt('scope_id', 0);
     // Save the asset association
     if (!$assocObj->save($this->assoc)) {
         return array('error' => 'Asset association save failed');
     }
     // Get courses config
     $cconfig = Component::params('com_courses');
     // Build the upload path if it doesn't exist
     $uploadDirectory = PATH_APP . DS . trim($cconfig->get('uploadpath', '/site/courses'), DS) . DS . $this->asset['course_id'] . DS . $this->assoc['asset_id'] . DS;
     // Make sure upload directory exists and is writable
     if (!is_dir($uploadDirectory)) {
         if (!Filesystem::makeDirectory($uploadDirectory, 0755, true)) {
             return array('error' => 'Server error. Unable to create upload directory');
         }
     }
     if (!is_writable($uploadDirectory)) {
         return array('error' => 'Server error. Upload directory isn\'t writable');
     }
     // Get the final file path
     $target_path = $uploadDirectory . $filename . '.' . $ext;
     // Move the file to the site folder
     set_time_limit(60);
     // Scan for viruses
     if (!Filesystem::isSafe($_FILES['files']['tmp_name'][0])) {
         // Scan failed, delete asset and association and return an error
         $assetObj->delete();
         $assocObj->delete();
         Filesystem::deleteDirectory($uploadDirectory);
         return array('error' => 'File rejected because the anti-virus scan failed.');
     }
     if (!($move = move_uploaded_file($_FILES['files']['tmp_name'][0], $target_path))) {
         // Move failed, delete asset and association and return an error
         $assetObj->delete();
         $assocObj->delete();
         Filesystem::deleteDirectory($uploadDirectory);
         return array('error' => 'Move file failed');
     }
     // Get the url to return to the page
     $course_id = Request::getInt('course_id', 0);
     $offering_alias = Request::getCmd('offering', '');
     $course = new \Components\Courses\Models\Course($course_id);
     $url = Route::url('index.php?option=com_courses&controller=offering&gid=' . $course->get('alias') . '&offering=' . $offering_alias . '&asset=' . $assetObj->get('id'));
     $url = rtrim(str_replace('/api', '', Request::root()), '/') . '/' . ltrim($url, '/');
     $return_info = array('asset_id' => $this->assoc['asset_id'], 'asset_title' => $this->asset['title'], 'asset_type' => $this->asset['type'], 'asset_subtype' => $this->asset['subtype'], 'asset_url' => $url, 'course_id' => $this->asset['course_id'], 'offering_alias' => Request::getCmd('offering', ''), 'scope_id' => $this->assoc['scope_id'], 'asset_ext' => $ext, 'upload_path' => $uploadDirectory, 'target_path' => $target_path);
     // Return info
     return array('assets' => $return_info);
 }
Exemplo n.º 20
0
 /**
  * Delete a file
  *
  * @return  void
  */
 public function deleteTask()
 {
     // Check for request forgeries
     Request::checkToken('get');
     // Incoming member ID
     $id = Request::getInt('id', 0);
     if (!$id) {
         $this->setError(Lang::txt('COM_STORE_FEEDBACK_NO_ID'));
         $this->displayTask($id);
         return;
     }
     // Incoming picture
     $picture = Request::getVar('current', '');
     // Build the file path
     $path = PATH_APP . DS . trim($this->config->get('webpath', '/site/store'), DS) . DS . $id;
     // Attempt to delete the file
     if (!\Filesystem::deleteDirectory($path)) {
         $this->setError(Lang::txt('COM_STORE_UNABLE_TO_DELETE_FILE'));
         $this->displayTask($id);
         return;
     }
     // Push through to the image view
     $this->displayTask($id);
 }
Exemplo n.º 21
0
 /**
  * Erases all project information (to be used for test projects only)
  *
  * @return  void
  */
 public function eraseTask()
 {
     $id = Request::getVar('id', 0);
     $permanent = 1;
     // Initiate extended database class
     $obj = new Tables\Project($this->database);
     if (!$id or !$obj->loadProject($id)) {
         App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('COM_PROJECTS_NOTICE_ID_NOT_FOUND'), 'error');
         return;
     }
     // Get project group
     $group_prefix = $this->config->get('group_prefix', 'pr-');
     $prGroup = $group_prefix . $obj->alias;
     // Store project info
     $alias = $obj->alias;
     $identifier = $alias;
     // Delete project
     $obj->delete();
     // Erase all owners
     $objO = new Tables\Owner($this->database);
     $objO->removeOwners($id, '', 0, $permanent, '', $all = 1);
     // Erase owner group
     $group = new \Hubzero\User\Group();
     $group->read($prGroup);
     if ($group) {
         $group->delete();
     }
     // Erase all comments
     $objC = new Tables\Comment($this->database);
     $objC->deleteProjectComments($id, $permanent);
     // Erase all activities
     $objA = new Tables\Activity($this->database);
     $objA->deleteActivities($id, $permanent);
     // Erase all todos
     $objTD = new Tables\Todo($this->database);
     $objTD->deleteTodos($id, '', $permanent);
     // Erase all blog entries
     $objB = new Tables\Blog($this->database);
     $objB->deletePosts($id, $permanent);
     // Erase all notes
     if (file_exists(PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'page.php')) {
         include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'page.php';
         // Get all notes
         $this->database->setQuery("SELECT DISTINCT p.id FROM `#__wiki_pages` AS p\n\t\t\t\tWHERE p.scope_id=" . $this->database->quote($id) . " AND p.scope=" . $this->database->quote('project'));
         $notes = $this->database->loadObjectList();
         if ($notes) {
             foreach ($notes as $note) {
                 $page = \Components\Wiki\Models\Page::oneOrFail($note->id);
                 // Finally, delete the page itself
                 $page->destroy();
             }
         }
     }
     // Erase all files, remove files repository
     if ($alias) {
         // Delete base dir for .git repos
         $dir = $alias;
         $prefix = $this->config->get('offroot', 0) ? '' : PATH_CORE;
         $repodir = DS . trim($this->config->get('webpath'), DS);
         $path = $prefix . $repodir . DS . $dir;
         if (is_dir($path)) {
             Filesystem::deleteDirectory($path);
         }
         // Delete images/preview directories
         $webdir = DS . trim($this->config->get('imagepath', '/site/projects'), DS);
         $webpath = PATH_APP . $webdir . DS . $dir;
         if (is_dir($webpath)) {
             Filesystem::deleteDirectory($webpath);
         }
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('COM_PROJECTS_PROJECT') . ' #' . $id . ' (' . $alias . ') ' . Lang::txt('COM_PROJECTS_PROJECT_ERASED'));
 }
Exemplo n.º 22
0
 public function deleteUnexistingFiles()
 {
     $files = array('/includes/version.php', '/installation/sql/mysql/joomla_update_170to171.sql', '/installation/sql/mysql/joomla_update_172to173.sql', '/installation/sql/mysql/joomla_update_17ga.sql', '/libraries/cms/cmsloader.php', '/libraries/joomla/application/applicationexception.php', '/libraries/joomla/client/http.php', '/libraries/joomla/filter/filterinput.php', '/libraries/joomla/filter/filteroutput.php', '/libraries/joomla/form/fields/templatestyle.php', '/libraries/joomla/form/fields/user.php', '/libraries/joomla/form/fields/menu.php', '/libraries/joomla/form/fields/helpsite.php', '/libraries/joomla/form/formfield.php', '/libraries/joomla/form/formrule.php', '/libraries/joomla/utilities/garbagecron.txt', '/libraries/phpmailer/language/phpmailer.lang-en.php', '/core/assets/css/modal_msie.css', '/core/assets/images/modal/closebox.gif', '/components/com_admin/admin/sql/updates/sqlsrv/2.5.2-2012-03-05.sql', '/components/com_admin/admin/sql/updates/sqlsrv/2.5.3-2012-03-13.sql', '/components/com_admin/admin/sql/updates/sqlsrv/index.html', '/components/com_users/admin/controllers/config.php', '/administrator/language/en-GB/en-GB.plg_system_finder.ini', '/administrator/language/en-GB/en-GB.plg_system_finder.sys.ini', '/media/editors/tinymce/jscripts/tiny_mce/plugins/advhr/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/advimage/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/advlink/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/advlist/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/autolink/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/autoresize/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/autosave/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/bbcode/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/contextmenu/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/directionality/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/emotions/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/fullpage/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/fullscreen/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/iespell/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/inlinepopups/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/insertdatetime/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/layer/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/lists/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/media/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/nonbreaking/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/noneditable/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/pagebreak/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/paste/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/preview/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/print/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/save/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/searchreplace/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/spellchecker/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/style/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/tabfocus/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/table/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/template/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/visualchars/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/wordcount/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/plugins/xhtmlxtras/editor_plugin_src.js', '/media/editors/tinymce/jscripts/tiny_mce/themes/advanced/editor_template_src.js', '/media/editors/tinymce/jscripts/tiny_mce/themes/simple/editor_template_src.js', '/media/editors/tinymce/jscripts/tiny_mce/tiny_mce_src.js', '/media/com_finder/images/calendar.png', '/media/com_finder/images/mime/index.html', '/media/com_finder/images/mime/pdf.png', '/core/assets/js/swf-uncompressed.js', '/core/assets/js/swf.js', '/core/assets/js/uploader-uncompressed.js', '/core/assets/js/uploader.js', '/core/assets/swf/index.html', '/core/assets/swf/uploader.swf');
     // TODO There is an issue while deleting folders using the ftp mode
     $folders = array('/libraries/joomlacms', '/media/editors/tinymce/jscripts/tiny_mce/plugins/media/img', '/media/plg_highlight', '/media/mod_finder_status', '/administrator/components/com_admin/sql/updates/sqlsrv', '/media/com_finder/images/mime', '/media/com_finder/images', '/core/assets/swf/');
     foreach ($files as $file) {
         if (Filesystem::exists(PATH_CORE . $file) && !Filesystem::delete(PATH_CORE . $file)) {
             echo Lang::txt('FILES_JOOMLA_ERROR_FILE_FOLDER', $file) . '<br />';
         }
     }
     foreach ($folders as $folder) {
         if (Filesystem::exists(PATH_CORE . $folder) && !Filesystem::deleteDirectory(PATH_CORE . $folder)) {
             echo Lang::txt('FILES_JOOMLA_ERROR_FILE_FOLDER', $folder) . '<br />';
         }
     }
 }