Файл: adultscript-2.0.3-pro/files/modules/pornstar/components/comments.php
Строк: 122
<?php
defined('_VALID') or die('Restricted Access!');
class VComponent_pornstar_comments extends VModule_pornstar
{
public function __construct()
{
parent::__construct();
}
public function render()
{
$slug = VUri::request(1);
if (!$pornstar = $this->cache->get('pornstar_'.$slug, 3600)) {
$sql = "SELECT m.model_id, m.name, m.slug, m.description, m.ext, m.likes, m.rating, m.rated_by,
m.total_views, m.total_videos, m.total_albums, m.total_comments,
m.total_favorites, m.gender, mb.aliases, mb.birth_date, mb.birth_location,
mb.birth_name, mb.eye_color, mb.hair_color, mb.weight, mb.height,
mb.measurements, mb.ethnicity, mb.nationality, mb.natural_bust,
mb.performs, mb.links, mb.url, m.adv
FROM #__model AS m
LEFT JOIN #__model_bio AS mb ON (m.model_id = mb.model_id)
WHERE m.slug = '".$this->db->escape($slug)."'
AND m.status = '1'
LIMIT 1";
$this->db->query($sql);
if ($this->db->affected_rows()) {
$pornstar = $this->db->fetch_assoc();
$this->cache->store('pornstar_'.$slug, $pornstar, 3600);
} else {
VModule::load('404', TRUE);
}
}
if (!VUri::match('pornstar/'.$slug.'/comments/')) {
VF::redirect(BASE_URL.'/pornstar/'.$slug.'/comments/', 301);
}
VLanguage::load('frontend.pornstar');
$model_id = (int) $pornstar['model_id'];
$user_id = (VAuth::loggedin()) ? (int) $_SESSION['user_id'] : 0;
$subscribed = ($user_id && $this->is_subscribed($model_id, $user_id)) ? true : false;
if (!VBrowser::get('is_robot')) {
$this->db->query("UPDATE #__model
SET total_views = total_views+1
WHERE model_id = ".$model_id."
LIMIT 1");
if (VCfg::get('pornstar.track_views')) {
$this->db->query("INSERT INTO #__model_views
SET model_id = ".$model_id.",
user_id = ".$user_id.",
ip = ".VServer::ip(true).",
view_time = ".time());
}
}
$page = (isset($_GET['page'])) ? (int) trim($_GET['page']) : 1;
$sql_count = "SELECT COUNT(*) AS total_comments
FROM #__model_comments
WHERE model_id = ".$model_id;
$total_comments = $this->db->get_field($sql_count, 'total_comments');
$pagination = VPagination::get($page, $total_comments, VCfg::get('pornstar.comments_per_page'));
$sql = "SELECT c.comment_id, c.parent_id, c.user_id,
c.comment, c.add_time, c.nickname,
c.likes, c.rated_by,
u.username, u.gender, u.avatar
FROM #__model_comments AS c
LEFT JOIN #__user AS u ON (u.user_id = c.user_id)
WHERE c.model_id = ".$model_id."
AND c.status = '1'
ORDER BY c.comment_id DESC
LIMIT ".$pagination['limit'];
if (!$comments = $this->cache->get($sql, 3600)) {
$comments = $this->db->get_rows($sql);
if ($comments) {
$this->cache->store($sql, $comments, 3600);
}
}
$this->tpl->menu = 'pornstar';
$this->tpl->title = $pornstar['name'].' '.__('comments');
$this->tpl->meta_title = __('pornstar-meta-title', array($pornstar['name'].' - '.__('comments'), VF::cfg_item('site_name')));
$this->tpl->meta_desc = $this->tpl->meta_title.'. '.VF::cfg_item('meta_desc');
$this->tpl->meta_keys = strtolower($pornstar['name']).', '.VF::cfg_item('meta_keys');
$this->tpl->css = array(TPL_REL.'/css/style_model.css');
$this->tpl->canonical = BASE_URL.'/pornstar/'.$slug.'/comments/';
$this->tpl->canonicalm = MOBILE_URL.'/pornstar/'.$slug.'/';
$this->tpl->user_id = $user_id;
$this->tpl->pornstar = $pornstar;
$this->tpl->subscribed = $subscribed;
$this->tpl->comments = $comments;
$this->tpl->pagination = $pagination;
$this->tpl->albums = $this->count_model_albums($model_id);
$this->tpl->videos = $this->count_model_videos($model_id);
$this->tpl->load(array('header', 'pornstar_comments', 'footer'));
$this->tpl->display();
}
private function is_subscribed($model_id, $user_id)
{
$this->db->query("
SELECT model_id
FROM #__model_subscribers
WHERE model_id = ".$model_id."
AND user_id = ".$user_id."
LIMIT 1
");
return $this->db->affected_rows();
}
private function count_model_albums($model_id)
{
$sql_count = "SELECT COUNT(*) AS total_albums
FROM #__model_albums
WHERE model_id = ".$model_id;
return $this->db->get_field($sql_count, 'total_albums');
}
private function count_model_videos($model_id)
{
$sql_count = "SELECT COUNT(*) AS total_videos
FROM #__model_videos
WHERE model_id = ".$model_id;
return $this->db->get_field($sql_count, 'total_videos');
}
}