fooRequestElementBar() functions renamed, adding of request parameters added:
[mailer.git] / surfbar.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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 - 2009 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 start time
43 $GLOBALS['startTime'] = microtime(true);
44
45 // Set module
46 $GLOBALS['module'] = 'surfbar';
47 $GLOBALS['output_mode'] = '0';
48 $GLOBALS['header_sent'] = 3;
49
50 // Load the required file(s)
51 require('inc/config-global.php');
52
53 // Set content type
54 setContentType('text/html');
55
56 // Is a frame active?
57 if (isGetRequestParameterSet('frame')) {
58         // Then we need to set header_sent to 0
59         $GLOBALS['header_sent'] = '0';
60 } // END - if
61
62 // Only logged in users may use this surfbar!
63 redirectOnUninstalledExtension('surfbar');
64
65 // No member?
66 if (!isMember()) {
67         // Should we display login window or redirect to main page?
68         if ((getConfig('surfbar_guest_login_form') == 'Y') && (isExtensionActive('user'))) {
69                 // Is the form sent?
70                 if ((isFormSent()) && (isPostRequestParameterSet('id')) && (isPostRequestParameterSet('password'))) {
71                         // Do the login procedure
72                         $URL = doUserLogin(postRequestParameter('id'), postRequestParameter('password'), basename(__FILE__), basename(__FILE__) . '?code=');
73
74                         // And redirect to the URL
75                         redirectToUrl($URL);
76                 } else {
77                         // Load header
78                         loadIncludeOnce('inc/header.php');
79
80                         // Is there a 'code' provided?
81                         if (isGetRequestParameterSet('code')) {
82                                 // Then generate an error message
83                                 loadTemplate('admin_settings_saved', false, getMessageFromErrorCode(getRequestParameter('code')));
84                         } // END - if
85
86                         // Display login form
87                         loadTemplate('surfbar_login_form');
88
89                         // Allow footer here
90                         $GLOBALS['header_sent'] = 2;
91
92                         // Load footer
93                         loadIncludeOnce('inc/footer.php');
94                 }
95         } else {
96                 // Redirect
97                 redirectToUrl('index.php');
98         }
99 } // END - if
100
101 // Initialize the surfbar
102 SURFBAR_INIT();
103
104 // Handle tasks on self-maintenance
105 SURFBAR_HANDLE_SELF_MAINTENANCE();
106
107 // Is there a check value?
108 if ((SURFBAR_CHECK_RELOAD_FULL()) || ((isGetRequestParameterSet('frame')) && (in_array(getRequestParameter('frame'), array('stop', 'stop2', 'stats', 'textlinks'))))) {
109         // Reload-lock is full, surfbar stopped so...
110         // Load header
111         loadIncludeOnce('inc/header.php');
112
113         // Load template
114         if (((isGetRequestParameterSet('frame')) && (getRequestParameter('frame') == 'stop2')) || (!isGetRequestParameterSet('frame'))) {
115                 // Load template for "start" page
116                 loadTemplate('surfbar_frame_start');
117
118                 // Load banner
119                 loadTemplate('surfbar_start_banner');
120
121                 // This makes the footer appear again
122                 unsetGetRequestParameter('frame');
123         } elseif ((isGetRequestParameterSet('frame')) && (getRequestParameter('frame') == 'stats')) {
124                 // Get total points amount
125                 $points = countSumTotalData(getMemberId(), 'user_points', 'points') - countSumTotalData(getMemberId(), 'user_data', 'used_points');
126
127                 // Prepare content
128                 $content = array(
129                         'points'   => translateComma($points),
130                         'online'   => SURFBAR_DETERMINE_TOTAL_ONLINE(),
131                         'reload'   => (getConfig('surfbar_stats_reload') * 1000),
132                         'c_total'  => translateComma(getConfig('surfbar_total_counter')),
133                         'c_today'  => translateComma(getConfig('surfbar_daily_counter')),
134                         'c_yester' => translateComma(getConfig('surfbar_yester_counter')),
135                         'c_week'   => translateComma(getConfig('surfbar_weekly_counter')),
136                         'c_month'  => translateComma(getConfig('surfbar_monthly_counter')),
137                 );
138
139                 // Load template for "stats" page
140                 loadTemplate('surfbar_frame_stats', false, $content);
141         } elseif ((isGetRequestParameterSet('frame')) && (getRequestParameter('frame') == 'textlinks')) {
142                 // Prepare content
143                 $content = array(
144                         'online'   => SURFBAR_DETERMINE_TOTAL_ONLINE(),
145                         'reload'   => (getConfig('surfbar_stats_reload') * 1000)
146                 );
147
148                 // Load template for "stats" page
149                 loadTemplate('surfbar_frame_textlinks', false, $content);
150         } else {
151                 // Prepare content
152                 $content = array(
153                         'start'     => str_repeat('X', strlen(getConfig('surfbar_restart_time'))),
154                         'autostart' => (getConfig('surfbar_autostart') == 'Y') ? 'true' : 'false'
155                 );
156
157                 // Load template for stopped surfbar
158                 loadTemplate('surfbar_stopped', false, $content);
159         }
160 } elseif ((isGetRequestParameterSet('check')) && (isGetRequestParameterSet('id')) && (isGetRequestParameterSet('salt'))) {
161         // Dummy next id get
162         SURFBAR_DETERMINE_NEXT_ID(getRequestParameter('id'));
163
164         // Check reload lock and validation code
165         if ((!SURFBAR_CHECK_RELOAD_LOCK(getRequestParameter('id'))) && (SURFBAR_CHECK_VALIDATION_CODE(getRequestParameter('id'), getRequestParameter('check'), getRequestParameter('salt')))) {
166                 // Lock the URL (id) down
167                 SURFBAR_LOCKDOWN_ID(getRequestParameter('id'));
168
169                 // Code is valid so pay points here
170                 SURFBAR_PAY_POINTS();
171
172                 // Check if reload is full
173                 if (SURFBAR_CHECK_RELOAD_FULL()) {
174                         // Then load waiting page
175                         SURFBAR_RELOAD_TO_STOP_PAGE();
176                 } // END - if
177         } else {
178                 // Reload to stop frame!
179                 SURFBAR_RELOAD_TO_STOP_PAGE();
180         }
181
182         // All done, so fix notice for footer.php
183         $GLOBALS['footer_sent'] = 1;
184 } else {
185         // Prepare content
186         $content = '';
187
188         // Determine template name
189         $templateName = SURFBAR_DETERMINE_TEMPLATE_NAME();
190
191         // Load header in frameset mode is the default
192         $isFrameset = true;
193
194         // Frame "top" set?
195         if ((isGetRequestParameterSet('frame')) && (getRequestParameter('frame') == 'top')) {
196                 // Determine next id
197                 $nextId = SURFBAR_DETERMINE_NEXT_ID();
198
199                 // Is there a valid id?
200                 if ($nextId > 0) {
201                         // Then prepare other content
202                         $content = array(
203                                 'id'          => $nextId,
204                                 'check'       => SURFBAR_GENERATE_VALIDATION_CODE($nextId),
205                                 'salt'        => SURFBAR_GET_SALT(),
206                                 'reward'      => translateComma(SURFBAR_GET_REWARD($nextId)),
207                                 'url'         => SURFBAR_GET_URL($nextId),
208                                 'curr_reload' => SURFBAR_GET_USER_LOCKS(),
209                                 'max_urls'    => SURFBAR_GET_TOTAL_URLS(),
210                                 'reload'      => SURFBAR_GET_RELOAD_TIME($nextId),
211                                 'xxx'         => str_repeat('X', strlen(SURFBAR_GET_RELOAD_TIME($nextId)))
212                         );
213
214                         // Update salt (double-call lock!) and statistics
215                         SURFBAR_UPDATE_SALT_STATS();
216                 } else {
217                         // Load new URL
218                         SURFBAR_RELOAD_TO_STOP_PAGE('stop');
219                 }
220         } elseif ((isGetRequestParameterSet('frame')) && (getRequestParameter('frame') == 'start')) {
221                 // Starter frame found so let the footer display
222                 unsetGetRequestParameter('frame');
223         }
224
225         // Load header
226         loadIncludeOnce('inc/header.php');
227
228         // Load that template
229         //* DEBUG: */ die("templateName={$templateName}<br />\n<strong>content</strong>=<pre>".print_r($content, true)."</pre>");
230         loadTemplate($templateName, false, $content);
231 }
232
233 // Load footer
234 $GLOBALS['footer_sent'] = 3;
235 loadIncludeOnce('inc/footer.php');
236
237 // [EOF]
238 ?>