Example #1
0
 /**
  * Notify the owner of the file passed as parameter that its file is going
  * to be deleted
  *
  * @param App_Model_File $file
  */
 private function notifyDeletionByEmail(App_Model_File $file)
 {
     try {
         $mail = $this->createMail();
         $subject = __r('[FileZ] Your file "%file_name%" is going to be deleted', array('file_name' => $file->file_name));
         $msg = __r('email_delete_notif (%file_name%, %file_url%, %filez_url%, %available_until%)', array('file_name' => $file->file_name, 'file_url' => $file->getDownloadUrl(), 'filez_url' => url_for('/'), 'available_until' => $file->getAvailableUntil()->toString(Zend_Date::DATE_FULL)));
         $mail->setBodyText($msg);
         $mail->setSubject($subject);
         $mail->addTo($file->uploader_email);
         $mail->send();
         fz_log('Delete notification sent to ' . $file->uploader_email, FZ_LOG_CRON);
     } catch (Exception $e) {
         fz_log('Can\'t send email to ' . $file->uploader_email . ' file_id:' . $file->id, FZ_LOG_CRON_ERROR);
     }
 }
 /**
  * Delete
  *  (array)ids
  *
  * @throws App_Exception_FileIsNotWritable
  * @throws App_Exception_Forbidden
  */
 public function deleteAction()
 {
     $files = App_Model_File::fetchAll(['user' => (string) $this->user->id, 'identity' => ['$in' => $this->getParam('ids')]]);
     foreach ($files as $file) {
         $this->storage->delete($file);
     }
 }
Example #3
0
 public function createAction()
 {
     $folder = $this->getDb()->getRepository('App_Model_Folder')->find($this->getRequest()->getParam('folder_id'));
     if (!$folder) {
         $this->addFlashMessageError('Folder not found');
         $this->_redirect($this->getUrl(array(), 'admin_index'));
     }
     $this->view->page_heading = 'Create New Media File';
     $form = new Admin_Form_CreateFile();
     $this->view->form = $form;
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if ($form->isValid($this->getRequest()->getPost())) {
         $file = new App_Model_File();
         $file->setName($form->name->getValue());
         $file->setFolder($folder);
         if (!$form->file->receive()) {
             $form->file->addError('There was an error processing the file');
             return;
         }
         $path_parts = pathinfo($form->file->getFileName());
         $file->setExtension($path_parts['extension']);
         try {
             $this->getDb()->persist($file);
             $this->getDb()->flush();
             if (!@rename($form->file->getFileName(), $file->getFullPath(Zend_Registry::get('media_path')))) {
                 throw new App_Model_FileMoveException();
             }
             $this->addFlashMessageSuccess('Your new media has been created successfully');
             $this->_redirect($this->getUrl(array('folder_id' => $folder->getId()), 'admin_view_folder'));
         } catch (PDOException $e) {
             $dbException = new App_Model_DBExceptionDecorator($e);
             if ($dbException->isDuplicateKeyViolation()) {
                 $form->name->addError('A file with this name already exists in this folder');
             } else {
                 throw $e;
             }
         } catch (App_Model_FileMoveException $e) {
             $this->getDb()->remove($file);
             $this->getDb()->flush();
             $form->file->addError('There was an error processing the file');
         }
     }
 }
