]> git.mxchange.org Git - friendica.git/commitdiff
Use new Model methods for groups
authorHypolite Petovan <mrpetovan@gmail.com>
Sat, 9 Dec 2017 18:45:17 +0000 (13:45 -0500)
committerHypolite Petovan <mrpetovan@gmail.com>
Sat, 9 Dec 2017 18:45:17 +0000 (13:45 -0500)
17 files changed:
include/api.php
include/follow.php
include/items.php
mod/contactgroup.php
mod/contacts.php
mod/dfrn_confirm.php
mod/dfrn_request.php
mod/group.php
mod/network.php
mod/nogroup.php
mod/ping.php
mod/settings.php
mod/update_display.php
mod/update_network.php
src/Model/User.php
src/Protocol/Diaspora.php
src/Worker/Notifier.php

index 03e042955f8cb2f67880742e94e8803d54e0aa90..70e11416da55f802ad6f13c1f5133fbbe05a568f 100644 (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;
index e08136cab1e925bf48d93a55cefb0945372c7663..539768b74ce0b65c365f0b80d7b98b05fbfff63c 100644 (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);
index 0779ed91e19da00bf3f4eec2ac984f57cf37a3db..834cf888a1d1fa8562a96636320c93429163954f 100644 (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);
index 0be57483865d0216a4abfea6e0e22e9fc3f187a9..887cf4dbaade8adc6e5b99a318b53e6d4f4d7dc3 100644 (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);
                        }
                }
        }
index 71ffcc2d664745b36fd1e128a5c16fd514e88b0e..3bb7b4f82c993862a9b8d3417e9deba1a988d15b 100644 (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,
index ec670922a979f723e49fb480bebd0708ed133093..f4d5c1b8679491eb36faf10d7f5a1ce499820bea 100644 (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.
index a6436b67829d8c594ff02d3bb67497a6c161ab05..eef2deb133b86d099ede75dffbc4f8bbf396ddf3 100644 (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);
index 4b64964cc63a9bb9345d8e45f3bb711b60482c2a..545ccea2c7fd36dd3c3f7430d4045f28566bf57d 100644 (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']);
                }
        }
 
index 3ac13b24e01c76a359d5a0e4e5e8ec39d878ffbe..e1e98a2d2d83579eeceb302ac3455f6871486ffb 100644 (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 = "";
index d7df8cb187d75c5b4af48fb018e5d573baa4d0c4..72cf0373046957da0e504b25757b6cafe63e13a2 100644 (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)
index 883129d14f1c22f2215e0de4e22ccba07dd60d8d..59f6589eb23989b9350ad7be19e2517f94fb6050 100644 (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) {
index 5f14c82835889a7a56a2819cb6923ea5b65be3cf..764356b4c445e3cb044dbe23e06333039deddbed 100644 (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;
index b0fbbbba637e1ca4d5eccedae12ab3c0c1afcbfe..b9294d755898bbe3cece89f4228fa8c8e3c237e7 100644 (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";
index 6519490eb033df40ca7b37a8a61f2ea21138b100..25b87bc2ae7fc194fb1c2ee8edfb0695a0bf4031 100644 (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";
index ae173fe73d6f3d27d68ebc703151f51d81efde13..5a3200b024064918318fee2c13405f3ab2226f22 100644 (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),
index d6f1078f4c7f26a0c252418cd21e1aeae0238093..3ef55443c2580900080d2fdaafa0d95a3c36544f 100644 (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);
 
index 18fff2afda1c50f493811b8b83b870e1c127636c..fb806be954715f36bc86355594c661eccf33843d 100644 (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