From 6fa17d1bfce96af4cb900c2955d1c4d22471a566 Mon Sep 17 00:00:00 2001 From: Daniel Neto Date: Mon, 10 Jul 2023 09:15:49 -0300 Subject: [PATCH] Add option to organize the videos order --- .gitmodules | 3 - install/checkConfiguration.php | 2 +- install/database.sql | 2 +- objects/bootGrid.php | 9 +- objects/functions.php | 2 + objects/video.php | 34 +++++- objects/videoSaveOrder.json.php | 25 +++++ plugin/Layout/videoAutocomplete.php | 6 +- plugin/PlayerSkins/PlayerSkins.php | 15 ++- updatedb/updateDb.v12.5.sql | 4 +- view/managerVideosOrganize.php | 167 ++++++++++++++++++++++++++++ view/managerVideos_body.php | 8 ++ 12 files changed, 260 insertions(+), 17 deletions(-) create mode 100644 objects/videoSaveOrder.json.php create mode 100644 view/managerVideosOrganize.php diff --git a/.gitmodules b/.gitmodules index 99daa7e3ad..e69de29bb2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "view/js/jquery-dialogextend"] - path = view/js/jquery-dialogextend - url = https://github.com/ROMB/jquery-dialogextend.git \ No newline at end of file diff --git a/install/checkConfiguration.php b/install/checkConfiguration.php index 2ce0624518..c17e34fc02 100644 --- a/install/checkConfiguration.php +++ b/install/checkConfiguration.php @@ -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'); diff --git a/install/database.sql b/install/database.sql index 87d478b979..5b1790e9fe 100644 --- a/install/database.sql +++ b/install/database.sql @@ -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, diff --git a/objects/bootGrid.php b/objects/bootGrid.php index 9f102ac82c..7829e76822 100644 --- a/objects/bootGrid.php +++ b/objects/bootGrid.php @@ -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 { diff --git a/objects/functions.php b/objects/functions.php index c70e3c9b39..cf59f33596 100644 --- a/objects/functions.php +++ b/objects/functions.php @@ -6075,7 +6075,9 @@ function getRowCount($default = 1000) { } function setRowCount($rowCount) { + global $global; $_REQUEST['rowCount'] = intval($rowCount); + $global['rowCount'] = $_REQUEST['rowCount']; } function getSearchVar() { diff --git a/objects/video.php b/objects/video.php index 4e46d67adc..ebb7eef3b6 100644 --- a/objects/video.php +++ b/objects/video.php @@ -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); diff --git a/objects/videoSaveOrder.json.php b/objects/videoSaveOrder.json.php new file mode 100644 index 0000000000..15c6560e77 --- /dev/null +++ b/objects/videoSaveOrder.json.php @@ -0,0 +1,25 @@ +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); diff --git a/plugin/Layout/videoAutocomplete.php b/plugin/Layout/videoAutocomplete.php index a6c7f870fe..e71f10c697 100644 --- a/plugin/Layout/videoAutocomplete.php +++ b/plugin/Layout/videoAutocomplete.php @@ -39,7 +39,7 @@ if (empty($name)) { data: data, success: function (data) { if (data.rows && data.rows[0]) { - $("#videoAutocomplete").val(data.rows[0].identification); + $("#videoAutocomplete").val(data.rows[0].title); $("#").val(videos_id); var photoURL = data.rows[0].videosURL.jpg.url; $("#videoAutocomplete-img").attr("src", photoURL); @@ -85,11 +85,11 @@ if (empty($name)) { }); }, focus: function (event, ui) { - $("#videoAutocomplete").val(ui.item.identification); + $("#videoAutocomplete").val(ui.item.title); return false; }, select: function (event, ui) { - $("#videoAutocomplete").val(ui.item.identification); + $("#videoAutocomplete").val(ui.item.title); $("#").val(ui.item.id); var photoURL = webSiteRootURL + 'img/notfound.jpg' if (ui.item.videosURL.jpg.url) { diff --git a/plugin/PlayerSkins/PlayerSkins.php b/plugin/PlayerSkins/PlayerSkins.php index 6eeccf2c7d..4ff0e5e983 100644 --- a/plugin/PlayerSkins/PlayerSkins.php +++ b/plugin/PlayerSkins/PlayerSkins.php @@ -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}';"; diff --git a/updatedb/updateDb.v12.5.sql b/updatedb/updateDb.v12.5.sql index 2c2452f197..7ff8bf81f6 100644 --- a/updatedb/updateDb.v12.5.sql +++ b/updatedb/updateDb.v12.5.sql @@ -1 +1,3 @@ -UPDATE configurations SET version = '12.4', modified = now() WHERE id = 1; \ No newline at end of file +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; \ No newline at end of file diff --git a/view/managerVideosOrganize.php b/view/managerVideosOrganize.php new file mode 100644 index 0000000000..8325ca3823 --- /dev/null +++ b/view/managerVideosOrganize.php @@ -0,0 +1,167 @@ + $value) { + $videos[] = array('videos_id' => $value['id'], 'title' => $value['title'], 'order' => $value['order']); +} + +$page = new Page('Sort videos'); +?> + +
+
+
+

Video Sorting

+
+
+

In this page, you can sort the order of videos.

+

When you sort the videos by creation date, the videos at the top will appear first.

+

To change the order, simply drag and drop the video title.

+

To add a new video, use the search bar below and click on the "Add" button.

+
+
+
+
+ +
+
+ +
+
+
+ +
+
    +
+
+ +
+ +
+ + + + +print(); +?> \ No newline at end of file diff --git a/view/managerVideos_body.php b/view/managerVideos_body.php index f719cd9999..968631cbfe 100644 --- a/view/managerVideos_body.php +++ b/view/managerVideos_body.php @@ -186,6 +186,14 @@ if (!empty($_GET['iframe'])) { + +