-
+ 254517B0604BE63728FE88B3965F8DA94140AE82CF34E1B22324506E4883F6937B9C07D9C9CE18A5BAC7DB55F4D72C787DFF30D486A7CE08E1D478B1011E4B05
mp-wp/wp-admin/includes/widgets.php
(0 . 0)(1 . 340)
47580 <?php
47581 /**
47582 * WordPress Widgets Administration API
47583 *
47584 * @package WordPress
47585 * @subpackage Administration
47586 */
47587
47588 /**
47589 * Display list of widgets, either all or matching search.
47590 *
47591 * The search parameter are search terms separated by spaces.
47592 *
47593 * @since unknown
47594 *
47595 * @param string $show Optional, default is all. What to display, can be 'all', 'unused', or 'used'.
47596 * @param string $_search Optional. Search for widgets. Should be unsanitized.
47597 */
47598 function wp_list_widgets( $show = 'all', $_search = false ) {
47599 global $wp_registered_widgets, $sidebars_widgets, $wp_registered_widget_controls;
47600 if ( $_search ) {
47601 // sanitize
47602 $search = preg_replace( '/[^\w\s]/', '', $_search );
47603 // array of terms
47604 $search_terms = preg_split( '/[\s]/', $search, -1, PREG_SPLIT_NO_EMPTY );
47605 } else {
47606 $search_terms = array();
47607 }
47608
47609 if ( !in_array( $show, array( 'all', 'unused', 'used' ) ) )
47610 $show = 'all';
47611 ?>
47612
47613 <ul id='widget-list'>
47614 <?php
47615 $no_widgets_shown = true;
47616 $already_shown = array();
47617 foreach ( $wp_registered_widgets as $name => $widget ) :
47618 if ( 'all' == $show && in_array( $widget['callback'], $already_shown ) ) // We already showed this multi-widget
47619 continue;
47620
47621 if ( $search_terms ) {
47622 $hit = false;
47623 // Simple case-insensitive search. Boolean OR.
47624 $search_text = preg_replace( '/[^\w]/', '', $widget['name'] );
47625 if ( isset($widget['description']) )
47626 $search_text .= preg_replace( '/[^\w]/', '', $widget['description'] );
47627
47628 foreach ( $search_terms as $search_term ) {
47629 if ( stristr( $search_text, $search_term ) ) {
47630 $hit = true;
47631 break;
47632 }
47633 }
47634 if ( !$hit )
47635 continue;
47636 }
47637
47638 $sidebar = is_active_widget( $widget['callback'], $widget['id'] );
47639
47640 if ( ( 'unused' == $show && $sidebar ) || ( 'used' == $show && !$sidebar ) )
47641 continue;
47642
47643 if ( ! isset( $widget['params'][0] ) )
47644 $widget['params'][0] = array();
47645 ob_start();
47646 $args = wp_list_widget_controls_dynamic_sidebar( array( 0 => array( 'widget_id' => $widget['id'], 'widget_name' => $widget['name'], '_display' => 'template', '_show' => $show ), 1 => $widget['params'][0] ) );
47647 $sidebar_args = call_user_func_array( 'wp_widget_control', $args );
47648 $widget_control_template = ob_get_contents();
47649 ob_end_clean();
47650
47651 $widget_id = $widget['id']; // save this for later in case we mess with $widget['id']
47652
47653 $is_multi = false !== strpos( $widget_control_template, '%i%' );
47654 if ( !$sidebar || $is_multi ) {
47655 $add_query = array(
47656 'sidebar' => $sidebar,
47657 'key' => false,
47658 'edit' => false
47659 );
47660 if ( 'all' == $show && $is_multi ) {
47661 // it's a multi-widget. We only need to show it in the list once.
47662 $already_shown[] = $widget['callback'];
47663 $num = (int) array_pop( $ids = explode( '-', $widget['id'] ) );
47664 $id_base = $wp_registered_widget_controls[$widget['id']]['id_base'];
47665 // so that we always add a new one when clicking "add"
47666 while ( isset($wp_registered_widgets["$id_base-$num"]) )
47667 $num++;
47668 $widget['id'] = "$id_base-$num";
47669 $add_query['base'] = $id_base;
47670 $add_query['key'] = $num;
47671 $add_query['sidebar'] = $GLOBALS['sidebar'];
47672 }
47673 $add_query['add'] = $widget['id'];
47674 $action = 'add';
47675 $add_url = clean_url( wp_nonce_url( add_query_arg( $add_query ), "add-widget_$widget[id]" ) );
47676 } else {
47677 $action = 'edit';
47678 $edit_url = clean_url( add_query_arg( array(
47679 'sidebar' => $sidebar,
47680 'edit' => $widget['id'],
47681 'key' => array_search( $widget['id'], $sidebars_widgets[$sidebar] ),
47682 ) ) );
47683
47684 $widget_control_template = '<textarea rows="1" cols="1">' . htmlspecialchars( $widget_control_template ) . '</textarea>';
47685 }
47686
47687 $widget_control_template = $sidebar_args['before_widget'] . $widget_control_template . $sidebar_args['after_widget'];
47688
47689 $no_widgets_shown = false;
47690
47691
47692 if ( 'all' != $show && $sidebar_args['_widget_title'] )
47693 $widget_title = $sidebar_args['_widget_title'];
47694 else
47695 $widget_title = $widget['name'];
47696 ?>
47697
47698 <li id="widget-list-item-<?php echo attribute_escape( $widget['id'] ); ?>" class="widget-list-item">
47699 <h4 class="widget-title widget-draggable">
47700
47701 <span><?php echo $widget_title; ?></span>
47702
47703 <?php if ( 'add' == $action ) : ?>
47704
47705 <a class="widget-action widget-control-add" href="<?php echo $add_url; ?>"><?php _e( 'Add' ); ?></a>
47706
47707 <?php elseif ( 'edit' == $action ) :
47708 // We echo a hidden edit link for the sake of the JS. Edit links are shown (needlessly?) after a widget is added.
47709 ?>
47710
47711 <a class="widget-action widget-control-edit" href="<?php echo $edit_url; ?>" style="display: none;"><?php _e( 'Edit' ); ?></a>
47712
47713 <?php endif; ?>
47714
47715 <br class="clear" />
47716
47717 </h4>
47718
47719
47720 <ul id="widget-control-info-<?php echo $widget['id']; ?>" class="widget-control-info">
47721
47722 <?php echo $widget_control_template; ?>
47723
47724 </ul>
47725
47726 <?php if ( 'add' == $action ) : ?>
47727 <?php endif; ?>
47728
47729 <div class="widget-description">
47730 <?php echo ( $widget_description = wp_widget_description( $widget_id ) ) ? $widget_description : ' '; ?>
47731 </div>
47732
47733 <br class="clear" />
47734
47735 </li>
47736
47737 <?php endforeach; if ( $no_widgets_shown ) : ?>
47738
47739 <li><?php _e( 'No matching widgets' ); ?></li>
47740
47741 <?php endif; ?>
47742
47743 </ul>
47744 <?php
47745 }
47746
47747 /**
47748 * {@internal Missing Short Description}}
47749 *
47750 * @since unknown
47751 *
47752 * @param string $sidebar
47753 */
47754 function wp_list_widget_controls( $sidebar ) {
47755 add_filter( 'dynamic_sidebar_params', 'wp_list_widget_controls_dynamic_sidebar' );
47756 ?>
47757
47758 <ul class="widget-control-list">
47759
47760 <?php if ( !dynamic_sidebar( $sidebar ) ) echo "<li />"; ?>
47761
47762 </ul>
47763
47764 <?php
47765 }
47766
47767 /**
47768 * {@internal Missing Short Description}}
47769 *
47770 * @since unknown
47771 *
47772 * @param array $params
47773 * @return array
47774 */
47775 function wp_list_widget_controls_dynamic_sidebar( $params ) {
47776 global $wp_registered_widgets;
47777 static $i = 0;
47778 $i++;
47779
47780 $widget_id = $params[0]['widget_id'];
47781
47782 $params[0]['before_widget'] = "<li id='widget-list-control-item-$i-$widget_id' class='widget-list-control-item widget-sortable'>\n";
47783 $params[0]['after_widget'] = "</li>";
47784 $params[0]['before_title'] = "%BEG_OF_TITLE%";
47785 $params[0]['after_title'] = "%END_OF_TITLE%";
47786 if ( is_callable( $wp_registered_widgets[$widget_id]['callback'] ) ) {
47787 $wp_registered_widgets[$widget_id]['_callback'] = $wp_registered_widgets[$widget_id]['callback'];
47788 $wp_registered_widgets[$widget_id]['callback'] = 'wp_widget_control';
47789 }
47790 return $params;
47791 }
47792
47793 /**
47794 * Meta widget used to display the control form for a widget.
47795 *
47796 * Called from dynamic_sidebar().
47797 *
47798 * @since unknown
47799 *
47800 * @param array $sidebar_args
47801 * @return array
47802 */
47803 function wp_widget_control( $sidebar_args ) {
47804 global $wp_registered_widgets, $wp_registered_widget_controls, $sidebars_widgets, $edit_widget;
47805 $widget_id = $sidebar_args['widget_id'];
47806 $sidebar_id = isset($sidebar_args['id']) ? $sidebar_args['id'] : false;
47807
47808 $control = isset($wp_registered_widget_controls[$widget_id]) ? $wp_registered_widget_controls[$widget_id] : 0;
47809 $widget = $wp_registered_widgets[$widget_id];
47810
47811 $key = $sidebar_id ? array_search( $widget_id, $sidebars_widgets[$sidebar_id] ) : 'no-key'; // position of widget in sidebar
47812
47813 $edit = -1 < $edit_widget && is_numeric($key) && $edit_widget === $key; // (bool) are we currently editing this widget
47814
47815 $id_format = $widget['id'];
47816
47817 if ( ! isset( $sidebar_args['_show'] ) )
47818 $sidebar_args['_show'] = '';
47819
47820 if ( ! isset( $sidebar_args['_display'] ) )
47821 $sidebar_args['_display'] = '';
47822
47823 // We aren't showing a widget control, we're outputing a template for a mult-widget control
47824 if ( 'all' == $sidebar_args['_show'] && 'template' == $sidebar_args['_display'] && isset($control['params'][0]['number']) ) {
47825 // number == -1 implies a template where id numbers are replaced by a generic '%i%'
47826 $control['params'][0]['number'] = -1;
47827 // if given, id_base means widget id's should be constructed like {$id_base}-{$id_number}
47828 if ( isset($control['id_base']) )
47829 $id_format = $control['id_base'] . '-%i%';
47830 }
47831
47832 $widget_title = '';
47833 // We grab the normal widget output to find the widget's title
47834 if ( ( 'all' != $sidebar_args['_show'] || 'template' != $sidebar_args['_display'] ) && is_callable( $widget['_callback'] ) ) {
47835 ob_start();
47836 $args = func_get_args();
47837 call_user_func_array( $widget['_callback'], $args );
47838 $widget_title = ob_get_clean();
47839 $widget_title = wp_widget_control_ob_filter( $widget_title );
47840 }
47841 $wp_registered_widgets[$widget_id]['callback'] = $wp_registered_widgets[$widget_id]['_callback'];
47842 unset($wp_registered_widgets[$widget_id]['_callback']);
47843
47844 if ( $widget_title && $widget_title != $sidebar_args['widget_name'] )
47845 $widget_title = sprintf( _c('%1$s: %2$s|1: widget name, 2: widget title' ), $sidebar_args['widget_name'], $widget_title );
47846 else
47847 $widget_title = wp_specialchars( strip_tags( $sidebar_args['widget_name'] ) );
47848
47849 $sidebar_args['_widget_title'] = $widget_title;
47850
47851 if ( empty($sidebar_args['_display']) || 'template' != $sidebar_args['_display'] )
47852 echo $sidebar_args['before_widget'];
47853 ?>
47854 <div class="widget-top">
47855 <h4 class="widget-title"><span><?php echo $widget_title ?></span>
47856
47857 <?php if ( $edit ) : ?>
47858
47859 <a class="widget-action widget-control-edit" href="<?php echo clean_url( remove_query_arg( array( 'edit', 'key' ) ) ); ?>"><?php _e('Cancel'); ?></a>
47860
47861 <?php else : ?>
47862
47863 <a class="widget-action widget-control-edit" href="<?php echo clean_url( add_query_arg( array( 'edit' => $id_format, 'key' => $key ) ) ); ?>"><?php _e('Edit'); ?></a>
47864
47865 <?php endif; ?>
47866
47867 <br class="clear" />
47868
47869 </h4></div>
47870
47871 <div class="widget-control"<?php if ( $edit ) echo ' style="display: block;"'; ?>>
47872
47873 <?php
47874 if ( $control )
47875 call_user_func_array( $control['callback'], $control['params'] );
47876 else
47877 echo '<p>' . __('There are no options for this widget.') . '</p>';
47878 ?>
47879
47880 <input type="hidden" name="widget-id[]" value="<?php echo $id_format; ?>" />
47881 <input type="hidden" class="widget-width" value="<?php echo $control['width']; ?>" />
47882
47883 <div class="widget-control-actions">
47884
47885 <?php if ( $control ) : ?>
47886
47887 <a class="button widget-action widget-control-save hide-if-no-js edit alignleft" href="#save:<?php echo $id_format; ?>"><?php _e('Done'); ?></a>
47888
47889 <?php endif; ?>
47890
47891 <a class="button widget-action widget-control-remove alignright" href="<?php echo clean_url( wp_nonce_url( add_query_arg( array( 'remove' => $id_format, 'key' => $key ) ), "remove-widget_$widget[id]" ) ); ?>"><?php _e('Remove'); ?></a>
47892 <br class="clear" />
47893 </div>
47894 </div>
47895 <?php
47896 if ( empty($sidebar_args['_display']) || 'template' != $sidebar_args['_display'] )
47897 echo $sidebar_args['after_widget'];
47898 return $sidebar_args;
47899 }
47900
47901 /**
47902 * {@internal Missing Short Description}}
47903 *
47904 * @since unknown
47905 *
47906 * @param string $string
47907 * @return string
47908 */
47909 function wp_widget_control_ob_filter( $string ) {
47910 if ( false === $beg = strpos( $string, '%BEG_OF_TITLE%' ) )
47911 return '';
47912 if ( false === $end = strpos( $string, '%END_OF_TITLE%' ) )
47913 return '';
47914 $string = substr( $string, $beg + 14 , $end - $beg - 14);
47915 $string = str_replace( ' ', ' ', $string );
47916 return trim( wp_specialchars( strip_tags( $string ) ) );
47917 }
47918
47919 ?>