]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
Merge pull request #512 from fermionic/auto-redir-for-local-hub-contacts
[friendica.git] / include / text.php
index c1e01343a8cd856134a3d68ca7f45a3975197b5d..23e3e5061153f51996f891c9a77e5ca03e777543 100644 (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,73 @@ 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;
+    
+
+       if(local_user() == $item['uid']) {
+           $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
  */