Cheetah
cache.php
Go to the documentation of this file.
1 <?php
2 
8 require_once( '../inc/header.inc.php' );
9 require_once( CH_DIRECTORY_PATH_INC . 'design.inc.php' );
10 require_once( CH_DIRECTORY_PATH_INC . 'admin_design.inc.php' );
11 require_once( CH_DIRECTORY_PATH_INC . 'admin.inc.php' );
12 
13 ch_import('ChWsbPaginate');
14 ch_import('ChWsbAdminIpBlockList');
15 ch_import('ChWsbCacheUtilities');
16 
17 $logged['admin'] = member_auth(1, true, true);
18 
19 $aCacheTypes = array (
20  array('action' => 'all', 'title' => _t('_adm_txt_dashboard_cache_all')),
21  array('action' => 'db', 'title' => _t('_adm_txt_dashboard_cache_db')),
22  array('action' => 'pb', 'title' => _t('_adm_txt_dashboard_cache_pb')),
23  array('action' => 'template', 'title' => _t('_adm_txt_dashboard_cache_template')),
24  array('action' => 'css', 'title' => _t('_adm_txt_dashboard_cache_css')),
25  array('action' => 'js', 'title' => _t('_adm_txt_dashboard_cache_js')),
26  array('action' => 'users', 'title' => _t('_adm_txt_dashboard_cache_users')),
27  array('action' => 'member_menu', 'title' => _t('_adm_txt_dashboard_cache_member_menu')),
28 );
29 
31 
32 if (!empty($_POST['clear_cache'])) {
33  $aResult = array();
34  switch ($_POST['clear_cache']) {
35  case 'all':
36  foreach ($aCacheTypes as $r) {
37  $aResult = $oCacheUtilities->clear($r['action']);
38  if ($aResult['code'] != 0)
39  break 2;
40  }
41  break;
42  case 'member_menu':
43  case 'pb':
44  case 'users':
45  case 'db':
46  case 'template':
47  case 'css':
48  case 'js':
49  $aResult = $oCacheUtilities->clear($_POST['clear_cache']);
50  break;
51  default:
52  $aResult = array('code' => 1, 'message' => _t('_Error Occured'));
53  }
54 
55  // add cache size data for chart in case of successful cache cleaning
56  if($aResult['code'] == 0) {
57  $aResult['chart_data'] = array ();
58  foreach ($aCacheTypes as $r) {
59  if('all' == $r['action'])
60  continue;
61 
62  $aResult['chart_data'][] = array(
63  'value' => round($oCacheUtilities->size($r['action']) / 1024, 2),
64  'color' => '#' . dechex(rand(0x000000, 0xFFFFFF)),
65  'highlight' => '',
66  'label' => ch_js_string($r['title'], CH_ESCAPE_STR_APOS),
67  );
68  }
69  }
70 
71  echo json_encode($aResult);
72  exit;
73 }
74 
76 $_page = array(
77  'name_index' => $iNameIndex,
78  'css_name' => array(),
79  'js_name' => array(),
80  'header' => _t('_adm_txt_cache'),
81  'header_text' => _t('_adm_txt_cache'),
82 );
83 
84 $aPages = array (
85  'clear' => array (
86  'title' => _t('_adm_txt_clear_cache'),
87  'url' => CH_WSB_URL_ADMIN . 'cache.php?mode=clear',
88  'func' => 'PageCodeClear',
89  'func_params' => array(),
90  ),
91  'engines' => array (
92  'title' => _t('_adm_admtools_cache_engines'),
93  'url' => CH_WSB_URL_ADMIN . 'cache.php?mode=engines',
94  'func' => 'PageCodeEngines',
95  'func_params' => array(),
96  ),
97  'settings' => array (
98  'title' => _t('_Settings'),
99  'url' => CH_WSB_URL_ADMIN . 'cache.php?mode=settings',
100  'func' => 'PageCodeSettings',
101  'func_params' => array(),
102  ),
103 );
104 
105 if (!isset($_GET['mode']) || !isset($aPages[$_GET['mode']]))
106  $sMode = 'clear';
107 else
108  $sMode = $_GET['mode'];
109 
110 $aTopItems = array();
111 foreach ($aPages as $k => $r)
112  $aTopItems['dbmenu_' . $k] = array(
113  'href' => $r['url'],
114  'title' => $r['title'],
115  'active' => $k == $sMode ? 1 : 0
116  );
117 
118 $_page['css_name'] = 'cache.css';
119 $_page_cont[$iNameIndex]['page_main_code'] = call_user_func_array($aPages[$sMode]['func'], $aPages[$sMode]['func_params']);
120 
121 PageCodeAdmin();
122 
123 function PageCodeClear ()
124 {
126 
127  $aChartData = array();
128  foreach ($aCacheTypes as $r) {
129  if ('all' == $r['action'])
130  continue;
131 
132  $aChartData[] = array(
133  'value' => round($oCacheUtilities->size($r['action']) / 1024, 2),
134  'color' => '#' . dechex(rand(0x000000, 0xFFFFFF)),
135  'highlight' => '',
136  'label' => ch_js_string($r['title'], CH_ESCAPE_STR_APOS),
137  );
138  }
139  $sChartData = json_encode($aChartData);
140 
141  $oAdmTemplate->addJsTranslation(array(
142  '_sys_kilobyte'
143  ));
144  $oAdmTemplate->addJsSystem(array(
145  'chart.min.js',
146  ));
147 
148  $s = $oAdmTemplate->parseHtmlByName('cache.html', array(
149  'ch_repeat:clear_action' => $aCacheTypes,
150  'chart_data' => $sChartData,
151  ));
152 
153  return DesignBoxAdmin(_t('_adm_txt_cache'), $s, $GLOBALS['aTopItems'], '', 11);
154 }
155 
156 function PageCodeEngines ()
157 {
158  ch_import('ChWsbAdminTools');
159  $oAdmTools = new ChWsbAdminTools();
160  $s = $oAdmTools->GenCommonCode();
161  $s .= $oAdmTools->GenCacheEnginesTable();
162 
163  return DesignBoxAdmin(_t('_adm_txt_cache'), $s, $GLOBALS['aTopItems'], '', 11);
164 }
165 
166 function PageCodeSettings ()
167 {
168  ch_import('ChWsbAdminSettings');
169  $oSettings = new ChWsbAdminSettings(24);
170 
171  $sResults = false;
172  if (isset($_POST['save']) && isset($_POST['cat']))
173  $sResult = $oSettings->saveChanges($_POST);
174 
175  $s = $oSettings->getForm();
176  if ($sResult)
177  $s = $sResult . $s;
178 
179  return DesignBoxAdmin(_t('_adm_txt_cache'), $s, $GLOBALS['aTopItems'], '', 11);
180 }
$oSettings
$oSettings
Definition: advanced_settings.php:20
$oAdmTemplate
$oAdmTemplate
Definition: admin_design.inc.php:18
PageCodeSettings
PageCodeSettings()
Definition: cache.php:166
ch_js_string
ch_js_string($mixedInput, $iQuoteType=CH_ESCAPE_STR_AUTO)
Definition: utils.inc.php:1294
$aCacheTypes
$aCacheTypes
Definition: cache.php:19
$sResult
$sResult
Definition: advanced_settings.php:26
$sMode
else $sMode
Definition: cache.php:108
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
$aResult
$aResult
Definition: index.php:19
php
PageCodeClear
PageCodeClear()
Definition: cache.php:123
ChWsbCacheUtilities
Definition: ChWsbCacheUtilities.php:9
$oAdmTools
$oAdmTools
Definition: admin_tools.php:16
$_page_cont
$_page_cont[$iNameIndex]['page_main_code']
Definition: cache.php:119
$aTopItems
$aTopItems
Definition: cache.php:110
$oCacheUtilities
$oCacheUtilities
Definition: cache.php:30
DesignBoxAdmin
DesignBoxAdmin($sTitle, $sContent, $mixedTopItems='', $sBottomItems='', $iIndex=1)
Definition: admin_design.inc.php:50
exit
exit
Definition: cart.php:21
$_GET
$_GET['debug']
Definition: index.php:67
ChWsbAdminTools
Definition: ChWsbAdminTools.php:11
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
PageCodeAdmin
PageCodeAdmin($oTemplate=null)
Definition: admin_design.inc.php:45
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
member_auth
member_auth($member=0, $error_handle=true, $bAjx=false)
Definition: admin.inc.php:262
$_page
$_page
Definition: cache.php:76
ChWsbAdminSettings
Definition: ChWsbAdminSettings.php:35
$logged
$logged['admin']
Definition: cache.php:17
$s
$s
Definition: embed.php:13
CH_ESCAPE_STR_APOS
const CH_ESCAPE_STR_APOS
escape apostrophes only, for js strings enclosed in apostrophes, for use in
Definition: utils.inc.php:33
PageCodeEngines
PageCodeEngines()
Definition: cache.php:156
$aPages
$aPages
Definition: cache.php:84
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
$iNameIndex
if(!empty($_POST['clear_cache'])) $iNameIndex
Definition: cache.php:75
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10