X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=include%2Ftext.php;h=044ee4e085a9cd2dd5045b4793c1d0ddf9c66814;hb=1cfff8fdd11e0e67e2bdb7ae85b9caf8106a734b;hp=78eae145e2c90a8617450e27ea31030cf08a4042;hpb=d284f8017cefb79571fe51c4ae3f85b9b4e517c9;p=friendica.git diff --git a/include/text.php b/include/text.php old mode 100644 new mode 100755 index 78eae145e2..044ee4e085 --- 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); @@ -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"); @@ -421,6 +426,12 @@ function attribute_contains($attr,$s) { if(! function_exists('logger')) { function logger($msg,$level = 0) { + // turn off logger in install mode + global $a; + global $db; + + if(($a->module == 'install') || (! ($db && $db->connected))) return; + $debugging = get_config('system','debugging'); $loglevel = intval(get_config('system','loglevel')); $logfile = get_config('system','logfile'); @@ -460,7 +471,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,19 +487,21 @@ 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 continue; } + if(substr($mtch,-1,1) === '.') + $mtch = substr($mtch,0,-1); // ignore strictly numeric tags like #1 if((strpos($mtch,'#') === 0) && ctype_digit(substr($mtch,1))) continue; - if(substr($mtch,-1,1) === '.') - $ret[] = substr($mtch,0,-1); - else - $ret[] = $mtch; + // 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; } } return $ret; @@ -527,12 +540,14 @@ function contact_block() { $a = get_app(); $shown = get_pconfig($a->profile['uid'],'system','display_friend_count'); - if(! $shown) + if($shown === false) $shown = 24; + if($shown == 0) + return; 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)) { @@ -543,7 +558,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) ); @@ -579,11 +594,13 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) { $url = $contact['url']; $sparkle = ''; + $redir = false; if($redirect) { $a = get_app(); $redirect_url = $a->get_baseurl() . '/redir/' . $contact['id']; if(local_user() && ($contact['uid'] == local_user()) && ($contact['network'] === 'dfrn')) { + $redir = true; $url = $redirect_url; $sparkle = ' sparkle'; } @@ -594,6 +611,7 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) { if($textmode) { return '
'. $contact['name'] . '
' . "\r\n"; @@ -601,6 +619,7 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) { else { return '
' . $contact['name'] 
 			. '
' . "\r\n"; @@ -624,7 +643,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; }} @@ -640,7 +659,8 @@ function valid_email($x){ if(! function_exists('linkify')) { function linkify($s) { - $s = preg_replace("/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'\%\$\!\+]*)/", ' $1', $s); + $s = preg_replace("/(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\'\%\$\!\+]*)/", ' $1', $s); + $s = preg_replace("/\<(.*?)(src|href)=(.*?)\&\;(.*?)\>/ism",'<$1$2=$3&$4>',$s); return($s); }} @@ -658,33 +678,107 @@ function linkify($s) { */ if(! function_exists('smilies')) { -function smilies($s) { +function smilies($s, $sample = false) { $a = get_app(); - return str_replace( - array( '<3', '</3', '<\\3', ':-)', ':)', ';-)', ':-(', ':(', ':-P', ':P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O', - '~friendika', 'Diaspora*' ), - array( + $texts = array( + '<3', + '</3', + '<\\3', + ':-)', +// ':)', + ';-)', +// ';)', + ':-(', +// ':(', + ':-P', +// ':P', + ':-"', + ':-"', + ':-x', + ':-X', + ':-D', +// ':D', + '8-|', + '8-O', + ':-O', + '\\o/', + 'o.O', + 'O.o', + '\\.../', + '\\ooo/', + ":'(", + ":-!", + ":-/", + ":-[", + "8-)", + ':beer', + ':homebrew', + ':coffee', + ':facepalm', + ':headdesk', + '~friendika', + '~friendica', + 'Diaspora*' + ); + + $icons = array( '<3', '</3', '<\\3', ':-)', - ':)', +// ':)', ';-)', +// ';)', ':-(', - ':(', +// ':(', ':-P', - ':P', +// ':P', + ':-\', ':-\', ':-x', ':-X', ':-D', +// ':D', '8-|', '8-O', + ':-O', + '\\o/', + 'o.O', + 'O.o', + '\\.../', + '\\ooo/', + ':\'(', + ':-!', + ':-/', + ':-[', + '8-)', + ':beer', + ':homebrew', + ':coffee', + ':facepalm', + ':headdesk', '~friendika ~friendika', - 'DiasporaDiaspora*', + '~friendica ~friendica', + 'DiasporaDiaspora*', + + ); + + $params = array('texts' => $texts, 'icons' => $icons, 'string' => $s); + call_hooks('smilie', $params); + + if($sample) { + $s = '
'; + for($x = 0; $x < count($params['texts']); $x ++) { + $s .= '
' . $params['texts'][$x] . '
' . $params['icons'][$x] . '
'; + } + } + else { + $s = str_replace($params['texts'],$params['icons'],$params['string']); + } + + return $s; - ), $s); }} @@ -734,7 +828,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; @@ -752,10 +853,10 @@ function prepare_body($item,$attach = false) { case 'audio': case 'image': case 'text': - $icon = '
'; + $icon = '
'; break; default: - $icon = '
'; + $icon = '
'; break; } $title = ((strlen(trim($matches[4]))) ? escape_tags(trim($matches[4])) : escape_tags($matches[1])); @@ -766,7 +867,11 @@ function prepare_body($item,$attach = false) { } $s .= '
'; } - return $s; + + + $prep_arr = array('item' => $item, 'html' => $s); + call_hooks('prepare_body_final', $prep_arr); + return $prep_arr['html']; }} @@ -777,7 +882,10 @@ function prepare_text($text) { require_once('include/bbcode.php'); - $s = smilies(bbcode($text)); + if(stristr($text,'[nosmile]')) + $s = bbcode($text); + else + $s = smilies(bbcode($text)); return $s; }} @@ -826,9 +934,14 @@ function feed_salmonlinks($nick) { if(! function_exists('get_plink')) { function get_plink($item) { $a = get_app(); - $plink = (((x($item,'plink')) && (! $item['private'])) ? '' : ''); - return $plink; + if (x($item,'plink') && (! $item['private'])){ + return array( + 'href' => $item['plink'], + 'title' => t('link to source'), + ); + } else { + return false; + } }} if(! function_exists('unamp')) { @@ -844,16 +957,22 @@ function lang_selector() { global $lang; $o = '
'; $o .= '