1
0
Fork 0

Replace init_groups_visitor with Group::getIdsByContactId

This commit is contained in:
Hypolite Petovan 2017-12-16 19:21:56 -05:00
parent 09467be02a
commit e16852c2f5
8 changed files with 16 additions and 28 deletions

View file

@ -5,6 +5,7 @@ use Friendica\Core\Config;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Group;
/** /**
* @brief Calculate the hash that is needed for the "Friendica" cookie * @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)) { if (DBM::is_result($r)) {
$remote_verified = true; $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)) { if (DBM::is_result($r)) {
$remote_verified = true; $remote_verified = true;
$groups = init_groups_visitor($remote_user); $groups = Group::getIdsByContactId($remote_user);
} }
} }
if ($remote_verified) { if ($remote_verified) {
@ -424,22 +425,3 @@ function check_form_security_token_ForbiddenOnErr($typename = '', $formname = 'f
killme(); 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;
}}

View file

@ -12,6 +12,7 @@ use Friendica\Core\PConfig;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Group;
require_once 'include/event.php'; require_once 'include/event.php';
require_once 'include/redir.php'; require_once 'include/redir.php';
@ -127,7 +128,7 @@ function cal_content(App $a) {
} }
} }
if($contact_id) { 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", $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($contact_id), intval($contact_id),
intval($a->profile['profile_uid']) intval($a->profile['profile_uid'])

View file

@ -5,6 +5,7 @@ use Friendica\Core\Config;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Protocol\DFRN; use Friendica\Protocol\DFRN;
function display_init(App $a) { function display_init(App $a) {
@ -270,7 +271,7 @@ function display_content(App $a, $update = false, $update_uid = 0) {
} }
if ($contact_id) { 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", $r = dba::fetch_first("SELECT * FROM `contact` WHERE `id` = ? AND `uid` = ? LIMIT 1",
$contact_id, $contact_id,
$a->profile['uid'] $a->profile['uid']

View file

@ -9,6 +9,7 @@ use Friendica\Core\Config;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Object\Image; use Friendica\Object\Image;
@ -1059,7 +1060,7 @@ function photos_content(App $a) {
} }
} }
if ($contact_id) { 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", $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
intval($contact_id), intval($contact_id),
intval($owner_uid) intval($owner_uid)

View file

@ -5,6 +5,7 @@ use Friendica\Core\Config;
use Friendica\Core\PConfig; use Friendica\Core\PConfig;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Group;
require_once('include/contact_widgets.php'); require_once('include/contact_widgets.php');
require_once('include/redir.php'); require_once('include/redir.php');
@ -137,7 +138,7 @@ function profile_content(App $a, $update = 0) {
} }
if ($contact_id) { 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", $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($contact_id), intval($contact_id),
intval($a->profile['profile_uid']) intval($a->profile['profile_uid'])

View file

@ -6,6 +6,7 @@ use Friendica\Core\System;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\Group;
require_once('include/items.php'); require_once('include/items.php');
require_once('include/acl_selectors.php'); require_once('include/acl_selectors.php');
@ -293,7 +294,7 @@ function videos_content(App $a) {
} }
} }
if($contact_id) { 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", $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
intval($contact_id), intval($contact_id),
intval($owner_uid) intval($owner_uid)

View file

@ -61,7 +61,7 @@ class Group extends BaseObject
* @param int $cid * @param int $cid
* @return array * @return array
*/ */
private static function getIdsByContactId($cid) public static function getIdsByContactId($cid)
{ {
$condition = ['contact-id' => $cid]; $condition = ['contact-id' => $cid];
$stmt = dba::select('group_member', ['gid'], $condition); $stmt = dba::select('group_member', ['gid'], $condition);

View file

@ -14,6 +14,7 @@ use Friendica\Core\Worker;
use Friendica\Database\DBM; use Friendica\Database\DBM;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Model\Group;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Object\Image; use Friendica\Object\Image;
@ -167,7 +168,7 @@ class DFRN
$contact = $r[0]; $contact = $r[0];
include_once 'include/security.php'; include_once 'include/security.php';
$groups = init_groups_visitor($contact['id']); $groups = Group::getIdsByContactId($contact['id']);
if (count($groups)) { if (count($groups)) {
for ($x = 0; $x < count($groups); $x ++) for ($x = 0; $x < count($groups); $x ++)