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