Added more wrapper, commented out another noisy debug line
[mailer.git] / surfbar.php
index 5adb2f674e61a21edcc48d880a8cb96aaea72631..9fce26b80c2c3247ac7ddd3d13625f3f195cae91 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 09/05/2008 *
- * ===============                              Last change: 09/05/2008 *
+ * Mailer v0.2.1-FINAL                                Start: 09/05/2008 *
+ * ===================                          Last change: 09/05/2008 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : surfbar.php                                      *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Die Surfbar selbst                               *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
  * MA  02110-1301  USA                                                  *
  ************************************************************************/
 
-// Load security stuff here (Oh, I hope this is not unsecure? Am I paranoia??? ;-) )
-require("inc/libs/security_functions.php");
+// Load security stuff here
+require('inc/libs/security_functions.php');
 
-// Init "action" and "what"
-global $what, $action, $startTime, $SURFBAR_CACHE;
-$SURFBAR_CACHE = array();
-$GLOBALS['startTime'] = microtime(true);
-$GLOBALS['what'] = ""; $GLOBALS['action'] = "";
+// Init start time
+$GLOBALS['__start_time'] = microtime(true);
 
-// Set module
-$GLOBALS['module'] = "surfbar";
-$GLOBALS['refid']  = 0;
-$CSS = 0;
-$msg = null;
+// Set module output mode
+$GLOBALS['__module']      = 'surfbar';
+$GLOBALS['__output_mode'] = '0';
+$GLOBALS['__header_sent'] = 3;
 
 // Load the required file(s)
