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