| [ Index ] |
PHP Cross Reference of PageLines Framework |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * 5 * Extend Control Interface 6 * 7 * @package PageLines Framework 8 * @subpackage OptionsUI 9 * @since 2.0.b9 10 * 11 */ 12 13 class PageLinesExtendUI { 14 15 16 /** 17 * Construct 18 */ 19 function __construct() { 20 21 $this->exprint = 'onClick="extendIt(\'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\')"'; 22 23 $this->defaultpane = array( 24 'name' => 'Unnamed', 25 'version' => 'No version', 26 'active' => false, 27 'desc' => 'No description.', 28 'auth_url' => 'http://www.pagelines.com', 29 'auth' => 'PageLines', 30 'image' => PL_ADMIN_IMAGES . '/thumb-default.png', 31 'buttons' => '', 32 'key' => '', 33 'type' => '', 34 'count' => '', 35 'status' => '', 36 'actions' => array(), 37 'screen' => '', 38 'screenshot'=> '', 39 'extended' => '', 40 'slug' => '', 41 'long' => '', 42 'external' => '', 43 'demo' => '' 44 ); 45 46 /** 47 * Hooked Actions 48 */ 49 add_action('admin_head', array(&$this, 'extension_js')); 50 51 } 52 53 /** 54 * Draw a list of extended items 55 */ 56 function extension_list( $args ){ 57 58 $defaults = array ( 59 60 'list' => array(), 61 'type' => 'addon', 62 'tab' => '', 63 'mode' => '', 64 'ext' => '', 65 'active' => '' 66 ); 67 68 $list = wp_parse_args( $args, $defaults ); 69 70 if( empty( $list['list'] ) ) { 71 if ( $list['tab'] == 'installed' ) 72 return $this->extension_banner( sprintf( __( 'Installed %s will appear here.', 'pagelines' ), $list['type'] ) ); 73 else 74 return $this->extension_banner( sprintf( __( 'Available %s %s will appear here.', 'pagelines' ), $list['tab'], $list['type'] ) ); 75 } 76 77 $count = 1; 78 if ( $list['mode'] == 'download' ) { 79 80 foreach( $list['list'] as $eid => $e ){ 81 $list['ext'] .= $this->graphic_pane( $e, 'download', $count ); 82 $count++; 83 } 84 85 $output = sprintf('<ul class="graphic_panes plpanes fix"><div class="plpanes-pad">%s</div></ul>', $list['ext']); 86 return $output; 87 } 88 89 90 if($list['mode'] == 'graphic'){ 91 92 $count = 1; 93 foreach( $list['list'] as $eid => $e ){ 94 95 if(isset($e['active']) && $e['active']) 96 $list['active'] .= $this->graphic_pane( $e, 'active', $count); 97 else 98 $list['ext'] .= $this->graphic_pane( $e, '', $count); 99 100 $count++; 101 } 102 103 $output = sprintf( 104 '<div class="graphic_panes plpanes fix"><div class="plpanes-pad">%s%s</div></div>', 105 $list['active'], 106 $list['ext'] 107 ); 108 109 } else { 110 111 $count = 1; 112 foreach( $list['list'] as $eid => $e ){ 113 if(isset($e['active']) && $e['active']) 114 $list['active'] .= $this->pane_template( $e, 'active', $count); 115 else 116 $list['ext'] .= $this->pane_template( $e, '', $count); 117 $count++; 118 } 119 $output = sprintf( 120 '<div class="plpanes fix"><div class="plpanes-pad"><div class="plpanes-wrap">%s%s</div></div></div>', 121 $list['active'], 122 $list['ext'] 123 ); 124 125 } 126 return $output; 127 } 128 129 130 /** 131 * 132 * @TODO document 133 * 134 */ 135 function graphic_pane( $e, $style = '', $count = ''){ 136 137 $e = wp_parse_args( $e, $this->defaultpane); 138 139 $image = sprintf( '<img class="" src="%s" alt="Thumb" />', $e['image'] ); 140 141 if ( 'integration' != $e['type'] ) 142 $title = sprintf('<h2><a href="%s">%s</a></h2>', $e['infourl'], $e['name'] ); 143 else 144 $title = sprintf('<h2>%s</h2>', $e['name'] ); 145 146 $text = sprintf('<p>%s</p>', $e['desc']); 147 148 $details = $this->grab_details( $e ); 149 150 $link = $this->get_extend_buttons( $e, $style ) ; 151 152 $dtitle = ($style == 'active') ? __('<h4>Active Theme</h4>', 'pagelines') : ''; 153 154 $alt = ($count % 2 == 0) ? 'alt_row' : ''; 155 156 $out = sprintf( 157 '<div class="%s %s plpane graphic_pane media fix">%s<div class="theme-screen img">%s</div><div class="theme-desc bd">%s%s<div class="pane-buttons">%s</div><div class="pane-dets">%s</div></div></div>', 158 $style, 159 $alt, 160 $dtitle, 161 $image, 162 $title, 163 $text, 164 $link, 165 join($details, ' <span class="pipe">|</span> ') 166 167 ); 168 169 170 return $out; 171 172 } 173 174 function pane_template( $e, $style = '', $count = ''){ 175 176 177 178 $e = wp_parse_args( $e, $this->defaultpane); 179 180 $image = sprintf( '<img class="" src="%s" alt="Thumb" />', $e['image'] ); 181 182 if ( 'internal' != $e['tab'] && 'child' != $e['tab'] ) 183 $title = sprintf('<h2><a href="%s">%s</a></h2>', $e['infourl'], $e['name'] ); 184 else 185 $title = sprintf('<h2>%s</h2>', $e['name'] ); 186 187 $text = sprintf('<p>%s</p>', $e['desc']); 188 189 $details = $this->grab_details( $e ); 190 191 $link = $this->get_extend_buttons( $e, $style ) ; 192 193 $dtitle = ($style == 'active') ? __('<h4>Activated</h4>', 'pagelines') : ''; 194 195 $alt = ($count % 2 == 0) ? 'alt_row' : ''; 196 197 $out = sprintf( 198 '<div class="%s %s plpane graphic_pane media fix">%s<div class="theme-screen img">%s</div><div class="theme-desc bd">%s%s<div class="pane-buttons">%s</div><div class="pane-dets">%s</div></div></div>', 199 $style, 200 $alt, 201 $dtitle, 202 $image, 203 $title, 204 $text, 205 $link, 206 join($details, ' <span class="pipe">|</span> ') 207 208 ); 209 210 211 return $out; 212 213 } 214 215 /** 216 * 217 * @TODO document 218 * 219 */ 220 function pane_template_old( $e, $count ){ 221 222 $demo = ''; 223 $external = ''; 224 $info = ''; 225 $auth = ''; 226 227 $s = wp_parse_args( $e, $this->defaultpane); 228 229 // if we are 'core' tab or 'child' tab we dont want to see store urls or versions, they are pointless... 230 $int = ( isset( $s['section']['type'] ) && ( $s['section']['type'] == 'parent' || $s['section']['type'] == 'custom') ) ? true : false; 231 232 233 $alt = ($count % 2 == 0) ? 'alt_row' : ''; 234 235 $details = $this->grab_details( $s ); 236 237 238 // Thumb 239 $thumb = sprintf( '<div class="pane-img-col"><div class="img paneimg"><img src="%s" alt="thumb" /></div></div>', $s['image'] ); 240 241 $title = sprintf( 242 '<div class="pane-head"><div class="pane-head-pad"><h3 class="pane-title">%s</h3><div class="pane-buttons">%s</div></div></div>', 243 $s['name'], 244 $this->get_extend_buttons( $e ) 245 ); 246 247 $body = sprintf( 248 '<div class="pane-desc"><div class="pane-desc-pad"><div class="pane-text">%s</div><div class="pane-dets"><div class="pane-dets-pad">%s</div></div></div></div>', 249 $s['desc'], 250 join($details, ' <span class="pipe">|</span> ') 251 ); 252 253 254 $out = sprintf( 255 '<div class="plpane %s"><div class="plpane-pad fix"><div class="plpane-box"><div class="plpane-box-pad fix">%s %s %s<div class="clear"></div></div> </div></div></div>', 256 $alt, 257 $thumb, 258 $title, 259 $body 260 ); 261 262 return $out; 263 264 } 265 266 267 /** 268 * 269 * @TODO document 270 * 271 */ 272 function grab_details( $args ){ 273 274 $target = 'target="_blank"'; 275 $details = array(); 276 if( 'internal' != $args['tab'] && $args['version'] ) 277 $details['version'] = sprintf( '<strong>v%s</strong>', $args['version'] ); 278 279 $details['cred'] = sprintf( 'by <a %s href="%s">%s</a>', $target, $args['auth_url'], $args['auth'] ); 280 281 if( 'internal' != $args['tab'] && 'integration' != $args['type'] ) 282 $details['overview'] = sprintf( '<a %s href="%s">Overview</a>', $target, $args['infourl'] ); 283 284 if ( $args['external'] ) 285 $details['homepage'] = sprintf( '<a %s href="%s">Homepage</a>', $target, $args['external'] ); 286 287 if ( $args['demo'] ) 288 $details['demo'] = sprintf( '<a %s href="%s">Demo</a>', $target, $args['demo'] ); 289 290 return $details; 291 } 292 293 294 295 /** 296 * 297 * @TODO document 298 * 299 */ 300 function get_extend_buttons( $e, $style = 'small'){ 301 302 /* 303 'Mode' = the extension handling mode 304 'Key' = the key of the element in the array, for the response 305 'Type' = what is being extended 306 'File' = the url for the extension/install/update 307 'duringText' = the text while the extension is happening 308 */ 309 310 $buttons = ''; 311 foreach( $e['actions'] as $type => $a ){ 312 313 if($a['condition']) 314 $buttons .= $this->extend_button( $e['key'], $a, $style); 315 316 } 317 318 return $buttons; 319 320 } 321 322 323 /** 324 * 325 * @TODO document 326 * 327 */ 328 function extend_button( $key, $a, $style = 'small'){ 329 330 $d = array( 331 'mode' => '', 332 'case' => '', 333 'file' => '', 334 'text' => 'Extend', 335 'dtext' => '', 336 'key' => $key, 337 'type' => '', 338 'path' => '', 339 'product' => 0, 340 'confirm' => false, 341 'dashboard' => false 342 ); 343 344 $a = wp_parse_args($a, $d); 345 346 $js_call = ( $a['mode'] == 'installed' ) ? '' : sprintf( $this->exprint, $a['case'], $a['key'], $a['type'], $a['file'], $a['path'], $a['product'], $a['dtext'], $a['dashboard']); 347 348 if( $a['mode'] == 'deactivate' || $a['mode'] == 'delete' || $a['mode'] == 'installed' ) 349 $class = 'discrete'; 350 else 351 $class = ''; 352 353 if ( $a['mode'] == 'subscribe' ) 354 $class = 'discrete subscribe'; 355 356 if ( $a['mode'] == 'unsubscribe' ) 357 $class = 'discrete unsubscribe'; 358 359 if($style == 'superlink') 360 $button = OptEngine::superlink( $a['text'], $a['mode'], '', '', $js_call); 361 else 362 $button = sprintf('<span class="extend_button %s" %s>%s</span>', $class, $js_call, $a['text']); 363 364 return $button; 365 } 366 367 368 369 /** 370 * 371 * @TODO document 372 * 373 */ 374 function install_button( $e ){ 375 376 377 $install_js_call = sprintf( $this->exprint, 'section_install', $key, 'sections', $key, __( 'Installing', 'pagelines' ) ); 378 379 $button = OptEngine::superlink( __( 'Install Section', 'pagelines' ), 'black', '', '', $install_js_call); 380 381 } 382 383 /** 384 * Draw a list of extended items 385 */ 386 function get_extend_plugin( $status = '', $tab = '' ){ 387 388 $key = 'ext'.$tab; 389 390 $name = 'pagelines-sections'; 391 392 if($status == 'notactive'){ 393 $file = '/' . trailingslashit( $name ) . $name . '.php'; 394 $btext = 'Activate Sections'; 395 $text = sprintf( __( 'Sections plugin installed, now activate it!', 'pagelines' ) ); 396 $install_js_call = sprintf( $this->exprint, 'plugin_activate', $key, 'plugins', $file, '', '', __( 'Activating', 'pagelines' ), 0 ); 397 398 } elseif($status == 'notinstalled'){ 399 $btext = __( 'Install It Now!', 'pagelines' ); 400 $text = __( 'You need to install and activate PageLines Sections Plugin', 'pagelines' ); 401 402 $install_js_call = sprintf( 403 $this->exprint, 404 'plugin_install', 405 $key, 406 'plugin', 407 'pagelines-sections', 408 '/pagelines-sections/pagelines-sections.php', 409 '', 410 __( 'Installing', 'pagelines' ), 411 0 412 ); 413 } 414 415 $eresponse = 'response'.$key; 416 417 // The button 418 $install_button = OptEngine::superlink($btext, 'blue', 'install_now iblock', '', $install_js_call); 419 420 // The banner 421 return sprintf('<div class="install-control fix"><span id="%s" class="banner-text">%s</span><br/><br/>%s</div>', $eresponse, $text, $install_button); 422 } 423 424 /** 425 * Draw a list of extended items 426 */ 427 function extension_banner( $text, $click = '', $button_text = 'Add Some →' ){ 428 429 if($click != ''){ 430 $thebutton = OptEngine::superlink($button_text, 'blue', 'install_now iblock', $click ); 431 $button = sprintf('<br/><br/>%s', $thebutton ); 432 433 } else 434 $button = ''; 435 436 // The banner 437 return sprintf('<div class="install-control fix"><span class="banner-text">%s</span>%s</div>', $text, $button); 438 } 439 440 441 /** 442 * 443 * @TODO document 444 * 445 */ 446 function upload_form( $type, $disabled = false ){ 447 448 $file = $type; 449 450 if ( $disabled ) 451 return $this->extension_banner( __( 'Sorry uploads do not work with this server config, please use FTP!', 'pagelines' ) ); 452 453 if ( EXTEND_NETWORK ) 454 return $this->extension_banner( __( 'Only network admins can upload sections!', 'pagelines' ) ); 455 456 ob_start(); 457 ?> 458 <div class="pagelines_upload_form"> 459 <h4><?php _e( 'Install a section in .zip format', 'pagelines' ) ?></h4> 460 <p class="install-help"><?php _e( 'If you have a section in a .zip format, you may install it by uploading it here.', 'pagelines' ) ?></p> 461 <?php printf( '<form method="post" enctype="multipart/form-data" action="%s">', admin_url( PL_ADMIN_STORE_URL ) ) ?> 462 <?php wp_nonce_field( 'pagelines_extend_upload', 'upload_check' ) ?> 463 <label class="screen-reader-text" for="<?php echo $file;?>"><?php _e( 'Section zip file', 'pagelines' ); ?></label> 464 <input type="file" id="<?php echo $file;?>" name="<?php echo $file;?>" /> 465 <input type="hidden" name="type" value="<?php echo $file;?>" /> 466 <input type="submit" class="button" value="<?php esc_attr_e('Install Now', 'pagelines' ) ?>" /> 467 </form> 468 </div> 469 <?php 470 471 return ob_get_clean(); 472 } 473 474 475 /** 476 * 477 * @TODO document 478 * 479 */ 480 function search_extend( $type ){ 481 482 return $this->extension_banner( __( 'Search functionality is currently disabled. Check back soon!', 'pagelines' ) ); 483 } 484 485 /** 486 * 487 * Add Javascript to header (hook in contructor) 488 * 489 */ 490 function extension_js(){ 491 492 if ( !isset( $_GET['page'] ) || ( strpos( $_GET['page'], PL_ADMIN_STORE_SLUG ) === false && strpos( $_GET['page'], PL_MAIN_DASH ) === false) ) 493 return; 494 ?> 495 <script type="text/javascript">/*<![CDATA[*/ 496 497 /* popup stuff for reference 498 jQuery(document).ready(function() { 499 jQuery('a.pane-info').colorbox({iframe:true, width:"50%", height:"60%"}); 500 }); 501 */ 502 function extendIt( mode, key, type, file, path, product, duringText, dash ){ 503 504 /* 505 'Mode' = the type of extension 506 'Key' = the key of the element in the array, for the response 507 'Type' = ? 508 'File' = the url for the extension/install/update 509 'duringText' = the text while the extension is happening 510 */ 511 512 var data = { 513 action: 'pagelines_ajax_extend_it_callback', 514 extend_mode: mode, 515 extend_type: type, 516 extend_file: file, 517 extend_path: path, 518 extend_product: product, 519 extend_dash: dash 520 }; 521 522 var responseElement = jQuery('#dialog'); 523 var duringTextLength = duringText.length + 3; 524 var dotInterval = 400; 525 526 jQuery.ajax({ 527 type: 'POST', 528 url: ajaxurl, 529 data: data, 530 beforeSend: function(){ 531 532 responseElement.html( duringText ).dialog({ 533 minWidth: 600, 534 modal: true, 535 dialogClass: 'pl_ajax_dialog', 536 open: function(event, ui) { 537 jQuery(".ui-dialog-titlebar-close").hide(); 538 } 539 }); 540 541 //responseElement.html( duringText ).slideDown(); 542 543 // add some dots while saving. 544 interval = window.setInterval(function(){ 545 546 var text = responseElement.text(); 547 548 if ( text.length < duringTextLength ){ 549 responseElement.text( text + '.' ); 550 } else { 551 responseElement.text( duringText ); 552 } 553 554 }, dotInterval); 555 556 }, 557 success: function( response ){ 558 window.clearInterval( interval ); // clear dots... 559 responseElement.dialog().html(response); 560 561 } 562 }); 563 564 } 565 /*]]>*/</script> 566 567 <?php } 568 569 570 } 571 572 /** 573 * 574 * Returns Extension Array Config 575 * 576 */ 577 function extension_array( ){ 578 579 global $extension_control; 580 581 $d = array( 582 'Sections' => array( 583 'icon' => PL_ADMIN_ICONS.'/dragdrop.png', 584 'htabs' => array( 585 'get_new_sections' => store_subtabs('section'), 586 'your_added_sections' => array( 587 'title' => __( 'Your Sections Added Via Store', 'pagelines' ), 588 'callback' => $extension_control->extension_engine( 'section_added', 'user' ) 589 ), 590 'core_framework' => array( 591 'title' => __( 'Your Sections From PageLines Framework', 'pagelines' ), 592 'callback' => $extension_control->extension_engine( 'section_added', 'internal' ) 593 ), 594 'child_theme' => array( 595 'title' => __( 'Your Sections From Your Child Theme', 'pagelines' ), 596 'callback' => $extension_control->extension_engine( 'section_added', 'child' ) 597 ), 598 599 600 ) 601 602 ), 603 'Themes' => array( 604 'icon' => PL_ADMIN_ICONS.'/extend-themes.png', 605 'htabs' => array( 606 'get_new_themes' => store_subtabs('theme'), 607 'your_themes' => array( 608 'title' => __( 'Your Installed PageLines Themes', 'pagelines' ), 609 'callback' => $extension_control->extension_engine( 'theme', 'installed' ) 610 ), 611 612 ) 613 ), 614 'Plugins' => array( 615 'icon' => PL_ADMIN_ICONS.'/extend-plugins.png', 616 'htabs' => array( 617 'get_new_plugins' => store_subtabs('plugin'), 618 'your_plugins' => array( 619 'title' => __( 'Your Installed PageLines Plugins', 'pagelines' ), 620 'callback' => $extension_control->extension_engine( 'plugin', 'installed' ) 621 ), 622 623 ) 624 625 ), 626 627 'Integrations' => array( 628 'icon' => PL_ADMIN_ICONS.'/puzzle.png', 629 'htabs' => array( 630 631 'available_integrations' => array( 632 'title' => __( 'Available PageLines Integrations', 'pagelines' ), 633 'callback' => $extension_control->extension_engine( 'integration' ) 634 ) 635 ) 636 ) 637 ); 638 if( EXTEND_NETWORK ) { 639 unset( $d['Sections']['htabs']['get_new_sections']); 640 unset( $d['Plugins']['htabs']['get_new_plugins']); 641 unset( $d['Themes']['htabs']['get_new_themes']); 642 unset( $d['Integrations']); 643 } 644 645 return apply_filters('extension_array', $d); 646 } 647 648 /** 649 * 650 * @TODO do 651 * 652 */ 653 function store_subtabs( $type ){ 654 global $extension_control; 655 656 $s = array( 657 'type' => 'subtabs', 658 'class' => 'left ht-special', 659 'featured' => array( 660 'title' => __( 'Featured', 'pagelines' ), 661 'class' => 'right', 662 ), 663 'premium' => array( 664 'title' => __( 'Top Premium', 'pagelines' ), 665 'class' => 'right', 666 ), 667 'free' => array( 668 'title' => __( 'Top Free', 'pagelines' ), 669 'class' => 'right', 670 ), 671 ); 672 673 674 foreach($s as $key => $subtab){ 675 676 if($type == 'theme'){ 677 678 $s['title'] = __( 'Add New Themes', 'pagelines' ); 679 680 if($key == 'featured' || $key == 'premium' || $key == 'free') 681 $s[$key]['callback'] = $extension_control->extension_engine( $type, $key ); 682 683 } elseif ($type == 'section'){ 684 685 $s['title'] = __( 'Add New Sections', 'pagelines' ); 686 687 if($key == 'featured' || $key == 'premium' || $key == 'free') 688 $s[$key]['callback'] = $extension_control->extension_engine( 'section_extend', $key ); 689 690 $s['upload'] = array( 691 'title' => __( 'Upload', 'pagelines' ), 692 'callback' => $extension_control->ui->upload_form( 'section', ( !is_writable( WP_PLUGIN_DIR ) ) ? true : false ) 693 ); 694 695 } elseif ($type == 'plugin' ){ 696 697 $s['title'] = __( 'Add New Plugins', 'pagelines' ); 698 699 if($key == 'featured' || $key == 'premium' || $key == 'free') 700 $s[$key]['callback'] = $extension_control->extension_engine( $type, $key ); 701 } 702 } 703 704 return $s; 705 }
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 |