]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
remove "smilie" expansion for Diaspora logo
[friendica.git] / include / text.php
index b9813cfa9fa983c6a38c738f8c4e01f3d25d6b11..c8c03174e613625281240e0f0276c74e56d2e630 100755 (executable)
@@ -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;
 
 }}
 
@@ -675,12 +681,24 @@ 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, $sample = false) {
        $a = get_app();
 
+       $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', 
@@ -719,7 +737,7 @@ function smilies($s, $sample = false) {
                ':headdesk',
                '~friendika', 
                '~friendica', 
-               'Diaspora*' 
+//             'Diaspora*' 
        );
 
        $icons = array(
@@ -759,8 +777,8 @@ function smilies($s, $sample = false) {
                '<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>',
 
        );
 
@@ -774,13 +792,37 @@ function smilies($s, $sample = false) {
                }
        }
        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);
+
        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')) {
@@ -972,7 +1014,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>';
                }
        }
@@ -1177,3 +1219,16 @@ function reltoabs($text, $base)
   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');
+}
+
+