Many rewrites to get rid of dublicate modreg inserts while ext-cache is registered
[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 start time
43 $GLOBALS['startTime'] = microtime(true);
44
45 // Set module
46 $GLOBALS['module'] = 'surfbar';
47 $GLOBALS['refid']  = 0;
48 $GLOBALS['output_mode'] = 0;
49 $GLOBALS['header_sent'] = 3;
50 $msg = null;
51
52 // Load the required file(s)
53 require('inc/config-global.php');
54
55 // Is a frame active?
56 if (REQUEST_ISSET_GET('frame')) {
57         // Then we need to set header_sent to 0
58         $GLOBALS['header_sent'] = 0;
59 } // END - if
60
61 // Is the script installed?
62 if (!isInstalled()) {
63         // You have to install first!
64         redirectToUrl('install.php');
65 } // END - if
66
67 // Only logged in users may use this surfbar!
68 redirectOnUninstalledExtension('surfbar');
69
70 // No member?
71 if (!IS_MEMBER()) {
72         // Redirect
73         // @TODO Display quick login form here or redirect as configured
74         redirectToUrl('modules.php?module=index');
75 } // END - if
76
77 // Initialize the surfbar
78 SURFBAR_INIT();
79
80 // Handle tasks on self-maintenance
81 SURFBAR_HANDLE_SELF_MAINTENANCE();
82
83 // Is there a check value?
84 if ((SURFBAR_CHECK_RELOAD_FULL()) || ((REQUEST_ISSET_GET('frame')) && (in_array(REQUEST_GET('frame'), array('stop', 'stop2', 'stats', 'textlinks'))))) {
85         // Reload-lock is full, surfbar stopped so...
86         // Load header
87         loadIncludeOnce('inc/header.php');
88
89         // Load template
90         if (((REQUEST_ISSET_GET('frame')) && (REQUEST_GET('frame') == 'stop')) || (!REQUEST_ISSET_GET('frame'))) {
91                 // Load template for "start" page
92                 LOAD_TEMPLATE('surfbar_frame_start');
93
94                 // Load banner
95                 LOAD_TEMPLATE('surfbar_start_banner');
96
97                 // This makes the footer appear again
98                 REQUEST_UNSET_GET('frame');
99         } elseif ((REQUEST_ISSET_GET('frame')) && (REQUEST_GET('frame') == 'stats')) {
100                 // Get total points amount
101                 $points = GET_TOTAL_DATA(getUserId(), 'user_points', 'points') - GET_TOTAL_DATA(getUserId(), 'user_data', 'used_points');
102
103                 // Prepare content
104                 $content = array(
105                         'points'   => translateComma($points),
106                         'online'   => SURFBAR_DETERMINE_TOTAL_ONLINE(),
107                         'reload'   => (getConfig('surfbar_stats_reload') * 1000),
108                         'c_total'  => translateComma(getConfig('surfbar_total_counter')),
109                         'c_today'  => translateComma(getConfig('surfbar_daily_counter')),
110                         'c_yester' => translateComma(getConfig('surfbar_yester_counter')),
111                         'c_week'   => translateComma(getConfig('surfbar_weekly_counter')),
112                         'c_month'  => translateComma(getConfig('surfbar_monthly_counter')),
113                 );
114
115                 // Load template for "stats" page
116                 LOAD_TEMPLATE('surfbar_frame_stats', false, $content);
117         } elseif ((REQUEST_ISSET_GET('frame')) && (REQUEST_GET('frame') == 'textlinks')) {
118                 // Prepare content
119                 $content = array(
120                         'online'   => SURFBAR_DETERMINE_TOTAL_ONLINE(),
121                         'reload'   => (getConfig('surfbar_stats_reload') * 1000)
122                 );
123
124                 // Load template for "stats" page
125                 LOAD_TEMPLATE('surfbar_frame_textlinks', false, $content);
126         } else {
127                 // Prepare content
128                 $content = array(
129                         'restart'   => getConfig('surfbar_restart_time'),
130                         'start'     => str_repeat('X', strlen(getConfig('surfbar_restart_time'))),
131                         'autostart' => (getConfig('surfbar_autostart') == 'Y') ? 'true' : 'false'
132                 );
133
134                 // Load template for stopped surfbar
135                 LOAD_TEMPLATE('surfbar_stopped', false, $content);
136         }
137 } elseif ((REQUEST_ISSET_GET(('check'))) && (REQUEST_ISSET_GET('id')) && (REQUEST_ISSET_GET(('salt')))) {
138         // Dummy next id get
139         SURFBAR_DETERMINE_NEXT_ID(REQUEST_GET('id'));
140
141         // Check reload lock and validation code
142         if ((!SURFBAR_CHECK_RELOAD_LOCK(REQUEST_GET('id'))) && (SURFBAR_CHECK_VALIDATION_CODE(REQUEST_GET('id'), REQUEST_GET('check'), REQUEST_GET('salt')))) {
143                 // Lock the URL (id) down
144                 SURFBAR_LOCKDOWN_ID(REQUEST_GET('id'));
145
146                 // Code is valid so pay points here
147                 SURFBAR_PAY_POINTS();
148
149                 // Check if reload is full
150                 if (SURFBAR_CHECK_RELOAD_FULL()) {
151                         // Then load waiting page
152                         SURFBAR_RELOAD_TO_STOP_PAGE();
153                 } // END - if
154         } else {
155                 // Reload to stop frame!
156                 SURFBAR_RELOAD_TO_STOP_PAGE();
157         }
158
159         // All done, so fix notice for footer.php
160         $GLOBALS['footer_sent'] = 1;
161 } else {
162         // Prepare content
163         $content = '';
164
165         // Determine template name
166         $templateName = SURFBAR_DETERMINE_TEMPLATE_NAME();
167
168         // Frame "top" set?
169         if ((REQUEST_ISSET_GET('frame')) && (REQUEST_GET('frame') == 'top')) {
170                 // Determine next id
171                 $nextId = SURFBAR_DETERMINE_NEXT_ID();
172
173                 // Is there a valid id?
174                 if ($nextId > 0) {
175                         // Then prepare other content
176                         $content = array(
177                                 'id'          => $nextId,
178                                 'check'       => SURFBAR_GENERATE_VALIDATION_CODE($nextId),
179                                 'salt'        => SURFBAR_GET_SALT(),
180                                 'points'      => translateComma(SURFBAR_GET_REWARD($nextId)),
181                                 'url'         => SURFBAR_GET_URL($nextId),
182                                 'curr_reload' => SURFBAR_GET_USER_LOCKS(),
183                                 'max_urls'    => SURFBAR_GET_TOTAL_URLS(),
184                                 'reload'      => SURFBAR_GET_RELOAD_TIME($nextId),
185                                 'xxx'         => str_repeat('X', strlen(SURFBAR_GET_RELOAD_TIME($nextId)))
186                         );
187
188                         // Update salt (double-call lock!) and statistics
189                         SURFBAR_UPDATE_SALT_STATS();
190                 } else {
191                         // Load new URL
192                         SURFBAR_RELOAD_TO_STOP_PAGE('stop2');
193                 }
194         } elseif ((REQUEST_ISSET_GET('frame')) && (REQUEST_GET('frame') == 'start')) {
195                 // Starter frame found so let the footer display
196                 REQUEST_UNSET_GET('frame');
197         } else {
198                 // Load header in frameset mode
199                 $isFrameset = true;
200         }
201
202         // Load header
203         loadIncludeOnce('inc/header.php');
204
205         // Load that template
206         //* DEBUG: */ die("templateName={$templateName}<br />\n<strong>content</strong>=<pre>".print_r($content, true)."</pre>");
207         LOAD_TEMPLATE($templateName, false, $content);
208 }
209
210 // Load footer
211 $GLOBALS['footer_sent'] = 3;
212 loadIncludeOnce('inc/footer.php');
213
214 // [EOF]
215 ?>