Exemple #1
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 . '.js';
         if (!file_exists($cacheFile)) {
             $js = '';
             foreach ($assets as $asset) {
                 $contents = $asset->getAssetContents();
                 if (isset($contents)) {
                     if ($asset->assetSupportsMinification()) {
                         $contents = \JShrink\Minifier::minify($contents);
                     }
                     $js .= $contents . "\n\n";
                 }
             }
             @file_put_contents($cacheFile, $js);
         }
         $asset = new JavascriptAsset();
         $asset->setAssetURL($relativeDirectory . '/' . $filename . '.js');
         $asset->setAssetPath($directory . '/' . $filename . '.js');
         $asset->setCombinedAssetSourceFiles($sourceFiles);
         return array($asset);
     }
     return $assets;
 }
Exemple #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;
             }
         }
     }
 }
 /**
  * {@inheritDoc}
  */
 public static function process($assets)
 {
     if (self::getOutputDirectory()) {
         $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 JavascriptAsset();
         $asset->setAssetURL($relativePath);
         $asset->setAssetPath($assetDir . $relativePath);
         $asset->setCombinedAssetSourceFiles($sourceFiles);
         return array($asset);
     }
     return $assets;
 }
Exemple #4
0
 public function javascript($file, $pkgHandle = null)
 {
     $asset = new JavascriptAsset();
     // 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 {
             if (file_exists(DIR_APPLICATION . '/' . DIRNAME_JAVASCRIPT . '/' . $file)) {
                 $asset->setAssetURL(REL_DIR_APPLICATION . '/' . DIRNAME_JAVASCRIPT . '/' . $file);
                 $asset->setAssetPath(DIR_APPLICATION . '/' . DIRNAME_JAVASCRIPT . '/' . $file);
             } else {
                 if ($pkgHandle != null) {
                     if (file_exists(DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_JAVASCRIPT . '/' . $file)) {
                         $asset->setAssetURL(REL_DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_JAVASCRIPT . '/' . $file);
                         $asset->setAssetPath(DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_JAVASCRIPT . '/' . $file);
                     } else {
                         if (file_exists(DIR_BASE_CORE . '/' . DIRNAME_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_JAVASCRIPT . '/' . $file)) {
                             $asset->setAssetURL(ASSETS_URL . '/' . DIRNAME_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_JAVASCRIPT . '/' . $file);
                             $asset->setAssetPath(DIR_BASE_CORE . '/' . DIRNAME_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_JAVASCRIPT . '/' . $file);
                         }
                     }
                 }
             }
         }
     }
     if (!$asset->getAssetURL()) {
         $asset->setAssetURL(ASSETS_URL_JAVASCRIPT . '/' . $file);
         $asset->setAssetPath(DIR_BASE_CORE . '/' . DIRNAME_JAVASCRIPT . '/' . $file);
     }
     return $asset;
 }
 public function javascript($file, $pkgHandle = null)
 {
     $asset = new JavascriptAsset();
     // 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) == '//') {
         $asset->setAssetURL($file);
         $asset->setAssetIsLocal(false);
     } else {
         if (substr($file, 0, 1) == '/') {
             $asset->setAssetURL($file);
             $asset->setAssetPath(DIR_APPLICATION . $file);
         } else {
             if (file_exists(DIR_APPLICATION . '/' . DIRNAME_JAVASCRIPT . '/' . $file)) {
                 $asset->setAssetURL(REL_DIR_APPLICATION . '/' . DIRNAME_JAVASCRIPT . '/' . $file);
                 $asset->setAssetPath(DIR_APPLICATION . '/' . DIRNAME_JAVASCRIPT . '/' . $file);
             } else {
                 if ($pkgHandle != null) {
                     if (file_exists(DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_JAVASCRIPT . '/' . $file)) {
                         $asset->setAssetURL(REL_DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_JAVASCRIPT . '/' . $file);
                         $asset->setAssetPath(DIR_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_JAVASCRIPT . '/' . $file);
                     } else {
                         if (file_exists(DIR_BASE_CORE . '/' . DIRNAME_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_JAVASCRIPT . '/' . $file)) {
                             $asset->setAssetURL(ASSETS_URL . '/' . DIRNAME_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_JAVASCRIPT . '/' . $file);
                             $asset->setAssetPath(DIR_BASE_CORE . '/' . DIRNAME_PACKAGES . '/' . $pkgHandle . '/' . DIRNAME_JAVASCRIPT . '/' . $file);
                         }
                     }
                 }
             }
         }
     }
     if (!$asset->getAssetURL()) {
         $asset->setAssetURL(ASSETS_URL_JAVASCRIPT . '/' . $file);
         $asset->setAssetPath(DIR_BASE_CORE . '/' . DIRNAME_JAVASCRIPT . '/' . $file);
     }
     return $asset;
 }
 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'), -4);
                     $asset = new CSSAsset($identifier);
                     $asset->setAssetURL($this->getBaseURL() . '/' . DIRNAME_CSS . '/' . $i);
                     $asset->setAssetPath($this->basePath . '/' . DIRNAME_CSS . '/' . $i);
                     $al->registerAsset($asset);
                     $v->requireAsset('css', 'blocks/' . $identifier);
                 }
             }
         }
         if (count($js) > 0) {
             foreach ($js as $i) {
                 if (substr($i, -3) == '.js') {
                     $identifier = substr($this->basePath, strpos($this->basePath, 'blocks'), -4);
                     $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);
                 }
             }
         }
     }
 }