mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 17:59:55 +02:00
Improve add view
This commit is contained in:
parent
6fe8b6a64f
commit
d9a3c9a9bf
3 changed files with 185 additions and 192 deletions
|
@ -151,7 +151,7 @@ if (!class_exists('Video')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$lastStatistic = self::getLastStatistics($this->id, User::getId());
|
$lastStatistic = VideoStatistic::getLastStatistics($this->id, User::getId());
|
||||||
if(!empty($lastStatistic)){
|
if(!empty($lastStatistic)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,12 @@ time.duration {
|
||||||
.thumbsImageContainer .thumbsImage{
|
.thumbsImageContainer .thumbsImage{
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
.thumbsImageContainer .progress{
|
||||||
|
height: 4px;
|
||||||
|
z-index: 1;
|
||||||
|
top: -4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
.videoLink .glyphicon-play-circle {
|
.videoLink .glyphicon-play-circle {
|
||||||
transition: all 0.3s ease-in-out;
|
transition: all 0.3s ease-in-out;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
|
|
|
@ -480,37 +480,45 @@ var last_videos_id = 0;
|
||||||
var last_currentTime = -1;
|
var last_currentTime = -1;
|
||||||
var videoViewAdded = false;
|
var videoViewAdded = false;
|
||||||
var addViewBeaconTimeout;
|
var addViewBeaconTimeout;
|
||||||
|
var _addViewCheck = false;
|
||||||
function addView(videos_id, currentTime) {
|
function addView(videos_id, currentTime) {
|
||||||
addViewSetCookie(PHPSESSID, videos_id, currentTime, seconds_watching_video);
|
addViewSetCookie(PHPSESSID, videos_id, currentTime, seconds_watching_video);
|
||||||
|
if(_addViewCheck){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (last_videos_id == videos_id && last_currentTime == currentTime) {
|
if (last_videos_id == videos_id && last_currentTime == currentTime) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (currentTime > 5 && currentTime % 5 !== 0) { // only update each 5 seconds
|
if (currentTime > 5 && currentTime % 30 !== 0) { // only update each 30 seconds
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
_addViewCheck = true;
|
||||||
if (!videoViewAdded || videoViewAdded !== videos_id) {
|
|
||||||
videoViewAdded = videos_id;
|
|
||||||
last_videos_id = videos_id;
|
last_videos_id = videos_id;
|
||||||
last_currentTime = currentTime;
|
last_currentTime = currentTime;
|
||||||
_addView(videos_id, currentTime);
|
_addView(videos_id, currentTime, seconds_watching_video);
|
||||||
}
|
setTimeout(function () {
|
||||||
|
_addViewCheck = false
|
||||||
|
}, 1000);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _addView(videos_id, currentTime) {
|
function _addView(videos_id, currentTime, seconds_watching_video) {
|
||||||
if (typeof PHPSESSID == 'undefined') {
|
if (typeof PHPSESSID == 'undefined') {
|
||||||
PHPSESSID = '';
|
PHPSESSID = '';
|
||||||
}
|
}
|
||||||
var url = webSiteRootURL + 'objects/videoAddViewCount.json.php';
|
var url = webSiteRootURL + 'objects/videoAddViewCount.json.php';
|
||||||
|
if(empty(PHPSESSID)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
url = addGetParam(url, 'PHPSESSID', PHPSESSID);
|
url = addGetParam(url, 'PHPSESSID', PHPSESSID);
|
||||||
//console.log('_addView', videos_id, currentTime);
|
//console.log('_addView', videos_id, currentTime);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: url,
|
url: url,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: {
|
data: {
|
||||||
'id': videos_id,
|
id: videos_id,
|
||||||
'currentTime': currentTime
|
currentTime: currentTime,
|
||||||
|
seconds_watching_video: seconds_watching_video
|
||||||
},
|
},
|
||||||
success: function (response) {
|
success: function (response) {
|
||||||
$('.view-count' + videos_id).text(response.countHTML);
|
$('.view-count' + videos_id).text(response.countHTML);
|
||||||
|
@ -530,22 +538,10 @@ function _addViewAsync() {
|
||||||
var url = webSiteRootURL + 'objects/videoAddViewCount.json.php';
|
var url = webSiteRootURL + 'objects/videoAddViewCount.json.php';
|
||||||
url = addGetParam(url, 'PHPSESSID', PHPSESSID);
|
url = addGetParam(url, 'PHPSESSID', PHPSESSID);
|
||||||
_addViewAsyncSent = true;
|
_addViewAsyncSent = true;
|
||||||
$.ajax({
|
_addView(mediaId, playerCurrentTime, seconds_watching_video);
|
||||||
url: url,
|
|
||||||
method: 'POST',
|
|
||||||
data: {
|
|
||||||
'id': mediaId,
|
|
||||||
'currentTime': playerCurrentTime,
|
|
||||||
'seconds_watching_video': seconds_watching_video
|
|
||||||
},
|
|
||||||
async: false,
|
|
||||||
success: function (response) {
|
|
||||||
//console.log('_addViewAsync', response);
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
_addViewAsyncSent = false;
|
_addViewAsyncSent = false;
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _addViewFromCookie_addingtime = false;
|
var _addViewFromCookie_addingtime = false;
|
||||||
|
@ -575,21 +571,12 @@ async function addViewFromCookie() {
|
||||||
forceCurrentTime = addView_playerCurrentTime;
|
forceCurrentTime = addView_playerCurrentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
$.ajax({
|
_addView(addView_videos_id, addView_playerCurrentTime, addView_seconds_watching_video)
|
||||||
url: url,
|
setTimeout(function () {
|
||||||
method: 'POST',
|
|
||||||
data: {
|
|
||||||
'id': addView_videos_id,
|
|
||||||
'currentTime': addView_playerCurrentTime,
|
|
||||||
'seconds_watching_video': addView_seconds_watching_video
|
|
||||||
},
|
|
||||||
async: false,
|
|
||||||
success: function (response) {
|
|
||||||
_addViewFromCookie_addingtime = false;
|
_addViewFromCookie_addingtime = false;
|
||||||
//console.log('addViewFromCookie', response);
|
}, 2000);
|
||||||
addViewSetCookie(false, false, false, false);
|
addViewSetCookie(false, false, false, false);
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addViewSetCookie(PHPSESSID, videos_id, playerCurrentTime, seconds_watching_video) {
|
async function addViewSetCookie(PHPSESSID, videos_id, playerCurrentTime, seconds_watching_video) {
|
||||||
|
@ -2744,7 +2731,7 @@ function addAtMention(selector) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
async function selectAElements() {
|
async function selectAElements() {
|
||||||
$("a").each(function () {
|
$("a").each(function () {
|
||||||
var location = window.location.toString()
|
var location = window.location.toString()
|
||||||
var res = location.split("?");
|
var res = location.split("?");
|
||||||
|
@ -2755,7 +2742,7 @@ async function selectAElements() {
|
||||||
$(this).addClass("selected");
|
$(this).addClass("selected");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
var hidePleaseWaitTimeout = {};
|
var hidePleaseWaitTimeout = {};
|
||||||
var pleaseWaitIsINUse = {};
|
var pleaseWaitIsINUse = {};
|
||||||
|
@ -2937,7 +2924,7 @@ function openWindow(url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function openWindowWithPost(url, name, params, strWindowFeatures) {
|
function openWindowWithPost(url, name, params, strWindowFeatures) {
|
||||||
if(empty(strWindowFeatures)){
|
if (empty(strWindowFeatures)) {
|
||||||
strWindowFeatures = "directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,height=600,width=800";
|
strWindowFeatures = "directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,height=600,width=800";
|
||||||
}
|
}
|
||||||
var windowObject = window.open("about:blank", name, strWindowFeatures);
|
var windowObject = window.open("about:blank", name, strWindowFeatures);
|
||||||
|
@ -3275,19 +3262,19 @@ function notifyInputIfIsWrongFormat(_this, isValid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupMySQLInput(selector) {
|
function setupMySQLInput(selector) {
|
||||||
if(typeof $(selector).inputmask !== 'function'){
|
if (typeof $(selector).inputmask !== 'function') {
|
||||||
addScript(webSiteRootURL+'node_modules/inputmask/dist/jquery.inputmask.min.js');
|
addScript(webSiteRootURL + 'node_modules/inputmask/dist/jquery.inputmask.min.js');
|
||||||
setTimeout(function(){
|
setTimeout(function () {
|
||||||
setupMySQLInput(selector);
|
setupMySQLInput(selector);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$(selector).inputmask({
|
$(selector).inputmask({
|
||||||
mask: "9999-99-99 99:99:99",
|
mask: "9999-99-99 99:99:99",
|
||||||
onincomplete: function(buffer, opts) {
|
onincomplete: function (buffer, opts) {
|
||||||
notifyInputIfIsWrongFormat($(this), false);
|
notifyInputIfIsWrongFormat($(this), false);
|
||||||
},
|
},
|
||||||
oncomplete: function(buffer, opts) {
|
oncomplete: function (buffer, opts) {
|
||||||
notifyInputIfIsWrongFormat($(this), true);
|
notifyInputIfIsWrongFormat($(this), true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -3394,7 +3381,7 @@ function arrayToTemplate(itemsArray, template) {
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
function avideoLoadPage(url) {
|
function avideoLoadPage(url) {
|
||||||
console.log('avideoLoadPage', url);
|
console.log('avideoLoadPage', url);
|
||||||
avideoPushState(url);
|
avideoPushState(url);
|
||||||
if (inMainIframe()) {
|
if (inMainIframe()) {
|
||||||
|
@ -3402,9 +3389,9 @@ function avideoLoadPage(url) {
|
||||||
} else {
|
} else {
|
||||||
document.location = url;
|
document.location = url;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function avideoLoadPage3(url) {
|
function avideoLoadPage3(url) {
|
||||||
console.log('avideoLoadPage3', url);
|
console.log('avideoLoadPage3', url);
|
||||||
avideoPushState(url);
|
avideoPushState(url);
|
||||||
if (inMainIframe()) {
|
if (inMainIframe()) {
|
||||||
|
@ -3439,9 +3426,9 @@ function avideoLoadPage3(url) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function avideoLoadPage2(url) {
|
function avideoLoadPage2(url) {
|
||||||
console.log('avideoLoadPage', url);
|
console.log('avideoLoadPage', url);
|
||||||
avideoPushState(url);
|
avideoPushState(url);
|
||||||
modal.showPleaseWait();
|
modal.showPleaseWait();
|
||||||
|
@ -3469,10 +3456,10 @@ function avideoLoadPage2(url) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async function aHrefToAjax() {
|
async function aHrefToAjax() {
|
||||||
if(typeof useIframe === 'undefined' || !useIframe){
|
if(typeof useIframe === 'undefined' || !useIframe){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -3489,9 +3476,9 @@ async function aHrefToAjax() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addScripts(scriptsToAdd) {
|
function addScripts(scriptsToAdd) {
|
||||||
var localScripts = $("script");
|
var localScripts = $("script");
|
||||||
for (index in scriptsToAdd) {
|
for (index in scriptsToAdd) {
|
||||||
var script = scriptsToAdd[index];
|
var script = scriptsToAdd[index];
|
||||||
|
@ -3520,7 +3507,7 @@ function addScripts(scriptsToAdd) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
* */
|
* */
|
||||||
|
|
||||||
function addScript(src) {
|
function addScript(src) {
|
||||||
|
@ -3538,7 +3525,7 @@ function addScript(src) {
|
||||||
if (!scriptFound) {
|
if (!scriptFound) {
|
||||||
console.log('addScript', src);
|
console.log('addScript', src);
|
||||||
$('<script src="' + src + '" type="text/javascript"></script>').appendTo(document.body);
|
$('<script src="' + src + '" type="text/javascript"></script>').appendTo(document.body);
|
||||||
}else{
|
} else {
|
||||||
console.log('addScript already added ', src);
|
console.log('addScript already added ', src);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue