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()) {
106 if ($ret['success']) {
107 $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'), [
108 '$nick' => $a->data['user']['nickname'],
109 '$title' => L10n::t('Photo Albums'),
110 '$recent' => L10n::t('Recent Photos'),
111 '$albums' => $ret['albums'],
112 '$baseurl' => System::baseUrl(),
113 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'],
114 '$can_post' => $can_post
119 if (!x($a->page, 'aside')) {
120 $a->page['aside'] = '';
122 $a->page['aside'] .= $vcard_widget;
123 $a->page['aside'] .= $photo_albums_widget;
125 $tpl = get_markup_template("photos_head.tpl");
126 $a->page['htmlhead'] .= replace_macros($tpl,[
127 '$ispublic' => L10n::t('everybody')
134 function photos_post(App $a)
136 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
137 logger('mod_photos: REQUEST ' . print_r($_REQUEST, true), LOGGER_DATA);
138 logger('mod_photos: FILES ' . print_r($_FILES, true), LOGGER_DATA);
140 $phototypes = Image::supportedTypes();
145 $page_owner_uid = $a->data['user']['uid'];
146 $community_page = $a->data['user']['page-flags'] == PAGE_COMMUNITY;
148 if (local_user() && (local_user() == $page_owner_uid)) {
151 if ($community_page && remote_user()) {
153 if (x($_SESSION, 'remote') && is_array($_SESSION['remote'])) {
154 foreach ($_SESSION['remote'] as $v) {
155 if ($v['uid'] == $page_owner_uid) {
156 $contact_id = $v['cid'];
162 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
164 intval($page_owner_uid)
166 if (DBM::is_result($r)) {
168 $visitor = $contact_id;
175 notice(L10n::t('Permission denied.') . EOL);
179 $owner_record = User::getOwnerDataById($page_owner_uid);
181 if (!$owner_record) {
182 notice(L10n::t('Contact information unavailable') . EOL);
183 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
187 if ($a->argc > 3 && $a->argv[2] === 'album') {
188 $album = hex2bin($a->argv[3]);
190 if ($album === L10n::t('Profile Photos') || $album === 'Contact Photos' || $album === L10n::t('Contact Photos')) {
191 goaway($_SESSION['photo_return']);
192 return; // NOTREACHED
195 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
197 intval($page_owner_uid)
199 if (!DBM::is_result($r)) {
200 notice(L10n::t('Album not found.') . EOL);
201 goaway($_SESSION['photo_return']);
202 return; // NOTREACHED
205 // Check if the user has responded to a delete confirmation query
206 if ($_REQUEST['canceled']) {
207 goaway($_SESSION['photo_return']);
210 // RENAME photo album
211 $newalbum = notags(trim($_POST['albumname']));
212 if ($newalbum != $album) {
213 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
216 intval($page_owner_uid)
218 // Update the photo albums cache
219 Photo::clearAlbumCache($page_owner_uid);
221 $newurl = str_replace(bin2hex($album), bin2hex($newalbum), $_SESSION['photo_return']);
223 return; // NOTREACHED
227 * DELETE photo album and all its photos
230 if ($_POST['dropalbum'] == L10n::t('Delete Album')) {
231 // Check if we should do HTML-based delete confirmation
232 if (x($_REQUEST, 'confirm')) {
233 $drop_url = $a->query_string;
235 ['name' => 'albumname', 'value' => $_POST['albumname']],
237 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
239 '$message' => L10n::t('Do you really want to delete this photo album and all its photos?'),
240 '$extra_inputs' => $extra_inputs,
241 '$confirm' => L10n::t('Delete Album'),
242 '$confirm_url' => $drop_url,
243 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
244 '$cancel' => L10n::t('Cancel'),
246 $a->error = 1; // Set $a->error so the other module functions don't execute
252 // get the list of photos we are about to delete
255 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
257 intval($page_owner_uid),
261 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
262 intval(local_user()),
266 if (DBM::is_result($r)) {
267 foreach ($r as $rr) {
268 $res[] = "'" . dbesc($rr['rid']) . "'" ;
271 goaway($_SESSION['photo_return']);
272 return; // NOTREACHED
275 $str_res = implode(',', $res);
277 // remove the associated photos
278 q("DELETE FROM `photo` WHERE `resource-id` IN ($str_res) AND `uid` = %d",
279 intval($page_owner_uid)
282 // find and delete the corresponding item with all the comments and likes/dislikes
283 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
285 // Update the photo albums cache
286 Photo::clearAlbumCache($page_owner_uid);
289 goaway('photos/' . $a->data['user']['nickname']);
290 return; // NOTREACHED
294 // Check if the user has responded to a delete confirmation query for a single photo
295 if ($a->argc > 2 && x($_REQUEST, 'canceled')) {
296 goaway($_SESSION['photo_return']);
299 if ($a->argc > 2 && defaults($_POST, 'delete', '') === L10n::t('Delete Photo')) {
301 // same as above but remove single photo
303 // Check if we should do HTML-based delete confirmation
304 if (x($_REQUEST, 'confirm')) {
305 $drop_url = $a->query_string;
306 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
308 '$message' => L10n::t('Do you really want to delete this photo?'),
309 '$extra_inputs' => [],
310 '$confirm' => L10n::t('Delete Photo'),
311 '$confirm_url' => $drop_url,
312 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
313 '$cancel' => L10n::t('Cancel'),
315 $a->error = 1; // Set $a->error so the other module functions don't execute
320 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
322 intval($page_owner_uid),
326 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
327 intval(local_user()),
331 if (DBM::is_result($r)) {
332 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
333 intval($page_owner_uid),
334 dbesc($r[0]['resource-id'])
337 Item::deleteForUser(['resource-id' => $r[0]['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
339 // Update the photo albums cache
340 Photo::clearAlbumCache($page_owner_uid);
343 goaway('photos/' . $a->data['user']['nickname']);
344 return; // NOTREACHED
347 if ($a->argc > 2 && (x($_POST, 'desc') !== false || x($_POST, 'newtag') !== false || x($_POST, 'albname') !== false)) {
348 $desc = x($_POST, 'desc') ? notags(trim($_POST['desc'])) : '';
349 $rawtags = x($_POST, 'newtag') ? notags(trim($_POST['newtag'])) : '';
350 $item_id = x($_POST, 'item_id') ? intval($_POST['item_id']) : 0;
351 $albname = x($_POST, 'albname') ? notags(trim($_POST['albname'])) : '';
352 $origaname = x($_POST, 'origaname') ? notags(trim($_POST['origaname'])) : '';
353 $str_group_allow = perms2str($_POST['group_allow']);
354 $str_contact_allow = perms2str($_POST['contact_allow']);
355 $str_group_deny = perms2str($_POST['group_deny']);
356 $str_contact_deny = perms2str($_POST['contact_deny']);
358 $resource_id = $a->argv[2];
360 if (!strlen($albname)) {
361 $albname = DateTimeFormat::localNow('Y');
364 if (x($_POST,'rotate') !== false &&
365 (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
368 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0 LIMIT 1",
370 intval($page_owner_uid)
372 if (DBM::is_result($r)) {
373 $Image = new Image($r[0]['data'], $r[0]['type']);
374 if ($Image->isValid()) {
375 $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
376 $Image->rotate($rotate_deg);
378 $width = $Image->getWidth();
379 $height = $Image->getHeight();
381 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0",
382 dbesc($Image->asString()),
386 intval($page_owner_uid)
389 if ($width > 640 || $height > 640) {
390 $Image->scaleDown(640);
391 $width = $Image->getWidth();
392 $height = $Image->getHeight();
394 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 1",
395 dbesc($Image->asString()),
399 intval($page_owner_uid)
403 if ($width > 320 || $height > 320) {
404 $Image->scaleDown(320);
405 $width = $Image->getWidth();
406 $height = $Image->getHeight();
408 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 2",
409 dbesc($Image->asString()),
413 intval($page_owner_uid)
420 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
422 intval($page_owner_uid)
424 if (DBM::is_result($p)) {
425 $ext = $phototypes[$p[0]['type']];
426 $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",
429 dbesc($str_contact_allow),
430 dbesc($str_group_allow),
431 dbesc($str_contact_deny),
432 dbesc($str_group_deny),
434 intval($page_owner_uid)
437 // Update the photo albums cache if album name was changed
438 if ($albname !== $origaname) {
439 Photo::clearAlbumCache($page_owner_uid);
443 /* Don't make the item visible if the only change was the album name */
446 if ($p[0]['desc'] !== $desc || strlen($rawtags)) {
451 // Create item container
453 $uri = Item::newURI($page_owner_uid);
456 $arr['guid'] = get_guid(32);
457 $arr['uid'] = $page_owner_uid;
459 $arr['parent-uri'] = $uri;
460 $arr['type'] = 'photo';
462 $arr['resource-id'] = $p[0]['resource-id'];
463 $arr['contact-id'] = $owner_record['id'];
464 $arr['owner-name'] = $owner_record['name'];
465 $arr['owner-link'] = $owner_record['url'];
466 $arr['owner-avatar'] = $owner_record['thumb'];
467 $arr['author-name'] = $owner_record['name'];
468 $arr['author-link'] = $owner_record['url'];
469 $arr['author-avatar'] = $owner_record['thumb'];
470 $arr['title'] = $title;
471 $arr['allow_cid'] = $p[0]['allow_cid'];
472 $arr['allow_gid'] = $p[0]['allow_gid'];
473 $arr['deny_cid'] = $p[0]['deny_cid'];
474 $arr['deny_gid'] = $p[0]['deny_gid'];
475 $arr['visible'] = $visibility;
478 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
479 . '[img]' . System::baseUrl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
482 $item_id = Item::insert($arr);
486 $item = Item::selectFirst(['tag', 'inform'], ['id' => $item_id, 'uid' => $page_owner_uid]);
488 if (DBM::is_result($item)) {
489 $old_tag = $item['tag'];
490 $old_inform = $item['inform'];
493 if (strlen($rawtags)) {
497 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
498 $x = substr($rawtags, 0, 1);
499 if ($x !== '@' && $x !== '#') {
500 $rawtags = '#' . $rawtags;
504 $tags = get_tags($rawtags);
507 foreach ($tags as $tag) {
508 if (strpos($tag, '@') === 0) {
510 $name = substr($tag,1);
511 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
513 $links = @Probe::lrdd($name);
515 foreach ($links as $link) {
516 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
517 $profile = $link['@attributes']['href'];
519 if ($link['@attributes']['rel'] === 'salmon') {
520 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
521 if (strlen($inform)) {
528 $taginfo[] = [$newname, $profile, $salmon];
533 if (strrpos($newname, '+')) {
534 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
538 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
543 $newname = str_replace('_',' ',$name);
545 //select someone from this user's contacts by name
546 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
548 intval($page_owner_uid)
551 if (!DBM::is_result($r)) {
552 //select someone by attag or nick and the name passed in
553 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
556 intval($page_owner_uid)
561 if (DBM::is_result($r)) {
562 $newname = $r[0]['name'];
563 $profile = $r[0]['url'];
564 $notify = 'cid:' . $r[0]['id'];
565 if (strlen($inform)) {
572 if (substr($notify, 0, 4) === 'cid:') {
573 $taginfo[] = [$newname, $profile, $notify, $r[0], '@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]'];
575 $taginfo[] = [$newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'];
577 if (strlen($str_tags)) {
580 $profile = str_replace(',', '%2c', $profile);
581 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
583 } elseif (strpos($tag, '#') === 0) {
584 $tagname = substr($tag, 1);
585 $str_tags .= '#[url=' . System::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url]';
591 if (strlen($newtag) && strlen($str_tags)) {
594 $newtag .= $str_tags;
596 $newinform = $old_inform;
597 if (strlen($newinform) && strlen($inform)) {
600 $newinform .= $inform;
602 $fields = ['tag' => $newtag, 'inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
603 $condition = ['id' => $item_id];
604 Item::update($fields, $condition);
607 foreach ($p as $scales) {
608 if (intval($scales['scale']) == 2) {
612 if (intval($scales['scale']) == 4) {
618 if (count($taginfo)) {
619 foreach ($taginfo as $tagged) {
620 $uri = Item::newURI($page_owner_uid);
623 $arr['guid'] = get_guid(32);
624 $arr['uid'] = $page_owner_uid;
626 $arr['parent-uri'] = $uri;
627 $arr['type'] = 'activity';
629 $arr['contact-id'] = $owner_record['id'];
630 $arr['owner-name'] = $owner_record['name'];
631 $arr['owner-link'] = $owner_record['url'];
632 $arr['owner-avatar'] = $owner_record['thumb'];
633 $arr['author-name'] = $owner_record['name'];
634 $arr['author-link'] = $owner_record['url'];
635 $arr['author-avatar'] = $owner_record['thumb'];
637 $arr['allow_cid'] = $p[0]['allow_cid'];
638 $arr['allow_gid'] = $p[0]['allow_gid'];
639 $arr['deny_cid'] = $p[0]['deny_cid'];
640 $arr['deny_gid'] = $p[0]['deny_gid'];
642 $arr['verb'] = ACTIVITY_TAG;
643 $arr['gravity'] = GRAVITY_PARENT;
644 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
645 $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
646 $arr['tag'] = $tagged[4];
647 $arr['inform'] = $tagged[2];
649 $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]') ;
650 $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" ;
652 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
653 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
655 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
657 $arr['object'] .= '</link></object>' . "\n";
659 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $p[0]['desc'] . '</title><id>'
660 . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
661 $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>';
663 $item_id = Item::insert($arr);
665 Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
670 goaway($_SESSION['photo_return']);
671 return; // NOTREACHED
675 // default post action - upload a photo
676 Addon::callHooks('photo_post_init', $_POST);
678 // Determine the album to use
679 $album = x($_REQUEST, 'album') ? notags(trim($_REQUEST['album'])) : '';
680 $newalbum = x($_REQUEST, 'newalbum') ? notags(trim($_REQUEST['newalbum'])) : '';
682 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
684 if (!strlen($album)) {
685 if (strlen($newalbum)) {
688 $album = DateTimeFormat::localNow('Y');
693 * We create a wall item for every photo, but we don't want to
694 * overwhelm the data stream with a hundred newly uploaded photos.
695 * So we will make the first photo uploaded to this album in the last several hours
696 * visible by default, the rest will become visible over time when and if
697 * they acquire comments, likes, dislikes, and/or tags
700 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
702 intval($page_owner_uid)
704 if (!DBM::is_result($r) || ($album == L10n::t('Profile Photos'))) {
710 if (x($_REQUEST, 'not_visible') && $_REQUEST['not_visible'] !== 'false') {
714 $group_allow = defaults($_REQUEST, 'group_allow' , []);
715 $contact_allow = defaults($_REQUEST, 'contact_allow', []);
716 $group_deny = defaults($_REQUEST, 'group_deny' , []);
717 $contact_deny = defaults($_REQUEST, 'contact_deny' , []);
719 $str_group_allow = perms2str(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
720 $str_contact_allow = perms2str(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
721 $str_group_deny = perms2str(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
722 $str_contact_deny = perms2str(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
724 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
726 Addon::callHooks('photo_post_file', $ret);
728 if (x($ret, 'src') && x($ret, 'filesize')) {
730 $filename = $ret['filename'];
731 $filesize = $ret['filesize'];
732 $type = $ret['type'];
733 $error = UPLOAD_ERR_OK;
735 $src = $_FILES['userfile']['tmp_name'];
736 $filename = basename($_FILES['userfile']['name']);
737 $filesize = intval($_FILES['userfile']['size']);
738 $type = $_FILES['userfile']['type'];
739 $error = $_FILES['userfile']['error'];
742 if ($error !== UPLOAD_ERR_OK) {
744 case UPLOAD_ERR_INI_SIZE:
745 notice(L10n::t('Image exceeds size limit of %s', ini_get('upload_max_filesize')) . EOL);
747 case UPLOAD_ERR_FORM_SIZE:
748 notice(L10n::t('Image exceeds size limit of %s', formatBytes(defaults($_REQUEST, 'MAX_FILE_SIZE', 0))) . EOL);
750 case UPLOAD_ERR_PARTIAL:
751 notice(L10n::t('Image upload didn\'t complete, please try again') . EOL);
753 case UPLOAD_ERR_NO_FILE:
754 notice(L10n::t('Image file is missing') . EOL);
756 case UPLOAD_ERR_NO_TMP_DIR:
757 case UPLOAD_ERR_CANT_WRITE:
758 case UPLOAD_ERR_EXTENSION:
759 notice(L10n::t('Server can\'t accept new file upload at this time, please contact your administrator') . EOL);
764 Addon::callHooks('photo_post_end', $foo);
769 $type = Image::guessType($filename);
772 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
774 $maximagesize = Config::get('system', 'maximagesize');
776 if ($maximagesize && ($filesize > $maximagesize)) {
777 notice(L10n::t('Image exceeds size limit of %s', formatBytes($maximagesize)) . EOL);
780 Addon::callHooks('photo_post_end', $foo);
785 notice(L10n::t('Image file is empty.') . EOL);
788 Addon::callHooks('photo_post_end', $foo);
792 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
794 $imagedata = @file_get_contents($src);
796 $Image = new Image($imagedata, $type);
798 if (!$Image->isValid()) {
799 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
800 notice(L10n::t('Unable to process image.') . EOL);
803 Addon::callHooks('photo_post_end',$foo);
807 $exif = $Image->orient($src);
810 $max_length = Config::get('system', 'max_image_length');
812 $max_length = MAX_IMAGE_LENGTH;
814 if ($max_length > 0) {
815 $Image->scaleDown($max_length);
818 $width = $Image->getWidth();
819 $height = $Image->getHeight();
823 $photo_hash = Photo::newResource();
825 $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);
828 logger('mod/photos.php: photos_post(): image store failed', LOGGER_DEBUG);
829 notice(L10n::t('Image upload failed.') . EOL);
833 if ($width > 640 || $height > 640) {
834 $Image->scaleDown(640);
835 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);
839 if ($width > 320 || $height > 320) {
840 $Image->scaleDown(320);
841 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);
845 $uri = Item::newURI($page_owner_uid);
847 // Create item container
849 if ($exif && $exif['GPS'] && Feature::isEnabled($page_owner_uid, 'photo_location')) {
850 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
851 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
856 $arr['coord'] = $lat . ' ' . $lon;
859 $arr['guid'] = get_guid(32);
860 $arr['uid'] = $page_owner_uid;
862 $arr['parent-uri'] = $uri;
863 $arr['type'] = 'photo';
865 $arr['resource-id'] = $photo_hash;
866 $arr['contact-id'] = $owner_record['id'];
867 $arr['owner-name'] = $owner_record['name'];
868 $arr['owner-link'] = $owner_record['url'];
869 $arr['owner-avatar'] = $owner_record['thumb'];
870 $arr['author-name'] = $owner_record['name'];
871 $arr['author-link'] = $owner_record['url'];
872 $arr['author-avatar'] = $owner_record['thumb'];
874 $arr['allow_cid'] = $str_contact_allow;
875 $arr['allow_gid'] = $str_group_allow;
876 $arr['deny_cid'] = $str_contact_deny;
877 $arr['deny_gid'] = $str_group_deny;
878 $arr['visible'] = $visible;
881 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
882 . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$Image->getExt() . '[/img]'
885 $item_id = Item::insert($arr);
886 // Update the photo albums cache
887 Photo::clearAlbumCache($page_owner_uid);
890 Worker::add(PRIORITY_HIGH, "Notifier", 'wall-new', $item_id);
893 Addon::callHooks('photo_post_end', intval($item_id));
895 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
896 // if they do not wish to be redirected
898 goaway($_SESSION['photo_return']);
902 function photos_content(App $a)
906 // photos/name/upload
907 // photos/name/upload/xxxxx (xxxxx is album name)
908 // photos/name/album/xxxxx
909 // photos/name/album/xxxxx/edit
910 // photos/name/image/xxxxx
911 // photos/name/image/xxxxx/edit
913 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
914 notice(L10n::t('Public access denied.') . EOL);
918 require_once 'include/security.php';
919 require_once 'include/conversation.php';
921 if (!x($a->data,'user')) {
922 notice(L10n::t('No photos selected') . EOL);
926 $phototypes = Image::supportedTypes();
928 $_SESSION['photo_return'] = $a->cmd;
933 $datatype = $a->argv[2];
934 $datum = $a->argv[3];
935 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
936 $datatype = 'upload';
938 $datatype = 'summary';
947 // Setup permissions structures
951 $remote_contact = false;
954 $owner_uid = $a->data['user']['uid'];
956 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
958 if (local_user() && (local_user() == $owner_uid)) {
961 if ($community_page && remote_user()) {
962 if (is_array($_SESSION['remote'])) {
963 foreach ($_SESSION['remote'] as $v) {
964 if ($v['uid'] == $owner_uid) {
965 $contact_id = $v['cid'];
972 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
976 if (DBM::is_result($r)) {
979 $remote_contact = true;
980 $visitor = $contact_id;
988 // perhaps they're visiting - but not a community page, so they wouldn't have write access
989 if (remote_user() && !$visitor) {
991 if (is_array($_SESSION['remote'])) {
992 foreach ($_SESSION['remote'] as $v) {
993 if ($v['uid'] == $owner_uid) {
994 $contact_id = $v['cid'];
1000 $groups = Group::getIdsByContactId($contact_id);
1001 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1002 intval($contact_id),
1005 if (DBM::is_result($r)) {
1007 $remote_contact = true;
1012 if (!$remote_contact && local_user()) {
1013 $contact_id = $_SESSION['cid'];
1014 $contact = $a->contact;
1017 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
1018 notice(L10n::t('Access to this item is restricted.') . EOL);
1022 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
1027 $is_owner = (local_user() && (local_user() == $owner_uid));
1028 $o .= Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
1030 // Display upload form
1031 if ($datatype === 'upload') {
1033 notice(L10n::t('Permission denied.'));
1037 $selname = $datum ? hex2bin($datum) : '';
1041 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '> </option>';
1042 if (count($a->data['albums'])) {
1043 foreach ($a->data['albums'] as $album) {
1044 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos'))) {
1047 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1048 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1054 $ret = ['post_url' => 'photos/' . $a->data['user']['nickname'],
1055 'addon_text' => $uploader,
1056 'default_upload' => true];
1058 Addon::callHooks('photo_upload_form',$ret);
1060 $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), []);
1061 $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), [
1062 '$submit' => L10n::t('Submit'),
1065 $usage_message = '';
1067 $tpl = get_markup_template('photos_upload.tpl');
1069 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML($a->user));
1071 $o .= replace_macros($tpl,[
1072 '$pagename' => L10n::t('Upload Photos'),
1073 '$sessid' => session_id(),
1074 '$usage' => $usage_message,
1075 '$nickname' => $a->data['user']['nickname'],
1076 '$newalbum' => L10n::t('New album name: '),
1077 '$existalbumtext' => L10n::t('or existing album name: '),
1078 '$nosharetext' => L10n::t('Do not show a status post for this upload'),
1079 '$albumselect' => $albumselect,
1080 '$permissions' => L10n::t('Permissions'),
1081 '$aclselect' => $aclselect_e,
1082 '$alt_uploader' => $ret['addon_text'],
1083 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
1084 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
1085 '$uploadurl' => $ret['post_url'],
1087 // ACL permissions box
1088 '$group_perms' => L10n::t('Show to Groups'),
1089 '$contact_perms' => L10n::t('Show to Contacts'),
1090 '$return_path' => $a->query_string,
1096 // Display a single photo album
1097 if ($datatype === 'album') {
1098 $album = hex2bin($datum);
1100 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1101 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1105 if (DBM::is_result($r)) {
1106 $a->set_pager_total(count($r));
1107 $a->set_pager_itemspage(20);
1110 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1111 $order_field = defaults($_GET, 'order', '');
1112 if ($order_field === 'posted') {
1118 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1119 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1120 ANY_VALUE(`created`) as `created`
1121 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1122 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1125 intval($a->pager['start']),
1126 intval($a->pager['itemspage'])
1130 if ($cmd === 'edit') {
1131 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos'))) {
1133 $edit_tpl = get_markup_template('album_edit.tpl');
1137 $o .= replace_macros($edit_tpl,[
1138 '$nametext' => L10n::t('New album name: '),
1139 '$nickname' => $a->data['user']['nickname'],
1140 '$album' => $album_e,
1141 '$hexalbum' => bin2hex($album),
1142 '$submit' => L10n::t('Submit'),
1143 '$dropsubmit' => L10n::t('Delete Album')
1148 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos')) && $can_post) {
1149 $edit = [L10n::t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1153 if ($order_field === 'posted') {
1154 $order = [L10n::t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album)];
1156 $order = [L10n::t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted'];
1161 if (DBM::is_result($r)) {
1162 // "Twist" is only used for the duepunto theme with style "slackr"
1164 foreach ($r as $rr) {
1167 $ext = $phototypes[$rr['type']];
1169 $imgalt_e = $rr['filename'];
1170 $desc_e = $rr['desc'];
1174 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1175 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1176 . ($order_field === 'posted' ? '?f=&order=posted' : ''),
1177 'title' => L10n::t('View Photo'),
1178 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1182 'hash'=> $rr['resource-id'],
1187 $tpl = get_markup_template('photo_album.tpl');
1188 $o .= replace_macros($tpl, [
1189 '$photos' => $photos,
1191 '$can_post' => $can_post,
1192 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)],
1195 '$paginate' => paginate($a),
1202 // Display one photo
1203 if ($datatype === 'image') {
1204 // fetch image, item containing image, then comments
1205 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1206 $sql_extra ORDER BY `scale` ASC ",
1211 if (!DBM::is_result($ph)) {
1212 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1217 if (DBM::is_result($ph)) {
1218 notice(L10n::t('Permission denied. Access to this item may be restricted.'));
1220 notice(L10n::t('Photo not available') . EOL);
1229 * @todo This query is totally bad, the whole functionality has to be changed
1230 * The query leads to a really intense used index.
1231 * By now we hide it if someone wants to.
1233 if (!Config::get('system', 'no_count', false)) {
1234 $order_field = defaults($_GET, 'order', '');
1236 if ($order_field === 'posted') {
1242 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1243 $sql_extra ORDER BY `created` $order ",
1244 dbesc($ph[0]['album']),
1248 if (DBM::is_result($prvnxt)) {
1249 foreach ($prvnxt as $z => $entry) {
1250 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1254 $prv = count($prvnxt) - 1;
1256 if ($nxt >= count($prvnxt)) {
1262 $edit_suffix = ((($cmd === 'edit') && $can_post) ? '/edit' : '');
1263 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1264 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1268 if (count($ph) == 1) {
1269 $hires = $lores = $ph[0];
1272 if (count($ph) > 1) {
1273 if ($ph[1]['scale'] == 2) {
1274 // original is 640 or less, we can display it directly
1275 $hires = $lores = $ph[0];
1282 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1287 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1289 'edit' => ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? L10n::t('View photo') : L10n::t('Edit photo'))],
1290 'profile'=>['profile_photo/use/'.$ph[0]['resource-id'], L10n::t('Use as profile photo')],
1294 $lock = ((($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1295 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])))
1296 ? L10n::t('Private Message')
1302 if ($cmd === 'edit') {
1303 $tpl = get_markup_template('photo_edit_head.tpl');
1304 $a->page['htmlhead'] .= replace_macros($tpl,[
1305 '$prevlink' => $prevlink,
1306 '$nextlink' => $nextlink
1311 $prevlink = [$prevlink, '<div class="icon prev"></div>'] ;
1315 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1316 'title'=> L10n::t('View Full Size'),
1317 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . DateTimeFormat::utcNow('ymdhis'),
1318 'height' => $hires['height'],
1319 'width' => $hires['width'],
1320 'album' => $hires['album'],
1321 'filename' => $hires['filename'],
1325 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1329 // Do we have an item for this photo?
1331 // FIXME! - replace following code to display the conversation with our normal
1332 // conversation functions so that it works correctly and tracks changes
1333 // in the evolving conversation code.
1334 // The difference is that we won't be displaying the conversation head item
1335 // as a "post" but displaying instead the photo it is linked to
1337 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1338 $linked_items = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1345 if (DBM::is_result($linked_items)) {
1346 // This is a workaround to not being forced to rewrite the while $sql_extra handling
1347 $link_item = Item::selectFirst([], ['id' => $linked_items[0]['id']]);
1349 $condition = ["`parent` = ? AND `parent` != `id`", $link_item['parent']];
1350 $a->set_pager_total(dba::count('item', $condition));
1352 $params = ['order' => ['id'], 'limit' => [$a->pager['start'], $a->pager['itemspage']]];
1353 $result = Item::selectForUser($link_item['uid'], [], $condition, $params);
1354 $items = Item::inArray($result);
1356 if (local_user() && (local_user() == $link_item['uid'])) {
1357 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1360 if ($link_item['coord']) {
1361 $map = Map::byCoordinates($link_item['coord']);
1367 if (count($linked_items) && strlen($link_item['tag'])) {
1368 $arr = explode(',', $link_item['tag']);
1369 // parse tags and add links
1371 foreach ($arr as $t) {
1372 if (strlen($tag_str)) {
1375 $tag_str .= BBCode::convert($t);
1377 $tags = [L10n::t('Tags: '), $tag_str];
1378 if ($cmd === 'edit') {
1379 $tags[] = 'tagrm/' . $link_item['id'];
1380 $tags[] = L10n::t('[Remove any tag]');
1386 if ($cmd === 'edit' && $can_post) {
1387 $edit_tpl = get_markup_template('photo_edit.tpl');
1389 $album_e = $ph[0]['album'];
1390 $caption_e = $ph[0]['desc'];
1391 $aclselect_e = ACL::getFullSelectorHTML($ph[0]);
1393 $edit = replace_macros($edit_tpl, [
1394 '$id' => $ph[0]['id'],
1395 '$album' => ['albname', L10n::t('New album name'), $album_e,''],
1396 '$caption' => ['desc', L10n::t('Caption'), $caption_e, ''],
1397 '$tags' => ['newtag', L10n::t('Add a Tag'), "", L10n::t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1398 '$rotate_none' => ['rotate', L10n::t('Do not rotate'),0,'', true],
1399 '$rotate_cw' => ['rotate', L10n::t("Rotate CW \x28right\x29"),1,''],
1400 '$rotate_ccw' => ['rotate', L10n::t("Rotate CCW \x28left\x29"),2,''],
1402 '$nickname' => $a->data['user']['nickname'],
1403 '$resource_id' => $ph[0]['resource-id'],
1404 '$permissions' => L10n::t('Permissions'),
1405 '$aclselect' => $aclselect_e,
1407 '$item_id' => defaults($link_item, 'id', 0),
1408 '$submit' => L10n::t('Submit'),
1409 '$delete' => L10n::t('Delete Photo'),
1411 // ACL permissions box
1412 '$group_perms' => L10n::t('Show to Groups'),
1413 '$contact_perms' => L10n::t('Show to Contacts'),
1414 '$return_path' => $a->query_string,
1425 if (count($linked_items)) {
1426 $cmnt_tpl = get_markup_template('comment_item.tpl');
1427 $tpl = get_markup_template('photo_item.tpl');
1428 $return_url = $a->cmd;
1430 if ($can_post || can_write_wall($owner_uid)) {
1431 $like_tpl = get_markup_template('like_noshare.tpl');
1432 $likebuttons = replace_macros($like_tpl, [
1433 '$id' => $link_item['id'],
1434 '$likethis' => L10n::t("I like this \x28toggle\x29"),
1435 '$nolike' => (Feature::isEnabled(local_user(), 'dislike') ? L10n::t("I don't like this \x28toggle\x29") : ''),
1436 '$wait' => L10n::t('Please wait'),
1437 '$return_path' => $a->query_string,
1441 if (!DBM::is_result($items)) {
1442 if (($can_post || can_write_wall($owner_uid))) {
1443 $comments .= replace_macros($cmnt_tpl, [
1444 '$return_path' => '',
1445 '$jsreload' => $return_url,
1446 '$type' => 'wall-comment',
1447 '$id' => $link_item['id'],
1448 '$parent' => $link_item['id'],
1449 '$profile_uid' => $owner_uid,
1450 '$mylink' => $contact['url'],
1451 '$mytitle' => L10n::t('This is you'),
1452 '$myphoto' => $contact['thumb'],
1453 '$comment' => L10n::t('Comment'),
1454 '$submit' => L10n::t('Submit'),
1455 '$preview' => L10n::t('Preview'),
1456 '$sourceapp' => L10n::t($a->sourcename),
1458 '$rand_num' => random_digits(12)
1464 'like' => ['title' => L10n::t('Likes','title')],'dislike' => ['title' => L10n::t('Dislikes','title')],
1465 'attendyes' => ['title' => L10n::t('Attending','title')], 'attendno' => ['title' => L10n::t('Not attending','title')], 'attendmaybe' => ['title' => L10n::t('Might attend','title')]
1469 if (DBM::is_result($items)) {
1470 foreach ($items as $item) {
1471 builtin_activity_puller($item, $conv_responses);
1474 if (x($conv_responses['like'], $link_item['uri'])) {
1475 $like = format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like', $link_item['id']);
1477 if (x($conv_responses['dislike'], $link_item['uri'])) {
1478 $dislike = format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike', $link_item['id']);
1481 if (($can_post || can_write_wall($owner_uid))) {
1482 $comments .= replace_macros($cmnt_tpl,[
1483 '$return_path' => '',
1484 '$jsreload' => $return_url,
1485 '$type' => 'wall-comment',
1486 '$id' => $link_item['id'],
1487 '$parent' => $link_item['id'],
1488 '$profile_uid' => $owner_uid,
1489 '$mylink' => $contact['url'],
1490 '$mytitle' => L10n::t('This is you'),
1491 '$myphoto' => $contact['thumb'],
1492 '$comment' => L10n::t('Comment'),
1493 '$submit' => L10n::t('Submit'),
1494 '$preview' => L10n::t('Preview'),
1495 '$sourceapp' => L10n::t($a->sourcename),
1497 '$rand_num' => random_digits(12)
1501 foreach ($items as $item) {
1506 if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) {
1510 $profile_url = Contact::MagicLinkById($item['author-id']);
1511 if (strpos($profile_url, 'redir/') === 0) {
1512 $sparkle = ' sparkle';
1517 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1519 'dropping' => $dropping,
1520 'pagedrop' => false,
1521 'select' => L10n::t('Select'),
1522 'delete' => L10n::t('Delete'),
1525 $title_e = $item['title'];
1526 $body_e = BBCode::convert($item['body']);
1528 $comments .= replace_macros($template,[
1529 '$id' => $item['item_id'],
1530 '$profile_url' => $profile_url,
1531 '$name' => $item['author-name'],
1532 '$thumb' => $item['author-avatar'],
1533 '$sparkle' => $sparkle,
1534 '$title' => $title_e,
1536 '$ago' => Temporal::getRelativeDate($item['created']),
1537 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1539 '$comment' => $comment
1542 if (($can_post || can_write_wall($owner_uid))) {
1543 $comments .= replace_macros($cmnt_tpl, [
1544 '$return_path' => '',
1545 '$jsreload' => $return_url,
1546 '$type' => 'wall-comment',
1547 '$id' => $item['item_id'],
1548 '$parent' => $item['parent'],
1549 '$profile_uid' => $owner_uid,
1550 '$mylink' => $contact['url'],
1551 '$mytitle' => L10n::t('This is you'),
1552 '$myphoto' => $contact['thumb'],
1553 '$comment' => L10n::t('Comment'),
1554 '$submit' => L10n::t('Submit'),
1555 '$preview' => L10n::t('Preview'),
1556 '$sourceapp' => L10n::t($a->sourcename),
1558 '$rand_num' => random_digits(12)
1563 $response_verbs = ['like'];
1564 if (Feature::isEnabled($owner_uid, 'dislike')) {
1565 $response_verbs[] = 'dislike';
1567 $responses = get_responses($conv_responses, $response_verbs, '', $link_item);
1569 $paginate = paginate($a);
1572 $photo_tpl = get_markup_template('photo_view.tpl');
1573 $o .= replace_macros($photo_tpl, [
1574 '$id' => $ph[0]['id'],
1575 '$album' => [$album_link, $ph[0]['album']],
1579 '$prevlink' => $prevlink,
1580 '$nextlink' => $nextlink,
1581 '$desc' => $ph[0]['desc'],
1585 '$map_text' => L10n::t('Map'),
1586 '$likebuttons' => $likebuttons,
1588 '$dislike' => $dislike,
1589 'responses' => $responses,
1590 '$comments' => $comments,
1591 '$paginate' => $paginate,
1594 $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="photo" />' . "\n";
1595 $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1596 $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . $photo["href"] . '" />' . "\n";
1597 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1598 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1603 // Default - show recent photos with upload link (if applicable)
1606 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1607 $sql_extra GROUP BY `resource-id`",
1608 intval($a->data['user']['uid']),
1609 dbesc('Contact Photos'),
1610 dbesc(L10n::t('Contact Photos'))
1612 if (DBM::is_result($r)) {
1613 $a->set_pager_total(count($r));
1614 $a->set_pager_itemspage(20);
1617 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1618 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1619 ANY_VALUE(`created`) AS `created` FROM `photo`
1620 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1621 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1622 intval($a->data['user']['uid']),
1623 dbesc('Contact Photos'),
1624 dbesc(L10n::t('Contact Photos')),
1625 intval($a->pager['start']),
1626 intval($a->pager['itemspage'])
1630 if (DBM::is_result($r)) {
1631 // "Twist" is only used for the duepunto theme with style "slackr"
1633 foreach ($r as $rr) {
1634 //hide profile photos to others
1635 if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos'))) {
1641 $ext = $phototypes[$rr['type']];
1643 $alt_e = $rr['filename'];
1644 $name_e = $rr['album'];
1648 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1649 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1650 'title' => L10n::t('View Photo'),
1651 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1654 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1656 'alt' => L10n::t('View Album'),
1663 $tpl = get_markup_template('photos_recent.tpl');
1664 $o .= replace_macros($tpl, [
1665 '$title' => L10n::t('Recent Photos'),
1666 '$can_post' => $can_post,
1667 '$upload' => [L10n::t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'],
1668 '$photos' => $photos,
1669 '$paginate' => paginate($a),