Skip to content
This repository
Browse code

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
  • Loading branch information...
commit b400ddd22d9d9490db9e1e5d9e0de3691077828d 1 parent 2bdbdc8
fabrixxm authored September 19, 2012
74  include/conversation.php
@@ -350,6 +350,70 @@ function visible_activity($item) {
350 350
 	return true;
351 351
 }
352 352
 
  353
+
  354
+/**
  355
+ * returns 
  356
+ * [
  357
+ *    //categories [
  358
+ *          {
  359
+ *               'name': 'category name',
  360
+ *              'removeurl': 'url to remove this category',
  361
+ *             'first': 'is the first in this array? true/false',
  362
+ *               'last': 'is the last in this array? true/false',
  363
+ *           } ,
  364
+ *           ....
  365
+ *       ],
  366
+ *       // folders [
  367
+ *               'name': 'folder name',
  368
+ *               'removeurl': 'url to remove this folder',
  369
+ *               'first': 'is the first in this array? true/false',
  370
+ *               'last': 'is the last in this array? true/false',
  371
+ *           } ,
  372
+ *           ....       
  373
+ *       ]
  374
+ *   ]
  375
+ */
  376
+function get_cats_and_terms($item) {
  377
+    $categories = array();
  378
+    $folders = array();
  379
+
  380
+    $matches = false; $first = true;
  381
+    $cnt = preg_match_all('/<(.*?)>/',$item['file'],$matches,PREG_SET_ORDER);
  382
+    if($cnt) {
  383
+        foreach($matches as $mtch) {
  384
+            $categories[] = array(
  385
+                'name' => xmlify(file_tag_decode($mtch[1])),
  386
+                'removeurl' => $a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&cat=' . xmlify(file_tag_decode($mtch[1])),
  387
+                'first' => $first,
  388
+                'last' => false
  389
+            );
  390
+            $first = false;
  391
+        }
  392
+    }
  393
+    if (count($categories)) $categories[count($categories)-1]['last'] = true;
  394
+    
  395
+
  396
+
  397
+    $matches = false; $first = true;
  398
+    $cnt = preg_match_all('/\[(.*?)\]/',$item['file'],$matches,PREG_SET_ORDER);
  399
+    if($cnt) {
  400
+        foreach($matches as $mtch) {
  401
+            $folders[] = array(
  402
+                'name' => xmlify(file_tag_decode($mtch[1])),
  403
+                'removeurl' => $a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&term=' . xmlify(file_tag_decode($mtch[1])),
  404
+                'first' => $first,
  405
+                'last' => false
  406
+            );
  407
+            $first = false;
  408
+        }
  409
+    }
  410
+
  411
+    if (count($folders)) $folders[count($folders)-1]['last'] = true;
  412
+    
  413
+    return array($categories, $folders);
  414
+}
  415
+
  416
+
353 417
 /**
354 418
  * Recursively prepare a thread for HTML
355 419
  */
@@ -629,6 +693,10 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
629 693
 
630 694
 		$body = prepare_body($item,true);
631 695
 
  696
+		list($categories, $folders) = get_cats_and_terms($item);
  697
+
  698
+
  699
+
632 700
 		$tmp_item = array(
633 701
 			// collapse comments in template. I don't like this much...
634 702
 			'comment_firstcollapsed' => $firstcollapsed,
@@ -640,6 +708,8 @@ function prepare_threads_body($a, $items, $cmnt_tpl, $page_writeable, $mode, $pr
640 708
 			'tags' => template_escape($tags),
641 709
 			'hashtags' => template_escape($hashtags),
642 710
 			'mentions' => template_escape($mentions),
  711
+			'categories' => $categories,
  712
+			'folders' => $folders,
643 713
 			'body' => template_escape($body),
644 714
 			'text' => strip_tags(template_escape($body)),
645 715
 			'id' => $item['item_id'],
@@ -890,6 +960,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
890 960
 
891 961
 				$body = prepare_body($item,true);
892 962
 
  963
+				list($categories, $folders) = get_cats_and_terms($item);
893 964
 				//$tmp_item = replace_macros($tpl,array(
894 965
 				$tmp_item = array(
895 966
 					'template' => $tpl,
@@ -906,6 +977,8 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
906 977
 					'tags' => template_escape($tags),
907 978
 					'hashtags' => template_escape($hashtags),
908 979
 					'mentions' => template_escape($mentions),
  980
+					'categories' => $categories,
  981
+					'folders' => $folders,
909 982
 					'text' => strip_tags(template_escape($body)),
910 983
 					'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'),
911 984
 					'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) {
983 1056
 
984 1057
 	$o = replace_macros($page_template, array(
985 1058
 		'$baseurl' => $a->get_baseurl($ssl_state),
  1059
+        '$remove' => t('remove'),
986 1060
 		'$mode' => $mode,
987 1061
 		'$user' => $a->user,
988 1062
 		'$threads' => $threads,
27  include/text.php
@@ -1016,35 +1016,8 @@ function prepare_body($item,$attach = false) {
1016 1016
 		}
1017 1017
 		$s .= '<div class="clear"></div></div>';
1018 1018
 	}
1019  
-	$matches = false;
1020  
-	$cnt = preg_match_all('/<(.*?)>/',$item['file'],$matches,PREG_SET_ORDER);
1021  
-	if($cnt) {
1022  
-//		logger('prepare_text: categories: ' . print_r($matches,true), LOGGER_DEBUG);
1023  
-		foreach($matches as $mtch) {
1024  
-			if(strlen($x))
1025  
-				$x .= ',';
1026  
-			$x .= xmlify(file_tag_decode($mtch[1])) 
1027  
-				. ((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>' : '');
1028  
-		}
1029  
-		if(strlen($x))
1030  
-			$s .= '<div class="categorytags"><span>' . t('Categories:') . ' </span>' . $x . '</div>'; 
1031 1019
 
1032 1020
 
1033  
-	}
1034  
-	$matches = false;
1035  
-	$x = '';
1036  
-	$cnt = preg_match_all('/\[(.*?)\]/',$item['file'],$matches,PREG_SET_ORDER);
1037  
-	if($cnt) {
1038  
-//		logger('prepare_text: filed_under: ' . print_r($matches,true), LOGGER_DEBUG);
1039  
-		foreach($matches as $mtch) {
1040  
-			if(strlen($x))
1041  
-				$x .= '&nbsp;&nbsp;&nbsp;';
1042  
-			$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>';
1043  
-		}
1044  
-		if(strlen($x) && (local_user() == $item['uid']))
1045  
-			$s .= '<div class="filesavetags"><span>' . t('Filed under:') . ' </span>' . $x . '</div>'; 
1046  
-	}
1047  
-
1048 1021
 	// Look for spoiler
1049 1022
 	$spoilersearch = '<blockquote class="spoiler">';
1050 1023
 

0 notes on commit b400ddd

Please sign in to comment.
Something went wrong with that request. Please try again.