Пример #1
0
 /**
  * {@inheritDoc}
  */
 public static function process($assets)
 {
     if ($directory = self::getOutputDirectory()) {
         $relativeDirectory = self::getRelativeOutputDirectory();
         $filename = '';
         $sourceFiles = array();
         for ($i = 0; $i < count($assets); $i++) {
             $asset = $assets[$i];
             $filename .= $asset->getAssetHashKey();
             $sourceFiles[] = $asset->getAssetURL();
         }
         $filename = sha1($filename);
         $app = Facade::getFacadeApplication();
         $ah = $app->make('helper/assets');
         $paths = array();
         foreach ($assets as $asset) {
             $paths[] = $asset->getAssetPath();
         }
         $relativePath = $ah->javascriptPath($paths, array('name' => $filename, 'skipDigest' => true));
         $assetDir = Config::get('concrete.cache.directory');
         $asset = new CssAsset();
         $asset->setAssetURL($relativePath);
         $asset->setAssetPath($assetDir . $relativePath);
         $asset->setCombinedAssetSourceFiles($sourceFiles);
         return array($asset);
     }
     return $assets;
 }
Пример #2
0
 public function registerViewAssets()
 {
     $al = \AssetList::getInstance();
     $v = \View::getInstance();
     $env = \Environment::get();
     $identifier = 'menuitem/' . $this->menuItem->getHandle() . '/view';
     foreach (array('CSS' => 'view.css', 'JAVASCRIPT' => 'view.js') as $t => $i) {
         $r = $env->getRecord(DIRNAME_MENU_ITEMS . '/' . $this->menuItem->getHandle() . '/' . $i, $this->menuItem->getPackageHandle());
         if ($r->exists()) {
             switch ($t) {
                 case 'CSS':
                     $asset = new CssAsset($identifier);
                     $asset->setAssetURL($r->url);
                     $asset->setAssetPath($r->file);
                     $al->registerAsset($asset);
                     $v->requireAsset('css', $identifier);
                     break;
                 case 'JAVASCRIPT':
                     $asset = new JavascriptAsset($identifier);
                     $asset->setAssetURL($r->url);
                     $asset->setAssetPath($r->file);
                     $al->registerAsset($asset);
                     $v->requireAsset('javascript', $identifier);
                     break;
             }
         }
     }
 }
Пример #3
0
 public function view()
 {
     $b = $this->getBlockObject();
     $a = $b->getBlockAreaObject();
     $this->arLayout = $this->getAreaLayoutObject();
     if (is_object($this->arLayout)) {
         $this->arLayout->setAreaObject($a);
         $this->set('columns', $this->arLayout->getAreaLayoutColumns());
         $c = Page::getCurrentPage();
         $this->set('c', $c);
         if ($this->arLayout->isAreaLayoutUsingThemeGridFramework()) {
             $pt = $c->getCollectionThemeObject();
             $gf = $pt->getThemeGridFrameworkObject();
         }
         if (isset($gf) && is_object($gf)) {
             $this->set('gf', $gf);
             $this->render('view_grid');
         } else {
             $asset = new CssAsset();
             $asset->setAssetURL(URL::to('/ccm/system/css/layout', $this->bID));
             $asset->setAssetSupportsMinification(false);
             $asset->setAssetSupportsCombination(false);
             $this->requireAsset($asset);
             $this->render('view');
         }
     } else {
         $this->set('columns', array());
     }
 }
Пример #4
0
 /**
  * @return string|null
  */
 public function getAssetContents()
 {
     return parent::getAssetContentsByRoute($this->assetURL);
 }
