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\Core\Session;
19 use Friendica\Database\DBA;
20 use Friendica\Model\Contact;
21 use Friendica\Model\Group;
22 use Friendica\Model\Item;
23 use Friendica\Model\Photo;
24 use Friendica\Model\Profile;
25 use Friendica\Model\User;
26 use Friendica\Network\Probe;
27 use Friendica\Object\Image;
28 use Friendica\Protocol\DFRN;
29 use Friendica\Util\Crypto;
30 use Friendica\Util\DateTimeFormat;
31 use Friendica\Util\Map;
32 use Friendica\Util\Security;
33 use Friendica\Util\Strings;
34 use Friendica\Util\Temporal;
35 use Friendica\Util\XML;
37 function photos_init(App $a) {
39 if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
43 Nav::setSelected('home');
47 $user = DBA::selectFirst('user', [], ['nickname' => $nick, 'blocked' => false]);
49 if (!DBA::isResult($user)) {
53 $a->data['user'] = $user;
54 $a->profile_uid = $user['uid'];
55 $is_owner = (local_user() && (local_user() == $a->profile_uid));
57 $profile = Profile::getByNickname($nick, $a->profile_uid);
59 $account_type = Contact::getAccountType($profile);
61 $tpl = Renderer::getMarkupTemplate("widget/vcard.tpl");
63 $vcard_widget = Renderer::replaceMacros($tpl, [
64 '$name' => $profile['name'],
65 '$photo' => $profile['photo'],
66 '$addr' => defaults($profile, 'addr', ''),
67 '$account_type' => $account_type,
68 '$pdesc' => defaults($profile, 'pdesc', ''),
71 $albums = Photo::getAlbums($a->data['user']['uid']);
73 $albums_visible = ((intval($a->data['user']['hidewall']) && !Session::isAuthenticated()) ? false : true);
75 // add various encodings to the array so we can just loop through and pick them out in a template
76 $ret = ['success' => false];
79 $a->data['albums'] = $albums;
81 if ($albums_visible) {
82 $ret['success'] = true;
86 foreach ($albums as $k => $album) {
87 //hide profile photos to others
88 if (!$is_owner && !Session::getRemoteContactID($a->profile_uid) && ($album['album'] == L10n::t('Profile Photos')))
91 'text' => $album['album'],
92 'total' => $album['total'],
93 'url' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
94 'urlencode' => urlencode($album['album']),
95 'bin2hex' => bin2hex($album['album'])
97 $ret['albums'][] = $entry;
101 if (local_user() && $a->data['user']['uid'] == local_user()) {
107 if ($ret['success']) {
108 $photo_albums_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('photo_albums.tpl'), [
109 '$nick' => $a->data['user']['nickname'],
110 '$title' => L10n::t('Photo Albums'),
111 '$recent' => L10n::t('Recent Photos'),
112 '$albums' => $ret['albums'],
113 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'],
114 '$can_post' => $can_post
118 if (empty($a->page['aside'])) {
119 $a->page['aside'] = '';
122 $a->page['aside'] .= $vcard_widget;
124 if (!empty($photo_albums_widget)) {
125 $a->page['aside'] .= $photo_albums_widget;
128 $tpl = Renderer::getMarkupTemplate("photos_head.tpl");
130 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl,[
131 '$ispublic' => L10n::t('everybody')
138 function photos_post(App $a)
140 Logger::log('mod-photos: photos_post: begin' , Logger::DEBUG);
141 Logger::log('mod_photos: REQUEST ' . print_r($_REQUEST, true), Logger::DATA);
142 Logger::log('mod_photos: FILES ' . print_r($_FILES, true), Logger::DATA);
144 $phototypes = Image::supportedTypes();
149 $page_owner_uid = intval($a->data['user']['uid']);
150 $community_page = $a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
152 if (local_user() && (local_user() == $page_owner_uid)) {
154 } elseif ($community_page && !empty(Session::getRemoteContactID($page_owner_uid))) {
155 $contact_id = Session::getRemoteContactID($page_owner_uid);
157 $visitor = $contact_id;
161 notice(L10n::t('Permission denied.') . EOL);
165 $owner_record = User::getOwnerDataById($page_owner_uid);
167 if (!$owner_record) {
168 notice(L10n::t('Contact information unavailable') . EOL);
169 Logger::log('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
173 if ($a->argc > 3 && $a->argv[2] === 'album') {
174 if (!Strings::isHex($a->argv[3])) {
175 $a->internalRedirect('photos/' . $a->data['user']['nickname'] . '/album');
177 $album = hex2bin($a->argv[3]);
179 if ($album === L10n::t('Profile Photos') || $album === 'Contact Photos' || $album === L10n::t('Contact Photos')) {
180 $a->internalRedirect($_SESSION['photo_return']);
181 return; // NOTREACHED
184 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
186 intval($page_owner_uid)
189 if (!DBA::isResult($r)) {
190 notice(L10n::t('Album not found.') . EOL);
191 $a->internalRedirect($_SESSION['photo_return']);
192 return; // NOTREACHED
195 // Check if the user has responded to a delete confirmation query
196 if (!empty($_REQUEST['canceled'])) {
197 $a->internalRedirect($_SESSION['photo_return']);
200 // RENAME photo album
201 $newalbum = Strings::escapeTags(trim($_POST['albumname']));
202 if ($newalbum != $album) {
203 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
204 DBA::escape($newalbum),
206 intval($page_owner_uid)
208 // Update the photo albums cache
209 Photo::clearAlbumCache($page_owner_uid);
211 $a->internalRedirect('photos/' . $a->user['nickname'] . '/album/' . bin2hex($newalbum));
212 return; // NOTREACHED
216 * DELETE all photos filed in a given album
218 if (!empty($_POST['dropalbum'])) {
221 // get the list of photos we are about to delete
223 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
225 intval($page_owner_uid),
229 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
230 intval(local_user()),
235 if (DBA::isResult($r)) {
236 foreach ($r as $rr) {
240 // remove the associated photos
241 Photo::delete(['resource-id' => $res, 'uid' => $page_owner_uid]);
243 // find and delete the corresponding item with all the comments and likes/dislikes
244 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
246 // Update the photo albums cache
247 Photo::clearAlbumCache($page_owner_uid);
248 notice(L10n::t('Album successfully deleted'));
250 notice(L10n::t('Album was empty.'));
254 $a->internalRedirect('photos/' . $a->argv[1]);
257 if ($a->argc > 3 && $a->argv[2] === 'image') {
258 // Check if the user has responded to a delete confirmation query for a single photo
259 if (!empty($_POST['canceled'])) {
260 $a->internalRedirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]);
263 if (!empty($_POST['delete'])) {
264 // same as above but remove single photo
266 $condition = ['contact-id' => $visitor, 'uid' => $page_owner_uid, 'resource-id' => $a->argv[3]];
269 $condition = ['uid' => local_user(), 'resource-id' => $a->argv[3]];
272 $photo = DBA::selectFirst('photo', ['resource-id'], $condition);
274 if (DBA::isResult($photo)) {
275 Photo::delete(['uid' => $page_owner_uid, 'resource-id' => $photo['resource-id']]);
277 Item::deleteForUser(['resource-id' => $photo['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
279 // Update the photo albums cache
280 Photo::clearAlbumCache($page_owner_uid);
281 notice('Successfully deleted the photo.');
283 notice('Failed to delete the photo.');
284 $a->internalRedirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]);
287 $a->internalRedirect('photos/' . $a->argv[1]);
288 return; // NOTREACHED
292 if ($a->argc > 2 && (!empty($_POST['desc']) || !empty($_POST['newtag']) || isset($_POST['albname']))) {
293 $desc = !empty($_POST['desc']) ? Strings::escapeTags(trim($_POST['desc'])) : '';
294 $rawtags = !empty($_POST['newtag']) ? Strings::escapeTags(trim($_POST['newtag'])) : '';
295 $item_id = !empty($_POST['item_id']) ? intval($_POST['item_id']) : 0;
296 $albname = !empty($_POST['albname']) ? Strings::escapeTags(trim($_POST['albname'])) : '';
297 $origaname = !empty($_POST['origaname']) ? Strings::escapeTags(trim($_POST['origaname'])) : '';
299 $str_group_allow = !empty($_POST['group_allow']) ? perms2str($_POST['group_allow']) : '';
300 $str_contact_allow = !empty($_POST['contact_allow']) ? perms2str($_POST['contact_allow']) : '';
301 $str_group_deny = !empty($_POST['group_deny']) ? perms2str($_POST['group_deny']) : '';
302 $str_contact_deny = !empty($_POST['contact_deny']) ? perms2str($_POST['contact_deny']) : '';
304 $resource_id = $a->argv[3];
306 if (!strlen($albname)) {
307 $albname = DateTimeFormat::localNow('Y');
310 if (!empty($_POST['rotate']) && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
311 Logger::log('rotate');
313 $photo = Photo::getPhotoForUser($page_owner_uid, $resource_id);
315 if (DBA::isResult($photo)) {
316 $image = Photo::getImageForPhoto($photo);
318 if ($image->isValid()) {
319 $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
320 $image->rotate($rotate_deg);
322 $width = $image->getWidth();
323 $height = $image->getHeight();
325 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 0], $image);
327 if ($width > 640 || $height > 640) {
328 $image->scaleDown(640);
329 $width = $image->getWidth();
330 $height = $image->getHeight();
332 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 1], $image);
335 if ($width > 320 || $height > 320) {
336 $image->scaleDown(320);
337 $width = $image->getWidth();
338 $height = $image->getHeight();
340 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 2], $image);
346 $photos_stmt = DBA::select('photo', [], ['resource-id' => $resource_id, 'uid' => $page_owner_uid], ['order' => ['scale' => true]]);
348 $photos = DBA::toArray($photos_stmt);
350 if (DBA::isResult($photos)) {
352 $ext = $phototypes[$photo['type']];
354 ['desc' => $desc, 'album' => $albname, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow, 'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny],
355 ['resource-id' => $resource_id, 'uid' => $page_owner_uid]
358 // Update the photo albums cache if album name was changed
359 if ($albname !== $origaname) {
360 Photo::clearAlbumCache($page_owner_uid);
362 /* Don't make the item visible if the only change was the album name */
365 if ($photo['desc'] !== $desc || strlen($rawtags)) {
370 if (DBA::isResult($photos) && !$item_id) {
371 // Create item container
373 $uri = Item::newURI($page_owner_uid);
376 $arr['guid'] = System::createUUID();
377 $arr['uid'] = $page_owner_uid;
379 $arr['parent-uri'] = $uri;
380 $arr['post-type'] = Item::PT_IMAGE;
382 $arr['resource-id'] = $photo['resource-id'];
383 $arr['contact-id'] = $owner_record['id'];
384 $arr['owner-name'] = $owner_record['name'];
385 $arr['owner-link'] = $owner_record['url'];
386 $arr['owner-avatar'] = $owner_record['thumb'];
387 $arr['author-name'] = $owner_record['name'];
388 $arr['author-link'] = $owner_record['url'];
389 $arr['author-avatar'] = $owner_record['thumb'];
390 $arr['title'] = $title;
391 $arr['allow_cid'] = $photo['allow_cid'];
392 $arr['allow_gid'] = $photo['allow_gid'];
393 $arr['deny_cid'] = $photo['deny_cid'];
394 $arr['deny_gid'] = $photo['deny_gid'];
395 $arr['visible'] = $visibility;
398 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $photo['resource-id'] . ']'
399 . '[img]' . System::baseUrl() . '/photo/' . $photo['resource-id'] . '-' . $photo['scale'] . '.'. $ext . '[/img]'
402 $item_id = Item::insert($arr);
406 $item = Item::selectFirst(['tag', 'inform'], ['id' => $item_id, 'uid' => $page_owner_uid]);
408 if (DBA::isResult($item)) {
409 $old_tag = $item['tag'];
410 $old_inform = $item['inform'];
414 if (strlen($rawtags)) {
418 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
419 $x = substr($rawtags, 0, 1);
420 if ($x !== '@' && $x !== '#') {
421 $rawtags = '#' . $rawtags;
425 $tags = BBCode::getTags($rawtags);
428 foreach ($tags as $tag) {
429 if (strpos($tag, '@') === 0) {
432 $name = substr($tag,1);
434 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
436 $links = @Probe::lrdd($name);
439 foreach ($links as $link) {
440 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
441 $profile = $link['@attributes']['href'];
444 if ($link['@attributes']['rel'] === 'salmon') {
445 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
447 if (strlen($inform)) {
456 $taginfo[] = [$newname, $profile, $salmon];
461 if (strrpos($newname, '+')) {
462 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
466 $contact = DBA::selectFirst('contact', [], ['id' => $tagcid, 'uid' => $page_owner_uid]);
468 $newname = str_replace('_',' ',$name);
470 //select someone from this user's contacts by name
471 $contact = DBA::selectFirst('contact', [], ['name' => $newname, 'uid' => $page_owner_uid]);
472 if (!DBA::isResult($contact)) {
473 //select someone by attag or nick and the name passed in
474 $contact = DBA::selectFirst('contact', [],
475 ['(`attag` = ? OR `nick` = ?) AND `uid` = ?', $name, $name, $page_owner_uid],
476 ['order' => ['attag' => true]]
481 if (DBA::isResult($contact)) {
482 $newname = $contact['name'];
483 $profile = $contact['url'];
485 $notify = 'cid:' . $contact['id'];
486 if (strlen($inform)) {
494 if (!empty($contact)) {
495 $taginfo[] = [$newname, $profile, $notify, $contact, '@[url=' . str_replace(',', '%2c', $profile) . ']' . $newname . '[/url]'];
497 $taginfo[] = [$newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'];
500 if (strlen($str_tags)) {
504 $profile = str_replace(',', '%2c', $profile);
505 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
507 } elseif (strpos($tag, '#') === 0) {
508 $tagname = substr($tag, 1);
509 $str_tags .= '#[url=' . System::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url],';
514 $newtag = $old_tag ?? '';
515 if (strlen($newtag) && strlen($str_tags)) {
518 $newtag .= $str_tags;
520 $newinform = $old_inform ?? '';
521 if (strlen($newinform) && strlen($inform)) {
524 $newinform .= $inform;
526 $fields = ['tag' => $newtag, 'inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
527 $condition = ['id' => $item_id];
528 Item::update($fields, $condition);
531 foreach ($photos as $scales) {
532 if (intval($scales['scale']) == 2) {
537 if (intval($scales['scale']) == 4) {
543 if (count($taginfo)) {
544 foreach ($taginfo as $tagged) {
545 $uri = Item::newURI($page_owner_uid);
548 $arr['guid'] = System::createUUID();
549 $arr['uid'] = $page_owner_uid;
551 $arr['parent-uri'] = $uri;
553 $arr['contact-id'] = $owner_record['id'];
554 $arr['owner-name'] = $owner_record['name'];
555 $arr['owner-link'] = $owner_record['url'];
556 $arr['owner-avatar'] = $owner_record['thumb'];
557 $arr['author-name'] = $owner_record['name'];
558 $arr['author-link'] = $owner_record['url'];
559 $arr['author-avatar'] = $owner_record['thumb'];
561 $arr['allow_cid'] = $photo['allow_cid'];
562 $arr['allow_gid'] = $photo['allow_gid'];
563 $arr['deny_cid'] = $photo['deny_cid'];
564 $arr['deny_gid'] = $photo['deny_gid'];
566 $arr['verb'] = ACTIVITY_TAG;
567 $arr['gravity'] = GRAVITY_PARENT;
568 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
569 $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
570 $arr['tag'] = $tagged[4];
571 $arr['inform'] = $tagged[2];
573 $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]') ;
574 $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" ;
576 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
577 $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
579 $arr['object'] .= XML::escape('<link rel="photo" type="' . $photo['type'] . '" href="' . $tagged[3]['photo'] . '" />' . "\n");
581 $arr['object'] .= '</link></object>' . "\n";
583 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $photo['desc'] . '</title><id>'
584 . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '</id>';
585 $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>';
591 $a->internalRedirect($_SESSION['photo_return']);
592 return; // NOTREACHED
596 // default post action - upload a photo
597 Hook::callAll('photo_post_init', $_POST);
599 // Determine the album to use
600 $album = !empty($_REQUEST['album']) ? Strings::escapeTags(trim($_REQUEST['album'])) : '';
601 $newalbum = !empty($_REQUEST['newalbum']) ? Strings::escapeTags(trim($_REQUEST['newalbum'])) : '';
603 Logger::log('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , Logger::DEBUG);
605 if (!strlen($album)) {
606 if (strlen($newalbum)) {
609 $album = DateTimeFormat::localNow('Y');
614 * We create a wall item for every photo, but we don't want to
615 * overwhelm the data stream with a hundred newly uploaded photos.
616 * So we will make the first photo uploaded to this album in the last several hours
617 * visible by default, the rest will become visible over time when and if
618 * they acquire comments, likes, dislikes, and/or tags
621 $r = Photo::selectToArray([], ['`album` = ? AND `uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR', $album, $page_owner_uid]);
623 if (!DBA::isResult($r) || ($album == L10n::t('Profile Photos'))) {
629 if (!empty($_REQUEST['not_visible']) && $_REQUEST['not_visible'] !== 'false') {
633 $group_allow = defaults($_REQUEST, 'group_allow' , []);
634 $contact_allow = defaults($_REQUEST, 'contact_allow', []);
635 $group_deny = defaults($_REQUEST, 'group_deny' , []);
636 $contact_deny = defaults($_REQUEST, 'contact_deny' , []);
638 $str_group_allow = perms2str(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
639 $str_contact_allow = perms2str(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
640 $str_group_deny = perms2str(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
641 $str_contact_deny = perms2str(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
643 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
645 Hook::callAll('photo_post_file', $ret);
647 if (!empty($ret['src']) && !empty($ret['filesize'])) {
649 $filename = $ret['filename'];
650 $filesize = $ret['filesize'];
651 $type = $ret['type'];
652 $error = UPLOAD_ERR_OK;
653 } elseif (!empty($_FILES['userfile'])) {
654 $src = $_FILES['userfile']['tmp_name'];
655 $filename = basename($_FILES['userfile']['name']);
656 $filesize = intval($_FILES['userfile']['size']);
657 $type = $_FILES['userfile']['type'];
658 $error = $_FILES['userfile']['error'];
660 $error = UPLOAD_ERR_NO_FILE;
663 if ($error !== UPLOAD_ERR_OK) {
665 case UPLOAD_ERR_INI_SIZE:
666 notice(L10n::t('Image exceeds size limit of %s', ini_get('upload_max_filesize')) . EOL);
668 case UPLOAD_ERR_FORM_SIZE:
669 notice(L10n::t('Image exceeds size limit of %s', Strings::formatBytes(defaults($_REQUEST, 'MAX_FILE_SIZE', 0))) . EOL);
671 case UPLOAD_ERR_PARTIAL:
672 notice(L10n::t('Image upload didn\'t complete, please try again') . EOL);
674 case UPLOAD_ERR_NO_FILE:
675 notice(L10n::t('Image file is missing') . EOL);
677 case UPLOAD_ERR_NO_TMP_DIR:
678 case UPLOAD_ERR_CANT_WRITE:
679 case UPLOAD_ERR_EXTENSION:
680 notice(L10n::t('Server can\'t accept new file upload at this time, please contact your administrator') . EOL);
685 Hook::callAll('photo_post_end', $foo);
690 $type = Image::guessType($filename);
693 Logger::log('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', Logger::DEBUG);
695 $maximagesize = Config::get('system', 'maximagesize');
697 if ($maximagesize && ($filesize > $maximagesize)) {
698 notice(L10n::t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)) . EOL);
701 Hook::callAll('photo_post_end', $foo);
706 notice(L10n::t('Image file is empty.') . EOL);
709 Hook::callAll('photo_post_end', $foo);
713 Logger::log('mod/photos.php: photos_post(): loading the contents of ' . $src , Logger::DEBUG);
715 $imagedata = @file_get_contents($src);
717 $image = new Image($imagedata, $type);
719 if (!$image->isValid()) {
720 Logger::log('mod/photos.php: photos_post(): unable to process image' , Logger::DEBUG);
721 notice(L10n::t('Unable to process image.') . EOL);
724 Hook::callAll('photo_post_end',$foo);
728 $exif = $image->orient($src);
731 $max_length = Config::get('system', 'max_image_length');
733 $max_length = MAX_IMAGE_LENGTH;
735 if ($max_length > 0) {
736 $image->scaleDown($max_length);
739 $width = $image->getWidth();
740 $height = $image->getHeight();
744 $photo_hash = Photo::newResource();
746 $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);
749 Logger::log('mod/photos.php: photos_post(): image store failed', Logger::DEBUG);
750 notice(L10n::t('Image upload failed.') . EOL);
754 if ($width > 640 || $height > 640) {
755 $image->scaleDown(640);
756 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);
760 if ($width > 320 || $height > 320) {
761 $image->scaleDown(320);
762 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);
766 $uri = Item::newURI($page_owner_uid);
768 // Create item container
770 if ($exif && $exif['GPS'] && Feature::isEnabled($page_owner_uid, 'photo_location')) {
771 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
772 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
777 $arr['coord'] = $lat . ' ' . $lon;
780 $arr['guid'] = System::createUUID();
781 $arr['uid'] = $page_owner_uid;
783 $arr['parent-uri'] = $uri;
784 $arr['type'] = 'photo';
786 $arr['resource-id'] = $photo_hash;
787 $arr['contact-id'] = $owner_record['id'];
788 $arr['owner-name'] = $owner_record['name'];
789 $arr['owner-link'] = $owner_record['url'];
790 $arr['owner-avatar'] = $owner_record['thumb'];
791 $arr['author-name'] = $owner_record['name'];
792 $arr['author-link'] = $owner_record['url'];
793 $arr['author-avatar'] = $owner_record['thumb'];
795 $arr['allow_cid'] = $str_contact_allow;
796 $arr['allow_gid'] = $str_group_allow;
797 $arr['deny_cid'] = $str_contact_deny;
798 $arr['deny_gid'] = $str_group_deny;
799 $arr['visible'] = $visible;
802 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
803 . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$image->getExt() . '[/img]'
806 $item_id = Item::insert($arr);
807 // Update the photo albums cache
808 Photo::clearAlbumCache($page_owner_uid);
810 Hook::callAll('photo_post_end', $item_id);
812 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
813 // if they do not wish to be redirected
815 $a->internalRedirect($_SESSION['photo_return']);
819 function photos_content(App $a)
823 // photos/name/upload
824 // photos/name/upload/xxxxx (xxxxx is album name)
825 // photos/name/album/xxxxx
826 // photos/name/album/xxxxx/edit
827 // photos/name/album/xxxxx/drop
828 // photos/name/image/xxxxx
829 // photos/name/image/xxxxx/edit
830 // photos/name/image/xxxxx/drop
832 if (Config::get('system', 'block_public') && !Session::isAuthenticated()) {
833 notice(L10n::t('Public access denied.') . EOL);
837 if (empty($a->data['user'])) {
838 notice(L10n::t('No photos selected') . EOL);
842 $phototypes = Image::supportedTypes();
844 $_SESSION['photo_return'] = $a->cmd;
849 $datatype = $a->argv[2];
850 $datum = $a->argv[3];
851 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
852 $datatype = 'upload';
854 $datatype = 'summary';
863 // Setup permissions structures
867 $remote_contact = false;
872 $owner_uid = $a->data['user']['uid'];
874 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
876 if (local_user() && (local_user() == $owner_uid)) {
878 } elseif ($community_page && !empty(Session::getRemoteContactID($owner_uid))) {
879 $contact_id = Session::getRemoteContactID($owner_uid);
880 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
882 if (DBA::isResult($contact)) {
884 $remote_contact = true;
885 $visitor = $contact_id;
889 // perhaps they're visiting - but not a community page, so they wouldn't have write access
890 if (!empty(Session::getRemoteContactID($owner_uid)) && !$visitor) {
891 $contact_id = Session::getRemoteContactID($owner_uid);
893 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
895 $remote_contact = DBA::isResult($contact);
898 if (!$remote_contact && local_user()) {
899 $contact_id = $_SESSION['cid'];
900 $contact = $a->contact;
903 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
904 notice(L10n::t('Access to this item is restricted.') . EOL);
908 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid);
913 $is_owner = (local_user() && (local_user() == $owner_uid));
914 $o .= Profile::getTabs($a, 'photos', $is_owner, $a->data['user']['nickname']);
916 // Display upload form
917 if ($datatype === 'upload') {
919 notice(L10n::t('Permission denied.'));
923 $selname = Strings::isHex($datum) ? hex2bin($datum) : '';
927 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '><current year></option>';
928 if (!empty($a->data['albums'])) {
929 foreach ($a->data['albums'] as $album) {
930 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos'))) {
933 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
934 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
940 $ret = ['post_url' => 'photos/' . $a->data['user']['nickname'],
941 'addon_text' => $uploader,
942 'default_upload' => true];
944 Hook::callAll('photo_upload_form',$ret);
946 $default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
947 $default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
948 '$submit' => L10n::t('Submit'),
953 $tpl = Renderer::getMarkupTemplate('photos_upload.tpl');
955 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML($a->user));
957 $o .= Renderer::replaceMacros($tpl,[
958 '$pagename' => L10n::t('Upload Photos'),
959 '$sessid' => session_id(),
960 '$usage' => $usage_message,
961 '$nickname' => $a->data['user']['nickname'],
962 '$newalbum' => L10n::t('New album name: '),
963 '$existalbumtext' => L10n::t('or select existing album:'),
964 '$nosharetext' => L10n::t('Do not show a status post for this upload'),
965 '$albumselect' => $albumselect,
966 '$permissions' => L10n::t('Permissions'),
967 '$aclselect' => $aclselect_e,
968 '$lockstate' => is_array($a->user)
969 && (strlen($a->user['allow_cid'])
970 || strlen($a->user['allow_gid'])
971 || strlen($a->user['deny_cid'])
972 || strlen($a->user['deny_gid'])
973 ) ? 'lock' : 'unlock',
974 '$alt_uploader' => $ret['addon_text'],
975 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
976 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
977 '$uploadurl' => $ret['post_url'],
979 // ACL permissions box
980 '$group_perms' => L10n::t('Show to Groups'),
981 '$contact_perms' => L10n::t('Show to Contacts'),
982 '$return_path' => $a->query_string,
988 // Display a single photo album
989 if ($datatype === 'album') {
990 // if $datum is not a valid hex, redirect to the default page
991 if (!Strings::isHex($datum)) {
992 $a->internalRedirect('photos/' . $a->data['user']['nickname']. '/album');
994 $album = hex2bin($datum);
997 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
998 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1002 if (DBA::isResult($r)) {
1006 $pager = new Pager($a->query_string, 20);
1008 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1009 $order_field = defaults($_GET, 'order', '');
1010 if ($order_field === 'posted') {
1016 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1017 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1018 ANY_VALUE(`created`) as `created`
1019 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1020 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1022 DBA::escape($album),
1024 $pager->getItemsPerPage()
1027 if ($cmd === 'drop') {
1028 $drop_url = $a->query_string;
1031 ['name' => 'albumname', 'value' => $_POST['albumname']],
1034 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1035 '$method' => 'post',
1036 '$message' => L10n::t('Do you really want to delete this photo album and all its photos?'),
1037 '$extra_inputs' => $extra_inputs,
1038 '$confirm' => L10n::t('Delete Album'),
1039 '$confirm_url' => $drop_url,
1040 '$confirm_name' => 'dropalbum',
1041 '$cancel' => L10n::t('Cancel'),
1046 if ($cmd === 'edit') {
1047 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos'))) {
1049 $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
1053 $o .= Renderer::replaceMacros($edit_tpl,[
1054 '$nametext' => L10n::t('New album name: '),
1055 '$nickname' => $a->data['user']['nickname'],
1056 '$album' => $album_e,
1057 '$hexalbum' => bin2hex($album),
1058 '$submit' => L10n::t('Submit'),
1059 '$dropsubmit' => L10n::t('Delete Album')
1064 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos')) && $can_post) {
1065 $edit = [L10n::t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1066 $drop = [L10n::t('Drop Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/drop'];
1070 if ($order_field === 'posted') {
1071 $order = [L10n::t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1073 $order = [L10n::t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted', 'newest'];
1078 if (DBA::isResult($r)) {
1079 // "Twist" is only used for the duepunto theme with style "slackr"
1081 foreach ($r as $rr) {
1084 $ext = $phototypes[$rr['type']];
1086 $imgalt_e = $rr['filename'];
1087 $desc_e = $rr['desc'];
1091 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1092 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1093 . ($order_field === 'posted' ? '?f=&order=posted' : ''),
1094 'title' => L10n::t('View Photo'),
1095 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1099 'hash'=> $rr['resource-id'],
1104 $tpl = Renderer::getMarkupTemplate('photo_album.tpl');
1105 $o .= Renderer::replaceMacros($tpl, [
1106 '$photos' => $photos,
1108 '$can_post' => $can_post,
1109 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)],
1113 '$paginate' => $pager->renderFull($total),
1120 // Display one photo
1121 if ($datatype === 'image') {
1122 // fetch image, item containing image, then comments
1123 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1124 $sql_extra ORDER BY `scale` ASC ",
1129 if (!DBA::isResult($ph)) {
1130 if (DBA::exists('photo', ['resource-id' => $datum, 'uid' => $owner_uid])) {
1131 notice(L10n::t('Permission denied. Access to this item may be restricted.'));
1133 notice(L10n::t('Photo not available') . EOL);
1138 if ($cmd === 'drop') {
1139 $drop_url = $a->query_string;
1141 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1142 '$method' => 'post',
1143 '$message' => L10n::t('Do you really want to delete this photo?'),
1144 '$extra_inputs' => [],
1145 '$confirm' => L10n::t('Delete Photo'),
1146 '$confirm_url' => $drop_url,
1147 '$confirm_name' => 'delete',
1148 '$cancel' => L10n::t('Cancel'),
1156 * @todo This query is totally bad, the whole functionality has to be changed
1157 * The query leads to a really intense used index.
1158 * By now we hide it if someone wants to.
1160 if ($cmd === 'view' && !Config::get('system', 'no_count', false)) {
1161 $order_field = defaults($_GET, 'order', '');
1163 if ($order_field === 'posted') {
1169 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1170 $sql_extra ORDER BY `created` $order ",
1171 DBA::escape($ph[0]['album']),
1175 if (DBA::isResult($prvnxt)) {
1178 foreach ($prvnxt as $z => $entry) {
1179 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1183 $prv = count($prvnxt) - 1;
1185 if ($nxt >= count($prvnxt)) {
1192 if (!is_null($prv)) {
1193 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . ($order_field === 'posted' ? '?f=&order=posted' : '');
1195 if (!is_null($nxt)) {
1196 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . ($order_field === 'posted' ? '?f=&order=posted' : '');
1199 $tpl = Renderer::getMarkupTemplate('photo_edit_head.tpl');
1200 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl,[
1201 '$prevlink' => $prevlink,
1202 '$nextlink' => $nextlink
1206 $prevlink = [$prevlink, '<div class="icon prev"></div>'];
1210 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1215 if (count($ph) == 1) {
1216 $hires = $lores = $ph[0];
1219 if (count($ph) > 1) {
1220 if ($ph[1]['scale'] == 2) {
1221 // original is 640 or less, we can display it directly
1222 $hires = $lores = $ph[0];
1229 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1233 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1235 if ($cmd === 'edit') {
1236 $tools['view'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum, L10n::t('View photo')];
1238 $tools['edit'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/edit', L10n::t('Edit photo')];
1239 $tools['delete'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/drop', L10n::t('Delete photo')];
1240 $tools['profile'] = ['profile_photo/use/'.$ph[0]['resource-id'], L10n::t('Use as profile photo')];
1244 $ph[0]['uid'] == local_user()
1245 && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']))
1247 $tools['lock'] = L10n::t('Private Photo');
1252 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1253 'title'=> L10n::t('View Full Size'),
1254 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . DateTimeFormat::utcNow('ymdhis'),
1255 'height' => $hires['height'],
1256 'width' => $hires['width'],
1257 'album' => $hires['album'],
1258 'filename' => $hires['filename'],
1265 // Do we have an item for this photo?
1267 // FIXME! - replace following code to display the conversation with our normal
1268 // conversation functions so that it works correctly and tracks changes
1269 // in the evolving conversation code.
1270 // The difference is that we won't be displaying the conversation head item
1271 // as a "post" but displaying instead the photo it is linked to
1273 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1274 $linked_items = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1277 if (DBA::isResult($linked_items)) {
1278 // This is a workaround to not being forced to rewrite the while $sql_extra handling
1279 $link_item = Item::selectFirst([], ['id' => $linked_items[0]['id']]);
1282 if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
1283 $condition = ["`parent` = ? AND `parent` != `id`", $link_item['parent']];
1284 $total = DBA::count('item', $condition);
1286 $pager = new Pager($a->query_string);
1288 $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1289 $result = Item::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params);
1290 $items = Item::inArray($result);
1292 if (local_user() == $link_item['uid']) {
1293 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1297 if (!empty($link_item['coord'])) {
1298 $map = Map::byCoordinates($link_item['coord']);
1303 if (!empty($link_item['id']) && !empty($link_item['tag'])) {
1304 $arr = explode(',', $link_item['tag']);
1305 // parse tags and add links
1307 foreach ($arr as $tag) {
1309 'name' => BBCode::convert($tag),
1310 'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag)
1313 $tags = ['title' => L10n::t('Tags: '), 'tags' => $tag_arr];
1314 if ($cmd === 'edit') {
1315 $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
1316 $tags['removetitle'] = L10n::t('[Select tags to remove]');
1322 if ($cmd === 'edit' && $can_post) {
1323 $edit_tpl = Renderer::getMarkupTemplate('photo_edit.tpl');
1325 $album_e = $ph[0]['album'];
1326 $caption_e = $ph[0]['desc'];
1327 $aclselect_e = ACL::getFullSelectorHTML($a->user, false, $ph[0]);
1329 $edit = Renderer::replaceMacros($edit_tpl, [
1330 '$id' => $ph[0]['id'],
1331 '$album' => ['albname', L10n::t('New album name'), $album_e,''],
1332 '$caption' => ['desc', L10n::t('Caption'), $caption_e, ''],
1333 '$tags' => ['newtag', L10n::t('Add a Tag'), "", L10n::t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1334 '$rotate_none' => ['rotate', L10n::t('Do not rotate'),0,'', true],
1335 '$rotate_cw' => ['rotate', L10n::t("Rotate CW \x28right\x29"),1,''],
1336 '$rotate_ccw' => ['rotate', L10n::t("Rotate CCW \x28left\x29"),2,''],
1338 '$nickname' => $a->data['user']['nickname'],
1339 '$resource_id' => $ph[0]['resource-id'],
1340 '$permissions' => L10n::t('Permissions'),
1341 '$aclselect' => $aclselect_e,
1343 '$item_id' => $link_item['id'] ?? 0,
1344 '$submit' => L10n::t('Submit'),
1345 '$delete' => L10n::t('Delete Photo'),
1347 // ACL permissions box
1348 '$group_perms' => L10n::t('Show to Groups'),
1349 '$contact_perms' => L10n::t('Show to Contacts'),
1350 '$return_path' => $a->query_string,
1361 if (!empty($link_item['id']) && !empty($link_item['uri'])) {
1362 $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
1363 $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
1364 $return_path = $a->cmd;
1366 if ($cmd === 'view' && ($can_post || Security::canWriteToUserWall($owner_uid))) {
1367 $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl');
1368 $likebuttons = Renderer::replaceMacros($like_tpl, [
1369 '$id' => $link_item['id'],
1370 '$likethis' => L10n::t("I like this \x28toggle\x29"),
1371 '$nolike' => L10n::t("I don't like this \x28toggle\x29"),
1372 '$wait' => L10n::t('Please wait'),
1373 '$return_path' => $a->query_string,
1377 if (!DBA::isResult($items)) {
1378 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1379 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1380 '$return_path' => '',
1381 '$jsreload' => $return_path,
1382 '$id' => $link_item['id'],
1383 '$parent' => $link_item['id'],
1384 '$profile_uid' => $owner_uid,
1385 '$mylink' => $contact['url'],
1386 '$mytitle' => L10n::t('This is you'),
1387 '$myphoto' => $contact['thumb'],
1388 '$comment' => L10n::t('Comment'),
1389 '$submit' => L10n::t('Submit'),
1390 '$preview' => L10n::t('Preview'),
1391 '$sourceapp' => L10n::t($a->sourcename),
1393 '$rand_num' => Crypto::randomDigits(12)
1399 'like' => ['title' => L10n::t('Likes','title')],'dislike' => ['title' => L10n::t('Dislikes','title')],
1400 'attendyes' => ['title' => L10n::t('Attending','title')], 'attendno' => ['title' => L10n::t('Not attending','title')], 'attendmaybe' => ['title' => L10n::t('Might attend','title')]
1404 if (DBA::isResult($items)) {
1405 foreach ($items as $item) {
1406 builtin_activity_puller($item, $conv_responses);
1409 if (!empty($conv_responses['like'][$link_item['uri']])) {
1410 $like = format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like', $link_item['id']);
1413 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1414 $dislike = format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike', $link_item['id']);
1417 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1418 $comments .= Renderer::replaceMacros($cmnt_tpl,[
1419 '$return_path' => '',
1420 '$jsreload' => $return_path,
1421 '$id' => $link_item['id'],
1422 '$parent' => $link_item['id'],
1423 '$profile_uid' => $owner_uid,
1424 '$mylink' => $contact['url'],
1425 '$mytitle' => L10n::t('This is you'),
1426 '$myphoto' => $contact['thumb'],
1427 '$comment' => L10n::t('Comment'),
1428 '$submit' => L10n::t('Submit'),
1429 '$preview' => L10n::t('Preview'),
1430 '$sourceapp' => L10n::t($a->sourcename),
1432 '$rand_num' => Crypto::randomDigits(12)
1436 foreach ($items as $item) {
1441 if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) {
1445 $profile_url = Contact::magicLinkbyId($item['author-id']);
1446 if (strpos($profile_url, 'redir/') === 0) {
1447 $sparkle = ' sparkle';
1452 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1454 'dropping' => $dropping,
1455 'pagedrop' => false,
1456 'select' => L10n::t('Select'),
1457 'delete' => L10n::t('Delete'),
1460 $title_e = $item['title'];
1461 $body_e = BBCode::convert($item['body']);
1463 $comments .= Renderer::replaceMacros($template,[
1464 '$id' => $item['id'],
1465 '$profile_url' => $profile_url,
1466 '$name' => $item['author-name'],
1467 '$thumb' => $item['author-avatar'],
1468 '$sparkle' => $sparkle,
1469 '$title' => $title_e,
1471 '$ago' => Temporal::getRelativeDate($item['created']),
1472 '$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''),
1474 '$comment' => $comment
1477 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1478 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1479 '$return_path' => '',
1480 '$jsreload' => $return_path,
1481 '$id' => $item['id'],
1482 '$parent' => $item['parent'],
1483 '$profile_uid' => $owner_uid,
1484 '$mylink' => $contact['url'],
1485 '$mytitle' => L10n::t('This is you'),
1486 '$myphoto' => $contact['thumb'],
1487 '$comment' => L10n::t('Comment'),
1488 '$submit' => L10n::t('Submit'),
1489 '$preview' => L10n::t('Preview'),
1490 '$sourceapp' => L10n::t($a->sourcename),
1492 '$rand_num' => Crypto::randomDigits(12)
1497 $response_verbs = ['like'];
1498 $response_verbs[] = 'dislike';
1499 $responses = get_responses($conv_responses, $response_verbs, $link_item);
1501 $paginate = $pager->renderFull($total);
1504 $photo_tpl = Renderer::getMarkupTemplate('photo_view.tpl');
1505 $o .= Renderer::replaceMacros($photo_tpl, [
1506 '$id' => $ph[0]['id'],
1507 '$album' => [$album_link, $ph[0]['album']],
1510 '$prevlink' => $prevlink,
1511 '$nextlink' => $nextlink,
1512 '$desc' => $ph[0]['desc'],
1516 '$map_text' => L10n::t('Map'),
1517 '$likebuttons' => $likebuttons,
1519 '$dislike' => $dislike,
1520 'responses' => $responses,
1521 '$comments' => $comments,
1522 '$paginate' => $paginate,
1525 $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
1526 $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1527 $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . System::baseUrl() . "/" . $photo["href"] . '" />' . "\n";
1528 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1529 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1534 // Default - show recent photos with upload link (if applicable)
1537 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1538 $sql_extra GROUP BY `resource-id`",
1539 intval($a->data['user']['uid']),
1540 DBA::escape('Contact Photos'),
1541 DBA::escape(L10n::t('Contact Photos'))
1543 if (DBA::isResult($r)) {
1547 $pager = new Pager($a->query_string, 20);
1549 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1550 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1551 ANY_VALUE(`created`) AS `created` FROM `photo`
1552 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1553 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1554 intval($a->data['user']['uid']),
1555 DBA::escape('Contact Photos'),
1556 DBA::escape(L10n::t('Contact Photos')),
1558 $pager->getItemsPerPage()
1562 if (DBA::isResult($r)) {
1563 // "Twist" is only used for the duepunto theme with style "slackr"
1565 foreach ($r as $rr) {
1566 //hide profile photos to others
1567 if (!$is_owner && !Session::getRemoteContactID($owner_uid) && ($rr['album'] == L10n::t('Profile Photos'))) {
1572 $ext = $phototypes[$rr['type']];
1574 $alt_e = $rr['filename'];
1575 $name_e = $rr['album'];
1579 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1580 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1581 'title' => L10n::t('View Photo'),
1582 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1585 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1587 'alt' => L10n::t('View Album'),
1594 $tpl = Renderer::getMarkupTemplate('photos_recent.tpl');
1595 $o .= Renderer::replaceMacros($tpl, [
1596 '$title' => L10n::t('Recent Photos'),
1597 '$can_post' => $can_post,
1598 '$upload' => [L10n::t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'],
1599 '$photos' => $photos,
1600 '$paginate' => $pager->renderFull($total),