Файл: adultscript-2.0.3-pro/files/templates/defboot/extend/ajax/video_related.plugin.php
Строк: 86
<?php
function ajax_plugin_video_related()
{
$data = array('status' => 0, 'code' => '', 'msg' => '', 'debug' => '', 'end' => 0);
if (isset($_POST['video_id']) && isset($_POST['page'])) {
$video_id = (int) $_POST['video_id'];
$page = (int) $_POST['page'];
$db = VF::factory('database');
$db->query("SELECT v.title, GROUP_CONCAT(DISTINCT vt.name) AS tags
FROM #__video AS v
INNER JOIN #__video_tags AS vt ON (vt.video_id = v.video_id)
WHERE v.video_id = ".$video_id."
AND v.status = 1
GROUP BY v.video_id
LIMIT 1");
if ($db->affected_rows()) {
VLanguage::load('frontend.video');
$video = $db->fetch_assoc();
$limit = VCfg::get('video.related_per_page');
$start = ($page === 1) ? 0 : ($page*$limit);
$query = (VCfg::get('video.related_method') == 'simple')
? get_related_simple($video_id, $video['title'], $start, $limit)
: get_related_complex($video_id, $video['tags'], $start, $limit);
$related_total = $query['total'];
if ($related_total > VCfg::get('video.related_total')) {
$related_total = VCfg::get('video.related_total');
}
$related = $db->get_rows($query['sql']);
$pagination = VPagination::get($page, $related_total, $limit);
$hd_trans = __('hd').' ';
$code = array();
foreach ($related as $video) {
$percent = ($video['likes'] > 0 && $video['rated_by']) ? round($video['likes']*100/$video['rated_by']) : 100;
$class = ($percent > 50) ? 'up' : 'down';
$views = ($video['total_views'] == '1') ? __('view') : __('views');
$hd = ($video['hd']) ? $hd_trans : '';
$code[] = '<li id="video-'.$video['video_id'].'">';
$code[] = '<div class="video">';
$code[] = '<a href="'.REL_URL.'/'.$video['video_id'].'/'.$video['slug'].'/" title="'.e($video['title']).'" class="thumbnail">';
$code[] = '<img src="'.THUMB_URL.'/'.path($video['video_id']).'/'.$video['thumb'].'.jpg" alt="'.e($video['title']).'" id="preview-'.$video['video_id'].'-'.$video['thumb'].'-'.$video['thumbs'].'-related" />';
$code[] = '<span class="video-rating"><i class="fa fa-lg fa-thumbs-'.$class.'"></i>'.$percent.'%</span>';
$code[] = '<span class="video-title">'.e($video['title']).'</span>';
$code[] = '<span class="video-overlay badge transparent">'.$hd.VDate::duration($video['duration']).'</span>';
$code[] = '<div class="video-details hidden-xs hidden-sm">';
$code[] = '<span class="pull-left">'.VDate::nice($video['add_time']).'</span>';
$code[] = '<span class="pull-right text-right">'.$video['total_views'].' '.$views.'</span>';
$code[] = '</div>';
$code[] = '</a>';
$code[] = '</div>';
$code[] = '</li>';
}
$data['status'] = 1;
$data['code'] = implode('', $code);
$data['page'] = $page+1;
if ($related_total <= $limit*$page) {
$data['end'] = 1;
}
} else {
$data['msg'] = 'Invalid video!';
}
} else {
$data['msg'] = 'Invalid request!';
}
return json_encode($data);
}
function get_related_simple($video_id, $title, $start, $limit)
{
$db = VF::factory('database');
$title = $db->escape($title);
$sql_count = "SELECT COUNT(*) AS total_related
FROM #__video AS v
WHERE MATCH (v.title) AGAINST ('".$title."')
AND v.status = 1";
return array(
'total' => $db->get_field($sql_count, 'total_related'),
'sql' => "SELECT v.video_id, v.title, v.slug, v.likes, v.rating, v.rated_by, v.duration, v.thumb,
v.thumbs, v.total_views, v.add_time, v.ext, v.premium, u.username, v.hd,
MATCH (v.title) AGAINST ('".$title."') AS relevance
FROM #__video AS v
LEFT JOIN #__user AS u ON (u.user_id = v.user_id)
WHERE MATCH (v.title) AGAINST ('".$title."')
AND v.status = 1
AND v.video_id != ".$video_id."
ORDER BY relevance DESC
LIMIT ".$start.",".$limit
);
}
function get_related_complex($video_id, $tags, $start, $limit)
{
VF::load('sphinxapi.sphinxapi');
$sphinx = new SphinxClient();
$sphinx->SetServer(VF::cfg_item('sphinx_host'), VF::cfg_item('sphinx_port'));
$sphinx->SetConnectTimeout(1);
$sphinx->SetFieldWeights(array('tags' => 100, 'title' => 70, 'description' => 30));
$sphinx->SetMatchMode(SPH_MATCH_ANY);
$sphinx->SetFilter('video', array($video_id), true);
$sphinx->SetLimits($start, $limit, 1000);
$tags = str_replace(',', ' ', VText::truncate_words($title, 40, ''));
$results = $sphinx->Query($tags, VF::cfg_item('sphinx_index'));
if (isset($results['total']) && isset($results['matches'])) {
$ids = implode(',', array_keys($results['matches']));
return array(
'total' => $results['total'],
'sql' => 'SELECT v.video_id, v.title, v.slug, v.likes, v.rating, v.rated_by, v.duration, v.thumb,
v.thumbs, v.total_views, v.add_time, v.ext, v.premium, u.username, v.hd
FROM #__video AS v
LEFT JOIN #__user AS u on (u.user_id = v.user_id)
WHERE v.video_id IN ('.$ids.')
ORDER BY FIELD (v.video_id, '.$ids.')'
);
}
return array('total' => 0, 'sql' => FALSE);
}