예제 #1
0
 public function testAvatar()
 {
     $type = Type::add('default', t('Default'));
     $configuration = $type->getConfigurationObject();
     $fsl = StorageLocation::add($configuration, 'Default', true);
     $service = Core::make('user.registration');
     $ui = $service->create(array('uName' => 'andrew', 'uEmail' => '*****@*****.**'));
     $this->assertFalse($ui->hasAvatar());
     $avatar = $ui->getUserAvatar();
     $this->assertInstanceOf('Concrete\\Core\\User\\Avatar\\EmptyAvatar', $avatar);
     $this->assertEquals('<img src="/path/to/server/concrete/images/avatar_none.png" alt="andrew" class="u-avatar">', $avatar->output());
     $this->assertEquals('/path/to/server/concrete/images/avatar_none.png', $avatar->getPath());
     $ui->update(array('uHasAvatar' => true));
     // This is lame, I know.
     $ui = Core::make('Concrete\\Core\\User\\UserInfoFactory')->getByID(1);
     $this->assertTrue($ui->hasAvatar());
     $avatar = $ui->getUserAvatar();
     $this->assertEquals('http://www.dummyco.com/path/to/server/application/files/avatars/1.jpg', $avatar->getPath());
     $this->assertEquals('<img src="http://www.dummyco.com/path/to/server/application/files/avatars/1.jpg" alt="andrew" class="u-avatar">', $avatar->output());
     $service = Core::make('user.avatar');
     $service->removeAvatar($ui);
     // I KNOW I KNOW This is lame
     $ui = Core::make('Concrete\\Core\\User\\UserInfoFactory')->getByID(1);
     $this->assertFalse($ui->hasAvatar());
 }
예제 #2
0
 /**
  * @return array
  */
 public function getIncomingDirectoryContents()
 {
     $incoming_file_information = array();
     $fs = StorageLocation::getDefault()->getFileSystemObject();
     $items = $fs->listContents(REL_DIR_FILES_INCOMING);
     return $items;
 }
예제 #3
0
 public function getPath()
 {
     $fsl = StorageLocation::getDefault();
     $configuration = $fsl->getConfigurationObject();
     $src = $configuration->getPublicURLToFile(REL_DIR_FILES_AVATARS . '/' . $this->userInfo->getUserID() . '.jpg');
     return $src;
 }
예제 #4
0
 /**
  * @return \Concrete\Core\File\StorageLocation\StorageLocation
  */
 protected function getStorageLocation()
 {
     $type = Type::add('local', t('Local Storage'));
     $configuration = $type->getConfigurationObject();
     $configuration->setRootPath($this->getStorageDirectory());
     $configuration->setWebRootRelativePath('/application/files');
     return StorageLocation::add($configuration, 'Default', true);
 }
예제 #5
0
 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();
     });
 }
예제 #7
0
파일: Avatar.php 프로젝트: ceko/concrete5-1
 /**
  * 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;
     }
 }
예제 #8
0
 public function submit()
 {
     if ($this->validateAction()) {
         $post = $this->request->request->all();
         $fsl = FileStorageLocation::getByID($post['fslID']);
         if (is_object($fsl)) {
             $fIDs = $post['fID'];
             if (is_array($fIDs)) {
                 foreach ($fIDs as $fID) {
                     $f = File::getByID($fID);
                     if (is_object($f)) {
                         $fp = new Permissions($f);
                         if ($fp->canEditFilePermissions()) {
                             try {
                                 $f->setFileStorageLocation($fsl);
                             } catch (\Exception $e) {
                                 $json = new \Concrete\Core\Application\EditResponse();
                                 $err = \Core::make('error');
                                 $err->add($e->getMessage());
                                 $json->setError($err);
                                 $json->outputJSON();
                             }
                         }
                     }
                 }
             }
         } else {
             $json = new \Concrete\Core\Application\EditResponse();
             $err = \Core::make('error');
             $err->add(t('Please select valid file storage location.'));
             $json->setError($err);
             $json->outputJSON();
         }
         $response = new EditResponse();
         $response->setFiles($this->files);
         $response->setMessage(t('File storage locations updated successfully.'));
         $response->outputJSON();
     }
 }
예제 #9
0
 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());
 }
예제 #10
0
</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>
예제 #11
0
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.'));
 /**
  * {@inheritDoc}
  */
 public function save()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'save', array());
     return parent::save();
 }
