Changeset 10912
- Timestamp:
- 04/11/2009 02:37:24 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-ajax.php
r10909 r10912 1269 1269 die; 1270 1270 break; 1271 case 'widgets-order' : 1272 check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' ); 1273 1274 if ( !current_user_can('switch_themes') ) 1275 die('-1'); 1276 1277 unset( $_POST['savewidgets'], $_POST['action'] ); 1278 $sidebars_widgets = array('array_version' => 3); 1279 1280 foreach ( $_POST as $key => $val ) { 1281 if ( preg_match( '/^(wp_inactive_widgets|sidebar-[0-9]+)$/', $key ) ) { 1282 if ( preg_match( '/^[0-9a-z,_-]+$/i', $val ) ) { 1283 $val = explode(',', $val); 1284 1285 foreach ( $val as $k => $v ) { 1286 $val[$k] = substr($v, strpos($v, '_') + 1); 1287 } 1288 } elseif ( '' == $val ) { 1289 $val = array(); 1290 } else { 1291 die('-1'); 1292 } 1293 1294 $sidebars_widgets[$key] = $val; 1295 } 1296 } 1297 1298 wp_set_sidebars_widgets($sidebars_widgets); 1299 1300 die('1'); 1301 break; 1302 case 'save-widget' : 1303 check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' ); 1304 1305 if ( !current_user_can('switch_themes') ) 1306 die('-1'); 1307 1308 unset( $_POST['savewidgets'], $_POST['action'] ); 1309 1310 $number = isset($_POST['widget_number']) ? $_POST['widget_number'] : ''; 1311 if ( isset($_POST['id_base']) ) 1312 $id_base = $_POST['id_base']; 1313 else 1314 die('-1'); 1315 1316 $sidebar_id = (string) $_POST['sidebar']; 1317 $sidebars = wp_get_sidebars_widgets(); 1318 $sidebar = isset($sidebars[$sidebar_id]) ? $sidebars[$sidebar_id] : array(); 1319 1320 // delete 1321 if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) { 1322 $del_id = $_POST['widget-id']; 1323 $widget = isset($wp_registered_widgets[$del_id]) ? $wp_registered_widgets[$del_id] : false; 1324 1325 if ( !in_array($del_id, $sidebar, true) || !$widget ) 1326 die('-1'); 1327 1328 $option = str_replace( '-', '_', 'widget_' . $id_base ); 1329 $data = get_option($option); 1330 1331 if ( isset($widget['params'][0]['number']) ) { 1332 $number = $widget['params'][0]['number']; 1333 if ( is_array($data) && isset($data[$number]) ) { 1334 unset( $data[$number] ); 1335 update_option($option, $data); 1336 } 1337 } else { 1338 if ( $data ) { 1339 $data = array(); 1340 update_option($option, $data); 1341 } 1342 } 1343 1344 $sidebar = array_diff( $sidebar, array($del_id) ); 1345 $sidebars[$sidebar_id] = $sidebar; 1346 wp_set_sidebars_widgets($sidebars); 1347 1348 echo "deleted:$del_id"; 1349 die(); 1350 } 1351 1352 // save 1353 foreach ( (array) $wp_registered_widget_updates as $name => $control ) { 1354 if ( $name == $id_base ) { 1355 if ( !is_callable( $control['callback'] ) ) 1356 continue; 1357 1358 if ( $number ) { 1359 // don't delete other instances of the same multi-widget 1360 foreach ( $sidebar as $_widget_id ) { 1361 if ( isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) 1362 unset($wp_registered_widgets[$_widget_id]['params'][0]['number']); 1363 } 1364 } 1365 1366 ob_start(); 1367 call_user_func_array( $control['callback'], $control['params'] ); 1368 ob_end_clean(); 1369 break; 1370 } 1371 } 1372 1373 die('1'); 1374 break; 1271 1375 default : 1272 1376 do_action( 'wp_ajax_' . $_POST['action'] ); -
trunk/wp-admin/css/colors-classic.css
r10883 r10912 34 34 } 35 35 36 div#current-widgets,37 36 #postcustomstuff table, 38 37 #your-profile fieldset, … … 84 83 } 85 84 86 div.dashboard-widget-submit, 87 ul.widget-control-list div.widget-control-actions { 85 div.dashboard-widget-submit { 88 86 border-top-color: #ccc; 89 87 } … … 102 100 } 103 101 /* #upload-menu li a.upload-tab-link, */ 104 li.widget-list-control-item h4.widget-title a:hover,105 li.widget-list-control-item h4.widget-title a,106 #dragHelper li.widget-list-control-item h4.widget-title a,107 #draghelper li.widget-list-control-item h4.widget-title a:visited,108 102 .login #backtoblog a:hover, 109 103 #plugin-information .action-button a, … … 113 107 } 114 108 115 li.widget-list-control-item div.widget-control {116 background-color: #fff;117 border-color: #dfdfdf;118 }119 120 109 .metabox-holder .postbox h3, 121 110 #poststuff .postbox h3, … … 142 131 strong .post-com-count span { 143 132 background-color: #21759b; 144 }145 146 ul#widget-list li.widget-list-item h4.widget-title {147 background-color: #f0f0f0;148 color: #000;149 133 } 150 134 … … 277 261 } 278 262 279 .side-info ul , .widget-description{263 .side-info ul { 280 264 color: #666; 281 265 } … … 430 414 431 415 div#available-widgets-filter, 432 ul#widget-list li.widget-list-item,433 416 .commentlist li { 434 417 border-bottom-color: #ccc; … … 532 515 } 533 516 534 #current-widgets .drop-widget-here {535 background-color: #ffc;536 }537 538 517 #dashboard_secondary div.dashboard-widget-content ul li a { 539 518 background-color: #f9f9f9; … … 542 521 input.readonly, textarea.readonly { 543 522 background-color: #ddd; 544 }545 546 #dragHelper h4.widget-title,547 li.widget-list-control-item h4,548 #dragHelper li.widget-list-control-item h4 {549 background-color: #2683ae;550 color: #fff;551 523 } 552 524 … … 1596 1568 border-bottom-color: #ccc; 1597 1569 } 1570 1571 div.widgets-holder-wrap { 1572 background-color: #F1F1F1; 1573 border-color: #DDDDDD; 1574 } -
trunk/wp-admin/css/colors-fresh.css
r10883 r10912 34 34 } 35 35 36 div#current-widgets,37 36 #postcustomstuff table, 38 37 #your-profile fieldset, … … 84 83 } 85 84 86 div.dashboard-widget-submit, 87 ul.widget-control-list div.widget-control-actions { 85 div.dashboard-widget-submit { 88 86 border-top-color: #ccc; 89 87 } … … 102 100 } 103 101 /* #upload-menu li a.upload-tab-link, */ 104 li.widget-list-control-item h4.widget-title a:hover,105 li.widget-list-control-item h4.widget-title a,106 #dragHelper li.widget-list-control-item h4.widget-title a,107 #draghelper li.widget-list-control-item h4.widget-title a:visited,108 102 .login #backtoblog a:hover, 109 103 #plugin-information .action-button a, … … 113 107 } 114 108 115 li.widget-list-control-item div.widget-control { 116 background-color: #fff; 117 border-color: #dfdfdf; 118 } 119 120 .metabox-holder .postbox h3, 121 #poststuff .postbox h3, 122 #poststuff .stuffbox h3 { 109 .widget .widget-top, 110 .postbox h3, 111 .stuffbox h3 { 123 112 background: #dfdfdf url("../images/gray-grad.png") repeat-x left top; 124 113 text-shadow: #fff 0 1px 0; … … 142 131 strong .post-com-count span { 143 132 background-color: #21759b; 144 }145 146 ul#widget-list li.widget-list-item h4.widget-title {147 background-color: #f0f0f0;148 color: #000;149 133 } 150 134 … … 277 261 } 278 262 279 .side-info ul , .widget-description{263 .side-info ul { 280 264 color: #666; 281 265 } … … 430 414 431 415 div#available-widgets-filter, 432 ul#widget-list li.widget-list-item,433 416 .commentlist li { 434 417 border-bottom-color: #ccc; … … 532 515 } 533 516 534 #current-widgets .drop-widget-here {535 background-color: #ffc;536 }537 538 517 #dashboard_secondary div.dashboard-widget-content ul li a { 539 518 background-color: #f9f9f9; … … 542 521 input.readonly, textarea.readonly { 543 522 background-color: #ddd; 544 }545 546 #dragHelper h4.widget-title,547 li.widget-list-control-item h4,548 #dragHelper li.widget-list-control-item h4 {549 background-color: #2683ae;550 color: #fff;551 523 } 552 524 … … 643 615 } 644 616 645 . metabox-holder .postbox,646 #poststuff.postbox,617 .widget, 618 .postbox, 647 619 #titlediv, 648 620 #poststuff .postarea, … … 655 627 } 656 628 657 . metabox-holder .postbox,658 #poststuff.postbox {629 .widget, 630 .postbox { 659 631 background-color: #FFF; 660 632 } 661 633 634 .widget .widget-top, 662 635 .ui-sortable .postbox h3 { 663 636 color: #464646; 664 637 } 665 638 639 .widget .widget-top, 666 640 .ui-sortable .postbox h3:hover { 667 641 color: #000; … … 1596 1570 border-bottom-color: #ccc; 1597 1571 } 1572 1573 div.widgets-holder-wrap { 1574 background-color: #F1F1F1; 1575 border-color: #DDDDDD; 1576 } -
trunk/wp-admin/css/global.css
r10884 r10912 275 275 h4 { 276 276 display: block; 277 font-size: 1em; 277 278 font-weight: bold; 278 279 margin: 1.33em 0; -
trunk/wp-admin/css/ie.css
r10884 r10912 189 189 } 190 190 191 #the-comment-list .comment-item,192 ul#widget-list li.widget-list-item {193 zoom: 100%;194 }195 196 191 #wphead-info { 197 192 float: right; … … 208 203 } 209 204 210 * html div.widget-liquid-left -holder,205 * html div.widget-liquid-left, 211 206 * html div.widget-liquid-right { 212 207 display: block; … … 228 223 } 229 224 225 #the-comment-list .comment-item, 230 226 #post-status-info, 231 227 #wpwrap, … … 240 236 #editorcontainer, 241 237 .tablenav, 242 .widget-control-list, 243 li.widget-list-control-item, 238 .widget-liquid-left, 239 .widget-liquid-right, 240 #widgets-left, 241 .widgets-sortables, 244 242 #dragHelper, 245 li.widget-list-control-item h4,246 .widget -sortable,243 .widget .widget-top, 244 .widget, 247 245 .widget-control-actions, 248 246 .tagchecklist, … … 354 352 width: 145px; 355 353 } 354 355 * html .widget-top .widget-title-action a { 356 background: url("../images/menu-bits.gif") no-repeat scroll 0 -110px; 357 } 358 359 * html .widget { 360 border-color: #dfdfdf; 361 } 362 363 * html div.widget-liquid-left { 364 width: 99%; 365 } 366 367 #wp_inactive_widgets { 368 padding-bottom: 8px; 369 } 370 371 * html .widgets-sortables { 372 height: 50px; 373 } -
trunk/wp-admin/css/widgets-rtl.css
r10147 r10912 1 h4.widget-title span { 2 float: right; 3 } 4 h4.widget-title a { 5 float: left; 6 margin-left: 0; 7 margin-right: 1em; 8 } 9 ul#widget-list li.widget-list-item h4.widget-title { 10 float: right; 11 } 1 12 2 ul#widget-list li.widget-list-item div.widget-description { 13 3 margin: 0 200px 0 0; … … 20 10 float: right; 21 11 } 22 li.widget-list-control-item h4.widget-title a,23 #dragHelper li.widget-list-control-item h4.widget-title a,24 #draghelper li.widget-list-control-item h4.widget-title a:visited {25 right: auto;26 left: 1em;27 } -
trunk/wp-admin/css/widgets.css
r9944 r10912 1 1 /* 2 column liquid layout */ 2 div.widget-liquid-left -holder{2 div.widget-liquid-left { 3 3 float: left; 4 4 clear: left; 5 5 width: 100%; 6 margin-right: -3 10px;6 margin-right: -325px; 7 7 } 8 8 9 div .widget-liquid-left {10 margin-right: 3 20px;9 div#widgets-left { 10 margin-right: 335px; 11 11 } 12 12 … … 14 14 float: right; 15 15 clear: right; 16 width: 300px; 17 position: relative; 16 width: 320px; 18 17 } 19 18 20 /* pasitioning etc. */ 21 form#widgets-filter { 22 position: relative; 19 .widgets-sortables li { 20 width: 300px; 21 margin: 15px 0 18px; 22 } 23 24 #widgets-left .widgets-sortables li, 25 #widgets-left #widget-list li { 26 float: left; 27 margin: 0 15px 18px 3px; 28 width: 300px; 29 } 30 31 .widget-placeholder { 32 border-width: 1px; 33 border-style: dashed; 34 margin-bottom: 20px; 35 height: 25px; 36 width: 298px; 37 } 38 39 div.widgets-holder-wrap { 40 padding: 8px 8px 0; 41 margin: 12px 0; 42 border-width: 1px; 43 border-style: solid; 44 -moz-border-radius: 6px; 45 -khtml-border-radius: 6px; 46 -webkit-border-radius: 6px; 47 border-radius: 6px; 48 } 49 50 #widgets-left #available-widgets { 51 background-color: transparent; 52 border: 0 none; 23 53 } 24 54 … … 32 62 margin: 0; 33 63 padding: 0; 64 min-height: 100px; 34 65 } 35 66 36 ul#widget-list li.widget-list-item { 37 padding: .7em 0.9em; 38 margin: 0; 39 border-bottom-width: 1px; 40 border-bottom-style: solid; 67 .widget .widget-top { 68 font-size: 12px; 69 font-weight: bold; 41 70 line-height: 1; 42 71 } 43 72 44 h4.widget-title span { 45 float: left; 73 .widget-top .widget-title { 74 margin-right: 30px; 75 padding: 7px 9px; 46 76 } 47 77 48 h4.widget-title a{78 .widget-top .widget-title-action { 49 79 float: right; 50 text-decoration: underline;51 border-bottom: none;52 margin-left: 1em;53 80 } 54 81 55 ul#widget-list li.widget-list-item h4.widget-title { 56 position: relative; 57 margin: 0; 58 padding: .5em 1em; 59 width: 200px; 60 float: left; 61 font-size: 13px; 62 -moz-border-radius: 3px; 63 -khtml-border-radius: 3px; 64 -webkit-border-radius: 3px; 65 border-radius: 3px; 82 .widget-title-action a { 83 display: block; 84 width: 24px; 85 height: 26px; 66 86 } 67 87 68 #dragHelper h4.widget-title { 69 padding: .5em 1em; 70 margin: 0; 88 .widget-top:hover .widget-title-action a { 89 background: url("../images/menu-bits.gif") no-repeat scroll 0 -110px; 71 90 } 72 91 73 ul#widget-list li.widget-list-item div.widget-description { 74 display: block; 75 margin: 0 0 0 200px; 76 padding: 0 0 0 4em; 92 .widget .widget-inside { 93 margin: 15px; 77 94 font-size: 11px; 95 display: none; 78 96 } 79 97 80 ul#widget-list li.widget-list-item ul.widget-control-info { 98 .widget-control, 99 .widget-description { 81 100 display: none; 101 } 102 103 #available-widgets .widget-description, 104 .widget-liquid-right .widget-control, 105 #wp_inactive_widgets .widget-control { 106 display: block; 107 } 108 109 .widget .widget-control p { 110 margin: 0 0 1em; 111 padding: 0; 112 } 113 114 .widget-title h4 { 115 margin: 0; 116 line-height: 1; 117 } 118 119 .sidebar-name { 120 margin: 0 0 12px; 121 padding: 6px; 122 cursor: pointer; 123 } 124 125 .widgets-sortables { 126 min-height: 50px; 127 } 128 129 .widget-control-actions { 130 margin-top: 8px; 131 } 132 133 .widget-control-actions a { 134 text-decoration: none; 82 135 } 83 136 … … 88 141 } 89 142 90 ul.widget-control-list { 91 list-style: none; 92 margin: 0; 93 padding: 0 1em; 94 } 95 96 div#current-widgets p.submit { 97 padding: 1em; 98 } 99 100 li.widget-list-control-item { 101 margin: 1em 0; 102 -moz-border-radius: 3px; 103 -khtml-border-radius: 3px; 104 -webkit-border-radius: 3px; 105 border-radius: 3px; 106 } 107 108 li.widget-list-control-item h4, 109 #dragHelper li.widget-list-control-item h4, 110 li.widget-sortable h4 { 111 margin: 0; 112 cursor: move; 113 font-size: 13px; 114 padding: 0.4em 0.8em; 115 position: relative; 116 -moz-border-radius: 3px; 117 -khtml-border-radius: 3px; 118 -webkit-border-radius: 3px; 119 border-radius: 3px; 120 } 121 122 .widget-control-save, 123 .widget-control-remove { 124 margin-right: 8px; 125 float: left; 126 text-decoration: none; 127 } 128 129 li.widget-list-control-item h4.widget-title a, 130 #dragHelper li.widget-list-control-item h4.widget-title a, 131 #draghelper li.widget-list-control-item h4.widget-title a:visited { 132 right: 1em; 133 } 134 135 li.widget-list-control-item h4.widget-title a:hover { 143 .widget-title a, 144 .widget-title a:hover { 136 145 text-decoration: none; 137 146 border-bottom: none; 138 }139 140 li.widget-list-control-item div.widget-control {141 border-width: 0 1px 1px;142 border-style: none solid solid;143 display: none;144 padding: 15px;145 font-size: 11px;146 position: relative;147 }148 149 li.widget-list-control-item div.widget-control p {150 margin: 0 0 1em;151 padding: 0;152 }153 154 ul.widget-control-list div.widget-control-actions {155 padding: 0.5em 0 0;156 147 } 157 148 … … 161 152 } 162 153 163 div#current-widgets {164 padding-top: 1em;165 border-width: 1px 0 0;166 border-style: solid none none;167 }168 154 169 #widget-controls .widefat {170 width: 92%;171 padding: 3px;172 }173 174 #widget-controls select.widefat {175 width: auto;176 display: block;177 } -
trunk/wp-admin/includes/widgets.php
r10680 r10912 8 8 9 9 /** 10 * Display list of widgets, either all or matching search.10 * Display list of the available widgets, either all or matching search. 11 11 * 12 12 * The search parameter are search terms separated by spaces. … … 19 19 function wp_list_widgets( $show = 'all', $_search = false ) { 20 20 global $wp_registered_widgets, $sidebars_widgets, $wp_registered_widget_controls; 21 if ( $_search ) { 21 22 if ( $_search ) { 22 23 // sanitize 23 24 $search = preg_replace( '/[^\w\s]/', '', $_search ); … … 32 33 ?> 33 34 34 <ul id= 'widget-list'>35 35 <ul id="widget-list"> 36 <?php 36 37 $no_widgets_shown = true; 37 38 $already_shown = array(); 38 foreach ( $wp_registered_widgets as $name => $widget ) :39 foreach ( $wp_registered_widgets as $name => $widget ) { 39 40 if ( 'all' == $show && in_array( $widget['callback'], $already_shown ) ) // We already showed this multi-widget 40 41 continue; … … 64 65 if ( ! isset( $widget['params'][0] ) ) 65 66 $widget['params'][0] = array(); 66 ob_start(); 67 $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] ) ); 68 $sidebar_args = call_user_func_array( 'wp_widget_control', $args ); 69 $widget_control_template = ob_get_contents(); 70 ob_end_clean(); 71 72 $widget_id = $widget['id']; // save this for later in case we mess with $widget['id'] 73 74 $is_multi = false !== strpos( $widget_control_template, '%i%' ); 75 if ( !$sidebar || $is_multi ) { 76 $add_query = array( 77 'sidebar' => $sidebar, 78 'key' => false, 79 'edit' => false 80 ); 81 if ( 'all' == $show && $is_multi ) { 82 // it's a multi-widget. We only need to show it in the list once. 83 $already_shown[] = $widget['callback']; 84 $num = (int) array_pop( $ids = explode( '-', $widget['id'] ) ); 85 $id_base = $wp_registered_widget_controls[$widget['id']]['id_base']; 86 // so that we always add a new one when clicking "add" 87 while ( isset($wp_registered_widgets["$id_base-$num"]) ) 88 $num++; 89 $widget['id'] = "$id_base-$num"; 90 $add_query['base'] = $id_base; 91 $add_query['key'] = $num; 92 $add_query['sidebar'] = $GLOBALS['sidebar']; 93 } 94 $add_query['add'] = $widget['id']; 95 $action = 'add'; 96 $add_url = clean_url( wp_nonce_url( add_query_arg( $add_query ), "add-widget_$widget[id]" ) ); 67 68 $already_shown[] = $widget['callback']; 69 $no_widgets_shown = false; 70 71 $args = array( 'widget_id' => $widget['id'], 'widget_name' => $widget['name'], '_display' => 'template' ); 72 73 if ( isset($wp_registered_widget_controls[$widget['id']]['id_base']) && isset($widget['params'][0]['number']) ) { 74 $id_base = $wp_registered_widget_controls[$widget['id']]['id_base']; 75 $args['_temp_id'] = "$id_base-__i__"; 76 $args['_multi_num'] = next_widget_id_number($id_base); 77 $args['_add'] = 'multi'; 97 78 } else { 98 $action = 'edit'; 99 $edit_url = clean_url( add_query_arg( array( 100 'sidebar' => $sidebar, 101 'edit' => $widget['id'], 102 'key' => array_search( $widget['id'], $sidebars_widgets[$sidebar] ), 103 ) ) ); 104 105 $widget_control_template = '<textarea rows="1" cols="1">' . htmlspecialchars( $widget_control_template ) . '</textarea>'; 79 $args['_add'] = 'single'; 80 if ( $sidebar ) 81 $args['_hide'] = '1'; 106 82 } 107 83 108 $widget_control_template = $sidebar_args['before_widget'] . $widget_control_template . $sidebar_args['after_widget']; 109 110 $no_widgets_shown = false; 111 112 113 if ( 'all' != $show && $sidebar_args['_widget_title'] ) 114 $widget_title = $sidebar_args['_widget_title']; 115 else 116 $widget_title = $widget['name']; 117 ?> 118 119 <li id="widget-list-item-<?php echo attribute_escape( $widget['id'] ); ?>" class="widget-list-item"> 120 <h4 class="widget-title widget-draggable"> 121 122 <span><?php echo $widget_title; ?></span> 123 124 <?php if ( 'add' == $action ) : ?> 125 126 <a class="widget-action widget-control-add" href="<?php echo $add_url; ?>"><?php _e( 'Add' ); ?></a> 127 128 <?php elseif ( 'edit' == $action ) : 129 // We echo a hidden edit link for the sake of the JS. Edit links are shown (needlessly?) after a widget is added. 130 ?> 131 132 <a class="widget-action widget-control-edit" href="<?php echo $edit_url; ?>" style="display: none;"><?php _e( 'Edit' ); ?></a> 133 134 <?php endif; ?> 135 136 <br class="clear" /> 137 138 </h4> 139 140 141 <ul id="widget-control-info-<?php echo $widget['id']; ?>" class="widget-control-info"> 142 143 <?php echo $widget_control_template; ?> 144 145 </ul> 146 147 <?php if ( 'add' == $action ) : ?> 148 <?php endif; ?> 149 150 <div class="widget-description"> 151 <?php echo ( $widget_description = wp_widget_description( $widget_id ) ) ? $widget_description : ' '; ?> 152 </div> 153 154 <br class="clear" /> 155 156 </li> 157 158 <?php endforeach; if ( $no_widgets_shown ) : ?> 159 160 <li><?php _e( 'No matching widgets' ); ?></li> 161 162 <?php endif; ?> 163 84 $args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) ); 85 call_user_func_array( 'wp_widget_control', $args ); 86 } 87 88 if ( $no_widgets_shown ) 89 echo '<li>' . __( 'No matching widgets' ) . "</li>\n"; 90 ?> 164 91 </ul> 165 92 <?php … … 173 100 * @param string $sidebar 174 101 */ 175 function wp_list_widget_controls( $sidebar ) {102 function wp_list_widget_controls( $sidebar, $hide = false ) { 176 103 add_filter( 'dynamic_sidebar_params', 'wp_list_widget_controls_dynamic_sidebar' ); 177 104 ?> 178 105 179 <ul class="widget-control-list"> 180 181 <?php if ( !dynamic_sidebar( $sidebar ) ) echo "<li />"; ?> 182 106 <ul class="widgets-sortables<?php echo $hide ? ' hide-if-js' : ''; ?>"> 107 <?php dynamic_sidebar( $sidebar ); ?> 183 108 </ul> 184 109 … … 200 125 201 126 $widget_id = $params[0]['widget_id']; 202 203 $params[0]['before_widget'] = "<li id='widget-list-control-item-$i-$widget_id' class='widget-list-control-item widget-sortable'>\n"; 127 $id = isset($params[0]['_temp_id']) ? $params[0]['_temp_id'] : $widget_id; 128 $hidden = isset($params[0]['_hide']) ? ' style="display:none;"' : ''; 129 130 $params[0]['before_widget'] = "<li id='widget-${i}_$id' class='widget'$hidden>"; 204 131 $params[0]['after_widget'] = "</li>"; 205 $params[0]['before_title'] = "%BEG_OF_TITLE%"; 206 $params[0]['after_title'] = "%END_OF_TITLE%"; 132 $params[0]['before_title'] = "%BEG_OF_TITLE%"; // deprecated 133 $params[0]['after_title'] = "%END_OF_TITLE%"; // deprecated 207 134 if ( is_callable( $wp_registered_widgets[$widget_id]['callback'] ) ) { 208 135 $wp_registered_widgets[$widget_id]['_callback'] = $wp_registered_widgets[$widget_id]['callback']; 209 136 $wp_registered_widgets[$widget_id]['callback'] = 'wp_widget_control'; 210 137 } 138 211 139 return $params; 140 } 141 142 function next_widget_id_number($id_base) { 143 global $wp_registered_widgets; 144 $number = 2; 145 146 while ( isset($wp_registered_widgets["$id_base-$number"]) ) 147 $number++; 148 149 return $number; 212 150 } 213 151 … … 223 161 */ 224 162 function wp_widget_control( $sidebar_args ) { 225 global $wp_registered_widgets, $wp_registered_widget_controls, $sidebars_widgets, $edit_widget; 163 global $wp_registered_widgets, $wp_registered_widget_controls, $sidebars_widgets; 164 226 165 $widget_id = $sidebar_args['widget_id']; 227 166 $sidebar_id = isset($sidebar_args['id']) ? $sidebar_args['id'] : false; 228 167 229 $control = isset($wp_registered_widget_controls[$widget_id]) ? $wp_registered_widget_controls[$widget_id] : 0;168 $control = isset($wp_registered_widget_controls[$widget_id]) ? $wp_registered_widget_controls[$widget_id] : array(); 230 169 $widget = $wp_registered_widgets[$widget_id]; 231 170 232 171 $key = $sidebar_id ? array_search( $widget_id, $sidebars_widgets[$sidebar_id] ) : 'no-key'; // position of widget in sidebar 233 172 234 $edit = -1 < $edit_widget && is_numeric($key) && $edit_widget === $key; // (bool) are we currently editing this widget 173 $edit = isset($_GET['editwidget']); // editing without js 174 $nonce = $edit ? wp_create_nonce("edit-widget_$widget_id") : ''; 235 175 236 176 $id_format = $widget['id']; 237 177 238 if ( ! isset( $sidebar_args['_show'] ) ) 239 $sidebar_args['_show'] = ''; 240 241 if ( ! isset( $sidebar_args['_display'] ) ) 242 $sidebar_args['_display'] = ''; 178 $widget_number = isset($control['params'][0]['number']) ? $control['params'][0]['number'] : ''; 179 $add_new = $sidebar_args['_add']; 180 $id_base = isset($control['id_base']) ? $control['id_base'] : $widget_id; 243 181 244 182 // We aren't showing a widget control, we're outputing a template for a mult-widget control 245 if ( 'all' == $sidebar_args['_show'] && 'template' == $sidebar_args['_display'] && isset($control['params'][0]['number'])) {246 // number == -1 implies a template where id numbers are replaced by a generic ' %i%'183 if ( isset($sidebar_args['_display']) && 'template' == $sidebar_args['_display'] && $widget_number ) { 184 // number == -1 implies a template where id numbers are replaced by a generic '__i__' 247 185 $control['params'][0]['number'] = -1; 248 186 // if given, id_base means widget id's should be constructed like {$id_base}-{$id_number} 249 187 if ( isset($control['id_base']) ) 250 $id_format = $control['id_base'] . '-%i%'; 188 $id_format = $control['id_base'] . '-__i__'; 189 190 $multi_number = $sidebar_args['_multi_num']; 251 191 } 252 192 253 $widget_title = '';254 // We grab the normal widget output to find the widget's title255 if ( ( 'all' != $sidebar_args['_show'] || 'template' != $sidebar_args['_display'] ) && is_callable( $widget['_callback'] ) ) {256 ob_start();257 $args = func_get_args();258 call_user_func_array( $widget['_callback'], $args );259 $widget_title = ob_get_clean();260 $widget_title = wp_widget_control_ob_filter( $widget_title );261 }262 193 $wp_registered_widgets[$widget_id]['callback'] = $wp_registered_widgets[$widget_id]['_callback']; 263 194 unset($wp_registered_widgets[$widget_id]['_callback']); 264 195 265 if ( $widget_title && $widget_title != $sidebar_args['widget_name'] ) 266 /* translators: 1: widget name, 2: widget title */ 267 $widget_title = sprintf( _x('%1$s: %2$s', 'widget' ), $sidebar_args['widget_name'], $widget_title ); 268 else 269 $widget_title = wp_specialchars( strip_tags( $sidebar_args['widget_name'] ) ); 270 271 $sidebar_args['_widget_title'] = $widget_title; 272 273 if ( empty($sidebar_args['_display']) || 'template' != $sidebar_args['_display'] ) 274 echo $sidebar_args['before_widget']; 275 ?> 196 $widget_title = wp_specialchars( strip_tags( $sidebar_args['widget_name'] ) ); 197 198 echo $sidebar_args['before_widget']; ?> 276 199 <div class="widget-top"> 277 <h4 class="widget-title"><span><?php echo $widget_title ?></span> 278 279 <?php if ( $edit ) : ?> 280 281 <a class="widget-action widget-control-edit" href="<?php echo clean_url( remove_query_arg( array( 'edit', 'key' ) ) ); ?>"><?php _e('Cancel'); ?></a> 282 283 <?php else : ?> 284 285 <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> 286 287 <?php endif; ?> 288 289 <br class="clear" /> 290 291 </h4></div> 292 293 <div class="widget-control"<?php if ( $edit ) echo ' style="display: block;"'; ?>> 294 295 <?php 296 if ( $control ) 200 <div class="widget-title-action"> 201 <?php if ( !$edit ) { ?> 202 <a class="widget-action widget-control-edit" href="<?php echo clean_url( add_query_arg( array( 'edit' => $id_format, 'key' => $key ) ) ); ?>"></a> 203 <?php } ?> 204 </div> 205 <div class="widget-title"><h4><?php echo $widget_title ?></h4></div> 206 </div> 207 208 <div class="widget-inside"> 209 <form action="" method="post"> 210 <div class="widget-control"> 211 <?php 212 if ( isset($control['callback']) ) 297 213 call_user_func_array( $control['callback'], $control['params'] ); 298 214 else 299 echo '<p>' . __('There are no options for this widget.') . '</p>'; 300 ?> 301 302 <input type="hidden" name="widget-id[]" value="<?php echo $id_format; ?>" /> 303 <input type="hidden" class="widget-width" value="<?php echo $control['width']; ?>" /> 215 echo "\t\t<p>" . __('There are no options for this widget.') . "</p>\n"; ?> 216 217 <input type="hidden" name="widget-id" class="widget-id" value="<?php echo $id_format; ?>" /> 218 <input type="hidden" name="id_base" class="id_base" value="<?php echo $id_base; ?>" /> 219 <input type="hidden" name="widget-width" value="<?php echo $control['width']; ?>" /> 220 <input type="hidden" name="widget-height" value="<?php echo $control['height']; ?>" /> 221 <input type="hidden" name="widget_number" class="widget_number" value="<?php echo $widget_number; ?>" /> 222 <input type="hidden" name="add_new" class="add_new" value="<?php echo $add_new; ?>" /> 223 <?php 224 if ( isset($multi_number) ) 225 echo "\t\t\t<input type='hidden' name='multi_number' class='multi_number' value='$multi_number' />\n"; ?> 304 226 305 227 <div class="widget-control-actions"> 306 307 <?php if ( $control ) : ?> 308 309 <a class="button widget-action widget-control-save hide-if-no-js edit alignleft" href="#save:<?php echo $id_format; ?>"><?php _e('Done'); ?></a> 310 311 <?php endif; ?> 312 313 <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> 228 <a class="button widget-control-remove alignleft" href="<?php echo $edit ? clean_url( add_query_arg( array( 'remove' => $id_format, 'key' => $key, '_wpnonce' => $nonce ) ) ) : '#remove'; ?>"><?php _e('Remove'); ?></a> 229 <?php if ( !empty($control) ) { ?> 230 <a class="button-primary widget-control-save alignright" href="<?php echo $edit ? clean_url( add_query_arg( array( 'save' => $id_format, 'key' => $key, '_wpnonce' => $nonce ) ) ) : '#save'; ?>"><?php _e('Save'); ?></a> 231 <?php } ?> 314 232 <br class="clear" /> 315 233 </div> 316 234 </div> 317 <?php 318 if ( empty($sidebar_args['_display']) || 'template' != $sidebar_args['_display'] ) 319 echo $sidebar_args['after_widget']; 235 </form> 236 <div class="widget-description"> 237 <?php echo ( $widget_description = wp_widget_description($widget_id) ) ? "$widget_description\n" : "$widget_title\n"; ?> 238 </div> 239 </div> 240 <?php 241 echo $sidebar_args['after_widget']; 242 320 243 return $sidebar_args; 321 244 } 322 245 323 /**324 * {@internal Missing Short Description}}325 *326 * @since unknown327 *328 * @param string $string329 * @return string330 */331 function wp_widget_control_ob_filter( $string ) {332 if ( false === $beg = strpos( $string, '%BEG_OF_TITLE%' ) )333 return '';334 if ( false === $end = strpos( $string, '%END_OF_TITLE%' ) )335 return '';336 $string = substr( $string, $beg + 14 , $end - $beg - 14);337 $string = str_replace( ' ', ' ', $string );338 return trim( wp_specialchars( strip_tags( $string ) ) );339 }340 341 ?> -
trunk/wp-admin/js/widgets.dev.js
r10326 r10912 1 jQuery(function($) {2 $('.noscript-action').remove();3 1 4 var reminded = false; 5 var lameWidgetReminder = function() { 6 if ( reminded ) 7 return; 8 window.onbeforeunload = function () { return widgetsL10n.lamerReminder }; 9 $('h2:first').after( '<div class="updated"><p>' + widgetsL10n.lameReminder + '</p></div>' ); 10 $('#current-widgets .submit input[name=save-widgets]').css( 'background-color', '#ffffe0' ).click( function() { 11 window.onbeforeunload = null; 12 } ); 13 reminded = true; 14 }; 2 var wpWidgets; 3 (function($) { 15 4 16 var increment = 1; 5 wpWidgets = { 6 init : function() { 7 var rem; 8 $('h3.sidebar-name').click(function(){ 9 var c = $(this).siblings('.widgets-sortables'); 10 if ( c.is(':visible') ) { 11 c.hide().sortable('disable'); 12 } else { 13 c.show().sortable('enable').sortable('refresh'); 14 } 15 $(this).siblings('#widget-list').toggle(); 16 }); 17 this.addEvents(); 17 18 18 // Open or close widget control form 19 var toggleWidget = function( li, disableFields ) { 20 var width = li.find('input.widget-width').val(); 19 $('#widget-list .widget').draggable({ 20 connectToSortable: '.widgets-sortables', 21 handle: '.widget-title', 22 distance: 2, 23 tolerance: 'pointer', 24 // forcePlaceholderSize: true, 25 helper: 'clone', 26 start: function() { 27 wpWidgets.fixWebkit(1); 28 }, 29 stop: function(e,ui) { 30 if ( rem ) 31 $(rem).hide(); 32 rem = ''; 33 wpWidgets.fixWebkit(); 34 } 35 }); 21 36 22 // it seems IE chokes on these animations because of the positioning/floating 23 var widgetAnim = $.browser.msie ? function() { 24 var t = $(this); 25 if ( t.is(':visible') ) { 26 if ( disableFields ) { t.find( ':input:enabled' ).not( '[name="widget-id[]"], [name*="[submit]"]' ).attr( 'disabled', 'disabled' ); } 27 li.css( 'marginLeft', 0 ); 28 t.siblings('div').children('h4').children('a').text( widgetsL10n.edit ); 29 } else { 30 t.find( ':disabled' ).attr( 'disabled', '' ); // always enable on open 31 if ( width > 250 ) 32 li.css( 'marginLeft', ( width - 250 ) * -1 ); 33 t.siblings('div').children('h4').children('a').text( widgetsL10n.cancel ); 37 $('.widgets-sortables').sortable({ 38 placeholder: 'widget-placeholder', 39 connectWith: '.widgets-sortables', 40 items: '.widget', 41 handle: '.widget-title', 42 cursor: 'move', 43 distance: 2, 44 tolerance: 'pointer', 45 // forcePlaceholderSize: true, 46 // helper: 'clone', 47 opacity: 0.65, 48 start: function(e,ui) { 49 wpWidgets.fixWebkit(1); 50 }, 51 stop: function(e,ui) { 52 var add = ui.item.find('input.add_new').val(), n = ui.item.find('input.multi_number').val(), id = ui.item.attr('id'), sb = $(this).parent().attr('id'); 53 54 if ( add ) { 55 if ( 'multi' == add ) { 56 ui.item.html( ui.item.html().replace(/<[^<>]+>/g, function(m){ return m.replace(/__i__/g, n); }) ); 57 ui.item.attr( 'id', id.replace(/__i__/g, n) ); 58 n++; 59 $('li#' + id).find('input.multi_number').val(n); 60 } else if ( 'single' == add ) { 61 ui.item.attr( 'id', 'new-' + id ); 62 rem = 'li#' + id; 63 } 64 wpWidgets.addEvents(ui.item); 65 wpWidgets.save( ui.item.find('form').serializeArray(), sb, 0 ); 66 ui.item.find('input.add_new').val(''); 67 } 68 wpWidgets.saveOrder(sb); 69 wpWidgets.fixWebkit(); 70 }, 71 receive: function(e,ui) { 72 if ( !$(this).is(':visible') ) 73 $(this).sortable('cancel'); 34 74 } 35 t.toggle();36 } : function() {37 var t = $(this);38 75 39 if ( t.is(':visible') ) { 40 if ( disableFields ) { t.find( ':input:enabled' ).not( '[name="widget-id[]"], [name*="[submit]"]' ).attr( 'disabled', 'disabled' ); } 41 if ( width > 250 ) 42 li.animate( { marginLeft: 0 } ); 43 t.siblings('div').children('h4').children('a').text( widgetsL10n.edit ); 44 } else { 45 t.find( ':disabled' ).attr( 'disabled', '' ); // always enable on open 46 if ( width > 250 ) 47 li.animate( { marginLeft: ( width - 250 ) * -1 } ); 48 t.siblings('div').children('h4').children('a').text( widgetsL10n.cancel ); 49 } 50 t.animate( { height: 'toggle' } ); 76 }).not(':visible').sortable('disable'); 77 }, 78 79 saveOrder : function(sb) { 80 $('#' + sb + ' .ajax-feedback').css('visibility', 'visible'); 81 var p = { 82 action: 'widgets-order', 83 savewidgets: $('#_wpnonce_widgets').val() 84 }; 85 $('.widgets-sortables').each( function() { 86 p[$(this).parent().attr('id')] = $(this).sortable('toArray').join(','); 87 }); 88 $.post( ajaxurl, p, function(){ 89 $('.ajax-feedback').css('visibility', 'hidden'); 90 }); 91 }, 92 93 save : function(data, sb, del, t) { 94 var a; 95 sb = sb || ''; 96 $('#' + sb + ' .ajax-feedback').css('visibility', 'visible'); 97 98 a = { 99 action: 'save-widget', 100 savewidgets: $('#_wpnonce_widgets').val(), 101 sidebar: sb 51 102 }; 52 103 53 return li.children('div.widget-control').each( widgetAnim ).end();54 };104 if ( del ) 105 a['delete_widget'] = 1; 55 106 56 // onclick for edit/cancel links 57 var editClick = function() { 58 var q = wpAjax.unserialize( this.href ); 59 // if link is in available widgets list, make sure it points to the current sidebar 60 if ( ( q.sidebar && q.sidebar == $('#sidebar').val() ) || q.add ) { 61 var w = q.edit || q.add; 62 toggleWidget( $('#current-sidebar .widget-control-list input[name^="widget-id"][value=' + w + ']').parents('li:first'), false ).blur(); 107 $.map(data, function(n,i){ a[n.name] = n.value; }); 108 109 $.post( ajaxurl, a, function(r){ 110 var id; 111 $('.ajax-feedback').css('visibility', 'hidden'); 112 if ( !t ) 113 return; 114 115 if ( del ) { 116 $(t).parents('li.widget').remove(); 117 if ( !a.widget_number ) { 118 id = a['widget-id']; 119 $('#available-widgets .widget-id').each(function(){ 120 if ( $(this).val() == id ) 121 $(this).parents('li.widget').show(); 122 }); 123 } 124 } else { 125 $(t).parents('.widget-inside').hide(); 126 } 127 }); 128 }, 129 130 fixWebkit : function(n) { 131 n = n ? 'none' : ''; 132 $('body').css({ 133 WebkitUserSelect: n, 134 KhtmlUserSelect: n 135 }); 136 }, 137 138 addEvents : function(sc) { 139 sc = sc || document; 140 $('a.widget-action', sc).click(function(){ 141 $(this).parents('.widget-top').siblings('.widget-inside').toggle(); 142 return false; 143 }); 144 $('.widget-control-save', sc).click(function(){ 145 wpWidgets.save( $(this).parents('form').serializeArray(), $(this).parents('.widgets-holder-wrap').attr('id'), 0, this ); 63 146 return false; 64 } else if ( q.sidebar ) { // otherwise, redirect to correct page 65 return true; 66 } 67 68 // If link is in current widgets list, just open the form 69 toggleWidget( $(this).parents('li:first'), true ).blur(); 70 return false; 71 }; 72 73 // onclick for add links 74 var addClick = function() { 75 var oldLi = $(this).parents('li:first').find('ul.widget-control-info li'); 76 var newLi = oldLi.clone(); 77 78 if ( newLi.html().match( /%i%/ ) ) { 79 // supplid form is a template, replace %i% by unique id 80 var i = $('#generated-time').val() + increment.toString(); 81 increment++; 82 newLi.html( newLi.html().replace( /%i%/g, i ) ); 83 } else { 84 $(this).text( widgetsL10n.edit ).unbind().click( editClick ); 85 // save form content in textarea so we don't have any conflicting HTML ids 86 oldLi.html( '<textarea>' + oldLi.html() + '</textarea>' ); 87 } 88 89 // add event handlers 90 addWidgetControls( newLi ); 91 92 // add widget to sidebar sortable 93 widgetSortable.append( newLi ).SortableAddItem( newLi[0] ); 94 95 // increment widget counter 96 var n = parseInt( $('#widget-count').text(), 10 ) + 1; 97 $('#widget-count').text( n.toString() ) 98 99 lameWidgetReminder(); 100 return false; 101 }; 102 103 // add event handlers to all links found in context 104 var addWidgetControls = function( context ) { 105 if ( !context ) 106 context = document; 107 108 $('a.widget-control-edit', context).click( editClick ); 109 110 // onclick for save links 111 $('a.widget-control-save', context).click( function() { 112 lameWidgetReminder(); 113 toggleWidget( $(this).parents('li:first'), false ).blur() 147 }); 148 $('.widget-control-remove', sc).click(function(){ 149 wpWidgets.save( $(this).parents('form').serializeArray(), $(this).parents('.widgets-holder-wrap').attr('id'), 1, this ); 114 150 return false; 115 } ); 116 117 // onclick for remove links 118 $('a.widget-control-remove', context).click( function() { 119 var w = $(this).parents('li:first').find('input[name^="widget-id"]').val(); 120 $(this).parents('li:first').remove(); 121 var t = $('#widget-list ul#widget-control-info-' + w + ' textarea'); 122 t.parent().html( t.text() ).parents('li.widget-list-item:first').children( 'h4' ).children('a.widget-action') 123 .show().text( widgetsL10n.add ).unbind().click( addClick ); 124 var n = parseInt( $('#widget-count').text(), 10 ) - 1; 125 $('#widget-count').text( n.toString() ) 126 return false; 127 } ); 151 }); 128 152 } 129 153 130 addWidgetControls(); 154 }; 155 $(document).ready(function(){wpWidgets.init();}); 131 156 132 $('a.widget-control-add').click( addClick ); 133 134 var widgetSortable; 135 var widgetSortableInit = function() { 136 try { // a hack to make sortables work in jQuery 1.2+ and IE7 137 $('#current-sidebar .widget-control-list').SortableDestroy(); 138 } catch(e) {} 139 widgetSortable = $('#current-sidebar .widget-control-list').Sortable( { 140 accept: 'widget-sortable', 141 helperclass: 'sorthelper', 142 handle: 'h4.widget-title', 143 onStop: widgetSortableInit 144 } ); 145 } 146 147 // initialize sortable 148 widgetSortableInit(); 149 150 }); 157 })(jQuery); -
trunk/wp-admin/js/widgets.js
r10326 r10912 1 jQuery(function(e){e(".noscript-action").remove();var a=false;var h=function(){if(a){return}window.onbeforeunload=function(){return widgetsL10n.lamerReminder};e("h2:first").after('<div class="updated"><p>'+widgetsL10n.lameReminder+"</p></div>");e("#current-widgets .submit input[name=save-widgets]").css("background-color","#ffffe0").click(function(){window.onbeforeunload=null});a=true};var j=1;var g=function(k,m){var l=k.find("input.widget-width").val();var n=e.browser.msie?function(){var o=e(this);if(o.is(":visible")){if(m){o.find(":input:enabled").not('[name="widget-id[]"], [name*="[submit]"]').attr("disabled","disabled")}k.css("marginLeft",0);o.siblings("div").children("h4").children("a").text(widgetsL10n.edit)}else{o.find(":disabled").attr("disabled","");if(l>250){k.css("marginLeft",(l-250)*-1)}o.siblings("div").children("h4").children("a").text(widgetsL10n.cancel)}o.toggle()}:function(){var o=e(this);if(o.is(":visible")){if(m){o.find(":input:enabled").not('[name="widget-id[]"], [name*="[submit]"]').attr("disabled","disabled")}if(l>250){k.animate({marginLeft:0})}o.siblings("div").children("h4").children("a").text(widgetsL10n.edit)}else{o.find(":disabled").attr("disabled","");if(l>250){k.animate({marginLeft:(l-250)*-1})}o.siblings("div").children("h4").children("a").text(widgetsL10n.cancel)}o.animate({height:"toggle"})};return k.children("div.widget-control").each(n).end()};var b=function(){var l=wpAjax.unserialize(this.href);if((l.sidebar&&l.sidebar==e("#sidebar").val())||l.add){var k=l.edit||l.add;g(e('#current-sidebar .widget-control-list input[name^="widget-id"][value='+k+"]").parents("li:first"),false).blur();return false}else{if(l.sidebar){return true}}g(e(this).parents("li:first"),true).blur();return false};var c=function(){var o=e(this).parents("li:first").find("ul.widget-control-info li");var l=o.clone();if(l.html().match(/%i%/)){var k=e("#generated-time").val()+j.toString();j++;l.html(l.html().replace(/%i%/g,k))}else{e(this).text(widgetsL10n.edit).unbind().click(b);o.html("<textarea>"+o.html()+"</textarea>")}f(l);i.append(l).SortableAddItem(l[0]);var m=parseInt(e("#widget-count").text(),10)+1;e("#widget-count").text(m.toString());h();return false};var f=function(k){if(!k){k=document}e("a.widget-control-edit",k).click(b);e("a.widget-control-save",k).click(function(){h();g(e(this).parents("li:first"),false).blur();return false});e("a.widget-control-remove",k).click(function(){var l=e(this).parents("li:first").find('input[name^="widget-id"]').val();e(this).parents("li:first").remove();var m=e("#widget-list ul#widget-control-info-"+l+" textarea");m.parent().html(m.text()).parents("li.widget-list-item:first").children("h4").children("a.widget-action").show().text(widgetsL10n.add).unbind().click(c);var o=parseInt(e("#widget-count").text(),10)-1;e("#widget-count").text(o.toString());return false})};f();e("a.widget-control-add").click(c);var i;var d=function(){try{e("#current-sidebar .widget-control-list").SortableDestroy()}catch(k){}i=e("#current-sidebar .widget-control-list").Sortable({accept:"widget-sortable",helperclass:"sorthelper",handle:"h4.widget-title",onStop:d})};d()});1 var wpWidgets;(function(a){wpWidgets={init:function(){var b;a("h3.sidebar-name").click(function(){var d=a(this).siblings(".widgets-sortables");if(d.is(":visible")){d.hide().sortable("disable")}else{d.show().sortable("enable").sortable("refresh")}a(this).siblings("#widget-list").toggle()});this.addEvents();a("#widget-list .widget").draggable({connectToSortable:".widgets-sortables",handle:".widget-title",distance:2,tolerance:"pointer",helper:"clone",start:function(){wpWidgets.fixWebkit(1)},stop:function(d,c){if(b){a(b).hide()}b="";wpWidgets.fixWebkit()}});a(".widgets-sortables").sortable({placeholder:"widget-placeholder",connectWith:".widgets-sortables",items:".widget",handle:".widget-title",cursor:"move",distance:2,tolerance:"pointer",opacity:0.65,start:function(d,c){wpWidgets.fixWebkit(1)},stop:function(f,c){var d=c.item.find("input.add_new").val(),i=c.item.find("input.multi_number").val(),h=c.item.attr("id"),g=a(this).parent().attr("id");if(d){if("multi"==d){c.item.html(c.item.html().replace(/<[^<>]+>/g,function(e){return e.replace(/__i__/g,i)}));c.item.attr("id",h.replace(/__i__/g,i));i++;a("li#"+h).find("input.multi_number").val(i)}else{if("single"==d){c.item.attr("id","new-"+h);b="li#"+h}}wpWidgets.addEvents(c.item);wpWidgets.save(c.item.find("form").serializeArray(),g,0);c.item.find("input.add_new").val("")}wpWidgets.saveOrder(g);wpWidgets.fixWebkit()},receive:function(d,c){if(!a(this).is(":visible")){a(this).sortable("cancel")}}}).not(":visible").sortable("disable")},saveOrder:function(c){a("#"+c+" .ajax-feedback").css("visibility","visible");var b={action:"widgets-order",savewidgets:a("#_wpnonce_widgets").val()};a(".widgets-sortables").each(function(){b[a(this).parent().attr("id")]=a(this).sortable("toArray").join(",")});a.post(ajaxurl,b,function(){a(".ajax-feedback").css("visibility","hidden")})},save:function(e,f,c,d){var b;f=f||"";a("#"+f+" .ajax-feedback").css("visibility","visible");b={action:"save-widget",savewidgets:a("#_wpnonce_widgets").val(),sidebar:f};if(c){b.delete_widget=1}a.map(e,function(h,g){b[h.name]=h.value});a.post(ajaxurl,b,function(g){var h;a(".ajax-feedback").css("visibility","hidden");if(!d){return}if(c){a(d).parents("li.widget").remove();if(!b.widget_number){h=b["widget-id"];a("#available-widgets .widget-id").each(function(){if(a(this).val()==h){a(this).parents("li.widget").show()}})}}else{a(d).parents(".widget-inside").hide()}})},fixWebkit:function(b){b=b?"none":"";a("body").css({WebkitUserSelect:b,KhtmlUserSelect:b})},addEvents:function(b){b=b||document;a("a.widget-action",b).click(function(){a(this).parents(".widget-top").siblings(".widget-inside").toggle();return false});a(".widget-control-save",b).click(function(){wpWidgets.save(a(this).parents("form").serializeArray(),a(this).parents(".widgets-holder-wrap").attr("id"),0,this);return false});a(".widget-control-remove",b).click(function(){wpWidgets.save(a(this).parents("form").serializeArray(),a(this).parents(".widgets-holder-wrap").attr("id"),1,this);return false})}};a(document).ready(function(){wpWidgets.init()})})(jQuery); -
trunk/wp-admin/widgets.php
r10798 r10912 16 16 wp_die( __( 'Cheatin’ uh?' )); 17 17 18 wp_enqueue_script( array( 'wp-lists', 'admin-widgets' ));18 wp_enqueue_script('admin-widgets'); 19 19 wp_admin_css( 'widgets' ); 20 20 … … 24 24 $parent_file = 'themes.php'; 25 25 26 // $sidebar = What sidebar are we editing? 27 if ( isset($_GET['sidebar']) && isset($wp_registered_sidebars[$_GET['sidebar']]) ) { 28 $sidebar = attribute_escape( $_GET['sidebar'] ); 29 } elseif ( is_array($wp_registered_sidebars) && !empty($wp_registered_sidebars) ) { 30 // By default we look at the first defined sidebar 31 $sidebar = array_shift( $keys = array_keys($wp_registered_sidebars) ); 32 } else { 33 // If no sidebars, die. 26 // register the inactive_widgets area as sidebar 27 register_sidebar(array( 28 'name' => '', 29 'id' => 'wp_inactive_widgets', 30 'before_widget' => '', 31 'after_widget' => '', 32 'before_title' => '', 33 'after_title' => '', 34 )); 35 36 // These are the widgets grouped by sidebar 37 $sidebars_widgets = wp_get_sidebars_widgets(); 38 if ( empty( $sidebars_widgets ) ) 39 $sidebars_widgets = wp_get_widget_defaults(); 40 41 // look for "lost" widgets, perhaps run only after changin themes 42 function retrieve_widgets() { 43 global $wp_registered_widget_updates, $wp_registered_sidebars, $sidebars_widgets; 44 45 $key_sidebars = array_keys( (array) $wp_registered_sidebars); 46 $key_widgets = array_keys($sidebars_widgets); 47 if ( count($key_widgets) > count($key_sidebars) ) { 48 $changed_sidebars = array_diff( $key_widgets, $key_sidebars ); 49 foreach ( $changed_sidebars as $lost ) { 50 if ( is_array($sidebars_widgets[$lost]) ) 51 $sidebars_widgets['wp_inactive_widgets'] = array_merge( (array) $sidebars_widgets['wp_inactive_widgets'], $sidebars_widgets[$lost] ); 52 unset($sidebars_widgets[$lost]); 53 } 54 } 55 56 $shown_widgets = array(); 57 foreach ( $sidebars_widgets as $sidebar ) { 58 if ( is_array($sidebar) ) 59 $shown_widgets = array_merge($shown_widgets, $sidebar); 60 } 61 62 $all_widgets = array(); 63 foreach ( $wp_registered_widget_updates as $key => $val ) { 64 if ( isset($val['id_base']) ) 65 $all_widgets[] = $val['id_base']; 66 else 67 $all_widgets[] = $key; 68 } 69 70 $all_widgets = array_unique($all_widgets); 71 72 $lost_widgets = array(); 73 foreach ( $all_widgets as $name ) { 74 $data = get_option( str_replace('-', '_', "widget_$name") ); 75 if ( is_array($data) ) { 76 foreach ( $data as $num => $value ) { 77 if ( !is_numeric($num) ) // skip single widgets, some don't delete their settings 78 continue; 79 if ( is_array($value) && !in_array("$name-$num", $shown_widgets, true) ) 80 $lost_widgets[] = "$name-$num"; 81 } 82 } 83 } 84 85 $sidebars_widgets['wp_inactive_widgets'] = array_merge($lost_widgets, (array) $sidebars_widgets['wp_inactive_widgets']); 86 wp_set_sidebars_widgets($sidebars_widgets); 87 } 88 retrieve_widgets(); 89 90 if ( count($wp_registered_sidebars) == 1 ) { 91 // If only the "wp_inactive_widgets" is defined the theme has no sidebars, die. 34 92 require_once( 'admin-header.php' ); 35 93 ?> … … 49 107 } 50 108 51 // These are the widgets grouped by sidebar 52 $sidebars_widgets = wp_get_sidebars_widgets(); 53 if ( empty( $sidebars_widgets ) ) 54 $sidebars_widgets = wp_get_widget_defaults(); 55 56 // for the sake of PHP warnings 57 if ( empty( $sidebars_widgets[$sidebar] ) ) 58 $sidebars_widgets[$sidebar] = array(); 59 60 $http_post = 'post' == strtolower($_SERVER['REQUEST_METHOD']); 61 62 // We're updating a sidebar 63 if ( $http_post && isset($sidebars_widgets[$_POST['sidebar']]) ) { 64 check_admin_referer( 'edit-sidebar_' . $_POST['sidebar'] ); 65 66 /* Hack #1 67 * The widget_control is overloaded. It updates the widget's options AND echoes out the widget's HTML form. 68 * Since we want to update before sending out any headers, we have to catch it with an output buffer, 69 */ 70 ob_start(); 71 /* There can be multiple widgets of the same type, but the widget_control for that 72 * widget type needs only be called once if it's a multi-widget. 73 */ 74 $already_done = array(); 75 76 foreach ( $wp_registered_widget_updates as $name => $control ) { 77 if ( in_array( $control['callback'], $already_done ) ) 78 continue; 79 80 if ( is_callable( $control['callback'] ) ) { 81 call_user_func_array( $control['callback'], $control['params'] ); 82 $control_output = ob_get_contents(); 83 if ( false !== strpos( $control_output, '%i%' ) ) // if it's a multi-widget, only call control function once. 84 $already_done[] = $control['callback']; 85 } 86 87 ob_clean(); 88 } 89 ob_end_clean(); 90 91 // Prophylactic. Take out empty ids. 92 if ( isset($_POST['widget-id']) ) { 93 foreach ( (array) $_POST['widget-id'] as $key => $val ) { 94 if ( !$val ) 95 unset($_POST['widget-id'][$key]); 96 } 97 } 98 99 // Reset the key numbering and store 100 $new_sidebar = isset( $_POST['widget-id'] ) && is_array( $_POST['widget-id'] ) ? array_values( $_POST['widget-id'] ) : array(); 101 $sidebars_widgets[$_POST['sidebar']] = $new_sidebar; 102 wp_set_sidebars_widgets( $sidebars_widgets ); 103 104 wp_redirect( add_query_arg( 'message', 'updated' ) ); 105 exit; 106 } 107 108 // What widget (if any) are we editing 109 $edit_widget = -1; 110 111 $query_args = array('add', 'remove', 'key', 'edit', '_wpnonce', 'message', 'base' ); 112 113 if ( isset($_GET['add']) && $_GET['add'] ) { 114 // Add to the end of the sidebar 115 $control_callback; 116 if ( isset($wp_registered_widgets[$_GET['add']]) ) { 117 check_admin_referer( "add-widget_$_GET[add]" ); 118 $sidebars_widgets[$sidebar][] = $_GET['add']; 119 wp_set_sidebars_widgets( $sidebars_widgets ); 120 } elseif ( isset($_GET['base']) && isset($_GET['key']) ) { // It's a multi-widget 121 check_admin_referer( "add-widget_$_GET[add]" ); 122 // Copy minimal info from an existing instance of this widget to a new instance 123 foreach ( $wp_registered_widget_controls as $control ) { 124 if ( $_GET['base'] === $control['id_base'] ) { 125 $control_callback = $control['callback']; 126 $num = (int) $_GET['key']; 127 $control['params'][0]['number'] = $num; 128 $control['id'] = $control['id_base'] . '-' . $num; 129 $wp_registered_widget_controls[$control['id']] = $control; 130 $sidebars_widgets[$sidebar][] = $control['id']; 131 break; 132 } 133 } 134 } 135 136 // it's a multi-widget. The only way to add multi-widgets without JS is to actually submit POST content... 137 // so here we go 138 if ( is_callable( $control_callback ) ) { 139 require_once( 'admin-header.php' ); 140 ?> 141 <div class="wrap"> 142 <h2><?php _e( 'Add Widget' ); ?></h2> 143 <br /> 144 <form action="<?php echo clean_url( remove_query_arg( $query_args ) ); ?>" method="post"> 145 146 <ul class="widget-control-list"> 147 <li class="widget-list-control-item"> 148 <div class="widget-top"> 149 <h4 class="widget-title"><?php echo $control['name']; ?></h4> 150 </div> 151 <div class="widget-control" style="display: block;"> 152 <?php 153 call_user_func_array( $control_callback, $control['params'] ); 154 ?> 155 <div class="widget-control-actions"> 156 <input type="submit" class="button" value="<?php _e( 'Add Widget' ); ?>" /> 157 <input type="hidden" id='sidebar' name='sidebar' value="<?php echo $sidebar; ?>" /> 158 <?php wp_nonce_field ( 'edit-sidebar_' . $sidebar ); 159 foreach ( $sidebars_widgets[$sidebar] as $sidebar_widget_id ) : ?> 160 <input type="hidden" name='widget-id[]' value="<?php echo $sidebar_widget_id; ?>" /> 161 <?php endforeach; ?> 162 </div> 163 </div> 164 </li> 165 </ul> 166 </form> 167 </div> 168 <?php 169 170 require_once( 'admin-footer.php' ); 171 exit; 172 } 173 wp_redirect( remove_query_arg( $query_args ) ); 174 exit; 175 } elseif ( isset($_GET['remove']) && $_GET['remove'] && isset($_GET['key']) && is_numeric($_GET['key']) ) { 176 // Remove from sidebar the widget of type $_GET['remove'] and in position $_GET['key'] 177 $key = (int) $_GET['key']; 178 if ( -1 < $key && ( $keys = array_keys($sidebars_widgets[$sidebar], $_GET['remove']) ) && in_array($key, $keys) ) { 179 check_admin_referer( "remove-widget_$_GET[remove]" ); 180 unset($sidebars_widgets[$sidebar][$key]); 181 $sidebars_widgets[$sidebar] = array_values($sidebars_widgets[$sidebar]); 182 wp_set_sidebars_widgets( $sidebars_widgets ); 183 } 184 wp_redirect( remove_query_arg( $query_args ) ); 185 exit; 186 } elseif ( isset($_GET['edit']) && $_GET['edit'] && isset($_GET['key']) && is_numeric($_GET['key']) ) { 187 // Edit widget of type $_GET['edit'] and position $_GET['key'] 188 $key = (int) $_GET['key']; 189 if ( -1 < $key && ( $keys = array_keys($sidebars_widgets[$sidebar], $_GET['edit']) ) && in_array($key, $keys) ) 190 $edit_widget = $key; 191 } 192 193 // Total number of registered sidebars 194 $sidebar_widget_count = count($sidebars_widgets[$sidebar]); 195 196 // This is sort of lame since "widget" won't be converted to "widgets" in the JS 197 if ( 1 < $sidebars_count = count($wp_registered_sidebars) ) 198 $sidebar_info_text = _n( '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 ); 199 else 200 $sidebar_info_text = _n( 'You are using %1$s widget in the sidebar.', 'You are using %1$s widgets in the sidebar.', $sidebar_widget_count ); 201 202 203 $sidebar_info_text = sprintf( wp_specialchars( $sidebar_info_text ), "<span id='widget-count'>$sidebar_widget_count</span>", $wp_registered_sidebars[$sidebar]['name'] ); 204 205 $page = isset($_GET['apage']) ? abs( (int) $_GET['apage'] ) : 1; 206 207 /* TODO: Paginate widgets list 208 $page_links = paginate_links( array( 209 'base' => add_query_arg( 'apage', '%#%' ), 210 'format' => '', 211 'total' => ceil(($total = 105 )/ 10), 212 'current' => $page 213 )); 214 */ 215 $page_links = ' '; 216 109 /* 217 110 // Unsanitized! 218 111 $widget_search = isset($_GET['s']) ? $_GET['s'] : false; … … 224 117 'used' => __( 'Show used widgets' ) 225 118 ); 119 */ 226 120 227 121 $show = isset($_GET['show']) && isset($show_values[$_GET['show']]) ? attribute_escape( $_GET['show'] ) : false; … … 237 131 <?php endif; ?> 238 132 133 134 <div id="message" class="updated"><p>This page is not 100% ready, please use only on test installations.</p></div> 135 136 239 137 <div class="wrap"> 240 138 <?php screen_icon(); ?> 241 139 <h2><?php echo wp_specialchars( $title ); ?></h2> 242 140 141 142 <!-- 243 143 <form id="widgets-filter" action="" method="get"> 244 144 … … 248 148 <div class="nav"> 249 149 <select name="show" id="show"> 250 <?php foreach ( $show_values as $show_value => $show_text ) : $show_value = attribute_escape( $show_value ); ?>251 <option value='<?php echo $show_value; ?>'<?php selected( $show_value, $show ); ?>><?phpecho wp_specialchars( $show_text ); ?></option>252 <?php endforeach; ?>150 <?php //foreach ( $show_values as $show_value => $show_text ) : $show_value = attribute_escape( $show_value ); ?> 151 <option value='<?php //echo $show_value; ?>'<?php //selected( $show_value, $show ); ?>><?php //echo wp_specialchars( $show_text ); ?></option> 152 <?php //endforeach; ?> 253 153 </select> 254 154 <input type="submit" value="<?php _e('Show' ); ?>" class="button-secondary" /> 255 155 <p class="pagenav"> 256 <?php echo $page_links; ?>156 <?php // echo $page_links; ?> 257 157 </p> 258 158 </div> … … 265 165 <div class="nav"> 266 166 <select id="sidebar-selector" name="sidebar"> 267 <?php foreach ( $wp_registered_sidebars as $sidebar_id => $registered_sidebar ) : $sidebar_id = attribute_escape( $sidebar_id ); ?>268 <option value='<?php echo $sidebar_id; ?>'<?php selected( $sidebar_id, $sidebar ); ?>><?phpecho wp_specialchars( $registered_sidebar['name'] ); ?></option>269 <?php endforeach; ?>167 <?php //foreach ( $wp_registered_sidebars as $sidebar_id => $registered_sidebar ) : $sidebar_id = attribute_escape( $sidebar_id ); ?> 168 <option value='<?php //echo $sidebar_id; ?>'<?php selected( $sidebar_id, $open_sidebar ); ?>><?php //echo wp_specialchars( $registered_sidebar['name'] ); ?></option> 169 <?php //endforeach; ?> 270 170 </select> 271 171 <input type="submit" value="<?php _e('Show' ); ?>" class="button-secondary" /> … … 275 175 276 176 </form> 277 278 <div id="widget-content" class="widget-liquid-left-holder"> 279 280 <div id="available-widgets" class="widget-liquid-left"> 281 282 <?php wp_list_widgets( $show, $widget_search ); // This lists all the widgets for the query ( $show, $search ) ?> 283 284 <div class="nav"> 285 <p class="pagenav"> 286 <?php echo $page_links; ?> 287 </p> 288 </div> 289 </div> 290 </div> 291 292 <form id="widget-controls" action="" method="post"> 293 177 --> 178 179 <div class="widget-liquid-left"> 180 <div id="widgets-left"> 181 <div id="available-widgets" class="widgets-holder-wrap"> 182 <h3 class="sidebar-name"><?php _e('Available Widgets'); ?></h3> 183 <?php wp_list_widgets(); ?> 184 <br class="clear" /> 185 </div> 186 187 <div id="wp_inactive_widgets" class="widgets-holder-wrap"> 188 <h3 class="sidebar-name"><?php _e('Inactive Widgets'); ?> 189 <span><img src="images/loading-publish.gif" class="ajax-feedback" title="" alt="" /></span></h3> 190 <?php wp_list_widget_controls('wp_inactive_widgets'); ?> 191 <br class="clear" /> 192 </div> 193 </div> 194 </div> 195 196 <!-- 294 197 <div id="current-widgets-head" class="widget-liquid-right"> 295 198 296 199 <div id="sidebar-info"> 297 <p><?php echo $sidebar_info_text; ?></p>200 <p><?php //echo $sidebar_info_text; ?></p> 298 201 <p><?php _e( 'Add more from the Available Widgets section.' ); ?></p> 299 202 </div> 300 203 301 204 </div> 302 303 <div id="current-widgets" class="widget-liquid-right"> 304 <div id="current-sidebar"> 305 306 <?php wp_list_widget_controls( $sidebar ); // Show the control forms for each of the widgets in this sidebar ?> 307 308 </div> 309 310 <p class="submit"> 311 <input type="hidden" id='sidebar' name='sidebar' value="<?php echo $sidebar; ?>" /> 312 <input type="hidden" id="generated-time" name="generated-time" value="<?php echo time() - 1199145600; // Jan 1, 2008 ?>" /> 313 <input type="submit" name="save-widgets" class="button-primary" value="<?php _e( 'Save Changes' ); ?>" /> 314 <?php 315 wp_nonce_field( 'edit-sidebar_' . $sidebar ); 316 ?> 317 </p> 318 </div> 319 205 --> 206 207 <div class="widget-liquid-right"> 208 <?php 209 $i = 0; 210 foreach ( $wp_registered_sidebars as $sidebar => $registered_sidebar ) { 211 if ( 'wp_inactive_widgets' == $sidebar ) 212 continue; 213 ?> 214 <div id="<?php echo attribute_escape( $sidebar ); ?>" class="widgets-holder-wrap"> 215 <h3 class="sidebar-name"><?php echo wp_specialchars( $registered_sidebar['name'] ); ?> 216 <span><img src="images/loading-publish.gif" class="ajax-feedback" title="" alt="" /></span></h3> 217 <?php wp_list_widget_controls( $sidebar, $i ); // Show the control forms for each of the widgets in this sidebar ?> 218 </div> 219 <?php 220 $i++; 221 } ?> 222 </div> 223 <form action="" method="post"> 224 <?php wp_nonce_field( 'save-sidebar-widgets', '_wpnonce_widgets', false ); ?> 320 225 </form> 321 226 <br class="clear" /> 322 323 227 </div> 324 228 325 <?php do_action( 'sidebar_admin_page' ); ?> 326 327 <?php require_once( 'admin-footer.php' ); ?> 328 329 229 <?php 230 do_action( 'sidebar_admin_page' ); 231 require_once( 'admin-footer.php' ); -
trunk/wp-admin/wp-admin.css
r10872 r10912 1545 1545 } 1546 1546 1547 .ui-sortable .postbox h3 { 1548 cursor: pointer; 1547 .widget .widget-top, 1548 .postbox h3 { 1549 cursor: move; 1549 1550 -webkit-user-select: none; 1550 1551 -moz-user-select: none; … … 1553 1554 } 1554 1555 1555 . ui-sortable .postbox .hndle span {1556 .postbox .hndle span { 1556 1557 padding: 6px 0; 1557 1558 } 1558 1559 1559 . ui-sortable .postbox .hndle {1560 .postbox .hndle { 1560 1561 cursor: move; 1561 1562 } … … 1570 1571 } 1571 1572 1572 . meta-box-sortables .postbox .handlediv {1573 .postbox .handlediv { 1573 1574 float: right; 1574 1575 width: 23px; … … 1591 1592 } 1592 1593 1593 . metabox-holder .postbox,1594 #poststuff.postbox,1595 #poststuff.stuffbox {1594 .widget, 1595 .postbox, 1596 .stuffbox { 1596 1597 margin-bottom: 20px; 1597 1598 border-width: 1px; … … 1604 1605 } 1605 1606 1606 .metabox-holder .postbox h3, 1607 #poststuff .postbox h3, 1608 #poststuff .stuffbox h3 { 1607 .widget .widget-top, 1608 .postbox h3, 1609 .postbox h3, 1610 .stuffbox h3 { 1609 1611 -moz-border-radius: 6px 6px 0 0; 1610 1612 -webkit-border-top-right-radius: 6px; … … 3051 3053 clear: none; 3052 3054 } 3055 3056 .ajax-feedback { 3057 visibility: hidden; 3058 vertical-align: bottom; 3059 } -
trunk/wp-includes/default-widgets.php
r10896 r10912 141 141 <p> 142 142 <label for="<?php echo $this->get_field_id('category'); ?>"> 143 <select id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>" style="width: 97%;" />143 <select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>"> 144 144 <option value=""><?php _e('All Links'); ?></option> 145 145 <?php … … 150 150 } 151 151 ?> 152 </select></label><br /> 152 </select></label></p> 153 <p> 153 154 <label for="<?php echo $this->get_field_id('images'); ?>"> 154 155 <input class="checkbox" type="checkbox" <?php checked($instance['images'], true) ?> id="<?php echo $this->get_field_id('images'); ?>" name="<?php echo $this->get_field_name('images'); ?>" /> <?php _e('Show Link Image'); ?></label><br /> … … 185 186 echo $after_widget; 186 187 } 188 189 function form( $instance ) { ?> 190 <input name="<?php echo $this->get_field_name('title'); ?>" type="hidden" value="" /> 191 <?php 192 } 193 187 194 } 188 195 … … 883 890 $items = 10; 884 891 $error = false; 885 $number = ' %i%';892 $number = '__i__'; 886 893 $show_summary = 0; 887 894 $show_author = 0; -
trunk/wp-includes/script-loader.php
r10884 r10912 331 331 $scripts->add_data( 'media-upload', 'group', 1 ); 332 332 333 $scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'interface' ), '20090106' ); 334 $scripts->localize( 'admin-widgets', 'widgetsL10n', array( 335 'add' => __('Add'), 336 'edit' => __('Edit'), 337 'cancel' => __('Cancel'), 338 'lameReminder' => __('Remember to click the "Save Changes" button at the bottom of the Current Widgets column after you\'re all done!'), 339 'lamerReminder' => __("You're about to leave without having saved your changes!"), 340 'l10n_print_after' => 'try{convertEntities(widgetsL10n);}catch(e){};' 341 )); 333 $scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable' ), '20090411' ); 334 $scripts->add_data( 'admin-widgets', 'group', 1 ); 342 335 343 336 $scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array( 'jquery' ), '20090102' ); … … 426 419 $rtl_styles = array( 'global', 'colors', 'dashboard', 'ie', 'install', 'login', 'media', 'theme-editor', 'upload', 'widgets', 'press-this', 'plugin-install', 'farbtastic' ); 427 420 428 $styles->add( 'wp-admin', '/wp-admin/wp-admin.css', array(), '200904 05' );421 $styles->add( 'wp-admin', '/wp-admin/wp-admin.css', array(), '20090411' ); 429 422 $styles->add_data( 'wp-admin', 'rtl', '/wp-admin/rtl.css' ); 430 423 431 $styles->add( 'ie', '/wp-admin/css/ie.css', array(), '200904 07' );424 $styles->add( 'ie', '/wp-admin/css/ie.css', array(), '20090411' ); 432 425 $styles->add_data( 'ie', 'conditional', 'lte IE 7' ); 433 426 434 $styles->add( 'colors', true, array(), '200904 05' ); // Register "meta" stylesheet for admin colors427 $styles->add( 'colors', true, array(), '20090411' ); // Register "meta" stylesheet for admin colors 435 428 $styles->add( 'colors-fresh', '/wp-admin/css/colors-fresh.css', array(), '20081210'); // for login.php. Is there a better way? 436 429 $styles->add_data( 'colors-fresh', 'rtl', true ); … … 438 431 $styles->add_data( 'colors-classic', 'rtl', true ); 439 432 440 $styles->add( 'global', '/wp-admin/css/global.css', array(), '200904 07' );433 $styles->add( 'global', '/wp-admin/css/global.css', array(), '20090411' ); 441 434 $styles->add( 'media', '/wp-admin/css/media.css', array(), '20090325' ); 442 $styles->add( 'widgets', '/wp-admin/css/widgets.css', array(), '200 81210' );435 $styles->add( 'widgets', '/wp-admin/css/widgets.css', array(), '20090411' ); 443 436 $styles->add( 'dashboard', '/wp-admin/css/dashboard.css', array(), '20090305' ); 444 437 $styles->add( 'install', '/wp-admin/css/install.css', array(), '20081210' ); -
trunk/wp-includes/widgets.php
r10822 r10912 50 50 * This function should check that $new_instance is set correctly. 51 51 * The newly calculated value of $instance should be returned. 52 * If "false" is returned, the instance won't be saved/updated. 52 53 * 53 54 * @param array $new_instance New settings for this instance as input by the user via form() 54 55 * @param array $old_instance Old settings for this instance 55 * @return array Settings to save 56 * @return array Settings to save or bool false to cancel saving 56 57 */ 57 58 function update($new_instance, $old_instance) { … … 192 193 $this_sidebar = array(); 193 194 194 foreach ( $this_sidebar as $_widget_id ) { 195 // Remove all widgets of this type from the sidebar. We'll add the 196 // new data in a second. This makes sure we don't get any duplicate 197 // data since widget ids aren't necessarily persistent across multiple 198 // updates 199 if ( $this->_get_display_callback() == $wp_registered_widgets[$_widget_id]['callback'] && isset($wp_registered_widgets[$_widget_id]['params'][0]['number']) ) { 200 $number = $wp_registered_widgets[$_widget_id]['params'][0]['number']; 201 if( !in_array( $this->id_base . '-' . $number, (array)$_POST['widget-id'] ) ) { 202 // the widget has been removed. 195 if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) { 196 // Delete the settings for this instance of the widget 197 if ( isset($_POST['widget-id']) ) 198 $del_id = $_POST['widget-id']; 199 else 200 return; 201 202 if ( $this->_get_display_callback() == $wp_registered_widgets[$del_id]['callback'] && isset($wp_registered_widgets[$del_id]['params'][0]['number']) ) { 203 $number = $wp_registered_widgets[$del_id]['params'][0]['number']; 204 205 if ( $this->id_base . '-' . $number == $del_id ) { 203 206 unset($all_instances[$number]); 204 207 } 205 208 } 206 } 207 208 foreach ( (array) $_POST['widget-' . $this->id_base] as $number => $new_instance ) { 209 $new_instance = stripslashes_deep($new_instance); 210 $this->_set($number); 211 212 if ( !isset($new_instance['submit']) ) 213 continue; 214 215 if ( isset($all_instances[$number]) ) 216 $instance = $this->update($new_instance, $all_instances[$number]); 217 else 218 $instance = $this->update($new_instance, array()); 219 220 if ( !empty($instance) ) 221 $all_instances[$number] = $instance; 209 } else { 210 foreach ( (array) $_POST['widget-' . $this->id_base] as $number => $new_instance ) { 211 $new_instance = stripslashes_deep($new_instance); 212 $this->_set($number); 213 214 if ( isset($all_instances[$number]) ) 215 $instance = $this->update($new_instance, $all_instances[$number]); 216 else 217 $instance = $this->update($new_instance, array()); 218 219 if ( false !== $instance ) 220 $all_instances[$number] = $instance; 221 } 222 222 } 223 223 … … 237 237 238 238 if ( -1 == $widget_args['number'] ) { 239 // We echo out a form where 'number' can be set later via JS240 $this->_set(' %i%');239 // We echo out a form where 'number' can be set later 240 $this->_set('__i__'); 241 241 $instance = array(); 242 242 } else { … … 246 246 247 247 $this->form($instance); 248 ?>249 <input type="hidden" id="<?php echo $this->get_field_id('submit'); ?>" name="<?php echo $this->get_field_name('submit'); ?>" value="1" />250 <?php251 248 } 252 249 … … 254 251 function _register_one($number = -1) { 255 252 wp_register_sidebar_widget( $this->id, $this->name, $this->_get_display_callback(), $this->widget_options, array( 'number' => $number ) ); 256 _register_widget_update_callback( $this->id, $this->name, $this->_get_update_callback(), $this->control_options, array( 'number' => $number) );253 _register_widget_update_callback( $this->id_base, $this->_get_update_callback(), $this->control_options, array( 'number' => -1 ) ); 257 254 _register_widget_form_callback( $this->id, $this->name, $this->_get_form_callback(), $this->control_options, array( 'number' => $number ) ); 258 255 } … … 580 577 581 578 $id = strtolower($id); 579 $update_id = preg_replace( '/-[0-9]+$/', '', $id ); 582 580 583 581 if ( empty($control_callback) ) { 584 582 unset($wp_registered_widget_controls[$id]); 585 unset($wp_registered_widget_updates[$ id]);583 unset($wp_registered_widget_updates[$update_id]); 586 584 return; 587 585 } … … 603 601 $widget = array_merge($widget, $options); 604 602 605 $wp_registered_widget_controls[$id] = $wp_registered_widget_updates[$id] = $widget; 606 } 607 608 function _register_widget_update_callback($id, $name, $update_callback, $options = array()) { 603 $wp_registered_widget_controls[$id] = $widget; 604 605 if ( isset($wp_registered_widget_updates[$update_id]) ) 606 return; 607 608 if ( isset($widget['params'][0]['number']) ) 609 $widget['params'][0]['number'] = -1; 610 611 unset($widget['width'], $widget['height'], $widget['name'], $widget['id']); 612 $wp_registered_widget_updates[$update_id] = $widget; 613 } 614 615 function _register_widget_update_callback($id_base, $update_callback, $options = array()) { 609 616 global $wp_registered_widget_updates; 610 617 611 $id = strtolower($id); 612 613 if ( empty($update_callback) ) { 614 unset($wp_registered_widget_updates[$id]); 618 if ( isset($wp_registered_widget_updates[$id_base]) ) { 619 if ( empty($update_callback) ) 620 unset($wp_registered_widget_updates[$id_base]); 615 621 return; 616 622 } 617 623 618 if ( isset($wp_registered_widget_updates[$id]) && !did_action( 'widgets_init' ) )619 return;620 621 $defaults = array('width' => 250, 'height' => 200 ); // height is never used622 $options = wp_parse_args($options, $defaults);623 $options['width'] = (int) $options['width'];624 $options['height'] = (int) $options['height'];625 626 624 $widget = array( 627 'name' => $name,628 'id' => $id,629 625 'callback' => $update_callback, 630 'params' => array_slice(func_get_args(), 4)626 'params' => array_slice(func_get_args(), 3) 631 627 ); 628 632 629 $widget = array_merge($widget, $options); 633 634 $wp_registered_widget_updates[$id] = $widget; 630 $wp_registered_widget_updates[$id_base] = $widget; 635 631 } 636 632 … … 648 644 return; 649 645 650 $defaults = array('width' => 250, 'height' => 200 ); // height is never used646 $defaults = array('width' => 250, 'height' => 200 ); 651 647 $options = wp_parse_args($options, $defaults); 652 648 $options['width'] = (int) $options['width'];
Note: See TracChangeset
for help on using the changeset viewer.