| 1 | <?php |
||
| 2 | |||
| 3 | class thead extends tbody |
||
| 4 | { |
||
| 5 | /** @param array Attributes for the table Html tag */ |
||
| 6 | public static $attributes = []; |
||
| 7 | /** @param null|str Extension (from $_SERVER['REQUEST_URI']) */ |
||
| 8 | public static $pageExt; |
||
| 9 | |||
| 10 | protected static function load() |
||
| 11 | { |
||
| 12 | $items = self::$t['items']; |
||
| 13 | $v = ['items' => $items]; |
||
| 14 | |||
| 15 | if (self::config('FILTER_ACTIVE')) { |
||
| 16 | self::filterValues($v['f_value'], $v['f_options']); |
||
| 17 | } |
||
| 18 | |||
| 19 | $v['div_attributes'] = self::tagAttributes('div', $items); |
||
| 20 | |||
| 21 | $v['table_attributes'] = self::tagAttributes('table', $items); |
||
| 22 | |||
| 23 | $v['ths'] = self::$cols ? self::ths() : null; |
||
| 24 | |||
| 25 | $v['body'] = self::rowsTbody(); |
||
| 26 | |||
| 27 | $v['footer'] = self::rowsTfoot(); |
||
| 28 | |||
| 29 | return self::view('views/table.html', $v); |
||
| 30 | } |
||
| 31 | |||
| 32 | protected static function filterValues(&$f, &$opts = []) |
||
| 33 | { |
||
| 34 | $f = filter_input(INPUT_GET, 'filter', FILTER_SANITIZE_STRING) ?: null; |
||
| 35 | |||
| 36 | $by = filter_input(INPUT_GET, 'filter-by', FILTER_VALIDATE_INT); |
||
| 37 | foreach (self::$cols as $k => $v) { |
||
| 38 | if (isset($v[2]['sort']) && $v[2]['sort'] === false) { |
||
| 39 | continue; |
||
| 40 | } |
||
| 41 | $selected = $by === $k ? ' selected' : null; |
||
| 42 | $opts[] = "<option value=\"{$k}\"{$selected}>{$v[0]}</option>"; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | private static function tagAttributes($tag, $items) |
||
| 47 | { |
||
| 48 | $attr = $tag === 'div' ? |
||
| 49 | ['id' => $items . '-list', 'class' => 'table'] : |
||
| 50 | ['id' => $items . '-table', 'data-table' => 'js', |
||
| 51 | 'data-sort-a' => self::config('UTF8_ASC_SYMBOL'), |
||
| 52 | 'data-sort-d' => self::config('UTF8_DESC_SYMBOL')]; |
||
| 53 | if (array_key_exists($tag, self::$attributes)) { |
||
| 54 | $attr += self::$attributes[$tag]; |
||
| 55 | } |
||
| 56 | if (isset(self::$attributes[$tag]['class'])) { |
||
| 57 | $attr['class'] .= ' ' . self::$attributes[$tag]['class']; |
||
| 58 | } |
||
| 59 | return self::attributes($attr); |
||
| 60 | } |
||
| 61 | |||
| 62 | protected static function ths() |
||
| 63 | { |
||
| 64 | $ths = []; |
||
| 65 | $length = sizeof(self::$cols); |
||
| 66 | for ($i = 0; $i < $length; $i++) { |
||
| 67 | list($lbl, $col, $arg) = array_pad(self::$cols[$i], 3, null); |
||
| 68 | |||
| 69 | if (is_null($col)) { |
||
| 70 | $arg['sort'] = false; |
||
| 71 | } |
||
| 72 | |||
| 73 | $sort = $del = null; |
||
| 74 | |||
| 75 | $attr = self::thAttributes($col, $arg, $sort, $del); |
||
| 76 | |||
| 77 | $ths[] = self::th($i, $attr, $sort, $del, $lbl); |
||
| 78 | } |
||
| 79 | return implode('', $ths); |
||
| 80 | } |
||
| 81 | |||
| 82 | private static function thAttributes($col, $arg, &$sort, &$del) |
||
| 83 | { |
||
| 84 | if (isset($arg['width'])) { // Width attribute -> style |
||
| 85 | $width = 'width:' . $arg['width'] . ';'; |
||
| 86 | $arg['style'] = isset($arg['style']) ? |
||
| 87 | $width . $arg['style'] : |
||
| 88 | $width; |
||
| 89 | } |
||
| 90 | |||
| 91 | if (($del = isset($arg['type']) && $arg['type'] == 'delete')) { |
||
| 92 | $sort = false; |
||
| 93 | } else { |
||
| 94 | $sort = isset($arg['sort']) ? $arg['sort'] : $col; |
||
| 95 | } |
||
| 96 | |||
| 97 | return array_diff_key((array) $arg, ['sort', 'type', 'width']); |
||
| 98 | } |
||
| 99 | |||
| 100 | private static function th($i, $attr, $sort, $del, $lbl) |
||
| 101 | { |
||
| 102 | $th = '<th' . self::attributes($attr) . '>'; |
||
| 103 | if ($sort) { |
||
| 104 | $th .= '<a onclick="table.Sort(' . $i . ',this);">'; |
||
| 105 | } |
||
| 106 | if (!$del) { |
||
| 107 | if ($sort == self::$t['order']['col']) { |
||
| 108 | $span = self::$t['order']['dir'] === 'desc' ? |
||
| 109 | self::config('UTF8_DESC_SYMBOL') : |
||
| 110 | self::config('UTF8_ASC_SYMBOL'); |
||
| 111 | } else { |
||
| 112 | $span = ""; |
||
| 113 | } |
||
| 114 | $th .= '<span>' . $span . '</span>' . $lbl; |
||
| 115 | } else { |
||
| 116 | $th .= '<input id="' . self::$t['items'] . 'CheckDeleteAll"' . |
||
| 117 | ' onclick=\"checkAllDeleteCheckboxes(this,' . |
||
| 118 | ' \'' . self::$t['items'] . '\')" type="checkbox"/>'; |
||
| 119 | } |
||
| 120 | if ($sort) { |
||
| 121 | $th .= '</a>'; |
||
| 122 | } |
||
| 123 | $th .= '</th>'; |
||
| 124 | return $th; |
||
| 125 | } |
||
| 126 | |||
| 127 | protected static function request() |
||
| 128 | { |
||
| 129 | $export = function(){ |
||
| 130 | $exp = filter_input(INPUT_GET, 'export', FILTER_SANITIZE_STRING); |
||
| 131 | return in_array($exp, self::config('SAVES')) ? $exp : false; |
||
| 132 | }; |
||
| 133 | $order_dir = function(){ |
||
| 134 | $reset = filter_has_var(INPUT_GET, 'col') ? 'asc' : null; |
||
| 135 | return |
||
| 136 | in_array(filter_input(INPUT_GET, 'ord'), ['asc', 'desc']) ? |
||
| 137 | filter_input(INPUT_GET, 'ord') : |
||
| 138 | ($reset ?: self::$t['order']['dir']); |
||
| 139 | }; |
||
| 140 | $order_col = function(){ |
||
| 141 | $col = filter_input(INPUT_GET, 'col', FILTER_VALIDATE_INT); |
||
| 142 | if ($col) { |
||
| 143 | return isset(self::$cols[$col][2]['sort']) ? |
||
| 144 | self::$cols[$col][2]['sort'] : |
||
| 145 | self::$cols[$col][1]; |
||
| 146 | } |
||
| 147 | return self::$t['order']['col']; |
||
| 148 | }; |
||
| 149 | $filter = function(){ |
||
| 150 | $filter = filter_input(INPUT_GET, 'filter') ?: false; |
||
| 151 | if ($filter) { |
||
| 152 | $by = filter_input(INPUT_GET, 'filter-by', FILTER_VALIDATE_INT); |
||
| 153 | if ($by === false || is_null($by)) { |
||
| 154 | $by = self::request('FilterByAll'); |
||
|
0 ignored issues
–
show
|
|||
| 155 | } else { |
||
| 156 | $by = self::$cols[$by][1]; |
||
| 157 | } |
||
| 158 | $by = 'CONCAT(" ",' . $by . ', " ")'; |
||
| 159 | if (self::config('FILTER_CASE_SENSITIVE') !== true) { |
||
| 160 | $by .= ' COLLATE ' . self::config('DB_COLLATION_CI'); |
||
| 161 | } |
||
| 162 | $filter = $by . ' LIKE ' . '"%' . $filter . '%"'; |
||
| 163 | } |
||
| 164 | return $filter; |
||
| 165 | }; |
||
| 166 | $page = function(){ |
||
| 167 | return filter_has_var(INPUT_GET, 'pg') && self::$export == false ? |
||
| 168 | (int)filter_input(INPUT_GET, 'pg', FILTER_SANITIZE_NUMBER_INT) : |
||
| 169 | self::$t['page']; |
||
| 170 | }; |
||
| 171 | |||
| 172 | self::$export = $export(); |
||
| 173 | |||
| 174 | $t = [ |
||
| 175 | 'order' => [ |
||
| 176 | 'dir' => $order_dir(), |
||
| 177 | 'col' => $order_col() |
||
| 178 | ], |
||
| 179 | 'filter' => $filter(), |
||
| 180 | 'page' => $page() |
||
| 181 | ]; |
||
| 182 | //dd(array_merge(self::$t, $t)); |
||
| 183 | return array_merge(self::$t, $t); |
||
| 184 | } |
||
| 185 | } |
||
| 186 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.