3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 use Friendica\Content\Feature;
24 use Friendica\Content\Nav;
25 use Friendica\Content\Pager;
26 use Friendica\Content\Text\BBCode;
27 use Friendica\Content\Widget;
28 use Friendica\Core\ACL;
29 use Friendica\Core\Addon;
30 use Friendica\Core\Hook;
31 use Friendica\Core\Logger;
32 use Friendica\Core\Renderer;
33 use Friendica\Core\Session;
34 use Friendica\Core\System;
35 use Friendica\Database\DBA;
37 use Friendica\Model\Contact;
38 use Friendica\Model\Item;
39 use Friendica\Model\Photo;
40 use Friendica\Model\Post;
41 use Friendica\Model\Profile;
42 use Friendica\Model\Tag;
43 use Friendica\Model\User;
44 use Friendica\Module\BaseProfile;
45 use Friendica\Network\Probe;
46 use Friendica\Object\Image;
47 use Friendica\Protocol\Activity;
48 use Friendica\Util\Crypto;
49 use Friendica\Util\DateTimeFormat;
50 use Friendica\Util\Images;
51 use Friendica\Util\Map;
52 use Friendica\Security\Security;
53 use Friendica\Util\Strings;
54 use Friendica\Util\Temporal;
55 use Friendica\Util\XML;
56 use Friendica\Network\HTTPException;
58 function photos_init(App $a) {
60 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
64 Nav::setSelected('home');
66 if (DI::args()->getArgc() > 1) {
67 $owner = User::getOwnerDataByNick(DI::args()->getArgv()[1]);
68 if (!isset($owner['account_removed']) || $owner['account_removed']) {
69 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
72 $is_owner = (local_user() && (local_user() == $owner['uid']));
74 $albums = Photo::getAlbums($owner['uid']);
76 $albums_visible = ((intval($owner['hidewall']) && !Session::isAuthenticated()) ? false : true);
78 // add various encodings to the array so we can just loop through and pick them out in a template
79 $ret = ['success' => false];
82 if ($albums_visible) {
83 $ret['success'] = true;
87 foreach ($albums as $k => $album) {
89 'text' => $album['album'],
90 'total' => $album['total'],
91 'url' => 'photos/' . $owner['nickname'] . '/album/' . bin2hex($album['album']),
92 'urlencode' => urlencode($album['album']),
93 'bin2hex' => bin2hex($album['album'])
95 $ret['albums'][] = $entry;
99 if (local_user() && $owner['uid'] == local_user()) {
105 if ($ret['success']) {
106 $photo_albums_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('photo_albums.tpl'), [
107 '$nick' => $owner['nickname'],
108 '$title' => DI::l10n()->t('Photo Albums'),
109 '$recent' => DI::l10n()->t('Recent Photos'),
110 '$albums' => $ret['albums'],
111 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $owner['nickname'] . '/upload'],
112 '$can_post' => $can_post
116 if (empty(DI::page()['aside'])) {
117 DI::page()['aside'] = '';
120 DI::page()['aside'] .= Widget\VCard::getHTML($owner);
122 if (!empty($photo_albums_widget)) {
123 DI::page()['aside'] .= $photo_albums_widget;
126 $tpl = Renderer::getMarkupTemplate("photos_head.tpl");
128 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
129 '$ispublic' => DI::l10n()->t('everybody')
136 function photos_post(App $a)
138 $user = User::getByNickname(DI::args()->getArgv()[1]);
139 if (!DBA::isResult($user)) {
140 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
143 $phototypes = Images::supportedTypes();
148 $page_owner_uid = intval($user['uid']);
149 $community_page = $user['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
151 if (local_user() && (local_user() == $page_owner_uid)) {
153 } elseif ($community_page && !empty(Session::getRemoteContactID($page_owner_uid))) {
154 $contact_id = Session::getRemoteContactID($page_owner_uid);
156 $visitor = $contact_id;
160 notice(DI::l10n()->t('Permission denied.'));
164 $owner_record = User::getOwnerDataById($page_owner_uid);
166 if (!$owner_record) {
167 notice(DI::l10n()->t('Contact information unavailable'));
168 DI::logger()->info('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
172 $aclFormatter = DI::aclFormatter();
173 $str_contact_allow = isset($_REQUEST['contact_allow']) ? $aclFormatter->toString($_REQUEST['contact_allow']) : $owner_record['allow_cid'] ?? '';
174 $str_group_allow = isset($_REQUEST['group_allow']) ? $aclFormatter->toString($_REQUEST['group_allow']) : $owner_record['allow_gid'] ?? '';
175 $str_contact_deny = isset($_REQUEST['contact_deny']) ? $aclFormatter->toString($_REQUEST['contact_deny']) : $owner_record['deny_cid'] ?? '';
176 $str_group_deny = isset($_REQUEST['group_deny']) ? $aclFormatter->toString($_REQUEST['group_deny']) : $owner_record['deny_gid'] ?? '';
178 $visibility = $_REQUEST['visibility'] ?? '';
179 if ($visibility === 'public') {
180 // The ACL selector introduced in version 2019.12 sends ACL input data even when the Public visibility is selected
181 $str_contact_allow = $str_group_allow = $str_contact_deny = $str_group_deny = '';
182 } else if ($visibility === 'custom') {
183 // Since we know from the visibility parameter the item should be private, we have to prevent the empty ACL
184 // case that would make it public. So we always append the author's contact id to the allowed contacts.
185 // See https://github.com/friendica/friendica/issues/9672
186 $str_contact_allow .= $aclFormatter->toString(Contact::getPublicIdByUserId($page_owner_uid));
189 if (DI::args()->getArgc() > 3 && DI::args()->getArgv()[2] === 'album') {
190 if (!Strings::isHex(DI::args()->getArgv()[3] ?? '')) {
191 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
193 $album = hex2bin(DI::args()->getArgv()[3]);
195 if (!DBA::exists('photo', ['album' => $album, 'uid' => $page_owner_uid, 'photo-type' => Photo::DEFAULT])) {
196 notice(DI::l10n()->t('Album not found.'));
197 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
198 return; // NOTREACHED
201 // Check if the user has responded to a delete confirmation query
202 if (!empty($_REQUEST['canceled'])) {
203 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album/' . DI::args()->getArgv()[3]);
206 // RENAME photo album
207 $newalbum = trim($_POST['albumname'] ?? '');
208 if ($newalbum != $album) {
209 Photo::update(['album' => $newalbum], ['album' => $album, 'uid' => $page_owner_uid]);
210 // Update the photo albums cache
211 Photo::clearAlbumCache($page_owner_uid);
213 DI::baseUrl()->redirect('photos/' . $a->getLoggedInUserNickname() . '/album/' . bin2hex($newalbum));
214 return; // NOTREACHED
218 * DELETE all photos filed in a given album
220 if (!empty($_POST['dropalbum'])) {
223 // get the list of photos we are about to delete
225 $r = DBA::toArray(DBA::p("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = ? AND `uid` = ? AND `album` = ?",
231 $r = DBA::toArray(DBA::p("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = ? AND `album` = ?",
237 if (DBA::isResult($r)) {
238 foreach ($r as $rr) {
242 // remove the associated photos
243 Photo::delete(['resource-id' => $res, 'uid' => $page_owner_uid]);
245 // find and delete the corresponding item with all the comments and likes/dislikes
246 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
248 // Update the photo albums cache
249 Photo::clearAlbumCache($page_owner_uid);
250 notice(DI::l10n()->t('Album successfully deleted'));
252 notice(DI::l10n()->t('Album was empty.'));
256 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
259 if (DI::args()->getArgc() > 3 && DI::args()->getArgv()[2] === 'image') {
260 // Check if the user has responded to a delete confirmation query for a single photo
261 if (!empty($_POST['canceled'])) {
262 DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1] . '/image/' . DI::args()->getArgv()[3]);
265 if (!empty($_POST['delete'])) {
266 // same as above but remove single photo
268 $condition = ['contact-id' => $visitor, 'uid' => $page_owner_uid, 'resource-id' => DI::args()->getArgv()[3]];
271 $condition = ['uid' => local_user(), 'resource-id' => DI::args()->getArgv()[3]];
274 $photo = DBA::selectFirst('photo', ['resource-id'], $condition);
276 if (DBA::isResult($photo)) {
277 Photo::delete(['uid' => $page_owner_uid, 'resource-id' => $photo['resource-id']]);
279 Item::deleteForUser(['resource-id' => $photo['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
281 // Update the photo albums cache
282 Photo::clearAlbumCache($page_owner_uid);
284 notice(DI::l10n()->t('Failed to delete the photo.'));
285 DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1] . '/image/' . DI::args()->getArgv()[3]);
288 DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1]);
289 return; // NOTREACHED
293 if (DI::args()->getArgc() > 2 && (!empty($_POST['desc']) || !empty($_POST['newtag']) || isset($_POST['albname']))) {
294 $desc = !empty($_POST['desc']) ? trim($_POST['desc']) : '';
295 $rawtags = !empty($_POST['newtag']) ? trim($_POST['newtag']) : '';
296 $item_id = !empty($_POST['item_id']) ? intval($_POST['item_id']) : 0;
297 $albname = !empty($_POST['albname']) ? trim($_POST['albname']) : '';
298 $origaname = !empty($_POST['origaname']) ? trim($_POST['origaname']) : '';
300 $resource_id = DI::args()->getArgv()[3];
302 if (!strlen($albname)) {
303 $albname = DateTimeFormat::localNow('Y');
306 if (!empty($_POST['rotate']) && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
307 Logger::debug('rotate');
309 $photo = Photo::getPhotoForUser($page_owner_uid, $resource_id);
311 if (DBA::isResult($photo)) {
312 $image = Photo::getImageForPhoto($photo);
314 if ($image->isValid()) {
315 $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
316 $image->rotate($rotate_deg);
318 $width = $image->getWidth();
319 $height = $image->getHeight();
321 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 0], $image);
323 if ($width > 640 || $height > 640) {
324 $image->scaleDown(640);
325 $width = $image->getWidth();
326 $height = $image->getHeight();
328 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 1], $image);
331 if ($width > 320 || $height > 320) {
332 $image->scaleDown(320);
333 $width = $image->getWidth();
334 $height = $image->getHeight();
336 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 2], $image);
342 $photos_stmt = DBA::select('photo', [], ['resource-id' => $resource_id, 'uid' => $page_owner_uid], ['order' => ['scale' => true]]);
344 $photos = DBA::toArray($photos_stmt);
346 if (DBA::isResult($photos)) {
348 $ext = $phototypes[$photo['type']];
350 ['desc' => $desc, 'album' => $albname, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow, 'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny],
351 ['resource-id' => $resource_id, 'uid' => $page_owner_uid]
354 // Update the photo albums cache if album name was changed
355 if ($albname !== $origaname) {
356 Photo::clearAlbumCache($page_owner_uid);
360 if (DBA::isResult($photos) && !$item_id) {
361 // Create item container
363 $uri = Item::newURI();
366 $arr['guid'] = System::createUUID();
367 $arr['uid'] = $page_owner_uid;
369 $arr['post-type'] = Item::PT_IMAGE;
371 $arr['resource-id'] = $photo['resource-id'];
372 $arr['contact-id'] = $owner_record['id'];
373 $arr['owner-name'] = $owner_record['name'];
374 $arr['owner-link'] = $owner_record['url'];
375 $arr['owner-avatar'] = $owner_record['thumb'];
376 $arr['author-name'] = $owner_record['name'];
377 $arr['author-link'] = $owner_record['url'];
378 $arr['author-avatar'] = $owner_record['thumb'];
379 $arr['title'] = $title;
380 $arr['allow_cid'] = $photo['allow_cid'];
381 $arr['allow_gid'] = $photo['allow_gid'];
382 $arr['deny_cid'] = $photo['deny_cid'];
383 $arr['deny_gid'] = $photo['deny_gid'];
387 $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $user['nickname'] . '/image/' . $photo['resource-id'] . ']'
388 . '[img]' . DI::baseUrl() . '/photo/' . $photo['resource-id'] . '-' . $photo['scale'] . '.'. $ext . '[/img]'
391 $item_id = Item::insert($arr);
395 $item = Post::selectFirst(['inform', 'uri-id'], ['id' => $item_id, 'uid' => $page_owner_uid]);
397 if (DBA::isResult($item)) {
398 $old_inform = $item['inform'];
402 if (strlen($rawtags)) {
405 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
406 $x = substr($rawtags, 0, 1);
407 if ($x !== '@' && $x !== '#') {
408 $rawtags = '#' . $rawtags;
412 $tags = BBCode::getTags($rawtags);
415 foreach ($tags as $tag) {
416 if (strpos($tag, '@') === 0) {
419 $name = substr($tag,1);
421 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
423 $links = @Probe::lrdd($name);
426 foreach ($links as $link) {
427 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
428 $profile = $link['@attributes']['href'];
431 if ($link['@attributes']['rel'] === 'salmon') {
432 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
434 if (strlen($inform)) {
443 $taginfo[] = [$newname, $profile, $salmon];
448 if (strrpos($newname, '+')) {
449 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
453 $contact = DBA::selectFirst('contact', [], ['id' => $tagcid, 'uid' => $page_owner_uid]);
455 $newname = str_replace('_',' ',$name);
457 //select someone from this user's contacts by name
458 $contact = DBA::selectFirst('contact', [], ['name' => $newname, 'uid' => $page_owner_uid]);
459 if (!DBA::isResult($contact)) {
460 //select someone by attag or nick and the name passed in
461 $contact = DBA::selectFirst('contact', [],
462 ['(`attag` = ? OR `nick` = ?) AND `uid` = ?', $name, $name, $page_owner_uid],
463 ['order' => ['attag' => true]]
468 if (DBA::isResult($contact)) {
469 $newname = $contact['name'];
470 $profile = $contact['url'];
472 $notify = 'cid:' . $contact['id'];
473 if (strlen($inform)) {
481 if (!empty($contact)) {
482 $taginfo[] = [$newname, $profile, $notify, $contact];
484 $taginfo[] = [$newname, $profile, $notify, null];
487 $profile = str_replace(',', '%2c', $profile);
489 if (!empty($item['uri-id'])) {
490 Tag::store($item['uri-id'], Tag::MENTION, $newname, $profile);
493 } elseif (strpos($tag, '#') === 0) {
494 $tagname = substr($tag, 1);
495 if (!empty($item['uri-id'])) {
496 Tag::store($item['uri-id'], Tag::HASHTAG, $tagname);
502 $newinform = $old_inform ?? '';
503 if (strlen($newinform) && strlen($inform)) {
506 $newinform .= $inform;
508 $fields = ['inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
509 $condition = ['id' => $item_id];
510 Item::update($fields, $condition);
513 foreach ($photos as $scales) {
514 if (intval($scales['scale']) == 2) {
519 if (intval($scales['scale']) == 4) {
525 if (count($taginfo)) {
526 foreach ($taginfo as $tagged) {
527 $uri = Item::newURI();
530 $arr['guid'] = System::createUUID();
531 $arr['uid'] = $page_owner_uid;
534 $arr['contact-id'] = $owner_record['id'];
535 $arr['owner-name'] = $owner_record['name'];
536 $arr['owner-link'] = $owner_record['url'];
537 $arr['owner-avatar'] = $owner_record['thumb'];
538 $arr['author-name'] = $owner_record['name'];
539 $arr['author-link'] = $owner_record['url'];
540 $arr['author-avatar'] = $owner_record['thumb'];
542 $arr['allow_cid'] = $photo['allow_cid'];
543 $arr['allow_gid'] = $photo['allow_gid'];
544 $arr['deny_cid'] = $photo['deny_cid'];
545 $arr['deny_gid'] = $photo['deny_gid'];
547 $arr['verb'] = Activity::TAG;
548 $arr['gravity'] = GRAVITY_PARENT;
549 $arr['object-type'] = Activity\ObjectType::PERSON;
550 $arr['target-type'] = Activity\ObjectType::IMAGE;
551 $arr['inform'] = $tagged[2];
553 $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]') ;
554 $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" ;
556 $arr['object'] = '<object><type>' . Activity\ObjectType::PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
557 $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
559 $arr['object'] .= XML::escape('<link rel="photo" type="' . $photo['type'] . '" href="' . $tagged[3]['photo'] . '" />' . "\n");
561 $arr['object'] .= '</link></object>' . "\n";
563 $arr['target'] = '<target><type>' . Activity\ObjectType::IMAGE . '</type><title>' . $photo['desc'] . '</title><id>'
564 . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '</id>';
565 $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>';
571 DI::baseUrl()->redirect($_SESSION['photo_return']);
572 return; // NOTREACHED
576 // default post action - upload a photo
577 Hook::callAll('photo_post_init', $_POST);
579 // Determine the album to use
580 $album = trim($_REQUEST['album'] ?? '');
581 $newalbum = trim($_REQUEST['newalbum'] ?? '');
583 Logger::debug('album= ' . $album . ' newalbum= ' . $newalbum);
585 if (!strlen($album)) {
586 if (strlen($newalbum)) {
589 $album = DateTimeFormat::localNow('Y');
594 * We create a wall item for every photo, but we don't want to
595 * overwhelm the data stream with a hundred newly uploaded photos.
596 * So we will make the first photo uploaded to this album in the last several hours
597 * visible by default, the rest will become visible over time when and if
598 * they acquire comments, likes, dislikes, and/or tags
601 $r = Photo::selectToArray([], ['`album` = ? AND `uid` = ? AND `created` > ?', $album, $page_owner_uid, DateTimeFormat::utc('now - 3 hours')]);
603 if (!DBA::isResult($r) || ($album == DI::l10n()->t(Photo::PROFILE_PHOTOS))) {
609 if (!empty($_REQUEST['not_visible']) && $_REQUEST['not_visible'] !== 'false') {
613 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
615 Hook::callAll('photo_post_file', $ret);
617 if (!empty($ret['src']) && !empty($ret['filesize'])) {
619 $filename = $ret['filename'];
620 $filesize = $ret['filesize'];
621 $type = $ret['type'];
622 $error = UPLOAD_ERR_OK;
623 } elseif (!empty($_FILES['userfile'])) {
624 $src = $_FILES['userfile']['tmp_name'];
625 $filename = basename($_FILES['userfile']['name']);
626 $filesize = intval($_FILES['userfile']['size']);
627 $type = $_FILES['userfile']['type'];
628 $error = $_FILES['userfile']['error'];
630 $error = UPLOAD_ERR_NO_FILE;
633 if ($error !== UPLOAD_ERR_OK) {
635 case UPLOAD_ERR_INI_SIZE:
636 notice(DI::l10n()->t('Image exceeds size limit of %s', ini_get('upload_max_filesize')));
638 case UPLOAD_ERR_FORM_SIZE:
639 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($_REQUEST['MAX_FILE_SIZE'] ?? 0)));
641 case UPLOAD_ERR_PARTIAL:
642 notice(DI::l10n()->t('Image upload didn\'t complete, please try again'));
644 case UPLOAD_ERR_NO_FILE:
645 notice(DI::l10n()->t('Image file is missing'));
647 case UPLOAD_ERR_NO_TMP_DIR:
648 case UPLOAD_ERR_CANT_WRITE:
649 case UPLOAD_ERR_EXTENSION:
650 notice(DI::l10n()->t('Server can\'t accept new file upload at this time, please contact your administrator'));
655 Hook::callAll('photo_post_end', $foo);
659 $type = Images::getMimeTypeBySource($src, $filename, $type);
661 Logger::info('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes');
663 $maximagesize = DI::config()->get('system', 'maximagesize');
665 if ($maximagesize && ($filesize > $maximagesize)) {
666 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)));
669 Hook::callAll('photo_post_end', $foo);
674 notice(DI::l10n()->t('Image file is empty.'));
677 Hook::callAll('photo_post_end', $foo);
681 Logger::debug('loading contents', ['src' => $src]);
683 $imagedata = @file_get_contents($src);
685 $image = new Image($imagedata, $type);
687 if (!$image->isValid()) {
688 Logger::notice('unable to process image');
689 notice(DI::l10n()->t('Unable to process image.'));
692 Hook::callAll('photo_post_end',$foo);
696 $exif = $image->orient($src);
699 $max_length = DI::config()->get('system', 'max_image_length');
700 if ($max_length > 0) {
701 $image->scaleDown($max_length);
704 $width = $image->getWidth();
705 $height = $image->getHeight();
709 $resource_id = Photo::newResource();
711 $r = Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 0 , Photo::DEFAULT, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
714 Logger::warning('image store failed');
715 notice(DI::l10n()->t('Image upload failed.'));
719 if ($width > 640 || $height > 640) {
720 $image->scaleDown(640);
721 Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 1, Photo::DEFAULT, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
725 if ($width > 320 || $height > 320) {
726 $image->scaleDown(320);
727 Photo::store($image, $page_owner_uid, $visitor, $resource_id, $filename, $album, 2, Photo::DEFAULT, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
731 $uri = Item::newURI();
733 // Create item container
735 if (!empty($exif['GPS']) && Feature::isEnabled($page_owner_uid, 'photo_location')) {
736 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
737 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
742 $arr['coord'] = $lat . ' ' . $lon;
745 $arr['guid'] = System::createUUID();
746 $arr['uid'] = $page_owner_uid;
748 $arr['post-type'] = Item::PT_IMAGE;
750 $arr['resource-id'] = $resource_id;
751 $arr['contact-id'] = $owner_record['id'];
752 $arr['owner-name'] = $owner_record['name'];
753 $arr['owner-link'] = $owner_record['url'];
754 $arr['owner-avatar'] = $owner_record['thumb'];
755 $arr['author-name'] = $owner_record['name'];
756 $arr['author-link'] = $owner_record['url'];
757 $arr['author-avatar'] = $owner_record['thumb'];
759 $arr['allow_cid'] = $str_contact_allow;
760 $arr['allow_gid'] = $str_group_allow;
761 $arr['deny_cid'] = $str_contact_deny;
762 $arr['deny_gid'] = $str_group_deny;
763 $arr['visible'] = $visible;
766 $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $resource_id . ']'
767 . '[img]' . DI::baseUrl() . "/photo/{$resource_id}-{$smallest}.".$image->getExt() . '[/img]'
770 $item_id = Item::insert($arr);
771 // Update the photo albums cache
772 Photo::clearAlbumCache($page_owner_uid);
774 Hook::callAll('photo_post_end', $item_id);
776 // addon uploaders should call "exit()" within the photo_post_end hook
777 // if they do not wish to be redirected
779 DI::baseUrl()->redirect($_SESSION['photo_return']);
783 function photos_content(App $a)
787 // photos/name/upload
788 // photos/name/upload/xxxxx (xxxxx is album name)
789 // photos/name/album/xxxxx
790 // photos/name/album/xxxxx/edit
791 // photos/name/album/xxxxx/drop
792 // photos/name/image/xxxxx
793 // photos/name/image/xxxxx/edit
794 // photos/name/image/xxxxx/drop
796 $user = User::getByNickname(DI::args()->getArgv()[1]);
797 if (!DBA::isResult($user)) {
798 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
801 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
802 notice(DI::l10n()->t('Public access denied.'));
807 notice(DI::l10n()->t('No photos selected'));
811 $profile = Profile::getByUID($user['uid']);
813 $phototypes = Images::supportedTypes();
815 $_SESSION['photo_return'] = DI::args()->getCommand();
819 if (DI::args()->getArgc() > 3) {
820 $datatype = DI::args()->getArgv()[2];
821 $datum = DI::args()->getArgv()[3];
822 } elseif ((DI::args()->getArgc() > 2) && (DI::args()->getArgv()[2] === 'upload')) {
823 $datatype = 'upload';
825 $datatype = 'summary';
828 if (DI::args()->getArgc() > 4) {
829 $cmd = DI::args()->getArgv()[4];
834 // Setup permissions structures
838 $remote_contact = false;
843 $owner_uid = $user['uid'];
845 $community_page = (($user['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
847 if (local_user() && (local_user() == $owner_uid)) {
849 } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
850 $contact_id = Session::getRemoteContactID($owner_uid);
851 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
853 if (DBA::isResult($contact)) {
855 $remote_contact = true;
856 $visitor = $contact_id;
860 // perhaps they're visiting - but not a community page, so they wouldn't have write access
861 if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
862 $contact_id = Session::getRemoteContactID($owner_uid);
864 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
866 $remote_contact = DBA::isResult($contact);
869 if (!$remote_contact && local_user()) {
870 $contact_id = $_SESSION['cid'];
872 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
875 if ($user['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
876 notice(DI::l10n()->t('Access to this item is restricted.'));
880 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
885 $is_owner = (local_user() && (local_user() == $owner_uid));
886 $o .= BaseProfile::getTabsHTML($a, 'photos', $is_owner, $user['nickname'], $profile['hide-friends']);
888 // Display upload form
889 if ($datatype === 'upload') {
891 notice(DI::l10n()->t('Permission denied.'));
895 $selname = (!is_null($datum) && Strings::isHex($datum)) ? hex2bin($datum) : '';
899 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '><current year></option>';
900 $albums = Photo::getAlbums($owner_uid);
901 if (!empty($albums)) {
902 foreach ($albums as $album) {
903 if ($album['album'] === '') {
906 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
907 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
913 $ret = ['post_url' => 'photos/' . $user['nickname'],
914 'addon_text' => $uploader,
915 'default_upload' => true];
917 Hook::callAll('photo_upload_form',$ret);
919 $default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
920 $default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
921 '$submit' => DI::l10n()->t('Submit'),
926 $tpl = Renderer::getMarkupTemplate('photos_upload.tpl');
928 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId()));
930 $o .= Renderer::replaceMacros($tpl,[
931 '$pagename' => DI::l10n()->t('Upload Photos'),
932 '$sessid' => session_id(),
933 '$usage' => $usage_message,
934 '$nickname' => $user['nickname'],
935 '$newalbum' => DI::l10n()->t('New album name: '),
936 '$existalbumtext' => DI::l10n()->t('or select existing album:'),
937 '$nosharetext' => DI::l10n()->t('Do not show a status post for this upload'),
938 '$albumselect' => $albumselect,
939 '$permissions' => DI::l10n()->t('Permissions'),
940 '$aclselect' => $aclselect_e,
941 '$lockstate' => ACL::getLockstateForUserId($a->getLoggedInUserId()) ? 'lock' : 'unlock',
942 '$alt_uploader' => $ret['addon_text'],
943 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
944 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
945 '$uploadurl' => $ret['post_url'],
947 // ACL permissions box
948 '$return_path' => DI::args()->getQueryString(),
954 // Display a single photo album
955 if ($datatype === 'album') {
956 // if $datum is not a valid hex, redirect to the default page
957 if (is_null($datum) || !Strings::isHex($datum)) {
958 DI::baseUrl()->redirect('photos/' . $user['nickname']. '/album');
960 $album = hex2bin($datum);
962 if ($can_post && !Photo::exists(['uid' => $owner_uid, 'album' => $album, 'photo-type' => Photo::DEFAULT])) {
967 $r = DBA::toArray(DBA::p("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = ? AND `album` = ?
968 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
972 if (DBA::isResult($r)) {
976 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
978 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
979 $order_field = $_GET['order'] ?? '';
980 if ($order_field === 'created') {
986 $r = DBA::toArray(DBA::p("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
987 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
988 ANY_VALUE(`created`) as `created`
989 FROM `photo` WHERE `uid` = ? AND `album` = ?
990 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT ? , ?",
994 $pager->getItemsPerPage()
997 if ($cmd === 'drop') {
998 $drop_url = DI::args()->getQueryString();
1000 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1002 'message' => DI::l10n()->t('Do you really want to delete this photo album and all its photos?'),
1003 'confirm' => DI::l10n()->t('Delete Album'),
1004 'cancel' => DI::l10n()->t('Cancel'),
1006 '$method' => 'post',
1007 '$confirm_url' => $drop_url,
1008 '$confirm_name' => 'dropalbum',
1009 '$confirm_value' => 'dropalbum',
1014 if ($cmd === 'edit') {
1016 $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
1020 $o .= Renderer::replaceMacros($edit_tpl,[
1021 '$nametext' => DI::l10n()->t('New album name: '),
1022 '$nickname' => $user['nickname'],
1023 '$album' => $album_e,
1024 '$hexalbum' => bin2hex($album),
1025 '$submit' => DI::l10n()->t('Submit'),
1026 '$dropsubmit' => DI::l10n()->t('Delete Album')
1029 } elseif ($can_post) {
1030 $edit = [DI::l10n()->t('Edit Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1031 $drop = [DI::l10n()->t('Drop Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/drop'];
1034 if ($order_field === 'created') {
1035 $order = [DI::l10n()->t('Show Newest First'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1037 $order = [DI::l10n()->t('Show Oldest First'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '?order=created', 'newest'];
1042 if (DBA::isResult($r)) {
1043 // "Twist" is only used for the duepunto theme with style "slackr"
1045 foreach ($r as $rr) {
1048 $ext = $phototypes[$rr['type']];
1050 $imgalt_e = $rr['filename'];
1051 $desc_e = $rr['desc'];
1055 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1056 'link' => 'photos/' . $user['nickname'] . '/image/' . $rr['resource-id']
1057 . ($order_field === 'created' ? '?order=created' : ''),
1058 'title' => DI::l10n()->t('View Photo'),
1059 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1063 'hash'=> $rr['resource-id'],
1068 $tpl = Renderer::getMarkupTemplate('photo_album.tpl');
1069 $o .= Renderer::replaceMacros($tpl, [
1070 '$photos' => $photos,
1072 '$can_post' => $can_post,
1073 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $user['nickname'] . '/upload/' . bin2hex($album)],
1077 '$paginate' => $pager->renderFull($total),
1084 // Display one photo
1085 if ($datatype === 'image') {
1086 // fetch image, item containing image, then comments
1087 $ph = Photo::selectToArray([], ["`uid` = ? AND `resource-id` = ? " . $sql_extra, $owner_uid, $datum], ['order' => ['scale']]);
1089 if (!DBA::isResult($ph)) {
1090 if (DBA::exists('photo', ['resource-id' => $datum, 'uid' => $owner_uid])) {
1091 notice(DI::l10n()->t('Permission denied. Access to this item may be restricted.'));
1093 notice(DI::l10n()->t('Photo not available'));
1098 if ($cmd === 'drop') {
1099 $drop_url = DI::args()->getQueryString();
1101 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1103 'message' => DI::l10n()->t('Do you really want to delete this photo?'),
1104 'confirm' => DI::l10n()->t('Delete Photo'),
1105 'cancel' => DI::l10n()->t('Cancel'),
1107 '$method' => 'post',
1108 '$confirm_url' => $drop_url,
1109 '$confirm_name' => 'delete',
1110 '$confirm_value' => 'delete',
1118 * @todo This query is totally bad, the whole functionality has to be changed
1119 * The query leads to a really intense used index.
1120 * By now we hide it if someone wants to.
1122 if ($cmd === 'view' && !DI::config()->get('system', 'no_count', false)) {
1123 $order_field = $_GET['order'] ?? '';
1125 if ($order_field === 'created') {
1126 $params = ['order' => [$order_field]];
1127 } elseif (!empty($order_field)) {
1128 $params = ['order' => [$order_field => true]];
1133 $prvnxt = Photo::selectToArray(['resource-id'], ["`album` = ? AND `uid` = ? AND `scale` = ?" . $sql_extra, $ph[0]['album'], $owner_uid, 0], $params);
1135 if (DBA::isResult($prvnxt)) {
1138 foreach ($prvnxt as $z => $entry) {
1139 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1143 $prv = count($prvnxt) - 1;
1145 if ($nxt >= count($prvnxt)) {
1152 if (!is_null($prv)) {
1153 $prevlink = 'photos/' . $user['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . ($order_field === 'created' ? '?order=created' : '');
1155 if (!is_null($nxt)) {
1156 $nextlink = 'photos/' . $user['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . ($order_field === 'created' ? '?order=created' : '');
1159 $tpl = Renderer::getMarkupTemplate('photo_edit_head.tpl');
1160 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
1161 '$prevlink' => $prevlink,
1162 '$nextlink' => $nextlink
1166 $prevlink = [$prevlink, '<div class="icon prev"></div>'];
1170 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1175 if (count($ph) == 1) {
1176 $hires = $lores = $ph[0];
1179 if (count($ph) > 1) {
1180 if ($ph[1]['scale'] == 2) {
1181 // original is 640 or less, we can display it directly
1182 $hires = $lores = $ph[0];
1189 $album_link = 'photos/' . $user['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1193 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1195 if ($cmd === 'edit') {
1196 $tools['view'] = ['photos/' . $user['nickname'] . '/image/' . $datum, DI::l10n()->t('View photo')];
1198 $tools['edit'] = ['photos/' . $user['nickname'] . '/image/' . $datum . '/edit', DI::l10n()->t('Edit photo')];
1199 $tools['delete'] = ['photos/' . $user['nickname'] . '/image/' . $datum . '/drop', DI::l10n()->t('Delete photo')];
1200 $tools['profile'] = ['settings/profile/photo/crop/' . $ph[0]['resource-id'], DI::l10n()->t('Use as profile photo')];
1204 $ph[0]['uid'] == local_user()
1205 && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']))
1207 $tools['lock'] = DI::l10n()->t('Private Photo');
1212 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1213 'title'=> DI::l10n()->t('View Full Size'),
1214 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?_u=' . DateTimeFormat::utcNow('ymdhis'),
1215 'height' => $hires['height'],
1216 'width' => $hires['width'],
1217 'album' => $hires['album'],
1218 'filename' => $hires['filename'],
1225 // Do we have an item for this photo?
1227 // FIXME! - replace following code to display the conversation with our normal
1228 // conversation functions so that it works correctly and tracks changes
1229 // in the evolving conversation code.
1230 // The difference is that we won't be displaying the conversation head item
1231 // as a "post" but displaying instead the photo it is linked to
1233 $link_item = Post::selectFirst([], ["`resource-id` = ?" . $sql_extra, $datum]);
1235 if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
1236 $condition = ["`parent` = ? AND `gravity` = ?", $link_item['parent'], GRAVITY_COMMENT];
1237 $total = Post::count($condition);
1239 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
1241 $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1242 $items = Post::toArray(Post::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params));
1244 if (local_user() == $link_item['uid']) {
1245 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1249 if (!empty($link_item['coord'])) {
1250 $map = Map::byCoordinates($link_item['coord']);
1255 if (!empty($link_item['id'])) {
1256 // parse tags and add links
1258 foreach (Tag::getByURIId($link_item['uri-id']) as $tag) {
1260 'name' => $tag['name'],
1261 'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag['name'])
1264 $tags = ['title' => DI::l10n()->t('Tags: '), 'tags' => $tag_arr];
1265 if ($cmd === 'edit') {
1266 $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
1267 $tags['removetitle'] = DI::l10n()->t('[Select tags to remove]');
1273 if ($cmd === 'edit' && $can_post) {
1274 $edit_tpl = Renderer::getMarkupTemplate('photo_edit.tpl');
1276 $album_e = $ph[0]['album'];
1277 $caption_e = $ph[0]['desc'];
1278 $aclselect_e = ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId(), false, ACL::getDefaultUserPermissions($ph[0]));
1280 $edit = Renderer::replaceMacros($edit_tpl, [
1281 '$id' => $ph[0]['id'],
1282 '$album' => ['albname', DI::l10n()->t('New album name'), $album_e,''],
1283 '$caption' => ['desc', DI::l10n()->t('Caption'), $caption_e, ''],
1284 '$tags' => ['newtag', DI::l10n()->t('Add a Tag'), "", DI::l10n()->t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1285 '$rotate_none' => ['rotate', DI::l10n()->t('Do not rotate'),0,'', true],
1286 '$rotate_cw' => ['rotate', DI::l10n()->t("Rotate CW \x28right\x29"),1,''],
1287 '$rotate_ccw' => ['rotate', DI::l10n()->t("Rotate CCW \x28left\x29"),2,''],
1289 '$nickname' => $user['nickname'],
1290 '$resource_id' => $ph[0]['resource-id'],
1291 '$permissions' => DI::l10n()->t('Permissions'),
1292 '$aclselect' => $aclselect_e,
1294 '$item_id' => $link_item['id'] ?? 0,
1295 '$submit' => DI::l10n()->t('Submit'),
1296 '$delete' => DI::l10n()->t('Delete Photo'),
1298 // ACL permissions box
1299 '$return_path' => DI::args()->getQueryString(),
1309 if (!empty($link_item['id']) && !empty($link_item['uri'])) {
1310 $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
1311 $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
1312 $return_path = DI::args()->getCommand();
1314 if (!DBA::isResult($items)) {
1315 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1317 * Hmmm, code depending on the presence of a particular addon?
1318 * This should be better if done by a hook
1321 if (Addon::isEnabled('qcomment')) {
1322 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1323 $qcomment = $words ? explode("\n", $words) : [];
1326 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1327 '$return_path' => '',
1328 '$jsreload' => $return_path,
1329 '$id' => $link_item['id'],
1330 '$parent' => $link_item['id'],
1331 '$profile_uid' => $owner_uid,
1332 '$mylink' => $contact['url'],
1333 '$mytitle' => DI::l10n()->t('This is you'),
1334 '$myphoto' => $contact['thumb'],
1335 '$comment' => DI::l10n()->t('Comment'),
1336 '$submit' => DI::l10n()->t('Submit'),
1337 '$preview' => DI::l10n()->t('Preview'),
1338 '$loading' => DI::l10n()->t('Loading...'),
1339 '$qcomment' => $qcomment,
1340 '$rand_num' => Crypto::randomDigits(12)
1353 if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
1354 unset($conv_responses['dislike']);
1358 if (DBA::isResult($items)) {
1359 foreach ($items as $item) {
1360 DI::conversation()->builtinActivityPuller($item, $conv_responses);
1363 if (!empty($conv_responses['like'][$link_item['uri']])) {
1364 $like = DI::conversation()->formatActivity($conv_responses['like'][$link_item['uri']]['links'], 'like', $link_item['id']);
1367 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1368 $dislike = DI::conversation()->formatActivity($conv_responses['dislike'][$link_item['uri']]['links'], 'dislike', $link_item['id']);
1371 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1373 * Hmmm, code depending on the presence of a particular addon?
1374 * This should be better if done by a hook
1377 if (Addon::isEnabled('qcomment')) {
1378 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1379 $qcomment = $words ? explode("\n", $words) : [];
1382 $comments .= Renderer::replaceMacros($cmnt_tpl,[
1383 '$return_path' => '',
1384 '$jsreload' => $return_path,
1385 '$id' => $link_item['id'],
1386 '$parent' => $link_item['id'],
1387 '$profile_uid' => $owner_uid,
1388 '$mylink' => $contact['url'],
1389 '$mytitle' => DI::l10n()->t('This is you'),
1390 '$myphoto' => $contact['thumb'],
1391 '$comment' => DI::l10n()->t('Comment'),
1392 '$submit' => DI::l10n()->t('Submit'),
1393 '$preview' => DI::l10n()->t('Preview'),
1394 '$qcomment' => $qcomment,
1395 '$rand_num' => Crypto::randomDigits(12)
1399 foreach ($items as $item) {
1403 $activity = DI::activity();
1405 if (($activity->match($item['verb'], Activity::LIKE) ||
1406 $activity->match($item['verb'], Activity::DISLIKE)) &&
1407 ($item['gravity'] != GRAVITY_PARENT)) {
1411 $author = ['uid' => 0, 'id' => $item['author-id'],
1412 'network' => $item['author-network'], 'url' => $item['author-link']];
1413 $profile_url = Contact::magicLinkByContact($author);
1414 if (strpos($profile_url, 'redir/') === 0) {
1415 $sparkle = ' sparkle';
1420 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1422 'dropping' => $dropping,
1423 'pagedrop' => false,
1424 'select' => DI::l10n()->t('Select'),
1425 'delete' => DI::l10n()->t('Delete'),
1428 $title_e = $item['title'];
1429 $body_e = BBCode::convertForUriId($item['uri-id'], $item['body']);
1431 $comments .= Renderer::replaceMacros($template,[
1432 '$id' => $item['id'],
1433 '$profile_url' => $profile_url,
1434 '$name' => $item['author-name'],
1435 '$thumb' => $item['author-avatar'],
1436 '$sparkle' => $sparkle,
1437 '$title' => $title_e,
1439 '$ago' => Temporal::getRelativeDate($item['created']),
1440 '$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''),
1442 '$comment' => $comment
1445 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1447 * Hmmm, code depending on the presence of a particular addon?
1448 * This should be better if done by a hook
1451 if (Addon::isEnabled('qcomment')) {
1452 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1453 $qcomment = $words ? explode("\n", $words) : [];
1456 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1457 '$return_path' => '',
1458 '$jsreload' => $return_path,
1459 '$id' => $item['id'],
1460 '$parent' => $item['parent'],
1461 '$profile_uid' => $owner_uid,
1462 '$mylink' => $contact['url'],
1463 '$mytitle' => DI::l10n()->t('This is you'),
1464 '$myphoto' => $contact['thumb'],
1465 '$comment' => DI::l10n()->t('Comment'),
1466 '$submit' => DI::l10n()->t('Submit'),
1467 '$preview' => DI::l10n()->t('Preview'),
1468 '$qcomment' => $qcomment,
1469 '$rand_num' => Crypto::randomDigits(12)
1476 foreach ($conv_responses as $verb => $activity) {
1477 if (isset($activity[$link_item['uri']])) {
1478 $responses[$verb] = $activity[$link_item['uri']];
1482 if ($cmd === 'view' && ($can_post || Security::canWriteToUserWall($owner_uid))) {
1483 $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl');
1484 $likebuttons = Renderer::replaceMacros($like_tpl, [
1485 '$id' => $link_item['id'],
1486 '$like' => DI::l10n()->t('Like'),
1487 '$like_title' => DI::l10n()->t('I like this (toggle)'),
1488 '$dislike' => DI::l10n()->t('Dislike'),
1489 '$wait' => DI::l10n()->t('Please wait'),
1490 '$dislike_title' => DI::l10n()->t('I don\'t like this (toggle)'),
1491 '$hide_dislike' => DI::pConfig()->get(local_user(), 'system', 'hide_dislike'),
1492 '$responses' => $responses,
1493 '$return_path' => DI::args()->getQueryString(),
1497 $paginate = $pager->renderFull($total);
1500 $photo_tpl = Renderer::getMarkupTemplate('photo_view.tpl');
1501 $o .= Renderer::replaceMacros($photo_tpl, [
1502 '$id' => $ph[0]['id'],
1503 '$album' => [$album_link, $ph[0]['album']],
1506 '$prevlink' => $prevlink,
1507 '$nextlink' => $nextlink,
1508 '$desc' => $ph[0]['desc'],
1512 '$map_text' => DI::l10n()->t('Map'),
1513 '$likebuttons' => $likebuttons,
1515 '$dislike' => $dislike,
1516 '$comments' => $comments,
1517 '$paginate' => $paginate,
1520 DI::page()['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
1521 DI::page()['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1522 DI::page()['htmlhead'] .= '<meta name="twitter:image" content="' . DI::baseUrl() . "/" . $photo["href"] . '" />' . "\n";
1523 DI::page()['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1524 DI::page()['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1529 // Default - show recent photos with upload link (if applicable)
1532 $r = DBA::toArray(DBA::p("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = ? AND `photo-type` = ?
1533 $sql_extra GROUP BY `resource-id`",
1537 if (DBA::isResult($r)) {
1541 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
1543 $r = DBA::toArray(DBA::p("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1544 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1545 ANY_VALUE(`created`) AS `created` FROM `photo`
1546 WHERE `uid` = ? AND `photo-type` = ?
1547 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT ? , ?",
1551 $pager->getItemsPerPage()
1555 if (DBA::isResult($r)) {
1556 // "Twist" is only used for the duepunto theme with style "slackr"
1558 foreach ($r as $rr) {
1560 $ext = $phototypes[$rr['type']];
1562 $alt_e = $rr['filename'];
1563 $name_e = $rr['album'];
1567 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1568 'link' => 'photos/' . $user['nickname'] . '/image/' . $rr['resource-id'],
1569 'title' => DI::l10n()->t('View Photo'),
1570 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1573 'link' => 'photos/' . $user['nickname'] . '/album/' . bin2hex($rr['album']),
1575 'alt' => DI::l10n()->t('View Album'),
1582 $tpl = Renderer::getMarkupTemplate('photos_recent.tpl');
1583 $o .= Renderer::replaceMacros($tpl, [
1584 '$title' => DI::l10n()->t('Recent Photos'),
1585 '$can_post' => $can_post,
1586 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $user['nickname'] . '/upload'],
1587 '$photos' => $photos,
1588 '$paginate' => $pager->renderFull($total),