/** * Compile LESS to CSS for a specific theme or all themes * @param string $theme the specific theme */ public static function compileAll($theme = null) { $params = T3::getTplParams(); JFactory::getApplication()->setUserState('current_template_params', $params); // get files need to compile $files = array(); $toPath = T3Path::getLocalPath('', true); // t3 core plugin files $t3files = array('less/frontend-edit.less', 'less/legacy-grid.less', 'less/legacy-navigation.less', 'less/megamenu.less', 'less/off-canvas.less'); // all less file in the template folder $lessFiles = JFolder::files(T3_TEMPLATE_PATH, '.less', true, true, array('rtl', 'themes', '.svn', 'CVS', '.DS_Store', '__MACOSX')); $relLessFiles = array(); $importedFiles = array(); foreach ($lessFiles as $file) { $file = str_replace('\\', '/', $file); $lessContent = file_get_contents($file); $rel = ltrim(str_replace(T3_TEMPLATE_PATH, '', $file), '/'); $reldir = dirname($rel); $ignore = true; if (preg_match_all('#^\\s*@import\\s+"([^"]*)"#im', $lessContent, $matches)) { foreach ($matches[1] as $if) { $if = T3Path::cleanPath($reldir . '/' . $if); if (!in_array($if, $importedFiles)) { $importedFiles[] = $if; } // check if this file import anything in main less folder. if yes, put it in the compile list if (preg_match('@^less/@', $if)) { $ignore = false; } } } if (!$ignore) { $relLessFiles[] = $rel; } } $lessFiles = $relLessFiles; // ignore files which are imported in other file foreach ($lessFiles as $f) { if (!in_array($f, $importedFiles) && !preg_match('@^less/(themes|rtl)/@i', $f)) { $files[] = $f; } } //build t3files foreach ($t3files as $key => $file) { if (in_array($file, $files)) { unset($t3files[$key]); } } // build default if (!$theme || $theme == 'default') { self::buildVars('', 'ltr'); // compile all less files in template "less" folder foreach ($files as $lessPath) { $cssPath = self::getOutputCssPath($lessPath); self::compileCss(T3_TEMPLATE_REL . '/' . $lessPath, $toPath . $cssPath); } // if the template not overwrite the t3 core, we will compile those missing files if (!empty($t3files)) { foreach ($t3files as $lessPath) { $cssPath = self::getOutputCssPath($lessPath); self::compileCss(T3_REL . '/' . $lessPath, $toPath . $cssPath); } } } // build themes if (!$theme) { // get themes $themes = JFolder::folders(T3_TEMPLATE_PATH . '/less/themes'); } else { $themes = $theme != 'default' ? (array) $theme : array(); } if (is_array($themes)) { foreach ($themes as $t) { self::buildVars($t, 'ltr'); // compile foreach ($files as $lessPath) { $cssPath = self::getOutputCssPath($lessPath, $t); self::compileCss(T3_TEMPLATE_REL . '/' . $lessPath, $toPath . $cssPath); } if (!empty($t3files)) { foreach ($t3files as $lessPath) { $cssPath = self::getOutputCssPath($lessPath, $t); self::compileCss(T3_REL . '/' . $lessPath, $toPath . $cssPath); } } } } // compile rtl css if ($params && $params->get('build_rtl', 0)) { // compile default if (!$theme || $theme == 'default') { self::buildVars('', 'rtl'); // compile foreach ($files as $lessPath) { $cssPath = self::getOutputCssPath($lessPath, '', true); self::compileCss(T3_TEMPLATE_REL . '/' . $lessPath, $toPath . $cssPath); } if (!empty($t3files)) { foreach ($t3files as $lessPath) { $cssPath = self::getOutputCssPath($lessPath, '', true); self::compileCss(T3_REL . '/' . $lessPath, $toPath . $cssPath); } } } if (is_array($themes)) { // rtl for themes foreach ($themes as $t) { self::buildVars($t, 'rtl'); // compile foreach ($files as $lessPath) { $cssPath = self::getOutputCssPath($lessPath, $t, true); self::compileCss(T3_TEMPLATE_REL . '/' . $lessPath, $toPath . $cssPath); } if (!empty($t3files)) { foreach ($t3files as $lessPath) { $cssPath = self::getOutputCssPath($lessPath, $t, true); self::compileCss(T3_REL . '/' . $lessPath, $toPath . $cssPath); } } } } } }
/** * Compile LESS to CSS for a specific theme or all themes * @param string $theme the specific theme */ public static function compileAll($theme = null) { $params = T3::getTplParams(); JFactory::getApplication()->setUserState('current_template_params', $params); // get files need to compile $files = array(); $lesspath = T3_TEMPLATE_REL . '/less/'; $csspath = T3Path::getLocalPath('css/', true); $fullpath = JPath::clean(JPATH_ROOT . '/' . $lesspath); // t3 core plugin files $t3files = array('frontend-edit', 'legacy-grid', 'legacy-navigation', 'megamenu', 'off-canvas'); // all less file in less folders $lessFiles = JFolder::files($fullpath, '.less', true, true, array('rtl', 'themes', '.svn', 'CVS', '.DS_Store', '__MACOSX')); $lessContent = ''; $relLessFiles = array(); foreach ($lessFiles as $file) { $lessContent .= JFile::read($file) . "\n"; $relLessFiles[] = ltrim(str_replace($fullpath, '', $file), '/\\'); } $lessFiles = $relLessFiles; // get files imported in this list if (preg_match_all('#^\\s*@import\\s+"([^"]*)"#im', $lessContent, $matches)) { foreach ($lessFiles as $f) { if (!in_array($f, $matches[1])) { $files[] = substr($f, 0, -5); } } //build t3files foreach ($t3files as $key => $file) { if (in_array($file, $files)) { unset($t3files[$key]); } } } // build default if (!$theme || $theme == 'default') { self::buildVars('', 'ltr'); // compile all less files in template "less" folder foreach ($files as $file) { self::compileCss($lesspath . $file . '.less', $csspath . $file . '.css'); } // if the template not overwrite the t3 core, we will compile those missing files if (!empty($t3files)) { foreach ($t3files as $file) { self::compileCss(T3_REL . '/less/' . $file . '.less', $csspath . $file . '.css'); } } } // build themes if (!$theme) { // get themes $themes = JFolder::folders(JPATH_ROOT . '/' . $lesspath . '/themes'); } else { $themes = $theme != 'default' ? (array) $theme : array(); } if (is_array($themes)) { foreach ($themes as $t) { self::buildVars($t, 'ltr'); // compile foreach ($files as $file) { self::compileCss($lesspath . $file . '.less', $csspath . 'themes/' . $t . '/' . $file . '.css'); } if (!empty($t3files)) { foreach ($t3files as $file) { self::compileCss(T3_REL . '/less/' . $file . '.less', $csspath . 'themes/' . $t . '/' . $file . '.css'); } } } } // compile rtl css if ($params && $params->get('build_rtl', 0)) { // compile default if (!$theme || $theme == 'default') { self::buildVars('', 'rtl'); // compile foreach ($files as $file) { self::compileCss($lesspath . $file . '.less', $csspath . 'rtl/' . $file . '.css'); } if (!empty($t3files)) { foreach ($t3files as $file) { self::compileCss(T3_REL . '/less/' . $file . '.less', $csspath . 'rtl/' . $file . '.css'); } } } if (is_array($themes)) { // rtl for themes foreach ($themes as $t) { self::buildVars($t, 'rtl'); // compile foreach ($files as $file) { self::compileCss($lesspath . $file . '.less', $csspath . 'rtl/' . $t . '/' . $file . '.css'); } if (!empty($t3files)) { foreach ($t3files as $file) { self::compileCss(T3_REL . '/less/' . $file . '.less', $csspath . 'rtl/' . $t . '/' . $file . '.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')); } }
/** * * Clone Profile */ public static function duplicate($path) { $theme = JFactory::getApplication()->input->getCmd('theme'); $from = JFactory::getApplication()->input->getCmd('from'); $result = array(); if (empty($theme) || empty($from)) { return self::error(JText::_('T3_TM_INVALID_DATA_TO_SAVE')); } $source = $path . '/less/themes/' . $from; if (!JFolder::exists($source)) { // try to find the source in local $source = T3Path::getPath('less/themes/' . $from); if (!$source) { return self::error(JText::sprintf('T3_TM_NOT_FOUND', $from)); } } // $dest = $path . '/less/themes/' . $theme; // clone to local $dest = T3Path::getLocalPath('less/themes/' . $theme); if (JFolder::exists($dest)) { return self::error(JText::sprintf('T3_TM_EXISTED', $theme)); } // copy $from to $theme $status = @JFolder::copy($source, $dest); $rtlsource = $path . '/less/rtl/' . $from; if (!JFolder::exists($rtlsource)) { // try to find the source in local $rtlsource = T3Path::getPath('less/rtl/' . $from); } if ($rtlsource) { $rtldest = T3Path::getLocalPath('less/rtl/' . $theme); // copy $from to $theme @JFolder::copy($rtlsource, $rtldest); } $result = array(); if ($status) { $result['success'] = JText::_('T3_TM_CLONE_SUCCESSFULLY'); $result['theme'] = $theme; $result['reset'] = true; $result['type'] = 'duplicate'; } else { return self::error(JText::_('T3_TM_OPERATION_FAILED')); } //LessHelper::compileForTemplate(T3_TEMPLATE_PATH , $theme); T3::import('core/less'); T3Less::compileAll($theme); return self::response($result); }