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)
273 // Create item container
276 $basename = basename($filename);
277 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
281 $arr['uid'] = $page_owner_uid;
283 $arr['parent-uri'] = $uri;
284 $arr['type'] = 'photo';
286 $arr['resource-id'] = $p[0]['resource-id'];
287 $arr['contact-id'] = $owner_record['id'];
288 $arr['owner-name'] = $owner_record['name'];
289 $arr['owner-link'] = $owner_record['url'];
290 $arr['owner-avatar'] = $owner_record['thumb'];
291 $arr['author-name'] = $owner_record['name'];
292 $arr['author-link'] = $owner_record['url'];
293 $arr['author-avatar'] = $owner_record['thumb'];
294 $arr['title'] = $title;
295 $arr['allow_cid'] = $p[0]['allow_cid'];
296 $arr['allow_gid'] = $p[0]['allow_gid'];
297 $arr['deny_cid'] = $p[0]['deny_cid'];
298 $arr['deny_gid'] = $p[0]['deny_gid'];
299 $arr['last-child'] = 1;
300 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
301 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]'
304 $item_id = item_store($arr);
309 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
311 intval($page_owner_uid)
315 $old_tag = $r[0]['tag'];
316 $old_inform = $r[0]['inform'];
319 if(strlen($rawtags)) {
324 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
326 $x = substr($rawtags,0,1);
327 if($x !== '@' && $x !== '#')
328 $rawtags = '#' . $rawtags;
331 $tags = get_tags($rawtags);
334 foreach($tags as $tag) {
335 if(strpos($tag,'@') === 0) {
336 $name = substr($tag,1);
337 if((strpos($name,'@')) || (strpos($name,'http://'))) {
339 $links = @lrdd($name);
341 foreach($links as $link) {
342 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
343 $profile = $link['@attributes']['href'];
344 if($link['@attributes']['rel'] === 'salmon') {
345 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
352 $taginfo[] = array($newname,$profile,$salmon);
356 if(strstr($name,'_')) {
357 $newname = str_replace('_',' ',$name);
358 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
360 intval($page_owner_uid)
364 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
366 intval($page_owner_uid)
370 $newname = $r[0]['name'];
371 $profile = $r[0]['url'];
372 $notify = 'cid:' . $r[0]['id'];
379 if(substr($notify,0,4) === 'cid:')
380 $taginfo[] = array($newname,$profile,$notify,$r[0],'@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
382 $taginfo[] = array($newname,$profile,$notify,null,$str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
383 if(strlen($str_tags))
385 $profile = str_replace(',','%2c',$profile);
386 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
393 if(strlen($newtag) && strlen($str_tags))
395 $newtag .= $str_tags;
397 $newinform = $old_inform;
398 if(strlen($newinform) && strlen($inform))
400 $newinform .= $inform;
402 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
405 dbesc(datetime_convert()),
406 dbesc(datetime_convert()),
408 intval($page_owner_uid)
412 foreach($p as $scales) {
413 if(intval($scales['scale']) == 2) {
417 if(intval($scales['scale']) == 4) {
423 if(count($taginfo)) {
424 foreach($taginfo as $tagged) {
426 $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
430 $arr['uid'] = $page_owner_uid;
432 $arr['parent-uri'] = $uri;
433 $arr['type'] = 'activity';
435 $arr['contact-id'] = $owner_record['id'];
436 $arr['owner-name'] = $owner_record['name'];
437 $arr['owner-link'] = $owner_record['url'];
438 $arr['owner-avatar'] = $owner_record['thumb'];
439 $arr['author-name'] = $owner_record['name'];
440 $arr['author-link'] = $owner_record['url'];
441 $arr['author-avatar'] = $owner_record['thumb'];
443 $arr['allow_cid'] = $p[0]['allow_cid'];
444 $arr['allow_gid'] = $p[0]['allow_gid'];
445 $arr['deny_cid'] = $p[0]['deny_cid'];
446 $arr['deny_gid'] = $p[0]['deny_gid'];
447 $arr['last-child'] = 1;
449 $arr['verb'] = ACTIVITY_TAG;
450 $arr['object-type'] = ACTIVITY_OBJ_PERSON;
451 $arr['target-type'] = ACTIVITY_OBJ_PHOTO;
452 $arr['tag'] = $tagged[4];
453 $arr['inform'] = $tagged[2];
455 $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]' ;
456 $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" ;
458 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
459 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
461 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $tagged[3]['photo'] . '" />' . "\n");
462 $arr['object'] .= '</link></object>' . "\n";
464 $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
465 . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
466 $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>';
468 $item_id = item_store($arr);
469 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
470 //proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"tag\" \"$item_id\" & ",array(),$foo));
471 proc_run($php_path,"include/notifier.php","tag","$item_id");
477 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
478 return; // NOTREACHED
483 * default post action - upload a photo
486 call_hooks('photo_post_init', $_POST);
489 * Determine the album to use
492 $album = notags(trim($_REQUEST['album']));
493 $newalbum = notags(trim($_REQUEST['newalbum']));
495 logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , 'LOGGER_DEBUG');
497 if(! strlen($album)) {
498 if(strlen($newalbum))
501 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
506 * We create a wall item for every photo, but we don't want to
507 * overwhelm the data stream with a hundred newly uploaded photos.
508 * So we will make one photo (the first one uploaded to this album)
509 * visible by default, the rest will become visible over time when and if
510 * they acquire comments, likes, dislikes, and/or tags
514 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
516 intval($page_owner_uid)
518 if((! count($r)) || ($album == t('Profile Photos')))
523 $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',',$_REQUEST['group_allow'])));
524 $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
525 $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny'])));
526 $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny'])));
528 $ret = array('src' => '', 'filename' => '', 'filesize' => 0);
530 call_hooks('photo_post_file',$ret);
532 if(x($ret,'src') && x($ret,'filesize')) {
534 $filename = $ret['filename'];
535 $filesize = $ret['filesize'];
538 $src = $_FILES['userfile']['tmp_name'];
539 $filename = basename($_FILES['userfile']['name']);
540 $filesize = intval($_FILES['userfile']['size']);
543 $maximagesize = get_config('system','maximagesize');
545 if(($maximagesize) && ($filesize > $maximagesize)) {
546 notice( t('Image exceeds size limit of ') . $maximagesize . EOL);
551 logger('mod/photos.php: photos_post(): loading the contents of ' . $src , 'LOGGER_DEBUG');
553 $imagedata = @file_get_contents($src);
554 $ph = new Photo($imagedata);
556 if(! $ph->is_valid()) {
557 logger('mod/photos.php: photos_post(): unable to process image' , 'LOGGER_DEBUG');
558 notice( t('Unable to process image.') . EOL );
565 $width = $ph->getWidth();
566 $height = $ph->getHeight();
570 $photo_hash = photo_new_resource();
572 $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);
575 logger('mod/photos.php: photos_post(): image store failed' , 'LOGGER_DEBUG');
576 notice( t('Image upload failed.') . EOL );
580 if($width > 640 || $height > 640) {
581 $ph->scaleImage(640);
582 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
586 if($width > 320 || $height > 320) {
587 $ph->scaleImage(320);
588 $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
592 $basename = basename($filename);
593 $uri = item_new_uri($a->get_hostname(), $page_owner_uid);
595 // Create item container
599 $arr['uid'] = $page_owner_uid;
601 $arr['parent-uri'] = $uri;
602 $arr['type'] = 'photo';
604 $arr['resource-id'] = $photo_hash;
605 $arr['contact-id'] = $owner_record['id'];
606 $arr['owner-name'] = $owner_record['name'];
607 $arr['owner-link'] = $owner_record['url'];
608 $arr['owner-avatar'] = $owner_record['thumb'];
609 $arr['author-name'] = $owner_record['name'];
610 $arr['author-link'] = $owner_record['url'];
611 $arr['author-avatar'] = $owner_record['thumb'];
613 $arr['allow_cid'] = $str_contact_allow;
614 $arr['allow_gid'] = $str_group_allow;
615 $arr['deny_cid'] = $str_contact_deny;
616 $arr['deny_gid'] = $str_group_deny;
617 $arr['last-child'] = 1;
618 $arr['visible'] = $visible;
619 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
620 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
623 $item_id = item_store($arr);
625 call_hooks('photo_post_end',intval($item_id));
627 // addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
628 // if they do not wish to be redirected
630 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
636 function photos_content(&$a) {
640 // photos/name/upload
641 // photos/name/album/xxxxx
642 // photos/name/album/xxxxx/edit
643 // photos/name/image/xxxxx
644 // photos/name/image/xxxxx/edit
647 if(! x($a->data,'user')) {
648 notice( t('No photos selected') . EOL );
652 $_SESSION['photo_return'] = $a->cmd;
659 $datatype = $a->argv[2];
660 $datum = $a->argv[3];
662 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
663 $datatype = 'upload';
665 $datatype = 'summary';
673 // Setup permissions structures
679 $remote_contact = false;
681 $owner_uid = $a->data['user']['uid'];
683 $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
685 if((local_user()) && (local_user() == $owner_uid))
688 if($community_page && remote_user()) {
689 $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
690 intval(remote_user()),
696 $remote_contact = true;
697 $visitor = remote_user();
702 // perhaps they're visiting - but not a community page, so they wouldn't have write access
704 if(remote_user() && (! $visitor)) {
705 $contact_id = $_SESSION['visitor_id'];
706 $groups = init_groups_visitor($contact_id);
707 $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
708 intval(remote_user()),
713 $remote_contact = true;
717 if(! $remote_contact) {
719 $contact_id = $_SESSION['cid'];
720 $contact = $a->contact;
724 // default permissions - anonymous user
726 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
728 // Profile owner - everything is visible
730 if(local_user() && (local_user() == $owner_uid)) {
733 elseif(remote_user()) {
734 // authenticated visitor - here lie dragons
735 $gs = '<<>>'; // should be impossible to match
737 foreach($groups as $g)
738 $gs .= '|<' . intval($g) . '>';
740 $sql_extra = sprintf(
741 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
742 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
743 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
744 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
746 intval(remote_user()),
747 intval(remote_user()),
758 if($datatype === 'upload') {
760 notice( t('Permission denied.'));
763 $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
765 $albumselect .= '<option value="" selected="selected" > </option>';
766 if(count($a->data['albums'])) {
767 foreach($a->data['albums'] as $album) {
768 if(($album['album'] === '') || ($album['album'] == t('Contact Photos')))
770 $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
774 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
776 $albumselect .= '</select>';
780 $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
781 'addon_text' => $uploader,
782 'default_upload' => true);
785 call_hooks('photo_upload_form',$ret);
787 $default_upload = '<input type="file" name="userfile" /> <div class="photos-upload-submit-wrapper" >
788 <input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>';
793 $tpl = load_view_file('view/photos_upload.tpl');
794 $o .= replace_macros($tpl,array(
795 '$pagename' => t('Upload Photos'),
796 '$sessid' => session_id(),
797 '$nickname' => $a->data['user']['nickname'],
798 '$newalbum' => t('New album name: '),
799 '$existalbumtext' => t('or existing album name: '),
800 '$albumselect' => $albumselect,
801 '$permissions' => t('Permissions'),
802 '$aclselect' => (($visitor) ? '' : populate_acl($a->user, $celeb)),
803 '$uploader' => $ret['addon_text'],
804 '$default' => (($ret['default_upload']) ? $default_upload : ''),
805 '$uploadurl' => $ret['post_url']
812 if($datatype === 'album') {
814 $album = hex2bin($datum);
816 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
817 $sql_extra GROUP BY `resource-id`",
822 $a->set_pager_total(count($r));
823 $a->set_pager_itemspage(20);
826 $r = q("SELECT `resource-id`, `id`, `filename`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
827 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
830 intval($a->pager['start']),
831 intval($a->pager['itemspage'])
834 $o .= '<h3>' . $album . '</h3>';
836 if($cmd === 'edit') {
837 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
839 $edit_tpl = load_view_file('view/album_edit.tpl');
840 $o .= replace_macros($edit_tpl,array(
841 '$nametext' => t('New album name: '),
842 '$nickname' => $a->data['user']['nickname'],
844 '$hexalbum' => bin2hex($album),
845 '$submit' => t('Submit'),
846 '$dropsubmit' => t('Delete Album')
852 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
854 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
855 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
856 . t('Edit Album') . '</a></div>';
860 $tpl = load_view_file('view/photo_album.tpl');
863 $o .= replace_macros($tpl,array(
865 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
866 '$phototitle' => t('View Photo'),
867 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
868 '$imgalt' => $rr['filename']
872 $o .= '<div id="photo-album-end"></div>';
880 if($datatype === 'image') {
882 require_once('security.php');
883 require_once('bbcode.php');
885 $o = '<div id="live-display"></div>' . "\r\n";
886 // fetch image, item containing image, then comments
888 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
889 $sql_extra ORDER BY `scale` ASC ",
895 notice( t('Photo not available') . EOL );
900 $hires = $lores = $ph[0];
902 if($ph[1]['scale'] == 2) {
903 // original is 640 or less, we can display it directly
904 $hires = $lores = $ph[0];
913 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']) . '">' . $ph[0]['album'] . '</a></h3>';
915 if($can_post && ($ph[0]['uid'] == $owner_uid)) {
916 $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>';
919 $o .= ( ( ($ph[0]['uid'] == local_user()) && (strlen($ph[0]['allow_cid']) || strlen($ph[0]['allow_gid'])
920 || strlen($ph[0]['deny_cid']) || strlen($ph[0]['deny_gid'])) )
921 ? ' - <img src="images/lock_icon.gif" class="lockview" alt="' . t('Private Message') . '" onclick="lockview(event,\'photo/' . $ph[0]['id'] . '\');" />'
928 $o .= '<a href="' . $a->get_baseurl() . '/photo/'
929 . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg" title="'
930 . t('View Full Size') . '" ><img src="' . $a->get_baseurl() . '/photo/'
931 . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg' . '" /></a>';
934 // Do we have an item for this photo?
936 $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
939 if(count($linked_items)) {
940 $link_item = $linked_items[0];
941 $r = q("SELECT COUNT(*) AS `total`
942 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
943 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
944 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
945 AND `item`.`uid` = %d
947 dbesc($link_item['uri']),
948 dbesc($link_item['uri']),
949 intval($link_item['uid'])
954 $a->set_pager_total($r[0]['total']);
957 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
958 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
959 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
960 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
961 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
962 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
963 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
964 AND `item`.`uid` = %d
966 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
967 dbesc($link_item['uri']),
968 dbesc($link_item['uri']),
969 intval($link_item['uid']),
970 intval($a->pager['start']),
971 intval($a->pager['itemspage'])
975 if((local_user()) && (local_user() == $link_item['uid'])) {
976 q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
977 intval($link_item['parent']),
983 $o .= '<div id="photo-caption" >' . $ph[0]['desc'] . '</div>';
985 if(count($linked_items) && strlen($link_item['tag'])) {
986 $arr = explode(',',$link_item['tag']);
987 // parse tags and add links
988 $o .= '<div id="in-this-photo-text">' . t('Tags: ') . '</div>';
989 $o .= '<div id="in-this-photo">';
991 foreach($arr as $t) {
994 $tag_str .= bbcode($t);
996 $o .= $tag_str . '</div>';
998 $o .= '<div id="tag-remove"><a href="' . $a->get_baseurl() . '/tagrm/' . $link_item['id'] . '">' . t('[Remove any tag]') . '</a></div>';
1002 if(($cmd === 'edit') && ($can_post)) {
1003 $edit_tpl = load_view_file('view/photo_edit.tpl');
1004 $o .= replace_macros($edit_tpl, array(
1005 '$id' => $ph[0]['id'],
1006 '$album' => $ph[0]['album'],
1007 '$newalbum' => t('New album name'),
1008 '$nickname' => $a->data['user']['nickname'],
1009 '$resource_id' => $ph[0]['resource-id'],
1010 '$capt_label' => t('Caption'),
1011 '$caption' => $ph[0]['desc'],
1012 '$tag_label' => t('Add a Tag'),
1013 '$tags' => $link_item['tag'],
1014 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
1015 '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
1016 '$submit' => t('Submit'),
1017 '$delete' => t('Delete Photo')
1021 if(count($linked_items)) {
1023 $cmnt_tpl = load_view_file('view/comment_item.tpl');
1024 $tpl = load_view_file('view/photo_item.tpl');
1025 $return_url = $a->cmd;
1027 $like_tpl = load_view_file('view/like.tpl');
1031 if($can_post || can_write_wall($a,$owner_uid))
1032 $likebuttons = replace_macros($like_tpl,array('$id' => $link_item['id']));
1035 $o .= '<div id="photo-like-div">';
1039 if($can_post || can_write_wall($a,$owner_uid)) {
1040 if($link_item['last-child']) {
1041 $o .= replace_macros($cmnt_tpl,array(
1042 '$return_path' => $return_url,
1043 '$type' => 'wall-comment',
1044 '$id' => $link_item['id'],
1045 '$parent' => $link_item['id'],
1046 '$profile_uid' => $owner_uid,
1047 '$mylink' => $contact['url'],
1048 '$mytitle' => t('This is you'),
1049 '$myphoto' => $contact['thumb'],
1062 foreach($r as $item) {
1063 like_puller($a,$item,$alike,'like');
1064 like_puller($a,$item,$dlike,'dislike');
1067 $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
1068 $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
1070 $o .= '<div id="photo-like-div">';
1078 if($can_post || can_write_wall($a,$owner_uid)) {
1079 if($link_item['last-child']) {
1080 $o .= replace_macros($cmnt_tpl,array(
1081 '$return_path' => $return_url,
1082 '$type' => 'wall-comment',
1083 '$id' => $link_item['id'],
1084 '$parent' => $link_item['id'],
1085 '$profile_uid' => $owner_uid,
1086 '$mylink' => $contact['url'],
1087 '$mytitle' => t('This is you'),
1088 '$myphoto' => $contact['thumb'],
1095 foreach($r as $item) {
1100 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
1103 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
1105 if($can_post || can_write_wall($a,$owner_uid)) {
1107 if($item['last-child']) {
1108 $comment = replace_macros($cmnt_tpl,array(
1109 '$return_path' => $return_url,
1110 '$type' => 'wall-comment',
1111 '$id' => $item['item_id'],
1112 '$parent' => $item['parent'],
1113 '$profile_uid' => $owner_uid,
1114 '$mylink' => $contact['url'],
1115 '$mytitle' => t('This is you'),
1116 '$myphoto' => $contact['thumb'],
1123 if(local_user() && ($item['contact-uid'] == local_user())
1124 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
1125 $profile_url = $redirect_url;
1126 $sparkle = ' sparkle';
1129 $profile_url = $item['url'];
1133 $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
1135 $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
1136 $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
1138 $profile_link = $profile_url;
1142 if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
1143 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id']));
1146 $o .= replace_macros($template,array(
1147 '$id' => $item['item_id'],
1148 '$profile_url' => $profile_link,
1149 '$name' => $profile_name,
1150 '$thumb' => $profile_avatar,
1151 '$sparkle' => $sparkle,
1152 '$title' => $item['title'],
1153 '$body' => bbcode($item['body']),
1154 '$ago' => relative_date($item['created']),
1155 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
1157 '$comment' => $comment
1167 // Default - show recent photos with upload link (if applicable)
1170 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
1171 $sql_extra GROUP BY `resource-id`",
1172 intval($a->data['user']['uid']),
1173 dbesc( t('Contact Photos'))
1176 $a->set_pager_total(count($r));
1177 $a->set_pager_itemspage(20);
1180 $r = q("SELECT `resource-id`, `id`, `filename`, `album`, max(`scale`) AS `scale` FROM `photo`
1181 WHERE `uid` = %d AND `album` != '%s'
1182 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
1183 intval($a->data['user']['uid']),
1184 dbesc( t('Contact Photos')),
1185 intval($a->pager['start']),
1186 intval($a->pager['itemspage'])
1189 $o .= '<h3>' . t('Recent Photos') . '</h3>';
1192 $o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
1193 . $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
1196 $tpl = load_view_file('view/photo_top.tpl');
1198 foreach($r as $rr) {
1199 $o .= replace_macros($tpl,array(
1201 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname']
1202 . '/image/' . $rr['resource-id'],
1203 '$phototitle' => t('View Photo'),
1204 '$imgsrc' => $a->get_baseurl() . '/photo/'
1205 . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.jpg',
1206 '$albumlink' => $a->get_baseurl() . '/photos/'
1207 . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
1208 '$albumname' => $rr['album'],
1209 '$albumalt' => t('View Album'),
1210 '$imgalt' => $rr['filename']
1214 $o .= '<div id="photo-top-end"></div>';