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']);
593 $maximagesize = get_config('system','maximagesize');
595 if(($maximagesize) && ($filesize > $maximagesize)) {
596 notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
599 call_hooks('photo_post_end',$foo);
603 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , 'LOGGER_DEBUG');
605 $imagedata = @file_get_contents($src);
606 $ph = new Photo($imagedata);
608 if(! $ph->is_valid()) {
609 logger('mod/photos.php: photos_post(): unable to process image' , 'LOGGER_DEBUG');
610 notice( t('Unable to process image.') . EOL );
613 call_hooks('photo_post_end',$foo);
619 $width = $ph->getWidth();
620 $height = $ph->getHeight();
624 $photo_hash = photo_new_resource();
626 $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);
629 logger('mod/photos.php: photos_post(): image store failed' , 'LOGGER_DEBUG');
630 notice( t('Image upload failed.') . EOL );
634 if($width > 640 || $height > 640) {
635 $ph->scaleImage(640);
636 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
640 if($width > 320 || $height > 320) {
641 $ph->scaleImage(320);
642 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
646 $basename = basename($filename);
647 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
649 // Create item container
653 $arr['uid'] = $page_owner_uid;
655 $arr['parent-uri'] = $uri;
656 $arr['type'] = 'photo';
658 $arr['resource-id'] = $photo_hash;
659 $arr['contact-id'] = $owner_record['id'];
660 $arr['owner-name'] = $owner_record['name'];
661 $arr['owner-link'] = $owner_record['url'];
662 $arr['owner-avatar'] = $owner_record['thumb'];
663 $arr['author-name'] = $owner_record['name'];
664 $arr['author-link'] = $owner_record['url'];
665 $arr['author-avatar'] = $owner_record['thumb'];
667 $arr['allow_cid'] = $str_contact_allow;
668 $arr['allow_gid'] = $str_group_allow;
669 $arr['deny_cid'] = $str_contact_deny;
670 $arr['deny_gid'] = $str_group_deny;
671 $arr['last-child'] = 1;
672 $arr['visible'] = $visible;
673 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
674 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
677 $item_id = item_store($arr);
680 q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
681 dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
682 intval($page_owner_uid),
688 proc_run('php', "include/notifier.php", 'wall-new', $item_id);
690 call_hooks('photo_post_end',intval($item_id));
692 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
693 // if they do not wish to be redirected
695 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
701 function photos_content(&$a) {
705 // photos/name/upload
706 // photos/name/album/xxxxx
707 // photos/name/album/xxxxx/edit
708 // photos/name/image/xxxxx
709 // photos/name/image/xxxxx/edit
712 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
713 notice( t('Public access denied.') . EOL);
718 require_once('include/bbcode.php');
719 require_once('include/security.php');
720 require_once('include/conversation.php');
722 if(! x($a->data,'user')) {
723 notice( t('No photos selected') . EOL );
727 $_SESSION['photo_return'] = $a->cmd;
734 $datatype = $a->argv[2];
735 $datum = $a->argv[3];
737 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
738 $datatype = 'upload';
740 $datatype = 'summary';
748 // Setup permissions structures
754 $remote_contact = false;
756 $owner_uid = $a->data['user']['uid'];
760 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
762 if((local_user()) && (local_user() == $owner_uid))
765 if($community_page && remote_user()) {
766 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
767 intval(remote_user()),
773 $remote_contact = true;
774 $visitor = remote_user();
779 // perhaps they're visiting - but not a community page, so they wouldn't have write access
781 if(remote_user() && (! $visitor)) {
782 $contact_id = $_SESSION['visitor_id'];
783 $groups = init_groups_visitor($contact_id);
784 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
785 intval(remote_user()),
790 $remote_contact = true;
794 if(! $remote_contact) {
796 $contact_id = $_SESSION['cid'];
797 $contact = $a->contact;
801 $r = q("SELECT `hidewall` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
805 if(count($r) && $r[0]['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
806 notice( t('Access to this item is restricted.') . EOL);
810 // default permissions - anonymous user
812 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
814 // Profile owner - everything is visible
816 if(local_user() && (local_user() == $owner_uid)) {
819 elseif(remote_user()) {
820 // authenticated visitor - here lie dragons
821 $gs = '<<>>'; // should be impossible to match
823 foreach($groups as $g)
824 $gs .= '|<' . intval($g) . '>';
826 $sql_extra = sprintf(
827 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
828 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
829 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
830 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
832 intval(remote_user()),
833 intval(remote_user()),
844 if($datatype === 'upload') {
846 notice( t('Permission denied.'));
849 $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
851 $albumselect .= '<option value="" selected="selected" > </option>';
852 if(count($a->data['albums'])) {
853 foreach($a->data['albums'] as $album) {
854 if(($album['album'] === '') || ($album['album'] == t('Contact Photos')))
856 $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
860 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
862 $albumselect .= '</select>';
866 $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
867 'addon_text' => $uploader,
868 'default_upload' => true);
871 call_hooks('photo_upload_form',$ret);
873 $default_upload = '<input type="file" name="userfile" /> <div class="photos-upload-submit-wrapper" >
874 <input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>';
879 $tpl = get_markup_template('photos_upload.tpl');
880 $o .= replace_macros($tpl,array(
881 '$pagename' => t('Upload Photos'),
882 '$sessid' => session_id(),
883 '$nickname' => $a->data['user']['nickname'],
884 '$newalbum' => t('New album name: '),
885 '$existalbumtext' => t('or existing album name: '),
886 '$albumselect' => $albumselect,
887 '$permissions' => t('Permissions'),
888 '$aclselect' => (($visitor) ? '' : populate_acl($a->user, $celeb)),
889 '$uploader' => $ret['addon_text'],
890 '$default' => (($ret['default_upload']) ? $default_upload : ''),
891 '$uploadurl' => $ret['post_url']
898 if($datatype === 'album') {
900 $album = hex2bin($datum);
902 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
903 $sql_extra GROUP BY `resource-id`",
908 $a->set_pager_total(count($r));
909 $a->set_pager_itemspage(20);
912 $r = q("SELECT `resource-id`, `id`, `filename`, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
913 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
916 intval($a->pager['start']),
917 intval($a->pager['itemspage'])
920 $o .= '<h3>' . $album . '</h3>';
922 if($cmd === 'edit') {
923 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
925 $edit_tpl = get_markup_template('album_edit.tpl');
926 $o .= replace_macros($edit_tpl,array(
927 '$nametext' => t('New album name: '),
928 '$nickname' => $a->data['user']['nickname'],
930 '$hexalbum' => bin2hex($album),
931 '$submit' => t('Submit'),
932 '$dropsubmit' => t('Delete Album')
938 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
940 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
941 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
942 . t('Edit Album') . '</a></div>';
946 $tpl = get_markup_template('photo_album.tpl');
949 $o .= replace_macros($tpl,array(
951 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
952 '$phototitle' => t('View Photo'),
953 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
954 '$imgalt' => $rr['filename'],
955 '$desc'=> $rr['desc']
959 $o .= '<div id="photo-album-end"></div>';
967 if($datatype === 'image') {
972 // fetch image, item containing image, then comments
974 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
975 $sql_extra ORDER BY `scale` ASC ",
981 notice( t('Photo not available') . EOL );
988 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
989 $sql_extra ORDER BY `created` DESC ",
990 dbesc($ph[0]['album']),
995 for($z = 0; $z < count($prvnxt); $z++) {
996 if($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
1000 $prv = count($prvnxt) - 1;
1001 if($nxt >= count($prvnxt))
1006 $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] ;
1007 $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] ;
1012 $hires = $lores = $ph[0];
1013 if(count($ph) > 1) {
1014 if($ph[1]['scale'] == 2) {
1015 // original is 640 or less, we can display it directly
1016 $hires = $lores = $ph[0];
1024 $album_link = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1028 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
1030 'edit' => array($a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/edit', t('Edit photo')),
1031 'profile'=>array($a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
1035 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1036 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1037 ? t('Private Message')
1044 $prevlink = array($prevlink, '<div class="icon prev"></div>') ;
1047 'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg',
1048 'title'=> t('View Full Size'),
1049 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg'
1053 $nextlink = array($nextlink, '<div class="icon next"></div>');
1056 // Do we have an item for this photo?
1058 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1061 if(count($linked_items)) {
1062 $link_item = $linked_items[0];
1063 $r = q("SELECT COUNT(*) AS `total`
1064 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1065 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
1066 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1067 AND `item`.`uid` = %d
1069 dbesc($link_item['uri']),
1070 dbesc($link_item['uri']),
1071 intval($link_item['uid'])
1076 $a->set_pager_total($r[0]['total']);
1079 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1080 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1081 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1082 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1083 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1084 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
1085 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1086 AND `item`.`uid` = %d
1088 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1089 dbesc($link_item['uri']),
1090 dbesc($link_item['uri']),
1091 intval($link_item['uid']),
1092 intval($a->pager['start']),
1093 intval($a->pager['itemspage'])
1097 if((local_user()) && (local_user() == $link_item['uid'])) {
1098 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1099 intval($link_item['parent']),
1100 intval(local_user())
1106 if(count($linked_items) && strlen($link_item['tag'])) {
1107 $arr = explode(',',$link_item['tag']);
1108 // parse tags and add links
1110 foreach($arr as $t) {
1111 if(strlen($tag_str))
1113 $tag_str .= bbcode($t);
1115 $tags = array(t('Tags: '), $tag_str);
1116 if($cmd === 'edit') {
1117 $tags[] = $a->get_baseurl() . '/tagrm/' . $link_item['id'];
1118 $tags[] = t('[Remove any tag]');
1124 if(($cmd === 'edit') && ($can_post)) {
1125 $edit_tpl = get_markup_template('photo_edit.tpl');
1126 $edit = replace_macros($edit_tpl, array(
1127 '$id' => $ph[0]['id'],
1128 '$album' => $ph[0]['album'],
1129 '$newalbum' => t('New album name'),
1130 '$nickname' => $a->data['user']['nickname'],
1131 '$resource_id' => $ph[0]['resource-id'],
1132 '$capt_label' => t('Caption'),
1133 '$caption' => $ph[0]['desc'],
1134 '$tag_label' => t('Add a Tag'),
1135 '$tags' => $link_item['tag'],
1136 '$permissions' => t('Permissions'),
1137 '$aclselect' => populate_acl($ph[0]),
1138 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
1139 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1140 '$submit' => t('Submit'),
1141 '$delete' => t('Delete Photo')
1145 if(count($linked_items)) {
1147 $cmnt_tpl = get_markup_template('comment_item.tpl');
1148 $tpl = get_markup_template('photo_item.tpl');
1149 $return_url = $a->cmd;
1151 $like_tpl = get_markup_template('like_noshare.tpl');
1155 if($can_post || can_write_wall($a,$owner_uid)) {
1156 $likebuttons = replace_macros($like_tpl,array(
1157 '$id' => $link_item['id'],
1158 '$likethis' => t("I like this \x28toggle\x29"),
1159 '$nolike' => t("I don't like this \x28toggle\x29"),
1160 '$share' => t('Share'),
1161 '$wait' => t('Please wait')
1167 if($can_post || can_write_wall($a,$owner_uid)) {
1168 if($link_item['last-child']) {
1169 $comments .= replace_macros($cmnt_tpl,array(
1170 '$return_path' => '',
1171 '$jsreload' => $return_url,
1172 '$type' => 'wall-comment',
1173 '$id' => $link_item['id'],
1174 '$parent' => $link_item['id'],
1175 '$profile_uid' => $owner_uid,
1176 '$mylink' => $contact['url'],
1177 '$mytitle' => t('This is you'),
1178 '$myphoto' => $contact['thumb'],
1179 '$comment' => t('Comment'),
1180 '$submit' => t('Submit'),
1196 foreach($r as $item) {
1197 like_puller($a,$item,$alike,'like');
1198 like_puller($a,$item,$dlike,'dislike');
1201 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
1202 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
1206 if($can_post || can_write_wall($a,$owner_uid)) {
1207 if($link_item['last-child']) {
1208 $comments .= replace_macros($cmnt_tpl,array(
1209 '$return_path' => '',
1210 '$jsreload' => $return_url,
1211 '$type' => 'wall-comment',
1212 '$id' => $link_item['id'],
1213 '$parent' => $link_item['id'],
1214 '$profile_uid' => $owner_uid,
1215 '$mylink' => $contact['url'],
1216 '$mytitle' => t('This is you'),
1217 '$myphoto' => $contact['thumb'],
1218 '$comment' => t('Comment'),
1219 '$submit' => t('Submit'),
1226 foreach($r as $item) {
1231 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1234 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1236 if($can_post || can_write_wall($a,$owner_uid)) {
1238 if($item['last-child']) {
1239 $comments .= replace_macros($cmnt_tpl,array(
1240 '$return_path' => '',
1241 '$jsreload' => $return_url,
1242 '$type' => 'wall-comment',
1243 '$id' => $item['item_id'],
1244 '$parent' => $item['parent'],
1245 '$profile_uid' => $owner_uid,
1246 '$mylink' => $contact['url'],
1247 '$mytitle' => t('This is you'),
1248 '$myphoto' => $contact['thumb'],
1249 '$comment' => t('Comment'),
1250 '$submit' => t('Submit'),
1257 if(local_user() && ($item['contact-uid'] == local_user())
1258 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
1259 $profile_url = $redirect_url;
1260 $sparkle = ' sparkle';
1263 $profile_url = $item['url'];
1267 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1269 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1270 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1272 $profile_link = $profile_url;
1276 if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
1277 $drop = replace_macros(get_markup_template('wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
1280 $comments .= replace_macros($template,array(
1281 '$id' => $item['item_id'],
1282 '$profile_url' => $profile_link,
1283 '$name' => $profile_name,
1284 '$thumb' => $profile_avatar,
1285 '$sparkle' => $sparkle,
1286 '$title' => $item['title'],
1287 '$body' => bbcode($item['body']),
1288 '$ago' => relative_date($item['created']),
1289 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1291 '$comment' => $comment
1296 $paginate = paginate($a);
1299 $photo_tpl = get_markup_template('photo_view.tpl');
1300 $o .= replace_macros($photo_tpl, array(
1301 '$id' => $ph[0]['id'],
1302 '$album' => array($album_link,$ph[0]['album']),
1306 '$prevlink' => $prevlink,
1307 '$nextlink' => $nextlink,
1308 '$desc' => $ph[0]['desc'],
1311 '$likebuttons' => $likebuttons,
1313 '$dislike' => $dislike,
1314 '$comments' => $comments,
1315 '$paginate' => $paginate,
1321 // Default - show recent photos with upload link (if applicable)
1324 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
1325 $sql_extra GROUP BY `resource-id`",
1326 intval($a->data['user']['uid']),
1327 dbesc( t('Contact Photos'))
1330 $a->set_pager_total(count($r));
1331 $a->set_pager_itemspage(20);
1334 $r = q("SELECT `resource-id`, `id`, `filename`, `album`, max(`scale`) AS `scale` FROM `photo`
1335 WHERE `uid` = %d AND `album` != '%s'
1336 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1337 intval($a->data['user']['uid']),
1338 dbesc( t('Contact Photos')),
1339 intval($a->pager['start']),
1340 intval($a->pager['itemspage'])
1343 $o .= '<h3>' . t('Recent Photos') . '</h3>';
1346 $o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
1347 . $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
1350 $tpl = get_markup_template('photo_top.tpl');
1352 foreach($r as $rr) {
1353 $o .= replace_macros($tpl,array(
1355 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1356 '$phototitle' => t('View Photo'),
1357 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.jpg',
1358 '$albumlink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1359 '$albumname' => $rr['album'],
1360 '$albumalt' => t('View Album'),
1361 '$imgalt' => $rr['filename']
1365 $o .= '<div id="photo-top-end"></div>';