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