1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Suico; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
You may not change or alter any portion of this comment or credits |
7
|
|
|
of supporting developers from this source code or any supporting source code |
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
9
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
use Criteria; |
16
|
|
|
use XoopsPageNav; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @category Module |
20
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
21
|
|
|
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
22
|
|
|
* @author Marcello Brandão aka Suico, Mamba, LioMJ <https://xoops.org> |
23
|
|
|
*/ |
24
|
|
|
require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
25
|
|
|
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
26
|
|
|
require_once XOOPS_ROOT_PATH . '/class/criteria.php'; |
27
|
|
|
require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Class VideoController |
31
|
|
|
*/ |
32
|
|
|
class VideoController extends Controller |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Fetch videos |
36
|
|
|
* @param object $criteria |
37
|
|
|
* @return array of video objects |
38
|
|
|
*/ |
39
|
|
|
public function getVideos( |
40
|
|
|
$criteria |
41
|
|
|
) { |
42
|
|
|
return $this->videosFactory->getObjects($criteria); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Assign Videos Submit Form to theme |
47
|
|
|
* @param int $maxNbVideos the maximum number of videos a user can have |
48
|
|
|
* @param $presentNb |
49
|
|
|
*/ |
50
|
|
|
public function showFormSubmitVideos( |
51
|
|
|
$maxNbVideos, |
52
|
|
|
$presentNb |
53
|
|
|
): void { |
54
|
|
|
global $xoopsTpl; |
55
|
|
|
if ($this->isUser) { |
56
|
|
|
if ((1 === $this->isOwner) && ($maxNbVideos > $presentNb)) { |
57
|
|
|
echo ' '; |
58
|
|
|
$this->videosFactory->renderFormSubmit($xoopsTpl); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Assign Video Content to Template |
65
|
|
|
* @param $countVideos |
66
|
|
|
* @param $videos |
67
|
|
|
* @return array|bool |
68
|
|
|
*/ |
69
|
|
|
public function assignVideoContent( |
70
|
|
|
$countVideos, |
71
|
|
|
$videos |
72
|
|
|
) { |
73
|
|
|
if (0 === $countVideos) { |
74
|
|
|
return false; |
75
|
|
|
} |
76
|
|
|
/** |
77
|
|
|
* Lets populate an array with the dati from the videos |
78
|
|
|
*/ |
79
|
|
|
$i = 0; |
80
|
|
|
foreach ($videos as $video) { |
81
|
|
|
$videosArray[$i]['url'] = $video->getVar('youtube_code', 's'); |
82
|
|
|
$videosArray[$i]['title'] = $video->getVar('video_title', 's'); |
83
|
|
|
$videosArray[$i]['desc'] = $video->getVar('video_desc', 's'); |
84
|
|
|
$videosArray[$i]['id'] = $video->getVar('video_id', 's'); |
85
|
|
|
$videosArray[$i]['featured_video'] = $video->getVar('featured_video', 's'); |
86
|
|
|
$videosArray[$i]['date_created'] = \formatTimestamp($video->getVar('date_created', 's')); |
87
|
|
|
$videosArray[$i]['date_updated'] = \formatTimestamp($video->getVar('date_updated', 's')); |
88
|
|
|
$i++; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return $videosArray; |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Create a page navbar for videos |
96
|
|
|
* @param $countVideos |
97
|
|
|
* @param int $videosPerPage the number of videos in a page |
98
|
|
|
* @param int $start at which position of the array we start |
99
|
|
|
* @param int $interval how many pages between the first link and the next one |
100
|
|
|
* @return string|null |
101
|
|
|
* @return string|null |
102
|
|
|
*/ |
103
|
|
|
public function videosNavBar( |
104
|
|
|
$countVideos, |
105
|
|
|
$videosPerPage, |
106
|
|
|
$start, |
107
|
|
|
$interval |
108
|
|
|
) { |
109
|
|
|
$pageNav = new XoopsPageNav($countVideos, $videosPerPage, $start, 'start', 'uid=' . $this->uidOwner); |
110
|
|
|
|
111
|
|
|
return $pageNav->renderImageNav($interval); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return bool|void |
116
|
|
|
*/ |
117
|
|
|
public function checkPrivilege() |
118
|
|
|
{ |
119
|
|
|
if (0 === $this->helper->getConfig('enable_videos')) { |
120
|
|
|
\redirect_header('index.php?uid=' . $this->owner->getVar('uid'), 3, \_MD_SUICO_VIDEOS_ENABLED_NOT); |
121
|
|
|
} |
122
|
|
|
$criteria = new Criteria('config_uid', $this->owner->getVar('uid')); |
|
|
|
|
123
|
|
|
if (1 === $this->configsFactory->getCount($criteria)) { |
124
|
|
|
$configs = $this->configsFactory->getObjects($criteria); |
125
|
|
|
$config = $configs[0]->getVar('videos'); |
|
|
|
|
126
|
|
|
/* |
127
|
|
|
if (!$this->checkPrivilegeLevel($config)) { |
128
|
|
|
\redirect_header('index.php?uid=' . $this->owner->getVar('uid'), 10, sprintf(_MD_SUICO_NOPRIVILEGE,'Videos')); |
129
|
|
|
} |
130
|
|
|
*/ |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
return true; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|