]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Group.php
Add 'addon' folder as 'Friendica\Addon' namespace for autoload
[friendica.git] / src / Model / Group.php
index b01fc197014ad2ce9684ce4b05d39cc6bd1afc94..9a4fc23407b28e3d65a7e74fe3aab386fcaf349b 100644 (file)
@@ -4,13 +4,13 @@
  */
 namespace Friendica\Model;
 
+use Friendica\BaseModule;
 use Friendica\BaseObject;
 use Friendica\Core\L10n;
+use Friendica\Core\Logger;
+use Friendica\Core\Renderer;
 use Friendica\Database\DBA;
-
-require_once 'boot.php';
-require_once 'include/dba.php';
-require_once 'include/text.php';
+use Friendica\Util\Security;
 
 /**
  * @brief functions for interacting with the group database table
@@ -29,7 +29,7 @@ class Group extends BaseObject
        public static function create($uid, $name)
        {
                $return = false;
-               if (x($uid) && x($name)) {
+               if (!empty($uid) && !empty($name)) {
                        $gid = self::getIdByName($uid, $name); // check for dupes
                        if ($gid !== false) {
                                // This could be a problem.
@@ -198,7 +198,7 @@ class Group extends BaseObject
         */
        public static function removeByName($uid, $name) {
                $return = false;
-               if (x($uid) && x($name)) {
+               if (!empty($uid) && !empty($name)) {
                        $gid = self::getIdByName($uid, $name);
 
                        $return = self::remove($gid);
@@ -273,36 +273,25 @@ class Group extends BaseObject
         *
         * @param array $group_ids
         * @param boolean $check_dead
-        * @param boolean $use_gcontact
         * @return array
         */
-       public static function expand($group_ids, $check_dead = false, $use_gcontact = false)
+       public static function expand($group_ids, $check_dead = false)
        {
                if (!is_array($group_ids) || !count($group_ids)) {
                        return [];
                }
 
-               $condition = '`gid` IN (' . substr(str_repeat("?, ", count($group_ids)), 0, -2) . ')';
-               if ($use_gcontact) {
-                       $sql = 'SELECT `gcontact`.`id` AS `contact-id` FROM `group_member`
-                                       INNER JOIN `contact` ON `contact`.`id` = `group_member`.`contact-id`
-                                       INNER JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
-                               WHERE ' . $condition;
-                       $param_arr = array_merge([$sql], $group_ids);
-                       $stmt = call_user_func_array('dba::p', $param_arr);
-               } else {
-                       $condition_array = array_merge([$condition], $group_ids);
-                       $stmt = DBA::select('group_member', ['contact-id'], $condition_array);
-               }
+               $stmt = DBA::select('group_member', ['contact-id'], ['gid' => $group_ids]);
 
                $return = [];
                while($group_member = DBA::fetch($stmt)) {
                        $return[] = $group_member['contact-id'];
                }
 
-               if ($check_dead && !$use_gcontact) {
+               if ($check_dead) {
                        Contact::pruneUnavailable($return);
                }
+
                return $return;
        }
 
@@ -334,13 +323,13 @@ class Group extends BaseObject
                                'selected' => $gid == $group['id'] ? 'true' : ''
                        ];
                }
-               logger('groups: ' . print_r($display_groups, true));
+               Logger::log('groups: ' . print_r($display_groups, true));
 
                if ($label == '') {
                        $label = L10n::t('Default privacy group for new contacts');
                }
 
-               $o = replace_macros(get_markup_template('group_selection.tpl'), [
+               $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('group_selection.tpl'), [
                        '$label' => $label,
                        '$groups' => $display_groups
                ]);
@@ -360,7 +349,7 @@ class Group extends BaseObject
         * @param int $cid
         * @return string
         */
-       public static function sidebarWidget($every = 'contacts', $each = 'group', $editmode = 'standard', $group_id = '', $cid = 0)
+       public static function sidebarWidget($every = 'contact', $each = 'group', $editmode = 'standard', $group_id = '', $cid = 0)
        {
                $o = '';
 
@@ -407,20 +396,25 @@ class Group extends BaseObject
                        ];
                }
 
-               $tpl = get_markup_template('group_side.tpl');
-               $o = replace_macros($tpl, [
+               // Don't show the groups on the network page when there is only one
+               if ((count($display_groups) <= 2) && ($each == 'network')) {
+                       return '';
+               }
+
+               $tpl = Renderer::getMarkupTemplate('group_side.tpl');
+               $o = Renderer::replaceMacros($tpl, [
                        '$add' => L10n::t('add'),
                        '$title' => L10n::t('Groups'),
                        '$groups' => $display_groups,
                        'newgroup' => $editmode == 'extended' || $editmode == 'full' ? 1 : '',
                        'grouppage' => 'group/',
                        '$edittext' => L10n::t('Edit group'),
-                       '$ungrouped' => $every === 'contacts' ? L10n::t('Contacts not in any group') : '',
+                       '$ungrouped' => $every === 'contact' ? L10n::t('Contacts not in any group') : '',
                        '$ungrouped_selected' => (($group_id === 'none') ? 'group-selected' : ''),
                        '$createtext' => L10n::t('Create a new group'),
                        '$creategroup' => L10n::t('Group Name: '),
                        '$editgroupstext' => L10n::t('Edit groups'),
-                       '$form_security_token' => get_form_security_token('group_edit'),
+                       '$form_security_token' => BaseModule::getFormSecurityToken('group_edit'),
                ]);