Exemple #1
0
 /**
  * Delete a file in the wiki
  *
  * @return     void
  */
 public function deleteTask()
 {
     // Check if they are logged in
     if (User::isGuest()) {
         return false;
     }
     // Incoming member ID
     $id = Request::getInt('id', 0);
     if (!$id) {
         $this->setError(Lang::txt('MEMBERS_NO_ID'));
         $this->displayTask('', $id);
     }
     // Incoming file
     $file = Request::getVar('file', '');
     if (!$file) {
         $this->setError(Lang::txt('MEMBERS_NO_FILE'));
         $this->displayTask('', $id);
     }
     // Build the file path
     $dir = \Hubzero\Utility\String::pad($id);
     $path = PATH_APP . DS . $this->filespace() . DS . $dir;
     if (!file_exists($path . DS . $file) or !$file) {
         $this->setError(Lang::txt('FILE_NOT_FOUND'));
     } else {
         $ih = new \Components\Members\Helpers\ImgHandler();
         // Attempt to delete the file
         if (!Filesystem::delete($path . DS . $file)) {
             $this->setError(Lang::txt('UNABLE_TO_DELETE_FILE'));
             $this->displayTask($file, $id);
             return;
         }
         $curthumb = $ih->createThumbName($file);
         if (file_exists($path . DS . $curthumb)) {
             if (!Filesystem::delete($path . DS . $curthumb)) {
                 $this->setError(Lang::txt('UNABLE_TO_DELETE_FILE'));
                 $this->displayTask($file, $id);
                 return;
             }
         }
         // Instantiate a profile, change some info and save
         $profile = \Hubzero\User\Profile::getInstance($id);
         $profile->set('picture', '');
         if (!$profile->update()) {
             $this->setError($profile->getError());
         }
         $file = '';
     }
     // Push through to the image view
     $this->displayTask($file, $id);
 }
Exemple #2
0
 /**
  * Delete a file
  *
  * @return  void
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken('get');
     // Incoming member ID
     $id = Request::getInt('id', 0);
     if (!$id) {
         $this->setError(Lang::txt('COM_MEMBERS_NO_ID'));
         $this->displayTask('', $id);
         return;
     }
     // Incoming file
     $file = Request::getVar('file', '');
     if (!$file) {
         $this->setError(Lang::txt('COM_MEMBERS_NO_FILE'));
         $this->displayTask('', $id);
         return;
     }
     // Build the file path
     $dir = \Hubzero\Utility\String::pad($id);
     $path = PATH_APP . DS . trim($this->config->get('webpath', '/site/members'), DS) . DS . $dir;
     // if we have file
     if (!file_exists($path . DS . $file) or !$file) {
         $this->setError(Lang::txt('COM_MEMBERS_FILE_NOT_FOUND'));
     } else {
         $ih = new \Components\Members\Helpers\ImgHandler();
         // Attempt to delete the file
         if (!Filesystem::delete($path . DS . $file)) {
             $this->setError(Lang::txt('COM_MEMBERS_UNABLE_TO_DELETE_FILE'));
             $this->displayTask($file, $id);
             return;
         }
         // Get the file thumbnail name
         if ($file == 'profile.png') {
             $curthumb = 'thumb.png';
         } else {
             $curthumb = $ih->createThumbName($file);
         }
         // Remove the thumbnail
         if (file_exists($path . DS . $curthumb)) {
             if (!Filesystem::delete($path . DS . $curthumb)) {
                 $this->setError(Lang::txt('COM_MEMBERS_UNABLE_TO_DELETE_FILE'));
                 $this->displayTask($file, $id);
                 return;
             }
         }
         // Instantiate a profile, change some info and save
         $profile = \Hubzero\User\Profile::getInstance($id);
         $profile->set('picture', '');
         if (!$profile->update()) {
             $this->setError($profile->getError());
         }
         $file = '';
     }
     $this->displayTask($file, $id);
 }
Exemple #3
0
 /**
  * Upload a file to the wiki
  *
  * @return  void
  */
 public function uploadTask()
 {
     // Check if they are logged in
     if (User::isGuest()) {
         return false;
     }
     Request::checkToken();
     // Incoming member ID
     $id = Request::getInt('id', 0);
     if (!$id) {
         $this->setError(Lang::txt('MEMBERS_NO_ID'));
         return $this->displayTask('', $id);
     }
     // Incoming file
     $file = Request::getVar('upload', '', 'files', 'array');
     if (!$file['name']) {
         $this->setError(Lang::txt('MEMBERS_NO_FILE'));
         return $this->displayTask('', $id);
     }
     // Build upload path
     $dir = \Hubzero\Utility\String::pad($id);
     $path = PATH_APP . DS . $this->filespace() . DS . $dir;
     if (!is_dir($path)) {
         if (!Filesystem::makeDirectory($path)) {
             $this->setError(Lang::txt('UNABLE_TO_CREATE_UPLOAD_PATH'));
             return $this->displayTask('', $id);
         }
     }
     // Make the filename safe
     $file['name'] = Filesystem::clean($file['name']);
     $file['name'] = str_replace(' ', '_', $file['name']);
     // Do we have an old file we're replacing?
     $curfile = Request::getVar('currentfile', '');
     // Perform the upload
     if (!Filesystem::upload($file['tmp_name'], $path . DS . $file['name'])) {
         $this->setError(Lang::txt('ERROR_UPLOADING'));
         $file = $curfile;
     } else {
         $ih = new \Components\Members\Helpers\ImgHandler();
         if ($curfile != '') {
             // Yes - remove it
             if (file_exists($path . DS . $curfile)) {
                 if (!Filesystem::delete($path . DS . $curfile)) {
                     $this->setError(Lang::txt('UNABLE_TO_DELETE_FILE'));
                     return $this->displayTask($file['name'], $id);
                 }
             }
             $curthumb = $ih->createThumbName($curfile);
             if (file_exists($path . DS . $curthumb)) {
                 if (!Filesystem::delete($path . DS . $curthumb)) {
                     $this->setError(Lang::txt('UNABLE_TO_DELETE_FILE'));
                     return $this->displayTask($file['name'], $id);
                 }
             }
         }
         // Instantiate a profile, change some info and save
         $profile = Member::oneOrFail($id);
         $profile->set('picture', $file['name']);
         if (!$profile->save()) {
             $this->setError($profile->getError());
         }
         // Resize the image if necessary
         $ih->set('image', $file['name']);
         $ih->set('path', $path . DS);
         $ih->set('maxWidth', 186);
         $ih->set('maxHeight', 186);
         if (!$ih->process()) {
             $this->setError($ih->getError());
         }
         // Create a thumbnail image
         $ih->set('maxWidth', 50);
         $ih->set('maxHeight', 50);
         $ih->set('cropratio', '1:1');
         $ih->set('outputName', $ih->createThumbName());
         if (!$ih->process()) {
             $this->setError($ih->getError());
         }
         $file = $file['name'];
     }
     // Push through to the image view
     $this->displayTask($file, $id);
 }