From: Hypolite Petovan Date: Sun, 17 Dec 2017 00:21:56 +0000 (-0500) Subject: Replace init_groups_visitor with Group::getIdsByContactId X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e16852c2f5e2668c5f78ccf88f9177d2dd54bc96;p=friendica.git Replace init_groups_visitor with Group::getIdsByContactId --- diff --git a/include/security.php b/include/security.php index e6437db3c3..1a5629f935 100644 --- a/include/security.php +++ b/include/security.php @@ -5,6 +5,7 @@ use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Core\System; use Friendica\Database\DBM; +use Friendica\Model\Group; /** * @brief Calculate the hash that is needed for the "Friendica" cookie @@ -263,7 +264,7 @@ function permissions_sql($owner_id, $remote_verified = false, $groups = null) ); if (DBM::is_result($r)) { $remote_verified = true; - $groups = init_groups_visitor($remote_user); + $groups = Group::getIdsByContactId($remote_user); } } @@ -325,7 +326,7 @@ function item_permissions_sql($owner_id, $remote_verified = false, $groups = nul ); if (DBM::is_result($r)) { $remote_verified = true; - $groups = init_groups_visitor($remote_user); + $groups = Group::getIdsByContactId($remote_user); } } if ($remote_verified) { @@ -424,22 +425,3 @@ function check_form_security_token_ForbiddenOnErr($typename = '', $formname = 'f killme(); } } - -// Returns an array of group id's this contact is a member of. -// This array will only contain group id's related to the uid of this -// DFRN contact. They are *not* neccessarily unique across the entire site. - - -if (! function_exists('init_groups_visitor')) { -function init_groups_visitor($contact_id) { - $groups = array(); - $r = q("SELECT `gid` FROM `group_member` - WHERE `contact-id` = %d ", - intval($contact_id) - ); - if (DBM::is_result($r)) { - foreach ($r as $rr) - $groups[] = $rr['gid']; - } - return $groups; -}} diff --git a/mod/cal.php b/mod/cal.php index cef9857ea9..312489ef72 100644 --- a/mod/cal.php +++ b/mod/cal.php @@ -12,6 +12,7 @@ use Friendica\Core\PConfig; use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Model\Contact; +use Friendica\Model\Group; require_once 'include/event.php'; require_once 'include/redir.php'; @@ -127,7 +128,7 @@ function cal_content(App $a) { } } if($contact_id) { - $groups = init_groups_visitor($contact_id); + $groups = Group::getIdsByContactId($contact_id); $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), intval($a->profile['profile_uid']) diff --git a/mod/display.php b/mod/display.php index 12b10f36f8..67e6f435ec 100644 --- a/mod/display.php +++ b/mod/display.php @@ -5,6 +5,7 @@ use Friendica\Core\Config; use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Model\Contact; +use Friendica\Model\Group; use Friendica\Protocol\DFRN; function display_init(App $a) { @@ -270,7 +271,7 @@ function display_content(App $a, $update = false, $update_uid = 0) { } if ($contact_id) { - $groups = init_groups_visitor($contact_id); + $groups = Group::getIdsByContactId($contact_id); $r = dba::fetch_first("SELECT * FROM `contact` WHERE `id` = ? AND `uid` = ? LIMIT 1", $contact_id, $a->profile['uid'] diff --git a/mod/photos.php b/mod/photos.php index 4741815758..68b9752b5e 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -9,6 +9,7 @@ use Friendica\Core\Config; use Friendica\Core\Worker; use Friendica\Database\DBM; use Friendica\Model\Contact; +use Friendica\Model\Group; use Friendica\Model\Photo; use Friendica\Network\Probe; use Friendica\Object\Image; @@ -1059,7 +1060,7 @@ function photos_content(App $a) { } } if ($contact_id) { - $groups = init_groups_visitor($contact_id); + $groups = Group::getIdsByContactId($contact_id); $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), intval($owner_uid) diff --git a/mod/profile.php b/mod/profile.php index 59835bd4cb..fe2475c7af 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -5,6 +5,7 @@ use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Core\System; use Friendica\Database\DBM; +use Friendica\Model\Group; require_once('include/contact_widgets.php'); require_once('include/redir.php'); @@ -137,7 +138,7 @@ function profile_content(App $a, $update = 0) { } if ($contact_id) { - $groups = init_groups_visitor($contact_id); + $groups = Group::getIdsByContactId($contact_id); $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), intval($a->profile['profile_uid']) diff --git a/mod/videos.php b/mod/videos.php index bb0e0c237f..11b7e21be7 100644 --- a/mod/videos.php +++ b/mod/videos.php @@ -6,6 +6,7 @@ use Friendica\Core\System; use Friendica\Core\Worker; use Friendica\Database\DBM; use Friendica\Model\Contact; +use Friendica\Model\Group; require_once('include/items.php'); require_once('include/acl_selectors.php'); @@ -293,7 +294,7 @@ function videos_content(App $a) { } } if($contact_id) { - $groups = init_groups_visitor($contact_id); + $groups = Group::getIdsByContactId($contact_id); $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1", intval($contact_id), intval($owner_uid) diff --git a/src/Model/Group.php b/src/Model/Group.php index a23b417cc9..db9ec331e4 100644 --- a/src/Model/Group.php +++ b/src/Model/Group.php @@ -61,7 +61,7 @@ class Group extends BaseObject * @param int $cid * @return array */ - private static function getIdsByContactId($cid) + public static function getIdsByContactId($cid) { $condition = ['contact-id' => $cid]; $stmt = dba::select('group_member', ['gid'], $condition); diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index eeedd6324d..070cf598ac 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -14,6 +14,7 @@ use Friendica\Core\Worker; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Model\GContact; +use Friendica\Model\Group; use Friendica\Model\Profile; use Friendica\Model\User; use Friendica\Object\Image; @@ -167,7 +168,7 @@ class DFRN $contact = $r[0]; include_once 'include/security.php'; - $groups = init_groups_visitor($contact['id']); + $groups = Group::getIdsByContactId($contact['id']); if (count($groups)) { for ($x = 0; $x < count($groups); $x ++)