Hotfix
[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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Load security stuff here
39 require('inc/libs/security_functions.php');
40
41 // Init start time
42 $GLOBALS['startTime'] = microtime(true);
43
44 // Set module output mode
45 $GLOBALS['module'] = 'surfbar';
46 $GLOBALS['output_mode'] = '0';
47 $GLOBALS['header_sent'] = 3;
48
49 // Load the required file(s)
50 require('inc/config-global.php');
51
52 // Set content type
53 setContentType('text/html');
54
55 // Is a frame active?
56 if (isGetRequestElementSet('frame')) {
57         // Then we need to set header_sent to 0
58         $GLOBALS['header_sent'] = '0';
59 } // END - if
60
61 // Only logged in users may use this surfbar!
62 redirectOnUninstalledExtension('surfbar');
63
64 // No member?
65 if (!isMember()) {
66         // Should we display login window or redirect to main page?
67         if ((getConfig('surfbar_guest_login_form') == 'Y') && (isExtensionActive('user'))) {
68                 // Is the form sent?
69                 if ((isFormSent()) && (isPostRequestElementSet('id')) && (isPostRequestElementSet('password'))) {
70                         // Do the login procedure
71                         $url = doUserLogin(postRequestElement('id'), postRequestElement('password'), basename(__FILE__), basename(__FILE__) . '?code=');
72
73                         // And redirect to the URL
74                         redirectToUrl($url);
75                 } else {
76                         // Load header
77                         loadIncludeOnce('inc/header.php');
78
79                         // Is there a 'code' provided?
80                         if (isGetRequestElementSet('code')) {
81                                 // Then generate an error message
82                                 displayMessage(getMessageFromErrorCode(getRequestElement('code')));
83                         } // END - if
84
85                         // Display login form
86                         loadTemplate('surfbar_login_form');
87
88                         // Allow footer here
89                         $GLOBALS['header_sent'] = 2;
90
91                         // Load footer
92                         loadIncludeOnce('inc/footer.php');
93                 }
94         } else {
95                 // Redirect
96                 redirectToUrl('modules.php?module=index');
97         }
98 } // END - if
99
100 // Initialize the surfbar
101 SURFBAR_INIT();
102
103 // Handle tasks on self-maintenance
104 SURFBAR_HANDLE_SELF_MAINTENANCE();
105
106 // Is there a check value?
107 if ((SURFBAR_CHECK_RELOAD_FULL()) || ((isGetRequestElementSet('frame')) && (in_array(getRequestElement('frame'), array('stop', 'stop2', 'stats', 'textlinks'))))) {
108         // Reload-lock is full, surfbar stopped so...
109         // Load header
110         loadIncludeOnce('inc/header.php');
111
112         // Load template
113         if (((isGetRequestElementSet('frame')) && (getRequestElement('frame') == 'stop2')) || (!isGetRequestElementSet('frame'))) {
114                 // Load template for "start" page
115                 loadTemplate('surfbar_frame_start');
116
117                 // Load banner
118                 loadTemplate('surfbar_start_banner');
119
120                 // This makes the footer appear again
121                 unsetGetRequestElement('frame');
122         } elseif ((isGetRequestElementSet('frame')) && (getRequestElement('frame') == 'stats')) {
123                 // Prepare content
124                 $content = array(
125                         'points' => getTotalPoints(getMemberId()),
126                         'reload' => (getConfig('surfbar_stats_reload') * 1000)
127                 );
128
129                 // Load template for "stats" page
130                 loadTemplate('surfbar_frame_stats', false, $content);
131         } elseif ((isGetRequestElementSet('frame')) && (getRequestElement('frame') == 'textlinks')) {
132                 // Prepare content
133                 $content = array(
134                         'reload' => (getConfig('surfbar_stats_reload') * 1000)
135                 );
136
137                 // Load template for "stats" page
138                 loadTemplate('surfbar_frame_textlinks', false, $content);
139         } else {
140                 // Prepare content
141                 $content = array(
142                         'start'     => str_repeat('X', strlen(getConfig('surfbar_restart_time'))),
143                         'autostart' => (getConfig('surfbar_autostart') == 'Y') ? 'true' : 'false'
144                 );
145
146                 // Load template for stopped surfbar
147                 loadTemplate('surfbar_stopped', false, $content);
148         }
149 } elseif ((isGetRequestElementSet('check')) && (isGetRequestElementSet('id')) && (isGetRequestElementSet('salt'))) {
150         // Dummy next id get
151         SURFBAR_DETERMINE_NEXT_ID(getRequestElement('id'));
152
153         // Check reload lock and validation code
154         if ((!SURFBAR_CHECK_RELOAD_LOCK(getRequestElement('id'))) && (SURFBAR_CHECK_VALIDATION_CODE(getRequestElement('id'), getRequestElement('check'), getRequestElement('salt')))) {
155                 // Lock the URL (id) down
156                 SURFBAR_LOCKDOWN_ID(getRequestElement('id'));
157
158                 // Code is valid so pay points here
159                 SURFBAR_PAY_POINTS();
160
161                 // Check if reload is full
162                 if (SURFBAR_CHECK_RELOAD_FULL()) {
163                         // Then load waiting page
164                         SURFBAR_RELOAD_TO_STOP_PAGE();
165                 } // END - if
166
167                 // Load header to avoid a bug
168                 loadIncludeOnce('inc/header.php');
169         } else {
170                 // Reload to stop frame!
171                 SURFBAR_RELOAD_TO_STOP_PAGE();
172         }
173
174         // All done, so fix notice for footer.php
175         $GLOBALS['footer_sent'] = 1;
176 } else {
177         // Prepare content
178         $content = '';
179
180         // Frame "top" set?
181         if ((isGetRequestElementSet('frame')) && (getRequestElement('frame') == 'top')) {
182                 // Determine next id
183                 $nextId = SURFBAR_DETERMINE_NEXT_ID();
184                 //* DEBUG: */ die('nextId='.$nextId);
185
186                 // Is there a valid id?
187                 if ($nextId > 0) {
188                         // Then prepare other content
189                         $content = array(
190                                 'url_id' => $nextId,
191                                 'xxx'    => str_repeat('X', strlen(SURFBAR_GET_RELOAD_TIME($nextId))),
192                         );
193
194                         // Update salt (double-call lock!) and statistics
195                         SURFBAR_UPDATE_SALT_STATS();
196                 } else {
197                         // Load new URL
198                         SURFBAR_RELOAD_TO_STOP_PAGE('stop');
199                 }
200         } elseif ((isGetRequestElementSet('frame')) && (getRequestElement('frame') == 'start')) {
201                 // Starter frame found so let the footer display
202                 unsetGetRequestElement('frame');
203         }
204
205         // Load header
206         loadIncludeOnce('inc/header.php');
207
208         // Determine template name
209         $templateName = SURFBAR_DETERMINE_TEMPLATE_NAME();
210
211         // Load that template
212         //* DEBUG: */ die('templateName=' . $templateName . '<br /><strong>content</strong>=<pre>' . print_r($content, true) . '</pre>');
213         loadTemplate($templateName, false, $content);
214 }
215
216 // Load footer
217 $GLOBALS['footer_sent'] = 3;
218 loadIncludeOnce('inc/footer.php');
219
220 // [EOF]
221 ?>