]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
no more googlegroups
[friendica.git] / include / text.php
index a326412411703947bc1c827c5853c0f4bf4a6c47..6662ac8028f34d40e246f502508d23b8c19a37d9 100644 (file)
@@ -9,19 +9,38 @@
 // depending on the order in which they were declared in the array.   
 
 require_once("include/template_processor.php");
+require_once("include/friendica_smarty.php");
 
 if(! function_exists('replace_macros')) {  
 function replace_macros($s,$r) {
        global $t;
-       
-       //$ts = microtime();
-       $r =  $t->replace($s,$r);
-       //$tt = microtime() - $ts;
-       
-       //$a = get_app();
-       //$a->page['debug'] .= "$tt <br>\n";
-       return template_unescape($r);
 
+//     $ts = microtime();
+       $a = get_app();
+
+       if($a->theme['template_engine'] === 'smarty3') {
+               $template = '';
+               if(gettype($s) === 'string') {
+                       $template = $s;
+                       $s = new FriendicaSmarty();
+               }
+               foreach($r as $key=>$value) {
+                       if($key[0] === '$') {
+                               $key = substr($key, 1);
+                       }
+                       $s->assign($key, $value);
+               }
+               $output = $s->parsed($template);
+       }
+       else {
+               $r =  $t->replace($s,$r);
+       
+               $output = template_unescape($r);
+       }
+//     $tt = microtime() - $ts;
+//     $a = get_app();
+//     $a->page['debug'] .= "$tt <br>\n";
+       return $output;
 }}
 
 
