/** * {@inheritdoc} */ protected function _initCompiler() { if ($this->_compiler) { return $this->_compiler; } $this->_compiler = new \lessc(); if (class_exists('\\lessc_formatter_lessjs')) { $formatter = new \lessc_formatter_lessjs(); // configurate css view $formatter->openSingle = ' { '; $formatter->closeSingle = "}\n"; $formatter->close = "}\n"; $formatter->indentChar = ' '; $formatter->disableSingle = true; $formatter->breakSelectors = true; $formatter->assignSeparator = ': '; $formatter->selectorSeparator = ', '; $this->_compiler->setFormatter($formatter); } $this->_compiler->setPreserveComments(false); // Set paths $importPaths = (array) $this->_options->get('import_paths', []); foreach ($importPaths as $fullPath => $relPath) { $this->setImportPath($fullPath, $relPath); } // Set paths $this->_compiler->setVariables((array) $this->_options->get('global_vars', [])); return $this->_compiler; }
function Core_View_Helper_Css($files) { include_once LIBRARY_PATH . '/Less/lessc.inc.php'; $options = Core_Resource_View::getOptions(); $less = new lessc(); foreach ($files as $key => $file) { if (substr($file, 0, 1) != '/') { $filePaths[] = APPLICATION_PATH . '/theme/' . $options['theme'] . '/' . $file; } else { $filePaths[] = BASE_PATH . $file; } } if ($options['combineCss']) { $fileDate = 0; $cacheFile = ''; foreach ($filePaths as $filePath) { $fileDate = max(filemtime($filePath), $fileDate); $cacheFile .= $filePath; } $cacheFile = md5($cacheFile) . '.css'; $cacheFilePath = BASE_PATH . '/public/cache/' . $cacheFile; $cacheFileDate = file_exists($cacheFilePath) ? filemtime($cacheFilePath) : 0; if ($cacheFileDate < $fileDate) { $fileContent = ''; $less->setVariables(array('themeUrl' => "'" . BASE_URL . '/app/theme/' . $options['theme'] . "'", 'publicUrl' => "'" . BASE_URL . '/public' . "'")); foreach ($filePaths as $filePath) { $ext = pathinfo($filePath, PATHINFO_EXTENSION); if ($ext == 'less') { $fileContent .= $less->compileFile($filePath) . PHP_EOL; } else { $fileContent .= file_get_contents($filePath) . PHP_EOL; } } file_put_contents($cacheFilePath, $options['minify'] ? Core_Helper_Minify::minifyCss($fileContent) : $fileContent); } $fileLinks = array(BASE_URL . '/public/cache/' . $cacheFile); } else { foreach ($filePaths as $key => $filePath) { $ext = pathinfo($filePath, PATHINFO_EXTENSION); if ($ext == 'less') { $less->setVariables(array('themeUrl' => "'" . BASE_URL . '/app/theme/' . $options['theme'] . "'")); $cacheFile = md5($filePath) . '.css'; $cacheFilePath = BASE_PATH . '/public/cache/' . $cacheFile; $less->checkedCompile($filePath, $cacheFilePath); $fileLinks[] = BASE_URL . '/public/cache/' . $cacheFile; } else { $fileLinks[] = BASE_URL . '/' . trim(str_replace(BASE_PATH, '', $filePath), '/'); } } } foreach ($fileLinks as $link) { echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$link}\" />" . PHP_EOL; } }
public function actionLess() { Yii::import('mod.core.models.less.*'); if (isset($_POST['Less'])) { $path = Yii::getPathOfAlias('webroot.themes.default.less'); Yii::import('app.phpless.lessc'); $less = new lessc(); $param = array(); foreach ($_POST['Less'] as $key => $val) { $param[$key] = $val; } Yii::app()->settings->set('less', $param); $less->setVariables($param); /* $less->setVariables(array( 'btn-default-bgcolor' => '#e0e0e0', //#e0e0e0 'btn-primary-bgcolor' => '#265a88', 'btn-success-bgcolor' => '#419641', 'btn-info-bgcolor' => '#2aabd2', 'btn-warning-bgcolor' => '#eb9316', 'btn-danger-bgcolor' => '#c12e2a', )); */ $less->compileFile($path . "/bootstrap-theme.less", Yii::getPathOfAlias('webroot.themes.default.assets.css') . "/bootstrap-theme.css"); } $this->render('less', array('gradient' => new LessGradient())); }
function shoestrap_buttons_css() { $btn_color = get_theme_mod('shoestrap_buttons_color'); // Make sure colors are properly formatted $btn_color = '#' . str_replace('#', '', $btn_color); // if no color has been selected, set to #0066cc. This prevents errors with the php-less compiler. if (strlen($btn_color) < 3) { $btn_color = '#0066cc'; } ?> <style> <?php if (class_exists('lessc')) { $less = new lessc(); $less->setVariables(array("btnColor" => $btn_color)); $less->setFormatter("compressed"); if (shoestrap_get_brightness($btn_color) <= 160) { // The code below is a copied from bootstrap's buttons.less + mixins.less files echo $less->compile("\n @btnColorHighlight: darken(spin(@btnColor, 5%), 10%);\n \n .gradientBar(@primaryColor, @secondaryColor, @textColor: #fff, @textShadow: 0 -1px 0 rgba(0,0,0,.25)) {\n color: @textColor;\n text-shadow: @textShadow;\n #gradient > .vertical(@primaryColor, @secondaryColor);\n border-color: @secondaryColor @secondaryColor darken(@secondaryColor, 15%);\n border-color: rgba(0,0,0,.1) rgba(0,0,0,.1) fadein(rgba(0,0,0,.1), 15%);\n }\n \n #gradient {\n .vertical(@startColor: #555, @endColor: #333) {\n background-color: mix(@startColor, @endColor, 60%);\n background-image: -moz-linear-gradient(top, @startColor, @endColor); // FF 3.6+\n background-image: -webkit-gradient(linear, 0 0, 0 100%, from(@startColor), to(@endColor)); // Safari 4+, Chrome 2+\n background-image: -webkit-linear-gradient(top, @startColor, @endColor); // Safari 5.1+, Chrome 10+\n background-image: -o-linear-gradient(top, @startColor, @endColor); // Opera 11.10\n background-image: linear-gradient(to bottom, @startColor, @endColor); // Standard, IE10\n background-repeat: repeat-x;\n }\n }\n \n .buttonBackground(@startColor, @endColor, @textColor: #fff, @textShadow: 0 -1px 0 rgba(0,0,0,.25)) {\n .gradientBar(@startColor, @endColor, @textColor, @textShadow);\n *background-color: @endColor; /* Darken IE7 buttons by default so they stand out more given they won't have borders */\n .reset-filter();\n &:hover, &:active, &.active, &.disabled, &[disabled] {\n color: @textColor;\n background-color: @endColor;\n *background-color: darken(@endColor, 5%);\n }\n }\n .btn, .btn-primary{\n .buttonBackground(@btnColor, @btnColorHighlight);\n }\n "); } else { echo $less->compile("\n @btnColorHighlight: darken(@btnColor, 15%);\n \n .gradientBar(@primaryColor, @secondaryColor, @textColor: #333, @textShadow: 0 -1px 0 rgba(0,0,0,.25)) {\n color: @textColor;\n text-shadow: @textShadow;\n #gradient > .vertical(@primaryColor, @secondaryColor);\n border-color: @secondaryColor @secondaryColor darken(@secondaryColor, 15%);\n border-color: rgba(0,0,0,.1) rgba(0,0,0,.1) fadein(rgba(0,0,0,.1), 15%);\n }\n \n #gradient {\n .vertical(@startColor: #555, @endColor: #333) {\n background-color: mix(@startColor, @endColor, 60%);\n background-image: -moz-linear-gradient(top, @startColor, @endColor); // FF 3.6+\n background-image: -webkit-gradient(linear, 0 0, 0 100%, from(@startColor), to(@endColor)); // Safari 4+, Chrome 2+\n background-image: -webkit-linear-gradient(top, @startColor, @endColor); // Safari 5.1+, Chrome 10+\n background-image: -o-linear-gradient(top, @startColor, @endColor); // Opera 11.10\n background-image: linear-gradient(to bottom, @startColor, @endColor); // Standard, IE10\n background-repeat: repeat-x;\n }\n }\n \n .buttonBackground(@startColor, @endColor, @textColor: #333, @textShadow: 0 -1px 0 rgba(0,0,0,.25)) {\n .gradientBar(@startColor, @endColor, @textColor, @textShadow);\n *background-color: @endColor; /* Darken IE7 buttons by default so they stand out more given they won't have borders */\n .reset-filter();\n &:hover, &:active, &.active, &.disabled, &[disabled] {\n color: @textColor;\n background-color: @endColor;\n *background-color: darken(@endColor, 5%);\n }\n }\n .btn, .btn-primary{\n .buttonBackground(@btnColor, @btnColorHighlight);\n }\n "); } } ?> </style> <?php }
function CompileOptionsLess($inputFile) { global $dynamo_tpl; require_once get_template_directory() . '/dynamo_framework/lib/lessc.inc.php'; $less = new lessc(); $less->setPreserveComments(true); $url = "'" . get_template_directory_uri() . "'"; $body_bg_image = "'" . get_option($dynamo_tpl->name . '_body_bg_image') . "'"; $page404_bg_image = "'" . get_option($dynamo_tpl->name . '_page404_bg_image') . "'"; $subheader_area_bgimage = "'" . get_option($dynamo_tpl->name . '_subheader_area_bgimage') . "'"; $branding_logo_image = "'" . get_option($dynamo_tpl->name . '_branding_logo_image') . "'"; $expander_bgimage = "'" . get_option($dynamo_tpl->name . '_expander_bgimage') . "'"; $footer_bg_image = "'" . get_option($dynamo_tpl->name . '_footer_bg_image') . "'"; $expander_bgimage = "'" . get_option($dynamo_tpl->name . '_expander_bgimage') . "'"; $footerbgtype = 'n'; if (get_option($dynamo_tpl->name . '_footer_pattern', 'none') != 'none') { $footerbgtype = 'p'; } if (get_option($dynamo_tpl->name . '_footer_bg_image') != '') { $footerbgtype = 'i'; } $expanderbgtype = 'n'; if (get_option($dynamo_tpl->name . '_expander_pattern', 'none') != 'none') { $expanderbgtype = 'p'; } if (get_option($dynamo_tpl->name . '_expander_bgimage') != '') { $expanderbgtype = 'i'; } $less->setVariables(array("url" => $url, "fontsize_body" => get_option($dynamo_tpl->name . '_fontsize_body', '13px'), "fontsize_h1" => get_option($dynamo_tpl->name . '_fontsize_h1', '40px'), "fontsize_h2" => get_option($dynamo_tpl->name . '_fontsize_h2', '30px'), "fontsize_h3" => get_option($dynamo_tpl->name . '_fontsize_h3', '18px'), "fontsize_h4" => get_option($dynamo_tpl->name . '_fontsize_h4', '16px'), "fontsize_h5" => get_option($dynamo_tpl->name . '_fontsize_h5', '14px'), "fontsize_h6" => get_option($dynamo_tpl->name . '_fontsize_h6', '12px'), "maincontent_accent_color" => get_option($dynamo_tpl->name . '_maincontent_accent_color', '#3296dc'), "maincontent_secondary_accent_color" => get_option($dynamo_tpl->name . '_maincontent_secondary_accent_color', '#000000'), "page_wrap_state" => get_option($dynamo_tpl->name . '_page_wrap_state', 'streched'), "page_bgcolor" => get_option($dynamo_tpl->name . '_page_bgcolor', '#ffffff'), "page_pattern" => get_option($dynamo_tpl->name . '_page_pattern', 'none'), "body_bg_image_state" => get_option($dynamo_tpl->name . '_body_bg_image_state', 'N'), "body_bg_image" => $body_bg_image, "body_bgcolor" => get_option($dynamo_tpl->name . '_body_bgcolor', '#ffffff'), "body_pattern" => get_option($dynamo_tpl->name . '_body_pattern', 'none'), "paspartu_state" => get_option($dynamo_tpl->name . '_paspartu_state', 'N'), "paspartu_bg_color" => get_option($dynamo_tpl->name . '_paspartu_bg_color', '#ffffff'), "paspartu_width" => get_option($dynamo_tpl->name . '_paspartu_width', '30') . 'px', "top_bar_bg_color" => get_option($dynamo_tpl->name . '_top_bar_bg_color', '#000000'), "top_bar_text_color" => get_option($dynamo_tpl->name . '_top_bar_text_color', '#ffffff'), "top_bar_link_color" => get_option($dynamo_tpl->name . '_top_bar_link_color', '#3296dc'), "top_bar_hlink_color" => get_option($dynamo_tpl->name . '_top_bar_hlink_color', '#f2f2f2'), "top_bar_icon_color" => get_option($dynamo_tpl->name . '_top_bar_icon_color', '#ffffff'), "branding_logo_type" => get_option($dynamo_tpl->name . '_branding_logo_type'), "branding_logo_image" => $branding_logo_image, "branding_logo_image_width" => get_option($dynamo_tpl->name . '_branding_logo_image_width', '160') . 'px', "branding_logo_image_height" => get_option($dynamo_tpl->name . '_branding_logo_image_height', '50') . 'px', "branding_logo_top_margin" => get_option($dynamo_tpl->name . '_branding_logo_top_margin', '30') . 'px', "branding_logo_bottom_margin" => get_option($dynamo_tpl->name . '_branding_logo_bottom_margin', '10') . 'px', "sticky_logo_top_margin" => get_option($dynamo_tpl->name . '_sticky_logo_top_margin', '10') . 'px', "menu_top_bg_color" => get_option($dynamo_tpl->name . '_menu_top_bg_color', 'transparent'), "top_mainmenu_link_color" => get_option($dynamo_tpl->name . '_top_mainmenu_link_color', '#222222'), "top_mainmenu_hlink_color" => get_option($dynamo_tpl->name . '_top_mainmenu_hlink_color', '#3296dc'), "sticky_header_bgcolor" => get_option($dynamo_tpl->name . '_sticky_header_bgcolor', 'rgba(255,255,255,0.95)'), "sticky_mainmenu_link_color" => get_option($dynamo_tpl->name . '_sticky_mainmenu_link_color', '#222222'), "sticky_mainmenu_hlink_color" => get_option($dynamo_tpl->name . '_sticky_mainmenu_hlink_color', '#3296dc'), "aside_logo_image_width" => get_option($dynamo_tpl->name . '_aside_logo_image_width', '101') . 'px', "aside_logo_image_height" => get_option($dynamo_tpl->name . '_aside_logo_image_height', '35') . 'px', "aside_mainmenu_bg_color" => get_option($dynamo_tpl->name . '_aside_mainmenu_bg_color', '#ffffff'), "aside_mainmenu_link_color" => get_option($dynamo_tpl->name . '_aside_mainmenu_link_color', '#222222'), "aside_mainmenu_hlink_color" => get_option($dynamo_tpl->name . '_aside_mainmenu_hlink_color', '#3296dc'), "submenu_bgcolor" => get_option($dynamo_tpl->name . '_submenu_bgcolor', '#ffffff'), "submenu_topbordercolor" => get_option($dynamo_tpl->name . '_submenu_topbordercolor', '#3296dc'), "submenu_link_color" => get_option($dynamo_tpl->name . '_submenu_link_color', '#AFB4B9'), "submenu_hlink_color" => get_option($dynamo_tpl->name . '_submenu_hlink_color', '#AFB4B9'), "submenu_hbg_color" => get_option($dynamo_tpl->name . '_submenu_hbg_color', '#F6F6F6'), "overlay_mainmenu_bg_color" => get_option($dynamo_tpl->name . '_overlay_mainmenu_bg_color', '#ffffff'), "overlay_mainmenu_link_color" => get_option($dynamo_tpl->name . '_overlay_mainmenu_link_color', '#222222'), "overlay_mainmenu_hlink_color" => get_option($dynamo_tpl->name . '_overlay_mainmenu_hlink_color', '#3296dc'), "overlay_mainmenu_bg_color" => get_option($dynamo_tpl->name . '_overlay_mainmenu_bg_color', '#ffffff'), "overlay_mainmenu_link_color" => get_option($dynamo_tpl->name . '_overlay_mainmenu_link_color', '#222222'), "overlay_mainmenu_hlink_color" => get_option($dynamo_tpl->name . '_overlay_mainmenu_hlink_color', '#3296dc'), "overlapping_header_bgcolor" => get_option($dynamo_tpl->name . '_overlapping_header_bgcolor', '#ffffff'), "overlapping_mainmenu_link_color_light" => get_option($dynamo_tpl->name . '_overlapping_mainmenu_link_color_light', '#ffffff'), "overlapping_mainmenu_hlink_color_light" => get_option($dynamo_tpl->name . '_overlapping_mainmenu_hlink_color_light', '#3296dc'), "overlapping_mainmenu_link_color_dark" => get_option($dynamo_tpl->name . '_overlapping_mainmenu_link_color_dark', '#222222'), "overlapping_mainmenu_hlink_color_dark" => get_option($dynamo_tpl->name . '_overlapping_mainmenu_hlink_color_dark', '#3296dc'), "subheader_bgcolor" => get_option($dynamo_tpl->name . '_subheader_bgcolor', '#F7F8FA'), "subheader_pattern" => get_option($dynamo_tpl->name . '_subheader_pattern', 'none'), "subheader_area_bgimage" => $subheader_area_bgimage, "subheader_text_color" => get_option($dynamo_tpl->name . '_subheader_text_color', '#ffffff'), "expander_bgcolor" => get_option($dynamo_tpl->name . '_expander_bgcolor', '#222222'), "expander_bgimage" => $expander_bgimage, "expander_pattern" => get_option($dynamo_tpl->name . '_expander_pattern', 'none'), "expander_text_color" => get_option($dynamo_tpl->name . '_eexpander_text_color', '#ffffff'), "expander_link_color" => get_option($dynamo_tpl->name . '_expander_link_color', '#3296dc'), "expander_hlink_color" => get_option($dynamo_tpl->name . '_expander_hlink_color', '#f6f6f6'), "expanderbgtype" => $expanderbgtype, "maincontent_text_color" => get_option($dynamo_tpl->name . '_maincontent_text_color', '#7A7A7A'), "maincontent_headers_color" => get_option($dynamo_tpl->name . '_maincontent_headers_color', '#7A7A7A'), "maincontent_link_color" => get_option($dynamo_tpl->name . '_maincontent_link_color', '#3296dc'), "maincontent_hlink_color" => get_option($dynamo_tpl->name . '_maincontent_hlink_color', '#76797C'), "footer_bg_color" => get_option($dynamo_tpl->name . '_footer_bg_color', '#232D37'), "footer_bg_image" => $footer_bg_image, "footer_pattern" => get_option($dynamo_tpl->name . '_footer_pattern', 'none'), "footer_text_color" => get_option($dynamo_tpl->name . '_footer_text_color', '#BCC1C5'), "footer_header_color" => get_option($dynamo_tpl->name . '_footer_header_color', '#ffffff'), "footer_link_color" => get_option($dynamo_tpl->name . '_footer_link_color', '#ffffff'), "footer_hlink_color" => get_option($dynamo_tpl->name . '_footer_hlink_color', '#3296dc'), "footerbgtype" => $footerbgtype, "copyrightbgcolor" => get_option($dynamo_tpl->name . '_copyright_bg_color', 'rgba(0,0,0,.2)'), "copyrightbordercolor" => get_option($dynamo_tpl->name . '_copyright_border_color', 'rgba(0,0,0,0)'), "copyrighttextcolor" => get_option($dynamo_tpl->name . '_copyright_text_color', '#A2A2A2'), "copyrightlinkcolor" => get_option($dynamo_tpl->name . '_copyright_link_color', '#A2A2A2'), "copyrighthlinkcolor" => get_option($dynamo_tpl->name . '_copyright_hlink_color', '#fff'), "page404_bg_image" => $page404_bg_image, "page404_bg_image_state" => get_option($dynamo_tpl->name . '_404_bg_image_state', 'N'))); $less->compileFile(get_template_directory() . '/css/less/' . $inputFile, get_template_directory() . '/css/dynamic.css'); }
/** * Prepares the style compiler by adding variables to environment. * * @param array<string> $variables * @return string */ protected function bootstrap(array $variables) { // add reset like a boss $content = $this->prepareFile(WCF_DIR . 'style/bootstrap/reset.less'); // apply style variables $this->compiler->setVariables($variables); // add mixins $content .= $this->prepareFile(WCF_DIR . 'style/bootstrap/mixin.less'); return $content; }
/** * Filters an asset just before it's dumped. * * @param AssetInterface $asset */ public function filterDump(AssetInterface $asset) { $compiler = new \lessc(); $this->dispatch(new LoadThemeVariables($variables = new Collection())); $compiler->setVariables($variables->all()); if ($dir = $asset->getSourceDirectory()) { $compiler->importDir = $dir; } foreach ($this->loadPaths as $loadPath) { $compiler->addImportDir($loadPath); } $asset->setContent($compiler->parse($this->parser->parse($asset->getContent()))); }
function compileChildLessFile($input, $output, $params) { $less = new lessc(); $less->setVariables($params); // input and output location $inputFile = get_stylesheet_directory() . '/less/' . $input; $outputFile = get_stylesheet_directory() . '/css/' . $output; try { $less->compileFile($inputFile, $outputFile); } catch (Exception $ex) { echo "lessphp fatal error: " . $ex->getMessage(); } }
/** * Parse a Less file to CSS */ public function parse($src, $dst, $options) { $this->auto = isset($options['auto']) ? $options['auto'] : $this->auto; $variables = $this->variables; $assetManager = Yii::$app->assetManager; // Final url of the file being compiled $assetUrl = substr($dst, strpos($assetManager->basePath, $assetManager->baseUrl)); $variables['published-url'] = '"' . $assetUrl . '"'; // Root for the published folder $variables['published-base-url'] = '"/' . implode('/', array_slice(explode('/', ltrim($assetUrl, '/')), 0, 2)) . '"'; $less = new \lessc(); $less->setVariables($variables); // Compressed setting if ($this->compressed) { $less->setFormatter('compressed'); } \Less_Parser::$default_options['compress'] = $this->compressed; \Less_Parser::$default_options['relativeUrls'] = $this->relativeUrls; // Send out pre-compile event $event = new \yii\base\Event(); $this->runtime = ['sourceFile' => $src, 'destinationFile' => $dst, 'compiler' => $less]; $event->sender = $this; Event::trigger($this, self::EVENT_BEFORE_COMPILE, $event); try { if ($this->auto) { /* @var FileCache $cacheMgr */ $cacheMgr = Yii::createObject('yii\\caching\\FileCache'); $cacheMgr->init(); $cacheId = 'less#' . $dst; $cache = $cacheMgr->get($cacheId); if ($cache === false || @filemtime($dst) < @filemtime($src)) { $cache = $src; } $newCache = $less->cachedCompile($cache); if (!is_array($cache) || $newCache["updated"] > $cache["updated"]) { $cacheMgr->set($cacheId, $newCache); file_put_contents($dst, $newCache['compiled']); } } else { $less->compileFile($src, $dst); } // If needed, respect the users configuration if ($assetManager->fileMode !== null) { @chmod($dst, $assetManager->fileMode); } unset($this->less); } catch (\Exception $e) { throw new \Exception(__CLASS__ . ': Failed to compile less file : ' . $e->getMessage() . '.'); } }
protected function _getInlineCSS() { $s = ''; require_once $this->_sDirPlugins . 'lessphp/lessc.inc.php'; $oLess = new lessc(); $oConfigBase = new BxBaseConfig(); $oLess->setVariables($oConfigBase->aLessConfig); foreach ($this->_aFilesCss as $sFile) { if (substr($sFile, -5) !== '.less') { continue; } $s .= $oLess->compileFile($this->_sPathCss . $sFile) . "\n"; } return $s; }
function sh_theme_color_scheme($color = '') { $dir = SH_TH_ROOT; include_once $dir . '/includes/thirdparty/lessc.inc.php'; if (!$color) { $color = _WSH()->option('custom_color_scheme'); } if (!$color) { return; } $less = new lessc(); $less->setVariables(array("color" => $color)); // create a new cache object, and compile $cache = $less->cachedCompile(_WSH()->includes("/css/color.less")); return $cache['compiled']; file_put_contents(_WSH()->includes('/css/colors.css'), $cache["compiled"]); }
function thim_generate_less2css($fileout, $type, $less_variables = array(), $compile_file = '') { if (!$compile_file) { $compile_file = TP_THEME_DIR . 'less' . DIRECTORY_SEPARATOR . 'theme-options.less'; } $css = ""; WP_Filesystem(); global $wp_filesystem; $compiler = new lessc(); $compiler->setFormatter('compressed'); // set less varivalbles $compiler->setVariables($less_variables); // chose file less to compile $css .= $compiler->compileFile($compile_file); // get customcss $css .= thim_get_customcss(); // minifile css $regex = array("`^([\t\\s]+)`ism" => '', "`^\\/\\*(.+?)\\*\\/`ism" => "", "`([\n\\A;]+)\\/\\*(.+?)\\*\\/`ism" => "\$1", "`([\n\\A;\\s]+)//(.+?)[\n\r]`ism" => "\$1\n", "`(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+`ism" => "", "/\n/i" => ""); $css = preg_replace(array_keys($regex), $regex, $css); /*********************************** * Create style.css file ***********************************/ $style = thim_file_get_contents(TP_THEME_DIR . "inc/theme-info.txt"); // Determine whether Multisite support is enabled if (is_multisite()) { // Write Theme Info into style.css if (!file_put_contents($fileout . $type, $style, LOCK_EX)) { @chmod($fileout . $type, 0777); file_put_contents($fileout . $type, $style, LOCK_EX); } // Write the rest to specific site style-ID.css $fileout = $fileout . '-' . get_current_blog_id(); if (!file_put_contents($fileout . $type, $css, FILE_APPEND)) { @chmod($fileout . $type, 0777); file_put_contents($fileout . $type, $css, FILE_APPEND); } } else { // If this is not multisite, we write them all in style.css file $style .= $css; if (!file_put_contents($fileout . $type, $style, LOCK_EX)) { @chmod($fileout . $type, 0777); file_put_contents($fileout . $type, $style, LOCK_EX); } } }
/** * Compiles Bootstrap LESS codes and save the result in database. * * @return mixed */ function actions($options) { global $wp_filesystem; $uploads = wp_upload_dir(); if (!empty($options['less'])) { require_once plugin_dir_path(__FILE__) . 'lib/lessphp/lessc.inc.php'; $lessphp = new lessc(); $lessphp->setVariables(wp_parse_args($options['vars'], $this->default_bootstrap_variables())); $less = file_get_contents(dirname(__FILE__) . '/lib/bootstrap/less/mixins.less'); foreach ($options['less'] as $raw_less) { $less .= file_get_contents(dirname(__FILE__) . '/lib/bootstrap/less/' . $raw_less . '.less'); } /* compile LESS and minify the result */ $css = $this->minify_css($lessphp->parse($less)); WP_Filesystem(); $wp_filesystem->put_contents(trailingslashit($uploads['basedir']) . 'bootstrap.css', $css, 0644); } else { @unlink(trailingslashit($uploads['basedir']) . 'bootstrap.css'); } return $options; }
function less_css($handle) { include DUDE_THEME_DIR . "/less/variables.php"; // output css file name $css_path = DUDE_THEME_DIR . '/css/' . "{$handle}.css"; // automatically regenerate files if source's modified time has changed or vars have changed try { // initialise the parser $less = new lessc(); // load the cache $cache_path = DUDE_THEME_DIR . "/cache/{$handle}.css.cache"; if (file_exists($cache_path)) { $cache = unserialize(file_get_contents($cache_path)); } // If the cache or root path in it are invalid then regenerate if (empty($cache) || empty($cache['less']['root']) || !file_exists($cache['less']['root'])) { $cache = array('vars' => $vars, 'less' => DUDE_THEME_DIR . "/less/{$handle}.less"); } // less config $less->setFormatter("compressed"); $less->setVariables($vars); $less_cache = $less->cachedCompile($cache['less'], false); if (!file_exists($css_path) || empty($cache) || empty($cache['less']['updated']) || $less_cache['updated'] > $cache['less']['updated']) { file_put_contents($cache_path, serialize(array('vars' => $vars, 'less' => $less_cache))); file_put_contents($css_path, $less_cache['compiled']); } elseif ($vars !== $cache['vars']) { $less_cache = $less->cachedCompile($cache['less'], true); file_put_contents($cache_path, serialize(array('vars' => $vars, 'less' => $less_cache))); file_put_contents($css_path, $less_cache['compiled']); } } catch (exception $ex) { qa_fatal_error($ex->getMessage()); } // return the compiled stylesheet with the query string it had if any $url = DUDE_THEME_URL . "/css/{$handle}.css"; echo '<link href="' . $url . '" type="text/css" rel="stylesheet">'; }
/** * @return lessc */ protected function _initProcessor() { // lazy load if (!class_exists('lessc')) { require_once dirname(__FILE__) . '/class.less.leafo.php'; } $less = new lessc(); if ($this->_isDebug()) { $formatter = new lessc_formatter_lessjs(); // configurate css view $formatter->openSingle = " { "; $formatter->closeSingle = "}\n"; $formatter->close = "}\n"; $formatter->indentChar = " "; $formatter->disableSingle = true; $formatter->breakSelectors = true; $formatter->assignSeparator = ": "; $formatter->selectorSeparator = ", "; } else { // compress mode $formatter = new lessc_formatter_compressed(); $formatter->closeSingle = "}\n"; $formatter->close = "}\n"; } // set formatter $less->setFormatter($formatter); $less->setPreserveComments(false); // add paths for imports $less->addImportDir($this->_tpl->lessFull); $less->addImportDir(JPATH_ROOT); // from php $less->setVariables(array('css' => str_replace($this->_tpl->baseurl, '', $this->_tpl->css), 'less' => str_replace($this->_tpl->baseurl, '', $this->_tpl->less), 'images' => str_replace($this->_tpl->baseurl, '', $this->_tpl->img), 'debug' => (int) $this->_isDebug())); // add custom functions $less->registerFunction('data-uri', array($this, 'lib_dataUri')); return $less; }
function ro_theme_autoCompileLess($inputFile, $outputFile) { require_once ABS_PATH_FR . '/inc/lessc.inc.php'; global $tb_options; $less = new lessc(); $less->setFormatter("classic"); $less->setPreserveComments(true); /*Styling Options*/ $tb_primary_color = $tb_options['tb_primary_color']; $tb_secondary_color = $tb_options['tb_secondary_color']; $variables = array("tb_primary_color" => $tb_primary_color, "tb_secondary_color" => $tb_secondary_color); $less->setVariables($variables); $cacheFile = $inputFile . ".cache"; if (file_exists($cacheFile)) { $cache = unserialize(file_get_contents($cacheFile)); } else { $cache = $inputFile; } $newCache = $less->cachedCompile($inputFile); if (!is_array($cache) || $newCache["updated"] > $cache["updated"]) { file_put_contents($cacheFile, serialize($newCache)); file_put_contents($outputFile, $newCache['compiled']); } }
/** * Lessify the stylesheet and return the href of the compiled file * * @param string $src Source URL of the file to be parsed * @param string $handle An identifier for the file used to create the file name in the cache * @return string URL of the compiled stylesheet */ public function parse_stylesheet($src, $handle) { // we only want to handle .less files if (!preg_match('/\\.less(\\.php)?$/', preg_replace('/\\?.*$/', '', $src))) { return $src; } // get file path from $src if (!strstr($src, '?')) { $src .= '?'; } // prevent non-existent index warning when using list() & explode() // Match the URL schemes between WP_CONTENT_URL and $src, // so the str_replace further down will work $src_scheme = parse_url($src, PHP_URL_SCHEME); $wp_content_url_scheme = parse_url(WP_CONTENT_URL, PHP_URL_SCHEME); if ($src_scheme != $wp_content_url_scheme) { $src = set_url_scheme($src, $wp_content_url_scheme); } list($less_path, $query_string) = explode('?', str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $src)); // output css file name $css_path = trailingslashit($this->get_cache_dir()) . "{$handle}.css"; // automatically regenerate files if source's modified time has changed or vars have changed try { // initialise the parser $less = new lessc(); // load the cache $cache_path = "{$css_path}.cache"; if (file_exists($cache_path)) { $cache = unserialize(file_get_contents($cache_path)); } // vars to pass into the compiler - default @themeurl var for image urls etc... $this->vars['themeurl'] = '~"' . get_stylesheet_directory_uri() . '"'; $this->vars['lessurl'] = '~"' . dirname($src) . '"'; $this->vars = apply_filters('less_vars', $this->vars, $handle); // If the cache or root path in it are invalid then regenerate if (empty($cache) || empty($cache['less']['root']) || !file_exists($cache['less']['root'])) { $cache = array('vars' => $this->vars, 'less' => $less_path); } // less config $less->setFormatter(apply_filters('less_compression', $this->compression)); $less->setPreserveComments(apply_filters('less_preserve_comments', $this->preserve_comments)); $less->setVariables($this->vars); // add directories to scan for imports $import_dirs = apply_filters('less_import_dirs', $this->import_dirs); if (!empty($import_dirs)) { foreach ((array) $import_dirs as $dir) { $less->addImportDir($dir); } } // register and unregister functions foreach ($this->registered_functions as $name => $callable) { $less->registerFunction($name, $callable); } foreach ($this->unregistered_functions as $name) { $less->unregisterFunction($name); } // allow devs to mess around with the less object configuration do_action_ref_array('lessc', array(&$less)); // $less->cachedCompile only checks for changed file modification times // if using the theme customiser (changed variables not files) then force a compile if ($this->vars !== $cache['vars']) { $force = true; } else { $force = false; } $less_cache = $less->cachedCompile($cache['less'], apply_filters('less_force_compile', $force)); if (empty($cache) || empty($cache['less']['updated']) || $less_cache['updated'] > $cache['less']['updated'] || $this->vars !== $cache['vars']) { file_put_contents($cache_path, serialize(array('vars' => $this->vars, 'less' => $less_cache))); file_put_contents($css_path, $less_cache['compiled']); } } catch (exception $ex) { wp_die($ex->getMessage()); } // restore query string it had if any $url = trailingslashit($this->get_cache_dir(false)) . "{$handle}.css" . (!empty($query_string) ? "?{$query_string}" : ''); // restore original url scheme $url = set_url_scheme($url, $src_scheme); return add_query_arg('ver', $less_cache['updated'], $url); }
/** * Method that compiles LESS to CSS file * @param (string) Path to LESS file * @param (bool) If true additional LESS variables from "jm_bootstrap_variables" parameter will be added * @param (bool) Indicates if we are dealing with a file that belongs to template's core. * If yes, it means that we should add suffix for CSS file because different template styles may use * different variables * @param (bool) When true old version of LessC will be used. Otherwise Less_Parser class. */ protected function lessToCss($lessPath, $useVars = true, $coreStyle = true, $legacyCompiler = false) { if (class_exists('lessc') == false && $legacyCompiler) { require_once JMF_FRAMEWORK_PATH . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'lessc' . DIRECTORY_SEPARATOR . 'lessc.inc.0.4.0.php'; } if (class_exists('Less_Parser') == false && !$legacyCompiler) { require_once JMF_FRAMEWORK_PATH . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'libraries' . DIRECTORY_SEPARATOR . 'less_parser' . DIRECTORY_SEPARATOR . 'Less.php'; } $developer_mode = $this->params->get('devmode', false) == '1' ? true : false; $filename = JFile::stripExt(JFile::getName($lessPath)); $style_id = @JFactory::getApplication()->getTemplate(true)->id; $css_suffix = ''; // A suffix is simply ID of template style, eg. template.10.css if ($style_id > 0 && $coreStyle) { $css_suffix = '.' . $style_id; } // Establishing path to CSS file $cssPath = JPath::clean(JMF_TPL_PATH . '/css/' . $filename . $css_suffix . '.css'); // Checking if LESS file exists. If not we should make sure that we're looking in correct directory if (!JFile::exists($lessPath)) { $lessPath = JPath::clean(JMF_TPL_PATH . '/less/' . $filename . '.less'); } // If developer mode is disabled and CSS file is not older than LESS file, we do not have to compile LESS file. if (JFile::exists($lessPath) && JFile::exists($cssPath)) { $lessTime = filemtime($lessPath); $cssTime = filemtime($cssPath); if ($lessTime <= $cssTime && $developer_mode == false) { return JMF_TPL_URL . '/css/' . $filename . $css_suffix . '.css'; } } // At this point, either we are in developer mode or CSS file does not exist or is older than LESS file. // But if CSS file does exist, we should delete it if (JFile::exists($cssPath)) { JFile::delete($cssPath); } try { if ($legacyCompiler) { // Initialising LessC compiler $less = new lessc(); // Additional LESS variables if ($useVars) { $variables = $this->params->get('jm_bootstrap_variables', array()); if (!empty($variables)) { $less->setVariables($variables); } } // Checked Compile - LessC $less->checkedCompile($lessPath, $cssPath); } else { // Less_Parser compiler $less_parser_options = array('compress' => $this->params->get('cssCompress', '0') == '1' ? true : false, 'relativeUrls' => false, 'sourceMap' => false); if ($developer_mode) { //$less_parser_options['compress'] = false; $less_parser_options['sourceMap'] = true; $less_parser_options['sourceMapWriteTo'] = JPath::clean(JMF_TPL_PATH . '/css/' . $filename . $css_suffix . '.map'); $less_parser_options['sourceMapURL'] = JUri::base(false) . 'templates/' . JMF_TPL . '/css/' . $filename . $css_suffix . '.map'; } $less_parser = new Less_Parser($less_parser_options); // Less_Parser - LESS file $less_parser->parseFile($lessPath, JMF_TPL_URL . '/css'); // Additional LESS variables if ($useVars) { $variables = $this->params->get('jm_bootstrap_variables', array()); if (!empty($variables)) { // Less_Parser $less_parser->ModifyVars($variables); } } // Compilation - Less_Parser if ($css_content = $less_parser->getCss()) { if (JFile::write($cssPath, $css_content) == false) { throw new Exception('Cannot save CSS file. Please check your directory permissions.'); } } } } catch (exception $e) { throw new Exception(JText::sprintf('PLG_SYSTEM_JMFRAMEWORK_LESS_ERROR', $e->getMessage())); } // Returning CSS file's URL return JMF_TPL_URL . '/css/' . $filename . $css_suffix . '.css'; }
require_once locate_template('/lib/3rdparty/lessc.inc.php'); if (class_exists('lessc') && ya_options()->getCpanelValue('developer_mode')) { define('LESS_PATH', get_template_directory() . '/assets/less'); define('CSS__PATH', get_template_directory() . '/assets/css'); $scheme = ya_options()->getCpanelValue('scheme'); $scheme_vars = get_template_directory() . '/templates/presets/default.php'; $output_cssf = CSS__PATH . '/app-default.css'; if ($scheme && file_exists(get_template_directory() . '/templates/presets/' . $scheme . '.php')) { $scheme_vars = get_template_directory() . '/templates/presets/' . $scheme . '.php'; $output_cssf = CSS__PATH . "/app-{$scheme}.css"; } if (file_exists($scheme_vars)) { include $scheme_vars; try { // less variables by theme_mod // $less_variables['sidebar-width'] = ya_options()->sidebar_collapse_width.'px'; $less = new lessc(); $less->setImportDir(array(LESS_PATH . '/app/', LESS_PATH . '/bootstrap/')); $less->setVariables($less_variables); $cache = $less->cachedCompile(LESS_PATH . '/app.less'); file_put_contents($output_cssf, $cache["compiled"]); if (ya_options()->getCpanelValue('responsive_support')) { $responsive_cache = $less->cachedCompile(LESS_PATH . '/app-responsive.less'); file_put_contents(CSS__PATH . '/app-responsive.css', $responsive_cache["compiled"]); } } catch (Exception $e) { var_dump($e); exit; } } }
/** * Lessify the stylesheet and return the href of the compiled file * * @param string $src Source URL of the file to be parsed * @param string $handle An identifier for the file used to create the file name in the cache * @return string URL of the compiled stylesheet */ public function parse_stylesheet($src, $handle) { // we only want to handle .less files if (!preg_match('/\\.less(\\.php)?$/', preg_replace('/\\?.*$/', '', $src))) { return $src; } // get file path from $src if (!strstr($src, '?')) { $src .= '?'; } // prevent non-existent index warning when using list() & explode() // Match the URL schemes between WP_CONTENT_URL and $src, // so the str_replace further down will work $src_scheme = parse_url($src, PHP_URL_SCHEME); $wp_content_url_scheme = parse_url(WP_CONTENT_URL, PHP_URL_SCHEME); if ($src_scheme != $wp_content_url_scheme) { $src = set_url_scheme($src, $wp_content_url_scheme); } list($less_path, $query_string) = explode('?', str_replace(WP_CONTENT_URL, WP_CONTENT_DIR, $src)); $cache = $this->get_cached_file_data($handle); // vars to pass into the compiler - default @themeurl var for image urls etc... $this->vars['themeurl'] = '~"' . get_stylesheet_directory_uri() . '"'; $this->vars['lessurl'] = '~"' . dirname($src) . '"'; $this->vars = apply_filters('less_vars', $this->vars, $handle); // The overall "version" of the LESS file is all it's vars, src etc. $less_version = md5(serialize(array($this->vars, $src))); /** * Give the ability to disable always compiling the LESS with lessc() * and instead just use the $vars and $version of the LESS file to * dictate whether the LESS should be (re)generated. * * This means we don't need to run everything through the lessc() compiler * on every page load. The tradeoff is making a change in a LESS file will not * necessarily cause a (re)generation, one would need to bump the $ver param * on wp_enqueue_script() to cause that. */ if (!get_option('wp_less_always_compile_less', true)) { if (!empty($cache['version']) && $cache['version'] === $less_version) { // restore query string it had if any $url = $cache['url'] . (!empty($query_string) ? "?{$query_string}" : ''); $url = set_url_scheme($url, $src_scheme); return add_query_arg('ver', $less_version, $url); } } // automatically regenerate files if source's modified time has changed or vars have changed try { // initialise the parser if (!class_exists('lessc')) { return $url; //wp_die( 'the lessphp library is missing, aborting, run composer update' ); } // If the cache or root path in it are invalid then regenerate if (empty($cache) || empty($cache['less']['root']) || !file_exists($cache['less']['root'])) { $cache = array('vars' => $this->vars, 'less' => $less_path); } if (empty($cache['url'])) { $cache['url'] = trailingslashit($this->get_cache_dir(false)) . "{$handle}.css"; } // less config $less = new lessc(); $less->setFormatter(apply_filters('less_compression', $this->compression)); $less->setPreserveComments(apply_filters('less_preserve_comments', $this->preserve_comments)); $less->setVariables($this->vars); // add directories to scan for imports $import_dirs = apply_filters('less_import_dirs', $this->import_dirs); if (!empty($import_dirs)) { foreach ((array) $import_dirs as $dir) { $less->addImportDir($dir); } } // register and unregister functions foreach ($this->registered_functions as $name => $callable) { $less->registerFunction($name, $callable); } foreach ($this->unregistered_functions as $name) { $less->unregisterFunction($name); } // allow devs to mess around with the less object configuration do_action_ref_array('lessc', array(&$less)); // $less->cachedCompile only checks for changed file modification times // if using the theme customiser (changed variables not files) then force a compile if ($this->vars !== $cache['vars']) { $force = true; } else { $force = false; } $force = apply_filters('less_force_compile', $force); $less_cache = $less->cachedCompile($cache['less'], $force); // if they have the same values but differing order, they wont match //sort( $cache['less'] ); //sort( $less_cache ); if (empty($cache) || empty($cache['less']['updated']) || md5($less_cache['compiled']) !== md5($cache['less']['compiled']) || $this->vars !== $cache['vars']) { // output css file name $css_path = trailingslashit($this->get_cache_dir()) . "{$handle}.css"; $cache = array('vars' => $this->vars, 'url' => trailingslashit($this->get_cache_dir(false)) . "{$handle}.css", 'version' => $less_version, 'less' => null); /** * If the option to not have LESS always compiled is set, * then we dont store the whole less_cache in the options table as it's * not needed because we only do a comparison based off $vars and $src * (which includes the $ver param). * * This saves space on the options table for high performance environments. */ if (get_option('wp_less_always_compile_less', true)) { $cache['less'] = $less_cache; } $payload = '<strong>Rebuilt stylesheet with handle: "' . $handle . '"</strong><br>'; if ($this->vars != $cache['vars']) { $payload .= '<em>Variables changed</em>'; $difference = array_merge(array_diff_assoc($cache['vars'], $this->vars), array_diff_assoc($this->vars, $cache['vars'])); $payload .= '<pre>' . print_r($difference, true) . '</pre>'; } else { if (empty($cache) || empty($cache['less']['updated'])) { $payload .= '<em>Empty cache or empty last update time</em>'; } else { if ($less_cache['updated'] > $cache['less']['updated']) { $payload .= '<em>Update times different</em>'; } else { $payload .= '<em><strong>Unknown! Contact the developers poste haste!!!!!!!</em><strong></em>'; } } } $payload .= '<br>src: <code>"' . $src . '"</code> css path: <code>"' . $css_path . '"</code> and cache path: <code>"' . $cache_path . '"</code> and scheme <code>"' . $src_scheme . '"</code>'; $this->add_message(array('time' => time(), 'payload' => $payload)); $this->save_parsed_css($css_path, $less_cache['compiled']); $this->update_cached_file_data($handle, $cache); } } catch (exception $ex) { $this->add_message(array('time' => time(), 'payload' => '<strong>Lessphp failure</strong> ' . $ex->GetMessage())); wp_die(wp_strip_all_tags($ex->getMessage())); } // restore query string it had if any $url = $cache['url'] . (!empty($query_string) ? "?{$query_string}" : ''); // restore original url scheme $url = set_url_scheme($url, $src_scheme); if (get_option('wp_less_always_compile_less', true)) { return add_query_arg('ver', $less_cache['updated'], $url); } return add_query_arg('ver', $less_version, $url); }
function compileLess($inputFile, $outputFile) { if (!class_exists('lessc')) { require_once KPATH_FRAMEWORK . '/external/lessc/lessc.php'; } // Load the cache. $cacheDir = JPATH_CACHE . '/kunena'; if (!is_dir($cacheDir)) { KunenaFolder::create($cacheDir); } $cacheFile = "{$cacheDir}/kunena.{$this->name}.{$inputFile}.cache"; if (is_file($cacheFile)) { $cache = unserialize(file_get_contents($cacheFile)); } else { $cache = JPATH_SITE . '/' . $this->getFile($inputFile, false, 'less'); } $outputDir = KPATH_MEDIA . "/cache/{$this->name}/css"; if (!is_dir($outputDir)) { KunenaFolder::create($outputDir); } $outputFile = "{$outputDir}/{$outputFile}"; $less = new lessc(); $class = $this; $less->registerFunction('url', function ($arg) use($class) { list($type, $q, $values) = $arg; $value = reset($values); return "url({$q}{$class->getFile($value, true, 'media', 'media/kunena')}{$q})"; }); $less->setVariables($this->style_variables); $newCache = $less->cachedCompile($cache); if (!is_array($cache) || $newCache['updated'] > $cache['updated'] || !is_file($outputFile)) { $cache = serialize($newCache); KunenaFile::write($cacheFile, $cache); KunenaFile::write($outputFile, $newCache['compiled']); } }
/** * Compile LESS into CSS. * * @param string|array $source_filename * @param string $target_filename * @param array $variables (optional) * @parsm bool $minify (optional) * @return bool */ public static function compileLESS($source_filename, $target_filename, $variables = array(), $minify = false) { // Get the cleaned and concatenated content. $content = self::concatCSS($source_filename, $target_filename); // Compile! try { $less_compiler = new \lessc(); $less_compiler->setFormatter($minify ? 'compressed' : 'lessjs'); $less_compiler->setImportDir(array(dirname(is_array($source_filename) ? array_first($source_filename) : $source_filename))); if ($variables) { $less_compiler->setVariables($variables); } $charset = strpos($content, '@charset') === false ? '@charset "UTF-8";' . "\n" : ''; $content = $charset . $less_compiler->compile($content) . "\n"; $result = true; } catch (\Exception $e) { $content = '/*' . "\n" . 'Error while compiling LESS:' . "\n" . $e->getMessage() . "\n" . '*/' . "\n"; $result = false; } // Save the result to the target file. Storage::write($target_filename, $content); return $result; }
/** * Returns LESS compiler set up for use with MediaWiki * * @param Config $config * @throws MWException * @since 1.22 * @return lessc */ public static function getLessCompiler(Config $config) { // When called from the installer, it is possible that a required PHP extension // is missing (at least for now; see bug 47564). If this is the case, throw an // exception (caught by the installer) to prevent a fatal error later on. if (!class_exists('lessc')) { throw new MWException('MediaWiki requires the lessphp compiler'); } if (!function_exists('ctype_digit')) { throw new MWException('lessc requires the Ctype extension'); } $less = new lessc(); $less->setPreserveComments(true); $less->setVariables(self::getLessVars($config)); $less->setImportDir($config->get('ResourceLoaderLESSImportPaths')); foreach ($config->get('ResourceLoaderLESSFunctions') as $name => $func) { $less->registerFunction($name, $func); } return $less; }
/** * Less CSS * * @param mixed $mixed CSS string to process with Less compiler or an array with CSS file's Path and URL. * @return mixed string or an array with CSS file's Path and URL. */ function _lessCss($mixed) { require_once BX_DIRECTORY_PATH_PLUGINS . 'lessphp/lessc.inc.php'; $oLess = new lessc(); $oLess->setVariables($this->_oConfigTemplate->aLessConfig); if (is_array($mixed) && isset($mixed['url']) && isset($mixed['path'])) { $sPathFile = realpath($mixed['path']); $aInfoFile = pathinfo($sPathFile); if (!isset($aInfoFile['extension']) || $aInfoFile['extension'] != 'less') { return $mixed; } $sPathRoot = realpath(BX_DIRECTORY_PATH_ROOT); $sFile = $this->_sLessCachePrefix . trim(str_replace(array('.' . $aInfoFile['extension'], DIRECTORY_SEPARATOR), array('', '_'), bx_ltrim_str($sPathFile, $sPathRoot)), '_') . '.css'; $oLess->checkedCompile($mixed['path'], $this->_sCachePublicFolderPath . $sFile); return array('url' => $this->_sCachePublicFolderUrl . $sFile, 'path' => $this->_sCachePublicFolderPath . $sFile); } return $oLess->compile($mixed); }
function simple_less_compile($inputFile, $outputFile) { global $variablesArray; cherryVariables(); if ( empty($variablesArray) ) return; // custom formatter $formatter = new lessc_formatter_classic; $formatter->indentChar = "\t"; $less = new lessc; $less->setVariables($variablesArray); $less->setFormatter($formatter); try { $less->compileFile($inputFile, $outputFile); } catch (Exception $ex) { echo "lessphp fatal error: ".$ex->getMessage(); } }
<?php $baseRoot = dirname(dirname(dirname(__FILE__))); $systemRoot = $baseRoot . "/system/"; $wwwRoot = $baseRoot . "/www/"; $config = new stdclass(); $config->ui = new stdclass(); include $systemRoot . 'module/ui/config.php'; include $systemRoot . 'lib/lessc/lessc.class.php'; $lessc = new lessc(); $params = array(); foreach ($config->ui->themes['default'] as $theme => $defaults) { if (strpos(',default,tartan,wide,', $theme) === false) { continue; } foreach ($defaults as $section => $selector) { foreach ($selector as $attr => $settings) { foreach ($settings as $setting) { $params[$setting['name']] = $setting['default']; } } } unset($params['background-image-position']); unset($params['navbar-background-image-position']); $lessc->setVariables($params); $cssFile = $wwwRoot . 'data/css/default/' . $theme . '/style.css'; $lessTemplate = $wwwRoot . 'template/default/theme/' . $theme . '/style.less'; $lessc->compileFile($lessTemplate, $cssFile); print_r($cssFile . " Createed \n"); }
/** * Initialize less compiler * @param $formatterName * @param $z_textColor * @param $z_themeColor * @param $z_themeColor2 * @param $z_themeColorBtn * @param $z_themeColorHeader * @param $z_path * @return lessc */ protected function initializeLessCompiler($formatterName, $z_textColor, $z_themeColor, $z_themeColor2, $z_themeColorBtn, $z_themeColorHeader, $z_path) { $lessCompiler = new lessc(); $lessCompiler->setPreserveComments(false); $lessCompiler->setFormatter($formatterName); $lessCompiler->setImportDir($this->getLessFilesPath()); $lessCompiler->setVariables(array("z_textColor" => $z_textColor, "z_themeColor" => $z_themeColor, "z_themeColor2" => $z_themeColor2, "z_themeColorBtn" => $z_themeColorBtn, "z_themeColorHeader" => $z_themeColorHeader, "z_path" => $z_path)); return $lessCompiler; }
function sh_theme_color_scheme() { $dir = get_template_directory(); include_once $dir . '/includes/thirdparty/lessc.inc.php'; $styles = _WSH()->option(); $colors = sh_set($styles, 'color_selection', 'default'); $custom = sh_set($styles, 'custom_color_scheme'); $default = sh_set($styles, 'default_color_scheme', 'yellow'); //echo $colors.'<br>'.$custom.'<br>'. $default;exit; if ($colors === 'default') { $url = file_exists(get_stylesheet_directory_uri() . '/css/' . $default . '.css') ? get_stylesheet_directory_uri() . '/css/' . $default . '.css' : get_template_directory_uri() . '/css/' . $default . '.css'; echo '<link rel="stylesheet" type="text/css" href="' . $url . '" />'; return; } $transient = get_transient('_sh_color_scheme'); $update = $custom != $transient ? true : false; $url = file_exists(get_stylesheet_directory() . '/css/color.css') ? get_stylesheet_directory_uri() . '/css/color.css' : get_template_directory_uri() . '/css/color.css'; echo '<link rel="stylesheet" type="text/css" href="' . $url . '" />'; //if( !$update ) return; set_transient('_sh_color_scheme', $custom, DAY_IN_SECONDS); $less = new lessc(); $less->setVariables(array("sh_color" => $custom)); $lessss = file_exists(get_stylesheet_directory() . '/css/color.less') ? get_stylesheet_directory() . '/css/color.less' : get_template_directory() . '/css/color.less'; // create a new cache object, and compile $cache = $less->cachedCompile($lessss); $url = file_exists(get_stylesheet_directory() . '/css/color.css') ? get_stylesheet_directory() . '/css/color.css' : get_template_directory() . '/css/color.css'; file_put_contents($url, $cache["compiled"]); }
/** * @Route("/admin/less", name="admin_setless") */ public function setLessAction() { $less = new \lessc(); $less->setVariables(array("color" => "green", "base" => "960px")); $lesscode = file_get_contents("assets/less/layout.less"); $lesscode .= "@color: #000055;"; file_put_contents("assets/less/main.css", $less->compile($lesscode)); return new Response('<p class="magic">compiled, foo</p>'); }
<?php $js = 'library/javascript'; $styles = 'library/styles'; $images = 'library/images'; $zTabs = 'library/javascript/zTabs'; require 'library/includes/lessc.inc.php'; $less = new lessc(); // Setting higher level variables $less->setVariables(array('one-em' => '16px', 'light-blue' => '#d7eef4', 'full-width' => '90%')); try { $less->checkedCompile($styles . '/full_screen.less', $styles . '/full_screen.css'); } catch (Exception $e) { echo $e; } try { $result = $less->checkedCompile($zTabs . '/' . $styles . '/zTabs.less', $zTabs . '/' . $styles . '/zTabs.css'); } catch (Exception $e) { echo $e; } ?> <!DOCTYPE html> <html> <head> <title>Kate Green</title> <link href='http://fonts.googleapis.com/css?family=Simonetta:400,900,400italic,900italic' rel='stylesheet' /> <link rel="stylesheet" href="<?php echo $styles; ?> /reset.css" /> <link rel="stylesheet" href="<?php