Example #1
0
 /**
  * Attach a file to the issue
  *
  * @param \thebuggenie\core\entities\File $file The file to attach
  */
 public function attachFile(\thebuggenie\core\entities\File $file, $file_comment = '', $file_description = '')
 {
     $existed = !tables\IssueFiles::getTable()->addByIssueIDandFileID($this->getID(), $file->getID());
     if (!$existed) {
         $comment = new \thebuggenie\core\entities\Comment();
         $comment->setPostedBy(framework\Context::getUser()->getID());
         $comment->setTargetID($this->getID());
         $comment->setTargetType(Comment::TYPE_ISSUE);
         if ($file_comment) {
             $comment->setContent(framework\Context::getI18n()->__('A file was uploaded. %link_to_file This comment was attached: %comment', array('%comment' => "\n\n" . $file_comment, '%link_to_file' => "[[File:{$file->getRealFilename()}|thumb|{$file_description}]]")));
         } else {
             $comment->setContent(framework\Context::getI18n()->__('A file was uploaded. %link_to_file', array('%link_to_file' => "[[File:{$file->getRealFilename()}|thumb|{$file_description}]]")));
         }
         $comment->save();
         if ($this->_files !== null) {
             $this->_files[$file->getID()] = $file;
         }
     }
 }
Example #2
0
 /**
  * Attach a file to the issue
  *
  * @param File $file The file to attach
  */
 public function attachFile(File $file, $file_comment = '', $file_description = '', $return_comment = false)
 {
     $existed = !tables\IssueFiles::getTable()->addByIssueIDandFileID($this->getID(), $file->getID());
     if (!$existed) {
         $comment = new Comment();
         $comment->setPostedBy(framework\Context::getUser()->getID());
         $comment->setTargetID($this->getID());
         $comment->setTargetType(Comment::TYPE_ISSUE);
         if ($file_comment) {
             $comment->setContent(framework\Context::getI18n()->__("A file was uploaded.%link_to_file \n\nThis comment was attached: %comment", array('%comment' => "\n\n" . $file_comment, '%link_to_file' => "\n\n[[File:{$file->getRealFilename()}|thumb|{$file_description}]]")));
         } else {
             $comment->setContent(framework\Context::getI18n()->__('A file was uploaded.%link_to_file', array('%link_to_file' => "\n\n[[File:{$file->getRealFilename()}|thumb|{$file_description}]]")));
         }
         $comment->save();
         if ($this->_files !== null) {
             $this->_files[$file->getID()] = $file;
         }
         $this->touch();
         if ($return_comment) {
             return $comment;
         }
     }
     if ($return_comment) {
         return null;
     }
 }
Example #3
0
 public function runGetFile(framework\Request $request)
 {
     $file = new entities\File((int) $request['id']);
     if ($file instanceof entities\File) {
         if ($file->hasAccess()) {
             $disableCache = true;
             $isFile = false;
             $this->getResponse()->cleanBuffer();
             $this->getResponse()->clearHeaders();
             $this->getResponse()->setDecoration(\thebuggenie\core\framework\Response::DECORATE_NONE);
             if ($file->isImage() && \thebuggenie\core\framework\Settings::isUploadsImageCachingEnabled()) {
                 $this->getResponse()->addHeader('Pragma: public');
                 $this->getResponse()->addHeader('Cache-Control: public, max-age: 15768000');
                 $this->getResponse()->addHeader("Expires: " . gmdate('D, d M Y H:i:s', time() + 15768000) . " GMT");
                 $disableCache = false;
             }
             $this->getResponse()->addHeader('Content-disposition: ' . ($request['mode'] == 'download' ? 'attachment' : 'inline') . '; filename="' . $file->getOriginalFilename() . '"');
             $this->getResponse()->setContentType($file->getContentType());
             if (framework\Settings::getUploadStorage() == 'files') {
                 $fh = fopen(framework\Settings::getUploadsLocalpath() . $file->getRealFilename(), 'r');
                 $isFile = true;
             } else {
                 $fh = $file->getContent();
             }
             if (is_resource($fh)) {
                 if ($isFile && \thebuggenie\core\framework\Settings::isUploadsDeliveryUseXsend()) {
                     $this->getResponse()->addHeader('X-Sendfile: ' . framework\Settings::getUploadsLocalpath() . $file->getRealFilename());
                     $this->getResponse()->addHeader('X-Accel-Redirect: /files/' . $file->getRealFilename());
                     $this->getResponse()->renderHeaders($disableCache);
                 } else {
                     $this->getResponse()->renderHeaders($disableCache);
                     fpassthru($fh);
                 }
             } else {
                 $this->getResponse()->renderHeaders($disableCache);
                 echo $fh;
             }
             exit;
         }
     }
     $this->return404(framework\Context::getI18n()->__('This file does not exist'));
 }
 public function runGetFile(framework\Request $request)
 {
     $file = new entities\File((int) $request['id']);
     if ($file instanceof entities\File) {
         if ($file->hasAccess()) {
             $this->getResponse()->cleanBuffer();
             $this->getResponse()->clearHeaders();
             $this->getResponse()->setDecoration(\thebuggenie\core\framework\Response::DECORATE_NONE);
             $this->getResponse()->addHeader('Content-disposition: ' . ($request['mode'] == 'download' ? 'attachment' : 'inline') . '; filename="' . $file->getOriginalFilename() . '"');
             $this->getResponse()->setContentType($file->getContentType());
             $this->getResponse()->renderHeaders();
             if (framework\Settings::getUploadStorage() == 'files') {
                 fpassthru(fopen(framework\Settings::getUploadsLocalpath() . $file->getRealFilename(), 'r'));
                 exit;
             } else {
                 echo $file->getContent();
                 exit;
             }
         }
     }
     $this->return404(framework\Context::getI18n()->__('This file does not exist'));
 }