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'), [
1023 '$method' => 'post',
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 '$confirm_url' => $drop_url,
1027 '$confirm_name' => 'dropalbum',
1028 '$confirm_value' => 'dropalbum',
1029 '$cancel' => DI::l10n()->t('Cancel'),
1034 if ($cmd === 'edit') {
1035 if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS))) {
1037 $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
1041 $o .= Renderer::replaceMacros($edit_tpl,[
1042 '$nametext' => DI::l10n()->t('New album name: '),
1043 '$nickname' => $user['nickname'],
1044 '$album' => $album_e,
1045 '$hexalbum' => bin2hex($album),
1046 '$submit' => DI::l10n()->t('Submit'),
1047 '$dropsubmit' => DI::l10n()->t('Delete Album')
1052 if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS)) && $can_post) {
1053 $edit = [DI::l10n()->t('Edit Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1054 $drop = [DI::l10n()->t('Drop Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/drop'];
1058 if ($order_field === 'posted') {
1059 $order = [DI::l10n()->t('Show Newest First'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1061 $order = [DI::l10n()->t('Show Oldest First'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '?order=posted', 'newest'];
1066 if (DBA::isResult($r)) {
1067 // "Twist" is only used for the duepunto theme with style "slackr"
1069 foreach ($r as $rr) {
1072 $ext = $phototypes[$rr['type']];
1074 $imgalt_e = $rr['filename'];
1075 $desc_e = $rr['desc'];
1079 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1080 'link' => 'photos/' . $user['nickname'] . '/image/' . $rr['resource-id']
1081 . ($order_field === 'posted' ? '?order=posted' : ''),
1082 'title' => DI::l10n()->t('View Photo'),
1083 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1087 'hash'=> $rr['resource-id'],
1092 $tpl = Renderer::getMarkupTemplate('photo_album.tpl');
1093 $o .= Renderer::replaceMacros($tpl, [
1094 '$photos' => $photos,
1096 '$can_post' => $can_post,
1097 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $user['nickname'] . '/upload/' . bin2hex($album)],
1101 '$paginate' => $pager->renderFull($total),
1108 // Display one photo
1109 if ($datatype === 'image') {
1110 // fetch image, item containing image, then comments
1111 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1112 $sql_extra ORDER BY `scale` ASC ",
1117 if (!DBA::isResult($ph)) {
1118 if (DBA::exists('photo', ['resource-id' => $datum, 'uid' => $owner_uid])) {
1119 notice(DI::l10n()->t('Permission denied. Access to this item may be restricted.'));
1121 notice(DI::l10n()->t('Photo not available'));
1126 if ($cmd === 'drop') {
1127 $drop_url = DI::args()->getQueryString();
1129 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1130 '$method' => 'post',
1131 '$message' => DI::l10n()->t('Do you really want to delete this photo?'),
1132 '$confirm' => DI::l10n()->t('Delete Photo'),
1133 '$confirm_url' => $drop_url,
1134 '$confirm_name' => 'delete',
1135 '$confirm_value' => 'delete',
1136 '$cancel' => DI::l10n()->t('Cancel'),
1144 * @todo This query is totally bad, the whole functionality has to be changed
1145 * The query leads to a really intense used index.
1146 * By now we hide it if someone wants to.
1148 if ($cmd === 'view' && !DI::config()->get('system', 'no_count', false)) {
1149 $order_field = $_GET['order'] ?? '';
1151 if ($order_field === 'posted') {
1157 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1158 $sql_extra ORDER BY `created` $order ",
1159 DBA::escape($ph[0]['album']),
1163 if (DBA::isResult($prvnxt)) {
1166 foreach ($prvnxt as $z => $entry) {
1167 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1171 $prv = count($prvnxt) - 1;
1173 if ($nxt >= count($prvnxt)) {
1180 if (!is_null($prv)) {
1181 $prevlink = 'photos/' . $user['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1183 if (!is_null($nxt)) {
1184 $nextlink = 'photos/' . $user['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1187 $tpl = Renderer::getMarkupTemplate('photo_edit_head.tpl');
1188 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
1189 '$prevlink' => $prevlink,
1190 '$nextlink' => $nextlink
1194 $prevlink = [$prevlink, '<div class="icon prev"></div>'];
1198 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1203 if (count($ph) == 1) {
1204 $hires = $lores = $ph[0];
1207 if (count($ph) > 1) {
1208 if ($ph[1]['scale'] == 2) {
1209 // original is 640 or less, we can display it directly
1210 $hires = $lores = $ph[0];
1217 $album_link = 'photos/' . $user['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1221 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1223 if ($cmd === 'edit') {
1224 $tools['view'] = ['photos/' . $user['nickname'] . '/image/' . $datum, DI::l10n()->t('View photo')];
1226 $tools['edit'] = ['photos/' . $user['nickname'] . '/image/' . $datum . '/edit', DI::l10n()->t('Edit photo')];
1227 $tools['delete'] = ['photos/' . $user['nickname'] . '/image/' . $datum . '/drop', DI::l10n()->t('Delete photo')];
1228 $tools['profile'] = ['settings/profile/photo/crop/' . $ph[0]['resource-id'], DI::l10n()->t('Use as profile photo')];
1232 $ph[0]['uid'] == local_user()
1233 && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']))
1235 $tools['lock'] = DI::l10n()->t('Private Photo');
1240 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1241 'title'=> DI::l10n()->t('View Full Size'),
1242 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?_u=' . DateTimeFormat::utcNow('ymdhis'),
1243 'height' => $hires['height'],
1244 'width' => $hires['width'],
1245 'album' => $hires['album'],
1246 'filename' => $hires['filename'],
1253 // Do we have an item for this photo?
1255 // FIXME! - replace following code to display the conversation with our normal
1256 // conversation functions so that it works correctly and tracks changes
1257 // in the evolving conversation code.
1258 // The difference is that we won't be displaying the conversation head item
1259 // as a "post" but displaying instead the photo it is linked to
1261 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1262 $linked_items = q("SELECT `id` FROM `post-user-view` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1265 if (DBA::isResult($linked_items)) {
1266 // This is a workaround to not being forced to rewrite the while $sql_extra handling
1267 $link_item = Post::selectFirst([], ['id' => $linked_items[0]['id']]);
1270 if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
1271 $condition = ["`parent` = ? AND `gravity` = ?", $link_item['parent'], GRAVITY_COMMENT];
1272 $total = Post::count($condition);
1274 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
1276 $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1277 $items = Post::toArray(Post::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params));
1279 if (local_user() == $link_item['uid']) {
1280 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1284 if (!empty($link_item['coord'])) {
1285 $map = Map::byCoordinates($link_item['coord']);
1290 if (!empty($link_item['id'])) {
1291 $tag_text = Tag::getCSVByURIId($link_item['uri-id']);
1292 $arr = explode(',', $tag_text);
1293 // parse tags and add links
1295 foreach ($arr as $tag) {
1297 'name' => BBCode::convert($tag),
1298 'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag)
1301 $tags = ['title' => DI::l10n()->t('Tags: '), 'tags' => $tag_arr];
1302 if ($cmd === 'edit') {
1303 $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
1304 $tags['removetitle'] = DI::l10n()->t('[Select tags to remove]');
1310 if ($cmd === 'edit' && $can_post) {
1311 $edit_tpl = Renderer::getMarkupTemplate('photo_edit.tpl');
1313 $album_e = $ph[0]['album'];
1314 $caption_e = $ph[0]['desc'];
1315 $aclselect_e = ACL::getFullSelectorHTML(DI::page(), $a->getLoggedInUserId(), false, ACL::getDefaultUserPermissions($ph[0]));
1317 $edit = Renderer::replaceMacros($edit_tpl, [
1318 '$id' => $ph[0]['id'],
1319 '$album' => ['albname', DI::l10n()->t('New album name'), $album_e,''],
1320 '$caption' => ['desc', DI::l10n()->t('Caption'), $caption_e, ''],
1321 '$tags' => ['newtag', DI::l10n()->t('Add a Tag'), "", DI::l10n()->t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1322 '$rotate_none' => ['rotate', DI::l10n()->t('Do not rotate'),0,'', true],
1323 '$rotate_cw' => ['rotate', DI::l10n()->t("Rotate CW \x28right\x29"),1,''],
1324 '$rotate_ccw' => ['rotate', DI::l10n()->t("Rotate CCW \x28left\x29"),2,''],
1326 '$nickname' => $user['nickname'],
1327 '$resource_id' => $ph[0]['resource-id'],
1328 '$permissions' => DI::l10n()->t('Permissions'),
1329 '$aclselect' => $aclselect_e,
1331 '$item_id' => $link_item['id'] ?? 0,
1332 '$submit' => DI::l10n()->t('Submit'),
1333 '$delete' => DI::l10n()->t('Delete Photo'),
1335 // ACL permissions box
1336 '$return_path' => DI::args()->getQueryString(),
1346 if (!empty($link_item['id']) && !empty($link_item['uri'])) {
1347 $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
1348 $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
1349 $return_path = DI::args()->getCommand();
1351 if (!DBA::isResult($items)) {
1352 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1354 * Hmmm, code depending on the presence of a particular addon?
1355 * This should be better if done by a hook
1358 if (Addon::isEnabled('qcomment')) {
1359 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1360 $qcomment = $words ? explode("\n", $words) : [];
1363 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1364 '$return_path' => '',
1365 '$jsreload' => $return_path,
1366 '$id' => $link_item['id'],
1367 '$parent' => $link_item['id'],
1368 '$profile_uid' => $owner_uid,
1369 '$mylink' => $contact['url'],
1370 '$mytitle' => DI::l10n()->t('This is you'),
1371 '$myphoto' => $contact['thumb'],
1372 '$comment' => DI::l10n()->t('Comment'),
1373 '$submit' => DI::l10n()->t('Submit'),
1374 '$preview' => DI::l10n()->t('Preview'),
1375 '$loading' => DI::l10n()->t('Loading...'),
1376 '$qcomment' => $qcomment,
1377 '$rand_num' => Crypto::randomDigits(12)
1390 if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
1391 unset($conv_responses['dislike']);
1395 if (DBA::isResult($items)) {
1396 foreach ($items as $item) {
1397 builtin_activity_puller($item, $conv_responses);
1400 if (!empty($conv_responses['like'][$link_item['uri']])) {
1401 $like = format_activity($conv_responses['like'][$link_item['uri']]['links'], 'like', $link_item['id']);
1404 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1405 $dislike = format_activity($conv_responses['dislike'][$link_item['uri']]['links'], 'dislike', $link_item['id']);
1408 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1410 * Hmmm, code depending on the presence of a particular addon?
1411 * This should be better if done by a hook
1414 if (Addon::isEnabled('qcomment')) {
1415 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1416 $qcomment = $words ? explode("\n", $words) : [];
1419 $comments .= Renderer::replaceMacros($cmnt_tpl,[
1420 '$return_path' => '',
1421 '$jsreload' => $return_path,
1422 '$id' => $link_item['id'],
1423 '$parent' => $link_item['id'],
1424 '$profile_uid' => $owner_uid,
1425 '$mylink' => $contact['url'],
1426 '$mytitle' => DI::l10n()->t('This is you'),
1427 '$myphoto' => $contact['thumb'],
1428 '$comment' => DI::l10n()->t('Comment'),
1429 '$submit' => DI::l10n()->t('Submit'),
1430 '$preview' => DI::l10n()->t('Preview'),
1431 '$qcomment' => $qcomment,
1432 '$rand_num' => Crypto::randomDigits(12)
1436 foreach ($items as $item) {
1440 $activity = DI::activity();
1442 if (($activity->match($item['verb'], Activity::LIKE) ||
1443 $activity->match($item['verb'], Activity::DISLIKE)) &&
1444 ($item['gravity'] != GRAVITY_PARENT)) {
1448 $author = ['uid' => 0, 'id' => $item['author-id'],
1449 'network' => $item['author-network'], 'url' => $item['author-link']];
1450 $profile_url = Contact::magicLinkByContact($author);
1451 if (strpos($profile_url, 'redir/') === 0) {
1452 $sparkle = ' sparkle';
1457 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1459 'dropping' => $dropping,
1460 'pagedrop' => false,
1461 'select' => DI::l10n()->t('Select'),
1462 'delete' => DI::l10n()->t('Delete'),
1465 $title_e = $item['title'];
1466 $body_e = BBCode::convert($item['body']);
1468 $comments .= Renderer::replaceMacros($template,[
1469 '$id' => $item['id'],
1470 '$profile_url' => $profile_url,
1471 '$name' => $item['author-name'],
1472 '$thumb' => $item['author-avatar'],
1473 '$sparkle' => $sparkle,
1474 '$title' => $title_e,
1476 '$ago' => Temporal::getRelativeDate($item['created']),
1477 '$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''),
1479 '$comment' => $comment
1482 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1484 * Hmmm, code depending on the presence of a particular addon?
1485 * This should be better if done by a hook
1488 if (Addon::isEnabled('qcomment')) {
1489 $words = DI::pConfig()->get(local_user(), 'qcomment', 'words');
1490 $qcomment = $words ? explode("\n", $words) : [];
1493 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1494 '$return_path' => '',
1495 '$jsreload' => $return_path,
1496 '$id' => $item['id'],
1497 '$parent' => $item['parent'],
1498 '$profile_uid' => $owner_uid,
1499 '$mylink' => $contact['url'],
1500 '$mytitle' => DI::l10n()->t('This is you'),
1501 '$myphoto' => $contact['thumb'],
1502 '$comment' => DI::l10n()->t('Comment'),
1503 '$submit' => DI::l10n()->t('Submit'),
1504 '$preview' => DI::l10n()->t('Preview'),
1505 '$qcomment' => $qcomment,
1506 '$rand_num' => Crypto::randomDigits(12)
1513 foreach ($conv_responses as $verb => $activity) {
1514 if (isset($activity[$link_item['uri']])) {
1515 $responses[$verb] = $activity[$link_item['uri']];
1519 if ($cmd === 'view' && ($can_post || Security::canWriteToUserWall($owner_uid))) {
1520 $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl');
1521 $likebuttons = Renderer::replaceMacros($like_tpl, [
1522 '$id' => $link_item['id'],
1523 '$like' => DI::l10n()->t('Like'),
1524 '$like_title' => DI::l10n()->t('I like this (toggle)'),
1525 '$dislike' => DI::l10n()->t('Dislike'),
1526 '$wait' => DI::l10n()->t('Please wait'),
1527 '$dislike_title' => DI::l10n()->t('I don\'t like this (toggle)'),
1528 '$hide_dislike' => DI::pConfig()->get(local_user(), 'system', 'hide_dislike'),
1529 '$responses' => $responses,
1530 '$return_path' => DI::args()->getQueryString(),
1534 $paginate = $pager->renderFull($total);
1537 $photo_tpl = Renderer::getMarkupTemplate('photo_view.tpl');
1538 $o .= Renderer::replaceMacros($photo_tpl, [
1539 '$id' => $ph[0]['id'],
1540 '$album' => [$album_link, $ph[0]['album']],
1543 '$prevlink' => $prevlink,
1544 '$nextlink' => $nextlink,
1545 '$desc' => $ph[0]['desc'],
1549 '$map_text' => DI::l10n()->t('Map'),
1550 '$likebuttons' => $likebuttons,
1552 '$dislike' => $dislike,
1553 '$comments' => $comments,
1554 '$paginate' => $paginate,
1557 DI::page()['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
1558 DI::page()['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1559 DI::page()['htmlhead'] .= '<meta name="twitter:image" content="' . DI::baseUrl() . "/" . $photo["href"] . '" />' . "\n";
1560 DI::page()['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1561 DI::page()['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1566 // Default - show recent photos with upload link (if applicable)
1569 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1570 $sql_extra GROUP BY `resource-id`",
1571 intval($user['uid']),
1572 DBA::escape(Photo::CONTACT_PHOTOS),
1573 DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS))
1575 if (DBA::isResult($r)) {
1579 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
1581 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1582 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1583 ANY_VALUE(`created`) AS `created` FROM `photo`
1584 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1585 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1586 intval($user['uid']),
1587 DBA::escape(Photo::CONTACT_PHOTOS),
1588 DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS)),
1590 $pager->getItemsPerPage()
1594 if (DBA::isResult($r)) {
1595 // "Twist" is only used for the duepunto theme with style "slackr"
1597 foreach ($r as $rr) {
1598 //hide profile photos to others
1599 if (!$is_owner && !Session::getRemoteContactID($owner_uid) && ($rr['album'] == DI::l10n()->t('Profile Photos'))) {
1604 $ext = $phototypes[$rr['type']];
1606 $alt_e = $rr['filename'];
1607 $name_e = $rr['album'];
1611 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1612 'link' => 'photos/' . $user['nickname'] . '/image/' . $rr['resource-id'],
1613 'title' => DI::l10n()->t('View Photo'),
1614 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1617 'link' => 'photos/' . $user['nickname'] . '/album/' . bin2hex($rr['album']),
1619 'alt' => DI::l10n()->t('View Album'),
1626 $tpl = Renderer::getMarkupTemplate('photos_recent.tpl');
1627 $o .= Renderer::replaceMacros($tpl, [
1628 '$title' => DI::l10n()->t('Recent Photos'),
1629 '$can_post' => $can_post,
1630 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $user['nickname'] . '/upload'],
1631 '$photos' => $photos,
1632 '$paginate' => $pager->renderFull($total),