1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00
This commit is contained in:
Daniel Neto 2023-11-27 11:13:49 -03:00
parent d68427992f
commit e52be42f5c
4 changed files with 34 additions and 21 deletions

View file

@ -383,6 +383,7 @@ abstract class ObjectYPT implements ObjectInterface
}
$sql .= " VALUES (" . implode(", ", $fields) . ")";
}
//error_log("save: $sql [$formats]".json_encode($values));
//var_dump(static::getTableName(), $sql, $values);
//if(static::getTableName() == 'videos'){ echo $sql;var_dump($values); var_dump(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS));}//return false;
//echo $sql;var_dump($this, $values);exit;
@ -402,6 +403,7 @@ abstract class ObjectYPT implements ObjectInterface
return $id;
} else {
_error_log("ObjectYPT::Error on save 1: " . $sql . ' Error : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error . ' ' . json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)), AVideoLog::$ERROR);
_error_log("ObjectYPT::Error on save 2: " .json_encode($values), AVideoLog::$ERROR);
return false;
}
}

View file

@ -1807,7 +1807,7 @@ if (!class_exists('Video')) {
TimeLogEnd($timeLogName, __LINE__, 0.2);
$allowedDurationTypes = ['video', 'audio'];
$users_id = User::getId();
/**
*
* @var array $global
@ -1833,9 +1833,14 @@ if (!class_exists('Video')) {
}
$tlogName = TimeLogStart("video::getInfo index={$index} id={$row['id']} {$row['type']}");
$row = self::getInfo($row, $getStatistcs);
if ($getStatistcs) {
$row = self::getInfoPersonal($row);
} else {
}
if(!empty($users_id)){
TimeLogEnd($tlogName, __LINE__, $tolerance / 2);
$row['progress'] = self::getVideoPogressPercent($row['id'], $users_id);
}else {
$row['progress'] = ['percent' => 0, 'lastVideoTime' => 0, 'duration' => $row['duration_in_seconds']];
}
TimeLogEnd($tlogName, __LINE__, $tolerance / 2);
@ -2025,8 +2030,6 @@ if (!class_exists('Video')) {
$row['video_password'] = empty($rowOriginal['video_password']) ? '' : $rowOriginal['video_password'];
}
TimeLogEnd($timeLogName, __LINE__, $TimeLogLimit);
$row['progress'] = self::getVideoPogressPercent($row['id']);
TimeLogEnd($timeLogName, __LINE__, $TimeLogLimit);
$row['isFavorite'] = self::isFavorite($row['id']);
TimeLogEnd($timeLogName, __LINE__, $TimeLogLimit);
$row['isWatchLater'] = self::isWatchLater($row['id']);
@ -6014,7 +6017,7 @@ if (!class_exists('Video')) {
$plans = $sub->getPlansFromVideo($videos_id);
if (!empty($plans)) {
$obj->plugin = 'Subscription';
$obj->buyURL = "{$global['webSiteRootURL']}plugin/Subscription/showPlans.php?videos_id={$videos_id}";
$obj->buyURL = Subscription::getBuyURL($videos_id);
$obj->canVideoBePurchased = true;
return $obj;
}
@ -6023,16 +6026,7 @@ if (!class_exists('Video')) {
// check for PPV plugin
if (AVideoPlugin::isEnabledByName('PayPerView')) {
if (PayPerView::isVideoPayPerView($videos_id) || $obj->onlyPlayVideosWithPayPerViewActive) {
$url = "{$global['webSiteRootURL']}plugin/PayPerView/page/buy.php";
if (isSerie()) {
$redirectUri = getSelfURI();
} else {
$redirectUri = getRedirectToVideo($videos_id);
}
if (!empty($redirectUri)) {
$url = addQueryStringParameter($url, 'redirectUri', $redirectUri);
}
$url = addQueryStringParameter($url, 'videos_id', $videos_id);
$url = PayPerView::getBuyURL($videos_id);
$obj->plugin = 'PayPerView';
$obj->buyURL = $url;
$obj->canVideoBePurchased = true;

View file

@ -90,11 +90,11 @@ if (empty($_SESSION['addViewCount'][$_REQUEST['id']]['time'])) {
}
if (isset($_REQUEST['currentTime'])) {
$currentTime = intval($_REQUEST['currentTime']);
if ($currentTime < 0) {
$currentTime = 0;
$obj2->currentTime = intval($_REQUEST['currentTime']);
if ($obj2->currentTime < 0) {
$obj2->currentTime = 0;
}
$resp = VideoStatistic::updateStatistic($obj->getId(), User::getId(), $currentTime, $seconds_watching_video);
$resp = VideoStatistic::updateStatistic($obj->getId(), User::getId(), $obj2->currentTime, $obj2->seconds_watching_video);
} else {
$resp = 0;
}

View file

@ -95,26 +95,38 @@ class VideoStatistic extends ObjectYPT {
}
public static function updateStatistic($videos_id, $users_id, $lastVideoTime, $seconds_watching_video = 0) {
//error_log("updateStatistic: videos_id=$videos_id lastVideoTime=$lastVideoTime, seconds_watching_video=$seconds_watching_video line=" . __LINE__);
if(isBot()){
//error_log("updateStatistic: videos_id=$videos_id lastVideoTime=$lastVideoTime, seconds_watching_video=$seconds_watching_video line=" . __LINE__);
return false;
}
$lastStatistic = self::getLastStatistics($videos_id, $users_id, getRealIpAddr(), session_id());
if (empty($lastStatistic)) {
//error_log("updateStatistic: videos_id=$videos_id lastVideoTime=$lastVideoTime, seconds_watching_video=$seconds_watching_video line=" . __LINE__);
$vs = new VideoStatistic(0);
$vs->setUsers_id($users_id);
$vs->setVideos_id($videos_id);
$vs->setWhen(date("Y-m-d h:i:s"));
} else {
//error_log("updateStatistic: videos_id=$videos_id lastVideoTime=$lastVideoTime, seconds_watching_video=$seconds_watching_video line=" . __LINE__);
$vs = new VideoStatistic($lastStatistic['id']);
$elapsedTime = time() - $vs->created_php_time;
if ($seconds_watching_video > $elapsedTime) {
$seconds_watching_video = $elapsedTime;
}
}
$vs->setLastVideoTime($lastVideoTime);
if(empty($lastVideoTime) && empty($seconds_watching_video) && !empty($lastStatistic)){
//error_log("updateStatistic: videos_id=$videos_id lastVideoTime=$lastVideoTime, seconds_watching_video=$seconds_watching_video line=" . __LINE__);
// do not save because there is already a record and it is saving 0
}else{
//error_log("updateStatistic: videos_id=$videos_id lastVideoTime=$lastVideoTime, seconds_watching_video=$seconds_watching_video line=" . __LINE__);
$vs->setLastVideoTime($lastVideoTime);
}
//var_dump($lastVideoTime);exit;
$vs->setIp(getRealIpAddr());
if (!empty($seconds_watching_video) && $seconds_watching_video > 0) {
//error_log("updateStatistic: videos_id=$videos_id lastVideoTime=$lastVideoTime, seconds_watching_video=$seconds_watching_video line=" . __LINE__);
$totalVideoWatched = $vs->getSeconds_watching_video() + $seconds_watching_video;
//_error_log("updateStatistic: add more [$seconds_watching_video] to video [$videos_id] " . get_browser_name());
$vs->setSeconds_watching_video($totalVideoWatched);
@ -124,6 +136,7 @@ class VideoStatistic extends ObjectYPT {
//$totalVideoSeconds = timeToSeconds($hms);
//Video::addViewPercent();
}
//error_log("updateStatistic: videos_id=$videos_id lastVideoTime=$lastVideoTime, seconds_watching_video=$seconds_watching_video line=" . __LINE__);
//if($videos_id==4){ _error_log("updateStatistic $videos_id, $users_id, $lastVideoTime, $seconds_watching_video ".json_encode($lastStatistic));}
$id = $vs->save();
/*
@ -176,19 +189,23 @@ class VideoStatistic extends ObjectYPT {
$params = [];
$sql .= " AND videos_id = ? AND ";
$formats = 'i';
$params[] = $videos_id;
if (!empty($users_id)) {
$sql .= " users_id = ? ";
$formats .= 'i';
$params[] = $users_id;
} else{
$sql .= " users_id IS NULL ";
if (!empty($session_id)) {
$conditions[] = "session_id = ? ";
$formats .= 's';
$params[] = $session_id;
}
if (!empty($ip)) {
$conditions[] = " ip = ? ";
$formats .= '2';
$params[] = $ip;
}
if(!empty($conditions)){
@ -200,7 +217,7 @@ class VideoStatistic extends ObjectYPT {
$sql .= " ORDER BY id DESC LIMIT 1";
$res = sqlDAL::readSql($sql, str_repeat('s', count($params)), $params, true);
$res = sqlDAL::readSql($sql, $formats, $params, true);
$result = sqlDAL::fetchAssoc($res);
sqlDAL::close($res);