| [ Index ] |
PHP Cross Reference of YOURLS |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * YOURLS actions upon instantiating 5 */ 6 7 namespace YOURLS\Config; 8 9 class Init { 10 11 /** 12 * @var 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 // Check if we are in maintenance mode - if yes, it will die here. 36 if ($actions->check_maintenance_mode === true) { 37 yourls_check_maintenance_mode(); 38 } 39 40 // Fix REQUEST_URI for IIS 41 if ($actions->fix_request_uri === true) { 42 yourls_fix_request_uri(); 43 } 44 45 // Create the YOURLS object $ydb that will contain everything we globally need 46 if ($actions->include_db === true) { 47 $this->include_db_files(); 48 } 49 50 // Allow early and unconditional inclusion of custom code 51 if ($actions->include_cache === true) { 52 $this->include_cache_files(); 53 } 54 55 // Abort initialization here if fast init wanted (for tests/debug/do not use) 56 if ($actions->return_if_fast_init === true && defined('YOURLS_FAST_INIT') && YOURLS_FAST_INIT){ 57 return; 58 } 59 60 // Read options right from start 61 if ($actions->get_all_options === true) { 62 yourls_get_all_options(); 63 } 64 65 // Register shutdown function 66 if ($actions->register_shutdown === true) { 67 register_shutdown_function( 'yourls_shutdown' ); 68 } 69 70 // Core now loaded 71 if ($actions->core_loaded === true) { 72 yourls_do_action( 'init' ); // plugins can't see this, not loaded yet 73 } 74 75 // Check if need to redirect to install procedure 76 if ($actions->redirect_to_install === true) { 77 if (!yourls_is_installed() && !yourls_is_installing()) { 78 yourls_no_cache_headers(); 79 yourls_redirect( yourls_admin_url('install.php'), 307 ); 80 exit(); 81 } 82 } 83 84 // Check if upgrade is needed (bypassed if upgrading or installing) 85 if ($actions->check_if_upgrade_needed === true) { 86 if (!yourls_is_upgrading() && !yourls_is_installing() && yourls_upgrade_is_needed()) { 87 yourls_no_cache_headers(); 88 yourls_redirect( yourls_admin_url('upgrade.php'), 307 ); 89 exit(); 90 } 91 } 92 93 // Load all plugins 94 if ($actions->load_plugins === true) { 95 yourls_load_plugins(); 96 } 97 98 // Trigger plugin loaded action 99 if ($actions->plugins_loaded_action === true) { 100 yourls_do_action( 'plugins_loaded' ); 101 } 102 103 // Load locale 104 if ($actions->load_default_textdomain === true) { 105 yourls_load_default_textdomain(); 106 } 107 108 // If request for an admin page is http:// and SSL is required, redirect 109 if ($actions->redirect_ssl === true) { 110 $this->redirect_ssl_if_needed(); 111 } 112 113 // Is there a new version of YOURLS ? 114 if ($actions->check_new_version === true) { 115 if (yourls_is_installed() && !yourls_is_upgrading()) { 116 yourls_tell_if_new_version(); 117 } 118 } 119 120 if ($actions->init_admin === true) { 121 if (yourls_is_admin()) { 122 yourls_do_action( 'admin_init' ); 123 } 124 } 125 126 } 127 128 /** 129 * Redirect to the SSL version of the website if needed 130 * 131 * @since 1.7.3 132 * @return void 133 */ 134 public function redirect_ssl_if_needed(): void { 135 if (yourls_is_admin() && yourls_needs_ssl() && !yourls_is_ssl()) { 136 yourls_redirect(yourls_get_ssl_redirect_url($_SERVER['REQUEST_URI'] ?? '/')); 137 exit(); 138 } 139 } 140 141 /** 142 * @since 1.7.3 143 * @return void 144 */ 145 public function include_db_files() { 146 // Attempt to open drop-in replacement for the DB engine else default to core engine 147 $file = YOURLS_USERDIR . '/db.php'; 148 $attempt = false; 149 if(file_exists($file)) { 150 $attempt = yourls_include_file_sandbox( $file ); 151 // Check if we have an error to display 152 if ( is_string( $attempt ) ) { 153 yourls_add_notice( $attempt ); 154 } 155 } 156 157 // Fallback to core DB engine 158 if ( $attempt !== true ) { 159 require_once YOURLS_INC . '/class-mysql.php'; 160 yourls_db_connect(); 161 } 162 } 163 164 /** 165 * Include custom extension file. 166 * 167 * "Cache" stands for "Custom Additional Code for Hazardous Extensions". 168 * 169 * @since 1.7.3 170 * @return void 171 */ 172 public function include_cache_files() { 173 $file = YOURLS_USERDIR . '/cache.php'; 174 $attempt = false; 175 if(file_exists($file)) { 176 $attempt = yourls_include_file_sandbox($file); 177 // Check if we have an error to display 178 if (is_string($attempt)) { 179 yourls_add_notice($attempt); 180 } 181 } 182 } 183 184 /** 185 * @since 1.7.3 186 * @return void 187 */ 188 public function include_core_functions() { 189 require_once YOURLS_INC.'/version.php'; 190 require_once YOURLS_INC.'/functions.php'; 191 require_once YOURLS_INC.'/functions-geo.php'; 192 require_once YOURLS_INC.'/functions-shorturls.php'; 193 require_once YOURLS_INC.'/functions-debug.php'; 194 require_once YOURLS_INC.'/functions-options.php'; 195 require_once YOURLS_INC.'/functions-links.php'; 196 require_once YOURLS_INC.'/functions-plugins.php'; 197 require_once YOURLS_INC.'/functions-formatting.php'; 198 require_once YOURLS_INC.'/functions-api.php'; 199 require_once YOURLS_INC.'/functions-kses.php'; 200 require_once YOURLS_INC.'/functions-l10n.php'; 201 require_once YOURLS_INC.'/functions-compat.php'; 202 require_once YOURLS_INC.'/functions-html.php'; 203 require_once YOURLS_INC.'/functions-http.php'; 204 require_once YOURLS_INC.'/functions-infos.php'; 205 require_once YOURLS_INC.'/functions-deprecated.php'; 206 require_once YOURLS_INC.'/functions-auth.php'; 207 require_once YOURLS_INC.'/functions-upgrade.php'; 208 require_once YOURLS_INC.'/functions-install.php'; 209 } 210 211 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Nov 9 05:10:31 2026 | Cross-referenced by PHPXref 0.7.1 |