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\DBA;
17 use Friendica\Database\DBM;
18 use Friendica\Model\Contact;
19 use Friendica\Model\Group;
20 use Friendica\Model\Item;
21 use Friendica\Model\Photo;
22 use Friendica\Model\Profile;
23 use Friendica\Model\User;
24 use Friendica\Network\Probe;
25 use Friendica\Object\Image;
26 use Friendica\Protocol\DFRN;
27 use Friendica\Util\DateTimeFormat;
28 use Friendica\Util\Map;
29 use Friendica\Util\Temporal;
31 require_once 'include/items.php';
32 require_once 'include/security.php';
34 function photos_init(App $a) {
37 DFRN::autoRedir($a, $a->argv[1]);
40 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
44 Nav::setSelected('home');
48 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
52 if (!DBM::is_result($user)) {
56 $a->data['user'] = $user[0];
57 $a->profile_uid = $user[0]['uid'];
58 $is_owner = (local_user() && (local_user() == $a->profile_uid));
60 $profile = Profile::getByNickname($nick, $a->profile_uid);
62 $account_type = Contact::getAccountType($profile);
64 $tpl = get_markup_template("vcard-widget.tpl");
66 $vcard_widget = replace_macros($tpl, [
67 '$name' => $profile['name'],
68 '$photo' => $profile['photo'],
69 '$addr' => defaults($profile, 'addr', ''),
70 '$account_type' => $account_type,
71 '$pdesc' => defaults($profile, 'pdesc', ''),
74 $albums = Photo::getAlbums($a->data['user']['uid']);
76 $albums_visible = ((intval($a->data['user']['hidewall']) && !local_user() && !remote_user()) ? false : true);
78 // add various encodings to the array so we can just loop through and pick them out in a template
79 $ret = ['success' => false];
82 $a->data['albums'] = $albums;
83 if ($albums_visible) {
84 $ret['success'] = true;
88 foreach ($albums as $k => $album) {
89 //hide profile photos to others
90 if (!$is_owner && !remote_user() && ($album['album'] == L10n::t('Profile Photos')))
93 'text' => $album['album'],
94 'total' => $album['total'],
95 'url' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
96 'urlencode' => urlencode($album['album']),
97 'bin2hex' => bin2hex($album['album'])
99 $ret['albums'][] = $entry;
103 if (local_user() && $a->data['user']['uid'] == local_user()) {
109 if ($ret['success']) {
110 $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'), [
111 '$nick' => $a->data['user']['nickname'],
112 '$title' => L10n::t('Photo Albums'),
113 '$recent' => L10n::t('Recent Photos'),
114 '$albums' => $ret['albums'],
115 '$baseurl' => System::baseUrl(),
116 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'],
117 '$can_post' => $can_post
122 if (!x($a->page, 'aside')) {
123 $a->page['aside'] = '';
125 $a->page['aside'] .= $vcard_widget;
126 $a->page['aside'] .= $photo_albums_widget;
128 $tpl = get_markup_template("photos_head.tpl");
129 $a->page['htmlhead'] .= replace_macros($tpl,[
130 '$ispublic' => L10n::t('everybody')
137 function photos_post(App $a)
139 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
140 logger('mod_photos: REQUEST ' . print_r($_REQUEST, true), LOGGER_DATA);
141 logger('mod_photos: FILES ' . print_r($_FILES, true), LOGGER_DATA);
143 $phototypes = Image::supportedTypes();
148 $page_owner_uid = $a->data['user']['uid'];
149 $community_page = $a->data['user']['page-flags'] == PAGE_COMMUNITY;
151 if (local_user() && (local_user() == $page_owner_uid)) {
154 if ($community_page && remote_user()) {
156 if (x($_SESSION, 'remote') && is_array($_SESSION['remote'])) {
157 foreach ($_SESSION['remote'] as $v) {
158 if ($v['uid'] == $page_owner_uid) {
159 $contact_id = $v['cid'];
165 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
167 intval($page_owner_uid)
169 if (DBM::is_result($r)) {
171 $visitor = $contact_id;
178 notice(L10n::t('Permission denied.') . EOL);
182 $owner_record = User::getOwnerDataById($page_owner_uid);
184 if (!$owner_record) {
185 notice(L10n::t('Contact information unavailable') . EOL);
186 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
190 if ($a->argc > 3 && $a->argv[2] === 'album') {
191 $album = hex2bin($a->argv[3]);
193 if ($album === L10n::t('Profile Photos') || $album === 'Contact Photos' || $album === L10n::t('Contact Photos')) {
194 goaway($_SESSION['photo_return']);
195 return; // NOTREACHED
198 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
200 intval($page_owner_uid)
202 if (!DBM::is_result($r)) {
203 notice(L10n::t('Album not found.') . EOL);
204 goaway($_SESSION['photo_return']);
205 return; // NOTREACHED
208 // Check if the user has responded to a delete confirmation query
209 if ($_REQUEST['canceled']) {
210 goaway($_SESSION['photo_return']);
213 // RENAME photo album
214 $newalbum = notags(trim($_POST['albumname']));
215 if ($newalbum != $album) {
216 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
219 intval($page_owner_uid)
221 // Update the photo albums cache
222 Photo::clearAlbumCache($page_owner_uid);
224 $newurl = System::baseUrl() . '/photos/' . $a->user['nickname'] . '/album/' . bin2hex($newalbum);
226 return; // NOTREACHED
230 * DELETE photo album and all its photos
233 if ($_POST['dropalbum'] == L10n::t('Delete Album')) {
234 // Check if we should do HTML-based delete confirmation
235 if (x($_REQUEST, 'confirm')) {
236 $drop_url = $a->query_string;
238 ['name' => 'albumname', 'value' => $_POST['albumname']],
240 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
242 '$message' => L10n::t('Do you really want to delete this photo album and all its photos?'),
243 '$extra_inputs' => $extra_inputs,
244 '$confirm' => L10n::t('Delete Album'),
245 '$confirm_url' => $drop_url,
246 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
247 '$cancel' => L10n::t('Cancel'),
249 $a->error = 1; // Set $a->error so the other module functions don't execute
255 // get the list of photos we are about to delete
258 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
260 intval($page_owner_uid),
264 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
265 intval(local_user()),
269 if (DBM::is_result($r)) {
270 foreach ($r as $rr) {
271 $res[] = "'" . dbesc($rr['rid']) . "'" ;
274 goaway($_SESSION['photo_return']);
275 return; // NOTREACHED
278 $str_res = implode(',', $res);
280 // remove the associated photos
281 q("DELETE FROM `photo` WHERE `resource-id` IN ($str_res) AND `uid` = %d",
282 intval($page_owner_uid)
285 // find and delete the corresponding item with all the comments and likes/dislikes
286 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
288 // Update the photo albums cache
289 Photo::clearAlbumCache($page_owner_uid);
292 goaway('photos/' . $a->data['user']['nickname']);
293 return; // NOTREACHED
297 // Check if the user has responded to a delete confirmation query for a single photo
298 if ($a->argc > 2 && x($_REQUEST, 'canceled')) {
299 goaway($_SESSION['photo_return']);
302 if ($a->argc > 2 && defaults($_POST, 'delete', '') === L10n::t('Delete Photo')) {
304 // same as above but remove single photo
306 // Check if we should do HTML-based delete confirmation
307 if (x($_REQUEST, 'confirm')) {
308 $drop_url = $a->query_string;
309 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
311 '$message' => L10n::t('Do you really want to delete this photo?'),
312 '$extra_inputs' => [],
313 '$confirm' => L10n::t('Delete Photo'),
314 '$confirm_url' => $drop_url,
315 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
316 '$cancel' => L10n::t('Cancel'),
318 $a->error = 1; // Set $a->error so the other module functions don't execute
323 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
325 intval($page_owner_uid),
329 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
330 intval(local_user()),
334 if (DBM::is_result($r)) {
335 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
336 intval($page_owner_uid),
337 dbesc($r[0]['resource-id'])
340 Item::deleteForUser(['resource-id' => $r[0]['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
342 // Update the photo albums cache
343 Photo::clearAlbumCache($page_owner_uid);
346 goaway('photos/' . $a->data['user']['nickname']);
347 return; // NOTREACHED
350 if ($a->argc > 2 && (x($_POST, 'desc') !== false || x($_POST, 'newtag') !== false || x($_POST, 'albname') !== false)) {
351 $desc = !empty($_POST['desc']) ? notags(trim($_POST['desc'])) : '';
352 $rawtags = !empty($_POST['newtag']) ? notags(trim($_POST['newtag'])) : '';
353 $item_id = !empty($_POST['item_id']) ? intval($_POST['item_id']) : 0;
354 $albname = !empty($_POST['albname']) ? notags(trim($_POST['albname'])) : '';
355 $origaname = !empty($_POST['origaname']) ? notags(trim($_POST['origaname'])) : '';
357 $str_group_allow = !empty($_POST['group_allow']) ? perms2str($_POST['group_allow']) : '';
358 $str_contact_allow = !empty($_POST['contact_allow']) ? perms2str($_POST['contact_allow']) : '';
359 $str_group_deny = !empty($_POST['group_deny']) ? perms2str($_POST['group_deny']) : '';
360 $str_contact_deny = !empty($_POST['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::newURI($page_owner_uid);
460 $arr['guid'] = System::createGUID(32);
461 $arr['uid'] = $page_owner_uid;
463 $arr['parent-uri'] = $uri;
464 $arr['post-type'] = Item::PT_IMAGE;
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 $item = Item::selectFirst(['tag', 'inform'], ['id' => $item_id, 'uid' => $page_owner_uid]);
492 if (DBM::is_result($item)) {
493 $old_tag = $item['tag'];
494 $old_inform = $item['inform'];
497 if (strlen($rawtags)) {
501 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
502 $x = substr($rawtags, 0, 1);
503 if ($x !== '@' && $x !== '#') {
504 $rawtags = '#' . $rawtags;
508 $tags = get_tags($rawtags);
511 foreach ($tags as $tag) {
512 if (strpos($tag, '@') === 0) {
514 $name = substr($tag,1);
515 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
517 $links = @Probe::lrdd($name);
519 foreach ($links as $link) {
520 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
521 $profile = $link['@attributes']['href'];
523 if ($link['@attributes']['rel'] === 'salmon') {
524 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
525 if (strlen($inform)) {
532 $taginfo[] = [$newname, $profile, $salmon];
537 if (strrpos($newname, '+')) {
538 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
542 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
547 $newname = str_replace('_',' ',$name);
549 //select someone from this user's contacts by name
550 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
552 intval($page_owner_uid)
555 if (!DBM::is_result($r)) {
556 //select someone by attag or nick and the name passed in
557 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
560 intval($page_owner_uid)
565 if (DBM::is_result($r)) {
566 $newname = $r[0]['name'];
567 $profile = $r[0]['url'];
568 $notify = 'cid:' . $r[0]['id'];
569 if (strlen($inform)) {
576 if (substr($notify, 0, 4) === 'cid:') {
577 $taginfo[] = [$newname, $profile, $notify, $r[0], '@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]'];
579 $taginfo[] = [$newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'];
581 if (strlen($str_tags)) {
584 $profile = str_replace(',', '%2c', $profile);
585 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
587 } elseif (strpos($tag, '#') === 0) {
588 $tagname = substr($tag, 1);
589 $str_tags .= '#[url=' . System::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url]';
595 if (strlen($newtag) && strlen($str_tags)) {
598 $newtag .= $str_tags;
600 $newinform = $old_inform;
601 if (strlen($newinform) && strlen($inform)) {
604 $newinform .= $inform;
606 $fields = ['tag' => $newtag, 'inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
607 $condition = ['id' => $item_id];
608 Item::update($fields, $condition);
611 foreach ($p as $scales) {
612 if (intval($scales['scale']) == 2) {
616 if (intval($scales['scale']) == 4) {
622 if (count($taginfo)) {
623 foreach ($taginfo as $tagged) {
624 $uri = Item::newURI($page_owner_uid);
627 $arr['guid'] = System::createGUID(32);
628 $arr['uid'] = $page_owner_uid;
630 $arr['parent-uri'] = $uri;
632 $arr['contact-id'] = $owner_record['id'];
633 $arr['owner-name'] = $owner_record['name'];
634 $arr['owner-link'] = $owner_record['url'];
635 $arr['owner-avatar'] = $owner_record['thumb'];
636 $arr['author-name'] = $owner_record['name'];
637 $arr['author-link'] = $owner_record['url'];
638 $arr['author-avatar'] = $owner_record['thumb'];
640 $arr['allow_cid'] = $p[0]['allow_cid'];
641 $arr['allow_gid'] = $p[0]['allow_gid'];
642 $arr['deny_cid'] = $p[0]['deny_cid'];
643 $arr['deny_gid'] = $p[0]['deny_gid'];
645 $arr['verb'] = ACTIVITY_TAG;
646 $arr['gravity'] = GRAVITY_PARENT;
647 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
648 $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
649 $arr['tag'] = $tagged[4];
650 $arr['inform'] = $tagged[2];
652 $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]') ;
653 $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" ;
655 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
656 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
658 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
660 $arr['object'] .= '</link></object>' . "\n";
662 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $p[0]['desc'] . '</title><id>'
663 . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
664 $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>';
666 $item_id = Item::insert($arr);
668 Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
673 goaway($_SESSION['photo_return']);
674 return; // NOTREACHED
678 // default post action - upload a photo
679 Addon::callHooks('photo_post_init', $_POST);
681 // Determine the album to use
682 $album = x($_REQUEST, 'album') ? notags(trim($_REQUEST['album'])) : '';
683 $newalbum = x($_REQUEST, 'newalbum') ? notags(trim($_REQUEST['newalbum'])) : '';
685 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
687 if (!strlen($album)) {
688 if (strlen($newalbum)) {
691 $album = DateTimeFormat::localNow('Y');
696 * We create a wall item for every photo, but we don't want to
697 * overwhelm the data stream with a hundred newly uploaded photos.
698 * So we will make the first photo uploaded to this album in the last several hours
699 * visible by default, the rest will become visible over time when and if
700 * they acquire comments, likes, dislikes, and/or tags
703 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
705 intval($page_owner_uid)
708 if (!DBM::is_result($r) || ($album == L10n::t('Profile Photos'))) {
714 if (!empty($_REQUEST['not_visible']) && $_REQUEST['not_visible'] !== 'false') {
718 $group_allow = defaults($_REQUEST, 'group_allow' , []);
719 $contact_allow = defaults($_REQUEST, 'contact_allow', []);
720 $group_deny = defaults($_REQUEST, 'group_deny' , []);
721 $contact_deny = defaults($_REQUEST, 'contact_deny' , []);
723 $str_group_allow = perms2str(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
724 $str_contact_allow = perms2str(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
725 $str_group_deny = perms2str(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
726 $str_contact_deny = perms2str(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
728 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
730 Addon::callHooks('photo_post_file', $ret);
732 if (x($ret, 'src') && x($ret, 'filesize')) {
734 $filename = $ret['filename'];
735 $filesize = $ret['filesize'];
736 $type = $ret['type'];
737 $error = UPLOAD_ERR_OK;
739 $src = $_FILES['userfile']['tmp_name'];
740 $filename = basename($_FILES['userfile']['name']);
741 $filesize = intval($_FILES['userfile']['size']);
742 $type = $_FILES['userfile']['type'];
743 $error = $_FILES['userfile']['error'];
746 if ($error !== UPLOAD_ERR_OK) {
748 case UPLOAD_ERR_INI_SIZE:
749 notice(L10n::t('Image exceeds size limit of %s', ini_get('upload_max_filesize')) . EOL);
751 case UPLOAD_ERR_FORM_SIZE:
752 notice(L10n::t('Image exceeds size limit of %s', formatBytes(defaults($_REQUEST, 'MAX_FILE_SIZE', 0))) . EOL);
754 case UPLOAD_ERR_PARTIAL:
755 notice(L10n::t('Image upload didn\'t complete, please try again') . EOL);
757 case UPLOAD_ERR_NO_FILE:
758 notice(L10n::t('Image file is missing') . EOL);
760 case UPLOAD_ERR_NO_TMP_DIR:
761 case UPLOAD_ERR_CANT_WRITE:
762 case UPLOAD_ERR_EXTENSION:
763 notice(L10n::t('Server can\'t accept new file upload at this time, please contact your administrator') . EOL);
768 Addon::callHooks('photo_post_end', $foo);
773 $type = Image::guessType($filename);
776 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
778 $maximagesize = Config::get('system', 'maximagesize');
780 if ($maximagesize && ($filesize > $maximagesize)) {
781 notice(L10n::t('Image exceeds size limit of %s', formatBytes($maximagesize)) . EOL);
784 Addon::callHooks('photo_post_end', $foo);
789 notice(L10n::t('Image file is empty.') . EOL);
792 Addon::callHooks('photo_post_end', $foo);
796 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
798 $imagedata = @file_get_contents($src);
800 $Image = new Image($imagedata, $type);
802 if (!$Image->isValid()) {
803 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
804 notice(L10n::t('Unable to process image.') . EOL);
807 Addon::callHooks('photo_post_end',$foo);
811 $exif = $Image->orient($src);
814 $max_length = Config::get('system', 'max_image_length');
816 $max_length = MAX_IMAGE_LENGTH;
818 if ($max_length > 0) {
819 $Image->scaleDown($max_length);
822 $width = $Image->getWidth();
823 $height = $Image->getHeight();
827 $photo_hash = Photo::newResource();
829 $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);
832 logger('mod/photos.php: photos_post(): image store failed', LOGGER_DEBUG);
833 notice(L10n::t('Image upload failed.') . EOL);
837 if ($width > 640 || $height > 640) {
838 $Image->scaleDown(640);
839 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);
843 if ($width > 320 || $height > 320) {
844 $Image->scaleDown(320);
845 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);
849 $uri = Item::newURI($page_owner_uid);
851 // Create item container
853 if ($exif && $exif['GPS'] && Feature::isEnabled($page_owner_uid, 'photo_location')) {
854 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
855 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
860 $arr['coord'] = $lat . ' ' . $lon;
863 $arr['guid'] = System::createGUID(32);
864 $arr['uid'] = $page_owner_uid;
866 $arr['parent-uri'] = $uri;
867 $arr['type'] = 'photo';
869 $arr['resource-id'] = $photo_hash;
870 $arr['contact-id'] = $owner_record['id'];
871 $arr['owner-name'] = $owner_record['name'];
872 $arr['owner-link'] = $owner_record['url'];
873 $arr['owner-avatar'] = $owner_record['thumb'];
874 $arr['author-name'] = $owner_record['name'];
875 $arr['author-link'] = $owner_record['url'];
876 $arr['author-avatar'] = $owner_record['thumb'];
878 $arr['allow_cid'] = $str_contact_allow;
879 $arr['allow_gid'] = $str_group_allow;
880 $arr['deny_cid'] = $str_contact_deny;
881 $arr['deny_gid'] = $str_group_deny;
882 $arr['visible'] = $visible;
885 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
886 . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$Image->getExt() . '[/img]'
889 $item_id = Item::insert($arr);
890 // Update the photo albums cache
891 Photo::clearAlbumCache($page_owner_uid);
894 Worker::add(PRIORITY_HIGH, "Notifier", 'wall-new', $item_id);
897 Addon::callHooks('photo_post_end', intval($item_id));
899 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
900 // if they do not wish to be redirected
902 goaway($_SESSION['photo_return']);
906 function photos_content(App $a)
910 // photos/name/upload
911 // photos/name/upload/xxxxx (xxxxx is album name)
912 // photos/name/album/xxxxx
913 // photos/name/album/xxxxx/edit
914 // photos/name/image/xxxxx
915 // photos/name/image/xxxxx/edit
917 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
918 notice(L10n::t('Public access denied.') . EOL);
922 require_once 'include/security.php';
923 require_once 'include/conversation.php';
925 if (empty($a->data['user'])) {
926 notice(L10n::t('No photos selected') . EOL);
930 $phototypes = Image::supportedTypes();
932 $_SESSION['photo_return'] = $a->cmd;
937 $datatype = $a->argv[2];
938 $datum = $a->argv[3];
939 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
940 $datatype = 'upload';
942 $datatype = 'summary';
951 // Setup permissions structures
955 $remote_contact = false;
959 $owner_uid = $a->data['user']['uid'];
961 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
963 if (local_user() && (local_user() == $owner_uid)) {
966 if ($community_page && remote_user()) {
967 if (is_array($_SESSION['remote'])) {
968 foreach ($_SESSION['remote'] as $v) {
969 if ($v['uid'] == $owner_uid) {
970 $contact_id = $v['cid'];
977 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
981 if (DBM::is_result($r)) {
984 $remote_contact = true;
985 $visitor = $contact_id;
993 // perhaps they're visiting - but not a community page, so they wouldn't have write access
994 if (remote_user() && !$visitor) {
996 if (is_array($_SESSION['remote'])) {
997 foreach ($_SESSION['remote'] as $v) {
998 if ($v['uid'] == $owner_uid) {
999 $contact_id = $v['cid'];
1005 $groups = Group::getIdsByContactId($contact_id);
1006 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1007 intval($contact_id),
1010 if (DBM::is_result($r)) {
1012 $remote_contact = true;
1017 if (!$remote_contact && local_user()) {
1018 $contact_id = $_SESSION['cid'];
1019 $contact = $a->contact;
1022 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
1023 notice(L10n::t('Access to this item is restricted.') . EOL);
1027 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
1032 $is_owner = (local_user() && (local_user() == $owner_uid));
1033 $o .= Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
1035 // Display upload form
1036 if ($datatype === 'upload') {
1038 notice(L10n::t('Permission denied.'));
1042 $selname = $datum ? hex2bin($datum) : '';
1046 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '><current year></option>';
1047 if (count($a->data['albums'])) {
1048 foreach ($a->data['albums'] as $album) {
1049 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos'))) {
1052 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1053 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1059 $ret = ['post_url' => 'photos/' . $a->data['user']['nickname'],
1060 'addon_text' => $uploader,
1061 'default_upload' => true];
1063 Addon::callHooks('photo_upload_form',$ret);
1065 $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), []);
1066 $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), [
1067 '$submit' => L10n::t('Submit'),
1070 $usage_message = '';
1072 $tpl = get_markup_template('photos_upload.tpl');
1074 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML($a->user));
1076 $o .= replace_macros($tpl,[
1077 '$pagename' => L10n::t('Upload Photos'),
1078 '$sessid' => session_id(),
1079 '$usage' => $usage_message,
1080 '$nickname' => $a->data['user']['nickname'],
1081 '$newalbum' => L10n::t('New album name: '),
1082 '$existalbumtext' => L10n::t('or select existing album:'),
1083 '$nosharetext' => L10n::t('Do not show a status post for this upload'),
1084 '$albumselect' => $albumselect,
1085 '$permissions' => L10n::t('Permissions'),
1086 '$aclselect' => $aclselect_e,
1087 '$alt_uploader' => $ret['addon_text'],
1088 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
1089 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
1090 '$uploadurl' => $ret['post_url'],
1092 // ACL permissions box
1093 '$group_perms' => L10n::t('Show to Groups'),
1094 '$contact_perms' => L10n::t('Show to Contacts'),
1095 '$return_path' => $a->query_string,
1101 // Display a single photo album
1102 if ($datatype === 'album') {
1103 $album = hex2bin($datum);
1105 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1106 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1110 if (DBM::is_result($r)) {
1111 $a->set_pager_total(count($r));
1112 $a->set_pager_itemspage(20);
1115 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1116 $order_field = defaults($_GET, 'order', '');
1117 if ($order_field === 'posted') {
1123 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1124 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1125 ANY_VALUE(`created`) as `created`
1126 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1127 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1130 intval($a->pager['start']),
1131 intval($a->pager['itemspage'])
1135 if ($cmd === 'edit') {
1136 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos'))) {
1138 $edit_tpl = get_markup_template('album_edit.tpl');
1142 $o .= replace_macros($edit_tpl,[
1143 '$nametext' => L10n::t('New album name: '),
1144 '$nickname' => $a->data['user']['nickname'],
1145 '$album' => $album_e,
1146 '$hexalbum' => bin2hex($album),
1147 '$submit' => L10n::t('Submit'),
1148 '$dropsubmit' => L10n::t('Delete Album')
1153 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos')) && $can_post) {
1154 $edit = [L10n::t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1158 if ($order_field === 'posted') {
1159 $order = [L10n::t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1161 $order = [L10n::t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted', 'newest'];
1166 if (DBM::is_result($r)) {
1167 // "Twist" is only used for the duepunto theme with style "slackr"
1169 foreach ($r as $rr) {
1172 $ext = $phototypes[$rr['type']];
1174 $imgalt_e = $rr['filename'];
1175 $desc_e = $rr['desc'];
1179 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1180 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1181 . ($order_field === 'posted' ? '?f=&order=posted' : ''),
1182 'title' => L10n::t('View Photo'),
1183 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1187 'hash'=> $rr['resource-id'],
1192 $tpl = get_markup_template('photo_album.tpl');
1193 $o .= replace_macros($tpl, [
1194 '$photos' => $photos,
1196 '$can_post' => $can_post,
1197 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)],
1200 '$paginate' => paginate($a),
1207 // Display one photo
1208 if ($datatype === 'image') {
1209 // fetch image, item containing image, then comments
1210 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1211 $sql_extra ORDER BY `scale` ASC ",
1216 if (!DBM::is_result($ph)) {
1217 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1222 if (DBM::is_result($ph)) {
1223 notice(L10n::t('Permission denied. Access to this item may be restricted.'));
1225 notice(L10n::t('Photo not available') . EOL);
1234 * @todo This query is totally bad, the whole functionality has to be changed
1235 * The query leads to a really intense used index.
1236 * By now we hide it if someone wants to.
1238 if (!Config::get('system', 'no_count', false)) {
1239 $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 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1343 $linked_items = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1350 if (DBM::is_result($linked_items)) {
1351 // This is a workaround to not being forced to rewrite the while $sql_extra handling
1352 $link_item = Item::selectFirst([], ['id' => $linked_items[0]['id']]);
1354 $condition = ["`parent` = ? AND `parent` != `id`", $link_item['parent']];
1355 $a->set_pager_total(DBA::count('item', $condition));
1357 $params = ['order' => ['id'], 'limit' => [$a->pager['start'], $a->pager['itemspage']]];
1358 $result = Item::selectForUser($link_item['uid'], [], $condition, $params);
1359 $items = Item::inArray($result);
1361 if (local_user() && (local_user() == $link_item['uid'])) {
1362 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1365 if ($link_item['coord']) {
1366 $map = Map::byCoordinates($link_item['coord']);
1372 if (count($linked_items) && strlen($link_item['tag'])) {
1373 $arr = explode(',', $link_item['tag']);
1374 // parse tags and add links
1376 foreach ($arr as $t) {
1377 if (strlen($tag_str)) {
1380 $tag_str .= BBCode::convert($t);
1382 $tags = [L10n::t('Tags: '), $tag_str];
1383 if ($cmd === 'edit') {
1384 $tags[] = 'tagrm/' . $link_item['id'];
1385 $tags[] = L10n::t('[Remove any tag]');
1391 if ($cmd === 'edit' && $can_post) {
1392 $edit_tpl = get_markup_template('photo_edit.tpl');
1394 $album_e = $ph[0]['album'];
1395 $caption_e = $ph[0]['desc'];
1396 $aclselect_e = ACL::getFullSelectorHTML($ph[0]);
1398 $edit = replace_macros($edit_tpl, [
1399 '$id' => $ph[0]['id'],
1400 '$album' => ['albname', L10n::t('New album name'), $album_e,''],
1401 '$caption' => ['desc', L10n::t('Caption'), $caption_e, ''],
1402 '$tags' => ['newtag', L10n::t('Add a Tag'), "", L10n::t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1403 '$rotate_none' => ['rotate', L10n::t('Do not rotate'),0,'', true],
1404 '$rotate_cw' => ['rotate', L10n::t("Rotate CW \x28right\x29"),1,''],
1405 '$rotate_ccw' => ['rotate', L10n::t("Rotate CCW \x28left\x29"),2,''],
1407 '$nickname' => $a->data['user']['nickname'],
1408 '$resource_id' => $ph[0]['resource-id'],
1409 '$permissions' => L10n::t('Permissions'),
1410 '$aclselect' => $aclselect_e,
1412 '$item_id' => defaults($link_item, 'id', 0),
1413 '$submit' => L10n::t('Submit'),
1414 '$delete' => L10n::t('Delete Photo'),
1416 // ACL permissions box
1417 '$group_perms' => L10n::t('Show to Groups'),
1418 '$contact_perms' => L10n::t('Show to Contacts'),
1419 '$return_path' => $a->query_string,
1430 if (count($linked_items)) {
1431 $cmnt_tpl = get_markup_template('comment_item.tpl');
1432 $tpl = get_markup_template('photo_item.tpl');
1433 $return_url = $a->cmd;
1435 if ($can_post || can_write_wall($owner_uid)) {
1436 $like_tpl = get_markup_template('like_noshare.tpl');
1437 $likebuttons = replace_macros($like_tpl, [
1438 '$id' => $link_item['id'],
1439 '$likethis' => L10n::t("I like this \x28toggle\x29"),
1440 '$nolike' => (Feature::isEnabled(local_user(), 'dislike') ? L10n::t("I don't like this \x28toggle\x29") : ''),
1441 '$wait' => L10n::t('Please wait'),
1442 '$return_path' => $a->query_string,
1446 if (!DBM::is_result($items)) {
1447 if (($can_post || can_write_wall($owner_uid))) {
1448 $comments .= replace_macros($cmnt_tpl, [
1449 '$return_path' => '',
1450 '$jsreload' => $return_url,
1451 '$id' => $link_item['id'],
1452 '$parent' => $link_item['id'],
1453 '$profile_uid' => $owner_uid,
1454 '$mylink' => $contact['url'],
1455 '$mytitle' => L10n::t('This is you'),
1456 '$myphoto' => $contact['thumb'],
1457 '$comment' => L10n::t('Comment'),
1458 '$submit' => L10n::t('Submit'),
1459 '$preview' => L10n::t('Preview'),
1460 '$sourceapp' => L10n::t($a->sourcename),
1462 '$rand_num' => random_digits(12)
1468 'like' => ['title' => L10n::t('Likes','title')],'dislike' => ['title' => L10n::t('Dislikes','title')],
1469 'attendyes' => ['title' => L10n::t('Attending','title')], 'attendno' => ['title' => L10n::t('Not attending','title')], 'attendmaybe' => ['title' => L10n::t('Might attend','title')]
1473 if (DBM::is_result($items)) {
1474 foreach ($items as $item) {
1475 builtin_activity_puller($item, $conv_responses);
1478 if (x($conv_responses['like'], $link_item['uri'])) {
1479 $like = format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like', $link_item['id']);
1481 if (x($conv_responses['dislike'], $link_item['uri'])) {
1482 $dislike = format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike', $link_item['id']);
1485 if (($can_post || can_write_wall($owner_uid))) {
1486 $comments .= replace_macros($cmnt_tpl,[
1487 '$return_path' => '',
1488 '$jsreload' => $return_url,
1489 '$id' => $link_item['id'],
1490 '$parent' => $link_item['id'],
1491 '$profile_uid' => $owner_uid,
1492 '$mylink' => $contact['url'],
1493 '$mytitle' => L10n::t('This is you'),
1494 '$myphoto' => $contact['thumb'],
1495 '$comment' => L10n::t('Comment'),
1496 '$submit' => L10n::t('Submit'),
1497 '$preview' => L10n::t('Preview'),
1498 '$sourceapp' => L10n::t($a->sourcename),
1500 '$rand_num' => random_digits(12)
1504 foreach ($items as $item) {
1509 if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) {
1513 $profile_url = Contact::MagicLinkById($item['author-id']);
1514 if (strpos($profile_url, 'redir/') === 0) {
1515 $sparkle = ' sparkle';
1520 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1522 'dropping' => $dropping,
1523 'pagedrop' => false,
1524 'select' => L10n::t('Select'),
1525 'delete' => L10n::t('Delete'),
1528 $title_e = $item['title'];
1529 $body_e = BBCode::convert($item['body']);
1531 $comments .= replace_macros($template,[
1532 '$id' => $item['item_id'],
1533 '$profile_url' => $profile_url,
1534 '$name' => $item['author-name'],
1535 '$thumb' => $item['author-avatar'],
1536 '$sparkle' => $sparkle,
1537 '$title' => $title_e,
1539 '$ago' => Temporal::getRelativeDate($item['created']),
1540 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1542 '$comment' => $comment
1545 if (($can_post || can_write_wall($owner_uid))) {
1546 $comments .= replace_macros($cmnt_tpl, [
1547 '$return_path' => '',
1548 '$jsreload' => $return_url,
1549 '$id' => $item['item_id'],
1550 '$parent' => $item['parent'],
1551 '$profile_uid' => $owner_uid,
1552 '$mylink' => $contact['url'],
1553 '$mytitle' => L10n::t('This is you'),
1554 '$myphoto' => $contact['thumb'],
1555 '$comment' => L10n::t('Comment'),
1556 '$submit' => L10n::t('Submit'),
1557 '$preview' => L10n::t('Preview'),
1558 '$sourceapp' => L10n::t($a->sourcename),
1560 '$rand_num' => random_digits(12)
1565 $response_verbs = ['like'];
1566 if (Feature::isEnabled($owner_uid, 'dislike')) {
1567 $response_verbs[] = 'dislike';
1569 $responses = get_responses($conv_responses, $response_verbs, '', $link_item);
1571 $paginate = paginate($a);
1574 $photo_tpl = get_markup_template('photo_view.tpl');
1575 $o .= replace_macros($photo_tpl, [
1576 '$id' => $ph[0]['id'],
1577 '$album' => [$album_link, $ph[0]['album']],
1581 '$prevlink' => $prevlink,
1582 '$nextlink' => $nextlink,
1583 '$desc' => $ph[0]['desc'],
1587 '$map_text' => L10n::t('Map'),
1588 '$likebuttons' => $likebuttons,
1590 '$dislike' => $dislike,
1591 'responses' => $responses,
1592 '$comments' => $comments,
1593 '$paginate' => $paginate,
1596 $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="photo" />' . "\n";
1597 $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1598 $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . $photo["href"] . '" />' . "\n";
1599 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1600 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1605 // Default - show recent photos with upload link (if applicable)
1608 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1609 $sql_extra GROUP BY `resource-id`",
1610 intval($a->data['user']['uid']),
1611 dbesc('Contact Photos'),
1612 dbesc(L10n::t('Contact Photos'))
1615 if (DBM::is_result($r)) {
1616 $a->set_pager_total(count($r));
1617 $a->set_pager_itemspage(20);
1620 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1621 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1622 ANY_VALUE(`created`) AS `created` FROM `photo`
1623 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1624 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1625 intval($a->data['user']['uid']),
1626 dbesc('Contact Photos'),
1627 dbesc(L10n::t('Contact Photos')),
1628 intval($a->pager['start']),
1629 intval($a->pager['itemspage'])
1633 if (DBM::is_result($r)) {
1634 // "Twist" is only used for the duepunto theme with style "slackr"
1636 foreach ($r as $rr) {
1637 //hide profile photos to others
1638 if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos'))) {
1644 $ext = $phototypes[$rr['type']];
1646 $alt_e = $rr['filename'];
1647 $name_e = $rr['album'];
1651 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1652 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1653 'title' => L10n::t('View Photo'),
1654 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1657 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1659 'alt' => L10n::t('View Album'),
1666 $tpl = get_markup_template('photos_recent.tpl');
1667 $o .= replace_macros($tpl, [
1668 '$title' => L10n::t('Recent Photos'),
1669 '$can_post' => $can_post,
1670 '$upload' => [L10n::t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'],
1671 '$photos' => $photos,
1672 '$paginate' => paginate($a),