7 use Friendica\Content\Feature;
8 use Friendica\Content\Nav;
9 use Friendica\Content\Text\BBCode;
10 use Friendica\Core\Addon;
11 use Friendica\Core\Config;
12 use Friendica\Core\L10n;
13 use Friendica\Core\System;
14 use Friendica\Core\Worker;
15 use Friendica\Database\DBM;
16 use Friendica\Model\Contact;
17 use Friendica\Model\Group;
18 use Friendica\Model\Item;
19 use Friendica\Model\Photo;
20 use Friendica\Model\Profile;
21 use Friendica\Network\Probe;
22 use Friendica\Object\Image;
23 use Friendica\Protocol\DFRN;
24 use Friendica\Util\DateTimeFormat;
25 use Friendica\Util\Map;
26 use Friendica\Util\Temporal;
28 require_once 'include/items.php';
29 require_once 'include/acl_selectors.php';
30 require_once 'include/security.php';
32 function photos_init(App $a) {
35 DFRN::autoRedir($a, $a->argv[1]);
38 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
42 Nav::setSelected('home');
46 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
50 if (!DBM::is_result($user)) {
54 $a->data['user'] = $user[0];
55 $a->profile_uid = $user[0]['uid'];
56 $is_owner = (local_user() && (local_user() == $a->profile_uid));
58 $profile = Profile::getByNickname($nick, $a->profile_uid);
60 $account_type = Contact::getAccountType($profile);
62 $tpl = get_markup_template("vcard-widget.tpl");
64 $vcard_widget = replace_macros($tpl, [
65 '$name' => $profile['name'],
66 '$photo' => $profile['photo'],
67 '$addr' => defaults($profile, 'addr', ''),
68 '$account_type' => $account_type,
69 '$pdesc' => defaults($profile, 'pdesc', ''),
72 $albums = Photo::getAlbums($a->data['user']['uid']);
74 $albums_visible = ((intval($a->data['user']['hidewall']) && !local_user() && !remote_user()) ? false : true);
76 // add various encodings to the array so we can just loop through and pick them out in a template
77 $ret = ['success' => false];
80 $a->data['albums'] = $albums;
81 if ($albums_visible) {
82 $ret['success'] = true;
86 foreach ($albums as $k => $album) {
87 //hide profile photos to others
88 if (!$is_owner && !remote_user() && ($album['album'] == L10n::t('Profile Photos')))
91 'text' => $album['album'],
92 'total' => $album['total'],
93 'url' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
94 'urlencode' => urlencode($album['album']),
95 'bin2hex' => bin2hex($album['album'])
97 $ret['albums'][] = $entry;
101 if (local_user() && $a->data['user']['uid'] == local_user()) {
105 if ($ret['success']) {
106 $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'), [
107 '$nick' => $a->data['user']['nickname'],
108 '$title' => L10n::t('Photo Albums'),
109 '$recent' => L10n::t('Recent Photos'),
110 '$albums' => $ret['albums'],
111 '$baseurl' => System::baseUrl(),
112 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'],
113 '$can_post' => $can_post
118 if (!x($a->page, 'aside')) {
119 $a->page['aside'] = '';
121 $a->page['aside'] .= $vcard_widget;
122 $a->page['aside'] .= $photo_albums_widget;
124 $tpl = get_markup_template("photos_head.tpl");
125 $a->page['htmlhead'] .= replace_macros($tpl,[
126 '$ispublic' => L10n::t('everybody')
133 function photos_post(App $a)
135 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
136 logger('mod_photos: REQUEST ' . print_r($_REQUEST, true), LOGGER_DATA);
137 logger('mod_photos: FILES ' . print_r($_FILES, true), LOGGER_DATA);
139 $phototypes = Image::supportedTypes();
144 $page_owner_uid = $a->data['user']['uid'];
145 $community_page = $a->data['user']['page-flags'] == PAGE_COMMUNITY;
147 if (local_user() && (local_user() == $page_owner_uid)) {
150 if ($community_page && remote_user()) {
152 if (x($_SESSION, 'remote') && is_array($_SESSION['remote'])) {
153 foreach ($_SESSION['remote'] as $v) {
154 if ($v['uid'] == $page_owner_uid) {
155 $contact_id = $v['cid'];
161 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
163 intval($page_owner_uid)
165 if (DBM::is_result($r)) {
167 $visitor = $contact_id;
174 notice(L10n::t('Permission denied.') . EOL );
178 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
179 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
180 intval($page_owner_uid)
183 if (!DBM::is_result($r)) {
184 notice(L10n::t('Contact information unavailable') . EOL);
185 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
189 $owner_record = $r[0];
191 if ($a->argc > 3 && $a->argv[2] === 'album') {
192 $album = hex2bin($a->argv[3]);
194 if ($album === L10n::t('Profile Photos') || $album === 'Contact Photos' || $album === L10n::t('Contact Photos')) {
195 goaway($_SESSION['photo_return']);
196 return; // NOTREACHED
199 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
201 intval($page_owner_uid)
203 if (!DBM::is_result($r)) {
204 notice(L10n::t('Album not found.') . EOL);
205 goaway($_SESSION['photo_return']);
206 return; // NOTREACHED
209 // Check if the user has responded to a delete confirmation query
210 if ($_REQUEST['canceled']) {
211 goaway($_SESSION['photo_return']);
214 // RENAME photo album
215 $newalbum = notags(trim($_POST['albumname']));
216 if ($newalbum != $album) {
217 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
220 intval($page_owner_uid)
222 // Update the photo albums cache
223 Photo::clearAlbumCache($page_owner_uid);
225 $newurl = str_replace(bin2hex($album), bin2hex($newalbum), $_SESSION['photo_return']);
227 return; // NOTREACHED
231 * DELETE photo album and all its photos
234 if ($_POST['dropalbum'] == L10n::t('Delete Album')) {
235 // Check if we should do HTML-based delete confirmation
236 if (x($_REQUEST, 'confirm')) {
237 $drop_url = $a->query_string;
239 ['name' => 'albumname', 'value' => $_POST['albumname']],
241 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
243 '$message' => L10n::t('Do you really want to delete this photo album and all its photos?'),
244 '$extra_inputs' => $extra_inputs,
245 '$confirm' => L10n::t('Delete Album'),
246 '$confirm_url' => $drop_url,
247 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
248 '$cancel' => L10n::t('Cancel'),
250 $a->error = 1; // Set $a->error so the other module functions don't execute
256 // get the list of photos we are about to delete
259 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
261 intval($page_owner_uid),
265 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
266 intval(local_user()),
270 if (DBM::is_result($r)) {
271 foreach ($r as $rr) {
272 $res[] = "'" . dbesc($rr['rid']) . "'" ;
275 goaway($_SESSION['photo_return']);
276 return; // NOTREACHED
279 $str_res = implode(',', $res);
281 // remove the associated photos
282 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
283 intval($page_owner_uid)
286 // find and delete the corresponding item with all the comments and likes/dislikes
287 $r = q("SELECT `id` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
288 intval($page_owner_uid)
290 if (DBM::is_result($r)) {
291 foreach ($r as $rr) {
292 Item::deleteById($rr['id']);
296 // Update the photo albums cache
297 Photo::clearAlbumCache($page_owner_uid);
300 goaway('photos/' . $a->data['user']['nickname']);
301 return; // NOTREACHED
305 // Check if the user has responded to a delete confirmation query for a single photo
306 if ($a->argc > 2 && x($_REQUEST, 'canceled')) {
307 goaway($_SESSION['photo_return']);
310 if ($a->argc > 2 && defaults($_POST, 'delete', '') === L10n::t('Delete Photo')) {
312 // same as above but remove single photo
314 // Check if we should do HTML-based delete confirmation
315 if (x($_REQUEST, 'confirm')) {
316 $drop_url = $a->query_string;
317 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
319 '$message' => L10n::t('Do you really want to delete this photo?'),
320 '$extra_inputs' => [],
321 '$confirm' => L10n::t('Delete Photo'),
322 '$confirm_url' => $drop_url,
323 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
324 '$cancel' => L10n::t('Cancel'),
326 $a->error = 1; // Set $a->error so the other module functions don't execute
331 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
333 intval($page_owner_uid),
337 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
338 intval(local_user()),
342 if (DBM::is_result($r)) {
343 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
344 intval($page_owner_uid),
345 dbesc($r[0]['resource-id'])
347 $i = q("SELECT `id` FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
348 dbesc($r[0]['resource-id']),
349 intval($page_owner_uid)
351 if (DBM::is_result($i)) {
352 Item::deleteById($i[0]['id']);
354 // Update the photo albums cache
355 Photo::clearAlbumCache($page_owner_uid);
359 goaway('photos/' . $a->data['user']['nickname']);
360 return; // NOTREACHED
363 if ($a->argc > 2 && (x($_POST, 'desc') !== false || x($_POST, 'newtag') !== false || x($_POST, 'albname') !== false)) {
364 $desc = x($_POST, 'desc') ? notags(trim($_POST['desc'])) : '';
365 $rawtags = x($_POST, 'newtag') ? notags(trim($_POST['newtag'])) : '';
366 $item_id = x($_POST, 'item_id') ? intval($_POST['item_id']) : 0;
367 $albname = x($_POST, 'albname') ? notags(trim($_POST['albname'])) : '';
368 $origaname = x($_POST, 'origaname') ? notags(trim($_POST['origaname'])) : '';
369 $str_group_allow = perms2str($_POST['group_allow']);
370 $str_contact_allow = perms2str($_POST['contact_allow']);
371 $str_group_deny = perms2str($_POST['group_deny']);
372 $str_contact_deny = perms2str($_POST['contact_deny']);
374 $resource_id = $a->argv[2];
376 if (!strlen($albname)) {
377 $albname = DateTimeFormat::localNow('Y');
380 if (x($_POST,'rotate') !== false &&
381 (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
384 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0 LIMIT 1",
386 intval($page_owner_uid)
388 if (DBM::is_result($r)) {
389 $Image = new Image($r[0]['data'], $r[0]['type']);
390 if ($Image->isValid()) {
391 $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
392 $Image->rotate($rotate_deg);
394 $width = $Image->getWidth();
395 $height = $Image->getHeight();
397 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0",
398 dbesc($Image->asString()),
402 intval($page_owner_uid)
405 if ($width > 640 || $height > 640) {
406 $Image->scaleDown(640);
407 $width = $Image->getWidth();
408 $height = $Image->getHeight();
410 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 1",
411 dbesc($Image->asString()),
415 intval($page_owner_uid)
419 if ($width > 320 || $height > 320) {
420 $Image->scaleDown(320);
421 $width = $Image->getWidth();
422 $height = $Image->getHeight();
424 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 2",
425 dbesc($Image->asString()),
429 intval($page_owner_uid)
436 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
438 intval($page_owner_uid)
440 if (DBM::is_result($p)) {
441 $ext = $phototypes[$p[0]['type']];
442 $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",
445 dbesc($str_contact_allow),
446 dbesc($str_group_allow),
447 dbesc($str_contact_deny),
448 dbesc($str_group_deny),
450 intval($page_owner_uid)
453 // Update the photo albums cache if album name was changed
454 if ($albname !== $origaname) {
455 Photo::clearAlbumCache($page_owner_uid);
459 /* Don't make the item visible if the only change was the album name */
462 if ($p[0]['desc'] !== $desc || strlen($rawtags)) {
467 // Create item container
469 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
472 $arr['guid'] = get_guid(32);
473 $arr['uid'] = $page_owner_uid;
475 $arr['parent-uri'] = $uri;
476 $arr['type'] = 'photo';
478 $arr['resource-id'] = $p[0]['resource-id'];
479 $arr['contact-id'] = $owner_record['id'];
480 $arr['owner-name'] = $owner_record['name'];
481 $arr['owner-link'] = $owner_record['url'];
482 $arr['owner-avatar'] = $owner_record['thumb'];
483 $arr['author-name'] = $owner_record['name'];
484 $arr['author-link'] = $owner_record['url'];
485 $arr['author-avatar'] = $owner_record['thumb'];
486 $arr['title'] = $title;
487 $arr['allow_cid'] = $p[0]['allow_cid'];
488 $arr['allow_gid'] = $p[0]['allow_gid'];
489 $arr['deny_cid'] = $p[0]['deny_cid'];
490 $arr['deny_gid'] = $p[0]['deny_gid'];
491 $arr['visible'] = $visibility;
494 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
495 . '[img]' . System::baseUrl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
498 $item_id = Item::insert($arr);
502 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
504 intval($page_owner_uid)
507 if (DBM::is_result($r)) {
508 $old_tag = $r[0]['tag'];
509 $old_inform = $r[0]['inform'];
512 if (strlen($rawtags)) {
516 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
517 $x = substr($rawtags, 0, 1);
518 if ($x !== '@' && $x !== '#') {
519 $rawtags = '#' . $rawtags;
523 $tags = get_tags($rawtags);
526 foreach ($tags as $tag) {
527 if (strpos($tag, '@') === 0) {
529 $name = substr($tag,1);
530 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
532 $links = @Probe::lrdd($name);
534 foreach ($links as $link) {
535 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
536 $profile = $link['@attributes']['href'];
538 if ($link['@attributes']['rel'] === 'salmon') {
539 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
540 if (strlen($inform)) {
547 $taginfo[] = [$newname, $profile, $salmon];
552 if (strrpos($newname, '+')) {
553 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
557 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
562 $newname = str_replace('_',' ',$name);
564 //select someone from this user's contacts by name
565 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
567 intval($page_owner_uid)
570 if (!DBM::is_result($r)) {
571 //select someone by attag or nick and the name passed in
572 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
575 intval($page_owner_uid)
580 if (DBM::is_result($r)) {
581 $newname = $r[0]['name'];
582 $profile = $r[0]['url'];
583 $notify = 'cid:' . $r[0]['id'];
584 if (strlen($inform)) {
591 if (substr($notify, 0, 4) === 'cid:') {
592 $taginfo[] = [$newname, $profile, $notify, $r[0], '@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]'];
594 $taginfo[] = [$newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'];
596 if (strlen($str_tags)) {
599 $profile = str_replace(',', '%2c', $profile);
600 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
602 } elseif (strpos($tag, '#') === 0) {
603 $tagname = substr($tag, 1);
604 $str_tags .= '#[url=' . System::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url]';
610 if (strlen($newtag) && strlen($str_tags)) {
613 $newtag .= $str_tags;
615 $newinform = $old_inform;
616 if (strlen($newinform) && strlen($inform)) {
619 $newinform .= $inform;
621 $fields = ['tag' => $newtag, 'inform' => $newinform, 'edited' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()];
622 $condition = ['id' => $item_id];
623 Item::update($fields, $condition);
626 foreach ($p as $scales) {
627 if (intval($scales['scale']) == 2) {
631 if (intval($scales['scale']) == 4) {
637 if (count($taginfo)) {
638 foreach ($taginfo as $tagged) {
639 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
642 $arr['guid'] = get_guid(32);
643 $arr['uid'] = $page_owner_uid;
645 $arr['parent-uri'] = $uri;
646 $arr['type'] = 'activity';
648 $arr['contact-id'] = $owner_record['id'];
649 $arr['owner-name'] = $owner_record['name'];
650 $arr['owner-link'] = $owner_record['url'];
651 $arr['owner-avatar'] = $owner_record['thumb'];
652 $arr['author-name'] = $owner_record['name'];
653 $arr['author-link'] = $owner_record['url'];
654 $arr['author-avatar'] = $owner_record['thumb'];
656 $arr['allow_cid'] = $p[0]['allow_cid'];
657 $arr['allow_gid'] = $p[0]['allow_gid'];
658 $arr['deny_cid'] = $p[0]['deny_cid'];
659 $arr['deny_gid'] = $p[0]['deny_gid'];
661 $arr['verb'] = ACTIVITY_TAG;
662 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
663 $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
664 $arr['tag'] = $tagged[4];
665 $arr['inform'] = $tagged[2];
667 $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]') ;
668 $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" ;
670 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
671 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
673 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
675 $arr['object'] .= '</link></object>' . "\n";
677 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $p[0]['desc'] . '</title><id>'
678 . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
679 $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>';
681 $item_id = Item::insert($arr);
683 Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
688 goaway($_SESSION['photo_return']);
689 return; // NOTREACHED
693 // default post action - upload a photo
694 Addon::callHooks('photo_post_init', $_POST);
696 // Determine the album to use
697 $album = x($_REQUEST, 'album') ? notags(trim($_REQUEST['album'])) : '';
698 $newalbum = x($_REQUEST, 'newalbum') ? notags(trim($_REQUEST['newalbum'])) : '';
700 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
702 if (!strlen($album)) {
703 if (strlen($newalbum)) {
706 $album = DateTimeFormat::localNow('Y');
711 * We create a wall item for every photo, but we don't want to
712 * overwhelm the data stream with a hundred newly uploaded photos.
713 * So we will make the first photo uploaded to this album in the last several hours
714 * visible by default, the rest will become visible over time when and if
715 * they acquire comments, likes, dislikes, and/or tags
718 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
720 intval($page_owner_uid)
722 if (!DBM::is_result($r) || ($album == L10n::t('Profile Photos'))) {
728 if (x($_REQUEST, 'not_visible') && $_REQUEST['not_visible'] !== 'false') {
732 $group_allow = defaults($_REQUEST, 'group_allow' , []);
733 $contact_allow = defaults($_REQUEST, 'contact_allow', []);
734 $group_deny = defaults($_REQUEST, 'group_deny' , []);
735 $contact_deny = defaults($_REQUEST, 'contact_deny' , []);
737 $str_group_allow = perms2str(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
738 $str_contact_allow = perms2str(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
739 $str_group_deny = perms2str(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
740 $str_contact_deny = perms2str(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
742 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
744 Addon::callHooks('photo_post_file', $ret);
746 if (x($ret, 'src') && x($ret, 'filesize')) {
748 $filename = $ret['filename'];
749 $filesize = $ret['filesize'];
750 $type = $ret['type'];
751 $error = UPLOAD_ERR_OK;
753 $src = $_FILES['userfile']['tmp_name'];
754 $filename = basename($_FILES['userfile']['name']);
755 $filesize = intval($_FILES['userfile']['size']);
756 $type = $_FILES['userfile']['type'];
757 $error = $_FILES['userfile']['error'];
760 if ($error !== UPLOAD_ERR_OK) {
762 case UPLOAD_ERR_INI_SIZE:
763 notice(L10n::t('Image exceeds size limit of %s', ini_get('upload_max_filesize')) . EOL);
765 case UPLOAD_ERR_FORM_SIZE:
766 notice(L10n::t('Image exceeds size limit of %s', formatBytes(defaults($_REQUEST, 'MAX_FILE_SIZE', 0))) . EOL);
768 case UPLOAD_ERR_PARTIAL:
769 notice(L10n::t('Image upload didn\'t complete, please try again') . EOL);
771 case UPLOAD_ERR_NO_FILE:
772 notice(L10n::t('Image file is missing') . EOL);
774 case UPLOAD_ERR_NO_TMP_DIR:
775 case UPLOAD_ERR_CANT_WRITE:
776 case UPLOAD_ERR_EXTENSION:
777 notice(L10n::t('Server can\'t accept new file upload at this time, please contact your administrator') . EOL);
782 Addon::callHooks('photo_post_end', $foo);
787 $type = Image::guessType($filename);
790 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
792 $maximagesize = Config::get('system', 'maximagesize');
794 if ($maximagesize && ($filesize > $maximagesize)) {
795 notice(L10n::t('Image exceeds size limit of %s', formatBytes($maximagesize)) . EOL);
798 Addon::callHooks('photo_post_end', $foo);
803 notice(L10n::t('Image file is empty.') . EOL);
806 Addon::callHooks('photo_post_end', $foo);
810 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
812 $imagedata = @file_get_contents($src);
814 $Image = new Image($imagedata, $type);
816 if (!$Image->isValid()) {
817 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
818 notice(L10n::t('Unable to process image.') . EOL);
821 Addon::callHooks('photo_post_end',$foo);
825 $exif = $Image->orient($src);
828 $max_length = Config::get('system', 'max_image_length');
830 $max_length = MAX_IMAGE_LENGTH;
832 if ($max_length > 0) {
833 $Image->scaleDown($max_length);
836 $width = $Image->getWidth();
837 $height = $Image->getHeight();
841 $photo_hash = photo_new_resource();
843 $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);
846 logger('mod/photos.php: photos_post(): image store failed', LOGGER_DEBUG);
847 notice(L10n::t('Image upload failed.') . EOL);
851 if ($width > 640 || $height > 640) {
852 $Image->scaleDown(640);
853 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);
857 if ($width > 320 || $height > 320) {
858 $Image->scaleDown(320);
859 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);
863 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
865 // Create item container
867 if ($exif && $exif['GPS'] && Feature::isEnabled($page_owner_uid, 'photo_location')) {
868 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
869 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
874 $arr['coord'] = $lat . ' ' . $lon;
877 $arr['guid'] = get_guid(32);
878 $arr['uid'] = $page_owner_uid;
880 $arr['parent-uri'] = $uri;
881 $arr['type'] = 'photo';
883 $arr['resource-id'] = $photo_hash;
884 $arr['contact-id'] = $owner_record['id'];
885 $arr['owner-name'] = $owner_record['name'];
886 $arr['owner-link'] = $owner_record['url'];
887 $arr['owner-avatar'] = $owner_record['thumb'];
888 $arr['author-name'] = $owner_record['name'];
889 $arr['author-link'] = $owner_record['url'];
890 $arr['author-avatar'] = $owner_record['thumb'];
892 $arr['allow_cid'] = $str_contact_allow;
893 $arr['allow_gid'] = $str_group_allow;
894 $arr['deny_cid'] = $str_contact_deny;
895 $arr['deny_gid'] = $str_group_deny;
896 $arr['visible'] = $visible;
899 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
900 . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$Image->getExt() . '[/img]'
903 $item_id = Item::insert($arr);
904 // Update the photo albums cache
905 Photo::clearAlbumCache($page_owner_uid);
908 Worker::add(PRIORITY_HIGH, "Notifier", 'wall-new', $item_id);
911 Addon::callHooks('photo_post_end', intval($item_id));
913 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
914 // if they do not wish to be redirected
916 goaway($_SESSION['photo_return']);
920 function photos_content(App $a)
924 // photos/name/upload
925 // photos/name/upload/xxxxx (xxxxx is album name)
926 // photos/name/album/xxxxx
927 // photos/name/album/xxxxx/edit
928 // photos/name/image/xxxxx
929 // photos/name/image/xxxxx/edit
931 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
932 notice(L10n::t('Public access denied.') . EOL);
936 require_once 'include/security.php';
937 require_once 'include/conversation.php';
939 if (!x($a->data,'user')) {
940 notice(L10n::t('No photos selected') . EOL );
944 $phototypes = Image::supportedTypes();
946 $_SESSION['photo_return'] = $a->cmd;
951 $datatype = $a->argv[2];
952 $datum = $a->argv[3];
953 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
954 $datatype = 'upload';
956 $datatype = 'summary';
965 // Setup permissions structures
969 $remote_contact = false;
972 $owner_uid = $a->data['user']['uid'];
974 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
976 if (local_user() && (local_user() == $owner_uid)) {
979 if ($community_page && remote_user()) {
980 if (is_array($_SESSION['remote'])) {
981 foreach ($_SESSION['remote'] as $v) {
982 if ($v['uid'] == $owner_uid) {
983 $contact_id = $v['cid'];
990 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
994 if (DBM::is_result($r)) {
997 $remote_contact = true;
998 $visitor = $contact_id;
1006 // perhaps they're visiting - but not a community page, so they wouldn't have write access
1007 if (remote_user() && !$visitor) {
1009 if (is_array($_SESSION['remote'])) {
1010 foreach ($_SESSION['remote'] as $v) {
1011 if ($v['uid'] == $owner_uid) {
1012 $contact_id = $v['cid'];
1018 $groups = Group::getIdsByContactId($contact_id);
1019 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1020 intval($contact_id),
1023 if (DBM::is_result($r)) {
1025 $remote_contact = true;
1030 if (!$remote_contact && local_user()) {
1031 $contact_id = $_SESSION['cid'];
1032 $contact = $a->contact;
1035 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
1036 notice(L10n::t('Access to this item is restricted.') . EOL);
1040 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
1045 $is_owner = (local_user() && (local_user() == $owner_uid));
1046 $o .= Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
1048 // Display upload form
1049 if ($datatype === 'upload') {
1051 notice(L10n::t('Permission denied.'));
1055 $selname = $datum ? hex2bin($datum) : '';
1059 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '> </option>';
1060 if (count($a->data['albums'])) {
1061 foreach ($a->data['albums'] as $album) {
1062 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos'))) {
1065 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1066 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1072 $ret = ['post_url' => 'photos/' . $a->data['user']['nickname'],
1073 'addon_text' => $uploader,
1074 'default_upload' => true];
1076 Addon::callHooks('photo_upload_form',$ret);
1078 $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), []);
1079 $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), [
1080 '$submit' => L10n::t('Submit'),
1083 $usage_message = '';
1085 $tpl = get_markup_template('photos_upload.tpl');
1087 $aclselect_e = ($visitor ? '' : populate_acl($a->user));
1089 $o .= replace_macros($tpl,[
1090 '$pagename' => L10n::t('Upload Photos'),
1091 '$sessid' => session_id(),
1092 '$usage' => $usage_message,
1093 '$nickname' => $a->data['user']['nickname'],
1094 '$newalbum' => L10n::t('New album name: '),
1095 '$existalbumtext' => L10n::t('or existing album name: '),
1096 '$nosharetext' => L10n::t('Do not show a status post for this upload'),
1097 '$albumselect' => $albumselect,
1098 '$permissions' => L10n::t('Permissions'),
1099 '$aclselect' => $aclselect_e,
1100 '$alt_uploader' => $ret['addon_text'],
1101 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
1102 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
1103 '$uploadurl' => $ret['post_url'],
1105 // ACL permissions box
1106 '$group_perms' => L10n::t('Show to Groups'),
1107 '$contact_perms' => L10n::t('Show to Contacts'),
1108 '$return_path' => $a->query_string,
1114 // Display a single photo album
1115 if ($datatype === 'album') {
1116 $album = hex2bin($datum);
1118 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1119 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1123 if (DBM::is_result($r)) {
1124 $a->set_pager_total(count($r));
1125 $a->set_pager_itemspage(20);
1128 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1129 $order_field = defaults($_GET, 'order', '');
1130 if ($order_field === 'posted') {
1136 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1137 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1138 ANY_VALUE(`created`) as `created`
1139 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1140 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1143 intval($a->pager['start']),
1144 intval($a->pager['itemspage'])
1148 if ($cmd === 'edit') {
1149 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos'))) {
1151 $edit_tpl = get_markup_template('album_edit.tpl');
1155 $o .= replace_macros($edit_tpl,[
1156 '$nametext' => L10n::t('New album name: '),
1157 '$nickname' => $a->data['user']['nickname'],
1158 '$album' => $album_e,
1159 '$hexalbum' => bin2hex($album),
1160 '$submit' => L10n::t('Submit'),
1161 '$dropsubmit' => L10n::t('Delete Album')
1166 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos')) && $can_post) {
1167 $edit = [L10n::t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1171 if ($order_field === 'posted') {
1172 $order = [L10n::t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album)];
1174 $order = [L10n::t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted'];
1179 if (DBM::is_result($r)) {
1180 // "Twist" is only used for the duepunto theme with style "slackr"
1182 foreach ($r as $rr) {
1185 $ext = $phototypes[$rr['type']];
1187 $imgalt_e = $rr['filename'];
1188 $desc_e = $rr['desc'];
1192 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1193 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1194 . ($order_field === 'posted' ? '?f=&order=posted' : ''),
1195 'title' => L10n::t('View Photo'),
1196 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1200 'hash'=> $rr['resource-id'],
1205 $tpl = get_markup_template('photo_album.tpl');
1206 $o .= replace_macros($tpl, [
1207 '$photos' => $photos,
1209 '$can_post' => $can_post,
1210 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)],
1213 '$paginate' => paginate($a),
1220 // Display one photo
1221 if ($datatype === 'image') {
1222 // fetch image, item containing image, then comments
1223 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1224 $sql_extra ORDER BY `scale` ASC ",
1229 if (!DBM::is_result($ph)) {
1230 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1235 if (DBM::is_result($ph)) {
1236 notice(L10n::t('Permission denied. Access to this item may be restricted.'));
1238 notice(L10n::t('Photo not available') . EOL );
1246 /// @todo This query is totally bad, the whole functionality has to be changed
1247 // The query leads to a really intense used index.
1248 // By now we hide it if someone wants to.
1249 if (!Config::get('system', 'no_count', false)) {
1250 $order_field = defaults($_GET, 'order', '');
1251 if ($order_field === 'posted') {
1257 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1258 $sql_extra ORDER BY `created` $order ",
1259 dbesc($ph[0]['album']),
1263 if (DBM::is_result($prvnxt)) {
1264 foreach ($prvnxt as $z => $entry) {
1265 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1269 $prv = count($prvnxt) - 1;
1271 if ($nxt >= count($prvnxt)) {
1277 $edit_suffix = ((($cmd === 'edit') && $can_post) ? '/edit' : '');
1278 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1279 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1283 if (count($ph) == 1)
1284 $hires = $lores = $ph[0];
1285 if (count($ph) > 1) {
1286 if ($ph[1]['scale'] == 2) {
1287 // original is 640 or less, we can display it directly
1288 $hires = $lores = $ph[0];
1295 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1299 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1301 'edit' => ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? L10n::t('View photo') : L10n::t('Edit photo'))],
1302 'profile'=>['profile_photo/use/'.$ph[0]['resource-id'], L10n::t('Use as profile photo')],
1306 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1307 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1308 ? L10n::t('Private Message')
1314 if ( $cmd === 'edit') {
1315 $tpl = get_markup_template('photo_edit_head.tpl');
1316 $a->page['htmlhead'] .= replace_macros($tpl,[
1317 '$prevlink' => $prevlink,
1318 '$nextlink' => $nextlink
1323 $prevlink = [$prevlink, '<div class="icon prev"></div>'] ;
1326 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1327 'title'=> L10n::t('View Full Size'),
1328 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . DateTimeFormat::utcNow('ymdhis'),
1329 'height' => $hires['height'],
1330 'width' => $hires['width'],
1331 'album' => $hires['album'],
1332 'filename' => $hires['filename'],
1336 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1340 // Do we have an item for this photo?
1342 // FIXME! - replace following code to display the conversation with our normal
1343 // conversation functions so that it works correctly and tracks changes
1344 // in the evolving conversation code.
1345 // The difference is that we won't be displaying the conversation head item
1346 // as a "post" but displaying instead the photo it is linked to
1348 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1355 if (DBM::is_result($linked_items)) {
1356 $link_item = $linked_items[0];
1358 $r = q("SELECT COUNT(*) AS `total`
1359 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1360 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1361 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1362 AND `item`.`uid` = %d
1364 dbesc($link_item['uri']),
1365 dbesc($link_item['uri']),
1366 intval($link_item['uid'])
1370 if (DBM::is_result($r)) {
1371 $a->set_pager_total($r[0]['total']);
1375 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1376 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1377 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1378 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1379 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1380 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1381 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1382 AND `item`.`uid` = %d
1384 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1385 dbesc($link_item['uri']),
1386 dbesc($link_item['uri']),
1387 intval($link_item['uid']),
1388 intval($a->pager['start']),
1389 intval($a->pager['itemspage'])
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 $t) {
1409 if (strlen($tag_str)) {
1412 $tag_str .= BBCode::convert($t);
1414 $tags = [L10n::t('Tags: '), $tag_str];
1415 if ($cmd === 'edit') {
1416 $tags[] = 'tagrm/' . $link_item['id'];
1417 $tags[] = L10n::t('[Remove any tag]');
1423 if ($cmd === 'edit' && $can_post) {
1424 $edit_tpl = get_markup_template('photo_edit.tpl');
1426 $album_e = $ph[0]['album'];
1427 $caption_e = $ph[0]['desc'];
1428 $aclselect_e = populate_acl($ph[0]);
1430 $edit = replace_macros($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 = get_markup_template('comment_item.tpl');
1464 $tpl = get_markup_template('photo_item.tpl');
1465 $return_url = $a->cmd;
1467 if ($can_post || can_write_wall($owner_uid)) {
1468 $like_tpl = get_markup_template('like_noshare.tpl');
1469 $likebuttons = replace_macros($like_tpl, [
1470 '$id' => $link_item['id'],
1471 '$likethis' => L10n::t("I like this \x28toggle\x29"),
1472 '$nolike' => (Feature::isEnabled(local_user(), 'dislike') ? L10n::t("I don't like this \x28toggle\x29") : ''),
1473 '$wait' => L10n::t('Please wait'),
1474 '$return_path' => $a->query_string,
1478 if (!DBM::is_result($r)) {
1479 if (($can_post || can_write_wall($owner_uid))) {
1480 $comments .= replace_macros($cmnt_tpl, [
1481 '$return_path' => '',
1482 '$jsreload' => $return_url,
1483 '$type' => 'wall-comment',
1484 '$id' => $link_item['id'],
1485 '$parent' => $link_item['id'],
1486 '$profile_uid' => $owner_uid,
1487 '$mylink' => $contact['url'],
1488 '$mytitle' => L10n::t('This is you'),
1489 '$myphoto' => $contact['thumb'],
1490 '$comment' => L10n::t('Comment'),
1491 '$submit' => L10n::t('Submit'),
1492 '$preview' => L10n::t('Preview'),
1493 '$sourceapp' => L10n::t($a->sourcename),
1495 '$rand_num' => random_digits(12)
1501 'like' => ['title' => L10n::t('Likes','title')],'dislike' => ['title' => L10n::t('Dislikes','title')],
1502 'attendyes' => ['title' => L10n::t('Attending','title')], 'attendno' => ['title' => L10n::t('Not attending','title')], 'attendmaybe' => ['title' => L10n::t('Might attend','title')]
1506 if (DBM::is_result($r)) {
1507 foreach ($r as $item) {
1508 builtin_activity_puller($item, $conv_responses);
1511 if (x($conv_responses['like'], $link_item['uri'])) {
1512 $like = format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like', $link_item['id']);
1514 if (x($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 || can_write_wall($owner_uid))) {
1519 $comments .= replace_macros($cmnt_tpl,[
1520 '$return_path' => '',
1521 '$jsreload' => $return_url,
1522 '$type' => 'wall-comment',
1523 '$id' => $link_item['id'],
1524 '$parent' => $link_item['id'],
1525 '$profile_uid' => $owner_uid,
1526 '$mylink' => $contact['url'],
1527 '$mytitle' => L10n::t('This is you'),
1528 '$myphoto' => $contact['thumb'],
1529 '$comment' => L10n::t('Comment'),
1530 '$submit' => L10n::t('Submit'),
1531 '$preview' => L10n::t('Preview'),
1532 '$sourceapp' => L10n::t($a->sourcename),
1534 '$rand_num' => random_digits(12)
1538 foreach ($r as $item) {
1543 if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) {
1547 $redirect_url = 'redir/' . $item['cid'];
1549 if (local_user() && ($item['contact-uid'] == local_user())
1550 && ($item['network'] == NETWORK_DFRN) && !$item['self']) {
1551 $profile_url = $redirect_url;
1552 $sparkle = ' sparkle';
1554 $profile_url = $item['url'];
1558 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1560 $profile_name = ((strlen($item['author-name']) && $diff_author) ? $item['author-name'] : $item['name']);
1561 $profile_avatar = ((strlen($item['author-avatar']) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1563 $profile_link = $profile_url;
1565 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1567 'dropping' => $dropping,
1568 'pagedrop' => false,
1569 'select' => L10n::t('Select'),
1570 'delete' => L10n::t('Delete'),
1573 $name_e = $profile_name;
1574 $title_e = $item['title'];
1575 $body_e = BBCode::convert($item['body']);
1577 $comments .= replace_macros($template,[
1578 '$id' => $item['item_id'],
1579 '$profile_url' => $profile_link,
1581 '$thumb' => $profile_avatar,
1582 '$sparkle' => $sparkle,
1583 '$title' => $title_e,
1585 '$ago' => Temporal::getRelativeDate($item['created']),
1586 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1588 '$comment' => $comment
1591 if (($can_post || can_write_wall($owner_uid))) {
1592 $comments .= replace_macros($cmnt_tpl, [
1593 '$return_path' => '',
1594 '$jsreload' => $return_url,
1595 '$type' => 'wall-comment',
1596 '$id' => $item['item_id'],
1597 '$parent' => $item['parent'],
1598 '$profile_uid' => $owner_uid,
1599 '$mylink' => $contact['url'],
1600 '$mytitle' => L10n::t('This is you'),
1601 '$myphoto' => $contact['thumb'],
1602 '$comment' => L10n::t('Comment'),
1603 '$submit' => L10n::t('Submit'),
1604 '$preview' => L10n::t('Preview'),
1605 '$sourceapp' => L10n::t($a->sourcename),
1607 '$rand_num' => random_digits(12)
1612 $response_verbs = ['like'];
1613 if (Feature::isEnabled($owner_uid, 'dislike')) {
1614 $response_verbs[] = 'dislike';
1616 $responses = get_responses($conv_responses, $response_verbs, '', $link_item);
1618 $paginate = paginate($a);
1621 $photo_tpl = get_markup_template('photo_view.tpl');
1622 $o .= replace_macros($photo_tpl, [
1623 '$id' => $ph[0]['id'],
1624 '$album' => [$album_link, $ph[0]['album']],
1628 '$prevlink' => $prevlink,
1629 '$nextlink' => $nextlink,
1630 '$desc' => $ph[0]['desc'],
1634 '$map_text' => L10n::t('Map'),
1635 '$likebuttons' => $likebuttons,
1637 '$dislike' => $dislike,
1638 'responses' => $responses,
1639 '$comments' => $comments,
1640 '$paginate' => $paginate,
1643 $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="photo" />' . "\n";
1644 $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1645 $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . $photo["href"] . '" />' . "\n";
1646 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1647 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1652 // Default - show recent photos with upload link (if applicable)
1655 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1656 $sql_extra GROUP BY `resource-id`",
1657 intval($a->data['user']['uid']),
1658 dbesc('Contact Photos'),
1659 dbesc(L10n::t('Contact Photos'))
1661 if (DBM::is_result($r)) {
1662 $a->set_pager_total(count($r));
1663 $a->set_pager_itemspage(20);
1666 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1667 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1668 ANY_VALUE(`created`) AS `created` FROM `photo`
1669 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1670 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1671 intval($a->data['user']['uid']),
1672 dbesc('Contact Photos'),
1673 dbesc(L10n::t('Contact Photos')),
1674 intval($a->pager['start']),
1675 intval($a->pager['itemspage'])
1679 if (DBM::is_result($r)) {
1680 // "Twist" is only used for the duepunto theme with style "slackr"
1682 foreach ($r as $rr) {
1683 //hide profile photos to others
1684 if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos')))
1689 $ext = $phototypes[$rr['type']];
1691 $alt_e = $rr['filename'];
1692 $name_e = $rr['album'];
1696 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1697 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1698 'title' => L10n::t('View Photo'),
1699 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1702 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1704 'alt' => L10n::t('View Album'),
1711 $tpl = get_markup_template('photos_recent.tpl');
1712 $o .= replace_macros($tpl, [
1713 '$title' => L10n::t('Recent Photos'),
1714 '$can_post' => $can_post,
1715 '$upload' => [L10n::t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'],
1716 '$photos' => $photos,
1717 '$paginate' => paginate($a),