2 require_once('include/Photo.php');
3 require_once('include/items.php');
4 require_once('include/acl_selectors.php');
5 require_once('include/bbcode.php');
6 require_once('include/security.php');
8 function photos_init(&$a) {
11 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
18 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
25 $a->data['user'] = $r[0];
27 $sql_extra = permissions_sql($a->data['user']['uid']);
29 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra ",
30 intval($a->data['user']['uid'])
34 $a->data['albums'] = $albums;
36 $o .= '<h4><a href="' . $a->get_baseurl() . '/profile/' . $a->data['user']['nickname'] . '">' . $a->data['user']['username'] . '</a></h4>';
37 $o .= '<h4>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h4>';
40 foreach($albums as $album) {
42 // don't show contact photos. We once trasnlated this name, but then you could still access it under
43 // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
45 if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
47 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" />' . $album['album'] . '</a></li>';
52 if(! x($a->page,'aside'))
53 $a->page['aside'] = '';
54 $a->page['aside'] .= $o;
57 $a->page['htmlhead'] .= "<script> var ispublic = '" . t('everybody') . "';" ;
59 $a->page['htmlhead'] .= <<< EOT
61 $(document).ready(function() {
63 $('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() {
65 $('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() {
66 selstr = $(this).text();
67 $('#jot-perms-icon').removeClass('unlock').addClass('lock');
68 $('#jot-public').hide();
71 $('#jot-perms-icon').removeClass('lock').addClass('unlock');
72 $('#jot-public').show();
88 function photos_post(&$a) {
90 logger('mod/photos.php: photos_post(): begin' , 'LOGGER_DEBUG');
92 foreach($_REQUEST AS $key => $val) {
93 logger('mod/photos.php: photos_post(): $_REQUEST key: ' . $key . ' val: ' . $val , 'LOGGER_DEBUG');
96 foreach($_FILES AS $key => $val) {
97 logger('mod/photos.php: photos_post(): $_FILES key: ' . $key . ' val: ' . $val , 'LOGGER_DEBUG');
103 $page_owner_uid = $a->data['user']['uid'];
104 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
106 if((local_user()) && (local_user() == $page_owner_uid))
109 if($community_page && remote_user()) {
110 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
111 intval(remote_user()),
112 intval($page_owner_uid)
116 $visitor = remote_user();
122 notice( t('Permission denied.') . EOL );
126 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
127 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
128 intval($page_owner_uid)
132 notice( t('Contact information unavailable') . EOL);
133 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
137 $owner_record = $r[0];
140 if(($a->argc > 3) && ($a->argv[2] === 'album')) {
141 $album = hex2bin($a->argv[3]);
143 if($album === t('Profile Photos') || $album === 'Contact Photos' || $album === t('Contact Photos')) {
144 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
145 return; // NOTREACHED
148 $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
150 intval($page_owner_uid)
153 notice( t('Album not found.') . EOL);
154 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
155 return; // NOTREACHED
158 $newalbum = notags(trim($_POST['albumname']));
159 if($newalbum != $album) {
160 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
163 intval($page_owner_uid)
165 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
166 goaway($a->get_baseurl() . '/' . $newurl);
167 return; // NOTREACHED
171 if($_POST['dropalbum'] == t('Delete Album')) {
175 // get the list of photos we are about to delete
178 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
180 intval($page_owner_uid),
185 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
186 intval(local_user()),
192 $res[] = "'" . dbesc($rr['rid']) . "'" ;
196 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
197 return; // NOTREACHED
200 $str_res = implode(',', $res);
202 // remove the associated photos
204 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
205 intval($page_owner_uid)
208 // find and delete the corresponding item with all the comments and likes/dislikes
210 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
211 intval($page_owner_uid)
215 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
216 dbesc(datetime_convert()),
217 dbesc($rr['parent-uri']),
218 intval($page_owner_uid)
221 $drop_id = intval($rr['id']);
223 // send the notification upstream/downstream as the case may be
226 proc_run('php',"include/notifier.php","drop","$drop_id");
230 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
231 return; // NOTREACHED
234 if(($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
236 // same as above but remove single photo
239 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
241 intval($page_owner_uid),
246 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
247 intval(local_user()),
252 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
253 intval($page_owner_uid),
254 dbesc($r[0]['resource-id'])
256 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
257 dbesc($r[0]['resource-id']),
258 intval($page_owner_uid)
261 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
262 dbesc(datetime_convert()),
263 dbesc(datetime_convert()),
265 intval($page_owner_uid)
268 $url = $a->get_baseurl();
269 $drop_id = intval($i[0]['id']);
272 proc_run('php',"include/notifier.php","drop","$drop_id");
276 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
277 return; // NOTREACHED
280 if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
282 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
283 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
284 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
285 $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
286 $str_group_allow = perms2str($_POST['group_allow']);
287 $str_contact_allow = perms2str($_POST['contact_allow']);
288 $str_group_deny = perms2str($_POST['group_deny']);
289 $str_contact_deny = perms2str($_POST['contact_deny']);
291 $resource_id = $a->argv[2];
293 if(! strlen($albname))
294 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
297 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
299 intval($page_owner_uid)
302 $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",
305 dbesc($str_contact_allow),
306 dbesc($str_group_allow),
307 dbesc($str_contact_deny),
308 dbesc($str_group_deny),
310 intval($page_owner_uid)
314 /* Don't make the item visible if the only change was the album name */
317 if($p[0]['desc'] !== $desc || strlen($rawtags))
322 // Create item container
325 $basename = basename($filename);
326 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
330 $arr['uid'] = $page_owner_uid;
332 $arr['parent-uri'] = $uri;
333 $arr['type'] = 'photo';
335 $arr['resource-id'] = $p[0]['resource-id'];
336 $arr['contact-id'] = $owner_record['id'];
337 $arr['owner-name'] = $owner_record['name'];
338 $arr['owner-link'] = $owner_record['url'];
339 $arr['owner-avatar'] = $owner_record['thumb'];
340 $arr['author-name'] = $owner_record['name'];
341 $arr['author-link'] = $owner_record['url'];
342 $arr['author-avatar'] = $owner_record['thumb'];
343 $arr['title'] = $title;
344 $arr['allow_cid'] = $p[0]['allow_cid'];
345 $arr['allow_gid'] = $p[0]['allow_gid'];
346 $arr['deny_cid'] = $p[0]['deny_cid'];
347 $arr['deny_gid'] = $p[0]['deny_gid'];
348 $arr['last-child'] = 1;
349 $arr['visible'] = $visibility;
351 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
352 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]'
355 $item_id = item_store($arr);
360 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
362 intval($page_owner_uid)
366 $old_tag = $r[0]['tag'];
367 $old_inform = $r[0]['inform'];
370 if(strlen($rawtags)) {
375 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
377 $x = substr($rawtags,0,1);
378 if($x !== '@' && $x !== '#')
379 $rawtags = '#' . $rawtags;
382 $tags = get_tags($rawtags);
385 foreach($tags as $tag) {
388 if(strpos($tag,'@') === 0) {
389 $name = substr($tag,1);
390 if((strpos($name,'@')) || (strpos($name,'http://'))) {
392 $links = @lrdd($name);
394 foreach($links as $link) {
395 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
396 $profile = $link['@attributes']['href'];
397 if($link['@attributes']['rel'] === 'salmon') {
398 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
405 $taginfo[] = array($newname,$profile,$salmon);
409 if(strstr($name,'_') || strstr($name,' ')) {
410 $newname = str_replace('_',' ',$name);
411 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
413 intval($page_owner_uid)
417 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
419 intval($page_owner_uid)
423 $newname = $r[0]['name'];
424 $profile = $r[0]['url'];
425 $notify = 'cid:' . $r[0]['id'];
432 if(substr($notify,0,4) === 'cid:')
433 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
435 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
436 if(strlen($str_tags))
438 $profile = str_replace(',','%2c',$profile);
439 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
446 if(strlen($newtag) && strlen($str_tags))
448 $newtag .= $str_tags;
450 $newinform = $old_inform;
451 if(strlen($newinform) && strlen($inform))
453 $newinform .= $inform;
455 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
458 dbesc(datetime_convert()),
459 dbesc(datetime_convert()),
461 intval($page_owner_uid)
465 foreach($p as $scales) {
466 if(intval($scales['scale']) == 2) {
470 if(intval($scales['scale']) == 4) {
476 if(count($taginfo)) {
477 foreach($taginfo as $tagged) {
479 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
483 $arr['uid'] = $page_owner_uid;
485 $arr['parent-uri'] = $uri;
486 $arr['type'] = 'activity';
488 $arr['contact-id'] = $owner_record['id'];
489 $arr['owner-name'] = $owner_record['name'];
490 $arr['owner-link'] = $owner_record['url'];
491 $arr['owner-avatar'] = $owner_record['thumb'];
492 $arr['author-name'] = $owner_record['name'];
493 $arr['author-link'] = $owner_record['url'];
494 $arr['author-avatar'] = $owner_record['thumb'];
496 $arr['allow_cid'] = $p[0]['allow_cid'];
497 $arr['allow_gid'] = $p[0]['allow_gid'];
498 $arr['deny_cid'] = $p[0]['deny_cid'];
499 $arr['deny_gid'] = $p[0]['deny_gid'];
500 $arr['last-child'] = 1;
502 $arr['verb'] = ACTIVITY_TAG;
503 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
504 $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
505 $arr['tag'] = $tagged[4];
506 $arr['inform'] = $tagged[2];
508 $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]' ;
509 $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" ;
511 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
512 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
514 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $tagged[3]['photo'] . '" />' . "\n");
515 $arr['object'] .= '</link></object>' . "\n";
517 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
518 . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
519 $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>';
521 $item_id = item_store($arr);
523 q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
524 dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
525 intval($page_owner_uid),
529 proc_run('php',"include/notifier.php","tag","$item_id");
536 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
537 return; // NOTREACHED
542 * default post action - upload a photo
545 call_hooks('photo_post_init', $_POST);
548 * Determine the album to use
551 $album = notags(trim($_REQUEST['album']));
552 $newalbum = notags(trim($_REQUEST['newalbum']));
554 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , 'LOGGER_DEBUG');
556 if(! strlen($album)) {
557 if(strlen($newalbum))
560 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
565 * We create a wall item for every photo, but we don't want to
566 * overwhelm the data stream with a hundred newly uploaded photos.
567 * So we will make the first photo uploaded to this album in the last several hours
568 * visible by default, the rest will become visible over time when and if
569 * they acquire comments, likes, dislikes, and/or tags
573 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
575 intval($page_owner_uid)
577 if((! count($r)) || ($album == t('Profile Photos')))
582 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
583 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
584 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
585 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
587 $ret = array('src' => '', 'filename' => '', 'filesize' => 0);
589 call_hooks('photo_post_file',$ret);
591 if(x($ret,'src') && x($ret,'filesize')) {
593 $filename = $ret['filename'];
594 $filesize = $ret['filesize'];
597 $src = $_FILES['userfile']['tmp_name'];
598 $filename = basename($_FILES['userfile']['name']);
599 $filesize = intval($_FILES['userfile']['size']);
603 logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ' . $filesize . ' bytes', LOGGER_DEBUG);
605 $maximagesize = get_config('system','maximagesize');
607 if(($maximagesize) && ($filesize > $maximagesize)) {
608 notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
611 call_hooks('photo_post_end',$foo);
616 notice( t('Image file is empty.') . EOL);
619 call_hooks('photo_post_end',$foo);
623 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , 'LOGGER_DEBUG');
625 $imagedata = @file_get_contents($src);
626 $ph = new Photo($imagedata);
628 if(! $ph->is_valid()) {
629 logger('mod/photos.php: photos_post(): unable to process image' , 'LOGGER_DEBUG');
630 notice( t('Unable to process image.') . EOL );
633 call_hooks('photo_post_end',$foo);
639 $width = $ph->getWidth();
640 $height = $ph->getHeight();
644 $photo_hash = photo_new_resource();
646 $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);
649 logger('mod/photos.php: photos_post(): image store failed' , 'LOGGER_DEBUG');
650 notice( t('Image upload failed.') . EOL );
654 if($width > 640 || $height > 640) {
655 $ph->scaleImage(640);
656 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
660 if($width > 320 || $height > 320) {
661 $ph->scaleImage(320);
662 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
666 $basename = basename($filename);
667 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
669 // Create item container
673 $arr['uid'] = $page_owner_uid;
675 $arr['parent-uri'] = $uri;
676 $arr['type'] = 'photo';
678 $arr['resource-id'] = $photo_hash;
679 $arr['contact-id'] = $owner_record['id'];
680 $arr['owner-name'] = $owner_record['name'];
681 $arr['owner-link'] = $owner_record['url'];
682 $arr['owner-avatar'] = $owner_record['thumb'];
683 $arr['author-name'] = $owner_record['name'];
684 $arr['author-link'] = $owner_record['url'];
685 $arr['author-avatar'] = $owner_record['thumb'];
687 $arr['allow_cid'] = $str_contact_allow;
688 $arr['allow_gid'] = $str_group_allow;
689 $arr['deny_cid'] = $str_contact_deny;
690 $arr['deny_gid'] = $str_group_deny;
691 $arr['last-child'] = 1;
692 $arr['visible'] = $visible;
693 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
694 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
697 $item_id = item_store($arr);
700 q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
701 dbesc($a->get_baseurl() . '/display/' . $owner_record['nickname'] . '/' . $item_id),
702 intval($page_owner_uid),
708 proc_run('php', "include/notifier.php", 'wall-new', $item_id);
710 call_hooks('photo_post_end',intval($item_id));
712 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
713 // if they do not wish to be redirected
715 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
721 function photos_content(&$a) {
725 // photos/name/upload
726 // photos/name/album/xxxxx
727 // photos/name/album/xxxxx/edit
728 // photos/name/image/xxxxx
729 // photos/name/image/xxxxx/edit
732 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
733 notice( t('Public access denied.') . EOL);
738 require_once('include/bbcode.php');
739 require_once('include/security.php');
740 require_once('include/conversation.php');
742 if(! x($a->data,'user')) {
743 notice( t('No photos selected') . EOL );
747 $_SESSION['photo_return'] = $a->cmd;
754 $datatype = $a->argv[2];
755 $datum = $a->argv[3];
757 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
758 $datatype = 'upload';
760 $datatype = 'summary';
768 // Setup permissions structures
774 $remote_contact = false;
776 $owner_uid = $a->data['user']['uid'];
778 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
780 if((local_user()) && (local_user() == $owner_uid))
783 if($community_page && remote_user()) {
784 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
785 intval(remote_user()),
791 $remote_contact = true;
792 $visitor = remote_user();
797 // perhaps they're visiting - but not a community page, so they wouldn't have write access
799 if(remote_user() && (! $visitor)) {
800 $contact_id = $_SESSION['visitor_id'];
801 $groups = init_groups_visitor($contact_id);
802 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
803 intval(remote_user()),
808 $remote_contact = true;
812 if(! $remote_contact) {
814 $contact_id = $_SESSION['cid'];
815 $contact = $a->contact;
819 if($a->data['user']['hidewall'] && (local_user() != $owner_uid) && (! $remote_contact)) {
820 notice( t('Access to this item is restricted.') . EOL);
824 $sql_extra = permissions_sql($owner_uid,$remote_contact,$groups);
829 $tpl = get_markup_template('profile_tabs.tpl');
830 $_is_owner = (local_user() && (local_user() == $owner_uid));
831 $o .= replace_macros($tpl,array(
832 '$url' => $a->get_baseurl() . '/profile/' .$a->data['user']['nickname'],
833 '$phototab' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
834 '$status' => t('Status'),
835 '$profile' => t('Profile'),
836 '$photos' => t('Photos'),
837 '$events' => (($_is_owner) ? t('Events') : ''),
838 '$notes' => (($_is_owner) ? t('Personal Notes') : ''),
839 '$activetab' => "photos",
847 if($datatype === 'upload') {
849 notice( t('Permission denied.'));
852 $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
854 $albumselect .= '<option value="" selected="selected" > </option>';
855 if(count($a->data['albums'])) {
856 foreach($a->data['albums'] as $album) {
857 if(($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
859 $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
863 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
865 $albumselect .= '</select>';
869 $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
870 'addon_text' => $uploader,
871 'default_upload' => true);
874 call_hooks('photo_upload_form',$ret);
876 $default_upload = '<input type="file" name="userfile" /> <div class="photos-upload-submit-wrapper" >
877 <input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>';
882 $tpl = get_markup_template('photos_upload.tpl');
883 $o .= replace_macros($tpl,array(
884 '$pagename' => t('Upload Photos'),
885 '$sessid' => session_id(),
886 '$nickname' => $a->data['user']['nickname'],
887 '$newalbum' => t('New album name: '),
888 '$existalbumtext' => t('or existing album name: '),
889 '$albumselect' => $albumselect,
890 '$permissions' => t('Permissions'),
891 '$aclselect' => (($visitor) ? '' : populate_acl($a->user, $celeb)),
892 '$uploader' => $ret['addon_text'],
893 '$default' => (($ret['default_upload']) ? $default_upload : ''),
894 '$uploadurl' => $ret['post_url']
901 if($datatype === 'album') {
903 $album = hex2bin($datum);
905 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
906 AND `scale` <= 4 $sql_extra GROUP BY `resource-id`",
911 $a->set_pager_total(count($r));
912 $a->set_pager_itemspage(20);
915 $r = q("SELECT `resource-id`, `id`, `filename`, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
916 AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
919 intval($a->pager['start']),
920 intval($a->pager['itemspage'])
923 $o .= '<h3>' . $album . '</h3>';
925 if($cmd === 'edit') {
926 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
928 $edit_tpl = get_markup_template('album_edit.tpl');
929 $o .= replace_macros($edit_tpl,array(
930 '$nametext' => t('New album name: '),
931 '$nickname' => $a->data['user']['nickname'],
933 '$hexalbum' => bin2hex($album),
934 '$submit' => t('Submit'),
935 '$dropsubmit' => t('Delete Album')
941 if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
943 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
944 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
945 . t('Edit Album') . '</a></div>';
949 $tpl = get_markup_template('photo_album.tpl');
952 $o .= replace_macros($tpl,array(
954 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
955 '$phototitle' => t('View Photo'),
956 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
957 '$imgalt' => $rr['filename'],
958 '$desc'=> $rr['desc']
962 $o .= '<div id="photo-album-end"></div>';
970 if($datatype === 'image') {
975 // fetch image, item containing image, then comments
977 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
978 $sql_extra ORDER BY `scale` ASC ",
984 notice( t('Photo not available') . EOL );
991 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
992 $sql_extra ORDER BY `created` DESC ",
993 dbesc($ph[0]['album']),
998 for($z = 0; $z < count($prvnxt); $z++) {
999 if($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
1003 $prv = count($prvnxt) - 1;
1004 if($nxt >= count($prvnxt))
1009 $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] ;
1010 $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] ;
1015 $hires = $lores = $ph[0];
1016 if(count($ph) > 1) {
1017 if($ph[1]['scale'] == 2) {
1018 // original is 640 or less, we can display it directly
1019 $hires = $lores = $ph[0];
1027 $album_link = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
1031 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
1033 'edit' => array($a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/edit', t('Edit photo')),
1034 'profile'=>array($a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
1038 $lock = ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
1039 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
1040 ? t('Private Message')
1047 $prevlink = array($prevlink, '<div class="icon prev"></div>') ;
1050 'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg',
1051 'title'=> t('View Full Size'),
1052 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg'
1056 $nextlink = array($nextlink, '<div class="icon next"></div>');
1059 // Do we have an item for this photo?
1061 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1064 if(count($linked_items)) {
1065 $link_item = $linked_items[0];
1066 $r = q("SELECT COUNT(*) AS `total`
1067 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1068 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
1069 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1070 AND `item`.`uid` = %d
1072 dbesc($link_item['uri']),
1073 dbesc($link_item['uri']),
1074 intval($link_item['uid'])
1079 $a->set_pager_total($r[0]['total']);
1082 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1083 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1084 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1085 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1086 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1087 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
1088 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1089 AND `item`.`uid` = %d
1091 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1092 dbesc($link_item['uri']),
1093 dbesc($link_item['uri']),
1094 intval($link_item['uid']),
1095 intval($a->pager['start']),
1096 intval($a->pager['itemspage'])
1100 if((local_user()) && (local_user() == $link_item['uid'])) {
1101 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1102 intval($link_item['parent']),
1103 intval(local_user())
1110 if(count($linked_items) && strlen($link_item['tag'])) {
1111 $arr = explode(',',$link_item['tag']);
1112 // parse tags and add links
1114 foreach($arr as $t) {
1115 if(strlen($tag_str))
1117 $tag_str .= bbcode($t);
1119 $tags = array(t('Tags: '), $tag_str);
1120 if($cmd === 'edit') {
1121 $tags[] = $a->get_baseurl() . '/tagrm/' . $link_item['id'];
1122 $tags[] = t('[Remove any tag]');
1128 if(($cmd === 'edit') && ($can_post)) {
1129 $edit_tpl = get_markup_template('photo_edit.tpl');
1130 $edit = replace_macros($edit_tpl, array(
1131 '$id' => $ph[0]['id'],
1132 '$album' => $ph[0]['album'],
1133 '$newalbum' => t('New album name'),
1134 '$nickname' => $a->data['user']['nickname'],
1135 '$resource_id' => $ph[0]['resource-id'],
1136 '$capt_label' => t('Caption'),
1137 '$caption' => $ph[0]['desc'],
1138 '$tag_label' => t('Add a Tag'),
1139 '$tags' => $link_item['tag'],
1140 '$permissions' => t('Permissions'),
1141 '$aclselect' => populate_acl($ph[0]),
1142 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
1143 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1144 '$submit' => t('Submit'),
1145 '$delete' => t('Delete Photo')
1149 if(count($linked_items)) {
1151 $cmnt_tpl = get_markup_template('comment_item.tpl');
1152 $tpl = get_markup_template('photo_item.tpl');
1153 $return_url = $a->cmd;
1155 $like_tpl = get_markup_template('like_noshare.tpl');
1159 if($can_post || can_write_wall($a,$owner_uid)) {
1160 $likebuttons = replace_macros($like_tpl,array(
1161 '$id' => $link_item['id'],
1162 '$likethis' => t("I like this \x28toggle\x29"),
1163 '$nolike' => t("I don't like this \x28toggle\x29"),
1164 '$share' => t('Share'),
1165 '$wait' => t('Please wait')
1171 if($can_post || can_write_wall($a,$owner_uid)) {
1172 if($link_item['last-child']) {
1173 $comments .= replace_macros($cmnt_tpl,array(
1174 '$return_path' => '',
1175 '$jsreload' => $return_url,
1176 '$type' => 'wall-comment',
1177 '$id' => $link_item['id'],
1178 '$parent' => $link_item['id'],
1179 '$profile_uid' => $owner_uid,
1180 '$mylink' => $contact['url'],
1181 '$mytitle' => t('This is you'),
1182 '$myphoto' => $contact['thumb'],
1183 '$comment' => t('Comment'),
1184 '$submit' => t('Submit'),
1200 foreach($r as $item) {
1201 like_puller($a,$item,$alike,'like');
1202 like_puller($a,$item,$dlike,'dislike');
1205 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
1206 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
1210 if($can_post || can_write_wall($a,$owner_uid)) {
1211 if($link_item['last-child']) {
1212 $comments .= replace_macros($cmnt_tpl,array(
1213 '$return_path' => '',
1214 '$jsreload' => $return_url,
1215 '$type' => 'wall-comment',
1216 '$id' => $link_item['id'],
1217 '$parent' => $link_item['id'],
1218 '$profile_uid' => $owner_uid,
1219 '$mylink' => $contact['url'],
1220 '$mytitle' => t('This is you'),
1221 '$myphoto' => $contact['thumb'],
1222 '$comment' => t('Comment'),
1223 '$submit' => t('Submit'),
1230 foreach($r as $item) {
1235 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1238 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1240 if($can_post || can_write_wall($a,$owner_uid)) {
1242 if($item['last-child']) {
1243 $comments .= replace_macros($cmnt_tpl,array(
1244 '$return_path' => '',
1245 '$jsreload' => $return_url,
1246 '$type' => 'wall-comment',
1247 '$id' => $item['item_id'],
1248 '$parent' => $item['parent'],
1249 '$profile_uid' => $owner_uid,
1250 '$mylink' => $contact['url'],
1251 '$mytitle' => t('This is you'),
1252 '$myphoto' => $contact['thumb'],
1253 '$comment' => t('Comment'),
1254 '$submit' => t('Submit'),
1261 if(local_user() && ($item['contact-uid'] == local_user())
1262 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
1263 $profile_url = $redirect_url;
1264 $sparkle = ' sparkle';
1267 $profile_url = $item['url'];
1271 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1273 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1274 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1276 $profile_link = $profile_url;
1280 if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
1281 $drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
1284 $comments .= replace_macros($template,array(
1285 '$id' => $item['item_id'],
1286 '$profile_url' => $profile_link,
1287 '$name' => $profile_name,
1288 '$thumb' => $profile_avatar,
1289 '$sparkle' => $sparkle,
1290 '$title' => $item['title'],
1291 '$body' => bbcode($item['body']),
1292 '$ago' => relative_date($item['created']),
1293 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1295 '$comment' => $comment
1300 $paginate = paginate($a);
1303 $photo_tpl = get_markup_template('photo_view.tpl');
1304 $o .= replace_macros($photo_tpl, array(
1305 '$id' => $ph[0]['id'],
1306 '$album' => array($album_link,$ph[0]['album']),
1310 '$prevlink' => $prevlink,
1311 '$nextlink' => $nextlink,
1312 '$desc' => $ph[0]['desc'],
1315 '$likebuttons' => $likebuttons,
1317 '$dislike' => $dislike,
1318 '$comments' => $comments,
1319 '$paginate' => $paginate,
1325 // Default - show recent photos with upload link (if applicable)
1328 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1329 $sql_extra GROUP BY `resource-id`",
1330 intval($a->data['user']['uid']),
1331 dbesc('Contact Photos'),
1332 dbesc( t('Contact Photos'))
1335 $a->set_pager_total(count($r));
1336 $a->set_pager_itemspage(20);
1339 $r = q("SELECT `resource-id`, `id`, `filename`, `album`, max(`scale`) AS `scale` FROM `photo`
1340 WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
1341 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1342 intval($a->data['user']['uid']),
1343 dbesc('Contact Photos'),
1344 dbesc( t('Contact Photos')),
1345 intval($a->pager['start']),
1346 intval($a->pager['itemspage'])
1349 $o .= '<h3>' . t('Recent Photos') . '</h3>';
1352 $o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
1353 . $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
1356 $tpl = get_markup_template('photo_top.tpl');
1358 foreach($r as $rr) {
1359 $o .= replace_macros($tpl,array(
1361 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1362 '$phototitle' => t('View Photo'),
1363 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.jpg',
1364 '$albumlink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1365 '$albumname' => $rr['album'],
1366 '$albumalt' => t('View Album'),
1367 '$imgalt' => $rr['filename']
1371 $o .= '<div id="photo-top-end"></div>';