All database names are now 'back-ticked' and constant _MYSQL_PREFIX is wrapped. Partl...
[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_once("inc/libs/security_functions.php");
36
37 // Init "action" and "what"
38 global $what, $action, $startTime, $SURFBAR_CACHE;
39 $SURFBAR_CACHE = array();
40 $GLOBALS['startTime'] = microtime(true);
41 $GLOBALS['what'] = ""; $GLOBALS['action'] = "";
42
43 // Set module
44 $GLOBALS['module'] = "surfbar";
45 $GLOBALS['refid']  = 0;
46 $CSS = 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         if (!EXT_IS_ACTIVE("surfbar")) {
56                 // Surfbar deactivated
57                 LOAD_URL("modules.php?module=login&amp;msg=".CODE_EXTENSION_PROBLEM."&amp;ext=surfbar");
58         } elseif (!IS_MEMBER()) {
59                 // Redirect
60                 LOAD_URL("modules.php?module=index");
61         }
62
63         // Handle tasks on self-maintenance
64         SURFBAR_HANDLE_SELF_MAINTENANCE();
65
66         // Is there a check value?
67         if ((SURFBAR_CHECK_RELOAD_FULL()) || ((isset($_GET['frame'])) && (in_array($_GET['frame'], array("stop", "stop2", "stats", "textlinks"))))) {
68                 // Reload-lock is full, surfbar stopped so...
69                 // Load header
70                 require_once(PATH."inc/header.php");
71
72                 // Load template
73                 if (((isset($_GET['frame'])) && ($_GET['frame'] == "stop")) || (!isset($_GET['frame']))) {
74                         // Load template for "start" page
75                         LOAD_TEMPLATE("surfbar_frame_start");
76
77                         // Load banner
78                         LOAD_TEMPLATE("surfbar_start_banner");
79
80                         // This makes the footer appear again
81                         unset($_GET['frame']);
82                 } elseif ((isset($_GET['frame'])) && ($_GET['frame'] == "stats")) {
83                         // Get total points amount
84                         $points = GET_TOTAL_DATA($GLOBALS['userid'], "user_points", "points") - GET_TOTAL_DATA($GLOBALS['userid'], "user_data", "used_points");
85
86                         // Prepare content
87                         $content = array(
88                                 'points'   => TRANSLATE_COMMA($points),
89                                 'online'   => SURFBAR_DETERMINE_TOTAL_ONLINE(),
90                                 'reload'   => (getConfig('surfbar_stats_reload') * 1000),
91                                 'c_total'  => TRANSLATE_COMMA(getConfig('surfbar_total_counter')),
92                                 'c_today'  => TRANSLATE_COMMA(getConfig('surfbar_daily_counter')),
93                                 'c_yester' => TRANSLATE_COMMA(getConfig('surfbar_yester_counter')),
94                                 'c_week'   => TRANSLATE_COMMA(getConfig('surfbar_weekly_counter')),
95                                 'c_month'  => TRANSLATE_COMMA(getConfig('surfbar_monthly_counter')),
96                         );
97
98                         // Load template for "stats" page
99                         LOAD_TEMPLATE("surfbar_frame_stats", false, $content);
100                 } elseif ((isset($_GET['frame'])) && ($_GET['frame'] == "textlinks")) {
101                         // Prepare content
102                         $content = array(
103                                 'online'   => SURFBAR_DETERMINE_TOTAL_ONLINE(),
104                                 'reload'   => (getConfig('surfbar_stats_reload') * 1000)
105                         );
106
107                         // Load template for "stats" page
108                         LOAD_TEMPLATE("surfbar_frame_textlinks", false, $content);
109                 } else {
110                         // Prepare content
111                         $content = array(
112                                 'restart'   => getConfig('surfbar_restart_time'),
113                                 'start'     => str_repeat("X", strlen(getConfig('surfbar_restart_time'))),
114                                 'autostart' => (getConfig('surfbar_autostart') == "Y") ? "true" : "false"
115                         );
116
117                         // Load template for stopped surfbar
118                         LOAD_TEMPLATE("surfbar_stopped", false, $content);
119                 }
120         } elseif ((isset($_GET['check'])) && (isset($_GET['id'])) && (isset($_GET['salt']))) {
121                 // Dummy next id get
122                 SURFBAR_DETERMINE_NEXT_ID($_GET['id']);
123
124                 // Check reload lock and validation code
125                 if ((!SURFBAR_CHECK_RELOAD_LOCK($_GET['id'])) && (SURFBAR_CHECK_VALIDATION_CODE($_GET['id'], $_GET['check'], $_GET['salt']))) {
126                         // Lock the URL (id) down
127                         SURFBAR_LOCKDOWN_ID($_GET['id']);
128
129                         // Code is valid so pay points here
130                         SURFBAR_PAY_POINTS();
131
132                         // Check if reload is full
133                         if (SURFBAR_CHECK_RELOAD_FULL()) {
134                                 // Then load waiting page
135                                 SURFBAR_RELOAD_TO_STOP_PAGE();
136                         } // END - if
137                 } else {
138                         // Reload to stop frame!
139                         SURFBAR_RELOAD_TO_STOP_PAGE();
140                 }
141
142                 // All done, so fix notice for footer.php
143                 $footer = 1;
144         } else {
145                 // Prepare content
146                 $content = "";
147
148                 // Determine template name
149                 $templateName = SURFBAR_DETERMINE_TEMPLATE_NAME();
150
151                 // Frame "top" set?
152                 if ((isset($_GET['frame'])) && ($_GET['frame'] == "top")) {
153                         // Determine next id
154                         $nextId = SURFBAR_DETERMINE_NEXT_ID();
155
156                         // Is there a valid id?
157                         if ($nextId > 0) {
158                                 // Then prepare other content
159                                 $content = array(
160                                         'id'          => $nextId,
161                                         'check'       => SURFBAR_GENERATE_VALIDATION_CODE($nextId),
162                                         'salt'        => SURFBAR_GET_SALT(),
163                                         'reward'      => TRANSLATE_COMMA(SURFBAR_GET_REWARD($nextId)),
164                                         'url'         => SURFBAR_GET_URL($nextId),
165                                         'curr_reload' => SURFBAR_GET_USER_LOCKS(),
166                                         'max_urls'    => SURFBAR_GET_TOTAL_URLS(),
167                                         'reload'      => SURFBAR_GET_RELOAD_TIME($nextId),
168                                         'xxx'         => str_repeat("X", strlen(SURFBAR_GET_RELOAD_TIME($nextId)))
169                                 );
170
171                                 // Update salt (double-call lock!) and statistics
172                                 SURFBAR_UPDATE_SALT_STATS();
173                         } else {
174                                 // Load new URL
175                                 SURFBAR_RELOAD_TO_STOP_PAGE("stop2");
176                         }
177                 } elseif ((isset($_GET['frame'])) && ($_GET['frame'] == "start")) {
178                         // Starter frame found so let the footer display
179                         unset($_GET['frame']);
180                 } else {
181                         // Load header in frameset mode
182                         $isFrameset = true;
183                 }
184
185                 // Load header
186                 require_once(PATH."inc/header.php");
187
188                 // Load that template
189                 //* DEBUG: */ die("templateName={$templateName}<br />\n<strong>content</strong>=<pre>".print_r($content, true)."</pre>");
190                 LOAD_TEMPLATE($templateName, false, $content);
191         }
192
193         // Load footer
194         require_once(PATH."inc/footer.php");
195 } else {
196         // You have to install first!
197         LOAD_URL("install.php");
198 }
199
200 // Really all done here... ;-)
201 ?>