PluginProbe
CoolClock / trunk
CoolClock vtrunk
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 +20 -502 3.3trunk View file →
@@ -1,514 +1,32 @@
1 1 <?php
2 2 /*
3 3 Plugin Name: CoolClock
4 -Plugin URI: http://status301.net/wordpress-plugins/coolclock/
5 -Description: Add an analog clock to your sidebar.
4 +Plugin URI: https://status301.net/wordpress-plugins/coolclock/
5 +Description: An analog clock for your site.
6 6 Text Domain: coolclock
7 -Domain Path: languages
8 -Version: 3.3
7 +Domain Path: /languages
8 +Requires at least: 5.8
9 +Version: 4.3.8
9 10 Author: RavanH
10 -Author URI: http://status301.net/
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
11 14 */
12 15
13 -/**
14 - * CoolClock Class
15 - */
16 -class CoolClock {
16 +if ( ! defined( 'ABSPATH' ) ) exit;
17 17
18 - static $plugin_version = '3.3';
18 +define( 'COOLCLOCK_DIR', plugin_dir_path(__FILE__) );
19 19
20 - static $script_version = '3.0.0';
20 +/**************
21 + * CLASSES
22 + **************/
21 23
22 - static $add_script;
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';
23 27
24 - static $add_moreskins;
28 +/**************
29 + * INITIATE
30 + **************/
25 31
26 - static $done_excanvas = false;
27 -
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 class="coolclock';
96 -
97 - // align class ans style
98 - $output .= ( $align ) ? ' 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, 'coolclock' );
187 -
188 - // TODO user input (attributes) validation here !!
189 - /*
190 -skin -- must be one of these: 'swissRail' (default skin), 'chunkySwiss', 'chunkySwissOnBlack', 'fancy', 'machine', 'simonbaird_com', 'classic', 'modern', 'simple', 'securephp', 'Tes2', 'Lev', 'Sand', 'Sun', 'Tor', 'Cold', 'Babosa', 'Tumb', 'Stone', 'Disc', 'watermelon' or 'mister'. If the Advanced extension is activated, there is also 'minimal' available. Please note that these names are case sensitive.
191 -radius -- a number to define the clock radius. Do not add 'px' or any other measure descriptor.
192 -noseconds -- set to true (or 1) to hide the second hand
193 -gmtoffset -- a number to define a timezone relative the Greenwhich Mean Time. Do not set this parameter to default to local time.
194 -showdigital -- set to 'digital12' to show the time in 12h digital format (with am/pm) too
195 -scale -- must be one of these: 'linear' (default scale), 'logClock' or 'logClockRev'. Linear is our normal clock scale, the other two show a logarithmic time scale
196 -subtext -- optional text, centered below the clock
197 -align -- sets floating of the clock: 'left', 'right' or 'center'
198 -*/
199 - // set footer script flags
200 - self::$add_script = true;
201 -
202 - if ( !isset( $atts['skin'] ) )
203 - $atts['skin'] = self::$defaults['skin'];
204 -
205 - if ( in_array( $atts['skin'], self::$more_skins ) )
206 - self::$add_moreskins = true;
207 -
208 - // get output
209 - $output = self::canvas( $atts );
210 -
211 - return apply_filters( 'coolclock_shortcode_advanced', $output, $atts, $content );
212 - }
213 -
214 - static function no_wptexturize($shortcodes)
215 - {
216 - $shortcodes[] = 'coolclock';
217 - return $shortcodes;
218 - }
219 -
220 - /**
221 - * WIDGET
222 - */
223 -
224 - static function widget( $args, $instance, $number )
225 - {
226 - $skin = ( isset( $instance['skin'] ) )
227 - ? $instance['skin'] : self::$defaults['skin'];
228 -
229 - // add custom skin parameters to the plugin skins array
230 - if ( 'custom_'.$number == $skin )
231 - self::$advanced_skins_config[$skin] = wp_strip_all_tags( $instance['custom_skin'], true );
232 -
233 - // set footer script flags
234 - self::$add_script = true;
235 -
236 - if ( in_array( $skin, self::$more_skins ) )
237 - self::$add_moreskins = true;
238 -
239 - $output = self::canvas( array(
240 - 'skin' => $skin,
241 - 'radius' => $instance['radius'],
242 - 'noseconds' => $instance['noseconds'],
243 - 'gmtoffset' => $instance['gmtoffset'],
244 - 'showdigital' => $instance['showdigital'],
245 - 'scale' => $instance['scale'],
246 - 'align' => $instance['align'],
247 - 'subtext' => apply_filters('widget_text', $instance['subtext'], $instance)
248 - ) );
249 -
250 - return apply_filters( 'coolclock_widget_advanced', $output, $args, $instance );
251 - }
252 -
253 - static function update( $new_instance, $instance )
254 - {
255 - $instance['title'] = strip_tags( $new_instance['title'] );
256 - $instance['skin'] = strip_tags( $new_instance['skin'] );
257 - $instance['custom_skin'] = strip_tags( $new_instance['custom_skin'] );
258 - $instance['radius'] = ( (int) $new_instance['radius'] < 5 ) ? 5 : (int) $new_instance['radius'];
259 - $instance['noseconds'] = (bool) $new_instance['noseconds'];
260 - $instance['gmtoffset'] = ( $new_instance['gmtoffset'] == '' ) ? '' : (float) $new_instance['gmtoffset'];
261 - $instance['showdigital'] = strip_tags( $new_instance['showdigital'] );
262 - $instance['scale'] = strip_tags( $new_instance['scale'] );
263 - $instance['align'] = strip_tags( $new_instance['align'] );
264 -
265 - if ( current_user_can('unfiltered_html') )
266 - $instance['subtext'] = $new_instance['subtext'];
267 - else
268 - // wp_filter_post_kses() expects slashed
269 - $instance['subtext'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['subtext']) ) );
270 -
271 -
272 - return apply_filters( 'coolclock_widget_update_advanced', $instance, $new_instance );
273 - }
274 -
275 - static function form( $obj, $instance, $defaults = array('title'=>'','custom_skin'=>'') )
276 - {
277 - $defaults = array_merge( $defaults, self::$defaults, self::$advanced_defaults );
278 -
279 - $instance = wp_parse_args( (array) $instance, $defaults );
280 -
281 - $title = esc_attr( $instance['title'] );
282 - $subtext = esc_attr( $instance['subtext'] );
283 - $custom_skin = esc_attr( $instance['custom_skin'] );
284 -
285 - // Translatable skin names go here
286 - $skin_names = array (
287 - 'swissRail' => __('Swiss Rail','coolclock'),
288 - 'chunkySwiss' => __('Chunky Swiss','coolclock'),
289 - 'chunkySwissOnBlack' => __('Chunky Swiss White','coolclock'),
290 - 'fancy' => __('Fancy','coolclock'),
291 - 'machine' => __('Machine','coolclock'),
292 - 'simonbaird_com' => __('SimonBaird.com','coolclock'),
293 - 'classic' => __('Classic by Bonstio','coolclock'),
294 - 'modern' => __('Modern by Bonstio','coolclock'),
295 - 'simple' => __('Simple by Bonstio','coolclock'),
296 - 'securephp' => __('SecurePHP','coolclock'),
297 - 'Tes2' => __('Tes2','coolclock'),
298 - 'Lev' => __('Lev','coolclock'),
299 - 'Sand' => __('Sand','coolclock'),
300 - 'Sun' => __('Sun','coolclock'),
301 - 'Tor' => __('Tor','coolclock'),
302 - 'Cold' => __('Cold','coolclock'),
303 - 'Babosa' => __('Babosa','coolclock'),
304 - 'Tumb' => __('Tumb','coolclock'),
305 - 'Stone' => __('Stone','coolclock'),
306 - 'Disc' => __('Disc','coolclock'),
307 - 'watermelon' => __('Watermelon by Yoo Nhe','coolclock'),
308 - 'mister' => __('Mister by Carl Lister','coolclock'),
309 - 'minimal' => __('Minimal','coolclock')
310 - );
311 -
312 - $skins = array_merge( self::$default_skins, self::$more_skins, self::$advanced_skins );
313 -
314 - // Translatable type names go here
315 - $type_names = array (
316 - 'linear' => __('Linear','coolclock'),
317 - 'logClock' => __('Logarithmic','coolclock'),
318 - 'logClockRev' => __('Logarithmic reversed','coolclock')
319 - );
320 -
321 - // Translatable show options go here
322 - $showdigital_names = array (
323 - '' => __('none','coolclock'),
324 - 'digital12' => __('time (am/pm)','coolclock'),
325 - 'digital24' => __('time (24h)','coolclock'),
326 - 'date' => __('date','coolclock')
327 - );
328 -
329 - // Misc translations
330 - $stray = array(
331 - 'extra_settings' => __('Extra settings for the CoolClock widget.', 'coolclock')
332 - );
333 -
334 - // Title
335 - $output = '<p><label for="' . $obj->get_field_id('title') . '">' . __('Title:') . '</label> ';
336 - $output .= '<input class="widefat" id="' . $obj->get_field_id('title') . '" name="' . $obj->get_field_name('title') . '" type="text" value="' . $title . '" /></p>';
337 -
338 - // Clock settings
339 - $output .= '<p><strong>' . __('Clock', 'coolclock') . '</strong></p>';
340 - $output .= '<p><label for="' . $obj->get_field_id('skin') . '">' . __('Skin:', 'coolclock') . '</label> ';
341 - $output .= '<select class="select" id="' . $obj->get_field_id('skin') . '" name="' . $obj->get_field_name('skin') . '">';
342 - foreach ($skins as $value) {
343 - $output .= '<option value="' . $value . '"';
344 - $output .= ( $value == $instance['skin'] ) ? ' selected="selected">' : '>';
345 - $output .= ( isset($skin_names[$value]) ) ? $skin_names[$value] : $value;
346 - $output .= '</option>';
347 - } unset($value);
348 - $output .= '<option value="custom_' . $obj->number . '"';
349 - $output .= ( 'custom_'.$obj->number == $instance['skin'] ) ? ' selected="selected">' : '>';
350 - $output .= __('Custom (define below)', 'coolclock') . '</option></select></p>';
351 -
352 - // Custom skin field
353 - $output .= '<p><label for="' . $obj->get_field_id('custom_skin') . '">' . __('Custom skin parameters:', 'coolclock') . '</label> ';
354 - $output .= '<textarea class="widefat" id="' . $obj->get_field_id('custom_skin') . '" name="' . $obj->get_field_name('custom_skin') . '">' . $custom_skin . '</textarea></p>';
355 -
356 - // Radius
357 - $output .= '<p><label for="' . $obj->get_field_id('radius') . '">' . __('Radius:', 'coolclock') . '</label> ';
358 - $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>';
359 -
360 - // Second hand
361 - $output .= '<p><input id="' . $obj->get_field_id('noseconds') . '" name="' . $obj->get_field_name('noseconds') . '" type="checkbox" value=';
362 - $output .= ( $instance['noseconds'] ) ? '"true" checked="checked" />' : '"false" />';
363 - $output .= ' <label for="' . $obj->get_field_id('noseconds') . '">' . __('Hide second hand', 'coolclock') . '</label></p>';
364 -
365 - // Show digital
366 - if ( $instance['showdigital'] == 'true' || $instance['showdigital'] == '1' )
367 - $instance['showdigital'] = 'digital12'; // backward compat
368 -
369 - $output .= '<p><label for="' . $obj->get_field_id('showdigital') . '">' . __('Show digital:', 'coolclock') . '</label> ';
370 - $output .= '<select class="select" id="' . $obj->get_field_id('showdigital') . '" name="' . $obj->get_field_name('showdigital') . '">';
371 - foreach (self::$showdigital_options as $key => $value) {
372 - $output .= '<option value="' . $key . '"';
373 - $output .= ( $key == $instance['showdigital'] ) ? ' selected="selected">' : '>';
374 - $output .= ( isset($showdigital_names[$key]) ) ? $showdigital_names[$key] : $value;
375 - $output .= '</option>';
376 - } unset($value);
377 - $output .= '</select></p>';
378 -
379 - // USe GMT offset
380 - $output .= '<p><label for="' . $obj->get_field_id('gmtoffset') . '">' . __('GMT offset:', 'coolclock') . '</label> ';
381 - $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>';
382 -
383 - // Scale
384 - $output .= '<p><label for="' . $obj->get_field_id('scale') . '">' . __('Scale:', 'coolclock') . '</label> ';
385 - $output .= '<select class="select" id="' . $obj->get_field_id('scale') . '" name="' . $obj->get_field_name('scale') . '">';
386 - foreach (self::$clock_types as $key => $value) {
387 - $output .= '<option value="' . $key . '"';
388 - $output .= ( $key == $instance['scale'] ) ? ' selected="selected">' : '>';
389 - $output .= ( isset($type_names[$key]) ) ? $type_names[$key] : $value;
390 - $output .= '</option>';
391 - } unset($value);
392 - $output .= '</select></p>';
393 -
394 - // Align
395 - $output .= '<p><label for="' . $obj->get_field_id('align') . '">' . __('Align:', 'coolclock') . '</label> ';
396 - $output .= '<select class="select" id="' . $obj->get_field_id('align') . '" name="' . $obj->get_field_name('align') . '">';
397 - $output .= '<option value=""';
398 - $output .= ( $instance['align'] == '' ) ? ' selected="selected">' : '>';
399 - $output .= __('none', 'coolclock') . '</option>';
400 - $output .= '<option value="left"';
401 - $output .= ( $instance['align'] == 'left' ) ? ' selected="selected">' : '>';
402 - $output .= __('left', 'coolclock') . '</option>';
403 - $output .= '<option value="right"';
404 - $output .= ( $instance['align'] == 'right' ) ? ' selected="selected">' : '>';
405 - $output .= __('right', 'coolclock') . '</option>';
406 - $output .= '<option value="center"';
407 - $output .= ( $instance['align'] == 'center' ) ? ' selected="selected">' : '>';
408 - $output .= __('center', 'coolclock') . '</option>';
409 - $output .= '</select></p>';
410 -
411 - // Subtext
412 - $output .= '<p><label for="' . $obj->get_field_id('subtext') . '">' . __('Subtext:', 'coolclock') . '</label> ';
413 - $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>';
414 -
415 - // Advanced filter
416 - $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>';
417 -
418 - $output .= apply_filters( 'coolclock_widget_form_advanced', $advanced_form, $obj, $instance, $defaults );
419 -
420 - if ( class_exists( 'CoolClockAdvanced' ) && isset(CoolClockAdvanced::$plugin_version) && version_compare( CoolClockAdvanced::$plugin_version, '6.1', '<' ) ) { // add an upgrade notice
421 - $output .= '<div class="update-nag"><strong>' . __('Please upgrade the CoolClock - Advanced extension.', 'coolclock') . '</strong> '. ' <a href="http://premium.status301.net/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>';
422 - }
423 -
424 - return $output;
425 - }
426 -
427 - /**
428 - * INIT
429 - */
430 -
431 - static function init()
432 - {
433 - // text domain
434 - add_action( 'plugins_loaded', create_function( '', "return load_plugin_textdomain( 'coolclock', false, dirname(plugin_basename( __FILE__ )).'/languages' );" ) );
435 -
436 - // shortcode
437 - add_shortcode( 'coolclock', array( __CLASS__, 'handle_shortcode' ) );
438 -
439 - // widgets
440 - add_action( 'widgets_init', create_function( '', 'return register_widget("CoolClock_Widget");' ) );
441 -
442 - // allow shortcode in text widgets
443 - add_filter('widget_text', 'do_shortcode', 11);
444 -
445 - // prevent texturizing shortcode content
446 - add_filter( 'no_texturize_shortcodes', array( __CLASS__, 'no_wptexturize') );
447 -
448 - // register scripts
449 - add_action( 'wp_enqueue_scripts', array( __CLASS__, 'register_scripts') );
450 -
451 - // print scripts in footer
452 - add_action( 'wp_footer', array( __CLASS__, 'print_scripts' ) );
453 - }
454 -
455 -}
456 -
457 -CoolClock::init();
458 -
459 -/**
460 - * CoolClock Widget Class
461 - */
462 -class CoolClock_Widget extends WP_Widget {
463 -
464 - /** PHP5+ constructor */
465 - public function __construct() {
466 - parent::__construct(
467 - 'coolclock-widget',
468 - __('Analog Clock', 'coolclock'),
469 - array(
470 - 'classname' => 'coolclock',
471 - 'description' => __('Add an analog clock to your sidebar.', 'coolclock')
472 - ),
473 - array(
474 - 'width' => 300,
475 - 'id_base' => 'coolclock-widget'
476 - )
477 - );
478 - }
479 -
480 - /** @see WP_Widget::widget -- do not rename this */
481 - public function widget( $args, $instance ) {
482 -
483 - extract( $args );
484 - $title = apply_filters( 'widget_title', $instance['title'] );
485 - $number = $this->number;
486 -
487 - // Print output
488 - echo $before_widget;
489 -
490 - if ( $title )
491 - echo $before_title . $title . $after_title;
492 -
493 - echo CoolClock::widget( $args, $instance, $number );
494 -
495 - echo $after_widget;
496 -
497 - }
498 -
499 - /** @see WP_Widget::update -- do not rename this */
500 - public function update( $new_instance, $old_instance ) {
501 -
502 - return CoolClock::update( $new_instance, $old_instance );
503 -
504 - }
505 -
506 - /** @see WP_Widget::form -- do not rename this */
507 - public function form( $instance ) {
508 -
509 - // Print output
510 - echo CoolClock::form( $this, $instance );
511 -
512 - }
513 -
514 -}
32 +new CoolClock( __FILE__, '4.3.8' );