Ejemplo n.º 1
0
 public static function add(FileEntity $f, FileSet $fs)
 {
     $db = Loader::db();
     $fsDisplayOrder = $db->GetOne('SELECT count(fID) FROM FileSetFiles WHERE fsID = ?', array($fs->getFileSetID()));
     $db->insert('FileSetFiles', array('fsID' => $fs->getFileSetID(), 'timestamp' => date('Y-m-d H:i:s'), 'fID' => $f->getFileID(), 'fsDisplayOrder' => $fsDisplayOrder));
     $fsfID = $db->lastInsertId();
     return self::getByID($fsfID);
 }
Ejemplo n.º 2
0
 /**
  * @param File $f
  */
 public function setPermissionObject($f)
 {
     $this->permissionObject = $f;
     if ($f->overrideFileFolderPermissions()) {
         $this->permissionObjectToCheck = $f;
     } else {
         $this->permissionObjectToCheck = $f->getFileFolderObject();
     }
 }
Ejemplo n.º 3
0
 public function approve()
 {
     foreach ($this->file->getFileVersions() as $fv) {
         $fv->fvIsApproved = false;
         $fv->save(false);
     }
     $this->fvIsApproved = true;
     $uID = (int) (new User())->getUserID();
     if ($uID !== 0) {
         $this->fvApproverUID = $uID;
     }
     $this->save();
     $fe = new \Concrete\Core\File\Event\FileVersion($this);
     Events::dispatch('on_file_version_approve', $fe);
     $fo = $this->getFile();
     $fo->reindex();
     \Core::make('cache/request')->delete('file/version/approved/' . $this->getFileID());
 }
Ejemplo n.º 4
0
 public function setTreeNodeFile(\Concrete\Core\Entity\File\File $file)
 {
     $db = Loader::db();
     $db->Replace('TreeFileNodes', array('treeNodeID' => $this->getTreeNodeID(), 'fID' => $file->getFileID()), array('treeNodeID'), true);
     $this->fID = $file->getFileID();
 }
Ejemplo n.º 5
0
 /**
  * Returns a path to the specified item, resized and/or cropped to meet max width and height. $obj can either be
  * a string (path) or a file object.
  * Returns an object with the following properties: src, width, height
  *
  * @param File|string $obj
  * @param int $maxWidth
  * @param int $maxHeight
  * @param bool $crop
  * @return \stdClass Object that has the following properties: src, width, height
  */
 public function getThumbnail($obj, $maxWidth, $maxHeight, $crop = false)
 {
     $storage = $this->getStorageLocation();
     $filesystem = $storage->getFileSystemObject();
     $configuration = $storage->getConfigurationObject();
     $fh = \Core::make('helper/file');
     if ($obj instanceof File) {
         try {
             $fr = $obj->getFileResource();
             $fID = $obj->getFileID();
             $filename = md5(implode(':', array($fID, $maxWidth, $maxHeight, $crop, $fr->getTimestamp()))) . '.' . $fh->getExtension($fr->getPath());
         } catch (\Exception $e) {
             $filename = '';
         }
     } else {
         $filename = md5(implode(':', array($obj, $maxWidth, $maxHeight, $crop, filemtime($obj)))) . '.' . $fh->getExtension($obj);
     }
     $abspath = '/cache/' . $filename;
     if (!$filesystem->has($abspath)) {
         if ($obj instanceof File && $fr->exists()) {
             $image = \Image::load($fr->read());
         } else {
             $image = \Image::open($obj);
         }
         // create image there
         $this->create($image, $abspath, $maxWidth, $maxHeight, $crop);
     }
     $src = $configuration->getPublicURLToFile($abspath);
     $thumb = new \stdClass();
     $thumb->src = $src;
     //this is terrible
     try {
         //try and get it locally, otherwise use http
         $dimensions = getimagesize($abspath);
     } catch (\Exception $e) {
         //$dimensions = getimagesize($src);
     }
     $thumb->width = $dimensions[0];
     $thumb->height = $dimensions[1];
     return $thumb;
 }
