delete() публичный статический Метод

public static delete ( $file, $deleteIfNotEmpty = true )
Пример #1
0
 public function tearDown()
 {
     try {
         $this->filesystem->delete('file.txt');
     } catch (FileNotFoundException $e) {
     }
     $this->filesystem->deleteDir('files');
 }
Пример #2
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');
 }
Пример #3
0
 /**
  * @testdox dispatch should render output when only view exists
  */
 public function testDispatchShouldRenderOutputWhenViewExists()
 {
     // create a test view
     Filesystem::createDir('app/views/missing', 0777);
     Filesystem::write('app/views/missing/test.htm.php', 'working');
     $output = Dispatcher::dispatch(array('controller' => 'missing', 'action' => 'test') + self::$defaults);
     // destroy the test view
     Filesystem::delete('app/views/missing');
     $this->assertNotEquals('', $output);
 }
Пример #4
0
 /**
  * Clear Site.css & Site.less.cache files
  * 
  * @return  void
  */
 public function clear()
 {
     $cacheDir = PATH_APP . DS . 'cache';
     $files = array('site.css', 'site.less.cache');
     // Remove each file
     foreach ($files as $file) {
         if (!is_file($cacheDir . DS . $file)) {
             $this->output->addLine($file . ' does not exist', 'warning');
             continue;
         }
         if (!Filesystem::delete($cacheDir . DS . $file)) {
             $this->output->addLine('Unable to delete cache file: ' . $file, 'error');
         } else {
             $this->output->addLine($file . ' deleted', 'success');
         }
     }
     // success!
     $this->output->addLine('All CSS cache files removed!', 'success');
 }
Пример #5
0
 public function actionDelete($id = 0)
 {
     $request = $this->request;
     if (!$request->isPost()) {
         return;
     }
     $del = $request->post['del'];
     if ($del == 'Yes' && $id > 0) {
         try {
             $this->items->delete($id);
             $this->flashMessage('Item has been deleted.', 'ok');
             $this->redirect('default');
         } catch (DibiException $e) {
             $this->flashMessage('Delete error!' . $e, 'err');
         }
     } else {
         $this->flashMessage('There is some problem with deleting this item!', 'err');
         $this->redirect('default');
     }
 }
Пример #6
0
 /**
  * Close tickets in a pending state for a specific amount of time
  *
  * @param   object   $job  \Components\Cron\Models\Job
  * @return  boolean
  */
 public function cleanTempUploads(\Components\Cron\Models\Job $job)
 {
     $params = $job->get('params');
     $sconfig = Component::params('com_support');
     $path = PATH_APP . DS . trim($sconfig->get('webpath', '/site/tickets'), DS);
     $days = intval($params->get('support_tickettemp_age', '7'));
     $old = time() - $days * 24 * 60 * 60;
     $dirIterator = new DirectoryIterator($path);
     foreach ($dirIterator as $file) {
         if (!$file->isDir()) {
             continue;
         }
         $name = $file->getFilename();
         if (substr($name, 0, 1) != '-') {
             continue;
         }
         if (abs($name) < $old) {
             Filesystem::delete($file->getPathname());
         }
     }
 }
Пример #7
0
 public function admin($action = NULL)
 {
     if ($files = glob($this->dir . DS . 'js/jquery*')) {
         $current_script = reset($files);
         preg_match('#jquery-([\\d.]+)(\\.min)?\\.js#', $current_script, $matches);
         $current_version = $matches[1];
         $code = file_get_contents('http://code.jquery.com/');
         preg_match('#/jquery-([\\d\\.]+)\\.min\\.js#imsU', $code, $matches);
         $server_script = 'http://code.jquery.com' . $matches[0];
         $server_version = $matches[1];
         if (version_compare($server_version, $current_version, '>')) {
             if ($action = 'update') {
                 Filesystem::delete($current_script);
                 copy($server_script, dirname($current_script) . DS . basename($server_script));
                 success(t('jQuery library has been update successfully!'));
             } else {
                 info(t("Notice, jQuery framework has been updated to version <b>%s</b>. Current version is <b>%s</b>.", 'jQuery', $server_version, $current_version) . '<a href="' . Url::link('admin/jquery/update/') . '" class="button">' . t('Update') . '</a>');
             }
         }
     }
 }
Пример #8
0
 /**
  * Remove unused group folders
  *
  * @param   object   $job  \Components\Cron\Models\Job
  * @return  boolean
  */
 public function cleanGroupFolders(\Components\Cron\Models\Job $job)
 {
     // get group params
     $groupParameters = Component::params('com_groups');
     // get group upload path
     $groupUploadPath = ltrim($groupParameters->get('uploadpath', '/site/groups'), DS);
     // get group folders
     $groupFolders = Filesystem::directories(PATH_APP . DS . $groupUploadPath);
     // loop through each group folder
     foreach ($groupFolders as $groupFolder) {
         // load group object for each folder
         $hubzeroGroup = \Hubzero\User\Group::getInstance(trim($groupFolder));
         // if we dont have a group object delete folder
         if (!is_object($hubzeroGroup)) {
             // delete folder
             Filesystem::delete(PATH_APP . DS . $groupUploadPath . DS . $groupFolder);
         }
     }
     // job is no longer active
     return true;
 }
