3 * @copyright Copyright (C) 2020, Friendica
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\Profile;
34 use Friendica\Model\User;
35 use Friendica\Module\BaseProfile;
36 use Friendica\Util\Security;
38 function videos_init(App $a)
40 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
44 Nav::setSelected('home');
48 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
52 if (!DBA::isResult($user)) {
56 $a->data['user'] = $user[0];
57 $a->profile_uid = $user[0]['uid'];
59 $profile = Profile::getByNickname($nick, $a->profile_uid);
61 $account_type = Contact::getAccountType($profile);
63 $tpl = Renderer::getMarkupTemplate('widget/vcard.tpl');
65 $vcard_widget = Renderer::replaceMacros($tpl, [
66 '$name' => $profile['name'],
67 '$photo' => $profile['photo'],
68 '$addr' => $profile['addr'] ?? '',
69 '$account_type' => $account_type,
70 '$about' => BBCode::convert($profile['about']),
73 // If not there, create 'aside' empty
74 if (!isset(DI::page()['aside'])) {
75 DI::page()['aside'] = '';
78 DI::page()['aside'] .= $vcard_widget;
80 $tpl = Renderer::getMarkupTemplate("videos_head.tpl");
81 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl);
87 function videos_post(App $a)
89 $owner_uid = $a->data['user']['uid'];
91 if (local_user() != $owner_uid) {
92 DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']);
95 if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
96 $video_id = $_POST['id'];
98 if (Attach::exists(['id' => $video_id, 'uid' => local_user()])) {
99 // delete the attachment
100 Attach::delete(['id' => $video_id, 'uid' => local_user()]);
102 // delete items where the attach is used
103 Item::deleteForUser(['`attach` LIKE ? AND `uid` = ?',
104 '%attach/' . $video_id . '%',
109 DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']);
110 return; // NOTREACHED
113 DI::baseUrl()->redirect('videos/' . $a->data['user']['nickname']);
116 function videos_content(App $a)
118 // URLs (most aren't currently implemented):
120 // videos/name/upload
121 // videos/name/upload/xxxxx (xxxxx is album name)
122 // videos/name/album/xxxxx
123 // videos/name/album/xxxxx/edit
124 // videos/name/video/xxxxx
125 // videos/name/video/xxxxx/edit
128 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
129 notice(DI::l10n()->t('Public access denied.'));
133 if (empty($a->data['user'])) {
134 notice(DI::l10n()->t('No videos selected') . EOL );
138 //$phototypes = Photo::supportedTypes();
140 $_SESSION['video_return'] = DI::args()->getCommand();
146 $datatype = $a->argv[2];
147 } elseif(($a->argc > 2) && ($a->argv[2] === 'upload')) {
148 $datatype = 'upload';
150 $datatype = 'summary';
154 // Setup permissions structures
159 $remote_contact = false;
162 $owner_uid = $a->data['user']['uid'];
164 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
166 if ((local_user()) && (local_user() == $owner_uid)) {
168 } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
169 $contact_id = Session::getRemoteContactID($owner_uid);
171 $remote_contact = true;
172 $visitor = $contact_id;
175 // perhaps they're visiting - but not a community page, so they wouldn't have write access
176 if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
177 $contact_id = Session::getRemoteContactID($owner_uid);
178 $remote_contact = true;
181 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
182 notice(DI::l10n()->t('Access to this item is restricted.'));
186 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
191 $_is_owner = (local_user() && (local_user() == $owner_uid));
192 $o .= BaseProfile::getTabsHTML($a, 'videos', $_is_owner, $a->data['user']['nickname']);
197 if ($datatype === 'upload') {
198 return; // no uploading for now
200 // DELETED -- look at mod/photos.php if you want to implement
203 if ($datatype === 'album') {
204 return; // no albums for now
206 // DELETED -- look at mod/photos.php if you want to implement
210 if ($datatype === 'video') {
211 return; // no single video view for now
213 // DELETED -- look at mod/photos.php if you want to implement
216 // Default - show recent videos (no upload link for now)
220 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
221 $sql_extra GROUP BY hash",
222 intval($a->data['user']['uid'])
224 if (DBA::isResult($r)) {
228 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
230 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
231 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
233 WHERE `uid` = %d AND filetype LIKE '%%video%%'
234 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
235 intval($a->data['user']['uid']),
237 $pager->getItemsPerPage()
242 if (DBA::isResult($r)) {
243 foreach ($r as $rr) {
244 $alt_e = $rr['filename'];
245 /// @todo The album isn't part of the above query. This seems to be some unfinished code that needs to be reworked completely.
247 $name_e = $rr['album'];
251 'link' => DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['hash'],
252 'title' => DI::l10n()->t('View Video'),
253 'src' => DI::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
255 'mime' => $rr['filetype'],
257 'link' => DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
259 'alt' => DI::l10n()->t('View Album'),
265 $tpl = Renderer::getMarkupTemplate('videos_recent.tpl');
266 $o .= Renderer::replaceMacros($tpl, [
267 '$title' => DI::l10n()->t('Recent Videos'),
268 '$can_post' => $can_post,
269 '$upload' => [DI::l10n()->t('Upload New Videos'), DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/upload'],
270 '$videos' => $videos,
271 '$delete_url' => (($can_post) ? DI::baseUrl() . '/videos/' . $a->data['user']['nickname'] : false)
274 $o .= $pager->renderFull($total);