4 use Friendica\Core\System;
5 use Friendica\Core\Config;
6 use Friendica\Network\Probe;
8 require_once 'include/Photo.php';
9 require_once 'include/photos.php';
10 require_once 'include/items.php';
11 require_once 'include/acl_selectors.php';
12 require_once 'include/bbcode.php';
13 require_once 'include/security.php';
14 require_once 'include/redir.php';
15 require_once 'include/tags.php';
16 require_once 'include/threads.php';
18 function photos_init(App $a) {
21 auto_redir($a, $a->argv[1]);
24 if ((get_config('system', 'block_public')) && (! local_user()) && (! remote_user())) {
28 nav_set_selected('home');
32 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
36 if (! dbm::is_result($user)) {
40 $a->data['user'] = $user[0];
41 $a->profile_uid = $user[0]['uid'];
42 $is_owner = (local_user() && (local_user() == $a->profile_uid));
44 $profile = get_profiledata_by_nick($nick, $a->profile_uid);
46 $account_type = account_type($profile);
48 $tpl = get_markup_template("vcard-widget.tpl");
50 $vcard_widget .= replace_macros($tpl, array(
51 '$name' => $profile['name'],
52 '$photo' => $profile['photo'],
53 '$addr' => (($profile['addr'] != "") ? $profile['addr'] : ""),
54 '$account_type' => $account_type,
55 '$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""),
58 $albums = photo_albums($a->data['user']['uid']);
60 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
62 // add various encodings to the array so we can just loop through and pick them out in a template
63 $ret = array('success' => false);
66 $a->data['albums'] = $albums;
67 if ($albums_visible) {
68 $ret['success'] = true;
71 $ret['albums'] = array();
72 foreach ($albums as $k => $album) {
73 //hide profile photos to others
74 if ((! $is_owner) && (! remote_user()) && ($album['album'] == t('Profile Photos')))
77 'text' => $album['album'],
78 'total' => $album['total'],
79 'url' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
80 'urlencode' => urlencode($album['album']),
81 'bin2hex' => bin2hex($album['album'])
83 $ret['albums'][] = $entry;
89 if (local_user() && $a->data['user']['uid'] == local_user()) {
93 if ($albums['success']) {
94 $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'), array(
95 '$nick' => $a->data['user']['nickname'],
96 '$title' => t('Photo Albums'),
97 '$recent' => t('Recent Photos'),
98 '$albums' => $albums['albums'],
99 '$baseurl' => System::baseUrl(),
100 '$upload' => array(t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'),
101 '$can_post' => $can_post
106 if (! x($a->page, 'aside')) {
107 $a->page['aside'] = '';
109 $a->page['aside'] .= $vcard_widget;
110 $a->page['aside'] .= $photo_albums_widget;
113 $tpl = get_markup_template("photos_head.tpl");
114 $a->page['htmlhead'] .= replace_macros($tpl,array(
115 '$ispublic' => t('everybody')
125 function photos_post(App $a) {
127 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
130 logger('mod_photos: REQUEST ' . print_r($_REQUEST,true), LOGGER_DATA);
131 logger('mod_photos: FILES ' . print_r($_FILES,true), LOGGER_DATA);
133 $phototypes = Photo::supportedTypes();
138 $page_owner_uid = $a->data['user']['uid'];
139 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
141 if ((local_user()) && (local_user() == $page_owner_uid)) {
144 if ($community_page && remote_user()) {
146 if (is_array($_SESSION['remote'])) {
147 foreach ($_SESSION['remote'] as $v) {
148 if ($v['uid'] == $page_owner_uid) {
149 $contact_id = $v['cid'];
156 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
158 intval($page_owner_uid)
160 if (dbm::is_result($r)) {
162 $visitor = $contact_id;
169 notice( t('Permission denied.') . EOL );
173 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
174 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
175 intval($page_owner_uid)
178 if (! dbm::is_result($r)) {
179 notice( t('Contact information unavailable') . EOL);
180 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
184 $owner_record = $r[0];
187 if (($a->argc > 3) && ($a->argv[2] === 'album')) {
188 $album = hex2bin($a->argv[3]);
190 if ($album === t('Profile Photos') || $album === 'Contact Photos' || $album === t('Contact Photos')) {
191 goaway($_SESSION['photo_return']);
192 return; // NOTREACHED
195 $r = q("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
197 intval($page_owner_uid)
199 if (!dbm::is_result($r)) {
200 notice( t('Album not found.') . EOL);
201 goaway($_SESSION['photo_return']);
202 return; // NOTREACHED
205 // Check if the user has responded to a delete confirmation query
206 if ($_REQUEST['canceled']) {
207 goaway($_SESSION['photo_return']);
214 $newalbum = notags(trim($_POST['albumname']));
215 if ($newalbum != $album) {
216 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
219 intval($page_owner_uid)
221 // Update the photo albums cache
222 photo_albums($page_owner_uid, true);
224 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
226 return; // NOTREACHED
230 * DELETE photo album and all its photos
233 if ($_POST['dropalbum'] == t('Delete Album')) {
235 // Check if we should do HTML-based delete confirmation
236 if ($_REQUEST['confirm']) {
237 $drop_url = $a->query_string;
238 $extra_inputs = array(
239 array('name' => 'albumname', 'value' => $_POST['albumname']),
241 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
243 '$message' => t('Do you really want to delete this photo album and all its photos?'),
244 '$extra_inputs' => $extra_inputs,
245 '$confirm' => t('Delete Album'),
246 '$confirm_url' => $drop_url,
247 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
248 '$cancel' => t('Cancel'),
250 $a->error = 1; // Set $a->error so the other module functions don't execute
256 // get the list of photos we are about to delete
259 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
261 intval($page_owner_uid),
265 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
266 intval(local_user()),
270 if (dbm::is_result($r)) {
271 foreach ($r as $rr) {
272 $res[] = "'" . dbesc($rr['rid']) . "'" ;
275 goaway($_SESSION['photo_return']);
276 return; // NOTREACHED
279 $str_res = implode(',', $res);
281 // remove the associated photos
283 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
284 intval($page_owner_uid)
287 // find and delete the corresponding item with all the comments and likes/dislikes
289 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
290 intval($page_owner_uid)
292 if (dbm::is_result($r)) {
293 foreach ($r as $rr) {
294 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
295 dbesc(datetime_convert()),
296 dbesc($rr['parent-uri']),
297 intval($page_owner_uid)
299 create_tags_from_itemuri($rr['parent-uri'], $page_owner_uid);
300 delete_thread_uri($rr['parent-uri'], $page_owner_uid);
302 $drop_id = intval($rr['id']);
304 // send the notification upstream/downstream as the case may be
306 if ($rr['visible']) {
307 proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
312 // Update the photo albums cache
313 photo_albums($page_owner_uid, true);
316 goaway('photos/' . $a->data['user']['nickname']);
317 return; // NOTREACHED
321 // Check if the user has responded to a delete confirmation query for a single photo
322 if (($a->argc > 2) && $_REQUEST['canceled']) {
323 goaway($_SESSION['photo_return']);
326 if (($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
328 // same as above but remove single photo
330 // Check if we should do HTML-based delete confirmation
331 if ($_REQUEST['confirm']) {
332 $drop_url = $a->query_string;
333 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
335 '$message' => t('Do you really want to delete this photo?'),
336 '$extra_inputs' => array(),
337 '$confirm' => t('Delete Photo'),
338 '$confirm_url' => $drop_url,
339 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
340 '$cancel' => t('Cancel'),
342 $a->error = 1; // Set $a->error so the other module functions don't execute
347 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
349 intval($page_owner_uid),
353 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
354 intval(local_user()),
358 if (dbm::is_result($r)) {
359 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
360 intval($page_owner_uid),
361 dbesc($r[0]['resource-id'])
363 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
364 dbesc($r[0]['resource-id']),
365 intval($page_owner_uid)
367 if (dbm::is_result($i)) {
368 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
369 dbesc(datetime_convert()),
370 dbesc(datetime_convert()),
372 intval($page_owner_uid)
374 create_tags_from_itemuri($i[0]['uri'], $page_owner_uid);
375 delete_thread_uri($i[0]['uri'], $page_owner_uid);
377 $url = System::baseUrl();
378 $drop_id = intval($i[0]['id']);
380 // Update the photo albums cache
381 photo_albums($page_owner_uid, true);
383 if ($i[0]['visible']) {
384 proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
389 goaway('photos/' . $a->data['user']['nickname']);
390 return; // NOTREACHED
393 if (($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
395 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
396 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
397 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
398 $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
399 $origaname = ((x($_POST,'origaname')) ? notags(trim($_POST['origaname'])) : '');
400 $str_group_allow = perms2str($_POST['group_allow']);
401 $str_contact_allow = perms2str($_POST['contact_allow']);
402 $str_group_deny = perms2str($_POST['group_deny']);
403 $str_contact_deny = perms2str($_POST['contact_deny']);
405 $resource_id = $a->argv[2];
407 if (! strlen($albname)) {
408 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
412 if ((x($_POST,'rotate') !== false) &&
413 ( (intval($_POST['rotate']) == 1) || (intval($_POST['rotate']) == 2) )) {
416 $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0 LIMIT 1",
418 intval($page_owner_uid)
420 if (dbm::is_result($r)) {
421 $ph = new Photo($r[0]['data'], $r[0]['type']);
422 if ($ph->is_valid()) {
423 $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
424 $ph->rotate($rotate_deg);
426 $width = $ph->getWidth();
427 $height = $ph->getHeight();
429 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0",
430 dbesc($ph->imageString()),
434 intval($page_owner_uid)
437 if ($width > 640 || $height > 640) {
438 $ph->scaleImage(640);
439 $width = $ph->getWidth();
440 $height = $ph->getHeight();
442 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 1",
443 dbesc($ph->imageString()),
447 intval($page_owner_uid)
451 if ($width > 320 || $height > 320) {
452 $ph->scaleImage(320);
453 $width = $ph->getWidth();
454 $height = $ph->getHeight();
456 $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 2",
457 dbesc($ph->imageString()),
461 intval($page_owner_uid)
468 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
470 intval($page_owner_uid)
472 if (dbm::is_result($p)) {
473 $ext = $phototypes[$p[0]['type']];
474 $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",
477 dbesc($str_contact_allow),
478 dbesc($str_group_allow),
479 dbesc($str_contact_deny),
480 dbesc($str_group_deny),
482 intval($page_owner_uid)
485 // Update the photo albums cache if album name was changed
486 if ($albname !== $origaname) {
487 photo_albums($page_owner_uid, true);
491 /* Don't make the item visible if the only change was the album name */
494 if ($p[0]['desc'] !== $desc || strlen($rawtags)) {
500 // Create item container
503 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
506 $arr['guid'] = get_guid(32);
507 $arr['uid'] = $page_owner_uid;
509 $arr['parent-uri'] = $uri;
510 $arr['type'] = 'photo';
512 $arr['resource-id'] = $p[0]['resource-id'];
513 $arr['contact-id'] = $owner_record['id'];
514 $arr['owner-name'] = $owner_record['name'];
515 $arr['owner-link'] = $owner_record['url'];
516 $arr['owner-avatar'] = $owner_record['thumb'];
517 $arr['author-name'] = $owner_record['name'];
518 $arr['author-link'] = $owner_record['url'];
519 $arr['author-avatar'] = $owner_record['thumb'];
520 $arr['title'] = $title;
521 $arr['allow_cid'] = $p[0]['allow_cid'];
522 $arr['allow_gid'] = $p[0]['allow_gid'];
523 $arr['deny_cid'] = $p[0]['deny_cid'];
524 $arr['deny_gid'] = $p[0]['deny_gid'];
525 $arr['last-child'] = 1;
526 $arr['visible'] = $visibility;
529 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
530 . '[img]' . System::baseUrl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
533 $item_id = item_store($arr);
538 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
540 intval($page_owner_uid)
543 if (dbm::is_result($r)) {
544 $old_tag = $r[0]['tag'];
545 $old_inform = $r[0]['inform'];
548 if (strlen($rawtags)) {
553 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
555 $x = substr($rawtags,0,1);
556 if ($x !== '@' && $x !== '#') {
557 $rawtags = '#' . $rawtags;
561 $tags = get_tags($rawtags);
564 foreach ($tags as $tag) {
565 if (isset($profile)) {
568 if (strpos($tag, '@') === 0) {
569 $name = substr($tag,1);
570 if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
572 $links = @Probe::lrdd($name);
574 foreach ($links as $link) {
575 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
576 $profile = $link['@attributes']['href'];
578 if ($link['@attributes']['rel'] === 'salmon') {
579 $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
580 if (strlen($inform)) {
587 $taginfo[] = array($newname, $profile, $salmon);
592 if (strrpos($newname, '+')) {
593 $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
597 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
602 $newname = str_replace('_',' ',$name);
604 //select someone from this user's contacts by name
605 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
607 intval($page_owner_uid)
610 if (! dbm::is_result($r)) {
611 //select someone by attag or nick and the name passed in
612 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
615 intval($page_owner_uid)
620 if (dbm::is_result($r)) {
621 $newname = $r[0]['name'];
622 $profile = $r[0]['url'];
623 $notify = 'cid:' . $r[0]['id'];
624 if (strlen($inform)) {
631 if (substr($notify, 0, 4) === 'cid:') {
632 $taginfo[] = array($newname, $profile, $notify, $r[0], '@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
634 $taginfo[] = array($newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
636 if (strlen($str_tags)) {
639 $profile = str_replace(',', '%2c', $profile);
640 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
642 } elseif (strpos($tag, '#') === 0) {
643 $tagname = substr($tag, 1);
644 $str_tags .= '#[url=' . System::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url]';
650 if (strlen($newtag) && strlen($str_tags)) {
653 $newtag .= $str_tags;
655 $newinform = $old_inform;
656 if (strlen($newinform) && strlen($inform)) {
659 $newinform .= $inform;
661 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
664 dbesc(datetime_convert()),
665 dbesc(datetime_convert()),
667 intval($page_owner_uid)
669 create_tags_from_item($item_id);
670 update_thread($item_id);
673 foreach ($p as $scales) {
674 if (intval($scales['scale']) == 2) {
678 if (intval($scales['scale']) == 4) {
684 if (count($taginfo)) {
685 foreach ($taginfo as $tagged) {
687 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
690 $arr['guid'] = get_guid(32);
691 $arr['uid'] = $page_owner_uid;
693 $arr['parent-uri'] = $uri;
694 $arr['type'] = 'activity';
696 $arr['contact-id'] = $owner_record['id'];
697 $arr['owner-name'] = $owner_record['name'];
698 $arr['owner-link'] = $owner_record['url'];
699 $arr['owner-avatar'] = $owner_record['thumb'];
700 $arr['author-name'] = $owner_record['name'];
701 $arr['author-link'] = $owner_record['url'];
702 $arr['author-avatar'] = $owner_record['thumb'];
704 $arr['allow_cid'] = $p[0]['allow_cid'];
705 $arr['allow_gid'] = $p[0]['allow_gid'];
706 $arr['deny_cid'] = $p[0]['deny_cid'];
707 $arr['deny_gid'] = $p[0]['deny_gid'];
708 $arr['last-child'] = 1;
710 $arr['verb'] = ACTIVITY_TAG;
711 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
712 $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
713 $arr['tag'] = $tagged[4];
714 $arr['inform'] = $tagged[2];
716 $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]') ;
717 $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" ;
719 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
720 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
722 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
724 $arr['object'] .= '</link></object>' . "\n";
726 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $p[0]['desc'] . '</title><id>'
727 . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
728 $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>';
730 $item_id = item_store($arr);
732 proc_run(PRIORITY_HIGH, "include/notifier.php", "tag", $item_id);
737 goaway($_SESSION['photo_return']);
738 return; // NOTREACHED
743 * default post action - upload a photo
746 call_hooks('photo_post_init', $_POST);
749 * Determine the album to use
752 $album = notags(trim($_REQUEST['album']));
753 $newalbum = notags(trim($_REQUEST['newalbum']));
755 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
757 if (! strlen($album)) {
758 if (strlen($newalbum)) {
761 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
766 * We create a wall item for every photo, but we don't want to
767 * overwhelm the data stream with a hundred newly uploaded photos.
768 * So we will make the first photo uploaded to this album in the last several hours
769 * visible by default, the rest will become visible over time when and if
770 * they acquire comments, likes, dislikes, and/or tags
773 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
775 intval($page_owner_uid)
777 if ((! dbm::is_result($r)) || ($album == t('Profile Photos'))) {
783 if (intval($_REQUEST['not_visible']) || $_REQUEST['not_visible'] === 'true') {
787 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',', $_REQUEST['group_allow'])));
788 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',', $_REQUEST['contact_allow'])));
789 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',', $_REQUEST['group_deny'])));
790 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',', $_REQUEST['contact_deny'])));
792 $ret = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
794 call_hooks('photo_post_file',$ret);
796 if (x($ret,'src') && x($ret,'filesize')) {
798 $filename = $ret['filename'];
799 $filesize = $ret['filesize'];
800 $type = $ret['type'];
802 $src = $_FILES['userfile']['tmp_name'];
803 $filename = basename($_FILES['userfile']['name']);
804 $filesize = intval($_FILES['userfile']['size']);
805 $type = $_FILES['userfile']['type'];
808 $type = guess_image_type($filename);
811 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
813 $maximagesize = get_config('system','maximagesize');
815 if (($maximagesize) && ($filesize > $maximagesize)) {
816 notice( sprintf(t('Image exceeds size limit of %s'), formatBytes($maximagesize)) . EOL);
819 call_hooks('photo_post_end',$foo);
824 notice( t('Image file is empty.') . EOL);
827 call_hooks('photo_post_end',$foo);
831 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
833 $imagedata = @file_get_contents($src);
835 $ph = new Photo($imagedata, $type);
837 if (! $ph->is_valid()) {
838 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
839 notice( t('Unable to process image.') . EOL );
842 call_hooks('photo_post_end',$foo);
846 $exif = $ph->orient($src);
849 $max_length = get_config('system', 'max_image_length');
851 $max_length = MAX_IMAGE_LENGTH;
853 if ($max_length > 0) {
854 $ph->scaleImage($max_length);
857 $width = $ph->getWidth();
858 $height = $ph->getHeight();
862 $photo_hash = photo_new_resource();
864 $r = $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
867 logger('mod/photos.php: photos_post(): image store failed' , LOGGER_DEBUG);
868 notice( t('Image upload failed.') . EOL );
872 if ($width > 640 || $height > 640) {
873 $ph->scaleImage(640);
874 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
878 if ($width > 320 || $height > 320) {
879 $ph->scaleImage(320);
880 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
884 $basename = basename($filename);
885 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
887 // Create item container
891 /// @TODO merge these 2 if() into one?
892 if ($exif && $exif['GPS']) {
893 if (feature_enabled($channel_id,'photo_location')) {
894 $lat = getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
895 $lon = getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
902 $arr['coord'] = $lat . ' ' . $lon;
905 $arr['guid'] = get_guid(32);
906 $arr['uid'] = $page_owner_uid;
908 $arr['parent-uri'] = $uri;
909 $arr['type'] = 'photo';
911 $arr['resource-id'] = $photo_hash;
912 $arr['contact-id'] = $owner_record['id'];
913 $arr['owner-name'] = $owner_record['name'];
914 $arr['owner-link'] = $owner_record['url'];
915 $arr['owner-avatar'] = $owner_record['thumb'];
916 $arr['author-name'] = $owner_record['name'];
917 $arr['author-link'] = $owner_record['url'];
918 $arr['author-avatar'] = $owner_record['thumb'];
920 $arr['allow_cid'] = $str_contact_allow;
921 $arr['allow_gid'] = $str_group_allow;
922 $arr['deny_cid'] = $str_contact_deny;
923 $arr['deny_gid'] = $str_group_deny;
924 $arr['last-child'] = 1;
925 $arr['visible'] = $visible;
928 $arr['body'] = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
929 . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]'
932 $item_id = item_store($arr);
933 // Update the photo albums cache
934 photo_albums($page_owner_uid, true);
937 proc_run(PRIORITY_HIGH, "include/notifier.php", 'wall-new', $item_id);
940 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
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
963 if ((get_config('system', 'block_public')) && (! local_user()) && (! remote_user())) {
964 notice( t('Public access denied.') . EOL);
968 require_once 'include/bbcode.php';
969 require_once 'include/security.php';
970 require_once 'include/conversation.php';
972 if (! x($a->data,'user')) {
973 notice( t('No photos selected') . EOL );
977 $phototypes = Photo::supportedTypes();
979 $_SESSION['photo_return'] = $a->cmd;
986 $datatype = $a->argv[2];
987 $datum = $a->argv[3];
988 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
989 $datatype = 'upload';
991 $datatype = 'summary';
1001 // Setup permissions structures
1007 $remote_contact = false;
1010 $owner_uid = $a->data['user']['uid'];
1012 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
1014 if ((local_user()) && (local_user() == $owner_uid)) {
1017 if ($community_page && remote_user()) {
1018 if (is_array($_SESSION['remote'])) {
1019 foreach ($_SESSION['remote'] as $v) {
1020 if ($v['uid'] == $owner_uid) {
1021 $contact_id = $v['cid'];
1028 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1029 intval($contact_id),
1032 if (dbm::is_result($r)) {
1035 $remote_contact = true;
1036 $visitor = $contact_id;
1042 // perhaps they're visiting - but not a community page, so they wouldn't have write access
1044 if (remote_user() && (! $visitor)) {
1046 if (is_array($_SESSION['remote'])) {
1047 foreach ($_SESSION['remote'] as $v) {
1048 if ($v['uid'] == $owner_uid) {
1049 $contact_id = $v['cid'];
1055 $groups = init_groups_visitor($contact_id);
1056 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1057 intval($contact_id),
1060 if (dbm::is_result($r)) {
1062 $remote_contact = true;
1067 /// @TODO merge these 2 if() into one?
1068 if (! $remote_contact) {
1070 $contact_id = $_SESSION['cid'];
1071 $contact = $a->contact;
1075 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
1076 notice( t('Access to this item is restricted.') . EOL);
1080 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
1085 $is_owner = (local_user() && (local_user() == $owner_uid));
1086 $o .= profile_tabs($a, $is_owner, $a->data['user']['nickname']);
1089 * Display upload form
1092 if ($datatype === 'upload') {
1093 if (! ($can_post)) {
1094 notice(t('Permission denied.'));
1099 $selname = (($datum) ? hex2bin($datum) : '');
1105 $albumselect .= '<option value="" ' . ((! $selname) ? ' selected="selected" ' : '') . '> </option>';
1106 if (count($a->data['albums'])) {
1107 foreach ($a->data['albums'] as $album) {
1108 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos'))) {
1111 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1112 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1118 $ret = array('post_url' => 'photos/' . $a->data['user']['nickname'],
1119 'addon_text' => $uploader,
1120 'default_upload' => true);
1122 call_hooks('photo_upload_form',$ret);
1124 $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), array());
1125 $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), array(
1126 '$submit' => t('Submit'),
1129 $usage_message = '';
1131 // Private/public post links for the non-JS ACL form
1133 if ($_REQUEST['public']) {
1137 $query_str = $a->query_string;
1138 if (strpos($query_str, 'public=1') !== false) {
1139 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1143 * I think $a->query_string may never have ? in it, but I could be wrong
1144 * It looks like it's from the index.php?q=[etc] rewrite that the web
1145 * server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1147 if (strpos($query_str, '?') === false) {
1148 $public_post_link = '?public=1';
1150 $public_post_link = '&public=1';
1153 $tpl = get_markup_template('photos_upload.tpl');
1155 if ($a->theme['template_engine'] === 'internal') {
1156 $albumselect_e = template_escape($albumselect);
1157 $aclselect_e = (($visitor) ? '' : template_escape(populate_acl($a->user)));
1159 $albumselect_e = $albumselect;
1160 $aclselect_e = (($visitor) ? '' : populate_acl($a->user));
1163 $o .= replace_macros($tpl,array(
1164 '$pagename' => t('Upload Photos'),
1165 '$sessid' => session_id(),
1166 '$usage' => $usage_message,
1167 '$nickname' => $a->data['user']['nickname'],
1168 '$newalbum' => t('New album name: '),
1169 '$existalbumtext' => t('or existing album name: '),
1170 '$nosharetext' => t('Do not show a status post for this upload'),
1171 '$albumselect' => $albumselect_e,
1172 '$permissions' => t('Permissions'),
1173 '$aclselect' => $aclselect_e,
1174 '$alt_uploader' => $ret['addon_text'],
1175 '$default_upload_box' => (($ret['default_upload']) ? $default_upload_box : ''),
1176 '$default_upload_submit' => (($ret['default_upload']) ? $default_upload_submit : ''),
1177 '$uploadurl' => $ret['post_url'],
1179 // ACL permissions box
1180 '$acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
1181 '$group_perms' => t('Show to Groups'),
1182 '$contact_perms' => t('Show to Contacts'),
1183 '$private' => t('Private Photo'),
1184 '$public' => t('Public Photo'),
1185 '$is_private' => $private_post,
1186 '$return_path' => $query_str,
1187 '$public_link' => $public_post_link,
1195 * Display a single photo album
1198 if ($datatype === 'album') {
1200 $album = hex2bin($datum);
1202 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1203 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1207 if (dbm::is_result($r)) {
1208 $a->set_pager_total(count($r));
1209 $a->set_pager_itemspage(20);
1212 /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
1213 if ($_GET['order'] === 'posted') {
1219 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1220 ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
1221 ANY_VALUE(`created`) as `created`
1222 FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1223 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1226 intval($a->pager['start']),
1227 intval($a->pager['itemspage'])
1231 if ($cmd === 'edit') {
1232 if (($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1234 $edit_tpl = get_markup_template('album_edit.tpl');
1236 if ($a->theme['template_engine'] === 'internal') {
1237 $album_e = template_escape($album);
1242 $o .= replace_macros($edit_tpl,array(
1243 '$nametext' => t('New album name: '),
1244 '$nickname' => $a->data['user']['nickname'],
1245 '$album' => $album_e,
1246 '$hexalbum' => bin2hex($album),
1247 '$submit' => t('Submit'),
1248 '$dropsubmit' => t('Delete Album')
1253 if (($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos')) && $can_post) {
1254 $edit = array(t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit');
1258 if ($_GET['order'] === 'posted') {
1259 $order = array(t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album));
1261 $order = array(t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted');
1266 if (dbm::is_result($r))
1267 $twist = 'rotright';
1268 foreach ($r as $rr) {
1269 if ($twist == 'rotright') {
1272 $twist = 'rotright';
1275 $ext = $phototypes[$rr['type']];
1277 if ($a->theme['template_engine'] === 'internal') {
1278 $imgalt_e = template_escape($rr['filename']);
1279 $desc_e = template_escape($rr['desc']);
1281 $imgalt_e = $rr['filename'];
1282 $desc_e = $rr['desc'];
1287 'twist' => ' ' . $twist . rand(2,4),
1288 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1289 . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''),
1290 'title' => t('View Photo'),
1291 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1295 'hash'=> $rr['resource_id'],
1299 $tpl = get_markup_template('photo_album.tpl');
1300 $o .= replace_macros($tpl, array(
1301 '$photos' => $photos,
1303 '$can_post' => $can_post,
1304 '$upload' => array(t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)),
1307 '$paginate' => paginate($a),
1317 if ($datatype === 'image') {
1320 // fetch image, item containing image, then comments
1322 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1323 $sql_extra ORDER BY `scale` ASC ",
1328 if (! dbm::is_result($ph)) {
1329 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1334 if (dbm::is_result($ph)) {
1335 notice(t('Permission denied. Access to this item may be restricted.'));
1337 notice(t('Photo not available') . EOL );
1345 /// @todo This query is totally bad, the whole functionality has to be changed
1346 // The query leads to a really intense used index.
1347 // By now we hide it if someone wants to.
1348 if (!Config::get('system', 'no_count', false)) {
1349 if ($_GET['order'] === 'posted')
1354 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1355 $sql_extra ORDER BY `created` $order ",
1356 dbesc($ph[0]['album']),
1360 if (dbm::is_result($prvnxt)) {
1361 foreach ($prvnxt as $z => $entry) {
1362 if ($entry['resource-id'] == $ph[0]['resource-id']) {
1366 $prv = count($prvnxt) - 1;
1368 if ($nxt >= count($prvnxt)) {
1374 $edit_suffix = ((($cmd === 'edit') && ($can_post)) ? '/edit' : '');
1375 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1376 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1380 if (count($ph) == 1)
1381 $hires = $lores = $ph[0];
1382 if (count($ph) > 1) {
1383 if ($ph[1]['scale'] == 2) {
1384 // original is 640 or less, we can display it directly
1385 $hires = $lores = $ph[0];
1392 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1396 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1398 'edit' => array('photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? t('View photo') : t('Edit photo'))),
1399 'profile'=>array('profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
1403 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1404 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1405 ? t('Private Message')
1411 if ( $cmd === 'edit') {
1412 $tpl = get_markup_template('photo_edit_head.tpl');
1413 $a->page['htmlhead'] .= replace_macros($tpl,array(
1414 '$prevlink' => $prevlink,
1415 '$nextlink' => $nextlink
1420 $prevlink = array($prevlink, '<div class="icon prev"></div>') ;
1423 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1424 'title'=> t('View Full Size'),
1425 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis'),
1426 'height' => $hires['height'],
1427 'width' => $hires['width'],
1428 'album' => $hires['album'],
1429 'filename' => $hires['filename'],
1433 $nextlink = array($nextlink, '<div class="icon next"></div>');
1437 // Do we have an item for this photo?
1439 // FIXME! - replace following code to display the conversation with our normal
1440 // conversation functions so that it works correctly and tracks changes
1441 // in the evolving conversation code.
1442 // The difference is that we won't be displaying the conversation head item
1443 // as a "post" but displaying instead the photo it is linked to
1445 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1451 if (dbm::is_result($linked_items)) {
1452 $link_item = $linked_items[0];
1454 $r = q("SELECT COUNT(*) AS `total`
1455 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1456 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1457 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1458 AND `item`.`uid` = %d
1460 dbesc($link_item['uri']),
1461 dbesc($link_item['uri']),
1462 intval($link_item['uid'])
1466 if (dbm::is_result($r)) {
1467 $a->set_pager_total($r[0]['total']);
1471 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1472 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1473 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1474 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1475 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1476 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1477 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1478 AND `item`.`uid` = %d
1480 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1481 dbesc($link_item['uri']),
1482 dbesc($link_item['uri']),
1483 intval($link_item['uid']),
1484 intval($a->pager['start']),
1485 intval($a->pager['itemspage'])
1489 if ((local_user()) && (local_user() == $link_item['uid'])) {
1490 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1491 intval($link_item['parent']),
1492 intval(local_user())
1494 update_thread($link_item['parent']);
1497 if ($link_item['coord']) {
1498 $map = generate_map($link_item['coord']);
1504 if (count($linked_items) && strlen($link_item['tag'])) {
1505 $arr = explode(',', $link_item['tag']);
1506 // parse tags and add links
1508 foreach ($arr as $t) {
1509 if (strlen($tag_str)) {
1512 $tag_str .= bbcode($t);
1514 $tags = array(t('Tags: '), $tag_str);
1515 if ($cmd === 'edit') {
1516 $tags[] = 'tagrm/' . $link_item['id'];
1517 $tags[] = t('[Remove any tag]');
1523 if (($cmd === 'edit') && ($can_post)) {
1524 $edit_tpl = get_markup_template('photo_edit.tpl');
1526 // Private/public post links for the non-JS ACL form
1528 if ($_REQUEST['public']) {
1532 $query_str = $a->query_string;
1533 if (strpos($query_str, 'public=1') !== false) {
1534 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1538 * I think $a->query_string may never have ? in it, but I could be wrong
1539 * It looks like it's from the index.php?q=[etc] rewrite that the web
1540 * server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1542 if (strpos($query_str, '?') === false) {
1543 $public_post_link = '?public=1';
1545 $public_post_link = '&public=1';
1548 if ($a->theme['template_engine'] === 'internal') {
1549 $album_e = template_escape($ph[0]['album']);
1550 $caption_e = template_escape($ph[0]['desc']);
1551 $aclselect_e = template_escape(populate_acl($ph[0]));
1553 $album_e = $ph[0]['album'];
1554 $caption_e = $ph[0]['desc'];
1555 $aclselect_e = populate_acl($ph[0]);
1558 $edit = replace_macros($edit_tpl, array(
1559 '$id' => $ph[0]['id'],
1560 '$album' => array('albname', t('New album name'), $album_e,''),
1561 '$caption' => array('desc', t('Caption'), $caption_e, ''),
1562 '$tags' => array('newtag', t('Add a Tag'), "", t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')),
1563 '$rotate_none' => array('rotate', t('Do not rotate'),0,'', true),
1564 '$rotate_cw' => array('rotate', t('Rotate CW (right)'),1,''),
1565 '$rotate_ccw' => array('rotate', t('Rotate CCW (left)'),2,''),
1567 '$nickname' => $a->data['user']['nickname'],
1568 '$resource_id' => $ph[0]['resource-id'],
1569 '$permissions' => t('Permissions'),
1570 '$aclselect' => $aclselect_e,
1572 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1573 '$submit' => t('Submit'),
1574 '$delete' => t('Delete Photo'),
1576 // ACL permissions box
1577 '$acl_data' => construct_acl_data($a, $ph[0]), // For non-Javascript ACL selector
1578 '$group_perms' => t('Show to Groups'),
1579 '$contact_perms' => t('Show to Contacts'),
1580 '$private' => t('Private photo'),
1581 '$public' => t('Public photo'),
1582 '$is_private' => $private_post,
1583 '$return_path' => $query_str,
1584 '$public_link' => $public_post_link,
1588 if (count($linked_items)) {
1590 $cmnt_tpl = get_markup_template('comment_item.tpl');
1591 $tpl = get_markup_template('photo_item.tpl');
1592 $return_url = $a->cmd;
1594 $like_tpl = get_markup_template('like_noshare.tpl');
1598 if ($can_post || can_write_wall($a, $owner_uid)) {
1599 $likebuttons = replace_macros($like_tpl, array(
1600 '$id' => $link_item['id'],
1601 '$likethis' => t("I like this \x28toggle\x29"),
1602 '$nolike' => (feature_enabled(local_user(), 'dislike') ? t("I don't like this \x28toggle\x29") : ''),
1603 '$wait' => t('Please wait'),
1604 '$return_path' => $a->query_string,
1609 if (! dbm::is_result($r)) {
1610 if (($can_post || can_write_wall($a, $owner_uid)) && $link_item['last-child']) {
1611 $comments .= replace_macros($cmnt_tpl, array(
1612 '$return_path' => '',
1613 '$jsreload' => $return_url,
1614 '$type' => 'wall-comment',
1615 '$id' => $link_item['id'],
1616 '$parent' => $link_item['id'],
1617 '$profile_uid' => $owner_uid,
1618 '$mylink' => $contact['url'],
1619 '$mytitle' => t('This is you'),
1620 '$myphoto' => $contact['thumb'],
1621 '$comment' => t('Comment'),
1622 '$submit' => t('Submit'),
1623 '$preview' => t('Preview'),
1624 '$sourceapp' => t($a->sourcename),
1626 '$rand_num' => random_digits(12)
1637 $conv_responses = array(
1638 'like' => array('title' => t('Likes','title')),'dislike' => array('title' => t('Dislikes','title')),
1639 'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title'))
1643 if (dbm::is_result($r)) {
1645 foreach ($r as $item) {
1646 builtin_activity_puller($item, $conv_responses);
1649 $like = ((x($conv_responses['like'], $link_item['uri'])) ? format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like',$link_item['id']) : '');
1650 $dislike = ((x($conv_responses['dislike'], $link_item['uri'])) ? format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike',$link_item['id']) : '');
1652 if (($can_post || can_write_wall($a, $owner_uid)) && $link_item['last-child']) {
1653 $comments .= replace_macros($cmnt_tpl,array(
1654 '$return_path' => '',
1655 '$jsreload' => $return_url,
1656 '$type' => 'wall-comment',
1657 '$id' => $link_item['id'],
1658 '$parent' => $link_item['id'],
1659 '$profile_uid' => $owner_uid,
1660 '$mylink' => $contact['url'],
1661 '$mytitle' => t('This is you'),
1662 '$myphoto' => $contact['thumb'],
1663 '$comment' => t('Comment'),
1664 '$submit' => t('Submit'),
1665 '$preview' => t('Preview'),
1666 '$sourceapp' => t($a->sourcename),
1668 '$rand_num' => random_digits(12)
1673 foreach ($r as $item) {
1678 if (((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1681 $redirect_url = 'redir/' . $item['cid'];
1684 if (local_user() && ($item['contact-uid'] == local_user())
1685 && ($item['network'] == NETWORK_DFRN) && (! $item['self'] )) {
1686 $profile_url = $redirect_url;
1687 $sparkle = ' sparkle';
1689 $profile_url = $item['url'];
1693 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1695 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1696 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1698 $profile_link = $profile_url;
1700 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1702 'dropping' => $dropping,
1703 'pagedrop' => false,
1704 'select' => t('Select'),
1705 'delete' => t('Delete'),
1708 if ($a->theme['template_engine'] === 'internal') {
1709 $name_e = template_escape($profile_name);
1710 $title_e = template_escape($item['title']);
1711 $body_e = template_escape(bbcode($item['body']));
1713 $name_e = $profile_name;
1714 $title_e = $item['title'];
1715 $body_e = bbcode($item['body']);
1718 $comments .= replace_macros($template,array(
1719 '$id' => $item['item_id'],
1720 '$profile_url' => $profile_link,
1722 '$thumb' => $profile_avatar,
1723 '$sparkle' => $sparkle,
1724 '$title' => $title_e,
1726 '$ago' => relative_date($item['created']),
1727 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1729 '$comment' => $comment
1732 if (($can_post || can_write_wall($a, $owner_uid)) && $item['last-child']) {
1733 $comments .= replace_macros($cmnt_tpl, array(
1734 '$return_path' => '',
1735 '$jsreload' => $return_url,
1736 '$type' => 'wall-comment',
1737 '$id' => $item['item_id'],
1738 '$parent' => $item['parent'],
1739 '$profile_uid' => $owner_uid,
1740 '$mylink' => $contact['url'],
1741 '$mytitle' => t('This is you'),
1742 '$myphoto' => $contact['thumb'],
1743 '$comment' => t('Comment'),
1744 '$submit' => t('Submit'),
1745 '$preview' => t('Preview'),
1746 '$sourceapp' => t($a->sourcename),
1748 '$rand_num' => random_digits(12)
1754 $paginate = paginate($a);
1758 $response_verbs = array('like');
1759 if (feature_enabled($owner_uid, 'dislike')) {
1760 $response_verbs[] = 'dislike';
1762 $responses = get_responses($conv_responses,$response_verbs, '', $link_item);
1764 $photo_tpl = get_markup_template('photo_view.tpl');
1766 if ($a->theme['template_engine'] === 'internal') {
1767 $album_e = array($album_link,template_escape($ph[0]['album']));
1768 $tags_e = template_escape($tags);
1769 $like_e = template_escape($like);
1770 $dislike_e = template_escape($dislike);
1772 $album_e = array($album_link, $ph[0]['album']);
1775 $dislike_e = $dislike;
1778 $o .= replace_macros($photo_tpl, array(
1779 '$id' => $ph[0]['id'],
1780 '$album' => $album_e,
1784 '$prevlink' => $prevlink,
1785 '$nextlink' => $nextlink,
1786 '$desc' => $ph[0]['desc'],
1790 '$map_text' => t('Map'),
1791 '$likebuttons' => $likebuttons,
1793 '$dislike' => $dikslike_e,
1794 'responses' => $responses,
1795 '$comments' => $comments,
1796 '$paginate' => $paginate,
1799 $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="photo" />' . "\n";
1800 $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
1801 $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . $photo["href"] . '" />' . "\n";
1802 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
1803 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
1808 // Default - show recent photos with upload link (if applicable)
1811 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1812 $sql_extra GROUP BY `resource-id`",
1813 intval($a->data['user']['uid']),
1814 dbesc('Contact Photos'),
1815 dbesc( t('Contact Photos'))
1817 if (dbm::is_result($r)) {
1818 $a->set_pager_total(count($r));
1819 $a->set_pager_itemspage(20);
1822 $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
1823 ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
1824 ANY_VALUE(`created`) AS `created` FROM `photo`
1825 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1826 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1827 intval($a->data['user']['uid']),
1828 dbesc('Contact Photos'),
1829 dbesc( t('Contact Photos')),
1830 intval($a->pager['start']),
1831 intval($a->pager['itemspage'])
1835 if (dbm::is_result($r)) {
1836 $twist = 'rotright';
1837 foreach ($r as $rr) {
1838 //hide profile photos to others
1839 if ((! $is_owner) && (! remote_user()) && ($rr['album'] == t('Profile Photos')))
1842 if ($twist == 'rotright')
1845 $twist = 'rotright';
1847 $ext = $phototypes[$rr['type']];
1849 if ($a->theme['template_engine'] === 'internal') {
1850 $alt_e = template_escape($rr['filename']);
1851 $name_e = template_escape($rr['album']);
1853 $alt_e = $rr['filename'];
1854 $name_e = $rr['album'];
1859 'twist' => ' ' . $twist . rand(2,4),
1860 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1861 'title' => t('View Photo'),
1862 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1865 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1867 'alt' => t('View Album'),
1874 $tpl = get_markup_template('photos_recent.tpl');
1875 $o .= replace_macros($tpl, array(
1876 '$title' => t('Recent Photos'),
1877 '$can_post' => $can_post,
1878 '$upload' => array(t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'),
1879 '$photos' => $photos,
1880 '$paginate' => paginate($a),