예제 #1
0
 /**
  * Compile LESS to CSS for a specific theme or all themes
  * @param  string  $theme  the specific theme
  */
 public static function compileAll($theme = null)
 {
     $params = CANVAS::getTplParams();
     JFactory::getApplication()->setUserState('current_template_params', $params);
     // get files need to compile
     $files = array();
     $lesspath = CANVAS_TEMPLATE_REL . '/less/';
     $csspath = CANVASPath::getLocalPath('css/', true);
     $fullpath = JPath::clean(JPATH_ROOT . '/' . $lesspath);
     // canvas core plugin files
     $canvasfiles = 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 canvasfiles
         foreach ($canvasfiles as $key => $file) {
             if (in_array($file, $files)) {
                 unset($canvasfiles[$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 canvas core, we will compile those missing files
         if (!empty($canvasfiles)) {
             foreach ($canvasfiles as $file) {
                 self::compileCss(CANVAS_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($canvasfiles)) {
                 foreach ($canvasfiles as $file) {
                     self::compileCss(CANVAS_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($canvasfiles)) {
                 foreach ($canvasfiles as $file) {
                     self::compileCss(CANVAS_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($canvasfiles)) {
                     foreach ($canvasfiles as $file) {
                         self::compileCss(CANVAS_REL . '/less/' . $file . '.less', $csspath . 'rtl/' . $t . '/' . $file . '.css');
                     }
                 }
             }
         }
     }
 }
예제 #2
0
 /**
  *
  * Show thememagic form
  */
 public static function megamenu()
 {
     $tplparams = CANVAS::getTplParams();
     $url = JFactory::getURI();
     $url->delVar('canvasaction');
     $url->delVar('canvastask');
     $referer = $url->toString();
     $template = CANVAS_TEMPLATE;
     $styleid = JFactory::getApplication()->input->getCmd('id');
     $mm_type = $tplparams && $tplparams instanceof JRegistry ? $tplparams->get('mm_type', '') : null;
     //Keepalive
     $config = JFactory::getConfig();
     $lifetime = $config->get('lifetime') * 60000;
     $refreshTime = $lifetime <= 60000 ? 30000 : $lifetime - 60000;
     // Refresh time is 1 minute less than the liftime assined in the configuration.php file.
     // The longest refresh period is one hour to prevent integer overflow.
     if ($refreshTime > 3600000 || $refreshTime <= 0) {
         $refreshTime = 3600000;
     }
     //check config
     $currentconfig = $tplparams && $tplparams instanceof JRegistry ? $tplparams->get('mm_config', '') : null;
     if (!$currentconfig) {
         $currentconfig = '"{}"';
     }
     include CANVAS_ADMIN_PATH . '/admin/megamenu/megamenu.tpl.php';
     exit;
 }
예제 #3
0
 function replaceToolbar($body)
 {
     $canvastoolbar = CANVAS_ADMIN_PATH . '/admin/tpls/toolbar.php';
     $input = JFactory::getApplication()->input;
     if (file_exists($canvastoolbar) && class_exists('JToolBar')) {
         //get the existing toolbar html
         jimport('joomla.language.help');
         $params = CANVAS::getTplParams();
         $toolbar = JToolBar::getInstance('toolbar')->render('toolbar');
         $helpurl = JHelp::createURL($input->getCmd('view') == 'template' ? 'JHELP_EXTENSIONS_TEMPLATE_MANAGER_TEMPLATES_EDIT' : 'JHELP_EXTENSIONS_TEMPLATE_MANAGER_STYLES_EDIT');
         $helpurl = htmlspecialchars($helpurl, ENT_QUOTES);
         //render our toolbar
         ob_start();
         include $canvastoolbar;
         $canvastoolbar = ob_get_clean();
         //replace it
         $body = str_replace($toolbar, $canvastoolbar, $body);
     }
     return $body;
 }
예제 #4
0
 /**
  *
  * Show thememagic form
  */
 public static function thememagic($path)
 {
     $app = JFactory::getApplication();
     $input = $app->input;
     $isadmin = $app->isAdmin();
     if ($isadmin) {
         $tplparams = CANVAS::getTplParams();
     } else {
         $tplparams = $app->getTemplate(true)->params;
     }
     $url = $isadmin ? JUri::root(true) . '/index.php' : JUri::current();
     $url .= (preg_match('/\\?/', $url) ? '&' : '?') . 'themer=1';
     $url .= $tplparams->get('theme', -1) != -1 ? '&canvasstyle=' . $tplparams->get('theme') : '';
     if ($isadmin) {
         $url .= '&canvastmid=' . $input->getCmd('id');
     }
     $assetspath = CANVAS_TEMPLATE_PATH;
     $themepath = $assetspath . '/less/themes';
     if (!class_exists('JRegistryFormatLESS')) {
         include_once CANVAS_ADMIN_PATH . '/includes/format/less.php';
     }
     $themes = array();
     $jsondata = array();
     //push a default theme
     $tobj = new stdClass();
     $tobj->id = 'base';
     $tobj->title = JText::_('JDEFAULT');
     $themes['base'] = $tobj;
     $varfile = $assetspath . '/less/variables.less';
     if (file_exists($varfile)) {
         $params = new JRegistry();
         $params->loadString(JFile::read($varfile), 'LESS');
         $jsondata['base'] = $params->toArray();
     }
     if (JFolder::exists($themepath)) {
         $listthemes = JFolder::folders($themepath);
         if (count($listthemes)) {
             foreach ($listthemes as $theme) {
                 $varsfile = $themepath . '/' . $theme . '/variables-custom.less';
                 if (file_exists($varsfile)) {
                     $tobj = new stdClass();
                     $tobj->id = $theme;
                     $tobj->title = $theme;
                     //check for all less file in theme folder
                     $params = false;
                     $others = JFolder::files($themepath . '/' . $theme, '.less');
                     foreach ($others as $other) {
                         //get those developer custom values
                         if ($other == 'variables.less') {
                             $params = new JRegistry();
                             $params->loadString(JFile::read($themepath . '/' . $theme . '/variables.less'), 'LESS');
                         }
                         if ($other != 'variables-custom.less') {
                             $tobj->{$other} = true;
                         }
                     }
                     $cparams = new JRegistry();
                     $cparams->loadString(JFile::read($varsfile), 'LESS');
                     if ($params) {
                         foreach ($cparams->toArray() as $key => $value) {
                             $params->set($key, $value);
                         }
                     } else {
                         $params = $cparams;
                     }
                     $themes[$theme] = $tobj;
                     $jsondata[$theme] = $params->toArray();
                 }
             }
         }
     }
     $langs = array('addTheme' => JText::_('CANVAS_TM_ASK_ADD_THEME'), 'delTheme' => JText::_('CANVAS_TM_ASK_DEL_THEME'), 'overwriteTheme' => JText::_('CANVAS_TM_ASK_OVERWRITE_THEME'), 'correctName' => JText::_('CANVAS_TM_ASK_CORRECT_NAME'), 'themeExist' => JText::_('CANVAS_TM_EXISTED'), 'saveChange' => JText::_('CANVAS_TM_ASK_SAVE_CHANGED'), 'previewError' => JText::_('CANVAS_TM_PREVIEW_ERROR'), 'unknownError' => JText::_('CANVAS_MSG_UNKNOWN_ERROR'), 'lblCancel' => JText::_('JCANCEL'), 'lblOk' => JText::_('CANVAS_TM_LABEL_OK'), 'lblNo' => JText::_('JNO'), 'lblYes' => JText::_('JYES'), 'lblDefault' => JText::_('JDEFAULT'));
     //Keepalive
     $config = JFactory::getConfig();
     $lifetime = $config->get('lifetime') * 60000;
     $refreshTime = $lifetime <= 60000 ? 30000 : $lifetime - 60000;
     // Refresh time is 1 minute less than the liftime assined in the configuration.php file.
     // The longest refresh period is one hour to prevent integer overflow.
     if ($refreshTime > 3600000 || $refreshTime <= 0) {
         $refreshTime = 3600000;
     }
     $backurl = JFactory::getURI();
     $backurl->delVar('canvasaction');
     $backurl->delVar('canvastask');
     if (!$isadmin) {
         $backurl->delVar('tm');
         $backurl->delVar('themer');
     }
     CANVAS::import('depend/canvasform');
     $form = new CANVASForm('thememagic.themer', array('control' => 'canvasform'));
     $form->load(JFile::read(JFile::exists(CANVAS_TEMPLATE_PATH . '/thememagic.xml') ? CANVAS_TEMPLATE_PATH . '/thememagic.xml' : CANVAS_PATH . '/params/thememagic.xml'));
     $form->loadFile(CANVAS_TEMPLATE_PATH . '/templateDetails.xml', true, '//config');
     $tplform = new CANVASForm('thememagic.overwrite', array('control' => 'canvasform'));
     $tplform->loadFile(CANVAS_TEMPLATE_PATH . '/templateDetails.xml', true, '//config');
     $fieldSets = $form->getFieldsets('thememagic');
     $tplFieldSets = $tplform->getFieldsets('thememagic');
     $disabledFieldSets = array();
     foreach ($tplFieldSets as $name => $fieldSet) {
         if (isset($fieldSet->disabled)) {
             $disabledFieldSets[] = $name;
         }
     }
     include CANVAS_ADMIN_PATH . '/admin/thememagic/thememagic.tpl.php';
     exit;
 }