7 use Friendica\Content\Feature;
8 use Friendica\Content\Nav;
9 use Friendica\Content\Pager;
10 use Friendica\Content\Text\BBCode;
11 use Friendica\Core\ACL;
12 use Friendica\Core\Addon;
13 use Friendica\Core\Config;
14 use Friendica\Core\L10n;
15 use Friendica\Core\Logger;
16 use Friendica\Core\Renderer;
17 use Friendica\Core\System;
18 use Friendica\Core\Worker;
19 use Friendica\Database\DBA;
20 use Friendica\Model\Contact;
21 use Friendica\Model\Group;
22 use Friendica\Model\Item;
23 use Friendica\Model\Photo;
24 use Friendica\Model\Profile;
25 use Friendica\Model\User;
26 use Friendica\Network\Probe;
27 use Friendica\Object\Image;
28 use Friendica\Protocol\DFRN;
29 use Friendica\Util\Crypto;
30 use Friendica\Util\DateTimeFormat;
31 use Friendica\Util\Map;
32 use Friendica\Util\Security;
33 use Friendica\Util\Temporal;
34 use Friendica\Util\Strings;
35 use Friendica\Util\XML;
37 function photos_init(App $a) {
40 DFRN::autoRedir($a, $a->argv[1]);
43 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
47 Nav::setSelected('home');
51 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
55 if (!DBA::isResult($user)) {
59 $a->data['user'] = $user[0];
60 $a->profile_uid = $user[0]['uid'];
61 $is_owner = (local_user() && (local_user() == $a->profile_uid));
63 $profile = Profile::getByNickname($nick, $a->profile_uid);
65 $account_type = Contact::getAccountType($profile);
67 $tpl = Renderer::getMarkupTemplate("vcard-widget.tpl");
69 $vcard_widget = Renderer::replaceMacros($tpl, [
70 '$name' => $profile['name'],
71 '$photo' => $profile['photo'],
72 '$addr' => defaults($profile, 'addr', ''),
73 '$account_type' => $account_type,
74 '$pdesc' => defaults($profile, 'pdesc', ''),
77 $albums = Photo::getAlbums($a->data['user']['uid']);
79 $albums_visible = ((intval($a->data['user']['hidewall']) && !local_user() && !remote_user()) ? false : true);
81 // add various encodings to the array so we can just loop through and pick them out in a template
82 $ret = ['success' => false];
85 $a->data['albums'] = $albums;
87 if ($albums_visible) {
88 $ret['success'] = true;
92 foreach ($albums as $k => $album) {
93 //hide profile photos to others
94 if (!$is_owner && !remote_user() && ($album['album'] == L10n::t('Profile Photos')))
97 'text' => $album['album'],
98 'total' => $album['total'],
99 'url' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
100 'urlencode' => urlencode($album['album']),
101 'bin2hex' => bin2hex($album['album'])
103 $ret['albums'][] = $entry;
107 if (local_user() && $a->data['user']['uid'] == local_user()) {
113 if ($ret['success']) {
114 $photo_albums_widget = Renderer::replaceMacros(Renderer::getMarkupTemplate('photo_albums.tpl'), [
115 '$nick' => $a->data['user']['nickname'],
116 '$title' => L10n::t('Photo Albums'),
117 '$recent' => L10n::t('Recent Photos'),
118 '$albums' => $ret['albums'],
119 '$baseurl' => System::baseUrl(),
120 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'],
121 '$can_post' => $can_post
125 if (empty($a->page['aside'])) {
126 $a->page['aside'] = '';
129 $a->page['aside'] .= $vcard_widget;
131 if (!empty($photo_albums_widget)) {
132 $a->page['aside'] .= $photo_albums_widget;
135 $tpl = Renderer::getMarkupTemplate("photos_head.tpl");
137 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl,[
138 '$ispublic' => L10n::t('everybody')
145 function photos_post(App $a)
147 Logger::log('mod-photos: photos_post: begin' , Logger::DEBUG);
148 Logger::log('mod_photos: REQUEST ' . print_r($_REQUEST, true), Logger::DATA);
149 Logger::log('mod_photos: FILES ' . print_r($_FILES, true), Logger::DATA);
151 $phototypes = Image::supportedTypes();
156 $page_owner_uid = $a->data['user']['uid'];
157 $community_page = $a->data['user']['page-flags'] == Contact::PAGE_COMMUNITY;
159 if (local_user() && (local_user() == $page_owner_uid)) {
161 } elseif ($community_page && remote_user()) {
164 if (!empty($_SESSION['remote']) && is_array($_SESSION['remote'])) {
165 foreach ($_SESSION['remote'] as $v) {
166 if ($v['uid'] == $page_owner_uid) {
167 $contact_id = $v['cid'];
173 if ($contact_id > 0) {
174 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
176 intval($page_owner_uid)
179 if (DBA::isResult($r)) {
181 $visitor = $contact_id;
187 notice(L10n::t('Permission denied.') . EOL);
191 $owner_record = User::getOwnerDataById($page_owner_uid);
193 if (!$owner_record) {
194 notice(L10n::t('Contact information unavailable') . EOL);
195 Logger::log('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
199 if ($a->argc > 3 && $a->argv[2] === 'album') {
200 $album = hex2bin($a->argv[3]);
202 if ($album === L10n::t('Profile Photos') || $album === 'Contact Photos' || $album === L10n::t('Contact Photos')) {
203 $a->internalRedirect($_SESSION['photo_return']);
204 return; // NOTREACHED
207 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
209 intval($page_owner_uid)
212 if (!DBA::isResult($r)) {
213 notice(L10n::t('Album not found.') . EOL);
214 $a->internalRedirect($_SESSION['photo_return']);
215 return; // NOTREACHED
218 // Check if the user has responded to a delete confirmation query
219 if (!empty($_REQUEST['canceled'])) {
220 $a->internalRedirect($_SESSION['photo_return']);
223 // RENAME photo album
224 $newalbum = Strings::escapeTags(trim($_POST['albumname']));
225 if ($newalbum != $album) {
226 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
227 DBA::escape($newalbum),
229 intval($page_owner_uid)
231 // Update the photo albums cache
232 Photo::clearAlbumCache($page_owner_uid);
234 $a->internalRedirect('photos/' . $a->user['nickname'] . '/album/' . bin2hex($newalbum));
235 return; // NOTREACHED
239 * DELETE photo album and all its photos
242 if ($_POST['dropalbum'] == L10n::t('Delete Album')) {
243 // Check if we should do HTML-based delete confirmation
244 if (!empty($_REQUEST['confirm'])) {
245 $drop_url = $a->query_string;
248 ['name' => 'albumname', 'value' => $_POST['albumname']],
251 $a->page['content'] = Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
253 '$message' => L10n::t('Do you really want to delete this photo album and all its photos?'),
254 '$extra_inputs' => $extra_inputs,
255 '$confirm' => L10n::t('Delete Album'),
256 '$confirm_url' => $drop_url,
257 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
258 '$cancel' => L10n::t('Cancel'),
261 $a->error = 1; // Set $a->error so the other module functions don't execute
267 // get the list of photos we are about to delete
270 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
272 intval($page_owner_uid),
276 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
277 intval(local_user()),
282 if (DBA::isResult($r)) {
283 foreach ($r as $rr) {
287 $a->internalRedirect($_SESSION['photo_return']);
288 return; // NOTREACHED
291 // remove the associated photos
292 Photo::delete(['resource-id' => $res, 'uid' => $page_owner_uid]);
294 // find and delete the corresponding item with all the comments and likes/dislikes
295 Item::deleteForUser(['resource-id' => $res, 'uid' => $page_owner_uid], $page_owner_uid);
297 // Update the photo albums cache
298 Photo::clearAlbumCache($page_owner_uid);
301 $a->internalRedirect('photos/' . $a->data['user']['nickname']);
302 return; // NOTREACHED
306 // Check if the user has responded to a delete confirmation query for a single photo
307 if ($a->argc > 2 && !empty($_REQUEST['canceled'])) {
308 $a->internalRedirect($_SESSION['photo_return']);
311 if ($a->argc > 2 && defaults($_POST, 'delete', '') === L10n::t('Delete Photo')) {
313 // same as above but remove single photo
315 // Check if we should do HTML-based delete confirmation
316 if (!empty($_REQUEST['confirm'])) {
317 $drop_url = $a->query_string;
319 $a->page['content'] = Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
321 '$message' => L10n::t('Do you really want to delete this photo?'),
322 '$extra_inputs' => [],
323 '$confirm' => L10n::t('Delete Photo'),
324 '$confirm_url' => $drop_url,
325 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
326 '$cancel' => L10n::t('Cancel'),
329 $a->error = 1; // Set $a->error so the other module functions don't execute
334 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
336 intval($page_owner_uid),
337 DBA::escape($a->argv[2])
340 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
341 intval(local_user()),
342 DBA::escape($a->argv[2])
346 if (DBA::isResult($r)) {
347 Photo::delete(['resource-id' => $r[0]['resource-id'], 'uid' => $page_owner_uid]);
349 Item::deleteForUser(['resource-id' => $r[0]['resource-id'], 'uid' => $page_owner_uid], $page_owner_uid);
351 // Update the photo albums cache
352 Photo::clearAlbumCache($page_owner_uid);
355 $a->internalRedirect('photos/' . $a->data['user']['nickname']);
356 return; // NOTREACHED
359 if ($a->argc > 2 && (!empty($_POST['desc']) || !empty($_POST['newtag']) || isset($_POST['albname']))) {
360 $desc = !empty($_POST['desc']) ? Strings::escapeTags(trim($_POST['desc'])) : '';
361 $rawtags = !empty($_POST['newtag']) ? Strings::escapeTags(trim($_POST['newtag'])) : '';
362 $item_id = !empty($_POST['item_id']) ? intval($_POST['item_id']) : 0;
363 $albname = !empty($_POST['albname']) ? Strings::escapeTags(trim($_POST['albname'])) : '';
364 $origaname = !empty($_POST['origaname']) ? Strings::escapeTags(trim($_POST['origaname'])) : '';
366 $str_group_allow = !empty($_POST['group_allow']) ? perms2str($_POST['group_allow']) : '';
367 $str_contact_allow = !empty($_POST['contact_allow']) ? perms2str($_POST['contact_allow']) : '';
368 $str_group_deny = !empty($_POST['group_deny']) ? perms2str($_POST['group_deny']) : '';
369 $str_contact_deny = !empty($_POST['contact_deny']) ? perms2str($_POST['contact_deny']) : '';
371 $resource_id = $a->argv[2];
373 if (!strlen($albname)) {
374 $albname = DateTimeFormat::localNow('Y');
377 if (!empty($_POST['rotate']) && (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
378 Logger::log('rotate');
380 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0 LIMIT 1",
381 DBA::escape($resource_id),
382 intval($page_owner_uid)
385 if (DBA::isResult($r)) {
386 $image = new Image($r[0]['data'], $r[0]['type']);
388 if ($image->isValid()) {
389 $rotate_deg = ((intval($_POST['rotate']) == 1) ? 270 : 90);
390 $image->rotate($rotate_deg);
392 $width = $image->getWidth();
393 $height = $image->getHeight();
395 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0",
396 DBA::escape($image->asString()),
399 DBA::escape($resource_id),
400 intval($page_owner_uid)
403 if ($width > 640 || $height > 640) {
404 $image->scaleDown(640);
405 $width = $image->getWidth();
406 $height = $image->getHeight();
408 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 1",
409 DBA::escape($image->asString()),
412 DBA::escape($resource_id),
413 intval($page_owner_uid)
417 if ($width > 320 || $height > 320) {
418 $image->scaleDown(320);
419 $width = $image->getWidth();
420 $height = $image->getHeight();
422 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 2",
423 DBA::escape($image->asString()),
426 DBA::escape($resource_id),
427 intval($page_owner_uid)
434 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
435 DBA::escape($resource_id),
436 intval($page_owner_uid)
439 if (DBA::isResult($p)) {
440 $ext = $phototypes[$p[0]['type']];
441 $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",
443 DBA::escape($albname),
444 DBA::escape($str_contact_allow),
445 DBA::escape($str_group_allow),
446 DBA::escape($str_contact_deny),
447 DBA::escape($str_group_deny),
448 DBA::escape($resource_id),
449 intval($page_owner_uid)
452 // Update the photo albums cache if album name was changed
453 if ($albname !== $origaname) {
454 Photo::clearAlbumCache($page_owner_uid);
458 /* Don't make the item visible if the only change was the album name */
461 if ($p[0]['desc'] !== $desc || strlen($rawtags)) {
466 // Create item container
468 $uri = Item::newURI($page_owner_uid);
471 $arr['guid'] = System::createUUID();
472 $arr['uid'] = $page_owner_uid;
474 $arr['parent-uri'] = $uri;
475 $arr['post-type'] = Item::PT_IMAGE;
477 $arr['resource-id'] = $p[0]['resource-id'];
478 $arr['contact-id'] = $owner_record['id'];
479 $arr['owner-name'] = $owner_record['name'];
480 $arr['owner-link'] = $owner_record['url'];
481 $arr['owner-avatar'] = $owner_record['thumb'];
482 $arr['author-name'] = $owner_record['name'];
483 $arr['author-link'] = $owner_record['url'];
484 $arr['author-avatar'] = $owner_record['thumb'];
485 $arr['title'] = $title;
486 $arr['allow_cid'] = $p[0]['allow_cid'];
487 $arr['allow_gid'] = $p[0]['allow_gid'];
488 $arr['deny_cid'] = $p[0]['deny_cid'];
489 $arr['deny_gid'] = $p[0]['deny_gid'];
490 $arr['visible'] = $visibility;
493 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
494 . '[img]' . System::baseUrl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
497 $item_id = Item::insert($arr);
501 $item = Item::selectFirst(['tag', 'inform'], ['id' => $item_id, 'uid' => $page_owner_uid]);
503 if (DBA::isResult($item)) {
504 $old_tag = $item['tag'];
505 $old_inform = $item['inform'];
508 if (strlen($rawtags)) {
512 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
513 $x = substr($rawtags, 0, 1);
514 if ($x !== '@' && $x !== '#') {
515 $rawtags = '#' . $rawtags;
519 $tags = BBCode::getTags($rawtags);
522 foreach ($tags as $tag) {
523 if (strpos($tag, '@') === 0) {
525 $name = substr($tag,1);
527 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
529 $links = @Probe::lrdd($name);
532 foreach ($links as $link) {
533 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
534 $profile = $link['@attributes']['href'];
537 if ($link['@attributes']['rel'] === 'salmon') {
538 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
540 if (strlen($inform)) {
549 $taginfo[] = [$newname, $profile, $salmon];
555 if (strrpos($newname, '+')) {
556 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
560 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
565 $newname = str_replace('_',' ',$name);
567 //select someone from this user's contacts by name
568 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
569 DBA::escape($newname),
570 intval($page_owner_uid)
573 if (!DBA::isResult($r)) {
574 //select someone by attag or nick and the name passed in
575 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
578 intval($page_owner_uid)
583 if (DBA::isResult($r)) {
584 $newname = $r[0]['name'];
585 $profile = $r[0]['url'];
587 $notify = 'cid:' . $r[0]['id'];
588 if (strlen($inform)) {
596 if (substr($notify, 0, 4) === 'cid:') {
597 $taginfo[] = [$newname, $profile, $notify, $r[0], '@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]'];
599 $taginfo[] = [$newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'];
602 if (strlen($str_tags)) {
606 $profile = str_replace(',', '%2c', $profile);
607 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
609 } elseif (strpos($tag, '#') === 0) {
610 $tagname = substr($tag, 1);
611 $str_tags .= '#[url=' . System::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url],';
617 if (strlen($newtag) && strlen($str_tags)) {
620 $newtag .= $str_tags;
622 $newinform = $old_inform;
623 if (strlen($newinform) && strlen($inform)) {
626 $newinform .= $inform;
628 $fields = ['tag' => $newtag, 'inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
629 $condition = ['id' => $item_id];
630 Item::update($fields, $condition);
633 foreach ($p as $scales) {
634 if (intval($scales['scale']) == 2) {
639 if (intval($scales['scale']) == 4) {
645 if (count($taginfo)) {
646 foreach ($taginfo as $tagged) {
647 $uri = Item::newURI($page_owner_uid);
650 $arr['guid'] = System::createUUID();
651 $arr['uid'] = $page_owner_uid;
653 $arr['parent-uri'] = $uri;
655 $arr['contact-id'] = $owner_record['id'];
656 $arr['owner-name'] = $owner_record['name'];
657 $arr['owner-link'] = $owner_record['url'];
658 $arr['owner-avatar'] = $owner_record['thumb'];
659 $arr['author-name'] = $owner_record['name'];
660 $arr['author-link'] = $owner_record['url'];
661 $arr['author-avatar'] = $owner_record['thumb'];
663 $arr['allow_cid'] = $p[0]['allow_cid'];
664 $arr['allow_gid'] = $p[0]['allow_gid'];
665 $arr['deny_cid'] = $p[0]['deny_cid'];
666 $arr['deny_gid'] = $p[0]['deny_gid'];
668 $arr['verb'] = ACTIVITY_TAG;
669 $arr['gravity'] = GRAVITY_PARENT;
670 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
671 $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
672 $arr['tag'] = $tagged[4];
673 $arr['inform'] = $tagged[2];
675 $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]');
676 $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";
678 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
679 $arr['object'] .= '<link>' . XML::escape('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
681 $arr['object'] .= XML::escape('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
683 $arr['object'] .= '</link></object>' . "\n";
685 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $p[0]['desc'] . '</title><id>'
686 . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
687 $arr['target'] .= '<link>' . XML::escape('<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>';
689 $item_id = Item::insert($arr);
693 $a->internalRedirect($_SESSION['photo_return']);
694 return; // NOTREACHED
698 // default post action - upload a photo
699 Addon::callHooks('photo_post_init', $_POST);
701 // Determine the album to use
702 $album = !empty($_REQUEST['album']) ? Strings::escapeTags(trim($_REQUEST['album'])) : '';
703 $newalbum = !empty($_REQUEST['newalbum']) ? Strings::escapeTags(trim($_REQUEST['newalbum'])) : '';
705 Logger::log('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , Logger::DEBUG);
707 if (!strlen($album)) {
708 if (strlen($newalbum)) {
711 $album = DateTimeFormat::localNow('Y');
716 * We create a wall item for every photo, but we don't want to
717 * overwhelm the data stream with a hundred newly uploaded photos.
718 * So we will make the first photo uploaded to this album in the last several hours
719 * visible by default, the rest will become visible over time when and if
720 * they acquire comments, likes, dislikes, and/or tags
723 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
725 intval($page_owner_uid)
728 if (!DBA::isResult($r) || ($album == L10n::t('Profile Photos'))) {
734 if (!empty($_REQUEST['not_visible']) && $_REQUEST['not_visible'] !== 'false') {
738 $group_allow = defaults($_REQUEST, 'group_allow' , []);
739 $contact_allow = defaults($_REQUEST, 'contact_allow', []);
740 $group_deny = defaults($_REQUEST, 'group_deny' , []);
741 $contact_deny = defaults($_REQUEST, 'contact_deny' , []);
743 $str_group_allow = perms2str(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
744 $str_contact_allow = perms2str(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
745 $str_group_deny = perms2str(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
746 $str_contact_deny = perms2str(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
748 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
750 Addon::callHooks('photo_post_file', $ret);
752 if (!empty($ret['src']) && !empty($ret['filesize'])) {
754 $filename = $ret['filename'];
755 $filesize = $ret['filesize'];
756 $type = $ret['type'];
757 $error = UPLOAD_ERR_OK;
758 } elseif (!empty($_FILES['userfile'])) {
759 $src = $_FILES['userfile']['tmp_name'];
760 $filename = basename($_FILES['userfile']['name']);
761 $filesize = intval($_FILES['userfile']['size']);
762 $type = $_FILES['userfile']['type'];
763 $error = $_FILES['userfile']['error'];
765 $error = UPLOAD_ERR_NO_FILE;
768 if ($error !== UPLOAD_ERR_OK) {
770 case UPLOAD_ERR_INI_SIZE:
771 notice(L10n::t('Image exceeds size limit of %s', ini_get('upload_max_filesize')) . EOL);
773 case UPLOAD_ERR_FORM_SIZE:
774 notice(L10n::t('Image exceeds size limit of %s', Strings::formatBytes(defaults($_REQUEST, 'MAX_FILE_SIZE', 0))) . EOL);
776 case UPLOAD_ERR_PARTIAL:
777 notice(L10n::t('Image upload didn\'t complete, please try again') . EOL);
779 case UPLOAD_ERR_NO_FILE:
780 notice(L10n::t('Image file is missing') . EOL);
782 case UPLOAD_ERR_NO_TMP_DIR:
783 case UPLOAD_ERR_CANT_WRITE:
784 case UPLOAD_ERR_EXTENSION:
785 notice(L10n::t('Server can\'t accept new file upload at this time, please contact your administrator') . EOL);
790 Addon::callHooks('photo_post_end', $foo);
795 $type = Image::guessType($filename);
798 Logger::log('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', Logger::DEBUG);
800 $maximagesize = Config::get('system', 'maximagesize');
802 if ($maximagesize && ($filesize > $maximagesize)) {
803 notice(L10n::t('Image exceeds size limit of %s', Strings::formatBytes($maximagesize)) . EOL);
806 Addon::callHooks('photo_post_end', $foo);
811 notice(L10n::t('Image file is empty.') . EOL);
814 Addon::callHooks('photo_post_end', $foo);
818 Logger::log('mod/photos.php: photos_post(): loading the contents of ' . $src , Logger::DEBUG);
820 $imagedata = @file_get_contents($src);
822 $image = new Image($imagedata, $type);
824 if (!$image->isValid()) {
825 Logger::log('mod/photos.php: photos_post(): unable to process image' , Logger::DEBUG);
826 notice(L10n::t('Unable to process image.') . EOL);
829 Addon::callHooks('photo_post_end',$foo);
833 $exif = $image->orient($src);
836 $max_length = Config::get('system', 'max_image_length');
838 $max_length = MAX_IMAGE_LENGTH;
840 if ($max_length > 0) {
841 $image->scaleDown($max_length);
844 $width = $image->getWidth();
845 $height = $image->getHeight();
849 $photo_hash = Photo::newResource();
851 $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);
854 Logger::log('mod/photos.php: photos_post(): image store failed', Logger::DEBUG);
855 notice(L10n::t('Image upload failed.') . EOL);
859 if ($width > 640 || $height > 640) {
860 $image->scaleDown(640);
861 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);
865 if ($width > 320 || $height > 320) {
866 $image->scaleDown(320);
867 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);
871 $uri = Item::newURI($page_owner_uid);
873 // Create item container
875 if ($exif && $exif['GPS'] && Feature::isEnabled($page_owner_uid, 'photo_location')) {
876 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
877 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
882 $arr['coord'] = $lat . ' ' . $lon;
885 $arr['guid'] = System::createUUID();
886 $arr['uid'] = $page_owner_uid;
888 $arr['parent-uri'] = $uri;
889 $arr['type'] = 'photo';
891 $arr['resource-id'] = $photo_hash;
892 $arr['contact-id'] = $owner_record['id'];
893 $arr['owner-name'] = $owner_record['name'];
894 $arr['owner-link'] = $owner_record['url'];
895 $arr['owner-avatar'] = $owner_record['thumb'];
896 $arr['author-name'] = $owner_record['name'];
897 $arr['author-link'] = $owner_record['url'];
898 $arr['author-avatar'] = $owner_record['thumb'];
900 $arr['allow_cid'] = $str_contact_allow;
901 $arr['allow_gid'] = $str_group_allow;
902 $arr['deny_cid'] = $str_contact_deny;
903 $arr['deny_gid'] = $str_group_deny;
904 $arr['visible'] = $visible;
907 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
908 . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$image->getExt() . '[/img]'
911 $item_id = Item::insert($arr);
912 // Update the photo albums cache
913 Photo::clearAlbumCache($page_owner_uid);
915 Addon::callHooks('photo_post_end', $item_id);
917 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
918 // if they do not wish to be redirected
920 $a->internalRedirect($_SESSION['photo_return']);
924 function photos_content(App $a)
928 // photos/name/upload
929 // photos/name/upload/xxxxx (xxxxx is album name)
930 // photos/name/album/xxxxx
931 // photos/name/album/xxxxx/edit
932 // photos/name/image/xxxxx
933 // photos/name/image/xxxxx/edit
935 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
936 notice(L10n::t('Public access denied.') . EOL);
940 if (empty($a->data['user'])) {
941 notice(L10n::t('No photos selected') . EOL);
945 $phototypes = Image::supportedTypes();
947 $_SESSION['photo_return'] = $a->cmd;
952 $datatype = $a->argv[2];
953 $datum = $a->argv[3];
954 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
955 $datatype = 'upload';
957 $datatype = 'summary';
966 // Setup permissions structures
970 $remote_contact = false;
974 $owner_uid = $a->data['user']['uid'];
976 $community_page = (($a->data['user']['page-flags'] == Contact::PAGE_COMMUNITY) ? true : false);
978 if (local_user() && (local_user() == $owner_uid)) {
981 if ($community_page && remote_user()) {
982 if (is_array($_SESSION['remote'])) {
983 foreach ($_SESSION['remote'] as $v) {
984 if ($v['uid'] == $owner_uid) {
985 $contact_id = $v['cid'];
992 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
996 if (DBA::isResult($r)) {
999 $remote_contact = true;
1000 $visitor = $contact_id;
1008 // perhaps they're visiting - but not a community page, so they wouldn't have write access
1009 if (remote_user() && !$visitor) {
1011 if (is_array($_SESSION['remote'])) {
1012 foreach ($_SESSION['remote'] as $v) {
1013 if ($v['uid'] == $owner_uid) {
1014 $contact_id = $v['cid'];
1020 $groups = Group::getIdsByContactId($contact_id);
1021 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1022 intval($contact_id),
1025 if (DBA::isResult($r)) {
1027 $remote_contact = true;
1032 if (!$remote_contact && local_user()) {
1033 $contact_id = $_SESSION['cid'];
1034 $contact = $a->contact;
1037 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
1038 notice(L10n::t('Access to this item is restricted.') . EOL);
1042 $sql_extra = Security::getPermissionsSQLByUserId($owner_uid, $remote_contact, $groups);
1047 $is_owner = (local_user() && (local_user() == $owner_uid));
1048 $o .= Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
1050 // Display upload form
1051 if ($datatype === 'upload') {
1053 notice(L10n::t('Permission denied.'));
1057 $selname = $datum ? hex2bin($datum) : '';
1061 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '><current year></option>';
1062 if (!empty($a->data['albums'])) {
1063 foreach ($a->data['albums'] as $album) {
1064 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos'))) {
1067 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1068 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1074 $ret = ['post_url' => 'photos/' . $a->data['user']['nickname'],
1075 'addon_text' => $uploader,
1076 'default_upload' => true];
1078 Addon::callHooks('photo_upload_form',$ret);
1080 $default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
1081 $default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
1082 '$submit' => L10n::t('Submit'),
1085 $usage_message = '';
1087 $tpl = Renderer::getMarkupTemplate('photos_upload.tpl');
1089 $aclselect_e = ($visitor ? '' : ACL::getFullSelectorHTML($a->user));
1091 $o .= Renderer::replaceMacros($tpl,[
1092 '$pagename' => L10n::t('Upload Photos'),
1093 '$sessid' => session_id(),
1094 '$usage' => $usage_message,
1095 '$nickname' => $a->data['user']['nickname'],
1096 '$newalbum' => L10n::t('New album name: '),
1097 '$existalbumtext' => L10n::t('or select existing album:'),
1098 '$nosharetext' => L10n::t('Do not show a status post for this upload'),
1099 '$albumselect' => $albumselect,
1100 '$permissions' => L10n::t('Permissions'),
1101 '$aclselect' => $aclselect_e,
1102 '$lockstate' => is_array($a->user)
1103 && (strlen($a->user['allow_cid'])
1104 || strlen($a->user['allow_gid'])
1105 || strlen($a->user['deny_cid'])
1106 || strlen($a->user['deny_gid'])
1107 ) ? 'lock' : 'unlock',
1108 '$alt_uploader' => $ret['addon_text'],
1109 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
1110 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
1111 '$uploadurl' => $ret['post_url'],
1113 // ACL permissions box
1114 '$group_perms' => L10n::t('Show to Groups'),
1115 '$contact_perms' => L10n::t('Show to Contacts'),
1116 '$return_path' => $a->query_string,
1122 // Display a single photo album
1123 if ($datatype === 'album') {
1124 $album = hex2bin($datum);
1127 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1128 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1132 if (DBA::isResult($r)) {
1136 $pager = new Pager($a->query_string, 20);
1138 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1139 $order_field = defaults($_GET, 'order', '');
1140 if ($order_field === 'posted') {
1146 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1147 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1148 ANY_VALUE(`created`) as `created`
1149 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1150 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1152 DBA::escape($album),
1154 $pager->getItemsPerPage()
1158 if ($cmd === 'edit') {
1159 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos'))) {
1161 $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
1165 $o .= Renderer::replaceMacros($edit_tpl,[
1166 '$nametext' => L10n::t('New album name: '),
1167 '$nickname' => $a->data['user']['nickname'],
1168 '$album' => $album_e,
1169 '$hexalbum' => bin2hex($album),
1170 '$submit' => L10n::t('Submit'),
1171 '$dropsubmit' => L10n::t('Delete Album')
1176 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos')) && $can_post) {
1177 $edit = [L10n::t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1181 if ($order_field === 'posted') {
1182 $order = [L10n::t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album), 'oldest'];
1184 $order = [L10n::t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted', 'newest'];
1189 if (DBA::isResult($r)) {
1190 // "Twist" is only used for the duepunto theme with style "slackr"
1192 foreach ($r as $rr) {
1195 $ext = $phototypes[$rr['type']];
1197 $imgalt_e = $rr['filename'];
1198 $desc_e = $rr['desc'];
1202 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1203 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1204 . ($order_field === 'posted' ? '?f=&order=posted' : ''),
1205 'title' => L10n::t('View Photo'),
1206 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1210 'hash'=> $rr['resource-id'],
1215 $tpl = Renderer::getMarkupTemplate('photo_album.tpl');
1216 $o .= Renderer::replaceMacros($tpl, [
1217 '$photos' => $photos,
1219 '$can_post' => $can_post,
1220 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)],
1223 '$paginate' => $pager->renderFull($total),
1230 // Display one photo
1231 if ($datatype === 'image') {
1232 // fetch image, item containing image, then comments
1233 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1234 $sql_extra ORDER BY `scale` ASC ",
1239 if (!DBA::isResult($ph)) {
1240 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1245 if (DBA::isResult($ph)) {
1246 notice(L10n::t('Permission denied. Access to this item may be restricted.'));
1248 notice(L10n::t('Photo not available') . EOL);
1257 * @todo This query is totally bad, the whole functionality has to be changed
1258 * The query leads to a really intense used index.
1259 * By now we hide it if someone wants to.
1261 if (!Config::get('system', 'no_count', false)) {
1262 $order_field = defaults($_GET, 'order', '');
1264 if ($order_field === 'posted') {
1270 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1271 $sql_extra ORDER BY `created` $order ",
1272 DBA::escape($ph[0]['album']),
1276 if (DBA::isResult($prvnxt)) {
1279 foreach ($prvnxt as $z => $entry) {
1280 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1284 $prv = count($prvnxt) - 1;
1286 if ($nxt >= count($prvnxt)) {
1292 $edit_suffix = ((($cmd === 'edit') && $can_post) ? '/edit' : '');
1293 if (!is_null($prv)) {
1294 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1296 if (!is_null($nxt)) {
1297 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1302 if (count($ph) == 1) {
1303 $hires = $lores = $ph[0];
1306 if (count($ph) > 1) {
1307 if ($ph[1]['scale'] == 2) {
1308 // original is 640 or less, we can display it directly
1309 $hires = $lores = $ph[0];
1316 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1321 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1323 'edit' => ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? L10n::t('View photo') : L10n::t('Edit photo'))],
1324 'profile'=>['profile_photo/use/'.$ph[0]['resource-id'], L10n::t('Use as profile photo')],
1328 $lock = ((($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1329 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])))
1330 ? L10n::t('Private Message')
1336 if ($cmd === 'edit') {
1337 $tpl = Renderer::getMarkupTemplate('photo_edit_head.tpl');
1338 $a->page['htmlhead'] .= Renderer::replaceMacros($tpl,[
1339 '$prevlink' => $prevlink,
1340 '$nextlink' => $nextlink
1345 $prevlink = [$prevlink, '<div class="icon prev"></div>'];
1349 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1350 'title'=> L10n::t('View Full Size'),
1351 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . DateTimeFormat::utcNow('ymdhis'),
1352 'height' => $hires['height'],
1353 'width' => $hires['width'],
1354 'album' => $hires['album'],
1355 'filename' => $hires['filename'],
1359 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1363 // Do we have an item for this photo?
1365 // FIXME! - replace following code to display the conversation with our normal
1366 // conversation functions so that it works correctly and tracks changes
1367 // in the evolving conversation code.
1368 // The difference is that we won't be displaying the conversation head item
1369 // as a "post" but displaying instead the photo it is linked to
1371 /// @todo Rewrite this query. To do so, $sql_extra must be changed
1372 $linked_items = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1380 if (DBA::isResult($linked_items)) {
1381 // This is a workaround to not being forced to rewrite the while $sql_extra handling
1382 $link_item = Item::selectFirst([], ['id' => $linked_items[0]['id']]);
1384 $condition = ["`parent` = ? AND `parent` != `id`", $link_item['parent']];
1385 $total = DBA::count('item', $condition);
1387 $pager = new Pager($a->query_string);
1389 $params = ['order' => ['id'], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
1390 $result = Item::selectForUser($link_item['uid'], Item::ITEM_FIELDLIST, $condition, $params);
1391 $items = Item::inArray($result);
1393 if (local_user() && (local_user() == $link_item['uid'])) {
1394 Item::update(['unseen' => false], ['parent' => $link_item['parent']]);
1397 if ($link_item['coord']) {
1398 $map = Map::byCoordinates($link_item['coord']);
1404 if (count($linked_items) && strlen($link_item['tag'])) {
1405 $arr = explode(',', $link_item['tag']);
1406 // parse tags and add links
1408 foreach ($arr as $tag) {
1410 'name' => BBCode::convert($tag),
1411 'removeurl' => '/tagrm/'.$link_item['id'] . '/' . bin2hex($tag)
1414 $tags = ['title' => L10n::t('Tags: '), 'tags' => $tag_arr];
1415 if ($cmd === 'edit') {
1416 $tags['removeanyurl'] = 'tagrm/' . $link_item['id'];
1417 $tags['removetitle'] = L10n::t('[Select tags to remove]');
1423 if ($cmd === 'edit' && $can_post) {
1424 $edit_tpl = Renderer::getMarkupTemplate('photo_edit.tpl');
1426 $album_e = $ph[0]['album'];
1427 $caption_e = $ph[0]['desc'];
1428 $aclselect_e = ACL::getFullSelectorHTML($a->user, false, $ph[0]);
1430 $edit = Renderer::replaceMacros($edit_tpl, [
1431 '$id' => $ph[0]['id'],
1432 '$album' => ['albname', L10n::t('New album name'), $album_e,''],
1433 '$caption' => ['desc', L10n::t('Caption'), $caption_e, ''],
1434 '$tags' => ['newtag', L10n::t('Add a Tag'), "", L10n::t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1435 '$rotate_none' => ['rotate', L10n::t('Do not rotate'),0,'', true],
1436 '$rotate_cw' => ['rotate', L10n::t("Rotate CW \x28right\x29"),1,''],
1437 '$rotate_ccw' => ['rotate', L10n::t("Rotate CCW \x28left\x29"),2,''],
1439 '$nickname' => $a->data['user']['nickname'],
1440 '$resource_id' => $ph[0]['resource-id'],
1441 '$permissions' => L10n::t('Permissions'),
1442 '$aclselect' => $aclselect_e,
1444 '$item_id' => defaults($link_item, 'id', 0),
1445 '$submit' => L10n::t('Submit'),
1446 '$delete' => L10n::t('Delete Photo'),
1448 // ACL permissions box
1449 '$group_perms' => L10n::t('Show to Groups'),
1450 '$contact_perms' => L10n::t('Show to Contacts'),
1451 '$return_path' => $a->query_string,
1462 if (count($linked_items)) {
1463 $cmnt_tpl = Renderer::getMarkupTemplate('comment_item.tpl');
1464 $tpl = Renderer::getMarkupTemplate('photo_item.tpl');
1465 $return_path = $a->cmd;
1467 if ($can_post || Security::canWriteToUserWall($owner_uid)) {
1468 $like_tpl = Renderer::getMarkupTemplate('like_noshare.tpl');
1469 $likebuttons = Renderer::replaceMacros($like_tpl, [
1470 '$id' => $link_item['id'],
1471 '$likethis' => L10n::t("I like this \x28toggle\x29"),
1472 '$nolike' => L10n::t("I don't like this \x28toggle\x29"),
1473 '$wait' => L10n::t('Please wait'),
1474 '$return_path' => $a->query_string,
1478 if (!DBA::isResult($items)) {
1479 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1480 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1481 '$return_path' => '',
1482 '$jsreload' => $return_path,
1483 '$id' => $link_item['id'],
1484 '$parent' => $link_item['id'],
1485 '$profile_uid' => $owner_uid,
1486 '$mylink' => $contact['url'],
1487 '$mytitle' => L10n::t('This is you'),
1488 '$myphoto' => $contact['thumb'],
1489 '$comment' => L10n::t('Comment'),
1490 '$submit' => L10n::t('Submit'),
1491 '$preview' => L10n::t('Preview'),
1492 '$sourceapp' => L10n::t($a->sourcename),
1494 '$rand_num' => Crypto::randomDigits(12)
1500 'like' => ['title' => L10n::t('Likes','title')],'dislike' => ['title' => L10n::t('Dislikes','title')],
1501 'attendyes' => ['title' => L10n::t('Attending','title')], 'attendno' => ['title' => L10n::t('Not attending','title')], 'attendmaybe' => ['title' => L10n::t('Might attend','title')]
1505 if (DBA::isResult($items)) {
1506 foreach ($items as $item) {
1507 builtin_activity_puller($item, $conv_responses);
1510 if (!empty($conv_responses['like'][$link_item['uri']])) {
1511 $like = format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like', $link_item['id']);
1514 if (!empty($conv_responses['dislike'][$link_item['uri']])) {
1515 $dislike = format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike', $link_item['id']);
1518 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1519 $comments .= Renderer::replaceMacros($cmnt_tpl,[
1520 '$return_path' => '',
1521 '$jsreload' => $return_path,
1522 '$id' => $link_item['id'],
1523 '$parent' => $link_item['id'],
1524 '$profile_uid' => $owner_uid,
1525 '$mylink' => $contact['url'],
1526 '$mytitle' => L10n::t('This is you'),
1527 '$myphoto' => $contact['thumb'],
1528 '$comment' => L10n::t('Comment'),
1529 '$submit' => L10n::t('Submit'),
1530 '$preview' => L10n::t('Preview'),
1531 '$sourceapp' => L10n::t($a->sourcename),
1533 '$rand_num' => Crypto::randomDigits(12)
1537 foreach ($items as $item) {
1542 if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) {
1546 $profile_url = Contact::MagicLinkById($item['author-id']);
1547 if (strpos($profile_url, 'redir/') === 0) {
1548 $sparkle = ' sparkle';
1553 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1555 'dropping' => $dropping,
1556 'pagedrop' => false,
1557 'select' => L10n::t('Select'),
1558 'delete' => L10n::t('Delete'),
1561 $title_e = $item['title'];
1562 $body_e = BBCode::convert($item['body']);
1564 $comments .= Renderer::replaceMacros($template,[
1565 '$id' => $item['id'],
1566 '$profile_url' => $profile_url,
1567 '$name' => $item['author-name'],
1568 '$thumb' => $item['author-avatar'],
1569 '$sparkle' => $sparkle,
1570 '$title' => $title_e,
1572 '$ago' => Temporal::getRelativeDate($item['created']),
1573 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1575 '$comment' => $comment
1578 if (($can_post || Security::canWriteToUserWall($owner_uid))) {
1579 $comments .= Renderer::replaceMacros($cmnt_tpl, [
1580 '$return_path' => '',
1581 '$jsreload' => $return_path,
1582 '$id' => $item['item_id'],
1583 '$parent' => $item['parent'],
1584 '$profile_uid' => $owner_uid,
1585 '$mylink' => $contact['url'],
1586 '$mytitle' => L10n::t('This is you'),
1587 '$myphoto' => $contact['thumb'],
1588 '$comment' => L10n::t('Comment'),
1589 '$submit' => L10n::t('Submit'),
1590 '$preview' => L10n::t('Preview'),
1591 '$sourceapp' => L10n::t($a->sourcename),
1593 '$rand_num' => Crypto::randomDigits(12)
1598 $response_verbs = ['like'];
1599 $response_verbs[] = 'dislike';
1600 $responses = get_responses($conv_responses, $response_verbs, '', $link_item);
1602 $paginate = $pager->renderFull($total);
1605 $photo_tpl = Renderer::getMarkupTemplate('photo_view.tpl');
1606 $o .= Renderer::replaceMacros($photo_tpl, [
1607 '$id' => $ph[0]['id'],
1608 '$album' => [$album_link, $ph[0]['album']],
1612 '$prevlink' => $prevlink,
1613 '$nextlink' => $nextlink,
1614 '$desc' => $ph[0]['desc'],
1618 '$map_text' => L10n::t('Map'),
1619 '$likebuttons' => $likebuttons,
1621 '$dislike' => $dislike,
1622 'responses' => $responses,
1623 '$comments' => $comments,
1624 '$paginate' => $paginate,
1627 $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="summary_large_image" />' . "\n";
1628 $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1629 $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . $photo["href"] . '" />' . "\n";
1630 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1631 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1636 // Default - show recent photos with upload link (if applicable)
1639 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1640 $sql_extra GROUP BY `resource-id`",
1641 intval($a->data['user']['uid']),
1642 DBA::escape('Contact Photos'),
1643 DBA::escape(L10n::t('Contact Photos'))
1645 if (DBA::isResult($r)) {
1649 $pager = new Pager($a->query_string, 20);
1651 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1652 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1653 ANY_VALUE(`created`) AS `created` FROM `photo`
1654 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1655 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1656 intval($a->data['user']['uid']),
1657 DBA::escape('Contact Photos'),
1658 DBA::escape(L10n::t('Contact Photos')),
1660 $pager->getItemsPerPage()
1664 if (DBA::isResult($r)) {
1665 // "Twist" is only used for the duepunto theme with style "slackr"
1667 foreach ($r as $rr) {
1668 //hide profile photos to others
1669 if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos'))) {
1674 $ext = $phototypes[$rr['type']];
1676 $alt_e = $rr['filename'];
1677 $name_e = $rr['album'];
1681 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1682 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1683 'title' => L10n::t('View Photo'),
1684 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1687 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1689 'alt' => L10n::t('View Album'),
1696 $tpl = Renderer::getMarkupTemplate('photos_recent.tpl');
1697 $o .= Renderer::replaceMacros($tpl, [
1698 '$title' => L10n::t('Recent Photos'),
1699 '$can_post' => $can_post,
1700 '$upload' => [L10n::t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'],
1701 '$photos' => $photos,
1702 '$paginate' => $pager->renderFull($total),