[ Index ]

PHP Cross Reference of PageLines Framework

title

Body

[close]

/admin/ -> class.extend.ui.php (source)

   1  <?php
   2  /**
   3   *
   4   *
   5   *  Extend Control Interface
   6   *
   7   *  @package PageLines DMS
   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 &rarr;' ){
 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  /**
 575   *
 576   *  Returns Extension Array Config
 577   *
 578   */
 579  function extension_array(  ){
 580  
 581      global $extension_control;
 582  
 583      $d = array(
 584          'Sections' => array(
 585              'icon'        => PL_ADMIN_ICONS.'/dragdrop.png',
 586              'htabs'     => array(
 587                      'get_new_sections'    => store_subtabs('section'),
 588                      'your_added_sections'    => array(
 589                          'title'        => __( 'Your Sections Added Via Store', 'pagelines' ),
 590                          'callback'    => $extension_control->extension_engine( 'section_added', 'user' )
 591                          ),
 592                      'core_framework'    => array(
 593                          'title'        => __( 'Your Sections From PageLines Framework', 'pagelines' ),
 594                          'callback'    => $extension_control->extension_engine( 'section_added', 'internal' )
 595                          ),
 596                      'child_theme'    => array(
 597                          'title'        => __( 'Your Sections From Your Child Theme', 'pagelines' ),
 598                          'callback'    => $extension_control->extension_engine( 'section_added', 'child' )
 599                          ),
 600  
 601  
 602              )
 603  
 604          ),
 605          'Themes' => array(
 606              'icon'        => PL_ADMIN_ICONS.'/extend-themes.png',
 607              'htabs'     => array(
 608                  'get_new_themes'    => store_subtabs('theme'),
 609                  'your_themes'    => array(
 610                      'title'        => __( 'Your Installed PageLines Themes', 'pagelines' ),
 611                      'callback'    => $extension_control->extension_engine( 'theme', 'installed' )
 612                      ),
 613  
 614                  )
 615          ),
 616          'Plugins' => array(
 617              'icon'        => PL_ADMIN_ICONS.'/extend-plugins.png',
 618              'htabs'     => array(
 619                  'get_new_plugins'    => store_subtabs('plugin'),
 620                  'your_plugins'    => array(
 621                      'title'        => __( 'Your Installed PageLines Plugins', 'pagelines' ),
 622                      'callback'    => $extension_control->extension_engine( 'plugin', 'installed' )
 623                      ),
 624  
 625              )
 626  
 627          ),
 628  
 629          'Integrations' => array(
 630              'icon'        => PL_ADMIN_ICONS.'/puzzle.png',
 631              'htabs'     => array(
 632  
 633                  'available_integrations'    => array(
 634                      'title'        => __( 'Available PageLines Integrations', 'pagelines' ),
 635                      'callback'    => $extension_control->extension_engine( 'integration' )
 636                      )
 637                  )
 638          )
 639      );
 640      if( EXTEND_NETWORK ) {
 641          unset( $d['Sections']['htabs']['get_new_sections']);
 642          unset( $d['Plugins']['htabs']['get_new_plugins']);
 643          unset( $d['Themes']['htabs']['get_new_themes']);
 644          unset( $d['Integrations']);
 645      }
 646  
 647      return apply_filters('extension_array', $d);
 648  }
 649  
 650  /**
 651  *
 652  * @TODO do
 653  *
 654  */
 655  function store_subtabs( $type ){
 656      global $extension_control;
 657  
 658      $s = array(
 659          'type'        => 'subtabs',
 660          'class'        => 'left ht-special',
 661          'featured'    => array(
 662              'title'        => __( 'Featured', 'pagelines' ),
 663              'class'        => 'right',
 664              ),
 665          'premium'    => array(
 666              'title'        => __( 'Top Premium', 'pagelines' ),
 667              'class'        => 'right',
 668              ),
 669          'free'    => array(
 670              'title'        => __( 'Top Free', 'pagelines' ),
 671              'class'        => 'right',
 672              ),
 673      );
 674  
 675  
 676      foreach($s as $key => $subtab){
 677  
 678          if($type == 'theme'){
 679  
 680              $s['title']                = __( 'Add New Themes', 'pagelines' );
 681  
 682              if($key == 'featured' || $key == 'premium' || $key == 'free')
 683                  $s[$key]['callback']     = $extension_control->extension_engine( $type, $key );
 684  
 685          } elseif ($type == 'section'){
 686  
 687              $s['title']                = __( 'Add New Sections', 'pagelines' );
 688  
 689              if($key == 'featured' || $key == 'premium' || $key == 'free')
 690                  $s[$key]['callback']     = $extension_control->extension_engine( 'section_extend', $key );
 691  
 692              $s['upload'] = array(
 693                  'title'        => __( 'Upload', 'pagelines' ),
 694                  'callback'    => $extension_control->ui->upload_form( 'section', ( !is_writable( WP_PLUGIN_DIR ) ) ? true : false )
 695              );
 696  
 697          } elseif ($type == 'plugin' ){
 698  
 699              $s['title']                = __( 'Add New Plugins', 'pagelines' );
 700  
 701              if($key == 'featured' || $key == 'premium' || $key == 'free')
 702                  $s[$key]['callback']     = $extension_control->extension_engine( $type, $key );
 703          }
 704      }
 705  
 706      return $s;
 707  }


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