Пример #9
0
 /**
  * Batch resume download
  *
  * @return     void
  */
 public function batchTask()
 {
     // Login required
     if (User::isGuest()) {
         \Notify::warning(Lang::txt('COM_JOBS_PLEASE_LOGIN_ACCESS_EMPLOYER'));
         $this->login();
         return;
     }
     // Check authorization
     if (!$this->_admin && !$this->_emp) {
         App::redirect(Route::url('index.php?option=com_jobs&task=subscribe'));
     }
     // Incoming
     $pile = Request::getVar('pile', 'all');
     // Zip the requested resumes
     $archive = $this->_archiveResumes($pile);
     if ($archive) {
         // Initiate a new content server and serve up the file
         $xserver = new \Hubzero\Content\Server();
         $xserver->filename($archive['path']);
         $xserver->disposition('attachment');
         $xserver->acceptranges(false);
         $xserver->saveas(Lang::txt('JOBS_RESUME_BATCH=Resume Batch'));
         $result = $xserver->serve_attachment($archive['path'], $archive['name'], false);
         // Delete downloaded zip
         \Filesystem::delete($archive['path']);
         if (!$result) {
             throw new Exception(Lang::txt('COM_JOBS_ERROR_ARCHIVE_FAILED'), 500);
         } else {
             exit;
         }
     } else {
         App::redirect(Route::url('index.php?option=com_jobs&task=dashboard'), Lang::txt('COM_JOBS_ERROR_ARCHIVE_FAILED'), 'error');
     }
 }
Пример #10
0
 /**
  * Generate detailed responses CSV files and zip and offer up as download
  *
  * @return void
  **/
 private function downloadresponses()
 {
     require_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'models' . DS . 'formReport.php';
     // Only allow for instructors
     if (!$this->course->offering()->section()->access('manage')) {
         App::abort(403, 'Sorry, you don\'t have permission to do this');
     }
     if (!($asset_ids = Request::getVar('assets', false))) {
         App::abort(422, 'Sorry, we don\'t know what results you\'re trying to retrieve');
     }
     $protected = 'site' . DS . 'protected';
     $tmp = $protected . DS . 'tmp';
     // We're going to temporarily house this in PATH_APP/site/protected/tmp
     if (!Filesystem::exists($protected)) {
         App::abort(500, 'Missing temporary directory');
     }
     // Make sure tmp folder exists
     if (!Filesystem::exists($tmp)) {
         Filesystem::makeDirectory($tmp);
     } else {
         // Folder was already there - do a sanity check and make sure no old responses zips are lying around
         $files = Filesystem::files($tmp);
         if ($files && count($files) > 0) {
             foreach ($files as $file) {
                 if (strstr($file, 'responses.zip') !== false) {
                     Filesystem::delete($tmp . DS . $file);
                 }
             }
         }
     }
     // Get the individual asset ids
     $asset_ids = explode('-', $asset_ids);
     // Set up our zip archive
     $zip = new ZipArchive();
     $path = PATH_APP . DS . $tmp . DS . time() . '.responses.zip';
     $zip->open($path, ZipArchive::CREATE);
     // Loop through the assets
     foreach ($asset_ids as $asset_id) {
         // Is it a number?
         if (!is_numeric($asset_id)) {
             continue;
         }
         // Get the rest of the asset row
         $asset = new \Components\Courses\Tables\Asset($this->db);
         $asset->load($asset_id);
         // Make sure asset is a part of this course
         if ($asset->get('course_id') != $this->course->get('id')) {
             continue;
         }
         if ($details = \Components\Courses\Models\FormReport::getLetterResponsesForAssetId($this->db, $asset_id, true, $this->course->offering()->section()->get('id'))) {
             $output = implode(',', $details['headers']) . "\n";
             if (isset($details['responses']) && count($details['responses']) > 0) {
                 foreach ($details['responses'] as $response) {
                     $output .= implode(',', $response) . "\n";
                 }
             }
             $zip->addFromString($asset_id . '.responses.csv', $output);
         } else {
             continue;
         }
     }
     // Close the zip archive handler
     $zip->close();
     if (is_file($path)) {
         // Set up the server
         $xserver = new \Hubzero\Content\Server();
         $xserver->filename($path);
         $xserver->saveas('responses.zip');
         $xserver->disposition('attachment');
         $xserver->acceptranges(false);
         // Serve the file
         $xserver->serve();
         // Now delete the file
         Filesystem::delete($path);
     }
     // All done!
     exit;
 }
Пример #11
0
 /**
  * Upload a file
  *
  * @return     void
  */
 public function uploadTask()
 {
     // Check if they're logged in
     /*if (User::isGuest())
     		{
     			$this->displayTask();
     			return;
     		}*/
     if (Request::getVar('no_html', 0)) {
         return $this->ajaxUploadTask();
     }
     // Ensure we have an ID to work with
     $ticket = Request::getInt('ticket', 0, 'post');
     $comment = Request::getInt('comment', 0, 'post');
     if (!$ticket) {
         $this->setError(Lang::txt('COM_SUPPORT_NO_ID'));
         $this->displayTask();
         return;
     }
     // Incoming file
     $file = Request::getVar('upload', '', 'files', 'array');
     if (!$file['name']) {
         $this->setError(Lang::txt('COM_SUPPORT_NO_FILE'));
         $this->displayTask();
         return;
     }
     // Build the upload path if it doesn't exist
     $path = PATH_APP . DS . trim($this->config->get('filepath', '/site/tickets'), DS) . DS . $ticket;
     if (!is_dir($path)) {
         if (!Filesystem::makeDirectory($path)) {
             $this->setError(Lang::txt('Error uploading. Unable to create path.'));
             $this->displayTask();
             return;
         }
     }
     // Make the filename safe
     $file['name'] = urldecode($file['name']);
     $file['name'] = Filesystem::clean($file['name']);
     $file['name'] = str_replace(' ', '_', $file['name']);
     $ext = Filesystem::extension($file['name']);
     $filename = Filesystem::name($file['name']);
     while (file_exists($path . DS . $filename . '.' . $ext)) {
         $filename .= rand(10, 99);
     }
     //make sure that file is acceptable type
     if (!in_array($ext, explode(',', $this->config->get('file_ext')))) {
         $this->setError(Lang::txt('COM_SUPPORT_ERROR_INCORRECT_FILE_TYPE'));
         echo $this->getError();
         return;
     }
     $filename .= '.' . $ext;
     // Upload new files
     if (!\Filesystem::upload($file['tmp_name'], $path . DS . $filename)) {
         $this->setError(Lang::txt('ERROR_UPLOADING'));
     } else {
         $fle = $path . DS . $filename;
         if (!\Filesystem::isSafe($file)) {
             if (\Filesystem::delete($file)) {
                 $this->setError(Lang::txt('ATTACHMENT: File rejected because the anti-virus scan failed.'));
                 echo $this->getError();
                 return;
             }
         }
         // Create database entry
         $asset = new Attachment();
         $asset->bind(array('id' => 0, 'ticket' => $ticket, 'comment_id' => $comment, 'filename' => $filename, 'description' => Request::getVar('description', '')));
         if (!$asset->store(true)) {
             $this->setError($asset->getError());
         }
     }
     // Push through to the media view
     $this->displayTask();
 }
