XoopsModules25x /
suico
| 1 | <?php declare(strict_types=1); |
||
| 2 | |||
| 3 | namespace XoopsModules\Yogurt; |
||
| 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 | * @copyright XOOPS Project https://xoops.org/ |
||
| 20 | * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
||
| 21 | * @author Marcello Brandão aka Suico |
||
| 22 | * @author XOOPS Development Team |
||
| 23 | * @since |
||
| 24 | */ |
||
| 25 | require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
||
| 26 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 27 | require_once XOOPS_ROOT_PATH . '/class/criteria.php'; |
||
| 28 | require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||
| 29 | /** |
||
| 30 | * Module classes |
||
| 31 | */ |
||
| 32 | //require_once __DIR__ . '/Image.php'; |
||
| 33 | //require_once __DIR__ . '/Visitors.php'; |
||
| 34 | //require_once __DIR__ . '/Video.php'; |
||
| 35 | //require_once __DIR__ . '/Audio.php'; |
||
| 36 | //require_once __DIR__ . '/Friendrequest.php'; |
||
| 37 | //require_once __DIR__ . '/Friendship.php'; |
||
| 38 | //require_once __DIR__ . '/Relgroupuser.php'; |
||
| 39 | //require_once __DIR__ . '/Groups.php'; |
||
| 40 | //require_once __DIR__ . '/Notes.php'; |
||
| 41 | //require_once __DIR__ . '/Configs.php'; |
||
| 42 | //require_once __DIR__ . '/Suspensions.php'; |
||
| 43 | //if (str_replace('.', '', PHP_VERSION) > 499) { |
||
| 44 | // require_once __DIR__ . '/Id3v1.php'; |
||
| 45 | //} |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Class YogurtVideoController |
||
| 49 | */ |
||
| 50 | class VideoController extends YogurtController |
||
| 51 | { |
||
| 52 | /** |
||
| 53 | * Fetch videos |
||
| 54 | * @param object $criteria |
||
| 55 | * @return array of video objects |
||
| 56 | */ |
||
| 57 | public function getVideos( |
||
| 58 | $criteria |
||
| 59 | ) { |
||
| 60 | return $this->videosFactory->getObjects($criteria); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Assign Videos Submit Form to theme |
||
| 65 | * @param int $maxNbVideos the maximum number of videos a user can have |
||
| 66 | * @param $presentNb |
||
| 67 | */ |
||
| 68 | public function showFormSubmitVideos( |
||
| 69 | $maxNbVideos, |
||
| 70 | $presentNb |
||
| 71 | ) { |
||
| 72 | global $xoopsTpl; |
||
| 73 | |||
| 74 | if ($this->isUser) { |
||
| 75 | if ((1 === $this->isOwner) && ($maxNbVideos > $presentNb)) { |
||
| 76 | echo ' '; |
||
| 77 | $this->videosFactory->renderFormSubmit($xoopsTpl); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Assign Video Content to Template |
||
| 84 | * @param $nbVideos |
||
| 85 | * @param $videos |
||
| 86 | * @return bool |
||
| 87 | */ |
||
| 88 | public function assignVideoContent( |
||
| 89 | $nbVideos, |
||
| 90 | $videos |
||
| 91 | ) { |
||
| 92 | if (0 === $nbVideos) { |
||
| 93 | return false; |
||
| 94 | } |
||
| 95 | /** |
||
| 96 | * Lets populate an array with the dati from the videos |
||
| 97 | */ |
||
| 98 | $i = 0; |
||
| 99 | foreach ($videos as $video) { |
||
| 100 | $videosArray[$i]['url'] = $video->getVar('youtube_code', 's'); |
||
| 101 | $videosArray[$i]['desc'] = $video->getVar('video_desc', 's'); |
||
| 102 | $videosArray[$i]['id'] = $video->getVar('video_id', 's'); |
||
| 103 | |||
| 104 | $i++; |
||
| 105 | } |
||
| 106 | |||
| 107 | return $videosArray; |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Create a page navbar for videos |
||
| 112 | * @param $nbVideos |
||
| 113 | * @param int $videosPerPage the number of videos in a page |
||
| 114 | * @param int $start at which position of the array we start |
||
| 115 | * @param int $interval how many pages between the first link and the next one |
||
| 116 | * @return string|null |
||
| 117 | * @return string|null |
||
| 118 | */ |
||
| 119 | public function VideosNavBar( |
||
| 120 | $nbVideos, |
||
| 121 | $videosPerPage, |
||
| 122 | $start, |
||
| 123 | $interval |
||
| 124 | ) { |
||
| 125 | $pageNav = new XoopsPageNav($nbVideos, $videosPerPage, $start, 'start', 'uid=' . $this->uidOwner); |
||
| 126 | return $pageNav->renderImageNav($interval); |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @return bool|void |
||
| 131 | */ |
||
| 132 | public function checkPrivilege() |
||
| 133 | { |
||
| 134 | if (0 === $this->helper->getConfig('enable_videos')) { |
||
| 135 | \redirect_header('index.php?uid=' . $this->owner->getVar('uid'), 3, \_MD_YOGURT_VIDEOS_ENABLED_NOT); |
||
| 136 | } |
||
| 137 | $criteria = new Criteria('config_uid', $this->owner->getVar('uid')); |
||
| 138 | if (1 === $this->configsFactory->getCount($criteria)) { |
||
| 139 | $configs = $this->configsFactory->getObjects($criteria); |
||
| 140 | |||
| 141 | $config = $configs[0]->getVar('videos'); |
||
| 142 | |||
| 143 | if (!$this->checkPrivilegeLevel($config)) { |
||
| 144 | \redirect_header('index.php?uid=' . $this->owner->getVar('uid'), 10, \_MD_YOGURT_NOPRIVILEGE); |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | return true; |
||
| 149 | } |
||
| 150 | } |
||
| 151 |