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\DBM;
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 (!DBM::is_result($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 (!x($a->page, 'aside')) {
122 $a->page['aside'] = '';
124 $a->page['aside'] .= $vcard_widget;
125 $a->page['aside'] .= $photo_albums_widget;
127 $tpl = get_markup_template("photos_head.tpl");
128 $a->page['htmlhead'] .= replace_macros($tpl,[
129 '$ispublic' => L10n::t('everybody')
136 function photos_post(App $a)
138 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
139 logger('mod_photos: REQUEST ' . print_r($_REQUEST, true), LOGGER_DATA);
140 logger('mod_photos: FILES ' . print_r($_FILES, true), LOGGER_DATA);
142 $phototypes = Image::supportedTypes();
147 $page_owner_uid = $a->data['user']['uid'];
148 $community_page = $a->data['user']['page-flags'] == PAGE_COMMUNITY;
150 if (local_user() && (local_user() == $page_owner_uid)) {
153 if ($community_page && remote_user()) {
155 if (x($_SESSION, 'remote') && is_array($_SESSION['remote'])) {
156 foreach ($_SESSION['remote'] as $v) {
157 if ($v['uid'] == $page_owner_uid) {
158 $contact_id = $v['cid'];
164 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
166 intval($page_owner_uid)
168 if (DBM::is_result($r)) {
170 $visitor = $contact_id;
177 notice(L10n::t('Permission denied.') . EOL);
181 $owner_record = User::getOwnerDataById($page_owner_uid);
183 if (!$owner_record) {
184 notice(L10n::t('Contact information unavailable') . EOL);
185 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
189 if ($a->argc > 3 && $a->argv[2] === 'album') {
190 $album = hex2bin($a->argv[3]);
192 if ($album === L10n::t('Profile Photos') || $album === 'Contact Photos' || $album === L10n::t('Contact Photos')) {
193 goaway($_SESSION['photo_return']);
194 return; // NOTREACHED
197 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
199 intval($page_owner_uid)
201 if (!DBM::is_result($r)) {
202 notice(L10n::t('Album not found.') . EOL);
203 goaway($_SESSION['photo_return']);
204 return; // NOTREACHED
207 // Check if the user has responded to a delete confirmation query
208 if ($_REQUEST['canceled']) {
209 goaway($_SESSION['photo_return']);
212 // RENAME photo album
213 $newalbum = notags(trim($_POST['albumname']));
214 if ($newalbum != $album) {
215 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
218 intval($page_owner_uid)
220 // Update the photo albums cache
221 Photo::clearAlbumCache($page_owner_uid);
223 $newurl = str_replace(bin2hex($album), bin2hex($newalbum), $_SESSION['photo_return']);
225 return; // NOTREACHED
229 * DELETE photo album and all its photos
232 if ($_POST['dropalbum'] == L10n::t('Delete Album')) {
233 // Check if we should do HTML-based delete confirmation
234 if (x($_REQUEST, 'confirm')) {
235 $drop_url = $a->query_string;
237 ['name' => 'albumname', 'value' => $_POST['albumname']],
239 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
241 '$message' => L10n::t('Do you really want to delete this photo album and all its photos?'),
242 '$extra_inputs' => $extra_inputs,
243 '$confirm' => L10n::t('Delete Album'),
244 '$confirm_url' => $drop_url,
245 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
246 '$cancel' => L10n::t('Cancel'),
248 $a->error = 1; // Set $a->error so the other module functions don't execute
254 // get the list of photos we are about to delete
257 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
259 intval($page_owner_uid),
263 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
264 intval(local_user()),
268 if (DBM::is_result($r)) {
269 foreach ($r as $rr) {
270 $res[] = "'" . dbesc($rr['rid']) . "'" ;
273 goaway($_SESSION['photo_return']);
274 return; // NOTREACHED
277 $str_res = implode(',', $res);
279 // remove the associated photos
280 q("DELETE FROM `photo` WHERE `resource-id` IN ($str_res) AND `uid` = %d",
281 intval($page_owner_uid)
284 // find and delete the corresponding item with all the comments and likes/dislikes
285 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
287 // Update the photo albums cache
288 Photo::clearAlbumCache($page_owner_uid);
291 goaway('photos/' . $a->data['user']['nickname']);
292 return; // NOTREACHED
296 // Check if the user has responded to a delete confirmation query for a single photo
297 if ($a->argc > 2 && x($_REQUEST, 'canceled')) {
298 goaway($_SESSION['photo_return']);
301 if ($a->argc > 2 && defaults($_POST, 'delete', '') === L10n::t('Delete Photo')) {
303 // same as above but remove single photo
305 // Check if we should do HTML-based delete confirmation
306 if (x($_REQUEST, 'confirm')) {
307 $drop_url = $a->query_string;
308 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
310 '$message' => L10n::t('Do you really want to delete this photo?'),
311 '$extra_inputs' => [],
312 '$confirm' => L10n::t('Delete Photo'),
313 '$confirm_url' => $drop_url,
314 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
315 '$cancel' => L10n::t('Cancel'),
317 $a->error = 1; // Set $a->error so the other module functions don't execute
322 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
324 intval($page_owner_uid),
328 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
329 intval(local_user()),
333 if (DBM::is_result($r)) {
334 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
335 intval($page_owner_uid),
336 dbesc($r[0]['resource-id'])
339 Item::deleteForUser(['resource-id' => $r[0]['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
341 // Update the photo albums cache
342 Photo::clearAlbumCache($page_owner_uid);
345 goaway('photos/' . $a->data['user']['nickname']);
346 return; // NOTREACHED
349 if ($a->argc > 2 && (x($_POST, 'desc') !== false || x($_POST, 'newtag') !== false || x($_POST, 'albname') !== false)) {
350 $desc = x($_POST, 'desc') ? notags(trim($_POST['desc'])) : '';
351 $rawtags = x($_POST, 'newtag') ? notags(trim($_POST['newtag'])) : '';
352 $item_id = x($_POST, 'item_id') ? intval($_POST['item_id']) : 0;
353 $albname = x($_POST, 'albname') ? notags(trim($_POST['albname'])) : '';
354 $origaname = x($_POST, 'origaname') ? notags(trim($_POST['origaname'])) : '';
355 $str_group_allow = perms2str($_POST['group_allow']);
356 $str_contact_allow = perms2str($_POST['contact_allow']);
357 $str_group_deny = perms2str($_POST['group_deny']);
358 $str_contact_deny = perms2str($_POST['contact_deny']);
360 $resource_id = $a->argv[2];
362 if (!strlen($albname)) {
363 $albname = DateTimeFormat::localNow('Y');
366 if (x($_POST,'rotate') !== false &&
367 (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
370 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0 LIMIT 1",
372 intval($page_owner_uid)
374 if (DBM::is_result($r)) {
375 $Image = new Image($r[0]['data'], $r[0]['type']);
376 if ($Image->isValid()) {
377 $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
378 $Image->rotate($rotate_deg);
380 $width = $Image->getWidth();
381 $height = $Image->getHeight();
383 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0",
384 dbesc($Image->asString()),
388 intval($page_owner_uid)
391 if ($width > 640 || $height > 640) {
392 $Image->scaleDown(640);
393 $width = $Image->getWidth();
394 $height = $Image->getHeight();
396 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 1",
397 dbesc($Image->asString()),
401 intval($page_owner_uid)
405 if ($width > 320 || $height > 320) {
406 $Image->scaleDown(320);
407 $width = $Image->getWidth();
408 $height = $Image->getHeight();
410 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 2",
411 dbesc($Image->asString()),
415 intval($page_owner_uid)
422 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
424 intval($page_owner_uid)
426 if (DBM::is_result($p)) {
427 $ext = $phototypes[$p[0]['type']];
428 $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",
431 dbesc($str_contact_allow),
432 dbesc($str_group_allow),
433 dbesc($str_contact_deny),
434 dbesc($str_group_deny),
436 intval($page_owner_uid)
439 // Update the photo albums cache if album name was changed
440 if ($albname !== $origaname) {
441 Photo::clearAlbumCache($page_owner_uid);
445 /* Don't make the item visible if the only change was the album name */
448 if ($p[0]['desc'] !== $desc || strlen($rawtags)) {
453 // Create item container
455 $uri = Item::newURI($page_owner_uid);
458 $arr['guid'] = System::createGUID(32);
459 $arr['uid'] = $page_owner_uid;
461 $arr['parent-uri'] = $uri;
462 $arr['type'] = 'photo';
464 $arr['resource-id'] = $p[0]['resource-id'];
465 $arr['contact-id'] = $owner_record['id'];
466 $arr['owner-name'] = $owner_record['name'];
467 $arr['owner-link'] = $owner_record['url'];
468 $arr['owner-avatar'] = $owner_record['thumb'];
469 $arr['author-name'] = $owner_record['name'];
470 $arr['author-link'] = $owner_record['url'];
471 $arr['author-avatar'] = $owner_record['thumb'];
472 $arr['title'] = $title;
473 $arr['allow_cid'] = $p[0]['allow_cid'];
474 $arr['allow_gid'] = $p[0]['allow_gid'];
475 $arr['deny_cid'] = $p[0]['deny_cid'];
476 $arr['deny_gid'] = $p[0]['deny_gid'];
477 $arr['visible'] = $visibility;
480 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
481 . '[img]' . System::baseUrl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
484 $item_id = Item::insert($arr);
488 $item = Item::selectFirst(['tag', 'inform'], ['id' => $item_id, 'uid' => $page_owner_uid]);
490 if (DBM::is_result($item)) {
491 $old_tag = $item['tag'];
492 $old_inform = $item['inform'];
495 if (strlen($rawtags)) {
499 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
500 $x = substr($rawtags, 0, 1);
501 if ($x !== '@' && $x !== '#') {
502 $rawtags = '#' . $rawtags;
506 $tags = get_tags($rawtags);
509 foreach ($tags as $tag) {
510 if (strpos($tag, '@') === 0) {
512 $name = substr($tag,1);
513 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
515 $links = @Probe::lrdd($name);
517 foreach ($links as $link) {
518 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
519 $profile = $link['@attributes']['href'];
521 if ($link['@attributes']['rel'] === 'salmon') {
522 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
523 if (strlen($inform)) {
530 $taginfo[] = [$newname, $profile, $salmon];
535 if (strrpos($newname, '+')) {
536 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
540 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
545 $newname = str_replace('_',' ',$name);
547 //select someone from this user's contacts by name
548 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
550 intval($page_owner_uid)
553 if (!DBM::is_result($r)) {
554 //select someone by attag or nick and the name passed in
555 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
558 intval($page_owner_uid)
563 if (DBM::is_result($r)) {
564 $newname = $r[0]['name'];
565 $profile = $r[0]['url'];
566 $notify = 'cid:' . $r[0]['id'];
567 if (strlen($inform)) {
574 if (substr($notify, 0, 4) === 'cid:') {
575 $taginfo[] = [$newname, $profile, $notify, $r[0], '@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]'];
577 $taginfo[] = [$newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'];
579 if (strlen($str_tags)) {
582 $profile = str_replace(',', '%2c', $profile);
583 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
585 } elseif (strpos($tag, '#') === 0) {
586 $tagname = substr($tag, 1);
587 $str_tags .= '#[url=' . System::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url]';
593 if (strlen($newtag) && strlen($str_tags)) {
596 $newtag .= $str_tags;
598 $newinform = $old_inform;
599 if (strlen($newinform) && strlen($inform)) {
602 $newinform .= $inform;
604 $fields = ['tag' => $newtag, 'inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
605 $condition = ['id' => $item_id];
606 Item::update($fields, $condition);
609 foreach ($p as $scales) {
610 if (intval($scales['scale']) == 2) {
614 if (intval($scales['scale']) == 4) {
620 if (count($taginfo)) {
621 foreach ($taginfo as $tagged) {
622 $uri = Item::newURI($page_owner_uid);
625 $arr['guid'] = System::createGUID(32);
626 $arr['uid'] = $page_owner_uid;
628 $arr['parent-uri'] = $uri;
629 $arr['type'] = 'activity';
631 $arr['contact-id'] = $owner_record['id'];
632 $arr['owner-name'] = $owner_record['name'];
633 $arr['owner-link'] = $owner_record['url'];
634 $arr['owner-avatar'] = $owner_record['thumb'];
635 $arr['author-name'] = $owner_record['name'];
636 $arr['author-link'] = $owner_record['url'];
637 $arr['author-avatar'] = $owner_record['thumb'];
639 $arr['allow_cid'] = $p[0]['allow_cid'];
640 $arr['allow_gid'] = $p[0]['allow_gid'];
641 $arr['deny_cid'] = $p[0]['deny_cid'];
642 $arr['deny_gid'] = $p[0]['deny_gid'];
644 $arr['verb'] = ACTIVITY_TAG;
645 $arr['gravity'] = GRAVITY_PARENT;
646 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
647 $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
648 $arr['tag'] = $tagged[4];
649 $arr['inform'] = $tagged[2];
651 $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]') ;
652 $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" ;
654 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
655 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
657 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
659 $arr['object'] .= '</link></object>' . "\n";
661 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $p[0]['desc'] . '</title><id>'
662 . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
663 $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>';
665 $item_id = Item::insert($arr);
667 Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
672 goaway($_SESSION['photo_return']);
673 return; // NOTREACHED
677 // default post action - upload a photo
678 Addon::callHooks('photo_post_init', $_POST);
680 // Determine the album to use
681 $album = x($_REQUEST, 'album') ? notags(trim($_REQUEST['album'])) : '';
682 $newalbum = x($_REQUEST, 'newalbum') ? notags(trim($_REQUEST['newalbum'])) : '';
684 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
686 if (!strlen($album)) {
687 if (strlen($newalbum)) {
690 $album = DateTimeFormat::localNow('Y');
695 * We create a wall item for every photo, but we don't want to
696 * overwhelm the data stream with a hundred newly uploaded photos.
697 * So we will make the first photo uploaded to this album in the last several hours
698 * visible by default, the rest will become visible over time when and if
699 * they acquire comments, likes, dislikes, and/or tags
702 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
704 intval($page_owner_uid)
706 if (!DBM::is_result($r) || ($album == L10n::t('Profile Photos'))) {
712 if (x($_REQUEST, 'not_visible') && $_REQUEST['not_visible'] !== 'false') {
716 $group_allow = defaults($_REQUEST, 'group_allow' , []);
717 $contact_allow = defaults($_REQUEST, 'contact_allow', []);
718 $group_deny = defaults($_REQUEST, 'group_deny' , []);
719 $contact_deny = defaults($_REQUEST, 'contact_deny' , []);
721 $str_group_allow = perms2str(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
722 $str_contact_allow = perms2str(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
723 $str_group_deny = perms2str(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
724 $str_contact_deny = perms2str(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
726 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
728 Addon::callHooks('photo_post_file', $ret);
730 if (x($ret, 'src') && x($ret, 'filesize')) {
732 $filename = $ret['filename'];
733 $filesize = $ret['filesize'];
734 $type = $ret['type'];
735 $error = UPLOAD_ERR_OK;
737 $src = $_FILES['userfile']['tmp_name'];
738 $filename = basename($_FILES['userfile']['name']);
739 $filesize = intval($_FILES['userfile']['size']);
740 $type = $_FILES['userfile']['type'];
741 $error = $_FILES['userfile']['error'];
744 if ($error !== UPLOAD_ERR_OK) {
746 case UPLOAD_ERR_INI_SIZE:
747 notice(L10n::t('Image exceeds size limit of %s', ini_get('upload_max_filesize')) . EOL);
749 case UPLOAD_ERR_FORM_SIZE:
750 notice(L10n::t('Image exceeds size limit of %s', formatBytes(defaults($_REQUEST, 'MAX_FILE_SIZE', 0))) . EOL);
752 case UPLOAD_ERR_PARTIAL:
753 notice(L10n::t('Image upload didn\'t complete, please try again') . EOL);
755 case UPLOAD_ERR_NO_FILE:
756 notice(L10n::t('Image file is missing') . EOL);
758 case UPLOAD_ERR_NO_TMP_DIR:
759 case UPLOAD_ERR_CANT_WRITE:
760 case UPLOAD_ERR_EXTENSION:
761 notice(L10n::t('Server can\'t accept new file upload at this time, please contact your administrator') . EOL);
766 Addon::callHooks('photo_post_end', $foo);
771 $type = Image::guessType($filename);
774 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
776 $maximagesize = Config::get('system', 'maximagesize');
778 if ($maximagesize && ($filesize > $maximagesize)) {
779 notice(L10n::t('Image exceeds size limit of %s', formatBytes($maximagesize)) . EOL);
782 Addon::callHooks('photo_post_end', $foo);
787 notice(L10n::t('Image file is empty.') . EOL);
790 Addon::callHooks('photo_post_end', $foo);
794 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
796 $imagedata = @file_get_contents($src);
798 $Image = new Image($imagedata, $type);
800 if (!$Image->isValid()) {
801 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
802 notice(L10n::t('Unable to process image.') . EOL);
805 Addon::callHooks('photo_post_end',$foo);
809 $exif = $Image->orient($src);
812 $max_length = Config::get('system', 'max_image_length');
814 $max_length = MAX_IMAGE_LENGTH;
816 if ($max_length > 0) {
817 $Image->scaleDown($max_length);
820 $width = $Image->getWidth();
821 $height = $Image->getHeight();
825 $photo_hash = Photo::newResource();
827 $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);
830 logger('mod/photos.php: photos_post(): image store failed', LOGGER_DEBUG);
831 notice(L10n::t('Image upload failed.') . EOL);
835 if ($width > 640 || $height > 640) {
836 $Image->scaleDown(640);
837 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);
841 if ($width > 320 || $height > 320) {
842 $Image->scaleDown(320);
843 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);
847 $uri = Item::newURI($page_owner_uid);
849 // Create item container
851 if ($exif && $exif['GPS'] && Feature::isEnabled($page_owner_uid, 'photo_location')) {
852 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
853 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
858 $arr['coord'] = $lat . ' ' . $lon;
861 $arr['guid'] = System::createGUID(32);
862 $arr['uid'] = $page_owner_uid;
864 $arr['parent-uri'] = $uri;
865 $arr['type'] = 'photo';
867 $arr['resource-id'] = $photo_hash;
868 $arr['contact-id'] = $owner_record['id'];
869 $arr['owner-name'] = $owner_record['name'];
870 $arr['owner-link'] = $owner_record['url'];
871 $arr['owner-avatar'] = $owner_record['thumb'];
872 $arr['author-name'] = $owner_record['name'];
873 $arr['author-link'] = $owner_record['url'];
874 $arr['author-avatar'] = $owner_record['thumb'];
876 $arr['allow_cid'] = $str_contact_allow;
877 $arr['allow_gid'] = $str_group_allow;
878 $arr['deny_cid'] = $str_contact_deny;
879 $arr['deny_gid'] = $str_group_deny;
880 $arr['visible'] = $visible;
883 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
884 . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$Image->getExt() . '[/img]'
887 $item_id = Item::insert($arr);
888 // Update the photo albums cache
889 Photo::clearAlbumCache($page_owner_uid);
892 Worker::add(PRIORITY_HIGH, "Notifier", 'wall-new', $item_id);
895 Addon::callHooks('photo_post_end', intval($item_id));
897 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
898 // if they do not wish to be redirected
900 goaway($_SESSION['photo_return']);
904 function photos_content(App $a)
908 // photos/name/upload
909 // photos/name/upload/xxxxx (xxxxx is album name)
910 // photos/name/album/xxxxx
911 // photos/name/album/xxxxx/edit
912 // photos/name/image/xxxxx
913 // photos/name/image/xxxxx/edit
915 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
916 notice(L10n::t('Public access denied.') . EOL);
920 require_once 'include/security.php';
921 require_once 'include/conversation.php';
923 if (!x($a->data,'user')) {
924 notice(L10n::t('No photos selected') . EOL);
928 $phototypes = Image::supportedTypes();
930 $_SESSION['photo_return'] = $a->cmd;
935 $datatype = $a->argv[2];
936 $datum = $a->argv[3];
937 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
938 $datatype = 'upload';
940 $datatype = 'summary';
949 // Setup permissions structures
953 $remote_contact = false;
957 $owner_uid = $a->data['user']['uid'];
959 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
961 if (local_user() && (local_user() == $owner_uid)) {
964 if ($community_page && remote_user()) {
965 if (is_array($_SESSION['remote'])) {
966 foreach ($_SESSION['remote'] as $v) {
967 if ($v['uid'] == $owner_uid) {
968 $contact_id = $v['cid'];
975 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
979 if (DBM::is_result($r)) {
982 $remote_contact = true;
983 $visitor = $contact_id;
991 // perhaps they're visiting - but not a community page, so they wouldn't have write access
992 if (remote_user() && !$visitor) {
994 if (is_array($_SESSION['remote'])) {
995 foreach ($_SESSION['remote'] as $v) {
996 if ($v['uid'] == $owner_uid) {
997 $contact_id = $v['cid'];
1003 $groups = Group::getIdsByContactId($contact_id);
1004 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1005 intval($contact_id),
1008 if (DBM::is_result($r)) {
1010 $remote_contact = true;
1015 if (!$remote_contact && local_user()) {
1016 $contact_id = $_SESSION['cid'];
1017 $contact = $a->contact;
1020 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
1021 notice(L10n::t('Access to this item is restricted.') . EOL);
1025 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
1030 $is_owner = (local_user() && (local_user() == $owner_uid));
1031 $o .= Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
1033 // Display upload form
1034 if ($datatype === 'upload') {
1036 notice(L10n::t('Permission denied.'));
1040 $selname = $datum ? hex2bin($datum) : '';
1044 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '> </option>';
1045 if (count($a->data['albums'])) {
1046 foreach ($a->data['albums'] as $album) {
1047 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos'))) {
1050 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1051 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1057 $ret = ['post_url' => 'photos/' . $a->data['user']['nickname'],
1058 'addon_text' => $uploader,
1059 'default_upload' => true];
1061 Addon::callHooks('photo_upload_form',$ret);
1063 $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), []);
1064 $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), [
1065 '$submit' => L10n::t('Submit'),
1068 $usage_message = '';
1070 $tpl = get_markup_template('photos_upload.tpl');
1072 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML($a->user));
1074 $o .= replace_macros($tpl,[
1075 '$pagename' => L10n::t('Upload Photos'),
1076 '$sessid' => session_id(),
1077 '$usage' => $usage_message,
1078 '$nickname' => $a->data['user']['nickname'],
1079 '$newalbum' => L10n::t('New album name: '),
1080 '$existalbumtext' => L10n::t('or existing album name: '),
1081 '$nosharetext' => L10n::t('Do not show a status post for this upload'),
1082 '$albumselect' => $albumselect,
1083 '$permissions' => L10n::t('Permissions'),
1084 '$aclselect' => $aclselect_e,
1085 '$alt_uploader' => $ret['addon_text'],
1086 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
1087 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
1088 '$uploadurl' => $ret['post_url'],
1090 // ACL permissions box
1091 '$group_perms' => L10n::t('Show to Groups'),
1092 '$contact_perms' => L10n::t('Show to Contacts'),
1093 '$return_path' => $a->query_string,
1099 // Display a single photo album
1100 if ($datatype === 'album') {
1101 $album = hex2bin($datum);
1103 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1104 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1108 if (DBM::is_result($r)) {
1109 $a->set_pager_total(count($r));
1110 $a->set_pager_itemspage(20);
1113 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1114 $order_field = defaults($_GET, 'order', '');
1115 if ($order_field === 'posted') {
1121 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1122 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1123 ANY_VALUE(`created`) as `created`
1124 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1125 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1128 intval($a->pager['start']),
1129 intval($a->pager['itemspage'])
1133 if ($cmd === 'edit') {
1134 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos'))) {
1136 $edit_tpl = get_markup_template('album_edit.tpl');
1140 $o .= replace_macros($edit_tpl,[
1141 '$nametext' => L10n::t('New album name: '),
1142 '$nickname' => $a->data['user']['nickname'],
1143 '$album' => $album_e,
1144 '$hexalbum' => bin2hex($album),
1145 '$submit' => L10n::t('Submit'),
1146 '$dropsubmit' => L10n::t('Delete Album')
1151 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos')) && $can_post) {
1152 $edit = [L10n::t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1156 if ($order_field === 'posted') {
1157 $order = [L10n::t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album)];
1159 $order = [L10n::t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted'];
1164 if (DBM::is_result($r)) {
1165 // "Twist" is only used for the duepunto theme with style "slackr"
1167 foreach ($r as $rr) {
1170 $ext = $phototypes[$rr['type']];
1172 $imgalt_e = $rr['filename'];
1173 $desc_e = $rr['desc'];
1177 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1178 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1179 . ($order_field === 'posted' ? '?f=&order=posted' : ''),
1180 'title' => L10n::t('View Photo'),
1181 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1185 'hash'=> $rr['resource-id'],
1190 $tpl = get_markup_template('photo_album.tpl');
1191 $o .= replace_macros($tpl, [
1192 '$photos' => $photos,
1194 '$can_post' => $can_post,
1195 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)],
1198 '$paginate' => paginate($a),
1205 // Display one photo
1206 if ($datatype === 'image') {
1207 // fetch image, item containing image, then comments
1208 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1209 $sql_extra ORDER BY `scale` ASC ",
1214 if (!DBM::is_result($ph)) {
1215 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1220 if (DBM::is_result($ph)) {
1221 notice(L10n::t('Permission denied. Access to this item may be restricted.'));
1223 notice(L10n::t('Photo not available') . EOL);
1232 * @todo This query is totally bad, the whole functionality has to be changed
1233 * The query leads to a really intense used index.
1234 * By now we hide it if someone wants to.
1236 if (!Config::get('system', 'no_count', false)) {
1237 $order_field = defaults($_GET, 'order', '');
1239 if ($order_field === 'posted') {
1245 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1246 $sql_extra ORDER BY `created` $order ",
1247 dbesc($ph[0]['album']),
1251 if (DBM::is_result($prvnxt)) {
1252 foreach ($prvnxt as $z => $entry) {
1253 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1257 $prv = count($prvnxt) - 1;
1259 if ($nxt >= count($prvnxt)) {
1265 $edit_suffix = ((($cmd === 'edit') && $can_post) ? '/edit' : '');
1266 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1267 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1271 if (count($ph) == 1) {
1272 $hires = $lores = $ph[0];
1275 if (count($ph) > 1) {
1276 if ($ph[1]['scale'] == 2) {
1277 // original is 640 or less, we can display it directly
1278 $hires = $lores = $ph[0];
1285 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1290 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1292 'edit' => ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? L10n::t('View photo') : L10n::t('Edit photo'))],
1293 'profile'=>['profile_photo/use/'.$ph[0]['resource-id'], L10n::t('Use as profile photo')],
1297 $lock = ((($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1298 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])))
1299 ? L10n::t('Private Message')
1305 if ($cmd === 'edit') {
1306 $tpl = get_markup_template('photo_edit_head.tpl');
1307 $a->page['htmlhead'] .= replace_macros($tpl,[
1308 '$prevlink' => $prevlink,
1309 '$nextlink' => $nextlink
1314 $prevlink = [$prevlink, '<div class="icon prev"></div>'] ;
1318 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1319 'title'=> L10n::t('View Full Size'),
1320 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . DateTimeFormat::utcNow('ymdhis'),
1321 'height' => $hires['height'],
1322 'width' => $hires['width'],
1323 'album' => $hires['album'],
1324 'filename' => $hires['filename'],
1328 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1332 // Do we have an item for this photo?
1334 // FIXME! - replace following code to display the conversation with our normal
1335 // conversation functions so that it works correctly and tracks changes
1336 // in the evolving conversation code.
1337 // The difference is that we won't be displaying the conversation head item
1338 // as a "post" but displaying instead the photo it is linked to
1340 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1341 $linked_items = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1348 if (DBM::is_result($linked_items)) {
1349 // This is a workaround to not being forced to rewrite the while $sql_extra handling
1350 $link_item = Item::selectFirst([], ['id' => $linked_items[0]['id']]);
1352 $condition = ["`parent` = ? AND `parent` != `id`", $link_item['parent']];
1353 $a->set_pager_total(dba::count('item', $condition));
1355 $params = ['order' => ['id'], 'limit' => [$a->pager['start'], $a->pager['itemspage']]];
1356 $result = Item::selectForUser($link_item['uid'], [], $condition, $params);
1357 $items = Item::inArray($result);
1359 if (local_user() && (local_user() == $link_item['uid'])) {
1360 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1363 if ($link_item['coord']) {
1364 $map = Map::byCoordinates($link_item['coord']);
1370 if (count($linked_items) && strlen($link_item['tag'])) {
1371 $arr = explode(',', $link_item['tag']);
1372 // parse tags and add links
1374 foreach ($arr as $t) {
1375 if (strlen($tag_str)) {
1378 $tag_str .= BBCode::convert($t);
1380 $tags = [L10n::t('Tags: '), $tag_str];
1381 if ($cmd === 'edit') {
1382 $tags[] = 'tagrm/' . $link_item['id'];
1383 $tags[] = L10n::t('[Remove any tag]');
1389 if ($cmd === 'edit' && $can_post) {
1390 $edit_tpl = get_markup_template('photo_edit.tpl');
1392 $album_e = $ph[0]['album'];
1393 $caption_e = $ph[0]['desc'];
1394 $aclselect_e = ACL::getFullSelectorHTML($ph[0]);
1396 $edit = replace_macros($edit_tpl, [
1397 '$id' => $ph[0]['id'],
1398 '$album' => ['albname', L10n::t('New album name'), $album_e,''],
1399 '$caption' => ['desc', L10n::t('Caption'), $caption_e, ''],
1400 '$tags' => ['newtag', L10n::t('Add a Tag'), "", L10n::t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1401 '$rotate_none' => ['rotate', L10n::t('Do not rotate'),0,'', true],
1402 '$rotate_cw' => ['rotate', L10n::t("Rotate CW \x28right\x29"),1,''],
1403 '$rotate_ccw' => ['rotate', L10n::t("Rotate CCW \x28left\x29"),2,''],
1405 '$nickname' => $a->data['user']['nickname'],
1406 '$resource_id' => $ph[0]['resource-id'],
1407 '$permissions' => L10n::t('Permissions'),
1408 '$aclselect' => $aclselect_e,
1410 '$item_id' => defaults($link_item, 'id', 0),
1411 '$submit' => L10n::t('Submit'),
1412 '$delete' => L10n::t('Delete Photo'),
1414 // ACL permissions box
1415 '$group_perms' => L10n::t('Show to Groups'),
1416 '$contact_perms' => L10n::t('Show to Contacts'),
1417 '$return_path' => $a->query_string,
1428 if (count($linked_items)) {
1429 $cmnt_tpl = get_markup_template('comment_item.tpl');
1430 $tpl = get_markup_template('photo_item.tpl');
1431 $return_url = $a->cmd;
1433 if ($can_post || can_write_wall($owner_uid)) {
1434 $like_tpl = get_markup_template('like_noshare.tpl');
1435 $likebuttons = replace_macros($like_tpl, [
1436 '$id' => $link_item['id'],
1437 '$likethis' => L10n::t("I like this \x28toggle\x29"),
1438 '$nolike' => (Feature::isEnabled(local_user(), 'dislike') ? L10n::t("I don't like this \x28toggle\x29") : ''),
1439 '$wait' => L10n::t('Please wait'),
1440 '$return_path' => $a->query_string,
1444 if (!DBM::is_result($items)) {
1445 if (($can_post || can_write_wall($owner_uid))) {
1446 $comments .= replace_macros($cmnt_tpl, [
1447 '$return_path' => '',
1448 '$jsreload' => $return_url,
1449 '$type' => 'wall-comment',
1450 '$id' => $link_item['id'],
1451 '$parent' => $link_item['id'],
1452 '$profile_uid' => $owner_uid,
1453 '$mylink' => $contact['url'],
1454 '$mytitle' => L10n::t('This is you'),
1455 '$myphoto' => $contact['thumb'],
1456 '$comment' => L10n::t('Comment'),
1457 '$submit' => L10n::t('Submit'),
1458 '$preview' => L10n::t('Preview'),
1459 '$sourceapp' => L10n::t($a->sourcename),
1461 '$rand_num' => random_digits(12)
1467 'like' => ['title' => L10n::t('Likes','title')],'dislike' => ['title' => L10n::t('Dislikes','title')],
1468 'attendyes' => ['title' => L10n::t('Attending','title')], 'attendno' => ['title' => L10n::t('Not attending','title')], 'attendmaybe' => ['title' => L10n::t('Might attend','title')]
1472 if (DBM::is_result($items)) {
1473 foreach ($items as $item) {
1474 builtin_activity_puller($item, $conv_responses);
1477 if (x($conv_responses['like'], $link_item['uri'])) {
1478 $like = format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like', $link_item['id']);
1480 if (x($conv_responses['dislike'], $link_item['uri'])) {
1481 $dislike = format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike', $link_item['id']);
1484 if (($can_post || can_write_wall($owner_uid))) {
1485 $comments .= replace_macros($cmnt_tpl,[
1486 '$return_path' => '',
1487 '$jsreload' => $return_url,
1488 '$type' => 'wall-comment',
1489 '$id' => $link_item['id'],
1490 '$parent' => $link_item['id'],
1491 '$profile_uid' => $owner_uid,
1492 '$mylink' => $contact['url'],
1493 '$mytitle' => L10n::t('This is you'),
1494 '$myphoto' => $contact['thumb'],
1495 '$comment' => L10n::t('Comment'),
1496 '$submit' => L10n::t('Submit'),
1497 '$preview' => L10n::t('Preview'),
1498 '$sourceapp' => L10n::t($a->sourcename),
1500 '$rand_num' => random_digits(12)
1504 foreach ($items as $item) {
1509 if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) {
1513 $profile_url = Contact::MagicLinkById($item['author-id']);
1514 if (strpos($profile_url, 'redir/') === 0) {
1515 $sparkle = ' sparkle';
1520 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1522 'dropping' => $dropping,
1523 'pagedrop' => false,
1524 'select' => L10n::t('Select'),
1525 'delete' => L10n::t('Delete'),
1528 $title_e = $item['title'];
1529 $body_e = BBCode::convert($item['body']);
1531 $comments .= replace_macros($template,[
1532 '$id' => $item['item_id'],
1533 '$profile_url' => $profile_url,
1534 '$name' => $item['author-name'],
1535 '$thumb' => $item['author-avatar'],
1536 '$sparkle' => $sparkle,
1537 '$title' => $title_e,
1539 '$ago' => Temporal::getRelativeDate($item['created']),
1540 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1542 '$comment' => $comment
1545 if (($can_post || can_write_wall($owner_uid))) {
1546 $comments .= replace_macros($cmnt_tpl, [
1547 '$return_path' => '',
1548 '$jsreload' => $return_url,
1549 '$type' => 'wall-comment',
1550 '$id' => $item['item_id'],
1551 '$parent' => $item['parent'],
1552 '$profile_uid' => $owner_uid,
1553 '$mylink' => $contact['url'],
1554 '$mytitle' => L10n::t('This is you'),
1555 '$myphoto' => $contact['thumb'],
1556 '$comment' => L10n::t('Comment'),
1557 '$submit' => L10n::t('Submit'),
1558 '$preview' => L10n::t('Preview'),
1559 '$sourceapp' => L10n::t($a->sourcename),
1561 '$rand_num' => random_digits(12)
1566 $response_verbs = ['like'];
1567 if (Feature::isEnabled($owner_uid, 'dislike')) {
1568 $response_verbs[] = 'dislike';
1570 $responses = get_responses($conv_responses, $response_verbs, '', $link_item);
1572 $paginate = paginate($a);
1575 $photo_tpl = get_markup_template('photo_view.tpl');
1576 $o .= replace_macros($photo_tpl, [
1577 '$id' => $ph[0]['id'],
1578 '$album' => [$album_link, $ph[0]['album']],
1582 '$prevlink' => $prevlink,
1583 '$nextlink' => $nextlink,
1584 '$desc' => $ph[0]['desc'],
1588 '$map_text' => L10n::t('Map'),
1589 '$likebuttons' => $likebuttons,
1591 '$dislike' => $dislike,
1592 'responses' => $responses,
1593 '$comments' => $comments,
1594 '$paginate' => $paginate,
1597 $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="photo" />' . "\n";
1598 $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1599 $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . $photo["href"] . '" />' . "\n";
1600 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1601 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1606 // Default - show recent photos with upload link (if applicable)
1609 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1610 $sql_extra GROUP BY `resource-id`",
1611 intval($a->data['user']['uid']),
1612 dbesc('Contact Photos'),
1613 dbesc(L10n::t('Contact Photos'))
1615 if (DBM::is_result($r)) {
1616 $a->set_pager_total(count($r));
1617 $a->set_pager_itemspage(20);
1620 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1621 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1622 ANY_VALUE(`created`) AS `created` FROM `photo`
1623 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1624 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1625 intval($a->data['user']['uid']),
1626 dbesc('Contact Photos'),
1627 dbesc(L10n::t('Contact Photos')),
1628 intval($a->pager['start']),
1629 intval($a->pager['itemspage'])
1633 if (DBM::is_result($r)) {
1634 // "Twist" is only used for the duepunto theme with style "slackr"
1636 foreach ($r as $rr) {
1637 //hide profile photos to others
1638 if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos'))) {
1644 $ext = $phototypes[$rr['type']];
1646 $alt_e = $rr['filename'];
1647 $name_e = $rr['album'];
1651 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1652 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1653 'title' => L10n::t('View Photo'),
1654 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1657 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1659 'alt' => L10n::t('View Album'),
1666 $tpl = get_markup_template('photos_recent.tpl');
1667 $o .= replace_macros($tpl, [
1668 '$title' => L10n::t('Recent Photos'),
1669 '$can_post' => $can_post,
1670 '$upload' => [L10n::t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'],
1671 '$photos' => $photos,
1672 '$paginate' => paginate($a),