Файл: adultscript-2.0.3-pro/files/modules/kb/kb.php
Строк: 25
<?php
defined('_VALID') or die('Restricted Access!');
class VModule_kb
{
protected $db;
protected $cache;
public function __construct()
{
$this->db = VF::factory('database');
$this->cache = VF::factory('cache');
}
public function render()
{
VLanguage::load('frontend.kb');
$slug = VUri::request(1);
if ($slug) {
$url = 'kb/'.$slug.'/';
$this->db->query("
SELECT k.kb_id, k.kb_title, k.kb_content
FROM #__kb_categories AS kc
INNER JOIN #__kb AS k ON (k.cat_id = kc.cat_id)
WHERE slug = '".$this->db->escape($slug)."'
ORDER BY k.kb_id DESC
");
} else {
$url = 'kb/';
$this->db->query("
SELECT k.kb_id, k.kb_title, k.kb_content
FROM #__kb AS k
ORDER BY k.total_views DESC
LIMIT 10
");
}
$articles = $this->db->fetch_rows();
$tpl = VF::factory('template');
$tpl->menu = 'home';
$tpl->meta_title = __('article-meta-title', array(VF::cfg_item('site_name')));
$tpl->canonical = BASE_URL.'/'.$url;
$tpl->canonicalm = MOBILE_URL.'/'.$url;
$tpl->slug = $slug;
$tpl->articles = $articles;
$tpl->categories = $this->get_kb_categories();
$tpl->load(array('header', 'kb', 'footer'));
$tpl->display();
}
protected function get_kb_categories()
{
if (!$categories = $this->cache->get('kb_categories', 86400)) {
$this->db->query('SELECT cat_id, name, slug
FROM #__kb_categories
ORDER BY pos ASC');
if ($this->db->affected_rows()) {
$categories = $this->db->fetch_rows();
$this->cache->store('kb_categories', $categories, 86400);
} else {
$categories = array();
}
}
return $categories;
}
}