7 use Friendica\Content\Nav;
8 use Friendica\Content\Pager;
9 use Friendica\Core\Config;
10 use Friendica\Core\L10n;
11 use Friendica\Core\System;
12 use Friendica\Database\DBA;
13 use Friendica\Model\Contact;
14 use Friendica\Model\Group;
15 use Friendica\Model\Item;
16 use Friendica\Model\Profile;
17 use Friendica\Protocol\DFRN;
18 use Friendica\Util\Security;
20 require_once 'include/items.php';
22 function videos_init(App $a)
25 DFRN::autoRedir($a, $a->argv[1]);
28 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
32 Nav::setSelected('home');
38 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
42 if (!DBA::isResult($user)) {
46 $a->data['user'] = $user[0];
47 $a->profile_uid = $user[0]['uid'];
49 $profile = Profile::getByNickname($nick, $a->profile_uid);
51 $account_type = Contact::getAccountType($profile);
53 $tpl = get_markup_template("vcard-widget.tpl");
55 $vcard_widget = replace_macros($tpl, [
56 '$name' => $profile['name'],
57 '$photo' => $profile['photo'],
58 '$addr' => defaults($profile, 'addr', ''),
59 '$account_type' => $account_type,
60 '$pdesc' => defaults($profile, 'pdesc', ''),
63 /// @TODO Old-lost code?
64 /*$sql_extra = Security::getPermissionsSQLByUserId($a->data['user']['uid']);
66 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
67 intval($a->data['user']['uid'])
71 $a->data['albums'] = $albums;
73 $albums_visible = ((intval($a->data['user']['hidewall']) && (!local_user()) && (!remote_user())) ? false : true);
76 $o .= '<div id="sidebar-photos-albums" class="widget">';
77 $o .= '<h3>' . '<a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '">' . L10n::t('Photo Albums') . '</a></h3>';
80 foreach($albums as $album) {
82 // don't show contact photos. We once translated this name, but then you could still access it under
83 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
85 if((!strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos')))
87 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
91 if(local_user() && $a->data['user']['uid'] == local_user()) {
92 $o .= '<div id="photo-albums-upload-link"><a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .L10n::t('Upload New Photos') . '</a></div>';
98 // If not there, create 'aside' empty
99 if (!isset($a->page['aside'])) {
100 $a->page['aside'] = '';
103 $a->page['aside'] .= $vcard_widget;
105 $tpl = get_markup_template("videos_head.tpl");
106 $a->page['htmlhead'] .= replace_macros($tpl,[
107 '$baseurl' => System::baseUrl(),
114 function videos_post(App $a)
116 $owner_uid = $a->data['user']['uid'];
118 if (local_user() != $owner_uid) {
119 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
122 if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
123 // Check if we should do HTML-based delete confirmation
124 if (empty($_REQUEST['confirm'])) {
125 if (!empty($_REQUEST['canceled'])) {
126 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
129 $drop_url = $a->query_string;
131 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
133 '$message' => L10n::t('Do you really want to delete this video?'),
135 ['name' => 'id' , 'value' => $_POST['id']],
136 ['name' => 'delete', 'value' => 'x']
138 '$confirm' => L10n::t('Delete Video'),
139 '$confirm_url' => $drop_url,
140 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
141 '$cancel' => L10n::t('Cancel'),
145 $a->error = 1; // Set $a->error so the other module functions don't execute
150 $video_id = $_POST['id'];
152 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
153 intval(local_user()),
154 DBA::escape($video_id)
157 if (DBA::isResult($r)) {
158 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
159 intval(local_user()),
160 DBA::escape($video_id)
163 $i = q("SELECT `id` FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
164 DBA::escape($video_id),
168 if (DBA::isResult($i)) {
169 Item::deleteForUser(['id' => $i[0]['id']], local_user());
173 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
174 return; // NOTREACHED
177 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
180 function videos_content(App $a)
182 // URLs (most aren't currently implemented):
184 // videos/name/upload
185 // videos/name/upload/xxxxx (xxxxx is album name)
186 // videos/name/album/xxxxx
187 // videos/name/album/xxxxx/edit
188 // videos/name/video/xxxxx
189 // videos/name/video/xxxxx/edit
192 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
193 notice(L10n::t('Public access denied.') . EOL);
197 require_once 'include/conversation.php';
199 if (empty($a->data['user'])) {
200 notice(L10n::t('No videos selected') . EOL );
204 //$phototypes = Photo::supportedTypes();
206 $_SESSION['video_return'] = $a->cmd;
212 $datatype = $a->argv[2];
213 $datum = $a->argv[3];
214 } elseif(($a->argc > 2) && ($a->argv[2] === 'upload')) {
215 $datatype = 'upload';
217 $datatype = 'summary';
227 // Setup permissions structures
232 $remote_contact = false;
235 $owner_uid = $a->data['user']['uid'];
237 $community_page = (($a->data['user']['page-flags'] == Contact::PAGE_COMMUNITY) ? true : false);
239 if ((local_user()) && (local_user() == $owner_uid)) {
241 } elseif ($community_page && remote_user()) {
242 if (!empty($_SESSION['remote'])) {
243 foreach ($_SESSION['remote'] as $v) {
244 if ($v['uid'] == $owner_uid) {
245 $contact_id = $v['cid'];
251 if ($contact_id > 0) {
252 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
257 if (DBA::isResult($r)) {
260 $remote_contact = true;
261 $visitor = $contact_id;
268 // perhaps they're visiting - but not a community page, so they wouldn't have write access
269 if (remote_user() && (!$visitor)) {
272 if (!empty($_SESSION['remote'])) {
273 foreach($_SESSION['remote'] as $v) {
274 if($v['uid'] == $owner_uid) {
275 $contact_id = $v['cid'];
281 if ($contact_id > 0) {
282 $groups = Group::getIdsByContactId($contact_id);
283 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
288 if (DBA::isResult($r)) {
290 $remote_contact = true;
295 if (!$remote_contact && local_user()) {
296 $contact_id = $_SESSION['cid'];
297 $contact = $a->contact;
300 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (!$remote_contact)) {
301 notice(L10n::t('Access to this item is restricted.') . EOL);
305 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid, $remote_contact, $groups);
310 $_is_owner = (local_user() && (local_user() == $owner_uid));
311 $o .= Profile::getTabs($a, $_is_owner, $a->data['user']['nickname']);
316 if ($datatype === 'upload') {
317 return; // no uploading for now
319 // DELETED -- look at mod/photos.php if you want to implement
322 if ($datatype === 'album') {
323 return; // no albums for now
325 // DELETED -- look at mod/photos.php if you want to implement
329 if ($datatype === 'video') {
330 return; // no single video view for now
332 // DELETED -- look at mod/photos.php if you want to implement
335 // Default - show recent videos (no upload link for now)
339 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
340 $sql_extra GROUP BY hash",
341 intval($a->data['user']['uid'])
343 if (DBA::isResult($r)) {
346 $pager = new Pager($a->query_string, $total, 20);
348 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
349 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
351 WHERE `uid` = %d AND filetype LIKE '%%video%%'
352 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
353 intval($a->data['user']['uid']),
355 $pager->getItemsPerPage()
360 if (DBA::isResult($r)) {
361 foreach ($r as $rr) {
362 $alt_e = $rr['filename'];
363 /// @todo The album isn't part of the above query. This seems to be some unfinished code that needs to be reworked completely.
365 $name_e = $rr['album'];
369 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['hash'],
370 'title' => L10n::t('View Video'),
371 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
373 'mime' => $rr['filetype'],
375 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
377 'alt' => L10n::t('View Album'),
383 $tpl = get_markup_template('videos_recent.tpl');
384 $o .= replace_macros($tpl, [
385 '$title' => L10n::t('Recent Videos'),
386 '$can_post' => $can_post,
387 '$upload' => [L10n::t('Upload New Videos'), System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/upload'],
388 '$videos' => $videos,
389 '$delete_url' => (($can_post) ? System::baseUrl() . '/videos/' . $a->data['user']['nickname'] : false)
392 $o .= $pager->renderFull();