3 * @copyright Copyright (C) 2010-2022, 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]);
68 if (!isset($owner['account_removed']) || $owner['account_removed']) {
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) {
89 'text' => $album['album'],
90 'total' => $album['total'],
91 'url' => 'photos/' . $owner['nickname'] . '/album/' . bin2hex($album['album']),
92 'urlencode' => urlencode($album['album']),
93 'bin2hex' => bin2hex($album['album'])
95 $ret['albums'][] = $entry;
99 if (local_user() && $owner['uid'] == local_user()) {
105 if ($ret['success']) {
106 $photo_albums_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('photo_albums.tpl'), [
107 '$nick' => $owner['nickname'],
108 '$title' => DI::l10n()->t('Photo Albums'),
109 '$recent' => DI::l10n()->t('Recent Photos'),
110 '$albums' => $ret['albums'],
111 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $owner['nickname'] . '/upload'],
112 '$can_post' => $can_post
116 if (empty(DI::page()['aside'])) {
117 DI::page()['aside'] = '';
120 DI::page()['aside'] .= Widget\VCard::getHTML($owner);
122 if (!empty($photo_albums_widget)) {
123 DI::page()['aside'] .= $photo_albums_widget;
126 $tpl = Renderer::getMarkupTemplate("photos_head.tpl");
128 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
129 '$ispublic' => DI::l10n()->t('everybody')
136 function photos_post(App $a)
138 $user = User::getByNickname(DI::args()->getArgv()[1]);
139 if (!DBA::isResult($user)) {
140 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
143 $phototypes = Images::supportedTypes();
148 $page_owner_uid = intval($user['uid']);
149 $community_page = $user['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
151 if (local_user() && (local_user() == $page_owner_uid)) {
153 } elseif ($community_page && !empty(Session::getRemoteContactID($page_owner_uid))) {
154 $contact_id = Session::getRemoteContactID($page_owner_uid);
156 $visitor = $contact_id;
160 DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
164 $owner_record = User::getOwnerDataById($page_owner_uid);
166 if (!$owner_record) {
167 DI::sysmsg()->addNotice(DI::l10n()->t('Contact information unavailable'));
168 DI::logger()->info('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
172 $aclFormatter = DI::aclFormatter();
173 $str_contact_allow = isset($_REQUEST['contact_allow']) ? $aclFormatter->toString($_REQUEST['contact_allow']) : $owner_record['allow_cid'] ?? '';
174 $str_group_allow = isset($_REQUEST['group_allow']) ? $aclFormatter->toString($_REQUEST['group_allow']) : $owner_record['allow_gid'] ?? '';
175 $str_contact_deny = isset($_REQUEST['contact_deny']) ? $aclFormatter->toString($_REQUEST['contact_deny']) : $owner_record['deny_cid'] ?? '';
176 $str_group_deny = isset($_REQUEST['group_deny']) ? $aclFormatter->toString($_REQUEST['group_deny']) : $owner_record['deny_gid'] ?? '';
178 $visibility = $_REQUEST['visibility'] ?? '';
179 if ($visibility === 'public') {
180 // The ACL selector introduced in version 2019.12 sends ACL input data even when the Public visibility is selected
181 $str_contact_allow = $str_group_allow = $str_contact_deny = $str_group_deny = '';
182 } else if ($visibility === 'custom') {
183 // Since we know from the visibility parameter the item should be private, we have to prevent the empty ACL
184 // case that would make it public. So we always append the author's contact id to the allowed contacts.
185 // See https://github.com/friendica/friendica/issues/9672
186 $str_contact_allow .= $aclFormatter->toString(Contact::getPublicIdByUserId($page_owner_uid));
189 if (DI::args()->getArgc() > 3 && DI::args()->getArgv()[2] === 'album') {
190 if (!Strings::isHex(DI::args()->getArgv()[3] ?? '')) {
191 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
193 $album = hex2bin(DI::args()->getArgv()[3]);
195 if (!DBA::exists('photo', ['album' => $album, 'uid' => $page_owner_uid, 'photo-type' => Photo::DEFAULT])) {
196 DI::sysmsg()->addNotice(DI::l10n()->t('Album not found.'));
197 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
198 return; // NOTREACHED
201 // Check if the user has responded to a delete confirmation query
202 if (!empty($_REQUEST['canceled'])) {
203 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album/' . DI::args()->getArgv()[3]);
206 // RENAME photo album
207 $newalbum = trim($_POST['albumname'] ?? '');
208 if ($newalbum != $album) {
209 Photo::update(['album' => $newalbum], ['album' => $album, 'uid' => $page_owner_uid]);
210 // Update the photo albums cache
211 Photo::clearAlbumCache($page_owner_uid);
213 DI::baseUrl()->redirect('photos/' . $a->getLoggedInUserNickname() . '/album/' . bin2hex($newalbum));
214 return; // NOTREACHED
218 * DELETE all photos filed in a given album
220 if (!empty($_POST['dropalbum'])) {
223 // get the list of photos we are about to delete
225 $r = DBA::toArray(DBA::p("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = ? AND `uid` = ? AND `album` = ?",
231 $r = DBA::toArray(DBA::p("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = ? AND `album` = ?",
237 if (DBA::isResult($r)) {
238 foreach ($r as $rr) {
242 // remove the associated photos
243 Photo::delete(['resource-id' => $res, 'uid' => $page_owner_uid]);
245 // find and delete the corresponding item with all the comments and likes/dislikes
246 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
248 // Update the photo albums cache
249 Photo::clearAlbumCache($page_owner_uid);
250 DI::sysmsg()->addNotice(DI::l10n()->t('Album successfully deleted'));
252 DI::sysmsg()->addNotice(DI::l10n()->t('Album was empty.'));
256 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
259 if (DI::args()->getArgc() > 3 && DI::args()->getArgv()[2] === 'image') {
260 // Check if the user has responded to a delete confirmation query for a single photo
261 if (!empty($_POST['canceled'])) {
262 DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1] . '/image/' . DI::args()->getArgv()[3]);
265 if (!empty($_POST['delete'])) {
266 // same as above but remove single photo
268 $condition = ['contact-id' => $visitor, 'uid' => $page_owner_uid, 'resource-id' => DI::args()->getArgv()[3]];
271 $condition = ['uid' => local_user(), 'resource-id' => DI::args()->getArgv()[3]];
274 $photo = DBA::selectFirst('photo', ['resource-id'], $condition);
276 if (DBA::isResult($photo)) {
277 Photo::delete(['uid' => $page_owner_uid, 'resource-id' => $photo['resource-id']]);
279 Item::deleteForUser(['resource-id' => $photo['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
281 // Update the photo albums cache
282 Photo::clearAlbumCache($page_owner_uid);
284 DI::sysmsg()->addNotice(DI::l10n()->t('Failed to delete the photo.'));
285 DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1] . '/image/' . DI::args()->getArgv()[3]);
288 DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1]);
289 return; // NOTREACHED
293 if (DI::args()->getArgc() > 2 && (!empty($_POST['desc']) || !empty($_POST['newtag']) || isset($_POST['albname']))) {
294 $desc = !empty($_POST['desc']) ? trim($_POST['desc']) : '';
295 $rawtags = !empty($_POST['newtag']) ? trim($_POST['newtag']) : '';
296 $item_id = !empty($_POST['item_id']) ? intval($_POST['item_id']) : 0;
297 $albname = !empty($_POST['albname']) ? trim($_POST['albname']) : '';
298 $origaname = !empty($_POST['origaname']) ? trim($_POST['origaname']) : '';
300 $resource_id = DI::args()->getArgv()[3];
302 if (!strlen($albname)) {
303 $albname = DateTimeFormat::localNow('Y');
306 if (!empty($_POST['rotate']) && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
307 Logger::debug('rotate');
309 $photo = Photo::getPhotoForUser($page_owner_uid, $resource_id);
311 if (DBA::isResult($photo)) {
312 $image = Photo::getImageForPhoto($photo);
314 if ($image->isValid()) {
315 $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
316 $image->rotate($rotate_deg);
318 $width = $image->getWidth();
319 $height = $image->getHeight();
321 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 0], $image);
323 if ($width > 640 || $height > 640) {
324 $image->scaleDown(640);
325 $width = $image->getWidth();
326 $height = $image->getHeight();
328 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 1], $image);
331 if ($width > 320 || $height > 320) {
332 $image->scaleDown(320);
333 $width = $image->getWidth();
334 $height = $image->getHeight();
336 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 2], $image);
342 $photos_stmt = DBA::select('photo', [], ['resource-id' => $resource_id, 'uid' => $page_owner_uid], ['order' => ['scale' => true]]);
344 $photos = DBA::toArray($photos_stmt);
346 if (DBA::isResult($photos)) {
348 $ext = $phototypes[$photo['type']];
350 ['desc' => $desc, 'album' => $albname, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow, 'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny],
351 ['resource-id' => $resource_id, 'uid' => $page_owner_uid]
354 // Update the photo albums cache if album name was changed
355 if ($albname !== $origaname) {
356 Photo::clearAlbumCache($page_owner_uid);
360 if (DBA::isResult($photos) && !$item_id) {
361 // Create item container
363 $uri = Item::newURI();
366 $arr['guid'] = System::createUUID();
367 $arr['uid'] = $page_owner_uid;
369 $arr['post-type'] = Item::PT_IMAGE;
371 $arr['resource-id'] = $photo['resource-id'];
372 $arr['contact-id'] = $owner_record['id'];
373 $arr['owner-name'] = $owner_record['name'];
374 $arr['owner-link'] = $owner_record['url'];
375 $arr['owner-avatar'] = $owner_record['thumb'];
376 $arr['author-name'] = $owner_record['name'];
377 $arr['author-link'] = $owner_record['url'];
378 $arr['author-avatar'] = $owner_record['thumb'];
379 $arr['title'] = $title;
380 $arr['allow_cid'] = $photo['allow_cid'];
381 $arr['allow_gid'] = $photo['allow_gid'];
382 $arr['deny_cid'] = $photo['deny_cid'];
383 $arr['deny_gid'] = $photo['deny_gid'];
387 $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $user['nickname'] . '/image/' . $photo['resource-id'] . ']'
388 . '[img]' . DI::baseUrl() . '/photo/' . $photo['resource-id'] . '-' . $photo['scale'] . '.'. $ext . '[/img]'
391 $item_id = Item::insert($arr);
395 $item = Post::selectFirst(['inform', 'uri-id'], ['id' => $item_id, 'uid' => $page_owner_uid]);
397 if (DBA::isResult($item)) {
398 $old_inform = $item['inform'];
402 if (strlen($rawtags)) {
405 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
406 $x = substr($rawtags, 0, 1);
407 if ($x !== '@' && $x !== '#') {
408 $rawtags = '#' . $rawtags;
412 $tags = BBCode::getTags($rawtags);
415 foreach ($tags as $tag) {
416 if (strpos($tag, '@') === 0) {
419 $name = substr($tag,1);
421 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
423 $links = @Probe::lrdd($name);
426 foreach ($links as $link) {
427 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
428 $profile = $link['@attributes']['href'];
431 if ($link['@attributes']['rel'] === 'salmon') {
432 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
434 if (strlen($inform)) {
443 $taginfo[] = [$newname, $profile, $salmon];
448 if (strrpos($newname, '+')) {
449 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
453 $contact = DBA::selectFirst('contact', [], ['id' => $tagcid, 'uid' => $page_owner_uid]);
455 $newname = str_replace('_',' ',$name);
457 //select someone from this user's contacts by name
458 $contact = DBA::selectFirst('contact', [], ['name' => $newname, 'uid' => $page_owner_uid]);
459 if (!DBA::isResult($contact)) {
460 //select someone by attag or nick and the name passed in
461 $contact = DBA::selectFirst('contact', [],
462 ['(`attag` = ? OR `nick` = ?) AND `uid` = ?', $name, $name, $page_owner_uid],
463 ['order' => ['attag' => true]]
468 if (DBA::isResult($contact)) {
469 $newname = $contact['name'];
470 $profile = $contact['url'];
472 $notify = 'cid:' . $contact['id'];
473 if (strlen($inform)) {
481 if (!empty($contact)) {
482 $taginfo[] = [$newname, $profile, $notify, $contact];
484 $taginfo[] = [$newname, $profile, $notify, null];
487 $profile = str_replace(',', '%2c', $profile);
489 if (!empty($item['uri-id'])) {
490 Tag::store($item['uri-id'], Tag::MENTION, $newname, $profile);
493 } elseif (strpos($tag, '#') === 0) {
494 $tagname = substr($tag, 1);
495 if (!empty($item['uri-id'])) {
496 Tag::store($item['uri-id'], Tag::HASHTAG, $tagname);
502 $newinform = $old_inform ?? '';
503 if (strlen($newinform) && strlen($inform)) {
506 $newinform .= $inform;
508 $fields = ['inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
509 $condition = ['id' => $item_id];
510 Item::update($fields, $condition);
513 foreach ($photos as $scales) {
514 if (intval($scales['scale']) == 2) {
519 if (intval($scales['scale']) == 4) {
525 if (count($taginfo)) {
526 foreach ($taginfo as $tagged) {
527 $uri = Item::newURI();
530 'guid' => System::createUUID(),
531 'uid' => $page_owner_uid,
534 'contact-id' => $owner_record['id'],
535 'owner-name' => $owner_record['name'],
536 'owner-link' => $owner_record['url'],
537 'owner-avatar' => $owner_record['thumb'],
538 'author-name' => $owner_record['name'],
539 'author-link' => $owner_record['url'],
540 'author-avatar' => $owner_record['thumb'],
542 'allow_cid' => $photo['allow_cid'],
543 'allow_gid' => $photo['allow_gid'],
544 'deny_cid' => $photo['deny_cid'],
545 'deny_gid' => $photo['deny_gid'],
547 'verb' => Activity::TAG,
548 'gravity' => Item::GRAVITY_PARENT,
549 'object-type' => Activity\ObjectType::PERSON,
550 'target-type' => Activity\ObjectType::IMAGE,
551 'inform' => $tagged[2],
553 '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]') . "\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",
554 'object' => '<object><type>' . Activity\ObjectType::PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id><link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n"),
555 'target' => '<target><type>' . Activity\ObjectType::IMAGE . '</type><title>' . $photo['desc'] . '</title><id>' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '</id><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>',
559 $arr['object'] .= XML::escape('<link rel="photo" type="' . $photo['type'] . '" href="' . $tagged[3]['photo'] . '" />' . "\n");
561 $arr['object'] .= '</link></object>' . "\n";
567 DI::baseUrl()->redirect($_SESSION['photo_return']);
568 return; // NOTREACHED
572 // default post action - upload a photo
573 Hook::callAll('photo_post_init', $_POST);
575 // Determine the album to use
576 $album = trim($_REQUEST['album'] ?? '');
577 $newalbum = trim($_REQUEST['newalbum'] ?? '');
579 Logger::debug('album= ' . $album . ' newalbum= ' . $newalbum);
581 if (!strlen($album)) {
582 if (strlen($newalbum)) {
585 $album = DateTimeFormat::localNow('Y');
590 * We create a wall item for every photo, but we don't want to
591 * overwhelm the data stream with a hundred newly uploaded photos.
592 * So we will make the first photo uploaded to this album in the last several hours
593 * visible by default, the rest will become visible over time when and if
594 * they acquire comments, likes, dislikes, and/or tags
597 $r = Photo::selectToArray([], ['`album` = ? AND `uid` = ? AND `created` > ?', $album, $page_owner_uid, DateTimeFormat::utc('now - 3 hours')]);
599 if (!DBA::isResult($r) || ($album == DI::l10n()->t(Photo::PROFILE_PHOTOS))) {
605 if (!empty($_REQUEST['not_visible']) && $_REQUEST['not_visible'] !== 'false') {
609 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
611 Hook::callAll('photo_post_file', $ret);
613 if (!empty($ret['src']) && !empty($ret['filesize'])) {
615 $filename = $ret['filename'];
616 $filesize = $ret['filesize'];
617 $type = $ret['type'];
618 $error = UPLOAD_ERR_OK;
619 } elseif (!empty($_FILES['userfile'])) {
620 $src = $_FILES['userfile']['tmp_name'];
621 $filename = basename($_FILES['userfile']['name']);
622 $filesize = intval($_FILES['userfile']['size']);
623 $type = $_FILES['userfile']['type'];
624 $error = $_FILES['userfile']['error'];
626 $error = UPLOAD_ERR_NO_FILE;
629 if ($error !== UPLOAD_ERR_OK) {
631 case UPLOAD_ERR_INI_SIZE:
632 DI::sysmsg()->addNotice(DI::l10n()->t('Image exceeds size limit of %s', ini_get('upload_max_filesize')));
634 case UPLOAD_ERR_FORM_SIZE:
635 DI::sysmsg()->addNotice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($_REQUEST['MAX_FILE_SIZE'] ?? 0)));
637 case UPLOAD_ERR_PARTIAL:
638 DI::sysmsg()->addNotice(DI::l10n()->t('Image upload didn\'t complete, please try again'));
640 case UPLOAD_ERR_NO_FILE:
641 DI::sysmsg()->addNotice(DI::l10n()->t('Image file is missing'));
643 case UPLOAD_ERR_NO_TMP_DIR:
644 case UPLOAD_ERR_CANT_WRITE:
645 case UPLOAD_ERR_EXTENSION:
646 DI::sysmsg()->addNotice(DI::l10n()->t('Server can\'t accept new file upload at this time, please contact your administrator'));
651 Hook::callAll('photo_post_end', $foo);
655 $type = Images::getMimeTypeBySource($src, $filename, $type);
657 Logger::info('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes');
659 $maximagesize = DI::config()->get('system', 'maximagesize');
661 if ($maximagesize && ($filesize > $maximagesize)) {
662 DI::sysmsg()->addNotice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)));
665 Hook::callAll('photo_post_end', $foo);
670 DI::sysmsg()->addNotice(DI::l10n()->t('Image file is empty.'));
673 Hook::callAll('photo_post_end', $foo);
677 Logger::debug('loading contents', ['src' => $src]);
679 $imagedata = @file_get_contents($src);
681 $image = new Image($imagedata, $type);
683 if (!$image->isValid()) {
684 Logger::notice('unable to process image');
685 DI::sysmsg()->addNotice(DI::l10n()->t('Unable to process image.'));
688 Hook::callAll('photo_post_end',$foo);
692 $exif = $image->orient($src);
695 $max_length = DI::config()->get('system', 'max_image_length');
696 if ($max_length > 0) {
697 $image->scaleDown($max_length);
700 $width = $image->getWidth();
701 $height = $image->getHeight();
705 $resource_id = Photo::newResource();
707 $r = Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 0 , Photo::DEFAULT, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
710 Logger::warning('image store failed');
711 DI::sysmsg()->addNotice(DI::l10n()->t('Image upload failed.'));
715 if ($width > 640 || $height > 640) {
716 $image->scaleDown(640);
717 Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 1, Photo::DEFAULT, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
721 if ($width > 320 || $height > 320) {
722 $image->scaleDown(320);
723 Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 2, Photo::DEFAULT, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
727 $uri = Item::newURI();
729 // Create item container
731 if (!empty($exif['GPS']) && Feature::isEnabled($page_owner_uid, 'photo_location')) {
732 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
733 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
738 $arr['coord'] = $lat . ' ' . $lon;
741 $arr['guid'] = System::createUUID();
742 $arr['uid'] = $page_owner_uid;
744 $arr['post-type'] = Item::PT_IMAGE;
746 $arr['resource-id'] = $resource_id;
747 $arr['contact-id'] = $owner_record['id'];
748 $arr['owner-name'] = $owner_record['name'];
749 $arr['owner-link'] = $owner_record['url'];
750 $arr['owner-avatar'] = $owner_record['thumb'];
751 $arr['author-name'] = $owner_record['name'];
752 $arr['author-link'] = $owner_record['url'];
753 $arr['author-avatar'] = $owner_record['thumb'];
755 $arr['allow_cid'] = $str_contact_allow;
756 $arr['allow_gid'] = $str_group_allow;
757 $arr['deny_cid'] = $str_contact_deny;
758 $arr['deny_gid'] = $str_group_deny;
759 $arr['visible'] = $visible;
762 $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $resource_id . ']'
763 . '[img]' . DI::baseUrl() . "/photo/{$resource_id}-{$smallest}.".$image->getExt() . '[/img]'
766 $item_id = Item::insert($arr);
767 // Update the photo albums cache
768 Photo::clearAlbumCache($page_owner_uid);
770 Hook::callAll('photo_post_end', $item_id);
772 // addon uploaders should call "exit()" within the photo_post_end hook
773 // if they do not wish to be redirected
775 DI::baseUrl()->redirect($_SESSION['photo_return']);
779 function photos_content(App $a)
783 // photos/name/upload
784 // photos/name/upload/xxxxx (xxxxx is album name)
785 // photos/name/album/xxxxx
786 // photos/name/album/xxxxx/edit
787 // photos/name/album/xxxxx/drop
788 // photos/name/image/xxxxx
789 // photos/name/image/xxxxx/edit
790 // photos/name/image/xxxxx/drop
792 $user = User::getByNickname(DI::args()->getArgv()[1]);
793 if (!DBA::isResult($user)) {
794 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
797 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
798 DI::sysmsg()->addNotice(DI::l10n()->t('Public access denied.'));
803 DI::sysmsg()->addNotice(DI::l10n()->t('No photos selected'));
807 $profile = Profile::getByUID($user['uid']);
809 $phototypes = Images::supportedTypes();
811 $_SESSION['photo_return'] = DI::args()->getCommand();
815 if (DI::args()->getArgc() > 3) {
816 $datatype = DI::args()->getArgv()[2];
817 $datum = DI::args()->getArgv()[3];
818 } elseif ((DI::args()->getArgc() > 2) && (DI::args()->getArgv()[2] === 'upload')) {
819 $datatype = 'upload';
821 $datatype = 'summary';
824 if (DI::args()->getArgc() > 4) {
825 $cmd = DI::args()->getArgv()[4];
830 // Setup permissions structures
834 $remote_contact = false;
839 $owner_uid = $user['uid'];
841 $community_page = (($user['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
843 if (local_user() && (local_user() == $owner_uid)) {
845 } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
846 $contact_id = Session::getRemoteContactID($owner_uid);
847 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
849 if (DBA::isResult($contact)) {
851 $remote_contact = true;
852 $visitor = $contact_id;
856 // perhaps they're visiting - but not a community page, so they wouldn't have write access
857 if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
858 $contact_id = Session::getRemoteContactID($owner_uid);
860 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
862 $remote_contact = DBA::isResult($contact);
865 if (!$remote_contact && local_user()) {
866 $contact_id = $_SESSION['cid'];
868 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
871 if ($user['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
872 DI::sysmsg()->addNotice(DI::l10n()->t('Access to this item is restricted.'));
876 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
881 $is_owner = (local_user() && (local_user() == $owner_uid));
882 $o .= BaseProfile::getTabsHTML($a, 'photos', $is_owner, $user['nickname'], $profile['hide-friends']);
884 // Display upload form
885 if ($datatype === 'upload') {
887 DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied.'));
891 $selname = (!is_null($datum) && Strings::isHex($datum)) ? hex2bin($datum) : '';
895 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '><current year></option>';
896 $albums = Photo::getAlbums($owner_uid);
897 if (!empty($albums)) {
898 foreach ($albums as $album) {
899 if ($album['album'] === '') {
902 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
903 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
909 $ret = ['post_url' => 'photos/' . $user['nickname'],
910 'addon_text' => $uploader,
911 'default_upload' => true];
913 Hook::callAll('photo_upload_form',$ret);
915 $default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
916 $default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
917 '$submit' => DI::l10n()->t('Submit'),
922 $tpl = Renderer::getMarkupTemplate('photos_upload.tpl');
924 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId()));
926 $o .= Renderer::replaceMacros($tpl,[
927 '$pagename' => DI::l10n()->t('Upload Photos'),
928 '$sessid' => session_id(),
929 '$usage' => $usage_message,
930 '$nickname' => $user['nickname'],
931 '$newalbum' => DI::l10n()->t('New album name: '),
932 '$existalbumtext' => DI::l10n()->t('or select existing album:'),
933 '$nosharetext' => DI::l10n()->t('Do not show a status post for this upload'),
934 '$albumselect' => $albumselect,
935 '$permissions' => DI::l10n()->t('Permissions'),
936 '$aclselect' => $aclselect_e,
937 '$lockstate' => ACL::getLockstateForUserId($a->getLoggedInUserId()) ? 'lock' : 'unlock',
938 '$alt_uploader' => $ret['addon_text'],
939 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
940 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
941 '$uploadurl' => $ret['post_url'],
943 // ACL permissions box
944 '$return_path' => DI::args()->getQueryString(),
950 // Display a single photo album
951 if ($datatype === 'album') {
952 // if $datum is not a valid hex, redirect to the default page
953 if (is_null($datum) || !Strings::isHex($datum)) {
954 DI::baseUrl()->redirect('photos/' . $user['nickname']. '/album');
956 $album = hex2bin($datum);
958 if ($can_post && !Photo::exists(['uid' => $owner_uid, 'album' => $album, 'photo-type' => Photo::DEFAULT])) {
963 $r = DBA::toArray(DBA::p("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = ? AND `album` = ?
964 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
968 if (DBA::isResult($r)) {
972 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
974 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
975 $order_field = $_GET['order'] ?? '';
976 if ($order_field === 'created') {
982 $r = DBA::toArray(DBA::p("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
983 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
984 ANY_VALUE(`created`) as `created`
985 FROM `photo` WHERE `uid` = ? AND `album` = ?
986 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT ? , ?",
990 $pager->getItemsPerPage()
993 if ($cmd === 'drop') {
994 $drop_url = DI::args()->getQueryString();
996 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
998 'message' => DI::l10n()->t('Do you really want to delete this photo album and all its photos?'),
999 'confirm' => DI::l10n()->t('Delete Album'),
1000 'cancel' => DI::l10n()->t('Cancel'),
1002 '$method' => 'post',
1003 '$confirm_url' => $drop_url,
1004 '$confirm_name' => 'dropalbum',
1005 '$confirm_value' => 'dropalbum',
1010 if ($cmd === 'edit') {
1012 $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
1016 $o .= Renderer::replaceMacros($edit_tpl,[
1017 '$nametext' => DI::l10n()->t('New album name: '),
1018 '$nickname' => $user['nickname'],
1019 '$album' => $album_e,
1020 '$hexalbum' => bin2hex($album),
1021 '$submit' => DI::l10n()->t('Submit'),
1022 '$dropsubmit' => DI::l10n()->t('Delete Album')
1025 } elseif ($can_post) {
1026 $edit = [DI::l10n()->t('Edit Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1027 $drop = [DI::l10n()->t('Drop Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/drop'];
1030 if ($order_field === 'created') {
1031 $order = [DI::l10n()->t('Show Newest First'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1033 $order = [DI::l10n()->t('Show Oldest First'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '?order=created', 'newest'];
1038 if (DBA::isResult($r)) {
1039 // "Twist" is only used for the duepunto theme with style "slackr"
1041 foreach ($r as $rr) {
1044 $ext = $phototypes[$rr['type']];
1046 $imgalt_e = $rr['filename'];
1047 $desc_e = $rr['desc'];
1051 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1052 'link' => 'photos/' . $user['nickname'] . '/image/' . $rr['resource-id']
1053 . ($order_field === 'created' ? '?order=created' : ''),
1054 'title' => DI::l10n()->t('View Photo'),
1055 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1059 'hash'=> $rr['resource-id'],
1064 $tpl = Renderer::getMarkupTemplate('photo_album.tpl');
1065 $o .= Renderer::replaceMacros($tpl, [
1066 '$photos' => $photos,
1068 '$can_post' => $can_post,
1069 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $user['nickname'] . '/upload/' . bin2hex($album)],
1073 '$paginate' => $pager->renderFull($total),
1080 // Display one photo
1081 if ($datatype === 'image') {
1082 // fetch image, item containing image, then comments
1083 $ph = Photo::selectToArray([], ["`uid` = ? AND `resource-id` = ? " . $sql_extra, $owner_uid, $datum], ['order' => ['scale']]);
1085 if (!DBA::isResult($ph)) {
1086 if (DBA::exists('photo', ['resource-id' => $datum, 'uid' => $owner_uid])) {
1087 DI::sysmsg()->addNotice(DI::l10n()->t('Permission denied. Access to this item may be restricted.'));
1089 DI::sysmsg()->addNotice(DI::l10n()->t('Photo not available'));
1094 if ($cmd === 'drop') {
1095 $drop_url = DI::args()->getQueryString();
1097 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1099 'message' => DI::l10n()->t('Do you really want to delete this photo?'),
1100 'confirm' => DI::l10n()->t('Delete Photo'),
1101 'cancel' => DI::l10n()->t('Cancel'),
1103 '$method' => 'post',
1104 '$confirm_url' => $drop_url,
1105 '$confirm_name' => 'delete',
1106 '$confirm_value' => 'delete',
1114 * @todo This query is totally bad, the whole functionality has to be changed
1115 * The query leads to a really intense used index.
1116 * By now we hide it if someone wants to.
1118 if ($cmd === 'view' && !DI::config()->get('system', 'no_count', false)) {
1119 $order_field = $_GET['order'] ?? '';
1121 if ($order_field === 'created') {
1122 $params = ['order' => [$order_field]];
1123 } elseif (!empty($order_field)) {
1124 $params = ['order' => [$order_field => true]];
1129 $prvnxt = Photo::selectToArray(['resource-id'], ["`album` = ? AND `uid` = ? AND `scale` = ?" . $sql_extra, $ph[0]['album'], $owner_uid, 0], $params);
1131 if (DBA::isResult($prvnxt)) {
1134 foreach ($prvnxt as $z => $entry) {
1135 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1139 $prv = count($prvnxt) - 1;
1141 if ($nxt >= count($prvnxt)) {
1148 if (!is_null($prv)) {
1149 $prevlink = 'photos/' . $user['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . ($order_field === 'created' ? '?order=created' : '');
1151 if (!is_null($nxt)) {
1152 $nextlink = 'photos/' . $user['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . ($order_field === 'created' ? '?order=created' : '');
1155 $tpl = Renderer::getMarkupTemplate('photo_edit_head.tpl');
1156 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
1157 '$prevlink' => $prevlink,
1158 '$nextlink' => $nextlink
1162 $prevlink = [$prevlink, '<div class="icon prev"></div>'];
1166 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1171 if (count($ph) == 1) {
1172 $hires = $lores = $ph[0];
1175 if (count($ph) > 1) {
1176 if ($ph[1]['scale'] == 2) {
1177 // original is 640 or less, we can display it directly
1178 $hires = $lores = $ph[0];
1185 $album_link = 'photos/' . $user['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1189 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1191 if ($cmd === 'edit') {
1192 $tools['view'] = ['photos/' . $user['nickname'] . '/image/' . $datum, DI::l10n()->t('View photo')];
1194 $tools['edit'] = ['photos/' . $user['nickname'] . '/image/' . $datum . '/edit', DI::l10n()->t('Edit photo')];
1195 $tools['delete'] = ['photos/' . $user['nickname'] . '/image/' . $datum . '/drop', DI::l10n()->t('Delete photo')];
1196 $tools['profile'] = ['settings/profile/photo/crop/' . $ph[0]['resource-id'], DI::l10n()->t('Use as profile photo')];
1200 $ph[0]['uid'] == local_user()
1201 && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']))
1203 $tools['lock'] = DI::l10n()->t('Private Photo');
1208 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1209 'title'=> DI::l10n()->t('View Full Size'),
1210 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?_u=' . DateTimeFormat::utcNow('ymdhis'),
1211 'height' => $hires['height'],
1212 'width' => $hires['width'],
1213 'album' => $hires['album'],
1214 'filename' => $hires['filename'],
1221 // Do we have an item for this photo?
1223 // FIXME! - replace following code to display the conversation with our normal
1224 // conversation functions so that it works correctly and tracks changes
1225 // in the evolving conversation code.
1226 // The difference is that we won't be displaying the conversation head item
1227 // as a "post" but displaying instead the photo it is linked to
1229 $link_item = Post::selectFirst([], ["`resource-id` = ?" . $sql_extra, $datum]);
1231 if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
1232 $condition = ["`parent` = ? AND `gravity` = ?", $link_item['parent'], Item::GRAVITY_COMMENT];
1233 $total = Post::count($condition);
1235 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
1237 $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1238 $items = Post::toArray(Post::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params));
1240 if (local_user() == $link_item['uid']) {
1241 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1245 if (!empty($link_item['coord'])) {
1246 $map = Map::byCoordinates($link_item['coord']);
1251 if (!empty($link_item['id'])) {
1252 // parse tags and add links
1254 foreach (Tag::getByURIId($link_item['uri-id']) as $tag) {
1256 'name' => $tag['name'],
1257 'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag['name'])
1260 $tags = ['title' => DI::l10n()->t('Tags: '), 'tags' => $tag_arr];
1261 if ($cmd === 'edit') {
1262 $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
1263 $tags['removetitle'] = DI::l10n()->t('[Select tags to remove]');
1269 if ($cmd === 'edit' && $can_post) {
1270 $edit_tpl = Renderer::getMarkupTemplate('photo_edit.tpl');
1272 $album_e = $ph[0]['album'];
1273 $caption_e = $ph[0]['desc'];
1274 $aclselect_e = ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId(), false, ACL::getDefaultUserPermissions($ph[0]));
1276 $edit = Renderer::replaceMacros($edit_tpl, [
1277 '$id' => $ph[0]['id'],
1278 '$album' => ['albname', DI::l10n()->t('New album name'), $album_e,''],
1279 '$caption' => ['desc', DI::l10n()->t('Caption'), $caption_e, ''],
1280 '$tags' => ['newtag', DI::l10n()->t('Add a Tag'), "", DI::l10n()->t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1281 '$rotate_none' => ['rotate', DI::l10n()->t('Do not rotate'),0,'', true],
1282 '$rotate_cw' => ['rotate', DI::l10n()->t("Rotate CW \x28right\x29"),1,''],
1283 '$rotate_ccw' => ['rotate', DI::l10n()->t("Rotate CCW \x28left\x29"),2,''],
1285 '$nickname' => $user['nickname'],
1286 '$resource_id' => $ph[0]['resource-id'],
1287 '$permissions' => DI::l10n()->t('Permissions'),
1288 '$aclselect' => $aclselect_e,
1290 '$item_id' => $link_item['id'] ?? 0,
1291 '$submit' => DI::l10n()->t('Submit'),
1292 '$delete' => DI::l10n()->t('Delete Photo'),
1294 // ACL permissions box
1295 '$return_path' => DI::args()->getQueryString(),
1305 if (!empty($link_item['id']) && !empty($link_item['uri'])) {
1306 $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
1307 $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
1308 $return_path = DI::args()->getCommand();
1310 if (!DBA::isResult($items)) {
1311 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1313 * Hmmm, code depending on the presence of a particular addon?
1314 * This should be better if done by a hook
1317 if (Addon::isEnabled('qcomment')) {
1318 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1319 $qcomment = $words ? explode("\n", $words) : [];
1322 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1323 '$return_path' => '',
1324 '$jsreload' => $return_path,
1325 '$id' => $link_item['id'],
1326 '$parent' => $link_item['id'],
1327 '$profile_uid' => $owner_uid,
1328 '$mylink' => $contact['url'],
1329 '$mytitle' => DI::l10n()->t('This is you'),
1330 '$myphoto' => $contact['thumb'],
1331 '$comment' => DI::l10n()->t('Comment'),
1332 '$submit' => DI::l10n()->t('Submit'),
1333 '$preview' => DI::l10n()->t('Preview'),
1334 '$loading' => DI::l10n()->t('Loading...'),
1335 '$qcomment' => $qcomment,
1336 '$rand_num' => Crypto::randomDigits(12)
1349 if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
1350 unset($conv_responses['dislike']);
1354 if (DBA::isResult($items)) {
1355 foreach ($items as $item) {
1356 DI::conversation()->builtinActivityPuller($item, $conv_responses);
1359 if (!empty($conv_responses['like'][$link_item['uri']])) {
1360 $like = DI::conversation()->formatActivity($conv_responses['like'][$link_item['uri']]['links'], 'like', $link_item['id']);
1363 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1364 $dislike = DI::conversation()->formatActivity($conv_responses['dislike'][$link_item['uri']]['links'], 'dislike', $link_item['id']);
1367 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1369 * Hmmm, code depending on the presence of a particular addon?
1370 * This should be better if done by a hook
1373 if (Addon::isEnabled('qcomment')) {
1374 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1375 $qcomment = $words ? explode("\n", $words) : [];
1378 $comments .= Renderer::replaceMacros($cmnt_tpl,[
1379 '$return_path' => '',
1380 '$jsreload' => $return_path,
1381 '$id' => $link_item['id'],
1382 '$parent' => $link_item['id'],
1383 '$profile_uid' => $owner_uid,
1384 '$mylink' => $contact['url'],
1385 '$mytitle' => DI::l10n()->t('This is you'),
1386 '$myphoto' => $contact['thumb'],
1387 '$comment' => DI::l10n()->t('Comment'),
1388 '$submit' => DI::l10n()->t('Submit'),
1389 '$preview' => DI::l10n()->t('Preview'),
1390 '$qcomment' => $qcomment,
1391 '$rand_num' => Crypto::randomDigits(12)
1395 foreach ($items as $item) {
1399 $activity = DI::activity();
1401 if (($activity->match($item['verb'], Activity::LIKE) ||
1402 $activity->match($item['verb'], Activity::DISLIKE)) &&
1403 ($item['gravity'] != Item::GRAVITY_PARENT)) {
1407 $author = ['uid' => 0, 'id' => $item['author-id'],
1408 'network' => $item['author-network'], 'url' => $item['author-link']];
1409 $profile_url = Contact::magicLinkByContact($author);
1410 if (strpos($profile_url, 'redir/') === 0) {
1411 $sparkle = ' sparkle';
1416 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1418 'dropping' => $dropping,
1419 'pagedrop' => false,
1420 'select' => DI::l10n()->t('Select'),
1421 'delete' => DI::l10n()->t('Delete'),
1424 $title_e = $item['title'];
1425 $body_e = BBCode::convertForUriId($item['uri-id'], $item['body']);
1427 $comments .= Renderer::replaceMacros($template,[
1428 '$id' => $item['id'],
1429 '$profile_url' => $profile_url,
1430 '$name' => $item['author-name'],
1431 '$thumb' => $item['author-avatar'],
1432 '$sparkle' => $sparkle,
1433 '$title' => $title_e,
1435 '$ago' => Temporal::getRelativeDate($item['created']),
1436 '$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''),
1438 '$comment' => $comment
1441 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1443 * Hmmm, code depending on the presence of a particular addon?
1444 * This should be better if done by a hook
1447 if (Addon::isEnabled('qcomment')) {
1448 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1449 $qcomment = $words ? explode("\n", $words) : [];
1452 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1453 '$return_path' => '',
1454 '$jsreload' => $return_path,
1455 '$id' => $item['id'],
1456 '$parent' => $item['parent'],
1457 '$profile_uid' => $owner_uid,
1458 '$mylink' => $contact['url'],
1459 '$mytitle' => DI::l10n()->t('This is you'),
1460 '$myphoto' => $contact['thumb'],
1461 '$comment' => DI::l10n()->t('Comment'),
1462 '$submit' => DI::l10n()->t('Submit'),
1463 '$preview' => DI::l10n()->t('Preview'),
1464 '$qcomment' => $qcomment,
1465 '$rand_num' => Crypto::randomDigits(12)
1472 foreach ($conv_responses as $verb => $activity) {
1473 if (isset($activity[$link_item['uri']])) {
1474 $responses[$verb] = $activity[$link_item['uri']];
1478 if ($cmd === 'view' && ($can_post || Security::canWriteToUserWall($owner_uid))) {
1479 $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl');
1480 $likebuttons = Renderer::replaceMacros($like_tpl, [
1481 '$id' => $link_item['id'],
1482 '$like' => DI::l10n()->t('Like'),
1483 '$like_title' => DI::l10n()->t('I like this (toggle)'),
1484 '$dislike' => DI::l10n()->t('Dislike'),
1485 '$wait' => DI::l10n()->t('Please wait'),
1486 '$dislike_title' => DI::l10n()->t('I don\'t like this (toggle)'),
1487 '$hide_dislike' => DI::pConfig()->get(local_user(), 'system', 'hide_dislike'),
1488 '$responses' => $responses,
1489 '$return_path' => DI::args()->getQueryString(),
1493 $paginate = $pager->renderFull($total);
1496 $photo_tpl = Renderer::getMarkupTemplate('photo_view.tpl');
1497 $o .= Renderer::replaceMacros($photo_tpl, [
1498 '$id' => $ph[0]['id'],
1499 '$album' => [$album_link, $ph[0]['album']],
1502 '$prevlink' => $prevlink,
1503 '$nextlink' => $nextlink,
1504 '$desc' => $ph[0]['desc'],
1508 '$map_text' => DI::l10n()->t('Map'),
1509 '$likebuttons' => $likebuttons,
1511 '$dislike' => $dislike,
1512 '$comments' => $comments,
1513 '$paginate' => $paginate,
1516 DI::page()['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
1517 DI::page()['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1518 DI::page()['htmlhead'] .= '<meta name="twitter:image" content="' . DI::baseUrl() . "/" . $photo["href"] . '" />' . "\n";
1519 DI::page()['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1520 DI::page()['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1525 // Default - show recent photos with upload link (if applicable)
1528 $r = DBA::toArray(DBA::p("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = ? AND `photo-type` = ?
1529 $sql_extra GROUP BY `resource-id`",
1533 if (DBA::isResult($r)) {
1537 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
1539 $r = DBA::toArray(DBA::p("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1540 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1541 ANY_VALUE(`created`) AS `created` FROM `photo`
1542 WHERE `uid` = ? AND `photo-type` = ?
1543 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT ? , ?",
1547 $pager->getItemsPerPage()
1551 if (DBA::isResult($r)) {
1552 // "Twist" is only used for the duepunto theme with style "slackr"
1554 foreach ($r as $rr) {
1556 $ext = $phototypes[$rr['type']];
1558 $alt_e = $rr['filename'];
1559 $name_e = $rr['album'];
1563 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1564 'link' => 'photos/' . $user['nickname'] . '/image/' . $rr['resource-id'],
1565 'title' => DI::l10n()->t('View Photo'),
1566 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1569 'link' => 'photos/' . $user['nickname'] . '/album/' . bin2hex($rr['album']),
1571 'alt' => DI::l10n()->t('View Album'),
1578 $tpl = Renderer::getMarkupTemplate('photos_recent.tpl');
1579 $o .= Renderer::replaceMacros($tpl, [
1580 '$title' => DI::l10n()->t('Recent Photos'),
1581 '$can_post' => $can_post,
1582 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $user['nickname'] . '/upload'],
1583 '$photos' => $photos,
1584 '$paginate' => $pager->renderFull($total),