| 1 |
<?php |
| 2 |
/* |
| 3 |
Plugin Name: CoolClock |
| 4 |
Plugin URI: http://status301.net/wordpress-plugins/coolclock/ |
| 5 |
Description: Add an analog clock to your sidebar. |
| 6 |
Text Domain: coolclock |
| 7 |
Domain Path: languages |
| 8 |
Version: 0.1 |
| 9 |
Author: RavanH |
| 10 |
Author URI: http://status301.net/ |
| 11 |
*/ |
| 12 |
|
| 13 |
/** |
| 14 |
* CoolClock Widget Class |
| 15 |
*/ |
| 16 |
class CoolClock_Widget extends WP_Widget { |
| 17 |
|
| 18 |
/** constructor -- name this the same as the class above */ |
| 19 |
function CoolClock_Widget() { |
| 20 |
parent::WP_Widget( |
| 21 |
'coolclock-widget', |
| 22 |
__('Analog Clock', 'coolclock'), |
| 23 |
array( |
| 24 |
'classname' => 'coolclock', |
| 25 |
'description' => __('Add an analog clock to your sidebar.', 'coolclock') |
| 26 |
), |
| 27 |
array( |
| 28 |
'width' => 300, |
| 29 |
/*'height' => 350, */ |
| 30 |
'id_base' => 'coolclock-widget' |
| 31 |
) |
| 32 |
); |
| 33 |
} |
| 34 |
|
| 35 |
/** @see WP_Widget::widget -- do not rename this */ |
| 36 |
function widget($args, $instance) { |
| 37 |
extract( $args ); |
| 38 |
$title = apply_filters('widget_title', $instance['title']); |
| 39 |
$skin = ( isset($instance['skin']) ) ? $instance['skin'] : 'swissRail'; |
| 40 |
$radius = ( isset($instance['radius']) ) ? $instance['radius'] : 85 ; |
| 41 |
$clock_height = ( $radius ) ? 2*$radius.'px' : '170px'; |
| 42 |
$clock_width = ( $radius ) ? 2*$radius.'px' : '170px'; |
| 43 |
|
| 44 |
$background_height = ( isset($instance['background_height']) && $instance['background_height'] != '' ) ? $instance['background_height'].'px' : $clock_height; |
| 45 |
$background_width = ( isset($instance['background_width']) && $instance['background_width'] != '' ) ? $instance['background_width'].'px' : '100%'; |
| 46 |
//$background_color = ( isset($instance['background_color']) ) ? $instance['background_color'] : 'transparent'; |
| 47 |
$vertical_position_dist = ( isset($instance['vertical_position_dist']) ) ? $instance['vertical_position_dist'].'px' : '0'; |
| 48 |
$horizontal_position_dist = ( isset($instance['horizontal_position_dist']) ) ? $instance['horizontal_position_dist'].'px' : '0'; |
| 49 |
|
| 50 |
// add custom skin parameters to the plugin skins array |
| 51 |
if ( 'custom_'.$this->number == $skin ) |
| 52 |
CoolClock::$advanced_skins_config[$skin] = $instance['custom_skin']; |
| 53 |
|
| 54 |
// set footer script flags |
| 55 |
CoolClock::$add_script = true; |
| 56 |
if ( in_array( $skin, CoolClock::$more_skins ) ) |
| 57 |
CoolClock::$add_moreskins = true; |
| 58 |
if ( isset( CoolClock::$advanced_skins_config[$skin] ) ) |
| 59 |
CoolClock::$add_customskins = true; |
| 60 |
|
| 61 |
?> |
| 62 |
<?php echo $before_widget; ?> |
| 63 |
<?php if ( $title ) |
| 64 |
echo $before_title . $title . $after_title; ?> |
| 65 |
<div style="<?php if ( isset($instance['background_image']) && $instance['background_image'] != '' ) { echo 'background-image:url(\''.$instance['background_image'].'\');'; ?><?php if ( isset($instance['background_position']) ) echo 'background-position:'.$instance['background_position'].';'; ?><?php if ( isset($instance['background_repeat']) && $instance['background_repeat'] == false ) echo 'background-repeat:no-repeat;'; } ?>height:<?php echo $background_height; ?>;width:<?php echo $background_width; ?>;position:relative<?php //if ( isset($instance['background_color']) ) echo ';background-color:'.$instance['background_color']; ?>"> |
| 66 |
<div style="position:absolute;<?php if ( isset($instance['vertical_position_from']) ) echo $instance['vertical_position_from'] . ':' . $vertical_position_dist . ';'; ?><?php if ( isset($instance['horizontal_position_from']) ) echo $instance['horizontal_position_from'] . ':' . $horizontal_position_dist . ';'; ?>height:<?php echo $clock_height; ?>;width:<?php echo $clock_width; ?>"> |
| 67 |
<canvas class="CoolClock:<?php echo $skin; ?>:<?php echo $radius; ?>:<?php if ( $instance['noseconds'] ) echo 'noSeconds'; ?>:<?php if ( $instance['gmtoffset'] ) echo $instance['gmtoffset']; ?>:<?php if ( $instance['showdigital'] ) echo 'showDigital'; ?>"></canvas> |
| 68 |
</div> |
| 69 |
</div> |
| 70 |
|
| 71 |
<?php echo $after_widget; ?> |
| 72 |
<?php |
| 73 |
} |
| 74 |
|
| 75 |
/** @see WP_Widget::update -- do not rename this */ |
| 76 |
function update($new_instance, $old_instance) { |
| 77 |
|
| 78 |
$instance = $old_instance; |
| 79 |
|
| 80 |
return CoolClock::update($instance, $new_instance); |
| 81 |
} |
| 82 |
|
| 83 |
/** @see WP_Widget::form -- do not rename this */ |
| 84 |
function form($instance) { |
| 85 |
|
| 86 |
CoolClock::form($this, $instance, $defaults); |
| 87 |
} |
| 88 |
|
| 89 |
} // end class example_widget |
| 90 |
|
| 91 |
/** |
| 92 |
* CoolClock Class |
| 93 |
*/ |
| 94 |
class CoolClock { |
| 95 |
static $add_script; |
| 96 |
|
| 97 |
static $add_moreskins; |
| 98 |
|
| 99 |
static $add_customskins; |
| 100 |
|
| 101 |
static $defaults = array ( |
| 102 |
'skin' => 'swissRail', |
| 103 |
'radius' => 100, |
| 104 |
'noseconds' => false, // Hide seconds |
| 105 |
'gmtoffset' => '', // GMT offset |
| 106 |
'showdigital' => false, // Show digital time |
| 107 |
); |
| 108 |
|
| 109 |
static $advanced; |
| 110 |
|
| 111 |
static $advanced_defaults = array (); |
| 112 |
|
| 113 |
static $default_skins = array ( |
| 114 |
'swissRail', |
| 115 |
'chunkySwiss', |
| 116 |
'chunkySwissOnBlack' |
| 117 |
); |
| 118 |
|
| 119 |
static $more_skins = array ( |
| 120 |
'fancy', |
| 121 |
'machine', |
| 122 |
'simonbaird_com', |
| 123 |
'classic', |
| 124 |
'modern', |
| 125 |
'simple', |
| 126 |
'securephp', |
| 127 |
'Tes2', |
| 128 |
'Lev', |
| 129 |
'Sand', |
| 130 |
'Sun', |
| 131 |
'Tor', |
| 132 |
'Cold', |
| 133 |
'Babosa', |
| 134 |
'Tumb', |
| 135 |
'Stone', |
| 136 |
'Disc', |
| 137 |
'watermelon' |
| 138 |
); |
| 139 |
|
| 140 |
static $advanced_skins = array (); |
| 141 |
|
| 142 |
static $advanced_skins_config = array (); |
| 143 |
|
| 144 |
static function update($instance, $new_instance) { |
| 145 |
|
| 146 |
$instance['title'] = strip_tags($new_instance['title']); |
| 147 |
$instance['skin'] = strip_tags($new_instance['skin']); |
| 148 |
$instance['custom_skin'] = strip_tags($new_instance['custom_skin']); |
| 149 |
$instance['radius'] = ( (int) $new_instance['radius'] < 5 ) ? 5 : (int) $new_instance['radius']; |
| 150 |
$instance['noseconds'] = (bool) $new_instance['noseconds']; |
| 151 |
$instance['gmtoffset'] = ( !$new_instance['gmtoffset'] ) ? '' : (float) $new_instance['gmtoffset']; |
| 152 |
$instance['showdigital'] = (bool) $new_instance['showdigital']; |
| 153 |
|
| 154 |
if ( class_exists('CoolClockAdvanced') ) |
| 155 |
$instance = CoolClockAdvanced::update($instance, $new_instance); |
| 156 |
|
| 157 |
return $instance; |
| 158 |
} |
| 159 |
|
| 160 |
static function form($obj, $instance, $defaults) { |
| 161 |
|
| 162 |
$defaults = array ( |
| 163 |
'title' => '', |
| 164 |
'custom_skin' => '', |
| 165 |
); |
| 166 |
|
| 167 |
$defaults = array_merge($defaults, CoolClock::$defaults, CoolClock::$advanced_defaults); |
| 168 |
|
| 169 |
$instance = wp_parse_args( (array) $instance, $defaults ); |
| 170 |
|
| 171 |
$title = esc_attr( $instance['title'] ); |
| 172 |
$custom_skin = esc_attr( $instance['custom_skin'] ); |
| 173 |
|
| 174 |
// Translatable skin names go here |
| 175 |
$skin_names = array ( |
| 176 |
'swissRail' => __('Swiss Rail','coolclock'), |
| 177 |
'chunkySwiss' => __('Chunky Swiss','coolclock'), |
| 178 |
'chunkySwissOnBlack' => __('Chunky Swiss Black','coolclock'), |
| 179 |
'fancy' => __('Fancy','coolclock'), |
| 180 |
'machine' => __('Machine','coolclock'), |
| 181 |
'simonbaird_com' => __('SimonBaird.com','coolclock'), |
| 182 |
'classic' => __('Classic by Bonstio','coolclock'), |
| 183 |
'modern' => __('Modern by Bonstio','coolclock'), |
| 184 |
'simple' => __('Simple by Bonstio','coolclock'), |
| 185 |
'securephp' => __('SecurePHP','coolclock'), |
| 186 |
'Tes2' => __('Tes2','coolclock'), |
| 187 |
'Lev' => __('Lev','coolclock'), |
| 188 |
'Sand' => __('Sand','coolclock'), |
| 189 |
'Sun' => __('Sun','coolclock'), |
| 190 |
'Tor' => __('Tor','coolclock'), |
| 191 |
'Cold' => __('Cold','coolclock'), |
| 192 |
'Babosa' => __('Babosa','coolclock'), |
| 193 |
'Tumb' => __('Tumb','coolclock'), |
| 194 |
'Stone' => __('Stone','coolclock'), |
| 195 |
'Disc' => __('Disc','coolclock'), |
| 196 |
'watermelon' => __('Watermelon by Yoo Nhe','coolclock'), |
| 197 |
'minimal' => __('Minimal','coolclock') |
| 198 |
); |
| 199 |
|
| 200 |
$skins = array_merge(CoolClock::$default_skins,CoolClock::$more_skins,CoolClock::$advanced_skins); |
| 201 |
|
| 202 |
?> |
| 203 |
<p> |
| 204 |
<label for="<?php echo $obj->get_field_id('title'); ?>"><?php _e('Title:'); ?> </label> |
| 205 |
<input class="widefat" id="<?php echo $obj->get_field_id('title'); ?>" name="<?php echo $obj->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /> |
| 206 |
</p> |
| 207 |
|
| 208 |
<p><strong><?php _e('Clock', 'coolclock'); ?></strong></p> |
| 209 |
|
| 210 |
<p><label for="<?php echo $obj->get_field_id('skin'); ?>"><?php _e('Skin:', 'coolclock'); ?> </label> |
| 211 |
<select class="select" id="<?php echo $obj->get_field_id('skin'); ?>" name="<?php echo $obj->get_field_name('skin'); ?>"><?php foreach ($skins as $value) { echo "<option value=\"$value\""; if ($value == $instance['skin']) echo ' selected="selected"'; echo '>'; if ( isset($skin_names[$value]) ) echo $skin_names[$value]; else echo $value; echo'</option>'; } unset($value); ?><option value="custom_<?php echo $obj->number ?>"<?php if ( 'custom_'.$obj->number == $instance['skin']) echo ' selected="selected"'; ?>><?php _e('Custom (define below)', 'coolclock') ?></option></select></p> |
| 212 |
|
| 213 |
<p><label for="<?php echo $obj->get_field_id('custom_skin'); ?>"><?php _e('Custom skin parameters:', 'coolclock'); ?> </label> |
| 214 |
<textarea class="widefat" id="<?php echo $obj->get_field_id('custom_skin'); ?>" name="<?php echo $obj->get_field_name('custom_skin'); ?>"><?php echo $custom_skin; ?></textarea></p> |
| 215 |
|
| 216 |
<p><label for="<?php echo $obj->get_field_id('radius'); ?>"><?php _e('Radius:', 'coolclock'); ?></label> |
| 217 |
<input class="small-text" id="<?php echo $obj->get_field_id('radius'); ?>" name="<?php echo $obj->get_field_name('radius'); ?>" type="number" min="10" value="<?php echo $instance['radius']; ?>" /></p> |
| 218 |
|
| 219 |
<p><input id="<?php echo $obj->get_field_id('noseconds'); ?>" name="<?php echo $obj->get_field_name('noseconds'); ?>" type="checkbox" value=<?php echo ( $instance['noseconds'] ) ? '"true" checked="checked"' : '"false"'; ?> /> |
| 220 |
<label for="<?php echo $obj->get_field_id('noseconds'); ?>"><?php _e('Hide second hand', 'coolclock'); ?></label></p> |
| 221 |
|
| 222 |
<p><input id="<?php echo $obj->get_field_id('showdigital'); ?>" name="<?php echo $obj->get_field_name('showdigital'); ?>" type="checkbox" value=<?php echo ( $instance['showdigital'] ) ? '"true" checked="checked"' : '"false"'; ?> /> |
| 223 |
<label for="<?php echo $obj->get_field_id('showdigital'); ?>"><?php _e('Show digital time', 'coolclock'); ?></label></p> |
| 224 |
|
| 225 |
<p><label for="<?php echo $obj->get_field_id('gmtoffset'); ?>"><?php _e('GMT offset:', 'coolclock'); ?></label> |
| 226 |
<input class="small-text" id="<?php echo $obj->get_field_id('gmtoffset'); ?>" name="<?php echo $obj->get_field_name('gmtoffset'); ?>" type="number" step="0.5" value="<?php echo $instance['gmtoffset']; ?>" /> <?php _e('(leave blank for local time)', 'coolclock'); ?></p> |
| 227 |
|
| 228 |
<?php |
| 229 |
|
| 230 |
if ( class_exists('CoolClockAdvanced') ) { |
| 231 |
CoolClockAdvanced::form($obj, $instance, $defaults); |
| 232 |
} else { |
| 233 |
?> |
| 234 |
<p><strong><?php _e('Background'); ?></strong></p> |
| 235 |
|
| 236 |
<p><a href="http://status301.net/wordpress-plugins/coolclock-pro/"><?php _e('Available in the Pro extension »', 'coolclock'); ?></a></p> |
| 237 |
<?php |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
static function init() { |
| 242 |
load_plugin_textdomain('coolclock', false, dirname(plugin_basename( __FILE__ )).'/languages'); |
| 243 |
add_action('widgets_init', create_function('', 'return register_widget("CoolClock_Widget");')); |
| 244 |
|
| 245 |
//add_shortcode('myshortcode', array(__CLASS__, 'handle_shortcode')); |
| 246 |
|
| 247 |
add_action('init', array(__CLASS__, 'register_script')); |
| 248 |
add_action('wp_footer', array(__CLASS__, 'print_script')); |
| 249 |
} |
| 250 |
|
| 251 |
static function handle_shortcode($atts) { |
| 252 |
self::$add_script = true; |
| 253 |
|
| 254 |
// actual shortcode handling here |
| 255 |
} |
| 256 |
|
| 257 |
static function register_script() { |
| 258 |
wp_register_script('coolclock', 'http://randomibis.com/coolclock/coolclock.js', array('jquery'), '2.1.4', true); |
| 259 |
wp_register_script('coolclock-moreskins', 'http://randomibis.com/coolclock/moreskins.js', array('coolclock'), '2.1.4', true); |
| 260 |
} |
| 261 |
|
| 262 |
static function print_script() { |
| 263 |
if ( ! self::$add_script ) |
| 264 |
return; |
| 265 |
|
| 266 |
wp_print_scripts('coolclock'); |
| 267 |
|
| 268 |
if ( self::$add_moreskins ) |
| 269 |
wp_print_scripts('coolclock-moreskins'); |
| 270 |
|
| 271 |
if ( self::$add_customskins ) { |
| 272 |
echo '<script type="text/javascript">jQuery.extend(CoolClock.config.skins, { |
| 273 |
'; |
| 274 |
// loop through plugin custom skins |
| 275 |
foreach (self::$advanced_skins_config as $key => $value) |
| 276 |
echo $key.':{'.$value.'}, |
| 277 |
'; |
| 278 |
echo '});</script> |
| 279 |
'; |
| 280 |
} |
| 281 |
|
| 282 |
echo '<!--[if lt IE 9]><script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/flot/0.7/excanvas.min.js"></script><![endif]--> |
| 283 |
'; |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
CoolClock::init(); |
| 288 |
|
| 289 |
|