6 use Friendica\Content\Feature;
7 use Friendica\Content\Nav;
8 use Friendica\Core\Addon;
9 use Friendica\Core\L10n;
10 use Friendica\Core\System;
11 use Friendica\Core\Config;
12 use Friendica\Core\Worker;
13 use Friendica\Database\DBM;
14 use Friendica\Model\Contact;
15 use Friendica\Model\Group;
16 use Friendica\Model\Photo;
17 use Friendica\Model\Profile;
18 use Friendica\Network\Probe;
19 use Friendica\Object\Image;
20 use Friendica\Protocol\DFRN;
22 require_once 'include/items.php';
23 require_once 'include/acl_selectors.php';
24 require_once 'include/bbcode.php';
25 require_once 'include/security.php';
26 require_once 'include/tags.php';
27 require_once 'include/threads.php';
29 function photos_init(App $a) {
32 DFRN::autoRedir($a, $a->argv[1]);
35 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
39 Nav::setSelected('home');
43 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
47 if (!DBM::is_result($user)) {
51 $a->data['user'] = $user[0];
52 $a->profile_uid = $user[0]['uid'];
53 $is_owner = (local_user() && (local_user() == $a->profile_uid));
55 $profile = Profile::getByNickname($nick, $a->profile_uid);
57 $account_type = Contact::getAccountType($profile);
59 $tpl = get_markup_template("vcard-widget.tpl");
61 $vcard_widget = replace_macros($tpl, [
62 '$name' => $profile['name'],
63 '$photo' => $profile['photo'],
64 '$addr' => defaults($profile, 'addr', ''),
65 '$account_type' => $account_type,
66 '$pdesc' => defaults($profile, 'pdesc', ''),
69 $albums = Photo::getAlbums($a->data['user']['uid']);
71 $albums_visible = ((intval($a->data['user']['hidewall']) && !local_user() && !remote_user()) ? false : true);
73 // add various encodings to the array so we can just loop through and pick them out in a template
74 $ret = ['success' => false];
77 $a->data['albums'] = $albums;
78 if ($albums_visible) {
79 $ret['success'] = true;
83 foreach ($albums as $k => $album) {
84 //hide profile photos to others
85 if (!$is_owner && !remote_user() && ($album['album'] == L10n::t('Profile Photos')))
88 'text' => $album['album'],
89 'total' => $album['total'],
90 'url' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
91 'urlencode' => urlencode($album['album']),
92 'bin2hex' => bin2hex($album['album'])
94 $ret['albums'][] = $entry;
98 if (local_user() && $a->data['user']['uid'] == local_user()) {
102 if ($ret['success']) {
103 $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'), [
104 '$nick' => $a->data['user']['nickname'],
105 '$title' => L10n::t('Photo Albums'),
106 '$recent' => L10n::t('Recent Photos'),
107 '$albums' => $ret['albums'],
108 '$baseurl' => System::baseUrl(),
109 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'],
110 '$can_post' => $can_post
115 if (!x($a->page, 'aside')) {
116 $a->page['aside'] = '';
118 $a->page['aside'] .= $vcard_widget;
119 $a->page['aside'] .= $photo_albums_widget;
121 $tpl = get_markup_template("photos_head.tpl");
122 $a->page['htmlhead'] .= replace_macros($tpl,[
123 '$ispublic' => L10n::t('everybody')
130 function photos_post(App $a)
132 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
133 logger('mod_photos: REQUEST ' . print_r($_REQUEST, true), LOGGER_DATA);
134 logger('mod_photos: FILES ' . print_r($_FILES, true), LOGGER_DATA);
136 $phototypes = Image::supportedTypes();
141 $page_owner_uid = $a->data['user']['uid'];
142 $community_page = $a->data['user']['page-flags'] == PAGE_COMMUNITY;
144 if (local_user() && (local_user() == $page_owner_uid)) {
147 if ($community_page && remote_user()) {
149 if (x($_SESSION, 'remote') && is_array($_SESSION['remote'])) {
150 foreach ($_SESSION['remote'] as $v) {
151 if ($v['uid'] == $page_owner_uid) {
152 $contact_id = $v['cid'];
158 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
160 intval($page_owner_uid)
162 if (DBM::is_result($r)) {
164 $visitor = $contact_id;
171 notice(L10n::t('Permission denied.') . EOL );
175 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
176 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
177 intval($page_owner_uid)
180 if (!DBM::is_result($r)) {
181 notice(L10n::t('Contact information unavailable') . EOL);
182 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
186 $owner_record = $r[0];
188 if ($a->argc > 3 && $a->argv[2] === 'album') {
189 $album = hex2bin($a->argv[3]);
191 if ($album === L10n::t('Profile Photos') || $album === 'Contact Photos' || $album === L10n::t('Contact Photos')) {
192 goaway($_SESSION['photo_return']);
193 return; // NOTREACHED
196 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
198 intval($page_owner_uid)
200 if (!DBM::is_result($r)) {
201 notice(L10n::t('Album not found.') . EOL);
202 goaway($_SESSION['photo_return']);
203 return; // NOTREACHED
206 // Check if the user has responded to a delete confirmation query
207 if ($_REQUEST['canceled']) {
208 goaway($_SESSION['photo_return']);
211 // RENAME photo album
212 $newalbum = notags(trim($_POST['albumname']));
213 if ($newalbum != $album) {
214 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
217 intval($page_owner_uid)
219 // Update the photo albums cache
220 Photo::clearAlbumCache($page_owner_uid);
222 $newurl = str_replace(bin2hex($album), bin2hex($newalbum), $_SESSION['photo_return']);
224 return; // NOTREACHED
228 * DELETE photo album and all its photos
231 if ($_POST['dropalbum'] == L10n::t('Delete Album')) {
232 // Check if we should do HTML-based delete confirmation
233 if (x($_REQUEST, 'confirm')) {
234 $drop_url = $a->query_string;
236 ['name' => 'albumname', 'value' => $_POST['albumname']],
238 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
240 '$message' => L10n::t('Do you really want to delete this photo album and all its photos?'),
241 '$extra_inputs' => $extra_inputs,
242 '$confirm' => L10n::t('Delete Album'),
243 '$confirm_url' => $drop_url,
244 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
245 '$cancel' => L10n::t('Cancel'),
247 $a->error = 1; // Set $a->error so the other module functions don't execute
253 // get the list of photos we are about to delete
256 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
258 intval($page_owner_uid),
262 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
263 intval(local_user()),
267 if (DBM::is_result($r)) {
268 foreach ($r as $rr) {
269 $res[] = "'" . dbesc($rr['rid']) . "'" ;
272 goaway($_SESSION['photo_return']);
273 return; // NOTREACHED
276 $str_res = implode(',', $res);
278 // remove the associated photos
279 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
280 intval($page_owner_uid)
283 // find and delete the corresponding item with all the comments and likes/dislikes
284 $r = q("SELECT `id`, `parent-uri`, `visible` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
285 intval($page_owner_uid)
287 if (DBM::is_result($r)) {
288 foreach ($r as $rr) {
289 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
290 dbesc(datetime_convert()),
291 dbesc($rr['parent-uri']),
292 intval($page_owner_uid)
294 create_tags_from_itemuri($rr['parent-uri'], $page_owner_uid);
295 delete_thread_uri($rr['parent-uri'], $page_owner_uid);
297 $drop_id = intval($rr['id']);
299 // send the notification upstream/downstream as the case may be
300 if ($rr['visible']) {
301 Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
306 // Update the photo albums cache
307 Photo::clearAlbumCache($page_owner_uid);
310 goaway('photos/' . $a->data['user']['nickname']);
311 return; // NOTREACHED
315 // Check if the user has responded to a delete confirmation query for a single photo
316 if ($a->argc > 2 && x($_REQUEST, 'canceled')) {
317 goaway($_SESSION['photo_return']);
320 if ($a->argc > 2 && defaults($_POST, 'delete', '') === L10n::t('Delete Photo')) {
322 // same as above but remove single photo
324 // Check if we should do HTML-based delete confirmation
325 if (x($_REQUEST, 'confirm')) {
326 $drop_url = $a->query_string;
327 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), [
329 '$message' => L10n::t('Do you really want to delete this photo?'),
330 '$extra_inputs' => [],
331 '$confirm' => L10n::t('Delete Photo'),
332 '$confirm_url' => $drop_url,
333 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
334 '$cancel' => L10n::t('Cancel'),
336 $a->error = 1; // Set $a->error so the other module functions don't execute
341 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
343 intval($page_owner_uid),
347 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
348 intval(local_user()),
352 if (DBM::is_result($r)) {
353 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
354 intval($page_owner_uid),
355 dbesc($r[0]['resource-id'])
357 $i = q("SELECT `id`, `uri`, `visible` FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
358 dbesc($r[0]['resource-id']),
359 intval($page_owner_uid)
361 if (DBM::is_result($i)) {
362 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
363 dbesc(datetime_convert()),
364 dbesc(datetime_convert()),
366 intval($page_owner_uid)
368 create_tags_from_itemuri($i[0]['uri'], $page_owner_uid);
369 delete_thread_uri($i[0]['uri'], $page_owner_uid);
371 $url = System::baseUrl();
372 $drop_id = intval($i[0]['id']);
374 // Update the photo albums cache
375 Photo::clearAlbumCache($page_owner_uid);
377 if ($i[0]['visible']) {
378 Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
383 goaway('photos/' . $a->data['user']['nickname']);
384 return; // NOTREACHED
387 if ($a->argc > 2 && (x($_POST, 'desc') !== false || x($_POST, 'newtag') !== false || x($_POST, 'albname') !== false)) {
388 $desc = x($_POST, 'desc') ? notags(trim($_POST['desc'])) : '';
389 $rawtags = x($_POST, 'newtag') ? notags(trim($_POST['newtag'])) : '';
390 $item_id = x($_POST, 'item_id') ? intval($_POST['item_id']) : 0;
391 $albname = x($_POST, 'albname') ? notags(trim($_POST['albname'])) : '';
392 $origaname = x($_POST, 'origaname') ? notags(trim($_POST['origaname'])) : '';
393 $str_group_allow = perms2str($_POST['group_allow']);
394 $str_contact_allow = perms2str($_POST['contact_allow']);
395 $str_group_deny = perms2str($_POST['group_deny']);
396 $str_contact_deny = perms2str($_POST['contact_deny']);
398 $resource_id = $a->argv[2];
400 if (!strlen($albname)) {
401 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
404 if (x($_POST,'rotate') !== false &&
405 (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
408 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0 LIMIT 1",
410 intval($page_owner_uid)
412 if (DBM::is_result($r)) {
413 $Image = new Image($r[0]['data'], $r[0]['type']);
414 if ($Image->isValid()) {
415 $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
416 $Image->rotate($rotate_deg);
418 $width = $Image->getWidth();
419 $height = $Image->getHeight();
421 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0",
422 dbesc($Image->asString()),
426 intval($page_owner_uid)
429 if ($width > 640 || $height > 640) {
430 $Image->scaleDown(640);
431 $width = $Image->getWidth();
432 $height = $Image->getHeight();
434 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 1",
435 dbesc($Image->asString()),
439 intval($page_owner_uid)
443 if ($width > 320 || $height > 320) {
444 $Image->scaleDown(320);
445 $width = $Image->getWidth();
446 $height = $Image->getHeight();
448 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 2",
449 dbesc($Image->asString()),
453 intval($page_owner_uid)
460 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
462 intval($page_owner_uid)
464 if (DBM::is_result($p)) {
465 $ext = $phototypes[$p[0]['type']];
466 $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",
469 dbesc($str_contact_allow),
470 dbesc($str_group_allow),
471 dbesc($str_contact_deny),
472 dbesc($str_group_deny),
474 intval($page_owner_uid)
477 // Update the photo albums cache if album name was changed
478 if ($albname !== $origaname) {
479 Photo::clearAlbumCache($page_owner_uid);
483 /* Don't make the item visible if the only change was the album name */
486 if ($p[0]['desc'] !== $desc || strlen($rawtags)) {
491 // Create item container
493 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
496 $arr['guid'] = get_guid(32);
497 $arr['uid'] = $page_owner_uid;
499 $arr['parent-uri'] = $uri;
500 $arr['type'] = 'photo';
502 $arr['resource-id'] = $p[0]['resource-id'];
503 $arr['contact-id'] = $owner_record['id'];
504 $arr['owner-name'] = $owner_record['name'];
505 $arr['owner-link'] = $owner_record['url'];
506 $arr['owner-avatar'] = $owner_record['thumb'];
507 $arr['author-name'] = $owner_record['name'];
508 $arr['author-link'] = $owner_record['url'];
509 $arr['author-avatar'] = $owner_record['thumb'];
510 $arr['title'] = $title;
511 $arr['allow_cid'] = $p[0]['allow_cid'];
512 $arr['allow_gid'] = $p[0]['allow_gid'];
513 $arr['deny_cid'] = $p[0]['deny_cid'];
514 $arr['deny_gid'] = $p[0]['deny_gid'];
515 $arr['visible'] = $visibility;
518 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
519 . '[img]' . System::baseUrl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
522 $item_id = item_store($arr);
526 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
528 intval($page_owner_uid)
531 if (DBM::is_result($r)) {
532 $old_tag = $r[0]['tag'];
533 $old_inform = $r[0]['inform'];
536 if (strlen($rawtags)) {
540 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
541 $x = substr($rawtags, 0, 1);
542 if ($x !== '@' && $x !== '#') {
543 $rawtags = '#' . $rawtags;
547 $tags = get_tags($rawtags);
550 foreach ($tags as $tag) {
551 if (strpos($tag, '@') === 0) {
553 $name = substr($tag,1);
554 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
556 $links = @Probe::lrdd($name);
558 foreach ($links as $link) {
559 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
560 $profile = $link['@attributes']['href'];
562 if ($link['@attributes']['rel'] === 'salmon') {
563 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
564 if (strlen($inform)) {
571 $taginfo[] = [$newname, $profile, $salmon];
576 if (strrpos($newname, '+')) {
577 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
581 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
586 $newname = str_replace('_',' ',$name);
588 //select someone from this user's contacts by name
589 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
591 intval($page_owner_uid)
594 if (!DBM::is_result($r)) {
595 //select someone by attag or nick and the name passed in
596 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
599 intval($page_owner_uid)
604 if (DBM::is_result($r)) {
605 $newname = $r[0]['name'];
606 $profile = $r[0]['url'];
607 $notify = 'cid:' . $r[0]['id'];
608 if (strlen($inform)) {
615 if (substr($notify, 0, 4) === 'cid:') {
616 $taginfo[] = [$newname, $profile, $notify, $r[0], '@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]'];
618 $taginfo[] = [$newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'];
620 if (strlen($str_tags)) {
623 $profile = str_replace(',', '%2c', $profile);
624 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
626 } elseif (strpos($tag, '#') === 0) {
627 $tagname = substr($tag, 1);
628 $str_tags .= '#[url=' . System::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url]';
634 if (strlen($newtag) && strlen($str_tags)) {
637 $newtag .= $str_tags;
639 $newinform = $old_inform;
640 if (strlen($newinform) && strlen($inform)) {
643 $newinform .= $inform;
645 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
648 dbesc(datetime_convert()),
649 dbesc(datetime_convert()),
651 intval($page_owner_uid)
653 create_tags_from_item($item_id);
654 update_thread($item_id);
657 foreach ($p as $scales) {
658 if (intval($scales['scale']) == 2) {
662 if (intval($scales['scale']) == 4) {
668 if (count($taginfo)) {
669 foreach ($taginfo as $tagged) {
670 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
673 $arr['guid'] = get_guid(32);
674 $arr['uid'] = $page_owner_uid;
676 $arr['parent-uri'] = $uri;
677 $arr['type'] = 'activity';
679 $arr['contact-id'] = $owner_record['id'];
680 $arr['owner-name'] = $owner_record['name'];
681 $arr['owner-link'] = $owner_record['url'];
682 $arr['owner-avatar'] = $owner_record['thumb'];
683 $arr['author-name'] = $owner_record['name'];
684 $arr['author-link'] = $owner_record['url'];
685 $arr['author-avatar'] = $owner_record['thumb'];
687 $arr['allow_cid'] = $p[0]['allow_cid'];
688 $arr['allow_gid'] = $p[0]['allow_gid'];
689 $arr['deny_cid'] = $p[0]['deny_cid'];
690 $arr['deny_gid'] = $p[0]['deny_gid'];
692 $arr['verb'] = ACTIVITY_TAG;
693 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
694 $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
695 $arr['tag'] = $tagged[4];
696 $arr['inform'] = $tagged[2];
698 $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]') ;
699 $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" ;
701 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
702 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
704 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
706 $arr['object'] .= '</link></object>' . "\n";
708 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $p[0]['desc'] . '</title><id>'
709 . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
710 $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>';
712 $item_id = item_store($arr);
714 Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
719 goaway($_SESSION['photo_return']);
720 return; // NOTREACHED
724 // default post action - upload a photo
725 Addon::callHooks('photo_post_init', $_POST);
727 // Determine the album to use
728 $album = x($_REQUEST, 'album') ? notags(trim($_REQUEST['album'])) : '';
729 $newalbum = x($_REQUEST, 'newalbum') ? notags(trim($_REQUEST['newalbum'])) : '';
731 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
733 if (!strlen($album)) {
734 if (strlen($newalbum)) {
737 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
742 * We create a wall item for every photo, but we don't want to
743 * overwhelm the data stream with a hundred newly uploaded photos.
744 * So we will make the first photo uploaded to this album in the last several hours
745 * visible by default, the rest will become visible over time when and if
746 * they acquire comments, likes, dislikes, and/or tags
749 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
751 intval($page_owner_uid)
753 if (!DBM::is_result($r) || ($album == L10n::t('Profile Photos'))) {
759 if (x($_REQUEST, 'not_visible') && $_REQUEST['not_visible'] !== 'false') {
763 $group_allow = defaults($_REQUEST, 'group_allow' , []);
764 $contact_allow = defaults($_REQUEST, 'contact_allow', []);
765 $group_deny = defaults($_REQUEST, 'group_deny' , []);
766 $contact_deny = defaults($_REQUEST, 'contact_deny' , []);
768 $str_group_allow = perms2str(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
769 $str_contact_allow = perms2str(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
770 $str_group_deny = perms2str(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
771 $str_contact_deny = perms2str(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
773 $ret = ['src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''];
775 Addon::callHooks('photo_post_file', $ret);
777 if (x($ret, 'src') && x($ret, 'filesize')) {
779 $filename = $ret['filename'];
780 $filesize = $ret['filesize'];
781 $type = $ret['type'];
782 $error = UPLOAD_ERR_OK;
784 $src = $_FILES['userfile']['tmp_name'];
785 $filename = basename($_FILES['userfile']['name']);
786 $filesize = intval($_FILES['userfile']['size']);
787 $type = $_FILES['userfile']['type'];
788 $error = $_FILES['userfile']['error'];
791 if ($error !== UPLOAD_ERR_OK) {
793 case UPLOAD_ERR_INI_SIZE:
794 notice(L10n::t('Image exceeds size limit of %s', ini_get('upload_max_filesize')) . EOL);
796 case UPLOAD_ERR_FORM_SIZE:
797 notice(L10n::t('Image exceeds size limit of %s', formatBytes(defaults($_REQUEST, 'MAX_FILE_SIZE', 0))) . EOL);
799 case UPLOAD_ERR_PARTIAL:
800 notice(L10n::t('Image upload didn\'t complete, please try again') . EOL);
802 case UPLOAD_ERR_NO_FILE:
803 notice(L10n::t('Image file is missing') . EOL);
805 case UPLOAD_ERR_NO_TMP_DIR:
806 case UPLOAD_ERR_CANT_WRITE:
807 case UPLOAD_ERR_EXTENSION:
808 notice(L10n::t('Server can\'t accept new file upload at this time, please contact your administrator') . EOL);
813 Addon::callHooks('photo_post_end', $foo);
818 $type = Image::guessType($filename);
821 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
823 $maximagesize = Config::get('system', 'maximagesize');
825 if ($maximagesize && ($filesize > $maximagesize)) {
826 notice(L10n::t('Image exceeds size limit of %s', formatBytes($maximagesize)) . EOL);
829 Addon::callHooks('photo_post_end', $foo);
834 notice(L10n::t('Image file is empty.') . EOL);
837 Addon::callHooks('photo_post_end', $foo);
841 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
843 $imagedata = @file_get_contents($src);
845 $Image = new Image($imagedata, $type);
847 if (!$Image->isValid()) {
848 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
849 notice(L10n::t('Unable to process image.') . EOL);
852 Addon::callHooks('photo_post_end',$foo);
856 $exif = $Image->orient($src);
859 $max_length = Config::get('system', 'max_image_length');
861 $max_length = MAX_IMAGE_LENGTH;
863 if ($max_length > 0) {
864 $Image->scaleDown($max_length);
867 $width = $Image->getWidth();
868 $height = $Image->getHeight();
872 $photo_hash = photo_new_resource();
874 $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);
877 logger('mod/photos.php: photos_post(): image store failed', LOGGER_DEBUG);
878 notice(L10n::t('Image upload failed.') . EOL);
882 if ($width > 640 || $height > 640) {
883 $Image->scaleDown(640);
884 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);
888 if ($width > 320 || $height > 320) {
889 $Image->scaleDown(320);
890 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);
894 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
896 // Create item container
898 if ($exif && $exif['GPS'] && Feature::isEnabled($channel_id, 'photo_location')) {
899 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
900 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
905 $arr['coord'] = $lat . ' ' . $lon;
908 $arr['guid'] = get_guid(32);
909 $arr['uid'] = $page_owner_uid;
911 $arr['parent-uri'] = $uri;
912 $arr['type'] = 'photo';
914 $arr['resource-id'] = $photo_hash;
915 $arr['contact-id'] = $owner_record['id'];
916 $arr['owner-name'] = $owner_record['name'];
917 $arr['owner-link'] = $owner_record['url'];
918 $arr['owner-avatar'] = $owner_record['thumb'];
919 $arr['author-name'] = $owner_record['name'];
920 $arr['author-link'] = $owner_record['url'];
921 $arr['author-avatar'] = $owner_record['thumb'];
923 $arr['allow_cid'] = $str_contact_allow;
924 $arr['allow_gid'] = $str_group_allow;
925 $arr['deny_cid'] = $str_contact_deny;
926 $arr['deny_gid'] = $str_group_deny;
927 $arr['visible'] = $visible;
930 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
931 . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$Image->getExt() . '[/img]'
934 $item_id = item_store($arr);
935 // Update the photo albums cache
936 Photo::clearAlbumCache($page_owner_uid);
939 Worker::add(PRIORITY_HIGH, "Notifier", 'wall-new', $item_id);
942 Addon::callHooks('photo_post_end', intval($item_id));
944 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
945 // if they do not wish to be redirected
947 goaway($_SESSION['photo_return']);
951 function photos_content(App $a)
955 // photos/name/upload
956 // photos/name/upload/xxxxx (xxxxx is album name)
957 // photos/name/album/xxxxx
958 // photos/name/album/xxxxx/edit
959 // photos/name/image/xxxxx
960 // photos/name/image/xxxxx/edit
962 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
963 notice(L10n::t('Public access denied.') . EOL);
967 require_once 'include/bbcode.php';
968 require_once 'include/security.php';
969 require_once 'include/conversation.php';
971 if (!x($a->data,'user')) {
972 notice(L10n::t('No photos selected') . EOL );
976 $phototypes = Image::supportedTypes();
978 $_SESSION['photo_return'] = $a->cmd;
983 $datatype = $a->argv[2];
984 $datum = $a->argv[3];
985 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
986 $datatype = 'upload';
988 $datatype = 'summary';
997 // Setup permissions structures
1001 $remote_contact = false;
1004 $owner_uid = $a->data['user']['uid'];
1006 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
1008 if (local_user() && (local_user() == $owner_uid)) {
1011 if ($community_page && remote_user()) {
1012 if (is_array($_SESSION['remote'])) {
1013 foreach ($_SESSION['remote'] as $v) {
1014 if ($v['uid'] == $owner_uid) {
1015 $contact_id = $v['cid'];
1022 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1023 intval($contact_id),
1026 if (DBM::is_result($r)) {
1029 $remote_contact = true;
1030 $visitor = $contact_id;
1038 // perhaps they're visiting - but not a community page, so they wouldn't have write access
1039 if (remote_user() && !$visitor) {
1041 if (is_array($_SESSION['remote'])) {
1042 foreach ($_SESSION['remote'] as $v) {
1043 if ($v['uid'] == $owner_uid) {
1044 $contact_id = $v['cid'];
1050 $groups = Group::getIdsByContactId($contact_id);
1051 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1052 intval($contact_id),
1055 if (DBM::is_result($r)) {
1057 $remote_contact = true;
1062 if (!$remote_contact && local_user()) {
1063 $contact_id = $_SESSION['cid'];
1064 $contact = $a->contact;
1067 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
1068 notice(L10n::t('Access to this item is restricted.') . EOL);
1072 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
1077 $is_owner = (local_user() && (local_user() == $owner_uid));
1078 $o .= Profile::getTabs($a, $is_owner, $a->data['user']['nickname']);
1080 // Display upload form
1081 if ($datatype === 'upload') {
1083 notice(L10n::t('Permission denied.'));
1087 $selname = $datum ? hex2bin($datum) : '';
1091 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '> </option>';
1092 if (count($a->data['albums'])) {
1093 foreach ($a->data['albums'] as $album) {
1094 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === L10n::t('Contact Photos'))) {
1097 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1098 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1104 $ret = ['post_url' => 'photos/' . $a->data['user']['nickname'],
1105 'addon_text' => $uploader,
1106 'default_upload' => true];
1108 Addon::callHooks('photo_upload_form',$ret);
1110 $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), []);
1111 $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), [
1112 '$submit' => L10n::t('Submit'),
1115 $usage_message = '';
1117 $tpl = get_markup_template('photos_upload.tpl');
1119 $aclselect_e = ($visitor ? '' : populate_acl($a->user));
1121 $o .= replace_macros($tpl,[
1122 '$pagename' => L10n::t('Upload Photos'),
1123 '$sessid' => session_id(),
1124 '$usage' => $usage_message,
1125 '$nickname' => $a->data['user']['nickname'],
1126 '$newalbum' => L10n::t('New album name: '),
1127 '$existalbumtext' => L10n::t('or existing album name: '),
1128 '$nosharetext' => L10n::t('Do not show a status post for this upload'),
1129 '$albumselect' => $albumselect,
1130 '$permissions' => L10n::t('Permissions'),
1131 '$aclselect' => $aclselect_e,
1132 '$alt_uploader' => $ret['addon_text'],
1133 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
1134 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
1135 '$uploadurl' => $ret['post_url'],
1137 // ACL permissions box
1138 '$group_perms' => L10n::t('Show to Groups'),
1139 '$contact_perms' => L10n::t('Show to Contacts'),
1140 '$return_path' => $a->query_string,
1146 // Display a single photo album
1147 if ($datatype === 'album') {
1148 $album = hex2bin($datum);
1150 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1151 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1155 if (DBM::is_result($r)) {
1156 $a->set_pager_total(count($r));
1157 $a->set_pager_itemspage(20);
1160 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1161 $order_field = defaults($_GET, 'order', '');
1162 if ($order_field === 'posted') {
1168 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1169 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1170 ANY_VALUE(`created`) as `created`
1171 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1172 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1175 intval($a->pager['start']),
1176 intval($a->pager['itemspage'])
1180 if ($cmd === 'edit') {
1181 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos'))) {
1183 $edit_tpl = get_markup_template('album_edit.tpl');
1187 $o .= replace_macros($edit_tpl,[
1188 '$nametext' => L10n::t('New album name: '),
1189 '$nickname' => $a->data['user']['nickname'],
1190 '$album' => $album_e,
1191 '$hexalbum' => bin2hex($album),
1192 '$submit' => L10n::t('Submit'),
1193 '$dropsubmit' => L10n::t('Delete Album')
1198 if (($album !== L10n::t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== L10n::t('Contact Photos')) && $can_post) {
1199 $edit = [L10n::t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'];
1203 if ($order_field === 'posted') {
1204 $order = [L10n::t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album)];
1206 $order = [L10n::t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted'];
1211 if (DBM::is_result($r)) {
1212 // "Twist" is only used for the duepunto theme with style "slackr"
1214 foreach ($r as $rr) {
1217 $ext = $phototypes[$rr['type']];
1219 $imgalt_e = $rr['filename'];
1220 $desc_e = $rr['desc'];
1224 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1225 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1226 . ($order_field === 'posted' ? '?f=&order=posted' : ''),
1227 'title' => L10n::t('View Photo'),
1228 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1232 'hash'=> $rr['resource-id'],
1237 $tpl = get_markup_template('photo_album.tpl');
1238 $o .= replace_macros($tpl, [
1239 '$photos' => $photos,
1241 '$can_post' => $can_post,
1242 '$upload' => [L10n::t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)],
1245 '$paginate' => paginate($a),
1252 // Display one photo
1253 if ($datatype === 'image') {
1254 // fetch image, item containing image, then comments
1255 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1256 $sql_extra ORDER BY `scale` ASC ",
1261 if (!DBM::is_result($ph)) {
1262 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1267 if (DBM::is_result($ph)) {
1268 notice(L10n::t('Permission denied. Access to this item may be restricted.'));
1270 notice(L10n::t('Photo not available') . EOL );
1278 /// @todo This query is totally bad, the whole functionality has to be changed
1279 // The query leads to a really intense used index.
1280 // By now we hide it if someone wants to.
1281 if (!Config::get('system', 'no_count', false)) {
1282 $order_field = defaults($_GET, 'order', '');
1283 if ($order_field === 'posted') {
1289 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1290 $sql_extra ORDER BY `created` $order ",
1291 dbesc($ph[0]['album']),
1295 if (DBM::is_result($prvnxt)) {
1296 foreach ($prvnxt as $z => $entry) {
1297 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1301 $prv = count($prvnxt) - 1;
1303 if ($nxt >= count($prvnxt)) {
1309 $edit_suffix = ((($cmd === 'edit') && $can_post) ? '/edit' : '');
1310 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1311 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1315 if (count($ph) == 1)
1316 $hires = $lores = $ph[0];
1317 if (count($ph) > 1) {
1318 if ($ph[1]['scale'] == 2) {
1319 // original is 640 or less, we can display it directly
1320 $hires = $lores = $ph[0];
1327 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1331 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1333 'edit' => ['photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? L10n::t('View photo') : L10n::t('Edit photo'))],
1334 'profile'=>['profile_photo/use/'.$ph[0]['resource-id'], L10n::t('Use as profile photo')],
1338 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1339 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1340 ? L10n::t('Private Message')
1346 if ( $cmd === 'edit') {
1347 $tpl = get_markup_template('photo_edit_head.tpl');
1348 $a->page['htmlhead'] .= replace_macros($tpl,[
1349 '$prevlink' => $prevlink,
1350 '$nextlink' => $nextlink
1355 $prevlink = [$prevlink, '<div class="icon prev"></div>'] ;
1358 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1359 'title'=> L10n::t('View Full Size'),
1360 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis'),
1361 'height' => $hires['height'],
1362 'width' => $hires['width'],
1363 'album' => $hires['album'],
1364 'filename' => $hires['filename'],
1368 $nextlink = [$nextlink, '<div class="icon next"></div>'];
1372 // Do we have an item for this photo?
1374 // FIXME! - replace following code to display the conversation with our normal
1375 // conversation functions so that it works correctly and tracks changes
1376 // in the evolving conversation code.
1377 // The difference is that we won't be displaying the conversation head item
1378 // as a "post" but displaying instead the photo it is linked to
1380 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1387 if (DBM::is_result($linked_items)) {
1388 $link_item = $linked_items[0];
1390 $r = q("SELECT COUNT(*) AS `total`
1391 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1392 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1393 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1394 AND `item`.`uid` = %d
1396 dbesc($link_item['uri']),
1397 dbesc($link_item['uri']),
1398 intval($link_item['uid'])
1402 if (DBM::is_result($r)) {
1403 $a->set_pager_total($r[0]['total']);
1407 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1408 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1409 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1410 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1411 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1412 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1413 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1414 AND `item`.`uid` = %d
1416 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1417 dbesc($link_item['uri']),
1418 dbesc($link_item['uri']),
1419 intval($link_item['uid']),
1420 intval($a->pager['start']),
1421 intval($a->pager['itemspage'])
1425 if (local_user() && (local_user() == $link_item['uid'])) {
1426 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1427 intval($link_item['parent']),
1428 intval(local_user())
1430 update_thread($link_item['parent']);
1433 if ($link_item['coord']) {
1434 $map = Map::byCoordinates($link_item['coord']);
1440 if (count($linked_items) && strlen($link_item['tag'])) {
1441 $arr = explode(',', $link_item['tag']);
1442 // parse tags and add links
1444 foreach ($arr as $t) {
1445 if (strlen($tag_str)) {
1448 $tag_str .= bbcode($t);
1450 $tags = [L10n::t('Tags: '), $tag_str];
1451 if ($cmd === 'edit') {
1452 $tags[] = 'tagrm/' . $link_item['id'];
1453 $tags[] = L10n::t('[Remove any tag]');
1459 if ($cmd === 'edit' && $can_post) {
1460 $edit_tpl = get_markup_template('photo_edit.tpl');
1462 $album_e = $ph[0]['album'];
1463 $caption_e = $ph[0]['desc'];
1464 $aclselect_e = populate_acl($ph[0]);
1466 $edit = replace_macros($edit_tpl, [
1467 '$id' => $ph[0]['id'],
1468 '$album' => ['albname', L10n::t('New album name'), $album_e,''],
1469 '$caption' => ['desc', L10n::t('Caption'), $caption_e, ''],
1470 '$tags' => ['newtag', L10n::t('Add a Tag'), "", L10n::t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')],
1471 '$rotate_none' => ['rotate', L10n::t('Do not rotate'),0,'', true],
1472 '$rotate_cw' => ['rotate', L10n::t('Rotate CW (right)'),1,''],
1473 '$rotate_ccw' => ['rotate', L10n::t('Rotate CCW (left)'),2,''],
1475 '$nickname' => $a->data['user']['nickname'],
1476 '$resource_id' => $ph[0]['resource-id'],
1477 '$permissions' => L10n::t('Permissions'),
1478 '$aclselect' => $aclselect_e,
1480 '$item_id' => defaults($link_item, 'id', 0),
1481 '$submit' => L10n::t('Submit'),
1482 '$delete' => L10n::t('Delete Photo'),
1484 // ACL permissions box
1485 '$group_perms' => L10n::t('Show to Groups'),
1486 '$contact_perms' => L10n::t('Show to Contacts'),
1487 '$return_path' => $a->query_string,
1498 if (count($linked_items)) {
1499 $cmnt_tpl = get_markup_template('comment_item.tpl');
1500 $tpl = get_markup_template('photo_item.tpl');
1501 $return_url = $a->cmd;
1503 if ($can_post || can_write_wall($owner_uid)) {
1504 $like_tpl = get_markup_template('like_noshare.tpl');
1505 $likebuttons = replace_macros($like_tpl, [
1506 '$id' => $link_item['id'],
1507 '$likethis' => L10n::t("I like this \x28toggle\x29"),
1508 '$nolike' => (Feature::isEnabled(local_user(), 'dislike') ? L10n::t("I don't like this \x28toggle\x29") : ''),
1509 '$wait' => L10n::t('Please wait'),
1510 '$return_path' => $a->query_string,
1514 if (!DBM::is_result($r)) {
1515 if (($can_post || can_write_wall($owner_uid))) {
1516 $comments .= replace_macros($cmnt_tpl, [
1517 '$return_path' => '',
1518 '$jsreload' => $return_url,
1519 '$type' => 'wall-comment',
1520 '$id' => $link_item['id'],
1521 '$parent' => $link_item['id'],
1522 '$profile_uid' => $owner_uid,
1523 '$mylink' => $contact['url'],
1524 '$mytitle' => L10n::t('This is you'),
1525 '$myphoto' => $contact['thumb'],
1526 '$comment' => L10n::t('Comment'),
1527 '$submit' => L10n::t('Submit'),
1528 '$preview' => L10n::t('Preview'),
1529 '$sourceapp' => L10n::t($a->sourcename),
1531 '$rand_num' => random_digits(12)
1537 'like' => ['title' => L10n::t('Likes','title')],'dislike' => ['title' => L10n::t('Dislikes','title')],
1538 'attendyes' => ['title' => L10n::t('Attending','title')], 'attendno' => ['title' => L10n::t('Not attending','title')], 'attendmaybe' => ['title' => L10n::t('Might attend','title')]
1542 if (DBM::is_result($r)) {
1543 foreach ($r as $item) {
1544 builtin_activity_puller($item, $conv_responses);
1547 if (x($conv_responses['like'], $link_item['uri'])) {
1548 $like = format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like', $link_item['id']);
1550 if (x($conv_responses['dislike'], $link_item['uri'])) {
1551 $dislike = format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike', $link_item['id']);
1554 if (($can_post || can_write_wall($owner_uid))) {
1555 $comments .= replace_macros($cmnt_tpl,[
1556 '$return_path' => '',
1557 '$jsreload' => $return_url,
1558 '$type' => 'wall-comment',
1559 '$id' => $link_item['id'],
1560 '$parent' => $link_item['id'],
1561 '$profile_uid' => $owner_uid,
1562 '$mylink' => $contact['url'],
1563 '$mytitle' => L10n::t('This is you'),
1564 '$myphoto' => $contact['thumb'],
1565 '$comment' => L10n::t('Comment'),
1566 '$submit' => L10n::t('Submit'),
1567 '$preview' => L10n::t('Preview'),
1568 '$sourceapp' => L10n::t($a->sourcename),
1570 '$rand_num' => random_digits(12)
1574 foreach ($r as $item) {
1579 if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) {
1583 $redirect_url = 'redir/' . $item['cid'];
1585 if (local_user() && ($item['contact-uid'] == local_user())
1586 && ($item['network'] == NETWORK_DFRN) && !$item['self']) {
1587 $profile_url = $redirect_url;
1588 $sparkle = ' sparkle';
1590 $profile_url = $item['url'];
1594 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1596 $profile_name = ((strlen($item['author-name']) && $diff_author) ? $item['author-name'] : $item['name']);
1597 $profile_avatar = ((strlen($item['author-avatar']) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1599 $profile_link = $profile_url;
1601 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1603 'dropping' => $dropping,
1604 'pagedrop' => false,
1605 'select' => L10n::t('Select'),
1606 'delete' => L10n::t('Delete'),
1609 $name_e = $profile_name;
1610 $title_e = $item['title'];
1611 $body_e = bbcode($item['body']);
1613 $comments .= replace_macros($template,[
1614 '$id' => $item['item_id'],
1615 '$profile_url' => $profile_link,
1617 '$thumb' => $profile_avatar,
1618 '$sparkle' => $sparkle,
1619 '$title' => $title_e,
1621 '$ago' => relative_date($item['created']),
1622 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1624 '$comment' => $comment
1627 if (($can_post || can_write_wall($owner_uid))) {
1628 $comments .= replace_macros($cmnt_tpl, [
1629 '$return_path' => '',
1630 '$jsreload' => $return_url,
1631 '$type' => 'wall-comment',
1632 '$id' => $item['item_id'],
1633 '$parent' => $item['parent'],
1634 '$profile_uid' => $owner_uid,
1635 '$mylink' => $contact['url'],
1636 '$mytitle' => L10n::t('This is you'),
1637 '$myphoto' => $contact['thumb'],
1638 '$comment' => L10n::t('Comment'),
1639 '$submit' => L10n::t('Submit'),
1640 '$preview' => L10n::t('Preview'),
1641 '$sourceapp' => L10n::t($a->sourcename),
1643 '$rand_num' => random_digits(12)
1648 $response_verbs = ['like'];
1649 if (Feature::isEnabled($owner_uid, 'dislike')) {
1650 $response_verbs[] = 'dislike';
1652 $responses = get_responses($conv_responses, $response_verbs, '', $link_item);
1654 $paginate = paginate($a);
1657 $photo_tpl = get_markup_template('photo_view.tpl');
1658 $o .= replace_macros($photo_tpl, [
1659 '$id' => $ph[0]['id'],
1660 '$album' => [$album_link, $ph[0]['album']],
1664 '$prevlink' => $prevlink,
1665 '$nextlink' => $nextlink,
1666 '$desc' => $ph[0]['desc'],
1670 '$map_text' => L10n::t('Map'),
1671 '$likebuttons' => $likebuttons,
1673 '$dislike' => $dislike,
1674 'responses' => $responses,
1675 '$comments' => $comments,
1676 '$paginate' => $paginate,
1679 $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="photo" />' . "\n";
1680 $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1681 $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . $photo["href"] . '" />' . "\n";
1682 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1683 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1688 // Default - show recent photos with upload link (if applicable)
1691 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1692 $sql_extra GROUP BY `resource-id`",
1693 intval($a->data['user']['uid']),
1694 dbesc('Contact Photos'),
1695 dbesc(L10n::t('Contact Photos'))
1697 if (DBM::is_result($r)) {
1698 $a->set_pager_total(count($r));
1699 $a->set_pager_itemspage(20);
1702 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1703 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1704 ANY_VALUE(`created`) AS `created` FROM `photo`
1705 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1706 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1707 intval($a->data['user']['uid']),
1708 dbesc('Contact Photos'),
1709 dbesc(L10n::t('Contact Photos')),
1710 intval($a->pager['start']),
1711 intval($a->pager['itemspage'])
1715 if (DBM::is_result($r)) {
1716 // "Twist" is only used for the duepunto theme with style "slackr"
1718 foreach ($r as $rr) {
1719 //hide profile photos to others
1720 if (!$is_owner && !remote_user() && ($rr['album'] == L10n::t('Profile Photos')))
1725 $ext = $phototypes[$rr['type']];
1727 $alt_e = $rr['filename'];
1728 $name_e = $rr['album'];
1732 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1733 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1734 'title' => L10n::t('View Photo'),
1735 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1738 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1740 'alt' => L10n::t('View Album'),
1747 $tpl = get_markup_template('photos_recent.tpl');
1748 $o .= replace_macros($tpl, [
1749 '$title' => L10n::t('Recent Photos'),
1750 '$can_post' => $can_post,
1751 '$upload' => [L10n::t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'],
1752 '$photos' => $photos,
1753 '$paginate' => paginate($a),