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;
55 function photos_post(&$a) {
57 logger('mod/photos.php: photos_post(): begin' , 'LOGGER_DEBUG');
59 foreach($_REQUEST AS $key => $val) {
60 logger('mod/photos.php: photos_post(): $_REQUEST key: ' . $key . ' val: ' . $val , 'LOGGER_DEBUG');
63 foreach($_FILES AS $key => $val) {
64 logger('mod/photos.php: photos_post(): $_FILES key: ' . $key . ' val: ' . $val , 'LOGGER_DEBUG');
70 $page_owner_uid = $a->data['user']['uid'];
71 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
73 if((local_user()) && (local_user() == $page_owner_uid))
76 if($community_page && remote_user()) {
77 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
78 intval(remote_user()),
79 intval($page_owner_uid)
83 $visitor = remote_user();
89 notice( t('Permission denied.') . EOL );
93 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
94 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
95 intval($page_owner_uid)
99 notice( t('Contact information unavailable') . EOL);
100 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
104 $owner_record = $r[0];
107 if(($a->argc > 3) && ($a->argv[2] === 'album')) {
108 $album = hex2bin($a->argv[3]);
110 if($album == t('Profile Photos') || $album == t('Contact Photos')) {
111 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
112 return; // NOTREACHED
115 $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
117 intval($page_owner_uid)
120 notice( t('Album not found.') . EOL);
121 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
122 return; // NOTREACHED
125 $newalbum = notags(trim($_POST['albumname']));
126 if($newalbum != $album) {
127 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
130 intval($page_owner_uid)
132 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
133 goaway($a->get_baseurl() . '/' . $newurl);
134 return; // NOTREACHED
138 if($_POST['dropalbum'] == t('Delete Album')) {
142 // get the list of photos we are about to delete
145 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
147 intval($page_owner_uid),
152 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
153 intval(local_user()),
159 $res[] = "'" . dbesc($rr['rid']) . "'" ;
163 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
164 return; // NOTREACHED
167 $str_res = implode(',', $res);
169 // remove the associated photos
171 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
172 intval($page_owner_uid)
175 // find and delete the corresponding item with all the comments and likes/dislikes
177 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
178 intval($page_owner_uid)
182 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
183 dbesc(datetime_convert()),
184 dbesc($rr['parent-uri']),
185 intval($page_owner_uid)
188 $drop_id = intval($rr['id']);
190 // send the notification upstream/downstream as the case may be
193 proc_run('php',"include/notifier.php","drop","$drop_id");
197 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
198 return; // NOTREACHED
201 if(($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
203 // same as above but remove single photo
206 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
208 intval($page_owner_uid),
213 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
214 intval(local_user()),
219 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
220 intval($page_owner_uid),
221 dbesc($r[0]['resource-id'])
223 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
224 dbesc($r[0]['resource-id']),
225 intval($page_owner_uid)
228 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
229 dbesc(datetime_convert()),
230 dbesc(datetime_convert()),
232 intval($page_owner_uid)
235 $url = $a->get_baseurl();
236 $drop_id = intval($i[0]['id']);
239 proc_run('php',"include/notifier.php","drop","$drop_id");
243 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
244 return; // NOTREACHED
247 if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
249 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
250 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
251 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
252 $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
253 $str_group_allow = perms2str($_POST['group_allow']);
254 $str_contact_allow = perms2str($_POST['contact_allow']);
255 $str_group_deny = perms2str($_POST['group_deny']);
256 $str_contact_deny = perms2str($_POST['contact_deny']);
258 $resource_id = $a->argv[2];
260 if(! strlen($albname))
261 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
264 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
266 intval($page_owner_uid)
269 $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",
272 dbesc($str_contact_allow),
273 dbesc($str_group_allow),
274 dbesc($str_contact_deny),
275 dbesc($str_group_deny),
277 intval($page_owner_uid)
281 /* Don't make the item visible if the only change was the album name */
284 if($p[0]['desc'] !== $desc || strlen($rawtags))
289 // Create item container
292 $basename = basename($filename);
293 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
297 $arr['uid'] = $page_owner_uid;
299 $arr['parent-uri'] = $uri;
300 $arr['type'] = 'photo';
302 $arr['resource-id'] = $p[0]['resource-id'];
303 $arr['contact-id'] = $owner_record['id'];
304 $arr['owner-name'] = $owner_record['name'];
305 $arr['owner-link'] = $owner_record['url'];
306 $arr['owner-avatar'] = $owner_record['thumb'];
307 $arr['author-name'] = $owner_record['name'];
308 $arr['author-link'] = $owner_record['url'];
309 $arr['author-avatar'] = $owner_record['thumb'];
310 $arr['title'] = $title;
311 $arr['allow_cid'] = $p[0]['allow_cid'];
312 $arr['allow_gid'] = $p[0]['allow_gid'];
313 $arr['deny_cid'] = $p[0]['deny_cid'];
314 $arr['deny_gid'] = $p[0]['deny_gid'];
315 $arr['last-child'] = 1;
316 $arr['visible'] = $visibility;
318 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
319 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]'
322 $item_id = item_store($arr);
327 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
329 intval($page_owner_uid)
333 $old_tag = $r[0]['tag'];
334 $old_inform = $r[0]['inform'];
337 if(strlen($rawtags)) {
342 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
344 $x = substr($rawtags,0,1);
345 if($x !== '@' && $x !== '#')
346 $rawtags = '#' . $rawtags;
349 $tags = get_tags($rawtags);
352 foreach($tags as $tag) {
353 if(strpos($tag,'@') === 0) {
354 $name = substr($tag,1);
355 if((strpos($name,'@')) || (strpos($name,'http://'))) {
357 $links = @lrdd($name);
359 foreach($links as $link) {
360 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
361 $profile = $link['@attributes']['href'];
362 if($link['@attributes']['rel'] === 'salmon') {
363 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
370 $taginfo[] = array($newname,$profile,$salmon);
374 if(strstr($name,'_')) {
375 $newname = str_replace('_',' ',$name);
376 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
378 intval($page_owner_uid)
382 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
384 intval($page_owner_uid)
388 $newname = $r[0]['name'];
389 $profile = $r[0]['url'];
390 $notify = 'cid:' . $r[0]['id'];
397 if(substr($notify,0,4) === 'cid:')
398 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
400 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
401 if(strlen($str_tags))
403 $profile = str_replace(',','%2c',$profile);
404 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
411 if(strlen($newtag) && strlen($str_tags))
413 $newtag .= $str_tags;
415 $newinform = $old_inform;
416 if(strlen($newinform) && strlen($inform))
418 $newinform .= $inform;
420 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
423 dbesc(datetime_convert()),
424 dbesc(datetime_convert()),
426 intval($page_owner_uid)
430 foreach($p as $scales) {
431 if(intval($scales['scale']) == 2) {
435 if(intval($scales['scale']) == 4) {
441 if(count($taginfo)) {
442 foreach($taginfo as $tagged) {
444 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
448 $arr['uid'] = $page_owner_uid;
450 $arr['parent-uri'] = $uri;
451 $arr['type'] = 'activity';
453 $arr['contact-id'] = $owner_record['id'];
454 $arr['owner-name'] = $owner_record['name'];
455 $arr['owner-link'] = $owner_record['url'];
456 $arr['owner-avatar'] = $owner_record['thumb'];
457 $arr['author-name'] = $owner_record['name'];
458 $arr['author-link'] = $owner_record['url'];
459 $arr['author-avatar'] = $owner_record['thumb'];
461 $arr['allow_cid'] = $p[0]['allow_cid'];
462 $arr['allow_gid'] = $p[0]['allow_gid'];
463 $arr['deny_cid'] = $p[0]['deny_cid'];
464 $arr['deny_gid'] = $p[0]['deny_gid'];
465 $arr['last-child'] = 1;
467 $arr['verb'] = ACTIVITY_TAG;
468 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
469 $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
470 $arr['tag'] = $tagged[4];
471 $arr['inform'] = $tagged[2];
473 $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]' ;
474 $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" ;
476 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
477 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
479 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $tagged[3]['photo'] . '" />' . "\n");
480 $arr['object'] .= '</link></object>' . "\n";
482 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
483 . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
484 $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>';
486 $item_id = item_store($arr);
488 proc_run('php',"include/notifier.php","tag","$item_id");
494 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
495 return; // NOTREACHED
500 * default post action - upload a photo
503 call_hooks('photo_post_init', $_POST);
506 * Determine the album to use
509 $album = notags(trim($_REQUEST['album']));
510 $newalbum = notags(trim($_REQUEST['newalbum']));
512 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , 'LOGGER_DEBUG');
514 if(! strlen($album)) {
515 if(strlen($newalbum))
518 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
523 * We create a wall item for every photo, but we don't want to
524 * overwhelm the data stream with a hundred newly uploaded photos.
525 * So we will make one photo (the first one uploaded to this album)
526 * visible by default, the rest will become visible over time when and if
527 * they acquire comments, likes, dislikes, and/or tags
531 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
533 intval($page_owner_uid)
535 if((! count($r)) || ($album == t('Profile Photos')))
540 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
541 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
542 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
543 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
545 $ret = array('src' => '', 'filename' => '', 'filesize' => 0);
547 call_hooks('photo_post_file',$ret);
549 if(x($ret,'src') && x($ret,'filesize')) {
551 $filename = $ret['filename'];
552 $filesize = $ret['filesize'];
555 $src = $_FILES['userfile']['tmp_name'];
556 $filename = basename($_FILES['userfile']['name']);
557 $filesize = intval($_FILES['userfile']['size']);
560 $maximagesize = get_config('system','maximagesize');
562 if(($maximagesize) && ($filesize > $maximagesize)) {
563 notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
568 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , 'LOGGER_DEBUG');
570 $imagedata = @file_get_contents($src);
571 $ph = new Photo($imagedata);
573 if(! $ph->is_valid()) {
574 logger('mod/photos.php: photos_post(): unable to process image' , 'LOGGER_DEBUG');
575 notice( t('Unable to process image.') . EOL );
582 $width = $ph->getWidth();
583 $height = $ph->getHeight();
587 $photo_hash = photo_new_resource();
589 $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);
592 logger('mod/photos.php: photos_post(): image store failed' , 'LOGGER_DEBUG');
593 notice( t('Image upload failed.') . EOL );
597 if($width > 640 || $height > 640) {
598 $ph->scaleImage(640);
599 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
603 if($width > 320 || $height > 320) {
604 $ph->scaleImage(320);
605 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
609 $basename = basename($filename);
610 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
612 // Create item container
616 $arr['uid'] = $page_owner_uid;
618 $arr['parent-uri'] = $uri;
619 $arr['type'] = 'photo';
621 $arr['resource-id'] = $photo_hash;
622 $arr['contact-id'] = $owner_record['id'];
623 $arr['owner-name'] = $owner_record['name'];
624 $arr['owner-link'] = $owner_record['url'];
625 $arr['owner-avatar'] = $owner_record['thumb'];
626 $arr['author-name'] = $owner_record['name'];
627 $arr['author-link'] = $owner_record['url'];
628 $arr['author-avatar'] = $owner_record['thumb'];
630 $arr['allow_cid'] = $str_contact_allow;
631 $arr['allow_gid'] = $str_group_allow;
632 $arr['deny_cid'] = $str_contact_deny;
633 $arr['deny_gid'] = $str_group_deny;
634 $arr['last-child'] = 1;
635 $arr['visible'] = $visible;
636 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
637 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
640 $item_id = item_store($arr);
643 proc_run('php', "include/notifier.php", 'wall-new', $item_id);
645 call_hooks('photo_post_end',intval($item_id));
647 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
648 // if they do not wish to be redirected
650 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
656 function photos_content(&$a) {
660 // photos/name/upload
661 // photos/name/album/xxxxx
662 // photos/name/album/xxxxx/edit
663 // photos/name/image/xxxxx
664 // photos/name/image/xxxxx/edit
667 if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
668 notice( t('Public access denied.') . EOL);
673 require_once('include/bbcode.php');
674 require_once('include/security.php');
675 require_once('include/conversation.php');
677 if(! x($a->data,'user')) {
678 notice( t('No photos selected') . EOL );
682 $_SESSION['photo_return'] = $a->cmd;
689 $datatype = $a->argv[2];
690 $datum = $a->argv[3];
692 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
693 $datatype = 'upload';
695 $datatype = 'summary';
703 // Setup permissions structures
709 $remote_contact = false;
711 $owner_uid = $a->data['user']['uid'];
713 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
715 if((local_user()) && (local_user() == $owner_uid))
718 if($community_page && remote_user()) {
719 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
720 intval(remote_user()),
726 $remote_contact = true;
727 $visitor = remote_user();
732 // perhaps they're visiting - but not a community page, so they wouldn't have write access
734 if(remote_user() && (! $visitor)) {
735 $contact_id = $_SESSION['visitor_id'];
736 $groups = init_groups_visitor($contact_id);
737 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
738 intval(remote_user()),
743 $remote_contact = true;
747 if(! $remote_contact) {
749 $contact_id = $_SESSION['cid'];
750 $contact = $a->contact;
754 // default permissions - anonymous user
756 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
758 // Profile owner - everything is visible
760 if(local_user() && (local_user() == $owner_uid)) {
763 elseif(remote_user()) {
764 // authenticated visitor - here lie dragons
765 $gs = '<<>>'; // should be impossible to match
767 foreach($groups as $g)
768 $gs .= '|<' . intval($g) . '>';
770 $sql_extra = sprintf(
771 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
772 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
773 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
774 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
776 intval(remote_user()),
777 intval(remote_user()),
788 if($datatype === 'upload') {
790 notice( t('Permission denied.'));
793 $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
795 $albumselect .= '<option value="" selected="selected" > </option>';
796 if(count($a->data['albums'])) {
797 foreach($a->data['albums'] as $album) {
798 if(($album['album'] === '') || ($album['album'] == t('Contact Photos')))
800 $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
804 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
806 $albumselect .= '</select>';
810 $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
811 'addon_text' => $uploader,
812 'default_upload' => true);
815 call_hooks('photo_upload_form',$ret);
817 $default_upload = '<input type="file" name="userfile" /> <div class="photos-upload-submit-wrapper" >
818 <input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>';
823 $tpl = load_view_file('view/photos_upload.tpl');
824 $o .= replace_macros($tpl,array(
825 '$pagename' => t('Upload Photos'),
826 '$sessid' => session_id(),
827 '$nickname' => $a->data['user']['nickname'],
828 '$newalbum' => t('New album name: '),
829 '$existalbumtext' => t('or existing album name: '),
830 '$albumselect' => $albumselect,
831 '$permissions' => t('Permissions'),
832 '$aclselect' => (($visitor) ? '' : populate_acl($a->user, $celeb)),
833 '$uploader' => $ret['addon_text'],
834 '$default' => (($ret['default_upload']) ? $default_upload : ''),
835 '$uploadurl' => $ret['post_url']
842 if($datatype === 'album') {
844 $album = hex2bin($datum);
846 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
847 $sql_extra GROUP BY `resource-id`",
852 $a->set_pager_total(count($r));
853 $a->set_pager_itemspage(20);
856 $r = q("SELECT `resource-id`, `id`, `filename`, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
857 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
860 intval($a->pager['start']),
861 intval($a->pager['itemspage'])
864 $o .= '<h3>' . $album . '</h3>';
866 if($cmd === 'edit') {
867 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
869 $edit_tpl = load_view_file('view/album_edit.tpl');
870 $o .= replace_macros($edit_tpl,array(
871 '$nametext' => t('New album name: '),
872 '$nickname' => $a->data['user']['nickname'],
874 '$hexalbum' => bin2hex($album),
875 '$submit' => t('Submit'),
876 '$dropsubmit' => t('Delete Album')
882 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
884 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
885 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
886 . t('Edit Album') . '</a></div>';
890 $tpl = load_view_file('view/photo_album.tpl');
893 $o .= replace_macros($tpl,array(
895 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
896 '$phototitle' => t('View Photo'),
897 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
898 '$imgalt' => $rr['filename'],
899 '$desc'=> $rr['desc']
903 $o .= '<div id="photo-album-end"></div>';
911 if($datatype === 'image') {
915 $o = '<div id="live-display"></div>' . "\r\n";
916 // fetch image, item containing image, then comments
918 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
919 $sql_extra ORDER BY `scale` ASC ",
925 notice( t('Photo not available') . EOL );
932 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
933 $sql_extra ORDER BY `created` DESC ",
934 dbesc($ph[0]['album']),
939 for($z = 0; $z < count($prvnxt); $z++) {
940 if($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
944 $prv = count($prvnxt) - 1;
945 if($nxt >= count($prvnxt))
950 $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] ;
951 $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] ;
956 $hires = $lores = $ph[0];
958 if($ph[1]['scale'] == 2) {
959 // original is 640 or less, we can display it directly
960 $hires = $lores = $ph[0];
969 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']) . '">' . $ph[0]['album'] . '</a></h3>';
971 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
972 $o .= '<div id="photo-edit-link-wrap" ><a id="photo-edit-link" href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . '/edit' . '">' . t('Edit photo') . '</a>';
974 $o .= ' - <a id="photo-toprofile-link" href="' . $a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'].'">'.t('Use as profile photo').'</a>';
976 $o .= ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
977 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
978 ? ' - <img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,\'photo/' . $ph[0]['id'] . '\');" />'
985 $o .= '<div id="photo-prev-link"><a href="' . $prevlink .'">' . t('<< Prev') . '</a></div>' ;
987 $o .= '<div id="photo-photo"><a href="' . $a->get_baseurl() . '/photo/'
988 . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg" title="'
989 . t('View Full Size') . '" ><img src="' . $a->get_baseurl() . '/photo/'
990 . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg' . '" /></a></div>';
993 $o .= '<div id="photo-next-link"><a href="' . $nextlink .'">' . t('Next >>') . '</a></div>';
995 $o .= '<div id="photo-photo-end"></div>';
998 // Do we have an item for this photo?
1000 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
1003 if(count($linked_items)) {
1004 $link_item = $linked_items[0];
1005 $r = q("SELECT COUNT(*) AS `total`
1006 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1007 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
1008 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1009 AND `item`.`uid` = %d
1011 dbesc($link_item['uri']),
1012 dbesc($link_item['uri']),
1013 intval($link_item['uid'])
1018 $a->set_pager_total($r[0]['total']);
1021 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1022 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1023 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1024 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1025 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1026 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
1027 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1028 AND `item`.`uid` = %d
1030 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1031 dbesc($link_item['uri']),
1032 dbesc($link_item['uri']),
1033 intval($link_item['uid']),
1034 intval($a->pager['start']),
1035 intval($a->pager['itemspage'])
1039 if((local_user()) && (local_user() == $link_item['uid'])) {
1040 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1041 intval($link_item['parent']),
1042 intval(local_user())
1047 $o .= '<div id="photo-caption" >' . $ph[0]['desc'] . '</div>';
1049 if(count($linked_items) && strlen($link_item['tag'])) {
1050 $arr = explode(',',$link_item['tag']);
1051 // parse tags and add links
1052 $o .= '<div id="in-this-photo-text">' . t('Tags: ') . '</div>';
1053 $o .= '<div id="in-this-photo">';
1055 foreach($arr as $t) {
1056 if(strlen($tag_str))
1058 $tag_str .= bbcode($t);
1060 $o .= $tag_str . '</div>';
1062 $o .= '<div id="tag-remove"><a href="' . $a->get_baseurl() . '/tagrm/' . $link_item['id'] . '">' . t('[Remove any tag]') . '</a></div>';
1066 if(($cmd === 'edit') && ($can_post)) {
1067 $edit_tpl = load_view_file('view/photo_edit.tpl');
1068 $o .= replace_macros($edit_tpl, array(
1069 '$id' => $ph[0]['id'],
1070 '$album' => $ph[0]['album'],
1071 '$newalbum' => t('New album name'),
1072 '$nickname' => $a->data['user']['nickname'],
1073 '$resource_id' => $ph[0]['resource-id'],
1074 '$capt_label' => t('Caption'),
1075 '$caption' => $ph[0]['desc'],
1076 '$tag_label' => t('Add a Tag'),
1077 '$tags' => $link_item['tag'],
1078 '$permissions' => t('Permissions'),
1079 '$aclselect' => populate_acl($ph[0]),
1080 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
1081 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1082 '$submit' => t('Submit'),
1083 '$delete' => t('Delete Photo')
1087 if(count($linked_items)) {
1089 $cmnt_tpl = load_view_file('view/comment_item.tpl');
1090 $tpl = load_view_file('view/photo_item.tpl');
1091 $return_url = $a->cmd;
1093 $like_tpl = load_view_file('view/like_noshare.tpl');
1097 if($can_post || can_write_wall($a,$owner_uid)) {
1098 $likebuttons = replace_macros($like_tpl,array(
1099 '$id' => $item['id'],
1100 '$likethis' => t("I like this \x28toggle\x29"),
1101 '$nolike' => t("I don't like this \x28toggle\x29"),
1102 '$share' => t('Share'),
1103 '$wait' => t('Please wait')
1108 $o .= '<div id="photo-like-div">';
1112 if($can_post || can_write_wall($a,$owner_uid)) {
1113 if($link_item['last-child']) {
1114 $o .= replace_macros($cmnt_tpl,array(
1115 '$return_path' => '',
1116 '$jsreload' => $return_url,
1117 '$type' => 'wall-comment',
1118 '$id' => $link_item['id'],
1119 '$parent' => $link_item['id'],
1120 '$profile_uid' => $owner_uid,
1121 '$mylink' => $contact['url'],
1122 '$mytitle' => t('This is you'),
1123 '$myphoto' => $contact['thumb'],
1124 '$comment' => t('Comment'),
1125 '$submit' => t('Submit'),
1138 foreach($r as $item) {
1139 like_puller($a,$item,$alike,'like');
1140 like_puller($a,$item,$dlike,'dislike');
1143 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
1144 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
1146 $o .= '<div id="photo-like-div">';
1154 if($can_post || can_write_wall($a,$owner_uid)) {
1155 if($link_item['last-child']) {
1156 $o .= replace_macros($cmnt_tpl,array(
1157 '$return_path' => '',
1158 '$jsreload' => $return_url,
1159 '$type' => 'wall-comment',
1160 '$id' => $link_item['id'],
1161 '$parent' => $link_item['id'],
1162 '$profile_uid' => $owner_uid,
1163 '$mylink' => $contact['url'],
1164 '$mytitle' => t('This is you'),
1165 '$myphoto' => $contact['thumb'],
1172 foreach($r as $item) {
1177 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1180 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1182 if($can_post || can_write_wall($a,$owner_uid)) {
1184 if($item['last-child']) {
1185 $comment = replace_macros($cmnt_tpl,array(
1186 '$return_path' => '',
1187 '$jsreload' => $return_url,
1188 '$type' => 'wall-comment',
1189 '$id' => $item['item_id'],
1190 '$parent' => $item['parent'],
1191 '$profile_uid' => $owner_uid,
1192 '$mylink' => $contact['url'],
1193 '$mytitle' => t('This is you'),
1194 '$myphoto' => $contact['thumb'],
1201 if(local_user() && ($item['contact-uid'] == local_user())
1202 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
1203 $profile_url = $redirect_url;
1204 $sparkle = ' sparkle';
1207 $profile_url = $item['url'];
1211 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1213 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1214 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1216 $profile_link = $profile_url;
1220 if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
1221 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
1224 $o .= replace_macros($template,array(
1225 '$id' => $item['item_id'],
1226 '$profile_url' => $profile_link,
1227 '$name' => $profile_name,
1228 '$thumb' => $profile_avatar,
1229 '$sparkle' => $sparkle,
1230 '$title' => $item['title'],
1231 '$body' => bbcode($item['body']),
1232 '$ago' => relative_date($item['created']),
1233 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1235 '$comment' => $comment
1245 // Default - show recent photos with upload link (if applicable)
1248 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
1249 $sql_extra GROUP BY `resource-id`",
1250 intval($a->data['user']['uid']),
1251 dbesc( t('Contact Photos'))
1254 $a->set_pager_total(count($r));
1255 $a->set_pager_itemspage(20);
1258 $r = q("SELECT `resource-id`, `id`, `filename`, `album`, max(`scale`) AS `scale` FROM `photo`
1259 WHERE `uid` = %d AND `album` != '%s'
1260 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1261 intval($a->data['user']['uid']),
1262 dbesc( t('Contact Photos')),
1263 intval($a->pager['start']),
1264 intval($a->pager['itemspage'])
1267 $o .= '<h3>' . t('Recent Photos') . '</h3>';
1270 $o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
1271 . $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
1274 $tpl = load_view_file('view/photo_top.tpl');
1276 foreach($r as $rr) {
1277 $o .= replace_macros($tpl,array(
1279 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1280 '$phototitle' => t('View Photo'),
1281 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.jpg',
1282 '$albumlink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1283 '$albumname' => $rr['album'],
1284 '$albumalt' => t('View Album'),
1285 '$imgalt' => $rr['filename']
1289 $o .= '<div id="photo-top-end"></div>';