-require("inc/config.php");
-
-// Is the script installed?
-if (isBooleanConstantAndTrue('mxchange_installed')) {
-       // Only logged in users may use this surfbar!
-       if (!EXT_IS_ACTIVE("surfbar")) {
-               // Surfbar deactivated
-               LOAD_URL("modules.php?module=login&amp;msg=".constant('CODE_EXTENSION_PROBLEM')."&amp;ext=surfbar");
-       } elseif (!IS_MEMBER()) {
+require('inc/config-global.php');
+
+// Set content type
+setContentType('text/html');
+
+// Is a frame active?
+if (!isFullPage()) {
+       // Then we need to set header_sent to 0
+       $GLOBALS['__header_sent'] = '0';
+} // END - if
+
+// Only logged in users may use this surfbar!
+redirectOnUninstalledExtension('surfbar');
+
+// No member?
+if (!isMember()) {
+       // Should we display login window or redirect to main page?
+       if ((isSurfbarGuestLoginFormEnabled()) && (isExtensionActive('user'))) {
+               // Is the form sent?
+               if ((isFormSent('login')) && (isPostRequestElementSet('id')) && (isPostRequestElementSet('password'))) {
+                       // Do the login procedure
+                       $url = doUserLogin(postRequestElement('id'), postRequestElement('password'), basename(__FILE__), basename(__FILE__) . '?code=');
+
+                       // And redirect to the URL
+                       redirectToUrl($url);
+               } else {
+                       // Load header
+                       loadIncludeOnce('inc/header.php');
+
+                       // Is there a 'code' provided?
+                       if (isGetRequestElementSet('code')) {
+                               // Then generate an error message
+                               displayMessage(getMessageFromErrorCode(getRequestElement('code')));
+                       } // END - if
+
+                       // Display login form
+                       loadTemplate('surfbar_login_form');
+
+                       // Allow footer here
+                       $GLOBALS['__header_sent'] = 2;
+
+                       // Load footer
+                       loadIncludeOnce('inc/footer.php');
+               }
+       } else {
                // Redirect
-               LOAD_URL("modules.php?module=index");
+               redirectToUrl('modules.php?module=index');
        }
+} // END - if
 
-       // Handle tasks on self-maintenance
-       SURFBAR_HANDLE_SELF_MAINTENANCE();
+// Initialize the surfbar
+initSurfbar();
 
-       // Is there a check value?
-       if ((SURFBAR_CHECK_RELOAD_FULL()) || ((isset($_GET['frame'])) && (in_array($_GET['frame'], array("stop", "stop2", "stats", "textlinks"))))) {
-               // Reload-lock is full, surfbar stopped so...
-               // Load header
-               LOAD_INC_ONCE("inc/header.php");
+// Handle tasks on self-maintenance
+doSurfbarSelfMaintenance();
 
-               // Load template
-               if (((isset($_GET['frame'])) && ($_GET['frame'] == "stop")) || (!isset($_GET['frame']))) {
-                       // Load template for "start" page
-                       LOAD_TEMPLATE("surfbar_frame_start");
+// Is there a check value?
+if ((isSurfbarReloadFull()) || ((!isFullPage()) && (in_array(getRequestElement('frame'), array('stop', 'stop2', 'stats', 'textlinks'))))) {
+       // Reload-lock is full, surfbar stopped so...
+       // Load header
+       loadIncludeOnce('inc/header.php');
 
-                       // Load banner
-                       LOAD_TEMPLATE("surfbar_start_banner");
+       // Load template
+       if (((!isFullPage()) && (getRequestElement('frame') == 'stop2')) || (isFullPage())) {
+               // Load template for "start" page
+               loadTemplate('surfbar_frame_start');
 
-                       // This makes the footer appear again
-                       unset($_GET['frame']);
-               } elseif ((isset($_GET['frame'])) && ($_GET['frame'] == "stats")) {
-                       // Get total points amount
-                       $points = GET_TOTAL_DATA($GLOBALS['userid'], "user_points", "points") - GET_TOTAL_DATA($GLOBALS['userid'], "user_data", "used_points");
+               // Load banner
+               loadTemplate('surfbar_start_banner');
 
-                       // Prepare content
-                       $content = array(
-                               'points'   => TRANSLATE_COMMA($points),
-                               'online'   => SURFBAR_DETERMINE_TOTAL_ONLINE(),
-                               'reload'   => (getConfig('surfbar_stats_reload') * 1000),
-                               'c_total'  => TRANSLATE_COMMA(getConfig('surfbar_total_counter')),
-                               'c_today'  => TRANSLATE_COMMA(getConfig('surfbar_daily_counter')),
-                               'c_yester' => TRANSLATE_COMMA(getConfig('surfbar_yester_counter')),
-                               'c_week'   => TRANSLATE_COMMA(getConfig('surfbar_weekly_counter')),
-                               'c_month'  => TRANSLATE_COMMA(getConfig('surfbar_monthly_counter')),
-                       );
+               // This makes the footer appear again
+               unsetGetRequestElement('frame');
+       } elseif ((!isFullPage()) && (getRequestElement('frame') == 'stats')) {
+               // Prepare content
+               $content = array(
+                       'points' => getTotalPoints(getMemberId()),
+                       'reload' => (getSurfbarStatsReload() * 1000)
+               );
+
+               // Load template for "stats" page
+               loadTemplate('surfbar_frame_stats', false, $content);
+       } elseif ((!isFullPage()) && (getRequestElement('frame') == 'textlinks')) {
+               // Prepare content
+               $content = array(
+                       'reload' => (getSurfbarStatsReload() * 1000)
+               );
 
-                       // Load template for "stats" page
-                       LOAD_TEMPLATE("surfbar_frame_stats", false, $content);
-               } elseif ((isset($_GET['frame'])) && ($_GET['frame'] == "textlinks")) {
-                       // Prepare content
-                       $content = array(
-                               'online'   => SURFBAR_DETERMINE_TOTAL_ONLINE(),
-                               'reload'   => (getConfig('surfbar_stats_reload') * 1000)
-                       );
+               // Load template for "stats" page
+               loadTemplate('surfbar_frame_textlinks', false, $content);
+       } else {
+               // Prepare content
+               $content = array(
+                       'start'     => str_repeat('X', strlen(getSurfbarRestartTime())),
+                       'autostart' => (isSurfbarAutoStartEnbaled()) ? 'true' : 'false'
+               );
 
-                       // Load template for "stats" page
-                       LOAD_TEMPLATE("surfbar_frame_textlinks", false, $content);
-               } else {
-                       // Prepare content
+               // Load template for stopped surfbar
+               loadTemplate('surfbar_stopped', false, $content);
+       }
+} elseif ((isGetRequestElementSet('check')) && (isGetRequestElementSet('id')) && (isGetRequestElementSet('salt'))) {
+       // Dummy next id get
+       determineSurfbarNextId(getRequestElement('id'));
+
+       // Check reload lock and validation code
+       if ((!ifSurfbarReloadLock(getRequestElement('id'))) && (isSurfbarValidationCodeValid(getRequestElement('id'), getRequestElement('check'), getRequestElement('salt')))) {
+               // Lock the URL (id) down
+               addSurfbarReloadLockById(getRequestElement('id'));
+
+               // Code is valid so pay points here
+               doSurfbarPayPoints();
+
+               // Check if reload is full
+               if (isSurfbarReloadFull()) {
+                       // Then load waiting page
+                       redirectToSurfbarStopPage();
+               } // END - if
+
+               // Load header to avoid a bug
+               loadIncludeOnce('inc/header.php');
+       } else {
+               // Reload to stop frame!
+               redirectToSurfbarStopPage();
+       }
+
+       // All done, so fix notice for footer.php
+       $GLOBALS['__footer_sent'] = 1;
+} else {
+       // Prepare content
+       $content = '';
+
+       // Frame "top" set?
+       if ((!isFullPage()) && (getRequestElement('frame') == 'top')) {
+               // Determine next id
+               $nextId = determineSurfbarNextId();
+               //* DEBUG: */ exit('nextId='.$nextId);
+
+               // Is there a valid id?
+               if ($nextId > 0) {
+                       // Then prepare other content
                        $content = array(
-                               'restart'   => getConfig('surfbar_restart_time'),
-                               'start'     => str_repeat("X", strlen(getConfig('surfbar_restart_time'))),
-                               'autostart' => (getConfig('surfbar_autostart') == "Y") ? "true" : "false"
+                               'url_id' => $nextId,
+                               'xxx'    => str_repeat('X', strlen(gerSurfbarReloadTime($nextId))),
                        );
 
-                       // Load template for stopped surfbar
-                       LOAD_TEMPLATE("surfbar_stopped", false, $content);
-               }
-       } elseif ((isset($_GET['check'])) && (isset($_GET['id'])) && (isset($_GET['salt']))) {
-               // Dummy next id get
-               SURFBAR_DETERMINE_NEXT_ID($_GET['id']);
-
-               // Check reload lock and validation code
-               if ((!SURFBAR_CHECK_RELOAD_LOCK($_GET['id'])) && (SURFBAR_CHECK_VALIDATION_CODE($_GET['id'], $_GET['check'], $_GET['salt']))) {
-                       // Lock the URL (id) down
-                       SURFBAR_LOCKDOWN_ID($_GET['id']);
-
-                       // Code is valid so pay points here
-                       SURFBAR_PAY_POINTS();
-
-                       // Check if reload is full
-                       if (SURFBAR_CHECK_RELOAD_FULL()) {
-                               // Then load waiting page
-                               SURFBAR_RELOAD_TO_STOP_PAGE();
-                       } // END - if
+                       // Update salt (double-call lock!) and statistics
+                       updateSurfbarSaltStatistics();
                } else {
-                       // Reload to stop frame!
-                       SURFBAR_RELOAD_TO_STOP_PAGE();
-               }
-
-               // All done, so fix notice for footer.php
-               $footer = 1;
-       } else {
-               // Prepare content
-               $content = "";
-
-               // Determine template name
-               $templateName = SURFBAR_DETERMINE_TEMPLATE_NAME();
-
-               // Frame "top" set?
-               if ((isset($_GET['frame'])) && ($_GET['frame'] == "top")) {
-                       // Determine next id
-                       $nextId = SURFBAR_DETERMINE_NEXT_ID();
-
-                       // Is there a valid id?
-                       if ($nextId > 0) {
-                               // Then prepare other content
-                               $content = array(
-                                       'id'          => $nextId,
-                                       'check'       => SURFBAR_GENERATE_VALIDATION_CODE($nextId),
-                                       'salt'        => SURFBAR_GET_SALT(),
-                                       'reward'      => TRANSLATE_COMMA(SURFBAR_GET_REWARD($nextId)),
-                                       'url'         => SURFBAR_GET_URL($nextId),
-                                       'curr_reload' => SURFBAR_GET_USER_LOCKS(),
-                                       'max_urls'    => SURFBAR_GET_TOTAL_URLS(),
-                                       'reload'      => SURFBAR_GET_RELOAD_TIME($nextId),
-                                       'xxx'         => str_repeat("X", strlen(SURFBAR_GET_RELOAD_TIME($nextId)))
-                               );
-
-                               // Update salt (double-call lock!) and statistics
-                               SURFBAR_UPDATE_SALT_STATS();
-                       } else {
-                               // Load new URL
-                               SURFBAR_RELOAD_TO_STOP_PAGE("stop2");
-                       }
-               } elseif ((isset($_GET['frame'])) && ($_GET['frame'] == "start")) {
-                       // Starter frame found so let the footer display
-                       unset($_GET['frame']);
-               } else {
-                       // Load header in frameset mode
-                       $isFrameset = true;
+                       // Load new URL
+                       redirectToSurfbarStopPage('stop');
                }
+       } elseif ((!isFullPage()) && (getRequestElement('frame') == 'start')) {
+               // Starter frame found so let the footer display
+               unsetGetRequestElement('frame');
+       }
 
-               // Load header
-               LOAD_INC_ONCE("inc/header.php");
+       // Load header
+       loadIncludeOnce('inc/header.php');
 
-               // Load that template
-               //* DEBUG: */ die("templateName={$templateName}<br />\n<strong>content</strong>=<pre>".print_r($content, true)."</pre>");
-               LOAD_TEMPLATE($templateName, false, $content);
-       }
+       // Determine template name
+       $templateName = determineSurfbarTemplateName();
 
-       // Load footer
-       LOAD_INC_ONCE("inc/footer.php");
-} else {
-       // You have to install first!
-       LOAD_URL("install.php");
+       // Load that template
+       //* DEBUG: */ exit('templateName=' . $templateName . '<br /><strong>content</strong>=<pre>' . print_r($content, true) . '</pre>');
+       loadTemplate($templateName, false, $content);
 }
 
-// Really all done here... ;-)
+// Load footer
+$GLOBALS['__footer_sent'] = 3;
+loadIncludeOnce('inc/footer.php');
+
+// [EOF]
 ?>