diff --git a/include/conversation.php b/include/conversation.php index 1d927d201..a06dbd7bd 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -350,6 +350,70 @@ function visible_activity($item) { 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 */ @@ -629,6 +693,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 +708,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'], @@ -890,6 +960,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, @@ -906,6 +977,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'])), @@ -983,6 +1056,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, diff --git a/include/text.php b/include/text.php index c1e01343a..878ce80e9 100644 --- a/include/text.php +++ b/include/text.php @@ -1016,35 +1016,8 @@ function prepare_body($item,$attach = false) { } $s .= '
'; } - $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']) ? ' ' . t('[remove]') . '' : ''); - } - if(strlen($x)) - $s .= ' '; - } - $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 .= ' '; - $x .= xmlify(file_tag_decode($mtch[1])) . ' ' . t('[remove]') . ''; - } - if(strlen($x) && (local_user() == $item['uid'])) - $s .= ' '; - } - // Look for spoiler $spoilersearch = '';