Index: unk/bin/file_importer.php
===================================================================
--- /trunk/bin/file_importer.php	(revision 479)
+++ 	(revision )
@@ -1,124 +1,0 @@
-#!/usr/bin/php -q
-<?php
-/**
- * The Strangecode Codebase - a general application development framework for PHP
- * For details visit the project site: <http://trac.strangecode.com/codebase/>
- * Copyright 2001-2012 Strangecode, LLC
- * 
- * This file is part of The Strangecode Codebase.
- *
- * The Strangecode Codebase is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or (at your option)
- * any later version.
- * 
- * The Strangecode Codebase is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * file_importer.cli.php
- */
-
-// This file is only an example.
-
-
-// require realpath(dirname(__FILE__) . '/..') . '/config/cli_config.inc.php';
-// 
-// $app =& App::getInstance();
-// $db =& DB::getInstance();
-//  
-// 
-// // Test arguments.
-// if ($_SERVER['argc'] == 2 && is_dir($_SERVER['argv'][1])) {
-//     $file_dir = preg_replace('/\/$/', '', $_SERVER['argv'][1]);
-// } else {
-//     die("You must specify the directory of files to import as the only argument.\n");
-// }
-// 
-// // Get array of all files.
-// $files = getFilesRecursive($file_dir, 1);
-// 
-// // Loop through files.
-// // dump($files);
-// $file_count = 0;
-// if (is_array($files) && !empty($files)) {
-//     foreach ($files as $file) {
-//         if ($fp = fopen($file, 'r')) {
-//             echo ++$file_count . "\n";
-//             $file_text = join('', file($file));
-//             fclose($fp);
-// 
-//             // Do something with file contents.
-//             preg_match('/BALANCE:\s*\$([\.\d]+)/', $file_text, $amt);
-//             $file_date = date('Y-m-d', strtotime(preg_replace('|[^_]*_|', '', basename($file))));
-// //             $db->query("
-// //                 INSERT INTO invoice_tbl (
-// //                     client_id,
-// //                     invoice_type,
-// //                     invoice_date,
-// //                     invoice_amount,
-// //                     invoice_status,
-// //                     payment_type,
-// //                     invoice_text,
-// //                     email_sent_datetime,
-// //                     added_datetime
-// //                 ) VALUES (
-// //                     '" . $db->escapeString(0) . "',
-// //                     '" . $db->escapeString('hosting') . "',
-// //                     '" . $db->escapeString($file_date) . "',
-// //                     '" . $db->escapeString($amt[1]) . "',
-// //                     '" . $db->escapeString('Paid') . "',
-// //                     '" . $db->escapeString('') . "',
-// //                     '" . $db->escapeString($file_text) . "',
-// //                     '" . $db->escapeString($file_date) . "',
-// //                     NOW()
-// //                 )
-// //             ");
-// 
-//         } else {
-//             $app->logMsg('Could not open file: ' . $file, LOG_INFO, __FILE__, __LINE__);
-//         }
-//     }
-//     $app->logMsg('Processing complete: ' . $file_count . ' files total.', LOG_INFO, __FILE__, __LINE__);
-// } else {
-//     $app->logMsg('No files available in that directory.', LOG_INFO, __FILE__, __LINE__);
-// }
-// 
-// 
-// 
-// 
-// /**
-//  * Find all files in directories recursively with a specified file extension.
-//  *
-//  * @param  string $dir               the full path to the directory to scan
-//  * @param  array  $valid_extensions  valid extensions
-//  * @param  int    $recurs_lev        how many levels deep to scan. Set this
-//  *                                   to a low number to prevent infinite loops
-//  *
-//  * @return array   multi-dimentional array of found files on success
-//  */
-// function getFilesRecursive($dir, $recurs_lev=0, $return=true)
-// {
-//     static $output;
-// 
-//     $dir_handle = opendir($dir);
-//     while ($dir_handle && ($file = readdir($dir_handle)) !== false) {
-//         if (!preg_match('/^\./', $file)) {
-//             if (is_dir($dir . '/' . $file) && $recurs_lev > 0) {
-//                 getFilesRecursive($dir . '/' . $file, $valid_extensions, $recurs_lev - 1);
-//             } else if (!is_dir($dir . '/' . $file)) {
-//                 $output[] = $dir . '/' . $file;
-//             }
-//         }
-//     }
-//     if ($return) {
-//         return $output;
-//     }
-// }
-// 
Index: /trunk/docs/examples/_config.inc.php
===================================================================
--- /trunk/docs/examples/_config.inc.php	(revision 479)
+++ /trunk/docs/examples/_config.inc.php	(revision 480)
@@ -123,15 +123,21 @@
 // Load preferences for the user.
 require_once 'codebase/lib/Prefs.inc.php';
