XOOPS  2.6.0
system.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
20 class System
21 {
22 
26  public $module = null;
27 
31  private $xoops = null;
32 
36  private function __construct()
37  {
38  $this->xoops = Xoops::getInstance();
39  }
40 
46  public static function getInstance()
47  {
48  static $instance;
49  if (!isset($instance)) {
50  $class = __CLASS__;
51  $instance = new $class();
52  }
53  return $instance;
54  }
55 
59  public function checkRight()
60  {
61  if ($this->xoops->isUser()) {
62  $this->xoops->module = $this->xoops->getModuleByDirname('system');
63  if (!$this->xoops->user->isAdmin($this->xoops->module->mid())) {
64  return false;
65  }
66  } else {
67  return false;
68  }
69  return true;
70  }
71 
79  public function cleanVars(&$global, $key, $default = '', $type = 'int')
80  {
81  switch ($type) {
82  case 'array':
83  $ret = (isset($global[$key]) && is_array($global[$key])) ? $global[$key] : $default;
84  break;
85  case 'date':
86  $ret = (isset($global[$key])) ? strtotime($global[$key]) : $default;
87  break;
88  case 'string':
89  $ret = (isset($global[$key])) ? filter_var($global[$key], FILTER_SANITIZE_MAGIC_QUOTES) : $default;
90  break;
91  case 'int':
92  default:
93  $ret = (isset($global[$key])) ? filter_var($global[$key], FILTER_SANITIZE_NUMBER_INT) : $default;
94  break;
95  }
96  if ($ret === false) {
97  return $default;
98  }
99  return $ret;
100  }
101 
114  public function loadLanguage($name, $domain = '', $language = null)
115  {
120  if (empty($name)) {
121  return false;
122  }
123  $language = empty($language) ? $xoops->getConfig('language') : $language;
124  $path = 'modules/' . $domain . '/language/';
125  if (XoopsLoad::fileExists($file = $xoops->path($path . $language . '/admin/' . $name . '.php'))) {
126  $ret = include_once $file;
127  } else {
128  $ret = include_once $xoops->path($path . 'english/admin/' . $name . '.php');
129  }
130  return $ret;
131  }
132 
138  public function adminVersion($version, $value = '')
139  {
140  static $tblVersion = array();
141  if (is_array($tblVersion) && array_key_exists($version . '.' . $value, $tblVersion)) {
142  return $tblVersion[$version . '.' . $value];
143  }
145  $path = $xoops->path('modules/system/admin/' . $version . '/xoops_version.php');
147  $modversion = array();
148  include $path;
149  $retvalue = $modversion[$value];
150  $tblVersion[$version . '.' . $value] = $retvalue;
151  return $retvalue;
152  }
153  return '';
154  }
155 
174  public function cleanCache($cache)
175  {
176  $cachePath = \XoopsBaseConfig::get('var-path') . '/caches/';
177  $total_smarty_cache = 0;
178  $total_smarty_compile = 0;
179  $total_xoops_cache = 0;
180  if (!empty($cache)) {
181  for ($i = 0; $i < count($cache); ++$i) {
182  switch ($cache[$i]) {
183  case 1:
184  $files = glob($cachePath . 'smarty_cache/*.*');
185  $total_smarty_cache = 0;
186  foreach ($files as $filename) {
187  if (basename(strtolower($filename)) != 'index.html') {
188  unlink($filename);
189  ++$total_smarty_cache;
190  }
191  }
192  break;
193 
194  case 2:
195  $files = glob($cachePath . 'smarty_compile/*.*');
196  $total_smarty_compile = 0;
197  foreach ($files as $filename) {
198  if (basename(strtolower($filename)) != 'index.html') {
199  unlink($filename);
200  ++$total_smarty_compile;
201  }
202  }
203  break;
204 
205  case 3:
206  // ask the cache to clear itself
207  $status = Xoops::getInstance()->cache()->delete('system');
208  // this section captures legacy cache use only
209  $files = glob($cachePath . 'xoops_cache/*.*');
210  $total_xoops_cache = 0;
211  foreach ($files as $filename) {
212  if (basename(strtolower($filename)) != 'index.html') {
213  unlink($filename);
214  ++$total_xoops_cache;
215  }
216  }
217  $total_xoops_cache = $status || ($total_xoops_cache>0);
218  break;
219  }
220  }
221  $ret['smarty_cache'] = $total_smarty_cache;
222  $ret['smarty_compile'] = $total_smarty_compile;
223  $ret['xoops_cache'] = $total_xoops_cache;
224  return $ret;
225  } else {
226  return false;
227  }
228  }
229 }
$xoops
Definition: system.php:31
checkRight()
Definition: system.php:59
$path
Definition: execute.php:31
$i
Definition: dialog.php:68
static getInstance()
Definition: system.php:46
static getInstance()
Definition: Xoops.php:160
cleanVars(&$global, $key, $default= '', $type= 'int')
Definition: system.php:79
if(!isset($xoops->paths[$path_type])) if($path_type== 'var') $file
Definition: browse.php:55
$files
Definition: index.php:35
adminVersion($version, $value= '')
Definition: system.php:138
$status
static fileExists($file)
Definition: xoopsload.php:506
static get($name)
__construct()
Definition: system.php:36
$type
Definition: misc.php:33
$modversion
$module
Definition: system.php:26
$language
loadLanguage($name, $domain= '', $language=null)
Definition: system.php:114
cleanCache($cache)
Definition: system.php:174