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