3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 use Friendica\Content\Nav;
24 use Friendica\Content\Pager;
25 use Friendica\Content\Widget;
26 use Friendica\Core\Renderer;
27 use Friendica\Core\Session;
28 use Friendica\Database\DBA;
30 use Friendica\Model\Attach;
31 use Friendica\Model\Item;
32 use Friendica\Model\Profile;
33 use Friendica\Model\User;
34 use Friendica\Module\BaseProfile;
35 use Friendica\Security\Security;
36 use Friendica\Network\HTTPException;
38 function videos_init(App $a)
40 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
44 Nav::setSelected('home');
46 if (DI::args()->getArgc() > 1) {
47 $owner = User::getOwnerDataByNick(DI::args()->getArgv()[1]);
49 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
52 // If not there, create 'aside' empty
53 if (!isset(DI::page()['aside'])) {
54 DI::page()['aside'] = '';
57 DI::page()['aside'] .= Widget\VCard::getHTML($owner);
59 $tpl = Renderer::getMarkupTemplate("videos_head.tpl");
60 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl);
66 function videos_post(App $a)
68 $user = User::getByNickname(DI::args()->getArgv()[1]);
69 if (!DBA::isResult($user)) {
70 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
73 if (local_user() != $user['uid']) {
74 DI::baseUrl()->redirect('videos/' . $user['nickname']);
77 if ((DI::args()->getArgc() == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
78 $video_id = $_POST['id'];
80 if (Attach::exists(['id' => $video_id, 'uid' => local_user()])) {
81 // delete the attachment
82 Attach::delete(['id' => $video_id, 'uid' => local_user()]);
84 // delete items where the attach is used
85 Item::deleteForUser(['`attach` LIKE ? AND `uid` = ?',
86 '%attach/' . $video_id . '%',
91 DI::baseUrl()->redirect('videos/' . $user['nickname']);
95 DI::baseUrl()->redirect('videos/' . $user['nickname']);
98 function videos_content(App $a)
100 // URLs (most aren't currently implemented):
102 // videos/name/upload
103 // videos/name/upload/xxxxx (xxxxx is album name)
104 // videos/name/album/xxxxx
105 // videos/name/album/xxxxx/edit
106 // videos/name/video/xxxxx
107 // videos/name/video/xxxxx/edit
109 $user = User::getByNickname(DI::args()->getArgv()[1]);
110 if (!DBA::isResult($user)) {
111 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
114 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
115 notice(DI::l10n()->t('Public access denied.'));
120 notice(DI::l10n()->t('No videos selected') . EOL );
124 $profile = Profile::getByUID($user['uid']);
125 //$phototypes = Photo::supportedTypes();
127 $_SESSION['video_return'] = DI::args()->getCommand();
132 if (DI::args()->getArgc() > 3) {
133 $datatype = DI::args()->getArgv()[2];
134 } elseif((DI::args()->getArgc() > 2) && (DI::args()->getArgv()[2] === 'upload')) {
135 $datatype = 'upload';
137 $datatype = 'summary';
141 // Setup permissions structures
145 $remote_contact = false;
148 $community_page = (($user['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
150 if ((local_user()) && (local_user() == $user['uid'])) {
152 } elseif ($community_page && !empty(Session::getRemoteContactID($user['uid']))) {
153 $contact_id = Session::getRemoteContactID($user['uid']);
155 $remote_contact = true;
156 $visitor = $contact_id;
159 // perhaps they're visiting - but not a community page, so they wouldn't have write access
160 if (!empty(Session::getRemoteContactID($user['uid'])) && !$visitor) {
161 $contact_id = Session::getRemoteContactID($user['uid']);
162 $remote_contact = true;
165 if ($user['hidewall'] && (local_user() != $user['uid']) && !$remote_contact) {
166 notice(DI::l10n()->t('Access to this item is restricted.'));
170 $sql_extra = Security::getPermissionsSQLByUserId($user['uid']);
175 $_is_owner = (local_user() && (local_user() == $user['uid']));
176 $o .= BaseProfile::getTabsHTML($a, 'videos', $_is_owner, $user['nickname'], $profile['hide-friends']);
181 if ($datatype === 'upload') {
182 return; // no uploading for now
184 // DELETED -- look at mod/photos.php if you want to implement
187 if ($datatype === 'album') {
188 return; // no albums for now
190 // DELETED -- look at mod/photos.php if you want to implement
194 if ($datatype === 'video') {
195 return; // no single video view for now
197 // DELETED -- look at mod/photos.php if you want to implement
200 // Default - show recent videos (no upload link for now)
204 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
205 $sql_extra GROUP BY hash",
208 if (DBA::isResult($r)) {
212 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
214 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
215 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
217 WHERE `uid` = %d AND filetype LIKE '%%video%%'
218 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
219 intval($user['uid']),
221 $pager->getItemsPerPage()
226 if (DBA::isResult($r)) {
227 foreach ($r as $rr) {
228 $alt_e = $rr['filename'];
229 /// @todo The album isn't part of the above query. This seems to be some unfinished code that needs to be reworked completely.
231 $name_e = $rr['album'];
235 'link' => DI::baseUrl() . '/videos/' . $user['nickname'] . '/video/' . $rr['hash'],
236 'title' => DI::l10n()->t('View Video'),
237 'src' => DI::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
239 'mime' => $rr['filetype'],
241 'link' => DI::baseUrl() . '/videos/' . $user['nickname'] . '/album/' . bin2hex($rr['album']),
243 'alt' => DI::l10n()->t('View Album'),
249 $tpl = Renderer::getMarkupTemplate('videos_recent.tpl');
250 $o .= Renderer::replaceMacros($tpl, [
251 '$title' => DI::l10n()->t('Recent Videos'),
252 '$can_post' => $can_post,
253 '$upload' => [DI::l10n()->t('Upload New Videos'), DI::baseUrl() . '/videos/' . $user['nickname'] . '/upload'],
254 '$videos' => $videos,
255 '$delete_url' => (($can_post) ? DI::baseUrl() . '/videos/' . $user['nickname'] : false)
258 $o .= $pager->renderFull($total);