X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Ftext.php;h=7ed561bbbbf0d21aae96885e4c85089d1f863dc5;hb=05674206ba9a7c70c5e298e3925d95428abff78e;hp=cf802513c45629ebb2cfe4f3d5aacffd3ebe563e;hpb=4d146acf90376db9b09eaa5c98835be81a55c7f8;p=friendica.git diff --git a/include/text.php b/include/text.php index cf802513c4..7ed561bbbb 100644 --- a/include/text.php +++ b/include/text.php @@ -1,15 +1,20 @@ template_engine(); try { - $output = $t->replace_macros($s, $r); + $output = $t->replaceMacros($s, $r); } catch (Exception $e) { echo "
" . __FUNCTION__ . ": " . $e->getMessage() . "
"; killme(); @@ -41,18 +46,21 @@ function replace_macros($s, $r) { return $output; } +/** + * @brief Generates a pseudo-random string of hexadecimal characters + * + * @param int $size + * @return string + */ +function random_string($size = 64) +{ + $byte_size = ceil($size / 2); -// random string, there are 86 characters max in text mode, 128 for hex -// output is urlsafe + $bytes = random_bytes($byte_size); -define('RANDOM_STRING_HEX', 0x00); -define('RANDOM_STRING_TEXT', 0x01); + $return = substr(bin2hex($bytes), 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); + return $return; } /** @@ -591,7 +599,7 @@ function get_markup_template($s, $root = '') { $a = get_app(); $t = $a->template_engine(); try { - $template = $t->get_template_file($s, $root); + $template = $t->getTemplateFile($s, $root); } catch (Exception $e) { echo "
" . __FUNCTION__ . ": " . $e->getMessage() . "
"; killme(); @@ -987,7 +995,7 @@ function contact_block() { function micropro($contact, $redirect = false, $class = '', $textmode = false) { // Use the contact URL if no address is available - if ($contact["addr"] == "") { + if (!x($contact, "addr")) { $contact["addr"] = $contact["url"]; } @@ -996,7 +1004,6 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) { $redir = false; if ($redirect) { - $a = get_app(); $redirect_url = 'redir/' . $contact['id']; if (local_user() && ($contact['uid'] == local_user()) && ($contact['network'] === NETWORK_DFRN)) { $redir = true; @@ -1013,7 +1020,7 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) { } return replace_macros(get_markup_template(($textmode)?'micropro_txt.tpl':'micropro_img.tpl'),array( - '$click' => (($contact['click']) ? $contact['click'] : ''), + '$click' => defaults($contact, 'click', ''), '$class' => $class, '$url' => $url, '$photo' => proxy_url($contact['thumb'], false, PROXY_SIZE_THUMB), @@ -1034,15 +1041,13 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) { * @param boolean $savedsearch show save search button */ function search($s, $id = 'search-box', $url = 'search', $save = false, $aside = true) { - $a = get_app(); - $values = array( '$s' => htmlspecialchars($s), '$id' => $id, '$action_url' => $url, '$search_label' => t('Search'), '$save_label' => t('Save'), - '$savedsearch' => feature_enabled(local_user(),'savedsearch'), + '$savedsearch' => Feature::isEnabled(local_user(),'savedsearch'), '$search_hint' => t('@name, !forum, #tags, content'), ); @@ -1061,17 +1066,14 @@ function search($s, $id = 'search-box', $url = 'search', $save = false, $aside = } /** - * Check if $x is a valid email string + * @brief Check for a valid email string * - * @param string $x + * @param string $email_address * @return boolean */ -function valid_email($x){ - - /// @TODO Removed because Fabio told me so. - //if (Config::get('system','disable_email_validation')) - // return true; - return preg_match('/^[_a-zA-Z0-9\-\+]+(\.[_a-zA-Z0-9\-\+]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/', $x); +function valid_email($email_address) +{ + return preg_match('/^[_a-zA-Z0-9\-\+]+(\.[_a-zA-Z0-9\-\+]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)+$/', $email_address); } @@ -1111,43 +1113,9 @@ function get_poke_verbs() { return $arr; } -/** - * Load moods - * @return array index is mood, value is translated mood - * @hook mood_verbs moods array - */ -function get_mood_verbs() { - - $arr = array( - 'happy' => t('happy'), - 'sad' => t('sad'), - 'mellow' => t('mellow'), - 'tired' => t('tired'), - 'perky' => t('perky'), - 'angry' => t('angry'), - 'stupefied' => t('stupified'), - 'puzzled' => t('puzzled'), - 'interested' => t('interested'), - 'bitter' => t('bitter'), - 'cheerful' => t('cheerful'), - 'alive' => t('alive'), - 'annoyed' => t('annoyed'), - 'anxious' => t('anxious'), - 'cranky' => t('cranky'), - 'disturbed' => t('disturbed'), - 'frustrated' => t('frustrated'), - 'motivated' => t('motivated'), - 'relaxed' => t('relaxed'), - 'surprised' => t('surprised'), - ); - - call_hooks('mood_verbs', $arr); - return $arr; -} - /** * @brief Translate days and months names. - * + * * @param string $s String with day or month name. * @return string Translated string. */ @@ -1165,13 +1133,13 @@ function day_translate($s) { /** * @brief Translate short days and months names. - * + * * @param string $s String with short day or month name. * @return string Translated string. */ function day_short_translate($s) { $ret = str_replace(array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'), - array(t('Mon'), t('Tue'), t('Wed'), t('Thu'), t('Fri'), t('Sat'), t('Sund')), + array(t('Mon'), t('Tue'), t('Wed'), t('Thu'), t('Fri'), t('Sat'), t('Sun')), $s); $ret = str_replace(array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov','Dec'), array(t('Jan'), t('Feb'), t('Mar'), t('Apr'), t('May'), ('Jun'), t('Jul'), t('Aug'), t('Sep'), t('Oct'), t('Nov'), t('Dec')), @@ -1232,11 +1200,15 @@ function redir_private_images($a, &$item) } } -function put_item_in_cache(&$item, $update = false) { - - if (($item["rendered-hash"] != hash("md5", $item["body"])) || ($item["rendered-hash"] == "") || - ($item["rendered-html"] == "") || Config::get("system", "ignore_cache")) { +function put_item_in_cache(&$item, $update = false) +{ + $rendered_hash = defaults($item, 'rendered-hash', ''); + if ($rendered_hash == '' + || $item["rendered-html"] == "" + || $rendered_hash != hash("md5", $item["body"]) + || Config::get("system", "ignore_cache") + ) { // The function "redir_private_images" changes the body. // I'm not sure if we should store it permanently, so we save the old value. $body = $item["body"]; @@ -1402,7 +1374,7 @@ function prepare_body(&$item, $attach = false, $preview = false) { // Map. if (strpos($s, '
') !== false && x($item, 'coord')) { - $x = generate_map(trim($item['coord'])); + $x = Map::byCoordinates(trim($item['coord'])); if ($x) { $s = preg_replace('/\
/', '$0' . $x, $s); } @@ -1497,9 +1469,8 @@ function prepare_text($text) { * ] * ] */ -function get_cats_and_terms($item) { - - $a = get_app(); +function get_cats_and_terms($item) +{ $categories = array(); $folders = array(); @@ -1731,7 +1702,7 @@ function array_xmlify($val){ /** - * transorm link href and img src from relative to absolute + * transform link href and img src from relative to absolute * * @param string $text * @param string $base base url @@ -1927,9 +1898,10 @@ function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') { function file_tag_save_file($uid, $item, $file) { require_once "include/files.php"; - $result = false; - if (! intval($uid)) + if (! intval($uid)) { return false; + } + $r = q("SELECT `file` FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($item), intval($uid) @@ -1957,9 +1929,9 @@ function file_tag_save_file($uid, $item, $file) { function file_tag_unsave_file($uid, $item, $file, $cat = false) { require_once "include/files.php"; - $result = false; - if (! intval($uid)) + if (! intval($uid)) { return false; + } if ($cat == true) { $pattern = '<' . file_tag_encode($file) . '>' ; @@ -1969,7 +1941,6 @@ function file_tag_unsave_file($uid, $item, $file, $cat = false) { $termtype = TERM_FILE; } - $r = q("SELECT `file` FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($item), intval($uid) @@ -1990,8 +1961,8 @@ function file_tag_unsave_file($uid, $item, $file, $cat = false) { dbesc($file), intval(TERM_OBJ_POST), intval($termtype), - intval($uid)); - + intval($uid) + ); if (!DBM::is_result($r)) { $saved = PConfig::get($uid, 'system', 'filetags'); PConfig::set($uid, 'system', 'filetags', str_replace($pattern, '', $saved)); @@ -2056,7 +2027,7 @@ function deindent($text, $chr = "[\t ]", $count = NULL) { } function formatBytes($bytes, $precision = 2) { - $units = array('B', 'KB', 'MB', 'GB', 'TB'); + $units = array('B', 'KB', 'MB', 'GB', 'TB'); $bytes = max($bytes, 0); $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); @@ -2078,16 +2049,14 @@ function formatBytes($bytes, $precision = 2) { */ function format_network_name($network, $url = 0) { if ($network != "") { - require_once 'include/contact_selectors.php'; if ($url != "") { - $network_name = ''.network_to_name($network, $url).""; + $network_name = ''.ContactSelector::networkToName($network, $url).""; } else { - $network_name = network_to_name($network); + $network_name = ContactSelector::networkToName($network); } return $network_name; } - } /**