]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
Fixed...merged with mainline THEN added beards.
[friendica.git] / include / text.php
index 1db88ca2c8b80b00e31467ede6fe04befaeabaae..e7c95d35c995341386298fcd8044a2b6ed30d285 100644 (file)
@@ -14,7 +14,13 @@ if(! function_exists('replace_macros')) {
 function replace_macros($s,$r) {
        global $t;
        
-       return $t->replace($s,$r);
+       //$ts = microtime();
+       $r =  $t->replace($s,$r);
+       //$tt = microtime() - $ts;
+       
+       //$a = get_app();
+       //$a->page['debug'] .= "$tt <br>\n";
+       return $r;
 
 }}
 
@@ -428,8 +434,10 @@ if(! function_exists('logger')) {
 function logger($msg,$level = 0) {
        // turn off logger in install mode
        global $a;
-       if ($a->module == 'install') return;
-       
+       global $db;
+
+       if(($a->module == 'install') || (! ($db && $db->connected))) return;
+
        $debugging = get_config('system','debugging');
        $loglevel  = intval(get_config('system','loglevel'));
        $logfile   = get_config('system','logfile');
@@ -538,8 +546,10 @@ function contact_block() {
        $a = get_app();
 
        $shown = get_pconfig($a->profile['uid'],'system','display_friend_count');
-       if(! $shown)
+       if($shown === false)
                $shown = 24;
+       if($shown == 0)
+               return;
 
        if((! is_array($a->profile)) || ($a->profile['hide-friends']))
                return $o;
@@ -671,46 +681,152 @@ function linkify($s) {
  * @Parameter: string $s
  *
  * Returns string
+ *
+ * It is expected that this function will be called using HTML text.
+ * We will escape text between HTML pre and code blocks from being 
+ * processed. 
+ * 
+ * At a higher level, the bbcode [nosmile] tag can be used to prevent this 
+ * function from being executed by the prepare_text() routine when preparing
+ * bbcode source for HTML display
+ *
  */
 
 if(! function_exists('smilies')) {
-function smilies($s) {
+function smilies($s, $sample = false) {
        $a = get_app();
 
-       $s = str_replace(
-       array( '&lt;3', '&lt;/3', '&lt;\\3', ':-)', ':)', ';-)', ':-(', ':(', ':-P', ':P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O', '\\o/', 'o.O', 'O.o',
-               '~friendika', '~friendica', 'Diaspora*' ),
-       array(
+       $s = preg_replace_callback('/<pre>(.*?)<\/pre>/ism','smile_encode',$s);
+       $s = preg_replace_callback('/<code>(.*?)<\/code>/ism','smile_encode',$s);
+
+       $texts =  array( 
+               '&lt;3', 
+               '&lt;/3', 
+               '&lt;\\3', 
+               ':-)', 
+//             ':)', 
+               ';-)', 
+//             ';)', 
+               ':-(', 
+//             ':(', 
+               ':-P', 
+//             ':P', 
+               ':-"', 
+               ':-&quot;', 
+               ':-x', 
+               ':-X', 
+               ':-D', 
+//             ':D', 
+               '8-|', 
+               '8-O', 
+               ':-O', 
+               '\\o/', 
+               'o.O', 
+               'O.o', 
+               '\\.../', 
+               '\\ooo/', 
+               ":'(", 
+               ":-!", 
+               ":-/", 
+               ":-[", 
+               "8-)",
+               ':beer', 
+               ':homebrew', 
+               ':coffee', 
+               ':facepalm',
+               ':headdesk',
+               '~friendika', 
+               '~friendica', 
+//             'Diaspora*' 
+               ':beard',
+               ':whitebeard'
+
+       );
+
+       $icons = array(
                '<img src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="</3" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-brokenheart.gif" alt="<\\3" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-smile.gif" alt=":-)" />',
-               '<img src="' . $a->get_baseurl() . '/images/smiley-smile.gif" alt=":)" />',
+//             '<img src="' . $a->get_baseurl() . '/images/smiley-smile.gif" alt=":)" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-wink.gif" alt=";-)" />',
+//             '<img src="' . $a->get_baseurl() . '/images/smiley-wink.gif" alt=";)"/>',                
                '<img src="' . $a->get_baseurl() . '/images/smiley-frown.gif" alt=":-(" />',
-               '<img src="' . $a->get_baseurl() . '/images/smiley-frown.gif" alt=":(" />',
+//             '<img src="' . $a->get_baseurl() . '/images/smiley-frown.gif" alt=":(" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-tongue-out.gif" alt=":-P" />',
-               '<img src="' . $a->get_baseurl() . '/images/smiley-tongue-out.gif" alt=":P" />',
+//             '<img src="' . $a->get_baseurl() . '/images/smiley-tongue-out.gif" alt=":P" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-\"" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-\"" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-x" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-kiss.gif" alt=":-X" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-laughing.gif" alt=":-D" />',
+//             '<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-surprised.gif" alt=":-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/smiley-cry.gif" alt=":\'(" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-foot-in-mouth.gif" alt=":-!" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-undecided.gif" alt=":-/" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-embarassed.gif" alt=":-[" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-cool.gif" alt="8-)" />',
+               '<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" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-facepalm.gif" alt=":facepalm" />',
+               '<img src="' . $a->get_baseurl() . '/images/smiley-bangheaddesk.gif" alt=":headdesk" />',
                '<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>',
+               '<a href="http://friendica.com">~friendica <img src="' . $a->get_baseurl() . '/images/friendica-16.png" alt="~friendica" /></a>',
+//             '<a href="http://diasporafoundation.org">Diaspora<img src="' . $a->get_baseurl() . '/images/diaspora.png" alt="Diaspora*" /></a>',
+               '<img src="' . $a->get_baseurl() . '/images/beard.jpg" alt=":beard" />',
+               '<img src="' . $a->get_baseurl() . '/images/whitebeard.jpg" alt=":whitebeard" />'
+       );
 
-       ), $s);
+       $params = array('texts' => $texts, 'icons' => $icons, 'string' => $s);
+       call_hooks('smilie', $params);
+
+       if($sample) {
+               $s = '<div class="smiley-sample">';
+               for($x = 0; $x < count($params['texts']); $x ++) {
+                       $s .= '<dl><dt>' . $params['texts'][$x] . '</dt><dd>' . $params['icons'][$x] . '</dd></dl>';
+               }
+       }
+       else {
+               $params['string'] = preg_replace_callback('/&lt;(3+)/','preg_heart',$params['string']);
+               $s = str_replace($params['texts'],$params['icons'],$params['string']);
+       }
+
+       $s = preg_replace_callback('/<pre>(.*?)<\/pre>/ism','smile_decode',$s);
+       $s = preg_replace_callback('/<code>(.*?)<\/code>/ism','smile_decode',$s);
 
-       call_hooks('smilie', $s);
        return $s;
 
 }}
 
+function smile_encode($m) {
+       return(str_replace($m[1],base64url_encode($m[1]),$m[0]));
+}
+
+function smile_decode($m) {
+       return(str_replace($m[1],base64url_decode($m[1]),$m[0]));
+}
+
+// expand <3333 to the correct number of hearts
+
+function preg_heart($x) {
+       $a = get_app();
+       if(strlen($x[1]) == 1)
+               return $x[0];
+       $t = '';
+       for($cnt = 0; $cnt < strlen($x[1]); $cnt ++)
+               $t .= '<img src="' . $a->get_baseurl() . '/images/smiley-heart.gif" alt="<3" />';
+       $r =  str_replace($x[0],$t,$x[0]);
+       return $r;
+}
 
 
 if(! function_exists('day_translate')) {
@@ -783,10 +899,10 @@ function prepare_body($item,$attach = false) {
                                        case 'audio':
                                        case 'image':
                                        case 'text':
-                                               $icon = '<div class="attachtype type-' . $icontype . '"></div>';
+                                               $icon = '<div class="attachtype icon s22 type-' . $icontype . '"></div>';
                                                break;
                                        default:
-                                               $icon = '<div class="attachtype type-unkn"></div>';
+                                               $icon = '<div class="attachtype icon s22 type-unkn"></div>';
                                                break;
                                }
                                $title = ((strlen(trim($matches[4]))) ? escape_tags(trim($matches[4])) : escape_tags($matches[1]));
@@ -812,7 +928,10 @@ function prepare_text($text) {
 
        require_once('include/bbcode.php');
 
-       $s = smilies(bbcode($text));
+       if(stristr($text,'[nosmile]'))
+               $s = bbcode($text);
+       else
+               $s = smilies(bbcode($text));
 
        return $s;
 }}
@@ -899,7 +1018,7 @@ function lang_selector() {
                        }
                        $ll = substr($l,5);
                        $ll = substr($ll,0,strrpos($ll,'/'));
-                       $selected = (($ll === $lang && (x($_SESSION['language']))) ? ' selected="selected" ' : '');
+                       $selected = (($ll === $lang && (x($_SESSION, 'language'))) ? ' selected="selected" ' : '');
                        $o .= '<option value="' . $ll . '"' . $selected . '>' . $ll . '</option>';
                }
        }
@@ -946,6 +1065,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
@@ -1065,3 +1189,50 @@ 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;
+}
+
+function item_post_type($item) {
+       if(intval($item['event-id']))
+               return t('event');
+       if(strlen($item['resource-id']))
+               return t('photo');
+       if(strlen($item['verb']) && $item['verb'] !== ACTIVITY_POST)
+               return t('activity');
+       if($item['id'] != $item['parent'])
+               return t('comment');
+       return t('post');
+}
+
+