mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
This commit is contained in:
parent
d0f6ef2348
commit
48504cdc1f
9 changed files with 217 additions and 39 deletions
|
@ -11416,10 +11416,21 @@ function generateHorizontalFlickity($items)
|
|||
$carouselClass = 'carousel_' . uniqid();
|
||||
?>
|
||||
<div id="<?php echo $carouselClass; ?>" class="carousel HorizontalFlickity" style="visibility: hidden;">
|
||||
<?php foreach ($items as $item) { ?>
|
||||
<?php
|
||||
$initialIndex = 0;
|
||||
foreach ($items as $key => $item) {
|
||||
$isActive = false;
|
||||
if(!empty($item['isActive'])){
|
||||
$isActive = true;
|
||||
}
|
||||
$class = 'btn-default';
|
||||
if($isActive){
|
||||
$class = 'btn-primary';
|
||||
$initialIndex = $key;
|
||||
}
|
||||
?>
|
||||
<div class="carousel-cell">
|
||||
<a
|
||||
title="<?php echo $item['tooltip']; ?>"
|
||||
<a title="<?php echo $item['tooltip']; ?>"
|
||||
href="<?php echo $item['href']; ?>"
|
||||
<?php
|
||||
if (preg_match('/^#[0-9a-z.-]+/', $item['href'])) {
|
||||
|
@ -11430,7 +11441,7 @@ function generateHorizontalFlickity($items)
|
|||
if(!empty($item['onclick'])){
|
||||
echo 'onclick="'.$item['onclick'].'"';
|
||||
} ?>
|
||||
class="btn btn-default">
|
||||
class="btn <?php echo $class; ?>">
|
||||
<?php echo $item['label']; ?>
|
||||
</a>
|
||||
</div>
|
||||
|
@ -11451,7 +11462,10 @@ function generateHorizontalFlickity($items)
|
|||
wrapAround: true,
|
||||
pageDots: false,
|
||||
groupCells: true,
|
||||
//initialIndex: <?php echo $initialIndex; ?>,
|
||||
});
|
||||
|
||||
$carousel.flickity( 'selectCell', <?php echo $initialIndex; ?> );
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
|
@ -11462,3 +11476,24 @@ function generateHorizontalFlickity($items)
|
|||
}
|
||||
$generateHorizontalFlickityLoaded = 1;
|
||||
}
|
||||
|
||||
function saveRequestVars(){
|
||||
global $savedRequestVars;
|
||||
|
||||
$array = array('GET', 'POST', 'REQUEST');
|
||||
|
||||
foreach ($array as $value) {
|
||||
eval('$savedRequestVars[$value] = $_'.$value.';');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function restoreRequestVars(){
|
||||
global $savedRequestVars;
|
||||
|
||||
$array = array('GET', 'POST', 'REQUEST');
|
||||
|
||||
foreach ($array as $value) {
|
||||
eval('$_'.$value.' = $savedRequestVars[$value];');
|
||||
}
|
||||
}
|
|
@ -63,7 +63,19 @@ if ($seconds_watching_video < 0) {
|
|||
$seconds_watching_video = 0;
|
||||
}
|
||||
|
||||
// Comparison and update
|
||||
$current_time = time();
|
||||
if (isset($_SESSION['addViewCount'][$_REQUEST['id']]['last_update_time'])) {
|
||||
$elapsed_time = $current_time - $_SESSION['addViewCount'][$_REQUEST['id']]['last_update_time'];
|
||||
if ($seconds_watching_video > $elapsed_time) {
|
||||
$seconds_watching_video = $elapsed_time;
|
||||
}
|
||||
}
|
||||
|
||||
$_SESSION['addViewCount'][$_REQUEST['id']]['last_update_time'] = $current_time;
|
||||
|
||||
$obj2->seconds_watching_video = $seconds_watching_video;
|
||||
|
||||
if (empty($_SESSION['addViewCount'][$_REQUEST['id']]['time'])) {
|
||||
//_error_log("videos_statistics addView {$_REQUEST['id']} {$_SERVER['HTTP_USER_AGENT']} ".json_encode($_SESSION['addViewCount']));
|
||||
$resp = $obj->addView();
|
||||
|
|
|
@ -22,6 +22,7 @@ class VideoStatistic extends ObjectYPT {
|
|||
protected $seconds_watching_video;
|
||||
protected $json;
|
||||
protected $rewarded;
|
||||
protected $created_php_time;
|
||||
|
||||
public static function getSearchFieldsNames() {
|
||||
return ['json', 'ip', 'when', 'user', 'name', 'email', 'channelName'];
|
||||
|
@ -105,6 +106,10 @@ class VideoStatistic extends ObjectYPT {
|
|||
$vs->setWhen(date("Y-m-d h:i:s"));
|
||||
} else {
|
||||
$vs = new VideoStatistic($lastStatistic['id']);
|
||||
$elapsedTime = time() - $vs->created_php_time;
|
||||
if ($seconds_watching_video > $elapsedTime) {
|
||||
$seconds_watching_video = $elapsedTime;
|
||||
}
|
||||
}
|
||||
$vs->setLastVideoTime($lastVideoTime);
|
||||
$vs->setIp(getRealIpAddr());
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
<?php
|
||||
saveRequestVars();
|
||||
?>
|
||||
<div class="row mainArea">
|
||||
<?php
|
||||
if (!empty($currentCat)) {
|
||||
|
@ -163,3 +166,6 @@
|
|||
}
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
restoreRequestVars();
|
||||
?>
|
|
@ -32,6 +32,14 @@ foreach ($categories as $value) {
|
|||
if (!empty($obj->categoriesTopButtonsShowVideosCount)) {
|
||||
$label .= ' <span class="badge">' . $total . '</span>';
|
||||
}
|
||||
$items[] = array('href' => Category::getCategoryLinkFromName($value['clean_name']), 'tooltip' => __($value['name']), 'onclick' => '', 'label' => $label);
|
||||
$items[] = array(
|
||||
'href' => Category::getCategoryLinkFromName($value['clean_name']),
|
||||
'tooltip' => __($value['name']),
|
||||
'onclick' => '',
|
||||
'label' => $label,
|
||||
'isActive' => $value['clean_name'] == @$_REQUEST['catName'],
|
||||
'clean_name' => $value['clean_name']
|
||||
);
|
||||
}
|
||||
//var_dump($_REQUEST['catName'], $items);exit;
|
||||
generateHorizontalFlickity($items);
|
||||
|
|
|
@ -123,3 +123,69 @@ foreach ($rows as $key => $value) {
|
|||
}
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
$videosData = [];
|
||||
foreach ($data as $value) {
|
||||
$videosId = $value['videos_id'];
|
||||
$reward = $value['total_reward'];
|
||||
$title = $value['title'];
|
||||
|
||||
// If this videos_id is already in the $videosData array, update its reward, otherwise add it as a new entry.
|
||||
if (isset($videosData[$videosId])) {
|
||||
$videosData[$videosId]['reward'] += $reward;
|
||||
} else {
|
||||
$videosData[$videosId] = [
|
||||
'reward' => $reward,
|
||||
'title' => $title,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$videosIds = [];
|
||||
$rewards = [];
|
||||
$titles = [];
|
||||
foreach ($videosData as $videosId => $videoInfo) {
|
||||
$videosIds[] = $videosId;
|
||||
$rewards[] = $videoInfo['reward'];
|
||||
$titles[] = $videoInfo['title'];
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="container">
|
||||
<div class="panel">
|
||||
<div class="panel-body">
|
||||
<canvas id="rewardChart2" style="width:100%; height:400px;"></canvas>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let videosIds = <?php echo json_encode($videosIds); ?>;
|
||||
let rewards2 = <?php echo json_encode($rewards); ?>;
|
||||
let titles = <?php echo json_encode($titles); ?>;
|
||||
|
||||
new Chart(document.getElementById("rewardChart2"), {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: titles, // Use the video titles as labels
|
||||
datasets: [{
|
||||
data: rewards2,
|
||||
label: "Money Made",
|
||||
backgroundColor: "#3e95cd",
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
title: {
|
||||
display: true,
|
||||
text: 'Money Made per Video'
|
||||
},
|
||||
scales: {
|
||||
yAxes: [{
|
||||
ticks: {
|
||||
beginAtZero: true,
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -169,7 +169,6 @@ class PlayerSkins extends PluginAbstract {
|
|||
$htmlMediaTag .= '<video '.self::getPlaysinline().' id="mainVideo" style="display: none; height: 0;width: 0;" ></video>';
|
||||
//$htmlMediaTag .= '<div id="main-video" class="embed-responsive-item">';
|
||||
$htmlMediaTag .= '<iframe class="embed-responsive-item" scrolling="no" '.Video::$iframeAllowAttributes.' src="' . $url . '"></iframe>';
|
||||
$htmlMediaTag .= '<script>$(document).ready(function () {addView(' . intval($video['id']) . ', 0);});</script>';
|
||||
//$htmlMediaTag .= '</div>';
|
||||
} else {
|
||||
// youtube!
|
||||
|
@ -650,18 +649,14 @@ class PlayerSkins extends PluginAbstract {
|
|||
$url = Video::getURLFriendly($videos_id);
|
||||
$js .= "
|
||||
player.on('play', function () {
|
||||
addView({$videos_id}, this.currentTime());
|
||||
_addViewBeaconAdded = false;
|
||||
sendAVideoMobileMessage('play', this.currentTime());
|
||||
});
|
||||
player.on('ended', function () {
|
||||
var time = Math.round(this.currentTime());
|
||||
addView({$videos_id}, time);
|
||||
sendAVideoMobileMessage('ended', time);
|
||||
});
|
||||
player.on('pause', function () {
|
||||
var time = Math.round(this.currentTime());
|
||||
addView({$videos_id}, time);
|
||||
sendAVideoMobileMessage('pause', time);
|
||||
});
|
||||
player.on('volumechange', function () {
|
||||
|
@ -683,13 +678,6 @@ class PlayerSkins extends PluginAbstract {
|
|||
|
||||
$('#linkCurrentTime, .linkCurrentTime').val(url);
|
||||
|
||||
if (time >= 5 && time % 1 === 0) {
|
||||
addView({$videos_id}, time);
|
||||
} else {
|
||||
addViewFromCookie();
|
||||
addViewSetCookie(PHPSESSID, {$videos_id}, time, seconds_watching_video);
|
||||
}
|
||||
|
||||
sendAVideoMobileMessage('timeupdate', time);
|
||||
});
|
||||
;";
|
||||
|
|
|
@ -1,11 +1,31 @@
|
|||
var last_videos_id = 0;
|
||||
var last_currentTime = -1;
|
||||
var videoViewAdded = false;
|
||||
var addViewBeaconTimeout;
|
||||
var _addViewCheck = false;
|
||||
var isVideoPlaying = false;
|
||||
|
||||
// Create an encapsulation for seconds_watching_video
|
||||
var VideoWatchTime = (function () {
|
||||
var seconds_watching_video = 0;
|
||||
|
||||
return {
|
||||
increment: function() {
|
||||
if (isVideoPlaying) {
|
||||
seconds_watching_video++;
|
||||
}
|
||||
},
|
||||
reset: function() {
|
||||
seconds_watching_video = 0;
|
||||
},
|
||||
getValue: function() {
|
||||
return seconds_watching_video;
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
// Modify the addView function
|
||||
function addView(videos_id, currentTime) {
|
||||
addViewSetCookie(PHPSESSID, videos_id, currentTime, seconds_watching_video);
|
||||
addViewSetCookie(PHPSESSID, videos_id, currentTime, VideoWatchTime.getValue());
|
||||
|
||||
if (_addViewCheck) {
|
||||
return false;
|
||||
|
@ -15,15 +35,12 @@ function addView(videos_id, currentTime) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (currentTime > 5 && currentTime % 30 !== 0) { // only update each 30 seconds
|
||||
return false;
|
||||
}
|
||||
|
||||
// Removed the currentTime condition
|
||||
_addViewCheck = true;
|
||||
last_videos_id = videos_id;
|
||||
last_currentTime = currentTime;
|
||||
|
||||
_addView(videos_id, currentTime, seconds_watching_video);
|
||||
_addView(videos_id, currentTime, VideoWatchTime.getValue());
|
||||
|
||||
setTimeout(function() {
|
||||
_addViewCheck = false;
|
||||
|
@ -41,7 +58,6 @@ function _addView(videos_id, currentTime, seconds_watching_video) {
|
|||
}
|
||||
|
||||
console.log('_addView 2', videos_id, currentTime, seconds_watching_video);
|
||||
isVideoAddViewCount = true;
|
||||
|
||||
if (typeof PHPSESSID === 'undefined') {
|
||||
PHPSESSID = '';
|
||||
|
@ -53,22 +69,28 @@ function _addView(videos_id, currentTime, seconds_watching_video) {
|
|||
return false;
|
||||
}
|
||||
|
||||
isVideoAddViewCount = true;
|
||||
console.log('_addView 3', videos_id, currentTime, seconds_watching_video);
|
||||
url = addGetParam(url, 'PHPSESSID', PHPSESSID);
|
||||
|
||||
// reset seconds_watching_video
|
||||
var seconds_watching_video_to_send = seconds_watching_video;
|
||||
VideoWatchTime.reset();
|
||||
console.trace();
|
||||
$.ajax({
|
||||
url: url,
|
||||
method: 'POST',
|
||||
data: {
|
||||
id: videos_id,
|
||||
currentTime: currentTime,
|
||||
seconds_watching_video: seconds_watching_video
|
||||
seconds_watching_video: seconds_watching_video_to_send
|
||||
},
|
||||
success: function(response) {
|
||||
console.log('_addView 4', response);
|
||||
isVideoAddViewCount = false;
|
||||
$('.view-count' + videos_id).text(response.countHTML);
|
||||
PHPSESSID = response.session_id;
|
||||
}, complete: function(response) {
|
||||
console.log('_addView 5', response);
|
||||
isVideoAddViewCount = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -122,6 +144,49 @@ async function addViewSetCookie(PHPSESSID, videos_id, playerCurrentTime, seconds
|
|||
Cookies.set('addView_seconds_watching_video', seconds_watching_video, { path: '/', expires: 1 });
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
async function startAddViewCountInPlayer(){
|
||||
if(typeof player !== 'undefined' && typeof mediaId !== 'undefined'){
|
||||
player.on('play', function () {
|
||||
isVideoPlaying = true;
|
||||
addView(mediaId, this.currentTime());
|
||||
});
|
||||
player.on('pause', function () {
|
||||
isVideoPlaying = false;
|
||||
var time = Math.round(this.currentTime());
|
||||
addView(mediaId, time);
|
||||
});
|
||||
player.on('ended', function () {
|
||||
isVideoPlaying = false;
|
||||
var time = Math.round(this.currentTime());
|
||||
addView(mediaId, time);
|
||||
});
|
||||
|
||||
player.on('timeupdate', function() {
|
||||
var time = Math.round(this.currentTime());
|
||||
if (time === 0 || time % 30 === 0) {
|
||||
addView(mediaId, time);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
setTimeout(function() {
|
||||
startAddViewCountInPlayer();
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
|
||||
// Add beforeunload event
|
||||
window.addEventListener('beforeunload', (event) => {
|
||||
addViewFromCookie();
|
||||
});
|
||||
|
||||
$(document).ready(function() {
|
||||
// Use setInterval to update seconds_watching_video every second
|
||||
setInterval(function () {
|
||||
VideoWatchTime.increment();
|
||||
}, 1000);
|
||||
|
||||
// Call addViewFromCookie on the next page load
|
||||
addViewFromCookie();
|
||||
|
||||
startAddViewCountInPlayer();
|
||||
});
|
|
@ -266,8 +266,6 @@ async function lazyImage() {
|
|||
}
|
||||
|
||||
var pauseIfIsPlayinAdsInterval;
|
||||
var seconds_watching_video = 0;
|
||||
var _startCountPlayingTime;
|
||||
async function setPlayerListners() {
|
||||
if (typeof player !== 'undefined') {
|
||||
player.on('pause', function () {
|
||||
|
@ -275,7 +273,6 @@ async function setPlayerListners() {
|
|||
//console.log("setPlayerListners: pause");
|
||||
//userIsControling = true;
|
||||
clearInterval(pauseIfIsPlayinAdsInterval);
|
||||
clearInterval(_startCountPlayingTime);
|
||||
});
|
||||
player.on('play', function () {
|
||||
isTryingToPlay = false;
|
||||
|
@ -291,10 +288,6 @@ async function setPlayerListners() {
|
|||
pauseIfIsPlayinAdsInterval = setInterval(function () {
|
||||
pauseIfIsPlayinAds();
|
||||
}, 500);
|
||||
clearInterval(_startCountPlayingTime);
|
||||
_startCountPlayingTime = setInterval(function () {
|
||||
seconds_watching_video++;
|
||||
}, 1000);
|
||||
});
|
||||
$("#mainVideo .vjs-mute-control").click(function () {
|
||||
Cookies.set('muted', player.muted(), {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue