X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ftext.php;h=501121c80227418a21f641d363754be8a5112ce4;hb=d7243be2eaab96f56ae639b1afe823a1646811f4;hp=0641689d5091d3ac049fac54af66b300c9d7a7dc;hpb=06408664db04cd1cac255d21e7bab54e6ba0c047;p=friendica.git diff --git a/include/text.php b/include/text.php index 0641689d50..501121c802 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 ) { @@ -475,13 +482,12 @@ function get_tags($s) { // 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; @@ -564,11 +570,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 +587,7 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) { if($textmode) { return '
'. $contact['name'] . '
' . "\r\n"; @@ -586,6 +595,7 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) { else { return '
' . $contact['name'] 
 			. '
' . "\r\n"; @@ -595,12 +605,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 +625,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,7 +657,7 @@ if(! function_exists('smilies')) { function smilies($s) { $a = get_app(); - return str_replace( + $s = str_replace( array( '<3', '</3', '<\\3', ':-)', ':)', ';-)', ':-(', ':(', ':-P', ':P', ':-"', ':-x', ':-X', ':-D', '8-|', '8-O', '~friendika', 'Diaspora*' ), array( @@ -694,6 +681,10 @@ function smilies($s) { 'DiasporaDiaspora*', ), $s); + + call_hooks('smilie', $s); + return $s; + }} @@ -896,20 +887,6 @@ function generate_user_guid() { } -function pkcs5_pad ($text, $blocksize) -{ - $pad = $blocksize - (strlen($text) % $blocksize); - return $text . str_repeat(chr($pad), $pad); -} - -function pkcs5_unpad($text) -{ - $pad = ord($text{strlen($text)-1}); - if ($pad > strlen($text)) return false; - if (strspn($text, chr($pad), strlen($text) - $pad) != $pad) return false; - return substr($text, 0, -1 * $pad); -} - function base64url_encode($s, $strip_padding = false) { @@ -941,3 +918,7 @@ function base64url_decode($s) { return base64_decode(strtr($s,'-_','+/')); } + +function cc_license() { +return '
' . t('Shared content is covered by the Creative Commons Attribution 3.0 license.') . '
'; +}