]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
Code standards in api_get_user
[friendica.git] / include / text.php
index 54595452cdbf4b886ead91fcb2c9d72ac6a89ac8..5cc573697dac656f1c97df0e211815dc4a44a24e 100644 (file)
@@ -1,16 +1,19 @@
 <?php
-
+/**
+ * @file include/text.php
+ */
 use Friendica\App;
+use Friendica\Content\Feature;
+use Friendica\Content\Smilies;
 use Friendica\Core\Config;
 use Friendica\Core\PConfig;
 use Friendica\Core\System;
 use Friendica\Database\DBM;
+use Friendica\Util\Map;
 
-require_once "include/template_processor.php";
 require_once "include/friendica_smarty.php";
-require_once "include/Smilies.php";
-require_once "include/map.php";
 require_once "mod/proxy.php";
+require_once "include/conversation.php";
 
 /**
  * This is our template processor
@@ -31,7 +34,7 @@ function replace_macros($s, $r) {
 
        $t = $a->template_engine();
        try {
-               $output = $t->replace_macros($s, $r);
+               $output = $t->replaceMacros($s, $r);
        } catch (Exception $e) {
                echo "<pre><b>" . __FUNCTION__ . "</b>: " . $e->getMessage() . "</pre>";
                killme();
@@ -42,18 +45,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;
 }
 
 /**
@@ -592,7 +598,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 "<pre><b>" . __FUNCTION__ . "</b>: " . $e->getMessage() . "</pre>";
                killme();
@@ -1043,7 +1049,7 @@ function search($s, $id = 'search-box', $url = 'search', $save = false, $aside =
                        '$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'),
                );
 
@@ -1062,17 +1068,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);
 }
 
 
@@ -1112,43 +1115,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.
  */
@@ -1166,13 +1135,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')),
@@ -1403,7 +1372,7 @@ function prepare_body(&$item, $attach = false, $preview = false) {
 
        // Map.
        if (strpos($s, '<div class="map">') !== false && x($item, 'coord')) {
-               $x = generate_map(trim($item['coord']));
+               $x = Map::byCoordinates(trim($item['coord']));
                if ($x) {
                        $s = preg_replace('/\<div class\=\"map\"\>/', '$0' . $x, $s);
                }