예제 #13
0
 /**
  * @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);
 }
예제 #14
0
 public function import_files()
 {
     $type = \Concrete\Core\File\StorageLocation\Type\Type::add('default', t('Default'));
     \Concrete\Core\File\StorageLocation\Type\Type::add('local', t('Local'));
     $configuration = $type->getConfigurationObject();
     $fsl = \Concrete\Core\File\StorageLocation\StorageLocation::add($configuration, t('Default'), true);
     $thumbnailType = new Type();
     $thumbnailType->requireType();
     $thumbnailType->setName(tc('ThumbnailTypeName', 'File Manager Thumbnails'));
     $thumbnailType->setHandle(Config::get('concrete.icons.file_manager_listing.handle'));
     $thumbnailType->setWidth(Config::get('concrete.icons.file_manager_listing.width'));
     $thumbnailType->setHeight(Config::get('concrete.icons.file_manager_listing.height'));
     $thumbnailType->save();
     $thumbnailType = new Type();
     $thumbnailType->requireType();
     $thumbnailType->setName(tc('ThumbnailTypeName', 'File Manager Detail Thumbnails'));
     $thumbnailType->setHandle(Config::get('concrete.icons.file_manager_detail.handle'));
     $thumbnailType->setWidth(Config::get('concrete.icons.file_manager_detail.width'));
     $thumbnailType->save();
     if (is_dir($this->getPackagePath() . '/files')) {
         $ch = new ContentImporter();
         $computeThumbnails = true;
         if ($this->contentProvidesFileThumbnails()) {
             $computeThumbnails = false;
         }
         $ch->importFiles($this->getPackagePath() . '/files', $computeThumbnails);
     }
 }
예제 #15
0
 public function add()
 {
     list($request, $type) = $this->validateStorageRequest();
     if (!Loader::helper('validation/token')->validate('add')) {
         $this->error->add(Loader::helper('validation/token')->getErrorMessage());
     }
     if (!$this->error->has()) {
         $configuration = $type->getConfigurationObject();
         $configuration->loadFromRequest($request);
         $fsl = FileStorageLocation::add($configuration, $request->request->get('fslName'), $request->request->get('fslIsDefault'));
         $this->redirect('/dashboard/system/files/storage', 'storage_location_added');
     }
     $this->set('type', $type);
 }
예제 #16
0
 /**
  * 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 import_files()
 {
     $type = \Concrete\Core\File\StorageLocation\Type\Type::add('default', t('Default'));
     \Concrete\Core\File\StorageLocation\Type\Type::add('local', t('Local'));
     $configuration = $type->getConfigurationObject();
     $fsl = \Concrete\Core\File\StorageLocation\StorageLocation::add($configuration, t('Default'), true);
     $thumbnailType = new Type();
     $thumbnailType->requireType();
     $thumbnailType->setName(tc('ThumbnailTypeName', 'File Manager Thumbnails'));
     $thumbnailType->setHandle(\Config::get('concrete.icons.file_manager_listing.handle'));
     $thumbnailType->setWidth(\Config::get('concrete.icons.file_manager_listing.width'));
     $thumbnailType->setHeight(\Config::get('concrete.icons.file_manager_listing.height'));
     $thumbnailType->save();
     $thumbnailType = new Type();
     $thumbnailType->requireType();
     $thumbnailType->setName(tc('ThumbnailTypeName', 'File Manager Detail Thumbnails'));
     $thumbnailType->setHandle(\Config::get('concrete.icons.file_manager_detail.handle'));
     $thumbnailType->setWidth(\Config::get('concrete.icons.file_manager_detail.width'));
     $thumbnailType->save();
     if (is_dir($this->getPackagePath() . '/files')) {
         $fh = new FileImporter();
         $contents = Loader::helper('file')->getDirectoryContents($this->getPackagePath() . '/files');
         foreach ($contents as $filename) {
             $f = $fh->import($this->getPackagePath() . '/files/' . $filename, $filename);
         }
     }
 }
예제 #18
0
 /**
  * Determine the path for a file version thumbnail based on the storage location
  *
  * @param \Concrete\Core\File\Version $file_version
  * @param \Concrete\Core\File\Image\Thumbnail\Type\Version $thumbnail
  * @param \Concrete\Core\File\StorageLocation\StorageLocation $storage
  * @param \Concrete\Core\File\StorageLocation\Configuration\ConfigurationInterface $configuration
  * @return string
  */
 protected function determinePath(Version $file_version, ThumbnailVersion $thumbnail, StorageLocation $storage, ConfigurationInterface $configuration)
 {
     $fss = $storage->getFileSystemObject();
     $path = $thumbnail->getFilePath($file_version);
     if ($fss->has($path)) {
         if ($configuration instanceof DeferredConfigurationInterface) {
             return $path;
         }
         return $configuration->getPublicURLToFile($path);
     }
     return $this->getDefaultPath($file_version, $thumbnail, $storage, $configuration);
 }
예제 #19
0
 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()));
 }
예제 #20
0
</h4>

<form method="post" data-dialog-form="file-storage" action="<?php 
echo Loader::helper('concrete/urls')->getToolsURL('files/permissions');
?>
">
<div class="help-block"><p><?php 
echo t('All versions of a file will be moved to the selected location.');
?>
</p></div>

	<?php 
$token->output('set_location_' . $f->getFileID());
echo $form->hidden('task', 'set_location');
echo $form->hidden('fID', $f->getFileID());
$locations = FileStorageLocation::getList();
foreach ($locations as $fsl) {
    ?>
    <div class="radio"><label><?php 
    echo $form->radio('fslID', $fsl->getID(), $f->getStorageLocationID() == $fsl->getID());
    ?>
 <?php 
    echo $fsl->getDisplayName();
    ?>
</label></div>
<?php 
}
?>
</form>

<div id="ccm-file-storage-buttons" style="display: none">
예제 #21
0
 /**
  * Removes the storage type if no configurations exist.
  * @throws \Exception
  * @return bool
  */
 public function delete()
 {
     $list = StorageLocation::getList();
     foreach ($list as $item) {
         if ($item->getTypeObject()->getHandle() == $this->getHandle()) {
             throw new \Exception(t('Please remove all storage locations using this storage type.'));
         }
     }
     $em = \ORM::entityManager('core');
     $em->remove($this);
     $em->flush();
     return true;
 }
예제 #22
0
 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();
 }