mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-02 17:29:20 +02:00
Add option to organize the videos order
This commit is contained in:
parent
89795fe843
commit
6fa17d1bfc
12 changed files with 260 additions and 17 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +0,0 @@
|
|||
[submodule "view/js/jquery-dialogextend"]
|
||||
path = view/js/jquery-dialogextend
|
||||
url = https://github.com/ROMB/jquery-dialogextend.git
|
|
@ -4,7 +4,7 @@ if (file_exists("../videos/configuration.php")) {
|
|||
exit;
|
||||
}
|
||||
|
||||
$installationVersion = "12.4";
|
||||
$installationVersion = "12.5";
|
||||
|
||||
error_log("Installation: ".__LINE__." ". json_encode($_POST));
|
||||
header('Content-Type: application/json');
|
||||
|
|
|
@ -150,7 +150,7 @@ CREATE TABLE IF NOT EXISTS `videos` (
|
|||
`duration` VARCHAR(15) NOT NULL,
|
||||
`type` ENUM('audio', 'video', 'embed', 'linkVideo', 'linkAudio', 'torrent', 'pdf', 'image', 'gallery', 'article', 'serie', 'zip') NOT NULL DEFAULT 'video',
|
||||
`videoDownloadedLink` VARCHAR(255) NULL DEFAULT NULL,
|
||||
`order` INT(10) UNSIGNED NOT NULL DEFAULT 1,
|
||||
`order` INT(10) UNSIGNED NULL DEFAULT NULL,
|
||||
`rotation` SMALLINT(6) NULL DEFAULT 0,
|
||||
`zoom` FLOAT NULL DEFAULT 1,
|
||||
`youtubeId` VARCHAR(45) NULL DEFAULT NULL,
|
||||
|
|
|
@ -25,12 +25,19 @@ class BootGrid
|
|||
$direction = "ASC";
|
||||
if (strtoupper($value)==="DESC") {
|
||||
$direction = "DESC";
|
||||
}else
|
||||
if (strtoupper($value)==="IS NULL") {
|
||||
$direction = "IS NULL";
|
||||
}
|
||||
$key = preg_replace("/[^A-Za-z0-9._ ]/", '', $key);
|
||||
if ($key=='order') {
|
||||
$key = '`order`';
|
||||
}
|
||||
$orderBy[] = " {$keyPrefix}{$key} {$direction} ";
|
||||
if (strpos($key, $keyPrefix) === 0) {
|
||||
$orderBy[] = " {$key} {$direction} ";
|
||||
} else {
|
||||
$orderBy[] = " {$keyPrefix}{$key} {$direction} ";
|
||||
}
|
||||
}
|
||||
$sql .= " ORDER BY ".implode(",", $orderBy);
|
||||
} else {
|
||||
|
|
|
@ -6075,7 +6075,9 @@ function getRowCount($default = 1000) {
|
|||
}
|
||||
|
||||
function setRowCount($rowCount) {
|
||||
global $global;
|
||||
$_REQUEST['rowCount'] = intval($rowCount);
|
||||
$global['rowCount'] = $_REQUEST['rowCount'];
|
||||
}
|
||||
|
||||
function getSearchVar() {
|
||||
|
|
|
@ -1577,6 +1577,15 @@ if (!class_exists('Video')) {
|
|||
$_POST['sort']['v.created'] = $_POST['sort']['created'];
|
||||
unset($_POST['sort']['created']);
|
||||
}
|
||||
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']['v.created']);
|
||||
unset($_POST['sort']['created']);
|
||||
$_POST['sort']['v.order'] = 'IS NULL';
|
||||
$_POST['sort']['order'] = 'ASC';
|
||||
$_POST['sort']['v.created'] =$created;
|
||||
}
|
||||
//var_dump($_POST['sort']);exit;
|
||||
$sql .= BootGrid::getSqlFromPost([], empty($_POST['sort']['likes']) ? "v." : "", "", true);
|
||||
} else {
|
||||
unset($_POST['sort']['trending'], $_GET['sort']['trending']);
|
||||
|
@ -1619,7 +1628,7 @@ if (!class_exists('Video')) {
|
|||
}
|
||||
}
|
||||
|
||||
//echo $sql;var_dump($_REQUEST['doNotShowCatChilds']);exit;
|
||||
//echo $sql;//var_dump($_REQUEST['doNotShowCatChilds']);exit;
|
||||
//_error_log("getAllVideos($status, $showOnlyLoggedUserVideos , $ignoreGroup , ". json_encode($videosArrayId).")" . $sql);
|
||||
|
||||
$timeLogName = TimeLogStart("video::getAllVideos");
|
||||
|
@ -1993,7 +2002,7 @@ if (!class_exists('Video')) {
|
|||
* @param string $showOnlyLoggedUserVideos
|
||||
* @return array
|
||||
*/
|
||||
public static function getAllVideosLight($status = "viewable", $showOnlyLoggedUserVideos = false, $showUnlisted = false, $suggestedOnly = false, $type = '', $max_duration_in_seconds=0) {
|
||||
public static function getAllVideosLight($status = "viewable", $showOnlyLoggedUserVideos = false, $showUnlisted = false, $suggestedOnly = false, $type = '', $max_duration_in_seconds=0, $with_order_only=false) {
|
||||
global $global, $config;
|
||||
if ($config->currentVersionLowerThen('5')) {
|
||||
return [];
|
||||
|
@ -2010,6 +2019,11 @@ if (!class_exists('Video')) {
|
|||
}
|
||||
|
||||
$sql .= " WHERE 1=1 ";
|
||||
|
||||
if ($with_order_only) {
|
||||
$sql .= " AND v.`order` IS NOT NULL ";
|
||||
}
|
||||
|
||||
$blockedUsers = self::getBlockedUsersIdsArray();
|
||||
if (!empty($blockedUsers)) {
|
||||
$sql .= " AND v.users_id NOT IN ('" . implode("','", $blockedUsers) . "') ";
|
||||
|
@ -2847,6 +2861,22 @@ if (!class_exists('Video')) {
|
|||
return VideoHLS::updateHLSDurationIfNeed($this);
|
||||
}
|
||||
|
||||
static public function resetOrder() {
|
||||
if (!Permissions::canAdminVideos()) {
|
||||
return false;
|
||||
}
|
||||
$sql = "UPDATE videos SET `order` = NULL WHERE `order` IS NOT NULL";
|
||||
return sqlDAL::writeSql($sql);
|
||||
}
|
||||
|
||||
static public function updateOrder($videos_id, $order) {
|
||||
if (!Permissions::canAdminVideos()) {
|
||||
return false;
|
||||
}
|
||||
$sql = "UPDATE videos SET `order` = ?, modified = now() WHERE id = ?";
|
||||
return sqlDAL::writeSql($sql, "ii", [$order, $videos_id]);
|
||||
}
|
||||
|
||||
public function updateDurationIfNeed($fileExtension = ".mp4") {
|
||||
global $global;
|
||||
$source = self::getSourceFile($this->filename, $fileExtension, true);
|
||||
|
|
25
objects/videoSaveOrder.json.php
Normal file
25
objects/videoSaveOrder.json.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
//error_reporting(0);
|
||||
header('Content-Type: application/json');
|
||||
if (empty($global['systemRootPath'])) {
|
||||
$global['systemRootPath'] = '../';
|
||||
}
|
||||
require_once $global['systemRootPath'] . 'videos/configuration.php';
|
||||
|
||||
if (!Permissions::canAdminVideos()) {
|
||||
forbiddenPage('Permission denied');
|
||||
}
|
||||
|
||||
$obj = new stdClass();
|
||||
|
||||
$obj->error = true;
|
||||
$obj->msg = '';
|
||||
$obj->responses = array();
|
||||
mysqlBeginTransaction();
|
||||
Video::resetOrder();
|
||||
foreach ($_REQUEST['videos'] as $key => $value) {
|
||||
$obj->responses[] = Video::updateOrder($value['videos_id'], $value['order']);
|
||||
}
|
||||
$obj->error = empty($obj->responses);
|
||||
mysqlCommit();
|
||||
echo json_encode($obj);
|
|
@ -39,7 +39,7 @@ if (empty($name)) {
|
|||
data: data,
|
||||
success: function (data) {
|
||||
if (data.rows && data.rows[0]) {
|
||||
$("#videoAutocomplete<?php echo $id; ?>").val(data.rows[0].identification);
|
||||
$("#videoAutocomplete<?php echo $id; ?>").val(data.rows[0].title);
|
||||
$("#<?php echo $id; ?>").val(videos_id);
|
||||
var photoURL = data.rows[0].videosURL.jpg.url;
|
||||
$("#videoAutocomplete-img<?php echo $id; ?>").attr("src", photoURL);
|
||||
|
@ -85,11 +85,11 @@ if (empty($name)) {
|
|||
});
|
||||
},
|
||||
focus: function (event, ui) {
|
||||
$("#videoAutocomplete<?php echo $id; ?>").val(ui.item.identification);
|
||||
$("#videoAutocomplete<?php echo $id; ?>").val(ui.item.title);
|
||||
return false;
|
||||
},
|
||||
select: function (event, ui) {
|
||||
$("#videoAutocomplete<?php echo $id; ?>").val(ui.item.identification);
|
||||
$("#videoAutocomplete<?php echo $id; ?>").val(ui.item.title);
|
||||
$("#<?php echo $id; ?>").val(ui.item.id);
|
||||
var photoURL = webSiteRootURL + 'img/notfound.jpg'
|
||||
if (ui.item.videosURL.jpg.url) {
|
||||
|
|
|
@ -664,24 +664,29 @@ class PlayerSkins extends PluginAbstract {
|
|||
player.on('ratechange', function () {
|
||||
sendAVideoMobileMessage('ratechange', player.playbackRate);
|
||||
});
|
||||
player.on('timeupdate', function () {
|
||||
player.on('timeupdate', function() {
|
||||
var time = Math.round(this.currentTime());
|
||||
playerCurrentTime = time;
|
||||
var url = '{$url}';
|
||||
|
||||
if (url.indexOf('?') > -1) {
|
||||
url += '&t=' + time;
|
||||
url += '&t=' + time;
|
||||
} else {
|
||||
url += '?t=' + time;
|
||||
url += '?t=' + time;
|
||||
}
|
||||
|
||||
$('#linkCurrentTime, .linkCurrentTime').val(url);
|
||||
|
||||
if (time >= 5 && time % 1 === 0) {
|
||||
addView({$videos_id}, time);
|
||||
}else{
|
||||
} else {
|
||||
addViewFromCookie();
|
||||
addViewSetCookie(PHPSESSID, {$videos_id}, time, seconds_watching_video);
|
||||
}
|
||||
|
||||
sendAVideoMobileMessage('timeupdate', time);
|
||||
});";
|
||||
});
|
||||
;";
|
||||
|
||||
if (!empty($nextURL)) {
|
||||
$js .= "playNextURL = '{$nextURL}';";
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
UPDATE configurations SET version = '12.4', modified = now() WHERE id = 1;
|
||||
ALTER TABLE videos MODIFY COLUMN `order` INT(10) UNSIGNED DEFAULT NULL;
|
||||
UPDATE videos SET `order` = NULL WHERE id > 0;
|
||||
UPDATE configurations SET version = '12.5', modified = now() WHERE id = 1;
|
167
view/managerVideosOrganize.php
Normal file
167
view/managerVideosOrganize.php
Normal file
|
@ -0,0 +1,167 @@
|
|||
<?php
|
||||
global $global, $config;
|
||||
if (!isset($global['systemRootPath'])) {
|
||||
require_once '../videos/configuration.php';
|
||||
}
|
||||
|
||||
if (!Permissions::canAdminVideos()) {
|
||||
forbiddenPage('You Must be admin');
|
||||
}
|
||||
|
||||
$videos = array();
|
||||
setRowCount(100);
|
||||
$row = Video::getAllVideosLight("viewable", false, true, false, '', 0, true);
|
||||
foreach ($row as $key => $value) {
|
||||
$videos[] = array('videos_id' => $value['id'], 'title' => $value['title'], 'order' => $value['order']);
|
||||
}
|
||||
|
||||
$page = new Page('Sort videos');
|
||||
?>
|
||||
<style>
|
||||
#sortable {
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
#sortable li {
|
||||
margin: 0 3px 3px 3px;
|
||||
padding: 0.4em;
|
||||
padding-left: 1.5em;
|
||||
font-size: 1.4em;
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
#sortable li span {
|
||||
margin-left: 15px;
|
||||
}
|
||||
|
||||
.ui-state-highlight {
|
||||
height: 1.5em;
|
||||
line-height: 1.5em;
|
||||
}
|
||||
</style>
|
||||
<div class="container-fluid">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Video Sorting</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p>In this page, you can sort the order of videos.</p>
|
||||
<p>When you sort the videos by creation date, the videos at the top will appear first.</p>
|
||||
<p>To change the order, simply drag and drop the video title.</p>
|
||||
<p>To add a new video, use the search bar below and click on the "Add" button.</p>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="row">
|
||||
<div class="col-xs-10">
|
||||
<?php
|
||||
$autoComplete = Layout::getVideoAutocomplete(0, 'videoAutocomplete');
|
||||
?>
|
||||
</div>
|
||||
<div class="col-xs-2">
|
||||
<button class="btn btn-primary btn-block" id="addVideoBtn">
|
||||
<i class="fas fa-plus"></i>
|
||||
<span class="hidden-xs">
|
||||
<?php echo __('Add'); ?>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-footer">
|
||||
<button class="btn btn-success btn-block saveOrder">
|
||||
<i class="fas fa-save"></i>
|
||||
<?php echo __('Save'); ?>
|
||||
</button>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<ul id="sortable">
|
||||
</ul>
|
||||
</div>
|
||||
<div class="panel-footer">
|
||||
<button class="btn btn-success btn-block saveOrder">
|
||||
<i class="fas fa-save"></i>
|
||||
<?php echo __('Save'); ?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var videos = <?php echo json_encode($videos); ?>;
|
||||
|
||||
function addVideoItem(videos_id, title, order) {
|
||||
var newLi = $("<li>", {
|
||||
class: "ui-state-default clearfix",
|
||||
"data-videos-id": videos_id
|
||||
}).append(
|
||||
$("<i>", {
|
||||
class: "fas fa-arrows-alt-v"
|
||||
}),
|
||||
$("<span>").text(title),
|
||||
$("<button>", {
|
||||
class: "btn btn-danger pull-right removeVideoBtn",
|
||||
type: "button"
|
||||
}).html('<i class="fas fa-trash"></i>')
|
||||
);
|
||||
|
||||
if (order === 0) {
|
||||
$("#sortable").prepend(newLi);
|
||||
} else if (order > 0 && order <= $("#sortable li").length) {
|
||||
$("#sortable li:nth-child(" + order + ")").before(newLi);
|
||||
} else {
|
||||
$("#sortable").append(newLi);
|
||||
}
|
||||
}
|
||||
|
||||
function saveVideoOrder() {
|
||||
var videosList = [];
|
||||
$("#sortable li").each(function(index) {
|
||||
var videos_id = $(this).data("videos-id");
|
||||
var order = index + 1;
|
||||
videosList.push({
|
||||
videos_id: videos_id,
|
||||
order: order
|
||||
});
|
||||
});
|
||||
|
||||
avideoAjax("objects/videoSaveOrder.json.php", {
|
||||
videos: videosList
|
||||
});
|
||||
}
|
||||
|
||||
$(function() {
|
||||
$("#sortable").sortable({
|
||||
placeholder: "ui-state-highlight"
|
||||
});
|
||||
|
||||
for (const key in videos) {
|
||||
if (videos.hasOwnProperty(key)) {
|
||||
const video = videos[key];
|
||||
addVideoItem(video.videos_id, video.title, video.order);
|
||||
}
|
||||
}
|
||||
|
||||
$("#addVideoBtn").click(function() {
|
||||
var videos_id = $("#videoAutocomplete").val();
|
||||
var title = $("#videoAutocompletevideoAutocomplete").val();
|
||||
addVideoItem(videos_id, title, 0);
|
||||
});
|
||||
|
||||
$(document).on("click", ".removeVideoBtn", function() {
|
||||
$(this).closest("li").remove();
|
||||
});
|
||||
|
||||
$(".saveOrder").click(function() {
|
||||
saveVideoOrder();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<?php
|
||||
$page->print();
|
||||
?>
|
|
@ -186,6 +186,14 @@ if (!empty($_GET['iframe'])) {
|
|||
</button>
|
||||
<?php
|
||||
}
|
||||
if (Permissions::canAdminVideos()) {
|
||||
?>
|
||||
<button class="btn btn-sm btn-xs btn-default" onclick="avideoModalIframeFullScreen(webSiteRootURL+'view/managerVideosOrganize.php');">
|
||||
<i class="fas fa-sort-amount-up-alt"></i>
|
||||
<span class="hidden-md hidden-sm hidden-xs"><?php echo __("Sort Videos"); ?></span>
|
||||
</button>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue