PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/lgorence/quickpress
PHP | 206 lines | 118 code | 33 blank | 55 comment | 13 complexity | 9f4677f68bb7c1ef9e4122db54078c7f MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /**
  3. * The Archives widget replaces the default WordPress Archives 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_get_archives() 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. * Archives widget class.
  16. *
  17. * @since 0.6.0
  18. */
  19. class Hybrid_Widget_Archives 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' => 'archives',
  29. 'description' => esc_html__( 'An advanced widget that gives you total control over the output of your archives.', 'hybrid-core' )
  30. );
  31. /* Set up the widget control options. */
  32. $control_options = array(
  33. 'width' => 525,
  34. 'height' => 350
  35. );
  36. /* Create the widget. */
  37. $this->WP_Widget(
  38. 'hybrid-archives', // $this->id_base
  39. __( 'Archives', '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_get_archives() to the $instance array. */
  52. $args = $instance;
  53. /* Overwrite the $echo argument and set it to false. */
  54. $args['echo'] = false;
  55. /* Output the theme's $before_widget wrapper. */
  56. echo $before_widget;
  57. /* If a title was input by the user, display it. */
  58. if ( !empty( $instance['title'] ) )
  59. echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title;
  60. /* Get the archives list. */
  61. $archives = str_replace( array( "\r", "\n", "\t" ), '', wp_get_archives( $args ) );
  62. /* If the archives should be shown in a <select> drop-down. */
  63. if ( 'option' == $args['format'] ) {
  64. /* Create a title for the drop-down based on the archive type. */
  65. if ( 'yearly' == $args['type'] )
  66. $option_title = esc_html__( 'Select Year', 'hybrid-core' );
  67. elseif ( 'monthly' == $args['type'] )
  68. $option_title = esc_html__( 'Select Month', 'hybrid-core' );
  69. elseif ( 'weekly' == $args['type'] )
  70. $option_title = esc_html__( 'Select Week', 'hybrid-core' );
  71. elseif ( 'daily' == $args['type'] )
  72. $option_title = esc_html__( 'Select Day', 'hybrid-core' );
  73. elseif ( 'postbypost' == $args['type'] || 'alpha' == $args['type'] )
  74. $option_title = esc_html__( 'Select Post', 'hybrid-core' );
  75. /* Output the <select> element and each <option>. */
  76. echo '<p><select name="archive-dropdown" onchange=\'document.location.href=this.options[this.selectedIndex].value;\'>';
  77. echo '<option value="">' . $option_title . '</option>';
  78. echo $archives;
  79. echo '</select></p>';
  80. }
  81. /* If the format should be an unordered list. */
  82. elseif ( 'html' == $args['format'] ) {
  83. echo '<ul class="xoxo archives">' . $archives . '</ul><!-- .xoxo .archives -->';
  84. }
  85. /* All other formats. */
  86. else {
  87. echo $archives;
  88. }
  89. /* Close the theme's widget wrapper. */
  90. echo $after_widget;
  91. }
  92. /**
  93. * Updates the widget control options for the particular instance of the widget.
  94. *
  95. * @since 0.6.0
  96. */
  97. function update( $new_instance, $old_instance ) {
  98. $instance = $new_instance;
  99. $instance['title'] = strip_tags( $new_instance['title'] );
  100. $instance['before'] = strip_tags( $new_instance['before'] );
  101. $instance['after'] = strip_tags( $new_instance['after'] );
  102. $instance['limit'] = strip_tags( $new_instance['limit'] );
  103. $instance['show_post_count'] = ( isset( $new_instance['show_post_count'] ) ? 1 : 0 );
  104. return $instance;
  105. }
  106. /**
  107. * Displays the widget control options in the Widgets admin screen.
  108. *
  109. * @since 0.6.0
  110. */
  111. function form( $instance ) {
  112. /* Set up the default form values. */
  113. $defaults = array(
  114. 'title' => esc_attr__( 'Archives', 'hybrid-core' ),
  115. 'limit' => 10,
  116. 'type' => 'monthly',
  117. 'format' => 'html',
  118. 'before' => '',
  119. 'after' => '',
  120. 'show_post_count' => false
  121. );
  122. /* Merge the user-selected arguments with the defaults. */
  123. $instance = wp_parse_args( (array) $instance, $defaults );
  124. /* Create an array of archive types. */
  125. $type = array( 'alpha' => esc_attr__( 'Alphabetical', 'hybrid-core' ), 'daily' => esc_attr__( 'Daily', 'hybrid-core' ), 'monthly' => esc_attr__( 'Monthly', 'hybrid-core' ),'postbypost' => esc_attr__( 'Post By Post', 'hybrid-core' ), 'weekly' => esc_attr__( 'Weekly', 'hybrid-core' ), 'yearly' => esc_attr__( 'Yearly', 'hybrid-core' ) );
  126. /* Create an array of archive formats. */
  127. $format = array( 'custom' => esc_attr__( 'Custom', 'hybrid-core' ), 'html' => esc_attr__( 'HTML', 'hybrid-core' ), 'option' => esc_attr__( 'Option', 'hybrid-core' ) );
  128. ?>
  129. <div class="hybrid-widget-controls columns-2">
  130. <p>
  131. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'hybrid-core' ); ?></label>
  132. <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'] ); ?>" />
  133. </p>
  134. <p>
  135. <label for="<?php echo $this->get_field_id( 'limit' ); ?>"><code>limit</code></label>
  136. <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'] ); ?>" />
  137. </p>
  138. <p>
  139. <label for="<?php echo $this->get_field_id( 'type' ); ?>"><code>type</code></label>
  140. <select class="widefat" id="<?php echo $this->get_field_id( 'type' ); ?>" name="<?php echo $this->get_field_name( 'type' ); ?>">
  141. <?php foreach ( $type as $option_value => $option_label ) { ?>
  142. <option value="<?php echo esc_attr( $option_value ); ?>" <?php selected( $instance['type'], $option_value ); ?>><?php echo esc_html( $option_label ); ?></option>
  143. <?php } ?>
  144. </select>
  145. </p>
  146. <p>
  147. <label for="<?php echo $this->get_field_id( 'format' ); ?>"><code>format</code></label>
  148. <select class="widefat" id="<?php echo $this->get_field_id( 'format' ); ?>" name="<?php echo $this->get_field_name( 'format' ); ?>">
  149. <?php foreach ( $format as $option_value => $option_label ) { ?>
  150. <option value="<?php echo esc_attr( $option_value ); ?>" <?php selected( $instance['format'], $option_value ); ?>><?php echo esc_html( $option_label ); ?></option>
  151. <?php } ?>
  152. </select>
  153. </p>
  154. </div>
  155. <div class="hybrid-widget-controls columns-2 column-last">
  156. <p>
  157. <label for="<?php echo $this->get_field_id( 'before' ); ?>"><code>before</code></label>
  158. <input type="text" class="widefat code" id="<?php echo $this->get_field_id( 'before' ); ?>" name="<?php echo $this->get_field_name( 'before' ); ?>" value="<?php echo esc_attr( $instance['before'] ); ?>" />
  159. </p>
  160. <p>
  161. <label for="<?php echo $this->get_field_id( 'after' ); ?>"><code>after</code></label>
  162. <input type="text" class="widefat code" id="<?php echo $this->get_field_id( 'after' ); ?>" name="<?php echo $this->get_field_name( 'after' ); ?>" value="<?php echo esc_attr( $instance['after'] ); ?>" />
  163. </p>
  164. <p>
  165. <label for="<?php echo $this->get_field_id( 'show_post_count' ); ?>">
  166. <input class="checkbox" type="checkbox" <?php checked( $instance['show_post_count'], true ); ?> id="<?php echo $this->get_field_id( 'show_post_count' ); ?>" name="<?php echo $this->get_field_name( 'show_post_count' ); ?>" /> <?php _e( 'Show post count?', 'hybrid-core' ); ?> <code>show_post_count</code></label>
  167. </p>
  168. </div>
  169. <div style="clear:both;">&nbsp;</div>
  170. <?php
  171. }
  172. }
  173. ?>