/**
  * Process a WPLessStylesheet
  * 
  * This logic was previously held in WPLessStylesheet::save()
  * 
  * @since 1.4.2
  */
 public function saveStylesheet(WPLessStylesheet $stylesheet)
 {
     wp_mkdir_p(dirname($stylesheet->getTargetPath()));
     try {
         do_action('wp-less_stylesheet_save_pre', $stylesheet, $stylesheet->getVariables());
         file_put_contents($stylesheet->getTargetPath(), apply_filters('wp-less_stylesheet_save', $this->parse(null, $stylesheet->getVariables()), $stylesheet));
         chmod($stylesheet->getTargetPath(), 0666);
         $stylesheet->save();
         do_action('wp-less_stylesheet_save_post', $stylesheet);
     } catch (Exception $e) {
         wp_die($e->getMessage());
     }
 }
Ejemplo n.º 2
0
 /**
  * Process a WPLessStylesheet
  *
  * This logic was previously held in WPLessStylesheet::save()
  *
  * @since 1.4.2
  * @param WPLessStylesheet $stylesheet
  * @param null $css
  */
 public function saveStylesheet(WPLessStylesheet $stylesheet, $css = null)
 {
     wp_mkdir_p(dirname($stylesheet->getTargetPath()));
     try {
         do_action('wp-less_stylesheet_save_pre', $stylesheet, $this->getVariables());
         if ($css === null) {
             $css = $this->compileFile($stylesheet->getSourcePath());
         }
         file_put_contents($stylesheet->getTargetPath(), apply_filters('wp-less_stylesheet_save', $css, $stylesheet));
         chmod($stylesheet->getTargetPath(), 0666);
         $stylesheet->save();
         do_action('wp-less_stylesheet_save_post', $stylesheet);
     } catch (Exception $e) {
         wp_die($e->getMessage());
     }
 }
Ejemplo n.º 3
0
 /**
  * Process all stylesheets to compile just in time
  *
  * @author oncletom
  * @since 1.0
  * @version 1.1
  * @param $force boolean If set to true, rebuild all stylesheets, without considering they are updated or not
  */
 public function processStylesheets($force = false)
 {
     $styles = $this->getQueuedStylesToProcess();
     $force = is_bool($force) && $force ? !!$force : false;
     WPLessStylesheet::$upload_dir = $this->configuration->getUploadDir();
     WPLessStylesheet::$upload_uri = $this->configuration->getUploadUrl();
     if (empty($styles)) {
         return;
     }
     if (!wp_mkdir_p(WPLessStylesheet::$upload_dir)) {
         throw new WPLessException(sprintf('The upload dir folder (`%s`) is not writable from %s.', WPLessStylesheet::$upload_dir, get_class($this)));
     }
     foreach ($styles as $style_id) {
         $this->processStylesheet($style_id, $force);
     }
     do_action('wp-less_plugin_process_stylesheets', $styles);
 }
Ejemplo n.º 4
0
 /**
  * Process a WPLessStylesheet
  *
  * This logic was previously held in WPLessStylesheet::save()
  *
  * @since 1.4.2
  * @param WPLessStylesheet $stylesheet
  * @param null $css
  */
 public function saveStylesheet(WPLessStylesheet $stylesheet, $css = null)
 {
     wp_mkdir_p(dirname($stylesheet->getTargetPath()));
     set_error_handler(create_function('$severity, $message, $file, $line', 'throw new ErrorException($message, $severity, $severity, $file, $line);'));
     try {
         do_action('wp-less_stylesheet_save_pre', $stylesheet, $this->getVariables());
         if ($css === null) {
             $css = $this->compileFile($stylesheet->getSourcePath());
         }
         file_put_contents($stylesheet->getTargetPath(), apply_filters('wp-less_stylesheet_save', $css, $stylesheet));
         chmod($stylesheet->getTargetPath(), 0666);
         $stylesheet->save();
         do_action('wp-less_stylesheet_save_post', $stylesheet);
     } catch (Exception $e) {
         // wp_die($e->getMessage());
         do_action('wp-less_save_stylesheet_error', $e);
     }
     restore_error_handler();
 }
