PluginProbe
CoolClock / 4.3.4
CoolClock v4.3.4
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-shortcode.php

class-coolclock-shortcode.php in CoolClock 4.3.4, at includes/class-coolclock-shortcode.php

117 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * CoolClock Shortcode Class
5 */
6
7 class CoolClock_Shortcode {
8
9 public static function handle_shortcode( $atts, $content = null )
10 {
11 /**
12 * 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'.
13 * If the Advanced extension is activated, there is also 'minimal' available.
14 * radius A number to define the clock radius. Do not add 'px' or any other measure descriptor.
15 * noseconds Set to 'true' or 1 or without value to hide the second hand.
16 * gmtoffset A number to define a timezone relative the Greenwhich Mean Time. Do not set this parameter to default to local time.
17 * showdigital Set to 'true' or 1 or 'digital12' or without value to show the time in 12h digital format (with am/pm) too
18 * fontcolor Set to a color value to change the digital time color, digitalcolor for backward compatibility
19 * 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
20 * subtext Optional text, centered below the clock
21 * align Sets floating of the clock: 'left', 'right' or 'center'
22 */
23
24 if ( is_feed() )
25 return '';
26
27 // filter shortcode attributes
28 $defaults = array_merge( CoolClock::$defaults, CoolClock::$advanced_defaults );
29 $atts = shortcode_atts( $defaults, $atts, 'coolclock' );
30
31 // sanitize user input
32 if ( $content )
33 $content = wp_strip_all_tags( $content );
34
35 // backward compat fontcolor
36 if ( !empty( $atts['digitalcolor'] ) && empty($atts['fontcolor']) ) {
37 $atts['fontcolor'] = $atts['digitalcolor'];
38 }
39
40 // pre-treat possible empty attributes
41 if ( is_int( array_search( 'noseconds', $atts ) ) )
42 $atts['noseconds'] = true;
43 if ( is_int( array_search( 'showdigital', $atts ) ) )
44 $atts['showdigital'] = 'digital12';
45
46 // parse skin
47 $atts['skin'] = CoolClock::parse_skin( $atts['skin'], $content );
48
49 // radius, used in wrapper style and coolclock fields
50 $atts['radius'] = !empty( $atts['radius'] ) && is_numeric($atts['radius']) ? (int) $atts['radius'] : $defaults['radius'];
51 if ( 10 > $atts['radius'] ) $atts['radius'] = 10; // absolute minimum size 20x20
52
53 // clean gmtoffset
54 if ( !empty( $atts['gmtoffset'] ) ) {
55 $atts['gmtoffset'] = str_replace( ',', '.', $atts['gmtoffset'] );
56 $atts['gmtoffset'] = str_replace( array('1/2','½'), '.5', $atts['gmtoffset'] );
57 $atts['gmtoffset'] = str_replace( array('h',' '), '', $atts['gmtoffset'] );
58 $atts['gmtoffset'] = is_numeric( $atts['gmtoffset'] ) ? (float) trim( $atts['gmtoffset'] ) : '';
59 }
60
61 if ( !empty( $atts['scale'] ) )
62 $atts['scale'] = wp_strip_all_tags( $atts['scale'] );
63
64 // post-treat showdigital
65 if ( in_array( $atts['showdigital'], array('true','1') ) )
66 $atts['showdigital'] = true;
67 elseif ( !in_array( $atts['showdigital'], array('false','0') ) )
68 $atts['showdigital'] = wp_strip_all_tags( $atts['showdigital'] );
69 else
70 $atts['showdigital'] = '';
71
72 // post-treat noseconds
73 if ( 'false' === $atts['noseconds'] )
74 $atts['noseconds'] = false;
75
76 if ( !empty( $atts['fontcolor'] ) )
77 $atts['fontcolor'] = CoolClock::colorval( $atts['fontcolor'] );
78
79 if ( !empty( $atts['font'] ) )
80 $atts['font'] = wp_strip_all_tags( $atts['font'] );
81
82 if ( !empty( $atts['subtext'] ) )
83 $atts['subtext'] = wp_kses( $atts['subtext'], CoolClock::$allowed_tags );
84
85 $align = !empty( $atts['align'] ) ? wp_strip_all_tags( $atts['align'] ) : $defaults['align'];
86 $class = in_array( $align, array('left','right','center') ) ? ' align' . $align : '';
87
88 // inline container style
89 $styles = array(
90 'width' => 2 * $atts['radius'] . 'px',
91 'height' => 'auto' // leave height:auto at the end for old pro filter to find and replace
92 );
93 $styles = apply_filters( 'coolclock_container_styles', $styles, $atts, $defaults );
94
95 // set footer script flags
96 CoolClock::$add_script = true;
97
98 // Build output
99 // begin wrapper
100 $output = '<div class="coolclock-container ' . $class . '"' . CoolClock::inline_style( $styles ) . '>'; // should end with height:auto"> for old pro plugin to find and replace
101 // add canvas
102 $output .= CoolClock::canvas( $atts );
103 // end wrapper
104 $output .= '</div>';
105
106 // Return filtered output
107 return apply_filters( 'coolclock_shortcode', $output, $atts, $content );
108 }
109
110 public static function no_wptexturize( $shortcodes )
111 {
112 $shortcodes[] = 'coolclock';
113 return $shortcodes;
114 }
115
116 }
117