plugins/admin/CacheManager.php
author Dan
Sat, 12 Jul 2008 03:32:57 -0400
changeset 628 ab6f55abb17e
parent 613 c08670a77871
child 685 17ebe24cdf85
permissions -rw-r--r--
Rank editor is now in a working (beautiful) state. More intuitive than a Mac.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
605
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
     1
<?php
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
     2
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
     3
/*
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
     4
 * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
     5
 * Version 1.1.4 (Caoineag alpha 4)
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
     6
 * Copyright (C) 2006-2008 Dan Fuhry
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
     7
 *
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
     8
 * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
     9
 * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
    10
 *
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
    12
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
    13
 */
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
    14
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
    15
// Cache manager - regenerate and clear various cached values
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
    16
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
    17
function page_Admin_CacheManager()
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
    18
{
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
    19
  global $db, $session, $paths, $template, $plugins; // Common objects
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
    20
  global $lang;
613
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    21
  global $cache;
605
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
    22
  if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
    23
  {
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
    24
    $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true);
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
    25
    echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
    26
    echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
    27
    return;
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
    28
  }
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
    29
  
613
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    30
  // validation/actions
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    31
  if ( isset($_POST['refresh']) || isset($_POST['clear']) )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    32
  {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    33
    $success = false;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    34
    
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    35
    $target = ( isset($_POST['refresh']) ) ? $_POST['refresh'] : $_POST['clear'];
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    36
    $do_refresh = isset($_POST['refresh']);
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    37
    switch ( $target )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    38
    {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    39
      case 'page':
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    40
        $success = $cache->purge('page_meta');
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    41
        if ( $do_refresh && $success )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    42
          $success = $paths->update_metadata_cache();
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    43
        break;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    44
      case 'ranks':
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    45
        $success = $cache->purge('ranks');
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    46
        if ( $do_refresh && $success )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    47
          $success = generate_cache_userranks();
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    48
        break;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    49
      case 'sidebar':
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    50
        $success = $cache->purge('anon_sidebar');
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    51
        break;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    52
      case 'plugins':
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    53
        $success = $cache->purge('plugins');
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    54
        if ( $do_refresh && $success )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    55
          $success = $plugins->generate_plugins_cache();
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    56
        break;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    57
      case 'template':
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    58
        if ( $dh = opendir(ENANO_ROOT . '/cache') )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    59
        {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    60
          while ( $file = @readdir($dh) )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    61
          {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    62
            $fullpath = ENANO_ROOT . "/cache/$file";
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    63
            // we don't want to mess with directories
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    64
            if ( !is_file($fullpath) )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    65
              continue;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    66
            
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    67
            if ( preg_match('/\.(?:tpl|css)\.php$/', $file) )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    68
            {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    69
              unlink($fullpath);
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    70
            }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    71
          }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    72
          $success = true;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    73
        }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    74
        break;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    75
      case 'aes':
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    76
        $success = @unlink(ENANO_ROOT . '/cache/aes_decrypt.php');
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    77
        break;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    78
      case 'lang':
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    79
        if ( $dh = opendir(ENANO_ROOT . '/cache') )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    80
        {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    81
          while ( $file = @readdir($dh) )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    82
          {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    83
            $fullpath = ENANO_ROOT . "/cache/$file";
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    84
            // we don't want to mess with directories
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    85
            if ( !is_file($fullpath) )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    86
              continue;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    87
            
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    88
            if ( preg_match('/^lang_json_(?:[a-f0-9]+?)\.php$/', $file) || preg_match('/^(?:cache_)?lang_(?:[0-9]+?)\.php$/', $file) )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    89
              unlink($fullpath);
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    90
          }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    91
          $success = true;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    92
        }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    93
        if ( $do_refresh && $success )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    94
        {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    95
          // for each language in the database, call regen_caches()
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    96
          $q = $db->sql_query('SELECT lang_id FROM ' . table_prefix . 'language;');
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    97
          if ( !$q )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    98
            $db->_die();
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
    99
          while ( $row = $db->fetchrow($q) )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   100
          {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   101
            $lang_local = ( $row['lang_id'] == $lang->lang_id ) ? $lang : new Language($row['lang_id']);
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   102
            $success = $lang_local->regen_caches();
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   103
            if ( !$success )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   104
              break 2;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   105
          }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   106
        }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   107
        break;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   108
      case 'js':
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   109
        if ( $dh = opendir(ENANO_ROOT . '/cache') )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   110
        {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   111
          while ( $file = @readdir($dh) )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   112
          {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   113
            $fullpath = ENANO_ROOT . "/cache/$file";
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   114
            // we don't want to mess with directories
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   115
            if ( !is_file($fullpath) )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   116
              continue;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   117
            
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   118
            // compressed javascript
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   119
            if ( preg_match('/^jsres_(?:[A-z0-9_-]+)\.js\.json$/', $file) )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   120
              unlink($fullpath);
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   121
            // tinymce stuff
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   122
            else if ( preg_match('/^tiny_mce_(?:[a-f0-9]+)\.gz$/', $file) )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   123
              unlink($fullpath);
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   124
          }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   125
          $success = true;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   126
        }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   127
        break;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   128
      case 'thumbs':
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   129
        if ( $dh = opendir(ENANO_ROOT . '/cache') )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   130
        {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   131
          while ( $file = @readdir($dh) )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   132
          {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   133
            $fullpath = ENANO_ROOT . "/cache/$file";
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   134
            // we don't want to mess with directories
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   135
            if ( !is_file($fullpath) )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   136
              continue;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   137
            
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   138
            if ( preg_match('/^(?:[a-z0-9\._,-]+)-(?:[0-9]{10})-[0-9]+x[0-9]+\.([a-z0-9_-]+)$/i', $file) )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   139
              unlink($fullpath);
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   140
          }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   141
          $success = true;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   142
        }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   143
        break;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   144
      case 'all':
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   145
        $success = purge_all_caches();
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   146
        if ( $do_refresh )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   147
        {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   148
          //
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   149
          // refresh all static (non-incremental) caches
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   150
          //
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   151
          
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   152
          // pages
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   153
          $success = $paths->update_metadata_cache();
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   154
          if ( !$success )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   155
            break;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   156
          
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   157
          // user ranks
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   158
          $success = generate_cache_userranks();
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   159
          if ( !$success )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   160
            break;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   161
          
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   162
          // plugins
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   163
          $success = $plugins->generate_plugins_cache();
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   164
          if ( !$success )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   165
            break;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   166
          
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   167
          // languages
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   168
          $q = $db->sql_query('SELECT lang_id FROM ' . table_prefix . 'language;');
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   169
          if ( !$q )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   170
            $db->_die();
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   171
          while ( $row = $db->fetchrow($q) )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   172
          {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   173
            $lang_local = ( $row['lang_id'] == $lang->lang_id ) ? $lang : new Language($row['lang_id']);
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   174
            $success = $lang_local->regen_caches();
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   175
            if ( !$success )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   176
              break 2;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   177
          }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   178
        }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   179
        break;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   180
      default:
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   181
        $code = $plugins->setHook('acp_cache_manager_action');
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   182
        foreach ( $code as $cmd )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   183
        {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   184
          eval($cmd);
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   185
        }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   186
        break;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   187
    }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   188
    if ( $success )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   189
    {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   190
      echo '<div class="info-box">' . $lang->get('acpcm_msg_action_success') . '</div>';
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   191
    }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   192
    else
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   193
    {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   194
      echo '<div class="error-box">' . $lang->get('acpcm_err_action_failed') . '</div>';
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   195
    }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   196
  }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   197
  else if ( isset($_POST['save']) )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   198
  {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   199
    $config_value = ( isset($_POST['cache_thumbs']) ) ? '1' : '0';
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   200
    setConfig('cache_thumbs', $config_value);
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   201
    echo '<div class="info-box">' . $lang->get('acpcm_msg_action_success') . '</div>';
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   202
  }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   203
  
