2 require_once('include/Photo.php');
3 require_once('include/photos.php');
4 require_once('include/items.php');
5 require_once('include/acl_selectors.php');
6 require_once('include/bbcode.php');
7 require_once('include/security.php');
8 require_once('include/redir.php');
9 require_once('include/tags.php');
10 require_once('include/threads.php');
11 require_once('include/Probe.php');
13 function photos_init(App &$a) {
16 auto_redir($a, $a->argv[1]);
18 if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
22 nav_set_selected('home');
26 $user = qu("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
33 $a->data['user'] = $user[0];
34 $a->profile_uid = $user[0]['uid'];
35 $is_owner = (local_user() && (local_user() == $a->profile_uid));
37 $profile = get_profiledata_by_nick($nick, $a->profile_uid);
39 $account_type = account_type($profile);
41 $tpl = get_markup_template("vcard-widget.tpl");
43 $vcard_widget .= replace_macros($tpl, array(
44 '$name' => $profile['name'],
45 '$photo' => $profile['photo'],
46 '$addr' => (($profile['addr'] != "") ? $profile['addr'] : ""),
47 '$account_type' => $account_type,
48 '$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""),
51 $albums = photo_albums($a->data['user']['uid']);
53 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
55 // add various encodings to the array so we can just loop through and pick them out in a template
56 $ret = array('success' => false);
59 $a->data['albums'] = $albums;
61 $ret['success'] = true;
63 $ret['albums'] = array();
64 foreach ($albums as $k => $album) {
65 //hide profile photos to others
66 if ((! $is_owner) && (! remote_user()) && ($album['album'] == t('Profile Photos')))
69 'text' => $album['album'],
70 'total' => $album['total'],
71 'url' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
72 'urlencode' => urlencode($album['album']),
73 'bin2hex' => bin2hex($album['album'])
75 $ret['albums'][] = $entry;
81 if (local_user() && $a->data['user']['uid'] == local_user())
84 if ($albums['success']) {
85 $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'),array(
86 '$nick' => $a->data['user']['nickname'],
87 '$title' => t('Photo Albums'),
88 '$recent' => t('Recent Photos'),
89 '$albums' => $albums['albums'],
90 '$baseurl' => z_root(),
91 '$upload' => array( t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'),
92 '$can_post' => $can_post
97 if (! x($a->page,'aside'))
98 $a->page['aside'] = '';
99 $a->page['aside'] .= $vcard_widget;
100 $a->page['aside'] .= $photo_albums_widget;
103 $tpl = get_markup_template("photos_head.tpl");
104 $a->page['htmlhead'] .= replace_macros($tpl,array(
105 '$ispublic' => t('everybody')
115 function photos_post(App &$a) {
117 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
120 logger('mod_photos: REQUEST ' . print_r($_REQUEST,true), LOGGER_DATA);
121 logger('mod_photos: FILES ' . print_r($_FILES,true), LOGGER_DATA);
123 $phototypes = Photo::supportedTypes();
128 $page_owner_uid = $a->data['user']['uid'];
129 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
131 if ((local_user()) && (local_user() == $page_owner_uid))
134 if ($community_page && remote_user()) {
136 if (is_array($_SESSION['remote'])) {
137 foreach ($_SESSION['remote'] as $v) {
138 if ($v['uid'] == $page_owner_uid) {
139 $contact_id = $v['cid'];
146 $r = qu("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
148 intval($page_owner_uid)
150 if (dbm::is_result($r)) {
152 $visitor = $contact_id;
159 notice( t('Permission denied.') . EOL );
163 $r = qu("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
164 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
165 intval($page_owner_uid)
168 if (! dbm::is_result($r)) {
169 notice( t('Contact information unavailable') . EOL);
170 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
174 $owner_record = $r[0];
177 if (($a->argc > 3) && ($a->argv[2] === 'album')) {
178 $album = hex2bin($a->argv[3]);
180 if ($album === t('Profile Photos') || $album === 'Contact Photos' || $album === t('Contact Photos')) {
181 goaway($_SESSION['photo_return']);
182 return; // NOTREACHED
185 $r = qu("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
187 intval($page_owner_uid)
189 if (! dbm::is_result($r)) {
190 notice( t('Album not found.') . EOL);
191 goaway($_SESSION['photo_return']);
192 return; // NOTREACHED
195 // Check if the user has responded to a delete confirmation query
196 if ($_REQUEST['canceled']) {
197 goaway($_SESSION['photo_return']);
204 $newalbum = notags(trim($_POST['albumname']));
205 if ($newalbum != $album) {
206 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
209 intval($page_owner_uid)
211 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
213 return; // NOTREACHED
217 * DELETE photo album and all its photos
220 if ($_POST['dropalbum'] == t('Delete Album')) {
222 // Check if we should do HTML-based delete confirmation
223 if ($_REQUEST['confirm']) {
224 $drop_url = $a->query_string;
225 $extra_inputs = array(
226 array('name' => 'albumname', 'value' => $_POST['albumname']),
228 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
230 '$message' => t('Do you really want to delete this photo album and all its photos?'),
231 '$extra_inputs' => $extra_inputs,
232 '$confirm' => t('Delete Album'),
233 '$confirm_url' => $drop_url,
234 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
235 '$cancel' => t('Cancel'),
237 $a->error = 1; // Set $a->error so the other module functions don't execute
243 // get the list of photos we are about to delete
246 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
248 intval($page_owner_uid),
252 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
253 intval(local_user()),
257 if (dbm::is_result($r)) {
258 foreach ($r as $rr) {
259 $res[] = "'" . dbesc($rr['rid']) . "'" ;
262 goaway($_SESSION['photo_return']);
263 return; // NOTREACHED
266 $str_res = implode(',', $res);
268 // remove the associated photos
270 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
271 intval($page_owner_uid)
274 // find and delete the corresponding item with all the comments and likes/dislikes
276 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
277 intval($page_owner_uid)
279 if (dbm::is_result($r)) {
280 foreach ($r as $rr) {
281 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
282 dbesc(datetime_convert()),
283 dbesc($rr['parent-uri']),
284 intval($page_owner_uid)
286 create_tags_from_itemuri($rr['parent-uri'], $page_owner_uid);
287 delete_thread_uri($rr['parent-uri'], $page_owner_uid);
289 $drop_id = intval($rr['id']);
291 // send the notification upstream/downstream as the case may be
294 proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
298 goaway('photos/' . $a->data['user']['nickname']);
299 return; // NOTREACHED
303 // Check if the user has responded to a delete confirmation query for a single photo
304 if (($a->argc > 2) && $_REQUEST['canceled']) {
305 goaway($_SESSION['photo_return']);
308 if (($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
310 // same as above but remove single photo
312 // Check if we should do HTML-based delete confirmation
313 if ($_REQUEST['confirm']) {
314 $drop_url = $a->query_string;
315 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
317 '$message' => t('Do you really want to delete this photo?'),
318 '$extra_inputs' => array(),
319 '$confirm' => t('Delete Photo'),
320 '$confirm_url' => $drop_url,
321 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
322 '$cancel' => t('Cancel'),
324 $a->error = 1; // Set $a->error so the other module functions don't execute
329 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
331 intval($page_owner_uid),
335 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
336 intval(local_user()),
340 if (dbm::is_result($r)) {
341 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
342 intval($page_owner_uid),
343 dbesc($r[0]['resource-id'])
345 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
346 dbesc($r[0]['resource-id']),
347 intval($page_owner_uid)
349 if (dbm::is_result($i)) {
350 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
351 dbesc(datetime_convert()),
352 dbesc(datetime_convert()),
354 intval($page_owner_uid)
356 create_tags_from_itemuri($i[0]['uri'], $page_owner_uid);
357 delete_thread_uri($i[0]['uri'], $page_owner_uid);
359 $url = App::get_baseurl();
360 $drop_id = intval($i[0]['id']);
362 if ($i[0]['visible'])
363 proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
367 goaway('photos/' . $a->data['user']['nickname']);
368 return; // NOTREACHED
371 if (($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
373 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
374 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
375 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
376 $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
377 $str_group_allow = perms2str($_POST['group_allow']);
378 $str_contact_allow = perms2str($_POST['contact_allow']);
379 $str_group_deny = perms2str($_POST['group_deny']);
380 $str_contact_deny = perms2str($_POST['contact_deny']);
382 $resource_id = $a->argv[2];
384 if (! strlen($albname))
385 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
388 if ((x($_POST,'rotate') !== false) &&
389 ( (intval($_POST['rotate']) == 1) || (intval($_POST['rotate']) == 2) )) {
392 $r = q("select * from photo where `resource-id` = '%s' and uid = %d and scale = 0 limit 1",
394 intval($page_owner_uid)
396 if (dbm::is_result($r)) {
397 $ph = new Photo($r[0]['data'], $r[0]['type']);
398 if ($ph->is_valid()) {
399 $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
400 $ph->rotate($rotate_deg);
402 $width = $ph->getWidth();
403 $height = $ph->getHeight();
405 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 0",
406 dbesc($ph->imageString()),
410 intval($page_owner_uid)
413 if ($width > 640 || $height > 640) {
414 $ph->scaleImage(640);
415 $width = $ph->getWidth();
416 $height = $ph->getHeight();
418 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 1",
419 dbesc($ph->imageString()),
423 intval($page_owner_uid)
427 if ($width > 320 || $height > 320) {
428 $ph->scaleImage(320);
429 $width = $ph->getWidth();
430 $height = $ph->getHeight();
432 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 2",
433 dbesc($ph->imageString()),
437 intval($page_owner_uid)
444 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
446 intval($page_owner_uid)
449 $ext = $phototypes[$p[0]['type']];
450 $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",
453 dbesc($str_contact_allow),
454 dbesc($str_group_allow),
455 dbesc($str_contact_deny),
456 dbesc($str_group_deny),
458 intval($page_owner_uid)
462 /* Don't make the item visible if the only change was the album name */
465 if ($p[0]['desc'] !== $desc || strlen($rawtags))
470 // Create item container
473 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
476 $arr['guid'] = get_guid(32);
477 $arr['uid'] = $page_owner_uid;
479 $arr['parent-uri'] = $uri;
480 $arr['type'] = 'photo';
482 $arr['resource-id'] = $p[0]['resource-id'];
483 $arr['contact-id'] = $owner_record['id'];
484 $arr['owner-name'] = $owner_record['name'];
485 $arr['owner-link'] = $owner_record['url'];
486 $arr['owner-avatar'] = $owner_record['thumb'];
487 $arr['author-name'] = $owner_record['name'];
488 $arr['author-link'] = $owner_record['url'];
489 $arr['author-avatar'] = $owner_record['thumb'];
490 $arr['title'] = $title;
491 $arr['allow_cid'] = $p[0]['allow_cid'];
492 $arr['allow_gid'] = $p[0]['allow_gid'];
493 $arr['deny_cid'] = $p[0]['deny_cid'];
494 $arr['deny_gid'] = $p[0]['deny_gid'];
495 $arr['last-child'] = 1;
496 $arr['visible'] = $visibility;
499 $arr['body'] = '[url=' . App::get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
500 . '[img]' . App::get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
503 $item_id = item_store($arr);
508 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
510 intval($page_owner_uid)
513 if (dbm::is_result($r)) {
514 $old_tag = $r[0]['tag'];
515 $old_inform = $r[0]['inform'];
518 if (strlen($rawtags)) {
523 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
525 $x = substr($rawtags,0,1);
526 if ($x !== '@' && $x !== '#')
527 $rawtags = '#' . $rawtags;
530 $tags = get_tags($rawtags);
533 foreach ($tags as $tag) {
536 if (strpos($tag,'@') === 0) {
537 $name = substr($tag,1);
538 if ((strpos($name,'@')) || (strpos($name,'http://'))) {
540 $links = @Probe::lrdd($name);
542 foreach ($links as $link) {
543 if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
544 $profile = $link['@attributes']['href'];
545 if ($link['@attributes']['rel'] === 'salmon') {
546 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
553 $taginfo[] = array($newname,$profile,$salmon);
558 if (strrpos($newname,'+'))
559 $tagcid = intval(substr($newname,strrpos($newname,'+') + 1));
562 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
567 $newname = str_replace('_',' ',$name);
569 //select someone from this user's contacts by name
570 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
572 intval($page_owner_uid)
576 //select someone by attag or nick and the name passed in
577 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
580 intval($page_owner_uid)
584 /* elseif (strstr($name,'_') || strstr($name,' ')) {
585 $newname = str_replace('_',' ',$name);
586 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
588 intval($page_owner_uid)
591 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
594 intval($page_owner_uid)
597 if (dbm::is_result($r)) {
598 $newname = $r[0]['name'];
599 $profile = $r[0]['url'];
600 $notify = 'cid:' . $r[0]['id'];
607 if (substr($notify,0,4) === 'cid:')
608 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
610 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
611 if (strlen($str_tags))
613 $profile = str_replace(',','%2c',$profile);
614 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
616 } elseif (strpos($tag,'#') === 0) {
617 $tagname = substr($tag, 1);
618 $str_tags .= '#[url='.App::get_baseurl()."/search?tag=".$tagname.']'.$tagname.'[/url]';
624 if (strlen($newtag) && strlen($str_tags))
626 $newtag .= $str_tags;
628 $newinform = $old_inform;
629 if (strlen($newinform) && strlen($inform))
631 $newinform .= $inform;
633 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
636 dbesc(datetime_convert()),
637 dbesc(datetime_convert()),
639 intval($page_owner_uid)
641 create_tags_from_item($item_id);
642 update_thread($item_id);
645 foreach ($p as $scales) {
646 if (intval($scales['scale']) == 2) {
650 if (intval($scales['scale']) == 4) {
656 if (count($taginfo)) {
657 foreach ($taginfo as $tagged) {
659 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
662 $arr['guid'] = get_guid(32);
663 $arr['uid'] = $page_owner_uid;
665 $arr['parent-uri'] = $uri;
666 $arr['type'] = 'activity';
668 $arr['contact-id'] = $owner_record['id'];
669 $arr['owner-name'] = $owner_record['name'];
670 $arr['owner-link'] = $owner_record['url'];
671 $arr['owner-avatar'] = $owner_record['thumb'];
672 $arr['author-name'] = $owner_record['name'];
673 $arr['author-link'] = $owner_record['url'];
674 $arr['author-avatar'] = $owner_record['thumb'];
676 $arr['allow_cid'] = $p[0]['allow_cid'];
677 $arr['allow_gid'] = $p[0]['allow_gid'];
678 $arr['deny_cid'] = $p[0]['deny_cid'];
679 $arr['deny_gid'] = $p[0]['deny_gid'];
680 $arr['last-child'] = 1;
682 $arr['verb'] = ACTIVITY_TAG;
683 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
684 $arr['target-type'] = ACTIVITY_OBJ_IMAGE;
685 $arr['tag'] = $tagged[4];
686 $arr['inform'] = $tagged[2];
688 $arr['body'] = sprintf( t('%1$s was tagged in %2$s by %3$s'), '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]', '[url=' . App::get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . t('a photo') . '[/url]', '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]') ;
689 $arr['body'] .= "\n\n" . '[url=' . App::get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . '[img]' . App::get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '[/img][/url]' . "\n" ;
691 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
692 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
694 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
695 $arr['object'] .= '</link></object>' . "\n";
697 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $p[0]['desc'] . '</title><id>'
698 . App::get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
699 $arr['target'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . App::get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '" />' . "\n" . '<link rel="preview" type="'.$p[0]['type'].'" href="' . App::get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>';
701 $item_id = item_store($arr);
703 proc_run(PRIORITY_HIGH, "include/notifier.php", "tag", $item_id);
710 goaway($_SESSION['photo_return']);
711 return; // NOTREACHED
716 * default post action - upload a photo
719 call_hooks('photo_post_init', $_POST);
722 * Determine the album to use
725 $album = notags(trim($_REQUEST['album']));
726 $newalbum = notags(trim($_REQUEST['newalbum']));
728 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
730 if (! strlen($album)) {
731 if (strlen($newalbum))
734 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
739 * We create a wall item for every photo, but we don't want to
740 * overwhelm the data stream with a hundred newly uploaded photos.
741 * So we will make the first photo uploaded to this album in the last several hours
742 * visible by default, the rest will become visible over time when and if
743 * 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')))
756 if (intval($_REQUEST['not_visible']) || $_REQUEST['not_visible'] === 'true')
759 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
760 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
761 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
762 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
764 $ret = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
766 call_hooks('photo_post_file',$ret);
768 if (x($ret,'src') && x($ret,'filesize')) {
770 $filename = $ret['filename'];
771 $filesize = $ret['filesize'];
772 $type = $ret['type'];
774 $src = $_FILES['userfile']['tmp_name'];
775 $filename = basename($_FILES['userfile']['name']);
776 $filesize = intval($_FILES['userfile']['size']);
777 $type = $_FILES['userfile']['type'];
779 if ($type=="") $type=guess_image_type($filename);
781 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
783 $maximagesize = get_config('system','maximagesize');
785 if (($maximagesize) && ($filesize > $maximagesize)) {
786 notice( sprintf(t('Image exceeds size limit of %s'), formatBytes($maximagesize)) . EOL);
789 call_hooks('photo_post_end',$foo);
794 notice( t('Image file is empty.') . EOL);
797 call_hooks('photo_post_end',$foo);
801 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
803 $imagedata = @file_get_contents($src);
807 $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
808 intval($a->data['user']['uid'])
811 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
813 if (($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
814 notice( upgrade_message() . EOL );
817 call_hooks('photo_post_end',$foo);
822 $ph = new Photo($imagedata, $type);
824 if (! $ph->is_valid()) {
825 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
826 notice( t('Unable to process image.') . EOL );
829 call_hooks('photo_post_end',$foo);
833 $exif = $ph->orient($src);
836 $max_length = get_config('system','max_image_length');
838 $max_length = MAX_IMAGE_LENGTH;
840 $ph->scaleImage($max_length);
842 $width = $ph->getWidth();
843 $height = $ph->getHeight();
847 $photo_hash = photo_new_resource();
849 $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);
852 logger('mod/photos.php: photos_post(): image store failed' , LOGGER_DEBUG);
853 notice( t('Image upload failed.') . EOL );
857 if ($width > 640 || $height > 640) {
858 $ph->scaleImage(640);
859 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
863 if ($width > 320 || $height > 320) {
864 $ph->scaleImage(320);
865 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
869 $basename = basename($filename);
870 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
872 // Create item container
876 if ($exif && $exif['GPS']) {
877 if (feature_enabled($channel_id,'photo_location')) {
878 $lat = getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
879 $lon = getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
886 $arr['coord'] = $lat . ' ' . $lon;
888 $arr['guid'] = get_guid(32);
889 $arr['uid'] = $page_owner_uid;
891 $arr['parent-uri'] = $uri;
892 $arr['type'] = 'photo';
894 $arr['resource-id'] = $photo_hash;
895 $arr['contact-id'] = $owner_record['id'];
896 $arr['owner-name'] = $owner_record['name'];
897 $arr['owner-link'] = $owner_record['url'];
898 $arr['owner-avatar'] = $owner_record['thumb'];
899 $arr['author-name'] = $owner_record['name'];
900 $arr['author-link'] = $owner_record['url'];
901 $arr['author-avatar'] = $owner_record['thumb'];
903 $arr['allow_cid'] = $str_contact_allow;
904 $arr['allow_gid'] = $str_group_allow;
905 $arr['deny_cid'] = $str_contact_deny;
906 $arr['deny_gid'] = $str_group_deny;
907 $arr['last-child'] = 1;
908 $arr['visible'] = $visible;
911 $arr['body'] = '[url=' . App::get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
912 . '[img]' . App::get_baseurl() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]'
915 $item_id = item_store($arr);
918 proc_run(PRIORITY_HIGH, "include/notifier.php", 'wall-new', $item_id);
920 call_hooks('photo_post_end',intval($item_id));
922 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
923 // if they do not wish to be redirected
925 goaway($_SESSION['photo_return']);
931 function photos_content(App &$a) {
935 // photos/name/upload
936 // photos/name/upload/xxxxx (xxxxx is album name)
937 // photos/name/album/xxxxx
938 // photos/name/album/xxxxx/edit
939 // photos/name/image/xxxxx
940 // photos/name/image/xxxxx/edit
943 if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
944 notice( t('Public access denied.') . EOL);
949 require_once('include/bbcode.php');
950 require_once('include/security.php');
951 require_once('include/conversation.php');
953 if (! x($a->data,'user')) {
954 notice( t('No photos selected') . EOL );
958 $phototypes = Photo::supportedTypes();
960 $_SESSION['photo_return'] = $a->cmd;
967 $datatype = $a->argv[2];
968 $datum = $a->argv[3];
969 } elseif (($a->argc > 2) && ($a->argv[2] === 'upload'))
970 $datatype = 'upload';
972 $datatype = 'summary';
980 // Setup permissions structures
986 $remote_contact = false;
989 $owner_uid = $a->data['user']['uid'];
991 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
993 if ((local_user()) && (local_user() == $owner_uid))
996 if ($community_page && remote_user()) {
997 if (is_array($_SESSION['remote'])) {
998 foreach ($_SESSION['remote'] as $v) {
999 if ($v['uid'] == $owner_uid) {
1000 $contact_id = $v['cid'];
1007 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1008 intval($contact_id),
1011 if (dbm::is_result($r)) {
1014 $remote_contact = true;
1015 $visitor = $contact_id;
1021 // perhaps they're visiting - but not a community page, so they wouldn't have write access
1023 if (remote_user() && (! $visitor)) {
1025 if (is_array($_SESSION['remote'])) {
1026 foreach ($_SESSION['remote'] as $v) {
1027 if ($v['uid'] == $owner_uid) {
1028 $contact_id = $v['cid'];
1034 $groups = init_groups_visitor($contact_id);
1035 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
1036 intval($contact_id),
1039 if (dbm::is_result($r)) {
1041 $remote_contact = true;
1046 if (! $remote_contact) {
1048 $contact_id = $_SESSION['cid'];
1049 $contact = $a->contact;
1053 if ($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
1054 notice( t('Access to this item is restricted.') . EOL);
1058 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
1063 $is_owner = (local_user() && (local_user() == $owner_uid));
1064 $o .= profile_tabs($a,$is_owner, $a->data['user']['nickname']);
1067 * Display upload form
1070 if ($datatype === 'upload') {
1071 if (! ($can_post)) {
1072 notice( t('Permission denied.'));
1077 $selname = (($datum) ? hex2bin($datum) : '');
1083 $albumselect .= '<option value="" ' . ((! $selname) ? ' selected="selected" ' : '') . '> </option>';
1084 if (count($a->data['albums'])) {
1085 foreach ($a->data['albums'] as $album) {
1086 if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
1088 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1089 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1095 $ret = array('post_url' => 'photos/' . $a->data['user']['nickname'],
1096 'addon_text' => $uploader,
1097 'default_upload' => true);
1100 call_hooks('photo_upload_form',$ret);
1102 $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), array());
1103 $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), array(
1104 '$submit' => t('Submit'),
1107 $usage_message = '';
1108 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
1109 if ($limit !== false) {
1111 $r = q("select sum(datasize) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
1112 intval($a->data['user']['uid'])
1114 $usage_message = sprintf( t("You have used %1$.2f Mbytes of %2$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000 );
1118 // Private/public post links for the non-JS ACL form
1120 if ($_REQUEST['public'])
1123 $query_str = $a->query_string;
1124 if (strpos($query_str, 'public=1') !== false)
1125 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1127 // I think $a->query_string may never have ? in it, but I could be wrong
1128 // It looks like it's from the index.php?q=[etc] rewrite that the web
1129 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1130 if (strpos($query_str, '?') === false)
1131 $public_post_link = '?public=1';
1133 $public_post_link = '&public=1';
1137 $tpl = get_markup_template('photos_upload.tpl');
1139 if ($a->theme['template_engine'] === 'internal') {
1140 $albumselect_e = template_escape($albumselect);
1141 $aclselect_e = (($visitor) ? '' : template_escape(populate_acl($a->user)));
1143 $albumselect_e = $albumselect;
1144 $aclselect_e = (($visitor) ? '' : populate_acl($a->user));
1147 $o .= replace_macros($tpl,array(
1148 '$pagename' => t('Upload Photos'),
1149 '$sessid' => session_id(),
1150 '$usage' => $usage_message,
1151 '$nickname' => $a->data['user']['nickname'],
1152 '$newalbum' => t('New album name: '),
1153 '$existalbumtext' => t('or existing album name: '),
1154 '$nosharetext' => t('Do not show a status post for this upload'),
1155 '$albumselect' => $albumselect_e,
1156 '$permissions' => t('Permissions'),
1157 '$aclselect' => $aclselect_e,
1158 '$alt_uploader' => $ret['addon_text'],
1159 '$default_upload_box' => (($ret['default_upload']) ? $default_upload_box : ''),
1160 '$default_upload_submit' => (($ret['default_upload']) ? $default_upload_submit : ''),
1161 '$uploadurl' => $ret['post_url'],
1163 // ACL permissions box
1164 '$acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
1165 '$group_perms' => t('Show to Groups'),
1166 '$contact_perms' => t('Show to Contacts'),
1167 '$private' => t('Private Photo'),
1168 '$public' => t('Public Photo'),
1169 '$is_private' => $private_post,
1170 '$return_path' => $query_str,
1171 '$public_link' => $public_post_link,
1179 * Display a single photo album
1182 if ($datatype === 'album') {
1184 $album = hex2bin($datum);
1186 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1187 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1191 if (dbm::is_result($r)) {
1192 $a->set_pager_total(count($r));
1193 $a->set_pager_itemspage(20);
1196 if ($_GET['order'] === 'posted')
1201 $r = q("SELECT `resource-id`, `id`, `filename`, type, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1202 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1205 intval($a->pager['start']),
1206 intval($a->pager['itemspage'])
1210 if ($cmd === 'edit') {
1211 if (($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1213 $edit_tpl = get_markup_template('album_edit.tpl');
1215 if ($a->theme['template_engine'] === 'internal') {
1216 $album_e = template_escape($album);
1221 $o .= replace_macros($edit_tpl,array(
1222 '$nametext' => t('New album name: '),
1223 '$nickname' => $a->data['user']['nickname'],
1224 '$album' => $album_e,
1225 '$hexalbum' => bin2hex($album),
1226 '$submit' => t('Submit'),
1227 '$dropsubmit' => t('Delete Album')
1232 if (($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1234 $edit = array(t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit');
1239 if ($_GET['order'] === 'posted')
1240 $order = array(t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album));
1242 $order = array(t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted');
1246 if (dbm::is_result($r))
1247 $twist = 'rotright';
1248 foreach ($r as $rr) {
1249 if ($twist == 'rotright')
1252 $twist = 'rotright';
1254 $ext = $phototypes[$rr['type']];
1256 if ($a->theme['template_engine'] === 'internal') {
1257 $imgalt_e = template_escape($rr['filename']);
1258 $desc_e = template_escape($rr['desc']);
1260 $imgalt_e = $rr['filename'];
1261 $desc_e = $rr['desc'];
1266 'twist' => ' ' . $twist . rand(2,4),
1267 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1268 . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''),
1269 'title' => t('View Photo'),
1270 'src' => 'photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1274 'hash'=> $rr['resource_id'],
1278 $tpl = get_markup_template('photo_album.tpl');
1279 $o .= replace_macros($tpl, array(
1280 '$photos' => $photos,
1282 '$can_post' => $can_post,
1283 '$upload' => array(t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)),
1286 '$paginate' => paginate($a),
1297 if ($datatype === 'image') {
1300 // fetch image, item containing image, then comments
1302 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1303 $sql_extra ORDER BY `scale` ASC ",
1309 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1315 notice( t('Permission denied. Access to this item may be restricted.'));
1317 notice( t('Photo not available') . EOL );
1324 if ($_GET['order'] === 'posted')
1330 $prvnxt = qu("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1331 $sql_extra ORDER BY `created` $order ",
1332 dbesc($ph[0]['album']),
1336 if (count($prvnxt)) {
1337 for($z = 0; $z < count($prvnxt); $z++) {
1338 if ($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
1342 $prv = count($prvnxt) - 1;
1343 if ($nxt >= count($prvnxt))
1348 $edit_suffix = ((($cmd === 'edit') && ($can_post)) ? '/edit' : '');
1349 $prevlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1350 $nextlink = 'photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1354 if (count($ph) == 1)
1355 $hires = $lores = $ph[0];
1356 if (count($ph) > 1) {
1357 if ($ph[1]['scale'] == 2) {
1358 // original is 640 or less, we can display it directly
1359 $hires = $lores = $ph[0];
1366 $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1370 if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
1372 'edit' => array('photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? t('View photo') : t('Edit photo'))),
1373 'profile'=>array('profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
1377 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1378 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1379 ? t('Private Message')
1385 if ( $cmd === 'edit') {
1386 $tpl = get_markup_template('photo_edit_head.tpl');
1387 $a->page['htmlhead'] .= replace_macros($tpl,array(
1388 '$prevlink' => $prevlink,
1389 '$nextlink' => $nextlink
1394 $prevlink = array($prevlink, '<div class="icon prev"></div>') ;
1397 'href' => 'photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1398 'title'=> t('View Full Size'),
1399 'src' => 'photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis'),
1400 'height' => $hires['height'],
1401 'width' => $hires['width'],
1402 'album' => $hires['album'],
1403 'filename' => $hires['filename'],
1407 $nextlink = array($nextlink, '<div class="icon next"></div>');
1410 // Do we have an item for this photo?
1412 // FIXME! - replace following code to display the conversation with our normal
1413 // conversation functions so that it works correctly and tracks changes
1414 // in the evolving conversation code.
1415 // The difference is that we won't be displaying the conversation head item
1416 // as a "post" but displaying instead the photo it is linked to
1418 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1424 if (count($linked_items)) {
1425 $link_item = $linked_items[0];
1426 $r = qu("SELECT COUNT(*) AS `total`
1427 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1428 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1429 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1430 AND `item`.`uid` = %d
1432 dbesc($link_item['uri']),
1433 dbesc($link_item['uri']),
1434 intval($link_item['uid'])
1438 if (dbm::is_result($r))
1439 $a->set_pager_total($r[0]['total']);
1442 $r = qu("SELECT `item`.*, `item`.`id` AS `item_id`,
1443 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1444 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1445 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1446 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1447 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1448 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1449 AND `item`.`uid` = %d
1451 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1452 dbesc($link_item['uri']),
1453 dbesc($link_item['uri']),
1454 intval($link_item['uid']),
1455 intval($a->pager['start']),
1456 intval($a->pager['itemspage'])
1460 if ((local_user()) && (local_user() == $link_item['uid'])) {
1461 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1462 intval($link_item['parent']),
1463 intval(local_user())
1465 update_thread($link_item['parent']);
1468 if ($link_item['coord']) {
1469 $map = generate_map($link_item['coord']);
1475 if (count($linked_items) && strlen($link_item['tag'])) {
1476 $arr = explode(',',$link_item['tag']);
1477 // parse tags and add links
1479 foreach ($arr as $t) {
1480 if (strlen($tag_str))
1482 $tag_str .= bbcode($t);
1484 $tags = array(t('Tags: '), $tag_str);
1485 if ($cmd === 'edit') {
1486 $tags[] = 'tagrm/' . $link_item['id'];
1487 $tags[] = t('[Remove any tag]');
1493 if (($cmd === 'edit') && ($can_post)) {
1494 $edit_tpl = get_markup_template('photo_edit.tpl');
1496 // Private/public post links for the non-JS ACL form
1498 if ($_REQUEST['public'])
1501 $query_str = $a->query_string;
1502 if (strpos($query_str, 'public=1') !== false)
1503 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1505 // I think $a->query_string may never have ? in it, but I could be wrong
1506 // It looks like it's from the index.php?q=[etc] rewrite that the web
1507 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1508 if (strpos($query_str, '?') === false)
1509 $public_post_link = '?public=1';
1511 $public_post_link = '&public=1';
1514 if ($a->theme['template_engine'] === 'internal') {
1515 $album_e = template_escape($ph[0]['album']);
1516 $caption_e = template_escape($ph[0]['desc']);
1517 $aclselect_e = template_escape(populate_acl($ph[0]));
1519 $album_e = $ph[0]['album'];
1520 $caption_e = $ph[0]['desc'];
1521 $aclselect_e = populate_acl($ph[0]);
1524 $edit = replace_macros($edit_tpl, array(
1525 '$id' => $ph[0]['id'],
1526 '$album' => array('albname', t('New album name'), $album_e,''),
1527 '$caption' => array('desc', t('Caption'), $caption_e, ''),
1528 '$tags' => array('newtag', t('Add a Tag'), "", t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')),
1529 '$rotate_none' => array('rotate',t('Do not rotate'),0,'', true),
1530 '$rotate_cw' => array('rotate',t('Rotate CW (right)'),1,''),
1531 '$rotate_ccw' => array('rotate',t('Rotate CCW (left)'),2,''),
1533 '$nickname' => $a->data['user']['nickname'],
1534 '$resource_id' => $ph[0]['resource-id'],
1535 '$permissions' => t('Permissions'),
1536 '$aclselect' => $aclselect_e,
1538 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1539 '$submit' => t('Submit'),
1540 '$delete' => t('Delete Photo'),
1542 // ACL permissions box
1543 '$acl_data' => construct_acl_data($a, $ph[0]), // For non-Javascript ACL selector
1544 '$group_perms' => t('Show to Groups'),
1545 '$contact_perms' => t('Show to Contacts'),
1546 '$private' => t('Private photo'),
1547 '$public' => t('Public photo'),
1548 '$is_private' => $private_post,
1549 '$return_path' => $query_str,
1550 '$public_link' => $public_post_link,
1554 if (count($linked_items)) {
1556 $cmnt_tpl = get_markup_template('comment_item.tpl');
1557 $tpl = get_markup_template('photo_item.tpl');
1558 $return_url = $a->cmd;
1560 $like_tpl = get_markup_template('like_noshare.tpl');
1564 if ($can_post || can_write_wall($a,$owner_uid)) {
1565 $likebuttons = replace_macros($like_tpl,array(
1566 '$id' => $link_item['id'],
1567 '$likethis' => t("I like this \x28toggle\x29"),
1568 '$nolike' => (feature_enabled(local_user(), 'dislike') ? t("I don't like this \x28toggle\x29") : ''),
1569 '$share' => t('Share'),
1570 '$wait' => t('Please wait'),
1571 '$return_path' => $a->query_string,
1576 if (! dbm::is_result($r)) {
1577 if ($can_post || can_write_wall($a,$owner_uid)) {
1578 if ($link_item['last-child']) {
1579 $comments .= replace_macros($cmnt_tpl,array(
1580 '$return_path' => '',
1581 '$jsreload' => $return_url,
1582 '$type' => 'wall-comment',
1583 '$id' => $link_item['id'],
1584 '$parent' => $link_item['id'],
1585 '$profile_uid' => $owner_uid,
1586 '$mylink' => $contact['url'],
1587 '$mytitle' => t('This is you'),
1588 '$myphoto' => $contact['thumb'],
1589 '$comment' => t('Comment'),
1590 '$submit' => t('Submit'),
1591 '$preview' => t('Preview'),
1592 '$sourceapp' => t($a->sourcename),
1594 '$rand_num' => random_digits(12)
1606 $conv_responses = array(
1607 'like' => array('title' => t('Likes','title')),'dislike' => array('title' => t('Dislikes','title')),
1608 'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title'))
1614 if (dbm::is_result($r)) {
1616 foreach ($r as $item) {
1617 builtin_activity_puller($item, $conv_responses);
1620 $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']) : '');
1621 $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']) : '');
1625 if ($can_post || can_write_wall($a,$owner_uid)) {
1626 if ($link_item['last-child']) {
1627 $comments .= replace_macros($cmnt_tpl,array(
1628 '$return_path' => '',
1629 '$jsreload' => $return_url,
1630 '$type' => 'wall-comment',
1631 '$id' => $link_item['id'],
1632 '$parent' => $link_item['id'],
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)
1648 foreach ($r as $item) {
1653 if (((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1656 $redirect_url = 'redir/' . $item['cid'] ;
1659 if (local_user() && ($item['contact-uid'] == local_user())
1660 && ($item['network'] == NETWORK_DFRN) && (! $item['self'] )) {
1661 $profile_url = $redirect_url;
1662 $sparkle = ' sparkle';
1664 $profile_url = $item['url'];
1668 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1670 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1671 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1673 $profile_link = $profile_url;
1677 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1679 'dropping' => $dropping,
1680 'pagedrop' => false,
1681 'select' => t('Select'),
1682 'delete' => t('Delete'),
1686 if ($a->theme['template_engine'] === 'internal') {
1687 $name_e = template_escape($profile_name);
1688 $title_e = template_escape($item['title']);
1689 $body_e = template_escape(bbcode($item['body']));
1691 $name_e = $profile_name;
1692 $title_e = $item['title'];
1693 $body_e = bbcode($item['body']);
1696 $comments .= replace_macros($template,array(
1697 '$id' => $item['item_id'],
1698 '$profile_url' => $profile_link,
1700 '$thumb' => $profile_avatar,
1701 '$sparkle' => $sparkle,
1702 '$title' => $title_e,
1704 '$ago' => relative_date($item['created']),
1705 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1707 '$comment' => $comment
1710 if ($can_post || can_write_wall($a,$owner_uid)) {
1712 if ($item['last-child']) {
1713 $comments .= replace_macros($cmnt_tpl,array(
1714 '$return_path' => '',
1715 '$jsreload' => $return_url,
1716 '$type' => 'wall-comment',
1717 '$id' => $item['item_id'],
1718 '$parent' => $item['parent'],
1719 '$profile_uid' => $owner_uid,
1720 '$mylink' => $contact['url'],
1721 '$mytitle' => t('This is you'),
1722 '$myphoto' => $contact['thumb'],
1723 '$comment' => t('Comment'),
1724 '$submit' => t('Submit'),
1725 '$preview' => t('Preview'),
1726 '$sourceapp' => t($a->sourcename),
1728 '$rand_num' => random_digits(12)
1735 $paginate = paginate($a);
1739 $response_verbs = array('like');
1740 if (feature_enabled($owner_uid,'dislike'))
1741 $response_verbs[] = 'dislike';
1742 $responses = get_responses($conv_responses,$response_verbs,'',$link_item);
1744 $photo_tpl = get_markup_template('photo_view.tpl');
1746 if ($a->theme['template_engine'] === 'internal') {
1747 $album_e = array($album_link,template_escape($ph[0]['album']));
1748 $tags_e = template_escape($tags);
1749 $like_e = template_escape($like);
1750 $dislike_e = template_escape($dislike);
1752 $album_e = array($album_link,$ph[0]['album']);
1755 $dislike_e = $dislike;
1758 $o .= replace_macros($photo_tpl, array(
1759 '$id' => $ph[0]['id'],
1760 '$album' => $album_e,
1764 '$prevlink' => $prevlink,
1765 '$nextlink' => $nextlink,
1766 '$desc' => $ph[0]['desc'],
1770 '$map_text' => t('Map'),
1771 '$likebuttons' => $likebuttons,
1773 '$dislike' => $dikslike_e,
1774 'responses' => $responses,
1775 '$comments' => $comments,
1776 '$paginate' => $paginate,
1779 $a->page['htmlhead'] .= "\n".'<meta name="twitter:card" content="photo" />'."\n";
1780 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$photo["album"].'" />'."\n";
1781 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$photo["href"].'" />'."\n";
1782 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="'.$photo["width"].'" />'."\n";
1783 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="'.$photo["height"].'" />'."\n";
1788 // Default - show recent photos with upload link (if applicable)
1791 $r = qu("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1792 $sql_extra GROUP BY `resource-id`",
1793 intval($a->data['user']['uid']),
1794 dbesc('Contact Photos'),
1795 dbesc( t('Contact Photos'))
1797 if (dbm::is_result($r)) {
1798 $a->set_pager_total(count($r));
1799 $a->set_pager_itemspage(20);
1802 $r = qu("SELECT `resource-id`, `id`, `filename`, type, `album`, max(`scale`) AS `scale` FROM `photo`
1803 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1804 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1805 intval($a->data['user']['uid']),
1806 dbesc('Contact Photos'),
1807 dbesc( t('Contact Photos')),
1808 intval($a->pager['start']),
1809 intval($a->pager['itemspage'])
1813 if (dbm::is_result($r)) {
1814 $twist = 'rotright';
1815 foreach ($r as $rr) {
1816 //hide profile photos to others
1817 if ((! $is_owner) && (! remote_user()) && ($rr['album'] == t('Profile Photos')))
1820 if ($twist == 'rotright')
1823 $twist = 'rotright';
1825 $ext = $phototypes[$rr['type']];
1827 if ($a->theme['template_engine'] === 'internal') {
1828 $alt_e = template_escape($rr['filename']);
1829 $name_e = template_escape($rr['album']);
1831 $alt_e = $rr['filename'];
1832 $name_e = $rr['album'];
1837 'twist' => ' ' . $twist . rand(2,4),
1838 'link' => 'photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1839 'title' => t('View Photo'),
1840 'src' => 'photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1843 'link' => 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1845 'alt' => t('View Album'),
1852 $tpl = get_markup_template('photos_recent.tpl');
1853 $o .= replace_macros($tpl, array(
1854 '$title' => t('Recent Photos'),
1855 '$can_post' => $can_post,
1856 '$upload' => array(t('Upload New Photos'), 'photos/'.$a->data['user']['nickname'].'/upload'),
1857 '$photos' => $photos,
1858 '$paginate' => paginate($a),