forked from XoopsModules25x/suico
-
Notifications
You must be signed in to change notification settings - Fork 0
/
editvideo.php
78 lines (73 loc) · 2.67 KB
/
editvideo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
declare(strict_types=1);
/*
You may not change or alter any portion of this comment or credits
of supporting developers from this source code or any supporting source code
which is considered copyrighted (c) material of the original comment or credit authors.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* @category Module
* @package suico
* @copyright {@link https://xoops.org/ XOOPS Project}
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
* @author Marcello Brandão aka Suico, Mamba, LioMJ <https://xoops.org>
*/
use Xmf\Request;
use XoopsModules\Suico;
require __DIR__ . '/header.php';
if (!$GLOBALS['xoopsSecurity']->check()) {
redirect_header(Request::getString('HTTP_REFERER', '', 'SERVER'), 3, _MD_SUICO_TOKENEXPIRED);
}
$video_id = Request::getInt('video_id', 0, 'POST');
$marker = Request::getInt('marker', 0, 'POST');
$uid = (int)$xoopsUser->getVar('uid');
if (1 === $marker) {
/**
* Creating the factory loading the video changing its caption
*/
$videoFactory = new Suico\VideoHandler(
$xoopsDB
);
$video = $videoFactory->create(false);
$video->load($video_id);
$video->setVar('video_title', trim(htmlspecialchars($_POST['title'], ENT_QUOTES | ENT_HTML5)));
$video->setVar('video_desc', trim(htmlspecialchars($_POST['caption'], ENT_QUOTES | ENT_HTML5)));
/**
* Verifying who's the owner to allow changes
*/
if ($uid === $video->getVar('uid_owner')) {
if ($videoFactory->insert2($video)) {
redirect_header('videos.php?uid=' . $uid . '#' . $video_id, 2, _MD_SUICO_DESC_EDITED);
} else {
redirect_header('index.php?uid=' . $uid, 2, _MD_SUICO_ERROR);
}
}
}
/**
* Creating the factory and the criteria to edit the video
* The user must be the owner
*/
$videoFactory = new Suico\VideoHandler(
$xoopsDB
);
$criteria_video = new Criteria('video_id', $video_id);
$criteriaUid = new Criteria('uid_owner', $uid);
$criteria = new CriteriaCompo($criteria_video);
$criteria->add($criteriaUid);
/**
* Lets fetch the info of the video to be able to render the form
* The user must be the owner
*/
$array_vid = $videoFactory->getObjects(
$criteria
);
if ($array_vid) {
$title = $array_vid[0]->getVar('video_title');
$caption = $array_vid[0]->getVar('video_desc');
$url = $array_vid[0]->getVar('youtube_code');
}
$videoFactory->renderFormEdit($title, $caption, $video_id, $url);
require dirname(__DIR__, 2) . '/footer.php';