コード例 #1
0
 /**
  * Preview changes to the custom css/less
  *
  */
 function PreviewCSS()
 {
     global $page, $langmessage;
     $layout_info = common::LayoutInfo($this->curr_layout, false);
     $theme_colors = $this->GetThemeColors($layout_info['dir']);
     $color = $layout_info['theme_color'];
     // which color option
     if (array_key_exists('color', $_REQUEST)) {
         if (!isset($theme_colors[$color])) {
             message($langmessage['OOPS'] . ' (Invalid Color)');
             return false;
         }
         $color = $_REQUEST['color'];
     }
     $page->theme_color = $color;
     $page->theme_rel = dirname($page->theme_rel) . '/' . $color;
     $page->theme_path = dirname($page->theme_path) . '/' . $color;
     // which css files
     $less = array();
     if (file_exists($page->theme_dir . '/' . $page->theme_color . '/style.css')) {
         $page->css_user[] = rawurldecode($page->theme_path) . '/style.css';
     } else {
         $less[] = $page->theme_dir . '/' . $page->theme_color . '/style.less';
     }
     // variables.less
     $var_file = $page->theme_dir . '/' . $page->theme_color . '/variables.less';
     if (file_exists($var_file)) {
         $less[] = $var_file;
     }
     $temp = trim($_REQUEST['css']);
     if (!empty($temp)) {
         $less[] = $_REQUEST['css'] . "\n";
         //make sure this is seen as code and not a filename
     }
     if (count($less)) {
         $compiled = gpOutput::ParseLess($less);
         if (!$compiled) {
             message($langmessage['OOPS'] . ' (Invalid LESS)');
             return false;
         }
         $page->head .= '<style>' . $compiled . '</style>';
     }
     $page->get_theme_css = false;
 }
コード例 #2
0
ファイル: gpOutput.php プロジェクト: Bomberus/gpEasy-CMS
 /**
  * Convert a .less file to .css and include it in the page
  * @param mixed $less_files A strin or array of less filesThe absolute or relative path of the .less file
  *
  */
 static function CacheLess($less_files)
 {
     global $dataDir;
     //generage the name of the css file from the modified times and content length of each imported less file
     $files_hash = common::ArrayHash($less_files);
     $list_file = $dataDir . '/data/_cache/less_' . $files_hash . '.list';
     if (file_exists($list_file)) {
         $list = explode("\n", file_get_contents($list_file));
         //pop the etag
         $etag = array_pop($list);
         if (!ctype_alnum($etag)) {
             $list[] = $etag;
             $etag = false;
         }
         // generate an etag if needed or if logged in
         if (!$etag || common::LoggedIn()) {
             $etag = common::FilesEtag($list);
         }
         $compiled_name = 'less_' . $files_hash . '_' . $etag . '.css';
         $compiled_file = '/data/_cache/' . $compiled_name;
         if (file_exists($dataDir . $compiled_file)) {
             //msg('not using cache');
             return $compiled_file;
         }
     }
     $less_files = (array) $less_files;
     $compiled = gpOutput::ParseLess($less_files, $files_hash);
     if (!$compiled) {
         return false;
     }
     // generate the file name
     $etag = common::FilesEtag($less_files);
     $compiled_name = 'less_' . $files_hash . '_' . $etag . '.css';
     $compiled_file = '/data/_cache/' . $compiled_name;
     // save the cache
     // use the last line for the etag
     $less_files[] = $etag;
     $cache = implode("\n", $less_files);
     if (!gpFiles::Save($list_file, $cache)) {
         return false;
     }
     //save the css
     if (file_put_contents($dataDir . $compiled_file, $compiled)) {
         return $compiled_file;
     }
     return false;
 }