]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
update to v4.0.0; point to local host of SWF
[friendica.git] / include / text.php
index 71504a67e97365cc75973233ebe213e477fd9eb2..7b27d8b86e7a819020871c9f312fdb5f236b07e5 100644 (file)
@@ -15,39 +15,20 @@ if(! function_exists('replace_macros')) {
 /**
  * This is our template processor
  * 
- * @global Template $t
  * @param string|FriendicaSmarty $s the string requiring macro substitution, 
  *                                                                     or an instance of FriendicaSmarty
  * @param array $r key value pairs (search => replace)
  * @return string substituted string
  */
 function replace_macros($s,$r) {
-       global $t;
        
        $stamp1 = microtime(true);
 
        $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);
+       $t = $a->template_engine();
+       $output = $t->replace_macros($s,$r);
 
-               $output = template_unescape($r);
-       }
-       $a = get_app();
        $a->save_timestamp($stamp1, "rendering");
 
        return $output;
@@ -279,7 +260,6 @@ function hex2bin($s) {
 }}
 
 
-
 if(! function_exists('paginate')) {
 /**
  * Automatic pagination.
@@ -583,26 +563,13 @@ function get_markup_template($s, $root = '') {
        $stamp1 = microtime(true);
 
        $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;
-               $a->save_timestamp($stamp1, "rendering");
-
-               return $template;
-       }
-       else {
-               $template_file = get_template_file($a, $s, $root);
-               $a->save_timestamp($stamp1, "rendering");
-
-               $stamp1 = microtime(true);
-               $content = file_get_contents($template_file);
-               $a->save_timestamp($stamp1, "file");
-               return $content;
-
-       }
+       $t = $a->template_engine();
+       
+       $template = $t->get_template_file($s, $root);
+       
+       $a->save_timestamp($stamp1, "file");
+       
+       return $template;
 }}
 
 if(! function_exists("get_template_file")) {
@@ -624,6 +591,8 @@ function get_template_file($a, $filename, $root = '') {
                $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";
+       elseif (file_exists("{$root}/$filename"))
+               $template_file = "{$root}/$filename";
        else
                $template_file = "{$root}view/$filename";
 
@@ -1316,18 +1285,49 @@ function prepare_body($item,$attach = false) {
                return $s;
        }
 
+       $as = '';
+       $vhead = false;
        $arr = explode('[/attach],',$item['attach']);
        if(count($arr)) {
-               $s .= '<div class="body-attach">';
+               $as .= '<div class="body-attach">';
                foreach($arr as $r) {
                        $matches = false;
                        $icon = '';
                        $cnt = preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches, PREG_SET_ORDER);
                        if($cnt) {
                                foreach($matches as $mtch) {
-                                       $filetype = strtolower(substr( $mtch[3], 0, strpos($mtch[3],'/') ));
+                                       $mime = $mtch[3];
+
+                                       if((local_user() == $item['uid']) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN))
+                                               $the_url = $a->get_baseurl() . '/redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1];
+                                       else
+                                               $the_url = $mtch[1];
+
+                                       if(strpos($mime, 'video') !== false) {
+                                               if(!$vhead) {
+                                                       $vhead = true;
+                                                       $a->page['htmlhead'] .= replace_macros(get_markup_template('videos_head.tpl'), array(
+                                                               '$baseurl' => $a->get_baseurl(),
+                                                       ));
+                                                       $a->page['end'] .= replace_macros(get_markup_template('videos_end.tpl'), array(
+                                                               '$baseurl' => $a->get_baseurl(),
+                                                       ));
+                                               }
+
+                                               $id = end(explode('/', $the_url));
+                                               $as .= replace_macros(get_markup_template('video_top.tpl'), array(
+                                                       '$video'        => array(
+                                                               'id'       => $id,
+                                                               'title'         => t('View Video'),
+                                                               'src'           => $the_url,
+                                                               'mime'          => $mime,
+                                                       ),
+                                               ));
+                                       }
+
+                                       $filetype = strtolower(substr( $mime, 0, strpos($mime,'/') ));
                                        if($filetype) {
-                                               $filesubtype = strtolower(substr( $mtch[3], strpos($mtch[3],'/') + 1 ));
+                                               $filesubtype = strtolower(substr( $mime, strpos($mime,'/') + 1 ));
                                                $filesubtype = str_replace('.', '-', $filesubtype);
                                        }
                                        else {
@@ -1351,17 +1351,14 @@ function prepare_body($item,$attach = false) {
 
                                        $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))
-                                               $the_url = $a->get_baseurl() . '/redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1];
-                                       else
-                                               $the_url = $mtch[1];
 
-                                       $s .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="external-link" >' . $icon . '</a>';
+                                       $as .= '<a href="' . strip_tags($the_url) . '" title="' . $title . '" class="attachlink" target="external-link" >' . $icon . '</a>';
                                }
                        }
                }
-               $s .= '<div class="clear"></div></div>';
+               $as .= '<div class="clear"></div></div>';
        }
+       $s = $s . $as;
 
 
        // Look for spoiler
@@ -1694,6 +1691,16 @@ function base64url_decode($s) {
 
 
 if (!function_exists('str_getcsv')) {
+       /**
+        * Parse csv string
+        * 
+        * @param string $input
+        * @param string $delimiter
+        * @param string $enclosure
+        * @param string $escape
+        * @param string $eol
+        * @return boolean|array False on error, otherwise array[row][column]
+        */
     function str_getcsv($input, $delimiter = ',', $enclosure = '"', $escape = '\\', $eol = '\n') {
         if (is_string($input) && !empty($input)) {
             $output = array();
@@ -1750,6 +1757,11 @@ if (!function_exists('str_getcsv')) {
     }
 } 
 
+/**
+ * return div element with class 'clear'
+ * @return string
+ * @deprecated
+ */
 function cleardiv() {
        return '<div class="clear"></div>';
 }
@@ -1786,6 +1798,8 @@ function html2bb_video($s) {
 
 /**
  * apply xmlify() to all values of array $val, recursively
+ * @param array $val
+ * @return array
  */
 function array_xmlify($val){
        if (is_bool($val)) return $val?"true":"false";
@@ -1794,6 +1808,13 @@ function array_xmlify($val){
 }
 
 
+/**
+ * transorm link href and img src from relative to absolute
+ * 
+ * @param string $text
+ * @param string $base base url
+ * @return string
+ */
 function reltoabs($text, $base)
 {
   if (empty($base))
@@ -1826,6 +1847,12 @@ function reltoabs($text, $base)
   return $text;
 }
 
+/**
+ * get translated item type
+ * 
+ * @param array $itme
+ * @return string
+ */
 function item_post_type($item) {
        if(intval($item['event-id']))
                return t('event');