PageRenderTime 62ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/APP/wp-includes/default-widgets.php

https://bitbucket.org/AFelipeTrujillo/goblog
PHP | 1411 lines | 931 code | 222 blank | 258 comment | 126 complexity | 64eac025f0aa60a5127000fa6b38bcde MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file