PageRenderTime 56ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/default-widgets.php

https://github.com/davodey/WordPress
PHP | 1414 lines | 935 code | 221 blank | 258 comment | 126 complexity | 3f2474933c43e9c92a683af4f8e58239 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.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. public 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. public function widget( $args, $instance ) {
  19. /**
  20. * Filter the widget title.
  21. *
  22. * @since 2.6.0
  23. *
  24. * @param string $title The widget title. Default 'Pages'.
  25. * @param array $instance An array of the widget's settings.
  26. * @param mixed $id_base The widget ID.
  27. */
  28. $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base );
  29. $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
  30. $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
  31. if ( $sortby == 'menu_order' )
  32. $sortby = 'menu_order, post_title';
  33. /**
  34. * Filter the arguments for the Pages widget.
  35. *
  36. * @since 2.8.0
  37. *
  38. * @see wp_list_pages()
  39. *
  40. * @param array $args An array of arguments to retrieve the pages list.
  41. */
  42. $out = wp_list_pages( apply_filters( 'widget_pages_args', array(
  43. 'title_li' => '',
  44. 'echo' => 0,
  45. 'sort_column' => $sortby,
  46. 'exclude' => $exclude
  47. ) ) );
  48. if ( ! empty( $out ) ) {
  49. echo $args['before_widget'];
  50. if ( $title ) {
  51. echo $args['before_title'] . $title . $args['after_title'];
  52. }
  53. ?>
  54. <ul>
  55. <?php echo $out; ?>
  56. </ul>
  57. <?php
  58. echo $args['after_widget'];
  59. }
  60. }
  61. public 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. public 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. public function __construct() {
  102. $widget_ops = array('description' => __( "Your blogroll" ) );
  103. parent::__construct('links', __('Links'), $widget_ops);
  104. }
  105. public function widget( $args, $instance ) {
  106. $show_description = isset($instance['description']) ? $instance['description'] : false;
  107. $show_name = isset($instance['name']) ? $instance['name'] : false;
  108. $show_rating = isset($instance['rating']) ? $instance['rating'] : false;
  109. $show_images = isset($instance['images']) ? $instance['images'] : true;
  110. $category = isset($instance['category']) ? $instance['category'] : false;
  111. $orderby = isset( $instance['orderby'] ) ? $instance['orderby'] : 'name';
  112. $order = $orderby == 'rating' ? 'DESC' : 'ASC';
  113. $limit = isset( $instance['limit'] ) ? $instance['limit'] : -1;
  114. $before_widget = preg_replace( '/id="[^"]*"/', 'id="%id"', $args['before_widget'] );
  115. /**
  116. * Filter the arguments for the Links widget.
  117. *
  118. * @since 2.6.0
  119. *
  120. * @see wp_list_bookmarks()
  121. *
  122. * @param array $args An array of arguments to retrieve the links list.
  123. */
  124. wp_list_bookmarks( apply_filters( 'widget_links_args', array(
  125. 'title_before' => $args['before_title'], 'title_after' => $args['after_title'],
  126. 'category_before' => $before_widget, 'category_after' => $args['after_widget'],
  127. 'show_images' => $show_images, 'show_description' => $show_description,
  128. 'show_name' => $show_name, 'show_rating' => $show_rating,
  129. 'category' => $category, 'class' => 'linkcat widget',
  130. 'orderby' => $orderby, 'order' => $order,
  131. 'limit' => $limit,
  132. ) ) );
  133. }
  134. public function update( $new_instance, $old_instance ) {
  135. $new_instance = (array) $new_instance;
  136. $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 );
  137. foreach ( $instance as $field => $val ) {
  138. if ( isset($new_instance[$field]) )
  139. $instance[$field] = 1;
  140. }
  141. $instance['orderby'] = 'name';
  142. if ( in_array( $new_instance['orderby'], array( 'name', 'rating', 'id', 'rand' ) ) )
  143. $instance['orderby'] = $new_instance['orderby'];
  144. $instance['category'] = intval( $new_instance['category'] );
  145. $instance['limit'] = ! empty( $new_instance['limit'] ) ? intval( $new_instance['limit'] ) : -1;
  146. return $instance;
  147. }
  148. public function form( $instance ) {
  149. //Defaults
  150. $instance = wp_parse_args( (array) $instance, array( 'images' => true, 'name' => true, 'description' => false, 'rating' => false, 'category' => false, 'orderby' => 'name', 'limit' => -1 ) );
  151. $link_cats = get_terms( 'link_category' );
  152. if ( ! $limit = intval( $instance['limit'] ) )
  153. $limit = -1;
  154. ?>
  155. <p>
  156. <label for="<?php echo $this->get_field_id('category'); ?>"><?php _e( 'Select Link Category:' ); ?></label>
  157. <select class="widefat" id="<?php echo $this->get_field_id('category'); ?>" name="<?php echo $this->get_field_name('category'); ?>">
  158. <option value=""><?php _ex('All Links', 'links widget'); ?></option>
  159. <?php
  160. foreach ( $link_cats as $link_cat ) {
  161. echo '<option value="' . intval( $link_cat->term_id ) . '"'
  162. . selected( $instance['category'], $link_cat->term_id, false )
  163. . '>' . $link_cat->name . "</option>\n";
  164. }
  165. ?>
  166. </select>
  167. <label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e( 'Sort by:' ); ?></label>
  168. <select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat">
  169. <option value="name"<?php selected( $instance['orderby'], 'name' ); ?>><?php _e( 'Link title' ); ?></option>
  170. <option value="rating"<?php selected( $instance['orderby'], 'rating' ); ?>><?php _e( 'Link rating' ); ?></option>
  171. <option value="id"<?php selected( $instance['orderby'], 'id' ); ?>><?php _e( 'Link ID' ); ?></option>
  172. <option value="rand"<?php selected( $instance['orderby'], 'rand' ); ?>><?php _ex( 'Random', 'Links widget' ); ?></option>
  173. </select>
  174. </p>
  175. <p>
  176. <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'); ?>" />
  177. <label for="<?php echo $this->get_field_id('images'); ?>"><?php _e('Show Link Image'); ?></label><br />
  178. <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'); ?>" />
  179. <label for="<?php echo $this->get_field_id('name'); ?>"><?php _e('Show Link Name'); ?></label><br />
  180. <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'); ?>" />
  181. <label for="<?php echo $this->get_field_id('description'); ?>"><?php _e('Show Link Description'); ?></label><br />
  182. <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'); ?>" />
  183. <label for="<?php echo $this->get_field_id('rating'); ?>"><?php _e('Show Link Rating'); ?></label>
  184. </p>
  185. <p>
  186. <label for="<?php echo $this->get_field_id('limit'); ?>"><?php _e( 'Number of links to show:' ); ?></label>
  187. <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" />
  188. </p>
  189. <?php
  190. }
  191. }
  192. /**
  193. * Search widget class
  194. *
  195. * @since 2.8.0
  196. */
  197. class WP_Widget_Search extends WP_Widget {
  198. public function __construct() {
  199. $widget_ops = array('classname' => 'widget_search', 'description' => __( "A search form for your site.") );
  200. parent::__construct( 'search', _x( 'Search', 'Search widget' ), $widget_ops );
  201. }
  202. public function widget( $args, $instance ) {
  203. /** This filter is documented in wp-includes/default-widgets.php */
  204. $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
  205. echo $args['before_widget'];
  206. if ( $title ) {
  207. echo $args['before_title'] . $title . $args['after_title'];
  208. }
  209. // Use current theme search form if it exists
  210. get_search_form();
  211. echo $args['after_widget'];
  212. }
  213. public function form( $instance ) {
  214. $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
  215. $title = $instance['title'];
  216. ?>
  217. <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>
  218. <?php
  219. }
  220. public function update( $new_instance, $old_instance ) {
  221. $instance = $old_instance;
  222. $new_instance = wp_parse_args((array) $new_instance, array( 'title' => ''));
  223. $instance['title'] = strip_tags($new_instance['title']);
  224. return $instance;
  225. }
  226. }
  227. /**
  228. * Archives widget class
  229. *
  230. * @since 2.8.0
  231. */
  232. class WP_Widget_Archives extends WP_Widget {
  233. public function __construct() {
  234. $widget_ops = array('classname' => 'widget_archive', 'description' => __( 'A monthly archive of your site&#8217;s Posts.') );
  235. parent::__construct('archives', __('Archives'), $widget_ops);
  236. }
  237. public function widget( $args, $instance ) {
  238. $c = ! empty( $instance['count'] ) ? '1' : '0';
  239. $d = ! empty( $instance['dropdown'] ) ? '1' : '0';
  240. /** This filter is documented in wp-includes/default-widgets.php */
  241. $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Archives' ) : $instance['title'], $instance, $this->id_base );
  242. echo $args['before_widget'];
  243. if ( $title ) {
  244. echo $args['before_title'] . $title . $args['after_title'];
  245. }
  246. if ( $d ) {
  247. ?>
  248. <select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
  249. <option value=""><?php echo esc_attr( __( 'Select Month' ) ); ?></option>
  250. <?php
  251. /**
  252. * Filter the arguments for the Archives widget drop-down.
  253. *
  254. * @since 2.8.0
  255. *
  256. * @see wp_get_archives()
  257. *
  258. * @param array $args An array of Archives widget drop-down arguments.
  259. */
  260. wp_get_archives( apply_filters( 'widget_archives_dropdown_args', array(
  261. 'type' => 'monthly',
  262. 'format' => 'option',
  263. 'show_post_count' => $c
  264. ) ) );
  265. ?>
  266. </select>
  267. <?php
  268. } else {
  269. ?>
  270. <ul>
  271. <?php
  272. /**
  273. * Filter the arguments for the Archives widget.
  274. *
  275. * @since 2.8.0
  276. *
  277. * @see wp_get_archives()
  278. *
  279. * @param array $args An array of Archives option arguments.
  280. */
  281. wp_get_archives( apply_filters( 'widget_archives_args', array(
  282. 'type' => 'monthly',
  283. 'show_post_count' => $c
  284. ) ) );
  285. ?>
  286. </ul>
  287. <?php
  288. }
  289. echo $args['after_widget'];
  290. }
  291. public function update( $new_instance, $old_instance ) {
  292. $instance = $old_instance;
  293. $new_instance = wp_parse_args( (array) $new_instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
  294. $instance['title'] = strip_tags($new_instance['title']);
  295. $instance['count'] = $new_instance['count'] ? 1 : 0;
  296. $instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0;
  297. return $instance;
  298. }
  299. public function form( $instance ) {
  300. $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'count' => 0, 'dropdown' => '') );
  301. $title = strip_tags($instance['title']);
  302. $count = $instance['count'] ? 'checked="checked"' : '';
  303. $dropdown = $instance['dropdown'] ? 'checked="checked"' : '';
  304. ?>
  305. <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>
  306. <p>
  307. <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>
  308. <br/>
  309. <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>
  310. </p>
  311. <?php
  312. }
  313. }
  314. /**
  315. * Meta widget class
  316. *
  317. * Displays log in/out, RSS feed links, etc.
  318. *
  319. * @since 2.8.0
  320. */
  321. class WP_Widget_Meta extends WP_Widget {
  322. public function __construct() {
  323. $widget_ops = array('classname' => 'widget_meta', 'description' => __( "Login, RSS, &amp; WordPress.org links.") );
  324. parent::__construct('meta', __('Meta'), $widget_ops);
  325. }
  326. public function widget( $args, $instance ) {
  327. /** This filter is documented in wp-includes/default-widgets.php */
  328. $title = apply_filters( 'widget_title', empty($instance['title']) ? __( 'Meta' ) : $instance['title'], $instance, $this->id_base );
  329. echo $args['before_widget'];
  330. if ( $title ) {
  331. echo $args['before_title'] . $title . $args['after_title'];
  332. }
  333. ?>
  334. <ul>
  335. <?php wp_register(); ?>
  336. <li><?php wp_loginout(); ?></li>
  337. <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>
  338. <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>
  339. <?php
  340. /**
  341. * Filter the "Powered by WordPress" text in the Meta widget.
  342. *
  343. * @since 3.6.0
  344. *
  345. * @param string $title_text Default title text for the WordPress.org link.
  346. */
  347. echo apply_filters( 'widget_meta_poweredby', sprintf( '<li><a href="%s" title="%s">%s</a></li>',
  348. esc_url( __( 'https://wordpress.org/' ) ),
  349. esc_attr__( 'Powered by WordPress, state-of-the-art semantic personal publishing platform.' ),
  350. _x( 'WordPress.org', 'meta widget link text' )
  351. ) );
  352. wp_meta();
  353. ?>
  354. </ul>
  355. <?php
  356. echo $args['after_widget'];
  357. }
  358. public function update( $new_instance, $old_instance ) {
  359. $instance = $old_instance;
  360. $instance['title'] = strip_tags($new_instance['title']);
  361. return $instance;
  362. }
  363. public function form( $instance ) {
  364. $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
  365. $title = strip_tags($instance['title']);
  366. ?>
  367. <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>
  368. <?php
  369. }
  370. }
  371. /**
  372. * Calendar widget class
  373. *
  374. * @since 2.8.0
  375. */
  376. class WP_Widget_Calendar extends WP_Widget {
  377. public function __construct() {
  378. $widget_ops = array('classname' => 'widget_calendar', 'description' => __( 'A calendar of your site&#8217;s Posts.') );
  379. parent::__construct('calendar', __('Calendar'), $widget_ops);
  380. }
  381. public function widget( $args, $instance ) {
  382. /** This filter is documented in wp-includes/default-widgets.php */
  383. $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
  384. echo $args['before_widget'];
  385. if ( $title ) {
  386. echo $args['before_title'] . $title . $args['after_title'];
  387. }
  388. echo '<div id="calendar_wrap">';
  389. get_calendar();
  390. echo '</div>';
  391. echo $args['after_widget'];
  392. }
  393. public function update( $new_instance, $old_instance ) {
  394. $instance = $old_instance;
  395. $instance['title'] = strip_tags($new_instance['title']);
  396. return $instance;
  397. }
  398. public function form( $instance ) {
  399. $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
  400. $title = strip_tags($instance['title']);
  401. ?>
  402. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
  403. <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>
  404. <?php
  405. }
  406. }
  407. /**
  408. * Text widget class
  409. *
  410. * @since 2.8.0
  411. */
  412. class WP_Widget_Text extends WP_Widget {
  413. public function __construct() {
  414. $widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML.'));
  415. $control_ops = array('width' => 400, 'height' => 350);
  416. parent::__construct('text', __('Text'), $widget_ops, $control_ops);
  417. }
  418. public function widget( $args, $instance ) {
  419. /** This filter is documented in wp-includes/default-widgets.php */
  420. $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
  421. /**
  422. * Filter the content of the Text widget.
  423. *
  424. * @since 2.3.0
  425. *
  426. * @param string $widget_text The widget content.
  427. * @param WP_Widget $instance WP_Widget instance.
  428. */
  429. $text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance );
  430. echo $args['before_widget'];
  431. if ( ! empty( $title ) ) {
  432. echo $args['before_title'] . $title . $args['after_title'];
  433. } ?>
  434. <div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>
  435. <?php
  436. echo $args['after_widget'];
  437. }
  438. public 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. public 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. public 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. public function widget( $args, $instance ) {
  471. /** This filter is documented in wp-includes/default-widgets.php */
  472. $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title'], $instance, $this->id_base );
  473. $c = ! empty( $instance['count'] ) ? '1' : '0';
  474. $h = ! empty( $instance['hierarchical'] ) ? '1' : '0';
  475. $d = ! empty( $instance['dropdown'] ) ? '1' : '0';
  476. echo $args['before_widget'];
  477. if ( $title ) {
  478. echo $args['before_title'] . $title . $args['after_title'];
  479. }
  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 $args['after_widget'];
  524. }
  525. public 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. public 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. public 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. public 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. $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Recent Posts' );
  583. /** This filter is documented in wp-includes/default-widgets.php */
  584. $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
  585. $number = ( ! empty( $instance['number'] ) ) ? absint( $instance['number'] ) : 5;
  586. if ( ! $number )
  587. $number = 5;
  588. $show_date = isset( $instance['show_date'] ) ? $instance['show_date'] : false;
  589. /**
  590. * Filter the arguments for the Recent Posts widget.
  591. *
  592. * @since 3.4.0
  593. *
  594. * @see WP_Query::get_posts()
  595. *
  596. * @param array $args An array of arguments used to retrieve the recent posts.
  597. */
  598. $r = new WP_Query( apply_filters( 'widget_posts_args', array(
  599. 'posts_per_page' => $number,
  600. 'no_found_rows' => true,
  601. 'post_status' => 'publish',
  602. 'ignore_sticky_posts' => true
  603. ) ) );
  604. if ($r->have_posts()) :
  605. ?>
  606. <?php echo $args['before_widget']; ?>
  607. <?php if ( $title ) {
  608. echo $args['before_title'] . $title . $args['after_title'];
  609. } ?>
  610. <ul>
  611. <?php while ( $r->have_posts() ) : $r->the_post(); ?>
  612. <li>
  613. <a href="<?php the_permalink(); ?>"><?php get_the_title() ? the_title() : the_ID(); ?></a>
  614. <?php if ( $show_date ) : ?>
  615. <span class="post-date"><?php echo get_the_date(); ?></span>
  616. <?php endif; ?>
  617. </li>
  618. <?php endwhile; ?>
  619. </ul>
  620. <?php echo $args['after_widget']; ?>
  621. <?php
  622. // Reset the global $the_post as this query will have stomped on it
  623. wp_reset_postdata();
  624. endif;
  625. if ( ! $this->is_preview() ) {
  626. $cache[ $args['widget_id'] ] = ob_get_flush();
  627. wp_cache_set( 'widget_recent_posts', $cache, 'widget' );
  628. } else {
  629. ob_end_flush();
  630. }
  631. }
  632. public function update( $new_instance, $old_instance ) {
  633. $instance = $old_instance;
  634. $instance['title'] = strip_tags($new_instance['title']);
  635. $instance['number'] = (int) $new_instance['number'];
  636. $instance['show_date'] = isset( $new_instance['show_date'] ) ? (bool) $new_instance['show_date'] : false;
  637. $this->flush_widget_cache();
  638. $alloptions = wp_cache_get( 'alloptions', 'options' );
  639. if ( isset($alloptions['widget_recent_entries']) )
  640. delete_option('widget_recent_entries');
  641. return $instance;
  642. }
  643. public function flush_widget_cache() {
  644. wp_cache_delete('widget_recent_posts', 'widget');
  645. }
  646. public function form( $instance ) {
  647. $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
  648. $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
  649. $show_date = isset( $instance['show_date'] ) ? (bool) $instance['show_date'] : false;
  650. ?>
  651. <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
  652. <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>
  653. <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to show:' ); ?></label>
  654. <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>
  655. <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' ); ?>" />
  656. <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Display post date?' ); ?></label></p>
  657. <?php
  658. }
  659. }
  660. /**
  661. * Recent_Comments widget class
  662. *
  663. * @since 2.8.0
  664. */
  665. class WP_Widget_Recent_Comments extends WP_Widget {
  666. public function __construct() {
  667. $widget_ops = array('classname' => 'widget_recent_comments', 'description' => __( 'Your site&#8217;s most recent comments.' ) );
  668. parent::__construct('recent-comments', __('Recent Comments'), $widget_ops);
  669. $this->alt_option_name = 'widget_recent_comments';
  670. if ( is_active_widget(false, false, $this->id_base) )
  671. add_action( 'wp_head', array($this, 'recent_comments_style') );
  672. add_action( 'comment_post', array($this, 'flush_widget_cache') );
  673. add_action( 'edit_comment', array($this, 'flush_widget_cache') );
  674. add_action( 'transition_comment_status', array($this, 'flush_widget_cache') );
  675. }
  676. public function recent_comments_style() {
  677. /**
  678. * Filter the Recent Comments default widget styles.
  679. *
  680. * @since 3.1.0
  681. *
  682. * @param bool $active Whether the widget is active. Default true.
  683. * @param string $id_base The widget ID.
  684. */
  685. if ( ! current_theme_supports( 'widgets' ) // Temp hack #14876
  686. || ! apply_filters( 'show_recent_comments_widget_style', true, $this->id_base ) )
  687. return;
  688. ?>
  689. <style type="text/css">.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
  690. <?php
  691. }
  692. public function flush_widget_cache() {
  693. wp_cache_delete('widget_recent_comments', 'widget');
  694. }
  695. public function widget( $args, $instance ) {
  696. global $comments, $comment;
  697. $cache = array();
  698. if ( ! $this->is_preview() ) {
  699. $cache = wp_cache_get('widget_recent_comments', 'widget');
  700. }
  701. if ( ! is_array( $cache ) ) {
  702. $cache = array();
  703. }
  704. if ( ! isset( $args['widget_id'] ) )
  705. $args['widget_id'] = $this->id;
  706. if ( isset( $cache[ $args['widget_id'] ] ) ) {
  707. echo $cache[ $args['widget_id'] ];
  708. return;
  709. }
  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 .= $args['before_widget'];
  732. if ( $title ) {
  733. $output .= $args['before_title'] . $title . $args['after_title'];
  734. }
  735. $output .= '<ul id="recentcomments">';
  736. if ( $comments ) {
  737. // Prime cache for associated posts. (Prime post term cache if we need it for permalinks.)
  738. $post_ids = array_unique( wp_list_pluck( $comments, 'comment_post_ID' ) );
  739. _prime_post_caches( $post_ids, strpos( get_option( 'permalink_structure' ), '%category%' ), false );
  740. foreach ( (array) $comments as $comment) {
  741. $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>';
  742. }
  743. }
  744. $output .= '</ul>';
  745. $output .= $args['after_widget'];
  746. echo $output;
  747. if ( ! $this->is_preview() ) {
  748. $cache[ $args['widget_id'] ] = $output;
  749. wp_cache_set( 'widget_recent_comments', $cache, 'widget' );
  750. }
  751. }
  752. public function update( $new_instance, $old_instance ) {
  753. $instance = $old_instance;
  754. $instance['title'] = strip_tags($new_instance['title']);
  755. $instance['number'] = absint( $new_instance['number'] );
  756. $this->flush_widget_cache();
  757. $alloptions = wp_cache_get( 'alloptions', 'options' );
  758. if ( isset($alloptions['widget_recent_comments']) )
  759. delete_option('widget_recent_comments');
  760. return $instance;
  761. }
  762. public function form( $instance ) {
  763. $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
  764. $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
  765. ?>
  766. <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
  767. <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>
  768. <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of comments to show:' ); ?></label>
  769. <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>
  770. <?php
  771. }
  772. }
  773. /**
  774. * RSS widget class
  775. *
  776. * @since 2.8.0
  777. */
  778. class WP_Widget_RSS extends WP_Widget {
  779. public function __construct() {
  780. $widget_ops = array( 'description' => __('Entries from any RSS or Atom feed.') );
  781. $control_ops = array( 'width' => 400, 'height' => 200 );
  782. parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops );
  783. }
  784. public function widget($args, $instance) {
  785. if ( isset($instance['error']) && $instance['error'] )
  786. return;
  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 $args['before_widget'];
  816. if ( $title ) {
  817. echo $args['before_title'] . $title . $args['after_title'];
  818. }
  819. wp_widget_rss_output( $rss, $instance );
  820. echo $args['after_widget'];
  821. if ( ! is_wp_error($rss) )
  822. $rss->__destruct();
  823. unset($rss);
  824. }
  825. public function update($new_instance, $old_instance) {
  826. $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );
  827. return wp_widget_rss_process( $new_instance, $testurl );
  828. }
  829. public function form($instance) {
  830. if ( empty($instance) )
  831. $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
  832. $instance['number'] = $this->number;
  833. wp_widget_rss_form( $instance );
  834. }
  835. }
  836. /**
  837. * Display the RSS entries in a list.
  838. *
  839. * @since 2.5.0
  840. *
  841. * @param string|array|object $rss RSS url.
  842. * @param array $args Widget arguments.
  843. */
  844. function wp_widget_rss_output( $rss, $args = array() ) {
  845. if ( is_string( $rss ) ) {
  846. $rss = fetch_feed($rss);
  847. } elseif ( is_array($rss) && isset($rss['url']) ) {
  848. $args = $rss;
  849. $rss = fetch_feed($rss['url']);
  850. } elseif ( !is_object($rss) ) {
  851. return;
  852. }
  853. if ( is_wp_error($rss) ) {
  854. if ( is_admin() || current_user_can('manage_options') )
  855. echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';
  856. return;
  857. }
  858. $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0, 'items' => 0 );
  859. $args = wp_parse_args( $args, $default_args );
  860. $items = (int) $args['items'];
  861. if ( $items < 1 || 20 < $items )
  862. $items = 10;
  863. $show_summary = (int) $args['show_summary'];
  864. $show_author = (int) $args['show_author'];
  865. $show_date = (int) $args['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. }
  878. $link = esc_url( strip_tags( $link ) );
  879. $title = esc_html( trim( strip_tags( $item->get_title() ) ) );
  880. if ( empty( $title ) ) {
  881. $title = __( 'Untitled' );
  882. }
  883. $desc = @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) );
  884. $desc = esc_attr( wp_trim_words( $desc, 55, ' [&hellip;]' ) );
  885. $summary = '';
  886. if ( $show_summary ) {
  887. $summary = $desc;
  888. // Change existing [...] to [&hellip;].
  889. if ( '[...]' == substr( $summary, -5 ) ) {
  890. $summary = substr( $summary, 0, -5 ) . '[&hellip;]';
  891. }
  892. $summary = '<div class="rssSummary">' . esc_html( $summary ) . '</div>';
  893. }
  894. $date = '';
  895. if ( $show_date ) {
  896. $date = $item->get_date( 'U' );
  897. if ( $date ) {
  898. $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>';
  899. }
  900. }
  901. $author = '';
  902. if ( $show_author ) {
  903. $author = $item->get_author();
  904. if ( is_object($author) ) {
  905. $author = $author->get_name();
  906. $author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>';
  907. }
  908. }
  909. if ( $link == '' ) {
  910. echo "<li>$title{$date}{$summary}{$author}</li>";
  911. } elseif ( $show_summary ) {
  912. echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$summary}{$author}</li>";
  913. } else {
  914. echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$author}</li>";
  915. }
  916. }
  917. echo '</ul>';
  918. $rss->__destruct();
  919. unset($rss);
  920. }
  921. /**
  922. * Display RSS widget options form.
  923. *
  924. * The options for what fields are displayed for the RSS form are all booleans
  925. * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author',
  926. * 'show_date'.
  927. *
  928. * @since 2.5.0
  929. *
  930. * @param array|string $args Values for input fields.
  931. * @param array $inputs Override default display options.
  932. */
  933. function wp_widget_rss_form( $args, $inputs = null ) {
  934. $default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true );
  935. $inputs = wp_parse_args( $inputs, $default_inputs );
  936. $number = esc_attr( $args['number'] );
  937. $title = isset( $args['title'] ) ? esc_attr( $args['title'] ) : '';
  938. $url = isset( $args['url'] ) ? esc_url( $args['url'] ) : '';
  939. $items = isset( $args['items'] ) ? (int) $args['items'] : 0;
  940. if ( $items < 1 || 20 < $items ) {
  941. $items = 10;
  942. }
  943. $show_summary = isset( $args['show_summary'] ) ? (int) $args['show_summary'] : (int) $inputs['show_summary'];
  944. $show_author = isset( $args['show_author'] ) ? (int) $args['show_author'] : (int) $inputs['show_author'];
  945. $show_date = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date'];
  946. if ( ! empty( $args['error'] ) ) {
  947. echo '<p class="widget-error"><strong>' . sprintf( __( 'RSS Error: %s' ), $args['error'] ) . '</strong></p>';
  948. }
  949. if ( $inputs['url'] ) :
  950. ?>
  951. <p><label for="rss-url-<?php echo $number; ?>"><?php _e('Enter the RSS feed URL here:'); ?></label>
  952. <input class="widefat" id="rss-url-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][url]" type="text" value="<?php echo $url; ?>" /></p>
  953. <?php endif; if ( $inputs['title'] ) : ?>
  954. <p><label for="rss-title-<?php echo $number; ?>"><?php _e('Give the feed a title (optional):'); ?></label>
  955. <input class="widefat" id="rss-title-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][title]" type="text" value="<?php echo $title; ?>" /></p>
  956. <?php endif; if ( $inputs['items'] ) : ?>
  957. <p><label for="rss-items-<?php echo $number; ?>"><?php _e('How many items would you like to display?'); ?></label>
  958. <select id="rss-items-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][items]">
  959. <?php
  960. for ( $i = 1; $i <= 20; ++$i )
  961. echo "<option value='$i' " . selected( $items, $i, false ) . ">$i</option>";
  962. ?>
  963. </select></p>
  964. <?php endif; if ( $inputs['show_summary'] ) : ?>
  965. <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"'; ?>/>
  966. <label for="rss-show-summary-<?php echo $number; ?>"><?php _e('Display item content?'); ?></label></p>
  967. <?php endif; if ( $inputs['show_author'] ) : ?>
  968. <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"'; ?>/>
  969. <label for="rss-show-author-<?php echo $number; ?>"><?php _e('Display item author if available?'); ?></label></p>
  970. <?php endif; if ( $inputs['show_date'] ) : ?>
  971. <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"'; ?>/>
  972. <label for="rss-show-date-<?php echo $number; ?>"><?php _e('Display item date?'); ?></label></p>
  973. <?php
  974. endif;
  975. foreach ( array_keys($default_inputs) as $input ) :
  976. if ( 'hidden' === $inputs[$input] ) :
  977. $id = str_replace( '_', '-', $input );
  978. ?>
  979. <input type="hidden" id="rss-<?php echo $id; ?>-<?php echo $number; ?>" name="widget-rss[<?php echo $number; ?>][<?php echo $input; ?>]" value="<?php echo $$input; ?>" />
  980. <?php
  981. endif;
  982. endforeach;
  983. }
  984. /**
  985. * Process RSS feed widget data and optionally retrieve feed items.
  986. *
  987. * The feed widget can not have more than 20 items or it will reset back to the
  988. * default, which is 10.
  989. *
  990. * The resulting array has the feed title, feed url, feed link (from channel),
  991. * feed items, error (if any), and whether to show summary, author, and date.
  992. * All respectively in the order of the array elements.
  993. *
  994. * @since 2.5.0
  995. *
  996. * @param array $widget_rss RSS widget feed data. Expects unescaped data.
  997. * @param bool $check_feed Optional, default is true. Whether to check feed for errors.
  998. * @return array
  999. */
  1000. function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
  1001. $items = (int) $widget_rss['items'];
  1002. if ( $items < 1 || 20 < $items )
  1003. $items = 10;
  1004. $url = esc_url_raw( strip_tags( $widget_rss['url'] ) );
  1005. $title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : '';
  1006. $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0;
  1007. $show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] :0;
  1008. $show_date = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0;
  1009. if ( $check_feed ) {
  1010. $rss = fetch_feed($url);
  1011. $error = false;
  1012. $link = '';
  1013. if ( is_wp_error($rss) ) {
  1014. $error = $rss->get_error_message();
  1015. } else {
  1016. $link = esc_url(strip_tags($rss->get_permalink()));
  1017. while ( stristr($link, 'http') != $link )
  1018. $link = substr($link, 1);
  1019. $rss->__destruct();
  1020. unset($rss);
  1021. }
  1022. }
  1023. return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );
  1024. }
  1025. /**
  1026. * Tag cloud widget class
  1027. *
  1028. * @since 2.8.0
  1029. */
  1030. class WP_Widget_Tag_Cloud extends WP_Widget {
  1031. public function __construct() {
  1032. $widget_ops = array( 'description' => __( "A cloud of your most used tags.") );
  1033. parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops);
  1034. }
  1035. public function widget( $args, $instance ) {
  1036. $current_taxonomy = $this->_get_current_taxonomy($instance);
  1037. if ( !empty($instance['title']) ) {
  1038. $title = $instance['title'];
  1039. } else {
  1040. if ( 'post_tag' == $current_taxonomy ) {
  1041. $title = __('Tags');
  1042. } else {
  1043. $tax = get_taxonomy($current_taxonomy);
  1044. $title = $tax->labels->name;
  1045. }
  1046. }
  1047. /** This filter is documented in wp-includes/default-widgets.php */
  1048. $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
  1049. echo $args['before_widget'];
  1050. if ( $title ) {
  1051. echo $args['before_title'] . $title . $args['after_title'];
  1052. }
  1053. echo '<div class="tagcloud">';
  1054. /**
  1055. * Filter the taxonomy used in the Tag Cloud widget.
  1056. *
  1057. * @since 2.8.0
  1058. * @since 3.0.0 Added taxonomy drop-down.
  1059. *
  1060. * @see wp_tag_cloud()
  1061. *
  1062. * @param array $current_taxonomy The taxonomy to use in the tag cloud. Default 'tags'.
  1063. */
  1064. wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array(
  1065. 'taxonomy' => $current_taxonomy
  1066. ) ) );
  1067. echo "</div>\n";
  1068. echo $args['after_widget'];
  1069. }
  1070. public function update( $new_instance, $old_instance ) {
  1071. $instance['title'] = strip_tags(stripslashes($new_instance['title']));
  1072. $instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
  1073. return $instance;
  1074. }
  1075. public function form( $instance ) {
  1076. $current_taxonomy = $this->_get_current_taxonomy($instance);
  1077. ?>
  1078. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
  1079. <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>
  1080. <p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label>
  1081. <select class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>">
  1082. <?php foreach ( get_taxonomies() as $taxonomy ) :
  1083. $tax = get_taxonomy($taxonomy);
  1084. if ( !$tax->show_tagcloud || empty($tax->labels->name) )
  1085. continue;
  1086. ?>
  1087. <option value="<?php echo esc_attr($taxonomy) ?>" <?php selected($taxonomy, $current_taxonomy) ?>><?php echo $tax->labels->name; ?></option>
  1088. <?php endforeach; ?>
  1089. </select></p><?php
  1090. }
  1091. public function _get_current_taxonomy($instance) {
  1092. if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )
  1093. return $instance['taxonomy'];
  1094. return 'post_tag';
  1095. }
  1096. }
  1097. /**
  1098. * Navigation Menu widget class
  1099. *
  1100. * @since 3.0.0
  1101. */
  1102. class WP_Nav_Menu_Widget extends WP_Widget {
  1103. public function __construct() {
  1104. $widget_ops = array( 'description' => __('Add a custom menu to your sidebar.') );
  1105. parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops );
  1106. }
  1107. public function widget($args, $instance) {
  1108. // Get menu
  1109. $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;
  1110. if ( !$nav_menu )
  1111. return;
  1112. /** This filter is documented in wp-includes/default-widgets.php */
  1113. $instance['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
  1114. echo $args['before_widget'];
  1115. if ( !empty($instance['title']) )
  1116. echo $args['before_title'] . $instance['title'] . $args['after_title'];
  1117. wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu ) );
  1118. echo $args['after_widget'];
  1119. }
  1120. public function update( $new_instance, $old_instance ) {
  1121. $instance = array();
  1122. if ( ! empty( $new_instance['title'] ) ) {
  1123. $instance['title'] = strip_tags( stripslashes($new_instance['title']) );
  1124. }
  1125. if ( ! empty( $new_instance['nav_menu'] ) ) {
  1126. $instance['nav_menu'] = (int) $new_instance['nav_menu'];
  1127. }
  1128. return $instance;
  1129. }
  1130. public function form( $instance ) {
  1131. $title = isset( $instance['title'] ) ? $instance['title'] : '';
  1132. $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
  1133. // Get menus
  1134. $menus = wp_get_nav_menus( array( 'orderby' => 'name' ) );
  1135. // If no menus exists, direct the user to go and create some.
  1136. if ( !$menus ) {
  1137. echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>';
  1138. return;
  1139. }
  1140. ?>
  1141. <p>
  1142. <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
  1143. <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; ?>" />
  1144. </p>
  1145. <p>
  1146. <label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
  1147. <select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
  1148. <option value="0"><?php _e( '&mdash; Select &mdash;' ) ?></option>
  1149. <?php
  1150. foreach ( $menus as $menu ) {
  1151. echo '<option value="' . $menu->term_id . '"'
  1152. . selected( $nav_menu, $menu->term_id, false )
  1153. . '>'. esc_html( $menu->name ) . '</option>';
  1154. }
  1155. ?>
  1156. </select>
  1157. </p>
  1158. <?php
  1159. }
  1160. }
  1161. /**
  1162. * Register al…

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