| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* CoolClock Class |
| 5 |
*/ |
| 6 |
|
| 7 |
class CoolClock { |
| 8 |
|
| 9 |
static $plugin_version = '4.0'; |
| 10 |
|
| 11 |
static $script_version = '3.0.0'; |
| 12 |
|
| 13 |
private static $plugin_url; |
| 14 |
|
| 15 |
private static $plugin_basename; |
| 16 |
|
| 17 |
private static $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 |
); |
| 33 |
|
| 34 |
static $showdigital_options = array ( |
| 35 |
'' => '', |
| 36 |
'digital12' => 'showDigital' |
| 37 |
); |
| 38 |
|
| 39 |
static $advanced; |
| 40 |
|
| 41 |
static $advanced_defaults = array ( |
| 42 |
'subtext' => '', |
| 43 |
'align' => 'center' |
| 44 |
); |
| 45 |
|
| 46 |
static $default_skins = ['swissRail','chunkySwiss','chunkySwissOnBlack']; |
| 47 |
|
| 48 |
static $more_skins = ['fancy','machine','simonbaird_com','classic','modern','simple','securephp','Tes2','Lev','Sand','Sun','Tor','Cold','Babosa','Tumb','Stone','Disc','watermelon','mister']; |
| 49 |
|
| 50 |
static $advanced_skins = []; |
| 51 |
|
| 52 |
static $advanced_skins_config = []; |
| 53 |
|
| 54 |
static $clock_types = array ( |
| 55 |
'linear' => '', |
| 56 |
'logClock' => 'logClock', |
| 57 |
'logClockRev' => 'logClockRev' |
| 58 |
); |
| 59 |
|
| 60 |
/** |
| 61 |
* MAIN |
| 62 |
*/ |
| 63 |
|
| 64 |
public static function canvas( $atts ) { |
| 65 |
extract( $atts ); |
| 66 |
|
| 67 |
$output = ''; |
| 68 |
|
| 69 |
if ( ! self::$done_excanvas ){ |
| 70 |
$output .= '<!--[if lte IE 8]>'; |
| 71 |
$output .= '<script type=\'text/javascript\' src=\'' . self::$plugin_url . 'js/excanvas' . self::$min . '.js\'></script>'; |
| 72 |
$output .= '<![endif]-->' . PHP_EOL; |
| 73 |
self::$done_excanvas = true; |
| 74 |
} |
| 75 |
|
| 76 |
$output .= '<div class="coolclock'; |
| 77 |
|
| 78 |
// align class ans style |
| 79 |
$output .= ( $align ) ? ' align' . $align : ''; |
| 80 |
$output .= '" style="width:' . 2 * $radius . 'px;max-width:100%;height:auto">'; |
| 81 |
// canvas parameters |
| 82 |
$output .= '<canvas class="CoolClock:' . $skin . ':' . $radius . ':'; |
| 83 |
$output .= ( $noseconds == 'true' || $noseconds == '1' ) ? 'noSeconds:' : ':'; |
| 84 |
$output .= $gmtoffset; |
| 85 |
|
| 86 |
// show digital |
| 87 |
if ( $showdigital == 'true' || $showdigital == '1' ) |
| 88 |
$showdigital = 'digital12'; // backward compat |
| 89 |
|
| 90 |
if ( isset(self::$showdigital_options[$showdigital]) ) |
| 91 |
$output .= ':'.self::$showdigital_options[$showdigital]; |
| 92 |
else |
| 93 |
$output .= ':'; |
| 94 |
|
| 95 |
// set type |
| 96 |
if ( isset(self::$clock_types[$scale]) ) |
| 97 |
$output .= ':'.self::$clock_types[$scale]; |
| 98 |
else |
| 99 |
$output .= ':'; |
| 100 |
|
| 101 |
$output .= '"></canvas>'; |
| 102 |
$output .= ( $subtext ) ? '<div style="width:100%;text-align:center;padding-bottom:10px">' . $subtext . '</div></div>' : '</div>'; |
| 103 |
|
| 104 |
return $output; |
| 105 |
} |
| 106 |
|
| 107 |
public static function enqueue_scripts() { |
| 108 |
if ( ! self::$add_script ) |
| 109 |
return; |
| 110 |
|
| 111 |
wp_enqueue_script( 'coolclock', self::$plugin_url . 'js/coolclock' . self::$min . '.js', array('jquery'), self::$script_version, true ); |
| 112 |
|
| 113 |
if ( self::$add_moreskins ) |
| 114 |
wp_enqueue_script( 'coolclock-moreskins', self::$plugin_url . 'js/moreskins' . self::$min . '.js', array('coolclock'), self::$script_version, true ); |
| 115 |
|
| 116 |
if ( is_array( self::$advanced_skins_config ) && !empty( self::$advanced_skins_config ) ) { |
| 117 |
$script = 'jQuery.extend(CoolClock.config.skins, {' . PHP_EOL; |
| 118 |
// loop through plugin custom skins |
| 119 |
foreach (self::$advanced_skins_config as $key => $value) |
| 120 |
$script .= $key.':{'.$value.'},' . PHP_EOL; |
| 121 |
$script .= '});'; |
| 122 |
|
| 123 |
if ( self::$add_moreskins ) |
| 124 |
wp_add_inline_script( 'coolclock-moreskins', $script ); |
| 125 |
else |
| 126 |
wp_add_inline_script( 'coolclock', $script ); |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
public static function textdomain() { |
| 131 |
load_plugin_textdomain( 'coolclock', false, dirname(self::$plugin_basename).'/languages' ); |
| 132 |
} |
| 133 |
|
| 134 |
public static function register_widget() { |
| 135 |
register_widget("CoolClock_Widget"); |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* INIT |
| 140 |
*/ |
| 141 |
|
| 142 |
public function __construct( $file ) { |
| 143 |
// VARS |
| 144 |
self::$plugin_url = plugins_url( '/', $file ); |
| 145 |
self::$plugin_basename = plugin_basename( $file ); |
| 146 |
|
| 147 |
if ( defined('WP_DEBUG') && WP_DEBUG ) { |
| 148 |
self::$min = '.min'; |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
} |
| 153 |
|