605
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   204
  echo '<h3><img alt=" " src="' . scriptPath . '/images/icons/applets/cachemanager.png" />&nbsp;&nbsp;&nbsp;' . $lang->get('acpcm_heading_main') . '</h3>';
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   205
  echo '<p>' . $lang->get('acpcm_intro') . '</p>';
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   206
  
613
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   207
  echo '<div class="warning-box">' . $lang->get('acpcm_msg_refresh_warning') . '</div>';
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   208
  
605
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   209
  acp_start_form();
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   210
  ?>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   211
  <div class="tblholder">
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   212
    <table border="0" cellspacing="1" cellpadding="4">
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   213
      <!-- HEADER -->
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   214
      <tr>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   215
        <th colspan="2">
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   216
          <?php echo $lang->get('acpcm_table_header'); ?>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   217
        </th>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   218
      </tr>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   219
      
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   220
      <!-- ENABLE CACHE -->
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   221
      <tr>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   222
        <td class="row1" colspan="2">
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   223
          <label>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   224
            <input type="checkbox" name="cache_thumbs"<?php if ( getConfig('cache_thumbs') == '1' ) echo ' checked="checked"'; ?> />
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   225
            <?php echo $lang->get('acpcm_lbl_enable_cache'); ?>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   226
          </label>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   227
          <br />
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   228
          <small>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   229
            <?php echo $lang->get('acpcm_hint_enable_cache'); ?>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   230
          </small>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   231
        </td>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   232
      </tr>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   233
      
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   234
      <!-- CLEAR ALL -->
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   235
      <tr>
