Ejemplo n.º 1
0
 /**
  * @return scssc
  */
 private function get_compiler()
 {
     if (is_null($this->compiler)) {
         if (!class_exists('scssc')) {
             require_once dirname(__FILE__) . '/Compiler/lib/scssphp/scss.inc.php';
         }
         $this->compiler = new scssc();
         $this->compiler->setImportPaths($this->get_import_paths());
         $this->compiler->setFormatter('scss_formatter_compressed');
     }
     return $this->compiler;
 }
/**
 * Compile SCSS
 * 
 * @return string
 */
function mob_admin_compile_scss($scss_folder, $css_folder, $format_style = "scss_formatter")
{
    // scssc will be loaded automatically via Composer
    $scss_compiler = new scssc();
    // set the path where your _mixins are
    $scss_compiler->setImportPaths($scss_folder);
    // set css formatting (normal, nested or minimized), @see http://leafo.net/scssphp/docs/#output_formatting
    $scss_compiler->setFormatter($format_style);
    // get all .scss files from scss folder
    $filelist = glob($scss_folder . "*.scss");
    try {
        // step through all .scss files in that folder
        foreach ($filelist as $file_path) {
            // get path elements from that file
            $file_path_elements = pathinfo($file_path);
            // get file's name without extension
            $file_name = $file_path_elements['filename'];
            // get .scss's content, put it into $string_sass
            $string_sass = mob_file_read($scss_folder . $file_name . ".scss");
            // compile this SASS code to CSS
            $string_css = $scss_compiler->compile($string_sass);
            // write CSS into file with the same filename, but .css extension
            mob_file_write($css_folder . $file_name . ".css", $string_css);
        }
    } catch (Exception $e) {
        return $e->getMessage();
    }
}
Ejemplo n.º 3
0
 /**
  * Compiles all .scss files in a given folder into .css files in a given folder
  *
  * @param string $scss_folder source folder where you have your .scss files
  * @param string $css_folder destination folder where you want your .css files
  * @param string $format_style CSS output format, see http://leafo.net/scssphp/docs/#output_formatting for more.
  */
 public static function run($scss_folder, $css_folder, $format_style = "scss_formatter")
 {
     // scssc will be loaded automatically via Composer
     $scss_compiler = new scssc();
     // set the path where your _mixins are
     $scss_compiler->setImportPaths($scss_folder);
     // set css formatting (normal, nested or minimized), @see http://leafo.net/scssphp/docs/#output_formatting
     $scss_compiler->setFormatter($format_style);
     // get all .scss files from scss folder
     $filelist = glob($scss_folder . "*.scss");
     // step through all .scss files in that folder
     foreach ($filelist as $file_path) {
         // get path elements from that file
         $file_path_elements = pathinfo($file_path);
         // get file's name without extension
         $file_name = $file_path_elements['filename'];
         // get .scss's content, put it into $string_sass
         $string_sass = file_get_contents($scss_folder . $file_name . ".scss");
         // compile this SASS code to CSS
         $string_css = $scss_compiler->compile($string_sass);
         // create target directory if doesn't exist
         if (!is_dir($css_folder)) {
             mkdir($css_folder, 0777, true);
         }
         // write CSS into file with the same filename, but .css extension
         file_put_contents($css_folder . $file_name . ".css", $string_css);
     }
 }
