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\Text\BBCode;
26 use Friendica\Core\Renderer;
27 use Friendica\Core\Session;
28 use Friendica\Database\DBA;
30 use Friendica\Model\Attach;
31 use Friendica\Model\Contact;
32 use Friendica\Model\Item;
33 use Friendica\Model\User;
34 use Friendica\Module\BaseProfile;
35 use Friendica\Security\Security;
37 function videos_init(App $a)
39 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
43 Nav::setSelected('home');
47 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
51 if (!DBA::isResult($user)) {
55 $a->data['user'] = $user[0];
56 $a->profile_uid = $user[0]['uid'];
58 $profile = User::getOwnerDataByNick($nick);
60 $account_type = Contact::getAccountType($profile);
62 $tpl = Renderer::getMarkupTemplate('widget/vcard.tpl');
64 $vcard_widget = Renderer::replaceMacros($tpl, [
65 '$name' => $profile['name'],
66 '$photo' => $profile['photo'],
67 '$addr' => $profile['addr'] ?? '',
68 '$account_type' => $account_type,
69 '$about' => BBCode::convert($profile['about']),
72 // If not there, create 'aside' empty
73 if (!isset(DI::page()['aside'])) {
74 DI::page()['aside'] = '';
77 DI::page()['aside'] .= $vcard_widget;
79 $tpl = Renderer::getMarkupTemplate("videos_head.tpl");
80 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl);
86 function videos_post(App $a)
88 $owner_uid = $a->data['user']['uid'];
90 if (local_user() != $owner_uid) {
91 DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']);
94 if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
95 $video_id = $_POST['id'];
97 if (Attach::exists(['id' => $video_id, 'uid' => local_user()])) {
98 // delete the attachment
99 Attach::delete(['id' => $video_id, 'uid' => local_user()]);
101 // delete items where the attach is used
102 Item::deleteForUser(['`attach` LIKE ? AND `uid` = ?',
103 '%attach/' . $video_id . '%',
108 DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']);
109 return; // NOTREACHED
112 DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']);
115 function videos_content(App $a)
117 // URLs (most aren't currently implemented):
119 // videos/name/upload
120 // videos/name/upload/xxxxx (xxxxx is album name)
121 // videos/name/album/xxxxx
122 // videos/name/album/xxxxx/edit
123 // videos/name/video/xxxxx
124 // videos/name/video/xxxxx/edit
127 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
128 notice(DI::l10n()->t('Public access denied.'));
132 if (empty($a->data['user'])) {
133 notice(DI::l10n()->t('No videos selected') . EOL );
137 //$phototypes = Photo::supportedTypes();
139 $_SESSION['video_return'] = DI::args()->getCommand();
145 $datatype = $a->argv[2];
146 } elseif(($a->argc > 2) && ($a->argv[2] === 'upload')) {
147 $datatype = 'upload';
149 $datatype = 'summary';
153 // Setup permissions structures
158 $remote_contact = false;
161 $owner_uid = $a->data['user']['uid'];
163 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
165 if ((local_user()) && (local_user() == $owner_uid)) {
167 } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
168 $contact_id = Session::getRemoteContactID($owner_uid);
170 $remote_contact = true;
171 $visitor = $contact_id;
174 // perhaps they're visiting - but not a community page, so they wouldn't have write access
175 if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
176 $contact_id = Session::getRemoteContactID($owner_uid);
177 $remote_contact = true;
180 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
181 notice(DI::l10n()->t('Access to this item is restricted.'));
185 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
190 $_is_owner = (local_user() && (local_user() == $owner_uid));
191 $o .= BaseProfile::getTabsHTML($a, 'videos', $_is_owner, $a->data['user']['nickname']);
196 if ($datatype === 'upload') {
197 return; // no uploading for now
199 // DELETED -- look at mod/photos.php if you want to implement
202 if ($datatype === 'album') {
203 return; // no albums for now
205 // DELETED -- look at mod/photos.php if you want to implement
209 if ($datatype === 'video') {
210 return; // no single video view for now
212 // DELETED -- look at mod/photos.php if you want to implement
215 // Default - show recent videos (no upload link for now)
219 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
220 $sql_extra GROUP BY hash",
221 intval($a->data['user']['uid'])
223 if (DBA::isResult($r)) {
227 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
229 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
230 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
232 WHERE `uid` = %d AND filetype LIKE '%%video%%'
233 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
234 intval($a->data['user']['uid']),
236 $pager->getItemsPerPage()
241 if (DBA::isResult($r)) {
242 foreach ($r as $rr) {
243 $alt_e = $rr['filename'];
244 /// @todo The album isn't part of the above query. This seems to be some unfinished code that needs to be reworked completely.
246 $name_e = $rr['album'];
250 'link' => DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['hash'],
251 'title' => DI::l10n()->t('View Video'),
252 'src' => DI::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
254 'mime' => $rr['filetype'],
256 'link' => DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
258 'alt' => DI::l10n()->t('View Album'),
264 $tpl = Renderer::getMarkupTemplate('videos_recent.tpl');
265 $o .= Renderer::replaceMacros($tpl, [
266 '$title' => DI::l10n()->t('Recent Videos'),
267 '$can_post' => $can_post,
268 '$upload' => [DI::l10n()->t('Upload New Videos'), DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/upload'],
269 '$videos' => $videos,
270 '$delete_url' => (($can_post) ? DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] : false)
273 $o .= $pager->renderFull($total);