| @@ -5,111 +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 | - // filter shortcode attributes | |
| 28 | - $defaults = array_merge( CoolClock::$defaults, CoolClock::$advanced_defaults ); | |
| 29 | - $atts = shortcode_atts( $defaults, $atts, 'coolclock' ); | |
| 13 | + $atts = shortcode_atts( array_merge( CoolClock::$defaults, CoolClock::$advanced_defaults ), $atts, 'coolclock' ); | |
| 30 | 14 | |
| 31 | - // sanitize user input | |
| 32 | - if ( $content ) | |
| 33 | - $content = wp_strip_all_tags( $content ); | |
| 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 | + */ | |
| 34 | 27 | |
| 35 | - // backward compat fontcolor | |
| 36 | - if ( !empty( $atts['digitalcolor'] ) && empty($atts['fontcolor']) ) { | |
| 37 | - $atts['fontcolor'] = $atts['digitalcolor']; | |
| 38 | - } | |
| 28 | + // set footer script flags | |
| 29 | + CoolClock::$add_script = true; | |
| 39 | 30 | |
| 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'; | |
| 31 | + if ( !isset( $atts['skin'] ) ) | |
| 32 | + $atts['skin'] = CoolClock::$defaults['skin']; | |
| 45 | 33 | |
| 46 | - // parse skin | |
| 47 | - $atts['skin'] = CoolClock::parse_skin( $atts['skin'], $content ); | |
| 34 | + if ( in_array( $atts['skin'], CoolClock::$more_skins ) ) | |
| 35 | + CoolClock::$add_moreskins = true; | |
| 48 | 36 | |
| 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 | |
| 37 | + // get output | |
| 38 | + $output = CoolClock::canvas( $atts ); | |
| 52 | 39 | |
| 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 ); | |
| 40 | + return apply_filters( 'coolclock_shortcode_advanced', $output, $atts, $content ); | |
| 108 | 41 | } |
| 109 | 42 | |
| 110 | - public static function no_wptexturize( $shortcodes ) | |
| 111 | - { | |
| 43 | + public static function no_wptexturize($shortcodes) { | |
| 112 | 44 | $shortcodes[] = 'coolclock'; |
| 113 | 45 | return $shortcodes; |
| 114 | 46 | } |
| 115 | 47 | |