Example #4
0
 /**
  * Notify the file's owner by email that its file has been downloaded
  *
  * @param App_Model_File $file
  */
 private function sendFileDownloadedMail(App_Model_File $file)
 {
     if (!$file->notify_uploader) {
         return;
     }
     // find user IP
     // TODO: extract this function to generic place
     $ipaddress = '';
     if ($_SERVER['HTTP_CLIENT_IP']) {
         $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
     } else {
         if ($_SERVER['HTTP_X_FORWARDED_FOR']) {
             $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
         } else {
             if ($_SERVER['HTTP_X_FORWARDED']) {
                 $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
             } else {
                 if ($_SERVER['HTTP_FORWARDED_FOR']) {
                     $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
                 } else {
                     if ($_SERVER['HTTP_FORWARDED']) {
                         $ipaddress = $_SERVER['HTTP_FORWARDED'];
                     } else {
                         if ($_SERVER['REMOTE_ADDR']) {
                             $ipaddress = $_SERVER['REMOTE_ADDR'];
                         } else {
                             $ipaddress = 'UNKNOWN';
                         }
                     }
                 }
             }
         }
     }
     // Send confirmation mail
     $user = Fz_Db::getTable('User')->findById($file->created_by);
     // I don't get why $user = $this->getUser (); doesn't work ???
     $mail = $this->createMail();
     $mail->addTo($user->email);
     $mail->addTo($user->email, $user->firstname . ' ' . $user->lastname);
     $subject = __r('[FileZ] "%file_name%" downloaded', array('file_name' => $file->file_name));
     $msg = __r('email_file_downloaded (%file_name%, %file_url%, %sender%, %ip%)', array('file_name' => $file->file_name, 'file_url' => $file->getDownloadUrl(), 'sender' => $user, 'ip' => $ipaddress));
     $mail->setBodyText($msg);
     $mail->setSubject($subject);
     $mail->setReplyTo($user->email, $user);
     $mail->clearFrom();
     $mail->setFrom(fz_config_get('email', 'from_email'), fz_config_get('email', 'from_name'));
     try {
         $mail->send();
     } catch (Exception $e) {
         fz_log('Can\'t send email "File Downloaded" : ' . $e, FZ_LOG_ERROR);
     }
 }
Example #5
0
 /**
  * Checks if the user is the owner of the file. Stop the request if not.
  * 
  * @param App_Model_File $file
  * @param array $user
  */
 protected function checkOwner(App_Model_File $file, $user)
 {
     if ($file->isOwner($user)) {
         return;
     }
     halt(HTTP_UNAUTHORIZED, __('You are not the owner of the file'));
 }
Example #6
0
 /**
  * Notify the user by email that its file has been uploaded
  *
  * @param App_Model_File $file
  */
 private function sendFileUploadedMail(App_Model_File $file)
 {
     if (!$file->notify_uploader) {
         return;
     }
     $user = $this->getUser();
     $subject = __r('[FileZ] "%file_name%" uploaded successfully', array('file_name' => $file->file_name));
     $msg = __r('email_upload_success (%file_name%, %file_url%, %filez_url%, %available_from%, %available_until%)', array('file_name' => $file->file_name, 'available_from' => $file->getAvailableFrom()->toString(Zend_Date::DATE_LONG), 'available_until' => $file->getAvailableUntil()->toString(Zend_Date::DATE_LONG), 'file_url' => $file->getDownloadUrl(), 'filez_url' => fz_url_for('/', fz_config_get('app', 'https') == 'always')));
     $mail = $this->createMail();
     $mail->setBodyText($msg);
     $mail->setSubject($subject);
     $mail->addTo($user->email, $user->firstname . ' ' . $user->lastname);
     try {
         $mail->send();
     } catch (Exception $e) {
         fz_log('Can\'t send email "File Uploaded" : ' . $e, FZ_LOG_ERROR);
     }
 }
Example #7
0
 /**
  * @param App_Model_File $file
  *
  * @return bool
  *
  * @throws App_Exception_FileIsNotWritable
  * @throws App_Exception_Forbidden
  */
 public function delete(App_Model_File $file)
 {
     if ($file->user != (string) self::$_user->id) {
         throw new App_Exception_Forbidden();
     }
     $filePath = $this->_getAbsoluteFilePath($file->identity, $file->ext);
     $res = false;
     if (file_exists($filePath)) {
         if (!is_writable($filePath)) {
             throw new App_Exception_FileIsNotWritable($filePath);
         }
         $res = (bool) unlink($filePath);
         $file->delete();
     }
     try {
         $folderRelativePath = $this->_getRelativeFolderPath($file->identity);
         $path = implode('/', [self::$_config['path'], $folderRelativePath]);
         $count = count(explode('/', $folderRelativePath));
         for ($i = $count - 1; $i > -1; $i--) {
             rmdir($path);
             $path = dirname($path);
         }
     } catch (\Exception $e) {
     }
     return $res;
 }