public function getPath() { $fsl = StorageLocation::getDefault(); $configuration = $fsl->getConfigurationObject(); $src = $configuration->getPublicURLToFile(REL_DIR_FILES_AVATARS . '/' . $this->userInfo->getUserID() . '.jpg'); return $src; }
/** * @return array */ public function getIncomingDirectoryContents() { $incoming_file_information = array(); $fs = StorageLocation::getDefault()->getFileSystemObject(); $items = $fs->listContents(REL_DIR_FILES_INCOMING); return $items; }
public static function add($filename, $prefix, $data = array(), $fsl = false, $folder = false) { $db = Loader::db(); $dh = Loader::helper('date'); $date = $dh->getOverridableNow(); if (!is_object($fsl)) { $fsl = StorageLocation::getDefault(); } $uID = 0; $u = new User(); if (isset($data['uID'])) { $uID = $data['uID']; } else { if ($u->isRegistered()) { $uID = $u->getUserID(); } } if (!$folder instanceof FileFolder) { $filesystem = new Filesystem(); $folder = $filesystem->getRootFolder(); } $f = new \Concrete\Core\Entity\File\File(); $f->storageLocation = $fsl; $f->fDateAdded = new Carbon($date); $f->folderTreeNodeID = $folder->getTreeNodeID(); $em = \ORM::entityManager(); $em->persist($f); $em->flush(); if ($uID > 0) { $ui = UserInfo::getByID($uID); if (is_object($ui)) { $ue = $ui->getEntityObject(); if (is_object($ue)) { $f->setUser($ue); } } } $node = \Concrete\Core\Tree\Node\Type\File::add($f, $folder); $fv = Version::add($f, $filename, $prefix, $data); $f->versions->add($fv); $fve = new \Concrete\Core\File\Event\FileVersion($fv); Events::dispatch('on_file_add', $fve); $entities = $u->getUserAccessEntityObjects(); $hasUploader = false; foreach ($entities as $obj) { if ($obj instanceof FileUploaderPermissionAccessEntity) { $hasUploader = true; } } if (!$hasUploader) { $u->refreshUserGroups(); } return $fv; }
public function register() { $singletons = array('helper/file' => '\\Concrete\\Core\\File\\Service\\File', 'helper/concrete/file' => '\\Concrete\\Core\\File\\Service\\Application', 'helper/image' => '\\Concrete\\Core\\File\\Image\\BasicThumbnailer', 'helper/mime' => '\\Concrete\\Core\\File\\Service\\Mime', 'helper/zip' => '\\Concrete\\Core\\File\\Service\\Zip'); foreach ($singletons as $key => $value) { $this->app->singleton($key, $value); } $this->app->bind('image/imagick', '\\Imagine\\Imagick\\Imagine'); $this->app->bind('image/gd', '\\Imagine\\Gd\\Imagine'); $this->app->bind('image/thumbnailer', '\\Concrete\\Core\\File\\Image\\BasicThumbnailer'); $this->app->bind(StorageLocationInterface::class, function ($app) { return StorageLocation::getDefault(); }); }
public function testGetByDefault() { $this->getStorageLocation(); $type = Type::getByHandle('local'); $configuration = $type->getConfigurationObject(); StorageLocation::add($configuration, 'Other Storage'); $location = StorageLocation::getDefault(); $this->assertInstanceOf('\\Concrete\\Core\\File\\StorageLocation\\StorageLocation', $location); $this->assertEquals(true, $location->isDefault()); $this->assertEquals('Default', $location->getName()); $alternate = StorageLocation::getByID(2); $this->assertInstanceOf('\\Concrete\\Core\\File\\StorageLocation\\StorageLocation', $alternate); $this->assertEquals(false, $alternate->isDefault()); $this->assertEquals('Other Storage', $alternate->getName()); }
/** * gets the image path for a users avatar * @param \UserInfo $uo * @param bool $withNoCacheStr * @return bool|string $src */ public function getImagePath($uo, $withNoCacheStr = true) { if (!$uo->hasAvatar()) { return false; } $fsl = StorageLocation::getDefault(); $fs = $fsl->getFileSystemObject(); if ($fs->has(REL_DIR_FILES_AVATARS . '/' . $uo->getUserID() . '.jpg')) { $configuration = $fsl->getConfigurationObject(); $src = $configuration->getPublicURLToFile(REL_DIR_FILES_AVATARS . '/' . $uo->getUserID() . '.jpg'); $cacheStr = "?" . time(); if ($withNoCacheStr) { $src .= $cacheStr; } return $src; } }
public function updateUserAvatar(ImageInterface $image) { $fsl = StorageLocation::getDefault()->getFileSystemObject(); $image = $image->get('jpg'); $file = REL_DIR_FILES_AVATARS . '/' . $this->getUserID() . '.jpg'; if ($fsl->has($file)) { $fsl->delete($file); } $fsl->write($file, $image, array('visibility' => AdapterInterface::VISIBILITY_PUBLIC, 'mimetype' => 'image/jpeg')); $db = Loader::db(); $db->query("update Users set uHasAvatar = 1 where uID = ?", array($this->getUserID())); }
if ($valt->validate('import_incoming')) { if (!empty($_POST)) { $fi = new FileImporter(); foreach ($_POST as $k => $name) { if (preg_match("#^send_file#", $k)) { if (!$fp->canAddFileType($cf->getExtension($name))) { $resp = FileImporter::E_FILE_INVALID_EXTENSION; } else { $resp = $fi->importIncomingFile($name); } if (!$resp instanceof \Concrete\Core\File\Version) { $error->add($name . ': ' . FileImporter::getErrorMessage($resp)); } else { $files[] = $resp; if ($_POST['removeFilesAfterPost'] == 1) { $fsl = \Concrete\Core\File\StorageLocation\StorageLocation::getDefault()->getFileSystemObject(); $fsl->delete(REL_DIR_FILES_INCOMING . '/' . $name); } if (!is_object($fr)) { // we check $fr because we don't want to set it if we are replacing an existing file $respf = $resp->getFile(); $respf->setOriginalPage($_POST['ocID']); } else { $respf = $fr; } } } } } if (count($files) == 0) { $error->add(t('You must select at least one file.'));
</form> <?php } else { ?> <br/><br/> <?php if ($error) { ?> <div class="alert alert-danger"> <?php echo $error; ?> </div> <?php } else { echo t('No files found in %s for the storage location "%s".', REL_DIR_FILES_INCOMING, StorageLocation::getDefault()->getName()); } } ?> </div> <div id="dialog-buttons-local" style="display: none"> <button class="btn btn-default" onclick="jQuery.fn.dialog.closeTop()"><?php echo t("Close"); ?> </button> <button class="btn btn-success pull-right" data-button="launch-upload-complete" onclick="ConcreteFileImportDialog.loadDropzoneFiles()" disabled><?php echo t("View Uploaded"); ?> </button> </div>
/** * @param ImageInterface $image */ public function updateUserAvatar(ImageInterface $image) { $fsl = StorageLocation::getDefault()->getFileSystemObject(); $image = $image->get('jpg'); $file = REL_DIR_FILES_AVATARS . '/' . $this->getUserID() . '.jpg'; if ($fsl->has($file)) { $fsl->delete($file); } $fsl->write($file, $image, array('visibility' => AdapterInterface::VISIBILITY_PUBLIC, 'mimetype' => 'image/jpeg')); $db = $this->connection; $db->query("update Users set uHasAvatar = 1 where uID = ?", array($this->getUserID())); // run any internal event we have for user update $ui = self::getByID($this->uID); $ue = new \Concrete\Core\User\Event\UserInfo($ui); Events::dispatch('on_user_update', $ue); }
/** * Imports a file in the default file storage location's incoming directory. * * @param string $filename * @param ConcreteFile|bool $fr * * @return number Error Code | \Concrete\Core\File\Version */ public function importIncomingFile($filename, $fr = false) { $fh = Loader::helper('validation/file'); $fi = Loader::helper('file'); $cf = Core::make('helper/concrete/file'); $sanitizedFilename = $fi->sanitize($filename); $default = StorageLocation::getDefault(); $storage = $default->getFileSystemObject(); if (!$storage->has(REL_DIR_FILES_INCOMING . '/' . $filename)) { return Importer::E_FILE_INVALID; } if (!$fh->extension($filename)) { return Importer::E_FILE_INVALID_EXTENSION; } // first we import the file into the storage location that is the same. $prefix = $this->generatePrefix(); try { $copied = $storage->copy(REL_DIR_FILES_INCOMING . '/' . $filename, $cf->prefix($prefix, $sanitizedFilename)); } catch (\Exception $e) { $copied = false; } if (!$copied) { $storage->write($cf->prefix($prefix, $sanitizedFilename), $storage->read(REL_DIR_FILES_INCOMING . '/' . $filename)); } if (!$fr instanceof File) { // we have to create a new file object for this file version $fv = ConcreteFile::add($sanitizedFilename, $prefix, array('fvTitle' => $filename), $default); $fv->refreshAttributes($this->rescanThumbnailsOnImport); $fr = $fv->getFile(); } else { // We get a new version to modify $fv = $fr->getVersionToModify(true); $fv->updateFile($sanitizedFilename, $prefix); $fv->refreshAttributes($this->rescanThumbnailsOnImport); } return $fv; }
public function save() { $default = \Concrete\Core\File\StorageLocation\StorageLocation::getDefault(); $em = \ORM::entityManager(); $em->persist($this); if ($this->isDefault() && is_object($default) && $default->getID() != $this->getID()) { $default->setIsDefault(false); $em->persist($default); } $em->flush(); }