[ Index ]

PHP Cross Reference of PageLines Framework

title

Body

[close]

/includes/ -> class.template.php (source)

   1  <?php
   2  /**
   3   *
   4   *
   5   *  PageLines Template Class
   6   *
   7   *
   8   *  @package PageLines DMS
   9   *  @subpackage Sections
  10   *  @since 4.0
  11   *
  12   */
  13  class PageLinesTemplate {
  14  
  15      var $id;        // Root id for section.
  16      var $name;        // Name for this section.
  17      var $settings;    // Settings for this section
  18  
  19      var $layout;    // Layout type selected
  20      var $sections = array(); // HTML sections/effects for the page
  21  
  22      var $tsections = array();
  23      var $allsections = array();
  24      var $default_allsections = array();
  25      var $non_template_sections = array();
  26      var $tbuffer = array();
  27  
  28  
  29      /**
  30       * PHP5 constructor
  31       * @param   bool $template_type
  32       */
  33  	function __construct( $template_type = false ) {
  34  
  35  
  36  
  37          global $post;
  38          global $pl_section_factory;
  39          global $passive_sections; // passive sections for loading
  40  
  41          $post = (!isset($post) && isset($_GET['post'])) ? get_post($_GET['post'], 'object') : $post;
  42  
  43          $this->factory = $pl_section_factory->sections;
  44  
  45          // All section control settings
  46  
  47          $sc_set = (is_pagelines_special()) ? PAGELINES_SPECIAL : PAGELINES_TEMPLATES;
  48  
  49          $this->scontrol = ploption('section-control', array('setting' => $sc_set));
  50  
  51          $this->sc_default = ploption('section-control', array('setting' => PAGELINES_TEMPLATES));
  52  
  53          $this->map = $this->get_map();
  54  
  55          // Add passive sections
  56          $this->passive_sections = $passive_sections;
  57  
  58          /**
  59           * Template Type
  60           * This is how we decide which sections belong on the page
  61           */
  62          if( $template_type != false )
  63              $this->template_type = $template_type;
  64  
  65          else{
  66              if(is_admin())
  67                  $this->template_type = $this->admin_page_type_breaker();
  68              else
  69                  $this->template_type = $this->page_type_breaker();
  70          }
  71  
  72  
  73          if(!is_admin())
  74              $this->template_name = $this->page_type_name();
  75  
  76  
  77          // DEPRECATE AFTER THIS FOR V2 (for now)
  78          if(pl_deprecate_v2())
  79              return;
  80  
  81  
  82          add_action('admin_head', array(&$this, 'load_section_optionator'));
  83  
  84          add_action('pagelines_before_html', array(&$this, 'run_before_page'));
  85  
  86          add_action('pagelines_head', array(&$this, 'hook_and_print_sections'));
  87  
  88          add_action('wp_footer', array(&$this, 'print_template_section_scripts'));
  89  
  90  
  91          $this->load_sections_on_hook_names();
  92  
  93      }
  94  
  95  
  96      /**
  97      *
  98      * @TODO document
  99      *
 100      */
 101  	function adjust_template_type($type){
 102          $this->template_type = $type;
 103          $this->load_sections_on_hook_names();
 104      }
 105  
 106      /**
 107       * Page Type Breaker
 108       *
 109       * Returns template type based on WordPress conditionals
 110       *
 111       * @return mixed|void
 112       */
 113  	public static function page_type_breaker(){
 114          global $post;
 115          global $pl_integration;
 116          global $post_type_breaker;
 117  
 118          if( isset( $post_type_breaker ) )
 119              return apply_filters( 'pagelines_page_type', $post_type_breaker, $post );
 120  
 121          if(pl_is_integration())
 122              $type = pl_get_integration();
 123          elseif(is_404())
 124              $type = '404_page';
 125          elseif( pl_is_cpt('archive') )
 126              $type = get_post_type_plural();
 127          elseif( pl_is_cpt() )
 128              $type = get_post_type();
 129          elseif(is_tag() && VPRO)
 130              $type = 'tag';
 131          elseif(is_search() && VPRO)
 132              $type = 'search';
 133          elseif(is_category() && VPRO)
 134              $type = 'category';
 135          elseif(is_author() && VPRO)
 136              $type = 'author';
 137          elseif(is_archive() && VPRO)
 138              $type = 'archive';
 139          elseif(is_home() || (!VPRO && is_pagelines_special()))
 140              $type = 'posts';
 141          elseif(is_page_template()){
 142              /** Strip the page. and .php from page.[template-name].php */
 143              $page_filename = str_replace('.php', '', get_post_meta($post->ID,'_wp_page_template',true));
 144              $template_name = str_replace('page.', '', $page_filename);
 145              $type = $template_name;
 146          }elseif( is_single() )
 147              $type = 'single';
 148          else
 149              $type = 'default';
 150  
 151          $post_type_breaker = $type;
 152          return apply_filters('pagelines_page_type', $post_type_breaker, $post);
 153      }
 154  
 155  
 156  
 157      /**
 158       * Page Type Name
 159       *
 160       * @return String
 161       * @todo Finish documentation
 162       */
 163  	function page_type_name(){
 164  
 165          if(isset($this->map['templates']['templates'][$this->template_type]['name']))
 166              return $this->map['templates']['templates'][$this->template_type]['name'];
 167          else
 168              return ui_key( $this->template_type );
 169      }
 170  
 171      /**
 172       * Returns template type based on elements in WP admin
 173       */
 174  	public static function admin_page_type_breaker(){
 175          global $post;
 176  
 177  
 178          if ( !is_object( $post ) )
 179              return 'default';
 180  
 181          if( isset($post) && $post->post_type == 'post' )
 182              return 'single';
 183          elseif( isset($_GET['page']) && $_GET['page'] == 'pagelines' )
 184              return 'posts';
 185          elseif( isset($post) && !empty($post->page_template) && $post->post_type == 'page' ) {
 186              $page_filename = str_replace('.php', '', $post->page_template);
 187              $template_name = str_replace('page.', '', $page_filename);
 188              return $template_name;
 189          } elseif( isset($post) && get_post_meta($post->ID,'_wp_page_template',true) ){
 190              $page_filename = str_replace('.php', '', get_post_meta($post->ID,'_wp_page_template',true));
 191              $template_name = str_replace('page.', '', $page_filename);
 192              return $template_name;
 193          } elseif( isset($post) && isset($post->post_type) )
 194              return $post->post_type;
 195          else
 196              return 'default';
 197  
 198      }
 199  
 200  
 201      /**
 202       * Get current post type, set as GET on 'add new' pages
 203       */
 204  	public static function current_admin_post_type(){
 205          global $pagenow;
 206          global $post;
 207  
 208          $current_post_type = ( !isset($post) && isset($_GET['post_type']) )
 209                              ? $_GET['post_type']
 210                              : ( isset($post) && isset($post->post_type) ? $post->post_type :
 211                                  ($pagenow == 'post-new.php' ? 'post' : null));
 212  
 213          return $current_post_type;
 214  
 215      }
 216  
 217  
 218  
 219  
 220      /**
 221       *
 222       * Load sections on to class attributes the correspond w/ hook args
 223       *
 224       * TODO Account for different types of loads. e.g sidebar2 should only load if it is shown in the layout
 225       *
 226       */
 227  	function load_sections_on_hook_names(){
 228  
 229          foreach( $this->map as $hook => $h ){
 230  
 231              $tsections = $this->sections_at_hook( $hook, $h );
 232  
 233              // Set All Sections As Defined By the Map
 234              // This is before removal by section control
 235              if( is_array($tsections) )
 236                  $this->default_allsections = array_merge($this->default_allsections, $tsections);
 237  
 238              // Remove sections deactivated by Section Control
 239              if(!is_admin())
 240                  $tsections = $this->unset_hidden_sections($tsections, $hook);
 241  
 242              // Set Property after Template Hook Args
 243              $this->$hook = $tsections;
 244  
 245              // Create an array with all sections used on current page -
 246              if(is_array($this->$hook))
 247                  $this->allsections = array_merge($this->allsections, $this->$hook);
 248  
 249              if( is_array($this->$hook) && ($hook == 'header' || $hook == 'footer' || $hook == 'morefoot') )
 250                  $this->non_template_sections = array_merge($this->non_template_sections, $this->$hook);
 251  
 252  
 253          }
 254  
 255          // add passive sections (not in drag drop but added through options/hooks)
 256          if(is_array($this->passive_sections) && !empty($this->passive_sections))
 257              $this->allsections = array_merge($this->allsections, $this->passive_sections);
 258  
 259      }
 260  
 261  
 262      /**
 263       * Sections At Hook
 264       *
 265       * For a given hook, see which sections are placed there and return them
 266       *
 267       * @since   ...
 268       *
 269       * @param   $hook
 270       * @param   $h
 271       *
 272       * @return  array|mixed|void
 273       */
 274  	function sections_at_hook( $hook, $h ){
 275  
 276          /* Load in sections at hook in map, for this template type, allow for overriding */
 277          if( $hook == 'main' || $hook == 'templates' ){
 278  
 279              $sections = $this->section_cascade( $hook, $h );
 280  
 281              return apply_filters( 'pl_template_sections', $sections, $this->template_type, $hook );
 282  
 283          }
 284  
 285          elseif(isset($h['sections']))
 286              return $h['sections']; // Get Sections assigned in map
 287  
 288          else
 289              return array();
 290  
 291      }
 292  
 293      /**
 294       * Run down the map, if not at hook in map, then load default
 295       *     if default doesn't load, load a blank array
 296       */
 297  	function section_cascade( $hook, $h ){
 298  
 299          if( isset($h['templates'][$this->template_type]['sections']) )
 300              return $h['templates'][$this->template_type]['sections'];
 301  
 302          elseif( isset($h['templates']['default']['sections']) )
 303              return $h['templates']['default']['sections'];
 304  
 305          else
 306              return array();
 307  
 308      }
 309  
 310      /**
 311       * Unset sections based on section
 312       */
 313  	function unset_hidden_sections($ta_sections, $hook_id){
 314  
 315          global $post;
 316  
 317          if(is_array($ta_sections)){
 318              foreach($ta_sections as $key => $sid){
 319  
 320                  $template_slug = $this->get_template_slug( $hook_id );
 321  
 322                  $sc = $this->sc_settings( $this->scontrol, $template_slug, $sid );
 323                  $dsc = $this->sc_settings( $this->sc_default, $template_slug, $sid );
 324  
 325                  if($this->unset_section($sid, $template_slug, $sc, $dsc))
 326                      unset($ta_sections[$key]);
 327  
 328  
 329                  // do not show section if post/page is passworded.
 330                  if( post_password_required() ) {
 331                      if( 'main' === $hook_id && 'PageLinesPostLoop' !== $sid )
 332                          unset( $ta_sections[$key]);
 333                  }
 334              }
 335          }
 336  
 337          return $ta_sections;
 338  
 339      }
 340  
 341      /**
 342       * Get Section Control Settings for Section
 343       */
 344  	function sc_settings( $set, $tid, $sid ){
 345  
 346          return (isset($set[$tid][$sid])) ? $set[$tid][$sid] : null;
 347  
 348      }
 349  
 350  
 351      /**
 352      *
 353      * @TODO document
 354      *
 355      */
 356  	function get_template_slug( $hook_id ){
 357  
 358          // Get template slug
 359          if($hook_id == 'templates')
 360              $template_slug = $hook_id.'-'.$this->template_type;
 361          elseif ($hook_id == 'main')
 362              $template_slug = $hook_id.'-'.$this->template_type;
 363          else
 364              $template_slug = $hook_id;
 365  
 366          return $template_slug;
 367      }
 368  
 369      /**
 370       * Unset section based on Section Control
 371       */
 372  	function unset_section( $sid, $template_slug, $sc, $dsc){
 373          global $post;
 374  
 375          $post_id = ( isset($post) ) ? $post->ID : null;
 376  
 377          $oset = array('post_id' => $post_id);
 378  
 379          // Global Section Control Array
 380              $general_hide = (isset($dsc['hide'])) ? true : false;
 381  
 382          // Meta Controls
 383          if(is_pagelines_special()){
 384              $special_type = $this->template_type;
 385  
 386              $meta_reverse = ( isset($sc[$special_type]['show']) && $sc[$special_type]['show'] ) ? true : false;
 387              $meta_hide = ( isset($sc[$special_type]['hide']) && $sc[$special_type]['hide'] ) ? true : false;
 388          } else {
 389  
 390              $meta_reverse = ( plmeta( meta_option_name( array('show', $template_slug, $sid) ) , $oset ) ) ? true : false;
 391              $meta_hide = ( plmeta( meta_option_name( array('hide', $template_slug, $sid) ), $oset ) ) ? true : false;
 392          }
 393  
 394          return ( ($general_hide && !$meta_reverse) || (!$general_hide && $meta_hide) ) ? true : false;
 395  
 396  
 397      }
 398  
 399  
 400      /**
 401       * Hook up sections to hooks throughout the theme
 402       * Specifically, the hooks should link w/ template map slugs
 403       */
 404  	function hook_and_print_sections(){
 405  
 406          foreach( $this->map as $hook_id => $h ){
 407  
 408              if( isset($h['hook']) )
 409                  add_action( $h['hook'], array(&$this, 'print_section_html') );
 410  
 411          }
 412  
 413      }
 414  
 415      /**
 416       * Print section HTML from hooks.
 417       */
 418  	function print_section_html( $hook ){
 419  
 420          global $plbuffer;
 421          /**
 422           * Sections assigned to array already in get_loaded_sections
 423           */
 424          if( is_array( $this->$hook ) ){
 425  
 426              $markup_type = $this->map[$hook]['markup'];
 427  
 428              /**
 429               * Parse through sections assigned to this hook
 430               */
 431              foreach( $this->$hook as $key => $sid ){
 432  
 433                  /**
 434                   * This goes through and buffers sections so we can add classes to sections that 'tell the future'
 435                   * proved to be extremely hard to implement, and harder to work w/ all wp plugins (get_sidebars conflict)
 436                   * Leaving here for now, enabled by action.
 437                    * Original idea was for themers to use classes based on adjacent sections to style, instead, recommend using section hooks + options
 438                   *
 439                   */
 440                  if( has_action('buffer_sections') ){
 441  
 442                      /**
 443                       * Check for buffered version, use if that exists; then unset.
 444                       */
 445                      if(isset($plbuffer[$sid])){
 446                          $render = $plbuffer[$sid];
 447                          unset($plbuffer[$sid]);
 448                      }else
 449                          $render = $this->buffer_template($sid);
 450  
 451                      // RENDER //
 452                      if($render){
 453  
 454                          //$this->render_template($render, $sid, $markup_type);
 455  
 456                          // PREVIOUS //
 457                          $last_sid = $this->get_last_rendered($hook);
 458  
 459                           // NEXT //
 460                          $next_sid = $this->buffer_next_section($hook, $key, $sid);
 461  
 462                          // DRAW APPROPRIATE SECTION //
 463                          $this->render_template($render, $sid, $markup_type, $this->conc($sid, $next_sid), $this->conc($sid, $last_sid, 'previous'));
 464  
 465                          // SET AS LAST RENDERED //
 466                          $this->last_rendered = array('sid' => $sid, 'hook' => $hook);
 467  
 468                      }
 469  
 470  
 471                  } else {
 472  
 473                      $render = $this->buffer_template( $sid );
 474  
 475                      if($render)
 476                          $this->render_template($render, $sid, $markup_type);
 477  
 478                  }
 479  
 480              }
 481  
 482  
 483          }
 484      }
 485  
 486      /**
 487       * Renders the HTML template and adds surrounding 'standardized' markup and hooks
 488       */
 489  	function render_template($template, $sid, $markup, $next = '', $prev = ''){
 490  
 491          $classes = $prev.' '.$next;
 492  
 493          $p = splice_section_slug($sid);
 494          $section = $p['section'];
 495          $clone_id = $p['clone_id'];
 496  
 497          $s = $this->factory[ $section ];
 498  
 499          echo pl_source_comment($s->name . ' | Section Template', 2);
 500  
 501          $s->before_section_template( $clone_id );
 502  
 503          $s->before_section( $markup, $clone_id, $classes);
 504  
 505          echo $template;
 506  
 507          $s->after_section( $markup );
 508  
 509          $s->after_section_template( $clone_id );
 510  
 511      }
 512  
 513      /**
 514       * Runs template in an output buffer and returns the output
 515       */
 516  	function buffer_template( $sid ){
 517          global $post;
 518          global $wp_query;
 519          $save_query = $wp_query;
 520          $save_post = $post;
 521  
 522          /**
 523           * If this is a cloned element, remove the clone flag before instantiation here.
 524           */
 525          $p = splice_section_slug($sid);
 526          $section = $p['section'];
 527          $clone_id = $p['clone_id'];
 528  
 529          if( $this->in_factory( $section ) ){
 530  
 531              $s = $this->factory[ $section ];
 532  
 533              $s->setup_oset( $clone_id );
 534  
 535              /**
 536               * Load Template
 537               * Get Template in Buffer
 538               *****************************/
 539  
 540                  ob_start();
 541  
 542                      // If in child theme get that, if not load the class template function
 543                      $s->section_template_load( $clone_id );
 544  
 545                  $template_output =  ob_get_clean();
 546  
 547              /** END BUFFER *****************************/
 548          }
 549  
 550          // RESET //
 551              $wp_query = $save_query;
 552              $post = $save_post;
 553  
 554          return (isset($template_output) && $template_output != '') ? $template_output : false;
 555  
 556      }
 557  
 558  	function get_last_rendered($hook){
 559  
 560          $order = array('header', 'templates', 'morefoot', 'footer');
 561  
 562          $k = array_search($hook, $order);
 563  
 564  
 565          if($k && isset($this->last_rendered)){
 566              return $this->last_rendered['sid'];
 567          } elseif(isset($this->last_rendered) && ($hook == $this->last_rendered['hook'])){
 568              return $this->last_rendered['sid'];
 569          } else {
 570              return 'top';
 571          }
 572  
 573      }
 574      /**
 575       * Concatenation used in classes
 576       */
 577  	function conc($sid, $adjacent_sid, $mode = 'next'){
 578  
 579          if($mode == 'previous'){
 580  
 581              $adjacent_slug = ($adjacent_sid == 'top') ? 'top' : $this->get_section_slug($adjacent_sid);
 582  
 583              $conc = sprintf('%s-%s', $adjacent_slug, $this->get_section_slug($sid));
 584  
 585          }else{
 586              $adjacent_slug = ($adjacent_sid == 'bottom') ? 'bottom' : $this->get_section_slug($adjacent_sid);
 587  
 588              $conc = sprintf('%s-%s', $this->get_section_slug($sid), $adjacent_slug);
 589          }
 590  
 591          return $conc;
 592  
 593      }
 594  
 595      /**
 596       * Get the section slug from the unique section ID
 597       */
 598  	function get_section_slug($sid){
 599          $p = splice_section_slug($sid);
 600          $section = $p['section'];
 601          $clone_id = $p['clone_id'];
 602  
 603          if(isset($this->factory[ $section ]))
 604              return $this->factory[ $section ]->id;
 605          else
 606              return false;
 607      }
 608  
 609      /**
 610       * Recursive function for buffering following sections.
 611       * Needed for use in concatenating sections so themers can
 612       * design based on user configuration of sections
 613       */
 614  	function buffer_next_section($hook, $key, $sid = ''){
 615  
 616          global $plbuffer;
 617  
 618          $next = $this->next_section($hook, $key);
 619  
 620          if($next['sid'] == 'end')
 621              return 'bottom';
 622          else
 623              $plbuffer[$next['sid']] = $this->buffer_template($next['sid']);
 624  
 625          if(!$plbuffer[$next['sid']]){
 626  
 627              // Recursion
 628              return $this->buffer_next_section($next['hook'], $next['key'], $next['sid']);
 629  
 630          }else
 631              return $next['sid'];
 632  
 633      }
 634  
 635      /**
 636       * Finds the next section that is output by the framework
 637       */
 638  	function next_section($hook, $key){
 639  
 640          if(property_exists($this, $hook)){
 641              $in_area = $this->$hook;
 642  
 643          }
 644  
 645          if(isset($in_area[$key+1])){
 646              $data = array(
 647                  'sid'     => $in_area[$key+1],
 648                  'hook'    => $hook,
 649                  'key'    => $key+1
 650              );
 651          } else {
 652  
 653              $data = $this->area_next_section($hook);
 654          }
 655  
 656  
 657          return $data;
 658  
 659      }
 660  
 661      /**
 662       * Used if section is at the end of the template area
 663       */
 664  	function area_next_section($hook){
 665  
 666              $order = array(
 667                      'header',
 668                      'templates',
 669                      'morefoot',
 670                      'footer'
 671                  );
 672  
 673              // Current Area
 674              $k = array_search($hook, $order);
 675  
 676              if(!isset($k) || $k === false){
 677  
 678                      // probl
 679                  return array('sid'=>'end', 'hook' => false, 'key' => false);
 680              }
 681              $i = 1;
 682              foreach($order as $a) {
 683  
 684                  $area = (isset($order[ $k+$i ])) ? $order[ $k+$i ] : false;
 685  
 686                  if( $area && is_array($this->$area) && !empty($this->$area) ){
 687  
 688                      $karr = $this->$area;
 689  
 690                      $data = array(
 691                          'sid'     => $karr[0],
 692                          'hook'    => $area,
 693                          'key'    => 0
 694                      );
 695  
 696                      return $data;
 697  
 698                  }
 699  
 700                  $i++;
 701              }
 702  
 703              return array('sid'=>'end', 'hook' => false, 'key' => false);
 704  
 705  
 706      }
 707  
 708  
 709      /**
 710       * Tests if the section is in the factory singleton
 711       * @since 1.0.0
 712       */
 713  	function in_factory( $section ){
 714          return ( isset($this->factory[ $section ]) && is_object($this->factory[ $section ]) ) ? true : false;
 715      }
 716  
 717      /**
 718       * Gets template map, sets option if not present
 719       * @since 1.0.0
 720       */
 721  	function get_map(){
 722  
 723          // Get Section / Layout Map
 724          if(get_option( PAGELINES_TEMPLATE_MAP ) && is_array(get_option( PAGELINES_TEMPLATE_MAP ))){
 725              $map = get_option( PAGELINES_TEMPLATE_MAP );
 726              return $this->update_template_config($map);
 727  
 728          }else{
 729  
 730              $config = $this->update_template_config( the_template_map() );
 731              update_option( PAGELINES_TEMPLATE_MAP, $config );
 732              return $config;
 733          }
 734      }
 735  
 736      /**
 737       * When the default map is updated, we need to pull in the additional w/o the option val
 738       * This will also be used for post types, that are added to add them to the map
 739       *
 740       * @since 1.0.0
 741       *
 742       */
 743  	function update_template_config( $map ){
 744  
 745          $map_setup = the_template_map();
 746  
 747          // Use the map config array, and parse against the option value
 748          foreach( $map_setup as $hook_id => $hook_info ){
 749  
 750              if( !isset( $map[$hook_id] ) || !is_array( $map[$hook_id] ) )
 751                  $map[$hook_id] = $hook_info;
 752  
 753              // Use the names from the config instead
 754              $map[$hook_id]['name'] = $hook_info['name'];
 755              $map[$hook_id]['hook'] = $hook_info['hook'];
 756              $map[$hook_id]['markup'] = $hook_info['markup'];
 757  
 758              // Go through the sub-templates as well
 759              if(isset($hook_info['templates'])){
 760  
 761                  foreach($hook_info['templates'] as $sub_template => $stemplate){
 762  
 763                      if( !isset( $map[$hook_id]['templates'][$sub_template] ) )
 764                          $map[$hook_id]['templates'][$sub_template] = $stemplate;
 765  
 766                      $map[$hook_id]['templates'][$sub_template]['name'] = $stemplate['name'];
 767  
 768                      if(isset($stemplate['page_type']))
 769                          $map[$hook_id]['templates'][$sub_template]['page_type'] = $stemplate['page_type'];
 770  
 771                      $map[$hook_id]['templates'][$sub_template]['version'] = ( isset($stemplate['version']) && $stemplate['version'] != '' ) ? $stemplate['version'] : null;
 772  
 773                  }
 774  
 775              }
 776          }
 777  
 778          foreach( $map['templates']['templates'] as $hook => $h ){
 779  
 780              if(!isset($map_setup['templates']['templates'][$hook]))
 781                  unset($map['templates']['templates'][$hook]);
 782  
 783              if(!isset($map_setup['main']['templates'][$hook]))
 784                  unset($map['main']['templates'][$hook]);
 785  
 786          }
 787  
 788  
 789          return $map;
 790  
 791      }
 792  
 793      /**
 794       * Callback for resetting the options to default
 795       */
 796  	function reset_templates_to_default(){
 797  
 798          update_option(PAGELINES_TEMPLATES, array());
 799          update_option(PAGELINES_TEMPLATE_MAP, the_template_map());
 800  
 801      }
 802  
 803  
 804      /**
 805      *
 806      * @TODO document
 807      *
 808      */
 809  	function run_before_page(){
 810  
 811      }
 812  
 813  	function print_on_ready_scripts() {
 814  
 815          foreach( (array) $this->allsections as $sid){
 816  
 817              /**
 818               * If this is a cloned element, remove the clone flag before instantiation here.
 819               */
 820              $p = splice_section_slug($sid);
 821              $section = $p['section'];
 822              $clone_id = $p['clone_id'];
 823  
 824              if( $this->in_factory( $section ) ){
 825  
 826                  $s = $this->factory[$section];
 827                  $s->setup_oset( $clone_id );
 828  
 829                  ob_start();
 830  
 831                      $s->section_on_ready( $clone_id );
 832  
 833                  $scripts = ob_get_clean();
 834  
 835                  if($scripts != ''){
 836                      echo sprintf("\n/* %s Script */\n", $this->factory[$section]->name);
 837                      echo $scripts;
 838                  }
 839  
 840              }
 841          }
 842      }
 843  
 844  	function print_template_section_head() {
 845  
 846          foreach( (array) $this->allsections as $sid){
 847  
 848              /**
 849               * If this is a cloned element, remove the clone flag before instantiation here.
 850               */
 851              $p = splice_section_slug($sid);
 852              $section = $p['section'];
 853              $clone_id = $p['clone_id'];
 854  
 855              if( $this->in_factory( $section ) ){
 856  
 857                  $s = $this->factory[$section];
 858                  $s->setup_oset( $clone_id );
 859  
 860                  ob_start();
 861  
 862                      $s->section_head( $clone_id );
 863  
 864                  $section_head = ob_get_clean();
 865  
 866                  if($section_head != ''){
 867                      echo pl_source_comment($this->factory[$section]->name.' | Section Head');
 868                      echo $section_head;
 869                  }
 870  
 871              }
 872          }
 873      }
 874  
 875      /**
 876       * Runs the options w/ cloning
 877       *
 878       * @package PageLines DMS
 879       * @subpackage Sections
 880       * @since 2.0.b3
 881       */
 882  	function load_section_optionator( $mode = 'meta', $type = '' ){
 883  
 884          // Which sections to load and parse
 885          if($mode == 'integration')
 886              $parsed_sections = $this->non_template_sections;
 887          elseif($mode == 'default')
 888              $parsed_sections = $this->factory;
 889          else
 890              $parsed_sections = $this->default_allsections;
 891  
 892          // Parse active sections and load tab
 893          foreach( $parsed_sections as $key => $sid ){
 894  
 895              if($mode == 'default'){
 896  
 897                  $section = $key;
 898                  $clone_id = 1;
 899  
 900              } else {
 901  
 902                  $p = splice_section_slug($sid);
 903                  $section = $p['section'];
 904                  $clone_id = $p['clone_id'];
 905  
 906              }
 907  
 908              if(isset($this->factory[$section])){
 909  
 910                  $s = $this->factory[$section];
 911  
 912                  $s->setup_oset( $clone_id );
 913  
 914                  $s->section_optionator( array( 'clone_id' => $clone_id, 'type' => $type ) );
 915  
 916              }
 917  
 918          }
 919  
 920          // Load inactive sections last for meta stuff
 921          if($mode == 'meta' || $mode == ''){
 922  
 923              // Get inactive
 924              foreach( $this->factory as $key => $section ){
 925  
 926                  $inactive = ( !in_array( $key, $this->default_allsections) ) ? true : false;
 927  
 928                  if($inactive)
 929                      $section->section_optionator( array('clone_id' => 0, 'active' => false, 'type' => $type) );
 930              }
 931  
 932          }
 933  
 934  
 935  
 936      }
 937  
 938  
 939      /**
 940       * Print Section Styles (Hooked to wp_print_styles)
 941       *
 942       */
 943  	function print_template_section_styles(){
 944  
 945  
 946  
 947          if(is_array($this->allsections) && !has_action('override_pagelines_css_output') ){
 948              foreach($this->allsections as $section_slug){
 949  
 950                  $p = splice_section_slug( $section_slug );
 951  
 952                  if($this->in_factory( $p['section'] )) {
 953  
 954                      $s = $this->factory[$p['section']];
 955  
 956                      $s->section_styles();
 957                      // Auto load style.css for simplicity if its there.
 958                      if( is_file( $s->base_dir . '/style.css' ) ){
 959  
 960                          wp_register_style( $s->id, $s->base_url . '/style.css', array(), $s->settings['p_ver'], 'screen');
 961                           wp_enqueue_style( $s->id );
 962  
 963                      }
 964  
 965  
 966  
 967                  }
 968              }
 969  
 970  
 971          }
 972  
 973      }
 974  
 975  
 976  
 977      /**
 978      *
 979      * @TODO document
 980      *
 981      */
 982  	function print_template_section_scripts(){
 983  
 984  
 985          foreach($this->allsections as $section){
 986  
 987              $p = splice_section_slug( $section );
 988  
 989              if($this->in_factory( $p['section'] )){
 990  
 991                  $section_scripts = $this->factory[$p['section']]->section_scripts();
 992  
 993  
 994                  if(is_array( $section_scripts )){
 995  
 996                      foreach( $section_scripts as $js_id => $js_atts){
 997  
 998                          $defaults = array(
 999                                  'version' => '1.0',
1000                                  'dependancy' => null,
1001                                  'footer' => true
1002                              );
1003  
1004                          $parsed_js_atts = wp_parse_args($js_atts, $defaults);
1005  
1006                          wp_register_script($js_id, $parsed_js_atts['file'], $parsed_js_atts['dependancy'], $parsed_js_atts['version'], true);
1007  
1008                          wp_print_scripts($js_id);
1009  
1010                      }
1011  
1012                  }
1013              }
1014  
1015          }
1016      }
1017  } /* ------ END CLASS ------ */
1018  
1019  
1020  /**
1021   * PageLines Template Object
1022   * @global object $pagelines_template
1023   * @since 1.0.0
1024   */
1025  function build_pagelines_template(){
1026      $GLOBALS['pagelines_template'] = new PageLinesTemplate;
1027  }
1028  
1029  /**
1030   * Save Site Template Map
1031   *
1032   * @since 1.0.0
1033   */
1034  function save_template_map($templatemap){
1035      update_option( PAGELINES_TEMPLATE_MAP, $templatemap);
1036  }
1037  
1038  
1039  /**
1040   *  Used to parse section HTML for hooks
1041   *
1042   * @since 4.0.0
1043   */
1044  function pagelines_ob_section_template($section){
1045  
1046      /*
1047          Start Output Buffering
1048      */
1049      ob_start();
1050  
1051      /*
1052          Run The Section Template
1053      */
1054      $section->section_template( true );
1055  
1056      /*
1057          Clean Up Buffered Output
1058      */
1059      ob_end_clean();
1060  
1061  
1062  }
1063  
1064  /**
1065  *
1066  * @TODO do
1067  *
1068  */
1069  function reset_templates_to_default(){
1070      PageLinesTemplate::reset_templates_to_default();
1071  }
1072  
1073  
1074  /**
1075   * Workaround PageLines Template Styles
1076   *
1077   * Workaround for warning on WordPress login page when pagelines_template variable doesn't exist
1078   * due to there being no "pagelines_before_html" hook present. Not ideal; but best solution for now.
1079   *
1080   * @since 1.0.0
1081   */
1082  function workaround_pagelines_template_styles(){
1083      global $pagelines_template;
1084      if(is_object($pagelines_template)){
1085          $pagelines_template->print_template_section_styles();
1086      }
1087      else return;
1088  }
1089  
1090  /*
1091      TEMPLATE MAP
1092  
1093      This array controls the default template map of section in the theme
1094      Each top level needs a hook; and the top-level template needs to be included
1095      as an arg in said hook...
1096  */
1097  function the_template_map() {
1098  
1099      $template_map = array();
1100  
1101      $page_templates = the_sub_templates('templates');
1102      $content_templates = the_sub_templates('main');
1103  
1104      $template_map['header'] = array(
1105          'hook'             => 'pagelines_header',
1106          'name'            => __( 'Site Header', 'pagelines' ),
1107          'markup'        => 'content',
1108          'sections'         => array( 'PageLinesBranding','PLNavBar','PageLinesSecondNav' )
1109      );
1110  
1111      $template_map['footer'] = array(
1112          'hook'             => 'pagelines_footer',
1113          'name'            => __( 'Site Footer', 'pagelines' ),
1114          'markup'        => 'content',
1115          'sections'         => array('SimpleNav')
1116      );
1117  
1118      $template_map['templates'] = array(
1119          'hook'            => 'pagelines_template',
1120          'name'            => __( 'Page Templates', 'pagelines' ),
1121          'markup'        => 'content',
1122          'templates'        => $page_templates,
1123      );
1124  
1125      $template_map['main'] = array(
1126          'hook'            => 'pagelines_main',
1127          'name'            => __( 'Text Content Area', 'pagelines' ),
1128          'markup'        => 'copy',
1129          'templates'        => $content_templates,
1130      );
1131  
1132      $template_map['morefoot'] = array(
1133          'name'            => __( 'Morefoot Area', 'pagelines' ),
1134          'hook'             => 'pagelines_morefoot',
1135          'markup'        => 'content',
1136          'version'        => 'pro',
1137          'sections'         => array()
1138      );
1139  
1140      $template_map['sidebar1'] = array(
1141          'name'            => __( 'Sidebar 1', 'pagelines' ),
1142          'hook'             => 'pagelines_sidebar1',
1143          'markup'        => 'copy',
1144          'sections'         => array('PrimarySidebar')
1145      );
1146  
1147      $template_map['sidebar2'] = array(
1148          'name'            => __( 'Sidebar 2', 'pagelines' ),
1149          'hook'             => 'pagelines_sidebar2',
1150          'markup'        => 'copy',
1151          'sections'         => array('SecondarySidebar')
1152      );
1153  
1154      $template_map['sidebar_wrap'] = array(
1155          'name'            => __( 'Sidebar Wrap', 'pagelines' ),
1156          'hook'             => 'pagelines_sidebar_wrap',
1157          'markup'        => 'copy',
1158          'version'        => 'pro',
1159          'sections'         => array()
1160      );
1161  
1162      return apply_filters( PAGELINES_TEMPLATE_MAP, $template_map);
1163  }
1164  
1165  
1166  /**
1167  *
1168  * @TODO do
1169  *
1170  */
1171  function the_sub_templates( $t = 'templates' ){
1172  
1173      $map = array(
1174          'default' => array(
1175                  'name'            => __( 'Default', 'pagelines' ),
1176                  'sections'         => ($t == 'main') ? array('PageLinesPostLoop', 'PageLinesComments') : array('PageLinesContent'),
1177                  'page_type'        => 'page'
1178          ),
1179          'alpha' => array(
1180                  'name'            => __( '1', 'pagelines' ),
1181                  'sections'         => ($t == 'main') ? array( 'PageLinesPostLoop' ) : array('PageLinesFeatures', 'PageLinesBoxes', 'PageLinesContent'),
1182                  'page_type'        => 'page'
1183              ),
1184          'beta' =>     array(
1185                  'name'            => __( '2', 'pagelines' ),
1186                  'sections'         => ($t == 'main') ? array( 'PageLinesPostLoop' ) : array('PageLinesCarousel', 'PageLinesContent'),
1187                  'page_type'        => 'page'
1188              ),
1189          'gamma' =>     array(
1190                  'name'            => __( '3', 'pagelines' ),
1191                  'sections'         => ($t == 'main') ? array( 'PageLinesPostLoop' ) : array( 'PageLinesHighlight', 'PageLinesSoapbox', 'PageLinesBoxes' ),
1192                  'page_type'        => 'page'
1193              ),
1194          'delta' =>     array(
1195                  'name'            => __( '4', 'pagelines' ),
1196                  'sections'         => ($t == 'main') ? array( 'PageLinesPostLoop' ) : array( 'PageLinesHighlight', 'PageLinesContent' ),
1197                  'page_type'        => 'page'
1198              ),
1199          'epsilon' =>     array(
1200                  'name'            => __( '5', 'pagelines' ),
1201                  'sections'         => ($t == 'main') ? array( 'PageLinesPostLoop' ) : array( 'PageLinesHighlight', 'PageLinesBanners', 'PageLinesContent' ),
1202                  'page_type'        => 'page'
1203              ),
1204          'single' => array(
1205                  'name'            => __( 'Blog Post', 'pagelines' ),
1206                  'sections'         => ($t == 'main') ? array('PageLinesPostNav', 'PageLinesPostLoop', 'PageLinesShareBar', 'PageLinesComments', 'PageLinesPagination') : array('PageLinesContent'),
1207                  'page_type'        => 'post'
1208              ),
1209          'posts' => array(
1210                  'name'            => __( 'Blog', 'pagelines' ),
1211                  'sections'         => ($t == 'main') ? array('PageLinesQuickSlider', 'PageLinesPostsInfo','PageLinesPostLoop', 'PageLinesPagination') : array('PageLinesContent'),
1212                  'page_type'        => 'special'
1213              ),
1214          'tag' => array(
1215                  'name'            => __( 'Tag', 'pagelines' ),
1216                  'sections'         => ($t == 'main') ? array( 'PageLinesPostsInfo', 'PageLinesPostLoop', 'PageLinesPagination' ) : array('PageLinesContent'),
1217                  'version'        => 'pro',
1218                  'page_type'        => 'special'
1219              ),
1220          'archive' =>     array(
1221                  'name'            => __( 'Archive', 'pagelines' ),
1222                  'sections'         => ($t == 'main') ? array( 'PageLinesPostsInfo', 'PageLinesPostLoop', 'PageLinesPagination' ) : array('PageLinesContent'),
1223                  'version'        => 'pro',
1224                  'page_type'        => 'special'
1225              ),
1226          'category' =>     array(
1227                  'name'            => __( 'Category', 'pagelines' ),
1228                  'sections'         => ($t == 'main') ? array( 'PageLinesPostsInfo', 'PageLinesPostLoop', 'PageLinesPagination' ) : array('PageLinesContent'),
1229                  'version'        => 'pro',
1230                  'page_type'        => 'special'
1231              ),
1232          'search' =>     array(
1233                  'name'            => __( 'Search', 'pagelines' ),
1234                  'sections'         => ($t == 'main') ? array( 'PageLinesPostsInfo', 'PageLinesPostLoop', 'PageLinesPagination' ) : array('PageLinesContent'),
1235                  'version'        => 'pro',
1236                  'page_type'        => 'special'
1237              ),
1238          'author' =>     array(
1239                  'name'            => __( 'Author', 'pagelines' ),
1240                  'sections'         => ($t == 'main') ? array( 'PageLinesPostsInfo', 'PageLinesPostLoop', 'PageLinesPagination' ) : array('PageLinesContent'),
1241                  'version'        => 'pro',
1242                  'page_type'        => 'special'
1243              ),
1244          '404_page' =>     array(
1245                  'name'            => __( '404 Error', 'pagelines' ),
1246                  'sections'         => ($t == 'main') ? array( ) : array('PageLinesNoPosts'),
1247                  'version'        => 'pro',
1248                  'page_type'        => 'special'
1249              ),
1250  
1251  
1252      );
1253  
1254      $pt = custom_post_type_handler( $t );
1255  
1256  
1257      $map = array_merge($map, $pt);
1258  
1259      return apply_filters('the_sub_templates', $map, $t);
1260  
1261  }
1262  
1263  /**
1264   * Builds a sections for use outside of drag drop setup
1265   */
1266  function build_passive_section( $args = array() ){
1267  
1268      global $passive_sections;
1269  
1270      if(!isset($passive_sections))
1271          $passive_sections = array();
1272  
1273      $defaults = array(
1274          'sid'    => ''
1275      );
1276  
1277      $s = wp_parse_args($args, $defaults);
1278  
1279      $new = array($s['sid']);
1280  
1281      $passive_sections = array_merge($new, $passive_sections);
1282  
1283  }
1284  
1285  /**
1286   * Handles custom post types, and adds panel if applicable
1287   */
1288  function custom_post_type_handler( $area = 'main' ){
1289      global $post;
1290  
1291      // Get all 'public' post types
1292      $pts = get_post_types( array( 'publicly_queryable' => true ) );
1293  
1294  
1295      if(isset($pts['page']))
1296          unset($pts['page']);
1297  
1298      if(isset($pts['post']))
1299          unset($pts['post']);
1300  
1301      if(isset($pts['attachment']))
1302          unset($pts['attachment']);
1303  
1304  
1305      $post_type_array = array();
1306  
1307      foreach( $pts as $public_post_type ){
1308  
1309          $dragdrop = apply_filters('pl_cpt_dragdrop', true, $public_post_type, $area);
1310  
1311          if( $dragdrop ){
1312  
1313              $post_type_data = get_post_type_object( $public_post_type );
1314  
1315              $sections = ( $area == 'templates' ) ? 'PageLinesContent' : 'PageLinesPostLoop';
1316  
1317              $sections_array = apply_filters( 'pl_default_sections', array( $sections ), $area, $public_post_type );
1318  
1319              $cpt_plural = strtolower(get_post_type_plural( $public_post_type ));
1320  
1321              $post_type_array[ $cpt_plural ] = array(
1322                  'name'        => ui_key($cpt_plural),
1323                  'sections'    => $sections_array
1324              );
1325  
1326              $cpt_single = strtolower($public_post_type);
1327              $post_type_array[ $cpt_single ] = array(
1328                  'name'        => ui_key($cpt_single),
1329                  'sections'    => $sections_array
1330              );
1331          }
1332      }
1333      return $post_type_array;
1334  }


Generated: Fri Aug 30 18:26:24 2013 Cross-referenced by PHPXref 0.7.1