[ Index ]

PHP Cross Reference of PageLines Framework

title

Body

[close]

/admin/ -> actions.options.php (source)

   1  <?php
   2  
   3  // ====================================
   4  // = Build PageLines Option Interface =
   5  // ====================================
   6  
   7  // Add our menus where they belong.
   8  add_action( 'admin_menu', 'pagelines_add_admin_menu' );
   9  
  10  add_action('admin_menu', 'pagelines_add_admin_menus');
  11  
  12  if( ! function_exists( 'pagelines_add_admin_menu' ) ) {
  13      
  14  	function pagelines_add_admin_menus() {}
  15      
  16  	function pagelines_add_admin_menu() {
  17          global $_pagelines_account_hook;
  18          $_pagelines_account_hook = add_theme_page( PL_MAIN_DASH, __( 'DMS Dashboard', 'pagelines' ), 'edit_theme_options', PL_MAIN_DASH, 'pagelines_build_account_interface' );
  19      }
  20  }
  21  
  22  // Build option interface
  23  
  24  /**
  25   *
  26   * @TODO document
  27   *
  28   */
  29  function pagelines_build_option_interface(){
  30      pagelines_register_hook( 'pagelines_before_optionUI' );
  31      $args = array(
  32          'sanitize'         => 'pagelines_settings_callback',
  33      );
  34      $optionUI = new PageLinesOptionsUI( $args );
  35  }
  36  
  37  
  38  
  39  /**
  40   * Build Extension Interface
  41   * Will handle adding additional sections, plugins, child themes
  42   */
  43  function pagelines_build_templates_interface(){
  44  
  45      $args = array(
  46          'title'            => __( "Drag <span class='spamp'>&amp;</span> Drop Template Setup", 'pagelines' ),
  47          'settings'         => PAGELINES_TEMPLATES,
  48          'callback'        => 'templates_array',
  49          'basic_reset'    => true,
  50          'reset_cb'        => 'reset_templates_to_default',
  51          'show_save'        => false,
  52          'show_reset'    => false,
  53          'tabs'            => false
  54      );
  55  
  56      $optionUI = new PageLinesOptionsUI( $args );
  57  
  58  }
  59  
  60  
  61  /**
  62   * Build Extension Interface
  63   * Will handle adding additional sections, plugins, child themes
  64   */
  65  function pagelines_build_extension_interface(){
  66  
  67      $args = array(
  68          'title'            => __( 'The PageLines Store', 'pagelines' ),
  69          'settings'         => PAGELINES_EXTENSION,
  70          'callback'        => 'extension_array',
  71          'show_save'        => false,
  72          'show_reset'    => false,
  73          'fullform'        => false,
  74          'reset_store'    => true
  75      );
  76      $optionUI = new PageLinesOptionsUI( $args );
  77  }
  78  
  79  /**
  80   * Build Extension Interface
  81   * Will handle adding additional sections, plugins, child themes
  82   */
  83  function pagelines_build_account_interface(){
  84  
  85      global $account_control;
  86  
  87      $args = array(
  88          'title'            => __( 'PageLines Dashboard', 'pagelines' ),
  89          'settings'         => PAGELINES_ACCOUNT,
  90          'callback'        => array( $account_control, 'pagelines_account_array' ),
  91          'show_save'        => false,
  92          'show_reset'    => false,
  93          'fullform'        => false,
  94      );
  95      $optionUI = new PageLinesOptionsUI( $args );
  96  }
  97  
  98  
  99  /**
 100   * Build Meta Interface
 101   * Will handle meta for non-meta pages.. e.g. tags, categories
 102   */
 103  function pagelines_build_special(){
 104  
 105      $args = array(
 106          'title'            => __( 'Page Option Setup', 'pagelines' ),
 107          'settings'         => PAGELINES_SPECIAL,
 108          'callback'        => 'special_page_settings_array',
 109          'show_reset'    => false,
 110          'basic_reset'    => true
 111      );
 112      $optionUI = new PageLinesOptionsUI( $args );
 113  }
 114  
 115  /**
 116   * This is a necessary go-between to get our scripts and boxes loaded
 117   * on the theme settings page only, and not the rest of the admin
 118   */
 119  add_action( 'admin_menu', 'pagelines_theme_settings_init' );
 120  
 121  /**
 122   *
 123   * @TODO document
 124   *
 125   */
 126  function pagelines_theme_settings_init() {
 127      global $_pagelines_options_page_hook;
 128      global $_pagelines_ext_hook;
 129      global $_pagelines_special_hook;
 130      global $_pagelines_templates_hook;
 131      global $_pagelines_account_hook;
 132      global $_pagelines_dms_tools_hook;
 133  
 134      // Call only on PL pages
 135      add_action( "admin_print_scripts-{$_pagelines_options_page_hook}", 'pagelines_theme_settings_scripts' );
 136      add_action( "admin_print_scripts-{$_pagelines_ext_hook}", 'pagelines_theme_settings_scripts' );
 137      add_action( "admin_print_scripts-{$_pagelines_special_hook}", 'pagelines_theme_settings_scripts' );
 138      add_action( "admin_print_scripts-{$_pagelines_templates_hook}", 'pagelines_theme_settings_scripts' );
 139      add_action( "admin_print_scripts-{$_pagelines_account_hook}", 'pagelines_theme_settings_scripts' );
 140      add_action( "admin_print_scripts-{$_pagelines_dms_tools_hook}", 'pagelines_theme_settings_scripts' );
 141  
 142      // WordPress Page types
 143      add_action( 'load-post.php',  'pagelines_theme_settings_scripts' );
 144      add_action( 'load-post-new.php',  'pagelines_theme_settings_scripts' );
 145      add_action( 'load-user-edit.php',  'pagelines_theme_settings_scripts' );
 146      add_action( 'load-profile.php',  'pagelines_theme_settings_scripts' );
 147  }
 148  
 149  
 150  
 151  /**
 152   *
 153   * @TODO document
 154   *
 155   */
 156  function pagelines_theme_settings_scripts() {
 157  
 158      // Add Body Class
 159      add_filter( 'admin_body_class', 'pagelines_admin_body_class' );
 160  
 161      wp_enqueue_script( 'jquery-ajaxupload', PL_ADMIN_JS . '/jquery.ajaxupload.js', array( 'jquery' ), PL_CORE_VERSION );
 162      wp_enqueue_script( 'jquery-cookie', PL_ADMIN_JS . '/jquery.ckie.js', array( 'jquery' ), PL_CORE_VERSION );
 163      wp_enqueue_script( 'jquery-ui-core' );
 164      wp_enqueue_script( 'jquery-ui-tabs' );
 165      wp_enqueue_script( 'jquery-ui-dialog' );
 166      wp_enqueue_script( 'script-pagelines-settings', PL_ADMIN_JS . '/script.settings.js', array( 'jquery' ), PL_CORE_VERSION );
 167  
 168      wp_enqueue_script( 'jquery-ui-effects', PL_ADMIN_JS . '/jquery.effects.js', array( 'jquery' ), PL_CORE_VERSION ); // just has highlight effect
 169      wp_enqueue_script( 'jquery-ui-draggable' );
 170      wp_enqueue_script( 'jquery-ui-sortable' );
 171      wp_enqueue_script( 'script-pagelines-common', PL_ADMIN_JS . '/script.common.js', array( 'jquery' ), PL_CORE_VERSION );
 172  
 173  
 174      if(!pl_deprecate_v2()){
 175          wp_enqueue_script( 'jquery-layout', PL_ADMIN_JS . '/jquery.layout.js', array( 'jquery' ), PL_CORE_VERSION );
 176          wp_enqueue_script( 'thickbox' );
 177          wp_enqueue_style( 'thickbox' );
 178          // Color Picker
 179          wp_enqueue_script( 'colorpicker-js', PL_ADMIN_JS . '/colorpicker/js/colorpicker.js', array( 'jquery' ), PL_CORE_VERSION );
 180          wp_enqueue_style( 'colorpicker', PL_ADMIN_JS . '/colorpicker/css/colorpicker.css' );
 181  
 182          wp_enqueue_script( 'jquery-colorbox', PL_ADMIN_JS . '/colorbox/jquery.colorbox-min.js', array( 'jquery' ), PL_CORE_VERSION );
 183          wp_enqueue_style( 'colorbox', PL_ADMIN_JS . '/colorbox/colorbox.css' );
 184      }
 185      
 186      // Prettify
 187      wp_enqueue_script( 'codemirror', PL_ADMIN_JS . '/codemirror/codemirror.js', array( 'jquery' ), PL_CORE_VERSION );
 188      wp_enqueue_script( 'codemirror-css', PL_ADMIN_JS . '/codemirror/css/css.js', array( 'jquery' ), PL_CORE_VERSION );
 189      wp_enqueue_script( 'codemirror-less', PL_ADMIN_JS . '/codemirror/less/less.js', array( 'jquery' ), PL_CORE_VERSION );
 190      wp_enqueue_script( 'codemirror-js', PL_ADMIN_JS . '/codemirror/javascript/javascript.js', array( 'jquery' ), PL_CORE_VERSION );
 191      wp_enqueue_script( 'codemirror-xml', PL_ADMIN_JS . '/codemirror/xml/xml.js', array( 'jquery' ), PL_CORE_VERSION );
 192      wp_enqueue_script( 'codemirror-html', PL_ADMIN_JS . '/codemirror/htmlmixed/htmlmixed.js', array( 'jquery' ), PL_CORE_VERSION );
 193      wp_enqueue_style( 'codemirror', PL_ADMIN_JS . '/codemirror/codemirror.css' );
 194  
 195  
 196      $custom_css = array(
 197  
 198              'lineNumbers'    =>    true,
 199              'mode'    => 'text/x-less',
 200              'lineWrapping'    => true,
 201      );
 202  
 203      $headers = array(
 204  
 205              'lineNumbers'    =>    true,
 206              'mode'    => 'text/html',
 207              'lineWrapping'    => true,
 208      );
 209  
 210      wp_localize_script( 'script-pagelines-common', 'cm_customcss', apply_filters( 'pagelines_customcss_cm_options', $custom_css ) );
 211      wp_localize_script( 'script-pagelines-common', 'cm_headers', apply_filters( 'pagelines_headerscripts_cm_options', $headers ) );
 212  }
 213  
 214  add_action( 'admin_head', 'load_head' );
 215  
 216  /**
 217   *
 218   * @TODO document
 219   *
 220   */
 221  function load_head(){
 222  
 223      // Admin CSS
 224      printf( '<link rel="stylesheet" href="%s/admin.css?ver=%s" type="text/css" media="screen" />', PL_ADMIN_CSS, PL_CORE_VERSION );
 225  
 226  
 227  
 228      if( ploption( 'pagelines_favicon' ) )
 229          printf( '<link rel="shortcut icon" href="%s" type="image/x-icon" />', ploption( 'pagelines_favicon' ) );
 230  
 231      // Load on PageLines pages
 232      if( isset( $_GET['page'] ) && ( $_GET['page'] == 'pagelines' ) )
 233          include ( PL_ADMIN . '/admin.head.php' );
 234  
 235  }
 236  
 237  
 238  add_action( 'admin_init', 'pagelines_register_settings', 5 );
 239  
 240  /**
 241   *
 242   * @TODO document
 243   *
 244   */
 245  function pagelines_register_settings() {
 246  
 247  
 248      register_setting( PAGELINES_SETTINGS, PAGELINES_SETTINGS, 'pagelines_settings_callback' );
 249      register_setting( PAGELINES_SPECIAL, PAGELINES_SPECIAL );
 250      register_setting( PAGELINES_TEMPLATES, PAGELINES_TEMPLATES );
 251  
 252      /* Typography Options */
 253      $GLOBALS['pl_foundry'] = new PageLinesFoundry;
 254  
 255      /*
 256          Import/Exporting
 257      */
 258      pagelines_import_export();
 259  
 260      pagelines_process_reset_options();
 261  
 262      if ( !isset($_REQUEST['page'] ) || $_REQUEST['page'] != 'pagelines' )
 263          return;
 264  
 265      global $new_default_settings;
 266  
 267      /*
 268          New Default Options in Child Themes
 269      */
 270      if( !isset( $_GET['newoptions'] ) && pagelines_activate_or_reset() && !empty($new_default_settings ) ){
 271  
 272          $type = sprintf( '&%s=true', pagelines_activate_or_reset() );
 273  
 274          foreach( $new_default_settings as $key => $set )
 275              plupop( $set['key'], $set['value'], array( 'parent' => $set['parent'], 'subkey' => $set['subkey'], 'setting' => $set['setting'] ) );
 276  
 277          wp_redirect( admin_url( PL_SETTINGS_URL.'&newoptions=true'.$type ) );
 278      }
 279  
 280      /*
 281          Handle Reset of Options
 282      */
 283      if ( ploption( 'reset') ) {
 284  
 285          update_option( PAGELINES_SETTINGS, pagelines_settings_defaults() );
 286  
 287          global $extension_control;
 288  
 289          $extension_control->flush_caches();
 290  
 291          wp_redirect( admin_url( PL_SETTINGS_URL.'&reset=true' ) );
 292  
 293          exit;
 294  
 295      }
 296  
 297  }
 298  
 299  // Add Debug tab to main menu.
 300  
 301  
 302  /**
 303   *
 304   * @TODO document
 305   *
 306   */
 307  function pagelines_enable_debug( $option_array ) {
 308  
 309      $debug = new PageLinesDebug;
 310       $debug_option_array['debug'] = array(
 311           'debug_info' => array(
 312           'type'        => 'text_content',
 313           'layout'    => 'full',
 314           'exp'        => $debug->debug_info_template()
 315           ) );
 316       return array_merge( $option_array, $debug_option_array );
 317  }
 318  
 319  
 320  /**
 321   *
 322   * @TODO document
 323   *
 324   */
 325  function pagelines_admin_confirms(){
 326  
 327      $confirms = array();
 328  
 329      if( isset( $_GET['settings-updated'] ) )
 330          $confirms[]['text'] = sprintf( __( "%s Settings Saved. &nbsp;<a class='sh_preview' href='%s/' target='_blank'>View Your Site &rarr;</a>", 'pagelines' ), PL_NICECHILDTHEMENAME, home_url() );
 331      if( isset($_GET['pageaction']) ){
 332  
 333          if( $_GET['pageaction']=='activated' && !isset($_GET['settings-updated']) ){
 334              $confirms['activated']['text'] = sprintf( __( 'Congratulations! %s Has Been Successfully Activated.', 'pagelines' ), PL_NICECHILDTHEMENAME );
 335              $confirms['activated']['class'] = 'activated';
 336          }
 337  
 338          elseif( $_GET['pageaction']=='import' && isset($_GET['imported'] )){
 339              $confirms['settings-import']['text'] = __( 'Congratulations! New settings have been successfully imported.', 'pagelines' );
 340              $confirms['settings-import']['class'] = "settings-import";
 341          }
 342  
 343          elseif( $_GET['pageaction']=='import' && isset($_GET['error']) && !isset($_GET['settings-updated']) ){
 344              $confirms['settings-import-error']['text'] = __( 'There was an error with import. Please make sure you are using the correct file.', 'pagelines' );
 345          }
 346  
 347      }
 348  
 349      if( isset( $_GET['reset'] ) ){
 350  
 351          if( isset( $_GET['opt_id'] ) && $_GET['opt_id'] == 'resettemplates' )
 352              $confirms['reset']['text'] = __( 'Template Configuration Restored To Default.', 'pagelines' );
 353  
 354          elseif( isset($_GET['opt_id'] ) && $_GET['opt_id'] == 'resetlayout' )
 355              $confirms['reset']['text'] = __( 'Layout Dimensions Restored To Default.', 'pagelines' );
 356  
 357          else
 358              $confirms['reset']['text'] = __( 'Settings Restored To Default.', 'pagelines' );
 359  
 360      }
 361      if ( isset( $_GET['plinfo'] ) )
 362          $confirms[]['text'] = __( 'Launchpad settings saved.', 'pagelines' );
 363  
 364      if ( isset( $_GET['extend_upload'] ) )
 365          $confirms[]['text'] = sprintf( __( 'Successfully uploaded your %s', 'pagelines' ), $_GET['extend_upload'] );
 366  
 367      if ( isset( $_GET['extend_text'] ) )
 368          switch( $_GET['extend_text'] ) {
 369  
 370              case 'section_delete':
 371                  $confirms[]['text'] = __( 'Section was deleted.', 'pagelines' );
 372              break;
 373  
 374              case 'section_install':
 375                  $confirms[]['text'] = __( 'Section was installed.', 'pagelines' );
 376              break;
 377  
 378              case 'section_upgrade':
 379                  $confirms[]['text'] = __( 'Section was upgraded.', 'pagelines' );
 380              break;
 381  
 382              case 'plugin_install':
 383                  $confirms[]['text'] = __( 'Plugin was installed.', 'pagelines' );
 384              break;
 385  
 386              case 'plugin_delete':
 387                  $confirms[]['text'] = __( 'Plugin was deleted.', 'pagelines' );
 388              break;
 389  
 390              case 'plugin_upgrade':
 391                  $confirms[]['text'] = __( 'Plugin was upgraded.', 'pagelines' );
 392              break;
 393  
 394              case 'theme_install':
 395                  $confirms[]['text'] = __( 'Theme installed.', 'pagelines' );
 396              break;
 397  
 398              case 'theme_upgrade':
 399                  $confirms[]['text'] = __( 'Theme upgraded.', 'pagelines' );
 400              break;
 401              case 'theme_delete';
 402                  $confirms[]['text'] = __( 'Theme deleted.', 'pagelines' );
 403              break;
 404  
 405          }
 406          if ( ! empty( $confirms ) )
 407              do_action( 'extend_flush' );
 408  
 409      return apply_filters( 'pagelines_admin_confirms', $confirms );
 410  
 411   }
 412  
 413  
 414  
 415  /**
 416   *
 417   * @TODO document
 418   *
 419   */
 420  function pagelines_draw_confirms(){
 421  
 422      $confirms = pagelines_admin_confirms();
 423      $save_text = sprintf( '%s Settings Saved. &nbsp;<a class="btag" href="%s/" target="_blank">View Your Site &rarr;</a>', PL_NICECHILDTHEMENAME, home_url());
 424      printf( '<div id="message" class="confirmation slideup_message fade c_ajax"><div class="confirmation-pad c_response">%s</div></div>', $save_text);
 425  
 426      if( !empty( $confirms ) ){
 427          foreach ( $confirms as $c ){
 428  
 429              $class = ( isset($c['class'] ) ) ? $c['class'] : null;
 430  
 431              printf( '<div id="message" class="confirmation slideup_message fade %s"><div class="confirmation-pad">%s</div></div>', $class, $c['text'] );
 432          }
 433      }
 434  
 435  }
 436  
 437  
 438  /**
 439   *
 440   * @TODO document
 441   *
 442   */
 443  function pagelines_admin_errors(){
 444  
 445      $errors = array();
 446  
 447      if( ie_version() && ie_version() < 8){
 448  
 449          $errors['ie']['title'] = sprintf( __( 'You are using Internet Explorer version: %s', 'pagelines' ), ie_version() );
 450          $errors['ie']['text'] = __( "Advanced options don't support Internet Explorer version 7 or lower. Please switch to a standards based browser that will allow you to easily configure your site (e.g. Firefox, Chrome, Safari, even IE8 or better would work).", 'pagelines' );
 451  
 452      }
 453  
 454      if( floatval( phpversion() ) < 5.0){
 455          $errors['php']['title'] = sprintf( __( 'You are using PHP version %s', 'pagelines' ), phpversion() );
 456          $errors['php']['text'] = __( 'Version 5 or higher is required for this theme to work correctly. Please check with your host about upgrading to a newer version.', 'pagelines' );
 457      }
 458      if ( isset( $_GET['extend_error'] ) ) {
 459          $errors['extend']['title'] = __( 'Extension problem found', 'pagelines' );
 460  
 461          switch( $_GET['extend_error'] ) {
 462  
 463              case 'blank':
 464                  $errors['extend']['text'] = __( 'No file selected!', 'pagelines' );
 465              break;
 466  
 467              case 'filename':
 468                  $errors['extend']['text'] = __( 'The file did not appear to be a PageLines section.', 'pagelines' );
 469              break;
 470  
 471              default:
 472                  $errors['extend']['text'] = sprintf( __( 'Unknown error: %s', 'pagelines' ), $_GET['extend_error'] );
 473              break;
 474          }
 475  
 476      }
 477      return apply_filters( 'pagelines_admin_notifications', $errors );
 478  
 479  }
 480  
 481  
 482  /**
 483   *
 484   * @TODO document
 485   *
 486   */
 487  function pagelines_error_messages(){
 488  
 489      $errors = pagelines_admin_errors();
 490      if( !empty( $errors ) ):
 491          foreach ( $errors as $e ): ?>
 492      <div id="message" class="confirmation plerror fade">
 493          <div class="confirmation-pad">
 494                  <div class="confirmation-head">
 495                      <?php echo $e['title'];?>
 496                  </div>
 497                  <div class="confirmation-subtext">
 498                      <?php echo $e['text'];?>
 499                  </div>
 500          </div>
 501      </div>
 502  
 503  <?php     endforeach;
 504      endif;
 505  }
 506  
 507  $custom_attach = new PLImageUploader();
 508  
 509  class PLImageUploader{
 510  	function __construct() {
 511          if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'pl-custom-attach' ) {
 512  
 513              $this->option_id = (isset( $_REQUEST['oid'] )) ? $_REQUEST['oid'] : '';
 514  
 515              add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 15, 2 );
 516              add_filter( 'media_upload_tabs', array( $this, 'filter_upload_tabs' ) );
 517              add_filter( 'media_upload_mime_type_links', '__return_empty_array' );
 518              add_action( 'media_upload_library' , array( $this, 'the_js' ), 15 );
 519          }
 520      }
 521  
 522  
 523  	function the_js(){
 524          ?>
 525  
 526          <script type="text/javascript">
 527          jQuery(document).ready(function(){
 528              jQuery('.pl-frame-button').on('click', function(){
 529  
 530                  var optID = '#'+jQuery(this).data('selector')
 531                  var previewSel = '.pre_'+jQuery(this).data('selector')
 532                  var imgURL = jQuery(this).data('imgurl')
 533  
 534                  jQuery(optID, top.document).val(imgURL)
 535                  jQuery(previewSel, top.document).attr('src', imgURL)
 536                  parent.eval('tb_remove()')
 537              });
 538          });
 539          </script>
 540          </script>
 541  
 542          <?php
 543      }
 544  
 545      /**
 546       * Replace default attachment actions with "Set as header" link.
 547       *
 548       * @since 3.4.0
 549       */
 550  	function attachment_fields_to_edit( $form_fields, $post ) {
 551  
 552          $form_fields = array();
 553  
 554          $attach_id = $post->ID;
 555  
 556          $image_url = wp_get_attachment_url($attach_id);
 557  
 558          $form_fields['buttons'] = array(
 559              'tr' => sprintf(
 560                          '<tr class="submit"><td></td>
 561                              <td>
 562                              <span class="pl-frame-button  admin-blue button" title="3212" data-selector="%s" data-imgurl="%s">%s</span>
 563                              </td></tr>',
 564                              $this->option_id,
 565                              $image_url,
 566                              __( 'Select This Image For Option', 'pagelines' )
 567                      )
 568          );
 569          $form_fields['context'] = array(
 570              'input' => 'hidden',
 571              'value' => 'pl-custom-attach'
 572          );
 573  
 574          return $form_fields;
 575      }
 576  
 577      /**
 578       * Leave only "Media Library" tab in the uploader window.
 579       *
 580       * @since 3.4.0
 581       */
 582  	function filter_upload_tabs() {
 583          return array( 'library' => __('Media Library', 'pagelines') );
 584      }
 585  }


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