public function get_default_layout($cascade, $layout_slug = "", $add_global_regions = false) { $regions = new Upfront_Layout_Maker(); $template_path = $this->find_default_layout($cascade, $layout_slug); $current_theme = Upfront_ChildTheme::get_instance(); if ($add_global_regions && $current_theme && $current_theme->has_global_region('header')) { include get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'global-regions' . DIRECTORY_SEPARATOR . 'header.php'; } require $template_path; if ($add_global_regions && $current_theme && $current_theme->has_global_region('footer')) { include get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'global-regions' . DIRECTORY_SEPARATOR . 'footer.php'; } $layout = $regions->create_layout(); return $layout; }
private function initialize_default_breakpoints() { if (is_null(Upfront_ChildTheme::get_instance())) { return $this->get_default_breakpoints(); } $layout_properties = json_decode(Upfront_ChildTheme::get_settings()->get('layout_properties'), true); if (!is_array($layout_properties)) { return $this->get_default_breakpoints(); } foreach ($layout_properties as $property) { if ($property['name'] === 'grid') { $grid_settings = $property['value']; } } if (!isset($grid_settings)) { return $this->get_default_breakpoints(); } // Do the actual merge from here on $defaults = $this->get_default_breakpoints(); $properties = array('column_widths' => 'column_width', 'column_paddings' => 'column_padding', 'baselines' => 'baseline', 'type_paddings' => 'type_padding'); foreach ($properties as $prop_name => $prop_translated) { if (isset($grid_settings[$prop_name])) { foreach ($grid_settings[$prop_name] as $name => $value) { switch ($name) { case 'desktop': $defaults[0][$prop_translated] = $value; break; case 'tablet': $defaults[1][$prop_translated] = $value; break; case 'mobile': $defaults[2][$prop_translated] = $value; break; } } } } return $defaults; }
function create_layout() { $layout_ids = $_POST['data']; $stylesheet = $_POST['stylesheet']; $layout_slug = !empty($_POST['layout_slug']) ? $_POST['layout_slug'] : false; $load_dev = $_POST['load_dev'] == 1 ? true : false; $post_type = isset($_POST['new_post']) ? $_POST['new_post'] : false; $parsed = false; if (empty($layout_ids)) { $this->_out(new Upfront_JsonResponse_Error("No such layout")); } upfront_switch_stylesheet($stylesheet); if (is_string($layout_ids)) { $layout_ids = Upfront_EntityResolver::ids_from_url($layout_ids); $parsed = true; } // Start by nulling out the layout $layout = false; // Check if we're to inherit a layout from a page template if (!empty($_POST['use_existing'])) { // Resolve existing page template to a layout $tpl = preg_replace('/page_tpl-(.*)\\.php/', '\\1', $_POST['use_existing']); $theme = Upfront_ChildTheme::get_instance(); $settings = $theme->get_theme_settings(); if (!empty($tpl) && !empty($settings)) { $required_pages = $settings->get('required_pages'); if (!empty($required_pages)) { $required_pages = json_decode($required_pages, true); } $specificity = !empty($required_pages[$tpl]['layout']) ? $required_pages[$tpl]['layout'] : false; if (!empty($specificity)) { $template_layout = Upfront_Layout::from_entity_ids(array('specificity' => $specificity)); if (!empty($template_layout) && !$template_layout->is_empty()) { $layout = $template_layout; $layout->set('layout', $layout_ids); $layout->set('current_layout', $layout_ids['specificity']); } } } } // If we still don't have a template set, make one up if (empty($layout)) { $layout = Upfront_Layout::create_layout($layout_ids, $layout_slug); } global $post, $upfront_ajax_query; if (!$upfront_ajax_query) { $upfront_ajax_query = false; } if ($post_type) { $post = Upfront_PostModel::create($post_type); // set new layout IDS based on the created post ID $cascade = array('type' => 'single', 'item' => $post_type, 'specificity' => $post->ID); $layout_ids = Upfront_EntityResolver::get_entity_ids($cascade); } else { $post = $post; if ($post && is_singular()) { $layout_ids = Upfront_EntityResolver::get_entity_ids(); } else { if ($_POST['post_id']) { $posts = get_posts(array('include' => $_POST['post_id'], 'suppress_filters' => false)); if (sizeof($posts)) { $post = $posts[0]; } } } } $response = array('post' => $post, 'layout' => $layout->to_php(), 'cascade' => $layout_ids, 'query' => $upfront_ajax_query); $this->_out(new Upfront_JsonResponse_Success($response)); }
public function load_page_regions($data, $ids) { $layoutId = $this->_get_page_default_layout($ids); if (empty($layoutId) && !empty($ids['specificity'])) { $page_id = preg_replace('/.*-([0-9]+)$/', '$1', $ids['specificity']); $tpl = false; if (!empty($page_id) && is_numeric($page_id)) { $tpl = get_post_meta((int) $page_id, '_wp_page_template', true); } if (!empty($tpl)) { $theme = Upfront_ChildTheme::get_instance(); $tpl = preg_replace('/page_tpl-(.*)\\.php$/', '\\1', $tpl); $required_pages = $theme->get_theme_settings()->get('required_pages'); if (!empty($required_pages)) { $required_pages = json_decode($required_pages, true); } $layoutId = !empty($required_pages[$tpl]['layout']) ? $required_pages[$tpl]['layout'] : $layoutId; } } if ($layoutId) { $theme = Upfront_Theme::get_instance(); $ids['theme_defined'] = $layoutId; $data['regions'] = $theme->get_default_layout($ids, $layoutId); } return $data; }
function prepare_typography_styles($layout, $grid) { $typography = $layout->get_property_value('typography'); if (!$typography) { return ''; } $out = ''; $faces = array(); foreach ($typography as $element => $properties) { $properties = wp_parse_args($properties, array('font_face' => false, 'weight' => false, 'style' => false, 'size' => false, 'line_height' => false, 'color' => false)); $face = !empty($properties['font_face']) ? $properties['font_face'] : false; $faces[] = array('face' => $face, 'weight' => $properties['weight']); if (!empty($face) && false !== strpos($face, ' ')) { $face = '"' . $face . '"'; } $font = $properties['font_face'] ? "{$face}, {$properties['font_family']}" : "inherit"; $out .= ".upfront-output-object {$element} {\n" . "font-family: {$font};\n" . ($properties['weight'] ? "font-weight: {$properties['weight']};\n" : "") . ($properties['style'] ? "font-style: {$properties['style']};\n" : "") . ($properties['size'] ? "font-size: {$properties['size']}px;\n" : "") . ($properties['line_height'] ? "line-height: {$properties['line_height']}em;\n" : "") . "color: {$properties['color']};\n" . "}\n"; } // Responsive/breakpoint typography $breakpoints = $grid->get_breakpoints(); $tablet_typography; foreach ($breakpoints as $breakpoint) { // Ignore default/desktop breakpoint as we store it separately if ($breakpoint->is_default()) { continue; } $breakpoint_css = ''; // Breakpoint's typography should load (inherit) like this: // - if there is no typography for current breakpoint it should inherit settings from // wider one, if wider one is not defined inherit from one above, last one is default // typography // - in case of widest (tablet for now) it should inherit from default typography $breakpoint_id = $breakpoint->get_id(); $typography = $breakpoint->get_typography(); if ($breakpoint_id === 'tablet') { $tablet_typography = $typography; // needed for mobile } if (empty($typography) || false === isset($typography['h2'])) { switch ($breakpoint_id) { case 'tablet': $layout_properties = Upfront_ChildTheme::get_instance()->getLayoutProperties(); $value = upfront_get_property_value('typography', array('properties' => $layout_properties)); $typography = $value; break; case 'mobile': if (empty($tablet_typography)) { $layout_properties = Upfront_ChildTheme::get_instance()->getLayoutProperties(); $value = upfront_get_property_value('typography', array('properties' => $layout_properties)); $typography = $value; } else { $typography = $tablet_typography; } break; } } foreach ($typography as $element => $properties) { $properties = wp_parse_args($properties, array('font_face' => 'Arial', 'weight' => '400', 'style' => 'normal', 'size' => '16px', 'line_height' => '1.3', 'color' => 'black', 'font_family' => 'sans-serif')); $faces[] = array('face' => $properties['font_face'], 'weight' => $properties['weight']); $font = $properties['font_face'] ? "{$properties['font_face']}, {$properties['font_family']}" : "inherit"; $breakpoint_css .= ".upfront-output-object {$element} {\n" . "font-family: {$font};\n" . ($properties['weight'] ? "font-weight: {$properties['weight']};\n" : "") . ($properties['style'] ? "font-style: {$properties['style']};\n" : "") . ($properties['size'] ? "font-size: {$properties['size']}px;\n" : "") . ($properties['line_height'] ? "line-height: {$properties['line_height']}em;\n" : "") . "color: {$properties['color']};\n" . "}\n"; } $out .= $breakpoint->wrap($breakpoint_css, $breakpoints); } // Include Google fonts $faces = array_values(array_filter(array_unique($faces, SORT_REGULAR))); $google_fonts = new Upfront_Model_GoogleFonts(); $imports = ''; foreach ($faces as $face) { if (!$google_fonts->is_from_google($face['face'])) { continue; } $imports .= "@import \"https://fonts.googleapis.com/css?family=" . preg_replace('/\\s/', '+', $face['face']); if (400 !== (int) $face['weight'] && 'inherit' !== $face['weight']) { $imports .= ':' . $face['weight']; } $imports .= "\";\n"; } if (!empty($imports)) { $out = "{$imports}\n\n{$out}"; } $out = apply_filters('upfront_prepare_typography_styles', $out); return $out; }
function load_main() { $is_ssl = !empty($_GET['ssl']); $root = Upfront::get_root_url(); $ajax = admin_url('admin-ajax.php'); $site = home_url(); $includes_url = includes_url(); $current_theme_url = get_stylesheet_directory_uri(); if (empty($is_ssl) && is_ssl()) { $root = preg_replace('/^https:/', 'http:', $root); $includes_url = preg_replace('/^https:/', 'http:', $includes_url); $ajax = preg_replace('/^https:/', 'http:', $ajax); $site = preg_replace('/^https:/', 'http:', $site); $current_theme_url = preg_replace('/^https:/', 'http:', $current_theme_url); } $admin = admin_url(); $upfront_data_url = $ajax . '?action=upfront_data'; $entities = Upfront_Entity_Registry::get_instance(); $registered = $entities->get_all(); $child_instance = Upfront_ChildTheme::get_instance(); $paths = array("backbone" => $includes_url . "js/backbone.min", "underscore" => $includes_url . "js/underscore.min", "upfront-data" => $upfront_data_url, "text" => 'scripts/text', "async" => "scripts/async", "upfront" => "scripts/upfront", "models" => "scripts/upfront/upfront-models", "views" => "scripts/upfront/upfront-views", "editor_views" => "scripts/upfront/upfront-views-editor", "util" => "scripts/upfront/upfront-util", "behaviors" => "scripts/upfront/upfront-behaviors", "application" => "scripts/upfront/upfront-application", "objects" => "scripts/upfront/upfront-objects", "media" => "scripts/upfront/upfront-media", "content" => "scripts/upfront/upfront-content", "bg-settings" => "scripts/upfront/bg-settings/bg-settings", "spectrum" => "scripts/spectrum/spectrum", "responsive" => "scripts/responsive", "redactor_plugins" => 'scripts/redactor/plugins', "redactor" => 'scripts/redactor/redactor', "jquery-df" => 'scripts/jquery/jquery-dateFormat.min', "jquery-simulate" => 'scripts/jquery/jquery.simulate', "ueditor" => 'scripts/redactor/ueditor', "chosen" => "scripts/chosen/chosen.jquery.min", "findandreplace" => "scripts/findandreplace/findAndReplaceDOMText"); $paths = apply_filters('upfront-settings-requirement_paths', $paths + $registered); $shim = array('underscore' => array('exports' => '_'), 'redactor' => array('redactor_plugins'), 'jquery-df' => array('jquery'), 'chosen' => array('deps' => array('jquery'), 'exports' => 'jQuery.fn.chosen')); $require_config = array('baseUrl' => "{$root}", 'paths' => $paths, 'shim' => $shim, 'waitSeconds' => 60); if ($this->_debugger->is_active(Upfront_Debug::CACHED_RESPONSE)) { $require_config['urlArgs'] = "nocache=" + microtime(true); } $require_config = json_encode(apply_filters('upfront-settings-require_js_config', $require_config)); $layout_editor_requirements = array("core" => array('models', 'views', 'editor_views', 'behaviors', $upfront_data_url, 'media', 'content', 'spectrum', 'responsive', 'redactor', 'ueditor'), "entities" => array_merge(array('objects'), array_keys($registered))); $layout_editor_requirements = json_encode(apply_filters('upfront-settings-layout_editor_requirements', $layout_editor_requirements)); $grid = Upfront_Grid::get_grid(); $breakpoints = $grid->get_breakpoints(); $grid_info = array('breakpoint_columns' => array(), 'size_classes' => array(), 'margin_left_classes' => array(), 'margin_right_classes' => array(), 'margin_top_classes' => array(), 'margin_bottom_classes' => array(), 'scope' => $grid->get_grid_scope(), 'baseline' => '', 'size' => '', 'class' => '', 'left_margin_class' => '', 'right_margin_class' => '', 'baseline' => '', 'column_width' => '', 'column_padding' => '', 'type_padding' => '', 'top_margin_class' => '', 'bottom_margin_class' => '', 'size_name' => ''); foreach ($breakpoints as $context => $breakpoint) { $grid_info['breakpoint_columns'][$context] = $breakpoint->get_columns(); $grid_info['column_widths'][$context] = $breakpoint->get_column_width(); $grid_info['column_paddings'][$context] = $breakpoint->get_column_padding(); $grid_info['type_paddings'][$context] = $breakpoint->get_type_padding(); $grid_info['baselines'][$context] = $breakpoint->get_baseline(); $grid_info['size_classes'][$context] = $breakpoint->get_prefix(Upfront_GridBreakpoint::PREFIX_WIDTH); $grid_info['margin_left_classes'][$context] = $breakpoint->get_prefix(Upfront_GridBreakpoint::PREFIX_MARGIN_LEFT); $grid_info['margin_right_classes'][$context] = $breakpoint->get_prefix(Upfront_GridBreakpoint::PREFIX_MARGIN_RIGHT); $grid_info['margin_top_classes'][$context] = $breakpoint->get_prefix(Upfront_GridBreakpoint::PREFIX_MARGIN_TOP); $grid_info['margin_bottom_classes'][$context] = $breakpoint->get_prefix(Upfront_GridBreakpoint::PREFIX_MARGIN_BOTTOM); // @TODO temporary fix to keep old breakpoint work, before we move on to the new breakpoint system if ($breakpoint->is_default()) { $grid_info['size_name'] = $context; $grid_info['size'] = $breakpoint->get_columns(); $grid_info['column_width'] = $breakpoint->get_column_width(); $grid_info['column_padding'] = $breakpoint->get_column_padding(); $grid_info['type_padding'] = $breakpoint->get_type_padding(); $grid_info['baseline'] = $breakpoint->get_baseline(); $grid_info['class'] = $breakpoint->get_prefix(Upfront_GridBreakpoint::PREFIX_WIDTH); $grid_info['left_margin_class'] = $breakpoint->get_prefix(Upfront_GridBreakpoint::PREFIX_MARGIN_LEFT); $grid_info['right_margin_class'] = $breakpoint->get_prefix(Upfront_GridBreakpoint::PREFIX_MARGIN_RIGHT); $grid_info['top_margin_class'] = $breakpoint->get_prefix(Upfront_GridBreakpoint::PREFIX_MARGIN_TOP); $grid_info['bottom_margin_class'] = $breakpoint->get_prefix(Upfront_GridBreakpoint::PREFIX_MARGIN_BOTTOM); } } $grid_info = json_encode(apply_filters('upfront-settings-grid_info', $grid_info)); $theme_info = get_option('upfront_' . get_stylesheet() . '_responsive_settings'); $theme_info = apply_filters('upfront_get_responsive_settings', $theme_info); if (is_array($theme_info)) { $theme_info = json_encode($theme_info); } if (empty($theme_info) || $theme_info === '[]') { // Add defaults $defaults = Upfront_Grid::get_grid()->get_breakpoints_data(); $theme_info = json_encode(array('breakpoints' => $defaults)); } $theme_fonts = get_option('upfront_' . get_stylesheet() . '_theme_fonts'); $theme_fonts = apply_filters('upfront_get_theme_fonts', $theme_fonts, array('json' => true)); if (empty($theme_fonts)) { $theme_fonts = json_encode(array()); } $icon_fonts = get_option('upfront_' . get_stylesheet() . '_icon_fonts'); $icon_fonts = apply_filters('upfront_get_icon_fonts', $icon_fonts, array('json' => true)); if (empty($icon_fonts)) { $icon_fonts = json_encode(array()); } $additional_fonts = $child_instance ? $child_instance->getAdditionalFonts() : json_encode(array()); $current_user = wp_get_current_user(); $user_done_font_intro = in_array($current_user->user_login, get_option('upfront_users_done_font_intro', array())) ? 'true' : 'false'; $theme_colors = get_option('upfront_' . get_stylesheet() . '_theme_colors'); $theme_colors = apply_filters('upfront_get_theme_colors', $theme_colors, array('json' => true)); if (empty($theme_colors)) { $theme_colors = json_encode(array()); } $post_image_variants = get_option('upfront_' . get_stylesheet() . '_post_image_variants'); $post_image_variants = apply_filters('upfront_get_post_image_variants', $post_image_variants, array('json' => true)); if (empty($post_image_variants)) { $post_image_variants = json_encode(array()); } $button_presets = get_option('upfront_' . get_stylesheet() . '_button_presets'); $button_presets = apply_filters('upfront_get_button_presets', $button_presets, array('json' => true)); if (empty($button_presets)) { $button_presets = json_encode(array()); } $tab_presets = get_option('upfront_' . get_stylesheet() . '_tab_presets'); $tab_presets = apply_filters('upfront_get_tab_presets', $tab_presets, array('json' => true)); if (empty($tab_presets)) { $tab_presets = json_encode(array()); } $accordion_presets = get_option('upfront_' . get_stylesheet() . '_accordion_presets'); $accordion_presets = apply_filters('upfront_get_accordion_presets', $accordion_presets, array('json' => true)); if (empty($accordion_presets)) { $accordion_presets = json_encode(array()); } $debug = array("transients" => $this->_debugger->is_active(Upfront_Debug::JS_TRANSIENTS), "dev" => $this->_debugger->is_active(Upfront_Debug::DEV)); $debug = json_encode(apply_filters('upfront-settings-debug', $debug)); $specificity = json_encode(array('specificity' => __('This post only'), 'item' => __('All posts of this type'), 'type' => __('All posts'))); $content = json_encode(array('create' => array('page' => Upfront_VirtualPage::get_url('create/page'), 'post' => Upfront_VirtualPage::get_url('create/post')), 'edit' => array('page' => Upfront_VirtualPage::get_url('edit/page/'), 'post' => Upfront_VirtualPage::get_url('edit/post/')))); $allowed_modes = array(); if (Upfront_Permissions::current(Upfront_Permissions::LAYOUT_MODE)) { $allowed_modes[] = 'layout'; } if (Upfront_Permissions::current(Upfront_Permissions::CONTENT_MODE)) { $allowed_modes[] = 'content'; } if (Upfront_Permissions::current(Upfront_Permissions::THEME_MODE)) { $allowed_modes[] = 'theme'; } if (Upfront_Permissions::current(Upfront_Permissions::POSTLAYOUT_MODE)) { $allowed_modes[] = 'postlayout'; } if (Upfront_Permissions::current(Upfront_Permissions::RESPONSIVE_MODE)) { $allowed_modes[] = 'responsive'; } $application_modes = json_encode(array("LAYOUT" => "layout", "CONTENT" => "content", "THEME" => "theme", "POST" => "post layout", "CONTENT_STYLE" => "post content style", "POSTCONTENT" => "post content", "RESPONSIVE" => "responsive", "POSTCONTENT_STYLE" => false, "DEFAULT" => Upfront_Permissions::current(Upfront_Permissions::LAYOUT_MODE) ? "layout" : "content", "ALLOW" => Upfront_Permissions::current(Upfront_Permissions::LAYOUT_MODE) ? join(',', $allowed_modes) : "content")); $read_only = json_encode(defined('UPFRONT_READ_ONLY') && UPFRONT_READ_ONLY); $allow_revisions = json_encode(Upfront_Permissions::current(Upfront_Permissions::SAVE_REVISION)); $l10n = json_encode($this->_get_l10n_strings()); $content_settings = array(); if (Upfront_Permissions::current(Upfront_Permissions::CONTENT_MODE)) { $raw_post_types = get_post_types(array('public' => true), 'objects'); $content_settings["post_types"] = array(); foreach ($raw_post_types as $type => $obj) { if (empty($obj->labels->name)) { continue; } $content_settings["post_types"][] = array("name" => $type, "label" => $obj->labels->name); } } $content_settings = json_encode($content_settings); $main = <<<EOMainJs // Set up the global namespace var Upfront = window.Upfront || {}; Upfront.mainData = { \trequireConfig: {$require_config}, \troot: '{$root}', \tcurrentThemeUrl: '{$current_theme_url}', \tajax: '{$ajax}', \tadmin: '{$admin}', \tsite: '{$site}', \tdebug: {$debug}, \tlayoutEditorRequirements: {$layout_editor_requirements}, \tapplicationModes: {$application_modes}, \tALLOW_REVISIONS: {$allow_revisions}, \treadOnly: {$read_only}, \tspecificity: {$specificity}, \tgridInfo: {$grid_info}, \tthemeInfo: {$theme_info}, \tthemeFonts: {$theme_fonts}, \ticonFonts: {$icon_fonts}, \tadditionalFonts: {$additional_fonts}, \tuserDoneFontsIntro: {$user_done_font_intro}, \tbuttonPresets: {$button_presets}, \ttabPresets: {$tab_presets}, \taccordionPresets: {$accordion_presets}, \tthemeColors: {$theme_colors}, \tpostImageVariants: {$post_image_variants}, \tcontent: {$content}, \tcontent_settings: {$content_settings}, \tl10n: {$l10n} }; EOMainJs; $this->_out(new Upfront_JavascriptResponse_Success($main)); }