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 Photo::update(['album' => $newalbum], ['album' => $album, 'uid' => $page_owner_uid]);
218 // Update the photo albums cache
219 Photo::clearAlbumCache($page_owner_uid);
221 DI::baseUrl()->redirect('photos/' . $a->getLoggedInUserNickname() . '/album/' . bin2hex($newalbum));
222 return; // NOTREACHED
226 * DELETE all photos filed in a given album
228 if (!empty($_POST['dropalbum'])) {
231 // get the list of photos we are about to delete
233 $r = DBA::toArray(DBA::p("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = ? AND `uid` = ? AND `album` = ?",
239 $r = DBA::toArray(DBA::p("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = ? AND `album` = ?",
245 if (DBA::isResult($r)) {
246 foreach ($r as $rr) {
250 // remove the associated photos
251 Photo::delete(['resource-id' => $res, 'uid' => $page_owner_uid]);
253 // find and delete the corresponding item with all the comments and likes/dislikes
254 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
256 // Update the photo albums cache
257 Photo::clearAlbumCache($page_owner_uid);
258 notice(DI::l10n()->t('Album successfully deleted'));
260 notice(DI::l10n()->t('Album was empty.'));
264 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
267 if (DI::args()->getArgc() > 3 && DI::args()->getArgv()[2] === 'image') {
268 // Check if the user has responded to a delete confirmation query for a single photo
269 if (!empty($_POST['canceled'])) {
270 DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1] . '/image/' . DI::args()->getArgv()[3]);
273 if (!empty($_POST['delete'])) {
274 // same as above but remove single photo
276 $condition = ['contact-id' => $visitor, 'uid' => $page_owner_uid, 'resource-id' => DI::args()->getArgv()[3]];
279 $condition = ['uid' => local_user(), 'resource-id' => DI::args()->getArgv()[3]];
282 $photo = DBA::selectFirst('photo', ['resource-id'], $condition);
284 if (DBA::isResult($photo)) {
285 Photo::delete(['uid' => $page_owner_uid, 'resource-id' => $photo['resource-id']]);
287 Item::deleteForUser(['resource-id' => $photo['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
289 // Update the photo albums cache
290 Photo::clearAlbumCache($page_owner_uid);
292 notice(DI::l10n()->t('Failed to delete the photo.'));
293 DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1] . '/image/' . DI::args()->getArgv()[3]);
296 DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1]);
297 return; // NOTREACHED
301 if (DI::args()->getArgc() > 2 && (!empty($_POST['desc']) || !empty($_POST['newtag']) || isset($_POST['albname']))) {
302 $desc = !empty($_POST['desc']) ? Strings::escapeTags(trim($_POST['desc'])) : '';
303 $rawtags = !empty($_POST['newtag']) ? Strings::escapeTags(trim($_POST['newtag'])) : '';
304 $item_id = !empty($_POST['item_id']) ? intval($_POST['item_id']) : 0;
305 $albname = !empty($_POST['albname']) ? trim($_POST['albname']) : '';
306 $origaname = !empty($_POST['origaname']) ? Strings::escapeTags(trim($_POST['origaname'])) : '';
308 $resource_id = DI::args()->getArgv()[3];
310 if (!strlen($albname)) {
311 $albname = DateTimeFormat::localNow('Y');
314 if (!empty($_POST['rotate']) && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
315 Logger::notice('rotate');
317 $photo = Photo::getPhotoForUser($page_owner_uid, $resource_id);
319 if (DBA::isResult($photo)) {
320 $image = Photo::getImageForPhoto($photo);
322 if ($image->isValid()) {
323 $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
324 $image->rotate($rotate_deg);
326 $width = $image->getWidth();
327 $height = $image->getHeight();
329 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 0], $image);
331 if ($width > 640 || $height > 640) {
332 $image->scaleDown(640);
333 $width = $image->getWidth();
334 $height = $image->getHeight();
336 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 1], $image);
339 if ($width > 320 || $height > 320) {
340 $image->scaleDown(320);
341 $width = $image->getWidth();
342 $height = $image->getHeight();
344 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 2], $image);
350 $photos_stmt = DBA::select('photo', [], ['resource-id' => $resource_id, 'uid' => $page_owner_uid], ['order' => ['scale' => true]]);
352 $photos = DBA::toArray($photos_stmt);
354 if (DBA::isResult($photos)) {
356 $ext = $phototypes[$photo['type']];
358 ['desc' => $desc, 'album' => $albname, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow, 'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny],
359 ['resource-id' => $resource_id, 'uid' => $page_owner_uid]
362 // Update the photo albums cache if album name was changed
363 if ($albname !== $origaname) {
364 Photo::clearAlbumCache($page_owner_uid);
366 /* Don't make the item visible if the only change was the album name */
369 if ($photo['desc'] !== $desc || strlen($rawtags)) {
374 if (DBA::isResult($photos) && !$item_id) {
375 // Create item container
377 $uri = Item::newURI($page_owner_uid);
380 $arr['guid'] = System::createUUID();
381 $arr['uid'] = $page_owner_uid;
383 $arr['post-type'] = Item::PT_IMAGE;
385 $arr['resource-id'] = $photo['resource-id'];
386 $arr['contact-id'] = $owner_record['id'];
387 $arr['owner-name'] = $owner_record['name'];
388 $arr['owner-link'] = $owner_record['url'];
389 $arr['owner-avatar'] = $owner_record['thumb'];
390 $arr['author-name'] = $owner_record['name'];
391 $arr['author-link'] = $owner_record['url'];
392 $arr['author-avatar'] = $owner_record['thumb'];
393 $arr['title'] = $title;
394 $arr['allow_cid'] = $photo['allow_cid'];
395 $arr['allow_gid'] = $photo['allow_gid'];
396 $arr['deny_cid'] = $photo['deny_cid'];
397 $arr['deny_gid'] = $photo['deny_gid'];
398 $arr['visible'] = $visibility;
401 $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $user['nickname'] . '/image/' . $photo['resource-id'] . ']'
402 . '[img]' . DI::baseUrl() . '/photo/' . $photo['resource-id'] . '-' . $photo['scale'] . '.'. $ext . '[/img]'
405 $item_id = Item::insert($arr);
409 $item = Post::selectFirst(['inform', 'uri-id'], ['id' => $item_id, 'uid' => $page_owner_uid]);
411 if (DBA::isResult($item)) {
412 $old_inform = $item['inform'];
416 if (strlen($rawtags)) {
419 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
420 $x = substr($rawtags, 0, 1);
421 if ($x !== '@' && $x !== '#') {
422 $rawtags = '#' . $rawtags;
426 $tags = BBCode::getTags($rawtags);
429 foreach ($tags as $tag) {
430 if (strpos($tag, '@') === 0) {
433 $name = substr($tag,1);
435 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
437 $links = @Probe::lrdd($name);
440 foreach ($links as $link) {
441 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
442 $profile = $link['@attributes']['href'];
445 if ($link['@attributes']['rel'] === 'salmon') {
446 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
448 if (strlen($inform)) {
457 $taginfo[] = [$newname, $profile, $salmon];
462 if (strrpos($newname, '+')) {
463 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
467 $contact = DBA::selectFirst('contact', [], ['id' => $tagcid, 'uid' => $page_owner_uid]);
469 $newname = str_replace('_',' ',$name);
471 //select someone from this user's contacts by name
472 $contact = DBA::selectFirst('contact', [], ['name' => $newname, 'uid' => $page_owner_uid]);
473 if (!DBA::isResult($contact)) {
474 //select someone by attag or nick and the name passed in
475 $contact = DBA::selectFirst('contact', [],
476 ['(`attag` = ? OR `nick` = ?) AND `uid` = ?', $name, $name, $page_owner_uid],
477 ['order' => ['attag' => true]]
482 if (DBA::isResult($contact)) {
483 $newname = $contact['name'];
484 $profile = $contact['url'];
486 $notify = 'cid:' . $contact['id'];
487 if (strlen($inform)) {
495 if (!empty($contact)) {
496 $taginfo[] = [$newname, $profile, $notify, $contact];
498 $taginfo[] = [$newname, $profile, $notify, null];
501 $profile = str_replace(',', '%2c', $profile);
503 if (!empty($item['uri-id'])) {
504 Tag::store($item['uri-id'], Tag::MENTION, $newname, $profile);
507 } elseif (strpos($tag, '#') === 0) {
508 $tagname = substr($tag, 1);
509 if (!empty($item['uri-id'])) {
510 Tag::store($item['uri-id'], Tag::HASHTAG, $tagname);
516 $newinform = $old_inform ?? '';
517 if (strlen($newinform) && strlen($inform)) {
520 $newinform .= $inform;
522 $fields = ['inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
523 $condition = ['id' => $item_id];
524 Item::update($fields, $condition);
527 foreach ($photos as $scales) {
528 if (intval($scales['scale']) == 2) {
533 if (intval($scales['scale']) == 4) {
539 if (count($taginfo)) {
540 foreach ($taginfo as $tagged) {
541 $uri = Item::newURI($page_owner_uid);
544 $arr['guid'] = System::createUUID();
545 $arr['uid'] = $page_owner_uid;
548 $arr['contact-id'] = $owner_record['id'];
549 $arr['owner-name'] = $owner_record['name'];
550 $arr['owner-link'] = $owner_record['url'];
551 $arr['owner-avatar'] = $owner_record['thumb'];
552 $arr['author-name'] = $owner_record['name'];
553 $arr['author-link'] = $owner_record['url'];
554 $arr['author-avatar'] = $owner_record['thumb'];
556 $arr['allow_cid'] = $photo['allow_cid'];
557 $arr['allow_gid'] = $photo['allow_gid'];
558 $arr['deny_cid'] = $photo['deny_cid'];
559 $arr['deny_gid'] = $photo['deny_gid'];
561 $arr['verb'] = Activity::TAG;
562 $arr['gravity'] = GRAVITY_PARENT;
563 $arr['object-type'] = Activity\ObjectType::PERSON;
564 $arr['target-type'] = Activity\ObjectType::IMAGE;
565 $arr['inform'] = $tagged[2];
567 $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]') ;
568 $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" ;
570 $arr['object'] = '<object><type>' . Activity\ObjectType::PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
571 $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
573 $arr['object'] .= XML::escape('<link rel="photo" type="' . $photo['type'] . '" href="' . $tagged[3]['photo'] . '" />' . "\n");
575 $arr['object'] .= '</link></object>' . "\n";
577 $arr['target'] = '<target><type>' . Activity\ObjectType::IMAGE . '</type><title>' . $photo['desc'] . '</title><id>'
578 . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '</id>';
579 $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>';
585 DI::baseUrl()->redirect($_SESSION['photo_return']);
586 return; // NOTREACHED
590 // default post action - upload a photo
591 Hook::callAll('photo_post_init', $_POST);
593 // Determine the album to use
594 $album = trim($_REQUEST['album'] ?? '');
595 $newalbum = trim($_REQUEST['newalbum'] ?? '');
597 Logger::info('album= ' . $album . ' newalbum= ' . $newalbum);
599 if (!strlen($album)) {
600 if (strlen($newalbum)) {
603 $album = DateTimeFormat::localNow('Y');
608 * We create a wall item for every photo, but we don't want to
609 * overwhelm the data stream with a hundred newly uploaded photos.
610 * So we will make the first photo uploaded to this album in the last several hours
611 * visible by default, the rest will become visible over time when and if
612 * they acquire comments, likes, dislikes, and/or tags
615 $r = Photo::selectToArray([], ['`album` = ? AND `uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR', $album, $page_owner_uid]);
617 if (!DBA::isResult($r) || ($album == DI::l10n()->t('Profile Photos'))) {
623 if (!empty($_REQUEST['not_visible']) && $_REQUEST['not_visible'] !== 'false') {
627 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
629 Hook::callAll('photo_post_file', $ret);
631 if (!empty($ret['src']) && !empty($ret['filesize'])) {
633 $filename = $ret['filename'];
634 $filesize = $ret['filesize'];
635 $type = $ret['type'];
636 $error = UPLOAD_ERR_OK;
637 } elseif (!empty($_FILES['userfile'])) {
638 $src = $_FILES['userfile']['tmp_name'];
639 $filename = basename($_FILES['userfile']['name']);
640 $filesize = intval($_FILES['userfile']['size']);
641 $type = $_FILES['userfile']['type'];
642 $error = $_FILES['userfile']['error'];
644 $error = UPLOAD_ERR_NO_FILE;
647 if ($error !== UPLOAD_ERR_OK) {
649 case UPLOAD_ERR_INI_SIZE:
650 notice(DI::l10n()->t('Image exceeds size limit of %s', ini_get('upload_max_filesize')));
652 case UPLOAD_ERR_FORM_SIZE:
653 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($_REQUEST['MAX_FILE_SIZE'] ?? 0)));
655 case UPLOAD_ERR_PARTIAL:
656 notice(DI::l10n()->t('Image upload didn\'t complete, please try again'));
658 case UPLOAD_ERR_NO_FILE:
659 notice(DI::l10n()->t('Image file is missing'));
661 case UPLOAD_ERR_NO_TMP_DIR:
662 case UPLOAD_ERR_CANT_WRITE:
663 case UPLOAD_ERR_EXTENSION:
664 notice(DI::l10n()->t('Server can\'t accept new file upload at this time, please contact your administrator'));
669 Hook::callAll('photo_post_end', $foo);
673 $type = Images::getMimeTypeBySource($src, $filename, $type);
675 Logger::info('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes');
677 $maximagesize = DI::config()->get('system', 'maximagesize');
679 if ($maximagesize && ($filesize > $maximagesize)) {
680 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)));
683 Hook::callAll('photo_post_end', $foo);
688 notice(DI::l10n()->t('Image file is empty.'));
691 Hook::callAll('photo_post_end', $foo);
695 Logger::info('loading the contents of ' . $src);
697 $imagedata = @file_get_contents($src);
699 $image = new Image($imagedata, $type);
701 if (!$image->isValid()) {
702 Logger::info('unable to process image');
703 notice(DI::l10n()->t('Unable to process image.'));
706 Hook::callAll('photo_post_end',$foo);
710 $exif = $image->orient($src);
713 $max_length = DI::config()->get('system', 'max_image_length');
715 $max_length = MAX_IMAGE_LENGTH;
717 if ($max_length > 0) {
718 $image->scaleDown($max_length);
721 $width = $image->getWidth();
722 $height = $image->getHeight();
726 $resource_id = Photo::newResource();
728 $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);
731 Logger::info('image store failed');
732 notice(DI::l10n()->t('Image upload failed.'));
736 if ($width > 640 || $height > 640) {
737 $image->scaleDown(640);
738 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);
742 if ($width > 320 || $height > 320) {
743 $image->scaleDown(320);
744 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);
748 $uri = Item::newURI($page_owner_uid);
750 // Create item container
752 if (!empty($exif['GPS']) && Feature::isEnabled($page_owner_uid, 'photo_location')) {
753 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
754 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
759 $arr['coord'] = $lat . ' ' . $lon;
762 $arr['guid'] = System::createUUID();
763 $arr['uid'] = $page_owner_uid;
765 $arr['post-type'] = Item::PT_IMAGE;
767 $arr['resource-id'] = $resource_id;
768 $arr['contact-id'] = $owner_record['id'];
769 $arr['owner-name'] = $owner_record['name'];
770 $arr['owner-link'] = $owner_record['url'];
771 $arr['owner-avatar'] = $owner_record['thumb'];
772 $arr['author-name'] = $owner_record['name'];
773 $arr['author-link'] = $owner_record['url'];
774 $arr['author-avatar'] = $owner_record['thumb'];
776 $arr['allow_cid'] = $str_contact_allow;
777 $arr['allow_gid'] = $str_group_allow;
778 $arr['deny_cid'] = $str_contact_deny;
779 $arr['deny_gid'] = $str_group_deny;
780 $arr['visible'] = $visible;
783 $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $resource_id . ']'
784 . '[img]' . DI::baseUrl() . "/photo/{$resource_id}-{$smallest}.".$image->getExt() . '[/img]'
787 $item_id = Item::insert($arr);
788 // Update the photo albums cache
789 Photo::clearAlbumCache($page_owner_uid);
791 Hook::callAll('photo_post_end', $item_id);
793 // addon uploaders should call "exit()" within the photo_post_end hook
794 // if they do not wish to be redirected
796 DI::baseUrl()->redirect($_SESSION['photo_return']);
800 function photos_content(App $a)
804 // photos/name/upload
805 // photos/name/upload/xxxxx (xxxxx is album name)
806 // photos/name/album/xxxxx
807 // photos/name/album/xxxxx/edit
808 // photos/name/album/xxxxx/drop
809 // photos/name/image/xxxxx
810 // photos/name/image/xxxxx/edit
811 // photos/name/image/xxxxx/drop
813 $user = User::getByNickname(DI::args()->getArgv()[1]);
814 if (!DBA::isResult($user)) {
815 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
818 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
819 notice(DI::l10n()->t('Public access denied.'));
824 notice(DI::l10n()->t('No photos selected'));
828 $profile = Profile::getByUID($user['uid']);
830 $phototypes = Images::supportedTypes();
832 $_SESSION['photo_return'] = DI::args()->getCommand();
836 if (DI::args()->getArgc() > 3) {
837 $datatype = DI::args()->getArgv()[2];
838 $datum = DI::args()->getArgv()[3];
839 } elseif ((DI::args()->getArgc() > 2) && (DI::args()->getArgv()[2] === 'upload')) {
840 $datatype = 'upload';
842 $datatype = 'summary';
845 if (DI::args()->getArgc() > 4) {
846 $cmd = DI::args()->getArgv()[4];
851 // Setup permissions structures
855 $remote_contact = false;
860 $owner_uid = $user['uid'];
862 $community_page = (($user['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
864 if (local_user() && (local_user() == $owner_uid)) {
866 } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
867 $contact_id = Session::getRemoteContactID($owner_uid);
868 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
870 if (DBA::isResult($contact)) {
872 $remote_contact = true;
873 $visitor = $contact_id;
877 // perhaps they're visiting - but not a community page, so they wouldn't have write access
878 if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
879 $contact_id = Session::getRemoteContactID($owner_uid);
881 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
883 $remote_contact = DBA::isResult($contact);
886 if (!$remote_contact && local_user()) {
887 $contact_id = $_SESSION['cid'];
889 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
892 if ($user['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
893 notice(DI::l10n()->t('Access to this item is restricted.'));
897 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
902 $is_owner = (local_user() && (local_user() == $owner_uid));
903 $o .= BaseProfile::getTabsHTML($a, 'photos', $is_owner, $user['nickname'], $profile['hide-friends']);
905 // Display upload form
906 if ($datatype === 'upload') {
908 notice(DI::l10n()->t('Permission denied.'));
912 $selname = Strings::isHex($datum) ? hex2bin($datum) : '';
916 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '><current year></option>';
917 $albums = Photo::getAlbums($owner_uid);
918 if (!empty($albums)) {
919 foreach ($albums as $album) {
920 if (($album['album'] === '') || ($album['album'] === Photo::CONTACT_PHOTOS) || ($album['album'] === DI::l10n()->t(Photo::CONTACT_PHOTOS))) {
923 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
924 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
930 $ret = ['post_url' => 'photos/' . $user['nickname'],
931 'addon_text' => $uploader,
932 'default_upload' => true];
934 Hook::callAll('photo_upload_form',$ret);
936 $default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
937 $default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
938 '$submit' => DI::l10n()->t('Submit'),
943 $tpl = Renderer::getMarkupTemplate('photos_upload.tpl');
945 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId()));
947 $o .= Renderer::replaceMacros($tpl,[
948 '$pagename' => DI::l10n()->t('Upload Photos'),
949 '$sessid' => session_id(),
950 '$usage' => $usage_message,
951 '$nickname' => $user['nickname'],
952 '$newalbum' => DI::l10n()->t('New album name: '),
953 '$existalbumtext' => DI::l10n()->t('or select existing album:'),
954 '$nosharetext' => DI::l10n()->t('Do not show a status post for this upload'),
955 '$albumselect' => $albumselect,
956 '$permissions' => DI::l10n()->t('Permissions'),
957 '$aclselect' => $aclselect_e,
958 '$lockstate' => ACL::getLockstateForUserId($a->getLoggedInUserId()) ? 'lock' : 'unlock',
959 '$alt_uploader' => $ret['addon_text'],
960 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
961 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
962 '$uploadurl' => $ret['post_url'],
964 // ACL permissions box
965 '$return_path' => DI::args()->getQueryString(),
971 // Display a single photo album
972 if ($datatype === 'album') {
973 // if $datum is not a valid hex, redirect to the default page
974 if (!Strings::isHex($datum)) {
975 DI::baseUrl()->redirect('photos/' . $user['nickname']. '/album');
977 $album = hex2bin($datum);
980 $r = DBA::toArray(DBA::p("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = ? AND `album` = ?
981 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
985 if (DBA::isResult($r)) {
989 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
991 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
992 $order_field = $_GET['order'] ?? '';
993 if ($order_field === 'posted') {
999 $r = DBA::toArray(DBA::p("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1000 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1001 ANY_VALUE(`created`) as `created`
1002 FROM `photo` WHERE `uid` = ? AND `album` = ?
1003 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT ? , ?",
1005 DBA::escape($album),
1007 $pager->getItemsPerPage()
1010 if ($cmd === 'drop') {
1011 $drop_url = DI::args()->getQueryString();
1013 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1015 'message' => DI::l10n()->t('Do you really want to delete this photo album and all its photos?'),
1016 'confirm' => DI::l10n()->t('Delete Album'),
1017 'cancel' => DI::l10n()->t('Cancel'),
1019 '$method' => 'post',
1020 '$confirm_url' => $drop_url,
1021 '$confirm_name' => 'dropalbum',
1022 '$confirm_value' => 'dropalbum',
1027 if ($cmd === 'edit') {
1028 if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS))) {
1030 $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
1034 $o .= Renderer::replaceMacros($edit_tpl,[
1035 '$nametext' => DI::l10n()->t('New album name: '),
1036 '$nickname' => $user['nickname'],
1037 '$album' => $album_e,
1038 '$hexalbum' => bin2hex($album),
1039 '$submit' => DI::l10n()->t('Submit'),
1040 '$dropsubmit' => DI::l10n()->t('Delete Album')
1045 if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS)) && $can_post) {
1046 $edit = [DI::l10n()->t('Edit Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1047 $drop = [DI::l10n()->t('Drop Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/drop'];
1051 if ($order_field === 'posted') {
1052 $order = [DI::l10n()->t('Show Newest First'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1054 $order = [DI::l10n()->t('Show Oldest First'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '?order=posted', 'newest'];
1059 if (DBA::isResult($r)) {
1060 // "Twist" is only used for the duepunto theme with style "slackr"
1062 foreach ($r as $rr) {
1065 $ext = $phototypes[$rr['type']];
1067 $imgalt_e = $rr['filename'];
1068 $desc_e = $rr['desc'];
1072 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1073 'link' => 'photos/' . $user['nickname'] . '/image/' . $rr['resource-id']
1074 . ($order_field === 'posted' ? '?order=posted' : ''),
1075 'title' => DI::l10n()->t('View Photo'),
1076 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1080 'hash'=> $rr['resource-id'],
1085 $tpl = Renderer::getMarkupTemplate('photo_album.tpl');
1086 $o .= Renderer::replaceMacros($tpl, [
1087 '$photos' => $photos,
1089 '$can_post' => $can_post,
1090 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $user['nickname'] . '/upload/' . bin2hex($album)],
1094 '$paginate' => $pager->renderFull($total),
1101 // Display one photo
1102 if ($datatype === 'image') {
1103 // fetch image, item containing image, then comments
1104 $ph = Photo::selectToArray([], ["`uid` = ? AND `resource-id` = ? " . $sql_extra, $owner_uid, $datum], ['order' => ['scale' => true]]);
1106 if (!DBA::isResult($ph)) {
1107 if (DBA::exists('photo', ['resource-id' => $datum, 'uid' => $owner_uid])) {
1108 notice(DI::l10n()->t('Permission denied. Access to this item may be restricted.'));
1110 notice(DI::l10n()->t('Photo not available'));
1115 if ($cmd === 'drop') {
1116 $drop_url = DI::args()->getQueryString();
1118 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1120 'message' => DI::l10n()->t('Do you really want to delete this photo?'),
1121 'confirm' => DI::l10n()->t('Delete Photo'),
1122 'cancel' => DI::l10n()->t('Cancel'),
1124 '$method' => 'post',
1125 '$confirm_url' => $drop_url,
1126 '$confirm_name' => 'delete',
1127 '$confirm_value' => 'delete',
1135 * @todo This query is totally bad, the whole functionality has to be changed
1136 * The query leads to a really intense used index.
1137 * By now we hide it if someone wants to.
1139 if ($cmd === 'view' && !DI::config()->get('system', 'no_count', false)) {
1140 $order_field = $_GET['order'] ?? '';
1142 if ($order_field === 'posted') {
1148 $prvnxt = Photo::selectToArray(['resource-id'], ["`album` = ? AND `uid` = ? AND `scale` = ?" . $sql_extra, $ph[0]['album'], $owner_uid, 0]);
1150 if (DBA::isResult($prvnxt)) {
1153 foreach ($prvnxt as $z => $entry) {
1154 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1158 $prv = count($prvnxt) - 1;
1160 if ($nxt >= count($prvnxt)) {
1167 if (!is_null($prv)) {
1168 $prevlink = 'photos/' . $user['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1170 if (!is_null($nxt)) {
1171 $nextlink = 'photos/' . $user['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1174 $tpl = Renderer::getMarkupTemplate('photo_edit_head.tpl');
1175 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
1176 '$prevlink' => $prevlink,
1177 '$nextlink' => $nextlink
1181 $prevlink = [$prevlink, '<div class="icon prev"></div>'];
1185 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1190 if (count($ph) == 1) {
1191 $hires = $lores = $ph[0];
1194 if (count($ph) > 1) {
1195 if ($ph[1]['scale'] == 2) {
1196 // original is 640 or less, we can display it directly
1197 $hires = $lores = $ph[0];
1204 $album_link = 'photos/' . $user['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1208 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1210 if ($cmd === 'edit') {
1211 $tools['view'] = ['photos/' . $user['nickname'] . '/image/' . $datum, DI::l10n()->t('View photo')];
1213 $tools['edit'] = ['photos/' . $user['nickname'] . '/image/' . $datum . '/edit', DI::l10n()->t('Edit photo')];
1214 $tools['delete'] = ['photos/' . $user['nickname'] . '/image/' . $datum . '/drop', DI::l10n()->t('Delete photo')];
1215 $tools['profile'] = ['settings/profile/photo/crop/' . $ph[0]['resource-id'], DI::l10n()->t('Use as profile photo')];
1219 $ph[0]['uid'] == local_user()
1220 && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']))
1222 $tools['lock'] = DI::l10n()->t('Private Photo');
1227 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1228 'title'=> DI::l10n()->t('View Full Size'),
1229 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?_u=' . DateTimeFormat::utcNow('ymdhis'),
1230 'height' => $hires['height'],
1231 'width' => $hires['width'],
1232 'album' => $hires['album'],
1233 'filename' => $hires['filename'],
1240 // Do we have an item for this photo?
1242 // FIXME! - replace following code to display the conversation with our normal
1243 // conversation functions so that it works correctly and tracks changes
1244 // in the evolving conversation code.
1245 // The difference is that we won't be displaying the conversation head item
1246 // as a "post" but displaying instead the photo it is linked to
1248 $link_item = Post::selectFirst([], ["`resource-id` = ?" . $sql_extra, $datum]);
1250 if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
1251 $condition = ["`parent` = ? AND `gravity` = ?", $link_item['parent'], GRAVITY_COMMENT];
1252 $total = Post::count($condition);
1254 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
1256 $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1257 $items = Post::toArray(Post::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params));
1259 if (local_user() == $link_item['uid']) {
1260 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1264 if (!empty($link_item['coord'])) {
1265 $map = Map::byCoordinates($link_item['coord']);
1270 if (!empty($link_item['id'])) {
1271 $tag_text = Tag::getCSVByURIId($link_item['uri-id']);
1272 $arr = explode(',', $tag_text);
1273 // parse tags and add links
1275 foreach ($arr as $tag) {
1277 'name' => BBCode::convert($tag),
1278 'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag)
1281 $tags = ['title' => DI::l10n()->t('Tags: '), 'tags' => $tag_arr];
1282 if ($cmd === 'edit') {
1283 $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
1284 $tags['removetitle'] = DI::l10n()->t('[Select tags to remove]');
1290 if ($cmd === 'edit' && $can_post) {
1291 $edit_tpl = Renderer::getMarkupTemplate('photo_edit.tpl');
1293 $album_e = $ph[0]['album'];
1294 $caption_e = $ph[0]['desc'];
1295 $aclselect_e = ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId(), false, ACL::getDefaultUserPermissions($ph[0]));
1297 $edit = Renderer::replaceMacros($edit_tpl, [
1298 '$id' => $ph[0]['id'],
1299 '$album' => ['albname', DI::l10n()->t('New album name'), $album_e,''],
1300 '$caption' => ['desc', DI::l10n()->t('Caption'), $caption_e, ''],
1301 '$tags' => ['newtag', DI::l10n()->t('Add a Tag'), "", DI::l10n()->t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1302 '$rotate_none' => ['rotate', DI::l10n()->t('Do not rotate'),0,'', true],
1303 '$rotate_cw' => ['rotate', DI::l10n()->t("Rotate CW \x28right\x29"),1,''],
1304 '$rotate_ccw' => ['rotate', DI::l10n()->t("Rotate CCW \x28left\x29"),2,''],
1306 '$nickname' => $user['nickname'],
1307 '$resource_id' => $ph[0]['resource-id'],
1308 '$permissions' => DI::l10n()->t('Permissions'),
1309 '$aclselect' => $aclselect_e,
1311 '$item_id' => $link_item['id'] ?? 0,
1312 '$submit' => DI::l10n()->t('Submit'),
1313 '$delete' => DI::l10n()->t('Delete Photo'),
1315 // ACL permissions box
1316 '$return_path' => DI::args()->getQueryString(),
1326 if (!empty($link_item['id']) && !empty($link_item['uri'])) {
1327 $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
1328 $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
1329 $return_path = DI::args()->getCommand();
1331 if (!DBA::isResult($items)) {
1332 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1334 * Hmmm, code depending on the presence of a particular addon?
1335 * This should be better if done by a hook
1338 if (Addon::isEnabled('qcomment')) {
1339 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1340 $qcomment = $words ? explode("\n", $words) : [];
1343 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1344 '$return_path' => '',
1345 '$jsreload' => $return_path,
1346 '$id' => $link_item['id'],
1347 '$parent' => $link_item['id'],
1348 '$profile_uid' => $owner_uid,
1349 '$mylink' => $contact['url'],
1350 '$mytitle' => DI::l10n()->t('This is you'),
1351 '$myphoto' => $contact['thumb'],
1352 '$comment' => DI::l10n()->t('Comment'),
1353 '$submit' => DI::l10n()->t('Submit'),
1354 '$preview' => DI::l10n()->t('Preview'),
1355 '$loading' => DI::l10n()->t('Loading...'),
1356 '$qcomment' => $qcomment,
1357 '$rand_num' => Crypto::randomDigits(12)
1370 if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
1371 unset($conv_responses['dislike']);
1375 if (DBA::isResult($items)) {
1376 foreach ($items as $item) {
1377 DI::conversation()->builtinActivityPuller($item, $conv_responses);
1380 if (!empty($conv_responses['like'][$link_item['uri']])) {
1381 $like = DI::conversation()->formatActivity($conv_responses['like'][$link_item['uri']]['links'], 'like', $link_item['id']);
1384 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1385 $dislike = DI::conversation()->formatActivity($conv_responses['dislike'][$link_item['uri']]['links'], 'dislike', $link_item['id']);
1388 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1390 * Hmmm, code depending on the presence of a particular addon?
1391 * This should be better if done by a hook
1394 if (Addon::isEnabled('qcomment')) {
1395 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1396 $qcomment = $words ? explode("\n", $words) : [];
1399 $comments .= Renderer::replaceMacros($cmnt_tpl,[
1400 '$return_path' => '',
1401 '$jsreload' => $return_path,
1402 '$id' => $link_item['id'],
1403 '$parent' => $link_item['id'],
1404 '$profile_uid' => $owner_uid,
1405 '$mylink' => $contact['url'],
1406 '$mytitle' => DI::l10n()->t('This is you'),
1407 '$myphoto' => $contact['thumb'],
1408 '$comment' => DI::l10n()->t('Comment'),
1409 '$submit' => DI::l10n()->t('Submit'),
1410 '$preview' => DI::l10n()->t('Preview'),
1411 '$qcomment' => $qcomment,
1412 '$rand_num' => Crypto::randomDigits(12)
1416 foreach ($items as $item) {
1420 $activity = DI::activity();
1422 if (($activity->match($item['verb'], Activity::LIKE) ||
1423 $activity->match($item['verb'], Activity::DISLIKE)) &&
1424 ($item['gravity'] != GRAVITY_PARENT)) {
1428 $author = ['uid' => 0, 'id' => $item['author-id'],
1429 'network' => $item['author-network'], 'url' => $item['author-link']];
1430 $profile_url = Contact::magicLinkByContact($author);
1431 if (strpos($profile_url, 'redir/') === 0) {
1432 $sparkle = ' sparkle';
1437 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1439 'dropping' => $dropping,
1440 'pagedrop' => false,
1441 'select' => DI::l10n()->t('Select'),
1442 'delete' => DI::l10n()->t('Delete'),
1445 $title_e = $item['title'];
1446 $body_e = BBCode::convert($item['body']);
1448 $comments .= Renderer::replaceMacros($template,[
1449 '$id' => $item['id'],
1450 '$profile_url' => $profile_url,
1451 '$name' => $item['author-name'],
1452 '$thumb' => $item['author-avatar'],
1453 '$sparkle' => $sparkle,
1454 '$title' => $title_e,
1456 '$ago' => Temporal::getRelativeDate($item['created']),
1457 '$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''),
1459 '$comment' => $comment
1462 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1464 * Hmmm, code depending on the presence of a particular addon?
1465 * This should be better if done by a hook
1468 if (Addon::isEnabled('qcomment')) {
1469 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1470 $qcomment = $words ? explode("\n", $words) : [];
1473 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1474 '$return_path' => '',
1475 '$jsreload' => $return_path,
1476 '$id' => $item['id'],
1477 '$parent' => $item['parent'],
1478 '$profile_uid' => $owner_uid,
1479 '$mylink' => $contact['url'],
1480 '$mytitle' => DI::l10n()->t('This is you'),
1481 '$myphoto' => $contact['thumb'],
1482 '$comment' => DI::l10n()->t('Comment'),
1483 '$submit' => DI::l10n()->t('Submit'),
1484 '$preview' => DI::l10n()->t('Preview'),
1485 '$qcomment' => $qcomment,
1486 '$rand_num' => Crypto::randomDigits(12)
1493 foreach ($conv_responses as $verb => $activity) {
1494 if (isset($activity[$link_item['uri']])) {
1495 $responses[$verb] = $activity[$link_item['uri']];
1499 if ($cmd === 'view' && ($can_post || Security::canWriteToUserWall($owner_uid))) {
1500 $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl');
1501 $likebuttons = Renderer::replaceMacros($like_tpl, [
1502 '$id' => $link_item['id'],
1503 '$like' => DI::l10n()->t('Like'),
1504 '$like_title' => DI::l10n()->t('I like this (toggle)'),
1505 '$dislike' => DI::l10n()->t('Dislike'),
1506 '$wait' => DI::l10n()->t('Please wait'),
1507 '$dislike_title' => DI::l10n()->t('I don\'t like this (toggle)'),
1508 '$hide_dislike' => DI::pConfig()->get(local_user(), 'system', 'hide_dislike'),
1509 '$responses' => $responses,
1510 '$return_path' => DI::args()->getQueryString(),
1514 $paginate = $pager->renderFull($total);
1517 $photo_tpl = Renderer::getMarkupTemplate('photo_view.tpl');
1518 $o .= Renderer::replaceMacros($photo_tpl, [
1519 '$id' => $ph[0]['id'],
1520 '$album' => [$album_link, $ph[0]['album']],
1523 '$prevlink' => $prevlink,
1524 '$nextlink' => $nextlink,
1525 '$desc' => $ph[0]['desc'],
1529 '$map_text' => DI::l10n()->t('Map'),
1530 '$likebuttons' => $likebuttons,
1532 '$dislike' => $dislike,
1533 '$comments' => $comments,
1534 '$paginate' => $paginate,
1537 DI::page()['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
1538 DI::page()['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1539 DI::page()['htmlhead'] .= '<meta name="twitter:image" content="' . DI::baseUrl() . "/" . $photo["href"] . '" />' . "\n";
1540 DI::page()['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1541 DI::page()['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1546 // Default - show recent photos with upload link (if applicable)
1549 $r = DBA::toArray(DBA::p("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = ? AND NOT `album` IN (?, ?)
1550 $sql_extra GROUP BY `resource-id`",
1552 Photo::CONTACT_PHOTOS,
1553 DI::l10n()->t(Photo::CONTACT_PHOTOS)
1555 if (DBA::isResult($r)) {
1559 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
1561 $r = DBA::toArray(DBA::p("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1562 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1563 ANY_VALUE(`created`) AS `created` FROM `photo`
1564 WHERE `uid` = ? AND NOT `album` IN (?, ?)
1565 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT ? , ?",
1567 Photo::CONTACT_PHOTOS,
1568 DI::l10n()->t(Photo::CONTACT_PHOTOS),
1570 $pager->getItemsPerPage()
1574 if (DBA::isResult($r)) {
1575 // "Twist" is only used for the duepunto theme with style "slackr"
1577 foreach ($r as $rr) {
1578 //hide profile photos to others
1579 if (!$is_owner && !Session::getRemoteContactID($owner_uid) && ($rr['album'] == DI::l10n()->t('Profile Photos'))) {
1584 $ext = $phototypes[$rr['type']];
1586 $alt_e = $rr['filename'];
1587 $name_e = $rr['album'];
1591 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1592 'link' => 'photos/' . $user['nickname'] . '/image/' . $rr['resource-id'],
1593 'title' => DI::l10n()->t('View Photo'),
1594 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1597 'link' => 'photos/' . $user['nickname'] . '/album/' . bin2hex($rr['album']),
1599 'alt' => DI::l10n()->t('View Album'),
1606 $tpl = Renderer::getMarkupTemplate('photos_recent.tpl');
1607 $o .= Renderer::replaceMacros($tpl, [
1608 '$title' => DI::l10n()->t('Recent Photos'),
1609 '$can_post' => $can_post,
1610 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $user['nickname'] . '/upload'],
1611 '$photos' => $photos,
1612 '$paginate' => $pager->renderFull($total),