Extension ext-coupon continued, a lot improvements applied:
[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://www.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
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 (isGetRequestParameterSet('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()) && (isPostRequestParameterSet('id')) && (isPostRequestParameterSet('password'))) {
70                         // Do the login procedure
71                         $URL = doUserLogin(postRequestParameter('id'), postRequestParameter('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 (isGetRequestParameterSet('code')) {
81                                 // Then generate an error message
82                                 displayMessage(getMessageFromErrorCode(getRequestParameter('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()) || ((isGetRequestParameterSet('frame')) && (in_array(getRequestParameter('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 (((isGetRequestParameterSet('frame')) && (getRequestParameter('frame') == 'stop2')) || (!isGetRequestParameterSet('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                 unsetGetRequestParameter('frame');
122         } elseif ((isGetRequestParameterSet('frame')) && (getRequestParameter('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 ((isGetRequestParameterSet('frame')) && (getRequestParameter('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 ((isGetRequestParameterSet('check')) && (isGetRequestParameterSet('id')) && (isGetRequestParameterSet('salt'))) {
150         // Dummy next id get
151         SURFBAR_DETERMINE_NEXT_ID(getRequestParameter('id'));
152
153         // Check reload lock and validation code
154         if ((!SURFBAR_CHECK_RELOAD_LOCK(getRequestParameter('id'))) && (SURFBAR_CHECK_VALIDATION_CODE(getRequestParameter('id'), getRequestParameter('check'), getRequestParameter('salt')))) {
155                 // Lock the URL (id) down
156                 SURFBAR_LOCKDOWN_ID(getRequestParameter('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         } else {
167                 // Reload to stop frame!
168                 SURFBAR_RELOAD_TO_STOP_PAGE();
169         }
170
171         // All done, so fix notice for footer.php
172         $GLOBALS['footer_sent'] = 1;
173 } else {
174         // Prepare content
175         $content = '';
176
177         // Determine template name
178         $templateName = SURFBAR_DETERMINE_TEMPLATE_NAME();
179
180         // Load header in frameset mode is the default
181         $isFrameset = true;
182
183         // Frame "top" set?
184         if ((isGetRequestParameterSet('frame')) && (getRequestParameter('frame') == 'top')) {
185                 // Determine next id
186                 $nextId = SURFBAR_DETERMINE_NEXT_ID();
187
188                 // Is there a valid id?
189                 if ($nextId > 0) {
190                         // Then prepare other content
191                         $content = array(
192                                 'url_id' => $nextId,
193                                 'xxx'    => str_repeat('X', strlen(SURFBAR_GET_RELOAD_TIME($nextId))),
194                         );
195
196                         // Update salt (double-call lock!) and statistics
197                         SURFBAR_UPDATE_SALT_STATS();
198                 } else {
199                         // Load new URL
200                         SURFBAR_RELOAD_TO_STOP_PAGE('stop');
201                 }
202         } elseif ((isGetRequestParameterSet('frame')) && (getRequestParameter('frame') == 'start')) {
203                 // Starter frame found so let the footer display
204                 unsetGetRequestParameter('frame');
205         }
206
207         // Load header
208         loadIncludeOnce('inc/header.php');
209
210         // Load that template
211         //* DEBUG: */ die('templateName=' . $templateName . '<br /><strong>content</strong>=<pre>' . print_r($content, true) . '</pre>');
212         loadTemplate($templateName, false, $content);
213 }
214
215 // Load footer
216 $GLOBALS['footer_sent'] = 3;
217 loadIncludeOnce('inc/footer.php');
218
219 // [EOF]
220 ?>