Code Duplication    Length = 20-21 lines in 6 locations

class/class.newstopic.php 3 locations

@@ 410-430 (lines=21) @@
407
        if (true === $this->use_permission) {
408
            $xt            = new MyXoopsTree($this->table, 'topic_id', 'topic_pid');
409
            $parent_topics = $xt->getAllParentId($this->topic_id);
410
            if (!empty($this->m_groups) && is_array($this->m_groups)) {
411
                foreach ($this->m_groups as $m_g) {
412
                    $moderate_topics = XoopsPerms::getPermitted($this->mid, 'ModInTopic', $m_g);
413
                    $add             = true;
414
                    // only grant this permission when the group has this permission in all parent topics of the created topic
415
                    foreach ($parent_topics as $p_topic) {
416
                        if (!in_array($p_topic, $moderate_topics)) {
417
                            $add = false;
418
                            continue;
419
                        }
420
                    }
421
                    if (true === $add) {
422
                        $xp = new XoopsPerms();
423
                        $xp->setModuleId($this->mid);
424
                        $xp->setName('ModInTopic');
425
                        $xp->setItemId($this->topic_id);
426
                        $xp->store();
427
                        $xp->addGroup($m_g);
428
                    }
429
                }
430
            }
431
            if (!empty($this->s_groups) && is_array($this->s_groups)) {
432
                foreach ($this->s_groups as $s_g) {
433
                    $submit_topics = XoopsPerms::getPermitted($this->mid, 'SubmitInTopic', $s_g);
@@ 431-450 (lines=20) @@
428
                    }
429
                }
430
            }
431
            if (!empty($this->s_groups) && is_array($this->s_groups)) {
432
                foreach ($this->s_groups as $s_g) {
433
                    $submit_topics = XoopsPerms::getPermitted($this->mid, 'SubmitInTopic', $s_g);
434
                    $add           = true;
435
                    foreach ($parent_topics as $p_topic) {
436
                        if (!in_array($p_topic, $submit_topics)) {
437
                            $add = false;
438
                            continue;
439
                        }
440
                    }
441
                    if (true === $add) {
442
                        $xp = new XoopsPerms();
443
                        $xp->setModuleId($this->mid);
444
                        $xp->setName('SubmitInTopic');
445
                        $xp->setItemId($this->topic_id);
446
                        $xp->store();
447
                        $xp->addGroup($s_g);
448
                    }
449
                }
450
            }
451
            if (!empty($this->r_groups) && is_array($this->r_groups)) {
452
                foreach ($this->s_groups as $r_g) {
453
                    $read_topics = XoopsPerms::getPermitted($this->mid, 'ReadInTopic', $r_g);
@@ 451-470 (lines=20) @@
448
                    }
449
                }
450
            }
451
            if (!empty($this->r_groups) && is_array($this->r_groups)) {
452
                foreach ($this->s_groups as $r_g) {
453
                    $read_topics = XoopsPerms::getPermitted($this->mid, 'ReadInTopic', $r_g);
454
                    $add         = true;
455
                    foreach ($parent_topics as $p_topic) {
456
                        if (!in_array($p_topic, $read_topics)) {
457
                            $add = false;
458
                            continue;
459
                        }
460
                    }
461
                    if (true === $add) {
462
                        $xp = new XoopsPerms();
463
                        $xp->setModuleId($this->mid);
464
                        $xp->setName('ReadInTopic');
465
                        $xp->setItemId($this->topic_id);
466
                        $xp->store();
467
                        $xp->addGroup($r_g);
468
                    }
469
                }
470
            }
471
        }
472
473
        return true;

class/xoopstopic.php 3 locations

@@ 142-162 (lines=21) @@
139
            }
140
            $xt            = new MyXoopsTree($this->table, 'topic_id', 'topic_pid');
141
            $parent_topics = $xt->getAllParentId($this->topic_id);
142
            if (!empty($this->m_groups) && is_array($this->m_groups)) {
143
                foreach ($this->m_groups as $m_g) {
144
                    $moderate_topics = XoopsPerms::getPermitted($this->mid, 'ModInTopic', $m_g);
145
                    $add             = true;
146
                    // only grant this permission when the group has this permission in all parent topics of the created topic
147
                    foreach ($parent_topics as $p_topic) {
148
                        if (!in_array($p_topic, $moderate_topics)) {
149
                            $add = false;
150
                            continue;
151
                        }
152
                    }
153
                    if (true === $add) {
154
                        $xp = new XoopsPerms();
155
                        $xp->setModuleId($this->mid);
156
                        $xp->setName('ModInTopic');
157
                        $xp->setItemId($this->topic_id);
158
                        $xp->store();
159
                        $xp->addGroup($m_g);
160
                    }
161
                }
162
            }
163
            if (!empty($this->s_groups) && is_array($this->s_groups)) {
164
                foreach ($s_groups as $s_g) {
165
                    $submit_topics = XoopsPerms::getPermitted($this->mid, 'SubmitInTopic', $s_g);
@@ 163-182 (lines=20) @@
160
                    }
161
                }
162
            }
163
            if (!empty($this->s_groups) && is_array($this->s_groups)) {
164
                foreach ($s_groups as $s_g) {
165
                    $submit_topics = XoopsPerms::getPermitted($this->mid, 'SubmitInTopic', $s_g);
166
                    $add           = true;
167
                    foreach ($parent_topics as $p_topic) {
168
                        if (!in_array($p_topic, $submit_topics)) {
169
                            $add = false;
170
                            continue;
171
                        }
172
                    }
173
                    if (true === $add) {
174
                        $xp = new XoopsPerms();
175
                        $xp->setModuleId($this->mid);
176
                        $xp->setName('SubmitInTopic');
177
                        $xp->setItemId($this->topic_id);
178
                        $xp->store();
179
                        $xp->addGroup($s_g);
180
                    }
181
                }
182
            }
183
            if (!empty($this->r_groups) && is_array($this->r_groups)) {
184
                foreach ($r_groups as $r_g) {
185
                    $read_topics = XoopsPerms::getPermitted($this->mid, 'ReadInTopic', $r_g);
@@ 183-202 (lines=20) @@
180
                    }
181
                }
182
            }
183
            if (!empty($this->r_groups) && is_array($this->r_groups)) {
184
                foreach ($r_groups as $r_g) {
185
                    $read_topics = XoopsPerms::getPermitted($this->mid, 'ReadInTopic', $r_g);
186
                    $add         = true;
187
                    foreach ($parent_topics as $p_topic) {
188
                        if (!in_array($p_topic, $read_topics)) {
189
                            $add = false;
190
                            continue;
191
                        }
192
                    }
193
                    if (true === $add) {
194
                        $xp = new XoopsPerms();
195
                        $xp->setModuleId($this->mid);
196
                        $xp->setName('ReadInTopic');
197
                        $xp->setItemId($this->topic_id);
198
                        $xp->store();
199
                        $xp->addGroup($r_g);
200
                    }
201
                }
202
            }
203
        }
204
205
        return true;