]> git.mxchange.org Git - friendica.git/blobdiff - include/text.php
Merge pull request #4195 from zeroadam/ContactSelector-#3878
[friendica.git] / include / text.php
index 73180e8700c763d6ae6d502ab22d3f3975371d45..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);
 }
 
 
@@ -1144,7 +1139,7 @@ function day_translate($s) {
  */
 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')),
@@ -1205,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"];
@@ -1375,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);
                }
@@ -1470,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();
 
@@ -1704,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
@@ -1900,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)
@@ -1930,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) . '>' ;
@@ -1942,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)
@@ -1963,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));
@@ -2029,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));
@@ -2051,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;
        }
-
 }
 
 /**