web/wp-includes/default-widgets.php
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
   148 		<label for="<?php echo $this->get_field_id('category'); ?>"><?php _e( 'Select Link Category:' ); ?></label>
   148 		<label for="<?php echo $this->get_field_id('category'); ?>"><?php _e( 'Select Link Category:' ); ?></label>
   149 		<select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
   149 		<select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
   150 		<option value=""><?php _ex('All Links', 'links widget'); ?></option>
   150 		<option value=""><?php _ex('All Links', 'links widget'); ?></option>
   151 		<?php
   151 		<?php
   152 		foreach ( $link_cats as $link_cat ) {
   152 		foreach ( $link_cats as $link_cat ) {
   153 			echo '<option value="' . intval($link_cat->term_id) . '"'
   153 			echo '<option value="' . intval( $link_cat->term_id ) . '"'
   154 				. ( $link_cat->term_id == $instance['category'] ? ' selected="selected"' : '' )
   154 				. selected( $instance['category'], $link_cat->term_id, false )
   155 				. '>' . $link_cat->name . "</option>\n";
   155 				. '>' . $link_cat->name . "</option>\n";
   156 		}
   156 		}
   157 		?>
   157 		?>
   158 		</select>
   158 		</select>
   159 		<label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:' ); ?></label>
   159 		<label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:' ); ?></label>
   160 		<select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat">
   160 		<select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat">
   161 			<option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e( 'Link title' ); ?></option>
   161 			<option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e( 'Link title' ); ?></option>
   162 			<option value="rating"<?php selected( $instance['orderby'], 'rating' ); ?>><?php _e( 'Link rating' ); ?></option>
   162 			<option value="rating"<?php selected( $instance['orderby'], 'rating' ); ?>><?php _e( 'Link rating' ); ?></option>
   163 			<option value="id"<?php selected( $instance['orderby'], 'id' ); ?>><?php _e( 'Link ID' ); ?></option>
   163 			<option value="id"<?php selected( $instance['orderby'], 'id' ); ?>><?php _e( 'Link ID' ); ?></option>
   164 			<option value="rand"<?php selected( $instance['orderby'], 'rand' ); ?>><?php _e( 'Random' ); ?></option>
   164 			<option value="rand"<?php selected( $instance['orderby'], 'rand' ); ?>><?php _ex( 'Random', 'Links widget' ); ?></option>
   165 		</select>
   165 		</select>
   166 		</p>
   166 		</p>
   167 		<p>
   167 		<p>
   168 		<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'); ?>" />
   168 		<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'); ?>" />
   169 		<label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />
   169 		<label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />
   353 		parent::__construct('calendar', __('Calendar'), $widget_ops);
   353 		parent::__construct('calendar', __('Calendar'), $widget_ops);
   354 	}
   354 	}
   355 
   355 
   356 	function widget( $args, $instance ) {
   356 	function widget( $args, $instance ) {
   357 		extract($args);
   357 		extract($args);
   358 		$title = apply_filters('widget_title', empty($instance['title']) ? '&nbsp;' : $instance['title'], $instance, $this->id_base);
   358 		$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
   359 		echo $before_widget;
   359 		echo $before_widget;
   360 		if ( $title )
   360 		if ( $title )
   361 			echo $before_title . $title . $after_title;
   361 			echo $before_title . $title . $after_title;
   362 		echo '<div id="calendar_wrap">';
   362 		echo '<div id="calendar_wrap">';
   363 		get_calendar();
   363 		get_calendar();
   534 	function __construct() {
   534 	function __construct() {
   535 		$widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your site") );
   535 		$widget_ops = array('classname' => 'widget_recent_entries', 'description' => __( "The most recent posts on your site") );
   536 		parent::__construct('recent-posts', __('Recent Posts'), $widget_ops);
   536 		parent::__construct('recent-posts', __('Recent Posts'), $widget_ops);
   537 		$this->alt_option_name = 'widget_recent_entries';
   537 		$this->alt_option_name = 'widget_recent_entries';
   538 
   538 
   539 		add_action( 'save_post', array(&$this, 'flush_widget_cache') );
   539 		add_action( 'save_post', array($this, 'flush_widget_cache') );
   540 		add_action( 'deleted_post', array(&$this, 'flush_widget_cache') );
   540 		add_action( 'deleted_post', array($this, 'flush_widget_cache') );
   541 		add_action( 'switch_theme', array(&$this, 'flush_widget_cache') );
   541 		add_action( 'switch_theme', array($this, 'flush_widget_cache') );
   542 	}
   542 	}
   543 
   543 
   544 	function widget($args, $instance) {
   544 	function widget($args, $instance) {
   545 		$cache = wp_cache_get('widget_recent_posts', 'widget');
   545 		$cache = wp_cache_get('widget_recent_posts', 'widget');
   546 
   546 
   559 		extract($args);
   559 		extract($args);
   560 
   560 
   561 		$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base);
   561 		$title = apply_filters('widget_title', empty($instance['title']) ? __('Recent Posts') : $instance['title'], $instance, $this->id_base);
   562 		if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
   562 		if ( empty( $instance['number'] ) || ! $number = absint( $instance['number'] ) )
   563  			$number = 10;
   563  			$number = 10;
       
   564 		$show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
   564 
   565 
   565 		$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 ) ) );
   566 		$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 ) ) );
   566 		if ($r->have_posts()) :
   567 		if ($r->have_posts()) :
   567 ?>
   568 ?>
   568 		<?php echo $before_widget; ?>
   569 		<?php echo $before_widget; ?>
   569 		<?php if ( $title ) echo $before_title . $title . $after_title; ?>
   570 		<?php if ( $title ) echo $before_title . $title . $after_title; ?>
   570 		<ul>
   571 		<ul>
   571 		<?php  while ($r->have_posts()) : $r->the_post(); ?>
   572 		<?php while ( $r->have_posts() ) : $r->the_post(); ?>
   572 		<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>
   573 			<li>
       
   574 				<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>
       
   575 			<?php if ( $show_date ) : ?>
       
   576 				<span class="post-date"><?php echo get_the_date(); ?></span>
       
   577 			<?php endif; ?>
       
   578 			</li>
   573 		<?php endwhile; ?>
   579 		<?php endwhile; ?>
   574 		</ul>
   580 		</ul>
   575 		<?php echo $after_widget; ?>
   581 		<?php echo $after_widget; ?>
   576 <?php
   582 <?php
   577 		// Reset the global $the_post as this query will have stomped on it
   583 		// Reset the global $the_post as this query will have stomped on it
   585 
   591 
   586 	function update( $new_instance, $old_instance ) {
   592 	function update( $new_instance, $old_instance ) {
   587 		$instance = $old_instance;
   593 		$instance = $old_instance;
   588 		$instance['title'] = strip_tags($new_instance['title']);
   594 		$instance['title'] = strip_tags($new_instance['title']);
   589 		$instance['number'] = (int) $new_instance['number'];
   595 		$instance['number'] = (int) $new_instance['number'];
       
   596 		$instance['show_date'] = (bool) $new_instance['show_date'];
   590 		$this->flush_widget_cache();
   597 		$this->flush_widget_cache();
   591 
   598 
   592 		$alloptions = wp_cache_get( 'alloptions', 'options' );
   599 		$alloptions = wp_cache_get( 'alloptions', 'options' );
   593 		if ( isset($alloptions['widget_recent_entries']) )
   600 		if ( isset($alloptions['widget_recent_entries']) )
   594 			delete_option('widget_recent_entries');
   601 			delete_option('widget_recent_entries');
   599 	function flush_widget_cache() {
   606 	function flush_widget_cache() {
   600 		wp_cache_delete('widget_recent_posts', 'widget');
   607 		wp_cache_delete('widget_recent_posts', 'widget');
   601 	}
   608 	}
   602 
   609 
   603 	function form( $instance ) {
   610 	function form( $instance ) {
   604 		$title = isset($instance['title']) ? esc_attr($instance['title']) : '';
   611 		$title     = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
   605 		$number = isset($instance['number']) ? absint($instance['number']) : 5;
   612 		$number    = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
   606 ?>
   613 		$show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
   607 		<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
   614 ?>
   608 		<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>
   615 		<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
   609 
   616 		<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>
   610 		<p><label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number of posts to show:'); ?></label>
   617 
   611 		<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>
   618 		<p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to show:' ); ?></label>
       
   619 		<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>
       
   620 
       
   621 		<p><input class="checkbox" type="checkbox" <?php checked( $show_date ); ?> id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" />
       
   622 		<label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display post date?' ); ?></label></p>
   612 <?php
   623 <?php
   613 	}
   624 	}
   614 }
   625 }
   615 
   626 
   616 /**
   627 /**
   624 		$widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'The most recent comments' ) );
   635 		$widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'The most recent comments' ) );
   625 		parent::__construct('recent-comments', __('Recent Comments'), $widget_ops);
   636 		parent::__construct('recent-comments', __('Recent Comments'), $widget_ops);
   626 		$this->alt_option_name = 'widget_recent_comments';
   637 		$this->alt_option_name = 'widget_recent_comments';
   627 
   638 
   628 		if ( is_active_widget(false, false, $this->id_base) )
   639 		if ( is_active_widget(false, false, $this->id_base) )
   629 			add_action( 'wp_head', array(&$this, 'recent_comments_style') );
   640 			add_action( 'wp_head', array($this, 'recent_comments_style') );
   630 
   641 
   631 		add_action( 'comment_post', array(&$this, 'flush_widget_cache') );
   642 		add_action( 'comment_post', array($this, 'flush_widget_cache') );
   632 		add_action( 'transition_comment_status', array(&$this, 'flush_widget_cache') );
   643 		add_action( 'transition_comment_status', array($this, 'flush_widget_cache') );
   633 	}
   644 	}
   634 
   645 
   635 	function recent_comments_style() {
   646 	function recent_comments_style() {
   636 		if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876
   647 		if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876
   637 			|| ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) )
   648 			|| ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) )
   673 		if ( $title )
   684 		if ( $title )
   674 			$output .= $before_title . $title . $after_title;
   685 			$output .= $before_title . $title . $after_title;
   675 
   686 
   676 		$output .= '<ul id="recentcomments">';
   687 		$output .= '<ul id="recentcomments">';
   677 		if ( $comments ) {
   688 		if ( $comments ) {
       
   689 			// Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)
       
   690 			$post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) );
       
   691 			_prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false );
       
   692 
   678 			foreach ( (array) $comments as $comment) {
   693 			foreach ( (array) $comments as $comment) {
   679 				$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>';
   694 				$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>';
   680 			}
   695 			}
   681  		}
   696  		}
   682 		$output .= '</ul>';
   697 		$output .= '</ul>';
   827 	$show_summary  = (int) $show_summary;
   842 	$show_summary  = (int) $show_summary;
   828 	$show_author   = (int) $show_author;
   843 	$show_author   = (int) $show_author;
   829 	$show_date     = (int) $show_date;
   844 	$show_date     = (int) $show_date;
   830 
   845 
   831 	if ( !$rss->get_item_quantity() ) {
   846 	if ( !$rss->get_item_quantity() ) {
   832 		echo '<ul><li>' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '</li></ul>';
   847 		echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>';
   833 		$rss->__destruct();
   848 		$rss->__destruct();
   834 		unset($rss);
   849 		unset($rss);
   835 		return;
   850 		return;
   836 	}
   851 	}
   837 
   852 
   933 <?php endif; if ( $inputs['items'] ) : ?>
   948 <?php endif; if ( $inputs['items'] ) : ?>
   934 	<p><label for="rss-items-<?php echo $number; ?>"><?php _e('How many items would you like to display?'); ?></label>
   949 	<p><label for="rss-items-<?php echo $number; ?>"><?php _e('How many items would you like to display?'); ?></label>
   935 	<select id="rss-items-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][items]">
   950 	<select id="rss-items-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][items]">
   936 <?php
   951 <?php
   937 		for ( $i = 1; $i <= 20; ++$i )
   952 		for ( $i = 1; $i <= 20; ++$i )
   938 			echo "<option value='$i' " . ( $items == $i ? "selected='selected'" : '' ) . ">$i</option>";
   953 			echo "<option value='$i' " . selected( $items, $i, false ) . ">$i</option>";
   939 ?>
   954 ?>
   940 	</select></p>
   955 	</select></p>
   941 <?php endif; if ( $inputs['show_summary'] ) : ?>
   956 <?php endif; if ( $inputs['show_summary'] ) : ?>
   942 	<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"'; ?>/>
   957 	<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"'; ?>/>
   943 	<label for="rss-show-summary-<?php echo $number; ?>"><?php _e('Display item content?'); ?></label></p>
   958 	<label for="rss-show-summary-<?php echo $number; ?>"><?php _e('Display item content?'); ?></label></p>
  1128 		<p>
  1143 		<p>
  1129 			<label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
  1144 			<label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
  1130 			<select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
  1145 			<select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
  1131 		<?php
  1146 		<?php
  1132 			foreach ( $menus as $menu ) {
  1147 			foreach ( $menus as $menu ) {
  1133 				$selected = $nav_menu == $menu->term_id ? ' selected="selected"' : '';
  1148 				echo '<option value="' . $menu->term_id . '"'
  1134 				echo '<option'. $selected .' value="'. $menu->term_id .'">'. $menu->name .'</option>';
  1149 					. selected( $nav_menu, $menu->term_id, false )
       
  1150 					. '>'. $menu->name . '</option>';
  1135 			}
  1151 			}
  1136 		?>
  1152 		?>
  1137 			</select>
  1153 			</select>
  1138 		</p>
  1154 		</p>
  1139 		<?php
  1155 		<?php
  1156 
  1172 
  1157 	register_widget('WP_Widget_Calendar');
  1173 	register_widget('WP_Widget_Calendar');
  1158 
  1174 
  1159 	register_widget('WP_Widget_Archives');
  1175 	register_widget('WP_Widget_Archives');
  1160 
  1176 
  1161 	register_widget('WP_Widget_Links');
  1177 	if ( get_option( 'link_manager_enabled' ) )
       
  1178 		register_widget('WP_Widget_Links');
  1162 
  1179 
  1163 	register_widget('WP_Widget_Meta');
  1180 	register_widget('WP_Widget_Meta');
  1164 
  1181 
  1165 	register_widget('WP_Widget_Search');
  1182 	register_widget('WP_Widget_Search');
  1166 
  1183