Changeset 135


Ignore:
Timestamp:
Jun 1, 2006 7:42:53 AM (18 years ago)
Author:
scdev
Message:

Q - Finished integrating singleton methods into existing code. Renamed SessionCache? to Cache, and renamed methods in Cache and Prefs

Location:
branches/2.0singleton
Files:
34 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0singleton/bin/module_maker/skel/admin.php

    r132 r135  
    5858if (getFormData('break_list_cache', false)) {
    5959    // Break the cache because we are changing the list data.
    60     $cache->breakCache($_SERVER['PHP_SELF']);
     60    $cache->delete($_SERVER['PHP_SELF']);
    6161}
    6262
     
    258258
    259259    // Break the cache because we are changing the list data.
    260     $cache->breakCache($_SERVER['PHP_SELF']);
     260    $cache->delete($_SERVER['PHP_SELF']);
    261261
    262262    // Get the information for this object.
     
    288288   
    289289    // Break the cache because we are changing the list data.
    290     $cache->breakCache($_SERVER['PHP_SELF']);
     290    $cache->delete($_SERVER['PHP_SELF']);
    291291
    292292%INSERT%
     
    314314
    315315    // Break the cache because we are changing the list data.
    316     $cache->breakCache($_SERVER['PHP_SELF']);
     316    $cache->delete($_SERVER['PHP_SELF']);
    317317
    318318%UPDATE%
     
    383383    // without knowing the hash.
    384384    $cache_hash = md5($sql . '|' . $page->total_items);
    385     if ($prefs->getValue('cache_hash', $_SERVER['PHP_SELF']) != $cache_hash) {
    386         $cache->breakCache($_SERVER['PHP_SELF']);
    387         $prefs->setValue('cache_hash', $cache_hash, $_SERVER['PHP_SELF']);
    388     }
    389 
    390     if ($cache->isCached($_SERVER['PHP_SELF'])) {
     385    if ($prefs->get('cache_hash', $_SERVER['PHP_SELF']) != $cache_hash) {
     386        $cache->delete($_SERVER['PHP_SELF']);
     387        $prefs->set('cache_hash', $cache_hash, $_SERVER['PHP_SELF']);
     388    }
     389
     390    if ($cache->exists($_SERVER['PHP_SELF'])) {
    391391        // Get the cached results.
    392         $list = $cache->getCache($_SERVER['PHP_SELF']);
     392        $list = $cache->get($_SERVER['PHP_SELF']);
    393393    } else {
    394394        // If the list is not already cached, query now.
     
    401401        if (isset($list) && !empty($list)) {
    402402            // Cache the results.
    403             $cache->putCache($list, $_SERVER['PHP_SELF']);
     403            $cache->set($list, $_SERVER['PHP_SELF']);
    404404        }
    405405    }
     
    419419
    420420    // Break the cache because we are changing the list data.
    421     $cache->breakCache($_SERVER['PHP_SELF']);
     421    $cache->delete($_SERVER['PHP_SELF']);
    422422
    423423    // Count the ranks with invalid numbers
  • branches/2.0singleton/docs/file_layout.txt

    r42 r135  
    5555        RecordVersion.inc.php (db record versioning system)
    5656        ScriptTimer.inc.php (timer for scripts)
    57         SessionCache.inc.php (class for accessing a cache in a users session, stores any variables for quick retreival)
     57        Cache.inc.php (class for accessing a cache in a users session, stores any variables for quick retreival)
    5858        SortOrder.inc.php (class dealing with sorting of columns in database generated lists)
    5959        SpellCheck.inc.php
  • branches/2.0singleton/docs/revision_history.txt

    r42 r135  
    2222    - RecordLock
    2323    - RecordVersion
    24     - SessionCache
     24    - Cache
    2525    - Upload
    2626
     
    4747    - app object can be accessed globally without reference to object name by calling methods statically, e.g. App:logMsg()
    4848    - seperate application and codebase parameters from site configuration variables.
    49       Use $app->getParam('var') or App::getParam('var') to get app params.
     49      Use $app->getParam('var') or $app->getParam('var') to get app params.
    5050      F or site configurations do whatever you want (I'm using $cfg['node']['features'] format for configurations)
    5151
     
    5959
    6060DB object:
    61     - Self contained class for DB functions. db::query is the only necessary function. Maintains connections and state independent of App.
     61    - Self contained class for DB functions. $db->query is the only necessary function. Maintains connections and state independent of App.
    6262
    6363Full test suite for all codebase libraries. Run from the command line: "codebase/tests/run_tests.sh;"
  • branches/2.0singleton/lib/App.inc.php

    r127 r135  
    77 *
    88 * @author  Quinn Comendant <quinn@strangecode.com>
    9  * @version 2.0
     9 * @version 2.1
    1010 */
    1111
     
    2222class App {
    2323
    24     // Name of this application.
    25     var $app = '_app_';
     24    // Namespace of this application instance.
     25    var $ns;
    2626
    2727    // If $app->start has run successfully.
     
    3434    var $_carry_queries = array();
    3535
    36     // Hash of global application parameters.
     36    // Dictionary of global application parameters.
    3737    var $_params = array();
    3838
     
    9999
    100100        // General application log.
    101         'log_filename' => 'app_error_log',
     101        'log_filename' => 'app_log',
    102102
    103103        // Logging priority can be any of the following, or false to deactivate:
     
    128128     * This method enforces the singleton pattern for this class. Only one application is running at a time.
    129129     *
    130      * @return  object  Reference to the global SessionCache object.
     130     * $param   string  $namespace  Name of this application.
     131     * @return  object  Reference to the global Cache object.
    131132     * @access  public
    132133     * @static
    133134     */
    134     function &getInstance($app=null)
     135    function &getInstance($namespace='')
    135136    {
    136137        static $instance = null;
    137138
    138139        if ($instance === null) {
    139             $instance = new App($app);
     140            $instance = new App($namespace);
    140141        }
    141142
     
    146147     * Constructor.
    147148     */
    148     function App($app=null)
    149     {
    150         if (isset($app)) {
    151             $this->app .= $app;
    152         }
     149    function App($namespace='')
     150    {
     151        // Set namespace of application instance.
     152        $this->ns = '_app_' . $namespace;
    153153
    154154        // Initialize default parameters.
     
    164164    function setParam($param=null)
    165165    {
    166         if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
    167             $_this =& App::getInstance();
    168         }
    169 
    170166        if (isset($param) && is_array($param)) {
    171167            // Merge new parameters with old overriding only those passed.
    172             $_this->_params = array_merge($_this->_params, $param);
     168            $this->_params = array_merge($this->_params, $param);
    173169        }
    174170    }
     
    181177     * @return  mixed               Parameter value, or null if not existing.
    182178     */
    183     function &getParam($param=null)
    184     {
    185         if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
    186             $_this =& App::getInstance();
    187         }
    188 
     179    function getParam($param=null)
     180    {
    189181        if ($param === null) {
    190             return $_this->_params;
    191         } else if (isset($_this->_params[$param])) {
    192             return $_this->_params[$param];
     182            return $this->_params;
     183        } else if (isset($this->_params[$param])) {
     184            return $this->_params[$param];
    193185        } else {
    194186            trigger_error(sprintf('Parameter is not set: %s', $param), E_USER_NOTICE);
     
    239231            }
    240232
    241             // The only instance of the DB object.
     233            // There will ever only be one instance of the DB object, and here is where it is instantiated.
    242234            require_once dirname(__FILE__) . '/DB.inc.php';
    243 
    244235            $this->db =& DB::getInstance();
    245 
    246236            $this->db->setParam(array(
    247237                'db_server' => $this->getParam('db_server'),
     
    270260        if (true === $this->getParam('enable_session')) {
    271261
    272             // Set the session ID to one provided in GET/POST. This is necessary for linking
    273             // between domains and keeping the same session.
    274             if ($ses = getFormData($this->getParam('session_name'), false)) {
    275                 session_id($ses);
    276             }
    277 
    278262            if (true === $this->getParam('enable_db_session_handler') && true === $this->getParam('enable_db')) {
    279263                // Database session handling.
     
    295279            session_start();
    296280
    297             if (!isset($_SESSION[$this->app])) {
     281            if (!isset($_SESSION[$this->ns])) {
    298282                // Access session data using: $_SESSION['...'].
    299283                // Initialize here _after_ session has started.
    300                 $_SESSION[$this->app] = array(
     284                $_SESSION[$this->ns] = array(
    301285                    'messages' => array(),
    302286                    'boomerang' => array('url'),
     
    360344    function raiseMsg($message, $type=MSG_NOTICE, $file=null, $line=null)
    361345    {
    362         if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
    363             $_this =& App::getInstance();
    364         }
    365 
    366346        $message = trim($message);
    367347
    368         if (!$_this->running || '' == $message) {
    369             $_this->logMsg(sprintf('Canceled method call %s, application not running or message is an empty string.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     348        if (!$this->running || '' == $message) {
     349            $this->logMsg(sprintf('Canceled method call %s, application not running or message is an empty string.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
    370350            return false;
    371351        }
     
    373353        // Save message in session under unique key to avoid duplicate messages.
    374354        $msg_id = md5($type . $message . $file . $line);
    375         $_SESSION[$_this->app]['messages'][$msg_id] = array(
     355        $_SESSION[$this->ns]['messages'][$msg_id] = array(
    376356            'type'    => $type,
    377357            'message' => $message,
    378358            'file'    => $file,
    379359            'line'    => $line,
    380             'count'   => (isset($_SESSION[$_this->app]['messages'][$msg_id]['count']) ? (1 + $_SESSION[$_this->app]['messages'][$msg_id]['count']) : 1)
     360            'count'   => (isset($_SESSION[$this->ns]['messages'][$msg_id]['count']) ? (1 + $_SESSION[$this->ns]['messages'][$msg_id]['count']) : 1)
    381361        );
    382362
    383363        if (!in_array($type, array(MSG_NOTICE, MSG_SUCCESS, MSG_WARNING, MSG_ERR))) {
    384             $_this->logMsg(sprintf('Invalid MSG_* type: %s', $type), LOG_DEBUG, __FILE__, __LINE__);
     364            $this->logMsg(sprintf('Invalid MSG_* type: %s', $type), LOG_NOTICE, __FILE__, __LINE__);
    385365        }
    386366    }
     
    396376    function getRaisedMessages()
    397377    {
    398         if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
    399             $_this =& App::getInstance();
    400         }
    401 
    402         if (!$_this->running) {
    403             $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     378        if (!$this->running) {
     379            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
    404380            return false;
    405381        }
    406382       
    407383        $output = array();
    408         while (isset($_SESSION[$_this->app]['messages']) && $message = array_shift($_SESSION[$_this->app]['messages'])) {
     384        while (isset($_SESSION[$this->ns]['messages']) && $message = array_shift($_SESSION[$this->ns]['messages'])) {
    409385            $output[] = $message;
    410386        }
     
    421397    function clearRaisedMessages()
    422398    {
    423         if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
    424             $_this =& App::getInstance();
    425         }
    426 
    427         if (!$_this->running) {
    428             $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     399        if (!$this->running) {
     400            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
    429401            return false;
    430402        }
    431403       
    432         $_SESSION[$_this->app]['messages'] = array();
     404        $_SESSION[$this->ns]['messages'] = array();
    433405    }
    434406
     
    442414    function printRaisedMessages()
    443415    {
    444         if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
    445             $_this =& App::getInstance();
    446         }
    447 
    448         if (!$_this->running) {
    449             $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
    450             return false;
    451         }
    452 
    453         while (isset($_SESSION[$_this->app]['messages']) && $message = array_shift($_SESSION[$_this->app]['messages'])) {
     416        if (!$this->running) {
     417            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
     418            return false;
     419        }
     420
     421        while (isset($_SESSION[$this->ns]['messages']) && $message = array_shift($_SESSION[$this->ns]['messages'])) {
    454422            ?><div class="sc-msg"><?php
    455             if (error_reporting() > 0 && $_this->getParam('display_errors')) {
     423            if (error_reporting() > 0 && $this->getParam('display_errors')) {
    456424                echo "\n<!-- [" . $message['file'] . ' : ' . $message['line'] . '] -->';
    457425            }
     
    501469        static $previous_events = array();
    502470
    503         if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
    504             $_this =& App::getInstance();
    505         }
    506 
    507471        // If priority is not specified, assume the worst.
    508         if (!$_this->logPriorityToString($priority)) {
    509             $_this->logMsg(sprintf('Log priority %s not defined. (Message: %s)', $priority, $message), LOG_EMERG, $file, $line);
     472        if (!$this->logPriorityToString($priority)) {
     473            $this->logMsg(sprintf('Log priority %s not defined. (Message: %s)', $priority, $message), LOG_EMERG, $file, $line);
    510474            $priority = LOG_EMERG;
    511475        }
    512476
    513477        // If log file is not specified, don't log to a file.
    514         if (!$_this->getParam('log_directory') || !$_this->getParam('log_filename') || !is_dir($_this->getParam('log_directory')) || !is_writable($_this->getParam('log_directory'))) {
    515             $_this->setParam(array('log_file_priority' => false));
     478        if (!$this->getParam('log_directory') || !$this->getParam('log_filename') || !is_dir($this->getParam('log_directory')) || !is_writable($this->getParam('log_directory'))) {
     479            $this->setParam(array('log_file_priority' => false));
    516480            // We must use trigger_error to report this problem rather than calling $app->logMsg, which might lead to an infinite loop.
    517             trigger_error(sprintf('Codebase error: log directory (%s) not found or writable.', $_this->getParam('log_directory')), E_USER_NOTICE);
     481            trigger_error(sprintf('Codebase error: log directory (%s) not found or writable.', $this->getParam('log_directory')), E_USER_NOTICE);
    518482        }
    519483
     
    531495            $previous_events[$msg_id]++;
    532496            if ($previous_events[$msg_id] == 2) {
    533                 $_this->logMsg(sprintf('%s (Event repeated %s or more times)', $message, $previous_events[$msg_id]), $priority, $file, $line);
     497                $this->logMsg(sprintf('%s (Event repeated %s or more times)', $message, $previous_events[$msg_id]), $priority, $file, $line);
    534498            }
    535499            return false;
     
    543507            'remote ip' => getRemoteAddr(),
    544508            'pid'       => (substr(PHP_OS, 0, 3) != 'WIN' ? posix_getpid() : ''),
    545             'type'      => $_this->logPriorityToString($priority),
     509            'type'      => $this->logPriorityToString($priority),
    546510            'file:line' => "$file : $line",
    547511            'url'       => (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''),
     
    550514
    551515        // FILE ACTION
    552         if ($_this->getParam('log_file_priority') && $priority <= $_this->getParam('log_file_priority')) {
     516        if ($this->getParam('log_file_priority') && $priority <= $this->getParam('log_file_priority')) {
    553517            $event_str = '[' . join('] [', $event) . ']';
    554             error_log($event_str . "\n", 3, $_this->getParam('log_directory') . '/' . $_this->getParam('log_filename'));
     518            error_log($event_str . "\n", 3, $this->getParam('log_directory') . '/' . $this->getParam('log_filename'));
    555519        }
    556520
    557521        // EMAIL ACTION
    558         if ($_this->getParam('log_email_priority') && $priority <= $_this->getParam('log_email_priority')) {
     522        if ($this->getParam('log_email_priority') && $priority <= $this->getParam('log_email_priority')) {
    559523            $subject = sprintf('[%s %s] %s', getenv('HTTP_HOST'), $event['type'], $message);
    560524            $email_msg = sprintf("A %s log event occured on %s\n\n", $event['type'], getenv('HTTP_HOST'));
     
    563527                $email_msg .= sprintf("%-11s%s\n", $k, $v);
    564528            }
    565             mail($_this->getParam('log_to_email_address'), $subject, $email_msg, $headers, '-f codebase@strangecode.com');
     529            mail($this->getParam('log_to_email_address'), $subject, $email_msg, $headers, '-f codebase@strangecode.com');
    566530        }
    567531
    568532        // SMS ACTION
    569         if ($_this->getParam('log_sms_priority') && $priority <= $_this->getParam('log_sms_priority')) {
     533        if ($this->getParam('log_sms_priority') && $priority <= $this->getParam('log_sms_priority')) {
    570534            $subject = sprintf('[%s %s]', getenv('HTTP_HOST'), $priority);
    571535            $sms_msg = sprintf('%s [%s:%s]', $event['message'], basename($file), $line);
    572536            $headers = "From: codebase@strangecode.com";
    573             mail($_this->getParam('log_to_sms_address'), $subject, $sms_msg, $headers, '-f codebase@strangecode.com');
     537            mail($this->getParam('log_to_sms_address'), $subject, $sms_msg, $headers, '-f codebase@strangecode.com');
    574538        }
    575539
    576540        // SCREEN ACTION
    577         if ($_this->getParam('log_screen_priority') && $priority <= $_this->getParam('log_screen_priority')) {
     541        if ($this->getParam('log_screen_priority') && $priority <= $this->getParam('log_screen_priority')) {
    578542            echo "[{$event['date']}] [{$event['type']}] [{$event['file:line']}] [{$event['message']}]\n";
    579543        }
     
    620584    function carryQuery($query_key)
    621585    {
    622         if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
    623             $_this =& App::getInstance();
    624         }
    625 
    626586        // If not already set, and there is a non-empty value provided in the request...
    627         if (!isset($_this->_carry_queries[$query_key]) && getFormData($query_key, false)) {
     587        if (!isset($this->_carry_queries[$query_key]) && getFormData($query_key, false)) {
    628588            // Copy the value of the specified query argument into the _carry_queries array.
    629             $_this->_carry_queries[$query_key] = getFormData($query_key);
     589            $this->_carry_queries[$query_key] = getFormData($query_key);
    630590        }
    631591    }
     
    652612    function url($url, $carry_args=null, $always_include_sid=false)
    653613    {
    654         if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
    655             $_this =& App::getInstance();
    656         }
    657 
    658         if (!$_this->running) {
    659             $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     614        if (!$this->running) {
     615            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
    660616            return false;
    661617        }
     
    691647        if ($do_carry_queries) {
    692648            // Join the global _carry_queries and local one_time_carry_queries.
    693             $query_args = urlEncodeArray(array_merge($_this->_carry_queries, $one_time_carry_queries));
     649            $query_args = urlEncodeArray(array_merge($this->_carry_queries, $one_time_carry_queries));
    694650            foreach ($query_args as $key=>$val) {
    695651                // Check value is set and value does not already exist in the url.
     
    715671                    (
    716672                        !isset($_COOKIE[session_name()])
    717                         || !$_this->getParam('session_use_cookies')
     673                        || !$this->getParam('session_use_cookies')
    718674                    )
    719                     && $_this->getParam('enable_session')
     675                    && $this->getParam('enable_session')
    720676                    && isMyDomain($url)
    721677                    &&
     
    748704    function oHREF($url, $carry_args=null, $always_include_sid=false)
    749705    {
    750         if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
    751             $_this =& App::getInstance();
    752         }
    753 
    754         $url = $_this->url($url, $carry_args, $always_include_sid);
     706        $url = $this->url($url, $carry_args, $always_include_sid);
    755707
    756708        // Replace any & not followed by an html or unicode entity with it's &amp; equivalent.
     
    772724    function printHiddenSession($carry_args=null)
    773725    {
    774         if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
    775             $_this =& App::getInstance();
    776         }
    777 
    778         if (!$_this->running) {
    779             $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     726        if (!$this->running) {
     727            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
    780728            return false;
    781729        }
     
    808756            // Join the global _carry_queries and local one_time_carry_queries.
    809757            // urlencode is not used here, not for form data!
    810             $query_args = array_merge($_this->_carry_queries, $one_time_carry_queries);
     758            $query_args = array_merge($this->_carry_queries, $one_time_carry_queries);
    811759            foreach ($query_args as $key=>$val) {
    812                 echo '<input type="hidden" name="' . $key . '" value="' . $val . '" />';
     760                printf('<input type="hidden" name="%s" value="%s" />', $key, $val);
    813761            }
    814762        }
     
    816764        // Include the SID if cookies are disabled.
    817765        if (!isset($_COOKIE[session_name()]) && !ini_get('session.use_trans_sid')) {
    818             echo '<input type="hidden" name="' . session_name() . '" value="' . session_id() . '" />';
     766            printf('<input type="hidden" name="%s" value="%s" />', session_name(), session_id());
    819767        }
    820768    }
     
    829777     *                                          or FALSE to prevent carrying queries. Can be any of the following formats:
    830778     *                                          -array('key1', key2', key3')  <-- to save these keys if in the form data.
    831      *                                          -array('key1'=>'value', key2'='value')  <-- to set keys to default values if not present in form data.
     779     *                                          -array('key1' => 'value', key2' => 'value')  <-- to set keys to default values if not present in form data.
    832780     *                                          -false  <-- To not carry any queries. If URL already has queries those will be retained.
    833781     * @param   bool    $always_include_sid     Force session id to be added to Location header.
     
    835783    function dieURL($url, $carry_args=null, $always_include_sid=false)
    836784    {
    837         if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
    838             $_this =& App::getInstance();
    839         }
    840 
    841         if (!$_this->running) {
    842             $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     785        if (!$this->running) {
     786            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
    843787            return false;
    844788        }
     
    846790        if ('' == $url) {
    847791            // If URL is not specified, use the redirect_home_url.
    848             $url = $_this->getParam('redirect_home_url');
     792            $url = $this->getParam('redirect_home_url');
    849793        }
    850794
     
    856800        }
    857801
    858         $url = $_this->url($url, $carry_args, $always_include_sid);
     802        $url = $this->url($url, $carry_args, $always_include_sid);
    859803
    860804        header(sprintf('Location: %s', $url));
    861         $_this->logMsg(sprintf('dieURL: %s', $url), LOG_DEBUG, __FILE__, __LINE__);
     805        $this->logMsg(sprintf('dieURL: %s', $url), LOG_DEBUG, __FILE__, __LINE__);
    862806
    863807        // End this application.
    864808        // Recommended, although I'm not sure it's necessary: http://cn2.php.net/session_write_close
    865         $_this->stop();
     809        $this->stop();
    866810        die;
    867811    }
     
    884828    function dieBoomerangURL($id=null, $carry_args=null, $default_url=null)
    885829    {
    886         if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
    887             $_this =& App::getInstance();
    888         }
    889 
    890         if (!$_this->running) {
    891             $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     830        if (!$this->running) {
     831            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
    892832            return false;
    893833        }
    894834
    895835        // Get URL from stored boomerang. Allow non specific URL if ID not valid.
    896         if ($_this->validBoomerangURL($id, true)) {
    897             if (isset($id) && isset($_SESSION[$_this->app]['boomerang']['url'][$id])) {
    898                 $url = $_SESSION[$_this->app]['boomerang']['url'][$id];
    899                 $_this->logMsg(sprintf('dieBoomerangURL(%s) found: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
     836        if ($this->validBoomerangURL($id, true)) {
     837            if (isset($id) && isset($_SESSION[$this->ns]['boomerang']['url'][$id])) {
     838                $url = $_SESSION[$this->ns]['boomerang']['url'][$id];
     839                $this->logMsg(sprintf('dieBoomerangURL(%s) found: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    900840            } else {
    901                 $url = end($_SESSION[$_this->app]['boomerang']['url']);
    902                 $_this->logMsg(sprintf('dieBoomerangURL(%s) using: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
     841                $url = end($_SESSION[$this->ns]['boomerang']['url']);
     842                $this->logMsg(sprintf('dieBoomerangURL(%s) using: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    903843            }
    904844            // Delete stored boomerang.
    905             $_this->deleteBoomerangURL($id);
     845            $this->deleteBoomerangURL($id);
    906846        } else if (isset($default_url)) {
    907847            $url = $default_url;
     
    909849            // Ensure that the redirecting page is not also the referrer.
    910850            $url = getenv('HTTP_REFERER');
    911             $_this->logMsg(sprintf('dieBoomerangURL(%s) using referrer: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
     851            $this->logMsg(sprintf('dieBoomerangURL(%s) using referrer: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    912852        } else {
    913853            // If URL is not specified, use the redirect_home_url.
    914             $url = $_this->getParam('redirect_home_url');
    915             $_this->logMsg(sprintf('dieBoomerangURL(%s) not found, using redirect_home_url: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
     854            $url = $this->getParam('redirect_home_url');
     855            $this->logMsg(sprintf('dieBoomerangURL(%s) not found, using redirect_home_url: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    916856        }
    917857
    918858        // A redirection will never happen immediately twice.
    919859        // Set the time so ensure this doesn't happen.
    920         $_SESSION[$_this->app]['boomerang']['time'] = time();
    921         $_this->dieURL($url, $carry_args);
     860        $_SESSION[$this->ns]['boomerang']['time'] = time();
     861        $this->dieURL($url, $carry_args);
    922862    }
    923863
     
    931871    function setBoomerangURL($url=null, $id=null)
    932872    {
    933         if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
    934             $_this =& App::getInstance();
    935         }
    936 
    937         if (!$_this->running) {
    938             $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     873        if (!$this->running) {
     874            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
    939875            return false;
    940876        }
     
    946882            $url = preg_replace('/boomerang=[\w]+/', '', $url);
    947883
    948             if (isset($_SESSION[$_this->app]['boomerang']['url']) && is_array($_SESSION[$_this->app]['boomerang']['url']) && !empty($_SESSION[$_this->app]['boomerang']['url'])) {
     884            if (isset($_SESSION[$this->ns]['boomerang']['url']) && is_array($_SESSION[$this->ns]['boomerang']['url']) && !empty($_SESSION[$this->ns]['boomerang']['url'])) {
    949885                // If the URL currently exists in the boomerang array, delete.
    950                 while ($existing_key = array_search($url, $_SESSION[$_this->app]['boomerang']['url'])) {
    951                     unset($_SESSION[$_this->app]['boomerang']['url'][$existing_key]);
     886                while ($existing_key = array_search($url, $_SESSION[$this->ns]['boomerang']['url'])) {
     887                    unset($_SESSION[$this->ns]['boomerang']['url'][$existing_key]);
    952888                }
    953889            }
    954890
    955891            if (isset($id)) {
    956                 $_SESSION[$_this->app]['boomerang']['url'][$id] = $url;
     892                $_SESSION[$this->ns]['boomerang']['url'][$id] = $url;
    957893            } else {
    958                 $_SESSION[$_this->app]['boomerang']['url'][] = $url;
    959             }
    960             $_this->logMsg(sprintf('setBoomerangURL(%s): %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
     894                $_SESSION[$this->ns]['boomerang']['url'][] = $url;
     895            }
     896            $this->logMsg(sprintf('setBoomerangURL(%s): %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    961897            return true;
    962898        } else {
    963             $_this->logMsg(sprintf('setBoomerangURL(%s) is empty!', $id, $url), LOG_NOTICE, __FILE__, __LINE__);
     899            $this->logMsg(sprintf('setBoomerangURL(%s) is empty!', $id, $url), LOG_NOTICE, __FILE__, __LINE__);
    964900            return false;
    965901        }
     
    973909    function getBoomerangURL($id=null)
    974910    {
    975         if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
    976             $_this =& App::getInstance();
    977         }
    978 
    979         if (!$_this->running) {
    980             $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
     911        if (!$this->running) {
     912            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
    981913            return false;
    982914        }
    983915
    984916        if (isset($id)) {
    985             if (isset($_SESSION[$_this->app]['boomerang']['url'][$id])) {
    986                 return $_SESSION[$_this->app]['boomerang']['url'][$id];
     917            if (isset($_SESSION[$this->ns]['boomerang']['url'][$id])) {
     918                return $_SESSION[$this->ns]['boomerang']['url'][$id];
    987919            } else {
    988920                return '';
    989921            }
    990         } else if (is_array($_SESSION[$_this->app]['boomerang']['url'])) {
    991             return end($_SESSION[$_this->app]['boomerang']['url']);
     922        } else if (is_array($_SESSION[$this->ns]['boomerang']['url'])) {
     923            return end($_SESSION[$this->ns]['boomerang']['url']);
    992924        } else {
    993925            return false;
     
    1002934    function deleteBoomerangURL($id=null)
    1003935    {
    1004         if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
    1005             $_this =& App::getInstance();
    1006         }
    1007 
    1008         if (!$_this->running) {
    1009             $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
    1010             return false;
    1011         }
    1012 
    1013         $_this->logMsg(sprintf('deleteBoomerangURL(%s): %s', $id, $_this->getBoomerangURL($id)), LOG_DEBUG, __FILE__, __LINE__);
    1014 
    1015         if (isset($id) && isset($_SESSION[$_this->app]['boomerang']['url'][$id])) {
    1016             unset($_SESSION[$_this->app]['boomerang']['url'][$id]);
    1017         } else if (is_array($_SESSION[$_this->app]['boomerang']['url'])) {
    1018             array_pop($_SESSION[$_this->app]['boomerang']['url']);
     936        if (!$this->running) {
     937            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
     938            return false;
     939        }
     940
     941        $this->logMsg(sprintf('deleteBoomerangURL(%s): %s', $id, $this->getBoomerangURL($id)), LOG_DEBUG, __FILE__, __LINE__);
     942
     943        if (isset($id) && isset($_SESSION[$this->ns]['boomerang']['url'][$id])) {
     944            unset($_SESSION[$this->ns]['boomerang']['url'][$id]);
     945        } else if (is_array($_SESSION[$this->ns]['boomerang']['url'])) {
     946            array_pop($_SESSION[$this->ns]['boomerang']['url']);
    1019947        }
    1020948    }
     
    1028956    function validBoomerangURL($id=null, $use_nonspecificboomerang=false)
    1029957    {
    1030         if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
    1031             $_this =& App::getInstance();
    1032         }
    1033 
    1034         if (!$_this->running) {
    1035             $_this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_DEBUG, __FILE__, __LINE__);
    1036             return false;
    1037         }
    1038 
    1039         if (!isset($_SESSION[$_this->app]['boomerang']['url'])) {
    1040             $_this->logMsg(sprintf('validBoomerangURL(%s) no boomerang URL set.', $id), LOG_DEBUG, __FILE__, __LINE__);
     958        if (!$this->running) {
     959            $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__);
     960            return false;
     961        }
     962
     963        if (!isset($_SESSION[$this->ns]['boomerang']['url'])) {
     964            $this->logMsg(sprintf('validBoomerangURL(%s) no boomerang URL set.', $id), LOG_DEBUG, __FILE__, __LINE__);
    1041965            return false;
    1042966        }
     
    1045969        // a boomerang redirection will always occur at least several seconds after the last boomerang redirect
    1046970        // or a boomerang being set.
    1047         $boomerang_time = isset($_SESSION[$_this->app]['boomerang']['time']) ? $_SESSION[$_this->app]['boomerang']['time'] : 0;
     971        $boomerang_time = isset($_SESSION[$this->ns]['boomerang']['time']) ? $_SESSION[$this->ns]['boomerang']['time'] : 0;
    1048972
    1049973        $url = '';
    1050         if (isset($id) && isset($_SESSION[$_this->app]['boomerang']['url'][$id])) {
    1051             $url = $_SESSION[$_this->app]['boomerang']['url'][$id];
     974        if (isset($id) && isset($_SESSION[$this->ns]['boomerang']['url'][$id])) {
     975            $url = $_SESSION[$this->ns]['boomerang']['url'][$id];
    1052976        } else if (!isset($id) || $use_nonspecificboomerang) {
    1053977            // Use non specific boomerang if available.
    1054             $url = end($_SESSION[$_this->app]['boomerang']['url']);
    1055         }
    1056 
    1057         $_this->logMsg(sprintf('validBoomerangURL(%s) testing: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
     978            $url = end($_SESSION[$this->ns]['boomerang']['url']);
     979        }
     980
     981        $this->logMsg(sprintf('validBoomerangURL(%s) testing: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    1058982
    1059983        if ('' == $url) {
    1060             $_this->logMsg(sprintf('validBoomerangURL(%s) not valid, empty!', $id), LOG_DEBUG, __FILE__, __LINE__);
     984            $this->logMsg(sprintf('validBoomerangURL(%s) not valid, empty!', $id), LOG_DEBUG, __FILE__, __LINE__);
    1061985            return false;
    1062986        }
    1063987        if ($url == absoluteMe()) {
    1064988            // The URL we are directing to is the current page.
    1065             $_this->logMsg(sprintf('validBoomerangURL(%s) not valid, same as absoluteMe: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
     989            $this->logMsg(sprintf('validBoomerangURL(%s) not valid, same as absoluteMe: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    1066990            return false;
    1067991        }
    1068992        if ($boomerang_time >= (time() - 2)) {
    1069993            // Last boomerang direction was more than 2 seconds ago.
    1070             $_this->logMsg(sprintf('validBoomerangURL(%s) not valid, boomerang_time too short: %s', $id, time() - $boomerang_time), LOG_DEBUG, __FILE__, __LINE__);
    1071             return false;
    1072         }
    1073 
    1074         $_this->logMsg(sprintf('validBoomerangURL(%s) is valid: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
     994            $this->logMsg(sprintf('validBoomerangURL(%s) not valid, boomerang_time too short: %s', $id, time() - $boomerang_time), LOG_DEBUG, __FILE__, __LINE__);
     995            return false;
     996        }
     997
     998        $this->logMsg(sprintf('validBoomerangURL(%s) is valid: %s', $id, $url), LOG_DEBUG, __FILE__, __LINE__);
    1075999        return true;
    10761000    }
     
    10821006    function sslOn()
    10831007    {
    1084         if (!isset($_this) || !is_a($_this, 'App') && !is_subclass_of($_this, 'App')) {
    1085             $_this =& App::getInstance();
    1086         }
    1087 
    10881008        if (function_exists('apache_get_modules')) {
    10891009            $modules = apache_get_modules();
     
    10931013        }
    10941014
    1095         if ('' == getenv('HTTPS') && $_this->getParam('ssl_enabled') && in_array('mod_ssl', $modules)) {
    1096             $_this->raiseMsg(sprintf(_("Secure SSL connection made to %s"), $_this->getParam('ssl_domain')), MSG_NOTICE, __FILE__, __LINE__);
     1015        if ('' == getenv('HTTPS') && $this->getParam('ssl_enabled') && in_array('mod_ssl', $modules)) {
     1016            $this->raiseMsg(sprintf(_("Secure SSL connection made to %s"), $this->getParam('ssl_domain')), MSG_NOTICE, __FILE__, __LINE__);
    10971017            // Always append session because some browsers do not send cookie when crossing to SSL URL.
    1098             $_this->dieURL('https://' . $_this->getParam('ssl_domain') . getenv('REQUEST_URI'), null, true);
     1018            $this->dieURL('https://' . $this->getParam('ssl_domain') . getenv('REQUEST_URI'), null, true);
    10991019        }
    11001020    }
  • branches/2.0singleton/lib/Auth_File.inc.php

    r127 r135  
    11<?php
    22/**
     3 * Auth_File.inc.php
     4 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
     5 *
    36 * The Auth_File:: class provides a htpasswd file implementation for
    47 * authentication.
     
    100103            return $this->_params[$param];
    101104        } else {
    102             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
     105            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
    103106            return null;
    104107        }
  • branches/2.0singleton/lib/Auth_SQL.inc.php

    r130 r135  
    239239            return $this->_params[$param];
    240240        } else {
    241             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
     241            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
    242242            return null;
    243243        }
  • branches/2.0singleton/lib/AuthorizeNet.inc.php

    r127 r135  
    11<?php
     2/**
     3 * AuthorizeNet.inc.php
     4 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
     5 *
     6 * The AuthorizeNet class provides an abstract interface for communicating
     7 * with authorize.net's AIM interface. Supports Auth.Net v3.1
     8 *
     9 * @author  Quinn Comendant <quinn@strangecode.com>
     10 * @version 1.0
     11 * @date 2004-04-06
     12 */
     13 
    214// Example usage
    315// require_once 'codebase/lib/AuthorizeNet.inc.php';
     
    1426//     'x_Exp_Date' => '042008',
    1527//     'x_Invoice_Num' => '100',
    16 //     'x_Address' => '10 rue LevouvŽ',
     28//     'x_Address' => '10 rue Levouvé',
    1729//     'x_City' => 'SomeCity',
    1830//     'x_State' => 'CA',
     
    2739// }
    2840
    29 /**
    30  * The AuthorizeNet class provides an abstract interface for communicating
    31  * with authorize.net's AIM interface. Supports Auth.Net v3.1
    32  *
    33  * @author  Quinn Comendant <quinn@strangecode.com>
    34  * @version 1.0
    35  * @date 2004-04-06
    36  */
    37 
    38 require_once dirname(__FILE__) . '/Utilities.inc.php';
    39 
    40 class AuthorizeNet
    41 {
     41class AuthorizeNet {
     42
    4243    var $post_url = ''; // The URL to post data to.
    4344    var $md5_hash_value = ','; // A custom value for the response delimination character.
     
    156157            return $this->_params[$param];
    157158        } else {
    158             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
     159            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
    159160            return null;
    160161        }
  • branches/2.0singleton/lib/CSS.inc.php

    r127 r135  
    5252            return $this->_params[$param];
    5353        } else {
    54             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
     54            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
    5555            return null;
    5656        }
  • branches/2.0singleton/lib/DB.inc.php

    r127 r135  
    44 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
    55 *
    6  * DB abstraction layer.
     6 * Very lightweight DB semi-abstraction layer. Mainly to catch errors with mysql_query, with some goodies.
    77 *
    88 * @author  Quinn Comendant <quinn@strangecode.com>
    9  * @version 1.0.1
     9 * @version 2.1
    1010 */
    1111
    1212class DB {
    1313
    14     // If DB::connect has successfully opened a db connection.
     14    // If $db->connect has successfully opened a db connection.
    1515    var $_connected = false;
    1616
    17     // Database handler.
     17    // Database handle.
    1818    var $dbh;
    1919
     
    3030        'db_pass' => null,
    3131
    32         // Debugging.
    33         'db_always_debug' => false, // TRUE = display all SQL queries.
    34         'db_debug' => false, // TRUE = display db errors.
    35         'db_die_on_failure' => false, // TRUE = script stops on db error.
     32        // Display all SQL queries.
     33        'db_always_debug' => false,
     34
     35        // Display db errors.
     36        'db_debug' => false,
     37       
     38        // Script stops on db error.
     39        'db_die_on_failure' => false,
    3640    );
    3741
     
    4953     * This method enforces the singleton pattern for this class.
    5054     *
    51      * @return  object  Reference to the global SessionCache object.
     55     * @return  object  Reference to the global DB object.
    5256     * @access  public
    5357     * @static
     
    6569
    6670    /**
    67      * Constructor.
    68      */
    69     function DB()
    70     {
    71         // Initialize default params.
     71     * Set (or overwrite existing) parameters by passing an array of new parameters.
     72     *
     73     * @access public
     74     *
     75     * @param  array    $params     Array of parameters (key => val pairs).
     76     */
     77    function setParam($params)
     78    {
     79        $app =& App::getInstance();
     80   
    7281        if (isset($params) && is_array($params)) {
    7382            // Merge new parameters with old overriding only those passed.
    7483            $this->_params = array_merge($this->_params, $params);
    75         }
    76     }
    77 
    78     /**
    79      * Set (or overwrite existing) parameters by passing an array of new parameters.
    80      *
    81      * @access public
    82      *
    83      * @param  array    $params     Array of parameters (key => val pairs).
    84      */
    85     function setParam($params)
    86     {
    87         $app =& App::getInstance();
    88    
    89         if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
    90             $_this =& DB::getInstance();
    91         }
    92 
    93         if (isset($params) && is_array($params)) {
    94             // Merge new parameters with old overriding only those passed.
    95             $_this->_params = array_merge($_this->_params, $params);
    9684        } else {
    9785            $app->logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__);
     
    10088
    10189    /**
    102      * Return the value of a parameter.
    103      *
    104      * @access  public
    105      *
    106      * @param   string  $param      The key of the parameter to return.
    107      *
    108      * @return  mixed               Parameter value.
     90     * Return the value of a parameter, if it exists.
     91     *
     92     * @access public
     93     * @param string $param        Which parameter to return.
     94     * @return mixed               Configured parameter value.
    10995     */
    11096    function getParam($param)
     
    11298        $app =& App::getInstance();
    11399   
    114         if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
    115             $_this =& DB::getInstance();
    116         }
    117 
    118         if (isset($_this->_params[$param])) {
    119             return $_this->_params[$param];
     100        if (isset($this->_params[$param])) {
     101            return $this->_params[$param];
    120102        } else {
    121             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
     103            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
    122104            return null;
    123105        }
     
    135117        $app =& App::getInstance();
    136118   
    137         if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
    138             $_this =& DB::getInstance();
    139         }
    140 
    141         if (!$_this->getParam('db_name') || !$_this->getParam('db_user') || !$_this->getParam('db_pass')) {
     119        if (!$this->getParam('db_name') || !$this->getParam('db_user') || !$this->getParam('db_pass')) {
    142120            $app->logMsg('Database credentials missing.', LOG_EMERG, __FILE__, __LINE__);
    143121            return false;
     
    145123
    146124        // Connect to database. Always create a new link to the server.
    147         if ($_this->dbh = mysql_connect($_this->getParam('db_server'), $_this->getParam('db_user'), $_this->getParam('db_pass'), true)) {
     125        if ($this->dbh = mysql_connect($this->getParam('db_server'), $this->getParam('db_user'), $this->getParam('db_pass'), true)) {
    148126            // Select database
    149             mysql_select_db($_this->getParam('db_name'), $_this->dbh);
     127            mysql_select_db($this->getParam('db_name'), $this->dbh);
    150128        }
    151129
    152130        // Test for connection errors.
    153         if (!$_this->dbh || mysql_error($_this->dbh)) {
    154             $mysql_error_msg = $_this->dbh ? 'Codebase MySQL error: (' . mysql_errno($_this->dbh) . ') ' . mysql_error($_this->dbh) : 'Codebase MySQL error: Could not connect to server.';
     131        if (!$this->dbh || mysql_error($this->dbh)) {
     132            $mysql_error_msg = $this->dbh ? 'Codebase MySQL error: (' . mysql_errno($this->dbh) . ') ' . mysql_error($this->dbh) : 'Codebase MySQL error: Could not connect to server.';
    155133            $app->logMsg($mysql_error_msg, LOG_EMERG, __FILE__, __LINE__);
    156134
    157135            // Print helpful or pretty error?
    158             if ($_this->getParam('db_debug')) {
     136            if ($this->getParam('db_debug')) {
    159137                echo $mysql_error_msg . "\n";
    160             } else {
    161                 echo _("This page is temporarily unavailable. It should be back up in a few minutes.");
    162138            }
    163139
    164140            // Die or continue without connection?
    165             if ($_this->getParam('db_die_on_failure')) {
     141            if ($this->getParam('db_die_on_failure')) {
    166142                echo "\n\n<!-- Script execution stopped out of embarrassment. -->";
    167143                die;
     
    172148
    173149        // DB connection success!
    174         $_this->_connected = true;
     150        $this->_connected = true;
    175151
    176152        // Tell MySQL what character set we're useing. Available only on MySQL verions > 4.01.01.
    177         $_this->query("/*!40101 SET NAMES '" . $_this->mysql_character_sets[strtolower($app->getParam('character_set'))] . "' */");
     153        $this->query("/*!40101 SET NAMES '" . $this->mysql_character_sets[strtolower($app->getParam('character_set'))] . "' */");
    178154
    179155        return true;
     
    189165    function close()
    190166    {
    191         if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
    192             $_this =& DB::getInstance();
    193         }
    194 
    195         if (!$_this->_connected) {
    196             return false;
    197         }
    198 
    199         mysql_close($_this->dbh);
     167        if (!$this->_connected) {
     168            return false;
     169        }
     170
     171        return mysql_close($this->dbh);
    200172    }
    201173
     
    210182    function getDBH()
    211183    {
    212         if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
    213             $_this =& DB::getInstance();
    214         }
    215 
    216         if (!$_this->_connected) {
    217             return false;
    218         }
    219 
    220         return $_this->dbh;
     184        if (!$this->_connected) {
     185            return false;
     186        }
     187
     188        return $this->dbh;
    221189    }
    222190
     
    244212    function escapeString($string)
    245213    {
    246         if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
    247             $_this =& DB::getInstance();
    248         }
    249         return mysql_real_escape_string($string, $_this->dbh);
     214        return mysql_real_escape_string($string, $this->dbh);
    250215    }
    251216
     
    264229        static $_query_count = 0;
    265230
    266         if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
    267             $_this =& DB::getInstance();
    268         }
    269 
    270         if (!$_this->_connected) {
     231        if (!$this->_connected) {
    271232           return false;
    272233        }
     
    274235        $_query_count++;
    275236        $debugqry = preg_replace("/\n[\t ]+/", "\n", $query);
    276         if ($_this->getParam('db_always_debug') || $debug) {
     237        if ($this->getParam('db_always_debug') || $debug) {
    277238            echo "<!-- ----------------- Query $_query_count ---------------------\n$debugqry\n-->\n";
    278239        }
    279240
    280241        // Execute!
    281         $qid = mysql_query($query, $_this->dbh);
     242        $qid = mysql_query($query, $this->dbh);
    282243
    283244        // Error checking.
    284         if (!$qid || mysql_error($_this->dbh)) {
    285             if ($_this->getParam('db_debug')) {
    286                 echo '<pre style="padding:2em; background:#ddd; font:9px monaco;">' . wordwrap(mysql_error($_this->dbh)) . '<hr>' . htmlspecialchars($debugqry) . '</pre>';
     245        if (!$qid || mysql_error($this->dbh)) {
     246            if ($this->getParam('db_debug')) {
     247                echo '<pre style="padding:2em; background:#ddd; font:9px monaco;">' . wordwrap(mysql_error($this->dbh)) . '<hr>' . htmlspecialchars($debugqry) . '</pre>';
    287248            } else {
    288249                echo _("This page is temporarily unavailable. It should be back up in a few minutes.");
    289250            }
    290             $app->logMsg(sprintf('MySQL error %s: %s in query: %s', mysql_errno($_this->dbh), mysql_error($_this->dbh), $debugqry), LOG_EMERG, __FILE__, __LINE__);
    291             if ($_this->getParam('db_die_on_failure')) {
     251            $app->logMsg(sprintf('MySQL error %s: %s in query: %s', mysql_errno($this->dbh), mysql_error($this->dbh), $debugqry), LOG_EMERG, __FILE__, __LINE__);
     252            if ($this->getParam('db_die_on_failure')) {
    292253                echo "\n\n<!-- Script execution stopped out of embarrassment. -->";
    293254                die;
     
    312273        $app =& App::getInstance();
    313274   
    314         if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
    315             $_this =& DB::getInstance();
    316         }
    317 
    318         if (!$_this->_connected) {
    319             return false;
    320         }
    321 
    322         if (!isset($_this->existing_tables) || !$use_cached_results) {
    323             $_this->existing_tables = array();
    324             $qid = $_this->query("SHOW TABLES");
     275        if (!$this->_connected) {
     276            return false;
     277        }
     278
     279        if (!isset($this->existing_tables) || !$use_cached_results) {
     280            $this->existing_tables = array();
     281            $qid = $this->query("SHOW TABLES");
    325282            while (list($row) = mysql_fetch_row($qid)) {
    326                 $_this->existing_tables[] = $row;
    327             }
    328         }
    329         if (in_array($table, $_this->existing_tables)) {
     283                $this->existing_tables[] = $row;
     284            }
     285        }
     286        if (in_array($table, $this->existing_tables)) {
    330287            return true;
    331288        } else {
    332             $app->logMsg(sprintf('nonexistent DB table: %s.%s', $_this->getParam('db_name'), $table), LOG_ALERT, __FILE__, __LINE__);
     289            $app->logMsg(sprintf('nonexistent DB table: %s.%s', $this->getParam('db_name'), $table), LOG_ALERT, __FILE__, __LINE__);
    333290            return false;
    334291        }
     
    346303    function columnExists($table, $columns, $strict=true, $use_cached_results=true)
    347304    {
    348         if (!isset($_this) || !is_a($_this, 'DB') && !is_subclass_of($_this, 'DB')) {
    349             $_this =& DB::getInstance();
    350         }
    351 
    352         if (!$_this->_connected) {
     305        if (!$this->_connected) {
    353306            return false;
    354307        }
    355308
    356309        // Ensure the table exists.
    357         if (!$_this->tableExists($table, $use_cached_results)) {
     310        if (!$this->tableExists($table, $use_cached_results)) {
    358311            return false;
    359312        }
     
    364317        }
    365318
    366         if (!isset($_this->table_columns[$table]) || !$use_cached_results) {
     319        if (!isset($this->table_columns[$table]) || !$use_cached_results) {
    367320            // Populate and cache array of current columns for this table.
    368             $_this->table_columns[$table] = array();
    369             $qid = $_this->query("DESCRIBE $table");
     321            $this->table_columns[$table] = array();
     322            $qid = $this->query("DESCRIBE $table");
    370323            while ($row = mysql_fetch_row($qid)) {
    371                 $_this->table_columns[$table][] = $row[0];
     324                $this->table_columns[$table][] = $row[0];
    372325            }
    373326        }
     
    376329            // Do an exact comparison of table schemas.
    377330            sort($columns);
    378             sort($_this->table_columns[$table]);
    379             return $_this->table_columns[$table] == $columns;
     331            sort($this->table_columns[$table]);
     332            return $this->table_columns[$table] == $columns;
    380333        } else {
    381334            // Only check that the specified columns are available in the table.
    382             $match_columns = array_intersect($_this->table_columns[$table], $columns);
     335            $match_columns = array_intersect($this->table_columns[$table], $columns);
    383336            sort($columns);
    384337            sort($match_columns);
  • branches/2.0singleton/lib/DBSessionHandler.inc.php

    r127 r135  
    33 * DBSessionHandler.inc.php
    44 * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information.
     5 *
    56 * @author  Quinn Comendant <quinn@strangecode.com>
    6  * @version 1.3
     7 * @version 2.1
    78 * @since   1999
    89 */
     
    1314
    1415    var $_params = array(
    15         'db_server' => 'localhost',
    16         'db_name' => '',
    17         'db_user' => '',
    18         'db_pass' => '',
    1916        'db_table' => 'session_tbl',
    2017        'create_table' => true, // Automatically create table and verify columns. Better set to false after site launch.
     
    3027     * @since   18 Jul 2005 11:02:50
    3128     */
    32     function DBSessionHandler($db=null, $params=array())
     29    function DBSessionHandler($db, $params=array())
    3330    {
    3431        $app =& App::getInstance();
     
    3633        $this->_params = array_merge($this->_params, $params);
    3734
    38         if (isset($db)) {
    39             if (is_a($db, 'DB')) {
    40                 if ($db->isConnected()) {
    41                     // Use existing db connection.
    42                     $this->db =& $db;
    43                 } else {
    44                     $app->logMsg(sprintf('Provided DB object is not connected. %s', mysql_error($db->dbh)), LOG_ERR, __FILE__, __LINE__);
     35        if (!method_exists($db, 'isConnected')) {
     36            $app->logMsg(sprintf('Provided object (%s) is not a valid DB object.', get_class($db)), LOG_ERR, __FILE__, __LINE__);
     37        } else {
     38            if (!$db->isConnected()) {
     39                $app->logMsg('Provided DB object is not connected.', LOG_ERR, __FILE__, __LINE__);
     40            } else {
     41                // OK! We have a valid, connected DB object.
     42                $this->db =& $db;
     43
     44                // Get create tables config from global context.
     45                if (!is_null($app->getParam('db_create_tables'))) {
     46                    $this->_params['create_table'] = $app->getParam('db_create_tables');
    4547                }
    46             } else {
    47                 $app->logMsg(sprintf('Provided DB object is not valid. %s', gettype($db)), LOG_ERR, __FILE__, __LINE__);
     48
     49                // Ensure db table is fit.
     50                $this->initDB();
     51
     52                ini_set('session.save_handler', 'user');
     53                session_set_save_handler(
     54                    array(&$this, 'dbSessionOpen'),
     55                    array(&$this, 'dbSessionClose'),
     56                    array(&$this, 'dbSessionRead'),
     57                    array(&$this, 'dbSessionWrite'),
     58                    array(&$this, 'dbSessionDestroy'),
     59                    array(&$this, 'dbSessionGarbage')
     60                );
    4861            }
    49         } else {
    50             // Create our own new db connection.
    51             require_once dirname(__FILE__) . '/DB.inc.php';
    52 
    53             $this->db =& new DB();
    54             $this->db->setParam(array(
    55                 'db_server' => $this->_params['db_server'],
    56                 'db_name' => $this->_params['db_name'],
    57                 'db_user' => $this->_params['db_user'],
    58                 'db_pass' => $this->_params['db_pass'],
    59                 'db_always_debug' => $this->_params['db_always_debug'],
    60                 'db_debug' => $this->_params['db_debug'],
    61                 'db_die_on_failure' => $this->_params['db_die_on_failure'],
    62             ));
    63 
    64             // Connect to database.
    65             $this->db->connect();
    6662        }
    67 
    68         if (!isset($this) || !is_a($this->db, 'DB') || !$this->db->isConnected()) {
    69             trigger_error('Invalid DB object or unable to connect to database.', E_USER_ERROR);
    70         }
    71 
    72         // Get create tables config from global context.
    73         if (!is_null($app->getParam('db_create_tables'))) {
    74             $this->_params['create_table'] = $app->getParam('db_create_tables');
    75         }
    76 
    77         // Ensure db table is fit.
    78         $this->initDB();
    79 
    80         ini_set('session.save_handler', 'user');
    81         session_set_save_handler(
    82             array(&$this, 'dbSessionOpen'),
    83             array(&$this, 'dbSessionClose'),
    84             array(&$this, 'dbSessionRead'),
    85             array(&$this, 'dbSessionWrite'),
    86             array(&$this, 'dbSessionDestroy'),
    87             array(&$this, 'dbSessionGarbage')
    88         );
    8963    }
    9064
  • branches/2.0singleton/lib/Email.inc.php

    r127 r135  
    88 * @author  Quinn Comendant <quinn@strangecode.com>
    99 * @version 1.0
    10 -------------------------------------------------------------------------------------
     10 *
     11 
    1112// Example.
    1213$email = new Email(array(
     
    2829    $app->logMsg(sprintf('Error sending confirmation email to address %s', $frm['email']), LOG_NOTICE, __FILE__, __LINE__);
    2930}
    30 -------------------------------------------------------------------------------------
     31
     32 *
    3133 */
    3234class Email {
  • branches/2.0singleton/lib/FormValidator.inc.php

    r127 r135  
    2323 * $fv->validatePhone('phone1');
    2424 */
    25 class FormValidator
    26 {
     25class FormValidator {
    2726
    2827    // Array filling with error messages.
  • branches/2.0singleton/lib/Google_API.inc.php

    r42 r135  
    11<?php
    22/**
     3 * Google_API.inc.php
     4 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
     5 *
    36 * Interface to the Google API using SOAP/Client.php.
    47 *
     
    2528require_once 'SOAP/Client.php';
    2629
    27 
    28 /**
    29 * PHP Interface to the Google API
    30 *
    31 * @author  Sebastian Bergmann <sb@sebastian-bergmann.de>
    32 * @access  public
    33 */
    34 class Google_API
    35 {
     30class Google_API {
    3631
    3732    /**
  • branches/2.0singleton/lib/Hierarchy.inc.php

    r130 r135  
    22/**
    33 * Hierarchy.inc.php
    4  * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
    5  */
    6 
    7 /**
     4 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
     5 *
    86 * Objective: This class provides the tools to organize pieces of data into a
    97 * hierarchy of nodes. Any form of data (article, product, image) can be
  • branches/2.0singleton/lib/Image.inc.php

    r121 r135  
    22/**
    33 * Image.inc.php
    4  * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information.
     4 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
     5 *
    56 * @author  Quinn Comendant <quinn@strangecode.com>
    67 * @version 1.1
  • branches/2.0singleton/lib/ImageThumb.inc.php

    r128 r135  
    22/**
    33 * ImageThumb.inc.php
    4  * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
     4 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
    55 *
    66 * @author   Quinn Comendant <quinn@strangecode.com>
     
    131131    {
    132132        $app =& App::getInstance();
    133 
     133   
    134134        if (isset($this->_params[$param])) {
    135135            return $this->_params[$param];
    136136        } else {
    137             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
     137            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
    138138            return null;
    139139        }
  • branches/2.0singleton/lib/MCVE.inc.php

    r128 r135  
    11<?php
    22/**
     3 * MCVE.inc.php
     4 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
     5 *
    36 * The MCVE:: class provides functions for communicating with a MCVE server.
    47 *
  • branches/2.0singleton/lib/Nav.inc.php

    r128 r135  
    11<?php
    22/**
     3 * Nav.inc.php
     4 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
     5 *
    36 * The Nav:: class provides a system for working with navigation elements.
    47 * Currently it supports storing page titles and URLs for printing breadcrumbs
  • branches/2.0singleton/lib/PEdit.inc.php

    r128 r135  
    11<?php
    22/**
     3 * PEdit.inc.php
     4 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
     5 *
    36 * PEdit:: provides a mechanism to store text in php variables
    47 * which will be printed to the client browser under normal
     
    1114 * To use, include this file, initialize variables,
    1215 * and call printing/editing functions where you want data and forms to
    13  * show up. Below is an example of use:
     16 * show up.
     17 *
     18 * @author  Quinn Comendant <quinn@strangecode.com>
     19 * @concept Beau Smith <beau@beausmith.com>
     20 * @version 2.0
     21 *
     22 * Example of use:
    1423 
    1524 // Initialize PEdit object.
     
    3746 $pedit->formEnd();
    3847
    39  * @author  Quinn Comendant <quinn@strangecode.com>
    40  * @concept Beau Smith <beau@beausmith.com>
    41  * @version 2.0
    4248 */
    4349class PEdit {
     
    115121    {
    116122        $app =& App::getInstance();
    117 
     123   
    118124        if (isset($this->_params[$param])) {
    119125            return $this->_params[$param];
  • branches/2.0singleton/lib/PageNumbers.inc.php

    r132 r135  
    8181            $this->_per_page = $per_page;
    8282            if ($save_value) {
    83                 $prefs->setValue('items_per_page', $this->_per_page, $_SERVER['PHP_SELF']);
     83                $prefs->set('items_per_page', $this->_per_page, $_SERVER['PHP_SELF']);
    8484            }
    8585        } else if ($save_value && $prefs->exists('items_per_page', $_SERVER['PHP_SELF'])) {
    86             $this->_per_page = (int)$prefs->getValue('items_per_page', $_SERVER['PHP_SELF']);
     86            $this->_per_page = (int)$prefs->get('items_per_page', $_SERVER['PHP_SELF']);
    8787        } else if (is_numeric($default) && $default > 0) {
    8888            $this->_per_page = $default;
     
    109109            }
    110110            if ($save_value) {
    111                 $prefs->setValue('page_number', $this->current_page, $_SERVER['PHP_SELF']);
     111                $prefs->set('page_number', $this->current_page, $_SERVER['PHP_SELF']);
    112112            }
    113113        } else if ($save_value && $prefs->exists('page_number', $_SERVER['PHP_SELF'])) {
    114             $this->current_page = (int)$prefs->getValue('page_number', $_SERVER['PHP_SELF']);
     114            $this->current_page = (int)$prefs->get('page_number', $_SERVER['PHP_SELF']);
    115115        }
    116116        $this->set_page_number_initialized = true;
  • branches/2.0singleton/lib/PayPal.inc.php

    r128 r135  
    11<?php
    22/**
     3 * PayPal.inc.php
     4 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
     5 *
    36 * The PayPal:: class provides functions for creating PayPal buttons and for
    47 * receiving PayPal's Instant Payment Notification (IPN) service.
     
    233236    {
    234237        $app =& App::getInstance();
    235 
     238   
    236239        if (isset($this->_params[$param])) {
    237240            return $this->_params[$param];
    238241        } else {
    239             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
     242            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
    240243            return null;
    241244        }
  • branches/2.0singleton/lib/Prefs.inc.php

    r128 r135  
    11<?php
    22/**
     3 * Prefs.inc.php
     4 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
     5 *
    36 * Prefs:: provides an API for saving arbitrary values in a user's session.
    4  * Database save routines to come.
    57 *
    6  * @inspiration  Horde 2.0's Prefs class. This one is much simpler, but
    7  *               the API for the methods that exist are sort of like Horde's
    8  *               in case we want to be more like it in the future.
    98 * @author  Quinn Comendant <quinn@strangecode.com>
    10  * @version 1.1
     9 * @version 2.1
    1110 */
    1211class Prefs {
    1312
    14     /**
    15      * Where these preferences can be used. To differentiate between preferences
    16      * for a specific script, application, or global.
    17      * @var string $scope
    18      */
    19     var $scope = 'global';
    20 
    21     /**
    22      * Indicator whether we save in the database or not.
    23      * @var boolean $_perpetual
    24      */
    25     var $_perpetual = false;
    26 
    27     /**
    28      * Hash containing connection parameters.
    29      * @var array $params
    30      */
    31     var $params = array();
    32 
     13    // Namespace of preferences.
     14    var $ns;
    3315
    3416    /**
    3517     * Prefs constructor.
    3618     */
    37     function Prefs($dbh=false, $params=array())
     19    function Prefs($ns='')
    3820    {
    39         $this->params = $params;
    40         $_perpetual = false; // Until database routines are completed.
     21        $this->ns = '_pref_' . $ns;
     22       
     23        // Initialized the prefs array.
     24        if (!isset($_SESSION[$this->ns])) {
     25            $_SESSION[$this->ns] = array();
     26        }
    4127    }
    4228
     
    4531     * is not set already.
    4632     *
    47      * @param  string $pref      The name of the preference to modify.
     33     * @param  string $key       The name of the preference to modify.
    4834     * @param  string $val       The new value for this preference.
    49      * @param  string $scope     The scope for this preference.
    50      *
    51      * @return boolean  True if the value was successfully set.
    5235     */
    53     function setDefault($pref, $val, $scope=null)
     36    function default($key, $val)
    5437    {
    55         if (!isset($scope)) {
    56             $scope =& $this->scope;
    57         }
    58 
    59         // No empty values allowed.
    60         if ('' == $pref || '' == $val || '' == $scope) {
    61             return false;
    62         }
    63 
    64         // Initialized the prefs array.
    65         if (!isset($_SESSION['_prefs'])) {
    66             $_SESSION['_prefs'] = array();
    67         }
    68 
    69         // In case boolean or null values are passed as a string.
    70         if ($val == 'true') {
    71             $val = true;
    72         } else if ($val == 'false') {
    73             $val = false;
    74         } else if ($val == 'null') {
    75             $val = null;
    76         }
    77 
    7838        // Set it only if not set already.
    79         if (!isset($_SESSION['_prefs'][$scope][$pref])) {
    80             $_SESSION['_prefs'][$scope][$pref] = $val;
    81             return true;
     39        if (!isset($_SESSION[$this->ns][$key])) {
     40            $_SESSION[$this->ns][$key] = $val;
    8241        }
    8342    }
     
    8645     * Sets the given preferences to the specific value,
    8746     *
    88      * @param  string $pref      The name of the preference to modify.
     47     * @param  string $key       The name of the preference to modify.
    8948     * @param  string $val       The new value for this preference.
    90      * @param  string $scope     The scope for this preference.
    91      *
    92      * @return boolean  True if the value was successfully set.
    9349     */
    94     function setValue($pref, $val, $scope=null)
     50    function set($key, $val)
    9551    {
    96         if (!isset($scope)) {
    97             $scope =& $this->scope;
    98         }
    99 
    100         // No empty values allowed.
    101         if ('' == $pref || '' == $val || '' == $scope) {
    102             return false;
    103         }
    104 
    105         // Initialized the prefs array.
    106         if (!isset($_SESSION['_prefs'])) {
    107             $_SESSION['_prefs'] = array();
    108         }
    109 
    110         // In case boolean or null values are passed as a string.
    111         if ($val == 'true') {
    112             $val = true;
    113         } else if ($val == 'false') {
    114             $val = false;
    115         } else if ($val == 'null') {
    116             $val = null;
    117         }
    118 
    119         $_SESSION['_prefs'][$scope][$pref] = $val;
    120         return true;
     52        $_SESSION[$this->ns][$key] = $val;
    12153    }
    12254
     
    12456     * Returns the value of the requested preference.
    12557     *
    126      * @param string $pref      The name of the preference to retrieve.
    127      * @param string $scope     The scope for this preference.
     58     * @param string $key       The name of the preference to retrieve.
    12859     *
    12960     * @return string           The value of the preference.
    13061     */
    131     function getValue($pref, $scope=null)
     62    function get($key)
    13263    {
    133         if (!isset($scope)) {
    134             $scope =& $this->scope;
    135         }
    136 
    137         return (isset($_SESSION['_prefs'][$scope][$pref])) ? $_SESSION['_prefs'][$scope][$pref] : null;
     64        return (isset($_SESSION[$this->ns][$key])) ? $_SESSION[$this->ns][$key] : null;
    13865    }
    13966
     
    14168     * To see if a preference has been set.
    14269     *
    143      * @param string $pref      The name of the preference to check.
    144      * @param string $scope     The scope for this preference.
     70     * @param string $key       The name of the preference to check.
    14571     *
    14672     * @return boolean          True if the preference isset and not empty
    14773     *                          false otherwise.
    14874     */
    149     function exists($pref, $scope=null)
     75    function exists($key)
    15076    {
    151         if (!isset($scope)) {
    152             $scope =& $this->scope;
    153         }
    154 
    155         return isset($_SESSION['_prefs'][$scope][$pref]);
     77        return isset($_SESSION[$this->ns][$key]);
    15678    }
    15779
     
    15981     * Clear a set preference value.
    16082     *
    161      * @param string $pref      The name of the preference to check.
    162      * @param string $scope     The scope for this preference.
     83     * @param string $key       The name of the preference to check.
    16384     */
    164     function clearValue($pref, $scope=null)
     85    function delete($key)
    16586    {
    166         if (!isset($scope)) {
    167             $scope =& $this->scope;
     87        if (isset($_SESSION[$this->ns][$key])) {
     88            unset($_SESSION[$this->ns][$key]);
    16889        }
    169 
    170         if (isset($_SESSION['_prefs'][$scope][$pref])) {
    171             unset($_SESSION['_prefs'][$scope][$pref]);
    172         }
    173     }
    174 
    175     /**
    176      * Retrieves the requested set of preferences from the user's database
    177      * entry.
    178      *
    179      * @param optional array $prefs  An array listing the preferences to
    180      *                     retrieve. If not specified, retrieve all of the
    181      *                     preferences listed in the $prefs hash.
    182      *
    183      * @return mixed       True on success or a PEAR_Error object on failure.
    184      */
    185     function retrieve()
    186     {
    187         // Check that we don't have the preferences loaded yet.
    188         if ($_SESSION['_prefs']['loaded'] == true || !$_perpetual) {
    189             return true;
    190         }
    191 
    192         // FIXME: Database query goes here....
    193         return false;
    194 
    195         $_SESSION['_prefs']['loaded'] = true;
    196     }
    197 
    198     /**
    199      * Stores preferences to SQL server.
    200      *
    201      * @param array $prefs (optional) An array listing the preferences to be
    202      *                     stored.  If not specified, store all of the
    203      *                     preferences listed in the $prefs hash.
    204      *
    205      * @return mixed       True on success or a PEAR_Error object on failure.
    206      */
    207     function store($prefs=array())
    208     {
    209         $app =& App::getInstance();
    210 
    211         // If we are not storing prefs in perpetually.
    212         if (!$_perpetual) {
    213             return true;
    214         }
    215 
    216         /*
    217          * If a list of preferences to store hasn't been provided in
    218          * $prefs, assume all preferences are desired.
    219          */
    220         if (empty($prefs)) {
    221             $prefs =& $_SESSION['_prefs'];
    222         } else if ($_SESSION['_prefs']['loaded'] == true) {
    223             $prefs = array_merge($_SESSION['_prefs'], $prefs);
    224         }
    225 
    226         if (!is_array($prefs) || empty($prefs)) {
    227             $app->raiseMsg(_("No preferences are available."), MSG_ERR, __FILE__, __LINE__);
    228             $app->dieBoomerangURL();
    229         }
    230 
    231         // FIXME: Database query goes here....
    232         return false;
    233 
    23490    }
    23591
     
    23793     * Perform cleanup operations.
    23894     */
    239     function cleanup()
     95    function clear()
    24096    {
    241         $_SESSION['_prefs'] = array();
     97        $_SESSION[$this->ns] = array();
    24298    }
    24399}
    244100
    245101
    246 
    247 
    248102?>
  • branches/2.0singleton/lib/RecordLock.inc.php

    r130 r135  
    11<?php
    22/**
     3 * RecordLock.inc.php
     4 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
     5 *
    36 * The RecordLock:: class provides a system for locking abstract DB rows.
    47 *
    58 * @author  Quinn Comendant <quinn@strangecode.com>
    6  * @version 2.0
     9 * @version 2.1
    710 */
    811class RecordLock {
     
    3235    function &getInstance($auth_object)
    3336    {
    34         static $instances = array();
    35 
    36         if (!isset($instances[$auth_object->getVal('auth_name')])) {
    37             $instances[$auth_object->getVal('auth_name')] = new RecordLock($auth_object);
    38         }
    39 
    40         return $instances[$auth_object->getVal('auth_name')];
     37        static $instance = null;
     38
     39        if ($instance === null) {
     40            $instance = new RecordLock($auth_object);
     41        }
     42
     43        return $instance;
    4144    }
    4245
     
    4447     * Constructor. Pass an Auth object on which to perform user lookups.
    4548     *
    46      * @param mixed  $auth_object  An Auth_SQL object.
     49     * @param mixed  $auth_object  An Auth_SQL or Auth_FILE object.
    4750     */
    4851    function RecordLock($auth_object)
     
    5053        $app =& App::getInstance();
    5154
    52         if (!is_a($auth_object, 'Auth_SQL')) {
    53             trigger_error('Constructor not provided a valid Auth_SQL object.', E_USER_ERROR);
     55        if (!method_exists($auth_object, 'getVal') || !method_exists($auth_object, 'getUsername')) {
     56            trigger_error('Constructor not provided a valid Auth_* object.', E_USER_ERROR);
    5457        }
    5558
     
    125128
    126129    /**
    127      * Return the value of a param setting.
    128      *
    129      * @access  public
    130      * @param   string  $params Which param to return.
    131      * @return  mixed   Configured param value.
     130     * Return the value of a parameter, if it exists.
     131     *
     132     * @access public
     133     * @param string $param        Which parameter to return.
     134     * @return mixed               Configured parameter value.
    132135     */
    133136    function getParam($param)
    134137    {
    135138        $app =& App::getInstance();
    136 
     139   
    137140        if (isset($this->_params[$param])) {
    138141            return $this->_params[$param];
    139142        } else {
    140             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
     143            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
    141144            return null;
    142145        }
  • branches/2.0singleton/lib/RecordVersion.inc.php

    r130 r135  
    11<?php
    22/**
     3 * RecordVersion.inc.php
     4 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
     5 *
    36 * The RecordVersion:: class provides a system for saving, reviewing, and
    47 * restoring versions of a record of any DB table. All the data in the record is
     
    1417 * @version 2.1
    1518 */
    16 
    1719class RecordVersion {
    1820
     
    3335     * This method enforces the singleton pattern for this class.
    3436     *
    35      * @return  object  Reference to the global RecordVersion object.
     37     * @return  object  Reference to the global RecordLock object.
    3638     * @access  public
    3739     * @static
     
    3941    function &getInstance($auth_object)
    4042    {
    41         static $instances = array();
    42 
    43         if (!isset($instances[$auth_object->getVal('auth_name')])) {
    44             $instances[$auth_object->getVal('auth_name')] = new RecordVersion($auth_object);
    45         }
    46 
    47         return $instances[$auth_object->getVal('auth_name')];
     43        static $instance = null;
     44
     45        if ($instance === null) {
     46            $instance = new RecordLock($auth_object);
     47        }
     48
     49        return $instance;
    4850    }
    4951
     
    5759        $app =& App::getInstance();
    5860
    59         if (!is_a($auth_object, 'Auth_SQL')) {
    60             trigger_error('Constructor not provided a valid Auth_SQL object.', E_USER_ERROR);
     61        if (!method_exists($auth_object, 'getVal') || !method_exists($auth_object, 'getUsername')) {
     62            trigger_error('Constructor not provided a valid Auth_* object.', E_USER_ERROR);
    6163        }
    6264
     
    136138
    137139    /**
    138      * Return the value of a param setting.
    139      *
    140      * @access  public
    141      * @param   string  $params Which param to return.
    142      * @return  mixed   Configured param value.
     140     * Return the value of a parameter, if it exists.
     141     *
     142     * @access public
     143     * @param string $param        Which parameter to return.
     144     * @return mixed               Configured parameter value.
    143145     */
    144146    function getParam($param)
    145147    {
    146148        $app =& App::getInstance();
    147 
     149   
    148150        if (isset($this->_params[$param])) {
    149151            return $this->_params[$param];
    150152        } else {
    151             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
     153            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
    152154            return null;
    153155        }
  • branches/2.0singleton/lib/ScriptTimer.inc.php

    r92 r135  
    11<?php
    22/**
    3  * ScriptTimer.inc.php 
    4  * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
     3 * ScriptTimer.inc.php
     4 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
    55 */
    6  
    76class ScriptTimer {
    87
  • branches/2.0singleton/lib/SessionCache.inc.php

    r128 r135  
    11<?php
    22/**
    3  * SessionCache.inc.php
     3 * Cache.inc.php
     4 * code by strangecode :: www.strangecode.com :: this document contains copyrighted information
     5 *
    46 * Provides an API for storing a limited amount of data
    57 * intended to have a short lifetime in a user's session.
    68 *
    7  * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information.
    89 * @author  Quinn Comendant <quinn@strangecode.com>
    9  * @version 1.2
     10 * @version 2.1
    1011 * @since   2001
    1112 */
    12 class SessionCache
    13 {
     13 
     14// Flags.
     15define('CACHE_IGNORE_SIZE', 1);
     16
     17class Cache {
     18
    1419    var $_params = array(
    1520        'enabled' => true,
     
    2227     * This method enforces the singleton pattern for this class.
    2328     *
    24      * @return  object  Reference to the global SessionCache object.
     29     * @return  object  Reference to the global Cache object.
    2530     * @access  public
    2631     * @static
    2732     */
    28     function &getInstance() {
     33    function &getInstance()
     34    {
    2935        static $instance = null;
    3036
    3137        if ($instance === null) {
    32             $instance = new SessionCache();
     38            $instance = new Cache();
    3339        }
    3440
     
    4652        $app =& App::getInstance();
    4753
    48         if (!isset($_this) || !is_a($_this, 'SessionCache') && !is_subclass_of($_this, 'SessionCache')) {
    49             $_this =& SessionCache::getInstance();
    50         }
    51 
    5254        if (isset($params) && is_array($params)) {
    5355            // Merge new parameters with old overriding only those passed.
    54             $_this->_params = array_merge($_this->_params, $params);
     56            $this->_params = array_merge($this->_params, $params);
    5557        } else {
    5658            $app->logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__);
     
    6870    {
    6971        $app =& App::getInstance();
    70 
    71         if (!isset($_this) || !is_a($_this, 'SessionCache') && !is_subclass_of($_this, 'SessionCache')) {
    72             $_this =& SessionCache::getInstance();
    73         }
    74 
    75         if (isset($_this->_params[$param])) {
    76             return $_this->_params[$param];
    77         } else {
    78             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
     72   
     73        if (isset($this->_params[$param])) {
     74            return $this->_params[$param];
     75        } else {
     76            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
    7977            return null;
    8078        }
     
    8280
    8381    /**
    84      * Stores a new variable in the session cache. The $var_id is is md5'ed
     82     * Stores a new variable in the session cache. The $key is is md5'ed
    8583     * because if a variable id is a very large integer, the array_shift function
    86      * will reset the key to the next largest int key. Weird behaviour I can't
     84     * will reset the key to the next largest int key. Weird behavior I can't
    8785     * understand. $session_cache[32341234123] will become $session_cache[0]
    8886     * for example. Usage warning: if the variable is too big to fit, or is
    8987     * old and discarded, you must provide alternative ways of accessing the data.
    9088     *
     89     * @param str   $key        An identifier for the cached object.
    9190     * @param mixed $var          The var to store in the session cache.
    92      * @param str   $var_id       An identifyer for the cached object.
    93      * @param bool  $force_it_in  If we have something really big that we
    94      *                            still want to cache, setting this true
    95      *                            allows this.
    96      *
    97      * @return string        The $var_id, or false if the object was too big to cache.
    98      */
    99     function putCache($var, $var_id, $force_it_in=false)
     91     * @param bool  $flags      If we have something really big that we
     92     *                            still want to cache, setting this to
     93     *                            CACHE_IGNORE_SIZE allows this.
     94     *
     95     * @return bool               True on success, false otherwise.
     96     */
     97    function set($key, $var, $flags=0)
    10098    {
    10199        $app =& App::getInstance();
    102100
    103         if (!isset($_this) || !is_a($_this, 'SessionCache') && !is_subclass_of($_this, 'SessionCache')) {
    104             $_this =& SessionCache::getInstance();
    105         }
    106 
    107         if (!$_this->getParam('enabled')) {
    108             $app->logMsg(sprintf('SessionCache not enabled, not saving data.', null), LOG_DEBUG, __FILE__, __LINE__);
    109             return false;
    110         }
    111 
    112         $var_id = md5($var_id);
     101        if (!$this->getParam('enabled')) {
     102            $app->logMsg(sprintf('Cache not enabled, not saving data.', null), LOG_DEBUG, __FILE__, __LINE__);
     103            return false;
     104        }
     105
     106        $key = md5($key);
    113107        $serialized_var = serialize($var);
    114108        $serialized_var_len = strlen($serialized_var);
    115109
    116         if ($serialized_var_len >= $_this->getParam('soft_limit') && !$force_it_in) {
    117             $app->logMsg(sprintf('Serialized variable (%s bytes) more than soft_limit (%s bytes).', $serialized_var_len, $_this->getParam('soft_limit')), LOG_NOTICE, __FILE__, __LINE__);
    118             return false;
    119         }
    120 
    121         if ($serialized_var_len >= $_this->getParam('hard_limit')) {
    122             $app->logMsg(sprintf('Serialized variable (%s bytes) more than hard_limit (%s bytes).', $serialized_var_len, $_this->getParam('hard_limit')), LOG_NOTICE, __FILE__, __LINE__);
     110        if ($flags & CACHE_IGNORE_SIZE > 0 && $serialized_var_len >= $this->getParam('soft_limit')) {
     111            $app->logMsg(sprintf('Serialized variable (%s bytes) more than soft_limit (%s bytes).', $serialized_var_len, $this->getParam('soft_limit')), LOG_NOTICE, __FILE__, __LINE__);
     112            return false;
     113        }
     114
     115        if ($serialized_var_len >= $this->getParam('hard_limit')) {
     116            $app->logMsg(sprintf('Serialized variable (%s bytes) more than hard_limit (%s bytes).', $serialized_var_len, $this->getParam('hard_limit')), LOG_NOTICE, __FILE__, __LINE__);
    123117            return false;
    124118        }
     
    127121            $_SESSION['_session_cache'] = array();
    128122        } else {
    129             unset($_SESSION['_session_cache'][$var_id]);
     123            unset($_SESSION['_session_cache'][$key]);
    130124            // 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.
    131             while (strlen(serialize($_SESSION['_session_cache'])) + $serialized_var_len >= $_this->getParam('soft_limit')
    132             && sizeof($_SESSION['_session_cache']) >= $_this->getParam('min_items')) {
     125            while (strlen(serialize($_SESSION['_session_cache'])) + $serialized_var_len >= $this->getParam('soft_limit')
     126            && sizeof($_SESSION['_session_cache']) >= $this->getParam('min_items')) {
    133127                array_shift($_SESSION['_session_cache']);
    134128            }
    135129        }
    136         $_SESSION['_session_cache'][$var_id] =& $serialized_var;
     130        $_SESSION['_session_cache'][$key] =& $serialized_var;
    137131
    138132        if ($serialized_var_len >= 1024000) {
     
    140134        }
    141135
    142         return $var_id;
     136        return true;
    143137    }
    144138
     
    149143     * first.
    150144     *
    151      * @param string $var_id  The identifyer for the datum to retrieve.
     145     * @param string $key  The key for the datum to retrieve.
    152146     *
    153147     * @return mixed          The requested datum, or false on failure.
    154148     */
    155     function getCache($var_id)
    156     {
    157         if (!isset($_this) || !is_a($_this, 'SessionCache') && !is_subclass_of($_this, 'SessionCache')) {
    158             $_this =& SessionCache::getInstance();
    159         }
    160 
    161         if (!$_this->getParam('enabled')) {
    162             return false;
    163         }
    164 
    165         $var_id = md5($var_id);
    166         if (isset($_SESSION['_session_cache'][$var_id])) {
     149    function get($key)
     150    {
     151        if (!$this->getParam('enabled')) {
     152            return false;
     153        }
     154
     155        $key = md5($key);
     156        if (isset($_SESSION['_session_cache'][$key])) {
    167157            // Move the accessed cached datum to the top of the stack. Maybe somebody knows a better way to do this?
    168             $tmp =& $_SESSION['_session_cache'][$var_id];
    169             unset($_SESSION['_session_cache'][$var_id]);
    170             $_SESSION['_session_cache'][$var_id] =& $tmp;
     158            $tmp =& $_SESSION['_session_cache'][$key];
     159            unset($_SESSION['_session_cache'][$key]);
     160            $_SESSION['_session_cache'][$key] =& $tmp;
    171161            // Return the unserialized datum.
    172             return unserialize($_SESSION['_session_cache'][$var_id]);
     162            return unserialize($_SESSION['_session_cache'][$key]);
    173163        } else {
    174164            return false;
     
    179169     * Tells you if the object is cached.
    180170     *
    181      * @param string $var_id  The ID of the object to check.
     171     * @param string $key  The key of the object to check.
    182172     *
    183173     * @return bool           The return from isset().
    184174     */
    185     function isCached($var_id)
    186     {
    187         if (!isset($_this) || !is_a($_this, 'SessionCache') && !is_subclass_of($_this, 'SessionCache')) {
    188             $_this =& SessionCache::getInstance();
    189         }
    190 
    191         if (!$_this->getParam('enabled')) {
    192             return false;
    193         }
    194 
    195         $var_id = md5($var_id);
    196         return isset($_SESSION['_session_cache'][$var_id]);
     175    function exists($key)
     176    {
     177        if (!$this->getParam('enabled')) {
     178            return false;
     179        }
     180
     181        $key = md5($key);
     182        return isset($_SESSION['_session_cache'][$key]);
    197183    }
    198184
     
    200186     * Tells you if the object is cached.
    201187     *
    202      * @param string $var_id  The ID of the object to check.
     188     * @param string $key  The key of the object to check.
    203189     *
    204190     * @return bool           The return from isset().
    205191     */
    206     function breakCache($var_id)
    207     {
    208         $var_id = md5($var_id);
    209         if (isset($_SESSION['_session_cache'][$var_id])) {
    210             unset($_SESSION['_session_cache'][$var_id]);
    211         }
    212     }
    213 
    214 // END SessionCache
     192    function delete($key)
     193    {
     194        $key = md5($key);
     195        if (isset($_SESSION['_session_cache'][$key])) {
     196            unset($_SESSION['_session_cache'][$key]);
     197        }
     198    }
     199
     200// END Cache
    215201}
    216202
  • branches/2.0singleton/lib/SortOrder.inc.php

    r132 r135  
    7878        if (!empty($new_sort_by)) {
    7979            $this->sort_by = $new_sort_by;
    80             $prefs->setValue('sort_by', $this->sort_by, $_SERVER['PHP_SELF']);
     80            $prefs->set('sort_by', $this->sort_by, $_SERVER['PHP_SELF']);
    8181        } else if ($prefs->exists('sort_by', $_SERVER['PHP_SELF'])) {
    82             $this->sort_by = $prefs->getValue('sort_by', $_SERVER['PHP_SELF']);
     82            $this->sort_by = $prefs->get('sort_by', $_SERVER['PHP_SELF']);
    8383        } else {
    8484            $this->sort_by = $default_sort;
     
    9292        if (!empty($new_order)) {
    9393            $this->order = $new_order;
    94             $prefs->setValue('sort_order', $this->order, $_SERVER['PHP_SELF']);
     94            $prefs->set('sort_order', $this->order, $_SERVER['PHP_SELF']);
    9595        } else if ($prefs->exists('sort_order', $_SERVER['PHP_SELF'])) {
    96             $this->order = $prefs->getValue('sort_order', $_SERVER['PHP_SELF']);
     96            $this->order = $prefs->get('sort_order', $_SERVER['PHP_SELF']);
    9797        } else {
    9898            $this->order = $default_order;
     
    116116        if (isset($sort)) {
    117117            $this->sort_by = $sort;
    118             $prefs->setValue('sort_by', $this->sort_by, $_SERVER['PHP_SELF']);
     118            $prefs->set('sort_by', $this->sort_by, $_SERVER['PHP_SELF']);
    119119        }
    120120
     
    122122        if (isset($order)) {
    123123            $this->order = $order;
    124             $prefs->setValue('sort_order', $this->order, $_SERVER['PHP_SELF']);
     124            $prefs->set('sort_order', $this->order, $_SERVER['PHP_SELF']);
    125125        }
    126126    }
  • branches/2.0singleton/lib/SpellCheck.inc.php

    r128 r135  
    116116    {
    117117        $app =& App::getInstance();
    118 
     118   
    119119        if (isset($this->_params[$param])) {
    120120            return $this->_params[$param];
    121121        } else {
    122             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
     122            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
    123123            return null;
    124124        }
  • branches/2.0singleton/lib/Upload.inc.php

    r128 r135  
    9696    {
    9797        $app =& App::getInstance();
    98 
     98   
    9999        if (isset($this->_params[$param])) {
    100100            return $this->_params[$param];
    101101        } else {
    102             $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__);
     102            $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_NOTICE, __FILE__, __LINE__);
    103103            return null;
    104104        }
  • branches/2.0singleton/services/admins.php

    r132 r135  
    1111
    1212require_once 'codebase/lib/PageNumbers.inc.php';
    13 require_once 'codebase/lib/SessionCache.inc.php';
     13require_once 'codebase/lib/Cache.inc.php';
    1414require_once 'codebase/lib/FormValidator.inc.php';
    1515require_once 'codebase/lib/SortOrder.inc.php';
     
    3030$fv = new FormValidator();
    3131
    32 $cache =& SessionCache::getInstance();
     32$cache =& Cache::getInstance();
    3333
    3434// Instantiate a sorting object with the default sort and order. Add SQL for each column.
     
    7171if (getFormData('break_list_cache', false)) {
    7272    // Break the cache because we are changing the list data.
    73     $cache->breakCache($_SERVER['PHP_SELF']);
     73    $cache->delete($_SERVER['PHP_SELF']);
    7474}
    7575
     
    319319    $app =& App::getInstance();
    320320    $db =& DB::getInstance();
    321     $cache =& SessionCache::getInstance();
     321    $cache =& Cache::getInstance();
    322322   
    323323    $lock->select('admin_tbl', 'admin_id', $id);
     
    327327
    328328    // Break the cache because we are changing the list data.
    329     $cache->breakCache($_SERVER['PHP_SELF']);
     329    $cache->delete($_SERVER['PHP_SELF']);
    330330
    331331    // Get the information for this object.
     
    367367    $app =& App::getInstance();
    368368    $db =& DB::getInstance();
    369     $cache =& SessionCache::getInstance();
     369    $cache =& Cache::getInstance();
    370370   
    371371    // Break the cache because we are changing the list data.
    372     $cache->breakCache($_SERVER['PHP_SELF']);
     372    $cache->delete($_SERVER['PHP_SELF']);
    373373
    374374    // Insert record data.
     
    411411    $app =& App::getInstance();
    412412    $db =& DB::getInstance();
    413     $cache =& SessionCache::getInstance();
     413    $cache =& Cache::getInstance();
    414414   
    415415    $lock->select('admin_tbl', 'admin_id', $frm['admin_id']);
     
    419419
    420420    // Break the cache because we are changing the list data.
    421     $cache->breakCache($_SERVER['PHP_SELF']);
     421    $cache->delete($_SERVER['PHP_SELF']);
    422422
    423423    // If the userpass is left blank or with the filler **** characters, we don't want to update it.
     
    456456    $db =& DB::getInstance();
    457457    $prefs =& Prefs::getInstance();
    458     $cache =& SessionCache::getInstance();
     458    $cache =& Cache::getInstance();
    459459   
    460460    $where_clause = '';
     
    507507    // without knowing the hash.
    508508    $cache_hash = md5($sql . '|' . $page->total_items);
    509     if ($prefs->getValue('cache_hash', $_SERVER['PHP_SELF']) != $cache_hash) {
    510         $cache->breakCache($_SERVER['PHP_SELF']);
    511         $prefs->setValue('cache_hash', $cache_hash, $_SERVER['PHP_SELF']);
    512     }
    513 
    514     if ($cache->isCached($_SERVER['PHP_SELF']) && false) {
     509    if ($prefs->get('cache_hash', $_SERVER['PHP_SELF']) != $cache_hash) {
     510        $cache->delete($_SERVER['PHP_SELF']);
     511        $prefs->set('cache_hash', $cache_hash, $_SERVER['PHP_SELF']);
     512    }
     513
     514    if ($cache->exists($_SERVER['PHP_SELF']) && false) {
    515515        // Get the cached results.
    516         $list = $cache->getCache($_SERVER['PHP_SELF']);
     516        $list = $cache->get($_SERVER['PHP_SELF']);
    517517    } else {
    518518        // If the list is not already cached, query now.
     
    525525        if (isset($list) && !empty($list)) {
    526526            // Cache the results.
    527             $cache->putCache($list, $_SERVER['PHP_SELF']);
     527            $cache->set($list, $_SERVER['PHP_SELF']);
    528528        }
    529529    }
  • branches/2.0singleton/services/logout.php

    r129 r135  
    55 */
    66
    7 if (is_a($auth, 'Auth_SQL')) {
     7if (isset($auth) && method_exists($auth, 'getVal')) {
    88    // Delete the current user's record locks.
    99    require_once 'codebase/lib/RecordLock.inc.php';
  • branches/2.0singleton/services/logs.php

    r132 r135  
    4040// Set the defaults and catch incoming settings.
    4141$prefs =& Prefs::getInstance();
    42 $prefs->setDefault('log_file', $app->getParam('log_filename'), 'logs_module');
    43 $prefs->setValue('log_file', getFormData('log'), 'logs_module');
     42$prefs->default('log_file', $app->getParam('log_filename'), 'logs_module');
     43$prefs->set('log_file', getFormData('log'), 'logs_module');
    4444
    4545// Titles and navigation header.
    46 $nav->addPage(sprintf(_("Viewing log: <em>%s</em>"), $prefs->getValue('log_file', 'logs_module')), '/admin/logs.php');
     46$nav->addPage(sprintf(_("Viewing log: <em>%s</em>"), $prefs->get('log_file', 'logs_module')), '/admin/logs.php');
    4747
    4848/******************************************************************************
     
    5757case 'delete' :
    5858//     $auth->requireAccessClearance(ZONE_ADMIN_APPLOG_FUNC_RESET);
    59     deleteLog($prefs->getValue('log_file', 'logs_module'));
    60     $prefs->setValue('log_file', $app->getParam('log_filename'), 'logs_module');
     59    deleteLog($prefs->get('log_file', 'logs_module'));
     60    $prefs->set('log_file', $app->getParam('log_filename'), 'logs_module');
    6161    if ($app->validBoomerangURL('app_log')) {
    6262        // Display boomerang page.
     
    6969case 'clear' :
    7070//     $auth->requireAccessClearance(ZONE_ADMIN_APPLOG_FUNC_RESET);
    71     clearLog($prefs->getValue('log_file', 'logs_module'));
     71    clearLog($prefs->get('log_file', 'logs_module'));
    7272    if ($app->validBoomerangURL('app_log')) {
    7373        // Display boomerang page.
     
    8080case 'archive' :
    8181//     $auth->requireAccessClearance(ZONE_ADMIN_APPLOG_FUNC_RESET);
    82     if (archiveLog($prefs->getValue('log_file', 'logs_module'))) {
     82    if (archiveLog($prefs->get('log_file', 'logs_module'))) {
    8383        // Now flush current log.
    8484        $app->dieURL($_SERVER['PHP_SELF'] . '?op=clear');
     
    9898case 'download' :
    9999    header('Content-Type: application/octet-stream');
    100     header(sprintf('Content-Disposition: attachment; filename=%s.txt', $prefs->getValue('log_file', 'logs_module')));
    101     printLog($prefs->getValue('log_file', 'logs_module'));
     100    header(sprintf('Content-Disposition: attachment; filename=%s.txt', $prefs->get('log_file', 'logs_module')));
     101    printLog($prefs->get('log_file', 'logs_module'));
    102102    die;
    103103    break;
    104104
    105105default :
    106     $list =& getLog($prefs->getValue('log_file', 'logs_module'), getFormData('search_query'));
     106    $list =& getLog($prefs->get('log_file', 'logs_module'), getFormData('search_query'));
    107107    $main_template = 'log_list.ihtml';
    108108    break;
     
    126126include 'header.ihtml';
    127127if ('output' == $main_template) {
    128     printLog($prefs->getValue('log_file', 'logs_module'));
     128    printLog($prefs->get('log_file', 'logs_module'));
    129129} else {
    130130    include 'codebase/services/templates/' . $main_template;
  • branches/2.0singleton/services/templates/log_list.ihtml

    r132 r135  
    1010        <tr class="commandtext">
    1111            <td>
    12                 <?php if ($l['filename'] == $prefs->getValue('log_file', 'logs_module')) { ?>
     12                <?php if ($l['filename'] == $prefs->get('log_file', 'logs_module')) { ?>
    1313                    <span class="commanditem"><strong><?php echo sprintf(_("%s"), $l['filename']); ?></strong></span>
    1414                <?php } else { ?>
  • branches/2.0singleton/tests/SessionCacheTest.php

    r42 r135  
    44
    55/**
    6  * PHPUnit test case for SessionCache
     6 * PHPUnit test case for Cache
    77 *
    88 * The method skeletons below need to be filled in with
     
    1313 */
    1414require_once 'PHPUnit.php';
    15 class SessionCacheTest extends PHPUnit_TestCase {
     15class CacheTest extends PHPUnit_TestCase {
    1616
    17     var $SessionCache;
     17    var $Cache;
    1818
    19     function SessionCacheTest($name)
     19    function CacheTest($name)
    2020    {
    2121        $this->PHPUnit_TestCase($name);
     
    2525    {
    2626        require dirname(__FILE__) . '/_config.inc.php';
    27         require_once '../lib/SessionCache.inc.php';
    28         $this->SessionCache =& new SessionCache(PARAM);
     27        require_once '../lib/Cache.inc.php';
     28        $this->Cache =& new Cache(PARAM);
    2929    }
    3030
    3131    function tearDown()
    3232    {
    33         unset($this->SessionCache);
     33        unset($this->Cache);
    3434    }
    3535
    3636    function test_getinstance()
    3737    {
    38         $result = $this->SessionCache->getinstance(PARAM);
     38        $result = $this->Cache->getinstance(PARAM);
    3939        $expected = EXPECTED_VAL;
    4040        $this->assertEquals($expected, $result);
     
    4343    function test_setparam()
    4444    {
    45         $result = $this->SessionCache->setparam(PARAM);
     45        $result = $this->Cache->setparam(PARAM);
    4646        $expected = EXPECTED_VAL;
    4747        $this->assertEquals($expected, $result);
     
    5050    function test_getparam()
    5151    {
    52         $result = $this->SessionCache->getparam(PARAM);
     52        $result = $this->Cache->getparam(PARAM);
    5353        $expected = EXPECTED_VAL;
    5454        $this->assertEquals($expected, $result);
     
    5757    function test_putcache()
    5858    {
    59         $result = $this->SessionCache->putcache(PARAM);
     59        $result = $this->Cache->putcache(PARAM);
    6060        $expected = EXPECTED_VAL;
    6161        $this->assertEquals($expected, $result);
     
    6464    function test_getcache()
    6565    {
    66         $result = $this->SessionCache->getcache(PARAM);
     66        $result = $this->Cache->getcache(PARAM);
    6767        $expected = EXPECTED_VAL;
    6868        $this->assertEquals($expected, $result);
     
    7171    function test_iscached()
    7272    {
    73         $result = $this->SessionCache->iscached(PARAM);
     73        $result = $this->Cache->iscached(PARAM);
    7474        $expected = EXPECTED_VAL;
    7575        $this->assertEquals($expected, $result);
     
    7878    function test_breakcache()
    7979    {
    80         $result = $this->SessionCache->breakcache(PARAM);
     80        $result = $this->Cache->breakcache(PARAM);
    8181        $expected = EXPECTED_VAL;
    8282        $this->assertEquals($expected, $result);
     
    8585}
    8686// Running the test.
    87 $suite = new PHPUnit_TestSuite('SessionCacheTest');
     87$suite = new PHPUnit_TestSuite('CacheTest');
    8888$result = PHPUnit::run($suite);
    8989echo $result->toString();
Note: See TracChangeset for help on using the changeset viewer.