| Total Complexity | 209 |
| Total Lines | 1129 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like TopicRenderer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use TopicRenderer, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | class TopicRenderer |
||
| 28 | { |
||
| 29 | public $vars = []; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * reference to moduleConfig |
||
| 33 | */ |
||
| 34 | public $config; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Current user has no access to current page |
||
| 38 | */ |
||
| 39 | private $noperm = false; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * For multiple forums |
||
| 43 | */ |
||
| 44 | public $is_multiple = false; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * force to parse vars (run against static vars) irmtfan |
||
| 48 | */ |
||
| 49 | public $force = false; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Vistitor's level: 0 - anonymous; 1 - user; 2 - moderator or admin |
||
| 53 | */ |
||
| 54 | public $userlevel = 0; |
||
| 55 | |||
| 56 | public $query = []; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * reference to an object handler |
||
| 60 | */ |
||
| 61 | private $handler; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Requested page |
||
| 65 | */ |
||
| 66 | private $page = 'list.topic.php'; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * query variables |
||
| 70 | */ |
||
| 71 | private $args = ['forum', 'uid', 'lastposter', 'type', 'status', 'mode', 'sort', 'order', 'start', 'since']; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Constructor |
||
| 75 | */ |
||
| 76 | // public function TopicRenderer() |
||
| 77 | public function __construct() |
||
| 78 | { |
||
| 79 | $this->handler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Topic'); |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Access the only instance of this class |
||
| 84 | * @return TopicRenderer |
||
| 85 | */ |
||
| 86 | public static function getInstance() |
||
| 87 | { |
||
| 88 | static $instance; |
||
| 89 | if (null === $instance) { |
||
| 90 | $instance = new static(); |
||
| 91 | } |
||
| 92 | |||
| 93 | return $instance; |
||
| 94 | } |
||
| 95 | |||
| 96 | public function init() |
||
| 97 | { |
||
| 98 | $this->noperm = false; |
||
| 99 | $this->query = []; |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @param $var |
||
| 104 | * @param $val |
||
| 105 | * @return array|int|string |
||
| 106 | */ |
||
| 107 | public function setVar($var, $val) |
||
| 108 | { |
||
| 109 | switch ($var) { |
||
| 110 | case 'forum': |
||
| 111 | if (\is_numeric($val)) { |
||
| 112 | $val = (int)$val; |
||
| 113 | // START irmtfan - if the forum is array |
||
| 114 | } elseif (\is_array($val)) { |
||
| 115 | $val = \implode('|', $val); |
||
| 116 | //} elseif (!empty($val)) { |
||
| 117 | // $val = implode("|", array_map("intval", explode(", ", $val))); |
||
| 118 | } |
||
| 119 | // END irmtfan - if the forum is array |
||
| 120 | break; |
||
| 121 | case 'type': |
||
| 122 | case 'mode': |
||
| 123 | case 'order': |
||
| 124 | case 'start': |
||
| 125 | case 'since': |
||
| 126 | $val = (int)$val; |
||
| 127 | break; |
||
| 128 | case 'uid': // irmtfan add multi topic poster |
||
| 129 | case 'lastposter': // irmtfan add multi lastposter |
||
| 130 | break; |
||
| 131 | case 'status': |
||
| 132 | // START irmtfan to accept multiple status |
||
| 133 | $val = \is_array($val) ? $val : [$val]; |
||
| 134 | $val = \implode(',', $val); |
||
| 135 | //$val = (in_array($val, array_keys($this->getStatus( $this->userlevel ))) ) ? $val : "all"; //irmtfan no need to check if status is empty or not |
||
| 136 | //if ($val === "all" && !$this->is_multiple) $val = ""; irmtfan commented because it is done in sort |
||
| 137 | // END irmtfan to accept multiple status |
||
| 138 | break; |
||
| 139 | default: |
||
| 140 | break; |
||
| 141 | } |
||
| 142 | |||
| 143 | return $val; |
||
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @param array $vars |
||
| 148 | */ |
||
| 149 | public function setVars(array $vars = []) |
||
| 150 | { |
||
| 151 | $this->init(); |
||
| 152 | |||
| 153 | foreach ($vars as $var => $val) { |
||
| 154 | if (!\in_array($var, $this->args)) { |
||
| 155 | continue; |
||
| 156 | } |
||
| 157 | } |
||
| 158 | $this->parseVars(); |
||
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @param string $hash request hash, i.e. get, post |
||
| 163 | */ |
||
| 164 | public function setVarsFromRequest($hash = 'get') |
||
| 165 | { |
||
| 166 | $this->init(); |
||
| 167 | |||
| 168 | foreach ($this->args as $var) { |
||
| 169 | if (Request::hasVar($var, $hash)) { |
||
| 170 | continue; |
||
| 171 | } |
||
| 172 | switch ($var) { |
||
| 173 | case 'forum': |
||
| 174 | case 'status': |
||
| 175 | $this->setVar($var, Request::getArray($var, [], $hash)); |
||
| 176 | break; |
||
| 177 | default: |
||
| 178 | $this->setVar($var, Request::getString($var, '', $hash)); |
||
| 179 | break; |
||
| 180 | } |
||
| 181 | } |
||
| 182 | $this->parseVars(); |
||
| 183 | } |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @param null $status |
||
|
|
|||
| 187 | */ |
||
| 188 | public function myParseStatus($status = null) |
||
| 189 | { |
||
| 190 | switch ($status) { |
||
| 191 | case 'digest': |
||
| 192 | $this->query['where'][] = 't.topic_digest = 1'; |
||
| 193 | break; |
||
| 194 | case 'undigest': |
||
| 195 | $this->query['where'][] = 't.topic_digest = 0'; |
||
| 196 | break; |
||
| 197 | case 'sticky': |
||
| 198 | $this->query['where'][] = 't.topic_sticky = 1'; |
||
| 199 | break; |
||
| 200 | case 'unsticky': |
||
| 201 | $this->query['where'][] = 't.topic_sticky = 0'; |
||
| 202 | break; |
||
| 203 | case 'lock': |
||
| 204 | $this->query['where'][] = 't.topic_status = 1'; |
||
| 205 | break; |
||
| 206 | case 'unlock': |
||
| 207 | $this->query['where'][] = 't.topic_status = 0'; |
||
| 208 | break; |
||
| 209 | case 'poll': |
||
| 210 | $this->query['where'][] = 't.topic_haspoll = 1'; |
||
| 211 | break; |
||
| 212 | case 'unpoll': |
||
| 213 | $this->query['where'][] = 't.topic_haspoll = 0'; |
||
| 214 | break; |
||
| 215 | case 'voted': |
||
| 216 | $this->query['where'][] = 't.votes > 0'; |
||
| 217 | break; |
||
| 218 | case 'unvoted': |
||
| 219 | $this->query['where'][] = 't.votes < 1'; |
||
| 220 | break; |
||
| 221 | case 'replied': |
||
| 222 | $this->query['where'][] = 't.topic_replies > 0'; |
||
| 223 | break; |
||
| 224 | case 'unreplied': |
||
| 225 | $this->query['where'][] = 't.topic_replies < 1'; |
||
| 226 | break; |
||
| 227 | case 'viewed': |
||
| 228 | $this->query['where'][] = 't.topic_views > 0'; |
||
| 229 | break; |
||
| 230 | case 'unviewed': |
||
| 231 | $this->query['where'][] = 't.topic_views < 1'; |
||
| 232 | break; |
||
| 233 | case 'read': |
||
| 234 | // Skip |
||
| 235 | if (empty($this->config['read_mode'])) { |
||
| 236 | // Use database |
||
| 237 | } elseif (2 == $this->config['read_mode']) { |
||
| 238 | // START irmtfan use read_uid to find the unread posts when the user is logged in |
||
| 239 | $read_uid = \is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
||
| 240 | if (!empty($read_uid)) { |
||
| 241 | $this->query['join'][] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_reads_topic') . ' AS r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' '; |
||
| 242 | $this->query['where'][] = 'r.post_id = t.topic_last_post_id'; |
||
| 243 | } |
||
| 244 | |||
| 245 | // END irmtfan change criteria to get from uid p.uid = last post submit user id |
||
| 246 | // User cookie |
||
| 247 | } elseif (1 == $this->config['read_mode']) { |
||
| 248 | // START irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
||
| 249 | $startdate = !empty($this->vars['since']) ? (\time() - \newbbGetSinceTime($this->vars['since'])) : 0; |
||
| 250 | $lastvisit = \max($GLOBALS['last_visit'], $startdate); |
||
| 251 | if ($lastvisit) { |
||
| 252 | $readmode1query = ''; |
||
| 253 | if ($lastvisit > $startdate) { |
||
| 254 | $readmode1query = 'p.post_time < ' . $lastvisit; |
||
| 255 | } |
||
| 256 | $topics = []; |
||
| 257 | $topic_lastread = \newbbGetCookie('LT', true); |
||
| 258 | if (\count($topic_lastread) > 0) { |
||
| 259 | foreach ($topic_lastread as $id => $time) { |
||
| 260 | if ($time > $lastvisit) { |
||
| 261 | $topics[] = $id; |
||
| 262 | } |
||
| 263 | } |
||
| 264 | } |
||
| 265 | if (\count($topics) > 0) { |
||
| 266 | $topicquery = ' t.topic_id IN (' . \implode(',', $topics) . ')'; |
||
| 267 | // because it should be OR |
||
| 268 | $readmode1query = !empty($readmode1query) ? '(' . $readmode1query . ' OR ' . $topicquery . ')' : $topicquery; |
||
| 269 | } |
||
| 270 | $this->query['where'][] = $readmode1query; |
||
| 271 | } |
||
| 272 | // END irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
||
| 273 | } |
||
| 274 | break; |
||
| 275 | case 'unread': |
||
| 276 | // Skip |
||
| 277 | if (empty($this->config['read_mode'])) { |
||
| 278 | // Use database |
||
| 279 | } elseif (2 == $this->config['read_mode']) { |
||
| 280 | // START irmtfan use read_uid to find the unread posts when the user is logged in |
||
| 281 | $read_uid = \is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
||
| 282 | if (!empty($read_uid)) { |
||
| 283 | $this->query['join'][] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_reads_topic') . ' AS r ON r.read_item = t.topic_id AND r.uid = ' . $read_uid . ' '; |
||
| 284 | $this->query['where'][] = '(r.read_id IS NULL OR r.post_id < t.topic_last_post_id)'; |
||
| 285 | } |
||
| 286 | |||
| 287 | // END irmtfan change criteria to get from uid p.uid = last post submit user id |
||
| 288 | // User cookie |
||
| 289 | } elseif (1 == $this->config['read_mode']) { |
||
| 290 | // START irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
||
| 291 | $startdate = !empty($this->vars['since']) ? (\time() - \newbbGetSinceTime($this->vars['since'])) : 0; |
||
| 292 | $lastvisit = \max($GLOBALS['last_visit'], $startdate); |
||
| 293 | if ($lastvisit) { |
||
| 294 | if ($lastvisit > $startdate) { |
||
| 295 | $this->query['where'][] = 'p.post_time > ' . $lastvisit; |
||
| 296 | } |
||
| 297 | $topics = []; |
||
| 298 | $topic_lastread = \newbbGetCookie('LT', true); |
||
| 299 | if (\count($topic_lastread) > 0) { |
||
| 300 | foreach ($topic_lastread as $id => $time) { |
||
| 301 | if ($time > $lastvisit) { |
||
| 302 | $topics[] = $id; |
||
| 303 | } |
||
| 304 | } |
||
| 305 | } |
||
| 306 | if (\count($topics) > 0) { |
||
| 307 | $this->query['where'][] = ' t.topic_id NOT IN (' . \implode(',', $topics) . ')'; |
||
| 308 | } |
||
| 309 | } |
||
| 310 | // END irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
||
| 311 | } |
||
| 312 | break; |
||
| 313 | case 'pending': |
||
| 314 | if ($this->userlevel < 2) { |
||
| 315 | $this->noperm = true; |
||
| 316 | } else { |
||
| 317 | $this->query['where'][] = 't.approved = 0'; |
||
| 318 | } |
||
| 319 | break; |
||
| 320 | case 'deleted': |
||
| 321 | if ($this->userlevel < 2) { |
||
| 322 | $this->noperm = true; |
||
| 323 | } else { |
||
| 324 | $this->query['where'][] = 't.approved = -1'; |
||
| 325 | } |
||
| 326 | break; |
||
| 327 | case 'all': // For viewall.php; do not display sticky topics at first |
||
| 328 | case 'active': // same as 'all' |
||
| 329 | $this->query['where'][] = 't.approved = 1'; |
||
| 330 | break; |
||
| 331 | default: // irmtfan do nothing |
||
| 332 | break; |
||
| 333 | } |
||
| 334 | } |
||
| 335 | |||
| 336 | /** |
||
| 337 | * @param $var |
||
| 338 | * @param $val |
||
| 339 | */ |
||
| 340 | public function parseVar($var, $val) |
||
| 341 | { |
||
| 342 | switch ($var) { |
||
| 343 | case 'forum': |
||
| 344 | /** @var Newbb\ForumHandler $forumHandler */ $forumHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Forum'); |
||
| 345 | // START irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums |
||
| 346 | // Get accessible forums |
||
| 347 | $accessForums = $forumHandler->getIdsByValues(\array_map('\intval', @\explode('|', $val))); |
||
| 348 | // Filter specified forums if any |
||
| 349 | //if (!empty($val) && $_forums = @explode('|', $val)) { |
||
| 350 | //$accessForums = array_intersect($accessForums, array_map('intval', $_forums)); |
||
| 351 | //} |
||
| 352 | $this->vars['forum'] = $this->setVar('forum', $accessForums); |
||
| 353 | // END irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums |
||
| 354 | |||
| 355 | if (empty($accessForums)) { |
||
| 356 | $this->noperm = true; |
||
| 357 | // irmtfan - it just return return the forum_id only when the forum_id is the first allowed forum - no need for this code implode is enough removed. |
||
| 358 | //} elseif (count($accessForums) === 1) { |
||
| 359 | //$this->query["where"][] = "t.forum_id = " . $accessForums[0]; |
||
| 360 | } else { |
||
| 361 | $this->query['where'][] = 't.forum_id IN ( ' . \implode(', ', $accessForums) . ' )'; |
||
| 362 | } |
||
| 363 | break; |
||
| 364 | case 'uid': // irmtfan add multi topic poster |
||
| 365 | if (-1 !== $val) { |
||
| 366 | $val = \implode(',', \array_map('\intval', \explode(',', $val))); |
||
| 367 | $this->query['where'][] = 't.topic_poster IN ( ' . $val . ' )'; |
||
| 368 | } |
||
| 369 | break; |
||
| 370 | case 'lastposter': // irmtfan add multi lastposter |
||
| 371 | if (-1 !== $val) { |
||
| 372 | $val = \implode(',', \array_map('\intval', \explode(',', $val))); |
||
| 373 | $this->query['where'][] = 'p.uid IN ( ' . $val . ' )'; |
||
| 374 | } |
||
| 375 | break; |
||
| 376 | case 'since': |
||
| 377 | if (!empty($val)) { |
||
| 378 | // START irmtfan if unread && read_mode = 1 and last_visit > startdate do not add where query | to accept multiple status |
||
| 379 | $startdate = \time() - \newbbGetSinceTime($val); |
||
| 380 | if (\in_array('unread', \explode(',', $this->vars['status'])) && 1 == $this->config['read_mode'] |
||
| 381 | && $GLOBALS['last_visit'] > $startdate) { |
||
| 382 | break; |
||
| 383 | } |
||
| 384 | // irmtfan digest_time | to accept multiple status |
||
| 385 | if (\in_array('digest', \explode(',', $this->vars['status']))) { |
||
| 386 | $this->query['where'][] = 't.digest_time > ' . $startdate; |
||
| 387 | } |
||
| 388 | // irmtfan - should be >= instead of = |
||
| 389 | $this->query['where'][] = 'p.post_time >= ' . $startdate; |
||
| 390 | // END irmtfan if unread && read_mode = 1 and last_visit > startdate do not add where query |
||
| 391 | } |
||
| 392 | break; |
||
| 393 | case 'type': |
||
| 394 | if (!empty($val)) { |
||
| 395 | $this->query['where'][] = 't.type_id = ' . $val; |
||
| 396 | } |
||
| 397 | break; |
||
| 398 | case 'status': |
||
| 399 | // START irmtfan to accept multiple status |
||
| 400 | $val = \explode(',', $val); |
||
| 401 | // irmtfan - add 'all' to always parse t.approved = 1 |
||
| 402 | if (0 === \count(\array_intersect($val, ['all', 'active', 'pending', 'deleted']))) { |
||
| 403 | $val[] = 'all'; |
||
| 404 | } |
||
| 405 | foreach ($val as $key => $status) { |
||
| 406 | $this->myParseStatus($status); |
||
| 407 | } |
||
| 408 | // END irmtfan to accept multiple status |
||
| 409 | break; |
||
| 410 | case 'sort': |
||
| 411 | $sort = $this->getSort($val, 'sort'); |
||
| 412 | if ($sort) { |
||
| 413 | $this->query['sort'][] = $sort . (empty($this->vars['order']) ? ' DESC' : ' ASC'); |
||
| 414 | } else { // irmtfan if sort is not in the list |
||
| 415 | $this->query['sort'][] = 't.topic_last_post_id' . (empty($this->vars['order']) ? ' DESC' : ' ASC'); |
||
| 416 | } |
||
| 417 | break; |
||
| 418 | default: |
||
| 419 | break; |
||
| 420 | } |
||
| 421 | } |
||
| 422 | |||
| 423 | /** |
||
| 424 | * @return bool |
||
| 425 | */ |
||
| 426 | public function parseVars() |
||
| 427 | { |
||
| 428 | static $parsed; |
||
| 429 | // irmtfan - force to parse vars (run against static vars) |
||
| 430 | if (null !== $parsed && !$this->force) { |
||
| 431 | return true; |
||
| 432 | } |
||
| 433 | |||
| 434 | if (!isset($this->vars['forum'])) { |
||
| 435 | $this->vars['forum'] = null; |
||
| 436 | } |
||
| 437 | //irmtfan parse status for rendering topic correctly - if empty($_GET(status)) it will show all topics include deleted and pendings. 'all' instead of all |
||
| 438 | if (!isset($this->vars['status'])) { |
||
| 439 | $this->vars['status'] = 'all'; |
||
| 440 | } |
||
| 441 | // irmtfan if sort is not set or is empty get a default sort- if empty($_GET(sort)) | if sort=null eg: /list.topic.php?sort= |
||
| 442 | if (empty($this->vars['sort'])) { |
||
| 443 | $this->vars['sort'] = 'lastpost'; |
||
| 444 | } // use lastpost instead of sticky |
||
| 445 | |||
| 446 | foreach ($this->vars as $var => $val) { |
||
| 447 | $this->parseVar($var, $val); |
||
| 448 | if (empty($val)) { |
||
| 449 | unset($this->vars[$var]); |
||
| 450 | } |
||
| 451 | } |
||
| 452 | $parsed = true; |
||
| 453 | |||
| 454 | return true; |
||
| 455 | } |
||
| 456 | |||
| 457 | /** |
||
| 458 | * @param null $header |
||
| 459 | * @param null $var |
||
| 460 | * @return array|null |
||
| 461 | */ |
||
| 462 | public function getSort($header = null, $var = null) |
||
| 463 | { |
||
| 464 | $headers = [ |
||
| 465 | 'topic' => [ |
||
| 466 | 'title' => \_MD_NEWBB_TOPICS, |
||
| 467 | 'sort' => 't.topic_title', |
||
| 468 | ], |
||
| 469 | 'forum' => [ |
||
| 470 | 'title' => \_MD_NEWBB_FORUM, |
||
| 471 | 'sort' => 't.forum_id', |
||
| 472 | ], |
||
| 473 | 'poster' => [ |
||
| 474 | 'title' => \_MD_NEWBB_TOPICPOSTER, /*irmtfan _MD_NEWBB_POSTER to _MD_NEWBB_TOPICPOSTER*/ |
||
| 475 | 'sort' => 't.topic_poster', |
||
| 476 | ], |
||
| 477 | 'replies' => [ |
||
| 478 | 'title' => \_MD_NEWBB_REPLIES, |
||
| 479 | 'sort' => 't.topic_replies', |
||
| 480 | ], |
||
| 481 | 'views' => [ |
||
| 482 | 'title' => \_MD_NEWBB_VIEWS, |
||
| 483 | 'sort' => 't.topic_views', |
||
| 484 | ], |
||
| 485 | 'lastpost' => [ // irmtfan show topic_page_jump_icon smarty |
||
| 486 | 'title' => \_MD_NEWBB_LASTPOST, |
||
| 487 | /*irmtfan _MD_NEWBB_DATE to _MD_NEWBB_LASTPOSTTIME again change to _MD_LASTPOST*/ |
||
| 488 | 'sort' => 't.topic_last_post_id', |
||
| 489 | ], |
||
| 490 | // START irmtfan add more sorts |
||
| 491 | 'lastposttime' => [ // irmtfan same as lastpost |
||
| 492 | 'title' => \_MD_NEWBB_LASTPOSTTIME, |
||
| 493 | 'sort' => 't.topic_last_post_id', |
||
| 494 | ], |
||
| 495 | 'lastposter' => [ // irmtfan |
||
| 496 | 'title' => \_MD_NEWBB_POSTER, |
||
| 497 | 'sort' => 'p.uid', // poster uid |
||
| 498 | ], |
||
| 499 | 'lastpostmsgicon' => [ // irmtfan |
||
| 500 | 'title' => \_MD_NEWBB_MESSAGEICON, |
||
| 501 | 'sort' => 'p.icon', // post message icon |
||
| 502 | ], |
||
| 503 | 'ratings' => [ |
||
| 504 | 'title' => \_MD_NEWBB_RATINGS, |
||
| 505 | 'sort' => 't.rating', // irmtfan t.topic_rating to t.rating |
||
| 506 | ], |
||
| 507 | 'votes' => [ |
||
| 508 | 'title' => \_MD_NEWBB_VOTES, |
||
| 509 | 'sort' => 't.votes', |
||
| 510 | ], |
||
| 511 | 'publish' => [ |
||
| 512 | 'title' => \_MD_NEWBB_TOPICTIME, |
||
| 513 | 'sort' => 't.topic_id', |
||
| 514 | ], |
||
| 515 | 'digest' => [ |
||
| 516 | 'title' => \_MD_NEWBB_DIGEST, |
||
| 517 | 'sort' => 't.digest_time', |
||
| 518 | ], |
||
| 519 | 'sticky' => [ |
||
| 520 | 'title' => \_MD_NEWBB_STICKY, |
||
| 521 | 'sort' => 't.topic_sticky', |
||
| 522 | ], |
||
| 523 | 'lock' => [ |
||
| 524 | 'title' => \_MD_NEWBB_LOCK, |
||
| 525 | 'sort' => 't.topic_status', |
||
| 526 | ], |
||
| 527 | 'poll' => [ |
||
| 528 | 'title' => \_MD_NEWBB_POLL_POLL, |
||
| 529 | 'sort' => 't.poll_id', |
||
| 530 | ], |
||
| 531 | ]; |
||
| 532 | $types = $this->getTypes(); |
||
| 533 | if (!empty($types)) { |
||
| 534 | $headers['type'] = [ |
||
| 535 | 'title' => _MD_NEWBB_TYPE, |
||
| 536 | 'sort' => 't.type_id', |
||
| 537 | ]; |
||
| 538 | } |
||
| 539 | if (2 == $this->userlevel) { |
||
| 540 | $headers['approve'] = [ |
||
| 541 | 'title' => \_MD_NEWBB_APPROVE, |
||
| 542 | 'sort' => 't.approved', |
||
| 543 | ]; |
||
| 544 | } |
||
| 545 | // END irmtfan add more sorts |
||
| 546 | if (empty($header) && empty($var)) { |
||
| 547 | return $headers; |
||
| 548 | } |
||
| 549 | if (!empty($var) && !empty($header)) { |
||
| 550 | return @$headers[$header][$var]; |
||
| 551 | } |
||
| 552 | if (empty($var)) { |
||
| 553 | return @$headers[$header]; |
||
| 554 | } |
||
| 555 | $ret = null; |
||
| 556 | foreach (\array_keys($headers) as $key) { |
||
| 557 | $ret[$key] = @$headers[$key][$var]; |
||
| 558 | } |
||
| 559 | |||
| 560 | return $ret; |
||
| 561 | } |
||
| 562 | |||
| 563 | // START irmtfan add Display topic headers function |
||
| 564 | |||
| 565 | /** |
||
| 566 | * @param null $header |
||
| 567 | * @return array |
||
| 568 | */ |
||
| 569 | public function getHeader($header = null) |
||
| 570 | { |
||
| 571 | $headersSort = $this->getSort('', 'title'); |
||
| 572 | // additional headers - important: those cannot be in sort anyway |
||
| 573 | $headers = \array_merge( |
||
| 574 | $headersSort, |
||
| 575 | [ |
||
| 576 | 'attachment' => \_MD_NEWBB_TOPICSHASATT, // show attachment smarty |
||
| 577 | 'read' => \_MD_NEWBB_MARK_UNREAD . '|' . \_MD_NEWBB_MARK_READ, // read/unread show topic_folder smarty |
||
| 578 | 'pagenav' => \_MD_NEWBB_PAGENAV_DISPLAY, // show topic_page_jump smarty - sort by topic_replies? |
||
| 579 | ] |
||
| 580 | ); |
||
| 581 | |||
| 582 | return $this->getFromKeys($headers, $header); |
||
| 583 | } |
||
| 584 | |||
| 585 | // END irmtfan add Display topic headers function |
||
| 586 | |||
| 587 | /** |
||
| 588 | * @param null $type |
||
| 589 | * @param null $status |
||
| 590 | * @return array |
||
| 591 | */ |
||
| 592 | public function getStatus($type = null, $status = null) |
||
| 593 | { |
||
| 594 | $links = [ |
||
| 595 | //"" => "", /* irmtfan remove empty array */ |
||
| 596 | 'all' => _ALL, |
||
| 597 | 'digest' => \_MD_NEWBB_DIGEST, |
||
| 598 | 'undigest' => \_MD_NEWBB_UNDIGEST, // irmtfan add |
||
| 599 | 'sticky' => \_MD_NEWBB_STICKY, // irmtfan add |
||
| 600 | 'unsticky' => \_MD_NEWBB_UNSTICKY, // irmtfan add |
||
| 601 | 'lock' => \_MD_NEWBB_LOCK, // irmtfan add |
||
| 602 | 'unlock' => \_MD_NEWBB_UNLOCK, // irmtfan add |
||
| 603 | 'poll' => \_MD_NEWBB_TOPICHASPOLL, // irmtfan add |
||
| 604 | 'unpoll' => \_MD_NEWBB_TOPICHASNOTPOLL, // irmtfan add |
||
| 605 | 'voted' => \_MD_NEWBB_VOTED, // irmtfan add |
||
| 606 | 'unvoted' => \_MD_NEWBB_UNVOTED, // irmtfan add |
||
| 607 | 'viewed' => \_MD_NEWBB_VIEWED, // irmtfan add |
||
| 608 | 'unviewed' => \_MD_NEWBB_UNVIEWED, // irmtfan add |
||
| 609 | 'replied' => \_MD_NEWBB_REPLIED, // irmtfan add |
||
| 610 | 'unreplied' => \_MD_NEWBB_UNREPLIED, |
||
| 611 | 'read' => \_MD_NEWBB_READ, // irmtfan add |
||
| 612 | 'unread' => \_MD_NEWBB_UNREAD, |
||
| 613 | ]; |
||
| 614 | $links_admin = [ |
||
| 615 | 'active' => \_MD_NEWBB_TYPE_ADMIN, |
||
| 616 | 'pending' => \_MD_NEWBB_TYPE_PENDING, |
||
| 617 | 'deleted' => \_MD_NEWBB_TYPE_DELETED, |
||
| 618 | ]; |
||
| 619 | |||
| 620 | // all status, for admin |
||
| 621 | if ($type > 1) { |
||
| 622 | $links = \array_merge($links, $links_admin); // irmtfan to accept multiple status |
||
| 623 | } |
||
| 624 | |||
| 625 | return $this->getFromKeys($links, $status); // irmtfan to accept multiple status |
||
| 626 | } |
||
| 627 | |||
| 628 | /** |
||
| 629 | * @param \Smarty $xoopsTpl |
||
| 630 | * @throws \RuntimeException |
||
| 631 | */ |
||
| 632 | public function buildSelection(\Smarty $xoopsTpl) |
||
| 633 | { |
||
| 634 | $selection = ['action' => $this->page]; |
||
| 635 | $selection['vars'] = $this->vars; |
||
| 636 | require_once \dirname(__DIR__) . '/include/functions.forum.php'; |
||
| 637 | $forum_selected = empty($this->vars['forum']) ? null : \explode('|', @$this->vars['forum']); |
||
| 638 | $selection['forum'] = '<select name="forum[]" multiple="multiple">'; |
||
| 639 | $selection['forum'] .= '<option value="0">' . \_MD_NEWBB_ALL . '</option>'; |
||
| 640 | $selection['forum'] .= \newbbForumSelectBox($forum_selected); |
||
| 641 | $selection['forum'] .= '</select>'; |
||
| 642 | |||
| 643 | $sort_selected = $this->vars['sort']; |
||
| 644 | $sorts = $this->getSort('', 'title'); |
||
| 645 | $selection['sort'] = "<select name='sort'>"; |
||
| 646 | if (!\is_array($sorts)) { |
||
| 647 | throw new \RuntimeException('$sorts must be an array.'); |
||
| 648 | } |
||
| 649 | foreach ($sorts as $sort => $title) { |
||
| 650 | $selection['sort'] .= "<option value='" . $sort . "' " . (($sort == $sort_selected) ? " selected='selected'" : '') . '>' . $title . '</option>'; |
||
| 651 | } |
||
| 652 | $selection['sort'] .= '</select>'; |
||
| 653 | |||
| 654 | $selection['order'] = "<select name='order'>"; |
||
| 655 | $selection['order'] .= "<option value='0' " . (empty($this->vars['order']) ? " selected='selected'" : '') . '>' . _DESCENDING . '</option>'; |
||
| 656 | $selection['order'] .= "<option value='1' " . (!empty($this->vars['order']) ? " selected='selected'" : '') . '>' . _ASCENDING . '</option>'; |
||
| 657 | $selection['order'] .= '</select>'; |
||
| 658 | |||
| 659 | $since = isset($this->vars['since']) ? $this->vars['since'] : $this->config['since_default']; |
||
| 660 | $selection['since'] = \newbbSinceSelectBox($since); |
||
| 661 | |||
| 662 | $xoopsTpl->assign_by_ref('selection', $selection); |
||
| 663 | } |
||
| 664 | |||
| 665 | /** |
||
| 666 | * @param \Smarty $xoopsTpl |
||
| 667 | */ |
||
| 668 | public function buildSearch(\Smarty $xoopsTpl) |
||
| 669 | { |
||
| 670 | $search = []; |
||
| 671 | $search['forum'] = @$this->vars['forum']; |
||
| 672 | $search['since'] = @$this->vars['since']; |
||
| 673 | $search['searchin'] = 'both'; |
||
| 674 | |||
| 675 | $xoopsTpl->assign_by_ref('search', $search); |
||
| 676 | } |
||
| 677 | |||
| 678 | /** |
||
| 679 | * @param \Smarty $xoopsTpl |
||
| 680 | * @throws \RuntimeException |
||
| 681 | */ |
||
| 682 | public function buildHeaders(\Smarty $xoopsTpl) |
||
| 683 | { |
||
| 684 | $args = []; |
||
| 685 | foreach ($this->vars as $var => $val) { |
||
| 686 | if ('sort' === $var || 'order' === $var) { |
||
| 687 | continue; |
||
| 688 | } |
||
| 689 | $args[] = "{$var}={$val}"; |
||
| 690 | } |
||
| 691 | |||
| 692 | $headers = $this->getSort('', 'title'); |
||
| 693 | if (!\is_array($headers)) { |
||
| 694 | throw new \RuntimeException('$headers must be an array.'); |
||
| 695 | } |
||
| 696 | foreach ($headers as $header => $title) { |
||
| 697 | $_args = ["sort={$header}"]; |
||
| 698 | if (@$this->vars['sort'] == $header) { |
||
| 699 | $_args[] = 'order=' . ((@$this->vars['order'] + 1) % 2); |
||
| 700 | } |
||
| 701 | $headers_data[$header]['title'] = $title; |
||
| 702 | $headers_data[$header]['link'] = $this->page . '?' . \implode('&', \array_merge($args, $_args)); |
||
| 703 | } |
||
| 704 | $xoopsTpl->assign_by_ref('headers', $headers_data); |
||
| 705 | } |
||
| 706 | |||
| 707 | /** |
||
| 708 | * @param \Smarty $xoopsTpl |
||
| 709 | */ |
||
| 710 | public function buildFilters(\Smarty $xoopsTpl) |
||
| 711 | { |
||
| 712 | $args = []; |
||
| 713 | foreach ($this->vars as $var => $val) { |
||
| 714 | if ('status' === $var) { |
||
| 715 | continue; |
||
| 716 | } |
||
| 717 | $args[] = "{$var}={$val}"; |
||
| 718 | } |
||
| 719 | |||
| 720 | $links = $this->getStatus($this->userlevel); |
||
| 721 | |||
| 722 | $status = []; |
||
| 723 | foreach ($links as $link => $title) { |
||
| 724 | $_args = ["status={$link}"]; |
||
| 725 | $status[$link]['title'] = $title; |
||
| 726 | $status[$link]['link'] = $this->page . '?' . \implode('&', \array_merge($args, $_args)); |
||
| 727 | } |
||
| 728 | $xoopsTpl->assign_by_ref('filters', $status); |
||
| 729 | } |
||
| 730 | |||
| 731 | /** |
||
| 732 | * @param null $type_id |
||
| 733 | * @return mixed |
||
| 734 | */ |
||
| 735 | public function getTypes($type_id = null) |
||
| 736 | { |
||
| 737 | static $types; |
||
| 738 | if (!isset($types)) { |
||
| 739 | /** @var Newbb\TypeHandler $typeHandler */ |
||
| 740 | $typeHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Type'); |
||
| 741 | |||
| 742 | $types = $typeHandler->getByForum(\explode('|', @$this->vars['forum'])); |
||
| 743 | } |
||
| 744 | |||
| 745 | if (empty($type_id)) { |
||
| 746 | return $types; |
||
| 747 | } |
||
| 748 | |||
| 749 | return @$types[$type_id]; |
||
| 750 | } |
||
| 751 | |||
| 752 | /** |
||
| 753 | * @param \Smarty $xoopsTpl |
||
| 754 | * @return bool |
||
| 755 | */ |
||
| 756 | public function buildTypes(\Smarty $xoopsTpl) |
||
| 777 | } |
||
| 778 | |||
| 779 | /** |
||
| 780 | * @param \Smarty $xoopsTpl |
||
| 781 | * @return bool |
||
| 782 | */ |
||
| 783 | public function buildCurrent(\Smarty $xoopsTpl) |
||
| 784 | { |
||
| 785 | if (empty($this->vars['status']) && !$this->is_multiple) { |
||
| 786 | return true; |
||
| 787 | } |
||
| 788 | |||
| 789 | $args = []; |
||
| 790 | foreach ($this->vars as $var => $val) { |
||
| 791 | $args[] = "{$var}={$val}"; |
||
| 792 | } |
||
| 793 | |||
| 794 | $status = []; |
||
| 795 | $status['title'] = \implode(',', $this->getStatus($this->userlevel, $this->vars['status'])); // irmtfan to accept multiple status |
||
| 796 | //$status['link'] = $this->page.(empty($this->vars['status']) ? '' : '?status='.$this->vars['status']); |
||
| 797 | $status['link'] = $this->page . (empty($args) ? '' : '?' . \implode('&', $args)); |
||
| 798 | |||
| 799 | $xoopsTpl->assign_by_ref('current', $status); |
||
| 800 | } |
||
| 801 | |||
| 802 | /** |
||
| 803 | * @param \Smarty $xoopsTpl |
||
| 804 | */ |
||
| 805 | public function buildPagenav(\Smarty $xoopsTpl) |
||
| 831 | } |
||
| 832 | } |
||
| 833 | |||
| 834 | /** |
||
| 835 | * @return int |
||
| 836 | */ |
||
| 837 | public function getCount() |
||
| 864 | } |
||
| 865 | |||
| 866 | /** |
||
| 867 | * @param \Smarty $xoopsTpl |
||
| 868 | * @return array|void |
||
| 869 | */ |
||
| 870 | public function renderTopics(\Smarty $xoopsTpl = null) |
||
| 871 | { |
||
| 872 | $myts = \MyTextSanitizer::getInstance(); // irmtfan Instanciate |
||
| 873 | |||
| 874 | $ret = []; |
||
| 875 | //$this->parseVars(); |
||
| 1134 | } |
||
| 1135 | |||
| 1136 | // START irmtfan to create an array from selected keys of an array |
||
| 1137 | |||
| 1138 | /** |
||
| 1139 | * @param $array |
||
| 1140 | * @param null $keys |
||
| 1141 | * @return array |
||
| 1142 | */ |
||
| 1143 | public function getFromKeys($array, $keys = null) |
||
| 1160 |