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