7 use Friendica\Content\Nav;
8 use Friendica\Core\Config;
9 use Friendica\Core\L10n;
10 use Friendica\Core\System;
11 use Friendica\Database\DBA;
12 use Friendica\Model\Contact;
13 use Friendica\Model\Group;
14 use Friendica\Model\Item;
15 use Friendica\Model\Profile;
16 use Friendica\Protocol\DFRN;
18 require_once 'include/items.php';
19 require_once 'include/security.php';
21 function videos_init(App $a)
24 DFRN::autoRedir($a, $a->argv[1]);
27 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
31 Nav::setSelected('home');
37 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
41 if (!DBA::isResult($user)) {
45 $a->data['user'] = $user[0];
46 $a->profile_uid = $user[0]['uid'];
48 $profile = Profile::getByNickname($nick, $a->profile_uid);
50 $account_type = Contact::getAccountType($profile);
52 $tpl = get_markup_template("vcard-widget.tpl");
54 $vcard_widget = replace_macros($tpl, [
55 '$name' => $profile['name'],
56 '$photo' => $profile['photo'],
57 '$addr' => defaults($profile, 'addr', ''),
58 '$account_type' => $account_type,
59 '$pdesc' => defaults($profile, 'pdesc', ''),
62 /// @TODO Old-lost code?
63 /*$sql_extra = permissions_sql($a->data['user']['uid']);
65 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
66 intval($a->data['user']['uid'])
70 $a->data['albums'] = $albums;
72 $albums_visible = ((intval($a->data['user']['hidewall']) && (!local_user()) && (!remote_user())) ? false : true);
75 $o .= '<div id="sidebar-photos-albums" class="widget">';
76 $o .= '<h3>' . '<a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '">' . L10n::t('Photo Albums') . '</a></h3>';
79 foreach($albums as $album) {
81 // don't show contact photos. We once translated this name, but then you could still access it under
82 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
84 if((!strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos')))
86 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
90 if(local_user() && $a->data['user']['uid'] == local_user()) {
91 $o .= '<div id="photo-albums-upload-link"><a href="' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .L10n::t('Upload New Photos') . '</a></div>';
97 // If not there, create 'aside' empty
98 if (!isset($a->page['aside'])) {
99 $a->page['aside'] = '';
102 $a->page['aside'] .= $vcard_widget;
104 $tpl = get_markup_template("videos_head.tpl");
105 $a->page['htmlhead'] .= replace_macros($tpl,[
106 '$baseurl' => System::baseUrl(),
109 $tpl = get_markup_template("videos_end.tpl");
110 $a->page['end'] .= replace_macros($tpl,[
111 '$baseurl' => System::baseUrl(),
119 function videos_post(App $a)
121 $owner_uid = $a->data['user']['uid'];
123 if (local_user() != $owner_uid) {
124 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
127 if (($a->argc == 2) && !empty($_POST['delete']) && !empty($_POST['id'])) {
128 // Check if we should do HTML-based delete confirmation
129 if (empty($_REQUEST['confirm'])) {
130 if (!empty($_REQUEST['canceled'])) {
131 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
134 $drop_url = $a->query_string;
136 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
138 '$message' => L10n::t('Do you really want to delete this video?'),
140 ['name' => 'id' , 'value' => $_POST['id']],
141 ['name' => 'delete', 'value' => 'x']
143 '$confirm' => L10n::t('Delete Video'),
144 '$confirm_url' => $drop_url,
145 '$confirm_name' => 'confirm', // Needed so that confirmation will bring us back into this if statement
146 '$cancel' => L10n::t('Cancel'),
150 $a->error = 1; // Set $a->error so the other module functions don't execute
155 $video_id = $_POST['id'];
157 $r = q("SELECT `id` FROM `attach` WHERE `uid` = %d AND `id` = '%s' LIMIT 1",
158 intval(local_user()),
159 DBA::escape($video_id)
162 if (DBA::isResult($r)) {
163 q("DELETE FROM `attach` WHERE `uid` = %d AND `id` = '%s'",
164 intval(local_user()),
165 DBA::escape($video_id)
168 $i = q("SELECT `id` FROM `item` WHERE `attach` like '%%attach/%s%%' AND `uid` = %d LIMIT 1",
169 DBA::escape($video_id),
173 if (DBA::isResult($i)) {
174 Item::deleteForUser(['id' => $i[0]['id']], local_user());
178 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
179 return; // NOTREACHED
182 goaway(System::baseUrl() . '/videos/' . $a->data['user']['nickname']);
185 function videos_content(App $a)
187 // URLs (most aren't currently implemented):
189 // videos/name/upload
190 // videos/name/upload/xxxxx (xxxxx is album name)
191 // videos/name/album/xxxxx
192 // videos/name/album/xxxxx/edit
193 // videos/name/video/xxxxx
194 // videos/name/video/xxxxx/edit
197 if ((Config::get('system', 'block_public')) && (!local_user()) && (!remote_user())) {
198 notice(L10n::t('Public access denied.') . EOL);
202 require_once 'include/security.php';
203 require_once 'include/conversation.php';
205 if (empty($a->data['user'])) {
206 notice(L10n::t('No videos selected') . EOL );
210 //$phototypes = Photo::supportedTypes();
212 $_SESSION['video_return'] = $a->cmd;
218 $datatype = $a->argv[2];
219 $datum = $a->argv[3];
220 } elseif(($a->argc > 2) && ($a->argv[2] === 'upload')) {
221 $datatype = 'upload';
223 $datatype = 'summary';
233 // Setup permissions structures
238 $remote_contact = false;
241 $owner_uid = $a->data['user']['uid'];
243 $community_page = (($a->data['user']['page-flags'] == Contact::PAGE_COMMUNITY) ? true : false);
245 if ((local_user()) && (local_user() == $owner_uid)) {
247 } elseif ($community_page && remote_user()) {
248 if (!empty($_SESSION['remote'])) {
249 foreach ($_SESSION['remote'] as $v) {
250 if ($v['uid'] == $owner_uid) {
251 $contact_id = $v['cid'];
257 if ($contact_id > 0) {
258 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
263 if (DBA::isResult($r)) {
266 $remote_contact = true;
267 $visitor = $contact_id;
274 // perhaps they're visiting - but not a community page, so they wouldn't have write access
275 if (remote_user() && (!$visitor)) {
277 if (!empty($_SESSION['remote'])) {
278 foreach($_SESSION['remote'] as $v) {
279 if($v['uid'] == $owner_uid) {
280 $contact_id = $v['cid'];
286 if ($contact_id > 0) {
287 $groups = Group::getIdsByContactId($contact_id);
288 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
293 if (DBA::isResult($r)) {
295 $remote_contact = true;
300 if (!$remote_contact && local_user()) {
301 $contact_id = $_SESSION['cid'];
302 $contact = $a->contact;
305 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (!$remote_contact)) {
306 notice(L10n::t('Access to this item is restricted.') . EOL);
310 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
315 $_is_owner = (local_user() && (local_user() == $owner_uid));
316 $o .= Profile::getTabs($a, $_is_owner, $a->data['user']['nickname']);
321 if ($datatype === 'upload') {
322 return; // no uploading for now
324 // DELETED -- look at mod/photos.php if you want to implement
327 if ($datatype === 'album') {
328 return; // no albums for now
330 // DELETED -- look at mod/photos.php if you want to implement
334 if ($datatype === 'video') {
335 return; // no single video view for now
337 // DELETED -- look at mod/photos.php if you want to implement
340 // Default - show recent videos (no upload link for now)
343 $r = q("SELECT hash FROM `attach` WHERE `uid` = %d AND filetype LIKE '%%video%%'
344 $sql_extra GROUP BY hash",
345 intval($a->data['user']['uid'])
348 if (DBA::isResult($r)) {
349 $a->set_pager_total(count($r));
350 $a->set_pager_itemspage(20);
353 $r = q("SELECT hash, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`created`) AS `created`,
354 ANY_VALUE(`filename`) AS `filename`, ANY_VALUE(`filetype`) as `filetype`
356 WHERE `uid` = %d AND filetype LIKE '%%video%%'
357 $sql_extra GROUP BY hash ORDER BY `created` DESC LIMIT %d , %d",
358 intval($a->data['user']['uid']),
359 intval($a->pager['start']),
360 intval($a->pager['itemspage'])
365 if (DBA::isResult($r)) {
366 foreach ($r as $rr) {
367 $alt_e = $rr['filename'];
368 /// @todo The album isn't part of the above query. This seems to be some unfinished code that needs to be reworked completely.
369 $name_e = $rr['album'];
373 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/video/' . $rr['resource-id'],
374 'title' => L10n::t('View Video'),
375 'src' => System::baseUrl() . '/attach/' . $rr['id'] . '?attachment=0',
377 'mime' => $rr['filetype'],
379 'link' => System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
381 'alt' => L10n::t('View Album'),
387 $tpl = get_markup_template('videos_recent.tpl');
388 $o .= replace_macros($tpl, [
389 '$title' => L10n::t('Recent Videos'),
390 '$can_post' => $can_post,
391 '$upload' => [L10n::t('Upload New Videos'), System::baseUrl() . '/videos/' . $a->data['user']['nickname'] . '/upload'],
392 '$videos' => $videos,
393 '$delete_url' => (($can_post) ? System::baseUrl() . '/videos/' . $a->data['user']['nickname'] : false)