Changeset 467


Ignore:
Timestamp:
Feb 19, 2014 2:28:00 AM (10 years ago)
Author:
anonymous
Message:

Merged in changes from trunk to finish Eli's branch.

Location:
branches/eli_branch
Files:
33 edited

Legend:

Unmodified
Added
Removed
  • branches/eli_branch

  • branches/eli_branch/bin/module_maker/_config.inc.php

    r439 r467  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    2727    // Determine common site directory.
    2828    $common_base = realpath($_SERVER['argv'][1]);
    29    
     29
    3030    // First arg is path to current site. Realpath removes trailing /s
    3131    define('COMMON_BASE', $common_base);
  • branches/eli_branch/bin/module_maker/list_template.cli.php

    r444 r467  
    116116            $listrows[] = "<\x3fphp echo '9999-12-31' == \$list[\$i]['$field'] ? '' : date(\$app->getParam('date_format'), strtotime(\$list[\$i]['$field'])); \x3f>";
    117117        } else if (preg_match('/datetime/i', $type)) {
    118             $listrows[] = "<\x3fphp echo '0000-00-00 00:00:00' == \$list[\$i]['$field'] ? '' : date(\$app->getParam('date_format'), strtotime(\$list[\$i]['$field'])); \x3f>";
     118            $listrows[] = "<\x3fphp echo Validator::validateStrDate(\$list[\$i]['$field']) ? date(\$app->getParam('date_format'), strtotime(\$list[\$i]['$field'])) : ''; \x3f>";
    119119        } else if (preg_match('/date/i', $type)) {
    120             $listrows[] = "<\x3fphp echo '0000-00-00' == \$list[\$i]['$field'] ? '' : date(\$app->getParam('date_format'), strtotime(\$list[\$i]['$field'])); \x3f>";
     120            $listrows[] = "<\x3fphp echo Validator::validateStrDate(\$list[\$i]['$field']) ? date(\$app->getParam('date_format'), strtotime(\$list[\$i]['$field'])) : ''; \x3f>";
    121121        } else if (preg_match('/(amount|_rate)/i', $field)) {
    122122            $listrows[] = "<\x3fphp printf('$%01.2f', \$list[\$i]['$field']); \x3f>";
     
    140140<\x3fphp \$fv->printErrorMessages(); \x3f>
    141141
    142 <div id="commandbox">
     142<div class="commandbox">
    143143<form action="<\x3fphp echo oTxt(\$_SERVER['PHP_SELF']); \x3f>" method="get">
    144144<\x3fphp \$app->printHiddenSession(false); \x3f>
     
    148148    <input type="text" class="sc-small" size="20" name="search_query" value="<\x3fphp echo getFormData('search_query'); \x3f>" title="<\x3fphp echo oTxt(_("Fields searched: __///__.")); \x3f>" />
    149149    <select name="filter___///__">
    150         <\x3fphp // printSelectForm('__///___tbl', "CONCAT(__///___id, '&mdash;', city, '&mdash;', title)", '__///___id', getFormData('filter___///__'), array('Any __///__'), 'ORDER BY __///__ ASC'); \x3f>
     150        <\x3fphp // printSelectForm('__///___tbl', "CONCAT(__///___id, '&mdash;', city, '&mdash;', title)", '__///___id', getFormData('filter___///__'), array('' => 'Any __///__'), 'ORDER BY __///__ ASC'); \x3f>
    151151    </select>
    152152    <input type="submit" name="list" value="<\x3fphp echo _("Search"); \x3f>" />
  • branches/eli_branch/bin/module_maker/skel/adm_list.ihtml

    r320 r467  
    22<?php $fv->printErrorMessages(); ?>
    33
    4 <div id="commandbox">
     4<div class="commandbox">
    55    <span class="sc-nowrap commandtext"><a href="<?php echo $app->oHREF($_SERVER['PHP_SELF'] . '?op=add'); ?>"><?php echo _("Add %ITEM_TITLE%"); ?></a></span>
    66    <form action="<?php echo oTxt($_SERVER['PHP_SELF']); ?>" method="get" class="sc-form">
     
    88        <input type="text" class="sc-small" size="20" name="search_query" value="<?php echo getFormData('search_query'); ?>" title="<?php echo oTxt(_("Fields searched: __///__ %SEARCH_FIELDS%.")); ?>" />
    99        <select name="filter___///__" class="sc-small">
    10             <?php // printSelectForm('__///___tbl', "CONCAT(__///___id, '&mdash;', city, '&mdash;', title)", '__///___id', getFormData('filter___///__'), array('Any __///__'), 'ORDER BY __///__ ASC'); ?>
     10            <?php // printSelectForm('__///___tbl', "CONCAT(__///___id, '&mdash;', city, '&mdash;', title)", '__///___id', getFormData('filter___///__'), array('' => 'Any __///__'), 'ORDER BY __///__ ASC'); ?>
    1111        </select>
    1212        <input type="submit" value="<?php echo _("Filter"); ?>" />
  • branches/eli_branch/css/admin.inc.css

    r365 r467  
    11/**
    2  * admin.css
     2 * admin.inc.css
    33 *
    4  * CSS for the Strangecode administration sites.
     4 * CSS for a Strangecode administration site.
    55 */
    66
     
    212212/* BEAU: The old stuff that was here...
    213213#content table {
    214          background-color: #FFF; 
     214         background-color: #FFF;
    215215}
    216216
     
    249249
    250250/* Should this be an ID??? */
    251 #commandbox
     251#commandbox, .commandbox
    252252{
    253253    padding: 3px 5px 5px 5px;
     
    264264}
    265265
    266 #commandbox .form {
     266#commandbox .form, .commandbox .form, #commandbox form, .commandbox form, {
    267267    margin-top: 8px;
    268268}
     
    301301}
    302302
    303 #footer a:link, 
     303#footer a:link,
    304304#footer a:visited {
    305305    color: #333;
     
    307307}
    308308
    309 #footer a:active, 
     309#footer a:active,
    310310#footer a:hover {
    311311    color: #333;
  • branches/eli_branch/css/admin2.inc.css

    r436 r467  
    11/**
    2  * admin.css
     2 * admin2.inc.css
    33 *
    44 * CSS for the Strangecode administration sites.
     
    9595/*     float: left; */
    9696    min-width: 10em;
    97     width: 10em !important; 
     97    width: 10em !important;
    9898    _width: 10em;  /* IE6 hack */
    9999    margin: 0 0 10px 0;
     
    211211}
    212212
    213 table.list td, #commandbox table td {
     213table.list td, #commandbox table td, .commandbox table td {
    214214    font-size: 70%;
    215215    padding: 2px 6px 2px 2px;
     
    218218}
    219219
    220 table.list tr:hover, #commandbox table tr:hover {
     220table.list tr:hover, #commandbox table tr:hover, .commandbox table tr:hover {
    221221    background: #FAF8C7;
    222222}
     
    224224/*_____________________ COMMANDS ____________________*/
    225225
    226 /* Should this be an ID??? */
    227 #commandbox
     226/* We were using an ID, now using class. */
     227#commandbox, .commandbox
    228228{
    229229    padding: 3px 5px 5px 5px;
     
    240240}
    241241
    242 #commandbox form {
     242#commandbox form, .commandbox form {
    243243    margin: 8px 0 0 0;
    244244}
     
    277277}
    278278
    279 #footer a:link, 
     279#footer a:link,
    280280#footer a:visited {
    281281    color: #333;
     
    283283}
    284284
    285 #footer a:active, 
     285#footer a:active,
    286286#footer a:hover {
    287287    color: #333;
     
    304304    margin: 1em 0 0 0;
    305305    padding: 0;
    306     border: 0; 
     306    border: 0;
    307307}
    308308
    309309legend {
    310310    font-size: 90%;
    311     font-weight: bold; 
     311    font-weight: bold;
    312312    padding: 0;
    313313    margin: 0;
     
    318318.sc-small,
    319319.sc-medium,
    320 .sc-large, 
     320.sc-large,
    321321.sc-full,
    322322#sc-captcha-input,
  • branches/eli_branch/css/codebase.inc.css

    r394 r467  
    11/**
    2  * codebase.css
     2 * codebase.inc.css
    33 *
    44 * CSS used in codebase templates and scripts that generate HTML. Do not arbitrarily
     
    1818.sc-msg-success { color: #090; }
    1919.sc-msg-notice { color: #C60; }
    20 .sc-msg-warning, 
     20.sc-msg-warning,
    2121.sc-msg-error { color: #f00; }
    2222.sc-msg > .sc-msg-success,
     
    3939    border-spacing: 0;
    4040}
    41 #sc-pedit-versions-table th, 
     41#sc-pedit-versions-table th,
    4242#sc-pedit-versions-table td {
    4343    border-bottom: 1px solid #CC9;
  • branches/eli_branch/css/utilities.inc.css

    r406 r467  
    11/**
    2  * utilities.css
     2 * utilities.inc.css
    33 *
    44 * CSS used often in Strangecode applications. Do not arbitrarily
     
    1414input.sc-medium, textarea.sc-medium, select.sc-medium,
    1515input.sc-large, textarea.sc-large, select.sc-large,
    16 input.sc-full, textarea.sc-full, select.sc-full { margin: 0 0.5em 0 0; }
     16input.sc-full, textarea.sc-full, select.sc-full { margin: 0 0.5em 0 0; padding: 3px 0.25em; border-width: 1px; }
    1717
    18 input.sc-tiny, textarea.sc-tiny, select.sc-tiny, label.sc-tiny          { width: 4.75em; }
    19 input.sc-small, textarea.sc-small, select.sc-small, label.sc-small      { width: 10em; }
    20 input.sc-medium, textarea.sc-medium, select.sc-medium, label.sc-medium  { width: 20.5em; }
    21 input.sc-large, textarea.sc-large, select.sc-large, label.sc-large      { width: 41.5em; }
     18/*
     19The following widths are calculated using `width = (maxwidth - (1.2 * multiple)) / multiple`
     20where width is the saught value, maxwidth is the width of a sc-large, and multiple is the number
     21of times an element fits within maxwidth (i.e. sc-tiny has a multiple of 8).
     22The values are dependent on the margin, padding, and border set above.
     23*/
     24input.sc-tiny, textarea.sc-tiny, select.sc-tiny, label.sc-tiny          { width: 4.54em; }
     25input.sc-small, textarea.sc-small, select.sc-small, label.sc-small      { width: 10.15em; }
     26input.sc-medium, textarea.sc-medium, select.sc-medium, label.sc-medium  { width: 21.42em; }
     27input.sc-large, textarea.sc-large, select.sc-large, label.sc-large      { width: 44em; }
    2228input.sc-full, textarea.sc-full, select.sc-full, label.sc-full          { width: 100%; }
    2329
     
    4753}
    4854.sc-note:hover { cursor: help; }
     55.sc-ellipsis {
     56    overflow: hidden;
     57    white-space: nowrap;
     58    text-overflow: ellipsis;
     59}
    4960
    5061/* .sc-pkg class wraps enclosing block element around inner floated elements */
  • branches/eli_branch/lib/ACL.inc.php

    r439 r467  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    2323/*
    2424* ACL.inc.php
    25 * 
     25*
    2626* Uses the ARO/ACO/AXO model of Access Control Lists.
    2727* Uses Modified Preorder Tree Traversal to maintain a tree-structure.
    2828* See: http://www.sitepoint.com/print/hierarchical-data-database
    2929* Includes a command-line tool for managing rights (codebase/bin/acl.cli.php).
    30 * 
     30*
    3131*
    3232* @author   Quinn Comendant <quinn@strangecode.com>
     
    4141    // Configuration parameters for this object.
    4242    private $_params = array(
    43        
     43
    4444        // If false nothing will be cached or retrieved. Useful for testing realtime data requests.
    4545        'enable_cache' => true,
     
    9494    {
    9595        $app =& App::getInstance();
    96    
     96
    9797        if (isset($params) && is_array($params)) {
    9898            // Merge new parameters with old overriding only those passed.
     
    113113    {
    114114        $app =& App::getInstance();
    115    
     115
    116116        if (isset($this->_params[$param])) {
    117117            return $this->_params[$param];
     
    145145                $app->logMsg(sprintf('Dropping and recreating tables acl_tbl, aro_tbl, aco_tbl, axo_tbl.', null), LOG_INFO, __FILE__, __LINE__);
    146146            }
    147            
     147
    148148            // acl_tbl
    149149            $db->query("
     
    171171                $qid = $db->query("SELECT 1 FROM acl_tbl");
    172172                if (mysql_num_rows($qid) == 0) {
    173                     $qid = $db->query("REPLACE INTO acl_tbl VALUES ('1', '1', '1', 'deny', NOW())");                   
    174                 }               
     173                    $qid = $db->query("REPLACE INTO acl_tbl VALUES ('1', '1', '1', 'deny', NOW())");
     174                }
    175175            }
    176176
     
    202202                    $qid = $db->query("SELECT 1 FROM {$a_o}_tbl WHERE name = 'root'");
    203203                    if (mysql_num_rows($qid) == 0) {
    204                         $qid = $db->query("REPLACE INTO {$a_o}_tbl (name, lft, rgt, added_datetime) VALUES ('root', 1, 2, NOW())");                   
    205                     }                   
     204                        $qid = $db->query("REPLACE INTO {$a_o}_tbl (name, lft, rgt, added_datetime) VALUES ('root', 1, 2, NOW())");
     205                    }
    206206                }
    207207
     
    228228        $app =& App::getInstance();
    229229        $db =& DB::getInstance();
    230        
     230
    231231        $this->initDB();
    232        
     232
    233233        switch ($type) {
    234234        case 'aro' :
     
    246246            break;
    247247        }
    248        
     248
    249249        // If $parent is null, use root object.
    250250        if (is_null($parent)) {
    251251            $parent = 'root';
    252252        }
    253        
     253
    254254        // Ensure node and parent name aren't empty.
    255255        if ('' == trim($name) || '' == trim($parent)) {
     
    257257            return false;
    258258        }
    259        
     259
    260260        // Ensure node is unique.
    261261        $qid = $db->query("SELECT 1 FROM $tbl WHERE name = '" . $db->escapeString($name) . "'");
     
    264264            return false;
    265265        }
    266        
     266
    267267        // Select the rgt of $parent.
    268268        $qid = $db->query("SELECT rgt FROM $tbl WHERE name = '" . $db->escapeString($parent) . "'");
     
    275275        $db->query("UPDATE $tbl SET lft = lft + 2 WHERE lft >= $parent_rgt");
    276276        $db->query("UPDATE $tbl SET rgt = rgt + 2 WHERE rgt >= $parent_rgt");
    277        
     277
    278278        // Insert new node just below parent. Lft is parent's old rgt.
    279279        $db->query("
    280             INSERT INTO $tbl (name, lft, rgt, added_datetime) 
     280            INSERT INTO $tbl (name, lft, rgt, added_datetime)
    281281            VALUES ('" . $db->escapeString($name) . "', $parent_rgt, $parent_rgt + 1, NOW())
    282282        ");
     
    315315        $app =& App::getInstance();
    316316        $db =& DB::getInstance();
    317        
     317
    318318        $this->initDB();
    319319
     
    336336            break;
    337337        }
    338        
     338
    339339        // Ensure node name isn't empty.
    340340        if ('' == trim($name)) {
     
    342342            return false;
    343343        }
    344        
     344
    345345        // Select the lft and rgt of $name to use for selecting children and reordering transversals.
    346346        $qid = $db->query("SELECT lft, rgt FROM $tbl WHERE name = '" . $db->escapeString($name) . "'");
     
    349349            return false;
    350350        }
    351        
     351
    352352        // Remove node and all children of node, as well as acl_tbl links.
    353353        $db->query("
    354             DELETE $tbl, acl_tbl 
     354            DELETE $tbl, acl_tbl
    355355            FROM $tbl
    356356            LEFT JOIN acl_tbl ON ($tbl.$primary_key = acl_tbl.$primary_key)
     
    366366        return true;
    367367    }
    368    
     368
    369369    // Alias functions for the different object types.
    370370    public function removeRequestObject($name)
     
    397397        $app =& App::getInstance();
    398398        $db =& DB::getInstance();
    399        
     399
    400400        $this->initDB();
    401401
     
    418418            break;
    419419        }
    420        
     420
    421421        // If $new_parent is null, use root object.
    422422        if (is_null($new_parent)) {
    423423            $new_parent = 'root';
    424424        }
    425        
     425
    426426        // Ensure node and parent name aren't empty.
    427427        if ('' == trim($name) || '' == trim($new_parent)) {
     
    429429            return false;
    430430        }
    431        
     431
    432432        // Select the lft and rgt of $name to use for selecting children and reordering transversals.
    433433        $qid = $db->query("SELECT lft, rgt FROM $tbl WHERE name = '" . $db->escapeString($name) . "'");
     
    436436            return false;
    437437        }
    438        
     438
    439439        // Total number of transversal values (that is, the count of self plus all children times two).
    440440        $total_transversal_value = ($rgt - $lft + 1);
     
    446446            return false;
    447447        }
    448        
     448
    449449        // Ensure the new parent is not a child of the node being moved.
    450450        if ($new_parent_rgt <= $rgt && $new_parent_rgt >= $lft) {
     
    452452            return false;
    453453        }
    454        
     454
    455455        // Collect unique ids of all nodes being moved. The transversal numbers will become duplicated so these will be needed to identify these.
    456456        $qid = $db->query("
     
    472472        // Apply transformation to new parent rgt also.
    473473        $new_parent_rgt = $new_parent_rgt > $rgt ? $new_parent_rgt - $total_transversal_value : $new_parent_rgt;
    474        
     474
    475475        // Update transversal values of moved node and children.
    476476        $db->query("
    477             UPDATE $tbl SET 
     477            UPDATE $tbl SET
    478478                lft = lft - ($lft - $new_parent_rgt),
    479479                rgt = rgt - ($lft - $new_parent_rgt)
     
    488488        return true;
    489489    }
    490    
     490
    491491    // Alias functions for the different object types.
    492492    public function moveRequestObject($name, $new_parent=null)
     
    502502        return $this->move($name, $new_parent, 'axo');
    503503    }
    504    
     504
    505505    /*
    506506    * Add an entry to the acl_tbl to allow (or deny) a truple with the specified
     
    528528        $aco = is_null($aco) ? 'root' : $aco;
    529529        $axo = is_null($axo) ? 'root' : $axo;
    530        
     530
    531531        // Flush old cached values.
    532532        $cache_hash = $aro . '|' . $aco . '|' . $axo;
     
    552552        // Access must be 'allow' or 'deny'.
    553553        $allow = 'allow' == $access ? 'allow' : 'deny';
    554        
     554
    555555        $db->query("REPLACE INTO acl_tbl VALUES ('$aro_id', '$aco_id', '$axo_id', '$allow', NOW())");
    556556        $app->logMsg(sprintf('Set %s: %s -> %s -> %s.', $allow, $aro, $aco, $axo), LOG_INFO, __FILE__, __LINE__);
    557        
     557
    558558        return true;
    559559    }
     
    577577        return $this->grant($aro, $aco, $axo, 'deny');
    578578    }
    579    
     579
    580580    /*
    581581    * Delete an entry from the acl_tbl completely to allow other permissions to cascade down.
     
    610610        $aco = is_null($aco) ? 'root' : $aco;
    611611        $axo = is_null($axo) ? 'root' : $axo;
    612        
     612
    613613        // Flush old cached values.
    614614        $cache_hash = $aro . '|' . $aco . '|' . $axo;
     
    621621            return false;
    622622        }
    623        
     623
    624624        $qid = $db->query("
    625625            DELETE acl_tbl
     
    632632
    633633        $app->logMsg(sprintf('Deleted %s acl_tbl links: %s -> %s -> %s', mysql_affected_rows($db->getDBH()), $aro, $aco, $axo), LOG_INFO, __FILE__, __LINE__);
    634        
     634
    635635        return true;
    636636    }
    637    
     637
    638638    /*
    639639    * Calculates the most specific cascading privilege found for a requested
    640     * ARO -> ACO -> AXO entry. Returns FALSE if the entry is denied. By default, 
     640    * ARO -> ACO -> AXO entry. Returns FALSE if the entry is denied. By default,
    641641    * all entries are denied, unless some point in the hierarchy is set to "allow."
    642642    *
     
    654654        $app =& App::getInstance();
    655655        $db =& DB::getInstance();
    656        
     656
    657657        $this->initDB();
    658658
     
    661661        $aco = is_null($aco) || '' == trim($aco) ? 'root' : $aco;
    662662        $axo = is_null($axo) || '' == trim($axo) ? 'root' : $axo;
    663        
     663
    664664        $cache_hash = $aro . '|' . $aco . '|' . $axo;
    665665        if ($this->cache->exists($cache_hash) && true === $this->getParam('enable_cache')) {
     
    687687            $this->cache->set($cache_hash, $access);
    688688        }
    689        
     689
    690690        if ('allow' == $access) {
    691691            $app->logMsg(sprintf('Access granted: %s -> %s -> %s.', $aro, $aco, $axo), LOG_DEBUG, __FILE__, __LINE__);
     
    697697    }
    698698
     699    /*
     700    * Bounce user if they are denied access. Because this function calls dieURL() it must be called before any other HTTP header output.
     701    *
     702    * @access   public
     703    * @param    string $aro Identifier of an existing ARO object.
     704    * @param    string $aco Identifier of an existing ACO object (or null to use root).
     705    * @param    string $axo Identifier of an existing AXO object (or null to use root).
     706    * @param    string $message The text description of a message to raise.
     707    * @param    int    $type    The type of message: MSG_NOTICE,
     708    *                           MSG_SUCCESS, MSG_WARNING, or MSG_ERR.
     709    * @param    string $file    __FILE__.
     710    * @param    string $line    __LINE__.
     711    * @author   Quinn Comendant <quinn@strangecode.com>
     712    * @version  1.0
     713    * @since    20 Jan 2014 12:09:03
     714    */
     715    public function requireAllow($aro, $aco=null, $axo=null, $message='', $type=MSG_NOTICE, $file=null, $line=null)
     716    {
     717        $app =& App::getInstance();
     718
     719        if (!$this->check($aro, $aco, $axo)) {
     720            $message = '' == trim($message) ? sprintf(_("You have insufficient privileges to view <em>%s %s</em>"), $aco, $axo) : $message;
     721            $app->raiseMsg($message, $type, $file, $line);
     722            $app->dieBoomerangURL();
     723        }
     724    }
     725
    699726} // End class.
    700 
    701 
  • branches/eli_branch/lib/App.inc.php

    r449 r467  
    403403            $this->db->close();
    404404        }
     405        $mem_current = memory_get_usage();
     406        $mem_peak = memory_get_peak_usage();
    405407        $this->timer->stop('_app');
    406         $this->logMsg(sprintf('Script ended gracefully. Execution time: %s. Number of db queries: %s.', $this->timer->getTime('_app'), $num_queries), LOG_DEBUG, __FILE__, __LINE__);
     408        $this->logMsg(sprintf('Script ended gracefully. Execution time: %s. Number of db queries: %s. Memory usage: %s. Peak memory: %s.', $this->timer->getTime('_app'), $num_queries, $mem_current, $mem_peak), LOG_DEBUG, __FILE__, __LINE__);
    407409    }
    408410
     
    961963            // urlencode is not used here, not for form data!
    962964            $query_args = array_merge($this->_carry_queries, $one_time_carry_queries);
    963             foreach ($query_args as $key=>$val) {
    964                 printf('<input type="hidden" name="%s" value="%s" />', $key, $val);
    965             }
     965            foreach ($query_args as $key => $val) {
     966                if (is_array($val)) {
     967                    foreach ($val as $subval) {
     968                        printf('<input type="hidden" name="%s[]" value="%s" />', $key, $subval);
     969                    }
     970                } else {
     971                    printf('<input type="hidden" name="%s" value="%s" />', $key, $val);
     972                }
     973            }
     974            unset($query_args, $key, $val, $subval);
    966975        }
    967976
     
    12381247        }
    12391248    }
    1240 
    1241 
    12421249} // End.
  • branches/eli_branch/lib/Auth_SQL.inc.php

    r449 r467  
    424424            // No login: failed authentication!
    425425            return false;
     426        }
     427
     428        // Convert 'priv' to 'user_type' nomenclature to support older implementations.
     429        if (isset($user_data['priv'])) {
     430            $user_data['user_type'] = $user_data['priv'];
    426431        }
    427432
     
    649654            }
    650655            $app->logMsg(sprintf('User_id %s (%s) session expired: %s', $this->get('user_id'), $this->get('username'), join(', ', $expire_reasons)), LOG_INFO, __FILE__, __LINE__);
    651         } else {
    652             $app->logMsg(sprintf('Session not authenticated: %s', getDump($_SESSION['_auth_sql'][$this->_ns])), LOG_DEBUG, __FILE__, __LINE__);
    653656        }
    654657
  • branches/eli_branch/lib/Cache.inc.php

    r439 r467  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    3131 * @since   2001
    3232 */
    33  
     33
    3434// Flags.
    3535define('CACHE_ALLOW_OVERSIZED', 1);
     
    4242    // Configuration parameters for this object.
    4343    private $_params = array(
    44        
     44
    4545        // If false nothing will be cached or retrieved. Useful for testing realtime data requests.
    4646        'enabled' => true,
     
    4848        // The maximum size in bytes of any one variable.
    4949        'item_size_limit' => 4194304, // 4 MB
    50        
     50
    5151        // The maximum size in bytes before the cache will begin flushing out old items.
    5252        'stack_size_limit' => 4194304, // 4 MB
    53        
     53
    5454        // The minimum items to keep in the cache regardless of item or cache size.
    5555        'min_items' => 5,
    5656    );
    57    
     57
    5858    /*
    5959    * Constructor
     
    6868    {
    6969        $app =& App::getInstance();
    70        
     70
    7171        $this->_ns = $namespace;
    7272
     
    7575            $this->setParam(array('enabled' => false));
    7676        }
    77        
     77
    7878        if (!isset($_SESSION['_cache'][$this->_ns])) {
    7979            $this->clear();
     
    127127    {
    128128        $app =& App::getInstance();
    129    
     129
    130130        if (isset($this->_params[$param])) {
    131131            return $this->_params[$param];
     
    138138    /**
    139139     * Stores a new variable in the session cache. The $key should not be numeric
    140      * because the array_shift function will reset the key to the next largest 
     140     * because the array_shift function will reset the key to the next largest
    141141     * int key. Weird behavior I can't understand. For example $cache["123"] will become $cache[0]
    142142     *
     
    168168            $app->logMsg(sprintf('Serialized variable (%s bytes) more than stack_size_limit (%s bytes).', $var_len, $this->getParam('stack_size_limit')), LOG_NOTICE, __FILE__, __LINE__);
    169169            return false;
    170         }       
     170        }
    171171
    172172        // Remove any value already stored under this key.
     
    253253        }
    254254    }
    255    
     255
    256256    /*
    257257    * Delete all existing items from the cache.
  • branches/eli_branch/lib/Email.inc.php

    r439 r467  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
    2121 */
    2222
    23 /**
    24  * Email.inc.php
    25  *
    26  * Easy email template usage.
    27  *
    28  * @author  Quinn Comendant <quinn@strangecode.com>
    29  * @version 1.0
    30  *
    31  
    32 // Example.
     23/*
     24* Email.inc.php
     25*
     26* Easy email template usage.
     27*
     28* @author  Quinn Comendant <quinn@strangecode.com>
     29* @version 1.0
     30*
     31* Example of use:
     32---------------------------------------------------------------------
     33// Setup email object.
    3334$email = new Email(array(
    3435    'to' => array($frm['email'], 'q@lovemachine.local'),
     
    4950    $app->logMsg(sprintf('Error sending confirmation email to address %s', $frm['email']), LOG_NOTICE, __FILE__, __LINE__);
    5051}
    51 
    52  *
    53  */
     52---------------------------------------------------------------------
     53*/
     54
    5455class Email {
    5556
     
    6162        'headers' => null,
    6263        'regex' => null,
    63        
     64
    6465        // A single carriage return (\n) should terminate lines for locally injected mail.
    6566        // A carriage return + line-feed (\r\n) should be used if sending mail directly with SMTP.
    6667        'crlf' => "\n",
    67        
     68
    6869        // RFC 2822 says line length MUST be no more than 998 characters, and SHOULD be no more than 78 characters, excluding the CRLF.
    6970        // http://mailformat.dan.info/body/linelength.html
     
    120121    {
    121122        $app =& App::getInstance();
    122    
     123
    123124        if (isset($params) && is_array($params)) {
    124125            // Enforce valid email addresses.
     
    147148    {
    148149        $app =& App::getInstance();
    149    
     150
    150151        if (isset($this->_params[$param])) {
    151152            return $this->_params[$param];
     
    167168    {
    168169        $app =& App::getInstance();
    169    
     170
    170171        // Load file, using include_path.
    171172        if (!$this->_template = file_get_contents($template, true)) {
     
    191192    {
    192193        $app =& App::getInstance();
    193    
     194
    194195        if ('' == trim($string)) {
    195196            $app->logMsg(sprintf('Empty string provided.', null), LOG_ERR, __FILE__, __LINE__);
     
    215216    {
    216217        $app =& App::getInstance();
    217    
     218
    218219        // Ensure template exists.
    219220        if (!isset($this->_template)) {
     
    285286        $final_body = isset($this->_template_replaced) ? $this->_template_replaced : $this->_template;
    286287        if (false !== $this->getParam('wrap')) {
    287             $final_body = wordwrap($final_body, $this->getParam('line_length'), $this->getParam('crlf'));           
     288            $final_body = wordwrap($final_body, $this->getParam('line_length'), $this->getParam('crlf'));
    288289        }
    289290
     
    320321            $envelope_sender_header = sprintf('-f %s', $envelope_sender_address);
    321322        } else {
    322             $envelope_sender_header = '';           
     323            $envelope_sender_header = '';
    323324        }
    324325
     
    331332        }
    332333
    333         // Send email without 5th parameter if safemode is enabled. 
     334        // Send email without 5th parameter if safemode is enabled.
    334335        if (ini_get('safe_mode')) {
    335336            $ret = mb_send_mail($final_to, $this->_params['subject'], $final_body, $final_headers);
     
    337338            $ret = mb_send_mail($final_to, $this->_params['subject'], $final_body, $final_headers, $envelope_sender_header);
    338339        }
    339        
     340
    340341        // Ensure message was successfully accepted for delivery.
    341342        if ($ret) {
     
    345346            $app->logMsg(sprintf('Email failure with parameters: %s, %s, %s, %s', $final_to, $this->_params['subject'], str_replace("\r\n", '\r\n', $final_headers), $envelope_sender_header), LOG_NOTICE, __FILE__, __LINE__);
    346347            return false;
    347         } 
     348        }
    348349    }
    349350
     
    366367    {
    367368        $app =& App::getInstance();
    368    
     369
    369370        // If an array, check values recursively.
    370371        if (is_array($email)) {
  • branches/eli_branch/lib/FormValidator.inc.php

    r450 r467  
    481481            $app->logMsg(sprintf('The email address %s is not valid.', oTxt($email)), LOG_DEBUG, __FILE__, __LINE__);
    482482            return false;
    483             break;
    484483
    485484        case parent::EMAIL_LENGTH_FAIL :
     
    488487            $app->logMsg(sprintf('The email address %s must contain less than 256 characters.', oTxt($email)), LOG_DEBUG, __FILE__, __LINE__);
    489488            return false;
    490             break;
    491489
    492490        case parent::EMAIL_MX_FAIL :
     
    495493            $app->logMsg(sprintf('The email address %s does not have a valid domain name.', oTxt($email)), LOG_INFO, __FILE__, __LINE__);
    496494            return false;
    497             break;
    498495
    499496        case parent::EMAIL_SUCCESS :
    500497        default :
    501498            return true;
    502             break;
    503499        }
    504500    }
     
    535531        $app =& App::getInstance();
    536532
    537         if (parent::validateStrDate(getFormData($form_name))) {
     533        if (parent::validateStrDate(getFormData($form_name, ''))) {
    538534            return true;
    539535        } else {
  • branches/eli_branch/lib/Hierarchy.inc.php

    r439 r467  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    2323/**
    2424 * Hierarchy.inc.php
    25  * 
     25 *
    2626 * Objective: This class provides the tools to organize pieces of data into a
    2727 * hierarchy of nodes. Any form of data (article, product, image) can be
     
    116116    {
    117117            $app =& App::getInstance();
    118    
     118
    119119            if (!isset($child_type) || !isset($child_id)) {
    120120            if ($this->node_init) {
     
    150150    {
    151151            $app =& App::getInstance();
    152    
     152
    153153            if (preg_match('/^([[:alnum:]]+)__-?([[:digit:]]+)$/', $node, $node_parts)) {
    154154            return array('node_type' => $node_parts[1], 'node_id' => $node_parts[2]);
     
    171171        $app =& App::getInstance();
    172172        $db =& DB::getInstance();
    173    
     173
    174174        if (!isset($child_type) || !isset($child_id)) {
    175175            if ($this->node_init) {
     
    250250        $app =& App::getInstance();
    251251        $db =& DB::getInstance();
    252    
     252
    253253        if (!isset($child_type) || !isset($child_id)) {
    254254            if ($this->node_init) {
     
    377377        $app =& App::getInstance();
    378378        $db =& DB::getInstance();
    379    
     379
    380380        if (!isset($child_type) || !isset($child_id)) {
    381381            if ($this->node_init) {
     
    428428        $app =& App::getInstance();
    429429        $db =& DB::getInstance();
    430    
     430
    431431        if (!isset($child_type) || !isset($child_id)) {
    432432            if ($this->node_init) {
     
    472472        $app =& App::getInstance();
    473473        $db =& DB::getInstance();
    474    
     474
    475475        if (!isset($child_type) || !isset($child_id)) {
    476476            if ($this->node_init) {
     
    564564    {
    565565        $app =& App::getInstance();
    566    
     566
    567567        if (!isset($child_type) || !isset($child_id)) {
    568568            if ($this->node_init) {
     
    625625    {
    626626        $db =& DB::getInstance();
    627    
     627
    628628        static $output = array();
    629629        static $return_flag;
     
    680680        $app =& App::getInstance();
    681681        $db =& DB::getInstance();
    682    
     682
    683683        if (!isset($child_type) || !isset($child_id)) {
    684684            if ($this->node_init) {
     
    731731    {
    732732        $app =& App::getInstance();
    733    
     733
    734734        static $output = array();
    735735        static $is_a_leaf = array();
     
    804804    {
    805805        $db =& DB::getInstance();
    806    
     806
    807807        // Reset all the category counters to zero.
    808808        $db->query("UPDATE node_tbl SET subnode_quantity = 0");
     
    828828    {
    829829        $db =& DB::getInstance();
    830    
     830
    831831        $db->query("
    832832            UPDATE node_tbl
  • branches/eli_branch/lib/Image.inc.php

    r439 r467  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    4949            // Pattern passed to glob() with $id to match image filenames.
    5050            'filename_pattern' => '%s*',
    51            
     51
    5252            // The path to the image source directory. (Ex: /var/www/htdocs/images)
    5353            'base_path' => '',
    54            
     54
    5555            // The URL to the image directory. (Ex: /images)
    5656            'base_url' => '',
    57            
     57
    5858            // Image to use in the case of a missing image.
    5959            'default_image_file' => '',
     
    6161        $this->_params = array_merge($defaults, $params);
    6262    }
    63    
     63
    6464    /**
    6565     * Tests if an image with specified id exists on the file system.
     
    7777        $filepath = preg_match('!://!', $src) ? $src : getenv('DOCUMENT_ROOT') . $src;
    7878        // Use exif_imagetype to check not only file existence but that of a valid image.
     79        // The return value is the same value that getimagesize() returns in index 2 but exif_imagetype() is much faster.
    7980        return false != @exif_imagetype($filepath);
    8081    }
    81    
     82
    8283    /**
    8384     * Returns the value from getimagesize().
     
    8586     * @access  public
    8687     * @param   string  $id     Unique image identifier.
    87      * @param   int     $key    Which element from the array returned by getimagesize: 
    88      *                   - Index 0 contains the width of the image in pixels. 
    89      *                   - Index 1 contains the height. 
    90      *                   - Index 2 is the type of the image. 
     88     * @param   int     $key    Which element from the array returned by getimagesize:
     89     *                   - Index 0 contains the width of the image in pixels.
     90     *                   - Index 1 contains the height.
     91     *                   - Index 2 is the type of the image.
    9192     *                   - Index 3 is height="yyy" width="xxx" string.
    9293     * @return  mixed   return value of getimagesize.
     
    102103        return isset($img_size[$key]) ? $img_size[$key] : false;
    103104    }
    104    
     105
    105106    /**
    106107     * Returns the URL to the source of image specified by id.
     
    126127
    127128    /**
    128      * Returns an HTML <img> tag with the src set to an image specified by id. 
     129     * Returns an HTML <img> tag with the src set to an image specified by id.
    129130     * Automatically prints image width and height.
    130131     *
     
    142143        $src = $this->oSrc($id);
    143144        $filepath = preg_match('!://!', $src) ? $src : getenv('DOCUMENT_ROOT') . $src;
    144        
     145
    145146        if (false === ($gis = @getimagesize($filepath)) || preg_match('/width|height/', $extra)) {
    146147            $image_size = '';
     
    148149            $image_size = $gis[3];
    149150        }
    150        
     151
    151152        return sprintf('<img src="%s" %s alt="%s" %s />',
    152153            $src,
  • branches/eli_branch/lib/Navigation.inc.php

    r439 r467  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    2828 * and titles, as well as setting page params such as hiding the page title on
    2929 * some pages but not others, and storing vars like the page title itself.
    30  * 
     30 *
    3131 * Note: this class was renamed from "Nav" because of the change in API and to be more descriptive.
    3232 *
     
    3737
    3838    // Configuration parameters for this object.
    39     private $_params = array(       
     39    private $_params = array(
    4040        'head_title' => true,
    4141        'body_title' => true,
     
    6868     * current page added last. Vars can be specified for any page, but only vars
    6969     * from the "current" page will be accessed with Nav::get.
    70      * 
     70     *
    7171     * @access  public
    7272     * @param   string  $title      The title of the page.
     
    9494    {
    9595        $app =& App::getInstance();
    96    
     96
    9797        if (isset($params) && is_array($params)) {
    9898            // Merge new parameters with old overriding only those passed.
     
    113113    {
    114114        $app =& App::getInstance();
    115    
     115
    116116        if (isset($this->_params[$param])) {
    117117            return $this->_params[$param];
     
    142142    {
    143143        // Set params of current page.
    144         $curr_page =& $this->pages[sizeof($this->pages) - 1];       
     144        $curr_page =& $this->pages[sizeof($this->pages) - 1];
    145145        $curr_page[$key] = $val;
    146146    }
     
    157157    {
    158158        $curr_page =& $this->pages[sizeof($this->pages) - 1];
    159        
     159
    160160        switch ($key) {
    161161        case 'title' :
     
    279279     * @return  mixed   The value set for $return, TRUE by default.
    280280     */
    281     public function currentPage($page_uri, $return=true)
    282     {
    283         if (preg_match('/^' . preg_quote(urldecode($page_uri), '/') . '/i', $_SERVER['PHP_SELF'])) {
    284             return $return;
    285         }
     281    public function currentPage($test_uri, $true_return=true, $false_return=false, $strip_query=false)
     282    {
     283        $actual_uri = $strip_query ? strtok($_SERVER['REQUEST_URI'], '?') : $_SERVER['REQUEST_URI'];
     284        $test_uri = $strip_query ? strtok($test_uri, '?') : $test_uri;
     285        if (preg_match('/^' . preg_quote(urldecode($test_uri), '/') . '$/i', $actual_uri)) {
     286            return $true_return;
     287        }
     288        return $false_return;
    286289    }
    287290
  • branches/eli_branch/lib/PEdit.inc.php

    r439 r467  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    3535 * and call printing/editing functions where you want data and forms to
    3636 * show up.
    37  * 
     37 *
    3838 * @author  Quinn Comendant <quinn@strangecode.com>
    3939 * @concept Beau Smith <beau@beausmith.com>
    40  * @version 2.0 
    41  * 
     40 * @version 2.0
     41 *
    4242 * Example of use:
    43  
     43
    4444 // Initialize PEdit object.
    4545 require_once 'codebase/lib/PEdit.inc.php';
     
    4848     'authorized' => true,
    4949 ));
    50  
     50
    5151 // Setup content data types.
    5252 $pedit->set('title');
    5353 $pedit->set('content', array('type' => 'textarea'));
    54  
     54
    5555 // After setting all parameters and data, load the data.
    5656 $pedit->start();
    57  
     57
    5858 // Print content.
    5959 echo $pedit->get('title');
    6060 echo $pedit->get('content');
    61  
     61
    6262 // Print additional PEdit functionality.
    6363 $pedit->formBegin();
     
    9696    {
    9797        $this->setParam($params);
    98        
     98
    9999        if ($this->getParam('authorized') === true) {
    100100            $this->_authorized = true;
    101101        }
    102        
     102
    103103        // Setup PEAR XML libraries.
    104104        require_once 'XML/Serializer.php';
     
    114114        ));
    115115    }
    116    
     116
    117117    /**
    118118     * Set (or overwrite existing) parameters by passing an array of new parameters.
     
    143143    {
    144144        $app =& App::getInstance();
    145    
     145
    146146        if (isset($this->_params[$param])) {
    147147            return $this->_params[$param];
     
    151151        }
    152152    }
    153    
     153
    154154    /*
    155155    * Load the pedit data and run automatic functions.
     
    166166            trigger_error(sprintf('PEdit data directory not found: %s', $this->getParam('data_dir')), E_USER_WARNING);
    167167        }
    168        
     168
    169169        // The location of the data file. (i.e.: "COMMON_DIR/html/_pedit_data/news/index.xml")
    170170        $this->_data_file = sprintf('%s%s.xml', $this->getParam('data_dir'), $_SERVER['SCRIPT_NAME']);
    171        
    172         // Make certain the evaluated path matches the assumed path (realpath will expand /../../); 
     171
     172        // Make certain the evaluated path matches the assumed path (realpath will expand /../../);
    173173        // if realpath returns FALSE we're not concerned because it means the file doesn't exist (_initializeDataFile() will create it).
    174174        if (false !== realpath($this->_data_file) && $this->_data_file !== realpath($this->_data_file)) {
     
    199199            break;
    200200        }
    201        
     201
    202202        // Load data.
    203203        $this->_loadDataFile();
     
    258258            return false;
    259259        }
    260         ?>       
     260        ?>
    261261        <form action="<?php echo oTxt($_SERVER['PHP_SELF']); ?>" method="post" id="sc-pedit-form">
    262262        <input type="hidden" name="filename" value="<?php echo oTxt($_SERVER['PHP_SELF']); ?>" />
     
    307307    public function printForm($name, $type='text')
    308308    {
    309         if ($this->_authorized && $this->op == 'Edit' && $this->_data_loaded) {       
     309        if ($this->_authorized && $this->op == 'Edit' && $this->_data_loaded) {
    310310            ?>
    311311            <div class="sc-pedit-item">
     
    468468        }
    469469        $xml_file_contents = file_get_contents($this->_data_file);
    470         $status = $this->xml_unserializer->unserialize($xml_file_contents, false);   
     470        $status = $this->xml_unserializer->unserialize($xml_file_contents, false);
    471471        if (PEAR::isError($status)) {
    472472            $app->logMsg(sprintf('XML_Unserialize error: %s', $status->getMessage()), LOG_WARNING, __FILE__, __LINE__);
     
    487487        return true;
    488488    }
    489    
     489
    490490    /*
    491491    * Start a new data file.
     
    535535                return false;
    536536            }
    537            
     537
    538538            // Collect posted data that is already specified in _data (by set()).
    539539            foreach ($new_data as $name => $content) {
     
    542542                }
    543543            }
    544            
     544
    545545            if (is_array($this->_data) && !empty($this->_data)) {
    546546                $xml_file_contents = $this->xml_serializer->serialize($this->_data);
     
    549549        }
    550550    }
    551    
     551
    552552    /*
    553553    * Writes content to the specified file.
     
    587587        if ($fp = fopen($filename, 'w')) {
    588588            if (flock($fp, LOCK_EX)) {
    589                 fwrite($fp, $content, mb_strlen($content));
     589                fwrite($fp, $content);
    590590                flock($fp, LOCK_UN);
    591591            } else {
     
    639639        return true;
    640640    }
    641    
     641
    642642    /*
    643643    * Delete all versions older than versions_min_days if there are more than versions_min_qty or 100.
     
    714714            return false;
    715715        }
    716        
     716
    717717        // The file to restore.
    718718        $version_file = sprintf('%s__%s.xml', preg_replace('/\.xml$/', '', $this->_data_file), $version);
    719        
     719
    720720        // Ensure specified version exists.
    721721        if (!file_exists($version_file)) {
  • branches/eli_branch/lib/Prefs.inc.php

    r438 r467  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    2424 * Prefs.inc.php
    2525 *
    26  * Prefs provides an API for saving arbitrary values in a user's session. 
     26 * Prefs provides an API for saving arbitrary values in a user's session.
    2727 * Session prefs can be stored into a database with the optional save() and load() methods.
    2828 *
    2929 * @author  Quinn Comendant <quinn@strangecode.com>
    3030 * @version 2.1
    31  * 
     31 *
    3232 * Example of use:
    3333---------------------------------------------------------------------
     
    5959    // Configuration parameters for this object.
    6060    var $_params = array(
    61        
     61
    6262        // Enable database storage. If this is false, all prefs will live only as long as the session.
    6363        'persistent' => false,
    64        
     64
    6565        // The current user_id for which to load/save persistent preferences.
    6666        'user_id' => null,
    67        
     67
    6868        // How long before we force a reload of the persistent prefs data? 3600 = once every hour.
    6969        'load_timeout' => 3600,
    70        
     70
    7171        // Name of database table to store persistent prefs.
    7272        'db_table' => 'pref_tbl',
     
    8585
    8686        $this->_ns = $namespace;
    87        
     87
    8888        // Initialized the prefs array.
    89         if (!isset($_SESSION['_prefs'][$this->_ns])) {
     89        if (!isset($_SESSION['_prefs'][$this->_ns]['saved'])) {
    9090            $this->clear();
    9191        }
     
    160160    {
    161161        $app =& App::getInstance();
    162    
     162
    163163        if (isset($this->_params[$param])) {
    164164            return $this->_params[$param];
     
    170170
    171171    /**
    172      * Sets the default values for preferences. If a preference is not explicitly 
     172     * Sets the default values for preferences. If a preference is not explicitly
    173173     * set, the value set here will be used. Can be called multiple times to merge additional
    174174     * defaults together.
    175175     *
    176      * @param  array $defaults  Array of key-value pairs 
     176     * @param  array $defaults  Array of key-value pairs
    177177     */
    178178    function setDefaults($defaults)
     
    200200            return false;
    201201        }
    202        
    203         // Set a persistent preference if...
     202
     203        // Set a saved preference if...
    204204        // - there isn't a default.
    205         // - the new value is different than the default
    206         // - there is a previously existing persistent key.
    207         if (!isset($_SESSION['_prefs'][$this->_ns]['defaults'][$key]) || $_SESSION['_prefs'][$this->_ns]['defaults'][$key] != $val || isset($_SESSION['_prefs'][$this->_ns]['persistent'][$key])) {
    208             $_SESSION['_prefs'][$this->_ns]['persistent'][$key] = $val;           
     205        // - or the new value is different than the default
     206        // - 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;
    209211            $app->logMsg(sprintf('Setting preference %s => %s', $key, truncate(getDump($val, true), 128, 'end')), LOG_DEBUG, __FILE__, __LINE__);
    210212        } else {
     
    214216
    215217    /**
    216      * Returns the value of the requested preference. Persistent values take precedence, but if none is set
     218     * Returns the value of the requested preference. Saved values take precedence, but if none is set
    217219     * a default value is returned, or if not that, null.
    218220     *
     
    224226    {
    225227        $app =& App::getInstance();
    226         if (isset($_SESSION['_prefs'][$this->_ns]['persistent']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['persistent'])) {
    227             $app->logMsg(sprintf('Found %s in persistent', $key), LOG_DEBUG, __FILE__, __LINE__);
    228             return $_SESSION['_prefs'][$this->_ns]['persistent'][$key];
     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];
    229231        } else if (isset($_SESSION['_prefs'][$this->_ns]['defaults']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['defaults'])) {
    230232            $app->logMsg(sprintf('Found %s in defaults', $key), LOG_DEBUG, __FILE__, __LINE__);
     
    244246    function exists($key)
    245247    {
    246         return array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['persistent']);
    247     }
    248 
    249     /**
    250      * Clear a set preference value. This will also remove the value from the database. 
     248        return array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved']);
     249    }
     250
     251    /**
     252     * Clear a set preference value. This will also remove the value from the database.
    251253     *
    252254     * @param string $key       The name of the preference to delete.
     
    254256    function delete($key)
    255257    {
    256         unset($_SESSION['_prefs'][$this->_ns]['persistent'][$key]);
    257     }
    258 
    259     /**
    260      * Resets the $_SESSION cache. This should be executed with the same consideration 
     258        unset($_SESSION['_prefs'][$this->_ns]['saved'][$key]);
     259    }
     260
     261    /**
     262     * Resets the $_SESSION cache. This should be executed with the same consideration
    261263     * as $auth->clear(), such as when logging out.
    262264     */
     
    269271                'load_datetime' => '1970-01-01',
    270272                'defaults' => array(),
    271                 'persistent' => array(),
     273                'saved' => array(),
    272274            );
    273275            break;
     
    277279            break;
    278280
    279         case 'persistent' :
    280             $_SESSION['_prefs'][$this->_ns]['persistent'] = array();
     281        case 'saved' :
     282            $_SESSION['_prefs'][$this->_ns]['saved'] = array();
    281283            break;
    282284        }
    283285    }
    284    
     286
    285287    /*
    286288    * Retrieves all prefs from the database and stores them in the $_SESSION.
     
    297299        $app =& App::getInstance();
    298300        $db =& DB::getInstance();
    299        
     301
    300302        // Skip this method if not using the db.
    301303        if (true !== $this->getParam('persistent')) {
     
    315317            return false;
    316318        }
    317        
     319
    318320        // Clear existing cache.
    319         $this->clear('persistent');
    320        
     321        $this->clear('saved');
     322
    321323        // Retrieve all prefs for this user and namespace.
    322324        $qid = $db->query("
     
    328330        ");
    329331        while (list($key, $val) = mysql_fetch_row($qid)) {
    330             $_SESSION['_prefs'][$this->_ns]['persistent'][$key] = unserialize($val);
     332            $_SESSION['_prefs'][$this->_ns]['saved'][$key] = unserialize($val);
    331333        }
    332        
     334
    333335        $app->logMsg(sprintf('Loaded %s prefs from database.', mysql_num_rows($qid)), LOG_DEBUG, __FILE__, __LINE__);
    334        
     336
    335337        // Data loaded only once per session.
    336338        $_SESSION['_prefs'][$this->_ns]['loaded'] = true;
    337339        $_SESSION['_prefs'][$this->_ns]['load_datetime'] = date('Y-m-d H:i:s');
    338        
     340
    339341        return true;
    340342    }
    341    
     343
    342344    /*
    343345    * Returns true if the prefs had been loaded from the database into the $_SESSION recently.
    344346    * This function is simply a check so the database isn't access every page load.
    345     * 
     347    *
    346348    * @access   private
    347349    * @return   bool    True if prefs are loaded.
     
    354356        if (isset($_SESSION['_prefs'][$this->_ns]['load_datetime'])
    355357        && strtotime($_SESSION['_prefs'][$this->_ns]['load_datetime']) > time() - $this->getParam('load_timeout')
    356         && isset($_SESSION['_prefs'][$this->_ns]['loaded']) 
     358        && isset($_SESSION['_prefs'][$this->_ns]['loaded'])
    357359        && true === $_SESSION['_prefs'][$this->_ns]['loaded']) {
    358360            return true;
     
    361363        }
    362364    }
    363    
     365
    364366    /*
    365367    * Saves all prefs stored in the $_SESSION into the database.
     
    375377        $app =& App::getInstance();
    376378        $db =& DB::getInstance();
    377        
     379
    378380        // Skip this method if not using the db.
    379381        if (true !== $this->getParam('persistent')) {
    380382            return true;
    381383        }
    382        
     384
    383385        // User_id must not be empty.
    384386        if ('' == $this->getParam('user_id')) {
     
    389391        $this->initDB();
    390392
    391         if (isset($_SESSION['_prefs'][$this->_ns]['persistent']) && is_array($_SESSION['_prefs'][$this->_ns]['persistent']) && !empty($_SESSION['_prefs'][$this->_ns]['persistent'])) {
     393        if (isset($_SESSION['_prefs'][$this->_ns]['saved']) && is_array($_SESSION['_prefs'][$this->_ns]['saved']) && !empty($_SESSION['_prefs'][$this->_ns]['saved'])) {
    392394            // Delete old prefs from database.
    393395            $db->query("
     
    396398                AND pref_namespace = '" . $db->escapeString($this->_ns) . "'
    397399            ");
    398            
     400
    399401            // Insert new prefs.
    400402            $insert_values = array();
    401             foreach ($_SESSION['_prefs'][$this->_ns]['persistent'] as $key => $val) {
    402                 $insert_values[] = sprintf("('%s', '%s', '%s', '%s')", 
    403                     $db->escapeString($this->getParam('user_id')), 
    404                     $db->escapeString($this->_ns), 
    405                     $db->escapeString($key), 
     403            foreach ($_SESSION['_prefs'][$this->_ns]['saved'] as $key => $val) {
     404                $insert_values[] = sprintf("('%s', '%s', '%s', '%s')",
     405                    $db->escapeString($this->getParam('user_id')),
     406                    $db->escapeString($this->_ns),
     407                    $db->escapeString($key),
    406408                    $db->escapeString(serialize($val))
    407409                );
     
    409411            // TODO: after MySQL 5.0.23 is released this query could benefit from INSERT DELAYED.
    410412            $db->query("
    411                 INSERT INTO " . $db->escapeString($this->getParam('db_table')) . " 
     413                INSERT INTO " . $db->escapeString($this->getParam('db_table')) . "
    412414                (user_id, pref_namespace, pref_key, pref_value)
    413415                VALUES " . join(', ', $insert_values) . "
    414416            ");
    415            
     417
    416418            $app->logMsg(sprintf('Saved %s prefs to database.', sizeof($insert_values)), LOG_DEBUG, __FILE__, __LINE__);
    417419            return true;
    418420        }
    419        
     421
    420422        return false;
    421423    }
  • branches/eli_branch/lib/SortOrder.inc.php

    r451 r467  
    2424 * SortOrder.inc.php
    2525 *
    26  * SortOrder can determing how to sort results of a database query for display
     26 * SortOrder can determine how to sort results of a database query for display
    2727 * on a listing. It can print column headers that will be links to
    2828 * automatically change the sort and order.
     
    139139     *                               for example, for an alphabetical sort)
    140140     */
    141     public function set($sort = null, $order = null)
     141    public function set($sort=null, $order=null, $save_value=true)
    142142    {
    143143        // Set new sort value.
    144144        if (isset($sort)) {
    145145            $this->sort_by = $sort;
    146             $this->prefs->set('sort_by', $this->sort_by);
     146            if ($save_value) {
     147                $this->prefs->set('sort_by', $this->sort_by);
     148            }
    147149        }
    148150
     
    150152        if (isset($order)) {
    151153            $this->order = $order;
    152             $this->prefs->set('sort_order', $this->order);
     154            if ($save_value) {
     155                $this->prefs->set('sort_order', $this->order);
     156            }
    153157        }
    154158    }
  • branches/eli_branch/lib/Utilities.inc.php

    r439 r467  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    3333 * @param  bool  $var_dump Use var_dump instead of print_r.
    3434 */
    35 function dump($var, $display=false, $var_dump=false)
    36 {
     35function dump($var, $display=false, $var_dump=false, $file='', $line='')
     36{
     37    if (defined('_CLI')) {
     38        echo "\n$file $line\n";
     39    } else {
     40        echo $display ? "\n<br /><strong>$file $line</strong>\n<br /><pre>\n" : "\n\n\n<!--\n$file $line\n";
     41    }
     42    if ($var_dump) {
     43        var_dump($var);
     44    } else {
     45        print_r($var);
     46    }
    3747    if (defined('_CLI')) {
    3848        echo "\n";
    39     } else {       
    40         echo $display ? "\n<br /><pre>\n" : "\n\n\n<!--\n";
    41     }
    42     if ($var_dump) {
    43         var_dump($var);
    44     } else {
    45         print_r($var);
    46     }
    47     if (defined('_CLI')) {
    48         echo "\n";
    49     } else {       
     49    } else {
    5050        echo $display ?  "\n</pre><br />\n" : "\n-->\n\n\n";
    5151    }
    5252}
    5353
    54 /**
    55  * Return dump as variable.
    56  *
    57  * @param  mixed $var           Variable to dump.
    58  * @param  bool  $serialize     Remove line-endings. Useful for logging variables.
    59  * @return string Dump of var.
    60  */
     54/*
     55* Log a PHP variable to javascript console. Relies on getDump(), below.
     56*
     57* @access   public
     58* @param    mixed   $var      The variable to dump.
     59* @param    string  $prefix   A short note to print before the output to make identifying output easier.
     60* @param    string  $file     The value of __FILE__.
     61* @param    string  $line     The value of __LINE__.
     62* @return   null
     63* @author   Quinn Comendant <quinn@strangecode.com>
     64*/
     65function jsDump($var, $prefix='jsDump', $file='-', $line='-')
     66{
     67    if (!empty($var)) {
     68        ?>
     69        <script type="text/javascript" charset="utf-8">
     70        /* <![CDATA[ */
     71        window.console && console.log('<?php printf('%s: %s (on line %s of %s)', $prefix, str_replace("'", "\\'", getDump($var, true)), $line, $file); ?>');
     72        /* ]]> */
     73        </script>
     74        <?php
     75    }
     76}
     77
     78/*
     79* Return a string version of any variable, optionally serialized on one line.
     80*
     81* @access   public
     82* @param    mixed   $var        The variable to dump.
     83* @param    bool    $serialize  If true, remove line-endings. Useful for logging variables.
     84* @return   string              The dumped variable.
     85* @author   Quinn Comendant <quinn@strangecode.com>
     86*/
    6187function getDump($var, $serialize=false)
    6288{
     
    6591    $d = ob_get_contents();
    6692    ob_end_clean();
    67     return $serialize ? preg_replace('/\s+/m', '', $d) : $d;
     93    return $serialize ? preg_replace('/\s+/m', ' ', $d) : $d;
    6894}
    6995
     
    180206{
    181207    $words = preg_split('/[^\w]/', $search, -1, PREG_SPLIT_NO_EMPTY);
    182    
     208
    183209    $search = array();
    184210    $replace = array();
    185    
     211
    186212    foreach ($words as $w) {
    187213        if ('' != trim($w)) {
     
    266292
    267293/**
    268  * Turns "a really long string" into "a rea...string"
     294 * Truncates "a really long string" into a string of specified length
     295 * at the beginning: "
long string"
     296 * at the middle: "a rea
string"
     297 * or at the end: "a really
".
     298 *
     299 * The regular expressions below first match and replace the string to the specified length and position,
     300 * and secondly they remove any whitespace from around the delimiter (to avoid "this 
 " from happening).
    269301 *
    270302 * @access  public
     
    272304 * @param   int     $len    Maximum string length.
    273305 * @param   string  $where  Where to cut the string. One of: 'start', 'middle', or 'end'.
    274  * @return  string          Truncated output string
     306 * @return  string          Truncated output string.
    275307 * @author  Quinn Comendant <quinn@strangecode.com>
    276308 * @since   29 Mar 2006 13:48:49
    277309 */
    278 function truncate($str, $len, $where='end', $delim='
')
    279 {
    280     if ($len <= 3 || mb_strlen($str) <= 3) {
    281         return '';
    282     }
    283     $part1 = floor(($len - 3) / 2);
    284     $part2 = ceil(($len - 3) / 2);
     310function truncate($str, $len=50, $where='end', $delim='
')
     311{
     312    $dlen = mb_strlen($delim);
     313    if ($len <= $dlen || mb_strlen($str) <= $dlen) {
     314        return substr($str, 0, $len);
     315    }
     316    $part1 = floor(($len - $dlen) / 2);
     317    $part2 = ceil(($len - $dlen) / 2);
    285318    switch ($where) {
    286319    case 'start' :
    287         return preg_replace(array(sprintf('/^.{4,}(.{%s})$/sU', $part1 + $part2), '/\s*\.{3,}\s*/sU'), array($delim . '$1', $delim), $str);
    288         break;
     320        return preg_replace(array(sprintf('/^.{%s,}(.{%s})$/sU', $dlen + 1, $part1 + $part2), sprintf('/\s*%s{%s,}\s*/sU', preg_quote($delim), $dlen)), array($delim . '$1', $delim), $str);
     321
     322    case 'middle' :
     323        return preg_replace(array(sprintf('/^(.{%s}).{%s,}(.{%s})$/sU', $part1, $dlen + 1, $part2), sprintf('/\s*%s{%s,}\s*/sU', preg_quote($delim), $dlen)), array('$1' . $delim . '$2', $delim), $str);
     324
     325    case 'end' :
    289326    default :
    290     case 'middle' :
    291         return preg_replace(array(sprintf('/^(.{%s}).{4,}(.{%s})$/sU', $part1, $part2), '/\s*\.{3,}\s*/sU'), array('$1' . $delim . '$2', $delim), $str);
    292         break;   
    293     case 'end' :
    294         return preg_replace(array(sprintf('/^(.{%s}).{4,}$/sU', $part1 + $part2), '/\s*\.{3,}\s*/sU'), array('$1' . $delim, $delim), $str);
    295         break;
     327        return preg_replace(array(sprintf('/^(.{%s}).{%s,}$/sU', $part1 + $part2, $dlen + 1), sprintf('/\s*%s{%s,}\s*/sU', preg_quote($delim), $dlen)), array('$1' . $delim, $delim), $str);
    296328    }
    297329}
     
    307339* @since    06 Dec 2008 17:04:01
    308340*/
    309 if (!function_exists('mb_ucfirst')) {   
     341if (!function_exists('mb_ucfirst')) {
    310342    function mb_ucfirst($string)
    311343    {
     
    326358* @since    20 Jan 2013 12:33:26
    327359*/
    328 if (!function_exists('mb_strtr')) {   
     360if (!function_exists('mb_strtr')) {
    329361    function mb_strtr($string, $from, $to)
    330362    {
     
    367399/*
    368400* Returns a human readable amount of time for the given amount of seconds.
    369 * 
     401*
    370402* 45 seconds
    371403* 12 minutes
     
    374406* 1 week
    375407* 4 months
    376 * 
     408*
    377409* Months are calculated using the real number of days in a year: 365.2422 / 12.
    378410*
     
    400432        'century' => array(3155692608, _("century"), _("centuries")),
    401433    );
    402    
     434
    403435    // Max unit to calculate.
    404436    $max_unit = isset($units[$max_unit]) ? $max_unit : 'year';
     
    416448    }
    417449    $final_time = sprintf($format, $final_time);
    418     return sprintf('%s %s', $final_time, (1 == $final_time ? $units[$final_unit][1] : $units[$final_unit][2]));   
     450    return sprintf('%s %s', $final_time, (1 == $final_time ? $units[$final_unit][1] : $units[$final_unit][2]));
    419451}
    420452
     
    430462{
    431463    $app =& App::getInstance();
    432    
     464
    433465    foreach (explode(PATH_SEPARATOR, get_include_path()) as $path) {
    434466        $fullpath = $path . DIRECTORY_SEPARATOR . $file;
     
    680712 * escaped.  This is useful for putting values coming in from posted
    681713 * checkboxes into a SET column of a database.
    682  * 
     714 *
    683715 *
    684716 * @param  array $in      Array to convert.
     
    688720{
    689721    $db =& DB::getInstance();
    690    
     722
    691723    if (is_array($in) && !empty($in)) {
    692724        return join($separator, array_map(array($db, 'escapeString'), $in));
     
    839871{
    840872    $app =& App::getInstance();
    841    
     873
    842874    if ('' == trim($val)) {
    843875        $app->logMsg(sprintf('Cannot add signature to an empty string.', null), LOG_INFO, __FILE__, __LINE__);
     
    848880        $salt = $app->getParam('signing_key');
    849881    }
    850    
     882
    851883    // TODO: consider using more bits-per-character, such as done with:
    852884    // http://www.php.net/manual/en/function.sha1.php#86239
     
    916948{
    917949    $app =& App::getInstance();
    918    
     950
    919951    $add_members = '/usr/lib/mailman/bin/add_members';
    920952    /// FIXME: checking of executable is disabled.
     
    948980{
    949981    $app =& App::getInstance();
    950    
     982
    951983    $remove_members = '/usr/lib/mailman/bin/remove_members';
    952984    /// FIXME: checking of executable is disabled.
  • branches/eli_branch/lib/Validator.inc.php

    r450 r467  
    218218    /**
    219219     * Verifies that date can be processed by the strtotime function.
     220     * Empty strings are considered valid. Other values are tested on their return value from strtotime(). Null values will fail.
    220221     *
    221222     * @param  string  $val The input data to validate.
     
    226227        $app =& App::getInstance();
    227228
    228         if ('' == trim($val)) {
     229        if (is_string($val) && '' === trim($val)) {
    229230            // Don't be too bothered about empty strings.
    230231            return true;
     
    232233
    233234        $timestamp = strtotime($val);
    234         // Return values change between php4 and php5.
    235         if ('' != trim($val) && ($timestamp === -1 || $timestamp === false)) {
     235        if (!$timestamp || $timestamp < 1) {
    236236            return false;
    237237        } else {
     
    239239        }
    240240    }
    241 
    242241
    243242    /**
  • branches/eli_branch/services/admins.php

    r438 r467  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    2727// require_once dirname(__FILE__) . '/_config.inc.php';
    2828
     29$app->sslOn();
    2930$auth->requireLogin();
    30 $app->sslOn();
    3131
    3232require_once 'codebase/lib/PageNumbers.inc.php';
     
    282282    $app =& App::getInstance();
    283283    $db =& DB::getInstance();
    284    
     284
    285285    $lock->select($auth->getParam('db_table'), $auth->getParam('db_primary_key'), $id);
    286286    if ($lock->isLocked() && !$lock->isMine()) {
     
    341341    $app =& App::getInstance();
    342342    $db =& DB::getInstance();
    343    
     343
    344344    $lock->select($auth->getParam('db_table'), $auth->getParam('db_primary_key'), $id);
    345345    if ($lock->isLocked() && !$lock->isMine()) {
     
    353353    $qid = $db->query("
    354354        SELECT " . $auth->getParam('db_username_column') . "
     355        FROM " . $auth->getParam('db_table') . "
    355356        WHERE " . $auth->getParam('db_primary_key') . " = '" . $db->escapeString($id) . "'
    356357    ");
     
    386387    $app =& App::getInstance();
    387388    $db =& DB::getInstance();
    388    
     389
    389390    // Remove any stale cached list data.
    390391    $cache->delete('list');
     
    429430    $app =& App::getInstance();
    430431    $db =& DB::getInstance();
    431    
     432
    432433    $lock->select($auth->getParam('db_table'), $auth->getParam('db_primary_key'), $frm['admin_id']);
    433434    if ($lock->isLocked() && !$lock->isMine()) {
     
    474475    global $auth;
    475476    $db =& DB::getInstance();
    476    
     477
    477478    $where_clause = '';
    478479
     
    508509        SELECT
    509510            " . $auth->getParam('db_table') . ".*,
    510             " . $auth->getParam('db_table') . "." . $auth->getParam('db_primary_key') . " AS admin_id,           
     511            " . $auth->getParam('db_table') . "." . $auth->getParam('db_primary_key') . " AS admin_id,
    511512            a1." . $auth->getParam('db_username_column') . " AS added_admin_username,
    512513            a2." . $auth->getParam('db_username_column') . " AS modified_admin_username
     
    536537        return $list;
    537538    }
    538    
     539
    539540    // The list was not cached, so issue the real query.
    540541    $qid = $db->query($sql);
  • branches/eli_branch/services/lock.php

    r438 r467  
    2828require_once 'codebase/lib/Lock.inc.php';
    2929
     30$app->sslOn();
    3031$auth->requireLogin();
    31 $app->sslOn();
    3232
    3333if (getFormData('boomerang', false)) {
  • branches/eli_branch/services/login.php

    r447 r467  
    3232$app->sslOn();
    3333
    34 $frm['username'] = getFormdata('username');
     34require_once 'codebase/lib/Prefs.inc.php';
     35$login_prefs = new Prefs('login');
     36$login_prefs->setDefaults(array('username' => ''));
     37
     38if ('' != $login_prefs->get('username')) {
     39    $frm['remember_me'] = '1';
     40}
     41
     42$frm['username'] = getFormdata('username', $login_prefs->get('username'));
    3543$frm['password'] = getFormdata('password');
    3644
     
    3947
    4048    if ($auth->login($frm['username'], $frm['password'])) {
     49        if (getFormData('remember_me')) {
     50            $login_prefs->set('username', getFormData('username'));
     51        } else {
     52            $login_prefs->set('username', '');
     53        }
    4154        $app->raiseMsg(_("You are now logged in."), MSG_SUCCESS, __FILE__, __LINE__);
    4255        $app->dieBoomerangURL('login');
  • branches/eli_branch/services/logs.php

    r438 r467  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    2727// require_once dirname(__FILE__) . '/_config.inc.php';
    2828
     29$app->sslOn();
    2930$auth->requireLogin();
    30 // $auth->requireAccessClearance(ZONE_ADMIN_APPLOG);
    31 $app->sslOn();
    3231
    3332require_once 'codebase/lib/PageNumbers.inc.php';
     
    6463));
    6564if (getFormData('log', false)) {
    66     $tmp_prefs->set('log_file', getFormData('log'));   
     65    $tmp_prefs->set('log_file', getFormData('log'));
    6766}
    6867
     
    8079switch (getFormData('op')) {
    8180case 'delete' :
    82 //     $auth->requireAccessClearance(ZONE_ADMIN_APPLOG_FUNC_RESET);
    8381    deleteLog($tmp_prefs->get('log_file'));
    8482    $tmp_prefs->set('log_file', $app->getParam('log_filename'));
     
    9290
    9391case 'clear' :
    94 //     $auth->requireAccessClearance(ZONE_ADMIN_APPLOG_FUNC_RESET);
    9592    clearLog($tmp_prefs->get('log_file'));
    9693    if ($app->validBoomerangURL('app_log')) {
     
    103100
    104101case 'archive' :
    105 //     $auth->requireAccessClearance(ZONE_ADMIN_APPLOG_FUNC_RESET);
    106102    if (archiveLog($tmp_prefs->get('log_file'))) {
    107103        // Now flush current log.
  • branches/eli_branch/services/templates/admin_list.ihtml

    r432 r467  
    22<?php $fv->printErrorMessages(); ?>
    33
    4 <div id="commandbox">
     4<div class="commandbox">
    55    <span class="sc-nowrap commanditem"><a href="<?php echo $app->oHREF($_SERVER['PHP_SELF'] . '?op=add'); ?>"><?php echo _("Add Administrator"); ?></a></span>
    66    <form action="<?php echo oTxt($_SERVER['PHP_SELF']); ?>" method="get" class="sc-form">
     
    3838        <td class="sc-nowrap"><?php echo oTxt($list[$i]['first_name'], true); ?> <?php echo oTxt($list[$i]['last_name'], true); ?> &nbsp;</td>
    3939        <td class="sc-nowrap"><?php echo round($list[$i]['seconds_online'] / 60); ?> &nbsp;</td>
    40         <td class="sc-nowrap"><?php 
     40        <td class="sc-nowrap"><?php
    4141            if ($auth->isLoggedIn($list[$i]['admin_id'])) {
    4242                ?><strong><?php echo date($app->getParam('date_format'), strtotime($list[$i]['last_login_datetime'])) ?></strong><?php
    4343            } else {
    44                 echo '0000-00-00 00:00:00' == $list[$i]['last_login_datetime'] ? '' : date($app->getParam('date_format'), strtotime($list[$i]['last_login_datetime']));
     44                echo Validator::validateStrDate($list[$i]['last_login_datetime']) ? date($app->getParam('date_format'), strtotime($list[$i]['last_login_datetime'])) : '';
    4545            }
    4646        ?> &nbsp;</td>
    4747        <td class="sc-nowrap"><?php echo gethostbyaddr($list[$i]['last_login_ip']); ?> &nbsp;</td>
    48         <td class="sc-nowrap"><?php echo '0000-00-00 00:00:00' == $list[$i]['added_datetime'] ? '' : date($app->getParam('date_format'), strtotime($list[$i]['added_datetime'])); ?> &nbsp;</td>
     48        <td class="sc-nowrap"><?php echo Validator::validateStrDate($list[$i]['added_datetime']) ? date($app->getParam('date_format'), strtotime($list[$i]['added_datetime'])) : ''; ?> &nbsp;</td>
    4949        <td class="sc-nowrap"><?php echo oTxt($list[$i]['added_admin_username'], true); ?> &nbsp;</td>
    50         <td class="sc-nowrap"><?php echo '0000-00-00 00:00:00' == $list[$i]['modified_datetime'] ? '' : date($app->getParam('date_format'), strtotime($list[$i]['modified_datetime'])); ?> &nbsp;</td>
     50        <td class="sc-nowrap"><?php echo Validator::validateStrDate($list[$i]['modified_datetime']) ? date($app->getParam('date_format'), strtotime($list[$i]['modified_datetime'])) : ''; ?> &nbsp;</td>
    5151        <td class="sc-nowrap"><?php echo oTxt($list[$i]['modified_admin_username'], true); ?> &nbsp;</td>
    5252        <td class="sc-padleft sc-nowrap" align="right"><a title="<?php printf(_("Delete %s"), oTxt($list[$i]['username'])) ?>" href="<?php echo $app->oHREF($_SERVER['PHP_SELF'] . "?op=del&admin_id=" . $list[$i]['admin_id']); ?>" onclick="javascript:return confirm('<?php printf(_("Are you sure you want to delete the record %s? This action is permanent and cannot be undone."), oTxt($list[$i]['username'])) ?>')"><img src="/admin/i/trash.gif" alt="Delete" width="10" height="10" border="0" /></a> &nbsp;</td>
  • branches/eli_branch/services/templates/log_list.ihtml

    r320 r467  
    11<form action="<?php echo oTxt($_SERVER['PHP_SELF']); ?>" method="get" class="sc-form">
    22<?php $app->printHiddenSession(false); ?>
    3 <div id="commandbox">
     3<div class="commandbox">
    44<?php if (is_array($logs) && !empty($logs)) { ?>
    55    <table>
  • branches/eli_branch/services/templates/login_form.ihtml

    r421 r467  
    1717        </td>
    1818    </tr>
     19    <tr class="sc-form-row">
     20        <td class="sc-right">&nbsp;</td>
     21        <td>
     22            <label class="sc-label-secondary"><input type="checkbox" name="remember_me" id="remember_me" value="1"<?php frmChecked($frm['remember_me']) ?> /> <?php echo _("Remember my username"); ?></label>
     23        </td>
     24    </tr>
    1925    <tr>
    2026        <td>&nbsp;</td>
     
    2329</table>
    2430</form>
     31<script type="text/javascript" charset="utf-8">
     32/* <![CDATA[ */
     33$(document).ready(function() {
     34    if ($('input[name="username"]').val() != '') {
     35        $('input[name="password"]').focus();
     36    } else {
     37        $('input[name="username"]').focus();
     38    }
     39});
     40/* ]]> */
     41</script>
  • branches/eli_branch/services/templates/versions_diff.ihtml

    r270 r467  
    1 <div id="commandbox">
     1<div class="commandbox">
    22<?php if (!getFormData('current', false)) { ?>
    33    <span class="sc-nowrap commanditem"><a href="<?php echo $app->oHREF($_SERVER['PHP_SELF'] . '?op=restore', array('version_id', 'version_title')); ?>"><?php echo _("Restore this saved version"); ?></a></span>
  • branches/eli_branch/services/templates/versions_view.ihtml

    r365 r467  
    1 <div id="commandbox">
     1<div class="commandbox">
    22<span class="sc-nowrap commanditem"><a href="<?php echo $app->ohref(oTxt($_SERVER['PHP_SELF'])); ?>"><?php echo _("Back to the Versions List"); ?></a></span>
    33<?php if (!getFormData('current', false)) { ?>
  • branches/eli_branch/services/versions.php

    r438 r467  
    44 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    55 * Copyright 2001-2012 Strangecode, LLC
    6  * 
     6 *
    77 * This file is part of The Strangecode Codebase.
    88 *
     
    1111 * Free Software Foundation, either version 3 of the License, or (at your option)
    1212 * any later version.
    13  * 
     13 *
    1414 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1515 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1616 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    1717 * details.
    18  * 
     18 *
    1919 * You should have received a copy of the GNU General Public License along with
    2020 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    2727// require_once dirname(__FILE__) . '/_config.inc.php';
    2828
     29$app->sslOn();
    2930$auth->requireLogin();
    30 $app->sslOn();
    3131
    3232require_once 'codebase/lib/Version.inc.php';
     
    3838
    3939// Since we're using the singleton pattern we can instantiate a Version object earlier with custom parameters.
    40 $version =& Version::getInstance($auth);   
     40$version =& Version::getInstance($auth);
    4141
    4242// Query arguments to retain their values between page requests.
  • branches/eli_branch/tests/Auth_SQLTest.php

    r447 r467  
    256256        $this->assertType('array', $result);
    257257    }
    258 
    259 //     function test_inclearancezone()
    260 //     {
    261 //         $result = $this->Auth_SQL->inclearancezone(PARAM);
    262 //         $expected = EXPECTED_VAL;
    263 //         $this->assertEquals($expected, $result);
    264 //     }
    265 //
    266 //     function test_requireaccessclearance()
    267 //     {
    268 //         $result = $this->Auth_SQL->requireaccessclearance(PARAM);
    269 //         $expected = EXPECTED_VAL;
    270 //         $this->assertEquals($expected, $result);
    271 //     }
    272 
    273258}
    274259// Running the test.
Note: See TracChangeset for help on using the changeset viewer.