コード例 #1
0
ファイル: lessphp.php プロジェクト: sedici/wpmu-istec
 /**
  * Parse all the less files resolving the dependencies.
  *
  * @param array $variables
  * @param bool  $compile_core If set to true, it forces compilation of core CSS only, suitable for shipping.
  * @throws Ai1ec_File_Not_Found_Exception|Exception
  * @throws Exception
  * @return string
  */
 public function parse_less_files(array $variables = null, $compile_core = false)
 {
     // If no variables are passed, initialize from DB, config file, and
     // extension injections in one call.
     if (empty($variables)) {
         $variables = $this->get_saved_variables(false);
     }
     // convert the variables to key / value
     $variables = $this->convert_less_variables_for_parsing($variables);
     // Inject additional constants from extensions
     $variables = apply_filters('ai1ec_less_constants', $variables);
     // Use this variables for hashmap purposes.
     $this->variables = $variables;
     // Load the static variables defined in the theme's variables.less file.
     $this->load_static_theme_variables();
     $loader = $this->_registry->get('theme.loader');
     //Allow extensions to add their own LESS files.
     $this->files = apply_filters('ai1ec_less_files', $this->files);
     $this->files[] = 'override.less';
     // Find out the active theme URL.
     $option = $this->_registry->get('model.option');
     $theme = $option->get('ai1ec_current_theme');
     $this->lessc->addImportDir($theme['theme_dir'] . DIRECTORY_SEPARATOR . 'less');
     $import_dirs = array();
     foreach ($this->files as $file) {
         $file_to_parse = null;
         try {
             // Get the filename following our fallback convention
             $file_to_parse = $loader->get_file($file);
         } catch (Ai1ec_Exception $e) {
             // We let child themes override styles of Vortex.
             // So there is no fallback for override and we can continue.
             if ($file !== 'override.less') {
                 throw $e;
             } else {
                 // It's an override, skip it.
                 continue;
             }
         }
         // We prepend the unparsed variables.less file we got earlier.
         // We do this as we do not import that anymore in the less files.
         $this->unparsed_variable_file .= $file_to_parse->get_content();
         // Set the import directories for the file. Includes current directory of
         // file as well as theme directory in core. This is important for
         // dependencies to be resolved correctly.
         $dir = dirname($file_to_parse->get_name());
         if (!isset($import_dirs[$dir])) {
             $import_dirs[$dir] = true;
             $this->lessc->addImportDir($dir);
         }
     }
     $variables['fontdir'] = '~"' . Ai1ec_Http_Response_Helper::remove_protocols($theme['theme_url']) . '/font"';
     $variables['fontdir_default'] = '~"' . Ai1ec_Http_Response_Helper::remove_protocols($this->default_theme_url) . 'font"';
     $variables['imgdir'] = '~"' . Ai1ec_Http_Response_Helper::remove_protocols($theme['theme_url']) . '/img"';
     $variables['imgdir_default'] = '~"' . Ai1ec_Http_Response_Helper::remove_protocols($this->default_theme_url) . 'img"';
     if (true === $compile_core) {
         $variables['fontdir'] = '~"../font"';
         $variables['fontdir_default'] = '~"../font"';
         $variables['imgdir'] = '~"../img"';
         $variables['imgdir_default'] = '~"../img"';
     }
     try {
         $this->parsed_css = $this->lessc->parse($this->unparsed_variable_file, $variables);
     } catch (Exception $e) {
         throw $e;
     }
     // Replace font placeholders
     $this->parsed_css = preg_replace_callback('/__BASE64_FONT_([a-zA-Z0-9]+)_(\\S+)__/m', array($this, 'load_font_base64'), $this->parsed_css);
     return $this->parsed_css;
 }
コード例 #2
0
ファイル: frontend.php プロジェクト: zhebiewang/WP
 /**
  * Get the url to retrieve the css
  *
  * @return string
  */
 public function get_css_url()
 {
     // get what's saved. I t could be false, a int or a string.
     // if it's false or a int, use PHP to render CSS
     $saved_par = $this->db_adapter->get(self::QUERY_STRING_PARAM);
     // if it's empty it's a new install probably. Return static css.
     // if it's numeric, just consider it a new install
     if (empty($saved_par)) {
         $theme = $this->_registry->get('model.option')->get('ai1ec_current_theme');
         return Ai1ec_Http_Response_Helper::remove_protocols(apply_filters('ai1ec_frontend_standard_css_url', $theme['theme_url'] . '/css/ai1ec_parsed_css.css'));
     }
     if (is_numeric($saved_par)) {
         if ($this->_registry->get('model.settings')->get('render_css_as_link')) {
             $time = (int) $saved_par;
             $template_helper = $this->_registry->get('template.link.helper');
             return Ai1ec_Http_Response_Helper::remove_protocols(add_query_arg(array(self::QUERY_STRING_PARAM => $time), trailingslashit(ai1ec_get_site_url())));
         } else {
             add_action('wp_head', array($this, 'echo_css'));
             return '';
         }
     }
     // otherwise return the string
     return Ai1ec_Http_Response_Helper::remove_protocols($saved_par);
 }