Mercurial > hg > vamp-website
comparison forum/index.php @ 76:e3e11437ecea website
Add forum code
author | Chris Cannam |
---|---|
date | Sun, 07 Jul 2013 11:25:48 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
75:72f59aa7e503 | 76:e3e11437ecea |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * Simple Machines Forum (SMF) | |
5 * | |
6 * @package SMF | |
7 * @author Simple Machines http://www.simplemachines.org | |
8 * @copyright 2011 Simple Machines | |
9 * @license http://www.simplemachines.org/about/smf/license.php BSD | |
10 * | |
11 * @version 2.0.4 | |
12 */ | |
13 | |
14 /* This, as you have probably guessed, is the crux on which SMF functions. | |
15 Everything should start here, so all the setup and security is done | |
16 properly. The most interesting part of this file is the action array in | |
17 the smf_main() function. It is formatted as so: | |
18 | |
19 'action-in-url' => array('Source-File.php', 'FunctionToCall'), | |
20 | |
21 Then, you can access the FunctionToCall() function from Source-File.php | |
22 with the URL index.php?action=action-in-url. Relatively simple, no? | |
23 */ | |
24 | |
25 $forum_version = 'SMF 2.0.4'; | |
26 | |
27 // Get everything started up... | |
28 define('SMF', 1); | |
29 if (function_exists('set_magic_quotes_runtime')) | |
30 @set_magic_quotes_runtime(0); | |
31 error_reporting(defined('E_STRICT') ? E_ALL | E_STRICT : E_ALL); | |
32 $time_start = microtime(); | |
33 | |
34 // This makes it so headers can be sent! | |
35 ob_start(); | |
36 | |
37 // Do some cleaning, just in case. | |
38 foreach (array('db_character_set', 'cachedir') as $variable) | |
39 if (isset($GLOBALS[$variable])) | |
40 unset($GLOBALS[$variable], $GLOBALS[$variable]); | |
41 | |
42 // Load the settings... | |
43 require_once(dirname(__FILE__) . '/Settings.php'); | |
44 | |
45 // Make absolutely sure the cache directory is defined. | |
46 if ((empty($cachedir) || !file_exists($cachedir)) && file_exists($boarddir . '/cache')) | |
47 $cachedir = $boarddir . '/cache'; | |
48 | |
49 // And important includes. | |
50 require_once($sourcedir . '/QueryString.php'); | |
51 require_once($sourcedir . '/Subs.php'); | |
52 require_once($sourcedir . '/Errors.php'); | |
53 require_once($sourcedir . '/Load.php'); | |
54 require_once($sourcedir . '/Security.php'); | |
55 | |
56 // Using an pre-PHP 5.1 version? | |
57 if (@version_compare(PHP_VERSION, '5.1') == -1) | |
58 require_once($sourcedir . '/Subs-Compat.php'); | |
59 | |
60 // If $maintenance is set specifically to 2, then we're upgrading or something. | |
61 if (!empty($maintenance) && $maintenance == 2) | |
62 db_fatal_error(); | |
63 | |
64 // Create a variable to store some SMF specific functions in. | |
65 $smcFunc = array(); | |
66 | |
67 // Initate the database connection and define some database functions to use. | |
68 loadDatabase(); | |
69 | |
70 // Load the settings from the settings table, and perform operations like optimizing. | |
71 reloadSettings(); | |
72 // Clean the request variables, add slashes, etc. | |
73 cleanRequest(); | |
74 $context = array(); | |
75 | |
76 // Seed the random generator. | |
77 if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69) | |
78 smf_seed_generator(); | |
79 | |
80 // Before we get carried away, are we doing a scheduled task? If so save CPU cycles by jumping out! | |
81 if (isset($_GET['scheduled'])) | |
82 { | |
83 require_once($sourcedir . '/ScheduledTasks.php'); | |
84 AutoTask(); | |
85 } | |
86 | |
87 // Check if compressed output is enabled, supported, and not already being done. | |
88 if (!empty($modSettings['enableCompressedOutput']) && !headers_sent()) | |
89 { | |
90 // If zlib is being used, turn off output compression. | |
91 if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler' || @version_compare(PHP_VERSION, '4.2.0') == -1) | |
92 $modSettings['enableCompressedOutput'] = '0'; | |
93 else | |
94 { | |
95 ob_end_clean(); | |
96 ob_start('ob_gzhandler'); | |
97 } | |
98 } | |
99 | |
100 // Register an error handler. | |
101 set_error_handler('error_handler'); | |
102 | |
103 // Start the session. (assuming it hasn't already been.) | |
104 loadSession(); | |
105 | |
106 // Determine if this is using WAP, WAP2, or imode. Technically, we should check that wap comes before application/xhtml or text/html, but this doesn't work in practice as much as it should. | |
107 if (isset($_REQUEST['wap']) || isset($_REQUEST['wap2']) || isset($_REQUEST['imode'])) | |
108 unset($_SESSION['nowap']); | |
109 elseif (isset($_REQUEST['nowap'])) | |
110 $_SESSION['nowap'] = true; | |
111 elseif (!isset($_SESSION['nowap'])) | |
112 { | |
113 if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/vnd.wap.xhtml+xml') !== false) | |
114 $_REQUEST['wap2'] = 1; | |
115 elseif (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'text/vnd.wap.wml') !== false) | |
116 { | |
117 if (strpos($_SERVER['HTTP_USER_AGENT'], 'DoCoMo/') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'portalmmm/') !== false) | |
118 $_REQUEST['imode'] = 1; | |
119 else | |
120 $_REQUEST['wap'] = 1; | |
121 } | |
122 } | |
123 | |
124 if (!defined('WIRELESS')) | |
125 define('WIRELESS', isset($_REQUEST['wap']) || isset($_REQUEST['wap2']) || isset($_REQUEST['imode'])); | |
126 | |
127 // Some settings and headers are different for wireless protocols. | |
128 if (WIRELESS) | |
129 { | |
130 define('WIRELESS_PROTOCOL', isset($_REQUEST['wap']) ? 'wap' : (isset($_REQUEST['wap2']) ? 'wap2' : (isset($_REQUEST['imode']) ? 'imode' : ''))); | |
131 | |
132 // Some cellphones can't handle output compression... | |
133 $modSettings['enableCompressedOutput'] = '0'; | |
134 // !!! Do we want these hard coded? | |
135 $modSettings['defaultMaxMessages'] = 5; | |
136 $modSettings['defaultMaxTopics'] = 9; | |
137 | |
138 // Wireless protocol header. | |
139 if (WIRELESS_PROTOCOL == 'wap') | |
140 header('Content-Type: text/vnd.wap.wml'); | |
141 } | |
142 | |
143 // Restore post data if we are revalidating OpenID. | |
144 if (isset($_GET['openid_restore_post']) && !empty($_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]['post']) && empty($_POST)) | |
145 { | |
146 $_POST = $_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]['post']; | |
147 unset($_SESSION['openid']['saved_data'][$_GET['openid_restore_post']]); | |
148 } | |
149 | |
150 // What function shall we execute? (done like this for memory's sake.) | |
151 call_user_func(smf_main()); | |
152 | |
153 // Call obExit specially; we're coming from the main area ;). | |
154 obExit(null, null, true); | |
155 | |
156 // The main controlling function. | |
157 function smf_main() | |
158 { | |
159 global $modSettings, $settings, $user_info, $board, $topic, $board_info, $maintenance, $sourcedir; | |
160 | |
161 // Special case: session keep-alive, output a transparent pixel. | |
162 if (isset($_GET['action']) && $_GET['action'] == 'keepalive') | |
163 { | |
164 header('Content-Type: image/gif'); | |
165 die("\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x21\xF9\x04\x01\x00\x00\x00\x00\x2C\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3B"); | |
166 } | |
167 | |
168 // Load the user's cookie (or set as guest) and load their settings. | |
169 loadUserSettings(); | |
170 | |
171 // Load the current board's information. | |
172 loadBoard(); | |
173 | |
174 // Load the current user's permissions. | |
175 loadPermissions(); | |
176 | |
177 // Attachments don't require the entire theme to be loaded. | |
178 if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'dlattach' && (!empty($modSettings['allow_guestAccess']) && $user_info['is_guest'])) | |
179 detectBrowser(); | |
180 // Load the current theme. (note that ?theme=1 will also work, may be used for guest theming.) | |
181 else | |
182 loadTheme(); | |
183 | |
184 // Check if the user should be disallowed access. | |
185 is_not_banned(); | |
186 | |
187 // If we are in a topic and don't have permission to approve it then duck out now. | |
188 if (!empty($topic) && empty($board_info['cur_topic_approved']) && !allowedTo('approve_posts') && ($user_info['id'] != $board_info['cur_topic_starter'] || $user_info['is_guest'])) | |
189 fatal_lang_error('not_a_topic', false); | |
190 | |
191 // Do some logging, unless this is an attachment, avatar, toggle of editor buttons, theme option, XML feed etc. | |
192 if (empty($_REQUEST['action']) || !in_array($_REQUEST['action'], array('dlattach', 'findmember', 'jseditor', 'jsoption', 'requestmembers', 'smstats', '.xml', 'xmlhttp', 'verificationcode', 'viewquery', 'viewsmfile'))) | |
193 { | |
194 // Log this user as online. | |
195 writeLog(); | |
196 | |
197 // Track forum statistics and hits...? | |
198 if (!empty($modSettings['hitStats'])) | |
199 trackStats(array('hits' => '+')); | |
200 } | |
201 | |
202 // Is the forum in maintenance mode? (doesn't apply to administrators.) | |
203 if (!empty($maintenance) && !allowedTo('admin_forum')) | |
204 { | |
205 // You can only login.... otherwise, you're getting the "maintenance mode" display. | |
206 if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'login2' || $_REQUEST['action'] == 'logout')) | |
207 { | |
208 require_once($sourcedir . '/LogInOut.php'); | |
209 return $_REQUEST['action'] == 'login2' ? 'Login2' : 'Logout'; | |
210 } | |
211 // Don't even try it, sonny. | |
212 else | |
213 { | |
214 require_once($sourcedir . '/Subs-Auth.php'); | |
215 return 'InMaintenance'; | |
216 } | |
217 } | |
218 // If guest access is off, a guest can only do one of the very few following actions. | |
219 elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'register', 'register2', 'reminder', 'activate', 'help', 'smstats', 'mailq', 'verificationcode', 'openidreturn')))) | |
220 { | |
221 require_once($sourcedir . '/Subs-Auth.php'); | |
222 return 'KickGuest'; | |
223 } | |
224 elseif (empty($_REQUEST['action'])) | |
225 { | |
226 // Action and board are both empty... BoardIndex! | |
227 if (empty($board) && empty($topic)) | |
228 { | |
229 require_once($sourcedir . '/BoardIndex.php'); | |
230 return 'BoardIndex'; | |
231 } | |
232 // Topic is empty, and action is empty.... MessageIndex! | |
233 elseif (empty($topic)) | |
234 { | |
235 require_once($sourcedir . '/MessageIndex.php'); | |
236 return 'MessageIndex'; | |
237 } | |
238 // Board is not empty... topic is not empty... action is empty.. Display! | |
239 else | |
240 { | |
241 require_once($sourcedir . '/Display.php'); | |
242 return 'Display'; | |
243 } | |
244 } | |
245 | |
246 // Here's the monstrous $_REQUEST['action'] array - $_REQUEST['action'] => array($file, $function). | |
247 $actionArray = array( | |
248 'activate' => array('Register.php', 'Activate'), | |
249 'admin' => array('Admin.php', 'AdminMain'), | |
250 'announce' => array('Post.php', 'AnnounceTopic'), | |
251 'attachapprove' => array('ManageAttachments.php', 'ApproveAttach'), | |
252 'buddy' => array('Subs-Members.php', 'BuddyListToggle'), | |
253 'calendar' => array('Calendar.php', 'CalendarMain'), | |
254 'clock' => array('Calendar.php', 'clock'), | |
255 'collapse' => array('BoardIndex.php', 'CollapseCategory'), | |
256 'coppa' => array('Register.php', 'CoppaForm'), | |
257 'credits' => array('Who.php', 'Credits'), | |
258 'deletemsg' => array('RemoveTopic.php', 'DeleteMessage'), | |
259 'display' => array('Display.php', 'Display'), | |
260 'dlattach' => array('Display.php', 'Download'), | |
261 'editpoll' => array('Poll.php', 'EditPoll'), | |
262 'editpoll2' => array('Poll.php', 'EditPoll2'), | |
263 'emailuser' => array('SendTopic.php', 'EmailUser'), | |
264 'findmember' => array('Subs-Auth.php', 'JSMembers'), | |
265 'groups' => array('Groups.php', 'Groups'), | |
266 'help' => array('Help.php', 'ShowHelp'), | |
267 'helpadmin' => array('Help.php', 'ShowAdminHelp'), | |
268 'im' => array('PersonalMessage.php', 'MessageMain'), | |
269 'jseditor' => array('Subs-Editor.php', 'EditorMain'), | |
270 'jsmodify' => array('Post.php', 'JavaScriptModify'), | |
271 'jsoption' => array('Themes.php', 'SetJavaScript'), | |
272 'lock' => array('LockTopic.php', 'LockTopic'), | |
273 'lockvoting' => array('Poll.php', 'LockVoting'), | |
274 'login' => array('LogInOut.php', 'Login'), | |
275 'login2' => array('LogInOut.php', 'Login2'), | |
276 'logout' => array('LogInOut.php', 'Logout'), | |
277 'markasread' => array('Subs-Boards.php', 'MarkRead'), | |
278 'mergetopics' => array('SplitTopics.php', 'MergeTopics'), | |
279 'mlist' => array('Memberlist.php', 'Memberlist'), | |
280 'moderate' => array('ModerationCenter.php', 'ModerationMain'), | |
281 'modifycat' => array('ManageBoards.php', 'ModifyCat'), | |
282 'modifykarma' => array('Karma.php', 'ModifyKarma'), | |
283 'movetopic' => array('MoveTopic.php', 'MoveTopic'), | |
284 'movetopic2' => array('MoveTopic.php', 'MoveTopic2'), | |
285 'notify' => array('Notify.php', 'Notify'), | |
286 'notifyboard' => array('Notify.php', 'BoardNotify'), | |
287 'openidreturn' => array('Subs-OpenID.php', 'smf_openID_return'), | |
288 'pm' => array('PersonalMessage.php', 'MessageMain'), | |
289 'post' => array('Post.php', 'Post'), | |
290 'post2' => array('Post.php', 'Post2'), | |
291 'printpage' => array('Printpage.php', 'PrintTopic'), | |
292 'profile' => array('Profile.php', 'ModifyProfile'), | |
293 'quotefast' => array('Post.php', 'QuoteFast'), | |
294 'quickmod' => array('MessageIndex.php', 'QuickModeration'), | |
295 'quickmod2' => array('Display.php', 'QuickInTopicModeration'), | |
296 'recent' => array('Recent.php', 'RecentPosts'), | |
297 'register' => array('Register.php', 'Register'), | |
298 'register2' => array('Register.php', 'Register2'), | |
299 'reminder' => array('Reminder.php', 'RemindMe'), | |
300 'removepoll' => array('Poll.php', 'RemovePoll'), | |
301 'removetopic2' => array('RemoveTopic.php', 'RemoveTopic2'), | |
302 'reporttm' => array('SendTopic.php', 'ReportToModerator'), | |
303 'requestmembers' => array('Subs-Auth.php', 'RequestMembers'), | |
304 'restoretopic' => array('RemoveTopic.php', 'RestoreTopic'), | |
305 'search' => array('Search.php', 'PlushSearch1'), | |
306 'search2' => array('Search.php', 'PlushSearch2'), | |
307 'sendtopic' => array('SendTopic.php', 'EmailUser'), | |
308 'smstats' => array('Stats.php', 'SMStats'), | |
309 'suggest' => array('Subs-Editor.php', 'AutoSuggestHandler'), | |
310 'spellcheck' => array('Subs-Post.php', 'SpellCheck'), | |
311 'splittopics' => array('SplitTopics.php', 'SplitTopics'), | |
312 'stats' => array('Stats.php', 'DisplayStats'), | |
313 'sticky' => array('LockTopic.php', 'Sticky'), | |
314 'theme' => array('Themes.php', 'ThemesMain'), | |
315 'trackip' => array('Profile-View.php', 'trackIP'), | |
316 'about:mozilla' => array('Karma.php', 'BookOfUnknown'), | |
317 'about:unknown' => array('Karma.php', 'BookOfUnknown'), | |
318 'unread' => array('Recent.php', 'UnreadTopics'), | |
319 'unreadreplies' => array('Recent.php', 'UnreadTopics'), | |
320 'verificationcode' => array('Register.php', 'VerificationCode'), | |
321 'viewprofile' => array('Profile.php', 'ModifyProfile'), | |
322 'vote' => array('Poll.php', 'Vote'), | |
323 'viewquery' => array('ViewQuery.php', 'ViewQuery'), | |
324 'viewsmfile' => array('Admin.php', 'DisplayAdminFile'), | |
325 'who' => array('Who.php', 'Who'), | |
326 '.xml' => array('News.php', 'ShowXmlFeed'), | |
327 'xmlhttp' => array('Xml.php', 'XMLhttpMain'), | |
328 ); | |
329 | |
330 // Allow modifying $actionArray easily. | |
331 call_integration_hook('integrate_actions', array(&$actionArray)); | |
332 | |
333 // Get the function and file to include - if it's not there, do the board index. | |
334 if (!isset($_REQUEST['action']) || !isset($actionArray[$_REQUEST['action']])) | |
335 { | |
336 // Catch the action with the theme? | |
337 if (!empty($settings['catch_action'])) | |
338 { | |
339 require_once($sourcedir . '/Themes.php'); | |
340 return 'WrapAction'; | |
341 } | |
342 | |
343 // Fall through to the board index then... | |
344 require_once($sourcedir . '/BoardIndex.php'); | |
345 return 'BoardIndex'; | |
346 } | |
347 | |
348 // Otherwise, it was set - so let's go to that action. | |
349 require_once($sourcedir . '/' . $actionArray[$_REQUEST['action']][0]); | |
350 return $actionArray[$_REQUEST['action']][1]; | |
351 } | |
352 | |
353 ?> |