PageRenderTime 58ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-includes/default-widgets.php

https://gitlab.com/geyson/geyson
PHP | 1650 lines | 984 code | 219 blank | 447 comment | 129 complexity | defd705b63adc03e33d3edb5fa1e3dc8 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0

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

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