Пример #12
0
 /**
  * Remove image
  *
  * @param	int			Image ID
  * @return	bool		Success of Failure
  */
 public function removeImage($imgId)
 {
     $img = $this->getImage();
     if (empty($img)) {
         return false;
     }
     if ($imgId == $img->imgId) {
         $this->data->image = false;
         // Remove the actual file
         $config = Component::params('com_storefront');
         $imgWebPath = trim($config->get('collectionsImagesFolder', '/site/storefront/collections'), DS);
         $path = PATH_APP . DS . $imgWebPath . DS . $this->getId();
         if (!is_file($path . DS . $img->imgName)) {
             return false;
         }
         Filesystem::delete($path . DS . $img->imgName);
         return true;
     }
 }
Пример #13
0
 /**
  * Delete a file in the wiki
  *
  * @return  void
  */
 public function _fileDelete()
 {
     // Check if they're logged in
     if (User::isGuest()) {
         return $this->_files();
     }
     $no_html = Request::getVar('no_html', 0);
     // Incoming file
     $file = trim(Request::getVar('file', '', 'get'));
     if (!$file) {
         $this->setError(Lang::txt('PLG_COURSES_PAGES_ERROR_NO_FILE_PROVIDED'));
         if ($no_html) {
             ob_clean();
             header('Content-type: text/plain');
             echo json_encode(array('success' => false, 'error' => $this->getError()));
             exit;
         }
         return $this->_files();
     }
     // Build the file path
     $path = $this->_path();
     // Delete the file
     if (!file_exists($path . DS . $file) or !$file) {
         $this->setError(Lang::txt('PLG_COURSES_PAGES_ERROR_FILE_NOT_FOUND'));
         if ($no_html) {
             ob_clean();
             header('Content-type: text/plain');
             echo json_encode(array('success' => false, 'error' => $this->getError()));
             exit;
         }
         return $this->_files();
     } else {
         // Attempt to delete the file
         if (!Filesystem::delete($path . DS . $file)) {
             $this->setError(Lang::txt('PLG_COURSES_PAGES_ERROR_UNABLE_TO_DELETE_FILE'));
             if ($no_html) {
                 ob_clean();
                 header('Content-type: text/plain');
                 echo json_encode(array('success' => false, 'error' => $this->getError()));
                 exit;
             }
         }
     }
     if ($no_html) {
         return $this->_fileList();
     }
     // Push through to the media view
     return $this->_files();
 }
Пример #14
0
 /**
  * Get preview image
  *
  * @return  mixed
  */
 public function getPreview($model, $hash = '', $get = 'name', $render = '', $hashed = NULL)
 {
     if (!$model instanceof Project) {
         return false;
     }
     $image = NULL;
     if (!$hashed) {
         $hash = $hash ? $hash : $this->get('hash');
         $hash = $hash ? substr($hash, 0, 10) : '';
         // Determine name and size
         switch ($render) {
             case 'medium':
                 $hashed = md5($this->get('name') . '-' . $hash) . '.png';
                 $maxWidth = 600;
                 $maxHeight = 600;
                 break;
             case 'thumb':
                 $hashed = $hash ? Helpers\Html::createThumbName($this->get('name'), '-' . $hash, 'png') : NULL;
                 $maxWidth = 80;
                 $maxHeight = 80;
                 break;
             default:
                 $hashed = $hash ? Helpers\Html::createThumbName($this->get('name'), '-' . $hash . '-thumb', 'png') : NULL;
                 $maxWidth = 180;
                 $maxHeight = 180;
                 break;
         }
     }
     // Target directory
     $target = PATH_APP . DS . trim($model->config()->get('imagepath', '/site/projects'), DS);
     $target .= DS . strtolower($model->get('alias')) . DS . 'preview';
     $remoteThumb = NULL;
     if ($this->get('remoteId') && $this->get('modified')) {
         $remoteThumb = substr($this->get('remoteId'), 0, 20) . '_' . strtotime($this->get('modified')) . '.png';
     }
     if ($hashed && is_file($target . DS . $hashed)) {
         // First check locally generated thumbnail
         $image = $target . DS . $hashed;
     } elseif ($remoteThumb && is_file($target . DS . $remoteThumb)) {
         // Check remotely generated thumbnail
         $image = $target . DS . $remoteThumb;
         // Copy this over as local thumb
         if ($hashed && Filesystem::copy($target . DS . $remoteThumb, $target . DS . $hashed)) {
             Filesystem::delete($target . DS . $remoteThumb);
         }
     } else {
         // Generate thumbnail locally
         if (!file_exists($target)) {
             Filesystem::makeDirectory($target, 0755, true, true);
         }
         // Make sure it's an image file
         if (!$this->isImage() || !is_file($this->get('fullPath'))) {
             return false;
         }
         if (!Filesystem::copy($this->get('fullPath'), $target . DS . $hashed)) {
             return false;
         }
         // Resize the image if necessary
         $hi = new \Hubzero\Image\Processor($target . DS . $hashed);
         $square = $render == 'thumb' ? true : false;
         $hi->resize($maxWidth, false, false, $square);
         $hi->save($target . DS . $hashed);
         $image = $target . DS . $hashed;
     }
     // Return image
     if ($get == 'localPath') {
         return str_replace(PATH_APP, '', $image);
     } elseif ($get == 'fullPath') {
         return $image;
     } elseif ($get == 'url') {
         return Route::url('index.php?option=com_projects&alias=' . $model->get('alias') . '&controller=media&media=' . urlencode(basename($image)));
     }
     return basename($image);
 }
