-
+ D41F6DA17520E87F2974D32425467F9D417FA00230A2369B974EC198B4E1E5587E81C4A53238E9999996C303045E6DF423FCA0F29677E0BA385487EDF787182B
mp-wp/wp-admin/widgets.php
(0 . 0)(1 . 326)
59966 <?php
59967 /**
59968 * Widgets administration panel.
59969 *
59970 * @package WordPress
59971 * @subpackage Administration
59972 */
59973
59974 /** WordPress Administration Bootstrap */
59975 require_once( 'admin.php' );
59976
59977 /** WordPress Administration Widgets API */
59978 require_once(ABSPATH . 'wp-admin/includes/widgets.php');
59979
59980 if ( ! current_user_can('switch_themes') )
59981 wp_die( __( 'Cheatin’ uh?' ));
59982
59983 wp_enqueue_script( array( 'wp-lists', 'admin-widgets' ) );
59984 wp_admin_css( 'widgets' );
59985
59986 do_action( 'sidebar_admin_setup' );
59987
59988 $title = __( 'Widgets' );
59989 $parent_file = 'themes.php';
59990
59991 // $sidebar = What sidebar are we editing?
59992 if ( isset($_GET['sidebar']) && isset($wp_registered_sidebars[$_GET['sidebar']]) ) {
59993 $sidebar = attribute_escape( $_GET['sidebar'] );
59994 } elseif ( is_array($wp_registered_sidebars) && !empty($wp_registered_sidebars) ) {
59995 // By default we look at the first defined sidebar
59996 $sidebar = array_shift( $keys = array_keys($wp_registered_sidebars) );
59997 } else {
59998 // If no sidebars, die.
59999 require_once( 'admin-header.php' );
60000 ?>
60001
60002 <div class="wrap">
60003 <?php screen_icon(); ?>
60004 <h2><?php echo wp_specialchars( $title ); ?></h2>
60005 <div class="error">
60006 <p><?php _e( 'No Sidebars Defined' ); ?></p>
60007 </div>
60008 <p><?php _e( 'The theme you are currently using isn’t widget-aware, meaning that it has no sidebars that you are able to change. For information on making your theme widget-aware, please <a href="http://codex.wordpress.org/Widgetizing_Themes">follow these instructions</a>.' ); ?></p>
60009 </div>
60010
60011 <?php
60012 require_once( 'admin-footer.php' );
60013 exit;
60014 }
60015
60016 // These are the widgets grouped by sidebar
60017 $sidebars_widgets = wp_get_sidebars_widgets();
60018 if ( empty( $sidebars_widgets ) )
60019 $sidebars_widgets = wp_get_widget_defaults();
60020
60021 // for the sake of PHP warnings
60022 if ( empty( $sidebars_widgets[$sidebar] ) )
60023 $sidebars_widgets[$sidebar] = array();
60024
60025 $http_post = 'post' == strtolower($_SERVER['REQUEST_METHOD']);
60026
60027 // We're updating a sidebar
60028 if ( $http_post && isset($sidebars_widgets[$_POST['sidebar']]) ) {
60029 check_admin_referer( 'edit-sidebar_' . $_POST['sidebar'] );
60030
60031 /* Hack #1
60032 * The widget_control is overloaded. It updates the widget's options AND echoes out the widget's HTML form.
60033 * Since we want to update before sending out any headers, we have to catch it with an output buffer,
60034 */
60035 ob_start();
60036 /* There can be multiple widgets of the same type, but the widget_control for that
60037 * widget type needs only be called once if it's a multi-widget.
60038 */
60039 $already_done = array();
60040
60041 foreach ( $wp_registered_widget_controls as $name => $control ) {
60042 if ( in_array( $control['callback'], $already_done ) )
60043 continue;
60044
60045 if ( is_callable( $control['callback'] ) ) {
60046 call_user_func_array( $control['callback'], $control['params'] );
60047 $control_output = ob_get_contents();
60048 if ( false !== strpos( $control_output, '%i%' ) ) // if it's a multi-widget, only call control function once.
60049 $already_done[] = $control['callback'];
60050 }
60051
60052 ob_clean();
60053 }
60054 ob_end_clean();
60055
60056 // Prophylactic. Take out empty ids.
60057 foreach ( (array) $_POST['widget-id'] as $key => $val )
60058 if ( !$val )
60059 unset($_POST['widget-id'][$key]);
60060
60061 // Reset the key numbering and store
60062 $new_sidebar = isset( $_POST['widget-id'] ) && is_array( $_POST['widget-id'] ) ? array_values( $_POST['widget-id'] ) : array();
60063 $sidebars_widgets[$_POST['sidebar']] = $new_sidebar;
60064 wp_set_sidebars_widgets( $sidebars_widgets );
60065
60066 wp_redirect( add_query_arg( 'message', 'updated' ) );
60067 exit;
60068 }
60069
60070 // What widget (if any) are we editing
60071 $edit_widget = -1;
60072
60073 $query_args = array('add', 'remove', 'key', 'edit', '_wpnonce', 'message', 'base' );
60074
60075 if ( isset($_GET['add']) && $_GET['add'] ) {
60076 // Add to the end of the sidebar
60077 $control_callback;
60078 if ( isset($wp_registered_widgets[$_GET['add']]) ) {
60079 check_admin_referer( "add-widget_$_GET[add]" );
60080 $sidebars_widgets[$sidebar][] = $_GET['add'];
60081 wp_set_sidebars_widgets( $sidebars_widgets );
60082 } elseif ( isset($_GET['base']) && isset($_GET['key']) ) { // It's a multi-widget
60083 check_admin_referer( "add-widget_$_GET[add]" );
60084 // Copy minimal info from an existing instance of this widget to a new instance
60085 foreach ( $wp_registered_widget_controls as $control ) {
60086 if ( $_GET['base'] === $control['id_base'] ) {
60087 $control_callback = $control['callback'];
60088 $num = (int) $_GET['key'];
60089 $control['params'][0]['number'] = $num;
60090 $control['id'] = $control['id_base'] . '-' . $num;
60091 $wp_registered_widget_controls[$control['id']] = $control;
60092 $sidebars_widgets[$sidebar][] = $control['id'];
60093 break;
60094 }
60095 }
60096 }
60097
60098 // it's a multi-widget. The only way to add multi-widgets without JS is to actually submit POST content...
60099 // so here we go
60100 if ( is_callable( $control_callback ) ) {
60101 require_once( 'admin-header.php' );
60102 ?>
60103 <div class="wrap">
60104 <h2><?php _e( 'Add Widget' ); ?></h2>
60105 <br />
60106 <form action="<?php echo clean_url( remove_query_arg( $query_args ) ); ?>" method="post">
60107
60108 <ul class="widget-control-list">
60109 <li class="widget-list-control-item">
60110 <div class="widget-top">
60111 <h4 class="widget-title"><?php echo $control['name']; ?></h4>
60112 </div>
60113 <div class="widget-control" style="display: block;">
60114 <?php
60115 call_user_func_array( $control_callback, $control['params'] );
60116 ?>
60117 <div class="widget-control-actions">
60118 <input type="submit" class="button" value="<?php _e( 'Add Widget' ); ?>" />
60119 <input type="hidden" id='sidebar' name='sidebar' value="<?php echo $sidebar; ?>" />
60120 <?php wp_nonce_field ( 'edit-sidebar_' . $sidebar );
60121 foreach ( $sidebars_widgets[$sidebar] as $sidebar_widget_id ) : ?>
60122 <input type="hidden" name='widget-id[]' value="<?php echo $sidebar_widget_id; ?>" />
60123 <?php endforeach; ?>
60124 </div>
60125 </div>
60126 </li>
60127 </ul>
60128 </form>
60129 </div>
60130 <?php
60131
60132 require_once( 'admin-footer.php' );
60133 exit;
60134 }
60135 wp_redirect( remove_query_arg( $query_args ) );
60136 exit;
60137 } elseif ( isset($_GET['remove']) && $_GET['remove'] && isset($_GET['key']) && is_numeric($_GET['key']) ) {
60138 // Remove from sidebar the widget of type $_GET['remove'] and in position $_GET['key']
60139 $key = (int) $_GET['key'];
60140 if ( -1 < $key && ( $keys = array_keys($sidebars_widgets[$sidebar], $_GET['remove']) ) && in_array($key, $keys) ) {
60141 check_admin_referer( "remove-widget_$_GET[remove]" );
60142 unset($sidebars_widgets[$sidebar][$key]);
60143 $sidebars_widgets[$sidebar] = array_values($sidebars_widgets[$sidebar]);
60144 wp_set_sidebars_widgets( $sidebars_widgets );
60145 }
60146 wp_redirect( remove_query_arg( $query_args ) );
60147 exit;
60148 } elseif ( isset($_GET['edit']) && $_GET['edit'] && isset($_GET['key']) && is_numeric($_GET['key']) ) {
60149 // Edit widget of type $_GET['edit'] and position $_GET['key']
60150 $key = (int) $_GET['key'];
60151 if ( -1 < $key && ( $keys = array_keys($sidebars_widgets[$sidebar], $_GET['edit']) ) && in_array($key, $keys) )
60152 $edit_widget = $key;
60153 }
60154
60155 // Total number of registered sidebars
60156 $sidebar_widget_count = count($sidebars_widgets[$sidebar]);
60157
60158 // This is sort of lame since "widget" won't be converted to "widgets" in the JS
60159 if ( 1 < $sidebars_count = count($wp_registered_sidebars) )
60160 $sidebar_info_text = __ngettext( 'You are using %1$s widget in the "%2$s" sidebar.', 'You are using %1$s widgets in the "%2$s" sidebar.', $sidebar_widget_count );
60161 else
60162 $sidebar_info_text = __ngettext( 'You are using %1$s widget in the sidebar.', 'You are using %1$s widgets in the sidebar.', $sidebar_widget_count );
60163
60164
60165 $sidebar_info_text = sprintf( wp_specialchars( $sidebar_info_text ), "<span id='widget-count'>$sidebar_widget_count</span>", $wp_registered_sidebars[$sidebar]['name'] );
60166
60167 $page = isset($_GET['apage']) ? abs( (int) $_GET['apage'] ) : 1;
60168
60169 /* TODO: Paginate widgets list
60170 $page_links = paginate_links( array(
60171 'base' => add_query_arg( 'apage', '%#%' ),
60172 'format' => '',
60173 'total' => ceil(($total = 105 )/ 10),
60174 'current' => $page
60175 ));
60176 */
60177 $page_links = ' ';
60178
60179 // Unsanitized!
60180 $widget_search = isset($_GET['s']) ? $_GET['s'] : false;
60181
60182 // Not entirely sure what all should be here
60183 $show_values = array(
60184 '' => $widget_search ? __( 'Show any widgets' ) : __( 'Show all widgets' ),
60185 'unused' => __( 'Show unused widgets' ),
60186 'used' => __( 'Show used widgets' )
60187 );
60188
60189 $show = isset($_GET['show']) && isset($show_values[$_GET['show']]) ? attribute_escape( $_GET['show'] ) : false;
60190
60191 $messages = array(
60192 'updated' => __('Changes saved.')
60193 );
60194
60195 require_once( 'admin-header.php' ); ?>
60196
60197 <?php if ( isset($_GET['message']) && isset($messages[$_GET['message']]) ) : ?>
60198 <div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div>
60199 <?php endif; ?>
60200
60201 <div class="wrap">
60202 <?php screen_icon(); ?>
60203 <h2><?php echo wp_specialchars( $title ); ?></h2>
60204
60205 <form id="widgets-filter" action="" method="get">
60206
60207 <div class="widget-liquid-left-holder">
60208 <div id="available-widgets-filter" class="widget-liquid-left">
60209 <h3><label for="show"><?php _e('Available Widgets'); ?></label></h3>
60210 <div class="nav">
60211 <select name="show" id="show">
60212 <?php foreach ( $show_values as $show_value => $show_text ) : $show_value = attribute_escape( $show_value ); ?>
60213 <option value='<?php echo $show_value; ?>'<?php selected( $show_value, $show ); ?>><?php echo wp_specialchars( $show_text ); ?></option>
60214 <?php endforeach; ?>
60215 </select>
60216 <input type="submit" value="<?php _e('Show' ); ?>" class="button-secondary" />
60217 <p class="pagenav">
60218 <?php echo $page_links; ?>
60219 </p>
60220 </div>
60221 </div>
60222 </div>
60223
60224 <div id="available-sidebars" class="widget-liquid-right">
60225 <h3><label for="sidebar-selector"><?php _e('Current Widgets'); ?></label></h3>
60226
60227 <div class="nav">
60228 <select id="sidebar-selector" name="sidebar">
60229 <?php foreach ( $wp_registered_sidebars as $sidebar_id => $registered_sidebar ) : $sidebar_id = attribute_escape( $sidebar_id ); ?>
60230 <option value='<?php echo $sidebar_id; ?>'<?php selected( $sidebar_id, $sidebar ); ?>><?php echo wp_specialchars( $registered_sidebar['name'] ); ?></option>
60231 <?php endforeach; ?>
60232 </select>
60233 <input type="submit" value="<?php _e('Show' ); ?>" class="button-secondary" />
60234 </div>
60235
60236 </div>
60237
60238 </form>
60239
60240 <div id="widget-content" class="widget-liquid-left-holder">
60241
60242 <div id="available-widgets" class="widget-liquid-left">
60243
60244 <?php wp_list_widgets( $show, $widget_search ); // This lists all the widgets for the query ( $show, $search ) ?>
60245
60246 <div class="nav">
60247 <p class="pagenav">
60248 <?php echo $page_links; ?>
60249 </p>
60250 </div>
60251 </div>
60252 </div>
60253
60254 <form id="widget-controls" action="" method="post">
60255
60256 <div id="current-widgets-head" class="widget-liquid-right">
60257
60258 <div id="sidebar-info">
60259 <p><?php echo $sidebar_info_text; ?></p>
60260 <p><?php _e( 'Add more from the Available Widgets section.' ); ?></p>
60261 </div>
60262
60263 </div>
60264
60265 <div id="current-widgets" class="widget-liquid-right">
60266 <div id="current-sidebar">
60267
60268 <?php wp_list_widget_controls( $sidebar ); // Show the control forms for each of the widgets in this sidebar ?>
60269
60270 </div>
60271
60272 <p class="submit">
60273 <input type="hidden" id='sidebar' name='sidebar' value="<?php echo $sidebar; ?>" />
60274 <input type="hidden" id="generated-time" name="generated-time" value="<?php echo time() - 1199145600; // Jan 1, 2008 ?>" />
60275 <input type="submit" name="save-widgets" class="button-primary" value="<?php _e( 'Save Changes' ); ?>" />
60276 <?php
60277 wp_nonce_field( 'edit-sidebar_' . $sidebar );
60278 ?>
60279 </p>
60280 </div>
60281
60282 </form>
60283 <br class="clear" />
60284
60285 </div>
60286
60287 <?php do_action( 'sidebar_admin_page' ); ?>
60288
60289 <?php require_once( 'admin-footer.php' ); ?>
60290
60291