Пример #5
0
 public function css($file, $pkgHandle = null)
 {
     $asset = new CssAsset();
     // if the first character is a / then that means we just go right through, it's a direct path
     if (substr($file, 0, 4) == 'http' || substr($file, 0, 2) == '//' || strpos($file, '?') > 0) {
         // we can't cache this file, so we make sure to say it's not local. It may BE local –but we can't cache it.
         $asset->setAssetURL($file);
         $asset->setAssetIsLocal(false);
     } else {
         if (substr($file, 0, 1) == '/') {
             $asset->setAssetURL($file);
             // if we're in a relative directory, strip the relative part of the $file, since it'll
             // duplicate in DIR_BASE
             if (DIR_REL != '') {
                 $file = substr($file, strlen(DIR_REL));
             }
             $asset->setAssetPath(DIR_BASE . $file);
         } else {
             $v = View::getInstance();
             // checking the theme directory for it. It's just in the root.
             if ($v instanceof View && $v->getThemeDirectory() != '' && file_exists($v->getThemeDirectory() . '/' . $file)) {
                 $asset->setAssetURL($v->getThemePath() . '/' . $file);
                 $asset->setAssetPath($v->getThemeDirectory() . '/' . $file);
             } else {
                 if (file_exists(DIR_APPLICATION . '/' . DIRNAME_CSS . '/' . $file)) {
                     $asset->setAssetURL(REL_DIR_APPLICATION . '/' . DIRNAME_CSS . '/' . $file);
                     $asset->setAssetPath(DIR_APPLICATION . '/' . DIRNAME_CSS . '/' . $file);
                 } else {
                     if ($pkgHandle != null) {
                         if (file_exists(DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_CSS . '/' . $file)) {
                             $asset->setAssetURL(REL_DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_CSS . '/' . $file);
                             $asset->setAssetPath(DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_CSS . '/' . $file);
                         } else {
                             if (file_exists(DIR_BASE_CORE . '/' . DIRNAME_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_CSS . '/' . $file)) {
                                 $asset->setAssetURL(ASSETS_URL . '/' . DIRNAME_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_CSS . '/' . $file);
                                 $asset->setAssetPath(DIR_BASE_CORE . '/' . DIRNAME_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_CSS . '/' . $file);
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!$asset->getAssetURL()) {
         $asset->setAssetURL(ASSETS_URL_CSS . '/' . $file);
         $asset->setAssetPath(DIR_BASE_CORE . '/' . DIRNAME_CSS . '/' . $file);
     }
     return $asset;
 }
Пример #6
0
 public function view()
 {
     $b = $this->getBlockObject();
     $a = $b->getBlockAreaObject();
     $this->arLayout = $this->getAreaLayoutObject();
     if (is_object($this->arLayout)) {
         $this->arLayout->setAreaObject($a);
         $this->set('columns', $this->arLayout->getAreaLayoutColumns());
         $c = Page::getCurrentPage();
         $this->set('c', $c);
         $gf = false;
         if ($this->arLayout->isAreaLayoutUsingThemeGridFramework()) {
             $pt = $c->getCollectionThemeObject();
             $gf = $pt->getThemeGridFrameworkObject();
         }
         if ($this->arLayout instanceof CustomLayout) {
             $asset = new CssAsset();
             $asset->setAssetURL(URL::to('/ccm/system/css/layout', $this->arLayout->getAreaLayoutID()));
             $asset->setAssetSupportsMinification(false);
             $asset->setAssetSupportsCombination(false);
             $this->requireAsset($asset);
         }
         $formatter = $this->arLayout->getFormatter();
         $this->set('formatter', $formatter);
     } else {
         $this->set('columns', array());
     }
 }
Пример #7
0
 /**
  * @param Asset[] $assets
  *
  * @return Asset[]
  */
 public static function process($assets)
 {
     if ($directory = self::getOutputDirectory()) {
         $relativeDirectory = self::getRelativeOutputDirectory();
         $filename = '';
         $sourceFiles = array();
         for ($i = 0; $i < count($assets); $i++) {
             $asset = $assets[$i];
             $filename .= $asset->getAssetHashKey();
             $sourceFiles[] = $asset->getAssetURL();
         }
         $filename = sha1($filename);
         $cacheFile = $directory . '/' . $filename . '.css';
         if (!file_exists($cacheFile)) {
             $css = '';
             foreach ($assets as $asset) {
                 $contents = $asset->getAssetContents();
                 if (isset($contents)) {
                     $contents = CssAsset::changePaths($contents, $asset->getAssetURLPath(), $relativeDirectory);
                     if ($asset->assetSupportsMinification()) {
                         $contents = \CssMin::minify($contents);
                     }
                     $css .= $contents . "\n\n";
                 }
             }
             @file_put_contents($cacheFile, $css);
         }
         $asset = new CssAsset();
         $asset->setAssetURL($relativeDirectory . '/' . $filename . '.css');
         $asset->setAssetPath($directory . '/' . $filename . '.css');
         $asset->setCombinedAssetSourceFiles($sourceFiles);
         return array($asset);
     }
     return $assets;
 }
Пример #8
0
 public function registerTemplateAssets()
 {
     $items = array();
     $h = Loader::helper("html");
     $dh = Loader::helper('file');
     if ($this->checkAssets == false) {
         return $items;
     } else {
         $al = AssetList::getInstance();
         $v = View::getInstance();
         foreach ($this->itemsToCheck as $t => $i) {
             if (file_exists($this->basePath . '/' . $i)) {
                 $identifier = substr($this->basePath, strpos($this->basePath, 'blocks'));
                 // $identifier = 'blocks/page_list', 'blocks/feature', 'blocks/page_list/templates/responsive', etc...
                 switch ($t) {
                     case 'CSS':
                         $asset = new CssAsset($identifier);
                         $asset->setAssetURL($this->getBaseURL() . '/' . $i);
                         $asset->setAssetPath($this->basePath . '/' . $i);
                         $al->registerAsset($asset);
                         $v->requireAsset('css', $identifier);
                         break;
                     case 'JAVASCRIPT':
                         $asset = new JavascriptAsset($identifier);
                         $asset->setAssetURL($this->getBaseURL() . '/' . $i);
                         $asset->setAssetPath($this->basePath . '/' . $i);
                         $al->registerAsset($asset);
                         $v->requireAsset('javascript', $identifier);
                         break;
                 }
             }
         }
         $css = $dh->getDirectoryContents($this->basePath . '/' . DIRNAME_CSS);
         $js = $dh->getDirectoryContents($this->basePath . '/' . DIRNAME_JAVASCRIPT);
         if (count($css) > 0) {
             foreach ($css as $i) {
                 if (substr($i, -4) == '.css') {
                     $identifier = substr($this->basePath, strpos($this->basePath, 'blocks')) . '/' . $i;
                     $asset = new CssAsset($identifier);
                     $asset->setAssetURL($this->getBaseURL() . '/' . DIRNAME_CSS . '/' . $i);
                     $asset->setAssetPath($this->basePath . '/' . DIRNAME_CSS . '/' . $i);
                     $al->registerAsset($asset);
                     $v->requireAsset('css', $identifier);
                 }
             }
         }
         if (count($js) > 0) {
             foreach ($js as $i) {
                 if (substr($i, -3) == '.js') {
                     $identifier = substr($this->basePath, strpos($this->basePath, 'blocks')) . '/' . $i;
                     $asset = new JavascriptAsset($identifier);
                     $asset->setAssetURL($this->getBaseURL() . '/' . DIRNAME_JAVASCRIPT . '/' . $i);
                     $asset->setAssetPath($this->basePath . '/' . DIRNAME_JAVASCRIPT . '/' . $i);
                     $al->registerAsset($asset);
                     $v->requireAsset('javascript', $identifier);
                 }
             }
         }
     }
 }