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
coolclock / includes / class-coolclock-shortcode.php

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

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