X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ftext.php;h=59fc1500746a5f6b213efc4c3230b0564631a74c;hb=a1a07e7287e9e764912bbd08383cf43503deb9e8;hp=7b43cd34087993682a33952705aada3f369db790;hpb=afb04142ce0ec4f291ed22be6e9f7781a7714628;p=friendica.git diff --git a/include/text.php b/include/text.php index 7b43cd3408..59fc150074 100644 --- a/include/text.php +++ b/include/text.php @@ -19,11 +19,18 @@ function replace_macros($s,$r) { }} -// random hex string, 64 chars max +// random string, there are 86 characters max in text mode, 128 for hex +// output is urlsafe + +define('RANDOM_STRING_HEX', 0x00 ); +define('RANDOM_STRING_TEXT', 0x01 ); if(! function_exists('random_string')) { -function random_string($size = 64) { - return(substr(hash('sha256',uniqid(rand(),true)),0,$size)); +function random_string($size = 64,$type = RANDOM_STRING_HEX) { + // generate a bit of entropy and run it through the whirlpool + $s = hash('whirlpool', (string) rand() . uniqid(rand(),true) . (string) rand(),(($type == RANDOM_STRING_TEXT) ? true : false)); + $s = (($type == RANDOM_STRING_TEXT) ? str_replace("\n","",base64url_encode($s,true)) : $s); + return(substr($s,0,$size)); }} /** @@ -140,7 +147,7 @@ if(! function_exists('xmlify')) { function xmlify($str) { $buffer = ''; - for($x = 0; $x < strlen($str); $x ++) { + for($x = 0; $x < mb_strlen($str); $x ++) { $char = $str[$x]; switch( $char ) { @@ -188,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); @@ -381,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"); @@ -453,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 @@ -469,19 +481,18 @@ 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; + $ret[] = $mtch; } } return $ret; @@ -532,22 +543,30 @@ function contact_block() { $total = intval($r[0]['total']); } if(! $total) { - $o .= '

' . t('No contacts') . '

'; - return $o; - } - $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 ORDER BY RAND() LIMIT %d", - intval($a->profile['uid']), - intval($shown) - ); - if(count($r)) { - $o .= '

' . sprintf( tt('%d Contact','%d Contacts', $total),$total) . '

'; - foreach($r as $rr) { - $o .= micropro($rr,true,'mpfriend'); - } - $o .= '
'; - $o .= '
' . t('View Contacts') . '
'; + $contacts = t('No contacts'); + $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", + intval($a->profile['uid']), + intval($shown) + ); + if(count($r)) { + $contacts = sprintf( tt('%d Contact','%d Contacts', $total),$total); + $micropro = Array(); + foreach($r as $rr) { + $micropro[] = micropro($rr,true,'mpfriend'); + } + } } + + $tpl = get_markup_template('contact_block.tpl'); + $o = replace_macros($tpl, array( + '$contacts' => $contacts, + '$nickname' => $a->profile['nickname'], + '$viewcontacts' => t('View Contacts'), + '$micropro' => $micropro, + )); $arr = array('contacts' => $r, 'output' => $o); @@ -564,11 +583,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'; } @@ -579,6 +600,7 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) { if($textmode) { return '
'. $contact['name'] . '
' . "\r\n"; @@ -586,6 +608,7 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) { else { return '
' . $contact['name'] 
 			. '
' . "\r\n"; @@ -595,12 +618,14 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) { if(! function_exists('search')) { -function search($s,$id='search-box',$url='/search') { +function search($s,$id='search-box',$url='/search',$save = false) { $a = get_app(); $o = '
'; $o .= '
'; $o .= ''; $o .= ''; + if($save) + $o .= ''; $o .= '
'; return $o; }} @@ -613,32 +638,6 @@ function valid_email($x){ }} -if(! function_exists('aes_decrypt')) { -function aes_decrypt($val,$ky) -{ - $key="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; - for($a=0;$a=0 and ord(substr($dec, strlen($dec)-1,1))<=16)? chr(ord( substr($dec,strlen($dec)-1,1))):null)); -}} - - -if(! function_exists('aes_encrypt')) { -function aes_encrypt($val,$ky) -{ - $key="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; - for($a=0;$a$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); }} @@ -670,8 +670,9 @@ if(! function_exists('smilies')) { function smilies($s) { $a = get_app(); - return str_replace( - array( '<3', '</3', '<\\3', ':-)', ':)', ';-)', ':-(', ':(', ':-P', ':P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O', '~friendika' ), + $s = str_replace( + array( '<3', '</3', '<\\3', ':-)', ':)', ';-)', ':-(', ':(', ':-P', ':P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O', + '~friendika', '~friendica', 'Diaspora*' ), array( '<3', '</3', @@ -690,8 +691,14 @@ function smilies($s) { '8-|', '8-O', '~friendika ~friendika', + '~friendica ~friendica', + 'DiasporaDiaspora*', ), $s); + + call_hooks('smilie', $s); + return $s; + }} @@ -741,7 +748,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; @@ -773,7 +787,19 @@ function prepare_body($item,$attach = false) { } $s .= '
'; } - return $s; + + $arr = explode(',',$item['tag']); + if(count($arr)) { + $s .= '
'; + foreach($arr as $r) { + $s .= bbcode($r) . ' '; + } + $s .= '
'; + } + + $prep_arr = array('item' => $item, 'html' => $s); + call_hooks('prepare_body_final', $prep_arr); + return $prep_arr['html']; }} @@ -833,9 +859,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')) { @@ -851,16 +882,22 @@ function lang_selector() { global $lang; $o = '
'; $o .= '