7 use Friendica\Content\Feature;
8 use Friendica\Content\Nav;
9 use Friendica\Content\Pager;
10 use Friendica\Content\Text\BBCode;
11 use Friendica\Core\ACL;
12 use Friendica\Core\Config;
13 use Friendica\Core\Hook;
14 use Friendica\Core\L10n;
15 use Friendica\Core\Logger;
16 use Friendica\Core\Renderer;
17 use Friendica\Core\System;
18 use Friendica\Database\DBA;
19 use Friendica\Model\Contact;
20 use Friendica\Model\Group;
21 use Friendica\Model\Item;
22 use Friendica\Model\Photo;
23 use Friendica\Model\Profile;
24 use Friendica\Model\User;
25 use Friendica\Network\Probe;
26 use Friendica\Object\Image;
27 use Friendica\Protocol\DFRN;
28 use Friendica\Util\Crypto;
29 use Friendica\Util\DateTimeFormat;
30 use Friendica\Util\Map;
31 use Friendica\Util\Security;
32 use Friendica\Util\Strings;
33 use Friendica\Util\Temporal;
34 use Friendica\Util\XML;
36 function photos_init(App $a) {
39 DFRN::autoRedir($a, $a->argv[1]);
42 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
46 Nav::setSelected('home');
50 $user = DBA::selectFirst('user', [], ['nickname' => $nick, 'blocked' => false]);
52 if (!DBA::isResult($user)) {
56 $a->data['user'] = $user;
57 $a->profile_uid = $user['uid'];
58 $is_owner = (local_user() && (local_user() == $a->profile_uid));
60 $profile = Profile::getByNickname($nick, $a->profile_uid);
62 $account_type = Contact::getAccountType($profile);
64 $tpl = Renderer::getMarkupTemplate("widget/vcard.tpl");
66 $vcard_widget = Renderer::replaceMacros($tpl, [
67 '$name' => $profile['name'],
68 '$photo' => $profile['photo'],
69 '$addr' => defaults($profile, 'addr', ''),
70 '$account_type' => $account_type,
71 '$pdesc' => defaults($profile, 'pdesc', ''),
74 $albums = Photo::getAlbums($a->data['user']['uid']);
76 $albums_visible = ((intval($a->data['user']['hidewall']) && !local_user() && !remote_user()) ? false : true);
78 // add various encodings to the array so we can just loop through and pick them out in a template
79 $ret = ['success' => false];
82 $a->data['albums'] = $albums;
84 if ($albums_visible) {
85 $ret['success'] = true;
89 foreach ($albums as $k => $album) {
90 //hide profile photos to others
91 if (!$is_owner && !remote_user() && ($album['album'] == L10n::t('Profile Photos')))
94 'text' => $album['album'],
95 'total' => $album['total'],
96 'url' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
97 'urlencode' => urlencode($album['album']),
98 'bin2hex' => bin2hex($album['album'])
100 $ret['albums'][] = $entry;
104 if (local_user() && $a->data['user']['uid'] == local_user()) {
110 if ($ret['success']) {
111 $photo_albums_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('photo_albums.tpl'), [
112 '$nick' => $a->data['user']['nickname'],
113 '$title' => L10n::t('Photo Albums'),
114 '$recent' => L10n::t('Recent Photos'),
115 '$albums' => $ret['albums'],
116 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'],
117 '$can_post' => $can_post
121 if (empty($a->page['aside'])) {
122 $a->page['aside'] = '';
125 $a->page['aside'] .= $vcard_widget;
127 if (!empty($photo_albums_widget)) {
128 $a->page['aside'] .= $photo_albums_widget;
131 $tpl = Renderer::getMarkupTemplate("photos_head.tpl");
133 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl,[
134 '$ispublic' => L10n::t('everybody')
141 function photos_post(App $a)
143 Logger::log('mod-photos: photos_post: begin' , Logger::DEBUG);
144 Logger::log('mod_photos: REQUEST ' . print_r($_REQUEST, true), Logger::DATA);
145 Logger::log('mod_photos: FILES ' . print_r($_FILES, true), Logger::DATA);
147 $phototypes = Image::supportedTypes();
152 $page_owner_uid = intval($a->data['user']['uid']);
153 $community_page = $a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
155 if (local_user() && (local_user() == $page_owner_uid)) {
157 } elseif ($community_page && remote_user()) {
160 if (!empty($_SESSION['remote']) && is_array($_SESSION['remote'])) {
161 foreach ($_SESSION['remote'] as $v) {
162 if ($v['uid'] == $page_owner_uid) {
163 $contact_id = $v['cid'];
169 if ($contact_id > 0) {
170 if (DBA::exists('contact', ['id' => $contact_id, 'uid' => $page_owner_uid, 'blocked' => false, 'pending' => false])) {
172 $visitor = $contact_id;
178 notice(L10n::t('Permission denied.') . EOL);
182 $owner_record = User::getOwnerDataById($page_owner_uid);
184 if (!$owner_record) {
185 notice(L10n::t('Contact information unavailable') . EOL);
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 $a->internalRedirect('photos/' . $a->data['user']['nickname'] . '/album');
194 $album = hex2bin($a->argv[3]);
196 if ($album === L10n::t('Profile Photos') || $album === 'Contact Photos' || $album === L10n::t('Contact Photos')) {
197 $a->internalRedirect($_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(L10n::t('Album not found.') . EOL);
208 $a->internalRedirect($_SESSION['photo_return']);
209 return; // NOTREACHED
212 // Check if the user has responded to a delete confirmation query
213 if (!empty($_REQUEST['canceled'])) {
214 $a->internalRedirect($_SESSION['photo_return']);
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 $a->internalRedirect('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(L10n::t('Album successfully deleted'));
267 notice(L10n::t('Album was empty.'));
271 $a->internalRedirect('photos/' . $a->argv[1]);
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 $a->internalRedirect('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);
298 notice('Successfully deleted the photo.');
300 notice('Failed to delete the photo.');
301 $a->internalRedirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]);
304 $a->internalRedirect('photos/' . $a->argv[1]);
305 return; // NOTREACHED
309 if ($a->argc > 2 && (!empty($_POST['desc']) || !empty($_POST['newtag']) || isset($_POST['albname']))) {
310 $desc = !empty($_POST['desc']) ? Strings::escapeTags(trim($_POST['desc'])) : '';
311 $rawtags = !empty($_POST['newtag']) ? Strings::escapeTags(trim($_POST['newtag'])) : '';
312 $item_id = !empty($_POST['item_id']) ? intval($_POST['item_id']) : 0;
313 $albname = !empty($_POST['albname']) ? Strings::escapeTags(trim($_POST['albname'])) : '';
314 $origaname = !empty($_POST['origaname']) ? Strings::escapeTags(trim($_POST['origaname'])) : '';
316 $str_group_allow = !empty($_POST['group_allow']) ? perms2str($_POST['group_allow']) : '';
317 $str_contact_allow = !empty($_POST['contact_allow']) ? perms2str($_POST['contact_allow']) : '';
318 $str_group_deny = !empty($_POST['group_deny']) ? perms2str($_POST['group_deny']) : '';
319 $str_contact_deny = !empty($_POST['contact_deny']) ? perms2str($_POST['contact_deny']) : '';
321 $resource_id = $a->argv[3];
323 if (!strlen($albname)) {
324 $albname = DateTimeFormat::localNow('Y');
327 if (!empty($_POST['rotate']) && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
328 Logger::log('rotate');
330 $photo = Photo::getPhotoForUser($page_owner_uid, $resource_id);
332 if (DBA::isResult($photo)) {
333 $image = Photo::getImageForPhoto($photo);
335 if ($image->isValid()) {
336 $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
337 $image->rotate($rotate_deg);
339 $width = $image->getWidth();
340 $height = $image->getHeight();
342 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 0], $image);
344 if ($width > 640 || $height > 640) {
345 $image->scaleDown(640);
346 $width = $image->getWidth();
347 $height = $image->getHeight();
349 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 1], $image);
352 if ($width > 320 || $height > 320) {
353 $image->scaleDown(320);
354 $width = $image->getWidth();
355 $height = $image->getHeight();
357 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 2], $image);
363 $photos_stmt = DBA::select('photo', [], ['resource-id' => $resource_id, 'uid' => $page_owner_uid], ['order' => ['scale' => true]]);
365 $photos = DBA::toArray($photos_stmt);
367 if (DBA::isResult($photos)) {
369 $ext = $phototypes[$photo['type']];
371 ['desc' => $desc, 'album' => $albname, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow, 'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny],
372 ['resource-id' => $resource_id, 'uid' => $page_owner_uid]
375 // Update the photo albums cache if album name was changed
376 if ($albname !== $origaname) {
377 Photo::clearAlbumCache($page_owner_uid);
379 /* Don't make the item visible if the only change was the album name */
382 if ($photo['desc'] !== $desc || strlen($rawtags)) {
387 if (DBA::isResult($photos) && !$item_id) {
388 // Create item container
390 $uri = Item::newURI($page_owner_uid);
393 $arr['guid'] = System::createUUID();
394 $arr['uid'] = $page_owner_uid;
396 $arr['parent-uri'] = $uri;
397 $arr['post-type'] = Item::PT_IMAGE;
399 $arr['resource-id'] = $photo['resource-id'];
400 $arr['contact-id'] = $owner_record['id'];
401 $arr['owner-name'] = $owner_record['name'];
402 $arr['owner-link'] = $owner_record['url'];
403 $arr['owner-avatar'] = $owner_record['thumb'];
404 $arr['author-name'] = $owner_record['name'];
405 $arr['author-link'] = $owner_record['url'];
406 $arr['author-avatar'] = $owner_record['thumb'];
407 $arr['title'] = $title;
408 $arr['allow_cid'] = $photo['allow_cid'];
409 $arr['allow_gid'] = $photo['allow_gid'];
410 $arr['deny_cid'] = $photo['deny_cid'];
411 $arr['deny_gid'] = $photo['deny_gid'];
412 $arr['visible'] = $visibility;
415 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $photo['resource-id'] . ']'
416 . '[img]' . System::baseUrl() . '/photo/' . $photo['resource-id'] . '-' . $photo['scale'] . '.'. $ext . '[/img]'
419 $item_id = Item::insert($arr);
423 $item = Item::selectFirst(['tag', 'inform'], ['id' => $item_id, 'uid' => $page_owner_uid]);
425 if (DBA::isResult($item)) {
426 $old_tag = $item['tag'];
427 $old_inform = $item['inform'];
431 if (strlen($rawtags)) {
435 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
436 $x = substr($rawtags, 0, 1);
437 if ($x !== '@' && $x !== '#') {
438 $rawtags = '#' . $rawtags;
442 $tags = BBCode::getTags($rawtags);
445 foreach ($tags as $tag) {
446 if (strpos($tag, '@') === 0) {
449 $name = substr($tag,1);
451 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
453 $links = @Probe::lrdd($name);
456 foreach ($links as $link) {
457 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
458 $profile = $link['@attributes']['href'];
461 if ($link['@attributes']['rel'] === 'salmon') {
462 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
464 if (strlen($inform)) {
473 $taginfo[] = [$newname, $profile, $salmon];
478 if (strrpos($newname, '+')) {
479 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
483 $contact = DBA::selectFirst('contact', [], ['id' => $tagcid, 'uid' => $page_owner_uid]);
485 $newname = str_replace('_',' ',$name);
487 //select someone from this user's contacts by name
488 $contact = DBA::selectFirst('contact', [], ['name' => $newname, 'uid' => $page_owner_uid]);
489 if (!DBA::isResult($contact)) {
490 //select someone by attag or nick and the name passed in
491 $contact = DBA::selectFirst('contact', [],
492 ['(`attag` = ? OR `nick` = ?) AND `uid` = ?', $name, $name, $page_owner_uid],
493 ['order' => ['attag' => true]]
498 if (DBA::isResult($contact)) {
499 $newname = $contact['name'];
500 $profile = $contact['url'];
502 $notify = 'cid:' . $contact['id'];
503 if (strlen($inform)) {
511 if (!empty($contact)) {
512 $taginfo[] = [$newname, $profile, $notify, $contact, '@[url=' . str_replace(',', '%2c', $profile) . ']' . $newname . '[/url]'];
514 $taginfo[] = [$newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'];
517 if (strlen($str_tags)) {
521 $profile = str_replace(',', '%2c', $profile);
522 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
524 } elseif (strpos($tag, '#') === 0) {
525 $tagname = substr($tag, 1);
526 $str_tags .= '#[url=' . System::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url],';
531 $newtag = $old_tag ?? '';
532 if (strlen($newtag) && strlen($str_tags)) {
535 $newtag .= $str_tags;
537 $newinform = $old_inform ?? '';
538 if (strlen($newinform) && strlen($inform)) {
541 $newinform .= $inform;
543 $fields = ['tag' => $newtag, 'inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
544 $condition = ['id' => $item_id];
545 Item::update($fields, $condition);
548 foreach ($photos as $scales) {
549 if (intval($scales['scale']) == 2) {
554 if (intval($scales['scale']) == 4) {
560 if (count($taginfo)) {
561 foreach ($taginfo as $tagged) {
562 $uri = Item::newURI($page_owner_uid);
565 $arr['guid'] = System::createUUID();
566 $arr['uid'] = $page_owner_uid;
568 $arr['parent-uri'] = $uri;
570 $arr['contact-id'] = $owner_record['id'];
571 $arr['owner-name'] = $owner_record['name'];
572 $arr['owner-link'] = $owner_record['url'];
573 $arr['owner-avatar'] = $owner_record['thumb'];
574 $arr['author-name'] = $owner_record['name'];
575 $arr['author-link'] = $owner_record['url'];
576 $arr['author-avatar'] = $owner_record['thumb'];
578 $arr['allow_cid'] = $photo['allow_cid'];
579 $arr['allow_gid'] = $photo['allow_gid'];
580 $arr['deny_cid'] = $photo['deny_cid'];
581 $arr['deny_gid'] = $photo['deny_gid'];
583 $arr['verb'] = ACTIVITY_TAG;
584 $arr['gravity'] = GRAVITY_PARENT;
585 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
586 $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
587 $arr['tag'] = $tagged[4];
588 $arr['inform'] = $tagged[2];
590 $arr['body'] = L10n::t('%1$s was tagged in %2$s by %3$s', '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]', '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . ']' . L10n::t('a photo') . '[/url]', '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]') ;
591 $arr['body'] .= "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . ']' . '[img]' . System::baseUrl() . "/photo/" . $photo['resource-id'] . '-' . $best . '.' . $ext . '[/img][/url]' . "\n" ;
593 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
594 $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
596 $arr['object'] .= XML::escape('<link rel="photo" type="' . $photo['type'] . '" href="' . $tagged[3]['photo'] . '" />' . "\n");
598 $arr['object'] .= '</link></object>' . "\n";
600 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $photo['desc'] . '</title><id>'
601 . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '</id>';
602 $arr['target'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '" />' . "\n" . '<link rel="preview" type="' . $photo['type'] . '" href="' . System::baseUrl() . "/photo/" . $photo['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>';
608 $a->internalRedirect($_SESSION['photo_return']);
609 return; // NOTREACHED
613 // default post action - upload a photo
614 Hook::callAll('photo_post_init', $_POST);
616 // Determine the album to use
617 $album = !empty($_REQUEST['album']) ? Strings::escapeTags(trim($_REQUEST['album'])) : '';
618 $newalbum = !empty($_REQUEST['newalbum']) ? Strings::escapeTags(trim($_REQUEST['newalbum'])) : '';
620 Logger::log('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , Logger::DEBUG);
622 if (!strlen($album)) {
623 if (strlen($newalbum)) {
626 $album = DateTimeFormat::localNow('Y');
631 * We create a wall item for every photo, but we don't want to
632 * overwhelm the data stream with a hundred newly uploaded photos.
633 * So we will make the first photo uploaded to this album in the last several hours
634 * visible by default, the rest will become visible over time when and if
635 * they acquire comments, likes, dislikes, and/or tags
638 $r = Photo::selectToArray([], ['`album` = ? AND `uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR', $album, $page_owner_uid]);
640 if (!DBA::isResult($r) || ($album == L10n::t('Profile Photos'))) {
646 if (!empty($_REQUEST['not_visible']) && $_REQUEST['not_visible'] !== 'false') {
650 $group_allow = defaults($_REQUEST, 'group_allow' , []);
651 $contact_allow = defaults($_REQUEST, 'contact_allow', []);
652 $group_deny = defaults($_REQUEST, 'group_deny' , []);
653 $contact_deny = defaults($_REQUEST, 'contact_deny' , []);
655 $str_group_allow = perms2str(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
656 $str_contact_allow = perms2str(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
657 $str_group_deny = perms2str(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
658 $str_contact_deny = perms2str(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
660 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
662 Hook::callAll('photo_post_file', $ret);
664 if (!empty($ret['src']) && !empty($ret['filesize'])) {
666 $filename = $ret['filename'];
667 $filesize = $ret['filesize'];
668 $type = $ret['type'];
669 $error = UPLOAD_ERR_OK;
670 } elseif (!empty($_FILES['userfile'])) {
671 $src = $_FILES['userfile']['tmp_name'];
672 $filename = basename($_FILES['userfile']['name']);
673 $filesize = intval($_FILES['userfile']['size']);
674 $type = $_FILES['userfile']['type'];
675 $error = $_FILES['userfile']['error'];
677 $error = UPLOAD_ERR_NO_FILE;
680 if ($error !== UPLOAD_ERR_OK) {
682 case UPLOAD_ERR_INI_SIZE:
683 notice(L10n::t('Image exceeds size limit of %s', ini_get('upload_max_filesize')) . EOL);
685 case UPLOAD_ERR_FORM_SIZE:
686 notice(L10n::t('Image exceeds size limit of %s', Strings::formatBytes(defaults($_REQUEST, 'MAX_FILE_SIZE', 0))) . EOL);
688 case UPLOAD_ERR_PARTIAL:
689 notice(L10n::t('Image upload didn\'t complete, please try again') . EOL);
691 case UPLOAD_ERR_NO_FILE:
692 notice(L10n::t('Image file is missing') . EOL);
694 case UPLOAD_ERR_NO_TMP_DIR:
695 case UPLOAD_ERR_CANT_WRITE:
696 case UPLOAD_ERR_EXTENSION:
697 notice(L10n::t('Server can\'t accept new file upload at this time, please contact your administrator') . EOL);
702 Hook::callAll('photo_post_end', $foo);
707 $type = Image::guessType($filename);
710 Logger::log('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', Logger::DEBUG);
712 $maximagesize = Config::get('system', 'maximagesize');
714 if ($maximagesize && ($filesize > $maximagesize)) {
715 notice(L10n::t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)) . EOL);
718 Hook::callAll('photo_post_end', $foo);
723 notice(L10n::t('Image file is empty.') . EOL);
726 Hook::callAll('photo_post_end', $foo);
730 Logger::log('mod/photos.php: photos_post(): loading the contents of ' . $src , Logger::DEBUG);
732 $imagedata = @file_get_contents($src);
734 $image = new Image($imagedata, $type);
736 if (!$image->isValid()) {
737 Logger::log('mod/photos.php: photos_post(): unable to process image' , Logger::DEBUG);
738 notice(L10n::t('Unable to process image.') . EOL);
741 Hook::callAll('photo_post_end',$foo);
745 $exif = $image->orient($src);
748 $max_length = Config::get('system', 'max_image_length');
750 $max_length = MAX_IMAGE_LENGTH;
752 if ($max_length > 0) {
753 $image->scaleDown($max_length);
756 $width = $image->getWidth();
757 $height = $image->getHeight();
761 $photo_hash = Photo::newResource();
763 $r = Photo::store($image, $page_owner_uid, $visitor, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
766 Logger::log('mod/photos.php: photos_post(): image store failed', Logger::DEBUG);
767 notice(L10n::t('Image upload failed.') . EOL);
771 if ($width > 640 || $height > 640) {
772 $image->scaleDown(640);
773 Photo::store($image, $page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
777 if ($width > 320 || $height > 320) {
778 $image->scaleDown(320);
779 Photo::store($image, $page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
783 $uri = Item::newURI($page_owner_uid);
785 // Create item container
787 if ($exif && $exif['GPS'] && Feature::isEnabled($page_owner_uid, 'photo_location')) {
788 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
789 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
794 $arr['coord'] = $lat . ' ' . $lon;
797 $arr['guid'] = System::createUUID();
798 $arr['uid'] = $page_owner_uid;
800 $arr['parent-uri'] = $uri;
801 $arr['type'] = 'photo';
803 $arr['resource-id'] = $photo_hash;
804 $arr['contact-id'] = $owner_record['id'];
805 $arr['owner-name'] = $owner_record['name'];
806 $arr['owner-link'] = $owner_record['url'];
807 $arr['owner-avatar'] = $owner_record['thumb'];
808 $arr['author-name'] = $owner_record['name'];
809 $arr['author-link'] = $owner_record['url'];
810 $arr['author-avatar'] = $owner_record['thumb'];
812 $arr['allow_cid'] = $str_contact_allow;
813 $arr['allow_gid'] = $str_group_allow;
814 $arr['deny_cid'] = $str_contact_deny;
815 $arr['deny_gid'] = $str_group_deny;
816 $arr['visible'] = $visible;
819 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
820 . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$image->getExt() . '[/img]'
823 $item_id = Item::insert($arr);
824 // Update the photo albums cache
825 Photo::clearAlbumCache($page_owner_uid);
827 Hook::callAll('photo_post_end', $item_id);
829 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
830 // if they do not wish to be redirected
832 $a->internalRedirect($_SESSION['photo_return']);
836 function photos_content(App $a)
840 // photos/name/upload
841 // photos/name/upload/xxxxx (xxxxx is album name)
842 // photos/name/album/xxxxx
843 // photos/name/album/xxxxx/edit
844 // photos/name/album/xxxxx/drop
845 // photos/name/image/xxxxx
846 // photos/name/image/xxxxx/edit
847 // photos/name/image/xxxxx/drop
849 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
850 notice(L10n::t('Public access denied.') . EOL);
854 if (empty($a->data['user'])) {
855 notice(L10n::t('No photos selected') . EOL);
859 $phototypes = Image::supportedTypes();
861 $_SESSION['photo_return'] = $a->cmd;
866 $datatype = $a->argv[2];
867 $datum = $a->argv[3];
868 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
869 $datatype = 'upload';
871 $datatype = 'summary';
880 // Setup permissions structures
884 $remote_contact = false;
889 $owner_uid = $a->data['user']['uid'];
891 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
893 if (local_user() && (local_user() == $owner_uid)) {
896 if ($community_page && remote_user()) {
897 if (is_array($_SESSION['remote'])) {
898 foreach ($_SESSION['remote'] as $v) {
899 if ($v['uid'] == $owner_uid) {
900 $contact_id = $v['cid'];
907 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
909 if (DBA::isResult($contact)) {
911 $remote_contact = true;
912 $visitor = $contact_id;
920 // perhaps they're visiting - but not a community page, so they wouldn't have write access
921 if (remote_user() && !$visitor) {
923 if (is_array($_SESSION['remote'])) {
924 foreach ($_SESSION['remote'] as $v) {
925 if ($v['uid'] == $owner_uid) {
926 $contact_id = $v['cid'];
933 $groups = Group::getIdsByContactId($contact_id);
935 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
937 $remote_contact = DBA::isResult($contact);
941 if (!$remote_contact && local_user()) {
942 $contact_id = $_SESSION['cid'];
943 $contact = $a->contact;
946 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
947 notice(L10n::t('Access to this item is restricted.') . EOL);
951 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid, $remote_contact, $groups);
956 $is_owner = (local_user() && (local_user() == $owner_uid));
957 $o .= Profile::getTabs($a, 'photos', $is_owner, $a->data['user']['nickname']);
959 // Display upload form
960 if ($datatype === 'upload') {
962 notice(L10n::t('Permission denied.'));
966 $selname = Strings::isHex($datum) ? hex2bin($datum) : '';
970 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '><current year></option>';
971 if (!empty($a->data['albums'])) {
972 foreach ($a->data['albums'] as $album) {
973 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos'))) {
976 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
977 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
983 $ret = ['post_url' => 'photos/' . $a->data['user']['nickname'],
984 'addon_text' => $uploader,
985 'default_upload' => true];
987 Hook::callAll('photo_upload_form',$ret);
989 $default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
990 $default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
991 '$submit' => L10n::t('Submit'),
996 $tpl = Renderer::getMarkupTemplate('photos_upload.tpl');
998 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML($a->user));
1000 $o .= Renderer::replaceMacros($tpl,[
1001 '$pagename' => L10n::t('Upload Photos'),
1002 '$sessid' => session_id(),
1003 '$usage' => $usage_message,
1004 '$nickname' => $a->data['user']['nickname'],
1005 '$newalbum' => L10n::t('New album name: '),
1006 '$existalbumtext' => L10n::t('or select existing album:'),
1007 '$nosharetext' => L10n::t('Do not show a status post for this upload'),
1008 '$albumselect' => $albumselect,
1009 '$permissions' => L10n::t('Permissions'),
1010 '$aclselect' => $aclselect_e,
1011 '$lockstate' => is_array($a->user)
1012 && (strlen($a->user['allow_cid'])
1013 || strlen($a->user['allow_gid'])
1014 || strlen($a->user['deny_cid'])
1015 || strlen($a->user['deny_gid'])
1016 ) ? 'lock' : 'unlock',
1017 '$alt_uploader' => $ret['addon_text'],
1018 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
1019 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
1020 '$uploadurl' => $ret['post_url'],
1022 // ACL permissions box
1023 '$group_perms' => L10n::t('Show to Groups'),
1024 '$contact_perms' => L10n::t('Show to Contacts'),
1025 '$return_path' => $a->query_string,
1031 // Display a single photo album
1032 if ($datatype === 'album') {
1033 // if $datum is not a valid hex, redirect to the default page
1034 if (!Strings::isHex($datum)) {
1035 $a->internalRedirect('photos/' . $a->data['user']['nickname']. '/album');
1037 $album = hex2bin($datum);
1040 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1041 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1045 if (DBA::isResult($r)) {
1049 $pager = new Pager($a->query_string, 20);
1051 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1052 $order_field = defaults($_GET, 'order', '');
1053 if ($order_field === 'posted') {
1059 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1060 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1061 ANY_VALUE(`created`) as `created`
1062 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1063 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1065 DBA::escape($album),
1067 $pager->getItemsPerPage()
1070 if ($cmd === 'drop') {
1071 $drop_url = $a->query_string;
1074 ['name' => 'albumname', 'value' => $_POST['albumname']],
1077 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1078 '$method' => 'post',
1079 '$message' => L10n::t('Do you really want to delete this photo album and all its photos?'),
1080 '$extra_inputs' => $extra_inputs,
1081 '$confirm' => L10n::t('Delete Album'),
1082 '$confirm_url' => $drop_url,
1083 '$confirm_name' => 'dropalbum',
1084 '$cancel' => L10n::t('Cancel'),
1089 if ($cmd === 'edit') {
1090 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos'))) {
1092 $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
1096 $o .= Renderer::replaceMacros($edit_tpl,[
1097 '$nametext' => L10n::t('New album name: '),
1098 '$nickname' => $a->data['user']['nickname'],
1099 '$album' => $album_e,
1100 '$hexalbum' => bin2hex($album),
1101 '$submit' => L10n::t('Submit'),
1102 '$dropsubmit' => L10n::t('Delete Album')
1107 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos')) && $can_post) {
1108 $edit = [L10n::t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1109 $drop = [L10n::t('Drop Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/drop'];
1113 if ($order_field === 'posted') {
1114 $order = [L10n::t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1116 $order = [L10n::t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted', 'newest'];
1121 if (DBA::isResult($r)) {
1122 // "Twist" is only used for the duepunto theme with style "slackr"
1124 foreach ($r as $rr) {
1127 $ext = $phototypes[$rr['type']];
1129 $imgalt_e = $rr['filename'];
1130 $desc_e = $rr['desc'];
1134 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1135 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1136 . ($order_field === 'posted' ? '?f=&order=posted' : ''),
1137 'title' => L10n::t('View Photo'),
1138 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1142 'hash'=> $rr['resource-id'],
1147 $tpl = Renderer::getMarkupTemplate('photo_album.tpl');
1148 $o .= Renderer::replaceMacros($tpl, [
1149 '$photos' => $photos,
1151 '$can_post' => $can_post,
1152 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)],
1156 '$paginate' => $pager->renderFull($total),
1163 // Display one photo
1164 if ($datatype === 'image') {
1165 // fetch image, item containing image, then comments
1166 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1167 $sql_extra ORDER BY `scale` ASC ",
1172 if (!DBA::isResult($ph)) {
1173 if (DBA::exists('photo', ['resource-id' => $datum, 'uid' => $owner_uid])) {
1174 notice(L10n::t('Permission denied. Access to this item may be restricted.'));
1176 notice(L10n::t('Photo not available') . EOL);
1181 if ($cmd === 'drop') {
1182 $drop_url = $a->query_string;
1184 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1185 '$method' => 'post',
1186 '$message' => L10n::t('Do you really want to delete this photo?'),
1187 '$extra_inputs' => [],
1188 '$confirm' => L10n::t('Delete Photo'),
1189 '$confirm_url' => $drop_url,
1190 '$confirm_name' => 'delete',
1191 '$cancel' => L10n::t('Cancel'),
1199 * @todo This query is totally bad, the whole functionality has to be changed
1200 * The query leads to a really intense used index.
1201 * By now we hide it if someone wants to.
1203 if ($cmd === 'view' && !Config::get('system', 'no_count', false)) {
1204 $order_field = defaults($_GET, 'order', '');
1206 if ($order_field === 'posted') {
1212 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1213 $sql_extra ORDER BY `created` $order ",
1214 DBA::escape($ph[0]['album']),
1218 if (DBA::isResult($prvnxt)) {
1221 foreach ($prvnxt as $z => $entry) {
1222 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1226 $prv = count($prvnxt) - 1;
1228 if ($nxt >= count($prvnxt)) {
1235 if (!is_null($prv)) {
1236 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . ($order_field === 'posted' ? '?f=&order=posted' : '');
1238 if (!is_null($nxt)) {
1239 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . ($order_field === 'posted' ? '?f=&order=posted' : '');
1242 $tpl = Renderer::getMarkupTemplate('photo_edit_head.tpl');
1243 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl,[
1244 '$prevlink' => $prevlink,
1245 '$nextlink' => $nextlink
1249 $prevlink = [$prevlink, '<div class="icon prev"></div>'];
1253 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1258 if (count($ph) == 1) {
1259 $hires = $lores = $ph[0];
1262 if (count($ph) > 1) {
1263 if ($ph[1]['scale'] == 2) {
1264 // original is 640 or less, we can display it directly
1265 $hires = $lores = $ph[0];
1272 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1276 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1278 if ($cmd === 'edit') {
1279 $tools['view'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum, L10n::t('View photo')];
1281 $tools['edit'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/edit', L10n::t('Edit photo')];
1282 $tools['delete'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/drop', L10n::t('Delete photo')];
1283 $tools['profile'] = ['profile_photo/use/'.$ph[0]['resource-id'], L10n::t('Use as profile photo')];
1287 $ph[0]['uid'] == local_user()
1288 && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']))
1290 $tools['lock'] = L10n::t('Private Photo');
1295 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1296 'title'=> L10n::t('View Full Size'),
1297 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . DateTimeFormat::utcNow('ymdhis'),
1298 'height' => $hires['height'],
1299 'width' => $hires['width'],
1300 'album' => $hires['album'],
1301 'filename' => $hires['filename'],
1308 // Do we have an item for this photo?
1310 // FIXME! - replace following code to display the conversation with our normal
1311 // conversation functions so that it works correctly and tracks changes
1312 // in the evolving conversation code.
1313 // The difference is that we won't be displaying the conversation head item
1314 // as a "post" but displaying instead the photo it is linked to
1316 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1317 $linked_items = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1320 if (DBA::isResult($linked_items)) {
1321 // This is a workaround to not being forced to rewrite the while $sql_extra handling
1322 $link_item = Item::selectFirst([], ['id' => $linked_items[0]['id']]);
1325 if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
1326 $condition = ["`parent` = ? AND `parent` != `id`", $link_item['parent']];
1327 $total = DBA::count('item', $condition);
1329 $pager = new Pager($a->query_string);
1331 $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1332 $result = Item::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params);
1333 $items = Item::inArray($result);
1335 if (local_user() == $link_item['uid']) {
1336 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1340 if (!empty($link_item['coord'])) {
1341 $map = Map::byCoordinates($link_item['coord']);
1346 if (!empty($link_item['id']) && !empty($link_item['tag'])) {
1347 $arr = explode(',', $link_item['tag']);
1348 // parse tags and add links
1350 foreach ($arr as $tag) {
1352 'name' => BBCode::convert($tag),
1353 'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag)
1356 $tags = ['title' => L10n::t('Tags: '), 'tags' => $tag_arr];
1357 if ($cmd === 'edit') {
1358 $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
1359 $tags['removetitle'] = L10n::t('[Select tags to remove]');
1365 if ($cmd === 'edit' && $can_post) {
1366 $edit_tpl = Renderer::getMarkupTemplate('photo_edit.tpl');
1368 $album_e = $ph[0]['album'];
1369 $caption_e = $ph[0]['desc'];
1370 $aclselect_e = ACL::getFullSelectorHTML($a->user, false, $ph[0]);
1372 $edit = Renderer::replaceMacros($edit_tpl, [
1373 '$id' => $ph[0]['id'],
1374 '$album' => ['albname', L10n::t('New album name'), $album_e,''],
1375 '$caption' => ['desc', L10n::t('Caption'), $caption_e, ''],
1376 '$tags' => ['newtag', L10n::t('Add a Tag'), "", L10n::t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1377 '$rotate_none' => ['rotate', L10n::t('Do not rotate'),0,'', true],
1378 '$rotate_cw' => ['rotate', L10n::t("Rotate CW \x28right\x29"),1,''],
1379 '$rotate_ccw' => ['rotate', L10n::t("Rotate CCW \x28left\x29"),2,''],
1381 '$nickname' => $a->data['user']['nickname'],
1382 '$resource_id' => $ph[0]['resource-id'],
1383 '$permissions' => L10n::t('Permissions'),
1384 '$aclselect' => $aclselect_e,
1386 '$item_id' => $link_item['id'] ?? 0,
1387 '$submit' => L10n::t('Submit'),
1388 '$delete' => L10n::t('Delete Photo'),
1390 // ACL permissions box
1391 '$group_perms' => L10n::t('Show to Groups'),
1392 '$contact_perms' => L10n::t('Show to Contacts'),
1393 '$return_path' => $a->query_string,
1404 if (!empty($link_item['id']) && !empty($link_item['uri'])) {
1405 $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
1406 $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
1407 $return_path = $a->cmd;
1409 if ($cmd === 'view' && ($can_post || Security::canWriteToUserWall($owner_uid))) {
1410 $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl');
1411 $likebuttons = Renderer::replaceMacros($like_tpl, [
1412 '$id' => $link_item['id'],
1413 '$likethis' => L10n::t("I like this \x28toggle\x29"),
1414 '$nolike' => L10n::t("I don't like this \x28toggle\x29"),
1415 '$wait' => L10n::t('Please wait'),
1416 '$return_path' => $a->query_string,
1420 if (!DBA::isResult($items)) {
1421 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1422 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1423 '$return_path' => '',
1424 '$jsreload' => $return_path,
1425 '$id' => $link_item['id'],
1426 '$parent' => $link_item['id'],
1427 '$profile_uid' => $owner_uid,
1428 '$mylink' => $contact['url'],
1429 '$mytitle' => L10n::t('This is you'),
1430 '$myphoto' => $contact['thumb'],
1431 '$comment' => L10n::t('Comment'),
1432 '$submit' => L10n::t('Submit'),
1433 '$preview' => L10n::t('Preview'),
1434 '$sourceapp' => L10n::t($a->sourcename),
1436 '$rand_num' => Crypto::randomDigits(12)
1442 'like' => ['title' => L10n::t('Likes','title')],'dislike' => ['title' => L10n::t('Dislikes','title')],
1443 'attendyes' => ['title' => L10n::t('Attending','title')], 'attendno' => ['title' => L10n::t('Not attending','title')], 'attendmaybe' => ['title' => L10n::t('Might attend','title')]
1447 if (DBA::isResult($items)) {
1448 foreach ($items as $item) {
1449 builtin_activity_puller($item, $conv_responses);
1452 if (!empty($conv_responses['like'][$link_item['uri']])) {
1453 $like = format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like', $link_item['id']);
1456 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1457 $dislike = format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike', $link_item['id']);
1460 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1461 $comments .= Renderer::replaceMacros($cmnt_tpl,[
1462 '$return_path' => '',
1463 '$jsreload' => $return_path,
1464 '$id' => $link_item['id'],
1465 '$parent' => $link_item['id'],
1466 '$profile_uid' => $owner_uid,
1467 '$mylink' => $contact['url'],
1468 '$mytitle' => L10n::t('This is you'),
1469 '$myphoto' => $contact['thumb'],
1470 '$comment' => L10n::t('Comment'),
1471 '$submit' => L10n::t('Submit'),
1472 '$preview' => L10n::t('Preview'),
1473 '$sourceapp' => L10n::t($a->sourcename),
1475 '$rand_num' => Crypto::randomDigits(12)
1479 foreach ($items as $item) {
1484 if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) {
1488 $profile_url = Contact::magicLinkbyId($item['author-id']);
1489 if (strpos($profile_url, 'redir/') === 0) {
1490 $sparkle = ' sparkle';
1495 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1497 'dropping' => $dropping,
1498 'pagedrop' => false,
1499 'select' => L10n::t('Select'),
1500 'delete' => L10n::t('Delete'),
1503 $title_e = $item['title'];
1504 $body_e = BBCode::convert($item['body']);
1506 $comments .= Renderer::replaceMacros($template,[
1507 '$id' => $item['id'],
1508 '$profile_url' => $profile_url,
1509 '$name' => $item['author-name'],
1510 '$thumb' => $item['author-avatar'],
1511 '$sparkle' => $sparkle,
1512 '$title' => $title_e,
1514 '$ago' => Temporal::getRelativeDate($item['created']),
1515 '$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''),
1517 '$comment' => $comment
1520 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1521 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1522 '$return_path' => '',
1523 '$jsreload' => $return_path,
1524 '$id' => $item['id'],
1525 '$parent' => $item['parent'],
1526 '$profile_uid' => $owner_uid,
1527 '$mylink' => $contact['url'],
1528 '$mytitle' => L10n::t('This is you'),
1529 '$myphoto' => $contact['thumb'],
1530 '$comment' => L10n::t('Comment'),
1531 '$submit' => L10n::t('Submit'),
1532 '$preview' => L10n::t('Preview'),
1533 '$sourceapp' => L10n::t($a->sourcename),
1535 '$rand_num' => Crypto::randomDigits(12)
1540 $response_verbs = ['like'];
1541 $response_verbs[] = 'dislike';
1542 $responses = get_responses($conv_responses, $response_verbs, $link_item);
1544 $paginate = $pager->renderFull($total);
1547 $photo_tpl = Renderer::getMarkupTemplate('photo_view.tpl');
1548 $o .= Renderer::replaceMacros($photo_tpl, [
1549 '$id' => $ph[0]['id'],
1550 '$album' => [$album_link, $ph[0]['album']],
1553 '$prevlink' => $prevlink,
1554 '$nextlink' => $nextlink,
1555 '$desc' => $ph[0]['desc'],
1559 '$map_text' => L10n::t('Map'),
1560 '$likebuttons' => $likebuttons,
1562 '$dislike' => $dislike,
1563 'responses' => $responses,
1564 '$comments' => $comments,
1565 '$paginate' => $paginate,
1568 $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
1569 $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1570 $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . System::baseUrl() . "/" . $photo["href"] . '" />' . "\n";
1571 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1572 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1577 // Default - show recent photos with upload link (if applicable)
1580 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1581 $sql_extra GROUP BY `resource-id`",
1582 intval($a->data['user']['uid']),
1583 DBA::escape('Contact Photos'),
1584 DBA::escape(L10n::t('Contact Photos'))
1586 if (DBA::isResult($r)) {
1590 $pager = new Pager($a->query_string, 20);
1592 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1593 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1594 ANY_VALUE(`created`) AS `created` FROM `photo`
1595 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1596 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1597 intval($a->data['user']['uid']),
1598 DBA::escape('Contact Photos'),
1599 DBA::escape(L10n::t('Contact Photos')),
1601 $pager->getItemsPerPage()
1605 if (DBA::isResult($r)) {
1606 // "Twist" is only used for the duepunto theme with style "slackr"
1608 foreach ($r as $rr) {
1609 //hide profile photos to others
1610 if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos'))) {
1615 $ext = $phototypes[$rr['type']];
1617 $alt_e = $rr['filename'];
1618 $name_e = $rr['album'];
1622 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1623 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1624 'title' => L10n::t('View Photo'),
1625 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1628 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1630 'alt' => L10n::t('View Album'),
1637 $tpl = Renderer::getMarkupTemplate('photos_recent.tpl');
1638 $o .= Renderer::replaceMacros($tpl, [
1639 '$title' => L10n::t('Recent Photos'),
1640 '$can_post' => $can_post,
1641 '$upload' => [L10n::t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'],
1642 '$photos' => $photos,
1643 '$paginate' => $pager->renderFull($total),