mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-06 03:50:04 +02:00
Option to clone playlist
This commit is contained in:
parent
7a431e1ac6
commit
53f58c358b
5 changed files with 139 additions and 40 deletions
|
@ -84,6 +84,7 @@ function _error_log_debug($message, $show_args = false)
|
|||
function _error_log($message, $type = 0, $doNotRepeat = false)
|
||||
{
|
||||
if(isSchedulerRun()){
|
||||
echo $message.PHP_EOL;
|
||||
return false;
|
||||
}
|
||||
if (empty($doNotRepeat)) {
|
||||
|
|
|
@ -159,10 +159,10 @@ class PlayList extends ObjectYPT
|
|||
}
|
||||
}
|
||||
|
||||
if(!empty($_REQUEST['searchPlaylist'])){
|
||||
if (!empty($_REQUEST['searchPlaylist'])) {
|
||||
$sql .= " AND pl.name LIKE CONCAT('%', ?, '%') ";
|
||||
$formats .= "s";
|
||||
$values[] = $_REQUEST['searchPlaylist'];
|
||||
$values[] = trim($_REQUEST['searchPlaylist']);
|
||||
}
|
||||
|
||||
$sql .= self::getSqlFromPost("pl.");
|
||||
|
@ -291,11 +291,11 @@ class PlayList extends ObjectYPT
|
|||
}
|
||||
}
|
||||
$sql .= self::getSqlSearchFromPost("pl.");
|
||||
|
||||
if(!empty($_REQUEST['searchPlaylist'])){
|
||||
|
||||
if (!empty($_REQUEST['searchPlaylist'])) {
|
||||
$sql .= " AND pl.name LIKE CONCAT('%', ?, '%') ";
|
||||
$formats .= "s";
|
||||
$values[] = $_REQUEST['searchPlaylist'];
|
||||
$values[] = trim($_REQUEST['searchPlaylist']);
|
||||
}
|
||||
$res = sqlDAL::readSql($sql, $formats, $values, $refreshCacheFromPlaylist);
|
||||
$row = sqlDAL::fetchAssoc($res);
|
||||
|
@ -326,8 +326,8 @@ class PlayList extends ObjectYPT
|
|||
$sql .= " LEFT JOIN videos v ON pl.id = serie_playlists_id ";
|
||||
}
|
||||
$sql .= " LEFT JOIN users u ON u.id = pl.users_id WHERE 1=1 ";
|
||||
|
||||
if($includeSeries && isForKidsSet()){
|
||||
|
||||
if ($includeSeries && isForKidsSet()) {
|
||||
$sql .= " AND v.made_for_kids = 1 ";
|
||||
}
|
||||
if (!empty($playlists_id)) {
|
||||
|
@ -930,7 +930,8 @@ class PlayList extends ObjectYPT
|
|||
return sqlDAL::writeSql($sql);
|
||||
}
|
||||
|
||||
static function getNextOrder($playlists_id){
|
||||
static function getNextOrder($playlists_id)
|
||||
{
|
||||
$sql = 'SELECT MAX(`order`) AS max_order
|
||||
FROM playlists_has_videos
|
||||
WHERE playlists_id = ? ';
|
||||
|
@ -939,10 +940,10 @@ class PlayList extends ObjectYPT
|
|||
$row = sqlDAL::fetchAssoc($res);
|
||||
sqlDAL::close($res);
|
||||
$max_order = 0;
|
||||
if(!empty($row['max_order'])){
|
||||
if (!empty($row['max_order'])) {
|
||||
$max_order = intval($row['max_order']);
|
||||
}
|
||||
return ($max_order+1);
|
||||
return ($max_order + 1);
|
||||
}
|
||||
|
||||
public function addVideo($videos_id, $add, $order = 0, $_deleteCache = true)
|
||||
|
@ -952,7 +953,7 @@ class PlayList extends ObjectYPT
|
|||
$this->id = intval($this->id);
|
||||
$videos_id = intval($videos_id);
|
||||
$order = intval($order);
|
||||
|
||||
|
||||
if (empty($this->id) || empty($videos_id)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -966,7 +967,7 @@ class PlayList extends ObjectYPT
|
|||
$values[] = $videos_id;
|
||||
} else {
|
||||
$this->addVideo($videos_id, false, 0, false);
|
||||
if(empty($order)){
|
||||
if (empty($order)) {
|
||||
$order = self::getNextOrder($this->id);
|
||||
}
|
||||
$sql = "INSERT INTO playlists_has_videos ( playlists_id, videos_id , `order`) VALUES (?, ?, ?) ";
|
||||
|
@ -992,7 +993,7 @@ class PlayList extends ObjectYPT
|
|||
{
|
||||
$cacheHandler = new PlayListCacheHandler($playlists_id);
|
||||
$cacheHandler->deleteCache();
|
||||
|
||||
|
||||
$pl = new PlayList($playlists_id);
|
||||
$cacheHandler = new PlayListUserCacheHandler($pl->getUsers_id());
|
||||
$cacheHandler->deleteCache();
|
||||
|
@ -1076,7 +1077,7 @@ class PlayList extends ObjectYPT
|
|||
{
|
||||
global $playListCanSee;
|
||||
$index = "$playlist_id, $users_id";
|
||||
if(isset($playListCanSe[$index])){
|
||||
if (isset($playListCanSe[$index])) {
|
||||
return $playListCanSe[$index];
|
||||
}
|
||||
$playListCanSe[$index] = true;
|
||||
|
@ -1242,4 +1243,39 @@ class PlayList extends ObjectYPT
|
|||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
public static function clone($playlists_id)
|
||||
{
|
||||
// Modify the name to include " (Clone)"
|
||||
$sql = "INSERT INTO playlists (name, created, modified, users_id, status, showOnTV, showOnFirstPage)
|
||||
SELECT
|
||||
CONCAT(name, ' (Clone)') AS name,
|
||||
NOW() AS created,
|
||||
NOW() AS modified,
|
||||
users_id,
|
||||
status,
|
||||
showOnTV,
|
||||
showOnFirstPage
|
||||
FROM
|
||||
playlists
|
||||
WHERE
|
||||
id = ?";
|
||||
|
||||
$new_playlist_id = sqlDAL::writeSql($sql, 'i', [$playlists_id]);
|
||||
|
||||
// Clone the videos associated with the playlist
|
||||
$sql = "INSERT INTO playlists_has_videos (playlists_id, videos_id, `order`)
|
||||
SELECT
|
||||
? AS playlists_id,
|
||||
videos_id,
|
||||
`order`
|
||||
FROM
|
||||
playlists_has_videos
|
||||
WHERE
|
||||
playlists_id = ?";
|
||||
|
||||
sqlDAL::writeSql($sql, 'ii', [$new_playlist_id, $playlists_id]);
|
||||
|
||||
return $new_playlist_id;
|
||||
}
|
||||
}
|
||||
|
|
41
plugin/PlayLists/clone.json.php
Normal file
41
plugin/PlayLists/clone.json.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
global $global, $config;
|
||||
if (!isset($global['systemRootPath'])) {
|
||||
require_once '../../videos/configuration.php';
|
||||
}
|
||||
require_once $global['systemRootPath'] . 'objects/playlist.php';
|
||||
require_once $global['systemRootPath'] . 'objects/configuration.php';
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$obj = new stdClass();
|
||||
$obj->error = true;
|
||||
$obj->msg = "";
|
||||
|
||||
if(!User::isLogged()){
|
||||
forbiddenPage('Must login');
|
||||
}
|
||||
|
||||
$users_id = User::getId();
|
||||
|
||||
$playlistPlugin = AVideoPlugin::getObjectDataIfEnabled('PlayLists');
|
||||
|
||||
if (empty($playlistPlugin)) {
|
||||
forbiddenPage('Programs plugin not enabled');
|
||||
}
|
||||
|
||||
$playlists_id = intval($_REQUEST['playlists_id']);
|
||||
if (empty($playlists_id)) {
|
||||
forbiddenPage('Programs id error');
|
||||
}
|
||||
|
||||
$pl = new PlayList($playlists_id);
|
||||
if (User::getId() != $pl->getUsers_id() && !User::isAdmin()) {
|
||||
forbiddenPage('Programs does not belong to you');
|
||||
}
|
||||
|
||||
$obj->new_playlist_id = PlayList::clone($playlists_id);
|
||||
|
||||
$obj->error = empty($obj->new_playlist_id);
|
||||
|
||||
die(json_encode($obj));
|
|
@ -106,7 +106,7 @@ $_page = new Page(array('Manage playlist'));
|
|||
<li class="pull-right ">
|
||||
<form class="navbar-form form-inline input-group" role="search" id="searchFormPlaylist" method="get">
|
||||
<input type="search" id="searchPlaylist" name="searchPlaylist" placeholder="<?php echo __('Search Playlist'); ?>" class="form-control" value="<?php echo @$_REQUEST['searchPlaylist']; ?>" autocomplete="off">
|
||||
<input type="hidden" name="PlaylistOwnerUsersId" value="<?php echo @$_REQUEST['PlaylistOwnerUsersId']; ?>" >
|
||||
<input type="hidden" name="PlaylistOwnerUsersId" value="<?php echo @$_REQUEST['PlaylistOwnerUsersId']; ?>">
|
||||
<span class="input-group-append">
|
||||
<button class="btn btn-default btn-outline-secondary border-right-0 border py-2 faa-parent animated-hover" type="submit" id="buttonSearchPlaylist">
|
||||
<i class="fas fa-search faa-shake"></i>
|
||||
|
@ -153,7 +153,7 @@ $_page = new Page(array('Manage playlist'));
|
|||
?>
|
||||
<div class="col-sm-6 col-md-4 col-lg-3 pl pl<?php echo $value["id"]; ?> <?php echo implode(' ', $classes) ?>">
|
||||
<div class="panel panel-<?php echo $totalSubPlaylists ? 'primary' : 'default'; ?>">
|
||||
<div class="panel-heading">
|
||||
<div class="panel-heading clearfix">
|
||||
<?php
|
||||
echo "[{$value["id"]}] ";
|
||||
if (!empty($totalSubPlaylists)) {
|
||||
|
@ -174,6 +174,9 @@ $_page = new Page(array('Manage playlist'));
|
|||
<button type="button" class="btn btn-default btn-xs editBtn " onclick="editPlayList(<?php echo $value['id']; ?>);" data-toggle="tooltip" title="<?php echo __('Edit'); ?>">
|
||||
<i class="fas fa-edit"></i>
|
||||
</button>
|
||||
<button type="button" class="btn btn-default btn-xs cloneBtn " onclick="clonePlayList(<?php echo $value['id']; ?>);" data-toggle="tooltip" title="<?php echo __('Clone'); ?>">
|
||||
<i class="fa-regular fa-clone"></i>
|
||||
</button>
|
||||
<?php
|
||||
echo PlayLists::scheduleLiveButton($value['id'], false);
|
||||
?>
|
||||
|
@ -422,6 +425,22 @@ $_page = new Page(array('Manage playlist'));
|
|||
avideoModalIframe(webSiteRootURL + 'viewProgram/' + playlists_id);
|
||||
}
|
||||
|
||||
function clonePlayList(playlists_id) {
|
||||
var url = 'plugin/PlayLists/clone.json.php';
|
||||
var data = {
|
||||
"playlists_id": playlists_id
|
||||
};
|
||||
var pleaseWait = true;
|
||||
var returnFunction = function(response) {
|
||||
console.log('returnFunction', response);
|
||||
if (!response.error) {
|
||||
avideoToastSuccess(__('Playlist cloned') + ' #' + response.new_playlist_id);
|
||||
editPlayList(response.new_playlist_id);
|
||||
}
|
||||
};
|
||||
avideoAjaxWithResponse(url, data, pleaseWait, returnFunction);
|
||||
}
|
||||
|
||||
function removeFromSerie(playlists_id, videos_id) {
|
||||
swal({
|
||||
title: "<?php echo __('Are you sure?'); ?>",
|
||||
|
|
|
@ -1763,6 +1763,9 @@ function avideoResponse(response) {
|
|||
avideoToastInfo(response.msg);
|
||||
} else {
|
||||
avideoToastSuccess(response.msg);
|
||||
if (typeof response.eval !== 'undefined') {
|
||||
eval(response.eval);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2358,42 +2361,41 @@ function changeVideoStatus(videos_id, status) {
|
|||
}
|
||||
|
||||
function avideoAjax(url, data) {
|
||||
if (!url.startsWith('http')) {
|
||||
url = webSiteRootURL + url;
|
||||
}
|
||||
avideoAjax2(url, data, true);
|
||||
avideoAjaxWithResponse(url, data, true, ()=>{});
|
||||
}
|
||||
|
||||
function avideoAjax2(url, data, pleaseWait) {
|
||||
function avideoAjaxWithResponse(url, data, pleaseWait, returnFunction) {
|
||||
if (pleaseWait) {
|
||||
modal.showPleaseWait();
|
||||
}
|
||||
if (!url.startsWith('http')) {
|
||||
url = webSiteRootURL + url;
|
||||
}
|
||||
$.ajax({
|
||||
url: url,
|
||||
data: data,
|
||||
type: 'post',
|
||||
success: function (response) {
|
||||
if (response.error) {
|
||||
avideoAlertError(response.msg);
|
||||
} else {
|
||||
avideoToastSuccess(response.msg);
|
||||
if (typeof response.eval !== 'undefined') {
|
||||
eval(response.eval);
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function (response) {
|
||||
//console.error('avideoAjax2', url, data, pleaseWait, response.responseJSON);
|
||||
if (response.responseJSON.error) {
|
||||
avideoAlertError(response.responseJSON.msg);
|
||||
} else {
|
||||
avideoToastError(response.responseJSON.msg);
|
||||
}
|
||||
},
|
||||
complete: function (response) {
|
||||
complete: function (jqXHR, textStatus) {
|
||||
if (pleaseWait) {
|
||||
modal.hidePleaseWait();
|
||||
}
|
||||
if (jqXHR.status >= 200 && jqXHR.status < 300) {
|
||||
// Successful response
|
||||
if (jqXHR.responseJSON) {
|
||||
avideoResponse(jqXHR.responseJSON);
|
||||
returnFunction(jqXHR.responseJSON);
|
||||
} else {
|
||||
returnFunction(jqXHR.responseText);
|
||||
}
|
||||
} else {
|
||||
// Error response
|
||||
console.error('Error:', textStatus, jqXHR.statusText);
|
||||
if (jqXHR.responseJSON) {
|
||||
avideoResponse(jqXHR.responseJSON);
|
||||
} else {
|
||||
avideoAlertError(textStatus + ': ' + jqXHR.statusText);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue