]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - includes/load-yourls.php
- move test for error reporting
[Github/YOURLS.git] / includes / load-yourls.php
1 <?php\r
2 // This file initialize everything needed for YOURLS\r
3 \r
4 // Include settings and functions\r
5 if( !file_exists(dirname(__FILE__).'/config.php') ) {\r
6         require_once (dirname(__FILE__).'/functions.php');\r
7         require_once (dirname(__FILE__).'/functions-html.php');\r
8         define('YOURLS_SITE', dirname($_SERVER['REQUEST_URI'])); // LOL. Wild guess.\r
9         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
10 }\r
11         \r
12 require_once (dirname(__FILE__).'/config.php');\r
13 require_once (dirname(__FILE__).'/version.php');\r
14 require_once (dirname(__FILE__).'/functions.php');\r
15 require_once (dirname(__FILE__).'/functions-baseconvert.php');\r
16 require_once (dirname(__FILE__).'/class-mysql.php');\r
17 // Load auth functions if needed\r
18 if( yourls_is_private() )\r
19         require_once( dirname(__FILE__).'/functions-auth.php' );\r
20 // Load template functions if needed\r
21 if( yourls_has_interface() )\r
22         require_once( dirname(__FILE__).'/functions-html.php' );\r
23 \r
24 // Check if config.php was properly updated for 1.4\r
25 if( !defined('YOURLS_DB_PREFIX') )\r
26         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
27 \r
28 // Define constants that have not been user defined in config.php\r
29 if( !defined('YOURLS_DB_TABLE_URL') )\r
30         define('YOURLS_DB_TABLE_URL', YOURLS_DB_PREFIX.'url'); // table to store URLs\r
31 if( !defined('YOURLS_DB_TABLE_OPTIONS') )\r
32         define('YOURLS_DB_TABLE_OPTIONS', YOURLS_DB_PREFIX.'options'); // table to store options\r
33 if( !defined('YOURLS_DB_TABLE_LOG') )\r
34         define('YOURLS_DB_TABLE_LOG', YOURLS_DB_PREFIX.'log');  // table to store hits, for stats\r
35 if( !defined('YOURLS_FLOOD_DELAY_SECONDS') )\r
36         define('YOURLS_FLOOD_DELAY_SECONDS', 15 ); // minimum delay in sec before a same IP can add another URL. Note: logged in users are not throttled down.\r
37 if( !defined('YOURLS_FLOOD_IP_WHITELIST') )\r
38         define('YOURLS_FLOOD_IP_WHITELIST', '' ); // comma separated list of IPs that can bypass flood check.\r
39 if( !defined('YOURLS_COOKIE_LIFE') )\r
40         define( 'YOURLS_COOKIE_LIFE', 60*60*24*7 ); // life span of an auth cookie in seconds (60*60*24*7 = 7 days)\r
41 if( !defined('YOURLS_NONCE_LIFE') )\r
42         define( 'YOURLS_NONCE_LIFE', 3600 ); // life span of a nonce in seconds\r
43 if( !defined('YOURLS_NOSTATS') )\r
44         define( 'YOURLS_NOSTATS', false ); // if set to true, disable stat logging (no use for it, too busy servers, ...)\r
45 if( !defined('YOURLS_ADMIN_SSL') )\r
46         define( 'YOURLS_ADMIN_SSL', false ); // if set to true, force https:// in the admin area\r
47 if( !defined('YOURLS_DEBUG') )\r
48         define( 'YOURLS_DEBUG', false ); // if set to true, verbose debug infos. Will break things. Don't enable.\r
49 \r
50 // Error reporting\r
51 if (defined('YOURLS_DEBUG') && YOURLS_DEBUG == true) {\r
52         error_reporting(E_ALL);\r
53 } else {\r
54         error_reporting(E_ERROR | E_PARSE);\r
55 }\r
56 \r
57 // If request for an admin page is http:// and SSL is required, redirect\r
58 if( yourls_is_admin() && yourls_needs_ssl() && !yourls_is_ssl() ) {\r
59         if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {\r
60                 yourls_redirect( preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI']) );\r
61                 exit();\r
62         } else {\r
63                 yourls_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );\r
64                 exit();\r
65         }\r
66 }\r
67 \r
68 // Create the YOURLS object $ydb that will contain everything we globally need\r
69 if ( function_exists( 'yourls_db_connect' ) ) {\r
70         global $ydb;\r
71         yourls_db_connect();\r
72 }\r
73 \r
74 // Read options right from start\r
75 yourls_get_all_options();\r
76 \r
77 // Check if need to redirect to install procedure\r
78 if( !yourls_is_installed() && ( !defined('YOURLS_INSTALLING') || YOURLS_INSTALLING != true ) ) {\r
79         yourls_redirect( YOURLS_SITE .'/admin/install.php' );\r
80 }\r
81 \r
82 // Check if upgrade is needed.\r
83 // Note: this is bypassable with define('YOURLS_NO_UPGRADE_CHECK', true)\r
84 // This is also bypassed if YOURLS_INSTALLING\r
85 if (\r
86         ( !defined('YOURLS_NO_UPGRADE_CHECK') || YOURLS_NO_UPGRADE_CHECK != true )\r
87         &&  \r
88         ( !defined('YOURLS_INSTALLING') || YOURLS_INSTALLING != true )\r
89 ) {\r
90         if ( yourls_upgrade_is_needed() ) {\r
91                 yourls_redirect( YOURLS_SITE .'/admin/upgrade.php' );\r
92         }\r
93 }