3 require_once('Photo.php');
4 require_once('include/items.php');
5 require_once('view/acl_selectors.php');
6 require_once('include/bbcode.php');
8 function photos_init(&$a) {
12 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' LIMIT 1",
19 $a->data['user'] = $r[0];
21 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d",
22 intval($a->data['user']['uid'])
26 $a->data['albums'] = $albums;
28 $o .= '<h4><a href="' . $a->get_baseurl() . '/profile/' . $a->data['user']['nickname'] . '">' . $a->data['user']['username'] . '</a></h4>';
29 $o .= '<h4>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h4>';
32 foreach($albums as $album) {
33 if((! strlen($album['album'])) || ($album['album'] == t('Contact Photos')))
35 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" />' . $album['album'] . '</a></li>';
39 $a->page['aside'] .= $o;
47 function photos_post(&$a) {
51 notice( t('Permission denied.') . EOL );
55 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
56 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
61 notice( t('Contact information unavailable') . EOL);
62 logger('photos_post: unable to locate contact record for logged in user. uid=' . local_user());
66 $contact_record = $r[0];
69 if(($a->argc > 2) && ($a->argv[1] === 'album')) {
70 $album = hex2bin($a->argv[2]);
72 if($album == t('Profile Photos') || $album == t('Contact Photos')) {
73 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
77 $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
82 notice( t('Album not found.') . EOL);
83 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
87 $newalbum = notags(trim($_POST['albumname']));
88 if($newalbum != $album) {
89 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
94 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
95 goaway($a->get_baseurl() . '/' . $newurl);
99 if($_POST['dropalbum'] == t('Delete Album')) {
102 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
103 intval(local_user()),
108 $res[] = "'" . dbesc($rr['rid']) . "'" ;
112 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
113 return; // NOTREACHED
115 $str_res = implode(',', $res);
117 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
120 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
125 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
126 dbesc(datetime_convert()),
127 dbesc($rr['parent-uri']),
131 $drop_id = intval($rr['id']);
132 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
133 $proc_debug = get_config('system','proc_debug');
135 // send the notification upstream/downstream as the case may be
138 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" $proc_debug & ",
144 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
145 return; // NOTREACHED
148 if(($a->argc > 1) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
149 $r = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
150 intval(local_user()),
154 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
155 intval(local_user()),
156 dbesc($r[0]['resource-id'])
158 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
159 dbesc($r[0]['resource-id']),
163 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
164 dbesc(datetime_convert()),
165 dbesc(datetime_convert()),
170 $url = $a->get_baseurl();
171 $drop_id = intval($i[0]['id']);
172 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
174 $proc_debug = get_config('system','proc_debug');
176 // send the notification upstream/downstream as the case may be
179 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" $proc_debug & ",
184 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
185 return; // NOTREACHED
188 if(($a->argc > 1) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false))) {
190 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
191 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
192 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
193 $resource_id = $a->argv[1];
195 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
199 if((count($p)) && ($p[0]['desc'] !== $desc)) {
200 $r = q("UPDATE `photo` SET `desc` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d",
208 // Create item container
211 $basename = basename($filename);
212 $uri = item_new_uri($a->get_hostname(),local_user());
216 $arr['uid'] = local_user();
218 $arr['parent-uri'] = $uri;
219 $arr['type'] = 'photo';
221 $arr['resource-id'] = $p[0]['resource-id'];
222 $arr['contact-id'] = $contact_record['id'];
223 $arr['owner-name'] = $contact_record['name'];
224 $arr['owner-link'] = $contact_record['url'];
225 $arr['owner-avatar'] = $contact_record['thumb'];
226 $arr['title'] = $title;
227 $arr['allow_cid'] = $p[0]['allow_cid'];
228 $arr['allow_gid'] = $p[0]['allow_gid'];
229 $arr['deny_cid'] = $p[0]['deny_cid'];
230 $arr['deny_gid'] = $p[0]['deny_gid'];
231 $arr['last-child'] = 1;
232 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
233 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]'
236 $item_id = item_store($arr);
241 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
247 $old_tag = $r[0]['tag'];
248 $old_inform = $r[0]['inform'];
251 if(strlen($rawtags)) {
256 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
258 $x = substr($rawtags,0,1);
259 if($x !== '@' && $x !== '#')
260 $rawtags = '#' . $rawtags;
262 $tags = get_tags($rawtags);
265 foreach($tags as $tag) {
266 if(strpos($tag,'@') === 0) {
267 $name = substr($tag,1);
268 if((strpos($name,'@')) || (strpos($name,'http://'))) {
270 $links = @lrdd($name);
272 foreach($links as $link) {
273 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
274 $profile = $link['@attributes']['href'];
275 if($link['@attributes']['rel'] === 'salmon') {
278 $inform .= 'url:' . str_replace(',','%2c',$link['@attributes']['href']);
285 if(strstr($name,'_')) {
286 $newname = str_replace('_',' ',$name);
287 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
293 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
299 $profile = $r[0]['url'];
302 $inform .= 'cid:' . $r[0]['id'];
306 if(strlen($str_tags))
308 $profile = str_replace(',','%2c',$profile);
309 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
316 if(strlen($newtag) && strlen($str_tags))
318 $newtag .= $str_tags;
320 $newinform = $old_inform;
321 if(strlen($newinform) && strlen($inform))
323 $newinform .= $inform;
325 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
328 dbesc(datetime_convert()),
329 dbesc(datetime_convert()),
334 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
335 return; // NOTREACHED
341 if(! x($_FILES,'userfile'))
344 if($_POST['partitionCount'])
347 $java_upload = false;
349 $album = notags(trim($_POST['album']));
350 $newalbum = notags(trim($_POST['newalbum']));
352 if(! strlen($album)) {
353 if(strlen($newalbum))
356 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
359 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
363 if((! count($r)) || ($album == t('Profile Photos')))
369 $str_group_allow = perms2str($_POST['group_allow']);
370 $str_contact_allow = perms2str($_POST['contact_allow']);
371 $str_group_deny = perms2str($_POST['group_deny']);
372 $str_contact_deny = perms2str($_POST['contact_deny']);
374 $src = $_FILES['userfile']['tmp_name'];
375 $filename = basename($_FILES['userfile']['name']);
376 $filesize = intval($_FILES['userfile']['size']);
378 $imagedata = @file_get_contents($src);
379 $ph = new Photo($imagedata);
381 if(! $ph->is_valid()) {
382 notice( t('Unable to process image.') . EOL );
389 $width = $ph->getWidth();
390 $height = $ph->getHeight();
394 $photo_hash = photo_new_resource();
396 $r = $ph->store(local_user(), 0, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
399 notice( t('Image upload failed.') . EOL );
403 if($width > 640 || $height > 640) {
404 $ph->scaleImage(640);
405 $ph->store(local_user(), 0, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
409 if($width > 320 || $height > 320) {
410 $ph->scaleImage(320);
411 $ph->store(local_user(), 0, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
415 $basename = basename($filename);
416 $uri = item_new_uri($a->get_hostname(), local_user());
418 // Create item container
423 $arr['uid'] = local_user();
425 $arr['parent-uri'] = $uri;
426 $arr['type'] = 'photo';
428 $arr['resource-id'] = $photo_hash;
429 $arr['contact-id'] = $contact_record['id'];
430 $arr['owner-name'] = $contact_record['name'];
431 $arr['owner-link'] = $contact_record['url'];
432 $arr['owner-avatar'] = $contact_record['thumb'];
433 $arr['title'] = $title;
434 $arr['allow_cid'] = $str_contact_allow;
435 $arr['allow_gid'] = $str_group_allow;
436 $arr['deny_cid'] = $str_contact_deny;
437 $arr['deny_gid'] = $str_group_deny;
438 $arr['last-child'] = 1;
439 $arr['visible'] = $visible;
440 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $contact_record['nickname'] . '/image/' . $photo_hash . ']'
441 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
444 $item_id = item_store($arr);
447 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
448 return; // NOTREACHED
452 return; // NOTREACHED
458 function photos_content(&$a) {
462 // photos/name/upload
463 // photos/name/album/xxxxx
464 // photos/name/album/xxxxx/edit
465 // photos/name/image/xxxxx
466 // photos/name/image/xxxxx/edit
469 if(! x($a->data,'user')) {
470 notice( t('No photos selected') . EOL );
474 $_SESSION['photo_return'] = $a->cmd;
481 $datatype = $a->argv[2];
482 $datum = $a->argv[3];
484 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
485 $datatype = 'upload';
487 $datatype = 'summary';
495 // Setup permissions structures
498 $owner_uid = $a->data['user']['uid'];
503 $remote_contact = false;
506 $contact_id = $_SESSION['visitor_id'];
507 $groups = init_groups_visitor($contact_id);
508 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
514 $remote_contact = true;
518 if(! $remote_contact) {
520 $contact_id = $_SESSION['cid'];
521 $contact = $a->contact;
526 // default permissions - anonymous user
528 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
530 // Profile owner - everything is visible
532 if(local_user() && (local_user() == $owner_uid)) {
535 elseif(remote_user()) {
536 // authenticated visitor - here lie dragons
537 $gs = '<<>>'; // should be impossible to match
539 foreach($groups as $g)
540 $gs .= '|<' . intval($g) . '>';
542 $sql_extra = sprintf(
543 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
544 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
545 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
546 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
548 intval($_SESSION['visitor_id']),
549 intval($_SESSION['visitor_id']),
560 if($datatype === 'upload') {
561 if( ! (local_user() && (local_user() == $a->data['user']['uid']))) {
562 notice( t('Permission denied.'));
565 $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
567 $albumselect .= '<option value="" selected="selected" > </option>';
568 if(count($a->data['albums'])) {
569 foreach($a->data['albums'] as $album) {
570 if(($album['album'] === '') || ($album['album'] == t('Contact Photos')))
572 $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
576 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
578 $albumselect .= '</select>';
579 $tpl = load_view_file('view/photos_upload.tpl');
580 $o .= replace_macros($tpl,array(
581 '$pagename' => t('Upload Photos'),
582 '$sessid' => session_id(),
583 '$newalbum' => t('New album name: '),
584 '$existalbumtext' => t('or existing album name: '),
585 '$filestext' => t('Select files to upload: '),
586 '$albumselect' => $albumselect,
587 '$permissions' => t('Permissions'),
588 '$aclselect' => populate_acl($a->user, $celeb),
589 '$archive' => $a->get_baseurl() . '/jumploader_z.jar',
590 '$nojava' => t('Use the following controls only if the Java uploader [above] fails to launch.'),
591 '$uploadurl' => $a->get_baseurl() . '/photos',
592 '$submit' => t('Submit')
599 if($datatype === 'album') {
601 $album = hex2bin($datum);
603 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
604 $sql_extra GROUP BY `resource-id`",
605 intval($a->data['user']['uid']),
609 $a->set_pager_total(count($r));
612 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
613 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
614 intval($a->data['user']['uid']),
616 intval($a->pager['start']),
617 intval($a->pager['itemspage'])
620 $o .= '<h3>' . $album . '</h3>';
622 if($cmd === 'edit') {
623 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
624 if(local_user() && (local_user() == $a->data['user']['uid'])) {
625 $edit_tpl = load_view_file('view/album_edit.tpl');
626 $o .= replace_macros($edit_tpl,array(
627 '$nametext' => t('New album name: '),
629 '$hexalbum' => bin2hex($album),
630 '$submit' => t('Submit'),
631 '$dropsubmit' => t('Delete Album')
637 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
638 if(local_user() && (local_user() == $a->data['user']['uid'])) {
639 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
640 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
641 . t('Edit Album') . '</a></div>';
645 $tpl = load_view_file('view/photo_album.tpl');
648 $o .= replace_macros($tpl,array(
650 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
651 '$phototitle' => t('View Photo'),
652 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
653 '$imgalt' => $rr['filename']
657 $o .= '<div id="photo-album-end"></div>';
663 if($datatype === 'image') {
665 require_once('security.php');
666 require_once('bbcode.php');
668 // fetch image, item containing image, then comments
670 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
671 $sql_extra ORDER BY `scale` ASC ",
672 intval($a->data['user']['uid']),
677 notice( t('Photo not available') . EOL );
682 $hires = $lores = $ph[0];
684 if($ph[1]['scale'] == 2) {
685 // original is 640 or less, we can display it directly
686 $hires = $lores = $ph[0];
695 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']) . '">' . $ph[0]['album'] . '</a></h3>';
697 if(local_user() && ($ph[0]['uid'] == local_user())) {
698 $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></div>';
702 $o .= '<a href="' . $a->get_baseurl() . '/photo/'
703 . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg" title="'
704 . t('View Full Size') . '" ><img src="' . $a->get_baseurl() . '/photo/'
705 . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg' . '" /></a>';
708 // Do we have an item for this photo?
710 $i1 = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
715 $r = q("SELECT COUNT(*) AS `total`
716 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
717 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
718 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
719 AND `item`.`uid` = %d
721 dbesc($i1[0]['uri']),
722 dbesc($i1[0]['uri']),
723 intval($i1[0]['uid'])
728 $a->set_pager_total($r[0]['total']);
731 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
732 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
733 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
734 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
735 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
736 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
737 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
738 AND `item`.`uid` = %d
740 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
741 dbesc($i1[0]['uri']),
742 dbesc($i1[0]['uri']),
743 intval($i1[0]['uid']),
744 intval($a->pager['start']),
745 intval($a->pager['itemspage'])
750 $o .= '<div id="photo-caption" >' . $ph[0]['desc'] . '</div>';
752 if(count($i1) && strlen($i1[0]['tag'])) {
753 $arr = explode(',',$i1[0]['tag']);
754 // parse tags and add links
755 $o .= '<div id="in-this-photo-text">' . t('Tags: ') . '</div>';
756 $o .= '<div id="in-this-photo">';
758 foreach($arr as $t) {
761 $tag_str .= bbcode($t);
763 $o .= $tag_str . '</div>';
766 if($cmd === 'edit') {
767 $edit_tpl = load_view_file('view/photo_edit.tpl');
768 $o .= replace_macros($edit_tpl, array(
769 '$id' => $ph[0]['id'],
770 '$resource_id' => $ph[0]['resource-id'],
771 '$capt_label' => t('Caption'),
772 '$caption' => $ph[0]['desc'],
773 '$tag_label' => t('Add a Tag'),
774 '$tags' => $i1[0]['tag'],
775 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
776 '$item_id' => ((count($i1)) ? $i1[0]['id'] : 0),
777 '$submit' => t('Submit'),
778 '$delete' => t('Delete Photo')
785 $cmnt_tpl = load_view_file('view/comment_item.tpl');
786 $tpl = load_view_file('view/photo_item.tpl');
787 $return_url = $a->cmd;
789 $like_tpl = load_view_file('view/like.tpl');
791 if(can_write_wall($a,$a->data['user']['uid'])) {
792 if($i1[0]['last-child']) {
793 $o .= replace_macros($cmnt_tpl,array(
794 '$return_path' => $return_url,
795 '$type' => 'wall-comment',
796 '$id' => $i1[0]['id'],
797 '$parent' => $i1[0]['id'],
798 '$profile_uid' => $a->data['user']['uid'],
799 '$mylink' => $contact['url'],
800 '$mytitle' => t('This is you'),
801 '$myphoto' => $contact['thumb'],
813 foreach($r as $item) {
814 like_puller($a,$item,$alike,'like');
815 like_puller($a,$item,$dlike,'dislike');
820 if(can_write_wall($a,$a->data['user']['uid']))
821 $likebuttons = replace_macros($like_tpl,array('$id' => $i1[0]['id']));
823 $like = ((isset($alike[$i1[0]['id']])) ? format_like($alike[$i1[0]['id']],$alike[$i1[0]['id'] . '-l'],'like',$i1[0]['id']) : '');
824 $dislike = ((isset($dlike[$i1[0]['id']])) ? format_like($dlike[$i1[0]['id']],$dlike[$i1[0]['id'] . '-l'],'dislike',$i1[0]['id']) : '');
830 foreach($r as $item) {
835 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
838 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
840 if(can_write_wall($a,$a->data['user']['uid'])) {
842 if($item['last-child']) {
843 $comment = replace_macros($cmnt_tpl,array(
844 '$return_path' => $return_url,
845 '$type' => 'wall-comment',
846 '$id' => $item['item_id'],
847 '$parent' => $item['parent'],
848 '$profile_uid' => $a->data['user']['uid'],
849 '$mylink' => $contact['url'],
850 '$mytitle' => t('This is you'),
851 '$myphoto' => $contact['thumb'],
858 if(local_user() && ($item['contact-uid'] == local_user())
859 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
860 $profile_url = $redirect_url;
861 $sparkle = ' sparkle';
864 $profile_url = $item['url'];
868 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
869 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
870 $profile_link = $profile_url;
874 if(($item['contact-id'] == $_SESSION['visitor_id']) || ($item['uid'] == local_user()))
875 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id']));
878 $o .= replace_macros($template,array(
879 '$id' => $item['item_id'],
880 '$profile_url' => $profile_link,
881 '$name' => $profile_name,
882 '$thumb' => $profile_avatar,
883 '$sparkle' => $sparkle,
884 '$title' => $item['title'],
885 '$body' => bbcode($item['body']),
886 '$ago' => relative_date($item['created']),
887 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
889 '$comment' => $comment
899 // Default - show recent photos with upload link (if applicable)
901 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
902 $sql_extra GROUP BY `resource-id`",
903 intval($a->data['user']['uid']),
904 dbesc( t('Contact Photos'))
907 $a->set_pager_total(count($r));
910 $r = q("SELECT `resource-id`, `album`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
911 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
912 intval($a->data['user']['uid']),
913 dbesc( t('Contact Photos')),
914 intval($a->pager['start']),
915 intval($a->pager['itemspage'])
918 $o .= '<h3>' . t('Recent Photos') . '</h3>';
920 if( local_user() && (local_user() == $a->data['user']['uid'])) {
921 $o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
922 . $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
925 $tpl = load_view_file('view/photo_top.tpl');
928 $o .= replace_macros($tpl,array(
930 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname']
931 . '/image/' . $rr['resource-id'],
932 '$phototitle' => t('View Photo'),
933 '$imgsrc' => $a->get_baseurl() . '/photo/'
934 . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
935 '$albumlink' => $a->get_baseurl . '/photos/'
936 . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
937 '$albumname' => $rr['album'],
938 '$albumalt' => t('View Album'),
939 '$imgalt' => $rr['filename']
943 $o .= '<div id="photo-top-end"></div>';