1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GeminiLabs\SiteReviews\Controllers; |
4
|
|
|
|
5
|
|
|
use GeminiLabs\SiteReviews\Commands\RegisterPostType; |
6
|
|
|
use GeminiLabs\SiteReviews\Commands\RegisterShortcodes; |
7
|
|
|
use GeminiLabs\SiteReviews\Commands\RegisterTaxonomy; |
8
|
|
|
use GeminiLabs\SiteReviews\Commands\RegisterWidgets; |
9
|
|
|
use GeminiLabs\SiteReviews\Database\Query; |
10
|
|
|
use GeminiLabs\SiteReviews\Helpers\Arr; |
11
|
|
|
use GeminiLabs\SiteReviews\Install; |
12
|
|
|
|
13
|
|
|
class MainController extends Controller |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @return bool |
17
|
|
|
* @filter site-reviews/devmode |
18
|
|
|
*/ |
19
|
|
|
public function filterDevmode() |
20
|
|
|
{ |
21
|
|
|
$parts = explode('.', parse_url(get_home_url(), PHP_URL_HOST)); |
22
|
|
|
$tld = end($parts); |
23
|
|
|
return 'test' === $tld; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* switch_to_blog() was run before this hook was triggered. |
28
|
|
|
* @param array $tables |
29
|
|
|
* @return array |
30
|
|
|
* @see http://developer.wordpress.org/reference/functions/wp_uninitialize_site/ |
31
|
|
|
* @filter wpmu_drop_tables |
32
|
|
|
*/ |
33
|
|
|
public function filterDropTables($tables) |
34
|
|
|
{ |
35
|
|
|
$customTables = [ // order is intentional |
36
|
|
|
glsr()->prefix.'ratings' => glsr(Query::class)->table('ratings'), |
37
|
|
|
glsr()->prefix.'assigned_posts' => glsr(Query::class)->table('assigned_posts'), |
38
|
|
|
glsr()->prefix.'assigned_terms' => glsr(Query::class)->table('assigned_terms'), |
39
|
|
|
glsr()->prefix.'assigned_users' => glsr(Query::class)->table('assigned_users'), |
40
|
|
|
]; |
41
|
|
|
foreach ($customTables as $key => $table) { |
42
|
|
|
$tables = Arr::prepend($tables, $table, $key); // Custom tables have foreign indexes so they must be removed first! |
43
|
|
|
} |
44
|
|
|
return $tables; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return void |
49
|
|
|
* @action init |
50
|
|
|
*/ |
51
|
|
|
public function initDefaults() |
52
|
|
|
{ |
53
|
|
|
// This cannot be done before plugins_loaded as it uses the gettext functions |
54
|
|
|
glsr()->storeDefaults(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param \WP_Site $site |
59
|
|
|
* @return void |
60
|
|
|
* @action wp_insert_site |
61
|
|
|
*/ |
62
|
|
|
public function installOnNewSite($site) |
63
|
|
|
{ |
64
|
|
|
if (is_plugin_active_for_network(plugin_basename(glsr()->file))) { |
65
|
|
|
glsr(Install::class)->runOnSite($site->blog_id); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return void |
71
|
|
|
* @action admin_footer |
72
|
|
|
* @action wp_footer |
73
|
|
|
*/ |
74
|
|
|
public function logOnce() |
75
|
|
|
{ |
76
|
|
|
glsr_log()->logOnce(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return void |
81
|
|
|
* @action plugins_loaded |
82
|
|
|
*/ |
83
|
|
|
public function registerAddons() |
84
|
|
|
{ |
85
|
|
|
glsr()->action('addon/register', glsr()); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return void |
90
|
|
|
* @action plugins_loaded |
91
|
|
|
*/ |
92
|
|
|
public function registerLanguages() |
93
|
|
|
{ |
94
|
|
|
load_plugin_textdomain(glsr()->id, false, |
95
|
|
|
trailingslashit(plugin_basename(glsr()->path()).'/'.glsr()->languages) |
96
|
|
|
); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return void |
101
|
|
|
* @action init |
102
|
|
|
*/ |
103
|
|
|
public function registerPostType() |
104
|
|
|
{ |
105
|
|
|
$this->execute(new RegisterPostType()); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return void |
110
|
|
|
* @action plugins_loaded |
111
|
|
|
*/ |
112
|
|
|
public function registerReviewTypes() |
113
|
|
|
{ |
114
|
|
|
$types = glsr()->filterArray('addon/types', []); |
115
|
|
|
$types = wp_parse_args($types, [ |
116
|
|
|
'local' => _x('Local Review', 'admin-text', 'site-reviews'), |
117
|
|
|
]); |
118
|
|
|
glsr()->store('review_types', $types); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return void |
123
|
|
|
* @action init |
124
|
|
|
*/ |
125
|
|
|
public function registerShortcodes() |
126
|
|
|
{ |
127
|
|
|
$this->execute(new RegisterShortcodes([ |
128
|
|
|
'site_reviews', |
129
|
|
|
'site_reviews_form', |
130
|
|
|
'site_reviews_summary', |
131
|
|
|
])); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return void |
136
|
|
|
* @action init |
137
|
|
|
*/ |
138
|
|
|
public function registerTaxonomy() |
139
|
|
|
{ |
140
|
|
|
$this->execute(new RegisterTaxonomy()); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return void |
145
|
|
|
* @action widgets_init |
146
|
|
|
*/ |
147
|
|
|
public function registerWidgets() |
148
|
|
|
{ |
149
|
|
|
$this->execute(new RegisterWidgets()); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return void |
154
|
|
|
* @action init |
155
|
|
|
*/ |
156
|
|
|
public function updateAddons() |
157
|
|
|
{ |
158
|
|
|
glsr()->action('addon/update', glsr()); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|