From a6ac9edca001f16f8cb1eb28967c7e0264c92d77 Mon Sep 17 00:00:00 2001 From: Daniel Neto Date: Thu, 10 Aug 2023 14:39:00 -0300 Subject: [PATCH] showonFirstpage update --- install/checkConfiguration.php | 2 +- install/database.sql | 4 +- objects/functions.php | 2 + objects/playlist.php | 88 ++++++++++--- objects/playlistAddOnFirstPage.json.php | 26 ++++ objects/video.php | 124 +++++++++++-------- plugin/Gallery/Gallery.php | 4 + plugin/Gallery/view/mainArea.php | 54 ++++++-- plugin/PlayLists/View/getPlaylistButtons.php | 3 +- updatedb/updateDb.v12.9.sql | 8 +- view/channelPlaylistItems.php | 6 +- view/channelProgram.php | 39 +++++- 12 files changed, 262 insertions(+), 98 deletions(-) create mode 100644 objects/playlistAddOnFirstPage.json.php diff --git a/install/checkConfiguration.php b/install/checkConfiguration.php index c4428574c1..156a56febe 100644 --- a/install/checkConfiguration.php +++ b/install/checkConfiguration.php @@ -4,7 +4,7 @@ if (file_exists("../videos/configuration.php")) { exit; } -$installationVersion = "12.8"; +$installationVersion = "12.9"; error_log("Installation: ".__LINE__." ". json_encode($_POST)); header('Content-Type: application/json'); diff --git a/install/database.sql b/install/database.sql index 7cfd16cbcc..66e623b79d 100644 --- a/install/database.sql +++ b/install/database.sql @@ -501,10 +501,12 @@ CREATE TABLE IF NOT EXISTS `playlists` ( `modified` DATETIME NULL DEFAULT NULL, `users_id` INT(11) NOT NULL, `status` ENUM('public', 'private', 'unlisted', 'favorite', 'watch_later') NOT NULL DEFAULT 'public', - `showOnTV` TINYINT NULL, + `showOnTV` TINYINT NULL,, + `showOnFirstPage` TINYINT(1) UNSIGNED NULL DEFAULT 0, PRIMARY KEY (`id`), INDEX `fk_playlists_users1_idx` (`users_id` ASC), INDEX `showOnTVindex3` (`showOnTV` ASC), + INDEX `showonFirstpage` (`showOnFirstPage` ASC), CONSTRAINT `fk_playlists_users1` FOREIGN KEY (`users_id`) REFERENCES `users` (`id`) diff --git a/objects/functions.php b/objects/functions.php index 5278fab7d3..6d41c4701b 100644 --- a/objects/functions.php +++ b/objects/functions.php @@ -11382,7 +11382,9 @@ function modifyURL($url) 'ads_w' => 'ads.w', //player width 'ads_h' => 'ads.h', //player height 'app_store_url' => 'ads.app_store_url', //player height + 'ads_app_store_url' => 'ads.app_store_url', //player height 'app_name' => 'ads.app_name', //player height + 'ads_app_name' => 'ads.app_name', //player height 'ads_cb' => 'ads.cb', 'ads_channel_name' => 'ads.channel_name', 'ads_content_genre' => 'ads.content_genre', diff --git a/objects/playlist.php b/objects/playlist.php index da48b60f91..bbba17611c 100644 --- a/objects/playlist.php +++ b/objects/playlist.php @@ -16,6 +16,7 @@ class PlayList extends ObjectYPT { protected $users_id; protected $status; protected $showOnTV; + protected $showOnFirstPage; protected $modified; public static $validStatus = ['public', 'private', 'unlisted', 'favorite', 'watch_later']; @@ -85,9 +86,10 @@ class PlayList extends ObjectYPT { } $videosArrayId = PlayList::getVideosIdFromPlaylist($playlists_id); $videosP = Video::getAllVideos("viewable", false, true, $videosArrayId, false, true); - $videosP = PlayList::sortVideos($videosP, $videosArrayId); + //$videosP = PlayList::sortVideos($videosP, $videosArrayId); foreach ($videosP as $key => $value2) { if (empty($videosP[$key]['type'])) { + //echo 'unset ';var_dump($videosP[$key]); unset($videosP[$key]); continue; } @@ -101,6 +103,8 @@ class PlayList extends ObjectYPT { if ($videosP[$key]['type'] !== Video::$videoTypeLinkVideo) { $videosP[$key]['videos'] = Video::getVideosPaths($videosP[$key]['filename'], true); } + $videosP[$key]['playlists_id'] = $playlists_id; + $videosP[$key]['playlist_index'] = $key; } return $videosP; @@ -703,25 +707,31 @@ class PlayList extends ObjectYPT { } public static function sortVideos($videosList, $listIdOrder) { - $list = []; - foreach ($listIdOrder as $value) { - $found = false; - foreach ($videosList as $key => $value2) { - if ($value2['id'] == $value) { - $list[] = $value2; - unset($videosList[$key]); - $found = true; - } + usort($videosList, function($a, $b) use ($listIdOrder) { + // Get the index of the 'id' from the $listIdOrder array + $indexA = array_search($a['id'], $listIdOrder); + $indexB = array_search($b['id'], $listIdOrder); + + // If both IDs are found in $listIdOrder + if ($indexA !== false && $indexB !== false) { + return $indexA - $indexB; // Sort based on the order in $listIdOrder } - if (!$found) { - $v = new Video("", "", $value); - if (empty($v->getFilename())) { - continue; - } - $list[] = ['id' => $value]; + + // If $a['id'] is not found, it should come after $b + if ($indexA === false && $indexB !== false) { + return 1; } - } - return $list; + + // If $b['id'] is not found, it should come after $a + if ($indexB === false && $indexA !== false) { + return -1; + } + + // If neither ID is found, sort them based on their IDs + return $a['id'] - $b['id']; + }); + + return $videosList; } public function save() { @@ -734,6 +744,7 @@ class PlayList extends ObjectYPT { $this->setUsers_id($users_id); } $this->showOnTV = intval($this->showOnTV); + $this->showOnFirstPage = intval($this->showOnFirstPage); $playlists_id = parent::save(); if (!empty($playlists_id)) { self::deleteCacheDir($playlists_id); @@ -894,6 +905,19 @@ class PlayList extends ObjectYPT { $this->showOnTV = intval($showOnTV); } + public function getShowOnFirstPage() { + return intval($this->showOnFirstPage); + } + + public function setShowOnFirstPage($showOnFirstPage) { + if (strtolower($showOnFirstPage) === "false") { + $showOnFirstPage = 0; + } elseif (strtolower($showOnFirstPage) === "true") { + $showOnFirstPage = 1; + } + $this->showOnFirstPage = intval($showOnFirstPage); + } + public static function getAllToShowOnTV() { global $global; if (!static::isTableInstalled()) { @@ -921,6 +945,34 @@ class PlayList extends ObjectYPT { return $rows; } + + public static function getAllToShowOnFirstPage() { + global $global; + if (!static::isTableInstalled()) { + return false; + } + $sql = "SELECT u.*, pl.* FROM playlists pl " + . " LEFT JOIN users u ON users_id = u.id " + . " WHERE showOnFirstPage=1 "; + + //$sql .= self::getSqlFromPost(); + //echo $sql;exit; + $res = sqlDAL::readSql($sql); + $fullData = sqlDAL::fetchAllAssoc($res); + sqlDAL::close($res); + $rows = []; + if ($res !== false) { + foreach ($fullData as $row) { + $row = cleanUpRowFromDatabase($row); + $rows[] = $row; + } + } else { + //die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); + $rows = []; + } + return $rows; + } + public static function showPlayListSelector($playListArray) { $collections = []; $videos = []; diff --git a/objects/playlistAddOnFirstPage.json.php b/objects/playlistAddOnFirstPage.json.php new file mode 100644 index 0000000000..08b30ef02c --- /dev/null +++ b/objects/playlistAddOnFirstPage.json.php @@ -0,0 +1,26 @@ +playlist_id = $_REQUEST['playlist_id']; +$obj->showOnFirstPage = $_REQUEST['showOnFirstPage']; +$obj->msg = ''; + +$pl = new PlayList($_POST['playlist_id']); +$pl->setShowOnFirstPage($_REQUEST['showOnFirstPage']); +$obj->saved = $pl->save(); +$obj->error = empty($obj->saved); + +echo json_encode($obj); diff --git a/objects/video.php b/objects/video.php index 2b20fdc5cb..2bba4b13fd 100644 --- a/objects/video.php +++ b/objects/video.php @@ -1651,8 +1651,11 @@ if (!class_exists('Video')) { $sql .= " AND v.status = '{$status}'"; } */ - - $sql .= self::getSQLByStatus($status, $showUnlisted); + if (!empty($videosArrayId) && is_array($videosArrayId) && (is_numeric($videosArrayId[0]))) { + $sql .= " ORDER BY FIELD(v.id, '" . implode("', '", $videosArrayId) . "') "; + } else { + $sql .= self::getSQLByStatus($status, $showUnlisted); + } //var_dump($max_duration_in_seconds);echo $sql;exit; if (!empty($_REQUEST['catName'])) { $catName = ($_REQUEST['catName']); @@ -1711,59 +1714,60 @@ if (!class_exists('Video')) { } $sql .= AVideoPlugin::getVideoWhereClause(); - - if ($suggestedOnly) { - $sql .= " AND v.isSuggested = 1 AND v.status = '" . self::$statusActive . "' "; - $sql .= " ORDER BY RAND() "; - $sort = @$_POST['sort']; - unset($_POST['sort']); - $sql .= BootGrid::getSqlFromPost([], empty($_POST['sort']['likes']) ? "v." : "", "", true); - if (strpos(mb_strtolower($sql), 'limit') === false) { - $sql .= " LIMIT 60 "; - } - $_POST['sort'] = $sort; - } elseif (!isset($_POST['sort']['trending']) && !isset($_GET['sort']['trending'])) { - if (!empty($_POST['sort']['created']) && !empty($_POST['sort']['likes'])) { - $_POST['sort']['v.created'] = $_POST['sort']['created']; - unset($_POST['sort']['created']); - } - $sort = $_POST['sort']; - if (!empty($_POST['sort']['v.created']) || !empty($_POST['sort']['created'])) { - $created = !empty($_POST['sort']['v.created']) ? $_POST['sort']['v.created'] : $_POST['sort']['created']; + if (empty($videosArrayId)) { + if ($suggestedOnly) { + $sql .= " AND v.isSuggested = 1 AND v.status = '" . self::$statusActive . "' "; + $sql .= " ORDER BY RAND() "; + $sort = @$_POST['sort']; unset($_POST['sort']); - $_POST['sort'] = array(); - if (strtoupper($created) === 'DESC') { - $_POST['sort']['v.`order`'] = 'IS NOT NULL DESC'; - $_POST['sort']['`order`'] = 'ASC'; + $sql .= BootGrid::getSqlFromPost([], empty($_POST['sort']['likes']) ? "v." : "", "", true); + if (strpos(mb_strtolower($sql), 'limit') === false) { + $sql .= " LIMIT 60 "; + } + $_POST['sort'] = $sort; + } elseif (!isset($_POST['sort']['trending']) && !isset($_GET['sort']['trending'])) { + if (!empty($_POST['sort']['created']) && !empty($_POST['sort']['likes'])) { + $_POST['sort']['v.created'] = $_POST['sort']['created']; + unset($_POST['sort']['created']); + } + $sort = $_POST['sort']; + if (!empty($_POST['sort']['v.created']) || !empty($_POST['sort']['created'])) { + $created = !empty($_POST['sort']['v.created']) ? $_POST['sort']['v.created'] : $_POST['sort']['created']; + unset($_POST['sort']); + $_POST['sort'] = array(); + if (strtoupper($created) === 'DESC') { + $_POST['sort']['v.`order`'] = 'IS NOT NULL DESC'; + $_POST['sort']['`order`'] = 'ASC'; + } + + $_POST['sort']['v.created'] = $created; + } + //var_dump($_POST['sort']);exit; + $sql .= BootGrid::getSqlFromPost([], empty($_POST['sort']['likes']) ? "v." : "", "", true); + unset($_POST['sort']); + $_POST['sort'] = $sort; + //var_dump($sql);exit; + } else { + unset($_POST['sort']['trending'], $_GET['sort']['trending']); + $rows = []; + if (!empty($_REQUEST['current']) && $_REQUEST['current'] == 1) { + $rows = VideoStatistic::getVideosWithMoreViews($status, $showOnlyLoggedUserVideos, $showUnlisted, $suggestedOnly); + } + //var_dump($_REQUEST['current'], $rows); + $ids = []; + foreach ($rows as $row) { + $ids[] = $row['id']; } - $_POST['sort']['v.created'] = $created; - } - //var_dump($_POST['sort']);exit; - $sql .= BootGrid::getSqlFromPost([], empty($_POST['sort']['likes']) ? "v." : "", "", true); - unset($_POST['sort']); - $_POST['sort'] = $sort; - //var_dump($sql);exit; - } else { - unset($_POST['sort']['trending'], $_GET['sort']['trending']); - $rows = []; - if (!empty($_REQUEST['current']) && $_REQUEST['current'] == 1) { - $rows = VideoStatistic::getVideosWithMoreViews($status, $showOnlyLoggedUserVideos, $showUnlisted, $suggestedOnly); - } - //var_dump($_REQUEST['current'], $rows); - $ids = []; - foreach ($rows as $row) { - $ids[] = $row['id']; - } + //$daysLimit = getTrendingLimit(); - //$daysLimit = getTrendingLimit(); - - if (!empty($ids)) { - $sql .= " ORDER BY FIND_IN_SET(v.id, '" . implode(",", $ids) . "') DESC, likes DESC "; - } else { - $sql .= " ORDER BY likes DESC "; + if (!empty($ids)) { + $sql .= " ORDER BY FIND_IN_SET(v.id, '" . implode(",", $ids) . "') DESC, likes DESC "; + } else { + $sql .= " ORDER BY likes DESC "; + } + $sql .= ObjectYPT::getSqlLimit(); } - $sql .= ObjectYPT::getSqlLimit(); } if (strpos(mb_strtolower($sql), 'limit') === false) { if (!empty($_GET['limitOnceToOne'])) { @@ -1785,7 +1789,7 @@ if (!class_exists('Video')) { } } - //var_dump($max_duration_in_seconds);echo $sql;exit; + //var_dump($max_duration_in_seconds);echo $sql; //exit; //_error_log("getAllVideos($status, $showOnlyLoggedUserVideos , $ignoreGroup , ". json_encode($videosArrayId).")" . $sql); $timeLogName = TimeLogStart("video::getAllVideos"); @@ -3221,7 +3225,7 @@ if (!class_exists('Video')) { $tags = Video::getTags($video_id); $_getTagsHTMLLabelArray[$video_id] = []; - $valid_tags = [__("Paid Content"), __("Group"), __("Plugin"), __("Rating"),__("Pinned")]; + $valid_tags = [__("Paid Content"), __("Group"), __("Plugin"), __("Rating"), __("Pinned")]; foreach ($tags as $value2) { if (empty($value2->label) || empty($value2->text)) { continue; @@ -3326,7 +3330,7 @@ if (!class_exists('Video')) { $tags = []; if (empty($type) || $type === VideoTags::$TagTypePinned) { - if($video->getOrder()){ + if ($video->getOrder()) { $objTag = new stdClass(); $objTag->label = __("Pinned"); $objTag->type = "default"; @@ -6508,8 +6512,18 @@ if (!class_exists('Video')) { $galleryVideoButtons .= $galleryDropDownMenu . ''; } - $href = Video::getLink($video['id'], $video['clean_title']); - $embed = Video::getLink($video['id'], $video['clean_title'], true); + + if (!empty($video['playlists_id']) && isset($video['playlist_index'])) { + if (!class_exists('PlayLists')) { + AVideoPlugin::loadPlugin('PlayLists'); + } + $href = PlayLists::getLink($video['playlists_id'], false, $video['playlist_index']); + $embed = PlayLists::getLink($video['playlists_id'], true, $video['playlist_index']); + } else { + $href = Video::getLink($video['id'], $video['clean_title']); + $embed = Video::getLink($video['id'], $video['clean_title'], true); + } + $title = safeString($video['title']); $a = 'SuggestedRowCount = 12; $obj->SuggestedOrder = 1; + $obj->PlayLists = true; + $obj->PlayListsRowCount = 12; + $obj->PlayListsOrder = 2; + $obj->Trending = true; $obj->TrendingCustomTitle = ""; $obj->TrendingRowCount = 12; diff --git a/plugin/Gallery/view/mainArea.php b/plugin/Gallery/view/mainArea.php index 3fdfd744e7..4adc75004e 100644 --- a/plugin/Gallery/view/mainArea.php +++ b/plugin/Gallery/view/mainArea.php @@ -12,7 +12,7 @@ saveRequestVars(); $users_id_array = VideoStatistic::getUsersIDFromChannelsWithMoreViews(); $channels = Channel::getChannels(true, "u.id, '" . implode(",", $users_id_array) . "'"); if (!empty($channels)) { - ?> + ?>

@@ -28,7 +28,7 @@ saveRequestVars(); ?>
- doNotShowLiveOnVideosList)) { - ?> + ?>
- diff --git a/plugin/PlayLists/View/getPlaylistButtons.php b/plugin/PlayLists/View/getPlaylistButtons.php index 9ae764e2ee..1bf6355efa 100644 --- a/plugin/PlayLists/View/getPlaylistButtons.php +++ b/plugin/PlayLists/View/getPlaylistButtons.php @@ -21,6 +21,8 @@ if (empty($isASerie)) { } else { $currentSerieVideos_id = $isASerie['id']; } + +getSharePopupButton(0, "{$global['webSiteRootURL']}viewProgram/{$program['id']}/".urlencode($program['name']), $program['name'], 'btn-xs'); ?> " > @@ -72,7 +74,6 @@ if (PlayLists::canManagePlaylist($playlists_id)) { echo PlayLists::getShowOnTVSwitch($program['id']); if ($program['status'] != "favorite" && $program['status'] != "watch_later") { if (AVideoPlugin::isEnabledByName("PlayLists")) { - getSharePopupButton(0, "{$global['webSiteRootURL']}viewProgram/{$program['id']}/".urlencode($program['name']), $program['name'], 'btn-xs'); ?>