Changeset 22 for trunk/lib/App.inc.php


Ignore:
Timestamp:
Nov 23, 2005 9:29:33 PM (19 years ago)
Author:
scdev
Message:

More bugs and shifting things about.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/App.inc.php

    r21 r22  
    152152        }
    153153       
    154         if (!isset($_SESSION[$this->app])) {
    155             $_SESSION[$this->app] = array();
    156         }
    157 
    158154        // Initialize default parameters.
    159155        $this->_params = array_merge($this->_params, $this->_param_defaults);
     
    296292            session_name($this->getParam('session_name'));
    297293           
    298             // Start the session. Access session data using: $_SESSION['...']
     294            // Start the session.
    299295            session_start();
     296           
     297            if (!isset($_SESSION[$this->app])) {
     298                // Access session data using: $_SESSION['...'].
     299                // Initialize here _after_ session has started.
     300                $_SESSION[$this->app] = array(
     301                    'messages' => array(),
     302                    'boomerang' => array('url'),
     303                );
     304            }
    300305        }
    301306       
     
    374379       
    375380        if (!in_array($type, array(MSG_NOTICE, MSG_SUCCESS, MSG_WARNING, MSG_ERR))) {
    376             App::logMsg(sprintf('Invalid MSG_* type: %s', $type), LOG_DEBUG, __FILE__, __LINE__);
     381            $this->logMsg(sprintf('Invalid MSG_* type: %s', $type), LOG_DEBUG, __FILE__, __LINE__);
    377382        }
    378383    }
     
    752757        if (preg_match('!^/!', $url)) {
    753758            // If relative URL is given, prepend correct local hostname.
    754             $my_url = parse_url($_SERVER['SCRIPT_URI']);
    755             $url = sprintf('%s://%s%s', $my_url['scheme'], $my_url['host'], $url);
    756         }
    757    
     759            $scheme = 'on' == getenv('HTTPS') ? 'https' : 'http';
     760            $host = getenv('HTTP_HOST');
     761            $url = sprintf('%s://%s%s', $scheme, $host, $url);
     762        }
     763
    758764        $url = $this->oHREF($url, $carry_args, $always_include_sid);
    759765       
     
    787793            if (isset($id) && isset($_SESSION[$this->app]['boomerang']['url'][$id])) {
    788794                $url = $_SESSION[$this->app]['boomerang']['url'][$id];
     795                $this->logMsg(sprintf('dieBoomerangURL(%s) found: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    789796            } else {
    790797                $url = end($_SESSION[$this->app]['boomerang']['url']);
    791             }
    792         } else if (!refererIsMe() && !preg_match('/admin_common/', getenv('SCRIPT_NAME'))) {
     798                $this->logMsg(sprintf('dieBoomerangURL(%s) using: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
     799            }
     800            // Delete stored boomerang.
     801            $this->deleteBoomerangURL($id);
     802        } else if (!refererIsMe()) {
    793803            // Ensure that the redirecting page is not also the referrer.
    794             // admin_common is an alias of 'admin', which confuses this function. Just here for local testing.
    795804            $url = getenv('HTTP_REFERER');
     805            $this->logMsg(sprintf('dieBoomerangURL(%s) using referrer: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    796806        } else {
    797             $url = '';
    798         }
    799    
    800         $this->logMsg(sprintf('dieBoomerangURL: %s', $url), LOG_DEBUG, __FILE__, __LINE__);
    801    
    802         // Delete stored boomerang.
    803         $this->deleteBoomerangURL($id);
     807            // If URL is not specified, use the redirect_home_url.
     808            $url = $this->getParam('redirect_home_url');
     809            $this->logMsg(sprintf('dieBoomerangURL(%s) not found, using redirect_home_url: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
     810        }
     811   
    804812           
    805813        // A redirection will never happen immediatly twice.
     
    825833            return false;
    826834        }
    827        
    828835        // A redirection will never happen immediatly after setting the boomerangURL.
    829836        // Set the time so ensure this doesn't happen. See App::validBoomerangURL for more.
    830837   
    831         if (isset($url) && is_string($url)) {
     838        if ('' != $url && is_string($url)) {
    832839            // Delete any boomerang request keys in the query string.
    833840            $url = preg_replace('/boomerang=[\w]+/', '', $url);
    834841           
    835             if (is_array($_SESSION[$this->app]['boomerang']['url']) && !empty($_SESSION[$this->app]['boomerang']['url'])) {
     842            if (isset($_SESSION[$this->app]['boomerang']['url']) && is_array($_SESSION[$this->app]['boomerang']['url']) && !empty($_SESSION[$this->app]['boomerang']['url'])) {
    836843                // If the URL currently exists in the boomerang array, delete.
    837844                while ($existing_key = array_search($url, $_SESSION[$this->app]['boomerang']['url'])) {
     
    845852                $_SESSION[$this->app]['boomerang']['url'][] = $url;
    846853            }
    847             $this->logMsg(sprintf('setBoomerangURL: %s', $url), LOG_DEBUG, __FILE__, __LINE__);
     854            $this->logMsg(sprintf('setBoomerangURL(%s): %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    848855            return true;
    849856        } else {
     857            $this->logMsg(sprintf('setBoomerangURL(%s) is empty!', $id, $url), LOG_NOTICE, __FILE__, __LINE__);
    850858            return false;
    851859        }
     
    895903        }
    896904       
     905        $this->logMsg(sprintf('deleteBoomerangURL(%s): %s', $id, $this->getBoomerangURL($id)), LOG_DEBUG, __FILE__, __LINE__);
     906
    897907        if (isset($id) && isset($_SESSION[$this->app]['boomerang']['url'][$id])) {
    898908            unset($_SESSION[$this->app]['boomerang']['url'][$id]);
     
    927937        $boomerang_time = isset($_SESSION[$this->app]['boomerang']['time']) ? $_SESSION[$this->app]['boomerang']['time'] : 0;
    928938       
     939        $url = '';
    929940        if (isset($id) && isset($_SESSION[$this->app]['boomerang']['url'][$id])) {
    930941            $url = $_SESSION[$this->app]['boomerang']['url'][$id];
     
    934945        }
    935946   
    936         $this->logMsg(sprintf('validBoomerangURL testing url: %s', $url), LOG_DEBUG, __FILE__, __LINE__);
    937         if (empty($url)) {
     947        $this->logMsg(sprintf('validBoomerangURL(%s) testing: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
     948
     949        if ('' == $url) {
     950            $this->logMsg(sprintf('validBoomerangURL(%s) not valid, empty!', $id), LOG_NOTICE, __FILE__, __LINE__);
    938951            return false;
    939952        }
    940953        if ($url == absoluteMe()) {
    941954            // The URL we are directing to is the current page.
    942             $this->logMsg(sprintf('Boomerang URL not valid, same as absoluteMe: %s', $url), LOG_WARNING, __FILE__, __LINE__);
     955            $this->logMsg(sprintf('validBoomerangURL(%s) not valid, same as absoluteMe: %s', $id, $url), LOG_NOTICE, __FILE__, __LINE__);
    943956            return false;
    944957        }
    945958        if ($boomerang_time >= (time() - 2)) {
    946959            // Last boomerang direction was more than 2 seconds ago.
    947             $this->logMsg(sprintf('Boomerang URL not valid, boomerang_time too short: %s', time() - $boomerang_time), LOG_WARNING, __FILE__, __LINE__);
    948             return false;
    949         }
    950        
    951         $this->logMsg(sprintf('validBoomerangURL found: %s', $url), LOG_DEBUG, __FILE__, __LINE__);
     960            $this->logMsg(sprintf('validBoomerangURL(%s) not valid, boomerang_time too short: %s', $id, time() - $boomerang_time), LOG_NOTICE, __FILE__, __LINE__);
     961            return false;
     962        }
     963       
     964        $this->logMsg(sprintf('validBoomerangURL(%s) is valid: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    952965        return true;
    953966    }
Note: See TracChangeset for help on using the changeset viewer.