source: trunk/smf/index.php @ 1184

Revision 1165, 15.2 KB checked in by infoarena, 3 months ago (diff)

Updated SMF to 1.1.16

  • Property svn:eol-style set to native
Line 
1<?php
2/**********************************************************************************
3* index.php                                                                       *
4***********************************************************************************
5* SMF: Simple Machines Forum                                                      *
6* Open-Source Project Inspired by Zef Hemel (zef@zefhemel.com)                    *
7* =============================================================================== *
8* Software Version:           SMF 1.1.16                                          *
9* Software by:                Simple Machines (http://www.simplemachines.org)     *
10* Copyright 2006-2009 by:     Simple Machines LLC (http://www.simplemachines.org) *
11*           2001-2006 by:     Lewis Media (http://www.lewismedia.com)             *
12* Support, News, Updates at:  http://www.simplemachines.org                       *
13***********************************************************************************
14* This program is free software; you may redistribute it and/or modify it under   *
15* the terms of the provided license as published by Simple Machines LLC.          *
16*                                                                                 *
17* This program is distributed in the hope that it is and will be useful, but      *
18* WITHOUT ANY WARRANTIES; without even any implied warranty of MERCHANTABILITY    *
19* or FITNESS FOR A PARTICULAR PURPOSE.                                            *
20*                                                                                 *
21* See the "license.txt" file for details of the Simple Machines license.          *
22* The latest version can always be found at http://www.simplemachines.org.        *
23**********************************************************************************/
24
25
26/*      This, as you have probably guessed, is the crux on which SMF functions.
27        Everything should start here, so all the setup and security is done
28        properly.  The most interesting part of this file is the action array in
29        the smf_main() function.  It is formatted as so:
30
31                'action-in-url' => array('Source-File.php', 'FunctionToCall'),
32
33        Then, you can access the FunctionToCall() function from Source-File.php
34        with the URL index.php?action=action-in-url.  Relatively simple, no?
35*/
36
37$forum_version = 'SMF 1.1.16';
38
39// Get everything started up...
40define('SMF', 1);
41@set_magic_quotes_runtime(0);
42error_reporting(E_ALL);
43$time_start = microtime();
44
45// Make sure some things simply do not exist.
46foreach (array('db_character_set') as $variable)
47        if (isset($GLOBALS[$variable]))
48                unset($GLOBALS[$variable], $GLOBALS[$variable]);
49
50// Load the settings...
51require_once(dirname(__FILE__) . '/Settings.php');
52
53// And important includes.
54require_once($sourcedir . '/QueryString.php');
55require_once($sourcedir . '/Subs.php');
56require_once($sourcedir . '/Errors.php');
57
58// infoarena integration (must stay here)
59require_once(dirname(__FILE__) . '/infoarena.php');
60
61require_once($sourcedir . '/Load.php');
62require_once($sourcedir . '/Security.php');
63
64// Using an old version of PHP?
65if (@version_compare(PHP_VERSION, '4.2.3') != 1)
66        require_once($sourcedir . '/Subs-Compat.php');
67
68// If $maintenance is set specifically to 2, then we're upgrading or something.
69if (!empty($maintenance) && $maintenance == 2)
70        db_fatal_error();
71
72// Connect to the MySQL database.
73if (empty($db_persist))
74        $db_connection = @mysql_connect($db_server, $db_user, $db_passwd);
75else
76        $db_connection = @mysql_pconnect($db_server, $db_user, $db_passwd);
77
78// Show an error if the connection couldn't be made.
79if (!$db_connection || !@mysql_select_db($db_name, $db_connection))
80        db_fatal_error();
81
82// restore infoarena session (if such a session exists)
83identity_restore();
84
85// Load the settings from the settings table, and perform operations like optimizing.
86reloadSettings();
87// Clean the request variables, add slashes, etc.
88cleanRequest();
89$context = array();
90
91// Seed the random generator?
92if (empty($modSettings['rand_seed']) || mt_rand(1, 250) == 69)
93        smf_seed_generator();
94
95// 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.
96if (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/vnd.wap.xhtml+xml') !== false)
97        $_REQUEST['wap2'] = 1;
98elseif (isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'text/vnd.wap.wml') !== false)
99{
100        if (strpos($_SERVER['HTTP_USER_AGENT'], 'DoCoMo/') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'portalmmm/') !== false)
101                $_REQUEST['imode'] = 1;
102        else
103                $_REQUEST['wap'] = 1;
104}
105
106if (!defined('WIRELESS'))
107        define('WIRELESS', isset($_REQUEST['wap']) || isset($_REQUEST['wap2']) || isset($_REQUEST['imode']));
108
109// Some settings and headers are different for wireless protocols.
110if (WIRELESS)
111{
112        define('WIRELESS_PROTOCOL', isset($_REQUEST['wap']) ? 'wap' : (isset($_REQUEST['wap2']) ? 'wap2' : (isset($_REQUEST['imode']) ? 'imode' : '')));
113
114        // Some cellphones can't handle output compression...
115        $modSettings['enableCompressedOutput'] = '0';
116        // !!! Do we want these hard coded?
117        $modSettings['defaultMaxMessages'] = 5;
118        $modSettings['defaultMaxTopics'] = 9;
119
120        // Wireless protocol header.
121        if (WIRELESS_PROTOCOL == 'wap')
122                header('Content-Type: text/vnd.wap.wml');
123}
124
125// Check if compressed output is enabled, supported, and not already being done.
126if (!empty($modSettings['enableCompressedOutput']) && !headers_sent() && ob_get_length() == 0)
127{
128        // If zlib is being used, turn off output compression.
129        if (@ini_get('zlib.output_compression') == '1' || @ini_get('output_handler') == 'ob_gzhandler' || @version_compare(PHP_VERSION, '4.2.0') == -1)
130                $modSettings['enableCompressedOutput'] = '0';
131        else
132                ob_start('ob_gzhandler');
133}
134// This makes it so headers can be sent!
135if (empty($modSettings['enableCompressedOutput']))
136        ob_start();
137
138// Register an error handler.
139set_error_handler('error_handler');
140
141// Start the session. (assuming it hasn't already been.)
142loadSession();
143
144// What function shall we execute? (done like this for memory's sake.)
145call_user_func(smf_main());
146
147// Call obExit specially; we're coming from the main area ;).
148obExit(null, null, true);
149
150// The main controlling function.
151function smf_main()
152{
153        global $modSettings, $settings, $user_info, $board, $topic, $maintenance, $sourcedir;
154
155        // Special case: session keep-alive.
156        if (isset($_GET['action']) && $_GET['action'] == 'keepalive')
157                die;
158
159        // Load the user's cookie (or set as guest) and load their settings.
160        loadUserSettings();
161
162        // Load the current board's information.
163        loadBoard();
164
165        // Load the current theme.  (note that ?theme=1 will also work, may be used for guest theming.)
166        loadTheme();
167
168        // Check if the user should be disallowed access.
169        is_not_banned();
170
171        // Load the current user's permissions.
172        loadPermissions();
173
174        // Do some logging, unless this is an attachment, avatar, theme option or XML feed.
175        if (empty($_REQUEST['action']) || !in_array($_REQUEST['action'], array('dlattach', 'jsoption', '.xml')))
176        {
177                // Log this user as online.
178                writeLog();
179
180                // Track forum statistics and hits...?
181                if (!empty($modSettings['hitStats']))
182                        trackStats(array('hits' => '+'));
183        }
184
185        // Is the forum in maintenance mode? (doesn't apply to administrators.)
186        if (!empty($maintenance) && !allowedTo('admin_forum'))
187        {
188                // You can only login.... otherwise, you're getting the "maintenance mode" display.
189                if (isset($_REQUEST['action']) && ($_REQUEST['action'] == 'login2' || $_REQUEST['action'] == 'logout'))
190                {
191                        require_once($sourcedir . '/LogInOut.php');
192                        return $_REQUEST['action'] == 'login2' ? 'Login2' : 'Logout';
193                }
194                // Don't even try it, sonny.
195                else
196                {
197                        require_once($sourcedir . '/Subs-Auth.php');
198                        return 'InMaintenance';
199                }
200        }
201        // If guest access is off, a guest can only do one of the very few following actions.
202        elseif (empty($modSettings['allow_guestAccess']) && $user_info['is_guest'] && (!isset($_REQUEST['action']) || !in_array($_REQUEST['action'], array('coppa', 'login', 'login2', 'register', 'register2', 'reminder', 'activate', 'smstats', 'help', 'verificationcode'))))
203        {
204                require_once($sourcedir . '/Subs-Auth.php');
205                return 'KickGuest';
206        }
207        elseif (empty($_REQUEST['action']))
208        {
209                // Action and board are both empty... BoardIndex!
210                if (empty($board) && empty($topic))
211                {
212                        require_once($sourcedir . '/BoardIndex.php');
213                        return 'BoardIndex';
214                }
215                // Topic is empty, and action is empty.... MessageIndex!
216                elseif (empty($topic))
217                {
218                        require_once($sourcedir . '/MessageIndex.php');
219                        return 'MessageIndex';
220                }
221                // Board is not empty... topic is not empty... action is empty.. Display!
222                else
223                {
224                        require_once($sourcedir . '/Display.php');
225                        return 'Display';
226                }
227        }
228
229        // Here's the monstrous $_REQUEST['action'] array - $_REQUEST['action'] => array($file, $function).
230        $actionArray = array(
231                'activate' => array('Register.php', 'Activate'),
232                'admin' => array('Admin.php', 'Admin'),
233                'announce' => array('Post.php', 'AnnounceTopic'),
234                'ban' => array('ManageBans.php', 'Ban'),
235                'boardrecount' => array('Admin.php', 'AdminBoardRecount'),
236                'buddy' => array('Subs-Members.php', 'BuddyListToggle'),
237                'calendar' => array('Calendar.php', 'CalendarMain'),
238                'cleanperms' => array('Admin.php', 'CleanupPermissions'),
239                'collapse' => array('Subs-Boards.php', 'CollapseCategory'),
240                'convertentities' => array('Admin.php', 'ConvertEntities'),
241                'convertutf8' => array('Admin.php', 'ConvertUtf8'),
242                'coppa' => array('Register.php', 'CoppaForm'),
243                'deletemsg' => array('RemoveTopic.php', 'DeleteMessage'),
244                'detailedversion' => array('Admin.php', 'VersionDetail'),
245                'display' => array('Display.php', 'Display'),
246                'dlattach' => array('Display.php', 'Download'),
247                'dumpdb' => array('DumpDatabase.php', 'DumpDatabase2'),
248                'editpoll' => array('Poll.php', 'EditPoll'),
249                'editpoll2' => array('Poll.php', 'EditPoll2'),
250                'featuresettings' => array('ModSettings.php', 'ModifyFeatureSettings'),
251                'featuresettings2' => array('ModSettings.php', 'ModifyFeatureSettings2'),
252
253        // Features stripped for integration with infoarena
254                // 'findmember' => array('Subs-Auth.php', 'JSMembers'),
255                // 'mlist' => array('Memberlist.php', 'Memberlist'),
256
257                'help' => array('Help.php', 'ShowHelp'),
258                'helpadmin' => array('Help.php', 'ShowAdminHelp'),
259                'im' => array('PersonalMessage.php', 'MessageMain'),
260                'jsoption' => array('Themes.php', 'SetJavaScript'),
261                'jsmodify' => array('Post.php', 'JavaScriptModify'),
262                'lock' => array('LockTopic.php', 'LockTopic'),
263                'lockVoting' => array('Poll.php', 'LockVoting'),
264
265        // Features stripped for integration with infoarena
266                // 'login' => array('LogInOut.php', 'Login'),
267                // 'login2' => array('LogInOut.php', 'Login2'),
268                // 'logout' => array('LogInOut.php', 'Logout'),
269
270                'maintain' => array('Admin.php', 'Maintenance'),
271                'manageattachments' => array('ManageAttachments.php', 'ManageAttachments'),
272                'manageboards' => array('ManageBoards.php', 'ManageBoards'),
273                'managecalendar' => array('ManageCalendar.php', 'ManageCalendar'),
274                'managesearch' => array('ManageSearch.php', 'ManageSearch'),
275                'markasread' => array('Subs-Boards.php', 'MarkRead'),
276                'membergroups' => array('ManageMembergroups.php', 'ModifyMembergroups'),
277                'mergetopics' => array('SplitTopics.php', 'MergeTopics'),
278                'modifycat' => array('ManageBoards.php', 'ModifyCat'),
279                'modifykarma' => array('Karma.php', 'ModifyKarma'),
280                'modlog' => array('Modlog.php', 'ViewModlog'),
281                'movetopic' => array('MoveTopic.php', 'MoveTopic'),
282                'movetopic2' => array('MoveTopic.php', 'MoveTopic2'),
283                'news' => array('ManageNews.php', 'ManageNews'),
284                'notify' => array('Notify.php', 'Notify'),
285                'notifyboard' => array('Notify.php', 'BoardNotify'),
286                'optimizetables' => array('Admin.php', 'OptimizeTables'),
287                'packageget' => array('PackageGet.php', 'PackageGet'),
288                'packages' => array('Packages.php', 'Packages'),
289                'permissions' => array('ManagePermissions.php', 'ModifyPermissions'),
290                'pgdownload' => array('PackageGet.php', 'PackageGet'),
291                'pm' => array('PersonalMessage.php', 'MessageMain'),
292                'post' => array('Post.php', 'Post'),
293                'post2' => array('Post.php', 'Post2'),
294                'postsettings' => array('ManagePosts.php', 'ManagePostSettings'),
295                'printpage' => array('Printpage.php', 'PrintTopic'),
296
297        // Features stripped for integration with infoarena
298                'profile' => array('Profile.php', 'ModifyProfile'),
299                'profile2' => array('Profile.php', 'ModifyProfile2'),
300
301                'quotefast' => array('Post.php', 'QuoteFast'),
302                'quickmod' => array('Subs-Boards.php', 'QuickModeration'),
303                'quickmod2' => array('Subs-Boards.php', 'QuickModeration2'),
304                'recent' => array('Recent.php', 'RecentPosts'),
305                'regcenter' => array('ManageRegistration.php', 'RegCenter'),
306
307        // Features stripped for integration with infoarena
308                // 'register' => array('Register.php', 'Register'),
309                // 'register2' => array('Register.php', 'Register2'),
310                // 'reminder' => array('Reminder.php', 'RemindMe'),
311
312                'removetopic2' => array('RemoveTopic.php', 'RemoveTopic2'),
313                'removeoldtopics2' => array('RemoveTopic.php', 'RemoveOldTopics2'),
314                'removepoll' => array('Poll.php', 'RemovePoll'),
315                'repairboards' => array('RepairBoards.php', 'RepairBoards'),
316                'reporttm' => array('SendTopic.php', 'ReportToModerator'),
317                'reports' => array('Reports.php', 'ReportsMain'),
318                'requestmembers' => array('Subs-Auth.php', 'RequestMembers'),
319                'search' => array('Search.php', 'PlushSearch1'),
320                'search2' => array('Search.php', 'PlushSearch2'),
321                'sendtopic' => array('SendTopic.php', 'SendTopic'),
322                'serversettings' => array('ManageServer.php', 'ModifySettings'),
323                'serversettings2' => array('ManageServer.php', 'ModifySettings2'),
324                'smileys' => array('ManageSmileys.php', 'ManageSmileys'),
325                'smstats' => array('Stats.php', 'SMStats'),
326                'spellcheck' => array('Subs-Post.php', 'SpellCheck'),
327                'splittopics' => array('SplitTopics.php', 'SplitTopics'),
328                'stats' => array('Stats.php', 'DisplayStats'),
329                'sticky' => array('LockTopic.php', 'Sticky'),
330                'theme' => array('Themes.php', 'ThemesMain'),
331                'trackip' => array('Profile.php', 'trackIP'),
332                'about:mozilla' => array('Karma.php', 'BookOfUnknown'),
333                'about:unknown' => array('Karma.php', 'BookOfUnknown'),
334                'unread' => array('Recent.php', 'UnreadTopics'),
335                'unreadreplies' => array('Recent.php', 'UnreadTopics'),
336                'viewErrorLog' => array('ManageErrors.php', 'ViewErrorLog'),
337                'viewmembers' => array('ManageMembers.php', 'ViewMembers'),
338                'viewprofile' => array('Profile.php', 'ModifyProfile'),
339
340        // Feature stripped for integration with infoarena
341                'verificationcode' => array('Register.php', 'VerificationCode'),
342
343                'vote' => array('Poll.php', 'Vote'),
344                'viewquery' => array('ViewQuery.php', 'ViewQuery'),
345                'who' => array('Who.php', 'Who'),
346                '.xml' => array('News.php', 'ShowXmlFeed'),
347        );
348
349        // Get the function and file to include - if it's not there, do the board index.
350        if (!isset($_REQUEST['action']) || !isset($actionArray[$_REQUEST['action']]))
351        {
352                // Catch the action with the theme?
353                if (!empty($settings['catch_action']))
354                {
355                        require_once($sourcedir . '/Themes.php');
356                        return 'WrapAction';
357                }
358
359                // Fall through to the board index then...
360                require_once($sourcedir . '/BoardIndex.php');
361                return 'BoardIndex';
362        }
363
364        // Otherwise, it was set - so let's go to that action.
365        require_once($sourcedir . '/' . $actionArray[$_REQUEST['action']][0]);
366        return $actionArray[$_REQUEST['action']][1];
367}
368
369?>
Note: See TracBrowser for help on using the repository browser.