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 );
56 $r = q("SELECT `contact`.* `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
57 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
61 $contact_record = $r[0];
64 if(($a->argc > 2) && ($a->argv[1] === 'album')) {
65 $album = hex2bin($a->argv[2]);
67 if($album == t('Profile Photos') || $album == t('Contact Photos')) {
68 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
72 $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
77 notice( t('Album not found.') . EOL);
78 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
82 $newalbum = notags(trim($_POST['albumname']));
83 if($newalbum != $album) {
84 q("UPDATE `photo` SET `album` = '%s' WHERE `album` = '%s' AND `uid` = %d",
89 $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
90 goaway($a->get_baseurl() . '/' . $newurl);
94 if($_POST['dropalbum'] == t('Delete Album')) {
97 $r = q("SELECT distinct(`resource-id`) as `rid` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
103 $res[] = "'" . dbesc($rr['rid']) . "'" ;
107 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
108 return; // NOTREACHED
110 $str_res = implode(',', $res);
112 q("DELETE FROM `photo` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
115 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
120 q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
121 dbesc(datetime_convert()),
122 dbesc($rr['parent-uri']),
126 $drop_id = intval($rr['id']);
127 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
128 $proc_debug = get_config('system','proc_debug');
130 // send the notification upstream/downstream as the case may be
133 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" $proc_debug & ",
139 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
140 return; // NOTREACHED
143 if(($a->argc > 1) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
144 $r = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
145 intval(local_user()),
149 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
150 intval(local_user()),
151 dbesc($r[0]['resource-id'])
153 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
154 dbesc($r[0]['resource-id']),
158 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
159 dbesc(datetime_convert()),
160 dbesc(datetime_convert()),
165 $url = $a->get_baseurl();
166 $drop_id = intval($i[0]['id']);
167 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
169 $proc_debug = get_config('system','proc_debug');
171 // send the notification upstream/downstream as the case may be
174 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" $proc_debug & ",
179 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
180 return; // NOTREACHED
183 if(($a->argc > 1) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false))) {
185 $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : '');
186 $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : '');
187 $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0);
188 $resource_id = $a->argv[1];
190 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
194 if((count($p)) && ($p[0]['desc'] !== $desc)) {
195 $r = q("UPDATE `photo` SET `desc` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d",
203 // Create item container
206 $basename = basename($filename);
207 $uri = item_new_uri($a->get_hostname(),local_user());
211 $arr['uid'] = local_user();
213 $arr['parent-uri'] = $uri;
214 $arr['type'] = 'photo';
216 $arr['resource-id'] = $p[0]['resource-id'];
217 $arr['contact-id'] = $contact_record['id'];
218 $arr['owner-name'] = $contact_record['name'];
219 $arr['owner-link'] = $contact_record['url'];
220 $arr['owner-avatar'] = $contact_record['thumb'];
221 $arr['title'] = $title;
222 $arr['allow_cid'] = $p[0]['allow_cid'];
223 $arr['allow_gid'] = $p[0]['allow_gid'];
224 $arr['deny_cid'] = $p[0]['deny_cid'];
225 $arr['deny_gid'] = $p[0]['deny_gid'];
226 $arr['last-child'] = 1;
227 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
228 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]'
231 $item_id = item_store($arr);
236 $r = q("SELECT * FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1",
242 $old_tag = $r[0]['tag'];
243 $old_inform = $r[0]['inform'];
246 if(strlen($rawtags)) {
251 // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
253 $x = substr($rawtags,0,1);
254 if($x !== '@' && $x !== '#')
255 $rawtags = '#' . $rawtags;
257 $tags = get_tags($rawtags);
260 foreach($tags as $tag) {
261 if(strpos($tag,'@') === 0) {
262 $name = substr($tag,1);
263 if((strpos($name,'@')) || (strpos($name,'http://'))) {
265 $links = @lrdd($name);
267 foreach($links as $link) {
268 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page')
269 $profile = $link['@attributes']['href'];
270 if($link['@attributes']['rel'] === 'salmon') {
273 $inform .= 'url:' . str_replace(',','%2c',$link['@attributes']['href']);
280 if(strstr($name,'_')) {
281 $newname = str_replace('_',' ',$name);
282 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
288 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
294 $profile = $r[0]['url'];
297 $inform .= 'cid:' . $r[0]['id'];
301 if(strlen($str_tags))
303 $profile = str_replace(',','%2c',$profile);
304 $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]';
311 if(strlen($newtag) && strlen($str_tags))
313 $newtag .= $str_tags;
315 $newinform = $old_inform;
316 if(strlen($newinform) && strlen($inform))
318 $newinform .= $inform;
320 $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
323 dbesc(datetime_convert()),
324 dbesc(datetime_convert()),
329 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
330 return; // NOTREACHED
336 if(! x($_FILES,'userfile'))
339 if($_POST['partitionCount'])
342 $java_upload = false;
344 $album = notags(trim($_POST['album']));
345 $newalbum = notags(trim($_POST['newalbum']));
347 if(! strlen($album)) {
348 if(strlen($newalbum))
351 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
354 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
358 if((! count($r)) || ($album == t('Profile Photos')))
364 $str_group_allow = perms2str($_POST['group_allow']);
365 $str_contact_allow = perms2str($_POST['contact_allow']);
366 $str_group_deny = perms2str($_POST['group_deny']);
367 $str_contact_deny = perms2str($_POST['contact_deny']);
369 $src = $_FILES['userfile']['tmp_name'];
370 $filename = basename($_FILES['userfile']['name']);
371 $filesize = intval($_FILES['userfile']['size']);
373 $imagedata = @file_get_contents($src);
374 $ph = new Photo($imagedata);
376 if(! $ph->is_valid()) {
377 notice( t('Unable to process image.') . EOL );
384 $width = $ph->getWidth();
385 $height = $ph->getHeight();
389 $photo_hash = photo_new_resource();
391 $r = $ph->store(local_user(), 0, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
394 notice( t('Image upload failed.') . EOL );
398 if($width > 640 || $height > 640) {
399 $ph->scaleImage(640);
400 $ph->store(local_user(), 0, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
404 if($width > 320 || $height > 320) {
405 $ph->scaleImage(320);
406 $ph->store(local_user(), 0, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
410 $basename = basename($filename);
411 $uri = item_new_uri($a->get_hostname(), local_user());
413 // Create item container
418 $arr['uid'] = local_user();
420 $arr['parent-uri'] = $uri;
421 $arr['type'] = 'photo';
423 $arr['resource-id'] = $photo_hash;
424 $arr['contact-id'] = $contact_record['id'];
425 $arr['owner-name'] = $contact_record['name'];
426 $arr['owner-link'] = $contact_record['url'];
427 $arr['owner-avatar'] = $contact_record['thumb'];
428 $arr['title'] = $title;
429 $arr['allow_cid'] = $str_contact_allow;
430 $arr['allow_gid'] = $str_group_allow;
431 $arr['deny_cid'] = $str_contact_deny;
432 $arr['deny_gid'] = $str_group_deny;
433 $arr['last-child'] = 1;
434 $arr['visible'] = $visible;
435 $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $contact_record['nickname'] . '/image/' . $photo_hash . ']'
436 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
439 $item_id = item_store($arr);
442 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
443 return; // NOTREACHED
447 return; // NOTREACHED
453 function photos_content(&$a) {
457 // photos/name/upload
458 // photos/name/album/xxxxx
459 // photos/name/album/xxxxx/edit
460 // photos/name/image/xxxxx
461 // photos/name/image/xxxxx/edit
464 if(! x($a->data,'user')) {
465 notice( t('No photos selected') . EOL );
469 $_SESSION['photo_return'] = $a->cmd;
476 $datatype = $a->argv[2];
477 $datum = $a->argv[3];
479 elseif(($a->argc > 2) && ($a->argv[2] === 'upload'))
480 $datatype = 'upload';
482 $datatype = 'summary';
490 // Setup permissions structures
493 $owner_uid = $a->data['user']['uid'];
498 $remote_contact = false;
501 $contact_id = $_SESSION['visitor_id'];
502 $groups = init_groups_visitor($contact_id);
503 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
509 $remote_contact = true;
513 if(! $remote_contact) {
515 $contact_id = $_SESSION['cid'];
516 $contact = $a->contact;
521 // default permissions - anonymous user
523 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
525 // Profile owner - everything is visible
527 if(local_user() && (local_user() == $owner_uid)) {
530 elseif(remote_user()) {
531 // authenticated visitor - here lie dragons
532 $gs = '<<>>'; // should be impossible to match
534 foreach($groups as $g)
535 $gs .= '|<' . intval($g) . '>';
537 $sql_extra = sprintf(
538 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
539 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
540 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
541 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
543 intval($_SESSION['visitor_id']),
544 intval($_SESSION['visitor_id']),
555 if($datatype === 'upload') {
556 if( ! (local_user() && (local_user() == $a->data['user']['uid']))) {
557 notice( t('Permission denied.'));
560 $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
562 $albumselect .= '<option value="" selected="selected" > </option>';
563 if(count($a->data['albums'])) {
564 foreach($a->data['albums'] as $album) {
565 if(($album['album'] === '') || ($album['album'] == t('Contact Photos')))
567 $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
571 $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
573 $albumselect .= '</select>';
574 $tpl = load_view_file('view/photos_upload.tpl');
575 $o .= replace_macros($tpl,array(
576 '$pagename' => t('Upload Photos'),
577 '$sessid' => session_id(),
578 '$newalbum' => t('New album name: '),
579 '$existalbumtext' => t('or existing album name: '),
580 '$filestext' => t('Select files to upload: '),
581 '$albumselect' => $albumselect,
582 '$permissions' => t('Permissions'),
583 '$aclselect' => populate_acl($a->user, $celeb),
584 '$archive' => $a->get_baseurl() . '/jumploader_z.jar',
585 '$nojava' => t('Use the following controls only if the Java uploader [above] fails to launch.'),
586 '$uploadurl' => $a->get_baseurl() . '/photos',
587 '$submit' => t('Submit')
594 if($datatype === 'album') {
596 $album = hex2bin($datum);
598 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
599 $sql_extra GROUP BY `resource-id`",
600 intval($a->data['user']['uid']),
604 $a->set_pager_total(count($r));
607 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
608 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
609 intval($a->data['user']['uid']),
611 intval($a->pager['start']),
612 intval($a->pager['itemspage'])
615 $o .= '<h3>' . $album . '</h3>';
617 if($cmd === 'edit') {
618 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
619 if(local_user() && (local_user() == $a->data['user']['uid'])) {
620 $edit_tpl = load_view_file('view/album_edit.tpl');
621 $o .= replace_macros($edit_tpl,array(
622 '$nametext' => t('New album name: '),
624 '$hexalbum' => bin2hex($album),
625 '$submit' => t('Submit'),
626 '$dropsubmit' => t('Delete Album')
632 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
633 if(local_user() && (local_user() == $a->data['user']['uid'])) {
634 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
635 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
636 . t('Edit Album') . '</a></div>';
640 $tpl = load_view_file('view/photo_album.tpl');
643 $o .= replace_macros($tpl,array(
645 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
646 '$phototitle' => t('View Photo'),
647 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
648 '$imgalt' => $rr['filename']
652 $o .= '<div id="photo-album-end"></div>';
658 if($datatype === 'image') {
660 require_once('security.php');
661 require_once('bbcode.php');
663 // fetch image, item containing image, then comments
665 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
666 $sql_extra ORDER BY `scale` ASC ",
667 intval($a->data['user']['uid']),
672 notice( t('Photo not available') . EOL );
677 $hires = $lores = $ph[0];
679 if($ph[1]['scale'] == 2) {
680 // original is 640 or less, we can display it directly
681 $hires = $lores = $ph[0];
690 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']) . '">' . $ph[0]['album'] . '</a></h3>';
692 if(local_user() && ($ph[0]['uid'] == local_user())) {
693 $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>';
697 $o .= '<a href="' . $a->get_baseurl() . '/photo/'
698 . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg" title="'
699 . t('View Full Size') . '" ><img src="' . $a->get_baseurl() . '/photo/'
700 . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg' . '" /></a>';
703 // Do we have an item for this photo?
705 $i1 = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
710 $r = q("SELECT COUNT(*) AS `total`
711 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
712 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
713 AND NOT `item`.`type` IN ( 'remote', 'net-comment')
714 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
716 dbesc($i1[0]['uri']),
722 $a->set_pager_total($r[0]['total']);
725 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
726 `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
727 `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
728 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
729 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
730 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
731 AND NOT `item`.`type` IN ( 'remote', 'net-comment')
732 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
734 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
735 dbesc($i1[0]['uri']),
736 dbesc($i1[0]['uri']),
737 intval($a->pager['start']),
738 intval($a->pager['itemspage'])
743 $o .= '<div id="photo-caption" >' . $ph[0]['desc'] . '</div>';
745 if(count($i1) && strlen($i1[0]['tag'])) {
746 $arr = explode(',',$i1[0]['tag']);
747 // parse tags and add links
748 $o .= '<div id="in-this-photo-text">' . t('Tags: ') . '</div>';
749 $o .= '<div id="in-this-photo">';
751 foreach($arr as $t) {
754 $tag_str .= bbcode($t);
756 $o .= $tag_str . '</div>';
759 if($cmd === 'edit') {
760 $edit_tpl = load_view_file('view/photo_edit.tpl');
761 $o .= replace_macros($edit_tpl, array(
762 '$id' => $ph[0]['id'],
763 '$resource_id' => $ph[0]['resource-id'],
764 '$capt_label' => t('Caption'),
765 '$caption' => $ph[0]['desc'],
766 '$tag_label' => t('Add a Tag'),
767 '$tags' => $i1[0]['tag'],
768 '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
769 '$item_id' => ((count($i1)) ? $i1[0]['id'] : 0),
770 '$submit' => t('Submit'),
771 '$delete' => t('Delete Photo')
778 $cmnt_tpl = load_view_file('view/comment_item.tpl');
779 $tpl = load_view_file('view/photo_item.tpl');
780 $return_url = $a->cmd;
782 if(can_write_wall($a,$a->data['user']['uid'])) {
783 if($i1[0]['last-child']) {
784 $o .= replace_macros($cmnt_tpl,array(
785 '$return_path' => $return_url,
786 '$type' => 'wall-comment',
787 '$id' => $i1[0]['id'],
788 '$parent' => $i1[0]['id'],
789 '$profile_uid' => $a->data['user']['uid'],
790 '$mylink' => $contact['url'],
791 '$mytitle' => t('This is you'),
792 '$myphoto' => $contact['thumb'],
801 foreach($r as $item) {
805 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
807 if(can_write_wall($a,$a->data['user']['uid'])) {
808 if($item['last-child']) {
809 $comment = replace_macros($cmnt_tpl,array(
810 '$return_path' => $return_url,
811 '$type' => 'wall-comment',
812 '$id' => $item['item_id'],
813 '$parent' => $item['parent'],
814 '$profile_uid' => $a->data['user']['uid'],
815 '$mylink' => $contact['url'],
816 '$mytitle' => t('This is you'),
817 '$myphoto' => $contact['thumb'],
824 if(local_user() && ($item['contact-uid'] == local_user())
825 && ($item['network'] == 'dfrn') && (! $item['self'] )) {
826 $profile_url = $redirect_url;
827 $sparkle = ' sparkle';
830 $profile_url = $item['url'];
834 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
835 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
836 $profile_link = $profile_url;
840 if(($item['contact-id'] == $_SESSION['visitor_id']) || ($item['uid'] == local_user()))
841 $drop = replace_macros(load_view_file('view/wall_item_drop.tpl'), array('$id' => $item['id']));
844 $o .= replace_macros($template,array(
845 '$id' => $item['item_id'],
846 '$profile_url' => $profile_link,
847 '$name' => $profile_name,
848 '$thumb' => $profile_avatar,
849 '$sparkle' => $sparkle,
850 '$title' => $item['title'],
851 '$body' => bbcode($item['body']),
852 '$ago' => relative_date($item['created']),
853 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
855 '$comment' => $comment
865 // Default - show recent photos with upload link (if applicable)
867 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
868 $sql_extra GROUP BY `resource-id`",
869 intval($a->data['user']['uid']),
870 dbesc( t('Contact Photos'))
873 $a->set_pager_total(count($r));
876 $r = q("SELECT `resource-id`, `album`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
877 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
878 intval($a->data['user']['uid']),
879 dbesc( t('Contact Photos')),
880 intval($a->pager['start']),
881 intval($a->pager['itemspage'])
884 $o .= '<h3>' . t('Recent Photos') . '</h3>';
886 if( local_user() && (local_user() == $a->data['user']['uid'])) {
887 $o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
888 . $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
891 $tpl = load_view_file('view/photo_top.tpl');
894 $o .= replace_macros($tpl,array(
896 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname']
897 . '/image/' . $rr['resource-id'],
898 '$phototitle' => t('View Photo'),
899 '$imgsrc' => $a->get_baseurl() . '/photo/'
900 . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
901 '$albumlink' => $a->get_baseurl . '/photos/'
902 . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
903 '$albumname' => $rr['album'],
904 '$albumalt' => t('View Album'),
905 '$imgalt' => $rr['filename']
909 $o .= '<div id="photo-top-end"></div>';