raw
mp-wp_genesis           1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * Widgets administration panel.
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Administration
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /** WordPress Administration Bootstrap */
mp-wp_genesis 10 require_once( 'admin.php' );
mp-wp_genesis 11
mp-wp_genesis 12 /** WordPress Administration Widgets API */
mp-wp_genesis 13 require_once(ABSPATH . 'wp-admin/includes/widgets.php');
mp-wp_genesis 14
mp-wp_genesis 15 if ( ! current_user_can('switch_themes') )
mp-wp_genesis 16 wp_die( __( 'Cheatin&#8217; uh?' ));
mp-wp_genesis 17
mp-wp_genesis 18 wp_admin_css( 'widgets' );
mp-wp_genesis 19
mp-wp_genesis 20 do_action( 'sidebar_admin_setup' );
mp-wp_genesis 21
mp-wp_genesis 22 $title = __( 'Widgets' );
mp-wp_genesis 23 $parent_file = 'themes.php';
mp-wp_genesis 24
mp-wp_genesis 25 // $sidebar = What sidebar are we editing?
mp-wp_genesis 26 if ( isset($_GET['sidebar']) && isset($wp_registered_sidebars[$_GET['sidebar']]) ) {
mp-wp_genesis 27 $sidebar = attribute_escape( $_GET['sidebar'] );
mp-wp_genesis 28 } elseif ( is_array($wp_registered_sidebars) && !empty($wp_registered_sidebars) ) {
mp-wp_genesis 29 // By default we look at the first defined sidebar
mp-wp_genesis 30 $sidebar = array_shift( $keys = array_keys($wp_registered_sidebars) );
mp-wp_genesis 31 } else {
mp-wp_genesis 32 // If no sidebars, die.
mp-wp_genesis 33 require_once( 'admin-header.php' );
mp-wp_genesis 34 ?>
mp-wp_genesis 35
mp-wp_genesis 36 <div class="wrap">
mp-wp_genesis 37 <?php screen_icon(); ?>
mp-wp_genesis 38 <h2><?php echo wp_specialchars( $title ); ?></h2>
mp-wp_genesis 39 <div class="error">
mp-wp_genesis 40 <p><?php _e( 'No Sidebars Defined' ); ?></p>
mp-wp_genesis 41 </div>
mp-wp_genesis 42 <p><?php _e( 'The theme you are currently using isn&#8217;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>
mp-wp_genesis 43 </div>
mp-wp_genesis 44
mp-wp_genesis 45 <?php
mp-wp_genesis 46 require_once( 'admin-footer.php' );
mp-wp_genesis 47 exit;
mp-wp_genesis 48 }
mp-wp_genesis 49
mp-wp_genesis 50 // These are the widgets grouped by sidebar
mp-wp_genesis 51 $sidebars_widgets = wp_get_sidebars_widgets();
mp-wp_genesis 52 if ( empty( $sidebars_widgets ) )
mp-wp_genesis 53 $sidebars_widgets = wp_get_widget_defaults();
mp-wp_genesis 54
mp-wp_genesis 55 // for the sake of PHP warnings
mp-wp_genesis 56 if ( empty( $sidebars_widgets[$sidebar] ) )
mp-wp_genesis 57 $sidebars_widgets[$sidebar] = array();
mp-wp_genesis 58
mp-wp_genesis 59 $http_post = 'post' == strtolower($_SERVER['REQUEST_METHOD']);
mp-wp_genesis 60
mp-wp_genesis 61 // We're updating a sidebar
mp-wp_genesis 62 if ( $http_post && isset($sidebars_widgets[$_POST['sidebar']]) ) {
mp-wp_genesis 63 check_admin_referer( 'edit-sidebar_' . $_POST['sidebar'] );
mp-wp_genesis 64
mp-wp_genesis 65 /* Hack #1
mp-wp_genesis 66 * The widget_control is overloaded. It updates the widget's options AND echoes out the widget's HTML form.
mp-wp_genesis 67 * Since we want to update before sending out any headers, we have to catch it with an output buffer,
mp-wp_genesis 68 */
mp-wp_genesis 69 ob_start();
mp-wp_genesis 70 /* There can be multiple widgets of the same type, but the widget_control for that
mp-wp_genesis 71 * widget type needs only be called once if it's a multi-widget.
mp-wp_genesis 72 */
mp-wp_genesis 73 $already_done = array();
mp-wp_genesis 74
mp-wp_genesis 75 foreach ( $wp_registered_widget_controls as $name => $control ) {
mp-wp_genesis 76 if ( in_array( $control['callback'], $already_done ) )
mp-wp_genesis 77 continue;
mp-wp_genesis 78
mp-wp_genesis 79 if ( is_callable( $control['callback'] ) ) {
mp-wp_genesis 80 call_user_func_array( $control['callback'], $control['params'] );
mp-wp_genesis 81 $control_output = ob_get_contents();
mp-wp_genesis 82 if ( false !== strpos( $control_output, '%i%' ) ) // if it's a multi-widget, only call control function once.
mp-wp_genesis 83 $already_done[] = $control['callback'];
mp-wp_genesis 84 }
mp-wp_genesis 85
mp-wp_genesis 86 ob_clean();
mp-wp_genesis 87 }
mp-wp_genesis 88 ob_end_clean();
mp-wp_genesis 89
mp-wp_genesis 90 // Prophylactic. Take out empty ids.
mp-wp_genesis 91 foreach ( (array) $_POST['widget-id'] as $key => $val )
mp-wp_genesis 92 if ( !$val )
mp-wp_genesis 93 unset($_POST['widget-id'][$key]);
mp-wp_genesis 94
mp-wp_genesis 95 // Reset the key numbering and store
mp-wp_genesis 96 $new_sidebar = isset( $_POST['widget-id'] ) && is_array( $_POST['widget-id'] ) ? array_values( $_POST['widget-id'] ) : array();
mp-wp_genesis 97 $sidebars_widgets[$_POST['sidebar']] = $new_sidebar;
mp-wp_genesis 98 wp_set_sidebars_widgets( $sidebars_widgets );
mp-wp_genesis 99
mp-wp_genesis 100 wp_redirect( add_query_arg( 'message', 'updated' ) );
mp-wp_genesis 101 exit;
mp-wp_genesis 102 }
mp-wp_genesis 103
mp-wp_genesis 104 // What widget (if any) are we editing
mp-wp_genesis 105 $edit_widget = -1;
mp-wp_genesis 106
mp-wp_genesis 107 $query_args = array('add', 'remove', 'key', 'edit', '_wpnonce', 'message', 'base' );
mp-wp_genesis 108
mp-wp_genesis 109 if ( isset($_GET['add']) && $_GET['add'] ) {
mp-wp_genesis 110 // Add to the end of the sidebar
mp-wp_genesis 111 $control_callback;
mp-wp_genesis 112 if ( isset($wp_registered_widgets[$_GET['add']]) ) {
mp-wp_genesis 113 check_admin_referer( "add-widget_$_GET[add]" );
mp-wp_genesis 114 $sidebars_widgets[$sidebar][] = $_GET['add'];
mp-wp_genesis 115 wp_set_sidebars_widgets( $sidebars_widgets );
mp-wp_genesis 116 } elseif ( isset($_GET['base']) && isset($_GET['key']) ) { // It's a multi-widget
mp-wp_genesis 117 check_admin_referer( "add-widget_$_GET[add]" );
mp-wp_genesis 118 // Copy minimal info from an existing instance of this widget to a new instance
mp-wp_genesis 119 foreach ( $wp_registered_widget_controls as $control ) {
mp-wp_genesis 120 if ( $_GET['base'] === $control['id_base'] ) {
mp-wp_genesis 121 $control_callback = $control['callback'];
mp-wp_genesis 122 $num = (int) $_GET['key'];
mp-wp_genesis 123 $control['params'][0]['number'] = $num;
mp-wp_genesis 124 $control['id'] = $control['id_base'] . '-' . $num;
mp-wp_genesis 125 $wp_registered_widget_controls[$control['id']] = $control;
mp-wp_genesis 126 $sidebars_widgets[$sidebar][] = $control['id'];
mp-wp_genesis 127 break;
mp-wp_genesis 128 }
mp-wp_genesis 129 }
mp-wp_genesis 130 }
mp-wp_genesis 131
mp-wp_genesis 132 // it's a multi-widget. The only way to add multi-widgets without JS is to actually submit POST content...
mp-wp_genesis 133 // so here we go
mp-wp_genesis 134 if ( is_callable( $control_callback ) ) {
mp-wp_genesis 135 require_once( 'admin-header.php' );
mp-wp_genesis 136 ?>
mp-wp_genesis 137 <div class="wrap">
mp-wp_genesis 138 <h2><?php _e( 'Add Widget' ); ?></h2>
mp-wp_genesis 139 <br />
mp-wp_genesis 140 <form action="<?php echo clean_url( remove_query_arg( $query_args ) ); ?>" method="post">
mp-wp_genesis 141
mp-wp_genesis 142 <ul class="widget-control-list">
mp-wp_genesis 143 <li class="widget-list-control-item">
mp-wp_genesis 144 <div class="widget-top">
mp-wp_genesis 145 <h4 class="widget-title"><?php echo $control['name']; ?></h4>
mp-wp_genesis 146 </div>
mp-wp_genesis 147 <div class="widget-control" style="display: block;">
mp-wp_genesis 148 <?php
mp-wp_genesis 149 call_user_func_array( $control_callback, $control['params'] );
mp-wp_genesis 150 ?>
mp-wp_genesis 151 <div class="widget-control-actions">
mp-wp_genesis 152 <input type="submit" class="button" value="<?php _e( 'Add Widget' ); ?>" />
mp-wp_genesis 153 <input type="hidden" id='sidebar' name='sidebar' value="<?php echo $sidebar; ?>" />
mp-wp_genesis 154 <?php wp_nonce_field ( 'edit-sidebar_' . $sidebar );
mp-wp_genesis 155 foreach ( $sidebars_widgets[$sidebar] as $sidebar_widget_id ) : ?>
mp-wp_genesis 156 <input type="hidden" name='widget-id[]' value="<?php echo $sidebar_widget_id; ?>" />
mp-wp_genesis 157 <?php endforeach; ?>
mp-wp_genesis 158 </div>
mp-wp_genesis 159 </div>
mp-wp_genesis 160 </li>
mp-wp_genesis 161 </ul>
mp-wp_genesis 162 </form>
mp-wp_genesis 163 </div>
mp-wp_genesis 164 <?php
mp-wp_genesis 165
mp-wp_genesis 166 require_once( 'admin-footer.php' );
mp-wp_genesis 167 exit;
mp-wp_genesis 168 }
mp-wp_genesis 169 wp_redirect( remove_query_arg( $query_args ) );
mp-wp_genesis 170 exit;
mp-wp_genesis 171 } elseif ( isset($_GET['remove']) && $_GET['remove'] && isset($_GET['key']) && is_numeric($_GET['key']) ) {
mp-wp_genesis 172 // Remove from sidebar the widget of type $_GET['remove'] and in position $_GET['key']
mp-wp_genesis 173 $key = (int) $_GET['key'];
mp-wp_genesis 174 if ( -1 < $key && ( $keys = array_keys($sidebars_widgets[$sidebar], $_GET['remove']) ) && in_array($key, $keys) ) {
mp-wp_genesis 175 check_admin_referer( "remove-widget_$_GET[remove]" );
mp-wp_genesis 176 unset($sidebars_widgets[$sidebar][$key]);
mp-wp_genesis 177 $sidebars_widgets[$sidebar] = array_values($sidebars_widgets[$sidebar]);
mp-wp_genesis 178 wp_set_sidebars_widgets( $sidebars_widgets );
mp-wp_genesis 179 }
mp-wp_genesis 180 wp_redirect( remove_query_arg( $query_args ) );
mp-wp_genesis 181 exit;
mp-wp_genesis 182 } elseif ( isset($_GET['edit']) && $_GET['edit'] && isset($_GET['key']) && is_numeric($_GET['key']) ) {
mp-wp_genesis 183 // Edit widget of type $_GET['edit'] and position $_GET['key']
mp-wp_genesis 184 $key = (int) $_GET['key'];
mp-wp_genesis 185 if ( -1 < $key && ( $keys = array_keys($sidebars_widgets[$sidebar], $_GET['edit']) ) && in_array($key, $keys) )
mp-wp_genesis 186 $edit_widget = $key;
mp-wp_genesis 187 }
mp-wp_genesis 188
mp-wp_genesis 189 // Total number of registered sidebars
mp-wp_genesis 190 $sidebar_widget_count = count($sidebars_widgets[$sidebar]);
mp-wp_genesis 191
mp-wp_genesis 192 // This is sort of lame since "widget" won't be converted to "widgets" in the JS
mp-wp_genesis 193 if ( 1 < $sidebars_count = count($wp_registered_sidebars) )
mp-wp_genesis 194 $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 );
mp-wp_genesis 195 else
mp-wp_genesis 196 $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 );
mp-wp_genesis 197
mp-wp_genesis 198
mp-wp_genesis 199 $sidebar_info_text = sprintf( wp_specialchars( $sidebar_info_text ), "<span id='widget-count'>$sidebar_widget_count</span>", $wp_registered_sidebars[$sidebar]['name'] );
mp-wp_genesis 200
mp-wp_genesis 201 $page = isset($_GET['apage']) ? abs( (int) $_GET['apage'] ) : 1;
mp-wp_genesis 202
mp-wp_genesis 203 /* TODO: Paginate widgets list
mp-wp_genesis 204 $page_links = paginate_links( array(
mp-wp_genesis 205 'base' => add_query_arg( 'apage', '%#%' ),
mp-wp_genesis 206 'format' => '',
mp-wp_genesis 207 'total' => ceil(($total = 105 )/ 10),
mp-wp_genesis 208 'current' => $page
mp-wp_genesis 209 ));
mp-wp_genesis 210 */
mp-wp_genesis 211 $page_links = '&nbsp;';
mp-wp_genesis 212
mp-wp_genesis 213 // Unsanitized!
mp-wp_genesis 214 $widget_search = isset($_GET['s']) ? $_GET['s'] : false;
mp-wp_genesis 215
mp-wp_genesis 216 // Not entirely sure what all should be here
mp-wp_genesis 217 $show_values = array(
mp-wp_genesis 218 '' => $widget_search ? __( 'Show any widgets' ) : __( 'Show all widgets' ),
mp-wp_genesis 219 'unused' => __( 'Show unused widgets' ),
mp-wp_genesis 220 'used' => __( 'Show used widgets' )
mp-wp_genesis 221 );
mp-wp_genesis 222
mp-wp_genesis 223 $show = isset($_GET['show']) && isset($show_values[$_GET['show']]) ? attribute_escape( $_GET['show'] ) : false;
mp-wp_genesis 224
mp-wp_genesis 225 $messages = array(
mp-wp_genesis 226 'updated' => __('Changes saved.')
mp-wp_genesis 227 );
mp-wp_genesis 228
mp-wp_genesis 229 require_once( 'admin-header.php' ); ?>
mp-wp_genesis 230
mp-wp_genesis 231 <?php if ( isset($_GET['message']) && isset($messages[$_GET['message']]) ) : ?>
mp-wp_genesis 232 <div id="message" class="updated fade"><p><?php echo $messages[$_GET['message']]; ?></p></div>
mp-wp_genesis 233 <?php endif; ?>
mp-wp_genesis 234
mp-wp_genesis 235 <div class="wrap">
mp-wp_genesis 236 <?php screen_icon(); ?>
mp-wp_genesis 237 <h2><?php echo wp_specialchars( $title ); ?></h2>
mp-wp_genesis 238
mp-wp_genesis 239 <form id="widgets-filter" action="" method="get">
mp-wp_genesis 240
mp-wp_genesis 241 <div class="widget-liquid-left-holder">
mp-wp_genesis 242 <div id="available-widgets-filter" class="widget-liquid-left">
mp-wp_genesis 243 <h3><label for="show"><?php _e('Available Widgets'); ?></label></h3>
mp-wp_genesis 244 <div class="nav">
mp-wp_genesis 245 <select name="show" id="show">
mp-wp_genesis 246 <?php foreach ( $show_values as $show_value => $show_text ) : $show_value = attribute_escape( $show_value ); ?>
mp-wp_genesis 247 <option value='<?php echo $show_value; ?>'<?php selected( $show_value, $show ); ?>><?php echo wp_specialchars( $show_text ); ?></option>
mp-wp_genesis 248 <?php endforeach; ?>
mp-wp_genesis 249 </select>
mp-wp_genesis 250 <input type="submit" value="<?php _e('Show' ); ?>" class="button-secondary" />
mp-wp_genesis 251 <p class="pagenav">
mp-wp_genesis 252 <?php echo $page_links; ?>
mp-wp_genesis 253 </p>
mp-wp_genesis 254 </div>
mp-wp_genesis 255 </div>
mp-wp_genesis 256 </div>
mp-wp_genesis 257
mp-wp_genesis 258 <div id="available-sidebars" class="widget-liquid-right">
mp-wp_genesis 259 <h3><label for="sidebar-selector"><?php _e('Current Widgets'); ?></label></h3>
mp-wp_genesis 260
mp-wp_genesis 261 <div class="nav">
mp-wp_genesis 262 <select id="sidebar-selector" name="sidebar">
mp-wp_genesis 263 <?php foreach ( $wp_registered_sidebars as $sidebar_id => $registered_sidebar ) : $sidebar_id = attribute_escape( $sidebar_id ); ?>
mp-wp_genesis 264 <option value='<?php echo $sidebar_id; ?>'<?php selected( $sidebar_id, $sidebar ); ?>><?php echo wp_specialchars( $registered_sidebar['name'] ); ?></option>
mp-wp_genesis 265 <?php endforeach; ?>
mp-wp_genesis 266 </select>
mp-wp_genesis 267 <input type="submit" value="<?php _e('Show' ); ?>" class="button-secondary" />
mp-wp_genesis 268 </div>
mp-wp_genesis 269
mp-wp_genesis 270 </div>
mp-wp_genesis 271
mp-wp_genesis 272 </form>
mp-wp_genesis 273
mp-wp_genesis 274 <div id="widget-content" class="widget-liquid-left-holder">
mp-wp_genesis 275
mp-wp_genesis 276 <div id="available-widgets" class="widget-liquid-left">
mp-wp_genesis 277
mp-wp_genesis 278 <?php wp_list_widgets( $show, $widget_search ); // This lists all the widgets for the query ( $show, $search ) ?>
mp-wp_genesis 279
mp-wp_genesis 280 <div class="nav">
mp-wp_genesis 281 <p class="pagenav">
mp-wp_genesis 282 <?php echo $page_links; ?>
mp-wp_genesis 283 </p>
mp-wp_genesis 284 </div>
mp-wp_genesis 285 </div>
mp-wp_genesis 286 </div>
mp-wp_genesis 287
mp-wp_genesis 288 <form id="widget-controls" action="" method="post">
mp-wp_genesis 289
mp-wp_genesis 290 <div id="current-widgets-head" class="widget-liquid-right">
mp-wp_genesis 291
mp-wp_genesis 292 <div id="sidebar-info">
mp-wp_genesis 293 <p><?php echo $sidebar_info_text; ?></p>
mp-wp_genesis 294 <p><?php _e( 'Add more from the Available Widgets section.' ); ?></p>
mp-wp_genesis 295 </div>
mp-wp_genesis 296
mp-wp_genesis 297 </div>
mp-wp_genesis 298
mp-wp_genesis 299 <div id="current-widgets" class="widget-liquid-right">
mp-wp_genesis 300 <div id="current-sidebar">
mp-wp_genesis 301
mp-wp_genesis 302 <?php wp_list_widget_controls( $sidebar ); // Show the control forms for each of the widgets in this sidebar ?>
mp-wp_genesis 303
mp-wp_genesis 304 </div>
mp-wp_genesis 305
mp-wp_genesis 306 <p class="submit">
mp-wp_genesis 307 <input type="hidden" id='sidebar' name='sidebar' value="<?php echo $sidebar; ?>" />
mp-wp_genesis 308 <input type="hidden" id="generated-time" name="generated-time" value="<?php echo time() - 1199145600; // Jan 1, 2008 ?>" />
mp-wp_genesis 309 <input type="submit" name="save-widgets" class="button-primary" value="<?php _e( 'Save Changes' ); ?>" />
mp-wp_genesis 310 <?php
mp-wp_genesis 311 wp_nonce_field( 'edit-sidebar_' . $sidebar );
mp-wp_genesis 312 ?>
mp-wp_genesis 313 </p>
mp-wp_genesis 314 </div>
mp-wp_genesis 315
mp-wp_genesis 316 </form>
mp-wp_genesis 317 <br class="clear" />
mp-wp_genesis 318
mp-wp_genesis 319 </div>
mp-wp_genesis 320
mp-wp_genesis 321 <?php do_action( 'sidebar_admin_page' ); ?>
mp-wp_genesis 322
mp-wp_genesis 323 <?php require_once( 'admin-footer.php' ); ?>
mp-wp_genesis 324
mp-wp_genesis 325