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;
263 $tags = get_tags($rawtags);
266 foreach($tags as $tag) {
267 if(strpos($tag,'@') === 0) {
268 $name = substr($tag,1);
269 if((strpos($name,'@')) || (strpos($name,'http://'))) {
271 $links = @lrdd($name);
273 foreach($links as $link) {
274 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
275 $profile = $link['@attributes']['href'];
276 if($link['@attributes']['rel'] === 'salmon') {
277 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
284 $taginfo[] = array($newname,$profile,$salmon);
288 if(strstr($name,'_')) {
289 $newname = str_replace('_',' ',$name);
290 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
296 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
302 $profile = $r[0]['url'];
303 $notify = 'cid:' . $r[0]['id'];
310 $taginfo[] = array($newname,$profile,$notify);
311 if(strlen($str_tags))
313 $profile = str_replace(',','%2c',$profile);
314 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
321 if(strlen($newtag) && strlen($str_tags))
323 $newtag .= $str_tags;
325 $newinform = $old_inform;
326 if(strlen($newinform) && strlen($inform))
328 $newinform .= $inform;
330 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
333 dbesc(datetime_convert()),
334 dbesc(datetime_convert()),
339 if(count($taginfo)) {
340 foreach($taginfo as $tagged) {
341 // $slap = create_photo_tag(local_user(),$item_id, $tagged);
346 // call notifier on new tag activity
349 // $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
351 // $proc_debug = get_config('system','proc_debug');
353 // send the notification upstream/downstream as the case may be
355 // if($i[0]['visible'])
356 // proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" $proc_debug & ",
362 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
363 return; // NOTREACHED
367 // default post action - upload a photo
369 if(! x($_FILES,'userfile'))
372 if($_POST['partitionCount'])
375 $java_upload = false;
377 $album = notags(trim($_POST['album']));
378 $newalbum = notags(trim($_POST['newalbum']));
380 if(! strlen($album)) {
381 if(strlen($newalbum))
384 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
387 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
391 if((! count($r)) || ($album == t('Profile Photos')))
397 $str_group_allow = perms2str($_POST['group_allow']);
398 $str_contact_allow = perms2str($_POST['contact_allow']);
399 $str_group_deny = perms2str($_POST['group_deny']);
400 $str_contact_deny = perms2str($_POST['contact_deny']);
402 $src = $_FILES['userfile']['tmp_name'];
403 $filename = basename($_FILES['userfile']['name']);
404 $filesize = intval($_FILES['userfile']['size']);
406 $imagedata = @file_get_contents($src);
407 $ph = new Photo($imagedata);
409 if(! $ph->is_valid()) {
410 notice( t('Unable to process image.') . EOL );
417 $width = $ph->getWidth();
418 $height = $ph->getHeight();
422 $photo_hash = photo_new_resource();
424 $r = $ph->store(local_user(), 0, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
427 notice( t('Image upload failed.') . EOL );
431 if($width > 640 || $height > 640) {
432 $ph->scaleImage(640);
433 $ph->store(local_user(), 0, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
437 if($width > 320 || $height > 320) {
438 $ph->scaleImage(320);
439 $ph->store(local_user(), 0, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
443 $basename = basename($filename);
444 $uri = item_new_uri($a->get_hostname(), local_user());
446 // Create item container
451 $arr['uid'] = local_user();
453 $arr['parent-uri'] = $uri;
454 $arr['type'] = 'photo';
456 $arr['resource-id'] = $photo_hash;
457 $arr['contact-id'] = $contact_record['id'];
458 $arr['owner-name'] = $contact_record['name'];
459 $arr['owner-link'] = $contact_record['url'];
460 $arr['owner-avatar'] = $contact_record['thumb'];
461 $arr['title'] = $title;
462 $arr['allow_cid'] = $str_contact_allow;
463 $arr['allow_gid'] = $str_group_allow;
464 $arr['deny_cid'] = $str_contact_deny;
465 $arr['deny_gid'] = $str_group_deny;
466 $arr['last-child'] = 1;
467 $arr['visible'] = $visible;
468 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $contact_record['nickname'] . '/image/' . $photo_hash . ']'
469 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
472 $item_id = item_store($arr);
475 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
476 return; // NOTREACHED
480 return; // NOTREACHED
486 function photos_content(&$a) {
490 // photos/name/upload
491 // photos/name/album/xxxxx
492 // photos/name/album/xxxxx/edit
493 // photos/name/image/xxxxx
494 // photos/name/image/xxxxx/edit
497 if(! x($a->data,'user')) {
498 notice( t('No photos selected') . EOL );
502 $_SESSION['photo_return'] = $a->cmd;
509 $datatype = $a->argv[2];
510 $datum = $a->argv[3];
512 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
513 $datatype = 'upload';
515 $datatype = 'summary';
523 // Setup permissions structures
526 $owner_uid = $a->data['user']['uid'];
531 $remote_contact = false;
534 $contact_id = $_SESSION['visitor_id'];
535 $groups = init_groups_visitor($contact_id);
536 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
542 $remote_contact = true;
546 if(! $remote_contact) {
548 $contact_id = $_SESSION['cid'];
549 $contact = $a->contact;
554 // default permissions - anonymous user
556 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
558 // Profile owner - everything is visible
560 if(local_user() && (local_user() == $owner_uid)) {
563 elseif(remote_user()) {
564 // authenticated visitor - here lie dragons
565 $gs = '<<>>'; // should be impossible to match
567 foreach($groups as $g)
568 $gs .= '|<' . intval($g) . '>';
570 $sql_extra = sprintf(
571 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
572 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
573 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
574 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
576 intval($_SESSION['visitor_id']),
577 intval($_SESSION['visitor_id']),
588 if($datatype === 'upload') {
589 if( ! (local_user() && (local_user() == $a->data['user']['uid']))) {
590 notice( t('Permission denied.'));
593 $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
595 $albumselect .= '<option value="" selected="selected" > </option>';
596 if(count($a->data['albums'])) {
597 foreach($a->data['albums'] as $album) {
598 if(($album['album'] === '') || ($album['album'] == t('Contact Photos')))
600 $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
604 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
606 $albumselect .= '</select>';
607 $tpl = load_view_file('view/photos_upload.tpl');
608 $o .= replace_macros($tpl,array(
609 '$pagename' => t('Upload Photos'),
610 '$sessid' => session_id(),
611 '$newalbum' => t('New album name: '),
612 '$existalbumtext' => t('or existing album name: '),
613 '$filestext' => t('Select files to upload: '),
614 '$albumselect' => $albumselect,
615 '$permissions' => t('Permissions'),
616 '$aclselect' => populate_acl($a->user, $celeb),
617 '$archive' => $a->get_baseurl() . '/jumploader_z.jar',
618 '$nojava' => t('Use the following controls only if the Java uploader [above] fails to launch.'),
619 '$uploadurl' => $a->get_baseurl() . '/photos',
620 '$submit' => t('Submit')
627 if($datatype === 'album') {
629 $album = hex2bin($datum);
631 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
632 $sql_extra GROUP BY `resource-id`",
633 intval($a->data['user']['uid']),
637 $a->set_pager_total(count($r));
640 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
641 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
642 intval($a->data['user']['uid']),
644 intval($a->pager['start']),
645 intval($a->pager['itemspage'])
648 $o .= '<h3>' . $album . '</h3>';
650 if($cmd === 'edit') {
651 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
652 if(local_user() && (local_user() == $a->data['user']['uid'])) {
653 $edit_tpl = load_view_file('view/album_edit.tpl');
654 $o .= replace_macros($edit_tpl,array(
655 '$nametext' => t('New album name: '),
657 '$hexalbum' => bin2hex($album),
658 '$submit' => t('Submit'),
659 '$dropsubmit' => t('Delete Album')
665 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
666 if(local_user() && (local_user() == $a->data['user']['uid'])) {
667 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
668 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
669 . t('Edit Album') . '</a></div>';
673 $tpl = load_view_file('view/photo_album.tpl');
676 $o .= replace_macros($tpl,array(
678 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
679 '$phototitle' => t('View Photo'),
680 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
681 '$imgalt' => $rr['filename']
685 $o .= '<div id="photo-album-end"></div>';
691 if($datatype === 'image') {
693 require_once('security.php');
694 require_once('bbcode.php');
696 $o = '<div id="live-display"></div>' . "\r\n";
697 // fetch image, item containing image, then comments
699 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
700 $sql_extra ORDER BY `scale` ASC ",
701 intval($a->data['user']['uid']),
706 notice( t('Photo not available') . EOL );
711 $hires = $lores = $ph[0];
713 if($ph[1]['scale'] == 2) {
714 // original is 640 or less, we can display it directly
715 $hires = $lores = $ph[0];
724 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']) . '">' . $ph[0]['album'] . '</a></h3>';
726 if(local_user() && ($ph[0]['uid'] == local_user())) {
727 $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>';
731 $o .= '<a href="' . $a->get_baseurl() . '/photo/'
732 . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg" title="'
733 . t('View Full Size') . '" ><img src="' . $a->get_baseurl() . '/photo/'
734 . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg' . '" /></a>';
737 // Do we have an item for this photo?
739 $i1 = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
744 $r = q("SELECT COUNT(*) AS `total`
745 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
746 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
747 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
748 AND `item`.`uid` = %d
750 dbesc($i1[0]['uri']),
751 dbesc($i1[0]['uri']),
752 intval($i1[0]['uid'])
757 $a->set_pager_total($r[0]['total']);
760 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
761 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
762 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
763 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
764 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
765 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
766 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
767 AND `item`.`uid` = %d
769 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
770 dbesc($i1[0]['uri']),
771 dbesc($i1[0]['uri']),
772 intval($i1[0]['uid']),
773 intval($a->pager['start']),
774 intval($a->pager['itemspage'])
779 $o .= '<div id="photo-caption" >' . $ph[0]['desc'] . '</div>';
781 if(count($i1) && strlen($i1[0]['tag'])) {
782 $arr = explode(',',$i1[0]['tag']);
783 // parse tags and add links
784 $o .= '<div id="in-this-photo-text">' . t('Tags: ') . '</div>';
785 $o .= '<div id="in-this-photo">';
787 foreach($arr as $t) {
790 $tag_str .= bbcode($t);
792 $o .= $tag_str . '</div>';
795 if($cmd === 'edit') {
796 $edit_tpl = load_view_file('view/photo_edit.tpl');
797 $o .= replace_macros($edit_tpl, array(
798 '$id' => $ph[0]['id'],
799 '$resource_id' => $ph[0]['resource-id'],
800 '$capt_label' => t('Caption'),
801 '$caption' => $ph[0]['desc'],
802 '$tag_label' => t('Add a Tag'),
803 '$tags' => $i1[0]['tag'],
804 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
805 '$item_id' => ((count($i1)) ? $i1[0]['id'] : 0),
806 '$submit' => t('Submit'),
807 '$delete' => t('Delete Photo')
814 $cmnt_tpl = load_view_file('view/comment_item.tpl');
815 $tpl = load_view_file('view/photo_item.tpl');
816 $return_url = $a->cmd;
818 $like_tpl = load_view_file('view/like.tpl');
820 if(can_write_wall($a,$a->data['user']['uid'])) {
821 if($i1[0]['last-child']) {
822 $o .= replace_macros($cmnt_tpl,array(
823 '$return_path' => $return_url,
824 '$type' => 'wall-comment',
825 '$id' => $i1[0]['id'],
826 '$parent' => $i1[0]['id'],
827 '$profile_uid' => $a->data['user']['uid'],
828 '$mylink' => $contact['url'],
829 '$mytitle' => t('This is you'),
830 '$myphoto' => $contact['thumb'],
842 foreach($r as $item) {
843 like_puller($a,$item,$alike,'like');
844 like_puller($a,$item,$dlike,'dislike');
849 if(can_write_wall($a,$a->data['user']['uid']))
850 $likebuttons = replace_macros($like_tpl,array('$id' => $i1[0]['id']));
852 $like = ((isset($alike[$i1[0]['id']])) ? format_like($alike[$i1[0]['id']],$alike[$i1[0]['id'] . '-l'],'like',$i1[0]['id']) : '');
853 $dislike = ((isset($dlike[$i1[0]['id']])) ? format_like($dlike[$i1[0]['id']],$dlike[$i1[0]['id'] . '-l'],'dislike',$i1[0]['id']) : '');
855 $o .= '<div id="photo-like-div">';
862 foreach($r as $item) {
867 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
870 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
872 if(can_write_wall($a,$a->data['user']['uid'])) {
874 if($item['last-child']) {
875 $comment = replace_macros($cmnt_tpl,array(
876 '$return_path' => $return_url,
877 '$type' => 'wall-comment',
878 '$id' => $item['item_id'],
879 '$parent' => $item['parent'],
880 '$profile_uid' => $a->data['user']['uid'],
881 '$mylink' => $contact['url'],
882 '$mytitle' => t('This is you'),
883 '$myphoto' => $contact['thumb'],
890 if(local_user() && ($item['contact-uid'] == local_user())
891 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
892 $profile_url = $redirect_url;
893 $sparkle = ' sparkle';
896 $profile_url = $item['url'];
900 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
901 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
902 $profile_link = $profile_url;
906 if(($item['contact-id'] == $_SESSION['visitor_id']) || ($item['uid'] == local_user()))
907 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id']));
910 $o .= replace_macros($template,array(
911 '$id' => $item['item_id'],
912 '$profile_url' => $profile_link,
913 '$name' => $profile_name,
914 '$thumb' => $profile_avatar,
915 '$sparkle' => $sparkle,
916 '$title' => $item['title'],
917 '$body' => bbcode($item['body']),
918 '$ago' => relative_date($item['created']),
919 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
921 '$comment' => $comment
931 // Default - show recent photos with upload link (if applicable)
933 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
934 $sql_extra GROUP BY `resource-id`",
935 intval($a->data['user']['uid']),
936 dbesc( t('Contact Photos'))
939 $a->set_pager_total(count($r));
942 $r = q("SELECT `resource-id`, `album`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
943 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
944 intval($a->data['user']['uid']),
945 dbesc( t('Contact Photos')),
946 intval($a->pager['start']),
947 intval($a->pager['itemspage'])
950 $o .= '<h3>' . t('Recent Photos') . '</h3>';
952 if( local_user() && (local_user() == $a->data['user']['uid'])) {
953 $o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
954 . $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
957 $tpl = load_view_file('view/photo_top.tpl');
960 $o .= replace_macros($tpl,array(
962 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname']
963 . '/image/' . $rr['resource-id'],
964 '$phototitle' => t('View Photo'),
965 '$imgsrc' => $a->get_baseurl() . '/photo/'
966 . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
967 '$albumlink' => $a->get_baseurl . '/photos/'
968 . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
969 '$albumname' => $rr['album'],
970 '$albumalt' => t('View Album'),
971 '$imgalt' => $rr['filename']
975 $o .= '<div id="photo-top-end"></div>';