Changeset 477


Ignore:
Timestamp:
May 3, 2014 3:13:19 PM (10 years ago)
Author:
anonymous
Message:

Added cookie storage to Prefs(). Created App->addCookie method. Improved PHP version checks.

Location:
trunk
Files:
6 edited

Legend:

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

    r476 r477  
    179179        $this->timer = new ScriptTimer();
    180180        $this->timer->start('_app');
     181
     182        // The codebase now requires a minimum PHP version.
     183        $codebase_minimum_php_version = '5.3.0';
     184        if (version_compare(PHP_VERSION, $codebase_minimum_php_version, '<')) {
     185            $this->logMsg(sprintf('Codebase minimum PHP version of %s not satisfied (you have %s). ', $codebase_minimum_php_version, phpversion()), LOG_NOTICE, __FILE__, __LINE__);
     186        }
    181187    }
    182188
     
    608614        preg_match_all('/(<[^>\s]{7,})[^>]*>/', $message, $strip_tags_allow);
    609615        $message = strip_tags(preg_replace('/\s+/', ' ', $message), (!empty($strip_tags_allow[1]) ? join('> ', $strip_tags_allow[1]) . '>' : null));
     616
     617        // Serialize multi-line messages.
     618        $message = preg_replace('/\s+/m', ' ', $message);
    610619
    611620        // Store this event under a unique key, counting each time it occurs so that it only gets reported a limited number of times.
     
    12411250    }
    12421251
    1243 
    12441252    /**
    12451253     * to enforce the user to connect via http (port 80) by redirecting them to
     
    12521260        }
    12531261    }
     1262
     1263    /*
     1264    * Sets a cookie, with error checking and some sane defaults.
     1265    *
     1266    * @access   public
     1267    * @param    string  $name       The name of the cookie.
     1268    * @param    string  $value      The value of the cookie.
     1269    * @param    string  $expire     The time the cookie expires, as a unix timestamp or string value passed to strtotime.
     1270    * @param    string  $path       The path on the server in which the cookie will be available on
     1271    * @param    string  $domain     The domain that the cookie is available to
     1272    * @param    bool    $secure     Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client.
     1273    * @param    bool    $httponly   When TRUE the cookie will be made accessible only through the HTTP protocol (makes cookies unreadable to javascript).
     1274    * @return   bool                True on success, false on error.
     1275    * @author   Quinn Comendant <quinn@strangecode.com>
     1276    * @version  1.0
     1277    * @since    02 May 2014 16:36:34
     1278    */
     1279    public function setCookie($name, $value, $expire='+10 years', $path=null, $domain=null, $secure=null, $httponly=null)
     1280    {
     1281        if (!is_scalar($name)) {
     1282            $this->logMsg(sprintf('Cookie name must be scalar, is not: %s', getDump($name)), LOG_NOTICE, __FILE__, __LINE__);
     1283            return false;
     1284        }
     1285        if (!is_scalar($value)) {
     1286            $this->logMsg(sprintf('Cookie "%s" value must be scalar, is not: %s', $name, getDump($value)), LOG_NOTICE, __FILE__, __LINE__);
     1287            return false;
     1288        }
     1289
     1290        // Defaults.
     1291        $expire = (is_numeric($expire) ? $expire : (is_string($expire) ? strtotime($expire) : $expire));
     1292        $secure = $secure ?: ('' != getenv('HTTPS') && $this->getParam('ssl_enabled'));
     1293        $httponly = $httponly ?: true;
     1294
     1295        // Make sure the expiration date is a valid 32bit integer.
     1296        if (is_int($expire) && $expire > 2147483647) {
     1297            $this->logMsg(sprintf('Cookie "%s" expire time exceeds a 32bit integer (%s)', $key, date('r', $expire)), LOG_NOTICE, __FILE__, __LINE__);
     1298        }
     1299
     1300        // Measure total cookie length and warn if larger than max recommended size of 4093.
     1301        // https://stackoverflow.com/questions/640938/what-is-the-maximum-size-of-a-web-browsers-cookies-key
     1302        // The date the header name include 51 bytes: Set-Cookie: ; expires=Fri, 03-May-2024 00:04:47 GMT
     1303        $cookielen = strlen($name . $value . $path . $domain . ($secure ? '; secure' : '') . ($httponly ? '; httponly' : '')) + 51;
     1304        if ($cookielen > 4093) {
     1305            $this->logMsg(sprintf('Cookie "%s" has a size greater than 4093 bytes (is %s bytes)', $key, $cookielen), LOG_NOTICE, __FILE__, __LINE__);
     1306        }
     1307
     1308        // Ensure PHP version allow use of httponly.
     1309        if (version_compare(PHP_VERSION, '5.2.0', '>=')) {
     1310            $ret = setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
     1311        } else {
     1312            $ret = setcookie($name, $value, $expire, $path, $domain, $secure);
     1313        }
     1314
     1315        if (false === $ret) {
     1316            $this->logMsg(sprintf('Failed to set cookie (%s=%s) probably due to output before headers.', $name, $value), LOG_NOTICE, __FILE__, __LINE__);
     1317        }
     1318        return $ret;
     1319    }
    12541320} // End.
  • trunk/lib/ImageThumb.inc.php

    r468 r477  
    128128                if (!is_dir($params['source_dir'])) {
    129129                    $app->logMsg(sprintf('Attempting to auto-create source directory: %s', $params['source_dir']), LOG_NOTICE, __FILE__, __LINE__);
    130                     if (phpversion() > '5') {
     130                    if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
    131131                        // Recursive.
    132132                        mkdir($params['source_dir'], isset($params['dest_dir_perms']) ? $params['dest_dir_perms'] : $this->getParam('dest_dir_perms'), true);
     
    607607
    608608        // Sharpen image using a custom filter matrix.
    609         if (phpversion() > '5.1' && true === $spec['sharpen'] && $spec['sharpen_value'] > 0) {
     609        if (version_compare(PHP_VERSION, '5.1.0', '>=') && true === $spec['sharpen'] && $spec['sharpen_value'] > 0) {
    610610            $sharpen_value = round((((48 - 10) / (100 - 1)) * (100 - $spec['sharpen_value'])) + 10); // TODO: WTF is this math?
    611611            imageconvolution($dest_image_resource, array(array(-1, -1, -1), array(-1, $sharpen_value, -1),array(-1, -1, -1)), ($sharpen_value - 8), 0);
  • trunk/lib/Prefs.inc.php

    r468 r477  
    3030 * @version 2.1
    3131 *
    32  * Example of use:
     32 * Example of use (database storagetype):
    3333---------------------------------------------------------------------
    3434// Load preferences for the user's session.
     
    3636$prefs = new Prefs('my-namespace');
    3737$prefs->setParam(array(
    38     'persistent' => $auth->isLoggedIn(),
     38    'storagetype' => ($auth->isLoggedIn() ? 'database' : 'session'),
    3939    'user_id' => $auth->get('user_id'),
    4040));
     
    4949$prefs->set('datalog_num_entries', getFormData('datalog_num_entries'));
    5050$prefs->save();
    51 
    5251---------------------------------------------------------------------
    5352 */
     
    6059    private $_params = array(
    6160
     61        // Legacy parameter, superceeded by the 'storagetype' setting.
    6262        // Enable database storage. If this is false, all prefs will live only as long as the session.
    63         'persistent' => false,
    64 
    65         // The current user_id for which to load/save persistent preferences.
     63        'persistent' => null,
     64
     65        // Store preferences in one of the available storage mechanisms: session, cookie, database
     66        'storagetype' => 'session',
     67
     68        // ----------------------------------------------------------
     69        // Cookie-type settings.
     70
     71        // Lifespan of the cookie. If set to an integer, interpreted as a timestamp (0 for 'when user closes browser'), otherwise as a strtotime-compatible value ('tomorrow', etc).
     72        'cookie_expire' => '+10 years',
     73
     74        // The path on the server in which the cookie will be available on.
     75        'cookie_path' => null,
     76
     77        // The domain that the cookie is available to.
     78        'cookie_domain' => null,
     79
     80        // ----------------------------------------------------------
     81        // Database-type settings.
     82
     83        // The current user_id for which to load/save database-backed preferences.
    6684        'user_id' => null,
    6785
     
    82100    public function __construct($namespace='')
    83101    {
    84         $app =& App::getInstance();
     102        $app =& App::getInstance();
    85103
    86104        $this->_ns = $namespace;
     
    106124    public function initDB($recreate_db=false)
    107125    {
    108         $app =& App::getInstance();
    109         $db =& DB::getInstance();
     126        $app =& App::getInstance();
     127        $db =& DB::getInstance();
    110128
    111129        static $_db_tested = false;
     
    144162    public function setParam($params=null)
    145163    {
     164        // CLI scripts can't use prefs stored in HTTP-based protocols.
     165        if (defined('_CLI')
     166        && isset($params['storagetype'])
     167        && in_array($params['storagetype'], array('cookie', 'session'))) {
     168            $app->logMsg(sprintf('Storage type %s not available for CLI', $params['storagetype']), LOG_NOTICE, __FILE__, __LINE__);
     169        }
     170
     171        // Convert the legacy param 'persistent' to 'storagetype=database'.
     172        if (isset($params['persistent']) && $params['persistent'] && !isset($params['storagetype'])) {
     173            $params['storagetype'] = 'database';
     174        }
     175
    146176        if (isset($params) && is_array($params)) {
    147177            // Merge new parameters with old overriding only those passed.
     
    159189    public function getParam($param)
    160190    {
    161         $app =& App::getInstance();
     191        $app =& App::getInstance();
    162192
    163193        if (isset($this->_params[$param])) {
     
    190220     * @param  string $key          The name of the preference to modify.
    191221     * @param  string $val          The new value for this preference.
    192      * @param  bool   $persistent   Save this value forever? Set to false and value will exist as long as the session is in use.
    193222     */
    194223    public function set($key, $val)
     
    196225        $app =& App::getInstance();
    197226
    198         if ('' == $key) {
    199             $app->logMsg(sprintf('Key is empty (provided with value: %s)', $val), LOG_NOTICE, __FILE__, __LINE__);
     227        if (!is_string($key)) {
     228            $app->logMsg(sprintf('Key is not a string-compatible type (%s)', getDump($key)), LOG_NOTICE, __FILE__, __LINE__);
     229            return false;
     230        }
     231        if ('' == trim($key)) {
     232            $app->logMsg(sprintf('Key is empty (along with value: %s)', $val), LOG_NOTICE, __FILE__, __LINE__);
     233            return false;
     234        }
     235        if (!is_scalar($val) && !is_array($val) && !is_object($val)) {
     236            $app->logMsg(sprintf('Value is not a string-compatible type (%s=%s)', $key, getDump($val)), LOG_WARNING, __FILE__, __LINE__);
    200237            return false;
    201238        }
     
    205242        // - or the new value is different than the default
    206243        // - or there is a previously existing saved key.
    207         if (!isset($_SESSION['_prefs'][$this->_ns]['defaults'][$key])
    208         || $_SESSION['_prefs'][$this->_ns]['defaults'][$key] != $val
    209         || isset($_SESSION['_prefs'][$this->_ns]['saved'][$key])) {
    210             $_SESSION['_prefs'][$this->_ns]['saved'][$key] = $val;
    211             $app->logMsg(sprintf('Setting preference %s => %s', $key, truncate(getDump($val, true), 128, 'end')), LOG_DEBUG, __FILE__, __LINE__);
    212         } else {
    213             $app->logMsg(sprintf('Not setting preference %s => %s', $key, truncate(getDump($val, true), 128, 'end')), LOG_DEBUG, __FILE__, __LINE__);
    214         }
     244        switch ($this->getParam('storagetype')) {
     245        case 'session':
     246        case 'database': // DB prefs are saved in the session temporarily until they are saved.
     247            if (!isset($_SESSION['_prefs'][$this->_ns]['defaults'][$key])
     248            || $_SESSION['_prefs'][$this->_ns]['defaults'][$key] != $val
     249            || isset($_SESSION['_prefs'][$this->_ns]['saved'][$key])) {
     250                $_SESSION['_prefs'][$this->_ns]['saved'][$key] = $val;
     251                $app->logMsg(sprintf('Setting session preference %s => %s', $key, getDump($val, true)), LOG_DEBUG, __FILE__, __LINE__);
     252            } else {
     253                $app->logMsg(sprintf('Not setting session preference %s => %s', $key, getDump($val, true)), LOG_DEBUG, __FILE__, __LINE__);
     254            }
     255            break;
     256
     257        case 'cookie':
     258            $name = $this->_getCookieName($key);
     259            $val = json_encode($val);
     260            $app->setCookie($name, $val, $this->getParam('cookie_expire'), $this->getParam('cookie_path'), $this->getParam('cookie_domain'));
     261            $app->logMsg(sprintf('Setting cookie preference %s => %s', $key, $val), LOG_DEBUG, __FILE__, __LINE__);
     262            break;
     263        }
     264
    215265    }
    216266
     
    226276    {
    227277        $app =& App::getInstance();
    228         if (isset($_SESSION['_prefs'][$this->_ns]['saved']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved'])) {
    229             $app->logMsg(sprintf('Found %s in saved', $key), LOG_DEBUG, __FILE__, __LINE__);
    230             return $_SESSION['_prefs'][$this->_ns]['saved'][$key];
    231         } else if (isset($_SESSION['_prefs'][$this->_ns]['defaults']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['defaults'])) {
    232             $app->logMsg(sprintf('Found %s in defaults', $key), LOG_DEBUG, __FILE__, __LINE__);
    233             return $_SESSION['_prefs'][$this->_ns]['defaults'][$key];
    234         } else {
    235             $app->logMsg(sprintf('Key not found in prefs cache: %s', $key), LOG_DEBUG, __FILE__, __LINE__);
    236             return null;
     278
     279        switch ($this->getParam('storagetype')) {
     280        case 'session':
     281        case 'database':
     282            if (isset($_SESSION['_prefs'][$this->_ns]['saved']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved'])) {
     283                $app->logMsg(sprintf('Found %s in saved', $key), LOG_DEBUG, __FILE__, __LINE__);
     284                return $_SESSION['_prefs'][$this->_ns]['saved'][$key];
     285            } else if (isset($_SESSION['_prefs'][$this->_ns]['defaults']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['defaults'])) {
     286                $app->logMsg(sprintf('Found %s in defaults', $key), LOG_DEBUG, __FILE__, __LINE__);
     287                return $_SESSION['_prefs'][$this->_ns]['defaults'][$key];
     288            } else {
     289                $app->logMsg(sprintf('Key not found in prefs cache: %s', $key), LOG_DEBUG, __FILE__, __LINE__);
     290                return null;
     291            }
     292            break;
     293
     294        case 'cookie':
     295            $name = $this->_getCookieName($key);
     296            if ($this->exists($key)) {
     297                $val = json_decode($_COOKIE[$name]);
     298                $app->logMsg(sprintf('Found %s in cookie: %s', $key, getDump($val)), LOG_DEBUG, __FILE__, __LINE__);
     299                return $val;
     300            } else {
     301                $app->logMsg(sprintf('Key not found in cookie: %s', $key), LOG_DEBUG, __FILE__, __LINE__);
     302                return null;
     303            }
     304            break;
    237305        }
    238306    }
     
    246314    public function exists($key)
    247315    {
    248         return array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved']);
     316        switch ($this->getParam('storagetype')) {
     317        case 'session':
     318        case 'database':
     319            return array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved']);
     320
     321        case 'cookie':
     322            $name = $this->_getCookieName($key);
     323            return isset($_COOKIE[$name]);
     324        }
     325
    249326    }
    250327
     
    256333    public function delete($key)
    257334    {
    258         unset($_SESSION['_prefs'][$this->_ns]['saved'][$key]);
     335        $app =& App::getInstance();
     336
     337        switch ($this->getParam('storagetype')) {
     338        case 'session':
     339        case 'database':
     340            unset($_SESSION['_prefs'][$this->_ns]['saved'][$key]);
     341            break;
     342
     343        case 'cookie':
     344            if ($this->exists($key)) {
     345                // Just set the existing value to an empty string, which expires in the past.
     346                $name = $this->_getCookieName($key);
     347                $app->setCookie($name, '', time() - 86400);
     348                // Also unset the received cookie value, so it is unavailable.
     349                unset($_COOKIE[$name]);
     350            }
     351            break;
     352        }
     353
    259354    }
    260355
     
    265360    public function clear($focus='all')
    266361    {
     362
    267363        switch ($focus) {
    268364        case 'all' :
    269             $_SESSION['_prefs'][$this->_ns] = array(
    270                 'loaded' => false,
    271                 'load_datetime' => '1970-01-01',
    272                 'defaults' => array(),
    273                 'saved' => array(),
    274             );
    275             break;
    276 
     365            switch ($this->getParam('storagetype')) {
     366            case 'session':
     367            case 'database':
     368                $_SESSION['_prefs'][$this->_ns] = array(
     369                    'loaded' => false,
     370                    'load_datetime' => '1970-01-01',
     371                    'defaults' => array(),
     372                    'saved' => array(),
     373                );
     374                break;
     375            case 'cookie':
     376                foreach ($_COOKIE as $key => $value) {
     377                    // All cookie keys with our internal prefix. Use only the last part as the key.
     378                    if (preg_match('/^' . preg_quote(sprintf('strangecode-%s-', $this->_ns)) . '(.+)$/i', $key, $match)) {
     379                        $this->delete($match[1]);
     380                    }
     381                }
     382                break;
     383            }
     384            break;
    277385        case 'defaults' :
    278386            $_SESSION['_prefs'][$this->_ns]['defaults'] = array();
    279387            break;
    280 
    281388        case 'saved' :
    282389            $_SESSION['_prefs'][$this->_ns]['saved'] = array();
     
    298405    {
    299406        $app =& App::getInstance();
    300         $db =& DB::getInstance();
    301 
    302         // Skip this method if not using the db.
    303         if (true !== $this->getParam('persistent')) {
    304             return true;
    305         }
     407        $db =& DB::getInstance();
     408
     409        // Skip this method if not using the db.
     410        if ('database' != $this->getParam('storagetype')) {
     411            return true;
     412        }
    306413
    307414        $this->initDB();
    308415
    309416        // Prefs already loaded for this session.
    310         if (!$force && $this->_isLoaded()) {
    311             return true;
    312         }
     417        if (!$force && $this->_isLoaded()) {
     418            return true;
     419        }
    313420
    314421        // User_id must not be empty.
     
    322429
    323430        // Retrieve all prefs for this user and namespace.
    324         $qid = $db->query("
    325             SELECT pref_key, pref_value
    326             FROM " . $db->escapeString($this->getParam('db_table')) . "
    327             WHERE user_id = '" . $db->escapeString($this->getParam('user_id')) . "'
    328             AND pref_namespace = '" . $db->escapeString($this->_ns) . "'
    329             LIMIT 10000
    330         ");
    331         while (list($key, $val) = mysql_fetch_row($qid)) {
     431        $qid = $db->query("
     432            SELECT pref_key, pref_value
     433            FROM " . $db->escapeString($this->getParam('db_table')) . "
     434            WHERE user_id = '" . $db->escapeString($this->getParam('user_id')) . "'
     435            AND pref_namespace = '" . $db->escapeString($this->_ns) . "'
     436            LIMIT 10000
     437        ");
     438        while (list($key, $val) = mysql_fetch_row($qid)) {
    332439            $_SESSION['_prefs'][$this->_ns]['saved'][$key] = unserialize($val);
    333         }
    334 
    335         $app->logMsg(sprintf('Loaded %s prefs from database.', mysql_num_rows($qid)), LOG_DEBUG, __FILE__, __LINE__);
    336 
    337         // Data loaded only once per session.
    338         $_SESSION['_prefs'][$this->_ns]['loaded'] = true;
     440        }
     441
     442        $app->logMsg(sprintf('Loaded %s prefs from database.', mysql_num_rows($qid)), LOG_DEBUG, __FILE__, __LINE__);
     443
     444        // Data loaded only once per session.
     445        $_SESSION['_prefs'][$this->_ns]['loaded'] = true;
    339446        $_SESSION['_prefs'][$this->_ns]['load_datetime'] = date('Y-m-d H:i:s');
    340447
    341         return true;
     448        return true;
    342449    }
    343450
     
    354461    private function _isLoaded()
    355462    {
     463        if ('database' != $this->getParam('storagetype')) {
     464            return true;
     465        }
     466
    356467        if (isset($_SESSION['_prefs'][$this->_ns]['load_datetime'])
    357468        && strtotime($_SESSION['_prefs'][$this->_ns]['load_datetime']) > time() - $this->getParam('load_timeout')
     
    376487    {
    377488        $app =& App::getInstance();
    378         $db =& DB::getInstance();
    379 
    380         // Skip this method if not using the db.
    381         if (true !== $this->getParam('persistent')) {
    382             return true;
    383         }
     489        $db =& DB::getInstance();
     490
     491        // Skip this method if not using the db.
     492        if ('database' != $this->getParam('storagetype')) {
     493            return true;
     494        }
    384495
    385496        // User_id must not be empty.
     
    395506            $db->query("
    396507                DELETE FROM " . $db->escapeString($this->getParam('db_table')) . "
    397                 WHERE user_id = '" . $db->escapeString($this->getParam('user_id')) . "'
    398                 AND pref_namespace = '" . $db->escapeString($this->_ns) . "'
     508                WHERE user_id = '" . $db->escapeString($this->getParam('user_id')) . "'
     509                AND pref_namespace = '" . $db->escapeString($this->_ns) . "'
    399510            ");
    400511
     
    422533        return false;
    423534    }
     535
     536    /*
     537    *
     538    *
     539    * @access   public
     540    * @param
     541    * @return
     542    * @author   Quinn Comendant <quinn@strangecode.com>
     543    * @version  1.0
     544    * @since    02 May 2014 18:17:04
     545    */
     546    private function _getCookieName($key)
     547    {
     548        $app =& App::getInstance();
     549
     550        if (mb_strpos($key, sprintf('strangecode-%s', $this->_ns)) === 0) {
     551            $app->logMsg(sprintf('Invalid key name (%s). Leave off "strangecode-%s-" and it should work.', $key, $this->_ns), LOG_NOTICE, __FILE__, __LINE__);
     552        }
     553        return sprintf('strangecode-%s-%s', $this->_ns, $key);
     554    }
    424555}
    425556
  • trunk/lib/Upload.inc.php

    r468 r477  
    8686                if (!is_dir($params['upload_path'])) {
    8787                    $app->logMsg(sprintf('Attempting to auto-create upload directory: %s', $params['upload_path']), LOG_NOTICE, __FILE__, __LINE__);
    88                     if (phpversion() > '5') {
     88                    if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
    8989                        // Recursive.
    9090                        mkdir($params['upload_path'], isset($params['dest_dir_perms']) ? $params['dest_dir_perms'] : $this->getParam('dest_dir_perms'), true);
  • trunk/lib/Utilities.inc.php

    r474 r477  
    2929 * Print variable dump.
    3030 *
    31  * @param  mixed $var      Variable to dump.
    32  * @param  bool  $display   Hide the dump in HTML comments?
    33  * @param  bool  $var_dump Use var_dump instead of print_r.
     31 * @param  mixed    $var        The variable to dump.
     32 * @param  bool     $display    Print the dump in <pre> tags or hide it in html comments (non-CLI only).
     33 * @param  bool     $var_dump   Use var_dump instead of print_r.
     34 * @param  string   $file       Value of __FILE__.
     35 * @param  string   $line       Value of __LINE__
    3436 */
    3537function dump($var, $display=false, $var_dump=false, $file='', $line='')
    3638{
    37     if (empty($var)) {
    38         $var = '(nothing to dump)';
    39     }
    4039    if (defined('_CLI')) {
    41         echo "\nDUMP FROM: $file $line\n";
    42     } else {
    43         echo $display ? "\n<br />DUMP: <strong>$file $line</strong>\n<br /><pre>\n" : "\n\n\n<!--\n$file $line\n";
     40        echo "DUMP FROM: $file $line\n";
     41    } else {
     42        echo $display ? "\n<br />DUMP <strong>$file $line</strong><br /><pre>\n" : "\n<!-- DUMP $file $line\n";
    4443    }
    4544    if ($var_dump) {
    4645        var_dump($var);
    4746    } else {
    48         print_r($var);
     47        // Print human-readable descriptions of invisible types.
     48        if (null === $var) {
     49            echo '(null)';
     50        } else if (true === $var) {
     51            echo '(bool: true)';
     52        } else if (false === $var) {
     53            echo '(bool: false)';
     54        } else if (is_scalar($var) && '' === $var) {
     55            echo '(empty string)';
     56        } else if (is_scalar($var) && preg_match('/^\s+$/', $var)) {
     57            echo '(only white space)';
     58        } else {
     59            print_r($var);
     60        }
    4961    }
    5062    if (defined('_CLI')) {
    5163        echo "\n";
    5264    } else {
    53         echo $display ?  "\n</pre><br />\n" : "\n-->\n\n\n";
     65        echo $display ? "\n</pre><br />\n" : "\n-->\n";
    5466    }
    5567}
  • trunk/services/login.php

    r468 r477  
    3232$app->sslOn();
    3333
     34// Cookie-based storage preferences.
    3435require_once 'codebase/lib/Prefs.inc.php';
    3536$login_prefs = new Prefs('login');
    36 $login_prefs->setDefaults(array('username' => ''));
     37$login_prefs->setParam(array('storagetype' => 'cookie'));
    3738
    3839$frm['username'] = getFormdata('username', $login_prefs->get('username'));
Note: See TracChangeset for help on using the changeset viewer.