]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
Let an item be accssible via the GUI (additionally to uid and item id)
[friendica.git] / include / text.php
index 71f75bf31345c94097f1c2490753e4e0d8a62224..4d6aa8697ae650e57499d8dc5f24b6523084dc30 100644 (file)
@@ -1,13 +1,5 @@
 <?php
 
-// This is our template processor.
-// $s is the string requiring macro substitution.
-// $r is an array of key value pairs (search => replace)
-// returns substituted string.
-// WARNING: this is pretty basic, and doesn't properly handle search strings that are substrings of each other.
-// For instance if 'test' => "foo" and 'testing' => "bar", testing could become either bar or fooing, 
-// depending on the order in which they were declared in the array.
-
 require_once("include/template_processor.php");
 require_once("include/friendica_smarty.php");
 
@@ -218,14 +210,16 @@ function xmlify($str) {
                                break;
                }       
        }*/
-
+       /*
        $buffer = mb_ereg_replace("&", "&amp;", $str);
        $buffer = mb_ereg_replace("'", "&apos;", $buffer);
-       $buffer = mb_ereg_replace("\"", "&quot;", $buffer);
+       $buffer = mb_ereg_replace('"', "&quot;", $buffer);
        $buffer = mb_ereg_replace("<", "&lt;", $buffer);
        $buffer = mb_ereg_replace(">", "&gt;", $buffer);
-
+       */
+       $buffer = htmlspecialchars($str, ENT_QUOTES);
        $buffer = trim($buffer);
+       
        return($buffer);
 }}
 
@@ -238,11 +232,13 @@ if(! function_exists('unxmlify')) {
 function unxmlify($s) {
 //     $ret = str_replace('&amp;','&', $s);
 //     $ret = str_replace(array('&lt;','&gt;','&quot;','&apos;'),array('<','>','"',"'"),$ret);
-       $ret = mb_ereg_replace('&amp;', '&', $s);
+       /*$ret = mb_ereg_replace('&amp;', '&', $s);
        $ret = mb_ereg_replace('&apos;', "'", $ret);
        $ret = mb_ereg_replace('&quot;', '"', $ret);
        $ret = mb_ereg_replace('&lt;', "<", $ret);
        $ret = mb_ereg_replace('&gt;', ">", $ret);
+       */
+       $ret = htmlspecialchars_decode($s, ENT_QUOTES);
        return $ret;    
 }}
 
@@ -657,6 +653,9 @@ function attribute_contains($attr,$s) {
 }}
 
 if(! function_exists('logger')) {
+/* setup int->string log level map */
+$LOGGER_LEVELS = array();
+       
 /**
  * log levels:
  * LOGGER_NORMAL (default)
@@ -674,9 +673,16 @@ function logger($msg,$level = 0) {
        // turn off logger in install mode
        global $a;
        global $db;
-
+       global $LOGGER_LEVELS;
+       
        if(($a->module == 'install') || (! ($db && $db->connected))) return;
 
+    if (count($LOGGER_LEVEL)==0){
+        foreach (get_defined_constants() as $k=>$v){
+            if (substr($k,0,7)=="LOGGER_") $LOGGER_LEVELS[$v] = substr($k,7,7);
+        }        
+    }
+    
        $debugging = get_config('system','debugging');
        $loglevel  = intval(get_config('system','loglevel'));
        $logfile   = get_config('system','logfile');
@@ -684,8 +690,19 @@ function logger($msg,$level = 0) {
        if((! $debugging) || (! $logfile) || ($level > $loglevel))
                return;
 
+       $callers = debug_backtrace(); 
+       $logline =  sprintf("%s@%s\t[%s]:%s:%s:%s\t%s\n", 
+                                datetime_convert(), 
+                                session_id(),
+                                $LOGGER_LEVELS[$level],
+                                basename($callers[0]['file']),
+                                $callers[0]['line'],
+                                $callers[1]['function'],
+                                $msg
+                               );
+       
        $stamp1 = microtime(true);
-       @file_put_contents($logfile, datetime_convert() . ':' . session_id() . ' ' . $msg . "\n", FILE_APPEND);
+       @file_put_contents($logfile, $logline, FILE_APPEND);
        $a->save_timestamp($stamp1, "file");
        return;
 }}
@@ -749,7 +766,7 @@ function get_tags($s) {
        // Otherwise pull out single word tags. These can be @nickname, @first_last
        // and #hash tags.
 
-       if(preg_match_all('/([@#][^ \x0D\x0A,;:?]+)([ \x0D\x0A,;:?]|$)/',$s,$match)) {
+       if(preg_match_all('/([!#@][^ \x0D\x0A,;:?]+)([ \x0D\x0A,;:?]|$)/',$s,$match)) {
                foreach($match[1] as $mtch) {
                        if(strstr($mtch,"]")) {
                                // we might be inside a bbcode color tag - leave it alone
@@ -1129,7 +1146,7 @@ function smilies($s, $sample = false) {
                '<img class="smiley" src="' . $a->get_baseurl() . '/images/like.gif" alt=":like" />',
                '<img class="smiley" src="' . $a->get_baseurl() . '/images/dislike.gif" alt=":dislike" />',
                '<a href="http://friendica.com">~friendica <img class="smiley" src="' . $a->get_baseurl() . '/images/friendica-16.png" alt="~friendica" /></a>',
-               '<a href="http://friendica.com">red <img class="smiley" src="' . $a->get_baseurl() . '/images/rhash-16.png" alt="red" /></a>'
+               '<a href="http://redmatrix.me/">red <img class="smiley" src="' . $a->get_baseurl() . '/images/rhash-16.png" alt="red" /></a>'
        );
 
        $params = array('texts' => $texts, 'icons' => $icons, 'string' => $s);
@@ -1276,7 +1293,7 @@ if(! function_exists('prepare_body')) {
  * @hook prepare_body ('item'=>item array, 'html'=>body string) after first bbcode to html
  * @hook prepare_body_final ('item'=>item array, 'html'=>body string) after attach icons and blockquote special case handling (spoiler, author)
  */
-function prepare_body(&$item,$attach = false) {
+function prepare_body(&$item,$attach = false, $preview = false) {
 
        $a = get_app();
        call_hooks('prepare_body_init', $item);
@@ -1336,7 +1353,7 @@ function prepare_body(&$item,$attach = false) {
        }
 
 
-       $prep_arr = array('item' => $item, 'html' => $s);
+       $prep_arr = array('item' => $item, 'html' => $s, 'preview' => $preview);
        call_hooks('prepare_body', $prep_arr);
        $s = $prep_arr['html'];
 
@@ -2168,7 +2185,7 @@ function normalise_openid($s) {
 
 function undo_post_tagging($s) {
        $matches = null;
-       $cnt = preg_match_all('/([@#])\[url=(.*?)\](.*?)\[\/url\]/ism',$s,$matches,PREG_SET_ORDER);
+       $cnt = preg_match_all('/([!#@])\[url=(.*?)\](.*?)\[\/url\]/ism',$s,$matches,PREG_SET_ORDER);
        if($cnt) {
                foreach($matches as $mtch) {
                        $s = str_replace($mtch[0], $mtch[1] . $mtch[3],$s);