PageRenderTime 67ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/wordpress/wp-content/theme/hybrid/library/classes/widget-categories.php

http://ooxx.googlecode.com/
PHP | 246 lines | 191 code | 24 blank | 31 comment | 22 complexity | 1d5a9f49ca5f9e196821050020d2cbc9 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * Categories Widget Class
  4. *
  5. * The Categories widget replaces the default WordPress Categories widget. This version gives total
  6. * control over the output to the user by allowing the input of all the arguments typically seen
  7. * in the wp_list_categories() function.
  8. *
  9. * @since 0.6
  10. * @link http://codex.wordpress.org/Template_Tags/wp_list_categories
  11. * @link http://themehybrid.com/themes/hybrid/widgets
  12. *
  13. * @package Hybrid
  14. * @subpackage Classes
  15. */
  16. class Hybrid_Widget_Categories extends WP_Widget {
  17. var $prefix;
  18. var $textdomain;
  19. /**
  20. * Set up the widget's unique name, ID, class, description, and other options.
  21. * @since 0.6
  22. */
  23. function Hybrid_Widget_Categories() {
  24. $this->prefix = hybrid_get_prefix();
  25. $this->textdomain = hybrid_get_textdomain();
  26. $widget_ops = array( 'classname' => 'categories', 'description' => __( 'An advanced widget that gives you total control over the output of your category links.', $this->textdomain ) );
  27. $control_ops = array( 'width' => 800, 'height' => 350, 'id_base' => "{$this->prefix}-categories" );
  28. $this->WP_Widget( "{$this->prefix}-categories", __( 'Categories', $this->textdomain ), $widget_ops, $control_ops );
  29. }
  30. /**
  31. * Outputs the widget based on the arguments input through the widget controls.
  32. * @since 0.6
  33. */
  34. function widget( $args, $instance ) {
  35. extract( $args );
  36. $title = apply_filters( 'widget_title', $instance['title'] );
  37. $style = $instance['style'];
  38. $orderby = $instance['orderby'];
  39. $order = $instance['order'];
  40. $exclude = $instance['exclude'];
  41. $exclude_tree = $instance['exclude_tree'];
  42. $include = $instance['include'];
  43. $depth = (int)$instance['depth'];
  44. $number = (int)$instance['number'];
  45. $child_of = (int)$instance['child_of'];
  46. $current_category = (int)$instance['current_category'];
  47. $feed_image = $instance['feed_image'];
  48. $search = $instance['search'];
  49. $hierarchical = isset( $instance['hierarchical'] ) ? $instance['hierarchical'] : false;
  50. $use_desc_for_title = isset( $instance['use_desc_for_title'] ) ? $instance['use_desc_for_title'] : false;
  51. $show_last_update = isset( $instance['show_last_update'] ) ? $instance['show_last_updated'] : false;
  52. $show_count = isset( $instance['show_count'] ) ? $instance['show_count'] : false;
  53. $hide_empty = isset( $instance['hide_empty'] ) ? $instance['hide_empty'] : false;
  54. $feed = isset( $instance['feed'] ) ? $instance['feed'] : false;
  55. if ( $feed )
  56. $feed = __( 'RSS', $this->textdomain );
  57. $args = array(
  58. 'exclude' => $exclude,
  59. 'exclude_tree' => $exclude_tree,
  60. 'include' => $include,
  61. 'number' => $number,
  62. 'depth' => $depth,
  63. 'orderby' => $orderby,
  64. 'order' => $order,
  65. 'show_last_update' => $show_last_update,
  66. 'style' => $style,
  67. 'show_count' => $show_count,
  68. 'hide_empty' => $hide_empty,
  69. 'use_desc_for_title' => $use_desc_for_title,
  70. 'child_of' => $child_of,
  71. 'feed' => $feed,
  72. 'feed_image' => $feed_image,
  73. 'hierarchical' => $hierarchical,
  74. 'title_li' => false,
  75. 'current_category' => $current_category,
  76. 'echo' => 0,
  77. 'depth' => $depth,
  78. 'search' => $search,
  79. );
  80. echo $before_widget;
  81. if ( $title )
  82. echo $before_title . $title . $after_title;
  83. $categories = str_replace( array( "\r", "\n", "\t" ), '', wp_list_categories( $args ) );
  84. if ( 'list' == $style )
  85. $categories = '<ul class="xoxo categories">' . $categories . '</ul><!-- .xoxo .categories -->';
  86. echo $categories;
  87. echo $after_widget;
  88. }
  89. /**
  90. * Updates the widget control options for the particular instance of the widget.
  91. * @since 0.6
  92. */
  93. function update( $new_instance, $old_instance ) {
  94. $instance = $old_instance;
  95. $instance['title'] = strip_tags( $new_instance['title'] );
  96. $instance['exclude'] = strip_tags( $new_instance['exclude'] );
  97. $instance['exclude_tree'] = strip_tags( $new_instance['exclude_tree'] );
  98. $instance['include'] = strip_tags( $new_instance['include'] );
  99. $instance['depth'] = strip_tags( $new_instance['depth'] );
  100. $instance['number'] = strip_tags( $new_instance['number'] );
  101. $instance['child_of'] = strip_tags( $new_instance['child_of'] );
  102. $instance['current_category'] = strip_tags( $new_instance['current_category'] );
  103. $instance['feed_image'] = strip_tags( $new_instance['feed_image'] );
  104. $instance['search'] = strip_tags( $new_instance['search'] );
  105. $instance['style'] = $new_instance['style'];
  106. $instance['orderby'] = $new_instance['orderby'];
  107. $instance['order'] = $new_instance['order'];
  108. $instance['hierarchical'] = ( isset( $new_instance['hierarchical'] ) ? 1 : 0 );
  109. $instance['use_desc_for_title'] = ( isset( $new_instance['use_desc_for_title'] ) ? 1 : 0 );
  110. $instance['show_last_update'] = ( isset( $new_instance['show_last_update'] ) ? 1 : 0 );
  111. $instance['show_count'] = ( isset( $new_instance['show_count'] ) ? 1 : 0 );
  112. $instance['hide_empty'] = ( isset( $new_instance['hide_empty'] ) ? 1 : 0 );
  113. $instance['feed'] = ( isset( $new_instance['feed'] ) ? 1 : 0 );
  114. return $instance;
  115. }
  116. /**
  117. * Displays the widget control options in the Widgets admin screen.
  118. * @since 0.6
  119. */
  120. function form( $instance ) {
  121. // Defaults
  122. $defaults = array( 'title' => __( 'Categories', $this->textdomain ), 'style' => 'list', 'hierarchical' => true, 'hide_empty' => true, 'order' => 'ASC', 'orderby' => 'name' );
  123. $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  124. <div style="float:left;width:31%;">
  125. <p>
  126. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', $this->textdomain ); ?></label>
  127. <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $instance['title']; ?>" style="width:100%;" />
  128. </p>
  129. <p>
  130. <label for="<?php echo $this->get_field_id( 'style' ); ?>"><?php _e( 'Style:', $this->textdomain ); ?> <code>style</code></label>
  131. <select id="<?php echo $this->get_field_id( 'style' ); ?>" name="<?php echo $this->get_field_name( 'style' ); ?>" class="widefat" style="width:100%;">
  132. <option <?php if ( 'list' == $instance['style'] ) echo 'selected="selected"'; ?>>list</option>
  133. <option <?php if ( 'none' == $instance['style'] ) echo 'selected="selected"'; ?>>none</option>
  134. </select>
  135. </p>
  136. <p>
  137. <label for="<?php echo $this->get_field_id( 'order' ); ?>"><?php _e( 'Order:', $this->textdomain ); ?> <code>order</code></label>
  138. <select id="<?php echo $this->get_field_id( 'order' ); ?>" name="<?php echo $this->get_field_name( 'order' ); ?>" class="widefat" style="width:100%;">
  139. <option <?php if ( 'ASC' == $instance['order'] ) echo 'selected="selected"'; ?>>ASC</option>
  140. <option <?php if ( 'DESC' == $instance['order'] ) echo 'selected="selected"'; ?>>DESC</option>
  141. </select>
  142. </p>
  143. <p>
  144. <label for="<?php echo $this->get_field_id( 'orderby' ); ?>"><?php _e( 'Order By:', $this->textdomain ); ?> <code>orderby</code></label>
  145. <select id="<?php echo $this->get_field_id( 'orderby' ); ?>" name="<?php echo $this->get_field_name( 'orderby' ); ?>" class="widefat" style="width:100%;">
  146. <option <?php if ( 'name' == $instance['orderby'] ) echo 'selected="selected"'; ?>>name</option>
  147. <option <?php if ( 'slug' == $instance['orderby'] ) echo 'selected="selected"'; ?>>slug</option>
  148. <option <?php if ( 'ID' == $instance['orderby'] ) echo 'selected="selected"'; ?>>ID</option>
  149. <option <?php if ( 'count' == $instance['orderby'] ) echo 'selected="selected"'; ?>>count</option>
  150. <option <?php if ( 'term_group' == $instance['orderby'] ) echo 'selected="selected"'; ?>>term_group</option>
  151. </select>
  152. </p>
  153. <p>
  154. <label for="<?php echo $this->get_field_id( 'depth' ); ?>"><?php _e( 'Depth:', $this->textdomain ); ?> <code>depth</code></label>
  155. <input id="<?php echo $this->get_field_id( 'depth' ); ?>" name="<?php echo $this->get_field_name( 'depth' ); ?>" type="text" value="<?php echo $instance['depth']; ?>" style="width:100%;" />
  156. </p>
  157. <p>
  158. <label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number:', $this->textdomain ); ?> <code>number</code></label>
  159. <input id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo $instance['number']; ?>" style="width:100%;" />
  160. </p>
  161. </div>
  162. <div style="float:left;width:31%;margin-left:3.5%;">
  163. <p>
  164. <label for="<?php echo $this->get_field_id( 'include' ); ?>"><?php _e( 'Include:', $this->textdomain ); ?> <code>include</code></label>
  165. <input id="<?php echo $this->get_field_id( 'include' ); ?>" name="<?php echo $this->get_field_name( 'include' ); ?>" type="text" value="<?php echo $instance['include']; ?>" style="width:100%;" />
  166. </p>
  167. <p>
  168. <label for="<?php echo $this->get_field_id( 'exclude' ); ?>"><?php _e( 'Exclude:', $this->textdomain ); ?> <code>exclude</code></label>
  169. <input id="<?php echo $this->get_field_id( 'exclude' ); ?>" name="<?php echo $this->get_field_name( 'exclude' ); ?>" type="text" value="<?php echo $instance['exclude']; ?>" style="width:100%;" />
  170. </p>
  171. <p>
  172. <label for="<?php echo $this->get_field_id( 'exclude_tree' ); ?>"><?php _e( 'Exclude Tree:', $this->textdomain ); ?> <code>exclude_tree</code></label>
  173. <input id="<?php echo $this->get_field_id( 'exclude_tree' ); ?>" name="<?php echo $this->get_field_name( 'exclude_tree' ); ?>" type="text" value="<?php echo $instance['exclude_tree']; ?>" style="width:100%;" />
  174. </p>
  175. <p>
  176. <label for="<?php echo $this->get_field_id( 'child_of' ); ?>"><?php _e( 'Child Of:', $this->textdomain ); ?> <code>child_of</code></label>
  177. <input id="<?php echo $this->get_field_id( 'child_of' ); ?>" name="<?php echo $this->get_field_name( 'child_of' ); ?>" type="text" value="<?php echo $instance['child_of']; ?>" style="width:100%;" />
  178. </p>
  179. <p>
  180. <label for="<?php echo $this->get_field_id( 'search' ); ?>"><?php _e( 'Search:', $this->textdomain ); ?> <code>search</code></label>
  181. <input id="<?php echo $this->get_field_id( 'search' ); ?>" name="<?php echo $this->get_field_name( 'search' ); ?>" type="text" value="<?php echo $instance['search']; ?>" style="width:100%;" />
  182. </p>
  183. <p>
  184. <label for="<?php echo $this->get_field_id( 'current_category' ); ?>"><?php _e( 'Current Category:', $this->textdomain ); ?> <code>current_category</code></label>
  185. <input id="<?php echo $this->get_field_id( 'current_category' ); ?>" name="<?php echo $this->get_field_name( 'current_category' ); ?>" type="text" value="<?php echo $instance['current_category']; ?>" style="width:100%;" />
  186. </p>
  187. </div>
  188. <div style="float:right;width:31%;margin-left:3.5%;">
  189. <p>
  190. <label for="<?php echo $this->get_field_id( 'feed_image' ); ?>"><?php _e( 'Feed Image:', $this->textdomain ); ?> <code>feed_image</code></label>
  191. <input id="<?php echo $this->get_field_id( 'feed_image' ); ?>" name="<?php echo $this->get_field_name( 'feed_image' ); ?>" type="text" value="<?php echo $instance['feed_image']; ?>" style="width:100%;" />
  192. </p>
  193. <p>
  194. <label for="<?php echo $this->get_field_id( 'hierarchical' ); ?>">
  195. <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?', $this->textdomain ); ?> <code>hierarchical</code></label>
  196. </p>
  197. <p>
  198. <label for="<?php echo $this->get_field_id( 'use_desc_for_title' ); ?>">
  199. <input class="checkbox" type="checkbox" <?php checked( $instance['use_desc_for_title'], true ); ?> id="<?php echo $this->get_field_id( 'use_desc_for_title' ); ?>" name="<?php echo $this->get_field_name( 'use_desc_for_title' ); ?>" /> <?php _e( 'Use description?', $this->textdomain ); ?> <code>use_desc_for_title</code></label>
  200. </p>
  201. <p>
  202. <label for="<?php echo $this->get_field_id( 'show_last_update' ); ?>">
  203. <input class="checkbox" type="checkbox" <?php checked( $instance['show_last_update'], true ); ?> id="<?php echo $this->get_field_id( 'show_last_update' ); ?>" name="<?php echo $this->get_field_name( 'show_last_update' ); ?>" /> <?php _e( 'Show last update?', $this->textdomain ); ?> <code>show_last_update</code></label>
  204. </p>
  205. <p>
  206. <label for="<?php echo $this->get_field_id( 'show_count' ); ?>">
  207. <input class="checkbox" type="checkbox" <?php checked( $instance['show_count'], true ); ?> id="<?php echo $this->get_field_id( 'show_count' ); ?>" name="<?php echo $this->get_field_name( 'show_count' ); ?>" /> <?php _e( 'Show count?', $this->textdomain ); ?> <code>show_count</code></label>
  208. </p>
  209. <p>
  210. <label for="<?php echo $this->get_field_id( 'hide_empty' ); ?>">
  211. <input class="checkbox" type="checkbox" <?php checked( $instance['hide_empty'], true ); ?> id="<?php echo $this->get_field_id( 'hide_empty' ); ?>" name="<?php echo $this->get_field_name( 'hide_empty' ); ?>" /> <?php _e( 'Hide empty?', $this->textdomain ); ?> <code>hide_empty</code></label>
  212. </p>
  213. <p>
  214. <label for="<?php echo $this->get_field_id( 'feed' ); ?>">
  215. <input class="checkbox" type="checkbox" <?php checked( $instance['feed'], true ); ?> id="<?php echo $this->get_field_id( 'feed' ); ?>" name="<?php echo $this->get_field_name( 'feed' ); ?>" /> <?php _e( 'Show RSS feed?', $this->textdomain ); ?> <code>feed</code></label>
  216. </p>
  217. </div>
  218. <div style="clear:both;">&nbsp;</div>
  219. <?php
  220. }
  221. }
  222. ?>