jigoshop /widgets/product_tag_cloud.php

Language PHP Lines 119
MD5 Hash fa3d9705350055b458de7906c8f6f751
Repository https://github.com/scottpoulin/jigoshop.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
 * Tag Cloud Widget
 *
 * DISCLAIMER
 *
 * Do not edit or add directly to this file if you wish to upgrade Jigoshop to newer
 * versions in the future. If you wish to customise Jigoshop core for your needs,
 * please use our GitHub repository to publish essential changes for consideration.
 *
 * @package             Jigoshop
 * @category            Widgets
 * @author              Jigoshop
 * @copyright           Copyright Š 2011-2013 Jigoshop.
 * @license             http://jigoshop.com/license/commercial-edition
 */

class Jigoshop_Widget_Tag_Cloud extends WP_Widget {

	/**
	 * Constructor
	 *
	 * Setup the widget with the available options
	 */
	public function __construct() {

		$options = array(
			'description' => __( "Your most used product tags in cloud format", 'jigoshop'),
		);

		// Create the widget
		parent::__construct('product_tag_cloud', __('Jigoshop: Product Tag Cloud', 'jigoshop'), $options);
	}

	/**
	 * Widget
	 *
	 * Display the widget in the sidebar
	 *
	 * @param	array	sidebar arguments
	 * @param	array	instance
	 */
	public function widget( $args, $instance ) {

		// Get the widget cache from the transient
		$cache = get_transient( 'jigoshop_widget_cache' );
		// If this tag cloud widget instance is cached, get from the cache
		if ( isset( $cache[$this->id] ) ) {
			echo $cache[$this->id];
			return false;
		}

		// Otherwise Start buffering and output the Widget
		ob_start();

		// Extract the widget arguments
		extract($args);

		// Set the widget title
		$title = ( ! empty($instance['title']) ) ? $instance['title'] : __('Product Tags', 'jigoshop');
		$title = apply_filters('widget_title', $title, $instance, $this->id_base);

		// Print the widget wrapper & title
		echo $before_widget;
		echo $before_title . $title . $after_title;

		// Print tag cloud with wrapper
		echo '<div class="tagcloud">';
		wp_tag_cloud( apply_filters('widget_tag_cloud_args', array('taxonomy' => 'product_tag') ) );
		echo "</div>\n";

		// Print closing widget wrapper
		echo $after_widget;

		// Flush output buffer and save to transient cache
		$result = ob_get_flush();
		$cache[$this->id] = $result;
		set_transient( 'jigoshop_widget_cache', $cache, 3600*3 ); // 3 hours ahead
	}

	/**
	 * Update
	 *
	 * Handles the processing of information entered in the wordpress admin
	 *
	 * @param	array	new instance
	 * @param	array	old instance
	 * @return	array	instance
	 */
	public function update( $new_instance, $old_instance ) {
		$instance = $old_instance;

		// Save new values
		$instance['title'] = strip_tags(stripslashes($new_instance['title']));
		$instance['taxonomy'] = stripslashes(isset($new_instance['taxonomy']) ? $new_instance['taxonomy'] : '');

		return $instance;
	}

	/**
	 * Form
	 *
	 * Displays the form for the wordpress admin
	 *
	 * @param	array	instance
	 */
	public function form( $instance ) {
		$title = (isset($instance['title'])) ? esc_attr($instance['title']) : null;

		// Widget title
		?>
		<p>
			<label for="<?php echo esc_attr( $this->get_field_id('title') ); ?>"><?php _e('Title:', 'jigoshop'); ?></label>
			<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 ); ?>" />
		</p>
		<?php
	}

} // class Jigoshop_Widget_Tag_Cloud
Back to Top