PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/news/library/classes/widget-bookmarks.php

https://bitbucket.org/lgorence/quickpress
PHP | 326 lines | 239 code | 35 blank | 52 comment | 12 complexity | 14034e84cf72ec7bc7b2f5854e41d232 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /**
  3. * The Bookmarks widget replaces the default WordPress Links widget. This version gives total
  4. * control over the output to the user by allowing the input of all the arguments typically seen
  5. * in the wp_list_bookmarks() function.
  6. *
  7. * @package Hybrid
  8. * @subpackage Classes
  9. * @author Justin Tadlock <justin@justintadlock.com>
  10. * @copyright Copyright (c) 2008 - 2012, Justin Tadlock
  11. * @link http://themehybrid.com/hybrid-core
  12. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  13. */
  14. /**
  15. * Bookmarks Widget Class
  16. *
  17. * @since 0.6.0
  18. */
  19. class Hybrid_Widget_Bookmarks extends WP_Widget {
  20. /**
  21. * Set up the widget's unique name, ID, class, description, and other options.
  22. *
  23. * @since 1.2.0
  24. */
  25. function __construct() {
  26. /* Set up the widget options. */
  27. $widget_options = array(
  28. 'classname' => 'bookmarks',
  29. 'description' => esc_html__( 'An advanced widget that gives you total control over the output of your bookmarks (links).', 'hybrid-core' )
  30. );
  31. /* Set up the widget control options. */
  32. $control_options = array(
  33. 'width' => 800,
  34. 'height' => 350
  35. );
  36. /* Create the widget. */
  37. $this->WP_Widget(
  38. 'hybrid-bookmarks', // $this->id_base
  39. __( 'Bookmarks', 'hybrid-core' ), // $this->name
  40. $widget_options, // $this->widget_options
  41. $control_options // $this->control_options
  42. );
  43. }
  44. /**
  45. * Outputs the widget based on the arguments input through the widget controls.
  46. *
  47. * @since 0.6.0
  48. */
  49. function widget( $sidebar, $instance ) {
  50. extract( $sidebar );
  51. /* Set up the $before_widget ID for multiple widgets created by the bookmarks widget. */
  52. if ( !empty( $instance['categorize'] ) )
  53. $before_widget = preg_replace( '/id="[^"]*"/','id="%id"', $before_widget );
  54. /* Add a class to $before_widget if one is set. */
  55. if ( !empty( $instance['class'] ) )
  56. $before_widget = str_replace( 'class="', 'class="' . esc_attr( $instance['class'] ) . ' ', $before_widget );
  57. /* Set the $args for wp_list_bookmarks() to the $instance array. */
  58. $args = $instance;
  59. /* wp_list_bookmarks() hasn't been updated in WP to use wp_parse_id_list(), so we have to pass strings for includes/excludes. */
  60. if ( !empty( $args['category'] ) && is_array( $args['category'] ) )
  61. $args['category'] = join( ', ', $args['category'] );
  62. if ( !empty( $args['exclude_category'] ) && is_array( $args['exclude_category'] ) )
  63. $args['exclude_category'] = join( ', ', $args['exclude_category'] );
  64. if ( !empty( $args['include'] ) && is_array( $args['include'] ) )
  65. $args['include'] = join( ',', $args['include'] );
  66. if ( !empty( $args['exclude'] ) && is_array( $args['exclude'] ) )
  67. $args['exclude'] = join( ',', $args['exclude'] );
  68. /* If no limit is given, set it to -1. */
  69. $args['limit'] = empty( $args['limit'] ) ? -1 : $args['limit'];
  70. /* Some arguments must be set to the sidebar arguments to be output correctly. */
  71. $args['title_li'] = apply_filters( 'widget_title', ( empty( $args['title_li'] ) ? __( 'Bookmarks', 'hybrid-core' ) : $args['title_li'] ), $instance, $this->id_base );
  72. $args['title_before'] = $before_title;
  73. $args['title_after'] = $after_title;
  74. $args['category_before'] = $before_widget;
  75. $args['category_after'] = $after_widget;
  76. $args['category_name'] = '';
  77. $args['echo'] = false;
  78. /* Output the bookmarks widget. */
  79. $bookmarks = str_replace( array( "\r", "\n", "\t" ), '', wp_list_bookmarks( $args ) );
  80. /* If no title is given and the bookmarks aren't categorized, add a wrapper <ul>. */
  81. if ( empty( $args['title_li'] ) && false === $args['categorize'] )
  82. $bookmarks = '<ul class="xoxo bookmarks">' . $bookmarks . '</ul>';
  83. /* Output the bookmarks. */
  84. echo $bookmarks;
  85. }
  86. /**
  87. * Updates the widget control options for the particular instance of the widget.
  88. *
  89. * @since 0.6.0
  90. */
  91. function update( $new_instance, $old_instance ) {
  92. $instance = $old_instance;
  93. /* Set the instance to the new instance. */
  94. $instance = $new_instance;
  95. $instance['title_li'] = strip_tags( $new_instance['title_li'] );
  96. $instance['limit'] = strip_tags( $new_instance['limit'] );
  97. $instance['class'] = strip_tags( $new_instance['class'] );
  98. $instance['search'] = strip_tags( $new_instance['search'] );
  99. $instance['category_order'] = $new_instance['category_order'];
  100. $instance['category_orderby'] = $new_instance['category_orderby'];
  101. $instance['orderby'] = $new_instance['orderby'];
  102. $instance['order'] = $new_instance['order'];
  103. $instance['between'] = $new_instance['between'];
  104. $instance['link_before'] = $new_instance['link_before'];
  105. $instance['link_after'] = $new_instance['link_after'];
  106. $instance['categorize'] = ( isset( $new_instance['categorize'] ) ? 1 : 0 );
  107. $instance['hide_invisible'] = ( isset( $new_instance['hide_invisible'] ) ? 1 : 0 );
  108. $instance['show_private'] = ( isset( $new_instance['show_private'] ) ? 1 : 0 );
  109. $instance['show_rating'] = ( isset( $new_instance['show_rating'] ) ? 1 : 0 );
  110. $instance['show_updated'] = ( isset( $new_instance['show_updated'] ) ? 1 : 0 );
  111. $instance['show_images'] = ( isset( $new_instance['show_images'] ) ? 1 : 0 );
  112. $instance['show_name'] = ( isset( $new_instance['show_name'] ) ? 1 : 0 );
  113. $instance['show_description'] = ( isset( $new_instance['show_description'] ) ? 1 : 0 );
  114. return $instance;
  115. }
  116. /**
  117. * Displays the widget control options in the Widgets admin screen.
  118. *
  119. * @since 0.6.0
  120. */
  121. function form( $instance ) {
  122. /* Set up the default form values. */
  123. $defaults = array(
  124. 'title_li' => esc_attr__( 'Bookmarks', 'hybrid-core' ),
  125. 'categorize' => true,
  126. 'category_order' => 'ASC',
  127. 'category_orderby' => 'name',
  128. 'category' => array(),
  129. 'exclude_category' => array(),
  130. 'limit' => -1,
  131. 'order' => 'ASC',
  132. 'orderby' => 'name',
  133. 'include' => array(),
  134. 'exclude' => array(),
  135. 'search' => '',
  136. 'hide_invisible' => true,
  137. 'show_description' => false,
  138. 'show_images' => false,
  139. 'show_rating' => false,
  140. 'show_updated' => false,
  141. 'show_private' => false,
  142. 'show_name' => false,
  143. 'class' => 'linkcat',
  144. 'link_before' => '<span>',
  145. 'link_after' => '</span>',
  146. 'between' => '<br />',
  147. );
  148. /* Merge the user-selected arguments with the defaults. */
  149. $instance = wp_parse_args( (array) $instance, $defaults );
  150. $terms = get_terms( 'link_category' );
  151. $bookmarks = get_bookmarks( array( 'hide_invisible' => false ) );
  152. $category_order = array( 'ASC' => esc_attr__( 'Ascending', 'hybrid-core' ), 'DESC' => esc_attr__( 'Descending', 'hybrid-core' ) );
  153. $category_orderby = array( 'count' => esc_attr__( 'Count', 'hybrid-core' ), 'ID' => esc_attr__( 'ID', 'hybrid-core' ), 'name' => esc_attr__( 'Name', 'hybrid-core' ), 'slug' => esc_attr__( 'Slug', 'hybrid-core' ) );
  154. $order = array( 'ASC' => esc_attr__( 'Ascending', 'hybrid-core' ), 'DESC' => esc_attr__( 'Descending', 'hybrid-core' ) );
  155. $orderby = array( 'id' => esc_attr__( 'ID', 'hybrid-core' ), 'description' => esc_attr__( 'Description', 'hybrid-core' ), 'length' => esc_attr__( 'Length', 'hybrid-core' ), 'name' => esc_attr__( 'Name', 'hybrid-core' ), 'notes' => esc_attr__( 'Notes', 'hybrid-core' ), 'owner' => esc_attr__( 'Owner', 'hybrid-core' ), 'rand' => esc_attr__( 'Random', 'hybrid-core' ), 'rating' => esc_attr__( 'Rating', 'hybrid-core' ), 'rel' => esc_attr__( 'Rel', 'hybrid-core' ), 'rss' => esc_attr__( 'RSS', 'hybrid-core' ), 'target' => esc_attr__( 'Target', 'hybrid-core' ), 'updated' => esc_attr__( 'Updated', 'hybrid-core' ), 'url' => esc_attr__( 'URL', 'hybrid-core' ) );
  156. ?>
  157. <div class="hybrid-widget-controls columns-3">
  158. <p>
  159. <label for="<?php echo $this->get_field_id( 'title_li' ); ?>"><?php _e( 'Title:', 'hybrid-core' ); ?></label>
  160. <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title_li' ); ?>" name="<?php echo $this->get_field_name( 'title_li' ); ?>" value="<?php echo esc_attr( $instance['title_li'] ); ?>" />
  161. </p>
  162. <p>
  163. <label for="<?php echo $this->get_field_id( 'category_order' ); ?>"><code>category_order</code></label>
  164. <select class="widefat" id="<?php echo $this->get_field_id( 'category_order' ); ?>" name="<?php echo $this->get_field_name( 'category_order' ); ?>">
  165. <?php foreach ( $category_order as $option_value => $option_label ) { ?>
  166. <option value="<?php echo esc_attr( $option_value ); ?>" <?php selected( $instance['category_order'], $option_value ); ?>><?php echo esc_html( $option_label ); ?></option>
  167. <?php } ?>
  168. </select>
  169. </p>
  170. <p>
  171. <label for="<?php echo $this->get_field_id( 'category_orderby' ); ?>"><code>category_orderby</code></label>
  172. <select class="widefat" id="<?php echo $this->get_field_id( 'category_orderby' ); ?>" name="<?php echo $this->get_field_name( 'category_orderby' ); ?>">
  173. <?php foreach ( $category_orderby as $option_value => $option_label ) { ?>
  174. <option value="<?php echo esc_attr( $option_value ); ?>" <?php selected( $instance['category_orderby'], $option_value ); ?>><?php echo esc_html( $option_label ); ?></option>
  175. <?php } ?>
  176. </select>
  177. </p>
  178. <p>
  179. <label for="<?php echo $this->get_field_id( 'category' ); ?>"><code>category</code></label>
  180. <select class="widefat" id="<?php echo $this->get_field_id( 'category' ); ?>" name="<?php echo $this->get_field_name( 'category' ); ?>[]" size="4" multiple="multiple">
  181. <?php foreach ( $terms as $term ) { ?>
  182. <option value="<?php echo esc_attr( $term->term_id ); ?>" <?php echo ( in_array( $term->term_id, (array) $instance['category'] ) ? 'selected="selected"' : '' ); ?>><?php echo esc_html( $term->name ); ?></option>
  183. <?php } ?>
  184. </select>
  185. </p>
  186. <p>
  187. <label for="<?php echo $this->get_field_id( 'exclude_category' ); ?>"><code>exclude_category</code></label>
  188. <select class="widefat" id="<?php echo $this->get_field_id( 'exclude_category' ); ?>" name="<?php echo $this->get_field_name( 'exclude_category' ); ?>[]" size="4" multiple="multiple">
  189. <?php foreach ( $terms as $term ) { ?>
  190. <option value="<?php echo esc_attr( $term->term_id ); ?>" <?php echo ( in_array( $term->term_id, (array) $instance['exclude_category'] ) ? 'selected="selected"' : '' ); ?>><?php echo esc_html( $term->name ); ?></option>
  191. <?php } ?>
  192. </select>
  193. </p>
  194. <p>
  195. <label for="<?php echo $this->get_field_id( 'class' ); ?>"><code>class</code></label>
  196. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'class' ); ?>" name="<?php echo $this->get_field_name( 'class' ); ?>" value="<?php echo esc_attr( $instance['class'] ); ?>" />
  197. </p>
  198. </div>
  199. <div class="hybrid-widget-controls columns-3">
  200. <p>
  201. <label for="<?php echo $this->get_field_id( 'limit' ); ?>"><code>limit</code></label>
  202. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'limit' ); ?>" name="<?php echo $this->get_field_name( 'limit' ); ?>" value="<?php echo esc_attr( $instance['limit'] ); ?>" />
  203. </p>
  204. <p>
  205. <label for="<?php echo $this->get_field_id( 'order' ); ?>"><code>order</code></label>
  206. <select class="widefat" id="<?php echo $this->get_field_id( 'order' ); ?>" name="<?php echo $this->get_field_name( 'order' ); ?>">
  207. <?php foreach ( $order as $option_value => $option_label ) { ?>
  208. <option value="<?php echo esc_attr( $option_value ); ?>" <?php selected( $instance['order'], $option_value ); ?>><?php echo esc_html( $option_label ); ?></option>
  209. <?php } ?>
  210. </select>
  211. </p>
  212. <p>
  213. <label for="<?php echo $this->get_field_id( 'orderby' ); ?>"><code>orderby</code></label>
  214. <select class="widefat" id="<?php echo $this->get_field_id( 'orderby' ); ?>" name="<?php echo $this->get_field_name( 'orderby' ); ?>">
  215. <?php foreach ( $orderby as $option_value => $option_label ) { ?>
  216. <option value="<?php echo esc_attr( $option_value ); ?>" <?php selected( $instance['orderby'], $option_value ); ?>><?php echo esc_html( $option_label ); ?></option>
  217. <?php } ?>
  218. </select>
  219. </p>
  220. <p>
  221. <label for="<?php echo $this->get_field_id( 'include' ); ?>"><code>include</code></label>
  222. <select class="widefat" id="<?php echo $this->get_field_id( 'include' ); ?>" name="<?php echo $this->get_field_name( 'include' ); ?>[]" size="4" multiple="multiple">
  223. <?php foreach ( $bookmarks as $bookmark ) { ?>
  224. <option value="<?php echo esc_attr( $bookmark->link_id ); ?>" <?php echo ( in_array( $bookmark->link_id, (array) $instance['include'] ) ? 'selected="selected"' : '' ); ?>><?php echo esc_html( $bookmark->link_name ); ?></option>
  225. <?php } ?>
  226. </select>
  227. </p>
  228. <p>
  229. <label for="<?php echo $this->get_field_id( 'exclude' ); ?>"><code>exclude</code></label>
  230. <select class="widefat" id="<?php echo $this->get_field_id( 'exclude' ); ?>" name="<?php echo $this->get_field_name( 'exclude' ); ?>[]" size="4" multiple="multiple">
  231. <?php foreach ( $bookmarks as $bookmark ) { ?>
  232. <option value="<?php echo esc_attr( $bookmark->link_id ); ?>" <?php echo ( in_array( $bookmark->link_id, (array) $instance['exclude'] ) ? 'selected="selected"' : '' ); ?>><?php echo esc_html( $bookmark->link_name ); ?></option>
  233. <?php } ?>
  234. </select>
  235. </p>
  236. <p>
  237. <label for="<?php echo $this->get_field_id( 'search' ); ?>"><code>search</code></label>
  238. <input type="text" class="widefat code" id="<?php echo $this->get_field_id( 'search' ); ?>" name="<?php echo $this->get_field_name( 'search' ); ?>" value="<?php echo esc_attr( $instance['search'] ); ?>" />
  239. </p>
  240. </div>
  241. <div class="hybrid-widget-controls columns-3 column-last">
  242. <p>
  243. <label for="<?php echo $this->get_field_id( 'between' ); ?>"><code>between</code></label>
  244. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'between' ); ?>" name="<?php echo $this->get_field_name( 'between' ); ?>" value="<?php echo esc_attr( $instance['between'] ); ?>" />
  245. </p>
  246. <p>
  247. <label for="<?php echo $this->get_field_id( 'link_before' ); ?>"><code>link_before</code></label>
  248. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'link_before' ); ?>" name="<?php echo $this->get_field_name( 'link_before' ); ?>" value="<?php echo esc_attr( $instance['link_before'] ); ?>" />
  249. </p>
  250. <p>
  251. <label for="<?php echo $this->get_field_id( 'link_after' ); ?>"><code>link_after</code></label>
  252. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'link_after' ); ?>" name="<?php echo $this->get_field_name( 'link_after' ); ?>" value="<?php echo esc_attr( $instance['link_after'] ); ?>" />
  253. </p>
  254. <p>
  255. <label for="<?php echo $this->get_field_id( 'categorize' ); ?>">
  256. <input class="checkbox" type="checkbox" <?php checked( $instance['categorize'], true ); ?> id="<?php echo $this->get_field_id( 'categorize' ); ?>" name="<?php echo $this->get_field_name( 'categorize' ); ?>" /> <?php _e( 'Categorize?', 'hybrid-core' ); ?> <code>categorize</code></label>
  257. </p>
  258. <p>
  259. <label for="<?php echo $this->get_field_id( 'show_description' ); ?>">
  260. <input class="checkbox" type="checkbox" <?php checked( $instance['show_description'], true ); ?> id="<?php echo $this->get_field_id( 'show_description' ); ?>" name="<?php echo $this->get_field_name( 'show_description' ); ?>" /> <?php _e( 'Show description?', 'hybrid-core' ); ?> <code>show_description</code></label>
  261. </p>
  262. <p>
  263. <label for="<?php echo $this->get_field_id( 'hide_invisible' ); ?>">
  264. <input class="checkbox" type="checkbox" <?php checked( $instance['hide_invisible'], true ); ?> id="<?php echo $this->get_field_id( 'hide_invisible' ); ?>" name="<?php echo $this->get_field_name( 'hide_invisible' ); ?>" /> <?php _e( 'Hide invisible?', 'hybrid-core' ); ?> <code>hide_invisible</code></label>
  265. </p>
  266. <p>
  267. <label for="<?php echo $this->get_field_id( 'show_rating' ); ?>">
  268. <input class="checkbox" type="checkbox" <?php checked( $instance['show_rating'], true ); ?> id="<?php echo $this->get_field_id( 'show_rating' ); ?>" name="<?php echo $this->get_field_name( 'show_rating' ); ?>" /> <?php _e( 'Show rating?', 'hybrid-core' ); ?> <code>show_rating</code></label>
  269. </p>
  270. <p>
  271. <label for="<?php echo $this->get_field_id( 'show_updated' ); ?>">
  272. <input class="checkbox" type="checkbox" <?php checked( $instance['show_updated'], true ); ?> id="<?php echo $this->get_field_id( 'show_updated' ); ?>" name="<?php echo $this->get_field_name( 'show_updated' ); ?>" /> <?php _e( 'Show updated?', 'hybrid-core' ); ?> <code>show_updated</code></label>
  273. </p>
  274. <p>
  275. <label for="<?php echo $this->get_field_id( 'show_images' ); ?>">
  276. <input class="checkbox" type="checkbox" <?php checked( $instance['show_images'], true ); ?> id="<?php echo $this->get_field_id( 'show_images' ); ?>" name="<?php echo $this->get_field_name( 'show_images' ); ?>" /> <?php _e( 'Show images?', 'hybrid-core' ); ?> <code>show_images</code></label>
  277. </p>
  278. <p>
  279. <label for="<?php echo $this->get_field_id( 'show_name' ); ?>">
  280. <input class="checkbox" type="checkbox" <?php checked( $instance['show_name'], true ); ?> id="<?php echo $this->get_field_id( 'show_name' ); ?>" name="<?php echo $this->get_field_name( 'show_name' ); ?>" /> <?php _e( 'Show name?', 'hybrid-core' ); ?> <code>show_name</code></label>
  281. </p>
  282. <p>
  283. <label for="<?php echo $this->get_field_id( 'show_private' ); ?>">
  284. <input class="checkbox" type="checkbox" <?php checked( $instance['show_private'], true ); ?> id="<?php echo $this->get_field_id( 'show_private' ); ?>" name="<?php echo $this->get_field_name( 'show_private' ); ?>" /> <?php _e( 'Show private?', 'hybrid-core' ); ?> <code>show_private</code></label>
  285. </p>
  286. </div>
  287. <div style="clear:both;">&nbsp;</div>
  288. <?php
  289. }
  290. }
  291. ?>