Changeset 894373
- Timestamp:
- 04/16/2014 03:58:23 PM (12 years ago)
- Location:
- flux/trunk
- Files:
-
- 2 edited
-
flux.php (modified) (2 diffs)
-
plugin.php (modified) (50 diffs)
Legend:
- Unmodified
- Added
- Removed
-
flux/trunk/flux.php
r755031 r894373 8 8 * Author URI: http://github.com/onemanonelaptop 9 9 */ 10 10 11 11 /* Copyright 2011 Rob Holmes ( email: rob@onemanonelaptop.com ) 12 12 … … 25 25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 26 26 */ 27 27 28 28 add_action( 'plugins_loaded', 'flux' ); 29 29 /** 30 30 * Runs on plugins_loaded action and defines the required classes 31 31 * after the classes are defined the flux action is fired, this is where child 32 * plugins define their functionality 32 * plugins define their functionality 33 33 */ 34 34 if (!function_exists('flux')) { -
flux/trunk/plugin.php
r755030 r894373 20 20 /** 21 21 * The Plugin Class 22 */ 22 */ 23 23 class Plugin { 24 24 … … 74 74 75 75 var $debug_messages = array(); 76 76 77 77 /** 78 78 * Constructor … … 121 121 122 122 // Save the custom post fields with the post data 123 add_action('save_post', array(&$this,'diy_save_post')); 123 add_action('save_post', array(&$this,'diy_save_post')); 124 124 125 125 // Register the scripts and styles needed for metaboxes and fields … … 132 132 133 133 // Setup the ajax callback for autocomplete widget 134 add_action('wp_ajax_suggest_action_' . $this->slug, array(&$this,'diy_suggest_posts_callback')); 135 add_action('wp_ajax_attachments_action', array(&$this,'diy_suggest_attachments')); 136 add_action('wp_ajax_save_attachment_action', array(&$this,'diy_save_attachment')); 134 add_action('wp_ajax_suggest_action_' . $this->slug, array(&$this,'diy_suggest_posts_callback')); 135 add_action('wp_ajax_attachments_action', array(&$this,'diy_suggest_attachments')); 136 add_action('wp_ajax_save_attachment_action', array(&$this,'diy_save_attachment')); 137 137 138 138 // add_action('wp_ajax_suggest_action', array(&$this,'diy_suggest_users_callback')); … … 142 142 } // end function 143 143 144 145 144 145 146 146 /* 147 147 * Usage for a custom post type named 'movies': … … 163 163 } 164 164 165 165 166 166 /** 167 167 * Validate callback when saving a plugins options 168 * 168 * 169 169 * @param array $data The form post data 170 170 * @return array The validated data … … 194 194 if (isset($metabox['#post_types']) && is_array($metabox['#post_types'])) { 195 195 foreach ($metabox['#post_types'] as $post_type) { 196 // Add the metabox 197 add_meta_box( 198 $key, 196 // Add the metabox 197 add_meta_box( 198 $key, 199 199 $metabox['#title'], 200 200 array(&$this,'render_metabox_fields'), 201 $post_type, 201 $post_type, 202 202 $metabox['#context'], 203 'core', 203 'core', 204 204 $key 205 205 ); 206 } 206 } 207 207 } // end if 208 208 … … 250 250 */ 251 251 function render_metabox_fields($post,$args) { 252 252 253 253 // sotre the metabox id (array key) 254 254 $key = $args['args']; … … 264 264 $this->apply_defaults($values); 265 265 } 266 266 267 267 // print any visibility options form the metabox definition 268 268 print $this->metabox_visibility($key); 269 269 // print any positioning options form the metabox definition 270 270 print $this->metabox_positioning($key); 271 271 272 272 // retrieve the form 273 273 $newform = new Form($this->forms[$key]); … … 279 279 * Called when a settings filed does not yet exist for a page's metabox 280 280 * Use the form definition to biuld an array of values and save the 281 * setting 281 * setting 282 282 */ 283 283 function apply_defaults(&$values) { 284 284 285 // go through each element recurisvely 285 // go through each element recurisvely 286 286 foreach($values as $key => $value) { 287 287 288 288 // special treatement for multi groups 289 289 if ($key == '#type') { … … 299 299 } // if 300 300 } // foreach 301 301 302 302 } // if 303 303 } // if … … 312 312 unset($values['#default_value']); 313 313 // $values = $save; 314 315 314 315 316 316 } else { 317 317 318 318 unset($values[$key]); 319 319 } 320 320 321 321 } 322 322 return $values; 323 323 } // function 324 324 325 325 /** 326 326 * Allow metaboxes to be fixed in certain positions … … 343 343 344 344 /** 345 * Insert a div into a metabox to indiate its visibility settings 345 * Insert a div into a metabox to indiate its visibility settings 346 346 * Used by jquery to disable/enable visiblity settings 347 347 * @param string $id Array key of the metabox 348 * @return string 348 * @return string 349 349 */ 350 350 function metabox_visibility($id) { … … 363 363 * Recursively create options pages from the pages array 364 364 * 365 * @since 0.0.9366 * @access public365 * @since 0.0.9 366 * @access public 367 367 */ 368 368 public function diy_register_pages() { … … 378 378 global $admin_page_hooks; 379 379 foreach ($elements as $key => $page) { 380 381 if (is_array( $page) && isset( $page['#type'])) { 382 383 384 380 385 if ($page['#type'] == 'menu') { 381 386 $elements[$key]['#hook'] = add_menu_page( __($page['#title']), __($page['#link_text']), 'manage_options', $key, array(&$this,'diy_render_options_page' )); 382 383 384 387 388 389 385 390 } 386 391 387 392 // Add theme pages 388 393 if ($page['#type'] == 'theme') { … … 398 403 if ($page['#type'] == 'options') { 399 404 // Set the callback 400 if (empty($elements[$key]['#callback'])) { 405 if (empty($elements[$key]['#callback'])) { 401 406 $elements[$key]['#callback'] = 'diy_render_options_page'; 402 407 } 403 if ($elements['#parent']) { 408 if ($elements['#parent']) { 404 409 // allow a link destination, custom callback 405 if (isset($elements[$key]['#destination'])) { 410 if (isset($elements[$key]['#destination'])) { 406 411 407 412 $elements[$key]['#hook'] = add_submenu_page( $elements['#parent'], __($page['#title']), __($page['#link_text']), 'manage_options', $elements[$key]['#destination'] ,'' ); 408 413 } else { 409 414 $elements[$key]['#hook'] = add_submenu_page( $elements['#parent'], __($page['#title']), __($page['#link_text']), 'manage_options', $key, array($this, 'diy_render_options_page') ); 410 411 415 416 412 417 } 413 418 } else { … … 422 427 423 428 } 429 } 424 430 425 431 // recursively register any nested pages … … 431 437 } 432 438 439 433 440 } // end foreach 434 441 } // function … … 438 445 * Runs only on an options page load hook and enables the scripts needed for metaboxes 439 446 * 440 * @since 0.0.1441 * @access public447 * @since 0.0.1 448 * @access public 442 449 */ 443 450 function diy_enqueue_settings_page_scripts() { … … 450 457 * Add a settings link to the plugin list page 451 458 * 452 * @since 0.0.1453 * @param string $file the filename of the plugin currently being rendered on the installed plugins page454 * @param array $links an array of the current registered links in html format455 * @return array456 * @access public459 * @since 0.0.1 460 * @param string $file the filename of the plugin currently being rendered on the installed plugins page 461 * @param array $links an array of the current registered links in html format 462 * @return array 463 * @access public 457 464 */ 458 465 function diy_add_settings_link($links, $file) { … … 470 477 * On the plugin page make sure there are two columns 471 478 * 472 * @since 0.0.1473 * @access public479 * @since 0.0.1 480 * @access public 474 481 * @param int $columns 475 482 * @param string $screen … … 478 485 function diy_settings_page_columns($columns, $screen) { 479 486 global $current_screen; 480 487 481 488 if ($screen == $current_screen->id) { 482 489 $columns[$screen] = 2; … … 489 496 * Create the options page form 490 497 * 491 * @since 0.0.1492 * @access public498 * @since 0.0.1 499 * @access public 493 500 */ 494 501 public function diy_render_options_page() { … … 498 505 if (isset($this->pages[$current_screen->parent_file]) && is_array($this->pages[$current_screen->parent_file][$current_page])) { 499 506 $page = $this->pages[$current_screen->parent_file][$current_page]; 500 507 501 508 } else { 502 509 $page = $this->pages[$current_page]; 503 504 } 505 506 510 511 } 512 513 507 514 // @todo escape 508 515 … … 511 518 ?> 512 519 <div class="wrap"> 513 <?php 520 <?php 514 521 // Output a custom settings page icon 515 522 if (!empty($page['#icon'])) { … … 528 535 <div id="poststuff" class="metabox-holder<?php echo 2 == $screen_layout_columns ? ' has-right-sidebar' : ''; ?>"> 529 536 <div id="side-info-column" class="inner-sidebar"> 530 <?php 531 537 <?php 538 532 539 do_meta_boxes( $page['#hook'], 'side', $data = array()); ?> 533 540 </div> 534 541 <div id="post-body" class="has-sidebar"> 535 542 <div id="post-body-content" class="has-sidebar-content"> 536 <?php 543 <?php 537 544 do_meta_boxes( $page['#hook'], 'normal', $data = array()); ?> 538 545 <br/> 539 546 <p> 540 <input type="submit" value="Save Changes" class="button-primary" name="Submit"/> 547 <input type="submit" value="Save Changes" class="button-primary" name="Submit"/> 541 548 </p> 542 549 </div> 543 550 </div> 544 <br class="clear"/> 545 </div> 551 <br class="clear"/> 552 </div> 546 553 </form> 547 554 </div> … … 554 561 * Register the admin scripts 555 562 * 556 * @since 0.0.1557 * @access public563 * @since 0.0.1 564 * @access public 558 565 */ 559 566 function diy_scripts_and_styles() { … … 566 573 // if admin.js exists in the child plugin include it 567 574 if (file_exists($this->diy_path . 'admin.js')) { 568 575 569 576 wp_register_script('diy' ,$this->diy_url . 'admin.js', array('jquery','jquery-ui-sortable','jquery-ui-sortable','media-upload','thickbox','editor')); 570 577 } … … 572 579 // if admin.css exists in the child plugin include it 573 580 if (file_exists($this->diy_path . 'admin.css')) { 574 581 575 582 wp_register_style('diy' ,$this->diy_url . 'admin.css'); 576 583 } … … 591 598 // only load the google map if we have used one 592 599 wp_register_script('gmap','http://maps.google.com/maps/api/js?sensor=false'); 593 594 600 601 595 602 // Add custom scripts and styles to the plugin/theme page only 596 603 add_action('admin_print_scripts-widgets.php', array(&$this, 'diy_admin_scripts')); 597 604 add_action('admin_print_styles-widgets.php', array(&$this, 'diy_admin_styles')); 598 605 599 606 600 607 // Add custom scripts and styles to the post editor pages 601 608 add_action('admin_print_scripts-post.php', array(&$this, 'diy_admin_scripts')); 602 609 add_action('admin_print_scripts-post-new.php',array(&$this, 'diy_admin_scripts')); 603 610 add_action('admin_print_styles-post.php', array(&$this, 'diy_admin_styles')); 604 add_action('admin_print_styles-post-new.php',array(&$this, 'diy_admin_styles')); 611 add_action('admin_print_styles-post-new.php',array(&$this, 'diy_admin_styles')); 605 612 606 613 } // function … … 609 616 * Add custom styles to this plugins options page only 610 617 * 611 * @since 0.0.1612 * @access public618 * @since 0.0.1 619 * @access public 613 620 */ 614 621 function diy_admin_styles() { … … 624 631 // Allow cropping 625 632 wp_enqueue_script('jcrop'); 626 633 627 634 } // function 628 635 … … 630 637 * Add scripts globally to all post.php and post-new.php admin screens 631 638 * 632 * @since 0.0.1633 * @access public639 * @since 0.0.1 640 * @access public 634 641 */ 635 642 function diy_admin_scripts() { … … 637 644 wp_enqueue_script('diy'); 638 645 // Color picker 639 wp_enqueue_script('farbtastic'); 646 wp_enqueue_script('farbtastic'); 640 647 // Allow Jquery Chosen 641 648 wp_enqueue_script('suggest'); … … 646 653 } // function 647 654 648 655 649 656 /** 650 657 * Ajax callback function to return list of attachments … … 652 659 * @since 0.0.8 653 660 * @access public 654 */ 661 */ 655 662 function diy_save_attachment() { 656 663 // If the upload field has a file in it … … 668 675 669 676 // Options array for the wp_handle_upload function. 'test_upload' => false 670 $upload_overrides = array( 'test_form' => false ); 677 $upload_overrides = array( 'test_form' => false ); 671 678 672 679 // Handle the upload using WP's wp_handle_upload function. Takes the posted file and an options array … … 731 738 } // function 732 739 733 740 734 741 function diy_suggest_attachments() { 735 742 $args = array( … … 738 745 ); 739 746 740 747 741 748 742 749 $the_query = new WP_Query($args); … … 747 754 endwhile; 748 755 } 749 756 750 757 751 758 /** … … 755 762 * @access public 756 763 * @todo split this out into many functions for each type of suggestion i.e. users by role, attachments by extension 757 */ 764 */ 758 765 function diy_suggest_posts_callback() { 759 766 global $wpdb; 760 767 761 768 $group = $wpdb->escape($_GET['group']); 762 $field = $wpdb->escape($_GET['field']); 769 $field = $wpdb->escape($_GET['field']); 763 770 $in = $wpdb->escape($_GET['q']); 764 771 … … 775 782 776 783 $custom_args = $this->forms; 777 778 779 784 785 786 780 787 foreach ($parts as $part) { 781 788 if (!is_numeric($part)) { 782 789 $custom_args = $custom_args[$part]; 783 790 } 784 791 785 792 } 786 793 $custom_args = $custom_args['#wp_query']; … … 824 831 * Modify the query WHERE clause when performing a suggest ajax request 825 832 * 826 * @since 0.0.2827 * @access public828 */ 833 * @since 0.0.2 834 * @access public 835 */ 829 836 function diy_modify_posts_where( $where, &$wp_query ) { 830 837 global $wpdb; … … 841 848 * @since 0.0.8 842 849 * @access public 843 */ 850 */ 844 851 function diy_modify_posts_where_url( $where, &$wp_query ) { 845 852 global $wpdb; … … 852 859 853 860 854 861 855 862 856 863 /** 857 864 * Save the post meta box field data 858 865 * 859 * @since 0.0.1860 * @access public866 * @since 0.0.1 867 * @access public 861 868 * @param string $post_id The post id we are saving 862 */ 869 */ 863 870 function diy_save_post( $post_id ) { 864 871 global $post, $new_meta_boxes; … … 952 959 /** 953 960 * Never actually gets called as render_metabox_fields handles it 954 */ 961 */ 955 962 function settings_field_callback($args) { } // end function 956 963 … … 962 969 return; 963 970 } 964 // go through each element recurisvely 971 // go through each element recurisvely 965 972 foreach($values as $key => $value) { 966 973 // if it is an array then carry on recursivley 967 if (is_array($values[$key])) { 968 self::suggest_fix($values[$key]); 969 } else { 974 if (is_array($values[$key])) { 975 self::suggest_fix($values[$key]); 976 } else { 970 977 // if the [# string is found in the data 971 978 if (strlen(strstr($values[$key],'[#'))>0) { 972 // extract it [# ] 979 // extract it [# ] 973 980 preg_match('/.*\[#(.*)\]/', $values[$key], $matches); 974 981 $values[$key] = $matches[1]; … … 982 989 // if the [* string is found in the data 983 990 if (strlen(strstr($values[$key],'[*'))>0) { 984 // extract it [* ] 991 // extract it [* ] 985 992 preg_match('/.*\[\*(.*)\]/', $values[$key], $matches); 986 993 $values[$key] = $matches[1]; … … 997 1004 /** 998 1005 * Save the forms array 999 * @param array $forms 1006 * @param array $forms 1000 1007 */ 1001 1008 function forms($forms) { … … 1006 1013 /** 1007 1014 * Save the pages array 1008 * @param array $pages 1015 * @param array $pages 1009 1016 */ 1010 1017 function pages($pages) {
Note: See TracChangeset
for help on using the changeset viewer.