X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=include%2Ftext.php;h=409d40d59f6155a6a5533e986ff7a29b99ea9329;hb=8b6942c5727a80d85ab4a9fca2d74acb2b7c9739;hp=f204e3f9b97dda32ef1da0a67433d362957eae6e;hpb=5eca42975cdf3fc0e5be2dfdb05ded9d19ed5b7c;p=friendica.git diff --git a/include/text.php b/include/text.php index f204e3f9b9..409d40d59f 100644 --- a/include/text.php +++ b/include/text.php @@ -80,6 +80,9 @@ function escape_tags($string) { if(! function_exists('autoname')) { function autoname($len) { + if($len <= 0) + return ''; + $vowels = array('a','a','ai','au','e','e','e','ee','ea','i','ie','o','ou','u'); if(mt_rand(0,5) == 4) $vowels[] = 'y'; @@ -225,6 +228,9 @@ if(! function_exists('paginate')) { function paginate(&$a) { $o = ''; $stripped = preg_replace('/(&page=[0-9]*)/','',$a->query_string); + +// $stripped = preg_replace('/&zrl=(.*?)([\?&]|$)/ism','',$stripped); + $stripped = str_replace('q=','',$stripped); $stripped = trim($stripped,'/'); $pagenum = $a->pager['page']; @@ -552,7 +558,7 @@ function contact_block() { 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 AND `hidden` = 0", + $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0 AND `archive` = 0", intval($a->profile['uid']) ); if(count($r)) { @@ -563,7 +569,7 @@ function contact_block() { $micropro = Null; } else { - $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", + $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `blocked` = 0 and `pending` = 0 AND `hidden` = 0 AND `archive` = 0 ORDER BY RAND() LIMIT %d", intval($a->profile['uid']), intval($shown) ); @@ -640,7 +646,7 @@ function search($s,$id='search-box',$url='/search',$save = false) { $a = get_app(); $o = '
'; $o .= '
'; - $o .= ''; + $o .= ''; $o .= ''; if($save) $o .= ''; @@ -650,6 +656,10 @@ function search($s,$id='search-box',$url='/search',$save = false) { if(! function_exists('valid_email')) { function valid_email($x){ + + if(get_config('system','disable_email_validation')) + return true; + if(preg_match('/^[_a-zA-Z0-9\-\+]+(\.[_a-zA-Z0-9\-\+]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/',$x)) return true; return false; @@ -725,6 +735,8 @@ function smilies($s, $sample = false) { '\\o/', 'o.O', 'O.o', + 'o_O', + 'O_o', ":'(", ":-!", ":-/", @@ -734,42 +746,48 @@ function smilies($s, $sample = false) { ':homebrew', ':coffee', ':facepalm', + ':like', + ':dislike', '~friendika', '~friendica' ); $icons = array( - '<3', - '</3', - '<\\3', - ':-)', - ';-)', - ':-(', - ':-P', - ':-p', - ':-\', - ':-\', - ':-x', - ':-X', - ':-D', - '8-|', - '8-O', - ':-O', - '\\o/', - 'o.O', - 'O.o', - ':\'(', - ':-!', - ':-/', - ':-[', - '8-)', - ':beer', - ':homebrew', - ':coffee', - ':facepalm', - '~friendika ~friendika', - '~friendica ~friendica' + '<3', + '</3', + '<\\3', + ':-)', + ';-)', + ':-(', + ':-P', + ':-p', + ':-\', + ':-\', + ':-x', + ':-X', + ':-D', + '8-|', + '8-O', + ':-O', + '\\o/', + 'o.O', + 'O.o', + 'o_O', + 'O_o', + ':\'(', + ':-!', + ':-/', + ':-[', + '8-)', + ':beer', + ':homebrew', + ':coffee', + ':facepalm', + ':like', + ':dislike', + '~friendika ~friendika', + '~friendica ~friendica' ); $params = array('texts' => $texts, 'icons' => $icons, 'string' => $s); @@ -809,7 +827,7 @@ function preg_heart($x) { return $x[0]; $t = ''; for($cnt = 0; $cnt < strlen($x[1]); $cnt ++) - $t .= '<3'; + $t .= '<3'; $r = str_replace($x[0],$t,$x[0]); return $r; } @@ -877,6 +895,7 @@ function prepare_body($item,$attach = false) { } else $s = prepare_text($item['body']); + $prep_arr = array('item' => $item, 'html' => $s); call_hooks('prepare_body', $prep_arr); $s = $prep_arr['html']; @@ -891,24 +910,30 @@ function prepare_body($item,$attach = false) { foreach($arr as $r) { $matches = false; $icon = ''; - $cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"\[\/attach\]|',$r,$matches); + $cnt = preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"\[\/attach\]|',$r,$matches, PREG_SET_ORDER); if($cnt) { - $icontype = strtolower(substr($matches[3],0,strpos($matches[3],'/'))); - switch($icontype) { - case 'video': - case 'audio': - case 'image': - case 'text': - $icon = '
'; - break; - default: - $icon = '
'; - break; + foreach($matches as $mtch) { + $icontype = strtolower(substr($mtch[3],0,strpos($mtch[3],'/'))); + switch($icontype) { + case 'video': + case 'audio': + case 'image': + case 'text': + $icon = '
'; + break; + default: + $icon = '
'; + break; + } + $title = ((strlen(trim($mtch[4]))) ? escape_tags(trim($mtch[4])) : escape_tags($mtch[1])); + $title .= ' ' . $mtch[2] . ' ' . t('bytes'); + if((local_user() == $item['uid']) && $item['contact-id'] != $a->contact['id']) + $the_url = $a->get_baseurl() . '/redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1]; + else + $the_url = $mtch[1]; + + $s .= '' . $icon . ''; } - $title = ((strlen(trim($matches[4]))) ? escape_tags(trim($matches[4])) : escape_tags($matches[1])); - $title .= ' ' . $matches[2] . ' ' . t('bytes'); - - $s .= '' . $icon . ''; } } $s .= '
'; @@ -920,7 +945,8 @@ function prepare_body($item,$attach = false) { foreach($matches as $mtch) { if(strlen($x)) $x .= ','; - $x .= xmlify(file_tag_decode($mtch[1])); + $x .= xmlify(file_tag_decode($mtch[1])) + . ((local_user() == $item['uid']) ? ' ' . t('[remove]') . '' : ''); } if(strlen($x)) $s .= '
' . t('Categories:') . ' ' . $x . '
'; @@ -1037,12 +1063,13 @@ function feed_salmonlinks($nick) { if(! function_exists('get_plink')) { function get_plink($item) { $a = get_app(); - if (x($item,'plink') && (! $item['private'])){ + if (x($item,'plink') && ($item['private'] != 1)) { return array( 'href' => $item['plink'], 'title' => t('link to source'), ); - } else { + } + else { return false; } }} @@ -1058,10 +1085,12 @@ function unamp($s) { if(! function_exists('lang_selector')) { function lang_selector() { global $lang; - $o = '
'; - $o .= ''; + + $tpl = get_markup_template("lang_selector.tpl"); + $o = replace_macros($tpl, array( + '$title' => t('Select an alternate language'), + '$langs' => array($lang_options, $selected), + + )); return $o; }} @@ -1226,13 +1260,13 @@ function bb_translate_video($s) { function html2bb_video($s) { - $s = preg_replace('#]+>(.*?)https+://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+)(.*?)#ism', + $s = preg_replace('#]+>(.*?)https?://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+)(.*?)#ism', '[youtube]$2[/youtube]', $s); - $s = preg_replace('#](.*?)https+://www.youtube.com/embed/([A-Za-z0-9\-_=]+)(.*?)#ism', + $s = preg_replace('#](.*?)https?://www.youtube.com/embed/([A-Za-z0-9\-_=]+)(.*?)#ism', '[youtube]$2[/youtube]', $s); - $s = preg_replace('#](.*?)https+://player.vimeo.com/video/([0-9]+)(.*?)#ism', + $s = preg_replace('#](.*?)https?://player.vimeo.com/video/([0-9]+)(.*?)#ism', '[vimeo]$2[/vimeo]', $s); return $s; @@ -1449,12 +1483,16 @@ function file_tag_save_file($uid,$item,$file) { return true; } -function file_tag_unsave_file($uid,$item,$file) { +function file_tag_unsave_file($uid,$item,$file,$cat = false) { $result = false; if(! intval($uid)) return false; - $pattern = '[' . file_tag_encode($file) . ']' ; + if($cat == true) + $pattern = '<' . file_tag_encode($file) . '>' ; + else + $pattern = '[' . file_tag_encode($file) . ']' ; + $r = q("select file from item where id = %d and uid = %d limit 1", intval($item), @@ -1469,13 +1507,14 @@ function file_tag_unsave_file($uid,$item,$file) { intval($uid) ); - $r = q("select file from item where uid = %d " . file_tag_file_query('item',$file), + $r = q("select file from item where uid = %d and deleted = 0 " . file_tag_file_query('item',$file,(($cat) ? 'category' : 'file')), intval($uid) ); if(! count($r)) { $saved = get_pconfig($uid,'system','filetags'); set_pconfig($uid,'system','filetags',str_replace($pattern,'',$saved)); + } return true; } @@ -1496,3 +1535,26 @@ function undo_post_tagging($s) { return $s; } +function fix_mce_lf($s) { + $s = str_replace("\r\n","\n",$s); + return $s; +} + + +function protect_sprintf($s) { + return(str_replace('%','%%',$s)); +} + + +function is_a_date_arg($s) { + $i = intval($s); + if($i > 1900) { + $y = date('Y'); + if($i <= $y+1 && strpos($s,'-') == 4) { + $m = intval(substr($s,5)); + if($m > 0 && $m <= 12) + return true; + } + } + return false; +}