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']);
185 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
187 // send the notification upstream/downstream as the case may be
190 //proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" & ",array(),$foo));
191 proc_run($php_path,"include/notifier.php","drop","$drop_id");
195 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
196 return; // NOTREACHED
199 if(($a->argc > 2) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
201 // same as above but remove single photo
204 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `contact-id` = %d AND `uid` = %d AND `resource-id` = '%s' LIMIT 1",
206 intval($page_owner_uid),
211 $r = q("SELECT `id`, `resource-id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
212 intval(local_user()),
217 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
218 intval($page_owner_uid),
219 dbesc($r[0]['resource-id'])
221 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
222 dbesc($r[0]['resource-id']),
223 intval($page_owner_uid)
226 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
227 dbesc(datetime_convert()),
228 dbesc(datetime_convert()),
230 intval($page_owner_uid)
233 $url = $a->get_baseurl();
234 $drop_id = intval($i[0]['id']);
235 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
238 //proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" & ", array(),$foo));
239 proc_run($php_path,"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 $resource_id = $a->argv[2];
255 if(! strlen($albname))
256 $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
259 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
261 intval($page_owner_uid)
263 if((count($p)) && (($p[0]['desc'] !== $desc) || ($p[0]['album'] !== $albname))) {
264 $r = q("UPDATE `photo` SET `desc` = '%s', `album` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d",
268 intval($page_owner_uid)
272 /* Don't make the item visible if the only change was the album name */
275 if($p[0]['desc'] !== $desc || strlen($rawtags))
280 // Create item container
283 $basename = basename($filename);
284 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
288 $arr['uid'] = $page_owner_uid;
290 $arr['parent-uri'] = $uri;
291 $arr['type'] = 'photo';
293 $arr['resource-id'] = $p[0]['resource-id'];
294 $arr['contact-id'] = $owner_record['id'];
295 $arr['owner-name'] = $owner_record['name'];
296 $arr['owner-link'] = $owner_record['url'];
297 $arr['owner-avatar'] = $owner_record['thumb'];
298 $arr['author-name'] = $owner_record['name'];
299 $arr['author-link'] = $owner_record['url'];
300 $arr['author-avatar'] = $owner_record['thumb'];
301 $arr['title'] = $title;
302 $arr['allow_cid'] = $p[0]['allow_cid'];
303 $arr['allow_gid'] = $p[0]['allow_gid'];
304 $arr['deny_cid'] = $p[0]['deny_cid'];
305 $arr['deny_gid'] = $p[0]['deny_gid'];
306 $arr['last-child'] = 1;
307 $arr['visible'] = $visibility;
308 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
309 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]'
312 $item_id = item_store($arr);
317 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
319 intval($page_owner_uid)
323 $old_tag = $r[0]['tag'];
324 $old_inform = $r[0]['inform'];
327 if(strlen($rawtags)) {
332 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
334 $x = substr($rawtags,0,1);
335 if($x !== '@' && $x !== '#')
336 $rawtags = '#' . $rawtags;
339 $tags = get_tags($rawtags);
342 foreach($tags as $tag) {
343 if(strpos($tag,'@') === 0) {
344 $name = substr($tag,1);
345 if((strpos($name,'@')) || (strpos($name,'http://'))) {
347 $links = @lrdd($name);
349 foreach($links as $link) {
350 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
351 $profile = $link['@attributes']['href'];
352 if($link['@attributes']['rel'] === 'salmon') {
353 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
360 $taginfo[] = array($newname,$profile,$salmon);
364 if(strstr($name,'_')) {
365 $newname = str_replace('_',' ',$name);
366 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
368 intval($page_owner_uid)
372 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
374 intval($page_owner_uid)
378 $newname = $r[0]['name'];
379 $profile = $r[0]['url'];
380 $notify = 'cid:' . $r[0]['id'];
387 if(substr($notify,0,4) === 'cid:')
388 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
390 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
391 if(strlen($str_tags))
393 $profile = str_replace(',','%2c',$profile);
394 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
401 if(strlen($newtag) && strlen($str_tags))
403 $newtag .= $str_tags;
405 $newinform = $old_inform;
406 if(strlen($newinform) && strlen($inform))
408 $newinform .= $inform;
410 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
413 dbesc(datetime_convert()),
414 dbesc(datetime_convert()),
416 intval($page_owner_uid)
420 foreach($p as $scales) {
421 if(intval($scales['scale']) == 2) {
425 if(intval($scales['scale']) == 4) {
431 if(count($taginfo)) {
432 foreach($taginfo as $tagged) {
434 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
438 $arr['uid'] = $page_owner_uid;
440 $arr['parent-uri'] = $uri;
441 $arr['type'] = 'activity';
443 $arr['contact-id'] = $owner_record['id'];
444 $arr['owner-name'] = $owner_record['name'];
445 $arr['owner-link'] = $owner_record['url'];
446 $arr['owner-avatar'] = $owner_record['thumb'];
447 $arr['author-name'] = $owner_record['name'];
448 $arr['author-link'] = $owner_record['url'];
449 $arr['author-avatar'] = $owner_record['thumb'];
451 $arr['allow_cid'] = $p[0]['allow_cid'];
452 $arr['allow_gid'] = $p[0]['allow_gid'];
453 $arr['deny_cid'] = $p[0]['deny_cid'];
454 $arr['deny_gid'] = $p[0]['deny_gid'];
455 $arr['last-child'] = 1;
457 $arr['verb'] = ACTIVITY_TAG;
458 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
459 $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
460 $arr['tag'] = $tagged[4];
461 $arr['inform'] = $tagged[2];
463 $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]' ;
464 $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" ;
466 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
467 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
469 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $tagged[3]['photo'] . '" />' . "\n");
470 $arr['object'] .= '</link></object>' . "\n";
472 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
473 . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
474 $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>';
476 $item_id = item_store($arr);
477 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
478 //proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"tag\" \"$item_id\" & ",array(),$foo));
479 proc_run($php_path,"include/notifier.php","tag","$item_id");
485 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
486 return; // NOTREACHED
491 * default post action - upload a photo
494 call_hooks('photo_post_init', $_POST);
497 * Determine the album to use
500 $album = notags(trim($_REQUEST['album']));
501 $newalbum = notags(trim($_REQUEST['newalbum']));
503 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , 'LOGGER_DEBUG');
505 if(! strlen($album)) {
506 if(strlen($newalbum))
509 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
514 * We create a wall item for every photo, but we don't want to
515 * overwhelm the data stream with a hundred newly uploaded photos.
516 * So we will make one photo (the first one uploaded to this album)
517 * visible by default, the rest will become visible over time when and if
518 * they acquire comments, likes, dislikes, and/or tags
522 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
524 intval($page_owner_uid)
526 if((! count($r)) || ($album == t('Profile Photos')))
531 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
532 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
533 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
534 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
536 $ret = array('src' => '', 'filename' => '', 'filesize' => 0);
538 call_hooks('photo_post_file',$ret);
540 if(x($ret,'src') && x($ret,'filesize')) {
542 $filename = $ret['filename'];
543 $filesize = $ret['filesize'];
546 $src = $_FILES['userfile']['tmp_name'];
547 $filename = basename($_FILES['userfile']['name']);
548 $filesize = intval($_FILES['userfile']['size']);
551 $maximagesize = get_config('system','maximagesize');
553 if(($maximagesize) && ($filesize > $maximagesize)) {
554 notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
559 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , 'LOGGER_DEBUG');
561 $imagedata = @file_get_contents($src);
562 $ph = new Photo($imagedata);
564 if(! $ph->is_valid()) {
565 logger('mod/photos.php: photos_post(): unable to process image' , 'LOGGER_DEBUG');
566 notice( t('Unable to process image.') . EOL );
573 $width = $ph->getWidth();
574 $height = $ph->getHeight();
578 $photo_hash = photo_new_resource();
580 $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);
583 logger('mod/photos.php: photos_post(): image store failed' , 'LOGGER_DEBUG');
584 notice( t('Image upload failed.') . EOL );
588 if($width > 640 || $height > 640) {
589 $ph->scaleImage(640);
590 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
594 if($width > 320 || $height > 320) {
595 $ph->scaleImage(320);
596 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
600 $basename = basename($filename);
601 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
603 // Create item container
607 $arr['uid'] = $page_owner_uid;
609 $arr['parent-uri'] = $uri;
610 $arr['type'] = 'photo';
612 $arr['resource-id'] = $photo_hash;
613 $arr['contact-id'] = $owner_record['id'];
614 $arr['owner-name'] = $owner_record['name'];
615 $arr['owner-link'] = $owner_record['url'];
616 $arr['owner-avatar'] = $owner_record['thumb'];
617 $arr['author-name'] = $owner_record['name'];
618 $arr['author-link'] = $owner_record['url'];
619 $arr['author-avatar'] = $owner_record['thumb'];
621 $arr['allow_cid'] = $str_contact_allow;
622 $arr['allow_gid'] = $str_group_allow;
623 $arr['deny_cid'] = $str_contact_deny;
624 $arr['deny_gid'] = $str_group_deny;
625 $arr['last-child'] = 1;
626 $arr['visible'] = $visible;
627 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
628 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
631 $item_id = item_store($arr);
633 call_hooks('photo_post_end',intval($item_id));
635 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
636 // if they do not wish to be redirected
638 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
644 function photos_content(&$a) {
648 // photos/name/upload
649 // photos/name/album/xxxxx
650 // photos/name/album/xxxxx/edit
651 // photos/name/image/xxxxx
652 // photos/name/image/xxxxx/edit
655 if(! x($a->data,'user')) {
656 notice( t('No photos selected') . EOL );
660 $_SESSION['photo_return'] = $a->cmd;
667 $datatype = $a->argv[2];
668 $datum = $a->argv[3];
670 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
671 $datatype = 'upload';
673 $datatype = 'summary';
681 // Setup permissions structures
687 $remote_contact = false;
689 $owner_uid = $a->data['user']['uid'];
691 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
693 if((local_user()) && (local_user() == $owner_uid))
696 if($community_page && remote_user()) {
697 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
698 intval(remote_user()),
704 $remote_contact = true;
705 $visitor = remote_user();
710 // perhaps they're visiting - but not a community page, so they wouldn't have write access
712 if(remote_user() && (! $visitor)) {
713 $contact_id = $_SESSION['visitor_id'];
714 $groups = init_groups_visitor($contact_id);
715 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
716 intval(remote_user()),
721 $remote_contact = true;
725 if(! $remote_contact) {
727 $contact_id = $_SESSION['cid'];
728 $contact = $a->contact;
732 // default permissions - anonymous user
734 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
736 // Profile owner - everything is visible
738 if(local_user() && (local_user() == $owner_uid)) {
741 elseif(remote_user()) {
742 // authenticated visitor - here lie dragons
743 $gs = '<<>>'; // should be impossible to match
745 foreach($groups as $g)
746 $gs .= '|<' . intval($g) . '>';
748 $sql_extra = sprintf(
749 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
750 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
751 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
752 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
754 intval(remote_user()),
755 intval(remote_user()),
766 if($datatype === 'upload') {
768 notice( t('Permission denied.'));
771 $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
773 $albumselect .= '<option value="" selected="selected" > </option>';
774 if(count($a->data['albums'])) {
775 foreach($a->data['albums'] as $album) {
776 if(($album['album'] === '') || ($album['album'] == t('Contact Photos')))
778 $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
782 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
784 $albumselect .= '</select>';
788 $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
789 'addon_text' => $uploader,
790 'default_upload' => true);
793 call_hooks('photo_upload_form',$ret);
795 $default_upload = '<input type="file" name="userfile" /> <div class="photos-upload-submit-wrapper" >
796 <input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>';
801 $tpl = load_view_file('view/photos_upload.tpl');
802 $o .= replace_macros($tpl,array(
803 '$pagename' => t('Upload Photos'),
804 '$sessid' => session_id(),
805 '$nickname' => $a->data['user']['nickname'],
806 '$newalbum' => t('New album name: '),
807 '$existalbumtext' => t('or existing album name: '),
808 '$albumselect' => $albumselect,
809 '$permissions' => t('Permissions'),
810 '$aclselect' => (($visitor) ? '' : populate_acl($a->user, $celeb)),
811 '$uploader' => $ret['addon_text'],
812 '$default' => (($ret['default_upload']) ? $default_upload : ''),
813 '$uploadurl' => $ret['post_url']
820 if($datatype === 'album') {
822 $album = hex2bin($datum);
824 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
825 $sql_extra GROUP BY `resource-id`",
830 $a->set_pager_total(count($r));
831 $a->set_pager_itemspage(20);
834 $r = q("SELECT `resource-id`, `id`, `filename`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
835 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
838 intval($a->pager['start']),
839 intval($a->pager['itemspage'])
842 $o .= '<h3>' . $album . '</h3>';
844 if($cmd === 'edit') {
845 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
847 $edit_tpl = load_view_file('view/album_edit.tpl');
848 $o .= replace_macros($edit_tpl,array(
849 '$nametext' => t('New album name: '),
850 '$nickname' => $a->data['user']['nickname'],
852 '$hexalbum' => bin2hex($album),
853 '$submit' => t('Submit'),
854 '$dropsubmit' => t('Delete Album')
860 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
862 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
863 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
864 . t('Edit Album') . '</a></div>';
868 $tpl = load_view_file('view/photo_album.tpl');
871 $o .= replace_macros($tpl,array(
873 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
874 '$phototitle' => t('View Photo'),
875 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
876 '$imgalt' => $rr['filename']
880 $o .= '<div id="photo-album-end"></div>';
888 if($datatype === 'image') {
890 require_once('security.php');
891 require_once('bbcode.php');
893 $o = '<div id="live-display"></div>' . "\r\n";
894 // fetch image, item containing image, then comments
896 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
897 $sql_extra ORDER BY `scale` ASC ",
903 notice( t('Photo not available') . EOL );
908 $hires = $lores = $ph[0];
910 if($ph[1]['scale'] == 2) {
911 // original is 640 or less, we can display it directly
912 $hires = $lores = $ph[0];
921 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']) . '">' . $ph[0]['album'] . '</a></h3>';
923 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
924 $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>';
926 $o .= ' - <a id="photo-toprofile-link" href="' . $a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'].'">'.t('Use as profile photo').'</a>';
928 $o .= ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
929 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
930 ? ' - <img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,\'photo/' . $ph[0]['id'] . '\');" />'
937 $o .= '<a href="' . $a->get_baseurl() . '/photo/'
938 . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg" title="'
939 . t('View Full Size') . '" ><img src="' . $a->get_baseurl() . '/photo/'
940 . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg' . '" /></a>';
943 // Do we have an item for this photo?
945 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
948 if(count($linked_items)) {
949 $link_item = $linked_items[0];
950 $r = q("SELECT COUNT(*) AS `total`
951 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
952 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
953 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
954 AND `item`.`uid` = %d
956 dbesc($link_item['uri']),
957 dbesc($link_item['uri']),
958 intval($link_item['uid'])
963 $a->set_pager_total($r[0]['total']);
966 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
967 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
968 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
969 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
970 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
971 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
972 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
973 AND `item`.`uid` = %d
975 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
976 dbesc($link_item['uri']),
977 dbesc($link_item['uri']),
978 intval($link_item['uid']),
979 intval($a->pager['start']),
980 intval($a->pager['itemspage'])
984 if((local_user()) && (local_user() == $link_item['uid'])) {
985 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
986 intval($link_item['parent']),
992 $o .= '<div id="photo-caption" >' . $ph[0]['desc'] . '</div>';
994 if(count($linked_items) && strlen($link_item['tag'])) {
995 $arr = explode(',',$link_item['tag']);
996 // parse tags and add links
997 $o .= '<div id="in-this-photo-text">' . t('Tags: ') . '</div>';
998 $o .= '<div id="in-this-photo">';
1000 foreach($arr as $t) {
1001 if(strlen($tag_str))
1003 $tag_str .= bbcode($t);
1005 $o .= $tag_str . '</div>';
1007 $o .= '<div id="tag-remove"><a href="' . $a->get_baseurl() . '/tagrm/' . $link_item['id'] . '">' . t('[Remove any tag]') . '</a></div>';
1011 if(($cmd === 'edit') && ($can_post)) {
1012 $edit_tpl = load_view_file('view/photo_edit.tpl');
1013 $o .= replace_macros($edit_tpl, array(
1014 '$id' => $ph[0]['id'],
1015 '$album' => $ph[0]['album'],
1016 '$newalbum' => t('New album name'),
1017 '$nickname' => $a->data['user']['nickname'],
1018 '$resource_id' => $ph[0]['resource-id'],
1019 '$capt_label' => t('Caption'),
1020 '$caption' => $ph[0]['desc'],
1021 '$tag_label' => t('Add a Tag'),
1022 '$tags' => $link_item['tag'],
1023 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
1024 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1025 '$submit' => t('Submit'),
1026 '$delete' => t('Delete Photo')
1030 if(count($linked_items)) {
1032 $cmnt_tpl = load_view_file('view/comment_item.tpl');
1033 $tpl = load_view_file('view/photo_item.tpl');
1034 $return_url = $a->cmd;
1036 $like_tpl = load_view_file('view/like.tpl');
1040 if($can_post || can_write_wall($a,$owner_uid))
1041 $likebuttons = replace_macros($like_tpl,array('$id' => $link_item['id']));
1044 $o .= '<div id="photo-like-div">';
1048 if($can_post || can_write_wall($a,$owner_uid)) {
1049 if($link_item['last-child']) {
1050 $o .= replace_macros($cmnt_tpl,array(
1051 '$return_path' => $return_url,
1052 '$type' => 'wall-comment',
1053 '$id' => $link_item['id'],
1054 '$parent' => $link_item['id'],
1055 '$profile_uid' => $owner_uid,
1056 '$mylink' => $contact['url'],
1057 '$mytitle' => t('This is you'),
1058 '$myphoto' => $contact['thumb'],
1071 foreach($r as $item) {
1072 like_puller($a,$item,$alike,'like');
1073 like_puller($a,$item,$dlike,'dislike');
1076 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
1077 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
1079 $o .= '<div id="photo-like-div">';
1087 if($can_post || can_write_wall($a,$owner_uid)) {
1088 if($link_item['last-child']) {
1089 $o .= replace_macros($cmnt_tpl,array(
1090 '$return_path' => $return_url,
1091 '$type' => 'wall-comment',
1092 '$id' => $link_item['id'],
1093 '$parent' => $link_item['id'],
1094 '$profile_uid' => $owner_uid,
1095 '$mylink' => $contact['url'],
1096 '$mytitle' => t('This is you'),
1097 '$myphoto' => $contact['thumb'],
1104 foreach($r as $item) {
1109 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1112 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1114 if($can_post || can_write_wall($a,$owner_uid)) {
1116 if($item['last-child']) {
1117 $comment = replace_macros($cmnt_tpl,array(
1118 '$return_path' => $return_url,
1119 '$type' => 'wall-comment',
1120 '$id' => $item['item_id'],
1121 '$parent' => $item['parent'],
1122 '$profile_uid' => $owner_uid,
1123 '$mylink' => $contact['url'],
1124 '$mytitle' => t('This is you'),
1125 '$myphoto' => $contact['thumb'],
1132 if(local_user() && ($item['contact-uid'] == local_user())
1133 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
1134 $profile_url = $redirect_url;
1135 $sparkle = ' sparkle';
1138 $profile_url = $item['url'];
1142 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1144 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1145 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1147 $profile_link = $profile_url;
1151 if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
1152 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id']));
1155 $o .= replace_macros($template,array(
1156 '$id' => $item['item_id'],
1157 '$profile_url' => $profile_link,
1158 '$name' => $profile_name,
1159 '$thumb' => $profile_avatar,
1160 '$sparkle' => $sparkle,
1161 '$title' => $item['title'],
1162 '$body' => bbcode($item['body']),
1163 '$ago' => relative_date($item['created']),
1164 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1166 '$comment' => $comment
1176 // Default - show recent photos with upload link (if applicable)
1179 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
1180 $sql_extra GROUP BY `resource-id`",
1181 intval($a->data['user']['uid']),
1182 dbesc( t('Contact Photos'))
1185 $a->set_pager_total(count($r));
1186 $a->set_pager_itemspage(20);
1189 $r = q("SELECT `resource-id`, `id`, `filename`, `album`, max(`scale`) AS `scale` FROM `photo`
1190 WHERE `uid` = %d AND `album` != '%s'
1191 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1192 intval($a->data['user']['uid']),
1193 dbesc( t('Contact Photos')),
1194 intval($a->pager['start']),
1195 intval($a->pager['itemspage'])
1198 $o .= '<h3>' . t('Recent Photos') . '</h3>';
1201 $o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
1202 . $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
1205 $tpl = load_view_file('view/photo_top.tpl');
1207 foreach($r as $rr) {
1208 $o .= replace_macros($tpl,array(
1210 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname']
1211 . '/image/' . $rr['resource-id'],
1212 '$phototitle' => t('View Photo'),
1213 '$imgsrc' => $a->get_baseurl() . '/photo/'
1214 . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.jpg',
1215 '$albumlink' => $a->get_baseurl() . '/photos/'
1216 . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1217 '$albumname' => $rr['album'],
1218 '$albumalt' => t('View Album'),
1219 '$imgalt' => $rr['filename']
1223 $o .= '<div id="photo-top-end"></div>';