PageRenderTime 56ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-includes/default-widgets.php

https://bitbucket.org/acipriani/madeinapulia.com
PHP | 1423 lines | 941 code | 223 blank | 259 comment | 123 complexity | 1fffbeb699ec5bd9d4a738f78cc2b4a1 MD5 | raw file
Possible License(s): GPL-3.0, MIT, BSD-3-Clause, LGPL-2.1, GPL-2.0, Apache-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. 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 esc_attr_e( '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'); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
  338. <li><a href="<?php bloginfo('comments_rss2_url'); ?>"><?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 WP_Comment_Query::query() for information on accepted arguments.
  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">';
  742. /* translators: comments widget: 1: comment author, 2: post link */
  743. $output .= sprintf( _x( '%1$s on %2$s', 'widgets' ),
  744. '<span class="comment-author-link">' . get_comment_author_link() . '</span>',
  745. '<a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">' . get_the_title( $comment->comment_post_ID ) . '</a>'
  746. );
  747. $output .= '</li>';
  748. }
  749. }
  750. $output .= '</ul>';
  751. $output .= $args['after_widget'];
  752. echo $output;
  753. if ( ! $this->is_preview() ) {
  754. $cache[ $args['widget_id'] ] = $output;
  755. wp_cache_set( 'widget_recent_comments', $cache, 'widget' );
  756. }
  757. }
  758. public function update( $new_instance, $old_instance ) {
  759. $instance = $old_instance;
  760. $instance['title'] = strip_tags($new_instance['title']);
  761. $instance['number'] = absint( $new_instance['number'] );
  762. $this->flush_widget_cache();
  763. $alloptions = wp_cache_get( 'alloptions', 'options' );
  764. if ( isset($alloptions['widget_recent_comments']) )
  765. delete_option('widget_recent_comments');
  766. return $instance;
  767. }
  768. public function form( $instance ) {
  769. $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
  770. $number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
  771. ?>
  772. <p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
  773. <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>
  774. <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of comments to show:' ); ?></label>
  775. <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>
  776. <?php
  777. }
  778. }
  779. /**
  780. * RSS widget class
  781. *
  782. * @since 2.8.0
  783. */
  784. class WP_Widget_RSS extends WP_Widget {
  785. public function __construct() {
  786. $widget_ops = array( 'description' => __('Entries from any RSS or Atom feed.') );
  787. $control_ops = array( 'width' => 400, 'height' => 200 );
  788. parent::__construct( 'rss', __('RSS'), $widget_ops, $control_ops );
  789. }
  790. public function widget($args, $instance) {
  791. if ( isset($instance['error']) && $instance['error'] )
  792. return;
  793. $url = ! empty( $instance['url'] ) ? $instance['url'] : '';
  794. while ( stristr($url, 'http') != $url )
  795. $url = substr($url, 1);
  796. if ( empty($url) )
  797. return;
  798. // self-url destruction sequence
  799. if ( in_array( untrailingslashit( $url ), array( site_url(), home_url() ) ) )
  800. return;
  801. $rss = fetch_feed($url);
  802. $title = $instance['title'];
  803. $desc = '';
  804. $link = '';
  805. if ( ! is_wp_error($rss) ) {
  806. $desc = esc_attr(strip_tags(@html_entity_decode($rss->get_description(), ENT_QUOTES, get_option('blog_charset'))));
  807. if ( empty($title) )
  808. $title = esc_html(strip_tags($rss->get_title()));
  809. $link = esc_url(strip_tags($rss->get_permalink()));
  810. while ( stristr($link, 'http') != $link )
  811. $link = substr($link, 1);
  812. }
  813. if ( empty($title) )
  814. $title = empty($desc) ? __('Unknown Feed') : $desc;
  815. /** This filter is documented in wp-includes/default-widgets.php */
  816. $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
  817. $url = esc_url(strip_tags($url));
  818. $icon = includes_url('images/rss.png');
  819. if ( $title )
  820. $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>";
  821. echo $args['before_widget'];
  822. if ( $title ) {
  823. echo $args['before_title'] . $title . $args['after_title'];
  824. }
  825. wp_widget_rss_output( $rss, $instance );
  826. echo $args['after_widget'];
  827. if ( ! is_wp_error($rss) )
  828. $rss->__destruct();
  829. unset($rss);
  830. }
  831. public function update($new_instance, $old_instance) {
  832. $testurl = ( isset( $new_instance['url'] ) && ( !isset( $old_instance['url'] ) || ( $new_instance['url'] != $old_instance['url'] ) ) );
  833. return wp_widget_rss_process( $new_instance, $testurl );
  834. }
  835. public function form($instance) {
  836. if ( empty($instance) )
  837. $instance = array( 'title' => '', 'url' => '', 'items' => 10, 'error' => false, 'show_summary' => 0, 'show_author' => 0, 'show_date' => 0 );
  838. $instance['number'] = $this->number;
  839. wp_widget_rss_form( $instance );
  840. }
  841. }
  842. /**
  843. * Display the RSS entries in a list.
  844. *
  845. * @since 2.5.0
  846. *
  847. * @param string|array|object $rss RSS url.
  848. * @param array $args Widget arguments.
  849. */
  850. function wp_widget_rss_output( $rss, $args = array() ) {
  851. if ( is_string( $rss ) ) {
  852. $rss = fetch_feed($rss);
  853. } elseif ( is_array($rss) && isset($rss['url']) ) {
  854. $args = $rss;
  855. $rss = fetch_feed($rss['url']);
  856. } elseif ( !is_object($rss) ) {
  857. return;
  858. }
  859. if ( is_wp_error($rss) ) {
  860. if ( is_admin() || current_user_can('manage_options') )
  861. echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';
  862. return;
  863. }
  864. $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0, 'items' => 0 );
  865. $args = wp_parse_args( $args, $default_args );
  866. $items = (int) $args['items'];
  867. if ( $items < 1 || 20 < $items )
  868. $items = 10;
  869. $show_summary = (int) $args['show_summary'];
  870. $show_author = (int) $args['show_author'];
  871. $show_date = (int) $args['show_date'];
  872. if ( !$rss->get_item_quantity() ) {
  873. echo '<ul><li>' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</li></ul>';
  874. $rss->__destruct();
  875. unset($rss);
  876. return;
  877. }
  878. echo '<ul>';
  879. foreach ( $rss->get_items( 0, $items ) as $item ) {
  880. $link = $item->get_link();
  881. while ( stristr( $link, 'http' ) != $link ) {
  882. $link = substr( $link, 1 );
  883. }
  884. $link = esc_url( strip_tags( $link ) );
  885. $title = esc_html( trim( strip_tags( $item->get_title() ) ) );
  886. if ( empty( $title ) ) {
  887. $title = __( 'Untitled' );
  888. }
  889. $desc = @html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) );
  890. $desc = esc_attr( wp_trim_words( $desc, 55, ' [&hellip;]' ) );
  891. $summary = '';
  892. if ( $show_summary ) {
  893. $summary = $desc;
  894. // Change existing [...] to [&hellip;].
  895. if ( '[...]' == substr( $summary, -5 ) ) {
  896. $summary = substr( $summary, 0, -5 ) . '[&hellip;]';
  897. }
  898. $summary = '<div class="rssSummary">' . esc_html( $summary ) . '</div>';
  899. }
  900. $date = '';
  901. if ( $show_date ) {
  902. $date = $item->get_date( 'U' );
  903. if ( $date ) {
  904. $date = ' <span class="rss-date">' . date_i18n( get_option( 'date_format' ), $date ) . '</span>';
  905. }
  906. }
  907. $author = '';
  908. if ( $show_author ) {
  909. $author = $item->get_author();
  910. if ( is_object($author) ) {
  911. $author = $author->get_name();
  912. $author = ' <cite>' . esc_html( strip_tags( $author ) ) . '</cite>';
  913. }
  914. }
  915. if ( $link == '' ) {
  916. echo "<li>$title{$date}{$summary}{$author}</li>";
  917. } elseif ( $show_summary ) {
  918. echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$summary}{$author}</li>";
  919. } else {
  920. echo "<li><a class='rsswidget' href='$link'>$title</a>{$date}{$author}</li>";
  921. }
  922. }
  923. echo '</ul>';
  924. $rss->__destruct();
  925. unset($rss);
  926. }
  927. /**
  928. * Display RSS widget options form.
  929. *
  930. * The options for what fields are displayed for the RSS form are all booleans
  931. * and are as follows: 'url', 'title', 'items', 'show_summary', 'show_author',
  932. * 'show_date'.
  933. *
  934. * @since 2.5.0
  935. *
  936. * @param array|string $args Values for input fields.
  937. * @param array $inputs Override default display options.
  938. */
  939. function wp_widget_rss_form( $args, $inputs = null ) {
  940. $default_inputs = array( 'url' => true, 'title' => true, 'items' => true, 'show_summary' => true, 'show_author' => true, 'show_date' => true );
  941. $inputs = wp_parse_args( $inputs, $default_inputs );
  942. $args['number'] = esc_attr( $args['number'] );
  943. $args['title'] = isset( $args['title'] ) ? esc_attr( $args['title'] ) : '';
  944. $args['url'] = isset( $args['url'] ) ? esc_url( $args['url'] ) : '';
  945. $args['items'] = isset( $args['items'] ) ? (int) $args['items'] : 0;
  946. if ( $args['items'] < 1 || 20 < $args['items'] ) {
  947. $args['items'] = 10;
  948. }
  949. $args['show_summary'] = isset( $args['show_summary'] ) ? (int) $args['show_summary'] : (int) $inputs['show_summary'];
  950. $args['show_author'] = isset( $args['show_author'] ) ? (int) $args['show_author'] : (int) $inputs['show_author'];
  951. $args['show_date'] = isset( $args['show_date'] ) ? (int) $args['show_date'] : (int) $inputs['show_date'];
  952. if ( ! empty( $args['error'] ) ) {
  953. echo '<p class="widget-error"><strong>' . sprintf( __( 'RSS Error: %s' ), $args['error'] ) . '</strong></p>';
  954. }
  955. if ( $inputs['url'] ) :
  956. ?>
  957. <p><label for="rss-url-<?php echo $args['number']; ?>"><?php _e( 'Enter the RSS feed URL here:' ); ?></label>
  958. <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>
  959. <?php endif; if ( $inputs['title'] ) : ?>
  960. <p><label for="rss-title-<?php echo $args['number']; ?>"><?php _e( 'Give the feed a title (optional):' ); ?></label>
  961. <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>
  962. <?php endif; if ( $inputs['items'] ) : ?>
  963. <p><label for="rss-items-<?php echo $args['number']; ?>"><?php _e( 'How many items would you like to display?' ); ?></label>
  964. <select id="rss-items-<?php echo $args['number']; ?>" name="widget-rss[<?php echo $args['number']; ?>][items]">
  965. <?php
  966. for ( $i = 1; $i <= 20; ++$i ) {
  967. echo "<option value='$i' " . selected( $args['items'], $i, false ) . ">$i</option>";
  968. }
  969. ?>
  970. </select></p>
  971. <?php endif; if ( $inputs['show_summary'] ) : ?>
  972. <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'] ); ?> />
  973. <label for="rss-show-summary-<?php echo $args['number']; ?>"><?php _e( 'Display item content?' ); ?></label></p>
  974. <?php endif; if ( $inputs['show_author'] ) : ?>
  975. <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'] ); ?> />
  976. <label for="rss-show-author-<?php echo $args['number']; ?>"><?php _e( 'Display item author if available?' ); ?></label></p>
  977. <?php endif; if ( $inputs['show_date'] ) : ?>
  978. <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'] ); ?>/>
  979. <label for="rss-show-date-<?php echo $args['number']; ?>"><?php _e( 'Display item date?' ); ?></label></p>
  980. <?php
  981. endif;
  982. foreach ( array_keys($default_inputs) as $input ) :
  983. if ( 'hidden' === $inputs[$input] ) :
  984. $id = str_replace( '_', '-', $input );
  985. ?>
  986. <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 ]; ?>" />
  987. <?php
  988. endif;
  989. endforeach;
  990. }
  991. /**
  992. * Process RSS feed widget data and optionally retrieve feed items.
  993. *
  994. * The feed widget can not have more than 20 items or it will reset back to the
  995. * default, which is 10.
  996. *
  997. * The resulting array has the feed title, feed url, feed link (from channel),
  998. * feed items, error (if any), and whether to show summary, author, and date.
  999. * All respectively in the order of the array elements.
  1000. *
  1001. * @since 2.5.0
  1002. *
  1003. * @param array $widget_rss RSS widget feed data. Expects unescaped data.
  1004. * @param bool $check_feed Optional, default is true. Whether to check feed for errors.
  1005. * @return array
  1006. */
  1007. function wp_widget_rss_process( $widget_rss, $check_feed = true ) {
  1008. $items = (int) $widget_rss['items'];
  1009. if ( $items < 1 || 20 < $items )
  1010. $items = 10;
  1011. $url = esc_url_raw( strip_tags( $widget_rss['url'] ) );
  1012. $title = isset( $widget_rss['title'] ) ? trim( strip_tags( $widget_rss['title'] ) ) : '';
  1013. $show_summary = isset( $widget_rss['show_summary'] ) ? (int) $widget_rss['show_summary'] : 0;
  1014. $show_author = isset( $widget_rss['show_author'] ) ? (int) $widget_rss['show_author'] :0;
  1015. $show_date = isset( $widget_rss['show_date'] ) ? (int) $widget_rss['show_date'] : 0;
  1016. if ( $check_feed ) {
  1017. $rss = fetch_feed($url);
  1018. $error = false;
  1019. $link = '';
  1020. if ( is_wp_error($rss) ) {
  1021. $error = $rss->get_error_message();
  1022. } else {
  1023. $link = esc_url(strip_tags($rss->get_permalink()));
  1024. while ( stristr($link, 'http') != $link )
  1025. $link = substr($link, 1);
  1026. $rss->__destruct();
  1027. unset($rss);
  1028. }
  1029. }
  1030. return compact( 'title', 'url', 'link', 'items', 'error', 'show_summary', 'show_author', 'show_date' );
  1031. }
  1032. /**
  1033. * Tag cloud widget class
  1034. *
  1035. * @since 2.8.0
  1036. */
  1037. class WP_Widget_Tag_Cloud extends WP_Widget {
  1038. public function __construct() {
  1039. $widget_ops = array( 'description' => __( "A cloud of your most used tags.") );
  1040. parent::__construct('tag_cloud', __('Tag Cloud'), $widget_ops);
  1041. }
  1042. public function widget( $args, $instance ) {
  1043. $current_taxonomy = $this->_get_current_taxonomy($instance);
  1044. if ( !empty($instance['title']) ) {
  1045. $title = $instance['title'];
  1046. } else {
  1047. if ( 'post_tag' == $current_taxonomy ) {
  1048. $title = __('Tags');
  1049. } else {
  1050. $tax = get_taxonomy($current_taxonomy);
  1051. $title = $tax->labels->name;
  1052. }
  1053. }
  1054. /** This filter is documented in wp-includes/default-widgets.php */
  1055. $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
  1056. echo $args['before_widget'];
  1057. if ( $title ) {
  1058. echo $args['before_title'] . $title . $args['after_title'];
  1059. }
  1060. echo '<div class="tagcloud">';
  1061. /**
  1062. * Filter the taxonomy used in the Tag Cloud widget.
  1063. *
  1064. * @since 2.8.0
  1065. * @since 3.0.0 Added taxonomy drop-down.
  1066. *
  1067. * @see wp_tag_cloud()
  1068. *
  1069. * @param array $current_taxonomy The taxonomy to use in the tag cloud. Default 'tags'.
  1070. */
  1071. wp_tag_cloud( apply_filters( 'widget_tag_cloud_args', array(
  1072. 'taxonomy' => $current_taxonomy
  1073. ) ) );
  1074. echo "</div>\n";
  1075. echo $args['after_widget'];
  1076. }
  1077. public function update( $new_instance, $old_instance ) {
  1078. $instance['title'] = strip_tags(stripslashes($new_instance['title']));
  1079. $instance['taxonomy'] = stripslashes($new_instance['taxonomy']);
  1080. return $instance;
  1081. }
  1082. public function form( $instance ) {
  1083. $current_taxonomy = $this->_get_current_taxonomy($instance);
  1084. ?>
  1085. <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
  1086. <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>
  1087. <p><label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:') ?></label>
  1088. <select class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>" name="<?php echo $this->get_field_name('taxonomy'); ?>">
  1089. <?php foreach ( get_taxonomies() as $taxonomy ) :
  1090. $tax = get_taxonomy($taxonomy);
  1091. if ( !$tax->show_tagcloud || empty($tax->labels->name) )
  1092. continue;
  1093. ?>
  1094. <option value="<?php echo esc_attr($taxonomy) ?>" <?php selected($taxonomy, $current_taxonomy) ?>><?php echo $tax->labels->name; ?></option>
  1095. <?php endforeach; ?>
  1096. </select></p><?php
  1097. }
  1098. public function _get_current_taxonomy($instance) {
  1099. if ( !empty($instance['taxonomy']) && taxonomy_exists($instance['taxonomy']) )
  1100. return $instance['taxonomy'];
  1101. return 'post_tag';
  1102. }
  1103. }
  1104. /**
  1105. * Navigation Menu widget class
  1106. *
  1107. * @since 3.0.0
  1108. */
  1109. class WP_Nav_Menu_Widget extends WP_Widget {
  1110. public function __construct() {
  1111. $widget_ops = array( 'description' => __('Add a custom menu to your sidebar.') );
  1112. parent::__construct( 'nav_menu', __('Custom Menu'), $widget_ops );
  1113. }
  1114. public function widget($args, $instance) {
  1115. // Get menu
  1116. $nav_menu = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;
  1117. if ( !$nav_menu )
  1118. return;
  1119. /** This filter is documented in wp-includes/default-widgets.php */
  1120. $instance['title'] = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
  1121. echo $args['before_widget'];
  1122. if ( !empty($instance['title']) )
  1123. echo $args['before_title'] . $instance['title'] . $args['after_title'];
  1124. wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu ) );
  1125. echo $args['after_widget'];
  1126. }
  1127. public function update( $new_instance, $old_instance ) {
  1128. $instance = array();
  1129. if ( ! empty( $new_instance['title'] ) ) {
  1130. $instance['title'] = strip_tags( stripslashes($new_instance['title']) );
  1131. }
  1132. if ( ! empty( $new_instance['nav_menu'] ) ) {
  1133. $instance['nav_menu'] = (int) $new_instance['nav_menu'];
  1134. }
  1135. return $instance;
  1136. }
  1137. public function form( $instance ) {
  1138. $title = isset( $instance['title'] ) ? $instance['title'] : '';
  1139. $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
  1140. // Get menus
  1141. $menus = wp_get_nav_menus();
  1142. // If no menus exists, direct the user to go and create some.
  1143. if ( !$menus ) {
  1144. echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Create some</a>.'), admin_url('nav-menus.php') ) .'</p>';
  1145. return;
  1146. }
  1147. ?>
  1148. <p>
  1149. <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
  1150. <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; ?>" />
  1151. </p>
  1152. <p>
  1153. <label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
  1154. <select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
  1155. <option value="0"><?php _e( '&mdash; Select &mdash;' ) ?></option>
  1156. <?php
  1157. foreach ( $menus as $menu ) {
  1158. echo '<option value="' . $menu->term_id . '"'
  1159. . selected( $nav_menu, $menu->

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