-
Notifications
You must be signed in to change notification settings - Fork 3
/
hm-time.php
127 lines (95 loc) · 3.51 KB
/
hm-time.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
* Plugin Name: Time
* Description: Define working hours / timezones for users
* Author: Jenny Wong
* Author URI: http://jwong.co.uk/
* Version: 0.1.0
* Plugin URI: https://github.com/humanmade/hm-time
* License: GPLv2 or later
*/
/* Copyright 2014
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
if ( ! defined( 'ABSPATH' ) ){
exit;
}
define ( 'PLUGIN_URL', plugin_dir_url ( __FILE__ ) );
register_activation_hook ( __FILE__, 'hm_time_install' );
register_deactivation_hook ( __FILE__, 'hm_time_uninstall' );
function hm_time_install (){
$hm_time_options = array (
'default_set_method' => 'manual',
'geoip_user_id' => '',
'geoip_license_key' => '',
'foursquare_client_id' => '',
'foursquare_client_secret' => '',
'foursquare_redirect_uri' => home_url( '/wp-json/hm-time/v1/auth' ),
'foursquare_push_secret' => '',
'foursquare_push_url' => admin_url( '/wp-json/hm-time/v1/push' ),
'foursquare_push_version' => '',
'google_timezone_api_key' => ''
);
$hm_time_options = apply_filters ( 'add_hm_time_options', $hm_time_options );
update_option ( 'hm_time_options', $hm_time_options );
}
function hm_time_uninstall (){
}
require_once ( 'includes/settings.php' );
require_once ( 'includes/user-profile-fields.php' );
require_once ( 'includes/api-users.php' );
$options = hm_time_options();
$geoip_user_id = $options['geoip_user_id'];
$geoip_license_key = $options['geoip_license_key'];
if ( ! empty ( $geoip_user_id ) && ! empty ( $geoip_license_key ) ){
require_once ( 'vendor/autoload.php' );
require_once ( 'includes/geoip.php' );
}
$foursquare = array ();
$foursquare['foursquare_client_id'] = $options['foursquare_client_id'];
$foursquare['foursquare_client_secret'] = $options['foursquare_client_secret'];
$foursquare['foursquare_redirect_uri'] = $options['foursquare_redirect_uri'];
$foursquare['foursquare_push_secret'] = $options['foursquare_push_secret'];
$foursquare['foursquare_push_url'] = $options['foursquare_push_url'];
$foursquare['foursquare_push_version'] = $options['foursquare_push_version'];
$foursquare['google_timezone_api_key'] = $options['google_timezone_api_key'];
foreach ( $foursquare as $key => $value ){
$foursquare[$key] = trim ( $value );
}
if( !in_array ( '', $foursquare ) ){
require_once ('includes/foursquare.php');
require_once ('includes/api-foursquare.php');
}
function hm_time_options ( $key = null, $format = null ){
$options = get_option ( 'hm_time_options' );
if ( !empty ( $key ) && array_key_exists ( $key, $options ) ){
return $options[$key];
}
switch ( $format ){
case 'string':
return '';
break;
case 'boolean':
return false;
break;
default:
return $options;
break;
}
}
function hm_time_timezone_options () {
$hm_time_set_method_array = array (
'manual' => 'Manual'
);
$hm_time_set_method_array = apply_filters( 'hm_time_set_method_array', $hm_time_set_method_array );
return $hm_time_set_method_array;
}