[ XREF Home ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

title

Body

[close]

/wp-includes/ -> default-widgets.php (source)

   1  <?php
   2  /**
   3   * Default Widgets
   4   *
   5   * @package WordPress
   6   * @subpackage Widgets
   7   */
   8  
   9  /**
  10   * Pages widget class
  11   *
  12   * @since 2.8.0
  13   */
  14  class WP_Widget_Pages extends WP_Widget {
  15  
  16  	function __construct() {
  17          $widget_ops = array('classname' => 'widget_pages', 'description' => __( 'Your site&#8217;s WordPress Pages') );
  18          parent::__construct('pages', __('Pages'), $widget_ops);
  19      }
  20  
  21  	function widget( $args, $instance ) {
  22          extract( $args );
  23  
  24          $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base);
  25          $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
  26          $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
  27  
  28          if ( $sortby == 'menu_order' )
  29              $sortby = 'menu_order, post_title';
  30  
  31          $out = wp_list_pages( apply_filters('widget_pages_args', array('title_li' => '', 'echo' => 0, 'sort_column' => $sortby, 'exclude' => $exclude) ) );
  32  
  33          if ( !empty( $out ) ) {
  34              echo $before_widget;
  35              if ( $title)
  36                  echo $before_title . $title . $after_title;
  37          ?>
  38          <ul>
  39              <?php echo $out; ?>
  40          </ul>
  41          <?php
  42              echo $after_widget;
  43          }
  44      }
  45  
  46  	function update( $new_instance, $old_instance ) {
  47          $instance = $old_instance;
  48          $instance['title'] = strip_tags($new_instance['title']);
  49          if ( in_array( $new_instance['sortby'], array( 'post_title', 'menu_order', 'ID' ) ) ) {
  50              $instance['sortby'] = $new_instance['sortby'];
  51          } else {
  52              $instance['sortby'] = 'menu_order';
  53          }
  54  
  55          $instance['exclude'] = strip_tags( $new_instance['exclude'] );
  56  
  57          return $instance;
  58      }
  59  
  60  	function form( $instance ) {
  61          //Defaults
  62          $instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') );
  63          $title = esc_attr( $instance['title'] );
  64          $exclude = esc_attr( $instance['exclude'] );
  65      ?>
  66          <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
  67          <p>
  68              <label for="<?php echo $this->get_field_id('sortby'); ?>"><?php _e( 'Sort by:' ); ?></label>
  69              <select name="<?php echo $this->get_field_name('sortby'); ?>" id="<?php echo $this->get_field_id('sortby'); ?>" class="widefat">
  70                  <option value="post_title"<?php selected( $instance['sortby'], 'post_title' ); ?>><?php _e('Page title'); ?></option>
  71                  <option value="menu_order"<?php selected( $instance['sortby'], 'menu_order' ); ?>><?php _e('Page order'); ?></option>
  72                  <option value="ID"<?php selected( $instance['sortby'], 'ID' ); ?>><?php _e( 'Page ID' ); ?></option>
  73              </select>
  74          </p>
  75          <p>
  76              <label for="<?php echo $this->get_field_id('exclude'); ?>"><?php _e( 'Exclude:' ); ?></label> <input type="text" value="<?php echo $exclude; ?>" name="<?php echo $this->get_field_name('exclude'); ?>" id="<?php echo $this->get_field_id('exclude'); ?>" class="widefat" />
  77              <br />
  78              <small><?php _e( 'Page IDs, separated by commas.' ); ?></small>
  79          </p>
  80  <?php
  81      }
  82  
  83  }
  84  
  85  /**
  86   * Links widget class
  87   *
  88   * @since 2.8.0
  89   */
  90  class WP_Widget_Links extends WP_Widget {
  91  
  92  	function __construct() {
  93          $widget_ops = array('description' => __( "Your blogroll" ) );
  94          parent::__construct('links', __('Links'), $widget_ops);
  95      }
  96  
  97  	function widget( $args, $instance ) {
  98          extract($args, EXTR_SKIP);
  99  
 100          $show_description = isset($instance['description']) ? $instance['description'] : false;
 101          $show_name = isset($instance['name']) ? $instance['name'] : false;
 102          $show_rating = isset($instance['rating']) ? $instance['rating'] : false;
 103          $show_images = isset($instance['images']) ? $instance['images'] : true;
 104          $category = isset($instance['category']) ? $instance['category'] : false;
 105  
 106          if ( is_admin() && !$category ) {
 107              // Display All Links widget as such in the widgets screen
 108              echo $before_widget . $before_title. __('All Links') . $after_title . $after_widget;
 109              return;
 110          }
 111  
 112          $before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
 113          wp_list_bookmarks(apply_filters('widget_links_args', array(
 114              'title_before' => $before_title, 'title_after' => $after_title,
 115              'category_before' => $before_widget, 'category_after' => $after_widget,
 116              'show_images' => $show_images, 'show_description' => $show_description,
 117              'show_name' => $show_name, 'show_rating' => $show_rating,
 118              'category' => $category, 'class' => 'linkcat widget'
 119          )));
 120      }
 121  
 122  	function update( $new_instance, $old_instance ) {
 123          $new_instance = (array) $new_instance;
 124          $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0);
 125          foreach ( $instance as $field => $val ) {
 126              if ( isset($new_instance[$field]) )
 127                  $instance[$field] = 1;
 128          }
 129          $instance['category'] = intval($new_instance['category']);
 130  
 131          return $instance;
 132      }
 133  
 134  	function form( $instance ) {
 135  
 136          //Defaults
 137          $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false ) );
 138          $link_cats = get_terms( 'link_category');
 139  ?>
 140          <p>
 141          <label for="<?php echo $this->get_field_id('category'); ?>" class="screen-reader-text"><?php _e('Select Link Category'); ?></label>
 142          <select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
 143          <option value=""><?php _e('All Links'); ?></option>
 144          <?php
 145          foreach ( $link_cats as $link_cat ) {
 146              echo '<option value="' . intval($link_cat->term_id) . '"'
 147                  . ( $link_cat->term_id == $instance['category'] ? ' selected="selected"' : '' )
 148                  . '>' . $link_cat->name . "</option>\n";
 149          }
 150          ?>
 151          </select></p>
 152          <p>
 153          <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'); ?>" />
 154          <label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />
 155          <input class="checkbox" type="checkbox" <?php checked($instance['name'], true) ?> id="<?php echo $this->get_field_id('name'); ?>" name="<?php echo $this->get_field_name('name'); ?>" />
 156          <label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Show Link Name'); ?></label><br />
 157          <input class="checkbox" type="checkbox" <?php checked($instance['description'], true) ?> id="<?php echo $this->get_field_id('description'); ?>" name="<?php echo $this->get_field_name('description'); ?>" />
 158          <label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Show Link Description'); ?></label><br />
 159          <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'); ?>" />
 160          <label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label>
 161          </p>
 162  <?php
 163      }
 164  }
 165  
 166  /**
 167   * Search widget class
 168   *
 169   * @since 2.8.0
 170   */
 171  class WP_Widget_Search extends WP_Widget {
 172  
 173  	function __construct() {
 174          $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site") );
 175          parent::__construct('search', __('Search'), $widget_ops);
 176      }
 177  
 178  	function widget( $args, $instance ) {
 179          extract($args);
 180          $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
 181  
 182          echo $before_widget;
 183          if ( $title )
 184              echo $before_title . $title . $after_title;
 185  
 186          // Use current theme search form if it exists
 187          get_search_form();
 188  
 189          echo $after_widget;
 190      }
 191  
 192  	function form( $instance ) {
 193          $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
 194          $title = $instance['title'];
 195  ?>
 196          <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></label></p>
 197  <?php
 198      }
 199  
 200  	function update( $new_instance, $old_instance ) {
 201          $instance = $old_instance;
 202          $new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));
 203          $instance['title'] = strip_tags($new_instance['title']);
 204          return $instance;
 205      }
 206  
 207  }
 208  
 209  /**
 210   * Archives widget class
 211   *
 212   * @since 2.8.0
 213   */
 214  class WP_Widget_Archives extends WP_Widget {
 215  
 216  	function __construct() {
 217          $widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site&#8217;s posts') );
 218          parent::__construct('archives', __('Archives'), $widget_ops);
 219      }
 220  
 221  	function widget( $args, $instance ) {
 222          extract($args);
 223          $c = $instance['count'] ? '1' : '0';
 224          $d = $instance['dropdown'] ? '1' : '0';
 225          $title = apply_filters('widget_title', empty($instance['title']) ? __('Archives') : $instance['title'], $instance, $this->id_base);
 226  
 227          echo $before_widget;
 228          if ( $title )
 229              echo $before_title . $title . $after_title;
 230  
 231          if ( $d ) {
 232  ?>
 233          <select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo esc_attr(__('Select Month')); ?></option> <?php wp_get_archives(apply_filters('widget_archives_dropdown_args', array('type' => 'monthly', 'format' => 'option', 'show_post_count' => $c))); ?> </select>
 234  <?php
 235          } else {
 236  ?>
 237          <ul>
 238          <?php wp_get_archives(apply_filters('widget_archives_args', array('type' => 'monthly', 'show_post_count' => $c))); ?>
 239          </ul>
 240  <?php
 241          }
 242  
 243          echo $after_widget;
 244      }
 245  
 246  	function update( $new_instance, $old_instance ) {
 247          $instance = $old_instance;
 248          $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
 249          $instance['title'] = strip_tags($new_instance['title']);
 250          $instance['count'] = $new_instance['count'] ? 1 : 0;
 251          $instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0;
 252  
 253          return $instance;
 254      }
 255  
 256  	function form( $instance ) {
 257          $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
 258          $title = strip_tags($instance['title']);
 259          $count = $instance['count'] ? 'checked="checked"' : '';
 260          $dropdown = $instance['dropdown'] ? 'checked="checked"' : '';
 261  ?>
 262          <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
 263          <p>
 264              <input class="checkbox" type="checkbox" <?php echo $dropdown; ?> id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>" /> <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e('Display as dropdown'); ?></label>
 265              <br/>
 266              <input class="checkbox" type="checkbox" <?php echo $count; ?> id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" /> <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Show post counts'); ?></label>
 267          </p>
 268  <?php
 269      }
 270  }
 271  
 272  /**
 273   * Meta widget class
 274   *
 275   * Displays log in/out, RSS feed links, etc.
 276   *
 277   * @since 2.8.0
 278   */
 279  class WP_Widget_Meta extends WP_Widget {
 280  
 281  	function __construct() {
 282          $widget_ops = array('classname' => 'widget_meta', 'description' => __( "Log in/out, admin, feed and WordPress links") );
 283          parent::__construct('meta', __('Meta'), $widget_ops);
 284      }
 285  
 286  	function widget( $args, $instance ) {
 287          extract($args);
 288          $title = apply_filters('widget_title', empty($instance['title']) ? __('Meta') : $instance['title'], $instance, $this->id_base);
 289  
 290          echo $before_widget;
 291          if ( $title )
 292              echo $before_title . $title . $after_title;
 293  ?>
 294              <ul>
 295              <?php wp_register(); ?>
 296              <li><?php wp_loginout(); ?></li>
 297              <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>
 298              <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>
 299              <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>
 300              <?php wp_meta(); ?>
 301              </ul>
 302  <?php
 303          echo $after_widget;
 304      }
 305  
 306  	function update( $new_instance, $old_instance ) {
 307          $instance = $old_instance;
 308          $instance['title'] = strip_tags($new_instance['title']);
 309  
 310          return $instance;
 311      }
 312  
 313  	function form( $instance ) {
 314          $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
 315          $title = strip_tags($instance['title']);
 316  ?>
 317              <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
 318  <?php
 319      }
 320  }
 321  
 322  /**
 323   * Calendar widget class
 324   *
 325   * @since 2.8.0
 326   */
 327  class WP_Widget_Calendar extends WP_Widget {
 328  
 329  	function __construct() {
 330          $widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A calendar of your site&#8217;s posts') );
 331          parent::__construct('calendar', __('Calendar'), $widget_ops);
 332      }
 333  
 334  	function widget( $args, $instance ) {
 335          extract($args);
 336          $title = apply_filters('widget_title', empty($instance['title']) ? '&nbsp;' : $instance['title'], $instance, $this->id_base);
 337          echo $before_widget;
 338          if ( $title )
 339              echo $before_title . $title . $after_title;
 340          echo '<div id="calendar_wrap">';
 341          get_calendar();
 342          echo '</div>';
 343          echo $after_widget;
 344      }
 345  
 346  	function update( $new_instance, $old_instance ) {
 347          $instance = $old_instance;
 348          $instance['title'] = strip_tags($new_instance['title']);
 349  
 350          return $instance;
 351      }
 352  
 353  	function form( $instance ) {
 354          $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
 355          $title = strip_tags($instance['title']);
 356  ?>
 357          <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
 358          <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
 359  <?php
 360      }
 361  }
 362  
 363  /**
 364   * Text widget class
 365   *
 366   * @since 2.8.0
 367   */
 368  class WP_Widget_Text extends WP_Widget {
 369  
 370  	function __construct() {
 371          $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML'));
 372          $control_ops = array('width' => 400, 'height' => 350);
 373          parent::__construct('text', __('Text'), $widget_ops, $control_ops);
 374      }
 375  
 376  	function widget( $args, $instance ) {
 377          extract($args);
 378          $title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
 379          $text = apply_filters( 'widget_text', $instance['text'], $instance );
 380          echo $before_widget;
 381          if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
 382              <div class="textwidget"><?php echo $instance['filter'] ? wpautop($text) : $text; ?></div>
 383          <?php
 384          echo $after_widget;
 385      }
 386  
 387  	function update( $new_instance, $old_instance ) {
 388          $instance = $old_instance;
 389          $instance['title'] = strip_tags($new_instance['title']);
 390          if ( current_user_can('unfiltered_html') )
 391              $instance['text'] =  $new_instance['text'];
 392          else
 393              $instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed
 394          $instance['filter'] = isset($new_instance['filter']);
 395          return $instance;
 396      }
 397  
 398  	function form( $instance ) {
 399          $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
 400          $title = strip_tags($instance['title']);
 401          $text = esc_textarea($instance['text']);
 402  ?>
 403          <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
 404          <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
 405  
 406          <textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea>
 407  
 408          <p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked(isset($instance['filter']) ? $instance['filter'] : 0); ?> />&nbsp;<label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p>
 409  <?php
 410      }
 411  }
 412  
 413  /**
 414   * Categories widget class
 415   *
 416   * @since 2.8.0
 417   */
 418  class WP_Widget_Categories extends WP_Widget {
 419  
 420  	function __construct() {
 421          $widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories" ) );
 422          parent::__construct('categories', __('Categories'), $widget_ops);
 423      }
 424  
 425  	function widget( $args, $instance ) {
 426          extract( $args );
 427  
 428          $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base);
 429          $c = $instance['count'] ? '1' : '0';
 430          $h = $instance['hierarchical'] ? '1' : '0';
 431          $d = $instance['dropdown'] ? '1' : '0';
 432  
 433          echo $before_widget;
 434          if ( $title )
 435              echo $before_title . $title . $after_title;
 436  
 437          $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
 438  
 439          if ( $d ) {
 440              $cat_args['show_option_none'] = __('Select Category');
 441              wp_dropdown_categories(apply_filters('widget_categories_dropdown_args', $cat_args));
 442  ?>
 443  
 444  <script type='text/javascript'>
 445  /* <![CDATA[ */
 446      var dropdown = document.getElementById("cat");
 447  	function onCatChange() {
 448          if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
 449              location.href = "<?php echo home_url(); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
 450          }
 451      }
 452      dropdown.onchange = onCatChange;
 453  /* ]]> */
 454  </script>
 455  
 456  <?php
 457          } else {
 458  ?>
 459          <ul>
 460  <?php
 461          $cat_args['title_li'] = '';
 462          wp_list_categories(apply_filters('widget_categories_args', $cat_args));
 463  ?>
 464          </ul>
 465  <?php
 466          }
 467  
 468          echo $after_widget;
 469      }
 470  
 471  	function update( $new_instance, $old_instance ) {
 472          $instance = $old_instance;
 473          $instance['title'] = strip_tags($new_instance['title']);
 474          $instance['count'] = !empty($new_instance['count']) ? 1 : 0;
 475          $instance['hierarchical'] = !empty($new_instance['hierarchical']) ? 1 : 0;
 476          $instance['dropdown'] = !empty($new_instance['dropdown']) ? 1 : 0;
 477  
 478          return $instance;
 479      }
 480  
 481  	function form( $instance ) {
 482          //Defaults
 483          $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
 484          $title = esc_attr( $instance['title'] );
 485          $count = isset($instance['count']) ? (bool) $instance['count'] :false;
 486          $hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
 487          $dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
 488  ?>
 489          <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label>
 490          <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
 491  
 492          <p><input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('dropdown'); ?>" name="<?php echo $this->get_field_name('dropdown'); ?>"<?php checked( $dropdown ); ?> />
 493          <label for="<?php echo $this->get_field_id('dropdown'); ?>"><?php _e( 'Display as dropdown' ); ?></label><br />
 494  
 495          <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> />
 496          <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e( 'Show post counts' ); ?></label><br />
 497  
 498          <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> />
 499          <label for="<?php echo $this->get_field_id('hierarchical'); ?>"><?php _e( 'Show hierarchy' ); ?></label></p>
 500  <?php
 501      }
 502  
 503  }
 504  
 505  /**
 506   * Recent_Posts widget class
 507   *
 508   * @since 2.8.0
 509   */
 510  class WP_Widget_Recent_Posts extends WP_Widget {
 511  
 512  	function __construct() {
 513          $widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your site") );
 514          parent::__construct('recent-posts', __('Recent Posts'), $widget_ops);
 515          $this->alt_option_name = 'widget_recent_entries';
 516  
 517          add_action( 'save_post', array(&$this, 'flush_widget_cache') );
 518          add_action( 'deleted_post', array(&$this, 'flush_widget_cache') );
 519          add_action( 'switch_theme', array(&$this, 'flush_widget_cache') );
 520      }
 521  
 522  	function widget($args, $instance) {
 523          $cache = wp_cache_get('widget_recent_posts', 'widget');
 524  
 525          if ( !is_array($cache) )
 526              $cache = array();
 527  
 528          if ( isset($cache[$args['widget_id']]) ) {
 529              echo $cache[$args['widget_id']];
 530              return;
 531          }
 532  
 533          ob_start();
 534          extract($args);
 535  
 536          $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base);
 537          if ( ! $number = absint( $instance['number'] ) )
 538               $number = 10;
 539  
 540          $r = new WP_Query(array('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true));
 541          if ($r->have_posts()) :
 542  ?>
 543          <?php echo $before_widget; ?>
 544          <?php if ( $title ) echo $before_title . $title . $after_title; ?>
 545          <ul>
 546          <?php  while ($r->have_posts()) : $r->the_post(); ?>
 547          <li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
 548          <?php endwhile; ?>
 549          </ul>
 550          <?php echo $after_widget; ?>
 551  <?php
 552          // Reset the global $the_post as this query will have stomped on it
 553          wp_reset_postdata();
 554  
 555          endif;
 556  
 557          $cache[$args['widget_id']] = ob_get_flush();
 558          wp_cache_set('widget_recent_posts', $cache, 'widget');
 559      }
 560  
 561  	function update( $new_instance, $old_instance ) {
 562          $instance = $old_instance;
 563          $instance['title'] = strip_tags($new_instance['title']);
 564          $instance['number'] = (int) $new_instance['number'];
 565          $this->flush_widget_cache();
 566  
 567          $alloptions = wp_cache_get( 'alloptions', 'options' );
 568          if ( isset($alloptions['widget_recent_entries']) )
 569              delete_option('widget_recent_entries');
 570  
 571          return $instance;
 572      }
 573  
 574  	function flush_widget_cache() {
 575          wp_cache_delete('widget_recent_posts', 'widget');
 576      }
 577  
 578  	function form( $instance ) {
 579          $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
 580          $number = isset($instance['number']) ? absint($instance['number']) : 5;
 581  ?>
 582          <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
 583          <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
 584  
 585          <p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts to show:'); ?></label>
 586          <input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>
 587  <?php
 588      }
 589  }
 590  
 591  /**
 592   * Recent_Comments widget class
 593   *
 594   * @since 2.8.0
 595   */
 596  class WP_Widget_Recent_Comments extends WP_Widget {
 597  
 598  	function __construct() {
 599          $widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'The most recent comments' ) );
 600          parent::__construct('recent-comments', __('Recent Comments'), $widget_ops);
 601          $this->alt_option_name = 'widget_recent_comments';
 602  
 603          if ( is_active_widget(false, false, $this->id_base) )
 604              add_action( 'wp_head', array(&$this, 'recent_comments_style') );
 605  
 606          add_action( 'comment_post', array(&$this, 'flush_widget_cache') );
 607          add_action( 'transition_comment_status', array(&$this, 'flush_widget_cache') );
 608      }
 609  
 610  	function recent_comments_style() {
 611          if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876
 612              || ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) )
 613              return;
 614          ?>
 615      <style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
 616  <?php
 617      }
 618  
 619  	function flush_widget_cache() {
 620          wp_cache_delete('widget_recent_comments', 'widget');
 621      }
 622  
 623  	function widget( $args, $instance ) {
 624          global $comments, $comment;
 625  
 626          $cache = wp_cache_get('widget_recent_comments', 'widget');
 627  
 628          if ( ! is_array( $cache ) )
 629              $cache = array();
 630  
 631          if ( isset( $cache[$args['widget_id']] ) ) {
 632              echo $cache[$args['widget_id']];
 633              return;
 634          }
 635  
 636           extract($args, EXTR_SKIP);
 637           $output = '';
 638           $title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Comments') : $instance['title']);
 639  
 640          if ( ! $number = absint( $instance['number'] ) )
 641               $number = 5;
 642  
 643          $comments = get_comments( array( 'number' => $number, 'status' => 'approve', 'post_status' => 'publish' ) );
 644          $output .= $before_widget;
 645          if ( $title )
 646              $output .= $before_title . $title . $after_title;
 647  
 648          $output .= '<ul id="recentcomments">';
 649          if ( $comments ) {
 650              foreach ( (array) $comments as $comment) {
 651                  $output .=  '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
 652              }
 653           }
 654          $output .= '</ul>';
 655          $output .= $after_widget;
 656  
 657          echo $output;
 658          $cache[$args['widget_id']] = $output;
 659          wp_cache_set('widget_recent_comments', $cache, 'widget');
 660      }
 661  
 662  	function update( $new_instance, $old_instance ) {
 663          $instance = $old_instance;
 664          $instance['title'] = strip_tags($new_instance['title']);
 665          $instance['number'] = absint( $new_instance['number'] );
 666          $this->flush_widget_cache();
 667  
 668          $alloptions = wp_cache_get( 'alloptions', 'options' );
 669          if ( isset($alloptions['widget_recent_comments']) )
 670              delete_option('widget_recent_comments');
 671  
 672          return $instance;
 673      }
 674  
 675  	function form( $instance ) {
 676          $title = isset($instance['title']) ? esc_attr($instance['title']) : '';
 677          $number = isset($instance['number']) ? absint($instance['number']) : 5;
 678  ?>
 679          <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
 680          <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
 681  
 682          <p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of comments to show:'); ?></label>
 683          <input id="<?php echo $this->get_field_id('number'); ?>" name="<?php echo $this->get_field_name('number'); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>
 684  <?php
 685      }
 686  }
 687  
 688  /**
 689   * RSS widget class
 690   *
 691   * @since 2.8.0
 692   */
 693  class WP_Widget_RSS extends WP_Widget {
 694  
 695  	function __construct() {
 696          $widget_ops = array( 'description' => __('Entries from any RSS or Atom feed') );
 697          $control_ops = array( 'width' => 400, 'height' => 200 );
 698          parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops );
 699      }
 700  
 701  	function widget($args, $instance) {
 702  
 703          if ( isset($instance['error']) && $instance['error'] )
 704              return;
 705  
 706          extract($args, EXTR_SKIP);
 707  
 708          $url = $instance['url'];
 709          while ( stristr($url, 'http') != $url )
 710              $url = substr($url, 1);
 711  
 712          if ( empty($url) )
 713              return;
 714  
 715          // self-url destruction sequence
 716          if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) )
 717              return;
 718  
 719          $rss = fetch_feed($url);
 720          $title = $instance['title'];
 721          $desc = '';
 722          $link = '';
 723  
 724          if ( ! is_wp_error($rss) ) {
 725              $desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset'))));
 726              if ( empty($title) )
 727                  $title = esc_html(strip_tags($rss->get_title()));
 728              $link = esc_url(strip_tags($rss->get_permalink()));
 729              while ( stristr($link, 'http') != $link )
 730                  $link = substr($link, 1);
 731          }
 732  
 733          if ( empty($title) )
 734              $title = empty($desc) ? __('Unknown Feed') : $desc;
 735  
 736          $title = apply_filters('widget_title', $title, $instance, $this->id_base);
 737          $url = esc_url(strip_tags($url));
 738          $icon = includes_url('images/rss.png');
 739          if ( $title )
 740              $title = "<a class='rsswidget' href='$url' title='" . esc_attr__( 'Syndicate this content' ) ."'><img style='border:0' width='14' height='14' src='$icon' alt='RSS' /></a> <a class='rsswidget' href='$link' title='$desc'>$title</a>";
 741  
 742          echo $before_widget;
 743          if ( $title )
 744              echo $before_title . $title . $after_title;
 745          wp_widget_rss_output( $rss, $instance );
 746          echo $after_widget;
 747  
 748          if ( ! is_wp_error($rss) )
 749              $rss->__destruct();
 750          unset($rss);
 751      }
 752  
 753  	function update($new_instance, $old_instance) {
 754          $testurl = ( isset($new_instance['url']) && ($new_instance['url'] != $old_instance['url']) );
 755          return wp_widget_rss_process( $new_instance, $testurl );
 756      }
 757  
 758  	function form($instance) {
 759  
 760          if ( empty($instance) )
 761              $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
 762          $instance['number'] = $this->number;
 763  
 764          wp_widget_rss_form( $instance );
 765      }
 766  }
 767  
 768  /**
 769   * Display the RSS entries in a list.
 770   *
 771   * @since 2.5.0
 772   *
 773   * @param string|array|object $rss RSS url.
 774   * @param array $args Widget arguments.
 775   */
 776  function wp_widget_rss_output( $rss, $args = array() ) {
 777      if ( is_string( $rss ) ) {
 778          $rss = fetch_feed($rss);
 779      } elseif ( is_array($rss) && isset($rss['url']) ) {
 780          $args = $rss;
 781          $rss = fetch_feed($rss['url']);
 782      } elseif ( !is_object($rss) ) {
 783          return;
 784      }
 785  
 786      if ( is_wp_error($rss) ) {
 787          if ( is_admin() || current_user_can('manage_options') )
 788              echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';
 789          return;
 790      }
 791  
 792      $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0 );
 793      $args = wp_parse_args( $args, $default_args );
 794      extract( $args, EXTR_SKIP );
 795  
 796      $items = (int) $items;
 797      if ( $items < 1 || 20 < $items )
 798          $items = 10;
 799      $show_summary  = (int) $show_summary;
 800      $show_author   = (int) $show_author;
 801      $show_date     = (int) $show_date;
 802  
 803      if ( !$rss->get_item_quantity() ) {
 804          echo '<ul><li>' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '</li></ul>';
 805          $rss->__destruct();
 806          unset($rss);
 807          return;
 808      }
 809  
 810      echo '<ul>';
 811      foreach ( $rss->get_items(0, $items) as $item ) {
 812          $link = $item->get_link();
 813          while ( stristr($link, 'http') != $link )
 814              $link = substr($link, 1);
 815          $link = esc_url(strip_tags($link));
 816          $title = esc_attr(strip_tags($item->get_title()));
 817          if ( empty($title) )
 818              $title = __('Untitled');
 819  
 820          $desc = str_replace( array("\n", "\r"), ' ', esc_attr( strip_tags( @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option('blog_charset') ) ) ) );
 821          $desc = wp_html_excerpt( $desc, 360 );
 822  
 823          // Append ellipsis. Change existing [...] to [&hellip;].
 824          if ( '[...]' == substr( $desc, -5 ) )
 825              $desc = substr( $desc, 0, -5 ) . '[&hellip;]';
 826          elseif ( '[&hellip;]' != substr( $desc, -10 ) )
 827              $desc .= ' [&hellip;]';
 828  
 829          $desc = esc_html( $desc );
 830  
 831          if ( $show_summary ) {
 832              $summary = "<div class='rssSummary'>$desc</div>";
 833          } else {
 834              $summary = '';
 835          }
 836  
 837          $date = '';
 838          if ( $show_date ) {
 839              $date = $item->get_date( 'U' );
 840  
 841              if ( $date ) {
 842                  $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>';
 843              }
 844          }
 845  
 846          $author = '';
 847          if ( $show_author ) {
 848              $author = $item->get_author();
 849              if ( is_object($author) ) {
 850                  $author = $author->get_name();
 851                  $author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>';
 852              }
 853          }
 854  
 855          if ( $link == '' ) {
 856              echo "<li>$title{$date}{$summary}{$author}</li>";
 857          } else {
 858              echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>";
 859          }
 860      }
 861      echo '</ul>';
 862      $rss->__destruct();
 863      unset($rss);
 864  }
 865  
 866  
 867  
 868  /**
 869   * Display RSS widget options form.
 870   *
 871   * The options for what fields are displayed for the RSS form are all booleans
 872   * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author',
 873   * 'show_date'.
 874   *
 875   * @since 2.5.0
 876   *
 877   * @param array|string $args Values for input fields.
 878   * @param array $inputs Override default display options.
 879   */
 880  function wp_widget_rss_form( $args, $inputs = null ) {
 881  
 882      $default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true );
 883      $inputs = wp_parse_args( $inputs, $default_inputs );
 884      extract( $args );
 885      extract( $inputs, EXTR_SKIP);
 886  
 887      $number = esc_attr( $number );
 888      $title  = esc_attr( $title );
 889      $url    = esc_url( $url );
 890      $items  = (int) $items;
 891      if ( $items < 1 || 20 < $items )
 892          $items  = 10;
 893      $show_summary   = (int) $show_summary;
 894      $show_author    = (int) $show_author;
 895      $show_date      = (int) $show_date;
 896  
 897      if ( !empty($error) )
 898          echo '<p class="widget-error"><strong>' . sprintf( __('RSS Error: %s'), $error) . '</strong></p>';
 899  
 900      if ( $inputs['url'] ) :
 901  ?>
 902      <p><label for="rss-url-<?php echo $number; ?>"><?php _e('Enter the RSS feed URL here:'); ?></label>
 903      <input class="widefat" id="rss-url-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][url]" type="text" value="<?php echo $url; ?>" /></p>
 904  <?php endif; if ( $inputs['title'] ) : ?>
 905      <p><label for="rss-title-<?php echo $number; ?>"><?php _e('Give the feed a title (optional):'); ?></label>
 906      <input class="widefat" id="rss-title-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" /></p>
 907  <?php endif; if ( $inputs['items'] ) : ?>
 908      <p><label for="rss-items-<?php echo $number; ?>"><?php _e('How many items would you like to display?'); ?></label>
 909      <select id="rss-items-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][items]">
 910  <?php
 911          for ( $i = 1; $i <= 20; ++$i )
 912              echo "<option value='$i' " . ( $items == $i ? "selected='selected'" : '' ) . ">$i</option>";
 913  ?>
 914      </select></p>
 915  <?php endif; if ( $inputs['show_summary'] ) : ?>
 916      <p><input id="rss-show-summary-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_summary]" type="checkbox" value="1" <?php if ( $show_summary ) echo 'checked="checked"'; ?>/>
 917      <label for="rss-show-summary-<?php echo $number; ?>"><?php _e('Display item content?'); ?></label></p>
 918  <?php endif; if ( $inputs['show_author'] ) : ?>
 919      <p><input id="rss-show-author-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_author]" type="checkbox" value="1" <?php if ( $show_author ) echo 'checked="checked"'; ?>/>
 920      <label for="rss-show-author-<?php echo $number; ?>"><?php _e('Display item author if available?'); ?></label></p>
 921  <?php endif; if ( $inputs['show_date'] ) : ?>
 922      <p><input id="rss-show-date-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][show_date]" type="checkbox" value="1" <?php if ( $show_date ) echo 'checked="checked"'; ?>/>
 923      <label for="rss-show-date-<?php echo $number; ?>"><?php _e('Display item date?'); ?></label></p>
 924  <?php
 925      endif;
 926      foreach ( array_keys($default_inputs) as $input ) :
 927          if ( 'hidden' === $inputs[$input] ) :
 928              $id = str_replace( '_', '-', $input );
 929  ?>
 930      <input type="hidden" id="rss-<?php echo $id; ?>-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][<?php echo $input; ?>]" value="<?php echo $$input; ?>" />
 931  <?php
 932          endif;
 933      endforeach;
 934  }
 935  
 936  /**
 937   * Process RSS feed widget data and optionally retrieve feed items.
 938   *
 939   * The feed widget can not have more than 20 items or it will reset back to the
 940   * default, which is 10.
 941   *
 942   * The resulting array has the feed title, feed url, feed link (from channel),
 943   * feed items, error (if any), and whether to show summary, author, and date.
 944   * All respectively in the order of the array elements.
 945   *
 946   * @since 2.5.0
 947   *
 948   * @param array $widget_rss RSS widget feed data. Expects unescaped data.
 949   * @param bool $check_feed Optional, default is true. Whether to check feed for errors.
 950   * @return array
 951   */
 952  function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
 953      $items = (int) $widget_rss['items'];
 954      if ( $items < 1 || 20 < $items )
 955          $items = 10;
 956      $url           = esc_url_raw(strip_tags( $widget_rss['url'] ));
 957      $title         = trim(strip_tags( $widget_rss['title'] ));
 958      $show_summary  = isset($widget_rss['show_summary']) ? (int) $widget_rss['show_summary'] : 0;
 959      $show_author   = isset($widget_rss['show_author']) ? (int) $widget_rss['show_author'] :0;
 960      $show_date     = isset($widget_rss['show_date']) ? (int) $widget_rss['show_date'] : 0;
 961  
 962      if ( $check_feed ) {
 963          $rss = fetch_feed($url);
 964          $error = false;
 965          $link = '';
 966          if ( is_wp_error($rss) ) {
 967              $error = $rss->get_error_message();
 968          } else {
 969              $link = esc_url(strip_tags($rss->get_permalink()));
 970              while ( stristr($link, 'http') != $link )
 971                  $link = substr($link, 1);
 972  
 973              $rss->__destruct();
 974              unset($rss);
 975          }
 976      }
 977  
 978      return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );
 979  }
 980  
 981  /**
 982   * Tag cloud widget class
 983   *
 984   * @since 2.8.0
 985   */
 986  class WP_Widget_Tag_Cloud extends WP_Widget {
 987  
 988  	function __construct() {
 989          $widget_ops = array( 'description' => __( "Your most used tags in cloud format") );
 990          parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops);
 991      }
 992  
 993  	function widget( $args, $instance ) {
 994          extract($args);
 995          $current_taxonomy = $this->_get_current_taxonomy($instance);
 996          if ( !empty($instance['title']) ) {
 997              $title = $instance['title'];
 998          } else {
 999              if ( 'post_tag' == $current_taxonomy ) {
1000                  $title = __('Tags');
1001              } else {
1002                  $tax = get_taxonomy($current_taxonomy);
1003                  $title = $tax->labels->name;
1004              }
1005          }
1006          $title = apply_filters('widget_title', $title, $instance, $this->id_base);
1007  
1008          echo $before_widget;
1009          if ( $title )
1010              echo $before_title . $title . $after_title;
1011          echo '<div class="tagcloud">';
1012          wp_tag_cloud( apply_filters('widget_tag_cloud_args', array('taxonomy' => $current_taxonomy) ) );
1013          echo "</div>\n";
1014          echo $after_widget;
1015      }
1016  
1017  	function update( $new_instance, $old_instance ) {
1018          $instance['title'] = strip_tags(stripslashes($new_instance['title']));
1019          $instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
1020          return $instance;
1021      }
1022  
1023  	function form( $instance ) {
1024          $current_taxonomy = $this->_get_current_taxonomy($instance);
1025  ?>
1026      <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
1027      <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>
1028      <p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label>
1029      <select class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>">
1030      <?php foreach ( get_object_taxonomies('post') as $taxonomy ) :
1031                  $tax = get_taxonomy($taxonomy);
1032                  if ( !$tax->show_tagcloud || empty($tax->labels->name) )
1033                      continue;
1034      ?>
1035          <option value="<?php echo esc_attr($taxonomy) ?>" <?php selected($taxonomy, $current_taxonomy) ?>><?php echo $tax->labels->name; ?></option>
1036      <?php endforeach; ?>
1037      </select></p><?php
1038      }
1039  
1040  	function _get_current_taxonomy($instance) {
1041          if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )
1042              return $instance['taxonomy'];
1043  
1044          return 'post_tag';
1045      }
1046  }
1047  
1048  /**
1049   * Navigation Menu widget class
1050   *
1051   * @since 3.0.0
1052   */
1053   class WP_Nav_Menu_Widget extends WP_Widget {
1054  
1055  	function __construct() {
1056          $widget_ops = array( 'description' => __('Use this widget to add one of your custom menus as a widget.') );
1057          parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops );
1058      }
1059  
1060  	function widget($args, $instance) {
1061          // Get menu
1062          $nav_menu = wp_get_nav_menu_object( $instance['nav_menu'] );
1063  
1064          if ( !$nav_menu )
1065              return;
1066  
1067          $instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
1068  
1069          echo $args['before_widget'];
1070  
1071          if ( !empty($instance['title']) )
1072              echo $args['before_title'] . $instance['title'] . $args['after_title'];
1073  
1074          wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu ) );
1075  
1076          echo $args['after_widget'];
1077      }
1078  
1079  	function update( $new_instance, $old_instance ) {
1080          $instance['title'] = strip_tags( stripslashes($new_instance['title']) );
1081          $instance['nav_menu'] = (int) $new_instance['nav_menu'];
1082          return $instance;
1083      }
1084  
1085  	function form( $instance ) {
1086          $title = isset( $instance['title'] ) ? $instance['title'] : '';
1087          $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
1088  
1089          // Get menus
1090          $menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
1091  
1092          // If no menus exists, direct the user to go and create some.
1093          if ( !$menus ) {
1094              echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>';
1095              return;
1096          }
1097          ?>
1098          <p>
1099              <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
1100              <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" />
1101          </p>
1102          <p>
1103              <label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
1104              <select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
1105          <?php
1106              foreach ( $menus as $menu ) {
1107                  $selected = $nav_menu == $menu->term_id ? ' selected="selected"' : '';
1108                  echo '<option'. $selected .' value="'. $menu->term_id .'">'. $menu->name .'</option>';
1109              }
1110          ?>
1111              </select>
1112          </p>
1113          <?php
1114      }
1115  }
1116  
1117  /**
1118   * Register all of the default WordPress widgets on startup.
1119   *
1120   * Calls 'widgets_init' action after all of the WordPress widgets have been
1121   * registered.
1122   *
1123   * @since 2.2.0
1124   */
1125  function wp_widgets_init() {
1126      if ( !is_blog_installed() )
1127          return;
1128  
1129      register_widget('WP_Widget_Pages');
1130  
1131      register_widget('WP_Widget_Calendar');
1132  
1133      register_widget('WP_Widget_Archives');
1134  
1135      register_widget('WP_Widget_Links');
1136  
1137      register_widget('WP_Widget_Meta');
1138  
1139      register_widget('WP_Widget_Search');
1140  
1141      register_widget('WP_Widget_Text');
1142  
1143      register_widget('WP_Widget_Categories');
1144  
1145      register_widget('WP_Widget_Recent_Posts');
1146  
1147      register_widget('WP_Widget_Recent_Comments');
1148  
1149      register_widget('WP_Widget_RSS');
1150  
1151      register_widget('WP_Widget_Tag_Cloud');
1152  
1153      register_widget('WP_Nav_Menu_Widget');
1154  
1155      do_action('widgets_init');
1156  }
1157  
1158  add_action('init', 'wp_widgets_init', 1);


Generated: Wed Jun 1 08:30:02 2011 Cross-referenced by PHPXref 0.7
Provided by Yoast and awesome WordPress Hosting