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) {
38 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
42 Nav::setSelected('home');
46 $user = DBA::selectFirst('user', [], ['nickname' => $nick, 'blocked' => false]);
48 if (!DBA::isResult($user)) {
52 $a->data['user'] = $user;
53 $a->profile_uid = $user['uid'];
54 $is_owner = (local_user() && (local_user() == $a->profile_uid));
56 $profile = Profile::getByNickname($nick, $a->profile_uid);
58 $account_type = Contact::getAccountType($profile);
60 $tpl = Renderer::getMarkupTemplate("widget/vcard.tpl");
62 $vcard_widget = Renderer::replaceMacros($tpl, [
63 '$name' => $profile['name'],
64 '$photo' => $profile['photo'],
65 '$addr' => defaults($profile, 'addr', ''),
66 '$account_type' => $account_type,
67 '$pdesc' => defaults($profile, 'pdesc', ''),
70 $albums = Photo::getAlbums($a->data['user']['uid']);
72 $albums_visible = ((intval($a->data['user']['hidewall']) && !local_user() && !remote_user()) ? false : true);
74 // add various encodings to the array so we can just loop through and pick them out in a template
75 $ret = ['success' => false];
78 $a->data['albums'] = $albums;
80 if ($albums_visible) {
81 $ret['success'] = true;
85 foreach ($albums as $k => $album) {
86 //hide profile photos to others
87 if (!$is_owner && !remote_user($a->profile_uid) && ($album['album'] == L10n::t('Profile Photos')))
90 'text' => $album['album'],
91 'total' => $album['total'],
92 'url' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
93 'urlencode' => urlencode($album['album']),
94 'bin2hex' => bin2hex($album['album'])
96 $ret['albums'][] = $entry;
100 if (local_user() && $a->data['user']['uid'] == local_user()) {
106 if ($ret['success']) {
107 $photo_albums_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('photo_albums.tpl'), [
108 '$nick' => $a->data['user']['nickname'],
109 '$title' => L10n::t('Photo Albums'),
110 '$recent' => L10n::t('Recent Photos'),
111 '$albums' => $ret['albums'],
112 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'],
113 '$can_post' => $can_post
117 if (empty($a->page['aside'])) {
118 $a->page['aside'] = '';
121 $a->page['aside'] .= $vcard_widget;
123 if (!empty($photo_albums_widget)) {
124 $a->page['aside'] .= $photo_albums_widget;
127 $tpl = Renderer::getMarkupTemplate("photos_head.tpl");
129 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl,[
130 '$ispublic' => L10n::t('everybody')
137 function photos_post(App $a)
139 Logger::log('mod-photos: photos_post: begin' , Logger::DEBUG);
140 Logger::log('mod_photos: REQUEST ' . print_r($_REQUEST, true), Logger::DATA);
141 Logger::log('mod_photos: FILES ' . print_r($_FILES, true), Logger::DATA);
143 $phototypes = Image::supportedTypes();
148 $page_owner_uid = intval($a->data['user']['uid']);
149 $community_page = $a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY;
151 if (local_user() && (local_user() == $page_owner_uid)) {
153 } elseif ($community_page && !empty(remote_user($page_owner_uid))) {
154 $contact_id = remote_user($page_owner_uid);
156 $visitor = $contact_id;
160 notice(L10n::t('Permission denied.') . EOL);
164 $owner_record = User::getOwnerDataById($page_owner_uid);
166 if (!$owner_record) {
167 notice(L10n::t('Contact information unavailable') . EOL);
168 Logger::log('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
172 if ($a->argc > 3 && $a->argv[2] === 'album') {
173 if (!Strings::isHex($a->argv[3])) {
174 $a->internalRedirect('photos/' . $a->data['user']['nickname'] . '/album');
176 $album = hex2bin($a->argv[3]);
178 if ($album === L10n::t('Profile Photos') || $album === 'Contact Photos' || $album === L10n::t('Contact Photos')) {
179 $a->internalRedirect($_SESSION['photo_return']);
180 return; // NOTREACHED
183 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
185 intval($page_owner_uid)
188 if (!DBA::isResult($r)) {
189 notice(L10n::t('Album not found.') . EOL);
190 $a->internalRedirect($_SESSION['photo_return']);
191 return; // NOTREACHED
194 // Check if the user has responded to a delete confirmation query
195 if (!empty($_REQUEST['canceled'])) {
196 $a->internalRedirect($_SESSION['photo_return']);
199 // RENAME photo album
200 $newalbum = Strings::escapeTags(trim($_POST['albumname']));
201 if ($newalbum != $album) {
202 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
203 DBA::escape($newalbum),
205 intval($page_owner_uid)
207 // Update the photo albums cache
208 Photo::clearAlbumCache($page_owner_uid);
210 $a->internalRedirect('photos/' . $a->user['nickname'] . '/album/' . bin2hex($newalbum));
211 return; // NOTREACHED
215 * DELETE all photos filed in a given album
217 if (!empty($_POST['dropalbum'])) {
220 // get the list of photos we are about to delete
222 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
224 intval($page_owner_uid),
228 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
229 intval(local_user()),
234 if (DBA::isResult($r)) {
235 foreach ($r as $rr) {
239 // remove the associated photos
240 Photo::delete(['resource-id' => $res, 'uid' => $page_owner_uid]);
242 // find and delete the corresponding item with all the comments and likes/dislikes
243 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
245 // Update the photo albums cache
246 Photo::clearAlbumCache($page_owner_uid);
247 notice(L10n::t('Album successfully deleted'));
249 notice(L10n::t('Album was empty.'));
253 $a->internalRedirect('photos/' . $a->argv[1]);
256 if ($a->argc > 3 && $a->argv[2] === 'image') {
257 // Check if the user has responded to a delete confirmation query for a single photo
258 if (!empty($_POST['canceled'])) {
259 $a->internalRedirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]);
262 if (!empty($_POST['delete'])) {
263 // same as above but remove single photo
265 $condition = ['contact-id' => $visitor, 'uid' => $page_owner_uid, 'resource-id' => $a->argv[3]];
268 $condition = ['uid' => local_user(), 'resource-id' => $a->argv[3]];
271 $photo = DBA::selectFirst('photo', ['resource-id'], $condition);
273 if (DBA::isResult($photo)) {
274 Photo::delete(['uid' => $page_owner_uid, 'resource-id' => $photo['resource-id']]);
276 Item::deleteForUser(['resource-id' => $photo['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
278 // Update the photo albums cache
279 Photo::clearAlbumCache($page_owner_uid);
280 notice('Successfully deleted the photo.');
282 notice('Failed to delete the photo.');
283 $a->internalRedirect('photos/' . $a->argv[1] . '/image/' . $a->argv[3]);
286 $a->internalRedirect('photos/' . $a->argv[1]);
287 return; // NOTREACHED
291 if ($a->argc > 2 && (!empty($_POST['desc']) || !empty($_POST['newtag']) || isset($_POST['albname']))) {
292 $desc = !empty($_POST['desc']) ? Strings::escapeTags(trim($_POST['desc'])) : '';
293 $rawtags = !empty($_POST['newtag']) ? Strings::escapeTags(trim($_POST['newtag'])) : '';
294 $item_id = !empty($_POST['item_id']) ? intval($_POST['item_id']) : 0;
295 $albname = !empty($_POST['albname']) ? Strings::escapeTags(trim($_POST['albname'])) : '';
296 $origaname = !empty($_POST['origaname']) ? Strings::escapeTags(trim($_POST['origaname'])) : '';
298 $str_group_allow = !empty($_POST['group_allow']) ? perms2str($_POST['group_allow']) : '';
299 $str_contact_allow = !empty($_POST['contact_allow']) ? perms2str($_POST['contact_allow']) : '';
300 $str_group_deny = !empty($_POST['group_deny']) ? perms2str($_POST['group_deny']) : '';
301 $str_contact_deny = !empty($_POST['contact_deny']) ? perms2str($_POST['contact_deny']) : '';
303 $resource_id = $a->argv[3];
305 if (!strlen($albname)) {
306 $albname = DateTimeFormat::localNow('Y');
309 if (!empty($_POST['rotate']) && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
310 Logger::log('rotate');
312 $photo = Photo::getPhotoForUser($page_owner_uid, $resource_id);
314 if (DBA::isResult($photo)) {
315 $image = Photo::getImageForPhoto($photo);
317 if ($image->isValid()) {
318 $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
319 $image->rotate($rotate_deg);
321 $width = $image->getWidth();
322 $height = $image->getHeight();
324 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 0], $image);
326 if ($width > 640 || $height > 640) {
327 $image->scaleDown(640);
328 $width = $image->getWidth();
329 $height = $image->getHeight();
331 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 1], $image);
334 if ($width > 320 || $height > 320) {
335 $image->scaleDown(320);
336 $width = $image->getWidth();
337 $height = $image->getHeight();
339 Photo::update(['height' => $height, 'width' => $width], ['resource-id' => $resource_id, 'uid' => $page_owner_uid, 'scale' => 2], $image);
345 $photos_stmt = DBA::select('photo', [], ['resource-id' => $resource_id, 'uid' => $page_owner_uid], ['order' => ['scale' => true]]);
347 $photos = DBA::toArray($photos_stmt);
349 if (DBA::isResult($photos)) {
351 $ext = $phototypes[$photo['type']];
353 ['desc' => $desc, 'album' => $albname, 'allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow, 'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny],
354 ['resource-id' => $resource_id, 'uid' => $page_owner_uid]
357 // Update the photo albums cache if album name was changed
358 if ($albname !== $origaname) {
359 Photo::clearAlbumCache($page_owner_uid);
361 /* Don't make the item visible if the only change was the album name */
364 if ($photo['desc'] !== $desc || strlen($rawtags)) {
369 if (DBA::isResult($photos) && !$item_id) {
370 // Create item container
372 $uri = Item::newURI($page_owner_uid);
375 $arr['guid'] = System::createUUID();
376 $arr['uid'] = $page_owner_uid;
378 $arr['parent-uri'] = $uri;
379 $arr['post-type'] = Item::PT_IMAGE;
381 $arr['resource-id'] = $photo['resource-id'];
382 $arr['contact-id'] = $owner_record['id'];
383 $arr['owner-name'] = $owner_record['name'];
384 $arr['owner-link'] = $owner_record['url'];
385 $arr['owner-avatar'] = $owner_record['thumb'];
386 $arr['author-name'] = $owner_record['name'];
387 $arr['author-link'] = $owner_record['url'];
388 $arr['author-avatar'] = $owner_record['thumb'];
389 $arr['title'] = $title;
390 $arr['allow_cid'] = $photo['allow_cid'];
391 $arr['allow_gid'] = $photo['allow_gid'];
392 $arr['deny_cid'] = $photo['deny_cid'];
393 $arr['deny_gid'] = $photo['deny_gid'];
394 $arr['visible'] = $visibility;
397 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $photo['resource-id'] . ']'
398 . '[img]' . System::baseUrl() . '/photo/' . $photo['resource-id'] . '-' . $photo['scale'] . '.'. $ext . '[/img]'
401 $item_id = Item::insert($arr);
405 $item = Item::selectFirst(['tag', 'inform'], ['id' => $item_id, 'uid' => $page_owner_uid]);
407 if (DBA::isResult($item)) {
408 $old_tag = $item['tag'];
409 $old_inform = $item['inform'];
413 if (strlen($rawtags)) {
417 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
418 $x = substr($rawtags, 0, 1);
419 if ($x !== '@' && $x !== '#') {
420 $rawtags = '#' . $rawtags;
424 $tags = BBCode::getTags($rawtags);
427 foreach ($tags as $tag) {
428 if (strpos($tag, '@') === 0) {
431 $name = substr($tag,1);
433 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
435 $links = @Probe::lrdd($name);
438 foreach ($links as $link) {
439 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
440 $profile = $link['@attributes']['href'];
443 if ($link['@attributes']['rel'] === 'salmon') {
444 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
446 if (strlen($inform)) {
455 $taginfo[] = [$newname, $profile, $salmon];
460 if (strrpos($newname, '+')) {
461 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
465 $contact = DBA::selectFirst('contact', [], ['id' => $tagcid, 'uid' => $page_owner_uid]);
467 $newname = str_replace('_',' ',$name);
469 //select someone from this user's contacts by name
470 $contact = DBA::selectFirst('contact', [], ['name' => $newname, 'uid' => $page_owner_uid]);
471 if (!DBA::isResult($contact)) {
472 //select someone by attag or nick and the name passed in
473 $contact = DBA::selectFirst('contact', [],
474 ['(`attag` = ? OR `nick` = ?) AND `uid` = ?', $name, $name, $page_owner_uid],
475 ['order' => ['attag' => true]]
480 if (DBA::isResult($contact)) {
481 $newname = $contact['name'];
482 $profile = $contact['url'];
484 $notify = 'cid:' . $contact['id'];
485 if (strlen($inform)) {
493 if (!empty($contact)) {
494 $taginfo[] = [$newname, $profile, $notify, $contact, '@[url=' . str_replace(',', '%2c', $profile) . ']' . $newname . '[/url]'];
496 $taginfo[] = [$newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'];
499 if (strlen($str_tags)) {
503 $profile = str_replace(',', '%2c', $profile);
504 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
506 } elseif (strpos($tag, '#') === 0) {
507 $tagname = substr($tag, 1);
508 $str_tags .= '#[url=' . System::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url],';
513 $newtag = $old_tag ?? '';
514 if (strlen($newtag) && strlen($str_tags)) {
517 $newtag .= $str_tags;
519 $newinform = $old_inform ?? '';
520 if (strlen($newinform) && strlen($inform)) {
523 $newinform .= $inform;
525 $fields = ['tag' => $newtag, 'inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
526 $condition = ['id' => $item_id];
527 Item::update($fields, $condition);
530 foreach ($photos as $scales) {
531 if (intval($scales['scale']) == 2) {
536 if (intval($scales['scale']) == 4) {
542 if (count($taginfo)) {
543 foreach ($taginfo as $tagged) {
544 $uri = Item::newURI($page_owner_uid);
547 $arr['guid'] = System::createUUID();
548 $arr['uid'] = $page_owner_uid;
550 $arr['parent-uri'] = $uri;
552 $arr['contact-id'] = $owner_record['id'];
553 $arr['owner-name'] = $owner_record['name'];
554 $arr['owner-link'] = $owner_record['url'];
555 $arr['owner-avatar'] = $owner_record['thumb'];
556 $arr['author-name'] = $owner_record['name'];
557 $arr['author-link'] = $owner_record['url'];
558 $arr['author-avatar'] = $owner_record['thumb'];
560 $arr['allow_cid'] = $photo['allow_cid'];
561 $arr['allow_gid'] = $photo['allow_gid'];
562 $arr['deny_cid'] = $photo['deny_cid'];
563 $arr['deny_gid'] = $photo['deny_gid'];
565 $arr['verb'] = ACTIVITY_TAG;
566 $arr['gravity'] = GRAVITY_PARENT;
567 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
568 $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
569 $arr['tag'] = $tagged[4];
570 $arr['inform'] = $tagged[2];
572 $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]') ;
573 $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" ;
575 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
576 $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
578 $arr['object'] .= XML::escape('<link rel="photo" type="' . $photo['type'] . '" href="' . $tagged[3]['photo'] . '" />' . "\n");
580 $arr['object'] .= '</link></object>' . "\n";
582 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $photo['desc'] . '</title><id>'
583 . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo['resource-id'] . '</id>';
584 $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>';
590 $a->internalRedirect($_SESSION['photo_return']);
591 return; // NOTREACHED
595 // default post action - upload a photo
596 Hook::callAll('photo_post_init', $_POST);
598 // Determine the album to use
599 $album = !empty($_REQUEST['album']) ? Strings::escapeTags(trim($_REQUEST['album'])) : '';
600 $newalbum = !empty($_REQUEST['newalbum']) ? Strings::escapeTags(trim($_REQUEST['newalbum'])) : '';
602 Logger::log('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , Logger::DEBUG);
604 if (!strlen($album)) {
605 if (strlen($newalbum)) {
608 $album = DateTimeFormat::localNow('Y');
613 * We create a wall item for every photo, but we don't want to
614 * overwhelm the data stream with a hundred newly uploaded photos.
615 * So we will make the first photo uploaded to this album in the last several hours
616 * visible by default, the rest will become visible over time when and if
617 * they acquire comments, likes, dislikes, and/or tags
620 $r = Photo::selectToArray([], ['`album` = ? AND `uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR', $album, $page_owner_uid]);
622 if (!DBA::isResult($r) || ($album == L10n::t('Profile Photos'))) {
628 if (!empty($_REQUEST['not_visible']) && $_REQUEST['not_visible'] !== 'false') {
632 $group_allow = defaults($_REQUEST, 'group_allow' , []);
633 $contact_allow = defaults($_REQUEST, 'contact_allow', []);
634 $group_deny = defaults($_REQUEST, 'group_deny' , []);
635 $contact_deny = defaults($_REQUEST, 'contact_deny' , []);
637 $str_group_allow = perms2str(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
638 $str_contact_allow = perms2str(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
639 $str_group_deny = perms2str(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
640 $str_contact_deny = perms2str(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
642 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
644 Hook::callAll('photo_post_file', $ret);
646 if (!empty($ret['src']) && !empty($ret['filesize'])) {
648 $filename = $ret['filename'];
649 $filesize = $ret['filesize'];
650 $type = $ret['type'];
651 $error = UPLOAD_ERR_OK;
652 } elseif (!empty($_FILES['userfile'])) {
653 $src = $_FILES['userfile']['tmp_name'];
654 $filename = basename($_FILES['userfile']['name']);
655 $filesize = intval($_FILES['userfile']['size']);
656 $type = $_FILES['userfile']['type'];
657 $error = $_FILES['userfile']['error'];
659 $error = UPLOAD_ERR_NO_FILE;
662 if ($error !== UPLOAD_ERR_OK) {
664 case UPLOAD_ERR_INI_SIZE:
665 notice(L10n::t('Image exceeds size limit of %s', ini_get('upload_max_filesize')) . EOL);
667 case UPLOAD_ERR_FORM_SIZE:
668 notice(L10n::t('Image exceeds size limit of %s', Strings::formatBytes(defaults($_REQUEST, 'MAX_FILE_SIZE', 0))) . EOL);
670 case UPLOAD_ERR_PARTIAL:
671 notice(L10n::t('Image upload didn\'t complete, please try again') . EOL);
673 case UPLOAD_ERR_NO_FILE:
674 notice(L10n::t('Image file is missing') . EOL);
676 case UPLOAD_ERR_NO_TMP_DIR:
677 case UPLOAD_ERR_CANT_WRITE:
678 case UPLOAD_ERR_EXTENSION:
679 notice(L10n::t('Server can\'t accept new file upload at this time, please contact your administrator') . EOL);
684 Hook::callAll('photo_post_end', $foo);
689 $type = Image::guessType($filename);
692 Logger::log('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', Logger::DEBUG);
694 $maximagesize = Config::get('system', 'maximagesize');
696 if ($maximagesize && ($filesize > $maximagesize)) {
697 notice(L10n::t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)) . EOL);
700 Hook::callAll('photo_post_end', $foo);
705 notice(L10n::t('Image file is empty.') . EOL);
708 Hook::callAll('photo_post_end', $foo);
712 Logger::log('mod/photos.php: photos_post(): loading the contents of ' . $src , Logger::DEBUG);
714 $imagedata = @file_get_contents($src);
716 $image = new Image($imagedata, $type);
718 if (!$image->isValid()) {
719 Logger::log('mod/photos.php: photos_post(): unable to process image' , Logger::DEBUG);
720 notice(L10n::t('Unable to process image.') . EOL);
723 Hook::callAll('photo_post_end',$foo);
727 $exif = $image->orient($src);
730 $max_length = Config::get('system', 'max_image_length');
732 $max_length = MAX_IMAGE_LENGTH;
734 if ($max_length > 0) {
735 $image->scaleDown($max_length);
738 $width = $image->getWidth();
739 $height = $image->getHeight();
743 $photo_hash = Photo::newResource();
745 $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);
748 Logger::log('mod/photos.php: photos_post(): image store failed', Logger::DEBUG);
749 notice(L10n::t('Image upload failed.') . EOL);
753 if ($width > 640 || $height > 640) {
754 $image->scaleDown(640);
755 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);
759 if ($width > 320 || $height > 320) {
760 $image->scaleDown(320);
761 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);
765 $uri = Item::newURI($page_owner_uid);
767 // Create item container
769 if ($exif && $exif['GPS'] && Feature::isEnabled($page_owner_uid, 'photo_location')) {
770 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
771 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
776 $arr['coord'] = $lat . ' ' . $lon;
779 $arr['guid'] = System::createUUID();
780 $arr['uid'] = $page_owner_uid;
782 $arr['parent-uri'] = $uri;
783 $arr['type'] = 'photo';
785 $arr['resource-id'] = $photo_hash;
786 $arr['contact-id'] = $owner_record['id'];
787 $arr['owner-name'] = $owner_record['name'];
788 $arr['owner-link'] = $owner_record['url'];
789 $arr['owner-avatar'] = $owner_record['thumb'];
790 $arr['author-name'] = $owner_record['name'];
791 $arr['author-link'] = $owner_record['url'];
792 $arr['author-avatar'] = $owner_record['thumb'];
794 $arr['allow_cid'] = $str_contact_allow;
795 $arr['allow_gid'] = $str_group_allow;
796 $arr['deny_cid'] = $str_contact_deny;
797 $arr['deny_gid'] = $str_group_deny;
798 $arr['visible'] = $visible;
801 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
802 . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$image->getExt() . '[/img]'
805 $item_id = Item::insert($arr);
806 // Update the photo albums cache
807 Photo::clearAlbumCache($page_owner_uid);
809 Hook::callAll('photo_post_end', $item_id);
811 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
812 // if they do not wish to be redirected
814 $a->internalRedirect($_SESSION['photo_return']);
818 function photos_content(App $a)
822 // photos/name/upload
823 // photos/name/upload/xxxxx (xxxxx is album name)
824 // photos/name/album/xxxxx
825 // photos/name/album/xxxxx/edit
826 // photos/name/album/xxxxx/drop
827 // photos/name/image/xxxxx
828 // photos/name/image/xxxxx/edit
829 // photos/name/image/xxxxx/drop
831 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
832 notice(L10n::t('Public access denied.') . EOL);
836 if (empty($a->data['user'])) {
837 notice(L10n::t('No photos selected') . EOL);
841 $phototypes = Image::supportedTypes();
843 $_SESSION['photo_return'] = $a->cmd;
848 $datatype = $a->argv[2];
849 $datum = $a->argv[3];
850 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
851 $datatype = 'upload';
853 $datatype = 'summary';
862 // Setup permissions structures
866 $remote_contact = false;
871 $owner_uid = $a->data['user']['uid'];
873 $community_page = (($a->data['user']['page-flags'] == User::PAGE_FLAGS_COMMUNITY) ? true : false);
875 if (local_user() && (local_user() == $owner_uid)) {
877 } elseif ($community_page && !empty(remote_user($owner_uid))) {
878 $contact_id = remote_user($owner_uid);
879 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
881 if (DBA::isResult($contact)) {
883 $remote_contact = true;
884 $visitor = $contact_id;
888 // perhaps they're visiting - but not a community page, so they wouldn't have write access
889 if (!empty(remote_user($owner_uid)) && !$visitor) {
890 $contact_id = remote_user($owner_uid);
892 $contact = DBA::selectFirst('contact', [], ['id' => $contact_id, 'uid' => $owner_uid, 'blocked' => false, 'pending' => false]);
894 $remote_contact = DBA::isResult($contact);
897 if (!$remote_contact && local_user()) {
898 $contact_id = $_SESSION['cid'];
899 $contact = $a->contact;
902 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
903 notice(L10n::t('Access to this item is restricted.') . EOL);
907 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid, $remote_contact);
912 $is_owner = (local_user() && (local_user() == $owner_uid));
913 $o .= Profile::getTabs($a, 'photos', $is_owner, $a->data['user']['nickname']);
915 // Display upload form
916 if ($datatype === 'upload') {
918 notice(L10n::t('Permission denied.'));
922 $selname = Strings::isHex($datum) ? hex2bin($datum) : '';
926 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '><current year></option>';
927 if (!empty($a->data['albums'])) {
928 foreach ($a->data['albums'] as $album) {
929 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos'))) {
932 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
933 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
939 $ret = ['post_url' => 'photos/' . $a->data['user']['nickname'],
940 'addon_text' => $uploader,
941 'default_upload' => true];
943 Hook::callAll('photo_upload_form',$ret);
945 $default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
946 $default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
947 '$submit' => L10n::t('Submit'),
952 $tpl = Renderer::getMarkupTemplate('photos_upload.tpl');
954 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML($a->user));
956 $o .= Renderer::replaceMacros($tpl,[
957 '$pagename' => L10n::t('Upload Photos'),
958 '$sessid' => session_id(),
959 '$usage' => $usage_message,
960 '$nickname' => $a->data['user']['nickname'],
961 '$newalbum' => L10n::t('New album name: '),
962 '$existalbumtext' => L10n::t('or select existing album:'),
963 '$nosharetext' => L10n::t('Do not show a status post for this upload'),
964 '$albumselect' => $albumselect,
965 '$permissions' => L10n::t('Permissions'),
966 '$aclselect' => $aclselect_e,
967 '$lockstate' => is_array($a->user)
968 && (strlen($a->user['allow_cid'])
969 || strlen($a->user['allow_gid'])
970 || strlen($a->user['deny_cid'])
971 || strlen($a->user['deny_gid'])
972 ) ? 'lock' : 'unlock',
973 '$alt_uploader' => $ret['addon_text'],
974 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
975 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
976 '$uploadurl' => $ret['post_url'],
978 // ACL permissions box
979 '$group_perms' => L10n::t('Show to Groups'),
980 '$contact_perms' => L10n::t('Show to Contacts'),
981 '$return_path' => $a->query_string,
987 // Display a single photo album
988 if ($datatype === 'album') {
989 // if $datum is not a valid hex, redirect to the default page
990 if (!Strings::isHex($datum)) {
991 $a->internalRedirect('photos/' . $a->data['user']['nickname']. '/album');
993 $album = hex2bin($datum);
996 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
997 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1001 if (DBA::isResult($r)) {
1005 $pager = new Pager($a->query_string, 20);
1007 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1008 $order_field = defaults($_GET, 'order', '');
1009 if ($order_field === 'posted') {
1015 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1016 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1017 ANY_VALUE(`created`) as `created`
1018 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1019 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1021 DBA::escape($album),
1023 $pager->getItemsPerPage()
1026 if ($cmd === 'drop') {
1027 $drop_url = $a->query_string;
1030 ['name' => 'albumname', 'value' => $_POST['albumname']],
1033 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1034 '$method' => 'post',
1035 '$message' => L10n::t('Do you really want to delete this photo album and all its photos?'),
1036 '$extra_inputs' => $extra_inputs,
1037 '$confirm' => L10n::t('Delete Album'),
1038 '$confirm_url' => $drop_url,
1039 '$confirm_name' => 'dropalbum',
1040 '$cancel' => L10n::t('Cancel'),
1045 if ($cmd === 'edit') {
1046 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos'))) {
1048 $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
1052 $o .= Renderer::replaceMacros($edit_tpl,[
1053 '$nametext' => L10n::t('New album name: '),
1054 '$nickname' => $a->data['user']['nickname'],
1055 '$album' => $album_e,
1056 '$hexalbum' => bin2hex($album),
1057 '$submit' => L10n::t('Submit'),
1058 '$dropsubmit' => L10n::t('Delete Album')
1063 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos')) && $can_post) {
1064 $edit = [L10n::t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1065 $drop = [L10n::t('Drop Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/drop'];
1069 if ($order_field === 'posted') {
1070 $order = [L10n::t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1072 $order = [L10n::t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted', 'newest'];
1077 if (DBA::isResult($r)) {
1078 // "Twist" is only used for the duepunto theme with style "slackr"
1080 foreach ($r as $rr) {
1083 $ext = $phototypes[$rr['type']];
1085 $imgalt_e = $rr['filename'];
1086 $desc_e = $rr['desc'];
1090 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1091 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1092 . ($order_field === 'posted' ? '?f=&order=posted' : ''),
1093 'title' => L10n::t('View Photo'),
1094 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1098 'hash'=> $rr['resource-id'],
1103 $tpl = Renderer::getMarkupTemplate('photo_album.tpl');
1104 $o .= Renderer::replaceMacros($tpl, [
1105 '$photos' => $photos,
1107 '$can_post' => $can_post,
1108 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)],
1112 '$paginate' => $pager->renderFull($total),
1119 // Display one photo
1120 if ($datatype === 'image') {
1121 // fetch image, item containing image, then comments
1122 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1123 $sql_extra ORDER BY `scale` ASC ",
1128 if (!DBA::isResult($ph)) {
1129 if (DBA::exists('photo', ['resource-id' => $datum, 'uid' => $owner_uid])) {
1130 notice(L10n::t('Permission denied. Access to this item may be restricted.'));
1132 notice(L10n::t('Photo not available') . EOL);
1137 if ($cmd === 'drop') {
1138 $drop_url = $a->query_string;
1140 return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
1141 '$method' => 'post',
1142 '$message' => L10n::t('Do you really want to delete this photo?'),
1143 '$extra_inputs' => [],
1144 '$confirm' => L10n::t('Delete Photo'),
1145 '$confirm_url' => $drop_url,
1146 '$confirm_name' => 'delete',
1147 '$cancel' => L10n::t('Cancel'),
1155 * @todo This query is totally bad, the whole functionality has to be changed
1156 * The query leads to a really intense used index.
1157 * By now we hide it if someone wants to.
1159 if ($cmd === 'view' && !Config::get('system', 'no_count', false)) {
1160 $order_field = defaults($_GET, 'order', '');
1162 if ($order_field === 'posted') {
1168 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1169 $sql_extra ORDER BY `created` $order ",
1170 DBA::escape($ph[0]['album']),
1174 if (DBA::isResult($prvnxt)) {
1177 foreach ($prvnxt as $z => $entry) {
1178 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1182 $prv = count($prvnxt) - 1;
1184 if ($nxt >= count($prvnxt)) {
1191 if (!is_null($prv)) {
1192 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . ($order_field === 'posted' ? '?f=&order=posted' : '');
1194 if (!is_null($nxt)) {
1195 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . ($order_field === 'posted' ? '?f=&order=posted' : '');
1198 $tpl = Renderer::getMarkupTemplate('photo_edit_head.tpl');
1199 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl,[
1200 '$prevlink' => $prevlink,
1201 '$nextlink' => $nextlink
1205 $prevlink = [$prevlink, '<div class="icon prev"></div>'];
1209 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1214 if (count($ph) == 1) {
1215 $hires = $lores = $ph[0];
1218 if (count($ph) > 1) {
1219 if ($ph[1]['scale'] == 2) {
1220 // original is 640 or less, we can display it directly
1221 $hires = $lores = $ph[0];
1228 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1232 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1234 if ($cmd === 'edit') {
1235 $tools['view'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum, L10n::t('View photo')];
1237 $tools['edit'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/edit', L10n::t('Edit photo')];
1238 $tools['delete'] = ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/drop', L10n::t('Delete photo')];
1239 $tools['profile'] = ['profile_photo/use/'.$ph[0]['resource-id'], L10n::t('Use as profile photo')];
1243 $ph[0]['uid'] == local_user()
1244 && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid']) || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid']))
1246 $tools['lock'] = L10n::t('Private Photo');
1251 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1252 'title'=> L10n::t('View Full Size'),
1253 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . DateTimeFormat::utcNow('ymdhis'),
1254 'height' => $hires['height'],
1255 'width' => $hires['width'],
1256 'album' => $hires['album'],
1257 'filename' => $hires['filename'],
1264 // Do we have an item for this photo?
1266 // FIXME! - replace following code to display the conversation with our normal
1267 // conversation functions so that it works correctly and tracks changes
1268 // in the evolving conversation code.
1269 // The difference is that we won't be displaying the conversation head item
1270 // as a "post" but displaying instead the photo it is linked to
1272 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1273 $linked_items = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1276 if (DBA::isResult($linked_items)) {
1277 // This is a workaround to not being forced to rewrite the while $sql_extra handling
1278 $link_item = Item::selectFirst([], ['id' => $linked_items[0]['id']]);
1281 if (!empty($link_item['parent']) && !empty($link_item['uid'])) {
1282 $condition = ["`parent` = ? AND `parent` != `id`", $link_item['parent']];
1283 $total = DBA::count('item', $condition);
1285 $pager = new Pager($a->query_string);
1287 $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1288 $result = Item::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params);
1289 $items = Item::inArray($result);
1291 if (local_user() == $link_item['uid']) {
1292 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1296 if (!empty($link_item['coord'])) {
1297 $map = Map::byCoordinates($link_item['coord']);
1302 if (!empty($link_item['id']) && !empty($link_item['tag'])) {
1303 $arr = explode(',', $link_item['tag']);
1304 // parse tags and add links
1306 foreach ($arr as $tag) {
1308 'name' => BBCode::convert($tag),
1309 'removeurl' => '/tagrm/' . $link_item['id'] . '/' . bin2hex($tag)
1312 $tags = ['title' => L10n::t('Tags: '), 'tags' => $tag_arr];
1313 if ($cmd === 'edit') {
1314 $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
1315 $tags['removetitle'] = L10n::t('[Select tags to remove]');
1321 if ($cmd === 'edit' && $can_post) {
1322 $edit_tpl = Renderer::getMarkupTemplate('photo_edit.tpl');
1324 $album_e = $ph[0]['album'];
1325 $caption_e = $ph[0]['desc'];
1326 $aclselect_e = ACL::getFullSelectorHTML($a->user, false, $ph[0]);
1328 $edit = Renderer::replaceMacros($edit_tpl, [
1329 '$id' => $ph[0]['id'],
1330 '$album' => ['albname', L10n::t('New album name'), $album_e,''],
1331 '$caption' => ['desc', L10n::t('Caption'), $caption_e, ''],
1332 '$tags' => ['newtag', L10n::t('Add a Tag'), "", L10n::t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1333 '$rotate_none' => ['rotate', L10n::t('Do not rotate'),0,'', true],
1334 '$rotate_cw' => ['rotate', L10n::t("Rotate CW \x28right\x29"),1,''],
1335 '$rotate_ccw' => ['rotate', L10n::t("Rotate CCW \x28left\x29"),2,''],
1337 '$nickname' => $a->data['user']['nickname'],
1338 '$resource_id' => $ph[0]['resource-id'],
1339 '$permissions' => L10n::t('Permissions'),
1340 '$aclselect' => $aclselect_e,
1342 '$item_id' => $link_item['id'] ?? 0,
1343 '$submit' => L10n::t('Submit'),
1344 '$delete' => L10n::t('Delete Photo'),
1346 // ACL permissions box
1347 '$group_perms' => L10n::t('Show to Groups'),
1348 '$contact_perms' => L10n::t('Show to Contacts'),
1349 '$return_path' => $a->query_string,
1360 if (!empty($link_item['id']) && !empty($link_item['uri'])) {
1361 $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
1362 $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
1363 $return_path = $a->cmd;
1365 if ($cmd === 'view' && ($can_post || Security::canWriteToUserWall($owner_uid))) {
1366 $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl');
1367 $likebuttons = Renderer::replaceMacros($like_tpl, [
1368 '$id' => $link_item['id'],
1369 '$likethis' => L10n::t("I like this \x28toggle\x29"),
1370 '$nolike' => L10n::t("I don't like this \x28toggle\x29"),
1371 '$wait' => L10n::t('Please wait'),
1372 '$return_path' => $a->query_string,
1376 if (!DBA::isResult($items)) {
1377 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1378 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1379 '$return_path' => '',
1380 '$jsreload' => $return_path,
1381 '$id' => $link_item['id'],
1382 '$parent' => $link_item['id'],
1383 '$profile_uid' => $owner_uid,
1384 '$mylink' => $contact['url'],
1385 '$mytitle' => L10n::t('This is you'),
1386 '$myphoto' => $contact['thumb'],
1387 '$comment' => L10n::t('Comment'),
1388 '$submit' => L10n::t('Submit'),
1389 '$preview' => L10n::t('Preview'),
1390 '$sourceapp' => L10n::t($a->sourcename),
1392 '$rand_num' => Crypto::randomDigits(12)
1398 'like' => ['title' => L10n::t('Likes','title')],'dislike' => ['title' => L10n::t('Dislikes','title')],
1399 'attendyes' => ['title' => L10n::t('Attending','title')], 'attendno' => ['title' => L10n::t('Not attending','title')], 'attendmaybe' => ['title' => L10n::t('Might attend','title')]
1403 if (DBA::isResult($items)) {
1404 foreach ($items as $item) {
1405 builtin_activity_puller($item, $conv_responses);
1408 if (!empty($conv_responses['like'][$link_item['uri']])) {
1409 $like = format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like', $link_item['id']);
1412 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1413 $dislike = format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike', $link_item['id']);
1416 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1417 $comments .= Renderer::replaceMacros($cmnt_tpl,[
1418 '$return_path' => '',
1419 '$jsreload' => $return_path,
1420 '$id' => $link_item['id'],
1421 '$parent' => $link_item['id'],
1422 '$profile_uid' => $owner_uid,
1423 '$mylink' => $contact['url'],
1424 '$mytitle' => L10n::t('This is you'),
1425 '$myphoto' => $contact['thumb'],
1426 '$comment' => L10n::t('Comment'),
1427 '$submit' => L10n::t('Submit'),
1428 '$preview' => L10n::t('Preview'),
1429 '$sourceapp' => L10n::t($a->sourcename),
1431 '$rand_num' => Crypto::randomDigits(12)
1435 foreach ($items as $item) {
1440 if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) {
1444 $profile_url = Contact::magicLinkbyId($item['author-id']);
1445 if (strpos($profile_url, 'redir/') === 0) {
1446 $sparkle = ' sparkle';
1451 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1453 'dropping' => $dropping,
1454 'pagedrop' => false,
1455 'select' => L10n::t('Select'),
1456 'delete' => L10n::t('Delete'),
1459 $title_e = $item['title'];
1460 $body_e = BBCode::convert($item['body']);
1462 $comments .= Renderer::replaceMacros($template,[
1463 '$id' => $item['id'],
1464 '$profile_url' => $profile_url,
1465 '$name' => $item['author-name'],
1466 '$thumb' => $item['author-avatar'],
1467 '$sparkle' => $sparkle,
1468 '$title' => $title_e,
1470 '$ago' => Temporal::getRelativeDate($item['created']),
1471 '$indent' => (($item['parent'] != $item['id']) ? ' comment' : ''),
1473 '$comment' => $comment
1476 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1477 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1478 '$return_path' => '',
1479 '$jsreload' => $return_path,
1480 '$id' => $item['id'],
1481 '$parent' => $item['parent'],
1482 '$profile_uid' => $owner_uid,
1483 '$mylink' => $contact['url'],
1484 '$mytitle' => L10n::t('This is you'),
1485 '$myphoto' => $contact['thumb'],
1486 '$comment' => L10n::t('Comment'),
1487 '$submit' => L10n::t('Submit'),
1488 '$preview' => L10n::t('Preview'),
1489 '$sourceapp' => L10n::t($a->sourcename),
1491 '$rand_num' => Crypto::randomDigits(12)
1496 $response_verbs = ['like'];
1497 $response_verbs[] = 'dislike';
1498 $responses = get_responses($conv_responses, $response_verbs, $link_item);
1500 $paginate = $pager->renderFull($total);
1503 $photo_tpl = Renderer::getMarkupTemplate('photo_view.tpl');
1504 $o .= Renderer::replaceMacros($photo_tpl, [
1505 '$id' => $ph[0]['id'],
1506 '$album' => [$album_link, $ph[0]['album']],
1509 '$prevlink' => $prevlink,
1510 '$nextlink' => $nextlink,
1511 '$desc' => $ph[0]['desc'],
1515 '$map_text' => L10n::t('Map'),
1516 '$likebuttons' => $likebuttons,
1518 '$dislike' => $dislike,
1519 'responses' => $responses,
1520 '$comments' => $comments,
1521 '$paginate' => $paginate,
1524 $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
1525 $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1526 $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . System::baseUrl() . "/" . $photo["href"] . '" />' . "\n";
1527 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1528 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1533 // Default - show recent photos with upload link (if applicable)
1536 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1537 $sql_extra GROUP BY `resource-id`",
1538 intval($a->data['user']['uid']),
1539 DBA::escape('Contact Photos'),
1540 DBA::escape(L10n::t('Contact Photos'))
1542 if (DBA::isResult($r)) {
1546 $pager = new Pager($a->query_string, 20);
1548 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1549 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1550 ANY_VALUE(`created`) AS `created` FROM `photo`
1551 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1552 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1553 intval($a->data['user']['uid']),
1554 DBA::escape('Contact Photos'),
1555 DBA::escape(L10n::t('Contact Photos')),
1557 $pager->getItemsPerPage()
1561 if (DBA::isResult($r)) {
1562 // "Twist" is only used for the duepunto theme with style "slackr"
1564 foreach ($r as $rr) {
1565 //hide profile photos to others
1566 if (!$is_owner && !remote_user($owner_uid) && ($rr['album'] == L10n::t('Profile Photos'))) {
1571 $ext = $phototypes[$rr['type']];
1573 $alt_e = $rr['filename'];
1574 $name_e = $rr['album'];
1578 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1579 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1580 'title' => L10n::t('View Photo'),
1581 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1584 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1586 'alt' => L10n::t('View Album'),
1593 $tpl = Renderer::getMarkupTemplate('photos_recent.tpl');
1594 $o .= Renderer::replaceMacros($tpl, [
1595 '$title' => L10n::t('Recent Photos'),
1596 '$can_post' => $can_post,
1597 '$upload' => [L10n::t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'],
1598 '$photos' => $photos,
1599 '$paginate' => $pager->renderFull($total),