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
 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.º 3
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.º 4
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.º 5
0
 public function getFileID()
 {
     return $this->file->getFileID();
 }
Ejemplo n.º 6
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;
 }