/** * Method to get the list of files for the field options. * Specify the target directory with a directory attribute * Attributes allow an exclude mask and stripping of extensions from file name. * Default attribute may optionally be set to null (no file) or -1 (use a default). * * @return array The field option objects. * * @since 11.1 */ protected function getOptions() { $table = JTable::getInstance('Style', 'TemplatesTable', array()); $table->load((int) JFactory::getApplication()->input->getInt('id')); // update path to this template $path = (string) $this->element['directory']; if (!is_dir($path)) { // process path in template $options = array(); $vals = array(); // get all path in template $paths = T3Path::getAllPath($path); foreach ($paths as $path) { $this->directory = $this->element['directory'] = $path; $tmps = parent::getOptions(); foreach ($tmps as $tmp) { if (in_array($tmp->value, $vals)) { continue; } $vals[] = $tmp->value; $options[] = $tmp; } } return $options; } return parent::getOptions(); }
/** * 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 = T3Path::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 = T3Path::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); } } } }
/** * 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(T3_TEMPLATE_REL, '@') . '/@i'; $rtpl_less_check = '@' . preg_quote(T3_TEMPLATE_REL, '@') . '/less/@i'; $app = JFactory::getApplication(); $theme = $app->getUserState('current_theme'); $dir = $app->getUserState('current_direction'); $is_rtl = $dir == 'rtl'; $rel_path = preg_replace($rtpl_check, '', $path); $rel_dir = dirname($rel_path); // 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[] = basename($rel_path); $arr[] = ''; $list = array(); $rtl_list = array(); $list[$path] = ''; $import = false; foreach ($arr as $chunk) { if ($import) { $import = false; $import_url = T3Path::cleanPath(T3_TEMPLATE_REL . '/' . $rel_dir . '/' . $chunk); // if $url in less folder, get all its overrides if (preg_match($rtpl_less_check, $import_url)) { $less_rel_url = preg_replace($rtpl_less_check, '', $import_url); $array = T3Path::getAllPath('less/' . $less_rel_url, true); if ($theme) { $array = array_merge($array, T3Path::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] = T3Path::relativePath(dirname($path), $f); } } // rtl overrides if ($is_rtl) { $array = T3Path::getAllPath('less/rtl/' . $less_rel_url, true); if ($theme) { $array = array_merge($array, T3Path::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] = T3Path::relativePath(dirname($path), $f); } } } } else { $list[$import_url] = T3Path::cleanPath($chunk); // rtl override if ($is_rtl) { $rtl_url = preg_replace('/\\/less\\//', '/less/rtl/', $import_url); if (is_file(JPATH_ROOT . '/' . $rtl_url)) { $rtl_list[$rtl_url] = T3Path::relativePath(dirname($path), $rtl_url); } } } } 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; }
public static function addAssets() { $japp = JFactory::getApplication(); $user = JFactory::getUser(); //do nothing when site is offline and user has not login (the offline page is only show login form) if ($japp->getCfg('offline') && !$user->authorise('core.login.offline')) { return; } $jdoc = JFactory::getDocument(); $params = $japp->getTemplate(true)->params; $devmode = $params->get('devmode', 0); if (defined('T3_THEMER') && $params->get('themermode', 1)) { $jdoc->addStyleSheet(T3_URL . '/css/thememagic.css'); $jdoc->addScript(T3_URL . '/js/thememagic.js'); $theme = $params->get('theme'); $params = new JRegistry(); $themeinfo = new stdClass(); if ($theme) { foreach (T3Path::getAllPath('less/themes/' . $theme) as $themepath) { //$themepath = T3_TEMPLATE_PATH . '/less/themes/' . $theme; if (file_exists($themepath . '/variables-custom.less')) { if (!class_exists('JRegistryFormatLESS')) { include_once T3_ADMIN_PATH . '/includes/format/less.php'; } //default variables $varfile = T3_TEMPLATE_PATH . '/less/variables.less'; if (file_exists($varfile)) { $params->loadString(JFile::read($varfile), 'LESS'); //get all less files in "theme" folder $others = JFolder::files($themepath, '.less'); foreach ($others as $other) { //get those developer custom values if ($other == 'variables.less') { $devparams = new JRegistry(); $devparams->loadString(JFile::read($themepath . '/variables.less'), 'LESS'); //overwrite the default variables foreach ($devparams->toArray() as $key => $value) { $params->set($key, $value); } } //ok, we will import it later if ($other != 'variables-custom.less' && $other != 'variables.less') { $themeinfo->{$other} = true; } } //load custom variables if (file_exists($themepath . '/variables-custom.less')) { $cparams = new JRegistry(); $cparams->loadString(JFile::read($themepath . '/variables-custom.less'), 'LESS'); //and overwrite those defaults variables foreach ($cparams->toArray() as $key => $value) { $params->set($key, $value); } } } } } } $cache = array(); // a little security if ($user->authorise('core.manage', 'com_templates') || isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], JUri::base() . 'administrator') !== false) { T3::import('core/path'); $baseurl = JUri::base(); //should we provide a list of less path foreach (array(T3_TEMPLATE_PATH . '/less', T3_PATH . '/bootstrap/less', T3_PATH . '/less') as $lesspath) { if (is_dir($lesspath)) { $lessfiles = JFolder::files($lesspath, '.less', true, true); if (is_array($lessfiles)) { foreach ($lessfiles as $less) { $path = ltrim(str_replace(array(JPATH_ROOT, '\\'), array('', '/'), $less), '/'); $path = T3Path::cleanPath($path); $fullurl = $baseurl . preg_replace('@(\\+)|(/+)@', '/', $path); $cache[$fullurl] = JFile::read($less); } } } } } //workaround for bootstrap icon path $sparams = new JRegistry(); if (defined('T3_BASE_RSP_IN_CLASS') && T3_BASE_RSP_IN_CLASS) { $sparams->set('icon-font-path', '"' . JUri::base() . 'plugins/system/t3/base-bs3/bootstrap/fonts/"'); } // enable development mode for less.js if ($devmode) { $jdoc->addScriptDeclaration(' var less = window.less || {}; less.env = \'development\'; '); } $jdoc->addScriptDeclaration(' var T3Theme = window.T3Theme || {}; T3Theme.vars = ' . json_encode($params->toArray()) . '; T3Theme.svars = ' . json_encode($sparams->toArray()) . '; T3Theme.others = ' . json_encode($themeinfo) . '; T3Theme.theme = \'' . $theme . '\'; T3Theme.template = \'' . T3_TEMPLATE . '\'; T3Theme.base = \'' . JURI::base() . '\'; T3Theme.cache = ' . json_encode($cache) . '; if(typeof less != \'undefined\'){ //we need to build one - cause the js will have unexpected behavior try{ if(window.parent != window && window.parent.T3Theme && window.parent.T3Theme.applyLess){ window.parent.T3Theme.applyLess(true); } else { less.refresh(); } } catch(e){ } }'); } }