Пример #1
0
 /**
  * Parse a less file to get all its overrides before compile
  * @param  string  $path the less file
  */
 public static function parse($path)
 {
     $rtpl_check = '@' . preg_quote(CANVAS_TEMPLATE_REL, '@') . '/@i';
     $rtpl_less_check = '@' . preg_quote(CANVAS_TEMPLATE_REL, '@') . '/less/@i';
     $app = JFactory::getApplication();
     $theme = $app->getUserState('current_theme');
     $dir = $app->getUserState('current_direction');
     $is_rtl = $dir == 'rtl';
     $less_rel_path = preg_replace($rtpl_less_check, '', $path);
     $less_rel_dir = dirname($less_rel_path);
     $less_rel_dir = $less_rel_dir == '.' ? '' : $less_rel_dir . '/';
     // check path
     $realpath = realpath(JPATH_ROOT . '/' . $path);
     if (!is_file($realpath)) {
         return false;
     }
     // get file content
     $content = file_get_contents($realpath);
     //remove vars.less
     $content = preg_replace(self::$rimportvars, '', $content);
     // split into array, separated by the import
     $arr = preg_split(self::$rimport, $content, -1, PREG_SPLIT_DELIM_CAPTURE);
     $arr[] = $less_rel_path;
     $arr[] = '';
     $list = array();
     $rtl_list = array();
     $list[$path] = '';
     $import = false;
     foreach ($arr as $chunk) {
         if ($import) {
             $import = false;
             $import_url = CANVASPath::cleanPath(CANVAS_TEMPLATE_REL . '/less/' . $less_rel_dir . $chunk);
             // if $url in template, get all its overrides
             if (preg_match($rtpl_less_check, $import_url)) {
                 $less_rel_url = CANVASPath::cleanPath($less_rel_dir . $chunk);
                 $array = CANVASPath::getAllPath('less/' . $less_rel_url, true);
                 if ($theme) {
                     $array = array_merge($array, CANVASPath::getAllPath('less/themes/' . $theme . '/' . $less_rel_url, true));
                 }
                 foreach ($array as $f) {
                     // add file in template only
                     if (preg_match($rtpl_check, $f)) {
                         $list[$f] = CANVASPath::relativePath(dirname($path), $f);
                     }
                 }
                 // rtl overrides
                 if ($is_rtl) {
                     $array = CANVASPath::getAllPath('less/rtl/' . $less_rel_url, true);
                     if ($theme) {
                         $array = array_merge($array, CANVASPath::getAllPath('less/rtl/themes/' . $theme . '/' . $less_rel_url, true));
                     }
                     foreach ($array as $f) {
                         // add file in template only
                         if (preg_match($rtpl_check, $f)) {
                             $rtl_list[$f] = CANVASPath::relativePath(dirname($path), $f);
                         }
                     }
                 }
             } else {
                 $list[$import_url] = $chunk;
             }
         } else {
             $import = true;
             $list[$chunk] = false;
         }
     }
     // remove itself
     unset($list[$path]);
     // join rtl
     if ($is_rtl) {
         $list["\n\n#" . self::$krtlsep . "{content: \"separator\";}\n\n"] = false;
         $list = array_merge($list, $rtl_list);
     }
     return $list;
 }
Пример #2
0
 /**
  * Add some other condition assets (css, javascript). Use to parse /etc/assets.xml
  *
  * @return  null
  */
 function addExtraAssets()
 {
     $base = JURI::base(true);
     $regurl = '#(http|https)://([a-zA-Z0-9.]|%[0-9A-Za-z]|/|:[0-9]?)*#iu';
     $afiles = CANVASPath::getAllPath('etc/assets.xml');
     foreach ($afiles as $afile) {
         if (is_file($afile)) {
             //load xml
             $axml = JFactory::getXML($afile);
             //process if exist
             if ($axml) {
                 foreach ($axml as $node => $nodevalue) {
                     //ignore others node
                     if ($node == 'stylesheets' || $node == 'scripts') {
                         foreach ($nodevalue->file as $file) {
                             $compatible = (string) $file['compatible'];
                             if ($compatible) {
                                 $parts = explode(' ', $compatible);
                                 $operator = '=';
                                 //exact equal to
                                 $operand = $parts[0];
                                 if (count($parts) == 2) {
                                     $operator = $parts[0];
                                     $operand = $parts[1];
                                 }
                                 //compare with Joomla version
                                 if (!version_compare(JVERSION, $operand, $operator)) {
                                     continue;
                                 }
                             }
                             $url = (string) $file;
                             if (substr($url, 0, 2) == '//') {
                                 //external link
                             } else {
                                 if ($url[0] == '/') {
                                     //absolute link from based folder
                                     $url = is_file(JPATH_ROOT . $url) ? $base . $url : false;
                                 } else {
                                     if (!preg_match($regurl, $url)) {
                                         //not match a full url -> sure internal link
                                         $url = CANVASPath::getUrl($url);
                                         // so get it
                                     }
                                 }
                             }
                             if ($url) {
                                 if ($node == 'stylesheets') {
                                     $type = $file['type'] ? (string) $file['type'] : 'text/css';
                                     $media = $file['media'] ? (string) $file['media'] : null;
                                     $this->addStylesheet($url, $type, $media);
                                 } else {
                                     $type = $file['type'] ? (string) $file['type'] : 'text/javascript';
                                     $defer = $file['defer'] ? (bool) $file['defer'] : false;
                                     $async = $file['async'] ? (bool) $file['async'] : false;
                                     $this->addScript($url, $type, $defer, $async);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // template extended styles
     $aparams = $this->_tpl->params->toArray();
     $extras = array();
     $itemid = JFactory::getApplication()->input->get('Itemid');
     foreach ($aparams as $name => $value) {
         if (preg_match('/^theme_extras_(.+)$/', $name, $m)) {
             $extras[$m[1]] = $value;
         }
     }
     if (count($extras)) {
         foreach ($extras as $extra => $pages) {
             if (!is_array($pages) || !count($pages) || in_array(0, $pages)) {
                 continue;
                 // disabled
             }
             if (in_array(-1, $pages) || in_array($itemid, $pages)) {
                 // load this style
                 $this->addCss('extras/' . $extra);
             }
         }
     }
     // load addon lib scripts/styles
     // -------------------------------------------
     // load holder.js
     if ($this->params->get('load_holder_js', 1)) {
         $this->addScript(CANVAS_URL . '/js/holder.js');
     }
     // load wow.js
     if ($this->params->get('load_wow_js', 1)) {
         $this->addScript(CANVAS_URL . '/js/wow.min.js');
     }
     // load animate.css
     if ($this->params->get('load_animate_css', 1)) {
         $this->addStyleSheet(CANVAS_URL . '/css/animate.min.css');
     }
 }