@@ -154,10 +173,11 @@ function autoname($len) {
 
 if(! function_exists('xmlify')) {
 function xmlify($str) {
-       $buffer = '';
+/*     $buffer = '';
        
-       for($x = 0; $x < mb_strlen($str); $x ++) {
-               $char = $str[$x];
+       $len = mb_strlen($str);
+       for($x = 0; $x < $len; $x ++) {
+               $char = mb_substr($str,$x,1);
         
                switch( $char ) {
 
@@ -185,7 +205,14 @@ function xmlify($str) {
                                $buffer .= $char;
                                break;
                }       
-       }
+       }*/
+
+       $buffer = mb_ereg_replace("&", "&amp;", $str);
+       $buffer = mb_ereg_replace("'", "&apos;", $buffer);
+       $buffer = mb_ereg_replace("\"", "&quot;", $buffer);
+       $buffer = mb_ereg_replace("<", "&lt;", $buffer);
+       $buffer = mb_ereg_replace(">", "&gt;", $buffer);
+
        $buffer = trim($buffer);
        return($buffer);
 }}
@@ -195,8 +222,13 @@ function xmlify($str) {
 
 if(! function_exists('unxmlify')) {
 function unxmlify($s) {
-       $ret = str_replace('&amp;','&', $s);
-       $ret = str_replace(array('&lt;','&gt;','&quot;','&apos;'),array('<','>','"',"'"),$ret);
+//     $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('&apos;', "'", $ret);
+       $ret = mb_ereg_replace('&quot;', '"', $ret);
+       $ret = mb_ereg_replace('&lt;', "<", $ret);
+       $ret = mb_ereg_replace('&gt;', ">", $ret);
        return $ret;    
 }}
 
@@ -292,11 +324,11 @@ function alt_pager(&$a, $i) {
         $o .= '<div class="pager">';
 
        if($a->pager['page']>1)
-         $o .= "<a href=\"$url"."&page=".($a->pager['page'] - 1).'">' . t('newer') . '</a>';
+         $o .= "<a href=\"$url"."&page=".($a->pager['page'] - 1).'" class="pager_newer">' . t('newer') . '</a>';
         if($i>0) {
           if($a->pager['page']>1)
                  $o .= "&nbsp;-&nbsp;";
-         $o .= "<a href=\"$url"."&page=".($a->pager['page'] + 1).'">' . t('older') . '</a>';
+         $o .= "<a href=\"$url"."&page=".($a->pager['page'] + 1).'" class="pager_older">' . t('older') . '</a>';
        }
 
 
@@ -421,29 +453,63 @@ if(! function_exists('get_intltext_template')) {
 function get_intltext_template($s) {
        global $lang;
 
+       $a = get_app();
+       $engine = '';
+       if($a->theme['template_engine'] === 'smarty3')
+               $engine = "/smarty3";
+
        if(! isset($lang))
                $lang = 'en';
 
-       if(file_exists("view/$lang/$s"))
-               return file_get_contents("view/$lang/$s");
-       elseif(file_exists("view/en/$s"))
-               return file_get_contents("view/en/$s");
+       if(file_exists("view/$lang$engine/$s"))
+               return file_get_contents("view/$lang$engine/$s");
+       elseif(file_exists("view/en$engine/$s"))
+               return file_get_contents("view/en$engine/$s");
        else
-               return file_get_contents("view/$s");
+               return file_get_contents("view$engine/$s");
 }}
 
 if(! function_exists('get_markup_template')) {
-function get_markup_template($s) {
-       $a=get_app();
+function get_markup_template($s, $root = '') {
+//     $ts = microtime();
+       $a = get_app();
+
+       if($a->theme['template_engine'] === 'smarty3') {
+               $template_file = get_template_file($a, 'smarty3/' . $s, $root);
+
+               $template = new FriendicaSmarty();
+               $template->filename = $template_file;
+
+//             $tt = microtime() - $ts;
+//             $a->page['debug'] .= "$tt <br>\n";
+               return $template;
+       }
+       else {
+               $template_file = get_template_file($a, $s, $root);
+//             $file_contents = file_get_contents($template_file);
+//             $tt = microtime() - $ts;
+//             $a->page['debug'] .= "$tt <br>\n";
+//             return $file_contents;
+               return file_get_contents($template_file);
+       }       
+}}
+
+if(! function_exists("get_template_file")) {
+function get_template_file($a, $filename, $root = '') {
        $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");
+
+       // Make sure $root ends with a slash /
+       if($root !== '' && $root[strlen($root)-1] !== '/')
+               $root = $root . '/';
+
+       if(file_exists("{$root}view/theme/$theme/$filename"))
+               $template_file = "{$root}view/theme/$theme/$filename";
+       elseif (x($a->theme_info,"extends") && file_exists("{$root}view/theme/{$a->theme_info["extends"]}/$filename"))
+               $template_file = "{$root}view/theme/{$a->theme_info["extends"]}/$filename";
        else
-               return file_get_contents("view/$s");
+               $template_file = "{$root}view/$filename";
 
+       return $template_file;
 }}
 
 
@@ -982,19 +1048,33 @@ function prepare_body($item,$attach = false) {
        $s = $prep_arr['html'];
 
        if(! $attach) {
+               // Replace the blockquotes with quotes that are used in mails
+               $mailquote = '<blockquote type="cite" class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">';
+               $s = str_replace(array('<blockquote>', '<blockquote class="spoiler">', '<blockquote class="author">'), array($mailquote, $mailquote, $mailquote), $s);
                return $s;
        }
 
-       $arr = explode(',',$item['attach']);
+       $arr = explode('[/attach],',$item['attach']);
        if(count($arr)) {
                $s .= '<div class="body-attach">';
                foreach($arr as $r) {
                        $matches = false;
                        $icon = '';
-                       $cnt = preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"\[\/attach\]|',$r,$matches, PREG_SET_ORDER);
+                       $cnt = preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches, PREG_SET_ORDER);
                        if($cnt) {
                                foreach($matches as $mtch) {
-                                       $icontype = strtolower(substr($mtch[3],0,strpos($mtch[3],'/')));
+                                       $filetype = strtolower(substr( $mtch[3], 0, strpos($mtch[3],'/') ));
+                                       if($filetype) {
+                                               $filesubtype = strtolower(substr( $mtch[3], strpos($mtch[3],'/') + 1 ));
+                                               $filesubtype = str_replace('.', '-', $filesubtype);
+                                       }
+                                       else {
+                                               $filetype = 'unkn';
+                                               $filesubtype = 'unkn';
+                                       }
+
+                                       $icon = '<div class="attachtype icon s22 type-' . $filetype . ' subtype-' . $filesubtype . '"></div>';
+                                       /*$icontype = strtolower(substr($mtch[3],0,strpos($mtch[3],'/')));
                                        switch($icontype) {
                                                case 'video':
                                                case 'audio':
@@ -1005,7 +1085,8 @@ function prepare_body($item,$attach = false) {
                                                default:
                                                        $icon = '<div class="attachtype icon s22 type-unkn"></div>';
                                                        break;
-                                       }
+                                       }*/
+
                                        $title = ((strlen(trim($mtch[4]))) ? escape_tags(trim($mtch[4])) : escape_tags($mtch[1]));
                                        $title .= ' ' . $mtch[2] . ' ' . t('bytes');
                                        if((local_user() == $item['uid']) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN))