X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ftext.php;h=e7c95d35c995341386298fcd8044a2b6ed30d285;hb=67456bad067dd06c5775979c07c25c767164da36;hp=08803cc9b7be5b54bb7f4b9ceb8b6e980e520939;hpb=962467ee686046434e6ad060863eabb55fef2652;p=friendica.git
diff --git a/include/text.php b/include/text.php
index 08803cc9b7..e7c95d35c9 100644
--- a/include/text.php
+++ b/include/text.php
@@ -14,7 +14,13 @@ if(! function_exists('replace_macros')) {
function replace_macros($s,$r) {
global $t;
- return $t->replace($s,$r);
+ //$ts = microtime();
+ $r = $t->replace($s,$r);
+ //$tt = microtime() - $ts;
+
+ //$a = get_app();
+ //$a->page['debug'] .= "$tt
\n";
+ return $r;
}}
@@ -426,6 +432,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');
@@ -492,6 +504,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;
}
}
@@ -531,12 +546,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)) {
@@ -547,7 +564,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)
);
@@ -632,7 +649,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;
}}
@@ -664,43 +681,152 @@ function linkify($s) {
* @Parameter: string $s
*
* Returns string
+ *
+ * It is expected that this function will be called using HTML text.
+ * We will escape text between HTML pre and code blocks from being
+ * processed.
+ *
+ * At a higher level, the bbcode [nosmile] tag can be used to prevent this
+ * function from being executed by the prepare_text() routine when preparing
+ * bbcode source for HTML display
+ *
*/
if(! function_exists('smilies')) {
-function smilies($s) {
+function smilies($s, $sample = false) {
$a = get_app();
- $s = str_replace(
- array( '<3', '</3', '<\\3', ':-)', ':)', ';-)', ':-(', ':(', ':-P', ':P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O',
- '~friendika', '~friendica', 'Diaspora*' ),
- array(
+ $s = preg_replace_callback('/
(.*?)<\/pre>/ism','smile_encode',$s);
+ $s = preg_replace_callback('/(.*?)<\/code>/ism','smile_encode',$s);
+
+ $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*'
+ ':beard',
+ ':whitebeard'
+
+ );
+
+ $icons = array(
'
',
'
',
'
',
'
',
- '
',
+// '
',
'
',
+// '
',
'
',
- '
',
+// '
',
'
',
- '
',
+// '
',
+ '
',
'
',
'
',
'
',
'
',
+// '
',
'
',
'
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
'~friendika
',
- '~friendica
',
- 'Diaspora
',
+ '~friendica
',
+// 'Diaspora
',
+ '
',
+ '
'
+ );
- ), $s);
+ $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 {
+ $params['string'] = preg_replace_callback('/<(3+)/','preg_heart',$params['string']);
+ $s = str_replace($params['texts'],$params['icons'],$params['string']);
+ }
+
+ $s = preg_replace_callback('/(.*?)<\/pre>/ism','smile_decode',$s);
+ $s = preg_replace_callback('/(.*?)<\/code>/ism','smile_decode',$s);
- call_hooks('smilie', $s);
return $s;
}}
+function smile_encode($m) {
+ return(str_replace($m[1],base64url_encode($m[1]),$m[0]));
+}
+
+function smile_decode($m) {
+ return(str_replace($m[1],base64url_decode($m[1]),$m[0]));
+}
+
+// expand <3333 to the correct number of hearts
+
+function preg_heart($x) {
+ $a = get_app();
+ if(strlen($x[1]) == 1)
+ return $x[0];
+ $t = '';
+ for($cnt = 0; $cnt < strlen($x[1]); $cnt ++)
+ $t .= '
';
+ $r = str_replace($x[0],$t,$x[0]);
+ return $r;
+}
if(! function_exists('day_translate')) {
@@ -773,10 +899,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]));
@@ -802,7 +928,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;
}}
@@ -889,7 +1018,7 @@ function lang_selector() {
}
$ll = substr($l,5);
$ll = substr($ll,0,strrpos($ll,'/'));
- $selected = (($ll === $lang && (x($_SESSION['language']))) ? ' selected="selected" ' : '');
+ $selected = (($ll === $lang && (x($_SESSION, 'language'))) ? ' selected="selected" ' : '');
$o .= '';
}
}
@@ -936,6 +1065,11 @@ function base64url_encode($s, $strip_padding = false) {
function base64url_decode($s) {
+ if(is_array($s)) {
+ logger('base64url_decode: illegal input: ' . print_r(debug_backtrace(), true));
+ return $s;
+ }
+
/*
* // Placeholder for new rev of salmon which strips base64 padding.
* // PHP base64_decode handles the un-padded input without requiring this step
@@ -1055,3 +1189,50 @@ function array_xmlify($val){
if (is_array($val)) return array_map('array_xmlify', $val);
return xmlify((string) $val);
}
+
+
+function reltoabs($text, $base)
+{
+ if (empty($base))
+ return $text;
+
+ $base = rtrim($base,'/');
+
+ $base2 = $base . "/";
+
+ // Replace links
+ $pattern = "/]*) href=\"(?!http|https|\/)([^\"]*)\"/";
+ $replace = "]*) href=\"(?!http|https)([^\"]*)\"/";
+ $replace = "]*) src=\"(?!http|https|\/)([^\"]*)\"/";
+ $replace = "
]*) src=\"(?!http|https)([^\"]*)\"/";
+ $replace = "![](\"")