]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - includes/load-yourls.php
Started implementation of the maintenance mode
[Github/YOURLS.git] / includes / load-yourls.php
1 <?php\r
2 // This file initialize everything needed for YOURLS\r
3 \r
4 // Include settings\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
11 } else {\r
12         // config.php not found :(\r
13         require_once (dirname(__FILE__).'/functions.php');\r
14         require_once (dirname(__FILE__).'/functions-html.php');\r
15         define('YOURLS_SITE', dirname($_SERVER['REQUEST_URI'])); // LOL. Wild guess.\r
16         yourls_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
17 }\r
18 \r
19 // Include all functions\r
20 require_once (dirname(__FILE__).'/version.php');\r
21 require_once (dirname(__FILE__).'/functions.php');\r
22 require_once (dirname(__FILE__).'/functions-compat.php');\r
23 require_once (dirname(__FILE__).'/class-mysql.php');\r
24 require_once (dirname(__FILE__).'/functions-plugins.php');\r
25 // Load auth functions if needed\r
26 if( yourls_is_private() )\r
27         require_once( dirname(__FILE__).'/functions-auth.php' );\r
28 // Load template functions if needed\r
29 if( yourls_has_interface() )\r
30         require_once( dirname(__FILE__).'/functions-html.php' );\r
31 \r
32 // Check if config.php was properly updated for 1.4\r
33 if( !defined('YOURLS_DB_PREFIX') )\r
34         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
35 \r
36 // Define constants that have not been user defined in config.php\r
37 \r
38 // physical path of YOURLS root\r
39 if( !defined('YOURLS_ABSPATH') )\r
40         define('YOURLS_ABSPATH', yourls_sanitize_filename( dirname(dirname(__FILE__))) );\r
41 \r
42 // physical path of includes directory\r
43 if( !defined('YOURLS_INC') )\r
44         define('YOURLS_INC', yourls_sanitize_filename( YOURLS_ABSPATH.'/includes' ) );\r
45 \r
46 // physical path of user directory\r
47 if( !defined('YOURLS_USERDIR') )\r
48         define('YOURLS_USERDIR', yourls_sanitize_filename( YOURLS_ABSPATH.'/user' ) );\r
49 \r
50 // physical path of plugins directory\r
51 if( !defined('YOURLS_PLUGINDIR') )\r
52         define('YOURLS_PLUGINDIR', yourls_sanitize_filename( YOURLS_USERDIR.'/plugins' ) );\r
53 \r
54 // physical path of pages directory\r
55 if( !defined('YOURLS_PAGEDIR') )\r
56         define('YOURLS_ABSPATH', yourls_sanitize_filename( YOURLS_ABSPATH.'/pages' ) );\r
57 \r
58 // table to store URLs\r
59 if( !defined('YOURLS_DB_TABLE_URL') )\r
60         define('YOURLS_DB_TABLE_URL', YOURLS_DB_PREFIX.'url');\r
61 \r
62 // table to store options\r
63 if( !defined('YOURLS_DB_TABLE_OPTIONS') )\r
64         define('YOURLS_DB_TABLE_OPTIONS', YOURLS_DB_PREFIX.'options');\r
65 \r
66 // table to store hits, for stats\r
67 if( !defined('YOURLS_DB_TABLE_LOG') )\r
68         define('YOURLS_DB_TABLE_LOG', YOURLS_DB_PREFIX.'log');\r
69 \r
70 // minimum delay in sec before a same IP can add another URL. Note: logged in users are not throttled down.\r
71 if( !defined('YOURLS_FLOOD_DELAY_SECONDS') )\r
72         define('YOURLS_FLOOD_DELAY_SECONDS', 15 );\r
73 \r
74 // comma separated list of IPs that can bypass flood check.\r
75 if( !defined('YOURLS_FLOOD_IP_WHITELIST') )\r
76         define('YOURLS_FLOOD_IP_WHITELIST', '' );\r
77 \r
78 // life span of an auth cookie in seconds (60*60*24*7 = 7 days)\r
79 if( !defined('YOURLS_COOKIE_LIFE') )\r
80         define( 'YOURLS_COOKIE_LIFE', 60*60*24*7 );\r
81 \r
82 // life span of a nonce in seconds\r
83 if( !defined('YOURLS_NONCE_LIFE') )\r
84         define( 'YOURLS_NONCE_LIFE', 3600 );\r
85 \r
86 // if set to true, disable stat logging (no use for it, too busy servers, ...)\r
87 if( !defined('YOURLS_NOSTATS') )\r
88         define( 'YOURLS_NOSTATS', false );\r
89 \r
90 // if set to true, force https:// in the admin area\r
91 if( !defined('YOURLS_ADMIN_SSL') )\r
92         define( 'YOURLS_ADMIN_SSL', false );\r
93 \r
94 // if set to true, verbose debug infos. Will break things. Don't enable.\r
95 if( !defined('YOURLS_DEBUG') )\r
96         define( 'YOURLS_DEBUG', false );\r
97         \r
98 // Error reporting\r
99 if (defined('YOURLS_DEBUG') && YOURLS_DEBUG == true) {\r
100         error_reporting(E_ALL);\r
101 } else {\r
102         error_reporting(E_ERROR | E_PARSE);\r
103 }\r
104 \r
105 // If request for an admin page is http:// and SSL is required, redirect\r
106 if( yourls_is_admin() && yourls_needs_ssl() && !yourls_is_ssl() ) {\r
107         if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {\r
108                 yourls_redirect( preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI']) );\r
109                 exit();\r
110         } else {\r
111                 yourls_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );\r
112                 exit();\r
113         }\r
114 }\r
115 \r
116 // Create the YOURLS object $ydb that will contain everything we globally need\r
117 global $ydb;\r
118 yourls_db_connect();\r
119 \r
120 // Read options right from start\r
121 yourls_get_all_options();\r
122 \r
123 // Core now loaded\r
124 yourls_do_action( 'init' );\r
125 \r
126 // Check if we are in maintenance mode\r
127 yourls_check_maintenance_mode();\r
128 \r
129 // Check if need to redirect to install procedure\r
130 if( !yourls_is_installed() && ( !defined('YOURLS_INSTALLING') || YOURLS_INSTALLING != true ) ) {\r
131         yourls_redirect( YOURLS_SITE .'/admin/install.php' );\r
132 }\r
133 \r
134 // Check if upgrade is needed.\r
135 // Note: this is bypassable with define('YOURLS_NO_UPGRADE_CHECK', true)\r
136 // This is also bypassed if YOURLS_INSTALLING\r
137 if (\r
138         ( !defined('YOURLS_NO_UPGRADE_CHECK') || YOURLS_NO_UPGRADE_CHECK != true )\r
139         &&  \r
140         ( !defined('YOURLS_INSTALLING') || YOURLS_INSTALLING != true )\r
141 ) {\r
142         if ( yourls_upgrade_is_needed() ) {\r
143                 yourls_redirect( YOURLS_SITE .'/admin/upgrade.php' );\r
144         }\r
145 }\r
146 \r
147 // Init all plugins\r
148 yourls_load_plugins();\r
149 yourls_do_action( 'plugins_loaded' );\r