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
This commit is contained in:
parent
eda96a82d7
commit
dd25c7db7e
3 changed files with 89 additions and 65 deletions
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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' : '');
|
||||
|
||||
|
|
Loading…
Reference in a new issue