/** * Get all information related to drawing a page. * Includes sections, data, and their model keys * @return array uniqueIDs, Data, option keys for model */ function get_view_model() { $view_model = $this->list['sections']; foreach ($view_model as $uid => &$info) { // Dont need the data added below unset($info['data']); $info['values'] = array('type' => '', 'value' => '', 'opts' => ''); $defaults = isset($this->factory[$info['object']]) ? $this->factory[$info['object']]->section_defaults() : array(); $data = isset($this->sections_data[$uid]) ? $this->sections_data[$uid] : $defaults; $modelized_data = pl_defaults_model($data); $keys = array(); $opts = array(); if (pl_is_static_template('viewmodel') && $info['object'] == 'PL_Content') { $opts = pl_get_template_settings(); } elseif (isset($this->factory[$info['object']])) { $opts = $this->factory[$info['object']]->section_opts(); } $keys = $this->recursive_parse_opts($opts, $data); /** Parse together for standard section options which aren't in array */ $info['values'] = wp_parse_args($keys, $modelized_data); $info = apply_filters('pl_model_' . $info['object'], $info); } unset($info); // set by reference if (isset($view_model[''])) { unset($view_model['']); } return $view_model; }
/** * Load a section via ajax */ function load_section($response, $data) { $map_meta = array('clone' => $data['UID'], 'object' => $data['object'], 'content' => array()); $level = 0; global $plfactory; if (is_object($plfactory->factory[$map_meta['object']])) { /** We need to setup the $post variable as if this is a normal page load */ global $wp_query; global $pl_page; /** Get the section object */ $s = $plfactory->factory[$map_meta['object']]; $s->level = 0; $s->meta = $map_meta; $s->content = $map_meta['content']; /** Set basic page variables, for loop */ $pl_page->type = 'loading'; /** Set post data in case its used */ //$post = get_post( $data['pageID'] ); /** Set query data in case its used, for example in PostLoop or Docker, will be incorrect for archive/category pages ( no ID ) */ $query = empty($data['query']) ? 'post_type=post&post_status=published' : $data['query']; $wp_query = new WP_Query($query); $GLOBALS['post'] = $wp_query->post; /** CSS - style.css */ if (is_file($s->base_dir . '/style.css')) { $response['css_style'] = $s->base_url . '/style.css'; } /** CSS - build.css */ if (is_file($s->base_dir . '/build.css')) { $response['css_build'] = $s->base_url . '/build.css'; } /** * JAVASCRIPT + CUSTOM STYLES * Load scripts using PL enqueue function and pl_live_scripts global */ global $pl_live_scripts; global $pl_live_styles; $pl_live_scripts = array(); $pl_live_styles = array(); $s->section_styles(); $response['scripts'] = $pl_live_scripts; /** * OPTIONS & MODEL - Get the options for the section, json encoded */ global $plfactory; $response['model'] = array_merge($plfactory->recursive_parse_opts($s->section_opts()), pl_defaults_model($s->section_defaults())); /** * TEMPLATE - Get the section template and assign to a variable to be returned in response */ ob_start(); $s->active_loading = true; $s->render($map_meta, $level); $section_template = ob_get_clean(); $response['template'] = $section_template; /** HEAD -- Do section <head> */ ob_start(); $s->section_head(); $head = ob_get_clean(); $response['head'] = $head; /** FOOT -- Do section <foot> */ ob_start(); $s->section_foot(); $foot = ob_get_clean(); $response['foot'] = $foot; } return $response; }