/** * @param string $theme template theme * @param string $dir direction (ltr or rtl) * @return mixed */ public static function buildVars($theme = null, $dir = null) { $app = JFactory::getApplication(); $params = null; if ($app->isAdmin()) { $params = $app->getUserState('current_template_params'); } else { $tpl = $app->getTemplate(true); $params = $tpl->params; } if (!$params) { CANVAS::error(JText::_('CANVAS_MSG_CANNOT_DETECT_TEMPLATE')); exit; } $responsive = $params->get('responsive', 1); // theme style if ($theme === null) { $theme = $params->get('theme'); } // --------- // preset selector from url //---------- if ($theme === null) { $theme = $app->getUserState('vars_preset', null); } $theme = JRequest::getVar('theme', null) ? JRequest::getVar('theme', '') : $theme; $app->setUserState('vars_preset', $theme); // ------------------------ // end preset selector from url // detect RTL if ($dir === null) { $doc = JFactory::getDocument(); $dir = $doc->direction; } $app->setUserState('current_theme', $theme); $app->setUserState('current_direction', $dir); $app->setUserState('current_key_sufix', "_{$theme}_{$dir}"); $path = CANVAS_TEMPLATE_PATH . '/less/vars.less'; if (!is_file($path)) { CANVAS::error(JText::_('CANVAS_MSG_LESS_NOT_VALID')); exit; } // force re-build less if switch responsive mode and get last modified time if ($responsive !== self::getState('current_responsive')) { self::setState('current_responsive', $responsive); $last_modified = time(); touch($path, $last_modified); } else { $last_modified = filemtime($path); } $vars_content = file_get_contents($path); $vars_urls = array(); preg_match_all('#^\\s*@import\\s+"([^"]*)"#im', $vars_content, $matches); if (count($matches[0])) { foreach ($matches[1] as $url) { $path = CANVASPath::cleanPath(CANVAS_TEMPLATE_PATH . '/less/' . $url); if (file_exists($path)) { $last_modified = max($last_modified, filemtime($path)); $vars_urls[] = CANVASPath::cleanPath(CANVAS_TEMPLATE_REL . '/less/' . $url); } } } // add override variables $paths = array(); if ($theme) { $paths[] = CANVAS_TEMPLATE_REL . "/less/themes/{$theme}/variables.less"; $paths[] = CANVAS_TEMPLATE_REL . "/less/themes/{$theme}/variables-custom.less"; } if ($dir == 'rtl') { $paths[] = CANVAS_TEMPLATE_REL . "/less/rtl/variables.less"; if ($theme) { $paths[] = CANVAS_TEMPLATE_REL . "/less/rtl/themes/{$theme}/variables.less"; } } if (!defined('CANVAS_LOCAL_DISABLED')) { $paths[] = CANVAS_LOCAL_REL . "/less/variables.less"; if ($theme) { $paths[] = CANVAS_LOCAL_REL . "/less/themes/{$theme}/variables.less"; $paths[] = CANVAS_LOCAL_REL . "/less/themes/{$theme}/variables-custom.less"; } if ($dir == 'rtl') { $paths[] = CANVAS_LOCAL_REL . "/less/rtl/variables.less"; if ($theme) { $paths[] = CANVAS_LOCAL_REL . "/less/rtl/themes/{$theme}/variables.less"; } } } if (!$responsive) { $paths[] = CANVAS_REL . '/less/non-responsive-variables.less'; $paths[] = CANVAS_TEMPLATE_REL . '/less/non-responsive-variables.less'; } foreach ($paths as $file) { if (is_file(JPATH_ROOT . '/' . $file)) { $last_modified = max($last_modified, filemtime(JPATH_ROOT . '/' . $file)); $vars_urls[] = $file; } } if (self::getState('vars_last_modified') != $last_modified) { self::setState('vars_last_modified', $last_modified); } self::setState('vars_urls_content', implode('|', $vars_urls)); }
/** * initialize CANVAS */ public static function init($xml) { $app = JFactory::getApplication(); $input = $app->input; $coretheme = isset($xml->canvas) && isset($xml->canvas->base) ? trim((string) $xml->canvas->base) : 'base'; // check coretheme in media/canvas/themes folder // if not exists, use default base theme in CANVAS if (!$coretheme) { $coretheme = 'base'; } foreach (array(CANVAS_EX_BASE_PATH, CANVAS_ADMIN_PATH) as $basedir) { if (is_dir($basedir . '/' . $coretheme)) { if (is_file($basedir . '/' . $coretheme . '/define.php')) { include_once $basedir . '/' . $coretheme . '/define.php'; } break; } } if (!defined('CANVAS')) { // get ready for the canvas core base theme include_once CANVAS_CORE_BASE_PATH . '/define.php'; } if (!defined('CANVAS')) { CANVAS::error(JText::sprintf('CANVAS_MSG_FAILED_INIT_BASE', $coretheme)); exit; } define('CANVAS_CORE_TEMPLATE_BASE', $coretheme); define('CANVAS_TEMPLATE', $xml->tplname); define('CANVAS_TEMPLATE_URL', JURI::root(true) . '/templates/' . CANVAS_TEMPLATE); define('CANVAS_TEMPLATE_PATH', JPATH_ROOT . '/templates/' . CANVAS_TEMPLATE); define('CANVAS_TEMPLATE_REL', 'templates/' . CANVAS_TEMPLATE); define('CANVAS_LOCAL_URL', CANVAS_TEMPLATE_URL . '/' . CANVAS_LOCAL_DIR); define('CANVAS_LOCAL_PATH', CANVAS_TEMPLATE_PATH . '/' . CANVAS_LOCAL_DIR); define('CANVAS_LOCAL_REL', CANVAS_TEMPLATE_REL . '/' . CANVAS_LOCAL_DIR); if ($input->getCmd('themer', 0)) { define('CANVAS_THEMER', 1); } if (!$app->isAdmin()) { $params = $app->getTemplate(true)->params; define('CANVAS_DEV_FOLDER', $params->get('canvas-assets', 'canvas-assets') . '/dev'); define('CANVAS_DEV_MODE', $params->get('devmode', 0)); } else { $params = self::getTemplate()->params; define('CANVAS_DEV_FOLDER', $params->get('canvas-assets', 'canvas-assets') . '/dev'); } if (!is_dir(JPATH_ROOT . '/' . CANVAS_DEV_FOLDER)) { jimport('joomla.filesystem.folder'); JFolder::create(JPATH_ROOT . '/' . CANVAS_DEV_FOLDER); } if ($input->getCmd('canvaslock', '')) { JFactory::getSession()->set('CANVAS.canvaslock', $input->getCmd('canvaslock', '')); $input->set('canvaslock', null); } // load core library CANVAS::import('core/path'); CANVAS::import('core/canvasj'); if (!$app->isAdmin()) { if (version_compare(JVERSION, '3.0', 'ge')) { // override core joomla class // JViewLegacy CANVAS::register('JViewLegacy', CANVAS_ADMIN_PATH . '/includes/joomla30/viewlegacy.php'); // JModuleHelper CANVAS::register('JModuleHelper', CANVAS_ADMIN_PATH . '/includes/joomla30/modulehelper.php'); // JPagination CANVAS::register('JPagination', CANVAS_ADMIN_PATH . '/includes/joomla30/pagination.php'); // Register CANVAS Layout File to put a canvas base layer for layout files CANVAS::register('JLayoutFile', CANVAS_ADMIN_PATH . '/includes/joomla25/layout/file.php'); } else { // override core joomla class // JView CANVAS::register('JView', CANVAS_ADMIN_PATH . '/includes/joomla25/view.php', 'joomla.application.component.view'); // JModuleHelper CANVAS::register('JModuleHelper', CANVAS_ADMIN_PATH . '/includes/joomla25/modulehelper.php', 'joomla.application.module.helper'); // JPagination CANVAS::register('JPagination', CANVAS_ADMIN_PATH . '/includes/joomla25/pagination.php', 'joomla.html.pagination'); //register layout CANVAS::register('JLayout', CANVAS_ADMIN_PATH . '/includes/joomla25/layout/layout.php'); CANVAS::register('JLayoutBase', CANVAS_ADMIN_PATH . '/includes/joomla25/layout/base.php'); CANVAS::register('JLayoutFile', CANVAS_ADMIN_PATH . '/includes/joomla25/layout/file.php'); CANVAS::register('JLayoutHelper', CANVAS_ADMIN_PATH . '/includes/joomla25/layout/helper.php'); CANVAS::register('JHtmlBootstrap', CANVAS_ADMIN_PATH . '/includes/joomla25/html/bootstrap.php'); CANVAS::register('JHtmlString', CANVAS_ADMIN_PATH . '/includes/joomla25/html/string.php'); // load j25 compat language JFactory::getLanguage()->load('plg_system_canvas.j25.compat', JPATH_ADMINISTRATOR); } // import renderer CANVAS::import('renderer/pageclass'); CANVAS::import('renderer/megamenu'); CANVAS::import('renderer/canvasbootstrap'); } else { } // capture for tm=1 => show theme magic if ($input->getCmd('tm') == 1) { $input->set('canvasaction', 'theme'); $input->set('canvastask', 'thememagic'); } }