From 37253656e3f1403b25c5f0fee6c9631140c4507a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Wed, 25 Jul 2018 04:53:46 +0200 Subject: [PATCH] Moved CONTACT_* constants to Friendica\Model\Contact class, lesser in global namespace (#5490) * Rewrite: - moved all CONTACT_* constants from boot.php to Contact class * CR request: - renamed Contact::CONTACT_IS_* -> Contact::* ;-) --- boot.php | 19 +++-------------- include/api.php | 6 +++--- include/conversation.php | 2 +- include/security.php | 5 +++-- mod/contacts.php | 31 ++++++++++++++++++---------- mod/dfrn_confirm.php | 26 +++++++++++------------ mod/dfrn_notify.php | 2 +- mod/dfrn_request.php | 2 +- mod/follow.php | 2 +- mod/network.php | 8 ++++---- mod/pubsub.php | 3 ++- mod/repair_ostatus.php | 8 ++++---- mod/salmon.php | 2 +- mod/unfollow.php | 6 +++--- src/Core/ACL.php | 4 ++-- src/Model/Contact.php | 43 +++++++++++++++++++++++++-------------- src/Model/Item.php | 7 +++++-- src/Model/Profile.php | 5 +++-- src/Network/Probe.php | 3 ++- src/Protocol/DFRN.php | 8 ++++---- src/Protocol/Diaspora.php | 36 ++++++++++++++++---------------- src/Protocol/OStatus.php | 6 +++--- src/Worker/Cron.php | 3 ++- src/Worker/Delivery.php | 2 +- src/Worker/Notifier.php | 5 +++-- src/Worker/OnePoll.php | 13 ++++++------ 26 files changed, 139 insertions(+), 118 deletions(-) diff --git a/boot.php b/boot.php index 767f4eae61..426d0b1d79 100644 --- a/boot.php +++ b/boot.php @@ -152,19 +152,6 @@ define('REGISTER_OPEN', 2); * @} */ -/** - * @name Contact_is - * - * Relationship types - * @{ - */ -define('CONTACT_IS_FOLLOWER', 1); -define('CONTACT_IS_SHARING', 2); -define('CONTACT_IS_FRIEND', 3); -/** - * @} - */ - /** * @name Update * @@ -181,10 +168,10 @@ define('UPDATE_FAILED', 1); * @name page/profile types * * PAGE_NORMAL is a typical personal profile account - * PAGE_SOAPBOX automatically approves all friend requests as CONTACT_IS_SHARING, (readonly) - * PAGE_COMMUNITY automatically approves all friend requests as CONTACT_IS_SHARING, but with + * PAGE_SOAPBOX automatically approves all friend requests as Contact::SHARING, (readonly) + * PAGE_COMMUNITY automatically approves all friend requests as Contact::SHARING, but with * write access to wall and comments (no email and not included in page owner's ACL lists) - * PAGE_FREELOVE automatically approves all friend requests as full friends (CONTACT_IS_FRIEND). + * PAGE_FREELOVE automatically approves all friend requests as full friends (Contact::FRIEND). * * @{ */ diff --git a/include/api.php b/include/api.php index 35e2c480cc..c00578cdf0 100644 --- a/include/api.php +++ b/include/api.php @@ -753,7 +753,7 @@ function api_get_user(App $a, $contact_id = null) 'contributors_enabled' => false, 'is_translator' => false, 'is_translation_enabled' => false, - 'following' => (($uinfo[0]['rel'] == CONTACT_IS_FOLLOWER) || ($uinfo[0]['rel'] == CONTACT_IS_FRIEND)), + 'following' => (($uinfo[0]['rel'] == Contact::FOLLOWER) || ($uinfo[0]['rel'] == Contact::FRIEND)), 'follow_request_sent' => false, 'statusnet_blocking' => false, 'notifications' => false, @@ -3186,9 +3186,9 @@ function api_statuses_f($qtype) $sql_extra = ''; if ($qtype == 'friends') { - $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_SHARING), intval(CONTACT_IS_FRIEND)); + $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(Contact::SHARING), intval(Contact::FRIEND)); } elseif ($qtype == 'followers') { - $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(CONTACT_IS_FOLLOWER), intval(CONTACT_IS_FRIEND)); + $sql_extra = sprintf(" AND ( `rel` = %d OR `rel` = %d ) ", intval(Contact::FOLLOWER), intval(Contact::FRIEND)); } // friends and followers only for self diff --git a/include/conversation.php b/include/conversation.php index 93788399aa..89bc4b5478 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -866,7 +866,7 @@ function item_photo_menu($item) { $menu[L10n::t("Poke")] = $poke_link; } - if ((($cid == 0) || ($rel == CONTACT_IS_FOLLOWER)) && + if ((($cid == 0) || ($rel == Contact::FOLLOWER)) && in_array($item['network'], [NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA])) { $menu[L10n::t('Connect/Follow')] = 'follow?url=' . urlencode($item['author-link']); } diff --git a/include/security.php b/include/security.php index cd24279119..82cac3f97c 100644 --- a/include/security.php +++ b/include/security.php @@ -9,6 +9,7 @@ use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\Model\Contact; use Friendica\Model\Group; use Friendica\Util\DateTimeFormat; @@ -241,8 +242,8 @@ function can_write_wall($owner) AND `user`.`blockwall` = 0 AND `readonly` = 0 AND ( `contact`.`rel` IN ( %d , %d ) OR `user`.`page-flags` = %d ) LIMIT 1", intval($owner), intval($cid), - intval(CONTACT_IS_SHARING), - intval(CONTACT_IS_FRIEND), + intval(Contact::SHARING), + intval(Contact::FRIEND), intval(PAGE_COMMUNITY) ); diff --git a/mod/contacts.php b/mod/contacts.php index 52363d742c..ae23974e03 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -514,18 +514,21 @@ function contacts_content(App $a) $dir_icon = ''; $relation_text = ''; switch ($contact['rel']) { - case CONTACT_IS_FRIEND: + case Contact::FRIEND: $dir_icon = 'images/lrarrow.gif'; $relation_text = L10n::t('You are mutual friends with %s'); break; - case CONTACT_IS_FOLLOWER; + + case Contact::FOLLOWER; $dir_icon = 'images/larrow.gif'; $relation_text = L10n::t('You are sharing with %s'); break; - case CONTACT_IS_SHARING; + + case Contact::SHARING; $dir_icon = 'images/rarrow.gif'; $relation_text = L10n::t('%s is sharing with you'); break; + default: break; } @@ -590,10 +593,10 @@ function contacts_content(App $a) $follow = ''; $follow_text = ''; if (in_array($contact['network'], [NETWORK_DIASPORA, NETWORK_OSTATUS, NETWORK_DFRN])) { - if ($contact['rel'] == CONTACT_IS_FOLLOWER) { + if ($contact['rel'] == Contact::FOLLOWER) { $follow = System::baseUrl(true) . "/follow?url=" . urlencode($contact["url"]); $follow_text = L10n::t("Connect/Follow"); - } elseif ($contact['rel'] == CONTACT_IS_FRIEND) { + } elseif ($contact['rel'] == Contact::FRIEND) { $follow = System::baseUrl(true) . "/unfollow?url=" . urlencode($contact["url"]); $follow_text = L10n::t("Disconnect/Unfollow"); } @@ -781,7 +784,7 @@ function contacts_content(App $a) $sql_extra .= sprintf(" AND network = '%s' ", DBA::escape($nets)); } - $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ", intval($sort_type)) : ''); + $sql_extra2 = ((($sort_type > 0) && ($sort_type <= Contact::FRIEND)) ? sprintf(" AND `rel` = %d ", intval($sort_type)) : ''); $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ", @@ -905,11 +908,12 @@ function contacts_tab($a, $contact_id, $active_tab) return $tab_str; } -function contact_posts($a, $contact_id) +function contact_posts(App $a, $contact_id) { $o = contacts_tab($a, $contact_id, 1); $contact = DBA::selectFirst('contact', ['url'], ['id' => $contact_id]); + if (DBA::isResult($contact)) { $a->page['aside'] = ""; Profile::load($a, "", 0, Contact::getDetailsByURL($contact["url"])); @@ -919,28 +923,33 @@ function contact_posts($a, $contact_id) return $o; } -function _contact_detail_for_template($rr) +function _contact_detail_for_template(array $rr) { $dir_icon = ''; $alt_text = ''; + switch ($rr['rel']) { - case CONTACT_IS_FRIEND: + case Contact::FRIEND: $dir_icon = 'images/lrarrow.gif'; $alt_text = L10n::t('Mutual Friendship'); break; - case CONTACT_IS_FOLLOWER; + + case Contact::FOLLOWER; $dir_icon = 'images/larrow.gif'; $alt_text = L10n::t('is a fan of yours'); break; - case CONTACT_IS_SHARING; + + case Contact::SHARING; $dir_icon = 'images/rarrow.gif'; $alt_text = L10n::t('you are a fan of'); break; + default: break; } $url = Contact::magicLink($rr['url']); + if (strpos($url, 'redir/') === 0) { $sparkle = ' class="sparkle" '; } else { diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index a2871b3b39..f2d9dd8385 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -305,12 +305,12 @@ function dfrn_confirm_post(App $a, $handsfree = null) logger('dfrn_confirm: confirm - imported photos'); if ($network === NETWORK_DFRN) { - $new_relation = CONTACT_IS_FOLLOWER; - if (($relation == CONTACT_IS_SHARING) || ($duplex)) { - $new_relation = CONTACT_IS_FRIEND; + $new_relation = Contact::FOLLOWER; + if (($relation == Contact::SHARING) || ($duplex)) { + $new_relation = Contact::FRIEND; } - if (($relation == CONTACT_IS_SHARING) && ($duplex)) { + if (($relation == Contact::SHARING) && ($duplex)) { $duplex = 0; } @@ -347,12 +347,12 @@ function dfrn_confirm_post(App $a, $handsfree = null) if ($network === NETWORK_DIASPORA) { if ($duplex) { - $new_relation = CONTACT_IS_FRIEND; + $new_relation = Contact::FRIEND; } else { - $new_relation = CONTACT_IS_FOLLOWER; + $new_relation = Contact::FOLLOWER; } - if ($new_relation != CONTACT_IS_FOLLOWER) { + if ($new_relation != Contact::FOLLOWER) { $writable = 1; } } @@ -391,7 +391,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) // reload contact info $contact = DBA::selectFirst('contact', [], ['id' => $contact_id]); - if ((isset($new_relation) && $new_relation == CONTACT_IS_FRIEND)) { + if ((isset($new_relation) && $new_relation == Contact::FRIEND)) { if (DBA::isResult($contact) && ($contact['network'] === NETWORK_DIASPORA)) { $ret = Diaspora::sendShare($user, $contact); logger('share returns: ' . $ret); @@ -547,12 +547,12 @@ function dfrn_confirm_post(App $a, $handsfree = null) logger('dfrn_confirm: request - photos imported'); - $new_relation = CONTACT_IS_SHARING; - if (($relation == CONTACT_IS_FOLLOWER) || ($duplex)) { - $new_relation = CONTACT_IS_FRIEND; + $new_relation = Contact::SHARING; + if (($relation == Contact::FOLLOWER) || ($duplex)) { + $new_relation = Contact::FRIEND; } - if (($relation == CONTACT_IS_FOLLOWER) && ($duplex)) { + if (($relation == Contact::FOLLOWER) && ($duplex)) { $duplex = 0; } @@ -598,7 +598,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) $combined = $r[0]; if ($combined['notify-flags'] & NOTIFY_CONFIRM) { - $mutual = ($new_relation == CONTACT_IS_FRIEND); + $mutual = ($new_relation == Contact::FRIEND); notification([ 'type' => NOTIFY_CONFIRM, 'notify_flags' => $combined['notify-flags'], diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index 6f03bc6c15..3595df9c91 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -375,7 +375,7 @@ function dfrn_notify_content(App $a) { $rino = $rino_remote; } - if (($r[0]['rel'] && ($r[0]['rel'] != CONTACT_IS_SHARING)) || ($r[0]['page-flags'] == PAGE_COMMUNITY)) { + if (($r[0]['rel'] && ($r[0]['rel'] != Contact::SHARING)) || ($r[0]['page-flags'] == PAGE_COMMUNITY)) { $perm = 'rw'; } else { $perm = 'r'; diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index ede469e1ff..566ee152b1 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -309,7 +309,7 @@ function dfrn_request_post(App $a) if (strlen($ret[0]['issued-id'])) { notice(L10n::t('You have already introduced yourself here.') . EOL); return; - } elseif ($ret[0]['rel'] == CONTACT_IS_FRIEND) { + } elseif ($ret[0]['rel'] == Contact::FRIEND) { notice(L10n::t('Apparently you are already friends with %s.', $a->profile['name']) . EOL); return; } else { diff --git a/mod/follow.php b/mod/follow.php index df1977aba9..6f938ebbbe 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -65,7 +65,7 @@ function follow_content(App $a) $r = q("SELECT `pending` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND `network` != '%s' LIMIT 1", - intval(local_user()), DBA::escape(CONTACT_IS_FOLLOWER), DBA::escape(NETWORK_DFRN), DBA::escape(normalise_link($url)), + intval(local_user()), DBA::escape(Contact::FOLLOWER), DBA::escape(NETWORK_DFRN), DBA::escape(normalise_link($url)), DBA::escape(normalise_link($url)), DBA::escape($url), DBA::escape(NETWORK_STATUSNET)); if ($r) { diff --git a/mod/network.php b/mod/network.php index aec992756d..b96ba96e17 100644 --- a/mod/network.php +++ b/mod/network.php @@ -776,8 +776,8 @@ function networkThreadedView(App $a, $update, $parent) AND NOT `item`.`moderated` AND $sql_extra4 $sql_extra3 $sql_extra $sql_range $sql_nets ORDER BY `order_date` DESC LIMIT 100", - intval(CONTACT_IS_SHARING), - intval(CONTACT_IS_FRIEND), + intval(Contact::SHARING), + intval(Contact::FRIEND), intval(local_user()), intval(local_user()) ); @@ -796,8 +796,8 @@ function networkThreadedView(App $a, $update, $parent) AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) $sql_extra2 $sql_extra3 $sql_range $sql_extra $sql_nets ORDER BY `order_date` DESC $pager_sql", - intval(CONTACT_IS_SHARING), - intval(CONTACT_IS_FRIEND), + intval(Contact::SHARING), + intval(Contact::FRIEND), intval(local_user()), intval(local_user()) ); diff --git a/mod/pubsub.php b/mod/pubsub.php index 5fc40f83d8..ef97bb7f7f 100644 --- a/mod/pubsub.php +++ b/mod/pubsub.php @@ -2,6 +2,7 @@ use Friendica\App; use Friendica\Database\DBA; +use Friendica\Model\Contact; use Friendica\Protocol\OStatus; require_once('include/security.php'); @@ -113,7 +114,7 @@ function pubsub_post(App $a) } } - if (!in_array($contact['rel'], [CONTACT_IS_SHARING, CONTACT_IS_FRIEND]) && ($contact['network'] != NETWORK_FEED)) { + if (!in_array($contact['rel'], [Contact::SHARING, Contact::FRIEND]) && ($contact['network'] != NETWORK_FEED)) { logger('Contact ' . $contact['id'] . ' is not expected to share with us - ignored.'); hub_post_return(); } diff --git a/mod/repair_ostatus.php b/mod/repair_ostatus.php index 44d9fbd44a..7531ad35c2 100644 --- a/mod/repair_ostatus.php +++ b/mod/repair_ostatus.php @@ -29,8 +29,8 @@ function repair_ostatus_content(App $a) { `uid` = %d AND `network` = '%s' AND `rel` IN (%d, %d)", intval($uid), DBA::escape(NETWORK_OSTATUS), - intval(CONTACT_IS_FRIEND), - intval(CONTACT_IS_SHARING)); + intval(Contact::FRIEND), + intval(Contact::SHARING)); if (!$r) return($o.L10n::t("Error")); @@ -43,8 +43,8 @@ function repair_ostatus_content(App $a) { LIMIT %d, 1", intval($uid), DBA::escape(NETWORK_OSTATUS), - intval(CONTACT_IS_FRIEND), - intval(CONTACT_IS_SHARING), $counter++); + intval(Contact::FRIEND), + intval(Contact::SHARING), $counter++); if (!$r) { $o .= L10n::t("Done"); diff --git a/mod/salmon.php b/mod/salmon.php index becdd74753..d1f9cf9a31 100644 --- a/mod/salmon.php +++ b/mod/salmon.php @@ -171,7 +171,7 @@ function salmon_post(App $a, $xml = '') { // Have we ignored the person? // If so we can not accept this post. - //if((DBA::isResult($r)) && (($r[0]['readonly']) || ($r[0]['rel'] == CONTACT_IS_FOLLOWER) || ($r[0]['blocked']))) { + //if((DBA::isResult($r)) && (($r[0]['readonly']) || ($r[0]['rel'] == Contact::FOLLOWER) || ($r[0]['blocked']))) { if (DBA::isResult($r) && $r[0]['blocked']) { logger('Ignoring this author.'); System::httpExit(202); diff --git a/mod/unfollow.php b/mod/unfollow.php index e926533609..f4e4316d6a 100644 --- a/mod/unfollow.php +++ b/mod/unfollow.php @@ -27,7 +27,7 @@ function unfollow_post(App $a) $return_url = $_SESSION['return_url']; $condition = ["`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?", - $uid, CONTACT_IS_FRIEND, normalise_link($url), + $uid, Contact::FRIEND, normalise_link($url), normalise_link($url), $url, NETWORK_STATUSNET]; $contact = DBA::selectFirst('contact', [], $condition); @@ -43,7 +43,7 @@ function unfollow_post(App $a) Contact::terminateFriendship($r[0], $contact); } } - DBA::update('contact', ['rel' => CONTACT_IS_FOLLOWER], ['id' => $contact['id']]); + DBA::update('contact', ['rel' => Contact::FOLLOWER], ['id' => $contact['id']]); info(L10n::t('Contact unfollowed').EOL); goaway(System::baseUrl().'/contacts/'.$contact['id']); @@ -66,7 +66,7 @@ function unfollow_content(App $a) $submit = L10n::t('Submit Request'); $condition = ["`uid` = ? AND `rel` = ? AND (`nurl` = ? OR `alias` = ? OR `alias` = ?) AND `network` != ?", - local_user(), CONTACT_IS_FRIEND, normalise_link($url), + local_user(), Contact::FRIEND, normalise_link($url), normalise_link($url), $url, NETWORK_STATUSNET]; $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition); diff --git a/src/Core/ACL.php b/src/Core/ACL.php index 415978bae0..99bda66a5d 100644 --- a/src/Core/ACL.php +++ b/src/Core/ACL.php @@ -75,7 +75,7 @@ class ACL extends BaseObject $sql_extra = ''; if (!empty($x['mutual'])) { - $sql_extra .= sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND)); + $sql_extra .= sprintf(" AND `rel` = %d ", intval(Contact::FRIEND)); } if (!empty($x['exclude'])) { @@ -151,7 +151,7 @@ class ACL extends BaseObject // When used for private messages, we limit correspondence to mutual DFRN/Friendica friends and the selector // to one recipient. By default our selector allows multiple selects amongst all contacts. - $sql_extra = sprintf(" AND `rel` = %d ", intval(CONTACT_IS_FRIEND)); + $sql_extra = sprintf(" AND `rel` = %d ", intval(Contact::FRIEND)); $sql_extra .= sprintf(" AND `network` IN ('%s' , '%s') ", NETWORK_DFRN, NETWORK_DIASPORA); $tabindex_attr = !empty($tabindex) ? ' tabindex="' . intval($tabindex) . '"' : ''; diff --git a/src/Model/Contact.php b/src/Model/Contact.php index b9164837a1..90c30ef93f 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -30,6 +30,19 @@ require_once 'include/text.php'; */ class Contact extends BaseObject { + /** + * @name Contact_is + * + * Relationship types + * @{ + */ + const FOLLOWER = 1; + const SHARING = 2; + const FRIEND = 3; + /** + * @} + */ + /** * @brief Returns a list of contacts belonging in a group * @@ -849,7 +862,7 @@ class Contact extends BaseObject 'about' => $data["about"], 'network' => $data["network"], 'pubkey' => $data["pubkey"], - 'rel' => CONTACT_IS_SHARING, + 'rel' => self::SHARING, 'priority' => $data["priority"], 'batch' => $data["batch"], 'request' => $data["request"], @@ -1374,12 +1387,12 @@ class Contact extends BaseObject if (DBA::isResult($r)) { // update contact - $new_relation = (($r[0]['rel'] == CONTACT_IS_FOLLOWER) ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING); + $new_relation = (($r[0]['rel'] == self::FOLLOWER) ? self::FRIEND : self::SHARING); $fields = ['rel' => $new_relation, 'subhub' => $subhub, 'readonly' => false]; DBA::update('contact', $fields, ['id' => $r[0]['id']]); } else { - $new_relation = ((in_array($ret['network'], [NETWORK_MAIL])) ? CONTACT_IS_FRIEND : CONTACT_IS_SHARING); + $new_relation = ((in_array($ret['network'], [NETWORK_MAIL])) ? self::FRIEND : self::SHARING); // create contact record DBA::insert('contact', [ @@ -1500,9 +1513,9 @@ class Contact extends BaseObject } if (is_array($contact)) { - if (($contact['rel'] == CONTACT_IS_SHARING) - || ($sharing && $contact['rel'] == CONTACT_IS_FOLLOWER)) { - DBA::update('contact', ['rel' => CONTACT_IS_FRIEND, 'writable' => true], + if (($contact['rel'] == self::SHARING) + || ($sharing && $contact['rel'] == self::FOLLOWER)) { + DBA::update('contact', ['rel' => self::FRIEND, 'writable' => true], ['id' => $contact['id'], 'uid' => $importer['uid']]); } // send email notification to owner? @@ -1524,7 +1537,7 @@ class Contact extends BaseObject DBA::escape($nick), DBA::escape($photo), DBA::escape(NETWORK_OSTATUS), - intval(CONTACT_IS_FOLLOWER) + intval(self::FOLLOWER) ); $contact_record = [ @@ -1580,19 +1593,19 @@ class Contact extends BaseObject } } - public static function removeFollower($importer, $contact, array $datarray = [], $item = "") { - - if (($contact['rel'] == CONTACT_IS_FRIEND) || ($contact['rel'] == CONTACT_IS_SHARING)) { - DBA::update('contact', ['rel' => CONTACT_IS_SHARING], ['id' => $contact['id']]); + public static function removeFollower($importer, $contact, array $datarray = [], $item = "") + { + if (($contact['rel'] == self::FRIEND) || ($contact['rel'] == self::SHARING)) { + DBA::update('contact', ['rel' => self::SHARING], ['id' => $contact['id']]); } else { Contact::remove($contact['id']); } } - public static function removeSharer($importer, $contact, array $datarray = [], $item = "") { - - if (($contact['rel'] == CONTACT_IS_FRIEND) || ($contact['rel'] == CONTACT_IS_FOLLOWER)) { - DBA::update('contact', ['rel' => CONTACT_IS_FOLLOWER], ['id' => $contact['id']]); + public static function removeSharer($importer, $contact, array $datarray = [], $item = "") + { + if (($contact['rel'] == self::FRIEND) || ($contact['rel'] == self::FOLLOWER)) { + DBA::update('contact', ['rel' => self::FOLLOWER], ['id' => $contact['id']]); } else { Contact::remove($contact['id']); } diff --git a/src/Model/Item.php b/src/Model/Item.php index 8c803fff96..e2dc28e833 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -15,6 +15,7 @@ use Friendica\Core\PConfig; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\Model\Contact; use Friendica\Object\Image; use Friendica\Protocol\Diaspora; use Friendica\Protocol\OStatus; @@ -600,7 +601,7 @@ class Item extends BaseObject STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = $master_table.`author-id` AND NOT `author`.`blocked` STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = $master_table.`owner-id` AND NOT `owner`.`blocked` LEFT JOIN `user-item` ON `user-item`.`iid` = $master_table_key AND `user-item`.`uid` = %d", - CONTACT_IS_SHARING, CONTACT_IS_FRIEND, GRAVITY_PARENT, intval($uid)); + Contact::SHARING, Contact::FRIEND, GRAVITY_PARENT, intval($uid)); } else { if (strpos($sql_commands, "`contact`.") !== false) { $joins .= "LEFT JOIN `contact` ON `contact`.`id` = $master_table.`contact-id`"; @@ -2025,8 +2026,10 @@ class Item extends BaseObject $users = []; $condition = ["`nurl` IN (SELECT `nurl` FROM `contact` WHERE `id` = ?) AND `uid` != 0 AND NOT `blocked` AND `rel` IN (?, ?)", - $parent['owner-id'], CONTACT_IS_SHARING, CONTACT_IS_FRIEND]; + $parent['owner-id'], Contact::SHARING, Contact::FRIEND]; + $contacts = DBA::select('contact', ['uid'], $condition); + while ($contact = DBA::fetch($contacts)) { $users[$contact['uid']] = $contact['uid']; } diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 1bd7a97027..15ad83ed85 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -16,6 +16,7 @@ use Friendica\Core\PConfig; use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\Model\Contact; use Friendica\Protocol\Diaspora; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; @@ -340,14 +341,14 @@ class Profile "SELECT `url` FROM `contact` WHERE `uid` = %d AND `id` = '%s' AND `rel` = %d", intval($profile['uid']), intval(remote_user()), - intval(CONTACT_IS_FRIEND) + intval(Contact::FRIEND) ); } else { $r = q( "SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d", intval($profile['uid']), DBA::escape(normalise_link(self::getMyURL())), - intval(CONTACT_IS_FRIEND) + intval(Contact::FRIEND) ); } if ($r) { diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 3ad33662a7..385ab9dec1 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -14,6 +14,7 @@ use Friendica\Core\Cache; use Friendica\Core\Config; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\Model\Contact; use Friendica\Model\Profile; use Friendica\Protocol\Email; use Friendica\Protocol\Feed; @@ -447,7 +448,7 @@ class Probe 'pubkey' => $data['pubkey'], 'priority' => $data['priority'], 'writable' => true, - 'rel' => CONTACT_IS_SHARING]; + 'rel' => Contact::SHARING]; $fieldnames = []; diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 928f44e9c7..eda85023fd 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -1260,7 +1260,7 @@ class DFRN if (($contact['duplex'] && strlen($contact['pubkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey'])) - || ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey'])) + || ($contact['rel'] == Contact::SHARING && strlen($contact['pubkey'])) ) { openssl_public_decrypt($sent_dfrn_id, $final_dfrn_id, $contact['pubkey']); openssl_public_decrypt($challenge, $postvars['challenge'], $contact['pubkey']); @@ -1288,7 +1288,7 @@ class DFRN $postvars['dissolve'] = '1'; } - if ((($contact['rel']) && ($contact['rel'] != CONTACT_IS_SHARING) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) { + if ((($contact['rel']) && ($contact['rel'] != Contact::SHARING) && (! $contact['blocked'])) || ($owner['page-flags'] == PAGE_COMMUNITY)) { $postvars['data'] = $atom; $postvars['perm'] = 'rw'; } else { @@ -1323,7 +1323,7 @@ class DFRN if ($dfrn_version >= 2.1) { if (($contact['duplex'] && strlen($contact['pubkey'])) || ($owner['page-flags'] == PAGE_COMMUNITY && strlen($contact['pubkey'])) - || ($contact['rel'] == CONTACT_IS_SHARING && strlen($contact['pubkey'])) + || ($contact['rel'] == Contact::SHARING && strlen($contact['pubkey'])) ) { openssl_public_encrypt($key, $postvars['key'], $contact['pubkey']); } else { @@ -2712,7 +2712,7 @@ class DFRN $item["owner-id"] = Contact::getIdForURL($importer["url"], 0); } - if (($importer["rel"] == CONTACT_IS_FOLLOWER) && (!self::tgroupCheck($importer["importer_uid"], $item))) { + if (($importer["rel"] == Contact::FOLLOWER) && (!self::tgroupCheck($importer["importer_uid"], $item))) { logger("Contact ".$importer["id"]." is only follower and tgroup check was negative.", LOGGER_DEBUG); return; } diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index c0b57dafaf..372f8a6f7f 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -177,7 +177,7 @@ class Diaspora 'name' => 'relay', 'nick' => 'relay', 'url' => $server_url, 'network' => NETWORK_DIASPORA, 'batch' => $server_url . '/receive/public', - 'rel' => CONTACT_IS_FOLLOWER, 'blocked' => false, + 'rel' => Contact::FOLLOWER, 'blocked' => false, 'pending' => false, 'writable' => true]; $fields = array_merge($fields, $network_fields); @@ -1079,14 +1079,14 @@ class Diaspora */ // It is deactivated by now, due to side effects. See issue https://github.com/friendica/friendica/pull/4033 // It is not removed by now. Possibly the code is needed? - //if (!$is_comment && $contact["rel"] == CONTACT_IS_FOLLOWER && in_array($importer["page-flags"], array(PAGE_FREELOVE))) { + //if (!$is_comment && $contact["rel"] == Contact::FOLLOWER && in_array($importer["page-flags"], array(PAGE_FREELOVE))) { // dba::update( // 'contact', - // array('rel' => CONTACT_IS_FRIEND, 'writable' => true), + // array('rel' => Contact::FRIEND, 'writable' => true), // array('id' => $contact["id"], 'uid' => $contact["uid"]) // ); // - // $contact["rel"] = CONTACT_IS_FRIEND; + // $contact["rel"] = Contact::FRIEND; // logger("defining user ".$contact["nick"]." as friend"); //} @@ -1095,11 +1095,11 @@ class Diaspora // Maybe blocked, don't accept. return false; // We are following this person? - } elseif (($contact["rel"] == CONTACT_IS_SHARING) || ($contact["rel"] == CONTACT_IS_FRIEND)) { + } elseif (($contact["rel"] == Contact::SHARING) || ($contact["rel"] == Contact::FRIEND)) { // Yes, then it is fine. return true; // Is it a post to a community? - } elseif (($contact["rel"] == CONTACT_IS_FOLLOWER) && in_array($importer["page-flags"], [PAGE_COMMUNITY, PAGE_PRVGROUP])) { + } elseif (($contact["rel"] == Contact::FOLLOWER) && in_array($importer["page-flags"], [PAGE_COMMUNITY, PAGE_PRVGROUP])) { // That's good return true; // Is the message a global user or a comment? @@ -2305,10 +2305,10 @@ class Diaspora { $a = get_app(); - if ($contact["rel"] == CONTACT_IS_SHARING) { + if ($contact["rel"] == Contact::SHARING) { DBA::update( 'contact', - ['rel' => CONTACT_IS_FRIEND, 'writable' => true], + ['rel' => Contact::FRIEND, 'writable' => true], ['id' => $contact["id"], 'uid' => $importer["uid"]] ); } @@ -2359,7 +2359,7 @@ class Diaspora // If we are now friends, we are sending a share message. // Normally we needn't to do so, but the first message could have been vanished. - if (in_array($contact["rel"], [CONTACT_IS_FRIEND])) { + if (in_array($contact["rel"], [Contact::FRIEND])) { $u = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($importer["uid"])); if ($u) { logger("Sending share message to author ".$author." - Contact: ".$contact["id"]." - User: ".$importer["uid"], LOGGER_DEBUG); @@ -2455,16 +2455,16 @@ class Diaspora Contact::updateAvatar($contact_record["photo"], $importer["uid"], $contact_record["id"]); - // technically they are sharing with us (CONTACT_IS_SHARING), + // technically they are sharing with us (Contact::SHARING), // but if our page-type is PAGE_COMMUNITY or PAGE_SOAPBOX // we are going to change the relationship and make them a follower. if (($importer["page-flags"] == PAGE_FREELOVE) && $sharing && $following) { - $new_relation = CONTACT_IS_FRIEND; + $new_relation = Contact::FRIEND; } elseif (($importer["page-flags"] == PAGE_FREELOVE) && $sharing) { - $new_relation = CONTACT_IS_SHARING; + $new_relation = Contact::SHARING; } else { - $new_relation = CONTACT_IS_FOLLOWER; + $new_relation = Contact::FOLLOWER; } $r = q( @@ -3269,13 +3269,15 @@ class Diaspora /* switch ($contact["rel"]) { - case CONTACT_IS_FRIEND: + case Contact::FRIEND: $following = true; $sharing = true; - case CONTACT_IS_SHARING: + + case Contact::SHARING: $following = false; $sharing = true; - case CONTACT_IS_FOLLOWER: + + case Contact::FOLLOWER: $following = true; $sharing = false; } @@ -4131,7 +4133,7 @@ class Diaspora AND `uid` = %d AND `rel` != %d", DBA::escape(NETWORK_DIASPORA), intval($uid), - intval(CONTACT_IS_SHARING) + intval(Contact::SHARING) ); } diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 7c6f7f1ce4..33d251fd61 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -76,7 +76,7 @@ class OStatus if ($aliaslink != '') { $condition = ["`uid` = ? AND `alias` = ? AND `network` != ? AND `rel` IN (?, ?)", $importer["uid"], $aliaslink, NETWORK_STATUSNET, - CONTACT_IS_SHARING, CONTACT_IS_FRIEND]; + Contact::SHARING, Contact::FRIEND]; $contact = DBA::selectFirst('contact', [], $condition); } @@ -87,14 +87,14 @@ class OStatus $condition = ["`uid` = ? AND `nurl` IN (?, ?) AND `network` != ? AND `rel` IN (?, ?)", $importer["uid"], normalise_link($author["author-link"]), normalise_link($aliaslink), - NETWORK_STATUSNET, CONTACT_IS_SHARING, CONTACT_IS_FRIEND]; + NETWORK_STATUSNET, Contact::SHARING, Contact::FRIEND]; $contact = DBA::selectFirst('contact', [], $condition); } if (!DBA::isResult($contact) && ($addr != '')) { $condition = ["`uid` = ? AND `addr` = ? AND `network` != ? AND `rel` IN (?, ?)", $importer["uid"], $addr, NETWORK_STATUSNET, - CONTACT_IS_SHARING, CONTACT_IS_FRIEND]; + Contact::SHARING, Contact::FRIEND]; $contact = DBA::selectFirst('contact', [], $condition); } diff --git a/src/Worker/Cron.php b/src/Worker/Cron.php index b28c421619..edd3e22ef4 100644 --- a/src/Worker/Cron.php +++ b/src/Worker/Cron.php @@ -9,6 +9,7 @@ use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\Worker; use Friendica\Database\DBA; +use Friendica\Model\Contact; use Friendica\Util\DateTimeFormat; require_once 'include/dba.php'; @@ -221,7 +222,7 @@ class Cron } // Check Diaspora contacts or followers once a week - if (($contact["network"] == NETWORK_DIASPORA) || ($contact["rel"] == CONTACT_IS_FOLLOWER)) { + if (($contact["network"] == NETWORK_DIASPORA) || ($contact["rel"] == Contact::FOLLOWER)) { $contact['priority'] = 4; } diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index 022faa2d7a..a996f85fee 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -424,7 +424,7 @@ class Delivery extends BaseObject // only expose our real email address to true friends - if (($contact['rel'] == CONTACT_IS_FRIEND) && !$contact['blocked']) { + if (($contact['rel'] == Contact::FRIEND) && !$contact['blocked']) { if ($reply_to) { $headers = 'From: ' . Email::encodeHeader($local_user['username'],'UTF-8') . ' <' . $reply_to.'>' . "\n"; $headers .= 'Sender: ' . $local_user['email'] . "\n"; diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 61b05a1b19..a1ac094116 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -442,7 +442,7 @@ class Notifier AND `uid` = %d AND `rel` != %d AND NOT `blocked` AND NOT `pending` AND NOT `archive` GROUP BY `batch`", DBA::escape(NETWORK_DIASPORA), intval($owner['uid']), - intval(CONTACT_IS_SHARING) + intval(Contact::SHARING) ); // Fetch the participation list @@ -456,7 +456,8 @@ class Notifier } $condition = ['network' => NETWORK_DFRN, 'uid' => $owner['uid'], 'blocked' => false, - 'pending' => false, 'archive' => false, 'rel' => [CONTACT_IS_FOLLOWER, CONTACT_IS_FRIEND]]; + 'pending' => false, 'archive' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]; + $r2 = DBA::toArray(DBA::select('contact', ['id', 'name', 'network'], $condition)); $r = array_merge($r2, $r1); diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index 890d066826..b3af0b7018 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -68,9 +68,10 @@ class OnePoll } // Diaspora users, archived users and followers are only checked if they still exist. - if ($contact['archive'] || ($contact["network"] == NETWORK_DIASPORA) || ($contact["rel"] == CONTACT_IS_FOLLOWER)) { + if ($contact['archive'] || ($contact["network"] == NETWORK_DIASPORA) || ($contact["rel"] == Contact::FOLLOWER)) { $last_updated = PortableContact::lastUpdated($contact["url"], true); $updated = DateTimeFormat::utcNow(); + if ($last_updated) { logger('Contact '.$contact['id'].' had last update on '.$last_updated, LOGGER_DEBUG); @@ -87,6 +88,7 @@ class OnePoll Contact::markForArchival($contact); logger('Contact '.$contact['id'].' is marked for archival', LOGGER_DEBUG); } + return; } @@ -197,7 +199,6 @@ class OnePoll logger('handshake with url ' . $url . ' returns xml: ' . $handshake_xml, LOGGER_DATA); - if (!strlen($handshake_xml) || ($html_code >= 400) || !$html_code) { logger("$url appears to be dead - marking for death "); @@ -296,7 +297,7 @@ class OnePoll // Will only do this once per notify-enabled OStatus contact // or if relationship changes - $stat_writeable = ((($contact['notify']) && ($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['rel'] == CONTACT_IS_FRIEND)) ? 1 : 0); + $stat_writeable = ((($contact['notify']) && ($contact['rel'] == Contact::FOLLOWER || $contact['rel'] == Contact::FRIEND)) ? 1 : 0); // Contacts from OStatus are always writable if ($contact['network'] === NETWORK_OSTATUS) { @@ -310,7 +311,7 @@ class OnePoll // Are we allowed to import from this person? - if ($contact['rel'] == CONTACT_IS_FOLLOWER || $contact['blocked']) { + if ($contact['rel'] == Contact::FOLLOWER || $contact['blocked']) { // set the last-update so we don't keep polling DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]); return; @@ -330,7 +331,6 @@ class OnePoll $xml = $ret['body']; } elseif ($contact['network'] === NETWORK_MAIL) { - logger("Mail: Fetching for ".$contact['addr'], LOGGER_DEBUG); $mail_disabled = ((function_exists('imap_open') && (! Config::get('system', 'imap_disabled'))) ? 0 : 1); @@ -371,6 +371,7 @@ class OnePoll logger("Mail: Parsing ".count($msgs)." mails from ".$contact['addr']." for ".$mailconf['user'], LOGGER_DEBUG); $metas = Email::messageMeta($mbox, implode(',', $msgs)); + if (count($metas) != count($msgs)) { logger("for " . $mailconf['user'] . " there are ". count($msgs) . " messages but received " . count($metas) . " metas", LOGGER_DEBUG); } else { @@ -602,7 +603,7 @@ class OnePoll logger("Contact ".$contact['id']." returned hub: ".$hub." Network: ".$contact['network']." Relation: ".$contact['rel']." Update: ".$hub_update); - if (strlen($hub) && $hub_update && (($contact['rel'] != CONTACT_IS_FOLLOWER) || $contact['network'] == NETWORK_FEED)) { + if (strlen($hub) && $hub_update && (($contact['rel'] != Contact::FOLLOWER) || $contact['network'] == NETWORK_FEED)) { logger('hub ' . $hubmode . ' : ' . $hub . ' contact name : ' . $contact['name'] . ' local user : ' . $importer['name']); $hubs = explode(',', $hub); if (count($hubs)) {