1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00
Daniel Neto 2023-07-21 17:50:58 -03:00
parent d0f6ef2348
commit 48504cdc1f
9 changed files with 217 additions and 39 deletions

View file

@ -11416,10 +11416,21 @@ function generateHorizontalFlickity($items)
$carouselClass = 'carousel_' . uniqid(); $carouselClass = 'carousel_' . uniqid();
?> ?>
<div id="<?php echo $carouselClass; ?>" class="carousel HorizontalFlickity" style="visibility: hidden;"> <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"> <div class="carousel-cell">
<a <a title="<?php echo $item['tooltip']; ?>"
title="<?php echo $item['tooltip']; ?>"
href="<?php echo $item['href']; ?>" href="<?php echo $item['href']; ?>"
<?php <?php
if (preg_match('/^#[0-9a-z.-]+/', $item['href'])) { if (preg_match('/^#[0-9a-z.-]+/', $item['href'])) {
@ -11430,7 +11441,7 @@ function generateHorizontalFlickity($items)
if(!empty($item['onclick'])){ if(!empty($item['onclick'])){
echo 'onclick="'.$item['onclick'].'"'; echo 'onclick="'.$item['onclick'].'"';
} ?> } ?>
class="btn btn-default"> class="btn <?php echo $class; ?>">
<?php echo $item['label']; ?> <?php echo $item['label']; ?>
</a> </a>
</div> </div>
@ -11451,7 +11462,10 @@ function generateHorizontalFlickity($items)
wrapAround: true, wrapAround: true,
pageDots: false, pageDots: false,
groupCells: true, groupCells: true,
//initialIndex: <?php echo $initialIndex; ?>,
}); });
$carousel.flickity( 'selectCell', <?php echo $initialIndex; ?> );
}); });
</script> </script>
<?php <?php
@ -11462,3 +11476,24 @@ function generateHorizontalFlickity($items)
} }
$generateHorizontalFlickityLoaded = 1; $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];');
}
}

View file

@ -63,7 +63,19 @@ if ($seconds_watching_video < 0) {
$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; $obj2->seconds_watching_video = $seconds_watching_video;
if (empty($_SESSION['addViewCount'][$_REQUEST['id']]['time'])) { if (empty($_SESSION['addViewCount'][$_REQUEST['id']]['time'])) {
//_error_log("videos_statistics addView {$_REQUEST['id']} {$_SERVER['HTTP_USER_AGENT']} ".json_encode($_SESSION['addViewCount'])); //_error_log("videos_statistics addView {$_REQUEST['id']} {$_SERVER['HTTP_USER_AGENT']} ".json_encode($_SESSION['addViewCount']));
$resp = $obj->addView(); $resp = $obj->addView();

View file

@ -22,6 +22,7 @@ class VideoStatistic extends ObjectYPT {
protected $seconds_watching_video; protected $seconds_watching_video;
protected $json; protected $json;
protected $rewarded; protected $rewarded;
protected $created_php_time;
public static function getSearchFieldsNames() { public static function getSearchFieldsNames() {
return ['json', 'ip', 'when', 'user', 'name', 'email', 'channelName']; 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")); $vs->setWhen(date("Y-m-d h:i:s"));
} else { } else {
$vs = new VideoStatistic($lastStatistic['id']); $vs = new VideoStatistic($lastStatistic['id']);
$elapsedTime = time() - $vs->created_php_time;
if ($seconds_watching_video > $elapsedTime) {
$seconds_watching_video = $elapsedTime;
}
} }
$vs->setLastVideoTime($lastVideoTime); $vs->setLastVideoTime($lastVideoTime);
$vs->setIp(getRealIpAddr()); $vs->setIp(getRealIpAddr());

View file

@ -1,3 +1,6 @@
<?php
saveRequestVars();
?>
<div class="row mainArea"> <div class="row mainArea">
<?php <?php
if (!empty($currentCat)) { if (!empty($currentCat)) {
@ -162,4 +165,7 @@
include $global['systemRootPath'] . 'view/include/notfound.php'; include $global['systemRootPath'] . 'view/include/notfound.php';
} }
?> ?>
</div> </div>
<?php
restoreRequestVars();
?>

View file

@ -32,6 +32,14 @@ foreach ($categories as $value) {
if (!empty($obj->categoriesTopButtonsShowVideosCount)) { if (!empty($obj->categoriesTopButtonsShowVideosCount)) {
$label .= ' <span class="badge">' . $total . '</span>'; $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); generateHorizontalFlickity($items);

View file

@ -122,4 +122,70 @@ foreach ($rows as $key => $value) {
} }
} }
}); });
</script> </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>

View file

