-
+ E7DDA6B7A7EF1274B63301166F469F16BDC8EB8D1B6DCC6A67A8B0F1F6BF32261EBE1AD9B7582E811430EB62FEA9F949A26EF941D15E7DC525568FB4EDEB41B3
mp-wp/wp-includes/class.wp-dependencies.php
(0 . 0)(1 . 209)
81532 <?php
81533 /**
81534 * BackPress Scripts enqueue.
81535 *
81536 * These classes were refactored from the WordPress WP_Scripts and WordPress
81537 * script enqueue API.
81538 *
81539 * @package BackPress
81540 * @since r74
81541 */
81542
81543 /**
81544 * BackPress enqueued dependiences class.
81545 *
81546 * @package BackPress
81547 * @uses _WP_Dependency
81548 * @since r74
81549 */
81550 class WP_Dependencies {
81551 var $registered = array();
81552 var $queue = array();
81553 var $to_do = array();
81554 var $done = array();
81555 var $args = array();
81556
81557 function WP_Dependencies() {
81558 $args = func_get_args();
81559 call_user_func_array( array(&$this, '__construct'), $args );
81560 }
81561
81562 function __construct() {}
81563
81564 /**
81565 * Do the dependencies
81566 *
81567 * Process the items passed to it or the queue. Processes all dependencies.
81568 *
81569 * @param mixed handles (optional) items to be processed. (void) processes queue, (string) process that item, (array of strings) process those items
81570 * @return array Items that have been processed
81571 */
81572 function do_items( $handles = false ) {
81573 // Print the queue if nothing is passed. If a string is passed, print that script. If an array is passed, print those scripts.
81574 $handles = false === $handles ? $this->queue : (array) $handles;
81575 $this->all_deps( $handles );
81576
81577 foreach( $this->to_do as $handle ) {
81578 if ( !in_array($handle, $this->done) && isset($this->registered[$handle]) ) {
81579 if ( $this->registered[$handle]->src ) { // Else it defines a group.
81580 $this->do_item( $handle );
81581 }
81582 $this->done[] = $handle;
81583 }
81584 }
81585
81586 $this->to_do = array();
81587 return $this->done;
81588 }
81589
81590 function do_item( $handle ) {
81591 return isset($this->registered[$handle]);
81592 }
81593
81594 /**
81595 * Determines dependencies
81596 *
81597 * Recursively builds array of items to process taking dependencies into account. Does NOT catch infinite loops.
81598 *
81599
81600 * @param mixed handles Accepts (string) dep name or (array of strings) dep names
81601 * @param bool recursion Used internally when function calls itself
81602 */
81603 function all_deps( $handles, $recursion = false ) {
81604 if ( !$handles = (array) $handles )
81605 return false;
81606
81607 foreach ( $handles as $handle ) {
81608 $handle = explode('?', $handle);
81609 if ( isset($handle[1]) )
81610 $this->args[$handle[0]] = $handle[1];
81611 $handle = $handle[0];
81612
81613 if ( isset($this->to_do[$handle]) ) // Already grobbed it and its deps
81614 continue;
81615
81616 $keep_going = true;
81617 if ( !isset($this->registered[$handle]) )
81618 $keep_going = false; // Script doesn't exist
81619 elseif ( $this->registered[$handle]->deps && array_diff($this->registered[$handle]->deps, array_keys($this->registered)) )
81620 $keep_going = false; // Script requires deps which don't exist (not a necessary check. efficiency?)
81621 elseif ( $this->registered[$handle]->deps && !$this->all_deps( $this->registered[$handle]->deps, true ) )
81622 $keep_going = false; // Script requires deps which don't exist
81623
81624 if ( !$keep_going ) { // Either script or its deps don't exist.
81625 if ( $recursion )
81626 return false; // Abort this branch.
81627 else
81628 continue; // We're at the top level. Move on to the next one.
81629 }
81630
81631 $this->to_do[$handle] = true;
81632 }
81633
81634 if ( !$recursion ) // at the end
81635 $this->to_do = array_keys( $this->to_do );
81636 return true;
81637 }
81638
81639 /**
81640 * Adds item
81641 *
81642 * Adds the item only if no item of that name already exists
81643 *
81644 * @param string handle Script name
81645 * @param string src Script url
81646 * @param array deps (optional) Array of script names on which this script depends
81647 * @param string ver (optional) Script version (used for cache busting)
81648 * @return array Hierarchical array of dependencies
81649 */
81650 function add( $handle, $src, $deps = array(), $ver = false, $args = null ) {
81651 if ( isset($this->registered[$handle]) )
81652 return false;
81653 $this->registered[$handle] = new _WP_Dependency( $handle, $src, $deps, $ver, $args );
81654 return true;
81655 }
81656
81657 /**
81658 * Adds extra data
81659 *
81660 * Adds data only if script has already been added
81661 *
81662 * @param string handle Script name
81663 * @param string data_name Name of object in which to store extra data
81664 * @param array data Array of extra data
81665 * @return bool success
81666 */
81667 function add_data( $handle, $data_name, $data ) {
81668 if ( !isset($this->registered[$handle]) )
81669 return false;
81670 return $this->registered[$handle]->add_data( $data_name, $data );
81671 }
81672
81673 function remove( $handles ) {
81674 foreach ( (array) $handles as $handle )
81675 unset($this->registered[$handle]);
81676 }
81677
81678 function enqueue( $handles ) {
81679 foreach ( (array) $handles as $handle ) {
81680 $handle = explode('?', $handle);
81681 if ( !in_array($handle[0], $this->queue) && isset($this->registered[$handle[0]]) ) {
81682 $this->queue[] = $handle[0];
81683 if ( isset($handle[1]) )
81684 $this->args[$handle[0]] = $handle[1];
81685 }
81686 }
81687 }
81688
81689 function dequeue( $handles ) {
81690 foreach ( (array) $handles as $handle )
81691 unset( $this->queue[$handle] );
81692 }
81693
81694 function query( $handle, $list = 'registered' ) { // registered, queue, done, to_do
81695 switch ( $list ) :
81696 case 'registered':
81697 case 'scripts': // back compat
81698 if ( isset($this->registered[$handle]) )
81699 return $this->registered[$handle];
81700 break;
81701 case 'to_print': // back compat
81702 case 'printed': // back compat
81703 if ( 'to_print' == $list )
81704 $list = 'to_do';
81705 else
81706 $list = 'printed';
81707 default:
81708 if ( in_array($handle, $this->$list) )
81709 return true;
81710 break;
81711 endswitch;
81712 return false;
81713 }
81714
81715 }
81716
81717 class _WP_Dependency {
81718 var $handle;
81719 var $src;
81720 var $deps = array();
81721 var $ver = false;
81722 var $args = null;
81723
81724 var $extra = array();
81725
81726 function _WP_Dependency() {
81727 @list($this->handle, $this->src, $this->deps, $this->ver, $this->args) = func_get_args();
81728 if ( !is_array($this->deps) )
81729 $this->deps = array();
81730 if ( !$this->ver )
81731 $this->ver = false;
81732 }
81733
81734 function add_data( $name, $data ) {
81735 if ( !is_scalar($name) )
81736 return false;
81737 $this->extra[$name] = $data;
81738 return true;
81739 }
81740 }