]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
Merge commit 'upstream/master'
[friendica.git] / include / text.php
index 011006b764cfd2058f2e41b2b08f9d9a494fda58..d34fd7fbeec35bcacfb5a1bd2fa201a3e770d692 100644 (file)
@@ -874,16 +874,30 @@ function link_compare($a,$b) {
 if(! function_exists('prepare_body')) {
 function prepare_body($item,$attach = false) {
 
+       $a = get_app();
        call_hooks('prepare_body_init', $item); 
 
-       $s = prepare_text($item['body']);
+       $cache = get_config('system','itemcache');
+
+       if (($cache != '')) {
+               $cachefile = $cache."/".$item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body']);
+
+               if (file_exists($cachefile))
+                       $s = file_get_contents($cachefile);
+               else {
+                       $s = prepare_text($item['body']);
+                       file_put_contents($cachefile, $s);
+               }
+       } else
+               $s = prepare_text($item['body']);
 
        $prep_arr = array('item' => $item, 'html' => $s);
        call_hooks('prepare_body', $prep_arr);
        $s = $prep_arr['html'];
 
-       if(! $attach)
+       if(! $attach) {
                return $s;
+       }
 
        $arr = explode(',',$item['attach']);
        if(count($arr)) {
@@ -913,10 +927,37 @@ 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 .= file_tag_decode($mtch[1]);
+               }
+               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 .= file_tag_decode($mtch[1]). ' <a href="' . $a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&term=' . 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>'; 
+       }
+
        $prep_arr = array('item' => $item, 'html' => $s);
        call_hooks('prepare_body_final', $prep_arr);
+
        return $prep_arr['html'];
 }}
 
@@ -1267,7 +1308,7 @@ function file_tag_save_file($uid,$item,$file) {
        if(count($r)) {
                if(! stristr($r[0]['file'],'[' . file_tag_encode($file) . ']'))
                        q("update item set file = '%s' where id = %d and uid = %d limit 1",
-                               dbesc($r[0]['file'] . '[' . $file_tag_encode($file) . ']'),
+                               dbesc($r[0]['file'] . '[' . file_tag_encode($file) . ']'),
                                intval($item),
                                intval($uid)
                        );