public static function get_layout($layout_ids, $apply = false) { $layout = Upfront_Layout::from_entity_ids($layout_ids); if ($layout->is_empty()) { $layout = Upfront_Layout::create_layout($layout_ids); } $post_id = is_singular() ? get_the_ID() : ''; $post = get_post($post_id); self::$_instance = new self($layout, $post); // Add actions add_action('wp_enqueue_scripts', array(self::$_instance, 'add_styles')); add_action('wp_enqueue_scripts', array(self::$_instance, 'add_scripts'), 2); // Do the template... if ($apply) { return self::$_instance->apply_layout(); } return self::$_instance; }
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)); }
/** * Run first on each AJAX action registered with upfront_add_ajax */ function upfront_ajax_init() { $stylesheet = $layout_ids = $storage_key = $load_dev = false; // Automatically instantiate Upfront_Layout object if ($_SERVER['REQUEST_METHOD'] == 'POST') { $layout_ids = !empty($_POST['layout']) ? $_POST['layout'] : false; $storage_key = !empty($_POST['storage_key']) ? $_POST['storage_key'] : false; $stylesheet = !empty($_POST['stylesheet']) ? $_POST['stylesheet'] : false; $load_dev = !empty($_POST['load_dev']) && $_POST['load_dev'] == 1 ? true : false; } else { if (isset($_GET['layout'])) { $layout_ids = !empty($_GET['layout']) ? $_GET['layout'] : false; $storage_key = !empty($_GET['storage_key']) ? $_GET['storage_key'] : false; $stylesheet = !empty($_GET['stylesheet']) ? $_GET['stylesheet'] : false; $load_dev = !empty($_GET['load_dev']) && $_GET['load_dev'] == 1 ? true : false; } } if ($stylesheet === false) { $stylesheet = apply_filters('upfront_get_stylesheet', $stylesheet); } upfront_switch_stylesheet($stylesheet); if (!is_array($layout_ids)) { return; } $layout = Upfront_Layout::from_entity_ids($layout_ids, $storage_key, $load_dev); if ($layout->is_empty()) { $layout = Upfront_Layout::create_layout($layout_ids); } }