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');
7 function photos_init(&$a) {
10 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
17 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
24 $a->data['user'] = $r[0];
26 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d",
27 intval($a->data['user']['uid'])
31 $a->data['albums'] = $albums;
33 $o .= '<h4><a href="' . $a->get_baseurl() . '/profile/' . $a->data['user']['nickname'] . '">' . $a->data['user']['username'] . '</a></h4>';
34 $o .= '<h4>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h4>';
37 foreach($albums as $album) {
38 if((! strlen($album['album'])) || ($album['album'] == t('Contact Photos')))
40 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" />' . $album['album'] . '</a></li>';
45 if(! x($a->page,'aside'))
46 $a->page['aside'] = '';
47 $a->page['aside'] .= $o;
50 $a->page['htmlhead'] .= "<script> var ispublic = '" . t('everybody') . "';" ;
52 $a->page['htmlhead'] .= <<< EOT
54 $(document).ready(function() {
56 $('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() {
58 $('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() {
59 selstr = $(this).text();
60 $('#jot-perms-icon').removeClass('unlock').addClass('lock');
61 $('#jot-public').hide();
64 $('#jot-perms-icon').removeClass('lock').addClass('unlock');
65 $('#jot-public').show();
81 function photos_post(&$a) {
83 logger('mod/photos.php: photos_post(): begin' , 'LOGGER_DEBUG');
85 foreach($_REQUEST AS $key => $val) {
86 logger('mod/photos.php: photos_post(): $_REQUEST key: ' . $key . ' val: ' . $val , 'LOGGER_DEBUG');
89 foreach($_FILES AS $key => $val) {
90 logger('mod/photos.php: photos_post(): $_FILES key: ' . $key . ' val: ' . $val , 'LOGGER_DEBUG');
96 $page_owner_uid = $a->data['user']['uid'];
97 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
99 if((local_user()) && (local_user() == $page_owner_uid))
102 if($community_page && remote_user()) {
103 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
104 intval(remote_user()),
105 intval($page_owner_uid)
109 $visitor = remote_user();
115 notice( t('Permission denied.') . EOL );
119 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
120 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
121 intval($page_owner_uid)
125 notice( t('Contact information unavailable') . EOL);
126 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
130 $owner_record = $r[0];
133 if(($a->argc > 3) && ($a->argv[2] === 'album')) {
134 $album = hex2bin($a->argv[3]);
136 if($album == t('Profile Photos') || $album == t('Contact Photos')) {
137 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
138 return; // NOTREACHED
141 $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
143 intval($page_owner_uid)
146 notice( t('Album not found.') . EOL);
147 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
148 return; // NOTREACHED
151 $newalbum = notags(trim($_POST['albumname']));
152 if($newalbum != $album) {
153 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
156 intval($page_owner_uid)
158 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
159 goaway($a->get_baseurl() . '/' . $newurl);
160 return; // NOTREACHED
164 if($_POST['dropalbum'] == t('Delete Album')) {
168 // get the list of photos we are about to delete
171 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
173 intval($page_owner_uid),
178 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
179 intval(local_user()),
185 $res[] = "'" . dbesc($rr['rid']) . "'" ;
189 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
190 return; // NOTREACHED
193 $str_res = implode(',', $res);
195 // remove the associated photos
197 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
198 intval($page_owner_uid)
201 // find and delete the corresponding item with all the comments and likes/dislikes
203 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
204 intval($page_owner_uid)
208 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
209 dbesc(datetime_convert()),
210 dbesc($rr['parent-uri']),
211 intval($page_owner_uid)
214 $drop_id = intval($rr['id']);
216 // send the notification upstream/downstream as the case may be
219 proc_run('php',"include/notifier.php","drop","$drop_id");
223 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
224 return; // NOTREACHED
227 if(($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
229 // same as above but remove single photo
232 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
234 intval($page_owner_uid),
239 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
240 intval(local_user()),
245 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
246 intval($page_owner_uid),
247 dbesc($r[0]['resource-id'])
249 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
250 dbesc($r[0]['resource-id']),
251 intval($page_owner_uid)
254 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
255 dbesc(datetime_convert()),
256 dbesc(datetime_convert()),
258 intval($page_owner_uid)
261 $url = $a->get_baseurl();
262 $drop_id = intval($i[0]['id']);
265 proc_run('php',"include/notifier.php","drop","$drop_id");
269 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
270 return; // NOTREACHED
273 if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
275 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
276 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
277 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
278 $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
279 $str_group_allow = perms2str($_POST['group_allow']);
280 $str_contact_allow = perms2str($_POST['contact_allow']);
281 $str_group_deny = perms2str($_POST['group_deny']);
282 $str_contact_deny = perms2str($_POST['contact_deny']);
284 $resource_id = $a->argv[2];
286 if(! strlen($albname))
287 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
290 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
292 intval($page_owner_uid)
295 $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",
298 dbesc($str_contact_allow),
299 dbesc($str_group_allow),
300 dbesc($str_contact_deny),
301 dbesc($str_group_deny),
303 intval($page_owner_uid)
307 /* Don't make the item visible if the only change was the album name */
310 if($p[0]['desc'] !== $desc || strlen($rawtags))
315 // Create item container
318 $basename = basename($filename);
319 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
323 $arr['uid'] = $page_owner_uid;
325 $arr['parent-uri'] = $uri;
326 $arr['type'] = 'photo';
328 $arr['resource-id'] = $p[0]['resource-id'];
329 $arr['contact-id'] = $owner_record['id'];
330 $arr['owner-name'] = $owner_record['name'];
331 $arr['owner-link'] = $owner_record['url'];
332 $arr['owner-avatar'] = $owner_record['thumb'];
333 $arr['author-name'] = $owner_record['name'];
334 $arr['author-link'] = $owner_record['url'];
335 $arr['author-avatar'] = $owner_record['thumb'];
336 $arr['title'] = $title;
337 $arr['allow_cid'] = $p[0]['allow_cid'];
338 $arr['allow_gid'] = $p[0]['allow_gid'];
339 $arr['deny_cid'] = $p[0]['deny_cid'];
340 $arr['deny_gid'] = $p[0]['deny_gid'];
341 $arr['last-child'] = 1;
342 $arr['visible'] = $visibility;
344 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
345 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]'
348 $item_id = item_store($arr);
353 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
355 intval($page_owner_uid)
359 $old_tag = $r[0]['tag'];
360 $old_inform = $r[0]['inform'];
363 if(strlen($rawtags)) {
368 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
370 $x = substr($rawtags,0,1);
371 if($x !== '@' && $x !== '#')
372 $rawtags = '#' . $rawtags;
375 $tags = get_tags($rawtags);
378 foreach($tags as $tag) {
379 if(strpos($tag,'@') === 0) {
380 $name = substr($tag,1);
381 if((strpos($name,'@')) || (strpos($name,'http://'))) {
383 $links = @lrdd($name);
385 foreach($links as $link) {
386 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
387 $profile = $link['@attributes']['href'];
388 if($link['@attributes']['rel'] === 'salmon') {
389 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
396 $taginfo[] = array($newname,$profile,$salmon);
400 if(strstr($name,'_')) {
401 $newname = str_replace('_',' ',$name);
402 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
404 intval($page_owner_uid)
408 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
410 intval($page_owner_uid)
414 $newname = $r[0]['name'];
415 $profile = $r[0]['url'];
416 $notify = 'cid:' . $r[0]['id'];
423 if(substr($notify,0,4) === 'cid:')
424 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
426 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
427 if(strlen($str_tags))
429 $profile = str_replace(',','%2c',$profile);
430 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
437 if(strlen($newtag) && strlen($str_tags))
439 $newtag .= $str_tags;
441 $newinform = $old_inform;
442 if(strlen($newinform) && strlen($inform))
444 $newinform .= $inform;
446 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
449 dbesc(datetime_convert()),
450 dbesc(datetime_convert()),
452 intval($page_owner_uid)
456 foreach($p as $scales) {
457 if(intval($scales['scale']) == 2) {
461 if(intval($scales['scale']) == 4) {
467 if(count($taginfo)) {
468 foreach($taginfo as $tagged) {
470 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
474 $arr['uid'] = $page_owner_uid;
476 $arr['parent-uri'] = $uri;
477 $arr['type'] = 'activity';
479 $arr['contact-id'] = $owner_record['id'];
480 $arr['owner-name'] = $owner_record['name'];
481 $arr['owner-link'] = $owner_record['url'];
482 $arr['owner-avatar'] = $owner_record['thumb'];
483 $arr['author-name'] = $owner_record['name'];
484 $arr['author-link'] = $owner_record['url'];
485 $arr['author-avatar'] = $owner_record['thumb'];
487 $arr['allow_cid'] = $p[0]['allow_cid'];
488 $arr['allow_gid'] = $p[0]['allow_gid'];
489 $arr['deny_cid'] = $p[0]['deny_cid'];
490 $arr['deny_gid'] = $p[0]['deny_gid'];
491 $arr['last-child'] = 1;
493 $arr['verb'] = ACTIVITY_TAG;
494 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
495 $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
496 $arr['tag'] = $tagged[4];
497 $arr['inform'] = $tagged[2];
499 $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]' ;
500 $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" ;
502 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
503 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
505 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $tagged[3]['photo'] . '" />' . "\n");
506 $arr['object'] .= '</link></object>' . "\n";
508 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
509 . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
510 $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>';
512 $item_id = item_store($arr);
514 proc_run('php',"include/notifier.php","tag","$item_id");
520 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
521 return; // NOTREACHED
526 * default post action - upload a photo
529 call_hooks('photo_post_init', $_POST);
532 * Determine the album to use
535 $album = notags(trim($_REQUEST['album']));
536 $newalbum = notags(trim($_REQUEST['newalbum']));
538 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , 'LOGGER_DEBUG');
540 if(! strlen($album)) {
541 if(strlen($newalbum))
544 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
549 * We create a wall item for every photo, but we don't want to
550 * overwhelm the data stream with a hundred newly uploaded photos.
551 * So we will make one photo (the first one uploaded to this album)
552 * visible by default, the rest will become visible over time when and if
553 * they acquire comments, likes, dislikes, and/or tags
557 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
559 intval($page_owner_uid)
561 if((! count($r)) || ($album == t('Profile Photos')))
566 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
567 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
568 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
569 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
571 $ret = array('src' => '', 'filename' => '', 'filesize' => 0);
573 call_hooks('photo_post_file',$ret);
575 if(x($ret,'src') && x($ret,'filesize')) {
577 $filename = $ret['filename'];
578 $filesize = $ret['filesize'];
581 $src = $_FILES['userfile']['tmp_name'];
582 $filename = basename($_FILES['userfile']['name']);
583 $filesize = intval($_FILES['userfile']['size']);
586 $maximagesize = get_config('system','maximagesize');
588 if(($maximagesize) && ($filesize > $maximagesize)) {
589 notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
592 call_hooks('photo_post_end',$foo);
596 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , 'LOGGER_DEBUG');
598 $imagedata = @file_get_contents($src);
599 $ph = new Photo($imagedata);
601 if(! $ph->is_valid()) {
602 logger('mod/photos.php: photos_post(): unable to process image' , 'LOGGER_DEBUG');
603 notice( t('Unable to process image.') . EOL );
606 call_hooks('photo_post_end',$foo);
612 $width = $ph->getWidth();
613 $height = $ph->getHeight();
617 $photo_hash = photo_new_resource();
619 $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);
622 logger('mod/photos.php: photos_post(): image store failed' , 'LOGGER_DEBUG');
623 notice( t('Image upload failed.') . EOL );
627 if($width > 640 || $height > 640) {
628 $ph->scaleImage(640);
629 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
633 if($width > 320 || $height > 320) {
634 $ph->scaleImage(320);
635 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
639 $basename = basename($filename);
640 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
642 // Create item container
646 $arr['uid'] = $page_owner_uid;
648 $arr['parent-uri'] = $uri;
649 $arr['type'] = 'photo';
651 $arr['resource-id'] = $photo_hash;
652 $arr['contact-id'] = $owner_record['id'];
653 $arr['owner-name'] = $owner_record['name'];
654 $arr['owner-link'] = $owner_record['url'];
655 $arr['owner-avatar'] = $owner_record['thumb'];
656 $arr['author-name'] = $owner_record['name'];
657 $arr['author-link'] = $owner_record['url'];
658 $arr['author-avatar'] = $owner_record['thumb'];
660 $arr['allow_cid'] = $str_contact_allow;
661 $arr['allow_gid'] = $str_group_allow;
662 $arr['deny_cid'] = $str_contact_deny;
663 $arr['deny_gid'] = $str_group_deny;
664 $arr['last-child'] = 1;
665 $arr['visible'] = $visible;
666 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
667 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
670 $item_id = item_store($arr);
673 q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
674 dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
675 intval($page_owner_uid),
681 proc_run('php', "include/notifier.php", 'wall-new', $item_id);
683 call_hooks('photo_post_end',intval($item_id));
685 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
686 // if they do not wish to be redirected
688 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
694 function photos_content(&$a) {
698 // photos/name/upload
699 // photos/name/album/xxxxx
700 // photos/name/album/xxxxx/edit
701 // photos/name/image/xxxxx
702 // photos/name/image/xxxxx/edit
705 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
706 notice( t('Public access denied.') . EOL);
711 require_once('include/bbcode.php');
712 require_once('include/security.php');
713 require_once('include/conversation.php');
715 if(! x($a->data,'user')) {
716 notice( t('No photos selected') . EOL );
720 $_SESSION['photo_return'] = $a->cmd;
727 $datatype = $a->argv[2];
728 $datum = $a->argv[3];
730 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
731 $datatype = 'upload';
733 $datatype = 'summary';
741 // Setup permissions structures
747 $remote_contact = false;
749 $owner_uid = $a->data['user']['uid'];
753 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
755 if((local_user()) && (local_user() == $owner_uid))
758 if($community_page && remote_user()) {
759 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
760 intval(remote_user()),
766 $remote_contact = true;
767 $visitor = remote_user();
772 // perhaps they're visiting - but not a community page, so they wouldn't have write access
774 if(remote_user() && (! $visitor)) {
775 $contact_id = $_SESSION['visitor_id'];
776 $groups = init_groups_visitor($contact_id);
777 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
778 intval(remote_user()),
783 $remote_contact = true;
787 if(! $remote_contact) {
789 $contact_id = $_SESSION['cid'];
790 $contact = $a->contact;
794 $r = q("SELECT `hidewall` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
798 if(count($r) && $r[0]['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
799 notice( t('Access to this item is restricted.') . EOL);
803 // default permissions - anonymous user
805 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
807 // Profile owner - everything is visible
809 if(local_user() && (local_user() == $owner_uid)) {
812 elseif(remote_user()) {
813 // authenticated visitor - here lie dragons
814 $gs = '<<>>'; // should be impossible to match
816 foreach($groups as $g)
817 $gs .= '|<' . intval($g) . '>';
819 $sql_extra = sprintf(
820 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
821 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
822 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
823 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
825 intval(remote_user()),
826 intval(remote_user()),
837 if($datatype === 'upload') {
839 notice( t('Permission denied.'));
842 $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
844 $albumselect .= '<option value="" selected="selected" > </option>';
845 if(count($a->data['albums'])) {
846 foreach($a->data['albums'] as $album) {
847 if(($album['album'] === '') || ($album['album'] == t('Contact Photos')))
849 $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
853 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
855 $albumselect .= '</select>';
859 $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
860 'addon_text' => $uploader,
861 'default_upload' => true);
864 call_hooks('photo_upload_form',$ret);
866 $default_upload = '<input type="file" name="userfile" /> <div class="photos-upload-submit-wrapper" >
867 <input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>';
872 $tpl = get_markup_template('photos_upload.tpl');
873 $o .= replace_macros($tpl,array(
874 '$pagename' => t('Upload Photos'),
875 '$sessid' => session_id(),
876 '$nickname' => $a->data['user']['nickname'],
877 '$newalbum' => t('New album name: '),
878 '$existalbumtext' => t('or existing album name: '),
879 '$albumselect' => $albumselect,
880 '$permissions' => t('Permissions'),
881 '$aclselect' => (($visitor) ? '' : populate_acl($a->user, $celeb)),
882 '$uploader' => $ret['addon_text'],
883 '$default' => (($ret['default_upload']) ? $default_upload : ''),
884 '$uploadurl' => $ret['post_url']
891 if($datatype === 'album') {
893 $album = hex2bin($datum);
895 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
896 $sql_extra GROUP BY `resource-id`",
901 $a->set_pager_total(count($r));
902 $a->set_pager_itemspage(20);
905 $r = q("SELECT `resource-id`, `id`, `filename`, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
906 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
909 intval($a->pager['start']),
910 intval($a->pager['itemspage'])
913 $o .= '<h3>' . $album . '</h3>';
915 if($cmd === 'edit') {
916 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
918 $edit_tpl = get_markup_template('album_edit.tpl');
919 $o .= replace_macros($edit_tpl,array(
920 '$nametext' => t('New album name: '),
921 '$nickname' => $a->data['user']['nickname'],
923 '$hexalbum' => bin2hex($album),
924 '$submit' => t('Submit'),
925 '$dropsubmit' => t('Delete Album')
931 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
933 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
934 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
935 . t('Edit Album') . '</a></div>';
939 $tpl = get_markup_template('photo_album.tpl');
942 $o .= replace_macros($tpl,array(
944 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
945 '$phototitle' => t('View Photo'),
946 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
947 '$imgalt' => $rr['filename'],
948 '$desc'=> $rr['desc']
952 $o .= '<div id="photo-album-end"></div>';
960 if($datatype === 'image') {
965 // fetch image, item containing image, then comments
967 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
968 $sql_extra ORDER BY `scale` ASC ",
974 notice( t('Photo not available') . EOL );
981 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
982 $sql_extra ORDER BY `created` DESC ",
983 dbesc($ph[0]['album']),
988 for($z = 0; $z < count($prvnxt); $z++) {
989 if($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
993 $prv = count($prvnxt) - 1;
994 if($nxt >= count($prvnxt))
999 $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] ;
1000 $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] ;
1005 $hires = $lores = $ph[0];
1006 if(count($ph) > 1) {
1007 if($ph[1]['scale'] == 2) {
1008 // original is 640 or less, we can display it directly
1009 $hires = $lores = $ph[0];
1017 $album_link = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1021 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
1023 'edit' => array($a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/edit', t('Edit photo')),
1024 'profile'=>array($a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
1028 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1029 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1030 ? t('Private Message')
1037 $prevlink = array($prevlink, t('<< Prev')) ;
1040 'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg',
1041 'title'=> t('View Full Size'),
1042 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg'
1046 $nextlink = array($nextlink, t('Next >>'));
1049 // Do we have an item for this photo?
1051 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1054 if(count($linked_items)) {
1055 $link_item = $linked_items[0];
1056 $r = q("SELECT COUNT(*) AS `total`
1057 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1058 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
1059 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1060 AND `item`.`uid` = %d
1062 dbesc($link_item['uri']),
1063 dbesc($link_item['uri']),
1064 intval($link_item['uid'])
1069 $a->set_pager_total($r[0]['total']);
1072 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1073 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1074 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1075 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1076 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1077 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
1078 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1079 AND `item`.`uid` = %d
1081 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1082 dbesc($link_item['uri']),
1083 dbesc($link_item['uri']),
1084 intval($link_item['uid']),
1085 intval($a->pager['start']),
1086 intval($a->pager['itemspage'])
1090 if((local_user()) && (local_user() == $link_item['uid'])) {
1091 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1092 intval($link_item['parent']),
1093 intval(local_user())
1099 if(count($linked_items) && strlen($link_item['tag'])) {
1100 $arr = explode(',',$link_item['tag']);
1101 // parse tags and add links
1103 foreach($arr as $t) {
1104 if(strlen($tag_str))
1106 $tag_str .= bbcode($t);
1108 $tags = array(t('Tags: '), $tag_str);
1110 $tags[] = $a->get_baseurl() . '/tagrm/' . $link_item['id'];
1111 $tags[] = t('[Remove any tag]');
1116 if(($cmd === 'edit') && ($can_post)) {
1117 $edit_tpl = get_markup_template('photo_edit.tpl');
1118 $edit = replace_macros($edit_tpl, array(
1119 '$id' => $ph[0]['id'],
1120 '$album' => $ph[0]['album'],
1121 '$newalbum' => t('New album name'),
1122 '$nickname' => $a->data['user']['nickname'],
1123 '$resource_id' => $ph[0]['resource-id'],
1124 '$capt_label' => t('Caption'),
1125 '$caption' => $ph[0]['desc'],
1126 '$tag_label' => t('Add a Tag'),
1127 '$tags' => $link_item['tag'],
1128 '$permissions' => t('Permissions'),
1129 '$aclselect' => populate_acl($ph[0]),
1130 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
1131 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1132 '$submit' => t('Submit'),
1133 '$delete' => t('Delete Photo')
1137 if(count($linked_items)) {
1139 $cmnt_tpl = get_markup_template('comment_item.tpl');
1140 $tpl = get_markup_template('photo_item.tpl');
1141 $return_url = $a->cmd;
1143 $like_tpl = get_markup_template('like_noshare.tpl');
1147 if($can_post || can_write_wall($a,$owner_uid)) {
1148 $likebuttons = replace_macros($like_tpl,array(
1149 '$id' => $link_item['id'],
1150 '$likethis' => t("I like this \x28toggle\x29"),
1151 '$nolike' => t("I don't like this \x28toggle\x29"),
1152 '$share' => t('Share'),
1153 '$wait' => t('Please wait')
1159 if($can_post || can_write_wall($a,$owner_uid)) {
1160 if($link_item['last-child']) {
1161 $comments .= replace_macros($cmnt_tpl,array(
1162 '$return_path' => '',
1163 '$jsreload' => $return_url,
1164 '$type' => 'wall-comment',
1165 '$id' => $link_item['id'],
1166 '$parent' => $link_item['id'],
1167 '$profile_uid' => $owner_uid,
1168 '$mylink' => $contact['url'],
1169 '$mytitle' => t('This is you'),
1170 '$myphoto' => $contact['thumb'],
1171 '$comment' => t('Comment'),
1172 '$submit' => t('Submit'),
1188 foreach($r as $item) {
1189 like_puller($a,$item,$alike,'like');
1190 like_puller($a,$item,$dlike,'dislike');
1193 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
1194 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
1198 if($can_post || can_write_wall($a,$owner_uid)) {
1199 if($link_item['last-child']) {
1200 $comments .= replace_macros($cmnt_tpl,array(
1201 '$return_path' => '',
1202 '$jsreload' => $return_url,
1203 '$type' => 'wall-comment',
1204 '$id' => $link_item['id'],
1205 '$parent' => $link_item['id'],
1206 '$profile_uid' => $owner_uid,
1207 '$mylink' => $contact['url'],
1208 '$mytitle' => t('This is you'),
1209 '$myphoto' => $contact['thumb'],
1210 '$comment' => t('Comment'),
1211 '$submit' => t('Submit'),
1218 foreach($r as $item) {
1223 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1226 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1228 if($can_post || can_write_wall($a,$owner_uid)) {
1230 if($item['last-child']) {
1231 $comments .= replace_macros($cmnt_tpl,array(
1232 '$return_path' => '',
1233 '$jsreload' => $return_url,
1234 '$type' => 'wall-comment',
1235 '$id' => $item['item_id'],
1236 '$parent' => $item['parent'],
1237 '$profile_uid' => $owner_uid,
1238 '$mylink' => $contact['url'],
1239 '$mytitle' => t('This is you'),
1240 '$myphoto' => $contact['thumb'],
1241 '$comment' => t('Comment'),
1242 '$submit' => t('Submit'),
1249 if(local_user() && ($item['contact-uid'] == local_user())
1250 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
1251 $profile_url = $redirect_url;
1252 $sparkle = ' sparkle';
1255 $profile_url = $item['url'];
1259 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1261 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1262 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1264 $profile_link = $profile_url;
1268 if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
1269 $drop = replace_macros(get_markup_template('wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
1272 $comments .= replace_macros($template,array(
1273 '$id' => $item['item_id'],
1274 '$profile_url' => $profile_link,
1275 '$name' => $profile_name,
1276 '$thumb' => $profile_avatar,
1277 '$sparkle' => $sparkle,
1278 '$title' => $item['title'],
1279 '$body' => bbcode($item['body']),
1280 '$ago' => relative_date($item['created']),
1281 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1283 '$comment' => $comment
1288 $paginate = paginate($a);
1291 $photo_tpl = get_markup_template('photo_view.tpl');
1292 $o .= replace_macros($photo_tpl, array(
1293 '$id' => $ph[0]['id'],
1294 '$album' => array($album_link,$ph[0]['album']),
1298 '$prevlink' => $prevlink,
1299 '$nextlink' => $nextlink,
1300 '$desc' => $ph[0]['desc'],
1303 '$likebuttons' => $likebuttons,
1305 '$dislike' => $dislike,
1306 '$comments' => $comments,
1307 '$paginate' => $paginate,
1313 // Default - show recent photos with upload link (if applicable)
1316 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
1317 $sql_extra GROUP BY `resource-id`",
1318 intval($a->data['user']['uid']),
1319 dbesc( t('Contact Photos'))
1322 $a->set_pager_total(count($r));
1323 $a->set_pager_itemspage(20);
1326 $r = q("SELECT `resource-id`, `id`, `filename`, `album`, max(`scale`) AS `scale` FROM `photo`
1327 WHERE `uid` = %d AND `album` != '%s'
1328 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1329 intval($a->data['user']['uid']),
1330 dbesc( t('Contact Photos')),
1331 intval($a->pager['start']),
1332 intval($a->pager['itemspage'])
1335 $o .= '<h3>' . t('Recent Photos') . '</h3>';
1338 $o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
1339 . $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
1342 $tpl = get_markup_template('photo_top.tpl');
1344 foreach($r as $rr) {
1345 $o .= replace_macros($tpl,array(
1347 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1348 '$phototitle' => t('View Photo'),
1349 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.jpg',
1350 '$albumlink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1351 '$albumname' => $rr['album'],
1352 '$albumalt' => t('View Album'),
1353 '$imgalt' => $rr['filename']
1357 $o .= '<div id="photo-top-end"></div>';