]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/default-widgets.php
WordPress 3.4
[autoinstalls/wordpress.git] / wp-includes / default-widgets.php
index df7ef39ac5f84f72b05d3bba8d664d1ffa6f2c34..e4856dac68b790a958e9b4948c1dc2e6861da841 100644 (file)
@@ -102,12 +102,9 @@ class WP_Widget_Links extends WP_Widget {
                $show_rating = isset($instance['rating']) ? $instance['rating'] : false;
                $show_images = isset($instance['images']) ? $instance['images'] : true;
                $category = isset($instance['category']) ? $instance['category'] : false;
                $show_rating = isset($instance['rating']) ? $instance['rating'] : false;
                $show_images = isset($instance['images']) ? $instance['images'] : true;
                $category = isset($instance['category']) ? $instance['category'] : false;
-
-               if ( is_admin() && !$category ) {
-                       // Display All Links widget as such in the widgets screen
-                       echo $before_widget . $before_title . _x('All Links', 'links widget') . $after_title . $after_widget;
-                       return;
-               }
+               $orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name';
+               $order = $orderby == 'rating' ? 'DESC' : 'ASC';
+               $limit = isset( $instance['limit'] ) ? $instance['limit'] : -1;
 
                $before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
                wp_list_bookmarks(apply_filters('widget_links_args', array(
 
                $before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
                wp_list_bookmarks(apply_filters('widget_links_args', array(
@@ -115,18 +112,26 @@ class WP_Widget_Links extends WP_Widget {
                        'category_before' => $before_widget, 'category_after' => $after_widget,
                        'show_images' => $show_images, 'show_description' => $show_description,
                        'show_name' => $show_name, 'show_rating' => $show_rating,
                        'category_before' => $before_widget, 'category_after' => $after_widget,
                        'show_images' => $show_images, 'show_description' => $show_description,
                        'show_name' => $show_name, 'show_rating' => $show_rating,
-                       'category' => $category, 'class' => 'linkcat widget'
+                       'category' => $category, 'class' => 'linkcat widget',
+                       'orderby' => $orderby, 'order' => $order,
+                       'limit' => $limit,
                )));
        }
 
        function update( $new_instance, $old_instance ) {
                $new_instance = (array) $new_instance;
                )));
        }
 
        function update( $new_instance, $old_instance ) {
                $new_instance = (array) $new_instance;
-               $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0);
+               $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 );
                foreach ( $instance as $field => $val ) {
                        if ( isset($new_instance[$field]) )
                                $instance[$field] = 1;
                }
                foreach ( $instance as $field => $val ) {
                        if ( isset($new_instance[$field]) )
                                $instance[$field] = 1;
                }
-               $instance['category'] = intval($new_instance['category']);
+
+               $instance['orderby'] = 'name';
+               if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) )
+                       $instance['orderby'] = $new_instance['orderby'];
+
+               $instance['category'] = intval( $new_instance['category'] );
+               $instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1;
 
                return $instance;
        }
 
                return $instance;
        }
@@ -134,11 +139,13 @@ class WP_Widget_Links extends WP_Widget {
        function form( $instance ) {
 
                //Defaults
        function form( $instance ) {
 
                //Defaults
-               $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false ) );
-               $link_cats = get_terms( 'link_category');
+               $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) );
+               $link_cats = get_terms( 'link_category' );
+               if ( ! $limit = intval( $instance['limit'] ) )
+                       $limit = -1;
 ?>
                <p>
 ?>
                <p>
-               <label for="<?php echo $this->get_field_id('category'); ?>" class="screen-reader-text"><?php _e('Select Link Category'); ?></label>
+               <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e( 'Select Link Category:' ); ?></label>
                <select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
                <option value=""><?php _ex('All Links', 'links widget'); ?></option>
                <?php
                <select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
                <option value=""><?php _ex('All Links', 'links widget'); ?></option>
                <?php
@@ -148,7 +155,15 @@ class WP_Widget_Links extends WP_Widget {
                                . '>' . $link_cat->name . "</option>\n";
                }
                ?>
                                . '>' . $link_cat->name . "</option>\n";
                }
                ?>
