X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ftext.php;h=f210bff72100c363ee4355fb0a07eed4a86d90f8;hb=602821279a504752f15829afbe7eca848352d0c8;hp=f8bbfcee2436ee224694e65e24d247367419a1b8;hpb=b763c810fb02ba322e9232bfd23da3a04ecd271e;p=friendica.git diff --git a/include/text.php b/include/text.php index f8bbfcee24..f210bff721 100644 --- a/include/text.php +++ b/include/text.php @@ -20,6 +20,10 @@ function replace_macros($s,$r) { $stamp1 = microtime(true); $a = get_app(); + + // pass $baseurl to all templates + $r['$baseurl'] = $a->get_baseurl(); + $t = $a->template_engine(); try { @@ -220,7 +224,7 @@ function xmlify($str) { $buffer = mb_ereg_replace("<", "<", $buffer); $buffer = mb_ereg_replace(">", ">", $buffer); */ - $buffer = htmlspecialchars($str, ENT_QUOTES); + $buffer = htmlspecialchars($str, ENT_QUOTES, "UTF-8"); $buffer = trim($buffer); return($buffer); @@ -470,11 +474,17 @@ if(! function_exists('item_new_uri')) { * @param int $uid * @return string */ -function item_new_uri($hostname,$uid) { +function item_new_uri($hostname,$uid, $guid = "") { do { $dups = false; - $hash = random_string(); + + if ($guid == "") + $hash = get_guid(32); + else { + $hash = $guid; + $guid = ""; + } $uri = "urn:X-dfrn:" . $hostname . ':' . $uid . ':' . $hash; @@ -868,8 +878,14 @@ 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 AND `archive` = 0", - intval($a->profile['uid']) + $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 + AND `network` IN ('%s', '%s', '%s')", + intval($a->profile['uid']), + dbesc(NETWORK_DFRN), + dbesc(NETWORK_OSTATUS), + dbesc(NETWORK_DIASPORA) ); if(count($r)) { $total = intval($r[0]['total']); @@ -879,8 +895,14 @@ 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 AND `archive` = 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 + AND `network` IN ('%s', '%s', '%s') ORDER BY RAND() LIMIT %d", intval($a->profile['uid']), + dbesc(NETWORK_DFRN), + dbesc(NETWORK_OSTATUS), + dbesc(NETWORK_DIASPORA), intval($shown) ); if(count($r)) { @@ -952,7 +974,7 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) { . (($click) ? ' fakelink' : '') . '" ' . (($redir) ? ' target="redir" ' : '') . (($url) ? ' href="' . $url . '"' : '') . $click . ' >' . $contact['name']
+			. proxy_url($contact['micro'], false, PROXY_SIZE_THUMB) . '' . "\r\n"; } }} @@ -968,16 +990,29 @@ if(! function_exists('search')) { * @param string $url search url * @param boolean $savedsearch show save search button */ -function search($s,$id='search-box',$url='/search',$save = false) { +function search($s,$id='search-box',$url='/search',$save = false, $aside = true) { $a = get_app(); - return replace_macros(get_markup_template('searchbox.tpl'), array( - '$s' => $s, - '$id' => $id, - '$action_url' => $a->get_baseurl((stristr($url,'network')) ? true : false) . $url, - '$search_label' => t('Search'), - '$save_label' => t('Save'), - '$savedsearch' => feature_enabled(local_user(),'savedsearch'), - )); + + $values = array( + '$s' => $s, + '$id' => $id, + '$action_url' => $a->get_baseurl((stristr($url,'network')) ? true : false) . $url, + '$search_label' => t('Search'), + '$save_label' => t('Save'), + '$savedsearch' => feature_enabled(local_user(),'savedsearch'), + ); + + if (!$aside) { + $values['$searchoption'] = array( + t("Full Text"), + t("Tags"), + t("Contacts")); + + if (get_config('system','poco_local_search')) + $values['$searchoption'][] = t("Forums"); + } + + return replace_macros(get_markup_template('searchbox.tpl'), $values); }} if(! function_exists('valid_email')) { @@ -989,8 +1024,9 @@ if(! function_exists('valid_email')) { */ function valid_email($x){ - if(get_config('system','disable_email_validation')) - return true; + // Removed because Fabio told me so. + //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; @@ -1138,9 +1174,9 @@ function smilies($s, $sample = false) { ); $icons = array( - '<3', - '</3', - '<\\3', + '<3', + '</3', + '<\\3', ':-)', ';-)', ':-(', @@ -1217,7 +1253,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; } @@ -1379,9 +1415,6 @@ function prepare_body(&$item,$attach = false, $preview = false) { put_item_in_cache($item, true); $s = $item["rendered-html"]; - require_once("mod/proxy.php"); - $s = proxy_parse_html($s); - $prep_arr = array('item' => $item, 'html' => $s, 'preview' => $preview); call_hooks('prepare_body', $prep_arr); $s = $prep_arr['html']; @@ -1474,7 +1507,7 @@ function prepare_body(&$item,$attach = false, $preview = false) { if($x) { $s = preg_replace('/\
/','$0' . $x,$s); } - } + } // Look for spoiler @@ -1676,11 +1709,14 @@ function get_plink($item) { //'href' => $a->get_baseurl()."/display/".$a->user['nickname']."/".$item['id'], 'href' => $a->get_baseurl()."/display/".$item['guid'], 'orig' => $a->get_baseurl()."/display/".$item['guid'], - 'title' => t('link to source'), + 'title' => t('View on separate page'), + 'orig_title' => t('view on separate page'), ); - if (x($item,'plink')) + if (x($item,'plink')) { $ret["href"] = $item['plink']; + $ret["title"] = t('link to source'); + } } elseif (x($item,'plink') && ($item['private'] != 1)) $ret = array( @@ -1707,50 +1743,6 @@ function unamp($s) { }} - - -if(! function_exists('lang_selector')) { -/** - * get html for language selector - * @global string $lang - * @return string - * @template lang_selector.tpl - */ -function lang_selector() { - global $lang; - - $langs = glob('view/*/strings.php'); - - $lang_options = array(); - $selected = ""; - - if(is_array($langs) && count($langs)) { - $langs[] = ''; - if(! in_array('view/en/strings.php',$langs)) - $langs[] = 'view/en/'; - asort($langs); - foreach($langs as $l) { - if($l == '') { - $lang_options[""] = t('default'); - continue; - } - $ll = substr($l,5); - $ll = substr($ll,0,strrpos($ll,'/')); - $selected = (($ll === $lang && (x($_SESSION, 'language'))) ? $ll : $selected); - $lang_options[$ll]=$ll; - } - } - - $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; -}} - - if(! function_exists('return_bytes')) { /** * return number of bytes in size (K, M, G) @@ -1773,7 +1765,7 @@ function return_bytes ($size_str) { function generate_user_guid() { $found = true; do { - $guid = random_string(16); + $guid = get_guid(32); $x = q("SELECT `uid` FROM `user` WHERE `guid` = '%s' LIMIT 1", dbesc($guid) ); @@ -2282,3 +2274,15 @@ function deindent($text, $chr="[\t ]", $count=NULL) { return implode("\n", $lines); } + +function formatBytes($bytes, $precision = 2) { + $units = array('B', 'KB', 'MB', 'GB', 'TB'); + + $bytes = max($bytes, 0); + $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); + $pow = min($pow, count($units) - 1); + + $bytes /= pow(1024, $pow); + + return round($bytes, $precision) . ' ' . $units[$pow]; +}