/**
  * Generates asset thumbnails.
  *
  * @return bool, false if thumbnails are not supported.
  */
 public function generateThumbnails()
 {
     if (!$this->supportsThumbnails()) {
         return false;
     }
     $tn = new lyMediaThumbnails($this->getPath(), in_array($this->getType(), array('image/png', 'image/gif')) ? $this->getType() : 'image/jpeg', $this->getThumbnailFile(null));
     $tn->generate();
     return true;
 }
 /**
  * Generates asset thumbnails.
  *
  * @return bool, false if thumbnails are not supported.
  */
 public function generateThumbnails()
 {
     if (!$this->supportsThumbnails()) {
         return false;
     }
     $tn = new lyMediaThumbnails($this->getFolderPath(), $this->getFilename());
     $tn->generate();
     return true;
 }
 /**
  * Checks if asset file and thumbnails exist in filesystem.
  *
  * @param string $folder asset folder (relative path)
  * @param string $file asset filename
  * @param boolean $check_thumbs check existence/non-existence of thumbnail files
  * @param boolean $exist true=must exist, false=must not exist
  * 
  * @return lyMediaTestFunctional current lyMediaTestFunctional instance
  */
 protected function checkFile($folder, $file, $check_thumbs = true, $exist = true)
 {
     $fs = new lyMediaFileSystem();
     $this->test()->is($fs->is_file($folder . $file), $exist, 'File ' . $folder . $file . ($exist ? ' has ' : ' has not ') . 'been found');
     if ($check_thumbs) {
         $tn = new lyMediaThumbnails($folder, $file);
         foreach ($tn->getThumbnailPaths() as $file_path) {
             $this->test()->is($fs->is_file($file_path), $exist, 'Thumbnail ' . basename($file_path) . ($exist ? ' has ' : ' has not ') . 'been found');
         }
     }
     return $this;
 }
 /**
  * Checks if asset file and asset thumbnails (if supported) exist in filesystem.
  *
  * @param lyMediaAsset $asset
  * @param boolean $exist true=must exist, false=must not exist
  * 
  * @return lyMediaTestFunctional current lyMediaTestFunctional instance
  */
 protected function checkFile($asset, $exist = true)
 {
     $fs = new lyMediaFileSystem();
     $file_path = $asset->getPath();
     $this->test()->is($fs->is_file($file_path), $exist, 'File ' . $file_path . ($exist ? ' has ' : ' has not ') . 'been found');
     if ($asset->supportsThumbnails()) {
         $tn = new lyMediaThumbnails($file_path, in_array($asset->getType(), array('image/png', 'image/gif')) ? $asset->getType() : 'image/jpeg', $asset->getThumbnailFile(null));
         foreach ($tn->getThumbnailPaths() as $file_path) {
             $this->test()->is($fs->is_file($file_path), $exist, 'Thumbnail ' . basename($file_path) . ($exist ? ' has ' : ' has not ') . 'been found');
         }
     }
     return $this;
 }
function thumbnail_uri($asset, $folder_path = null, $type = 'small')
{
    if ($asset->supportsThumbnails()) {
        $uri = '/' . (isset($folder_path) ? $folder_path : $asset->getFolderPath()) . lyMediaThumbnails::getThumbnailFolder() . '/' . $asset->getThumbnailFile($type);
    } else {
        $uri = '/lyMediaManagerPlugin/images/' . $asset->getThumbnailFile($type);
    }
    return $uri;
}
 public function setup()
 {
     parent::setup();
     unset($this['title'], $this['description'], $this['relative_path'], $this['lft'], $this['rgt'], $this['level'], $this['created_at'], $this['updated_at']);
     $this->widgetSchema['parent_id'] = new sfWidgetFormInputHidden();
     $this->validatorSchema['parent_id'] = new sfValidatorInteger();
     $this->widgetSchema['name']->setAttribute('size', 10);
     $this->widgetSchema['name']->setLabel('Add subfolder');
     $this->validatorSchema['name'] = new sfValidatorRegex(array('required' => true, 'must_match' => false, 'pattern' => '#^' . lyMediaThumbnails::getThumbnailFolder() . '$|[^a-z0-9-_]#i'));
     $this->validatorSchema->setPostValidator(new lyMediaValidatorFolder());
 }
 public function setup()
 {
     parent::setup();
     unset($this['relative_path'], $this['lft'], $this['rgt'], $this['level'], $this['created_at'], $this['updated_at']);
     $query = Doctrine_Query::create()->from('lyMediaFolder f');
     if (!$this->isNew()) {
         $query->where('f.lft < ? OR f.rgt > ?', array($this->getObject()->getLft(), $this->getObject()->getRgt()));
     }
     $this->widgetSchema['parent_id'] = new sfWidgetFormDoctrineChoice(array('model' => 'lyMediaManagerFolder', 'order_by' => array('lft', ''), 'method' => 'getIndentName', 'query' => $query));
     if ($this->isNew()) {
         if ($user = $this->getOption('user')) {
             if ($user->getAttribute('view') == 'icons' && $user->getAttribute('folder_id')) {
                 $this->setDefault('parent_id', $user->getAttribute('folder_id'));
             }
         }
     } else {
         $this->widgetSchema['parent_id']->setOption('add_empty', 'Move to ...');
     }
     $this->validatorSchema['parent_id'] = new sfValidatorDoctrineChoice(array('required' => $this->isNew(), 'model' => 'lyMediaFolder'));
     $this->validatorSchema['name'] = new sfValidatorRegex(array('required' => true, 'must_match' => false, 'pattern' => '#^' . lyMediaThumbnails::getThumbnailFolder() . '$|[^a-z0-9-_]#i'));
     $this->validatorSchema->setPostValidator(new lyMediaValidatorFolder());
 }
