PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/widgets/product_tag_cloud.php

https://github.com/ThemesWpFr/jigoshop
PHP | 119 lines | 44 code | 19 blank | 56 comment | 1 complexity | 6760dd066ccb24226bd3ac43c15987a1 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * Tag Cloud Widget
  4. *
  5. * DISCLAIMER
  6. *
  7. * Do not edit or add directly to this file if you wish to upgrade Jigoshop to newer
  8. * versions in the future. If you wish to customise Jigoshop core for your needs,
  9. * please use our GitHub repository to publish essential changes for consideration.
  10. *
  11. * @package Jigoshop
  12. * @category Widgets
  13. * @author Jigowatt
  14. * @copyright Copyright Š 2011-2012 Jigowatt Ltd.
  15. * @license http://jigoshop.com/license/commercial-edition
  16. */
  17. class Jigoshop_Widget_Tag_Cloud extends WP_Widget {
  18. /**
  19. * Constructor
  20. *
  21. * Setup the widget with the available options
  22. */
  23. public function __construct() {
  24. $options = array(
  25. 'description' => __( "Your most used product tags in cloud format", 'jigoshop'),
  26. );
  27. // Create the widget
  28. parent::__construct('product_tag_cloud', __('Jigoshop: Product Tag Cloud', 'jigoshop'), $options);
  29. }
  30. /**
  31. * Widget
  32. *
  33. * Display the widget in the sidebar
  34. *
  35. * @param array sidebar arguments
  36. * @param array instance
  37. */
  38. public function widget( $args, $instance ) {
  39. // Get the widget cache from the transient
  40. $cache = get_transient( 'jigoshop_widget_cache' );
  41. // If this tag cloud widget instance is cached, get from the cache
  42. if ( isset( $cache[$this->id] ) ) {
  43. echo $cache[$this->id];
  44. return false;
  45. }
  46. // Otherwise Start buffering and output the Widget
  47. ob_start();
  48. // Extract the widget arguments
  49. extract($args);
  50. // Set the widget title
  51. $title = ( ! empty($instance['title']) ) ? $instance['title'] : __('Product Tags', 'jigoshop');
  52. $title = apply_filters('widget_title', $title, $instance, $this->id_base);
  53. // Print the widget wrapper & title
  54. echo $before_widget;
  55. echo $before_title . $title . $after_title;
  56. // Print tag cloud with wrapper
  57. echo '<div class="tagcloud">';
  58. wp_tag_cloud( apply_filters('widget_tag_cloud_args', array('taxonomy' => 'product_tag') ) );
  59. echo "</div>\n";
  60. // Print closing widget wrapper
  61. echo $after_widget;
  62. // Flush output buffer and save to transient cache
  63. $result = ob_get_flush();
  64. $cache[$this->id] = $result;
  65. set_transient( 'jigoshop_widget_cache', $cache, 3600*3 ); // 3 hours ahead
  66. }
  67. /**
  68. * Update
  69. *
  70. * Handles the processing of information entered in the wordpress admin
  71. *
  72. * @param array new instance
  73. * @param array old instance
  74. * @return array instance
  75. */
  76. public function update( $new_instance, $old_instance ) {
  77. $instance = $old_instance;
  78. // Save new values
  79. $instance['title'] = strip_tags(stripslashes($new_instance['title']));
  80. $instance['taxonomy'] = stripslashes(isset($new_instance['taxonomy']) ? $new_instance['taxonomy'] : '');
  81. return $instance;
  82. }
  83. /**
  84. * Form
  85. *
  86. * Displays the form for the wordpress admin
  87. *
  88. * @param array instance
  89. */
  90. public function form( $instance ) {
  91. $title = (isset($instance['title'])) ? esc_attr($instance['title']) : null;
  92. // Widget title
  93. ?>
  94. <p>
  95. <label for="<?php echo esc_attr( $this->get_field_id('title') ); ?>"><?php _e('Title:', 'jigoshop'); ?></label>
  96. <input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id('title') ); ?>" name="<?php echo esc_attr( $this->get_field_name('title') ); ?>" value="<?php echo esc_attr( $title ); ?>" />
  97. </p>
  98. <?php
  99. }
  100. } // class Jigoshop_Widget_Tag_Cloud