1
1
Fork 0

conversation: new 'categories' and 'folder' elements to $item

remove static "Filed under" e "Category" text from message body
both are lists of array whith
'name' : category/folder name
'remove': url to remove
'first': bool first in array
'last' : bool last in array
This commit is contained in:
Fabrixxm 2012-09-19 11:38:32 -04:00
parent 2bdbdc8d8e
commit b400ddd22d
2 changed files with 74 additions and 27 deletions

View file

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

View file

@ -1016,35 +1016,8 @@ function prepare_body($item,$attach = false) {
} }
$s .= '<div class="clear"></div></div>'; $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 // Look for spoiler
$spoilersearch = '<blockquote class="spoiler">'; $spoilersearch = '<blockquote class="spoiler">';