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 = $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 $album = hex2bin($a->argv[3]);
193 if ($album === L10n::t('Profile Photos') || $album === 'Contact Photos' || $album === L10n::t('Contact Photos')) {
194 $a->internalRedirect($_SESSION['photo_return']);
195 return; // NOTREACHED
198 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
200 intval($page_owner_uid)
203 if (!DBA::isResult($r)) {
204 notice(L10n::t('Album not found.') . EOL);
205 $a->internalRedirect($_SESSION['photo_return']);
206 return; // NOTREACHED
209 // Check if the user has responded to a delete confirmation query
210 if (!empty($_REQUEST['canceled'])) {
211 $a->internalRedirect($_SESSION['photo_return']);
214 // RENAME photo album
215 $newalbum = Strings::escapeTags(trim($_POST['albumname']));
216 if ($newalbum != $album) {
217 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
218 DBA::escape($newalbum),
220 intval($page_owner_uid)
222 // Update the photo albums cache
223 Photo::clearAlbumCache($page_owner_uid);
225 $a->internalRedirect('photos/' . $a->user['nickname'] . '/album/' . bin2hex($newalbum));
226 return; // NOTREACHED
230 * DELETE all photos filed in a given album
232 if (!empty($_POST['dropalbum'])) {
235 // get the list of photos we are about to delete
237 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
239 intval($page_owner_uid),
243 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
244 intval(local_user()),
249 if (DBA::isResult($r)) {
250 foreach ($r as $rr) {
254 // remove the associated photos
255 Photo::delete(['resource-id' => $res, 'uid' => $page_owner_uid]);
257 // find and delete the corresponding item with all the comments and likes/dislikes
258 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
260 // Update the photo albums cache
261 Photo::clearAlbumCache($page_owner_uid);
262 notice(L10n::t('Album successfully deleted'));
264 notice(L10n::t('Album was empty.'));
268 $a->internalRedirect('photos/' . $a->argv[1]);
271 if ($a->argc > 3 && $a->argv[2] === 'image') {
272 // Check if the user has responded to a delete confirmation query for a single photo
273 if (!empty($_POST['canceled'])) {
274 $a->internalRedirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]);
277 if (!empty($_POST['delete'])) {
278 // same as above but remove single photo
280 $condition = ['contact-id' => $visitor, 'uid' => $page_owner_uid, 'resource-id' => $a->argv[3]];
283 $condition = ['uid' => local_user(), 'resource-id' => $a->argv[3]];
286 $photo = DBA::selectFirst('photo', ['resource-id'], $condition);
288 if (DBA::isResult($photo)) {
289 Photo::delete(['uid' => $page_owner_uid, 'resource-id' => $photo['resource-id']]);
291 Item::deleteForUser(['resource-id' => $photo['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
293 // Update the photo albums cache
294 Photo::clearAlbumCache($page_owner_uid);
295 notice('Successfully deleted the photo.');
297 notice('Failed to delete the photo.');
298 $a->internalRedirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]);
301 $a->internalRedirect('photos/' . $a->argv[1]);
302 return; // NOTREACHED
306 if ($a->argc > 2 && (!empty($_POST['desc']) || !empty($_POST['newtag']) || isset($_POST['albname']))) {
307 $desc = !empty($_POST['desc']) ? Strings::escapeTags(trim($_POST['desc'])) : '';
308 $rawtags = !empty($_POST['newtag']) ? Strings::escapeTags(trim($_POST['newtag'])) : '';
309 $item_id = !empty($_POST['item_id']) ? intval($_POST['item_id']) : 0;
310 $albname = !empty($_POST['albname']) ? Strings::escapeTags(trim($_POST['albname'])) : '';
311 $origaname = !empty($_POST['origaname']) ? Strings::escapeTags(trim($_POST['origaname'])) : '';
313 $str_group_allow = !empty($_POST['group_allow']) ? perms2str($_POST['group_allow']) : '';
314 $str_contact_allow = !empty($_POST['contact_allow']) ? perms2str($_POST['contact_allow']) : '';
315 $str_group_deny = !empty($_POST['group_deny']) ? perms2str($_POST['group_deny']) : '';
316 $str_contact_deny = !empty($_POST['contact_deny']) ? perms2str($_POST['contact_deny']) : '';
318 $resource_id = $a->argv[3];
320 if (!strlen($albname)) {
321 $albname = DateTimeFormat::localNow('Y');
324 if (!empty($_POST['rotate']) && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
325 Logger::log('rotate');
327 $photo = Photo::getPhotoForUser($page_owner_uid, $resource_id);
329 if (DBA::isResult($photo)) {
330 $image = Photo::getImageForPhoto($photo);
332 if ($image->isValid()) {
333 $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
334 $image->rotate($rotate_deg);
336 $width = $image->getWidth();
337 $height = $image->getHeight();
339 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 0], $image);
341 if ($width > 640 || $height > 640) {
342 $image->scaleDown(640);
343 $width = $image->getWidth();
344 $height = $image->getHeight();
346 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 1], $image);
349 if ($width > 320 || $height > 320) {
350 $image->scaleDown(320);
351 $width = $image->getWidth();
352 $height = $image->getHeight();
354 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 2], $image);
360 $photos_stmt = DBA::select('photo', [], ['resource-id' => $resource_id, 'uid' => $page_owner_uid], ['order' => ['scale' => true]]);
362 $photos = DBA::toArray($photos_stmt);
364 if (DBA::isResult($photos)) {
366 $ext = $phototypes[$photo['type']];
368 ['desc' => $desc, 'album' => $albname, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow, 'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny],
369 ['resource-id' => $resource_id, 'uid' => $page_owner_uid]
372 // Update the photo albums cache if album name was changed
373 if ($albname !== $origaname) {
374 Photo::clearAlbumCache($page_owner_uid);
376 /* Don't make the item visible if the only change was the album name */
379 if ($photo['desc'] !== $desc || strlen($rawtags)) {
384 if (DBA::isResult($photos) && !$item_id) {
385 // Create item container
387 $uri = Item::newURI($page_owner_uid);
390 $arr['guid'] = System::createUUID();
391 $arr['uid'] = $page_owner_uid;
393 $arr['parent-uri'] = $uri;
394 $arr['post-type'] = Item::PT_IMAGE;
396 $arr['resource-id'] = $photo['resource-id'];
397 $arr['contact-id'] = $owner_record['id'];
398 $arr['owner-name'] = $owner_record['name'];
399 $arr['owner-link'] = $owner_record['url'];
400 $arr['owner-avatar'] = $owner_record['thumb'];
401 $arr['author-name'] = $owner_record['name'];
402 $arr['author-link'] = $owner_record['url'];
403 $arr['author-avatar'] = $owner_record['thumb'];
404 $arr['title'] = $title;
405 $arr['allow_cid'] = $photo['allow_cid'];
406 $arr['allow_gid'] = $photo['allow_gid'];
407 $arr['deny_cid'] = $photo['deny_cid'];
408 $arr['deny_gid'] = $photo['deny_gid'];
409 $arr['visible'] = $visibility;
412 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $photo['resource-id'] . ']'
413 . '[img]' . System::baseUrl() . '/photo/' . $photo['resource-id'] . '-' . $photo['scale'] . '.'. $ext . '[/img]'
416 $item_id = Item::insert($arr);
420 $item = Item::selectFirst(['tag', 'inform'], ['id' => $item_id, 'uid' => $page_owner_uid]);
422 if (DBA::isResult($item)) {
423 $old_tag = $item['tag'];
424 $old_inform = $item['inform'];
428 if (strlen($rawtags)) {
432 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
433 $x = substr($rawtags, 0, 1);
434 if ($x !== '@' && $x !== '#') {
435 $rawtags = '#' . $rawtags;
439 $tags = BBCode::getTags($rawtags);
442 foreach ($tags as $tag) {
443 if (strpos($tag, '@') === 0) {
446 $name = substr($tag,1);
448 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
450 $links = @Probe::lrdd($name);
453 foreach ($links as $link) {
454 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
455 $profile = $link['@attributes']['href'];
458 if ($link['@attributes']['rel'] === 'salmon') {
459 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
461 if (strlen($inform)) {
470 $taginfo[] = [$newname, $profile, $salmon];
475 if (strrpos($newname, '+')) {
476 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
480 $contact = DBA::selectFirst('contact', [], ['id' => $tagcid, 'uid' => $page_owner_uid]);
482 $newname = str_replace('_',' ',$name);
484 //select someone from this user's contacts by name
485 $contact = DBA::selectFirst('contact', [], ['name' => $newname, 'uid' => $page_owner_uid]);
486 if (!DBA::isResult($contact)) {
487 //select someone by attag or nick and the name passed in
488 $contact = DBA::selectFirst('contact', [],
489 ['(`attag` = ? OR `nick` = ?) AND `uid` = ?', $name, $name, $page_owner_uid],
490 ['order' => ['attag' => true]]
495 if (DBA::isResult($contact)) {
496 $newname = $contact['name'];
497 $profile = $contact['url'];
499 $notify = 'cid:' . $contact['id'];
500 if (strlen($inform)) {
508 if (!empty($contact)) {
509 $taginfo[] = [$newname, $profile, $notify, $contact, '@[url=' . str_replace(',', '%2c', $profile) . ']' . $newname . '[/url]'];
511 $taginfo[] = [$newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'];
514 if (strlen($str_tags)) {
518 $profile = str_replace(',', '%2c', $profile);
519 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
521 } elseif (strpos($tag, '#') === 0) {
522 $tagname = substr($tag, 1);
523 $str_tags .= '#[url=' . System::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url],';
528 $newtag = $old_tag ?? '';
529 if (strlen($newtag) && strlen($str_tags)) {
532 $newtag .= $str_tags;
534 $newinform = $old_inform ?? '';
535 if (strlen($newinform) && strlen($inform)) {
538 $newinform .= $inform;
540 $fields = ['tag' => $newtag, 'inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
541 $condition = ['id' => $item_id];
542 Item::update($fields, $condition);
545 foreach ($photos as $scales) {
546 if (intval($scales['scale']) == 2) {
551 if (intval($scales['scale']) == 4) {
557 if (count($taginfo)) {
558 foreach ($taginfo as $tagged) {
559 $uri = Item::newURI($page_owner_uid);
562 $arr['guid'] = System::createUUID();
563 $arr['uid'] = $page_owner_uid;
565 $arr['parent-uri'] = $uri;
567 $arr['contact-id'] = $owner_record['id'];
568 $arr['owner-name'] = $owner_record['name'];
569 $arr['owner-link'] = $owner_record['url'];
570 $arr['owner-avatar'] = $owner_record['thumb'];
571 $arr['author-name'] = $owner_record['name'];
572 $arr['author-link'] = $owner_record['url'];
573 $arr['author-avatar'] = $owner_record['thumb'];
575 $arr['allow_cid'] = $photo['allow_cid'];
576 $arr['allow_gid'] = $photo['allow_gid'];
577 $arr['deny_cid'] = $photo['deny_cid'];
578 $arr['deny_gid'] = $photo['deny_gid'];
580 $arr['verb'] = ACTIVITY_TAG;
581 $arr['gravity'] = GRAVITY_PARENT;
582 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
583 $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
584 $arr['tag'] = $tagged[4];
585 $arr['inform'] = $tagged[2];
587 $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]') ;
588 $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" ;
590 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
591 $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
593 $arr['object'] .= XML::escape('<link rel="photo" type="' . $photo['type'] . '" href="' . $tagged[3]['photo'] . '" />' . "\n");
595 $arr['object'] .= '</link></object>' . "\n";
597 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $photo['desc'] . '</title><id>'
598 . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '</id>';
599 $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>';
605 $a->internalRedirect($_SESSION['photo_return']);
606 return; // NOTREACHED
610 // default post action - upload a photo
611 Hook::callAll('photo_post_init', $_POST);
613 // Determine the album to use
614 $album = !empty($_REQUEST['album']) ? Strings::escapeTags(trim($_REQUEST['album'])) : '';
615 $newalbum = !empty($_REQUEST['newalbum']) ? Strings::escapeTags(trim($_REQUEST['newalbum'])) : '';
617 Logger::log('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , Logger::DEBUG);
619 if (!strlen($album)) {
620 if (strlen($newalbum)) {
623 $album = DateTimeFormat::localNow('Y');
628 * We create a wall item for every photo, but we don't want to
629 * overwhelm the data stream with a hundred newly uploaded photos.
630 * So we will make the first photo uploaded to this album in the last several hours
631 * visible by default, the rest will become visible over time when and if
632 * they acquire comments, likes, dislikes, and/or tags
635 $r = Photo::select([], ['`album` = ? AND `uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR', $album, $page_owner_uid]);
637 if (!DBA::isResult($r) || ($album == L10n::t('Profile Photos'))) {
643 if (!empty($_REQUEST['not_visible']) && $_REQUEST['not_visible'] !== 'false') {
647 $group_allow = defaults($_REQUEST, 'group_allow' , []);
648 $contact_allow = defaults($_REQUEST, 'contact_allow', []);
649 $group_deny = defaults($_REQUEST, 'group_deny' , []);
650 $contact_deny = defaults($_REQUEST, 'contact_deny' , []);
652 $str_group_allow = perms2str(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
653 $str_contact_allow = perms2str(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
654 $str_group_deny = perms2str(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
655 $str_contact_deny = perms2str(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
657 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
659 Hook::callAll('photo_post_file', $ret);
661 if (!empty($ret['src']) && !empty($ret['filesize'])) {
663 $filename = $ret['filename'];
664 $filesize = $ret['filesize'];
665 $type = $ret['type'];
666 $error = UPLOAD_ERR_OK;
667 } elseif (!empty($_FILES['userfile'])) {
668 $src = $_FILES['userfile']['tmp_name'];
669 $filename = basename($_FILES['userfile']['name']);
670 $filesize = intval($_FILES['userfile']['size']);
671 $type = $_FILES['userfile']['type'];
672 $error = $_FILES['userfile']['error'];
674 $error = UPLOAD_ERR_NO_FILE;
677 if ($error !== UPLOAD_ERR_OK) {
679 case UPLOAD_ERR_INI_SIZE:
680 notice(L10n::t('Image exceeds size limit of %s', ini_get('upload_max_filesize')) . EOL);
682 case UPLOAD_ERR_FORM_SIZE:
683 notice(L10n::t('Image exceeds size limit of %s', Strings::formatBytes(defaults($_REQUEST, 'MAX_FILE_SIZE', 0))) . EOL);
685 case UPLOAD_ERR_PARTIAL:
686 notice(L10n::t('Image upload didn\'t complete, please try again') . EOL);
688 case UPLOAD_ERR_NO_FILE:
689 notice(L10n::t('Image file is missing') . EOL);
691 case UPLOAD_ERR_NO_TMP_DIR:
692 case UPLOAD_ERR_CANT_WRITE:
693 case UPLOAD_ERR_EXTENSION:
694 notice(L10n::t('Server can\'t accept new file upload at this time, please contact your administrator') . EOL);
699 Hook::callAll('photo_post_end', $foo);
704 $type = Image::guessType($filename);
707 Logger::log('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', Logger::DEBUG);
709 $maximagesize = Config::get('system', 'maximagesize');
711 if ($maximagesize && ($filesize > $maximagesize)) {
712 notice(L10n::t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)) . EOL);
715 Hook::callAll('photo_post_end', $foo);
720 notice(L10n::t('Image file is empty.') . EOL);
723 Hook::callAll('photo_post_end', $foo);
727 Logger::log('mod/photos.php: photos_post(): loading the contents of ' . $src , Logger::DEBUG);
729 $imagedata = @file_get_contents($src);
731 $image = new Image($imagedata, $type);
733 if (!$image->isValid()) {
734 Logger::log('mod/photos.php: photos_post(): unable to process image' , Logger::DEBUG);
735 notice(L10n::t('Unable to process image.') . EOL);
738 Hook::callAll('photo_post_end',$foo);
742 $exif = $image->orient($src);
745 $max_length = Config::get('system', 'max_image_length');
747 $max_length = MAX_IMAGE_LENGTH;
749 if ($max_length > 0) {
750 $image->scaleDown($max_length);
753 $width = $image->getWidth();
754 $height = $image->getHeight();
758 $photo_hash = Photo::newResource();
760 $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);
763 Logger::log('mod/photos.php: photos_post(): image store failed', Logger::DEBUG);
764 notice(L10n::t('Image upload failed.') . EOL);
768 if ($width > 640 || $height > 640) {
769 $image->scaleDown(640);
770 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);
774 if ($width > 320 || $height > 320) {
775 $image->scaleDown(320);
776 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);
780 $uri = Item::newURI($page_owner_uid);
782 // Create item container
784 if ($exif && $exif['GPS'] && Feature::isEnabled($page_owner_uid, 'photo_location')) {
785 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
786 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
791 $arr['coord'] = $lat . ' ' . $lon;
794 $arr['guid'] = System::createUUID();
795 $arr['uid'] = $page_owner_uid;
797 $arr['parent-uri'] = $uri;
798 $arr['type'] = 'photo';
800 $arr['resource-id'] = $photo_hash;
801 $arr['contact-id'] = $owner_record['id'];
802 $arr['owner-name'] = $owner_record['name'];
803 $arr['owner-link'] = $owner_record['url'];
804 $arr['owner-avatar'] = $owner_record['thumb'];
805 $arr['author-name'] = $owner_record['name'];
806 $arr['author-link'] = $owner_record['url'];
807 $arr['author-avatar'] = $owner_record['thumb'];
809 $arr['allow_cid'] = $str_contact_allow;
810 $arr['allow_gid'] = $str_group_allow;
811 $arr['deny_cid'] = $str_contact_deny;
812 $arr['deny_gid'] = $str_group_deny;
813 $arr['visible'] = $visible;
816 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
817 . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$image->getExt() . '[/img]'
820 $item_id = Item::insert($arr);
821 // Update the photo albums cache
822 Photo::clearAlbumCache($page_owner_uid);
824 Hook::callAll('photo_post_end', $item_id);
826 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
827 // if they do not wish to be redirected
829 $a->internalRedirect($_SESSION['photo_return']);
833 function photos_content(App $a)
837 // photos/name/upload
838 // photos/name/upload/xxxxx (xxxxx is album name)
839 // photos/name/album/xxxxx
840 // photos/name/album/xxxxx/edit
841 // photos/name/album/xxxxx/drop
842 // photos/name/image/xxxxx
843 // photos/name/image/xxxxx/edit
844 // photos/name/image/xxxxx/drop
846 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
847 notice(L10n::t('Public access denied.') . EOL);
851 if (empty($a->data['user'])) {
852 notice(L10n::t('No photos selected') . EOL);
856 $phototypes = Image::supportedTypes();
858 $_SESSION['photo_return'] = $a->cmd;
863 $datatype = $a->argv[2];
864 $datum = $a->argv[3];
865 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
866 $datatype = 'upload';
868 $datatype = 'summary';
877 // Setup permissions structures
881 $remote_contact = false;
886 $owner_uid = $a->data['user']['uid'];
888 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
890 if (local_user() && (local_user() == $owner_uid)) {
893 if ($community_page && remote_user()) {
894 if (is_array($_SESSION['remote'])) {
895 foreach ($_SESSION['remote'] as $v) {
896 if ($v['uid'] == $owner_uid) {
897 $contact_id = $v['cid'];
904 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
906 if (DBA::isResult($contact)) {
908 $remote_contact = true;
909 $visitor = $contact_id;
917 // perhaps they're visiting - but not a community page, so they wouldn't have write access
918 if (remote_user() && !$visitor) {
920 if (is_array($_SESSION['remote'])) {
921 foreach ($_SESSION['remote'] as $v) {
922 if ($v['uid'] == $owner_uid) {
923 $contact_id = $v['cid'];
930 $groups = Group::getIdsByContactId($contact_id);
932 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
934 $remote_contact = DBA::isResult($contact);
938 if (!$remote_contact && local_user()) {
939 $contact_id = $_SESSION['cid'];
940 $contact = $a->contact;
943 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
944 notice(L10n::t('Access to this item is restricted.') . EOL);
948 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid, $remote_contact, $groups);
953 $is_owner = (local_user() && (local_user() == $owner_uid));
954 $o .= Profile::getTabs($a, 'photos', $is_owner, $a->data['user']['nickname']);
956 // Display upload form
957 if ($datatype === 'upload') {
959 notice(L10n::t('Permission denied.'));
963 $selname = $datum ? hex2bin($datum) : '';
967 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '><current year></option>';
968 if (!empty($a->data['albums'])) {
969 foreach ($a->data['albums'] as $album) {
970 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos'))) {
973 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
974 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
980 $ret = ['post_url' => 'photos/' . $a->data['user']['nickname'],
981 'addon_text' => $uploader,
982 'default_upload' => true];
984 Hook::callAll('photo_upload_form',$ret);
986 $default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
987 $default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
988 '$submit' => L10n::t('Submit'),
993 $tpl = Renderer::getMarkupTemplate('photos_upload.tpl');
995 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML($a->user));
997 $o .= Renderer::replaceMacros($tpl,[
998 '$pagename' => L10n::t('Upload Photos'),
999 '$sessid' => session_id(),
1000 '$usage' => $usage_message,
1001 '$nickname' => $a->data['user']['nickname'],
1002 '$newalbum' => L10n::t('New album name: '),
1003 '$existalbumtext' => L10n::t('or select existing album:'),
1004 '$nosharetext' => L10n::t('Do not show a status post for this upload'),
1005 '$albumselect' => $albumselect,
1006 '$permissions' => L10n::t('Permissions'),
1007 '$aclselect' => $aclselect_e,
1008 '$lockstate' => is_array($a->user)
1009 && (strlen($a->user['allow_cid'])
1010 || strlen($a->user['allow_gid'])
1011 || strlen($a->user['deny_cid'])
1012 || strlen($a->user['deny_gid'])
1013 ) ? 'lock' : 'unlock',
1014 '$alt_uploader' => $ret['addon_text'],
1015 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
1016 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
1017 '$uploadurl' => $ret['post_url'],
1019 // ACL permissions box
1020 '$group_perms' => L10n::t('Show to Groups'),
1021 '$contact_perms' => L10n::t('Show to Contacts'),
1022 '$return_path' => $a->query_string,
1028 // Display a single photo album
1029 if ($datatype === 'album') {
1030 // if $datum is not a valid hex, redirect to the default page
1031 if (!Strings::isHex($datum)) {
1032 $a->internalRedirect();
1034 $album = hex2bin($datum);
1037 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1038 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1042 if (DBA::isResult($r)) {
1046 $pager = new Pager($a->query_string, 20);
1048 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1049 $order_field = defaults($_GET, 'order', '');
1050 if ($order_field === 'posted') {
1056 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1057 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1058 ANY_VALUE(`created`) as `created`
1059 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1060 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1062 DBA::escape($album),
1064 $pager->getItemsPerPage()
1067 if ($cmd === 'drop') {
1068 $drop_url = $a->query_string;
1071 ['name' => 'albumname', 'value' => $_POST['albumname']],
1074 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1075 '$method' => 'post',
1076 '$message' => L10n::t('Do you really want to delete this photo album and all its photos?'),
1077 '$extra_inputs' => $extra_inputs,
1078 '$confirm' => L10n::t('Delete Album'),
1079 '$confirm_url' => $drop_url,
1080 '$confirm_name' => 'dropalbum',
1081 '$cancel' => L10n::t('Cancel'),
1086 if ($cmd === 'edit') {
1087 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos'))) {
1089 $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
1093 $o .= Renderer::replaceMacros($edit_tpl,[
1094 '$nametext' => L10n::t('New album name: '),
1095 '$nickname' => $a->data['user']['nickname'],
1096 '$album' => $album_e,
1097 '$hexalbum' => bin2hex($album),
1098 '$submit' => L10n::t('Submit'),
1099 '$dropsubmit' => L10n::t('Delete Album')
1104 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos')) && $can_post) {
1105 $edit = [L10n::t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1106 $drop = [L10n::t('Drop Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/drop'];
1110 if ($order_field === 'posted') {
1111 $order = [L10n::t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1113 $order = [L10n::t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted', 'newest'];
1118 if (DBA::isResult($r)) {
1119 // "Twist" is only used for the duepunto theme with style "slackr"
1121 foreach ($r as $rr) {
1124 $ext = $phototypes[$rr['type']];
1126 $imgalt_e = $rr['filename'];
1127 $desc_e = $rr['desc'];
1131 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1132 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1133 . ($order_field === 'posted' ? '?f=&order=posted' : ''),
1134 'title' => L10n::t('View Photo'),
1135 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1139 'hash'=> $rr['resource-id'],
1144 $tpl = Renderer::getMarkupTemplate('photo_album.tpl');
1145 $o .= Renderer::replaceMacros($tpl, [
1146 '$photos' => $photos,
1148 '$can_post' => $can_post,
1149 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)],
1153 '$paginate' => $pager->renderFull($total),
1160 // Display one photo
1161 if ($datatype === 'image') {
1162 // fetch image, item containing image, then comments
1163 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1164 $sql_extra ORDER BY `scale` ASC ",
1169 if (!DBA::isResult($ph)) {
1170 if (DBA::exists('photo', ['resource-id' => $datum, 'uid' => $owner_uid])) {
1171 notice(L10n::t('Permission denied. Access to this item may be restricted.'));
1173 notice(L10n::t('Photo not available') . EOL);
1178 if ($cmd === 'drop') {
1179 $drop_url = $a->query_string;
1181 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1182 '$method' => 'post',
1183 '$message' => L10n::t('Do you really want to delete this photo?'),
1184 '$extra_inputs' => [],
1185 '$confirm' => L10n::t('Delete Photo'),
1186 '$confirm_url' => $drop_url,
1187 '$confirm_name' => 'delete',
1188 '$cancel' => L10n::t('Cancel'),
1196 * @todo This query is totally bad, the whole functionality has to be changed
1197 * The query leads to a really intense used index.
1198 * By now we hide it if someone wants to.
1200 if ($cmd === 'view' && !Config::get('system', 'no_count', false)) {
1201 $order_field = defaults($_GET, 'order', '');
1203 if ($order_field === 'posted') {
1209 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1210 $sql_extra ORDER BY `created` $order ",
1211 DBA::escape($ph[0]['album']),
1215 if (DBA::isResult($prvnxt)) {
1218 foreach ($prvnxt as $z => $entry) {
1219 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1223 $prv = count($prvnxt) - 1;
1225 if ($nxt >= count($prvnxt)) {
1232 if (!is_null($prv)) {
1233 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . ($order_field === 'posted' ? '?f=&order=posted' : '');
1235 if (!is_null($nxt)) {
1236 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . ($order_field === 'posted' ? '?f=&order=posted' : '');
1239 $tpl = Renderer::getMarkupTemplate('photo_edit_head.tpl');
1240 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl,[
1241 '$prevlink' => $prevlink,
1242 '$nextlink' => $nextlink
1246 $prevlink = [$prevlink, '<div class="icon prev"></div>'];
1250 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1255 if (count($ph) == 1) {
1256 $hires = $lores = $ph[0];
1259 if (count($ph) > 1) {
1260 if ($ph[1]['scale'] == 2) {
1261 // original is 640 or less, we can display it directly
1262 $hires = $lores = $ph[0];
1269 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1273 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1275 if ($cmd === 'edit') {
1276 $tools['view'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum, L10n::t('View photo')];
1278 $tools['edit'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/edit', L10n::t('Edit photo')];
1279 $tools['delete'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/drop', L10n::t('Delete photo')];
1280 $tools['profile'] = ['profile_photo/use/'.$ph[0]['resource-id'], L10n::t('Use as profile photo')];
1284 $ph[0]['uid'] == local_user()
1285 && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']))
1287 $tools['lock'] = L10n::t('Private Photo');
1292 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1293 'title'=> L10n::t('View Full Size'),
1294 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . DateTimeFormat::utcNow('ymdhis'),
1295 'height' => $hires['height'],
1296 'width' => $hires['width'],
1297 'album' => $hires['album'],
1298 'filename' => $hires['filename'],
1301 // Do we have an item for this photo?
1303 // FIXME! - replace following code to display the conversation with our normal
1304 // conversation functions so that it works correctly and tracks changes
1305 // in the evolving conversation code.
1306 // The difference is that we won't be displaying the conversation head item
1307 // as a "post" but displaying instead the photo it is linked to
1309 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1310 $linked_items = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1318 if (DBA::isResult($linked_items)) {
1319 // This is a workaround to not being forced to rewrite the while $sql_extra handling
1320 $link_item = Item::selectFirst([], ['id' => $linked_items[0]['id']]);
1322 $condition = ["`parent` = ? AND `parent` != `id`", $link_item['parent']];
1323 $total = DBA::count('item', $condition);
1325 $pager = new Pager($a->query_string);
1327 $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1328 $result = Item::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params);
1329 $items = Item::inArray($result);
1331 if (local_user() && (local_user() == $link_item['uid'])) {
1332 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1335 if ($link_item['coord']) {
1336 $map = Map::byCoordinates($link_item['coord']);
1342 if (count($linked_items) && strlen($link_item['tag'])) {
1343 $arr = explode(',', $link_item['tag']);
1344 // parse tags and add links
1346 foreach ($arr as $tag) {
1348 'name' => BBCode::convert($tag),
1349 'removeurl' => '/tagrm/'.$link_item['id'] . '/' . bin2hex($tag)
1352 $tags = ['title' => L10n::t('Tags: '), 'tags' => $tag_arr];
1353 if ($cmd === 'edit') {
1354 $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
1355 $tags['removetitle'] = L10n::t('[Select tags to remove]');
1361 if ($cmd === 'edit' && $can_post) {
1362 $edit_tpl = Renderer::getMarkupTemplate('photo_edit.tpl');
1364 $album_e = $ph[0]['album'];
1365 $caption_e = $ph[0]['desc'];
1366 $aclselect_e = ACL::getFullSelectorHTML($a->user, false, $ph[0]);
1368 $edit = Renderer::replaceMacros($edit_tpl, [
1369 '$id' => $ph[0]['id'],
1370 '$album' => ['albname', L10n::t('New album name'), $album_e,''],
1371 '$caption' => ['desc', L10n::t('Caption'), $caption_e, ''],
1372 '$tags' => ['newtag', L10n::t('Add a Tag'), "", L10n::t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1373 '$rotate_none' => ['rotate', L10n::t('Do not rotate'),0,'', true],
1374 '$rotate_cw' => ['rotate', L10n::t("Rotate CW \x28right\x29"),1,''],
1375 '$rotate_ccw' => ['rotate', L10n::t("Rotate CCW \x28left\x29"),2,''],
1377 '$nickname' => $a->data['user']['nickname'],
1378 '$resource_id' => $ph[0]['resource-id'],
1379 '$permissions' => L10n::t('Permissions'),
1380 '$aclselect' => $aclselect_e,
1382 '$item_id' => defaults($link_item, 'id', 0),
1383 '$submit' => L10n::t('Submit'),
1384 '$delete' => L10n::t('Delete Photo'),
1386 // ACL permissions box
1387 '$group_perms' => L10n::t('Show to Groups'),
1388 '$contact_perms' => L10n::t('Show to Contacts'),
1389 '$return_path' => $a->query_string,
1400 if (count($linked_items)) {
1401 $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
1402 $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
1403 $return_path = $a->cmd;
1405 if ($cmd === 'view' && ($can_post || Security::canWriteToUserWall($owner_uid))) {
1406 $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl');
1407 $likebuttons = Renderer::replaceMacros($like_tpl, [
1408 '$id' => $link_item['id'],
1409 '$likethis' => L10n::t("I like this \x28toggle\x29"),
1410 '$nolike' => L10n::t("I don't like this \x28toggle\x29"),
1411 '$wait' => L10n::t('Please wait'),
1412 '$return_path' => $a->query_string,
1416 if (!DBA::isResult($items)) {
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)
1438 'like' => ['title' => L10n::t('Likes','title')],'dislike' => ['title' => L10n::t('Dislikes','title')],
1439 'attendyes' => ['title' => L10n::t('Attending','title')], 'attendno' => ['title' => L10n::t('Not attending','title')], 'attendmaybe' => ['title' => L10n::t('Might attend','title')]
1443 if (DBA::isResult($items)) {
1444 foreach ($items as $item) {
1445 builtin_activity_puller($item, $conv_responses);
1448 if (!empty($conv_responses['like'][$link_item['uri']])) {
1449 $like = format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like', $link_item['id']);
1452 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1453 $dislike = format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike', $link_item['id']);
1456 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1457 $comments .= Renderer::replaceMacros($cmnt_tpl,[
1458 '$return_path' => '',
1459 '$jsreload' => $return_path,
1460 '$id' => $link_item['id'],
1461 '$parent' => $link_item['id'],
1462 '$profile_uid' => $owner_uid,
1463 '$mylink' => $contact['url'],
1464 '$mytitle' => L10n::t('This is you'),
1465 '$myphoto' => $contact['thumb'],
1466 '$comment' => L10n::t('Comment'),
1467 '$submit' => L10n::t('Submit'),
1468 '$preview' => L10n::t('Preview'),
1469 '$sourceapp' => L10n::t($a->sourcename),
1471 '$rand_num' => Crypto::randomDigits(12)
1475 foreach ($items as $item) {
1480 if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) {
1484 $profile_url = Contact::magicLinkbyId($item['author-id']);
1485 if (strpos($profile_url, 'redir/') === 0) {
1486 $sparkle = ' sparkle';
1491 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1493 'dropping' => $dropping,
1494 'pagedrop' => false,
1495 'select' => L10n::t('Select'),
1496 'delete' => L10n::t('Delete'),
1499 $title_e = $item['title'];
1500 $body_e = BBCode::convert($item['body']);
1502 $comments .= Renderer::replaceMacros($template,[
1503 '$id' => $item['id'],
1504 '$profile_url' => $profile_url,
1505 '$name' => $item['author-name'],
1506 '$thumb' => $item['author-avatar'],
1507 '$sparkle' => $sparkle,
1508 '$title' => $title_e,
1510 '$ago' => Temporal::getRelativeDate($item['created']),
1511 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1513 '$comment' => $comment
1516 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1517 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1518 '$return_path' => '',
1519 '$jsreload' => $return_path,
1520 '$id' => $item['item_id'],
1521 '$parent' => $item['parent'],
1522 '$profile_uid' => $owner_uid,
1523 '$mylink' => $contact['url'],
1524 '$mytitle' => L10n::t('This is you'),
1525 '$myphoto' => $contact['thumb'],
1526 '$comment' => L10n::t('Comment'),
1527 '$submit' => L10n::t('Submit'),
1528 '$preview' => L10n::t('Preview'),
1529 '$sourceapp' => L10n::t($a->sourcename),
1531 '$rand_num' => Crypto::randomDigits(12)
1536 $response_verbs = ['like'];
1537 $response_verbs[] = 'dislike';
1538 $responses = get_responses($conv_responses, $response_verbs, $link_item);
1540 $paginate = $pager->renderFull($total);
1543 $photo_tpl = Renderer::getMarkupTemplate('photo_view.tpl');
1544 $o .= Renderer::replaceMacros($photo_tpl, [
1545 '$id' => $ph[0]['id'],
1546 '$album' => [$album_link, $ph[0]['album']],
1549 '$prevlink' => $prevlink,
1550 '$nextlink' => $nextlink,
1551 '$desc' => $ph[0]['desc'],
1555 '$map_text' => L10n::t('Map'),
1556 '$likebuttons' => $likebuttons,
1558 '$dislike' => $dislike,
1559 'responses' => $responses,
1560 '$comments' => $comments,
1561 '$paginate' => $paginate,
1564 $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
1565 $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1566 $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . $photo["href"] . '" />' . "\n";
1567 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1568 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1573 // Default - show recent photos with upload link (if applicable)
1576 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1577 $sql_extra GROUP BY `resource-id`",
1578 intval($a->data['user']['uid']),
1579 DBA::escape('Contact Photos'),
1580 DBA::escape(L10n::t('Contact Photos'))
1582 if (DBA::isResult($r)) {
1586 $pager = new Pager($a->query_string, 20);
1588 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1589 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1590 ANY_VALUE(`created`) AS `created` FROM `photo`
1591 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1592 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1593 intval($a->data['user']['uid']),
1594 DBA::escape('Contact Photos'),
1595 DBA::escape(L10n::t('Contact Photos')),
1597 $pager->getItemsPerPage()
1601 if (DBA::isResult($r)) {
1602 // "Twist" is only used for the duepunto theme with style "slackr"
1604 foreach ($r as $rr) {
1605 //hide profile photos to others
1606 if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos'))) {
1611 $ext = $phototypes[$rr['type']];
1613 $alt_e = $rr['filename'];
1614 $name_e = $rr['album'];
1618 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1619 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1620 'title' => L10n::t('View Photo'),
1621 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1624 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1626 'alt' => L10n::t('View Album'),
1633 $tpl = Renderer::getMarkupTemplate('photos_recent.tpl');
1634 $o .= Renderer::replaceMacros($tpl, [
1635 '$title' => L10n::t('Recent Photos'),
1636 '$can_post' => $can_post,
1637 '$upload' => [L10n::t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'],
1638 '$photos' => $photos,
1639 '$paginate' => $pager->renderFull($total),