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');
12 function photos_init(&$a) {
15 auto_redir($a, $a->argv[1]);
17 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
21 nav_set_selected('home');
27 $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
34 $a->data['user'] = $user[0];
35 $a->profile_uid = $user[0]['uid'];
36 $is_owner = (local_user() && (local_user() == $a->profile_uid));
38 $profile = get_profiledata_by_nick($nick, $a->profile_uid);
40 if((intval($profile['page-flags']) == PAGE_COMMUNITY) || (intval($profile['page-flags']) == PAGE_PRVGROUP))
41 $account_type = t('Forum');
45 $tpl = get_markup_template("vcard-widget.tpl");
47 $vcard_widget .= replace_macros($tpl, array(
48 '$name' => $profile['name'],
49 '$photo' => $profile['photo'],
50 '$addr' => (($profile['addr'] != "") ? $profile['addr'] : ""),
51 '$account_type' => $account_type,
52 '$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""),
56 $sql_extra = permissions_sql($a->data['user']['uid']);
58 $albums = q("SELECT count(distinct `resource-id`) AS `total`, `album` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
59 $sql_extra group by album order by created desc",
60 intval($a->data['user']['uid']),
61 dbesc('Contact Photos'),
62 dbesc( t('Contact Photos'))
65 $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
67 // add various encodings to the array so we can just loop through and pick them out in a template
68 $ret = array('success' => false);
71 $a->data['albums'] = $albums;
73 $ret['success'] = true;
75 $ret['albums'] = array();
76 foreach($albums as $k => $album) {
77 //hide profile photos to others
78 if((! $is_owner) && (! remote_user()) && ($album['album'] == t('Profile Photos')))
81 'text' => $album['album'],
82 'total' => $album['total'],
83 'url' => z_root() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album['album']),
84 'urlencode' => urlencode($album['album']),
85 'bin2hex' => bin2hex($album['album'])
87 $ret['albums'][] = $entry;
93 if(local_user() && $a->data['user']['uid'] == local_user())
96 if($albums['success']) {
97 $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'),array(
98 '$nick' => $a->data['user']['nickname'],
99 '$title' => t('Photo Albums'),
100 '$recent' => t('Recent Photos'),
101 '$albums' => $albums['albums'],
102 '$baseurl' => z_root(),
103 '$upload' => array( t('Upload New Photos'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload'),
104 '$can_post' => $can_post
109 if(! x($a->page,'aside'))
110 $a->page['aside'] = '';
111 $a->page['aside'] .= $vcard_widget;
112 $a->page['aside'] .= $photo_albums_widget;
115 $tpl = get_markup_template("photos_head.tpl");
116 $a->page['htmlhead'] .= replace_macros($tpl,array(
117 '$ispublic' => t('everybody')
127 function photos_post(&$a) {
129 logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
132 logger('mod_photos: REQUEST ' . print_r($_REQUEST,true), LOGGER_DATA);
133 logger('mod_photos: FILES ' . print_r($_FILES,true), LOGGER_DATA);
135 $phototypes = Photo::supportedTypes();
140 $page_owner_uid = $a->data['user']['uid'];
141 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
143 if((local_user()) && (local_user() == $page_owner_uid))
146 if($community_page && remote_user()) {
148 if(is_array($_SESSION['remote'])) {
149 foreach($_SESSION['remote'] as $v) {
150 if($v['uid'] == $page_owner_uid) {
158 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
160 intval($page_owner_uid)
171 notice( t('Permission denied.') . EOL );
175 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
176 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
177 intval($page_owner_uid)
181 notice( t('Contact information unavailable') . EOL);
182 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
186 $owner_record = $r[0];
189 if(($a->argc > 3) && ($a->argv[2] === 'album')) {
190 $album = hex2bin($a->argv[3]);
192 if($album === t('Profile Photos') || $album === 'Contact Photos' || $album === t('Contact Photos')) {
193 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
194 return; // NOTREACHED
197 $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
199 intval($page_owner_uid)
202 notice( t('Album not found.') . EOL);
203 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
204 return; // NOTREACHED
207 // Check if the user has responded to a delete confirmation query
208 if($_REQUEST['canceled']) {
209 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
216 $newalbum = notags(trim($_POST['albumname']));
217 if($newalbum != $album) {
218 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
221 intval($page_owner_uid)
223 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
224 goaway($a->get_baseurl() . '/' . $newurl);
225 return; // NOTREACHED
229 * DELETE photo album and all its photos
232 if($_POST['dropalbum'] == t('Delete Album')) {
234 // Check if we should do HTML-based delete confirmation
235 if($_REQUEST['confirm']) {
236 $drop_url = $a->query_string;
237 $extra_inputs = array(
238 array('name' => 'albumname', 'value' => $_POST['albumname']),
240 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
242 '$message' => t('Do you really want to delete this photo album and all its photos?'),
243 '$extra_inputs' => $extra_inputs,
244 '$confirm' => t('Delete Album'),
245 '$confirm_url' => $drop_url,
246 '$confirm_name' => 'dropalbum', // Needed so that confirmation will bring us back into this if statement
247 '$cancel' => t('Cancel'),
249 $a->error = 1; // Set $a->error so the other module functions don't execute
255 // get the list of photos we are about to delete
258 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
260 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()),
272 $res[] = "'" . dbesc($rr['rid']) . "'" ;
276 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
277 return; // NOTREACHED
280 $str_res = implode(',', $res);
282 // remove the associated photos
284 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
285 intval($page_owner_uid)
288 // find and delete the corresponding item with all the comments and likes/dislikes
290 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
291 intval($page_owner_uid)
295 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
296 dbesc(datetime_convert()),
297 dbesc($rr['parent-uri']),
298 intval($page_owner_uid)
300 create_tags_from_itemuri($rr['parent-uri'], $page_owner_uid);
301 delete_thread_uri($rr['parent-uri'], $page_owner_uid);
303 $drop_id = intval($rr['id']);
305 // send the notification upstream/downstream as the case may be
308 proc_run('php',"include/notifier.php","drop","$drop_id");
312 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
313 return; // NOTREACHED
317 // Check if the user has responded to a delete confirmation query for a single photo
318 if(($a->argc > 2) && $_REQUEST['canceled']) {
319 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
322 if(($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
324 // same as above but remove single photo
326 // Check if we should do HTML-based delete confirmation
327 if($_REQUEST['confirm']) {
328 $drop_url = $a->query_string;
329 $a->page['content'] = replace_macros(get_markup_template('confirm.tpl'), array(
331 '$message' => t('Do you really want to delete this photo?'),
332 '$extra_inputs' => array(),
333 '$confirm' => t('Delete Photo'),
334 '$confirm_url' => $drop_url,
335 '$confirm_name' => 'delete', // Needed so that confirmation will bring us back into this if statement
336 '$cancel' => t('Cancel'),
338 $a->error = 1; // Set $a->error so the other module functions don't execute
343 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
345 intval($page_owner_uid),
350 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
351 intval(local_user()),
356 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
357 intval($page_owner_uid),
358 dbesc($r[0]['resource-id'])
360 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
361 dbesc($r[0]['resource-id']),
362 intval($page_owner_uid)
365 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
366 dbesc(datetime_convert()),
367 dbesc(datetime_convert()),
369 intval($page_owner_uid)
371 create_tags_from_itemuri($i[0]['uri'], $page_owner_uid);
372 delete_thread_uri($i[0]['uri'], $page_owner_uid);
374 $url = $a->get_baseurl();
375 $drop_id = intval($i[0]['id']);
378 proc_run('php',"include/notifier.php","drop","$drop_id");
382 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
383 return; // NOTREACHED
386 if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
388 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
389 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
390 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
391 $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
392 $str_group_allow = perms2str($_POST['group_allow']);
393 $str_contact_allow = perms2str($_POST['contact_allow']);
394 $str_group_deny = perms2str($_POST['group_deny']);
395 $str_contact_deny = perms2str($_POST['contact_deny']);
397 $resource_id = $a->argv[2];
399 if(! strlen($albname))
400 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
403 if((x($_POST,'rotate') !== false) &&
404 ( (intval($_POST['rotate']) == 1) || (intval($_POST['rotate']) == 2) )) {
407 $r = q("select * from photo where `resource-id` = '%s' and uid = %d and scale = 0 limit 1",
409 intval($page_owner_uid)
412 $ph = new Photo($r[0]['data'], $r[0]['type']);
413 if($ph->is_valid()) {
414 $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
415 $ph->rotate($rotate_deg);
417 $width = $ph->getWidth();
418 $height = $ph->getHeight();
420 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 0",
421 dbesc($ph->imageString()),
425 intval($page_owner_uid)
428 if($width > 640 || $height > 640) {
429 $ph->scaleImage(640);
430 $width = $ph->getWidth();
431 $height = $ph->getHeight();
433 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 1",
434 dbesc($ph->imageString()),
438 intval($page_owner_uid)
442 if($width > 320 || $height > 320) {
443 $ph->scaleImage(320);
444 $width = $ph->getWidth();
445 $height = $ph->getHeight();
447 $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 2",
448 dbesc($ph->imageString()),
452 intval($page_owner_uid)
459 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
461 intval($page_owner_uid)
464 $ext = $phototypes[$p[0]['type']];
465 $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",
468 dbesc($str_contact_allow),
469 dbesc($str_group_allow),
470 dbesc($str_contact_deny),
471 dbesc($str_group_deny),
473 intval($page_owner_uid)
477 /* Don't make the item visible if the only change was the album name */
480 if($p[0]['desc'] !== $desc || strlen($rawtags))
485 // Create item container
488 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
492 $arr['uid'] = $page_owner_uid;
494 $arr['parent-uri'] = $uri;
495 $arr['type'] = 'photo';
497 $arr['resource-id'] = $p[0]['resource-id'];
498 $arr['contact-id'] = $owner_record['id'];
499 $arr['owner-name'] = $owner_record['name'];
500 $arr['owner-link'] = $owner_record['url'];
501 $arr['owner-avatar'] = $owner_record['thumb'];
502 $arr['author-name'] = $owner_record['name'];
503 $arr['author-link'] = $owner_record['url'];
504 $arr['author-avatar'] = $owner_record['thumb'];
505 $arr['title'] = $title;
506 $arr['allow_cid'] = $p[0]['allow_cid'];
507 $arr['allow_gid'] = $p[0]['allow_gid'];
508 $arr['deny_cid'] = $p[0]['deny_cid'];
509 $arr['deny_gid'] = $p[0]['deny_gid'];
510 $arr['last-child'] = 1;
511 $arr['visible'] = $visibility;
514 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
515 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
518 $item_id = item_store($arr);
523 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
525 intval($page_owner_uid)
529 $old_tag = $r[0]['tag'];
530 $old_inform = $r[0]['inform'];
533 if(strlen($rawtags)) {
538 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
540 $x = substr($rawtags,0,1);
541 if($x !== '@' && $x !== '#')
542 $rawtags = '#' . $rawtags;
545 $tags = get_tags($rawtags);
548 foreach($tags as $tag) {
551 if(strpos($tag,'@') === 0) {
552 $name = substr($tag,1);
553 if((strpos($name,'@')) || (strpos($name,'http://'))) {
555 $links = @lrdd($name);
557 foreach($links as $link) {
558 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
559 $profile = $link['@attributes']['href'];
560 if($link['@attributes']['rel'] === 'salmon') {
561 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
568 $taginfo[] = array($newname,$profile,$salmon);
574 if(strrpos($newname,'+'))
575 $tagcid = intval(substr($newname,strrpos($newname,'+') + 1));
578 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
584 $newname = str_replace('_',' ',$name);
586 //select someone from this user's contacts by name
587 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
589 intval($page_owner_uid)
593 //select someone by attag or nick and the name passed in
594 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
597 intval($page_owner_uid)
601 /* elseif(strstr($name,'_') || strstr($name,' ')) {
602 $newname = str_replace('_',' ',$name);
603 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
605 intval($page_owner_uid)
609 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
612 intval($page_owner_uid)
616 $newname = $r[0]['name'];
617 $profile = $r[0]['url'];
618 $notify = 'cid:' . $r[0]['id'];
625 if(substr($notify,0,4) === 'cid:')
626 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
628 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
629 if(strlen($str_tags))
631 $profile = str_replace(',','%2c',$profile);
632 $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
634 } elseif (strpos($tag,'#') === 0) {
635 $tagname = substr($tag, 1);
636 $str_tags .= '#[url='.$a->get_baseurl()."/search?tag=".$tagname.']'.$tagname.'[/url]';
642 if(strlen($newtag) && strlen($str_tags))
644 $newtag .= $str_tags;
646 $newinform = $old_inform;
647 if(strlen($newinform) && strlen($inform))
649 $newinform .= $inform;
651 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
654 dbesc(datetime_convert()),
655 dbesc(datetime_convert()),
657 intval($page_owner_uid)
659 create_tags_from_item($item_id);
660 update_thread($item_id);
663 foreach($p as $scales) {
664 if(intval($scales['scale']) == 2) {
668 if(intval($scales['scale']) == 4) {
674 if(count($taginfo)) {
675 foreach($taginfo as $tagged) {
677 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
681 $arr['uid'] = $page_owner_uid;
683 $arr['parent-uri'] = $uri;
684 $arr['type'] = 'activity';
686 $arr['contact-id'] = $owner_record['id'];
687 $arr['owner-name'] = $owner_record['name'];
688 $arr['owner-link'] = $owner_record['url'];
689 $arr['owner-avatar'] = $owner_record['thumb'];
690 $arr['author-name'] = $owner_record['name'];
691 $arr['author-link'] = $owner_record['url'];
692 $arr['author-avatar'] = $owner_record['thumb'];
694 $arr['allow_cid'] = $p[0]['allow_cid'];
695 $arr['allow_gid'] = $p[0]['allow_gid'];
696 $arr['deny_cid'] = $p[0]['deny_cid'];
697 $arr['deny_gid'] = $p[0]['deny_gid'];
698 $arr['last-child'] = 1;
700 $arr['verb'] = ACTIVITY_TAG;
701 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
702 $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
703 $arr['tag'] = $tagged[4];
704 $arr['inform'] = $tagged[2];
706 $arr['body'] = sprintf( t('%1$s was tagged in %2$s by %3$s'), '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]', '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . t('a photo') . '[/url]', '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]') ;
707 $arr['body'] .= "\n\n" . '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . '[img]' . $a->get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '[/img][/url]' . "\n" ;
709 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
710 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
712 $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
713 $arr['object'] .= '</link></object>' . "\n";
715 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
716 . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
717 $arr['target'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '" />' . "\n" . '<link rel="preview" type="'.$p[0]['type'].'" href="' . $a->get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>';
719 $item_id = item_store($arr);
721 //q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
722 // dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
723 // intval($page_owner_uid),
727 proc_run('php',"include/notifier.php","tag","$item_id");
734 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
735 return; // NOTREACHED
740 * default post action - upload a photo
743 call_hooks('photo_post_init', $_POST);
746 * Determine the album to use
749 $album = notags(trim($_REQUEST['album']));
750 $newalbum = notags(trim($_REQUEST['newalbum']));
752 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
754 if(! strlen($album)) {
755 if(strlen($newalbum))
758 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
763 * We create a wall item for every photo, but we don't want to
764 * overwhelm the data stream with a hundred newly uploaded photos.
765 * So we will make the first photo uploaded to this album in the last several hours
766 * visible by default, the rest will become visible over time when and if
767 * they acquire comments, likes, dislikes, and/or tags
771 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
773 intval($page_owner_uid)
775 if((! count($r)) || ($album == t('Profile Photos')))
780 if(intval($_REQUEST['not_visible']) || $_REQUEST['not_visible'] === 'true')
783 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
784 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
785 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
786 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
788 $ret = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
790 call_hooks('photo_post_file',$ret);
792 if(x($ret,'src') && x($ret,'filesize')) {
794 $filename = $ret['filename'];
795 $filesize = $ret['filesize'];
796 $type = $ret['type'];
799 $src = $_FILES['userfile']['tmp_name'];
800 $filename = basename($_FILES['userfile']['name']);
801 $filesize = intval($_FILES['userfile']['size']);
802 $type = $_FILES['userfile']['type'];
804 if ($type=="") $type=guess_image_type($filename);
806 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
808 $maximagesize = get_config('system','maximagesize');
810 if(($maximagesize) && ($filesize > $maximagesize)) {
811 notice( sprintf(t('Image exceeds size limit of %s'), formatBytes($maximagesize)) . EOL);
814 call_hooks('photo_post_end',$foo);
819 notice( t('Image file is empty.') . EOL);
822 call_hooks('photo_post_end',$foo);
826 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
828 $imagedata = @file_get_contents($src);
832 $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
833 intval($a->data['user']['uid'])
836 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
838 if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
839 notice( upgrade_message() . EOL );
842 call_hooks('photo_post_end',$foo);
847 $ph = new Photo($imagedata, $type);
849 if(! $ph->is_valid()) {
850 logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
851 notice( t('Unable to process image.') . EOL );
854 call_hooks('photo_post_end',$foo);
858 $exif = $ph->orient($src);
861 $max_length = get_config('system','max_image_length');
863 $max_length = MAX_IMAGE_LENGTH;
865 $ph->scaleImage($max_length);
867 $width = $ph->getWidth();
868 $height = $ph->getHeight();
872 $photo_hash = photo_new_resource();
874 $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);
877 logger('mod/photos.php: photos_post(): image store failed' , LOGGER_DEBUG);
878 notice( t('Image upload failed.') . EOL );
882 if($width > 640 || $height > 640) {
883 $ph->scaleImage(640);
884 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
888 if($width > 320 || $height > 320) {
889 $ph->scaleImage(320);
890 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
894 $basename = basename($filename);
895 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
897 // Create item container
901 if($exif && $exif['GPS']) {
902 if(feature_enabled($channel_id,'photo_location')) {
903 $lat = getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
904 $lon = getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
911 $arr['coord'] = $lat . ' ' . $lon;
913 $arr['uid'] = $page_owner_uid;
915 $arr['parent-uri'] = $uri;
916 $arr['type'] = 'photo';
918 $arr['resource-id'] = $photo_hash;
919 $arr['contact-id'] = $owner_record['id'];
920 $arr['owner-name'] = $owner_record['name'];
921 $arr['owner-link'] = $owner_record['url'];
922 $arr['owner-avatar'] = $owner_record['thumb'];
923 $arr['author-name'] = $owner_record['name'];
924 $arr['author-link'] = $owner_record['url'];
925 $arr['author-avatar'] = $owner_record['thumb'];
927 $arr['allow_cid'] = $str_contact_allow;
928 $arr['allow_gid'] = $str_group_allow;
929 $arr['deny_cid'] = $str_contact_deny;
930 $arr['deny_gid'] = $str_group_deny;
931 $arr['last-child'] = 1;
932 $arr['visible'] = $visible;
935 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
936 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]'
939 $item_id = item_store($arr);
942 // q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d",
943 // dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
944 // intval($page_owner_uid),
950 proc_run('php', "include/notifier.php", 'wall-new', $item_id);
952 call_hooks('photo_post_end',intval($item_id));
954 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
955 // if they do not wish to be redirected
957 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
963 function photos_content(&$a) {
967 // photos/name/upload
968 // photos/name/upload/xxxxx (xxxxx is album name)
969 // photos/name/album/xxxxx
970 // photos/name/album/xxxxx/edit
971 // photos/name/image/xxxxx
972 // photos/name/image/xxxxx/edit
975 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
976 notice( t('Public access denied.') . EOL);
981 require_once('include/bbcode.php');
982 require_once('include/security.php');
983 require_once('include/conversation.php');
985 if(! x($a->data,'user')) {
986 notice( t('No photos selected') . EOL );
990 $phototypes = Photo::supportedTypes();
992 $_SESSION['photo_return'] = $a->cmd;
999 $datatype = $a->argv[2];
1000 $datum = $a->argv[3];
1002 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
1003 $datatype = 'upload';
1005 $datatype = 'summary';
1013 // Setup permissions structures
1019 $remote_contact = false;
1022 $owner_uid = $a->data['user']['uid'];
1024 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
1026 // get the access rights for photos
1027 $photos_perms = photos_permissions($owner_uid, $community_page);
1029 // convert keys of the $photo_persms array into variables
1030 if(count($photos_perms)) {
1031 foreach ($photos_perms as $key => $value) {
1036 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
1037 notice( t('Access to this item is restricted.') . EOL);
1041 $sql_extra = permissions_sql($owner_uid, $remote_contact, $groups);
1046 $is_owner = (local_user() && (local_user() == $owner_uid));
1047 $o .= profile_tabs($a,$is_owner, $a->data['user']['nickname']);
1050 * Display upload form
1053 if($datatype === 'upload') {
1055 notice( t('Permission denied.'));
1060 $selname = (($datum) ? hex2bin($datum) : '');
1066 $albumselect .= '<option value="" ' . ((! $selname) ? ' selected="selected" ' : '') . '> </option>';
1067 if(count($a->data['albums'])) {
1068 foreach($a->data['albums'] as $album) {
1069 if(($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
1071 $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
1072 $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
1078 $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
1079 'addon_text' => $uploader,
1080 'default_upload' => true);
1083 call_hooks('photo_upload_form',$ret);
1085 $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), array());
1086 $default_upload_submit = replace_macros(get_markup_template('photos_default_uploader_submit.tpl'), array(
1087 '$submit' => t('Submit'),
1090 $usage_message = '';
1091 $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
1092 if($limit !== false) {
1094 $r = q("select sum(datasize) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
1095 intval($a->data['user']['uid'])
1097 $usage_message = sprintf( t("You have used %1$.2f Mbytes of %2$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000 );
1101 // Private/public post links for the non-JS ACL form
1103 if($_REQUEST['public'])
1106 $query_str = $a->query_string;
1107 if(strpos($query_str, 'public=1') !== false)
1108 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1110 // I think $a->query_string may never have ? in it, but I could be wrong
1111 // It looks like it's from the index.php?q=[etc] rewrite that the web
1112 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1113 if(strpos($query_str, '?') === false)
1114 $public_post_link = '?public=1';
1116 $public_post_link = '&public=1';
1120 $tpl = get_markup_template('photos_upload.tpl');
1122 if($a->theme['template_engine'] === 'internal') {
1123 $albumselect_e = template_escape($albumselect);
1124 $aclselect_e = (($visitor) ? '' : template_escape(populate_acl($a->user)));
1127 $albumselect_e = $albumselect;
1128 $aclselect_e = (($visitor) ? '' : populate_acl($a->user));
1131 $o .= replace_macros($tpl,array(
1132 '$pagename' => t('Upload Photos'),
1133 '$sessid' => session_id(),
1134 '$usage' => $usage_message,
1135 '$nickname' => $a->data['user']['nickname'],
1136 '$newalbum' => t('New album name: '),
1137 '$existalbumtext' => t('or existing album name: '),
1138 '$nosharetext' => t('Do not show a status post for this upload'),
1139 '$albumselect' => $albumselect_e,
1140 '$permissions' => t('Permissions'),
1141 '$aclselect' => $aclselect_e,
1142 '$alt_uploader' => $ret['addon_text'],
1143 '$default_upload_box' => (($ret['default_upload']) ? $default_upload_box : ''),
1144 '$default_upload_submit' => (($ret['default_upload']) ? $default_upload_submit : ''),
1145 '$uploadurl' => $ret['post_url'],
1147 // ACL permissions box
1148 '$acl_data' => construct_acl_data($a, $a->user), // For non-Javascript ACL selector
1149 '$group_perms' => t('Show to Groups'),
1150 '$contact_perms' => t('Show to Contacts'),
1151 '$private' => t('Private Photo'),
1152 '$public' => t('Public Photo'),
1153 '$is_private' => $private_post,
1154 '$return_path' => $query_str,
1155 '$public_link' => $public_post_link,
1163 * Display a single photo album
1166 if($datatype === 'album') {
1168 $album = hex2bin($datum);
1170 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1171 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
1176 $a->set_pager_total(count($r));
1177 $a->set_pager_itemspage(20);
1180 if($_GET['order'] === 'posted')
1185 $r = q("SELECT `resource-id`, `id`, `filename`, type, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
1186 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
1189 intval($a->pager['start']),
1190 intval($a->pager['itemspage'])
1194 if($cmd === 'edit') {
1195 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1197 $edit_tpl = get_markup_template('album_edit.tpl');
1199 if($a->theme['template_engine'] === 'internal') {
1200 $album_e = template_escape($album);
1206 $o .= replace_macros($edit_tpl,array(
1207 '$nametext' => t('New album name: '),
1208 '$nickname' => $a->data['user']['nickname'],
1209 '$album' => $album_e,
1210 '$hexalbum' => bin2hex($album),
1211 '$submit' => t('Submit'),
1212 '$dropsubmit' => t('Delete Album')
1218 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
1220 $edit = array(t('Edit Album'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit');
1225 if($_GET['order'] === 'posted')
1226 $order = array(t('Show Newest First'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album));
1228 $order = array(t('Show Oldest First'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted');
1233 $twist = 'rotright';
1234 foreach($r as $rr) {
1235 if($twist == 'rotright')
1238 $twist = 'rotright';
1240 $ext = $phototypes[$rr['type']];
1242 if($a->theme['template_engine'] === 'internal') {
1243 $imgalt_e = template_escape($rr['filename']);
1244 $desc_e = template_escape($rr['desc']);
1247 $imgalt_e = $rr['filename'];
1248 $desc_e = $rr['desc'];
1253 'twist' => ' ' . $twist . rand(2,4),
1254 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
1255 . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''),
1256 'title' => t('View Photo'),
1257 'src' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
1261 'hash'=> $rr['resource_id'],
1265 $tpl = get_markup_template('photo_album.tpl');
1266 $o .= replace_macros($tpl, array(
1267 '$photos' => $photos,
1269 '$can_post' => $can_post,
1270 '$upload' => array(t('Upload New Photos'), $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album)),
1285 if($datatype === 'image') {
1288 // fetch image, item containing image, then comments
1290 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1291 $sql_extra ORDER BY `scale` ASC ",
1297 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1303 notice( t('Permission denied. Access to this item may be restricted.'));
1305 notice( t('Photo not available') . EOL );
1312 if($_GET['order'] === 'posted')
1318 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1319 $sql_extra ORDER BY `created` $order ",
1320 dbesc($ph[0]['album']),
1324 if(count($prvnxt)) {
1325 for($z = 0; $z < count($prvnxt); $z++) {
1326 if($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
1330 $prv = count($prvnxt) - 1;
1331 if($nxt >= count($prvnxt))
1336 $edit_suffix = ((($cmd === 'edit') && ($can_post)) ? '/edit' : '');
1337 $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1338 $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
1343 $hires = $lores = $ph[0];
1344 if(count($ph) > 1) {
1345 if($ph[1]['scale'] == 2) {
1346 // original is 640 or less, we can display it directly
1347 $hires = $lores = $ph[0];
1355 $album_link = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1359 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
1361 'edit' => array($a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? t('View photo') : t('Edit photo'))),
1362 'profile'=>array($a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
1366 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1367 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1368 ? t('Private Message')
1374 if( $cmd === 'edit') {
1375 $tpl = get_markup_template('photo_edit_head.tpl');
1376 $a->page['htmlhead'] .= replace_macros($tpl,array(
1377 '$prevlink' => $prevlink,
1378 '$nextlink' => $nextlink
1383 $prevlink = array($prevlink, '<div class="icon prev"></div>') ;
1386 'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
1387 'title'=> t('View Full Size'),
1388 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis'),
1389 'height' => $hires['height'],
1390 'width' => $hires['width'],
1391 'album' => $hires['album'],
1392 'filename' => $hires['filename'],
1396 $nextlink = array($nextlink, '<div class="icon next"></div>');
1399 // Do we have an item for this photo?
1401 // FIXME! - replace following code to display the conversation with our normal
1402 // conversation functions so that it works correctly and tracks changes
1403 // in the evolving conversation code.
1404 // The difference is that we won't be displaying the conversation head item
1405 // as a "post" but displaying instead the photo it is linked to
1407 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1413 if(count($linked_items)) {
1414 $link_item = $linked_items[0];
1415 $r = q("SELECT COUNT(*) AS `total`
1416 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1417 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1418 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1419 AND `item`.`uid` = %d
1421 dbesc($link_item['uri']),
1422 dbesc($link_item['uri']),
1423 intval($link_item['uid'])
1428 $a->set_pager_total($r[0]['total']);
1431 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1432 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1433 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1434 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1435 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1436 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
1437 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1438 AND `item`.`uid` = %d
1440 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1441 dbesc($link_item['uri']),
1442 dbesc($link_item['uri']),
1443 intval($link_item['uid']),
1444 intval($a->pager['start']),
1445 intval($a->pager['itemspage'])
1449 if((local_user()) && (local_user() == $link_item['uid'])) {
1450 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1451 intval($link_item['parent']),
1452 intval(local_user())
1454 update_thread($link_item['parent']);
1457 if($link_item['coord']) {
1458 $map = generate_map($link_item['coord']);
1464 if(count($linked_items) && strlen($link_item['tag'])) {
1465 $arr = explode(',',$link_item['tag']);
1466 // parse tags and add links
1468 foreach($arr as $t) {
1469 if(strlen($tag_str))
1471 $tag_str .= bbcode($t);
1473 $tags = array(t('Tags: '), $tag_str);
1474 if($cmd === 'edit') {
1475 $tags[] = $a->get_baseurl() . '/tagrm/' . $link_item['id'];
1476 $tags[] = t('[Remove any tag]');
1482 if(($cmd === 'edit') && ($can_post)) {
1483 $edit_tpl = get_markup_template('photo_edit.tpl');
1485 // Private/public post links for the non-JS ACL form
1487 if($_REQUEST['public'])
1490 $query_str = $a->query_string;
1491 if(strpos($query_str, 'public=1') !== false)
1492 $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
1494 // I think $a->query_string may never have ? in it, but I could be wrong
1495 // It looks like it's from the index.php?q=[etc] rewrite that the web
1496 // server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
1497 if(strpos($query_str, '?') === false)
1498 $public_post_link = '?public=1';
1500 $public_post_link = '&public=1';
1503 if($a->theme['template_engine'] === 'internal') {
1504 $album_e = template_escape($ph[0]['album']);
1505 $caption_e = template_escape($ph[0]['desc']);
1506 $aclselect_e = template_escape(populate_acl($ph[0]));
1509 $album_e = $ph[0]['album'];
1510 $caption_e = $ph[0]['desc'];
1511 $aclselect_e = populate_acl($ph[0]);
1514 $edit = replace_macros($edit_tpl, array(
1515 '$id' => $ph[0]['id'],
1516 '$album' => array('albname', t('New album name'), $album_e,''),
1517 '$caption' => array('desc', t('Caption'), $caption_e, ''),
1518 '$tags' => array('newtag', t('Add a Tag'), "", t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')),
1519 '$rotate_none' => array('rotate',t('Do not rotate'),0,'', true),
1520 '$rotate_cw' => array('rotate',t('Rotate CW (right)'),1,''),
1521 '$rotate_ccw' => array('rotate',t('Rotate CCW (left)'),2,''),
1523 '$nickname' => $a->data['user']['nickname'],
1524 '$resource_id' => $ph[0]['resource-id'],
1525 '$permissions' => t('Permissions'),
1526 '$aclselect' => $aclselect_e,
1528 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1529 '$submit' => t('Submit'),
1530 '$delete' => t('Delete Photo'),
1532 // ACL permissions box
1533 '$acl_data' => construct_acl_data($a, $ph[0]), // For non-Javascript ACL selector
1534 '$group_perms' => t('Show to Groups'),
1535 '$contact_perms' => t('Show to Contacts'),
1536 '$private' => t('Private photo'),
1537 '$public' => t('Public photo'),
1538 '$is_private' => $private_post,
1539 '$return_path' => $query_str,
1540 '$public_link' => $public_post_link,
1544 if(count($linked_items)) {
1546 $cmnt_tpl = get_markup_template('comment_item.tpl');
1547 $tpl = get_markup_template('photo_item.tpl');
1548 $return_url = $a->cmd;
1550 $like_tpl = get_markup_template('like_noshare.tpl');
1554 if($can_post || can_write_wall($a,$owner_uid)) {
1555 $likebuttons = replace_macros($like_tpl,array(
1556 '$id' => $link_item['id'],
1557 '$likethis' => t("I like this \x28toggle\x29"),
1558 '$nolike' => (feature_enabled(local_user(), 'dislike') ? t("I don't like this \x28toggle\x29") : ''),
1559 '$share' => t('Share'),
1560 '$wait' => t('Please wait'),
1561 '$return_path' => $a->query_string,
1567 if($can_post || can_write_wall($a,$owner_uid)) {
1568 if($link_item['last-child']) {
1569 $comments .= replace_macros($cmnt_tpl,array(
1570 '$return_path' => '',
1571 '$jsreload' => $return_url,
1572 '$type' => 'wall-comment',
1573 '$id' => $link_item['id'],
1574 '$parent' => $link_item['id'],
1575 '$profile_uid' => $owner_uid,
1576 '$mylink' => $contact['url'],
1577 '$mytitle' => t('This is you'),
1578 '$myphoto' => $contact['thumb'],
1579 '$comment' => t('Comment'),
1580 '$submit' => t('Submit'),
1581 '$preview' => t('Preview'),
1582 '$sourceapp' => t($a->sourcename),
1584 '$rand_num' => random_digits(12)
1596 $conv_responses = array(
1597 'like' => array('title' => t('Likes','title')),'dislike' => array('title' => t('Dislikes','title')),
1598 'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title'))
1606 foreach($r as $item) {
1607 builtin_activity_puller($item, $conv_responses);
1610 $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']) : '');
1611 $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']) : '');
1615 if($can_post || can_write_wall($a,$owner_uid)) {
1616 if($link_item['last-child']) {
1617 $comments .= replace_macros($cmnt_tpl,array(
1618 '$return_path' => '',
1619 '$jsreload' => $return_url,
1620 '$type' => 'wall-comment',
1621 '$id' => $link_item['id'],
1622 '$parent' => $link_item['id'],
1623 '$profile_uid' => $owner_uid,
1624 '$mylink' => $contact['url'],
1625 '$mytitle' => t('This is you'),
1626 '$myphoto' => $contact['thumb'],
1627 '$comment' => t('Comment'),
1628 '$submit' => t('Submit'),
1629 '$preview' => t('Preview'),
1630 '$sourceapp' => t($a->sourcename),
1632 '$rand_num' => random_digits(12)
1638 foreach($r as $item) {
1643 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1646 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1649 if(local_user() && ($item['contact-uid'] == local_user())
1650 && ($item['network'] == NETWORK_DFRN) && (! $item['self'] )) {
1651 $profile_url = $redirect_url;
1652 $sparkle = ' sparkle';
1655 $profile_url = $item['url'];
1659 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1661 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1662 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1664 $profile_link = $profile_url;
1668 $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
1670 'dropping' => $dropping,
1671 'pagedrop' => false,
1672 'select' => t('Select'),
1673 'delete' => t('Delete'),
1677 if($a->theme['template_engine'] === 'internal') {
1678 $name_e = template_escape($profile_name);
1679 $title_e = template_escape($item['title']);
1680 $body_e = template_escape(bbcode($item['body']));
1683 $name_e = $profile_name;
1684 $title_e = $item['title'];
1685 $body_e = bbcode($item['body']);
1688 $comments .= replace_macros($template,array(
1689 '$id' => $item['item_id'],
1690 '$profile_url' => $profile_link,
1692 '$thumb' => $profile_avatar,
1693 '$sparkle' => $sparkle,
1694 '$title' => $title_e,
1696 '$ago' => relative_date($item['created']),
1697 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1699 '$comment' => $comment
1702 if($can_post || can_write_wall($a,$owner_uid)) {
1704 if($item['last-child']) {
1705 $comments .= replace_macros($cmnt_tpl,array(
1706 '$return_path' => '',
1707 '$jsreload' => $return_url,
1708 '$type' => 'wall-comment',
1709 '$id' => $item['item_id'],
1710 '$parent' => $item['parent'],
1711 '$profile_uid' => $owner_uid,
1712 '$mylink' => $contact['url'],
1713 '$mytitle' => t('This is you'),
1714 '$myphoto' => $contact['thumb'],
1715 '$comment' => t('Comment'),
1716 '$submit' => t('Submit'),
1717 '$preview' => t('Preview'),
1718 '$sourceapp' => t($a->sourcename),
1720 '$rand_num' => random_digits(12)
1727 $paginate = paginate($a);
1731 $response_verbs = array('like');
1732 if(feature_enabled($owner_uid,'dislike'))
1733 $response_verbs[] = 'dislike';
1734 $responses = get_responses($conv_responses,$response_verbs,'',$link_item);
1736 $photo_tpl = get_markup_template('photo_view.tpl');
1738 if($a->theme['template_engine'] === 'internal') {
1739 $album_e = array($album_link,template_escape($ph[0]['album']));
1740 $tags_e = template_escape($tags);
1741 $like_e = template_escape($like);
1742 $dislike_e = template_escape($dislike);
1745 $album_e = array($album_link,$ph[0]['album']);
1748 $dislike_e = $dislike;
1751 $o .= replace_macros($photo_tpl, array(
1752 '$id' => $ph[0]['id'],
1753 '$album' => $album_e,
1757 '$prevlink' => $prevlink,
1758 '$nextlink' => $nextlink,
1759 '$desc' => $ph[0]['desc'],
1763 '$map_text' => t('Map'),
1764 '$likebuttons' => $likebuttons,
1766 '$dislike' => $dikslike_e,
1767 'responses' => $responses,
1768 '$comments' => $comments,
1769 '$paginate' => $paginate,
1772 $a->page['htmlhead'] .= "\n".'<meta name="twitter:card" content="photo" />'."\n";
1773 $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$photo["album"].'" />'."\n";
1774 $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$photo["href"].'" />'."\n";
1775 $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="'.$photo["width"].'" />'."\n";
1776 $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="'.$photo["height"].'" />'."\n";
1781 // Default - show recent photos with upload link (if applicable)
1784 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1785 $sql_extra GROUP BY `resource-id`",
1786 intval($a->data['user']['uid']),
1787 dbesc('Contact Photos'),
1788 dbesc( t('Contact Photos'))
1791 $a->set_pager_total(count($r));
1792 $a->set_pager_itemspage(20);
1795 $r = q("SELECT `resource-id`, `id`, `filename`, `type`, `album`, max(`scale`) AS `scale` FROM `photo`
1796 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1797 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1798 intval($a->data['user']['uid']),
1799 dbesc('Contact Photos'),
1800 dbesc( t('Contact Photos')),
1801 intval($a->pager['start']),
1802 intval($a->pager['itemspage'])
1809 $twist = 'rotright';
1810 foreach($r as $rr) {
1811 //hide profile photos to others
1812 if((! $is_owner) && (! remote_user()) && ($rr['album'] == t('Profile Photos')))
1815 if($twist == 'rotright')
1818 $twist = 'rotright';
1819 $ext = $phototypes[$rr['type']];
1821 if($a->theme['template_engine'] === 'internal') {
1822 $alt_e = template_escape($rr['filename']);
1823 $name_e = template_escape($rr['album']);
1826 $alt_e = $rr['filename'];
1827 $name_e = $rr['album'];
1832 'twist' => ' ' . $twist . rand(2,4),
1833 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1834 'title' => t('View Photo'),
1835 'src' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
1838 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1840 'alt' => t('View Album'),
1847 $tpl = get_markup_template('photos_recent.tpl');
1848 $o .= replace_macros($tpl, array(
1849 '$title' => t('Recent Photos'),
1850 '$can_post' => $can_post,
1851 '$upload' => array(t('Upload New Photos'), $a->get_baseurl().'/photos/'.$a->data['user']['nickname'].'/upload'),
1852 '$photos' => $photos,