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