Merge pull request #492 from fabrixxm/blog-like

More data in $item array
This commit is contained in:
friendica 2012-09-20 02:15:12 -07:00
commit 58399c854f
4 changed files with 107 additions and 29 deletions

View File

@ -350,6 +350,7 @@ function visible_activity($item) {
return true;
}
/**
* Recursively prepare a thread for HTML
*/
@ -629,6 +630,10 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
$body = prepare_body($item,true);
list($categories, $folders) = get_cats_and_terms($item);
$tmp_item = array(
// collapse comments in template. I don't like this much...
'comment_firstcollapsed' => $firstcollapsed,
@ -640,6 +645,8 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
'tags' => template_escape($tags),
'hashtags' => template_escape($hashtags),
'mentions' => template_escape($mentions),
'categories' => $categories,
'folders' => $folders,
'body' => template_escape($body),
'text' => strip_tags(template_escape($body)),
'id' => $item['item_id'],
@ -892,6 +899,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
$body = prepare_body($item,true);
list($categories, $folders) = get_cats_and_terms($item);
//$tmp_item = replace_macros($tpl,array(
$tmp_item = array(
'template' => $tpl,
@ -908,6 +916,8 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
'tags' => template_escape($tags),
'hashtags' => template_escape($hashtags),
'mentions' => template_escape($mentions),
'categories' => $categories,
'folders' => $folders,
'text' => strip_tags(template_escape($body)),
'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])),
@ -985,6 +995,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
$o = replace_macros($page_template, array(
'$baseurl' => $a->get_baseurl($ssl_state),
'$remove' => t('remove'),
'$mode' => $mode,
'$user' => $a->user,
'$threads' => $threads,

View File

@ -1016,35 +1016,8 @@ function prepare_body($item,$attach = false) {
}
$s .= '<div class="clear"></div></div>';
}
$matches = false;
$cnt = preg_match_all('/<(.*?)>/',$item['file'],$matches,PREG_SET_ORDER);
if($cnt) {
// logger('prepare_text: categories: ' . print_r($matches,true), LOGGER_DEBUG);
foreach($matches as $mtch) {
if(strlen($x))
$x .= ',';
$x .= xmlify(file_tag_decode($mtch[1]))
. ((local_user() == $item['uid']) ? ' <a href="' . $a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&cat=' . xmlify(file_tag_decode($mtch[1])) . '" title="' . t('remove') . '" >' . t('[remove]') . '</a>' : '');
}
if(strlen($x))
$s .= '<div class="categorytags"><span>' . t('Categories:') . ' </span>' . $x . '</div>';
}
$matches = false;
$x = '';
$cnt = preg_match_all('/\[(.*?)\]/',$item['file'],$matches,PREG_SET_ORDER);
if($cnt) {
// logger('prepare_text: filed_under: ' . print_r($matches,true), LOGGER_DEBUG);
foreach($matches as $mtch) {
if(strlen($x))
$x .= '&nbsp;&nbsp;&nbsp;';
$x .= xmlify(file_tag_decode($mtch[1])) . ' <a href="' . $a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&term=' . xmlify(file_tag_decode($mtch[1])) . '" title="' . t('remove') . '" >' . t('[remove]') . '</a>';
}
if(strlen($x) && (local_user() == $item['uid']))
$s .= '<div class="filesavetags"><span>' . t('Filed under:') . ' </span>' . $x . '</div>';
}
// Look for spoiler
$spoilersearch = '<blockquote class="spoiler">';
@ -1098,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
*/

View File

@ -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' : '');

View File

@ -25,6 +25,13 @@
echo $file . "\n";
include_once($file);
}
echo "Directory: object\n";
$files = glob('object/*.php');
foreach($files as $file) {
echo $file . "\n";
include_once($file);
}
echo "Directory: addon\n";
$dirs = glob('addon/*');