]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/widgets.php
Wordpress 2.6.2
[autoinstalls/wordpress.git] / wp-includes / widgets.php
index 9fa26306f8a16513051d4bff684f6551a64540b3..73e1f6e8ca681f55cf997f78167a92010e001eaf 100644 (file)
@@ -57,7 +57,7 @@ function register_sidebar($args = array()) {
                'after_title' => "</h2>\n",
        );
 
-       $sidebar = array_merge($defaults, $args);
+       $sidebar = array_merge($defaults, (array) $args);
 
        $wp_registered_sidebars[$sidebar['id']] = $sidebar;
 
@@ -95,6 +95,8 @@ function register_sidebar_widget($name, $output_callback, $classname = '') {
 function wp_register_sidebar_widget($id, $name, $output_callback, $options = array()) {
        global $wp_registered_widgets;
 
+       $id = strtolower($id);
+
        if ( empty($output_callback) ) {
                unset($wp_registered_widgets[$id]);
                return;
@@ -164,6 +166,8 @@ function register_widget_control($name, $control_callback, $width = '', $height
  */
 function wp_register_widget_control($id, $name, $control_callback, $options = array()) {
        global $wp_registered_widget_controls;
+       
+       $id = strtolower($id);
 
        if ( empty($control_callback) ) {
                unset($wp_registered_widget_controls[$id]);
@@ -306,9 +310,9 @@ function wp_get_sidebars_widgets($update = true) {
                                        $_sidebars_widgets[$index][$i] = $id;
                                        continue;
                                }
-                               
+
                                $found = false;
-                               
+
                                foreach ( $wp_registered_widgets as $widget_id => $widget ) {
                                        if ( strtolower($widget['name']) == strtolower($name) ) {
                                                $_sidebars_widgets[$index][$i] = $widget['id'];
@@ -320,10 +324,10 @@ function wp_get_sidebars_widgets($update = true) {
                                                break;
                                        }
                                }
-                               
+
                                if ( $found )
                                        continue;
-                               
+
                                unset($_sidebars_widgets[$index][$i]);
                        }
                        $_sidebars_widgets['array_version'] = 2;
@@ -381,7 +385,7 @@ function wp_widget_pages( $args ) {
        extract( $args );
        $options = get_option( 'widget_pages' );
 
-       $title = empty( $options['title'] ) ? __( 'Pages' ) : $options['title'];
+       $title = empty( $options['title'] ) ? __( 'Pages' ) : apply_filters('widget_title', $options['title']);
        $sortby = empty( $options['sortby'] ) ? 'menu_order' : $options['sortby'];
        $exclude = empty( $options['exclude'] ) ? '' : $options['exclude'];
 
@@ -448,25 +452,31 @@ function wp_widget_links($args) {
        extract($args, EXTR_SKIP);
 
        $before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
-       wp_list_bookmarks(array(
+       wp_list_bookmarks(apply_filters('widget_links_args', array(
                'title_before' => $before_title, 'title_after' => $after_title,
                'category_before' => $before_widget, 'category_after' => $after_widget,
                'show_images' => true, 'class' => 'linkcat widget'
-       ));
+       )));
 }
 
 function wp_widget_search($args) {
        extract($args);
-?>
-               <?php echo $before_widget; ?>
-                       <form id="searchform" method="get" action="<?php bloginfo('home'); ?>">
-                       <div>
-                       <input type="text" name="s" id="s" size="15" /><br />
+       $searchform_template = get_template_directory() . '/searchform.php';
+       
+       echo $before_widget;
+       
+       // Use current theme search form if it exists
+       if ( file_exists($searchform_template) ) {
+               include_once($searchform_template);
+       } else { ?>
+               <form id="searchform" method="get" action="<?php bloginfo('url'); ?>/"><div>
+                       <label class="hidden" for="s"><?php _e('Search for:'); ?></label>
+                       <input type="text" name="s" id="s" size="15" value="<?php the_search_query(); ?>" />
                        <input type="submit" value="<?php echo attribute_escape(__('Search')); ?>" />
-                       </div>
-                       </form>
-               <?php echo $after_widget; ?>
-<?php
+               </div></form>
+       <?php }
+       
+       echo $after_widget;
 }
 
 function wp_widget_archives($args) {
@@ -474,7 +484,7 @@ function wp_widget_archives($args) {
        $options = get_option('widget_archives');
        $c = $options['count'] ? '1' : '0';
        $d = $options['dropdown'] ? '1' : '0';
-       $title = empty($options['title']) ? __('Archives') : $options['title'];
+       $title = empty($options['title']) ? __('Archives') : apply_filters('widget_title', $options['title']);
 
        echo $before_widget;
        echo $before_title . $title . $after_title;
@@ -522,7 +532,7 @@ function wp_widget_archives_control() {
 function wp_widget_meta($args) {
        extract($args);
        $options = get_option('widget_meta');
-       $title = empty($options['title']) ? __('Meta') : $options['title'];
+       $title = empty($options['title']) ? __('Meta') : apply_filters('widget_title', $options['title']);
 ?>
                <?php echo $before_widget; ?>
                        <?php echo $before_title . $title . $after_title; ?>
@@ -556,7 +566,7 @@ function wp_widget_meta_control() {
 function wp_widget_calendar($args) {
        extract($args);
        $options = get_option('widget_calendar');
-       $title = $options['title'];
+       $title = apply_filters('widget_title', $options['title']);
        if ( empty($title) )
                $title = '&nbsp;';
        echo $before_widget . $before_title . $title . $after_title;
@@ -593,7 +603,7 @@ function wp_widget_text($args, $widget_args = 1) {
        if ( !isset($options[$number]) )
                return;
 
-       $title = $options[$number]['title'];
+       $title = apply_filters('widget_title', $options[$number]['title']);
        $text = apply_filters( 'widget_text', $options[$number]['text'] );
 ?>
                <?php echo $before_widget; ?>
@@ -705,15 +715,16 @@ function wp_widget_categories($args, $widget_args = 1) {
        $h = $options[$number]['hierarchical'] ? '1' : '0';
        $d = $options[$number]['dropdown'] ? '1' : '0';
 
-       $title = empty($options[$number]['title']) ? __('Categories') : $options[$number]['title'];
+       $title = empty($options[$number]['title']) ? __('Categories') : apply_filters('widget_title', $options[$number]['title']);
 
        echo $before_widget;
        echo $before_title . $title . $after_title;
 
-       $cat_args = "orderby=name&show_count={$c}&hierarchical={$h}";
+       $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
 
        if ( $d ) {
-               wp_dropdown_categories($cat_args . '&show_option_none= ' . __('Select Category'));
+               $cat_args['show_option_none'] = __('Select Category');
+               wp_dropdown_categories($cat_args);
 ?>
 
 <script type='text/javascript'>
@@ -732,7 +743,10 @@ function wp_widget_categories($args, $widget_args = 1) {
        } else {
 ?>
                <ul>
-               <?php wp_list_categories($cat_args . '&title_li='); ?>
+               <?php 
+                       $cat_args['title_li'] = '';
+                       wp_list_categories($cat_args); 
+               ?>
                </ul>
 <?php
        }
@@ -890,7 +904,7 @@ function wp_widget_recent_entries($args) {
 
        extract($args);
        $options = get_option('widget_recent_entries');
-       $title = empty($options['title']) ? __('Recent Posts') : $options['title'];
+       $title = empty($options['title']) ? __('Recent Posts') : apply_filters('widget_title', $options['title']);
        if ( !$number = (int) $options['number'] )
                $number = 10;
        else if ( $number < 1 )
@@ -898,7 +912,7 @@ function wp_widget_recent_entries($args) {
        else if ( $number > 15 )
                $number = 15;
 
-       $r = new WP_Query("showposts=$number&what_to_show=posts&nopaging=0&post_status=publish");
+       $r = new WP_Query(array('showposts' => $number, 'what_to_show' => 'posts', 'nopaging' => 0, 'post_status' => 'publish'));
        if ($r->have_posts()) :
 ?>
                <?php echo $before_widget; ?>
@@ -955,7 +969,7 @@ function wp_widget_recent_comments($args) {
        global $wpdb, $comments, $comment;
        extract($args, EXTR_SKIP);
        $options = get_option('widget_recent_comments');
-       $title = empty($options['title']) ? __('Recent Comments') : $options['title'];
+       $title = empty($options['title']) ? __('Recent Comments') : apply_filters('widget_title', $options['title']);
        if ( !$number = (int) $options['number'] )
                $number = 5;
        else if ( $number < 1 )
@@ -1029,7 +1043,7 @@ function wp_widget_recent_comments_register() {
 function wp_widget_rss($args, $widget_args = 1) {
        extract($args, EXTR_SKIP);
        if ( is_numeric($widget_args) )
-               $widget_args = array( 'number' => $widegt_args );
+               $widget_args = array( 'number' => $widget_args );
        $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
        extract($widget_args, EXTR_SKIP);
 
@@ -1061,11 +1075,12 @@ function wp_widget_rss($args, $widget_args = 1) {
                $title = $desc;
        if ( empty($title) )
                $title = __('Unknown Feed');
+       $title = apply_filters('widget_title', $title );
        $url = clean_url(strip_tags($url));
        if ( file_exists(dirname(__FILE__) . '/rss.png') )
-               $icon = str_replace(ABSPATH, get_option('siteurl').'/', dirname(__FILE__)) . '/rss.png';
+               $icon = str_replace(ABSPATH, site_url() . '/', dirname(__FILE__)) . '/rss.png';
        else
-               $icon = get_option('siteurl').'/wp-includes/images/rss.png';
+               $icon = includes_url('images/rss.png');
        $title = "<a class='rsswidget' href='$url' title='" . attribute_escape(__('Syndicate this content')) ."'><img style='background:orange;color:white;border:none;' width='14' height='14' src='$icon' alt='RSS' /></a> <a class='rsswidget' href='$link' title='$desc'>$title</a>";
 
        echo $before_widget;
@@ -1110,18 +1125,11 @@ function wp_widget_rss_output( $rss, $args = array() ) {
                        if ( empty($title) )
                                $title = __('Untitled');
                        $desc = '';
-                               if ( isset( $item['description'] ) && is_string( $item['description'] ) )
-                                       $desc = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($item['description'], ENT_QUOTES))));
-                               elseif ( isset( $item['summary'] ) && is_string( $item['summary'] ) )
-                                       $desc = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($item['summary'], ENT_QUOTES))));
-
                        $summary = '';
                        if ( isset( $item['description'] ) && is_string( $item['description'] ) )
-                               $summary = $item['description'];
+                               $desc = $summary = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($item['description'], ENT_QUOTES))));
                        elseif ( isset( $item['summary'] ) && is_string( $item['summary'] ) )
-                               $summary = $item['summary'];
-
-                       $desc = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($summary, ENT_QUOTES))));
+                               $desc = $summary = str_replace(array("\n", "\r"), ' ', attribute_escape(strip_tags(html_entity_decode($item['summary'], ENT_QUOTES))));
 
                        if ( $show_summary ) {
                                $desc = '';
@@ -1140,7 +1148,7 @@ function wp_widget_rss_output( $rss, $args = array() ) {
 
                                if ( $date ) {
                                        if ( $date_stamp = strtotime( $date ) )
-                                               $date = '<span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date_stamp ) . '</span>';
+                                               $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date_stamp ) . '</span>';
                                        else
                                                $date = '';
                                }
@@ -1154,8 +1162,12 @@ function wp_widget_rss_output( $rss, $args = array() ) {
                                        $author = ' <cite>' . wp_specialchars( strip_tags( $item['author_name'] ) ) . '</cite>';
                        }
 
-                       echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>";
-               }
+                       if ( $link == '' ) {
+                               echo "<li>$title{$date}{$summary}{$author}</li>"; 
+                       } else {
+                               echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>"; 
+                       }
+}
                echo '</ul>';
        } else {
                echo '<ul><li>' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '</li></ul>';
@@ -1353,7 +1365,7 @@ function wp_widget_rss_register() {
 function wp_widget_tag_cloud($args) {
        extract($args);
        $options = get_option('widget_tag_cloud');
-       $title = empty($options['title']) ? __('Tags') : $options['title'];
+       $title = empty($options['title']) ? __('Tags') : apply_filters('widget_title', $options['title']);
 
        echo $before_widget;
        echo $before_title . $title . $after_title;
@@ -1496,7 +1508,7 @@ function widget_many_control( $widget_args = 1 ) {
                        $options[$widget_number] = array( 'something' => $something );  // Even simple widgets should store stuff in array, rather than in scalar
                }
 
-               update_option('widget_text', $options);
+               update_option('widget_many', $options);
 
                $updated = true; // So that we don't go through this more than once
        }
@@ -1538,8 +1550,8 @@ function widget_many_register() {
                // $id should look like {$id_base}-{$o}
                $id = "many-$o"; // Never never never translate an id
                $registered = true;
-               wp_register_sidebar_widget( $id, $name, 'wp_widget_text', $widget_ops, array( 'number' => $o ) );
-               wp_register_widget_control( $id, $name, 'wp_widget_text_control', $control_ops, array( 'number' => $o ) );
+               wp_register_sidebar_widget( $id, $name, 'widget_many', $widget_ops, array( 'number' => $o ) );
+               wp_register_widget_control( $id, $name, 'widget_many_control', $control_ops, array( 'number' => $o ) );
        }
 
        // If there are none, we register the widget's existance with a generic template