2 // This file initialize everything needed for YOURLS
\r
5 if( file_exists(dirname(__FILE__).'/config.php') ) {
\r
6 // config.php in /includes/
\r
7 require_once( dirname(__FILE__).'/config.php' );
\r
8 } elseif ( file_exists(dirname(dirname(__FILE__)).'/user/config.php') ) {
\r
9 // config.php in /user/
\r
10 require_once( dirname(dirname(__FILE__)).'/user/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 yourls_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 plugins directory
\r
40 if( !defined('YOURLS_PLUGINDIR') )
\r
41 define('YOURLS_PLUGINDIR', YOURLS_USERDIR.'/plugins' );
\r
43 // URL of plugins directory
\r
44 if( !defined('YOURLS_PLUGINURL') )
\r
45 define('YOURLS_PLUGINURL', YOURLS_USERURL.'/plugins');
\r
47 // physical path of pages directory
\r
48 if( !defined('YOURLS_PAGEDIR') )
\r
49 define('YOURLS_PAGEDIR', YOURLS_ABSPATH.'/pages' );
\r
51 // table to store URLs
\r
52 if( !defined('YOURLS_DB_TABLE_URL') )
\r
53 define('YOURLS_DB_TABLE_URL', YOURLS_DB_PREFIX.'url');
\r
55 // table to store options
\r
56 if( !defined('YOURLS_DB_TABLE_OPTIONS') )
\r
57 define('YOURLS_DB_TABLE_OPTIONS', YOURLS_DB_PREFIX.'options');
\r
59 // table to store hits, for stats
\r
60 if( !defined('YOURLS_DB_TABLE_LOG') )
\r
61 define('YOURLS_DB_TABLE_LOG', YOURLS_DB_PREFIX.'log');
\r
63 // minimum delay in sec before a same IP can add another URL. Note: logged in users are not throttled down.
\r
64 if( !defined('YOURLS_FLOOD_DELAY_SECONDS') )
\r
65 define('YOURLS_FLOOD_DELAY_SECONDS', 15 );
\r
67 // comma separated list of IPs that can bypass flood check.
\r
68 if( !defined('YOURLS_FLOOD_IP_WHITELIST') )
\r
69 define('YOURLS_FLOOD_IP_WHITELIST', '' );
\r
71 // life span of an auth cookie in seconds (60*60*24*7 = 7 days)
\r
72 if( !defined('YOURLS_COOKIE_LIFE') )
\r
73 define( 'YOURLS_COOKIE_LIFE', 60*60*24*7 );
\r
75 // life span of a nonce in seconds
\r
76 if( !defined('YOURLS_NONCE_LIFE') )
\r
77 define( 'YOURLS_NONCE_LIFE', 3600 );
\r
79 // if set to true, disable stat logging (no use for it, too busy servers, ...)
\r
80 if( !defined('YOURLS_NOSTATS') )
\r
81 define( 'YOURLS_NOSTATS', false );
\r
83 // if set to true, force https:// in the admin area
\r
84 if( !defined('YOURLS_ADMIN_SSL') )
\r
85 define( 'YOURLS_ADMIN_SSL', false );
\r
87 // if set to true, verbose debug infos. Will break things. Don't enable.
\r
88 if( !defined('YOURLS_DEBUG') )
\r
89 define( 'YOURLS_DEBUG', false );
\r
92 if (defined('YOURLS_DEBUG') && YOURLS_DEBUG == true) {
\r
93 error_reporting(E_ALL);
\r
95 error_reporting(E_ERROR | E_PARSE);
\r
98 // Include all functions
\r
99 require_once( YOURLS_INC.'/version.php' );
\r
100 require_once( YOURLS_INC.'/functions.php');
\r
101 require_once( YOURLS_INC.'/functions-compat.php' );
\r
102 // Allow drop-in replacement for the DB engine
\r
103 if( file_exists( YOURLS_USERDIR.'/db.php' ) ) {
\r
104 require_once( YOURLS_USERDIR.'/db.php' );
\r
106 require_once( YOURLS_INC.'/class-mysql.php' );
\r
108 require_once( YOURLS_INC.'/functions-plugins.php');
\r
109 // Load auth functions if needed
\r
110 if( yourls_is_private() )
\r
111 require_once( YOURLS_INC.'/functions-auth.php' );
\r
112 // Load template functions if needed
\r
113 if( yourls_has_interface() )
\r
114 require_once( YOURLS_INC.'/functions-html.php' );
\r
116 // If request for an admin page is http:// and SSL is required, redirect
\r
117 if( yourls_is_admin() && yourls_needs_ssl() && !yourls_is_ssl() ) {
\r
118 if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
\r
119 yourls_redirect( preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI']) );
\r
122 yourls_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
\r
127 // Fix REQUEST_URI for IIS
\r
128 wp_fix_request_uri();
\r
130 // Create the YOURLS object $ydb that will contain everything we globally need
\r
132 yourls_db_connect();
\r
134 // Read options right from start
\r
135 yourls_get_all_options();
\r
138 yourls_do_action( 'init' ); // plugins can't see this, not loaded yet
\r
140 // Check if we are in maintenance mode
\r
141 yourls_check_maintenance_mode();
\r
143 // Check if need to redirect to install procedure
\r
144 if( !yourls_is_installed() && ( !defined('YOURLS_INSTALLING') || YOURLS_INSTALLING != true ) ) {
\r
145 yourls_redirect( yourls_admin_url( 'install.php' ), 302 );
\r
148 // Check if upgrade is needed.
\r
149 // Note: this is bypassable with define('YOURLS_NO_UPGRADE_CHECK', true)
\r
150 // This is also bypassed if YOURLS_INSTALLING
\r
152 ( !defined('YOURLS_NO_UPGRADE_CHECK') || YOURLS_NO_UPGRADE_CHECK != true )
\r
154 ( !defined('YOURLS_INSTALLING') || YOURLS_INSTALLING != true )
\r
156 if ( yourls_upgrade_is_needed() ) {
\r
157 yourls_redirect( YOURLS_SITE .'/admin/upgrade.php', 302 );
\r
161 // Init all plugins
\r
162 yourls_load_plugins();
\r
163 yourls_do_action( 'plugins_loaded' );
\r
165 if( yourls_is_admin() )
\r
166 yourls_do_action( 'admin_init' );
\r