@ -169,7 +169,6 @@ class PlayerSkins extends PluginAbstract {
$htmlMediaTag .= '<video '.self::getPlaysinline().' id="mainVideo" style="display: none; height: 0;width: 0;" ></video>'; $htmlMediaTag .= '<video '.self::getPlaysinline().' id="mainVideo" style="display: none; height: 0;width: 0;" ></video>';
//$htmlMediaTag .= '<div id="main-video" class="embed-responsive-item">'; //$htmlMediaTag .= '<div id="main-video" class="embed-responsive-item">';
$htmlMediaTag .= '<iframe class="embed-responsive-item" scrolling="no" '.Video::$iframeAllowAttributes.' src="' . $url . '"></iframe>'; $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>'; //$htmlMediaTag .= '</div>';
} else { } else {
// youtube! // youtube!
@ -650,18 +649,14 @@ class PlayerSkins extends PluginAbstract {
$url = Video::getURLFriendly($videos_id); $url = Video::getURLFriendly($videos_id);
$js .= " $js .= "
player.on('play', function () { player.on('play', function () {
addView({$videos_id}, this.currentTime());
_addViewBeaconAdded = false;
sendAVideoMobileMessage('play', this.currentTime()); sendAVideoMobileMessage('play', this.currentTime());
}); });
player.on('ended', function () { player.on('ended', function () {
var time = Math.round(this.currentTime()); var time = Math.round(this.currentTime());
addView({$videos_id}, time);
sendAVideoMobileMessage('ended', time); sendAVideoMobileMessage('ended', time);
}); });
player.on('pause', function () { player.on('pause', function () {
var time = Math.round(this.currentTime()); var time = Math.round(this.currentTime());
addView({$videos_id}, time);
sendAVideoMobileMessage('pause', time); sendAVideoMobileMessage('pause', time);
}); });
player.on('volumechange', function () { player.on('volumechange', function () {
@ -683,13 +678,6 @@ class PlayerSkins extends PluginAbstract {
$('#linkCurrentTime, .linkCurrentTime').val(url); $('#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); sendAVideoMobileMessage('timeupdate', time);
}); });
;"; ;";

View file

@ -1,11 +1,31 @@
var last_videos_id = 0; var last_videos_id = 0;
var last_currentTime = -1; var last_currentTime = -1;
var videoViewAdded = false; var videoViewAdded = false;
var addViewBeaconTimeout;
var _addViewCheck = false; 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) { function addView(videos_id, currentTime) {
addViewSetCookie(PHPSESSID, videos_id, currentTime, seconds_watching_video); addViewSetCookie(PHPSESSID, videos_id, currentTime, VideoWatchTime.getValue());
if (_addViewCheck) { if (_addViewCheck) {
return false; return false;
@ -15,15 +35,12 @@ function addView(videos_id, currentTime) {
return false; return false;
} }
if (currentTime > 5 && currentTime % 30 !== 0) { // only update each 30 seconds // Removed the currentTime condition
return false;
}
_addViewCheck = true; _addViewCheck = true;
last_videos_id = videos_id; last_videos_id = videos_id;
last_currentTime = currentTime; last_currentTime = currentTime;
_addView(videos_id, currentTime, seconds_watching_video); _addView(videos_id, currentTime, VideoWatchTime.getValue());
setTimeout(function() { setTimeout(function() {
_addViewCheck = false; _addViewCheck = false;
@ -41,7 +58,6 @@ function _addView(videos_id, currentTime, seconds_watching_video) {
} }
console.log('_addView 2', videos_id, currentTime, seconds_watching_video); console.log('_addView 2', videos_id, currentTime, seconds_watching_video);
isVideoAddViewCount = true;
if (typeof PHPSESSID === 'undefined') { if (typeof PHPSESSID === 'undefined') {
PHPSESSID = ''; PHPSESSID = '';
@ -52,23 +68,29 @@ function _addView(videos_id, currentTime, seconds_watching_video) {
if (empty(PHPSESSID)) { if (empty(PHPSESSID)) {
return false; return false;
} }
isVideoAddViewCount = true;
console.log('_addView 3', videos_id, currentTime, seconds_watching_video); console.log('_addView 3', videos_id, currentTime, seconds_watching_video);
url = addGetParam(url, 'PHPSESSID', PHPSESSID); url = addGetParam(url, 'PHPSESSID', PHPSESSID);
// reset seconds_watching_video
var seconds_watching_video_to_send = seconds_watching_video;
VideoWatchTime.reset();
console.trace();
$.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 seconds_watching_video: seconds_watching_video_to_send
}, },
success: function(response) { success: function(response) {
console.log('_addView 4', response); console.log('_addView 4', response);
isVideoAddViewCount = false;
$('.view-count' + videos_id).text(response.countHTML); $('.view-count' + videos_id).text(response.countHTML);
PHPSESSID = response.session_id; 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 }); 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(); 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();
});

View file

@ -266,8 +266,6 @@ async function lazyImage() {
} }
var pauseIfIsPlayinAdsInterval; var pauseIfIsPlayinAdsInterval;
var seconds_watching_video = 0;
var _startCountPlayingTime;
async function setPlayerListners() { async function setPlayerListners() {
if (typeof player !== 'undefined') { if (typeof player !== 'undefined') {
player.on('pause', function () { player.on('pause', function () {
@ -275,7 +273,6 @@ async function setPlayerListners() {
//console.log("setPlayerListners: pause"); //console.log("setPlayerListners: pause");
//userIsControling = true; //userIsControling = true;
clearInterval(pauseIfIsPlayinAdsInterval); clearInterval(pauseIfIsPlayinAdsInterval);
clearInterval(_startCountPlayingTime);
}); });
player.on('play', function () { player.on('play', function () {
isTryingToPlay = false; isTryingToPlay = false;
@ -291,10 +288,6 @@ async function setPlayerListners() {
pauseIfIsPlayinAdsInterval = setInterval(function () { pauseIfIsPlayinAdsInterval = setInterval(function () {
pauseIfIsPlayinAds(); pauseIfIsPlayinAds();
}, 500); }, 500);
clearInterval(_startCountPlayingTime);
_startCountPlayingTime = setInterval(function () {
seconds_watching_video++;
}, 1000);
}); });
$("#mainVideo .vjs-mute-control").click(function () { $("#mainVideo .vjs-mute-control").click(function () {
Cookies.set('muted', player.muted(), { Cookies.set('muted', player.muted(), {