diff --git a/install/checkConfiguration.php b/install/checkConfiguration.php index 79e752bcc4..b94063e5f0 100644 --- a/install/checkConfiguration.php +++ b/install/checkConfiguration.php @@ -4,7 +4,7 @@ if (file_exists("../videos/configuration.php")) { exit; } -$installationVersion = "11.1"; +$installationVersion = "11.2"; error_log("Installation: ".__LINE__." ". json_encode($_POST)); header('Content-Type: application/json'); diff --git a/install/database.sql b/install/database.sql index 8bc5a52b89..dd0bee61ec 100644 --- a/install/database.sql +++ b/install/database.sql @@ -150,6 +150,7 @@ CREATE TABLE IF NOT EXISTS `videos` ( `filepath` VARCHAR(255) NULL DEFAULT NULL, `filesize` BIGINT(19) UNSIGNED NULL DEFAULT 0, `live_transmitions_history_id` INT(11) NULL DEFAULT NULL, + `total_seconds_watching` INT(11) NULL DEFAULT 0, PRIMARY KEY (`id`), INDEX `fk_videos_users_idx` (`users_id` ASC), INDEX `fk_videos_categories1_idx` (`categories_id` ASC), @@ -162,6 +163,7 @@ CREATE TABLE IF NOT EXISTS `videos` ( INDEX `video_status_idx` (`status` ASC), INDEX `video_type_idx` (`type` ASC) , INDEX `fk_videos_live_transmitions_history1_idx` (`live_transmitions_history_id` ASC), + INDEX `total_sec_watchinindex` (`total_seconds_watching` ASC), FULLTEXT INDEX `index17vname` (`title`), FULLTEXT INDEX `index18vdesc` (`description`), CONSTRAINT `fk_videos_sites1` @@ -307,11 +309,13 @@ CREATE TABLE IF NOT EXISTS `videos_statistics` ( `modified` DATETIME NULL DEFAULT NULL, `lastVideoTime` INT(11) NULL DEFAULT NULL, `session_id` VARCHAR(45) NOT NULL, + `seconds_watching_video` INT(11) NULL DEFAULT NULL, PRIMARY KEY (`id`), INDEX `fk_videos_statistics_users1_idx` (`users_id` ASC), INDEX `fk_videos_statistics_videos1_idx` (`videos_id` ASC), INDEX `when_statisci` (`when` ASC), INDEX `session_id_statistics` (`session_id` ASC), + INDEX `sec_watchin_videos` (`seconds_watching_video` ASC), CONSTRAINT `fk_videos_statistics_users1` FOREIGN KEY (`users_id`) REFERENCES `users` (`id`) diff --git a/objects/functions.php b/objects/functions.php index 2ac6958be2..1c2c77cb1f 100644 --- a/objects/functions.php +++ b/objects/functions.php @@ -2157,7 +2157,7 @@ function combineFiles($filesArray, $extension = "js") { $str = ""; $fileName = ""; foreach ($filesArray as $value) { - $fileName .= $value.filectime($global['systemRootPath'] . $value).filemtime($global['systemRootPath'] . $value); + $fileName .= $value . filectime($global['systemRootPath'] . $value) . filemtime($global['systemRootPath'] . $value); } if ($advancedCustom != false) { $minifyEnabled = $advancedCustom->EnableMinifyJS; @@ -2543,7 +2543,7 @@ function isMobile($userAgent = null, $httpHeaders = null) { return $detect->isMobile($userAgent, $httpHeaders); } -function isChannelPage(){ +function isChannelPage() { return strpos($_SERVER["SCRIPT_NAME"], 'view/channel.php') !== false; } @@ -5174,8 +5174,8 @@ function getPagination($total, $page = 0, $link = "", $maxVisible = 10, $infinit if (preg_match("/(current=[0-9]+)/i", $link, $match)) { $link = str_replace($match[1], "current={page}", $link); } else { - $link = addQueryStringParameter($link, 'current', '{page}'); - //$link .= (parse_url($link, PHP_URL_QUERY) ? '&' : '?') . 'current={page}'; + //$link = addQueryStringParameter($link, 'current', '{page}'); + $link .= (parse_url($link, PHP_URL_QUERY) ? '&' : '?') . 'current={page}'; } } @@ -6292,7 +6292,7 @@ function getStatsNotifications($force_recreate = false) { $json = ObjectYPT::getCache($cacheName, 0, true); } if (empty($json)) { - _error_log('getStatsNotifications: 1 ' . json_encode(debug_backtrace())); + //_error_log('getStatsNotifications: 1 ' . json_encode(debug_backtrace())); $json = Live::getStats(); $json = object_to_array($json); @@ -7003,3 +7003,31 @@ function number_format_short($n, $precision = 1) { return $n_format . $suffix; } + +function seconds2human($ss) { + $s = $ss % 60; + $m = floor(($ss % 3600) / 60); + $h = floor(($ss % 86400) / 3600); + $d = floor(($ss % 2592000) / 86400); + $M = floor($ss / 2592000); + + $times = array(); + + if(!empty($M)){ + $times[] = "$M ".__('m'); + } + if(!empty($d)){ + $times[] = "$d ".__('d'); + } + if(!empty($h)){ + $times[] = "$h ".__('h'); + } + if(!empty($m)){ + $times[] = "$m ".__('min'); + } + if(!empty($s)){ + $times[] = "$s ".__('sec'); + } + + return implode(', ', $times); +} diff --git a/objects/video.php b/objects/video.php index 30e7611f57..4880ef561d 100644 --- a/objects/video.php +++ b/objects/video.php @@ -57,6 +57,7 @@ if (!class_exists('Video')) { private $filepath; private $filesize; private $live_transmitions_history_id; + private $total_seconds_watching; public static $statusDesc = array( 'a' => 'Active', 'k' => 'Active and Encoding', @@ -117,6 +118,23 @@ if (!class_exists('Video')) { } die($sql . ' Error : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } + + public function addSecondsWatching($seconds_watching) { + global $global; + + $seconds_watching = intval($seconds_watching); + + if(empty($seconds_watching)){ + return false; + } + + if (empty($this->id)) { + return false; + } + $sql = "UPDATE videos SET total_seconds_watching = total_seconds_watching+{$seconds_watching}, modified = now() WHERE id = ?"; + _error_log($sql."={$this->id}"); + return sqlDAL::writeSql($sql, "i", array($this->id)); + } public function updateViewsCount($total) { global $global; @@ -1203,6 +1221,8 @@ if (!class_exists('Video')) { $row['isWatchLater'] = self::isWatchLater($row['id']); $row['favoriteId'] = self::getFavoriteIdFromUser(User::getId()); $row['watchLaterId'] = self::getWatchLaterIdFromUser(User::getId()); + $row['total_seconds_watching_human'] = seconds2human($row['total_seconds_watching']); + $row['views_count_short'] = number_format_short($row['views_count']); if (empty($row['externalOptions'])) { $row['externalOptions'] = json_encode(array('videoStartSeconds' => '00:00:00')); @@ -4492,7 +4512,15 @@ if (!class_exists('Video')) { $btnHTML = str_replace($search, $replace, $content); return $btnHTML; } + + function getTotal_seconds_watching() { + return $this->total_seconds_watching; + } + function setTotal_seconds_watching($total_seconds_watching) { + $this->total_seconds_watching = $total_seconds_watching; + } + } } diff --git a/objects/videoAddViewCount.json.php b/objects/videoAddViewCount.json.php index 8ff67db608..e8845bdd77 100644 --- a/objects/videoAddViewCount.json.php +++ b/objects/videoAddViewCount.json.php @@ -52,8 +52,17 @@ if (empty($_SESSION['addViewCount'][$_REQUEST['id']]['time'])) { $resp = $obj->addView(); _session_start(); $_SESSION['addViewCount'][$_REQUEST['id']]['time'] = strtotime("+{$seconds} seconds"); -} elseif (!empty($_REQUEST['currentTime'])) { - $resp = VideoStatistic::updateStatistic($obj->getId(), User::getId(), intval($_REQUEST['currentTime'])); +} elseif (isset($_REQUEST['currentTime'])) { + $currentTime = intval($_REQUEST['currentTime']); + if($currentTime<0){ + $currentTime = 0; + } + $seconds_watching_video = intval(@$_REQUEST['seconds_watching_video']); + if($seconds_watching_video<0){ + $seconds_watching_video = 0; + } + + $resp = VideoStatistic::updateStatistic($obj->getId(), User::getId(), $currentTime, $seconds_watching_video); } else { $resp = 0; } diff --git a/objects/video_statistic.php b/objects/video_statistic.php index 55abb06a48..1df74b8a0e 100644 --- a/objects/video_statistic.php +++ b/objects/video_statistic.php @@ -19,6 +19,7 @@ class VideoStatistic extends ObjectYPT { protected $videos_id; protected $lastVideoTime; protected $session_id; + protected $seconds_watching_video; public static function getSearchFieldsNames() { return array(); @@ -69,7 +70,7 @@ class VideoStatistic extends ObjectYPT { } } - public static function updateStatistic($videos_id, $users_id, $lastVideoTime) { + public static function updateStatistic($videos_id, $users_id, $lastVideoTime, $seconds_watching_video=0) { $lastStatistic = self::getLastStatistics($videos_id, $users_id); if (empty($lastStatistic)) { $vs = new VideoStatistic(0); @@ -80,7 +81,26 @@ class VideoStatistic extends ObjectYPT { $vs = new VideoStatistic($lastStatistic['id']); } $vs->setLastVideoTime($lastVideoTime); - return $vs->save(); + + if(!empty($seconds_watching_video) && $seconds_watching_video > 0){ + $totalVideoWatched = $vs->getSeconds_watching_video()+$seconds_watching_video; + $vs->setSeconds_watching_video($totalVideoWatched); + $v = new Video('', '', $videos_id); + $v->addSecondsWatching($seconds_watching_video); + + //$totalVideoSeconds = timeToSeconds($hms); + + //Video::addViewPercent(); + + } + + $id = $vs->save(); + /* + if(!empty($id)){ + Video::clearCache($videos_id); + } + */ + return $id; } public function save() { @@ -460,5 +480,70 @@ class VideoStatistic extends ObjectYPT { _error_log("Id for table " . static::getTableName() . " not defined for deletion", AVideoLog::$ERROR); return false; } + + function getSeconds_watching_video() { + return intval($this->seconds_watching_video); + } + + function setSeconds_watching_video($seconds_watching_video) { + $this->seconds_watching_video = intval($seconds_watching_video); + } + + + + public static function getAllFromVideos_id($videos_id) { + global $global; + if (!static::isTableInstalled()) { + return false; + } + + $videos_id = intval($videos_id); + + if(empty($videos_id)){ + return false; + } + + $sql = "SELECT * FROM " . static::getTableName() . " WHERE videos_id=$videos_id "; + + $sql .= self::getSqlFromPost(); + //echo $sql;//exit; + $res = sqlDAL::readSql($sql); + $fullData = sqlDAL::fetchAllAssoc($res); + sqlDAL::close($res); + $rows = array(); + if ($res != false) { + foreach ($fullData as $row) { + $rows[] = $row; + } + } else { + die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); + } + return $rows; + } + + public static function getTotalFromVideos_id($videos_id) { + global $global; + if (!static::isTableInstalled()) { + return false; + } + + $videos_id = intval($videos_id); + + if(empty($videos_id)){ + return false; + } + + $sql = "SELECT count(id) as total FROM " . static::getTableName() . " WHERE videos_id=$videos_id "; + + $sql .= self::getSqlSearchFromPost(); + + //echo $sql;//exit; + $res = sqlDAL::readSql($sql); + $result = sqlDAL::fetchAssoc($res); + if (!empty($result)) { + return intval($result['total']); + } + return 0; + } } diff --git a/plugin/PlayerSkins/PlayerSkins.php b/plugin/PlayerSkins/PlayerSkins.php index ac2204fef7..d0f8a998df 100644 --- a/plugin/PlayerSkins/PlayerSkins.php +++ b/plugin/PlayerSkins/PlayerSkins.php @@ -373,7 +373,7 @@ class PlayerSkins extends PluginAbstract { if (empty($currentTime) && isVideoPlayerHasProgressBar()) { $currentTime = self::getCurrentTime(); } - + if (!empty($global['doNotLoadPlayer'])) { return ''; } @@ -384,7 +384,6 @@ class PlayerSkins extends PluginAbstract { if (empty($prepareStartPlayerJS_getDataSetup)) { $prepareStartPlayerJS_getDataSetup = array(); } - if (empty($noReadyFunction)) { $js .= "var originalVideo; var adTagOptions; @@ -471,9 +470,9 @@ class PlayerSkins extends PluginAbstract { $videos_id = getVideos_id(); if (!empty($videos_id)) { $video = Video::getVideoLight($videos_id); - $progress = Video::getVideoPogressPercent($videos_id); + $progress = Video::getVideoPogressPercent($videos_id); if (!empty($progress) && !empty($progress['lastVideoTime'])) { - $currentTime = intval($video['progress']['lastVideoTime']); + $currentTime = intval($progress['lastVideoTime']); } else if (!empty($video['externalOptions'])) { $json = _json_decode($video['externalOptions']); if (!empty($json->videoStartSeconds)) { diff --git a/updatedb/updateDb.v11.2.sql b/updatedb/updateDb.v11.2.sql new file mode 100644 index 0000000000..8c86773679 --- /dev/null +++ b/updatedb/updateDb.v11.2.sql @@ -0,0 +1,17 @@ +SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; +SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; +SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES'; + +ALTER TABLE `videos` +ADD COLUMN `total_seconds_watching` INT(11) NULL DEFAULT 0 AFTER `live_transmitions_history_id`, +ADD INDEX `total_sec_watchinindex` (`total_seconds_watching` ASC); + +ALTER TABLE `videos_statistics` +ADD COLUMN `seconds_watching_video` INT(11) NULL DEFAULT NULL AFTER `session_id`, +ADD INDEX `sec_watchin_videos` (`seconds_watching_video` ASC); + +SET SQL_MODE=@OLD_SQL_MODE; +SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; +SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; + +UPDATE configurations SET version = '11.2', modified = now() WHERE id = 1; \ No newline at end of file diff --git a/view/js/script.js b/view/js/script.js index 3ff8438da3..f03874fb44 100644 --- a/view/js/script.js +++ b/view/js/script.js @@ -170,6 +170,9 @@ lazyImage(); var pleaseWaitIsINUse = false; var pauseIfIsPlayinAdsInterval; +var seconds_watching_video = 0; +var _startCountPlayingTime; + function setPlayerListners() { if (typeof player !== 'undefined') { player.on('pause', function () { @@ -177,6 +180,7 @@ function setPlayerListners() { console.log("setPlayerListners: pause"); //userIsControling = true; clearInterval(pauseIfIsPlayinAdsInterval); + clearInterval(_startCountPlayingTime); }); player.on('play', function () { @@ -187,6 +191,9 @@ function setPlayerListners() { pauseIfIsPlayinAdsInterval = setInterval(function () { pauseIfIsPlayinAds(); }, 500); + _startCountPlayingTime = setInterval(function(){ + seconds_watching_video++; + },1000); }); $("#mainVideo .vjs-mute-control").click(function () { @@ -436,7 +443,6 @@ function addView(videos_id, currentTime) { } videoViewAdded = videos_id; - last_videos_id = videos_id; last_currentTime = currentTime; _addView(videos_id, currentTime); @@ -447,6 +453,7 @@ function addViewBeacon() { var url = webSiteRootURL + 'objects/videoAddViewCount.json.php?PHPSESSID=' + PHPSESSID; url = addGetParam(url, 'id', mediaId); url = addGetParam(url, 'currentTime', player.currentTime()); + url = addGetParam(url, 'seconds_watching_video', seconds_watching_video); var beacon = new Image(); beacon.src = url; } diff --git a/view/managerVideos_body.php b/view/managerVideos_body.php index 8f5821b086..743bf3ffd0 100644 --- a/view/managerVideos_body.php +++ b/view/managerVideos_body.php @@ -290,16 +290,19 @@
User | +When | +Time | +
---|---|---|
+ + | ++ + | ++ + | +User | +When | +Time | + +