Changeset 152 for trunk/services


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/services
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • 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.