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) {
14 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' LIMIT 1",
21 $a->data['user'] = $r[0];
23 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d",
24 intval($a->data['user']['uid'])
28 $a->data['albums'] = $albums;
30 $o .= '<h4><a href="' . $a->get_baseurl() . '/profile/' . $a->data['user']['nickname'] . '">' . $a->data['user']['username'] . '</a></h4>';
31 $o .= '<h4>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h4>';
34 foreach($albums as $album) {
35 if((! strlen($album['album'])) || ($album['album'] == t('Contact Photos')))
37 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" />' . $album['album'] . '</a></li>';
42 if(! x($a->page,'aside'))
43 $a->page['aside'] = '';
44 $a->page['aside'] .= $o;
52 function photos_post(&$a) {
56 notice( t('Permission denied.') . EOL );
60 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
61 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
66 notice( t('Contact information unavailable') . EOL);
67 logger('photos_post: unable to locate contact record for logged in user. uid=' . local_user());
71 $contact_record = $r[0];
74 if(($a->argc > 2) && ($a->argv[1] === 'album')) {
75 $album = hex2bin($a->argv[2]);
77 if($album == t('Profile Photos') || $album == t('Contact Photos')) {
78 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
82 $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
87 notice( t('Album not found.') . EOL);
88 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
92 $newalbum = notags(trim($_POST['albumname']));
93 if($newalbum != $album) {
94 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
99 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
100 goaway($a->get_baseurl() . '/' . $newurl);
101 return; // NOTREACHED
104 if($_POST['dropalbum'] == t('Delete Album')) {
107 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
108 intval(local_user()),
113 $res[] = "'" . dbesc($rr['rid']) . "'" ;
117 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
118 return; // NOTREACHED
120 $str_res = implode(',', $res);
122 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
125 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
130 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
131 dbesc(datetime_convert()),
132 dbesc($rr['parent-uri']),
136 $drop_id = intval($rr['id']);
137 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
138 $proc_debug = get_config('system','proc_debug');
140 // send the notification upstream/downstream as the case may be
143 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" $proc_debug & ",
149 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
150 return; // NOTREACHED
153 if(($a->argc > 1) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
154 $r = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
155 intval(local_user()),
159 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
160 intval(local_user()),
161 dbesc($r[0]['resource-id'])
163 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
164 dbesc($r[0]['resource-id']),
168 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
169 dbesc(datetime_convert()),
170 dbesc(datetime_convert()),
175 $url = $a->get_baseurl();
176 $drop_id = intval($i[0]['id']);
177 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
179 $proc_debug = get_config('system','proc_debug');
181 // send the notification upstream/downstream as the case may be
184 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" $proc_debug & ",
189 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
190 return; // NOTREACHED
193 if(($a->argc > 1) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false))) {
195 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
196 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
197 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
198 $resource_id = $a->argv[1];
200 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
204 if((count($p)) && ($p[0]['desc'] !== $desc)) {
205 $r = q("UPDATE `photo` SET `desc` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d",
213 // Create item container
216 $basename = basename($filename);
217 $uri = item_new_uri($a->get_hostname(),local_user());
221 $arr['uid'] = local_user();
223 $arr['parent-uri'] = $uri;
224 $arr['type'] = 'photo';
226 $arr['resource-id'] = $p[0]['resource-id'];
227 $arr['contact-id'] = $contact_record['id'];
228 $arr['owner-name'] = $contact_record['name'];
229 $arr['owner-link'] = $contact_record['url'];
230 $arr['owner-avatar'] = $contact_record['thumb'];
231 $arr['author-name'] = $contact_record['name'];
232 $arr['author-link'] = $contact_record['url'];
233 $arr['author-avatar'] = $contact_record['thumb'];
234 $arr['title'] = $title;
235 $arr['allow_cid'] = $p[0]['allow_cid'];
236 $arr['allow_gid'] = $p[0]['allow_gid'];
237 $arr['deny_cid'] = $p[0]['deny_cid'];
238 $arr['deny_gid'] = $p[0]['deny_gid'];
239 $arr['last-child'] = 1;
240 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
241 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]'
244 $item_id = item_store($arr);
249 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
255 $old_tag = $r[0]['tag'];
256 $old_inform = $r[0]['inform'];
259 if(strlen($rawtags)) {
264 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
266 $x = substr($rawtags,0,1);
267 if($x !== '@' && $x !== '#')
268 $rawtags = '#' . $rawtags;
271 $tags = get_tags($rawtags);
274 foreach($tags as $tag) {
275 if(strpos($tag,'@') === 0) {
276 $name = substr($tag,1);
277 if((strpos($name,'@')) || (strpos($name,'http://'))) {
279 $links = @lrdd($name);
281 foreach($links as $link) {
282 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
283 $profile = $link['@attributes']['href'];
284 if($link['@attributes']['rel'] === 'salmon') {
285 $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
292 $taginfo[] = array($newname,$profile,$salmon);
296 if(strstr($name,'_')) {
297 $newname = str_replace('_',' ',$name);
298 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
304 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
310 $profile = $r[0]['url'];
311 $notify = 'cid:' . $r[0]['id'];
318 $taginfo[] = array($newname,$profile,$notify);
319 if(strlen($str_tags))
321 $profile = str_replace(',','%2c',$profile);
322 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
329 if(strlen($newtag) && strlen($str_tags))
331 $newtag .= $str_tags;
333 $newinform = $old_inform;
334 if(strlen($newinform) && strlen($inform))
336 $newinform .= $inform;
338 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
341 dbesc(datetime_convert()),
342 dbesc(datetime_convert()),
347 if(count($taginfo)) {
348 foreach($taginfo as $tagged) {
349 // $slap = create_photo_tag(local_user(),$item_id, $tagged);
354 // call notifier on new tag activity
357 // $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
359 // $proc_debug = get_config('system','proc_debug');
361 // send the notification upstream/downstream as the case may be
363 // if($i[0]['visible'])
364 // proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" $proc_debug & ",
370 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
371 return; // NOTREACHED
375 // default post action - upload a photo
377 if(! x($_FILES,'userfile'))
380 if($_POST['partitionCount'])
383 $java_upload = false;
385 $album = notags(trim($_POST['album']));
386 $newalbum = notags(trim($_POST['newalbum']));
388 if(! strlen($album)) {
389 if(strlen($newalbum))
392 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
395 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
399 if((! count($r)) || ($album == t('Profile Photos')))
405 $str_group_allow = perms2str($_POST['group_allow']);
406 $str_contact_allow = perms2str($_POST['contact_allow']);
407 $str_group_deny = perms2str($_POST['group_deny']);
408 $str_contact_deny = perms2str($_POST['contact_deny']);
410 $src = $_FILES['userfile']['tmp_name'];
411 $filename = basename($_FILES['userfile']['name']);
412 $filesize = intval($_FILES['userfile']['size']);
414 $imagedata = @file_get_contents($src);
415 $ph = new Photo($imagedata);
417 if(! $ph->is_valid()) {
418 notice( t('Unable to process image.') . EOL );
425 $width = $ph->getWidth();
426 $height = $ph->getHeight();
430 $photo_hash = photo_new_resource();
432 $r = $ph->store(local_user(), 0, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
435 notice( t('Image upload failed.') . EOL );
439 if($width > 640 || $height > 640) {
440 $ph->scaleImage(640);
441 $ph->store(local_user(), 0, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
445 if($width > 320 || $height > 320) {
446 $ph->scaleImage(320);
447 $ph->store(local_user(), 0, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
451 $basename = basename($filename);
452 $uri = item_new_uri($a->get_hostname(), local_user());
454 // Create item container
459 $arr['uid'] = local_user();
461 $arr['parent-uri'] = $uri;
462 $arr['type'] = 'photo';
464 $arr['resource-id'] = $photo_hash;
465 $arr['contact-id'] = $contact_record['id'];
466 $arr['owner-name'] = $contact_record['name'];
467 $arr['owner-link'] = $contact_record['url'];
468 $arr['owner-avatar'] = $contact_record['thumb'];
469 $arr['author-name'] = $contact_record['name'];
470 $arr['author-link'] = $contact_record['url'];
471 $arr['author-avatar'] = $contact_record['thumb'];
473 $arr['allow_cid'] = $str_contact_allow;
474 $arr['allow_gid'] = $str_group_allow;
475 $arr['deny_cid'] = $str_contact_deny;
476 $arr['deny_gid'] = $str_group_deny;
477 $arr['last-child'] = 1;
478 $arr['visible'] = $visible;
479 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $contact_record['nickname'] . '/image/' . $photo_hash . ']'
480 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
483 $item_id = item_store($arr);
486 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
487 return; // NOTREACHED
491 return; // NOTREACHED
497 function photos_content(&$a) {
501 // photos/name/upload
502 // photos/name/album/xxxxx
503 // photos/name/album/xxxxx/edit
504 // photos/name/image/xxxxx
505 // photos/name/image/xxxxx/edit
508 if(! x($a->data,'user')) {
509 notice( t('No photos selected') . EOL );
513 $_SESSION['photo_return'] = $a->cmd;
520 $datatype = $a->argv[2];
521 $datum = $a->argv[3];
523 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
524 $datatype = 'upload';
526 $datatype = 'summary';
534 // Setup permissions structures
537 $owner_uid = $a->data['user']['uid'];
542 $remote_contact = false;
545 $contact_id = $_SESSION['visitor_id'];
546 $groups = init_groups_visitor($contact_id);
547 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
553 $remote_contact = true;
557 if(! $remote_contact) {
559 $contact_id = $_SESSION['cid'];
560 $contact = $a->contact;
565 // default permissions - anonymous user
567 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
569 // Profile owner - everything is visible
571 if(local_user() && (local_user() == $owner_uid)) {
574 elseif(remote_user()) {
575 // authenticated visitor - here lie dragons
576 $gs = '<<>>'; // should be impossible to match
578 foreach($groups as $g)
579 $gs .= '|<' . intval($g) . '>';
581 $sql_extra = sprintf(
582 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
583 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
584 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
585 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
587 intval($_SESSION['visitor_id']),
588 intval($_SESSION['visitor_id']),
599 if($datatype === 'upload') {
600 if( ! (local_user() && (local_user() == $a->data['user']['uid']))) {
601 notice( t('Permission denied.'));
604 $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
606 $albumselect .= '<option value="" selected="selected" > </option>';
607 if(count($a->data['albums'])) {
608 foreach($a->data['albums'] as $album) {
609 if(($album['album'] === '') || ($album['album'] == t('Contact Photos')))
611 $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
615 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
617 $albumselect .= '</select>';
618 $tpl = load_view_file('view/photos_upload.tpl');
619 $o .= replace_macros($tpl,array(
620 '$pagename' => t('Upload Photos'),
621 '$sessid' => session_id(),
622 '$newalbum' => t('New album name: '),
623 '$existalbumtext' => t('or existing album name: '),
624 '$filestext' => t('Select files to upload: '),
625 '$albumselect' => $albumselect,
626 '$permissions' => t('Permissions'),
627 '$aclselect' => populate_acl($a->user, $celeb),
628 '$archive' => $a->get_baseurl() . '/jumploader_z.jar',
629 '$nojava' => t('Use the following controls only if the Java uploader [above] fails to launch.'),
630 '$uploadurl' => $a->get_baseurl() . '/photos',
631 '$submit' => t('Submit')
638 if($datatype === 'album') {
640 $album = hex2bin($datum);
642 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
643 $sql_extra GROUP BY `resource-id`",
644 intval($a->data['user']['uid']),
648 $a->set_pager_total(count($r));
651 $r = q("SELECT `resource-id`, `id`, `filename`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
652 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
653 intval($a->data['user']['uid']),
655 intval($a->pager['start']),
656 intval($a->pager['itemspage'])
659 $o .= '<h3>' . $album . '</h3>';
661 if($cmd === 'edit') {
662 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
663 if(local_user() && (local_user() == $a->data['user']['uid'])) {
664 $edit_tpl = load_view_file('view/album_edit.tpl');
665 $o .= replace_macros($edit_tpl,array(
666 '$nametext' => t('New album name: '),
668 '$hexalbum' => bin2hex($album),
669 '$submit' => t('Submit'),
670 '$dropsubmit' => t('Delete Album')
676 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
677 if(local_user() && (local_user() == $a->data['user']['uid'])) {
678 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
679 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
680 . t('Edit Album') . '</a></div>';
684 $tpl = load_view_file('view/photo_album.tpl');
687 $o .= replace_macros($tpl,array(
689 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
690 '$phototitle' => t('View Photo'),
691 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
692 '$imgalt' => $rr['filename']
696 $o .= '<div id="photo-album-end"></div>';
702 if($datatype === 'image') {
704 require_once('security.php');
705 require_once('bbcode.php');
707 $o = '<div id="live-display"></div>' . "\r\n";
708 // fetch image, item containing image, then comments
710 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
711 $sql_extra ORDER BY `scale` ASC ",
712 intval($a->data['user']['uid']),
717 notice( t('Photo not available') . EOL );
722 $hires = $lores = $ph[0];
724 if($ph[1]['scale'] == 2) {
725 // original is 640 or less, we can display it directly
726 $hires = $lores = $ph[0];
735 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']) . '">' . $ph[0]['album'] . '</a></h3>';
737 if(local_user() && ($ph[0]['uid'] == local_user())) {
738 $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>';
742 $o .= '<a href="' . $a->get_baseurl() . '/photo/'
743 . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg" title="'
744 . t('View Full Size') . '" ><img src="' . $a->get_baseurl() . '/photo/'
745 . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg' . '" /></a>';
748 // Do we have an item for this photo?
750 $i1 = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
755 $r = q("SELECT COUNT(*) AS `total`
756 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
757 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
758 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
759 AND `item`.`uid` = %d
761 dbesc($i1[0]['uri']),
762 dbesc($i1[0]['uri']),
763 intval($i1[0]['uid'])
768 $a->set_pager_total($r[0]['total']);
771 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
772 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
773 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
774 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
775 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
776 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
777 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
778 AND `item`.`uid` = %d
780 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
781 dbesc($i1[0]['uri']),
782 dbesc($i1[0]['uri']),
783 intval($i1[0]['uid']),
784 intval($a->pager['start']),
785 intval($a->pager['itemspage'])
790 $o .= '<div id="photo-caption" >' . $ph[0]['desc'] . '</div>';
792 if(count($i1) && strlen($i1[0]['tag'])) {
793 $arr = explode(',',$i1[0]['tag']);
794 // parse tags and add links
795 $o .= '<div id="in-this-photo-text">' . t('Tags: ') . '</div>';
796 $o .= '<div id="in-this-photo">';
798 foreach($arr as $t) {
801 $tag_str .= bbcode($t);
803 $o .= $tag_str . '</div>';
806 if($cmd === 'edit') {
807 $edit_tpl = load_view_file('view/photo_edit.tpl');
808 $o .= replace_macros($edit_tpl, array(
809 '$id' => $ph[0]['id'],
810 '$resource_id' => $ph[0]['resource-id'],
811 '$capt_label' => t('Caption'),
812 '$caption' => $ph[0]['desc'],
813 '$tag_label' => t('Add a Tag'),
814 '$tags' => $i1[0]['tag'],
815 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
816 '$item_id' => ((count($i1)) ? $i1[0]['id'] : 0),
817 '$submit' => t('Submit'),
818 '$delete' => t('Delete Photo')
825 $cmnt_tpl = load_view_file('view/comment_item.tpl');
826 $tpl = load_view_file('view/photo_item.tpl');
827 $return_url = $a->cmd;
829 $like_tpl = load_view_file('view/like.tpl');
833 if(can_write_wall($a,$a->data['user']['uid']))
834 $likebuttons = replace_macros($like_tpl,array('$id' => $i1[0]['id']));
837 $o .= '<div id="photo-like-div">';
842 if(can_write_wall($a,$a->data['user']['uid'])) {
843 if($i1[0]['last-child']) {
844 $o .= replace_macros($cmnt_tpl,array(
845 '$return_path' => $return_url,
846 '$type' => 'wall-comment',
847 '$id' => $i1[0]['id'],
848 '$parent' => $i1[0]['id'],
849 '$profile_uid' => $a->data['user']['uid'],
850 '$mylink' => $contact['url'],
851 '$mytitle' => t('This is you'),
852 '$myphoto' => $contact['thumb'],
864 foreach($r as $item) {
865 like_puller($a,$item,$alike,'like');
866 like_puller($a,$item,$dlike,'dislike');
869 $like = ((isset($alike[$i1[0]['id']])) ? format_like($alike[$i1[0]['id']],$alike[$i1[0]['id'] . '-l'],'like',$i1[0]['id']) : '');
870 $dislike = ((isset($dlike[$i1[0]['id']])) ? format_like($dlike[$i1[0]['id']],$dlike[$i1[0]['id'] . '-l'],'dislike',$i1[0]['id']) : '');
872 $o .= '<div id="photo-like-div">';
879 foreach($r as $item) {
884 if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
887 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
889 if(can_write_wall($a,$a->data['user']['uid'])) {
891 if($item['last-child']) {
892 $comment = replace_macros($cmnt_tpl,array(
893 '$return_path' => $return_url,
894 '$type' => 'wall-comment',
895 '$id' => $item['item_id'],
896 '$parent' => $item['parent'],
897 '$profile_uid' => $a->data['user']['uid'],
898 '$mylink' => $contact['url'],
899 '$mytitle' => t('This is you'),
900 '$myphoto' => $contact['thumb'],
907 if(local_user() && ($item['contact-uid'] == local_user())
908 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
909 $profile_url = $redirect_url;
910 $sparkle = ' sparkle';
913 $profile_url = $item['url'];
917 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
918 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
919 $profile_link = $profile_url;
923 if(($item['contact-id'] == $_SESSION['visitor_id']) || ($item['uid'] == local_user()))
924 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id']));
927 $o .= replace_macros($template,array(
928 '$id' => $item['item_id'],
929 '$profile_url' => $profile_link,
930 '$name' => $profile_name,
931 '$thumb' => $profile_avatar,
932 '$sparkle' => $sparkle,
933 '$title' => $item['title'],
934 '$body' => bbcode($item['body']),
935 '$ago' => relative_date($item['created']),
936 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
938 '$comment' => $comment
948 // Default - show recent photos with upload link (if applicable)
951 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
952 $sql_extra GROUP BY `resource-id`",
953 intval($a->data['user']['uid']),
954 dbesc( t('Contact Photos'))
957 $a->set_pager_total(count($r));
960 $r = q("SELECT `resource-id`, `id`, `filename`, `album`, max(`scale`) AS `scale` FROM `photo`
961 WHERE `uid` = %d AND `album` != '%s'
962 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
963 intval($a->data['user']['uid']),
964 dbesc( t('Contact Photos')),
965 intval($a->pager['start']),
966 intval($a->pager['itemspage'])
969 $o .= '<h3>' . t('Recent Photos') . '</h3>';
971 if( local_user() && (local_user() == $a->data['user']['uid'])) {
972 $o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
973 . $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
976 $tpl = load_view_file('view/photo_top.tpl');
979 $o .= replace_macros($tpl,array(
981 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname']
982 . '/image/' . $rr['resource-id'],
983 '$phototitle' => t('View Photo'),
984 '$imgsrc' => $a->get_baseurl() . '/photo/'
985 . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
986 '$albumlink' => $a->get_baseurl() . '/photos/'
987 . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
988 '$albumname' => $rr['album'],
989 '$albumalt' => t('View Album'),
990 '$imgalt' => $rr['filename']
994 $o .= '<div id="photo-top-end"></div>';