3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 use Friendica\Content\Feature;
24 use Friendica\Content\Nav;
25 use Friendica\Content\Pager;
26 use Friendica\Content\Text\BBCode;
27 use Friendica\Core\ACL;
28 use Friendica\Core\Hook;
29 use Friendica\Core\Logger;
30 use Friendica\Core\Renderer;
31 use Friendica\Core\Session;
32 use Friendica\Core\System;
33 use Friendica\Database\DBA;
35 use Friendica\Model\Contact;
36 use Friendica\Model\Item;
37 use Friendica\Model\Photo;
38 use Friendica\Model\Profile;
39 use Friendica\Model\Tag;
40 use Friendica\Model\User;
41 use Friendica\Module\BaseProfile;
42 use Friendica\Network\Probe;
43 use Friendica\Object\Image;
44 use Friendica\Protocol\Activity;
45 use Friendica\Util\Crypto;
46 use Friendica\Util\DateTimeFormat;
47 use Friendica\Util\Images;
48 use Friendica\Util\Map;
49 use Friendica\Util\Security;
50 use Friendica\Util\Strings;
51 use Friendica\Util\Temporal;
52 use Friendica\Util\XML;
54 function photos_init(App $a) {
56 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
60 Nav::setSelected('home');
64 $user = DBA::selectFirst('user', [], ['nickname' => $nick, 'blocked' => false]);
66 if (!DBA::isResult($user)) {
70 $a->data['user'] = $user;
71 $a->profile_uid = $user['uid'];
72 $is_owner = (local_user() && (local_user() == $a->profile_uid));
74 $profile = Profile::getByNickname($nick, $a->profile_uid);
76 $account_type = Contact::getAccountType($profile);
78 $tpl = Renderer::getMarkupTemplate('widget/vcard.tpl');
80 $vcard_widget = Renderer::replaceMacros($tpl, [
81 '$name' => $profile['name'],
82 '$photo' => $profile['photo'],
83 '$addr' => $profile['addr'] ?? '',
84 '$account_type' => $account_type,
85 '$about' => BBCode::convert($profile['about'] ?? ''),
88 $albums = Photo::getAlbums($a->data['user']['uid']);
90 $albums_visible = ((intval($a->data['user']['hidewall']) && !Session::isAuthenticated()) ? false : true);
92 // add various encodings to the array so we can just loop through and pick them out in a template
93 $ret = ['success' => false];
96 $a->data['albums'] = $albums;
98 if ($albums_visible) {
99 $ret['success'] = true;
103 foreach ($albums as $k => $album) {
104 //hide profile photos to others
105 if (!$is_owner && !Session::getRemoteContactID($a->profile_uid) && ($album['album'] == DI::l10n()->t('Profile Photos')))
108 'text' => $album['album'],
109 'total' => $album['total'],
110 'url' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
111 'urlencode' => urlencode($album['album']),
112 'bin2hex' => bin2hex($album['album'])
114 $ret['albums'][] = $entry;
118 if (local_user() && $a->data['user']['uid'] == local_user()) {
124 if ($ret['success']) {
125 $photo_albums_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('photo_albums.tpl'), [
126 '$nick' => $a->data['user']['nickname'],
127 '$title' => DI::l10n()->t('Photo Albums'),
128 '$recent' => DI::l10n()->t('Recent Photos'),
129 '$albums' => $ret['albums'],
130 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'],
131 '$can_post' => $can_post
135 if (empty(DI::page()['aside'])) {
136 DI::page()['aside'] = '';
139 DI::page()['aside'] .= $vcard_widget;
141 if (!empty($photo_albums_widget)) {
142 DI::page()['aside'] .= $photo_albums_widget;
145 $tpl = Renderer::getMarkupTemplate("photos_head.tpl");
147 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
148 '$ispublic' => DI::l10n()->t('everybody')
155 function photos_post(App $a)
157 Logger::log('mod-photos: photos_post: begin' , Logger::DEBUG);
158 Logger::log('mod_photos: REQUEST ' . print_r($_REQUEST, true), Logger::DATA);
159 Logger::log('mod_photos: FILES ' . print_r($_FILES, true), Logger::DATA);
161 $phototypes = Images::supportedTypes();
166 $page_owner_uid = intval($a->data['user']['uid']);
167 $community_page = $a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
169 if (local_user() && (local_user() == $page_owner_uid)) {
171 } elseif ($community_page && !empty(Session::getRemoteContactID($page_owner_uid))) {
172 $contact_id = Session::getRemoteContactID($page_owner_uid);
174 $visitor = $contact_id;
178 notice(DI::l10n()->t('Permission denied.') . EOL);
182 $owner_record = User::getOwnerDataById($page_owner_uid);
184 if (!$owner_record) {
185 notice(DI::l10n()->t('Contact information unavailable') . EOL);
186 Logger::log('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
190 if ($a->argc > 3 && $a->argv[2] === 'album') {
191 if (!Strings::isHex($a->argv[3])) {
192 DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname'] . '/album');
194 $album = hex2bin($a->argv[3]);
196 if ($album === DI::l10n()->t('Profile Photos') || $album === 'Contact Photos' || $album === DI::l10n()->t('Contact Photos')) {
197 DI::baseUrl()->redirect($_SESSION['photo_return']);
198 return; // NOTREACHED
201 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
203 intval($page_owner_uid)
206 if (!DBA::isResult($r)) {
207 notice(DI::l10n()->t('Album not found.') . EOL);
208 DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname'] . '/album');
209 return; // NOTREACHED
212 // Check if the user has responded to a delete confirmation query
213 if (!empty($_REQUEST['canceled'])) {
214 DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname'] . '/album/' . $a->argv[3]);
217 // RENAME photo album
218 $newalbum = Strings::escapeTags(trim($_POST['albumname']));
219 if ($newalbum != $album) {
220 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
221 DBA::escape($newalbum),
223 intval($page_owner_uid)
225 // Update the photo albums cache
226 Photo::clearAlbumCache($page_owner_uid);
228 DI::baseUrl()->redirect('photos/' . $a->user['nickname'] . '/album/' . bin2hex($newalbum));
229 return; // NOTREACHED
233 * DELETE all photos filed in a given album
235 if (!empty($_POST['dropalbum'])) {
238 // get the list of photos we are about to delete
240 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
242 intval($page_owner_uid),
246 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
247 intval(local_user()),
252 if (DBA::isResult($r)) {
253 foreach ($r as $rr) {
257 // remove the associated photos
258 Photo::delete(['resource-id' => $res, 'uid' => $page_owner_uid]);
260 // find and delete the corresponding item with all the comments and likes/dislikes
261 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
263 // Update the photo albums cache
264 Photo::clearAlbumCache($page_owner_uid);
265 notice(DI::l10n()->t('Album successfully deleted'));
267 notice(DI::l10n()->t('Album was empty.'));
271 DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname'] . '/album');
274 if ($a->argc > 3 && $a->argv[2] === 'image') {
275 // Check if the user has responded to a delete confirmation query for a single photo
276 if (!empty($_POST['canceled'])) {
277 DI::baseUrl()->redirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]);
280 if (!empty($_POST['delete'])) {
281 // same as above but remove single photo
283 $condition = ['contact-id' => $visitor, 'uid' => $page_owner_uid, 'resource-id' => $a->argv[3]];
286 $condition = ['uid' => local_user(), 'resource-id' => $a->argv[3]];
289 $photo = DBA::selectFirst('photo', ['resource-id'], $condition);
291 if (DBA::isResult($photo)) {
292 Photo::delete(['uid' => $page_owner_uid, 'resource-id' => $photo['resource-id']]);
294 Item::deleteForUser(['resource-id' => $photo['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
296 // Update the photo albums cache
297 Photo::clearAlbumCache($page_owner_uid);
298 notice('Successfully deleted the photo.');
300 notice('Failed to delete the photo.');
301 DI::baseUrl()->redirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]);
304 DI::baseUrl()->redirect('photos/' . $a->argv[1]);
305 return; // NOTREACHED
309 if ($a->argc > 2 && (!empty($_POST['desc']) || !empty($_POST['newtag']) || isset($_POST['albname']))) {
310 $desc = !empty($_POST['desc']) ? Strings::escapeTags(trim($_POST['desc'])) : '';
311 $rawtags = !empty($_POST['newtag']) ? Strings::escapeTags(trim($_POST['newtag'])) : '';
312 $item_id = !empty($_POST['item_id']) ? intval($_POST['item_id']) : 0;
313 $albname = !empty($_POST['albname']) ? trim($_POST['albname']) : '';
314 $origaname = !empty($_POST['origaname']) ? Strings::escapeTags(trim($_POST['origaname'])) : '';
316 $aclFormatter = DI::aclFormatter();
318 $str_group_allow = !empty($_POST['group_allow']) ? $aclFormatter->toString($_POST['group_allow']) : '';
319 $str_contact_allow = !empty($_POST['contact_allow']) ? $aclFormatter->toString($_POST['contact_allow']) : '';
320 $str_group_deny = !empty($_POST['group_deny']) ? $aclFormatter->toString($_POST['group_deny']) : '';
321 $str_contact_deny = !empty($_POST['contact_deny']) ? $aclFormatter->toString($_POST['contact_deny']) : '';
323 $resource_id = $a->argv[3];
325 if (!strlen($albname)) {
326 $albname = DateTimeFormat::localNow('Y');
329 if (!empty($_POST['rotate']) && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
330 Logger::log('rotate');
332 $photo = Photo::getPhotoForUser($page_owner_uid, $resource_id);
334 if (DBA::isResult($photo)) {
335 $image = Photo::getImageForPhoto($photo);
337 if ($image->isValid()) {
338 $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
339 $image->rotate($rotate_deg);
341 $width = $image->getWidth();
342 $height = $image->getHeight();
344 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 0], $image);
346 if ($width > 640 || $height > 640) {
347 $image->scaleDown(640);
348 $width = $image->getWidth();
349 $height = $image->getHeight();
351 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 1], $image);
354 if ($width > 320 || $height > 320) {
355 $image->scaleDown(320);
356 $width = $image->getWidth();
357 $height = $image->getHeight();
359 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 2], $image);
365 $photos_stmt = DBA::select('photo', [], ['resource-id' => $resource_id, 'uid' => $page_owner_uid], ['order' => ['scale' => true]]);
367 $photos = DBA::toArray($photos_stmt);
369 if (DBA::isResult($photos)) {
371 $ext = $phototypes[$photo['type']];
373 ['desc' => $desc, 'album' => $albname, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow, 'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny],
374 ['resource-id' => $resource_id, 'uid' => $page_owner_uid]
377 // Update the photo albums cache if album name was changed
378 if ($albname !== $origaname) {
379 Photo::clearAlbumCache($page_owner_uid);
381 /* Don't make the item visible if the only change was the album name */
384 if ($photo['desc'] !== $desc || strlen($rawtags)) {
389 if (DBA::isResult($photos) && !$item_id) {
390 // Create item container
392 $uri = Item::newURI($page_owner_uid);
395 $arr['guid'] = System::createUUID();
396 $arr['uid'] = $page_owner_uid;
398 $arr['parent-uri'] = $uri;
399 $arr['post-type'] = Item::PT_IMAGE;
401 $arr['resource-id'] = $photo['resource-id'];
402 $arr['contact-id'] = $owner_record['id'];
403 $arr['owner-name'] = $owner_record['name'];
404 $arr['owner-link'] = $owner_record['url'];
405 $arr['owner-avatar'] = $owner_record['thumb'];
406 $arr['author-name'] = $owner_record['name'];
407 $arr['author-link'] = $owner_record['url'];
408 $arr['author-avatar'] = $owner_record['thumb'];
409 $arr['title'] = $title;
410 $arr['allow_cid'] = $photo['allow_cid'];
411 $arr['allow_gid'] = $photo['allow_gid'];
412 $arr['deny_cid'] = $photo['deny_cid'];
413 $arr['deny_gid'] = $photo['deny_gid'];
414 $arr['visible'] = $visibility;
417 $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $photo['resource-id'] . ']'
418 . '[img]' . DI::baseUrl() . '/photo/' . $photo['resource-id'] . '-' . $photo['scale'] . '.'. $ext . '[/img]'
421 $item_id = Item::insert($arr);
425 $item = Item::selectFirst(['tag', 'inform', 'uri-id'], ['id' => $item_id, 'uid' => $page_owner_uid]);
427 if (DBA::isResult($item)) {
428 $old_tag = $item['tag'];
429 $old_inform = $item['inform'];
433 if (strlen($rawtags)) {
437 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
438 $x = substr($rawtags, 0, 1);
439 if ($x !== '@' && $x !== '#') {
440 $rawtags = '#' . $rawtags;
444 $tags = BBCode::getTags($rawtags);
447 foreach ($tags as $tag) {
448 if (strpos($tag, '@') === 0) {
451 $name = substr($tag,1);
453 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
455 $links = @Probe::lrdd($name);
458 foreach ($links as $link) {
459 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
460 $profile = $link['@attributes']['href'];
463 if ($link['@attributes']['rel'] === 'salmon') {
464 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
466 if (strlen($inform)) {
475 $taginfo[] = [$newname, $profile, $salmon];
480 if (strrpos($newname, '+')) {
481 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
485 $contact = DBA::selectFirst('contact', [], ['id' => $tagcid, 'uid' => $page_owner_uid]);
487 $newname = str_replace('_',' ',$name);
489 //select someone from this user's contacts by name
490 $contact = DBA::selectFirst('contact', [], ['name' => $newname, 'uid' => $page_owner_uid]);
491 if (!DBA::isResult($contact)) {
492 //select someone by attag or nick and the name passed in
493 $contact = DBA::selectFirst('contact', [],
494 ['(`attag` = ? OR `nick` = ?) AND `uid` = ?', $name, $name, $page_owner_uid],
495 ['order' => ['attag' => true]]
500 if (DBA::isResult($contact)) {
501 $newname = $contact['name'];
502 $profile = $contact['url'];
504 $notify = 'cid:' . $contact['id'];
505 if (strlen($inform)) {
513 if (!empty($contact)) {
514 $taginfo[] = [$newname, $profile, $notify, $contact, '@[url=' . str_replace(',', '%2c', $profile) . ']' . $newname . '[/url]'];
516 $taginfo[] = [$newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'];
519 if (strlen($str_tags)) {
523 $profile = str_replace(',', '%2c', $profile);
524 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
526 if (!empty($item['uri-id'])) {
527 Tag::store($item['uri-id'], Tag::MENTION, $newname, $profile);
530 } elseif (strpos($tag, '#') === 0) {
531 $tagname = substr($tag, 1);
532 $str_tags .= '#[url=' . DI::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url],';
533 if (!empty($item['uri-id'])) {
534 Tag::store($item['uri-id'], Tag::HASHTAG, $tagname);
540 $newtag = $old_tag ?? '';
541 if (strlen($newtag) && strlen($str_tags)) {
544 $newtag .= $str_tags;
546 $newinform = $old_inform ?? '';
547 if (strlen($newinform) && strlen($inform)) {
550 $newinform .= $inform;
552 $fields = ['tag' => $newtag, 'inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
553 $condition = ['id' => $item_id];
554 Item::update($fields, $condition);
557 foreach ($photos as $scales) {
558 if (intval($scales['scale']) == 2) {
563 if (intval($scales['scale']) == 4) {
569 if (count($taginfo)) {
570 foreach ($taginfo as $tagged) {
571 $uri = Item::newURI($page_owner_uid);
574 $arr['guid'] = System::createUUID();
575 $arr['uid'] = $page_owner_uid;
577 $arr['parent-uri'] = $uri;
579 $arr['contact-id'] = $owner_record['id'];
580 $arr['owner-name'] = $owner_record['name'];
581 $arr['owner-link'] = $owner_record['url'];
582 $arr['owner-avatar'] = $owner_record['thumb'];
583 $arr['author-name'] = $owner_record['name'];
584 $arr['author-link'] = $owner_record['url'];
585 $arr['author-avatar'] = $owner_record['thumb'];
587 $arr['allow_cid'] = $photo['allow_cid'];
588 $arr['allow_gid'] = $photo['allow_gid'];
589 $arr['deny_cid'] = $photo['deny_cid'];
590 $arr['deny_gid'] = $photo['deny_gid'];
592 $arr['verb'] = Activity::TAG;
593 $arr['gravity'] = GRAVITY_PARENT;
594 $arr['object-type'] = Activity\ObjectType::PERSON;
595 $arr['target-type'] = Activity\ObjectType::IMAGE;
596 $arr['tag'] = $tagged[4];
597 $arr['inform'] = $tagged[2];
599 $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]') ;
600 $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" ;
602 $arr['object'] = '<object><type>' . Activity\ObjectType::PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
603 $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
605 $arr['object'] .= XML::escape('<link rel="photo" type="' . $photo['type'] . '" href="' . $tagged[3]['photo'] . '" />' . "\n");
607 $arr['object'] .= '</link></object>' . "\n";
609 $arr['target'] = '<target><type>' . Activity\ObjectType::IMAGE . '</type><title>' . $photo['desc'] . '</title><id>'
610 . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '</id>';
611 $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>';
617 DI::baseUrl()->redirect($_SESSION['photo_return']);
618 return; // NOTREACHED
622 // default post action - upload a photo
623 Hook::callAll('photo_post_init', $_POST);
625 // Determine the album to use
626 $album = trim($_REQUEST['album'] ?? '');
627 $newalbum = trim($_REQUEST['newalbum'] ?? '');
629 Logger::info('album= ' . $album . ' newalbum= ' . $newalbum);
631 if (!strlen($album)) {
632 if (strlen($newalbum)) {
635 $album = DateTimeFormat::localNow('Y');
640 * We create a wall item for every photo, but we don't want to
641 * overwhelm the data stream with a hundred newly uploaded photos.
642 * So we will make the first photo uploaded to this album in the last several hours
643 * visible by default, the rest will become visible over time when and if
644 * they acquire comments, likes, dislikes, and/or tags
647 $r = Photo::selectToArray([], ['`album` = ? AND `uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR', $album, $page_owner_uid]);
649 if (!DBA::isResult($r) || ($album == DI::l10n()->t('Profile Photos'))) {
655 if (!empty($_REQUEST['not_visible']) && $_REQUEST['not_visible'] !== 'false') {
659 $group_allow = $_REQUEST['group_allow'] ?? [];
660 $contact_allow = $_REQUEST['contact_allow'] ?? [];
661 $group_deny = $_REQUEST['group_deny'] ?? [];
662 $contact_deny = $_REQUEST['contact_deny'] ?? [];
664 $aclFormatter = DI::aclFormatter();
666 $str_group_allow = $aclFormatter->toString(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
667 $str_contact_allow = $aclFormatter->toString(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
668 $str_group_deny = $aclFormatter->toString(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
669 $str_contact_deny = $aclFormatter->toString(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
671 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
673 Hook::callAll('photo_post_file', $ret);
675 if (!empty($ret['src']) && !empty($ret['filesize'])) {
677 $filename = $ret['filename'];
678 $filesize = $ret['filesize'];
679 $type = $ret['type'];
680 $error = UPLOAD_ERR_OK;
681 } elseif (!empty($_FILES['userfile'])) {
682 $src = $_FILES['userfile']['tmp_name'];
683 $filename = basename($_FILES['userfile']['name']);
684 $filesize = intval($_FILES['userfile']['size']);
685 $type = $_FILES['userfile']['type'];
686 $error = $_FILES['userfile']['error'];
688 $error = UPLOAD_ERR_NO_FILE;
691 if ($error !== UPLOAD_ERR_OK) {
693 case UPLOAD_ERR_INI_SIZE:
694 notice(DI::l10n()->t('Image exceeds size limit of %s', ini_get('upload_max_filesize')) . EOL);
696 case UPLOAD_ERR_FORM_SIZE:
697 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($_REQUEST['MAX_FILE_SIZE'] ?? 0)) . EOL);
699 case UPLOAD_ERR_PARTIAL:
700 notice(DI::l10n()->t('Image upload didn\'t complete, please try again') . EOL);
702 case UPLOAD_ERR_NO_FILE:
703 notice(DI::l10n()->t('Image file is missing') . EOL);
705 case UPLOAD_ERR_NO_TMP_DIR:
706 case UPLOAD_ERR_CANT_WRITE:
707 case UPLOAD_ERR_EXTENSION:
708 notice(DI::l10n()->t('Server can\'t accept new file upload at this time, please contact your administrator') . EOL);
713 Hook::callAll('photo_post_end', $foo);
717 $type = Images::getMimeTypeBySource($src, $filename, $type);
719 Logger::log('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', Logger::DEBUG);
721 $maximagesize = DI::config()->get('system', 'maximagesize');
723 if ($maximagesize && ($filesize > $maximagesize)) {
724 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)) . EOL);
727 Hook::callAll('photo_post_end', $foo);
732 notice(DI::l10n()->t('Image file is empty.') . EOL);
735 Hook::callAll('photo_post_end', $foo);
739 Logger::log('mod/photos.php: photos_post(): loading the contents of ' . $src , Logger::DEBUG);
741 $imagedata = @file_get_contents($src);
743 $image = new Image($imagedata, $type);
745 if (!$image->isValid()) {
746 Logger::log('mod/photos.php: photos_post(): unable to process image' , Logger::DEBUG);
747 notice(DI::l10n()->t('Unable to process image.') . EOL);
750 Hook::callAll('photo_post_end',$foo);
754 $exif = $image->orient($src);
757 $max_length = DI::config()->get('system', 'max_image_length');
759 $max_length = MAX_IMAGE_LENGTH;
761 if ($max_length > 0) {
762 $image->scaleDown($max_length);
765 $width = $image->getWidth();
766 $height = $image->getHeight();
770 $resource_id = Photo::newResource();
772 $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);
775 Logger::log('mod/photos.php: photos_post(): image store failed', Logger::DEBUG);
776 notice(DI::l10n()->t('Image upload failed.') . EOL);
780 if ($width > 640 || $height > 640) {
781 $image->scaleDown(640);
782 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);
786 if ($width > 320 || $height > 320) {
787 $image->scaleDown(320);
788 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);
792 $uri = Item::newURI($page_owner_uid);
794 // Create item container
796 if ($exif && $exif['GPS'] && Feature::isEnabled($page_owner_uid, 'photo_location')) {
797 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
798 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
803 $arr['coord'] = $lat . ' ' . $lon;
806 $arr['guid'] = System::createUUID();
807 $arr['uid'] = $page_owner_uid;
809 $arr['parent-uri'] = $uri;
810 $arr['type'] = 'photo';
812 $arr['resource-id'] = $resource_id;
813 $arr['contact-id'] = $owner_record['id'];
814 $arr['owner-name'] = $owner_record['name'];
815 $arr['owner-link'] = $owner_record['url'];
816 $arr['owner-avatar'] = $owner_record['thumb'];
817 $arr['author-name'] = $owner_record['name'];
818 $arr['author-link'] = $owner_record['url'];
819 $arr['author-avatar'] = $owner_record['thumb'];
821 $arr['allow_cid'] = $str_contact_allow;
822 $arr['allow_gid'] = $str_group_allow;
823 $arr['deny_cid'] = $str_contact_deny;
824 $arr['deny_gid'] = $str_group_deny;
825 $arr['visible'] = $visible;
828 $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $resource_id . ']'
829 . '[img]' . DI::baseUrl() . "/photo/{$resource_id}-{$smallest}.".$image->getExt() . '[/img]'
832 $item_id = Item::insert($arr);
833 // Update the photo albums cache
834 Photo::clearAlbumCache($page_owner_uid);
836 Hook::callAll('photo_post_end', $item_id);
838 // addon uploaders should call "exit()" within the photo_post_end hook
839 // if they do not wish to be redirected
841 DI::baseUrl()->redirect($_SESSION['photo_return']);
845 function photos_content(App $a)
849 // photos/name/upload
850 // photos/name/upload/xxxxx (xxxxx is album name)
851 // photos/name/album/xxxxx
852 // photos/name/album/xxxxx/edit
853 // photos/name/album/xxxxx/drop
854 // photos/name/image/xxxxx
855 // photos/name/image/xxxxx/edit
856 // photos/name/image/xxxxx/drop
858 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
859 notice(DI::l10n()->t('Public access denied.') . EOL);
863 if (empty($a->data['user'])) {
864 notice(DI::l10n()->t('No photos selected') . EOL);
868 $phototypes = Images::supportedTypes();
870 $_SESSION['photo_return'] = DI::args()->getCommand();
875 $datatype = $a->argv[2];
876 $datum = $a->argv[3];
877 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
878 $datatype = 'upload';
880 $datatype = 'summary';
889 // Setup permissions structures
893 $remote_contact = false;
898 $owner_uid = $a->data['user']['uid'];
900 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
902 if (local_user() && (local_user() == $owner_uid)) {
904 } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
905 $contact_id = Session::getRemoteContactID($owner_uid);
906 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
908 if (DBA::isResult($contact)) {
910 $remote_contact = true;
911 $visitor = $contact_id;
915 // perhaps they're visiting - but not a community page, so they wouldn't have write access
916 if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
917 $contact_id = Session::getRemoteContactID($owner_uid);
919 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
921 $remote_contact = DBA::isResult($contact);
924 if (!$remote_contact && local_user()) {
925 $contact_id = $_SESSION['cid'];
926 $contact = $a->contact;
929 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
930 notice(DI::l10n()->t('Access to this item is restricted.') . EOL);
934 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
939 $is_owner = (local_user() && (local_user() == $owner_uid));
940 $o .= BaseProfile::getTabsHTML($a, 'photos', $is_owner, $a->data['user']['nickname']);
942 // Display upload form
943 if ($datatype === 'upload') {
945 notice(DI::l10n()->t('Permission denied.'));
949 $selname = Strings::isHex($datum) ? hex2bin($datum) : '';
953 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '><current year></option>';
954 if (!empty($a->data['albums'])) {
955 foreach ($a->data['albums'] as $album) {
956 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === DI::l10n()->t('Contact Photos'))) {
959 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
960 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
966 $ret = ['post_url' => 'photos/' . $a->data['user']['nickname'],
967 'addon_text' => $uploader,
968 'default_upload' => true];
970 Hook::callAll('photo_upload_form',$ret);
972 $default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
973 $default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
974 '$submit' => DI::l10n()->t('Submit'),
979 $tpl = Renderer::getMarkupTemplate('photos_upload.tpl');
981 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML(DI::page(), $a->user));
983 $o .= Renderer::replaceMacros($tpl,[
984 '$pagename' => DI::l10n()->t('Upload Photos'),
985 '$sessid' => session_id(),
986 '$usage' => $usage_message,
987 '$nickname' => $a->data['user']['nickname'],
988 '$newalbum' => DI::l10n()->t('New album name: '),
989 '$existalbumtext' => DI::l10n()->t('or select existing album:'),
990 '$nosharetext' => DI::l10n()->t('Do not show a status post for this upload'),
991 '$albumselect' => $albumselect,
992 '$permissions' => DI::l10n()->t('Permissions'),
993 '$aclselect' => $aclselect_e,
994 '$lockstate' => is_array($a->user)
995 && (strlen($a->user['allow_cid'])
996 || strlen($a->user['allow_gid'])
997 || strlen($a->user['deny_cid'])
998 || strlen($a->user['deny_gid'])
999 ) ? 'lock' : 'unlock',
1000 '$alt_uploader' => $ret['addon_text'],
1001 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
1002 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
1003 '$uploadurl' => $ret['post_url'],
1005 // ACL permissions box
1006 '$group_perms' => DI::l10n()->t('Show to Groups'),
1007 '$contact_perms' => DI::l10n()->t('Show to Contacts'),
1008 '$return_path' => DI::args()->getQueryString(),
1014 // Display a single photo album
1015 if ($datatype === 'album') {
1016 // if $datum is not a valid hex, redirect to the default page
1017 if (!Strings::isHex($datum)) {
1018 DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname']. '/album');
1020 $album = hex2bin($datum);
1023 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1024 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1028 if (DBA::isResult($r)) {
1032 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
1034 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1035 $order_field = $_GET['order'] ?? '';
1036 if ($order_field === 'posted') {
1042 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1043 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1044 ANY_VALUE(`created`) as `created`
1045 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1046 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1048 DBA::escape($album),
1050 $pager->getItemsPerPage()
1053 if ($cmd === 'drop') {
1054 $drop_url = DI::args()->getQueryString();
1056 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1057 '$method' => 'post',
1058 '$message' => DI::l10n()->t('Do you really want to delete this photo album and all its photos?'),
1059 '$extra_inputs' => [],
1060 '$confirm' => DI::l10n()->t('Delete Album'),
1061 '$confirm_url' => $drop_url,
1062 '$confirm_name' => 'dropalbum',
1063 '$cancel' => DI::l10n()->t('Cancel'),
1068 if ($cmd === 'edit') {
1069 if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== DI::l10n()->t('Contact Photos'))) {
1071 $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
1075 $o .= Renderer::replaceMacros($edit_tpl,[
1076 '$nametext' => DI::l10n()->t('New album name: '),
1077 '$nickname' => $a->data['user']['nickname'],
1078 '$album' => $album_e,
1079 '$hexalbum' => bin2hex($album),
1080 '$submit' => DI::l10n()->t('Submit'),
1081 '$dropsubmit' => DI::l10n()->t('Delete Album')
1086 if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== DI::l10n()->t('Contact Photos')) && $can_post) {
1087 $edit = [DI::l10n()->t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1088 $drop = [DI::l10n()->t('Drop Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/drop'];
1092 if ($order_field === 'posted') {
1093 $order = [DI::l10n()->t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1095 $order = [DI::l10n()->t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?order=posted', 'newest'];
1100 if (DBA::isResult($r)) {
1101 // "Twist" is only used for the duepunto theme with style "slackr"
1103 foreach ($r as $rr) {
1106 $ext = $phototypes[$rr['type']];
1108 $imgalt_e = $rr['filename'];
1109 $desc_e = $rr['desc'];
1113 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1114 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1115 . ($order_field === 'posted' ? '?order=posted' : ''),
1116 'title' => DI::l10n()->t('View Photo'),
1117 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1121 'hash'=> $rr['resource-id'],
1126 $tpl = Renderer::getMarkupTemplate('photo_album.tpl');
1127 $o .= Renderer::replaceMacros($tpl, [
1128 '$photos' => $photos,
1130 '$can_post' => $can_post,
1131 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)],
1135 '$paginate' => $pager->renderFull($total),
1142 // Display one photo
1143 if ($datatype === 'image') {
1144 // fetch image, item containing image, then comments
1145 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1146 $sql_extra ORDER BY `scale` ASC ",
1151 if (!DBA::isResult($ph)) {
1152 if (DBA::exists('photo', ['resource-id' => $datum, 'uid' => $owner_uid])) {
1153 notice(DI::l10n()->t('Permission denied. Access to this item may be restricted.'));
1155 notice(DI::l10n()->t('Photo not available') . EOL);
1160 if ($cmd === 'drop') {
1161 $drop_url = DI::args()->getQueryString();
1163 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1164 '$method' => 'post',
1165 '$message' => DI::l10n()->t('Do you really want to delete this photo?'),
1166 '$extra_inputs' => [],
1167 '$confirm' => DI::l10n()->t('Delete Photo'),
1168 '$confirm_url' => $drop_url,
1169 '$confirm_name' => 'delete',
1170 '$cancel' => DI::l10n()->t('Cancel'),
1178 * @todo This query is totally bad, the whole functionality has to be changed
1179 * The query leads to a really intense used index.
1180 * By now we hide it if someone wants to.
1182 if ($cmd === 'view' && !DI::config()->get('system', 'no_count', false)) {
1183 $order_field = $_GET['order'] ?? '';
1185 if ($order_field === 'posted') {
1191 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1192 $sql_extra ORDER BY `created` $order ",
1193 DBA::escape($ph[0]['album']),
1197 if (DBA::isResult($prvnxt)) {
1200 foreach ($prvnxt as $z => $entry) {
1201 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1205 $prv = count($prvnxt) - 1;
1207 if ($nxt >= count($prvnxt)) {
1214 if (!is_null($prv)) {
1215 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1217 if (!is_null($nxt)) {
1218 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1221 $tpl = Renderer::getMarkupTemplate('photo_edit_head.tpl');
1222 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
1223 '$prevlink' => $prevlink,
1224 '$nextlink' => $nextlink
1228 $prevlink = [$prevlink, '<div class="icon prev"></div>'];
1232 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1237 if (count($ph) == 1) {
1238 $hires = $lores = $ph[0];
1241 if (count($ph) > 1) {
1242 if ($ph[1]['scale'] == 2) {
1243 // original is 640 or less, we can display it directly
1244 $hires = $lores = $ph[0];
1251 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1255 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1257 if ($cmd === 'edit') {
1258 $tools['view'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum, DI::l10n()->t('View photo')];
1260 $tools['edit'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/edit', DI::l10n()->t('Edit photo')];
1261 $tools['delete'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/drop', DI::l10n()->t('Delete photo')];
1262 $tools['profile'] = ['settings/profile/photo/crop/' . $ph[0]['resource-id'], DI::l10n()->t('Use as profile photo')];
1266 $ph[0]['uid'] == local_user()
1267 && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']))
1269 $tools['lock'] = DI::l10n()->t('Private Photo');
1274 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1275 'title'=> DI::l10n()->t('View Full Size'),
1276 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?_u=' . DateTimeFormat::utcNow('ymdhis'),
1277 'height' => $hires['height'],
1278 'width' => $hires['width'],
1279 'album' => $hires['album'],
1280 'filename' => $hires['filename'],
1287 // Do we have an item for this photo?
1289 // FIXME! - replace following code to display the conversation with our normal
1290 // conversation functions so that it works correctly and tracks changes
1291 // in the evolving conversation code.
1292 // The difference is that we won't be displaying the conversation head item
1293 // as a "post" but displaying instead the photo it is linked to
1295 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1296 $linked_items = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1299 if (DBA::isResult($linked_items)) {
1300 // This is a workaround to not being forced to rewrite the while $sql_extra handling
1301 $link_item = Item::selectFirst([], ['id' => $linked_items[0]['id']]);
1304 if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
1305 $condition = ["`parent` = ? AND `parent` != `id`", $link_item['parent']];
1306 $total = DBA::count('item', $condition);
1308 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
1310 $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1311 $result = Item::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params);
1312 $items = Item::inArray($result);
1314 if (local_user() == $link_item['uid']) {
1315 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1319 if (!empty($link_item['coord'])) {
1320 $map = Map::byCoordinates($link_item['coord']);
1325 if (!empty($link_item['id']) && !empty($link_item['tag'])) {
1326 $arr = explode(',', $link_item['tag']);
1327 // parse tags and add links
1329 foreach ($arr as $tag) {
1331 'name' => BBCode::convert($tag),
1332 'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag)
1335 $tags = ['title' => DI::l10n()->t('Tags: '), 'tags' => $tag_arr];
1336 if ($cmd === 'edit') {
1337 $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
1338 $tags['removetitle'] = DI::l10n()->t('[Select tags to remove]');
1344 if ($cmd === 'edit' && $can_post) {
1345 $edit_tpl = Renderer::getMarkupTemplate('photo_edit.tpl');
1347 $album_e = $ph[0]['album'];
1348 $caption_e = $ph[0]['desc'];
1349 $aclselect_e = ACL::getFullSelectorHTML(DI::page(), $a->user, false, ACL::getDefaultUserPermissions($ph[0]));
1351 $edit = Renderer::replaceMacros($edit_tpl, [
1352 '$id' => $ph[0]['id'],
1353 '$album' => ['albname', DI::l10n()->t('New album name'), $album_e,''],
1354 '$caption' => ['desc', DI::l10n()->t('Caption'), $caption_e, ''],
1355 '$tags' => ['newtag', DI::l10n()->t('Add a Tag'), "", DI::l10n()->t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1356 '$rotate_none' => ['rotate', DI::l10n()->t('Do not rotate'),0,'', true],
1357 '$rotate_cw' => ['rotate', DI::l10n()->t("Rotate CW \x28right\x29"),1,''],
1358 '$rotate_ccw' => ['rotate', DI::l10n()->t("Rotate CCW \x28left\x29"),2,''],
1360 '$nickname' => $a->data['user']['nickname'],
1361 '$resource_id' => $ph[0]['resource-id'],
1362 '$permissions' => DI::l10n()->t('Permissions'),
1363 '$aclselect' => $aclselect_e,
1365 '$item_id' => $link_item['id'] ?? 0,
1366 '$submit' => DI::l10n()->t('Submit'),
1367 '$delete' => DI::l10n()->t('Delete Photo'),
1369 // ACL permissions box
1370 '$group_perms' => DI::l10n()->t('Show to Groups'),
1371 '$contact_perms' => DI::l10n()->t('Show to Contacts'),
1372 '$return_path' => DI::args()->getQueryString(),
1382 if (!empty($link_item['id']) && !empty($link_item['uri'])) {
1383 $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
1384 $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
1385 $return_path = DI::args()->getCommand();
1387 if ($cmd === 'view' && ($can_post || Security::canWriteToUserWall($owner_uid))) {
1388 $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl');
1389 $likebuttons = Renderer::replaceMacros($like_tpl, [
1390 '$id' => $link_item['id'],
1391 '$likethis' => DI::l10n()->t("I like this \x28toggle\x29"),
1392 '$dislike' => DI::pConfig()->get(local_user(), 'system', 'hide_dislike') ? '' : DI::l10n()->t("I don't like this \x28toggle\x29"),
1393 '$wait' => DI::l10n()->t('Please wait'),
1394 '$return_path' => DI::args()->getQueryString(),
1398 if (!DBA::isResult($items)) {
1399 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1400 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1401 '$return_path' => '',
1402 '$jsreload' => $return_path,
1403 '$id' => $link_item['id'],
1404 '$parent' => $link_item['id'],
1405 '$profile_uid' => $owner_uid,
1406 '$mylink' => $contact['url'],
1407 '$mytitle' => DI::l10n()->t('This is you'),
1408 '$myphoto' => $contact['thumb'],
1409 '$comment' => DI::l10n()->t('Comment'),
1410 '$submit' => DI::l10n()->t('Submit'),
1411 '$preview' => DI::l10n()->t('Preview'),
1412 '$loading' => DI::l10n()->t('Loading...'),
1413 '$sourceapp' => DI::l10n()->t($a->sourcename),
1415 '$rand_num' => Crypto::randomDigits(12)
1428 if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
1429 unset($conv_responses['dislike']);
1433 if (DBA::isResult($items)) {
1434 foreach ($items as $item) {
1435 builtin_activity_puller($item, $conv_responses);
1438 if (!empty($conv_responses['like'][$link_item['uri']])) {
1439 $like = format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like', $link_item['id']);
1442 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1443 $dislike = format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike', $link_item['id']);
1446 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1447 $comments .= Renderer::replaceMacros($cmnt_tpl,[
1448 '$return_path' => '',
1449 '$jsreload' => $return_path,
1450 '$id' => $link_item['id'],
1451 '$parent' => $link_item['id'],
1452 '$profile_uid' => $owner_uid,
1453 '$mylink' => $contact['url'],
1454 '$mytitle' => DI::l10n()->t('This is you'),
1455 '$myphoto' => $contact['thumb'],
1456 '$comment' => DI::l10n()->t('Comment'),
1457 '$submit' => DI::l10n()->t('Submit'),
1458 '$preview' => DI::l10n()->t('Preview'),
1459 '$sourceapp' => DI::l10n()->t($a->sourcename),
1461 '$rand_num' => Crypto::randomDigits(12)
1465 foreach ($items as $item) {
1469 $activity = DI::activity();
1471 if (($activity->match($item['verb'], Activity::LIKE) ||
1472 $activity->match($item['verb'], Activity::DISLIKE)) &&
1473 ($item['id'] != $item['parent'])) {
1477 $profile_url = Contact::magicLinkbyId($item['author-id']);
1478 if (strpos($profile_url, 'redir/') === 0) {
1479 $sparkle = ' sparkle';
1484 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1486 'dropping' => $dropping,
1487 'pagedrop' => false,
1488 'select' => DI::l10n()->t('Select'),
1489 'delete' => DI::l10n()->t('Delete'),
1492 $title_e = $item['title'];
1493 $body_e = BBCode::convert($item['body']);
1495 $comments .= Renderer::replaceMacros($template,[
1496 '$id' => $item['id'],
1497 '$profile_url' => $profile_url,
1498 '$name' => $item['author-name'],
1499 '$thumb' => $item['author-avatar'],
1500 '$sparkle' => $sparkle,
1501 '$title' => $title_e,
1503 '$ago' => Temporal::getRelativeDate($item['created']),
1504 '$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''),
1506 '$comment' => $comment
1509 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1510 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1511 '$return_path' => '',
1512 '$jsreload' => $return_path,
1513 '$id' => $item['id'],
1514 '$parent' => $item['parent'],
1515 '$profile_uid' => $owner_uid,
1516 '$mylink' => $contact['url'],
1517 '$mytitle' => DI::l10n()->t('This is you'),
1518 '$myphoto' => $contact['thumb'],
1519 '$comment' => DI::l10n()->t('Comment'),
1520 '$submit' => DI::l10n()->t('Submit'),
1521 '$preview' => DI::l10n()->t('Preview'),
1522 '$sourceapp' => DI::l10n()->t($a->sourcename),
1524 '$rand_num' => Crypto::randomDigits(12)
1530 $paginate = $pager->renderFull($total);
1533 $photo_tpl = Renderer::getMarkupTemplate('photo_view.tpl');
1534 $o .= Renderer::replaceMacros($photo_tpl, [
1535 '$id' => $ph[0]['id'],
1536 '$album' => [$album_link, $ph[0]['album']],
1539 '$prevlink' => $prevlink,
1540 '$nextlink' => $nextlink,
1541 '$desc' => $ph[0]['desc'],
1545 '$map_text' => DI::l10n()->t('Map'),
1546 '$likebuttons' => $likebuttons,
1548 '$dislike' => $dislike,
1549 '$comments' => $comments,
1550 '$paginate' => $paginate,
1553 DI::page()['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
1554 DI::page()['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1555 DI::page()['htmlhead'] .= '<meta name="twitter:image" content="' . DI::baseUrl() . "/" . $photo["href"] . '" />' . "\n";
1556 DI::page()['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1557 DI::page()['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1562 // Default - show recent photos with upload link (if applicable)
1565 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1566 $sql_extra GROUP BY `resource-id`",
1567 intval($a->data['user']['uid']),
1568 DBA::escape('Contact Photos'),
1569 DBA::escape(DI::l10n()->t('Contact Photos'))
1571 if (DBA::isResult($r)) {
1575 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
1577 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1578 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1579 ANY_VALUE(`created`) AS `created` FROM `photo`
1580 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1581 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1582 intval($a->data['user']['uid']),
1583 DBA::escape('Contact Photos'),
1584 DBA::escape(DI::l10n()->t('Contact Photos')),
1586 $pager->getItemsPerPage()
1590 if (DBA::isResult($r)) {
1591 // "Twist" is only used for the duepunto theme with style "slackr"
1593 foreach ($r as $rr) {
1594 //hide profile photos to others
1595 if (!$is_owner && !Session::getRemoteContactID($owner_uid) && ($rr['album'] == DI::l10n()->t('Profile Photos'))) {
1600 $ext = $phototypes[$rr['type']];
1602 $alt_e = $rr['filename'];
1603 $name_e = $rr['album'];
1607 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1608 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1609 'title' => DI::l10n()->t('View Photo'),
1610 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1613 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1615 'alt' => DI::l10n()->t('View Album'),
1622 $tpl = Renderer::getMarkupTemplate('photos_recent.tpl');
1623 $o .= Renderer::replaceMacros($tpl, [
1624 '$title' => DI::l10n()->t('Recent Photos'),
1625 '$can_post' => $can_post,
1626 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'],
1627 '$photos' => $photos,
1628 '$paginate' => $pager->renderFull($total),