Commit dc5e46d0 by Scott

Hide Caching link if directory not defined

parent 61472952
...@@ -34,14 +34,15 @@ class Q2A_Storage_CacheManager ...@@ -34,14 +34,15 @@ class Q2A_Storage_CacheManager
*/ */
private function __construct() private function __construct()
{ {
$optEnabled = qa_opt('caching_enabled') == 1; if (qa_opt('caching_enabled') != 1)
return;
$config = array( $config = array(
'dir' => defined('QA_CACHE_DIRECTORY') ? QA_CACHE_DIRECTORY : null, 'dir' => defined('QA_CACHE_DIRECTORY') ? QA_CACHE_DIRECTORY : null,
); );
$this->cacheDriver = new Q2A_Storage_FileCache($config); $this->cacheDriver = new Q2A_Storage_FileCache($config);
$this->enabled = $optEnabled && $this->cacheDriver->isEnabled(); $this->enabled = $this->cacheDriver->isEnabled();
} }
/** /**
......
...@@ -35,16 +35,17 @@ class Q2A_Storage_FileCache ...@@ -35,16 +35,17 @@ class Q2A_Storage_FileCache
*/ */
public function __construct($config) public function __construct($config)
{ {
if (!isset($config['dir'])) if (isset($config['dir'])) {
return; $this->cacheDir = realpath($config['dir']);
$this->cacheDir = realpath($config['dir']); if (!is_writable($this->cacheDir)) {
$this->error = qa_lang_html_sub('admin/caching_dir_error', $this->cacheDir);
if (!is_writable($this->cacheDir)) { } elseif (strpos($this->cacheDir, realpath($_SERVER['DOCUMENT_ROOT'])) === 0 || strpos($this->cacheDir, realpath(QA_BASE_DIR)) === 0) {
$this->error = qa_lang_html_sub('admin/caching_dir_error', $this->cacheDir); // check the folder is outside the public root - checks against server root and Q2A root, in order to handle symbolic links
} elseif (strpos($this->cacheDir, realpath($_SERVER['DOCUMENT_ROOT'])) === 0 || strpos($this->cacheDir, realpath(QA_BASE_DIR)) === 0) { $this->error = qa_lang_html_sub('admin/caching_dir_public', $this->cacheDir);
// check the folder is outside the public root - checks against server root and Q2A root, in order to handle symbolic links }
$this->error = qa_lang_html_sub('admin/caching_dir_public', $this->cacheDir); } else {
$this->error = qa_lang_html('admin/caching_dir_missing');
} }
$this->enabled = empty($this->error); $this->enabled = empty($this->error);
......
...@@ -341,10 +341,12 @@ ...@@ -341,10 +341,12 @@
'url' => qa_path_html('admin/spam'), 'url' => qa_path_html('admin/spam'),
); );
$navigation['admin/caching']=array( if (defined('QA_CACHE_DIRECTORY')) {
'label' => qa_lang_html('admin/caching_title'), $navigation['admin/caching']=array(
'url' => qa_path_html('admin/caching'), 'label' => qa_lang_html('admin/caching_title'),
); 'url' => qa_path_html('admin/caching'),
);
}
$navigation['admin/stats']=array( $navigation['admin/stats']=array(
'label' => qa_lang_html('admin/stats_title'), 'label' => qa_lang_html('admin/stats_title'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment