Changeset 152


Ignore:
Timestamp:
Jun 7, 2006 5:35:16 AM (18 years ago)
Author:
scdev
Message:

Q - In the middle of working on the Prefs and Cache instantiation mode...can't decide to use singleton pattern or global vars. Updated ImageThumb? to allow filenames with path elements such as 01/23/4567_file.jpg.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/module_maker/skel/admin.php

    r151 r152  
    1414
    1515require_once 'codebase/lib/PageNumbers.inc.php';
    16 require_once 'codebase/lib/SessionCache.inc.php';
     16require_once 'codebase/lib/Cache.inc.php';
    1717require_once 'codebase/lib/FormValidator.inc.php';
    1818require_once 'codebase/lib/SortOrder.inc.php';
     
    3333$fv = new FormValidator();
    3434
    35 $cache =& Cache::getInstance();
     35// Configure the prefs object.
     36$prefs =& Prefs::getInstance('%NAME_PLURAL%');
     37$prefs->setParam(array('persistent' => false));
     38
     39// Configure the cache object.
     40$cache =& Cache::getInstance('%NAME_PLURAL%');
     41$cache->setParam(array('enable' => true));
    3642
    3743%SORT_ORDER%
    3844
    39 // Instantiate page numbers. Total items are set and calculation is done in the getRecordList function.
     45// Instantiate page numbers. Total items are set and calculation is done in the getCachedList function.
    4046$page = new PageNumbers();
    4147$page->setPerPage(getFormData('per_page'), 100);
     
    5763
    5864if (getFormData('break_list_cache', false)) {
    59     // Break the cache because we are changing the list data.
    60     $cache->delete($_SERVER['PHP_SELF']);
     65    // Remove any stale cached list data.
     66    $cache->delete('list');
    6167}
    6268
     
    171177default :
    172178//     $auth->requireAccessClearance(ZONE_ADMIN_%NAME_UPPER%_FUNC_LIST, _("Permission to view %NAME_PLURAL% list denied."));
    173     $list =& getRecordList();
     179    $list =& getCachedList();
    174180    $main_template = '%ADMIN_LIST_TEMPLATE%';
    175181    break;
     
    250256    global $lock;
    251257    $db =& DB::getInstance();
    252     $cache =& Cache::getInstance();
     258    $cache =& Cache::getInstance('%NAME_PLURAL%');
    253259   
    254260    $lock->select('%DB_TBL%', '%PRIMARY_KEY%', $id);
     
    257263    }
    258264
    259     // Break the cache because we are changing the list data.
    260     $cache->delete($_SERVER['PHP_SELF']);
     265    // Remove any stale cached list data.
     266    $cache->delete('list');
    261267
    262268    // Get the information for this object.
     
    285291    global $auth;
    286292    $db =& DB::getInstance();
    287     $cache =& Cache::getInstance();
     293    $cache =& Cache::getInstance('%NAME_PLURAL%');
    288294   
    289     // Break the cache because we are changing the list data.
    290     $cache->delete($_SERVER['PHP_SELF']);
     295    // Remove any stale cached list data.
     296    $cache->delete('list');
    291297
    292298%INSERT%
     
    306312    global $auth, $lock;
    307313    $app =& App::getInstance();
    308     $cache =& Cache::getInstance();
     314    $cache =& Cache::getInstance('%NAME_PLURAL%');
    309315   
    310316    $lock->select('%DB_TBL%', '%PRIMARY_KEY%', $frm['%PRIMARY_KEY%']);
     
    313319    }
    314320
    315     // Break the cache because we are changing the list data.
    316     $cache->delete($_SERVER['PHP_SELF']);
     321    // Remove any stale cached list data.
     322    $cache->delete('list');
    317323
    318324%UPDATE%
     
    328334}
    329335
    330 function &getRecordList()
     336function &getCachedList()
    331337{
    332338    global $page;
    333339    global $so;
    334     $db =& DB::getInstance();
    335     $prefs =& Prefs::getInstance();
    336     $cache =& Cache::getInstance();
    337    
     340    $db =& DB::getInstance();   
     341    $prefs =& Prefs::getInstance('%NAME_PLURAL%');
     342    $cache =& Cache::getInstance('%NAME_PLURAL%');
     343   
    338344    $where_clause = '';
    339345
     
    377383    ";
    378384
     385    // Use a cash hash to determine if the result-set has changed.
    379386    // A unique key for this query, with the total_items in case db records
    380387    // were added since the last cache. This identifies a unique set of
     
    383390    // without knowing the hash.
    384391    $cache_hash = md5($sql . '|' . $page->total_items);
    385     if ($prefs->get('cache_hash', $_SERVER['PHP_SELF']) != $cache_hash) {
    386         $cache->delete($_SERVER['PHP_SELF']);
    387         $prefs->set('cache_hash', $cache_hash, $_SERVER['PHP_SELF']);
    388     }
    389 
    390     if ($cache->exists($_SERVER['PHP_SELF'])) {
    391         // Get the cached results.
    392         $list = $cache->get($_SERVER['PHP_SELF']);
    393     } else {
    394         // If the list is not already cached, query now.
    395         $qid = $db->query($sql);
    396         // Fill an array with the items for this page.
    397         while ($row = mysql_fetch_assoc($qid)) {
    398             $list[] = $row;
    399         }
    400 
    401         if (isset($list) && !empty($list)) {
    402             // Cache the results.
    403             $cache->set($list, $_SERVER['PHP_SELF']);
    404         }
     392    if ($prefs->get('cache_hash') != $cache_hash) {
     393        $cache->delete('list');
     394        $prefs->set('cache_hash', $cache_hash);
     395    }
     396
     397    // First try to return from the cache.
     398    if ($cache->exists('list')) {
     399        return $cache->get('list');
     400    }
     401   
     402    // The list was not cached, so issue the real query.
     403    $qid = $db->query($sql);
     404    while ($row = mysql_fetch_assoc($qid)) {
     405        $list[] = $row;
     406    }
     407
     408    // Save this list into the cache.
     409    if (isset($list) && !empty($list)) {
     410        $cache->set('list', $list);
    405411    }
    406412
     
    411417{
    412418    $db =& DB::getInstance();
    413     $cache =& Cache::getInstance();
     419    $cache =& Cache::getInstance('%NAME_PLURAL%');
    414420   
    415421    if (!is_array($ranks)) {
     
    418424    }
    419425
    420     // Break the cache because we are changing the list data.
    421     $cache->delete($_SERVER['PHP_SELF']);
     426    // Remove any stale cached list data.
     427    $cache->delete('list');
    422428
    423429    // Count the ranks with invalid numbers
  • trunk/lib/Cache.inc.php

    r146 r152  
    1313 
    1414// Flags.
    15 define('CACHE_IGNORE_SIZE', 1);
     15define('CACHE_ALLOW_OVERSIZED', 1);
    1616
    1717class Cache {
    1818
     19    // Namespace of this instance of Prefs.
     20    var $_ns;
     21
     22    // Configuration parameters for this object.
    1923    var $_params = array(
     24       
     25        // If false nothing will be cached or retreived. Useful for testing realtime data requests.
    2026        'enabled' => true,
    21         'soft_limit' => 204800,
    22         'hard_limit' => 4194304,
    23         'min_items' => 3,
     27
     28        // The maximum size in bytes of any one variable.
     29        'item_size_limit' => 4194304, // 4 MB
     30       
     31        // The maximum size in bytes before the cache will begin flushing out old items.
     32        'stack_size_limit' => 4194304, // 4 MB
     33       
     34        // The minimum items to keep in the cache regardless of item or cache size.
     35        'min_items' => 5,
    2436    );
     37   
     38    /*
     39    * Constructor
     40    *
     41    * @access   public
     42    * @param    string  $namespace  This object will store data under this realm.
     43    * @author   Quinn Comendant <quinn@strangecode.com>
     44    * @version  1.0
     45    * @since    05 Jun 2006 23:14:21
     46    */
     47    function Cache($namespace='')
     48    {
     49        $this->_ns = '_cache' . $namespace;
     50       
     51        if (!isset($_SESSION[$this->_ns])) {
     52            $this->clear();
     53        }
     54    }
    2555
    2656    /**
     
    3161     * @static
    3262     */
    33     function &getInstance()
    34     {
    35         static $instance = null;
    36 
    37         if ($instance === null) {
    38             $instance = new Cache();
    39         }
    40 
    41         return $instance;
     63    function &getInstance($namespace='')
     64    {
     65        static $instances = array();
     66
     67        if (!array_key_exists($namespace, $instances)) {
     68            $instances[$namespace] = new Cache($namespace);
     69        }
     70
     71        return $instances[$namespace];
    4272    }
    4373
     
    81111    /**
    82112     * Stores a new variable in the session cache. The $key is is md5'ed
    83      * because if a variable id is a very large integer, the array_shift function
     113     * because if a key is numeric, the array_shift function
    84114     * will reset the key to the next largest int key. Weird behavior I can't
    85      * understand. $session_cache[32341234123] will become $session_cache[0]
    86      * for example. Usage warning: if the variable is too big to fit, or is
    87      * old and discarded, you must provide alternative ways of accessing the data.
     115     * understand. For example $cache["123"] will become $cache[0]
    88116     *
    89117     * @param str   $key        An identifier for the cached object.
    90      * @param mixed $var          The var to store in the session cache.
     118     * @param mixed $var        The var to store in the session cache.
    91119     * @param bool  $flags      If we have something really big that we
    92      *                            still want to cache, setting this to
    93      *                            CACHE_IGNORE_SIZE allows this.
    94      *
    95      * @return bool               True on success, false otherwise.
     120     *                          still want to cache, setting this to
     121     *                          CACHE_ALLOW_OVERSIZED allows this.
     122     * @return bool             True on success, false otherwise.
    96123     */
    97124    function set($key, $var, $flags=0)
     
    99126        $app =& App::getInstance();
    100127
    101         if (!$this->getParam('enabled')) {
     128        if (true !== $this->getParam('enabled')) {
    102129            $app->logMsg(sprintf('Cache not enabled, not saving data.', null), LOG_DEBUG, __FILE__, __LINE__);
    103130            return false;
     
    105132
    106133        $key = md5($key);
    107         $serialized_var = serialize($var);
    108         $serialized_var_len = strlen($serialized_var);
    109 
    110         if ($flags & CACHE_IGNORE_SIZE > 0 && $serialized_var_len >= $this->getParam('soft_limit')) {
    111             $app->logMsg(sprintf('Serialized variable (%s bytes) more than soft_limit (%s bytes).', $serialized_var_len, $this->getParam('soft_limit')), LOG_NOTICE, __FILE__, __LINE__);
    112             return false;
    113         }
    114 
    115         if ($serialized_var_len >= $this->getParam('hard_limit')) {
    116             $app->logMsg(sprintf('Serialized variable (%s bytes) more than hard_limit (%s bytes).', $serialized_var_len, $this->getParam('hard_limit')), LOG_NOTICE, __FILE__, __LINE__);
    117             return false;
    118         }
    119 
    120         if (!isset($_SESSION['_session_cache'])) {
    121             $_SESSION['_session_cache'] = array();
    122         } else {
    123             unset($_SESSION['_session_cache'][$key]);
    124             // Continue to prune the cache if it's length is too long for the new variable to fit, but keep at least MIN_ITEMS at least.
    125             while (strlen(serialize($_SESSION['_session_cache'])) + $serialized_var_len >= $this->getParam('soft_limit')
    126             && sizeof($_SESSION['_session_cache']) >= $this->getParam('min_items')) {
    127                 array_shift($_SESSION['_session_cache']);
    128             }
    129         }
    130         $_SESSION['_session_cache'][$key] =& $serialized_var;
    131 
    132         if ($serialized_var_len >= 1024000) {
    133             $app->logMsg(sprintf('Successfully cached oversized variable (%s bytes).', $serialized_var_len), LOG_DEBUG, __FILE__, __LINE__);
     134        $var = serialize($var);
     135        $var_len = strlen($var);
     136
     137        if ($var_len >= $this->getParam('item_size_limit')) {
     138            $app->logMsg(sprintf('Serialized variable (%s bytes) more than item_size_limit (%s bytes).', $var_len, $this->getParam('item_size_limit')), LOG_NOTICE, __FILE__, __LINE__);
     139            return false;
     140        }
     141
     142        if ($flags & CACHE_ALLOW_OVERSIZED == 0 && $var_len >= $this->getParam('stack_size_limit')) {
     143            $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__);
     144            return false;
     145        }       
     146
     147        // Remove any value already stored under this key.
     148        unset($_SESSION[$this->_ns][$key]);
     149
     150        // Continue to prune the cache if its size is greater than stack_size_limit, but keep at least min_items.
     151        while (strlen(serialize($_SESSION[$this->_ns])) + $var_len >= $this->getParam('stack_size_limit') && sizeof($_SESSION[$this->_ns]) >= $this->getParam('min_items')) {
     152            array_shift($_SESSION[$this->_ns]);
     153        }
     154
     155        // Save this value under the specified key.
     156        $_SESSION[$this->_ns][$key] =& $var;
     157
     158        if ($var_len >= 1024000) {
     159            $app->logMsg(sprintf('Successfully cached oversized variable (%s bytes).', $var_len), LOG_DEBUG, __FILE__, __LINE__);
    134160        }
    135161
     
    144170     *
    145171     * @param string $key  The key for the datum to retrieve.
    146      *
    147172     * @return mixed          The requested datum, or false on failure.
    148173     */
    149174    function get($key)
    150175    {
    151         if (!$this->getParam('enabled')) {
    152             return false;
    153         }
    154 
    155         $key = md5($key);
    156         if (isset($_SESSION['_session_cache'][$key])) {
     176        if (true !== $this->getParam('enabled')) {
     177            return false;
     178        }
     179
     180        $key = md5($key);
     181        if (isset($_SESSION[$this->_ns][$key])) {
    157182            // Move the accessed cached datum to the top of the stack. Maybe somebody knows a better way to do this?
    158             $tmp =& $_SESSION['_session_cache'][$key];
    159             unset($_SESSION['_session_cache'][$key]);
    160             $_SESSION['_session_cache'][$key] =& $tmp;
     183            $tmp =& $_SESSION[$this->_ns][$key];
     184            unset($_SESSION[$this->_ns][$key]);
     185            $_SESSION[$this->_ns][$key] =& $tmp;
    161186            // Return the unserialized datum.
    162             return unserialize($_SESSION['_session_cache'][$key]);
     187            return unserialize($_SESSION[$this->_ns][$key]);
    163188        } else {
    164189            return false;
     
    170195     *
    171196     * @param string $key  The key of the object to check.
    172      *
    173197     * @return bool           The return from isset().
    174198     */
    175199    function exists($key)
    176200    {
    177         if (!$this->getParam('enabled')) {
    178             return false;
    179         }
    180 
    181         $key = md5($key);
    182         return isset($_SESSION['_session_cache'][$key]);
     201        if (true !== $this->getParam('enabled')) {
     202            return false;
     203        }
     204
     205        $key = md5($key);
     206        return array_key_exists($key, $_SESSION[$this->_ns]);
    183207    }
    184208
     
    187211     *
    188212     * @param string $key  The key of the object to check.
    189      *
    190213     * @return bool           The return from isset().
    191214     */
     
    193216    {
    194217        $key = md5($key);
    195         if (isset($_SESSION['_session_cache'][$key])) {
    196             unset($_SESSION['_session_cache'][$key]);
    197         }
     218        unset($_SESSION[$this->_ns][$key]);
     219    }
     220   
     221    /*
     222    * Delete all existing items from the cache.
     223    *
     224    * @access   public
     225    * @author   Quinn Comendant <quinn@strangecode.com>
     226    * @version  1.0
     227    * @since    05 Jun 2006 23:51:34
     228    */
     229    function clear()
     230    {
     231        $_SESSION[$this->_ns] = array();
    198232    }
    199233
  • trunk/lib/ImageThumb.inc.php

    r146 r152  
    99 */
    1010
    11 // Image resize options.
     11// Image proprtion options.
    1212define('IMAGETHUMB_FIT_WIDTH', 1);
    1313define('IMAGETHUMB_FIT_HEIGHT', 2);
     
    1515define('IMAGETHUMB_STRETCH', 4);
    1616define('IMAGETHUMB_NO_SCALE', 5);
     17
     18// Image resize options.
    1719define('IMAGETHUMB_METHOD_NETPBM', 6);
    1820define('IMAGETHUMB_METHOD_GD', 7);
     
    3234
    3335        // Permissions of autocreated directories. Must be at least 0700 with owner=apache.
    34         'dest_dir_perms' => 0777,
     36        'dest_dir_perms' => 0700,
    3537
    3638        // Require file to have one of the following file name extentions.
     
    5052   
    5153    // Default image size specs.
    52     var $default_image_specs = array(
    53         // The destination for an image thumbnail size. Path relative to source_dir (eg: ../thumbs).
     54    var $_default_image_specs = array(
     55        // The destination for an image thumbnail size.
     56        // Use initial / to specify absolute paths, leave off to specify a path relative to source_dir (eg: ../thumbs).
    5457        'dest_dir' => null,
    5558       
     
    8588
    8689    // Final specifications for image sizes, set with setSpec().
    87     var $image_specs = array();
     90    var $_image_specs = array();
    8891
    8992    /**
     
    99102        if (isset($params) && is_array($params)) {
    100103
    101             // Enforce valid upload_path parameter.
     104            // Enforce valid source_dir parameter.
    102105            if (isset($params['source_dir'])) {
    103106                $params['source_dir'] = realpath($params['source_dir']);
    104                 // Must be directory.
     107                // Source must be directory.
    105108                if (!is_dir($params['source_dir'])) {
    106                     $app->logMsg(sprintf('Source directory invalid: %s', $params['source_dir']), LOG_ERR, __FILE__, __LINE__);
    107                     trigger_error(sprintf('Source directory invalid: %s', $params['source_dir']), E_USER_ERROR);
    108                 }
    109                 // Must be readable.
     109                    $app->logMsg(sprintf('Attempting to auto-create source directory: %s', $params['source_dir']), LOG_NOTICE, __FILE__, __LINE__);
     110                    if (phpversion() > '5') {
     111                        // Recursive.
     112                        mkdir($params['source_dir'], isset($params['dest_dir_perms']) ? $params['dest_dir_perms'] : $this->getParam('dest_dir_perms'), true);
     113                    } else {
     114                        mkdir($params['source_dir'], isset($params['dest_dir_perms']) ? $params['dest_dir_perms'] : $this->getParam('dest_dir_perms'));
     115                    }
     116                    if (!is_dir($params['source_dir'])) {
     117                        $app->logMsg(sprintf('Source directory invalid: %s', $params['source_dir']), LOG_ERR, __FILE__, __LINE__);
     118                        trigger_error(sprintf('Source directory invalid: %s', $params['source_dir']), E_USER_ERROR);
     119                    }
     120                }
     121                // Source must be readable.
    110122                if (!is_readable($params['source_dir'])) {
    111123                    $app->logMsg(sprintf('Source directory not readable: %s', $params['source_dir']), LOG_ERR, __FILE__, __LINE__);
     
    151163
    152164        // A little sanity checking.
    153         if (!isset($spec['dest_dir']) || '' == $spec['dest_dir']) {
     165        if (!isset($spec['dest_dir']) || '' == trim($spec['dest_dir'])) {
    154166            $app->logMsg('setSpec error: dest_dir not specified.', LOG_ERR, __FILE__, __LINE__);
     167        } else {
     168            $spec['dest_dir'] = trim($spec['dest_dir']);           
    155169        }
    156170        if (isset($spec['dest_file_type'])) {
     
    198212        }
    199213       
    200         if (isset($index) && isset($this->image_specs[$index])) {
    201             // Merge with previous.
    202             $final_spec = array_merge($this->image_specs[$index], $spec);
    203             $this->image_specs[$index] = $final_spec;
     214        // Add to _image_specs array.
     215        if (isset($index) && isset($this->_image_specs[$index])) {
     216            // Merge with existing spec if index is provided.
     217            $final_spec = array_merge($this->_image_specs[$index], $spec);
     218            $this->_image_specs[$index] = $final_spec;
    204219        } else {
    205             // Merge with defaults.
    206             $final_spec = array_merge($this->default_image_specs, $spec);           
    207             $this->image_specs[] = $final_spec;
     220            // Merge with spec defaults.
     221            $final_spec = array_merge($this->_default_image_specs, $spec);           
     222            $this->_image_specs[] = $final_spec;
    208223        }
    209224       
     
    245260            return 0 === $return_val;
    246261        } else {
    247             $app->logMsg(sprintf('No images found to thumbnail in directory %s.', $this->getParam('source_dir')), LOG_NOTICE, __FILE__, __LINE__);
     262            $app->logMsg(sprintf('No source images found in directory: %s', $this->getParam('source_dir')), LOG_NOTICE, __FILE__, __LINE__);
    248263            return false;
    249264        }
     
    266281       
    267282        // Ensure we have a source.
    268         if (sizeof($this->image_specs) < 1) {
     283        if (sizeof($this->_image_specs) < 1) {
    269284            if (is_array($runtime_specs)) {
    270285                $this->setSpec($runtime_specs, 0);
     
    284299        if (!file_exists($source_file)) {
    285300            $this->_raiseMsg(sprintf(_("Image resizing failed: source image %s was not found."), $file_name), MSG_ERR, __FILE__, __LINE__);
    286             $app->logMsg(sprintf('Source image not found: %s', $source_file), LOG_ALERT, __FILE__, __LINE__);
     301            $app->logMsg(sprintf('Source image not found: %s', $source_file), LOG_WARNING, __FILE__, __LINE__);
    287302            return false;
    288303        }
     
    291306        if (!is_readable($source_file)) {
    292307            $this->_raiseMsg(sprintf(_("Image resizing failed: source image %s is not readable."), $file_name), MSG_ERR, __FILE__, __LINE__);
    293             $app->logMsg(sprintf('Source image not readable: %s', $source_file), LOG_ALERT, __FILE__, __LINE__);
     308            $app->logMsg(sprintf('Source image not readable: %s', $source_file), LOG_WARNING, __FILE__, __LINE__);
    294309            return false;
    295310        }
     
    298313        if (filesize($source_file) <= 0) {
    299314            $this->_raiseMsg(sprintf(_("Image resizing failed: source image %s is zero bytes."), $file_name), MSG_ERR, __FILE__, __LINE__);
    300             $app->logMsg(sprintf('Source image is zero bytes: %s', $source_file), LOG_ALERT, __FILE__, __LINE__);
     315            $app->logMsg(sprintf('Source image is zero bytes: %s', $source_file), LOG_WARNING, __FILE__, __LINE__);
    301316            return false;
    302317        }
     
    310325
    311326        // Ensure destination directories are created. This will only be called once per page load.
    312         $this->_createDestDirs();
     327        if (!$this->_createDestDirs()) {
     328            return false;
     329        }
    313330       
    314331        // To keep this script running even if user tries to stop browser.
     
    320337        $return_val = 0;
    321338
    322         foreach ($this->image_specs as $index => $spec) {
     339        foreach ($this->_image_specs as $index => $spec) {
    323340           
    324341            if (is_array($runtime_specs)) {
     
    328345           
    329346            // Destination filename uses the extention defined by dest_file_extention.
    330             $dest_file = realpath(sprintf('%s/%s/%s.%s', $this->getParam('source_dir'), $spec['dest_dir'], substr($file_name, 0, strrpos($file_name, '.')), $spec['dest_file_extention']));
     347            if ('/' == $spec['dest_dir']{0}) {
     348                // Absolute path.
     349                $dest_file = sprintf('%s/%s.%s', $spec['dest_dir'], substr($file_name, 0, strrpos($file_name, '.')), $spec['dest_file_extention']);
     350            } else {
     351                // Relative path.
     352                $dest_file = sprintf('%s/%s/%s.%s', $this->getParam('source_dir'), $spec['dest_dir'], substr($file_name, 0, strrpos($file_name, '.')), $spec['dest_file_extention']);
     353            }
     354                 
     355            // Ensure destination directory exists and is writable.
     356            if (!is_dir(dirname($dest_file)) || !is_writable(dirname($dest_file))) {
     357                $this->_createDestDirs($dest_file);
     358                if (!is_dir(dirname($dest_file)) || !is_writable(dirname($dest_file))) {
     359                    $app->logMsg(sprintf('Image resizing failed, dest_dir invalid: %s', dirname($dest_file)), LOG_ERR, __FILE__, __LINE__);
     360                    $return_val++;
     361                    continue;
     362                }
     363            }
    331364
    332365            // Skip existing thumbnails with file size below $spec['keep_filesize'].
     
    343376            if ($image_size['0'] <= $spec['width'] && $image_size['1'] <= $spec['height'] && !$spec['allow_upscaling']) {
    344377                $spec['scaling_type'] = IMAGETHUMB_NO_SCALE;
    345                 $app->logMsg(sprintf('Image %s smaller than specified %s thumbnail size. Keeping original size.', $file_name, $spec['dest_dir']), LOG_DEBUG, __FILE__, __LINE__);
     378                $app->logMsg(sprintf('Image %s smaller than specified %s thumbnail size. Keeping original size.', $file_name, basename($spec['dest_dir'])), LOG_DEBUG, __FILE__, __LINE__);
    346379            }
    347380
     
    349382            if (IMAGETHUMB_METHOD_NETPBM === $this->getParam('resize_method') && file_exists($this->getParam('anytopnm_binary')) && file_exists($this->getParam('pnmscale_binary')) && file_exists($this->getParam('cjpeg_binary'))) {
    350383                // Resize using Netpbm binaries.
    351                 $app->logMsg(sprintf('Resizing with Netpbm...', null), LOG_DEBUG, __FILE__, __LINE__);
     384                $app->logMsg(sprintf('Resizing with Netpbm: %s', $file_name), LOG_DEBUG, __FILE__, __LINE__);
    352385                $return_val += $this->_resizeWithNetpbm($source_file, $dest_file, $spec);
    353386            } else if (IMAGETHUMB_METHOD_GD === $this->getParam('resize_method') && extension_loaded('gd')) {
    354387                // Resize with GD.
    355                 $app->logMsg(sprintf('Resizing with GD...', null), LOG_DEBUG, __FILE__, __LINE__);
     388                $app->logMsg(sprintf('Resizing with GD: %s', $file_name), LOG_DEBUG, __FILE__, __LINE__);
    356389                $return_val += $this->_resizeWithGD($source_file, $dest_file, $spec);
    357390            } else {
    358                 $app->logMsg(sprintf('Image thumbnailing failed. Neither Netpbm or GD is available.', null), LOG_DEBUG, __FILE__, __LINE__);
     391                $app->logMsg(sprintf('Image thumbnailing canceled. Neither Netpbm or GD is available.', null), LOG_ERR, __FILE__, __LINE__);
    359392                return false;
    360393            }
    361394        }
    362395
    363         // If > 0, there was a problem thumb-nailing.
     396        // If > 0, there was a problem thumbnailing.
    364397        return 0 === $return_val;
    365398    }
     
    516549        if (!imagecopyresampled($dest_image_resource, $source_image_resource, 0, 0, 0, 0, $dest_image_width, $dest_image_height, $source_image_width, $source_image_height)) {
    517550            $app->logMsg(sprintf('Error resampling image %s', $source_file), LOG_WARNING, __FILE__, __LINE__);
     551            // Always cleanup images from memory.
     552            imagedestroy($source_image_resource);
     553            imagedestroy($dest_image_resource);
    518554            return 1;
    519555        }
     
    543579        default :
    544580            $app->logMsg(sprintf('Destination image type %s not supported for image %s.', $spec['dest_file_type'], $dest_file), LOG_WARNING, __FILE__, __LINE__);
     581            // Always cleanup images from memory.
     582            imagedestroy($source_image_resource);
     583            imagedestroy($dest_image_resource);
    545584            return 1;
    546585            break;
    547586        }
     587
     588        // Always cleanup images from memory.
     589        imagedestroy($source_image_resource);
     590        imagedestroy($dest_image_resource);
    548591
    549592        if ($return_val) {
    550593            // Success!
    551594            // Make the thumbnail writable so the user can delete it over ftp without being 'apache'.
    552             chmod($dest_file, $this->getParam('dest_file_perms'));
    553             $app->logMsg(sprintf('Successfully resized image %s', $dest_file), LOG_DEBUG, __FILE__, __LINE__);
     595            if (!chmod($dest_file, $this->getParam('dest_file_perms'))) {
     596                $app->logMsg(sprintf('chmod failed on file: %s', $dest_file), LOG_ERR, __FILE__, __LINE__);
     597            }
     598            $app->logMsg(sprintf('Successfully resized image: %s', $dest_file), LOG_DEBUG, __FILE__, __LINE__);
    554599            return 0;
    555600        } else {
    556601            // An error occurred.
    557             $app->logMsg(sprintf('Image %s failed resizing.', $dest_file), LOG_ERR, __FILE__, __LINE__);
     602            $app->logMsg(sprintf('Failed resizing image: %s', $dest_file), LOG_ERR, __FILE__, __LINE__);
    558603            return 1;
    559604        }
     
    578623
    579624        $return_val = 0;
    580         foreach ($this->image_specs as $spec) {
    581             $dest_file = realpath(sprintf('%s/%s/%s.%s', $this->getParam('source_dir'), $spec['dest_dir'], substr($file_name, 0, strrpos($file_name, '.')), $spec['dest_file_extention']));
     625        foreach ($this->_image_specs as $spec) {
     626            if ('/' == $spec['dest_dir']{0}) {
     627                // Absolute path.
     628                $dest_file = realpath(sprintf('%s/%s.%s', $spec['dest_dir'], substr($file_name, 0, strrpos($file_name, '.')), $spec['dest_file_extention']));               
     629            } else {
     630                // Relative path.
     631                $dest_file = realpath(sprintf('%s/%s/%s.%s', $this->getParam('source_dir'), $spec['dest_dir'], substr($file_name, 0, strrpos($file_name, '.')), $spec['dest_file_extention']));
     632            }
    582633            if (file_exists($dest_file)) {
    583634                if (!unlink($dest_file)) {
     
    657708     * @return  bool true on success, false on failure.
    658709     */
    659     function _createDestDirs()
    660     {
    661         $app =& App::getInstance();
    662 
    663         static $already_checked = false;
    664 
    665         if (!$already_checked) {
     710    function _createDestDirs($filename=null)
     711    {
     712        $app =& App::getInstance();
     713
     714        // Keep track of directories we've already created.
     715        $dd_hash = md5(isset($filename) ? dirname($filename) : 'none');
     716        static $already_checked = array();
     717
     718        $return_val = 0;
     719
     720        if (!isset($already_checked[$dd_hash])) {
    666721            // Ensure we have a source.
    667722            if ('' == $this->getParam('source_dir')) {
     
    671726       
    672727            // Loop through specs and ensure all dirs are created.
    673             $return_val = 0;
    674             foreach ($this->image_specs as $spec) {
    675                 if (!file_exists($this->getParam('source_dir') . '/' . $spec['dest_dir'])) {
    676                     if (!mkdir($this->getParam('source_dir') . '/' . $spec['dest_dir'], $this->getParam('dest_dir_perms'))) {
    677                         $return_val++;
    678                         $app->logMsg(sprintf('mkdir failure: %s', $this->getParam('source_dir') . '/' . $spec['dest_dir']), LOG_ERR, __FILE__, __LINE__);
     728            foreach ($this->_image_specs as $spec) {
     729                if (isset($filename)) {
     730                    $dest_dir = dirname($filename);
     731                } else {
     732                    if ('/' == $spec['dest_dir']{0}) {
     733                        // Absolute path.
     734                        $dest_dir = $spec['dest_dir'];
     735                    } else {
     736                        // Relative path.
     737                        $dest_dir = sprintf('%s/%s', $this->getParam('source_dir'), $spec['dest_dir']);
    679738                    }
    680739                }
    681             }
    682 
    683             // If > 0, there was a problem creating dest dirs.
    684             return 0 === $return_val;
    685         }
    686 
    687         $already_checked = true;
     740                if (!file_exists($dest_dir)) {
     741                    if (phpversion() > '5' && false) { ///
     742                        // Recursive.
     743                        if (! ($ret = mkdir($dest_dir, $this->getParam('dest_dir_perms'), true))) {
     744                            $return_val++;
     745                            $app->logMsg(sprintf('mkdir failure: %s', $dest_dir), LOG_ERR, __FILE__, __LINE__);
     746                        }
     747                    } else {
     748                        // Recursive mkdir for php 4.
     749                        $path = '';
     750                        foreach (array_diff(explode('/', $dest_dir), array('')) as $dir) {
     751                            $path .= '/' . $dir;
     752                            if (! ($ret = file_exists($path) ? true : mkdir($path, $this->getParam('dest_dir_perms')))) {
     753                                $return_val++;
     754                                $app->logMsg(sprintf('mkdir failure: %s', $path), LOG_ERR, __FILE__, __LINE__);
     755                                break;
     756                            }
     757                        }
     758                    }
     759
     760                    if ($ret) {
     761                        $app->logMsg(sprintf('mkdir success: %s', $dest_dir), LOG_DEBUG, __FILE__, __LINE__);                       
     762                    }
     763                }
     764            }
     765        }
     766
     767        $already_checked[$dd_hash] = true;
     768
     769        // If > 0, there was a problem creating dest dirs.
     770        return 0 === $return_val;
    688771    }
    689772
  • trunk/lib/PageNumbers.inc.php

    r136 r152  
    7272    function setPerPage($per_page, $default=25, $save_value=true)
    7373    {
    74         $prefs =& Prefs::getInstance();
     74        $prefs =& Prefs::getInstance($_SERVER['PHP_SELF']);
     75        $prefs->setParam(array('persistent' => false));
    7576   
    7677        // (1) By provided argument, if valid.
     
    8182            $this->_per_page = $per_page;
    8283            if ($save_value) {
    83                 $prefs->set('items_per_page', $this->_per_page, $_SERVER['PHP_SELF']);
    84             }
    85         } else if ($save_value && $prefs->exists('items_per_page', $_SERVER['PHP_SELF'])) {
    86             $this->_per_page = (int)$prefs->get('items_per_page', $_SERVER['PHP_SELF']);
     84                $prefs->set('items_per_page', $this->_per_page);
     85            }
     86        } else if ($save_value && $prefs->exists('items_per_page')) {
     87            $this->_per_page = (int)$prefs->get('items_per_page');
    8788        } else if (is_numeric($default) && $default > 0) {
    8889            $this->_per_page = $default;
     
    9697    function setPageNumber($page_number, $save_value=true)
    9798    {
    98         $prefs =& Prefs::getInstance();
     99        $prefs =& Prefs::getInstance($_SERVER['PHP_SELF']);
     100        $prefs->setParam(array('persistent' => false));
    99101   
    100     // (1) By provided argument, if valid.
     102        // (1) By provided argument, if valid.
    101103        // (2) By saved preference, if available.
    102104        // (3) Don't change from what was provided at class instantiation.
     
    109111            }
    110112            if ($save_value) {
    111                 $prefs->set('page_number', $this->current_page, $_SERVER['PHP_SELF']);
    112             }
    113         } else if ($save_value && $prefs->exists('page_number', $_SERVER['PHP_SELF'])) {
    114             $this->current_page = (int)$prefs->get('page_number', $_SERVER['PHP_SELF']);
     113                $prefs->set('page_number', $this->current_page);
     114            }
     115        } else if ($save_value && $prefs->exists('page_number')) {
     116            $this->current_page = (int)$prefs->get('page_number');
    115117        }
    116118        $this->set_page_number_initialized = true;
  • trunk/lib/Prefs.inc.php

    r151 r152  
    1414// Load preferences for the user's session.
    1515require_once 'codebase/lib/Prefs.inc.php';
    16 $prefs = new Prefs('bURB');
     16$prefs =& Prefs::getInstance('my-namespace');
    1717$prefs->setParam(array(
    18     'enable_db' => $auth->isLoggedIn(),
     18    'persistent' => $auth->isLoggedIn(),
    1919    'user_id' => $auth->get('user_id'),
    2020));
     
    3737    var $_ns;
    3838
    39     // Configuration of this object.
     39    // Configuration parameters for this object.
    4040    var $_params = array(
    4141       
    42         // The current user_id for which to load/save preferences.
     42        // Enable database storage. If this is false, all prefs will live only as long as the session.
     43        'persistent' => false,
     44       
     45        // The current user_id for which to load/save persistent preferences.
    4346        'user_id' => null,
    4447       
    45         // How long before we force a reload of the prefs data? 3600 = once every hour.
     48        // How long before we force a reload of the persistent prefs data? 3600 = once every hour.
    4649        'load_timeout' => 3600,
    4750       
    48         // Enable database storage.
    49         'enable_db' => true,
    50        
    51         // Name of database table to store prefs.
     51        // Name of database table to store persistent prefs.
    5252        'db_table' => 'pref_tbl',
    5353
     
    7474            $this->setParam(array('create_table' => $app->getParam('db_create_tables')));
    7575        }
     76    }
     77
     78    /**
     79     * This method enforces the singleton pattern for this class.
     80     *
     81     * @return  object  Reference to the global Prefs object.
     82     * @access  public
     83     * @static
     84     */
     85    function &getInstance($namespace='')
     86    {
     87        static $instances = array();
     88
     89        if (!array_key_exists($namespace, $instances)) {
     90            $instances[$namespace] = new Prefs($namespace);
     91        }
     92
     93        return $instances[$namespace];
    7694    }
    7795
     
    167185     * This function determins what data is saved to the database. Ensure clean values!
    168186     *
    169      * @param  string $key       The name of the preference to modify.
    170      * @param  string $val       The new value for this preference.
     187     * @param  string $key          The name of the preference to modify.
     188     * @param  string $val          The new value for this preference.
     189     * @param  bool   $persistent   Save this value forever? Set to false and value will exist as long as the session is in use.
    171190     */
    172191    function set($key, $val)
    173192    {
    174193        $app =& App::getInstance();
     194
    175195        if ('' == $key) {
    176196            $app->logMsg(sprintf('Key is empty (provided with value: %s)', $val), LOG_NOTICE, __FILE__, __LINE__);
    177197            return false;
    178198        }
     199       
    179200        if (!isset($_SESSION[$this->_ns]['defaults'][$key]) || $_SESSION[$this->_ns]['defaults'][$key] != $val || isset($_SESSION[$this->_ns]['persistent'][$key])) {
    180201            $_SESSION[$this->_ns]['persistent'][$key] = $val;           
     
    193214    {
    194215        $app =& App::getInstance();
    195         if (isset($_SESSION[$this->_ns]['persistent'][$key])) {
     216        if (array_key_exists($key, $_SESSION[$this->_ns]['persistent'])) {
    196217            return $_SESSION[$this->_ns]['persistent'][$key];
    197         } else if (isset($_SESSION[$this->_ns]['defaults'][$key])) {
     218        } else if (array_key_exists($key, $_SESSION[$this->_ns]['defaults'])) {
    198219            return $_SESSION[$this->_ns]['defaults'][$key];
    199220        } else {
    200             $app->logMsg(sprintf('Key not defined in default or persistent prefs cache: %s', $key), LOG_NOTICE, __FILE__, __LINE__);
     221            $app->logMsg(sprintf('Key not found in prefs cache: %s', $key), LOG_NOTICE, __FILE__, __LINE__);
    201222            return null;
    202223        }
     
    204225
    205226    /**
    206      * To see if a persistent preference has been set.
     227     * To see if a preference has been set.
    207228     *
    208229     * @param string $key       The name of the preference to check.
     
    211232    function exists($key)
    212233    {
    213         return isset($_SESSION[$this->_ns]['persistent'][$key]);
     234        return array_key_exists($key, $_SESSION[$this->_ns]['persistent']);
    214235    }
    215236
     
    254275       
    255276        // Skip this method if not using the db.
    256         if (true !== $this->getParam('enable_db')) {
     277        if (true !== $this->getParam('persistent')) {
    257278            return true;
    258279        }
     
    332353       
    333354        // Skip this method if not using the db.
    334         if (true !== $this->getParam('enable_db')) {
     355        if (true !== $this->getParam('persistent')) {
    335356            return true;
    336357        }
  • trunk/lib/SortOrder.inc.php

    r136 r152  
    6969    function setDefault($default_sort = '', $default_order = '')
    7070    {
    71         $prefs =& Prefs::getInstance();
     71        $prefs =& Prefs::getInstance($_SERVER['PHP_SELF']);
     72        $prefs->setParam(array('persistent' => false));
    7273
    7374        // Which column to sort by?
     
    7879        if (!empty($new_sort_by)) {
    7980            $this->sort_by = $new_sort_by;
    80             $prefs->set('sort_by', $this->sort_by, $_SERVER['PHP_SELF']);
    81         } else if ($prefs->exists('sort_by', $_SERVER['PHP_SELF'])) {
    82             $this->sort_by = $prefs->get('sort_by', $_SERVER['PHP_SELF']);
     81            $prefs->set('sort_by', $this->sort_by);
     82        } else if ($prefs->exists('sort_by')) {
     83            $this->sort_by = $prefs->get('sort_by');
    8384        } else {
    8485            $this->sort_by = $default_sort;
     
    9293        if (!empty($new_order)) {
    9394            $this->order = $new_order;
    94             $prefs->set('sort_order', $this->order, $_SERVER['PHP_SELF']);
    95         } else if ($prefs->exists('sort_order', $_SERVER['PHP_SELF'])) {
    96             $this->order = $prefs->get('sort_order', $_SERVER['PHP_SELF']);
     95            $prefs->set('sort_order', $this->order);
     96        } else if ($prefs->exists('sort_order')) {
     97            $this->order = $prefs->get('sort_order');
    9798        } else {
    9899            $this->order = $default_order;
     
    111112    function set($sort = null, $order = null)
    112113    {
    113         $prefs =& Prefs::getInstance();
     114        $prefs =& Prefs::getInstance($_SERVER['PHP_SELF']);
     115        $prefs->setParam(array('persistent' => false));
    114116
    115117        // Set new sort value.
    116118        if (isset($sort)) {
    117119            $this->sort_by = $sort;
    118             $prefs->set('sort_by', $this->sort_by, $_SERVER['PHP_SELF']);
     120            $prefs->set('sort_by', $this->sort_by);
    119121        }
    120122
     
    122124        if (isset($order)) {
    123125            $this->order = $order;
    124             $prefs->set('sort_order', $this->order, $_SERVER['PHP_SELF']);
     126            $prefs->set('sort_order', $this->order);
    125127        }
    126128    }
  • trunk/lib/Upload.inc.php

    r146 r152  
    6363            if (isset($params['upload_path'])) {
    6464                $params['upload_path'] = realpath($params['upload_path']);
    65                 // Must be directory.
     65                // Source must be directory.
    6666                if (!is_dir($params['upload_path'])) {
    6767                    $app->logMsg(sprintf('Attempting to auto-create upload directory: %s', $params['upload_path']), LOG_NOTICE, __FILE__, __LINE__);
    68                     mkdir($params['upload_path'], $this->getParam('dest_dir_perms'));
     68                    if (phpversion() > '5') {
     69                        // Recursive.
     70                        mkdir($params['upload_path'], isset($params['dest_dir_perms']) ? $params['dest_dir_perms'] : $this->getParam('dest_dir_perms'), true);
     71                    } else {
     72                        mkdir($params['upload_path'], isset($params['dest_dir_perms']) ? $params['dest_dir_perms'] : $this->getParam('dest_dir_perms'));
     73                    }
    6974                    if (!is_dir($params['upload_path'])) {
    7075                        $app->logMsg(sprintf('Upload directory invalid: %s', $params['upload_path']), LOG_ERR, __FILE__, __LINE__);
     
    7277                    }
    7378                }
    74                 // Must be writable.
     79                // Source must be writable.
    7580                if (!is_writable($params['upload_path'])) {
    7681                    $app->logMsg(sprintf('Upload directory not writable: %s', $params['upload_path']), LOG_ERR, __FILE__, __LINE__);
  • trunk/services/admins.php

    r147 r152  
    3030$fv = new FormValidator();
    3131
    32 $cache =& Cache::getInstance();
     32// Configure the prefs object.
     33$prefs =& Prefs::getInstance('admins');
     34$prefs->setParam(array('persistent' => false));
     35
     36// Configure the cache object.
     37$cache =& Cache::getInstance('admins');
     38$cache->setParam(array('enable' => true));
    3339
    3440// Instantiate a sorting object with the default sort and order. Add SQL for each column.
     
    7076
    7177if (getFormData('break_list_cache', false)) {
    72     // Break the cache because we are changing the list data.
    73     $cache->delete($_SERVER['PHP_SELF']);
     78    // Remove any stale cached list data.
     79    $cache->delete('list');
    7480}
    7581
     
    319325    $app =& App::getInstance();
    320326    $db =& DB::getInstance();
    321     $cache =& Cache::getInstance();
     327    $cache =& Cache::getInstance('admins');
    322328   
    323329    $lock->select('admin_tbl', 'admin_id', $id);
     
    326332    }
    327333
    328     // Break the cache because we are changing the list data.
    329     $cache->delete($_SERVER['PHP_SELF']);
     334    // Remove any stale cached list data.
     335    $cache->delete('list');
    330336
    331337    // Get the information for this object.
     
    367373    $app =& App::getInstance();
    368374    $db =& DB::getInstance();
    369     $cache =& Cache::getInstance();
     375    $cache =& Cache::getInstance('admins');
    370376   
    371     // Break the cache because we are changing the list data.
    372     $cache->delete($_SERVER['PHP_SELF']);
     377    // Remove any stale cached list data.
     378    $cache->delete('list');
    373379
    374380    // Insert record data.
     
    411417    $app =& App::getInstance();
    412418    $db =& DB::getInstance();
    413     $cache =& Cache::getInstance();
     419    $cache =& Cache::getInstance('admins');
    414420   
    415421    $lock->select('admin_tbl', 'admin_id', $frm['admin_id']);
     
    418424    }
    419425
    420     // Break the cache because we are changing the list data.
    421     $cache->delete($_SERVER['PHP_SELF']);
     426    // Remove any stale cached list data.
     427    $cache->delete('list');
    422428
    423429    // If the userpass is left blank or with the filler **** characters, we don't want to update it.
     
    455461    global $so;
    456462    $db =& DB::getInstance();
    457     $prefs =& Prefs::getInstance();
    458     $cache =& Cache::getInstance();
     463    $prefs =& Prefs::getInstance('admins');
     464    $cache =& Cache::getInstance('admins');
    459465   
    460466    $where_clause = '';
     
    501507    ";
    502508
     509    // Use a cash hash to determine if the result-set has changed.
    503510    // A unique key for this query, with the total_items in case db records
    504511    // were added since the last cache. This identifies a unique set of
     
    507514    // without knowing the hash.
    508515    $cache_hash = md5($sql . '|' . $page->total_items);
    509     if ($prefs->get('cache_hash', $_SERVER['PHP_SELF']) != $cache_hash) {
    510         $cache->delete($_SERVER['PHP_SELF']);
    511         $prefs->set('cache_hash', $cache_hash, $_SERVER['PHP_SELF']);
    512     }
    513 
    514     if ($cache->exists($_SERVER['PHP_SELF']) && false) {
    515         // Get the cached results.
    516         $list = $cache->get($_SERVER['PHP_SELF']);
    517     } else {
    518         // If the list is not already cached, query now.
    519         $qid = $db->query($sql);
    520         // Fill an array with the items for this page.
    521         while ($row = mysql_fetch_assoc($qid)) {
    522             $list[] = $row;
    523         }
    524 
    525         if (isset($list) && !empty($list)) {
    526             // Cache the results.
    527             $cache->set($list, $_SERVER['PHP_SELF']);
    528         }
     516    if ($prefs->get('cache_hash') != $cache_hash) {
     517        $cache->delete('list');
     518        $prefs->set('cache_hash', $cache_hash);
     519    }
     520
     521    // First try to return from the cache.
     522    if ($cache->exists('list')) {
     523        return $cache->get('list');
     524    }
     525   
     526    // The list was not cached, so issue the real query.
     527    $qid = $db->query($sql);
     528    while ($row = mysql_fetch_assoc($qid)) {
     529        $list[] = $row;
     530    }
     531
     532    // Save this list into the cache.
     533    if (isset($list) && !empty($list)) {
     534        $cache->set('list', $list);
    529535    }
    530536
  • trunk/services/logs.php

    r143 r152  
    3939
    4040// Set the defaults and catch incoming settings.
    41 $prefs =& Prefs::getInstance();
    42 $prefs->setDefault('log_file', $app->getParam('log_filename'), 'logs_module');
    43 $prefs->set('log_file', getFormData('log'), 'logs_module');
     41$prefs =& Prefs::getInstance('admin_logs');
     42$prefs->setDefaults(array(
     43    'log_file' => $app->getParam('log_filename')
     44));
     45$prefs->set('log_file', getFormData('log'));
    4446
    4547// Titles and navigation header.
    46 $nav->addPage(sprintf(_("Viewing log: <em>%s</em>"), $prefs->get('log_file', 'logs_module')), '/admin/logs.php');
     48$nav->addPage(sprintf(_("Viewing log: <em>%s</em>"), $prefs->get('log_file')), '/admin/logs.php');
    4749
    4850/********************************************************************
     
    5759case 'delete' :
    5860//     $auth->requireAccessClearance(ZONE_ADMIN_APPLOG_FUNC_RESET);
    59     deleteLog($prefs->get('log_file', 'logs_module'));
    60     $prefs->set('log_file', $app->getParam('log_filename'), 'logs_module');
     61    deleteLog($prefs->get('log_file'));
     62    $prefs->set('log_file', $app->getParam('log_filename'));
    6163    if ($app->validBoomerangURL('app_log')) {
    6264        // Display boomerang page.
     
    6971case 'clear' :
    7072//     $auth->requireAccessClearance(ZONE_ADMIN_APPLOG_FUNC_RESET);
    71     clearLog($prefs->get('log_file', 'logs_module'));
     73    clearLog($prefs->get('log_file'));
    7274    if ($app->validBoomerangURL('app_log')) {
    7375        // Display boomerang page.
     
    8082case 'archive' :
    8183//     $auth->requireAccessClearance(ZONE_ADMIN_APPLOG_FUNC_RESET);
    82     if (archiveLog($prefs->get('log_file', 'logs_module'))) {
     84    if (archiveLog($prefs->get('log_file'))) {
    8385        // Now flush current log.
    8486        $app->dieURL($_SERVER['PHP_SELF'] . '?op=clear');
     
    98100case 'download' :
    99101    header('Content-Type: application/octet-stream');
    100     header(sprintf('Content-Disposition: attachment; filename=%s.txt', $prefs->get('log_file', 'logs_module')));
    101     printLog($prefs->get('log_file', 'logs_module'));
     102    header(sprintf('Content-Disposition: attachment; filename=%s.txt', $prefs->get('log_file')));
     103    printLog($prefs->get('log_file'));
    102104    die;
    103105    break;
    104106
    105107default :
    106     $list =& getLog($prefs->get('log_file', 'logs_module'), getFormData('search_query'));
     108    $list =& getLog($prefs->get('log_file'), getFormData('search_query'));
    107109    $main_template = 'log_list.ihtml';
    108110    break;
     
    126128include 'header.ihtml';
    127129if ('output' == $main_template) {
    128     printLog($prefs->get('log_file', 'logs_module'));
     130    printLog($prefs->get('log_file'));
    129131} else {
    130132    include 'codebase/services/templates/' . $main_template;
  • trunk/services/templates/log_list.ihtml

    r136 r152  
    1010        <tr class="commandtext">
    1111            <td>
    12                 <?php if ($l['filename'] == $prefs->get('log_file', 'logs_module')) { ?>
     12                <?php if ($l['filename'] == $prefs->get('log_file')) { ?>
    1313                    <span class="commanditem"><strong><?php echo sprintf(_("%s"), $l['filename']); ?></strong></span>
    1414                <?php } else { ?>
Note: See TracChangeset for help on using the changeset viewer.