7 use Friendica\Content\Feature;
8 use Friendica\Content\Nav;
9 use Friendica\Content\Text\BBCode;
10 use Friendica\Core\ACL;
11 use Friendica\Core\Addon;
12 use Friendica\Core\Config;
13 use Friendica\Core\L10n;
14 use Friendica\Core\System;
15 use Friendica\Core\Worker;
16 use Friendica\Database\DBA;
17 use Friendica\Model\Contact;
18 use Friendica\Model\Group;
19 use Friendica\Model\Item;
20 use Friendica\Model\Photo;
21 use Friendica\Model\Profile;
22 use Friendica\Model\User;
23 use Friendica\Network\Probe;
24 use Friendica\Object\Image;
25 use Friendica\Protocol\DFRN;
26 use Friendica\Util\DateTimeFormat;
27 use Friendica\Util\Map;
28 use Friendica\Util\Temporal;
30 require_once 'include/items.php';
31 require_once 'include/security.php';
33 function photos_init(App $a) {
36 DFRN::autoRedir($a, $a->argv[1]);
39 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
43 Nav::setSelected('home');
47 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
51 if (!DBA::isResult($user)) {
55 $a->data['user'] = $user[0];
56 $a->profile_uid = $user[0]['uid'];
57 $is_owner = (local_user() && (local_user() == $a->profile_uid));
59 $profile = Profile::getByNickname($nick, $a->profile_uid);
61 $account_type = Contact::getAccountType($profile);
63 $tpl = get_markup_template("vcard-widget.tpl");
65 $vcard_widget = replace_macros($tpl, [
66 '$name' => $profile['name'],
67 '$photo' => $profile['photo'],
68 '$addr' => defaults($profile, 'addr', ''),
69 '$account_type' => $account_type,
70 '$pdesc' => defaults($profile, 'pdesc', ''),
73 $albums = Photo::getAlbums($a->data['user']['uid']);
75 $albums_visible = ((intval($a->data['user']['hidewall']) && !local_user() && !remote_user()) ? false : true);
77 // add various encodings to the array so we can just loop through and pick them out in a template
78 $ret = ['success' => false];
81 $a->data['albums'] = $albums;
82 if ($albums_visible) {
83 $ret['success'] = true;
87 foreach ($albums as $k => $album) {
88 //hide profile photos to others
89 if (!$is_owner && !remote_user() && ($album['album'] == L10n::t('Profile Photos')))
92 'text' => $album['album'],
93 'total' => $album['total'],
94 'url' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
95 'urlencode' => urlencode($album['album']),
96 'bin2hex' => bin2hex($album['album'])
98 $ret['albums'][] = $entry;
102 if (local_user() && $a->data['user']['uid'] == local_user()) {
108 if ($ret['success']) {
109 $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'), [
110 '$nick' => $a->data['user']['nickname'],
111 '$title' => L10n::t('Photo Albums'),
112 '$recent' => L10n::t('Recent Photos'),
113 '$albums' => $ret['albums'],
114 '$baseurl' => System::baseUrl(),
115 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'],
116 '$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 = get_markup_template("photos_head.tpl");
133 $a->page['htmlhead'] .= replace_macros($tpl,[
134 '$ispublic' => L10n::t('everybody')
141 function photos_post(App $a)
143 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
144 logger('mod_photos: REQUEST ' . print_r($_REQUEST, true), LOGGER_DATA);
145 logger('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'] == Contact::PAGE_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'];
170 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
172 intval($page_owner_uid)
175 if (DBA::isResult($r)) {
177 $visitor = $contact_id;
183 notice(L10n::t('Permission denied.') . EOL);
187 $owner_record = User::getOwnerDataById($page_owner_uid);
189 if (!$owner_record) {
190 notice(L10n::t('Contact information unavailable') . EOL);
191 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
195 if ($a->argc > 3 && $a->argv[2] === 'album') {
196 $album = hex2bin($a->argv[3]);
198 if ($album === L10n::t('Profile Photos') || $album === 'Contact Photos' || $album === L10n::t('Contact Photos')) {
199 goaway($_SESSION['photo_return']);
200 return; // NOTREACHED
203 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
205 intval($page_owner_uid)
207 if (!DBA::isResult($r)) {
208 notice(L10n::t('Album not found.') . EOL);
209 goaway($_SESSION['photo_return']);
210 return; // NOTREACHED
213 // Check if the user has responded to a delete confirmation query
214 if ($_REQUEST['canceled']) {
215 goaway($_SESSION['photo_return']);
218 // RENAME photo album
219 $newalbum = notags(trim($_POST['albumname']));
220 if ($newalbum != $album) {
221 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
222 DBA::escape($newalbum),
224 intval($page_owner_uid)
226 // Update the photo albums cache
227 Photo::clearAlbumCache($page_owner_uid);
229 $newurl = System::baseUrl() . '/photos/' . $a->user['nickname'] . '/album/' . bin2hex($newalbum);
231 return; // NOTREACHED
235 * DELETE photo album and all its photos
238 if ($_POST['dropalbum'] == L10n::t('Delete Album')) {
239 // Check if we should do HTML-based delete confirmation
240 if (!empty($_REQUEST['confirm'])) {
241 $drop_url = $a->query_string;
244 ['name' => 'albumname', 'value' => $_POST['albumname']],
247 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
249 '$message' => L10n::t('Do you really want to delete this photo album and all its photos?'),
250 '$extra_inputs' => $extra_inputs,
251 '$confirm' => L10n::t('Delete Album'),
252 '$confirm_url' => $drop_url,
253 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
254 '$cancel' => L10n::t('Cancel'),
256 $a->error = 1; // Set $a->error so the other module functions don't execute
262 // get the list of photos we are about to delete
265 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
267 intval($page_owner_uid),
271 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
272 intval(local_user()),
276 if (DBA::isResult($r)) {
277 foreach ($r as $rr) {
278 $res[] = "'" . DBA::escape($rr['rid']) . "'" ;
281 goaway($_SESSION['photo_return']);
282 return; // NOTREACHED
285 $str_res = implode(',', $res);
287 // remove the associated photos
288 q("DELETE FROM `photo` WHERE `resource-id` IN ($str_res) AND `uid` = %d",
289 intval($page_owner_uid)
292 // find and delete the corresponding item with all the comments and likes/dislikes
293 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
295 // Update the photo albums cache
296 Photo::clearAlbumCache($page_owner_uid);
299 goaway('photos/' . $a->data['user']['nickname']);
300 return; // NOTREACHED
304 // Check if the user has responded to a delete confirmation query for a single photo
305 if ($a->argc > 2 && !empty($_REQUEST['canceled'])) {
306 goaway($_SESSION['photo_return']);
309 if ($a->argc > 2 && defaults($_POST, 'delete', '') === L10n::t('Delete Photo')) {
311 // same as above but remove single photo
313 // Check if we should do HTML-based delete confirmation
314 if (!empty($_REQUEST['confirm'])) {
315 $drop_url = $a->query_string;
316 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
318 '$message' => L10n::t('Do you really want to delete this photo?'),
319 '$extra_inputs' => [],
320 '$confirm' => L10n::t('Delete Photo'),
321 '$confirm_url' => $drop_url,
322 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
323 '$cancel' => L10n::t('Cancel'),
325 $a->error = 1; // Set $a->error so the other module functions don't execute
330 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
332 intval($page_owner_uid),
333 DBA::escape($a->argv[2])
336 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
337 intval(local_user()),
338 DBA::escape($a->argv[2])
342 if (DBA::isResult($r)) {
343 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
344 intval($page_owner_uid),
345 DBA::escape($r[0]['resource-id'])
348 Item::deleteForUser(['resource-id' => $r[0]['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
350 // Update the photo albums cache
351 Photo::clearAlbumCache($page_owner_uid);
354 goaway('photos/' . $a->data['user']['nickname']);
355 return; // NOTREACHED
358 if ($a->argc > 2 && (!empty($_POST['desc']) || !empty($_POST['newtag']) || !empty($_POST['albname']) !== false)) {
359 $desc = !empty($_POST['desc']) ? notags(trim($_POST['desc'])) : '';
360 $rawtags = !empty($_POST['newtag']) ? notags(trim($_POST['newtag'])) : '';
361 $item_id = !empty($_POST['item_id']) ? intval($_POST['item_id']) : 0;
362 $albname = !empty($_POST['albname']) ? notags(trim($_POST['albname'])) : '';
363 $origaname = !empty($_POST['origaname']) ? notags(trim($_POST['origaname'])) : '';
365 $str_group_allow = !empty($_POST['group_allow']) ? perms2str($_POST['group_allow']) : '';
366 $str_contact_allow = !empty($_POST['contact_allow']) ? perms2str($_POST['contact_allow']) : '';
367 $str_group_deny = !empty($_POST['group_deny']) ? perms2str($_POST['group_deny']) : '';
368 $str_contact_deny = !empty($_POST['contact_deny']) ? perms2str($_POST['contact_deny']) : '';
370 $resource_id = $a->argv[2];
372 if (!strlen($albname)) {
373 $albname = DateTimeFormat::localNow('Y');
376 if (!empty($_POST['rotate']) && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
379 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0 LIMIT 1",
380 DBA::escape($resource_id),
381 intval($page_owner_uid)
384 if (DBA::isResult($r)) {
385 $image = new Image($r[0]['data'], $r[0]['type']);
387 if ($image->isValid()) {
388 $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
389 $image->rotate($rotate_deg);
391 $width = $image->getWidth();
392 $height = $image->getHeight();
394 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0",
395 DBA::escape($image->asString()),
398 DBA::escape($resource_id),
399 intval($page_owner_uid)
402 if ($width > 640 || $height > 640) {
403 $image->scaleDown(640);
404 $width = $image->getWidth();
405 $height = $image->getHeight();
407 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 1",
408 DBA::escape($image->asString()),
411 DBA::escape($resource_id),
412 intval($page_owner_uid)
416 if ($width > 320 || $height > 320) {
417 $image->scaleDown(320);
418 $width = $image->getWidth();
419 $height = $image->getHeight();
421 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 2",
422 DBA::escape($image->asString()),
425 DBA::escape($resource_id),
426 intval($page_owner_uid)
433 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
434 DBA::escape($resource_id),
435 intval($page_owner_uid)
437 if (DBA::isResult($p)) {
438 $ext = $phototypes[$p[0]['type']];
439 $r = q("UPDATE `photo` SET `desc` = '%s', `album` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d",
441 DBA::escape($albname),
442 DBA::escape($str_contact_allow),
443 DBA::escape($str_group_allow),
444 DBA::escape($str_contact_deny),
445 DBA::escape($str_group_deny),
446 DBA::escape($resource_id),
447 intval($page_owner_uid)
450 // Update the photo albums cache if album name was changed
451 if ($albname !== $origaname) {
452 Photo::clearAlbumCache($page_owner_uid);
456 /* Don't make the item visible if the only change was the album name */
459 if ($p[0]['desc'] !== $desc || strlen($rawtags)) {
464 // Create item container
466 $uri = Item::newURI($page_owner_uid);
469 $arr['guid'] = System::createGUID(32);
470 $arr['uid'] = $page_owner_uid;
472 $arr['parent-uri'] = $uri;
473 $arr['post-type'] = Item::PT_IMAGE;
475 $arr['resource-id'] = $p[0]['resource-id'];
476 $arr['contact-id'] = $owner_record['id'];
477 $arr['owner-name'] = $owner_record['name'];
478 $arr['owner-link'] = $owner_record['url'];
479 $arr['owner-avatar'] = $owner_record['thumb'];
480 $arr['author-name'] = $owner_record['name'];
481 $arr['author-link'] = $owner_record['url'];
482 $arr['author-avatar'] = $owner_record['thumb'];
483 $arr['title'] = $title;
484 $arr['allow_cid'] = $p[0]['allow_cid'];
485 $arr['allow_gid'] = $p[0]['allow_gid'];
486 $arr['deny_cid'] = $p[0]['deny_cid'];
487 $arr['deny_gid'] = $p[0]['deny_gid'];
488 $arr['visible'] = $visibility;
491 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
492 . '[img]' . System::baseUrl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
495 $item_id = Item::insert($arr);
499 $item = Item::selectFirst(['tag', 'inform'], ['id' => $item_id, 'uid' => $page_owner_uid]);
501 if (DBA::isResult($item)) {
502 $old_tag = $item['tag'];
503 $old_inform = $item['inform'];
506 if (strlen($rawtags)) {
510 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
511 $x = substr($rawtags, 0, 1);
512 if ($x !== '@' && $x !== '#') {
513 $rawtags = '#' . $rawtags;
517 $tags = get_tags($rawtags);
520 foreach ($tags as $tag) {
521 if (strpos($tag, '@') === 0) {
523 $name = substr($tag,1);
524 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
526 $links = @Probe::lrdd($name);
528 foreach ($links as $link) {
529 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
530 $profile = $link['@attributes']['href'];
532 if ($link['@attributes']['rel'] === 'salmon') {
533 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
534 if (strlen($inform)) {
541 $taginfo[] = [$newname, $profile, $salmon];
546 if (strrpos($newname, '+')) {
547 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
551 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
556 $newname = str_replace('_',' ',$name);
558 //select someone from this user's contacts by name
559 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
560 DBA::escape($newname),
561 intval($page_owner_uid)
564 if (!DBA::isResult($r)) {
565 //select someone by attag or nick and the name passed in
566 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
569 intval($page_owner_uid)
574 if (DBA::isResult($r)) {
575 $newname = $r[0]['name'];
576 $profile = $r[0]['url'];
577 $notify = 'cid:' . $r[0]['id'];
578 if (strlen($inform)) {
585 if (substr($notify, 0, 4) === 'cid:') {
586 $taginfo[] = [$newname, $profile, $notify, $r[0], '@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]'];
588 $taginfo[] = [$newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'];
590 if (strlen($str_tags)) {
593 $profile = str_replace(',', '%2c', $profile);
594 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
596 } elseif (strpos($tag, '#') === 0) {
597 $tagname = substr($tag, 1);
598 $str_tags .= '#[url=' . System::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url]';
604 if (strlen($newtag) && strlen($str_tags)) {
607 $newtag .= $str_tags;
609 $newinform = $old_inform;
610 if (strlen($newinform) && strlen($inform)) {
613 $newinform .= $inform;
615 $fields = ['tag' => $newtag, 'inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
616 $condition = ['id' => $item_id];
617 Item::update($fields, $condition);
620 foreach ($p as $scales) {
621 if (intval($scales['scale']) == 2) {
625 if (intval($scales['scale']) == 4) {
631 if (count($taginfo)) {
632 foreach ($taginfo as $tagged) {
633 $uri = Item::newURI($page_owner_uid);
636 $arr['guid'] = System::createGUID(32);
637 $arr['uid'] = $page_owner_uid;
639 $arr['parent-uri'] = $uri;
641 $arr['contact-id'] = $owner_record['id'];
642 $arr['owner-name'] = $owner_record['name'];
643 $arr['owner-link'] = $owner_record['url'];
644 $arr['owner-avatar'] = $owner_record['thumb'];
645 $arr['author-name'] = $owner_record['name'];
646 $arr['author-link'] = $owner_record['url'];
647 $arr['author-avatar'] = $owner_record['thumb'];
649 $arr['allow_cid'] = $p[0]['allow_cid'];
650 $arr['allow_gid'] = $p[0]['allow_gid'];
651 $arr['deny_cid'] = $p[0]['deny_cid'];
652 $arr['deny_gid'] = $p[0]['deny_gid'];
654 $arr['verb'] = ACTIVITY_TAG;
655 $arr['gravity'] = GRAVITY_PARENT;
656 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
657 $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
658 $arr['tag'] = $tagged[4];
659 $arr['inform'] = $tagged[2];
661 $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/' . $p[0]['resource-id'] . ']' . L10n::t('a photo') . '[/url]', '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]') ;
662 $arr['body'] .= "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . '[img]' . System::baseUrl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '[/img][/url]' . "\n" ;
664 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
665 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
667 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
669 $arr['object'] .= '</link></object>' . "\n";
671 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $p[0]['desc'] . '</title><id>'
672 . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
673 $arr['target'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '" />' . "\n" . '<link rel="preview" type="'.$p[0]['type'].'" href="' . System::baseUrl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>';
675 $item_id = Item::insert($arr);
677 Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
682 goaway($_SESSION['photo_return']);
683 return; // NOTREACHED
687 // default post action - upload a photo
688 Addon::callHooks('photo_post_init', $_POST);
690 // Determine the album to use
691 $album = !empty($_REQUEST['album']) ? notags(trim($_REQUEST['album'])) : '';
692 $newalbum = !empty($_REQUEST['newalbum']) ? notags(trim($_REQUEST['newalbum'])) : '';
694 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
696 if (!strlen($album)) {
697 if (strlen($newalbum)) {
700 $album = DateTimeFormat::localNow('Y');
705 * We create a wall item for every photo, but we don't want to
706 * overwhelm the data stream with a hundred newly uploaded photos.
707 * So we will make the first photo uploaded to this album in the last several hours
708 * visible by default, the rest will become visible over time when and if
709 * they acquire comments, likes, dislikes, and/or tags
712 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
714 intval($page_owner_uid)
717 if (!DBA::isResult($r) || ($album == L10n::t('Profile Photos'))) {
723 if (!empty($_REQUEST['not_visible']) && $_REQUEST['not_visible'] !== 'false') {
727 $group_allow = defaults($_REQUEST, 'group_allow' , []);
728 $contact_allow = defaults($_REQUEST, 'contact_allow', []);
729 $group_deny = defaults($_REQUEST, 'group_deny' , []);
730 $contact_deny = defaults($_REQUEST, 'contact_deny' , []);
732 $str_group_allow = perms2str(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
733 $str_contact_allow = perms2str(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
734 $str_group_deny = perms2str(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
735 $str_contact_deny = perms2str(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
737 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
739 Addon::callHooks('photo_post_file', $ret);
741 if (!empty($ret['src']) && !empty($ret['filesize'])) {
743 $filename = $ret['filename'];
744 $filesize = $ret['filesize'];
745 $type = $ret['type'];
746 $error = UPLOAD_ERR_OK;
748 $src = $_FILES['userfile']['tmp_name'];
749 $filename = basename($_FILES['userfile']['name']);
750 $filesize = intval($_FILES['userfile']['size']);
751 $type = $_FILES['userfile']['type'];
752 $error = $_FILES['userfile']['error'];
755 if ($error !== UPLOAD_ERR_OK) {
757 case UPLOAD_ERR_INI_SIZE:
758 notice(L10n::t('Image exceeds size limit of %s', ini_get('upload_max_filesize')) . EOL);
760 case UPLOAD_ERR_FORM_SIZE:
761 notice(L10n::t('Image exceeds size limit of %s', formatBytes(defaults($_REQUEST, 'MAX_FILE_SIZE', 0))) . EOL);
763 case UPLOAD_ERR_PARTIAL:
764 notice(L10n::t('Image upload didn\'t complete, please try again') . EOL);
766 case UPLOAD_ERR_NO_FILE:
767 notice(L10n::t('Image file is missing') . EOL);
769 case UPLOAD_ERR_NO_TMP_DIR:
770 case UPLOAD_ERR_CANT_WRITE:
771 case UPLOAD_ERR_EXTENSION:
772 notice(L10n::t('Server can\'t accept new file upload at this time, please contact your administrator') . EOL);
777 Addon::callHooks('photo_post_end', $foo);
782 $type = Image::guessType($filename);
785 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
787 $maximagesize = Config::get('system', 'maximagesize');
789 if ($maximagesize && ($filesize > $maximagesize)) {
790 notice(L10n::t('Image exceeds size limit of %s', formatBytes($maximagesize)) . EOL);
793 Addon::callHooks('photo_post_end', $foo);
798 notice(L10n::t('Image file is empty.') . EOL);
801 Addon::callHooks('photo_post_end', $foo);
805 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
807 $imagedata = @file_get_contents($src);
809 $image = new Image($imagedata, $type);
811 if (!$image->isValid()) {
812 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
813 notice(L10n::t('Unable to process image.') . EOL);
816 Addon::callHooks('photo_post_end',$foo);
820 $exif = $image->orient($src);
823 $max_length = Config::get('system', 'max_image_length');
825 $max_length = MAX_IMAGE_LENGTH;
827 if ($max_length > 0) {
828 $image->scaleDown($max_length);
831 $width = $image->getWidth();
832 $height = $image->getHeight();
836 $photo_hash = Photo::newResource();
838 $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);
841 logger('mod/photos.php: photos_post(): image store failed', LOGGER_DEBUG);
842 notice(L10n::t('Image upload failed.') . EOL);
846 if ($width > 640 || $height > 640) {
847 $image->scaleDown(640);
848 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);
852 if ($width > 320 || $height > 320) {
853 $image->scaleDown(320);
854 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);
858 $uri = Item::newURI($page_owner_uid);
860 // Create item container
862 if ($exif && $exif['GPS'] && Feature::isEnabled($page_owner_uid, 'photo_location')) {
863 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
864 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
869 $arr['coord'] = $lat . ' ' . $lon;
872 $arr['guid'] = System::createGUID(32);
873 $arr['uid'] = $page_owner_uid;
875 $arr['parent-uri'] = $uri;
876 $arr['type'] = 'photo';
878 $arr['resource-id'] = $photo_hash;
879 $arr['contact-id'] = $owner_record['id'];
880 $arr['owner-name'] = $owner_record['name'];
881 $arr['owner-link'] = $owner_record['url'];
882 $arr['owner-avatar'] = $owner_record['thumb'];
883 $arr['author-name'] = $owner_record['name'];
884 $arr['author-link'] = $owner_record['url'];
885 $arr['author-avatar'] = $owner_record['thumb'];
887 $arr['allow_cid'] = $str_contact_allow;
888 $arr['allow_gid'] = $str_group_allow;
889 $arr['deny_cid'] = $str_contact_deny;
890 $arr['deny_gid'] = $str_group_deny;
891 $arr['visible'] = $visible;
894 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
895 . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$image->getExt() . '[/img]'
898 $item_id = Item::insert($arr);
899 // Update the photo albums cache
900 Photo::clearAlbumCache($page_owner_uid);
903 Worker::add(PRIORITY_HIGH, "Notifier", 'wall-new', $item_id);
906 Addon::callHooks('photo_post_end', $item_id);
908 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
909 // if they do not wish to be redirected
911 goaway($_SESSION['photo_return']);
915 function photos_content(App $a)
919 // photos/name/upload
920 // photos/name/upload/xxxxx (xxxxx is album name)
921 // photos/name/album/xxxxx
922 // photos/name/album/xxxxx/edit
923 // photos/name/image/xxxxx
924 // photos/name/image/xxxxx/edit
926 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
927 notice(L10n::t('Public access denied.') . EOL);
931 require_once 'include/security.php';
932 require_once 'include/conversation.php';
934 if (empty($a->data['user'])) {
935 notice(L10n::t('No photos selected') . EOL);
939 $phototypes = Image::supportedTypes();
941 $_SESSION['photo_return'] = $a->cmd;
946 $datatype = $a->argv[2];
947 $datum = $a->argv[3];
948 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
949 $datatype = 'upload';
951 $datatype = 'summary';
960 // Setup permissions structures
964 $remote_contact = false;
968 $owner_uid = $a->data['user']['uid'];
970 $community_page = (($a->data['user']['page-flags'] == Contact::PAGE_COMMUNITY) ? true : false);
972 if (local_user() && (local_user() == $owner_uid)) {
975 if ($community_page && remote_user()) {
976 if (is_array($_SESSION['remote'])) {
977 foreach ($_SESSION['remote'] as $v) {
978 if ($v['uid'] == $owner_uid) {
979 $contact_id = $v['cid'];
986 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
990 if (DBA::isResult($r)) {
993 $remote_contact = true;
994 $visitor = $contact_id;
1002 // perhaps they're visiting - but not a community page, so they wouldn't have write access
1003 if (remote_user() && !$visitor) {
1005 if (is_array($_SESSION['remote'])) {
1006 foreach ($_SESSION['remote'] as $v) {
1007 if ($v['uid'] == $owner_uid) {
1008 $contact_id = $v['cid'];
1014 $groups = Group::getIdsByContactId($contact_id);
1015 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1016 intval($contact_id),
1019 if (DBA::isResult($r)) {
1021 $remote_contact = true;
1026 if (!$remote_contact && local_user()) {
1027 $contact_id = $_SESSION['cid'];
1028 $contact = $a->contact;
1031 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
1032 notice(L10n::t('Access to this item is restricted.') . EOL);
1036 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
1041 $is_owner = (local_user() && (local_user() == $owner_uid));
1042 $o .= Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
1044 // Display upload form
1045 if ($datatype === 'upload') {
1047 notice(L10n::t('Permission denied.'));
1051 $selname = $datum ? hex2bin($datum) : '';
1055 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '><current year></option>';
1056 if (!empty($a->data['albums'])) {
1057 foreach ($a->data['albums'] as $album) {
1058 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos'))) {
1061 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1062 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1068 $ret = ['post_url' => 'photos/' . $a->data['user']['nickname'],
1069 'addon_text' => $uploader,
1070 'default_upload' => true];
1072 Addon::callHooks('photo_upload_form',$ret);
1074 $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), []);
1075 $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), [
1076 '$submit' => L10n::t('Submit'),
1079 $usage_message = '';
1081 $tpl = get_markup_template('photos_upload.tpl');
1083 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML($a->user));
1085 $o .= replace_macros($tpl,[
1086 '$pagename' => L10n::t('Upload Photos'),
1087 '$sessid' => session_id(),
1088 '$usage' => $usage_message,
1089 '$nickname' => $a->data['user']['nickname'],
1090 '$newalbum' => L10n::t('New album name: '),
1091 '$existalbumtext' => L10n::t('or select existing album:'),
1092 '$nosharetext' => L10n::t('Do not show a status post for this upload'),
1093 '$albumselect' => $albumselect,
1094 '$permissions' => L10n::t('Permissions'),
1095 '$aclselect' => $aclselect_e,
1096 '$alt_uploader' => $ret['addon_text'],
1097 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
1098 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
1099 '$uploadurl' => $ret['post_url'],
1101 // ACL permissions box
1102 '$group_perms' => L10n::t('Show to Groups'),
1103 '$contact_perms' => L10n::t('Show to Contacts'),
1104 '$return_path' => $a->query_string,
1110 // Display a single photo album
1111 if ($datatype === 'album') {
1112 $album = hex2bin($datum);
1114 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1115 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1119 if (DBA::isResult($r)) {
1120 $a->set_pager_total(count($r));
1121 $a->set_pager_itemspage(20);
1124 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1125 $order_field = defaults($_GET, 'order', '');
1126 if ($order_field === 'posted') {
1132 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1133 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1134 ANY_VALUE(`created`) as `created`
1135 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1136 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1138 DBA::escape($album),
1139 intval($a->pager['start']),
1140 intval($a->pager['itemspage'])
1144 if ($cmd === 'edit') {
1145 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos'))) {
1147 $edit_tpl = get_markup_template('album_edit.tpl');
1151 $o .= replace_macros($edit_tpl,[
1152 '$nametext' => L10n::t('New album name: '),
1153 '$nickname' => $a->data['user']['nickname'],
1154 '$album' => $album_e,
1155 '$hexalbum' => bin2hex($album),
1156 '$submit' => L10n::t('Submit'),
1157 '$dropsubmit' => L10n::t('Delete Album')
1162 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos')) && $can_post) {
1163 $edit = [L10n::t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1167 if ($order_field === 'posted') {
1168 $order = [L10n::t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1170 $order = [L10n::t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted', 'newest'];
1175 if (DBA::isResult($r)) {
1176 // "Twist" is only used for the duepunto theme with style "slackr"
1178 foreach ($r as $rr) {
1181 $ext = $phototypes[$rr['type']];
1183 $imgalt_e = $rr['filename'];
1184 $desc_e = $rr['desc'];
1188 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1189 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1190 . ($order_field === 'posted' ? '?f=&order=posted' : ''),
1191 'title' => L10n::t('View Photo'),
1192 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1196 'hash'=> $rr['resource-id'],
1201 $tpl = get_markup_template('photo_album.tpl');
1202 $o .= replace_macros($tpl, [
1203 '$photos' => $photos,
1205 '$can_post' => $can_post,
1206 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)],
1209 '$paginate' => paginate($a),
1216 // Display one photo
1217 if ($datatype === 'image') {
1218 // fetch image, item containing image, then comments
1219 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1220 $sql_extra ORDER BY `scale` ASC ",
1225 if (!DBA::isResult($ph)) {
1226 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1231 if (DBA::isResult($ph)) {
1232 notice(L10n::t('Permission denied. Access to this item may be restricted.'));
1234 notice(L10n::t('Photo not available') . EOL);
1243 * @todo This query is totally bad, the whole functionality has to be changed
1244 * The query leads to a really intense used index.
1245 * By now we hide it if someone wants to.
1247 if (!Config::get('system', 'no_count', false)) {
1248 $order_field = defaults($_GET, 'order', '');
1250 if ($order_field === 'posted') {
1256 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1257 $sql_extra ORDER BY `created` $order ",
1258 DBA::escape($ph[0]['album']),
1262 if (DBA::isResult($prvnxt)) {
1265 foreach ($prvnxt as $z => $entry) {
1266 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1270 $prv = count($prvnxt) - 1;
1272 if ($nxt >= count($prvnxt)) {
1278 $edit_suffix = ((($cmd === 'edit') && $can_post) ? '/edit' : '');
1279 if (!is_null($prv)) {
1280 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1282 if (!is_null($nxt)) {
1283 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1288 if (count($ph) == 1) {
1289 $hires = $lores = $ph[0];
1292 if (count($ph) > 1) {
1293 if ($ph[1]['scale'] == 2) {
1294 // original is 640 or less, we can display it directly
1295 $hires = $lores = $ph[0];
1302 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1307 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1309 'edit' => ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? L10n::t('View photo') : L10n::t('Edit photo'))],
1310 'profile'=>['profile_photo/use/'.$ph[0]['resource-id'], L10n::t('Use as profile photo')],
1314 $lock = ((($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1315 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])))
1316 ? L10n::t('Private Message')
1322 if ($cmd === 'edit') {
1323 $tpl = get_markup_template('photo_edit_head.tpl');
1324 $a->page['htmlhead'] .= replace_macros($tpl,[
1325 '$prevlink' => $prevlink,
1326 '$nextlink' => $nextlink
1331 $prevlink = [$prevlink, '<div class="icon prev"></div>'] ;
1335 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1336 'title'=> L10n::t('View Full Size'),
1337 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . DateTimeFormat::utcNow('ymdhis'),
1338 'height' => $hires['height'],
1339 'width' => $hires['width'],
1340 'album' => $hires['album'],
1341 'filename' => $hires['filename'],
1345 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1349 // Do we have an item for this photo?
1351 // FIXME! - replace following code to display the conversation with our normal
1352 // conversation functions so that it works correctly and tracks changes
1353 // in the evolving conversation code.
1354 // The difference is that we won't be displaying the conversation head item
1355 // as a "post" but displaying instead the photo it is linked to
1357 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1358 $linked_items = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1365 if (DBA::isResult($linked_items)) {
1366 // This is a workaround to not being forced to rewrite the while $sql_extra handling
1367 $link_item = Item::selectFirst([], ['id' => $linked_items[0]['id']]);
1369 $condition = ["`parent` = ? AND `parent` != `id`", $link_item['parent']];
1370 $a->set_pager_total(DBA::count('item', $condition));
1372 $params = ['order' => ['id'], 'limit' => [$a->pager['start'], $a->pager['itemspage']]];
1373 $result = Item::selectForUser($link_item['uid'], [], $condition, $params);
1374 $items = Item::inArray($result);
1376 if (local_user() && (local_user() == $link_item['uid'])) {
1377 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1380 if ($link_item['coord']) {
1381 $map = Map::byCoordinates($link_item['coord']);
1387 if (count($linked_items) && strlen($link_item['tag'])) {
1388 $arr = explode(',', $link_item['tag']);
1389 // parse tags and add links
1391 foreach ($arr as $t) {
1392 if (strlen($tag_str)) {
1395 $tag_str .= BBCode::convert($t);
1397 $tags = [L10n::t('Tags: '), $tag_str];
1398 if ($cmd === 'edit') {
1399 $tags[] = 'tagrm/' . $link_item['id'];
1400 $tags[] = L10n::t('[Remove any tag]');
1406 if ($cmd === 'edit' && $can_post) {
1407 $edit_tpl = get_markup_template('photo_edit.tpl');
1409 $album_e = $ph[0]['album'];
1410 $caption_e = $ph[0]['desc'];
1411 $aclselect_e = ACL::getFullSelectorHTML($ph[0]);
1413 $edit = replace_macros($edit_tpl, [
1414 '$id' => $ph[0]['id'],
1415 '$album' => ['albname', L10n::t('New album name'), $album_e,''],
1416 '$caption' => ['desc', L10n::t('Caption'), $caption_e, ''],
1417 '$tags' => ['newtag', L10n::t('Add a Tag'), "", L10n::t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1418 '$rotate_none' => ['rotate', L10n::t('Do not rotate'),0,'', true],
1419 '$rotate_cw' => ['rotate', L10n::t("Rotate CW \x28right\x29"),1,''],
1420 '$rotate_ccw' => ['rotate', L10n::t("Rotate CCW \x28left\x29"),2,''],
1422 '$nickname' => $a->data['user']['nickname'],
1423 '$resource_id' => $ph[0]['resource-id'],
1424 '$permissions' => L10n::t('Permissions'),
1425 '$aclselect' => $aclselect_e,
1427 '$item_id' => defaults($link_item, 'id', 0),
1428 '$submit' => L10n::t('Submit'),
1429 '$delete' => L10n::t('Delete Photo'),
1431 // ACL permissions box
1432 '$group_perms' => L10n::t('Show to Groups'),
1433 '$contact_perms' => L10n::t('Show to Contacts'),
1434 '$return_path' => $a->query_string,
1445 if (count($linked_items)) {
1446 $cmnt_tpl = get_markup_template('comment_item.tpl');
1447 $tpl = get_markup_template('photo_item.tpl');
1448 $return_url = $a->cmd;
1450 if ($can_post || can_write_wall($owner_uid)) {
1451 $like_tpl = get_markup_template('like_noshare.tpl');
1452 $likebuttons = replace_macros($like_tpl, [
1453 '$id' => $link_item['id'],
1454 '$likethis' => L10n::t("I like this \x28toggle\x29"),
1455 '$nolike' => (Feature::isEnabled(local_user(), 'dislike') ? L10n::t("I don't like this \x28toggle\x29") : ''),
1456 '$wait' => L10n::t('Please wait'),
1457 '$return_path' => $a->query_string,
1461 if (!DBA::isResult($items)) {
1462 if (($can_post || can_write_wall($owner_uid))) {
1463 $comments .= replace_macros($cmnt_tpl, [
1464 '$return_path' => '',
1465 '$jsreload' => $return_url,
1466 '$id' => $link_item['id'],
1467 '$parent' => $link_item['id'],
1468 '$profile_uid' => $owner_uid,
1469 '$mylink' => $contact['url'],
1470 '$mytitle' => L10n::t('This is you'),
1471 '$myphoto' => $contact['thumb'],
1472 '$comment' => L10n::t('Comment'),
1473 '$submit' => L10n::t('Submit'),
1474 '$preview' => L10n::t('Preview'),
1475 '$sourceapp' => L10n::t($a->sourcename),
1477 '$rand_num' => random_digits(12)
1483 'like' => ['title' => L10n::t('Likes','title')],'dislike' => ['title' => L10n::t('Dislikes','title')],
1484 'attendyes' => ['title' => L10n::t('Attending','title')], 'attendno' => ['title' => L10n::t('Not attending','title')], 'attendmaybe' => ['title' => L10n::t('Might attend','title')]
1488 if (DBA::isResult($items)) {
1489 foreach ($items as $item) {
1490 builtin_activity_puller($item, $conv_responses);
1493 if (!empty($conv_responses['like'][$link_item['uri']])) {
1494 $like = format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like', $link_item['id']);
1497 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1498 $dislike = format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike', $link_item['id']);
1501 if (($can_post || can_write_wall($owner_uid))) {
1502 $comments .= replace_macros($cmnt_tpl,[
1503 '$return_path' => '',
1504 '$jsreload' => $return_url,
1505 '$id' => $link_item['id'],
1506 '$parent' => $link_item['id'],
1507 '$profile_uid' => $owner_uid,
1508 '$mylink' => $contact['url'],
1509 '$mytitle' => L10n::t('This is you'),
1510 '$myphoto' => $contact['thumb'],
1511 '$comment' => L10n::t('Comment'),
1512 '$submit' => L10n::t('Submit'),
1513 '$preview' => L10n::t('Preview'),
1514 '$sourceapp' => L10n::t($a->sourcename),
1516 '$rand_num' => random_digits(12)
1520 foreach ($items as $item) {
1525 if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) {
1529 $profile_url = Contact::MagicLinkById($item['author-id']);
1530 if (strpos($profile_url, 'redir/') === 0) {
1531 $sparkle = ' sparkle';
1536 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1538 'dropping' => $dropping,
1539 'pagedrop' => false,
1540 'select' => L10n::t('Select'),
1541 'delete' => L10n::t('Delete'),
1544 $title_e = $item['title'];
1545 $body_e = BBCode::convert($item['body']);
1547 $comments .= replace_macros($template,[
1548 '$id' => $item['item_id'],
1549 '$profile_url' => $profile_url,
1550 '$name' => $item['author-name'],
1551 '$thumb' => $item['author-avatar'],
1552 '$sparkle' => $sparkle,
1553 '$title' => $title_e,
1555 '$ago' => Temporal::getRelativeDate($item['created']),
1556 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1558 '$comment' => $comment
1561 if (($can_post || can_write_wall($owner_uid))) {
1562 $comments .= replace_macros($cmnt_tpl, [
1563 '$return_path' => '',
1564 '$jsreload' => $return_url,
1565 '$id' => $item['item_id'],
1566 '$parent' => $item['parent'],
1567 '$profile_uid' => $owner_uid,
1568 '$mylink' => $contact['url'],
1569 '$mytitle' => L10n::t('This is you'),
1570 '$myphoto' => $contact['thumb'],
1571 '$comment' => L10n::t('Comment'),
1572 '$submit' => L10n::t('Submit'),
1573 '$preview' => L10n::t('Preview'),
1574 '$sourceapp' => L10n::t($a->sourcename),
1576 '$rand_num' => random_digits(12)
1581 $response_verbs = ['like'];
1582 if (Feature::isEnabled($owner_uid, 'dislike')) {
1583 $response_verbs[] = 'dislike';
1585 $responses = get_responses($conv_responses, $response_verbs, '', $link_item);
1587 $paginate = paginate($a);
1590 $photo_tpl = get_markup_template('photo_view.tpl');
1591 $o .= replace_macros($photo_tpl, [
1592 '$id' => $ph[0]['id'],
1593 '$album' => [$album_link, $ph[0]['album']],
1597 '$prevlink' => $prevlink,
1598 '$nextlink' => $nextlink,
1599 '$desc' => $ph[0]['desc'],
1603 '$map_text' => L10n::t('Map'),
1604 '$likebuttons' => $likebuttons,
1606 '$dislike' => $dislike,
1607 'responses' => $responses,
1608 '$comments' => $comments,
1609 '$paginate' => $paginate,
1612 $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="photo" />' . "\n";
1613 $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1614 $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . $photo["href"] . '" />' . "\n";
1615 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1616 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1621 // Default - show recent photos with upload link (if applicable)
1624 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1625 $sql_extra GROUP BY `resource-id`",
1626 intval($a->data['user']['uid']),
1627 DBA::escape('Contact Photos'),
1628 DBA::escape(L10n::t('Contact Photos'))
1631 if (DBA::isResult($r)) {
1632 $a->set_pager_total(count($r));
1633 $a->set_pager_itemspage(20);
1636 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1637 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1638 ANY_VALUE(`created`) AS `created` FROM `photo`
1639 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1640 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1641 intval($a->data['user']['uid']),
1642 DBA::escape('Contact Photos'),
1643 DBA::escape(L10n::t('Contact Photos')),
1644 intval($a->pager['start']),
1645 intval($a->pager['itemspage'])
1649 if (DBA::isResult($r)) {
1650 // "Twist" is only used for the duepunto theme with style "slackr"
1652 foreach ($r as $rr) {
1653 //hide profile photos to others
1654 if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos'))) {
1660 $ext = $phototypes[$rr['type']];
1662 $alt_e = $rr['filename'];
1663 $name_e = $rr['album'];
1667 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1668 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1669 'title' => L10n::t('View Photo'),
1670 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1673 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1675 'alt' => L10n::t('View Album'),
1682 $tpl = get_markup_template('photos_recent.tpl');
1683 $o .= replace_macros($tpl, [
1684 '$title' => L10n::t('Recent Photos'),
1685 '$can_post' => $can_post,
1686 '$upload' => [L10n::t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'],
1687 '$photos' => $photos,
1688 '$paginate' => paginate($a),