1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +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) . ")"; $sql .= " VALUES (" . implode(", ", $fields) . ")";
} }
//error_log("save: $sql [$formats]".json_encode($values));
//var_dump(static::getTableName(), $sql, $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; //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; //echo $sql;var_dump($this, $values);exit;
@ -402,6 +403,7 @@ abstract class ObjectYPT implements ObjectInterface
return $id; return $id;
} else { } 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 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; return false;
} }
} }

View file

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

View file

@ -90,11 +90,11 @@ if (empty($_SESSION['addViewCount'][$_REQUEST['id']]['time'])) {
} }
if (isset($_REQUEST['currentTime'])) { if (isset($_REQUEST['currentTime'])) {
$currentTime = intval($_REQUEST['currentTime']); $obj2->currentTime = intval($_REQUEST['currentTime']);
if ($currentTime < 0) { if ($obj2->currentTime < 0) {
$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 { } else {
$resp = 0; $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) { 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()){ if(isBot()){
//error_log("updateStatistic: videos_id=$videos_id lastVideoTime=$lastVideoTime, seconds_watching_video=$seconds_watching_video line=" . __LINE__);
return false; return false;
} }
$lastStatistic = self::getLastStatistics($videos_id, $users_id, getRealIpAddr(), session_id()); $lastStatistic = self::getLastStatistics($videos_id, $users_id, getRealIpAddr(), session_id());
if (empty($lastStatistic)) { 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 = new VideoStatistic(0);
$vs->setUsers_id($users_id); $vs->setUsers_id($users_id);
$vs->setVideos_id($videos_id); $vs->setVideos_id($videos_id);
$vs->setWhen(date("Y-m-d h:i:s")); $vs->setWhen(date("Y-m-d h:i:s"));
} else { } else {
//error_log("updateStatistic: videos_id=$videos_id lastVideoTime=$lastVideoTime, seconds_watching_video=$seconds_watching_video line=" . __LINE__);
$vs = new VideoStatistic($lastStatistic['id']); $vs = new VideoStatistic($lastStatistic['id']);
$elapsedTime = time() - $vs->created_php_time; $elapsedTime = time() - $vs->created_php_time;
if ($seconds_watching_video > $elapsedTime) { if ($seconds_watching_video > $elapsedTime) {
$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()); $vs->setIp(getRealIpAddr());
if (!empty($seconds_watching_video) && $seconds_watching_video > 0) { 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; $totalVideoWatched = $vs->getSeconds_watching_video() + $seconds_watching_video;
//_error_log("updateStatistic: add more [$seconds_watching_video] to video [$videos_id] " . get_browser_name()); //_error_log("updateStatistic: add more [$seconds_watching_video] to video [$videos_id] " . get_browser_name());
$vs->setSeconds_watching_video($totalVideoWatched); $vs->setSeconds_watching_video($totalVideoWatched);
@ -124,6 +136,7 @@ class VideoStatistic extends ObjectYPT {
//$totalVideoSeconds = timeToSeconds($hms); //$totalVideoSeconds = timeToSeconds($hms);
//Video::addViewPercent(); //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));} //if($videos_id==4){ _error_log("updateStatistic $videos_id, $users_id, $lastVideoTime, $seconds_watching_video ".json_encode($lastStatistic));}
$id = $vs->save(); $id = $vs->save();
/* /*
@ -176,19 +189,23 @@ class VideoStatistic extends ObjectYPT {
$params = []; $params = [];
$sql .= " AND videos_id = ? AND "; $sql .= " AND videos_id = ? AND ";
$formats = 'i';
$params[] = $videos_id; $params[] = $videos_id;
if (!empty($users_id)) { if (!empty($users_id)) {
$sql .= " users_id = ? "; $sql .= " users_id = ? ";
$formats .= 'i';
$params[] = $users_id; $params[] = $users_id;
} else{ } else{
$sql .= " users_id IS NULL "; $sql .= " users_id IS NULL ";
if (!empty($session_id)) { if (!empty($session_id)) {
$conditions[] = "session_id = ? "; $conditions[] = "session_id = ? ";
$formats .= 's';
$params[] = $session_id; $params[] = $session_id;
} }
if (!empty($ip)) { if (!empty($ip)) {
$conditions[] = " ip = ? "; $conditions[] = " ip = ? ";
$formats .= '2';
$params[] = $ip; $params[] = $ip;
} }
if(!empty($conditions)){ if(!empty($conditions)){
@ -200,7 +217,7 @@ class VideoStatistic extends ObjectYPT {
$sql .= " ORDER BY id DESC LIMIT 1"; $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); $result = sqlDAL::fetchAssoc($res);
sqlDAL::close($res); sqlDAL::close($res);