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