Changeset 5399
- Timestamp:
- 05/06/2007 07:08:11 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/widgets.php
r5381 r5399 65 65 } 66 66 67 function register_sidebar_widget($name, $output_callback, $classname = '', $id = '') { 68 global $wp_registered_widgets, $wp_register_widget_defaults; 69 67 function register_sidebar_widget($name, $output_callback, $classname = '') { 70 68 // Compat 71 69 if ( is_array($name) ) { … … 76 74 } 77 75 78 // Last resort -- this can be broken when names get translated so please provide a unique id. 79 if ( empty($id) ) 80 $id = sanitize_title($name); 81 82 if ( (!isset($classname) || empty($classname) || !is_string($classname)) && is_string($output_callback) ) 83 $classname = $output_callback; 84 76 $id = sanitize_title($name); 77 $options = array(); 78 if ( !empty($classname) ) 79 $options['classname'] = $classname; 80 $params = array_slice(func_get_args(), 3); 81 $args = array($id, $name, $output_callback, $options); 82 if ( !empty($params) ) 83 $args = array_merge($args, $params); 84 85 call_user_func_array('wp_register_sidebar_widget', $args); 86 } 87 88 function wp_register_sidebar_widget($id, $name, $output_callback, $options = array()) { 89 90 global $wp_registered_widgets, $wp_register_widget_defaults; 91 92 $id = sanitize_title($id); 93 94 if ( empty($output_callback) ) { 95 unset($wp_registered_widgets[$id]); 96 return; 97 } 98 99 $defaults = array('classname' => $output_callback); 100 $options = wp_parse_args($options, $defaults); 85 101 $widget = array( 86 102 'name' => $name, 87 103 'id' => $id, 88 104 'callback' => $output_callback, 89 'classname' => $classname,90 105 'params' => array_slice(func_get_args(), 4) 91 106 ); 92 93 if ( empty($output_callback) ) 94 unset($wp_registered_widgets[$id]); 95 elseif ( is_callable($output_callback) && ( !isset($wp_registered_widgets[$id]) || !$wp_register_widget_defaults) ) 107 $widget = array_merge($widget, $options); 108 109 if ( is_callable($output_callback) && ( !isset($wp_registered_widgets[$id]) || !$wp_register_widget_defaults) ) 96 110 $wp_registered_widgets[$id] = $widget; 97 111 } 98 112 99 113 function unregister_sidebar_widget($id) { 100 $id = sanitize_title($id); 101 register_sidebar_widget('', '', '', $id); 102 unregister_widget_control($id); 103 } 104 105 function register_widget_control($name, $control_callback, $width = 300, $height = 200, $id = '') { 106 global $wp_registered_widget_controls, $wp_register_widget_defaults; 107 114 return wp_unregister_sidebar_widget($id); 115 } 116 117 function wp_unregister_sidebar_widget($id) { 118 wp_register_sidebar_widget($id, '', ''); 119 wp_unregister_widget_control($id); 120 } 121 122 function register_widget_control($name, $control_callback, $width = '', $height = '') { 108 123 // Compat 109 124 if ( is_array($name) ) { … … 114 129 } 115 130 116 if ( empty($id) ) 117 $id = $name; 131 $id = sanitize_title($name); 132 $options = array(); 133 if ( !empty($width) ) 134 $options['width'] = $width; 135 if ( !empty($height) ) 136 $options['height'] = $height; 137 $params = array_slice(func_get_args(), 4); 138 $args = array($id, $name, $control_callback, $options); 139 if ( !empty($params) ) 140 $args = array_merge($args, $params); 141 142 call_user_func_array('wp_register_widget_control', $args); 143 } 144 145 function wp_register_widget_control($id, $name, $control_callback, $options = array()) { 146 global $wp_registered_widget_controls, $wp_register_widget_defaults; 118 147 119 148 $id = sanitize_title($id); 120 149 121 $width = (int) $width > 90 ? (int) $width + 60 : 360; 122 $height = (int) $height > 60 ? (int) $height + 40 : 240; 123 124 if ( empty($control_callback) ) 150 if ( empty($control_callback) ) { 125 151 unset($wp_registered_widget_controls[$id]); 126 elseif ( !isset($wp_registered_widget_controls[$id]) || !$wp_register_widget_defaults ) 127 $wp_registered_widget_controls[$id] = array( 128 'name' => $name, 129 'id' => $id, 130 'callback' => $control_callback, 131 'width' => $width, 132 'height' => $height, 133 'params' => array_slice(func_get_args(), 5) 134 ); 152 return; 153 } 154 155 if ( isset($wp_registered_widget_controls[$id]) && $wp_register_widget_defaults ) 156 return; 157 158 $defaults = array('width' => 300, 'height' => 200); 159 $options = wp_parse_args($options, $defaults); 160 $options['width'] = (int) $options['width']; 161 $options['height'] = (int) $options['height']; 162 $options['width'] = $options['width'] > 90 ? $options['width'] + 60 : 360; 163 $options['height'] = $options['height'] > 60 ? $options['height'] + 40 : 240; 164 165 $widget = array( 166 'name' => $name, 167 'id' => $id, 168 'callback' => $control_callback, 169 'params' => array_slice(func_get_args(), 4) 170 ); 171 $widget = array_merge($widget, $options); 172 173 $wp_registered_widget_controls[$id] = $widget; 135 174 } 136 175 137 176 function unregister_widget_control($id) { 138 $id = sanitize_title($id); 139 return register_widget_control($id, ''); 177 return wp_unregister_widget_control($id); 178 } 179 180 function wp_unregister_widget_control($id) { 181 return wp_register_widget_control($id, '', ''); 140 182 } 141 183 … … 516 558 if ( $number < 1 ) $number = 1; 517 559 if ( $number > 9 ) $number = 9; 560 $dims = array('width' => 460, 'height' => 350); 561 $class = array('classname' => 'widget_text'); 518 562 for ($i = 1; $i <= 9; $i++) { 519 563 $name = sprintf(__('Text %d'), $i); 520 564 $id = "text-$i"; // Never never never translate an id 521 register_sidebar_widget($name, $i <= $number ? 'wp_widget_text' : /* unregister */ '', 'widget_text', $id, $i);522 register_widget_control($name, $i <= $number ? 'wp_widget_text_control' : /* unregister */ '', 460, 350, $id, $i);565 wp_register_sidebar_widget($id, $name, $i <= $number ? 'wp_widget_text' : /* unregister */ '', $class, $i); 566 wp_register_widget_control($id, $name, $i <= $number ? 'wp_widget_text_control' : /* unregister */ '', $dims, $i); 523 567 } 524 568 add_action('sidebar_admin_setup', 'wp_widget_text_setup'); … … 711 755 712 756 function wp_widget_recent_comments_register() { 713 register_sidebar_widget(__('Recent Comments'), 'wp_widget_recent_comments', null, 'recent-comments'); 714 register_widget_control(__('Recent Comments'), 'wp_widget_recent_comments_control', 320, 90, 'recent-comments'); 757 $dims = array('width' => 320, 'height' => 90); 758 $class = array('classname' => 'widget_recent_comments'); 759 wp_register_sidebar_widget('recent-comments', __('Recent Comments'), 'wp_widget_recent_comments', $class); 760 wp_register_widget_control('recent-comments', __('Recent Comments'), 'wp_widget_recent_comments_control', $dims); 715 761 716 762 if ( is_active_widget('wp_widget_recent_comments') ) … … 732 778 if ( empty($url) ) 733 779 return; 734 $rss = fetch_rss _summary($url, array( 'link', 'title', 'description' ));780 $rss = fetch_rss($url); 735 781 $link = wp_specialchars(strip_tags($rss->channel['link']), 1); 736 782 while ( strstr($link, 'http') != $link ) … … 791 837 if ( $url !== $options[$number]['url'] ) { 792 838 require_once(ABSPATH . WPINC . '/rss.php'); 793 $rss = fetch_rss _summary($url);794 if ( is_object($rss) && $rss->status == 200) {839 $rss = fetch_rss($url); 840 if ( is_object($rss) ) { 795 841 $newoptions[$number]['url'] = $url; 796 842 $newoptions[$number]['error'] = false; … … 798 844 $newoptions[$number]['error'] = true; 799 845 $newoptions[$number]['url'] = wp_specialchars(__('Error: could not find an RSS or ATOM feed at that URL.'), 1); 800 $error = sprintf(__('Error in RSS %1$d: %2$s' , 'sandbox'), $number, $newoptions[$number]['error']);846 $error = sprintf(__('Error in RSS %1$d: %2$s'), $number, $newoptions[$number]['error']); 801 847 } 802 848 } … … 856 902 if ( $number < 1 ) $number = 1; 857 903 if ( $number > 9 ) $number = 9; 904 $dims = array('width' => 410, 'height' => 200); 905 $class = array('classname' => 'widget_rss'); 858 906 for ($i = 1; $i <= 9; $i++) { 859 907 $name = sprintf(__('RSS %d'), $i); 860 908 $id = "rss-$i"; // Never never never translate an id 861 register_sidebar_widget($name, $i <= $number ? 'wp_widget_rss' : /* unregister */ '', 'widget_rss', $id, $i);862 register_widget_control($name, $i <= $number ? 'wp_widget_rss_control' : /* unregister */ '', 410, 200, $id, $i);909 wp_register_sidebar_widget($id, $name, $i <= $number ? 'wp_widget_rss' : /* unregister */ '', $class, $i); 910 wp_register_widget_control($id, $name, $i <= $number ? 'wp_widget_rss_control' : /* unregister */ '', $dims, $i); 863 911 } 864 912 add_action('sidebar_admin_setup', 'wp_widget_rss_setup'); … … 870 918 871 919 $wp_register_widget_defaults = true; 872 873 register_sidebar_widget(__('Pages'), 'wp_widget_pages', 'widget_pages', 'pages'); 874 register_widget_control(__('Pages'), 'wp_widget_pages_control', 300, 90, 'pages'); 875 register_sidebar_widget(__('Calendar'), 'wp_widget_calendar', 'widget_calendar', 'calendar'); 876 register_widget_control(__('Calendar'), 'wp_widget_calendar_control', 300, 90, 'calendar'); 877 register_sidebar_widget(__('Archives'), 'wp_widget_archives', 'widget_archives', 'archives'); 878 register_widget_control(__('Archives'), 'wp_widget_archives_control', 300, 100, 'archives'); 879 register_sidebar_widget(__('Links'), 'wp_widget_links', 'widget_links', 'links'); 880 register_sidebar_widget(__('Meta'), 'wp_widget_meta', 'widget_meta', 'meta'); 881 register_widget_control(__('Meta'), 'wp_widget_meta_control', 300, 90, 'meta'); 882 register_sidebar_widget(__('Search'), 'wp_widget_search', 'widget_search', 'search'); 883 register_sidebar_widget(__('Categories'), 'wp_widget_categories', 'widget_categories', 'categories'); 884 register_widget_control(__('Categories'), 'wp_widget_categories_control', 300, 150, 'categories'); 885 register_sidebar_widget(__('Recent Posts'), 'wp_widget_recent_entries', 'widget_recent_entries', 'recent-posts'); 886 register_widget_control(__('Recent Posts'), 'wp_widget_recent_entries_control', 300, 90, 'recent-posts'); 920 $dims90 = array('height' => 90, 'width' => 300); 921 $dims100 = array('height' => 100, 'width' => 300); 922 $dims150 = array('height' => 150, 'width' => 300); 923 $class = array('classname' => 'widget_pages'); 924 wp_register_sidebar_widget('pages', __('Pages'), 'wp_widget_pages', $class); 925 wp_register_widget_control('pages', __('Pages'), 'wp_widget_pages_control', $dims90); 926 $class['classname'] = 'widget_calendar'; 927 wp_register_sidebar_widget('calendar', __('Calendar'), 'wp_widget_calendar', $class); 928 wp_register_widget_control('calendar', __('Calendar'), 'wp_widget_calendar_control', $dims90); 929 $class['classname'] = 'widget_archives'; 930 wp_register_sidebar_widget('archives', __('Archives'), 'wp_widget_archives', $class); 931 wp_register_widget_control('archives', __('Archives'), 'wp_widget_archives_control', $dims100); 932 $class['classname'] = 'widget_links'; 933 wp_register_sidebar_widget('links', __('Links'), 'wp_widget_links', $class); 934 $class['classname'] = 'widget_meta'; 935 wp_register_sidebar_widget('meta', __('Meta'), 'wp_widget_meta', $class); 936 wp_register_widget_control('meta', __('Meta'), 'wp_widget_meta_control', $dims90); 937 $class['classname'] = 'widget_search'; 938 wp_register_sidebar_widget('search', __('Search'), 'wp_widget_search', $class); 939 $class['classname'] = 'widget_categories'; 940 wp_register_sidebar_widget('categories', __('Categories'), 'wp_widget_categories', $class); 941 wp_register_widget_control('categories', __('Categories'), 'wp_widget_categories_control', $dims150); 942 $class['classname'] = 'widget_recent_entries'; 943 wp_register_sidebar_widget('recent-posts', __('Recent Posts'), 'wp_widget_recent_entries', $class); 944 wp_register_widget_control('recent-posts', __('Recent Posts'), 'wp_widget_recent_entries_control', $dims90); 887 945 wp_widget_text_register(); 888 946 wp_widget_rss_register();
Note: See TracChangeset
for help on using the changeset viewer.