PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/lgorence/quickpress
PHP | 120 lines | 54 code | 19 blank | 47 comment | 1 complexity | 5d2714ede59a9041171d8e3afbd40245 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /**
  3. * The calendar widget was created to give users the ability to show a post calendar for their blog
  4. * using all the available options given in the get_calendar() function. It replaces the default WordPress
  5. * calendar widget.
  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. * Calendar Widget Class
  16. *
  17. * @since 0.6.0
  18. */
  19. class Hybrid_Widget_Calendar 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' => 'calendar',
  29. 'description' => esc_html__( 'An advanced widget that gives you total control over the output of your calendar.', 'hybrid-core' )
  30. );
  31. /* Set up the widget control options. */
  32. $control_options = array(
  33. 'width' => 200,
  34. 'height' => 350
  35. );
  36. /* Create the widget. */
  37. $this->WP_Widget(
  38. 'hybrid-calendar', // $this->id_base
  39. __( 'Calendar', '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. /* Get the $initial argument. */
  52. $initial = !empty( $instance['initial'] ) ? true : false;
  53. /* Output the theme's widget wrapper. */
  54. echo $before_widget;
  55. /* If a title was input by the user, display it. */
  56. if ( !empty( $instance['title'] ) )
  57. echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title;
  58. /* Display the calendar. */
  59. echo '<div class="calendar-wrap">';
  60. echo str_replace( array( "\r", "\n", "\t" ), '', get_calendar( $initial, false ) );
  61. echo '</div><!-- .calendar-wrap -->';
  62. /* Close the theme's widget wrapper. */
  63. echo $after_widget;
  64. }
  65. /**
  66. * Updates the widget control options for the particular instance of the widget.
  67. *
  68. * @since 0.6.0
  69. */
  70. function update( $new_instance, $old_instance ) {
  71. $instance['title'] = strip_tags( $new_instance['title'] );
  72. $instance['initial'] = ( isset( $new_instance['initial'] ) ? 1 : 0 );
  73. return $instance;
  74. }
  75. /**
  76. * Displays the widget control options in the Widgets admin screen.
  77. *
  78. * @since 0.6.0
  79. */
  80. function form( $instance ) {
  81. /* Set up the default form values. */
  82. $defaults = array(
  83. 'title' => esc_attr__( 'Calendar', 'hybrid-core' ),
  84. 'initial' => false
  85. );
  86. /* Merge the user-selected arguments with the defaults. */
  87. $instance = wp_parse_args( (array) $instance, $defaults ); ?>
  88. <div class="hybrid-widget-controls columns-1">
  89. <p>
  90. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'hybrid-core' ); ?></label>
  91. <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'] ); ?>" />
  92. </p>
  93. <p>
  94. <input class="checkbox" type="checkbox" <?php checked( $instance['initial'], true ); ?> id="<?php echo $this->get_field_id( 'initial' ); ?>" name="<?php echo $this->get_field_name( 'initial' ); ?>" />
  95. <label for="<?php echo $this->get_field_id( 'initial' ); ?>"><?php _e( 'One-letter abbreviation?', 'hybrid-core' ); ?> <code>initial</code></label>
  96. </p>
  97. </div>
  98. <?php
  99. }
  100. }
  101. ?>