]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - includes/load-yourls.php
Use __DIR__ instead of dirname(__FILE__)
[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( __DIR__ ) . '/user/config.php' ) ) {
6         // config.php in /user/
7         define( 'YOURLS_CONFIGFILE', str_replace( '\\', '/', dirname( __DIR__ ) ) . '/user/config.php' );
8 } elseif ( file_exists( __DIR__ . '/config.php' ) ) {
9         // config.php in /includes/
10         define( 'YOURLS_CONFIGFILE', str_replace( '\\', '/', __DIR__ ) . '/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( __DIR__ ) ) );
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-infos.php' );
115
116 // Load auth functions if needed
117 if( yourls_is_private() ) {
118         require_once( YOURLS_INC.'/functions-auth.php' );
119 }
120
121 // Enforce UTC timezone to suppress PHP warnings -- correct date/time will be managed using the config time offset
122 date_default_timezone_set( 'UTC' );
123
124 // Load locale
125 yourls_load_default_textdomain();
126
127 // Check if we are in maintenance mode - if yes, it will die here.
128 yourls_check_maintenance_mode();
129
130 // Fix REQUEST_URI for IIS
131 yourls_fix_request_uri();
132         
133 // If request for an admin page is http:// and SSL is required, redirect
134 if( yourls_is_admin() && yourls_needs_ssl() && !yourls_is_ssl() ) {
135         if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
136                 yourls_redirect( preg_replace( '|^http://|', 'https://', $_SERVER['REQUEST_URI'] ) );
137                 exit();
138         } else {
139                 yourls_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
140                 exit();
141         }
142 }
143
144 // Create the YOURLS object $ydb that will contain everything we globally need
145 global $ydb;
146
147 // Allow drop-in replacement for the DB engine
148 if( file_exists( YOURLS_USERDIR.'/db.php' ) ) {
149         require_once( YOURLS_USERDIR.'/db.php' );
150 } else {
151         require_once( YOURLS_INC.'/class-mysql.php' );
152         yourls_db_connect();
153 }
154
155 // Allow early inclusion of a cache layer
156 if( file_exists( YOURLS_USERDIR.'/cache.php' ) )
157         require_once( YOURLS_USERDIR.'/cache.php' );
158
159 // Read options right from start
160 yourls_get_all_options();
161
162 // Register shutdown function
163 register_shutdown_function( 'yourls_shutdown' );
164
165 // Core now loaded
166 yourls_do_action( 'init' ); // plugins can't see this, not loaded yet
167
168 // Check if need to redirect to install procedure
169 if( !yourls_is_installed() && !yourls_is_installing() ) {
170         yourls_redirect( yourls_admin_url( 'install.php' ), 302 );
171 }
172
173 // Check if upgrade is needed (bypassed if upgrading or installing)
174 if ( !yourls_is_upgrading() && !yourls_is_installing() ) {
175         if ( yourls_upgrade_is_needed() ) {
176                 yourls_redirect( YOURLS_SITE .'/admin/upgrade.php', 302 );
177         }
178 }
179
180 // Init all plugins
181 yourls_load_plugins();
182 yourls_do_action( 'plugins_loaded' );
183
184 // Is there a new version of YOURLS ?
185 if( yourls_is_installed() && !yourls_is_upgrading() && yourls_maybe_check_core_version() ) {
186     yourls_new_core_version_notice();
187 }
188
189 if( yourls_is_admin() )
190         yourls_do_action( 'admin_init' );
191