3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 use Friendica\Content\Feature;
24 use Friendica\Content\Nav;
25 use Friendica\Content\Pager;
26 use Friendica\Content\Text\BBCode;
27 use Friendica\Content\Widget;
28 use Friendica\Core\ACL;
29 use Friendica\Core\Addon;
30 use Friendica\Core\Hook;
31 use Friendica\Core\Logger;
32 use Friendica\Core\Renderer;
33 use Friendica\Core\Session;
34 use Friendica\Core\System;
35 use Friendica\Database\DBA;
37 use Friendica\Model\Contact;
38 use Friendica\Model\Item;
39 use Friendica\Model\Photo;
40 use Friendica\Model\Post;
41 use Friendica\Model\Profile;
42 use Friendica\Model\Tag;
43 use Friendica\Model\User;
44 use Friendica\Module\BaseProfile;
45 use Friendica\Network\Probe;
46 use Friendica\Object\Image;
47 use Friendica\Protocol\Activity;
48 use Friendica\Util\Crypto;
49 use Friendica\Util\DateTimeFormat;
50 use Friendica\Util\Images;
51 use Friendica\Util\Map;
52 use Friendica\Security\Security;
53 use Friendica\Util\Strings;
54 use Friendica\Util\Temporal;
55 use Friendica\Util\XML;
56 use Friendica\Network\HTTPException;
58 function photos_init(App $a) {
60 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
64 Nav::setSelected('home');
66 if (DI::args()->getArgc() > 1) {
67 $owner = User::getOwnerDataByNick(DI::args()->getArgv()[1]);
69 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
72 $is_owner = (local_user() && (local_user() == $owner['uid']));
74 $albums = Photo::getAlbums($owner['uid']);
76 $albums_visible = ((intval($owner['hidewall']) && !Session::isAuthenticated()) ? false : true);
78 // add various encodings to the array so we can just loop through and pick them out in a template
79 $ret = ['success' => false];
82 if ($albums_visible) {
83 $ret['success'] = true;
87 foreach ($albums as $k => $album) {
88 //hide profile photos to others
89 if (!$is_owner && !Session::getRemoteContactID($owner['uid']) && ($album['album'] == DI::l10n()->t('Profile Photos')))
92 'text' => $album['album'],
93 'total' => $album['total'],
94 'url' => 'photos/' . $owner['nickname'] . '/album/' . bin2hex($album['album']),
95 'urlencode' => urlencode($album['album']),
96 'bin2hex' => bin2hex($album['album'])
98 $ret['albums'][] = $entry;
102 if (local_user() && $owner['uid'] == local_user()) {
108 if ($ret['success']) {
109 $photo_albums_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('photo_albums.tpl'), [
110 '$nick' => $owner['nickname'],
111 '$title' => DI::l10n()->t('Photo Albums'),
112 '$recent' => DI::l10n()->t('Recent Photos'),
113 '$albums' => $ret['albums'],
114 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $owner['nickname'] . '/upload'],
115 '$can_post' => $can_post
119 if (empty(DI::page()['aside'])) {
120 DI::page()['aside'] = '';
123 DI::page()['aside'] .= Widget\VCard::getHTML($owner);
125 if (!empty($photo_albums_widget)) {
126 DI::page()['aside'] .= $photo_albums_widget;
129 $tpl = Renderer::getMarkupTemplate("photos_head.tpl");
131 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
132 '$ispublic' => DI::l10n()->t('everybody')
139 function photos_post(App $a)
141 $user = User::getByNickname(DI::args()->getArgv()[1]);
142 if (!DBA::isResult($user)) {
143 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
146 $phototypes = Images::supportedTypes();
151 $page_owner_uid = intval($user['uid']);
152 $community_page = $user['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
154 if (local_user() && (local_user() == $page_owner_uid)) {
156 } elseif ($community_page && !empty(Session::getRemoteContactID($page_owner_uid))) {
157 $contact_id = Session::getRemoteContactID($page_owner_uid);
159 $visitor = $contact_id;
163 notice(DI::l10n()->t('Permission denied.'));
167 $owner_record = User::getOwnerDataById($page_owner_uid);
169 if (!$owner_record) {
170 notice(DI::l10n()->t('Contact information unavailable'));
171 DI::logger()->info('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
175 $aclFormatter = DI::aclFormatter();
176 $str_contact_allow = isset($_REQUEST['contact_allow']) ? $aclFormatter->toString($_REQUEST['contact_allow']) : $owner_record['allow_cid'] ?? '';
177 $str_group_allow = isset($_REQUEST['group_allow']) ? $aclFormatter->toString($_REQUEST['group_allow']) : $owner_record['allow_gid'] ?? '';
178 $str_contact_deny = isset($_REQUEST['contact_deny']) ? $aclFormatter->toString($_REQUEST['contact_deny']) : $owner_record['deny_cid'] ?? '';
179 $str_group_deny = isset($_REQUEST['group_deny']) ? $aclFormatter->toString($_REQUEST['group_deny']) : $owner_record['deny_gid'] ?? '';
181 $visibility = $_REQUEST['visibility'] ?? '';
182 if ($visibility === 'public') {
183 // The ACL selector introduced in version 2019.12 sends ACL input data even when the Public visibility is selected
184 $str_contact_allow = $str_group_allow = $str_contact_deny = $str_group_deny = '';
185 } else if ($visibility === 'custom') {
186 // Since we know from the visibility parameter the item should be private, we have to prevent the empty ACL
187 // case that would make it public. So we always append the author's contact id to the allowed contacts.
188 // See https://github.com/friendica/friendica/issues/9672
189 $str_contact_allow .= $aclFormatter->toString(Contact::getPublicIdByUserId($page_owner_uid));
192 if (DI::args()->getArgc() > 3 && DI::args()->getArgv()[2] === 'album') {
193 if (!Strings::isHex(DI::args()->getArgv()[3])) {
194 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
196 $album = hex2bin(DI::args()->getArgv()[3]);
198 if ($album === DI::l10n()->t('Profile Photos') || $album === Photo::CONTACT_PHOTOS || $album === DI::l10n()->t(Photo::CONTACT_PHOTOS)) {
199 DI::baseUrl()->redirect($_SESSION['photo_return']);
200 return; // NOTREACHED
203 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
205 intval($page_owner_uid)
208 if (!DBA::isResult($r)) {
209 notice(DI::l10n()->t('Album not found.'));
210 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
211 return; // NOTREACHED
214 // Check if the user has responded to a delete confirmation query
215 if (!empty($_REQUEST['canceled'])) {
216 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album/' . DI::args()->getArgv()[3]);
219 // RENAME photo album
220 $newalbum = Strings::escapeTags(trim($_POST['albumname']));
221 if ($newalbum != $album) {
222 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
223 DBA::escape($newalbum),
225 intval($page_owner_uid)
227 // Update the photo albums cache
228 Photo::clearAlbumCache($page_owner_uid);
230 DI::baseUrl()->redirect('photos/' . $a->getLoggedInUserNickname() . '/album/' . bin2hex($newalbum));
231 return; // NOTREACHED
235 * DELETE all photos filed in a given album
237 if (!empty($_POST['dropalbum'])) {
240 // get the list of photos we are about to delete
242 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
244 intval($page_owner_uid),
248 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
249 intval(local_user()),
254 if (DBA::isResult($r)) {
255 foreach ($r as $rr) {
259 // remove the associated photos
260 Photo::delete(['resource-id' => $res, 'uid' => $page_owner_uid]);
262 // find and delete the corresponding item with all the comments and likes/dislikes
263 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
265 // Update the photo albums cache
266 Photo::clearAlbumCache($page_owner_uid);
267 notice(DI::l10n()->t('Album successfully deleted'));
269 notice(DI::l10n()->t('Album was empty.'));
273 DI::baseUrl()->redirect('photos/' . $user['nickname'] . '/album');
276 if (DI::args()->getArgc() > 3 && DI::args()->getArgv()[2] === 'image') {
277 // Check if the user has responded to a delete confirmation query for a single photo
278 if (!empty($_POST['canceled'])) {
279 DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1] . '/image/' . DI::args()->getArgv()[3]);
282 if (!empty($_POST['delete'])) {
283 // same as above but remove single photo
285 $condition = ['contact-id' => $visitor, 'uid' => $page_owner_uid, 'resource-id' => DI::args()->getArgv()[3]];
288 $condition = ['uid' => local_user(), 'resource-id' => DI::args()->getArgv()[3]];
291 $photo = DBA::selectFirst('photo', ['resource-id'], $condition);
293 if (DBA::isResult($photo)) {
294 Photo::delete(['uid' => $page_owner_uid, 'resource-id' => $photo['resource-id']]);
296 Item::deleteForUser(['resource-id' => $photo['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
298 // Update the photo albums cache
299 Photo::clearAlbumCache($page_owner_uid);
301 notice(DI::l10n()->t('Failed to delete the photo.'));
302 DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1] . '/image/' . DI::args()->getArgv()[3]);
305 DI::baseUrl()->redirect('photos/' . DI::args()->getArgv()[1]);
306 return; // NOTREACHED
310 if (DI::args()->getArgc() > 2 && (!empty($_POST['desc']) || !empty($_POST['newtag']) || isset($_POST['albname']))) {
311 $desc = !empty($_POST['desc']) ? Strings::escapeTags(trim($_POST['desc'])) : '';
312 $rawtags = !empty($_POST['newtag']) ? Strings::escapeTags(trim($_POST['newtag'])) : '';
313 $item_id = !empty($_POST['item_id']) ? intval($_POST['item_id']) : 0;
314 $albname = !empty($_POST['albname']) ? trim($_POST['albname']) : '';
315 $origaname = !empty($_POST['origaname']) ? Strings::escapeTags(trim($_POST['origaname'])) : '';
317 $resource_id = DI::args()->getArgv()[3];
319 if (!strlen($albname)) {
320 $albname = DateTimeFormat::localNow('Y');
323 if (!empty($_POST['rotate']) && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
324 Logger::log('rotate');
326 $photo = Photo::getPhotoForUser($page_owner_uid, $resource_id);
328 if (DBA::isResult($photo)) {
329 $image = Photo::getImageForPhoto($photo);
331 if ($image->isValid()) {
332 $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
333 $image->rotate($rotate_deg);
335 $width = $image->getWidth();
336 $height = $image->getHeight();
338 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 0], $image);
340 if ($width > 640 || $height > 640) {
341 $image->scaleDown(640);
342 $width = $image->getWidth();
343 $height = $image->getHeight();
345 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 1], $image);
348 if ($width > 320 || $height > 320) {
349 $image->scaleDown(320);
350 $width = $image->getWidth();
351 $height = $image->getHeight();
353 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 2], $image);
359 $photos_stmt = DBA::select('photo', [], ['resource-id' => $resource_id, 'uid' => $page_owner_uid], ['order' => ['scale' => true]]);
361 $photos = DBA::toArray($photos_stmt);
363 if (DBA::isResult($photos)) {
365 $ext = $phototypes[$photo['type']];
367 ['desc' => $desc, 'album' => $albname, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow, 'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny],
368 ['resource-id' => $resource_id, 'uid' => $page_owner_uid]
371 // Update the photo albums cache if album name was changed
372 if ($albname !== $origaname) {
373 Photo::clearAlbumCache($page_owner_uid);
375 /* Don't make the item visible if the only change was the album name */
378 if ($photo['desc'] !== $desc || strlen($rawtags)) {
383 if (DBA::isResult($photos) && !$item_id) {
384 // Create item container
386 $uri = Item::newURI($page_owner_uid);
389 $arr['guid'] = System::createUUID();
390 $arr['uid'] = $page_owner_uid;
392 $arr['post-type'] = Item::PT_IMAGE;
394 $arr['resource-id'] = $photo['resource-id'];
395 $arr['contact-id'] = $owner_record['id'];
396 $arr['owner-name'] = $owner_record['name'];
397 $arr['owner-link'] = $owner_record['url'];
398 $arr['owner-avatar'] = $owner_record['thumb'];
399 $arr['author-name'] = $owner_record['name'];
400 $arr['author-link'] = $owner_record['url'];
401 $arr['author-avatar'] = $owner_record['thumb'];
402 $arr['title'] = $title;
403 $arr['allow_cid'] = $photo['allow_cid'];
404 $arr['allow_gid'] = $photo['allow_gid'];
405 $arr['deny_cid'] = $photo['deny_cid'];
406 $arr['deny_gid'] = $photo['deny_gid'];
407 $arr['visible'] = $visibility;
410 $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $user['nickname'] . '/image/' . $photo['resource-id'] . ']'
411 . '[img]' . DI::baseUrl() . '/photo/' . $photo['resource-id'] . '-' . $photo['scale'] . '.'. $ext . '[/img]'
414 $item_id = Item::insert($arr);
418 $item = Post::selectFirst(['inform', 'uri-id'], ['id' => $item_id, 'uid' => $page_owner_uid]);
420 if (DBA::isResult($item)) {
421 $old_inform = $item['inform'];
425 if (strlen($rawtags)) {
428 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
429 $x = substr($rawtags, 0, 1);
430 if ($x !== '@' && $x !== '#') {
431 $rawtags = '#' . $rawtags;
435 $tags = BBCode::getTags($rawtags);
438 foreach ($tags as $tag) {
439 if (strpos($tag, '@') === 0) {
442 $name = substr($tag,1);
444 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
446 $links = @Probe::lrdd($name);
449 foreach ($links as $link) {
450 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
451 $profile = $link['@attributes']['href'];
454 if ($link['@attributes']['rel'] === 'salmon') {
455 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
457 if (strlen($inform)) {
466 $taginfo[] = [$newname, $profile, $salmon];
471 if (strrpos($newname, '+')) {
472 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
476 $contact = DBA::selectFirst('contact', [], ['id' => $tagcid, 'uid' => $page_owner_uid]);
478 $newname = str_replace('_',' ',$name);
480 //select someone from this user's contacts by name
481 $contact = DBA::selectFirst('contact', [], ['name' => $newname, 'uid' => $page_owner_uid]);
482 if (!DBA::isResult($contact)) {
483 //select someone by attag or nick and the name passed in
484 $contact = DBA::selectFirst('contact', [],
485 ['(`attag` = ? OR `nick` = ?) AND `uid` = ?', $name, $name, $page_owner_uid],
486 ['order' => ['attag' => true]]
491 if (DBA::isResult($contact)) {
492 $newname = $contact['name'];
493 $profile = $contact['url'];
495 $notify = 'cid:' . $contact['id'];
496 if (strlen($inform)) {
504 if (!empty($contact)) {
505 $taginfo[] = [$newname, $profile, $notify, $contact];
507 $taginfo[] = [$newname, $profile, $notify, null];
510 $profile = str_replace(',', '%2c', $profile);
512 if (!empty($item['uri-id'])) {
513 Tag::store($item['uri-id'], Tag::MENTION, $newname, $profile);
516 } elseif (strpos($tag, '#') === 0) {
517 $tagname = substr($tag, 1);
518 if (!empty($item['uri-id'])) {
519 Tag::store($item['uri-id'], Tag::HASHTAG, $tagname);
525 $newinform = $old_inform ?? '';
526 if (strlen($newinform) && strlen($inform)) {
529 $newinform .= $inform;
531 $fields = ['inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
532 $condition = ['id' => $item_id];
533 Item::update($fields, $condition);
536 foreach ($photos as $scales) {
537 if (intval($scales['scale']) == 2) {
542 if (intval($scales['scale']) == 4) {
548 if (count($taginfo)) {
549 foreach ($taginfo as $tagged) {
550 $uri = Item::newURI($page_owner_uid);
553 $arr['guid'] = System::createUUID();
554 $arr['uid'] = $page_owner_uid;
557 $arr['contact-id'] = $owner_record['id'];
558 $arr['owner-name'] = $owner_record['name'];
559 $arr['owner-link'] = $owner_record['url'];
560 $arr['owner-avatar'] = $owner_record['thumb'];
561 $arr['author-name'] = $owner_record['name'];
562 $arr['author-link'] = $owner_record['url'];
563 $arr['author-avatar'] = $owner_record['thumb'];
565 $arr['allow_cid'] = $photo['allow_cid'];
566 $arr['allow_gid'] = $photo['allow_gid'];
567 $arr['deny_cid'] = $photo['deny_cid'];
568 $arr['deny_gid'] = $photo['deny_gid'];
570 $arr['verb'] = Activity::TAG;
571 $arr['gravity'] = GRAVITY_PARENT;
572 $arr['object-type'] = Activity\ObjectType::PERSON;
573 $arr['target-type'] = Activity\ObjectType::IMAGE;
574 $arr['inform'] = $tagged[2];
576 $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]') ;
577 $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" ;
579 $arr['object'] = '<object><type>' . Activity\ObjectType::PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
580 $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
582 $arr['object'] .= XML::escape('<link rel="photo" type="' . $photo['type'] . '" href="' . $tagged[3]['photo'] . '" />' . "\n");
584 $arr['object'] .= '</link></object>' . "\n";
586 $arr['target'] = '<target><type>' . Activity\ObjectType::IMAGE . '</type><title>' . $photo['desc'] . '</title><id>'
587 . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '</id>';
588 $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>';
594 DI::baseUrl()->redirect($_SESSION['photo_return']);
595 return; // NOTREACHED
599 // default post action - upload a photo
600 Hook::callAll('photo_post_init', $_POST);
602 // Determine the album to use
603 $album = trim($_REQUEST['album'] ?? '');
604 $newalbum = trim($_REQUEST['newalbum'] ?? '');
606 Logger::info('album= ' . $album . ' newalbum= ' . $newalbum);
608 if (!strlen($album)) {
609 if (strlen($newalbum)) {
612 $album = DateTimeFormat::localNow('Y');
617 * We create a wall item for every photo, but we don't want to
618 * overwhelm the data stream with a hundred newly uploaded photos.
619 * So we will make the first photo uploaded to this album in the last several hours
620 * visible by default, the rest will become visible over time when and if
621 * they acquire comments, likes, dislikes, and/or tags
624 $r = Photo::selectToArray([], ['`album` = ? AND `uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR', $album, $page_owner_uid]);
626 if (!DBA::isResult($r) || ($album == DI::l10n()->t('Profile Photos'))) {
632 if (!empty($_REQUEST['not_visible']) && $_REQUEST['not_visible'] !== 'false') {
636 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
638 Hook::callAll('photo_post_file', $ret);
640 if (!empty($ret['src']) && !empty($ret['filesize'])) {
642 $filename = $ret['filename'];
643 $filesize = $ret['filesize'];
644 $type = $ret['type'];
645 $error = UPLOAD_ERR_OK;
646 } elseif (!empty($_FILES['userfile'])) {
647 $src = $_FILES['userfile']['tmp_name'];
648 $filename = basename($_FILES['userfile']['name']);
649 $filesize = intval($_FILES['userfile']['size']);
650 $type = $_FILES['userfile']['type'];
651 $error = $_FILES['userfile']['error'];
653 $error = UPLOAD_ERR_NO_FILE;
656 if ($error !== UPLOAD_ERR_OK) {
658 case UPLOAD_ERR_INI_SIZE:
659 notice(DI::l10n()->t('Image exceeds size limit of %s', ini_get('upload_max_filesize')));
661 case UPLOAD_ERR_FORM_SIZE:
662 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($_REQUEST['MAX_FILE_SIZE'] ?? 0)));
664 case UPLOAD_ERR_PARTIAL:
665 notice(DI::l10n()->t('Image upload didn\'t complete, please try again'));
667 case UPLOAD_ERR_NO_FILE:
668 notice(DI::l10n()->t('Image file is missing'));
670 case UPLOAD_ERR_NO_TMP_DIR:
671 case UPLOAD_ERR_CANT_WRITE:
672 case UPLOAD_ERR_EXTENSION:
673 notice(DI::l10n()->t('Server can\'t accept new file upload at this time, please contact your administrator'));
678 Hook::callAll('photo_post_end', $foo);
682 $type = Images::getMimeTypeBySource($src, $filename, $type);
684 Logger::log('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', Logger::DEBUG);
686 $maximagesize = DI::config()->get('system', 'maximagesize');
688 if ($maximagesize && ($filesize > $maximagesize)) {
689 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)));
692 Hook::callAll('photo_post_end', $foo);
697 notice(DI::l10n()->t('Image file is empty.'));
700 Hook::callAll('photo_post_end', $foo);
704 Logger::log('mod/photos.php: photos_post(): loading the contents of ' . $src , Logger::DEBUG);
706 $imagedata = @file_get_contents($src);
708 $image = new Image($imagedata, $type);
710 if (!$image->isValid()) {
711 Logger::log('mod/photos.php: photos_post(): unable to process image' , Logger::DEBUG);
712 notice(DI::l10n()->t('Unable to process image.'));
715 Hook::callAll('photo_post_end',$foo);
719 $exif = $image->orient($src);
722 $max_length = DI::config()->get('system', 'max_image_length');
724 $max_length = MAX_IMAGE_LENGTH;
726 if ($max_length > 0) {
727 $image->scaleDown($max_length);
730 $width = $image->getWidth();
731 $height = $image->getHeight();
735 $resource_id = Photo::newResource();
737 $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);
740 Logger::log('mod/photos.php: photos_post(): image store failed', Logger::DEBUG);
741 notice(DI::l10n()->t('Image upload failed.'));
745 if ($width > 640 || $height > 640) {
746 $image->scaleDown(640);
747 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);
751 if ($width > 320 || $height > 320) {
752 $image->scaleDown(320);
753 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);
757 $uri = Item::newURI($page_owner_uid);
759 // Create item container
761 if (!empty($exif['GPS']) && Feature::isEnabled($page_owner_uid, 'photo_location')) {
762 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
763 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
768 $arr['coord'] = $lat . ' ' . $lon;
771 $arr['guid'] = System::createUUID();
772 $arr['uid'] = $page_owner_uid;
774 $arr['post-type'] = Item::PT_IMAGE;
776 $arr['resource-id'] = $resource_id;
777 $arr['contact-id'] = $owner_record['id'];
778 $arr['owner-name'] = $owner_record['name'];
779 $arr['owner-link'] = $owner_record['url'];
780 $arr['owner-avatar'] = $owner_record['thumb'];
781 $arr['author-name'] = $owner_record['name'];
782 $arr['author-link'] = $owner_record['url'];
783 $arr['author-avatar'] = $owner_record['thumb'];
785 $arr['allow_cid'] = $str_contact_allow;
786 $arr['allow_gid'] = $str_group_allow;
787 $arr['deny_cid'] = $str_contact_deny;
788 $arr['deny_gid'] = $str_group_deny;
789 $arr['visible'] = $visible;
792 $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $resource_id . ']'
793 . '[img]' . DI::baseUrl() . "/photo/{$resource_id}-{$smallest}.".$image->getExt() . '[/img]'
796 $item_id = Item::insert($arr);
797 // Update the photo albums cache
798 Photo::clearAlbumCache($page_owner_uid);
800 Hook::callAll('photo_post_end', $item_id);
802 // addon uploaders should call "exit()" within the photo_post_end hook
803 // if they do not wish to be redirected
805 DI::baseUrl()->redirect($_SESSION['photo_return']);
809 function photos_content(App $a)
813 // photos/name/upload
814 // photos/name/upload/xxxxx (xxxxx is album name)
815 // photos/name/album/xxxxx
816 // photos/name/album/xxxxx/edit
817 // photos/name/album/xxxxx/drop
818 // photos/name/image/xxxxx
819 // photos/name/image/xxxxx/edit
820 // photos/name/image/xxxxx/drop
822 $user = User::getByNickname(DI::args()->getArgv()[1]);
823 if (!DBA::isResult($user)) {
824 throw new HTTPException\NotFoundException(DI::l10n()->t('User not found.'));
827 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
828 notice(DI::l10n()->t('Public access denied.'));
833 notice(DI::l10n()->t('No photos selected'));
837 $profile = Profile::getByUID($user['uid']);
839 $phototypes = Images::supportedTypes();
841 $_SESSION['photo_return'] = DI::args()->getCommand();
845 if (DI::args()->getArgc() > 3) {
846 $datatype = DI::args()->getArgv()[2];
847 $datum = DI::args()->getArgv()[3];
848 } elseif ((DI::args()->getArgc() > 2) && (DI::args()->getArgv()[2] === 'upload')) {
849 $datatype = 'upload';
851 $datatype = 'summary';
854 if (DI::args()->getArgc() > 4) {
855 $cmd = DI::args()->getArgv()[4];
860 // Setup permissions structures
864 $remote_contact = false;
869 $owner_uid = $user['uid'];
871 $community_page = (($user['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
873 if (local_user() && (local_user() == $owner_uid)) {
875 } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
876 $contact_id = Session::getRemoteContactID($owner_uid);
877 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
879 if (DBA::isResult($contact)) {
881 $remote_contact = true;
882 $visitor = $contact_id;
886 // perhaps they're visiting - but not a community page, so they wouldn't have write access
887 if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
888 $contact_id = Session::getRemoteContactID($owner_uid);
890 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
892 $remote_contact = DBA::isResult($contact);
895 if (!$remote_contact && local_user()) {
896 $contact_id = $_SESSION['cid'];
898 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
901 if ($user['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
902 notice(DI::l10n()->t('Access to this item is restricted.'));
906 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
911 $is_owner = (local_user() && (local_user() == $owner_uid));
912 $o .= BaseProfile::getTabsHTML($a, 'photos', $is_owner, $user['nickname'], $profile['hide-friends']);
914 // Display upload form
915 if ($datatype === 'upload') {
917 notice(DI::l10n()->t('Permission denied.'));
921 $selname = Strings::isHex($datum) ? hex2bin($datum) : '';
925 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '><current year></option>';
926 $albums = Photo::getAlbums($owner_uid);
927 if (!empty($albums)) {
928 foreach ($albums as $album) {
929 if (($album['album'] === '') || ($album['album'] === Photo::CONTACT_PHOTOS) || ($album['album'] === DI::l10n()->t(Photo::CONTACT_PHOTOS))) {
932 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
933 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
939 $ret = ['post_url' => 'photos/' . $user['nickname'],
940 'addon_text' => $uploader,
941 'default_upload' => true];
943 Hook::callAll('photo_upload_form',$ret);
945 $default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
946 $default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
947 '$submit' => DI::l10n()->t('Submit'),
952 $tpl = Renderer::getMarkupTemplate('photos_upload.tpl');
954 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId()));
956 $o .= Renderer::replaceMacros($tpl,[
957 '$pagename' => DI::l10n()->t('Upload Photos'),
958 '$sessid' => session_id(),
959 '$usage' => $usage_message,
960 '$nickname' => $user['nickname'],
961 '$newalbum' => DI::l10n()->t('New album name: '),
962 '$existalbumtext' => DI::l10n()->t('or select existing album:'),
963 '$nosharetext' => DI::l10n()->t('Do not show a status post for this upload'),
964 '$albumselect' => $albumselect,
965 '$permissions' => DI::l10n()->t('Permissions'),
966 '$aclselect' => $aclselect_e,
967 '$lockstate' => ACL::getLockstateForUserId($a->getLoggedInUserId()) ? 'lock' : 'unlock',
968 '$alt_uploader' => $ret['addon_text'],
969 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
970 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
971 '$uploadurl' => $ret['post_url'],
973 // ACL permissions box
974 '$return_path' => DI::args()->getQueryString(),
980 // Display a single photo album
981 if ($datatype === 'album') {
982 // if $datum is not a valid hex, redirect to the default page
983 if (!Strings::isHex($datum)) {
984 DI::baseUrl()->redirect('photos/' . $user['nickname']. '/album');
986 $album = hex2bin($datum);
989 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
990 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
994 if (DBA::isResult($r)) {
998 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
1000 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1001 $order_field = $_GET['order'] ?? '';
1002 if ($order_field === 'posted') {
1008 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1009 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1010 ANY_VALUE(`created`) as `created`
1011 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1012 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1014 DBA::escape($album),
1016 $pager->getItemsPerPage()
1019 if ($cmd === 'drop') {
1020 $drop_url = DI::args()->getQueryString();
1022 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1024 'message' => DI::l10n()->t('Do you really want to delete this photo album and all its photos?'),
1025 'confirm' => DI::l10n()->t('Delete Album'),
1026 'cancel' => DI::l10n()->t('Cancel'),
1028 '$method' => 'post',
1029 '$confirm_url' => $drop_url,
1030 '$confirm_name' => 'dropalbum',
1031 '$confirm_value' => 'dropalbum',
1036 if ($cmd === 'edit') {
1037 if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS))) {
1039 $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
1043 $o .= Renderer::replaceMacros($edit_tpl,[
1044 '$nametext' => DI::l10n()->t('New album name: '),
1045 '$nickname' => $user['nickname'],
1046 '$album' => $album_e,
1047 '$hexalbum' => bin2hex($album),
1048 '$submit' => DI::l10n()->t('Submit'),
1049 '$dropsubmit' => DI::l10n()->t('Delete Album')
1054 if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS)) && $can_post) {
1055 $edit = [DI::l10n()->t('Edit Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1056 $drop = [DI::l10n()->t('Drop Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/drop'];
1060 if ($order_field === 'posted') {
1061 $order = [DI::l10n()->t('Show Newest First'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1063 $order = [DI::l10n()->t('Show Oldest First'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '?order=posted', 'newest'];
1068 if (DBA::isResult($r)) {
1069 // "Twist" is only used for the duepunto theme with style "slackr"
1071 foreach ($r as $rr) {
1074 $ext = $phototypes[$rr['type']];
1076 $imgalt_e = $rr['filename'];
1077 $desc_e = $rr['desc'];
1081 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1082 'link' => 'photos/' . $user['nickname'] . '/image/' . $rr['resource-id']
1083 . ($order_field === 'posted' ? '?order=posted' : ''),
1084 'title' => DI::l10n()->t('View Photo'),
1085 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1089 'hash'=> $rr['resource-id'],
1094 $tpl = Renderer::getMarkupTemplate('photo_album.tpl');
1095 $o .= Renderer::replaceMacros($tpl, [
1096 '$photos' => $photos,
1098 '$can_post' => $can_post,
1099 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $user['nickname'] . '/upload/' . bin2hex($album)],
1103 '$paginate' => $pager->renderFull($total),
1110 // Display one photo
1111 if ($datatype === 'image') {
1112 // fetch image, item containing image, then comments
1113 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1114 $sql_extra ORDER BY `scale` ASC ",
1119 if (!DBA::isResult($ph)) {
1120 if (DBA::exists('photo', ['resource-id' => $datum, 'uid' => $owner_uid])) {
1121 notice(DI::l10n()->t('Permission denied. Access to this item may be restricted.'));
1123 notice(DI::l10n()->t('Photo not available'));
1128 if ($cmd === 'drop') {
1129 $drop_url = DI::args()->getQueryString();
1131 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1133 'message' => DI::l10n()->t('Do you really want to delete this photo?'),
1134 'confirm' => DI::l10n()->t('Delete Photo'),
1135 'cancel' => DI::l10n()->t('Cancel'),
1137 '$method' => 'post',
1138 '$confirm_url' => $drop_url,
1139 '$confirm_name' => 'delete',
1140 '$confirm_value' => 'delete',
1148 * @todo This query is totally bad, the whole functionality has to be changed
1149 * The query leads to a really intense used index.
1150 * By now we hide it if someone wants to.
1152 if ($cmd === 'view' && !DI::config()->get('system', 'no_count', false)) {
1153 $order_field = $_GET['order'] ?? '';
1155 if ($order_field === 'posted') {
1161 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1162 $sql_extra ORDER BY `created` $order ",
1163 DBA::escape($ph[0]['album']),
1167 if (DBA::isResult($prvnxt)) {
1170 foreach ($prvnxt as $z => $entry) {
1171 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1175 $prv = count($prvnxt) - 1;
1177 if ($nxt >= count($prvnxt)) {
1184 if (!is_null($prv)) {
1185 $prevlink = 'photos/' . $user['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1187 if (!is_null($nxt)) {
1188 $nextlink = 'photos/' . $user['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1191 $tpl = Renderer::getMarkupTemplate('photo_edit_head.tpl');
1192 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
1193 '$prevlink' => $prevlink,
1194 '$nextlink' => $nextlink
1198 $prevlink = [$prevlink, '<div class="icon prev"></div>'];
1202 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1207 if (count($ph) == 1) {
1208 $hires = $lores = $ph[0];
1211 if (count($ph) > 1) {
1212 if ($ph[1]['scale'] == 2) {
1213 // original is 640 or less, we can display it directly
1214 $hires = $lores = $ph[0];
1221 $album_link = 'photos/' . $user['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1225 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1227 if ($cmd === 'edit') {
1228 $tools['view'] = ['photos/' . $user['nickname'] . '/image/' . $datum, DI::l10n()->t('View photo')];
1230 $tools['edit'] = ['photos/' . $user['nickname'] . '/image/' . $datum . '/edit', DI::l10n()->t('Edit photo')];
1231 $tools['delete'] = ['photos/' . $user['nickname'] . '/image/' . $datum . '/drop', DI::l10n()->t('Delete photo')];
1232 $tools['profile'] = ['settings/profile/photo/crop/' . $ph[0]['resource-id'], DI::l10n()->t('Use as profile photo')];
1236 $ph[0]['uid'] == local_user()
1237 && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']))
1239 $tools['lock'] = DI::l10n()->t('Private Photo');
1244 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1245 'title'=> DI::l10n()->t('View Full Size'),
1246 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?_u=' . DateTimeFormat::utcNow('ymdhis'),
1247 'height' => $hires['height'],
1248 'width' => $hires['width'],
1249 'album' => $hires['album'],
1250 'filename' => $hires['filename'],
1257 // Do we have an item for this photo?
1259 // FIXME! - replace following code to display the conversation with our normal
1260 // conversation functions so that it works correctly and tracks changes
1261 // in the evolving conversation code.
1262 // The difference is that we won't be displaying the conversation head item
1263 // as a "post" but displaying instead the photo it is linked to
1265 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1266 $linked_items = q("SELECT `id` FROM `post-user-view` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1269 if (DBA::isResult($linked_items)) {
1270 // This is a workaround to not being forced to rewrite the while $sql_extra handling
1271 $link_item = Post::selectFirst([], ['id' => $linked_items[0]['id']]);
1274 if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
1275 $condition = ["`parent` = ? AND `gravity` = ?", $link_item['parent'], GRAVITY_COMMENT];
1276 $total = Post::count($condition);
1278 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
1280 $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1281 $items = Post::toArray(Post::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params));
1283 if (local_user() == $link_item['uid']) {
1284 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1288 if (!empty($link_item['coord'])) {
1289 $map = Map::byCoordinates($link_item['coord']);
1294 if (!empty($link_item['id'])) {
1295 $tag_text = Tag::getCSVByURIId($link_item['uri-id']);
1296 $arr = explode(',', $tag_text);
1297 // parse tags and add links
1299 foreach ($arr as $tag) {
1301 'name' => BBCode::convert($tag),
1302 'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag)
1305 $tags = ['title' => DI::l10n()->t('Tags: '), 'tags' => $tag_arr];
1306 if ($cmd === 'edit') {
1307 $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
1308 $tags['removetitle'] = DI::l10n()->t('[Select tags to remove]');
1314 if ($cmd === 'edit' && $can_post) {
1315 $edit_tpl = Renderer::getMarkupTemplate('photo_edit.tpl');
1317 $album_e = $ph[0]['album'];
1318 $caption_e = $ph[0]['desc'];
1319 $aclselect_e = ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId(), false, ACL::getDefaultUserPermissions($ph[0]));
1321 $edit = Renderer::replaceMacros($edit_tpl, [
1322 '$id' => $ph[0]['id'],
1323 '$album' => ['albname', DI::l10n()->t('New album name'), $album_e,''],
1324 '$caption' => ['desc', DI::l10n()->t('Caption'), $caption_e, ''],
1325 '$tags' => ['newtag', DI::l10n()->t('Add a Tag'), "", DI::l10n()->t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1326 '$rotate_none' => ['rotate', DI::l10n()->t('Do not rotate'),0,'', true],
1327 '$rotate_cw' => ['rotate', DI::l10n()->t("Rotate CW \x28right\x29"),1,''],
1328 '$rotate_ccw' => ['rotate', DI::l10n()->t("Rotate CCW \x28left\x29"),2,''],
1330 '$nickname' => $user['nickname'],
1331 '$resource_id' => $ph[0]['resource-id'],
1332 '$permissions' => DI::l10n()->t('Permissions'),
1333 '$aclselect' => $aclselect_e,
1335 '$item_id' => $link_item['id'] ?? 0,
1336 '$submit' => DI::l10n()->t('Submit'),
1337 '$delete' => DI::l10n()->t('Delete Photo'),
1339 // ACL permissions box
1340 '$return_path' => DI::args()->getQueryString(),
1350 if (!empty($link_item['id']) && !empty($link_item['uri'])) {
1351 $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
1352 $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
1353 $return_path = DI::args()->getCommand();
1355 if (!DBA::isResult($items)) {
1356 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1358 * Hmmm, code depending on the presence of a particular addon?
1359 * This should be better if done by a hook
1362 if (Addon::isEnabled('qcomment')) {
1363 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1364 $qcomment = $words ? explode("\n", $words) : [];
1367 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1368 '$return_path' => '',
1369 '$jsreload' => $return_path,
1370 '$id' => $link_item['id'],
1371 '$parent' => $link_item['id'],
1372 '$profile_uid' => $owner_uid,
1373 '$mylink' => $contact['url'],
1374 '$mytitle' => DI::l10n()->t('This is you'),
1375 '$myphoto' => $contact['thumb'],
1376 '$comment' => DI::l10n()->t('Comment'),
1377 '$submit' => DI::l10n()->t('Submit'),
1378 '$preview' => DI::l10n()->t('Preview'),
1379 '$loading' => DI::l10n()->t('Loading...'),
1380 '$qcomment' => $qcomment,
1381 '$rand_num' => Crypto::randomDigits(12)
1394 if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
1395 unset($conv_responses['dislike']);
1399 if (DBA::isResult($items)) {
1400 foreach ($items as $item) {
1401 DI::conversation()->builtinActivityPuller($item, $conv_responses);
1404 if (!empty($conv_responses['like'][$link_item['uri']])) {
1405 $like = DI::conversation()->formatActivity($conv_responses['like'][$link_item['uri']]['links'], 'like', $link_item['id']);
1408 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1409 $dislike = DI::conversation()->formatActivity($conv_responses['dislike'][$link_item['uri']]['links'], 'dislike', $link_item['id']);
1412 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1414 * Hmmm, code depending on the presence of a particular addon?
1415 * This should be better if done by a hook
1418 if (Addon::isEnabled('qcomment')) {
1419 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1420 $qcomment = $words ? explode("\n", $words) : [];
1423 $comments .= Renderer::replaceMacros($cmnt_tpl,[
1424 '$return_path' => '',
1425 '$jsreload' => $return_path,
1426 '$id' => $link_item['id'],
1427 '$parent' => $link_item['id'],
1428 '$profile_uid' => $owner_uid,
1429 '$mylink' => $contact['url'],
1430 '$mytitle' => DI::l10n()->t('This is you'),
1431 '$myphoto' => $contact['thumb'],
1432 '$comment' => DI::l10n()->t('Comment'),
1433 '$submit' => DI::l10n()->t('Submit'),
1434 '$preview' => DI::l10n()->t('Preview'),
1435 '$qcomment' => $qcomment,
1436 '$rand_num' => Crypto::randomDigits(12)
1440 foreach ($items as $item) {
1444 $activity = DI::activity();
1446 if (($activity->match($item['verb'], Activity::LIKE) ||
1447 $activity->match($item['verb'], Activity::DISLIKE)) &&
1448 ($item['gravity'] != GRAVITY_PARENT)) {
1452 $author = ['uid' => 0, 'id' => $item['author-id'],
1453 'network' => $item['author-network'], 'url' => $item['author-link']];
1454 $profile_url = Contact::magicLinkByContact($author);
1455 if (strpos($profile_url, 'redir/') === 0) {
1456 $sparkle = ' sparkle';
1461 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1463 'dropping' => $dropping,
1464 'pagedrop' => false,
1465 'select' => DI::l10n()->t('Select'),
1466 'delete' => DI::l10n()->t('Delete'),
1469 $title_e = $item['title'];
1470 $body_e = BBCode::convert($item['body']);
1472 $comments .= Renderer::replaceMacros($template,[
1473 '$id' => $item['id'],
1474 '$profile_url' => $profile_url,
1475 '$name' => $item['author-name'],
1476 '$thumb' => $item['author-avatar'],
1477 '$sparkle' => $sparkle,
1478 '$title' => $title_e,
1480 '$ago' => Temporal::getRelativeDate($item['created']),
1481 '$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''),
1483 '$comment' => $comment
1486 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1488 * Hmmm, code depending on the presence of a particular addon?
1489 * This should be better if done by a hook
1492 if (Addon::isEnabled('qcomment')) {
1493 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1494 $qcomment = $words ? explode("\n", $words) : [];
1497 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1498 '$return_path' => '',
1499 '$jsreload' => $return_path,
1500 '$id' => $item['id'],
1501 '$parent' => $item['parent'],
1502 '$profile_uid' => $owner_uid,
1503 '$mylink' => $contact['url'],
1504 '$mytitle' => DI::l10n()->t('This is you'),
1505 '$myphoto' => $contact['thumb'],
1506 '$comment' => DI::l10n()->t('Comment'),
1507 '$submit' => DI::l10n()->t('Submit'),
1508 '$preview' => DI::l10n()->t('Preview'),
1509 '$qcomment' => $qcomment,
1510 '$rand_num' => Crypto::randomDigits(12)
1517 foreach ($conv_responses as $verb => $activity) {
1518 if (isset($activity[$link_item['uri']])) {
1519 $responses[$verb] = $activity[$link_item['uri']];
1523 if ($cmd === 'view' && ($can_post || Security::canWriteToUserWall($owner_uid))) {
1524 $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl');
1525 $likebuttons = Renderer::replaceMacros($like_tpl, [
1526 '$id' => $link_item['id'],
1527 '$like' => DI::l10n()->t('Like'),
1528 '$like_title' => DI::l10n()->t('I like this (toggle)'),
1529 '$dislike' => DI::l10n()->t('Dislike'),
1530 '$wait' => DI::l10n()->t('Please wait'),
1531 '$dislike_title' => DI::l10n()->t('I don\'t like this (toggle)'),
1532 '$hide_dislike' => DI::pConfig()->get(local_user(), 'system', 'hide_dislike'),
1533 '$responses' => $responses,
1534 '$return_path' => DI::args()->getQueryString(),
1538 $paginate = $pager->renderFull($total);
1541 $photo_tpl = Renderer::getMarkupTemplate('photo_view.tpl');
1542 $o .= Renderer::replaceMacros($photo_tpl, [
1543 '$id' => $ph[0]['id'],
1544 '$album' => [$album_link, $ph[0]['album']],
1547 '$prevlink' => $prevlink,
1548 '$nextlink' => $nextlink,
1549 '$desc' => $ph[0]['desc'],
1553 '$map_text' => DI::l10n()->t('Map'),
1554 '$likebuttons' => $likebuttons,
1556 '$dislike' => $dislike,
1557 '$comments' => $comments,
1558 '$paginate' => $paginate,
1561 DI::page()['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
1562 DI::page()['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1563 DI::page()['htmlhead'] .= '<meta name="twitter:image" content="' . DI::baseUrl() . "/" . $photo["href"] . '" />' . "\n";
1564 DI::page()['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1565 DI::page()['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1570 // Default - show recent photos with upload link (if applicable)
1573 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1574 $sql_extra GROUP BY `resource-id`",
1575 intval($user['uid']),
1576 DBA::escape(Photo::CONTACT_PHOTOS),
1577 DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS))
1579 if (DBA::isResult($r)) {
1583 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
1585 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1586 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1587 ANY_VALUE(`created`) AS `created` FROM `photo`
1588 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1589 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1590 intval($user['uid']),
1591 DBA::escape(Photo::CONTACT_PHOTOS),
1592 DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS)),
1594 $pager->getItemsPerPage()
1598 if (DBA::isResult($r)) {
1599 // "Twist" is only used for the duepunto theme with style "slackr"
1601 foreach ($r as $rr) {
1602 //hide profile photos to others
1603 if (!$is_owner && !Session::getRemoteContactID($owner_uid) && ($rr['album'] == DI::l10n()->t('Profile Photos'))) {
1608 $ext = $phototypes[$rr['type']];
1610 $alt_e = $rr['filename'];
1611 $name_e = $rr['album'];
1615 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1616 'link' => 'photos/' . $user['nickname'] . '/image/' . $rr['resource-id'],
1617 'title' => DI::l10n()->t('View Photo'),
1618 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1621 'link' => 'photos/' . $user['nickname'] . '/album/' . bin2hex($rr['album']),
1623 'alt' => DI::l10n()->t('View Album'),
1630 $tpl = Renderer::getMarkupTemplate('photos_recent.tpl');
1631 $o .= Renderer::replaceMacros($tpl, [
1632 '$title' => DI::l10n()->t('Recent Photos'),
1633 '$can_post' => $can_post,
1634 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $user['nickname'] . '/upload'],
1635 '$photos' => $photos,
1636 '$paginate' => $pager->renderFull($total),