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