01ddd7e57ac7de9a95560f288dfd63f636b26ce9
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Load security stuff here (Oh, I hope this is not unsecure? Am I paranoia??? ;-) )
35 require("inc/libs/security_functions.php");
36
37 // Init "action" and "what"
38 $GLOBALS['cache_array']['surfbar'] = array();
39 $GLOBALS['startTime'] = microtime(true);
40 $GLOBALS['what'] = "";
41 $GLOBALS['action'] = "";
42
43 // Set module
44 $GLOBALS['module'] = "surfbar";
45 $GLOBALS['refid']  = 0;
46 $GLOBALS['output_mode'] = 0;
47 $msg = null;
48
49 // Load the required file(s)
50 require("inc/config.php");
51
52 // Is the script installed?
53 if (isBooleanConstantAndTrue('mxchange_installed')) {
54         // Only logged in users may use this surfbar!
55         REDIRECT_ON_UNINSTALLED_EXTENSION("surfbar");
56
57         // No member?
58         if (!IS_MEMBER()) {
59                 // Redirect
60                 // @TODO Display quick login form here or redirect as configured
61                 LOAD_URL("modules.php?module=index");
62         } // END - if
63
64         // Handle tasks on self-maintenance
65         SURFBAR_HANDLE_SELF_MAINTENANCE();
66
67         // Is there a check value?
68         if ((SURFBAR_CHECK_RELOAD_FULL()) || ((REQUEST_ISSET_GET(('frame'))) && (in_array(REQUEST_GET('frame'), array("stop", "stop2", "stats", "textlinks"))))) {
69                 // Reload-lock is full, surfbar stopped so...
70                 // Load header
71                 LOAD_INC_ONCE("inc/header.php");
72
73                 // Load template
74                 if (((REQUEST_ISSET_GET(('frame'))) && (REQUEST_GET('frame') == "stop")) || (!REQUEST_ISSET_GET(('frame')))) {
75                         // Load template for "start" page
76                         LOAD_TEMPLATE("surfbar_frame_start");
77
78                         // Load banner
79                         LOAD_TEMPLATE("surfbar_start_banner");
80
81                         // This makes the footer appear again
82                         REQUEST_UNSET_GET(('frame'));
83                 } elseif ((REQUEST_ISSET_GET(('frame'))) && (REQUEST_GET('frame') == "stats")) {
84                         // Get total points amount
85                         $points = GET_TOTAL_DATA($GLOBALS['userid'], "user_points", "points") - GET_TOTAL_DATA($GLOBALS['userid'], "user_data", "used_points");
86
87                         // Prepare content
88                         $content = array(
89                                 'points'   => TRANSLATE_COMMA($points),
90                                 'online'   => SURFBAR_DETERMINE_TOTAL_ONLINE(),
91                                 'reload'   => (getConfig('surfbar_stats_reload') * 1000),
92                                 'c_total'  => TRANSLATE_COMMA(getConfig('surfbar_total_counter')),
93                                 'c_today'  => TRANSLATE_COMMA(getConfig('surfbar_daily_counter')),
94                                 'c_yester' => TRANSLATE_COMMA(getConfig('surfbar_yester_counter')),
95                                 'c_week'   => TRANSLATE_COMMA(getConfig('surfbar_weekly_counter')),
96                                 'c_month'  => TRANSLATE_COMMA(getConfig('surfbar_monthly_counter')),
97                         );
98
99                         // Load template for "stats" page
100                         LOAD_TEMPLATE("surfbar_frame_stats", false, $content);
101                 } elseif ((REQUEST_ISSET_GET(('frame'))) && (REQUEST_GET('frame') == "textlinks")) {
102                         // Prepare content
103                         $content = array(
104                                 'online'   => SURFBAR_DETERMINE_TOTAL_ONLINE(),
105                                 'reload'   => (getConfig('surfbar_stats_reload') * 1000)
106                         );
107
108                         // Load template for "stats" page
109                         LOAD_TEMPLATE("surfbar_frame_textlinks", false, $content);
110                 } else {
111                         // Prepare content
112                         $content = array(
113                                 'restart'   => getConfig('surfbar_restart_time'),
114                                 'start'     => str_repeat("X", strlen(getConfig('surfbar_restart_time'))),
115                                 'autostart' => (getConfig('surfbar_autostart') == "Y") ? "true" : "false"
116                         );
117
118                         // Load template for stopped surfbar
119                         LOAD_TEMPLATE("surfbar_stopped", false, $content);
120                 }
121         } elseif ((REQUEST_ISSET_GET(('check'))) && (REQUEST_ISSET_GET(('id'))) && (REQUEST_ISSET_GET(('salt')))) {
122                 // Dummy next id get
123                 SURFBAR_DETERMINE_NEXT_ID(REQUEST_GET('id'));
124
125                 // Check reload lock and validation code
126                 if ((!SURFBAR_CHECK_RELOAD_LOCK(REQUEST_GET('id'))) && (SURFBAR_CHECK_VALIDATION_CODE(REQUEST_GET('id'), REQUEST_GET('check'), REQUEST_GET('salt')))) {
127                         // Lock the URL (id) down
128                         SURFBAR_LOCKDOWN_ID(REQUEST_GET('id'));
129
130                         // Code is valid so pay points here
131                         SURFBAR_PAY_POINTS();
132
133                         // Check if reload is full
134                         if (SURFBAR_CHECK_RELOAD_FULL()) {
135                                 // Then load waiting page
136                                 SURFBAR_RELOAD_TO_STOP_PAGE();
137                         } // END - if
138                 } else {
139                         // Reload to stop frame!
140                         SURFBAR_RELOAD_TO_STOP_PAGE();
141                 }
142
143                 // All done, so fix notice for footer.php
144                 $GLOBALS['footer_sent'] = 1;
145         } else {
146                 // Prepare content
147                 $content = "";
148
149                 // Determine template name
150                 $templateName = SURFBAR_DETERMINE_TEMPLATE_NAME();
151
152                 // Frame "top" set?
153                 if ((REQUEST_ISSET_GET(('frame'))) && (REQUEST_GET('frame') == "top")) {
154                         // Determine next id
155                         $nextId = SURFBAR_DETERMINE_NEXT_ID();
156
157                         // Is there a valid id?
158                         if ($nextId > 0) {
159                                 // Then prepare other content
160                                 $content = array(
161                                         'id'          => $nextId,
162                                         'check'       => SURFBAR_GENERATE_VALIDATION_CODE($nextId),
163                                         'salt'        => SURFBAR_GET_SALT(),
164                                         'reward'      => TRANSLATE_COMMA(SURFBAR_GET_REWARD($nextId)),
165                                         'url'         => SURFBAR_GET_URL($nextId),
166                                         'curr_reload' => SURFBAR_GET_USER_LOCKS(),
167                                         'max_urls'    => SURFBAR_GET_TOTAL_URLS(),
168                                         'reload'      => SURFBAR_GET_RELOAD_TIME($nextId),
169                                         'xxx'         => str_repeat("X", strlen(SURFBAR_GET_RELOAD_TIME($nextId)))
170                                 );
171
172                                 // Update salt (double-call lock!) and statistics
173                                 SURFBAR_UPDATE_SALT_STATS();
174                         } else {
175                                 // Load new URL
176                                 SURFBAR_RELOAD_TO_STOP_PAGE("stop2");
177                         }
178                 } elseif ((REQUEST_ISSET_GET(('frame'))) && (REQUEST_GET('frame') == "start")) {
179                         // Starter frame found so let the footer display
180                         REQUEST_UNSET_GET(('frame'));
181                 } else {
182                         // Load header in frameset mode
183                         $isFrameset = true;
184                 }
185
186                 // Load header
187                 LOAD_INC_ONCE("inc/header.php");
188
189                 // Load that template
190                 //* DEBUG: */ die("templateName={$templateName}<br />\n<strong>content</strong>=<pre>".print_r($content, true)."</pre>");
191                 LOAD_TEMPLATE($templateName, false, $content);
192         }
193
194         // Load footer
195         LOAD_INC_ONCE("inc/footer.php");
196 } else {
197         // You have to install first!
198         LOAD_URL("install.php");
199 }
200
201 // Really all done here... ;-)
202 ?>