__('Adds Analog Clock to sidebar', 'analog-clock-widget') ) );
$this->clock_aligns = array(
'none' => __('none', 'analog-clock-widge'),
'left' => __('left', 'analog-clock-widge'),
'center' => __('center', 'analog-clock-widge'),
'right' => __('right', 'analog-clock-widge')
);
add_action('wp_enqueue_scripts', array($this, 'widgets_scripts'));
add_action( 'admin_enqueue_scripts', array($this, 'admin_scripts') );
}
// Enqueue scripts.
function widgets_scripts(){
if(!self::$did_script && is_active_widget(false, false, $this->id_base, true)){
wp_register_script('raphael-min', CURRENCYR_PLUGIN_URL . 'js/raphael-min.js', array( 'jquery' ), CURRENCYR_VERSION );
wp_enqueue_script('raphael-min');
wp_register_script('analog-clock-widget', CURRENCYR_PLUGIN_URL . 'js/analog-clock-widget.js', array( 'jquery' ), CURRENCYR_VERSION );
wp_enqueue_script('analog-clock-widget');
self::$did_script = true;
}
}
// Admin Panel Enqueue scripts.
function admin_scripts( $hook ) {
if ( 'widgets.php' != $hook ) {
return;
}
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker' );
wp_enqueue_script( 'underscore' );
}
// Get Time of location
public function getDateInfo($lng, $lat, $username) {
if(!$lng || !$lat || !$username){
return true;
}
$url = "http://api.geonames.org/timezone?lat=$lat&lng=$lng&username=$username";
try {
$timedata = file_get_contents($url);
$sxml = simplexml_load_string($timedata);
if($sxml->timezone->time){
$local_time = strtotime($sxml->timezone->time);
return array('error' => 0, 'date' => date("F j,Y H:i", $local_time));
}elseif(isset($sxml->status) && isset($sxml->status['message'])){
return array('error' => 1, 'message' => ucfirst($sxml->status['message']));
}
return true;
} catch (Exception $exc) {
return true;
}
}
// Widget output.
public function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
echo $args['before_widget'];
if ( ! empty( $title ) )
echo $args['before_title'] . $title . $args['after_title'];
if(!$instance['longitude'] && !$instance['latitude'] && !$instance['username']) {
$local_time = false;
} else {
$local_time = $this->getDateInfo($instance['longitude'], $instance['latitude'], $instance['username']);
}
if(is_array($local_time)){
if($local_time['error']){
echo $local_time['message'];
return;
} else {
$local_time = $local_time['date'];
}
} elseif($local_time){
echo __('Error! Please Validate your fields.', 'analog-clock-widget');
echo $args['after_widget'];
return;
}
?>
GeoNames.org. You will then receive an email with a confirmation link and after you have confirmed the email you can enable your account for the webservice on your account page.', 'analog-clock-widget'); ?>