Пример #15
0
 /**
  * Deletes a file
  *
  * @return  void
  */
 public function deletefileTask()
 {
     // 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 file to delete
     $file = Request::getVar('delFile', '');
     if (!$file) {
         $this->setError(Lang::txt('COM_RESOURCES_ERROR_NO_FILE'));
         $this->displayTask();
         return;
     }
     // Check if the file even exists
     if (!file_exists($path . DS . $file) or !$file) {
         $this->setError(Lang::txt('COM_RESOURCES_ERROR_FILE_NOT_FOUND'));
     } else {
         // Attempt to delete the file
         if (!\Filesystem::delete($path . DS . $file)) {
             $this->setError(Lang::txt('COM_RESOURCES_ERROR_UNABLE_TO_DELETE_FILE'));
         }
     }
     // Push through to the media view
     $this->displayTask();
 }
Пример #16
0
 /**
  * Delete record
  *
  * @return  boolean  True if successful, False if not
  */
 public function destroy()
 {
     $path = $this->path();
     if (file_exists($path)) {
         if (!\Filesystem::delete($path)) {
             $this->addError('Unable to delete file.');
             return false;
         }
     }
     return parent::destroy();
 }
Пример #17
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'));
         }
     }
 }
Пример #18
0
 /**
  * Delete image
  *
  * @return     void
  */
 public function deleteimgTask()
 {
     // Incoming
     $ajax = Request::getInt('ajax', 0);
     // Check if they are logged in
     if (User::isGuest()) {
         if ($ajax) {
             echo json_encode(array('error' => Lang::txt('User login required')));
             return;
         }
         $this->_showError();
         return;
     }
     // Incoming project ID
     if (!$this->model->exists() || !$this->model->access('manager')) {
         $this->setError(Lang::txt('COM_PROJECTS_ERROR_NO_ID'));
         if ($ajax) {
             echo json_encode(array('error' => $this->getError()));
             return;
         }
         $this->_showError();
         return;
     }
     // Incoming file
     $file = Request::getVar('file', '');
     $file = $file ? $file : $this->model->get('picture');
     if (!$file) {
         $this->setError(Lang::txt('COM_PROJECTS_FILE_NOT_FOUND'));
         if ($ajax) {
             echo json_encode(array('error' => $this->getError()));
             return;
         }
         $this->_showError();
         return;
     }
     // Build path
     $webdir = DS . trim($this->config->get('imagepath', '/site/projects'), DS);
     $path = PATH_APP . $webdir . DS . $this->model->get('alias') . DS . 'images';
     if (!file_exists($path . DS . $file) or !$file) {
         $this->setError(Lang::txt('COM_PROJECTS_FILE_NOT_FOUND'));
         if ($ajax) {
             echo json_encode(array('error' => $this->getError()));
             return;
         }
     } else {
         // Attempt to delete the file
         if (!Filesystem::delete($path . DS . $file)) {
             $this->setError(Lang::txt('COM_PROJECTS_UNABLE_TO_DELETE_FILE'));
             if ($ajax) {
                 echo json_encode(array('error' => $this->getError()));
                 return;
             }
             $this->_showError();
             return;
         }
         // Delete thumbnail
         $curthumb = Helpers\Html::createThumbName($file);
         $curthumb = file_exists($path . DS . $curthumb) ? $curthumb : 'thumb.png';
         if (file_exists($path . DS . $curthumb)) {
             if (!Filesystem::delete($path . DS . $curthumb)) {
                 $this->setError(Lang::txt('COM_PROJECTS_UNABLE_TO_DELETE_FILE'));
                 if ($ajax) {
                     echo json_encode(array('error' => $this->getError()));
                     return;
                 }
                 $this->_showError();
                 return;
             }
         }
         // Instantiate a project, change some info and save
         if (!file_exists($path . DS . $file)) {
             $this->model->set('picture', '');
             if (!$this->model->store()) {
                 $this->setError($this->model->getError());
                 if ($ajax) {
                     echo json_encode(array('error' => $this->model->getError()));
                     return;
                 }
                 return;
             }
         }
     }
     if ($ajax && $this->getError()) {
         echo json_encode(array('error' => $this->getError()));
         return;
     } elseif ($ajax) {
         echo json_encode(array('success' => true));
         return;
     }
     // Go to error page
     if ($this->getError()) {
         $this->_showError();
     }
     // Return to project page
     App::redirect(Route::url($this->model->link()));
     return;
 }