Ejemplo n.º 6
0
 public function __construct(FileEntity $file)
 {
     parent::__construct();
     $this->setAttribute('data-search-file-menu', $file->getFileID());
     $this->addItem(new LinkItem('#', t('Clear'), ['data-file-manager-action' => 'clear']));
     $this->addItem(new DividerItem());
     $fp = new \Permissions($file);
     if ($fp->canViewFile() && $file->canView()) {
         $this->addItem(new DialogLinkItem(REL_DIR_FILES_TOOLS_REQUIRED . '/files/view?fID=' . $file->getFileID(), t('View'), t('View'), '90%', '75%'));
     }
     if ($fp->canViewFile() && $file->canView()) {
         $this->addItem(new LinkItem('#', t('Download'), ['data-file-manager-action' => 'download', 'data-file-id' => $file->getFileID()]));
     }
     if ($file->canEdit() && $fp->canEditFileContents()) {
         $this->addItem(new DialogLinkItem(REL_DIR_FILES_TOOLS_REQUIRED . '/files/edit?fID=' . $file->getFileID(), t('Edit'), t('Edit'), '90%', '75%'));
         $this->addItem(new DialogLinkItem(\URL::to('/ccm/system/dialogs/file/thumbnails?fID=' . $file->getFileID()), t('Thumbnails'), t('Thumbnails'), '90%', '75%'));
     }
     if ($fp->canViewFileInFileManager()) {
         $this->addItem(new DialogLinkItem(\URL::to('/ccm/system/dialogs/file/properties?fID=' . $file->getFileID()), t('Properties'), t('Properties'), '850', '450'));
     }
     if ($fp->canEditFileContents()) {
         $this->addItem(new DialogLinkItem(REL_DIR_FILES_TOOLS_REQUIRED . '/files/replace?fID=' . $file->getFileID(), t('Replace'), t('Replace'), '500', '200'));
     }
     if ($fp->canCopyFile()) {
         $this->addItem(new LinkItem('#', t('Duplicate'), ['data-file-manager-action' => 'duplicate', 'data-file-id' => $file->getFileID()]));
     }
     if ($fp->canViewFileInFileManager()) {
         $this->addItem(new DialogLinkItem(\URL::to('/ccm/system/dialogs/file/sets?fID=' . $file->getFileID()), t('Sets'), t('File Sets'), '500', '400'));
     }
     if ($fp->canEditFilePermissions() || $fp->canDeleteFile()) {
         $this->addItem(new DividerItem());
     }
     if ($fp->canEditFilePermissions()) {
         $this->addItem(new DialogLinkItem(REL_DIR_FILES_TOOLS_REQUIRED . '/files/permissions?fID=' . $file->getFileID(), t('Permissions'), t('Permissions & Access'), '520', '450'));
     }
     $this->addItem(new DialogLinkItem(\URL::to('/ccm/system/dialogs/file/usage', $file->getFileID()), t('File Usage'), t('File Usage'), '90%', '75%'));
     if ($fp->canDeleteFile()) {
         $this->addItem(new DeleteItem($file->getFileNodeObject()));
     }
 }
Ejemplo n.º 7
0
 /**
  * @param \Concrete\Core\Entity\File\File $file
  * @param null|int $rcID
  */
 protected function download(\Concrete\Core\Entity\File\File $file, $rcID = null)
 {
     $filename = $file->getFilename();
     $file->trackDownload($rcID);
     $fsl = $file->getFileStorageLocationObject();
     $configuration = $fsl->getConfigurationObject();
     $fv = $file->getVersion();
     if ($configuration->hasPublicURL()) {
         return \Redirect::url($fv->getURL())->send();
     } else {
         return $fv->forceDownload();
     }
 }
Ejemplo n.º 8
0
 /**
  * Returns a path to the specified item, resized and/or cropped to meet max width and height. $obj can either be
  * a string (path) or a file object.
  * Returns an object with the following properties: src, width, height
  *
  * @param File|string $obj
  * @param int $maxWidth
  * @param int $maxHeight
  * @param bool $crop
  * @return \stdClass Object that has the following properties: src, width, height
  */
 public function getThumbnail($obj, $maxWidth, $maxHeight, $crop = false)
 {
     $storage = $this->getStorageLocation();
     $filesystem = $storage->getFileSystemObject();
     $configuration = $storage->getConfigurationObject();
     $fh = \Core::make('helper/file');
     if ($obj instanceof File) {
         try {
             $fr = $obj->getFileResource();
             $fID = $obj->getFileID();
             $filename = md5(implode(':', array($fID, $maxWidth, $maxHeight, $crop, $fr->getTimestamp()))) . '.' . $fh->getExtension($fr->getPath());
         } catch (\Exception $e) {
             $filename = '';
         }
     } else {
         $filename = md5(implode(':', array($obj, $maxWidth, $maxHeight, $crop, filemtime($obj)))) . '.' . $fh->getExtension($obj);
     }
     $abspath = '/cache/' . $filename;
     if (!$filesystem->has($abspath)) {
         if ($obj instanceof File && $fr->exists()) {
             $image = \Image::load($fr->read());
         } else {
             $image = \Image::open($obj);
         }
         // create image there
         $this->create($image, $abspath, $maxWidth, $maxHeight, $crop);
     }
     $src = $configuration->getPublicURLToFile($abspath);
     $thumb = new \stdClass();
     $thumb->src = $src;
     // this is a hack, but we shouldn't go out on the network if we don't have to. We should probably
     // add a method to the configuration to handle this. The file storage locations should be able to handle
     // thumbnails.
     if ($configuration instanceof DefaultConfiguration) {
         $dimensionsPath = $configuration->getRootPath() . $abspath;
     } else {
         $dimensionsPath = $src;
     }
     try {
         //try and get it locally, otherwise use http
         $dimensions = getimagesize($dimensionsPath);
         $thumb->width = $dimensions[0];
         $thumb->height = $dimensions[1];
     } catch (\Exception $e) {
     }
     return $thumb;
 }
Ejemplo n.º 9
0
 /**
  * Add attachment to send with an email.
  *
  * Sample Code:
  * $attachment = $mailHelper->addAttachment($fileObject);
  * $attachment->filename = "CustomFilename";
  * $mailHelper->send();
  *
  * @param \Concrete\Core\Entity\File\File $fob File to attach
  *
  * @return \StdClass Pointer to the attachment
  *
  * @throws \Exception
  */
 public function addAttachment(\Concrete\Core\Entity\File\File $fob)
 {
     // Get file version.
     $fv = $fob->getVersion();
     // Get file data.
     $mimetype = $fv->getMimeType();
     $filename = $fv->getFilename();
     $resource = $fob->getFileResource();
     $content = $resource->read();
     // Create attachment.
     $mp = new MimePart($content);
     $mp->type = $mimetype;
     $mp->disposition = Mime::DISPOSITION_ATTACHMENT;
     $mp->encoding = Mime::ENCODING_BASE64;
     $mp->filename = $filename;
     // Add mimepart to attachments.
     $this->attachments[] = $mp;
 }