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\Addon;
13 use Friendica\Core\Config;
14 use Friendica\Core\L10n;
15 use Friendica\Core\Logger;
16 use Friendica\Core\Renderer;
17 use Friendica\Core\System;
18 use Friendica\Core\Worker;
19 use Friendica\Database\DBA;
20 use Friendica\Model\Contact;
21 use Friendica\Model\Group;
22 use Friendica\Model\Item;
23 use Friendica\Model\Photo;
24 use Friendica\Model\Profile;
25 use Friendica\Model\User;
26 use Friendica\Network\Probe;
27 use Friendica\Object\Image;
28 use Friendica\Protocol\DFRN;
29 use Friendica\Util\DateTimeFormat;
30 use Friendica\Util\Map;
31 use Friendica\Util\Security;
32 use Friendica\Util\Strings;
33 use Friendica\Util\Temporal;
35 require_once 'include/items.php';
37 function photos_init(App $a) {
40 DFRN::autoRedir($a, $a->argv[1]);
43 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
47 Nav::setSelected('home');
51 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
55 if (!DBA::isResult($user)) {
59 $a->data['user'] = $user[0];
60 $a->profile_uid = $user[0]['uid'];
61 $is_owner = (local_user() && (local_user() == $a->profile_uid));
63 $profile = Profile::getByNickname($nick, $a->profile_uid);
65 $account_type = Contact::getAccountType($profile);
67 $tpl = Renderer::getMarkupTemplate("vcard-widget.tpl");
69 $vcard_widget = Renderer::replaceMacros($tpl, [
70 '$name' => $profile['name'],
71 '$photo' => $profile['photo'],
72 '$addr' => defaults($profile, 'addr', ''),
73 '$account_type' => $account_type,
74 '$pdesc' => defaults($profile, 'pdesc', ''),
77 $albums = Photo::getAlbums($a->data['user']['uid']);
79 $albums_visible = ((intval($a->data['user']['hidewall']) && !local_user() && !remote_user()) ? false : true);
81 // add various encodings to the array so we can just loop through and pick them out in a template
82 $ret = ['success' => false];
85 $a->data['albums'] = $albums;
87 if ($albums_visible) {
88 $ret['success'] = true;
92 foreach ($albums as $k => $album) {
93 //hide profile photos to others
94 if (!$is_owner && !remote_user() && ($album['album'] == L10n::t('Profile Photos')))
97 'text' => $album['album'],
98 'total' => $album['total'],
99 'url' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
100 'urlencode' => urlencode($album['album']),
101 'bin2hex' => bin2hex($album['album'])
103 $ret['albums'][] = $entry;
107 if (local_user() && $a->data['user']['uid'] == local_user()) {
113 if ($ret['success']) {
114 $photo_albums_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('photo_albums.tpl'), [
115 '$nick' => $a->data['user']['nickname'],
116 '$title' => L10n::t('Photo Albums'),
117 '$recent' => L10n::t('Recent Photos'),
118 '$albums' => $ret['albums'],
119 '$baseurl' => System::baseUrl(),
120 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'],
121 '$can_post' => $can_post
125 if (empty($a->page['aside'])) {
126 $a->page['aside'] = '';
129 $a->page['aside'] .= $vcard_widget;
131 if (!empty($photo_albums_widget)) {
132 $a->page['aside'] .= $photo_albums_widget;
135 $tpl = Renderer::getMarkupTemplate("photos_head.tpl");
137 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl,[
138 '$ispublic' => L10n::t('everybody')
145 function photos_post(App $a)
147 Logger::log('mod-photos: photos_post: begin' , Logger::DEBUG);
148 Logger::log('mod_photos: REQUEST ' . print_r($_REQUEST, true), Logger::DATA);
149 Logger::log('mod_photos: FILES ' . print_r($_FILES, true), Logger::DATA);
151 $phototypes = Image::supportedTypes();
156 $page_owner_uid = $a->data['user']['uid'];
157 $community_page = $a->data['user']['page-flags'] == Contact::PAGE_COMMUNITY;
159 if (local_user() && (local_user() == $page_owner_uid)) {
161 } elseif ($community_page && remote_user()) {
164 if (!empty($_SESSION['remote']) && is_array($_SESSION['remote'])) {
165 foreach ($_SESSION['remote'] as $v) {
166 if ($v['uid'] == $page_owner_uid) {
167 $contact_id = $v['cid'];
173 if ($contact_id > 0) {
174 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
176 intval($page_owner_uid)
179 if (DBA::isResult($r)) {
181 $visitor = $contact_id;
187 notice(L10n::t('Permission denied.') . EOL);
191 $owner_record = User::getOwnerDataById($page_owner_uid);
193 if (!$owner_record) {
194 notice(L10n::t('Contact information unavailable') . EOL);
195 Logger::log('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
199 if ($a->argc > 3 && $a->argv[2] === 'album') {
200 $album = hex2bin($a->argv[3]);
202 if ($album === L10n::t('Profile Photos') || $album === 'Contact Photos' || $album === L10n::t('Contact Photos')) {
203 $a->internalRedirect($_SESSION['photo_return']);
204 return; // NOTREACHED
207 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
209 intval($page_owner_uid)
212 if (!DBA::isResult($r)) {
213 notice(L10n::t('Album not found.') . EOL);
214 $a->internalRedirect($_SESSION['photo_return']);
215 return; // NOTREACHED
218 // Check if the user has responded to a delete confirmation query
219 if (!empty($_REQUEST['canceled'])) {
220 $a->internalRedirect($_SESSION['photo_return']);
223 // RENAME photo album
224 $newalbum = notags(trim($_POST['albumname']));
225 if ($newalbum != $album) {
226 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
227 DBA::escape($newalbum),
229 intval($page_owner_uid)
231 // Update the photo albums cache
232 Photo::clearAlbumCache($page_owner_uid);
234 $a->internalRedirect('photos/' . $a->user['nickname'] . '/album/' . bin2hex($newalbum));
235 return; // NOTREACHED
239 * DELETE photo album and all its photos
242 if ($_POST['dropalbum'] == L10n::t('Delete Album')) {
243 // Check if we should do HTML-based delete confirmation
244 if (!empty($_REQUEST['confirm'])) {
245 $drop_url = $a->query_string;
248 ['name' => 'albumname', 'value' => $_POST['albumname']],
251 $a->page['content'] = Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
253 '$message' => L10n::t('Do you really want to delete this photo album and all its photos?'),
254 '$extra_inputs' => $extra_inputs,
255 '$confirm' => L10n::t('Delete Album'),
256 '$confirm_url' => $drop_url,
257 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
258 '$cancel' => L10n::t('Cancel'),
261 $a->error = 1; // Set $a->error so the other module functions don't execute
267 // get the list of photos we are about to delete
270 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
272 intval($page_owner_uid),
276 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
277 intval(local_user()),
282 if (DBA::isResult($r)) {
283 foreach ($r as $rr) {
284 $res[] = "'" . DBA::escape($rr['rid']) . "'" ;
287 $a->internalRedirect($_SESSION['photo_return']);
288 return; // NOTREACHED
291 $str_res = implode(',', $res);
293 // remove the associated photos
294 q("DELETE FROM `photo` WHERE `resource-id` IN ($str_res) AND `uid` = %d",
295 intval($page_owner_uid)
298 // find and delete the corresponding item with all the comments and likes/dislikes
299 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
301 // Update the photo albums cache
302 Photo::clearAlbumCache($page_owner_uid);
305 $a->internalRedirect('photos/' . $a->data['user']['nickname']);
306 return; // NOTREACHED
310 // Check if the user has responded to a delete confirmation query for a single photo
311 if ($a->argc > 2 && !empty($_REQUEST['canceled'])) {
312 $a->internalRedirect($_SESSION['photo_return']);
315 if ($a->argc > 2 && defaults($_POST, 'delete', '') === L10n::t('Delete Photo')) {
317 // same as above but remove single photo
319 // Check if we should do HTML-based delete confirmation
320 if (!empty($_REQUEST['confirm'])) {
321 $drop_url = $a->query_string;
323 $a->page['content'] = Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
325 '$message' => L10n::t('Do you really want to delete this photo?'),
326 '$extra_inputs' => [],
327 '$confirm' => L10n::t('Delete Photo'),
328 '$confirm_url' => $drop_url,
329 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
330 '$cancel' => L10n::t('Cancel'),
333 $a->error = 1; // Set $a->error so the other module functions don't execute
338 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
340 intval($page_owner_uid),
341 DBA::escape($a->argv[2])
344 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
345 intval(local_user()),
346 DBA::escape($a->argv[2])
350 if (DBA::isResult($r)) {
351 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
352 intval($page_owner_uid),
353 DBA::escape($r[0]['resource-id'])
356 Item::deleteForUser(['resource-id' => $r[0]['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
358 // Update the photo albums cache
359 Photo::clearAlbumCache($page_owner_uid);
362 $a->internalRedirect('photos/' . $a->data['user']['nickname']);
363 return; // NOTREACHED
366 if ($a->argc > 2 && (!empty($_POST['desc']) || !empty($_POST['newtag']) || !empty($_POST['albname']) !== false)) {
367 $desc = !empty($_POST['desc']) ? notags(trim($_POST['desc'])) : '';
368 $rawtags = !empty($_POST['newtag']) ? notags(trim($_POST['newtag'])) : '';
369 $item_id = !empty($_POST['item_id']) ? intval($_POST['item_id']) : 0;
370 $albname = !empty($_POST['albname']) ? notags(trim($_POST['albname'])) : '';
371 $origaname = !empty($_POST['origaname']) ? notags(trim($_POST['origaname'])) : '';
373 $str_group_allow = !empty($_POST['group_allow']) ? perms2str($_POST['group_allow']) : '';
374 $str_contact_allow = !empty($_POST['contact_allow']) ? perms2str($_POST['contact_allow']) : '';
375 $str_group_deny = !empty($_POST['group_deny']) ? perms2str($_POST['group_deny']) : '';
376 $str_contact_deny = !empty($_POST['contact_deny']) ? perms2str($_POST['contact_deny']) : '';
378 $resource_id = $a->argv[2];
380 if (!strlen($albname)) {
381 $albname = DateTimeFormat::localNow('Y');
384 if (!empty($_POST['rotate']) && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
385 Logger::log('rotate');
387 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0 LIMIT 1",
388 DBA::escape($resource_id),
389 intval($page_owner_uid)
392 if (DBA::isResult($r)) {
393 $image = new Image($r[0]['data'], $r[0]['type']);
395 if ($image->isValid()) {
396 $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
397 $image->rotate($rotate_deg);
399 $width = $image->getWidth();
400 $height = $image->getHeight();
402 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0",
403 DBA::escape($image->asString()),
406 DBA::escape($resource_id),
407 intval($page_owner_uid)
410 if ($width > 640 || $height > 640) {
411 $image->scaleDown(640);
412 $width = $image->getWidth();
413 $height = $image->getHeight();
415 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 1",
416 DBA::escape($image->asString()),
419 DBA::escape($resource_id),
420 intval($page_owner_uid)
424 if ($width > 320 || $height > 320) {
425 $image->scaleDown(320);
426 $width = $image->getWidth();
427 $height = $image->getHeight();
429 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 2",
430 DBA::escape($image->asString()),
433 DBA::escape($resource_id),
434 intval($page_owner_uid)
441 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
442 DBA::escape($resource_id),
443 intval($page_owner_uid)
446 if (DBA::isResult($p)) {
447 $ext = $phototypes[$p[0]['type']];
448 $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",
450 DBA::escape($albname),
451 DBA::escape($str_contact_allow),
452 DBA::escape($str_group_allow),
453 DBA::escape($str_contact_deny),
454 DBA::escape($str_group_deny),
455 DBA::escape($resource_id),
456 intval($page_owner_uid)
459 // Update the photo albums cache if album name was changed
460 if ($albname !== $origaname) {
461 Photo::clearAlbumCache($page_owner_uid);
465 /* Don't make the item visible if the only change was the album name */
468 if ($p[0]['desc'] !== $desc || strlen($rawtags)) {
473 // Create item container
475 $uri = Item::newURI($page_owner_uid);
478 $arr['guid'] = System::createUUID();
479 $arr['uid'] = $page_owner_uid;
481 $arr['parent-uri'] = $uri;
482 $arr['post-type'] = Item::PT_IMAGE;
484 $arr['resource-id'] = $p[0]['resource-id'];
485 $arr['contact-id'] = $owner_record['id'];
486 $arr['owner-name'] = $owner_record['name'];
487 $arr['owner-link'] = $owner_record['url'];
488 $arr['owner-avatar'] = $owner_record['thumb'];
489 $arr['author-name'] = $owner_record['name'];
490 $arr['author-link'] = $owner_record['url'];
491 $arr['author-avatar'] = $owner_record['thumb'];
492 $arr['title'] = $title;
493 $arr['allow_cid'] = $p[0]['allow_cid'];
494 $arr['allow_gid'] = $p[0]['allow_gid'];
495 $arr['deny_cid'] = $p[0]['deny_cid'];
496 $arr['deny_gid'] = $p[0]['deny_gid'];
497 $arr['visible'] = $visibility;
500 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
501 . '[img]' . System::baseUrl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
504 $item_id = Item::insert($arr);
508 $item = Item::selectFirst(['tag', 'inform'], ['id' => $item_id, 'uid' => $page_owner_uid]);
510 if (DBA::isResult($item)) {
511 $old_tag = $item['tag'];
512 $old_inform = $item['inform'];
515 if (strlen($rawtags)) {
519 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
520 $x = substr($rawtags, 0, 1);
521 if ($x !== '@' && $x !== '#') {
522 $rawtags = '#' . $rawtags;
526 $tags = get_tags($rawtags);
529 foreach ($tags as $tag) {
530 if (strpos($tag, '@') === 0) {
532 $name = substr($tag,1);
534 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
536 $links = @Probe::lrdd($name);
539 foreach ($links as $link) {
540 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
541 $profile = $link['@attributes']['href'];
544 if ($link['@attributes']['rel'] === 'salmon') {
545 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
547 if (strlen($inform)) {
556 $taginfo[] = [$newname, $profile, $salmon];
562 if (strrpos($newname, '+')) {
563 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
567 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
572 $newname = str_replace('_',' ',$name);
574 //select someone from this user's contacts by name
575 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
576 DBA::escape($newname),
577 intval($page_owner_uid)
580 if (!DBA::isResult($r)) {
581 //select someone by attag or nick and the name passed in
582 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
585 intval($page_owner_uid)
590 if (DBA::isResult($r)) {
591 $newname = $r[0]['name'];
592 $profile = $r[0]['url'];
594 $notify = 'cid:' . $r[0]['id'];
595 if (strlen($inform)) {
603 if (substr($notify, 0, 4) === 'cid:') {
604 $taginfo[] = [$newname, $profile, $notify, $r[0], '@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]'];
606 $taginfo[] = [$newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'];
609 if (strlen($str_tags)) {
613 $profile = str_replace(',', '%2c', $profile);
614 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
616 } elseif (strpos($tag, '#') === 0) {
617 $tagname = substr($tag, 1);
618 $str_tags .= '#[url=' . System::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url],';
624 if (strlen($newtag) && strlen($str_tags)) {
627 $newtag .= $str_tags;
629 $newinform = $old_inform;
630 if (strlen($newinform) && strlen($inform)) {
633 $newinform .= $inform;
635 $fields = ['tag' => $newtag, 'inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
636 $condition = ['id' => $item_id];
637 Item::update($fields, $condition);
640 foreach ($p as $scales) {
641 if (intval($scales['scale']) == 2) {
646 if (intval($scales['scale']) == 4) {
652 if (count($taginfo)) {
653 foreach ($taginfo as $tagged) {
654 $uri = Item::newURI($page_owner_uid);
657 $arr['guid'] = System::createUUID();
658 $arr['uid'] = $page_owner_uid;
660 $arr['parent-uri'] = $uri;
662 $arr['contact-id'] = $owner_record['id'];
663 $arr['owner-name'] = $owner_record['name'];
664 $arr['owner-link'] = $owner_record['url'];
665 $arr['owner-avatar'] = $owner_record['thumb'];
666 $arr['author-name'] = $owner_record['name'];
667 $arr['author-link'] = $owner_record['url'];
668 $arr['author-avatar'] = $owner_record['thumb'];
670 $arr['allow_cid'] = $p[0]['allow_cid'];
671 $arr['allow_gid'] = $p[0]['allow_gid'];
672 $arr['deny_cid'] = $p[0]['deny_cid'];
673 $arr['deny_gid'] = $p[0]['deny_gid'];
675 $arr['verb'] = ACTIVITY_TAG;
676 $arr['gravity'] = GRAVITY_PARENT;
677 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
678 $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
679 $arr['tag'] = $tagged[4];
680 $arr['inform'] = $tagged[2];
682 $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]') ;
683 $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" ;
685 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
686 $arr['object'] .= '<link>' . Strings::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
688 $arr['object'] .= Strings::escape('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
690 $arr['object'] .= '</link></object>' . "\n";
692 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $p[0]['desc'] . '</title><id>'
693 . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
694 $arr['target'] .= '<link>' . Strings::escape('<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>';
696 $item_id = Item::insert($arr);
700 $a->internalRedirect($_SESSION['photo_return']);
701 return; // NOTREACHED
705 // default post action - upload a photo
706 Addon::callHooks('photo_post_init', $_POST);
708 // Determine the album to use
709 $album = !empty($_REQUEST['album']) ? notags(trim($_REQUEST['album'])) : '';
710 $newalbum = !empty($_REQUEST['newalbum']) ? notags(trim($_REQUEST['newalbum'])) : '';
712 Logger::log('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , Logger::DEBUG);
714 if (!strlen($album)) {
715 if (strlen($newalbum)) {
718 $album = DateTimeFormat::localNow('Y');
723 * We create a wall item for every photo, but we don't want to
724 * overwhelm the data stream with a hundred newly uploaded photos.
725 * So we will make the first photo uploaded to this album in the last several hours
726 * visible by default, the rest will become visible over time when and if
727 * they acquire comments, likes, dislikes, and/or tags
730 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
732 intval($page_owner_uid)
735 if (!DBA::isResult($r) || ($album == L10n::t('Profile Photos'))) {
741 if (!empty($_REQUEST['not_visible']) && $_REQUEST['not_visible'] !== 'false') {
745 $group_allow = defaults($_REQUEST, 'group_allow' , []);
746 $contact_allow = defaults($_REQUEST, 'contact_allow', []);
747 $group_deny = defaults($_REQUEST, 'group_deny' , []);
748 $contact_deny = defaults($_REQUEST, 'contact_deny' , []);
750 $str_group_allow = perms2str(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
751 $str_contact_allow = perms2str(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
752 $str_group_deny = perms2str(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
753 $str_contact_deny = perms2str(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
755 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
757 Addon::callHooks('photo_post_file', $ret);
759 if (!empty($ret['src']) && !empty($ret['filesize'])) {
761 $filename = $ret['filename'];
762 $filesize = $ret['filesize'];
763 $type = $ret['type'];
764 $error = UPLOAD_ERR_OK;
765 } elseif (!empty($_FILES['userfile'])) {
766 $src = $_FILES['userfile']['tmp_name'];
767 $filename = basename($_FILES['userfile']['name']);
768 $filesize = intval($_FILES['userfile']['size']);
769 $type = $_FILES['userfile']['type'];
770 $error = $_FILES['userfile']['error'];
772 $error = UPLOAD_ERR_NO_FILE;
775 if ($error !== UPLOAD_ERR_OK) {
777 case UPLOAD_ERR_INI_SIZE:
778 notice(L10n::t('Image exceeds size limit of %s', ini_get('upload_max_filesize')) . EOL);
780 case UPLOAD_ERR_FORM_SIZE:
781 notice(L10n::t('Image exceeds size limit of %s', formatBytes(defaults($_REQUEST, 'MAX_FILE_SIZE', 0))) . EOL);
783 case UPLOAD_ERR_PARTIAL:
784 notice(L10n::t('Image upload didn\'t complete, please try again') . EOL);
786 case UPLOAD_ERR_NO_FILE:
787 notice(L10n::t('Image file is missing') . EOL);
789 case UPLOAD_ERR_NO_TMP_DIR:
790 case UPLOAD_ERR_CANT_WRITE:
791 case UPLOAD_ERR_EXTENSION:
792 notice(L10n::t('Server can\'t accept new file upload at this time, please contact your administrator') . EOL);
797 Addon::callHooks('photo_post_end', $foo);
802 $type = Image::guessType($filename);
805 Logger::log('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', Logger::DEBUG);
807 $maximagesize = Config::get('system', 'maximagesize');
809 if ($maximagesize && ($filesize > $maximagesize)) {
810 notice(L10n::t('Image exceeds size limit of %s', formatBytes($maximagesize)) . EOL);
813 Addon::callHooks('photo_post_end', $foo);
818 notice(L10n::t('Image file is empty.') . EOL);
821 Addon::callHooks('photo_post_end', $foo);
825 Logger::log('mod/photos.php: photos_post(): loading the contents of ' . $src , Logger::DEBUG);
827 $imagedata = @file_get_contents($src);
829 $image = new Image($imagedata, $type);
831 if (!$image->isValid()) {
832 Logger::log('mod/photos.php: photos_post(): unable to process image' , Logger::DEBUG);
833 notice(L10n::t('Unable to process image.') . EOL);
836 Addon::callHooks('photo_post_end',$foo);
840 $exif = $image->orient($src);
843 $max_length = Config::get('system', 'max_image_length');
845 $max_length = MAX_IMAGE_LENGTH;
847 if ($max_length > 0) {
848 $image->scaleDown($max_length);
851 $width = $image->getWidth();
852 $height = $image->getHeight();
856 $photo_hash = Photo::newResource();
858 $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);
861 Logger::log('mod/photos.php: photos_post(): image store failed', Logger::DEBUG);
862 notice(L10n::t('Image upload failed.') . EOL);
866 if ($width > 640 || $height > 640) {
867 $image->scaleDown(640);
868 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);
872 if ($width > 320 || $height > 320) {
873 $image->scaleDown(320);
874 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);
878 $uri = Item::newURI($page_owner_uid);
880 // Create item container
882 if ($exif && $exif['GPS'] && Feature::isEnabled($page_owner_uid, 'photo_location')) {
883 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
884 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
889 $arr['coord'] = $lat . ' ' . $lon;
892 $arr['guid'] = System::createUUID();
893 $arr['uid'] = $page_owner_uid;
895 $arr['parent-uri'] = $uri;
896 $arr['type'] = 'photo';
898 $arr['resource-id'] = $photo_hash;
899 $arr['contact-id'] = $owner_record['id'];
900 $arr['owner-name'] = $owner_record['name'];
901 $arr['owner-link'] = $owner_record['url'];
902 $arr['owner-avatar'] = $owner_record['thumb'];
903 $arr['author-name'] = $owner_record['name'];
904 $arr['author-link'] = $owner_record['url'];
905 $arr['author-avatar'] = $owner_record['thumb'];
907 $arr['allow_cid'] = $str_contact_allow;
908 $arr['allow_gid'] = $str_group_allow;
909 $arr['deny_cid'] = $str_contact_deny;
910 $arr['deny_gid'] = $str_group_deny;
911 $arr['visible'] = $visible;
914 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
915 . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$image->getExt() . '[/img]'
918 $item_id = Item::insert($arr);
919 // Update the photo albums cache
920 Photo::clearAlbumCache($page_owner_uid);
922 Addon::callHooks('photo_post_end', $item_id);
924 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
925 // if they do not wish to be redirected
927 $a->internalRedirect($_SESSION['photo_return']);
931 function photos_content(App $a)
935 // photos/name/upload
936 // photos/name/upload/xxxxx (xxxxx is album name)
937 // photos/name/album/xxxxx
938 // photos/name/album/xxxxx/edit
939 // photos/name/image/xxxxx
940 // photos/name/image/xxxxx/edit
942 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
943 notice(L10n::t('Public access denied.') . EOL);
947 require_once 'include/conversation.php';
949 if (empty($a->data['user'])) {
950 notice(L10n::t('No photos selected') . EOL);
954 $phototypes = Image::supportedTypes();
956 $_SESSION['photo_return'] = $a->cmd;
961 $datatype = $a->argv[2];
962 $datum = $a->argv[3];
963 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
964 $datatype = 'upload';
966 $datatype = 'summary';
975 // Setup permissions structures
979 $remote_contact = false;
983 $owner_uid = $a->data['user']['uid'];
985 $community_page = (($a->data['user']['page-flags'] == Contact::PAGE_COMMUNITY) ? true : false);
987 if (local_user() && (local_user() == $owner_uid)) {
990 if ($community_page && remote_user()) {
991 if (is_array($_SESSION['remote'])) {
992 foreach ($_SESSION['remote'] as $v) {
993 if ($v['uid'] == $owner_uid) {
994 $contact_id = $v['cid'];
1001 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1002 intval($contact_id),
1005 if (DBA::isResult($r)) {
1008 $remote_contact = true;
1009 $visitor = $contact_id;
1017 // perhaps they're visiting - but not a community page, so they wouldn't have write access
1018 if (remote_user() && !$visitor) {
1020 if (is_array($_SESSION['remote'])) {
1021 foreach ($_SESSION['remote'] as $v) {
1022 if ($v['uid'] == $owner_uid) {
1023 $contact_id = $v['cid'];
1029 $groups = Group::getIdsByContactId($contact_id);
1030 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1031 intval($contact_id),
1034 if (DBA::isResult($r)) {
1036 $remote_contact = true;
1041 if (!$remote_contact && local_user()) {
1042 $contact_id = $_SESSION['cid'];
1043 $contact = $a->contact;
1046 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
1047 notice(L10n::t('Access to this item is restricted.') . EOL);
1051 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid, $remote_contact, $groups);
1056 $is_owner = (local_user() && (local_user() == $owner_uid));
1057 $o .= Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
1059 // Display upload form
1060 if ($datatype === 'upload') {
1062 notice(L10n::t('Permission denied.'));
1066 $selname = $datum ? hex2bin($datum) : '';
1070 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '><current year></option>';
1071 if (!empty($a->data['albums'])) {
1072 foreach ($a->data['albums'] as $album) {
1073 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos'))) {
1076 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1077 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1083 $ret = ['post_url' => 'photos/' . $a->data['user']['nickname'],
1084 'addon_text' => $uploader,
1085 'default_upload' => true];
1087 Addon::callHooks('photo_upload_form',$ret);
1089 $default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
1090 $default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
1091 '$submit' => L10n::t('Submit'),
1094 $usage_message = '';
1096 $tpl = Renderer::getMarkupTemplate('photos_upload.tpl');
1098 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML($a->user));
1100 $o .= Renderer::replaceMacros($tpl,[
1101 '$pagename' => L10n::t('Upload Photos'),
1102 '$sessid' => session_id(),
1103 '$usage' => $usage_message,
1104 '$nickname' => $a->data['user']['nickname'],
1105 '$newalbum' => L10n::t('New album name: '),
1106 '$existalbumtext' => L10n::t('or select existing album:'),
1107 '$nosharetext' => L10n::t('Do not show a status post for this upload'),
1108 '$albumselect' => $albumselect,
1109 '$permissions' => L10n::t('Permissions'),
1110 '$aclselect' => $aclselect_e,
1111 '$lockstate' => is_array($a->user)
1112 && (strlen($a->user['allow_cid'])
1113 || strlen($a->user['allow_gid'])
1114 || strlen($a->user['deny_cid'])
1115 || strlen($a->user['deny_gid'])
1116 ) ? 'lock' : 'unlock',
1117 '$alt_uploader' => $ret['addon_text'],
1118 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
1119 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
1120 '$uploadurl' => $ret['post_url'],
1122 // ACL permissions box
1123 '$group_perms' => L10n::t('Show to Groups'),
1124 '$contact_perms' => L10n::t('Show to Contacts'),
1125 '$return_path' => $a->query_string,
1131 // Display a single photo album
1132 if ($datatype === 'album') {
1133 $album = hex2bin($datum);
1136 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1137 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1141 if (DBA::isResult($r)) {
1145 $pager = new Pager($a->query_string, 20);
1147 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1148 $order_field = defaults($_GET, 'order', '');
1149 if ($order_field === 'posted') {
1155 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1156 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1157 ANY_VALUE(`created`) as `created`
1158 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1159 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1161 DBA::escape($album),
1163 $pager->getItemsPerPage()
1167 if ($cmd === 'edit') {
1168 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos'))) {
1170 $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
1174 $o .= Renderer::replaceMacros($edit_tpl,[
1175 '$nametext' => L10n::t('New album name: '),
1176 '$nickname' => $a->data['user']['nickname'],
1177 '$album' => $album_e,
1178 '$hexalbum' => bin2hex($album),
1179 '$submit' => L10n::t('Submit'),
1180 '$dropsubmit' => L10n::t('Delete Album')
1185 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos')) && $can_post) {
1186 $edit = [L10n::t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1190 if ($order_field === 'posted') {
1191 $order = [L10n::t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1193 $order = [L10n::t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted', 'newest'];
1198 if (DBA::isResult($r)) {
1199 // "Twist" is only used for the duepunto theme with style "slackr"
1201 foreach ($r as $rr) {
1204 $ext = $phototypes[$rr['type']];
1206 $imgalt_e = $rr['filename'];
1207 $desc_e = $rr['desc'];
1211 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1212 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1213 . ($order_field === 'posted' ? '?f=&order=posted' : ''),
1214 'title' => L10n::t('View Photo'),
1215 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1219 'hash'=> $rr['resource-id'],
1224 $tpl = Renderer::getMarkupTemplate('photo_album.tpl');
1225 $o .= Renderer::replaceMacros($tpl, [
1226 '$photos' => $photos,
1228 '$can_post' => $can_post,
1229 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)],
1232 '$paginate' => $pager->renderFull($total),
1239 // Display one photo
1240 if ($datatype === 'image') {
1241 // fetch image, item containing image, then comments
1242 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1243 $sql_extra ORDER BY `scale` ASC ",
1248 if (!DBA::isResult($ph)) {
1249 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1254 if (DBA::isResult($ph)) {
1255 notice(L10n::t('Permission denied. Access to this item may be restricted.'));
1257 notice(L10n::t('Photo not available') . EOL);
1266 * @todo This query is totally bad, the whole functionality has to be changed
1267 * The query leads to a really intense used index.
1268 * By now we hide it if someone wants to.
1270 if (!Config::get('system', 'no_count', false)) {
1271 $order_field = defaults($_GET, 'order', '');
1273 if ($order_field === 'posted') {
1279 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1280 $sql_extra ORDER BY `created` $order ",
1281 DBA::escape($ph[0]['album']),
1285 if (DBA::isResult($prvnxt)) {
1288 foreach ($prvnxt as $z => $entry) {
1289 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1293 $prv = count($prvnxt) - 1;
1295 if ($nxt >= count($prvnxt)) {
1301 $edit_suffix = ((($cmd === 'edit') && $can_post) ? '/edit' : '');
1302 if (!is_null($prv)) {
1303 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1305 if (!is_null($nxt)) {
1306 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1311 if (count($ph) == 1) {
1312 $hires = $lores = $ph[0];
1315 if (count($ph) > 1) {
1316 if ($ph[1]['scale'] == 2) {
1317 // original is 640 or less, we can display it directly
1318 $hires = $lores = $ph[0];
1325 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1330 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1332 'edit' => ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? L10n::t('View photo') : L10n::t('Edit photo'))],
1333 'profile'=>['profile_photo/use/'.$ph[0]['resource-id'], L10n::t('Use as profile photo')],
1337 $lock = ((($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1338 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])))
1339 ? L10n::t('Private Message')
1345 if ($cmd === 'edit') {
1346 $tpl = Renderer::getMarkupTemplate('photo_edit_head.tpl');
1347 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl,[
1348 '$prevlink' => $prevlink,
1349 '$nextlink' => $nextlink
1354 $prevlink = [$prevlink, '<div class="icon prev"></div>'] ;
1358 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1359 'title'=> L10n::t('View Full Size'),
1360 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . DateTimeFormat::utcNow('ymdhis'),
1361 'height' => $hires['height'],
1362 'width' => $hires['width'],
1363 'album' => $hires['album'],
1364 'filename' => $hires['filename'],
1368 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1372 // Do we have an item for this photo?
1374 // FIXME! - replace following code to display the conversation with our normal
1375 // conversation functions so that it works correctly and tracks changes
1376 // in the evolving conversation code.
1377 // The difference is that we won't be displaying the conversation head item
1378 // as a "post" but displaying instead the photo it is linked to
1380 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1381 $linked_items = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1389 if (DBA::isResult($linked_items)) {
1390 // This is a workaround to not being forced to rewrite the while $sql_extra handling
1391 $link_item = Item::selectFirst([], ['id' => $linked_items[0]['id']]);
1393 $condition = ["`parent` = ? AND `parent` != `id`", $link_item['parent']];
1394 $total = DBA::count('item', $condition);
1396 $pager = new Pager($a->query_string);
1398 $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1399 $result = Item::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params);
1400 $items = Item::inArray($result);
1402 if (local_user() && (local_user() == $link_item['uid'])) {
1403 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1406 if ($link_item['coord']) {
1407 $map = Map::byCoordinates($link_item['coord']);
1413 if (count($linked_items) && strlen($link_item['tag'])) {
1414 $arr = explode(',', $link_item['tag']);
1415 // parse tags and add links
1417 foreach ($arr as $tag) {
1419 'name' => BBCode::convert($tag),
1420 'removeurl' => '/tagrm/'.$link_item['id'] . '/' . bin2hex($tag)
1423 $tags = ['title' => L10n::t('Tags: '), 'tags' => $tag_arr];
1424 if ($cmd === 'edit') {
1425 $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
1426 $tags['removetitle'] = L10n::t('[Select tags to remove]');
1432 if ($cmd === 'edit' && $can_post) {
1433 $edit_tpl = Renderer::getMarkupTemplate('photo_edit.tpl');
1435 $album_e = $ph[0]['album'];
1436 $caption_e = $ph[0]['desc'];
1437 $aclselect_e = ACL::getFullSelectorHTML($a->user, false, $ph[0]);
1439 $edit = Renderer::replaceMacros($edit_tpl, [
1440 '$id' => $ph[0]['id'],
1441 '$album' => ['albname', L10n::t('New album name'), $album_e,''],
1442 '$caption' => ['desc', L10n::t('Caption'), $caption_e, ''],
1443 '$tags' => ['newtag', L10n::t('Add a Tag'), "", L10n::t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1444 '$rotate_none' => ['rotate', L10n::t('Do not rotate'),0,'', true],
1445 '$rotate_cw' => ['rotate', L10n::t("Rotate CW \x28right\x29"),1,''],
1446 '$rotate_ccw' => ['rotate', L10n::t("Rotate CCW \x28left\x29"),2,''],
1448 '$nickname' => $a->data['user']['nickname'],
1449 '$resource_id' => $ph[0]['resource-id'],
1450 '$permissions' => L10n::t('Permissions'),
1451 '$aclselect' => $aclselect_e,
1453 '$item_id' => defaults($link_item, 'id', 0),
1454 '$submit' => L10n::t('Submit'),
1455 '$delete' => L10n::t('Delete Photo'),
1457 // ACL permissions box
1458 '$group_perms' => L10n::t('Show to Groups'),
1459 '$contact_perms' => L10n::t('Show to Contacts'),
1460 '$return_path' => $a->query_string,
1471 if (count($linked_items)) {
1472 $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
1473 $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
1474 $return_path = $a->cmd;
1476 if ($can_post || Security::canWriteToUserWall($owner_uid)) {
1477 $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl');
1478 $likebuttons = Renderer::replaceMacros($like_tpl, [
1479 '$id' => $link_item['id'],
1480 '$likethis' => L10n::t("I like this \x28toggle\x29"),
1481 '$nolike' => (Feature::isEnabled(local_user(), 'dislike') ? L10n::t("I don't like this \x28toggle\x29") : ''),
1482 '$wait' => L10n::t('Please wait'),
1483 '$return_path' => $a->query_string,
1487 if (!DBA::isResult($items)) {
1488 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1489 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1490 '$return_path' => '',
1491 '$jsreload' => $return_path,
1492 '$id' => $link_item['id'],
1493 '$parent' => $link_item['id'],
1494 '$profile_uid' => $owner_uid,
1495 '$mylink' => $contact['url'],
1496 '$mytitle' => L10n::t('This is you'),
1497 '$myphoto' => $contact['thumb'],
1498 '$comment' => L10n::t('Comment'),
1499 '$submit' => L10n::t('Submit'),
1500 '$preview' => L10n::t('Preview'),
1501 '$sourceapp' => L10n::t($a->sourcename),
1503 '$rand_num' => random_digits(12)
1509 'like' => ['title' => L10n::t('Likes','title')],'dislike' => ['title' => L10n::t('Dislikes','title')],
1510 'attendyes' => ['title' => L10n::t('Attending','title')], 'attendno' => ['title' => L10n::t('Not attending','title')], 'attendmaybe' => ['title' => L10n::t('Might attend','title')]
1514 if (DBA::isResult($items)) {
1515 foreach ($items as $item) {
1516 builtin_activity_puller($item, $conv_responses);
1519 if (!empty($conv_responses['like'][$link_item['uri']])) {
1520 $like = format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like', $link_item['id']);
1523 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1524 $dislike = format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike', $link_item['id']);
1527 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1528 $comments .= Renderer::replaceMacros($cmnt_tpl,[
1529 '$return_path' => '',
1530 '$jsreload' => $return_path,
1531 '$id' => $link_item['id'],
1532 '$parent' => $link_item['id'],
1533 '$profile_uid' => $owner_uid,
1534 '$mylink' => $contact['url'],
1535 '$mytitle' => L10n::t('This is you'),
1536 '$myphoto' => $contact['thumb'],
1537 '$comment' => L10n::t('Comment'),
1538 '$submit' => L10n::t('Submit'),
1539 '$preview' => L10n::t('Preview'),
1540 '$sourceapp' => L10n::t($a->sourcename),
1542 '$rand_num' => random_digits(12)
1546 foreach ($items as $item) {
1551 if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) {
1555 $profile_url = Contact::MagicLinkById($item['author-id']);
1556 if (strpos($profile_url, 'redir/') === 0) {
1557 $sparkle = ' sparkle';
1562 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1564 'dropping' => $dropping,
1565 'pagedrop' => false,
1566 'select' => L10n::t('Select'),
1567 'delete' => L10n::t('Delete'),
1570 $title_e = $item['title'];
1571 $body_e = BBCode::convert($item['body']);
1573 $comments .= Renderer::replaceMacros($template,[
1574 '$id' => $item['id'],
1575 '$profile_url' => $profile_url,
1576 '$name' => $item['author-name'],
1577 '$thumb' => $item['author-avatar'],
1578 '$sparkle' => $sparkle,
1579 '$title' => $title_e,
1581 '$ago' => Temporal::getRelativeDate($item['created']),
1582 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1584 '$comment' => $comment
1587 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1588 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1589 '$return_path' => '',
1590 '$jsreload' => $return_path,
1591 '$id' => $item['item_id'],
1592 '$parent' => $item['parent'],
1593 '$profile_uid' => $owner_uid,
1594 '$mylink' => $contact['url'],
1595 '$mytitle' => L10n::t('This is you'),
1596 '$myphoto' => $contact['thumb'],
1597 '$comment' => L10n::t('Comment'),
1598 '$submit' => L10n::t('Submit'),
1599 '$preview' => L10n::t('Preview'),
1600 '$sourceapp' => L10n::t($a->sourcename),
1602 '$rand_num' => random_digits(12)
1607 $response_verbs = ['like'];
1608 if (Feature::isEnabled($owner_uid, 'dislike')) {
1609 $response_verbs[] = 'dislike';
1611 $responses = get_responses($conv_responses, $response_verbs, '', $link_item);
1613 $paginate = $pager->renderFull($total);
1616 $photo_tpl = Renderer::getMarkupTemplate('photo_view.tpl');
1617 $o .= Renderer::replaceMacros($photo_tpl, [
1618 '$id' => $ph[0]['id'],
1619 '$album' => [$album_link, $ph[0]['album']],
1623 '$prevlink' => $prevlink,
1624 '$nextlink' => $nextlink,
1625 '$desc' => $ph[0]['desc'],
1629 '$map_text' => L10n::t('Map'),
1630 '$likebuttons' => $likebuttons,
1632 '$dislike' => $dislike,
1633 'responses' => $responses,
1634 '$comments' => $comments,
1635 '$paginate' => $paginate,
1638 $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
1639 $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1640 $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . $photo["href"] . '" />' . "\n";
1641 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1642 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1647 // Default - show recent photos with upload link (if applicable)
1650 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1651 $sql_extra GROUP BY `resource-id`",
1652 intval($a->data['user']['uid']),
1653 DBA::escape('Contact Photos'),
1654 DBA::escape(L10n::t('Contact Photos'))
1656 if (DBA::isResult($r)) {
1660 $pager = new Pager($a->query_string, 20);
1662 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1663 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1664 ANY_VALUE(`created`) AS `created` FROM `photo`
1665 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1666 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1667 intval($a->data['user']['uid']),
1668 DBA::escape('Contact Photos'),
1669 DBA::escape(L10n::t('Contact Photos')),
1671 $pager->getItemsPerPage()
1675 if (DBA::isResult($r)) {
1676 // "Twist" is only used for the duepunto theme with style "slackr"
1678 foreach ($r as $rr) {
1679 //hide profile photos to others
1680 if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos'))) {
1686 $ext = $phototypes[$rr['type']];
1688 $alt_e = $rr['filename'];
1689 $name_e = $rr['album'];
1693 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1694 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1695 'title' => L10n::t('View Photo'),
1696 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1699 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1701 'alt' => L10n::t('View Album'),
1708 $tpl = Renderer::getMarkupTemplate('photos_recent.tpl');
1709 $o .= Renderer::replaceMacros($tpl, [
1710 '$title' => L10n::t('Recent Photos'),
1711 '$can_post' => $can_post,
1712 '$upload' => [L10n::t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'],
1713 '$photos' => $photos,
1714 '$paginate' => $pager->renderFull($total),