[ 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 // 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 and unconditional inclusion of custom code 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 exit(); 91 } 92 } 93 94 // Check if upgrade is needed (bypassed if upgrading or installing) 95 if ($actions->check_if_upgrade_needed === true) { 96 if (!yourls_is_upgrading() && !yourls_is_installing() && yourls_upgrade_is_needed()) { 97 yourls_no_cache_headers(); 98 yourls_redirect( yourls_admin_url('upgrade.php'), 307 ); 99 exit(); 100 } 101 } 102 103 // Load all plugins 104 if ($actions->load_plugins === true) { 105 yourls_load_plugins(); 106 } 107 108 // Trigger plugin loaded action 109 if ($actions->plugins_loaded_action === true) { 110 yourls_do_action( 'plugins_loaded' ); 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 * @since 1.7.3 130 * @return void 131 */ 132 public function redirect_ssl_if_needed() { 133 if (yourls_is_admin() && yourls_needs_ssl() && !yourls_is_ssl()) { 134 if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { 135 yourls_redirect( preg_replace( '|^http://|', 'https://', $_SERVER['REQUEST_URI'] ) ); 136 } else { 137 yourls_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); 138 } 139 exit(); 140 } 141 } 142 143 /** 144 * @since 1.7.3 145 * @return void 146 */ 147 public function include_db_files() { 148 // Attempt to open drop-in replacement for the DB engine else default to core engine 149 $file = YOURLS_USERDIR . '/db.php'; 150 $attempt = false; 151 if(file_exists($file)) { 152 $attempt = yourls_include_file_sandbox( $file ); 153 // Check if we have an error to display 154 if ( is_string( $attempt ) ) { 155 yourls_add_notice( $attempt ); 156 } 157 } 158 159 // Fallback to core DB engine 160 if ( $attempt !== true ) { 161 require_once YOURLS_INC . '/class-mysql.php'; 162 yourls_db_connect(); 163 } 164 } 165 166 /** 167 * Include custom extension file. 168 * 169 * "Cache" stands for "Custom Additional Code for Hazardous Extensions". 170 * 171 * @since 1.7.3 172 * @return void 173 */ 174 public function include_cache_files() { 175 $file = YOURLS_USERDIR . '/cache.php'; 176 $attempt = false; 177 if(file_exists($file)) { 178 $attempt = yourls_include_file_sandbox($file); 179 // Check if we have an error to display 180 if (is_string($attempt)) { 181 yourls_add_notice($attempt); 182 } 183 } 184 } 185 186 /** 187 * @since 1.7.3 188 * @return void 189 */ 190 public function include_core_functions() { 191 require_once YOURLS_INC.'/version.php'; 192 require_once YOURLS_INC.'/functions.php'; 193 require_once YOURLS_INC.'/functions-geo.php'; 194 require_once YOURLS_INC.'/functions-shorturls.php'; 195 require_once YOURLS_INC.'/functions-debug.php'; 196 require_once YOURLS_INC.'/functions-options.php'; 197 require_once YOURLS_INC.'/functions-links.php'; 198 require_once YOURLS_INC.'/functions-plugins.php'; 199 require_once YOURLS_INC.'/functions-formatting.php'; 200 require_once YOURLS_INC.'/functions-api.php'; 201 require_once YOURLS_INC.'/functions-kses.php'; 202 require_once YOURLS_INC.'/functions-l10n.php'; 203 require_once YOURLS_INC.'/functions-compat.php'; 204 require_once YOURLS_INC.'/functions-html.php'; 205 require_once YOURLS_INC.'/functions-http.php'; 206 require_once YOURLS_INC.'/functions-infos.php'; 207 require_once YOURLS_INC.'/functions-deprecated.php'; 208 require_once YOURLS_INC.'/functions-auth.php'; 209 require_once YOURLS_INC.'/functions-upgrade.php'; 210 require_once YOURLS_INC.'/functions-install.php'; 211 } 212 213 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Tue Jan 21 05:10:11 2025 | Cross-referenced by PHPXref 0.7.1 |