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 q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
515 dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
516 intval($page_owner_uid),
520 proc_run('php',"include/notifier.php","tag","$item_id");
527 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
528 return; // NOTREACHED
533 * default post action - upload a photo
536 call_hooks('photo_post_init', $_POST);
539 * Determine the album to use
542 $album = notags(trim($_REQUEST['album']));
543 $newalbum = notags(trim($_REQUEST['newalbum']));
545 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , 'LOGGER_DEBUG');
547 if(! strlen($album)) {
548 if(strlen($newalbum))
551 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
556 * We create a wall item for every photo, but we don't want to
557 * overwhelm the data stream with a hundred newly uploaded photos.
558 * So we will make the first photo uploaded to this album in the last several hours
559 * visible by default, the rest will become visible over time when and if
560 * they acquire comments, likes, dislikes, and/or tags
564 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
566 intval($page_owner_uid)
568 if((! count($r)) || ($album == t('Profile Photos')))
573 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
574 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
575 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
576 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
578 $ret = array('src' => '', 'filename' => '', 'filesize' => 0);
580 call_hooks('photo_post_file',$ret);
582 if(x($ret,'src') && x($ret,'filesize')) {
584 $filename = $ret['filename'];
585 $filesize = $ret['filesize'];
588 $src = $_FILES['userfile']['tmp_name'];
589 $filename = basename($_FILES['userfile']['name']);
590 $filesize = intval($_FILES['userfile']['size']);
594 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ' . $filesize . ' bytes', LOGGER_DEBUG);
596 $maximagesize = get_config('system','maximagesize');
598 if(($maximagesize) && ($filesize > $maximagesize)) {
599 notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
602 call_hooks('photo_post_end',$foo);
607 notice( t('Image file is empty.') . EOL);
610 call_hooks('photo_post_end',$foo);
614 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , 'LOGGER_DEBUG');
616 $imagedata = @file_get_contents($src);
617 $ph = new Photo($imagedata);
619 if(! $ph->is_valid()) {
620 logger('mod/photos.php: photos_post(): unable to process image' , 'LOGGER_DEBUG');
621 notice( t('Unable to process image.') . EOL );
624 call_hooks('photo_post_end',$foo);
630 $width = $ph->getWidth();
631 $height = $ph->getHeight();
635 $photo_hash = photo_new_resource();
637 $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);
640 logger('mod/photos.php: photos_post(): image store failed' , 'LOGGER_DEBUG');
641 notice( t('Image upload failed.') . EOL );
645 if($width > 640 || $height > 640) {
646 $ph->scaleImage(640);
647 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
651 if($width > 320 || $height > 320) {
652 $ph->scaleImage(320);
653 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
657 $basename = basename($filename);
658 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
660 // Create item container
664 $arr['uid'] = $page_owner_uid;
666 $arr['parent-uri'] = $uri;
667 $arr['type'] = 'photo';
669 $arr['resource-id'] = $photo_hash;
670 $arr['contact-id'] = $owner_record['id'];
671 $arr['owner-name'] = $owner_record['name'];
672 $arr['owner-link'] = $owner_record['url'];
673 $arr['owner-avatar'] = $owner_record['thumb'];
674 $arr['author-name'] = $owner_record['name'];
675 $arr['author-link'] = $owner_record['url'];
676 $arr['author-avatar'] = $owner_record['thumb'];
678 $arr['allow_cid'] = $str_contact_allow;
679 $arr['allow_gid'] = $str_group_allow;
680 $arr['deny_cid'] = $str_contact_deny;
681 $arr['deny_gid'] = $str_group_deny;
682 $arr['last-child'] = 1;
683 $arr['visible'] = $visible;
684 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
685 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
688 $item_id = item_store($arr);
691 q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
692 dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
693 intval($page_owner_uid),
699 proc_run('php', "include/notifier.php", 'wall-new', $item_id);
701 call_hooks('photo_post_end',intval($item_id));
703 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
704 // if they do not wish to be redirected
706 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
712 function photos_content(&$a) {
716 // photos/name/upload
717 // photos/name/album/xxxxx
718 // photos/name/album/xxxxx/edit
719 // photos/name/image/xxxxx
720 // photos/name/image/xxxxx/edit
723 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
724 notice( t('Public access denied.') . EOL);
729 require_once('include/bbcode.php');
730 require_once('include/security.php');
731 require_once('include/conversation.php');
733 if(! x($a->data,'user')) {
734 notice( t('No photos selected') . EOL );
738 $_SESSION['photo_return'] = $a->cmd;
745 $datatype = $a->argv[2];
746 $datum = $a->argv[3];
748 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
749 $datatype = 'upload';
751 $datatype = 'summary';
759 // Setup permissions structures
765 $remote_contact = false;
767 $owner_uid = $a->data['user']['uid'];
771 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
773 if((local_user()) && (local_user() == $owner_uid))
776 if($community_page && remote_user()) {
777 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
778 intval(remote_user()),
784 $remote_contact = true;
785 $visitor = remote_user();
790 // perhaps they're visiting - but not a community page, so they wouldn't have write access
792 if(remote_user() && (! $visitor)) {
793 $contact_id = $_SESSION['visitor_id'];
794 $groups = init_groups_visitor($contact_id);
795 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
796 intval(remote_user()),
801 $remote_contact = true;
805 if(! $remote_contact) {
807 $contact_id = $_SESSION['cid'];
808 $contact = $a->contact;
812 $r = q("SELECT `hidewall` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
816 if(count($r) && $r[0]['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
817 notice( t('Access to this item is restricted.') . EOL);
821 // default permissions - anonymous user
823 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
825 // Profile owner - everything is visible
827 if(local_user() && (local_user() == $owner_uid)) {
830 elseif(remote_user()) {
831 // authenticated visitor - here lie dragons
832 $gs = '<<>>'; // should be impossible to match
834 foreach($groups as $g)
835 $gs .= '|<' . intval($g) . '>';
837 $sql_extra = sprintf(
838 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
839 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
840 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
841 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
843 intval(remote_user()),
844 intval(remote_user()),
853 $tpl = get_markup_template('profile_tabs.tpl');
854 $_is_owner = (local_user() && (local_user() == $owner_uid));
855 $o .= replace_macros($tpl,array(
856 '$url' => $a->get_baseurl() . '/profile/' .$a->data['user']['nickname'],
857 '$phototab' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
858 '$status' => t('Status'),
859 '$profile' => t('Profile'),
860 '$photos' => t('Photos'),
861 '$events' => (($_is_owner) ? t('Events') : ''),
862 '$notes' => (($_is_owner) ? t('Personal Notes') : ''),
863 '$activetab' => "photos",
871 if($datatype === 'upload') {
873 notice( t('Permission denied.'));
876 $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
878 $albumselect .= '<option value="" selected="selected" > </option>';
879 if(count($a->data['albums'])) {
880 foreach($a->data['albums'] as $album) {
881 if(($album['album'] === '') || ($album['album'] == t('Contact Photos')))
883 $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
887 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
889 $albumselect .= '</select>';
893 $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
894 'addon_text' => $uploader,
895 'default_upload' => true);
898 call_hooks('photo_upload_form',$ret);
900 $default_upload = '<input type="file" name="userfile" /> <div class="photos-upload-submit-wrapper" >
901 <input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>';
906 $tpl = get_markup_template('photos_upload.tpl');
907 $o .= replace_macros($tpl,array(
908 '$pagename' => t('Upload Photos'),
909 '$sessid' => session_id(),
910 '$nickname' => $a->data['user']['nickname'],
911 '$newalbum' => t('New album name: '),
912 '$existalbumtext' => t('or existing album name: '),
913 '$albumselect' => $albumselect,
914 '$permissions' => t('Permissions'),
915 '$aclselect' => (($visitor) ? '' : populate_acl($a->user, $celeb)),
916 '$uploader' => $ret['addon_text'],
917 '$default' => (($ret['default_upload']) ? $default_upload : ''),
918 '$uploadurl' => $ret['post_url']
925 if($datatype === 'album') {
927 $album = hex2bin($datum);
929 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
930 $sql_extra GROUP BY `resource-id`",
935 $a->set_pager_total(count($r));
936 $a->set_pager_itemspage(20);
939 $r = q("SELECT `resource-id`, `id`, `filename`, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
940 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
943 intval($a->pager['start']),
944 intval($a->pager['itemspage'])
947 $o .= '<h3>' . $album . '</h3>';
949 if($cmd === 'edit') {
950 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
952 $edit_tpl = get_markup_template('album_edit.tpl');
953 $o .= replace_macros($edit_tpl,array(
954 '$nametext' => t('New album name: '),
955 '$nickname' => $a->data['user']['nickname'],
957 '$hexalbum' => bin2hex($album),
958 '$submit' => t('Submit'),
959 '$dropsubmit' => t('Delete Album')
965 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
967 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
968 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
969 . t('Edit Album') . '</a></div>';
973 $tpl = get_markup_template('photo_album.tpl');
976 $o .= replace_macros($tpl,array(
978 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
979 '$phototitle' => t('View Photo'),
980 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
981 '$imgalt' => $rr['filename'],
982 '$desc'=> $rr['desc']
986 $o .= '<div id="photo-album-end"></div>';
994 if($datatype === 'image') {
999 // fetch image, item containing image, then comments
1001 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
1002 $sql_extra ORDER BY `scale` ASC ",
1008 notice( t('Photo not available') . EOL );
1015 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
1016 $sql_extra ORDER BY `created` DESC ",
1017 dbesc($ph[0]['album']),
1021 if(count($prvnxt)) {
1022 for($z = 0; $z < count($prvnxt); $z++) {
1023 if($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
1027 $prv = count($prvnxt) - 1;
1028 if($nxt >= count($prvnxt))
1033 $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] ;
1034 $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] ;
1039 $hires = $lores = $ph[0];
1040 if(count($ph) > 1) {
1041 if($ph[1]['scale'] == 2) {
1042 // original is 640 or less, we can display it directly
1043 $hires = $lores = $ph[0];
1051 $album_link = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1055 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
1057 'edit' => array($a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/edit', t('Edit photo')),
1058 'profile'=>array($a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
1062 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1063 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1064 ? t('Private Message')
1071 $prevlink = array($prevlink, '<div class="icon prev"></div>') ;
1074 'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg',
1075 'title'=> t('View Full Size'),
1076 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg'
1080 $nextlink = array($nextlink, '<div class="icon next"></div>');
1083 // Do we have an item for this photo?
1085 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1088 if(count($linked_items)) {
1089 $link_item = $linked_items[0];
1090 $r = q("SELECT COUNT(*) AS `total`
1091 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1092 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
1093 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1094 AND `item`.`uid` = %d
1096 dbesc($link_item['uri']),
1097 dbesc($link_item['uri']),
1098 intval($link_item['uid'])
1103 $a->set_pager_total($r[0]['total']);
1106 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1107 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1108 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1109 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1110 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1111 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
1112 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1113 AND `item`.`uid` = %d
1115 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1116 dbesc($link_item['uri']),
1117 dbesc($link_item['uri']),
1118 intval($link_item['uid']),
1119 intval($a->pager['start']),
1120 intval($a->pager['itemspage'])
1124 if((local_user()) && (local_user() == $link_item['uid'])) {
1125 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1126 intval($link_item['parent']),
1127 intval(local_user())
1133 if(count($linked_items) && strlen($link_item['tag'])) {
1134 $arr = explode(',',$link_item['tag']);
1135 // parse tags and add links
1137 foreach($arr as $t) {
1138 if(strlen($tag_str))
1140 $tag_str .= bbcode($t);
1142 $tags = array(t('Tags: '), $tag_str);
1143 if($cmd === 'edit') {
1144 $tags[] = $a->get_baseurl() . '/tagrm/' . $link_item['id'];
1145 $tags[] = t('[Remove any tag]');
1151 if(($cmd === 'edit') && ($can_post)) {
1152 $edit_tpl = get_markup_template('photo_edit.tpl');
1153 $edit = replace_macros($edit_tpl, array(
1154 '$id' => $ph[0]['id'],
1155 '$album' => $ph[0]['album'],
1156 '$newalbum' => t('New album name'),
1157 '$nickname' => $a->data['user']['nickname'],
1158 '$resource_id' => $ph[0]['resource-id'],
1159 '$capt_label' => t('Caption'),
1160 '$caption' => $ph[0]['desc'],
1161 '$tag_label' => t('Add a Tag'),
1162 '$tags' => $link_item['tag'],
1163 '$permissions' => t('Permissions'),
1164 '$aclselect' => populate_acl($ph[0]),
1165 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
1166 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1167 '$submit' => t('Submit'),
1168 '$delete' => t('Delete Photo')
1172 if(count($linked_items)) {
1174 $cmnt_tpl = get_markup_template('comment_item.tpl');
1175 $tpl = get_markup_template('photo_item.tpl');
1176 $return_url = $a->cmd;
1178 $like_tpl = get_markup_template('like_noshare.tpl');
1182 if($can_post || can_write_wall($a,$owner_uid)) {
1183 $likebuttons = replace_macros($like_tpl,array(
1184 '$id' => $link_item['id'],
1185 '$likethis' => t("I like this \x28toggle\x29"),
1186 '$nolike' => t("I don't like this \x28toggle\x29"),
1187 '$share' => t('Share'),
1188 '$wait' => t('Please wait')
1194 if($can_post || can_write_wall($a,$owner_uid)) {
1195 if($link_item['last-child']) {
1196 $comments .= replace_macros($cmnt_tpl,array(
1197 '$return_path' => '',
1198 '$jsreload' => $return_url,
1199 '$type' => 'wall-comment',
1200 '$id' => $link_item['id'],
1201 '$parent' => $link_item['id'],
1202 '$profile_uid' => $owner_uid,
1203 '$mylink' => $contact['url'],
1204 '$mytitle' => t('This is you'),
1205 '$myphoto' => $contact['thumb'],
1206 '$comment' => t('Comment'),
1207 '$submit' => t('Submit'),
1223 foreach($r as $item) {
1224 like_puller($a,$item,$alike,'like');
1225 like_puller($a,$item,$dlike,'dislike');
1228 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
1229 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
1233 if($can_post || can_write_wall($a,$owner_uid)) {
1234 if($link_item['last-child']) {
1235 $comments .= replace_macros($cmnt_tpl,array(
1236 '$return_path' => '',
1237 '$jsreload' => $return_url,
1238 '$type' => 'wall-comment',
1239 '$id' => $link_item['id'],
1240 '$parent' => $link_item['id'],
1241 '$profile_uid' => $owner_uid,
1242 '$mylink' => $contact['url'],
1243 '$mytitle' => t('This is you'),
1244 '$myphoto' => $contact['thumb'],
1245 '$comment' => t('Comment'),
1246 '$submit' => t('Submit'),
1253 foreach($r as $item) {
1258 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1261 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1263 if($can_post || can_write_wall($a,$owner_uid)) {
1265 if($item['last-child']) {
1266 $comments .= replace_macros($cmnt_tpl,array(
1267 '$return_path' => '',
1268 '$jsreload' => $return_url,
1269 '$type' => 'wall-comment',
1270 '$id' => $item['item_id'],
1271 '$parent' => $item['parent'],
1272 '$profile_uid' => $owner_uid,
1273 '$mylink' => $contact['url'],
1274 '$mytitle' => t('This is you'),
1275 '$myphoto' => $contact['thumb'],
1276 '$comment' => t('Comment'),
1277 '$submit' => t('Submit'),
1284 if(local_user() && ($item['contact-uid'] == local_user())
1285 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
1286 $profile_url = $redirect_url;
1287 $sparkle = ' sparkle';
1290 $profile_url = $item['url'];
1294 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1296 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1297 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1299 $profile_link = $profile_url;
1303 if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
1304 $drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
1307 $comments .= replace_macros($template,array(
1308 '$id' => $item['item_id'],
1309 '$profile_url' => $profile_link,
1310 '$name' => $profile_name,
1311 '$thumb' => $profile_avatar,
1312 '$sparkle' => $sparkle,
1313 '$title' => $item['title'],
1314 '$body' => bbcode($item['body']),
1315 '$ago' => relative_date($item['created']),
1316 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1318 '$comment' => $comment
1323 $paginate = paginate($a);
1326 $photo_tpl = get_markup_template('photo_view.tpl');
1327 $o .= replace_macros($photo_tpl, array(
1328 '$id' => $ph[0]['id'],
1329 '$album' => array($album_link,$ph[0]['album']),
1333 '$prevlink' => $prevlink,
1334 '$nextlink' => $nextlink,
1335 '$desc' => $ph[0]['desc'],
1338 '$likebuttons' => $likebuttons,
1340 '$dislike' => $dislike,
1341 '$comments' => $comments,
1342 '$paginate' => $paginate,
1348 // Default - show recent photos with upload link (if applicable)
1351 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
1352 $sql_extra GROUP BY `resource-id`",
1353 intval($a->data['user']['uid']),
1354 dbesc( t('Contact Photos'))
1357 $a->set_pager_total(count($r));
1358 $a->set_pager_itemspage(20);
1361 $r = q("SELECT `resource-id`, `id`, `filename`, `album`, max(`scale`) AS `scale` FROM `photo`
1362 WHERE `uid` = %d AND `album` != '%s'
1363 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1364 intval($a->data['user']['uid']),
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' => $rr['album'],
1387 '$albumalt' => t('View Album'),
1388 '$imgalt' => $rr['filename']
1392 $o .= '<div id="photo-top-end"></div>';