Exemplo n.º 1
0
 public function getUrlAsset($type, $ssl = false)
 {
     if (!is_string($type)) {
         throw new \Exception('Asset type must be a string');
     }
     if (Http::isHttps()) {
         $ssl = true;
     }
     if (!is_array($this->_assets)) {
         return false;
     }
     if (!array_key_exists($type, $this->_assets)) {
         return false;
     }
     $asset = $this->_assets[$type];
     return Router::getHost(true, $ssl) . str_replace(DS, '/', str_replace(PATH_ROOT, '', $asset['directory']));
 }
Exemplo n.º 2
0
 protected function _getContent()
 {
     if ($this->_type == Template::ASSET_CSS) {
         $content = '';
         foreach ($this->_files as $file) {
             $f = file_get_contents($file['name']);
             if ($this->_compress && !$file['alreadyCompressed']) {
                 $f = $this->_compressCss($f);
             }
             $content .= $f;
         }
         //rewrite url path
         if ($this->getRewriteUrls()) {
             return preg_replace("#\\[HOSTNAME]#", Router::getHost(true, Http::isHttps()), $content);
         }
         return $content;
     } elseif ($this->_type == Template::ASSET_JS) {
         $notCompressed = $content = '';
         foreach ($this->_files as $file) {
             $js = file_get_contents($file['name']);
             if ($this->_compress && !$file['alreadyCompressed']) {
                 // Compress file with Javascript Packer plugin
                 $packer = new JavaScriptPacker($js);
                 $notCompressed .= trim($packer->pack());
             } else {
                 $content .= $js;
             }
             if (substr($notCompressed, -1) != ';') {
                 $notCompressed .= ';';
             }
         }
         //rewrite url path
         if ($this->getRewriteUrls()) {
             return preg_replace("#\\[HOSTNAME]#", Router::getHost(true, Http::isHttps()), $content . $notCompressed);
         }
         return $content . $notCompressed;
     }
 }