コード例 #1
0
 public static function getPathFromWebDir($type, $asset)
 {
     $package = substr($asset, 0, strpos($asset, '.'));
     if (in_array($package, array('core', 'lib', 'front', 'admin'))) {
         $name = substr($asset, strpos($asset, '.') + 1);
     } else {
         $name = $asset;
     }
     switch ($type) {
         case 'js':
             switch ($package) {
                 case 'core':
                     $path = '/' . sfConfig::get('dm_core_asset') . '/js/' . $name . '.js';
                     break;
                 case 'lib':
                     $path = '/' . sfConfig::get('dm_core_asset') . '/lib/' . $name . '.js';
                     break;
                 case 'front':
                     $path = '/' . sfConfig::get('dm_front_asset') . '/js/' . $name . '.js';
                     break;
                 case 'admin':
                     $path = '/' . sfConfig::get('dm_admin_asset') . '/js/' . $name . '.js';
                     break;
                 default:
                     $path = '/' . dmString::str_replace_once('.', '/' . $type . '/', $asset) . '.js';
             }
             break;
         case 'css':
             switch ($package) {
                 case 'core':
                     $path = '/' . sfConfig::get('dm_core_asset') . '/css/' . $name . '.css';
                     break;
                 case 'lib':
                     $path = '/' . sfConfig::get('dm_core_asset') . '/lib/' . $name . '.css';
                     break;
                 case 'front':
                     $path = '/' . sfConfig::get('dm_front_asset') . '/css/' . $name . '.css';
                     break;
                 case 'admin':
                     $path = '/' . sfConfig::get('dm_admin_asset') . '/css/' . $name . '.css';
                     break;
                 default:
                     $path = '/' . dmString::str_replace_once('.', '/' . $type . '/', $asset) . '.css';
             }
             break;
         default:
             $path = '/' . dmString::str_replace_once('.', '/', $asset);
     }
     if (!isset($path)) {
         throw new dmException("Can not find path for asset {$type}.{$package}.{$asset}");
     }
     return $path;
 }
コード例 #2
0
 protected function formatGeshiCode(array $matches)
 {
     $code = $matches[2];
     $language = $matches[1];
     $cacheKey = md5($code . $language);
     if ($this->getOption('use_cache') && ($cache = $this->cacheManager->getCache('markdown')->get($cacheKey))) {
         return $cache;
     }
     $code = html_entity_decode($code);
     require_once dmOs::join(sfConfig::get('sf_lib_dir'), 'vendor/geshi/geshi.php');
     $geshi = new GeSHi($code, $language);
     $geshi->enable_classes();
     $html = $geshi->parse_code();
     $html = dmString::str_replace_once('> ', '>', $html);
     $html = dmString::str_replace_once("\n<span class=\"kw2\">&lt;?php</span>", '', $html);
     $html = dmString::str_replace_once("\n", '', $html);
     $html = dmString::str_replace_once('  ', '', $html);
     if ($this->getOption('use_cache')) {
         $this->cacheManager->getCache('markdown')->set($cacheKey, $html);
     }
     return $html;
 }
コード例 #3
0
 /**
  * Move into another folder
  *
  * @param DmMediaFolder $folder
  */
 public function move(DmMediaFolder $folder)
 {
     if ($folder->id == $this->nodeParentId) {
         return $this;
     }
     if ($folder->getNode()->isDescendantOfOrEqualTo($this)) {
         throw new dmException('Can not move to a descendant');
     }
     if ($this->getNode()->isRoot()) {
         throw new dmException('The root folder cannot be moved');
     }
     if (!$this->isWritable()) {
         throw new dmException(sprintf('The folder %s is not writable.', dmProject::unRootify($this->fullPath)));
     }
     if (!$folder->isWritable()) {
         throw new dmException(sprintf('The folder %s is not writable.', dmProject::unRootify($folder->fullPath)));
     }
     if ($folder->hasSubFolder($this->name)) {
         throw new dmException(sprintf('The selected folder already contains a folder named "%s".', $this->name));
     }
     $oldRelPath = $this->get('rel_path');
     $newRelPath = $folder->get('rel_path') . '/' . $this->name;
     $fs = $this->getService('filesystem');
     $oldFullPath = $this->getFullPath();
     $newFullPath = dmOs::join($folder->getFullPath(), $this->name);
     if (!rename($oldFullPath, $newFullPath)) {
         throw new dmException('Can not move %s to %s', dmProject::unRootify($oldFullPath), dmProject::unRootify($newFullPath));
     }
     $this->set('rel_path', $newRelPath);
     $this->clearCache();
     $this->getNode()->moveAsFirstChildOf($folder);
     //update descendants
     if ($descendants = $this->getNode()->getDescendants()) {
         foreach ($descendants as $folder) {
             $folder->set('rel_path', dmString::str_replace_once($oldRelPath, $newRelPath, $folder->get('rel_path')));
             $folder->save();
         }
     }
     return $this;
 }
