function prepare_theme_styles()
 {
     // Fix storage key missing _dev in dev mode. This is regular GET request.
     $storage_key = Upfront_Layout::get_storage_key();
     if (isset($_GET['load_dev']) && $_GET['load_dev'] == 1 && strpos($storage_key, '_dev') === false) {
         $storage_key = $storage_key . '_dev';
     }
     $styles = get_option($storage_key . '_' . get_stylesheet() . '_styles', array());
     $out = '';
     //$layout = Upfront_Layout::get_cascade();
     $layout = Upfront_Layout::get_parsed_cascade();
     // Use pure static method instead
     $layout_id = !empty($layout['specificity']) ? $layout['specificity'] : (!empty($layout['item']) ? $layout['item'] : $layout['type']);
     $layout_style_loaded = false;
     // Keep track of global layout CSS, so we sent over to the filter
     if (is_array($styles)) {
         foreach ($styles as $type => $elements) {
             foreach ($elements as $name => $content) {
                 // If region CSS, only load the one saved matched the layout_id
                 $style_rx = '/^(' . preg_quote("{$layout_id}", '/') . '|' . preg_quote("{$type}", '/') . ')/';
                 if (preg_match('/^region(-container|)$/', $type) && !preg_match($style_rx, $name)) {
                     continue;
                 }
                 $out .= $content;
                 if ($type == 'layout' && $name == 'layout-style') {
                     $layout_style_loaded = true;
                 }
             }
         }
     }
     $out = apply_filters('upfront_prepare_theme_styles', $out, $layout_style_loaded);
     return $out;
 }
 public function getThemeStylesAsCss()
 {
     //$layout = Upfront_Layout::get_cascade();
     $layout = Upfront_Layout::get_parsed_cascade();
     // Use pure static method instead
     $layout_id = !empty($layout['specificity']) ? $layout['specificity'] : (!empty($layout['item']) ? $layout['item'] : $layout['type']);
     $out = '';
     // See if there are styles in theme files
     $styles_root = get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'element-styles';
     // List subdirectories as element types
     $element_types = is_dir($styles_root) ? array_diff(scandir($styles_root), Upfront::$Excluded_Files) : array();
     $alternate_layout_id = false;
     if (!empty($layout['item']) && 'single-page' == $layout['item'] && !empty($layout['specificity'])) {
         $page_id = preg_replace('/.*-([0-9]+)$/', '$1', $layout['specificity']);
         if (is_numeric($page_id)) {
             foreach ($this->get_required_pages() as $page) {
                 if ((int) $page->get_id() !== (int) $page_id) {
                     continue;
                 }
                 $alternate_layout_id = $page->get_layout_name();
                 break;
             }
         }
     }
     foreach ($element_types as $type) {
         $style_files = array_diff(scandir($styles_root . DIRECTORY_SEPARATOR . $type), Upfront::$Excluded_Files);
         foreach ($style_files as $style) {
             // If region CSS, only load the one saved matched the layout_id
             $style_rx = '/^(' . preg_quote("{$layout_id}", '/') . '|' . preg_quote("{$type}", '/') . (!empty($alternate_layout_id) ? '|' . preg_quote($alternate_layout_id, '/') : '') . ')/';
             if (preg_match('/^region(-container|)$/', $type) && !preg_match($style_rx, $style)) {
                 continue;
             }
             $style_content = file_get_contents($styles_root . DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR . $style);
             $style_content = $this->_expand_passive_relative_url($style_content);
             $out .= $style_content;
         }
     }
     // Add icon font style if there is active icon font other than UpFont
     $font = $this->getActiveIconFont();
     if ($font) {
         //$out .= "\nin font \n";
         $longSrc = '';
         foreach ($font['files'] as $type => $file) {
             $longSrc .= "url('" . self::THEME_BASE_URL_MACRO . '/icon-fonts/' . $file . "') format('";
             switch ($type) {
                 case 'eot':
                     $longSrc .= 'embedded-opentype';
                     break;
                 case 'woff':
                     $longSrc .= 'woff';
                     break;
                 case 'ttf':
                     $longSrc .= 'truetype';
                     break;
                 case 'svg':
                     $longSrc .= 'svg';
                     break;
             }
             $longSrc .= "'),";
         }
         $icon_font_style = "@font-face {" . "\tfont-family: '" . $font['family'] . "';";
         if (isset($font['files']['eot'])) {
             $icon_font_style .= "src: url('" . self::THEME_BASE_URL_MACRO . '/icon-fonts/' . $font['files']['eot'] . "');";
         }
         $icon_font_style .= "src:" . substr($longSrc, 0, -1) . ';';
         $icon_font_style .= "\tfont-weight: normal;" . "\tfont-style: normal;" . "}" . ".uf_font_icon {" . "\tfont-family: '" . $font['family'] . "'!important;" . "}";
         $out .= $this->_expand_passive_relative_url($icon_font_style) . "\n";
     }
     $this->_theme_styles_called = true;
     return $out;
 }
Beispiel #3
0
 public function get_entity_ids_value()
 {
     $entities = array();
     $entities = Upfront_Layout::get_parsed_cascade();
     if (empty($entities)) {
         $entities = Upfront_EntityResolver::get_entity_ids();
     }
     $entities['storage_key'] = Upfront_Model::get_storage_key();
     return base64_encode(json_encode($entities));
 }