PageRenderTime 57ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/lgorence/quickpress
PHP | 264 lines | 189 code | 26 blank | 49 comment | 1 complexity | 39d68a72005eb00177e737bc9aa957d2 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /**
  3. * The Pages widget replaces the default WordPress Pages 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_pages() function.
  6. *
  7. * @package Hybrid
  8. * @subpackage Widgets
  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. * Pages Widget Class
  16. *
  17. * @since 0.6.0
  18. */
  19. class Hybrid_Widget_Pages 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' => 'pages',
  29. 'description' => esc_html__( 'An advanced widget that gives you total control over the output of your page 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-pages', // $this->id_base
  39. __( 'Pages', '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 the $args for wp_list_pages() to the $instance array. */
  52. $args = $instance;
  53. /* Set the $title_li and $echo to false. */
  54. $args['title_li'] = false;
  55. $args['echo'] = false;
  56. /* Open the output of the widget. */
  57. echo $before_widget;
  58. /* If a title was input by the user, display it. */
  59. if ( !empty( $instance['title'] ) )
  60. echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title;
  61. /* Output the page list. */
  62. echo '<ul class="xoxo pages">' . str_replace( array( "\r", "\n", "\t" ), '', wp_list_pages( $args ) ) . '</ul>';
  63. /* Close the output of the widget. */
  64. echo $after_widget;
  65. }
  66. /**
  67. * Updates the widget control options for the particular instance of the widget.
  68. *
  69. * @since 0.6.0
  70. */
  71. function update( $new_instance, $old_instance ) {
  72. $instance = $old_instance;
  73. /* Set the instance to the new instance. */
  74. $instance = $new_instance;
  75. $instance['title'] = strip_tags( $new_instance['title'] );
  76. $instance['depth'] = strip_tags( $new_instance['depth'] );
  77. $instance['child_of'] = strip_tags( $new_instance['child_of'] );
  78. $instance['meta_key'] = strip_tags( $new_instance['meta_key'] );
  79. $instance['meta_value'] = strip_tags( $new_instance['meta_value'] );
  80. $instance['date_format'] = strip_tags( $new_instance['date_format'] );
  81. $instance['number'] = strip_tags( $new_instance['number'] );
  82. $instance['offset'] = strip_tags( $new_instance['offset'] );
  83. $instance['include'] = preg_replace( '/[^0-9,]/', '', $new_instance['include'] );
  84. $instance['exclude'] = preg_replace( '/[^0-9,]/', '', $new_instance['exclude'] );
  85. $instance['exclude_tree'] = preg_replace( '/[^0-9,]/', '', $new_instance['exclude_tree'] );
  86. $instance['authors'] = preg_replace( '/[^0-9,]/', '', $new_instance['authors'] );
  87. $instance['post_type'] = $new_instance['post_type'];
  88. $instance['sort_column'] = $new_instance['sort_column'];
  89. $instance['sort_order'] = $new_instance['sort_order'];
  90. $instance['show_date'] = $new_instance['show_date'];
  91. $instance['link_before'] = $new_instance['link_before'];
  92. $instance['link_after'] = $new_instance['link_after'];
  93. $instance['hierarchical'] = ( isset( $new_instance['hierarchical'] ) ? 1 : 0 );
  94. return $instance;
  95. }
  96. /**
  97. * Displays the widget control options in the Widgets admin screen.
  98. *
  99. * @since 0.6.0
  100. */
  101. function form( $instance ) {
  102. /* Set up the default form values. */
  103. $defaults = array(
  104. 'title' => esc_attr__( 'Pages', 'hybrid-core'),
  105. 'post_type' => 'page',
  106. 'depth' => 0,
  107. 'number' => '',
  108. 'offset' => '',
  109. 'child_of' => '',
  110. 'include' => '',
  111. 'exclude' => '',
  112. 'exclude_tree' => '',
  113. 'meta_key' => '',
  114. 'meta_value' => '',
  115. 'authors' => '',
  116. 'link_before' => '',
  117. 'link_after' => '',
  118. 'show_date' => '',
  119. 'hierarchical' => true,
  120. 'sort_column' => 'post_title',
  121. 'sort_order' => 'ASC',
  122. 'date_format' => get_option( 'date_format' )
  123. );
  124. /* Merge the user-selected arguments with the defaults. */
  125. $instance = wp_parse_args( (array) $instance, $defaults );
  126. $post_types = get_post_types( array( 'public' => true, 'hierarchical' => true ), 'objects' );
  127. $sort_order = array( 'ASC' => esc_attr__( 'Ascending', 'hybrid-core' ), 'DESC' => esc_attr__( 'Descending', 'hybrid-core' ) );
  128. $sort_column = array( 'post_author' => esc_attr__( 'Author', 'hybrid-core' ), 'post_date' => esc_attr__( 'Date', 'hybrid-core' ), 'ID' => esc_attr__( 'ID', 'hybrid-core' ), 'menu_order' => esc_attr__( 'Menu Order', 'hybrid-core' ), 'post_modified' => esc_attr__( 'Modified', 'hybrid-core' ), 'post_name' => esc_attr__( 'Slug', 'hybrid-core' ), 'post_title' => esc_attr__( 'Title', 'hybrid-core' ) );
  129. $show_date = array( '' => '', 'created' => esc_attr__( 'Created', 'hybrid-core' ), 'modified' => esc_attr__( 'Modified', 'hybrid-core' ) );
  130. $meta_key = array_merge( array( '' ), (array) get_meta_keys() );
  131. ?>
  132. <div class="hybrid-widget-controls columns-3">
  133. <p>
  134. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'hybrid-core' ); ?></label>
  135. <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" />
  136. </p>
  137. <p>
  138. <label for="<?php echo $this->get_field_id( 'post_type' ); ?>"><code>post_type</code></label>
  139. <select class="widefat" id="<?php echo $this->get_field_id( 'post_type' ); ?>" name="<?php echo $this->get_field_name( 'post_type' ); ?>">
  140. <?php foreach ( $post_types as $post_type ) { ?>
  141. <option value="<?php echo esc_attr( $post_type->name ); ?>" <?php selected( $instance['post_type'], $post_type->name ); ?>><?php echo esc_html( $post_type->labels->singular_name ); ?></option>
  142. <?php } ?>
  143. </select>
  144. </p>
  145. <p>
  146. <label for="<?php echo $this->get_field_id( 'sort_order' ); ?>"><code>sort_order</code></label>
  147. <select class="widefat" id="<?php echo $this->get_field_id( 'sort_order' ); ?>" name="<?php echo $this->get_field_name( 'sort_order' ); ?>">
  148. <?php foreach ( $sort_order as $option_value => $option_label ) { ?>
  149. <option value="<?php echo esc_attr( $option_value ); ?>" <?php selected( $instance['sort_order'], $option_value ); ?>><?php echo esc_html( $option_label ); ?></option>
  150. <?php } ?>
  151. </select>
  152. </p>
  153. <p>
  154. <label for="<?php echo $this->get_field_id( 'sort_column' ); ?>"><code>sort_column</code></label>
  155. <select class="widefat" id="<?php echo $this->get_field_id( 'sort_column' ); ?>" name="<?php echo $this->get_field_name( 'sort_column' ); ?>">
  156. <?php foreach ( $sort_column as $option_value => $option_label ) { ?>
  157. <option value="<?php echo esc_attr( $option_value ); ?>" <?php selected( $instance['sort_column'], $option_value ); ?>><?php echo esc_html( $option_label ); ?></option>
  158. <?php } ?>
  159. </select>
  160. </p>
  161. <p>
  162. <label for="<?php echo $this->get_field_id( 'depth' ); ?>"><code>depth</code></label>
  163. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'depth' ); ?>" name="<?php echo $this->get_field_name( 'depth' ); ?>" value="<?php echo esc_attr( $instance['depth'] ); ?>" />
  164. </p>
  165. <p>
  166. <label for="<?php echo $this->get_field_id( 'number' ); ?>"><code>number</code></label>
  167. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" value="<?php echo esc_attr( $instance['number'] ); ?>" />
  168. </p>
  169. </div>
  170. <div class="hybrid-widget-controls columns-3">
  171. <p>
  172. <label for="<?php echo $this->get_field_id( 'offset' ); ?>"><code>offset</code></label>
  173. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'offset' ); ?>" name="<?php echo $this->get_field_name( 'offset' ); ?>" value="<?php echo esc_attr( $instance['offset'] ); ?>" />
  174. </p>
  175. <p>
  176. <label for="<?php echo $this->get_field_id( 'child_of' ); ?>"><code>child_of</code></label>
  177. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'child_of' ); ?>" name="<?php echo $this->get_field_name( 'child_of' ); ?>" value="<?php echo esc_attr( $instance['child_of'] ); ?>" />
  178. </p>
  179. <p>
  180. <label for="<?php echo $this->get_field_id( 'include' ); ?>"><code>include</code></label>
  181. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'include' ); ?>" name="<?php echo $this->get_field_name( 'include' ); ?>" value="<?php echo esc_attr( $instance['include'] ); ?>" />
  182. </p>
  183. <p>
  184. <label for="<?php echo $this->get_field_id( 'exclude' ); ?>"><code>exclude</code></label>
  185. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'exclude' ); ?>" name="<?php echo $this->get_field_name( 'exclude' ); ?>" value="<?php echo esc_attr( $instance['exclude'] ); ?>" />
  186. </p>
  187. <p>
  188. <label for="<?php echo $this->get_field_id( 'exclude_tree' ); ?>"><code>exclude_tree</code></label>
  189. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'exclude_tree' ); ?>" name="<?php echo $this->get_field_name( 'exclude_tree' ); ?>" value="<?php echo esc_attr( $instance['exclude_tree'] ); ?>" />
  190. </p>
  191. <p>
  192. <label for="<?php echo $this->get_field_id( 'meta_key' ); ?>"><code>meta_key</code></label>
  193. <select class="widefat" id="<?php echo $this->get_field_id( 'meta_key' ); ?>" name="<?php echo $this->get_field_name( 'meta_key' ); ?>">
  194. <?php foreach ( $meta_key as $meta ) { ?>
  195. <option value="<?php echo esc_attr( $meta ); ?>" <?php selected( $instance['meta_key'], $meta ); ?>><?php echo esc_html( $meta ); ?></option>
  196. <?php } ?>
  197. </select>
  198. </p>
  199. <p>
  200. <label for="<?php echo $this->get_field_id( 'meta_value' ); ?>"><code>meta_value</code></label>
  201. <input type="text" class="widefat code" id="<?php echo $this->get_field_id( 'meta_value' ); ?>" name="<?php echo $this->get_field_name( 'meta_value' ); ?>" value="<?php echo esc_attr( $instance['meta_value'] ); ?>" />
  202. </p>
  203. </div>
  204. <div class="hybrid-widget-controls columns-3 column-last">
  205. <p>
  206. <label for="<?php echo $this->get_field_id( 'authors' ); ?>"><code>authors</code></label>
  207. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'authors' ); ?>" name="<?php echo $this->get_field_name( 'authors' ); ?>" value="<?php echo esc_attr( $instance['authors'] ); ?>" />
  208. </p>
  209. <p>
  210. <label for="<?php echo $this->get_field_id( 'link_before' ); ?>"><code>link_before</code></label>
  211. <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'] ); ?>" />
  212. </p>
  213. <p>
  214. <label for="<?php echo $this->get_field_id( 'link_after' ); ?>"><code>link_after</code></label>
  215. <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'] ); ?>" />
  216. </p>
  217. <p>
  218. <label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><code>show_date</code></label>
  219. <select class="widefat" id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>">
  220. <?php foreach ( $show_date as $option_value => $option_label ) { ?>
  221. <option value="<?php echo esc_attr( $option_value ); ?>" <?php selected( $instance['show_date'], $option_value ); ?>><?php echo esc_html( $option_label ); ?></option>
  222. <?php } ?>
  223. </select>
  224. </p>
  225. <p>
  226. <label for="<?php echo $this->get_field_id( 'date_format' ); ?>"><code>date_format</code></label>
  227. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'date_format' ); ?>" name="<?php echo $this->get_field_name( 'date_format' ); ?>" value="<?php echo esc_attr( $instance['date_format'] ); ?>" />
  228. </p>
  229. <p>
  230. <label for="<?php echo $this->get_field_id( 'hierarchical' ); ?>">
  231. <input class="checkbox" type="checkbox" <?php checked( $instance['hierarchical'], true ); ?> id="<?php echo $this->get_field_id( 'hierarchical' ); ?>" name="<?php echo $this->get_field_name( 'hierarchical' ); ?>" /> <?php _e( 'Hierarchical?', 'hybrid-core'); ?> <code>hierarchical</code></label>
  232. </p>
  233. </div>
  234. <div style="clear:both;">&nbsp;</div>
  235. <?php
  236. }
  237. }
  238. ?>