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\Network\Probe;
23 use Friendica\Object\Image;
24 use Friendica\Protocol\DFRN;
25 use Friendica\Util\DateTimeFormat;
26 use Friendica\Util\Map;
27 use Friendica\Util\Temporal;
29 require_once 'include/items.php';
30 require_once 'include/security.php';
32 function photos_init(App $a) {
35 DFRN::autoRedir($a, $a->argv[1]);
38 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
42 Nav::setSelected('home');
46 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
50 if (!DBM::is_result($user)) {
54 $a->data['user'] = $user[0];
55 $a->profile_uid = $user[0]['uid'];
56 $is_owner = (local_user() && (local_user() == $a->profile_uid));
58 $profile = Profile::getByNickname($nick, $a->profile_uid);
60 $account_type = Contact::getAccountType($profile);
62 $tpl = get_markup_template("vcard-widget.tpl");
64 $vcard_widget = replace_macros($tpl, [
65 '$name' => $profile['name'],
66 '$photo' => $profile['photo'],
67 '$addr' => defaults($profile, 'addr', ''),
68 '$account_type' => $account_type,
69 '$pdesc' => defaults($profile, 'pdesc', ''),
72 $albums = Photo::getAlbums($a->data['user']['uid']);
74 $albums_visible = ((intval($a->data['user']['hidewall']) && !local_user() && !remote_user()) ? false : true);
76 // add various encodings to the array so we can just loop through and pick them out in a template
77 $ret = ['success' => false];
80 $a->data['albums'] = $albums;
81 if ($albums_visible) {
82 $ret['success'] = true;
86 foreach ($albums as $k => $album) {
87 //hide profile photos to others
88 if (!$is_owner && !remote_user() && ($album['album'] == L10n::t('Profile Photos')))
91 'text' => $album['album'],
92 'total' => $album['total'],
93 'url' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
94 'urlencode' => urlencode($album['album']),
95 'bin2hex' => bin2hex($album['album'])
97 $ret['albums'][] = $entry;
101 if (local_user() && $a->data['user']['uid'] == local_user()) {
105 if ($ret['success']) {
106 $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'), [
107 '$nick' => $a->data['user']['nickname'],
108 '$title' => L10n::t('Photo Albums'),
109 '$recent' => L10n::t('Recent Photos'),
110 '$albums' => $ret['albums'],
111 '$baseurl' => System::baseUrl(),
112 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'],
113 '$can_post' => $can_post
118 if (!x($a->page, 'aside')) {
119 $a->page['aside'] = '';
121 $a->page['aside'] .= $vcard_widget;
122 $a->page['aside'] .= $photo_albums_widget;
124 $tpl = get_markup_template("photos_head.tpl");
125 $a->page['htmlhead'] .= replace_macros($tpl,[
126 '$ispublic' => L10n::t('everybody')
133 function photos_post(App $a)
135 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
136 logger('mod_photos: REQUEST ' . print_r($_REQUEST, true), LOGGER_DATA);
137 logger('mod_photos: FILES ' . print_r($_FILES, true), LOGGER_DATA);
139 $phototypes = Image::supportedTypes();
144 $page_owner_uid = $a->data['user']['uid'];
145 $community_page = $a->data['user']['page-flags'] == PAGE_COMMUNITY;
147 if (local_user() && (local_user() == $page_owner_uid)) {
150 if ($community_page && remote_user()) {
152 if (x($_SESSION, 'remote') && is_array($_SESSION['remote'])) {
153 foreach ($_SESSION['remote'] as $v) {
154 if ($v['uid'] == $page_owner_uid) {
155 $contact_id = $v['cid'];
161 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
163 intval($page_owner_uid)
165 if (DBM::is_result($r)) {
167 $visitor = $contact_id;
174 notice(L10n::t('Permission denied.') . EOL );
178 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
179 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
180 intval($page_owner_uid)
183 if (!DBM::is_result($r)) {
184 notice(L10n::t('Contact information unavailable') . EOL);
185 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
189 $owner_record = $r[0];
191 if ($a->argc > 3 && $a->argv[2] === 'album') {
192 $album = hex2bin($a->argv[3]);
194 if ($album === L10n::t('Profile Photos') || $album === 'Contact Photos' || $album === L10n::t('Contact Photos')) {
195 goaway($_SESSION['photo_return']);
196 return; // NOTREACHED
199 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
201 intval($page_owner_uid)
203 if (!DBM::is_result($r)) {
204 notice(L10n::t('Album not found.') . EOL);
205 goaway($_SESSION['photo_return']);
206 return; // NOTREACHED
209 // Check if the user has responded to a delete confirmation query
210 if ($_REQUEST['canceled']) {
211 goaway($_SESSION['photo_return']);
214 // RENAME photo album
215 $newalbum = notags(trim($_POST['albumname']));
216 if ($newalbum != $album) {
217 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
220 intval($page_owner_uid)
222 // Update the photo albums cache
223 Photo::clearAlbumCache($page_owner_uid);
225 $newurl = str_replace(bin2hex($album), bin2hex($newalbum), $_SESSION['photo_return']);
227 return; // NOTREACHED
231 * DELETE photo album and all its photos
234 if ($_POST['dropalbum'] == L10n::t('Delete Album')) {
235 // Check if we should do HTML-based delete confirmation
236 if (x($_REQUEST, 'confirm')) {
237 $drop_url = $a->query_string;
239 ['name' => 'albumname', 'value' => $_POST['albumname']],
241 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
243 '$message' => L10n::t('Do you really want to delete this photo album and all its photos?'),
244 '$extra_inputs' => $extra_inputs,
245 '$confirm' => L10n::t('Delete Album'),
246 '$confirm_url' => $drop_url,
247 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
248 '$cancel' => L10n::t('Cancel'),
250 $a->error = 1; // Set $a->error so the other module functions don't execute
256 // get the list of photos we are about to delete
259 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
261 intval($page_owner_uid),
265 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
266 intval(local_user()),
270 if (DBM::is_result($r)) {
271 foreach ($r as $rr) {
272 $res[] = "'" . dbesc($rr['rid']) . "'" ;
275 goaway($_SESSION['photo_return']);
276 return; // NOTREACHED
279 $str_res = implode(',', $res);
281 // remove the associated photos
282 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
283 intval($page_owner_uid)
286 // find and delete the corresponding item with all the comments and likes/dislikes
287 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
289 // Update the photo albums cache
290 Photo::clearAlbumCache($page_owner_uid);
293 goaway('photos/' . $a->data['user']['nickname']);
294 return; // NOTREACHED
298 // Check if the user has responded to a delete confirmation query for a single photo
299 if ($a->argc > 2 && x($_REQUEST, 'canceled')) {
300 goaway($_SESSION['photo_return']);
303 if ($a->argc > 2 && defaults($_POST, 'delete', '') === L10n::t('Delete Photo')) {
305 // same as above but remove single photo
307 // Check if we should do HTML-based delete confirmation
308 if (x($_REQUEST, 'confirm')) {
309 $drop_url = $a->query_string;
310 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
312 '$message' => L10n::t('Do you really want to delete this photo?'),
313 '$extra_inputs' => [],
314 '$confirm' => L10n::t('Delete Photo'),
315 '$confirm_url' => $drop_url,
316 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
317 '$cancel' => L10n::t('Cancel'),
319 $a->error = 1; // Set $a->error so the other module functions don't execute
324 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
326 intval($page_owner_uid),
330 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
331 intval(local_user()),
335 if (DBM::is_result($r)) {
336 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
337 intval($page_owner_uid),
338 dbesc($r[0]['resource-id'])
341 Item::deleteForUser(['resource-id' => $r[0]['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
343 // Update the photo albums cache
344 Photo::clearAlbumCache($page_owner_uid);
347 goaway('photos/' . $a->data['user']['nickname']);
348 return; // NOTREACHED
351 if ($a->argc > 2 && (x($_POST, 'desc') !== false || x($_POST, 'newtag') !== false || x($_POST, 'albname') !== false)) {
352 $desc = x($_POST, 'desc') ? notags(trim($_POST['desc'])) : '';
353 $rawtags = x($_POST, 'newtag') ? notags(trim($_POST['newtag'])) : '';
354 $item_id = x($_POST, 'item_id') ? intval($_POST['item_id']) : 0;
355 $albname = x($_POST, 'albname') ? notags(trim($_POST['albname'])) : '';
356 $origaname = x($_POST, 'origaname') ? notags(trim($_POST['origaname'])) : '';
357 $str_group_allow = perms2str($_POST['group_allow']);
358 $str_contact_allow = perms2str($_POST['contact_allow']);
359 $str_group_deny = perms2str($_POST['group_deny']);
360 $str_contact_deny = perms2str($_POST['contact_deny']);
362 $resource_id = $a->argv[2];
364 if (!strlen($albname)) {
365 $albname = DateTimeFormat::localNow('Y');
368 if (x($_POST,'rotate') !== false &&
369 (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
372 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0 LIMIT 1",
374 intval($page_owner_uid)
376 if (DBM::is_result($r)) {
377 $Image = new Image($r[0]['data'], $r[0]['type']);
378 if ($Image->isValid()) {
379 $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
380 $Image->rotate($rotate_deg);
382 $width = $Image->getWidth();
383 $height = $Image->getHeight();
385 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0",
386 dbesc($Image->asString()),
390 intval($page_owner_uid)
393 if ($width > 640 || $height > 640) {
394 $Image->scaleDown(640);
395 $width = $Image->getWidth();
396 $height = $Image->getHeight();
398 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 1",
399 dbesc($Image->asString()),
403 intval($page_owner_uid)
407 if ($width > 320 || $height > 320) {
408 $Image->scaleDown(320);
409 $width = $Image->getWidth();
410 $height = $Image->getHeight();
412 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 2",
413 dbesc($Image->asString()),
417 intval($page_owner_uid)
424 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
426 intval($page_owner_uid)
428 if (DBM::is_result($p)) {
429 $ext = $phototypes[$p[0]['type']];
430 $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",
433 dbesc($str_contact_allow),
434 dbesc($str_group_allow),
435 dbesc($str_contact_deny),
436 dbesc($str_group_deny),
438 intval($page_owner_uid)
441 // Update the photo albums cache if album name was changed
442 if ($albname !== $origaname) {
443 Photo::clearAlbumCache($page_owner_uid);
447 /* Don't make the item visible if the only change was the album name */
450 if ($p[0]['desc'] !== $desc || strlen($rawtags)) {
455 // Create item container
457 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
460 $arr['guid'] = get_guid(32);
461 $arr['uid'] = $page_owner_uid;
463 $arr['parent-uri'] = $uri;
464 $arr['type'] = 'photo';
466 $arr['resource-id'] = $p[0]['resource-id'];
467 $arr['contact-id'] = $owner_record['id'];
468 $arr['owner-name'] = $owner_record['name'];
469 $arr['owner-link'] = $owner_record['url'];
470 $arr['owner-avatar'] = $owner_record['thumb'];
471 $arr['author-name'] = $owner_record['name'];
472 $arr['author-link'] = $owner_record['url'];
473 $arr['author-avatar'] = $owner_record['thumb'];
474 $arr['title'] = $title;
475 $arr['allow_cid'] = $p[0]['allow_cid'];
476 $arr['allow_gid'] = $p[0]['allow_gid'];
477 $arr['deny_cid'] = $p[0]['deny_cid'];
478 $arr['deny_gid'] = $p[0]['deny_gid'];
479 $arr['visible'] = $visibility;
482 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
483 . '[img]' . System::baseUrl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
486 $item_id = Item::insert($arr);
490 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
492 intval($page_owner_uid)
495 if (DBM::is_result($r)) {
496 $old_tag = $r[0]['tag'];
497 $old_inform = $r[0]['inform'];
500 if (strlen($rawtags)) {
504 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
505 $x = substr($rawtags, 0, 1);
506 if ($x !== '@' && $x !== '#') {
507 $rawtags = '#' . $rawtags;
511 $tags = get_tags($rawtags);
514 foreach ($tags as $tag) {
515 if (strpos($tag, '@') === 0) {
517 $name = substr($tag,1);
518 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
520 $links = @Probe::lrdd($name);
522 foreach ($links as $link) {
523 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
524 $profile = $link['@attributes']['href'];
526 if ($link['@attributes']['rel'] === 'salmon') {
527 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
528 if (strlen($inform)) {
535 $taginfo[] = [$newname, $profile, $salmon];
540 if (strrpos($newname, '+')) {
541 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
545 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
550 $newname = str_replace('_',' ',$name);
552 //select someone from this user's contacts by name
553 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
555 intval($page_owner_uid)
558 if (!DBM::is_result($r)) {
559 //select someone by attag or nick and the name passed in
560 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
563 intval($page_owner_uid)
568 if (DBM::is_result($r)) {
569 $newname = $r[0]['name'];
570 $profile = $r[0]['url'];
571 $notify = 'cid:' . $r[0]['id'];
572 if (strlen($inform)) {
579 if (substr($notify, 0, 4) === 'cid:') {
580 $taginfo[] = [$newname, $profile, $notify, $r[0], '@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]'];
582 $taginfo[] = [$newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'];
584 if (strlen($str_tags)) {
587 $profile = str_replace(',', '%2c', $profile);
588 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
590 } elseif (strpos($tag, '#') === 0) {
591 $tagname = substr($tag, 1);
592 $str_tags .= '#[url=' . System::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url]';
598 if (strlen($newtag) && strlen($str_tags)) {
601 $newtag .= $str_tags;
603 $newinform = $old_inform;
604 if (strlen($newinform) && strlen($inform)) {
607 $newinform .= $inform;
609 $fields = ['tag' => $newtag, 'inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
610 $condition = ['id' => $item_id];
611 Item::update($fields, $condition);
614 foreach ($p as $scales) {
615 if (intval($scales['scale']) == 2) {
619 if (intval($scales['scale']) == 4) {
625 if (count($taginfo)) {
626 foreach ($taginfo as $tagged) {
627 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
630 $arr['guid'] = get_guid(32);
631 $arr['uid'] = $page_owner_uid;
633 $arr['parent-uri'] = $uri;
634 $arr['type'] = 'activity';
636 $arr['contact-id'] = $owner_record['id'];
637 $arr['owner-name'] = $owner_record['name'];
638 $arr['owner-link'] = $owner_record['url'];
639 $arr['owner-avatar'] = $owner_record['thumb'];
640 $arr['author-name'] = $owner_record['name'];
641 $arr['author-link'] = $owner_record['url'];
642 $arr['author-avatar'] = $owner_record['thumb'];
644 $arr['allow_cid'] = $p[0]['allow_cid'];
645 $arr['allow_gid'] = $p[0]['allow_gid'];
646 $arr['deny_cid'] = $p[0]['deny_cid'];
647 $arr['deny_gid'] = $p[0]['deny_gid'];
649 $arr['verb'] = ACTIVITY_TAG;
650 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
651 $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
652 $arr['tag'] = $tagged[4];
653 $arr['inform'] = $tagged[2];
655 $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]') ;
656 $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" ;
658 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
659 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
661 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
663 $arr['object'] .= '</link></object>' . "\n";
665 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $p[0]['desc'] . '</title><id>'
666 . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
667 $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>';
669 $item_id = Item::insert($arr);
671 Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
676 goaway($_SESSION['photo_return']);
677 return; // NOTREACHED
681 // default post action - upload a photo
682 Addon::callHooks('photo_post_init', $_POST);
684 // Determine the album to use
685 $album = x($_REQUEST, 'album') ? notags(trim($_REQUEST['album'])) : '';
686 $newalbum = x($_REQUEST, 'newalbum') ? notags(trim($_REQUEST['newalbum'])) : '';
688 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
690 if (!strlen($album)) {
691 if (strlen($newalbum)) {
694 $album = DateTimeFormat::localNow('Y');
699 * We create a wall item for every photo, but we don't want to
700 * overwhelm the data stream with a hundred newly uploaded photos.
701 * So we will make the first photo uploaded to this album in the last several hours
702 * visible by default, the rest will become visible over time when and if
703 * they acquire comments, likes, dislikes, and/or tags
706 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
708 intval($page_owner_uid)
710 if (!DBM::is_result($r) || ($album == L10n::t('Profile Photos'))) {
716 if (x($_REQUEST, 'not_visible') && $_REQUEST['not_visible'] !== 'false') {
720 $group_allow = defaults($_REQUEST, 'group_allow' , []);
721 $contact_allow = defaults($_REQUEST, 'contact_allow', []);
722 $group_deny = defaults($_REQUEST, 'group_deny' , []);
723 $contact_deny = defaults($_REQUEST, 'contact_deny' , []);
725 $str_group_allow = perms2str(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
726 $str_contact_allow = perms2str(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
727 $str_group_deny = perms2str(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
728 $str_contact_deny = perms2str(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
730 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
732 Addon::callHooks('photo_post_file', $ret);
734 if (x($ret, 'src') && x($ret, 'filesize')) {
736 $filename = $ret['filename'];
737 $filesize = $ret['filesize'];
738 $type = $ret['type'];
739 $error = UPLOAD_ERR_OK;
741 $src = $_FILES['userfile']['tmp_name'];
742 $filename = basename($_FILES['userfile']['name']);
743 $filesize = intval($_FILES['userfile']['size']);
744 $type = $_FILES['userfile']['type'];
745 $error = $_FILES['userfile']['error'];
748 if ($error !== UPLOAD_ERR_OK) {
750 case UPLOAD_ERR_INI_SIZE:
751 notice(L10n::t('Image exceeds size limit of %s', ini_get('upload_max_filesize')) . EOL);
753 case UPLOAD_ERR_FORM_SIZE:
754 notice(L10n::t('Image exceeds size limit of %s', formatBytes(defaults($_REQUEST, 'MAX_FILE_SIZE', 0))) . EOL);
756 case UPLOAD_ERR_PARTIAL:
757 notice(L10n::t('Image upload didn\'t complete, please try again') . EOL);
759 case UPLOAD_ERR_NO_FILE:
760 notice(L10n::t('Image file is missing') . EOL);
762 case UPLOAD_ERR_NO_TMP_DIR:
763 case UPLOAD_ERR_CANT_WRITE:
764 case UPLOAD_ERR_EXTENSION:
765 notice(L10n::t('Server can\'t accept new file upload at this time, please contact your administrator') . EOL);
770 Addon::callHooks('photo_post_end', $foo);
775 $type = Image::guessType($filename);
778 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
780 $maximagesize = Config::get('system', 'maximagesize');
782 if ($maximagesize && ($filesize > $maximagesize)) {
783 notice(L10n::t('Image exceeds size limit of %s', formatBytes($maximagesize)) . EOL);
786 Addon::callHooks('photo_post_end', $foo);
791 notice(L10n::t('Image file is empty.') . EOL);
794 Addon::callHooks('photo_post_end', $foo);
798 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
800 $imagedata = @file_get_contents($src);
802 $Image = new Image($imagedata, $type);
804 if (!$Image->isValid()) {
805 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
806 notice(L10n::t('Unable to process image.') . EOL);
809 Addon::callHooks('photo_post_end',$foo);
813 $exif = $Image->orient($src);
816 $max_length = Config::get('system', 'max_image_length');
818 $max_length = MAX_IMAGE_LENGTH;
820 if ($max_length > 0) {
821 $Image->scaleDown($max_length);
824 $width = $Image->getWidth();
825 $height = $Image->getHeight();
829 $photo_hash = Photo::newResource();
831 $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);
834 logger('mod/photos.php: photos_post(): image store failed', LOGGER_DEBUG);
835 notice(L10n::t('Image upload failed.') . EOL);
839 if ($width > 640 || $height > 640) {
840 $Image->scaleDown(640);
841 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);
845 if ($width > 320 || $height > 320) {
846 $Image->scaleDown(320);
847 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);
851 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
853 // Create item container
855 if ($exif && $exif['GPS'] && Feature::isEnabled($page_owner_uid, 'photo_location')) {
856 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
857 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
862 $arr['coord'] = $lat . ' ' . $lon;
865 $arr['guid'] = get_guid(32);
866 $arr['uid'] = $page_owner_uid;
868 $arr['parent-uri'] = $uri;
869 $arr['type'] = 'photo';
871 $arr['resource-id'] = $photo_hash;
872 $arr['contact-id'] = $owner_record['id'];
873 $arr['owner-name'] = $owner_record['name'];
874 $arr['owner-link'] = $owner_record['url'];
875 $arr['owner-avatar'] = $owner_record['thumb'];
876 $arr['author-name'] = $owner_record['name'];
877 $arr['author-link'] = $owner_record['url'];
878 $arr['author-avatar'] = $owner_record['thumb'];
880 $arr['allow_cid'] = $str_contact_allow;
881 $arr['allow_gid'] = $str_group_allow;
882 $arr['deny_cid'] = $str_contact_deny;
883 $arr['deny_gid'] = $str_group_deny;
884 $arr['visible'] = $visible;
887 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
888 . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$Image->getExt() . '[/img]'
891 $item_id = Item::insert($arr);
892 // Update the photo albums cache
893 Photo::clearAlbumCache($page_owner_uid);
896 Worker::add(PRIORITY_HIGH, "Notifier", 'wall-new', $item_id);
899 Addon::callHooks('photo_post_end', intval($item_id));
901 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
902 // if they do not wish to be redirected
904 goaway($_SESSION['photo_return']);
908 function photos_content(App $a)
912 // photos/name/upload
913 // photos/name/upload/xxxxx (xxxxx is album name)
914 // photos/name/album/xxxxx
915 // photos/name/album/xxxxx/edit
916 // photos/name/image/xxxxx
917 // photos/name/image/xxxxx/edit
919 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
920 notice(L10n::t('Public access denied.') . EOL);
924 require_once 'include/security.php';
925 require_once 'include/conversation.php';
927 if (!x($a->data,'user')) {
928 notice(L10n::t('No photos selected') . EOL );
932 $phototypes = Image::supportedTypes();
934 $_SESSION['photo_return'] = $a->cmd;
939 $datatype = $a->argv[2];
940 $datum = $a->argv[3];
941 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
942 $datatype = 'upload';
944 $datatype = 'summary';
953 // Setup permissions structures
957 $remote_contact = false;
960 $owner_uid = $a->data['user']['uid'];
962 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
964 if (local_user() && (local_user() == $owner_uid)) {
967 if ($community_page && remote_user()) {
968 if (is_array($_SESSION['remote'])) {
969 foreach ($_SESSION['remote'] as $v) {
970 if ($v['uid'] == $owner_uid) {
971 $contact_id = $v['cid'];
978 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
982 if (DBM::is_result($r)) {
985 $remote_contact = true;
986 $visitor = $contact_id;
994 // perhaps they're visiting - but not a community page, so they wouldn't have write access
995 if (remote_user() && !$visitor) {
997 if (is_array($_SESSION['remote'])) {
998 foreach ($_SESSION['remote'] as $v) {
999 if ($v['uid'] == $owner_uid) {
1000 $contact_id = $v['cid'];
1006 $groups = Group::getIdsByContactId($contact_id);
1007 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1008 intval($contact_id),
1011 if (DBM::is_result($r)) {
1013 $remote_contact = true;
1018 if (!$remote_contact && local_user()) {
1019 $contact_id = $_SESSION['cid'];
1020 $contact = $a->contact;
1023 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
1024 notice(L10n::t('Access to this item is restricted.') . EOL);
1028 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
1033 $is_owner = (local_user() && (local_user() == $owner_uid));
1034 $o .= Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
1036 // Display upload form
1037 if ($datatype === 'upload') {
1039 notice(L10n::t('Permission denied.'));
1043 $selname = $datum ? hex2bin($datum) : '';
1047 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '> </option>';
1048 if (count($a->data['albums'])) {
1049 foreach ($a->data['albums'] as $album) {
1050 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos'))) {
1053 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1054 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1060 $ret = ['post_url' => 'photos/' . $a->data['user']['nickname'],
1061 'addon_text' => $uploader,
1062 'default_upload' => true];
1064 Addon::callHooks('photo_upload_form',$ret);
1066 $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), []);
1067 $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), [
1068 '$submit' => L10n::t('Submit'),
1071 $usage_message = '';
1073 $tpl = get_markup_template('photos_upload.tpl');
1075 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML($a->user));
1077 $o .= replace_macros($tpl,[
1078 '$pagename' => L10n::t('Upload Photos'),
1079 '$sessid' => session_id(),
1080 '$usage' => $usage_message,
1081 '$nickname' => $a->data['user']['nickname'],
1082 '$newalbum' => L10n::t('New album name: '),
1083 '$existalbumtext' => L10n::t('or existing album name: '),
1084 '$nosharetext' => L10n::t('Do not show a status post for this upload'),
1085 '$albumselect' => $albumselect,
1086 '$permissions' => L10n::t('Permissions'),
1087 '$aclselect' => $aclselect_e,
1088 '$alt_uploader' => $ret['addon_text'],
1089 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
1090 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
1091 '$uploadurl' => $ret['post_url'],
1093 // ACL permissions box
1094 '$group_perms' => L10n::t('Show to Groups'),
1095 '$contact_perms' => L10n::t('Show to Contacts'),
1096 '$return_path' => $a->query_string,
1102 // Display a single photo album
1103 if ($datatype === 'album') {
1104 $album = hex2bin($datum);
1106 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1107 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1111 if (DBM::is_result($r)) {
1112 $a->set_pager_total(count($r));
1113 $a->set_pager_itemspage(20);
1116 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1117 $order_field = defaults($_GET, 'order', '');
1118 if ($order_field === 'posted') {
1124 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1125 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1126 ANY_VALUE(`created`) as `created`
1127 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1128 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1131 intval($a->pager['start']),
1132 intval($a->pager['itemspage'])
1136 if ($cmd === 'edit') {
1137 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos'))) {
1139 $edit_tpl = get_markup_template('album_edit.tpl');
1143 $o .= replace_macros($edit_tpl,[
1144 '$nametext' => L10n::t('New album name: '),
1145 '$nickname' => $a->data['user']['nickname'],
1146 '$album' => $album_e,
1147 '$hexalbum' => bin2hex($album),
1148 '$submit' => L10n::t('Submit'),
1149 '$dropsubmit' => L10n::t('Delete Album')
1154 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos')) && $can_post) {
1155 $edit = [L10n::t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1159 if ($order_field === 'posted') {
1160 $order = [L10n::t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album)];
1162 $order = [L10n::t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted'];
1167 if (DBM::is_result($r)) {
1168 // "Twist" is only used for the duepunto theme with style "slackr"
1170 foreach ($r as $rr) {
1173 $ext = $phototypes[$rr['type']];
1175 $imgalt_e = $rr['filename'];
1176 $desc_e = $rr['desc'];
1180 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1181 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1182 . ($order_field === 'posted' ? '?f=&order=posted' : ''),
1183 'title' => L10n::t('View Photo'),
1184 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1188 'hash'=> $rr['resource-id'],
1193 $tpl = get_markup_template('photo_album.tpl');
1194 $o .= replace_macros($tpl, [
1195 '$photos' => $photos,
1197 '$can_post' => $can_post,
1198 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)],
1201 '$paginate' => paginate($a),
1208 // Display one photo
1209 if ($datatype === 'image') {
1210 // fetch image, item containing image, then comments
1211 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1212 $sql_extra ORDER BY `scale` ASC ",
1217 if (!DBM::is_result($ph)) {
1218 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1223 if (DBM::is_result($ph)) {
1224 notice(L10n::t('Permission denied. Access to this item may be restricted.'));
1226 notice(L10n::t('Photo not available') . EOL );
1235 * @todo This query is totally bad, the whole functionality has to be changed
1236 * The query leads to a really intense used index.
1237 * By now we hide it if someone wants to.
1239 if (!Config::get('system', 'no_count', false)) {
1240 $order_field = defaults($_GET, 'order', '');
1241 if ($order_field === 'posted') {
1247 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1248 $sql_extra ORDER BY `created` $order ",
1249 dbesc($ph[0]['album']),
1253 if (DBM::is_result($prvnxt)) {
1254 foreach ($prvnxt as $z => $entry) {
1255 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1259 $prv = count($prvnxt) - 1;
1261 if ($nxt >= count($prvnxt)) {
1267 $edit_suffix = ((($cmd === 'edit') && $can_post) ? '/edit' : '');
1268 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1269 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1273 if (count($ph) == 1) {
1274 $hires = $lores = $ph[0];
1277 if (count($ph) > 1) {
1278 if ($ph[1]['scale'] == 2) {
1279 // original is 640 or less, we can display it directly
1280 $hires = $lores = $ph[0];
1287 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1292 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1294 'edit' => ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? L10n::t('View photo') : L10n::t('Edit photo'))],
1295 'profile'=>['profile_photo/use/'.$ph[0]['resource-id'], L10n::t('Use as profile photo')],
1299 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1300 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1301 ? L10n::t('Private Message')
1307 if ( $cmd === 'edit') {
1308 $tpl = get_markup_template('photo_edit_head.tpl');
1309 $a->page['htmlhead'] .= replace_macros($tpl,[
1310 '$prevlink' => $prevlink,
1311 '$nextlink' => $nextlink
1316 $prevlink = [$prevlink, '<div class="icon prev"></div>'] ;
1320 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1321 'title'=> L10n::t('View Full Size'),
1322 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . DateTimeFormat::utcNow('ymdhis'),
1323 'height' => $hires['height'],
1324 'width' => $hires['width'],
1325 'album' => $hires['album'],
1326 'filename' => $hires['filename'],
1330 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1334 // Do we have an item for this photo?
1336 // FIXME! - replace following code to display the conversation with our normal
1337 // conversation functions so that it works correctly and tracks changes
1338 // in the evolving conversation code.
1339 // The difference is that we won't be displaying the conversation head item
1340 // as a "post" but displaying instead the photo it is linked to
1342 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1349 if (DBM::is_result($linked_items)) {
1350 $link_item = $linked_items[0];
1352 $r = q("SELECT COUNT(*) AS `total`
1353 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1354 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1355 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1356 AND `item`.`uid` = %d
1358 dbesc($link_item['uri']),
1359 dbesc($link_item['uri']),
1360 intval($link_item['uid'])
1364 if (DBM::is_result($r)) {
1365 $a->set_pager_total($r[0]['total']);
1369 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1370 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1371 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1372 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1373 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1374 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1375 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1376 AND `item`.`uid` = %d
1378 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1379 dbesc($link_item['uri']),
1380 dbesc($link_item['uri']),
1381 intval($link_item['uid']),
1382 intval($a->pager['start']),
1383 intval($a->pager['itemspage'])
1387 if (local_user() && (local_user() == $link_item['uid'])) {
1388 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1391 if ($link_item['coord']) {
1392 $map = Map::byCoordinates($link_item['coord']);
1398 if (count($linked_items) && strlen($link_item['tag'])) {
1399 $arr = explode(',', $link_item['tag']);
1400 // parse tags and add links
1402 foreach ($arr as $t) {
1403 if (strlen($tag_str)) {
1406 $tag_str .= BBCode::convert($t);
1408 $tags = [L10n::t('Tags: '), $tag_str];
1409 if ($cmd === 'edit') {
1410 $tags[] = 'tagrm/' . $link_item['id'];
1411 $tags[] = L10n::t('[Remove any tag]');
1417 if ($cmd === 'edit' && $can_post) {
1418 $edit_tpl = get_markup_template('photo_edit.tpl');
1420 $album_e = $ph[0]['album'];
1421 $caption_e = $ph[0]['desc'];
1422 $aclselect_e = ACL::getFullSelectorHTML($ph[0]);
1424 $edit = replace_macros($edit_tpl, [
1425 '$id' => $ph[0]['id'],
1426 '$album' => ['albname', L10n::t('New album name'), $album_e,''],
1427 '$caption' => ['desc', L10n::t('Caption'), $caption_e, ''],
1428 '$tags' => ['newtag', L10n::t('Add a Tag'), "", L10n::t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1429 '$rotate_none' => ['rotate', L10n::t('Do not rotate'),0,'', true],
1430 '$rotate_cw' => ['rotate', L10n::t("Rotate CW \x28right\x29"),1,''],
1431 '$rotate_ccw' => ['rotate', L10n::t("Rotate CCW \x28left\x29"),2,''],
1433 '$nickname' => $a->data['user']['nickname'],
1434 '$resource_id' => $ph[0]['resource-id'],
1435 '$permissions' => L10n::t('Permissions'),
1436 '$aclselect' => $aclselect_e,
1438 '$item_id' => defaults($link_item, 'id', 0),
1439 '$submit' => L10n::t('Submit'),
1440 '$delete' => L10n::t('Delete Photo'),
1442 // ACL permissions box
1443 '$group_perms' => L10n::t('Show to Groups'),
1444 '$contact_perms' => L10n::t('Show to Contacts'),
1445 '$return_path' => $a->query_string,
1456 if (count($linked_items)) {
1457 $cmnt_tpl = get_markup_template('comment_item.tpl');
1458 $tpl = get_markup_template('photo_item.tpl');
1459 $return_url = $a->cmd;
1461 if ($can_post || can_write_wall($owner_uid)) {
1462 $like_tpl = get_markup_template('like_noshare.tpl');
1463 $likebuttons = replace_macros($like_tpl, [
1464 '$id' => $link_item['id'],
1465 '$likethis' => L10n::t("I like this \x28toggle\x29"),
1466 '$nolike' => (Feature::isEnabled(local_user(), 'dislike') ? L10n::t("I don't like this \x28toggle\x29") : ''),
1467 '$wait' => L10n::t('Please wait'),
1468 '$return_path' => $a->query_string,
1472 if (!DBM::is_result($r)) {
1473 if (($can_post || can_write_wall($owner_uid))) {
1474 $comments .= replace_macros($cmnt_tpl, [
1475 '$return_path' => '',
1476 '$jsreload' => $return_url,
1477 '$type' => 'wall-comment',
1478 '$id' => $link_item['id'],
1479 '$parent' => $link_item['id'],
1480 '$profile_uid' => $owner_uid,
1481 '$mylink' => $contact['url'],
1482 '$mytitle' => L10n::t('This is you'),
1483 '$myphoto' => $contact['thumb'],
1484 '$comment' => L10n::t('Comment'),
1485 '$submit' => L10n::t('Submit'),
1486 '$preview' => L10n::t('Preview'),
1487 '$sourceapp' => L10n::t($a->sourcename),
1489 '$rand_num' => random_digits(12)
1495 'like' => ['title' => L10n::t('Likes','title')],'dislike' => ['title' => L10n::t('Dislikes','title')],
1496 'attendyes' => ['title' => L10n::t('Attending','title')], 'attendno' => ['title' => L10n::t('Not attending','title')], 'attendmaybe' => ['title' => L10n::t('Might attend','title')]
1500 if (DBM::is_result($r)) {
1501 foreach ($r as $item) {
1502 builtin_activity_puller($item, $conv_responses);
1505 if (x($conv_responses['like'], $link_item['uri'])) {
1506 $like = format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like', $link_item['id']);
1508 if (x($conv_responses['dislike'], $link_item['uri'])) {
1509 $dislike = format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike', $link_item['id']);
1512 if (($can_post || can_write_wall($owner_uid))) {
1513 $comments .= replace_macros($cmnt_tpl,[
1514 '$return_path' => '',
1515 '$jsreload' => $return_url,
1516 '$type' => 'wall-comment',
1517 '$id' => $link_item['id'],
1518 '$parent' => $link_item['id'],
1519 '$profile_uid' => $owner_uid,
1520 '$mylink' => $contact['url'],
1521 '$mytitle' => L10n::t('This is you'),
1522 '$myphoto' => $contact['thumb'],
1523 '$comment' => L10n::t('Comment'),
1524 '$submit' => L10n::t('Submit'),
1525 '$preview' => L10n::t('Preview'),
1526 '$sourceapp' => L10n::t($a->sourcename),
1528 '$rand_num' => random_digits(12)
1532 foreach ($r as $item) {
1537 if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) {
1541 $profile_url = Contact::MagicLinkById($item['cid']);
1542 if (strpos($profile_url, 'redir/') === 0) {
1543 $sparkle = ' sparkle';
1548 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1550 $profile_name = ((strlen($item['author-name']) && $diff_author) ? $item['author-name'] : $item['name']);
1551 $profile_avatar = ((strlen($item['author-avatar']) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1553 $profile_link = $profile_url;
1555 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1557 'dropping' => $dropping,
1558 'pagedrop' => false,
1559 'select' => L10n::t('Select'),
1560 'delete' => L10n::t('Delete'),
1563 $name_e = $profile_name;
1564 $title_e = $item['title'];
1565 $body_e = BBCode::convert($item['body']);
1567 $comments .= replace_macros($template,[
1568 '$id' => $item['item_id'],
1569 '$profile_url' => $profile_link,
1571 '$thumb' => $profile_avatar,
1572 '$sparkle' => $sparkle,
1573 '$title' => $title_e,
1575 '$ago' => Temporal::getRelativeDate($item['created']),
1576 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1578 '$comment' => $comment
1581 if (($can_post || can_write_wall($owner_uid))) {
1582 $comments .= replace_macros($cmnt_tpl, [
1583 '$return_path' => '',
1584 '$jsreload' => $return_url,
1585 '$type' => 'wall-comment',
1586 '$id' => $item['item_id'],
1587 '$parent' => $item['parent'],
1588 '$profile_uid' => $owner_uid,
1589 '$mylink' => $contact['url'],
1590 '$mytitle' => L10n::t('This is you'),
1591 '$myphoto' => $contact['thumb'],
1592 '$comment' => L10n::t('Comment'),
1593 '$submit' => L10n::t('Submit'),
1594 '$preview' => L10n::t('Preview'),
1595 '$sourceapp' => L10n::t($a->sourcename),
1597 '$rand_num' => random_digits(12)
1602 $response_verbs = ['like'];
1603 if (Feature::isEnabled($owner_uid, 'dislike')) {
1604 $response_verbs[] = 'dislike';
1606 $responses = get_responses($conv_responses, $response_verbs, '', $link_item);
1608 $paginate = paginate($a);
1611 $photo_tpl = get_markup_template('photo_view.tpl');
1612 $o .= replace_macros($photo_tpl, [
1613 '$id' => $ph[0]['id'],
1614 '$album' => [$album_link, $ph[0]['album']],
1618 '$prevlink' => $prevlink,
1619 '$nextlink' => $nextlink,
1620 '$desc' => $ph[0]['desc'],
1624 '$map_text' => L10n::t('Map'),
1625 '$likebuttons' => $likebuttons,
1627 '$dislike' => $dislike,
1628 'responses' => $responses,
1629 '$comments' => $comments,
1630 '$paginate' => $paginate,
1633 $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="photo" />' . "\n";
1634 $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1635 $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . $photo["href"] . '" />' . "\n";
1636 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1637 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1642 // Default - show recent photos with upload link (if applicable)
1645 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1646 $sql_extra GROUP BY `resource-id`",
1647 intval($a->data['user']['uid']),
1648 dbesc('Contact Photos'),
1649 dbesc(L10n::t('Contact Photos'))
1651 if (DBM::is_result($r)) {
1652 $a->set_pager_total(count($r));
1653 $a->set_pager_itemspage(20);
1656 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1657 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1658 ANY_VALUE(`created`) AS `created` FROM `photo`
1659 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1660 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1661 intval($a->data['user']['uid']),
1662 dbesc('Contact Photos'),
1663 dbesc(L10n::t('Contact Photos')),
1664 intval($a->pager['start']),
1665 intval($a->pager['itemspage'])
1669 if (DBM::is_result($r)) {
1670 // "Twist" is only used for the duepunto theme with style "slackr"
1672 foreach ($r as $rr) {
1673 //hide profile photos to others
1674 if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos'))) {
1680 $ext = $phototypes[$rr['type']];
1682 $alt_e = $rr['filename'];
1683 $name_e = $rr['album'];
1687 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1688 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1689 'title' => L10n::t('View Photo'),
1690 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1693 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1695 'alt' => L10n::t('View Album'),
1702 $tpl = get_markup_template('photos_recent.tpl');
1703 $o .= replace_macros($tpl, [
1704 '$title' => L10n::t('Recent Photos'),
1705 '$can_post' => $can_post,
1706 '$upload' => [L10n::t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'],
1707 '$photos' => $photos,
1708 '$paginate' => paginate($a),