コード例 #4
0
 public static function getPathFromWebDir($type, $asset)
 {
     $package = substr($asset, 0, strpos($asset, '.'));
     if (in_array($package, array('core', 'lib', 'front', 'admin'))) {
         $name = substr($asset, strpos($asset, '.') + 1);
     } else {
         $name = $asset;
     }
     switch ($type) {
         case 'js':
             switch ($package) {
                 case 'core':
                     $path = '/' . sfConfig::get('dm_core_asset') . '/js/' . $name . '.js';
                     break;
                 case 'lib':
                     $path = '/' . sfConfig::get('dm_core_asset') . '/lib/' . $name . '.js';
                     break;
                 case 'front':
                     $path = '/' . sfConfig::get('dm_front_asset') . '/js/' . $name . '.js';
                     break;
                 case 'admin':
                     $path = '/' . sfConfig::get('dm_admin_asset') . '/js/' . $name . '.js';
                     break;
                 default:
                     $path = '/' . dmString::str_replace_once('.', '/' . $type . '/', $asset) . '.js';
             }
             break;
         case 'css':
             switch ($package) {
                 case 'core':
                     $path = '/' . sfConfig::get('dm_core_asset') . '/css/' . $name . '.css';
                     break;
                 case 'lib':
                     $path = '/' . sfConfig::get('dm_core_asset') . '/lib/' . $name . '.css';
                     break;
                 case 'front':
                     $path = '/' . sfConfig::get('dm_front_asset') . '/css/' . $name . '.css';
                     break;
                 case 'admin':
                     $path = '/' . sfConfig::get('dm_admin_asset') . '/css/' . $name . '.css';
                     break;
                 default:
                     $path = '/' . dmString::str_replace_once('.', '/' . $type . '/', $asset) . '.css';
             }
             break;
         default:
             $path = '/' . dmString::str_replace_once('.', '/', $asset);
     }
     if (!isset($path)) {
         throw new dmException("Can not find path for asset {$type}.{$package}.{$asset}");
     }
     // check for source version of the file in `dev` environment
     if (sfConfig::get('sf_environment') == 'dev') {
         $webPath = sfConfig::get('sf_web_dir');
         $fsPath = $webPath . $path;
         $fsSourceFilePath = null;
         $fsDirName = dirname($fsPath);
         $fsFilename = basename($fsPath);
         if (strpos($fsFilename, '.min.')) {
             $possibleFsSourceFilePath = $fsDirName . DIRECTORY_SEPARATOR . str_replace('.min.', '.', $fsFilename);
             if (file_exists($possibleFsSourceFilePath)) {
                 $fsSourceFilePath = $possibleFsSourceFilePath;
             }
         }
         if (is_null($fsSourceFilePath)) {
             $fsPathDirectories = explode(DIRECTORY_SEPARATOR, $fsDirName);
             $fsFilename = str_replace('.min.', '.', $fsFilename);
             foreach ($fsPathDirectories as $fsDirectory) {
                 if (in_array($fsDirectory, array('min', 'minified', 'compressed', 'minimized'))) {
                     foreach (array('source', 'unminified', 'uncompressed', 'unminimized') as $possibleSourceDirName) {
                         $search = DIRECTORY_SEPARATOR . $fsDirectory . DIRECTORY_SEPARATOR;
                         $replace = DIRECTORY_SEPARATOR . $possibleSourceDirName . DIRECTORY_SEPARATOR;
                         $possibleFsSourceFilePath = str_replace($search, $replace, $fsDirName . DIRECTORY_SEPARATOR) . $fsFilename;
                         if (file_exists($possibleFsSourceFilePath)) {
                             $fsSourceFilePath = $possibleFsSourceFilePath;
                             break;
                         }
                     }
                     //break after a directory with minified files is found
                     break;
                 }
             }
             unset($fsDirectory);
         }
         if (!is_null($fsSourceFilePath)) {
             $fs = dmContext::getInstance()->getFilesystem();
             $path = '/' . $fs->getRelativeDir($webPath . DIRECTORY_SEPARATOR, $fsSourceFilePath);
         }
     }
     return $path;
 }
コード例 #5
0
ファイル: dmMarkdown.php プロジェクト: theolymp/diem
 public function _doAnchors_inline_callback($matches)
 {
     $text = $this->runSpanGamut($matches[2]);
     $url = $matches[3] == '' ? $matches[4] : $matches[3];
     $title = $matches[7];
     $attrs = $matches[9];
     if (false !== strpos($url, '#')) {
         $anchor = preg_replace('{.*\\#([\\w\\d\\-\\:]+).*}i', '$1', $url);
         $url = dmString::str_replace_once('#' . $anchor, '', $url);
     } else {
         $anchor = null;
     }
     if (strlen($url) == 0 && $anchor) {
         $link = $this->helper->link('#' . $anchor)->text($text);
     } else {
         $link = $this->helper->link($url)->text($text);
         if ($anchor) {
             $link->anchor($anchor);
         }
     }
     if ($title) {
         $link->title($title);
     }
     if ($attrs) {
         $link->set($attrs);
     }
     return $this->hashPart($link->render());
 }