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