]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
Merge branch 'master' into groups
[friendica.git] / include / text.php
index ea64a3d2820992893d3b1261422e8b2bda05f0cf..08803cc9b7be5b54bb7f4b9ceb8b6e980e520939 100644 (file)
@@ -195,6 +195,9 @@ function unxmlify($s) {
 
 if(! function_exists('hex2bin')) {
 function hex2bin($s) {
+       if(! (is_string($s) && strlen($s)))
+               return '';
+
        if(! ctype_xdigit($s)) {
                logger('hex2bin: illegal input: ' . print_r(debug_backtrace(), true));
                return($s);
@@ -388,11 +391,13 @@ function get_intltext_template($s) {
 
 if(! function_exists('get_markup_template')) {
 function get_markup_template($s) {
-
+       $a=get_app();
        $theme = current_theme();
        
        if(file_exists("view/theme/$theme/$s"))
                return file_get_contents("view/theme/$theme/$s");
+       elseif (x($a->theme_info,"extends") && file_exists("view/theme/".$a->theme_info["extends"]."/$s"))
+               return file_get_contents("view/theme/".$a->theme_info["extends"]."/$s");
        else
                return file_get_contents("view/$s");
 
@@ -460,7 +465,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
@@ -476,7 +481,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
@@ -667,7 +672,7 @@ function smilies($s) {
 
        $s = str_replace(
        array( '<3', '</3', '<\\3', ':-)', ':)', ';-)', ':-(', ':(', ':-P', ':P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O', 
-               '~friendika', 'Diaspora*' ),
+               '~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" />',
@@ -686,7 +691,8 @@ function smilies($s) {
                '<img src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt="8-|" />',
                '<img src="' . $a->get_baseurl() . '/images/smiley-surprised.gif" alt="8-O" />',
                '<a href="http://project.friendika.com">~friendika <img src="' . $a->get_baseurl() . '/images/friendika-16.png" alt="~friendika" /></a>',
-               '<a href="http://joindiaspora.com">Diaspora<img src="' . $a->get_baseurl() . '/images/diaspora.png" alt="Diaspora*" /></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);
 
@@ -742,7 +748,14 @@ function link_compare($a,$b) {
 if(! function_exists('prepare_body')) {
 function prepare_body($item,$attach = false) {
 
+       call_hooks('prepare_body_init', $item); 
+
        $s = prepare_text($item['body']);
+
+       $prep_arr = array('item' => $item, 'html' => $s);
+       call_hooks('prepare_body', $prep_arr);
+       $s = $prep_arr['html'];
+
        if(! $attach)
                return $s;
 
@@ -774,7 +787,11 @@ function prepare_body($item,$attach = false) {
                }
                $s .= '<div class="clear"></div></div>';
        }
-       return $s;
+
+
+       $prep_arr = array('item' => $item, 'html' => $s);
+       call_hooks('prepare_body_final', $prep_arr);
+       return $prep_arr['html'];
 }}
 
 
@@ -857,7 +874,7 @@ function lang_selector() {
        global $lang;
        $o = '<div id="lang-select-icon" class="icon language" title="' . t('Select an alternate language') . '" onclick="openClose(\'language-selector\');" ></div>';
        $o .= '<div id="language-selector" style="display: none;" >';
-       $o .= '<form action="" method="post" ><select name="system_language" onchange="this.form.submit();" >';
+       $o .= '<form action="#" method="post" ><select name="system_language" onchange="this.form.submit();" >';
        $langs = glob('view/*/strings.php');
        if(is_array($langs) && count($langs)) {
                $langs[] = '';
@@ -872,7 +889,7 @@ function lang_selector() {
                        }
                        $ll = substr($l,5);
                        $ll = substr($ll,0,strrpos($ll,'/'));
-                       $selected = (($ll === $lang) ? ' selected="selected" ' : '');
+                       $selected = (($ll === $lang && (x($_SESSION['language']))) ? ' selected="selected" ' : '');
                        $o .= '<option value="' . $ll . '"' . $selected . '>' . $ll . '</option>';
                }
        }
@@ -995,3 +1012,46 @@ if (!function_exists('str_getcsv')) {
         }
     }
 } 
+
+function cleardiv() {
+       return '<div class="clear"></div>';
+}
+
+
+function bb_translate_video($s) {
+
+       $matches = null;
+       $r = preg_match_all("/\[video\](.*?)\[\/video\]/ism",$s,$matches,PREG_SET_ORDER);
+       if($r) {
+               foreach($matches as $mtch) {
+                       if((stristr($mtch[1],'youtube')) || (stristr($mtch[1],'youtu.be')))
+                               $s = str_replace($mtch[0],'[youtube]' . $mtch[1] . '[/youtube]',$s);
+                       elseif(stristr($mtch[1],'vimeo'))
+                               $s = str_replace($mtch[0],'[vimeo]' . $mtch[1] . '[/vimeo]',$s);
+               }
+       }
+       return $s;      
+}
+
+function html2bb_video($s) {
+
+       $s = preg_replace('#<object[^>]+>(.*?)https+://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+)(.*?)</object>#ism',
+                       '[youtube]$2[/youtube]', $s);
+
+       $s = preg_replace('#<iframe[^>](.*?)https+://www.youtube.com/embed/([A-Za-z0-9\-_=]+)(.*?)</iframe>#ism',
+                       '[youtube]$2[/youtube]', $s);
+
+       $s = preg_replace('#<iframe[^>](.*?)https+://player.vimeo.com/video/([0-9]+)(.*?)</iframe>#ism',
+                       '[vimeo]$2[/vimeo]', $s);
+
+       return $s;
+}
+
+/**
+ * apply xmlify() to all values of array $val, recursively
+ */
+function array_xmlify($val){
+       if (is_bool($val)) return $val?"true":"false";
+       if (is_array($val)) return array_map('array_xmlify', $val);
+       return xmlify((string) $val);
+}