Use new Model methods for groups

This commit is contained in:
Hypolite Petovan 2017-12-09 13:45:17 -05:00
parent fe89e7760e
commit abdecd2b2f
17 changed files with 65 additions and 63 deletions

View File

@ -13,6 +13,7 @@ use Friendica\Core\NotificationsManager;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Model\Photo;
use Friendica\Model\User;
use Friendica\Network\FKOAuth1;
@ -4645,7 +4646,7 @@ function api_friendica_group_show($type)
// loop through all groups and retrieve all members for adding data in the user array
foreach ($r as $rr) {
$members = group_get_members($rr['id']);
$members = Contact::getByGroupId($rr['id']);
$users = array();
if ($type == "xml") {
@ -4713,7 +4714,7 @@ function api_friendica_group_delete($type)
}
// delete group
$ret = group_rmv($uid, $name);
$ret = Group::removeByName($uid, $name);
if ($ret) {
// return success
$success = array('success' => $ret, 'gid' => $gid, 'name' => $name, 'status' => 'deleted', 'wrong users' => array());
@ -4764,9 +4765,9 @@ function api_friendica_group_create($type)
$reactivate_group = true;
// create group
$ret = group_add($uid, $name);
$ret = Group::create($uid, $name);
if ($ret) {
$gid = group_byname($uid, $name);
$gid = Group::getIdByName($uid, $name);
} else {
throw new BadRequestException('other API error');
}
@ -4783,7 +4784,7 @@ function api_friendica_group_create($type)
intval($uid)
);
if (count($contact))
$result = group_add_member($uid, $name, $cid, $gid);
$result = Group::create_member($uid, $name, $cid, $gid);
else {
$erroraddinguser = true;
$errorusers[] = $cid;
@ -4822,14 +4823,14 @@ function api_friendica_group_update($type)
throw new BadRequestException('gid not specified');
// remove members
$members = group_get_members($gid);
$members = Contact::getByGroupId($gid);
foreach ($members as $member) {
$cid = $member['id'];
foreach ($users as $user) {
$found = ($user['cid'] == $cid ? true : false);
}
if (!$found) {
$ret = group_rmv_member($uid, $name, $cid);
$ret = Group::removeMemberByName($uid, $name, $cid);
}
}
@ -4846,7 +4847,7 @@ function api_friendica_group_update($type)
);
if (count($contact)) {
$result = group_add_member($uid, $name, $cid, $gid);
$result = Group::create_member($uid, $name, $cid, $gid);
} else {
$erroraddinguser = true;
$errorusers[] = $cid;

View File

@ -8,6 +8,8 @@ use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Model\User;
use Friendica\Network\Probe;
use Friendica\Protocol\Diaspora;
use Friendica\Protocol\OStatus;
@ -244,10 +246,7 @@ function new_contact($uid, $url, $interactive = false, $network = '') {
$contact_id = $r[0]['id'];
$result['cid'] = $contact_id;
$def_gid = get_default_group($uid, $contact["network"]);
if (intval($def_gid)) {
group_add_member($uid, '', $contact_id, $def_gid);
}
Group::addMember(User::getDefaultGroup($uid, $contact["network"]), $contact_id);
// Update the avatar
Contact::updateAvatar($ret['photo'], $uid, $contact_id);

View File

@ -12,6 +12,8 @@ use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\GContact;
use Friendica\Model\Group;
use Friendica\Model\User;
use Friendica\Object\Image;
use Friendica\Protocol\DFRN;
use Friendica\Protocol\OStatus;
@ -1720,11 +1722,7 @@ function new_follower($importer, $contact, $datarray, $item, $sharing = false) {
'hash' => $hash, 'datetime' => datetime_convert()));
}
$def_gid = get_default_group($importer['uid'], $contact_record["network"]);
if (intval($def_gid)) {
group_add_member($importer['uid'], '', $contact_record['id'], $def_gid);
}
Group::addMember(User::getDefaultGroup($importer['uid'], $contact_record["network"]), $contact_record['id']);
if (($r[0]['notify-flags'] & NOTIFY_INTRO) &&
in_array($r[0]['page-flags'], array(PAGE_NORMAL))) {
@ -1958,9 +1956,9 @@ function compare_permissions($obj1, $obj2) {
/// @TODO type-hint is array
function enumerate_permissions($obj) {
$allow_people = expand_acl($obj['allow_cid']);
$allow_groups = expand_groups(expand_acl($obj['allow_gid']));
$allow_groups = Group::expand(expand_acl($obj['allow_gid']));
$deny_people = expand_acl($obj['deny_cid']);
$deny_groups = expand_groups(expand_acl($obj['deny_gid']));
$deny_groups = Group::expand(expand_acl($obj['deny_gid']));
$recipients = array_unique(array_merge($allow_people, $allow_groups));
$deny = array_unique(array_merge($deny_people, $deny_groups));
$recipients = array_diff($recipients, $deny);

View File

@ -4,6 +4,8 @@ use Friendica\App;
use Friendica\Database\DBM;
require_once('include/group.php');
use Friendica\Model\Contact;
use Friendica\Model\Group;
function contactgroup_content(App $a)
{
@ -31,7 +33,7 @@ function contactgroup_content(App $a)
}
$group = $r[0];
$members = group_get_members($group['id']);
$members = Contact::getByGroupId($group['id']);
$preselected = array();
if (count($members)) {
foreach ($members as $member) {
@ -39,12 +41,11 @@ function contactgroup_content(App $a)
}
}
if($change) {
if(in_array($change,$preselected)) {
group_rmv_member(local_user(),$group['name'],$change);
}
else {
group_add_member(local_user(),$group['name'],$change);
if ($change) {
if (in_array($change, $preselected)) {
Group::removeMember($group['id'], $change);
} else {
Group::addMember($group['id'], $change);
}
}
}

View File

@ -8,6 +8,7 @@ use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\GContact;
use Friendica\Model\Group;
use Friendica\Network\Probe;
require_once 'include/contact_selectors.php';
@ -77,7 +78,7 @@ function contacts_init(App $a) {
$findpeople_widget .= findpeople_widget();
}
$groups_widget .= group_side('contacts','group','full',0,$contact_id);
$groups_widget .= Group::sidebarWidget('contacts','group','full',0,$contact_id);
$a->page['aside'] .= replace_macros(get_markup_template("contacts-widget-sidebar.tpl"),array(
'$vcard_widget' => $vcard_widget,

View File

@ -25,6 +25,8 @@ use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Model\User;
use Friendica\Network\Probe;
use Friendica\Protocol\Diaspora;
@ -502,9 +504,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) {
}
}
$def_gid = get_default_group($uid, $contact["network"]);
if($contact && intval($def_gid))
group_add_member($uid, '', $contact['id'], $def_gid);
Group::addMember(User::getDefaultGroup($uid, $contact["network"]), $contact['id']);
// Let's send our user to the contact editor in case they want to
// do anything special with this new friend.

View File

@ -16,6 +16,8 @@ use Friendica\Core\PConfig;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Model\User;
use Friendica\Network\Probe;
require_once 'include/enotify.php';
@ -190,9 +192,7 @@ function dfrn_request_post(App $a) {
$parms['key'] // this was already escaped
);
if (DBM::is_result($r)) {
$def_gid = get_default_group(local_user(), $r[0]["network"]);
if(intval($def_gid))
group_add_member(local_user(), '', $r[0]['id'], $def_gid);
Group::addMember(User::getDefaultGroup($uid, $r[0]["network"]), $r[0]['id']);
if (isset($photo)) {
Contact::updateAvatar($photo, local_user(), $r[0]["id"], true);

View File

@ -10,11 +10,13 @@ use Friendica\Core\Config;
use Friendica\Core\PConfig;
use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Group;
function group_init(App $a) {
if (local_user()) {
require_once 'include/group.php';
$a->page['aside'] = group_side('contacts', 'group', 'extended', (($a->argc > 1) ? intval($a->argv[1]) : 0));
$a->page['aside'] = Group::sidebarWidget('contacts', 'group', 'extended', (($a->argc > 1) ? intval($a->argv[1]) : 0));
}
}
@ -29,10 +31,10 @@ function group_post(App $a) {
check_form_security_token_redirectOnErr('/group/new', 'group_edit');
$name = notags(trim($_POST['groupname']));
$r = group_add(local_user(), $name);
$r = Group::create(local_user(), $name);
if ($r) {
info(t('Group created.') . EOL);
$r = group_byname(local_user(), $name);
$r = Group::getIdByName(local_user(), $name);
if ($r) {
goaway(System::baseUrl() . '/group/' . $r);
}
@ -69,7 +71,7 @@ function group_post(App $a) {
}
}
$a->page['aside'] = group_side();
$a->page['aside'] = Group::sidebarWidget();
}
return;
}
@ -118,7 +120,7 @@ function group_content(App $a) {
$result = null;
if (DBM::is_result($r)) {
$result = group_rmv(local_user(), $r[0]['name']);
$result = Group::removeByName(local_user(), $r[0]['name']);
}
if ($result) {
@ -158,7 +160,7 @@ function group_content(App $a) {
}
$group = $r[0];
$members = group_get_members($group['id']);
$members = Contact::getByGroupId($group['id']);
$preselected = array();
$entry = array();
$id = 0;
@ -171,12 +173,12 @@ function group_content(App $a) {
if ($change) {
if (in_array($change, $preselected)) {
group_rmv_member(local_user(), $group['name'], $change);
Group::removeMember($group['id'], $change);
} else {
group_add_member(local_user(), $group['name'], $change);
Group::create_member(local_user(), $group['name'], $change);
}
$members = group_get_members($group['id']);
$members = Contact::getByGroupId($group['id']);
$preselected = array();
if (count($members)) {
foreach ($members as $member) {
@ -233,7 +235,7 @@ function group_content(App $a) {
$groupeditor['members'][] = $entry;
} else {
group_rmv_member(local_user(), $group['name'], $member['id']);
Group::removeMember($group['id'], $member['id']);
}
}

View File

@ -10,6 +10,7 @@ use Friendica\Core\Config;
use Friendica\Core\PConfig;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Group;
require_once 'include/conversation.php';
require_once 'include/group.php';
@ -157,7 +158,7 @@ function network_init(App $a) {
$a->page['aside'] = '';
}
$a->page['aside'] .= (Feature::isEnabled(local_user(),'groups') ? group_side('network/0','network','standard',$group_id) : '');
$a->page['aside'] .= (Feature::isEnabled(local_user(),'groups') ? Group::sidebarWidget('network/0','network','standard',$group_id) : '');
$a->page['aside'] .= (Feature::isEnabled(local_user(), 'forumlist_widget') ? ForumManager::widget(local_user(), $cid) : '');
$a->page['aside'] .= posted_date_widget('network',local_user(),false);
$a->page['aside'] .= networks_widget('network',(x($_GET, 'nets') ? $_GET['nets'] : ''));
@ -567,7 +568,7 @@ function networkThreadedView(App $a, $update = 0) {
$o .= $tabs;
if ($group) {
if (($t = group_public_members($group)) && !PConfig::get(local_user(),'system','nowarn_insecure')) {
if (($t = Contact::getOStatusCountByGroupId($group)) && !PConfig::get(local_user(), 'system', 'nowarn_insecure')) {
notice(sprintf(tt("Warning: This group contains %s member from a network that doesn't allow non public messages.",
"Warning: This group contains %s members from a network that doesn't allow non public messages.",
$t), $t).EOL);
@ -644,7 +645,7 @@ function networkThreadedView(App $a, $update = 0) {
// NOTREACHED
}
$contacts = expand_groups(array($group));
$contacts = Group::expand(array($group));
if ((is_array($contacts)) && count($contacts)) {
$contact_str_self = "";

View File

@ -5,6 +5,7 @@
use Friendica\App;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Group;
require_once 'include/contact_selectors.php';
@ -21,7 +22,7 @@ function nogroup_init(App $a)
$a->page['aside'] = '';
}
$a->page['aside'] .= group_side('contacts', 'group', 'extended', 0, $contact_id);
$a->page['aside'] .= Group::sidebarWidget('contacts', 'group', 'extended');
}
function nogroup_content(App $a)

View File

@ -10,6 +10,7 @@ use Friendica\Core\System;
use Friendica\Core\PConfig;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Util\XML;
require_once 'include/datetime.php';
@ -152,7 +153,7 @@ function ping_init(App $a)
if ($network_count) {
if (intval(Feature::isEnabled(local_user(), 'groups'))) {
// Find out how unseen network posts are spread across groups
$group_counts = groups_count_unseen();
$group_counts = Group::countUnseen();
if (DBM::is_result($group_counts)) {
foreach ($group_counts as $group_count) {
if ($group_count['count'] > 0) {

View File

@ -10,6 +10,7 @@ use Friendica\Core\Config;
use Friendica\Core\PConfig;
use Friendica\Database\DBM;
use Friendica\Model\GContact;
use Friendica\Model\Group;
use Friendica\Model\User;
use Friendica\Protocol\Email;
@ -834,7 +835,7 @@ function settings_content(App $a) {
$default_group = PConfig::get(local_user(), 'ostatus', 'default_group');
$legacy_contact = PConfig::get(local_user(), 'ostatus', 'legacy_contact');
$settings_connectors .= mini_group_select(local_user(), $default_group, t("Default group for OStatus contacts"));
$settings_connectors .= Group::displayGroupSelection(local_user(), $default_group, t("Default group for OStatus contacts"));
/// @TODO Found to much different usage to test empty/non-empty strings (e.g. empty(), trim() == '') which is wanted?
if ($legacy_contact != "") {
@ -1218,8 +1219,7 @@ function settings_content(App $a) {
'network_only' => array('expire_network_only', t("Only expire posts by others:"), $expire_network_only, '', array(t('No'), t('Yes'))),
);
require_once('include/group.php');
$group_select = mini_group_select(local_user(), $a->user['def_gid']);
$group_select = Group::displayGroupSelection(local_user(), $a->user['def_gid']);
// Private/public post links for the non-JS ACL form
$private_post = 1;

View File

@ -22,7 +22,7 @@ function update_display_content(App $a)
$text = preg_replace($pattern, $replace, $text);
if (PConfig::get(local_user(), "system", "bandwith_saver")) {
$replace = "<br />".t("[Embedded content - reload page to view]")."<br />";
$replace = "<br />" . t("[Embedded content - reload page to view]") . "<br />";
$pattern = "/<\s*audio[^>]*>(.*?)<\s*\/\s*audio>/i";
$text = preg_replace($pattern, $replace, $text);
$pattern = "/<\s*video[^>]*>(.*?)<\s*\/\s*video>/i";

View File

@ -27,7 +27,7 @@ function update_network_content(App $a)
$text = preg_replace($pattern, $replace, $text);
if (PConfig::get(local_user(), "system", "bandwith_saver")) {
$replace = "<br />".t("[Embedded content - reload page to view]")."<br />";
$replace = "<br />" . t("[Embedded content - reload page to view]") . "<br />";
$pattern = "/<\s*audio[^>]*>(.*?)<\s*\/\s*audio>/i";
$text = preg_replace($pattern, $replace, $text);
$pattern = "/<\s*video[^>]*>(.*?)<\s*\/\s*video>/i";

View File

@ -376,8 +376,7 @@ class User
// Create a group with no members. This allows somebody to use it
// right away as a default group for new contacts.
group_add($newuid, t('Friends'));
Group::create($newuid, t('Friends'));
$r = q("SELECT `id` FROM `group` WHERE `uid` = %d AND `name` = '%s'",
intval($newuid),

View File

@ -18,7 +18,9 @@ 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\Network\Probe;
use Friendica\Util\XML;
@ -37,7 +39,6 @@ require_once 'include/queue_fn.php';
*/
class Diaspora
{
/**
* @brief Return a list of relay servers
*
@ -2462,11 +2463,7 @@ class Diaspora
logger("Author ".$author." was added as contact number ".$contact_record["id"].".", LOGGER_DEBUG);
$def_gid = get_default_group($importer['uid'], $ret["network"]);
if (intval($def_gid)) {
group_add_member($importer["uid"], "", $contact_record["id"], $def_gid);
}
Group::addMember(User::getDefaultGroup($importer['uid'], $ret["network"]), $contact_record['id']);
Contact::updateAvatar($ret["photo"], $importer['uid'], $contact_record["id"], true);

View File

@ -8,6 +8,7 @@ use Friendica\Core\Config;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Network\Probe;
use Friendica\Protocol\Diaspora;
use Friendica\Protocol\OStatus;
@ -349,9 +350,9 @@ class Notifier {
}
$allow_people = expand_acl($parent['allow_cid']);
$allow_groups = expand_groups(expand_acl($parent['allow_gid']),true);
$allow_groups = Group::expand(expand_acl($parent['allow_gid']),true);
$deny_people = expand_acl($parent['deny_cid']);
$deny_groups = expand_groups(expand_acl($parent['deny_gid']));
$deny_groups = Group::expand(expand_acl($parent['deny_gid']));
// if our parent is a public forum (forum_mode == 1), uplink to the origional author causing
// a delivery fork. private groups (forum_mode == 2) do not uplink