-$prefs = new Prefs('permanent');
-$prefs->setParam(array(
-    'persistent' => $auth->isLoggedIn(),
+$prefs = new Prefs('permanent', array(
+    'storagetype' => ($auth->isLoggedIn() ? 'database' : 'session'),
     'user_id' => $auth->get('user_id'),
 ));
 $prefs->setDefaults(array(
+    // ...
 ));
 $prefs->load();
+// Load preferences for temporary usage.
+require_once 'codebase/lib/Prefs.inc.php';
+$c_prefs = new Prefs('config');
+$c_prefs->setParam(array(
+    'storagetype' => 'cookie',
+));
 // Temporary prefs.
-$tmp_prefs = new Prefs('temporary');
-$tmp_prefs->setDefaults(array(
+$c_prefs = new Prefs('settings');
+$c_prefs->setDefaults(array(
 ));
 
Index: /trunk/lib/App.inc.php
===================================================================
--- /trunk/lib/App.inc.php	(revision 479)
+++ /trunk/lib/App.inc.php	(revision 480)
@@ -807,5 +807,5 @@
                 unset($this->_carry_queries[$k]);
             }
-            if ($unset && array_key_exists($k, $_REQUEST)) {
+            if ($unset && (isset($_REQUEST) && array_key_exists($k, $_REQUEST))) {
                 unset($_REQUEST[$k], $_GET[$k], $_POST[$k], $_COOKIE[$k]);
             }
Index: /trunk/lib/Cache.inc.php
===================================================================
--- /trunk/lib/Cache.inc.php	(revision 479)
+++ /trunk/lib/Cache.inc.php	(revision 480)
@@ -211,5 +211,5 @@
         }
 
-        if (array_key_exists($key, $_SESSION['_cache'][$this->_ns])) {
+        if (isset($_SESSION['_cache'][$this->_ns]) && array_key_exists($key, $_SESSION['_cache'][$this->_ns])) {
             $app->logMsg(sprintf('Retreiving %s from cache.', $key), LOG_DEBUG, __FILE__, __LINE__);
             // Move the accessed cached datum to the top of the stack. Maybe somebody knows a better way to do this?
@@ -240,5 +240,5 @@
         }
 
-        return array_key_exists($key, $_SESSION['_cache'][$this->_ns]);
+        return (isset($_SESSION['_cache'][$this->_ns]) && array_key_exists($key, $_SESSION['_cache'][$this->_ns]));
     }
 
@@ -251,5 +251,5 @@
     public function delete($key)
     {
-        if (array_key_exists($key, $_SESSION['_cache'][$this->_ns])) {
+        if (isset($_SESSION['_cache'][$this->_ns]) && array_key_exists($key, $_SESSION['_cache'][$this->_ns])) {
             unset($_SESSION['_cache'][$this->_ns][$key]);
             return true;
Index: unk/lib/Google_API.inc.php
===================================================================
--- /trunk/lib/Google_API.inc.php	(revision 479)
+++ 	(revision )
@@ -1,168 +1,0 @@
-<?php
-/**
- * The Strangecode Codebase - a general application development framework for PHP
- * For details visit the project site: <http://trac.strangecode.com/codebase/>
- * Copyright 2001-2012 Strangecode, LLC
- * 
- * This file is part of The Strangecode Codebase.
- *
- * The Strangecode Codebase is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or (at your option)
- * any later version.
- * 
- * The Strangecode Codebase is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * Google_API.inc.php
- *
- * Interface to the Google API using SOAP/Client.php.
- *
- * @author  Quinn Comendant <quinn@strangecode.com>
- * @version 1.1
- */
-
-// Example of use:
-//
-// require_once 'Google_API.php';
-// $google = new Google_API('your license key');
-// $result = $google->search(
-//   array(
-//     'query' => 'sebastian bergmann'
-//   )
-// );
-// if (false !== $result) {
-//   print_r($result);
-// } else {
-//   echo 'Query failed.';
-// }
-
-require_once 'SOAP/Client.php';
-
-class Google_API {
-
-    /**
-     * @var    string
-     * @access private
-     */
-    private $_licenseKey = '';
-
-    /**
-     * @var    object
-     * @access private
-     */
-    private $_soapClient = NULL;
-
-    /**
-     * Constructor.
-     *
-     * @param  string
-     * @access public
-     */
-    public function __construct($licenseKey)
-    {
-        $this->_licenseKey = $licenseKey;
-        $this->_soapClient = new SOAP_Client(
-          'http://api.google.com/search/beta2'
-        );
-    }
-
-    /**
-     * Retrieves a page by URL from the Google Cache.
-     *
-     * @param  string
-     * @return mixed
-     * @access public
-     */
-    public function getCachedPage($url)
-    {
-        $result = $this->_performAPICall(
-            'doGetCachedPage',
-            array(
-                'key' => $this->_licenseKey,
-                'url' => $url
-            )
-        );
-        if ($result) {
-            $result = base64_decode($result);
-        }
-        return $result;
-    }
-
-    /**
-     * Retrieves a spelling suggestion for a phrase.
-     *
-     * @param  string
-     * @return mixed
-     * @access public
-     */
-    public function getSpellingSuggestion($phrase)
-    {
-        return $this->_performAPICall(
-            'doSpellingSuggestion',
-            array(
-                'key'    => $this->_licenseKey,
-                'phrase' => $phrase
-            )
-        );
-    }
-
-    /**
-     * Performs a web search.
-     *
-     * @param  array
-     * @return mixed
-     * @access public
-     */
-    public function search($parameters = array())
-    {
-        if (!isset($parameters['query'])) {
-            return false;
-        }
-        return $this->_performAPICall(
-            'doGoogleSearch',
-            array(
-                'key'         => $this->_licenseKey,
-                'q'           => $parameters['query'],
-                'start'       => isset($parameters['start'])      ? $parameters['start']      : 0,
-                'maxResults'  => isset($parameters['maxResults']) ? $parameters['maxResults'] : 10,
-                'filter'      => isset($parameters['filter'])     ? $parameters['filter']     : false,
-                'restrict'    => isset($parameters['restrict'])   ? $parameters['restrict']   : '',
-                'safeSearch'  => isset($parameters['safeSearch']) ? $parameters['safeSearch'] : false,
-                'lr'          => isset($parameters['lr'])         ? $parameters['lr']         : '',
-                'ie'          => isset($parameters['ie'])         ? $parameters['ie']         : '',
-                'oe'          => isset($parameters['oe'])         ? $parameters['oe']         : ''
-            )
-        );
-    }
-
-    /**
-     * @param  string
-     * @param  array
-     * @return mixed
-     * @access private
-     */
-    private function _performAPICall($apiCall, $parameters)
-    {
-        $app =& App::getInstance();
-        
-        $result = $this->_soapClient->call(
-            $apiCall,
-            $parameters,
-            'urn:GoogleSearch'
-        );
-        if (!PEAR::isError($result)) {
-            return $result;
-        } else {
-            $app->logMsg(sprintf('Soap Pear error: %s', $result->getMessage()), LOG_NOTICE, __FILE__, __LINE__);
-            return false;
-        }
-    }
-}
Index: unk/lib/MCVE.inc.php
===================================================================
--- /trunk/lib/MCVE.inc.php	(revision 479)
+++ 	(revision )
@@ -1,209 +1,0 @@
-<?php
-/**
- * The Strangecode Codebase - a general application development framework for PHP
- * For details visit the project site: <http://trac.strangecode.com/codebase/>
- * Copyright 2001-2012 Strangecode, LLC
- * 
- * This file is part of The Strangecode Codebase.
- *
- * The Strangecode Codebase is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or (at your option)
- * any later version.
- * 
- * The Strangecode Codebase is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- * details.
- * 
- * You should have received a copy of the GNU General Public License along with
- * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * MCVE.inc.php
- *
- * The MCVE class provides functions for communicating with a MCVE server.
- *
- * @author  Quinn Comendant <quinn@strangecode.com>
- * @version 1.0
- */
-class MCVE {
-
-    public $username;
-    public $password;
-    public $host = 'localhost';
-    public $ip_port = 8333;
-    public $ssl_port = 8444;
-    public $ca_bundle_file = '/usr/share/ssl/certs/ca-bundle.crt';
-    public $connect_method = 'ip';
-    public $timeout = 10;
-    public $blocking = 1;
-    public $connected = false;
-    public $conn;
-
-    public function __construct($username, $password)
-    {
-        $app =& App::getInstance();
-
-        // Ensure PHP was compiled with the MCVE functions.
-        if (!extension_loaded('mcve')) {
-            trigger_error('MCVE class instantiation failed: MCVE extension not available.', E_USER_ERROR);
-        }
-        if ('' == $username || '' == $password) {
-            $app->logMsg(sprintf('Empty username or password provided.', null), LOG_ERR, __FILE__, __LINE__);
-        }
-        $this->username = $username;
-        $this->password = $password;
-    }
-
-    private function _connect()
-    {
-        $app =& App::getInstance();
-
-        if ($this->connected) {
-            return true;
-        }
-
-        // Initialize SSL structures and definitions.
-        MCVE_InitEngine($this->ca_bundle_file);
-
-        // Allocate Connection Structures
-        $this->conn = MCVE_InitConn();
-
-        // Set Connection Method and Locations
-        switch ($this->connect_method) {
-        case 'ip' :
-            if (!MCVE_SetIP($this->conn, $this->host, $this->ip_port)) {
-                $app->logMsg('Could not set method to IP.', LOG_ERR, __FILE__, __LINE__);
-                return false;
-            }
-            break;
-        case 'ssl' :
-            if (!MCVE_SetSSL($this->conn, $this->host, $this->ssl_port)) {
-                $app->logMsg('Could not set method to SSL.', LOG_ERR, __FILE__, __LINE__);
-                return false;
-            }
-            break;
-        case 'dropfile' :
-            if (!MCVE_SetDropFile($this->conn, '/var/mcve/trans')) {
-                $app->logMsg('Could not set method to dropfile.', LOG_ERR, __FILE__, __LINE__);
-                return false;
-            }
-            break;
-        default :
-            $app->logMsg('Connection method not defined.', LOG_ERR, __FILE__, __LINE__);
-            return false;
-        }
-
-        // Put connection into non-blocking mode, meaning that the client must
-        // loop waiting for the transaction to complete. You should always specify
-        // this function with your blocking preference as the default is currently
-        // non-blocking, but future versions of php_mcve will default to blocking.
-        if (!MCVE_SetBlocking($this->conn, $this->blocking)) {
-            $app->logMsg('Could not set blocking mode.', LOG_ERR, __FILE__, __LINE__);
-            return false;
-        }
-
-        // Maximum of 30s per transaction allowed. Timeout occurs on server-end, not client-end
-        if (!MCVE_SetTimeout($this->conn, $this->timeout)) {
-            $app->logMsg('Could not set timeout.', LOG_ERR, __FILE__, __LINE__);
-            return false;
-        }
-
-        // Connect to MCVE, if there's an error, print the exact reason for connection failure
-        if (!MCVE_Connect($this->conn)) {
-            $error = MCVE_ConnectionError($this->conn);
-            $app->logMsg("$error. Are you sure the MCVE engine is running?", LOG_ERR, __FILE__, __LINE__);
-            return false;
-        }
-
-        $this->connected = true;
-        return true;
-    }
-
-    public function beginTrans()
-    {
-        if (!$this->_connect()) {
-            return false;
-        }
-        $tid = MCVE_TransNew($this->conn); // Allocate memory for sending a transaction.
-        $this->transParam($tid, MC_USERNAME, $this->username);
-        $this->transParam($tid, MC_PASSWORD, $this->password);
-        return $tid;
-    }
-
-    public function transParam($tid, $key, $var1, $var2=null)
-    {
-        if (!isset($var2)) {
-            return MCVE_TransParam($this->conn, $tid, $key, $var1);
-        } else {
-            return MCVE_TransParam($this->conn, $tid, $key, $var1, $var2);
-        }
-
-    }
-
-    public function sendTrans($tid, $type='', $hide_msg=false)
-    {
-        $app =& App::getInstance();
-
-        // Finalize structuring of  to MCVE and ready it to be sent
-        if (!MCVE_TransSend($this->conn, $tid)) {
-            $app->logMsg('Transaction improperly structured, possibly not enough info.', LOG_ERR, __FILE__, __LINE__);
-            return false;
-        }
-
-        // Perform actual communication with MCVE engine.
-        // If blocking method is used, loop until transaction is complete
-        if ($this->blocking != 1) {
-            while (MCVE_CheckStatus($this->conn, $tid) != MCVE_DONE) {
-                MCVE_Monitor($this->conn); // Perform communication on connection
-                MCVE_uwait(10000); // Microsecond thread-safe sleep timer. Better than usleep()
-            }
-        }
-
-        $ret_status = MCVE_ReturnStatus($this->conn, $tid);
-        $ret_code = MCVE_ReturnCode($this->conn, $tid);
-        $ret_text = mcve_text_code($ret_code);
-        $verbiage = MCVE_TransactionText($this->conn, $tid);
-
-        // Check to see if transaction was successful or not using a strict success/fail function
-        if ($ret_status == MCVE_FAIL) {
-            $app->raiseMsg(sprintf('MCVE %s failure: %s %s', $type, $ret_text, ('' == $verbiage ? '' : '(' . trim($verbiage) . ')')), MSG_WARNING, __FILE__, __LINE__);
-            return false;
-        } else if ($ret_status == MCVE_SUCCESS) {
-            if (!$hide_msg) {
-                $app->raiseMsg(sprintf(_("MCVE %s success: %s %s"), $type, $ret_text, ('' == $verbiage ? '' : '(' . trim($verbiage) . ')')), MSG_SUCCESS, __FILE__, __LINE__);
-            }
-            $app->logMsg(sprintf('MCVE success details. Auth: %s; Batch: %s; Item: %s; TTID: %s; AVS: %s; CV: %s.',
-                MCVE_TransactionAuth($this->conn, $tid),
-                MCVE_TransactionBatch($this->conn, $tid),
-                MCVE_TransactionItem($this->conn, $tid),
-                MCVE_TransactionID($this->conn, $tid),
-                mcve_text_avs(MCVE_TransactionAVS($this->conn, $tid)),
-                mcve_text_cv(MCVE_TransactionCV($this->conn, $tid))
-            ), LOG_INFO, __FILE__, __LINE__);
-            return true;
-        } else {
-            $app->logMsg(sprintf('Transaction failed. Unknown return code: %s', $ret_status), LOG_ERR, __FILE__, __LINE__);
-            return false;
-        }
-    }
-
-    public function disconnect($tid)
-    {
-        if ($this->connected) {
-            // Optional, clean up memory by transaction ... This is done automatically by
-            // MCVE_DestroyConn though
-            MCVE_DeleteTrans($this->conn, $tid);
-
-            // Clean up and close MCVE.
-            MCVE_DestroyConn($this->conn);
-            MCVE_DestroyEngine();
-
-            $this->connected = false;
-        }
-    }
-}
-// End of class.
-
Index: /trunk/lib/Prefs.inc.php
===================================================================
--- /trunk/lib/Prefs.inc.php	(revision 479)
+++ /trunk/lib/Prefs.inc.php	(revision 480)
@@ -275,7 +275,7 @@
             // - or the new value is different than the default
             // - or there is a previously existing saved key.
-            if (!array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['defaults'])
+            if (!(isset($_SESSION['_prefs'][$this->_ns]['defaults']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['defaults']))
             || $_SESSION['_prefs'][$this->_ns]['defaults'][$key] != $val
-            || array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved'])) {
+            || (isset($_SESSION['_prefs'][$this->_ns]['saved']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved']))) {
                 $_SESSION['_prefs'][$this->_ns]['saved'][$key] = $val;
                 $app->logMsg(sprintf('Setting session preference %s => %s', $key, getDump($val, true)), LOG_DEBUG, __FILE__, __LINE__);
@@ -348,9 +348,9 @@
         case 'session':
         case 'database':
-            return array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved']);
+            return (isset($_SESSION['_prefs'][$this->_ns]['saved']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved']));
 
         case 'cookie':
             $name = $this->_getCookieName($key);
-            return array_key_exists($name, $_COOKIE);
+            return (isset($_COOKIE) && array_key_exists($name, $_COOKIE));
         }
 
Index: /trunk/tests/PrefsTest.php
===================================================================
--- /trunk/tests/PrefsTest.php	(revision 479)
+++ /trunk/tests/PrefsTest.php	(revision 480)
@@ -7,5 +7,5 @@
  * For details visit the project site: <http://trac.strangecode.com/codebase/>
  * Copyright 2001-2012 Strangecode, LLC
- * 
+ *
  * This file is part of The Strangecode Codebase.
  *
@@ -14,10 +14,10 @@
  * Free Software Foundation, either version 3 of the License, or (at your option)
  * any later version.
- * 
+ *
  * The Strangecode Codebase is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  * details.
- * 
+ *
  * You should have received a copy of the GNU General Public License along with
  * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
@@ -47,5 +47,7 @@
         require dirname(__FILE__) . '/_config.inc.php';
         require_once '../lib/Prefs.inc.php';
-        $this->Prefs =& new Prefs(PARAM);
+        $prefs = new Prefs('test', array(
+            'storagetype' => 'session',
+        ));
     }
 
