[ Index ]

PHP Cross Reference of PageLines Framework

title

Body

[close]

/sections/boxes/ -> section.php (source)

   1  <?php
   2  /*
   3      Section: Boxes
   4      Author: PageLines
   5      Author URI: http://www.pagelines.com
   6      Description: Creates boxes and box layouts
   7      Class Name: PageLinesBoxes
   8      Workswith: templates, main, header, morefoot
   9      Cloning: true
  10  */
  11  
  12  /**
  13   * Boxes Section
  14   *
  15   * @package PageLines Framework
  16   * @author PageLines
  17   */
  18  class PageLinesBoxes extends PageLinesSection {
  19  
  20      var $taxID = 'box-sets';
  21      var $ptID = 'boxes';
  22  
  23      /**
  24      * PHP that always loads no matter if section is added or not.
  25      */
  26  	function section_persistent(){
  27  
  28          $this->post_type_setup();
  29  
  30          $this->post_meta_setup();
  31  
  32      }
  33  
  34  
  35      /**
  36      *
  37      * @TODO document
  38      *
  39      */
  40  	function post_type_setup(){
  41              $args = array(
  42                      'label'             => __('Boxes', 'pagelines'),
  43                      'singular_label'     => __('Box', 'pagelines'),
  44                      'description'         => __( 'For creating boxes in box type layouts.', 'pagelines'),
  45                      'menu_icon'            => $this->icon
  46                  );
  47              $taxonomies = array(
  48                  $this->taxID => array(
  49                          'label' => __('Box Sets', 'pagelines'),
  50                          'singular_label' => __('Box Set', 'pagelines'),
  51                      )
  52              );
  53              $columns = array(
  54                  'cb'             => "<input type=\"checkbox\" />",
  55                  'title'         => 'Title',
  56                  'bdescription'     => 'Text',
  57                  'bmedia'         => 'Media',
  58                  $this->taxID     => 'Box Sets'
  59              );
  60  
  61              $this->post_type = new PageLinesPostType( $this->ptID, $args, $taxonomies, $columns, array(&$this, 'column_display'));
  62  
  63              $this->post_type->set_default_posts( 'pagelines_default_boxes', $this); // Default
  64      }
  65  
  66  
  67      /**
  68      *
  69      * @TODO document
  70      *
  71      */
  72  	function post_meta_setup(){
  73  
  74              $type_meta_array = array(
  75  
  76                  'box_setup' => array(
  77                      'type'        => 'multi_option',
  78                      'title'        => __('Individual Box Options', 'pagelines'),
  79                      'shortexp'    => __('Basic setup options for handling of this box', 'pagelines'),
  80                      'selectvalues'    => array(
  81  
  82                          'the_box_icon'         => array(
  83                                  'type'         => 'image_upload',
  84                                  'inputlabel'     => __( 'Box Image', 'pagelines'),
  85                              ),
  86                          'the_box_icon_link'        => array(
  87                                  'type' => 'text',
  88                                  'inputlabel' => __( 'Box Link (Optional)', 'pagelines'),
  89                              ),
  90                          'the_box_icon_target'        => array(
  91                                  'type' => 'check',
  92                                  'inputlabel' => __( 'Open link in New Window?', 'pagelines'),
  93                              ),
  94                          'box_class' => array(
  95                              'default'        => '',
  96                              'type'             => 'text',
  97                              'size'            => 'small',
  98                              'inputlabel'     => __( 'Boxes Custom Class', 'pagelines'),
  99                          ),
 100                          'box_more_text' => array(
 101                              'default'        => '',
 102                              'type'             => 'text',
 103                              'size'            => 'small',
 104                              'inputlabel'     => __( 'More Link Text (Shows if link and text is set)', 'pagelines'),
 105                          ),
 106                      ),
 107                  ),
 108  
 109              );
 110  
 111              $post_types = array($this->id);
 112  
 113              $type_metapanel_settings = array(
 114                      'id'         => 'boxes-metapanel',
 115                      'name'         => PL_THEMENAME . ' Box Options',
 116                      'posttype'     => $post_types,
 117                  );
 118  
 119              global $boxes_meta_panel;
 120  
 121              $boxes_meta_panel =  new PageLinesMetaPanel( $type_metapanel_settings );
 122  
 123              $type_metatab_settings = array(
 124                  'id'         => 'boxes-type-metatab',
 125                  'name'         => 'Box Setup Options',
 126                  'icon'         => $this->icon,
 127              );
 128  
 129              $boxes_meta_panel->register_tab( $type_metatab_settings, $type_meta_array );
 130  
 131      }
 132  
 133  
 134      /**
 135      *
 136      * @TODO document
 137      *
 138      */
 139  	function section_optionator( $settings ){
 140  
 141          $settings = wp_parse_args($settings, $this->optionator_default);
 142  
 143              $tab = array(
 144                  'box_setup' => array(
 145                      'type'        => 'multi_option',
 146                      'title'        => __('Box Setup Options', 'pagelines'),
 147                      'shortexp'    => __('Basic setup options for handling of boxes.', 'pagelines'),
 148                      'selectvalues'    => array(
 149  
 150                          'box_set' => array(
 151                              'default'        => 'default-boxes',
 152                              'type'             => 'select_taxonomy',
 153                              'taxonomy_id'    => $this->taxID,
 154                              'inputlabel'    => __( 'Box Set To Show', 'pagelines'),
 155                          ),
 156                          'box_col_number' => array(
 157                              'type'             => 'count_select',
 158                              'default'        => '3',
 159                              'count_number'    => '5',
 160                              'count_start'    => '1',
 161                              'inputlabel'         => __( "Boxes Per Row", 'pagelines'),
 162                          ),
 163                          'box_items' => array(
 164                              'default'        => '6',
 165                              'type'             => 'text_small',
 166                              'size'            => 'small',
 167                              'inputlabel'     => __( 'Maximum Boxes To Show', 'pagelines'),
 168                          ),
 169                      ),
 170                  ),
 171  
 172                      'box_image_formatting' => array(
 173                          'type'        => 'multi_option',
 174                          'title'        => __('Box Image Options', 'pagelines'),
 175                          'shortexp'    => __('Options for formatting box images.', 'pagelines'),
 176                          'exp'        => __('', 'pagelines'),
 177                          'selectvalues'    => array(
 178  
 179                              'box_thumb_type' => array(
 180                                  'type'         => 'select',
 181                                  'default'    => 'inline_thumbs',
 182                                  'selectvalues'    => array(
 183                                          'inline_thumbs'    => array('name' => __( 'Image At Left', 'pagelines') ),
 184                                          'top_thumbs'    => array('name' => __( 'Image On Top', 'pagelines') ),
 185                                          'only_thumbs'    => array('name' => __( "Only The Image, No Text", 'pagelines') )
 186                                      ),
 187                                  'inputlabel' => __( 'Box Thumb Style (optional - defaults to Image At Left)', 'pagelines'),
 188  
 189                              ),
 190                              'box_thumb_size' => array(
 191                                  'default'        => '64',
 192                                  'type'             => 'text_small',
 193                                  'size'            => 'small',
 194                                  'inputlabel'         => __( 'Enter the max image size in pixels (optional)', 'pagelines'),
 195                              ),
 196                              'box_thumb_frame' => array(
 197                                  'default'        => '64',
 198                                  'type'             => 'check',
 199                                  'size'            => 'small',
 200                                  'inputlabel'         => __( 'Add A Frame To Images', 'pagelines'),
 201                              ),
 202                          ),
 203                      ),
 204  
 205  
 206                      'box_ordering' => array(
 207                          'type'        => 'multi_option',
 208                          'title'        => __('Box Ordering Options', 'pagelines'),
 209                          'shortexp'    => __('Optionally control the ordering of the boxes', 'pagelines'),
 210                          'exp'        => __('The easiest way to order boxes is using a post type order plugin for WordPress. However, if you would like to do it algorithmically, we have provided these options for you.', 'pagelines'),
 211                          'selectvalues'    => array(
 212  
 213                              'box_orderby' => array(
 214                                  'type'            => 'select',
 215                                  'default'        => 'ID',
 216                                  'inputlabel'    => 'Order Boxes By (If Not With Post Type Order Plugin)',
 217                                  'selectvalues' => array(
 218                                      'ID'         => array('name' => __( 'Post ID (default)', 'pagelines') ),
 219                                      'title'     => array('name' => __( 'Title', 'pagelines') ),
 220                                      'date'         => array('name' => __( 'Date', 'pagelines') ),
 221                                      'modified'     => array('name' => __( 'Last Modified', 'pagelines') ),
 222                                      'rand'         => array('name' => __( 'Random', 'pagelines') ),
 223                                  )
 224                              ),
 225                              'box_order' => array(
 226                                      'default' => 'DESC',
 227                                      'type' => 'select',
 228                                      'selectvalues' => array(
 229                                          'DESC'         => array('name' => __( 'Descending', 'pagelines') ),
 230                                          'ASC'         => array('name' => __( 'Ascending', 'pagelines') ),
 231                                      ),
 232                                      'inputlabel'=> __( 'Select sort order', 'pagelines'),
 233                              ),
 234                          ),
 235                      ),
 236  
 237                      'box_more_text' => array(
 238                          'default'        => '',
 239                          'type'             => 'text',
 240                          'size'            => 'small',
 241                          'inputlabel'     => __( 'More Link Text', 'pagelines'),
 242                          'title'         => __( 'More Link Text', 'pagelines'),
 243                          'shortexp'         => __( 'Enter text for More links on linked box elements for this page.', 'pagelines'),
 244                          'exp'            => __( 'If this option is blank (and not set in defaults), no more text will show.<br/><br/> This option can be overridden in individual box settings.', 'pagelines')
 245                      ),
 246                      'box_class' => array(
 247                          'default'        => '',
 248                          'type'             => 'text',
 249                          'size'            => 'small',
 250                          'inputlabel'     => __( 'Add custom css class to these boxes', 'pagelines'),
 251                          'title'         => __( 'Custom CSS class', 'pagelines'),
 252                          'shortexp'         => __( 'Add a custom CSS class to this set of boxes.', 'pagelines'),
 253                      ),
 254              );
 255  
 256              $tab_settings = array(
 257                      'id'         => 'fboxes_meta',
 258                      'name'         => 'Boxes',
 259                      'icon'         => $this->icon,
 260                      'clone_id'    => $settings['clone_id'],
 261                      'active'    => $settings['active']
 262                  );
 263  
 264              register_metatab($tab_settings, $tab);
 265      }
 266  
 267      /**
 268      * Section template.
 269      */
 270     function section_template( $clone_id = null ) {
 271  
 272          // Options
 273              $per_row = ( ploption( 'box_col_number', $this->oset) ) ? ploption( 'box_col_number', $this->oset) : 3;
 274              $box_set = ( ploption( 'box_set', $this->oset ) ) ? ploption( 'box_set', $this->oset ) : null;
 275              $box_limit = ploption( 'box_items', $this->oset );
 276              $this->thumb_type = ( ploption( 'box_thumb_type', $this->oset) ) ? ploption( 'box_thumb_type', $this->oset) : 'inline_thumbs';
 277              $this->thumb_size = ploption('box_thumb_size', $this->oset);
 278              $this->framed = ploption('box_thumb_frame', $this->oset);
 279  
 280  
 281              $class = ( ploption( 'box_class', $this->oset ) ) ? ploption( 'box_class', $this->oset ) : null;
 282  
 283          // Actions
 284              // Set up the query for this page
 285                  $orderby = ( ploption('box_orderby', $this->oset) ) ? ploption('box_orderby', $this->oset) : 'ID';
 286                  $order = ( ploption('box_order', $this->oset) ) ? ploption('box_order', $this->oset) : 'DESC';
 287                  $params = array( 'orderby'    => $orderby, 'order' => $order, 'post_type'    => $this->ptID );
 288                  $params[ 'showposts' ] = ( ploption('box_items', $this->oset) ) ? ploption('box_items', $this->oset) : $per_row;
 289                  $params[ $this->taxID ] = ( ploption( 'box_set', $this->oset ) ) ? ploption( 'box_set', $this->oset ) : null;
 290                  $params[ 'no_found_rows' ] = 1;
 291  
 292                  $q = new WP_Query( $params );
 293  
 294                  if(empty($q->posts)){
 295                      echo setup_section_notify( $this, 'Add Box Posts To Activate.', admin_url('edit.php?post_type='.$this->ptID), 'Add Posts' );
 296                      return;
 297                  }
 298  
 299              // Grid Args
 300                  $args = array( 'per_row' => $per_row, 'callback' => array(&$this, 'draw_boxes'), 'class' => $class );
 301  
 302              // Call the Grid
 303                  printf('<div class="fboxes fix">%s</div>', grid( $q, $args ));
 304  
 305      }
 306  
 307  
 308      /**
 309      *
 310      * @TODO document
 311      *
 312      */
 313  	function draw_boxes($p, $args){
 314  
 315          setup_postdata($p);
 316  
 317          $oset = array('post_id' => $p->ID);
 318           $box_link = plmeta('the_box_icon_link', $oset);
 319          $box_icon = plmeta('the_box_icon', $oset);
 320          $box_target = (plmeta('the_box_icon_target', $oset)) ? 'target="_blank"' : '';
 321  
 322          $class = ( plmeta( 'box_class', $oset ) ) ? plmeta( 'box_class', $oset ) : null;
 323  
 324          $image = ($box_icon) ? self::_get_box_image( $p, $box_icon, $box_link, $this->thumb_size, $box_target) : '';
 325  
 326          $title_text = ($box_link) ? sprintf('<a %s href="%s">%s</a>', $box_target, $box_link, $p->post_title ) : $p->post_title;
 327  
 328          $title = do_shortcode(sprintf('<div class="fboxtitle"><h3>%s</h3></div>', $title_text));
 329  
 330          if(plmeta('box_more_text', $oset)){
 331              $more_text = plmeta('box_more_text', $oset);
 332          } elseif(ploption('box_more_text', $this->oset)){
 333              $more_text = ploption('box_more_text', $this->oset);
 334          }else
 335              $more_text = false;
 336  
 337          $more_link = ($box_link && $more_text) ? sprintf('<span class="fboxmore-wrap"><a class="fboxmore" href="%s" %s>%s</a></span>', $box_link, $box_target, $more_text) : '';
 338  
 339          $more_link = apply_filters('box_more_link', $more_link);
 340  
 341          $content = sprintf('<div class="fboxtext">%s %s %s</div>', do_shortcode($p->post_content), pledit( $p->ID ), $more_link);
 342  
 343          $info = ($this->thumb_type != 'only_thumbs') ? sprintf('<div class="fboxinfo fix bd">%s%s</div>', $title, $content) : '';
 344  
 345          return sprintf(
 346              '<div id="%s" class="fbox %s"><div class="media box-media %s"><div class="blocks box-media-pad">%s%s</div></div></div>',
 347              'fbox_'.$p->ID,
 348              $class,
 349              $this->thumb_type,
 350              $image,
 351              $info
 352          );
 353  
 354      }
 355  
 356  
 357  
 358      /**
 359      *
 360      * @TODO document
 361      *
 362      */
 363  	function _get_box_image( $bpost, $box_icon, $box_link = false, $box_thumb_size = false, $box_target){
 364              global $pagelines_ID;
 365  
 366              $frame = ($this->framed) ? 'pl-imageframe' : '';
 367  
 368              if($this->thumb_type == 'inline_thumbs'){
 369                  $max_width = ($box_thumb_size) ? $box_thumb_size : 65;
 370                  $image_style = 'max-width: 100%';
 371                  $wrapper_style = sprintf('width: 22%%; max-width:%dpx', $max_width);
 372                  $wrapper_class = sprintf('fboxgraphic img %s', $frame);
 373              } else {
 374                  $max_width = ($box_thumb_size) ? $box_thumb_size.'px' : '100%';
 375                  $image_style = 'max-width: 100%';
 376                  $wrapper_style = sprintf('max-width:%s', $max_width);
 377                  $wrapper_class = sprintf('fboxgraphic %s', $frame);
 378              }
 379  
 380              // Make the image's tag with url
 381              $image_tag = sprintf('<img src="%s" alt="%s" style="%s" />', $box_icon, esc_html($bpost->post_title), $image_style);
 382  
 383              // If link for box is set, add it
 384              $image_output = ( $box_link ) ? sprintf('<a href="%s" title="%s" %s>%s</a>', $box_link, esc_html($bpost->post_title), $box_target, $image_tag ) : $image_tag;
 385  
 386              $wrapper = sprintf('<div class="%s" style="%s">%s</div>', $wrapper_class, $wrapper_style, $image_output );
 387  
 388              // Filter output
 389              return apply_filters('pl_box_image', $wrapper, $bpost->ID);
 390      }
 391  
 392  
 393  
 394          /**
 395          *
 396          * @TODO document
 397          *
 398          */
 399  		function pagelines_default_boxes($post_type){
 400  
 401              $d = array_reverse( $this->get_default_fboxes() );
 402  
 403              foreach($d as $dp){
 404                  // Create post object
 405                  $default_post = array();
 406                  $default_post['post_title'] = $dp['title'];
 407                  $default_post['post_content'] = $dp['text'];
 408                  $default_post['post_type'] = $post_type;
 409                  $default_post['post_status'] = 'publish';
 410                  if ( defined( 'ICL_LANGUAGE_CODE' ) )
 411                      $default_post['icl_post_language'] = ICL_LANGUAGE_CODE;
 412                  $newPostID = wp_insert_post( $default_post );
 413  
 414                  if(isset($dp['media']))
 415                      update_post_meta($newPostID, 'the_box_icon', $dp['media']);
 416  
 417                  wp_set_object_terms($newPostID, 'default-boxes', $this->taxID );
 418  
 419                  // Add other default sets, if applicable.
 420                  if(isset($dp['set']))
 421                      wp_set_object_terms($newPostID, $dp['set'], $this->taxID, true);
 422  
 423              }
 424          }
 425  
 426  
 427          /**
 428          *
 429          * @TODO document
 430          *
 431          */
 432  		function get_default_fboxes(){
 433              $default_boxes[] = array(
 434                                      'title' => 'Drag <span class="spamp">&amp;</span> Drop',
 435                                      'text'     => 'PageLines is a drag &amp; drop framework that allows you to completely customize your website with drag &amp; drop.',
 436                                      'media' => $this->base_url.'/images/fbox3.png'
 437                                  );
 438  
 439              $default_boxes[] = array(
 440                                      'title' => 'Responsive <span class="spamp">&amp;</span> Mobile',
 441                                      'text'     => "Built from the ground up to look great on mobile devices. PageLines utilizes an advanced responsive framework.",
 442                                      'media' => $this->base_url.'/images/fbox2.png'
 443                                  );
 444  
 445              $default_boxes[] = array(
 446                                      'title'    => 'Tons of Addons',
 447                                      'text'     => "Load up your own sections, themes and plugins using PageLines' one of a kind extension marketplace.",
 448                                      'media' => $this->base_url.'/images/fbox1.png'
 449                                  );
 450  
 451              return apply_filters('pagelines_default_boxes', $default_boxes);
 452          }
 453  
 454  
 455      /**
 456      *
 457      * @TODO document
 458      *
 459      */
 460  	function column_display($column){
 461          global $post;
 462  
 463          switch ($column){
 464              case 'bdescription':
 465                  the_excerpt();
 466                  break;
 467              case 'bmedia':
 468                  if(get_post_meta($post->ID, 'the_box_icon', true ))
 469                      echo '<img src="'.get_post_meta($post->ID, 'the_box_icon', true ).'" style="max-width: 80px; margin: 10px; border: 1px solid #ccc; padding: 5px; background: #fff" />';
 470  
 471                  break;
 472              case $this->taxID:
 473                  echo get_the_term_list($post->ID, 'box-sets', '', ', ','');
 474                  break;
 475          }
 476      }
 477  }


Generated: Thu May 23 23:52:43 2013 Cross-referenced by PHPXref 0.7.1