예제 #8
0
<div class="lymedia_asset">
  <div class="lymedia_asset_frame">
    <?php 
if ($popup) {
    ?>
    <div class="lymedia_popup_info">
      <span>
        <?php 
    echo image_path('/' . $asset->getPath());
    ?>
      </span>
      <?php 
    foreach (lyMediaThumbnails::getThumbnailSettings() as $type => $params) {
        ?>
        <span class="<?php 
        echo $type;
        ?>
">
          <?php 
        echo thumbnail_image_path($asset, $folder->getRelativePath(), $type);
        ?>
        </span>
      <?php 
    }
    ?>
    </div>
    <?php 
}
?>
    <?php 
echo thumbnail_image_tag($asset, $folder->getRelativePath(), 'small', 'alt=asset title=' . $asset->getTitle());
 /**
  * Returns thumbnail types from plugin configuration.
  * 
  * @return array
  */
 protected function getThumbnailTypes()
 {
     return array_keys(lyMediaThumbnails::getThumbnailSettings());
 }
 /**
  * Used by synchronize task.
  *
  * @param string $baseFolder
  * @param bool $verbose
  * @param bool $removeOrphanAssets
  * @param bool $removeOrphanFolders
  */
 public function synchronizeWith($baseFolder, $verbose = true, $removeOrphanAssets = false, $removeOrphanFolders = false)
 {
     if (!is_dir($baseFolder)) {
         throw new lyMediaException(sprintf('%s is not a directory', $baseFolder));
     }
     $files = sfFinder::type('file')->maxdepth(0)->ignore_version_control()->in($baseFolder);
     $assets = $this->getAssetsWithFilenames();
     $fs = new lyMediaFileSystem();
     foreach ($files as $file) {
         $basename = basename($file);
         if (!array_key_exists($basename, $assets)) {
             // File exists, asset does not exist: create asset
             $fs->import($file, $this->getRelativePath() . $basename);
             $lyMediaAsset = new lyMediaAsset();
             $lyMediaAsset->setFolderId($this->getId());
             $lyMediaAsset->setFilename($basename);
             $lyMediaAsset->setType(mime_content_type($file));
             $lyMediaAsset->setFilesize(round(filesize($file) / 1024));
             $lyMediaAsset->save();
             if ($verbose) {
                 lyMediaTools::log(sprintf("Importing file %s", $file), 'green');
             }
         } else {
             // File exists, asset exists: do nothing
             unset($assets[basename($file)]);
         }
     }
     foreach ($assets as $name => $asset) {
         if ($removeOrphanAssets) {
             // File does not exist, asset exists: delete asset
             $asset->delete();
             if ($verbose) {
                 lyMediaTools::log(sprintf("Deleting asset %s", $asset->getPath()), 'yellow');
             }
         } else {
             if ($verbose) {
                 lyMediaTools::log(sprintf("Warning: No file for asset %s", $asset->getPath()), 'red');
             }
         }
     }
     $dirs = sfFinder::type('dir')->maxdepth(0)->discard(lyMediaThumbnails::getThumbnailFolder())->ignore_version_control()->in($baseFolder);
     $folders = $this->getSubfoldersWithFolderNames();
     foreach ($dirs as $dir) {
         list(, $name) = lyMediaTools::splitPath($dir);
         if (!array_key_exists($name, $folders)) {
             // dir exists in filesystem, not in database: create folder in database
             $lyMediaFolder = new lyMediaFolder();
             $lyMediaFolder->setName($name);
             $lyMediaFolder->create($this);
             if ($verbose) {
                 lyMediaTools::log(sprintf("Importing directory %s", $dir), 'green');
             }
         } else {
             // dir exists in filesystem and database: look inside
             $lyMediaFolder = $folders[$name];
             unset($folders[$name]);
         }
         $lyMediaFolder->synchronizeWith($dir, $verbose, $removeOrphanAssets, $removeOrphanFolders);
     }
     foreach ($folders as $name => $folder) {
         if ($removeOrphanFolders) {
             $folder->delete(null, true);
             if ($verbose) {
                 lyMediaTools::log(sprintf("Deleting folder %s", $folder->getRelativePath()), 'yellow');
             }
         } else {
             if ($verbose) {
                 lyMediaTools::log(sprintf("Warning: No directory for folder %s", $folder->getRelativePath()), 'red');
             }
         }
     }
 }