613
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   236
      <td class="row2" style="width: 120px; text-align: center;">
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   237
          <button name="clear" value="all"><?php echo $lang->get('acpcm_btn_clear_all'); ?></button>
605
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   238
        </td>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   239
        <td class="row2">
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   240
          <?php echo $lang->get('acpcm_hint_clear_all'); ?>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   241
        </td>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   242
      </tr>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   243
      
613
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   244
      <?php
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   245
      // if caching is disabled, might as well break off here
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   246
      if ( getConfig('cache_thumbs') == '1' ):
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   247
      ?>
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   248
      
605
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   249
      <!-- REFRESH ALL -->
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   250
      <tr>
613
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   251
        <td class="row1" style="text-align: center;">
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   252
          <button name="refresh" value="all"><?php echo $lang->get('acpcm_btn_refresh_all'); ?></button>
605
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   253
        </td>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   254
        <td class="row1">
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   255
          <?php echo $lang->get('acpcm_hint_refresh_all'); ?>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   256
        </td>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   257
      </tr>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   258
      
613
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   259
      <!-- INDIVIDUAL CACHES -->
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   260
      <tr>
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   261
        <th class="subhead" colspan="2">
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   262
          <?php echo $lang->get('acpcm_th_individual_caches'); ?>
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   263
        </th>
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   264
      </tr>
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   265
      
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   266
      <?php
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   267
      $class = 'row2';
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   268
      $cache_list = array('page', 'ranks', 'sidebar', 'plugins', 'template', 'aes', 'lang', 'js', 'thumbs');
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   269
      $code = $plugins->setHook('acp_cache_manager_list_caches');
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   270
      foreach ( $code as $cmd )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   271
      {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   272
        eval($cmd);
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   273
      }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   274
      foreach ( $cache_list as $target )
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   275
      {
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   276
        $class = ( $class == 'row1' ) ? 'row2' : 'row1';
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   277
        ?><tr>
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   278
        <td class="<?php echo $class; ?>" style="text-align: center;">
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   279
          <button name="refresh" value="<?php echo $target; ?>"<?php if ( in_array($target, array('template', 'sidebar', 'aes', 'js', 'thumbs')) ) echo ' disabled="disabled"'; ?>>
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   280
            <?php echo $lang->get('acpcm_btn_refresh'); ?>
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   281
          </button>
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   282
          <button name="clear" value="<?php echo $target; ?>">
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   283
            <?php echo $lang->get('acpcm_btn_clear'); ?>
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   284
          </button>
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   285
        </td>
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   286
        <td class="<?php echo $class; ?>">
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   287
          <b><?php echo $lang->get("acpcm_cache_{$target}_desc_title"); ?></b> &ndash;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   288
          <?php echo $lang->get("acpcm_cache_{$target}_desc_body"); ?>
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   289
        </td>
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   290
        </tr>
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   291
      <?php
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   292
      }
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   293
      
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   294
      // getConfig('cache_thumbs') == '1'
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   295
      endif;
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   296
      ?>
c08670a77871 Completed work (we hope) on CacheManager admin page
Dan
parents: 605
diff changeset
   297
      
605
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   298
      <!-- SAVE CHANGES -->
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   299
      <tr>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   300
        <th colspan="2" class="subhead">
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   301
          <input type="submit" name="save" value="<?php echo $lang->get('etc_save_changes'); ?>" style="font-weight: bold;" />
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   302
          <input type="submit" name="cancel" value="<?php echo $lang->get('etc_cancel'); ?>" />
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   303
        </th>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   304
      </tr>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   305
    </table>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   306
  </div>
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   307
  <?php
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   308
  echo '</form>';
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   309
}
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   310
d2d4e40ecd29 First draft of new CacheManager admin page. Backend is yet to be implemented.
Dan
parents:
diff changeset
   311
?>