These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace Redaxscript\Modules\TableSorter; |
||
3 | |||
4 | use Redaxscript\Db; |
||
5 | use Redaxscript\Filter; |
||
6 | use Redaxscript\Head; |
||
7 | use Redaxscript\Header; |
||
8 | use Redaxscript\Module; |
||
9 | use function array_search; |
||
10 | use function file_get_contents; |
||
11 | use function json_decode; |
||
12 | use function json_encode; |
||
13 | |||
14 | /** |
||
15 | * javaScript powered table sorter |
||
16 | * |
||
17 | * @since 4.0.0 |
||
18 | * |
||
19 | * @package Redaxscript |
||
20 | * @category Modules |
||
21 | * @author Henry Ruhs |
||
22 | */ |
||
23 | |||
24 | class TableSorter extends Module\Module |
||
25 | { |
||
26 | /** |
||
27 | * array of the module |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | |||
32 | protected static $_moduleArray = |
||
33 | [ |
||
34 | 'name' => 'Table Sorter', |
||
35 | 'alias' => 'TableSorter', |
||
36 | 'author' => 'Redaxmedia', |
||
37 | 'description' => 'JavaScript powered table sorter', |
||
38 | 'version' => '4.0.0' |
||
39 | ]; |
||
40 | |||
41 | /** |
||
42 | * renderStart |
||
43 | * |
||
44 | * @since 4.0.0 |
||
45 | */ |
||
46 | |||
47 | public function renderStart() : void |
||
48 | { |
||
49 | if ($this->_registry->get('loggedIn') === $this->_registry->get('token')) |
||
50 | { |
||
51 | /* link */ |
||
52 | |||
53 | $link = Head\Link::getInstance(); |
||
54 | $link |
||
55 | ->init() |
||
56 | ->appendFile('modules/TableSorter/dist/styles/table-sorter.min.css'); |
||
57 | |||
58 | /* script */ |
||
59 | |||
60 | $script = Head\Script::getInstance(); |
||
61 | $script |
||
62 | ->init('foot') |
||
63 | ->appendFile( |
||
64 | [ |
||
65 | 'https://cdnjs.cloudflare.com/ajax/libs/dragula/3.7.2/dragula.min.js', |
||
66 | 'modules/TableSorter/assets/scripts/init.js', |
||
67 | 'modules/TableSorter/dist/scripts/table-sorter.min.js' |
||
68 | ]); |
||
69 | |||
70 | /* router */ |
||
71 | |||
72 | if ($this->_registry->get('firstParameter') === 'module' && $this->_registry->get('secondParameter') === 'table-sorter' && $this->_registry->get('thirdParameter') === 'sort' && $this->_registry->get('tokenParameter')) |
||
73 | { |
||
74 | $this->_registry->set('renderBreak', true); |
||
0 ignored issues
–
show
|
|||
75 | echo $this->_sort(); |
||
76 | } |
||
77 | } |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * sort |
||
82 | * |
||
83 | * @since 4.0.0 |
||
84 | * |
||
85 | * @return string|null |
||
86 | */ |
||
87 | |||
88 | protected function _sort() : ?string |
||
89 | { |
||
90 | if ($this->_request->getServer('HTTP_X_REQUESTED_WITH') === 'XMLHttpRequest') |
||
91 | { |
||
92 | $postArray = $this->_sanitizePost(); |
||
93 | $contents = Db::forTablePrefix($postArray['table'])->whereIn('id', $postArray['rankArray'])->findMany(); |
||
94 | |||
95 | /* process contents */ |
||
96 | |||
97 | foreach ($contents as $value) |
||
98 | { |
||
99 | $value->set('rank', array_search($value->id, $postArray['rankArray'])); |
||
100 | } |
||
101 | |||
102 | /* handle response */ |
||
103 | |||
104 | if ($contents->save()) |
||
105 | { |
||
106 | Header::contentType('application/json'); |
||
107 | return json_encode($postArray['rankArray']); |
||
108 | } |
||
109 | } |
||
110 | Header::responseCode(404); |
||
111 | exit; |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * sanitize the post |
||
116 | * |
||
117 | * @since 4.0.0 |
||
118 | * |
||
119 | * @return array |
||
120 | */ |
||
121 | |||
122 | protected function _sanitizePost() : array |
||
123 | { |
||
124 | $specialFilter = new Filter\Special(); |
||
125 | $content = file_get_contents('php://input'); |
||
126 | $postArray = (array)json_decode($content); |
||
127 | |||
128 | /* sanitize post */ |
||
129 | |||
130 | return |
||
131 | [ |
||
132 | 'table' => $specialFilter->sanitize($postArray['table']), |
||
133 | 'rankArray' => $postArray['rankArray'] |
||
134 | ]; |
||
135 | } |
||
136 | } |
||
137 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: