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