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['object-type'] = ACTIVITY_OBJ_PERSON;
644 $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
645 $arr['tag'] = $tagged[4];
646 $arr['inform'] = $tagged[2];
648 $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]') ;
649 $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" ;
651 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
652 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
654 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
656 $arr['object'] .= '</link></object>' . "\n";
658 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $p[0]['desc'] . '</title><id>'
659 . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
660 $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>';
662 $item_id = Item::insert($arr);
664 Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
669 goaway($_SESSION['photo_return']);
670 return; // NOTREACHED
674 // default post action - upload a photo
675 Addon::callHooks('photo_post_init', $_POST);
677 // Determine the album to use
678 $album = x($_REQUEST, 'album') ? notags(trim($_REQUEST['album'])) : '';
679 $newalbum = x($_REQUEST, 'newalbum') ? notags(trim($_REQUEST['newalbum'])) : '';
681 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
683 if (!strlen($album)) {
684 if (strlen($newalbum)) {
687 $album = DateTimeFormat::localNow('Y');
692 * We create a wall item for every photo, but we don't want to
693 * overwhelm the data stream with a hundred newly uploaded photos.
694 * So we will make the first photo uploaded to this album in the last several hours
695 * visible by default, the rest will become visible over time when and if
696 * they acquire comments, likes, dislikes, and/or tags
699 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
701 intval($page_owner_uid)
703 if (!DBM::is_result($r) || ($album == L10n::t('Profile Photos'))) {
709 if (x($_REQUEST, 'not_visible') && $_REQUEST['not_visible'] !== 'false') {
713 $group_allow = defaults($_REQUEST, 'group_allow' , []);
714 $contact_allow = defaults($_REQUEST, 'contact_allow', []);
715 $group_deny = defaults($_REQUEST, 'group_deny' , []);
716 $contact_deny = defaults($_REQUEST, 'contact_deny' , []);
718 $str_group_allow = perms2str(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
719 $str_contact_allow = perms2str(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
720 $str_group_deny = perms2str(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
721 $str_contact_deny = perms2str(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
723 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
725 Addon::callHooks('photo_post_file', $ret);
727 if (x($ret, 'src') && x($ret, 'filesize')) {
729 $filename = $ret['filename'];
730 $filesize = $ret['filesize'];
731 $type = $ret['type'];
732 $error = UPLOAD_ERR_OK;
734 $src = $_FILES['userfile']['tmp_name'];
735 $filename = basename($_FILES['userfile']['name']);
736 $filesize = intval($_FILES['userfile']['size']);
737 $type = $_FILES['userfile']['type'];
738 $error = $_FILES['userfile']['error'];
741 if ($error !== UPLOAD_ERR_OK) {
743 case UPLOAD_ERR_INI_SIZE:
744 notice(L10n::t('Image exceeds size limit of %s', ini_get('upload_max_filesize')) . EOL);
746 case UPLOAD_ERR_FORM_SIZE:
747 notice(L10n::t('Image exceeds size limit of %s', formatBytes(defaults($_REQUEST, 'MAX_FILE_SIZE', 0))) . EOL);
749 case UPLOAD_ERR_PARTIAL:
750 notice(L10n::t('Image upload didn\'t complete, please try again') . EOL);
752 case UPLOAD_ERR_NO_FILE:
753 notice(L10n::t('Image file is missing') . EOL);
755 case UPLOAD_ERR_NO_TMP_DIR:
756 case UPLOAD_ERR_CANT_WRITE:
757 case UPLOAD_ERR_EXTENSION:
758 notice(L10n::t('Server can\'t accept new file upload at this time, please contact your administrator') . EOL);
763 Addon::callHooks('photo_post_end', $foo);
768 $type = Image::guessType($filename);
771 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
773 $maximagesize = Config::get('system', 'maximagesize');
775 if ($maximagesize && ($filesize > $maximagesize)) {
776 notice(L10n::t('Image exceeds size limit of %s', formatBytes($maximagesize)) . EOL);
779 Addon::callHooks('photo_post_end', $foo);
784 notice(L10n::t('Image file is empty.') . EOL);
787 Addon::callHooks('photo_post_end', $foo);
791 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
793 $imagedata = @file_get_contents($src);
795 $Image = new Image($imagedata, $type);
797 if (!$Image->isValid()) {
798 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
799 notice(L10n::t('Unable to process image.') . EOL);
802 Addon::callHooks('photo_post_end',$foo);
806 $exif = $Image->orient($src);
809 $max_length = Config::get('system', 'max_image_length');
811 $max_length = MAX_IMAGE_LENGTH;
813 if ($max_length > 0) {
814 $Image->scaleDown($max_length);
817 $width = $Image->getWidth();
818 $height = $Image->getHeight();
822 $photo_hash = Photo::newResource();
824 $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);
827 logger('mod/photos.php: photos_post(): image store failed', LOGGER_DEBUG);
828 notice(L10n::t('Image upload failed.') . EOL);
832 if ($width > 640 || $height > 640) {
833 $Image->scaleDown(640);
834 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);
838 if ($width > 320 || $height > 320) {
839 $Image->scaleDown(320);
840 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);
844 $uri = Item::newURI($page_owner_uid);
846 // Create item container
848 if ($exif && $exif['GPS'] && Feature::isEnabled($page_owner_uid, 'photo_location')) {
849 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
850 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
855 $arr['coord'] = $lat . ' ' . $lon;
858 $arr['guid'] = get_guid(32);
859 $arr['uid'] = $page_owner_uid;
861 $arr['parent-uri'] = $uri;
862 $arr['type'] = 'photo';
864 $arr['resource-id'] = $photo_hash;
865 $arr['contact-id'] = $owner_record['id'];
866 $arr['owner-name'] = $owner_record['name'];
867 $arr['owner-link'] = $owner_record['url'];
868 $arr['owner-avatar'] = $owner_record['thumb'];
869 $arr['author-name'] = $owner_record['name'];
870 $arr['author-link'] = $owner_record['url'];
871 $arr['author-avatar'] = $owner_record['thumb'];
873 $arr['allow_cid'] = $str_contact_allow;
874 $arr['allow_gid'] = $str_group_allow;
875 $arr['deny_cid'] = $str_contact_deny;
876 $arr['deny_gid'] = $str_group_deny;
877 $arr['visible'] = $visible;
880 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
881 . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$Image->getExt() . '[/img]'
884 $item_id = Item::insert($arr);
885 // Update the photo albums cache
886 Photo::clearAlbumCache($page_owner_uid);
889 Worker::add(PRIORITY_HIGH, "Notifier", 'wall-new', $item_id);
892 Addon::callHooks('photo_post_end', intval($item_id));
894 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
895 // if they do not wish to be redirected
897 goaway($_SESSION['photo_return']);
901 function photos_content(App $a)
905 // photos/name/upload
906 // photos/name/upload/xxxxx (xxxxx is album name)
907 // photos/name/album/xxxxx
908 // photos/name/album/xxxxx/edit
909 // photos/name/image/xxxxx
910 // photos/name/image/xxxxx/edit
912 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
913 notice(L10n::t('Public access denied.') . EOL);
917 require_once 'include/security.php';
918 require_once 'include/conversation.php';
920 if (!x($a->data,'user')) {
921 notice(L10n::t('No photos selected') . EOL);
925 $phototypes = Image::supportedTypes();
927 $_SESSION['photo_return'] = $a->cmd;
932 $datatype = $a->argv[2];
933 $datum = $a->argv[3];
934 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
935 $datatype = 'upload';
937 $datatype = 'summary';
946 // Setup permissions structures
950 $remote_contact = false;
953 $owner_uid = $a->data['user']['uid'];
955 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
957 if (local_user() && (local_user() == $owner_uid)) {
960 if ($community_page && remote_user()) {
961 if (is_array($_SESSION['remote'])) {
962 foreach ($_SESSION['remote'] as $v) {
963 if ($v['uid'] == $owner_uid) {
964 $contact_id = $v['cid'];
971 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
975 if (DBM::is_result($r)) {
978 $remote_contact = true;
979 $visitor = $contact_id;
987 // perhaps they're visiting - but not a community page, so they wouldn't have write access
988 if (remote_user() && !$visitor) {
990 if (is_array($_SESSION['remote'])) {
991 foreach ($_SESSION['remote'] as $v) {
992 if ($v['uid'] == $owner_uid) {
993 $contact_id = $v['cid'];
999 $groups = Group::getIdsByContactId($contact_id);
1000 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1001 intval($contact_id),
1004 if (DBM::is_result($r)) {
1006 $remote_contact = true;
1011 if (!$remote_contact && local_user()) {
1012 $contact_id = $_SESSION['cid'];
1013 $contact = $a->contact;
1016 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
1017 notice(L10n::t('Access to this item is restricted.') . EOL);
1021 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
1026 $is_owner = (local_user() && (local_user() == $owner_uid));
1027 $o .= Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
1029 // Display upload form
1030 if ($datatype === 'upload') {
1032 notice(L10n::t('Permission denied.'));
1036 $selname = $datum ? hex2bin($datum) : '';
1040 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '> </option>';
1041 if (count($a->data['albums'])) {
1042 foreach ($a->data['albums'] as $album) {
1043 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos'))) {
1046 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1047 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1053 $ret = ['post_url' => 'photos/' . $a->data['user']['nickname'],
1054 'addon_text' => $uploader,
1055 'default_upload' => true];
1057 Addon::callHooks('photo_upload_form',$ret);
1059 $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), []);
1060 $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), [
1061 '$submit' => L10n::t('Submit'),
1064 $usage_message = '';
1066 $tpl = get_markup_template('photos_upload.tpl');
1068 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML($a->user));
1070 $o .= replace_macros($tpl,[
1071 '$pagename' => L10n::t('Upload Photos'),
1072 '$sessid' => session_id(),
1073 '$usage' => $usage_message,
1074 '$nickname' => $a->data['user']['nickname'],
1075 '$newalbum' => L10n::t('New album name: '),
1076 '$existalbumtext' => L10n::t('or existing album name: '),
1077 '$nosharetext' => L10n::t('Do not show a status post for this upload'),
1078 '$albumselect' => $albumselect,
1079 '$permissions' => L10n::t('Permissions'),
1080 '$aclselect' => $aclselect_e,
1081 '$alt_uploader' => $ret['addon_text'],
1082 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
1083 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
1084 '$uploadurl' => $ret['post_url'],
1086 // ACL permissions box
1087 '$group_perms' => L10n::t('Show to Groups'),
1088 '$contact_perms' => L10n::t('Show to Contacts'),
1089 '$return_path' => $a->query_string,
1095 // Display a single photo album
1096 if ($datatype === 'album') {
1097 $album = hex2bin($datum);
1099 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1100 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1104 if (DBM::is_result($r)) {
1105 $a->set_pager_total(count($r));
1106 $a->set_pager_itemspage(20);
1109 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1110 $order_field = defaults($_GET, 'order', '');
1111 if ($order_field === 'posted') {
1117 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1118 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1119 ANY_VALUE(`created`) as `created`
1120 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1121 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1124 intval($a->pager['start']),
1125 intval($a->pager['itemspage'])
1129 if ($cmd === 'edit') {
1130 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos'))) {
1132 $edit_tpl = get_markup_template('album_edit.tpl');
1136 $o .= replace_macros($edit_tpl,[
1137 '$nametext' => L10n::t('New album name: '),
1138 '$nickname' => $a->data['user']['nickname'],
1139 '$album' => $album_e,
1140 '$hexalbum' => bin2hex($album),
1141 '$submit' => L10n::t('Submit'),
1142 '$dropsubmit' => L10n::t('Delete Album')
1147 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos')) && $can_post) {
1148 $edit = [L10n::t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1152 if ($order_field === 'posted') {
1153 $order = [L10n::t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album)];
1155 $order = [L10n::t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted'];
1160 if (DBM::is_result($r)) {
1161 // "Twist" is only used for the duepunto theme with style "slackr"
1163 foreach ($r as $rr) {
1166 $ext = $phototypes[$rr['type']];
1168 $imgalt_e = $rr['filename'];
1169 $desc_e = $rr['desc'];
1173 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1174 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1175 . ($order_field === 'posted' ? '?f=&order=posted' : ''),
1176 'title' => L10n::t('View Photo'),
1177 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1181 'hash'=> $rr['resource-id'],
1186 $tpl = get_markup_template('photo_album.tpl');
1187 $o .= replace_macros($tpl, [
1188 '$photos' => $photos,
1190 '$can_post' => $can_post,
1191 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)],
1194 '$paginate' => paginate($a),
1201 // Display one photo
1202 if ($datatype === 'image') {
1203 // fetch image, item containing image, then comments
1204 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1205 $sql_extra ORDER BY `scale` ASC ",
1210 if (!DBM::is_result($ph)) {
1211 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1216 if (DBM::is_result($ph)) {
1217 notice(L10n::t('Permission denied. Access to this item may be restricted.'));
1219 notice(L10n::t('Photo not available') . EOL);
1228 * @todo This query is totally bad, the whole functionality has to be changed
1229 * The query leads to a really intense used index.
1230 * By now we hide it if someone wants to.
1232 if (!Config::get('system', 'no_count', false)) {
1233 if ($_GET['order'] === 'posted') {
1239 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1240 $sql_extra ORDER BY `created` $order ",
1241 dbesc($ph[0]['album']),
1245 if (DBM::is_result($prvnxt)) {
1246 foreach ($prvnxt as $z => $entry) {
1247 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1251 $prv = count($prvnxt) - 1;
1253 if ($nxt >= count($prvnxt)) {
1259 $edit_suffix = ((($cmd === 'edit') && $can_post) ? '/edit' : '');
1260 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1261 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1265 if (count($ph) == 1) {
1266 $hires = $lores = $ph[0];
1269 if (count($ph) > 1) {
1270 if ($ph[1]['scale'] == 2) {
1271 // original is 640 or less, we can display it directly
1272 $hires = $lores = $ph[0];
1279 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1284 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1286 'edit' => ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? L10n::t('View photo') : L10n::t('Edit photo'))],
1287 'profile'=>['profile_photo/use/'.$ph[0]['resource-id'], L10n::t('Use as profile photo')],
1291 $lock = ((($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1292 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])))
1293 ? L10n::t('Private Message')
1299 if ($cmd === 'edit') {
1300 $tpl = get_markup_template('photo_edit_head.tpl');
1301 $a->page['htmlhead'] .= replace_macros($tpl,[
1302 '$prevlink' => $prevlink,
1303 '$nextlink' => $nextlink
1308 $prevlink = [$prevlink, '<div class="icon prev"></div>'] ;
1312 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1313 'title'=> L10n::t('View Full Size'),
1314 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . DateTimeFormat::utcNow('ymdhis'),
1315 'height' => $hires['height'],
1316 'width' => $hires['width'],
1317 'album' => $hires['album'],
1318 'filename' => $hires['filename'],
1322 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1326 // Do we have an item for this photo?
1328 // FIXME! - replace following code to display the conversation with our normal
1329 // conversation functions so that it works correctly and tracks changes
1330 // in the evolving conversation code.
1331 // The difference is that we won't be displaying the conversation head item
1332 // as a "post" but displaying instead the photo it is linked to
1334 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1335 $linked_items = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1342 if (DBM::is_result($linked_items)) {
1343 // This is a workaround to not being forced to rewrite the while $sql_extra handling
1344 $link_item = Item::selectFirstForUser(local_user(), [], ['id' => $linked_items[0]['id']]);
1346 $r = q("SELECT COUNT(*) AS `total`
1347 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1348 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1349 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1350 AND `item`.`uid` = %d
1352 dbesc($link_item['uri']),
1353 dbesc($link_item['uri']),
1354 intval($link_item['uid'])
1358 if (DBM::is_result($r)) {
1359 $a->set_pager_total($r[0]['total']);
1363 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1364 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1365 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1366 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1367 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1368 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1369 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1370 AND `item`.`uid` = %d
1372 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1373 dbesc($link_item['uri']),
1374 dbesc($link_item['uri']),
1375 intval($link_item['uid']),
1376 intval($a->pager['start']),
1377 intval($a->pager['itemspage'])
1381 if (local_user() && (local_user() == $link_item['uid'])) {
1382 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1385 if ($link_item['coord']) {
1386 $map = Map::byCoordinates($link_item['coord']);
1392 if (count($linked_items) && strlen($link_item['tag'])) {
1393 $arr = explode(',', $link_item['tag']);
1394 // parse tags and add links
1396 foreach ($arr as $t) {
1397 if (strlen($tag_str)) {
1400 $tag_str .= BBCode::convert($t);
1402 $tags = [L10n::t('Tags: '), $tag_str];
1403 if ($cmd === 'edit') {
1404 $tags[] = 'tagrm/' . $link_item['id'];
1405 $tags[] = L10n::t('[Remove any tag]');
1411 if ($cmd === 'edit' && $can_post) {
1412 $edit_tpl = get_markup_template('photo_edit.tpl');
1414 $album_e = $ph[0]['album'];
1415 $caption_e = $ph[0]['desc'];
1416 $aclselect_e = ACL::getFullSelectorHTML($ph[0]);
1418 $edit = replace_macros($edit_tpl, [
1419 '$id' => $ph[0]['id'],
1420 '$album' => ['albname', L10n::t('New album name'), $album_e,''],
1421 '$caption' => ['desc', L10n::t('Caption'), $caption_e, ''],
1422 '$tags' => ['newtag', L10n::t('Add a Tag'), "", L10n::t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1423 '$rotate_none' => ['rotate', L10n::t('Do not rotate'),0,'', true],
1424 '$rotate_cw' => ['rotate', L10n::t("Rotate CW \x28right\x29"),1,''],
1425 '$rotate_ccw' => ['rotate', L10n::t("Rotate CCW \x28left\x29"),2,''],
1427 '$nickname' => $a->data['user']['nickname'],
1428 '$resource_id' => $ph[0]['resource-id'],
1429 '$permissions' => L10n::t('Permissions'),
1430 '$aclselect' => $aclselect_e,
1432 '$item_id' => defaults($link_item, 'id', 0),
1433 '$submit' => L10n::t('Submit'),
1434 '$delete' => L10n::t('Delete Photo'),
1436 // ACL permissions box
1437 '$group_perms' => L10n::t('Show to Groups'),
1438 '$contact_perms' => L10n::t('Show to Contacts'),
1439 '$return_path' => $a->query_string,
1450 if (count($linked_items)) {
1451 $cmnt_tpl = get_markup_template('comment_item.tpl');
1452 $tpl = get_markup_template('photo_item.tpl');
1453 $return_url = $a->cmd;
1455 if ($can_post || can_write_wall($owner_uid)) {
1456 $like_tpl = get_markup_template('like_noshare.tpl');
1457 $likebuttons = replace_macros($like_tpl, [
1458 '$id' => $link_item['id'],
1459 '$likethis' => L10n::t("I like this \x28toggle\x29"),
1460 '$nolike' => (Feature::isEnabled(local_user(), 'dislike') ? L10n::t("I don't like this \x28toggle\x29") : ''),
1461 '$wait' => L10n::t('Please wait'),
1462 '$return_path' => $a->query_string,
1466 if (!DBM::is_result($r)) {
1467 if (($can_post || can_write_wall($owner_uid))) {
1468 $comments .= replace_macros($cmnt_tpl, [
1469 '$return_path' => '',
1470 '$jsreload' => $return_url,
1471 '$type' => 'wall-comment',
1472 '$id' => $link_item['id'],
1473 '$parent' => $link_item['id'],
1474 '$profile_uid' => $owner_uid,
1475 '$mylink' => $contact['url'],
1476 '$mytitle' => L10n::t('This is you'),
1477 '$myphoto' => $contact['thumb'],
1478 '$comment' => L10n::t('Comment'),
1479 '$submit' => L10n::t('Submit'),
1480 '$preview' => L10n::t('Preview'),
1481 '$sourceapp' => L10n::t($a->sourcename),
1483 '$rand_num' => random_digits(12)
1489 'like' => ['title' => L10n::t('Likes','title')],'dislike' => ['title' => L10n::t('Dislikes','title')],
1490 'attendyes' => ['title' => L10n::t('Attending','title')], 'attendno' => ['title' => L10n::t('Not attending','title')], 'attendmaybe' => ['title' => L10n::t('Might attend','title')]
1494 if (DBM::is_result($r)) {
1495 foreach ($r as $item) {
1496 builtin_activity_puller($item, $conv_responses);
1499 if (x($conv_responses['like'], $link_item['uri'])) {
1500 $like = format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like', $link_item['id']);
1502 if (x($conv_responses['dislike'], $link_item['uri'])) {
1503 $dislike = format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike', $link_item['id']);
1506 if (($can_post || can_write_wall($owner_uid))) {
1507 $comments .= replace_macros($cmnt_tpl,[
1508 '$return_path' => '',
1509 '$jsreload' => $return_url,
1510 '$type' => 'wall-comment',
1511 '$id' => $link_item['id'],
1512 '$parent' => $link_item['id'],
1513 '$profile_uid' => $owner_uid,
1514 '$mylink' => $contact['url'],
1515 '$mytitle' => L10n::t('This is you'),
1516 '$myphoto' => $contact['thumb'],
1517 '$comment' => L10n::t('Comment'),
1518 '$submit' => L10n::t('Submit'),
1519 '$preview' => L10n::t('Preview'),
1520 '$sourceapp' => L10n::t($a->sourcename),
1522 '$rand_num' => random_digits(12)
1526 foreach ($r as $item) {
1531 if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) {
1535 $profile_url = Contact::MagicLinkById($item['cid']);
1536 if (strpos($profile_url, 'redir/') === 0) {
1537 $sparkle = ' sparkle';
1542 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1544 $profile_name = ((strlen($item['author-name']) && $diff_author) ? $item['author-name'] : $item['name']);
1545 $profile_avatar = ((strlen($item['author-avatar']) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1547 $profile_link = $profile_url;
1549 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1551 'dropping' => $dropping,
1552 'pagedrop' => false,
1553 'select' => L10n::t('Select'),
1554 'delete' => L10n::t('Delete'),
1557 $name_e = $profile_name;
1558 $title_e = $item['title'];
1559 $body_e = BBCode::convert($item['body']);
1561 $comments .= replace_macros($template,[
1562 '$id' => $item['item_id'],
1563 '$profile_url' => $profile_link,
1565 '$thumb' => $profile_avatar,
1566 '$sparkle' => $sparkle,
1567 '$title' => $title_e,
1569 '$ago' => Temporal::getRelativeDate($item['created']),
1570 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1572 '$comment' => $comment
1575 if (($can_post || can_write_wall($owner_uid))) {
1576 $comments .= replace_macros($cmnt_tpl, [
1577 '$return_path' => '',
1578 '$jsreload' => $return_url,
1579 '$type' => 'wall-comment',
1580 '$id' => $item['item_id'],
1581 '$parent' => $item['parent'],
1582 '$profile_uid' => $owner_uid,
1583 '$mylink' => $contact['url'],
1584 '$mytitle' => L10n::t('This is you'),
1585 '$myphoto' => $contact['thumb'],
1586 '$comment' => L10n::t('Comment'),
1587 '$submit' => L10n::t('Submit'),
1588 '$preview' => L10n::t('Preview'),
1589 '$sourceapp' => L10n::t($a->sourcename),
1591 '$rand_num' => random_digits(12)
1596 $response_verbs = ['like'];
1597 if (Feature::isEnabled($owner_uid, 'dislike')) {
1598 $response_verbs[] = 'dislike';
1600 $responses = get_responses($conv_responses, $response_verbs, '', $link_item);
1602 $paginate = paginate($a);
1605 $photo_tpl = get_markup_template('photo_view.tpl');
1606 $o .= replace_macros($photo_tpl, [
1607 '$id' => $ph[0]['id'],
1608 '$album' => [$album_link, $ph[0]['album']],
1612 '$prevlink' => $prevlink,
1613 '$nextlink' => $nextlink,
1614 '$desc' => $ph[0]['desc'],
1618 '$map_text' => L10n::t('Map'),
1619 '$likebuttons' => $likebuttons,
1621 '$dislike' => $dislike,
1622 'responses' => $responses,
1623 '$comments' => $comments,
1624 '$paginate' => $paginate,
1627 $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="photo" />' . "\n";
1628 $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1629 $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . $photo["href"] . '" />' . "\n";
1630 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1631 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1636 // Default - show recent photos with upload link (if applicable)
1639 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1640 $sql_extra GROUP BY `resource-id`",
1641 intval($a->data['user']['uid']),
1642 dbesc('Contact Photos'),
1643 dbesc(L10n::t('Contact Photos'))
1645 if (DBM::is_result($r)) {
1646 $a->set_pager_total(count($r));
1647 $a->set_pager_itemspage(20);
1650 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1651 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1652 ANY_VALUE(`created`) AS `created` FROM `photo`
1653 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1654 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1655 intval($a->data['user']['uid']),
1656 dbesc('Contact Photos'),
1657 dbesc(L10n::t('Contact Photos')),
1658 intval($a->pager['start']),
1659 intval($a->pager['itemspage'])
1663 if (DBM::is_result($r)) {
1664 // "Twist" is only used for the duepunto theme with style "slackr"
1666 foreach ($r as $rr) {
1667 //hide profile photos to others
1668 if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos'))) {
1674 $ext = $phototypes[$rr['type']];
1676 $alt_e = $rr['filename'];
1677 $name_e = $rr['album'];
1681 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1682 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1683 'title' => L10n::t('View Photo'),
1684 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1687 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1689 'alt' => L10n::t('View Album'),
1696 $tpl = get_markup_template('photos_recent.tpl');
1697 $o .= replace_macros($tpl, [
1698 '$title' => L10n::t('Recent Photos'),
1699 '$can_post' => $can_post,
1700 '$upload' => [L10n::t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'],
1701 '$photos' => $photos,
1702 '$paginate' => paginate($a),