X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=inline;f=include%2Fgroup.php;h=8956d21c311d57df24a8a98a0704b119c5e66b45;hb=e6e8ebbac5ec0b7d93c164c2ffd4c6c80fb845fc;hp=53c0b78d841b5854f1eb08604a3c69aef0d2aad0;hpb=68286910a319dc52662833142a02f651826d273e;p=friendica.git
diff --git a/include/group.php b/include/group.php
index 53c0b78d84..8956d21c31 100644
--- a/include/group.php
+++ b/include/group.php
@@ -4,9 +4,9 @@
function group_add($uid,$name) {
$ret = false;
- if(x($uid) && x($name)) {
+ if (x($uid) && x($name)) {
$r = group_byname($uid,$name); // check for dups
- if($r !== false) {
+ if ($r !== false) {
// This could be a problem.
// Let's assume we've just created a group which we once deleted
@@ -17,20 +17,16 @@ function group_add($uid,$name) {
$z = q("SELECT * FROM `group` WHERE `id` = %d LIMIT 1",
intval($r)
);
- if(count($z) && $z[0]['deleted']) {
+ if (count($z) && $z[0]['deleted']) {
$r = q("UPDATE `group` SET `deleted` = 0 WHERE `uid` = %d AND `name` = '%s'",
intval($uid),
dbesc($name)
);
- notice( t('A deleted group with this name was revived. Existing item permissions may apply to this group and any future members. If this is not what you intended, please create another group with a different name.') . EOL);
+ notice( t('A deleted group with this name was revived. Existing item permissions may apply to this group and any future members. If this is not what you intended, please create another group with a different name.') . EOL);
}
return true;
}
- $r = q("INSERT INTO `group` ( `uid`, `name` )
- VALUES( %d, '%s' ) ",
- intval($uid),
- dbesc($name)
- );
+ $r = dba::insert('group', array('uid' => $uid, 'name' => $name));
$ret = $r;
}
return $ret;
@@ -39,38 +35,38 @@ function group_add($uid,$name) {
function group_rmv($uid,$name) {
$ret = false;
- if(x($uid) && x($name)) {
+ if (x($uid) && x($name)) {
$r = q("SELECT id FROM `group` WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
intval($uid),
dbesc($name)
);
- if(count($r))
+ if (dbm::is_result($r))
$group_id = $r[0]['id'];
- if(! $group_id)
+ if (! $group_id)
return false;
// remove group from default posting lists
$r = q("SELECT def_gid, allow_gid, deny_gid FROM user WHERE uid = %d LIMIT 1",
intval($uid)
);
- if($r) {
+ if ($r) {
$user_info = $r[0];
$change = false;
- if($user_info['def_gid'] == $group_id) {
+ if ($user_info['def_gid'] == $group_id) {
$user_info['def_gid'] = 0;
$change = true;
}
- if(strpos($user_info['allow_gid'], '<' . $group_id . '>') !== false) {
+ if (strpos($user_info['allow_gid'], '<' . $group_id . '>') !== false) {
$user_info['allow_gid'] = str_replace('<' . $group_id . '>', '', $user_info['allow_gid']);
$change = true;
}
- if(strpos($user_info['deny_gid'], '<' . $group_id . '>') !== false) {
+ if (strpos($user_info['deny_gid'], '<' . $group_id . '>') !== false) {
$user_info['deny_gid'] = str_replace('<' . $group_id . '>', '', $user_info['deny_gid']);
$change = true;
}
- if($change) {
+ if ($change) {
q("UPDATE user SET def_gid = %d, allow_gid = '%s', deny_gid = '%s' WHERE uid = %d",
intval($user_info['def_gid']),
dbesc($user_info['allow_gid']),
@@ -100,22 +96,22 @@ function group_rmv($uid,$name) {
}
function group_byname($uid,$name) {
- if((! $uid) || (! strlen($name)))
+ if ((! $uid) || (! strlen($name)))
return false;
$r = q("SELECT * FROM `group` WHERE `uid` = %d AND `name` = '%s' LIMIT 1",
intval($uid),
dbesc($name)
);
- if(count($r))
+ if (dbm::is_result($r))
return $r[0]['id'];
return false;
}
function group_rmv_member($uid,$name,$member) {
$gid = group_byname($uid,$name);
- if(! $gid)
+ if (! $gid)
return false;
- if(! ( $uid && $gid && $member))
+ if (! ( $uid && $gid && $member))
return false;
$r = q("DELETE FROM `group_member` WHERE `uid` = %d AND `gid` = %d AND `contact-id` = %d",
intval($uid),
@@ -129,9 +125,9 @@ function group_rmv_member($uid,$name,$member) {
function group_add_member($uid,$name,$member,$gid = 0) {
- if(! $gid)
+ if (! $gid)
$gid = group_byname($uid,$name);
- if((! $gid) || (! $uid) || (! $member))
+ if ((! $gid) || (! $uid) || (! $member))
return false;
$r = q("SELECT * FROM `group_member` WHERE `uid` = %d AND `gid` = %d AND `contact-id` = %d LIMIT 1",
@@ -139,23 +135,19 @@ function group_add_member($uid,$name,$member,$gid = 0) {
intval($gid),
intval($member)
);
- if(count($r))
+ if (dbm::is_result($r))
return true; // You might question this, but
// we indicate success because the group member was in fact created
// -- It was just created at another time
- if(! count($r))
- $r = q("INSERT INTO `group_member` (`uid`, `gid`, `contact-id`)
- VALUES( %d, %d, %d ) ",
- intval($uid),
- intval($gid),
- intval($member)
- );
+ if (! dbm::is_result($r)) {
+ $r = dba::insert('group_member', array('uid' => $uid, 'gid' => $gid, 'contact-id' => $member));
+ }
return $r;
}
function group_get_members($gid) {
$ret = array();
- if(intval($gid)) {
+ if (intval($gid)) {
$r = q("SELECT `group_member`.`contact-id`, `contact`.* FROM `group_member`
INNER JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id`
WHERE `gid` = %d AND `group_member`.`uid` = %d AND
@@ -164,7 +156,7 @@ function group_get_members($gid) {
intval($gid),
intval(local_user())
);
- if(count($r))
+ if (dbm::is_result($r))
$ret = $r;
}
return $ret;
@@ -172,7 +164,7 @@ function group_get_members($gid) {
function group_public_members($gid) {
$ret = 0;
- if(intval($gid)) {
+ if (intval($gid)) {
$r = q("SELECT `contact`.`id` AS `contact-id` FROM `group_member`
INNER JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id`
WHERE `gid` = %d AND `group_member`.`uid` = %d
@@ -181,7 +173,7 @@ function group_public_members($gid) {
intval(local_user()),
dbesc(NETWORK_OSTATUS)
);
- if(count($r))
+ if (dbm::is_result($r))
$ret = count($r);
}
return $ret;
@@ -197,8 +189,8 @@ function mini_group_select($uid,$gid = 0, $label = "") {
intval($uid)
);
$grps[] = array('name' => '', 'id' => '0', 'selected' => '');
- if(count($r)) {
- foreach($r as $rr) {
+ if (dbm::is_result($r)) {
+ foreach ($r as $rr) {
$grps[] = array('name' => $rr['name'], 'id' => $rr['id'], 'selected' => (($gid == $rr['id']) ? 'true' : ''));
}
@@ -233,7 +225,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
$o = '';
- if(! local_user())
+ if (! local_user())
return '';
$groups = array();
@@ -251,12 +243,12 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
intval($_SESSION['uid'])
);
$member_of = array();
- if($cid) {
+ if ($cid) {
$member_of = groups_containing(local_user(),$cid);
}
- if(count($r)) {
- foreach($r as $rr) {
+ if (dbm::is_result($r)) {
+ foreach ($r as $rr) {
$selected = (($group_id == $rr['id']) ? ' group-selected' : '');
if ($editmode == "full") {
@@ -301,7 +293,7 @@ function group_side($every="contacts",$each="group",$editmode = "standard", $gro
}
function expand_groups($a,$check_dead = false, $use_gcontact = false) {
- if(! (is_array($a) && count($a)))
+ if (! (is_array($a) && count($a)))
return array();
$groups = implode(',', $a);
$groups = dbesc($groups);
@@ -316,10 +308,10 @@ function expand_groups($a,$check_dead = false, $use_gcontact = false) {
$ret = array();
- if(count($r))
- foreach($r as $rr)
+ if (dbm::is_result($r))
+ foreach ($r as $rr)
$ret[] = $rr['contact-id'];
- if($check_dead AND !$use_gcontact) {
+ if ($check_dead && !$use_gcontact) {
require_once('include/acl_selectors.php');
$ret = prune_deadguys($ret);
}
@@ -345,9 +337,10 @@ function groups_containing($uid,$c) {
);
$ret = array();
- if(count($r)) {
- foreach($r as $rr)
+ if (dbm::is_result($r)) {
+ foreach ($r as $rr) {
$ret[] = $rr['gid'];
+ }
}
return $ret;
@@ -398,7 +391,7 @@ function get_default_group($uid, $network = "") {
return $default_group;
$g = q("SELECT `def_gid` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid));
- if($g && intval($g[0]["def_gid"]))
+ if ($g && intval($g[0]["def_gid"]))
$default_group = $g[0]["def_gid"];
return $default_group;