Ejemplo n.º 5
0
	/**
	 * Update custom.less stylesheet.
	 */
	function presscore_generate_less_css_file( $handler = 'dt-custom.less', $src = '' ) {

		/**
		 * Include WP-Less.
		 *
		 */
		require_once( PRESSCORE_EXTENSIONS_DIR . '/wp-less/bootstrap-for-theme.php' );

		// WP-Less init
		if ( class_exists('WPLessPlugin') ) {
			$less = WPLessPlugin::getInstance();
			$less->dispatch();
		}

		/**
		 * Less helpers.
		 *
		 * @since presscore 1.0.6
		 */
		require_once( PRESSCORE_EXTENSIONS_DIR . '/less-functions.php' );

		/**
		 * Less variables.
		 *
		 * @since presscore 0.5
		 */
		if ( $located_file = locate_template( 'inc/less-vars.php' ) ) {
			include_once( $located_file );
		}

		// $less = WPLessPlugin::getInstance();
		$config = $less->getConfiguration();

		if ( !wp_style_is($handler, 'registered') ) {

			if ( !$src ) {
				$src = PRESSCORE_THEME_URI . '/css/custom.less';
			}

			wp_register_style( $handler, $src );
		}

		// save options
		$options = presscore_compile_less_vars();

		if ( $options ) {
			$less->setVariables( $options );
		}

		WPLessStylesheet::$upload_dir = $config->getUploadDir();
		WPLessStylesheet::$upload_uri = $config->getUploadUrl();

		return $less->processStylesheet( $handler, true );
	}
Ejemplo n.º 6
0
 /**
  * Process a single stylesheet
  *
  * @author oncletom
  * @since 1.1
  * @version 1.3
  * @param string $handle
  * @param $force boolean If set to true, rebuild all stylesheets, without considering they are updated or not
  * @return WPLessStylesheet
  */
 public function processStylesheet($handle, $force = false)
 {
     $force = !!$force ? $force : $this->configuration->alwaysRecompile();
     $wp_styles = $this->getStyles();
     $stylesheet = new WPLessStylesheet($wp_styles->registered[$handle], $this->getCompiler()->getVariables());
     if ($this->configuration->getCompilationStrategy() === 'legacy' && $stylesheet->hasToCompile()) {
         $this->getCompiler()->saveStylesheet($stylesheet);
     } elseif ($this->configuration->getCompilationStrategy() !== 'legacy') {
         $this->getCompiler()->cacheStylesheet($stylesheet, $force);
     }
     $wp_styles->registered[$handle]->src = $stylesheet->getTargetUri();
     return $stylesheet;
 }
Ejemplo n.º 7
0
 /**
  *
  * Parse and register less file and convert it to css
  *
  * @param string $handler
  * @param string $src      css file source
  * @param array  $deps
  * @param bool   $version
  * @param string $media
  * @param bool   $compress the file should by compressed
  *
  * @return mixed
  * @throws Exception
  * @access public
  */
 public function registerStylesheetsTemplates($handler = 'custom.less', $src = '', array $deps = array(), $version = false, $media = 'all', $compress = false)
 {
     if (class_exists('\\WPLessPlugin')) {
         $less = \WPLessPlugin::getInstance();
         $less->dispatch();
         // we’re done, everything works as if the plugin is activated
         $less_config = $less->getConfiguration();
         $less_config->setUploadDir($this->upload_dir);
         $less_config->setUploadUrl($this->upload_url);
         $css_uri = FileSystem::getDirectory('css_uri');
         $less->setImportDir(array($css_uri . 'less'));
         $less_variable = $this->variables;
         $less->setVariables($less_variable);
         \Less_Parser::$default_options['compress'] = $compress;
         //\Less_Parser::$default_options['cache_method'] = 'serialize';
         \WPLessStylesheet::$upload_dir = $less_config->getUploadDir();
         \WPLessStylesheet::$upload_uri = $less_config->getUploadUrl();
         if (!wp_style_is($handler, 'registered')) {
             if (!$src) {
                 $src = $css_uri . 'less/style.less';
             }
             wp_register_style($handler, $src, $deps, $version, $media);
             wp_enqueue_style($handler);
         }
         return $less->processStylesheet($handler, true);
     } else {
         throw new Exception(Translate::translate('WP-Less plugin not found.'));
     }
 }