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\Feature;
24 use Friendica\Content\Nav;
25 use Friendica\Content\Pager;
26 use Friendica\Content\Text\BBCode;
27 use Friendica\Core\ACL;
28 use Friendica\Core\Addon;
29 use Friendica\Core\Hook;
30 use Friendica\Core\Logger;
31 use Friendica\Core\Renderer;
32 use Friendica\Core\Session;
33 use Friendica\Core\System;
34 use Friendica\Database\DBA;
36 use Friendica\Model\Contact;
37 use Friendica\Model\Item;
38 use Friendica\Model\Photo;
39 use Friendica\Model\Post;
40 use Friendica\Model\Profile;
41 use Friendica\Model\Tag;
42 use Friendica\Model\User;
43 use Friendica\Module\BaseProfile;
44 use Friendica\Network\Probe;
45 use Friendica\Object\Image;
46 use Friendica\Protocol\Activity;
47 use Friendica\Util\Crypto;
48 use Friendica\Util\DateTimeFormat;
49 use Friendica\Util\Images;
50 use Friendica\Util\Map;
51 use Friendica\Security\Security;
52 use Friendica\Util\Strings;
53 use Friendica\Util\Temporal;
54 use Friendica\Util\XML;
56 function photos_init(App $a) {
58 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
62 Nav::setSelected('home');
66 $user = DBA::selectFirst('user', [], ['nickname' => $nick, 'blocked' => false]);
68 if (!DBA::isResult($user)) {
72 $a->data['user'] = $user;
73 $a->profile_uid = $user['uid'];
74 $is_owner = (local_user() && (local_user() == $a->profile_uid));
76 $profile = Profile::getByNickname($nick, $a->profile_uid);
78 $account_type = Contact::getAccountType($profile);
80 $tpl = Renderer::getMarkupTemplate('widget/vcard.tpl');
82 $vcard_widget = Renderer::replaceMacros($tpl, [
83 '$name' => $profile['name'],
84 '$photo' => $profile['photo'],
85 '$addr' => $profile['addr'] ?? '',
86 '$account_type' => $account_type,
87 '$about' => BBCode::convert($profile['about']),
90 $albums = Photo::getAlbums($a->data['user']['uid']);
92 $albums_visible = ((intval($a->data['user']['hidewall']) && !Session::isAuthenticated()) ? false : true);
94 // add various encodings to the array so we can just loop through and pick them out in a template
95 $ret = ['success' => false];
98 $a->data['albums'] = $albums;
100 if ($albums_visible) {
101 $ret['success'] = true;
105 foreach ($albums as $k => $album) {
106 //hide profile photos to others
107 if (!$is_owner && !Session::getRemoteContactID($a->profile_uid) && ($album['album'] == DI::l10n()->t('Profile Photos')))
110 'text' => $album['album'],
111 'total' => $album['total'],
112 'url' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
113 'urlencode' => urlencode($album['album']),
114 'bin2hex' => bin2hex($album['album'])
116 $ret['albums'][] = $entry;
120 if (local_user() && $a->data['user']['uid'] == local_user()) {
126 if ($ret['success']) {
127 $photo_albums_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('photo_albums.tpl'), [
128 '$nick' => $a->data['user']['nickname'],
129 '$title' => DI::l10n()->t('Photo Albums'),
130 '$recent' => DI::l10n()->t('Recent Photos'),
131 '$albums' => $ret['albums'],
132 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'],
133 '$can_post' => $can_post
137 if (empty(DI::page()['aside'])) {
138 DI::page()['aside'] = '';
141 DI::page()['aside'] .= $vcard_widget;
143 if (!empty($photo_albums_widget)) {
144 DI::page()['aside'] .= $photo_albums_widget;
147 $tpl = Renderer::getMarkupTemplate("photos_head.tpl");
149 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
150 '$ispublic' => DI::l10n()->t('everybody')
157 function photos_post(App $a)
159 $phototypes = Images::supportedTypes();
164 $page_owner_uid = intval($a->data['user']['uid']);
165 $community_page = $a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
167 if (local_user() && (local_user() == $page_owner_uid)) {
169 } elseif ($community_page && !empty(Session::getRemoteContactID($page_owner_uid))) {
170 $contact_id = Session::getRemoteContactID($page_owner_uid);
172 $visitor = $contact_id;
176 notice(DI::l10n()->t('Permission denied.'));
180 $owner_record = User::getOwnerDataById($page_owner_uid);
182 if (!$owner_record) {
183 notice(DI::l10n()->t('Contact information unavailable'));
184 DI::logger()->info('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
188 $aclFormatter = DI::aclFormatter();
189 $str_contact_allow = isset($_REQUEST['contact_allow']) ? $aclFormatter->toString($_REQUEST['contact_allow']) : $owner_record['allow_cid'] ?? '';
190 $str_group_allow = isset($_REQUEST['group_allow']) ? $aclFormatter->toString($_REQUEST['group_allow']) : $owner_record['allow_gid'] ?? '';
191 $str_contact_deny = isset($_REQUEST['contact_deny']) ? $aclFormatter->toString($_REQUEST['contact_deny']) : $owner_record['deny_cid'] ?? '';
192 $str_group_deny = isset($_REQUEST['group_deny']) ? $aclFormatter->toString($_REQUEST['group_deny']) : $owner_record['deny_gid'] ?? '';
194 $visibility = $_REQUEST['visibility'] ?? '';
195 if ($visibility === 'public') {
196 // The ACL selector introduced in version 2019.12 sends ACL input data even when the Public visibility is selected
197 $str_contact_allow = $str_group_allow = $str_contact_deny = $str_group_deny = '';
198 } else if ($visibility === 'custom') {
199 // Since we know from the visibility parameter the item should be private, we have to prevent the empty ACL
200 // case that would make it public. So we always append the author's contact id to the allowed contacts.
201 // See https://github.com/friendica/friendica/issues/9672
202 $str_contact_allow .= $aclFormatter->toString(Contact::getPublicIdByUserId($page_owner_uid));
205 if ($a->argc > 3 && $a->argv[2] === 'album') {
206 if (!Strings::isHex($a->argv[3])) {
207 DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname'] . '/album');
209 $album = hex2bin($a->argv[3]);
211 if ($album === DI::l10n()->t('Profile Photos') || $album === Photo::CONTACT_PHOTOS || $album === DI::l10n()->t(Photo::CONTACT_PHOTOS)) {
212 DI::baseUrl()->redirect($_SESSION['photo_return']);
213 return; // NOTREACHED
216 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
218 intval($page_owner_uid)
221 if (!DBA::isResult($r)) {
222 notice(DI::l10n()->t('Album not found.'));
223 DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname'] . '/album');
224 return; // NOTREACHED
227 // Check if the user has responded to a delete confirmation query
228 if (!empty($_REQUEST['canceled'])) {
229 DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname'] . '/album/' . $a->argv[3]);
232 // RENAME photo album
233 $newalbum = Strings::escapeTags(trim($_POST['albumname']));
234 if ($newalbum != $album) {
235 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
236 DBA::escape($newalbum),
238 intval($page_owner_uid)
240 // Update the photo albums cache
241 Photo::clearAlbumCache($page_owner_uid);
243 DI::baseUrl()->redirect('photos/' . $a->user['nickname'] . '/album/' . bin2hex($newalbum));
244 return; // NOTREACHED
248 * DELETE all photos filed in a given album
250 if (!empty($_POST['dropalbum'])) {
253 // get the list of photos we are about to delete
255 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
257 intval($page_owner_uid),
261 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
262 intval(local_user()),
267 if (DBA::isResult($r)) {
268 foreach ($r as $rr) {
272 // remove the associated photos
273 Photo::delete(['resource-id' => $res, 'uid' => $page_owner_uid]);
275 // find and delete the corresponding item with all the comments and likes/dislikes
276 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
278 // Update the photo albums cache
279 Photo::clearAlbumCache($page_owner_uid);
280 notice(DI::l10n()->t('Album successfully deleted'));
282 notice(DI::l10n()->t('Album was empty.'));
286 DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname'] . '/album');
289 if ($a->argc > 3 && $a->argv[2] === 'image') {
290 // Check if the user has responded to a delete confirmation query for a single photo
291 if (!empty($_POST['canceled'])) {
292 DI::baseUrl()->redirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]);
295 if (!empty($_POST['delete'])) {
296 // same as above but remove single photo
298 $condition = ['contact-id' => $visitor, 'uid' => $page_owner_uid, 'resource-id' => $a->argv[3]];
301 $condition = ['uid' => local_user(), 'resource-id' => $a->argv[3]];
304 $photo = DBA::selectFirst('photo', ['resource-id'], $condition);
306 if (DBA::isResult($photo)) {
307 Photo::delete(['uid' => $page_owner_uid, 'resource-id' => $photo['resource-id']]);
309 Item::deleteForUser(['resource-id' => $photo['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
311 // Update the photo albums cache
312 Photo::clearAlbumCache($page_owner_uid);
314 notice(DI::l10n()->t('Failed to delete the photo.'));
315 DI::baseUrl()->redirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]);
318 DI::baseUrl()->redirect('photos/' . $a->argv[1]);
319 return; // NOTREACHED
323 if ($a->argc > 2 && (!empty($_POST['desc']) || !empty($_POST['newtag']) || isset($_POST['albname']))) {
324 $desc = !empty($_POST['desc']) ? Strings::escapeTags(trim($_POST['desc'])) : '';
325 $rawtags = !empty($_POST['newtag']) ? Strings::escapeTags(trim($_POST['newtag'])) : '';
326 $item_id = !empty($_POST['item_id']) ? intval($_POST['item_id']) : 0;
327 $albname = !empty($_POST['albname']) ? trim($_POST['albname']) : '';
328 $origaname = !empty($_POST['origaname']) ? Strings::escapeTags(trim($_POST['origaname'])) : '';
330 $resource_id = $a->argv[3];
332 if (!strlen($albname)) {
333 $albname = DateTimeFormat::localNow('Y');
336 if (!empty($_POST['rotate']) && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
337 Logger::log('rotate');
339 $photo = Photo::getPhotoForUser($page_owner_uid, $resource_id);
341 if (DBA::isResult($photo)) {
342 $image = Photo::getImageForPhoto($photo);
344 if ($image->isValid()) {
345 $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
346 $image->rotate($rotate_deg);
348 $width = $image->getWidth();
349 $height = $image->getHeight();
351 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 0], $image);
353 if ($width > 640 || $height > 640) {
354 $image->scaleDown(640);
355 $width = $image->getWidth();
356 $height = $image->getHeight();
358 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 1], $image);
361 if ($width > 320 || $height > 320) {
362 $image->scaleDown(320);
363 $width = $image->getWidth();
364 $height = $image->getHeight();
366 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 2], $image);
372 $photos_stmt = DBA::select('photo', [], ['resource-id' => $resource_id, 'uid' => $page_owner_uid], ['order' => ['scale' => true]]);
374 $photos = DBA::toArray($photos_stmt);
376 if (DBA::isResult($photos)) {
378 $ext = $phototypes[$photo['type']];
380 ['desc' => $desc, 'album' => $albname, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow, 'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny],
381 ['resource-id' => $resource_id, 'uid' => $page_owner_uid]
384 // Update the photo albums cache if album name was changed
385 if ($albname !== $origaname) {
386 Photo::clearAlbumCache($page_owner_uid);
388 /* Don't make the item visible if the only change was the album name */
391 if ($photo['desc'] !== $desc || strlen($rawtags)) {
396 if (DBA::isResult($photos) && !$item_id) {
397 // Create item container
399 $uri = Item::newURI($page_owner_uid);
402 $arr['guid'] = System::createUUID();
403 $arr['uid'] = $page_owner_uid;
405 $arr['post-type'] = Item::PT_IMAGE;
407 $arr['resource-id'] = $photo['resource-id'];
408 $arr['contact-id'] = $owner_record['id'];
409 $arr['owner-name'] = $owner_record['name'];
410 $arr['owner-link'] = $owner_record['url'];
411 $arr['owner-avatar'] = $owner_record['thumb'];
412 $arr['author-name'] = $owner_record['name'];
413 $arr['author-link'] = $owner_record['url'];
414 $arr['author-avatar'] = $owner_record['thumb'];
415 $arr['title'] = $title;
416 $arr['allow_cid'] = $photo['allow_cid'];
417 $arr['allow_gid'] = $photo['allow_gid'];
418 $arr['deny_cid'] = $photo['deny_cid'];
419 $arr['deny_gid'] = $photo['deny_gid'];
420 $arr['visible'] = $visibility;
423 $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $photo['resource-id'] . ']'
424 . '[img]' . DI::baseUrl() . '/photo/' . $photo['resource-id'] . '-' . $photo['scale'] . '.'. $ext . '[/img]'
427 $item_id = Item::insert($arr);
431 $item = Post::selectFirst(['tag', 'inform', 'uri-id'], ['id' => $item_id, 'uid' => $page_owner_uid]);
433 if (DBA::isResult($item)) {
434 $old_inform = $item['inform'];
438 if (strlen($rawtags)) {
441 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
442 $x = substr($rawtags, 0, 1);
443 if ($x !== '@' && $x !== '#') {
444 $rawtags = '#' . $rawtags;
448 $tags = BBCode::getTags($rawtags);
451 foreach ($tags as $tag) {
452 if (strpos($tag, '@') === 0) {
455 $name = substr($tag,1);
457 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
459 $links = @Probe::lrdd($name);
462 foreach ($links as $link) {
463 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
464 $profile = $link['@attributes']['href'];
467 if ($link['@attributes']['rel'] === 'salmon') {
468 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
470 if (strlen($inform)) {
479 $taginfo[] = [$newname, $profile, $salmon];
484 if (strrpos($newname, '+')) {
485 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
489 $contact = DBA::selectFirst('contact', [], ['id' => $tagcid, 'uid' => $page_owner_uid]);
491 $newname = str_replace('_',' ',$name);
493 //select someone from this user's contacts by name
494 $contact = DBA::selectFirst('contact', [], ['name' => $newname, 'uid' => $page_owner_uid]);
495 if (!DBA::isResult($contact)) {
496 //select someone by attag or nick and the name passed in
497 $contact = DBA::selectFirst('contact', [],
498 ['(`attag` = ? OR `nick` = ?) AND `uid` = ?', $name, $name, $page_owner_uid],
499 ['order' => ['attag' => true]]
504 if (DBA::isResult($contact)) {
505 $newname = $contact['name'];
506 $profile = $contact['url'];
508 $notify = 'cid:' . $contact['id'];
509 if (strlen($inform)) {
517 if (!empty($contact)) {
518 $taginfo[] = [$newname, $profile, $notify, $contact];
520 $taginfo[] = [$newname, $profile, $notify, null];
523 $profile = str_replace(',', '%2c', $profile);
525 if (!empty($item['uri-id'])) {
526 Tag::store($item['uri-id'], Tag::MENTION, $newname, $profile);
529 } elseif (strpos($tag, '#') === 0) {
530 $tagname = substr($tag, 1);
531 if (!empty($item['uri-id'])) {
532 Tag::store($item['uri-id'], Tag::HASHTAG, $tagname);
538 $newinform = $old_inform ?? '';
539 if (strlen($newinform) && strlen($inform)) {
542 $newinform .= $inform;
544 $fields = ['inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
545 $condition = ['id' => $item_id];
546 Item::update($fields, $condition);
549 foreach ($photos as $scales) {
550 if (intval($scales['scale']) == 2) {
555 if (intval($scales['scale']) == 4) {
561 if (count($taginfo)) {
562 foreach ($taginfo as $tagged) {
563 $uri = Item::newURI($page_owner_uid);
566 $arr['guid'] = System::createUUID();
567 $arr['uid'] = $page_owner_uid;
570 $arr['contact-id'] = $owner_record['id'];
571 $arr['owner-name'] = $owner_record['name'];
572 $arr['owner-link'] = $owner_record['url'];
573 $arr['owner-avatar'] = $owner_record['thumb'];
574 $arr['author-name'] = $owner_record['name'];
575 $arr['author-link'] = $owner_record['url'];
576 $arr['author-avatar'] = $owner_record['thumb'];
578 $arr['allow_cid'] = $photo['allow_cid'];
579 $arr['allow_gid'] = $photo['allow_gid'];
580 $arr['deny_cid'] = $photo['deny_cid'];
581 $arr['deny_gid'] = $photo['deny_gid'];
583 $arr['verb'] = Activity::TAG;
584 $arr['gravity'] = GRAVITY_PARENT;
585 $arr['object-type'] = Activity\ObjectType::PERSON;
586 $arr['target-type'] = Activity\ObjectType::IMAGE;
587 $arr['inform'] = $tagged[2];
589 $arr['body'] = DI::l10n()->t('%1$s was tagged in %2$s by %3$s', '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]', '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . ']' . DI::l10n()->t('a photo') . '[/url]', '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]') ;
590 $arr['body'] .= "\n\n" . '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . ']' . '[img]' . DI::baseUrl() . "/photo/" . $photo['resource-id'] . '-' . $best . '.' . $ext . '[/img][/url]' . "\n" ;
592 $arr['object'] = '<object><type>' . Activity\ObjectType::PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
593 $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
595 $arr['object'] .= XML::escape('<link rel="photo" type="' . $photo['type'] . '" href="' . $tagged[3]['photo'] . '" />' . "\n");
597 $arr['object'] .= '</link></object>' . "\n";
599 $arr['target'] = '<target><type>' . Activity\ObjectType::IMAGE . '</type><title>' . $photo['desc'] . '</title><id>'
600 . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '</id>';
601 $arr['target'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '" />' . "\n" . '<link rel="preview" type="' . $photo['type'] . '" href="' . DI::baseUrl() . "/photo/" . $photo['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>';
607 DI::baseUrl()->redirect($_SESSION['photo_return']);
608 return; // NOTREACHED
612 // default post action - upload a photo
613 Hook::callAll('photo_post_init', $_POST);
615 // Determine the album to use
616 $album = trim($_REQUEST['album'] ?? '');
617 $newalbum = trim($_REQUEST['newalbum'] ?? '');
619 Logger::info('album= ' . $album . ' newalbum= ' . $newalbum);
621 if (!strlen($album)) {
622 if (strlen($newalbum)) {
625 $album = DateTimeFormat::localNow('Y');
630 * We create a wall item for every photo, but we don't want to
631 * overwhelm the data stream with a hundred newly uploaded photos.
632 * So we will make the first photo uploaded to this album in the last several hours
633 * visible by default, the rest will become visible over time when and if
634 * they acquire comments, likes, dislikes, and/or tags
637 $r = Photo::selectToArray([], ['`album` = ? AND `uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR', $album, $page_owner_uid]);
639 if (!DBA::isResult($r) || ($album == DI::l10n()->t('Profile Photos'))) {
645 if (!empty($_REQUEST['not_visible']) && $_REQUEST['not_visible'] !== 'false') {
649 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
651 Hook::callAll('photo_post_file', $ret);
653 if (!empty($ret['src']) && !empty($ret['filesize'])) {
655 $filename = $ret['filename'];
656 $filesize = $ret['filesize'];
657 $type = $ret['type'];
658 $error = UPLOAD_ERR_OK;
659 } elseif (!empty($_FILES['userfile'])) {
660 $src = $_FILES['userfile']['tmp_name'];
661 $filename = basename($_FILES['userfile']['name']);
662 $filesize = intval($_FILES['userfile']['size']);
663 $type = $_FILES['userfile']['type'];
664 $error = $_FILES['userfile']['error'];
666 $error = UPLOAD_ERR_NO_FILE;
669 if ($error !== UPLOAD_ERR_OK) {
671 case UPLOAD_ERR_INI_SIZE:
672 notice(DI::l10n()->t('Image exceeds size limit of %s', ini_get('upload_max_filesize')));
674 case UPLOAD_ERR_FORM_SIZE:
675 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($_REQUEST['MAX_FILE_SIZE'] ?? 0)));
677 case UPLOAD_ERR_PARTIAL:
678 notice(DI::l10n()->t('Image upload didn\'t complete, please try again'));
680 case UPLOAD_ERR_NO_FILE:
681 notice(DI::l10n()->t('Image file is missing'));
683 case UPLOAD_ERR_NO_TMP_DIR:
684 case UPLOAD_ERR_CANT_WRITE:
685 case UPLOAD_ERR_EXTENSION:
686 notice(DI::l10n()->t('Server can\'t accept new file upload at this time, please contact your administrator'));
691 Hook::callAll('photo_post_end', $foo);
695 $type = Images::getMimeTypeBySource($src, $filename, $type);
697 Logger::log('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', Logger::DEBUG);
699 $maximagesize = DI::config()->get('system', 'maximagesize');
701 if ($maximagesize && ($filesize > $maximagesize)) {
702 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)));
705 Hook::callAll('photo_post_end', $foo);
710 notice(DI::l10n()->t('Image file is empty.'));
713 Hook::callAll('photo_post_end', $foo);
717 Logger::log('mod/photos.php: photos_post(): loading the contents of ' . $src , Logger::DEBUG);
719 $imagedata = @file_get_contents($src);
721 $image = new Image($imagedata, $type);
723 if (!$image->isValid()) {
724 Logger::log('mod/photos.php: photos_post(): unable to process image' , Logger::DEBUG);
725 notice(DI::l10n()->t('Unable to process image.'));
728 Hook::callAll('photo_post_end',$foo);
732 $exif = $image->orient($src);
735 $max_length = DI::config()->get('system', 'max_image_length');
737 $max_length = MAX_IMAGE_LENGTH;
739 if ($max_length > 0) {
740 $image->scaleDown($max_length);
743 $width = $image->getWidth();
744 $height = $image->getHeight();
748 $resource_id = Photo::newResource();
750 $r = Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
753 Logger::log('mod/photos.php: photos_post(): image store failed', Logger::DEBUG);
754 notice(DI::l10n()->t('Image upload failed.'));
758 if ($width > 640 || $height > 640) {
759 $image->scaleDown(640);
760 Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
764 if ($width > 320 || $height > 320) {
765 $image->scaleDown(320);
766 Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
770 $uri = Item::newURI($page_owner_uid);
772 // Create item container
774 if (!empty($exif['GPS']) && Feature::isEnabled($page_owner_uid, 'photo_location')) {
775 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
776 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
781 $arr['coord'] = $lat . ' ' . $lon;
784 $arr['guid'] = System::createUUID();
785 $arr['uid'] = $page_owner_uid;
787 $arr['type'] = 'photo';
789 $arr['resource-id'] = $resource_id;
790 $arr['contact-id'] = $owner_record['id'];
791 $arr['owner-name'] = $owner_record['name'];
792 $arr['owner-link'] = $owner_record['url'];
793 $arr['owner-avatar'] = $owner_record['thumb'];
794 $arr['author-name'] = $owner_record['name'];
795 $arr['author-link'] = $owner_record['url'];
796 $arr['author-avatar'] = $owner_record['thumb'];
798 $arr['allow_cid'] = $str_contact_allow;
799 $arr['allow_gid'] = $str_group_allow;
800 $arr['deny_cid'] = $str_contact_deny;
801 $arr['deny_gid'] = $str_group_deny;
802 $arr['visible'] = $visible;
805 $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $resource_id . ']'
806 . '[img]' . DI::baseUrl() . "/photo/{$resource_id}-{$smallest}.".$image->getExt() . '[/img]'
809 $item_id = Item::insert($arr);
810 // Update the photo albums cache
811 Photo::clearAlbumCache($page_owner_uid);
813 Hook::callAll('photo_post_end', $item_id);
815 // addon uploaders should call "exit()" within the photo_post_end hook
816 // if they do not wish to be redirected
818 DI::baseUrl()->redirect($_SESSION['photo_return']);
822 function photos_content(App $a)
826 // photos/name/upload
827 // photos/name/upload/xxxxx (xxxxx is album name)
828 // photos/name/album/xxxxx
829 // photos/name/album/xxxxx/edit
830 // photos/name/album/xxxxx/drop
831 // photos/name/image/xxxxx
832 // photos/name/image/xxxxx/edit
833 // photos/name/image/xxxxx/drop
835 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
836 notice(DI::l10n()->t('Public access denied.'));
840 if (empty($a->data['user'])) {
841 notice(DI::l10n()->t('No photos selected'));
845 $phototypes = Images::supportedTypes();
847 $_SESSION['photo_return'] = DI::args()->getCommand();
852 $datatype = $a->argv[2];
853 $datum = $a->argv[3];
854 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
855 $datatype = 'upload';
857 $datatype = 'summary';
866 // Setup permissions structures
870 $remote_contact = false;
875 $owner_uid = $a->data['user']['uid'];
877 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
879 if (local_user() && (local_user() == $owner_uid)) {
881 } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
882 $contact_id = Session::getRemoteContactID($owner_uid);
883 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
885 if (DBA::isResult($contact)) {
887 $remote_contact = true;
888 $visitor = $contact_id;
892 // perhaps they're visiting - but not a community page, so they wouldn't have write access
893 if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
894 $contact_id = Session::getRemoteContactID($owner_uid);
896 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
898 $remote_contact = DBA::isResult($contact);
901 if (!$remote_contact && local_user()) {
902 $contact_id = $_SESSION['cid'];
903 $contact = $a->contact;
906 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
907 notice(DI::l10n()->t('Access to this item is restricted.'));
911 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
916 $is_owner = (local_user() && (local_user() == $owner_uid));
917 $o .= BaseProfile::getTabsHTML($a, 'photos', $is_owner, $a->data['user']['nickname']);
919 // Display upload form
920 if ($datatype === 'upload') {
922 notice(DI::l10n()->t('Permission denied.'));
926 $selname = Strings::isHex($datum) ? hex2bin($datum) : '';
930 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '><current year></option>';
931 if (!empty($a->data['albums'])) {
932 foreach ($a->data['albums'] as $album) {
933 if (($album['album'] === '') || ($album['album'] === Photo::CONTACT_PHOTOS) || ($album['album'] === DI::l10n()->t(Photo::CONTACT_PHOTOS))) {
936 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
937 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
943 $ret = ['post_url' => 'photos/' . $a->data['user']['nickname'],
944 'addon_text' => $uploader,
945 'default_upload' => true];
947 Hook::callAll('photo_upload_form',$ret);
949 $default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
950 $default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
951 '$submit' => DI::l10n()->t('Submit'),
956 $tpl = Renderer::getMarkupTemplate('photos_upload.tpl');
958 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML(DI::page(), $a->user));
960 $o .= Renderer::replaceMacros($tpl,[
961 '$pagename' => DI::l10n()->t('Upload Photos'),
962 '$sessid' => session_id(),
963 '$usage' => $usage_message,
964 '$nickname' => $a->data['user']['nickname'],
965 '$newalbum' => DI::l10n()->t('New album name: '),
966 '$existalbumtext' => DI::l10n()->t('or select existing album:'),
967 '$nosharetext' => DI::l10n()->t('Do not show a status post for this upload'),
968 '$albumselect' => $albumselect,
969 '$permissions' => DI::l10n()->t('Permissions'),
970 '$aclselect' => $aclselect_e,
971 '$lockstate' => is_array($a->user)
972 && (strlen($a->user['allow_cid'])
973 || strlen($a->user['allow_gid'])
974 || strlen($a->user['deny_cid'])
975 || strlen($a->user['deny_gid'])
976 ) ? 'lock' : 'unlock',
977 '$alt_uploader' => $ret['addon_text'],
978 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
979 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
980 '$uploadurl' => $ret['post_url'],
982 // ACL permissions box
983 '$return_path' => DI::args()->getQueryString(),
989 // Display a single photo album
990 if ($datatype === 'album') {
991 // if $datum is not a valid hex, redirect to the default page
992 if (!Strings::isHex($datum)) {
993 DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname']. '/album');
995 $album = hex2bin($datum);
998 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
999 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1003 if (DBA::isResult($r)) {
1007 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
1009 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1010 $order_field = $_GET['order'] ?? '';
1011 if ($order_field === 'posted') {
1017 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1018 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1019 ANY_VALUE(`created`) as `created`
1020 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1021 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1023 DBA::escape($album),
1025 $pager->getItemsPerPage()
1028 if ($cmd === 'drop') {
1029 $drop_url = DI::args()->getQueryString();
1031 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1032 '$method' => 'post',
1033 '$message' => DI::l10n()->t('Do you really want to delete this photo album and all its photos?'),
1034 '$confirm' => DI::l10n()->t('Delete Album'),
1035 '$confirm_url' => $drop_url,
1036 '$confirm_name' => 'dropalbum',
1037 '$cancel' => DI::l10n()->t('Cancel'),
1042 if ($cmd === 'edit') {
1043 if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS))) {
1045 $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
1049 $o .= Renderer::replaceMacros($edit_tpl,[
1050 '$nametext' => DI::l10n()->t('New album name: '),
1051 '$nickname' => $a->data['user']['nickname'],
1052 '$album' => $album_e,
1053 '$hexalbum' => bin2hex($album),
1054 '$submit' => DI::l10n()->t('Submit'),
1055 '$dropsubmit' => DI::l10n()->t('Delete Album')
1060 if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS)) && $can_post) {
1061 $edit = [DI::l10n()->t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1062 $drop = [DI::l10n()->t('Drop Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/drop'];
1066 if ($order_field === 'posted') {
1067 $order = [DI::l10n()->t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1069 $order = [DI::l10n()->t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?order=posted', 'newest'];
1074 if (DBA::isResult($r)) {
1075 // "Twist" is only used for the duepunto theme with style "slackr"
1077 foreach ($r as $rr) {
1080 $ext = $phototypes[$rr['type']];
1082 $imgalt_e = $rr['filename'];
1083 $desc_e = $rr['desc'];
1087 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1088 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1089 . ($order_field === 'posted' ? '?order=posted' : ''),
1090 'title' => DI::l10n()->t('View Photo'),
1091 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1095 'hash'=> $rr['resource-id'],
1100 $tpl = Renderer::getMarkupTemplate('photo_album.tpl');
1101 $o .= Renderer::replaceMacros($tpl, [
1102 '$photos' => $photos,
1104 '$can_post' => $can_post,
1105 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)],
1109 '$paginate' => $pager->renderFull($total),
1116 // Display one photo
1117 if ($datatype === 'image') {
1118 // fetch image, item containing image, then comments
1119 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1120 $sql_extra ORDER BY `scale` ASC ",
1125 if (!DBA::isResult($ph)) {
1126 if (DBA::exists('photo', ['resource-id' => $datum, 'uid' => $owner_uid])) {
1127 notice(DI::l10n()->t('Permission denied. Access to this item may be restricted.'));
1129 notice(DI::l10n()->t('Photo not available'));
1134 if ($cmd === 'drop') {
1135 $drop_url = DI::args()->getQueryString();
1137 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1138 '$method' => 'post',
1139 '$message' => DI::l10n()->t('Do you really want to delete this photo?'),
1140 '$confirm' => DI::l10n()->t('Delete Photo'),
1141 '$confirm_url' => $drop_url,
1142 '$confirm_name' => 'delete',
1143 '$cancel' => DI::l10n()->t('Cancel'),
1151 * @todo This query is totally bad, the whole functionality has to be changed
1152 * The query leads to a really intense used index.
1153 * By now we hide it if someone wants to.
1155 if ($cmd === 'view' && !DI::config()->get('system', 'no_count', false)) {
1156 $order_field = $_GET['order'] ?? '';
1158 if ($order_field === 'posted') {
1164 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1165 $sql_extra ORDER BY `created` $order ",
1166 DBA::escape($ph[0]['album']),
1170 if (DBA::isResult($prvnxt)) {
1173 foreach ($prvnxt as $z => $entry) {
1174 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1178 $prv = count($prvnxt) - 1;
1180 if ($nxt >= count($prvnxt)) {
1187 if (!is_null($prv)) {
1188 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1190 if (!is_null($nxt)) {
1191 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1194 $tpl = Renderer::getMarkupTemplate('photo_edit_head.tpl');
1195 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
1196 '$prevlink' => $prevlink,
1197 '$nextlink' => $nextlink
1201 $prevlink = [$prevlink, '<div class="icon prev"></div>'];
1205 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1210 if (count($ph) == 1) {
1211 $hires = $lores = $ph[0];
1214 if (count($ph) > 1) {
1215 if ($ph[1]['scale'] == 2) {
1216 // original is 640 or less, we can display it directly
1217 $hires = $lores = $ph[0];
1224 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1228 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1230 if ($cmd === 'edit') {
1231 $tools['view'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum, DI::l10n()->t('View photo')];
1233 $tools['edit'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/edit', DI::l10n()->t('Edit photo')];
1234 $tools['delete'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/drop', DI::l10n()->t('Delete photo')];
1235 $tools['profile'] = ['settings/profile/photo/crop/' . $ph[0]['resource-id'], DI::l10n()->t('Use as profile photo')];
1239 $ph[0]['uid'] == local_user()
1240 && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']))
1242 $tools['lock'] = DI::l10n()->t('Private Photo');
1247 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1248 'title'=> DI::l10n()->t('View Full Size'),
1249 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?_u=' . DateTimeFormat::utcNow('ymdhis'),
1250 'height' => $hires['height'],
1251 'width' => $hires['width'],
1252 'album' => $hires['album'],
1253 'filename' => $hires['filename'],
1260 // Do we have an item for this photo?
1262 // FIXME! - replace following code to display the conversation with our normal
1263 // conversation functions so that it works correctly and tracks changes
1264 // in the evolving conversation code.
1265 // The difference is that we won't be displaying the conversation head item
1266 // as a "post" but displaying instead the photo it is linked to
1268 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1269 $linked_items = q("SELECT `id` FROM `post-view` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1272 if (DBA::isResult($linked_items)) {
1273 // This is a workaround to not being forced to rewrite the while $sql_extra handling
1274 $link_item = Post::selectFirst([], ['id' => $linked_items[0]['id']]);
1277 if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
1278 $condition = ["`parent` = ? AND `gravity` != ?", $link_item['parent'], GRAVITY_PARENT];
1279 $total = Post::count($condition);
1281 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
1283 $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1284 $items = Post::toArray(Post::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params));
1286 if (local_user() == $link_item['uid']) {
1287 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1291 if (!empty($link_item['coord'])) {
1292 $map = Map::byCoordinates($link_item['coord']);
1297 if (!empty($link_item['id'])) {
1298 $tag_text = Tag::getCSVByURIId($link_item['uri-id']);
1299 $arr = explode(',', $tag_text);
1300 // parse tags and add links
1302 foreach ($arr as $tag) {
1304 'name' => BBCode::convert($tag),
1305 'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag)
1308 $tags = ['title' => DI::l10n()->t('Tags: '), 'tags' => $tag_arr];
1309 if ($cmd === 'edit') {
1310 $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
1311 $tags['removetitle'] = DI::l10n()->t('[Select tags to remove]');
1317 if ($cmd === 'edit' && $can_post) {
1318 $edit_tpl = Renderer::getMarkupTemplate('photo_edit.tpl');
1320 $album_e = $ph[0]['album'];
1321 $caption_e = $ph[0]['desc'];
1322 $aclselect_e = ACL::getFullSelectorHTML(DI::page(), $a->user, false, ACL::getDefaultUserPermissions($ph[0]));
1324 $edit = Renderer::replaceMacros($edit_tpl, [
1325 '$id' => $ph[0]['id'],
1326 '$album' => ['albname', DI::l10n()->t('New album name'), $album_e,''],
1327 '$caption' => ['desc', DI::l10n()->t('Caption'), $caption_e, ''],
1328 '$tags' => ['newtag', DI::l10n()->t('Add a Tag'), "", DI::l10n()->t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1329 '$rotate_none' => ['rotate', DI::l10n()->t('Do not rotate'),0,'', true],
1330 '$rotate_cw' => ['rotate', DI::l10n()->t("Rotate CW \x28right\x29"),1,''],
1331 '$rotate_ccw' => ['rotate', DI::l10n()->t("Rotate CCW \x28left\x29"),2,''],
1333 '$nickname' => $a->data['user']['nickname'],
1334 '$resource_id' => $ph[0]['resource-id'],
1335 '$permissions' => DI::l10n()->t('Permissions'),
1336 '$aclselect' => $aclselect_e,
1338 '$item_id' => $link_item['id'] ?? 0,
1339 '$submit' => DI::l10n()->t('Submit'),
1340 '$delete' => DI::l10n()->t('Delete Photo'),
1342 // ACL permissions box
1343 '$return_path' => DI::args()->getQueryString(),
1353 if (!empty($link_item['id']) && !empty($link_item['uri'])) {
1354 $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
1355 $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
1356 $return_path = DI::args()->getCommand();
1358 if (!DBA::isResult($items)) {
1359 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1361 * Hmmm, code depending on the presence of a particular addon?
1362 * This should be better if done by a hook
1365 if (Addon::isEnabled('qcomment')) {
1366 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1367 $qcomment = $words ? explode("\n", $words) : [];
1370 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1371 '$return_path' => '',
1372 '$jsreload' => $return_path,
1373 '$id' => $link_item['id'],
1374 '$parent' => $link_item['id'],
1375 '$profile_uid' => $owner_uid,
1376 '$mylink' => $contact['url'],
1377 '$mytitle' => DI::l10n()->t('This is you'),
1378 '$myphoto' => $contact['thumb'],
1379 '$comment' => DI::l10n()->t('Comment'),
1380 '$submit' => DI::l10n()->t('Submit'),
1381 '$preview' => DI::l10n()->t('Preview'),
1382 '$loading' => DI::l10n()->t('Loading...'),
1383 '$sourceapp' => DI::l10n()->t($a->sourcename),
1384 '$qcomment' => $qcomment,
1385 '$rand_num' => Crypto::randomDigits(12)
1398 if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
1399 unset($conv_responses['dislike']);
1403 if (DBA::isResult($items)) {
1404 foreach ($items as $item) {
1405 builtin_activity_puller($item, $conv_responses);
1408 if (!empty($conv_responses['like'][$link_item['uri']])) {
1409 $like = format_activity($conv_responses['like'][$link_item['uri']]['links'], 'like', $link_item['id']);
1412 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1413 $dislike = format_activity($conv_responses['dislike'][$link_item['uri']]['links'], 'dislike', $link_item['id']);
1416 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1418 * Hmmm, code depending on the presence of a particular addon?
1419 * This should be better if done by a hook
1422 if (Addon::isEnabled('qcomment')) {
1423 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1424 $qcomment = $words ? explode("\n", $words) : [];
1427 $comments .= Renderer::replaceMacros($cmnt_tpl,[
1428 '$return_path' => '',
1429 '$jsreload' => $return_path,
1430 '$id' => $link_item['id'],
1431 '$parent' => $link_item['id'],
1432 '$profile_uid' => $owner_uid,
1433 '$mylink' => $contact['url'],
1434 '$mytitle' => DI::l10n()->t('This is you'),
1435 '$myphoto' => $contact['thumb'],
1436 '$comment' => DI::l10n()->t('Comment'),
1437 '$submit' => DI::l10n()->t('Submit'),
1438 '$preview' => DI::l10n()->t('Preview'),
1439 '$sourceapp' => DI::l10n()->t($a->sourcename),
1440 '$qcomment' => $qcomment,
1441 '$rand_num' => Crypto::randomDigits(12)
1445 foreach ($items as $item) {
1449 $activity = DI::activity();
1451 if (($activity->match($item['verb'], Activity::LIKE) ||
1452 $activity->match($item['verb'], Activity::DISLIKE)) &&
1453 ($item['gravity'] != GRAVITY_PARENT)) {
1457 $profile_url = Contact::magicLinkById($item['author-id']);
1458 if (strpos($profile_url, 'redir/') === 0) {
1459 $sparkle = ' sparkle';
1464 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1466 'dropping' => $dropping,
1467 'pagedrop' => false,
1468 'select' => DI::l10n()->t('Select'),
1469 'delete' => DI::l10n()->t('Delete'),
1472 $title_e = $item['title'];
1473 $body_e = BBCode::convert($item['body']);
1475 $comments .= Renderer::replaceMacros($template,[
1476 '$id' => $item['id'],
1477 '$profile_url' => $profile_url,
1478 '$name' => $item['author-name'],
1479 '$thumb' => $item['author-avatar'],
1480 '$sparkle' => $sparkle,
1481 '$title' => $title_e,
1483 '$ago' => Temporal::getRelativeDate($item['created']),
1484 '$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''),
1486 '$comment' => $comment
1489 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1491 * Hmmm, code depending on the presence of a particular addon?
1492 * This should be better if done by a hook
1495 if (Addon::isEnabled('qcomment')) {
1496 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1497 $qcomment = $words ? explode("\n", $words) : [];
1500 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1501 '$return_path' => '',
1502 '$jsreload' => $return_path,
1503 '$id' => $item['id'],
1504 '$parent' => $item['parent'],
1505 '$profile_uid' => $owner_uid,
1506 '$mylink' => $contact['url'],
1507 '$mytitle' => DI::l10n()->t('This is you'),
1508 '$myphoto' => $contact['thumb'],
1509 '$comment' => DI::l10n()->t('Comment'),
1510 '$submit' => DI::l10n()->t('Submit'),
1511 '$preview' => DI::l10n()->t('Preview'),
1512 '$sourceapp' => DI::l10n()->t($a->sourcename),
1513 '$qcomment' => $qcomment,
1514 '$rand_num' => Crypto::randomDigits(12)
1521 foreach ($conv_responses as $verb => $activity) {
1522 if (isset($activity[$link_item['uri']])) {
1523 $responses[$verb] = $activity[$link_item['uri']];
1527 if ($cmd === 'view' && ($can_post || Security::canWriteToUserWall($owner_uid))) {
1528 $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl');
1529 $likebuttons = Renderer::replaceMacros($like_tpl, [
1530 '$id' => $link_item['id'],
1531 '$like' => DI::l10n()->t('Like'),
1532 '$like_title' => DI::l10n()->t('I like this (toggle)'),
1533 '$dislike' => DI::l10n()->t('Dislike'),
1534 '$wait' => DI::l10n()->t('Please wait'),
1535 '$dislike_title' => DI::l10n()->t('I don\'t like this (toggle)'),
1536 '$hide_dislike' => DI::pConfig()->get(local_user(), 'system', 'hide_dislike'),
1537 '$responses' => $responses,
1538 '$return_path' => DI::args()->getQueryString(),
1542 $paginate = $pager->renderFull($total);
1545 $photo_tpl = Renderer::getMarkupTemplate('photo_view.tpl');
1546 $o .= Renderer::replaceMacros($photo_tpl, [
1547 '$id' => $ph[0]['id'],
1548 '$album' => [$album_link, $ph[0]['album']],
1551 '$prevlink' => $prevlink,
1552 '$nextlink' => $nextlink,
1553 '$desc' => $ph[0]['desc'],
1557 '$map_text' => DI::l10n()->t('Map'),
1558 '$likebuttons' => $likebuttons,
1560 '$dislike' => $dislike,
1561 '$comments' => $comments,
1562 '$paginate' => $paginate,
1565 DI::page()['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
1566 DI::page()['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1567 DI::page()['htmlhead'] .= '<meta name="twitter:image" content="' . DI::baseUrl() . "/" . $photo["href"] . '" />' . "\n";
1568 DI::page()['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1569 DI::page()['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1574 // Default - show recent photos with upload link (if applicable)
1577 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1578 $sql_extra GROUP BY `resource-id`",
1579 intval($a->data['user']['uid']),
1580 DBA::escape(Photo::CONTACT_PHOTOS),
1581 DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS))
1583 if (DBA::isResult($r)) {
1587 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
1589 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1590 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1591 ANY_VALUE(`created`) AS `created` FROM `photo`
1592 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1593 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1594 intval($a->data['user']['uid']),
1595 DBA::escape(Photo::CONTACT_PHOTOS),
1596 DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS)),
1598 $pager->getItemsPerPage()
1602 if (DBA::isResult($r)) {
1603 // "Twist" is only used for the duepunto theme with style "slackr"
1605 foreach ($r as $rr) {
1606 //hide profile photos to others
1607 if (!$is_owner && !Session::getRemoteContactID($owner_uid) && ($rr['album'] == DI::l10n()->t('Profile Photos'))) {
1612 $ext = $phototypes[$rr['type']];
1614 $alt_e = $rr['filename'];
1615 $name_e = $rr['album'];
1619 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1620 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1621 'title' => DI::l10n()->t('View Photo'),
1622 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1625 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1627 'alt' => DI::l10n()->t('View Album'),
1634 $tpl = Renderer::getMarkupTemplate('photos_recent.tpl');
1635 $o .= Renderer::replaceMacros($tpl, [
1636 '$title' => DI::l10n()->t('Recent Photos'),
1637 '$can_post' => $can_post,
1638 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'],
1639 '$photos' => $photos,
1640 '$paginate' => $pager->renderFull($total),