Skip to content

Commit

Permalink
Add option to organize the videos order
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Neto committed Jul 10, 2023
1 parent 89795fe commit 6fa17d1
Show file tree
Hide file tree
Showing 12 changed files with 260 additions and 17 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "view/js/jquery-dialogextend"]
path = view/js/jquery-dialogextend
url = https://github.com/ROMB/jquery-dialogextend.git
2 changes: 1 addition & 1 deletion install/checkConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
exit;
}

$installationVersion = "12.4";
$installationVersion = "12.5";

error_log("Installation: ".__LINE__." ". json_encode($_POST));
header('Content-Type: application/json');
Expand Down
2 changes: 1 addition & 1 deletion install/database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion objects/bootGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ public static function getSqlFromPost($searchFieldsNames = [], $keyPrefix = "",
$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 {
Expand Down
2 changes: 2 additions & 0 deletions objects/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6075,7 +6075,9 @@ function getRowCount($default = 1000) {
}

function setRowCount($rowCount) {
global $global;
$_REQUEST['rowCount'] = intval($rowCount);
$global['rowCount'] = $_REQUEST['rowCount'];
}

function getSearchVar() {
Expand Down
34 changes: 32 additions & 2 deletions objects/video.php
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,15 @@ public static function getAllVideos($status = "viewable", $showOnlyLoggedUserVid
$_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']);
Expand Down Expand Up @@ -1619,7 +1628,7 @@ public static function getAllVideos($status = "viewable", $showOnlyLoggedUserVid
}
}

//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");
Expand Down Expand Up @@ -1993,7 +2002,7 @@ public static function updateFilesize($videos_id) {
* @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 [];
Expand All @@ -2010,6 +2019,11 @@ public static function getAllVideosLight($status = "viewable", $showOnlyLoggedUs
}

$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) . "') ";
Expand Down Expand Up @@ -2847,6 +2861,22 @@ public function updateHLSDurationIfNeed() {
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);
Expand Down
25 changes: 25 additions & 0 deletions objects/videoSaveOrder.json.php
Original file line number Diff line number Diff line change
@@ -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);
6 changes: 3 additions & 3 deletions plugin/Layout/videoAutocomplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function updateVideoAutocomplete<?php echo $id; ?>() {
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);
Expand Down Expand Up @@ -85,11 +85,11 @@ function resetvideoAutocomplete<?php echo $id; ?>() {
});
},
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) {
Expand Down
15 changes: 10 additions & 5 deletions plugin/PlayerSkins/PlayerSkins.php
Original file line number Diff line number Diff line change
Expand Up @@ -664,24 +664,29 @@ static function playerJSCodeOnLoad($videos_id, $nextURL = "") {
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}';";
Expand Down
4 changes: 3 additions & 1 deletion updatedb/updateDb.v12.5.sql
Original file line number Diff line number Diff line change
@@ -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 changes: 167 additions & 0 deletions view/managerVideosOrganize.php
Original file line number Diff line number Diff line change
@@ -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();
?>
8 changes: 8 additions & 0 deletions view/managerVideos_body.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@
</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>
Expand Down

0 comments on commit 6fa17d1

Please sign in to comment.