Пример #19
0
 /**
  * Delete a record and any associated content
  *
  * @param   integer  $oid  Record ID
  * @return  boolean  True on success
  */
 public function delete($oid = null)
 {
     $k = $this->_tbl_key;
     if ($oid) {
         $this->{$k} = intval($oid);
     }
     // Dlete attachments
     $this->_db->setQuery("SELECT * FROM `#__wish_attachments` WHERE wish=" . $this->_db->quote($this->{$k}));
     if ($attachments = $this->_db->loadObjectList()) {
         $config = Component::params('com_wishlist');
         $path = PATH_APP . DS . trim($config->get('webpath', '/site/wishes'), DS) . DS . $oid;
         foreach ($attachments as $attachment) {
             if (file_exists($path . DS . $attachment->filename) or !$attachment->filename) {
                 // Attempt to delete the file
                 if (!\Filesystem::delete($path . DS . $attachment->filename)) {
                     $this->setError(Lang::txt('UNABLE_TO_DELETE_FILE'));
                 }
             }
         }
     }
     // Delete the plan
     $query = 'DELETE FROM `#__wishlist_implementation` WHERE wishid = ' . $this->_db->quote($this->{$k});
     $this->_db->setQuery($query);
     if (!$this->_db->query()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // Remove all tags
     include_once dirname(__DIR__) . DS . 'models' . DS . 'tags.php';
     $wt = new Tags($oid);
     $wt->setTags('', User::get('id'), 1);
     // Delete the wish
     return parent::delete($oid);
 }
Пример #20
0
 /**
  * Clean out old system CSS files
  *
  * @param   object   $job  \Components\Cron\Models\Job
  * @return  boolean
  */
 public function cleanSystemCss(\Components\Cron\Models\Job $job)
 {
     if (!is_dir($this->_path)) {
         return;
     }
     $docs = array();
     $dirIterator = new DirectoryIterator($this->_path);
     foreach ($dirIterator as $file) {
         if ($file->isDot() || $file->isDir()) {
             continue;
         }
         if ($file->isFile()) {
             $name = $file->getFilename();
             $ext = Filesystem::extension($name);
             if ('cvs' == strtolower($name) || '.svn' == strtolower($name) || $ext != 'css') {
                 continue;
             }
             if (substr($name, 0, strlen('system-')) != 'system-') {
                 continue;
             }
             $docs[$this->_path . DS . $name] = $name;
         }
     }
     if (count($docs) > 1) {
         foreach ($docs as $p => $n) {
             Filesystem::delete($p);
         }
     }
     return true;
 }
Пример #21
0
 /**
  * Unpublish file attachment
  *
  * @param      object  		$objPA
  * @param      object  		$pub
  * @param      object  		$configs
  *
  * @return     boolean or error
  */
 public function unpublishAttachment($row, $pub, $configs)
 {
     // Get file path
     $deletePath = $this->getFilePath($row->path, $row->id, $configs, $row->params);
     // Hash file
     $hfile = $deletePath . '.hash';
     // Delete file
     if (is_file($deletePath)) {
         if (Filesystem::delete($deletePath)) {
             // Also delete hash file
             if (is_file($hfile)) {
                 Filesystem::delete($hfile);
             }
             // Remove any related files managed by handler
             if ($configs->handler) {
                 $configs->handler->cleanUp($deletePath, $configs);
             }
         } else {
             return false;
         }
     }
     return true;
 }
Пример #22
0
 /**
  * Upload an image
  *
  * @return  void
  */
 public function uploadTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $id = Request::getInt('id', 0);
     if (!$id) {
         $this->setError(Lang::txt('COM_STORE_FEEDBACK_NO_ID'));
         $this->displayTask($id);
         return;
     }
     // Incoming file
     $file = Request::getVar('upload', '', 'files', 'array');
     if (!$file['name']) {
         $this->setError(Lang::txt('COM_STORE_FEEDBACK_NO_FILE'));
         $this->displayTask($id);
         return;
     }
     // Build upload path
     $path = PATH_APP . DS . trim($this->config->get('webpath', '/site/store'), DS) . DS . $id;
     if (!is_dir($path)) {
         if (!\Filesystem::makeDirectory($path)) {
             $this->setError(Lang::txt('COM_STORE_UNABLE_TO_CREATE_UPLOAD_PATH'));
             $this->displayTask($id);
             return;
         }
     }
     // Make the filename safe
     $file['name'] = \Filesystem::clean($file['name']);
     $file['name'] = str_replace(' ', '_', $file['name']);
     require_once dirname(dirname(__DIR__)) . DS . 'helpers' . DS . 'imghandler.php';
     // Perform the upload
     if (!\Filesystem::upload($file['tmp_name'], $path . DS . $file['name'])) {
         $this->setError(Lang::txt('COM_STORE_ERROR_UPLOADING'));
     } else {
         $ih = new ImgHandler();
         // Do we have an old file we're replacing?
         if ($curfile = Request::getVar('currentfile', '')) {
             // Remove old image
             if (file_exists($path . DS . $curfile)) {
                 if (!\Filesystem::delete($path . DS . $curfile)) {
                     $this->setError(Lang::txt('COM_STORE_UNABLE_TO_DELETE_FILE'));
                     $this->displayTask($id);
                     return;
                 }
             }
             // Get the old thumbnail name
             $curthumb = $ih->createThumbName($curfile);
             // Remove old thumbnail
             if (file_exists($path . DS . $curthumb)) {
                 if (!\Filesystem::delete($path . DS . $curthumb)) {
                     $this->setError(Lang::txt('COM_STORE_UNABLE_TO_DELETE_FILE'));
                     $this->displayTask($id);
                     return;
                 }
             }
         }
         // Create a thumbnail image
         $ih->set('image', $file['name']);
         $ih->set('path', $path . DS);
         $ih->set('maxWidth', 80);
         $ih->set('maxHeight', 80);
         $ih->set('cropratio', '1:1');
         $ih->set('outputName', $ih->createThumbName());
         if (!$ih->process()) {
             $this->setError($ih->getError());
         }
     }
     // Push through to the image view
     $this->displayTask($id);
 }
