2 // This file initialize everything needed for YOURLS
5 if( file_exists( dirname( dirname( __FILE__ ) ) . '/user/config.php' ) ) {
6 // config.php in /user/
7 require_once( dirname( dirname( __FILE__ ) ) . '/user/config.php' );
8 } elseif ( file_exists( dirname( __FILE__ ) . '/config.php' ) ) {
9 // config.php in /includes/
10 require_once( dirname( __FILE__ ) . '/config.php' );
12 // config.php not found :(
13 die( '<p class="error">Cannot find <tt>config.php</tt>.</p><p>Please read the <tt>readme.html</tt> to learn how to install YOURLS</p>' );
16 // Check if config.php was properly updated for 1.4
17 if( !defined( 'YOURLS_DB_PREFIX' ) )
18 die( '<p class="error">Your <tt>config.php</tt> does not contain all the required constant definitions.</p><p>Please check <tt>config-sample.php</tt> and update your config accordingly, there are new stuffs!</p>' );
21 // Define core constants that have not been user defined in config.php
23 // physical path of YOURLS root
24 if( !defined( 'YOURLS_ABSPATH' ) )
25 define( 'YOURLS_ABSPATH', str_replace( '\\', '/', dirname( dirname( __FILE__ ) ) ) );
27 // physical path of includes directory
28 if( !defined( 'YOURLS_INC' ) )
29 define( 'YOURLS_INC', YOURLS_ABSPATH.'/includes' );
31 // physical path of user directory
32 if( !defined( 'YOURLS_USERDIR' ) )
33 define( 'YOURLS_USERDIR', YOURLS_ABSPATH.'/user' );
35 // URL of user directory
36 if( !defined( 'YOURLS_USERURL' ) )
37 define( 'YOURLS_USERURL', YOURLS_SITE.'/user' );
39 // physical path of translations directory
40 if( !defined( 'YOURLS_LANG_DIR' ) )
41 define( 'YOURLS_LANG_DIR', YOURLS_USERDIR.'/languages' );
43 // physical path of plugins directory
44 if( !defined( 'YOURLS_PLUGINDIR' ) )
45 define( 'YOURLS_PLUGINDIR', YOURLS_USERDIR.'/plugins' );
47 // URL of plugins directory
48 if( !defined( 'YOURLS_PLUGINURL' ) )
49 define( 'YOURLS_PLUGINURL', YOURLS_USERURL.'/plugins' );
51 // physical path of pages directory
52 if( !defined( 'YOURLS_PAGEDIR' ) )
53 define('YOURLS_PAGEDIR', YOURLS_ABSPATH.'/pages' );
55 // table to store URLs
56 if( !defined( 'YOURLS_DB_TABLE_URL' ) )
57 define( 'YOURLS_DB_TABLE_URL', YOURLS_DB_PREFIX.'url' );
59 // table to store options
60 if( !defined( 'YOURLS_DB_TABLE_OPTIONS' ) )
61 define( 'YOURLS_DB_TABLE_OPTIONS', YOURLS_DB_PREFIX.'options' );
63 // table to store hits, for stats
64 if( !defined( 'YOURLS_DB_TABLE_LOG' ) )
65 define( 'YOURLS_DB_TABLE_LOG', YOURLS_DB_PREFIX.'log' );
67 // minimum delay in sec before a same IP can add another URL. Note: logged in users are not throttled down.
68 if( !defined( 'YOURLS_FLOOD_DELAY_SECONDS' ) )
69 define( 'YOURLS_FLOOD_DELAY_SECONDS', 15 );
71 // comma separated list of IPs that can bypass flood check.
72 if( !defined( 'YOURLS_FLOOD_IP_WHITELIST' ) )
73 define( 'YOURLS_FLOOD_IP_WHITELIST', '' );
75 // life span of an auth cookie in seconds (60*60*24*7 = 7 days)
76 if( !defined( 'YOURLS_COOKIE_LIFE' ) )
77 define( 'YOURLS_COOKIE_LIFE', 60*60*24*7 );
79 // life span of a nonce in seconds
80 if( !defined( 'YOURLS_NONCE_LIFE' ) )
81 define( 'YOURLS_NONCE_LIFE', 43200 ); // 3600 * 12
83 // if set to true, disable stat logging (no use for it, too busy servers, ...)
84 if( !defined( 'YOURLS_NOSTATS' ) )
85 define( 'YOURLS_NOSTATS', false );
87 // if set to true, force https:// in the admin area
88 if( !defined( 'YOURLS_ADMIN_SSL' ) )
89 define( 'YOURLS_ADMIN_SSL', false );
91 // if set to true, verbose debug infos. Will break things. Don't enable.
92 if( !defined( 'YOURLS_DEBUG' ) )
93 define( 'YOURLS_DEBUG', false );
96 if( defined( 'YOURLS_DEBUG' ) && YOURLS_DEBUG == true ) {
97 error_reporting( -1 );
99 error_reporting( E_ERROR | E_PARSE );
102 // Include all functions
103 require_once( YOURLS_INC.'/version.php' );
104 require_once( YOURLS_INC.'/functions.php');
105 require_once( YOURLS_INC.'/functions-plugins.php' );
106 require_once( YOURLS_INC.'/functions-formatting.php' );
107 require_once( YOURLS_INC.'/functions-api.php' );
108 require_once( YOURLS_INC.'/functions-kses.php' );
109 require_once( YOURLS_INC.'/functions-l10n.php' );
110 require_once( YOURLS_INC.'/functions-compat.php' );
111 require_once( YOURLS_INC.'/functions-html.php' );
112 // Allow drop-in replacement for the DB engine
113 if( file_exists( YOURLS_USERDIR.'/db.php' ) ) {
114 require_once( YOURLS_USERDIR.'/db.php' );
116 require_once( YOURLS_INC.'/class-mysql.php' );
118 // Load auth functions if needed
119 if( yourls_is_private() )
120 require_once( YOURLS_INC.'/functions-auth.php' );
122 // Allow early inclusion of a cache layer
123 if( file_exists( YOURLS_USERDIR.'/cache.php' ) )
124 require_once( YOURLS_USERDIR.'/cache.php' );
127 yourls_load_default_textdomain();
129 // Check if we are in maintenance mode - if yes, it will die here.
130 yourls_check_maintenance_mode();
132 // If request for an admin page is http:// and SSL is required, redirect
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'] ) );
138 yourls_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
143 // Fix REQUEST_URI for IIS
144 yourls_fix_request_uri();
146 // Create the YOURLS object $ydb that will contain everything we globally need
150 // Read options right from start
151 yourls_get_all_options();
153 // Register shutdown function
154 register_shutdown_function( 'yourls_shutdown' );
157 yourls_do_action( 'init' ); // plugins can't see this, not loaded yet
159 // Check if need to redirect to install procedure
160 if( !yourls_is_installed() && !yourls_is_installing() ) {
161 yourls_redirect( yourls_admin_url( 'install.php' ), 302 );
164 // Check if upgrade is needed (bypassed if upgrading or installing)
165 if ( !yourls_is_upgrading() && !yourls_is_installing() ) {
166 if ( yourls_upgrade_is_needed() ) {
167 yourls_redirect( YOURLS_SITE .'/admin/upgrade.php', 302 );
172 yourls_load_plugins();
173 yourls_do_action( 'plugins_loaded' );
175 if( yourls_is_admin() )
176 yourls_do_action( 'admin_init' );