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) {
13 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
20 $a->data['user'] = $r[0];
22 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d",
23 intval($a->data['user']['uid'])
27 $a->data['albums'] = $albums;
29 $o .= '<h4><a href="' . $a->get_baseurl() . '/profile/' . $a->data['user']['nickname'] . '">' . $a->data['user']['username'] . '</a></h4>';
30 $o .= '<h4>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h4>';
33 foreach($albums as $album) {
34 if((! strlen($album['album'])) || ($album['album'] == t('Contact Photos')))
36 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" />' . $album['album'] . '</a></li>';
41 if(! x($a->page,'aside'))
42 $a->page['aside'] = '';
43 $a->page['aside'] .= $o;
51 function photos_post(&$a) {
53 logger('mod/photos.php: photos_post(): begin' , 'LOGGER_DEBUG');
55 foreach($_REQUEST AS $key => $val) {
56 logger('mod/photos.php: photos_post(): $_REQUEST key: ' . $key . ' val: ' . $val , 'LOGGER_DEBUG');
59 foreach($_FILES AS $key => $val) {
60 logger('mod/photos.php: photos_post(): $_FILES key: ' . $key . ' val: ' . $val , 'LOGGER_DEBUG');
66 $page_owner_uid = $a->data['user']['uid'];
67 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
69 if((local_user()) && (local_user() == $page_owner_uid))
72 if($community_page && remote_user()) {
73 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
74 intval(remote_user()),
75 intval($page_owner_uid)
79 $visitor = remote_user();
85 notice( t('Permission denied.') . EOL );
89 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
90 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
91 intval($page_owner_uid)
95 notice( t('Contact information unavailable') . EOL);
96 logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
100 $owner_record = $r[0];
103 if(($a->argc > 3) && ($a->argv[2] === 'album')) {
104 $album = hex2bin($a->argv[3]);
106 if($album == t('Profile Photos') || $album == t('Contact Photos')) {
107 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
108 return; // NOTREACHED
111 $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
113 intval($page_owner_uid)
116 notice( t('Album not found.') . EOL);
117 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
118 return; // NOTREACHED
121 $newalbum = notags(trim($_POST['albumname']));
122 if($newalbum != $album) {
123 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
126 intval($page_owner_uid)
128 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
129 goaway($a->get_baseurl() . '/' . $newurl);
130 return; // NOTREACHED
134 if($_POST['dropalbum'] == t('Delete Album')) {
138 // get the list of photos we are about to delete
141 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `album` = '%s'",
143 intval($page_owner_uid),
148 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
149 intval(local_user()),
155 $res[] = "'" . dbesc($rr['rid']) . "'" ;
159 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
160 return; // NOTREACHED
163 $str_res = implode(',', $res);
165 // remove the associated photos
167 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
168 intval($page_owner_uid)
171 // find and delete the corresponding item with all the comments and likes/dislikes
173 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
174 intval($page_owner_uid)
178 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
179 dbesc(datetime_convert()),
180 dbesc($rr['parent-uri']),
181 intval($page_owner_uid)
184 $drop_id = intval($rr['id']);
186 // send the notification upstream/downstream as the case may be
189 proc_run('php',"include/notifier.php","drop","$drop_id");
193 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
194 return; // NOTREACHED
197 if(($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
199 // same as above but remove single photo
202 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
204 intval($page_owner_uid),
209 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
210 intval(local_user()),
215 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
216 intval($page_owner_uid),
217 dbesc($r[0]['resource-id'])
219 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
220 dbesc($r[0]['resource-id']),
221 intval($page_owner_uid)
224 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
225 dbesc(datetime_convert()),
226 dbesc(datetime_convert()),
228 intval($page_owner_uid)
231 $url = $a->get_baseurl();
232 $drop_id = intval($i[0]['id']);
235 proc_run('php',"include/notifier.php","drop","$drop_id");
239 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
240 return; // NOTREACHED
243 if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) {
245 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
246 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
247 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
248 $albname = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
249 $str_group_allow = perms2str($_POST['group_allow']);
250 $str_contact_allow = perms2str($_POST['contact_allow']);
251 $str_group_deny = perms2str($_POST['group_deny']);
252 $str_contact_deny = perms2str($_POST['contact_deny']);
254 $resource_id = $a->argv[2];
256 if(! strlen($albname))
257 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
260 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
262 intval($page_owner_uid)
265 $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",
268 dbesc($str_contact_allow),
269 dbesc($str_group_allow),
270 dbesc($str_contact_deny),
271 dbesc($str_group_deny),
273 intval($page_owner_uid)
277 /* Don't make the item visible if the only change was the album name */
280 if($p[0]['desc'] !== $desc || strlen($rawtags))
285 // Create item container
288 $basename = basename($filename);
289 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
293 $arr['uid'] = $page_owner_uid;
295 $arr['parent-uri'] = $uri;
296 $arr['type'] = 'photo';
298 $arr['resource-id'] = $p[0]['resource-id'];
299 $arr['contact-id'] = $owner_record['id'];
300 $arr['owner-name'] = $owner_record['name'];
301 $arr['owner-link'] = $owner_record['url'];
302 $arr['owner-avatar'] = $owner_record['thumb'];
303 $arr['author-name'] = $owner_record['name'];
304 $arr['author-link'] = $owner_record['url'];
305 $arr['author-avatar'] = $owner_record['thumb'];
306 $arr['title'] = $title;
307 $arr['allow_cid'] = $p[0]['allow_cid'];
308 $arr['allow_gid'] = $p[0]['allow_gid'];
309 $arr['deny_cid'] = $p[0]['deny_cid'];
310 $arr['deny_gid'] = $p[0]['deny_gid'];
311 $arr['last-child'] = 1;
312 $arr['visible'] = $visibility;
314 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
315 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]'
318 $item_id = item_store($arr);
323 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
325 intval($page_owner_uid)
329 $old_tag = $r[0]['tag'];
330 $old_inform = $r[0]['inform'];
333 if(strlen($rawtags)) {
338 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
340 $x = substr($rawtags,0,1);
341 if($x !== '@' && $x !== '#')
342 $rawtags = '#' . $rawtags;
345 $tags = get_tags($rawtags);
348 foreach($tags as $tag) {
349 if(strpos($tag,'@') === 0) {
350 $name = substr($tag,1);
351 if((strpos($name,'@')) || (strpos($name,'http://'))) {
353 $links = @lrdd($name);
355 foreach($links as $link) {
356 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
357 $profile = $link['@attributes']['href'];
358 if($link['@attributes']['rel'] === 'salmon') {
359 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
366 $taginfo[] = array($newname,$profile,$salmon);
370 if(strstr($name,'_')) {
371 $newname = str_replace('_',' ',$name);
372 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
374 intval($page_owner_uid)
378 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
380 intval($page_owner_uid)
384 $newname = $r[0]['name'];
385 $profile = $r[0]['url'];
386 $notify = 'cid:' . $r[0]['id'];
393 if(substr($notify,0,4) === 'cid:')
394 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
396 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
397 if(strlen($str_tags))
399 $profile = str_replace(',','%2c',$profile);
400 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
407 if(strlen($newtag) && strlen($str_tags))
409 $newtag .= $str_tags;
411 $newinform = $old_inform;
412 if(strlen($newinform) && strlen($inform))
414 $newinform .= $inform;
416 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
419 dbesc(datetime_convert()),
420 dbesc(datetime_convert()),
422 intval($page_owner_uid)
426 foreach($p as $scales) {
427 if(intval($scales['scale']) == 2) {
431 if(intval($scales['scale']) == 4) {
437 if(count($taginfo)) {
438 foreach($taginfo as $tagged) {
440 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
444 $arr['uid'] = $page_owner_uid;
446 $arr['parent-uri'] = $uri;
447 $arr['type'] = 'activity';
449 $arr['contact-id'] = $owner_record['id'];
450 $arr['owner-name'] = $owner_record['name'];
451 $arr['owner-link'] = $owner_record['url'];
452 $arr['owner-avatar'] = $owner_record['thumb'];
453 $arr['author-name'] = $owner_record['name'];
454 $arr['author-link'] = $owner_record['url'];
455 $arr['author-avatar'] = $owner_record['thumb'];
457 $arr['allow_cid'] = $p[0]['allow_cid'];
458 $arr['allow_gid'] = $p[0]['allow_gid'];
459 $arr['deny_cid'] = $p[0]['deny_cid'];
460 $arr['deny_gid'] = $p[0]['deny_gid'];
461 $arr['last-child'] = 1;
463 $arr['verb'] = ACTIVITY_TAG;
464 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
465 $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
466 $arr['tag'] = $tagged[4];
467 $arr['inform'] = $tagged[2];
469 $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]' ;
470 $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" ;
472 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
473 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
475 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $tagged[3]['photo'] . '" />' . "\n");
476 $arr['object'] .= '</link></object>' . "\n";
478 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
479 . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
480 $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>';
482 $item_id = item_store($arr);
484 proc_run('php',"include/notifier.php","tag","$item_id");
490 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
491 return; // NOTREACHED
496 * default post action - upload a photo
499 call_hooks('photo_post_init', $_POST);
502 * Determine the album to use
505 $album = notags(trim($_REQUEST['album']));
506 $newalbum = notags(trim($_REQUEST['newalbum']));
508 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , 'LOGGER_DEBUG');
510 if(! strlen($album)) {
511 if(strlen($newalbum))
514 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
519 * We create a wall item for every photo, but we don't want to
520 * overwhelm the data stream with a hundred newly uploaded photos.
521 * So we will make one photo (the first one uploaded to this album)
522 * visible by default, the rest will become visible over time when and if
523 * they acquire comments, likes, dislikes, and/or tags
527 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
529 intval($page_owner_uid)
531 if((! count($r)) || ($album == t('Profile Photos')))
536 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
537 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
538 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
539 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
541 $ret = array('src' => '', 'filename' => '', 'filesize' => 0);
543 call_hooks('photo_post_file',$ret);
545 if(x($ret,'src') && x($ret,'filesize')) {
547 $filename = $ret['filename'];
548 $filesize = $ret['filesize'];
551 $src = $_FILES['userfile']['tmp_name'];
552 $filename = basename($_FILES['userfile']['name']);
553 $filesize = intval($_FILES['userfile']['size']);
556 $maximagesize = get_config('system','maximagesize');
558 if(($maximagesize) && ($filesize > $maximagesize)) {
559 notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
564 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , 'LOGGER_DEBUG');
566 $imagedata = @file_get_contents($src);
567 $ph = new Photo($imagedata);
569 if(! $ph->is_valid()) {
570 logger('mod/photos.php: photos_post(): unable to process image' , 'LOGGER_DEBUG');
571 notice( t('Unable to process image.') . EOL );
578 $width = $ph->getWidth();
579 $height = $ph->getHeight();
583 $photo_hash = photo_new_resource();
585 $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);
588 logger('mod/photos.php: photos_post(): image store failed' , 'LOGGER_DEBUG');
589 notice( t('Image upload failed.') . EOL );
593 if($width > 640 || $height > 640) {
594 $ph->scaleImage(640);
595 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
599 if($width > 320 || $height > 320) {
600 $ph->scaleImage(320);
601 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
605 $basename = basename($filename);
606 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
608 // Create item container
612 $arr['uid'] = $page_owner_uid;
614 $arr['parent-uri'] = $uri;
615 $arr['type'] = 'photo';
617 $arr['resource-id'] = $photo_hash;
618 $arr['contact-id'] = $owner_record['id'];
619 $arr['owner-name'] = $owner_record['name'];
620 $arr['owner-link'] = $owner_record['url'];
621 $arr['owner-avatar'] = $owner_record['thumb'];
622 $arr['author-name'] = $owner_record['name'];
623 $arr['author-link'] = $owner_record['url'];
624 $arr['author-avatar'] = $owner_record['thumb'];
626 $arr['allow_cid'] = $str_contact_allow;
627 $arr['allow_gid'] = $str_group_allow;
628 $arr['deny_cid'] = $str_contact_deny;
629 $arr['deny_gid'] = $str_group_deny;
630 $arr['last-child'] = 1;
631 $arr['visible'] = $visible;
632 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
633 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
636 $item_id = item_store($arr);
638 call_hooks('photo_post_end',intval($item_id));
640 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
641 // if they do not wish to be redirected
643 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
649 function photos_content(&$a) {
653 // photos/name/upload
654 // photos/name/album/xxxxx
655 // photos/name/album/xxxxx/edit
656 // photos/name/image/xxxxx
657 // photos/name/image/xxxxx/edit
660 require_once('include/bbcode.php');
661 require_once('include/security.php');
662 require_once('include/conversation.php');
664 if(! x($a->data,'user')) {
665 notice( t('No photos selected') . EOL );
669 $_SESSION['photo_return'] = $a->cmd;
676 $datatype = $a->argv[2];
677 $datum = $a->argv[3];
679 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
680 $datatype = 'upload';
682 $datatype = 'summary';
690 // Setup permissions structures
696 $remote_contact = false;
698 $owner_uid = $a->data['user']['uid'];
700 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
702 if((local_user()) && (local_user() == $owner_uid))
705 if($community_page && remote_user()) {
706 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
707 intval(remote_user()),
713 $remote_contact = true;
714 $visitor = remote_user();
719 // perhaps they're visiting - but not a community page, so they wouldn't have write access
721 if(remote_user() && (! $visitor)) {
722 $contact_id = $_SESSION['visitor_id'];
723 $groups = init_groups_visitor($contact_id);
724 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
725 intval(remote_user()),
730 $remote_contact = true;
734 if(! $remote_contact) {
736 $contact_id = $_SESSION['cid'];
737 $contact = $a->contact;
741 // default permissions - anonymous user
743 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
745 // Profile owner - everything is visible
747 if(local_user() && (local_user() == $owner_uid)) {
750 elseif(remote_user()) {
751 // authenticated visitor - here lie dragons
752 $gs = '<<>>'; // should be impossible to match
754 foreach($groups as $g)
755 $gs .= '|<' . intval($g) . '>';
757 $sql_extra = sprintf(
758 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
759 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
760 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
761 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
763 intval(remote_user()),
764 intval(remote_user()),
775 if($datatype === 'upload') {
777 notice( t('Permission denied.'));
780 $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
782 $albumselect .= '<option value="" selected="selected" > </option>';
783 if(count($a->data['albums'])) {
784 foreach($a->data['albums'] as $album) {
785 if(($album['album'] === '') || ($album['album'] == t('Contact Photos')))
787 $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
791 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
793 $albumselect .= '</select>';
797 $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
798 'addon_text' => $uploader,
799 'default_upload' => true);
802 call_hooks('photo_upload_form',$ret);
804 $default_upload = '<input type="file" name="userfile" /> <div class="photos-upload-submit-wrapper" >
805 <input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>';
810 $tpl = load_view_file('view/photos_upload.tpl');
811 $o .= replace_macros($tpl,array(
812 '$pagename' => t('Upload Photos'),
813 '$sessid' => session_id(),
814 '$nickname' => $a->data['user']['nickname'],
815 '$newalbum' => t('New album name: '),
816 '$existalbumtext' => t('or existing album name: '),
817 '$albumselect' => $albumselect,
818 '$permissions' => t('Permissions'),
819 '$aclselect' => (($visitor) ? '' : populate_acl($a->user, $celeb)),
820 '$uploader' => $ret['addon_text'],
821 '$default' => (($ret['default_upload']) ? $default_upload : ''),
822 '$uploadurl' => $ret['post_url']
829 if($datatype === 'album') {
831 $album = hex2bin($datum);
833 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
834 $sql_extra GROUP BY `resource-id`",
839 $a->set_pager_total(count($r));
840 $a->set_pager_itemspage(20);
843 $r = q("SELECT `resource-id`, `id`, `filename`, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
844 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
847 intval($a->pager['start']),
848 intval($a->pager['itemspage'])
851 $o .= '<h3>' . $album . '</h3>';
853 if($cmd === 'edit') {
854 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
856 $edit_tpl = load_view_file('view/album_edit.tpl');
857 $o .= replace_macros($edit_tpl,array(
858 '$nametext' => t('New album name: '),
859 '$nickname' => $a->data['user']['nickname'],
861 '$hexalbum' => bin2hex($album),
862 '$submit' => t('Submit'),
863 '$dropsubmit' => t('Delete Album')
869 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
871 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
872 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
873 . t('Edit Album') . '</a></div>';
877 $tpl = load_view_file('view/photo_album.tpl');
880 $o .= replace_macros($tpl,array(
882 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
883 '$phototitle' => t('View Photo'),
884 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
885 '$imgalt' => $rr['filename'],
886 '$desc'=> $rr['desc']
890 $o .= '<div id="photo-album-end"></div>';
898 if($datatype === 'image') {
902 $o = '<div id="live-display"></div>' . "\r\n";
903 // fetch image, item containing image, then comments
905 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
906 $sql_extra ORDER BY `scale` ASC ",
912 notice( t('Photo not available') . EOL );
919 $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
920 $sql_extra ORDER BY `created` DESC ",
921 dbesc($ph[0]['album']),
926 for($z = 0; $z < count($prvnxt); $z++) {
927 if($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) {
931 $prv = count($prvnxt) - 1;
932 if($nxt >= count($prvnxt))
937 $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] ;
938 $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] ;
943 $hires = $lores = $ph[0];
945 if($ph[1]['scale'] == 2) {
946 // original is 640 or less, we can display it directly
947 $hires = $lores = $ph[0];
956 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']) . '">' . $ph[0]['album'] . '</a></h3>';
958 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
959 $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>';
961 $o .= ' - <a id="photo-toprofile-link" href="' . $a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'].'">'.t('Use as profile photo').'</a>';
963 $o .= ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
964 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
965 ? ' - <img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,\'photo/' . $ph[0]['id'] . '\');" />'
972 $o .= '<div id="photo-prev-link"><a href="' . $prevlink .'">' . t('<< Prev') . '</a></div>' ;
974 $o .= '<div id="photo-photo"><a href="' . $a->get_baseurl() . '/photo/'
975 . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg" title="'
976 . t('View Full Size') . '" ><img src="' . $a->get_baseurl() . '/photo/'
977 . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg' . '" /></a></div>';
980 $o .= '<div id="photo-next-link"><a href="' . $nextlink .'">' . t('Next >>') . '</a></div>';
982 $o .= '<div id="photo-photo-end"></div>';
985 // Do we have an item for this photo?
987 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
990 if(count($linked_items)) {
991 $link_item = $linked_items[0];
992 $r = q("SELECT COUNT(*) AS `total`
993 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
994 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
995 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
996 AND `item`.`uid` = %d
998 dbesc($link_item['uri']),
999 dbesc($link_item['uri']),
1000 intval($link_item['uid'])
1005 $a->set_pager_total($r[0]['total']);
1008 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
1009 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
1010 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
1011 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
1012 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
1013 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
1014 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
1015 AND `item`.`uid` = %d
1017 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
1018 dbesc($link_item['uri']),
1019 dbesc($link_item['uri']),
1020 intval($link_item['uid']),
1021 intval($a->pager['start']),
1022 intval($a->pager['itemspage'])
1026 if((local_user()) && (local_user() == $link_item['uid'])) {
1027 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
1028 intval($link_item['parent']),
1029 intval(local_user())
1034 $o .= '<div id="photo-caption" >' . $ph[0]['desc'] . '</div>';
1036 if(count($linked_items) && strlen($link_item['tag'])) {
1037 $arr = explode(',',$link_item['tag']);
1038 // parse tags and add links
1039 $o .= '<div id="in-this-photo-text">' . t('Tags: ') . '</div>';
1040 $o .= '<div id="in-this-photo">';
1042 foreach($arr as $t) {
1043 if(strlen($tag_str))
1045 $tag_str .= bbcode($t);
1047 $o .= $tag_str . '</div>';
1049 $o .= '<div id="tag-remove"><a href="' . $a->get_baseurl() . '/tagrm/' . $link_item['id'] . '">' . t('[Remove any tag]') . '</a></div>';
1053 if(($cmd === 'edit') && ($can_post)) {
1054 $edit_tpl = load_view_file('view/photo_edit.tpl');
1055 $o .= replace_macros($edit_tpl, array(
1056 '$id' => $ph[0]['id'],
1057 '$album' => $ph[0]['album'],
1058 '$newalbum' => t('New album name'),
1059 '$nickname' => $a->data['user']['nickname'],
1060 '$resource_id' => $ph[0]['resource-id'],
1061 '$capt_label' => t('Caption'),
1062 '$caption' => $ph[0]['desc'],
1063 '$tag_label' => t('Add a Tag'),
1064 '$tags' => $link_item['tag'],
1065 '$permissions' => t('Permissions'),
1066 '$aclselect' => populate_acl($ph[0]),
1067 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
1068 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1069 '$submit' => t('Submit'),
1070 '$delete' => t('Delete Photo')
1074 if(count($linked_items)) {
1076 $cmnt_tpl = load_view_file('view/comment_item.tpl');
1077 $tpl = load_view_file('view/photo_item.tpl');
1078 $return_url = $a->cmd;
1080 $like_tpl = load_view_file('view/like_noshare.tpl');
1084 if($can_post || can_write_wall($a,$owner_uid)) {
1085 $likebuttons = replace_macros($like_tpl,array(
1086 '$id' => $item['id'],
1087 '$likethis' => t("I like this \x28toggle\x29"),
1088 '$nolike' => t("I don't like this \x28toggle\x29"),
1089 '$share' => t('Share'),
1090 '$wait' => t('Please wait')
1095 $o .= '<div id="photo-like-div">';
1099 if($can_post || can_write_wall($a,$owner_uid)) {
1100 if($link_item['last-child']) {
1101 $o .= replace_macros($cmnt_tpl,array(
1102 '$return_path' => '',
1103 '$jsreload' => $return_url,
1104 '$type' => 'wall-comment',
1105 '$id' => $link_item['id'],
1106 '$parent' => $link_item['id'],
1107 '$profile_uid' => $owner_uid,
1108 '$mylink' => $contact['url'],
1109 '$mytitle' => t('This is you'),
1110 '$myphoto' => $contact['thumb'],
1111 '$comment' => t('Comment'),
1112 '$submit' => t('Submit'),
1125 foreach($r as $item) {
1126 like_puller($a,$item,$alike,'like');
1127 like_puller($a,$item,$dlike,'dislike');
1130 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
1131 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
1133 $o .= '<div id="photo-like-div">';
1141 if($can_post || can_write_wall($a,$owner_uid)) {
1142 if($link_item['last-child']) {
1143 $o .= replace_macros($cmnt_tpl,array(
1144 '$return_path' => '',
1145 '$jsreload' => $return_url,
1146 '$type' => 'wall-comment',
1147 '$id' => $link_item['id'],
1148 '$parent' => $link_item['id'],
1149 '$profile_uid' => $owner_uid,
1150 '$mylink' => $contact['url'],
1151 '$mytitle' => t('This is you'),
1152 '$myphoto' => $contact['thumb'],
1159 foreach($r as $item) {
1164 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1167 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1169 if($can_post || can_write_wall($a,$owner_uid)) {
1171 if($item['last-child']) {
1172 $comment = replace_macros($cmnt_tpl,array(
1173 '$return_path' => '',
1174 '$jsreload' => $return_url,
1175 '$type' => 'wall-comment',
1176 '$id' => $item['item_id'],
1177 '$parent' => $item['parent'],
1178 '$profile_uid' => $owner_uid,
1179 '$mylink' => $contact['url'],
1180 '$mytitle' => t('This is you'),
1181 '$myphoto' => $contact['thumb'],
1188 if(local_user() && ($item['contact-uid'] == local_user())
1189 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
1190 $profile_url = $redirect_url;
1191 $sparkle = ' sparkle';
1194 $profile_url = $item['url'];
1198 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1200 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1201 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1203 $profile_link = $profile_url;
1207 if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
1208 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
1211 $o .= replace_macros($template,array(
1212 '$id' => $item['item_id'],
1213 '$profile_url' => $profile_link,
1214 '$name' => $profile_name,
1215 '$thumb' => $profile_avatar,
1216 '$sparkle' => $sparkle,
1217 '$title' => $item['title'],
1218 '$body' => bbcode($item['body']),
1219 '$ago' => relative_date($item['created']),
1220 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1222 '$comment' => $comment
1232 // Default - show recent photos with upload link (if applicable)
1235 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
1236 $sql_extra GROUP BY `resource-id`",
1237 intval($a->data['user']['uid']),
1238 dbesc( t('Contact Photos'))
1241 $a->set_pager_total(count($r));
1242 $a->set_pager_itemspage(20);
1245 $r = q("SELECT `resource-id`, `id`, `filename`, `album`, max(`scale`) AS `scale` FROM `photo`
1246 WHERE `uid` = %d AND `album` != '%s'
1247 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1248 intval($a->data['user']['uid']),
1249 dbesc( t('Contact Photos')),
1250 intval($a->pager['start']),
1251 intval($a->pager['itemspage'])
1254 $o .= '<h3>' . t('Recent Photos') . '</h3>';
1257 $o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
1258 . $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
1261 $tpl = load_view_file('view/photo_top.tpl');
1263 foreach($r as $rr) {
1264 $o .= replace_macros($tpl,array(
1266 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
1267 '$phototitle' => t('View Photo'),
1268 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.jpg',
1269 '$albumlink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1270 '$albumname' => $rr['album'],
1271 '$albumalt' => t('View Album'),
1272 '$imgalt' => $rr['filename']
1276 $o .= '<div id="photo-top-end"></div>';