Пример #23
0
 /**
  * Delete a resume
  *
  * @param   object   $database  Database
  * @param   string   $option    Component name
  * @param   object   $member    Profile
  * @param   integer  $emp       Is user employer?
  * @return  string
  */
 protected function _deleteresume($database, $option, $member, $emp)
 {
     $row = new \Components\Jobs\Tables\Resume($database);
     if (!$row->loadResume($member->get('id'))) {
         $this->setError(Lang::txt('Resume ID not found.'));
         return '';
     }
     // Incoming file
     $file = $row->filename;
     $path = $this->build_path($member->get('id'));
     if (!file_exists(PATH_APP . $path . DS . $file) or !$file) {
         $this->setError(Lang::txt('FILE_NOT_FOUND'));
     } else {
         // Attempt to delete the file
         if (!Filesystem::delete(PATH_APP . $path . DS . $file)) {
             $this->setError(Lang::txt('UNABLE_TO_DELETE_FILE'));
         } else {
             $row->delete();
             // Remove stats for prev resume
             $jobstats = new \Components\Jobs\Tables\JobStats($database);
             $jobstats->deleteStats($member->get('id'), 'seeker');
             // Do not include profile in search without a resume
             $js = new \Components\Jobs\Tables\JobSeeker($database);
             $js->loadSeeker($member->get('id'));
             $js->bind(array('active' => 0));
             if (!$js->store()) {
                 $this->setError($js->getError());
             }
         }
     }
     // Push through to the main view
     return $this->_view($database, $option, $member, $emp);
 }
Пример #24
0
 /**
  * Unpublish version/delete draft
  *
  * @return     string
  */
 public function cancelDraft()
 {
     // Incoming
     $pid = $this->_pid ? $this->_pid : Request::getInt('pid', 0);
     $confirm = Request::getInt('confirm', 0);
     $version = Request::getVar('version', 'default');
     $ajax = Request::getInt('ajax', 0);
     // Check permission
     if (!$this->model->access('content')) {
         throw new Exception(Lang::txt('ALERTNOTAUTH'), 403);
         return;
     }
     // Load publication model
     $pub = new \Components\Publications\Models\Publication($pid, $version);
     if (!$pub->exists() || !$pub->belongsToProject($this->model->get('id'))) {
         throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_NOT_FOUND'), 404);
         return;
     }
     // Save version ID
     $vid = $pub->version->get('id');
     // Append breadcrumbs
     if (!$ajax) {
         Pathway::append(stripslashes($pub->version->get('title')), $pub->link('edit'));
     }
     $baseUrl = Route::url($pub->link('editbase'));
     $baseEdit = Route::url($pub->link('edit'));
     // Can only unpublish published version or delete a draft
     if ($pub->version->get('state') != 1 && $pub->version->get('state') != 3 && $pub->version->get('state') != 4) {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_CANT_DELETE'));
     }
     // Unpublish/delete version
     if ($confirm) {
         if (!$this->getError()) {
             $pubtitle = \Hubzero\Utility\String::truncate($pub->version->get('title'), 100);
             if ($pub->version->get('state') == 1) {
                 // Unpublish published version
                 $pub->version->set('published_down', Date::toSql());
                 $pub->version->set('modified', Date::toSql());
                 $pub->version->set('modified_by', $this->_uid);
                 $pub->version->set('state', 0);
                 if (!$pub->version->store()) {
                     throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_UNPUBLISH_FAILED'), 403);
                     return;
                 } else {
                     $this->_msg = Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_UNPUBLISHED');
                     // Add activity
                     $action = Lang::txt('PLG_PROJECTS_PUBLICATIONS_ACTIVITY_UNPUBLISHED');
                     $action .= ' ' . strtolower(Lang::txt('version')) . ' ' . $pub->version->get('version_label') . ' ' . Lang::txt('PLG_PROJECTS_PUBLICATIONS_OF') . ' ' . strtolower(Lang::txt('publication')) . ' "' . $pubtitle . '" ';
                     $aid = $this->model->recordActivity($action, $pid, $pubtitle, Route::url($pub->link('editversion')), 'publication', 0);
                 }
             } elseif ($pub->version->get('state') == 3 || $pub->version->get('state') == 4) {
                 $vlabel = $pub->version->get('version_label');
                 // Delete draft version
                 if (!$pub->version->delete()) {
                     throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_DELETE_DRAFT_FAILED'), 403);
                     return;
                 }
                 // Delete authors
                 $pa = new \Components\Publications\Tables\Author($this->_database);
                 $authors = $pa->deleteAssociations($vid);
                 // Delete attachments
                 $pContent = new \Components\Publications\Tables\Attachment($this->_database);
                 $pContent->deleteAttachments($vid);
                 // Delete screenshots
                 $pScreenshot = new \Components\Publications\Tables\Screenshot($this->_database);
                 $pScreenshot->deleteScreenshots($vid);
                 // Build publication path
                 $path = PATH_APP . DS . trim($this->_pubconfig->get('webpath'), DS) . DS . \Hubzero\Utility\String::pad($pid);
                 // Build version path
                 $vPath = $path . DS . \Hubzero\Utility\String::pad($vid);
                 // Delete all version files
                 if (is_dir($vPath)) {
                     Filesystem::deleteDirectory($vPath);
                 }
                 // Delete access accosiations
                 $pAccess = new \Components\Publications\Tables\Access($this->_database);
                 $pAccess->deleteGroups($vid);
                 // Delete audience
                 $pAudience = new \Components\Publications\Tables\Audience($this->_database);
                 $pAudience->deleteAudience($vid);
                 // Delete publication existence
                 if ($pub->versionCount() == 0) {
                     // Delete all files
                     if (is_dir($path)) {
                         Filesystem::delete($path);
                     }
                     $pub->publication->delete($pid);
                     $pub->publication->deleteExistence($pid);
                     // Delete related publishing activity from feed
                     $objAA = $this->model->table('Activity');
                     $objAA->deleteActivityByReference($this->model->get('id'), $pid, 'publication');
                 }
                 // Add activity
                 $action = Lang::txt('PLG_PROJECTS_PUBLICATIONS_ACTIVITY_DRAFT_DELETED');
                 $action .= ' ' . $vlabel . ' ';
                 $action .= Lang::txt('PLG_PROJECTS_PUBLICATIONS_OF_PUBLICATION') . ' "' . $pubtitle . '"';
                 $aid = $this->model->recordActivity($action, $pid, '', '', 'publication', 0);
                 $this->_msg = Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_DRAFT_DELETED');
             }
         }
     } else {
         $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => 'cancel'));
         // Output HTML
         $view->option = $this->_option;
         $view->database = $this->_database;
         $view->project = $this->model;
         $view->uid = $this->_uid;
         $view->pid = $pid;
         $view->pub = $pub;
         $view->publishedCount = $pub->version->getPublishedCount($pid);
         $view->task = $this->_task;
         $view->config = $this->model->config();
         $view->pubconfig = $this->_pubconfig;
         $view->ajax = $ajax;
         $view->title = $this->_area['title'];
         // Get messages	and errors
         $view->msg = $this->_msg;
         if ($this->getError()) {
             $view->setError($this->getError());
         }
         return $view->loadTemplate();
     }
     // Pass error or success message
     if ($this->getError()) {
         \Notify::message($this->getError(), 'error', 'projects');
     } elseif (!empty($this->_msg)) {
         \Notify::message($this->_msg, 'success', 'projects');
     }
     App::redirect($baseUrl);
     return;
 }
