From dd25c7db7ed29d21045ec300d61ec31739ca887a Mon Sep 17 00:00:00 2001 From: Fabrixxm Date: Thu, 20 Sep 2012 09:46:49 +0200 Subject: [PATCH] more $item data - add $item.categories and $item.folders to object/Item.php - add $item.hastags and $item.mentions to object/Item.php - add $item.total_comments_num and $item.total_comments_text to object/Item.php (those are set for top_level item also with no comments) - move get_cats_and_terms() to include/text.php --- include/conversation.php | 63 -------------------------------------- include/text.php | 66 ++++++++++++++++++++++++++++++++++++++++ object/Item.php | 25 +++++++++++++-- 3 files changed, 89 insertions(+), 65 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index 664f81f3bc..fc4b85e794 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -351,69 +351,6 @@ function visible_activity($item) { } -/** - * returns - * [ - * //categories [ - * { - * 'name': 'category name', - * 'removeurl': 'url to remove this category', - * 'first': 'is the first in this array? true/false', - * 'last': 'is the last in this array? true/false', - * } , - * .... - * ], - * // folders [ - * 'name': 'folder name', - * 'removeurl': 'url to remove this folder', - * 'first': 'is the first in this array? true/false', - * 'last': 'is the last in this array? true/false', - * } , - * .... - * ] - * ] - */ -function get_cats_and_terms($item) { - $categories = array(); - $folders = array(); - - $matches = false; $first = true; - $cnt = preg_match_all('/<(.*?)>/',$item['file'],$matches,PREG_SET_ORDER); - if($cnt) { - foreach($matches as $mtch) { - $categories[] = array( - 'name' => xmlify(file_tag_decode($mtch[1])), - 'removeurl' => $a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&cat=' . xmlify(file_tag_decode($mtch[1])), - 'first' => $first, - 'last' => false - ); - $first = false; - } - } - if (count($categories)) $categories[count($categories)-1]['last'] = true; - - - - $matches = false; $first = true; - $cnt = preg_match_all('/\[(.*?)\]/',$item['file'],$matches,PREG_SET_ORDER); - if($cnt) { - foreach($matches as $mtch) { - $folders[] = array( - 'name' => xmlify(file_tag_decode($mtch[1])), - 'removeurl' => $a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&term=' . xmlify(file_tag_decode($mtch[1])), - 'first' => $first, - 'last' => false - ); - $first = false; - } - } - - if (count($folders)) $folders[count($folders)-1]['last'] = true; - - return array($categories, $folders); -} - - /** * Recursively prepare a thread for HTML */ diff --git a/include/text.php b/include/text.php index 878ce80e9b..9b55078cbe 100644 --- a/include/text.php +++ b/include/text.php @@ -1071,6 +1071,72 @@ function prepare_text($text) { }} +/** + * returns + * [ + * //categories [ + * { + * 'name': 'category name', + * 'removeurl': 'url to remove this category', + * 'first': 'is the first in this array? true/false', + * 'last': 'is the last in this array? true/false', + * } , + * .... + * ], + * // folders [ + * 'name': 'folder name', + * 'removeurl': 'url to remove this folder', + * 'first': 'is the first in this array? true/false', + * 'last': 'is the last in this array? true/false', + * } , + * .... + * ] + * ] + */ +function get_cats_and_terms($item) { + $a = get_app(); + $categories = array(); + $folders = array(); + + $matches = false; $first = true; + $cnt = preg_match_all('/<(.*?)>/',$item['file'],$matches,PREG_SET_ORDER); + if($cnt) { + foreach($matches as $mtch) { + $categories[] = array( + 'name' => xmlify(file_tag_decode($mtch[1])), + 'url' => "#", + 'removeurl' => ((local_user() == $item['uid'])?$a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&cat=' . xmlify(file_tag_decode($mtch[1])):""), + 'first' => $first, + 'last' => false + ); + $first = false; + } + } + if (count($categories)) $categories[count($categories)-1]['last'] = true; + + + + $matches = false; $first = true; + $cnt = preg_match_all('/\[(.*?)\]/',$item['file'],$matches,PREG_SET_ORDER); + if($cnt) { + foreach($matches as $mtch) { + $folders[] = array( + 'name' => xmlify(file_tag_decode($mtch[1])), + 'url' => "#", + 'removeurl' => ((local_user() == $item['uid'])?$a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&term=' . xmlify(file_tag_decode($mtch[1])):""), + 'first' => $first, + 'last' => false + ); + $first = false; + } + } + + if (count($folders)) $folders[count($folders)-1]['last'] = true; + + return array($categories, $folders); +} + + /** * return atom link elements for all of our hubs */ diff --git a/object/Item.php b/object/Item.php index d40a384f56..04d52a896e 100644 --- a/object/Item.php +++ b/object/Item.php @@ -143,10 +143,20 @@ class Item extends BaseObject { $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_google($locate)); $tags=array(); + $hashtags = array(); + $mentions = array(); foreach(explode(',',$item['tag']) as $tag){ $tag = trim($tag); - if ($tag!="") $tags[] = bbcode($tag); - } + if ($tag!="") { + $t = bbcode($tag); + $tags[] = $t; + if($t[0] == '#') + $hashtags[] = $t; + elseif($t[0] == '@') + $mentions[] = $t; + } + + } $like = ((x($alike,$item['uri'])) ? format_like($alike[$item['uri']],$alike[$item['uri'] . '-l'],'like',$item['uri']) : ''); $dislike = ((x($dlike,$item['uri'])) ? format_like($dlike[$item['uri']],$dlike[$item['uri'] . '-l'],'dislike',$item['uri']) : ''); @@ -195,11 +205,17 @@ class Item extends BaseObject { $body = prepare_body($item,true); + list($categories, $folders) = get_cats_and_terms($item); + $tmp_item = array( 'template' => $this->get_template(), 'type' => implode("",array_slice(explode("/",$item['verb']),-1)), 'tags' => $tags, + 'hashtags' => $hashtags, + 'mentions' => $mentions, + 'categories' => $categories, + 'folders' => $folders, 'body' => template_escape($body), 'text' => strip_tags(template_escape($body)), 'id' => $this->get_id(), @@ -266,6 +282,11 @@ class Item extends BaseObject { } } + if ($this->is_toplevel()) { + $result['total_comments_num'] = $total_children; + $result['total_comments_text'] = tt('comment', 'comments', $total_children); + } + $result['private'] = $item['private']; $result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : ''); -- 2.39.5