private function _to_scoped_style($raw, $id) { $id = !empty($id) ? "#{$id}" : ''; $scoped = ''; $raw = explode('}', $raw); if (empty($raw)) { return $scoped; } foreach ($raw as $rule) { $scoped .= "{$id} {$rule} }"; } if (class_exists('Upfront_UFC')) { $scoped = Upfront_UFC::init()->process_colors($scoped); } return !empty($scoped) ? "<style>{$scoped}</style>" : ''; }
public function get_markup() { $element_id = $this->_get_property('element_id'); $element_id = $element_id ? "id='{$element_id}'" : ''; $content = $this->_get_property('content'); $matches = array(); //$regex = '/<div class="plaintxt_padding([^>]*)>(.+?)<\/div>/s'; //preg_match($regex, $content, $matches); //if (sizeof($matches) > 1) $content = $matches[2]; if (preg_match('/<div class="plaintxt_padding([^>]*)>/s', $content)) { $doc = new DOMDocument(); $clean_doc = new DOMDocument(); $doc->loadHTML($content); $divs = $doc->getElementsByTagName('div'); $plaintxt_wrap = false; foreach ($divs as $div) { if (!$div->hasAttributes()) { continue; } $class = $div->attributes->getNamedItem('class'); if (!is_null($class) && !empty($class->nodeValue) && strpos($class->nodeValue, 'plaintxt_padding') !== false) { $plaintxt_wrap = $div; break; } } if ($plaintxt_wrap !== false && $plaintxt_wrap->hasChildNodes()) { foreach ($plaintxt_wrap->childNodes as $node) { $import_node = $clean_doc->importNode($node, true); $clean_doc->appendChild($import_node); } } $content = $clean_doc->saveHTML(); } $style = array(); if ($this->_get_property('background_color') && '' != $this->_get_property('background_color')) { $style[] = 'background-color: ' . Upfront_UFC::init()->process_colors($this->_get_property('background_color')); } if ($this->_get_property('border') && '' != $this->_get_property('border')) { $style[] = 'border: ' . Upfront_UFC::init()->process_colors($this->_get_property('border')); } $content = $this->_decorate_content($content); return (sizeof($style) > 0 ? "<div class='plaintxt_padding' style='" . implode(';', $style) . "'>" : '') . $content . (sizeof($style) > 0 ? "</div>" : ''); }
function load_styles() { $grid = Upfront_Grid::get_grid(); $layout = apply_filters('upfront-style-base_layout', Upfront_Layout::get_instance()); $preprocessor = new Upfront_StylePreprocessor($grid, $layout); $base_only = isset($_POST['base_only']) ? filter_var($_POST['base_only'], FILTER_VALIDATE_BOOLEAN) : false; // Alright, so initialize the var first $style = ''; // Add typography styles - rearranging so the imports from Google fonts come first, if needed. // When loading styles in editor mode don't include typography styles since they are generated // by javascript if (false === $base_only) { $style = $this->prepare_typography_styles($layout, $grid); $style .= $preprocessor->process(); } // Always load original theme styles into theme unless we're in builder, yay // Reasoning behind it: we want theme users to always have original theme styles loaded // because if they want to override some style they can add their own additional properties // or nullify explicitly existing rules. So, to avoid complex initialization logic depending // on wheather there is something in database just load theme styles always. In builder though // we don't want this because user is editing actual theme styles. $style .= $this->load_theme_styles_unless_in_builder(); // When loading styles in editor mode don't include element styles and colors since they // will be loaded separately to the body. If they are included in main style than after // style is edited in editor (e.g. some property is removed) inconsistencies may occur // especially with rules removal since those would still be defined in main style. if ($base_only) { $this->_out(new Upfront_JsonResponse_Success(array('styles' => $style))); return; } //Add theme styles $style .= $this->prepare_theme_styles(); // Add theme colors styles $style .= $this->_get_theme_colors_styles(); // Add elements presets styles $style = apply_filters('get_element_preset_styles', $style); $style = Upfront_UFC::init()->process_colors($style); $this->_out(new Upfront_CssResponse_Success($style)); }
public function get_markup() { $data = array(); $data['id'] = $this->_get_property('element_id'); $button_presets = get_option('upfront_' . get_stylesheet() . '_button_presets'); $button_presets = apply_filters('upfront_get_button_presets', $button_presets, array('json' => true)); $presets = json_decode($button_presets, true); $preset = false; $markup = ""; if (is_array($presets)) { foreach ($presets as $item) { if ($item['id'] == $this->_get_property('currentpreset')) { $preset = $item; break; } } } $ufc = Upfront_UFC::init(); $data['content'] = $this->_get_property('content'); if ($data['content'] == '') { $default_properties = $this->default_properties(); $data['content'] = $default_properties['content']; } $data['href'] = $this->_get_property('href'); $data['align'] = $this->_get_property('align'); $data['style_static'] = "border: " . $preset['borderwidth'] . "px " . $preset['bordertype'] . " " . $ufc->process_colors($preset['bordercolor']) . "; " . "border-radius: " . $preset['borderradius1'] . "px " . $preset['borderradius2'] . "px " . $preset['borderradius4'] . "px " . $preset['borderradius3'] . "px; " . "background-color: " . $ufc->process_colors($preset['bgcolor']) . "; " . "font-size: " . $preset['fontsize'] . "px; " . "font-family: " . $preset['fontface'] . "; " . "color: " . $ufc->process_colors($preset['color']) . "; " . "transition: all " . $preset['hov_duration'] . "s " . $preset['hov_transition'] . "; "; $data['style_hover'] = ''; if (isset($preset['hov_borderwidth'])) { $data['style_hover'] = $data['style_hover'] . 'border-width: ' . $preset['hov_borderwidth'] . 'px; '; } if (isset($preset['hov_bordertype'])) { $data['style_hover'] = $data['style_hover'] . 'border-style: ' . $preset['hov_bordertype'] . '; '; } if (isset($preset['hov_bordercolor'])) { $data['style_hover'] = $data['style_hover'] . 'border-color: ' . $ufc->process_colors($preset['hov_bordercolor']) . '; '; } if (isset($preset['hov_borderradius1'])) { $data['style_hover'] = $data['style_hover'] . 'border-top-left-radius: ' . $preset['hov_borderradius1'] . 'px; '; } if (isset($preset['hov_borderradius2'])) { $data['style_hover'] = $data['style_hover'] . 'border-top-right-radius: ' . $preset['hov_borderradius2'] . 'px; '; } if (isset($preset['hov_borderradius3'])) { $data['style_hover'] = $data['style_hover'] . 'border-bottom-right-radius: ' . $preset['hov_borderradius3'] . 'px; '; } if (isset($preset['hov_borderradius4'])) { $data['style_hover'] = $data['style_hover'] . 'border-bottom-left-radius: ' . $preset['hov_borderradius4'] . 'px; '; } if (isset($preset['hov_bgcolor'])) { $data['style_hover'] = $data['style_hover'] . 'background-color: ' . $ufc->process_colors($preset['hov_bgcolor']) . '; '; } if (isset($preset['hov_fontsize'])) { $data['style_hover'] = $data['style_hover'] . 'font-size: ' . $preset['hov_fontsize'] . 'px; '; } if (isset($preset['hov_fontface'])) { $data['style_hover'] = $data['style_hover'] . 'font-family: ' . $preset['hov_fontsize'] . '; '; } if (isset($preset['hov_color'])) { $data['style_hover'] = $data['style_hover'] . 'color: ' . $ufc->process_colors($preset['hov_color']) . '; '; } $data['linkTarget'] = strpos($data['href'], '#') === 0 || strpos($data['href'], 'mailto:') === 0 ? '_self' : $this->_get_property('linkTarget'); /* $data['style_hover'] = "border: ".$preset['hov_borderwidth']."px ".$preset['hov_bordertype']." ".$preset['hov_bordercolor']."; "."border-radius: ".$preset['hov_borderradius1']."px ".$preset['hov_borderradius2']."px ".$preset['hov_borderradius4']."px ".$preset['hov_borderradius3']."px; "."background-color: ".$preset['hov_bgcolor']."; "."font-size: ".$preset['hov_fontsize']."px; "."font-family: ".$preset['hov_fontface']."; "."color: ".$preset['hov_color']."; "; */ $markup = upfront_get_template('ubutton', $data, dirname(dirname(__FILE__)) . '/tpl/ubutton.php.html'); return $markup; }