X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ftext.php;h=c8c03174e613625281240e0f0276c74e56d2e630;hb=eec4cff84be630bf3a4165321a423c29ed7926e9;hp=29e53c663512961aad71cd6df60a8ff21e0e43ce;hpb=d2e110abf5c530b6e4f2e32bf8812faa3fa131f2;p=friendica.git
diff --git a/include/text.php b/include/text.php
old mode 100644
new mode 100755
index 29e53c6635..c8c03174e6
--- 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');
@@ -534,8 +546,10 @@ 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;
@@ -635,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;
}}
@@ -667,43 +681,148 @@ 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*'
+ );
+
+ $icons = array(
'
',
'
',
'
',
'
',
- '
',
+// '
',
'
',
+// '
',
'
',
- '
',
+// '
',
'
',
- '
',
+// '
',
+ '
',
'
',
'
',
'
',
'
',
+// '
',
'
',
'
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
'~friendika
',
- '~friendica
',
- 'Diaspora
',
+ '~friendica
',
+// 'Diaspora
',
+
+ );
+
+ $params = array('texts' => $texts, 'icons' => $icons, 'string' => $s);
+ call_hooks('smilie', $params);
- ), $s);
+ 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')) {
@@ -776,10 +895,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]));
@@ -805,7 +924,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;
}}
@@ -892,7 +1014,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 .= '';
}
}
@@ -939,6 +1061,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
@@ -1058,3 +1185,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 = "![](\"")