1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Newbb; |
4
|
|
|
|
5
|
|
|
// |
6
|
|
|
// ------------------------------------------------------------------------ // |
7
|
|
|
// XOOPS - PHP Content Management System // |
8
|
|
|
// Copyright (c) 2000-2020 XOOPS.org // |
9
|
|
|
// <https://xoops.org> // |
10
|
|
|
// ------------------------------------------------------------------------ // |
11
|
|
|
// This program is free software; you can redistribute it and/or modify // |
12
|
|
|
// it under the terms of the GNU General Public License as published by // |
13
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
14
|
|
|
// (at your option) any later version. // |
15
|
|
|
// // |
16
|
|
|
// You may not change or alter any portion of this comment or credits // |
17
|
|
|
// of supporting developers from this source code or any supporting // |
18
|
|
|
// source code which is considered copyrighted (c) material of the // |
19
|
|
|
// original comment or credit authors. // |
20
|
|
|
// // |
21
|
|
|
// This program is distributed in the hope that it will be useful, // |
22
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
23
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
24
|
|
|
// GNU General Public License for more details. // |
25
|
|
|
// // |
26
|
|
|
// You should have received a copy of the GNU General Public License // |
27
|
|
|
// along with this program; if not, write to the Free Software // |
28
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
29
|
|
|
// ------------------------------------------------------------------------ // |
30
|
|
|
// Author: phppp (D.J., [email protected]) // |
31
|
|
|
// URL: https://xoops.org // |
32
|
|
|
// Project: Article Project // |
33
|
|
|
// ------------------------------------------------------------------------ // |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
require_once $GLOBALS['xoops']->path('class/xoopstree.php'); |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Class Tree |
40
|
|
|
*/ |
41
|
|
|
class Tree extends \XoopsTree |
42
|
|
|
{ |
43
|
|
|
/** @var string */ |
44
|
|
|
private $prefix = ' '; |
45
|
|
|
|
46
|
|
|
/** @var string */ |
47
|
|
|
private $increment = ' '; |
48
|
|
|
|
49
|
|
|
/** @var array */ |
50
|
|
|
private $postArray = []; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $table_name |
54
|
|
|
* @param string $id_name |
55
|
|
|
* @param string $pid_name |
56
|
|
|
*/ |
57
|
|
|
public function __construct($table_name, $id_name = 'post_id', $pid_name = 'pid') |
58
|
|
|
{ |
59
|
|
|
parent::__construct($table_name, $id_name, $pid_name); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string $val |
64
|
|
|
*/ |
65
|
|
|
public function setPrefix($val = '') |
66
|
|
|
{ |
67
|
|
|
$this->prefix = $val; |
68
|
|
|
$this->increment = $val; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param $sel_id |
73
|
|
|
* @param string $order |
74
|
|
|
*/ |
75
|
|
|
public function getAllPostArray($sel_id, $order = '') |
76
|
|
|
{ |
77
|
|
|
$this->postArray = $this->getAllChild($sel_id, $order); |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param $postArray |
82
|
|
|
*/ |
83
|
|
|
public function setPostArray($postArray) |
84
|
|
|
{ |
85
|
|
|
$this->postArray = $postArray; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
// returns an array of first child objects for a given id($sel_id) |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param $postTree_array |
92
|
|
|
* @param int $pid |
93
|
|
|
* @param string $prefix |
94
|
|
|
* @return bool |
95
|
|
|
*/ |
96
|
|
|
public function getPostTree(&$postTree_array, $pid = 0, $prefix = ' ') |
97
|
|
|
{ |
98
|
|
|
if (!\is_array($postTree_array)) { |
99
|
|
|
$postTree_array = []; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$newPostArray = []; |
103
|
|
|
$prefix .= $this->increment; |
104
|
|
|
foreach ($this->postArray as $post) { |
105
|
|
|
if ($post->getVar('pid') == $pid) { |
106
|
|
|
$postTree_array[] = [ |
107
|
|
|
'prefix' => $prefix, |
108
|
|
|
'icon' => $post->getVar('icon'), |
109
|
|
|
'post_time' => $post->getVar('post_time'), |
110
|
|
|
'post_id' => $post->getVar('post_id'), |
111
|
|
|
'forum_id' => $post->getVar('forum_id'), |
112
|
|
|
'subject' => $post->getVar('subject'), |
113
|
|
|
'poster_name' => $post->getVar('poster_name'), |
114
|
|
|
'uid' => $post->getVar('uid'), |
115
|
|
|
]; |
116
|
|
|
$this->getPostTree($postTree_array, $post->getVar('post_id'), $prefix); |
117
|
|
|
} else { |
118
|
|
|
$newPostArray[] = $post; |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
$this->postArray = $newPostArray; |
122
|
|
|
unset($newPostArray); |
123
|
|
|
|
124
|
|
|
return true; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.