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