PluginProbe
CoolClock / 4.3.9
CoolClock v4.3.9
4.3.9 4.3.8 trunk 0.1 2.0 2.9.8 3.0 3.1 3.2 3.3 4.0 4.1 4.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7
coolclock / includes / class-coolclock-widget.php

class-coolclock-widget.php in CoolClock 4.3.9, at includes/class-coolclock-widget.php

320 lines 15.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * CoolClock Widget Class
4 */
5
6 class CoolClock_Widget extends WP_Widget {
7
8 /** PHP5+ constructor */
9 public function __construct() {
10 parent::__construct(
11 'coolclock-widget',
12 __('Analog Clock', 'coolclock'),
13 array(
14 'classname' => 'coolclock',
15 'description' => __('Add an analog clock to your sidebar.', 'coolclock')
16 ),
17 array(
18 'width' => 300,
19 'id_base' => 'coolclock-widget'
20 )
21 );
22 }
23
24 /** @see WP_Widget::widget -- do not rename this */
25 public function widget( $args, $instance ) {
26 extract( $args );
27
28 $defaults = array_merge( array('title'=>'','custom_skin'=>''), CoolClock::$defaults, CoolClock::$advanced_defaults );
29
30 // backward compat
31 if ( isset($instance['digitalcolor']) && !isset($instance['fontcolor']) ) $instance['fontcolor'] = $instance['digitalcolor'];
32
33 $title = !empty($instance['title']) ? apply_filters( 'widget_title', $instance['title'] ) : '';
34 //$number = $this->number;
35
36 // set footer script flags
37 CoolClock::$add_script = true;
38
39 // Print output
40 echo wp_kses_post( $before_widget );
41
42 if ( $title ) {
43 echo wp_kses_post( $before_title ) . esc_html( $title ) . wp_kses_post( $after_title );
44 }
45
46 // set skin
47 $instance['skin'] = CoolClock::parse_skin(
48 ! empty( $instance['skin'] ) ? $instance['skin'] : $defaults['skin'],
49 ! empty( $instance['custom_skin'] ) ? $instance['custom_skin'] : ''
50 );
51
52 // radius, used in wrapper style and coolclock fields
53 $instance['radius'] = !empty( $instance['radius'] ) && is_numeric( $instance['radius'] ) ? (int) $instance['radius'] : $defaults['radius'];
54 if ( 10 > $instance['radius'] ) $instance['radius'] = 10; // absolute minimum size 20x20
55
56 $align = !empty( $instance['align'] ) ? $instance['align'] : $defaults['align'];
57 $styles = array(
58 'width' => 2 * $instance['radius'] . 'px',
59 'height' => 'auto',
60 );
61 if ( in_array( $align, array('left','center') ) ) {
62 $styles['margin-right'] = 'auto';
63 if ( 'left' == $align ) $styles['margin-left'] = '0';
64 }
65 if ( in_array( $align, array('right','center') ) ) {
66 $styles['margin-left'] = 'auto';
67 if ( 'right' == $align ) $styles['margin-right'] = '0';
68 }
69 $styles = apply_filters( 'coolclock_container_styles', $styles, $instance, $defaults );
70
71 // Build output
72 // begin wrapper
73 $output = '<div class="coolclock-container"' . CoolClock::inline_style( $styles ) . '>';
74 // add canvas
75 $output .= CoolClock::canvas( $instance );
76 // end wrapper
77 $output .= '</div>';
78
79 // Print filtered output. wp_kses_post() strips <canvas>, so extend its
80 // allowed tags rather than using it directly (which would silently
81 // remove the clock).
82 $allowed_html = array_merge(
83 wp_kses_allowed_html( 'post' ),
84 array(
85 'canvas' => array(
86 'class' => true,
87 'style' => true,
88 'width' => true,
89 'height' => true,
90 ),
91 )
92 );
93 echo wp_kses( apply_filters( 'coolclock_widget', $output, $args, $instance ), $allowed_html );
94
95 echo wp_kses_post( $after_widget );
96 }
97
98 /** @see WP_Widget::update -- do not rename this */
99 public function update( $new_instance, $old_instance ) {
100 // parse custom skin code
101 $skin_array = !empty($new_instance['custom_skin']) ? CoolClock::skin_array( wp_strip_all_tags( $new_instance['custom_skin'] ) ) : array();
102
103 $instance['title'] = !empty($new_instance['title']) ? wp_strip_all_tags( $new_instance['title'] ) : '';
104 $instance['skin'] = !empty($new_instance['skin']) ? wp_strip_all_tags( $new_instance['skin'] ) : '';
105 $instance['custom_skin'] = !empty($skin_array) ? wp_json_encode( $skin_array ) : '';
106 $instance['radius'] = ( empty($new_instance['radius']) || (int) $new_instance['radius'] < 5 ) ? 5 : (int) $new_instance['radius'];
107 $instance['noseconds'] = !empty($new_instance['noseconds']) ? '1' : '';
108 $instance['gmtoffset'] = isset($new_instance['gmtoffset']) && $new_instance['gmtoffset'] !== '' ? (float) $new_instance['gmtoffset'] : '';
109 $instance['showdigital'] = !empty($new_instance['showdigital']) ? wp_strip_all_tags( $new_instance['showdigital'] ) : '';
110 $instance['fontcolor'] = !empty($new_instance['fontcolor']) ? CoolClock::colorval( $new_instance['fontcolor'] ) : '';
111 $instance['scale'] = !empty($new_instance['scale']) ? wp_strip_all_tags( $new_instance['scale'] ) : '';
112 $instance['align'] = !empty($new_instance['align']) ? wp_strip_all_tags( $new_instance['align'] ) : '';
113 $instance['subtext'] = wp_kses( $new_instance['subtext'], CoolClock::$allowed_tags );
114
115 return apply_filters( 'coolclock_widget_update_advanced', $instance, $new_instance );
116 }
117
118 /** @see WP_Widget::form -- do not rename this */
119 public function form( $instance ) {
120 $output = '';
121 $advanced = '';
122
123 // backward compat
124 if ( isset($instance['digitalcolor']) && !isset($instance['fontcolor']) ) $instance['fontcolor'] = $instance['digitalcolor'];
125
126 $defaults = array_merge( array('title'=>'','custom_skin'=>''), CoolClock::$defaults, CoolClock::$advanced_defaults );
127
128 $instance = wp_parse_args( (array) $instance, $defaults );
129
130 $title = esc_attr( $instance['title'] );
131 $subtext = esc_attr( $instance['subtext'] );
132 $custom_skin = esc_attr( $instance['custom_skin'] );
133
134 // Translatable skin names go here
135 $skin_names = array (
136 'swissrail' => __('Swiss Rail','coolclock'),
137 'chunkyswiss' => __('Chunky Swiss','coolclock'),
138 'chunkyswissonblack' => __('Chunky Swiss White','coolclock'),
139 'fancy' => __('Fancy','coolclock'),
140 'machine' => __('Machine','coolclock'),
141 'simonbaird_com' => __('SimonBaird.com','coolclock'),
142 'classic' => __('Classic by Bonstio','coolclock'),
143 'modern' => __('Modern by Bonstio','coolclock'),
144 'simple' => __('Simple by Bonstio','coolclock'),
145 'securephp' => __('SecurePHP','coolclock'),
146 'tes2' => __('Tes2','coolclock'),
147 'lev' => __('Lev','coolclock'),
148 'sand' => __('Sand','coolclock'),
149 'sun' => __('Sun','coolclock'),
150 'tor' => __('Tor','coolclock'),
151 'cold' => __('Cold','coolclock'),
152 'babosa' => __('Babosa','coolclock'),
153 'tumb' => __('Tumb','coolclock'),
154 'stone' => __('Stone','coolclock'),
155 'disc' => __('Disc','coolclock'),
156 'watermelon' => __('Watermelon by Yoo Nhe','coolclock'),
157 'mister' => __('Mister by Carl Lister','coolclock'),
158 'minimal' => __('Minimal','coolclock')
159 );
160
161 // Translatable type names go here
162 $type_names = array (
163 'linear' => __('Linear','coolclock'),
164 'logclock' => __('Logarithmic','coolclock'),
165 'logclockrev' => __('Logarithmic reversed','coolclock')
166 );
167
168 // Translatable show digital options go here
169 $showdigital_names = array (
170 '' => __( 'No', 'coolclock' ),
171 'digital12' => __('time (am/pm)','coolclock'),
172 'digital24' => __('time (24h)','coolclock'),
173 'date' => __('date','coolclock'),
174 'digital12+' => __('time + seconds (am/pm)','coolclock'),
175 'digital24+' => __('time + seconds (24h)','coolclock'),
176 'text' => __('custom text','coolclock')
177 );
178
179 // Title
180 $output .= '<style type="text/css">#available-widgets [class*=clock] .widget-title:before{content:"\f469"}</style>
181 <p><label for="' . $this->get_field_id('title') . '">' . __( 'Title:', 'coolclock' ) . '</label> ';
182 $output .= '<input class="widefat" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $title . '" /></p>';
183
184 // Clock settings
185 $output .= '<fieldset><legend>' . __('Clock', 'coolclock') . '</legend>';
186 $output .= '<p class="description"><a href="https://premium.status301.com/coolclock-widget-settings/" target="_blank">' . __('CoolClock widget instructions &raquo;', 'coolclock') . '</a></p>';
187
188 $output .= '<p><label for="' . $this->get_field_id('skin') . '">' . __('Skin:', 'coolclock') . '</label> ';
189 $output .= '<select class="select" id="' . $this->get_field_id('skin') . '" name="' . $this->get_field_name('skin') . '">';
190 $output .= '<option value="' . $defaults['skin'] . '" ' . selected( $defaults['skin'], $instance['skin'], false ) . '>';
191 $output .= ( isset($skin_names[$defaults['skin']]) ) ? $skin_names[$defaults['skin']] : $defaults['skin'];
192 $output .= '</option>';
193 foreach ( CoolClock::get_all_skins() as $skin => $parms ) {
194 $output .= '<option value="' . $skin . '" ' . selected( $skin, $instance['skin'], false ) . '>';
195 $output .= ( isset($skin_names[$skin]) ) ? $skin_names[$skin] : $skin;
196 $output .= '</option>';
197 }
198 $output .= '<option value="custom_' . $this->number . '" ' . selected( 'custom_'.$this->number, $instance['skin'], false ) . '>';
199 $output .= __('Custom (define below)', 'coolclock') . '</option></select></p>';
200
201 // Custom skin field
202 $output .= '<p><label for="' . $this->get_field_id('custom_skin') . '">' . __('Custom skin parameters:', 'coolclock') . '</label> ';
203 $output .= '<textarea class="widefat" id="' . $this->get_field_id('custom_skin') . '" name="' . $this->get_field_name('custom_skin') . '">' . $custom_skin . '</textarea></p>';
204
205 $output .= '<p class="description"><em>' . sprintf(
206 /* translators: %s: link to the JSON parameters documentation */
207 __( '(set Skin to Custom above, then add %s here)', 'coolclock' ),
208 '<a href="https://premium.status301.com/coolclock-custom-skin/" target="_blank">' . __( 'parameters in JSON format', 'coolclock' ) . '</a>'
209 ) . '</em></p>';
210
211 // Radius
212 $output .= '<p><label for="' . $this->get_field_id('radius') . '">' . __('Radius:', 'coolclock') . '</label> ';
213 $output .= '<input class="small-text" id="' . $this->get_field_id('radius') . '" name="' . $this->get_field_name('radius') . '" type="number" min="10" value="' . $instance['radius'] . '" /></p>';
214
215 // Second hand
216 $output .= '<p><input id="' . $this->get_field_id('noseconds') . '" name="' . $this->get_field_name('noseconds') . '" type="checkbox" value=';
217 $output .= ( $instance['noseconds'] ) ? '"true" checked="checked" />' : '"false" />';
218 $output .= ' <label for="' . $this->get_field_id('noseconds') . '">' . __('Hide second hand', 'coolclock') . '</label></p>';
219
220 // Align
221 $output .= '<p><label for="' . $this->get_field_id('align') . '">' . __('Align:', 'coolclock') . '</label> ';
222 $output .= '<select class="select" id="' . $this->get_field_id('align') . '" name="' . $this->get_field_name('align') . '">';
223 $output .= '<option value="">';
224 $output .= __( 'none', 'coolclock' ) . '</option>';
225 $output .= '<option value="left" ' . selected( $instance['align'], 'left', false ) . '>';
226 $output .= __('left', 'coolclock') . '</option>';
227 $output .= '<option value="right" ' . selected( $instance['align'], 'right', false ) . '>';
228 $output .= __('right', 'coolclock') . '</option>';
229 $output .= '<option value="center" ' . selected( $instance['align'], 'center', false ) . '>';
230 $output .= __('center', 'coolclock') . '</option>';
231 $output .= '</select></p>';
232
233 // Subtext
234 $output .= '<p><label for="' . $this->get_field_id('subtext') . '">' . __('Subtext:', 'coolclock') . '</label> ';
235 $output .= '<input class="widefat" id="' . $this->get_field_id('subtext') . '" name="' . $this->get_field_name('subtext') . '" type="text" value="' . $subtext . '" /> <span class="description"><em>' . __('(basic HTML allowed)', 'coolclock') . '</em></span></p>';
236
237 $output .= '</fieldset>'; //<div class="coolclock-advanced" style="background-color:rgba(0,0,0,.03);padding:1px 7px;border-radius:5px;margin-bottom:10px">';
238
239 $output .= '<fieldset><legend>' . __( 'Advanced', 'coolclock' ) . '</legend>';
240
241 // Use GMT offset
242 $output .= '<p><label for="' . $this->get_field_id('gmtoffset') . '">' . __('GMT offset:', 'coolclock') . '</label> ';
243 $output .= '<input class="small-text" id="' . $this->get_field_id('gmtoffset') . '" name="' . $this->get_field_name('gmtoffset') . '" type="number" step="0.5" value="' . $instance['gmtoffset'] . '" /> <span class="description"><em>' . __('(leave blank for visitor local time)', 'coolclock') . '</em></span></p>';
244
245 // Scale
246 $output .= '<p><label for="' . $this->get_field_id('scale') . '">' . __('Scale:', 'coolclock') . '</label> ';
247 $output .= '<select class="select" id="' . $this->get_field_id('scale') . '" name="' . $this->get_field_name('scale') . '">';
248 foreach ( CoolClock::$clock_types as $key => $value ) {
249 $output .= '<option value="' . $key . '" ' . selected( $key, strtolower($instance['scale']), false ) . '">';
250 $output .= ( isset($type_names[$key]) ) ? $type_names[$key] : $value;
251 $output .= '</option>';
252 }
253 $output .= '</select></p>';
254
255 // Show digital
256 if ( $instance['showdigital'] == 'true' || $instance['showdigital'] == '1' )
257 $instance['showdigital'] = 'digital12'; // backward compat
258
259 $output .= '<p><label for="' . $this->get_field_id('showdigital') . '">' . __('Show digital:', 'coolclock') . '</label> ';
260 $output .= '<select class="select" id="' . $this->get_field_id('showdigital') . '" name="' . $this->get_field_name('showdigital') . '">';
261 foreach ( CoolClock::$showdigital_options as $key => $value ) {
262 $output .= '<option value="' . $key . '" ' . selected( $key, $instance['showdigital'], false ) . '>';
263 $output .= ( isset($showdigital_names[$key]) ) ? $showdigital_names[$key] : $value;
264 $output .= '</option>';
265 }
266 $output .= '</select></p>';
267
268 $output .= '<p><label for="' . $this->get_field_id('fontcolor') . '">' . __('Digital font color:', 'coolclock') . '</label> ';
269 $output .= '<input id="' . $this->get_field_id('fontcolor') . '" name="' . $this->get_field_name('fontcolor') . '" type="text" value="' . $instance['fontcolor'] . '" /> <span class="description"><em>' . __('(use a valid HTML color code or name)', 'coolclock') . '</em></span></p>';
270 $output .= '</fieldset>';
271
272 $advanced .= '<p class="description"><a href="https://premium.status301.com/downloads/coolclock-advanced/">' . __('More digital font options &raquo;', 'coolclock') . '</a></p>
273 <fieldset><legend>' . __( 'Background', 'coolclock' ) . '</legend><p class="description"><a href="https://premium.status301.com/downloads/coolclock-advanced/">' . __('Available in the Advanced extension &raquo;', 'coolclock') . '</a></p></fieldset>';
274
275 // Advanced filter
276 $output .= apply_filters( 'coolclock_widget_form_advanced', $advanced, $this, $instance, $defaults );
277
278 $output .= '</div>';
279
280 if ( class_exists( 'CoolClockAdvanced' ) && isset(CoolClockAdvanced::$plugin_version) && version_compare( CoolClockAdvanced::$plugin_version, '7.1', '<' ) ) { // add an upgrade notice
281 $output .= '<div class="update-nag"><strong>' . __('Please upgrade the CoolClock - Advanced extension.', 'coolclock') . '</strong> '. ' <a href="https://premium.status301.com/account/" target="_blank">' . __('Please log in with your account credentials here.', 'coolclock') . '</a>' . __('You can download the new version using the link in the downloads list.', 'coolclock') . '</div>';
282 }
283
284 // wp_kses_post() strips form controls (input/select/option/textarea/style),
285 // which would silently break this settings screen. Extend the allowed
286 // tags with what an admin settings form actually needs instead.
287 $allowed_html = array_merge(
288 wp_kses_allowed_html( 'post' ),
289 array(
290 'style' => array( 'type' => true ),
291 'input' => array(
292 'id' => true,
293 'class' => true,
294 'name' => true,
295 'type' => true,
296 'value' => true,
297 'min' => true,
298 'step' => true,
299 'checked' => true,
300 ),
301 'select' => array(
302 'id' => true,
303 'class' => true,
304 'name' => true,
305 ),
306 'option' => array(
307 'value' => true,
308 'selected' => true,
309 ),
310 'textarea' => array(
311 'id' => true,
312 'class' => true,
313 'name' => true,
314 ),
315 )
316 );
317 echo wp_kses( $output, $allowed_html );
318 }
319 }
320