+ if(count($r))
+ $a->set_pager_total($r[0]['total']);
+
+
+ $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
+ `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
+ `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
+ `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
+ FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
+ WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
+ AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
+ AND `item`.`uid` = %d
+ $sql_extra
+ ORDER BY `parent` DESC, `id` ASC LIMIT %d ,%d ",
+ dbesc($link_item['uri']),
+ dbesc($link_item['uri']),
+ intval($link_item['uid']),
+ intval($a->pager['start']),
+ intval($a->pager['itemspage'])
+
+ );
+
+ if((local_user()) && (local_user() == $link_item['uid'])) {
+ q("UPDATE `item` SET `unseen` = 0 WHERE `parent` = %d and `uid` = %d",
+ intval($link_item['parent']),
+ intval(local_user())
+ );
+ }
+ }
+
+ $tags=Null;
+
+ if(count($linked_items) && strlen($link_item['tag'])) {
+ $arr = explode(',',$link_item['tag']);
+ // parse tags and add links
+ $tag_str = '';
+ foreach($arr as $t) {
+ if(strlen($tag_str))
+ $tag_str .= ', ';
+ $tag_str .= bbcode($t);
+ }
+ $tags = array(t('Tags: '), $tag_str);
+ if($cmd === 'edit') {
+ $tags[] = $a->get_baseurl() . '/tagrm/' . $link_item['id'];
+ $tags[] = t('[Remove any tag]');
+ }
+ }
+
+
+ $edit = Null;
+ if(($cmd === 'edit') && ($can_post)) {
+ $edit_tpl = get_markup_template('photo_edit.tpl');
+ $edit = replace_macros($edit_tpl, array(
+ '$id' => $ph[0]['id'],
+ '$album' => $ph[0]['album'],
+ '$newalbum' => t('New album name'),
+ '$nickname' => $a->data['user']['nickname'],
+ '$resource_id' => $ph[0]['resource-id'],
+ '$capt_label' => t('Caption'),
+ '$caption' => $ph[0]['desc'],
+ '$tag_label' => t('Add a Tag'),
+ '$tags' => $link_item['tag'],
+ '$permissions' => t('Permissions'),
+ '$aclselect' => populate_acl($ph[0]),
+ '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
+ '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
+ '$submit' => t('Submit'),
+ '$delete' => t('Delete Photo')
+ ));
+ }
+
+ if(count($linked_items)) {
+
+ $cmnt_tpl = get_markup_template('comment_item.tpl');
+ $tpl = get_markup_template('photo_item.tpl');
+ $return_url = $a->cmd;
+
+ $like_tpl = get_markup_template('like_noshare.tpl');
+
+ $likebuttons = '';
+
+ if($can_post || can_write_wall($a,$owner_uid)) {
+ $likebuttons = replace_macros($like_tpl,array(
+ '$id' => $link_item['id'],
+ '$likethis' => t("I like this \x28toggle\x29"),
+ '$nolike' => t("I don't like this \x28toggle\x29"),
+ '$share' => t('Share'),
+ '$wait' => t('Please wait')
+ ));
+ }
+
+ $comments = '';
+ if(! count($r)) {
+ if($can_post || can_write_wall($a,$owner_uid)) {
+ if($link_item['last-child']) {
+ $comments .= replace_macros($cmnt_tpl,array(
+ '$return_path' => '',
+ '$jsreload' => $return_url,
+ '$type' => 'wall-comment',
+ '$id' => $link_item['id'],
+ '$parent' => $link_item['id'],
+ '$profile_uid' => $owner_uid,
+ '$mylink' => $contact['url'],
+ '$mytitle' => t('This is you'),
+ '$myphoto' => $contact['thumb'],
+ '$comment' => t('Comment'),
+ '$submit' => t('Submit'),
+ '$ww' => ''
+ ));
+ }
+ }
+ }
+
+ $alike = array();
+ $dlike = array();
+
+ $like = '';
+ $dislike = '';
+
+ // display comments
+ if(count($r)) {
+
+ foreach($r as $item) {
+ like_puller($a,$item,$alike,'like');
+ like_puller($a,$item,$dlike,'dislike');
+ }
+
+ $like = ((isset($alike[$link_item['id']])) ? format_like($alike[$link_item['id']],$alike[$link_item['id'] . '-l'],'like',$link_item['id']) : '');
+ $dislike = ((isset($dlike[$link_item['id']])) ? format_like($dlike[$link_item['id']],$dlike[$link_item['id'] . '-l'],'dislike',$link_item['id']) : '');
+
+
+
+ if($can_post || can_write_wall($a,$owner_uid)) {
+ if($link_item['last-child']) {
+ $comments .= replace_macros($cmnt_tpl,array(
+ '$return_path' => '',
+ '$jsreload' => $return_url,
+ '$type' => 'wall-comment',
+ '$id' => $link_item['id'],
+ '$parent' => $link_item['id'],
+ '$profile_uid' => $owner_uid,
+ '$mylink' => $contact['url'],
+ '$mytitle' => t('This is you'),
+ '$myphoto' => $contact['thumb'],
+ '$comment' => t('Comment'),
+ '$submit' => t('Submit'),
+ '$ww' => ''
+ ));
+ }
+ }
+
+
+ foreach($r as $item) {
+ $comment = '';
+ $template = $tpl;
+ $sparkle = '';
+
+ if(((activity_match($item['verb'],ACTIVITY_LIKE)) || (activity_match($item['verb'],ACTIVITY_DISLIKE))) && ($item['id'] != $item['parent']))
+ continue;
+
+ $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
+
+ if($can_post || can_write_wall($a,$owner_uid)) {
+
+ if($item['last-child']) {
+ $comments .= replace_macros($cmnt_tpl,array(
+ '$return_path' => '',
+ '$jsreload' => $return_url,
+ '$type' => 'wall-comment',
+ '$id' => $item['item_id'],
+ '$parent' => $item['parent'],
+ '$profile_uid' => $owner_uid,
+ '$mylink' => $contact['url'],
+ '$mytitle' => t('This is you'),
+ '$myphoto' => $contact['thumb'],
+ '$comment' => t('Comment'),
+ '$submit' => t('Submit'),
+ '$ww' => ''
+ ));
+ }
+ }
+
+
+ if(local_user() && ($item['contact-uid'] == local_user())
+ && ($item['network'] == 'dfrn') && (! $item['self'] )) {
+ $profile_url = $redirect_url;
+ $sparkle = ' sparkle';
+ }
+ else {
+ $profile_url = $item['url'];
+ $sparkle = '';
+ }
+
+ $diff_author = (($item['url'] !== $item['author-link']) ? true : false);
+
+ $profile_name = (((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']);
+ $profile_avatar = (((strlen($item['author-avatar'])) && $diff_author) ? $item['author-avatar'] : $item['thumb']);
+
+ $profile_link = $profile_url;
+
+ $drop = '';
+
+ if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
+ $drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));
+
+
+ $comments .= replace_macros($template,array(
+ '$id' => $item['item_id'],
+ '$profile_url' => $profile_link,
+ '$name' => $profile_name,
+ '$thumb' => $profile_avatar,
+ '$sparkle' => $sparkle,
+ '$title' => $item['title'],
+ '$body' => bbcode($item['body']),
+ '$ago' => relative_date($item['created']),
+ '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
+ '$drop' => $drop,
+ '$comment' => $comment
+ ));
+ }
+ }
+
+ $paginate = paginate($a);
+ }
+
+ $photo_tpl = get_markup_template('photo_view.tpl');
+ $o .= replace_macros($photo_tpl, array(
+ '$id' => $ph[0]['id'],
+ '$album' => array($album_link,$ph[0]['album']),
+ '$tools' => $tools,
+ '$lock' => $lock,
+ '$photo' => $photo,
+ '$prevlink' => $prevlink,
+ '$nextlink' => $nextlink,
+ '$desc' => $ph[0]['desc'],
+ '$tags' => $tags,
+ '$edit' => $edit,
+ '$likebuttons' => $likebuttons,
+ '$like' => $like,
+ '$dislike' => $dislike,
+ '$comments' => $comments,
+ '$paginate' => $paginate,
+ ));
+