From 7ab126ebec8874eddb6ab211064ed7c9ec188cf6 Mon Sep 17 00:00:00 2001
From: Ozh
Things should not last very long, thank you for your patience and please excuse the inconvenience'; - yourls_die( $message, $title , 503 ); - } - -} - -// Toggle maintenance mode -function yourls_maintenance_mode( $maintenance = true ) { - yourls_update_option( 'maintenance_mode', (bool)$maintenance ); -} - // Quick UA check for mobile devices. Return boolean. function yourls_is_mobile_device() { // Strings searched @@ -1710,3 +1681,31 @@ function yourls_favicon( $echo = true ) { echo $favicon; return $favicon; } + +// Check for maintenance mode. If yes, die. See yourls_maintenance_mode(). Stolen from WP. +function yourls_check_maintenance_mode() { + + $file = YOURLS_ABSPATH . '/.maintenance' ; + if ( !file_exists( $file ) || defined( 'YOURLS_UPGRADING' ) || defined( 'YOURLS_INSTALLING' ) ) + return; + + global $maintenance_start; + + include( $file ); + // If the $maintenance_start timestamp is older than 10 minutes, don't die. + if ( ( time() - $maintenance_start ) >= 600 ) + return; + + // Use any /user/maintenance.php file + if( file_exists( YOURLS_USERDIR.'/maintenance.php' ) ) { + include( YOURLS_USERDIR.'/maintenance.php' ); + die(); + } + + // https://www.youtube.com/watch?v=Xw-m4jEY-Ns + $title = 'Service temporarily unavailable'; + $message = 'Our service is currently undergoing scheduled maintenance.
+Things should not last very long, thank you for your patience and please excuse the inconvenience'; + yourls_die( $message, $title , 503 ); + +} diff --git a/includes/load-yourls.php b/includes/load-yourls.php index a27df88..afaaefc 100644 --- a/includes/load-yourls.php +++ b/includes/load-yourls.php @@ -115,6 +115,9 @@ // Allow early inclusion of a cache layer if( file_exists( YOURLS_USERDIR.'/cache.php' ) ) require_once( YOURLS_USERDIR.'/cache.php' ); + +// Check if we are in maintenance mode - if yes, it will die here. +yourls_check_maintenance_mode(); // If request for an admin page is http:// and SSL is required, redirect if( yourls_is_admin() && yourls_needs_ssl() && !yourls_is_ssl() ) { @@ -143,9 +146,6 @@ // Core now loaded yourls_do_action( 'init' ); // plugins can't see this, not loaded yet -// Check if we are in maintenance mode -yourls_check_maintenance_mode(); - // Check if need to redirect to install procedure if( !yourls_is_installed() && ( !defined('YOURLS_INSTALLING') || YOURLS_INSTALLING != true ) ) { yourls_redirect( yourls_admin_url( 'install.php' ), 302 ); -- 2.45.0