mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-06 03:50:04 +02:00
This commit is contained in:
parent
b8beee3a56
commit
04d0e5e5ba
2 changed files with 39 additions and 14 deletions
|
@ -5,13 +5,15 @@ if (!isset($global['systemRootPath'])) {
|
|||
require_once '../videos/configuration.php';
|
||||
}
|
||||
|
||||
_error_log('Add view '. json_encode($_REQUEST));
|
||||
|
||||
if(!empty($_GET['SESSID'])){
|
||||
@session_write_close();
|
||||
session_id($_GET['PHPSESSID']);
|
||||
_session_start();
|
||||
}
|
||||
|
||||
if (empty($_POST['id'])) {
|
||||
if (empty($_REQUEST['id'])) {
|
||||
die('{"error":"' . __("Permission denied") . '"}');
|
||||
}
|
||||
if (empty($_COOKIE[$global['session_name']])) {
|
||||
|
@ -21,7 +23,7 @@ if(empty($_COOKIE) && isIframe() && isIframeInDifferentDomain()){
|
|||
die('{"error":"isIframeInDifferentDomain"}');
|
||||
}
|
||||
require_once $global['systemRootPath'] . 'objects/video.php';
|
||||
$obj = new Video("", "", $_POST['id']);
|
||||
$obj = new Video("", "", $_REQUEST['id']);
|
||||
if (empty($obj)) {
|
||||
die("Object not found");
|
||||
}
|
||||
|
@ -33,25 +35,25 @@ if (empty($_SESSION['addViewCount'])) {
|
|||
$seconds = parseDurationToSeconds($obj->getDuration());
|
||||
|
||||
if (!empty($seconds)) {
|
||||
$percent = (intval($_POST['currentTime']) / $seconds) * 100;
|
||||
$percent = (intval($_REQUEST['currentTime']) / $seconds) * 100;
|
||||
$percentOptions = array(25,50,75,100);
|
||||
foreach ($percentOptions as $value) {
|
||||
if ($percent >= $value) {
|
||||
if (empty($_SESSION['addViewCount'][$_POST['id']][$value]) && !empty($_POST['currentTime'])) {
|
||||
if (empty($_SESSION['addViewCount'][$_REQUEST['id']][$value]) && !empty($_REQUEST['currentTime'])) {
|
||||
if ($obj->addViewPercent($value)) {
|
||||
_session_start();
|
||||
$_SESSION['addViewCount'][$_POST['id']][$value] = 1;
|
||||
$_SESSION['addViewCount'][$_REQUEST['id']][$value] = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($_SESSION['addViewCount'][$_POST['id']]['time'])) {
|
||||
if (empty($_SESSION['addViewCount'][$_REQUEST['id']]['time'])) {
|
||||
$resp = $obj->addView();
|
||||
_session_start();
|
||||
$_SESSION['addViewCount'][$_POST['id']]['time'] = strtotime("+{$seconds} seconds");
|
||||
} elseif (!empty($_POST['currentTime'])) {
|
||||
$resp = VideoStatistic::updateStatistic($obj->getId(), User::getId(), intval($_POST['currentTime']));
|
||||
$_SESSION['addViewCount'][$_REQUEST['id']]['time'] = strtotime("+{$seconds} seconds");
|
||||
} elseif (!empty($_REQUEST['currentTime'])) {
|
||||
$resp = VideoStatistic::updateStatistic($obj->getId(), User::getId(), intval($_REQUEST['currentTime']));
|
||||
} else {
|
||||
$resp = 0;
|
||||
}
|
||||
|
|
|
@ -422,6 +422,7 @@ function isMobile() {
|
|||
|
||||
var last_videos_id = 0;
|
||||
var last_currentTime = -1;
|
||||
var videoViewAdded = false;
|
||||
function addView(videos_id, currentTime) {
|
||||
if (last_videos_id == videos_id && last_currentTime == currentTime) {
|
||||
return false;
|
||||
|
@ -429,14 +430,31 @@ function addView(videos_id, currentTime) {
|
|||
if (currentTime > 5 && currentTime % 30 !== 0) { // only update each 30 seconds
|
||||
return false;
|
||||
}
|
||||
|
||||
if (videoViewAdded) {
|
||||
return false;
|
||||
}
|
||||
|
||||
videoViewAdded = true;
|
||||
|
||||
last_videos_id = videos_id;
|
||||
last_currentTime = currentTime;
|
||||
_addView(videos_id, currentTime);
|
||||
}
|
||||
|
||||
function addViewBeacon() {
|
||||
if (typeof player === 'object' && typeof mediaId !== 'undefined') {
|
||||
var url = webSiteRootURL + 'objects/videoAddViewCount.json.php?PHPSESSID=' + PHPSESSID;
|
||||
url = addGetParam(url, 'id', mediaId);
|
||||
url = addGetParam(url, 'currentTime', player.currentTime());
|
||||
var beacon = new Image();
|
||||
beacon.src = url;
|
||||
}
|
||||
}
|
||||
|
||||
function _addView(videos_id, currentTime) {
|
||||
$.ajax({
|
||||
url: webSiteRootURL + 'objects/videoAddViewCount.json.php?PHPSESSID='+PHPSESSID,
|
||||
url: webSiteRootURL + 'objects/videoAddViewCount.json.php?PHPSESSID=' + PHPSESSID,
|
||||
method: 'POST',
|
||||
data: {
|
||||
'id': videos_id,
|
||||
|
@ -1212,7 +1230,7 @@ function tabsCategoryDocumentHeightChanged() {
|
|||
return false;
|
||||
}
|
||||
|
||||
function checkDescriptionArea(){
|
||||
function checkDescriptionArea() {
|
||||
$(".descriptionArea").each(function (index) {
|
||||
if ($(this).height() < $(this).find('.descriptionAreaContent').height()) {
|
||||
$(this).find('.descriptionAreaShowMoreBtn').show();
|
||||
|
@ -1221,10 +1239,15 @@ function checkDescriptionArea(){
|
|||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
$(window).bind('beforeunload', function () {
|
||||
addViewBeacon();
|
||||
});
|
||||
|
||||
checkDescriptionArea();
|
||||
setInterval(function(){// check for the carousel
|
||||
setInterval(function () {// check for the carousel
|
||||
checkDescriptionArea();
|
||||
},3000);
|
||||
}, 3000);
|
||||
|
||||
|
||||
Cookies.set('timezone', Intl.DateTimeFormat().resolvedOptions().timeZone, {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue