PluginProbe
CoolClock / 2.9.8
CoolClock v2.9.8
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 / coolclock.php

coolclock.php in CoolClock 2.9.8, at coolclock.php

499 lines 17.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: CoolClock
4 Plugin URI: http://status301.net/wordpress-plugins/coolclock/
5 Description: Add an analog clock to your sidebar.
6 Text Domain: coolclock
7 Domain Path: languages
8 Version: 2.9.8
9 Author: RavanH
10 Author URI: http://status301.net/
11 */
12
13 /**
14 * CoolClock Class
15 */
16 class CoolClock {
17
18 static $plugin_version = '2.9.8';
19
20 static $script_version = '3.0.0-pre3';
21
22 static $add_script;
23
24 static $add_moreskins;
25
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',
51 'chunkySwiss',
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;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 /* switch ( $scale ) {
121 case 'linear':
122 default:
123 break;
124 case 'logClock':
125 $output .= ':logClock';
126 break;
127 case 'logClockRev':
128 $output .= ':logClockRev';
129 }
130 */
131 $output .= '"></canvas>';
132 $output .= ( $subtext ) ? '<div style="width:100%;text-align:center;padding-bottom:10px">' . $subtext . '</div></div>' : '</div>';
133
134 // before returning, try including excanvas which needs to be there before the first canvas...
135 self::print_excanvas();
136
137 return $output;
138 }
139
140 static function print_excanvas()
141 {
142 if ( self::$done_excanvas )
143 return;
144
145 echo '<!--[if lte IE 8]>';
146 wp_print_scripts( 'excanvas' );
147 echo '<![endif]-->
148 ';
149 self::$done_excanvas = true;
150 }
151
152 static function print_scripts()
153 {
154 if ( ! self::$add_script )
155 return;
156
157 wp_print_scripts( 'coolclock' );
158
159 if ( self::$add_moreskins )
160 wp_print_scripts('coolclock-moreskins');
161
162 if ( is_array( self::$advanced_skins_config ) && !empty( self::$advanced_skins_config ) ) {
163 echo '<script type="text/javascript">jQuery.extend(CoolClock.config.skins, {
164 ';
165 // loop through plugin custom skins
166 foreach (self::$advanced_skins_config as $key => $value)
167 echo $key.':{'.$value.'},
168 ';
169 echo '});</script>
170 ';
171 }
172 }
173
174 /**
175 * SHORTCODE
176 */
177
178 static function handle_shortcode( $atts, $content = null )
179 {
180 if ( is_feed() )
181 return '';
182
183 $atts = shortcode_atts( array_merge( self::$defaults, self::$advanced_defaults ), $atts );
184
185 // set footer script flags
186 self::$add_script = true;
187
188 $skin = ( isset( $atts['skin'] ) )
189 ? $atts['skin'] : 'swissRail';
190
191 if ( in_array( $atts['skin'], self::$more_skins ) )
192 self::$add_moreskins = true;
193
194 $output = self::canvas( $atts );
195 return apply_filters( 'coolclock_shortcode_advanced', $output, $atts, $content );
196 }
197
198 static function no_wptexturize($shortcodes)
199 {
200 $shortcodes[] = 'coolclock';
201 return $shortcodes;
202 }
203
204 /**
205 * WIDGET
206 */
207
208 static function widget( $args, $instance, $number )
209 {
210 $skin = ( isset( $instance['skin'] ) )
211 ? $instance['skin'] : 'swissRail';
212
213 // add custom skin parameters to the plugin skins array
214 if ( 'custom_'.$number == $skin )
215 self::$advanced_skins_config[$skin] = wp_strip_all_tags( $instance['custom_skin'], true );
216
217 // set footer script flags
218 self::$add_script = true;
219
220 if ( in_array( $skin, self::$more_skins ) )
221 self::$add_moreskins = true;
222
223 $output = self::canvas( array(
224 'skin' => $skin,
225 'radius' => $instance['radius'],
226 'noseconds' => $instance['noseconds'],
227 'gmtoffset' => $instance['gmtoffset'],
228 'showdigital' => $instance['showdigital'],
229 'scale' => $instance['scale'],
230 'align' => $instance['align'],
231 'subtext' => apply_filters('widget_text', $instance['subtext'], $instance)
232 ) );
233
234 return apply_filters( 'coolclock_widget_advanced', $output, $args, $instance );
235 }
236
237 static function update( $new_instance, $instance )
238 {
239 $instance['title'] = strip_tags( $new_instance['title'] );
240 $instance['skin'] = strip_tags( $new_instance['skin'] );
241 $instance['custom_skin'] = strip_tags( $new_instance['custom_skin'] );
242 $instance['radius'] = ( (int) $new_instance['radius'] < 5 ) ? 5 : (int) $new_instance['radius'];
243 $instance['noseconds'] = (bool) $new_instance['noseconds'];
244 $instance['gmtoffset'] = ( $new_instance['gmtoffset'] == '' ) ? '' : (float) $new_instance['gmtoffset'];
245 $instance['showdigital'] = strip_tags( $new_instance['showdigital'] );
246 $instance['scale'] = strip_tags( $new_instance['scale'] );
247 $instance['align'] = strip_tags( $new_instance['align'] );
248
249 if ( current_user_can('unfiltered_html') )
250 $instance['subtext'] = $new_instance['subtext'];
251 else
252 // wp_filter_post_kses() expects slashed
253 $instance['subtext'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['subtext']) ) );
254
255
256 return apply_filters( 'coolclock_widget_update_advanced', $instance, $new_instance );
257 }
258
259 static function form( $obj, $instance, $defaults = array('title'=>'','custom_skin'=>'') )
260 {
261 $defaults = array_merge( $defaults, self::$defaults, self::$advanced_defaults );
262
263 $instance = wp_parse_args( (array) $instance, $defaults );
264
265 $title = esc_attr( $instance['title'] );
266 $subtext = esc_attr( $instance['subtext'] );
267 $custom_skin = esc_attr( $instance['custom_skin'] );
268
269 // Translatable skin names go here
270 $skin_names = array (
271 'swissRail' => __('Swiss Rail','coolclock'),
272 'chunkySwiss' => __('Chunky Swiss','coolclock'),
273 'chunkySwissOnBlack' => __('Chunky Swiss Black','coolclock'),
274 'fancy' => __('Fancy','coolclock'),
275 'machine' => __('Machine','coolclock'),
276 'simonbaird_com' => __('SimonBaird.com','coolclock'),
277 'classic' => __('Classic by Bonstio','coolclock'),
278 'modern' => __('Modern by Bonstio','coolclock'),
279 'simple' => __('Simple by Bonstio','coolclock'),
280 'securephp' => __('SecurePHP','coolclock'),
281 'Tes2' => __('Tes2','coolclock'),
282 'Lev' => __('Lev','coolclock'),
283 'Sand' => __('Sand','coolclock'),
284 'Sun' => __('Sun','coolclock'),
285 'Tor' => __('Tor','coolclock'),
286 'Cold' => __('Cold','coolclock'),
287 'Babosa' => __('Babosa','coolclock'),
288 'Tumb' => __('Tumb','coolclock'),
289 'Stone' => __('Stone','coolclock'),
290 'Disc' => __('Disc','coolclock'),
291 'watermelon' => __('Watermelon by Yoo Nhe','coolclock'),
292 'mister' => __('Mister by Carl Lister','coolclock'),
293 'minimal' => __('Minimal','coolclock')
294 );
295
296 $skins = array_merge( self::$default_skins, self::$more_skins, self::$advanced_skins );
297
298 // Translatable type names go here
299 $type_names = array (
300 'linear' => __('Linear','coolclock'),
301 'logClock' => __('Logarithmic','coolclock'),
302 'logClockRev' => __('Logarithmic reversed','coolclock')
303 );
304
305 // Translatable show options go here
306 $showdigital_names = array (
307 '' => __('none','coolclock'),
308 'digital12' => __('time (am/pm)','coolclock'),
309 'digital24' => __('time (24h)','coolclock'),
310 'date' => __('date','coolclock')
311 );
312
313 // Title
314 $output = '<p><label for="' . $obj->get_field_id('title') . '">' . __('Title:') . '</label> ';
315 $output .= '<input class="widefat" id="' . $obj->get_field_id('title') . '" name="' . $obj->get_field_name('title') . '" type="text" value="' . $title . '" /></p>';
316
317 // Clock settings
318 $output .= '<p><strong>' . __('Clock', 'coolclock') . '</strong></p>';
319 $output .= '<p><label for="' . $obj->get_field_id('skin') . '">' . __('Skin:', 'coolclock') . '</label> ';
320 $output .= '<select class="select" id="' . $obj->get_field_id('skin') . '" name="' . $obj->get_field_name('skin') . '">';
321 foreach ($skins as $value) {
322 $output .= '<option value="' . $value . '"';
323 $output .= ( $value == $instance['skin'] ) ? ' selected="selected">' : '>';
324 $output .= ( isset($skin_names[$value]) ) ? $skin_names[$value] : $value;
325 $output .= '</option>';
326 } unset($value);
327 $output .= '<option value="custom_' . $obj->number . '"';
328 $output .= ( 'custom_'.$obj->number == $instance['skin'] ) ? ' selected="selected">' : '>';
329 $output .= __('Custom (define below)', 'coolclock') . '</option></select></p>';
330
331 // Custom skin field
332 $output .= '<p><label for="' . $obj->get_field_id('custom_skin') . '">' . __('Custom skin parameters:', 'coolclock') . '</label> ';
333 $output .= '<textarea class="widefat" id="' . $obj->get_field_id('custom_skin') . '" name="' . $obj->get_field_name('custom_skin') . '">' . $custom_skin . '</textarea></p>';
334
335 // Radius
336 $output .= '<p><label for="' . $obj->get_field_id('radius') . '">' . __('Radius:', 'coolclock') . '</label> ';
337 $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>';
338
339 // Second hand
340 $output .= '<p><input id="' . $obj->get_field_id('noseconds') . '" name="' . $obj->get_field_name('noseconds') . '" type="checkbox" value=';
341 $output .= ( $instance['noseconds'] ) ? '"true" checked="checked" />' : '"false" />';
342 $output .= ' <label for="' . $obj->get_field_id('noseconds') . '">' . __('Hide second hand', 'coolclock') . '</label></p>';
343
344 // Show digital
345 if ( $instance['showdigital'] == 'true' || $instance['showdigital'] == '1' )
346 $instance['showdigital'] = 'digital12'; // backward compat
347
348 $output .= '<p><label for="' . $obj->get_field_id('showdigital') . '">' . __('Show digital:', 'coolclock') . '</label> ';
349 $output .= '<select class="select" id="' . $obj->get_field_id('showdigital') . '" name="' . $obj->get_field_name('showdigital') . '">';
350 foreach (self::$showdigital_options as $key => $value) {
351 $output .= '<option value="' . $key . '"';
352 $output .= ( $key == $instance['showdigital'] ) ? ' selected="selected">' : '>';
353 $output .= ( isset($showdigital_names[$key]) ) ? $showdigital_names[$key] : $value;
354 $output .= '</option>';
355 } unset($value);
356 $output .= '</select></p>';
357
358 // USe GMT offset
359 $output .= '<p><label for="' . $obj->get_field_id('gmtoffset') . '">' . __('GMT offset:', 'coolclock') . '</label> ';
360 $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>';
361
362 // Scale
363 $output .= '<p><label for="' . $obj->get_field_id('scale') . '">' . __('Scale:', 'coolclock') . '</label> ';
364 $output .= '<select class="select" id="' . $obj->get_field_id('scale') . '" name="' . $obj->get_field_name('scale') . '">';
365 foreach (self::$clock_types as $key => $value) {
366 $output .= '<option value="' . $key . '"';
367 $output .= ( $key == $instance['scale'] ) ? ' selected="selected">' : '>';
368 $output .= ( isset($type_names[$key]) ) ? $type_names[$key] : $value;
369 $output .= '</option>';
370 } unset($value);
371 $output .= '</select></p>';
372
373 // Align
374 $output .= '<p><label for="' . $obj->get_field_id('align') . '">' . __('Align:', 'coolclock') . '</label> ';
375 $output .= '<select class="select" id="' . $obj->get_field_id('align') . '" name="' . $obj->get_field_name('align') . '">';
376 $output .= '<option value=""';
377 $output .= ( $instance['align'] == '' ) ? ' selected="selected">' : '>';
378 $output .= __('none', 'coolclock') . '</option>';
379 $output .= '<option value="left"';
380 $output .= ( $instance['align'] == 'left' ) ? ' selected="selected">' : '>';
381 $output .= __('left', 'coolclock') . '</option>';
382 $output .= '<option value="right"';
383 $output .= ( $instance['align'] == 'right' ) ? ' selected="selected">' : '>';
384 $output .= __('right', 'coolclock') . '</option>';
385 $output .= '<option value="center"';
386 $output .= ( $instance['align'] == 'center' ) ? ' selected="selected">' : '>';
387 $output .= __('center', 'coolclock') . '</option>';
388 $output .= '</select></p>';
389
390 // Subtext
391 $output .= '<p><label for="' . $obj->get_field_id('subtext') . '">' . __('Subtext:', 'coolclock') . '</label> ';
392 $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>';
393
394 // Advanced filter
395 if ( class_exists( 'CoolClockAdvanced' ) ) // add an upgrade notice
396 $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://status301.net/contact-en/">' . __('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>';
397 else
398 $advanced_form = '<p><strong>' . __('Background') . '</strong></p><p><a href="http://status301.net/wordpress-plugins/coolclock-advanced/">' . __('Available in the Advanced extension &raquo;', 'coolclock') . '</a></p>';
399
400 $output .= apply_filters( 'coolclock_widget_form_advanced', $advanced_form, $obj, $instance, $defaults );
401
402 return $output;
403 }
404
405 /**
406 * INIT
407 */
408
409 static function go()
410 {
411 add_action('plugins_loaded', create_function( '', "return load_plugin_textdomain( 'coolclock', false, dirname(plugin_basename( __FILE__ )).'/languages' );" ) );
412 add_action( 'init', array(__CLASS__, 'init' ) );
413 add_action( 'widgets_init', create_function( '', 'return register_widget("CoolClock_Widget");' ) );
414 }
415
416 static function init()
417 {
418 add_shortcode( 'coolclock', array( __CLASS__, 'handle_shortcode' ) );
419
420 // allow shortcode in text widgets
421 add_filter('widget_text', 'do_shortcode', 11);
422
423 // prevent texturizing shortcode content
424 add_filter( 'no_texturize_shortcodes', array( __CLASS__, 'no_wptexturize') );
425
426 if ( defined('WP_DEBUG') && false != WP_DEBUG ) {
427 wp_register_script( 'coolclock', plugins_url('/js/coolclock.js', __FILE__), array('jquery'), self::$script_version, true );
428 wp_register_script( 'coolclock-moreskins', plugins_url('/js/moreskins.js', __FILE__), array('coolclock'), self::$script_version, true );
429 wp_register_script( 'excanvas', plugins_url( '/js/excanvas.js', __FILE__ ), array(), '73', true );
430 } else {
431 wp_register_script( 'coolclock', plugins_url('/js/coolclock.min.js', __FILE__), array('jquery'), self::$script_version, true );
432 wp_register_script( 'coolclock-moreskins', plugins_url('/js/moreskins.min.js', __FILE__), array('coolclock'), self::$script_version, true );
433 wp_register_script( 'excanvas', plugins_url( '/js/excanvas.min.js', __FILE__ ), array(), '73', true );
434 }
435
436 add_action( 'wp_footer', array( __CLASS__, 'print_scripts' ) );
437 }
438
439 }
440
441 CoolClock::go();
442
443 /**
444 * CoolClock Widget Class
445 */
446 class CoolClock_Widget extends WP_Widget {
447
448 /** constructor -- name this the same as the class above */
449 function CoolClock_Widget() {
450 parent::WP_Widget(
451 'coolclock-widget',
452 __('Analog Clock', 'coolclock'),
453 array(
454 'classname' => 'coolclock',
455 'description' => __('Add an analog clock to your sidebar.', 'coolclock')
456 ),
457 array(
458 'width' => 300,
459 'id_base' => 'coolclock-widget'
460 )
461 );
462 }
463
464 /** @see WP_Widget::widget -- do not rename this */
465 function widget( $args, $instance ) {
466
467 extract( $args );
468 $title = apply_filters( 'widget_title', $instance['title'] );
469 $number = $this->number;
470
471 // Print output
472 echo $before_widget;
473
474 if ( $title )
475 echo $before_title . $title . $after_title;
476
477 echo CoolClock::widget( $args, $instance, $number );
478
479 echo $after_widget;
480
481 }
482
483 /** @see WP_Widget::update -- do not rename this */
484 function update( $new_instance, $old_instance ) {
485
486 return CoolClock::update( $new_instance, $old_instance );
487
488 }
489
490 /** @see WP_Widget::form -- do not rename this */
491 function form( $instance ) {
492
493 // Print output
494 echo CoolClock::form( $this, $instance );
495
496 }
497
498 }
499