X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=include%2Ftext.php;h=9dc90ac50ae19723f5803fd1e44e645f1dea9819;hb=5d3613c8bc057392d3d43986357da6dddf60ce85;hp=c1e01343a8cd856134a3d68ca7f45a3975197b5d;hpb=2a404ae6ddab795dd29e1c6a4c616092dc06b443;p=friendica.git
diff --git a/include/text.php b/include/text.php
index c1e01343a8..9dc90ac50a 100644
--- a/include/text.php
+++ b/include/text.php
@@ -6,22 +6,42 @@
// returns substituted string.
// WARNING: this is pretty basic, and doesn't properly handle search strings that are substrings of each other.
// For instance if 'test' => "foo" and 'testing' => "bar", testing could become either bar or fooing,
-// depending on the order in which they were declared in the array.
+// 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')) {
+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
\n";
- return template_unescape($r);
+ $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);
+
+ $output = template_unescape($r);
+ }
+ $a = get_app();
+ $a->save_timestamp($stamp1, "rendering");
+
+ return $output;
}}
@@ -154,10 +174,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 +206,14 @@ function xmlify($str) {
$buffer .= $char;
break;
}
- }
+ }*/
+
+ $buffer = mb_ereg_replace("&", "&", $str);
+ $buffer = mb_ereg_replace("'", "'", $buffer);
+ $buffer = mb_ereg_replace("\"", """, $buffer);
+ $buffer = mb_ereg_replace("<", "<", $buffer);
+ $buffer = mb_ereg_replace(">", ">", $buffer);
+
$buffer = trim($buffer);
return($buffer);
}}
@@ -195,8 +223,13 @@ function xmlify($str) {
if(! function_exists('unxmlify')) {
function unxmlify($s) {
- $ret = str_replace('&','&', $s);
- $ret = str_replace(array('<','>','"','''),array('<','>','"',"'"),$ret);
+// $ret = str_replace('&','&', $s);
+// $ret = str_replace(array('<','>','"','''),array('<','>','"',"'"),$ret);
+ $ret = mb_ereg_replace('&', '&', $s);
+ $ret = mb_ereg_replace(''', "'", $ret);
+ $ret = mb_ereg_replace('"', '"', $ret);
+ $ret = mb_ereg_replace('<', "<", $ret);
+ $ret = mb_ereg_replace('>', ">", $ret);
return $ret;
}}
@@ -292,11 +325,11 @@ function alt_pager(&$a, $i) {
$o .= '
'; + $s = str_replace(array('', '', ''), array($mailquote, $mailquote, $mailquote), $s); return $s; } - $arr = explode(',',$item['attach']); + $arr = explode('[/attach],',$item['attach']); if(count($arr)) { $s .= ''; 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 = ''; + /*$icontype = strtolower(substr($mtch[3],0,strpos($mtch[3],'/'))); switch($icontype) { case 'video': case 'audio': @@ -1002,7 +1147,8 @@ function prepare_body($item,$attach = false) { default: $icon = ''; 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)) @@ -1016,34 +1162,7 @@ function prepare_body($item,$attach = false) { } $s .= ''; } - $matches = false; - $cnt = preg_match_all('/<(.*?)>/',$item['file'],$matches,PREG_SET_ORDER); - if($cnt) { -// logger('prepare_text: categories: ' . print_r($matches,true), LOGGER_DEBUG); - foreach($matches as $mtch) { - if(strlen($x)) - $x .= ','; - $x .= xmlify(file_tag_decode($mtch[1])) - . ((local_user() == $item['uid']) ? ' ' . t('[remove]') . '' : ''); - } - if(strlen($x)) - $s .= ' '; - - } - $matches = false; - $x = ''; - $cnt = preg_match_all('/\[(.*?)\]/',$item['file'],$matches,PREG_SET_ORDER); - if($cnt) { -// logger('prepare_text: filed_under: ' . print_r($matches,true), LOGGER_DEBUG); - foreach($matches as $mtch) { - if(strlen($x)) - $x .= ' '; - $x .= xmlify(file_tag_decode($mtch[1])) . ' ' . t('[remove]') . ''; - } - if(strlen($x) && (local_user() == $item['uid'])) - $s .= ' '; - } // Look for spoiler $spoilersearch = ''; @@ -1098,6 +1217,73 @@ function prepare_text($text) { }} +/** + * returns + * [ + * //categories [ + * { + * 'name': 'category name', + * 'removeurl': 'url to remove this category', + * 'first': 'is the first in this array? true/false', + * 'last': 'is the last in this array? true/false', + * } , + * .... + * ], + * // folders [ + * 'name': 'folder name', + * 'removeurl': 'url to remove this folder', + * 'first': 'is the first in this array? true/false', + * 'last': 'is the last in this array? true/false', + * } , + * .... + * ] + * ] + */ +function get_cats_and_terms($item) { + $a = get_app(); + $categories = array(); + $folders = array(); + + $matches = false; $first = true; + $cnt = preg_match_all('/<(.*?)>/',$item['file'],$matches,PREG_SET_ORDER); + if($cnt) { + foreach($matches as $mtch) { + $categories[] = array( + 'name' => xmlify(file_tag_decode($mtch[1])), + 'url' => "#", + 'removeurl' => ((local_user() == $item['uid'])?$a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&cat=' . xmlify(file_tag_decode($mtch[1])):""), + 'first' => $first, + 'last' => false + ); + $first = false; + } + } + if (count($categories)) $categories[count($categories)-1]['last'] = true; + + + if(local_user() == $item['uid']) { + $matches = false; $first = true; + $cnt = preg_match_all('/\[(.*?)\]/',$item['file'],$matches,PREG_SET_ORDER); + if($cnt) { + foreach($matches as $mtch) { + $folders[] = array( + 'name' => xmlify(file_tag_decode($mtch[1])), + 'url' => "#", + 'removeurl' => ((local_user() == $item['uid'])?$a->get_baseurl() . '/filerm/' . $item['id'] . '?f=&term=' . xmlify(file_tag_decode($mtch[1])):""), + 'first' => $first, + 'last' => false + ); + $first = false; + } + } + } + + if (count($folders)) $folders[count($folders)-1]['last'] = true; + + return array($categories, $folders); +} + + /** * return atom link elements for all of our hubs */