Completed
Push — master ( 6452b0...d576ea )
by Michael
05:58 queued 03:02
created

MyXoopsTopic::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 9

Duplication

Lines 12
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 12
loc 12
rs 9.4285
cc 3
eloc 9
nc 3
nop 2
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 28 and the first side effect is on line 23.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * XOOPS news topic
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright       XOOPS Project (http://xoops.org)
13
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @package         kernel
15
 * @since           2.0.0
16
 * @author          Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/
17
 * @deprecated
18
 */
19
20
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
21
//$GLOBALS['xoopsLogger']->addDeprecated("'/class/xoopstopic.php' is deprecated since XOOPS 2.5.4, please create your own class instead.");
22
23
include_once XOOPS_ROOT_PATH . '/modules/news/class/xoopstree.php';
24
25
/**
26
 * Class MyXoopsTopic
27
 */
28
class MyXoopsTopic
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
29
{
30
    public $table;
31
    public $topic_id;
32
    public $topic_pid;
33
    public $topic_title;
34
    public $topic_imgurl;
35
    public $prefix; // only used in topic tree
36
    public $use_permission = false;
37
    public $mid; // module id used for setting permission
38
39
    /**
40
     * @param     $table
41
     * @param int $topicid
42
     */
43 View Code Duplication
    public function __construct($table, $topicid = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
    {
45
        $this->db    = XoopsDatabaseFactory::getDatabaseConnection();
0 ignored issues
show
Bug introduced by
The property db does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
46
        $this->table = $table;
47
        if (is_array($topicid)) {
48
            $this->makeTopic($topicid);
49
        } elseif ($topicid != 0) {
50
            $this->getTopic((int)$topicid);
51
        } else {
52
            $this->topic_id = $topicid;
53
        }
54
    }
55
56
    /**
57
     * @param $value
58
     */
59
    public function setTopicTitle($value)
60
    {
61
        $this->topic_title = $value;
62
    }
63
64
    /**
65
     * @param $value
66
     */
67
    public function setTopicImgurl($value)
68
    {
69
        $this->topic_imgurl = $value;
70
    }
71
72
    /**
73
     * @param $value
74
     */
75
    public function setTopicPid($value)
76
    {
77
        $this->topic_pid = $value;
78
    }
79
80
    /**
81
     * @param $topicid
82
     */
83 View Code Duplication
    public function getTopic($topicid)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
    {
85
        $topicid = (int)$topicid;
86
        $sql     = 'SELECT * FROM ' . $this->table . ' WHERE topic_id=' . $topicid . '';
87
        $array   = $this->db->fetchArray($this->db->query($sql));
88
        $this->makeTopic($array);
89
    }
90
91
    /**
92
     * @param $array
93
     */
94
    public function makeTopic($array)
95
    {
96
        foreach ($array as $key => $value) {
97
            $this->$key = $value;
98
        }
99
    }
100
101
    /**
102
     * @param $mid
103
     */
104
    public function usePermission($mid)
105
    {
106
        $this->mid            = $mid;
107
        $this->use_permission = true;
108
    }
109
110
    /**
111
     * @return bool
112
     */
113
    public function store()
114
    {
115
        $myts   = MyTextSanitizer::getInstance();
116
        $title  = '';
117
        $imgurl = '';
118
        if (isset($this->topic_title) && $this->topic_title != '') {
119
            $title = $myts->addSlashes($this->topic_title);
120
        }
121
        if (isset($this->topic_imgurl) && $this->topic_imgurl != '') {
122
            $imgurl = $myts->addSlashes($this->topic_imgurl);
123
        }
124
        if (!isset($this->topic_pid) || !is_numeric($this->topic_pid)) {
125
            $this->topic_pid = 0;
126
        }
127
        if (empty($this->topic_id)) {
128
            $this->topic_id = $this->db->genId($this->table . '_topic_id_seq');
129
            $sql            = sprintf("INSERT INTO %s (topic_id, topic_pid, topic_imgurl, topic_title) VALUES (%u, %u, '%s', '%s')", $this->table, $this->topic_id, $this->topic_pid, $imgurl, $title);
130
        } else {
131
            $sql = sprintf("UPDATE %s SET topic_pid = %u, topic_imgurl = '%s', topic_title = '%s' WHERE topic_id = %u", $this->table, $this->topic_pid, $imgurl, $title, $this->topic_id);
132
        }
133
        if (!$result = $this->db->query($sql)) {
134
            ErrorHandler::show('0022');
135
        }
136
        if ($this->use_permission == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
137
            if (empty($this->topic_id)) {
138
                $this->topic_id = $this->db->getInsertId();
139
            }
140
            $xt            = new MyXoopsTree($this->table, 'topic_id', 'topic_pid');
141
            $parent_topics = $xt->getAllParentId($this->topic_id);
142 View Code Duplication
            if (!empty($this->m_groups) && is_array($this->m_groups)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
143
                foreach ($this->m_groups as $m_g) {
0 ignored issues
show
Bug introduced by
The property m_groups does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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 ($add == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
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 View Code Duplication
            if (!empty($this->s_groups) && is_array($this->s_groups)) {
0 ignored issues
show
Bug introduced by
The property s_groups does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
164
                foreach ($s_groups as $s_g) {
0 ignored issues
show
Bug introduced by
The variable $s_groups does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
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 ($add == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
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 View Code Duplication
            if (!empty($this->r_groups) && is_array($this->r_groups)) {
0 ignored issues
show
Bug introduced by
The property r_groups does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
184
                foreach ($r_groups as $r_g) {
0 ignored issues
show
Bug introduced by
The variable $r_groups does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
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 ($add == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
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;
206
    }
207
208
    public function delete()
209
    {
210
        $sql = sprintf('DELETE FROM %s WHERE topic_id = %u', $this->table, $this->topic_id);
211
        $this->db->query($sql);
212
    }
213
214
    /**
215
     * @return int
216
     */
217
    public function topic_id()
218
    {
219
        return $this->topic_id;
220
    }
221
222
    public function topic_pid()
223
    {
224
        return $this->topic_pid;
225
    }
226
227
    /**
228
     * @param string $format
229
     *
230
     * @return mixed
231
     */
232 View Code Duplication
    public function topic_title($format = 'S')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
233
    {
234
        $myts = MyTextSanitizer::getInstance();
235
        switch ($format) {
236
            case 'S':
237
            case 'E':
238
                $title = $myts->htmlSpecialChars($this->topic_title);
239
                break;
240
            case 'P':
241
            case 'F':
242
                $title = $myts->htmlSpecialChars($myts->stripSlashesGPC($this->topic_title));
243
                break;
244
        }
245
246
        return $title;
0 ignored issues
show
Bug introduced by
The variable $title does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
247
    }
248
249
    /**
250
     * @param string $format
251
     *
252
     * @return mixed
253
     */
254 View Code Duplication
    public function topic_imgurl($format = 'S')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
255
    {
256
        $myts = MyTextSanitizer::getInstance();
257
        switch ($format) {
258
            case 'S':
259
            case 'E':
260
                $imgurl = $myts->htmlSpecialChars($this->topic_imgurl);
261
                break;
262
            case 'P':
263
            case 'F':
264
                $imgurl = $myts->htmlSpecialChars($myts->stripSlashesGPC($this->topic_imgurl));
265
                break;
266
        }
267
268
        return $imgurl;
0 ignored issues
show
Bug introduced by
The variable $imgurl does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
269
    }
270
271
    /**
272
     * @return null
273
     */
274
    public function prefix()
275
    {
276
        if (isset($this->prefix)) {
277
            return $this->prefix;
278
        }
279
280
        return null;
281
    }
282
283
    /**
284
     * @return array
285
     */
286 View Code Duplication
    public function getFirstChildTopics()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
287
    {
288
        $ret       = array();
289
        $xt        = new MyXoopsTree($this->table, 'topic_id', 'topic_pid');
290
        $topic_arr = $xt->getFirstChild($this->topic_id, 'topic_title');
291
        if (is_array($topic_arr) && count($topic_arr)) {
292
            foreach ($topic_arr as $topic) {
293
                $ret[] = new MyXoopsTopic($this->table, $topic);
294
            }
295
        }
296
297
        return $ret;
298
    }
299
300
    /**
301
     * @return array
302
     */
303 View Code Duplication
    public function getAllChildTopics()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
304
    {
305
        $ret       = array();
306
        $xt        = new MyXoopsTree($this->table, 'topic_id', 'topic_pid');
307
        $topic_arr = $xt->getAllChild($this->topic_id, 'topic_title');
308
        if (is_array($topic_arr) && count($topic_arr)) {
309
            foreach ($topic_arr as $topic) {
310
                $ret[] = new MyXoopsTopic($this->table, $topic);
311
            }
312
        }
313
314
        return $ret;
315
    }
316
317
    /**
318
     * @return array
319
     */
320 View Code Duplication
    public function getChildTopicsTreeArray()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
321
    {
322
        $ret       = array();
323
        $xt        = new MyXoopsTree($this->table, 'topic_id', 'topic_pid');
324
        $topic_arr = $xt->getChildTreeArray($this->topic_id, 'topic_title');
325
        if (is_array($topic_arr) && count($topic_arr)) {
326
            foreach ($topic_arr as $topic) {
327
                $ret[] = new MyXoopsTopic($this->table, $topic);
328
            }
329
        }
330
331
        return $ret;
332
    }
333
334
    /**
335
     * @param int    $none
336
     * @param        $seltopic
337
     * @param string $selname
338
     * @param string $onchange
339
     */
340
    public function makeTopicSelBox($none = 0, $seltopic = -1, $selname = '', $onchange = '')
341
    {
342
        $xt = new MyXoopsObjectTree($this->table, 'topic_id', 'topic_pid');
343
        if ($seltopic != -1) {
344
            $xt->makeMySelBox('topic_title', 'topic_title', $seltopic, $none, $selname, $onchange);
0 ignored issues
show
Bug introduced by
The method makeMySelBox() does not exist on MyXoopsObjectTree. Did you maybe mean makeSelBox()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
345
        } elseif (!empty($this->topic_id)) {
346
            $xt->makeMySelBox('topic_title', 'topic_title', $this->topic_id, $none, $selname, $onchange);
0 ignored issues
show
Bug introduced by
The method makeMySelBox() does not exist on MyXoopsObjectTree. Did you maybe mean makeSelBox()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
347
        } else {
348
            $xt->makeMySelBox('topic_title', 'topic_title', 0, $none, $selname, $onchange);
0 ignored issues
show
Bug introduced by
The method makeMySelBox() does not exist on MyXoopsObjectTree. Did you maybe mean makeSelBox()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
349
        }
350
    }
351
352
    //generates nicely formatted linked path from the root id to a given id
353
    /**
354
     * @param $funcURL
355
     *
356
     * @return mixed
357
     */
358 View Code Duplication
    public function getNiceTopicPathFromId($funcURL)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
359
    {
360
        $xt  = new MyXoopsObjectTree($this->table, 'topic_id', 'topic_pid');
361
        $ret = $xt->getNicePathFromId($this->topic_id, 'topic_title', $funcURL);
0 ignored issues
show
Bug introduced by
The method getNicePathFromId() does not seem to exist on object<MyXoopsObjectTree>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
362
363
        return $ret;
364
    }
365
366
    /**
367
     * @return mixed
368
     */
369 View Code Duplication
    public function getAllChildTopicsId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
370
    {
371
        $xt  = new MyXoopsObjectTree($this->table, 'topic_id', 'topic_pid');
372
        $ret = $xt->getAllChildId($this->topic_id, 'topic_title');
0 ignored issues
show
Bug introduced by
The method getAllChildId() does not exist on MyXoopsObjectTree. Did you maybe mean getAllChild()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
373
374
        return $ret;
375
    }
376
377
    /**
378
     * @return array
379
     */
380
    public function getTopicsList()
381
    {
382
        $result = $this->db->query('SELECT topic_id, topic_pid, topic_title FROM ' . $this->table);
383
        $ret    = array();
384
        $myts   = MyTextSanitizer::getInstance();
385 View Code Duplication
        while ($myrow = $this->db->fetchArray($result)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
386
            $ret[$myrow['topic_id']] = array('title' => $myts->htmlspecialchars($myrow['topic_title']), 'pid' => $myrow['topic_pid']);
387
        }
388
389
        return $ret;
390
    }
391
392
    /**
393
     * @param $pid
394
     * @param $title
395
     *
396
     * @return bool
397
     */
398
    public function topicExists($pid, $title)
399
    {
400
        $sql = 'SELECT COUNT(*) from ' . $this->table . ' WHERE topic_pid = ' . (int)$pid . " AND topic_title = '" . trim($title) . "'";
401
        $rs  = $this->db->query($sql);
402
        list($count) = $this->db->fetchRow($rs);
403
        if ($count > 0) {
404
            return true;
405
        } else {
406
            return false;
407
        }
408
    }
409
}
410