-
Notifications
You must be signed in to change notification settings - Fork 1
/
class-sublimevideo-admin.php
100 lines (84 loc) · 3.04 KB
/
class-sublimevideo-admin.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
<?php
class SublimeVideoAdmin {
static function init() {
wp_register_style('sublimevideo.css', SUBLIMEVIDEO_PLUGIN_URL.'assets/css/settings.css');
wp_enqueue_style('sublimevideo.css');
// register our settings
foreach (SublimeVideo::$user_editable_settings as $setting) {
register_setting('sv-settings-group', $setting);
}
}
public function __construct($api) {
$this->api = $api;
}
/* We need to handle hostname with subdomains (even www.).
* In my.sublimevideo.net, the "special" www. subdomain is removed though...
*/
public function available_sites() {
if (!isset($this->available_sites)) {
$sites = $this->api->sites();
$this->available_sites = array();
if (isset($sites)) {
$http_host = self::clean_http_host();
foreach ($sites as $site) {
$added = false;
$i = 0;
$public_domains = array_merge(array($site->main_domain), $site->extra_domains);
while (!$added && $i < count($public_domains)) {
if (
($site->wildcard && strstr($http_host, $public_domains[$i])) ||
($http_host == $public_domains[$i])
) {
$this->available_sites[] = $site;
$added = true;
}
$i++;
}
$i = 0;
while (!$added && $i < count($site->dev_domains)) {
if ($http_host == $site->dev_domains[$i]) {
$this->available_sites[] = $site;
$added = true;
}
$i++;
}
}
}
}
return $this->available_sites;
}
/* We need to handle hostname with subdomains (even www.).
* In my.sublimevideo.net, the "special" www. subdomain is removed though...
*/
public function alpha_stage_accessible() {
if (!$this->alpha_stage_accessible) {
$available_sites = self::available_sites();
$this->alpha_stage_accessible = false;
if (isset($available_sites)) {
foreach ($available_sites as $available_site) {
if ($available_site->accessible_stage == 'alpha') {
$this->alpha_stage_accessible = true;
break;
}
}
}
}
return $this->alpha_stage_accessible;
}
static function clean_http_host() {
return str_replace(':'.$_SERVER['SERVER_PORT'], '', preg_replace('/(www\.)(.+)/i', '$2', $_SERVER['HTTP_HOST']));
}
static function update_site_info($site=array()) {
$token = isset($site->token) ? $site->token : '';
$domain = isset($site->main_domain) && isset($site->wildcard) && isset($site->path) ? SublimeVideoUtils::site_with_wildcard_and_path($site) : '';
update_option('sv_site_token', $token);
update_option('sv_site_domain', $domain);
}
}
// Register the settings function
add_action('admin_init', array('SublimeVideoAdmin', 'init'));
// Add an item in the plugins menu
add_action('admin_menu', array('SublimeVideoUI', 'config_page'));
// Add a link in the plugins list
add_filter('plugin_action_links', array('SublimeVideoUI', 'plugin_action_links'), 10, 2);
?>