]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
Merge pull request #4195 from zeroadam/ContactSelector-#3878
[friendica.git] / include / text.php
index 3fce67fa1c3502703257c0c9326b0a945bd33d80..7ed561bbbbf0d21aae96885e4c85089d1f863dc5 100644 (file)
@@ -3,15 +3,16 @@
  * @file include/text.php
  */
 use Friendica\App;
+use Friendica\Content\ContactSelector;
 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/friendica_smarty.php";
-require_once "include/map.php";
 require_once "mod/proxy.php";
 require_once "include/conversation.php";
 
@@ -994,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"];
        }
 
@@ -1003,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;
@@ -1020,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),
@@ -1041,8 +1041,6 @@ 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,
@@ -1068,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);
 }
 
 
@@ -1118,40 +1113,6 @@ 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.
  *
@@ -1239,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"];
@@ -1409,7 +1374,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);
                }
@@ -1504,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();
 
@@ -1738,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
@@ -1934,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)
@@ -1964,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) . '>' ;
@@ -1976,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)
@@ -1997,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));
@@ -2063,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));
@@ -2085,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 = '<a href="'.$url.'">'.network_to_name($network, $url)."</a>";
+                       $network_name = '<a href="'.$url.'">'.ContactSelector::networkToName($network, $url)."</a>";
                } else {
-                       $network_name = network_to_name($network);
+                       $network_name = ContactSelector::networkToName($network);
                }
 
                return $network_name;
        }
-
 }
 
 /**