3 * @copyright Copyright (C) 2010-2021, the Friendica project
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\Content\Widget;
28 use Friendica\Core\ACL;
29 use Friendica\Core\Addon;
30 use Friendica\Core\Hook;
31 use Friendica\Core\Logger;
32 use Friendica\Core\Renderer;
33 use Friendica\Core\Session;
34 use Friendica\Core\System;
35 use Friendica\Database\DBA;
37 use Friendica\Model\Contact;
38 use Friendica\Model\Item;
39 use Friendica\Model\Photo;
40 use Friendica\Model\Post;
41 use Friendica\Model\Profile;
42 use Friendica\Model\Tag;
43 use Friendica\Model\User;
44 use Friendica\Module\BaseProfile;
45 use Friendica\Network\Probe;
46 use Friendica\Object\Image;
47 use Friendica\Protocol\Activity;
48 use Friendica\Util\Crypto;
49 use Friendica\Util\DateTimeFormat;
50 use Friendica\Util\Images;
51 use Friendica\Util\Map;
52 use Friendica\Security\Security;
53 use Friendica\Util\Strings;
54 use Friendica\Util\Temporal;
55 use Friendica\Util\XML;
56 use Friendica\Network\HTTPException;
58 function photos_init(App $a) {
60 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
64 Nav::setSelected('home');
66 if (DI::args()->getArgc() > 1) {
67 $owner = User::getOwnerDataByNick(DI::args()->getArgv()[1]);
69 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
72 $is_owner = (local_user() && (local_user() == $owner['uid']));
74 $albums = Photo::getAlbums($owner['uid']);
76 $albums_visible = ((intval($owner['hidewall']) && !Session::isAuthenticated()) ? false : true);
78 // add various encodings to the array so we can just loop through and pick them out in a template
79 $ret = ['success' => false];
82 if ($albums_visible) {
83 $ret['success'] = true;
87 foreach ($albums as $k => $album) {
88 //hide profile photos to others
89 if (!$is_owner && !Session::getRemoteContactID($owner['uid']) && ($album['album'] == DI::l10n()->t('Profile Photos')))
92 'text' => $album['album'],
93 'total' => $album['total'],
94 'url' => 'photos/' . $owner['nickname'] . '/album/' . bin2hex($album['album']),
95 'urlencode' => urlencode($album['album']),
96 'bin2hex' => bin2hex($album['album'])
98 $ret['albums'][] = $entry;
102 if (local_user() && $owner['uid'] == local_user()) {
108 if ($ret['success']) {
109 $photo_albums_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('photo_albums.tpl'), [
110 '$nick' => $owner['nickname'],
111 '$title' => DI::l10n()->t('Photo Albums'),
112 '$recent' => DI::l10n()->t('Recent Photos'),
113 '$albums' => $ret['albums'],
114 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $owner['nickname'] . '/upload'],
115 '$can_post' => $can_post
119 if (empty(DI::page()['aside'])) {
120 DI::page()['aside'] = '';
123 DI::page()['aside'] .= Widget\VCard::getHTML($owner);
125 if (!empty($photo_albums_widget)) {
126 DI::page()['aside'] .= $photo_albums_widget;
129 $tpl = Renderer::getMarkupTemplate("photos_head.tpl");
131 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
132 '$ispublic' => DI::l10n()->t('everybody')
139 function photos_post(App $a)
141 $user = User::getByNickname(DI::args()->getArgv()[1]);
142 if (!DBA::isResult($user)) {
143 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
146 $phototypes = Images::supportedTypes();
151 $page_owner_uid = intval($user['uid']);
152 $community_page = $user['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
154 if (local_user() && (local_user() == $page_owner_uid)) {
156 } elseif ($community_page && !empty(Session::getRemoteContactID($page_owner_uid))) {
157 $contact_id = Session::getRemoteContactID($page_owner_uid);
159 $visitor = $contact_id;
163 notice(DI::l10n()->t('Permission denied.'));
167 $owner_record = User::getOwnerDataById($page_owner_uid);
169 if (!$owner_record) {
170 notice(DI::l10n()->t('Contact information unavailable'));
171 DI::logger()->info('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
175 $aclFormatter = DI::aclFormatter();
176 $str_contact_allow = isset($_REQUEST['contact_allow']) ? $aclFormatter->toString($_REQUEST['contact_allow']) : $owner_record['allow_cid'] ?? '';
177 $str_group_allow = isset($_REQUEST['group_allow']) ? $aclFormatter->toString($_REQUEST['group_allow']) : $owner_record['allow_gid'] ?? '';
178 $str_contact_deny = isset($_REQUEST['contact_deny']) ? $aclFormatter->toString($_REQUEST['contact_deny']) : $owner_record['deny_cid'] ?? '';
179 $str_group_deny = isset($_REQUEST['group_deny']) ? $aclFormatter->toString($_REQUEST['group_deny']) : $owner_record['deny_gid'] ?? '';
181 $visibility = $_REQUEST['visibility'] ?? '';
182 if ($visibility === 'public') {
183 // The ACL selector introduced in version 2019.12 sends ACL input data even when the Public visibility is selected
184 $str_contact_allow = $str_group_allow = $str_contact_deny = $str_group_deny = '';
185 } else if ($visibility === 'custom') {
186 // Since we know from the visibility parameter the item should be private, we have to prevent the empty ACL
187 // case that would make it public. So we always append the author's contact id to the allowed contacts.
188 // See https://github.com/friendica/friendica/issues/9672
189 $str_contact_allow .= $aclFormatter->toString(Contact::getPublicIdByUserId($page_owner_uid));
192 if (DI::args()->getArgc() > 3 && DI::args()->getArgv()[2] === 'album') {
193 if (!Strings::isHex(DI::args()->getArgv()[3])) {
194 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
196 $album = hex2bin(DI::args()->getArgv()[3]);
198 if ($album === DI::l10n()->t('Profile Photos') || $album === Photo::CONTACT_PHOTOS || $album === DI::l10n()->t(Photo::CONTACT_PHOTOS)) {
199 DI::baseUrl()->redirect($_SESSION['photo_return']);
200 return; // NOTREACHED
203 if (!DBA::exists('photo', ['album' => $album, 'uid' => $page_owner_uid])) {
204 notice(DI::l10n()->t('Album not found.'));
205 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
206 return; // NOTREACHED
209 // Check if the user has responded to a delete confirmation query
210 if (!empty($_REQUEST['canceled'])) {
211 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album/' . DI::args()->getArgv()[3]);
214 // RENAME photo album
215 $newalbum = Strings::escapeTags(trim($_POST['albumname']));
216 if ($newalbum != $album) {
217 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
218 DBA::escape($newalbum),
220 intval($page_owner_uid)
222 // Update the photo albums cache
223 Photo::clearAlbumCache($page_owner_uid);
225 DI::baseUrl()->redirect('photos/' . $a->getLoggedInUserNickname() . '/album/' . bin2hex($newalbum));
226 return; // NOTREACHED
230 * DELETE all photos filed in a given album
232 if (!empty($_POST['dropalbum'])) {
235 // get the list of photos we are about to delete
237 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
239 intval($page_owner_uid),
243 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
244 intval(local_user()),
249 if (DBA::isResult($r)) {
250 foreach ($r as $rr) {
254 // remove the associated photos
255 Photo::delete(['resource-id' => $res, 'uid' => $page_owner_uid]);
257 // find and delete the corresponding item with all the comments and likes/dislikes
258 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
260 // Update the photo albums cache
261 Photo::clearAlbumCache($page_owner_uid);
262 notice(DI::l10n()->t('Album successfully deleted'));
264 notice(DI::l10n()->t('Album was empty.'));
268 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
271 if (DI::args()->getArgc() > 3 && DI::args()->getArgv()[2] === 'image') {
272 // Check if the user has responded to a delete confirmation query for a single photo
273 if (!empty($_POST['canceled'])) {
274 DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1] . '/image/' . DI::args()->getArgv()[3]);
277 if (!empty($_POST['delete'])) {
278 // same as above but remove single photo
280 $condition = ['contact-id' => $visitor, 'uid' => $page_owner_uid, 'resource-id' => DI::args()->getArgv()[3]];
283 $condition = ['uid' => local_user(), 'resource-id' => DI::args()->getArgv()[3]];
286 $photo = DBA::selectFirst('photo', ['resource-id'], $condition);
288 if (DBA::isResult($photo)) {
289 Photo::delete(['uid' => $page_owner_uid, 'resource-id' => $photo['resource-id']]);
291 Item::deleteForUser(['resource-id' => $photo['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
293 // Update the photo albums cache
294 Photo::clearAlbumCache($page_owner_uid);
296 notice(DI::l10n()->t('Failed to delete the photo.'));
297 DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1] . '/image/' . DI::args()->getArgv()[3]);
300 DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1]);
301 return; // NOTREACHED
305 if (DI::args()->getArgc() > 2 && (!empty($_POST['desc']) || !empty($_POST['newtag']) || isset($_POST['albname']))) {
306 $desc = !empty($_POST['desc']) ? Strings::escapeTags(trim($_POST['desc'])) : '';
307 $rawtags = !empty($_POST['newtag']) ? Strings::escapeTags(trim($_POST['newtag'])) : '';
308 $item_id = !empty($_POST['item_id']) ? intval($_POST['item_id']) : 0;
309 $albname = !empty($_POST['albname']) ? trim($_POST['albname']) : '';
310 $origaname = !empty($_POST['origaname']) ? Strings::escapeTags(trim($_POST['origaname'])) : '';
312 $resource_id = DI::args()->getArgv()[3];
314 if (!strlen($albname)) {
315 $albname = DateTimeFormat::localNow('Y');
318 if (!empty($_POST['rotate']) && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
319 Logger::notice('rotate');
321 $photo = Photo::getPhotoForUser($page_owner_uid, $resource_id);
323 if (DBA::isResult($photo)) {
324 $image = Photo::getImageForPhoto($photo);
326 if ($image->isValid()) {
327 $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
328 $image->rotate($rotate_deg);
330 $width = $image->getWidth();
331 $height = $image->getHeight();
333 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 0], $image);
335 if ($width > 640 || $height > 640) {
336 $image->scaleDown(640);
337 $width = $image->getWidth();
338 $height = $image->getHeight();
340 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 1], $image);
343 if ($width > 320 || $height > 320) {
344 $image->scaleDown(320);
345 $width = $image->getWidth();
346 $height = $image->getHeight();
348 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 2], $image);
354 $photos_stmt = DBA::select('photo', [], ['resource-id' => $resource_id, 'uid' => $page_owner_uid], ['order' => ['scale' => true]]);
356 $photos = DBA::toArray($photos_stmt);
358 if (DBA::isResult($photos)) {
360 $ext = $phototypes[$photo['type']];
362 ['desc' => $desc, 'album' => $albname, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow, 'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny],
363 ['resource-id' => $resource_id, 'uid' => $page_owner_uid]
366 // Update the photo albums cache if album name was changed
367 if ($albname !== $origaname) {
368 Photo::clearAlbumCache($page_owner_uid);
370 /* Don't make the item visible if the only change was the album name */
373 if ($photo['desc'] !== $desc || strlen($rawtags)) {
378 if (DBA::isResult($photos) && !$item_id) {
379 // Create item container
381 $uri = Item::newURI($page_owner_uid);
384 $arr['guid'] = System::createUUID();
385 $arr['uid'] = $page_owner_uid;
387 $arr['post-type'] = Item::PT_IMAGE;
389 $arr['resource-id'] = $photo['resource-id'];
390 $arr['contact-id'] = $owner_record['id'];
391 $arr['owner-name'] = $owner_record['name'];
392 $arr['owner-link'] = $owner_record['url'];
393 $arr['owner-avatar'] = $owner_record['thumb'];
394 $arr['author-name'] = $owner_record['name'];
395 $arr['author-link'] = $owner_record['url'];
396 $arr['author-avatar'] = $owner_record['thumb'];
397 $arr['title'] = $title;
398 $arr['allow_cid'] = $photo['allow_cid'];
399 $arr['allow_gid'] = $photo['allow_gid'];
400 $arr['deny_cid'] = $photo['deny_cid'];
401 $arr['deny_gid'] = $photo['deny_gid'];
402 $arr['visible'] = $visibility;
405 $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $user['nickname'] . '/image/' . $photo['resource-id'] . ']'
406 . '[img]' . DI::baseUrl() . '/photo/' . $photo['resource-id'] . '-' . $photo['scale'] . '.'. $ext . '[/img]'
409 $item_id = Item::insert($arr);
413 $item = Post::selectFirst(['inform', 'uri-id'], ['id' => $item_id, 'uid' => $page_owner_uid]);
415 if (DBA::isResult($item)) {
416 $old_inform = $item['inform'];
420 if (strlen($rawtags)) {
423 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
424 $x = substr($rawtags, 0, 1);
425 if ($x !== '@' && $x !== '#') {
426 $rawtags = '#' . $rawtags;
430 $tags = BBCode::getTags($rawtags);
433 foreach ($tags as $tag) {
434 if (strpos($tag, '@') === 0) {
437 $name = substr($tag,1);
439 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
441 $links = @Probe::lrdd($name);
444 foreach ($links as $link) {
445 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
446 $profile = $link['@attributes']['href'];
449 if ($link['@attributes']['rel'] === 'salmon') {
450 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
452 if (strlen($inform)) {
461 $taginfo[] = [$newname, $profile, $salmon];
466 if (strrpos($newname, '+')) {
467 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
471 $contact = DBA::selectFirst('contact', [], ['id' => $tagcid, 'uid' => $page_owner_uid]);
473 $newname = str_replace('_',' ',$name);
475 //select someone from this user's contacts by name
476 $contact = DBA::selectFirst('contact', [], ['name' => $newname, 'uid' => $page_owner_uid]);
477 if (!DBA::isResult($contact)) {
478 //select someone by attag or nick and the name passed in
479 $contact = DBA::selectFirst('contact', [],
480 ['(`attag` = ? OR `nick` = ?) AND `uid` = ?', $name, $name, $page_owner_uid],
481 ['order' => ['attag' => true]]
486 if (DBA::isResult($contact)) {
487 $newname = $contact['name'];
488 $profile = $contact['url'];
490 $notify = 'cid:' . $contact['id'];
491 if (strlen($inform)) {
499 if (!empty($contact)) {
500 $taginfo[] = [$newname, $profile, $notify, $contact];
502 $taginfo[] = [$newname, $profile, $notify, null];
505 $profile = str_replace(',', '%2c', $profile);
507 if (!empty($item['uri-id'])) {
508 Tag::store($item['uri-id'], Tag::MENTION, $newname, $profile);
511 } elseif (strpos($tag, '#') === 0) {
512 $tagname = substr($tag, 1);
513 if (!empty($item['uri-id'])) {
514 Tag::store($item['uri-id'], Tag::HASHTAG, $tagname);
520 $newinform = $old_inform ?? '';
521 if (strlen($newinform) && strlen($inform)) {
524 $newinform .= $inform;
526 $fields = ['inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
527 $condition = ['id' => $item_id];
528 Item::update($fields, $condition);
531 foreach ($photos as $scales) {
532 if (intval($scales['scale']) == 2) {
537 if (intval($scales['scale']) == 4) {
543 if (count($taginfo)) {
544 foreach ($taginfo as $tagged) {
545 $uri = Item::newURI($page_owner_uid);
548 $arr['guid'] = System::createUUID();
549 $arr['uid'] = $page_owner_uid;
552 $arr['contact-id'] = $owner_record['id'];
553 $arr['owner-name'] = $owner_record['name'];
554 $arr['owner-link'] = $owner_record['url'];
555 $arr['owner-avatar'] = $owner_record['thumb'];
556 $arr['author-name'] = $owner_record['name'];
557 $arr['author-link'] = $owner_record['url'];
558 $arr['author-avatar'] = $owner_record['thumb'];
560 $arr['allow_cid'] = $photo['allow_cid'];
561 $arr['allow_gid'] = $photo['allow_gid'];
562 $arr['deny_cid'] = $photo['deny_cid'];
563 $arr['deny_gid'] = $photo['deny_gid'];
565 $arr['verb'] = Activity::TAG;
566 $arr['gravity'] = GRAVITY_PARENT;
567 $arr['object-type'] = Activity\ObjectType::PERSON;
568 $arr['target-type'] = Activity\ObjectType::IMAGE;
569 $arr['inform'] = $tagged[2];
571 $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]') ;
572 $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" ;
574 $arr['object'] = '<object><type>' . Activity\ObjectType::PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
575 $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
577 $arr['object'] .= XML::escape('<link rel="photo" type="' . $photo['type'] . '" href="' . $tagged[3]['photo'] . '" />' . "\n");
579 $arr['object'] .= '</link></object>' . "\n";
581 $arr['target'] = '<target><type>' . Activity\ObjectType::IMAGE . '</type><title>' . $photo['desc'] . '</title><id>'
582 . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '</id>';
583 $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>';
589 DI::baseUrl()->redirect($_SESSION['photo_return']);
590 return; // NOTREACHED
594 // default post action - upload a photo
595 Hook::callAll('photo_post_init', $_POST);
597 // Determine the album to use
598 $album = trim($_REQUEST['album'] ?? '');
599 $newalbum = trim($_REQUEST['newalbum'] ?? '');
601 Logger::info('album= ' . $album . ' newalbum= ' . $newalbum);
603 if (!strlen($album)) {
604 if (strlen($newalbum)) {
607 $album = DateTimeFormat::localNow('Y');
612 * We create a wall item for every photo, but we don't want to
613 * overwhelm the data stream with a hundred newly uploaded photos.
614 * So we will make the first photo uploaded to this album in the last several hours
615 * visible by default, the rest will become visible over time when and if
616 * they acquire comments, likes, dislikes, and/or tags
619 $r = Photo::selectToArray([], ['`album` = ? AND `uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR', $album, $page_owner_uid]);
621 if (!DBA::isResult($r) || ($album == DI::l10n()->t('Profile Photos'))) {
627 if (!empty($_REQUEST['not_visible']) && $_REQUEST['not_visible'] !== 'false') {
631 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
633 Hook::callAll('photo_post_file', $ret);
635 if (!empty($ret['src']) && !empty($ret['filesize'])) {
637 $filename = $ret['filename'];
638 $filesize = $ret['filesize'];
639 $type = $ret['type'];
640 $error = UPLOAD_ERR_OK;
641 } elseif (!empty($_FILES['userfile'])) {
642 $src = $_FILES['userfile']['tmp_name'];
643 $filename = basename($_FILES['userfile']['name']);
644 $filesize = intval($_FILES['userfile']['size']);
645 $type = $_FILES['userfile']['type'];
646 $error = $_FILES['userfile']['error'];
648 $error = UPLOAD_ERR_NO_FILE;
651 if ($error !== UPLOAD_ERR_OK) {
653 case UPLOAD_ERR_INI_SIZE:
654 notice(DI::l10n()->t('Image exceeds size limit of %s', ini_get('upload_max_filesize')));
656 case UPLOAD_ERR_FORM_SIZE:
657 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($_REQUEST['MAX_FILE_SIZE'] ?? 0)));
659 case UPLOAD_ERR_PARTIAL:
660 notice(DI::l10n()->t('Image upload didn\'t complete, please try again'));
662 case UPLOAD_ERR_NO_FILE:
663 notice(DI::l10n()->t('Image file is missing'));
665 case UPLOAD_ERR_NO_TMP_DIR:
666 case UPLOAD_ERR_CANT_WRITE:
667 case UPLOAD_ERR_EXTENSION:
668 notice(DI::l10n()->t('Server can\'t accept new file upload at this time, please contact your administrator'));
673 Hook::callAll('photo_post_end', $foo);
677 $type = Images::getMimeTypeBySource($src, $filename, $type);
679 Logger::info('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes');
681 $maximagesize = DI::config()->get('system', 'maximagesize');
683 if ($maximagesize && ($filesize > $maximagesize)) {
684 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)));
687 Hook::callAll('photo_post_end', $foo);
692 notice(DI::l10n()->t('Image file is empty.'));
695 Hook::callAll('photo_post_end', $foo);
699 Logger::info('loading the contents of ' . $src);
701 $imagedata = @file_get_contents($src);
703 $image = new Image($imagedata, $type);
705 if (!$image->isValid()) {
706 Logger::info('unable to process image');
707 notice(DI::l10n()->t('Unable to process image.'));
710 Hook::callAll('photo_post_end',$foo);
714 $exif = $image->orient($src);
717 $max_length = DI::config()->get('system', 'max_image_length');
719 $max_length = MAX_IMAGE_LENGTH;
721 if ($max_length > 0) {
722 $image->scaleDown($max_length);
725 $width = $image->getWidth();
726 $height = $image->getHeight();
730 $resource_id = Photo::newResource();
732 $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);
735 Logger::info('image store failed');
736 notice(DI::l10n()->t('Image upload failed.'));
740 if ($width > 640 || $height > 640) {
741 $image->scaleDown(640);
742 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);
746 if ($width > 320 || $height > 320) {
747 $image->scaleDown(320);
748 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);
752 $uri = Item::newURI($page_owner_uid);
754 // Create item container
756 if (!empty($exif['GPS']) && Feature::isEnabled($page_owner_uid, 'photo_location')) {
757 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
758 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
763 $arr['coord'] = $lat . ' ' . $lon;
766 $arr['guid'] = System::createUUID();
767 $arr['uid'] = $page_owner_uid;
769 $arr['post-type'] = Item::PT_IMAGE;
771 $arr['resource-id'] = $resource_id;
772 $arr['contact-id'] = $owner_record['id'];
773 $arr['owner-name'] = $owner_record['name'];
774 $arr['owner-link'] = $owner_record['url'];
775 $arr['owner-avatar'] = $owner_record['thumb'];
776 $arr['author-name'] = $owner_record['name'];
777 $arr['author-link'] = $owner_record['url'];
778 $arr['author-avatar'] = $owner_record['thumb'];
780 $arr['allow_cid'] = $str_contact_allow;
781 $arr['allow_gid'] = $str_group_allow;
782 $arr['deny_cid'] = $str_contact_deny;
783 $arr['deny_gid'] = $str_group_deny;
784 $arr['visible'] = $visible;
787 $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $resource_id . ']'
788 . '[img]' . DI::baseUrl() . "/photo/{$resource_id}-{$smallest}.".$image->getExt() . '[/img]'
791 $item_id = Item::insert($arr);
792 // Update the photo albums cache
793 Photo::clearAlbumCache($page_owner_uid);
795 Hook::callAll('photo_post_end', $item_id);
797 // addon uploaders should call "exit()" within the photo_post_end hook
798 // if they do not wish to be redirected
800 DI::baseUrl()->redirect($_SESSION['photo_return']);
804 function photos_content(App $a)
808 // photos/name/upload
809 // photos/name/upload/xxxxx (xxxxx is album name)
810 // photos/name/album/xxxxx
811 // photos/name/album/xxxxx/edit
812 // photos/name/album/xxxxx/drop
813 // photos/name/image/xxxxx
814 // photos/name/image/xxxxx/edit
815 // photos/name/image/xxxxx/drop
817 $user = User::getByNickname(DI::args()->getArgv()[1]);
818 if (!DBA::isResult($user)) {
819 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
822 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
823 notice(DI::l10n()->t('Public access denied.'));
828 notice(DI::l10n()->t('No photos selected'));
832 $profile = Profile::getByUID($user['uid']);
834 $phototypes = Images::supportedTypes();
836 $_SESSION['photo_return'] = DI::args()->getCommand();
840 if (DI::args()->getArgc() > 3) {
841 $datatype = DI::args()->getArgv()[2];
842 $datum = DI::args()->getArgv()[3];
843 } elseif ((DI::args()->getArgc() > 2) && (DI::args()->getArgv()[2] === 'upload')) {
844 $datatype = 'upload';
846 $datatype = 'summary';
849 if (DI::args()->getArgc() > 4) {
850 $cmd = DI::args()->getArgv()[4];
855 // Setup permissions structures
859 $remote_contact = false;
864 $owner_uid = $user['uid'];
866 $community_page = (($user['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
868 if (local_user() && (local_user() == $owner_uid)) {
870 } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
871 $contact_id = Session::getRemoteContactID($owner_uid);
872 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
874 if (DBA::isResult($contact)) {
876 $remote_contact = true;
877 $visitor = $contact_id;
881 // perhaps they're visiting - but not a community page, so they wouldn't have write access
882 if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
883 $contact_id = Session::getRemoteContactID($owner_uid);
885 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
887 $remote_contact = DBA::isResult($contact);
890 if (!$remote_contact && local_user()) {
891 $contact_id = $_SESSION['cid'];
893 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
896 if ($user['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
897 notice(DI::l10n()->t('Access to this item is restricted.'));
901 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
906 $is_owner = (local_user() && (local_user() == $owner_uid));
907 $o .= BaseProfile::getTabsHTML($a, 'photos', $is_owner, $user['nickname'], $profile['hide-friends']);
909 // Display upload form
910 if ($datatype === 'upload') {
912 notice(DI::l10n()->t('Permission denied.'));
916 $selname = Strings::isHex($datum) ? hex2bin($datum) : '';
920 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '><current year></option>';
921 $albums = Photo::getAlbums($owner_uid);
922 if (!empty($albums)) {
923 foreach ($albums as $album) {
924 if (($album['album'] === '') || ($album['album'] === Photo::CONTACT_PHOTOS) || ($album['album'] === DI::l10n()->t(Photo::CONTACT_PHOTOS))) {
927 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
928 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
934 $ret = ['post_url' => 'photos/' . $user['nickname'],
935 'addon_text' => $uploader,
936 'default_upload' => true];
938 Hook::callAll('photo_upload_form',$ret);
940 $default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
941 $default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
942 '$submit' => DI::l10n()->t('Submit'),
947 $tpl = Renderer::getMarkupTemplate('photos_upload.tpl');
949 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId()));
951 $o .= Renderer::replaceMacros($tpl,[
952 '$pagename' => DI::l10n()->t('Upload Photos'),
953 '$sessid' => session_id(),
954 '$usage' => $usage_message,
955 '$nickname' => $user['nickname'],
956 '$newalbum' => DI::l10n()->t('New album name: '),
957 '$existalbumtext' => DI::l10n()->t('or select existing album:'),
958 '$nosharetext' => DI::l10n()->t('Do not show a status post for this upload'),
959 '$albumselect' => $albumselect,
960 '$permissions' => DI::l10n()->t('Permissions'),
961 '$aclselect' => $aclselect_e,
962 '$lockstate' => ACL::getLockstateForUserId($a->getLoggedInUserId()) ? 'lock' : 'unlock',
963 '$alt_uploader' => $ret['addon_text'],
964 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
965 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
966 '$uploadurl' => $ret['post_url'],
968 // ACL permissions box
969 '$return_path' => DI::args()->getQueryString(),
975 // Display a single photo album
976 if ($datatype === 'album') {
977 // if $datum is not a valid hex, redirect to the default page
978 if (!Strings::isHex($datum)) {
979 DI::baseUrl()->redirect('photos/' . $user['nickname']. '/album');
981 $album = hex2bin($datum);
984 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
985 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
989 if (DBA::isResult($r)) {
993 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
995 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
996 $order_field = $_GET['order'] ?? '';
997 if ($order_field === 'posted') {
1003 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1004 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1005 ANY_VALUE(`created`) as `created`
1006 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1007 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1009 DBA::escape($album),
1011 $pager->getItemsPerPage()
1014 if ($cmd === 'drop') {
1015 $drop_url = DI::args()->getQueryString();
1017 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1019 'message' => DI::l10n()->t('Do you really want to delete this photo album and all its photos?'),
1020 'confirm' => DI::l10n()->t('Delete Album'),
1021 'cancel' => DI::l10n()->t('Cancel'),
1023 '$method' => 'post',
1024 '$confirm_url' => $drop_url,
1025 '$confirm_name' => 'dropalbum',
1026 '$confirm_value' => 'dropalbum',
1031 if ($cmd === 'edit') {
1032 if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS))) {
1034 $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
1038 $o .= Renderer::replaceMacros($edit_tpl,[
1039 '$nametext' => DI::l10n()->t('New album name: '),
1040 '$nickname' => $user['nickname'],
1041 '$album' => $album_e,
1042 '$hexalbum' => bin2hex($album),
1043 '$submit' => DI::l10n()->t('Submit'),
1044 '$dropsubmit' => DI::l10n()->t('Delete Album')
1049 if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS)) && $can_post) {
1050 $edit = [DI::l10n()->t('Edit Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1051 $drop = [DI::l10n()->t('Drop Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/drop'];
1055 if ($order_field === 'posted') {
1056 $order = [DI::l10n()->t('Show Newest First'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1058 $order = [DI::l10n()->t('Show Oldest First'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '?order=posted', 'newest'];
1063 if (DBA::isResult($r)) {
1064 // "Twist" is only used for the duepunto theme with style "slackr"
1066 foreach ($r as $rr) {
1069 $ext = $phototypes[$rr['type']];
1071 $imgalt_e = $rr['filename'];
1072 $desc_e = $rr['desc'];
1076 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1077 'link' => 'photos/' . $user['nickname'] . '/image/' . $rr['resource-id']
1078 . ($order_field === 'posted' ? '?order=posted' : ''),
1079 'title' => DI::l10n()->t('View Photo'),
1080 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1084 'hash'=> $rr['resource-id'],
1089 $tpl = Renderer::getMarkupTemplate('photo_album.tpl');
1090 $o .= Renderer::replaceMacros($tpl, [
1091 '$photos' => $photos,
1093 '$can_post' => $can_post,
1094 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $user['nickname'] . '/upload/' . bin2hex($album)],
1098 '$paginate' => $pager->renderFull($total),
1105 // Display one photo
1106 if ($datatype === 'image') {
1107 // fetch image, item containing image, then comments
1108 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1109 $sql_extra ORDER BY `scale` ASC ",
1114 if (!DBA::isResult($ph)) {
1115 if (DBA::exists('photo', ['resource-id' => $datum, 'uid' => $owner_uid])) {
1116 notice(DI::l10n()->t('Permission denied. Access to this item may be restricted.'));
1118 notice(DI::l10n()->t('Photo not available'));
1123 if ($cmd === 'drop') {
1124 $drop_url = DI::args()->getQueryString();
1126 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1128 'message' => DI::l10n()->t('Do you really want to delete this photo?'),
1129 'confirm' => DI::l10n()->t('Delete Photo'),
1130 'cancel' => DI::l10n()->t('Cancel'),
1132 '$method' => 'post',
1133 '$confirm_url' => $drop_url,
1134 '$confirm_name' => 'delete',
1135 '$confirm_value' => 'delete',
1143 * @todo This query is totally bad, the whole functionality has to be changed
1144 * The query leads to a really intense used index.
1145 * By now we hide it if someone wants to.
1147 if ($cmd === 'view' && !DI::config()->get('system', 'no_count', false)) {
1148 $order_field = $_GET['order'] ?? '';
1150 if ($order_field === 'posted') {
1156 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1157 $sql_extra ORDER BY `created` $order ",
1158 DBA::escape($ph[0]['album']),
1162 if (DBA::isResult($prvnxt)) {
1165 foreach ($prvnxt as $z => $entry) {
1166 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1170 $prv = count($prvnxt) - 1;
1172 if ($nxt >= count($prvnxt)) {
1179 if (!is_null($prv)) {
1180 $prevlink = 'photos/' . $user['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1182 if (!is_null($nxt)) {
1183 $nextlink = 'photos/' . $user['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1186 $tpl = Renderer::getMarkupTemplate('photo_edit_head.tpl');
1187 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
1188 '$prevlink' => $prevlink,
1189 '$nextlink' => $nextlink
1193 $prevlink = [$prevlink, '<div class="icon prev"></div>'];
1197 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1202 if (count($ph) == 1) {
1203 $hires = $lores = $ph[0];
1206 if (count($ph) > 1) {
1207 if ($ph[1]['scale'] == 2) {
1208 // original is 640 or less, we can display it directly
1209 $hires = $lores = $ph[0];
1216 $album_link = 'photos/' . $user['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1220 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1222 if ($cmd === 'edit') {
1223 $tools['view'] = ['photos/' . $user['nickname'] . '/image/' . $datum, DI::l10n()->t('View photo')];
1225 $tools['edit'] = ['photos/' . $user['nickname'] . '/image/' . $datum . '/edit', DI::l10n()->t('Edit photo')];
1226 $tools['delete'] = ['photos/' . $user['nickname'] . '/image/' . $datum . '/drop', DI::l10n()->t('Delete photo')];
1227 $tools['profile'] = ['settings/profile/photo/crop/' . $ph[0]['resource-id'], DI::l10n()->t('Use as profile photo')];
1231 $ph[0]['uid'] == local_user()
1232 && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']))
1234 $tools['lock'] = DI::l10n()->t('Private Photo');
1239 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1240 'title'=> DI::l10n()->t('View Full Size'),
1241 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?_u=' . DateTimeFormat::utcNow('ymdhis'),
1242 'height' => $hires['height'],
1243 'width' => $hires['width'],
1244 'album' => $hires['album'],
1245 'filename' => $hires['filename'],
1252 // Do we have an item for this photo?
1254 // FIXME! - replace following code to display the conversation with our normal
1255 // conversation functions so that it works correctly and tracks changes
1256 // in the evolving conversation code.
1257 // The difference is that we won't be displaying the conversation head item
1258 // as a "post" but displaying instead the photo it is linked to
1260 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1261 $linked_items = q("SELECT `id` FROM `post-user-view` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1264 if (DBA::isResult($linked_items)) {
1265 // This is a workaround to not being forced to rewrite the while $sql_extra handling
1266 $link_item = Post::selectFirst([], ['id' => $linked_items[0]['id']]);
1269 if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
1270 $condition = ["`parent` = ? AND `gravity` = ?", $link_item['parent'], GRAVITY_COMMENT];
1271 $total = Post::count($condition);
1273 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
1275 $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1276 $items = Post::toArray(Post::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params));
1278 if (local_user() == $link_item['uid']) {
1279 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1283 if (!empty($link_item['coord'])) {
1284 $map = Map::byCoordinates($link_item['coord']);
1289 if (!empty($link_item['id'])) {
1290 $tag_text = Tag::getCSVByURIId($link_item['uri-id']);
1291 $arr = explode(',', $tag_text);
1292 // parse tags and add links
1294 foreach ($arr as $tag) {
1296 'name' => BBCode::convert($tag),
1297 'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag)
1300 $tags = ['title' => DI::l10n()->t('Tags: '), 'tags' => $tag_arr];
1301 if ($cmd === 'edit') {
1302 $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
1303 $tags['removetitle'] = DI::l10n()->t('[Select tags to remove]');
1309 if ($cmd === 'edit' && $can_post) {
1310 $edit_tpl = Renderer::getMarkupTemplate('photo_edit.tpl');
1312 $album_e = $ph[0]['album'];
1313 $caption_e = $ph[0]['desc'];
1314 $aclselect_e = ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId(), false, ACL::getDefaultUserPermissions($ph[0]));
1316 $edit = Renderer::replaceMacros($edit_tpl, [
1317 '$id' => $ph[0]['id'],
1318 '$album' => ['albname', DI::l10n()->t('New album name'), $album_e,''],
1319 '$caption' => ['desc', DI::l10n()->t('Caption'), $caption_e, ''],
1320 '$tags' => ['newtag', DI::l10n()->t('Add a Tag'), "", DI::l10n()->t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1321 '$rotate_none' => ['rotate', DI::l10n()->t('Do not rotate'),0,'', true],
1322 '$rotate_cw' => ['rotate', DI::l10n()->t("Rotate CW \x28right\x29"),1,''],
1323 '$rotate_ccw' => ['rotate', DI::l10n()->t("Rotate CCW \x28left\x29"),2,''],
1325 '$nickname' => $user['nickname'],
1326 '$resource_id' => $ph[0]['resource-id'],
1327 '$permissions' => DI::l10n()->t('Permissions'),
1328 '$aclselect' => $aclselect_e,
1330 '$item_id' => $link_item['id'] ?? 0,
1331 '$submit' => DI::l10n()->t('Submit'),
1332 '$delete' => DI::l10n()->t('Delete Photo'),
1334 // ACL permissions box
1335 '$return_path' => DI::args()->getQueryString(),
1345 if (!empty($link_item['id']) && !empty($link_item['uri'])) {
1346 $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
1347 $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
1348 $return_path = DI::args()->getCommand();
1350 if (!DBA::isResult($items)) {
1351 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1353 * Hmmm, code depending on the presence of a particular addon?
1354 * This should be better if done by a hook
1357 if (Addon::isEnabled('qcomment')) {
1358 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1359 $qcomment = $words ? explode("\n", $words) : [];
1362 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1363 '$return_path' => '',
1364 '$jsreload' => $return_path,
1365 '$id' => $link_item['id'],
1366 '$parent' => $link_item['id'],
1367 '$profile_uid' => $owner_uid,
1368 '$mylink' => $contact['url'],
1369 '$mytitle' => DI::l10n()->t('This is you'),
1370 '$myphoto' => $contact['thumb'],
1371 '$comment' => DI::l10n()->t('Comment'),
1372 '$submit' => DI::l10n()->t('Submit'),
1373 '$preview' => DI::l10n()->t('Preview'),
1374 '$loading' => DI::l10n()->t('Loading...'),
1375 '$qcomment' => $qcomment,
1376 '$rand_num' => Crypto::randomDigits(12)
1389 if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
1390 unset($conv_responses['dislike']);
1394 if (DBA::isResult($items)) {
1395 foreach ($items as $item) {
1396 DI::conversation()->builtinActivityPuller($item, $conv_responses);
1399 if (!empty($conv_responses['like'][$link_item['uri']])) {
1400 $like = DI::conversation()->formatActivity($conv_responses['like'][$link_item['uri']]['links'], 'like', $link_item['id']);
1403 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1404 $dislike = DI::conversation()->formatActivity($conv_responses['dislike'][$link_item['uri']]['links'], 'dislike', $link_item['id']);
1407 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1409 * Hmmm, code depending on the presence of a particular addon?
1410 * This should be better if done by a hook
1413 if (Addon::isEnabled('qcomment')) {
1414 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1415 $qcomment = $words ? explode("\n", $words) : [];
1418 $comments .= Renderer::replaceMacros($cmnt_tpl,[
1419 '$return_path' => '',
1420 '$jsreload' => $return_path,
1421 '$id' => $link_item['id'],
1422 '$parent' => $link_item['id'],
1423 '$profile_uid' => $owner_uid,
1424 '$mylink' => $contact['url'],
1425 '$mytitle' => DI::l10n()->t('This is you'),
1426 '$myphoto' => $contact['thumb'],
1427 '$comment' => DI::l10n()->t('Comment'),
1428 '$submit' => DI::l10n()->t('Submit'),
1429 '$preview' => DI::l10n()->t('Preview'),
1430 '$qcomment' => $qcomment,
1431 '$rand_num' => Crypto::randomDigits(12)
1435 foreach ($items as $item) {
1439 $activity = DI::activity();
1441 if (($activity->match($item['verb'], Activity::LIKE) ||
1442 $activity->match($item['verb'], Activity::DISLIKE)) &&
1443 ($item['gravity'] != GRAVITY_PARENT)) {
1447 $author = ['uid' => 0, 'id' => $item['author-id'],
1448 'network' => $item['author-network'], 'url' => $item['author-link']];
1449 $profile_url = Contact::magicLinkByContact($author);
1450 if (strpos($profile_url, 'redir/') === 0) {
1451 $sparkle = ' sparkle';
1456 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1458 'dropping' => $dropping,
1459 'pagedrop' => false,
1460 'select' => DI::l10n()->t('Select'),
1461 'delete' => DI::l10n()->t('Delete'),
1464 $title_e = $item['title'];
1465 $body_e = BBCode::convert($item['body']);
1467 $comments .= Renderer::replaceMacros($template,[
1468 '$id' => $item['id'],
1469 '$profile_url' => $profile_url,
1470 '$name' => $item['author-name'],
1471 '$thumb' => $item['author-avatar'],
1472 '$sparkle' => $sparkle,
1473 '$title' => $title_e,
1475 '$ago' => Temporal::getRelativeDate($item['created']),
1476 '$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''),
1478 '$comment' => $comment
1481 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1483 * Hmmm, code depending on the presence of a particular addon?
1484 * This should be better if done by a hook
1487 if (Addon::isEnabled('qcomment')) {
1488 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1489 $qcomment = $words ? explode("\n", $words) : [];
1492 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1493 '$return_path' => '',
1494 '$jsreload' => $return_path,
1495 '$id' => $item['id'],
1496 '$parent' => $item['parent'],
1497 '$profile_uid' => $owner_uid,
1498 '$mylink' => $contact['url'],
1499 '$mytitle' => DI::l10n()->t('This is you'),
1500 '$myphoto' => $contact['thumb'],
1501 '$comment' => DI::l10n()->t('Comment'),
1502 '$submit' => DI::l10n()->t('Submit'),
1503 '$preview' => DI::l10n()->t('Preview'),
1504 '$qcomment' => $qcomment,
1505 '$rand_num' => Crypto::randomDigits(12)
1512 foreach ($conv_responses as $verb => $activity) {
1513 if (isset($activity[$link_item['uri']])) {
1514 $responses[$verb] = $activity[$link_item['uri']];
1518 if ($cmd === 'view' && ($can_post || Security::canWriteToUserWall($owner_uid))) {
1519 $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl');
1520 $likebuttons = Renderer::replaceMacros($like_tpl, [
1521 '$id' => $link_item['id'],
1522 '$like' => DI::l10n()->t('Like'),
1523 '$like_title' => DI::l10n()->t('I like this (toggle)'),
1524 '$dislike' => DI::l10n()->t('Dislike'),
1525 '$wait' => DI::l10n()->t('Please wait'),
1526 '$dislike_title' => DI::l10n()->t('I don\'t like this (toggle)'),
1527 '$hide_dislike' => DI::pConfig()->get(local_user(), 'system', 'hide_dislike'),
1528 '$responses' => $responses,
1529 '$return_path' => DI::args()->getQueryString(),
1533 $paginate = $pager->renderFull($total);
1536 $photo_tpl = Renderer::getMarkupTemplate('photo_view.tpl');
1537 $o .= Renderer::replaceMacros($photo_tpl, [
1538 '$id' => $ph[0]['id'],
1539 '$album' => [$album_link, $ph[0]['album']],
1542 '$prevlink' => $prevlink,
1543 '$nextlink' => $nextlink,
1544 '$desc' => $ph[0]['desc'],
1548 '$map_text' => DI::l10n()->t('Map'),
1549 '$likebuttons' => $likebuttons,
1551 '$dislike' => $dislike,
1552 '$comments' => $comments,
1553 '$paginate' => $paginate,
1556 DI::page()['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
1557 DI::page()['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1558 DI::page()['htmlhead'] .= '<meta name="twitter:image" content="' . DI::baseUrl() . "/" . $photo["href"] . '" />' . "\n";
1559 DI::page()['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1560 DI::page()['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1565 // Default - show recent photos with upload link (if applicable)
1568 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1569 $sql_extra GROUP BY `resource-id`",
1570 intval($user['uid']),
1571 DBA::escape(Photo::CONTACT_PHOTOS),
1572 DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS))
1574 if (DBA::isResult($r)) {
1578 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
1580 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1581 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1582 ANY_VALUE(`created`) AS `created` FROM `photo`
1583 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1584 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1585 intval($user['uid']),
1586 DBA::escape(Photo::CONTACT_PHOTOS),
1587 DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS)),
1589 $pager->getItemsPerPage()
1593 if (DBA::isResult($r)) {
1594 // "Twist" is only used for the duepunto theme with style "slackr"
1596 foreach ($r as $rr) {
1597 //hide profile photos to others
1598 if (!$is_owner && !Session::getRemoteContactID($owner_uid) && ($rr['album'] == DI::l10n()->t('Profile Photos'))) {
1603 $ext = $phototypes[$rr['type']];
1605 $alt_e = $rr['filename'];
1606 $name_e = $rr['album'];
1610 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1611 'link' => 'photos/' . $user['nickname'] . '/image/' . $rr['resource-id'],
1612 'title' => DI::l10n()->t('View Photo'),
1613 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1616 'link' => 'photos/' . $user['nickname'] . '/album/' . bin2hex($rr['album']),
1618 'alt' => DI::l10n()->t('View Album'),
1625 $tpl = Renderer::getMarkupTemplate('photos_recent.tpl');
1626 $o .= Renderer::replaceMacros($tpl, [
1627 '$title' => DI::l10n()->t('Recent Photos'),
1628 '$can_post' => $can_post,
1629 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $user['nickname'] . '/upload'],
1630 '$photos' => $photos,
1631 '$paginate' => $pager->renderFull($total),