| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* CoolClock Widget Class |
| 5 |
*/ |
| 6 |
|
| 7 |
class CoolClock_Widget extends WP_Widget { |
| 8 |
|
| 9 |
/** PHP5+ constructor */ |
| 10 |
public function __construct() { |
| 11 |
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 |
); |
| 23 |
} |
| 24 |
|
| 25 |
/** @see WP_Widget::widget -- do not rename this */ |
| 26 |
public function widget( $args, $instance ) { |
| 27 |
extract( $args ); |
| 28 |
$title = !empty($instance['title']) ? apply_filters( 'widget_title', $instance['title'] ) : ''; |
| 29 |
$number = $this->number; |
| 30 |
|
| 31 |
// Print output |
| 32 |
echo $before_widget; |
| 33 |
|
| 34 |
if ( $title ) |
| 35 |
echo $before_title . $title . $after_title; |
| 36 |
|
| 37 |
// set skin |
| 38 |
$skin = ( isset( $instance['skin'] ) ) |
| 39 |
? $instance['skin'] : CoolClock::$defaults['skin']; |
| 40 |
|
| 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 ); |
| 44 |
|
| 45 |
// set footer script flags |
| 46 |
CoolClock::$add_script = true; |
| 47 |
|
| 48 |
if ( in_array( $skin, CoolClock::$more_skins ) ) |
| 49 |
CoolClock::$add_moreskins = true; |
| 50 |
|
| 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 |
) ); |
| 62 |
|
| 63 |
echo apply_filters( 'coolclock_widget_advanced', $output, $args, $instance ); |
| 64 |
|
| 65 |
echo $after_widget; |
| 66 |
} |
| 67 |
|
| 68 |
/** @see WP_Widget::update -- do not rename this */ |
| 69 |
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'] ) : ''; |
| 73 |
$instance['radius'] = ( empty($new_instance['radius']) || (int) $new_instance['radius'] < 5 ) ? 5 : (int) $new_instance['radius']; |
| 74 |
$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'] ) : ''; |
| 80 |
|
| 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 ); |
| 88 |
} |
| 89 |
|
| 90 |
/** @see WP_Widget::form -- do not rename this */ |
| 91 |
public function form( $instance ) { |
| 92 |
// Print output |
| 93 |
//echo CoolClock::form( $this, $instance ); |
| 94 |
$defaults = array_merge( array('title'=>'','custom_skin'=>''), CoolClock::$defaults, CoolClock::$advanced_defaults ); |
| 95 |
|
| 96 |
$instance = wp_parse_args( (array) $instance, $defaults ); |
| 97 |
|
| 98 |
$title = esc_attr( $instance['title'] ); |
| 99 |
$subtext = esc_attr( $instance['subtext'] ); |
| 100 |
$custom_skin = esc_attr( $instance['custom_skin'] ); |
| 101 |
|
| 102 |
// Translatable skin names go here |
| 103 |
$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 |
); |
| 128 |
|
| 129 |
$skins = array_merge( CoolClock::$default_skins, CoolClock::$more_skins, CoolClock::$advanced_skins ); |
| 130 |
|
| 131 |
// Translatable type names go here |
| 132 |
$type_names = array ( |
| 133 |
'linear' => __('Linear','coolclock'), |
| 134 |
'logClock' => __('Logarithmic','coolclock'), |
| 135 |
'logClockRev' => __('Logarithmic reversed','coolclock') |
| 136 |
); |
| 137 |
|
| 138 |
// Translatable show digital options go here |
| 139 |
$showdigital_names = array ( |
| 140 |
'' => __('none','coolclock'), |
| 141 |
'digital12' => __('time (am/pm)','coolclock'), |
| 142 |
'digital24' => __('time (24h)','coolclock'), |
| 143 |
'date' => __('date','coolclock') |
| 144 |
); |
| 145 |
|
| 146 |
// Misc translations |
| 147 |
$stray = array( |
| 148 |
'extra_settings' => __('Extra settings for the CoolClock widget.', 'coolclock') |
| 149 |
); |
| 150 |
|
| 151 |
// 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> '; |
| 154 |
$output .= '<input class="widefat" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $title . '" /></p>'; |
| 155 |
|
| 156 |
// Clock settings |
| 157 |
$output .= '<p><strong>' . __('Clock', 'coolclock') . '</strong></p>'; |
| 158 |
$output .= '<p><label for="' . $this->get_field_id('skin') . '">' . __('Skin:', 'coolclock') . '</label> '; |
| 159 |
$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; |
| 164 |
$output .= '</option>'; |
| 165 |
} unset($value); |
| 166 |
$output .= '<option value="custom_' . $this->number . '"'; |
| 167 |
$output .= ( 'custom_'.$this->number == $instance['skin'] ) ? ' selected="selected">' : '>'; |
| 168 |
$output .= __('Custom (define below)', 'coolclock') . '</option></select></p>'; |
| 169 |
|
| 170 |
// Custom skin field |
| 171 |
$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>'; |
| 173 |
|
| 174 |
// Radius |
| 175 |
$output .= '<p><label for="' . $this->get_field_id('radius') . '">' . __('Radius:', 'coolclock') . '</label> '; |
| 176 |
$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 |
|
| 178 |
// Second hand |
| 179 |
$output .= '<p><input id="' . $this->get_field_id('noseconds') . '" name="' . $this->get_field_name('noseconds') . '" type="checkbox" value='; |
| 180 |
$output .= ( $instance['noseconds'] ) ? '"true" checked="checked" />' : '"false" />'; |
| 181 |
$output .= ' <label for="' . $this->get_field_id('noseconds') . '">' . __('Hide second hand', 'coolclock') . '</label></p>'; |
| 182 |
|
| 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 |
// Align |
| 195 |
$output .= '<p><label for="' . $this->get_field_id('align') . '">' . __('Align:', 'coolclock') . '</label> '; |
| 196 |
$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">' : '>'; |
| 202 |
$output .= __('left', 'coolclock') . '</option>'; |
| 203 |
$output .= '<option value="right"'; |
| 204 |
$output .= ( $instance['align'] == 'right' ) ? ' selected="selected">' : '>'; |
| 205 |
$output .= __('right', 'coolclock') . '</option>'; |
| 206 |
$output .= '<option value="center"'; |
| 207 |
$output .= ( $instance['align'] == 'center' ) ? ' selected="selected">' : '>'; |
| 208 |
$output .= __('center', 'coolclock') . '</option>'; |
| 209 |
$output .= '</select></p>'; |
| 210 |
|
| 211 |
// Subtext |
| 212 |
$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>'; |
| 214 |
|
| 215 |
// Use GMT offset |
| 216 |
$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>'; |
| 218 |
|
| 219 |
// Show digital |
| 220 |
if ( $instance['showdigital'] == 'true' || $instance['showdigital'] == '1' ) |
| 221 |
$instance['showdigital'] = 'digital12'; // backward compat |
| 222 |
|
| 223 |
$output .= '<p><label for="' . $this->get_field_id('showdigital') . '">' . __('Show digital:', 'coolclock') . '</label> '; |
| 224 |
$output .= '<select class="select" id="' . $this->get_field_id('showdigital') . '" name="' . $this->get_field_name('showdigital') . '">'; |
| 225 |
foreach ( CoolClock::$showdigital_options as $key => $value ) { |
| 226 |
$output .= '<option value="' . $key . '"'; |
| 227 |
$output .= ( $key == $instance['showdigital'] ) ? ' selected="selected">' : '>'; |
| 228 |
$output .= ( isset($showdigital_names[$key]) ) ? $showdigital_names[$key] : $value; |
| 229 |
$output .= '</option>'; |
| 230 |
} |
| 231 |
$output .= '</select></p>'; |
| 232 |
|
| 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>'; |
| 235 |
|
| 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>'; |
| 238 |
|
| 239 |
// Advanced filter |
| 240 |
$output .= apply_filters( 'coolclock_widget_form_advanced', $advanced, $this, $instance, $defaults ); |
| 241 |
|
| 242 |
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>'; |
| 244 |
} |
| 245 |
|
| 246 |
echo $output; |
| 247 |
|
| 248 |
} |
| 249 |
} |
| 250 |
|