Пример #25
0
 /**
  * Delete records by comment ID
  *
  * @param   integer  $comment_id  ID of parent comment
  * @return  boolean  true  if successful otherwise returns and error message
  */
 public function deleteFile($filename = NULL)
 {
     if ($filename === null) {
         $filename = $this->filename;
     } else {
         if (is_numeric($filename) && $filename != $this->id) {
             $tbl = new self($this->_db);
             $tbl->load($filename);
             $filename = $tbl->filename;
         }
     }
     if (file_exists($this->_getUploadDir() . DS . $filename)) {
         if (!\Filesystem::delete($this->_getUploadDir() . DS . $filename)) {
             $this->setError(\Lang::txt('Unable to delete file.'));
             return false;
         }
     }
     return true;
 }
Пример #26
0
 /**
  * Delete a screenshot
  *
  * @return     void
  */
 public function deleteTask()
 {
     // Incoming parent ID
     $pid = Request::getInt('pid', 0);
     $version = Request::getVar('version', 'dev');
     if (!$pid) {
         $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_NO_ID'));
         $this->displayTask($pid, $version);
         return;
     }
     // Incoming child ID
     $file = Request::getVar('filename', '');
     if (!$file) {
         $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_NO_CHILD_ID'));
         $this->displayTask($pid, $version);
         return;
     }
     // Load resource info
     $row = new \Components\Resources\Tables\Resource($this->database);
     $row->load($pid);
     // Get version id
     $objV = new \Components\Tools\Tables\Version($this->database);
     $vid = $objV->getVersionIdFromResource($pid, $version);
     if ($vid == NULL) {
         $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_VERSION_ID_NOT_FOUND'));
         $this->displayTask($pid, $version);
         return;
     }
     include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php';
     // Build the path
     $listdir = \Components\Resources\Helpers\Html::build_path($row->created, $pid, '');
     $listdir .= DS . $vid;
     $path = $this->_buildUploadPath($listdir, '');
     // Check if the folder even exists
     if (!is_dir($path) or !$path) {
         $this->setError(Lang::txt('COM_TOOLS_DIRECTORY_NOT_FOUND'));
         $this->displayTask($pid, $version);
         return;
     } else {
         if (!Filesystem::exists($path . DS . $file)) {
             $this->displayTask($pid, $version);
             return;
         }
         if (!Filesystem::delete($path . DS . $file)) {
             $this->setError(Lang::txt('COM_TOOLS_UNABLE_TO_DELETE_FILE'));
             $this->displayTask($pid, $version);
             return;
         } else {
             // Delete thumbnail
             $tn = \Components\Resources\Helpers\Html::thumbnail($file);
             Filesystem::delete($path . DS . $tn);
             // Instantiate a new screenshot object
             $ss = new \Components\Resources\Tables\Screenshot($this->database);
             $ss->deleteScreenshot($file, $pid, $vid);
         }
     }
     $this->_rid = $pid;
     // Push through to the screenshot view
     $this->displayTask($pid, $version);
 }
Пример #27
0
 /**
  * Delete file
  *
  * @param      array	$params
  *
  * @return     array
  */
 public function deleteFile($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') != 'file' || !$file->exists()) {
         return false;
     }
     // Delete from Git
     $this->_git->gitDelete($file->get('localPath'), 'file', $commitMsg);
     $this->_git->gitCommit($commitMsg, $author, $date);
     // Untracked?
     if (!$this->get('remote') && file_exists($file->get('fullPath'))) {
         // Remove file that is not in Git
         if (!Filesystem::delete($file->get('fullPath'))) {
             return false;
         }
     }
     return true;
 }
Пример #28
0
 /**
  * Deletes a file
  *
  * @return     void
  */
 public function deleteTask()
 {
     // Check for request forgeries
     Request::checkToken('get');
     // Incoming directory (this should be a path built from a resource ID and its creation year/month)
     $resource = Request::getInt('resource', 0);
     if (!$resource) {
         $this->setError(Lang::txt('RESOURCES_NO_LISTDIR'));
         $this->displayTask();
         return;
     }
     // Incoming sub-directory
     //$subdir = Request::getVar('dirPath', '', 'post');
     $row = new Resource($this->database);
     $row->load($resource);
     // Incoming sub-directory
     //$subdir = Request::getVar('subdir', '');
     // allow for temp resource uploads
     if (!$row->created || $row->created == '0000-00-00 00:00:00') {
         $row->created = Date::format('Y-m-d 00:00:00');
     }
     $path = PATH_APP . DS . trim($this->config->get('uploadpath', '/site/resources'), DS) . Html::build_path($row->created, $resource, '') . DS . 'media';
     // Make sure the listdir follows YYYY/MM/#
     $parts = explode('/', $path);
     if (count($parts) < 4) {
         $this->setError(Lang::txt('DIRECTORY_NOT_FOUND'));
         $this->displayTask();
         return;
     }
     // Incoming file to delete
     $file = Request::getVar('file', '');
     if (!$file) {
         $this->setError(Lang::txt('RESOURCES_NO_FILE'));
         $this->displayTask();
         return;
     }
     // Check if the file even exists
     if (!file_exists($path . DS . $file) or !$file) {
         $this->setError(Lang::txt('FILE_NOT_FOUND'));
     } else {
         // Attempt to delete the file
         if (!\Filesystem::delete($path . DS . $file)) {
             $this->setError(Lang::txt('UNABLE_TO_DELETE_FILE'));
         }
     }
     // Push through to the media view
     $this->displayTask();
 }
