2 require_once('include/Photo.php');
3 require_once('include/items.php');
4 require_once('include/acl_selectors.php');
5 require_once('include/bbcode.php');
6 require_once('include/security.php');
8 function photos_init(&$a) {
11 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
18 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
25 $a->data['user'] = $r[0];
27 $sql_extra = permissions_sql($a->data['user']['uid']);
29 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra ",
30 intval($a->data['user']['uid'])
34 $a->data['albums'] = $albums;
36 $o .= '<div class="vcard">';
37 $o .= '<div class="fn">' . $a->data['user']['username'] . '</div>';
38 $o .= '<div id="profile-photo-wrapper"><img class="photo" style="width: 175px; height: 175px;" src="' . $a->get_baseurl() . '/photo/profile/' . $a->data['user']['uid'] . '.jpg" alt="' . $a->data['user']['username'] . '" /></div>';
41 $o .= '<div id="side-bar-photos-albums" class="widget">';
42 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h3>';
45 foreach($albums as $album) {
47 // don't show contact photos. We once translated this name, but then you could still access it under
48 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
50 if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
52 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>';
59 if(! x($a->page,'aside'))
60 $a->page['aside'] = '';
61 $a->page['aside'] .= $o;
64 $a->page['htmlhead'] .= "<script> var ispublic = '" . t('everybody') . "';" ;
66 $a->page['htmlhead'] .= <<< EOT
68 $(document).ready(function() {
70 $('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() {
72 $('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() {
73 selstr = $(this).text();
74 $('#jot-perms-icon').removeClass('unlock').addClass('lock');
75 $('#jot-public').hide();
78 $('#jot-perms-icon').removeClass('lock').addClass('unlock');
79 $('#jot-public').show();
95 function photos_post(&$a) {
97 logger('mod-photos: photos_post(): begin' , 'LOGGER_DEBUG');
100 logger('mod_photos: REQUEST ' . print_r($_REQUEST,true), LOGGER_DATA);
101 logger('mod_photos: FILES ' . print_r($_FILES,true), LOGGER_DATA);
106 $page_owner_uid = $a->data['user']['uid'];
107 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
109 if((local_user()) && (local_user() == $page_owner_uid))
112 if($community_page && remote_user()) {
113 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
114 intval(remote_user()),
115 intval($page_owner_uid)
119 $visitor = remote_user();
125 notice( t('Permission denied.') . EOL );
129 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
130 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
131 intval($page_owner_uid)
135 notice( t('Contact information unavailable') . EOL);
136 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
140 $owner_record = $r[0];
143 if(($a->argc > 3) && ($a->argv[2] === 'album')) {
144 $album = hex2bin($a->argv[3]);
146 if($album === t('Profile Photos') || $album === 'Contact Photos' || $album === t('Contact Photos')) {
147 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
148 return; // NOTREACHED
151 $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
153 intval($page_owner_uid)
156 notice( t('Album not found.') . EOL);
157 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
158 return; // NOTREACHED
161 $newalbum = notags(trim($_POST['albumname']));
162 if($newalbum != $album) {
163 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
166 intval($page_owner_uid)
168 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
169 goaway($a->get_baseurl() . '/' . $newurl);
170 return; // NOTREACHED
174 if($_POST['dropalbum'] == t('Delete Album')) {
178 // get the list of photos we are about to delete
181 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
183 intval($page_owner_uid),
188 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
189 intval(local_user()),
195 $res[] = "'" . dbesc($rr['rid']) . "'" ;
199 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
200 return; // NOTREACHED
203 $str_res = implode(',', $res);
205 // remove the associated photos
207 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
208 intval($page_owner_uid)
211 // find and delete the corresponding item with all the comments and likes/dislikes
213 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
214 intval($page_owner_uid)
218 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
219 dbesc(datetime_convert()),
220 dbesc($rr['parent-uri']),
221 intval($page_owner_uid)
224 $drop_id = intval($rr['id']);
226 // send the notification upstream/downstream as the case may be
229 proc_run('php',"include/notifier.php","drop","$drop_id");
233 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
234 return; // NOTREACHED
237 if(($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
239 // same as above but remove single photo
242 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
244 intval($page_owner_uid),
249 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
250 intval(local_user()),
255 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
256 intval($page_owner_uid),
257 dbesc($r[0]['resource-id'])
259 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
260 dbesc($r[0]['resource-id']),
261 intval($page_owner_uid)
264 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
265 dbesc(datetime_convert()),
266 dbesc(datetime_convert()),
268 intval($page_owner_uid)
271 $url = $a->get_baseurl();
272 $drop_id = intval($i[0]['id']);
275 proc_run('php',"include/notifier.php","drop","$drop_id");
279 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
280 return; // NOTREACHED
283 if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
285 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
286 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
287 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
288 $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
289 $str_group_allow = perms2str($_POST['group_allow']);
290 $str_contact_allow = perms2str($_POST['contact_allow']);
291 $str_group_deny = perms2str($_POST['group_deny']);
292 $str_contact_deny = perms2str($_POST['contact_deny']);
294 $resource_id = $a->argv[2];
296 if(! strlen($albname))
297 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
300 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
302 intval($page_owner_uid)
305 $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",
308 dbesc($str_contact_allow),
309 dbesc($str_group_allow),
310 dbesc($str_contact_deny),
311 dbesc($str_group_deny),
313 intval($page_owner_uid)
317 /* Don't make the item visible if the only change was the album name */
320 if($p[0]['desc'] !== $desc || strlen($rawtags))
325 // Create item container
328 $basename = basename($filename);
329 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
333 $arr['uid'] = $page_owner_uid;
335 $arr['parent-uri'] = $uri;
336 $arr['type'] = 'photo';
338 $arr['resource-id'] = $p[0]['resource-id'];
339 $arr['contact-id'] = $owner_record['id'];
340 $arr['owner-name'] = $owner_record['name'];
341 $arr['owner-link'] = $owner_record['url'];
342 $arr['owner-avatar'] = $owner_record['thumb'];
343 $arr['author-name'] = $owner_record['name'];
344 $arr['author-link'] = $owner_record['url'];
345 $arr['author-avatar'] = $owner_record['thumb'];
346 $arr['title'] = $title;
347 $arr['allow_cid'] = $p[0]['allow_cid'];
348 $arr['allow_gid'] = $p[0]['allow_gid'];
349 $arr['deny_cid'] = $p[0]['deny_cid'];
350 $arr['deny_gid'] = $p[0]['deny_gid'];
351 $arr['last-child'] = 1;
352 $arr['visible'] = $visibility;
355 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
356 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]'
359 $item_id = item_store($arr);
364 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
366 intval($page_owner_uid)
370 $old_tag = $r[0]['tag'];
371 $old_inform = $r[0]['inform'];
374 if(strlen($rawtags)) {
379 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
381 $x = substr($rawtags,0,1);
382 if($x !== '@' && $x !== '#')
383 $rawtags = '#' . $rawtags;
386 $tags = get_tags($rawtags);
389 foreach($tags as $tag) {
392 if(strpos($tag,'@') === 0) {
393 $name = substr($tag,1);
394 if((strpos($name,'@')) || (strpos($name,'http://'))) {
396 $links = @lrdd($name);
398 foreach($links as $link) {
399 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
400 $profile = $link['@attributes']['href'];
401 if($link['@attributes']['rel'] === 'salmon') {
402 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
409 $taginfo[] = array($newname,$profile,$salmon);
415 if(strrpos($newname,'+'))
416 $tagcid = intval(substr($newname,strrpos($newname,'+') + 1));
419 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
424 elseif(strstr($name,'_') || strstr($name,' ')) {
425 $newname = str_replace('_',' ',$name);
426 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
428 intval($page_owner_uid)
432 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
435 intval($page_owner_uid)
439 $newname = $r[0]['name'];
440 $profile = $r[0]['url'];
441 $notify = 'cid:' . $r[0]['id'];
448 if(substr($notify,0,4) === 'cid:')
449 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
451 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
452 if(strlen($str_tags))
454 $profile = str_replace(',','%2c',$profile);
455 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
462 if(strlen($newtag) && strlen($str_tags))
464 $newtag .= $str_tags;
466 $newinform = $old_inform;
467 if(strlen($newinform) && strlen($inform))
469 $newinform .= $inform;
471 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
474 dbesc(datetime_convert()),
475 dbesc(datetime_convert()),
477 intval($page_owner_uid)
481 foreach($p as $scales) {
482 if(intval($scales['scale']) == 2) {
486 if(intval($scales['scale']) == 4) {
492 if(count($taginfo)) {
493 foreach($taginfo as $tagged) {
495 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
499 $arr['uid'] = $page_owner_uid;
501 $arr['parent-uri'] = $uri;
502 $arr['type'] = 'activity';
504 $arr['contact-id'] = $owner_record['id'];
505 $arr['owner-name'] = $owner_record['name'];
506 $arr['owner-link'] = $owner_record['url'];
507 $arr['owner-avatar'] = $owner_record['thumb'];
508 $arr['author-name'] = $owner_record['name'];
509 $arr['author-link'] = $owner_record['url'];
510 $arr['author-avatar'] = $owner_record['thumb'];
512 $arr['allow_cid'] = $p[0]['allow_cid'];
513 $arr['allow_gid'] = $p[0]['allow_gid'];
514 $arr['deny_cid'] = $p[0]['deny_cid'];
515 $arr['deny_gid'] = $p[0]['deny_gid'];
516 $arr['last-child'] = 1;
518 $arr['verb'] = ACTIVITY_TAG;
519 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
520 $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
521 $arr['tag'] = $tagged[4];
522 $arr['inform'] = $tagged[2];
524 $arr['body'] = '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]' . ' ' . t('was tagged in a') . ' ' . '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . t('photo') . '[/url]' . ' ' . t('by') . ' ' . '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]' ;
525 $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 . '.jpg' . '[/img][/url]' . "\n" ;
527 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
528 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
530 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $tagged[3]['photo'] . '" />' . "\n");
531 $arr['object'] .= '</link></object>' . "\n";
533 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
534 . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
535 $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="image/jpeg" href="' . $a->get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.jpg' . '" />') . '</link></target>';
537 $item_id = item_store($arr);
539 q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
540 dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
541 intval($page_owner_uid),
545 proc_run('php',"include/notifier.php","tag","$item_id");
552 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
553 return; // NOTREACHED
558 * default post action - upload a photo
561 call_hooks('photo_post_init', $_POST);
564 * Determine the album to use
567 $album = notags(trim($_REQUEST['album']));
568 $newalbum = notags(trim($_REQUEST['newalbum']));
570 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , 'LOGGER_DEBUG');
572 if(! strlen($album)) {
573 if(strlen($newalbum))
576 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
581 * We create a wall item for every photo, but we don't want to
582 * overwhelm the data stream with a hundred newly uploaded photos.
583 * So we will make the first photo uploaded to this album in the last several hours
584 * visible by default, the rest will become visible over time when and if
585 * they acquire comments, likes, dislikes, and/or tags
589 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
591 intval($page_owner_uid)
593 if((! count($r)) || ($album == t('Profile Photos')))
598 if(intval($_REQUEST['not_visible']) || $_REQUEST['not_visible'] === 'true')
601 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
602 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
603 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
604 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
606 $ret = array('src' => '', 'filename' => '', 'filesize' => 0);
608 call_hooks('photo_post_file',$ret);
610 if(x($ret,'src') && x($ret,'filesize')) {
612 $filename = $ret['filename'];
613 $filesize = $ret['filesize'];
616 $src = $_FILES['userfile']['tmp_name'];
617 $filename = basename($_FILES['userfile']['name']);
618 $filesize = intval($_FILES['userfile']['size']);
622 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ' . $filesize . ' bytes', LOGGER_DEBUG);
624 $maximagesize = get_config('system','maximagesize');
626 if(($maximagesize) && ($filesize > $maximagesize)) {
627 notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
630 call_hooks('photo_post_end',$foo);
635 notice( t('Image file is empty.') . EOL);
638 call_hooks('photo_post_end',$foo);
642 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , 'LOGGER_DEBUG');
644 $imagedata = @file_get_contents($src);
645 $ph = new Photo($imagedata);
647 if(! $ph->is_valid()) {
648 logger('mod/photos.php: photos_post(): unable to process image' , 'LOGGER_DEBUG');
649 notice( t('Unable to process image.') . EOL );
652 call_hooks('photo_post_end',$foo);
658 $width = $ph->getWidth();
659 $height = $ph->getHeight();
663 $photo_hash = photo_new_resource();
665 $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);
668 logger('mod/photos.php: photos_post(): image store failed' , 'LOGGER_DEBUG');
669 notice( t('Image upload failed.') . EOL );
673 if($width > 640 || $height > 640) {
674 $ph->scaleImage(640);
675 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
679 if($width > 320 || $height > 320) {
680 $ph->scaleImage(320);
681 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
685 $basename = basename($filename);
686 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
688 // Create item container
692 $arr['uid'] = $page_owner_uid;
694 $arr['parent-uri'] = $uri;
695 $arr['type'] = 'photo';
697 $arr['resource-id'] = $photo_hash;
698 $arr['contact-id'] = $owner_record['id'];
699 $arr['owner-name'] = $owner_record['name'];
700 $arr['owner-link'] = $owner_record['url'];
701 $arr['owner-avatar'] = $owner_record['thumb'];
702 $arr['author-name'] = $owner_record['name'];
703 $arr['author-link'] = $owner_record['url'];
704 $arr['author-avatar'] = $owner_record['thumb'];
706 $arr['allow_cid'] = $str_contact_allow;
707 $arr['allow_gid'] = $str_group_allow;
708 $arr['deny_cid'] = $str_contact_deny;
709 $arr['deny_gid'] = $str_group_deny;
710 $arr['last-child'] = 1;
711 $arr['visible'] = $visible;
714 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
715 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
718 $item_id = item_store($arr);
721 q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
722 dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
723 intval($page_owner_uid),
729 proc_run('php', "include/notifier.php", 'wall-new', $item_id);
731 call_hooks('photo_post_end',intval($item_id));
733 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
734 // if they do not wish to be redirected
736 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
742 function photos_content(&$a) {
746 // photos/name/upload
747 // photos/name/album/xxxxx
748 // photos/name/album/xxxxx/edit
749 // photos/name/image/xxxxx
750 // photos/name/image/xxxxx/edit
753 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
754 notice( t('Public access denied.') . EOL);
759 require_once('include/bbcode.php');
760 require_once('include/security.php');
761 require_once('include/conversation.php');
763 if(! x($a->data,'user')) {
764 notice( t('No photos selected') . EOL );
768 $_SESSION['photo_return'] = $a->cmd;
775 $datatype = $a->argv[2];
776 $datum = $a->argv[3];
778 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
779 $datatype = 'upload';
781 $datatype = 'summary';
789 // Setup permissions structures
795 $remote_contact = false;
797 $owner_uid = $a->data['user']['uid'];
799 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
801 if((local_user()) && (local_user() == $owner_uid))
804 if($community_page && remote_user()) {
805 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
806 intval(remote_user()),
812 $remote_contact = true;
813 $visitor = remote_user();
818 // perhaps they're visiting - but not a community page, so they wouldn't have write access
820 if(remote_user() && (! $visitor)) {
821 $contact_id = $_SESSION['visitor_id'];
822 $groups = init_groups_visitor($contact_id);
823 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
824 intval(remote_user()),
829 $remote_contact = true;
833 if(! $remote_contact) {
835 $contact_id = $_SESSION['cid'];
836 $contact = $a->contact;
840 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
841 notice( t('Access to this item is restricted.') . EOL);
845 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
850 $_is_owner = (local_user() && (local_user() == $owner_uid));
851 $o .= profile_tabs($a,$_is_owner, $a->data['user']['nickname']);
858 if($datatype === 'upload') {
860 notice( t('Permission denied.'));
863 $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
865 $albumselect .= '<option value="" selected="selected" > </option>';
866 if(count($a->data['albums'])) {
867 foreach($a->data['albums'] as $album) {
868 if(($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
870 $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
874 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
876 $albumselect .= '</select>';
880 $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
881 'addon_text' => $uploader,
882 'default_upload' => true);
885 call_hooks('photo_upload_form',$ret);
887 $default_upload = '<input type="file" name="userfile" /> <div class="photos-upload-submit-wrapper" >
888 <input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>';
893 $tpl = get_markup_template('photos_upload.tpl');
894 $o .= replace_macros($tpl,array(
895 '$pagename' => t('Upload Photos'),
896 '$sessid' => session_id(),
897 '$nickname' => $a->data['user']['nickname'],
898 '$newalbum' => t('New album name: '),
899 '$existalbumtext' => t('or existing album name: '),
900 '$nosharetext' => t('Do not show a status post for this upload'),
901 '$albumselect' => template_escape($albumselect),
902 '$permissions' => t('Permissions'),
903 '$aclselect' => (($visitor) ? '' : template_escape(populate_acl($a->user, $celeb))),
904 '$uploader' => $ret['addon_text'],
905 '$default' => (($ret['default_upload']) ? $default_upload : ''),
906 '$uploadurl' => $ret['post_url']
913 if($datatype === 'album') {
915 $album = hex2bin($datum);
917 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
918 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
923 $a->set_pager_total(count($r));
924 $a->set_pager_itemspage(20);
927 $r = q("SELECT `resource-id`, `id`, `filename`, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
928 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
931 intval($a->pager['start']),
932 intval($a->pager['itemspage'])
935 $o .= '<h3>' . $album . '</h3>';
937 if($cmd === 'edit') {
938 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
940 $edit_tpl = get_markup_template('album_edit.tpl');
941 $o .= replace_macros($edit_tpl,array(
942 '$nametext' => t('New album name: '),
943 '$nickname' => $a->data['user']['nickname'],
944 '$album' => template_escape($album),
945 '$hexalbum' => bin2hex($album),
946 '$submit' => t('Submit'),
947 '$dropsubmit' => t('Delete Album')
953 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
955 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
956 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
957 . t('Edit Album') . '</a></div>';
961 $tpl = get_markup_template('photo_album.tpl');
964 $o .= replace_macros($tpl,array(
966 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
967 '$phototitle' => t('View Photo'),
968 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
969 '$imgalt' => template_escape($rr['filename']),
970 '$desc'=> template_escape($rr['desc'])
974 $o .= '<div id="photo-album-end"></div>';
982 if($datatype === 'image') {
987 // fetch image, item containing image, then comments
989 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
990 $sql_extra ORDER BY `scale` ASC ",
996 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1002 notice( t('Permission denied. Access to this item may be restricted.'));
1004 notice( t('Photo not available') . EOL );
1011 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1012 $sql_extra ORDER BY `created` DESC ",
1013 dbesc($ph[0]['album']),
1017 if(count($prvnxt)) {
1018 for($z = 0; $z < count($prvnxt); $z++) {
1019 if($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
1023 $prv = count($prvnxt) - 1;
1024 if($nxt >= count($prvnxt))
1029 $edit_suffix = ((($cmd === 'edit') && ($can_post)) ? '/edit' : '');
1030 $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix;
1031 $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix;
1036 $hires = $lores = $ph[0];
1037 if(count($ph) > 1) {
1038 if($ph[1]['scale'] == 2) {
1039 // original is 640 or less, we can display it directly
1040 $hires = $lores = $ph[0];
1048 $album_link = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1052 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
1054 'edit' => array($a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? t('View photo') : t('Edit photo'))),
1055 'profile'=>array($a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
1059 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1060 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1061 ? t('Private Message')
1068 $prevlink = array($prevlink, '<div class="icon prev"></div>') ;
1071 'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg',
1072 'title'=> t('View Full Size'),
1073 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg'
1077 $nextlink = array($nextlink, '<div class="icon next"></div>');
1080 // Do we have an item for this photo?
1082 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1085 if(count($linked_items)) {
1086 $link_item = $linked_items[0];
1087 $r = q("SELECT COUNT(*) AS `total`
1088 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1089 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
1090 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1091 AND `item`.`uid` = %d
1093 dbesc($link_item['uri']),
1094 dbesc($link_item['uri']),
1095 intval($link_item['uid'])
1100 $a->set_pager_total($r[0]['total']);
1103 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1104 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1105 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1106 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1107 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1108 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
1109 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1110 AND `item`.`uid` = %d
1112 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1113 dbesc($link_item['uri']),
1114 dbesc($link_item['uri']),
1115 intval($link_item['uid']),
1116 intval($a->pager['start']),
1117 intval($a->pager['itemspage'])
1121 if((local_user()) && (local_user() == $link_item['uid'])) {
1122 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1123 intval($link_item['parent']),
1124 intval(local_user())
1131 if(count($linked_items) && strlen($link_item['tag'])) {
1132 $arr = explode(',',$link_item['tag']);
1133 // parse tags and add links
1135 foreach($arr as $t) {
1136 if(strlen($tag_str))
1138 $tag_str .= bbcode($t);
1140 $tags = array(t('Tags: '), $tag_str);
1141 if($cmd === 'edit') {
1142 $tags[] = $a->get_baseurl() . '/tagrm/' . $link_item['id'];
1143 $tags[] = t('[Remove any tag]');
1149 if(($cmd === 'edit') && ($can_post)) {
1150 $edit_tpl = get_markup_template('photo_edit.tpl');
1151 $edit = replace_macros($edit_tpl, array(
1152 '$id' => $ph[0]['id'],
1153 '$album' => template_escape($ph[0]['album']),
1154 '$newalbum' => t('New album name'),
1155 '$nickname' => $a->data['user']['nickname'],
1156 '$resource_id' => $ph[0]['resource-id'],
1157 '$capt_label' => t('Caption'),
1158 '$caption' => template_escape($ph[0]['desc']),
1159 '$tag_label' => t('Add a Tag'),
1160 '$tags' => $link_item['tag'],
1161 '$permissions' => t('Permissions'),
1162 '$aclselect' => template_escape(populate_acl($ph[0])),
1163 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
1164 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1165 '$submit' => t('Submit'),
1166 '$delete' => t('Delete Photo')
1170 if(count($linked_items)) {
1172 $cmnt_tpl = get_markup_template('comment_item.tpl');
1173 $tpl = get_markup_template('photo_item.tpl');
1174 $return_url = $a->cmd;
1176 $like_tpl = get_markup_template('like_noshare.tpl');
1180 if($can_post || can_write_wall($a,$owner_uid)) {
1181 $likebuttons = replace_macros($like_tpl,array(
1182 '$id' => $link_item['id'],
1183 '$likethis' => t("I like this \x28toggle\x29"),
1184 '$nolike' => t("I don't like this \x28toggle\x29"),
1185 '$share' => t('Share'),
1186 '$wait' => t('Please wait')
1192 if($can_post || can_write_wall($a,$owner_uid)) {
1193 if($link_item['last-child']) {
1194 $comments .= replace_macros($cmnt_tpl,array(
1195 '$return_path' => '',
1196 '$jsreload' => $return_url,
1197 '$type' => 'wall-comment',
1198 '$id' => $link_item['id'],
1199 '$parent' => $link_item['id'],
1200 '$profile_uid' => $owner_uid,
1201 '$mylink' => $contact['url'],
1202 '$mytitle' => t('This is you'),
1203 '$myphoto' => $contact['thumb'],
1204 '$comment' => t('Comment'),
1205 '$submit' => t('Submit'),
1221 foreach($r as $item) {
1222 like_puller($a,$item,$alike,'like');
1223 like_puller($a,$item,$dlike,'dislike');
1226 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
1227 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
1231 if($can_post || can_write_wall($a,$owner_uid)) {
1232 if($link_item['last-child']) {
1233 $comments .= replace_macros($cmnt_tpl,array(
1234 '$return_path' => '',
1235 '$jsreload' => $return_url,
1236 '$type' => 'wall-comment',
1237 '$id' => $link_item['id'],
1238 '$parent' => $link_item['id'],
1239 '$profile_uid' => $owner_uid,
1240 '$mylink' => $contact['url'],
1241 '$mytitle' => t('This is you'),
1242 '$myphoto' => $contact['thumb'],
1243 '$comment' => t('Comment'),
1244 '$submit' => t('Submit'),
1251 foreach($r as $item) {
1256 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1259 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1261 if($can_post || can_write_wall($a,$owner_uid)) {
1263 if($item['last-child']) {
1264 $comments .= replace_macros($cmnt_tpl,array(
1265 '$return_path' => '',
1266 '$jsreload' => $return_url,
1267 '$type' => 'wall-comment',
1268 '$id' => $item['item_id'],
1269 '$parent' => $item['parent'],
1270 '$profile_uid' => $owner_uid,
1271 '$mylink' => $contact['url'],
1272 '$mytitle' => t('This is you'),
1273 '$myphoto' => $contact['thumb'],
1274 '$comment' => t('Comment'),
1275 '$submit' => t('Submit'),
1282 if(local_user() && ($item['contact-uid'] == local_user())
1283 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
1284 $profile_url = $redirect_url;
1285 $sparkle = ' sparkle';
1288 $profile_url = $item['url'];
1292 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1294 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1295 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1297 $profile_link = $profile_url;
1301 if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
1302 $drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
1305 $comments .= replace_macros($template,array(
1306 '$id' => $item['item_id'],
1307 '$profile_url' => $profile_link,
1308 '$name' => template_escape($profile_name),
1309 '$thumb' => $profile_avatar,
1310 '$sparkle' => $sparkle,
1311 '$title' => template_escape($item['title']),
1312 '$body' => template_escape(bbcode($item['body'])),
1313 '$ago' => relative_date($item['created']),
1314 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1316 '$comment' => $comment
1321 $paginate = paginate($a);
1324 $photo_tpl = get_markup_template('photo_view.tpl');
1325 $o .= replace_macros($photo_tpl, array(
1326 '$id' => $ph[0]['id'],
1327 '$album' => array($album_link,template_escape($ph[0]['album'])),
1331 '$prevlink' => $prevlink,
1332 '$nextlink' => $nextlink,
1333 '$desc' => $ph[0]['desc'],
1334 '$tags' => template_escape($tags),
1336 '$likebuttons' => $likebuttons,
1337 '$like' => template_escape($like),
1338 '$dislike' => template_escape($dislike),
1339 '$comments' => $comments,
1340 '$paginate' => $paginate,
1346 // Default - show recent photos with upload link (if applicable)
1349 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1350 $sql_extra GROUP BY `resource-id`",
1351 intval($a->data['user']['uid']),
1352 dbesc('Contact Photos'),
1353 dbesc( t('Contact Photos'))
1356 $a->set_pager_total(count($r));
1357 $a->set_pager_itemspage(20);
1360 $r = q("SELECT `resource-id`, `id`, `filename`, `album`, max(`scale`) AS `scale` FROM `photo`
1361 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1362 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1363 intval($a->data['user']['uid']),
1364 dbesc('Contact Photos'),
1365 dbesc( t('Contact Photos')),
1366 intval($a->pager['start']),
1367 intval($a->pager['itemspage'])
1370 $o .= '<h3>' . t('Recent Photos') . '</h3>';
1373 $o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
1374 . $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
1377 $tpl = get_markup_template('photo_top.tpl');
1379 foreach($r as $rr) {
1380 $o .= replace_macros($tpl,array(
1382 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1383 '$phototitle' => t('View Photo'),
1384 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.jpg',
1385 '$albumlink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1386 '$albumname' => template_escape($rr['album']),
1387 '$albumalt' => t('View Album'),
1388 '$imgalt' => template_escape($rr['filename'])
1392 $o .= '<div id="photo-top-end"></div>';