1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00

showonFirstpage update

This commit is contained in:
Daniel Neto 2023-08-10 14:39:00 -03:00
parent 7ac7481d5b
commit a6ac9edca0
12 changed files with 262 additions and 98 deletions

View file

@ -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');

View file

@ -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`)

View file

@ -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',

View file

@ -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 $a['id'] is not found, it should come after $b
if ($indexA === false && $indexB !== false) {
return 1;
}
if (!$found) {
$v = new Video("", "", $value);
if (empty($v->getFilename())) {
continue;
// If $b['id'] is not found, it should come after $a
if ($indexB === false && $indexA !== false) {
return -1;
}
$list[] = ['id' => $value];
}
}
return $list;
// 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 = [];

View file

@ -0,0 +1,26 @@
<?php
header('Content-Type: application/json');
global $global, $config;
if (!isset($global['systemRootPath'])) {
require_once '../videos/configuration.php';
}
require_once $global['systemRootPath'] . 'objects/user.php';
require_once $global['systemRootPath'] . 'objects/playlist.php';
if (!PlayLists::canManageAllPlaylists()) {
forbiddenPage('Permission denied');
}
if (empty($_REQUEST['playlist_id'])) {
forbiddenPage('playlist_id is empty');
}
$obj = new stdClass();
$obj->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);

View file

@ -1651,8 +1651,11 @@ if (!class_exists('Video')) {
$sql .= " AND v.status = '{$status}'";
}
*/
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,7 +1714,7 @@ if (!class_exists('Video')) {
}
$sql .= AVideoPlugin::getVideoWhereClause();
if (empty($videosArrayId)) {
if ($suggestedOnly) {
$sql .= " AND v.isSuggested = 1 AND v.status = '" . self::$statusActive . "' ";
$sql .= " ORDER BY RAND() ";
@ -1765,6 +1768,7 @@ if (!class_exists('Video')) {
}
$sql .= ObjectYPT::getSqlLimit();
}
}
if (strpos(mb_strtolower($sql), 'limit') === false) {
if (!empty($_GET['limitOnceToOne'])) {
$sql .= " LIMIT 1";
@ -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");
@ -6508,8 +6512,18 @@ if (!class_exists('Video')) {
$galleryVideoButtons .= $galleryDropDownMenu . '</div>';
}
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 = '<a videos_id="' . $videos_id . '"
href="' . $href . '"

View file

@ -84,6 +84,10 @@ class Gallery extends PluginAbstract
$obj->SuggestedRowCount = 12;
$obj->SuggestedOrder = 1;
$obj->PlayLists = true;
$obj->PlayListsRowCount = 12;
$obj->PlayListsOrder = 2;
$obj->Trending = true;
$obj->TrendingCustomTitle = "";
$obj->TrendingRowCount = 12;

View file

@ -70,6 +70,7 @@ saveRequestVars();
include $global['systemRootPath'] . 'plugin/Gallery/view/mainAreaCategory.php';
} else {
//var_dump($sections);exit;
foreach ($sections as $value) {
if (empty($value['active'])) {
continue;
@ -85,6 +86,37 @@ saveRequestVars();
if ($value['name'] == 'Suggested') {
createGallery(!empty($obj->SuggestedCustomTitle) ? $obj->SuggestedCustomTitle : __("Suggested"), 'suggested', $obj->SuggestedRowCount, 'SuggestedOrder', "", "", $orderString, "ASC", !$obj->hidePrivateVideos, "fas fa-star");
} else
if($value['name'] == 'PlayLists'){
$objPl = AVideoPlugin::getDataObject('PlayLists');
$plRows = PlayList::getAllToShowOnFirstPage();
//var_dump(count($plRows));exit;
if (!empty($plRows)) {
$rowCount = getRowCount();
setRowCount(12);
foreach ($plRows as $pl) {
?>
<!-- For Playlist -->
<div class="clear clearfix">
<h3 class="galleryTitle">
<a href="<?php echo "{$global['webSiteRootURL']}viewProgram/{$pl['id']}/" . urlencode($pl['name']); ?>">
<i class="fas fa-list"></i> <?php echo __($pl['name']); ?>
</a>
</h3>
<?php
$videos = PlayList::getAllFromPlaylistsID($pl['id']);
// need to add dechex because some times it return an negative value and make it fails on javascript playlists
?>
<div class="gallerySectionContent">
<?php
$countCols = createGallerySection($videos);
?>
</div>
</div>
<?php
}
setRowCount($rowCount);
}
}else
if ($value['name'] == 'Trending') {
createGallery(!empty($obj->TrendingCustomTitle) ? $obj->TrendingCustomTitle : __("Trending"), 'trending', $obj->TrendingRowCount, 'TrendingOrder', "zyx", "abc", $orderString, "ASC", !$obj->hidePrivateVideos, "fas fa-chart-line");
} else

View file

@ -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');
?>
<a href="<?php echo $link; ?>" class="btn btn-xs btn-default playAll hrefLink" data-toggle="tooltip" title="<?php echo __("Play All"); ?>" >
<span class="fa fa-play"></span> <span class="hidden-sm hidden-xs"><?php echo __("Play All"); ?></span>
@ -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');
?>
<button class="btn btn-xs btn-default" onclick="copyToClipboard($('#playListEmbedCode<?php echo $program['id']; ?>').val()); setTextEmbedCopied();" data-toggle="tooltip" title="<?php echo __("Copy Embed code"); ?>" >
<span class="fa fa-copy"></span> <span id="btnEmbedText" class="hidden-sm hidden-xs"><?php echo __("Embed code"); ?></span>

View file

@ -1,3 +1,5 @@
ALTER TABLE `configurations`
CHANGE COLUMN `language` `language` VARCHAR(25) NOT NULL DEFAULT 'en_US';
UPDATE configurations SET version = '12.8', modified = now() WHERE id = 1;
ALTER TABLE `playlists`
ADD COLUMN `showOnFirstPage` TINYINT(1) UNSIGNED NULL DEFAULT 0,
ADD INDEX `showonFirstpage` (`showOnFirstPage` ASC);
UPDATE configurations SET version = '12.9', modified = now() WHERE id = 1;

View file

@ -103,7 +103,7 @@ unset($_POST['current']);
@$timesC[__LINE__] += microtime(true) - $startC;
$startC = microtime(true);
//_error_log("channelPlaylist videosP: ".json_encode($videosP));
$videosP = PlayList::sortVideos($videosP, $videosArrayId);
//$videosP = PlayList::sortVideos($videosP, $videosArrayId);
@$timesC[__LINE__] += microtime(true) - $startC;
$startC = microtime(true);
//_error_log("channelPlaylist videosP2: ".json_encode($videosP));
@ -117,7 +117,8 @@ unset($_POST['current']);
<div class="panel-heading clearfix">
<div class="pull-left">
<strong style="font-size: 1.1em;" class="playlistName">
<?php echo __($playlist['name']); ?>
<!-- <?php echo basename(__FILE__); ?> -->
<a href="<?php echo "{$global['webSiteRootURL']}viewProgram/{$playlist['id']}/".urlencode($playlist['name']); ?>"><?php echo __($playlist['name']); ?></a>
</strong><br>
<small class="text-muted">
<?php echo seconds2human(PlayList::getTotalDurationFromPlaylistInSeconds($playlist['id'])); ?>
@ -131,7 +132,6 @@ unset($_POST['current']);
<?php
if (!empty($videosArrayId)) {
?>
<div class="panel-body">
<?php
$serie = PlayLists::isPlayListASerie($playlist['id']);

View file

@ -89,7 +89,7 @@ $playListsObj = AVideoPlugin::getObjectData("PlayLists");
@$timesC[__LINE__] += microtime(true) - $startC;
$startC = microtime(true);
//_error_log("channelPlaylist videosP: ".json_encode($videosP));
$videosP = PlayList::sortVideos($videosP, $videosArrayId);
//$videosP = PlayList::sortVideos($videosP, $videosArrayId);
@$timesC[__LINE__] += microtime(true) - $startC;
$startC = microtime(true);
//_error_log("channelPlaylist videosP2: ".json_encode($videosP));
@ -97,13 +97,19 @@ $playListsObj = AVideoPlugin::getObjectData("PlayLists");
@$timesC[__LINE__] += microtime(true) - $startC;
$startC = microtime(true);
$totalVideos = count($videosP);
$checked = '';
if(!empty($program['showOnFirstPage'])){
$checked = ' checked="checked" ';
}
?>
<br>
<div class="panel panel-default program" playListId="<?php echo $program['id']; ?>">
<div class="panel-heading clearfix">
<div class="panel-heading clearfix" style="padding-left: 10px;">
<span class="badge pull-right"><?php echo $totalVideos; ?> <?php echo __('Videos'); ?></span>
<div class="pull-left">
<strong style="font-size: 1.1em;" class="playlistName">
<!-- <?php echo basename(__FILE__); ?> -->
<?php echo __($program['name']); ?>
</strong><br>
<small class="text-muted">
@ -112,6 +118,20 @@ $playListsObj = AVideoPlugin::getObjectData("PlayLists");
</div>
<?php
PlayLists::getPLButtons($program['id'], false);
if (PlayLists::canManageAllPlaylists()) {
?>
<br>
<div class="pull-right" style="padding: 10px 0 0 0;">
<label for="addOnFirstPage<?php echo $program['id']; ?>">
<span style="margin-right: 10px;"><?php echo __('Add to first page'); ?></span>
</label>
<div class="material-small material-switch pull-right">
<input <?php echo $checked; ?> name="addOnFirstPage" id="addOnFirstPage<?php echo $program['id']; ?>" class="addOnFirstPage" type="checkbox" value="<?php echo $program['id']; ?>">
<label for="addOnFirstPage<?php echo $program['id']; ?>" class="label-success"></label>
</div>
</div>
<?php
}
?>
</div>
@ -318,6 +338,15 @@ $playListsObj = AVideoPlugin::getObjectData("PlayLists");
var currentObject;
$(function() {
$('.addOnFirstPage').on('change', function() {
url = webSiteRootURL + 'objects/playlistAddOnFirstPage.json.php';
var playlist_id = $(this).val();
var showOnFirstPage = $(this).prop('checked');
avideoAjax(url, {
playlist_id: playlist_id,
showOnFirstPage: showOnFirstPage
});
});
<?php
if (count($programs) <= 1 || !empty($palyListsObj->expandPlayListOnChannels)) {
?>
@ -343,7 +372,7 @@ $playListsObj = AVideoPlugin::getObjectData("PlayLists");
var playlist_id = $(currentObject).attr('playlist_id');
var video_id = $(currentObject).attr('video_id');
$.ajax({
url: '<?php echo $global['webSiteRootURL']; ?>objects/playlistRemoveVideo.php',
url: webSiteRootURL + 'objects/playlistRemoveVideo.php',
data: {
"playlist_id": playlist_id,
"video_id": video_id