7 use Friendica\Content\Nav;
8 use Friendica\Content\Pager;
9 use Friendica\Core\Config;
10 use Friendica\Core\L10n;
11 use Friendica\Core\Renderer;
12 use Friendica\Core\System;
13 use Friendica\Database\DBA;
14 use Friendica\Model\Contact;
15 use Friendica\Model\Group;
16 use Friendica\Model\Item;
17 use Friendica\Model\Profile;
18 use Friendica\Protocol\DFRN;
19 use Friendica\Util\Security;
21 require_once 'include/items.php';
23 function videos_init(App $a)
26 DFRN::autoRedir($a, $a->argv[1]);
29 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
33 Nav::setSelected('home');
39 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
43 if (!DBA::isResult($user)) {
47 $a->data['user'] = $user[0];
48 $a->profile_uid = $user[0]['uid'];
50 $profile = Profile::getByNickname($nick, $a->profile_uid);
52 $account_type = Contact::getAccountType($profile);
54 $tpl = Renderer::getMarkupTemplate("vcard-widget.tpl");
56 $vcard_widget = Renderer::replaceMacros($tpl, [
57 '$name' => $profile['name'],
58 '$photo' => $profile['photo'],
59 '$addr' => defaults($profile, 'addr', ''),
60 '$account_type' => $account_type,
61 '$pdesc' => defaults($profile, 'pdesc', ''),
64 /// @TODO Old-lost code?
65 /*$sql_extra = Security::getPermissionsSQLByUserId($a->data['user']['uid']);
67 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
68 intval($a->data['user']['uid'])
72 $a->data['albums'] = $albums;
74 $albums_visible = ((intval($a->data['user']['hidewall']) && (!local_user()) && (!remote_user())) ? false : true);
77 $o .= '<div id="sidebar-photos-albums" class="widget">';
78 $o .= '<h3>' . '<a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '">' . L10n::t('Photo Albums') . '</a></h3>';
81 foreach($albums as $album) {
83 // don't show contact photos. We once translated this name, but then you could still access it under
84 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
86 if((!strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos')))
88 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
92 if(local_user() && $a->data['user']['uid'] == local_user()) {
93 $o .= '<div id="photo-albums-upload-link"><a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .L10n::t('Upload New Photos') . '</a></div>';
99 // If not there, create 'aside' empty
100 if (!isset($a->page['aside'])) {
101 $a->page['aside'] = '';
104 $a->page['aside'] .= $vcard_widget;
106 $tpl = Renderer::getMarkupTemplate("videos_head.tpl");
107 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl,[
108 '$baseurl' => System::baseUrl(),
115 function videos_post(App $a)
117 $owner_uid = $a->data['user']['uid'];
119 if (local_user() != $owner_uid) {
120 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
123 if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
124 // Check if we should do HTML-based delete confirmation
125 if (empty($_REQUEST['confirm'])) {
126 if (!empty($_REQUEST['canceled'])) {
127 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
130 $drop_url = $a->query_string;
132 $a->page['content'] = Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
134 '$message' => L10n::t('Do you really want to delete this video?'),
136 ['name' => 'id' , 'value' => $_POST['id']],
137 ['name' => 'delete', 'value' => 'x']
139 '$confirm' => L10n::t('Delete Video'),
140 '$confirm_url' => $drop_url,
141 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
142 '$cancel' => L10n::t('Cancel'),
146 $a->error = 1; // Set $a->error so the other module functions don't execute
151 $video_id = $_POST['id'];
153 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
154 intval(local_user()),
155 DBA::escape($video_id)
158 if (DBA::isResult($r)) {
159 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
160 intval(local_user()),
161 DBA::escape($video_id)
164 $i = q("SELECT `id` FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
165 DBA::escape($video_id),
169 if (DBA::isResult($i)) {
170 Item::deleteForUser(['id' => $i[0]['id']], local_user());
174 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
175 return; // NOTREACHED
178 $a->internalRedirect('videos/' . $a->data['user']['nickname']);
181 function videos_content(App $a)
183 // URLs (most aren't currently implemented):
185 // videos/name/upload
186 // videos/name/upload/xxxxx (xxxxx is album name)
187 // videos/name/album/xxxxx
188 // videos/name/album/xxxxx/edit
189 // videos/name/video/xxxxx
190 // videos/name/video/xxxxx/edit
193 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
194 notice(L10n::t('Public access denied.') . EOL);
198 require_once 'include/conversation.php';
200 if (empty($a->data['user'])) {
201 notice(L10n::t('No videos selected') . EOL );
205 //$phototypes = Photo::supportedTypes();
207 $_SESSION['video_return'] = $a->cmd;
213 $datatype = $a->argv[2];
214 $datum = $a->argv[3];
215 } elseif(($a->argc > 2) && ($a->argv[2] === 'upload')) {
216 $datatype = 'upload';
218 $datatype = 'summary';
228 // Setup permissions structures
233 $remote_contact = false;
236 $owner_uid = $a->data['user']['uid'];
238 $community_page = (($a->data['user']['page-flags'] == Contact::PAGE_COMMUNITY) ? true : false);
240 if ((local_user()) && (local_user() == $owner_uid)) {
242 } elseif ($community_page && remote_user()) {
243 if (!empty($_SESSION['remote'])) {
244 foreach ($_SESSION['remote'] as $v) {
245 if ($v['uid'] == $owner_uid) {
246 $contact_id = $v['cid'];
252 if ($contact_id > 0) {
253 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
258 if (DBA::isResult($r)) {
261 $remote_contact = true;
262 $visitor = $contact_id;
269 // perhaps they're visiting - but not a community page, so they wouldn't have write access
270 if (remote_user() && (!$visitor)) {
273 if (!empty($_SESSION['remote'])) {
274 foreach($_SESSION['remote'] as $v) {
275 if($v['uid'] == $owner_uid) {
276 $contact_id = $v['cid'];
282 if ($contact_id > 0) {
283 $groups = Group::getIdsByContactId($contact_id);
284 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
289 if (DBA::isResult($r)) {
291 $remote_contact = true;
296 if (!$remote_contact && local_user()) {
297 $contact_id = $_SESSION['cid'];
298 $contact = $a->contact;
301 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (!$remote_contact)) {
302 notice(L10n::t('Access to this item is restricted.') . EOL);
306 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid, $remote_contact, $groups);
311 $_is_owner = (local_user() && (local_user() == $owner_uid));
312 $o .= Profile::getTabs($a, $_is_owner, $a->data['user']['nickname']);
317 if ($datatype === 'upload') {
318 return; // no uploading for now
320 // DELETED -- look at mod/photos.php if you want to implement
323 if ($datatype === 'album') {
324 return; // no albums for now
326 // DELETED -- look at mod/photos.php if you want to implement
330 if ($datatype === 'video') {
331 return; // no single video view for now
333 // DELETED -- look at mod/photos.php if you want to implement
336 // Default - show recent videos (no upload link for now)
340 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
341 $sql_extra GROUP BY hash",
342 intval($a->data['user']['uid'])
344 if (DBA::isResult($r)) {
348 $pager = new Pager($a->query_string, 20);
350 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
351 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
353 WHERE `uid` = %d AND filetype LIKE '%%video%%'
354 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
355 intval($a->data['user']['uid']),
357 $pager->getItemsPerPage()
362 if (DBA::isResult($r)) {
363 foreach ($r as $rr) {
364 $alt_e = $rr['filename'];
365 /// @todo The album isn't part of the above query. This seems to be some unfinished code that needs to be reworked completely.
367 $name_e = $rr['album'];
371 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['hash'],
372 'title' => L10n::t('View Video'),
373 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
375 'mime' => $rr['filetype'],
377 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
379 'alt' => L10n::t('View Album'),
385 $tpl = Renderer::getMarkupTemplate('videos_recent.tpl');
386 $o .= Renderer::replaceMacros($tpl, [
387 '$title' => L10n::t('Recent Videos'),
388 '$can_post' => $can_post,
389 '$upload' => [L10n::t('Upload New Videos'), System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/upload'],
390 '$videos' => $videos,
391 '$delete_url' => (($can_post) ? System::baseUrl() . '/videos/' . $a->data['user']['nickname'] : false)
394 $o .= $pager->renderFull($total);