-               </select></p>
+               </select>
+               <label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:' ); ?></label>
+               <select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat">
+                       <option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e( 'Link title' ); ?></option>
+                       <option value="rating"<?php selected( $instance['orderby'], 'rating' ); ?>><?php _e( 'Link rating' ); ?></option>
+                       <option value="id"<?php selected( $instance['orderby'], 'id' ); ?>><?php _e( 'Link ID' ); ?></option>
+                       <option value="rand"<?php selected( $instance['orderby'], 'rand' ); ?>><?php _e( 'Random' ); ?></option>
+               </select>
+               </p>
                <p>
                <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'); ?>" />
                <label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />
                <p>
                <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'); ?>" />
                <label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />
@@ -159,6 +174,10 @@ class WP_Widget_Links extends WP_Widget {
                <input class="checkbox" type="checkbox" <?php checked($instance['rating'], true) ?> id="<?php echo $this->get_field_id('rating'); ?>" name="<?php echo $this->get_field_name('rating'); ?>" />
                <label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label>
                </p>
                <input class="checkbox" type="checkbox" <?php checked($instance['rating'], true) ?> id="<?php echo $this->get_field_id('rating'); ?>" name="<?php echo $this->get_field_name('rating'); ?>" />
                <label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label>
                </p>
+               <p>
+               <label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e( 'Number of links to show:' ); ?></label>
+               <input id="<?php echo $this->get_field_id('limit'); ?>" name="<?php echo $this->get_field_name('limit'); ?>" type="text" value="<?php echo $limit == -1 ? '' : intval( $limit ); ?>" size="3" />
+               </p>
 <?php
        }
 }
 <?php
        }
 }
@@ -296,7 +315,10 @@ class WP_Widget_Meta extends WP_Widget {
                        <li><?php wp_loginout(); ?></li>
                        <li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php echo esc_attr(__('Syndicate this site using RSS 2.0')); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
                        <li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php echo esc_attr(__('The latest comments to all posts in RSS')); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
                        <li><?php wp_loginout(); ?></li>
                        <li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php echo esc_attr(__('Syndicate this site using RSS 2.0')); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
                        <li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php echo esc_attr(__('The latest comments to all posts in RSS')); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
-                       <li><a href="http://wordpress.org/" title="<?php echo esc_attr(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.')); ?>">WordPress.org</a></li>
+                       <li><a href="<?php esc_attr_e( 'http://wordpress.org/' ); ?>" title="<?php echo esc_attr(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.')); ?>"><?php
+                       /* translators: meta widget link text */
+                       _e( 'WordPress.org' );
+                       ?></a></li>
                        <?php wp_meta(); ?>
                        </ul>
 <?php
                        <?php wp_meta(); ?>
                        </ul>
 <?php
@@ -540,7 +562,7 @@ class WP_Widget_Recent_Posts extends WP_Widget {
                if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
                        $number = 10;
 
                if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
                        $number = 10;
 
-               $r = new WP_Query(array('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true));
+               $r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) );
                if ($r->have_posts()) :
 ?>
                <?php echo $before_widget; ?>
                if ($r->have_posts()) :
 ?>
                <?php echo $before_widget; ?>
@@ -646,7 +668,7 @@ class WP_Widget_Recent_Comments extends WP_Widget {
                if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
                        $number = 5;
 
                if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
                        $number = 5;
 
-               $comments = get_comments( array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish' ) );
+               $comments = get_comments( apply_filters( 'widget_comments_args', array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish' ) ) );
                $output .= $before_widget;
                if ( $title )
                        $output .= $before_title . $title . $after_title;
                $output .= $before_widget;
                if ( $title )
                        $output .= $before_title . $title . $after_title;
@@ -869,8 +891,6 @@ function wp_widget_rss_output( $rss, $args = array() ) {
        unset($rss);
 }
 
        unset($rss);
 }
 
-
-
 /**
  * Display RSS widget options form.
  *
 /**
  * Display RSS widget options form.
  *
@@ -1033,7 +1053,7 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php if (isset ( $instance['title'])) {echo esc_attr( $instance['title'] );} ?>" /></p>
        <p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label>
        <select class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>">
        <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php if (isset ( $instance['title'])) {echo esc_attr( $instance['title'] );} ?>" /></p>
        <p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label>
        <select class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>">
-       <?php foreach ( get_object_taxonomies('post') as $taxonomy ) :
+       <?php foreach ( get_taxonomies() as $taxonomy ) :
                                $tax = get_taxonomy($taxonomy);
                                if ( !$tax->show_tagcloud || empty($tax->labels->name) )
                                        continue;
                                $tax = get_taxonomy($taxonomy);
                                if ( !$tax->show_tagcloud || empty($tax->labels->name) )
                                        continue;