Changeset 534 for trunk/lib/ACL.inc.php


Ignore:
Timestamp:
Jul 27, 2015 7:56:08 AM (9 years ago)
Author:
anonymous
Message:

Improved module maker validation output. Allow disabling cache at run time for ACL. Added ACL getList() method. Improved ACL CLI listing. Fixed app boomerang array initialization. Now retaining identical boomerang URLs if the key is different. Added a maximum boomerang time. Added a way to disable cache per request through a query string. Added validator isDecimal() method. Added disableSelectOptions() HTML method. Added getGravatarURL() method. Change how navigation page array is managed. Updated navigation currentPage() method to test an array of URLs.

File:
1 edited

Legend:

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

    r506 r534  
    6565        // Configure the cache object.
    6666        $this->cache = new Cache('acl');
    67         $this->cache->setParam(array('enabled' => true));
    6867
    6968        // Get create tables config from global context.
     
    101100
    102101        if (isset($params) && is_array($params)) {
     102            // Some params require special processing. Catch those in a loop and process individually.
     103            foreach ($params as $key => $val) {
     104                switch ($key) {
     105                case 'enable_cache':
     106                    $this->cache->setParam(array('enabled' => $val));
     107                    break;
     108                }
     109
     110            }
     111            unset($key, $value);
     112
    103113            // Merge new parameters with old overriding only those passed.
    104114            $this->_params = array_merge($this->_params, $params);
     
    675685
    676686        $cache_hash = $aro . '|' . $aco . '|' . $axo;
    677         if ($this->cache->exists($cache_hash) && true === $this->getParam('enable_cache')) {
     687        if (true === $this->getParam('enable_cache') && $this->cache->exists($cache_hash)) {
    678688            // Access value is cached.
    679689            $access = $this->cache->get($cache_hash);
     
    694704            if (!list($access) = mysql_fetch_row($qid)) {
    695705                $this->cache->set($cache_hash, 'deny');
    696                 $app->logMsg(sprintf('Access denied: %s -> %s -> %s (no records found).', $aro, $aco, $axo), LOG_DEBUG, __FILE__, __LINE__);
     706                $app->logMsg(sprintf('Access denied: %s -> %s -> %s (no records found).', $aro, $aco, $axo), LOG_WARNING, __FILE__, __LINE__);
    697707                return false;
    698708            }
     
    704714            return true;
    705715        } else {
    706             $app->logMsg(sprintf('Access denied: %s -> %s -> %s', $aro, $aco, $axo), LOG_DEBUG, __FILE__, __LINE__);
     716            $app->logMsg(sprintf('Access denied: %s -> %s -> %s', $aro, $aco, $axo), LOG_NOTICE, __FILE__, __LINE__);
    707717            return false;
    708718        }
     
    736746    }
    737747
     748    /*
     749    * Returns an array of the specified object type starting specified root.
     750    *
     751    * @access   public
     752    * @param    string $type Table to list, one of: aro, aco, or axo.
     753    * @param    string $root Root node from which to begin from.
     754    * @return   mixed        Returns a multidimensional array of objects, or false on error.
     755    * @author   Quinn Comendant <quinn@strangecode.com>
     756    * @version  1.0
     757    * @since    17 Jun 2006 23:41:22
     758    */
     759    function getList($type, $root=null)
     760    {
     761        $app =& App::getInstance();
     762        $db =& DB::getInstance();
     763
     764        switch ($type) {
     765        case 'aro' :
     766            $tbl = 'aro_tbl';
     767            break;
     768        case 'aco' :
     769            $tbl = 'aco_tbl';
     770            break;
     771        case 'axo' :
     772            $tbl = 'axo_tbl';
     773            break;
     774        default :
     775            $app->logMsg(sprintf('Invalid access object type: %s', $type), LOG_ERR, __FILE__, __LINE__);
     776            return false;
     777        }
     778
     779        // By default start with the 'root' node.
     780        $root = !isset($root) ? 'root' : $root;
     781
     782        // Retrieve the left and right value of the $root node.
     783        $qid = $db->query("SELECT lft, rgt FROM $tbl WHERE name = '" . $db->escapeString($root) . "'");
     784        list($lft, $rgt) = mysql_fetch_row($qid);
     785
     786        $results = array();
     787        $depth = array();
     788
     789        // Retrieve all descendants of the root node
     790        $qid = $db->query("SELECT name, lft, rgt, added_datetime FROM $tbl WHERE lft BETWEEN $lft AND $rgt ORDER BY lft ASC");
     791        while (list($name, $lft, $rgt, $added_datetime) = mysql_fetch_row($qid)) {
     792            // If the last element of $depth is less than the current rgt it means we finished with a set of children nodes.
     793            while (sizeof($depth) > 0 && end($depth) < $rgt) {
     794                array_pop($depth);
     795            }
     796
     797            $results[] = array(
     798                'name' => $name,
     799                'added_datetime' => $added_datetime,
     800                'depth' => sizeof($depth),
     801            );
     802
     803            // Add this node to the stack.
     804            $depth[] = $rgt;
     805        }
     806
     807        return $results;
     808    }
     809
    738810} // End class.
Note: See TracChangeset for help on using the changeset viewer.