X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ftext.php;h=d6b3ceeab40600ac1c7f54b452c7856c694eeebb;hb=7f2070ca91aca9e92f3ac4c5b714742c6f9ecc3b;hp=fd413b7d65719a581b115cc82adc88f182bbc54a;hpb=7df6cb850efd323e03ea329957273f7d1e3c0323;p=friendica.git diff --git a/include/text.php b/include/text.php index fd413b7d65..d6b3ceeab4 100644 --- a/include/text.php +++ b/include/text.php @@ -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); @@ -462,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 @@ -478,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 @@ -489,6 +492,9 @@ function get_tags($s) { // ignore strictly numeric tags like #1 if((strpos($mtch,'#') === 0) && ctype_digit(substr($mtch,1))) continue; + // try not to catch url fragments + if(strpos($s,$mtch) && preg_match('/[a-zA-z0-9\/]/',substr($s,strpos($s,$mtch)-1,1))) + continue; $ret[] = $mtch; } } @@ -533,7 +539,7 @@ function contact_block() { if((! is_array($a->profile)) || ($a->profile['hide-friends'])) return $o; - $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0", + $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0", intval($a->profile['uid']) ); if(count($r)) { @@ -544,7 +550,7 @@ function contact_block() { $micropro = Null; } else { - $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 ORDER BY RAND() LIMIT %d", + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0 ORDER BY RAND() LIMIT %d", intval($a->profile['uid']), intval($shown) ); @@ -629,7 +635,7 @@ function search($s,$id='search-box',$url='/search',$save = false) { if(! function_exists('valid_email')) { function valid_email($x){ - if(preg_match('/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/',$x)) + if(preg_match('/^[_a-zA-Z0-9\-\+]+(\.[_a-zA-Z0-9\-\+]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/',$x)) return true; return false; }} @@ -668,8 +674,8 @@ function smilies($s) { $a = get_app(); $s = str_replace( - array( '<3', '</3', '<\\3', ':-)', ':)', ';-)', ':-(', ':(', ':-P', ':P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O', - '~friendika', 'Diaspora*' ), + array( '<3', '</3', '<\\3', ':-)', ':)', ';-)', ':-(', ':(', ':-P', ':P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O', '\\o/', + '~friendika', '~friendica', 'Diaspora*' ), array( '<3', '</3', @@ -687,7 +693,9 @@ function smilies($s) { ':-D', '8-|', '8-O', + '\\o/', '~friendika ~friendika', + '~friendica ~friendica', 'DiasporaDiaspora*', ), $s); @@ -748,7 +756,9 @@ function prepare_body($item,$attach = false) { $s = prepare_text($item['body']); - call_hooks('prepare_body', $s); + $prep_arr = array('item' => $item, 'html' => $s); + call_hooks('prepare_body', $prep_arr); + $s = $prep_arr['html']; if(! $attach) return $s; @@ -781,8 +791,11 @@ function prepare_body($item,$attach = false) { } $s .= '
'; } - call_hooks('prepare_body_final', $s); - return $s; + + + $prep_arr = array('item' => $item, 'html' => $s); + call_hooks('prepare_body_final', $prep_arr); + return $prep_arr['html']; }} @@ -1003,3 +1016,46 @@ if (!function_exists('str_getcsv')) { } } } + +function cleardiv() { + return '
'; +} + + +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('#]+>(.*?)https+://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+)(.*?)#ism', + '[youtube]$2[/youtube]', $s); + + $s = preg_replace('#](.*?)https+://www.youtube.com/embed/([A-Za-z0-9\-_=]+)(.*?)#ism', + '[youtube]$2[/youtube]', $s); + + $s = preg_replace('#](.*?)https+://player.vimeo.com/video/([0-9]+)(.*?)#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); +}