From: Hypolite Petovan Date: Sat, 9 Dec 2017 18:45:17 +0000 (-0500) Subject: Use new Model methods for groups X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=abdecd2b2fd61859070404c39b2cce304a27d175;p=friendica.git Use new Model methods for groups --- diff --git a/include/api.php b/include/api.php index 03e042955f..70e11416da 100644 --- a/include/api.php +++ b/include/api.php @@ -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; diff --git a/include/follow.php b/include/follow.php index e08136cab1..539768b74c 100644 --- a/include/follow.php +++ b/include/follow.php @@ -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); diff --git a/include/items.php b/include/items.php index 0779ed91e1..834cf888a1 100644 --- a/include/items.php +++ b/include/items.php @@ -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); diff --git a/mod/contactgroup.php b/mod/contactgroup.php index 0be5748386..887cf4dbaa 100644 --- a/mod/contactgroup.php +++ b/mod/contactgroup.php @@ -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); } } } diff --git a/mod/contacts.php b/mod/contacts.php index 71ffcc2d66..3bb7b4f82c 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -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, diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index ec670922a9..f4d5c1b867 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -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. diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index a6436b6782..eef2deb133 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -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); diff --git a/mod/group.php b/mod/group.php index 4b64964cc6..545ccea2c7 100644 --- a/mod/group.php +++ b/mod/group.php @@ -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']); } } diff --git a/mod/network.php b/mod/network.php index 3ac13b24e0..e1e98a2d2d 100644 --- a/mod/network.php +++ b/mod/network.php @@ -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 = ""; diff --git a/mod/nogroup.php b/mod/nogroup.php index d7df8cb187..72cf037304 100644 --- a/mod/nogroup.php +++ b/mod/nogroup.php @@ -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) diff --git a/mod/ping.php b/mod/ping.php index 883129d14f..59f6589eb2 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -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) { diff --git a/mod/settings.php b/mod/settings.php index 5f14c82835..764356b4c4 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -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; diff --git a/mod/update_display.php b/mod/update_display.php index b0fbbbba63..b9294d7558 100644 --- a/mod/update_display.php +++ b/mod/update_display.php @@ -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 = "
".t("[Embedded content - reload page to view]")."
"; + $replace = "
" . t("[Embedded content - reload page to view]") . "
"; $pattern = "/<\s*audio[^>]*>(.*?)<\s*\/\s*audio>/i"; $text = preg_replace($pattern, $replace, $text); $pattern = "/<\s*video[^>]*>(.*?)<\s*\/\s*video>/i"; diff --git a/mod/update_network.php b/mod/update_network.php index 6519490eb0..25b87bc2ae 100644 --- a/mod/update_network.php +++ b/mod/update_network.php @@ -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 = "
".t("[Embedded content - reload page to view]")."
"; + $replace = "
" . t("[Embedded content - reload page to view]") . "
"; $pattern = "/<\s*audio[^>]*>(.*?)<\s*\/\s*audio>/i"; $text = preg_replace($pattern, $replace, $text); $pattern = "/<\s*video[^>]*>(.*?)<\s*\/\s*video>/i"; diff --git a/src/Model/User.php b/src/Model/User.php index ae173fe73d..5a3200b024 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -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), diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index d6f1078f4c..3ef55443c2 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -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); diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 18fff2afda..fb806be954 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -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