Index: branches/2.0/lib/App.inc.php
===================================================================
--- branches/2.0/lib/App.inc.php	(revision 156)
+++ branches/2.0/lib/App.inc.php	(revision 157)
@@ -164,11 +164,9 @@
     function setParam($param=null)
     {
-        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
-            $this =& App::getInstance();
-        }
+        $_this =& App::getInstance();
 
         if (isset($param) && is_array($param)) {
             // Merge new parameters with old overriding only those passed.
-            $this->_params = array_merge($this->_params, $param);
+            $_this->_params = array_merge($_this->_params, $param);
         }
     }
@@ -183,12 +181,10 @@
     function &getParam($param=null)
     {
-        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
-            $this =& App::getInstance();
-        }
+        $_this =& App::getInstance();
 
         if ($param === null) {
-            return $this->_params;
-        } else if (isset($this->_params[$param])) {
-            return $this->_params[$param];
+            return $_this->_params;
+        } else if (isset($_this->_params[$param])) {
+            return $_this->_params[$param];
         } else {
             trigger_error(sprintf('Parameter is not set: %s', $param), E_USER_NOTICE);
@@ -360,12 +356,10 @@
     function raiseMsg($message, $type=MSG_NOTICE, $file=null, $line=null)
     {
-        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
-            $this =& App::getInstance();
-        }
+        $_this =& App::getInstance();
 
         $message = trim($message);
 
-        if (!$this->running || '' == $message) {
-            $this->logMsg(sprintf('Canceled method call %s, application not running or message is an empty string.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+        if (!$_this->running || '' == $message) {
+            $_this->logMsg(sprintf('Canceled method call %s, application not running or message is an empty string.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
             return false;
         }
@@ -373,14 +367,14 @@
         // Save message in session under unique key to avoid duplicate messages.
         $msg_id = md5($type . $message . $file . $line);
-        $_SESSION[$this->app]['messages'][$msg_id] = array(
+        $_SESSION[$_this->app]['messages'][$msg_id] = array(
             'type'    => $type,
             'message' => $message,
             'file'    => $file,
             'line'    => $line,
-            'count'   => (isset($_SESSION[$this->app]['messages'][$msg_id]['count']) ? (1 + $_SESSION[$this->app]['messages'][$msg_id]['count']) : 1)
+            'count'   => (isset($_SESSION[$_this->app]['messages'][$msg_id]['count']) ? (1 + $_SESSION[$_this->app]['messages'][$msg_id]['count']) : 1)
         );
 
         if (!in_array($type, array(MSG_NOTICE, MSG_SUCCESS, MSG_WARNING, MSG_ERR))) {
-            $this->logMsg(sprintf('Invalid MSG_* type: %s', $type), LOG_DEBUG, __FILE__, __LINE__);
+            $_this->logMsg(sprintf('Invalid MSG_* type: %s', $type), LOG_DEBUG, __FILE__, __LINE__);
         }
     }
@@ -396,15 +390,13 @@
     function getRaisedMessages()
     {
-        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
-            $this =& App::getInstance();
-        }
-
-        if (!$this->running) {
-            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+        $_this =& App::getInstance();
+
+        if (!$_this->running) {
+            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
             return false;
         }
         
         $output = array();
-        while (isset($_SESSION[$this->app]['messages']) && $message = array_shift($_SESSION[$this->app]['messages'])) {
+        while (isset($_SESSION[$_this->app]['messages']) && $message = array_shift($_SESSION[$_this->app]['messages'])) {
             $output[] = $message;
         }
@@ -421,14 +413,12 @@
     function clearRaisedMessages()
     {
-        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
-            $this =& App::getInstance();
-        }
-
-        if (!$this->running) {
-            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+        $_this =& App::getInstance();
+
+        if (!$_this->running) {
+            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
             return false;
         }
         
-        $_SESSION[$this->app]['messages'] = array();
+        $_SESSION[$_this->app]['messages'] = array();
     }
 
@@ -442,16 +432,14 @@
     function printRaisedMessages()
     {
-        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
-            $this =& App::getInstance();
-        }
-
-        if (!$this->running) {
-            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
-            return false;
-        }
-
-        while (isset($_SESSION[$this->app]['messages']) && $message = array_shift($_SESSION[$this->app]['messages'])) {
+        $_this =& App::getInstance();
+
+        if (!$_this->running) {
+            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+            return false;
+        }
+
+        while (isset($_SESSION[$_this->app]['messages']) && $message = array_shift($_SESSION[$_this->app]['messages'])) {
             ?><div class="sc-msg"><?php
-            if (error_reporting() > 0 && $this->getParam('display_errors')) {
+            if (error_reporting() > 0 && $_this->getParam('display_errors')) {
                 echo "\n<!-- [" . $message['file'] . ' : ' . $message['line'] . '] -->';
             }
@@ -501,19 +489,17 @@
         static $previous_events = array();
 
-        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
-            $this =& App::getInstance();
-        }
+        $_this =& App::getInstance();
 
         // If priority is not specified, assume the worst.
-        if (!$this->logPriorityToString($priority)) {
-            $this->logMsg(sprintf('Log priority %s not defined. (Message: %s)', $priority, $message), LOG_EMERG, $file, $line);
+        if (!$_this->logPriorityToString($priority)) {
+            $_this->logMsg(sprintf('Log priority %s not defined. (Message: %s)', $priority, $message), LOG_EMERG, $file, $line);
             $priority = LOG_EMERG;
         }
 
         // If log file is not specified, don't log to a file.
-        if (!$this->getParam('log_directory') || !$this->getParam('log_filename') || !is_dir($this->getParam('log_directory')) || !is_writable($this->getParam('log_directory'))) {
-            $this->setParam(array('log_file_priority' => false));
+        if (!$_this->getParam('log_directory') || !$_this->getParam('log_filename') || !is_dir($_this->getParam('log_directory')) || !is_writable($_this->getParam('log_directory'))) {
+            $_this->setParam(array('log_file_priority' => false));
             // We must use trigger_error to report this problem rather than calling App::logMsg, which might lead to an infinite loop.
-            trigger_error(sprintf('Codebase error: log directory (%s) not found or writable.', $this->getParam('log_directory')), E_USER_NOTICE);
+            trigger_error(sprintf('Codebase error: log directory (%s) not found or writable.', $_this->getParam('log_directory')), E_USER_NOTICE);
         }
 
@@ -531,5 +517,5 @@
             $previous_events[$msg_id]++;
             if ($previous_events[$msg_id] == 2) {
-                $this->logMsg(sprintf('%s (Event repeated %s or more times)', $message, $previous_events[$msg_id]), $priority, $file, $line);
+                $_this->logMsg(sprintf('%s (Event repeated %s or more times)', $message, $previous_events[$msg_id]), $priority, $file, $line);
             }
             return false;
@@ -543,5 +529,5 @@
             'remote ip' => getRemoteAddr(),
             'pid'       => (substr(PHP_OS, 0, 3) != 'WIN' ? posix_getpid() : ''),
-            'type'      => $this->logPriorityToString($priority),
+            'type'      => $_this->logPriorityToString($priority),
             'file:line' => "$file : $line",
             'url'       => (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''),
@@ -550,11 +536,11 @@
 
         // FILE ACTION
-        if ($this->getParam('log_file_priority') && $priority <= $this->getParam('log_file_priority')) {
+        if ($_this->getParam('log_file_priority') && $priority <= $_this->getParam('log_file_priority')) {
             $event_str = '[' . join('] [', $event) . ']';
-            error_log($event_str . "\n", 3, $this->getParam('log_directory') . '/' . $this->getParam('log_filename'));
+            error_log($event_str . "\n", 3, $_this->getParam('log_directory') . '/' . $_this->getParam('log_filename'));
         }
 
         // EMAIL ACTION
-        if ($this->getParam('log_email_priority') && $priority <= $this->getParam('log_email_priority')) {
+        if ($_this->getParam('log_email_priority') && $priority <= $_this->getParam('log_email_priority')) {
             $subject = sprintf('[%s %s] %s', getenv('HTTP_HOST'), $event['type'], $message);
             $email_msg = sprintf("A %s log event occured on %s\n\n", $event['type'], getenv('HTTP_HOST'));
@@ -563,17 +549,17 @@
                 $email_msg .= sprintf("%-11s%s\n", $k, $v);
             }
-            mail($this->getParam('log_to_email_address'), $subject, $email_msg, $headers, '-f codebase@strangecode.com');
+            mail($_this->getParam('log_to_email_address'), $subject, $email_msg, $headers, '-f codebase@strangecode.com');
         }
 
         // SMS ACTION
-        if ($this->getParam('log_sms_priority') && $priority <= $this->getParam('log_sms_priority')) {
+        if ($_this->getParam('log_sms_priority') && $priority <= $_this->getParam('log_sms_priority')) {
             $subject = sprintf('[%s %s]', getenv('HTTP_HOST'), $priority);
             $sms_msg = sprintf('%s [%s:%s]', $event['message'], basename($file), $line);
             $headers = "From: codebase@strangecode.com";
-            mail($this->getParam('log_to_sms_address'), $subject, $sms_msg, $headers, '-f codebase@strangecode.com');
+            mail($_this->getParam('log_to_sms_address'), $subject, $sms_msg, $headers, '-f codebase@strangecode.com');
         }
 
         // SCREEN ACTION
-        if ($this->getParam('log_screen_priority') && $priority <= $this->getParam('log_screen_priority')) {
+        if ($_this->getParam('log_screen_priority') && $priority <= $_this->getParam('log_screen_priority')) {
             echo "[{$event['date']}] [{$event['type']}] [{$event['file:line']}] [{$event['message']}]\n";
         }
@@ -620,12 +606,10 @@
     function carryQuery($query_key)
     {
-        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
-            $this =& App::getInstance();
-        }
+        $_this =& App::getInstance();
 
         // If not already set, and there is a non-empty value provided in the request...
-        if (!isset($this->_carry_queries[$query_key]) && getFormData($query_key, false)) {
+        if (!isset($_this->_carry_queries[$query_key]) && getFormData($query_key, false)) {
             // Copy the value of the specified query argument into the _carry_queries array.
-            $this->_carry_queries[$query_key] = getFormData($query_key);
+            $_this->_carry_queries[$query_key] = getFormData($query_key);
         }
     }
@@ -652,10 +636,8 @@
     function url($url, $carry_args=null, $always_include_sid=false)
     {
-        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
-            $this =& App::getInstance();
-        }
-
-        if (!$this->running) {
-            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+        $_this =& App::getInstance();
+
+        if (!$_this->running) {
+            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
             return false;
         }
@@ -691,5 +673,5 @@
         if ($do_carry_queries) {
             // Join the global _carry_queries and local one_time_carry_queries.
-            $query_args = urlEncodeArray(array_merge($this->_carry_queries, $one_time_carry_queries));
+            $query_args = urlEncodeArray(array_merge($_this->_carry_queries, $one_time_carry_queries));
             foreach ($query_args as $key=>$val) {
                 // Check value is set and value does not already exist in the url.
@@ -715,7 +697,7 @@
                     (
                         !isset($_COOKIE[session_name()])
-                        || !$this->getParam('session_use_cookies')
+                        || !$_this->getParam('session_use_cookies')
                     )
-                    && $this->getParam('enable_session')
+                    && $_this->getParam('enable_session')
                     && isMyDomain($url)
                     &&
@@ -748,9 +730,7 @@
     function oHREF($url, $carry_args=null, $always_include_sid=false)
     {
-        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
-            $this =& App::getInstance();
-        }
-
-        $url = $this->url($url, $carry_args, $always_include_sid);
+        $_this =& App::getInstance();
+
+        $url = $_this->url($url, $carry_args, $always_include_sid);
 
         // Replace any & not followed by an html or unicode entity with it's &amp; equivalent.
@@ -772,10 +752,8 @@
     function printHiddenSession($carry_args=null)
     {
-        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
-            $this =& App::getInstance();
-        }
-
-        if (!$this->running) {
-            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+        $_this =& App::getInstance();
+
+        if (!$_this->running) {
+            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
             return false;
         }
@@ -808,5 +786,5 @@
             // Join the global _carry_queries and local one_time_carry_queries.
             // urlencode is not used here, not for form data!
-            $query_args = array_merge($this->_carry_queries, $one_time_carry_queries);
+            $query_args = array_merge($_this->_carry_queries, $one_time_carry_queries);
             foreach ($query_args as $key=>$val) {
                 echo '<input type="hidden" name="' . $key . '" value="' . $val . '" />';
@@ -835,10 +813,8 @@
     function dieURL($url, $carry_args=null, $always_include_sid=false)
     {
-        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
-            $this =& App::getInstance();
-        }
-
-        if (!$this->running) {
-            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+        $_this =& App::getInstance();
+
+        if (!$_this->running) {
+            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
             return false;
         }
@@ -846,5 +822,5 @@
         if ('' == $url) {
             // If URL is not specified, use the redirect_home_url.
-            $url = $this->getParam('redirect_home_url');
+            $url = $_this->getParam('redirect_home_url');
         }
 
@@ -856,12 +832,12 @@
         }
 
-        $url = $this->url($url, $carry_args, $always_include_sid);
+        $url = $_this->url($url, $carry_args, $always_include_sid);
 
         header(sprintf('Location: %s', $url));
-        $this->logMsg(sprintf('dieURL: %s', $url), LOG_DEBUG, __FILE__, __LINE__);
+        $_this->logMsg(sprintf('dieURL: %s', $url), LOG_DEBUG, __FILE__, __LINE__);
 
         // End this application.
         // Recommended, although I'm not sure it's necessary: http://cn2.php.net/session_write_close
-        $this->stop();
+        $_this->stop();
         die;
     }
@@ -884,24 +860,22 @@
     function dieBoomerangURL($id=null, $carry_args=null, $default_url=null)
     {
-        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
-            $this =& App::getInstance();
-        }
-
-        if (!$this->running) {
-            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+        $_this =& App::getInstance();
+
+        if (!$_this->running) {
+            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
             return false;
         }
 
         // Get URL from stored boomerang. Allow non specific URL if ID not valid.
-        if ($this->validBoomerangURL($id, true)) {
-            if (isset($id) && isset($_SESSION[$this->app]['boomerang']['url'][$id])) {
-                $url = $_SESSION[$this->app]['boomerang']['url'][$id];
-                $this->logMsg(sprintf('dieBoomerangURL(%s) found: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
+        if ($_this->validBoomerangURL($id, true)) {
+            if (isset($id) && isset($_SESSION[$_this->app]['boomerang']['url'][$id])) {
+                $url = $_SESSION[$_this->app]['boomerang']['url'][$id];
+                $_this->logMsg(sprintf('dieBoomerangURL(%s) found: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
             } else {
-                $url = end($_SESSION[$this->app]['boomerang']['url']);
-                $this->logMsg(sprintf('dieBoomerangURL(%s) using: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
+                $url = end($_SESSION[$_this->app]['boomerang']['url']);
+                $_this->logMsg(sprintf('dieBoomerangURL(%s) using: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
             }
             // Delete stored boomerang.
-            $this->deleteBoomerangURL($id);
+            $_this->deleteBoomerangURL($id);
         } else if (isset($default_url)) {
             $url = $default_url;
@@ -909,15 +883,15 @@
             // Ensure that the redirecting page is not also the referrer.
             $url = getenv('HTTP_REFERER');
-            $this->logMsg(sprintf('dieBoomerangURL(%s) using referrer: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
+            $_this->logMsg(sprintf('dieBoomerangURL(%s) using referrer: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
         } else {
             // If URL is not specified, use the redirect_home_url.
-            $url = $this->getParam('redirect_home_url');
-            $this->logMsg(sprintf('dieBoomerangURL(%s) not found, using redirect_home_url: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
+            $url = $_this->getParam('redirect_home_url');
+            $_this->logMsg(sprintf('dieBoomerangURL(%s) not found, using redirect_home_url: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
         }
 
         // A redirection will never happen immediately twice.
         // Set the time so ensure this doesn't happen.
-        $_SESSION[$this->app]['boomerang']['time'] = time();
-        $this->dieURL($url, $carry_args);
+        $_SESSION[$_this->app]['boomerang']['time'] = time();
+        $_this->dieURL($url, $carry_args);
     }
 
@@ -931,10 +905,8 @@
     function setBoomerangURL($url=null, $id=null)
     {
-        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
-            $this =& App::getInstance();
-        }
-
-        if (!$this->running) {
-            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+        $_this =& App::getInstance();
+
+        if (!$_this->running) {
+            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
             return false;
         }
@@ -946,20 +918,20 @@
             $url = preg_replace('/boomerang=[\w]+/', '', $url);
 
-            if (isset($_SESSION[$this->app]['boomerang']['url']) && is_array($_SESSION[$this->app]['boomerang']['url']) && !empty($_SESSION[$this->app]['boomerang']['url'])) {
+            if (isset($_SESSION[$_this->app]['boomerang']['url']) && is_array($_SESSION[$_this->app]['boomerang']['url']) && !empty($_SESSION[$_this->app]['boomerang']['url'])) {
                 // If the URL currently exists in the boomerang array, delete.
-                while ($existing_key = array_search($url, $_SESSION[$this->app]['boomerang']['url'])) {
-                    unset($_SESSION[$this->app]['boomerang']['url'][$existing_key]);
+                while ($existing_key = array_search($url, $_SESSION[$_this->app]['boomerang']['url'])) {
+                    unset($_SESSION[$_this->app]['boomerang']['url'][$existing_key]);
                 }
             }
 
             if (isset($id)) {
-                $_SESSION[$this->app]['boomerang']['url'][$id] = $url;
+                $_SESSION[$_this->app]['boomerang']['url'][$id] = $url;
             } else {
-                $_SESSION[$this->app]['boomerang']['url'][] = $url;
-            }
-            $this->logMsg(sprintf('setBoomerangURL(%s): %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
+                $_SESSION[$_this->app]['boomerang']['url'][] = $url;
+            }
+            $_this->logMsg(sprintf('setBoomerangURL(%s): %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
             return true;
         } else {
-            $this->logMsg(sprintf('setBoomerangURL(%s) is empty!', $id, $url), LOG_NOTICE, __FILE__, __LINE__);
+            $_this->logMsg(sprintf('setBoomerangURL(%s) is empty!', $id, $url), LOG_NOTICE, __FILE__, __LINE__);
             return false;
         }
@@ -973,21 +945,19 @@
     function getBoomerangURL($id=null)
     {
-        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
-            $this =& App::getInstance();
-        }
-
-        if (!$this->running) {
-            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+        $_this =& App::getInstance();
+
+        if (!$_this->running) {
+            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
             return false;
         }
 
         if (isset($id)) {
-            if (isset($_SESSION[$this->app]['boomerang']['url'][$id])) {
-                return $_SESSION[$this->app]['boomerang']['url'][$id];
+            if (isset($_SESSION[$_this->app]['boomerang']['url'][$id])) {
+                return $_SESSION[$_this->app]['boomerang']['url'][$id];
             } else {
                 return '';
             }
-        } else if (is_array($_SESSION[$this->app]['boomerang']['url'])) {
-            return end($_SESSION[$this->app]['boomerang']['url']);
+        } else if (is_array($_SESSION[$_this->app]['boomerang']['url'])) {
+            return end($_SESSION[$_this->app]['boomerang']['url']);
         } else {
             return false;
@@ -1002,19 +972,17 @@
     function deleteBoomerangURL($id=null)
     {
-        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
-            $this =& App::getInstance();
-        }
-
-        if (!$this->running) {
-            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
-            return false;
-        }
-
-        $this->logMsg(sprintf('deleteBoomerangURL(%s): %s', $id, $this->getBoomerangURL($id)), LOG_DEBUG, __FILE__, __LINE__);
-
-        if (isset($id) && isset($_SESSION[$this->app]['boomerang']['url'][$id])) {
-            unset($_SESSION[$this->app]['boomerang']['url'][$id]);
-        } else if (is_array($_SESSION[$this->app]['boomerang']['url'])) {
-            array_pop($_SESSION[$this->app]['boomerang']['url']);
+        $_this =& App::getInstance();
+
+        if (!$_this->running) {
+            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+            return false;
+        }
+
+        $_this->logMsg(sprintf('deleteBoomerangURL(%s): %s', $id, $_this->getBoomerangURL($id)), LOG_DEBUG, __FILE__, __LINE__);
+
+        if (isset($id) && isset($_SESSION[$_this->app]['boomerang']['url'][$id])) {
+            unset($_SESSION[$_this->app]['boomerang']['url'][$id]);
+        } else if (is_array($_SESSION[$_this->app]['boomerang']['url'])) {
+            array_pop($_SESSION[$_this->app]['boomerang']['url']);
         }
     }
@@ -1028,15 +996,13 @@
     function validBoomerangURL($id=null, $use_nonspecificboomerang=false)
     {
-        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
-            $this =& App::getInstance();
-        }
-
-        if (!$this->running) {
-            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
-            return false;
-        }
-
-        if (!isset($_SESSION[$this->app]['boomerang']['url'])) {
-            $this->logMsg(sprintf('validBoomerangURL(%s) no boomerang URL set.', $id), LOG_DEBUG, __FILE__, __LINE__);
+        $_this =& App::getInstance();
+
+        if (!$_this->running) {
+            $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
+            return false;
+        }
+
+        if (!isset($_SESSION[$_this->app]['boomerang']['url'])) {
+            $_this->logMsg(sprintf('validBoomerangURL(%s) no boomerang URL set.', $id), LOG_DEBUG, __FILE__, __LINE__);
             return false;
         }
@@ -1045,32 +1011,32 @@
         // a boomerang redirection will always occur at least several seconds after the last boomerang redirect
         // or a boomerang being set.
-        $boomerang_time = isset($_SESSION[$this->app]['boomerang']['time']) ? $_SESSION[$this->app]['boomerang']['time'] : 0;
+        $boomerang_time = isset($_SESSION[$_this->app]['boomerang']['time']) ? $_SESSION[$_this->app]['boomerang']['time'] : 0;
 
         $url = '';
-        if (isset($id) && isset($_SESSION[$this->app]['boomerang']['url'][$id])) {
-            $url = $_SESSION[$this->app]['boomerang']['url'][$id];
+        if (isset($id) && isset($_SESSION[$_this->app]['boomerang']['url'][$id])) {
+            $url = $_SESSION[$_this->app]['boomerang']['url'][$id];
         } else if (!isset($id) || $use_nonspecificboomerang) {
             // Use non specific boomerang if available.
-            $url = end($_SESSION[$this->app]['boomerang']['url']);
-        }
-
-        $this->logMsg(sprintf('validBoomerangURL(%s) testing: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
+            $url = end($_SESSION[$_this->app]['boomerang']['url']);
+        }
+
+        $_this->logMsg(sprintf('validBoomerangURL(%s) testing: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
 
         if ('' == $url) {
-            $this->logMsg(sprintf('validBoomerangURL(%s) not valid, empty!', $id), LOG_DEBUG, __FILE__, __LINE__);
+            $_this->logMsg(sprintf('validBoomerangURL(%s) not valid, empty!', $id), LOG_DEBUG, __FILE__, __LINE__);
             return false;
         }
         if ($url == absoluteMe()) {
             // The URL we are directing to is the current page.
-            $this->logMsg(sprintf('validBoomerangURL(%s) not valid, same as absoluteMe: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
+            $_this->logMsg(sprintf('validBoomerangURL(%s) not valid, same as absoluteMe: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
             return false;
         }
         if ($boomerang_time >= (time() - 2)) {
             // Last boomerang direction was more than 2 seconds ago.
-            $this->logMsg(sprintf('validBoomerangURL(%s) not valid, boomerang_time too short: %s', $id, time() - $boomerang_time), LOG_DEBUG, __FILE__, __LINE__);
-            return false;
-        }
-
-        $this->logMsg(sprintf('validBoomerangURL(%s) is valid: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
+            $_this->logMsg(sprintf('validBoomerangURL(%s) not valid, boomerang_time too short: %s', $id, time() - $boomerang_time), LOG_DEBUG, __FILE__, __LINE__);
+            return false;
+        }
+
+        $_this->logMsg(sprintf('validBoomerangURL(%s) is valid: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
         return true;
     }
@@ -1082,7 +1048,5 @@
     function sslOn()
     {
-        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
-            $this =& App::getInstance();
-        }
+        $_this =& App::getInstance();
 
         if (function_exists('apache_get_modules')) {
@@ -1093,8 +1057,8 @@
         }
 
-        if ('' == getenv('HTTPS') && $this->getParam('ssl_enabled') && in_array('mod_ssl', $modules)) {
-            $this->raiseMsg(sprintf(_("Secure SSL connection made to %s"), $this->getParam('ssl_domain')), MSG_NOTICE, __FILE__, __LINE__);
+        if ('' == getenv('HTTPS') && $_this->getParam('ssl_enabled') && in_array('mod_ssl', $modules)) {
+            $_this->raiseMsg(sprintf(_("Secure SSL connection made to %s"), $_this->getParam('ssl_domain')), MSG_NOTICE, __FILE__, __LINE__);
             // Always append session because some browsers do not send cookie when crossing to SSL URL.
-            $this->dieURL('https://' . $this->getParam('ssl_domain') . getenv('REQUEST_URI'), null, true);
+            $_this->dieURL('https://' . $_this->getParam('ssl_domain') . getenv('REQUEST_URI'), null, true);
         }
     }
@@ -1107,10 +1071,8 @@
     function sslOff()
     {
-        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
-            $this =& App::getInstance();
-        }
+        $_this =& App::getInstance();
 
         if ('' != getenv('HTTPS')) {
-            $this->dieURL('http://' . getenv('HTTP_HOST') . getenv('REQUEST_URI'), null, true);
+            $_this->dieURL('http://' . getenv('HTTP_HOST') . getenv('REQUEST_URI'), null, true);
         }
     }
Index: branches/2.0/lib/DB.inc.php
===================================================================
--- branches/2.0/lib/DB.inc.php	(revision 156)
+++ branches/2.0/lib/DB.inc.php	(revision 157)
@@ -85,11 +85,9 @@
     function setParam($params)
     {
-        if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
-            $this =& DB::getInstance();
-        }
+        $_this =& DB::getInstance();
 
         if (isset($params) && is_array($params)) {
             // Merge new parameters with old overriding only those passed.
-            $this->_params = array_merge($this->_params, $params);
+            $_this->_params = array_merge($_this->_params, $params);
         } else {
             App::logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__);
@@ -108,10 +106,8 @@
     function getParam($param)
     {
-        if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
-            $this =& DB::getInstance();
-        }
-
-        if (isset($this->_params[$param])) {
-            return $this->_params[$param];
+        $_this =& DB::getInstance();
+
+        if (isset($_this->_params[$param])) {
+            return $_this->_params[$param];
         } else {
             App::logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
@@ -129,9 +125,7 @@
     function connect()
     {
-        if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
-            $this =& DB::getInstance();
-        }
-
-        if (!$this->getParam('db_name') || !$this->getParam('db_user') || !$this->getParam('db_pass')) {
+        $_this =& DB::getInstance();
+
+        if (!$_this->getParam('db_name') || !$_this->getParam('db_user') || !$_this->getParam('db_pass')) {
             App::logMsg('Database credentials missing.', LOG_EMERG, __FILE__, __LINE__);
             return false;
@@ -139,16 +133,16 @@
 
         // Connect to database. Always create a new link to the server.
-        if ($this->dbh = mysql_connect($this->getParam('db_server'), $this->getParam('db_user'), $this->getParam('db_pass'), true)) {
+        if ($_this->dbh = mysql_connect($_this->getParam('db_server'), $_this->getParam('db_user'), $_this->getParam('db_pass'), true)) {
             // Select database
-            mysql_select_db($this->getParam('db_name'), $this->dbh);
+            mysql_select_db($_this->getParam('db_name'), $_this->dbh);
         }
 
         // Test for connection errors.
-        if (!$this->dbh || mysql_error($this->dbh)) {
-            $mysql_error_msg = $this->dbh ? 'Codebase MySQL error: (' . mysql_errno($this->dbh) . ') ' . mysql_error($this->dbh) : 'Codebase MySQL error: Could not connect to server.';
+        if (!$_this->dbh || mysql_error($_this->dbh)) {
+            $mysql_error_msg = $_this->dbh ? 'Codebase MySQL error: (' . mysql_errno($_this->dbh) . ') ' . mysql_error($_this->dbh) : 'Codebase MySQL error: Could not connect to server.';
             App::logMsg($mysql_error_msg, LOG_EMERG, __FILE__, __LINE__);
 
             // Print helpful or pretty error?
-            if ($this->getParam('db_debug')) {
+            if ($_this->getParam('db_debug')) {
                 echo $mysql_error_msg . "\n";
             } else {
@@ -157,5 +151,5 @@
 
             // Die or continue without connection?
-            if ($this->getParam('db_die_on_failure')) {
+            if ($_this->getParam('db_die_on_failure')) {
                 echo "\n\n<!-- Script execution stopped out of embarrassment. -->";
                 die;
@@ -166,8 +160,8 @@
 
         // DB connection success!
-        $this->_connected = true;
+        $_this->_connected = true;
 
         // Tell MySQL what character set we're useing. Available only on MySQL verions > 4.01.01.
-        $this->query("/*!40101 SET NAMES '" . $this->mysql_character_sets[strtolower(App::getParam('character_set'))] . "' */");
+        $_this->query("/*!40101 SET NAMES '" . $_this->mysql_character_sets[strtolower(App::getParam('character_set'))] . "' */");
 
         return true;
@@ -183,13 +177,11 @@
     function close()
     {
-        if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
-            $this =& DB::getInstance();
-        }
-
-        if (!$this->_connected) {
-            return false;
-        }
-
-        mysql_close($this->dbh);
+        $_this =& DB::getInstance();
+
+        if (!$_this->_connected) {
+            return false;
+        }
+
+        mysql_close($_this->dbh);
     }
 
@@ -198,5 +190,5 @@
      *
      * @access  public
-     * @return  resource Current value of $this->dbh.
+     * @return  resource Current value of $_this->dbh.
      * @author  Quinn Comendant <quinn@strangecode.com>
      * @since   20 Aug 2005 13:50:36
@@ -204,13 +196,11 @@
     function getDBH()
     {
-        if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
-            $this =& DB::getInstance();
-        }
-
-        if (!$this->_connected) {
-            return false;
-        }
-
-        return $this->dbh;
+        $_this =& DB::getInstance();
+
+        if (!$_this->_connected) {
+            return false;
+        }
+
+        return $_this->dbh;
     }
 
@@ -224,5 +214,7 @@
     function isConnected()
     {
-        return $this->_connected;
+        $_this =& DB::getInstance();
+
+        return $_this->_connected;
     }
     
@@ -238,8 +230,7 @@
     function escapeString($string)
     {
-        if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
-            $this =& DB::getInstance();
-        }
-        return mysql_real_escape_string($string, $this->dbh);
+        $_this =& DB::getInstance();
+
+        return mysql_real_escape_string($string, $_this->dbh);
     }
 
@@ -256,9 +247,7 @@
         static $_query_count = 0;
 
-        if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
-            $this =& DB::getInstance();
-        }
-
-        if (!$this->_connected) {
+        $_this =& DB::getInstance();
+
+        if (!$_this->_connected) {
            return false;
         }
@@ -266,20 +255,20 @@
         $_query_count++;
         $debugqry = preg_replace("/\n[\t ]+/", "\n", $query);
-        if ($this->getParam('db_always_debug') || $debug) {
+        if ($_this->getParam('db_always_debug') || $debug) {
             echo "<!-- ----------------- Query $_query_count ---------------------\n$debugqry\n-->\n";
         }
 
         // Execute!
-        $qid = mysql_query($query, $this->dbh);
+        $qid = mysql_query($query, $_this->dbh);
 
         // Error checking.
-        if (!$qid || mysql_error($this->dbh)) {
-            if ($this->getParam('db_debug')) {
-                echo '<pre style="padding:2em; background:#ddd; font:9px monaco;">' . wordwrap(mysql_error($this->dbh)) . '<hr>' . htmlspecialchars($debugqry) . '</pre>';
+        if (!$qid || mysql_error($_this->dbh)) {
+            if ($_this->getParam('db_debug')) {
+                echo '<pre style="padding:2em; background:#ddd; font:9px monaco;">' . wordwrap(mysql_error($_this->dbh)) . '<hr>' . htmlspecialchars($debugqry) . '</pre>';
             } else {
                 echo _("This page is temporarily unavailable. It should be back up in a few minutes.");
             }
-            App::logMsg(sprintf('MySQL error %s: %s in query: %s', mysql_errno($this->dbh), mysql_error($this->dbh), $debugqry), LOG_EMERG, __FILE__, __LINE__);
-            if ($this->getParam('db_die_on_failure')) {
+            App::logMsg(sprintf('MySQL error %s: %s in query: %s', mysql_errno($_this->dbh), mysql_error($_this->dbh), $debugqry), LOG_EMERG, __FILE__, __LINE__);
+            if ($_this->getParam('db_die_on_failure')) {
                 echo "\n\n<!-- Script execution stopped out of embarrassment. -->";
                 die;
@@ -302,23 +291,21 @@
     function tableExists($table, $use_cached_results=true)
     {
-        if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
-            $this =& DB::getInstance();
-        }
-
-        if (!$this->_connected) {
-            return false;
-        }
-
-        if (!isset($this->existing_tables) || !$use_cached_results) {
-            $this->existing_tables = array();
-            $qid = $this->query("SHOW TABLES");
+        $_this =& DB::getInstance();
+
+        if (!$_this->_connected) {
+            return false;
+        }
+
+        if (!isset($_this->existing_tables) || !$use_cached_results) {
+            $_this->existing_tables = array();
+            $qid = $_this->query("SHOW TABLES");
             while (list($row) = mysql_fetch_row($qid)) {
-                $this->existing_tables[] = $row;
-            }
-        }
-        if (in_array($table, $this->existing_tables)) {
+                $_this->existing_tables[] = $row;
+            }
+        }
+        if (in_array($table, $_this->existing_tables)) {
             return true;
         } else {
-            App::logMsg(sprintf('nonexistent DB table: %s.%s', $this->getParam('db_name'), $table), LOG_ALERT, __FILE__, __LINE__);
+            App::logMsg(sprintf('nonexistent DB table: %s.%s', $_this->getParam('db_name'), $table), LOG_ALERT, __FILE__, __LINE__);
             return false;
         }
@@ -336,14 +323,12 @@
     function columnExists($table, $columns, $strict=true, $use_cached_results=true)
     {
-        if (!isset($this) || !is_a($this, 'DB') && !is_subclass_of($this, 'DB')) {
-            $this =& DB::getInstance();
-        }
-
-        if (!$this->_connected) {
+        $_this =& DB::getInstance();
+
+        if (!$_this->_connected) {
             return false;
         }
 
         // Ensure the table exists.
-        if (!$this->tableExists($table, $use_cached_results)) {
+        if (!$_this->tableExists($table, $use_cached_results)) {
             return false;
         }
@@ -354,10 +339,10 @@
         }
 
-        if (!isset($this->table_columns[$table]) || !$use_cached_results) {
+        if (!isset($_this->table_columns[$table]) || !$use_cached_results) {
             // Populate and cache array of current columns for this table.
-            $this->table_columns[$table] = array();
-            $qid = $this->query("DESCRIBE $table");
+            $_this->table_columns[$table] = array();
+            $qid = $_this->query("DESCRIBE $table");
             while ($row = mysql_fetch_row($qid)) {
-                $this->table_columns[$table][] = $row[0];
+                $_this->table_columns[$table][] = $row[0];
             }
         }
@@ -366,9 +351,9 @@
             // Do an exact comparison of table schemas.
             sort($columns);
-            sort($this->table_columns[$table]);
-            return $this->table_columns[$table] == $columns;
+            sort($_this->table_columns[$table]);
+            return $_this->table_columns[$table] == $columns;
         } else {
             // Only check that the specified columns are available in the table.
-            $match_columns = array_intersect($this->table_columns[$table], $columns);
+            $match_columns = array_intersect($_this->table_columns[$table], $columns);
             sort($columns);
             sort($match_columns);
@@ -386,6 +371,6 @@
     function resetCache()
     {
-        $this->existing_tables = null;
-        $this->table_columns = null;
+        $_this->existing_tables = null;
+        $_this->table_columns = null;
     }
 
Index: branches/2.0/lib/SessionCache.inc.php
===================================================================
--- branches/2.0/lib/SessionCache.inc.php	(revision 156)
+++ branches/2.0/lib/SessionCache.inc.php	(revision 157)
@@ -44,11 +44,9 @@
     function setParam($params)
     {
-        if (!isset($this) || !is_a($this, 'SessionCache') && !is_subclass_of($this, 'SessionCache')) {
-            $this =& SessionCache::getInstance();
-        }
+        $_this =& SessionCache::getInstance();
 
         if (isset($params) && is_array($params)) {
             // Merge new parameters with old overriding only those passed.
-            $this->_params = array_merge($this->_params, $params);
+            $_this->_params = array_merge($_this->_params, $params);
         } else {
             App::logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__);
@@ -65,10 +63,8 @@
     function getParam($param)
     {
-        if (!isset($this) || !is_a($this, 'SessionCache') && !is_subclass_of($this, 'SessionCache')) {
-            $this =& SessionCache::getInstance();
-        }
-
-        if (isset($this->_params[$param])) {
-            return $this->_params[$param];
+        $_this =& SessionCache::getInstance();
+
+        if (isset($_this->_params[$param])) {
+            return $_this->_params[$param];
         } else {
             App::logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
@@ -95,9 +91,7 @@
     function putCache($var, $var_id, $force_it_in=false)
     {
-        if (!isset($this) || !is_a($this, 'SessionCache') && !is_subclass_of($this, 'SessionCache')) {
-            $this =& SessionCache::getInstance();
-        }
-
-        if (!$this->getParam('enabled')) {
+        $_this =& SessionCache::getInstance();
+
+        if (!$_this->getParam('enabled')) {
             App::logMsg(sprintf('SessionCache not enabled, not saving data.', null), LOG_DEBUG, __FILE__, __LINE__);
             return false;
@@ -108,11 +102,11 @@
         $serialized_var_len = strlen($serialized_var);
 
-        if ($serialized_var_len >= $this->getParam('soft_limit') && !$force_it_in) {
-            App::logMsg(sprintf('Serialized variable (%s bytes) more than soft_limit (%s bytes).', $serialized_var_len, $this->getParam('soft_limit')), LOG_NOTICE, __FILE__, __LINE__);
-            return false;
-        }
-
-        if ($serialized_var_len >= $this->getParam('hard_limit')) {
-            App::logMsg(sprintf('Serialized variable (%s bytes) more than hard_limit (%s bytes).', $serialized_var_len, $this->getParam('hard_limit')), LOG_NOTICE, __FILE__, __LINE__);
+        if ($serialized_var_len >= $_this->getParam('soft_limit') && !$force_it_in) {
+            App::logMsg(sprintf('Serialized variable (%s bytes) more than soft_limit (%s bytes).', $serialized_var_len, $_this->getParam('soft_limit')), LOG_NOTICE, __FILE__, __LINE__);
+            return false;
+        }
+
+        if ($serialized_var_len >= $_this->getParam('hard_limit')) {
+            App::logMsg(sprintf('Serialized variable (%s bytes) more than hard_limit (%s bytes).', $serialized_var_len, $_this->getParam('hard_limit')), LOG_NOTICE, __FILE__, __LINE__);
             return false;
         }
@@ -123,6 +117,6 @@
             unset($_SESSION['_session_cache'][$var_id]);
             // Continue to prune the cache if it's length is too long for the new variable to fit, but keep at least MIN_ITEMS at least.
-            while (strlen(serialize($_SESSION['_session_cache'])) + $serialized_var_len >= $this->getParam('soft_limit')
-            && sizeof($_SESSION['_session_cache']) >= $this->getParam('min_items')) {
+            while (strlen(serialize($_SESSION['_session_cache'])) + $serialized_var_len >= $_this->getParam('soft_limit')
+            && sizeof($_SESSION['_session_cache']) >= $_this->getParam('min_items')) {
                 array_shift($_SESSION['_session_cache']);
             }
@@ -149,9 +143,7 @@
     function getCache($var_id)
     {
-        if (!isset($this) || !is_a($this, 'SessionCache') && !is_subclass_of($this, 'SessionCache')) {
-            $this =& SessionCache::getInstance();
-        }
-
-        if (!$this->getParam('enabled')) {
+        $_this =& SessionCache::getInstance();
+
+        if (!$_this->getParam('enabled')) {
             return false;
         }
@@ -179,9 +171,7 @@
     function isCached($var_id)
     {
-        if (!isset($this) || !is_a($this, 'SessionCache') && !is_subclass_of($this, 'SessionCache')) {
-            $this =& SessionCache::getInstance();
-        }
-
-        if (!$this->getParam('enabled')) {
+        $_this =& SessionCache::getInstance();
+
+        if (!$_this->getParam('enabled')) {
             return false;
         }
