]> git.mxchange.org Git - friendica.git/blobdiff - include/Contact.php
Parameter should fit ...
[friendica.git] / include / Contact.php
index 62122de6ce85f078090d29e66af2146456c3e176..8b575bf122bfba5f8c8cc887e01eeeca65600823 100644 (file)
@@ -576,6 +576,11 @@ function get_contact($url, $uid = 0, $no_update = false) {
                // Update the contact every 7 days
                $update_contact = ($contact['avatar-date'] < datetime_convert('','','now -7 days'));
 
+               // We force the update if the avatar is empty
+               if ($contact['avatar'] == '') {
+                       $update_contact = true;
+               }
+
                if (!$update_contact || $no_update) {
                        return $contact_id;
                }
@@ -602,6 +607,10 @@ function get_contact($url, $uid = 0, $no_update = false) {
                $data = array_merge($data, $gcontacts);
        }
 
+       if (!$contact_id && ($data["alias"] != '') && ($data["alias"] != $url)) {
+               $contact_id = get_contact($data["alias"], $uid, true);
+       }
+
        $url = $data["url"];
        if (!$contact_id) {
                dba::insert('contact', array('uid' => $uid, 'created' => datetime_convert(), 'url' => $data["url"],
@@ -653,7 +662,7 @@ function get_contact($url, $uid = 0, $no_update = false) {
 
        update_contact_avatar($data["photo"], $uid, $contact_id);
 
-       $contact = dba::select('contact', array('addr', 'alias', 'name', 'nick', 'keywords', 'location', 'about', 'avatar-date'),
+       $contact = dba::select('contact', array('url', 'nurl', 'addr', 'alias', 'name', 'nick', 'keywords', 'location', 'about', 'avatar-date'),
                                array('id' => $contact_id), array('limit' => 1));
 
        // This condition should always be true
@@ -663,6 +672,8 @@ function get_contact($url, $uid = 0, $no_update = false) {
 
        $updated = array('addr' => $data['addr'],
                        'alias' => $data['alias'],
+                       'url' => $data['url'],
+                       'nurl' => normalise_link($data['url']),
                        'name' => $data['name'],
                        'nick' => $data['nick']);
 
@@ -690,6 +701,44 @@ function get_contact($url, $uid = 0, $no_update = false) {
        return $contact_id;
 }
 
+/**
+ * @brief Checks if the contact is blocked
+ *
+ * @param int $cid contact id
+ *
+ * @return boolean Is the contact blocked?
+ */
+function blockedContact($cid) {
+       if ($cid == 0) {
+               return false;
+       }
+
+       $blocked = dba::select('contact', array('blocked'), array('id' => $cid), array('limit' => 1));
+       if (!dbm::is_result($blocked)) {
+               return false;
+       }
+       return (bool)$blocked['blocked'];
+}
+
+/**
+ * @brief Checks if the contact is hidden
+ *
+ * @param int $cid contact id
+ *
+ * @return boolean Is the contact hidden?
+ */
+function hiddenContact($cid) {
+       if ($cid == 0) {
+               return false;
+       }
+
+       $hidden = dba::select('contact', array('hidden'), array('id' => $cid), array('limit' => 1));
+       if (!dbm::is_result($hidden)) {
+               return false;
+       }
+       return (bool)$hidden['hidden'];
+}
+
 /**
  * @brief Returns posts from a given gcontact
  *
@@ -743,22 +792,25 @@ function posts_from_contact_url(App $a, $contact_url) {
 
        // There are no posts with "uid = 0" with connector networks
        // This speeds up the query a lot
-       $r = q("SELECT `network`, `id` AS `author-id` FROM `contact`
+       $r = q("SELECT `network`, `id` AS `author-id`, `contact-type` FROM `contact`
                WHERE `contact`.`nurl` = '%s' AND `contact`.`uid` = 0",
                dbesc(normalise_link($contact_url)));
-       if (in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, ""))) {
-               $sql = "(`item`.`uid` = 0 OR (`item`.`uid` = %d AND `item`.`private`))";
-       } else {
-               $sql = "`item`.`uid` = %d";
-       }
 
        if (!dbm::is_result($r)) {
                return '';
        }
 
+       if (in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, ""))) {
+               $sql = "(`item`.`uid` = 0 OR (`item`.`uid` = %d AND NOT `item`.`global`))";
+       } else {
+               $sql = "`item`.`uid` = %d";
+       }
+
        $author_id = intval($r[0]["author-id"]);
 
-       $r = q(item_query()." AND `item`.`author-id` = %d AND ".$sql.
+       $contact = ($r[0]["contact-type"] = ACCOUNT_TYPE_COMMUNITY ? 'owner-id' : 'author-id');
+
+       $r = q(item_query()." AND `item`.`".$contact."` = %d AND ".$sql.
                " ORDER BY `item`.`created` DESC LIMIT %d, %d",
                intval($author_id),
                intval(local_user()),