6 use Friendica\Content\Feature;
7 use Friendica\Core\System;
8 use Friendica\Core\Config;
9 use Friendica\Core\Worker;
10 use Friendica\Database\DBM;
11 use Friendica\Model\Contact;
12 use Friendica\Model\Group;
13 use Friendica\Model\Photo;
14 use Friendica\Network\Probe;
15 use Friendica\Object\Image;
17 require_once 'include/items.php';
18 require_once 'include/acl_selectors.php';
19 require_once 'include/bbcode.php';
20 require_once 'include/security.php';
21 require_once 'include/redir.php';
22 require_once 'include/tags.php';
23 require_once 'include/threads.php';
25 function photos_init(App $a) {
28 auto_redir($a, $a->argv[1]);
31 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
35 nav_set_selected('home');
39 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
43 if (!DBM::is_result($user)) {
47 $a->data['user'] = $user[0];
48 $a->profile_uid = $user[0]['uid'];
49 $is_owner = (local_user() && (local_user() == $a->profile_uid));
51 $profile = get_profiledata_by_nick($nick, $a->profile_uid);
53 $account_type = Contact::getAccountType($profile);
55 $tpl = get_markup_template("vcard-widget.tpl");
57 $vcard_widget = replace_macros($tpl, array(
58 '$name' => $profile['name'],
59 '$photo' => $profile['photo'],
60 '$addr' => defaults($profile, 'addr', ''),
61 '$account_type' => $account_type,
62 '$pdesc' => defaults($profile, 'pdesc', ''),
65 $albums = Photo::getAlbums($a->data['user']['uid']);
67 $albums_visible = ((intval($a->data['user']['hidewall']) && !local_user() && !remote_user()) ? false : true);
69 // add various encodings to the array so we can just loop through and pick them out in a template
70 $ret = array('success' => false);
73 $a->data['albums'] = $albums;
74 if ($albums_visible) {
75 $ret['success'] = true;
78 $ret['albums'] = array();
79 foreach ($albums as $k => $album) {
80 //hide profile photos to others
81 if (!$is_owner && !remote_user() && ($album['album'] == t('Profile Photos')))
84 'text' => $album['album'],
85 'total' => $album['total'],
86 'url' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
87 'urlencode' => urlencode($album['album']),
88 'bin2hex' => bin2hex($album['album'])
90 $ret['albums'][] = $entry;
94 if (local_user() && $a->data['user']['uid'] == local_user()) {
98 if ($ret['success']) {
99 $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'), array(
100 '$nick' => $a->data['user']['nickname'],
101 '$title' => t('Photo Albums'),
102 '$recent' => t('Recent Photos'),
103 '$albums' => $ret['albums'],
104 '$baseurl' => System::baseUrl(),
105 '$upload' => array(t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'),
106 '$can_post' => $can_post
111 if (!x($a->page, 'aside')) {
112 $a->page['aside'] = '';
114 $a->page['aside'] .= $vcard_widget;
115 $a->page['aside'] .= $photo_albums_widget;
117 $tpl = get_markup_template("photos_head.tpl");
118 $a->page['htmlhead'] .= replace_macros($tpl,array(
119 '$ispublic' => t('everybody')
126 function photos_post(App $a)
128 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
129 logger('mod_photos: REQUEST ' . print_r($_REQUEST, true), LOGGER_DATA);
130 logger('mod_photos: FILES ' . print_r($_FILES, true), LOGGER_DATA);
132 $phototypes = Image::supportedTypes();
137 $page_owner_uid = $a->data['user']['uid'];
138 $community_page = $a->data['user']['page-flags'] == PAGE_COMMUNITY;
140 if (local_user() && (local_user() == $page_owner_uid)) {
143 if ($community_page && remote_user()) {
145 if (x($_SESSION, 'remote') && is_array($_SESSION['remote'])) {
146 foreach ($_SESSION['remote'] as $v) {
147 if ($v['uid'] == $page_owner_uid) {
148 $contact_id = $v['cid'];
154 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
156 intval($page_owner_uid)
158 if (DBM::is_result($r)) {
160 $visitor = $contact_id;
167 notice( t('Permission denied.') . EOL );
171 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
172 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
173 intval($page_owner_uid)
176 if (!DBM::is_result($r)) {
177 notice( t('Contact information unavailable') . EOL);
178 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
182 $owner_record = $r[0];
184 if ($a->argc > 3 && $a->argv[2] === 'album') {
185 $album = hex2bin($a->argv[3]);
187 if ($album === t('Profile Photos') || $album === 'Contact Photos' || $album === t('Contact Photos')) {
188 goaway($_SESSION['photo_return']);
189 return; // NOTREACHED
192 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
194 intval($page_owner_uid)
196 if (!DBM::is_result($r)) {
197 notice( t('Album not found.') . EOL);
198 goaway($_SESSION['photo_return']);
199 return; // NOTREACHED
202 // Check if the user has responded to a delete confirmation query
203 if ($_REQUEST['canceled']) {
204 goaway($_SESSION['photo_return']);
207 // RENAME photo album
208 $newalbum = notags(trim($_POST['albumname']));
209 if ($newalbum != $album) {
210 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
213 intval($page_owner_uid)
215 // Update the photo albums cache
216 Photo::clearAlbumCache($page_owner_uid);
218 $newurl = str_replace(bin2hex($album), bin2hex($newalbum), $_SESSION['photo_return']);
220 return; // NOTREACHED
224 * DELETE photo album and all its photos
227 if ($_POST['dropalbum'] == t('Delete Album')) {
228 // Check if we should do HTML-based delete confirmation
229 if (x($_REQUEST, 'confirm')) {
230 $drop_url = $a->query_string;
231 $extra_inputs = array(
232 array('name' => 'albumname', 'value' => $_POST['albumname']),
234 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
236 '$message' => t('Do you really want to delete this photo album and all its photos?'),
237 '$extra_inputs' => $extra_inputs,
238 '$confirm' => t('Delete Album'),
239 '$confirm_url' => $drop_url,
240 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
241 '$cancel' => t('Cancel'),
243 $a->error = 1; // Set $a->error so the other module functions don't execute
249 // get the list of photos we are about to delete
252 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
254 intval($page_owner_uid),
258 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
259 intval(local_user()),
263 if (DBM::is_result($r)) {
264 foreach ($r as $rr) {
265 $res[] = "'" . dbesc($rr['rid']) . "'" ;
268 goaway($_SESSION['photo_return']);
269 return; // NOTREACHED
272 $str_res = implode(',', $res);
274 // remove the associated photos
275 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
276 intval($page_owner_uid)
279 // find and delete the corresponding item with all the comments and likes/dislikes
280 $r = q("SELECT `id`, `parent-uri`, `visible` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
281 intval($page_owner_uid)
283 if (DBM::is_result($r)) {
284 foreach ($r as $rr) {
285 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
286 dbesc(datetime_convert()),
287 dbesc($rr['parent-uri']),
288 intval($page_owner_uid)
290 create_tags_from_itemuri($rr['parent-uri'], $page_owner_uid);
291 delete_thread_uri($rr['parent-uri'], $page_owner_uid);
293 $drop_id = intval($rr['id']);
295 // send the notification upstream/downstream as the case may be
296 if ($rr['visible']) {
297 Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
302 // Update the photo albums cache
303 Photo::clearAlbumCache($page_owner_uid);
306 goaway('photos/' . $a->data['user']['nickname']);
307 return; // NOTREACHED
311 // Check if the user has responded to a delete confirmation query for a single photo
312 if ($a->argc > 2 && x($_REQUEST, 'canceled')) {
313 goaway($_SESSION['photo_return']);
316 if ($a->argc > 2 && defaults($_POST, 'delete', '') === t('Delete Photo')) {
318 // same as above but remove single photo
320 // Check if we should do HTML-based delete confirmation
321 if (x($_REQUEST, 'confirm')) {
322 $drop_url = $a->query_string;
323 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
325 '$message' => t('Do you really want to delete this photo?'),
326 '$extra_inputs' => array(),
327 '$confirm' => t('Delete Photo'),
328 '$confirm_url' => $drop_url,
329 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
330 '$cancel' => t('Cancel'),
332 $a->error = 1; // Set $a->error so the other module functions don't execute
337 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
339 intval($page_owner_uid),
343 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
344 intval(local_user()),
348 if (DBM::is_result($r)) {
349 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
350 intval($page_owner_uid),
351 dbesc($r[0]['resource-id'])
353 $i = q("SELECT `id`, `uri`, `visible` FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
354 dbesc($r[0]['resource-id']),
355 intval($page_owner_uid)
357 if (DBM::is_result($i)) {
358 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
359 dbesc(datetime_convert()),
360 dbesc(datetime_convert()),
362 intval($page_owner_uid)
364 create_tags_from_itemuri($i[0]['uri'], $page_owner_uid);
365 delete_thread_uri($i[0]['uri'], $page_owner_uid);
367 $url = System::baseUrl();
368 $drop_id = intval($i[0]['id']);
370 // Update the photo albums cache
371 Photo::clearAlbumCache($page_owner_uid);
373 if ($i[0]['visible']) {
374 Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
379 goaway('photos/' . $a->data['user']['nickname']);
380 return; // NOTREACHED
383 if ($a->argc > 2 && (x($_POST, 'desc') !== false || x($_POST, 'newtag') !== false || x($_POST, 'albname') !== false)) {
384 $desc = x($_POST, 'desc') ? notags(trim($_POST['desc'])) : '';
385 $rawtags = x($_POST, 'newtag') ? notags(trim($_POST['newtag'])) : '';
386 $item_id = x($_POST, 'item_id') ? intval($_POST['item_id']) : 0;
387 $albname = x($_POST, 'albname') ? notags(trim($_POST['albname'])) : '';
388 $origaname = x($_POST, 'origaname') ? notags(trim($_POST['origaname'])) : '';
389 $str_group_allow = perms2str($_POST['group_allow']);
390 $str_contact_allow = perms2str($_POST['contact_allow']);
391 $str_group_deny = perms2str($_POST['group_deny']);
392 $str_contact_deny = perms2str($_POST['contact_deny']);
394 $resource_id = $a->argv[2];
396 if (!strlen($albname)) {
397 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
400 if (x($_POST,'rotate') !== false &&
401 (intval($_POST['rotate']) == 1 || intval($_POST['rotate']) == 2)) {
404 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0 LIMIT 1",
406 intval($page_owner_uid)
408 if (DBM::is_result($r)) {
409 $Image = new Image($r[0]['data'], $r[0]['type']);
410 if ($Image->isValid()) {
411 $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
412 $Image->rotate($rotate_deg);
414 $width = $Image->getWidth();
415 $height = $Image->getHeight();
417 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0",
418 dbesc($Image->asString()),
422 intval($page_owner_uid)
425 if ($width > 640 || $height > 640) {
426 $Image->scaleDown(640);
427 $width = $Image->getWidth();
428 $height = $Image->getHeight();
430 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 1",
431 dbesc($Image->asString()),
435 intval($page_owner_uid)
439 if ($width > 320 || $height > 320) {
440 $Image->scaleDown(320);
441 $width = $Image->getWidth();
442 $height = $Image->getHeight();
444 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 2",
445 dbesc($Image->asString()),
449 intval($page_owner_uid)
456 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
458 intval($page_owner_uid)
460 if (DBM::is_result($p)) {
461 $ext = $phototypes[$p[0]['type']];
462 $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",
465 dbesc($str_contact_allow),
466 dbesc($str_group_allow),
467 dbesc($str_contact_deny),
468 dbesc($str_group_deny),
470 intval($page_owner_uid)
473 // Update the photo albums cache if album name was changed
474 if ($albname !== $origaname) {
475 Photo::clearAlbumCache($page_owner_uid);
479 /* Don't make the item visible if the only change was the album name */
482 if ($p[0]['desc'] !== $desc || strlen($rawtags)) {
487 // Create item container
489 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
492 $arr['guid'] = get_guid(32);
493 $arr['uid'] = $page_owner_uid;
495 $arr['parent-uri'] = $uri;
496 $arr['type'] = 'photo';
498 $arr['resource-id'] = $p[0]['resource-id'];
499 $arr['contact-id'] = $owner_record['id'];
500 $arr['owner-name'] = $owner_record['name'];
501 $arr['owner-link'] = $owner_record['url'];
502 $arr['owner-avatar'] = $owner_record['thumb'];
503 $arr['author-name'] = $owner_record['name'];
504 $arr['author-link'] = $owner_record['url'];
505 $arr['author-avatar'] = $owner_record['thumb'];
506 $arr['title'] = $title;
507 $arr['allow_cid'] = $p[0]['allow_cid'];
508 $arr['allow_gid'] = $p[0]['allow_gid'];
509 $arr['deny_cid'] = $p[0]['deny_cid'];
510 $arr['deny_gid'] = $p[0]['deny_gid'];
511 $arr['last-child'] = 1;
512 $arr['visible'] = $visibility;
515 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
516 . '[img]' . System::baseUrl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
519 $item_id = item_store($arr);
523 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
525 intval($page_owner_uid)
528 if (DBM::is_result($r)) {
529 $old_tag = $r[0]['tag'];
530 $old_inform = $r[0]['inform'];
533 if (strlen($rawtags)) {
537 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
538 $x = substr($rawtags, 0, 1);
539 if ($x !== '@' && $x !== '#') {
540 $rawtags = '#' . $rawtags;
544 $tags = get_tags($rawtags);
547 foreach ($tags as $tag) {
548 if (strpos($tag, '@') === 0) {
550 $name = substr($tag,1);
551 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
553 $links = @Probe::lrdd($name);
555 foreach ($links as $link) {
556 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
557 $profile = $link['@attributes']['href'];
559 if ($link['@attributes']['rel'] === 'salmon') {
560 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
561 if (strlen($inform)) {
568 $taginfo[] = array($newname, $profile, $salmon);
573 if (strrpos($newname, '+')) {
574 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
578 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
583 $newname = str_replace('_',' ',$name);
585 //select someone from this user's contacts by name
586 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
588 intval($page_owner_uid)
591 if (!DBM::is_result($r)) {
592 //select someone by attag or nick and the name passed in
593 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
596 intval($page_owner_uid)
601 if (DBM::is_result($r)) {
602 $newname = $r[0]['name'];
603 $profile = $r[0]['url'];
604 $notify = 'cid:' . $r[0]['id'];
605 if (strlen($inform)) {
612 if (substr($notify, 0, 4) === 'cid:') {
613 $taginfo[] = array($newname, $profile, $notify, $r[0], '@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
615 $taginfo[] = array($newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
617 if (strlen($str_tags)) {
620 $profile = str_replace(',', '%2c', $profile);
621 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
623 } elseif (strpos($tag, '#') === 0) {
624 $tagname = substr($tag, 1);
625 $str_tags .= '#[url=' . System::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url]';
631 if (strlen($newtag) && strlen($str_tags)) {
634 $newtag .= $str_tags;
636 $newinform = $old_inform;
637 if (strlen($newinform) && strlen($inform)) {
640 $newinform .= $inform;
642 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
645 dbesc(datetime_convert()),
646 dbesc(datetime_convert()),
648 intval($page_owner_uid)
650 create_tags_from_item($item_id);
651 update_thread($item_id);
654 foreach ($p as $scales) {
655 if (intval($scales['scale']) == 2) {
659 if (intval($scales['scale']) == 4) {
665 if (count($taginfo)) {
666 foreach ($taginfo as $tagged) {
667 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
670 $arr['guid'] = get_guid(32);
671 $arr['uid'] = $page_owner_uid;
673 $arr['parent-uri'] = $uri;
674 $arr['type'] = 'activity';
676 $arr['contact-id'] = $owner_record['id'];
677 $arr['owner-name'] = $owner_record['name'];
678 $arr['owner-link'] = $owner_record['url'];
679 $arr['owner-avatar'] = $owner_record['thumb'];
680 $arr['author-name'] = $owner_record['name'];
681 $arr['author-link'] = $owner_record['url'];
682 $arr['author-avatar'] = $owner_record['thumb'];
684 $arr['allow_cid'] = $p[0]['allow_cid'];
685 $arr['allow_gid'] = $p[0]['allow_gid'];
686 $arr['deny_cid'] = $p[0]['deny_cid'];
687 $arr['deny_gid'] = $p[0]['deny_gid'];
688 $arr['last-child'] = 1;
690 $arr['verb'] = ACTIVITY_TAG;
691 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
692 $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
693 $arr['tag'] = $tagged[4];
694 $arr['inform'] = $tagged[2];
696 $arr['body'] = sprintf( 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'] . ']' . t('a photo') . '[/url]', '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]') ;
697 $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" ;
699 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
700 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
702 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
704 $arr['object'] .= '</link></object>' . "\n";
706 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $p[0]['desc'] . '</title><id>'
707 . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
708 $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>';
710 $item_id = item_store($arr);
712 Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
717 goaway($_SESSION['photo_return']);
718 return; // NOTREACHED
722 // default post action - upload a photo
723 call_hooks('photo_post_init', $_POST);
725 // Determine the album to use
726 $album = x($_REQUEST, 'album') ? notags(trim($_REQUEST['album'])) : '';
727 $newalbum = x($_REQUEST, 'newalbum') ? notags(trim($_REQUEST['newalbum'])) : '';
729 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
731 if (!strlen($album)) {
732 if (strlen($newalbum)) {
735 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
740 * We create a wall item for every photo, but we don't want to
741 * overwhelm the data stream with a hundred newly uploaded photos.
742 * So we will make the first photo uploaded to this album in the last several hours
743 * visible by default, the rest will become visible over time when and if
744 * they acquire comments, likes, dislikes, and/or tags
747 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
749 intval($page_owner_uid)
751 if (!DBM::is_result($r) || ($album == t('Profile Photos'))) {
757 if (x($_REQUEST, 'not_visible') && $_REQUEST['not_visible'] !== 'false') {
761 $group_allow = defaults($_REQUEST, 'group_allow' , []);
762 $contact_allow = defaults($_REQUEST, 'contact_allow', []);
763 $group_deny = defaults($_REQUEST, 'group_deny' , []);
764 $contact_deny = defaults($_REQUEST, 'contact_deny' , []);
766 $str_group_allow = perms2str(is_array($group_allow) ? $group_allow : explode(',', $group_allow));
767 $str_contact_allow = perms2str(is_array($contact_allow) ? $contact_allow : explode(',', $contact_allow));
768 $str_group_deny = perms2str(is_array($group_deny) ? $group_deny : explode(',', $group_deny));
769 $str_contact_deny = perms2str(is_array($contact_deny) ? $contact_deny : explode(',', $contact_deny));
771 $ret = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
773 call_hooks('photo_post_file', $ret);
775 if (x($ret, 'src') && x($ret, 'filesize')) {
777 $filename = $ret['filename'];
778 $filesize = $ret['filesize'];
779 $type = $ret['type'];
780 $error = UPLOAD_ERR_OK;
782 $src = $_FILES['userfile']['tmp_name'];
783 $filename = basename($_FILES['userfile']['name']);
784 $filesize = intval($_FILES['userfile']['size']);
785 $type = $_FILES['userfile']['type'];
786 $error = $_FILES['userfile']['error'];
789 if ($error !== UPLOAD_ERR_OK) {
791 case UPLOAD_ERR_INI_SIZE:
792 notice(t('Image exceeds size limit of %s', ini_get('upload_max_filesize')) . EOL);
794 case UPLOAD_ERR_FORM_SIZE:
795 notice(t('Image exceeds size limit of %s', formatBytes(defaults($_REQUEST, 'MAX_FILE_SIZE', 0))) . EOL);
797 case UPLOAD_ERR_PARTIAL:
798 notice(t('Image upload didn\'t complete, please try again') . EOL);
800 case UPLOAD_ERR_NO_FILE:
801 notice(t('Image file is missing') . EOL);
803 case UPLOAD_ERR_NO_TMP_DIR:
804 case UPLOAD_ERR_CANT_WRITE:
805 case UPLOAD_ERR_EXTENSION:
806 notice(t('Server can\'t accept new file upload at this time, please contact your administrator') . EOL);
811 call_hooks('photo_post_end', $foo);
816 $type = Image::guessType($filename);
819 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
821 $maximagesize = Config::get('system', 'maximagesize');
823 if ($maximagesize && ($filesize > $maximagesize)) {
824 notice(t('Image exceeds size limit of %s', formatBytes($maximagesize)) . EOL);
827 call_hooks('photo_post_end', $foo);
832 notice(t('Image file is empty.') . EOL);
835 call_hooks('photo_post_end', $foo);
839 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
841 $imagedata = @file_get_contents($src);
843 $Image = new Image($imagedata, $type);
845 if (!$Image->isValid()) {
846 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
847 notice(t('Unable to process image.') . EOL);
850 call_hooks('photo_post_end',$foo);
854 $exif = $Image->orient($src);
857 $max_length = Config::get('system', 'max_image_length');
859 $max_length = MAX_IMAGE_LENGTH;
861 if ($max_length > 0) {
862 $Image->scaleDown($max_length);
865 $width = $Image->getWidth();
866 $height = $Image->getHeight();
870 $photo_hash = photo_new_resource();
872 $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);
875 logger('mod/photos.php: photos_post(): image store failed' , LOGGER_DEBUG);
876 notice(t('Image upload failed.') . EOL);
880 if ($width > 640 || $height > 640) {
881 $Image->scaleDown(640);
882 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);
886 if ($width > 320 || $height > 320) {
887 $Image->scaleDown(320);
888 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);
892 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
894 // Create item container
896 if ($exif && $exif['GPS'] && Feature::isEnabled($channel_id, 'photo_location')) {
897 $lat = Photo::getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
898 $lon = Photo::getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
903 $arr['coord'] = $lat . ' ' . $lon;
906 $arr['guid'] = get_guid(32);
907 $arr['uid'] = $page_owner_uid;
909 $arr['parent-uri'] = $uri;
910 $arr['type'] = 'photo';
912 $arr['resource-id'] = $photo_hash;
913 $arr['contact-id'] = $owner_record['id'];
914 $arr['owner-name'] = $owner_record['name'];
915 $arr['owner-link'] = $owner_record['url'];
916 $arr['owner-avatar'] = $owner_record['thumb'];
917 $arr['author-name'] = $owner_record['name'];
918 $arr['author-link'] = $owner_record['url'];
919 $arr['author-avatar'] = $owner_record['thumb'];
921 $arr['allow_cid'] = $str_contact_allow;
922 $arr['allow_gid'] = $str_group_allow;
923 $arr['deny_cid'] = $str_contact_deny;
924 $arr['deny_gid'] = $str_group_deny;
925 $arr['last-child'] = 1;
926 $arr['visible'] = $visible;
929 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
930 . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$Image->getExt() . '[/img]'
933 $item_id = item_store($arr);
934 // Update the photo albums cache
935 Photo::clearAlbumCache($page_owner_uid);
938 Worker::add(PRIORITY_HIGH, "Notifier", 'wall-new', $item_id);
941 call_hooks('photo_post_end', intval($item_id));
943 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
944 // if they do not wish to be redirected
946 goaway($_SESSION['photo_return']);
950 function photos_content(App $a)
954 // photos/name/upload
955 // photos/name/upload/xxxxx (xxxxx is album name)
956 // photos/name/album/xxxxx
957 // photos/name/album/xxxxx/edit
958 // photos/name/image/xxxxx
959 // photos/name/image/xxxxx/edit
961 if (Config::get('system', 'block_public') && !local_user() && !remote_user()) {
962 notice( t('Public access denied.') . EOL);
966 require_once 'include/bbcode.php';
967 require_once 'include/security.php';
968 require_once 'include/conversation.php';
970 if (!x($a->data,'user')) {
971 notice( t('No photos selected') . EOL );
975 $phototypes = Image::supportedTypes();
977 $_SESSION['photo_return'] = $a->cmd;
982 $datatype = $a->argv[2];
983 $datum = $a->argv[3];
984 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
985 $datatype = 'upload';
987 $datatype = 'summary';
996 // Setup permissions structures
1000 $remote_contact = false;
1003 $owner_uid = $a->data['user']['uid'];
1005 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
1007 if (local_user() && (local_user() == $owner_uid)) {
1010 if ($community_page && remote_user()) {
1011 if (is_array($_SESSION['remote'])) {
1012 foreach ($_SESSION['remote'] as $v) {
1013 if ($v['uid'] == $owner_uid) {
1014 $contact_id = $v['cid'];
1021 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1022 intval($contact_id),
1025 if (DBM::is_result($r)) {
1028 $remote_contact = true;
1029 $visitor = $contact_id;
1037 // perhaps they're visiting - but not a community page, so they wouldn't have write access
1038 if (remote_user() && !$visitor) {
1040 if (is_array($_SESSION['remote'])) {
1041 foreach ($_SESSION['remote'] as $v) {
1042 if ($v['uid'] == $owner_uid) {
1043 $contact_id = $v['cid'];
1049 $groups = Group::getIdsByContactId($contact_id);
1050 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1051 intval($contact_id),
1054 if (DBM::is_result($r)) {
1056 $remote_contact = true;
1061 if (!$remote_contact && local_user()) {
1062 $contact_id = $_SESSION['cid'];
1063 $contact = $a->contact;
1066 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && !$remote_contact) {
1067 notice( t('Access to this item is restricted.') . EOL);
1071 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
1076 $is_owner = (local_user() && (local_user() == $owner_uid));
1077 $o .= profile_tabs($a, $is_owner, $a->data['user']['nickname']);
1079 // Display upload form
1080 if ($datatype === 'upload') {
1082 notice(t('Permission denied.'));
1086 $selname = $datum ? hex2bin($datum) : '';
1090 $albumselect .= '<option value="" ' . (!$selname ? ' selected="selected" ' : '') . '> </option>';
1091 if (count($a->data['albums'])) {
1092 foreach ($a->data['albums'] as $album) {
1093 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos'))) {
1096 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1097 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1103 $ret = array('post_url' => 'photos/' . $a->data['user']['nickname'],
1104 'addon_text' => $uploader,
1105 'default_upload' => true);
1107 call_hooks('photo_upload_form',$ret);
1109 $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), array());
1110 $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), array(
1111 '$submit' => t('Submit'),
1114 $usage_message = '';
1116 $tpl = get_markup_template('photos_upload.tpl');
1118 $aclselect_e = ($visitor ? '' : populate_acl($a->user));
1120 $o .= replace_macros($tpl,array(
1121 '$pagename' => t('Upload Photos'),
1122 '$sessid' => session_id(),
1123 '$usage' => $usage_message,
1124 '$nickname' => $a->data['user']['nickname'],
1125 '$newalbum' => t('New album name: '),
1126 '$existalbumtext' => t('or existing album name: '),
1127 '$nosharetext' => t('Do not show a status post for this upload'),
1128 '$albumselect' => $albumselect,
1129 '$permissions' => t('Permissions'),
1130 '$aclselect' => $aclselect_e,
1131 '$alt_uploader' => $ret['addon_text'],
1132 '$default_upload_box' => ($ret['default_upload'] ? $default_upload_box : ''),
1133 '$default_upload_submit' => ($ret['default_upload'] ? $default_upload_submit : ''),
1134 '$uploadurl' => $ret['post_url'],
1136 // ACL permissions box
1137 '$group_perms' => t('Show to Groups'),
1138 '$contact_perms' => t('Show to Contacts'),
1139 '$return_path' => $a->query_string,
1145 // Display a single photo album
1146 if ($datatype === 'album') {
1147 $album = hex2bin($datum);
1149 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1150 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1154 if (DBM::is_result($r)) {
1155 $a->set_pager_total(count($r));
1156 $a->set_pager_itemspage(20);
1159 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1160 $order_field = defaults($_GET, 'order', '');
1161 if ($order_field === 'posted') {
1167 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1168 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1169 ANY_VALUE(`created`) as `created`
1170 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1171 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1174 intval($a->pager['start']),
1175 intval($a->pager['itemspage'])
1179 if ($cmd === 'edit') {
1180 if (($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1182 $edit_tpl = get_markup_template('album_edit.tpl');
1186 $o .= replace_macros($edit_tpl,array(
1187 '$nametext' => t('New album name: '),
1188 '$nickname' => $a->data['user']['nickname'],
1189 '$album' => $album_e,
1190 '$hexalbum' => bin2hex($album),
1191 '$submit' => t('Submit'),
1192 '$dropsubmit' => t('Delete Album')
1197 if (($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos')) && $can_post) {
1198 $edit = array(t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit');
1202 if ($order_field === 'posted') {
1203 $order = array(t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album));
1205 $order = array(t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted');
1210 if (DBM::is_result($r)) {
1211 // "Twist" is only used for the duepunto theme with style "slackr"
1213 foreach ($r as $rr) {
1216 $ext = $phototypes[$rr['type']];
1218 $imgalt_e = $rr['filename'];
1219 $desc_e = $rr['desc'];
1223 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1224 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1225 . ($order_field === 'posted' ? '?f=&order=posted' : ''),
1226 'title' => t('View Photo'),
1227 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1231 'hash'=> $rr['resource-id'],
1236 $tpl = get_markup_template('photo_album.tpl');
1237 $o .= replace_macros($tpl, array(
1238 '$photos' => $photos,
1240 '$can_post' => $can_post,
1241 '$upload' => array(t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)),
1244 '$paginate' => paginate($a),
1251 // Display one photo
1252 if ($datatype === 'image') {
1253 // fetch image, item containing image, then comments
1254 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1255 $sql_extra ORDER BY `scale` ASC ",
1260 if (!DBM::is_result($ph)) {
1261 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1266 if (DBM::is_result($ph)) {
1267 notice(t('Permission denied. Access to this item may be restricted.'));
1269 notice(t('Photo not available') . EOL );
1277 /// @todo This query is totally bad, the whole functionality has to be changed
1278 // The query leads to a really intense used index.
1279 // By now we hide it if someone wants to.
1280 if (!Config::get('system', 'no_count', false)) {
1281 $order_field = defaults($_GET, 'order', '');
1282 if ($order_field === 'posted') {
1288 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1289 $sql_extra ORDER BY `created` $order ",
1290 dbesc($ph[0]['album']),
1294 if (DBM::is_result($prvnxt)) {
1295 foreach ($prvnxt as $z => $entry) {
1296 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1300 $prv = count($prvnxt) - 1;
1302 if ($nxt >= count($prvnxt)) {
1308 $edit_suffix = ((($cmd === 'edit') && $can_post) ? '/edit' : '');
1309 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1310 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . ($order_field === 'posted' ? '?f=&order=posted' : '');
1314 if (count($ph) == 1)
1315 $hires = $lores = $ph[0];
1316 if (count($ph) > 1) {
1317 if ($ph[1]['scale'] == 2) {
1318 // original is 640 or less, we can display it directly
1319 $hires = $lores = $ph[0];
1326 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1330 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1332 'edit' => array('photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? t('View photo') : t('Edit photo'))),
1333 'profile'=>array('profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
1337 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1338 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1339 ? t('Private Message')
1345 if ( $cmd === 'edit') {
1346 $tpl = get_markup_template('photo_edit_head.tpl');
1347 $a->page['htmlhead'] .= replace_macros($tpl,array(
1348 '$prevlink' => $prevlink,
1349 '$nextlink' => $nextlink
1354 $prevlink = array($prevlink, '<div class="icon prev"></div>') ;
1357 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1358 'title'=> t('View Full Size'),
1359 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis'),
1360 'height' => $hires['height'],
1361 'width' => $hires['width'],
1362 'album' => $hires['album'],
1363 'filename' => $hires['filename'],
1367 $nextlink = array($nextlink, '<div class="icon next"></div>');
1371 // Do we have an item for this photo?
1373 // FIXME! - replace following code to display the conversation with our normal
1374 // conversation functions so that it works correctly and tracks changes
1375 // in the evolving conversation code.
1376 // The difference is that we won't be displaying the conversation head item
1377 // as a "post" but displaying instead the photo it is linked to
1379 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1386 if (DBM::is_result($linked_items)) {
1387 $link_item = $linked_items[0];
1389 $r = q("SELECT COUNT(*) AS `total`
1390 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1391 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1392 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1393 AND `item`.`uid` = %d
1395 dbesc($link_item['uri']),
1396 dbesc($link_item['uri']),
1397 intval($link_item['uid'])
1401 if (DBM::is_result($r)) {
1402 $a->set_pager_total($r[0]['total']);
1406 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1407 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1408 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1409 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1410 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1411 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1412 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1413 AND `item`.`uid` = %d
1415 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1416 dbesc($link_item['uri']),
1417 dbesc($link_item['uri']),
1418 intval($link_item['uid']),
1419 intval($a->pager['start']),
1420 intval($a->pager['itemspage'])
1424 if (local_user() && (local_user() == $link_item['uid'])) {
1425 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1426 intval($link_item['parent']),
1427 intval(local_user())
1429 update_thread($link_item['parent']);
1432 if ($link_item['coord']) {
1433 $map = Map::byCoordinates($link_item['coord']);
1439 if (count($linked_items) && strlen($link_item['tag'])) {
1440 $arr = explode(',', $link_item['tag']);
1441 // parse tags and add links
1443 foreach ($arr as $t) {
1444 if (strlen($tag_str)) {
1447 $tag_str .= bbcode($t);
1449 $tags = array(t('Tags: '), $tag_str);
1450 if ($cmd === 'edit') {
1451 $tags[] = 'tagrm/' . $link_item['id'];
1452 $tags[] = t('[Remove any tag]');
1458 if ($cmd === 'edit' && $can_post) {
1459 $edit_tpl = get_markup_template('photo_edit.tpl');
1461 $album_e = $ph[0]['album'];
1462 $caption_e = $ph[0]['desc'];
1463 $aclselect_e = populate_acl($ph[0]);
1465 $edit = replace_macros($edit_tpl, array(
1466 '$id' => $ph[0]['id'],
1467 '$album' => array('albname', t('New album name'), $album_e,''),
1468 '$caption' => array('desc', t('Caption'), $caption_e, ''),
1469 '$tags' => array('newtag', t('Add a Tag'), "", t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')),
1470 '$rotate_none' => array('rotate', t('Do not rotate'),0,'', true),
1471 '$rotate_cw' => array('rotate', t('Rotate CW (right)'),1,''),
1472 '$rotate_ccw' => array('rotate', t('Rotate CCW (left)'),2,''),
1474 '$nickname' => $a->data['user']['nickname'],
1475 '$resource_id' => $ph[0]['resource-id'],
1476 '$permissions' => t('Permissions'),
1477 '$aclselect' => $aclselect_e,
1479 '$item_id' => defaults($link_item, 'id', 0),
1480 '$submit' => t('Submit'),
1481 '$delete' => t('Delete Photo'),
1483 // ACL permissions box
1484 '$group_perms' => t('Show to Groups'),
1485 '$contact_perms' => t('Show to Contacts'),
1486 '$return_path' => $a->query_string,
1497 if (count($linked_items)) {
1498 $cmnt_tpl = get_markup_template('comment_item.tpl');
1499 $tpl = get_markup_template('photo_item.tpl');
1500 $return_url = $a->cmd;
1502 if ($can_post || can_write_wall($owner_uid)) {
1503 $like_tpl = get_markup_template('like_noshare.tpl');
1504 $likebuttons = replace_macros($like_tpl, array(
1505 '$id' => $link_item['id'],
1506 '$likethis' => t("I like this \x28toggle\x29"),
1507 '$nolike' => (Feature::isEnabled(local_user(), 'dislike') ? t("I don't like this \x28toggle\x29") : ''),
1508 '$wait' => t('Please wait'),
1509 '$return_path' => $a->query_string,
1513 if (!DBM::is_result($r)) {
1514 if (($can_post || can_write_wall($owner_uid)) && $link_item['last-child']) {
1515 $comments .= replace_macros($cmnt_tpl, array(
1516 '$return_path' => '',
1517 '$jsreload' => $return_url,
1518 '$type' => 'wall-comment',
1519 '$id' => $link_item['id'],
1520 '$parent' => $link_item['id'],
1521 '$profile_uid' => $owner_uid,
1522 '$mylink' => $contact['url'],
1523 '$mytitle' => t('This is you'),
1524 '$myphoto' => $contact['thumb'],
1525 '$comment' => t('Comment'),
1526 '$submit' => t('Submit'),
1527 '$preview' => t('Preview'),
1528 '$sourceapp' => t($a->sourcename),
1530 '$rand_num' => random_digits(12)
1535 $conv_responses = array(
1536 'like' => array('title' => t('Likes','title')),'dislike' => array('title' => t('Dislikes','title')),
1537 'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title'))
1541 if (DBM::is_result($r)) {
1542 foreach ($r as $item) {
1543 builtin_activity_puller($item, $conv_responses);
1546 if (x($conv_responses['like'], $link_item['uri'])) {
1547 $like = format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like', $link_item['id']);
1549 if (x($conv_responses['dislike'], $link_item['uri'])) {
1550 $dislike = format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike', $link_item['id']);
1553 if (($can_post || can_write_wall($owner_uid)) && $link_item['last-child']) {
1554 $comments .= replace_macros($cmnt_tpl,array(
1555 '$return_path' => '',
1556 '$jsreload' => $return_url,
1557 '$type' => 'wall-comment',
1558 '$id' => $link_item['id'],
1559 '$parent' => $link_item['id'],
1560 '$profile_uid' => $owner_uid,
1561 '$mylink' => $contact['url'],
1562 '$mytitle' => t('This is you'),
1563 '$myphoto' => $contact['thumb'],
1564 '$comment' => t('Comment'),
1565 '$submit' => t('Submit'),
1566 '$preview' => t('Preview'),
1567 '$sourceapp' => t($a->sourcename),
1569 '$rand_num' => random_digits(12)
1573 foreach ($r as $item) {
1578 if ((activity_match($item['verb'], ACTIVITY_LIKE) || activity_match($item['verb'], ACTIVITY_DISLIKE)) && ($item['id'] != $item['parent'])) {
1582 $redirect_url = 'redir/' . $item['cid'];
1584 if (local_user() && ($item['contact-uid'] == local_user())
1585 && ($item['network'] == NETWORK_DFRN) && !$item['self']) {
1586 $profile_url = $redirect_url;
1587 $sparkle = ' sparkle';
1589 $profile_url = $item['url'];
1593 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1595 $profile_name = ((strlen($item['author-name']) && $diff_author) ? $item['author-name'] : $item['name']);
1596 $profile_avatar = ((strlen($item['author-avatar']) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1598 $profile_link = $profile_url;
1600 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1602 'dropping' => $dropping,
1603 'pagedrop' => false,
1604 'select' => t('Select'),
1605 'delete' => t('Delete'),
1608 $name_e = $profile_name;
1609 $title_e = $item['title'];
1610 $body_e = bbcode($item['body']);
1612 $comments .= replace_macros($template,array(
1613 '$id' => $item['item_id'],
1614 '$profile_url' => $profile_link,
1616 '$thumb' => $profile_avatar,
1617 '$sparkle' => $sparkle,
1618 '$title' => $title_e,
1620 '$ago' => relative_date($item['created']),
1621 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1623 '$comment' => $comment
1626 if (($can_post || can_write_wall($owner_uid)) && $item['last-child']) {
1627 $comments .= replace_macros($cmnt_tpl, array(
1628 '$return_path' => '',
1629 '$jsreload' => $return_url,
1630 '$type' => 'wall-comment',
1631 '$id' => $item['item_id'],
1632 '$parent' => $item['parent'],
1633 '$profile_uid' => $owner_uid,
1634 '$mylink' => $contact['url'],
1635 '$mytitle' => t('This is you'),
1636 '$myphoto' => $contact['thumb'],
1637 '$comment' => t('Comment'),
1638 '$submit' => t('Submit'),
1639 '$preview' => t('Preview'),
1640 '$sourceapp' => t($a->sourcename),
1642 '$rand_num' => random_digits(12)
1647 $response_verbs = array('like');
1648 if (Feature::isEnabled($owner_uid, 'dislike')) {
1649 $response_verbs[] = 'dislike';
1651 $responses = get_responses($conv_responses, $response_verbs, '', $link_item);
1653 $paginate = paginate($a);
1656 $photo_tpl = get_markup_template('photo_view.tpl');
1657 $o .= replace_macros($photo_tpl, array(
1658 '$id' => $ph[0]['id'],
1659 '$album' => [$album_link, $ph[0]['album']],
1663 '$prevlink' => $prevlink,
1664 '$nextlink' => $nextlink,
1665 '$desc' => $ph[0]['desc'],
1669 '$map_text' => t('Map'),
1670 '$likebuttons' => $likebuttons,
1672 '$dislike' => $dislike,
1673 'responses' => $responses,
1674 '$comments' => $comments,
1675 '$paginate' => $paginate,
1678 $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="photo" />' . "\n";
1679 $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1680 $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . $photo["href"] . '" />' . "\n";
1681 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1682 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1687 // Default - show recent photos with upload link (if applicable)
1690 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1691 $sql_extra GROUP BY `resource-id`",
1692 intval($a->data['user']['uid']),
1693 dbesc('Contact Photos'),
1694 dbesc( t('Contact Photos'))
1696 if (DBM::is_result($r)) {
1697 $a->set_pager_total(count($r));
1698 $a->set_pager_itemspage(20);
1701 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1702 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1703 ANY_VALUE(`created`) AS `created` FROM `photo`
1704 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1705 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1706 intval($a->data['user']['uid']),
1707 dbesc('Contact Photos'),
1708 dbesc( t('Contact Photos')),
1709 intval($a->pager['start']),
1710 intval($a->pager['itemspage'])
1714 if (DBM::is_result($r)) {
1715 // "Twist" is only used for the duepunto theme with style "slackr"
1717 foreach ($r as $rr) {
1718 //hide profile photos to others
1719 if (!$is_owner && !remote_user() && ($rr['album'] == t('Profile Photos')))
1724 $ext = $phototypes[$rr['type']];
1726 $alt_e = $rr['filename'];
1727 $name_e = $rr['album'];
1731 'twist' => ' ' . ($twist ? 'rotleft' : 'rotright') . rand(2,4),
1732 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1733 'title' => t('View Photo'),
1734 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1737 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1739 'alt' => t('View Album'),
1746 $tpl = get_markup_template('photos_recent.tpl');
1747 $o .= replace_macros($tpl, array(
1748 '$title' => t('Recent Photos'),
1749 '$can_post' => $can_post,
1750 '$upload' => array(t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'),
1751 '$photos' => $photos,
1752 '$paginate' => paginate($a),