| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* CoolClock Class |
| 5 |
*/ |
| 6 |
|
| 7 |
class CoolClock { |
| 8 |
|
| 9 |
static $plugin_version; |
| 10 |
|
| 11 |
static $script_version = '3.1.0'; |
| 12 |
|
| 13 |
private static $plugin_url; |
| 14 |
|
| 15 |
private static $plugin_basename; |
| 16 |
|
| 17 |
private static $min = '.min'; |
| 18 |
|
| 19 |
static $add_script = false; |
| 20 |
|
| 21 |
static $add_moreskins = false; |
| 22 |
|
| 23 |
private static $done_excanvas = false; |
| 24 |
|
| 25 |
static $defaults = array( |
| 26 |
'skin' => 'swissRail', |
| 27 |
'radius' => 100, |
| 28 |
'noseconds' => false, // Hide seconds |
| 29 |
'gmtoffset' => '', // GMT offset |
| 30 |
'showdigital' => '', // Show digital time or date |
| 31 |
'scale' => 'linear', // Define type of clock linear/logarithmic/log reversed |
| 32 |
'digitalcolor' => '#333' |
| 33 |
); |
| 34 |
|
| 35 |
static $showdigital_options = array( |
| 36 |
'' => '', |
| 37 |
'digital12' => 'showDigital' |
| 38 |
); |
| 39 |
|
| 40 |
static $advanced = false; |
| 41 |
|
| 42 |
static $advanced_defaults = array( |
| 43 |
'subtext' => '', |
| 44 |
'align' => 'center' |
| 45 |
); |
| 46 |
|
| 47 |
static $default_skins = array('swissRail','chunkySwiss','chunkySwissOnBlack'); |
| 48 |
|
| 49 |
static $more_skins = array('fancy','machine','simonbaird_com','classic','modern','simple','securephp','Tes2','Lev','Sand','Sun','Tor','Cold','Babosa','Tumb','Stone','Disc','watermelon','mister'); |
| 50 |
|
| 51 |
static $advanced_skins = array(); |
| 52 |
|
| 53 |
static $advanced_skins_config = array(); |
| 54 |
|
| 55 |
static $clock_types = array( |
| 56 |
'linear' => '', |
| 57 |
'logClock' => 'logClock', |
| 58 |
'logClockRev' => 'logClockRev' |
| 59 |
); |
| 60 |
|
| 61 |
/** |
| 62 |
* MAIN |
| 63 |
*/ |
| 64 |
|
| 65 |
public static function canvas( $atts ) { |
| 66 |
extract( $atts ); |
| 67 |
|
| 68 |
$output = ''; |
| 69 |
|
| 70 |
if ( ! self::$done_excanvas ){ |
| 71 |
$output .= '<!--[if lte IE 8]>'; |
| 72 |
$output .= '<script type=\'text/javascript\' src=\'' . self::$plugin_url . 'js/excanvas' . self::$min . '.js\'></script>'; |
| 73 |
$output .= '<![endif]-->' . PHP_EOL; |
| 74 |
self::$done_excanvas = true; |
| 75 |
} |
| 76 |
|
| 77 |
$output .= '<div class="coolclock'; |
| 78 |
|
| 79 |
// align class ans style |
| 80 |
$output .= ( $align ) ? ' align' . $align : ''; |
| 81 |
$output .= '" style="width:' . 2 * $radius . 'px;max-width:100%;height:auto">'; |
| 82 |
// canvas parameters |
| 83 |
$output .= '<canvas class="CoolClock:' . $skin . ':' . $radius . ':'; |
| 84 |
$output .= ( $noseconds == 'true' || $noseconds == '1' ) ? 'noSeconds:' : ':'; |
| 85 |
$output .= $gmtoffset; |
| 86 |
|
| 87 |
// show digital |
| 88 |
if ( $showdigital == 'true' || $showdigital == '1' ) |
| 89 |
$showdigital = 'digital12'; // backward compat |
| 90 |
|
| 91 |
if ( isset(self::$showdigital_options[$showdigital]) ) |
| 92 |
$output .= ':'.self::$showdigital_options[$showdigital]; |
| 93 |
else |
| 94 |
$output .= ':'; |
| 95 |
|
| 96 |
// set type |
| 97 |
if ( isset(self::$clock_types[$scale]) ) |
| 98 |
$output .= ':'.self::$clock_types[$scale]; |
| 99 |
else |
| 100 |
$output .= ':'; |
| 101 |
|
| 102 |
// set font |
| 103 |
if ( isset($font) ) |
| 104 |
$output .= ':'.$font; |
| 105 |
else |
| 106 |
$output .= ':'; |
| 107 |
|
| 108 |
// set font color |
| 109 |
if ( isset($digitalcolor) ) |
| 110 |
$output .= ':'.$digitalcolor; |
| 111 |
else |
| 112 |
$output .= ':'; |
| 113 |
|
| 114 |
$output .= '"></canvas>'; |
| 115 |
$output .= ( $subtext ) ? '<div style="width:100%;text-align:center;padding-bottom:10px">' . $subtext . '</div></div>' : '</div>'; |
| 116 |
|
| 117 |
return $output; |
| 118 |
} |
| 119 |
|
| 120 |
public static function enqueue_scripts() { |
| 121 |
if ( ! self::$add_script ) |
| 122 |
return; |
| 123 |
|
| 124 |
wp_enqueue_script( 'coolclock', self::$plugin_url . 'js/coolclock' . self::$min . '.js', array('jquery'), self::$script_version, true ); |
| 125 |
|
| 126 |
if ( self::$add_moreskins ) |
| 127 |
wp_enqueue_script( 'coolclock-moreskins', self::$plugin_url . 'js/moreskins' . self::$min . '.js', array('coolclock'), self::$script_version, true ); |
| 128 |
|
| 129 |
if ( is_array( self::$advanced_skins_config ) && !empty( self::$advanced_skins_config ) ) { |
| 130 |
$script = 'jQuery.extend(CoolClock.config.skins, {' . PHP_EOL; |
| 131 |
// loop through plugin custom skins |
| 132 |
foreach (self::$advanced_skins_config as $key => $value) |
| 133 |
$script .= $key.':{'.$value.'},' . PHP_EOL; |
| 134 |
$script .= '});'; |
| 135 |
|
| 136 |
if ( self::$add_moreskins ) |
| 137 |
wp_add_inline_script( 'coolclock-moreskins', $script ); |
| 138 |
else |
| 139 |
wp_add_inline_script( 'coolclock', $script ); |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
public static function textdomain() { |
| 144 |
load_plugin_textdomain( 'coolclock', false, dirname(self::$plugin_basename).'/languages' ); |
| 145 |
} |
| 146 |
|
| 147 |
public static function register_widget() { |
| 148 |
register_widget("CoolClock_Widget"); |
| 149 |
} |
| 150 |
|
| 151 |
// add links to plugin's description |
| 152 |
public static function plugin_meta_links($links, $file) { |
| 153 |
$support_link = '<a target="_blank" href="https://wordpress.org/support/plugin/coolclock/">' . __('Support','coolclock') . '</a>'; |
| 154 |
$rate_link = '<a target="_blank" href="https://wordpress.org/support/plugin/coolclock/reviews/?filter=5#new-post">' . __('Rate � |
| 155 |
� |
| 156 |
� |
| 157 |
� |
| 158 |
� |
| 159 |
','coolclock') . '</a>'; |
| 160 |
|
| 161 |
if ( $file == self::$plugin_basename ) { |
| 162 |
$links[] = $support_link; |
| 163 |
$links[] = $rate_link; |
| 164 |
} |
| 165 |
|
| 166 |
return $links; |
| 167 |
} |
| 168 |
|
| 169 |
public static function colorval( $color ) |
| 170 |
{ |
| 171 |
$color = strip_tags( $color ); |
| 172 |
$color = trim( $color ); |
| 173 |
|
| 174 |
if (substr($color, 0, 1) == '#') { |
| 175 |
if ( ctype_xdigit(substr($color, 1)) ) |
| 176 |
return $color; |
| 177 |
|
| 178 |
return substr($color, 1); |
| 179 |
} |
| 180 |
|
| 181 |
return ctype_xdigit($color) ? '#'.$color : $color; |
| 182 |
} |
| 183 |
|
| 184 |
/** |
| 185 |
* INIT |
| 186 |
*/ |
| 187 |
|
| 188 |
public function __construct( $plugin_file, $plugin_version ) { |
| 189 |
// VARS |
| 190 |
self::$plugin_url = plugins_url( '/', $plugin_file ); |
| 191 |
self::$plugin_basename = plugin_basename( $plugin_file ); |
| 192 |
self::$plugin_version = $plugin_version; |
| 193 |
|
| 194 |
if ( defined('WP_DEBUG') && WP_DEBUG ) { |
| 195 |
self::$min = ''; |
| 196 |
} |
| 197 |
|
| 198 |
// text domain |
| 199 |
add_action( 'plugins_loaded', array( __CLASS__, 'textdomain' ) ); |
| 200 |
|
| 201 |
// widgets |
| 202 |
add_action( 'widgets_init', array( __CLASS__, 'register_widget' ) ); |
| 203 |
|
| 204 |
// enqueue scripts but only if shortcode or widget has been used |
| 205 |
// so it has to be done as late as the wp_footer action |
| 206 |
add_action( 'wp_footer', array( __CLASS__, 'enqueue_scripts' ), 1 ); |
| 207 |
|
| 208 |
add_filter( 'plugin_row_meta', array( __CLASS__, 'plugin_meta_links' ), 10, 2); |
| 209 |
|
| 210 |
/************** |
| 211 |
* SHORTCODE |
| 212 |
**************/ |
| 213 |
|
| 214 |
add_shortcode( 'coolclock', array( 'CoolClock_Shortcode', 'handle_shortcode' ) ); |
| 215 |
|
| 216 |
// prevent texturizing shortcode content |
| 217 |
add_filter( 'no_texturize_shortcodes', array( 'CoolClock_Shortcode', 'no_wptexturize') ); |
| 218 |
} |
| 219 |
|
| 220 |
} |
| 221 |
|