[ Index ]

PHP Cross Reference of PageLines Framework

title

Body

[close]

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

   1  <?php
   2  /**
   3   *
   4   *
   5   *  PageLines Custom Post Type Class
   6   *
   7   *
   8   *  @package PageLines DMS
   9   *  @subpackage Post Types
  10   *  @since 4.0
  11   *
  12   */
  13  class PageLinesPostType {
  14  
  15      var $id;        // Root id for section.
  16      var $settings;    // Settings for this section
  17  
  18  
  19      /**
  20       * PHP5 constructor
  21       *
  22       */
  23  	function __construct($id, $settings, $taxonomies = array(), $columns = array(), $column_display_function = '') {
  24  
  25          $this->id = $id;
  26          $this->taxonomies = $taxonomies;
  27          $this->columns = $columns;
  28          $this->columns_display_function = $column_display_function;
  29  
  30          $defaults = array(
  31                  'label'             => 'Posts',
  32                  'singular_label'     => 'Post',
  33                  'description'         => null,
  34                  'public'             => false,
  35                  'show_ui'             => true,
  36                  'capability_type'    => 'post',
  37                  'hierarchical'         => false,
  38                  'rewrite'             => false,
  39                  'supports'             => array( 'title', 'editor', 'thumbnail', 'revisions' ),
  40                  'menu_icon'         => PL_ADMIN_IMAGES . '/favicon-pagelines.ico',
  41                  'taxonomies'        => array(),
  42                  'menu_position'        => 20,
  43                  'featured_image'    => false,
  44                  'has_archive'        => false,
  45                  'map_meta_cap'        => false,
  46                  'dragdrop'            => true,
  47                  'load_sections'        => false,
  48                  'query_var'            => true
  49              );
  50  
  51          $this->settings = wp_parse_args($settings, $defaults); // settings for post type
  52  
  53          $this->register_post_type();
  54          $this->register_taxonomies();
  55          $this->register_columns();
  56          $this->featured_image();
  57          $this->section_loading();
  58  
  59      }
  60  
  61      /**
  62       * The register_post_type() function is not to be used before the 'init'.
  63       */
  64  	function register_post_type(){
  65          add_action( 'init', array(&$this,'init_register_post_type') );
  66      }
  67  
  68  
  69      /**
  70      *
  71      * @TODO document
  72      *
  73      */
  74  	function init_register_post_type(){
  75  
  76          $capability = (ploption('hide_controls_cpt')) ? ploption('hide_controls_cpt') : 'moderate_comments';
  77  
  78          register_post_type( $this->id , array(
  79                  'labels' => array(
  80                              'name'             => $this->settings['label'],
  81                              'singular_name' => $this->settings['singular_label'],
  82                              'add_new'        => __('Add New ', 'pagelines') . $this->settings['singular_label'],
  83                              'add_new_item'    => __('Add New ', 'pagelines') . $this->settings['singular_label'],
  84                              'edit'            => __('Edit ', 'pagelines') . $this->settings['singular_label'],
  85                              'edit_item'        => __('Edit ', 'pagelines') . $this->settings['singular_label'],
  86                              'view'            => __('View ', 'pagelines') . $this->settings['singular_label'],
  87                              'view_item'        => __('View ', 'pagelines') . $this->settings['singular_label'],
  88                          ),
  89  
  90                   'label'             => $this->settings['label'],
  91                  'singular_label'     => $this->settings['singular_label'],
  92                  'description'         => $this->settings['description'],
  93                  'public'             => $this->settings['public'],
  94                  'show_ui'             => $this->settings['show_ui'],
  95                  'capability_type'    => $this->settings['capability_type'],
  96                  'hierarchical'         => $this->settings['hierarchical'],
  97                  'rewrite'             => $this->settings['rewrite'],
  98                  'supports'             => $this->settings['supports'],
  99                  'menu_icon'         => $this->settings['menu_icon'],
 100                  'taxonomies'        => $this->settings['taxonomies'],
 101                  'menu_position'        => $this->settings['menu_position'],
 102                  'has_archive'        => $this->settings['has_archive'],
 103                  'map_meta_cap'        => $this->settings['map_meta_cap'],
 104                  'query_var'            => $this->settings['query_var'],
 105                  'capabilities' => array(
 106                      'publish_posts'         => $capability,
 107                      'edit_posts'             => $capability,
 108                      'edit_others_posts'     => $capability,
 109                      'delete_posts'             => $capability,
 110                      'delete_others_posts'     => $capability,
 111                      'read_private_posts'     => $capability,
 112                      'edit_post'             => $capability,
 113                      'delete_post'             => $capability,
 114                      'read_post'             => $capability,
 115                  ),
 116  
 117              ));
 118  
 119      }
 120  
 121  
 122      /**
 123      *
 124      * @TODO document
 125      *
 126      */
 127  	function register_taxonomies(){
 128  
 129          if( !empty($this->taxonomies) ){
 130  
 131              foreach($this->taxonomies as $tax_id => $tax_settings){
 132  
 133                  $defaults = array(
 134                      'hierarchical'         => true,
 135                      'label'             => '',
 136                      'singular_label'     => '',
 137                      'rewrite'             => true
 138                  );
 139  
 140                  $a = wp_parse_args($tax_settings, $defaults);
 141  
 142                  register_taxonomy( $tax_id, array($this->id), $a );
 143              }
 144  
 145          }
 146  
 147      }
 148  
 149  
 150      /**
 151      *
 152      * @TODO document
 153      *
 154      */
 155  	function register_columns(){
 156  
 157          add_filter( "manage_edit-{$this->id}_columns", array( &$this, 'set_columns' ) );
 158          add_action( "manage_{$this->id}_posts_custom_column",  array( &$this, 'set_column_values' ) );
 159      }
 160  
 161  
 162      /**
 163      *
 164      * @TODO document
 165      *
 166      */
 167  	function set_columns( $columns ){
 168  
 169          return $this->columns;
 170      }
 171  
 172  
 173      /**
 174      *
 175      * @TODO document
 176      *
 177      */
 178  	function set_column_values( $wp_column ){
 179  
 180          call_user_func( $this->columns_display_function, $wp_column );
 181  
 182      }
 183  
 184  
 185      /**
 186      *
 187      * @TODO document
 188      *
 189      */
 190  	function set_default_posts( $callback, $object = false){
 191  
 192          if(!get_posts('post_type='.$this->id)){
 193  
 194              if($object)
 195                  call_user_func( array($object, $callback), $this->id);
 196              else
 197                  call_user_func($callback, $this->id);
 198          }
 199  
 200      }
 201  
 202  
 203  
 204  
 205      /**
 206      *
 207      * @TODO document
 208      *
 209      */
 210  	function section_loading(){
 211  
 212          if( ! $this->settings['dragdrop'] )
 213              add_filter('pl_cpt_dragdrop', array(&$this, 'remove_dragdrop'), 10, 2);
 214  
 215          if ( true === $this->settings['load_sections'] || is_array( $this->settings['load_sections'] ) )
 216              add_filter('pl_template_sections', array(&$this, 'load_sections_for_type'), 10, 3);
 217  
 218      }
 219  
 220  
 221          /**
 222          *
 223          * @TODO document
 224          *
 225          */
 226  		function load_sections_for_type( $sections, $template_type, $hook ){
 227  
 228              if( $template_type == $this->id || $template_type == get_post_type_plural( $this->id ) )
 229                  return $this->settings['load_sections'];
 230              else
 231                  return $sections;
 232  
 233          }
 234  
 235  
 236          /**
 237          *
 238          * @TODO document
 239          *
 240          */
 241  		function remove_dragdrop( $bool, $post_type ){
 242              if( $post_type == $this->id )
 243                  return false;
 244              else
 245                  return $bool;
 246          }
 247  
 248  
 249      /**
 250       * Is the WP featured image supported
 251       */
 252  	function featured_image(){
 253  
 254          if( $this->settings['featured_image'] )
 255              add_filter('pl_support_featured_image', array(&$this, 'add_featured_image'));
 256  
 257      }
 258  
 259  
 260          /**
 261          *
 262          * @TODO document
 263          *
 264          */
 265  		function add_featured_image( $support_array ){
 266  
 267              $support_array[] = $this->id;
 268              return $support_array;
 269  
 270          }
 271  
 272  }
 273  /////// END OF PostType CLASS ////////
 274  
 275  /**
 276   * Checks to see if page is a CPT, or a CPT archive (type)
 277   *
 278   */
 279  function pl_is_cpt( $type = 'single' ){
 280  
 281      if( false == ( $currenttype = get_post_type() ) )
 282          return false;
 283  
 284      $std_pt = ( 'post' == $currenttype || 'page' == $currenttype || 'attachment' == $currenttype ) ? true : false;
 285  
 286      $is_type = ( ( $type == 'archive' && is_archive() ) || $type == 'single' ) ? true : false;
 287  
 288      return ( $is_type && !$std_pt  ? true : false );
 289  
 290  }
 291  
 292  /**
 293  *
 294  * @TODO do
 295  *
 296  */
 297  function get_post_type_plural( $id = null ){
 298  
 299      if(isset($id))
 300          return $id.'_archive';
 301      else
 302          return get_post_type().'_archive';
 303  }


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