(Possible) fixes for illegal array indexes
[mailer.git] / surfbar.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 09/05/2008 *
4  * ===============                              Last change: 09/05/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : surfbar.php                                      *
8  * -------------------------------------------------------------------- *
9  * Short description : The surfbar itself                               *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Die Surfbar selbst                               *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * Needs to be in all Files and every File needs "svn propset           *
18  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
19  * -------------------------------------------------------------------- *
20  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Load security stuff here
40 require('inc/libs/security_functions.php');
41
42 // Init "action" and "what"
43 $GLOBALS['cache_array']['surfbar'] = array();
44 $GLOBALS['startTime'] = microtime(true);
45 $GLOBALS['what'] = '';
46 $GLOBALS['action'] = '';
47
48 // Set module
49 $GLOBALS['module'] = 'surfbar';
50 $GLOBALS['refid']  = 0;
51 $GLOBALS['output_mode'] = 0;
52 $msg = null;
53
54 // Load the required file(s)
55 require('inc/config-global.php');
56
57 // Is the script installed?
58 if (!isInstalled()) {
59         // You have to install first!
60         redirectToUrl('install.php');
61 } // END - if
62
63 // Only logged in users may use this surfbar!
64 redirectOnUninstalledExtension('surfbar');
65
66 // No member?
67 if (!IS_MEMBER()) {
68         // Redirect
69         // @TODO Display quick login form here or redirect as configured
70         redirectToUrl('modules.php?module=index');
71 } // END - if
72
73 // Handle tasks on self-maintenance
74 SURFBAR_HANDLE_SELF_MAINTENANCE();
75
76 // Is there a check value?
77 if ((SURFBAR_CHECK_RELOAD_FULL()) || ((REQUEST_ISSET_GET('frame')) && (in_array(REQUEST_GET('frame'), array('stop', 'stop2', 'stats', 'textlinks'))))) {
78         // Reload-lock is full, surfbar stopped so...
79         // Load header
80         loadIncludeOnce('inc/header.php');
81
82         // Load template
83         if (((REQUEST_ISSET_GET('frame')) && (REQUEST_GET('frame') == 'stop')) || (!REQUEST_ISSET_GET('frame'))) {
84                 // Load template for "start" page
85                 LOAD_TEMPLATE('surfbar_frame_start');
86
87                 // Load banner
88                 LOAD_TEMPLATE('surfbar_start_banner');
89
90                 // This makes the footer appear again
91                 REQUEST_UNSET_GET('frame');
92         } elseif ((REQUEST_ISSET_GET('frame')) && (REQUEST_GET('frame') == 'stats')) {
93                 // Get total points amount
94                 $points = GET_TOTAL_DATA(getUserId(), 'user_points', 'points') - GET_TOTAL_DATA(getUserId(), 'user_data', 'used_points');
95
96                 // Prepare content
97                 $content = array(
98                         'points'   => translateComma($points),
99                         'online'   => SURFBAR_DETERMINE_TOTAL_ONLINE(),
100                         'reload'   => (getConfig('surfbar_stats_reload') * 1000),
101                         'c_total'  => translateComma(getConfig('surfbar_total_counter')),
102                         'c_today'  => translateComma(getConfig('surfbar_daily_counter')),
103                         'c_yester' => translateComma(getConfig('surfbar_yester_counter')),
104                         'c_week'   => translateComma(getConfig('surfbar_weekly_counter')),
105                         'c_month'  => translateComma(getConfig('surfbar_monthly_counter')),
106                 );
107
108                 // Load template for "stats" page
109                 LOAD_TEMPLATE('surfbar_frame_stats', false, $content);
110         } elseif ((REQUEST_ISSET_GET('frame')) && (REQUEST_GET('frame') == 'textlinks')) {
111                 // Prepare content
112                 $content = array(
113                         'online'   => SURFBAR_DETERMINE_TOTAL_ONLINE(),
114                         'reload'   => (getConfig('surfbar_stats_reload') * 1000)
115                 );
116
117                 // Load template for "stats" page
118                 LOAD_TEMPLATE('surfbar_frame_textlinks', false, $content);
119         } else {
120                 // Prepare content
121                 $content = array(
122                         'restart'   => getConfig('surfbar_restart_time'),
123                         'start'     => str_repeat('X', strlen(getConfig('surfbar_restart_time'))),
124                         'autostart' => (getConfig('surfbar_autostart') == 'Y') ? 'true' : 'false'
125                 );
126
127                 // Load template for stopped surfbar
128                 LOAD_TEMPLATE('surfbar_stopped', false, $content);
129         }
130 } elseif ((REQUEST_ISSET_GET(('check'))) && (REQUEST_ISSET_GET('id')) && (REQUEST_ISSET_GET(('salt')))) {
131         // Dummy next id get
132         SURFBAR_DETERMINE_NEXT_ID(REQUEST_GET('id'));
133
134         // Check reload lock and validation code
135         if ((!SURFBAR_CHECK_RELOAD_LOCK(REQUEST_GET('id'))) && (SURFBAR_CHECK_VALIDATION_CODE(REQUEST_GET('id'), REQUEST_GET('check'), REQUEST_GET('salt')))) {
136                 // Lock the URL (id) down
137                 SURFBAR_LOCKDOWN_ID(REQUEST_GET('id'));
138
139                 // Code is valid so pay points here
140                 SURFBAR_PAY_POINTS();
141
142                 // Check if reload is full
143                 if (SURFBAR_CHECK_RELOAD_FULL()) {
144                         // Then load waiting page
145                         SURFBAR_RELOAD_TO_STOP_PAGE();
146                 } // END - if
147         } else {
148                 // Reload to stop frame!
149                 SURFBAR_RELOAD_TO_STOP_PAGE();
150         }
151
152         // All done, so fix notice for footer.php
153         $GLOBALS['footer_sent'] = 1;
154 } else {
155         // Prepare content
156         $content = '';
157
158         // Determine template name
159         $templateName = SURFBAR_DETERMINE_TEMPLATE_NAME();
160
161         // Frame "top" set?
162         if ((REQUEST_ISSET_GET('frame')) && (REQUEST_GET('frame') == 'top')) {
163                 // Determine next id
164                 $nextId = SURFBAR_DETERMINE_NEXT_ID();
165
166                 // Is there a valid id?
167                 if ($nextId > 0) {
168                         // Then prepare other content
169                         $content = array(
170                                 'id'          => $nextId,
171                                 'check'       => SURFBAR_GENERATE_VALIDATION_CODE($nextId),
172                                 'salt'        => SURFBAR_GET_SALT(),
173                                 'reward'      => translateComma(SURFBAR_GET_REWARD($nextId)),
174                                 'url'         => SURFBAR_GET_URL($nextId),
175                                 'curr_reload' => SURFBAR_GET_USER_LOCKS(),
176                                 'max_urls'    => SURFBAR_GET_TOTAL_URLS(),
177                                 'reload'      => SURFBAR_GET_RELOAD_TIME($nextId),
178                                 'xxx'         => str_repeat('X', strlen(SURFBAR_GET_RELOAD_TIME($nextId)))
179                         );
180
181                         // Update salt (double-call lock!) and statistics
182                         SURFBAR_UPDATE_SALT_STATS();
183                 } else {
184                         // Load new URL
185                         SURFBAR_RELOAD_TO_STOP_PAGE('stop2');
186                 }
187         } elseif ((REQUEST_ISSET_GET('frame')) && (REQUEST_GET('frame') == 'start')) {
188                 // Starter frame found so let the footer display
189                 REQUEST_UNSET_GET('frame');
190         } else {
191                 // Load header in frameset mode
192                 $isFrameset = true;
193         }
194
195         // Load header
196         loadIncludeOnce('inc/header.php');
197
198         // Load that template
199         //* DEBUG: */ die("templateName={$templateName}<br />\n<strong>content</strong>=<pre>".print_r($content, true)."</pre>");
200         LOAD_TEMPLATE($templateName, false, $content);
201 }
202
203 // Load footer
204 loadIncludeOnce('inc/footer.php');
205
206 // [EOF]
207 ?>