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\Tag;
42 use Friendica\Model\User;
43 use Friendica\Module\BaseProfile;
44 use Friendica\Network\Probe;
45 use Friendica\Object\Image;
46 use Friendica\Protocol\Activity;
47 use Friendica\Util\Crypto;
48 use Friendica\Util\DateTimeFormat;
49 use Friendica\Util\Images;
50 use Friendica\Util\Map;
51 use Friendica\Security\Security;
52 use Friendica\Util\Strings;
53 use Friendica\Util\Temporal;
54 use Friendica\Util\XML;
55 use Friendica\Network\HTTPException;
57 function photos_init(App $a) {
59 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
63 Nav::setSelected('home');
66 $owner = User::getOwnerDataByNick($a->argv[1]);
68 $is_owner = (local_user() && (local_user() == $owner['uid']));
70 $albums = Photo::getAlbums($owner['uid']);
72 $albums_visible = ((intval($owner['hidewall']) && !Session::isAuthenticated()) ? false : true);
74 // add various encodings to the array so we can just loop through and pick them out in a template
75 $ret = ['success' => false];
78 if ($albums_visible) {
79 $ret['success'] = true;
83 foreach ($albums as $k => $album) {
84 //hide profile photos to others
85 if (!$is_owner && !Session::getRemoteContactID($owner['uid']) && ($album['album'] == DI::l10n()->t('Profile Photos')))
88 'text' => $album['album'],
89 'total' => $album['total'],
90 'url' => 'photos/' . $owner['nickname'] . '/album/' . bin2hex($album['album']),
91 'urlencode' => urlencode($album['album']),
92 'bin2hex' => bin2hex($album['album'])
94 $ret['albums'][] = $entry;
98 if (local_user() && $owner['uid'] == local_user()) {
104 if ($ret['success']) {
105 $photo_albums_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('photo_albums.tpl'), [
106 '$nick' => $owner['nickname'],
107 '$title' => DI::l10n()->t('Photo Albums'),
108 '$recent' => DI::l10n()->t('Recent Photos'),
109 '$albums' => $ret['albums'],
110 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $owner['nickname'] . '/upload'],
111 '$can_post' => $can_post
115 if (empty(DI::page()['aside'])) {
116 DI::page()['aside'] = '';
119 DI::page()['aside'] .= Widget\VCard::getHTML($owner);
121 if (!empty($photo_albums_widget)) {
122 DI::page()['aside'] .= $photo_albums_widget;
125 $tpl = Renderer::getMarkupTemplate("photos_head.tpl");
127 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
128 '$ispublic' => DI::l10n()->t('everybody')
135 function photos_post(App $a)
137 $user = User::getByNickname($a->argv[1]);
138 if (!DBA::isResult($user)) {
139 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
142 $phototypes = Images::supportedTypes();
147 $page_owner_uid = intval($user['uid']);
148 $community_page = $user['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
150 if (local_user() && (local_user() == $page_owner_uid)) {
152 } elseif ($community_page && !empty(Session::getRemoteContactID($page_owner_uid))) {
153 $contact_id = Session::getRemoteContactID($page_owner_uid);
155 $visitor = $contact_id;
159 notice(DI::l10n()->t('Permission denied.'));
163 $owner_record = User::getOwnerDataById($page_owner_uid);
165 if (!$owner_record) {
166 notice(DI::l10n()->t('Contact information unavailable'));
167 DI::logger()->info('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
171 $aclFormatter = DI::aclFormatter();
172 $str_contact_allow = isset($_REQUEST['contact_allow']) ? $aclFormatter->toString($_REQUEST['contact_allow']) : $owner_record['allow_cid'] ?? '';
173 $str_group_allow = isset($_REQUEST['group_allow']) ? $aclFormatter->toString($_REQUEST['group_allow']) : $owner_record['allow_gid'] ?? '';
174 $str_contact_deny = isset($_REQUEST['contact_deny']) ? $aclFormatter->toString($_REQUEST['contact_deny']) : $owner_record['deny_cid'] ?? '';
175 $str_group_deny = isset($_REQUEST['group_deny']) ? $aclFormatter->toString($_REQUEST['group_deny']) : $owner_record['deny_gid'] ?? '';
177 $visibility = $_REQUEST['visibility'] ?? '';
178 if ($visibility === 'public') {
179 // The ACL selector introduced in version 2019.12 sends ACL input data even when the Public visibility is selected
180 $str_contact_allow = $str_group_allow = $str_contact_deny = $str_group_deny = '';
181 } else if ($visibility === 'custom') {
182 // Since we know from the visibility parameter the item should be private, we have to prevent the empty ACL
183 // case that would make it public. So we always append the author's contact id to the allowed contacts.
184 // See https://github.com/friendica/friendica/issues/9672
185 $str_contact_allow .= $aclFormatter->toString(Contact::getPublicIdByUserId($page_owner_uid));
188 if ($a->argc > 3 && $a->argv[2] === 'album') {
189 if (!Strings::isHex($a->argv[3])) {
190 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
192 $album = hex2bin($a->argv[3]);
194 if ($album === DI::l10n()->t('Profile Photos') || $album === Photo::CONTACT_PHOTOS || $album === DI::l10n()->t(Photo::CONTACT_PHOTOS)) {
195 DI::baseUrl()->redirect($_SESSION['photo_return']);
196 return; // NOTREACHED
199 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
201 intval($page_owner_uid)
204 if (!DBA::isResult($r)) {
205 notice(DI::l10n()->t('Album not found.'));
206 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
207 return; // NOTREACHED
210 // Check if the user has responded to a delete confirmation query
211 if (!empty($_REQUEST['canceled'])) {
212 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album/' . $a->argv[3]);
215 // RENAME photo album
216 $newalbum = Strings::escapeTags(trim($_POST['albumname']));
217 if ($newalbum != $album) {
218 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
219 DBA::escape($newalbum),
221 intval($page_owner_uid)
223 // Update the photo albums cache
224 Photo::clearAlbumCache($page_owner_uid);
226 DI::baseUrl()->redirect('photos/' . $a->user['nickname'] . '/album/' . bin2hex($newalbum));
227 return; // NOTREACHED
231 * DELETE all photos filed in a given album
233 if (!empty($_POST['dropalbum'])) {
236 // get the list of photos we are about to delete
238 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
240 intval($page_owner_uid),
244 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
245 intval(local_user()),
250 if (DBA::isResult($r)) {
251 foreach ($r as $rr) {
255 // remove the associated photos
256 Photo::delete(['resource-id' => $res, 'uid' => $page_owner_uid]);
258 // find and delete the corresponding item with all the comments and likes/dislikes
259 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
261 // Update the photo albums cache
262 Photo::clearAlbumCache($page_owner_uid);
263 notice(DI::l10n()->t('Album successfully deleted'));
265 notice(DI::l10n()->t('Album was empty.'));
269 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
272 if ($a->argc > 3 && $a->argv[2] === 'image') {
273 // Check if the user has responded to a delete confirmation query for a single photo
274 if (!empty($_POST['canceled'])) {
275 DI::baseUrl()->redirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]);
278 if (!empty($_POST['delete'])) {
279 // same as above but remove single photo
281 $condition = ['contact-id' => $visitor, 'uid' => $page_owner_uid, 'resource-id' => $a->argv[3]];
284 $condition = ['uid' => local_user(), 'resource-id' => $a->argv[3]];
287 $photo = DBA::selectFirst('photo', ['resource-id'], $condition);
289 if (DBA::isResult($photo)) {
290 Photo::delete(['uid' => $page_owner_uid, 'resource-id' => $photo['resource-id']]);
292 Item::deleteForUser(['resource-id' => $photo['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
294 // Update the photo albums cache
295 Photo::clearAlbumCache($page_owner_uid);
297 notice(DI::l10n()->t('Failed to delete the photo.'));
298 DI::baseUrl()->redirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]);
301 DI::baseUrl()->redirect('photos/' . $a->argv[1]);
302 return; // NOTREACHED
306 if ($a->argc > 2 && (!empty($_POST['desc']) || !empty($_POST['newtag']) || isset($_POST['albname']))) {
307 $desc = !empty($_POST['desc']) ? Strings::escapeTags(trim($_POST['desc'])) : '';
308 $rawtags = !empty($_POST['newtag']) ? Strings::escapeTags(trim($_POST['newtag'])) : '';
309 $item_id = !empty($_POST['item_id']) ? intval($_POST['item_id']) : 0;
310 $albname = !empty($_POST['albname']) ? trim($_POST['albname']) : '';
311 $origaname = !empty($_POST['origaname']) ? Strings::escapeTags(trim($_POST['origaname'])) : '';
313 $resource_id = $a->argv[3];
315 if (!strlen($albname)) {
316 $albname = DateTimeFormat::localNow('Y');
319 if (!empty($_POST['rotate']) && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
320 Logger::log('rotate');
322 $photo = Photo::getPhotoForUser($page_owner_uid, $resource_id);
324 if (DBA::isResult($photo)) {
325 $image = Photo::getImageForPhoto($photo);
327 if ($image->isValid()) {
328 $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
329 $image->rotate($rotate_deg);
331 $width = $image->getWidth();
332 $height = $image->getHeight();
334 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 0], $image);
336 if ($width > 640 || $height > 640) {
337 $image->scaleDown(640);
338 $width = $image->getWidth();
339 $height = $image->getHeight();
341 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 1], $image);
344 if ($width > 320 || $height > 320) {
345 $image->scaleDown(320);
346 $width = $image->getWidth();
347 $height = $image->getHeight();
349 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 2], $image);
355 $photos_stmt = DBA::select('photo', [], ['resource-id' => $resource_id, 'uid' => $page_owner_uid], ['order' => ['scale' => true]]);
357 $photos = DBA::toArray($photos_stmt);
359 if (DBA::isResult($photos)) {
361 $ext = $phototypes[$photo['type']];
363 ['desc' => $desc, 'album' => $albname, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow, 'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny],
364 ['resource-id' => $resource_id, 'uid' => $page_owner_uid]
367 // Update the photo albums cache if album name was changed
368 if ($albname !== $origaname) {
369 Photo::clearAlbumCache($page_owner_uid);
371 /* Don't make the item visible if the only change was the album name */
374 if ($photo['desc'] !== $desc || strlen($rawtags)) {
379 if (DBA::isResult($photos) && !$item_id) {
380 // Create item container
382 $uri = Item::newURI($page_owner_uid);
385 $arr['guid'] = System::createUUID();
386 $arr['uid'] = $page_owner_uid;
388 $arr['post-type'] = Item::PT_IMAGE;
390 $arr['resource-id'] = $photo['resource-id'];
391 $arr['contact-id'] = $owner_record['id'];
392 $arr['owner-name'] = $owner_record['name'];
393 $arr['owner-link'] = $owner_record['url'];
394 $arr['owner-avatar'] = $owner_record['thumb'];
395 $arr['author-name'] = $owner_record['name'];
396 $arr['author-link'] = $owner_record['url'];
397 $arr['author-avatar'] = $owner_record['thumb'];
398 $arr['title'] = $title;
399 $arr['allow_cid'] = $photo['allow_cid'];
400 $arr['allow_gid'] = $photo['allow_gid'];
401 $arr['deny_cid'] = $photo['deny_cid'];
402 $arr['deny_gid'] = $photo['deny_gid'];
403 $arr['visible'] = $visibility;
406 $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $user['nickname'] . '/image/' . $photo['resource-id'] . ']'
407 . '[img]' . DI::baseUrl() . '/photo/' . $photo['resource-id'] . '-' . $photo['scale'] . '.'. $ext . '[/img]'
410 $item_id = Item::insert($arr);
414 $item = Post::selectFirst(['tag', 'inform', 'uri-id'], ['id' => $item_id, 'uid' => $page_owner_uid]);
416 if (DBA::isResult($item)) {
417 $old_inform = $item['inform'];
421 if (strlen($rawtags)) {
424 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
425 $x = substr($rawtags, 0, 1);
426 if ($x !== '@' && $x !== '#') {
427 $rawtags = '#' . $rawtags;
431 $tags = BBCode::getTags($rawtags);
434 foreach ($tags as $tag) {
435 if (strpos($tag, '@') === 0) {
438 $name = substr($tag,1);
440 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
442 $links = @Probe::lrdd($name);
445 foreach ($links as $link) {
446 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
447 $profile = $link['@attributes']['href'];
450 if ($link['@attributes']['rel'] === 'salmon') {
451 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
453 if (strlen($inform)) {
462 $taginfo[] = [$newname, $profile, $salmon];
467 if (strrpos($newname, '+')) {
468 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
472 $contact = DBA::selectFirst('contact', [], ['id' => $tagcid, 'uid' => $page_owner_uid]);
474 $newname = str_replace('_',' ',$name);
476 //select someone from this user's contacts by name
477 $contact = DBA::selectFirst('contact', [], ['name' => $newname, 'uid' => $page_owner_uid]);
478 if (!DBA::isResult($contact)) {
479 //select someone by attag or nick and the name passed in
480 $contact = DBA::selectFirst('contact', [],
481 ['(`attag` = ? OR `nick` = ?) AND `uid` = ?', $name, $name, $page_owner_uid],
482 ['order' => ['attag' => true]]
487 if (DBA::isResult($contact)) {
488 $newname = $contact['name'];
489 $profile = $contact['url'];
491 $notify = 'cid:' . $contact['id'];
492 if (strlen($inform)) {
500 if (!empty($contact)) {
501 $taginfo[] = [$newname, $profile, $notify, $contact];
503 $taginfo[] = [$newname, $profile, $notify, null];
506 $profile = str_replace(',', '%2c', $profile);
508 if (!empty($item['uri-id'])) {
509 Tag::store($item['uri-id'], Tag::MENTION, $newname, $profile);
512 } elseif (strpos($tag, '#') === 0) {
513 $tagname = substr($tag, 1);
514 if (!empty($item['uri-id'])) {
515 Tag::store($item['uri-id'], Tag::HASHTAG, $tagname);
521 $newinform = $old_inform ?? '';
522 if (strlen($newinform) && strlen($inform)) {
525 $newinform .= $inform;
527 $fields = ['inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
528 $condition = ['id' => $item_id];
529 Item::update($fields, $condition);
532 foreach ($photos as $scales) {
533 if (intval($scales['scale']) == 2) {
538 if (intval($scales['scale']) == 4) {
544 if (count($taginfo)) {
545 foreach ($taginfo as $tagged) {
546 $uri = Item::newURI($page_owner_uid);
549 $arr['guid'] = System::createUUID();
550 $arr['uid'] = $page_owner_uid;
553 $arr['contact-id'] = $owner_record['id'];
554 $arr['owner-name'] = $owner_record['name'];
555 $arr['owner-link'] = $owner_record['url'];
556 $arr['owner-avatar'] = $owner_record['thumb'];
557 $arr['author-name'] = $owner_record['name'];
558 $arr['author-link'] = $owner_record['url'];
559 $arr['author-avatar'] = $owner_record['thumb'];
561 $arr['allow_cid'] = $photo['allow_cid'];
562 $arr['allow_gid'] = $photo['allow_gid'];
563 $arr['deny_cid'] = $photo['deny_cid'];
564 $arr['deny_gid'] = $photo['deny_gid'];
566 $arr['verb'] = Activity::TAG;
567 $arr['gravity'] = GRAVITY_PARENT;
568 $arr['object-type'] = Activity\ObjectType::PERSON;
569 $arr['target-type'] = Activity\ObjectType::IMAGE;
570 $arr['inform'] = $tagged[2];
572 $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]') ;
573 $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" ;
575 $arr['object'] = '<object><type>' . Activity\ObjectType::PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
576 $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
578 $arr['object'] .= XML::escape('<link rel="photo" type="' . $photo['type'] . '" href="' . $tagged[3]['photo'] . '" />' . "\n");
580 $arr['object'] .= '</link></object>' . "\n";
582 $arr['target'] = '<target><type>' . Activity\ObjectType::IMAGE . '</type><title>' . $photo['desc'] . '</title><id>'
583 . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '</id>';
584 $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>';
590 DI::baseUrl()->redirect($_SESSION['photo_return']);
591 return; // NOTREACHED
595 // default post action - upload a photo
596 Hook::callAll('photo_post_init', $_POST);
598 // Determine the album to use
599 $album = trim($_REQUEST['album'] ?? '');
600 $newalbum = trim($_REQUEST['newalbum'] ?? '');
602 Logger::info('album= ' . $album . ' newalbum= ' . $newalbum);
604 if (!strlen($album)) {
605 if (strlen($newalbum)) {
608 $album = DateTimeFormat::localNow('Y');
613 * We create a wall item for every photo, but we don't want to
614 * overwhelm the data stream with a hundred newly uploaded photos.
615 * So we will make the first photo uploaded to this album in the last several hours
616 * visible by default, the rest will become visible over time when and if
617 * they acquire comments, likes, dislikes, and/or tags
620 $r = Photo::selectToArray([], ['`album` = ? AND `uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR', $album, $page_owner_uid]);
622 if (!DBA::isResult($r) || ($album == DI::l10n()->t('Profile Photos'))) {
628 if (!empty($_REQUEST['not_visible']) && $_REQUEST['not_visible'] !== 'false') {
632 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
634 Hook::callAll('photo_post_file', $ret);
636 if (!empty($ret['src']) && !empty($ret['filesize'])) {
638 $filename = $ret['filename'];
639 $filesize = $ret['filesize'];
640 $type = $ret['type'];
641 $error = UPLOAD_ERR_OK;
642 } elseif (!empty($_FILES['userfile'])) {
643 $src = $_FILES['userfile']['tmp_name'];
644 $filename = basename($_FILES['userfile']['name']);
645 $filesize = intval($_FILES['userfile']['size']);
646 $type = $_FILES['userfile']['type'];
647 $error = $_FILES['userfile']['error'];
649 $error = UPLOAD_ERR_NO_FILE;
652 if ($error !== UPLOAD_ERR_OK) {
654 case UPLOAD_ERR_INI_SIZE:
655 notice(DI::l10n()->t('Image exceeds size limit of %s', ini_get('upload_max_filesize')));
657 case UPLOAD_ERR_FORM_SIZE:
658 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($_REQUEST['MAX_FILE_SIZE'] ?? 0)));
660 case UPLOAD_ERR_PARTIAL:
661 notice(DI::l10n()->t('Image upload didn\'t complete, please try again'));
663 case UPLOAD_ERR_NO_FILE:
664 notice(DI::l10n()->t('Image file is missing'));
666 case UPLOAD_ERR_NO_TMP_DIR:
667 case UPLOAD_ERR_CANT_WRITE:
668 case UPLOAD_ERR_EXTENSION:
669 notice(DI::l10n()->t('Server can\'t accept new file upload at this time, please contact your administrator'));
674 Hook::callAll('photo_post_end', $foo);
678 $type = Images::getMimeTypeBySource($src, $filename, $type);
680 Logger::log('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', Logger::DEBUG);
682 $maximagesize = DI::config()->get('system', 'maximagesize');
684 if ($maximagesize && ($filesize > $maximagesize)) {
685 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)));
688 Hook::callAll('photo_post_end', $foo);
693 notice(DI::l10n()->t('Image file is empty.'));
696 Hook::callAll('photo_post_end', $foo);
700 Logger::log('mod/photos.php: photos_post(): loading the contents of ' . $src , Logger::DEBUG);
702 $imagedata = @file_get_contents($src);
704 $image = new Image($imagedata, $type);
706 if (!$image->isValid()) {
707 Logger::log('mod/photos.php: photos_post(): unable to process image' , Logger::DEBUG);
708 notice(DI::l10n()->t('Unable to process image.'));
711 Hook::callAll('photo_post_end',$foo);
715 $exif = $image->orient($src);
718 $max_length = DI::config()->get('system', 'max_image_length');
720 $max_length = MAX_IMAGE_LENGTH;
722 if ($max_length > 0) {
723 $image->scaleDown($max_length);
726 $width = $image->getWidth();
727 $height = $image->getHeight();
731 $resource_id = Photo::newResource();
733 $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);
736 Logger::log('mod/photos.php: photos_post(): image store failed', Logger::DEBUG);
737 notice(DI::l10n()->t('Image upload failed.'));
741 if ($width > 640 || $height > 640) {
742 $image->scaleDown(640);
743 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);
747 if ($width > 320 || $height > 320) {
748 $image->scaleDown(320);
749 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);
753 $uri = Item::newURI($page_owner_uid);
755 // Create item container
757 if (!empty($exif['GPS']) && Feature::isEnabled($page_owner_uid, 'photo_location')) {
758 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
759 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
764 $arr['coord'] = $lat . ' ' . $lon;
767 $arr['guid'] = System::createUUID();
768 $arr['uid'] = $page_owner_uid;
770 $arr['post-type'] = Item::PT_IMAGE;
772 $arr['resource-id'] = $resource_id;
773 $arr['contact-id'] = $owner_record['id'];
774 $arr['owner-name'] = $owner_record['name'];
775 $arr['owner-link'] = $owner_record['url'];
776 $arr['owner-avatar'] = $owner_record['thumb'];
777 $arr['author-name'] = $owner_record['name'];
778 $arr['author-link'] = $owner_record['url'];
779 $arr['author-avatar'] = $owner_record['thumb'];
781 $arr['allow_cid'] = $str_contact_allow;
782 $arr['allow_gid'] = $str_group_allow;
783 $arr['deny_cid'] = $str_contact_deny;
784 $arr['deny_gid'] = $str_group_deny;
785 $arr['visible'] = $visible;
788 $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $resource_id . ']'
789 . '[img]' . DI::baseUrl() . "/photo/{$resource_id}-{$smallest}.".$image->getExt() . '[/img]'
792 $item_id = Item::insert($arr);
793 // Update the photo albums cache
794 Photo::clearAlbumCache($page_owner_uid);
796 Hook::callAll('photo_post_end', $item_id);
798 // addon uploaders should call "exit()" within the photo_post_end hook
799 // if they do not wish to be redirected
801 DI::baseUrl()->redirect($_SESSION['photo_return']);
805 function photos_content(App $a)
809 // photos/name/upload
810 // photos/name/upload/xxxxx (xxxxx is album name)
811 // photos/name/album/xxxxx
812 // photos/name/album/xxxxx/edit
813 // photos/name/album/xxxxx/drop
814 // photos/name/image/xxxxx
815 // photos/name/image/xxxxx/edit
816 // photos/name/image/xxxxx/drop
818 $user = User::getByNickname($a->argv[1]);
819 if (!DBA::isResult($user)) {
820 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
823 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
824 notice(DI::l10n()->t('Public access denied.'));
829 notice(DI::l10n()->t('No photos selected'));
833 $phototypes = Images::supportedTypes();
835 $_SESSION['photo_return'] = DI::args()->getCommand();
840 $datatype = $a->argv[2];
841 $datum = $a->argv[3];
842 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
843 $datatype = 'upload';
845 $datatype = 'summary';
854 // Setup permissions structures
858 $remote_contact = false;
863 $owner_uid = $user['uid'];
865 $community_page = (($user['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
867 if (local_user() && (local_user() == $owner_uid)) {
869 } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
870 $contact_id = Session::getRemoteContactID($owner_uid);
871 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
873 if (DBA::isResult($contact)) {
875 $remote_contact = true;
876 $visitor = $contact_id;
880 // perhaps they're visiting - but not a community page, so they wouldn't have write access
881 if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
882 $contact_id = Session::getRemoteContactID($owner_uid);
884 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
886 $remote_contact = DBA::isResult($contact);
889 if (!$remote_contact && local_user()) {
890 $contact_id = $_SESSION['cid'];
892 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
895 if ($user['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
896 notice(DI::l10n()->t('Access to this item is restricted.'));
900 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
905 $is_owner = (local_user() && (local_user() == $owner_uid));
906 $o .= BaseProfile::getTabsHTML($a, 'photos', $is_owner, $user);
908 // Display upload form
909 if ($datatype === 'upload') {
911 notice(DI::l10n()->t('Permission denied.'));
915 $selname = Strings::isHex($datum) ? hex2bin($datum) : '';
919 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '><current year></option>';
920 $albums = Photo::getAlbums($owner_uid);
921 if (!empty($albums)) {
922 foreach ($albums as $album) {
923 if (($album['album'] === '') || ($album['album'] === Photo::CONTACT_PHOTOS) || ($album['album'] === DI::l10n()->t(Photo::CONTACT_PHOTOS))) {
926 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
927 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
933 $ret = ['post_url' => 'photos/' . $user['nickname'],
934 'addon_text' => $uploader,
935 'default_upload' => true];
937 Hook::callAll('photo_upload_form',$ret);
939 $default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
940 $default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
941 '$submit' => DI::l10n()->t('Submit'),
946 $tpl = Renderer::getMarkupTemplate('photos_upload.tpl');
948 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML(DI::page(), $a->user));
950 $o .= Renderer::replaceMacros($tpl,[
951 '$pagename' => DI::l10n()->t('Upload Photos'),
952 '$sessid' => session_id(),
953 '$usage' => $usage_message,
954 '$nickname' => $user['nickname'],
955 '$newalbum' => DI::l10n()->t('New album name: '),
956 '$existalbumtext' => DI::l10n()->t('or select existing album:'),
957 '$nosharetext' => DI::l10n()->t('Do not show a status post for this upload'),
958 '$albumselect' => $albumselect,
959 '$permissions' => DI::l10n()->t('Permissions'),
960 '$aclselect' => $aclselect_e,
961 '$lockstate' => is_array($a->user)
962 && (strlen($a->user['allow_cid'])
963 || strlen($a->user['allow_gid'])
964 || strlen($a->user['deny_cid'])
965 || strlen($a->user['deny_gid'])
966 ) ? 'lock' : 'unlock',
967 '$alt_uploader' => $ret['addon_text'],
968 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
969 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
970 '$uploadurl' => $ret['post_url'],
972 // ACL permissions box
973 '$return_path' => DI::args()->getQueryString(),
979 // Display a single photo album
980 if ($datatype === 'album') {
981 // if $datum is not a valid hex, redirect to the default page
982 if (!Strings::isHex($datum)) {
983 DI::baseUrl()->redirect('photos/' . $user['nickname']. '/album');
985 $album = hex2bin($datum);
988 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
989 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
993 if (DBA::isResult($r)) {
997 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
999 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1000 $order_field = $_GET['order'] ?? '';
1001 if ($order_field === 'posted') {
1007 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1008 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1009 ANY_VALUE(`created`) as `created`
1010 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1011 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1013 DBA::escape($album),
1015 $pager->getItemsPerPage()
1018 if ($cmd === 'drop') {
1019 $drop_url = DI::args()->getQueryString();
1021 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1022 '$method' => 'post',
1023 '$message' => DI::l10n()->t('Do you really want to delete this photo album and all its photos?'),
1024 '$confirm' => DI::l10n()->t('Delete Album'),
1025 '$confirm_url' => $drop_url,
1026 '$confirm_name' => 'dropalbum',
1027 '$cancel' => DI::l10n()->t('Cancel'),
1032 if ($cmd === 'edit') {
1033 if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS))) {
1035 $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
1039 $o .= Renderer::replaceMacros($edit_tpl,[
1040 '$nametext' => DI::l10n()->t('New album name: '),
1041 '$nickname' => $user['nickname'],
1042 '$album' => $album_e,
1043 '$hexalbum' => bin2hex($album),
1044 '$submit' => DI::l10n()->t('Submit'),
1045 '$dropsubmit' => DI::l10n()->t('Delete Album')
1050 if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS)) && $can_post) {
1051 $edit = [DI::l10n()->t('Edit Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1052 $drop = [DI::l10n()->t('Drop Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/drop'];
1056 if ($order_field === 'posted') {
1057 $order = [DI::l10n()->t('Show Newest First'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1059 $order = [DI::l10n()->t('Show Oldest First'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '?order=posted', 'newest'];
1064 if (DBA::isResult($r)) {
1065 // "Twist" is only used for the duepunto theme with style "slackr"
1067 foreach ($r as $rr) {
1070 $ext = $phototypes[$rr['type']];
1072 $imgalt_e = $rr['filename'];
1073 $desc_e = $rr['desc'];
1077 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1078 'link' => 'photos/' . $user['nickname'] . '/image/' . $rr['resource-id']
1079 . ($order_field === 'posted' ? '?order=posted' : ''),
1080 'title' => DI::l10n()->t('View Photo'),
1081 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1085 'hash'=> $rr['resource-id'],
1090 $tpl = Renderer::getMarkupTemplate('photo_album.tpl');
1091 $o .= Renderer::replaceMacros($tpl, [
1092 '$photos' => $photos,
1094 '$can_post' => $can_post,
1095 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $user['nickname'] . '/upload/' . bin2hex($album)],
1099 '$paginate' => $pager->renderFull($total),
1106 // Display one photo
1107 if ($datatype === 'image') {
1108 // fetch image, item containing image, then comments
1109 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1110 $sql_extra ORDER BY `scale` ASC ",
1115 if (!DBA::isResult($ph)) {
1116 if (DBA::exists('photo', ['resource-id' => $datum, 'uid' => $owner_uid])) {
1117 notice(DI::l10n()->t('Permission denied. Access to this item may be restricted.'));
1119 notice(DI::l10n()->t('Photo not available'));
1124 if ($cmd === 'drop') {
1125 $drop_url = DI::args()->getQueryString();
1127 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1128 '$method' => 'post',
1129 '$message' => DI::l10n()->t('Do you really want to delete this photo?'),
1130 '$confirm' => DI::l10n()->t('Delete Photo'),
1131 '$confirm_url' => $drop_url,
1132 '$confirm_name' => 'delete',
1133 '$cancel' => DI::l10n()->t('Cancel'),
1141 * @todo This query is totally bad, the whole functionality has to be changed
1142 * The query leads to a really intense used index.
1143 * By now we hide it if someone wants to.
1145 if ($cmd === 'view' && !DI::config()->get('system', 'no_count', false)) {
1146 $order_field = $_GET['order'] ?? '';
1148 if ($order_field === 'posted') {
1154 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1155 $sql_extra ORDER BY `created` $order ",
1156 DBA::escape($ph[0]['album']),
1160 if (DBA::isResult($prvnxt)) {
1163 foreach ($prvnxt as $z => $entry) {
1164 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1168 $prv = count($prvnxt) - 1;
1170 if ($nxt >= count($prvnxt)) {
1177 if (!is_null($prv)) {
1178 $prevlink = 'photos/' . $user['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1180 if (!is_null($nxt)) {
1181 $nextlink = 'photos/' . $user['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1184 $tpl = Renderer::getMarkupTemplate('photo_edit_head.tpl');
1185 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
1186 '$prevlink' => $prevlink,
1187 '$nextlink' => $nextlink
1191 $prevlink = [$prevlink, '<div class="icon prev"></div>'];
1195 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1200 if (count($ph) == 1) {
1201 $hires = $lores = $ph[0];
1204 if (count($ph) > 1) {
1205 if ($ph[1]['scale'] == 2) {
1206 // original is 640 or less, we can display it directly
1207 $hires = $lores = $ph[0];
1214 $album_link = 'photos/' . $user['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1218 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1220 if ($cmd === 'edit') {
1221 $tools['view'] = ['photos/' . $user['nickname'] . '/image/' . $datum, DI::l10n()->t('View photo')];
1223 $tools['edit'] = ['photos/' . $user['nickname'] . '/image/' . $datum . '/edit', DI::l10n()->t('Edit photo')];
1224 $tools['delete'] = ['photos/' . $user['nickname'] . '/image/' . $datum . '/drop', DI::l10n()->t('Delete photo')];
1225 $tools['profile'] = ['settings/profile/photo/crop/' . $ph[0]['resource-id'], DI::l10n()->t('Use as profile photo')];
1229 $ph[0]['uid'] == local_user()
1230 && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']))
1232 $tools['lock'] = DI::l10n()->t('Private Photo');
1237 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1238 'title'=> DI::l10n()->t('View Full Size'),
1239 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?_u=' . DateTimeFormat::utcNow('ymdhis'),
1240 'height' => $hires['height'],
1241 'width' => $hires['width'],
1242 'album' => $hires['album'],
1243 'filename' => $hires['filename'],
1250 // Do we have an item for this photo?
1252 // FIXME! - replace following code to display the conversation with our normal
1253 // conversation functions so that it works correctly and tracks changes
1254 // in the evolving conversation code.
1255 // The difference is that we won't be displaying the conversation head item
1256 // as a "post" but displaying instead the photo it is linked to
1258 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1259 $linked_items = q("SELECT `id` FROM `post-user-view` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1262 if (DBA::isResult($linked_items)) {
1263 // This is a workaround to not being forced to rewrite the while $sql_extra handling
1264 $link_item = Post::selectFirst([], ['id' => $linked_items[0]['id']]);
1267 if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
1268 $condition = ["`parent` = ? AND `gravity` = ?", $link_item['parent'], GRAVITY_COMMENT];
1269 $total = Post::count($condition);
1271 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
1273 $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1274 $items = Post::toArray(Post::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params));
1276 if (local_user() == $link_item['uid']) {
1277 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1281 if (!empty($link_item['coord'])) {
1282 $map = Map::byCoordinates($link_item['coord']);
1287 if (!empty($link_item['id'])) {
1288 $tag_text = Tag::getCSVByURIId($link_item['uri-id']);
1289 $arr = explode(',', $tag_text);
1290 // parse tags and add links
1292 foreach ($arr as $tag) {
1294 'name' => BBCode::convert($tag),
1295 'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag)
1298 $tags = ['title' => DI::l10n()->t('Tags: '), 'tags' => $tag_arr];
1299 if ($cmd === 'edit') {
1300 $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
1301 $tags['removetitle'] = DI::l10n()->t('[Select tags to remove]');
1307 if ($cmd === 'edit' && $can_post) {
1308 $edit_tpl = Renderer::getMarkupTemplate('photo_edit.tpl');
1310 $album_e = $ph[0]['album'];
1311 $caption_e = $ph[0]['desc'];
1312 $aclselect_e = ACL::getFullSelectorHTML(DI::page(), $a->user, false, ACL::getDefaultUserPermissions($ph[0]));
1314 $edit = Renderer::replaceMacros($edit_tpl, [
1315 '$id' => $ph[0]['id'],
1316 '$album' => ['albname', DI::l10n()->t('New album name'), $album_e,''],
1317 '$caption' => ['desc', DI::l10n()->t('Caption'), $caption_e, ''],
1318 '$tags' => ['newtag', DI::l10n()->t('Add a Tag'), "", DI::l10n()->t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1319 '$rotate_none' => ['rotate', DI::l10n()->t('Do not rotate'),0,'', true],
1320 '$rotate_cw' => ['rotate', DI::l10n()->t("Rotate CW \x28right\x29"),1,''],
1321 '$rotate_ccw' => ['rotate', DI::l10n()->t("Rotate CCW \x28left\x29"),2,''],
1323 '$nickname' => $user['nickname'],
1324 '$resource_id' => $ph[0]['resource-id'],
1325 '$permissions' => DI::l10n()->t('Permissions'),
1326 '$aclselect' => $aclselect_e,
1328 '$item_id' => $link_item['id'] ?? 0,
1329 '$submit' => DI::l10n()->t('Submit'),
1330 '$delete' => DI::l10n()->t('Delete Photo'),
1332 // ACL permissions box
1333 '$return_path' => DI::args()->getQueryString(),
1343 if (!empty($link_item['id']) && !empty($link_item['uri'])) {
1344 $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
1345 $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
1346 $return_path = DI::args()->getCommand();
1348 if (!DBA::isResult($items)) {
1349 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1351 * Hmmm, code depending on the presence of a particular addon?
1352 * This should be better if done by a hook
1355 if (Addon::isEnabled('qcomment')) {
1356 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1357 $qcomment = $words ? explode("\n", $words) : [];
1360 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1361 '$return_path' => '',
1362 '$jsreload' => $return_path,
1363 '$id' => $link_item['id'],
1364 '$parent' => $link_item['id'],
1365 '$profile_uid' => $owner_uid,
1366 '$mylink' => $contact['url'],
1367 '$mytitle' => DI::l10n()->t('This is you'),
1368 '$myphoto' => $contact['thumb'],
1369 '$comment' => DI::l10n()->t('Comment'),
1370 '$submit' => DI::l10n()->t('Submit'),
1371 '$preview' => DI::l10n()->t('Preview'),
1372 '$loading' => DI::l10n()->t('Loading...'),
1373 '$qcomment' => $qcomment,
1374 '$rand_num' => Crypto::randomDigits(12)
1387 if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
1388 unset($conv_responses['dislike']);
1392 if (DBA::isResult($items)) {
1393 foreach ($items as $item) {
1394 builtin_activity_puller($item, $conv_responses);
1397 if (!empty($conv_responses['like'][$link_item['uri']])) {
1398 $like = format_activity($conv_responses['like'][$link_item['uri']]['links'], 'like', $link_item['id']);
1401 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1402 $dislike = format_activity($conv_responses['dislike'][$link_item['uri']]['links'], 'dislike', $link_item['id']);
1405 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1407 * Hmmm, code depending on the presence of a particular addon?
1408 * This should be better if done by a hook
1411 if (Addon::isEnabled('qcomment')) {
1412 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1413 $qcomment = $words ? explode("\n", $words) : [];
1416 $comments .= Renderer::replaceMacros($cmnt_tpl,[
1417 '$return_path' => '',
1418 '$jsreload' => $return_path,
1419 '$id' => $link_item['id'],
1420 '$parent' => $link_item['id'],
1421 '$profile_uid' => $owner_uid,
1422 '$mylink' => $contact['url'],
1423 '$mytitle' => DI::l10n()->t('This is you'),
1424 '$myphoto' => $contact['thumb'],
1425 '$comment' => DI::l10n()->t('Comment'),
1426 '$submit' => DI::l10n()->t('Submit'),
1427 '$preview' => DI::l10n()->t('Preview'),
1428 '$qcomment' => $qcomment,
1429 '$rand_num' => Crypto::randomDigits(12)
1433 foreach ($items as $item) {
1437 $activity = DI::activity();
1439 if (($activity->match($item['verb'], Activity::LIKE) ||
1440 $activity->match($item['verb'], Activity::DISLIKE)) &&
1441 ($item['gravity'] != GRAVITY_PARENT)) {
1445 $author = ['uid' => 0, 'id' => $item['author-id'],
1446 'network' => $item['author-network'], 'url' => $item['author-link']];
1447 $profile_url = Contact::magicLinkByContact($author);
1448 if (strpos($profile_url, 'redir/') === 0) {
1449 $sparkle = ' sparkle';
1454 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1456 'dropping' => $dropping,
1457 'pagedrop' => false,
1458 'select' => DI::l10n()->t('Select'),
1459 'delete' => DI::l10n()->t('Delete'),
1462 $title_e = $item['title'];
1463 $body_e = BBCode::convert($item['body']);
1465 $comments .= Renderer::replaceMacros($template,[
1466 '$id' => $item['id'],
1467 '$profile_url' => $profile_url,
1468 '$name' => $item['author-name'],
1469 '$thumb' => $item['author-avatar'],
1470 '$sparkle' => $sparkle,
1471 '$title' => $title_e,
1473 '$ago' => Temporal::getRelativeDate($item['created']),
1474 '$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''),
1476 '$comment' => $comment
1479 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1481 * Hmmm, code depending on the presence of a particular addon?
1482 * This should be better if done by a hook
1485 if (Addon::isEnabled('qcomment')) {
1486 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1487 $qcomment = $words ? explode("\n", $words) : [];
1490 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1491 '$return_path' => '',
1492 '$jsreload' => $return_path,
1493 '$id' => $item['id'],
1494 '$parent' => $item['parent'],
1495 '$profile_uid' => $owner_uid,
1496 '$mylink' => $contact['url'],
1497 '$mytitle' => DI::l10n()->t('This is you'),
1498 '$myphoto' => $contact['thumb'],
1499 '$comment' => DI::l10n()->t('Comment'),
1500 '$submit' => DI::l10n()->t('Submit'),
1501 '$preview' => DI::l10n()->t('Preview'),
1502 '$qcomment' => $qcomment,
1503 '$rand_num' => Crypto::randomDigits(12)
1510 foreach ($conv_responses as $verb => $activity) {
1511 if (isset($activity[$link_item['uri']])) {
1512 $responses[$verb] = $activity[$link_item['uri']];
1516 if ($cmd === 'view' && ($can_post || Security::canWriteToUserWall($owner_uid))) {
1517 $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl');
1518 $likebuttons = Renderer::replaceMacros($like_tpl, [
1519 '$id' => $link_item['id'],
1520 '$like' => DI::l10n()->t('Like'),
1521 '$like_title' => DI::l10n()->t('I like this (toggle)'),
1522 '$dislike' => DI::l10n()->t('Dislike'),
1523 '$wait' => DI::l10n()->t('Please wait'),
1524 '$dislike_title' => DI::l10n()->t('I don\'t like this (toggle)'),
1525 '$hide_dislike' => DI::pConfig()->get(local_user(), 'system', 'hide_dislike'),
1526 '$responses' => $responses,
1527 '$return_path' => DI::args()->getQueryString(),
1531 $paginate = $pager->renderFull($total);
1534 $photo_tpl = Renderer::getMarkupTemplate('photo_view.tpl');
1535 $o .= Renderer::replaceMacros($photo_tpl, [
1536 '$id' => $ph[0]['id'],
1537 '$album' => [$album_link, $ph[0]['album']],
1540 '$prevlink' => $prevlink,
1541 '$nextlink' => $nextlink,
1542 '$desc' => $ph[0]['desc'],
1546 '$map_text' => DI::l10n()->t('Map'),
1547 '$likebuttons' => $likebuttons,
1549 '$dislike' => $dislike,
1550 '$comments' => $comments,
1551 '$paginate' => $paginate,
1554 DI::page()['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
1555 DI::page()['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1556 DI::page()['htmlhead'] .= '<meta name="twitter:image" content="' . DI::baseUrl() . "/" . $photo["href"] . '" />' . "\n";
1557 DI::page()['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1558 DI::page()['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1563 // Default - show recent photos with upload link (if applicable)
1566 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1567 $sql_extra GROUP BY `resource-id`",
1568 intval($user['uid']),
1569 DBA::escape(Photo::CONTACT_PHOTOS),
1570 DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS))
1572 if (DBA::isResult($r)) {
1576 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
1578 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1579 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1580 ANY_VALUE(`created`) AS `created` FROM `photo`
1581 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1582 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1583 intval($user['uid']),
1584 DBA::escape(Photo::CONTACT_PHOTOS),
1585 DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS)),
1587 $pager->getItemsPerPage()
1591 if (DBA::isResult($r)) {
1592 // "Twist" is only used for the duepunto theme with style "slackr"
1594 foreach ($r as $rr) {
1595 //hide profile photos to others
1596 if (!$is_owner && !Session::getRemoteContactID($owner_uid) && ($rr['album'] == DI::l10n()->t('Profile Photos'))) {
1601 $ext = $phototypes[$rr['type']];
1603 $alt_e = $rr['filename'];
1604 $name_e = $rr['album'];
1608 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1609 'link' => 'photos/' . $user['nickname'] . '/image/' . $rr['resource-id'],
1610 'title' => DI::l10n()->t('View Photo'),
1611 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1614 'link' => 'photos/' . $user['nickname'] . '/album/' . bin2hex($rr['album']),
1616 'alt' => DI::l10n()->t('View Album'),
1623 $tpl = Renderer::getMarkupTemplate('photos_recent.tpl');
1624 $o .= Renderer::replaceMacros($tpl, [
1625 '$title' => DI::l10n()->t('Recent Photos'),
1626 '$can_post' => $can_post,
1627 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/'.$user['nickname'].'/upload'],
1628 '$photos' => $photos,
1629 '$paginate' => $pager->renderFull($total),