3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 use Friendica\Content\Feature;
24 use Friendica\Content\Nav;
25 use Friendica\Content\Pager;
26 use Friendica\Content\Text\BBCode;
27 use Friendica\Core\ACL;
28 use Friendica\Core\Hook;
29 use Friendica\Core\Logger;
30 use Friendica\Core\Renderer;
31 use Friendica\Core\Session;
32 use Friendica\Core\System;
33 use Friendica\Database\DBA;
35 use Friendica\Model\Contact;
36 use Friendica\Model\Item;
37 use Friendica\Model\Photo;
38 use Friendica\Model\Profile;
39 use Friendica\Model\User;
40 use Friendica\Module\BaseProfile;
41 use Friendica\Network\Probe;
42 use Friendica\Object\Image;
43 use Friendica\Protocol\Activity;
44 use Friendica\Util\Crypto;
45 use Friendica\Util\DateTimeFormat;
46 use Friendica\Util\Images;
47 use Friendica\Util\Map;
48 use Friendica\Util\Security;
49 use Friendica\Util\Strings;
50 use Friendica\Util\Temporal;
51 use Friendica\Util\XML;
53 function photos_init(App $a) {
55 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
59 Nav::setSelected('home');
63 $user = DBA::selectFirst('user', [], ['nickname' => $nick, 'blocked' => false]);
65 if (!DBA::isResult($user)) {
69 $a->data['user'] = $user;
70 $a->profile_uid = $user['uid'];
71 $is_owner = (local_user() && (local_user() == $a->profile_uid));
73 $profile = Profile::getByNickname($nick, $a->profile_uid);
75 $account_type = Contact::getAccountType($profile);
77 $tpl = Renderer::getMarkupTemplate('widget/vcard.tpl');
79 $vcard_widget = Renderer::replaceMacros($tpl, [
80 '$name' => $profile['name'],
81 '$photo' => $profile['photo'],
82 '$addr' => $profile['addr'] ?? '',
83 '$account_type' => $account_type,
84 '$about' => BBCode::convert($profile['about'] ?? ''),
87 $albums = Photo::getAlbums($a->data['user']['uid']);
89 $albums_visible = ((intval($a->data['user']['hidewall']) && !Session::isAuthenticated()) ? false : true);
91 // add various encodings to the array so we can just loop through and pick them out in a template
92 $ret = ['success' => false];
95 $a->data['albums'] = $albums;
97 if ($albums_visible) {
98 $ret['success'] = true;
102 foreach ($albums as $k => $album) {
103 //hide profile photos to others
104 if (!$is_owner && !Session::getRemoteContactID($a->profile_uid) && ($album['album'] == DI::l10n()->t('Profile Photos')))
107 'text' => $album['album'],
108 'total' => $album['total'],
109 'url' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
110 'urlencode' => urlencode($album['album']),
111 'bin2hex' => bin2hex($album['album'])
113 $ret['albums'][] = $entry;
117 if (local_user() && $a->data['user']['uid'] == local_user()) {
123 if ($ret['success']) {
124 $photo_albums_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('photo_albums.tpl'), [
125 '$nick' => $a->data['user']['nickname'],
126 '$title' => DI::l10n()->t('Photo Albums'),
127 '$recent' => DI::l10n()->t('Recent Photos'),
128 '$albums' => $ret['albums'],
129 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'],
130 '$can_post' => $can_post
134 if (empty(DI::page()['aside'])) {
135 DI::page()['aside'] = '';
138 DI::page()['aside'] .= $vcard_widget;
140 if (!empty($photo_albums_widget)) {
141 DI::page()['aside'] .= $photo_albums_widget;
144 $tpl = Renderer::getMarkupTemplate("photos_head.tpl");
146 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
147 '$ispublic' => DI::l10n()->t('everybody')
154 function photos_post(App $a)
156 Logger::log('mod-photos: photos_post: begin' , Logger::DEBUG);
157 Logger::log('mod_photos: REQUEST ' . print_r($_REQUEST, true), Logger::DATA);
158 Logger::log('mod_photos: FILES ' . print_r($_FILES, true), Logger::DATA);
160 $phototypes = Images::supportedTypes();
165 $page_owner_uid = intval($a->data['user']['uid']);
166 $community_page = $a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
168 if (local_user() && (local_user() == $page_owner_uid)) {
170 } elseif ($community_page && !empty(Session::getRemoteContactID($page_owner_uid))) {
171 $contact_id = Session::getRemoteContactID($page_owner_uid);
173 $visitor = $contact_id;
177 notice(DI::l10n()->t('Permission denied.') . EOL);
181 $owner_record = User::getOwnerDataById($page_owner_uid);
183 if (!$owner_record) {
184 notice(DI::l10n()->t('Contact information unavailable') . EOL);
185 Logger::log('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
189 if ($a->argc > 3 && $a->argv[2] === 'album') {
190 if (!Strings::isHex($a->argv[3])) {
191 DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname'] . '/album');
193 $album = hex2bin($a->argv[3]);
195 if ($album === DI::l10n()->t('Profile Photos') || $album === 'Contact Photos' || $album === DI::l10n()->t('Contact Photos')) {
196 DI::baseUrl()->redirect($_SESSION['photo_return']);
197 return; // NOTREACHED
200 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
202 intval($page_owner_uid)
205 if (!DBA::isResult($r)) {
206 notice(DI::l10n()->t('Album not found.') . EOL);
207 DI::baseUrl()->redirect($_SESSION['photo_return']);
208 return; // NOTREACHED
211 // Check if the user has responded to a delete confirmation query
212 if (!empty($_REQUEST['canceled'])) {
213 DI::baseUrl()->redirect($_SESSION['photo_return']);
216 // RENAME photo album
217 $newalbum = Strings::escapeTags(trim($_POST['albumname']));
218 if ($newalbum != $album) {
219 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
220 DBA::escape($newalbum),
222 intval($page_owner_uid)
224 // Update the photo albums cache
225 Photo::clearAlbumCache($page_owner_uid);
227 DI::baseUrl()->redirect('photos/' . $a->user['nickname'] . '/album/' . bin2hex($newalbum));
228 return; // NOTREACHED
232 * DELETE all photos filed in a given album
234 if (!empty($_POST['dropalbum'])) {
237 // get the list of photos we are about to delete
239 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
241 intval($page_owner_uid),
245 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
246 intval(local_user()),
251 if (DBA::isResult($r)) {
252 foreach ($r as $rr) {
256 // remove the associated photos
257 Photo::delete(['resource-id' => $res, 'uid' => $page_owner_uid]);
259 // find and delete the corresponding item with all the comments and likes/dislikes
260 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
262 // Update the photo albums cache
263 Photo::clearAlbumCache($page_owner_uid);
264 notice(DI::l10n()->t('Album successfully deleted'));
266 notice(DI::l10n()->t('Album was empty.'));
270 DI::baseUrl()->redirect('photos/' . $a->argv[1]);
273 if ($a->argc > 3 && $a->argv[2] === 'image') {
274 // Check if the user has responded to a delete confirmation query for a single photo
275 if (!empty($_POST['canceled'])) {
276 DI::baseUrl()->redirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]);
279 if (!empty($_POST['delete'])) {
280 // same as above but remove single photo
282 $condition = ['contact-id' => $visitor, 'uid' => $page_owner_uid, 'resource-id' => $a->argv[3]];
285 $condition = ['uid' => local_user(), 'resource-id' => $a->argv[3]];
288 $photo = DBA::selectFirst('photo', ['resource-id'], $condition);
290 if (DBA::isResult($photo)) {
291 Photo::delete(['uid' => $page_owner_uid, 'resource-id' => $photo['resource-id']]);
293 Item::deleteForUser(['resource-id' => $photo['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
295 // Update the photo albums cache
296 Photo::clearAlbumCache($page_owner_uid);
297 notice('Successfully deleted the photo.');
299 notice('Failed to delete the photo.');
300 DI::baseUrl()->redirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]);
303 DI::baseUrl()->redirect('photos/' . $a->argv[1]);
304 return; // NOTREACHED
308 if ($a->argc > 2 && (!empty($_POST['desc']) || !empty($_POST['newtag']) || isset($_POST['albname']))) {
309 $desc = !empty($_POST['desc']) ? Strings::escapeTags(trim($_POST['desc'])) : '';
310 $rawtags = !empty($_POST['newtag']) ? Strings::escapeTags(trim($_POST['newtag'])) : '';
311 $item_id = !empty($_POST['item_id']) ? intval($_POST['item_id']) : 0;
312 $albname = !empty($_POST['albname']) ? Strings::escapeTags(trim($_POST['albname'])) : '';
313 $origaname = !empty($_POST['origaname']) ? Strings::escapeTags(trim($_POST['origaname'])) : '';
315 $aclFormatter = DI::aclFormatter();
317 $str_group_allow = !empty($_POST['group_allow']) ? $aclFormatter->toString($_POST['group_allow']) : '';
318 $str_contact_allow = !empty($_POST['contact_allow']) ? $aclFormatter->toString($_POST['contact_allow']) : '';
319 $str_group_deny = !empty($_POST['group_deny']) ? $aclFormatter->toString($_POST['group_deny']) : '';
320 $str_contact_deny = !empty($_POST['contact_deny']) ? $aclFormatter->toString($_POST['contact_deny']) : '';
322 $resource_id = $a->argv[3];
324 if (!strlen($albname)) {
325 $albname = DateTimeFormat::localNow('Y');
328 if (!empty($_POST['rotate']) && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
329 Logger::log('rotate');
331 $photo = Photo::getPhotoForUser($page_owner_uid, $resource_id);
333 if (DBA::isResult($photo)) {
334 $image = Photo::getImageForPhoto($photo);
336 if ($image->isValid()) {
337 $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
338 $image->rotate($rotate_deg);
340 $width = $image->getWidth();
341 $height = $image->getHeight();
343 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 0], $image);
345 if ($width > 640 || $height > 640) {
346 $image->scaleDown(640);
347 $width = $image->getWidth();
348 $height = $image->getHeight();
350 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 1], $image);
353 if ($width > 320 || $height > 320) {
354 $image->scaleDown(320);
355 $width = $image->getWidth();
356 $height = $image->getHeight();
358 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 2], $image);
364 $photos_stmt = DBA::select('photo', [], ['resource-id' => $resource_id, 'uid' => $page_owner_uid], ['order' => ['scale' => true]]);
366 $photos = DBA::toArray($photos_stmt);
368 if (DBA::isResult($photos)) {
370 $ext = $phototypes[$photo['type']];
372 ['desc' => $desc, 'album' => $albname, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow, 'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny],
373 ['resource-id' => $resource_id, 'uid' => $page_owner_uid]
376 // Update the photo albums cache if album name was changed
377 if ($albname !== $origaname) {
378 Photo::clearAlbumCache($page_owner_uid);
380 /* Don't make the item visible if the only change was the album name */
383 if ($photo['desc'] !== $desc || strlen($rawtags)) {
388 if (DBA::isResult($photos) && !$item_id) {
389 // Create item container
391 $uri = Item::newURI($page_owner_uid);
394 $arr['guid'] = System::createUUID();
395 $arr['uid'] = $page_owner_uid;
397 $arr['parent-uri'] = $uri;
398 $arr['post-type'] = Item::PT_IMAGE;
400 $arr['resource-id'] = $photo['resource-id'];
401 $arr['contact-id'] = $owner_record['id'];
402 $arr['owner-name'] = $owner_record['name'];
403 $arr['owner-link'] = $owner_record['url'];
404 $arr['owner-avatar'] = $owner_record['thumb'];
405 $arr['author-name'] = $owner_record['name'];
406 $arr['author-link'] = $owner_record['url'];
407 $arr['author-avatar'] = $owner_record['thumb'];
408 $arr['title'] = $title;
409 $arr['allow_cid'] = $photo['allow_cid'];
410 $arr['allow_gid'] = $photo['allow_gid'];
411 $arr['deny_cid'] = $photo['deny_cid'];
412 $arr['deny_gid'] = $photo['deny_gid'];
413 $arr['visible'] = $visibility;
416 $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $photo['resource-id'] . ']'
417 . '[img]' . DI::baseUrl() . '/photo/' . $photo['resource-id'] . '-' . $photo['scale'] . '.'. $ext . '[/img]'
420 $item_id = Item::insert($arr);
424 $item = Item::selectFirst(['tag', 'inform'], ['id' => $item_id, 'uid' => $page_owner_uid]);
426 if (DBA::isResult($item)) {
427 $old_tag = $item['tag'];
428 $old_inform = $item['inform'];
432 if (strlen($rawtags)) {
436 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
437 $x = substr($rawtags, 0, 1);
438 if ($x !== '@' && $x !== '#') {
439 $rawtags = '#' . $rawtags;
443 $tags = BBCode::getTags($rawtags);
446 foreach ($tags as $tag) {
447 if (strpos($tag, '@') === 0) {
450 $name = substr($tag,1);
452 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
454 $links = @Probe::lrdd($name);
457 foreach ($links as $link) {
458 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
459 $profile = $link['@attributes']['href'];
462 if ($link['@attributes']['rel'] === 'salmon') {
463 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
465 if (strlen($inform)) {
474 $taginfo[] = [$newname, $profile, $salmon];
479 if (strrpos($newname, '+')) {
480 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
484 $contact = DBA::selectFirst('contact', [], ['id' => $tagcid, 'uid' => $page_owner_uid]);
486 $newname = str_replace('_',' ',$name);
488 //select someone from this user's contacts by name
489 $contact = DBA::selectFirst('contact', [], ['name' => $newname, 'uid' => $page_owner_uid]);
490 if (!DBA::isResult($contact)) {
491 //select someone by attag or nick and the name passed in
492 $contact = DBA::selectFirst('contact', [],
493 ['(`attag` = ? OR `nick` = ?) AND `uid` = ?', $name, $name, $page_owner_uid],
494 ['order' => ['attag' => true]]
499 if (DBA::isResult($contact)) {
500 $newname = $contact['name'];
501 $profile = $contact['url'];
503 $notify = 'cid:' . $contact['id'];
504 if (strlen($inform)) {
512 if (!empty($contact)) {
513 $taginfo[] = [$newname, $profile, $notify, $contact, '@[url=' . str_replace(',', '%2c', $profile) . ']' . $newname . '[/url]'];
515 $taginfo[] = [$newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'];
518 if (strlen($str_tags)) {
522 $profile = str_replace(',', '%2c', $profile);
523 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
525 } elseif (strpos($tag, '#') === 0) {
526 $tagname = substr($tag, 1);
527 $str_tags .= '#[url=' . DI::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url],';
532 $newtag = $old_tag ?? '';
533 if (strlen($newtag) && strlen($str_tags)) {
536 $newtag .= $str_tags;
538 $newinform = $old_inform ?? '';
539 if (strlen($newinform) && strlen($inform)) {
542 $newinform .= $inform;
544 $fields = ['tag' => $newtag, 'inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
545 $condition = ['id' => $item_id];
546 Item::update($fields, $condition);
549 foreach ($photos as $scales) {
550 if (intval($scales['scale']) == 2) {
555 if (intval($scales['scale']) == 4) {
561 if (count($taginfo)) {
562 foreach ($taginfo as $tagged) {
563 $uri = Item::newURI($page_owner_uid);
566 $arr['guid'] = System::createUUID();
567 $arr['uid'] = $page_owner_uid;
569 $arr['parent-uri'] = $uri;
571 $arr['contact-id'] = $owner_record['id'];
572 $arr['owner-name'] = $owner_record['name'];
573 $arr['owner-link'] = $owner_record['url'];
574 $arr['owner-avatar'] = $owner_record['thumb'];
575 $arr['author-name'] = $owner_record['name'];
576 $arr['author-link'] = $owner_record['url'];
577 $arr['author-avatar'] = $owner_record['thumb'];
579 $arr['allow_cid'] = $photo['allow_cid'];
580 $arr['allow_gid'] = $photo['allow_gid'];
581 $arr['deny_cid'] = $photo['deny_cid'];
582 $arr['deny_gid'] = $photo['deny_gid'];
584 $arr['verb'] = Activity::TAG;
585 $arr['gravity'] = GRAVITY_PARENT;
586 $arr['object-type'] = Activity\ObjectType::PERSON;
587 $arr['target-type'] = Activity\ObjectType::IMAGE;
588 $arr['tag'] = $tagged[4];
589 $arr['inform'] = $tagged[2];
591 $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]') ;
592 $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" ;
594 $arr['object'] = '<object><type>' . Activity\ObjectType::PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
595 $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
597 $arr['object'] .= XML::escape('<link rel="photo" type="' . $photo['type'] . '" href="' . $tagged[3]['photo'] . '" />' . "\n");
599 $arr['object'] .= '</link></object>' . "\n";
601 $arr['target'] = '<target><type>' . Activity\ObjectType::IMAGE . '</type><title>' . $photo['desc'] . '</title><id>'
602 . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '</id>';
603 $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>';
609 DI::baseUrl()->redirect($_SESSION['photo_return']);
610 return; // NOTREACHED
614 // default post action - upload a photo
615 Hook::callAll('photo_post_init', $_POST);
617 // Determine the album to use
618 $album = !empty($_REQUEST['album']) ? Strings::escapeTags(trim($_REQUEST['album'])) : '';
619 $newalbum = !empty($_REQUEST['newalbum']) ? Strings::escapeTags(trim($_REQUEST['newalbum'])) : '';
621 Logger::log('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , Logger::DEBUG);
623 if (!strlen($album)) {
624 if (strlen($newalbum)) {
627 $album = DateTimeFormat::localNow('Y');
632 * We create a wall item for every photo, but we don't want to
633 * overwhelm the data stream with a hundred newly uploaded photos.
634 * So we will make the first photo uploaded to this album in the last several hours
635 * visible by default, the rest will become visible over time when and if
636 * they acquire comments, likes, dislikes, and/or tags
639 $r = Photo::selectToArray([], ['`album` = ? AND `uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR', $album, $page_owner_uid]);
641 if (!DBA::isResult($r) || ($album == DI::l10n()->t('Profile Photos'))) {
647 if (!empty($_REQUEST['not_visible']) && $_REQUEST['not_visible'] !== 'false') {
651 $group_allow = $_REQUEST['group_allow'] ?? [];
652 $contact_allow = $_REQUEST['contact_allow'] ?? [];
653 $group_deny = $_REQUEST['group_deny'] ?? [];
654 $contact_deny = $_REQUEST['contact_deny'] ?? [];
656 $aclFormatter = DI::aclFormatter();
658 $str_group_allow = $aclFormatter->toString(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
659 $str_contact_allow = $aclFormatter->toString(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
660 $str_group_deny = $aclFormatter->toString(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
661 $str_contact_deny = $aclFormatter->toString(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
663 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
665 Hook::callAll('photo_post_file', $ret);
667 if (!empty($ret['src']) && !empty($ret['filesize'])) {
669 $filename = $ret['filename'];
670 $filesize = $ret['filesize'];
671 $type = $ret['type'];
672 $error = UPLOAD_ERR_OK;
673 } elseif (!empty($_FILES['userfile'])) {
674 $src = $_FILES['userfile']['tmp_name'];
675 $filename = basename($_FILES['userfile']['name']);
676 $filesize = intval($_FILES['userfile']['size']);
677 $type = $_FILES['userfile']['type'];
678 $error = $_FILES['userfile']['error'];
680 $error = UPLOAD_ERR_NO_FILE;
683 if ($error !== UPLOAD_ERR_OK) {
685 case UPLOAD_ERR_INI_SIZE:
686 notice(DI::l10n()->t('Image exceeds size limit of %s', ini_get('upload_max_filesize')) . EOL);
688 case UPLOAD_ERR_FORM_SIZE:
689 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($_REQUEST['MAX_FILE_SIZE'] ?? 0)) . EOL);
691 case UPLOAD_ERR_PARTIAL:
692 notice(DI::l10n()->t('Image upload didn\'t complete, please try again') . EOL);
694 case UPLOAD_ERR_NO_FILE:
695 notice(DI::l10n()->t('Image file is missing') . EOL);
697 case UPLOAD_ERR_NO_TMP_DIR:
698 case UPLOAD_ERR_CANT_WRITE:
699 case UPLOAD_ERR_EXTENSION:
700 notice(DI::l10n()->t('Server can\'t accept new file upload at this time, please contact your administrator') . EOL);
705 Hook::callAll('photo_post_end', $foo);
710 $type = Images::guessType($filename);
713 Logger::log('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', Logger::DEBUG);
715 $maximagesize = DI::config()->get('system', 'maximagesize');
717 if ($maximagesize && ($filesize > $maximagesize)) {
718 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)) . EOL);
721 Hook::callAll('photo_post_end', $foo);
726 notice(DI::l10n()->t('Image file is empty.') . EOL);
729 Hook::callAll('photo_post_end', $foo);
733 Logger::log('mod/photos.php: photos_post(): loading the contents of ' . $src , Logger::DEBUG);
735 $imagedata = @file_get_contents($src);
737 $image = new Image($imagedata, $type);
739 if (!$image->isValid()) {
740 Logger::log('mod/photos.php: photos_post(): unable to process image' , Logger::DEBUG);
741 notice(DI::l10n()->t('Unable to process image.') . EOL);
744 Hook::callAll('photo_post_end',$foo);
748 $exif = $image->orient($src);
751 $max_length = DI::config()->get('system', 'max_image_length');
753 $max_length = MAX_IMAGE_LENGTH;
755 if ($max_length > 0) {
756 $image->scaleDown($max_length);
759 $width = $image->getWidth();
760 $height = $image->getHeight();
764 $resource_id = Photo::newResource();
766 $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);
769 Logger::log('mod/photos.php: photos_post(): image store failed', Logger::DEBUG);
770 notice(DI::l10n()->t('Image upload failed.') . EOL);
774 if ($width > 640 || $height > 640) {
775 $image->scaleDown(640);
776 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);
780 if ($width > 320 || $height > 320) {
781 $image->scaleDown(320);
782 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);
786 $uri = Item::newURI($page_owner_uid);
788 // Create item container
790 if ($exif && $exif['GPS'] && Feature::isEnabled($page_owner_uid, 'photo_location')) {
791 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
792 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
797 $arr['coord'] = $lat . ' ' . $lon;
800 $arr['guid'] = System::createUUID();
801 $arr['uid'] = $page_owner_uid;
803 $arr['parent-uri'] = $uri;
804 $arr['type'] = 'photo';
806 $arr['resource-id'] = $resource_id;
807 $arr['contact-id'] = $owner_record['id'];
808 $arr['owner-name'] = $owner_record['name'];
809 $arr['owner-link'] = $owner_record['url'];
810 $arr['owner-avatar'] = $owner_record['thumb'];
811 $arr['author-name'] = $owner_record['name'];
812 $arr['author-link'] = $owner_record['url'];
813 $arr['author-avatar'] = $owner_record['thumb'];
815 $arr['allow_cid'] = $str_contact_allow;
816 $arr['allow_gid'] = $str_group_allow;
817 $arr['deny_cid'] = $str_contact_deny;
818 $arr['deny_gid'] = $str_group_deny;
819 $arr['visible'] = $visible;
822 $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $resource_id . ']'
823 . '[img]' . DI::baseUrl() . "/photo/{$resource_id}-{$smallest}.".$image->getExt() . '[/img]'
826 $item_id = Item::insert($arr);
827 // Update the photo albums cache
828 Photo::clearAlbumCache($page_owner_uid);
830 Hook::callAll('photo_post_end', $item_id);
832 // addon uploaders should call "exit()" within the photo_post_end hook
833 // if they do not wish to be redirected
835 DI::baseUrl()->redirect($_SESSION['photo_return']);
839 function photos_content(App $a)
843 // photos/name/upload
844 // photos/name/upload/xxxxx (xxxxx is album name)
845 // photos/name/album/xxxxx
846 // photos/name/album/xxxxx/edit
847 // photos/name/album/xxxxx/drop
848 // photos/name/image/xxxxx
849 // photos/name/image/xxxxx/edit
850 // photos/name/image/xxxxx/drop
852 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
853 notice(DI::l10n()->t('Public access denied.') . EOL);
857 if (empty($a->data['user'])) {
858 notice(DI::l10n()->t('No photos selected') . EOL);
862 $phototypes = Images::supportedTypes();
864 $_SESSION['photo_return'] = DI::args()->getCommand();
869 $datatype = $a->argv[2];
870 $datum = $a->argv[3];
871 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
872 $datatype = 'upload';
874 $datatype = 'summary';
883 // Setup permissions structures
887 $remote_contact = false;
892 $owner_uid = $a->data['user']['uid'];
894 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
896 if (local_user() && (local_user() == $owner_uid)) {
898 } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
899 $contact_id = Session::getRemoteContactID($owner_uid);
900 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
902 if (DBA::isResult($contact)) {
904 $remote_contact = true;
905 $visitor = $contact_id;
909 // perhaps they're visiting - but not a community page, so they wouldn't have write access
910 if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
911 $contact_id = Session::getRemoteContactID($owner_uid);
913 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
915 $remote_contact = DBA::isResult($contact);
918 if (!$remote_contact && local_user()) {
919 $contact_id = $_SESSION['cid'];
920 $contact = $a->contact;
923 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
924 notice(DI::l10n()->t('Access to this item is restricted.') . EOL);
928 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
933 $is_owner = (local_user() && (local_user() == $owner_uid));
934 $o .= BaseProfile::getTabsHTML($a, 'photos', $is_owner, $a->data['user']['nickname']);
936 // Display upload form
937 if ($datatype === 'upload') {
939 notice(DI::l10n()->t('Permission denied.'));
943 $selname = Strings::isHex($datum) ? hex2bin($datum) : '';
947 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '><current year></option>';
948 if (!empty($a->data['albums'])) {
949 foreach ($a->data['albums'] as $album) {
950 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === DI::l10n()->t('Contact Photos'))) {
953 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
954 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
960 $ret = ['post_url' => 'photos/' . $a->data['user']['nickname'],
961 'addon_text' => $uploader,
962 'default_upload' => true];
964 Hook::callAll('photo_upload_form',$ret);
966 $default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
967 $default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
968 '$submit' => DI::l10n()->t('Submit'),
973 $tpl = Renderer::getMarkupTemplate('photos_upload.tpl');
975 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML(DI::page(), $a->user));
977 $o .= Renderer::replaceMacros($tpl,[
978 '$pagename' => DI::l10n()->t('Upload Photos'),
979 '$sessid' => session_id(),
980 '$usage' => $usage_message,
981 '$nickname' => $a->data['user']['nickname'],
982 '$newalbum' => DI::l10n()->t('New album name: '),
983 '$existalbumtext' => DI::l10n()->t('or select existing album:'),
984 '$nosharetext' => DI::l10n()->t('Do not show a status post for this upload'),
985 '$albumselect' => $albumselect,
986 '$permissions' => DI::l10n()->t('Permissions'),
987 '$aclselect' => $aclselect_e,
988 '$lockstate' => is_array($a->user)
989 && (strlen($a->user['allow_cid'])
990 || strlen($a->user['allow_gid'])
991 || strlen($a->user['deny_cid'])
992 || strlen($a->user['deny_gid'])
993 ) ? 'lock' : 'unlock',
994 '$alt_uploader' => $ret['addon_text'],
995 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
996 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
997 '$uploadurl' => $ret['post_url'],
999 // ACL permissions box
1000 '$group_perms' => DI::l10n()->t('Show to Groups'),
1001 '$contact_perms' => DI::l10n()->t('Show to Contacts'),
1002 '$return_path' => DI::args()->getQueryString(),
1008 // Display a single photo album
1009 if ($datatype === 'album') {
1010 // if $datum is not a valid hex, redirect to the default page
1011 if (!Strings::isHex($datum)) {
1012 DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname']. '/album');
1014 $album = hex2bin($datum);
1017 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1018 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1022 if (DBA::isResult($r)) {
1026 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
1028 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1029 $order_field = $_GET['order'] ?? '';
1030 if ($order_field === 'posted') {
1036 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1037 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1038 ANY_VALUE(`created`) as `created`
1039 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1040 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1042 DBA::escape($album),
1044 $pager->getItemsPerPage()
1047 if ($cmd === 'drop') {
1048 $drop_url = DI::args()->getQueryString();
1050 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1051 '$method' => 'post',
1052 '$message' => DI::l10n()->t('Do you really want to delete this photo album and all its photos?'),
1053 '$extra_inputs' => [],
1054 '$confirm' => DI::l10n()->t('Delete Album'),
1055 '$confirm_url' => $drop_url,
1056 '$confirm_name' => 'dropalbum',
1057 '$cancel' => DI::l10n()->t('Cancel'),
1062 if ($cmd === 'edit') {
1063 if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== DI::l10n()->t('Contact Photos'))) {
1065 $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
1069 $o .= Renderer::replaceMacros($edit_tpl,[
1070 '$nametext' => DI::l10n()->t('New album name: '),
1071 '$nickname' => $a->data['user']['nickname'],
1072 '$album' => $album_e,
1073 '$hexalbum' => bin2hex($album),
1074 '$submit' => DI::l10n()->t('Submit'),
1075 '$dropsubmit' => DI::l10n()->t('Delete Album')
1080 if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== DI::l10n()->t('Contact Photos')) && $can_post) {
1081 $edit = [DI::l10n()->t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1082 $drop = [DI::l10n()->t('Drop Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/drop'];
1086 if ($order_field === 'posted') {
1087 $order = [DI::l10n()->t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1089 $order = [DI::l10n()->t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?order=posted', 'newest'];
1094 if (DBA::isResult($r)) {
1095 // "Twist" is only used for the duepunto theme with style "slackr"
1097 foreach ($r as $rr) {
1100 $ext = $phototypes[$rr['type']];
1102 $imgalt_e = $rr['filename'];
1103 $desc_e = $rr['desc'];
1107 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1108 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1109 . ($order_field === 'posted' ? '?order=posted' : ''),
1110 'title' => DI::l10n()->t('View Photo'),
1111 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1115 'hash'=> $rr['resource-id'],
1120 $tpl = Renderer::getMarkupTemplate('photo_album.tpl');
1121 $o .= Renderer::replaceMacros($tpl, [
1122 '$photos' => $photos,
1124 '$can_post' => $can_post,
1125 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)],
1129 '$paginate' => $pager->renderFull($total),
1136 // Display one photo
1137 if ($datatype === 'image') {
1138 // fetch image, item containing image, then comments
1139 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1140 $sql_extra ORDER BY `scale` ASC ",
1145 if (!DBA::isResult($ph)) {
1146 if (DBA::exists('photo', ['resource-id' => $datum, 'uid' => $owner_uid])) {
1147 notice(DI::l10n()->t('Permission denied. Access to this item may be restricted.'));
1149 notice(DI::l10n()->t('Photo not available') . EOL);
1154 if ($cmd === 'drop') {
1155 $drop_url = DI::args()->getQueryString();
1157 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1158 '$method' => 'post',
1159 '$message' => DI::l10n()->t('Do you really want to delete this photo?'),
1160 '$extra_inputs' => [],
1161 '$confirm' => DI::l10n()->t('Delete Photo'),
1162 '$confirm_url' => $drop_url,
1163 '$confirm_name' => 'delete',
1164 '$cancel' => DI::l10n()->t('Cancel'),
1172 * @todo This query is totally bad, the whole functionality has to be changed
1173 * The query leads to a really intense used index.
1174 * By now we hide it if someone wants to.
1176 if ($cmd === 'view' && !DI::config()->get('system', 'no_count', false)) {
1177 $order_field = $_GET['order'] ?? '';
1179 if ($order_field === 'posted') {
1185 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1186 $sql_extra ORDER BY `created` $order ",
1187 DBA::escape($ph[0]['album']),
1191 if (DBA::isResult($prvnxt)) {
1194 foreach ($prvnxt as $z => $entry) {
1195 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1199 $prv = count($prvnxt) - 1;
1201 if ($nxt >= count($prvnxt)) {
1208 if (!is_null($prv)) {
1209 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1211 if (!is_null($nxt)) {
1212 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1215 $tpl = Renderer::getMarkupTemplate('photo_edit_head.tpl');
1216 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
1217 '$prevlink' => $prevlink,
1218 '$nextlink' => $nextlink
1222 $prevlink = [$prevlink, '<div class="icon prev"></div>'];
1226 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1231 if (count($ph) == 1) {
1232 $hires = $lores = $ph[0];
1235 if (count($ph) > 1) {
1236 if ($ph[1]['scale'] == 2) {
1237 // original is 640 or less, we can display it directly
1238 $hires = $lores = $ph[0];
1245 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1249 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1251 if ($cmd === 'edit') {
1252 $tools['view'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum, DI::l10n()->t('View photo')];
1254 $tools['edit'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/edit', DI::l10n()->t('Edit photo')];
1255 $tools['delete'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/drop', DI::l10n()->t('Delete photo')];
1256 $tools['profile'] = ['settings/profile/photo/crop/' . $ph[0]['resource-id'], DI::l10n()->t('Use as profile photo')];
1260 $ph[0]['uid'] == local_user()
1261 && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']))
1263 $tools['lock'] = DI::l10n()->t('Private Photo');
1268 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1269 'title'=> DI::l10n()->t('View Full Size'),
1270 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?_u=' . DateTimeFormat::utcNow('ymdhis'),
1271 'height' => $hires['height'],
1272 'width' => $hires['width'],
1273 'album' => $hires['album'],
1274 'filename' => $hires['filename'],
1281 // Do we have an item for this photo?
1283 // FIXME! - replace following code to display the conversation with our normal
1284 // conversation functions so that it works correctly and tracks changes
1285 // in the evolving conversation code.
1286 // The difference is that we won't be displaying the conversation head item
1287 // as a "post" but displaying instead the photo it is linked to
1289 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1290 $linked_items = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1293 if (DBA::isResult($linked_items)) {
1294 // This is a workaround to not being forced to rewrite the while $sql_extra handling
1295 $link_item = Item::selectFirst([], ['id' => $linked_items[0]['id']]);
1298 if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
1299 $condition = ["`parent` = ? AND `parent` != `id`", $link_item['parent']];
1300 $total = DBA::count('item', $condition);
1302 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
1304 $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1305 $result = Item::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params);
1306 $items = Item::inArray($result);
1308 if (local_user() == $link_item['uid']) {
1309 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1313 if (!empty($link_item['coord'])) {
1314 $map = Map::byCoordinates($link_item['coord']);
1319 if (!empty($link_item['id']) && !empty($link_item['tag'])) {
1320 $arr = explode(',', $link_item['tag']);
1321 // parse tags and add links
1323 foreach ($arr as $tag) {
1325 'name' => BBCode::convert($tag),
1326 'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag)
1329 $tags = ['title' => DI::l10n()->t('Tags: '), 'tags' => $tag_arr];
1330 if ($cmd === 'edit') {
1331 $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
1332 $tags['removetitle'] = DI::l10n()->t('[Select tags to remove]');
1338 if ($cmd === 'edit' && $can_post) {
1339 $edit_tpl = Renderer::getMarkupTemplate('photo_edit.tpl');
1341 $album_e = $ph[0]['album'];
1342 $caption_e = $ph[0]['desc'];
1343 $aclselect_e = ACL::getFullSelectorHTML(DI::page(), $a->user, false, ACL::getDefaultUserPermissions($ph[0]));
1345 $edit = Renderer::replaceMacros($edit_tpl, [
1346 '$id' => $ph[0]['id'],
1347 '$album' => ['albname', DI::l10n()->t('New album name'), $album_e,''],
1348 '$caption' => ['desc', DI::l10n()->t('Caption'), $caption_e, ''],
1349 '$tags' => ['newtag', DI::l10n()->t('Add a Tag'), "", DI::l10n()->t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1350 '$rotate_none' => ['rotate', DI::l10n()->t('Do not rotate'),0,'', true],
1351 '$rotate_cw' => ['rotate', DI::l10n()->t("Rotate CW \x28right\x29"),1,''],
1352 '$rotate_ccw' => ['rotate', DI::l10n()->t("Rotate CCW \x28left\x29"),2,''],
1354 '$nickname' => $a->data['user']['nickname'],
1355 '$resource_id' => $ph[0]['resource-id'],
1356 '$permissions' => DI::l10n()->t('Permissions'),
1357 '$aclselect' => $aclselect_e,
1359 '$item_id' => $link_item['id'] ?? 0,
1360 '$submit' => DI::l10n()->t('Submit'),
1361 '$delete' => DI::l10n()->t('Delete Photo'),
1363 // ACL permissions box
1364 '$group_perms' => DI::l10n()->t('Show to Groups'),
1365 '$contact_perms' => DI::l10n()->t('Show to Contacts'),
1366 '$return_path' => DI::args()->getQueryString(),
1377 if (!empty($link_item['id']) && !empty($link_item['uri'])) {
1378 $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
1379 $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
1380 $return_path = DI::args()->getCommand();
1382 if ($cmd === 'view' && ($can_post || Security::canWriteToUserWall($owner_uid))) {
1383 $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl');
1384 $likebuttons = Renderer::replaceMacros($like_tpl, [
1385 '$id' => $link_item['id'],
1386 '$likethis' => DI::l10n()->t("I like this \x28toggle\x29"),
1387 '$dislike' => DI::pConfig()->get(local_user(), 'system', 'hide_dislike') ? '' : DI::l10n()->t("I don't like this \x28toggle\x29"),
1388 '$wait' => DI::l10n()->t('Please wait'),
1389 '$return_path' => DI::args()->getQueryString(),
1393 if (!DBA::isResult($items)) {
1394 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1395 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1396 '$return_path' => '',
1397 '$jsreload' => $return_path,
1398 '$id' => $link_item['id'],
1399 '$parent' => $link_item['id'],
1400 '$profile_uid' => $owner_uid,
1401 '$mylink' => $contact['url'],
1402 '$mytitle' => DI::l10n()->t('This is you'),
1403 '$myphoto' => $contact['thumb'],
1404 '$comment' => DI::l10n()->t('Comment'),
1405 '$submit' => DI::l10n()->t('Submit'),
1406 '$preview' => DI::l10n()->t('Preview'),
1407 '$loading' => DI::l10n()->t('Loading...'),
1408 '$sourceapp' => DI::l10n()->t($a->sourcename),
1410 '$rand_num' => Crypto::randomDigits(12)
1416 'like' => ['title' => DI::l10n()->t('Likes','title')],
1417 'dislike' => ['title' => DI::l10n()->t('Dislikes','title')],
1418 'attendyes' => ['title' => DI::l10n()->t('Attending','title')],
1419 'attendno' => ['title' => DI::l10n()->t('Not attending','title')],
1420 'attendmaybe' => ['title' => DI::l10n()->t('Might attend','title')]
1423 if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
1424 unset($conv_responses['dislike']);
1428 if (DBA::isResult($items)) {
1429 foreach ($items as $item) {
1430 builtin_activity_puller($item, $conv_responses);
1433 if (!empty($conv_responses['like'][$link_item['uri']])) {
1434 $like = format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like', $link_item['id']);
1437 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1438 $dislike = format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike', $link_item['id']);
1441 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1442 $comments .= Renderer::replaceMacros($cmnt_tpl,[
1443 '$return_path' => '',
1444 '$jsreload' => $return_path,
1445 '$id' => $link_item['id'],
1446 '$parent' => $link_item['id'],
1447 '$profile_uid' => $owner_uid,
1448 '$mylink' => $contact['url'],
1449 '$mytitle' => DI::l10n()->t('This is you'),
1450 '$myphoto' => $contact['thumb'],
1451 '$comment' => DI::l10n()->t('Comment'),
1452 '$submit' => DI::l10n()->t('Submit'),
1453 '$preview' => DI::l10n()->t('Preview'),
1454 '$sourceapp' => DI::l10n()->t($a->sourcename),
1456 '$rand_num' => Crypto::randomDigits(12)
1460 foreach ($items as $item) {
1465 $activity = DI::activity();
1467 if (($activity->match($item['verb'], Activity::LIKE) ||
1468 $activity->match($item['verb'], Activity::DISLIKE)) &&
1469 ($item['id'] != $item['parent'])) {
1473 $profile_url = Contact::magicLinkbyId($item['author-id']);
1474 if (strpos($profile_url, 'redir/') === 0) {
1475 $sparkle = ' sparkle';
1480 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1482 'dropping' => $dropping,
1483 'pagedrop' => false,
1484 'select' => DI::l10n()->t('Select'),
1485 'delete' => DI::l10n()->t('Delete'),
1488 $title_e = $item['title'];
1489 $body_e = BBCode::convert($item['body']);
1491 $comments .= Renderer::replaceMacros($template,[
1492 '$id' => $item['id'],
1493 '$profile_url' => $profile_url,
1494 '$name' => $item['author-name'],
1495 '$thumb' => $item['author-avatar'],
1496 '$sparkle' => $sparkle,
1497 '$title' => $title_e,
1499 '$ago' => Temporal::getRelativeDate($item['created']),
1500 '$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''),
1502 '$comment' => $comment
1505 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1506 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1507 '$return_path' => '',
1508 '$jsreload' => $return_path,
1509 '$id' => $item['id'],
1510 '$parent' => $item['parent'],
1511 '$profile_uid' => $owner_uid,
1512 '$mylink' => $contact['url'],
1513 '$mytitle' => DI::l10n()->t('This is you'),
1514 '$myphoto' => $contact['thumb'],
1515 '$comment' => DI::l10n()->t('Comment'),
1516 '$submit' => DI::l10n()->t('Submit'),
1517 '$preview' => DI::l10n()->t('Preview'),
1518 '$sourceapp' => DI::l10n()->t($a->sourcename),
1520 '$rand_num' => Crypto::randomDigits(12)
1526 $responses = get_responses($conv_responses, ['like', 'dislike'], $link_item);
1528 $paginate = $pager->renderFull($total);
1531 $photo_tpl = Renderer::getMarkupTemplate('photo_view.tpl');
1532 $o .= Renderer::replaceMacros($photo_tpl, [
1533 '$id' => $ph[0]['id'],
1534 '$album' => [$album_link, $ph[0]['album']],
1537 '$prevlink' => $prevlink,
1538 '$nextlink' => $nextlink,
1539 '$desc' => $ph[0]['desc'],
1543 '$map_text' => DI::l10n()->t('Map'),
1544 '$likebuttons' => $likebuttons,
1546 '$dislike' => $dislike,
1547 'responses' => $responses,
1548 '$comments' => $comments,
1549 '$paginate' => $paginate,
1552 DI::page()['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
1553 DI::page()['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1554 DI::page()['htmlhead'] .= '<meta name="twitter:image" content="' . DI::baseUrl() . "/" . $photo["href"] . '" />' . "\n";
1555 DI::page()['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1556 DI::page()['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1561 // Default - show recent photos with upload link (if applicable)
1564 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1565 $sql_extra GROUP BY `resource-id`",
1566 intval($a->data['user']['uid']),
1567 DBA::escape('Contact Photos'),
1568 DBA::escape(DI::l10n()->t('Contact Photos'))
1570 if (DBA::isResult($r)) {
1574 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
1576 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1577 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1578 ANY_VALUE(`created`) AS `created` FROM `photo`
1579 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1580 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1581 intval($a->data['user']['uid']),
1582 DBA::escape('Contact Photos'),
1583 DBA::escape(DI::l10n()->t('Contact Photos')),
1585 $pager->getItemsPerPage()
1589 if (DBA::isResult($r)) {
1590 // "Twist" is only used for the duepunto theme with style "slackr"
1592 foreach ($r as $rr) {
1593 //hide profile photos to others
1594 if (!$is_owner && !Session::getRemoteContactID($owner_uid) && ($rr['album'] == DI::l10n()->t('Profile Photos'))) {
1599 $ext = $phototypes[$rr['type']];
1601 $alt_e = $rr['filename'];
1602 $name_e = $rr['album'];
1606 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1607 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1608 'title' => DI::l10n()->t('View Photo'),
1609 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1612 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1614 'alt' => DI::l10n()->t('View Album'),
1621 $tpl = Renderer::getMarkupTemplate('photos_recent.tpl');
1622 $o .= Renderer::replaceMacros($tpl, [
1623 '$title' => DI::l10n()->t('Recent Photos'),
1624 '$can_post' => $can_post,
1625 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'],
1626 '$photos' => $photos,
1627 '$paginate' => $pager->renderFull($total),