| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | 2 | /** |
| 4 | 3 | * CoolClock Widget Class |
| 5 | 4 | */ |
| 6 | 5 | |
| @@ -8,90 +7,123 @@ | ||
| 8 | 7 | |
| 9 | 8 | /** PHP5+ constructor */ |
| 10 | 9 | public function __construct() { |
| 11 | 10 | parent::__construct( |
| 12 | - 'coolclock-widget', | |
| 13 | - __('Analog Clock', 'coolclock'), | |
| 14 | - array( | |
| 15 | - 'classname' => 'coolclock', | |
| 16 | - 'description' => __('Add an analog clock to your sidebar.', 'coolclock') | |
| 17 | - ), | |
| 18 | - array( | |
| 19 | - 'width' => 300, | |
| 20 | - 'id_base' => 'coolclock-widget' | |
| 21 | - ) | |
| 22 | - ); | |
| 11 | + 'coolclock-widget', | |
| 12 | + __('Analog Clock', 'coolclock'), | |
| 13 | + array( | |
| 14 | + 'classname' => 'coolclock', | |
| 15 | + 'description' => __('Add an analog clock to your sidebar.', 'coolclock') | |
| 16 | + ), | |
| 17 | + array( | |
| 18 | + 'width' => 300, | |
| 19 | + 'id_base' => 'coolclock-widget' | |
| 20 | + ) | |
| 21 | + ); | |
| 23 | 22 | } |
| 24 | 23 | |
| 25 | 24 | /** @see WP_Widget::widget -- do not rename this */ |
| 26 | 25 | public function widget( $args, $instance ) { |
| 27 | 26 | extract( $args ); |
| 27 | + | |
| 28 | + $defaults = array_merge( array('title'=>'','custom_skin'=>''), CoolClock::$defaults, CoolClock::$advanced_defaults ); | |
| 29 | + | |
| 30 | + // backward compat | |
| 31 | + if ( isset($instance['digitalcolor']) && !isset($instance['fontcolor']) ) $instance['fontcolor'] = $instance['digitalcolor']; | |
| 32 | + | |
| 28 | 33 | $title = !empty($instance['title']) ? apply_filters( 'widget_title', $instance['title'] ) : ''; |
| 29 | - $number = $this->number; | |
| 34 | + //$number = $this->number; | |
| 30 | 35 | |
| 36 | + // set footer script flags | |
| 37 | + CoolClock::$add_script = true; | |
| 38 | + | |
| 31 | 39 | // Print output |
| 32 | - echo $before_widget; | |
| 40 | + echo wp_kses_post( $before_widget ); | |
| 33 | 41 | |
| 34 | - if ( $title ) | |
| 35 | - echo $before_title . $title . $after_title; | |
| 42 | + if ( $title ) { | |
| 43 | + echo wp_kses_post( $before_title ) . esc_html( $title ) . wp_kses_post( $after_title ); | |
| 44 | + } | |
| 36 | 45 | |
| 37 | 46 | // set skin |
| 38 | - $skin = ( isset( $instance['skin'] ) ) | |
| 39 | - ? $instance['skin'] : CoolClock::$defaults['skin']; | |
| 47 | + $instance['skin'] = CoolClock::parse_skin( | |
| 48 | + ! empty( $instance['skin'] ) ? $instance['skin'] : $defaults['skin'], | |
| 49 | + ! empty( $instance['custom_skin'] ) ? $instance['custom_skin'] : '' | |
| 50 | + ); | |
| 40 | 51 | |
| 41 | - // add custom skin parameters to the plugin skins array | |
| 42 | - if ( 'custom_'.$number == $skin ) | |
| 43 | - CoolClock::$advanced_skins_config[$skin] = wp_strip_all_tags( $instance['custom_skin'], true ); | |
| 52 | + // radius, used in wrapper style and coolclock fields | |
| 53 | + $instance['radius'] = !empty( $instance['radius'] ) && is_numeric( $instance['radius'] ) ? (int) $instance['radius'] : $defaults['radius']; | |
| 54 | + if ( 10 > $instance['radius'] ) $instance['radius'] = 10; // absolute minimum size 20x20 | |
| 44 | 55 | |
| 45 | - // set footer script flags | |
| 46 | - CoolClock::$add_script = true; | |
| 56 | + $align = !empty( $instance['align'] ) ? $instance['align'] : $defaults['align']; | |
| 57 | + $styles = array( | |
| 58 | + 'width' => 2 * $instance['radius'] . 'px', | |
| 59 | + 'height' => 'auto', | |
| 60 | + ); | |
| 61 | + if ( in_array( $align, array('left','center') ) ) { | |
| 62 | + $styles['margin-right'] = 'auto'; | |
| 63 | + if ( 'left' == $align ) $styles['margin-left'] = '0'; | |
| 64 | + } | |
| 65 | + if ( in_array( $align, array('right','center') ) ) { | |
| 66 | + $styles['margin-left'] = 'auto'; | |
| 67 | + if ( 'right' == $align ) $styles['margin-right'] = '0'; | |
| 68 | + } | |
| 69 | + $styles = apply_filters( 'coolclock_container_styles', $styles, $instance, $defaults ); | |
| 47 | 70 | |
| 48 | - if ( in_array( $skin, CoolClock::$more_skins ) ) | |
| 49 | - CoolClock::$add_moreskins = true; | |
| 71 | + // Build output | |
| 72 | + // begin wrapper | |
| 73 | + $output = '<div class="coolclock-container"' . CoolClock::inline_style( $styles ) . '>'; | |
| 74 | + // add canvas | |
| 75 | + $output .= CoolClock::canvas( $instance ); | |
| 76 | + // end wrapper | |
| 77 | + $output .= '</div>'; | |
| 50 | 78 | |
| 51 | - $output = CoolClock::canvas( array( | |
| 52 | - 'skin' => $skin, | |
| 53 | - 'radius' => !empty($instance['radius']) && is_numeric($instance['radius']) ? (int) $instance['radius'] : 100, | |
| 54 | - 'noseconds' => !empty($instance['radius']) ? $instance['noseconds'] : '', | |
| 55 | - 'gmtoffset' => !empty($instance['gmtoffset']) ? $instance['gmtoffset'] : '', | |
| 56 | - 'showdigital' => !empty($instance['showdigital']) ? $instance['showdigital'] : '', | |
| 57 | - 'digitalcolor' => !empty($instance['digitalcolor']) ? $instance['digitalcolor'] : '', | |
| 58 | - 'scale' => !empty($instance['scale']) ? $instance['scale'] : 'linear', | |
| 59 | - 'align' => !empty($instance['align']) ? $instance['align'] : 'center', | |
| 60 | - 'subtext' => !empty($instance['subtext']) ? apply_filters('widget_text', $instance['subtext'], $instance) : '' | |
| 61 | - ) ); | |
| 79 | + // Print filtered output. wp_kses_post() strips <canvas>, so extend its | |
| 80 | + // allowed tags rather than using it directly (which would silently | |
| 81 | + // remove the clock). | |
| 82 | + $allowed_html = array_merge( | |
| 83 | + wp_kses_allowed_html( 'post' ), | |
| 84 | + array( | |
| 85 | + 'canvas' => array( | |
| 86 | + 'class' => true, | |
| 87 | + 'style' => true, | |
| 88 | + 'width' => true, | |
| 89 | + 'height' => true, | |
| 90 | + ), | |
| 91 | + ) | |
| 92 | + ); | |
| 93 | + echo wp_kses( apply_filters( 'coolclock_widget', $output, $args, $instance ), $allowed_html ); | |
| 62 | 94 | |
| 63 | - echo apply_filters( 'coolclock_widget_advanced', $output, $args, $instance ); | |
| 64 | - | |
| 65 | - echo $after_widget; | |
| 95 | + echo wp_kses_post( $after_widget ); | |
| 66 | 96 | } |
| 67 | 97 | |
| 68 | 98 | /** @see WP_Widget::update -- do not rename this */ |
| 69 | 99 | public function update( $new_instance, $old_instance ) { |
| 70 | - $instance['title'] = !empty($new_instance['title']) ? strip_tags( $new_instance['title'] ) : ''; | |
| 71 | - $instance['skin'] = !empty($new_instance['skin']) ? strip_tags( $new_instance['skin'] ) : ''; | |
| 72 | - $instance['custom_skin'] = !empty($new_instance['custom_skin']) ? strip_tags( $new_instance['custom_skin'] ) : ''; | |
| 100 | + // parse custom skin code | |
| 101 | + $skin_array = !empty($new_instance['custom_skin']) ? CoolClock::skin_array( wp_strip_all_tags( $new_instance['custom_skin'] ) ) : array(); | |
| 102 | + | |
| 103 | + $instance['title'] = !empty($new_instance['title']) ? wp_strip_all_tags( $new_instance['title'] ) : ''; | |
| 104 | + $instance['skin'] = !empty($new_instance['skin']) ? wp_strip_all_tags( $new_instance['skin'] ) : ''; | |
| 105 | + $instance['custom_skin'] = !empty($skin_array) ? wp_json_encode( $skin_array ) : ''; | |
| 73 | 106 | $instance['radius'] = ( empty($new_instance['radius']) || (int) $new_instance['radius'] < 5 ) ? 5 : (int) $new_instance['radius']; |
| 74 | 107 | $instance['noseconds'] = !empty($new_instance['noseconds']) ? '1' : ''; |
| 75 | - $instance['gmtoffset'] = !empty($new_instance['gmtoffset']) ? (float) $new_instance['gmtoffset'] : ''; | |
| 76 | - $instance['showdigital'] = !empty($new_instance['showdigital']) ? strip_tags( $new_instance['showdigital'] ) : ''; | |
| 77 | - $instance['digitalcolor'] = !empty($new_instance['digitalcolor']) ? CoolClock::colorval( $new_instance['digitalcolor'] ) : ''; | |
| 78 | - $instance['scale'] = !empty($new_instance['scale']) ? strip_tags( $new_instance['scale'] ) : ''; | |
| 79 | - $instance['align'] = !empty($new_instance['align']) ? strip_tags( $new_instance['align'] ) : ''; | |
| 108 | + $instance['gmtoffset'] = isset($new_instance['gmtoffset']) && $new_instance['gmtoffset'] !== '' ? (float) $new_instance['gmtoffset'] : ''; | |
| 109 | + $instance['showdigital'] = !empty($new_instance['showdigital']) ? wp_strip_all_tags( $new_instance['showdigital'] ) : ''; | |
| 110 | + $instance['fontcolor'] = !empty($new_instance['fontcolor']) ? CoolClock::colorval( $new_instance['fontcolor'] ) : ''; | |
| 111 | + $instance['scale'] = !empty($new_instance['scale']) ? wp_strip_all_tags( $new_instance['scale'] ) : ''; | |
| 112 | + $instance['align'] = !empty($new_instance['align']) ? wp_strip_all_tags( $new_instance['align'] ) : ''; | |
| 113 | + $instance['subtext'] = wp_kses( $new_instance['subtext'], CoolClock::$allowed_tags ); | |
| 80 | 114 | |
| 81 | - if ( current_user_can('unfiltered_html') ) | |
| 82 | - $instance['subtext'] = $new_instance['subtext']; | |
| 83 | - else | |
| 84 | - // wp_filter_post_kses() expects slashed | |
| 85 | - $instance['subtext'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['subtext']) ) ); | |
| 86 | - | |
| 87 | - return apply_filters( 'coolclock_widget_update_advanced', $instance, $new_instance ); | |
| 115 | + return apply_filters( 'coolclock_widget_update_advanced', $instance, $new_instance ); | |
| 88 | 116 | } |
| 89 | 117 | |
| 90 | 118 | /** @see WP_Widget::form -- do not rename this */ |
| 91 | 119 | public function form( $instance ) { |
| 92 | - // Print output | |
| 93 | - //echo CoolClock::form( $this, $instance ); | |
| 120 | + $output = ''; | |
| 121 | + $advanced = ''; | |
| 122 | + | |
| 123 | + // backward compat | |
| 124 | + if ( isset($instance['digitalcolor']) && !isset($instance['fontcolor']) ) $instance['fontcolor'] = $instance['digitalcolor']; | |
| 125 | + | |
| 94 | 126 | $defaults = array_merge( array('title'=>'','custom_skin'=>''), CoolClock::$defaults, CoolClock::$advanced_defaults ); |
| 95 | 127 | |
| 96 | 128 | $instance = wp_parse_args( (array) $instance, $defaults ); |
| 97 | 129 | |
| @@ -100,78 +132,83 @@ | ||
| 100 | 132 | $custom_skin = esc_attr( $instance['custom_skin'] ); |
| 101 | 133 | |
| 102 | 134 | // Translatable skin names go here |
| 103 | 135 | $skin_names = array ( |
| 104 | - 'swissRail' => __('Swiss Rail','coolclock'), | |
| 105 | - 'chunkySwiss' => __('Chunky Swiss','coolclock'), | |
| 106 | - 'chunkySwissOnBlack' => __('Chunky Swiss White','coolclock'), | |
| 107 | - 'fancy' => __('Fancy','coolclock'), | |
| 108 | - 'machine' => __('Machine','coolclock'), | |
| 109 | - 'simonbaird_com' => __('SimonBaird.com','coolclock'), | |
| 110 | - 'classic' => __('Classic by Bonstio','coolclock'), | |
| 111 | - 'modern' => __('Modern by Bonstio','coolclock'), | |
| 112 | - 'simple' => __('Simple by Bonstio','coolclock'), | |
| 113 | - 'securephp' => __('SecurePHP','coolclock'), | |
| 114 | - 'Tes2' => __('Tes2','coolclock'), | |
| 115 | - 'Lev' => __('Lev','coolclock'), | |
| 116 | - 'Sand' => __('Sand','coolclock'), | |
| 117 | - 'Sun' => __('Sun','coolclock'), | |
| 118 | - 'Tor' => __('Tor','coolclock'), | |
| 119 | - 'Cold' => __('Cold','coolclock'), | |
| 120 | - 'Babosa' => __('Babosa','coolclock'), | |
| 121 | - 'Tumb' => __('Tumb','coolclock'), | |
| 122 | - 'Stone' => __('Stone','coolclock'), | |
| 123 | - 'Disc' => __('Disc','coolclock'), | |
| 124 | - 'watermelon' => __('Watermelon by Yoo Nhe','coolclock'), | |
| 125 | - 'mister' => __('Mister by Carl Lister','coolclock'), | |
| 126 | - 'minimal' => __('Minimal','coolclock') | |
| 127 | - ); | |
| 136 | + 'swissrail' => __('Swiss Rail','coolclock'), | |
| 137 | + 'chunkyswiss' => __('Chunky Swiss','coolclock'), | |
| 138 | + 'chunkyswissonblack' => __('Chunky Swiss White','coolclock'), | |
| 139 | + 'fancy' => __('Fancy','coolclock'), | |
| 140 | + 'machine' => __('Machine','coolclock'), | |
| 141 | + 'simonbaird_com' => __('SimonBaird.com','coolclock'), | |
| 142 | + 'classic' => __('Classic by Bonstio','coolclock'), | |
| 143 | + 'modern' => __('Modern by Bonstio','coolclock'), | |
| 144 | + 'simple' => __('Simple by Bonstio','coolclock'), | |
| 145 | + 'securephp' => __('SecurePHP','coolclock'), | |
| 146 | + 'tes2' => __('Tes2','coolclock'), | |
| 147 | + 'lev' => __('Lev','coolclock'), | |
| 148 | + 'sand' => __('Sand','coolclock'), | |
| 149 | + 'sun' => __('Sun','coolclock'), | |
| 150 | + 'tor' => __('Tor','coolclock'), | |
| 151 | + 'cold' => __('Cold','coolclock'), | |
| 152 | + 'babosa' => __('Babosa','coolclock'), | |
| 153 | + 'tumb' => __('Tumb','coolclock'), | |
| 154 | + 'stone' => __('Stone','coolclock'), | |
| 155 | + 'disc' => __('Disc','coolclock'), | |
| 156 | + 'watermelon' => __('Watermelon by Yoo Nhe','coolclock'), | |
| 157 | + 'mister' => __('Mister by Carl Lister','coolclock'), | |
| 158 | + 'minimal' => __('Minimal','coolclock') | |
| 159 | + ); | |
| 128 | 160 | |
| 129 | - $skins = array_merge( CoolClock::$default_skins, CoolClock::$more_skins, CoolClock::$advanced_skins ); | |
| 130 | - | |
| 131 | 161 | // Translatable type names go here |
| 132 | 162 | $type_names = array ( |
| 133 | - 'linear' => __('Linear','coolclock'), | |
| 134 | - 'logClock' => __('Logarithmic','coolclock'), | |
| 135 | - 'logClockRev' => __('Logarithmic reversed','coolclock') | |
| 136 | - ); | |
| 163 | + 'linear' => __('Linear','coolclock'), | |
| 164 | + 'logclock' => __('Logarithmic','coolclock'), | |
| 165 | + 'logclockrev' => __('Logarithmic reversed','coolclock') | |
| 166 | + ); | |
| 137 | 167 | |
| 138 | 168 | // Translatable show digital options go here |
| 139 | 169 | $showdigital_names = array ( |
| 140 | - '' => __('none','coolclock'), | |
| 141 | - 'digital12' => __('time (am/pm)','coolclock'), | |
| 142 | - 'digital24' => __('time (24h)','coolclock'), | |
| 143 | - 'date' => __('date','coolclock') | |
| 170 | + '' => __( 'No', 'coolclock' ), | |
| 171 | + 'digital12' => __('time (am/pm)','coolclock'), | |
| 172 | + 'digital24' => __('time (24h)','coolclock'), | |
| 173 | + 'date' => __('date','coolclock'), | |
| 174 | + 'digital12+' => __('time + seconds (am/pm)','coolclock'), | |
| 175 | + 'digital24+' => __('time + seconds (24h)','coolclock'), | |
| 176 | + 'text' => __('custom text','coolclock') | |
| 144 | 177 | ); |
| 145 | 178 | |
| 146 | - // Misc translations | |
| 147 | - $stray = array( | |
| 148 | - 'extra_settings' => __('Extra settings for the CoolClock widget.', 'coolclock') | |
| 149 | - ); | |
| 150 | - | |
| 151 | 179 | // Title |
| 152 | - $output = '<style type="text/css">#available-widgets [class*=clock] .widget-title:before{content:"\f469"}</style> | |
| 153 | - <p><label for="' . $this->get_field_id('title') . '">' . __('Title:') . '</label> '; | |
| 180 | + $output .= '<style type="text/css">#available-widgets [class*=clock] .widget-title:before{content:"\f469"}</style> | |
| 181 | + <p><label for="' . $this->get_field_id('title') . '">' . __( 'Title:', 'coolclock' ) . '</label> '; | |
| 154 | 182 | $output .= '<input class="widefat" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $title . '" /></p>'; |
| 155 | 183 | |
| 156 | 184 | // Clock settings |
| 157 | - $output .= '<p><strong>' . __('Clock', 'coolclock') . '</strong></p>'; | |
| 185 | + $output .= '<fieldset><legend>' . __('Clock', 'coolclock') . '</legend>'; | |
| 186 | + $output .= '<p class="description"><a href="https://premium.status301.com/coolclock-widget-settings/" target="_blank">' . __('CoolClock widget instructions »', 'coolclock') . '</a></p>'; | |
| 187 | + | |
| 158 | 188 | $output .= '<p><label for="' . $this->get_field_id('skin') . '">' . __('Skin:', 'coolclock') . '</label> '; |
| 159 | 189 | $output .= '<select class="select" id="' . $this->get_field_id('skin') . '" name="' . $this->get_field_name('skin') . '">'; |
| 160 | - foreach ($skins as $value) { | |
| 161 | - $output .= '<option value="' . $value . '"'; | |
| 162 | - $output .= ( $value == $instance['skin'] ) ? ' selected="selected">' : '>'; | |
| 163 | - $output .= ( isset($skin_names[$value]) ) ? $skin_names[$value] : $value; | |
| 190 | + $output .= '<option value="' . $defaults['skin'] . '" ' . selected( $defaults['skin'], $instance['skin'], false ) . '>'; | |
| 191 | + $output .= ( isset($skin_names[$defaults['skin']]) ) ? $skin_names[$defaults['skin']] : $defaults['skin']; | |
| 192 | + $output .= '</option>'; | |
| 193 | + foreach ( CoolClock::get_all_skins() as $skin => $parms ) { | |
| 194 | + $output .= '<option value="' . $skin . '" ' . selected( $skin, $instance['skin'], false ) . '>'; | |
| 195 | + $output .= ( isset($skin_names[$skin]) ) ? $skin_names[$skin] : $skin; | |
| 164 | 196 | $output .= '</option>'; |
| 165 | - } unset($value); | |
| 166 | - $output .= '<option value="custom_' . $this->number . '"'; | |
| 167 | - $output .= ( 'custom_'.$this->number == $instance['skin'] ) ? ' selected="selected">' : '>'; | |
| 197 | + } | |
| 198 | + $output .= '<option value="custom_' . $this->number . '" ' . selected( 'custom_'.$this->number, $instance['skin'], false ) . '>'; | |
| 168 | 199 | $output .= __('Custom (define below)', 'coolclock') . '</option></select></p>'; |
| 169 | 200 | |
| 170 | 201 | // Custom skin field |
| 171 | 202 | $output .= '<p><label for="' . $this->get_field_id('custom_skin') . '">' . __('Custom skin parameters:', 'coolclock') . '</label> '; |
| 172 | - $output .= '<textarea class="widefat" id="' . $this->get_field_id('custom_skin') . '" name="' . $this->get_field_name('custom_skin') . '">' . $custom_skin . '</textarea> <em>' . __('(set Skin to Custom above)', 'coolclock') . '</em></p>'; | |
| 203 | + $output .= '<textarea class="widefat" id="' . $this->get_field_id('custom_skin') . '" name="' . $this->get_field_name('custom_skin') . '">' . $custom_skin . '</textarea></p>'; | |
| 173 | 204 | |
| 205 | + $output .= '<p class="description"><em>' . sprintf( | |
| 206 | + /* translators: %s: link to the JSON parameters documentation */ | |
| 207 | + __( '(set Skin to Custom above, then add %s here)', 'coolclock' ), | |
| 208 | + '<a href="https://premium.status301.com/coolclock-custom-skin/" target="_blank">' . __( 'parameters in JSON format', 'coolclock' ) . '</a>' | |
| 209 | + ) . '</em></p>'; | |
| 210 | + | |
| 174 | 211 | // Radius |
| 175 | 212 | $output .= '<p><label for="' . $this->get_field_id('radius') . '">' . __('Radius:', 'coolclock') . '</label> '; |
| 176 | 213 | $output .= '<input class="small-text" id="' . $this->get_field_id('radius') . '" name="' . $this->get_field_name('radius') . '" type="number" min="10" value="' . $instance['radius'] . '" /></p>'; |
| 177 | 214 | |
| @@ -179,44 +216,43 @@ | ||
| 179 | 216 | $output .= '<p><input id="' . $this->get_field_id('noseconds') . '" name="' . $this->get_field_name('noseconds') . '" type="checkbox" value='; |
| 180 | 217 | $output .= ( $instance['noseconds'] ) ? '"true" checked="checked" />' : '"false" />'; |
| 181 | 218 | $output .= ' <label for="' . $this->get_field_id('noseconds') . '">' . __('Hide second hand', 'coolclock') . '</label></p>'; |
| 182 | 219 | |
| 183 | - // Scale | |
| 184 | - $output .= '<p><label for="' . $this->get_field_id('scale') . '">' . __('Scale:', 'coolclock') . '</label> '; | |
| 185 | - $output .= '<select class="select" id="' . $this->get_field_id('scale') . '" name="' . $this->get_field_name('scale') . '">'; | |
| 186 | - foreach ( CoolClock::$clock_types as $key => $value ) { | |
| 187 | - $output .= '<option value="' . $key . '"'; | |
| 188 | - $output .= ( $key == $instance['scale'] ) ? ' selected="selected">' : '>'; | |
| 189 | - $output .= ( isset($type_names[$key]) ) ? $type_names[$key] : $value; | |
| 190 | - $output .= '</option>'; | |
| 191 | - } | |
| 192 | - $output .= '</select></p>'; | |
| 193 | - | |
| 194 | 220 | // Align |
| 195 | 221 | $output .= '<p><label for="' . $this->get_field_id('align') . '">' . __('Align:', 'coolclock') . '</label> '; |
| 196 | 222 | $output .= '<select class="select" id="' . $this->get_field_id('align') . '" name="' . $this->get_field_name('align') . '">'; |
| 197 | - $output .= '<option value=""'; | |
| 198 | - $output .= ( $instance['align'] == '' ) ? ' selected="selected">' : '>'; | |
| 199 | - $output .= __('none', 'coolclock') . '</option>'; | |
| 200 | - $output .= '<option value="left"'; | |
| 201 | - $output .= ( $instance['align'] == 'left' ) ? ' selected="selected">' : '>'; | |
| 223 | + $output .= '<option value="">'; | |
| 224 | + $output .= __( 'none', 'coolclock' ) . '</option>'; | |
| 225 | + $output .= '<option value="left" ' . selected( $instance['align'], 'left', false ) . '>'; | |
| 202 | 226 | $output .= __('left', 'coolclock') . '</option>'; |
| 203 | - $output .= '<option value="right"'; | |
| 204 | - $output .= ( $instance['align'] == 'right' ) ? ' selected="selected">' : '>'; | |
| 227 | + $output .= '<option value="right" ' . selected( $instance['align'], 'right', false ) . '>'; | |
| 205 | 228 | $output .= __('right', 'coolclock') . '</option>'; |
| 206 | - $output .= '<option value="center"'; | |
| 207 | - $output .= ( $instance['align'] == 'center' ) ? ' selected="selected">' : '>'; | |
| 229 | + $output .= '<option value="center" ' . selected( $instance['align'], 'center', false ) . '>'; | |
| 208 | 230 | $output .= __('center', 'coolclock') . '</option>'; |
| 209 | 231 | $output .= '</select></p>'; |
| 210 | 232 | |
| 211 | 233 | // Subtext |
| 212 | 234 | $output .= '<p><label for="' . $this->get_field_id('subtext') . '">' . __('Subtext:', 'coolclock') . '</label> '; |
| 213 | - $output .= '<input class="widefat" id="' . $this->get_field_id('subtext') . '" name="' . $this->get_field_name('subtext') . '" type="text" value="' . $subtext . '" /> <em>' . __('(basic HTML allowed)', 'coolclock') . '</em></p>'; | |
| 235 | + $output .= '<input class="widefat" id="' . $this->get_field_id('subtext') . '" name="' . $this->get_field_name('subtext') . '" type="text" value="' . $subtext . '" /> <span class="description"><em>' . __('(basic HTML allowed)', 'coolclock') . '</em></span></p>'; | |
| 214 | 236 | |
| 237 | + $output .= '</fieldset>'; //<div class="coolclock-advanced" style="background-color:rgba(0,0,0,.03);padding:1px 7px;border-radius:5px;margin-bottom:10px">'; | |
| 238 | + | |
| 239 | + $output .= '<fieldset><legend>' . __( 'Advanced', 'coolclock' ) . '</legend>'; | |
| 240 | + | |
| 215 | 241 | // Use GMT offset |
| 216 | 242 | $output .= '<p><label for="' . $this->get_field_id('gmtoffset') . '">' . __('GMT offset:', 'coolclock') . '</label> '; |
| 217 | - $output .= '<input class="small-text" id="' . $this->get_field_id('gmtoffset') . '" name="' . $this->get_field_name('gmtoffset') . '" type="number" step="0.5" value="' . $instance['gmtoffset'] . '" /> <em>' . __('(leave blank for visitor local time)', 'coolclock') . '</em></p>'; | |
| 243 | + $output .= '<input class="small-text" id="' . $this->get_field_id('gmtoffset') . '" name="' . $this->get_field_name('gmtoffset') . '" type="number" step="0.5" value="' . $instance['gmtoffset'] . '" /> <span class="description"><em>' . __('(leave blank for visitor local time)', 'coolclock') . '</em></span></p>'; | |
| 218 | 244 | |
| 245 | + // Scale | |
| 246 | + $output .= '<p><label for="' . $this->get_field_id('scale') . '">' . __('Scale:', 'coolclock') . '</label> '; | |
| 247 | + $output .= '<select class="select" id="' . $this->get_field_id('scale') . '" name="' . $this->get_field_name('scale') . '">'; | |
| 248 | + foreach ( CoolClock::$clock_types as $key => $value ) { | |
| 249 | + $output .= '<option value="' . $key . '" ' . selected( $key, strtolower($instance['scale']), false ) . '">'; | |
| 250 | + $output .= ( isset($type_names[$key]) ) ? $type_names[$key] : $value; | |
| 251 | + $output .= '</option>'; | |
| 252 | + } | |
| 253 | + $output .= '</select></p>'; | |
| 254 | + | |
| 219 | 255 | // Show digital |
| 220 | 256 | if ( $instance['showdigital'] == 'true' || $instance['showdigital'] == '1' ) |
| 221 | 257 | $instance['showdigital'] = 'digital12'; // backward compat |
| 222 | 258 | |
| @@ -222,28 +258,62 @@ | ||
| 222 | 258 | |
| 223 | 259 | $output .= '<p><label for="' . $this->get_field_id('showdigital') . '">' . __('Show digital:', 'coolclock') . '</label> '; |
| 224 | 260 | $output .= '<select class="select" id="' . $this->get_field_id('showdigital') . '" name="' . $this->get_field_name('showdigital') . '">'; |
| 225 | 261 | foreach ( CoolClock::$showdigital_options as $key => $value ) { |
| 226 | - $output .= '<option value="' . $key . '"'; | |
| 227 | - $output .= ( $key == $instance['showdigital'] ) ? ' selected="selected">' : '>'; | |
| 262 | + $output .= '<option value="' . $key . '" ' . selected( $key, $instance['showdigital'], false ) . '>'; | |
| 228 | 263 | $output .= ( isset($showdigital_names[$key]) ) ? $showdigital_names[$key] : $value; |
| 229 | 264 | $output .= '</option>'; |
| 230 | 265 | } |
| 231 | 266 | $output .= '</select></p>'; |
| 232 | 267 | |
| 233 | - $advanced = '<p><label for="' . $this->get_field_id('digitalcolor') . '">' . __('Digital color:', 'coolclock') . '</label> '; | |
| 234 | - $advanced .= '<input id="' . $this->get_field_id('digitalcolor') . '" name="' . $this->get_field_name('digitalcolor') . '" type="text" value="' . $instance['digitalcolor'] . '" /> <em>' . __('(use a valid HTML color code or name)', 'coolclock') . '</em></p>'; | |
| 268 | + $output .= '<p><label for="' . $this->get_field_id('fontcolor') . '">' . __('Digital font color:', 'coolclock') . '</label> '; | |
| 269 | + $output .= '<input id="' . $this->get_field_id('fontcolor') . '" name="' . $this->get_field_name('fontcolor') . '" type="text" value="' . $instance['fontcolor'] . '" /> <span class="description"><em>' . __('(use a valid HTML color code or name)', 'coolclock') . '</em></span></p>'; | |
| 270 | + $output .= '</fieldset>'; | |
| 235 | 271 | |
| 236 | - $advanced .= '<p><a href="http://premium.status301.net/downloads/coolclock-advanced/">' . __('More digital font options »', 'coolclock') . '</a></p> | |
| 237 | - <p><strong>' . __('Background') . '</strong></p><p><a href="http://premium.status301.net/downloads/coolclock-advanced/">' . __('Available in the Advanced extension »', 'coolclock') . '</a></p>'; | |
| 272 | + $advanced .= '<p class="description"><a href="https://premium.status301.com/downloads/coolclock-advanced/">' . __('More digital font options »', 'coolclock') . '</a></p> | |
| 273 | + <fieldset><legend>' . __( 'Background', 'coolclock' ) . '</legend><p class="description"><a href="https://premium.status301.com/downloads/coolclock-advanced/">' . __('Available in the Advanced extension »', 'coolclock') . '</a></p></fieldset>'; | |
| 238 | 274 | |
| 239 | 275 | // Advanced filter |
| 240 | 276 | $output .= apply_filters( 'coolclock_widget_form_advanced', $advanced, $this, $instance, $defaults ); |
| 241 | 277 | |
| 278 | + $output .= '</div>'; | |
| 279 | + | |
| 242 | 280 | if ( class_exists( 'CoolClockAdvanced' ) && isset(CoolClockAdvanced::$plugin_version) && version_compare( CoolClockAdvanced::$plugin_version, '7.1', '<' ) ) { // add an upgrade notice |
| 243 | - $output .= '<div class="update-nag"><strong>' . __('Please upgrade the CoolClock - Advanced extension.', 'coolclock') . '</strong> '. ' <a href="http://premium.status301.net/account/" target="_blank">' . __('Please log in with your account credentials here.', 'coolclock') . '</a>' . __('You can download the new version using the link in the downloads list.', 'coolclock') . '</div>'; | |
| 281 | + $output .= '<div class="update-nag"><strong>' . __('Please upgrade the CoolClock - Advanced extension.', 'coolclock') . '</strong> '. ' <a href="https://premium.status301.com/account/" target="_blank">' . __('Please log in with your account credentials here.', 'coolclock') . '</a>' . __('You can download the new version using the link in the downloads list.', 'coolclock') . '</div>'; | |
| 244 | 282 | } |
| 245 | 283 | |
| 246 | - echo $output; | |
| 247 | - | |
| 284 | + // wp_kses_post() strips form controls (input/select/option/textarea/style), | |
| 285 | + // which would silently break this settings screen. Extend the allowed | |
| 286 | + // tags with what an admin settings form actually needs instead. | |
| 287 | + $allowed_html = array_merge( | |
| 288 | + wp_kses_allowed_html( 'post' ), | |
| 289 | + array( | |
| 290 | + 'style' => array( 'type' => true ), | |
| 291 | + 'input' => array( | |
| 292 | + 'id' => true, | |
| 293 | + 'class' => true, | |
| 294 | + 'name' => true, | |
| 295 | + 'type' => true, | |
| 296 | + 'value' => true, | |
| 297 | + 'min' => true, | |
| 298 | + 'step' => true, | |
| 299 | + 'checked' => true, | |
| 300 | + ), | |
| 301 | + 'select' => array( | |
| 302 | + 'id' => true, | |
| 303 | + 'class' => true, | |
| 304 | + 'name' => true, | |
| 305 | + ), | |
| 306 | + 'option' => array( | |
| 307 | + 'value' => true, | |
| 308 | + 'selected' => true, | |
| 309 | + ), | |
| 310 | + 'textarea' => array( | |
| 311 | + 'id' => true, | |
| 312 | + 'class' => true, | |
| 313 | + 'name' => true, | |
| 314 | + ), | |
| 315 | + ) | |
| 316 | + ); | |
| 317 | + echo wp_kses( $output, $allowed_html ); | |
| 248 | 318 | } |
| 249 | 319 | } |