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'] . '</h4>';
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></h4>';
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>';
57 if(! x($a->page,'aside'))
58 $a->page['aside'] = '';
59 $a->page['aside'] .= $o;
62 $a->page['htmlhead'] .= "<script> var ispublic = '" . t('everybody') . "';" ;
64 $a->page['htmlhead'] .= <<< EOT
66 $(document).ready(function() {
68 $('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() {
70 $('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() {
71 selstr = $(this).text();
72 $('#jot-perms-icon').removeClass('unlock').addClass('lock');
73 $('#jot-public').hide();
76 $('#jot-perms-icon').removeClass('lock').addClass('unlock');
77 $('#jot-public').show();
93 function photos_post(&$a) {
95 logger('mod/photos.php: photos_post(): begin' , 'LOGGER_DEBUG');
97 foreach($_REQUEST AS $key => $val) {
98 logger('mod/photos.php: photos_post(): $_REQUEST key: ' . $key . ' val: ' . $val , 'LOGGER_DEBUG');
101 foreach($_FILES AS $key => $val) {
102 logger('mod/photos.php: photos_post(): $_FILES key: ' . $key . ' val: ' . $val , 'LOGGER_DEBUG');
108 $page_owner_uid = $a->data['user']['uid'];
109 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
111 if((local_user()) && (local_user() == $page_owner_uid))
114 if($community_page && remote_user()) {
115 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
116 intval(remote_user()),
117 intval($page_owner_uid)
121 $visitor = remote_user();
127 notice( t('Permission denied.') . EOL );
131 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
132 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
133 intval($page_owner_uid)
137 notice( t('Contact information unavailable') . EOL);
138 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
142 $owner_record = $r[0];
145 if(($a->argc > 3) && ($a->argv[2] === 'album')) {
146 $album = hex2bin($a->argv[3]);
148 if($album === t('Profile Photos') || $album === 'Contact Photos' || $album === t('Contact Photos')) {
149 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
150 return; // NOTREACHED
153 $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
155 intval($page_owner_uid)
158 notice( t('Album not found.') . EOL);
159 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
160 return; // NOTREACHED
163 $newalbum = notags(trim($_POST['albumname']));
164 if($newalbum != $album) {
165 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
168 intval($page_owner_uid)
170 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
171 goaway($a->get_baseurl() . '/' . $newurl);
172 return; // NOTREACHED
176 if($_POST['dropalbum'] == t('Delete Album')) {
180 // get the list of photos we are about to delete
183 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
185 intval($page_owner_uid),
190 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
191 intval(local_user()),
197 $res[] = "'" . dbesc($rr['rid']) . "'" ;
201 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
202 return; // NOTREACHED
205 $str_res = implode(',', $res);
207 // remove the associated photos
209 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
210 intval($page_owner_uid)
213 // find and delete the corresponding item with all the comments and likes/dislikes
215 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
216 intval($page_owner_uid)
220 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
221 dbesc(datetime_convert()),
222 dbesc($rr['parent-uri']),
223 intval($page_owner_uid)
226 $drop_id = intval($rr['id']);
228 // send the notification upstream/downstream as the case may be
231 proc_run('php',"include/notifier.php","drop","$drop_id");
235 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
236 return; // NOTREACHED
239 if(($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
241 // same as above but remove single photo
244 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
246 intval($page_owner_uid),
251 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
252 intval(local_user()),
257 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
258 intval($page_owner_uid),
259 dbesc($r[0]['resource-id'])
261 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
262 dbesc($r[0]['resource-id']),
263 intval($page_owner_uid)
266 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
267 dbesc(datetime_convert()),
268 dbesc(datetime_convert()),
270 intval($page_owner_uid)
273 $url = $a->get_baseurl();
274 $drop_id = intval($i[0]['id']);
277 proc_run('php',"include/notifier.php","drop","$drop_id");
281 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
282 return; // NOTREACHED
285 if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
287 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
288 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
289 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
290 $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
291 $str_group_allow = perms2str($_POST['group_allow']);
292 $str_contact_allow = perms2str($_POST['contact_allow']);
293 $str_group_deny = perms2str($_POST['group_deny']);
294 $str_contact_deny = perms2str($_POST['contact_deny']);
296 $resource_id = $a->argv[2];
298 if(! strlen($albname))
299 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
302 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
304 intval($page_owner_uid)
307 $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",
310 dbesc($str_contact_allow),
311 dbesc($str_group_allow),
312 dbesc($str_contact_deny),
313 dbesc($str_group_deny),
315 intval($page_owner_uid)
319 /* Don't make the item visible if the only change was the album name */
322 if($p[0]['desc'] !== $desc || strlen($rawtags))
327 // Create item container
330 $basename = basename($filename);
331 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
335 $arr['uid'] = $page_owner_uid;
337 $arr['parent-uri'] = $uri;
338 $arr['type'] = 'photo';
340 $arr['resource-id'] = $p[0]['resource-id'];
341 $arr['contact-id'] = $owner_record['id'];
342 $arr['owner-name'] = $owner_record['name'];
343 $arr['owner-link'] = $owner_record['url'];
344 $arr['owner-avatar'] = $owner_record['thumb'];
345 $arr['author-name'] = $owner_record['name'];
346 $arr['author-link'] = $owner_record['url'];
347 $arr['author-avatar'] = $owner_record['thumb'];
348 $arr['title'] = $title;
349 $arr['allow_cid'] = $p[0]['allow_cid'];
350 $arr['allow_gid'] = $p[0]['allow_gid'];
351 $arr['deny_cid'] = $p[0]['deny_cid'];
352 $arr['deny_gid'] = $p[0]['deny_gid'];
353 $arr['last-child'] = 1;
354 $arr['visible'] = $visibility;
356 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
357 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]'
360 $item_id = item_store($arr);
365 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
367 intval($page_owner_uid)
371 $old_tag = $r[0]['tag'];
372 $old_inform = $r[0]['inform'];
375 if(strlen($rawtags)) {
380 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
382 $x = substr($rawtags,0,1);
383 if($x !== '@' && $x !== '#')
384 $rawtags = '#' . $rawtags;
387 $tags = get_tags($rawtags);
390 foreach($tags as $tag) {
393 if(strpos($tag,'@') === 0) {
394 $name = substr($tag,1);
395 if((strpos($name,'@')) || (strpos($name,'http://'))) {
397 $links = @lrdd($name);
399 foreach($links as $link) {
400 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
401 $profile = $link['@attributes']['href'];
402 if($link['@attributes']['rel'] === 'salmon') {
403 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
410 $taginfo[] = array($newname,$profile,$salmon);
414 if(strstr($name,'_') || strstr($name,' ')) {
415 $newname = str_replace('_',' ',$name);
416 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
418 intval($page_owner_uid)
422 $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
425 intval($page_owner_uid)
429 $newname = $r[0]['name'];
430 $profile = $r[0]['url'];
431 $notify = 'cid:' . $r[0]['id'];
438 if(substr($notify,0,4) === 'cid:')
439 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
441 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
442 if(strlen($str_tags))
444 $profile = str_replace(',','%2c',$profile);
445 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
452 if(strlen($newtag) && strlen($str_tags))
454 $newtag .= $str_tags;
456 $newinform = $old_inform;
457 if(strlen($newinform) && strlen($inform))
459 $newinform .= $inform;
461 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
464 dbesc(datetime_convert()),
465 dbesc(datetime_convert()),
467 intval($page_owner_uid)
471 foreach($p as $scales) {
472 if(intval($scales['scale']) == 2) {
476 if(intval($scales['scale']) == 4) {
482 if(count($taginfo)) {
483 foreach($taginfo as $tagged) {
485 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
489 $arr['uid'] = $page_owner_uid;
491 $arr['parent-uri'] = $uri;
492 $arr['type'] = 'activity';
494 $arr['contact-id'] = $owner_record['id'];
495 $arr['owner-name'] = $owner_record['name'];
496 $arr['owner-link'] = $owner_record['url'];
497 $arr['owner-avatar'] = $owner_record['thumb'];
498 $arr['author-name'] = $owner_record['name'];
499 $arr['author-link'] = $owner_record['url'];
500 $arr['author-avatar'] = $owner_record['thumb'];
502 $arr['allow_cid'] = $p[0]['allow_cid'];
503 $arr['allow_gid'] = $p[0]['allow_gid'];
504 $arr['deny_cid'] = $p[0]['deny_cid'];
505 $arr['deny_gid'] = $p[0]['deny_gid'];
506 $arr['last-child'] = 1;
508 $arr['verb'] = ACTIVITY_TAG;
509 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
510 $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
511 $arr['tag'] = $tagged[4];
512 $arr['inform'] = $tagged[2];
514 $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]' ;
515 $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" ;
517 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
518 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
520 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $tagged[3]['photo'] . '" />' . "\n");
521 $arr['object'] .= '</link></object>' . "\n";
523 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
524 . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
525 $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>';
527 $item_id = item_store($arr);
529 q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
530 dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
531 intval($page_owner_uid),
535 proc_run('php',"include/notifier.php","tag","$item_id");
542 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
543 return; // NOTREACHED
548 * default post action - upload a photo
551 call_hooks('photo_post_init', $_POST);
554 * Determine the album to use
557 $album = notags(trim($_REQUEST['album']));
558 $newalbum = notags(trim($_REQUEST['newalbum']));
560 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , 'LOGGER_DEBUG');
562 if(! strlen($album)) {
563 if(strlen($newalbum))
566 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
571 * We create a wall item for every photo, but we don't want to
572 * overwhelm the data stream with a hundred newly uploaded photos.
573 * So we will make the first photo uploaded to this album in the last several hours
574 * visible by default, the rest will become visible over time when and if
575 * they acquire comments, likes, dislikes, and/or tags
579 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
581 intval($page_owner_uid)
583 if((! count($r)) || ($album == t('Profile Photos')))
588 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
589 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
590 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
591 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
593 $ret = array('src' => '', 'filename' => '', 'filesize' => 0);
595 call_hooks('photo_post_file',$ret);
597 if(x($ret,'src') && x($ret,'filesize')) {
599 $filename = $ret['filename'];
600 $filesize = $ret['filesize'];
603 $src = $_FILES['userfile']['tmp_name'];
604 $filename = basename($_FILES['userfile']['name']);
605 $filesize = intval($_FILES['userfile']['size']);
609 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ' . $filesize . ' bytes', LOGGER_DEBUG);
611 $maximagesize = get_config('system','maximagesize');
613 if(($maximagesize) && ($filesize > $maximagesize)) {
614 notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
617 call_hooks('photo_post_end',$foo);
622 notice( t('Image file is empty.') . EOL);
625 call_hooks('photo_post_end',$foo);
629 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , 'LOGGER_DEBUG');
631 $imagedata = @file_get_contents($src);
632 $ph = new Photo($imagedata);
634 if(! $ph->is_valid()) {
635 logger('mod/photos.php: photos_post(): unable to process image' , 'LOGGER_DEBUG');
636 notice( t('Unable to process image.') . EOL );
639 call_hooks('photo_post_end',$foo);
645 $width = $ph->getWidth();
646 $height = $ph->getHeight();
650 $photo_hash = photo_new_resource();
652 $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);
655 logger('mod/photos.php: photos_post(): image store failed' , 'LOGGER_DEBUG');
656 notice( t('Image upload failed.') . EOL );
660 if($width > 640 || $height > 640) {
661 $ph->scaleImage(640);
662 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
666 if($width > 320 || $height > 320) {
667 $ph->scaleImage(320);
668 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
672 $basename = basename($filename);
673 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
675 // Create item container
679 $arr['uid'] = $page_owner_uid;
681 $arr['parent-uri'] = $uri;
682 $arr['type'] = 'photo';
684 $arr['resource-id'] = $photo_hash;
685 $arr['contact-id'] = $owner_record['id'];
686 $arr['owner-name'] = $owner_record['name'];
687 $arr['owner-link'] = $owner_record['url'];
688 $arr['owner-avatar'] = $owner_record['thumb'];
689 $arr['author-name'] = $owner_record['name'];
690 $arr['author-link'] = $owner_record['url'];
691 $arr['author-avatar'] = $owner_record['thumb'];
693 $arr['allow_cid'] = $str_contact_allow;
694 $arr['allow_gid'] = $str_group_allow;
695 $arr['deny_cid'] = $str_contact_deny;
696 $arr['deny_gid'] = $str_group_deny;
697 $arr['last-child'] = 1;
698 $arr['visible'] = $visible;
699 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
700 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
703 $item_id = item_store($arr);
706 q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
707 dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
708 intval($page_owner_uid),
714 proc_run('php', "include/notifier.php", 'wall-new', $item_id);
716 call_hooks('photo_post_end',intval($item_id));
718 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
719 // if they do not wish to be redirected
721 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
727 function photos_content(&$a) {
731 // photos/name/upload
732 // photos/name/album/xxxxx
733 // photos/name/album/xxxxx/edit
734 // photos/name/image/xxxxx
735 // photos/name/image/xxxxx/edit
738 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
739 notice( t('Public access denied.') . EOL);
744 require_once('include/bbcode.php');
745 require_once('include/security.php');
746 require_once('include/conversation.php');
748 if(! x($a->data,'user')) {
749 notice( t('No photos selected') . EOL );
753 $_SESSION['photo_return'] = $a->cmd;
760 $datatype = $a->argv[2];
761 $datum = $a->argv[3];
763 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
764 $datatype = 'upload';
766 $datatype = 'summary';
774 // Setup permissions structures
780 $remote_contact = false;
782 $owner_uid = $a->data['user']['uid'];
784 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
786 if((local_user()) && (local_user() == $owner_uid))
789 if($community_page && remote_user()) {
790 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
791 intval(remote_user()),
797 $remote_contact = true;
798 $visitor = remote_user();
803 // perhaps they're visiting - but not a community page, so they wouldn't have write access
805 if(remote_user() && (! $visitor)) {
806 $contact_id = $_SESSION['visitor_id'];
807 $groups = init_groups_visitor($contact_id);
808 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
809 intval(remote_user()),
814 $remote_contact = true;
818 if(! $remote_contact) {
820 $contact_id = $_SESSION['cid'];
821 $contact = $a->contact;
825 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
826 notice( t('Access to this item is restricted.') . EOL);
830 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
835 $tpl = get_markup_template('profile_tabs.tpl');
836 $_is_owner = (local_user() && (local_user() == $owner_uid));
837 $o .= replace_macros($tpl,array(
838 '$url' => $a->get_baseurl() . '/profile/' .$a->data['user']['nickname'],
839 '$phototab' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
840 '$status' => t('Status'),
841 '$profile' => t('Profile'),
842 '$photos' => t('Photos'),
843 '$events' => (($_is_owner) ? t('Events') : ''),
844 '$notes' => (($_is_owner) ? t('Personal Notes') : ''),
845 '$activetab' => "photos",
853 if($datatype === 'upload') {
855 notice( t('Permission denied.'));
858 $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
860 $albumselect .= '<option value="" selected="selected" > </option>';
861 if(count($a->data['albums'])) {
862 foreach($a->data['albums'] as $album) {
863 if(($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
865 $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
869 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
871 $albumselect .= '</select>';
875 $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
876 'addon_text' => $uploader,
877 'default_upload' => true);
880 call_hooks('photo_upload_form',$ret);
882 $default_upload = '<input type="file" name="userfile" /> <div class="photos-upload-submit-wrapper" >
883 <input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>';
888 $tpl = get_markup_template('photos_upload.tpl');
889 $o .= replace_macros($tpl,array(
890 '$pagename' => t('Upload Photos'),
891 '$sessid' => session_id(),
892 '$nickname' => $a->data['user']['nickname'],
893 '$newalbum' => t('New album name: '),
894 '$existalbumtext' => t('or existing album name: '),
895 '$albumselect' => template_escape($albumselect),
896 '$permissions' => t('Permissions'),
897 '$aclselect' => (($visitor) ? '' : template_escape(populate_acl($a->user, $celeb))),
898 '$uploader' => $ret['addon_text'],
899 '$default' => (($ret['default_upload']) ? $default_upload : ''),
900 '$uploadurl' => $ret['post_url']
907 if($datatype === 'album') {
909 $album = hex2bin($datum);
911 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
912 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
917 $a->set_pager_total(count($r));
918 $a->set_pager_itemspage(20);
921 $r = q("SELECT `resource-id`, `id`, `filename`, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
922 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
925 intval($a->pager['start']),
926 intval($a->pager['itemspage'])
929 $o .= '<h3>' . $album . '</h3>';
931 if($cmd === 'edit') {
932 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
934 $edit_tpl = get_markup_template('album_edit.tpl');
935 $o .= replace_macros($edit_tpl,array(
936 '$nametext' => t('New album name: '),
937 '$nickname' => $a->data['user']['nickname'],
938 '$album' => template_escape($album),
939 '$hexalbum' => bin2hex($album),
940 '$submit' => t('Submit'),
941 '$dropsubmit' => t('Delete Album')
947 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
949 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
950 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
951 . t('Edit Album') . '</a></div>';
955 $tpl = get_markup_template('photo_album.tpl');
958 $o .= replace_macros($tpl,array(
960 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
961 '$phototitle' => t('View Photo'),
962 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
963 '$imgalt' => template_escape($rr['filename']),
964 '$desc'=> template_escape($rr['desc'])
968 $o .= '<div id="photo-album-end"></div>';
976 if($datatype === 'image') {
981 // fetch image, item containing image, then comments
983 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
984 $sql_extra ORDER BY `scale` ASC ",
990 $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
996 notice( t('Permission denied. Access to this item may be restricted.'));
998 notice( t('Photo not available') . EOL );
1005 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1006 $sql_extra ORDER BY `created` DESC ",
1007 dbesc($ph[0]['album']),
1011 if(count($prvnxt)) {
1012 for($z = 0; $z < count($prvnxt); $z++) {
1013 if($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
1017 $prv = count($prvnxt) - 1;
1018 if($nxt >= count($prvnxt))
1023 $edit_suffix = ((($cmd === 'edit') && ($can_post)) ? '/edit' : '');
1024 $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix;
1025 $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix;
1030 $hires = $lores = $ph[0];
1031 if(count($ph) > 1) {
1032 if($ph[1]['scale'] == 2) {
1033 // original is 640 or less, we can display it directly
1034 $hires = $lores = $ph[0];
1042 $album_link = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1046 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
1048 'edit' => array($a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? t('View photo') : t('Edit photo'))),
1049 'profile'=>array($a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
1053 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1054 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1055 ? t('Private Message')
1062 $prevlink = array($prevlink, '<div class="icon prev"></div>') ;
1065 'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg',
1066 'title'=> t('View Full Size'),
1067 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg'
1071 $nextlink = array($nextlink, '<div class="icon next"></div>');
1074 // Do we have an item for this photo?
1076 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1079 if(count($linked_items)) {
1080 $link_item = $linked_items[0];
1081 $r = q("SELECT COUNT(*) AS `total`
1082 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1083 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
1084 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1085 AND `item`.`uid` = %d
1087 dbesc($link_item['uri']),
1088 dbesc($link_item['uri']),
1089 intval($link_item['uid'])
1094 $a->set_pager_total($r[0]['total']);
1097 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1098 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1099 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1100 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1101 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1102 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
1103 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1104 AND `item`.`uid` = %d
1106 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1107 dbesc($link_item['uri']),
1108 dbesc($link_item['uri']),
1109 intval($link_item['uid']),
1110 intval($a->pager['start']),
1111 intval($a->pager['itemspage'])
1115 if((local_user()) && (local_user() == $link_item['uid'])) {
1116 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1117 intval($link_item['parent']),
1118 intval(local_user())
1125 if(count($linked_items) && strlen($link_item['tag'])) {
1126 $arr = explode(',',$link_item['tag']);
1127 // parse tags and add links
1129 foreach($arr as $t) {
1130 if(strlen($tag_str))
1132 $tag_str .= bbcode($t);
1134 $tags = array(t('Tags: '), $tag_str);
1135 if($cmd === 'edit') {
1136 $tags[] = $a->get_baseurl() . '/tagrm/' . $link_item['id'];
1137 $tags[] = t('[Remove any tag]');
1143 if(($cmd === 'edit') && ($can_post)) {
1144 $edit_tpl = get_markup_template('photo_edit.tpl');
1145 $edit = replace_macros($edit_tpl, array(
1146 '$id' => $ph[0]['id'],
1147 '$album' => template_escape($ph[0]['album']),
1148 '$newalbum' => t('New album name'),
1149 '$nickname' => $a->data['user']['nickname'],
1150 '$resource_id' => $ph[0]['resource-id'],
1151 '$capt_label' => t('Caption'),
1152 '$caption' => template_escape($ph[0]['desc']),
1153 '$tag_label' => t('Add a Tag'),
1154 '$tags' => $link_item['tag'],
1155 '$permissions' => t('Permissions'),
1156 '$aclselect' => template_escape(populate_acl($ph[0])),
1157 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
1158 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1159 '$submit' => t('Submit'),
1160 '$delete' => t('Delete Photo')
1164 if(count($linked_items)) {
1166 $cmnt_tpl = get_markup_template('comment_item.tpl');
1167 $tpl = get_markup_template('photo_item.tpl');
1168 $return_url = $a->cmd;
1170 $like_tpl = get_markup_template('like_noshare.tpl');
1174 if($can_post || can_write_wall($a,$owner_uid)) {
1175 $likebuttons = replace_macros($like_tpl,array(
1176 '$id' => $link_item['id'],
1177 '$likethis' => t("I like this \x28toggle\x29"),
1178 '$nolike' => t("I don't like this \x28toggle\x29"),
1179 '$share' => t('Share'),
1180 '$wait' => t('Please wait')
1186 if($can_post || can_write_wall($a,$owner_uid)) {
1187 if($link_item['last-child']) {
1188 $comments .= replace_macros($cmnt_tpl,array(
1189 '$return_path' => '',
1190 '$jsreload' => $return_url,
1191 '$type' => 'wall-comment',
1192 '$id' => $link_item['id'],
1193 '$parent' => $link_item['id'],
1194 '$profile_uid' => $owner_uid,
1195 '$mylink' => $contact['url'],
1196 '$mytitle' => t('This is you'),
1197 '$myphoto' => $contact['thumb'],
1198 '$comment' => t('Comment'),
1199 '$submit' => t('Submit'),
1215 foreach($r as $item) {
1216 like_puller($a,$item,$alike,'like');
1217 like_puller($a,$item,$dlike,'dislike');
1220 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
1221 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
1225 if($can_post || can_write_wall($a,$owner_uid)) {
1226 if($link_item['last-child']) {
1227 $comments .= replace_macros($cmnt_tpl,array(
1228 '$return_path' => '',
1229 '$jsreload' => $return_url,
1230 '$type' => 'wall-comment',
1231 '$id' => $link_item['id'],
1232 '$parent' => $link_item['id'],
1233 '$profile_uid' => $owner_uid,
1234 '$mylink' => $contact['url'],
1235 '$mytitle' => t('This is you'),
1236 '$myphoto' => $contact['thumb'],
1237 '$comment' => t('Comment'),
1238 '$submit' => t('Submit'),
1245 foreach($r as $item) {
1250 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1253 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1255 if($can_post || can_write_wall($a,$owner_uid)) {
1257 if($item['last-child']) {
1258 $comments .= replace_macros($cmnt_tpl,array(
1259 '$return_path' => '',
1260 '$jsreload' => $return_url,
1261 '$type' => 'wall-comment',
1262 '$id' => $item['item_id'],
1263 '$parent' => $item['parent'],
1264 '$profile_uid' => $owner_uid,
1265 '$mylink' => $contact['url'],
1266 '$mytitle' => t('This is you'),
1267 '$myphoto' => $contact['thumb'],
1268 '$comment' => t('Comment'),
1269 '$submit' => t('Submit'),
1276 if(local_user() && ($item['contact-uid'] == local_user())
1277 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
1278 $profile_url = $redirect_url;
1279 $sparkle = ' sparkle';
1282 $profile_url = $item['url'];
1286 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1288 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1289 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1291 $profile_link = $profile_url;
1295 if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
1296 $drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
1299 $comments .= replace_macros($template,array(
1300 '$id' => $item['item_id'],
1301 '$profile_url' => $profile_link,
1302 '$name' => template_escape($profile_name),
1303 '$thumb' => $profile_avatar,
1304 '$sparkle' => $sparkle,
1305 '$title' => template_escape($item['title']),
1306 '$body' => template_escape(bbcode($item['body'])),
1307 '$ago' => relative_date($item['created']),
1308 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1310 '$comment' => $comment
1315 $paginate = paginate($a);
1318 $photo_tpl = get_markup_template('photo_view.tpl');
1319 $o .= replace_macros($photo_tpl, array(
1320 '$id' => $ph[0]['id'],
1321 '$album' => array($album_link,template_escape($ph[0]['album'])),
1325 '$prevlink' => $prevlink,
1326 '$nextlink' => $nextlink,
1327 '$desc' => $ph[0]['desc'],
1328 '$tags' => template_escape($tags),
1330 '$likebuttons' => $likebuttons,
1331 '$like' => template_escape($like),
1332 '$dislike' => template_escape($dislike),
1333 '$comments' => $comments,
1334 '$paginate' => $paginate,
1340 // Default - show recent photos with upload link (if applicable)
1343 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1344 $sql_extra GROUP BY `resource-id`",
1345 intval($a->data['user']['uid']),
1346 dbesc('Contact Photos'),
1347 dbesc( t('Contact Photos'))
1350 $a->set_pager_total(count($r));
1351 $a->set_pager_itemspage(20);
1354 $r = q("SELECT `resource-id`, `id`, `filename`, `album`, max(`scale`) AS `scale` FROM `photo`
1355 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1356 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1357 intval($a->data['user']['uid']),
1358 dbesc('Contact Photos'),
1359 dbesc( t('Contact Photos')),
1360 intval($a->pager['start']),
1361 intval($a->pager['itemspage'])
1364 $o .= '<h3>' . t('Recent Photos') . '</h3>';
1367 $o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
1368 . $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
1371 $tpl = get_markup_template('photo_top.tpl');
1373 foreach($r as $rr) {
1374 $o .= replace_macros($tpl,array(
1376 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1377 '$phototitle' => t('View Photo'),
1378 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.jpg',
1379 '$albumlink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1380 '$albumname' => template_escape($rr['album']),
1381 '$albumalt' => t('View Album'),
1382 '$imgalt' => template_escape($rr['filename'])
1386 $o .= '<div id="photo-top-end"></div>';