PluginProbe
Powerkit – Supercharge your WordPress Site / 2.3.8
Powerkit – Supercharge your WordPress Site v2.3.8
3.1.1 3.1.0 3.0.9 3.0.8 trunk 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 All 87 releases
powerkit / modules / twitter / public / class-powerkit-twitter-widget.php

class-powerkit-twitter-widget.php in Powerkit – Supercharge your WordPress Site 2.3.8, at modules/twitter/public/class-powerkit-twitter-widget.php

173 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Widget Twitter
4 *
5 * @link https://codesupply.co
6 * @since 1.0.0
7 *
8 * @package PowerKit
9 * @subpackage PowerKit/widgets
10 */
11
12 /**
13 * Widget Twitter Class
14 */
15 class Powerkit_Twitter_Widget extends WP_Widget {
16
17 /**
18 * Sets up a new widget instance.
19 */
20 public function __construct() {
21
22 $cache_timeout = (int) apply_filters( 'powerkit_twitter_cache_timeout', 60 );
23
24 $this->default_settings = apply_filters( 'powerkit_twitter_widget_settings', array(
25 'title' => esc_html__( 'Twitter Feed', 'powerkit' ),
26 'username' => '',
27 'number' => 5,
28 'template' => 'default',
29 'header' => true,
30 'button' => true,
31 'retweets' => false,
32 'replies' => false,
33 'cache_time' => $cache_timeout,
34 ) );
35
36 $widget_details = array(
37 'classname' => 'powerkit_twitter_widget',
38 'description' => esc_html__( 'A list of recent tweets.', 'powerkit' ),
39 );
40 parent::__construct( 'powerkit_twitter_widget', esc_html__( 'Twitter Feed', 'powerkit' ), $widget_details );
41 }
42
43 /**
44 * Outputs the content for the current widget instance.
45 *
46 * @param array $args Display arguments including 'before_title', 'after_title',
47 * 'before_widget', and 'after_widget'.
48 * @param array $instance Settings for the current widget instance.
49 */
50 public function widget( $args, $instance ) {
51 $params = array_merge( $this->default_settings, $instance );
52
53 // Before Widget.
54 echo $args['before_widget']; // XSS OK.
55 ?>
56
57 <div class="widget-body">
58 <?php
59 // Title.
60 if ( $params['title'] ) {
61 echo $args['before_title'] . apply_filters( 'widget_title', $params['title'], $instance, $this->id_base ) . $args['after_title']; // XSS.
62 }
63
64 powerkit_twitter_get_recent( $params, 'powerkit_twitter_widget_cache' );
65 ?>
66 </div>
67
68 <?php
69
70 // After Widget.
71 echo $args['after_widget']; // XSS OK.
72 }
73
74 /**
75 * Handles updating settings for the current widget instance.
76 *
77 * @param array $new_instance New settings for this instance as input by the user via
78 * WP_Widget::form().
79 * @param array $old_instance Old settings for this instance.
80 * @return array Settings to save or bool false to cancel saving.
81 */
82 public function update( $new_instance, $old_instance ) {
83 $instance = $new_instance;
84
85 // Display header.
86 if ( ! isset( $instance['header'] ) ) {
87 $instance['header'] = false;
88 }
89
90 // Display follow button.
91 if ( ! isset( $instance['button'] ) ) {
92 $instance['button'] = false;
93 }
94
95 // Include retweets.
96 if ( ! isset( $instance['retweets'] ) ) {
97 $instance['retweets'] = false;
98 }
99
100 // Include replies.
101 if ( ! isset( $instance['replies'] ) ) {
102 $instance['replies'] = false;
103 }
104
105 return $instance;
106 }
107
108 /**
109 * Outputs the widget settings form.
110 *
111 * @param array $instance Current settings.
112 */
113 public function form( $instance ) {
114 $params = array_merge( $this->default_settings, $instance );
115
116 $templates = apply_filters( 'powerkit_twitter_templates', array() );
117 ?>
118 <!-- Title -->
119 <p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'powerkit' ); ?></label>
120 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $params['title'] ); ?>" /></p>
121
122 <!-- Twitter User ID -->
123 <p><label for="<?php echo esc_attr( $this->get_field_id( 'username' ) ); ?>"><?php esc_html_e( 'Twitter user ID:', 'powerkit' ); ?></label>
124 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'username' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'username' ) ); ?>" type="text" value="<?php echo esc_attr( $params['username'] ); ?>" /></p>
125
126 <!-- Number of Tweets -->
127 <p><label for="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>"><?php esc_html_e( 'Number of tweets to display:', 'powerkit' ); ?></label>
128 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'number' ) ); ?>" type="number" value="<?php echo esc_attr( $params['number'] ); ?>" /></p>
129
130 <!-- Template -->
131 <?php if ( count( (array) $templates ) > 1 ) : ?>
132 <p><label for="<?php echo esc_attr( $this->get_field_id( 'Template' ) ); ?>"><?php esc_html_e( 'Template:', 'powerkit' ); ?></label>
133 <select name="<?php echo esc_attr( $this->get_field_name( 'template' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id( 'template' ) ); ?>" class="widefat">
134 <?php
135 if ( $templates ) {
136 foreach ( $templates as $key => $item ) {
137 ?>
138 <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $params['template'], $key ); ?>><?php echo esc_attr( $item['name'] ); ?></option>
139 <?php
140 }
141 }
142 ?>
143 </select>
144 </p>
145 <?php endif; ?>
146
147 <!-- Display header -->
148 <p><input id="<?php echo esc_attr( $this->get_field_id( 'header' ) ); ?>" class="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'header' ) ); ?>" type="checkbox" <?php checked( (bool) $params['header'] ); ?> />
149 <label for="<?php echo esc_attr( $this->get_field_id( 'header' ) ); ?>"><?php esc_html_e( 'Display header', 'powerkit' ); ?></label></p>
150
151 <!-- Display follow button -->
152 <p><input id="<?php echo esc_attr( $this->get_field_id( 'button' ) ); ?>" class="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'button' ) ); ?>" type="checkbox" <?php checked( (bool) $params['button'] ); ?> />
153 <label for="<?php echo esc_attr( $this->get_field_id( 'button' ) ); ?>"><?php esc_html_e( 'Display follow button', 'powerkit' ); ?></label></p>
154
155 <!-- Display header -->
156 <p><input id="<?php echo esc_attr( $this->get_field_id( 'retweets' ) ); ?>" class="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'retweets' ) ); ?>" type="checkbox" <?php checked( (bool) $params['retweets'] ); ?> />
157 <label for="<?php echo esc_attr( $this->get_field_id( 'retweets' ) ); ?>"><?php esc_html_e( 'Include retweets', 'powerkit' ); ?></label></p>
158
159 <!-- Display follow button -->
160 <p><input id="<?php echo esc_attr( $this->get_field_id( 'replies' ) ); ?>" class="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'replies' ) ); ?>" type="checkbox" <?php checked( (bool) $params['replies'] ); ?> />
161 <label for="<?php echo esc_attr( $this->get_field_id( 'replies' ) ); ?>"><?php esc_html_e( 'Include replies', 'powerkit' ); ?></label></p>
162 <?php
163 }
164 }
165
166 /**
167 * Register Widget
168 */
169 function powerkit_widget_init_twitter() {
170 register_widget( 'Powerkit_Twitter_Widget' );
171 }
172 add_action( 'widgets_init', 'powerkit_widget_init_twitter' );
173