Beispiel #1
0
function media_file_image_tag(DmMedia $file, $options = array()) {
  $options = array_merge(array(
              'width' => $file->isImage() ? 128 : 64,
              'height' => $file->isImage() ? 98 : 64
          ), dmString::toArray($options, true));

  if ($file->isImage()) {
    $image = _media($file);
  } else {
    if (file_exists(
            dmOs::join(
                    sfConfig::get('sf_web_dir')
                    .
                    '/dmCorePlugin/images/media/'
                    .
                    dmOs::getFileExtension($file->getFile(), false)
                    . '.png'
            )
    )) {
      $image = _media('/dmCorePlugin/images/media/' . dmOs::getFileExtension($file->getFile(), false) . '.png');
    } else {
      $image = _media('/dmCorePlugin/images/media/unknown.png');
    }
  }

  return $image->size($options['width'], $options['height']);
}
Beispiel #2
0
 public function executeDownload(dmWebRequest $request)
 {
     $this->forward404Unless($versionNumber = $request->getParameter('v'));
     $this->forward404Unless($version = dmDb::table('Version')->findOneByNumber($versionNumber));
     $this->forward404Unless($package = $version->Package);
     $this->forward404Unless($package->exists());
     $fileName = sprintf('diem-%s%s', $version->number, dmOs::getFileExtension($package->fullPath));
     $this->getService('event_log')->setOption('enabled', false);
     $version->mapValue('disable_versioning', true);
     $version->downloads = $version->downloads + 1;
     $version->save();
     $this->context->getEventDispatcher()->notify(new sfEvent($this, 'download.package', array('version' => $version->number)));
     return $this->download($package->fullPath, array('file_name' => $fileName));
 }
Beispiel #3
0
 public function openDir($dir)
 {
     $dir = $this->decodePath($dir);
     $this->validateOpenDir($dir);
     $content = array();
     $children = sfFinder::type('dir')->maxdepth(0)->not_name("/^\\..*/")->follow_link()->in($dir);
     natcasesort($children);
     foreach ($children as $child) {
         $isReadable = is_readable($child);
         $isWritable = is_writable($child);
         $content[] = array('attributes' => array('id' => $this->encodePath($child), 'class' => sprintf('dir %s %s', $isReadable ? 'readable_dir' : 'not_readable_dir', $isWritable ? 'writable_dir' : 'not_writable_dir'), 'rel' => 'folder'), 'state' => $isReadable ? 'closed' : '', 'data' => basename($child));
     }
     $files = sfFinder::type('file')->maxdepth(0)->not_name("/^\\..*/")->follow_link()->in($dir);
     natcasesort($files);
     foreach ($files as $file) {
         $content[] = array('attributes' => array('id' => $this->encodePath($file), 'class' => sprintf('file file_%s%s%s', strtolower(dmOs::getFileExtension($file, false)), is_readable($file) ? ' readable_file' : '', is_writable($file) ? ' writable_file' : ''), 'rel' => 'file'), 'data' => basename($file));
     }
     return $content;
 }
Beispiel #4
0
 public function executeSave(dmWebRequest $request)
 {
     $file = dmProject::rootify($request->getParameter('file'));
     $this->forward404Unless(file_exists($file), $file . ' does not exists');
     try {
         @$this->getService('file_backup')->save($file);
     } catch (dmException $e) {
         return $this->renderJson(array('type' => 'error', 'message' => 'backup failed : ' . $e->getMessage()));
     }
     @file_put_contents($file, $request->getParameter('code'));
     if (dmOs::getFileExtension($file, false) == 'css') {
         $return = array('type' => 'css', 'path' => $this->getHelper()->getStylesheetWebPath(dmOs::getFileWithoutExtension($file)));
     } else {
         $this->getService('cache_cleaner')->clearTemplate();
         $return = array('type' => 'php', 'widgets' => $this->getWidgetInnersForFile($file));
     }
     $return['message'] = $this->getI18n()->__('Your modifications have been saved');
     return $this->renderJson($return);
 }
Beispiel #5
0
 /**
  * Physically creates asset
  *
  * @param string $asset_path path to the asset original file
  * @param bool $move do move or just copy ?
  */
 public function create(sfValidatedFile $file)
 {
     $this->file = $this->getAvailableFileName(dmString::slugify(dmOs::getFileWithoutExtension($file->getOriginalName())) . dmOs::getFileExtension($file->getOriginalName(), true));
     $this->clearCache();
     $file->save($this->getFullPath());
     $this->refreshFromFile();
     return $this;
 }