]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - includes/load-yourls.php
Core version check -- first pass
[Github/YOURLS.git] / includes / load-yourls.php
1 <?php
2 // This file initialize everything needed for YOURLS
3
4 // Include settings
5 if( file_exists( dirname( dirname( __FILE__ ) ) . '/user/config.php' ) ) {
6         // config.php in /user/
7         define( 'YOURLS_CONFIGFILE', str_replace( '\\', '/', dirname( dirname( __FILE__ ) ) ) . '/user/config.php' );
8 } elseif ( file_exists( dirname( __FILE__ ) . '/config.php' ) ) {
9         // config.php in /includes/
10         define( 'YOURLS_CONFIGFILE', str_replace( '\\', '/', dirname( __FILE__ ) ) . '/config.php' );
11 } else {
12         // config.php not found :(
13         die( '<p class="error">Cannot find <tt>config.php</tt>.</p><p>Please read the <tt><a href="../readme.html#Install">readme.html</a></tt> to learn how to install YOURLS</p>' );
14 }
15 require_once( YOURLS_CONFIGFILE );
16
17 // Check if config.php was properly updated for 1.4
18 if( !defined( 'YOURLS_DB_PREFIX' ) )
19         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>' );
20
21         
22 // Define core constants that have not been user defined in config.php
23
24 // physical path of YOURLS root
25 if( !defined( 'YOURLS_ABSPATH' ) )
26         define( 'YOURLS_ABSPATH', str_replace( '\\', '/', dirname( dirname( __FILE__ ) ) ) );
27
28 // physical path of includes directory
29 if( !defined( 'YOURLS_INC' ) )
30         define( 'YOURLS_INC', YOURLS_ABSPATH.'/includes' );
31
32 // physical path of user directory
33 if( !defined( 'YOURLS_USERDIR' ) )
34         define( 'YOURLS_USERDIR', YOURLS_ABSPATH.'/user' );
35
36 // URL of user directory
37 if( !defined( 'YOURLS_USERURL' ) )
38         define( 'YOURLS_USERURL', YOURLS_SITE.'/user' );
39         
40 // physical path of translations directory
41 if( !defined( 'YOURLS_LANG_DIR' ) )
42         define( 'YOURLS_LANG_DIR', YOURLS_USERDIR.'/languages' );
43
44 // physical path of plugins directory
45 if( !defined( 'YOURLS_PLUGINDIR' ) )
46         define( 'YOURLS_PLUGINDIR', YOURLS_USERDIR.'/plugins' );
47
48 // URL of plugins directory
49 if( !defined( 'YOURLS_PLUGINURL' ) )
50         define( 'YOURLS_PLUGINURL', YOURLS_USERURL.'/plugins' );
51         
52 // physical path of pages directory
53 if( !defined( 'YOURLS_PAGEDIR' ) )
54         define('YOURLS_PAGEDIR', YOURLS_ABSPATH.'/pages' );
55
56 // table to store URLs
57 if( !defined( 'YOURLS_DB_TABLE_URL' ) )
58         define( 'YOURLS_DB_TABLE_URL', YOURLS_DB_PREFIX.'url' );
59
60 // table to store options
61 if( !defined( 'YOURLS_DB_TABLE_OPTIONS' ) )
62         define( 'YOURLS_DB_TABLE_OPTIONS', YOURLS_DB_PREFIX.'options' );
63
64 // table to store hits, for stats
65 if( !defined( 'YOURLS_DB_TABLE_LOG' ) )
66         define( 'YOURLS_DB_TABLE_LOG', YOURLS_DB_PREFIX.'log' );
67
68 // minimum delay in sec before a same IP can add another URL. Note: logged in users are not throttled down.
69 if( !defined( 'YOURLS_FLOOD_DELAY_SECONDS' ) )
70         define( 'YOURLS_FLOOD_DELAY_SECONDS', 15 );
71
72 // comma separated list of IPs that can bypass flood check.
73 if( !defined( 'YOURLS_FLOOD_IP_WHITELIST' ) )
74         define( 'YOURLS_FLOOD_IP_WHITELIST', '' );
75
76 // life span of an auth cookie in seconds (60*60*24*7 = 7 days)
77 if( !defined( 'YOURLS_COOKIE_LIFE' ) )
78         define( 'YOURLS_COOKIE_LIFE', 60*60*24*7 );
79
80 // life span of a nonce in seconds
81 if( !defined( 'YOURLS_NONCE_LIFE' ) )
82         define( 'YOURLS_NONCE_LIFE', 43200 ); // 3600 * 12
83
84 // if set to true, disable stat logging (no use for it, too busy servers, ...)
85 if( !defined( 'YOURLS_NOSTATS' ) )
86         define( 'YOURLS_NOSTATS', false );
87
88 // if set to true, force https:// in the admin area
89 if( !defined( 'YOURLS_ADMIN_SSL' ) )
90         define( 'YOURLS_ADMIN_SSL', false );
91
92 // if set to true, verbose debug infos. Will break things. Don't enable.
93 if( !defined( 'YOURLS_DEBUG' ) )
94         define( 'YOURLS_DEBUG', false );
95         
96 // Error reporting
97 if( defined( 'YOURLS_DEBUG' ) && YOURLS_DEBUG == true ) {
98         error_reporting( -1 );
99 } else {
100         error_reporting( E_ERROR | E_PARSE );
101 }
102
103 // Include all functions
104 require_once( YOURLS_INC.'/version.php' );
105 require_once( YOURLS_INC.'/functions.php');
106 require_once( YOURLS_INC.'/functions-plugins.php' );
107 require_once( YOURLS_INC.'/functions-formatting.php' );
108 require_once( YOURLS_INC.'/functions-api.php' );
109 require_once( YOURLS_INC.'/functions-kses.php' );
110 require_once( YOURLS_INC.'/functions-l10n.php' );
111 require_once( YOURLS_INC.'/functions-compat.php' );
112 require_once( YOURLS_INC.'/functions-html.php' );
113 require_once( YOURLS_INC.'/functions-http.php' );
114 require_once( YOURLS_INC.'/functions-update.php' );
115 require_once( YOURLS_INC.'/functions-infos.php' );
116
117 // Load auth functions if needed
118 if( yourls_is_private() ) {
119         require_once( YOURLS_INC.'/functions-auth.php' );
120 }
121
122 // Load locale
123 yourls_load_default_textdomain();
124
125 // Check if we are in maintenance mode - if yes, it will die here.
126 yourls_check_maintenance_mode();
127
128 // Fix REQUEST_URI for IIS
129 yourls_fix_request_uri();
130         
131 // If request for an admin page is http:// and SSL is required, redirect
132 if( yourls_is_admin() && yourls_needs_ssl() && !yourls_is_ssl() ) {
133         if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
134                 yourls_redirect( preg_replace( '|^http://|', 'https://', $_SERVER['REQUEST_URI'] ) );
135                 exit();
136         } else {
137                 yourls_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
138                 exit();
139         }
140 }
141
142 // Create the YOURLS object $ydb that will contain everything we globally need
143 global $ydb;
144
145 // Allow drop-in replacement for the DB engine
146 if( file_exists( YOURLS_USERDIR.'/db.php' ) ) {
147         require_once( YOURLS_USERDIR.'/db.php' );
148 } else {
149         require_once( YOURLS_INC.'/class-mysql.php' );
150         yourls_db_connect();
151 }
152
153 // Allow early inclusion of a cache layer
154 if( file_exists( YOURLS_USERDIR.'/cache.php' ) )
155         require_once( YOURLS_USERDIR.'/cache.php' );
156
157 // Read options right from start
158 yourls_get_all_options();
159
160 // Register shutdown function
161 register_shutdown_function( 'yourls_shutdown' );
162
163 // Core now loaded
164 yourls_do_action( 'init' ); // plugins can't see this, not loaded yet
165
166 // Check if need to redirect to install procedure
167 if( !yourls_is_installed() && !yourls_is_installing() ) {
168         yourls_redirect( yourls_admin_url( 'install.php' ), 302 );
169 }
170
171 // Check if upgrade is needed (bypassed if upgrading or installing)
172 if ( !yourls_is_upgrading() && !yourls_is_installing() ) {
173         if ( yourls_upgrade_is_needed() ) {
174                 yourls_redirect( YOURLS_SITE .'/admin/upgrade.php', 302 );
175         }
176 }
177
178 // Init all plugins
179 yourls_load_plugins();
180 yourls_do_action( 'plugins_loaded' );
181
182 if( yourls_is_admin() )
183         yourls_do_action( 'admin_init' );
184