3 require_once('Photo.php');
4 require_once('view/acl_selectors.php');
6 function photos_init(&$a) {
10 $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' LIMIT 1",
17 $a->data['user'] = $r[0];
19 $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d",
20 intval($a->data['user']['uid'])
24 $a->data['albums'] = $albums;
26 $o .= '<h4><a href="' . $a->get_baseurl() . '/profile/' . $a->data['user']['nickname'] . '">' . $a->data['user']['username'] . '</a></h4>';
27 $o .= '<h4>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h4>';
30 foreach($albums as $album) {
31 if((! strlen($album['album'])) || ($album['album'] == t('Contact Photos')))
33 $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" />' . $album['album'] . '</a></li>';
37 $a->page['aside'] .= $o;
46 function photos_post(&$a) {
50 notice( t('Permission denied.') . EOL );
56 $r = q("SELECT * FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
57 WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
58 intval($_SESSION['uid'])
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",
74 intval($_SESSION['uid'])
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",
87 intval($_SESSION['uid'])
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'",
98 intval($_SESSION['uid']),
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",
113 intval($_SESSION['uid'])
115 $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
116 intval($_SESSION['uid'])
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']),
123 intval($_SESSION['uid'])
126 $drop_id = intval($rr['id']);
127 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
129 // send the notification upstream/downstream as the case may be
132 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" & ",
138 goaway($a->get_baseurl() . '/photos/' . $a->data['user']['nickname']);
139 return; // NOTREACHED
142 if(($a->argc > 1) && (x($_POST,'delete')) && ($_POST['delete'] == t('Delete Photo'))) {
143 $r = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' LIMIT 1",
144 intval($_SESSION['uid']),
148 q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
149 intval($_SESSION['uid']),
150 dbesc($r[0]['resource-id'])
152 $i = q("SELECT * FROM `item` WHERE `resource-id` = '%s' AND `uid` = %d LIMIT 1",
153 dbesc($r[0]['resource-id']),
154 intval($_SESSION['uid'])
157 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
158 dbesc(datetime_convert()),
159 dbesc(datetime_convert()),
161 intval($_SESSION['uid'])
164 $url = $a->get_baseurl();
165 $drop_id = intval($i[0]['id']);
166 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
168 // send the notification upstream/downstream as the case may be
171 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" & ",
176 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
177 return; // NOTREACHED
182 if(($a->argc > 1) && (x($_POST,'desc') !== false)) {
183 $desc = notags(trim($_POST['desc']));
184 $tags = notags(trim($_POST['tags']));
185 $item_id = intval($_POST['item_id']);
186 $resource_id = $a->argv[1];
188 $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC",
190 intval($_SESSION['uid'])
193 $r = q("UPDATE `photo` SET `desc` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d",
196 intval($_SESSION['uid'])
202 $basename = basename($filename);
204 // Create item container
206 $body = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
207 . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]'
212 $item_hash = random_string();
214 $uri = "urn:X-dfrn:" . $a->get_hostname() . ':' . $_SESSION['uid'] . ':' . $item_hash;
216 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
220 } while($dups == true);
223 $r = q("INSERT INTO `item` (`uid`, `type`, `resource-id`, `contact-id`,
224 `owner-name`,`owner-link`,`owner-avatar`, `created`,
225 `edited`, `changed`, `uri`, `parent-uri`, `title`, `body`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`)
226 VALUES( %d, '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
227 intval($_SESSION['uid']),
229 dbesc($p[0]['resource-id']),
230 intval($contact_record['id']),
231 dbesc($contact_record['name']),
232 dbesc($contact_record['url']),
233 dbesc($contact_record['thumb']),
234 dbesc(datetime_convert()),
235 dbesc(datetime_convert()),
236 dbesc(datetime_convert()),
241 dbesc($p[0]['allow_cid']),
242 dbesc($p[0]['allow_gid']),
243 dbesc($p[0]['deny_cid']),
244 dbesc($p[0]['deny_gid'])
249 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
253 $item_id = $r[0]['id'];
254 q("UPDATE `item` SET `parent` = %d, `last-child` = 1 WHERE `id` = %d LIMIT 1",
261 $r = q("UPDATE `item` SET `tag` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1",
263 dbesc(datetime_convert()),
264 dbesc(datetime_convert()),
266 intval($_SESSION['uid'])
269 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
270 return; // NOTREACHED
276 if(! x($_FILES,'userfile'))
279 if($_POST['partitionCount'])
282 $java_upload = false;
284 $album = notags(trim($_POST['album']));
285 $newalbum = notags(trim($_POST['newalbum']));
287 if(! strlen($album)) {
288 if(strlen($newalbum))
291 $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
294 $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
296 intval($_SESSION['uid'])
298 if((! count($r)) || ($album == t('Profile Photos')))
303 $str_group_allow = '';
304 $group_allow = $_POST['group_allow'];
305 if(is_array($group_allow)) {
306 array_walk($group_allow,'sanitise_acl');
307 $str_group_allow = implode('',$group_allow);
310 $str_contact_allow = '';
311 $contact_allow = $_POST['contact_allow'];
312 if(is_array($contact_allow)) {
313 array_walk($contact_allow,'sanitise_acl');
314 $str_contact_allow = implode('',$contact_allow);
317 $str_group_deny = '';
318 $group_deny = $_POST['group_deny'];
319 if(is_array($group_deny)) {
320 array_walk($group_deny,'sanitise_acl');
321 $str_group_deny = implode('',$group_deny);
324 $str_contact_deny = '';
325 $contact_deny = $_POST['contact_deny'];
326 if(is_array($contact_deny)) {
327 array_walk($contact_deny,'sanitise_acl');
328 $str_contact_deny = implode('',$contact_deny);
332 $src = $_FILES['userfile']['tmp_name'];
333 $filename = basename($_FILES['userfile']['name']);
334 $filesize = intval($_FILES['userfile']['size']);
336 $imagedata = @file_get_contents($src);
337 $ph = new Photo($imagedata);
339 if(! ($image = $ph->getImage())) {
340 notice( t('Unable to process image.') . EOL );
347 $width = $ph->getWidth();
348 $height = $ph->getHeight();
352 $photo_hash = hash('md5',uniqid(mt_rand(),true));
354 $r = $ph->store($_SESSION['uid'], 0, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
357 notice( t('Image upload failed.') . EOL );
361 if($width > 640 || $height > 640) {
362 $ph->scaleImage(640);
363 $ph->store($_SESSION['uid'], 0, $photo_hash, $filename, $album, 1, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
367 if($width > 320 || $height > 320) {
368 $ph->scaleImage(320);
369 $ph->store($_SESSION['uid'], 0, $photo_hash, $filename, $album, 2, 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
373 $basename = basename($filename);
375 // Create item container
377 $body = '[url=' . $a->get_baseurl() . '/photos/' . $contact_record['nickname'] . '/image/' . $photo_hash . ']'
378 . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]'
383 $item_hash = random_string();
385 $uri = "urn:X-dfrn:" . $a->get_hostname() . ':' . $_SESSION['uid'] . ':' . $item_hash;
387 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
391 } while($dups == true);
394 $r = q("INSERT INTO `item` (`uid`, `type`, `resource-id`, `contact-id`,`owner-name`,`owner-link`,`owner-avatar`, `created`,
395 `edited`, `changed`, `uri`, `parent-uri`, `title`, `body`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `visible`)
396 VALUES( %d, '%s', '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d )",
397 intval($_SESSION['uid']),
400 intval($contact_record['id']),
401 dbesc($contact_record['name']),
402 dbesc($contact_record['url']),
403 dbesc($contact_record['thumb']),
404 dbesc(datetime_convert()),
405 dbesc(datetime_convert()),
406 dbesc(datetime_convert()),
411 dbesc($str_contact_allow),
412 dbesc($str_group_allow),
413 dbesc($str_contact_deny),
414 dbesc($str_group_deny),
419 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
423 q("UPDATE `item` SET `parent` = %d, `last-child` = 1 WHERE `id` = %d LIMIT 1",
431 goaway($a->get_baseurl() . '/' . $_SESSION['photo_return']);
432 return; // NOTREACHED
436 return; // NOTREACHED
442 function photos_content(&$a) {
446 // photos/name/upload
447 // photos/name/album/xxxxx
448 // photos/name/album/xxxxx/edit
449 // photos/name/image/xxxxx
450 // photos/name/image/xxxxx/edit
453 if(! x($a->data,'user')) {
454 notice( t('No photos selected') . EOL );
458 $_SESSION['photo_return'] = $a->cmd;
465 $datatype = $a->argv[2];
466 $datum = $a->argv[3];
468 elseif(($a->argc > 2) && ($a->argv[2] == 'upload'))
469 $datatype = 'upload';
471 $datatype = 'summary';
479 // Setup permissions structures
482 $owner_uid = $a->data['user']['uid'];
485 $contact_id = $_SESSION['visitor_id'];
486 $groups = init_groups_visitor($contact_id);
489 // default permissions - anonymous user
491 $sql_extra = " AND `allow_cid` = '' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = '' ";
493 // Profile owner - everything is visible
495 if(local_user() && ($_SESSION['uid'] == $owner_uid)) {
498 elseif(remote_user()) {
499 // authenticated visitor - here lie dragons
500 $gs = '<<>>'; // should be impossible to match
502 foreach($groups as $g)
503 $gs .= '|<' . intval($g) . '>';
505 $sql_extra = sprintf(
506 " AND ( `allow_cid` = '' OR `allow_cid` REGEXP '<%d>' )
507 AND ( `deny_cid` = '' OR NOT `deny_cid` REGEXP '<%d>' )
508 AND ( `allow_gid` = '' OR `allow_gid` REGEXP '%s' )
509 AND ( `deny_gid` = '' OR NOT `deny_gid` REGEXP '%s') ",
511 intval($_SESSION['visitor_id']),
512 intval($_SESSION['visitor_id']),
523 if($datatype == 'upload') {
524 if( ! (local_user() && ($_SESSION['uid'] == $a->data['user']['uid']))) {
525 notice( t('Permission denied.'));
528 $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
530 $albumselect .= '<option value="" selected="selected" > </option>';
531 if(count($a->data['albums'])) {
532 foreach($a->data['albums'] as $album) {
533 if(($album['album'] == '') || ($album['album'] == t('Contact Photos')))
535 $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
538 $albumselect .= '</select>';
539 $tpl = file_get_contents('view/photos_upload.tpl');
540 $o .= replace_macros($tpl,array(
541 '$pagename' => t('Upload Photos'),
542 '$sessid' => session_id(),
543 '$newalbum' => t('New album name: '),
544 '$existalbumtext' => t('or existing album name: '),
545 '$filestext' => t('Select files to upload: '),
546 '$albumselect' => $albumselect,
547 '$permissions' => t('Permissions'),
548 '$aclselect' => populate_acl($a->user),
549 '$archive' => $a->get_baseurl() . '/jumploader_z.jar',
550 '$nojava' => t('Use the following controls only if the Java uploader (above) fails to launch.'),
551 '$uploadurl' => $a->get_baseurl() . '/photos',
552 '$submit' => t('Submit')
559 if($datatype == 'album') {
561 $album = hex2bin($datum);
563 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
564 $sql_extra GROUP BY `resource-id`",
565 intval($a->data['user']['uid']),
569 $a->set_pager_total(count($r));
572 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
573 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
574 intval($a->data['user']['uid']),
576 intval($a->pager['start']),
577 intval($a->pager['itemspage'])
580 $o .= '<h3>' . $album . '</h3>';
583 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
584 if(local_user() && ($_SESSION['uid'] == $a->data['user']['uid'])) {
585 $edit_tpl = file_get_contents('view/album_edit.tpl');
586 $o .= replace_macros($edit_tpl,array(
587 '$nametext' => t('New album name: '),
589 '$hexalbum' => bin2hex($album),
590 '$submit' => t('Submit'),
591 '$dropsubmit' => t('Delete Album')
597 if(($album != t('Profile Photos')) && ($album != t('Contact Photos'))) {
598 if(local_user() && ($_SESSION['uid'] == $a->data['user']['uid'])) {
599 $o .= '<div id="album-edit-link"><a href="'. $a->get_baseurl() . '/photos/'
600 . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit' . '">'
601 . t('Edit Album') . '</a></div>';
605 $tpl = file_get_contents('view/photo_album.tpl');
608 $o .= replace_macros($tpl,array(
610 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
611 '$phototitle' => t('View Photo'),
612 '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
613 '$imgalt' => $rr['filename']
617 $o .= '<div id="photo-album-end"></div>';
623 if($datatype == 'image') {
625 require_once('security.php');
626 require_once('bbcode.php');
628 // fetch image, item containing image, then comments
630 $ph = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
631 $sql_extra ORDER BY `scale` ASC ",
632 intval($a->data['user']['uid']),
637 notice( t('Photo not available') . EOL );
642 $hires = $lores = $ph[0];
644 if($ph[1]['scale'] == 2) {
645 // original is 640 or less, we can display it directly
646 $hires = $lores = $ph[0];
655 $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']) . '">' . $ph[0]['album'] . '</a></h3>';
657 if(local_user() && ($ph[0]['uid'] == $_SESSION['uid'])) {
658 $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>';
662 $o .= '<a href="' . $a->get_baseurl() . '/photo/'
663 . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg" title="'
664 . t('View Full Size') . '" ><img src="' . $a->get_baseurl() . '/photo/'
665 . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg' . '" /></a>';
668 // Do we have an item for this photo?
670 $i1 = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
675 $r = q("SELECT COUNT(*) AS `total`
676 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
677 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
678 AND NOT `item`.`type` IN ( 'remote', 'net-comment')
679 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
681 dbesc($i1[0]['uri']),
687 $a->set_pager_total($r[0]['total']);
690 $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
691 `contact`.`name`, `contact`.`photo`, `contact`.`url`,
692 `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
693 `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
694 FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
695 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
696 AND NOT `item`.`type` IN ( 'remote', 'net-comment')
697 AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
699 ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
700 dbesc($i1[0]['uri']),
701 dbesc($i1[0]['uri']),
702 intval($a->pager['start']),
703 intval($a->pager['itemspage'])
708 $o .= '<div id="photo-caption" >' . $ph[0]['desc'] . '</div>';
710 if(count($i1) && strlen($i1[0]['tag'])) {
711 // parse tags and add links
712 $o .= '<div id="in-this-photo-text">' . t('In this photo: ') . '</div>';
713 $o .= '<div id="in-this-photo">' . $i1[0]['tag'] . '</div>';
717 $edit_tpl = file_get_contents('view/photo_edit.tpl');
718 $o .= replace_macros($edit_tpl, array(
719 '$id' => $ph[0]['id'],
720 '$resource_id' => $ph[0]['resource-id'],
721 '$capt_label' => t('Caption'),
722 '$caption' => $ph[0]['desc'],
723 '$tag_label' => t('Tags'),
724 '$tags' => $i1[0]['tag'],
725 '$item_id' => ((count($i1)) ? $i1[0]['id'] : 0),
726 '$submit' => t('Submit'),
727 '$delete' => t('Delete Photo')
733 // pull out how many people like the photo
735 $cmnt_tpl = file_get_contents('view/comment_item.tpl');
736 $tpl = file_get_contents('view/photo_item.tpl');
737 $return_url = $a->cmd;
739 if(can_write_wall($a,$a->data['user']['uid'])) {
740 if($i1[0]['last-child']) {
741 $o .= replace_macros($cmnt_tpl,array(
742 '$return_path' => $return_url,
743 '$type' => 'wall-comment',
744 '$id' => $i1[0]['id'],
745 '$parent' => $i1[0]['id'],
746 '$profile_uid' => $a->data['user']['uid'],
755 foreach($r as $item) {
759 $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
761 if(can_write_wall($a,$a->data['user']['uid'])) {
762 if($item['last-child']) {
763 $comment = replace_macros($cmnt_tpl,array(
764 '$return_path' => $return_url,
765 '$type' => 'wall-comment',
766 '$id' => $item['item_id'],
767 '$parent' => $item['parent'],
768 '$profile_uid' => $a->data['user']['uid'],
774 $profile_url = $item['url'];
776 if(local_user() && ($item['contact-uid'] == $_SESSION['uid'])
777 && ($item['rel'] == DIRECTION_IN || $item['rel'] == DIRECTION_BOTH) && (! $item['self'] ))
778 $profile_url = $redirect_url;
780 $profile_name = ((strlen($item['author-name'])) ? $item['author-name'] : $item['name']);
781 $profile_avatar = ((strlen($item['author-avatar'])) ? $item['author-avatar'] : $item['thumb']);
782 $profile_link = $profile_url;
786 if(($item['contact-id'] == $_SESSION['visitor_id']) || ($item['uid'] == $_SESSION['uid']))
787 $drop = replace_macros(file_get_contents('view/wall_item_drop.tpl'), array('$id' => $item['id']));
790 $o .= replace_macros($template,array(
791 '$id' => $item['item_id'],
792 '$profile_url' => $profile_link,
793 '$name' => $profile_name,
794 '$thumb' => $profile_avatar,
795 '$title' => $item['title'],
796 '$body' => bbcode($item['body']),
797 '$ago' => relative_date($item['created']),
798 '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
800 '$comment' => $comment
810 // Default - show recent photos with upload link (if applicable)
812 $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
813 $sql_extra GROUP BY `resource-id`",
814 intval($a->data['user']['uid']),
815 dbesc( t('Contact Photos'))
818 $a->set_pager_total(count($r));
821 $r = q("SELECT `resource-id`, `album`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s'
822 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
823 intval($a->data['user']['uid']),
824 dbesc( t('Contact Photos')),
825 intval($a->pager['start']),
826 intval($a->pager['itemspage'])
829 $o .= '<h3>' . t('Recent Photos') . '</h3>';
831 if( local_user() && ($_SESSION['uid'] == $a->data['user']['uid'])) {
832 $o .= '<div id="photo-top-links"><a id="photo-top-upload-link" href="'. $a->get_baseurl() . '/photos/'
833 . $a->data['user']['nickname'] . '/upload' . '">' . t('Upload New Photos') . '</a></div>';
836 $tpl = file_get_contents('view/photo_top.tpl');
839 $o .= replace_macros($tpl,array(
841 '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname']
842 . '/image/' . $rr['resource-id'],
843 '$phototitle' => t('View Photo'),
844 '$imgsrc' => $a->get_baseurl() . '/photo/'
845 . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg',
846 '$albumlink' => $a->get_baseurl . '/photos/'
847 . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
848 '$albumname' => $rr['album'],
849 '$albumalt' => t('View Album'),
850 '$imgalt' => $rr['filename']
854 $o .= '<div id="photo-top-end"></div>';