Пример #29
0
 /**
  * Serve file (usually via public link)
  *
  * @param   string   $type
  * @param   integer  $projectid
  * @param   string   $query
  * @return  void
  */
 public function serve($type = '', $projectid = 0, $query = '')
 {
     $this->_area = $this->onProjectAreas();
     if ($type != $this->_area['name']) {
         return false;
     }
     $data = json_decode($query);
     if (!isset($data->file) || !$projectid) {
         return false;
     }
     $file = $data->file;
     $disp = isset($data->disp) ? $data->disp : 'inline';
     $limited = isset($data->limited) ? $data->limited : 0;
     $hash = isset($data->hash) ? $data->hash : 0;
     $repoName = isset($data->repo) ? $data->repo : 'local';
     // Instantiate a project
     $model = new \Components\Projects\Models\Project($projectid);
     if (!$model->exists() || $limited == 1 && !$model->access('member')) {
         // Throw error
         App::abort(403, Lang::txt('COM_PROJECTS_ERROR_ACTION_NOT_AUTHORIZED'));
     }
     // Load repo
     $repo = new \Components\Projects\Models\Repo($model, $repoName);
     $deleteTemp = false;
     if ($hash) {
         $tempPath = sys_get_temp_dir();
         $tempName = 'temp-' . \Components\Projects\Helpers\Html::generateCode(4, 4, 0, 1, 0) . basename($file);
         $serve = $tempPath . DS . $tempName;
         // Get file content
         $repo->call('content', $params = array('fileName' => $file, 'hash' => $hash, 'target' => $serve));
         $deleteTemp = true;
     } else {
         $serve = $repo->get('path') . DS . $file;
     }
     // Ensure the file exist
     if (!file_exists($serve)) {
         // Throw error
         App::abort(404, Lang::txt('COM_PROJECTS_FILE_NOT_FOUND'));
     }
     // Initiate a new content server and serve up the file
     $server = new \Hubzero\Content\Server();
     $server->filename($serve);
     $server->disposition($disp);
     $server->acceptranges(false);
     // @TODO fix byte range support
     $server->saveas(basename($file));
     $result = $server->serve();
     if ($deleteTemp) {
         // Delete downloaded temp file
         Filesystem::delete($serve);
     }
     if (!$result) {
         // Should only get here on error
         App::abort(404, Lang::txt('PLG_PROJECTS_FILES_SERVER_ERROR'));
     } else {
         exit;
     }
     return;
 }
Пример #30
0
 /**
  * Upload a file
  *
  * @param      integer $listdir Wish ID
  * @return     string
  */
 public function uploadTask($listdir)
 {
     if (!$listdir) {
         $this->setError(Lang::txt('COM_WISHLIST_ERROR_NO_UPLOAD_DIRECTORY'));
         return '';
     }
     // Incoming file
     $file = Request::getVar('upload', array(), 'files', 'array');
     if (!isset($file['name']) || !$file['name']) {
         $this->setError(Lang::txt('COM_WISHLIST_ERROR_NO_FILE'));
         return '';
     }
     // Make the filename safe
     $file['name'] = \Filesystem::clean($file['name']);
     $file['name'] = str_replace(' ', '_', $file['name']);
     //make sure that file is acceptable type
     $attachment = new Attachment(array('id' => 0, 'description' => Request::getVar('description', ''), 'wish' => $listdir, 'filename' => $file['name']));
     // make sure that file is acceptable type
     if (!$attachment->isAllowedType()) {
         $this->setError(Lang::txt('ATTACHMENT: Incorrect file type.'));
         return Lang::txt('ATTACHMENT: Incorrect file type.');
     }
     $path = $attachment->link('dir');
     // Build the path if it doesn't exist
     if (!is_dir($path)) {
         if (!\Filesystem::makeDirectory($path)) {
             $this->setError(Lang::txt('COM_WISHLIST_UNABLE_TO_CREATE_UPLOAD_PATH'));
             return 'ATTACHMENT: ' . Lang::txt('COM_WISHLIST_UNABLE_TO_CREATE_UPLOAD_PATH');
         }
     }
     // Perform the upload
     if (!\Filesystem::upload($file['tmp_name'], $path . DS . $file['name'])) {
         $this->setError(Lang::txt('COM_WISHLIST_ERROR_UPLOADING'));
         return 'ATTACHMENT: ' . Lang::txt('COM_WISHLIST_ERROR_UPLOADING');
     } else {
         // Scan for viruses
         $path = $path . DS . $file['name'];
         //PATH_CORE . DS . 'virustest';
         if (!\Filesystem::isSafe($path)) {
             if (\Filesystem::delete($path)) {
                 $this->setError(Lang::txt('ATTACHMENT: File rejected because the anti-virus scan failed.'));
                 return Lang::txt('ATTACHMENT: File rejected because the anti-virus scan failed.');
             }
         }
         if (!$attachment->store(true)) {
             $this->setError($attachment->getError());
         }
         return '{attachment#' . $attachment->get('id') . '}';
     }
 }