PluginProbe
CoolClock / 3.2
CoolClock v3.2
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
← All changes | coolclock.php +490 -20 trunk3.2 View file →
@@ -1,32 +1,502 @@
1 1 <?php
2 2 /*
3 3 Plugin Name: CoolClock
4 -Plugin URI: https://status301.net/wordpress-plugins/coolclock/
5 -Description: An analog clock for your site.
4 +Plugin URI: http://status301.net/wordpress-plugins/coolclock/
5 +Description: Add an analog clock to your sidebar.
6 6 Text Domain: coolclock
7 -Domain Path: /languages
8 -Requires at least: 5.8
9 -Version: 4.3.8
7 +Domain Path: languages
8 +Version: 3.2
10 9 Author: RavanH
11 -Author URI: https://status301.net/
12 -License: GPL-2.0-or-later
13 -License URI: https://www.gnu.org/licenses/gpl-2.0.html
10 +Author URI: http://status301.net/
14 11 */
15 12
16 -if ( ! defined( 'ABSPATH' ) ) exit;
13 +/**
14 + * CoolClock Class
15 + */
16 +class CoolClock {
17 17
18 -define( 'COOLCLOCK_DIR', plugin_dir_path(__FILE__) );
18 + static $plugin_version = '3.2';
19 19
20 -/**************
21 - * CLASSES
22 - **************/
20 + static $script_version = '3.0.0';
23 21
24 -require COOLCLOCK_DIR . 'includes/class-coolclock.php';
25 -require COOLCLOCK_DIR . 'includes/class-coolclock-widget.php';
26 -require COOLCLOCK_DIR . 'includes/class-coolclock-shortcode.php';
22 + static $add_script;
27 23
28 -/**************
29 - * INITIATE
30 - **************/
24 + static $add_moreskins;
25 +
26 + static $done_excanvas = false;
31 27
32 -new CoolClock( __FILE__, '4.3.8' );
28 + static $defaults = array (
29 + 'skin' => 'swissRail',
30 + 'radius' => 100,
31 + 'noseconds' => false, // Hide seconds
32 + 'gmtoffset' => '', // GMT offset
33 + 'showdigital' => '', // Show digital time or date
34 + 'scale' => 'linear' // Define type of clock linear/logarithmic/log reversed
35 + );
36 +
37 + static $showdigital_options = array (
38 + '' => '',
39 + 'digital12' => 'showDigital'
40 + );
41 +
42 + static $advanced;
43 +
44 + static $advanced_defaults = array (
45 + 'subtext' => '',
46 + 'align' => 'center'
47 + );
48 +
49 + static $default_skins = array (
50 + 'swissRail', // plugin default
51 + 'chunkySwiss', // script default
52 + 'chunkySwissOnBlack'
53 + );
54 +
55 + static $more_skins = array (
56 + 'fancy',
57 + 'machine',
58 + 'simonbaird_com',
59 + 'classic',
60 + 'modern',
61 + 'simple',
62 + 'securephp',
63 + 'Tes2',
64 + 'Lev',
65 + 'Sand',
66 + 'Sun',
67 + 'Tor',
68 + 'Cold',
69 + 'Babosa',
70 + 'Tumb',
71 + 'Stone',
72 + 'Disc',
73 + 'watermelon',
74 + 'mister'
75 + );
76 +
77 + static $advanced_skins = array ();
78 +
79 + static $advanced_skins_config = array ();
80 +
81 + static $clock_types = array (
82 + 'linear' => '',
83 + 'logClock' => 'logClock',
84 + 'logClockRev' => 'logClockRev'
85 + );
86 +
87 + /**
88 + * MAIN
89 + */
90 +
91 + static function canvas( $atts )
92 + {
93 + extract( $atts );
94 +
95 + $output = '<div';
96 +
97 + // align class ans style
98 + $output .= ( $align ) ? ' class="align' . $align . '"' : '';
99 + $output .= ' style="width:' . 2 * $radius . 'px;max-width:100%;height:auto">';
100 + // canvas parameters
101 + $output .= '<canvas class="CoolClock:' . $skin . ':' . $radius . ':';
102 + $output .= ( $noseconds == 'true' || $noseconds == '1' ) ? 'noSeconds:' : ':';
103 + $output .= $gmtoffset;
104 +
105 + // show digital
106 + if ( $showdigital == 'true' || $showdigital == '1' )
107 + $showdigital = 'digital12'; // backward compat
108 +
109 + if ( isset(self::$showdigital_options[$showdigital]) )
110 + $output .= ':'.self::$showdigital_options[$showdigital];
111 + else
112 + $output .= ':';
113 +
114 + // set type
115 + if ( isset(self::$clock_types[$scale]) )
116 + $output .= ':'.self::$clock_types[$scale];
117 + else
118 + $output .= ':';
119 +
120 + $output .= '"></canvas>';
121 + $output .= ( $subtext ) ? '<div style="width:100%;text-align:center;padding-bottom:10px">' . $subtext . '</div></div>' : '</div>';
122 +
123 + // before returning, try including excanvas which needs to be there before the first canvas...
124 + self::print_excanvas();
125 +
126 + return $output;
127 + }
128 +
129 + static function print_excanvas()
130 + {
131 + if ( self::$done_excanvas )
132 + return;
133 +
134 + echo '<!--[if lte IE 8]>';
135 + wp_print_scripts( 'excanvas' );
136 + echo '<![endif]-->
137 +';
138 + self::$done_excanvas = true;
139 + }
140 +
141 + static function print_scripts()
142 + {
143 + if ( ! self::$add_script )
144 + return;
145 +
146 + wp_print_scripts( 'coolclock' );
147 +
148 + if ( self::$add_moreskins )
149 + wp_print_scripts('coolclock-moreskins');
150 +
151 + if ( is_array( self::$advanced_skins_config ) && !empty( self::$advanced_skins_config ) ) {
152 + echo '<script type="text/javascript">jQuery.extend(CoolClock.config.skins, {
153 +';
154 + // loop through plugin custom skins
155 + foreach (self::$advanced_skins_config as $key => $value)
156 + echo $key.':{'.$value.'},
157 +';
158 + echo '});</script>
159 +';
160 + }
161 + }
162 +
163 + /**
164 + * SCRIPTS
165 + */
166 +
167 + static function register_scripts()
168 + {
169 + $min = defined('WP_DEBUG') && WP_DEBUG ? '.min' : '';
170 +
171 + wp_register_script( 'coolclock', plugins_url( "/js/coolclock{$min}.js", __FILE__ ), array('jquery'), self::$script_version, true );
172 + wp_register_script( 'coolclock-moreskins', plugins_url( "/js/moreskins{$min}.js", __FILE__ ), array('coolclock'), self::$script_version, true );
173 + wp_register_script( 'excanvas', plugins_url( "/js/excanvas{$min}.js", __FILE__ ), array(), '73', true );
174 +
175 + }
176 +
177 + /**
178 + * SHORTCODE
179 + */
180 +
181 + static function handle_shortcode( $atts, $content = null )
182 + {
183 + if ( is_feed() )
184 + return '';
185 +
186 + $atts = shortcode_atts( array_merge( self::$defaults, self::$advanced_defaults ), $atts );
187 +
188 + // set footer script flags
189 + self::$add_script = true;
190 +
191 + if ( !isset( $atts['skin'] ) )
192 + $atts['skin'] = self::$defaults['skin'];
193 +
194 + if ( in_array( $atts['skin'], self::$more_skins ) )
195 + self::$add_moreskins = true;
196 +
197 + // get output
198 + $output = self::canvas( $atts );
199 +
200 + return apply_filters( 'coolclock_shortcode_advanced', $output, $atts, $content );
201 + }
202 +
203 + static function no_wptexturize($shortcodes)
204 + {
205 + $shortcodes[] = 'coolclock';
206 + return $shortcodes;
207 + }
208 +
209 + /**
210 + * WIDGET
211 + */
212 +
213 + static function widget( $args, $instance, $number )
214 + {
215 + $skin = ( isset( $instance['skin'] ) )
216 + ? $instance['skin'] : self::$defaults['skin'];
217 +
218 + // add custom skin parameters to the plugin skins array
219 + if ( 'custom_'.$number == $skin )
220 + self::$advanced_skins_config[$skin] = wp_strip_all_tags( $instance['custom_skin'], true );
221 +
222 + // set footer script flags
223 + self::$add_script = true;
224 +
225 + if ( in_array( $skin, self::$more_skins ) )
226 + self::$add_moreskins = true;
227 +
228 + $output = self::canvas( array(
229 + 'skin' => $skin,
230 + 'radius' => $instance['radius'],
231 + 'noseconds' => $instance['noseconds'],
232 + 'gmtoffset' => $instance['gmtoffset'],
233 + 'showdigital' => $instance['showdigital'],
234 + 'scale' => $instance['scale'],
235 + 'align' => $instance['align'],
236 + 'subtext' => apply_filters('widget_text', $instance['subtext'], $instance)
237 + ) );
238 +
239 + return apply_filters( 'coolclock_widget_advanced', $output, $args, $instance );
240 + }
241 +
242 + static function update( $new_instance, $instance )
243 + {
244 + $instance['title'] = strip_tags( $new_instance['title'] );
245 + $instance['skin'] = strip_tags( $new_instance['skin'] );
246 + $instance['custom_skin'] = strip_tags( $new_instance['custom_skin'] );
247 + $instance['radius'] = ( (int) $new_instance['radius'] < 5 ) ? 5 : (int) $new_instance['radius'];
248 + $instance['noseconds'] = (bool) $new_instance['noseconds'];
249 + $instance['gmtoffset'] = ( $new_instance['gmtoffset'] == '' ) ? '' : (float) $new_instance['gmtoffset'];
250 + $instance['showdigital'] = strip_tags( $new_instance['showdigital'] );
251 + $instance['scale'] = strip_tags( $new_instance['scale'] );
252 + $instance['align'] = strip_tags( $new_instance['align'] );
253 +
254 + if ( current_user_can('unfiltered_html') )
255 + $instance['subtext'] = $new_instance['subtext'];
256 + else
257 + // wp_filter_post_kses() expects slashed
258 + $instance['subtext'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['subtext']) ) );
259 +
260 +
261 + return apply_filters( 'coolclock_widget_update_advanced', $instance, $new_instance );
262 + }
263 +
264 + static function form( $obj, $instance, $defaults = array('title'=>'','custom_skin'=>'') )
265 + {
266 + $defaults = array_merge( $defaults, self::$defaults, self::$advanced_defaults );
267 +
268 + $instance = wp_parse_args( (array) $instance, $defaults );
269 +
270 + $title = esc_attr( $instance['title'] );
271 + $subtext = esc_attr( $instance['subtext'] );
272 + $custom_skin = esc_attr( $instance['custom_skin'] );
273 +
274 + // Translatable skin names go here
275 + $skin_names = array (
276 + 'swissRail' => __('Swiss Rail','coolclock'),
277 + 'chunkySwiss' => __('Chunky Swiss','coolclock'),
278 + 'chunkySwissOnBlack' => __('Chunky Swiss Black','coolclock'),
279 + 'fancy' => __('Fancy','coolclock'),
280 + 'machine' => __('Machine','coolclock'),
281 + 'simonbaird_com' => __('SimonBaird.com','coolclock'),
282 + 'classic' => __('Classic by Bonstio','coolclock'),
283 + 'modern' => __('Modern by Bonstio','coolclock'),
284 + 'simple' => __('Simple by Bonstio','coolclock'),
285 + 'securephp' => __('SecurePHP','coolclock'),
286 + 'Tes2' => __('Tes2','coolclock'),
287 + 'Lev' => __('Lev','coolclock'),
288 + 'Sand' => __('Sand','coolclock'),
289 + 'Sun' => __('Sun','coolclock'),
290 + 'Tor' => __('Tor','coolclock'),
291 + 'Cold' => __('Cold','coolclock'),
292 + 'Babosa' => __('Babosa','coolclock'),
293 + 'Tumb' => __('Tumb','coolclock'),
294 + 'Stone' => __('Stone','coolclock'),
295 + 'Disc' => __('Disc','coolclock'),
296 + 'watermelon' => __('Watermelon by Yoo Nhe','coolclock'),
297 + 'mister' => __('Mister by Carl Lister','coolclock'),
298 + 'minimal' => __('Minimal','coolclock')
299 + );
300 +
301 + $skins = array_merge( self::$default_skins, self::$more_skins, self::$advanced_skins );
302 +
303 + // Translatable type names go here
304 + $type_names = array (
305 + 'linear' => __('Linear','coolclock'),
306 + 'logClock' => __('Logarithmic','coolclock'),
307 + 'logClockRev' => __('Logarithmic reversed','coolclock')
308 + );
309 +
310 + // Translatable show options go here
311 + $showdigital_names = array (
312 + '' => __('none','coolclock'),
313 + 'digital12' => __('time (am/pm)','coolclock'),
314 + 'digital24' => __('time (24h)','coolclock'),
315 + 'date' => __('date','coolclock')
316 + );
317 +
318 + // Misc translations
319 + $stray = array(
320 + 'extra_settings' => __('Extra settings for the CoolClock widget.', 'coolclock')
321 + );
322 +
323 + // Title
324 + $output = '<p><label for="' . $obj->get_field_id('title') . '">' . __('Title:') . '</label> ';
325 + $output .= '<input class="widefat" id="' . $obj->get_field_id('title') . '" name="' . $obj->get_field_name('title') . '" type="text" value="' . $title . '" /></p>';
326 +
327 + // Clock settings
328 + $output .= '<p><strong>' . __('Clock', 'coolclock') . '</strong></p>';
329 + $output .= '<p><label for="' . $obj->get_field_id('skin') . '">' . __('Skin:', 'coolclock') . '</label> ';
330 + $output .= '<select class="select" id="' . $obj->get_field_id('skin') . '" name="' . $obj->get_field_name('skin') . '">';
331 + foreach ($skins as $value) {
332 + $output .= '<option value="' . $value . '"';
333 + $output .= ( $value == $instance['skin'] ) ? ' selected="selected">' : '>';
334 + $output .= ( isset($skin_names[$value]) ) ? $skin_names[$value] : $value;
335 + $output .= '</option>';
336 + } unset($value);
337 + $output .= '<option value="custom_' . $obj->number . '"';
338 + $output .= ( 'custom_'.$obj->number == $instance['skin'] ) ? ' selected="selected">' : '>';
339 + $output .= __('Custom (define below)', 'coolclock') . '</option></select></p>';
340 +
341 + // Custom skin field
342 + $output .= '<p><label for="' . $obj->get_field_id('custom_skin') . '">' . __('Custom skin parameters:', 'coolclock') . '</label> ';
343 + $output .= '<textarea class="widefat" id="' . $obj->get_field_id('custom_skin') . '" name="' . $obj->get_field_name('custom_skin') . '">' . $custom_skin . '</textarea></p>';
344 +
345 + // Radius
346 + $output .= '<p><label for="' . $obj->get_field_id('radius') . '">' . __('Radius:', 'coolclock') . '</label> ';
347 + $output .= '<input class="small-text" id="' . $obj->get_field_id('radius') . '" name="' . $obj->get_field_name('radius') . '" type="number" min="10" value="' . $instance['radius'] . '" /></p>';
348 +
349 + // Second hand
350 + $output .= '<p><input id="' . $obj->get_field_id('noseconds') . '" name="' . $obj->get_field_name('noseconds') . '" type="checkbox" value=';
351 + $output .= ( $instance['noseconds'] ) ? '"true" checked="checked" />' : '"false" />';
352 + $output .= ' <label for="' . $obj->get_field_id('noseconds') . '">' . __('Hide second hand', 'coolclock') . '</label></p>';
353 +
354 + // Show digital
355 + if ( $instance['showdigital'] == 'true' || $instance['showdigital'] == '1' )
356 + $instance['showdigital'] = 'digital12'; // backward compat
357 +
358 + $output .= '<p><label for="' . $obj->get_field_id('showdigital') . '">' . __('Show digital:', 'coolclock') . '</label> ';
359 + $output .= '<select class="select" id="' . $obj->get_field_id('showdigital') . '" name="' . $obj->get_field_name('showdigital') . '">';
360 + foreach (self::$showdigital_options as $key => $value) {
361 + $output .= '<option value="' . $key . '"';
362 + $output .= ( $key == $instance['showdigital'] ) ? ' selected="selected">' : '>';
363 + $output .= ( isset($showdigital_names[$key]) ) ? $showdigital_names[$key] : $value;
364 + $output .= '</option>';
365 + } unset($value);
366 + $output .= '</select></p>';
367 +
368 + // USe GMT offset
369 + $output .= '<p><label for="' . $obj->get_field_id('gmtoffset') . '">' . __('GMT offset:', 'coolclock') . '</label> ';
370 + $output .= '<input class="small-text" id="' . $obj->get_field_id('gmtoffset') . '" name="' . $obj->get_field_name('gmtoffset') . '" type="number" step="0.5" value="' . $instance['gmtoffset'] . '" /> ' . __('(leave blank for local time)', 'coolclock') . '</p>';
371 +
372 + // Scale
373 + $output .= '<p><label for="' . $obj->get_field_id('scale') . '">' . __('Scale:', 'coolclock') . '</label> ';
374 + $output .= '<select class="select" id="' . $obj->get_field_id('scale') . '" name="' . $obj->get_field_name('scale') . '">';
375 + foreach (self::$clock_types as $key => $value) {
376 + $output .= '<option value="' . $key . '"';
377 + $output .= ( $key == $instance['scale'] ) ? ' selected="selected">' : '>';
378 + $output .= ( isset($type_names[$key]) ) ? $type_names[$key] : $value;
379 + $output .= '</option>';
380 + } unset($value);
381 + $output .= '</select></p>';
382 +
383 + // Align
384 + $output .= '<p><label for="' . $obj->get_field_id('align') . '">' . __('Align:', 'coolclock') . '</label> ';
385 + $output .= '<select class="select" id="' . $obj->get_field_id('align') . '" name="' . $obj->get_field_name('align') . '">';
386 + $output .= '<option value=""';
387 + $output .= ( $instance['align'] == '' ) ? ' selected="selected">' : '>';
388 + $output .= __('none', 'coolclock') . '</option>';
389 + $output .= '<option value="left"';
390 + $output .= ( $instance['align'] == 'left' ) ? ' selected="selected">' : '>';
391 + $output .= __('left', 'coolclock') . '</option>';
392 + $output .= '<option value="right"';
393 + $output .= ( $instance['align'] == 'right' ) ? ' selected="selected">' : '>';
394 + $output .= __('right', 'coolclock') . '</option>';
395 + $output .= '<option value="center"';
396 + $output .= ( $instance['align'] == 'center' ) ? ' selected="selected">' : '>';
397 + $output .= __('center', 'coolclock') . '</option>';
398 + $output .= '</select></p>';
399 +
400 + // Subtext
401 + $output .= '<p><label for="' . $obj->get_field_id('subtext') . '">' . __('Subtext:', 'coolclock') . '</label> ';
402 + $output .= '<input class="widefat" id="' . $obj->get_field_id('subtext') . '" name="' . $obj->get_field_name('subtext') . '" type="text" value="' . $subtext . '" /> ' . __('(basic HTML allowed)', 'coolclock') . '</p>';
403 +
404 + // Advanced filter
405 + if ( class_exists( 'CoolClockAdvanced' ) ) // add an upgrade notice
406 + $advanced_form = '<p><strong>' . __('Background') . '</strong></p><p><strong>' . __('Please upgrade the CoolClock - Advanced extension.', 'coolclock') . '</strong> ' . __('You can download the new version using the remaining download credits and the link that you have received in the confirmation email after your first purchase.', 'coolclock') . ' <a href="http://premium.status301.net/contact/">' . __('If you do not have that email anymore, please contact us.', 'coolclock') . '</a></p>' . '<p><strong>' . __('Do NOT resave widget settings before upgrading the Advanced extension or your advanced settings will be lost!', 'coolclock') . '</strong>';
407 + else
408 + $advanced_form = '<p><strong>' . __('Background') . '</strong></p><p><a href="http://premium.status301.net/downloads/coolclock-advanced/">' . __('Available in the Advanced extension &raquo;', 'coolclock') . '</a></p>';
409 +
410 + $output .= apply_filters( 'coolclock_widget_form_advanced', $advanced_form, $obj, $instance, $defaults );
411 +
412 + return $output;
413 + }
414 +
415 + /**
416 + * INIT
417 + */
418 +
419 + static function init()
420 + {
421 + // text domain
422 + add_action( 'plugins_loaded', create_function( '', "return load_plugin_textdomain( 'coolclock', false, dirname(plugin_basename( __FILE__ )).'/languages' );" ) );
423 +
424 + // shortcode
425 + add_shortcode( 'coolclock', array( __CLASS__, 'handle_shortcode' ) );
426 +
427 + // widgets
428 + add_action( 'widgets_init', create_function( '', 'return register_widget("CoolClock_Widget");' ) );
429 +
430 + // allow shortcode in text widgets
431 + add_filter('widget_text', 'do_shortcode', 11);
432 +
433 + // prevent texturizing shortcode content
434 + add_filter( 'no_texturize_shortcodes', array( __CLASS__, 'no_wptexturize') );
435 +
436 + // register scripts
437 + add_action( 'wp_enqueue_scripts', array( __CLASS__, 'register_scripts') );
438 +
439 + // print scripts in footer
440 + add_action( 'wp_footer', array( __CLASS__, 'print_scripts' ) );
441 + }
442 +
443 +}
444 +
445 +CoolClock::init();
446 +
447 +/**
448 + * CoolClock Widget Class
449 + */
450 +class CoolClock_Widget extends WP_Widget {
451 +
452 + /** PHP5+ constructor */
453 + public function __construct() {
454 + parent::__construct(
455 + 'coolclock-widget',
456 + __('Analog Clock', 'coolclock'),
457 + array(
458 + 'classname' => 'coolclock',
459 + 'description' => __('Add an analog clock to your sidebar.', 'coolclock')
460 + ),
461 + array(
462 + 'width' => 300,
463 + 'id_base' => 'coolclock-widget'
464 + )
465 + );
466 + }
467 +
468 + /** @see WP_Widget::widget -- do not rename this */
469 + public function widget( $args, $instance ) {
470 +
471 + extract( $args );
472 + $title = apply_filters( 'widget_title', $instance['title'] );
473 + $number = $this->number;
474 +
475 + // Print output
476 + echo $before_widget;
477 +
478 + if ( $title )
479 + echo $before_title . $title . $after_title;
480 +
481 + echo CoolClock::widget( $args, $instance, $number );
482 +
483 + echo $after_widget;
484 +
485 + }
486 +
487 + /** @see WP_Widget::update -- do not rename this */
488 + public function update( $new_instance, $old_instance ) {
489 +
490 + return CoolClock::update( $new_instance, $old_instance );
491 +
492 + }
493 +
494 + /** @see WP_Widget::form -- do not rename this */
495 + public function form( $instance ) {
496 +
497 + // Print output
498 + echo CoolClock::form( $this, $instance );
499 +
500 + }
501 +
502 +}