| [ Index ] |
PHP Cross Reference of PageLines Framework |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * 5 * PageLines Meta Panel Option Handling 6 * 7 * 8 * @package PageLines Framework 9 * @subpackage Post Types 10 * @since 4.0 11 * 12 */ 13 class PageLinesMetaPanel { 14 15 var $tabs = array(); // Controller for drawing meta options 16 17 /** 18 * PHP5 constructor 19 */ 20 function __construct( $settings = array() ) { 21 22 global $post; 23 global $pagenow; 24 25 /** 26 * Single post pages have post as GET, not $post as object 27 */ 28 $post = (!isset($post) && isset($_GET['post'])) ? get_post($_GET['post'], 'object') : null; 29 30 $this->ptype = PageLinesTemplate::current_admin_post_type(); 31 32 $this->page_for_posts = ( isset($post) && get_option( 'page_for_posts' ) === $post->ID ) ? true : false; 33 34 $this->blacklist = apply_filters( 'pagelines_meta_blacklist', array( 'banners', 'feature', 'boxes', 'attachment', 'revision', 'nav_menu_item' )); 35 36 $defaults = array( 37 'id' => 'pagelines-metapanel', 38 'name' => $this->get_the_title(), 39 'posttype' => $this->get_the_post_types(), 40 'location' => 'normal', 41 'priority' => 'low', 42 'hide_tabs' => false, 43 'global' => false, 44 'handle' => 'metatabs', 45 ); 46 47 $this->settings = wp_parse_args($settings, $defaults); // settings for post type 48 49 $this->register_actions(); 50 51 $this->hide_tabs = $this->settings['hide_tabs']; 52 53 } 54 55 56 /** 57 * 58 * @TODO document 59 * 60 */ 61 function register_actions(){ 62 63 $privelidge = (ploption('hide_controls_meta')) ? ploption('hide_controls_meta') : 'publish_posts'; 64 65 if ( !current_user_can( $privelidge ) ) 66 return; 67 68 // Adds the box 69 add_action( 'admin_menu', array(&$this, 'add_metapanel_box') ); 70 71 72 // Saves the options. 73 add_action( 'post_updated', array(&$this, 'save_meta_options') ); 74 75 } 76 77 78 /** 79 * 80 * @TODO document 81 * 82 */ 83 function add_metapanel_box(){ 84 85 86 87 foreach( $this->settings['posttype'] as $post_type){ 88 89 if( $this->settings['global'] ){ 90 $obj = get_post_type_object($post_type); 91 92 if( !is_object($obj) || !$obj->public ) 93 continue; 94 } 95 96 add_meta_box($this->settings['id'], $this->settings['name'], 'pagelines_metapanel_callback', $post_type, $this->settings['location'], $this->settings['priority'], array( $this )); 97 } 98 99 100 101 } 102 103 104 105 /** 106 * 107 * @TODO document 108 * 109 */ 110 function get_the_post_types(){ 111 112 // if not in this array, then show the 113 $post_id = ( isset( $_GET['post'] ) ) ? $_GET['post'] : ( isset($_POST['post_ID']) ? $_POST['post_ID'] : null ); 114 115 116 if( isset( $post_id ) && !in_array( get_post_type( $post_id ), $this->blacklist ) ) 117 $pt = array( 'post', 'page', get_post_type( $post_id ) ); 118 else 119 $pt = array( 'post', 'page' ); 120 121 122 return $pt; 123 } 124 125 126 127 128 /** 129 * 130 * @TODO document 131 * 132 */ 133 function get_edit_type(){ 134 global $post; 135 136 if(!isset($this->ptype)) 137 $this->ptype = PageLinesTemplate::current_admin_post_type(); 138 139 if($this->ptype == 'post' || $this->ptype == 'page'){ 140 141 $current_template = (isset($post)) ? get_post_meta($post->ID, '_wp_page_template', true) : false; 142 143 $this->page_templates = array_flip( get_page_templates() ); 144 145 if( $this->ptype == 'page' && $current_template && $current_template != 'default') { 146 147 if(isset($this->page_templates[$current_template])) 148 $slug = $this->page_templates[$current_template]; 149 150 }elseif( $this->ptype == 'page' ) 151 $slug = 'Default Page'; 152 elseif( $this->ptype == 'post' ) 153 $slug = 'Single Post'; 154 elseif( $this->page_for_posts ) 155 $slug = 'Blog Page'; 156 else 157 $slug = ''; 158 159 160 } elseif( $this->ptype ) 161 $slug = $this->ptype; 162 elseif(isset($_GET['page']) && $_GET['page'] == PL_SPECIAL_OPTS_SLUG) 163 $slug = 'Special Meta'; 164 else 165 $slug = 'Default'; 166 167 if(isset($slug)) 168 $this->edit_slug = $slug; 169 170 return ( isset( $slug ) ) ? $slug : ''; 171 } 172 173 174 /** 175 * 176 * @TODO document 177 * 178 */ 179 function get_the_title(){ 180 global $post; 181 $this->base_name = __( 'PageLines Meta Settings', 'pagelines' ); 182 $name = $this->base_name; 183 return $name; 184 } 185 186 /** 187 * Register a new tab for the meta panel 188 * This will look at Clone values and draw cloned tabs for cloned sections 189 * 190 * @since 2.0.b4 191 */ 192 function register_tab( $o = array(), $option_array = array(), $location = 'bottom') { 193 194 $d = array( 195 'id' => '', 196 'name' => '', 197 'icon' => '', 198 'clone_id' => 1, 199 'active' => true 200 ); 201 202 $o = wp_parse_args($o, $d); 203 204 205 $tab_id = $o['id'].$o['clone_id']; 206 207 208 if( isset($o['clone_id']) && $o['clone_id'] != 1 ){ 209 210 $name = sprintf('%s (#%s)', $o['name'], $o['clone_id']); 211 212 /** 213 * For cloned tab, unset keys and change to new val w/ key 214 */ 215 foreach($option_array as $key => $opt){ 216 217 if($opt['type'] == 'text_content' || $opt['type'] == 'text_content_reverse'){ 218 unset( $option_array[$key] ); 219 continue; 220 221 } 222 223 $newkey = join( '_', array($key, $o['clone_id']) ); 224 225 226 227 if(isset($opt['title'])) 228 $opt['title'] = sprintf('%s (#%s)', $opt['title'], $o['clone_id']); 229 230 $new = $option_array[$newkey] = $opt; 231 232 unset( $option_array[$key] ); 233 234 /** 235 * For multi options, keys will need to be changed too. 236 */ 237 if( pagelines_is_multi_option( $key, $opt ) && isset($option_array[$newkey]['selectvalues']) && is_array($option_array[$newkey]['selectvalues']) ){ 238 foreach($option_array[$newkey]['selectvalues'] as $skey => $sopt){ 239 240 241 $snewkey = join( '_', array($skey, $o['clone_id']) ); 242 243 $option_array[$newkey]['selectvalues'][$snewkey] = $sopt; 244 245 unset( $option_array[$newkey]['selectvalues'][$skey] ); 246 247 } 248 } 249 250 251 } 252 253 254 } else 255 $name = $o['name']; 256 257 258 if($location == 'top'){ 259 260 $top[ $tab_id ] = new stdClass; 261 262 $top[ $tab_id ]->options = $option_array; 263 $top[ $tab_id ]->icon = $o['icon']; 264 $top[ $tab_id ]->active = $o['active']; 265 $top[ $tab_id ]->clone_id = $o['clone_id']; 266 $top[ $tab_id ]->name = $name; 267 268 269 $this->tabs = array_merge($top, $this->tabs); 270 271 } else { 272 273 $this->tabs[ $tab_id ] = new stdClass; 274 275 $this->tabs[ $tab_id ]->options = $option_array; 276 $this->tabs[ $tab_id ]->icon = $o['icon']; 277 $this->tabs[ $tab_id ]->active = $o['active']; 278 $this->tabs[ $tab_id ]->clone_id = $o['clone_id']; 279 $this->tabs[ $tab_id ]->name = $name; 280 } 281 282 } 283 284 285 286 /** 287 * 288 * @TODO document 289 * 290 */ 291 function draw_panel(){ 292 global $post_ID; 293 global $pagelines_template; 294 295 // if page doesn't support settings 296 if ( $this->page_for_posts ){ 297 $this->non_meta_template(); 298 return; 299 } 300 301 $set = array( 302 'handle' => $this->settings['handle'], 303 'title' => $this->settings['name'], 304 'tag' => ui_key($this->get_edit_type()), 305 'type' => 'meta', 306 'stext' => __('Save Meta Settings','pagelines'), 307 'tabs' => $this->tabs, 308 'hidetabs' => $this->hide_tabs, 309 'post_ID' => $post_ID, 310 'post_type' => $this->settings['posttype'], 311 ); 312 313 $panel = new PLPanel(); 314 315 $panel->the_panel($set); 316 } 317 318 319 /** 320 * 321 * @TODO document 322 * 323 */ 324 function posts_metapanel( $type, $mode = 'meta' ){ 325 326 327 $option_engine = new OptEngine( PAGELINES_SPECIAL ); 328 329 $handle = 'postsTabs'.$type; 330 331 // Zero Out Tabs 332 $this->tabs = array(); 333 334 do_global_meta_options( $mode ); 335 336 $special_template = new PageLinesTemplate( $type ); 337 338 $special_template->load_section_optionator( $mode, $type ); 339 340 ob_start(); ?> 341 342 <script type="text/javascript"> 343 jQuery(document).ready(function() { 344 <?php printf('var %1$s = jQuery("#%1$s").tabs({cookie: { name: "htabs-%2$s" }, fx: { opacity: "toggle", duration: 150 }});', $handle, $type ); ?> 345 }); 346 </script> 347 348 <div id="<?php echo $handle;?>" class="plist-nav fix"> 349 350 351 <ul class="fix plist"> 352 <?php if(count($this->tabs) != 1): ?> 353 <lh class="hlist-header">Select Settings Panel</lh> 354 <?php foreach($this->tabs as $tab => $t): ?> 355 <li> 356 <a class="<?php echo $tab;?> metapanel-tab <?php if(!$t->active && $type != 'default' ) echo 'inactive-tab';?>" href="#<?php echo $tab;?>"> 357 <span class="metatab_pad fix"> 358 <span class="metatab_icon" style="background: transparent url(<?php echo $t->icon; ?>) no-repeat 0 0;display: block;"> 359 <?php 360 if(!$t->active && $type != 'default' ) 361 printf('<span class="tab_inactive">inactive</span>'); 362 363 echo substr($t->name, 0, 17); 364 ?> 365 </span> 366 </span> 367 </a> 368 </li> 369 <?php endforeach;?> 370 <?php else: ?> 371 <lh class="hlist-header"><?php echo ucfirst($mode);?> Settings</lh> 372 <?php endif;?> 373 </ul> 374 375 <?php foreach($this->tabs as $tab => $t): ?> 376 <div id="<?php echo $tab;?>" class="posts_tab_content"> 377 <div class="posts_tab_content_pad"> 378 <div class="metatab_title" style="background: url(<?php echo $t->icon; ?>) no-repeat 10px 13px;" > 379 <?php 380 381 echo $t->name; 382 383 if(!$t->active && $type != 'default') 384 echo OptEngine::superlink(__( 'Inactive On Template', 'pagelines' ), 'black', 'right', admin_url('admin.php?page=pagelines_templates')); 385 elseif($type == 'default') 386 echo OptEngine::superlink(__( 'Sitewide Defaults', 'pagelines' ), null, 'right'); 387 ?> 388 </div> 389 <?php 390 foreach($t->options as $oid => $o){ 391 $o['special'] = $type; 392 $o['scontrol'] = $mode; 393 $o['clone_id'] = (isset($t->clone_id)) ? $t->clone_id : 1; 394 395 $option_engine->option_engine($oid, $o); 396 } 397 ?> 398 </div> 399 </div> 400 401 <?php endforeach;?> 402 </div> 403 <?php 404 405 return ob_get_clean(); 406 } 407 408 409 /** 410 * 411 * @TODO document 412 * 413 */ 414 function non_meta_template(){?> 415 <div class="metapanel_banner"> 416 <p> 417 <strong>Note:</strong> Individual page settings do not work on the blog page (<em>use the settings panel</em>). 418 </p> 419 </div> 420 421 <?php } 422 423 424 425 /** 426 * Save Meta Options 427 * 428 * Use tabs array to save options... 429 * Need to identify if the option is being set to empty or has never been set 430 * *Section Control* gets its own saving schema 431 */ 432 function save_meta_options( $postID ){ 433 434 // Make sure we are saving on the correct post type... 435 436 // Current post type is passed in $_POST 437 $current_post_type = ( isset( $_POST['post_type'] ) ) ? $_POST['post_type'] : false; 438 439 $post_type_save = ( in_array( $current_post_type, $this->settings['posttype'] ) ) ? true : false; 440 441 if((isset($_POST['update']) || isset($_POST['save']) || isset($_POST['publish'])) && $post_type_save){ 442 443 444 445 $page_template = (isset($_POST['page_template'])) ? $_POST['page_template'] : null; 446 $save_template = $this->get_save_template_type($_POST['post_type'], $page_template); 447 $template_type = new PageLinesTemplate($save_template); 448 $template_type->load_section_optionator( ); 449 450 451 // Loop through tabs 452 foreach($this->tabs as $tab => $t){ 453 // Loop through tab options 454 foreach($t->options as $oid => $o){ 455 456 457 458 if($oid == 'section_control') 459 $this->save_sc( $postID ); 460 elseif($oid == 'page_background_image') 461 $this->save_bg( $oid, $postID ); 462 elseif($o['type'] == 'text_content' || $o['type'] == 'text_content_reverse'){ 463 464 $option_value = isset( $_POST[$oid] ) ? $_POST[ $oid ] : null; 465 466 plupop($oid, $option_value); 467 plupop($oid, $option_value, array('setting' => PAGELINES_SPECIAL)); 468 469 }elseif($o['type'] == 'check' && (bool) pldefault($oid)){ 470 471 472 $reverse = $oid."_reverse"; 473 474 $option_value = isset( $_POST[$reverse] ) ? $_POST[ $reverse ] : null; 475 476 if( !empty($option_value) || get_post_meta($postID, $reverse) ){ 477 478 update_post_meta($postID, $reverse, $option_value ); 479 480 } 481 482 483 } else { 484 485 486 487 // Note: If the value is null, then test to see if the option is already set to something 488 // create and overwrite the option to null in that case (i.e. it is being set to empty) 489 if(isset($o['selectvalues']) && pagelines_is_multi_option($oid, $o) ){ 490 491 foreach($o['selectvalues'] as $sid =>$s ){ 492 $option_value = isset($_POST[$sid]) ? $_POST[$sid] : null; 493 494 if(!empty($option_value) || get_post_meta($postID, $sid)) 495 update_post_meta($postID, $sid, $option_value ); 496 } 497 498 } else { 499 500 $option_value = isset( $_POST[$oid] ) ? $_POST[ $oid ] : null; 501 502 503 if( !empty($option_value) || get_post_meta($postID, $oid) ){ 504 505 update_post_meta($postID, $oid, $option_value ); 506 507 } 508 509 510 } 511 512 513 } 514 } 515 } 516 } 517 } 518 519 520 /** 521 * 522 * @TODO document 523 * 524 */ 525 function get_save_template_type( $post_type = null, $template = 'default'){ 526 527 if( $post_type == 'post' ){ 528 return 'single'; 529 } elseif( $post_type == 'page' ){ 530 $page_filename = str_replace('.php', '', $template); 531 $template_name = str_replace('page.', '', $page_filename); 532 return $template_name; 533 } elseif( isset($post_type) ) 534 return $post_type; 535 else 536 return 'default'; 537 538 } 539 540 541 /** 542 * 543 * @TODO document 544 * 545 */ 546 function save_bg ( $oid, $postID ) { 547 $bg = OptEngine::_background_image_array(); 548 549 foreach($bg as $k => $i){ 550 $bgid = $oid.$k; 551 552 $option_value = isset($_POST[$bgid]) ? $_POST[$bgid] : null; 553 554 if(!empty($option_value) || get_post_meta($postID, $bgid)) 555 update_post_meta($postID, $bgid, $option_value ); 556 } 557 } 558 559 560 /** 561 * 562 * @TODO document 563 * 564 */ 565 function save_sc( $postID ){ 566 global $pagelines_template; 567 568 global $post; 569 570 $save_template = new PageLinesTemplate(); 571 572 573 foreach( $save_template->map as $hook => $h ){ 574 575 if(isset($h['sections'])){ 576 foreach($h['sections'] as $key => $section_slug) 577 $this->save_section_control($postID, $section_slug, $hook ); 578 579 } elseif (isset($h['templates'])){ 580 foreach($h['templates'] as $template => $t){ 581 582 if( isset($t['sections']) && !empty($t['sections'])){ 583 foreach($t['sections'] as $key => $section_slug){ 584 585 $template_slug = $hook.'-'.$template; 586 $this->save_section_control($postID, $section_slug, $template_slug ); 587 } 588 } 589 590 } 591 } 592 593 } 594 595 } 596 597 598 /** 599 * 600 * @TODO document 601 * 602 */ 603 function save_section_control($postID, $sid, $template_slug ){ 604 605 606 $check_name_hide = meta_option_name( array('hide', $template_slug, $sid) ); 607 608 $this->save_meta($postID, $check_name_hide); 609 610 $check_name_show = meta_option_name( array('show', $template_slug, $sid) ); 611 612 $this->save_meta($postID, $check_name_show); 613 614 } 615 616 617 /** 618 * 619 * @TODO document 620 * 621 */ 622 function save_meta($postID, $name){ 623 624 $option_value = isset($_POST[ $name ]) ? $_POST[ $name ] : null; 625 626 if(!empty($option_value) || get_post_meta($postID, $name)) 627 update_post_meta($postID, $name, $option_value ); 628 } 629 630 631 632 633 } 634 /////// END OF MetaOptions CLASS //////// 635 636 637 /** 638 * 639 * @TODO do 640 * 641 */ 642 function pagelines_metapanel_callback($post, $object){ 643 644 $object['args'][0]->draw_panel(); 645 646 } 647 648 649 /** 650 * 651 * @TODO do 652 * 653 */ 654 function register_metatab($settings, $option_array, $section = '', $location = 'bottom'){ 655 656 global $metapanel_options; 657 658 foreach($option_array as $key => $opt) 659 $option_array[$key]['section'] = $section; 660 661 $metapanel_options->register_tab($settings, $option_array, $location); 662 663 } 664 665 666 /** 667 * 668 * @TODO do 669 * 670 */ 671 function add_global_meta_options( $meta_array = array(), $location = 'bottom'){ 672 global $global_meta_options; 673 674 if($location == 'top') 675 $global_meta_options = array_merge($meta_array, $global_meta_options); 676 else 677 $global_meta_options = array_merge($global_meta_options, $meta_array); 678 679 } 680 681 /** 682 * 683 * @TODO do 684 * 685 */ 686 function do_global_meta_options( $mode = '' ){ 687 688 global $global_meta_options; 689 690 $metatab_settings = array( 691 'id' => 'general_page_meta', 692 'name' => __( 'Page Setup', 'pagelines' ), 693 'icon' => PL_ADMIN_ICONS . '/ileaf.png' 694 ); 695 696 697 if($mode == 'integration') 698 unset($global_meta_options['_pagelines_layout_mode']); 699 700 if($mode == 'default') 701 return; 702 703 register_metatab($metatab_settings, $global_meta_options, '', 'top'); 704 } 705 706 /** 707 * 708 * Returns Extension Array Config 709 * 710 */ 711 function special_page_settings_array( ){ 712 713 global $metapanel_options; 714 715 $d = array( 716 717 'site_defaults' => array( 718 'metapanel' => $metapanel_options->posts_metapanel( 'default', 'default' ), 719 'icon' => PL_ADMIN_ICONS.'/equalizer.png' 720 ), 721 'blog_page' => array( 722 'metapanel' => $metapanel_options->posts_metapanel( 'posts' ), 723 'icon' => PL_ADMIN_ICONS.'/blog.png' 724 ), 725 'archive_page' => array( 726 'metapanel' => $metapanel_options->posts_metapanel( 'archive' ), 727 'icon' => PL_ADMIN_ICONS.'/archives.png', 728 'version' => 'pro' 729 ), 730 'category_page' => array( 731 'metapanel' => $metapanel_options->posts_metapanel( 'category' ), 732 'icon' => PL_ADMIN_ICONS.'/category.png', 733 'version' => 'pro' 734 ), 735 'search_results' => array( 736 'metapanel' => $metapanel_options->posts_metapanel('search'), 737 'icon' => PL_ADMIN_ICONS.'/search.png', 738 'version' => 'pro' 739 ), 740 'tag_listing' => array( 741 'metapanel' => $metapanel_options->posts_metapanel('tag'), 742 'icon' => PL_ADMIN_ICONS.'/tag.png', 743 'version' => 'pro' 744 ), 745 'author_posts' => array( 746 'metapanel' => $metapanel_options->posts_metapanel('author'), 747 'icon' => PL_ADMIN_ICONS.'/author.png', 748 'version' => 'pro' 749 ), 750 '404_page' => array( 751 'metapanel' => $metapanel_options->posts_metapanel('404_page'), 752 'icon' => PL_ADMIN_ICONS.'/404.png', 753 'version' => 'pro' 754 ), 755 ); 756 757 $ints = handle_integrations_meta(); 758 759 $d = array_merge($d, $ints); 760 761 return apply_filters('postsmeta_settings_array', $d); 762 } 763 764 /** 765 * 766 * @TODO do 767 * 768 */ 769 function get_global_meta_options(){ 770 $opts = array( 771 772 '_pagelines_layout_mode' => array( 773 'type' => 'graphic_selector', 774 'sprite' => PL_ADMIN_IMAGES.'/sprite-layouts.png', 775 'height' => '50px', 776 'width' => '50px', 777 'selectvalues' => array( 778 'fullwidth' => array( 'name' => __( 'Fullwidth layout', 'pagelines' ), 'version' => 'pro', 'offset' => '0px 0px'), 779 'one-sidebar-right' => array( 'name' => __( 'One sidebar on right', 'pagelines' ), 'offset' => '0px -50px'), 780 'one-sidebar-left' => array( 'name' => __( 'One sidebar on left', 'pagelines' ), 'offset' => '0px -100px'), 781 'two-sidebar-right' => array( 'name' => __( 'Two sidebars on right', 'pagelines' ), 'version' => 'pro', 'offset' => '0px -150px' ), 782 'two-sidebar-left' => array( 'name' => __( 'Two sidebars on left', 'pagelines' ), 'version' => 'pro', 'offset' => '0px -200px' ), 783 'two-sidebar-center' => array( 'name' => __( 'Two sidebars, one on each side', 'pagelines' ), 'version' => 'pro', 'offset' => '0px -250px' ), 784 ), 785 'title' => __( 'Individual Page Content Layout', 'pagelines' ), 786 'inputlabel' => __( 'Select Page Layout', 'pagelines' ), 787 'layout' => 'interface', 788 'shortexp' => __( 'Select the layout that will be used on this page', 'pagelines' ), 789 'exp' => '', 790 ), 791 792 'section_control' => array( 793 'type' => 'section_control', 794 'title' => __( 'Individual Page Section Control', 'pagelines' ), 795 'layout' => 'interface', 796 'shortexp' => __( 'Control which sections appear on this specific page', 'pagelines' ), 797 'exp' => '', 798 ), 799 800 'page_background_image' => array( 801 'title' => 'Page Background Image', 802 'shortexp' => 'Setup A Background Image For This Page', 803 'exp' => 'Use this option to apply a background image to this page. This option will only be applied to the current page.<br/><br/><strong>Positioning</strong> Use percentages to position the images, 0% corresponds to the "top" or "left" side, 50% to center, etc..', 804 'type' => 'background_image', 805 'selectors' => cssgroup('page_background_image'), 806 'disabled_mode' => 'color_control' 807 ), 808 'disable_mobile_view' => array( 809 'default' => false, 810 'type' => 'check', 811 'title' => __( 'Disable Mobile Optimized View', 'pagelines' ), 812 'inputlabel' => __( 'Disable Mobile View', 'pagelines' ), 813 'shortexp' => __( 'Make it so mobile devices will see the full site, not the mobile optimized one.', 'pagelines' ), 814 'exp' => __( 'By default PageLines accommodates mobile devices resolution and shows a mobile optimized view. Check this option to make it so users see your full site.', 'pagelines' ), 815 ), 816 817 ); 818 819 return apply_filters('global_meta_options', $opts); 820 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Apr 6 23:00:27 2013 | Cross-referenced by PHPXref 0.7.1 |