|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* YOURLS actions upon instantiating |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace YOURLS\Config; |
|
8
|
|
|
|
|
9
|
|
|
class Init { |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @param InitDefaults |
|
|
|
|
|
|
13
|
|
|
*/ |
|
|
|
|
|
|
14
|
|
|
protected $actions; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @since 1.7.3 |
|
18
|
|
|
* |
|
19
|
|
|
* @param InitDefaults $actions |
|
20
|
|
|
*/ |
|
21
|
|
|
public function __construct(InitDefaults $actions) { |
|
22
|
|
|
|
|
23
|
|
|
$this->actions = $actions; |
|
24
|
|
|
|
|
25
|
|
|
// Include core files |
|
26
|
|
|
if ($actions->include_core_funcs === true) { |
|
27
|
|
|
$this->include_core_functions(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
// Enforce UTC timezone. Date/time can be adjusted with a plugin. |
|
31
|
|
|
if ($actions->default_timezone === true) { |
|
32
|
|
|
date_default_timezone_set( 'UTC' ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
// Load locale |
|
36
|
|
|
if ($actions->load_default_textdomain === true) { |
|
37
|
|
|
yourls_load_default_textdomain(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
// Check if we are in maintenance mode - if yes, it will die here. |
|
41
|
|
|
if ($actions->check_maintenance_mode === true) { |
|
42
|
|
|
yourls_check_maintenance_mode(); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
// Fix REQUEST_URI for IIS |
|
46
|
|
|
if ($actions->fix_request_uri === true) { |
|
47
|
|
|
yourls_fix_request_uri(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
// If request for an admin page is http:// and SSL is required, redirect |
|
51
|
|
|
if ($actions->redirect_ssl === true) { |
|
52
|
|
|
$this->redirect_ssl_if_needed(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
// Create the YOURLS object $ydb that will contain everything we globally need |
|
56
|
|
|
if ($actions->include_db === true) { |
|
57
|
|
|
$this->include_db_files(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
// Allow early inclusion of a cache layer |
|
61
|
|
|
if ($actions->include_cache === true) { |
|
62
|
|
|
$this->include_cache_files(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
// Abort initialization here if fast init wanted (for tests/debug/do not use) |
|
66
|
|
|
if ($actions->return_if_fast_init === true && defined('YOURLS_FAST_INIT') && YOURLS_FAST_INIT){ |
|
|
|
|
|
|
67
|
|
|
return; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
// Read options right from start |
|
71
|
|
|
if ($actions->get_all_options === true) { |
|
72
|
|
|
yourls_get_all_options(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
// Register shutdown function |
|
76
|
|
|
if ($actions->register_shutdown === true) { |
|
77
|
|
|
register_shutdown_function( 'yourls_shutdown' ); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
// Core now loaded |
|
81
|
|
|
if ($actions->core_loaded === true) { |
|
82
|
|
|
yourls_do_action( 'init' ); // plugins can't see this, not loaded yet |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
// Check if need to redirect to install procedure |
|
86
|
|
|
if ($actions->redirect_to_install === true) { |
|
87
|
|
|
if (!yourls_is_installed() && !yourls_is_installing()) { |
|
88
|
|
|
yourls_no_cache_headers(); |
|
89
|
|
|
yourls_redirect( yourls_admin_url('install.php'), 307 ); |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
// Check if upgrade is needed (bypassed if upgrading or installing) |
|
94
|
|
|
if ($actions->check_if_upgrade_needed === true) { |
|
95
|
|
|
if (!yourls_is_upgrading() && !yourls_is_installing() && yourls_upgrade_is_needed()) { |
|
96
|
|
|
yourls_no_cache_headers(); |
|
97
|
|
|
yourls_redirect( yourls_admin_url('upgrade.php'), 307 ); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
// Load all plugins |
|
102
|
|
|
if ($actions->load_plugins === true) { |
|
103
|
|
|
yourls_load_plugins(); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
// Trigger plugin loaded action |
|
107
|
|
|
if ($actions->plugins_loaded_action === true) { |
|
108
|
|
|
yourls_do_action( 'plugins_loaded' ); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
// Is there a new version of YOURLS ? |
|
112
|
|
|
if ($actions->check_new_version === true) { |
|
113
|
|
|
if (yourls_is_installed() && !yourls_is_upgrading()) { |
|
114
|
|
|
yourls_tell_if_new_version(); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
if ($actions->init_admin === true) { |
|
119
|
|
|
if (yourls_is_admin()) { |
|
120
|
|
|
yourls_do_action( 'admin_init' ); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
} |
|
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @since 1.7.3 |
|
128
|
|
|
* @return void |
|
129
|
|
|
*/ |
|
130
|
|
|
public function redirect_ssl_if_needed() { |
|
131
|
|
|
if (yourls_is_admin() && yourls_needs_ssl() && !yourls_is_ssl()) { |
|
132
|
|
|
if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { |
|
133
|
|
|
yourls_redirect( preg_replace( '|^http://|', 'https://', $_SERVER['REQUEST_URI'] ) ); |
|
|
|
|
|
|
134
|
|
|
} else { |
|
135
|
|
|
yourls_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
|
136
|
|
|
} |
|
137
|
|
|
exit(); |
|
|
|
|
|
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @since 1.7.3 |
|
143
|
|
|
* @return void |
|
144
|
|
|
*/ |
|
145
|
|
|
public function include_db_files() { |
|
146
|
|
|
// Allow drop-in replacement for the DB engine |
|
147
|
|
|
if (file_exists(YOURLS_USERDIR.'/db.php')) { |
|
148
|
|
|
require_once YOURLS_USERDIR.'/db.php'; |
|
149
|
|
|
} else { |
|
150
|
|
|
require_once YOURLS_INC.'/class-mysql.php'; |
|
151
|
|
|
yourls_db_connect(); |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @since 1.7.3 |
|
157
|
|
|
* @return void |
|
158
|
|
|
*/ |
|
159
|
|
|
public function include_cache_files() { |
|
160
|
|
|
if (file_exists(YOURLS_USERDIR.'/cache.php')) { |
|
161
|
|
|
require_once YOURLS_USERDIR.'/cache.php'; |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @since 1.7.3 |
|
167
|
|
|
* @return void |
|
168
|
|
|
*/ |
|
169
|
|
|
public function include_core_functions() { |
|
170
|
|
|
require_once YOURLS_INC.'/version.php'; |
|
171
|
|
|
require_once YOURLS_INC.'/functions.php'; |
|
172
|
|
|
require_once YOURLS_INC.'/functions-geo.php'; |
|
173
|
|
|
require_once YOURLS_INC.'/functions-shorturls.php'; |
|
174
|
|
|
require_once YOURLS_INC.'/functions-debug.php'; |
|
175
|
|
|
require_once YOURLS_INC.'/functions-options.php'; |
|
176
|
|
|
require_once YOURLS_INC.'/functions-links.php'; |
|
177
|
|
|
require_once YOURLS_INC.'/functions-plugins.php'; |
|
178
|
|
|
require_once YOURLS_INC.'/functions-formatting.php'; |
|
179
|
|
|
require_once YOURLS_INC.'/functions-api.php'; |
|
180
|
|
|
require_once YOURLS_INC.'/functions-kses.php'; |
|
181
|
|
|
require_once YOURLS_INC.'/functions-l10n.php'; |
|
182
|
|
|
require_once YOURLS_INC.'/functions-compat.php'; |
|
183
|
|
|
require_once YOURLS_INC.'/functions-html.php'; |
|
184
|
|
|
require_once YOURLS_INC.'/functions-http.php'; |
|
185
|
|
|
require_once YOURLS_INC.'/functions-infos.php'; |
|
186
|
|
|
require_once YOURLS_INC.'/functions-deprecated.php'; |
|
187
|
|
|
require_once YOURLS_INC.'/functions-auth.php'; |
|
188
|
|
|
|
|
189
|
|
|
// Load install & upgrade functions if needed |
|
190
|
|
|
if ($this->actions->include_install_upgrade_funcs === true) { |
|
191
|
|
|
require_once YOURLS_INC.'/functions-upgrade.php'; |
|
192
|
|
|
require_once YOURLS_INC.'/functions-install.php'; |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
} |
|
197
|
|
|
|