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 }
/** * Generate custom color scheme css * * @since 1.0 */ function bigboom_generate_custom_color_scheme() { parse_str($_POST['data'], $data); if (!isset($data['custom_color_scheme'])) { return; } if (!$data['custom_color_scheme']) { return; } $color_1 = $data['custom_color_1']; if (!$color_1) { return; } // Prepare LESS to compile $less = file_get_contents(THEME_DIR . '/css/color-schemes/mixin.less'); $less .= ".custom-color-scheme { .color-scheme({$color_1}); }"; // Compile require THEME_DIR . '/inc/libs/lessc.inc.php'; $compiler = new lessc(); $compiler->setFormatter('compressed'); $css = $compiler->compile($less); // Get file path $upload_dir = wp_upload_dir(); $dir = path_join($upload_dir['basedir'], 'custom-css'); $file = $dir . '/color-scheme.css'; // Create directory if it doesn't exists wp_mkdir_p($dir); @file_put_contents($file, $css); wp_send_json_success(); }
/** * Compiles LESS stylesheets into one CSS-stylesheet and writes them * to filesystem. Please be aware not to append '.css' within $filename! * * @param string $filename * @param array<string> $files * @param array<string> $variables * @param string $individualLess * @param wcf\system\Callback $callback */ protected function compileStylesheet($filename, array $files, array $variables, $individualLess, Callback $callback) { // build LESS bootstrap $less = $this->bootstrap($variables); foreach ($files as $file) { $less .= $this->prepareFile($file); } // append individual CSS/LESS if ($individualLess) { $less .= $individualLess; } try { $content = $this->compiler->compile($less); } catch (\Exception $e) { throw new SystemException("Could not compile LESS: ".$e->getMessage(), 0, '', $e); } $content = $callback($content); // write stylesheet file_put_contents($filename.'.css', $content); // convert stylesheet to RTL $content = StyleUtil::convertCSSToRTL($content); // write stylesheet for RTL file_put_contents($filename.'-rtl.css', $content); }
function jollyness_preprocess_html(&$vars) { //Process portfolio color if ($portfolio_category = taxonomy_vocabulary_machine_name_load('portfolio_category')) { $terms = taxonomy_get_tree($portfolio_category->vid); $less = new lessc(); $css = ''; $color = ''; $class = ''; foreach ($terms as $t) { $term = taxonomy_term_load($t->tid); $class = drupal_html_class($t->name); if (!empty($term->field_color)) { foreach ($term->field_color as $v) { $color = $v[0]['value']; break; } } if ($color) { $css .= ".dexp-masonry-filter,.dexp-portfolio-filter{.{$class} span:before{background-color: {$color} !important;}}"; $css .= ".{$class} .portfolio-item-overlay{background-color: rgba(red({$color}), green({$color}), blue({$color}), 0.7) !important;}"; } } $css = $less->compile($css); drupal_add_css($css, array('type' => 'inline')); } }
public static function compile($source, $path, $todir, $importdirs) { // call Less to compile $parser = new lessc(); $parser->setImportDir(array_keys($importdirs)); $parser->setPreserveComments(true); $output = $parser->compile($source); // update url $arr = preg_split(CANVASLess::$rsplitbegin . CANVASLess::$kfilepath . CANVASLess::$rsplitend, $output, -1, PREG_SPLIT_DELIM_CAPTURE); $output = ''; $file = $relpath = ''; $isfile = false; foreach ($arr as $s) { if ($isfile) { $isfile = false; $file = $s; $relpath = CANVASLess::relativePath($todir, dirname($file)); $output .= "\n#" . CANVASLess::$kfilepath . "{content: \"{$file}\";}\n"; } else { $output .= ($file ? CANVASPath::updateUrl($s, $relpath) : $s) . "\n\n"; $isfile = true; } } return $output; }
public static function parse($source, $isFile = true) { $parser = new lessc(); try { return $isFile ? $parser->compileFile($source) : $parser->compile($source); } catch (Exception $e) { return '/** LESS PARSE ERROR: ' . $e->getMessage() . ' **/'; } }
public static function compile($source, $importdirs) { // call Less to compile $parser = new lessc(); $parser->setImportDir(array_keys($importdirs)); $parser->setPreserveComments(true); $output = $parser->compile($source); return $output; }
/** * @param \AssetsBundle\AssetFile\AssetFile $oAssetFile * @return string */ public function filterAssetFile(\AssetsBundle\AssetFile\AssetFile $oAssetFile) { $oLessParser = new \lessc(); $oLessParser->addImportDir(getcwd()); $oLessParser->setAllowUrlRewrite(true); //Prevent time limit errors set_time_limit(0); return trim($oLessParser->compile($oAssetFile->getAssetFileContents())); }
/** * Compile the Less file in $origin to the CSS $destination file * * @param string $origin Input Less path * @param string $destination Output CSS path */ public static function compile($origin, $destination) { $less = new \lessc(); $less->indentChar = \Config::get('asset.indent_with'); $less->setImportDir(array(dirname($origin), dirname($destination))); $raw_css = $less->compile(file_get_contents($origin)); $destination = pathinfo($destination); \File::update($destination['dirname'], $destination['basename'], $raw_css); }
function jetpack_less_css_preprocess($less) { require_once dirname(__FILE__) . '/preprocessors/lessc.inc.php'; $compiler = new lessc(); try { return $compiler->compile($less); } catch (Exception $e) { return $less; } }
/** * Compiles LESS code into CSS code using <em>lessphp</em>, http://leafo.net/lessphp * * @param string $less Less code * @return string CSS code * @throws dmInvalidLessException */ public function compile($less, array $importDirs = array()) { $lessCompiler = new lessc(); $lessCompiler->setImportDir($importDirs); try { return $lessCompiler->compile($less); } catch (Exception $e) { throw new dmInvalidLessException($e->getMessage()); } }
/** * Builds a LESS/CSS resource from string * * @param string $string * * @return type * The compiled and compressed CSS */ public static function buildString($string) { $obj = new \lessc(); $obj->setFormatter('compressed'); try { $output = $obj->compile($string); } catch (\Exception $e) { throw $e; } return $output; }
/** * Compile all files into one file. * * @param string $filePath File location. * @param string $format Formatter for less. * * @return void */ public function compileTo($filePath, $format = 'compressed') { $less = ''; foreach ($this->_files as $file) { $less .= file_get_contents($file) . "\n\n"; } $this->_lessc->setImportDir($this->_importDirs); $this->_lessc->setFormatter($format); $result = $this->_lessc->compile($less); file_put_contents($filePath, $result); }
/** * lessphp compiler * @link https://github.com/leafo/lessphp * * @param string $file * * @return string */ protected function lessphp($file) { if (!class_exists('\\lessc')) { return Result::errorMissingPackage($this, 'lessc', 'leafo/lessphp'); } $lessCode = file_get_contents($file); $less = new \lessc(); if (isset($this->compilerOptions['importDirs'])) { $less->setImportDir($this->compilerOptions['importDirs']); } return $less->compile($lessCode); }
function add_less($file) { $target = str_replace(".less", ".css", $file); if (!file_exists($target) || filemtime($file) > filemtime($target)) { $c = new \lessc(); $res = $c->compile(file_get_contents($file)); file_put_contents($target, $res); } ?> <link type="text/css" rel="stylesheet" href="<?php echo $target; ?> " /><?php }
public function compileCss(&$templateData, $cssFileName) { glz_importLib('lessphp/lessc.inc.php'); $less = new lessc(); $less->setImportDir(array($this->path . '/less/')); $css = file_get_contents($this->path . '/less/styles.less'); // $css = $this->applyCssVariables($templateData, $less, $css); $css = $this->applyFont($templateData, $css); $css = $less->compile($css); $css = $this->fixUrl($css); $css = $this->addLogoCss($templateData, $css); $css = $this->addCustomCss($templateData, $css); file_put_contents($cssFileName, $css); $templateData->css = '<link rel="stylesheet" href="' . $cssFileName . '" type="text/css" media="screen" />'; }
/** * Compile function. Returns a compile content, or writes it to a file if path is specified. * * @param null|string $file * @return string|true */ public function compile($path = null) { parent::compile(); $file = $this->getMinifiedResource(); $file->rewind(); $less = new \lessc(); $string = $less->compile($file->read()); if (null !== $path) { $file2 = new FileObject($path, 'w+'); $file2->write($string); $string = true; } unset($file); unset($file2); return $string; }
static function OutputCSSText($ident, $css, $updated) { $jpc = JPATH_CACHE; $jpc = str_ireplace("administrator", "", $jpc); if (!file_exists($jpc . DS . 'fss' . DS . 'css')) { mkdir($jpc . DS . 'fss' . DS . 'css', 0777, true); } $out_filename = "{$ident}.css"; $out_file = $jpc . DS . 'fss' . DS . 'css' . DS . $out_filename; if (!is_file($out_file) || $updated > filemtime($out_file)) { require_once JPATH_SITE . DS . 'components' . DS . 'com_fss' . DS . 'helper' . DS . 'third' . DS . 'lessc.php'; $less = new lessc(); $output = $less->compile($css); JFile::write($out_file, $output); } $document = JFactory::getDocument(); $document->addStyleSheet(JURI::root(true) . "/cache/fss/css/" . $out_filename); }
/** @see ModuleConnector::init() */ public function init(array $params = array()) { // Pointer to resourcerouter $rr = m('resourcer'); // If CSS resource has been updated if (isset($rr->updated['css'])) { try { $less = new \lessc(); // Read updated CSS resource file and compile it $css = $less->compile(file_get_contents($rr->updated['css'])); // Write to the same place file_put_contents($rr->updated['css'], $css); } catch (Exception $e) { e('Ошибка обработки CSS: ' . $e->getMessage()); } } // Вызовем родительский метод parent::init($params); }
public function handle(Application $app, Request $request) { $filename = $request->attributes->get('filename'); if ($filename[0] != '/') { // relative path $filename = $app['frontcontroller.basepath'] . '/' . $filename; } $filename = realpath($filename); // Sanity check if (!$filename || !file_exists($filename)) { return $this->errorResponse('File not found', 404); } $content = file_get_contents($filename); $less = new \lessc(); $css = $less->compile($content); // TODO: Add more control over the caching headers $response = new Response($css, Response::HTTP_OK, array('content-type' => "text/css", 'Expires' => 'Mon, 04 Jul 2078 12:00:00 GMT', 'Cache-Control' => 'public, max-age=315360000', 'Vary' => 'Accept-Encoding')); return $response; }
public function minify() { ///TODO: handle errors... at all. /// Compile less files Module::Requires("extern.JShrink"); Module::Requires("extern.lessphp"); $buffer = file_get_contents($this->path); switch ($this->getExtension()) { case "less": $less = new lessc(); $less->setFormatter("compressed"); $buffer = $less->compile($buffer); break; case "js": $buffer = \JShrink\Minifier::minify($buffer, array('flaggedComments' => false)); break; } return $buffer; }
/** * @return array */ private function _getColorStyles() { $site = $this->getParams()->getSite('site'); $style = ''; foreach (array_reverse($site->getModules()) as $moduleName) { $file = new CM_File(CM_Util::getModulePath($moduleName) . 'layout/default/variables.less'); if ($file->exists()) { $style .= $file->read() . PHP_EOL; } } preg_match_all('#@(color\\w+)#', $style, $matches); $colors = array_unique($matches[1]); foreach ($colors as $variableName) { $style .= '.' . $variableName . ' { background-color: @' . $variableName . '; }' . PHP_EOL; } $lessCompiler = new lessc(); $style = $lessCompiler->compile($style); preg_match_all('#.(color\\w+)\\s+\\{([^}]+)\\}#', $style, $matches); return array_combine($matches[1], $matches[2]); }
/** * Generate custom color scheme css * * @since 1.0 */ function onehost_generate_custom_color_scheme() { parse_str($_POST['data'], $data); if (!isset($data['custom_color_scheme']) || !$data['custom_color_scheme']) { return; } $color_1 = $data['custom_color_1']; if (!$color_1) { return; } // Getting credentials $url = wp_nonce_url('themes.php?page=theme-options'); if (false === ($creds = request_filesystem_credentials($url, '', false, false, null))) { return; // stop the normal page form from displaying } // Try to get the wp_filesystem running if (!WP_Filesystem($creds)) { // Ask the user for them again request_filesystem_credentials($url, '', true, false, null); return; } global $wp_filesystem; // Prepare LESS to compile $less = $wp_filesystem->get_contents(THEME_DIR . '/css/color-schemes/mixin.less'); $less .= ".custom-color-scheme { .color-scheme({$color_1}); }"; // Compile require THEME_DIR . '/inc/libs/lessc.inc.php'; $compiler = new lessc(); $compiler->setFormatter('compressed'); $css = $compiler->compile($less); // Get file path $upload_dir = wp_upload_dir(); $dir = path_join($upload_dir['basedir'], 'custom-css'); $file = $dir . '/color-scheme.css'; // Create directory if it doesn't exists wp_mkdir_p($dir); $wp_filesystem->put_contents($file, $css, FS_CHMOD_FILE); wp_send_json_success(); }
function generate_less_to_css($less_folder, $params, $ignore_files) { WP_Filesystem(); global $wp_filesystem; $files = scandir($less_folder); $css = ''; $content_file_options = ""; foreach ($files as $file) { if (strpos($file, 'less') !== false) { if (exist_in_array($ignore_files, $file) == true) { continue; } $content_file_options = $params; $content_file_options .= $wp_filesystem->get_contents($less_folder . $file); $compiler = new lessc(); $compiler->setFormatter('compressed'); $css .= $compiler->compile($content_file_options); $content_file_options = ""; } } return $css; }
public function set($content, $vars = null) { $less = new \lessc(); $lessContent = ($vars === null ? $this->get(true) : $vars) . "/** START CSS */\n"; $newContent = $lessContent . trim($content); $less->setImportDir(PHPFOX_DIR . 'less/'); $content = str_replace('../../../../PF.Base/less/', '', $newContent); $parsed = $less->compile($content); $path = $this->_theme->getPath() . 'flavor/' . $this->_theme->flavor_folder; file_put_contents($path . '.less', $newContent); file_put_contents($path . '.css', $parsed); $this->db->update(':setting', array('value_actual' => (int) \Phpfox::getParam('core.css_edit_id') + 1), 'var_name = \'css_edit_id\''); $this->cache->del('setting'); return true; // file_put_contents($this->_theme->getPath() . 'flavor/' . $this->_theme->flavor_folder . '.min.css', $parsed); // if ($this->_get()) { /* $this->db->update(':theme_template', [ 'html_data' => $parsed, 'html_data_original' => $content, 'time_stamp_update' => PHPFOX_TIME ], [ 'folder' => $this->_theme->folder, 'type_id' => 'css', 'name' => $this->_theme->flavor_folder . '.css' ]); */ // return true; // } /* $this->db->insert(':theme_template', [ 'folder' => $this->_theme->folder, 'type_id' => 'css', 'name' => $this->_theme->flavor_folder . '.css', 'html_data' => $parsed, 'html_data_original' => $content, 'time_stamp' => PHPFOX_TIME ]); */ return true; }
public function handleFormUploadLess($form, $request, $task) { $form->handleRequest($request); if ($form->isValid()) { $dataObject = $form->getData(); $less = new \lessc(); $lesscode = file_get_contents("assets/less/layout.less"); $lesscode .= '@primary-color: ' . $dataObject->getPrimaryColor() . ';'; $lesscode .= '@secondary-color: ' . $dataObject->getSecondaryColor() . ';'; $lesscode .= '@highlight-success: ' . $dataObject->getHighlightSuccess() . ';'; $lesscode .= '@font-family: ' . $dataObject->getFontFamily() . ';'; $lesscode .= '@h1: ' . $dataObject->getH1() . ';'; $lesscode .= '@h2: ' . $dataObject->getH2() . ';'; $lesscode .= '@h3: ' . $dataObject->getH3() . ';'; $lesscode .= '@font-size: ' . $dataObject->getFontSize() . ';'; file_put_contents("assets/less/main.css", $less->compile($lesscode)); $em = $this->getDoctrine()->getManager(); $em->persist($dataObject); $em->flush(); return true; } }
function CompileStyleSheets($compile = true) { global $RootPath; $ResourceBundles = GetResourceBundles(); $FilePaths = array(); $lesstext = ""; foreach ($ResourceBundles as $bundle) { $lesstext .= $bundle->CompileStyleSheets(); } if ($compile) { try { $less = new \lessc(); $less->setFormatter("compressed"); $csstext = $less->compile($lesstext); echo "/* compiled with lessphp v0.4.0 - GPLv3/MIT - http://leafo.net/lessphp */\n"; echo "/* for human-readable source of this file, append ?compile=false to the file name */\n"; echo $csstext; } catch (\Exception $e) { echo "/* " . $e->getMessage() . " */\n"; } } else { echo $lesstext; } }
/** * Uses phpless to parse LESS in our CSS * * most of this function is error handling to show a nice useful error when * LESS compilation fails * * @param string $css * @return string */ function css_parseless($css) { global $conf; $less = new lessc(); $less->importDir[] = DOKU_INC; $less->setPreserveComments(!$conf['compress']); if (defined('DOKU_UNITTEST')) { $less->importDir[] = TMP_DIR; } try { return $less->compile($css); } catch (Exception $e) { // get exception message $msg = str_replace(array("\n", "\r", "'"), array(), $e->getMessage()); // try to use line number to find affected file if (preg_match('/line: (\\d+)$/', $msg, $m)) { $msg = substr($msg, 0, -1 * strlen($m[0])); //remove useless linenumber $lno = $m[1]; // walk upwards to last include $lines = explode("\n", $css); for ($i = $lno - 1; $i >= 0; $i--) { if (preg_match('/\\/(\\* XXXXXXXXX )(.*?)( XXXXXXXXX \\*)\\//', $lines[$i], $m)) { // we found it, add info to message $msg .= ' in ' . $m[2] . ' at line ' . ($lno - $i); break; } } } // something went wrong $error = 'A fatal error occured during compilation of the CSS files. ' . 'If you recently installed a new plugin or template it ' . 'might be broken and you should try disabling it again. [' . $msg . ']'; echo ".dokuwiki:before {\n content: '{$error}';\n background-color: red;\n display: block;\n background-color: #fcc;\n border-color: #ebb;\n color: #000;\n padding: 0.5em;\n }"; exit; } }
/** * lessphp compiler * * @link https://github.com/leafo/lessphp * @return string */ protected function lessphp($file) { $lessCode = file_get_contents($file); $less = new \lessc(); return $less->compile($lessCode); }
/** * 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); }