Changeset 740 for trunk/lib


Ignore:
Timestamp:
Nov 30, 2020 2:27:06 AM (3 years ago)
Author:
anonymous
Message:
 
Location:
trunk/lib
Files:
2 edited

Legend:

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

    r739 r740  
    18791879        }
    18801880
    1881         // Create a DateTime object and conver the timezone from server to user.
    1882         $dt = $this->convertTZ($datetime, $this->getParam('php_timezone'), $this->getParam('user_timezone'));
     1881        try {
     1882            // Create a DateTime object and conver the timezone from server to user.
     1883            $dt = $this->convertTZ($datetime, $this->getParam('php_timezone'), $this->getParam('user_timezone'));
     1884        } catch (Exception $e) {
     1885            $this->logMsg(sprintf('DateTime failed to parse string in %s: %s', __METHOD__, $datetime), LOG_NOTICE, __FILE__, __LINE__);
     1886            return '';
     1887        }
    18831888
    18841889        // By default, we try to use a localized date format. Set lc_date_format to null to use regular date_format instead.
     
    19061911    function dateToServerTZ($datetime, $format='Y-m-d H:i:s')
    19071912    {
    1908         return $this->convertTZ($datetime, $this->getParam('user_timezone'), $this->getParam('php_timezone'))->format($format);
     1913        try {
     1914            // Create a DateTime object and conver the timezone from server to user.
     1915            $dt = $this->convertTZ($datetime, $this->getParam('user_timezone'), $this->getParam('php_timezone'));
     1916        } catch (Exception $e) {
     1917            $this->logMsg(sprintf('DateTime failed to parse string in %s: %s', __METHOD__, $datetime), LOG_NOTICE, __FILE__, __LINE__);
     1918            return '';
     1919        }
     1920
     1921        return $dt->format($format);
    19091922    }
    19101923
  • trunk/lib/Prefs.inc.php

    r719 r740  
    332332            if (!(isset($_SESSION['_prefs'][$this->_ns]['defaults']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['defaults']))
    333333            || $_SESSION['_prefs'][$this->_ns]['defaults'][$key] != $val
    334             || (isset($_SESSION['_prefs'][$this->_ns]['saved']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved']))) {
     334            || $this->exists($key)) {
    335335                $_SESSION['_prefs'][$this->_ns]['saved'][$key] = $val;
    336336                $app->logMsg(sprintf('Setting session/database preference %s => %s', $key, getDump($val, true)), LOG_DEBUG, __FILE__, __LINE__);
     
    355355     * a default value is returned, or if not that, null.
    356356     *
    357      * @param string $key       The name of the preference to retrieve.
    358      *
     357     * @param string $key       The name of the preference to retrieve (or null to retrieve all keys).
    359358     * @return string           The value of the preference.
    360359     */
    361     public function get($key)
     360    public function get($key=null)
    362361    {
    363362        $app =& App::getInstance();
     
    368367        case 'session':
    369368        case 'database':
    370             if (isset($_SESSION['_prefs'][$this->_ns]['saved']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved'])) {
     369            if (is_null($key) && isset($_SESSION['_prefs'][$this->_ns]['saved'])) {
     370                return $_SESSION['_prefs'][$this->_ns]['saved'];
     371            }
     372            if ($this->exists($key)) {
    371373                $app->logMsg(sprintf('Found %s in saved', $key), LOG_DEBUG, __FILE__, __LINE__);
    372374                return $_SESSION['_prefs'][$this->_ns]['saved'][$key];
    373             } else if (isset($_SESSION['_prefs'][$this->_ns]['defaults']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['defaults'])) {
     375            }
     376            if (isset($_SESSION['_prefs'][$this->_ns]['defaults']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['defaults'])) {
    374377                $app->logMsg(sprintf('Found %s in defaults', $key), LOG_DEBUG, __FILE__, __LINE__);
    375378                return $_SESSION['_prefs'][$this->_ns]['defaults'][$key];
    376             } else {
    377                 $app->logMsg(sprintf('Key not found in prefs cache: %s', $key), LOG_DEBUG, __FILE__, __LINE__);
    378             }
     379            }
     380            $app->logMsg(sprintf('Key not found in prefs cache: %s', $key), LOG_DEBUG, __FILE__, __LINE__);
    379381            return null;
    380382
    381383        case 'cookie':
     384            if (is_null($key)) {
     385                $app->logMsg(sprintf('Unable to get(null) when using cookie storagetype.', null), LOG_WARNING, __FILE__, __LINE__);
     386                return null;
     387            }
    382388            $name = $this->_getCookieName($key);
    383389            if ($this->exists($key) && '' != $_COOKIE[$name]) {
     
    385391                $app->logMsg(sprintf('Found %s in cookie: %s', $key, getDump($val)), LOG_DEBUG, __FILE__, __LINE__);
    386392                return $val;
    387             } else {
    388                 $app->logMsg(sprintf('Did not find %s in cookie', $key), LOG_DEBUG, __FILE__, __LINE__);
    389             }
     393            }
     394            $app->logMsg(sprintf('Did not find %s in cookie', $key), LOG_DEBUG, __FILE__, __LINE__);
    390395            return null;
    391396        }
     
    405410        case 'session':
    406411        case 'database':
     412            // isset() does not return TRUE for array keys that correspond to a NULL value, while array_key_exists() does.
    407413            return (isset($_SESSION['_prefs'][$this->_ns]['saved']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved']));
    408414
Note: See TracChangeset for help on using the changeset viewer.