3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 use Friendica\Content\Feature;
24 use Friendica\Content\Nav;
25 use Friendica\Content\Pager;
26 use Friendica\Content\Text\BBCode;
27 use Friendica\Core\ACL;
28 use Friendica\Core\Hook;
29 use Friendica\Core\Logger;
30 use Friendica\Core\Renderer;
31 use Friendica\Core\Session;
32 use Friendica\Core\System;
33 use Friendica\Database\DBA;
35 use Friendica\Model\Contact;
36 use Friendica\Model\Item;
37 use Friendica\Model\Photo;
38 use Friendica\Model\Profile;
39 use Friendica\Model\Tag;
40 use Friendica\Model\User;
41 use Friendica\Module\BaseProfile;
42 use Friendica\Network\Probe;
43 use Friendica\Object\Image;
44 use Friendica\Protocol\Activity;
45 use Friendica\Util\Crypto;
46 use Friendica\Util\DateTimeFormat;
47 use Friendica\Util\Images;
48 use Friendica\Util\Map;
49 use Friendica\Util\Security;
50 use Friendica\Util\Strings;
51 use Friendica\Util\Temporal;
52 use Friendica\Util\XML;
54 function photos_init(App $a) {
56 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
60 Nav::setSelected('home');
64 $user = DBA::selectFirst('user', [], ['nickname' => $nick, 'blocked' => false]);
66 if (!DBA::isResult($user)) {
70 $a->data['user'] = $user;
71 $a->profile_uid = $user['uid'];
72 $is_owner = (local_user() && (local_user() == $a->profile_uid));
74 $profile = Profile::getByNickname($nick, $a->profile_uid);
76 $account_type = Contact::getAccountType($profile);
78 $tpl = Renderer::getMarkupTemplate('widget/vcard.tpl');
80 $vcard_widget = Renderer::replaceMacros($tpl, [
81 '$name' => $profile['name'],
82 '$photo' => $profile['photo'],
83 '$addr' => $profile['addr'] ?? '',
84 '$account_type' => $account_type,
85 '$about' => BBCode::convert($profile['about']),
88 $albums = Photo::getAlbums($a->data['user']['uid']);
90 $albums_visible = ((intval($a->data['user']['hidewall']) && !Session::isAuthenticated()) ? false : true);
92 // add various encodings to the array so we can just loop through and pick them out in a template
93 $ret = ['success' => false];
96 $a->data['albums'] = $albums;
98 if ($albums_visible) {
99 $ret['success'] = true;
103 foreach ($albums as $k => $album) {
104 //hide profile photos to others
105 if (!$is_owner && !Session::getRemoteContactID($a->profile_uid) && ($album['album'] == DI::l10n()->t('Profile Photos')))
108 'text' => $album['album'],
109 'total' => $album['total'],
110 'url' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
111 'urlencode' => urlencode($album['album']),
112 'bin2hex' => bin2hex($album['album'])
114 $ret['albums'][] = $entry;
118 if (local_user() && $a->data['user']['uid'] == local_user()) {
124 if ($ret['success']) {
125 $photo_albums_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('photo_albums.tpl'), [
126 '$nick' => $a->data['user']['nickname'],
127 '$title' => DI::l10n()->t('Photo Albums'),
128 '$recent' => DI::l10n()->t('Recent Photos'),
129 '$albums' => $ret['albums'],
130 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'],
131 '$can_post' => $can_post
135 if (empty(DI::page()['aside'])) {
136 DI::page()['aside'] = '';
139 DI::page()['aside'] .= $vcard_widget;
141 if (!empty($photo_albums_widget)) {
142 DI::page()['aside'] .= $photo_albums_widget;
145 $tpl = Renderer::getMarkupTemplate("photos_head.tpl");
147 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
148 '$ispublic' => DI::l10n()->t('everybody')
155 function photos_post(App $a)
157 Logger::log('mod-photos: photos_post: begin' , Logger::DEBUG);
158 Logger::log('mod_photos: REQUEST ' . print_r($_REQUEST, true), Logger::DATA);
159 Logger::log('mod_photos: FILES ' . print_r($_FILES, true), Logger::DATA);
161 $phototypes = Images::supportedTypes();
166 $page_owner_uid = intval($a->data['user']['uid']);
167 $community_page = $a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
169 if (local_user() && (local_user() == $page_owner_uid)) {
171 } elseif ($community_page && !empty(Session::getRemoteContactID($page_owner_uid))) {
172 $contact_id = Session::getRemoteContactID($page_owner_uid);
174 $visitor = $contact_id;
178 notice(DI::l10n()->t('Permission denied.'));
182 $owner_record = User::getOwnerDataById($page_owner_uid);
184 if (!$owner_record) {
185 notice(DI::l10n()->t('Contact information unavailable'));
186 Logger::log('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
190 if ($a->argc > 3 && $a->argv[2] === 'album') {
191 if (!Strings::isHex($a->argv[3])) {
192 DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname'] . '/album');
194 $album = hex2bin($a->argv[3]);
196 if ($album === DI::l10n()->t('Profile Photos') || $album === Photo::CONTACT_PHOTOS || $album === DI::l10n()->t(Photo::CONTACT_PHOTOS)) {
197 DI::baseUrl()->redirect($_SESSION['photo_return']);
198 return; // NOTREACHED
201 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
203 intval($page_owner_uid)
206 if (!DBA::isResult($r)) {
207 notice(DI::l10n()->t('Album not found.'));
208 DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname'] . '/album');
209 return; // NOTREACHED
212 // Check if the user has responded to a delete confirmation query
213 if (!empty($_REQUEST['canceled'])) {
214 DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname'] . '/album/' . $a->argv[3]);
217 // RENAME photo album
218 $newalbum = Strings::escapeTags(trim($_POST['albumname']));
219 if ($newalbum != $album) {
220 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
221 DBA::escape($newalbum),
223 intval($page_owner_uid)
225 // Update the photo albums cache
226 Photo::clearAlbumCache($page_owner_uid);
228 DI::baseUrl()->redirect('photos/' . $a->user['nickname'] . '/album/' . bin2hex($newalbum));
229 return; // NOTREACHED
233 * DELETE all photos filed in a given album
235 if (!empty($_POST['dropalbum'])) {
238 // get the list of photos we are about to delete
240 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
242 intval($page_owner_uid),
246 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
247 intval(local_user()),
252 if (DBA::isResult($r)) {
253 foreach ($r as $rr) {
257 // remove the associated photos
258 Photo::delete(['resource-id' => $res, 'uid' => $page_owner_uid]);
260 // find and delete the corresponding item with all the comments and likes/dislikes
261 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
263 // Update the photo albums cache
264 Photo::clearAlbumCache($page_owner_uid);
265 notice(DI::l10n()->t('Album successfully deleted'));
267 notice(DI::l10n()->t('Album was empty.'));
271 DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname'] . '/album');
274 if ($a->argc > 3 && $a->argv[2] === 'image') {
275 // Check if the user has responded to a delete confirmation query for a single photo
276 if (!empty($_POST['canceled'])) {
277 DI::baseUrl()->redirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]);
280 if (!empty($_POST['delete'])) {
281 // same as above but remove single photo
283 $condition = ['contact-id' => $visitor, 'uid' => $page_owner_uid, 'resource-id' => $a->argv[3]];
286 $condition = ['uid' => local_user(), 'resource-id' => $a->argv[3]];
289 $photo = DBA::selectFirst('photo', ['resource-id'], $condition);
291 if (DBA::isResult($photo)) {
292 Photo::delete(['uid' => $page_owner_uid, 'resource-id' => $photo['resource-id']]);
294 Item::deleteForUser(['resource-id' => $photo['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
296 // Update the photo albums cache
297 Photo::clearAlbumCache($page_owner_uid);
299 notice(DI::l10n()->t('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']) ? 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', 'uri-id'], ['id' => $item_id, 'uid' => $page_owner_uid]);
426 if (DBA::isResult($item)) {
427 $old_inform = $item['inform'];
431 if (strlen($rawtags)) {
434 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
435 $x = substr($rawtags, 0, 1);
436 if ($x !== '@' && $x !== '#') {
437 $rawtags = '#' . $rawtags;
441 $tags = BBCode::getTags($rawtags);
444 foreach ($tags as $tag) {
445 if (strpos($tag, '@') === 0) {
448 $name = substr($tag,1);
450 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
452 $links = @Probe::lrdd($name);
455 foreach ($links as $link) {
456 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
457 $profile = $link['@attributes']['href'];
460 if ($link['@attributes']['rel'] === 'salmon') {
461 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
463 if (strlen($inform)) {
472 $taginfo[] = [$newname, $profile, $salmon];
477 if (strrpos($newname, '+')) {
478 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
482 $contact = DBA::selectFirst('contact', [], ['id' => $tagcid, 'uid' => $page_owner_uid]);
484 $newname = str_replace('_',' ',$name);
486 //select someone from this user's contacts by name
487 $contact = DBA::selectFirst('contact', [], ['name' => $newname, 'uid' => $page_owner_uid]);
488 if (!DBA::isResult($contact)) {
489 //select someone by attag or nick and the name passed in
490 $contact = DBA::selectFirst('contact', [],
491 ['(`attag` = ? OR `nick` = ?) AND `uid` = ?', $name, $name, $page_owner_uid],
492 ['order' => ['attag' => true]]
497 if (DBA::isResult($contact)) {
498 $newname = $contact['name'];
499 $profile = $contact['url'];
501 $notify = 'cid:' . $contact['id'];
502 if (strlen($inform)) {
510 if (!empty($contact)) {
511 $taginfo[] = [$newname, $profile, $notify, $contact];
513 $taginfo[] = [$newname, $profile, $notify, null];
516 $profile = str_replace(',', '%2c', $profile);
518 if (!empty($item['uri-id'])) {
519 Tag::store($item['uri-id'], Tag::MENTION, $newname, $profile);
522 } elseif (strpos($tag, '#') === 0) {
523 $tagname = substr($tag, 1);
524 if (!empty($item['uri-id'])) {
525 Tag::store($item['uri-id'], Tag::HASHTAG, $tagname);
531 $newinform = $old_inform ?? '';
532 if (strlen($newinform) && strlen($inform)) {
535 $newinform .= $inform;
537 $fields = ['inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
538 $condition = ['id' => $item_id];
539 Item::update($fields, $condition);
542 foreach ($photos as $scales) {
543 if (intval($scales['scale']) == 2) {
548 if (intval($scales['scale']) == 4) {
554 if (count($taginfo)) {
555 foreach ($taginfo as $tagged) {
556 $uri = Item::newURI($page_owner_uid);
559 $arr['guid'] = System::createUUID();
560 $arr['uid'] = $page_owner_uid;
562 $arr['parent-uri'] = $uri;
564 $arr['contact-id'] = $owner_record['id'];
565 $arr['owner-name'] = $owner_record['name'];
566 $arr['owner-link'] = $owner_record['url'];
567 $arr['owner-avatar'] = $owner_record['thumb'];
568 $arr['author-name'] = $owner_record['name'];
569 $arr['author-link'] = $owner_record['url'];
570 $arr['author-avatar'] = $owner_record['thumb'];
572 $arr['allow_cid'] = $photo['allow_cid'];
573 $arr['allow_gid'] = $photo['allow_gid'];
574 $arr['deny_cid'] = $photo['deny_cid'];
575 $arr['deny_gid'] = $photo['deny_gid'];
577 $arr['verb'] = Activity::TAG;
578 $arr['gravity'] = GRAVITY_PARENT;
579 $arr['object-type'] = Activity\ObjectType::PERSON;
580 $arr['target-type'] = Activity\ObjectType::IMAGE;
581 $arr['inform'] = $tagged[2];
583 $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]') ;
584 $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" ;
586 $arr['object'] = '<object><type>' . Activity\ObjectType::PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
587 $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
589 $arr['object'] .= XML::escape('<link rel="photo" type="' . $photo['type'] . '" href="' . $tagged[3]['photo'] . '" />' . "\n");
591 $arr['object'] .= '</link></object>' . "\n";
593 $arr['target'] = '<target><type>' . Activity\ObjectType::IMAGE . '</type><title>' . $photo['desc'] . '</title><id>'
594 . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '</id>';
595 $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>';
601 DI::baseUrl()->redirect($_SESSION['photo_return']);
602 return; // NOTREACHED
606 // default post action - upload a photo
607 Hook::callAll('photo_post_init', $_POST);
609 // Determine the album to use
610 $album = trim($_REQUEST['album'] ?? '');
611 $newalbum = trim($_REQUEST['newalbum'] ?? '');
613 Logger::info('album= ' . $album . ' newalbum= ' . $newalbum);
615 if (!strlen($album)) {
616 if (strlen($newalbum)) {
619 $album = DateTimeFormat::localNow('Y');
624 * We create a wall item for every photo, but we don't want to
625 * overwhelm the data stream with a hundred newly uploaded photos.
626 * So we will make the first photo uploaded to this album in the last several hours
627 * visible by default, the rest will become visible over time when and if
628 * they acquire comments, likes, dislikes, and/or tags
631 $r = Photo::selectToArray([], ['`album` = ? AND `uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR', $album, $page_owner_uid]);
633 if (!DBA::isResult($r) || ($album == DI::l10n()->t('Profile Photos'))) {
639 if (!empty($_REQUEST['not_visible']) && $_REQUEST['not_visible'] !== 'false') {
643 $group_allow = $_REQUEST['group_allow'] ?? [];
644 $contact_allow = $_REQUEST['contact_allow'] ?? [];
645 $group_deny = $_REQUEST['group_deny'] ?? [];
646 $contact_deny = $_REQUEST['contact_deny'] ?? [];
648 $aclFormatter = DI::aclFormatter();
650 $str_group_allow = $aclFormatter->toString(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
651 $str_contact_allow = $aclFormatter->toString(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
652 $str_group_deny = $aclFormatter->toString(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
653 $str_contact_deny = $aclFormatter->toString(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
655 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
657 Hook::callAll('photo_post_file', $ret);
659 if (!empty($ret['src']) && !empty($ret['filesize'])) {
661 $filename = $ret['filename'];
662 $filesize = $ret['filesize'];
663 $type = $ret['type'];
664 $error = UPLOAD_ERR_OK;
665 } elseif (!empty($_FILES['userfile'])) {
666 $src = $_FILES['userfile']['tmp_name'];
667 $filename = basename($_FILES['userfile']['name']);
668 $filesize = intval($_FILES['userfile']['size']);
669 $type = $_FILES['userfile']['type'];
670 $error = $_FILES['userfile']['error'];
672 $error = UPLOAD_ERR_NO_FILE;
675 if ($error !== UPLOAD_ERR_OK) {
677 case UPLOAD_ERR_INI_SIZE:
678 notice(DI::l10n()->t('Image exceeds size limit of %s', ini_get('upload_max_filesize')));
680 case UPLOAD_ERR_FORM_SIZE:
681 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($_REQUEST['MAX_FILE_SIZE'] ?? 0)));
683 case UPLOAD_ERR_PARTIAL:
684 notice(DI::l10n()->t('Image upload didn\'t complete, please try again'));
686 case UPLOAD_ERR_NO_FILE:
687 notice(DI::l10n()->t('Image file is missing'));
689 case UPLOAD_ERR_NO_TMP_DIR:
690 case UPLOAD_ERR_CANT_WRITE:
691 case UPLOAD_ERR_EXTENSION:
692 notice(DI::l10n()->t('Server can\'t accept new file upload at this time, please contact your administrator'));
697 Hook::callAll('photo_post_end', $foo);
701 $type = Images::getMimeTypeBySource($src, $filename, $type);
703 Logger::log('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', Logger::DEBUG);
705 $maximagesize = DI::config()->get('system', 'maximagesize');
707 if ($maximagesize && ($filesize > $maximagesize)) {
708 notice(DI::l10n()->t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)));
711 Hook::callAll('photo_post_end', $foo);
716 notice(DI::l10n()->t('Image file is empty.'));
719 Hook::callAll('photo_post_end', $foo);
723 Logger::log('mod/photos.php: photos_post(): loading the contents of ' . $src , Logger::DEBUG);
725 $imagedata = @file_get_contents($src);
727 $image = new Image($imagedata, $type);
729 if (!$image->isValid()) {
730 Logger::log('mod/photos.php: photos_post(): unable to process image' , Logger::DEBUG);
731 notice(DI::l10n()->t('Unable to process image.'));
734 Hook::callAll('photo_post_end',$foo);
738 $exif = $image->orient($src);
741 $max_length = DI::config()->get('system', 'max_image_length');
743 $max_length = MAX_IMAGE_LENGTH;
745 if ($max_length > 0) {
746 $image->scaleDown($max_length);
749 $width = $image->getWidth();
750 $height = $image->getHeight();
754 $resource_id = Photo::newResource();
756 $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);
759 Logger::log('mod/photos.php: photos_post(): image store failed', Logger::DEBUG);
760 notice(DI::l10n()->t('Image upload failed.'));
764 if ($width > 640 || $height > 640) {
765 $image->scaleDown(640);
766 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);
770 if ($width > 320 || $height > 320) {
771 $image->scaleDown(320);
772 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);
776 $uri = Item::newURI($page_owner_uid);
778 // Create item container
780 if (!empty($exif['GPS']) && Feature::isEnabled($page_owner_uid, 'photo_location')) {
781 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
782 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
787 $arr['coord'] = $lat . ' ' . $lon;
790 $arr['guid'] = System::createUUID();
791 $arr['uid'] = $page_owner_uid;
793 $arr['parent-uri'] = $uri;
794 $arr['type'] = 'photo';
796 $arr['resource-id'] = $resource_id;
797 $arr['contact-id'] = $owner_record['id'];
798 $arr['owner-name'] = $owner_record['name'];
799 $arr['owner-link'] = $owner_record['url'];
800 $arr['owner-avatar'] = $owner_record['thumb'];
801 $arr['author-name'] = $owner_record['name'];
802 $arr['author-link'] = $owner_record['url'];
803 $arr['author-avatar'] = $owner_record['thumb'];
805 $arr['allow_cid'] = $str_contact_allow;
806 $arr['allow_gid'] = $str_group_allow;
807 $arr['deny_cid'] = $str_contact_deny;
808 $arr['deny_gid'] = $str_group_deny;
809 $arr['visible'] = $visible;
812 $arr['body'] = '[url=' . DI::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $resource_id . ']'
813 . '[img]' . DI::baseUrl() . "/photo/{$resource_id}-{$smallest}.".$image->getExt() . '[/img]'
816 $item_id = Item::insert($arr);
817 // Update the photo albums cache
818 Photo::clearAlbumCache($page_owner_uid);
820 Hook::callAll('photo_post_end', $item_id);
822 // addon uploaders should call "exit()" within the photo_post_end hook
823 // if they do not wish to be redirected
825 DI::baseUrl()->redirect($_SESSION['photo_return']);
829 function photos_content(App $a)
833 // photos/name/upload
834 // photos/name/upload/xxxxx (xxxxx is album name)
835 // photos/name/album/xxxxx
836 // photos/name/album/xxxxx/edit
837 // photos/name/album/xxxxx/drop
838 // photos/name/image/xxxxx
839 // photos/name/image/xxxxx/edit
840 // photos/name/image/xxxxx/drop
842 if (DI::config()->get('system', 'block_public') && !Session::isAuthenticated()) {
843 notice(DI::l10n()->t('Public access denied.'));
847 if (empty($a->data['user'])) {
848 notice(DI::l10n()->t('No photos selected'));
852 $phototypes = Images::supportedTypes();
854 $_SESSION['photo_return'] = DI::args()->getCommand();
859 $datatype = $a->argv[2];
860 $datum = $a->argv[3];
861 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
862 $datatype = 'upload';
864 $datatype = 'summary';
873 // Setup permissions structures
877 $remote_contact = false;
882 $owner_uid = $a->data['user']['uid'];
884 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
886 if (local_user() && (local_user() == $owner_uid)) {
888 } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
889 $contact_id = Session::getRemoteContactID($owner_uid);
890 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
892 if (DBA::isResult($contact)) {
894 $remote_contact = true;
895 $visitor = $contact_id;
899 // perhaps they're visiting - but not a community page, so they wouldn't have write access
900 if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
901 $contact_id = Session::getRemoteContactID($owner_uid);
903 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
905 $remote_contact = DBA::isResult($contact);
908 if (!$remote_contact && local_user()) {
909 $contact_id = $_SESSION['cid'];
910 $contact = $a->contact;
913 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
914 notice(DI::l10n()->t('Access to this item is restricted.'));
918 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
923 $is_owner = (local_user() && (local_user() == $owner_uid));
924 $o .= BaseProfile::getTabsHTML($a, 'photos', $is_owner, $a->data['user']['nickname']);
926 // Display upload form
927 if ($datatype === 'upload') {
929 notice(DI::l10n()->t('Permission denied.'));
933 $selname = Strings::isHex($datum) ? hex2bin($datum) : '';
937 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '><current year></option>';
938 if (!empty($a->data['albums'])) {
939 foreach ($a->data['albums'] as $album) {
940 if (($album['album'] === '') || ($album['album'] === Photo::CONTACT_PHOTOS) || ($album['album'] === DI::l10n()->t(Photo::CONTACT_PHOTOS))) {
943 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
944 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
950 $ret = ['post_url' => 'photos/' . $a->data['user']['nickname'],
951 'addon_text' => $uploader,
952 'default_upload' => true];
954 Hook::callAll('photo_upload_form',$ret);
956 $default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
957 $default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
958 '$submit' => DI::l10n()->t('Submit'),
963 $tpl = Renderer::getMarkupTemplate('photos_upload.tpl');
965 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML(DI::page(), $a->user));
967 $o .= Renderer::replaceMacros($tpl,[
968 '$pagename' => DI::l10n()->t('Upload Photos'),
969 '$sessid' => session_id(),
970 '$usage' => $usage_message,
971 '$nickname' => $a->data['user']['nickname'],
972 '$newalbum' => DI::l10n()->t('New album name: '),
973 '$existalbumtext' => DI::l10n()->t('or select existing album:'),
974 '$nosharetext' => DI::l10n()->t('Do not show a status post for this upload'),
975 '$albumselect' => $albumselect,
976 '$permissions' => DI::l10n()->t('Permissions'),
977 '$aclselect' => $aclselect_e,
978 '$lockstate' => is_array($a->user)
979 && (strlen($a->user['allow_cid'])
980 || strlen($a->user['allow_gid'])
981 || strlen($a->user['deny_cid'])
982 || strlen($a->user['deny_gid'])
983 ) ? 'lock' : 'unlock',
984 '$alt_uploader' => $ret['addon_text'],
985 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
986 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
987 '$uploadurl' => $ret['post_url'],
989 // ACL permissions box
990 '$group_perms' => DI::l10n()->t('Show to Groups'),
991 '$contact_perms' => DI::l10n()->t('Show to Contacts'),
992 '$return_path' => DI::args()->getQueryString(),
998 // Display a single photo album
999 if ($datatype === 'album') {
1000 // if $datum is not a valid hex, redirect to the default page
1001 if (!Strings::isHex($datum)) {
1002 DI::baseUrl()->redirect('photos/' . $a->data['user']['nickname']. '/album');
1004 $album = hex2bin($datum);
1007 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1008 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1012 if (DBA::isResult($r)) {
1016 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
1018 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1019 $order_field = $_GET['order'] ?? '';
1020 if ($order_field === 'posted') {
1026 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1027 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1028 ANY_VALUE(`created`) as `created`
1029 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1030 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1032 DBA::escape($album),
1034 $pager->getItemsPerPage()
1037 if ($cmd === 'drop') {
1038 $drop_url = DI::args()->getQueryString();
1040 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1041 '$method' => 'post',
1042 '$message' => DI::l10n()->t('Do you really want to delete this photo album and all its photos?'),
1043 '$extra_inputs' => [],
1044 '$confirm' => DI::l10n()->t('Delete Album'),
1045 '$confirm_url' => $drop_url,
1046 '$confirm_name' => 'dropalbum',
1047 '$cancel' => DI::l10n()->t('Cancel'),
1052 if ($cmd === 'edit') {
1053 if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS))) {
1055 $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
1059 $o .= Renderer::replaceMacros($edit_tpl,[
1060 '$nametext' => DI::l10n()->t('New album name: '),
1061 '$nickname' => $a->data['user']['nickname'],
1062 '$album' => $album_e,
1063 '$hexalbum' => bin2hex($album),
1064 '$submit' => DI::l10n()->t('Submit'),
1065 '$dropsubmit' => DI::l10n()->t('Delete Album')
1070 if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS)) && $can_post) {
1071 $edit = [DI::l10n()->t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1072 $drop = [DI::l10n()->t('Drop Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/drop'];
1076 if ($order_field === 'posted') {
1077 $order = [DI::l10n()->t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1079 $order = [DI::l10n()->t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?order=posted', 'newest'];
1084 if (DBA::isResult($r)) {
1085 // "Twist" is only used for the duepunto theme with style "slackr"
1087 foreach ($r as $rr) {
1090 $ext = $phototypes[$rr['type']];
1092 $imgalt_e = $rr['filename'];
1093 $desc_e = $rr['desc'];
1097 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1098 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1099 . ($order_field === 'posted' ? '?order=posted' : ''),
1100 'title' => DI::l10n()->t('View Photo'),
1101 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1105 'hash'=> $rr['resource-id'],
1110 $tpl = Renderer::getMarkupTemplate('photo_album.tpl');
1111 $o .= Renderer::replaceMacros($tpl, [
1112 '$photos' => $photos,
1114 '$can_post' => $can_post,
1115 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)],
1119 '$paginate' => $pager->renderFull($total),
1126 // Display one photo
1127 if ($datatype === 'image') {
1128 // fetch image, item containing image, then comments
1129 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1130 $sql_extra ORDER BY `scale` ASC ",
1135 if (!DBA::isResult($ph)) {
1136 if (DBA::exists('photo', ['resource-id' => $datum, 'uid' => $owner_uid])) {
1137 notice(DI::l10n()->t('Permission denied. Access to this item may be restricted.'));
1139 notice(DI::l10n()->t('Photo not available'));
1144 if ($cmd === 'drop') {
1145 $drop_url = DI::args()->getQueryString();
1147 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1148 '$method' => 'post',
1149 '$message' => DI::l10n()->t('Do you really want to delete this photo?'),
1150 '$extra_inputs' => [],
1151 '$confirm' => DI::l10n()->t('Delete Photo'),
1152 '$confirm_url' => $drop_url,
1153 '$confirm_name' => 'delete',
1154 '$cancel' => DI::l10n()->t('Cancel'),
1162 * @todo This query is totally bad, the whole functionality has to be changed
1163 * The query leads to a really intense used index.
1164 * By now we hide it if someone wants to.
1166 if ($cmd === 'view' && !DI::config()->get('system', 'no_count', false)) {
1167 $order_field = $_GET['order'] ?? '';
1169 if ($order_field === 'posted') {
1175 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1176 $sql_extra ORDER BY `created` $order ",
1177 DBA::escape($ph[0]['album']),
1181 if (DBA::isResult($prvnxt)) {
1184 foreach ($prvnxt as $z => $entry) {
1185 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1189 $prv = count($prvnxt) - 1;
1191 if ($nxt >= count($prvnxt)) {
1198 if (!is_null($prv)) {
1199 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1201 if (!is_null($nxt)) {
1202 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . ($order_field === 'posted' ? '?order=posted' : '');
1205 $tpl = Renderer::getMarkupTemplate('photo_edit_head.tpl');
1206 DI::page()['htmlhead'] .= Renderer::replaceMacros($tpl,[
1207 '$prevlink' => $prevlink,
1208 '$nextlink' => $nextlink
1212 $prevlink = [$prevlink, '<div class="icon prev"></div>'];
1216 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1221 if (count($ph) == 1) {
1222 $hires = $lores = $ph[0];
1225 if (count($ph) > 1) {
1226 if ($ph[1]['scale'] == 2) {
1227 // original is 640 or less, we can display it directly
1228 $hires = $lores = $ph[0];
1235 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1239 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1241 if ($cmd === 'edit') {
1242 $tools['view'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum, DI::l10n()->t('View photo')];
1244 $tools['edit'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/edit', DI::l10n()->t('Edit photo')];
1245 $tools['delete'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/drop', DI::l10n()->t('Delete photo')];
1246 $tools['profile'] = ['settings/profile/photo/crop/' . $ph[0]['resource-id'], DI::l10n()->t('Use as profile photo')];
1250 $ph[0]['uid'] == local_user()
1251 && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']))
1253 $tools['lock'] = DI::l10n()->t('Private Photo');
1258 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1259 'title'=> DI::l10n()->t('View Full Size'),
1260 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?_u=' . DateTimeFormat::utcNow('ymdhis'),
1261 'height' => $hires['height'],
1262 'width' => $hires['width'],
1263 'album' => $hires['album'],
1264 'filename' => $hires['filename'],
1271 // Do we have an item for this photo?
1273 // FIXME! - replace following code to display the conversation with our normal
1274 // conversation functions so that it works correctly and tracks changes
1275 // in the evolving conversation code.
1276 // The difference is that we won't be displaying the conversation head item
1277 // as a "post" but displaying instead the photo it is linked to
1279 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1280 $linked_items = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1283 if (DBA::isResult($linked_items)) {
1284 // This is a workaround to not being forced to rewrite the while $sql_extra handling
1285 $link_item = Item::selectFirst([], ['id' => $linked_items[0]['id']]);
1288 if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
1289 $condition = ["`parent` = ? AND `gravity` != ?", $link_item['parent'], GRAVITY_PARENT];
1290 $total = DBA::count('item', $condition);
1292 $pager = new Pager(DI::l10n(), DI::args()->getQueryString());
1294 $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1295 $result = Item::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params);
1296 $items = Item::inArray($result);
1298 if (local_user() == $link_item['uid']) {
1299 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1303 if (!empty($link_item['coord'])) {
1304 $map = Map::byCoordinates($link_item['coord']);
1309 if (!empty($link_item['id'])) {
1310 $tag_text = Tag::getCSVByURIId($link_item['uri-id']);
1311 $arr = explode(',', $tag_text);
1312 // parse tags and add links
1314 foreach ($arr as $tag) {
1316 'name' => BBCode::convert($tag),
1317 'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag)
1320 $tags = ['title' => DI::l10n()->t('Tags: '), 'tags' => $tag_arr];
1321 if ($cmd === 'edit') {
1322 $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
1323 $tags['removetitle'] = DI::l10n()->t('[Select tags to remove]');
1329 if ($cmd === 'edit' && $can_post) {
1330 $edit_tpl = Renderer::getMarkupTemplate('photo_edit.tpl');
1332 $album_e = $ph[0]['album'];
1333 $caption_e = $ph[0]['desc'];
1334 $aclselect_e = ACL::getFullSelectorHTML(DI::page(), $a->user, false, ACL::getDefaultUserPermissions($ph[0]));
1336 $edit = Renderer::replaceMacros($edit_tpl, [
1337 '$id' => $ph[0]['id'],
1338 '$album' => ['albname', DI::l10n()->t('New album name'), $album_e,''],
1339 '$caption' => ['desc', DI::l10n()->t('Caption'), $caption_e, ''],
1340 '$tags' => ['newtag', DI::l10n()->t('Add a Tag'), "", DI::l10n()->t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1341 '$rotate_none' => ['rotate', DI::l10n()->t('Do not rotate'),0,'', true],
1342 '$rotate_cw' => ['rotate', DI::l10n()->t("Rotate CW \x28right\x29"),1,''],
1343 '$rotate_ccw' => ['rotate', DI::l10n()->t("Rotate CCW \x28left\x29"),2,''],
1345 '$nickname' => $a->data['user']['nickname'],
1346 '$resource_id' => $ph[0]['resource-id'],
1347 '$permissions' => DI::l10n()->t('Permissions'),
1348 '$aclselect' => $aclselect_e,
1350 '$item_id' => $link_item['id'] ?? 0,
1351 '$submit' => DI::l10n()->t('Submit'),
1352 '$delete' => DI::l10n()->t('Delete Photo'),
1354 // ACL permissions box
1355 '$group_perms' => DI::l10n()->t('Show to Groups'),
1356 '$contact_perms' => DI::l10n()->t('Show to Contacts'),
1357 '$return_path' => DI::args()->getQueryString(),
1367 if (!empty($link_item['id']) && !empty($link_item['uri'])) {
1368 $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
1369 $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
1370 $return_path = DI::args()->getCommand();
1372 if ($cmd === 'view' && ($can_post || Security::canWriteToUserWall($owner_uid))) {
1373 $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl');
1374 $likebuttons = Renderer::replaceMacros($like_tpl, [
1375 '$id' => $link_item['id'],
1376 '$likethis' => DI::l10n()->t("I like this \x28toggle\x29"),
1377 '$dislike' => DI::pConfig()->get(local_user(), 'system', 'hide_dislike') ? '' : DI::l10n()->t("I don't like this \x28toggle\x29"),
1378 '$wait' => DI::l10n()->t('Please wait'),
1379 '$return_path' => DI::args()->getQueryString(),
1383 if (!DBA::isResult($items)) {
1384 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1385 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1386 '$return_path' => '',
1387 '$jsreload' => $return_path,
1388 '$id' => $link_item['id'],
1389 '$parent' => $link_item['id'],
1390 '$profile_uid' => $owner_uid,
1391 '$mylink' => $contact['url'],
1392 '$mytitle' => DI::l10n()->t('This is you'),
1393 '$myphoto' => $contact['thumb'],
1394 '$comment' => DI::l10n()->t('Comment'),
1395 '$submit' => DI::l10n()->t('Submit'),
1396 '$preview' => DI::l10n()->t('Preview'),
1397 '$loading' => DI::l10n()->t('Loading...'),
1398 '$sourceapp' => DI::l10n()->t($a->sourcename),
1400 '$rand_num' => Crypto::randomDigits(12)
1413 if (DI::pConfig()->get(local_user(), 'system', 'hide_dislike')) {
1414 unset($conv_responses['dislike']);
1418 if (DBA::isResult($items)) {
1419 foreach ($items as $item) {
1420 builtin_activity_puller($item, $conv_responses);
1423 if (!empty($conv_responses['like'][$link_item['uri']])) {
1424 $like = format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like', $link_item['id']);
1427 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1428 $dislike = format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike', $link_item['id']);
1431 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1432 $comments .= Renderer::replaceMacros($cmnt_tpl,[
1433 '$return_path' => '',
1434 '$jsreload' => $return_path,
1435 '$id' => $link_item['id'],
1436 '$parent' => $link_item['id'],
1437 '$profile_uid' => $owner_uid,
1438 '$mylink' => $contact['url'],
1439 '$mytitle' => DI::l10n()->t('This is you'),
1440 '$myphoto' => $contact['thumb'],
1441 '$comment' => DI::l10n()->t('Comment'),
1442 '$submit' => DI::l10n()->t('Submit'),
1443 '$preview' => DI::l10n()->t('Preview'),
1444 '$sourceapp' => DI::l10n()->t($a->sourcename),
1446 '$rand_num' => Crypto::randomDigits(12)
1450 foreach ($items as $item) {
1454 $activity = DI::activity();
1456 if (($activity->match($item['verb'], Activity::LIKE) ||
1457 $activity->match($item['verb'], Activity::DISLIKE)) &&
1458 ($item['gravity'] != GRAVITY_PARENT)) {
1462 $profile_url = Contact::magicLinkbyId($item['author-id']);
1463 if (strpos($profile_url, 'redir/') === 0) {
1464 $sparkle = ' sparkle';
1469 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1471 'dropping' => $dropping,
1472 'pagedrop' => false,
1473 'select' => DI::l10n()->t('Select'),
1474 'delete' => DI::l10n()->t('Delete'),
1477 $title_e = $item['title'];
1478 $body_e = BBCode::convert($item['body']);
1480 $comments .= Renderer::replaceMacros($template,[
1481 '$id' => $item['id'],
1482 '$profile_url' => $profile_url,
1483 '$name' => $item['author-name'],
1484 '$thumb' => $item['author-avatar'],
1485 '$sparkle' => $sparkle,
1486 '$title' => $title_e,
1488 '$ago' => Temporal::getRelativeDate($item['created']),
1489 '$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''),
1491 '$comment' => $comment
1494 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1495 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1496 '$return_path' => '',
1497 '$jsreload' => $return_path,
1498 '$id' => $item['id'],
1499 '$parent' => $item['parent'],
1500 '$profile_uid' => $owner_uid,
1501 '$mylink' => $contact['url'],
1502 '$mytitle' => DI::l10n()->t('This is you'),
1503 '$myphoto' => $contact['thumb'],
1504 '$comment' => DI::l10n()->t('Comment'),
1505 '$submit' => DI::l10n()->t('Submit'),
1506 '$preview' => DI::l10n()->t('Preview'),
1507 '$sourceapp' => DI::l10n()->t($a->sourcename),
1509 '$rand_num' => Crypto::randomDigits(12)
1515 $paginate = $pager->renderFull($total);
1518 $photo_tpl = Renderer::getMarkupTemplate('photo_view.tpl');
1519 $o .= Renderer::replaceMacros($photo_tpl, [
1520 '$id' => $ph[0]['id'],
1521 '$album' => [$album_link, $ph[0]['album']],
1524 '$prevlink' => $prevlink,
1525 '$nextlink' => $nextlink,
1526 '$desc' => $ph[0]['desc'],
1530 '$map_text' => DI::l10n()->t('Map'),
1531 '$likebuttons' => $likebuttons,
1533 '$dislike' => $dislike,
1534 '$comments' => $comments,
1535 '$paginate' => $paginate,
1538 DI::page()['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
1539 DI::page()['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1540 DI::page()['htmlhead'] .= '<meta name="twitter:image" content="' . DI::baseUrl() . "/" . $photo["href"] . '" />' . "\n";
1541 DI::page()['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1542 DI::page()['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1547 // Default - show recent photos with upload link (if applicable)
1550 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1551 $sql_extra GROUP BY `resource-id`",
1552 intval($a->data['user']['uid']),
1553 DBA::escape(Photo::CONTACT_PHOTOS),
1554 DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS))
1556 if (DBA::isResult($r)) {
1560 $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 20);
1562 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1563 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1564 ANY_VALUE(`created`) AS `created` FROM `photo`
1565 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1566 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1567 intval($a->data['user']['uid']),
1568 DBA::escape(Photo::CONTACT_PHOTOS),
1569 DBA::escape(DI::l10n()->t(Photo::CONTACT_PHOTOS)),
1571 $pager->getItemsPerPage()
1575 if (DBA::isResult($r)) {
1576 // "Twist" is only used for the duepunto theme with style "slackr"
1578 foreach ($r as $rr) {
1579 //hide profile photos to others
1580 if (!$is_owner && !Session::getRemoteContactID($owner_uid) && ($rr['album'] == DI::l10n()->t('Profile Photos'))) {
1585 $ext = $phototypes[$rr['type']];
1587 $alt_e = $rr['filename'];
1588 $name_e = $rr['album'];
1592 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1593 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1594 'title' => DI::l10n()->t('View Photo'),
1595 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1598 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1600 'alt' => DI::l10n()->t('View Album'),
1607 $tpl = Renderer::getMarkupTemplate('photos_recent.tpl');
1608 $o .= Renderer::replaceMacros($tpl, [
1609 '$title' => DI::l10n()->t('Recent Photos'),
1610 '$can_post' => $can_post,
1611 '$upload' => [DI::l10n()->t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'],
1612 '$photos' => $photos,
1613 '$paginate' => $pager->renderFull($total),