public static function compile($source, $path, $todir, $importdirs) { // call Less to compile $parser = new lessc(); $parser->setImportDir(array_keys($importdirs)); $parser->setPreserveComments(true); $output = $parser->compile($source); // update url $arr = preg_split(T3Less::$rsplitbegin . T3Less::$kfilepath . T3Less::$rsplitend, $output, -1, PREG_SPLIT_DELIM_CAPTURE); $output = ''; $file = $relpath = ''; $isfile = false; foreach ($arr as $s) { if ($isfile) { $isfile = false; $file = $s; $relpath = T3Less::relativePath($todir, dirname($file)); $output .= "\n#" . T3Less::$kfilepath . "{content: \"{$file}\";}\n"; } else { $output .= ($file ? T3Path::updateUrl($s, $relpath) : $s) . "\n\n"; $isfile = true; } } return $output; }
/** * 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(); }
/** * Load hook file * * @return void */ function _load() { if (defined('_T3_HOOK_CUSTOM')) { return; } define('_T3_HOOK_CUSTOM', 1); //include hook. Get all path to hook.php in themes $paths = T3Path::getPath('hook.php', true); if (is_array($paths)) { foreach ($paths as $path) { include $path; } } }
function gzip() { $file = JRequest::getVar('file'); //clean filepath $file = preg_replace('#[?\\#]+.*$#', '', $file); //check exists $filepath = T3Path::path(dirname($file)) . DS . basename($file); if (!is_file($filepath)) { echo "File {$file} {$filepath} not exist"; return; } $type = strtolower(JRequest::getCmd('type', 'css')); //$type must be in css or js if (!in_array($type, array('css', 'js'))) { echo "Type {$type} not support"; return; } //make sure the type of $file is the same with $type if (!preg_match('#\\.' . $type . '$#', $filepath)) { echo "Type {$type} not match"; return; } jimport('joomla.filesystem.file'); $data = @JFile::read($filepath); if (!$data) { echo "File {$filepath} empty"; return; } if ($type == 'js') { $type = 'javascript'; } JResponse::setHeader('Content-Type', "text/{$type};", true); //set cache time JResponse::setHeader('Cache-Control', "private", true); $offset = 365 * 24 * 60 * 60; //whenever the content is changed, the file name is changed also. Therefore we could set the cache time long. JResponse::setHeader('Expires', gmdate("D, d M Y H:i:s", time() + $offset) . " GMT", true); JResponse::allowCache(true); JResponse::setBody($data); echo JResponse::toString(1); }
function getT3Themes($template) { $themes = array(); $themes["engine.default"] = T3Path::path(T3_BASETHEME, false); $path = T3Path::path(T3_TEMPLATE_CORE) . DS . 'themes'; $_themes = @JFolder::folders($path); if (is_array($_themes)) { foreach ($_themes as $theme) { $themes["core.{$theme}"] = T3Path::path(T3_TEMPLATE_CORE, false) . DS . 'themes' . DS . $theme; } } $path = T3Path::path(T3_TEMPLATE_LOCAL) . DS . 'themes'; if (is_dir($path)) { $_themes = @JFolder::folders($path); if (is_array($_themes)) { foreach ($_themes as $theme) { $themes["local.{$theme}"] = T3Path::path(T3_TEMPLATE_LOCAL, false) . DS . 'themes' . DS . $theme; } } } return $themes; }
/** * Load block content * * @param $block string * Block name - the real block is tpls/blocks/[blockname].php * * @return string Block content */ function loadBlock($block, $vars = array()) { if (!$this->_block) { $this->_block = $block; } $path = T3Path::getPath('tpls/system/' . $block . '.php'); if (!$path) { $path = T3Path::getPath('tpls/blocks/' . $block . '.php'); } ob_start(); if ($path) { include $path; } else { echo "<div class=\"error\">Block [{$block}] not found!</div>"; } $content = ob_get_contents(); ob_end_clean(); if (isset($vars['spl'])) { $content = preg_replace('#(<[A-Za-z]+[^>^\\/]*)>#', '\\1 data-original="' . $block . '"' . (isset($vars['spl']) ? ' data-spotlight="' . $vars['name'] . '"' : '') . '>', $content, 1); $this->_block = null; } echo isset($vars['spl']) ? $content : "<div class=\"t3-admin-layout-section\">" . $content . "</div>"; }
public static function optimizecss($tpl) { $outputpath = JPATH_ROOT . '/' . $tpl->getParam('t3-assets', 't3-assets') . '/css'; $outputurl = JURI::root(true) . '/' . $tpl->getParam('t3-assets', 't3-assets') . '/css'; if (!JFile::exists($outputpath)){ JFolder::create($outputpath); @chmod($outputpath, 0755); } if (!is_writeable($outputpath)) { return false; } $doc = JFactory::getDocument(); //======================= Group css ================= // $cssgroups = array(); $stylesheets = array(); $ielimit = 4095; $selcounts = 0; $regex = '/\{.+?\}|,/s'; //selector counter $csspath = ''; foreach ($doc->_styleSheets as $url => $stylesheet) { $url = self::fixUrl($url); if ($stylesheet['mime'] == 'text/css' && ($csspath = self::cssPath($url))) { $stylesheet['path'] = $csspath; $stylesheet['data'] = JFile::read($csspath); $selcount = preg_match_all($regex, $stylesheet['data'], $matched); if(!$selcount) { $selcount = 1; //just for sure } //if we found an @import rule or reach IE limit css selector count, break into the new group if (preg_match('#@import\s+.+#', $stylesheet['data']) || $selcounts + $selcount >= $ielimit) { if(count($stylesheets)){ $cssgroup = array(); $groupname = array(); foreach ( $stylesheets as $gurl => $gsheet ) { $cssgroup[$gurl] = $gsheet; $groupname[] = $gurl; } $cssgroup['groupname'] = implode('', $groupname); $cssgroups[] = $cssgroup; } $stylesheets = array($url => $stylesheet); // empty - begin a new group $selcounts = $selcount; } else { $stylesheets[$url] = $stylesheet; $selcounts += $selcount; } } else { // first get all the stylsheets up to this point, and get them into // the items array if(count($stylesheets)){ $cssgroup = array(); $groupname = array(); foreach ( $stylesheets as $gurl => $gsheet ) { $cssgroup[$gurl] = $gsheet; $groupname[] = $gurl; } $cssgroup['groupname'] = implode('', $groupname); $cssgroups[] = $cssgroup; } //mark ignore current stylesheet $cssgroup = array($url => $stylesheet, 'ignore' => true); $cssgroups[] = $cssgroup; $stylesheets = array(); // empty - begin a new group } } if(count($stylesheets)){ $cssgroup = array(); $groupname = array(); foreach ( $stylesheets as $gurl => $gsheet ) { $cssgroup[$gurl] = $gsheet; $groupname[] = $gurl; } $cssgroup['groupname'] = implode('', $groupname); $cssgroups[] = $cssgroup; } //======================= Group css ================= // $output = array(); foreach ($cssgroups as $cssgroup) { if(isset($cssgroup['ignore'])){ unset($cssgroup['ignore']); foreach ($cssgroup as $furl => $fsheet) { $output[$furl] = $fsheet; } } else { $groupname = 'css-' . substr(md5($cssgroup['groupname']), 0, 5) . '.css'; $groupfile = $outputpath . '/' . $groupname; $grouptime = JFile::exists($groupfile) ? @filemtime($groupfile) : -1; $rebuild = $grouptime < 0; //filemtime == -1 => rebuild unset($cssgroup['groupname']); foreach ($cssgroup as $furl => $fsheet) { if(!$rebuild && @filemtime($fsheet['path']) > $grouptime){ $rebuild = true; } } if($rebuild){ $cssdata = array(); foreach ($cssgroup as $furl => $fsheet) { $cssdata[] = "\n\n/*==============================="; $cssdata[] = $furl; $cssdata[] = "================================================================================*/"; $cssmin = Minify_CSS_Compressor::process($fsheet['data']); $cssmin = T3Path::updateUrl($cssmin, T3Path::relativePath($outputurl, dirname($furl))); $cssdata[] = $cssmin; } $cssdata = implode("\n", $cssdata); JFile::write($groupfile, $cssdata); @chmod($groupfile, 0644); } $output[$outputurl . '/' . $groupname] = array( 'mime' => 'text/css', 'media' => null, 'attribs' => array() ); } } //apply the change make change $doc->_styleSheets = $output; }
/** * ------------------------------------------------------------------------ * JA T3v2 System Plugin for J3.x * ------------------------------------------------------------------------ * Copyright (C) 2004-2011 J.O.O.M Solutions Co., Ltd. All Rights Reserved. * @license - GNU/GPL, http://www.gnu.org/licenses/gpl.html * Author: J.O.O.M Solutions Co., Ltd * Websites: http://www.joomlart.com - http://www.joomlancers.com * ------------------------------------------------------------------------ */ // No direct access defined('_JEXEC') or die; $t3_based_path = JPATH_SITE . DS . 'templates' . DS . T3_ACTIVE_TEMPLATE . DS; $layout = str_replace($t3_based_path, '', $t3_current_layout); $layout_path = T3Path::getPath($layout); if (!$layout_path) { //Detect if it is module or component $parts = explode(DS, $layout, 4); $type = ''; if (isset($parts[1])) { $type = $parts[1]; } if ($type) { if (preg_match('/^com_/', $type)) { //component $layout_path = JPATH_SITE . DS . 'components' . DS . $parts[1] . DS . 'views' . DS . $parts[2] . DS . 'tmpl' . DS . $parts[3]; } else { if (preg_match('/^mod_/', $type)) { //component $layout_path = JPATH_SITE . DS . 'modules' . DS . $parts[1] . DS . 'tmpl' . DS . $parts[2];
* This file may not be redistributed in whole or significant part. * ------------------------------------------------------------------------ */ defined('_JEXEC') or die; // parse jdoc after render $params->set('parse-jdoc', 1); // use with T3 $t3doc = T3::getApp(); $doc = JFactory::getDocument(); // get params $tplparams = JFactory::getApplication()->getTemplate(true)->params; $sitename = $tplparams->get('sitename'); $slogan = $tplparams->get('slogan', ''); $logotype = $tplparams->get('logotype', 'text'); $logoimage = $logotype == 'image' ? $tplparams->get('logoimage', T3Path::getUrl('images/logo.png', '', true)) : ''; $logoimgsm = $logotype == 'image' && $tplparams->get('enable_logoimage_sm', 0) ? $tplparams->get('logoimage_sm', T3Path::getUrl('images/logo-sm.png', '', true)) : false; $logolink = $tplparams->get('logolink'); if (!$sitename) { $sitename = JFactory::getConfig()->get('sitename'); } $headright = $doc->countModules('head-search or languageswitcherload or right-menu') || $tplparams->get('addon_offcanvas_enable'); // get logo url $logourl = JURI::base(true); if ($logolink == 'page') { $logopageid = $tplparams->get('logolink_id'); $_item = JFactory::getApplication()->getMenu()->getItem($logopageid); if ($_item) { $logourl = JRoute::_('index.php?Itemid=' . $logopageid); } } // Header Params
/** * Popup prepare content method * * @param string $bodyContent The body string content. * * @return string The replaced body string content */ function replaceContent($bodyContent) { // Build HTML params area $xmlFile = T3Path::path(T3_CORE) . DS . 'params' . DS . "jatoolbar.xml"; if (!file_exists($xmlFile)) { return $bodyContent; } $str = ""; $configform = JForm::getInstance('params', $xmlFile, array('control' => 'jform')); $fieldSets = $configform->getFieldsets('params'); $html = ''; foreach ($fieldSets as $name => $fieldSet) { $html .= '<div class="panel"> <h3 id="jatoolbar-page" class="jpane-toggler title"> <a href="#"><span>' . JText::_($fieldSet->label) . '</span></a> </h3>'; $html .= ' <div class="jpane-slider content"> <fieldset class="panelform">'; if (isset($fieldSet->description) && trim($fieldSet->description)) { $html .= '<div class="block-des">' . JText::_($fieldSet->description) . '</div>'; } $html .= ' <ul class="adminformlist">'; foreach ($configform->getFieldset($name) as $field) { $html .= '<li>'; $html .= $field->label; $html .= $field->input; $html .= '</li>'; } $html .= '</ul> </fieldset> </div> </div>'; } preg_match_all("/<div class=\"panel\">([\\s\\S]*?)<\\/div>/i", $bodyContent, $arr); $bodyContent = str_replace($arr[0][count($arr[0]) - 1] . '</div>', $arr[0][count($arr[0]) - 1] . '</div>' . $html, $bodyContent); return $bodyContent; }
public static function addStylesheet($lesspath) { // build less vars, once only static $vars_built = false; $t3less = T3Less::getInstance(); if (!$vars_built) { self::buildVars(); $vars_built = true; } $app = JFactory::getApplication(); $tpl = $app->getTemplate(true); $theme = $tpl->params->get('theme'); $doc = JFactory::getDocument(); if (defined('T3_THEMER')) { // in Themer mode, using js to parse less for faster $doc->addStylesheet(JURI::base(true) . '/' . T3Path::cleanPath($lesspath), 'text/less'); // Add lessjs to process lesscss $doc->addScript(T3_URL . '/js/less-1.3.3.js'); } else { // in development mode, using php to compile less for a better view of development if (preg_match('#(template(-responsive)?.less)#', $lesspath)) { // Development mode is on, try to include less file inside folder less/ // get the less content $lessContent = JFile::read(JPATH_ROOT . '/' . $lesspath); $path = dirname($lesspath); // parse less content if (preg_match_all('#^\\s*@import\\s+"([^"]*)"#im', $lessContent, $matches)) { foreach ($matches[1] as $url) { if ($url == 'vars.less') { continue; } $url = $path . '/' . $url; $cssurl = $t3less->buildCss(T3Path::cleanPath($url)); $doc->addStyleSheet($cssurl); } } } else { $cssurl = $t3less->buildCss(T3Path::cleanPath($lesspath)); $doc->addStyleSheet($cssurl); } // check and add theme less if ($theme && !preg_match('#bootstrap#', $lesspath)) { $themepath = str_replace('/less/', '/less/themes/' . $theme . '/', $lesspath); if (is_file(JPATH_ROOT . '/' . $themepath)) { $cssurl = $t3less->buildCss(T3Path::cleanPath($themepath)); $doc->addStyleSheet($cssurl); } } } }
public static function updateUrl($css, $src) { self::$srcurl = $src; $css = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/', array('T3Path', 'replaceurl'), $css); $css = preg_replace_callback('/url\\(\\s*([^\\)\\s]+)\\s*\\)/', array('T3Path', 'replaceurl'), $css); return $css; }
/** * Find block path * * @param string $block Block name * * @return string Block layout path */ function findBlock($block) { $pathobj = T3Path::getInstance(); $file = 'blocks' . DS . $block . '.php'; return $pathobj->getPath($file); }
?> ; </script> <jdoc:include type="head" /> <?php if (T3Common::mobile_device_detect() == 'iphone') { ?> <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1; user-scalable=1;" /> <meta name="apple-touch-fullscreen" content="YES" /> <?php } ?> <?php if (T3Common::mobile_device_detect()) { ?> <meta name="HandheldFriendly" content="true" /> <?php } ?> <link href="<?php echo T3Path::getUrl('images/favicon.ico'); ?> " rel="shortcut icon" type="image/x-icon" /> <?php JHTML::stylesheet('templates/system/css/system.css'); JHTML::stylesheet('templates/system/css/general.css');
public static function purge() { // Initialize some variables $input = JFactory::getApplication()->input; $layout = $input->getCmd('layout'); $template = $input->getCmd('template'); if (!$layout) { return self::error(JText::_('T3_LAYOUT_UNKNOW_ACTION')); } // delete custom layout $layoutfile = T3Path::getLocalPath('tpls/' . $layout . '.php'); $initfile = T3Path::getLocalPath('etc/layout/' . $layout . '.ini'); // delete default layout $defaultlayoutfile = T3_TEMPLATE_PATH . '/tpls/' . $layout . '.php'; $defaultinitfile = T3_TEMPLATE_PATH . '/etc/layout/' . $layout . '.ini'; if (!@JFile::delete($layoutfile) || !@JFile::delete($defaultlayoutfile) || !@JFile::delete($initfile) || !@JFile::delete($defaultinitfile)) { return self::error(JText::_('T3_LAYOUT_DELETE_FAIL')); } else { return self::response(array('successful' => JText::_('T3_LAYOUT_DELETE_SUCCESSFULLY'), 'layout' => $layout, 'type' => 'delete')); } }
/** * Clean T3 cache * If $t3assets > 0, deleted all cached content in defaultgroup * If $t3assets > 1, deleted all cached content in assets group * If $t3assets > 2, deleted all cached content in css/js optimize folder * * @param int $t3assets Level cache * * @return void */ private function _clean($t3assets = 0) { $cache = $this->cache; // Clear cache in default group folder if ($t3assets > 0) { $cache->clean(); } // Clear cache in assets folder if ($t3assets > 1) { $cache->clean(self::T3_CACHE_ASSETS); } if ($t3assets > 2) { //clean t3-assets folder, the cache for js/css $templates = T3Common::get_active_templates(); //T3Common::log(var_export($templates, true)); foreach ($templates as $template) { $file = T3Path::path("templates/{$template}") . DS . 'params.ini'; if (is_file($file)) { $content = file_get_contents($file); $params = new JParameter($content); $cache_path = $params->get('optimize_folder', 't3-assets'); $path = T3Path::path($cache_path); //T3Common::log($path); if (is_dir($path)) { @JFolder::delete($path); } } } } }
/** * Return the pagination footer. * * @return string Pagination footer. * * @since 11.1 */ public function getListFooter() { $app = JFactory::getApplication(); $list = array(); $list['prefix'] = $this->prefix; $list['limit'] = $this->limit; $list['limitstart'] = $this->limitstart; $list['total'] = $this->total; $list['limitfield'] = $this->getLimitBox(); $list['pagescounter'] = $this->getPagesCounter(); $list['pageslinks'] = $this->getPagesLinks(); // T3: detect if chrome pagination.php in template or in plugin $chromePath = T3Path::getPath('html/pagination.php'); // $chromePath = JPATH_THEMES . '/' . $app->getTemplate() . '/html/pagination.php'; if (file_exists($chromePath)) { include_once $chromePath; if (function_exists('pagination_list_footer')) { return pagination_list_footer($list); } } return $this->_list_footer($list); }
/** * Add some other condition assets (css, javascript) */ function addExtraAssets() { $base = JURI::base(true); $regurl = '#(http|https)://([a-zA-Z0-9.]|%[0-9A-Za-z]|/|:[0-9]?)*#iu'; foreach (array(T3_PATH, T3_TEMPLATE_PATH) as $bpath) { //full path $afile = $bpath . '/etc/assets.xml'; if (is_file($afile)) { //load xml $axml = JFactory::getXML($afile); //parse stylesheets first if exist if ($axml) { foreach ($axml as $node => $nodevalue) { //ignore others node if ($node == 'stylesheets' || $node == 'scripts') { foreach ($nodevalue->file as $file) { $compatible = $file['compatible']; if ($compatible) { $parts = explode(' ', $compatible); $operator = '='; //exact equal to $operand = $parts[1]; 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') { $this->addStylesheet($url); } else { $this->addScript($url); } } } } } } } } }
/** * Get theme path * * @param string $name Theme name * @param bool $local Indicate theme is local or not * * @return string */ public static function getThemePath($name, $local = true) { $path = T3Path::path(T3_TEMPLATE); // Check template use newest folder structure or not // If themes is exists, considered as template use newest folder structure if (@is_dir($path . DS . 'themes')) { $path .= DS . 'themes' . DS . $name; } else { if ($local) { $path .= DS . 'local' . DS . 'themes' . DS . $name; } else { $path .= DS . 'core' . DS . 'themes' . DS . $name; } } return $path; }
/** * 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); } } } }
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; 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) { $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 $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); } } } } } $jdoc->addScriptDeclaration(' var T3Theme = window.T3Theme || {}; T3Theme.vars = ' . json_encode($params->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){ } }'); } }
/** * function loadParam * load and re-render parameters * * @return render success or not */ function renderAdmin() { $frwXml = T3_ADMIN_PATH . '/' . T3_ADMIN . '.xml'; $tplXml = T3_TEMPLATE_PATH . '/templateDetails.xml'; $cusXml = T3Path::getPath('etc/assets.xml'); $jtpl = T3_ADMIN_PATH . '/admin/tpls/default.php'; if (file_exists($tplXml) && file_exists($jtpl)) { T3::import('depend/t3form'); //get the current joomla default instance $form = JForm::getInstance('com_templates.style', 'style', array('control' => 'jform', 'load_data' => true)); //wrap $form = new T3Form($form); //remove all fields from group 'params' and reload them again in right other base on template.xml $form->removeGroup('params'); //load the template $form->loadFile(T3_PATH . '/params/template.xml'); //overwrite / extend with params of template $form->loadFile($tplXml, true, '//config'); //overwrite / extend with custom config in custom/etc/assets.xml if ($cusXml && file_exists($cusXml)) { $form->loadFile($cusXml, true, '//config'); } // extend parameters T3Bot::prepareForm($form); $xml = JFactory::getXML($tplXml); $fxml = JFactory::getXML($frwXml); $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('id, title')->from('#__template_styles')->where('template=' . $db->quote(T3_TEMPLATE)); $db->setQuery($query); $styles = $db->loadObjectList(); foreach ($styles as $key => &$style) { $style->title = ucwords(str_replace('_', ' ', $style->title)); } $session = JFactory::getSession(); $t3lock = $session->get('T3.t3lock', 'overview_params'); $session->set('T3.t3lock', null); $input = JFactory::getApplication()->input; include $jtpl; /* //search for global parameters $japp = JFactory::getApplication(); $pglobals = array(); foreach($form->getGroup('params') as $param){ if($form->getFieldAttribute($param->fieldname, 'global', 0, 'params')){ $pglobals[] = array('name' => $param->fieldname, 'value' => $form->getValue($param->fieldname, 'params')); } } $japp->setUserState('oparams', $pglobals); */ return true; } return false; }
function loadBlock($block) { $block_path = T3Path::findBlock($block); if ($block_path) { include $block_path; } }
public static function cb_import_path($match) { $f = $match[1]; $newf = T3Path::cleanPath(self::$_path . $f); return str_replace($f, $newf, $match[0]); }
/** * Sets an entire array of search paths for templates or resources. * * @param string The type of path to set, typically 'template'. * @param string|array The new set of search paths. If null or false, resets to the current directory only. */ protected function _setPath($type, $path) { jimport('joomla.application.helper'); $component = JApplicationHelper::getComponentName(); $app = JFactory::getApplication(); // Clear out the prior search dirs $this->_path[$type] = array(); // Actually add the user-specified directories $this->_addPath($type, $path); // Always add the fallback directories as last resort switch (strtolower($type)) { case 'template': // Set the alternative template search dir if (isset($app)) { $component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $component); $fallback = JPATH_THEMES . '/' . $app->getTemplate() . '/html/' . $component . '/' . $this->getName(); //if it is T3 template, update search path for template if (T3Common::detect()) { if (is_array($fallback1 = T3Path::getPath('html' . DS . $component . DS . $this->getName(), true))) { $fallback = array_reverse($fallback1); } } $this->_addPath('template', $fallback); } break; } }
/** * Get theme list * * @param string $template Template name * * @return array List of theme */ function getT3Themes($template) { $themes = array(); $themes["engine.default"] = T3Path::path(T3_BASETHEME, false); $path = T3Path::path(T3_TEMPLATE) . DS . 'themes'; // Check if template use newest folder structure or not // If themes folder is exists in template folder, considered as template use newest folder structure if (@is_dir($path)) { $path = T3Path::path(T3_TEMPLATE, false) . DS . 'themes'; $_themes = @JFolder::folders($path); if (is_array($_themes)) { foreach ($_themes as $theme) { if ('.local' == substr($theme, -6)) { $themes['local' . substr($theme, 0, -6)] = $path . DS . $theme; } else { $themes['core' . $theme] = $path . DS . $theme; } } } } else { // Compatible: if template use $path = T3Path::path(T3_TEMPLATE_CORE) . DS . 'themes'; $_themes = @JFolder::folders($path); if (is_array($_themes)) { foreach ($_themes as $theme) { $themes["core.{$theme}"] = T3Path::path(T3_TEMPLATE_CORE, false) . DS . 'themes' . DS . $theme; } } $path = T3Path::path(T3_TEMPLATE_LOCAL) . DS . 'themes'; if (is_dir($path)) { $_themes = @JFolder::folders($path); if (is_array($_themes)) { foreach ($_themes as $theme) { $themes["local.{$theme}"] = T3Path::path(T3_TEMPLATE_LOCAL, false) . DS . 'themes' . DS . $theme; } } } } return $themes; }
/** * Implement event onGetLayoutPath to return the layout which override by T3 & T3 templates * This event is fired by overriding ModuleHelper class * Return path to layout if found, false if not * * @param string $module The name of the module * @param string $layout The name of the module layout. If alternative * layout, in the form template:filename. * * @return null */ function onGetLayoutPath($module, $layout) { // Detect layout path in T3 themes if (T3Common::detect()) { $tPath = T3Path::getPath('html' . DS . $module . DS . $layout . '.php', false); if ($tPath) { return $tPath; } } return false; }
function saveLayout() { global $mainframe; t3_import('core/admin/util'); // Initialize some variables $client =& JApplicationHelper::getClientInfo(JRequest::getVar('client', '0', '', 'int')); //$json = JRequest::getVar('json'); $json = JRequest::getString('json', '', 'default', 2); $data = json_decode($json); $data = str_replace(array("\\n", "\\t"), array("\n", "\t"), $data) . ' '; $data = str_replace('\\', '', $data); $template = JRequest::getCmd('template'); $layout = JRequest::getCmd('layout'); $errors = array(); $result = array(); if (!$template || !$layout) { $result['error'] = JText::_('No template specified or Layout name contains space or special chracters.'); echo json_encode($result); exit; } // Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); $file = T3Path::path(T3_TEMPLATE_LOCAL) . DS . 'etc' . DS . 'layouts' . DS . strtolower($layout) . '.xml'; $file_core = T3Path::path(T3_TEMPLATE_CORE) . DS . 'etc' . DS . 'layouts' . DS . strtolower($layout) . '.xml'; //get layouts from core $file_base = T3Path::path(T3_BASETHEME) . DS . 'etc' . DS . 'layouts' . DS . strtolower($layout) . '.xml'; if (file_exists($file) || file_exists($file_core) || file_exists($file_base)) { $result['type'] = 'edit'; } else { $result['type'] = 'new'; } if (JFile::exists($file)) { @chmod($file, 0777); } $return = JFile::write($file, $data); // Try to make the params file unwriteable if (!$ftp['enabled'] && JPath::isOwner($file) && !JPath::setPermissions($file, '0555')) { $errors[] = sprintf(JText::_('Could not make the %s file unwritable'), $file); } if (!$return) { $errors[] = JText::_('Operation Failed') . ': ' . JText::sprintf('Failed to open file for writing.', $file); } if ($errors) { $result['error'] = implode('<br/>', $errors); } else { if ($result['type'] == 'new') { $result['successful'] = sprintf(JText::_('Layout %s was successfully created!'), $layout); } else { $result['successful'] = sprintf(JText::_('SAVE %s LAYOUT SUCCESSFULLY'), $layout); } $result['layout'] = $layout; } echo json_encode($result); exit; }
/** * Clean T3 cache * If $t3assets > 0, deleted all cached content in defaultgroup * If $t3assets > 1, deleted all cached content in assets group * If $t3assets > 2, deleted all cached content in css/js optimize folder * * @param int $t3assets Level cache * * @return void */ private function _clean($t3assets = 0) { $cache = $this->cache; // Clear cache in default group folder if ($t3assets > 0) { $cache->clean(); } // Clear cache in assets folder if ($t3assets > 1) { $cache->clean(self::T3_CACHE_ASSETS); } if ($t3assets > 2) { //clean t3-assets folder, the cache for js/css $templates = T3Common::get_active_templates(); //T3Common::log(var_export($templates, true)); foreach ($templates as $template) { $file = T3Path::path("templates/{$template}") . DS . 'params.ini'; if (is_file($file)) { $content = file_get_contents($file); // $params = new JParameter($content); // Strict standards: Declaration of JParameter::loadSetupFile() should be compatible with that of JRegistry::loadSetupFile() $params = $content; if (!$content instanceof JRegistry) { $params = new JRegistry($content); } $cache_path = $params->get('optimize_folder', 't3-assets'); $path = T3Path::path($cache_path); //T3Common::log($path); if (is_dir($path)) { @JFolder::delete($path); } } } } }
/** * Implement event onGetLayoutPath to return the layout which override by T3 & T3 templates * This event is fired by overriding ModuleHelper class * Return path to layout if found, false if not * * @param string $module The name of the module * @param string $layout The name of the module layout. If alternative * layout, in the form template:filename. * * @return null */ function onGetLayoutPath($module, $layout) { // Detect layout path in T3 themes if (defined('T3_PLUGIN') && T3::detect()) { T3::import('core/path'); $tPath = T3Path::getPath('html/' . $module . '/' . $layout . '.php'); if ($tPath) { return $tPath; } } return false; }