Ejemplo n.º 4
0
 /**
  * Compiles all .scss files in a given folder into .css files in a given folder
  *
  * @param string $scss_folder source folder where you have your .scss files
  * @param string $css_folder destination folder where you want your .css files
  * @param string $format_style CSS output format, see http://leafo.net/scssphp/docs/#output_formatting for more.
  */
 public static function run($scss_folder, $css_folder, $format_style = "scss_formatter", $file_append = false)
 {
     // scssc will be loaded automatically via Composer
     $scss_compiler = new scssc();
     // set the path where your _mixins are
     $scss_compiler->setImportPaths($scss_folder);
     // set css formatting (normal, nested or minimized), @see http://leafo.net/scssphp/docs/#output_formatting
     $scss_compiler->setFormatter($format_style);
     // create master css file
     if (!is_dir($css_folder) && $file_append == false) {
         file_put_contents($css_folder, "");
     }
     if (is_dir($scss_folder)) {
         $scan = scandir($scss_folder);
     } else {
         $scan = [$scss_folder];
     }
     if (!file_exists($scss_folder)) {
         throw new Exception("Arquivo inexistente: {$scss_folder}");
     }
     foreach ($scan as $file) {
         if (in_array($file, array(".", ".."))) {
             continue;
         }
         if (is_dir($scss_folder)) {
             if (!file_exists($css_folder . $file)) {
                 if (is_dir($css_folder)) {
                     if (!mkdir($css_folder . $file . "/")) {
                         throw new Exception("Falha ao compilar arquivo .scss. Não foi possível criar a pasta {$css_folder}{$file}/");
                     }
                     if (!chmod($css_folder . $file, 0755)) {
                         throw new Exception("Falha ao compilar arquivo .scss. Não foi possível mudar a permissão do arquivo {$css_folder}{$file}/ para 755 (rwxr-xr-x)");
                     }
                 }
             }
             if (is_dir($css_folder)) {
                 self::run($scss_folder . $file . "/", $css_folder . $file . "/", $format_style);
             } else {
                 self::run($scss_folder . $file, $css_folder, $format_style);
             }
         } else {
             if (preg_match('/(.*).scss$/', $file) and $file[0] != '.') {
                 // get path elements from that file
                 $file_path_elements = pathinfo($file);
                 // get file's name without extension
                 $file_name = $file_path_elements['filename'];
                 // get .scss's content, put it into $string_sass
                 $string_sass = file_get_contents($scss_folder);
                 // compile this SASS code to CSS
                 $string_css = $scss_compiler->compile($string_sass);
                 // write CSS into file with the same filename, but .css extension
                 if (is_dir($css_folder)) {
                     file_put_contents($css_folder . $file_name . ".css", $string_css);
                 } else {
                     file_put_contents($css_folder, $string_css, FILE_APPEND);
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 public static function compile_sass($parent)
 {
     if (!empty(self::$path)) {
         if (!class_exists('scssc') && !isset($GLOBALS['redux_scss_compiler'])) {
             $GLOBALS['redux_scss_compiler'] = true;
             require "scssphp/scss.inc.php";
         }
         $scss = new scssc();
         $scss->setImportPaths(self::$path);
         if (!$parent->args['dev_mode']) {
             $scss->setFormatter("scss_formatter_compressed");
         }
         $new_css = '';
         foreach (self::$import as $import) {
             $new_css .= $scss->compile($import);
         }
         if ($new_css != '') {
             if ($parent->args['sass']['page_output']) {
                 echo '<style type="text/css" id="redux-' . $parent->args['opt_name'] . '">' . $new_css . '</style>';
             } else {
                 $filesystem = $parent->filesystem;
                 $css_file = Redux_Helpers::cleanFilePath(ReduxFramework::$_upload_dir . $parent->args['opt_name'] . '-redux.css');
                 $ret_val = $filesystem->execute('put_contents', $css_file, array('content' => $new_css));
             }
         }
     }
 }
Ejemplo n.º 6
0
 public static function compile_sass($parent)
 {
     if (!empty(self::$path)) {
         require "scssphp/scss.inc.php";
         $scss = new scssc();
         $scss->setImportPaths(self::$path);
         if (!$parent->args['dev_mode']) {
             $scss->setFormatter("scss_formatter_compressed");
         }
         $new_css = '';
         foreach (self::$import as $import) {
             $new_css .= $scss->compile($import);
         }
         if ($new_css != '') {
             if ($parent->args['sass']['page_output']) {
                 echo '<style type="text/css" id="redux-' . $parent->args['opt_name'] . '">' . $new_css . '</style>';
             } else {
                 //Redux_Functions::initWpFilesystem();
                 //global $wp_filesystem;
                 $filesystem = $parent->filesystem;
                 $css_file = Redux_Helpers::cleanFilePath(ReduxFramework::$_upload_dir . $parent->args['opt_name'] . '-redux.css');
                 //$ret_val    = $wp_filesystem->put_contents($css_file, $new_css, FS_CHMOD_FILE);
                 $ret_val = $filesystem->execute('put_contents', $css_file, array('content' => $new_css));
             }
         }
     }
 }
 function compileScss()
 {
     require "scss.inc.php";
     $scss = new scssc();
     $scss->setImportPaths(get_stylesheet_directory() . '/assets/scss/');
     $scss->setFormatter('scss_formatter_compressed');
     file_put_contents(get_stylesheet_directory() . '/assets/css/global-gen.css', $scss->compile('@import "global.scss"'));
 }
Ejemplo n.º 8
0
 /**
  * Set values for Wp_Scss::properties
  *
  * @param string scss_dir - path to source directory for scss files
  * @param string css_dir - path to output directory for css files
  * @param string method - type of compile (compressed, expanded, etc)
  *
  * @var object scssc - instantiate the compiling object.
  *
  * @var array compile_errors - catches errors from compile
  */
 public function __construct($scss_dir, $css_dir, $compile_method)
 {
     $this->scss_dir = $scss_dir;
     $this->css_dir = $css_dir;
     $this->compile_method = $compile_method;
     global $scssc;
     $scssc = new scssc();
     $scssc->setFormatter($compile_method);
     $scssc->setImportPaths($scss_dir);
     $this->compile_errors = array();
 }
Ejemplo n.º 9
0
 public static function parse($source, $isFile = true)
 {
     $parser = new scssc();
     if ($isFile) {
         $parser->setImportPaths(dirname($source));
     }
     try {
         return $isFile ? $parser->compile('@import "' . basename($source) . '"') : $parser->compile($source);
     } catch (Exception $e) {
         return '/** SASS PARSE ERROR: ' . $e->getMessage() . ' **/';
     }
 }
Ejemplo n.º 10
0
 public function compile($scss_folder, $scss_filename, $stylename, $format_style = "scss_formatter")
 {
     require_once plugin_dir_path(__FILE__) . 'lib/scssphp/scss.inc.php';
     $scss_compiler = new scssc();
     $scss_compiler->setImportPaths($scss_folder);
     $scss_compiler->setFormatter($format_style);
     try {
         $file = $scss_filename;
         $content = file_get_contents($file);
         $string_css = $scss_compiler->compile($content);
         file_put_contents($stylename, $string_css);
     } catch (Exception $e) {
         echo $e->getMessage();
     }
 }
 public function run_compiler($scss_dir, $sass_vars, $sass_import_file, $css_name, $compile_method = 'scss_formatter_nested')
 {
     require_once WPCSC_PLUGIN_DIR . '/scssphp/scss.inc.php';
     $scss = new scssc();
     $scss->setImportPaths($scss_dir);
     $scss->setFormatter($compile_method);
     $scss->setVariables($sass_vars);
     $new_css = $scss->compile($sass_import_file);
     /* Write the CSS to the Database */
     $wpcscOptions = get_option('wpcsc1208_option_settings');
     /* Sanitze the CSS before going into the Database
        Refer to this doc, http://wptavern.com/wordpress-theme-review-team-sets-new-guidelines-for-custom-css-boxes */
     $wpcscOptions['wpcsc_content'][$css_name] = wp_kses($new_css, array('\'', '\\"'));
     update_option('wpcsc1208_option_settings', $wpcscOptions);
 }
Ejemplo n.º 12
0
 protected function compile($css)
 {
     $scss = new scssc();
     $scss->setImportPaths(maxButtons::get_plugin_path() . "assets/scss");
     //$scss->setFormatter('scss_formatter_compressed');
     $compile = " @import '_mixins.scss';  " . $css;
     maxButtonsUtils::addTime("CSSParser: Compile start ");
     try {
         $css = $scss->compile($compile);
     } catch (Exception $e) {
         $css = $this->output_css;
     }
     maxButtonsUtils::addTime("CSSParser: Compile end ");
     return $css;
 }
Ejemplo n.º 13
0
 /**
  * Compile the SCSS
  * @param \Contao\ThemeModel
  * @param boolean
  */
 public static function compile(\Contao\ThemeModel $objTheme, $blnForce = false)
 {
     if (!self::confirmDependencies()) {
         return;
     }
     //Get file key
     $strKey = self::getKey($objTheme);
     //Set file path
     $strCSSPath = 'assets/foundation/css/' . $strKey . '.css';
     //Compile the scss
     if (!file_exists(TL_ROOT . '/' . $strCSSPath) || $blnForce) {
         //Gather up the SCSS files in the assets/foundation/scss folder
         //This allows to work with different configs and edit defaults
         //Without affecting the original source
         $strBasePath = COMPOSER_DIR_RELATIVE . '/vendor/zurb/foundation/scss';
         $strCopyPath = 'assets/foundation/scss/' . $strKey;
         //Create new folder if not exists and clean it out
         $objNew = new \Folder($strCopyPath);
         $objNew->purge();
         $objOriginal = new \Folder($strBasePath);
         $objOriginal->copyTo($strCopyPath);
         //Apply the config
         self::applyConfig($objTheme, $strCopyPath);
         $strFoundationCSS = '';
         $strNormalizeCSS = '';
         //Create the SCSS compiler
         if (class_exists('scssc')) {
             $objCompiler = new \scssc();
             $objCompiler->setImportPaths(TL_ROOT . '/' . $strCopyPath);
             $objCompiler->setFormatter(\Config::get('debugMode') ? 'scss_formatter' : 'scss_formatter_compressed');
         } else {
             $objCompiler = new Compiler();
             $objCompiler->setImportPaths(TL_ROOT . '/' . $strCopyPath);
             $objCompiler->setFormatter(\Config::get('debugMode') ? 'Leafo\\ScssPhp\\Formatter\\Expanded' : 'Leafo\\ScssPhp\\Formatter\\Compressed');
         }
         $strFoundationContent = file_get_contents(TL_ROOT . '/' . $strCopyPath . '/foundation.scss');
         $strNormalizeContent = file_get_contents(TL_ROOT . '/' . $strCopyPath . '/normalize.scss');
         //Compile
         $strFoundationCSS = $objCompiler->compile($strFoundationContent);
         $strNormalizeCSS = $objCompiler->compile($strNormalizeContent);
         //Write to single CSS file cache
         $objFile = new \File($strCSSPath);
         $objFile->write($strNormalizeCSS . "\n" . $strFoundationCSS);
         $objFile->close();
     }
     return $strCSSPath;
 }
Ejemplo n.º 14
0
 private function compile($css)
 {
     $scss = new scssc();
     $scss->setImportPaths(maxButtons::get_plugin_path() . "assets/");
     $compile = " @import 'mixins.scss';  " . $css;
     $css = $scss->compile($compile);
     /*				
     	try {
     
     	}
     	catch (Exception $e) { 
     		//print_R($e);
     		echo "Warning: Parse failed";
     		//throw new compileException("Compile failed");
     	}
     */
     return $css;
 }
Ejemplo n.º 15
0
 protected function compile($css)
 {
     $scss = new scssc();
     $scss->setImportPaths(MB()->get_plugin_path() . "assets/scss");
     $minify = get_option("maxbuttons_minify", 1);
     if ($minify == 1) {
         $scss->setFormatter('scss_formatter_compressed');
     }
     $compile = " @import '_mixins.scss';  " . $css;
     //maxUtils::addTime("CSSParser: Compile start ");
     try {
         $css = $scss->compile($compile);
     } catch (Exception $e) {
         $css = $this->output_css;
     }
     //maxUtils::addTime("CSSParser: Compile end ");
     return $css;
 }
Ejemplo n.º 16
0
 /**
  * Watches a folder for .scss files, compiles them every X seconds
  * Re-compiling your .scss files every X seconds seems like "too much action" at first sight, but using a
  * "has-this-file-changed?"-check uses more CPU power than simply re-compiling them permanently :)
  * Beside that, we are only compiling .scss in development, for production we deploy .css, so we don't care.
  *
  * @param string $scss_folder source folder where you have your .scss files
  * @param string $css_folder destination folder where you want your .css files
  * @param int $interval interval in seconds
  * @param string $scssphp_script_path path where scss.inc.php (the scssphp script) is
  * @param string $format_style CSS output format, ee http://leafo.net/scssphp/docs/#output_formatting for more.
  */
 public function watch($scss_folder, $css_folder, $interval, $scssphp_script_path, $format_style = "scss_formatter")
 {
     // go on even if user "stops" the script by closing the browser, closing the terminal etc.
     ignore_user_abort(true);
     // set script running time to unlimited
     set_time_limit(0);
     // load the compiler script (scssphp), more here: http://www.leafo.net/scssphp
     require $scssphp_script_path;
     $scss_compiler = new scssc();
     // set the path to your to-be-imported mixins. please note: custom paths are coming up on future releases!
     $scss_compiler->setImportPaths($scss_folder);
     // set css formatting (normal, nested or minimized), @see http://leafo.net/scssphp/docs/#output_formatting
     $scss_compiler->setFormatter($format_style);
     // start an infinitive loop
     while (1) {
         // get all .scss files from scss folder
         $filelist = glob($scss_folder . "*.scss");
         // step through all .scss files in that folder
         foreach ($filelist as $file_path) {
             // get path elements from that file
             $file_path_elements = pathinfo($file_path);
             // get file's name without extension
             $file_name = $file_path_elements['filename'];
             // get .scss's content, put it into $string_sass
             $string_sass = file_get_contents($scss_folder . $file_name . ".scss");
             // try/catch block to prevent script stopping when scss compiler throws an error
             try {
                 // compile this SASS code to CSS
                 $string_css = $scss_compiler->compile($string_sass);
                 // write CSS into file with the same filename, but .css extension
                 file_put_contents($css_folder . $file_name . ".css", $string_css);
             } catch (Exception $e) {
                 // here we could put the exception message, but who cares ...
             }
         }
         // wait for X seconds
         sleep($interval);
     }
 }
Ejemplo n.º 17
0
function alfath_custom_css_compiler($options)
{
    global $wp_filesystem;
    if (empty($wp_filesystem)) {
        require_once ABSPATH . '/wp-admin/includes/file.php';
        WP_Filesystem();
    }
    if (!class_exists('scssc')) {
        require_once ADMIN_DIR . '/option/configs/scss.inc.php';
    }
    $scssc = new scssc();
    $scssc->setImportPaths(get_template_directory() . '/assets/sass/');
    $scssc->setNumberPrecision(10);
    $file = get_template_directory() . '/assets/sass/custom.scss';
    $target = get_template_directory() . '/assets/css/custom.css';
    $var = '';
    if ($wp_filesystem->exists($file)) {
        $scss = $wp_filesystem->get_contents($file);
        if (!$scss) {
            return new WP_Error('reading_error', 'Error when reading file');
        }
        $var .= '$primary-color: ' . $options['primary-color'] . ';';
        $var .= '$secondary-color: ' . $options['secondary-color'] . ';';
        $var .= '$background-color: ' . $options['background-color'] . ';';
        $scss = $var . $scss;
        // Fallback image
        if ($options['nav-bg-fallback-switch'] === '1' && $options['nav-bg-fallback']['url'] !== '') {
            $nav = " .nav-dropline { > li { &.active, &.open, &:hover, &:focus { background: url('" . $options['nav-bg-fallback']['url'] . "') no-repeat bottom left, url('" . $options['nav-bg-fallback']['url'] . "') no-repeat bottom right; @media (min-width: 1200px) { background: url('" . $options['nav-bg-fallback']['url'] . "') no-repeat top left, url('" . $options['nav-bg-fallback']['url'] . "') no-repeat top right; } } } }";
            $scss .= $nav;
        }
        // Fallback Image End;
        $css = $scssc->compile($scss);
        if (!$css) {
            return new WP_Error('compile_error', 'Error on compiling scss to css');
        }
        $wp_filesystem->put_contents($target, $css, FS_CHMOD_FILE);
    }
}
Ejemplo n.º 18
0
 protected function compile()
 {
     if (!class_exists('scssc')) {
         require_once __DIR__ . '/scss.inc.php';
     }
     $inputDir = dirname($this->inputFiles[0]);
     $outputDir = dirname($this->outputFile);
     $scss = new scssc();
     $scss->setFormatter('scss_formatter_compressed');
     $scss->setImportPaths($inputDir);
     if (!file_exists($outputDir)) {
         mkdir($outputDir, 0755, true);
     }
     try {
         $content = file_get_contents($this->inputFiles[0]);
         $css = $scss->compile($content);
         $css = AutoBuildPrefixer::addPrefixes($css);
     } catch (Exception $e) {
         $css = file_get_contents($this->outputFiles[0]);
         $css .= 'html:after{display:block;position:fixed;bottom:0;left:0;width:100%;padding:1em;font:14px sans;text-align:center;background:#d34;color:white;content:' . json_encode($e->getMessage()) . '}';
     }
     file_put_contents($this->outputFile, $css);
 }
Ejemplo n.º 19
0
 public static function compile_single_field($parent, $scss_path, $filename)
 {
     echo 'single field compile: ' . $scss_path . ' ' . $filename;
     if (!class_exists('scssc') && !isset($GLOBALS['redux_scss_compiler'])) {
         $GLOBALS['redux_scss_compiler'] = true;
         require "scssphp/scss.inc.php";
     }
     $scss = new scssc();
     $scss->setImportPaths($scss_path);
     if (!$parent->args['dev_mode']) {
         $scss->setFormatter("scss_formatter_compressed");
     }
     $new_css = $scss->compile('@import "' . $filename . '.scss"');
     unset($scss);
     $ret = @file_put_contents($scss_path . '/' . $filename . '.css', $new_css);
 }
Ejemplo n.º 20
0
 /**
  * Constructor
  *
  * @param string      $dir      Root directory to .scss files
  * @param string      $cacheDir Cache directory
  * @param \scssc|null $scss     SCSS compiler instance
  */
 public function __construct($dir, $cacheDir = null, $scss = null)
 {
     $this->dir = $dir;
     if (is_null($cacheDir)) {
         $cacheDir = $this->join($dir, 'scss_cache');
     }
     $this->cacheDir = $cacheDir;
     if (!is_dir($this->cacheDir)) {
         mkdir($this->cacheDir, 0755, true);
     }
     if (is_null($scss)) {
         $scss = new scssc();
         $scss->setImportPaths($this->dir);
     }
     $this->scss = $scss;
 }
Ejemplo n.º 21
0
 public function compile($scss_folder, $css_folder, $dynamic_scss_file, $scss_files, $css_file, $format_style = "scss_formatter")
 {
     // load the compiler script (scssphp), more here: http://www.leafo.net/scssphp
     require_once "scssphp/scss.inc.php";
     $scss_compiler = new scssc();
     // set the path to your to-be-imported mixins. please note: custom paths are coming up on future releases!
     $scss_compiler->setImportPaths($scss_folder);
     // set css formatting (normal, nested or minimized), @see http://leafo.net/scssphp/docs/#output_formatting
     $scss_compiler->setFormatter($format_style);
     $string_sass = '';
     $string_css = '';
     if (file_exists($dynamic_scss_file)) {
         $string_sass .= file_get_contents($dynamic_scss_file);
     }
     // step through all .scss files in that folder
     foreach ($scss_files as $file) {
         $file_path = $scss_folder . $file;
         if (!file_exists($file_path)) {
             continue;
         }
         // get .scss's content, put it into $string_sass
         $string_sass .= file_get_contents($file_path);
     }
     // try/catch block to prevent script stopping when scss compiler throws an error
     try {
         // compile this SASS code to CSS
         $string_css = $scss_compiler->compile($string_sass);
         // write CSS into file with the same filename, but .css extension
         file_put_contents($css_folder . $css_file, $string_css);
     } catch (Exception $e) {
         $this->print_error($e->getMessage());
     }
 }
Ejemplo n.º 22
0
<?php

require "vendor/scssphp/scss.inc.php";
$scss = new scssc();
// $scss->setFormatter("scss_formatter_compressed");
$scss->setImportPaths("css/scss/main/");
$server = new scss_server("css/scss", null, $scss);
$server->serve();
Ejemplo n.º 23
0
 /**
  * Compress and compile (if necessary) the code.
  * @param string $code
  * @param string $markup_type One of the MARKUP_TYPE_X values
  * @return mixed FALSE if failure, string if success
  * @author Jesse Bunch
  */
 private function _compile_and_compress($code, $markup_type)
 {
     @ini_set('memory_limit', '50M');
     @ini_set('memory_limit', '128M');
     @ini_set('memory_limit', '256M');
     @ini_set('memory_limit', '512M');
     @ini_set('memory_limit', '1024M');
     try {
         switch ($markup_type) {
             case self::MARKUP_TYPE_LESS:
                 // Compile with LESS
                 require_once CRAFT_PLUGINS_PATH . 'automin/vendor/lessphp/lessc.inc.php';
                 $less_obj = new \lessc();
                 $code = $less_obj->parse($code);
                 if ($this->settings['autominMinifyEnabled']) {
                     // Compress CSS
                     require_once CRAFT_PLUGINS_PATH . 'automin/vendor/class.minify_css_compressor.php';
                     $code = \Minify_CSS_Compressor::process($code);
                 }
                 break;
             case self::MARKUP_TYPE_SCSS:
                 // Compile with SCSS
                 require_once CRAFT_PLUGINS_PATH . 'automin/vendor/scssphp/scss.inc.php';
                 $scss_parser = new \scssc();
                 $scss_parser->setImportPaths($this->settings['autominSCSSIncludePaths']);
                 $code = $scss_parser->compile($code);
                 if ($this->settings['autominMinifyEnabled']) {
                     // Compress CSS
                     require_once CRAFT_PLUGINS_PATH . 'automin/vendor/class.minify_css_compressor.php';
                     $code = \Minify_CSS_Compressor::process($code);
                 }
                 break;
             case self::MARKUP_TYPE_CSS:
                 if ($this->settings['autominMinifyEnabled']) {
                     // Compress CSS
                     require_once CRAFT_PLUGINS_PATH . 'automin/vendor/class.minify_css_compressor.php';
                     $code = \Minify_CSS_Compressor::process($code);
                 }
                 break;
             case self::MARKUP_TYPE_JS:
                 if ($this->settings['autominMinifyEnabled']) {
                     // Compile JS
                     require_once CRAFT_PLUGINS_PATH . 'automin/vendor/class.jsmin.php';
                     $code = \JSMin::minify($code);
                 }
                 // require_once('libraries/class.minify_js_closure.php');
                 // $code = Minify_JS_ClosureCompiler::minify($code);
                 break;
         }
     } catch (Exception $e) {
         exit($e->getMessage());
         $this->_write_log('Compilation Exception: ' . $e->getMessage());
         return FALSE;
     }
     return $code;
 }
Ejemplo n.º 24
0
<?php

// SCSS Preprocessor
header('Content-Type: text/css');
if (!hasCache($file) || $is_new) {
    $scss = new scssc();
    $scss->setFormatter("scss_formatter");
    $scss->setImportPaths($dir);
    generateCache($file, $scss->compile(file_get_contents($file)));
}
outputCache($file);
Ejemplo n.º 25
0
<?php

define('SCSS_PATH', dirname(__FILE__) . '/scss');
require_once dirname(__FILE__) . '/superhero_scss.php';
$scss = new scssc();
$scss->setImportPaths(SCSS_PATH);
$scss->setFormatter('scss_formatter');
$values = $form_state['values'];
$presets = json_decode(base64_decode($values['superhero_presets']));
// Section Custom Style
foreach ($theme->sections as $section => $item) {
    $container = 'section-' . $section;
    $style_margin = trim($values["superhero_section_{$section}_style_margin"]);
    $style_padding = trim($values["superhero_section_{$section}_style_padding"]);
    $style_margin = $style_margin == "" ? "false" : $style_margin;
    $style_padding = $style_padding == "" ? "false" : $style_padding;
    $output = <<<SCSS
\t\$section: {$container};
\t\$style_margin: {$style_margin};
\t\$style_padding: {$style_padding};
\t@import "section";
SCSS;
    $CSS .= $scss->compile($output);
}
// Preset Colours
foreach ($presets as $k => $preset) {
    $maincolor = isset($preset->superhero_color_main) ? $preset->superhero_color_main : "false";
    $textcolor = isset($preset->superhero_color_text) ? $preset->superhero_color_text : "false";
    $linkcolor = isset($preset->superhero_color_link) ? $preset->superhero_color_link : "false";
    $hovercolor = isset($preset->superhero_color_hover) ? $preset->superhero_color_hover : "false";
    $headingcolor = isset($preset->superhero_color_heading) ? $preset->superhero_color_heading : "false";
Ejemplo n.º 26
0
 /**
  * Handle SCSS/LESS files
  *
  * @param string $content The file content
  * @param array  $arrFile The file array
  *
  * @return string The modified file content
  */
 protected function handleScssLess($content, $arrFile)
 {
     if ($arrFile['extension'] == self::SCSS) {
         $objCompiler = new \scssc();
         new \scss_compass($objCompiler);
         $objCompiler->setImportPaths(array(TL_ROOT . '/' . dirname($arrFile['name']), TL_ROOT . '/vendor/leafo/scssphp-compass/stylesheets'));
         $objCompiler->setFormatter(\Config::get('debugMode') ? 'scss_formatter' : 'scss_formatter_compressed');
     } else {
         $objCompiler = new \lessc();
         $objCompiler->setImportDir(array(TL_ROOT . '/' . dirname($arrFile['name'])));
         $objCompiler->setFormatter(\Config::get('debugMode') ? 'lessjs' : 'compressed');
     }
     return $this->fixPaths($objCompiler->compile($content), $arrFile);
 }
Ejemplo n.º 27
0
function porto_compile_css($import = false)
{
    if (current_user_can('manage_options') && (isset($_GET['compile_theme']) || $import)) {
        global $reduxPortoSettings;
        $reduxFramework = $reduxPortoSettings->ReduxFramework;
        $template_dir = porto_dir;
        // Compile SCSS files
        if (!class_exists('scssc')) {
            require_once porto_admin . '/scssphp/scss.inc.php';
        }
        // config file
        ob_start();
        require dirname(__FILE__) . '/config_scss_theme.php';
        $_config_css = ob_get_clean();
        $filename = $template_dir . '/scss/_config_theme.scss';
        if (is_writable(dirname($filename)) == false) {
            @chmod(dirname($filename), 0755);
        }
        if (file_exists($filename)) {
            if (is_writable($filename) == false) {
                @chmod($filename, 0755);
            }
            @unlink($filename);
        }
        $reduxFramework->filesystem->execute('put_contents', $filename, array('content' => $_config_css));
        ob_start();
        $scss = new scssc();
        $scss->setImportPaths($template_dir . '/scss');
        $scss->setFormatter('scss_formatter');
        echo $scss->compile('@import "theme.scss"');
        $_config_css = ob_get_clean();
        $filename = $template_dir . '/css/theme_' . get_current_blog_id() . '.css';
        if (is_writable(dirname($filename)) == false) {
            @chmod(dirname($filename), 0755);
        }
        if (file_exists($filename)) {
            if (is_writable($filename) == false) {
                @chmod($filename, 0755);
            }
            @unlink($filename);
        }
        $reduxFramework->filesystem->execute('put_contents', $filename, array('content' => $_config_css));
        if (!$import) {
            // finally redirect to success page
            wp_redirect(admin_url('admin.php?page=porto_settings&compile_theme_success=true'));
        }
    }
    if (current_user_can('manage_options') && (isset($_GET['compile_theme_rtl']) || $import)) {
        global $reduxPortoSettings;
        $reduxFramework = $reduxPortoSettings->ReduxFramework;
        $template_dir = porto_dir;
        // Compile SCSS files
        if (!class_exists('scssc')) {
            require_once porto_admin . '/scssphp/scss.inc.php';
        }
        // config file
        ob_start();
        require dirname(__FILE__) . '/config_scss_theme.php';
        $_config_css = ob_get_clean();
        $filename = $template_dir . '/scss/_config_theme.scss';
        if (is_writable(dirname($filename)) == false) {
            @chmod(dirname($filename), 0755);
        }
        if (file_exists($filename)) {
            if (is_writable($filename) == false) {
                @chmod($filename, 0755);
            }
            @unlink($filename);
        }
        $reduxFramework->filesystem->execute('put_contents', $filename, array('content' => $_config_css));
        ob_start();
        $scss = new scssc();
        $scss->setImportPaths($template_dir . '/scss');
        $scss->setFormatter('scss_formatter');
        echo $scss->compile('@import "theme_rtl.scss"');
        $_config_css = ob_get_clean();
        $filename = $template_dir . '/css/theme_rtl_' . get_current_blog_id() . '.css';
        if (is_writable(dirname($filename)) == false) {
            @chmod(dirname($filename), 0755);
        }
        if (file_exists($filename)) {
            if (is_writable($filename) == false) {
                @chmod($filename, 0755);
            }
            @unlink($filename);
        }
        $reduxFramework->filesystem->execute('put_contents', $filename, array('content' => $_config_css));
        if (!$import) {
            // finally redirect to success page
            wp_redirect(admin_url('admin.php?page=porto_settings&compile_theme_rtl_success=true'));
        }
    }
    if (current_user_can('manage_options') && (isset($_GET['compile_plugins']) || $import)) {
        global $reduxPortoSettings;
        $reduxFramework = $reduxPortoSettings->ReduxFramework;
        $template_dir = porto_dir;
        // Compile SCSS files
        if (!class_exists('scssc')) {
            require_once porto_admin . '/scssphp/scss.inc.php';
        }
        // config file
        ob_start();
        require dirname(__FILE__) . '/config_scss_plugins.php';
        $_config_css = ob_get_clean();
        $filename = $template_dir . '/scss/_config_plugins.scss';
        if (is_writable(dirname($filename)) == false) {
            @chmod(dirname($filename), 0755);
        }
        if (file_exists($filename)) {
            if (is_writable($filename) == false) {
                @chmod($filename, 0755);
            }
            @unlink($filename);
        }
        $reduxFramework->filesystem->execute('put_contents', $filename, array('content' => $_config_css));
        ob_start();
        $scss = new scssc();
        $scss->setImportPaths($template_dir . '/scss');
        $scss->setFormatter('scss_formatter');
        echo $scss->compile('@import "plugins.scss"');
        $_config_css = ob_get_clean();
        $filename = $template_dir . '/css/plugins_' . get_current_blog_id() . '.css';
        if (is_writable(dirname($filename)) == false) {
            @chmod(dirname($filename), 0755);
        }
        if (file_exists($filename)) {
            if (is_writable($filename) == false) {
                @chmod($filename, 0755);
            }
            @unlink($filename);
        }
        $reduxFramework->filesystem->execute('put_contents', $filename, array('content' => $_config_css));
        if (!$import) {
            // finally redirect to success page
            wp_redirect(admin_url('admin.php?page=porto_settings&compile_plugins_success=true'));
        }
    }
    if (current_user_can('manage_options') && (isset($_GET['compile_plugins_rtl']) || $import)) {
        global $reduxPortoSettings;
        $reduxFramework = $reduxPortoSettings->ReduxFramework;
        $template_dir = porto_dir;
        // Compile SCSS files
        if (!class_exists('scssc')) {
            require_once porto_admin . '/scssphp/scss.inc.php';
        }
        // config file
        ob_start();
        require dirname(__FILE__) . '/config_scss_plugins.php';
        $_config_css = ob_get_clean();
        $filename = $template_dir . '/scss/_config_plugins.scss';
        if (is_writable(dirname($filename)) == false) {
            @chmod(dirname($filename), 0755);
        }
        if (file_exists($filename)) {
            if (is_writable($filename) == false) {
                @chmod($filename, 0755);
            }
            @unlink($filename);
        }
        $reduxFramework->filesystem->execute('put_contents', $filename, array('content' => $_config_css));
        ob_start();
        $scss = new scssc();
        $scss->setImportPaths($template_dir . '/scss');
        $scss->setFormatter('scss_formatter');
        echo $scss->compile('@import "plugins_rtl.scss"');
        $_config_css = ob_get_clean();
        $filename = $template_dir . '/css/plugins_rtl_' . get_current_blog_id() . '.css';
        if (is_writable(dirname($filename)) == false) {
            @chmod(dirname($filename), 0755);
        }
        if (file_exists($filename)) {
            if (is_writable($filename) == false) {
                @chmod($filename, 0755);
            }
            @unlink($filename);
        }
        $reduxFramework->filesystem->execute('put_contents', $filename, array('content' => $_config_css));
        if (!$import) {
            // finally redirect to success page
            wp_redirect(admin_url('admin.php?page=porto_settings&compile_plugins_rtl_success=true'));
        }
    }
}
Ejemplo n.º 28
0
<?php

header('Content-Type: text/css');
require 'scss.inc.php';
$scss = new scssc();
$scss->setImportPaths(__DIR__ . '/');
echo $scss->compile('@import "_bootstrap.scss"');
Ejemplo n.º 29
0
// Langs:	PHP only
// Example:
// $fh = fopen(dirname(__FILE__)."/../file-dir-access.log", 'a');
// fwrite($fh, "SAVE >>> ".date("D dS M Y h:i:sa").": ".$fileLoc."/".$fileName."\n");
// fclose($fh);
// Compiling Sass and LESS files (.scss and .less to .css version, with same name, in same dir)
$fileName = basename($file);
$filePieces = explode(".", $file);
$fileExt = $filePieces[count($filePieces) - 1];
// SCSS Compiling if we have SCSSPHP plugin installed
if (strtolower($fileExt) == "scss" && file_exists(dirname(__FILE__) . "/../plugins/scssphp/scss.inc.php")) {
    // Load the SCSSPHP lib and start a new instance
    require dirname(__FILE__) . "/../plugins/scssphp/scss.inc.php";
    $scss = new scssc();
    // Set the import path and formatting type
    $scss->setImportPaths(dirname($file) . "/");
    $scss->setFormatter('scss_formatter_compressed');
    // scss_formatter, scss_formatter_nested, scss_formatter_compressed
    try {
        $scssContent = $scss->compile('@import "' . $fileName . '"');
        $fh = fopen(substr($file, 0, -4) . "css", 'w');
        fwrite($fh, $scssContent);
        fclose($fh);
    } catch (Exception $e) {
        echo ";top.ICEcoder.message('Couldn\\'t compile your Sass, error info below:\\n\\n" . $e->getMessage() . "');";
    }
}
// LESS Compiling if we have LESSPHP plugin installed
if (strtolower($fileExt) == "less" && file_exists(dirname(__FILE__) . "/../plugins/lessphp/lessc.inc.php")) {
    // Load the LESSPHP lib and start a new instance
    require dirname(__FILE__) . "/../plugins/lessphp/lessc.inc.php";
Ejemplo n.º 30
0
 /**
  * Compile the file with SASS
  *
  * @param   string  $sassFilePath   The SASS file path
  * @param   string  $filePath       The compiled file path
  */
 protected function _sassCompile($sassFilePath, $filePath)
 {
     // The compiled file must be writable
     if (!is_writable($filePath)) {
         $logger = Logger::getInstance();
         $logger->warning('The file ' . $filePath . ' is not writable');
         return;
     }
     // The SASS file must be readable
     if (!is_readable($sassFilePath)) {
         $logger = Logger::getInstance();
         $logger->warning('The file ' . $sassFilePath . ' is not readable');
         return;
     }
     // Compile
     $options = ['syntax' => 'scss'];
     try {
         //$parser = new \SassParser($options);
         //$content = $parser->toCss($sassFilePath);
         $parser = new \scssc();
         $parser->setImportPaths(dirname($sassFilePath) . '/');
         $source = file_get_contents($sassFilePath);
         $content = $parser->compile($source);
         file_put_contents($filePath, $content);
     } catch (\Exception $error) {
         $logger = Logger::getInstance();
         $logger->warning('Unable to compile ' . $filePath . ': ' . $error->getMessage());
     }
 }