]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
:coffee extended smilie
[friendica.git] / include / text.php
old mode 100644 (file)
new mode 100755 (executable)
index 8ada179..9aca145
@@ -426,6 +426,10 @@ function attribute_contains($attr,$s) {
 
 if(! function_exists('logger')) {
 function logger($msg,$level = 0) {
+       // turn off logger in install mode
+       global $a;
+       if ($a->module == 'install') return;
+       
        $debugging = get_config('system','debugging');
        $loglevel  = intval(get_config('system','loglevel'));
        $logfile   = get_config('system','logfile');
@@ -465,7 +469,7 @@ function get_tags($s) {
        // Match full names against @tags including the space between first and last
        // We will look these up afterward to see if they are full names or not recognisable.
 
-       if(preg_match_all('/(@[^ \x0D\x0A,:?]+ [^ \x0D\x0A,:?]+)([ \x0D\x0A,:?]|$)/',$s,$match)) {
+       if(preg_match_all('/(@[^ \x0D\x0A,:?]+ [^ \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
@@ -492,6 +496,9 @@ function get_tags($s) {
                        // ignore strictly numeric tags like #1
                        if((strpos($mtch,'#') === 0) && ctype_digit(substr($mtch,1)))
                                continue;
+                       // try not to catch url fragments
+                       if(strpos($s,$mtch) && preg_match('/[a-zA-z0-9\/]/',substr($s,strpos($s,$mtch)-1,1)))
+                               continue;
                        $ret[] = $mtch;
                }
        }
@@ -536,7 +543,7 @@ function contact_block() {
 
        if((! is_array($a->profile)) || ($a->profile['hide-friends']))
                return $o;
-       $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0",
+       $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0",
                        intval($a->profile['uid'])
        );
        if(count($r)) {
@@ -547,7 +554,7 @@ function contact_block() {
                $micropro = Null;
                
        } else {
-               $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 ORDER BY RAND() LIMIT %d",
+               $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0 ORDER BY RAND() LIMIT %d",
                                intval($a->profile['uid']),
                                intval($shown)
                );
@@ -632,7 +639,7 @@ function search($s,$id='search-box',$url='/search',$save = false) {
 
 if(! function_exists('valid_email')) {
 function valid_email($x){
-       if(preg_match('/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/',$x))
+       if(preg_match('/^[_a-zA-Z0-9\-\+]+(\.[_a-zA-Z0-9\-\+]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/',$x))
                return true;
        return false;
 }}
@@ -671,8 +678,9 @@ function smilies($s) {
        $a = get_app();
 
        $s = str_replace(
-       array( '<3', '</3', '<\\3', ':-)', ':)', ';-)', ':-(', ':(', ':-P', ':P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O', 
-               '~friendika', 'Diaspora*' ),
+       array( '<3', '</3', '<\\3', ':-)', ':)', ';-)', ':-(', ':(', ':-P', ':P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O', '\\o/', 'o.O', 'O.o', '\\.../', '\\ooo/', 
+ ':beer', ':homebrew', ':coffee', 
+               '~friendika', '~friendica', 'Diaspora*' ),
        array(
                '<img src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="</3" />',
@@ -690,7 +698,17 @@ function smilies($s) {
                '<img src="' . $a->get_baseurl() . '/images/smiley-laughing.gif" alt=":-D" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt="8-|" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt="8-O" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-thumbsup.gif" alt="\\o/" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-Oo.gif" alt="o.O" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-Oo.gif" alt="O.o" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-shaka.gif" alt="\\.../" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-shaka.gif" alt="\\ooo/" />',
+               '<img src="' . $a->get_baseurl() . '/images/beer_mug.gif" alt=":beer" />',
+               '<img src="' . $a->get_baseurl() . '/images/beer_mug.gif" alt=":homebrew" />',
+               '<img src="' . $a->get_baseurl() . '/images/coffee.gif" alt=":coffee" />',
+
                '<a href="http://project.friendika.com">~friendika <img src="' . $a->get_baseurl() . '/images/friendika-16.png" alt="~friendika" /></a>',
+               '<a href="http://friendica.com">~friendica <img src="' . $a->get_baseurl() . '/images/friendika-16.png" alt="~friendica" /></a>',
                '<a href="http://diasporafoundation.org">Diaspora<img src="' . $a->get_baseurl() . '/images/diaspora.png" alt="Diaspora*" /></a>',
 
        ), $s);
@@ -787,14 +805,6 @@ function prepare_body($item,$attach = false) {
                $s .= '<div class="clear"></div></div>';
        }
 
-       $arr = explode(',',$item['tag']);
-       if(count($arr)) {
-               $s .= '<div class="body-tag">';
-               foreach($arr as $r) {
-                       $s .= bbcode($r) . ' ';
-               }
-               $s .= '</div>';
-       }
 
        $prep_arr = array('item' => $item, 'html' => $s);
        call_hooks('prepare_body_final', $prep_arr);
@@ -943,6 +953,11 @@ function base64url_encode($s, $strip_padding = false) {
 
 function base64url_decode($s) {
 
+       if(is_array($s)) {
+               logger('base64url_decode: illegal input: ' . print_r(debug_backtrace(), true));
+               return $s;
+       }
+
 /*
  *  // Placeholder for new rev of salmon which strips base64 padding.
  *  // PHP base64_decode handles the un-padded input without requiring this step
@@ -1062,3 +1077,37 @@ function array_xmlify($val){
        if (is_array($val)) return array_map('array_xmlify', $val);
        return xmlify((string) $val);
 }
+
+
+function reltoabs($text, $base)
+{
+  if (empty($base))
+    return $text;
+
+  $base = rtrim($base,'/');
+
+  $base2 = $base . "/";
+       
+  // Replace links
+  $pattern = "/<a([^>]*) href=\"(?!http|https|\/)([^\"]*)\"/";
+  $replace = "<a\${1} href=\"" . $base2 . "\${2}\"";
+  $text = preg_replace($pattern, $replace, $text);
+
+  $pattern = "/<a([^>]*) href=\"(?!http|https)([^\"]*)\"/";
+  $replace = "<a\${1} href=\"" . $base . "\${2}\"";
+  $text = preg_replace($pattern, $replace, $text);
+
+  // Replace images
+  $pattern = "/<img([^>]*) src=\"(?!http|https|\/)([^\"]*)\"/";
+  $replace = "<img\${1} src=\"" . $base2 . "\${2}\"";
+  $text = preg_replace($pattern, $replace, $text); 
+
+  $pattern = "/<img([^>]*) src=\"(?!http|https)([^\"]*)\"/";
+  $replace = "<img\${1} src=\"" . $base . "\${2}\"";
+  $text = preg_replace($pattern, $replace, $text); 
+
+
+  // Done
+  return $text;
+}
+