@@ -8,127 +8,127 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class Utility |
| 10 | 10 | { |
| 11 | - use Common\VersionChecks; //checkVerXoops, checkVerPhp Traits |
|
| 12 | - |
|
| 13 | - use Common\ServerStats; // getServerStats Trait |
|
| 14 | - |
|
| 15 | - use Common\FilesManagement; // Files Management Trait |
|
| 16 | - |
|
| 17 | - //--------------- Custom module methods ----------------------------- |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Verify that a mysql table exists |
|
| 21 | - * |
|
| 22 | - * @package News |
|
| 23 | - * @author Hervé Thouzard (http://www.herve-thouzard.com) |
|
| 24 | - * @copyright (c) Hervé Thouzard |
|
| 25 | - * @param $tablename |
|
| 26 | - * @return bool |
|
| 27 | - */ |
|
| 28 | - public function tableExists($tablename) |
|
| 29 | - { |
|
| 30 | - global $xoopsDB; |
|
| 31 | - /** @var \XoopsMySQLDatabase $xoopsDB */ |
|
| 32 | - $result = $xoopsDB->queryF("SHOW TABLES LIKE '$tablename'"); |
|
| 33 | - |
|
| 34 | - return ($xoopsDB->getRowsNum($result) > 0); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Verify that a field exists inside a mysql table |
|
| 39 | - * |
|
| 40 | - * @package News |
|
| 41 | - * @author Hervé Thouzard (http://www.herve-thouzard.com) |
|
| 42 | - * @copyright (c) Hervé Thouzard |
|
| 43 | - * @param $fieldname |
|
| 44 | - * @param $table |
|
| 45 | - * @return bool |
|
| 46 | - */ |
|
| 47 | - public function fieldExists($fieldname, $table) |
|
| 48 | - { |
|
| 49 | - global $xoopsDB; |
|
| 50 | - $result = $xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); |
|
| 51 | - |
|
| 52 | - return ($xoopsDB->getRowsNum($result) > 0); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Add a field to a mysql table |
|
| 57 | - * |
|
| 58 | - * @package News |
|
| 59 | - * @author Hervé Thouzard (http://www.herve-thouzard.com) |
|
| 60 | - * @copyright (c) Hervé Thouzard |
|
| 61 | - * @param $field |
|
| 62 | - * @param $table |
|
| 63 | - * @return bool|\mysqli_result |
|
| 64 | - */ |
|
| 65 | - public function addField($field, $table) |
|
| 66 | - { |
|
| 67 | - global $xoopsDB; |
|
| 68 | - $result = $xoopsDB->queryF('ALTER TABLE ' . $table . " ADD $field"); |
|
| 69 | - |
|
| 70 | - return $result; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
|
| 75 | - * |
|
| 76 | - * @param string $folder Le chemin complet du répertoire à vérifier |
|
| 77 | - * |
|
| 78 | - * @return void |
|
| 79 | - */ |
|
| 80 | - public static function prepareFolder($folder) |
|
| 81 | - { |
|
| 82 | - try { |
|
| 83 | - if (!@mkdir($folder) && !is_dir($folder)) { |
|
| 84 | - throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
| 85 | - } else { |
|
| 86 | - file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
| 87 | - } |
|
| 88 | - } catch (\Exception $e) { |
|
| 89 | - echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - public static function cleanCache() |
|
| 94 | - { |
|
| 95 | - $cacheHelper = new \Xmf\Module\Helper\Cache('newbb'); |
|
| 96 | - if (method_exists($cacheHelper, 'clear')) { |
|
| 97 | - $cacheHelper->clear(); |
|
| 98 | - return; |
|
| 99 | - } |
|
| 100 | - // for 2.5 systems, clear everything |
|
| 101 | - require_once XOOPS_ROOT_PATH . '/modules/system/class/maintenance.php'; |
|
| 102 | - $maintenance = new \SystemMaintenance(); |
|
| 103 | - $cacheList = [ |
|
| 104 | - 3, // xoops_cache |
|
| 105 | - ]; |
|
| 106 | - $maintenance->CleanCache($cacheList); |
|
| 107 | - xoops_setActiveModules(); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Checks if a user is admin of NewBB |
|
| 112 | - * |
|
| 113 | - * @return boolean |
|
| 114 | - */ |
|
| 115 | - public static function userIsAdmin() |
|
| 116 | - { |
|
| 117 | - /** @var Newbb\Helper $helper */ |
|
| 118 | - $helper = Newbb\Helper::getInstance(); |
|
| 119 | - |
|
| 120 | - static $newbbIsAdmin; |
|
| 121 | - |
|
| 122 | - if (isset($newbbIsAdmin)) { |
|
| 123 | - return $newbbIsAdmin; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - if (!$GLOBALS['xoopsUser']) { |
|
| 127 | - $newbbIsAdmin = false; |
|
| 128 | - } else { |
|
| 129 | - $newbbIsAdmin = $GLOBALS['xoopsUser']->isAdmin($helper->getModule()->getVar('mid')); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return $newbbIsAdmin; |
|
| 133 | - } |
|
| 11 | + use Common\VersionChecks; //checkVerXoops, checkVerPhp Traits |
|
| 12 | + |
|
| 13 | + use Common\ServerStats; // getServerStats Trait |
|
| 14 | + |
|
| 15 | + use Common\FilesManagement; // Files Management Trait |
|
| 16 | + |
|
| 17 | + //--------------- Custom module methods ----------------------------- |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Verify that a mysql table exists |
|
| 21 | + * |
|
| 22 | + * @package News |
|
| 23 | + * @author Hervé Thouzard (http://www.herve-thouzard.com) |
|
| 24 | + * @copyright (c) Hervé Thouzard |
|
| 25 | + * @param $tablename |
|
| 26 | + * @return bool |
|
| 27 | + */ |
|
| 28 | + public function tableExists($tablename) |
|
| 29 | + { |
|
| 30 | + global $xoopsDB; |
|
| 31 | + /** @var \XoopsMySQLDatabase $xoopsDB */ |
|
| 32 | + $result = $xoopsDB->queryF("SHOW TABLES LIKE '$tablename'"); |
|
| 33 | + |
|
| 34 | + return ($xoopsDB->getRowsNum($result) > 0); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Verify that a field exists inside a mysql table |
|
| 39 | + * |
|
| 40 | + * @package News |
|
| 41 | + * @author Hervé Thouzard (http://www.herve-thouzard.com) |
|
| 42 | + * @copyright (c) Hervé Thouzard |
|
| 43 | + * @param $fieldname |
|
| 44 | + * @param $table |
|
| 45 | + * @return bool |
|
| 46 | + */ |
|
| 47 | + public function fieldExists($fieldname, $table) |
|
| 48 | + { |
|
| 49 | + global $xoopsDB; |
|
| 50 | + $result = $xoopsDB->queryF("SHOW COLUMNS FROM $table LIKE '$fieldname'"); |
|
| 51 | + |
|
| 52 | + return ($xoopsDB->getRowsNum($result) > 0); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Add a field to a mysql table |
|
| 57 | + * |
|
| 58 | + * @package News |
|
| 59 | + * @author Hervé Thouzard (http://www.herve-thouzard.com) |
|
| 60 | + * @copyright (c) Hervé Thouzard |
|
| 61 | + * @param $field |
|
| 62 | + * @param $table |
|
| 63 | + * @return bool|\mysqli_result |
|
| 64 | + */ |
|
| 65 | + public function addField($field, $table) |
|
| 66 | + { |
|
| 67 | + global $xoopsDB; |
|
| 68 | + $result = $xoopsDB->queryF('ALTER TABLE ' . $table . " ADD $field"); |
|
| 69 | + |
|
| 70 | + return $result; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
|
| 75 | + * |
|
| 76 | + * @param string $folder Le chemin complet du répertoire à vérifier |
|
| 77 | + * |
|
| 78 | + * @return void |
|
| 79 | + */ |
|
| 80 | + public static function prepareFolder($folder) |
|
| 81 | + { |
|
| 82 | + try { |
|
| 83 | + if (!@mkdir($folder) && !is_dir($folder)) { |
|
| 84 | + throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
| 85 | + } else { |
|
| 86 | + file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
| 87 | + } |
|
| 88 | + } catch (\Exception $e) { |
|
| 89 | + echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + public static function cleanCache() |
|
| 94 | + { |
|
| 95 | + $cacheHelper = new \Xmf\Module\Helper\Cache('newbb'); |
|
| 96 | + if (method_exists($cacheHelper, 'clear')) { |
|
| 97 | + $cacheHelper->clear(); |
|
| 98 | + return; |
|
| 99 | + } |
|
| 100 | + // for 2.5 systems, clear everything |
|
| 101 | + require_once XOOPS_ROOT_PATH . '/modules/system/class/maintenance.php'; |
|
| 102 | + $maintenance = new \SystemMaintenance(); |
|
| 103 | + $cacheList = [ |
|
| 104 | + 3, // xoops_cache |
|
| 105 | + ]; |
|
| 106 | + $maintenance->CleanCache($cacheList); |
|
| 107 | + xoops_setActiveModules(); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Checks if a user is admin of NewBB |
|
| 112 | + * |
|
| 113 | + * @return boolean |
|
| 114 | + */ |
|
| 115 | + public static function userIsAdmin() |
|
| 116 | + { |
|
| 117 | + /** @var Newbb\Helper $helper */ |
|
| 118 | + $helper = Newbb\Helper::getInstance(); |
|
| 119 | + |
|
| 120 | + static $newbbIsAdmin; |
|
| 121 | + |
|
| 122 | + if (isset($newbbIsAdmin)) { |
|
| 123 | + return $newbbIsAdmin; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + if (!$GLOBALS['xoopsUser']) { |
|
| 127 | + $newbbIsAdmin = false; |
|
| 128 | + } else { |
|
| 129 | + $newbbIsAdmin = $GLOBALS['xoopsUser']->isAdmin($helper->getModule()->getVar('mid')); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return $newbbIsAdmin; |
|
| 133 | + } |
|
| 134 | 134 | } |
@@ -20,47 +20,47 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class UserstatsHandler extends \XoopsPersistableObjectHandler |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @param \XoopsDatabase $db |
|
| 25 | - */ |
|
| 26 | - public function __construct(\XoopsDatabase $db) |
|
| 27 | - { |
|
| 28 | - parent::__construct($db, 'newbb_user_stats', Userstats::class, 'uid', ''); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @param null $db |
|
| 33 | - * @return UserstatsHandler |
|
| 34 | - */ |
|
| 35 | - public static function getInstance($db = null) |
|
| 36 | - { |
|
| 37 | - static $instance; |
|
| 38 | - if (null === $instance) { |
|
| 39 | - $instance = new static($db); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - return $instance; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param mixed $id |
|
| 47 | - * @param null $fields |
|
| 48 | - * @return null|\XoopsObject |
|
| 49 | - */ |
|
| 50 | - public function get($id = null, $fields = null) //get($id) |
|
| 51 | - { |
|
| 52 | - $object = null; |
|
| 53 | - if (!$id = (int)$id) { |
|
| 54 | - return $object; |
|
| 55 | - } |
|
| 56 | - $object = $this->create(false); |
|
| 57 | - $object->setVar($this->keyName, $id); |
|
| 58 | - if (!$row = $this->getStats($id)) { |
|
| 59 | - return $object; |
|
| 60 | - } |
|
| 61 | - $object->assignVars($row); |
|
| 62 | - |
|
| 63 | - /* |
|
| 23 | + /** |
|
| 24 | + * @param \XoopsDatabase $db |
|
| 25 | + */ |
|
| 26 | + public function __construct(\XoopsDatabase $db) |
|
| 27 | + { |
|
| 28 | + parent::__construct($db, 'newbb_user_stats', Userstats::class, 'uid', ''); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @param null $db |
|
| 33 | + * @return UserstatsHandler |
|
| 34 | + */ |
|
| 35 | + public static function getInstance($db = null) |
|
| 36 | + { |
|
| 37 | + static $instance; |
|
| 38 | + if (null === $instance) { |
|
| 39 | + $instance = new static($db); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + return $instance; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param mixed $id |
|
| 47 | + * @param null $fields |
|
| 48 | + * @return null|\XoopsObject |
|
| 49 | + */ |
|
| 50 | + public function get($id = null, $fields = null) //get($id) |
|
| 51 | + { |
|
| 52 | + $object = null; |
|
| 53 | + if (!$id = (int)$id) { |
|
| 54 | + return $object; |
|
| 55 | + } |
|
| 56 | + $object = $this->create(false); |
|
| 57 | + $object->setVar($this->keyName, $id); |
|
| 58 | + if (!$row = $this->getStats($id)) { |
|
| 59 | + return $object; |
|
| 60 | + } |
|
| 61 | + $object->assignVars($row); |
|
| 62 | + |
|
| 63 | + /* |
|
| 64 | 64 | $sql = "SELECT * FROM " . $this->table . " WHERE ".$this->keyName." = " . $id; |
| 65 | 65 | if (!$result = $this->db->query($sql)) { |
| 66 | 66 | return $object; |
@@ -70,27 +70,27 @@ discard block |
||
| 70 | 70 | } |
| 71 | 71 | */ |
| 72 | 72 | |
| 73 | - return $object; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param $id |
|
| 78 | - * @return null|array |
|
| 79 | - */ |
|
| 80 | - public function getStats($id) |
|
| 81 | - { |
|
| 82 | - if (empty($id)) { |
|
| 83 | - return null; |
|
| 84 | - } |
|
| 85 | - $sql = 'SELECT * FROM ' . $this->table . ' WHERE ' . $this->keyName . ' = ' . (int)$id; |
|
| 86 | - if (!$result = $this->db->query($sql)) { |
|
| 87 | - return null; |
|
| 88 | - } |
|
| 89 | - $row = $this->db->fetchArray($result); |
|
| 90 | - |
|
| 91 | - return $row; |
|
| 92 | - } |
|
| 93 | - /* |
|
| 73 | + return $object; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param $id |
|
| 78 | + * @return null|array |
|
| 79 | + */ |
|
| 80 | + public function getStats($id) |
|
| 81 | + { |
|
| 82 | + if (empty($id)) { |
|
| 83 | + return null; |
|
| 84 | + } |
|
| 85 | + $sql = 'SELECT * FROM ' . $this->table . ' WHERE ' . $this->keyName . ' = ' . (int)$id; |
|
| 86 | + if (!$result = $this->db->query($sql)) { |
|
| 87 | + return null; |
|
| 88 | + } |
|
| 89 | + $row = $this->db->fetchArray($result); |
|
| 90 | + |
|
| 91 | + return $row; |
|
| 92 | + } |
|
| 93 | + /* |
|
| 94 | 94 | function insert(\XoopsObject $object, $force = true) |
| 95 | 95 | { |
| 96 | 96 | if (!$object->isDirty()) { |
@@ -24,12 +24,12 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class Constants |
| 26 | 26 | { |
| 27 | - /**#@+ |
|
| 27 | + /**#@+ |
|
| 28 | 28 | * Constant definition |
| 29 | 29 | */ |
| 30 | 30 | |
| 31 | - const DISALLOW = 0; |
|
| 31 | + const DISALLOW = 0; |
|
| 32 | 32 | |
| 33 | - /**#@-*/ |
|
| 33 | + /**#@-*/ |
|
| 34 | 34 | } |
| 35 | 35 | |
@@ -25,1133 +25,1133 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class TopicRenderer |
| 27 | 27 | { |
| 28 | - public $vars = []; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * reference to moduleConfig |
|
| 32 | - */ |
|
| 33 | - public $config; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Current user has no access to current page |
|
| 37 | - */ |
|
| 38 | - private $noperm = false; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * For multiple forums |
|
| 42 | - */ |
|
| 43 | - public $is_multiple = false; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * force to parse vars (run against static vars) irmtfan |
|
| 47 | - */ |
|
| 48 | - public $force = false; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Vistitor's level: 0 - anonymous; 1 - user; 2 - moderator or admin |
|
| 52 | - */ |
|
| 53 | - public $userlevel = 0; |
|
| 54 | - |
|
| 55 | - public $query = []; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * reference to an object handler |
|
| 59 | - */ |
|
| 60 | - private $handler; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Requested page |
|
| 64 | - */ |
|
| 65 | - private $page = 'list.topic.php'; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * query variables |
|
| 69 | - */ |
|
| 70 | - private $args = ['forum', 'uid', 'lastposter', 'type', 'status', 'mode', 'sort', 'order', 'start', 'since']; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Constructor |
|
| 74 | - */ |
|
| 75 | - // public function TopicRenderer() |
|
| 76 | - public function __construct() |
|
| 77 | - { |
|
| 78 | - $this->handler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Access the only instance of this class |
|
| 83 | - * @return TopicRenderer |
|
| 84 | - */ |
|
| 85 | - public static function getInstance() |
|
| 86 | - { |
|
| 87 | - static $instance; |
|
| 88 | - if (null === $instance) { |
|
| 89 | - $instance = new static(); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - return $instance; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - public function init() |
|
| 96 | - { |
|
| 97 | - $this->noperm = false; |
|
| 98 | - $this->query = []; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @param $var |
|
| 103 | - * @param $val |
|
| 104 | - * @return array|int|string |
|
| 105 | - */ |
|
| 106 | - public function setVar($var, $val) |
|
| 107 | - { |
|
| 108 | - switch ($var) { |
|
| 109 | - case 'forum': |
|
| 110 | - if (is_numeric($val)) { |
|
| 111 | - $val = (int)$val; |
|
| 112 | - // START irmtfan - if the forum is array |
|
| 113 | - } elseif (is_array($val)) { |
|
| 114 | - $val = implode('|', $val); |
|
| 115 | - //} elseif (!empty($val)) { |
|
| 116 | - // $val = implode("|", array_map("intval", explode(", ", $val))); |
|
| 117 | - } |
|
| 118 | - // END irmtfan - if the forum is array |
|
| 119 | - break; |
|
| 120 | - |
|
| 121 | - case 'type': |
|
| 122 | - case 'mode': |
|
| 123 | - case 'order': |
|
| 124 | - case 'start': |
|
| 125 | - case 'since': |
|
| 126 | - $val = (int)$val; |
|
| 127 | - break; |
|
| 128 | - |
|
| 129 | - case 'uid': // irmtfan add multi topic poster |
|
| 130 | - case 'lastposter': // irmtfan add multi lastposter |
|
| 131 | - break; |
|
| 132 | - |
|
| 133 | - case 'status': |
|
| 134 | - // START irmtfan to accept multiple status |
|
| 135 | - $val = is_array($val) ? $val : [$val]; |
|
| 136 | - $val = implode(',', $val); |
|
| 137 | - //$val = (in_array($val, array_keys($this->getStatus( $this->userlevel ))) ) ? $val : "all"; //irmtfan no need to check if status is empty or not |
|
| 138 | - //if ($val === "all" && !$this->is_multiple) $val = ""; irmtfan commented because it is done in sort |
|
| 139 | - // END irmtfan to accept multiple status |
|
| 140 | - break; |
|
| 141 | - |
|
| 142 | - default: |
|
| 143 | - break; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return $val; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @param array $vars |
|
| 151 | - */ |
|
| 152 | - public function setVars(array $vars = []) |
|
| 153 | - { |
|
| 154 | - $this->init(); |
|
| 155 | - |
|
| 156 | - foreach ($vars as $var => $val) { |
|
| 157 | - if (!in_array($var, $this->args)) { |
|
| 158 | - continue; |
|
| 159 | - } |
|
| 160 | - $this->vars[$var] = $this->setVar($var, $val); |
|
| 161 | - } |
|
| 162 | - $this->parseVars(); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @param null $status |
|
| 167 | - */ |
|
| 168 | - public function myParseStatus($status = null) |
|
| 169 | - { |
|
| 170 | - switch ($status) { |
|
| 171 | - case 'digest': |
|
| 172 | - $this->query['where'][] = 't.topic_digest = 1'; |
|
| 173 | - break; |
|
| 174 | - |
|
| 175 | - case 'undigest': |
|
| 176 | - $this->query['where'][] = 't.topic_digest = 0'; |
|
| 177 | - break; |
|
| 178 | - |
|
| 179 | - case 'sticky': |
|
| 180 | - $this->query['where'][] = 't.topic_sticky = 1'; |
|
| 181 | - break; |
|
| 182 | - |
|
| 183 | - case 'unsticky': |
|
| 184 | - $this->query['where'][] = 't.topic_sticky = 0'; |
|
| 185 | - break; |
|
| 186 | - |
|
| 187 | - case 'lock': |
|
| 188 | - $this->query['where'][] = 't.topic_status = 1'; |
|
| 189 | - break; |
|
| 190 | - |
|
| 191 | - case 'unlock': |
|
| 192 | - $this->query['where'][] = 't.topic_status = 0'; |
|
| 193 | - break; |
|
| 194 | - |
|
| 195 | - case 'poll': |
|
| 196 | - $this->query['where'][] = 't.topic_haspoll = 1'; |
|
| 197 | - break; |
|
| 198 | - |
|
| 199 | - case 'unpoll': |
|
| 200 | - $this->query['where'][] = 't.topic_haspoll = 0'; |
|
| 201 | - break; |
|
| 202 | - |
|
| 203 | - case 'voted': |
|
| 204 | - $this->query['where'][] = 't.votes > 0'; |
|
| 205 | - break; |
|
| 206 | - |
|
| 207 | - case 'unvoted': |
|
| 208 | - $this->query['where'][] = 't.votes < 1'; |
|
| 209 | - break; |
|
| 210 | - |
|
| 211 | - case 'replied': |
|
| 212 | - $this->query['where'][] = 't.topic_replies > 0'; |
|
| 213 | - break; |
|
| 214 | - |
|
| 215 | - case 'unreplied': |
|
| 216 | - $this->query['where'][] = 't.topic_replies < 1'; |
|
| 217 | - break; |
|
| 218 | - |
|
| 219 | - case 'viewed': |
|
| 220 | - $this->query['where'][] = 't.topic_views > 0'; |
|
| 221 | - break; |
|
| 222 | - |
|
| 223 | - case 'unviewed': |
|
| 224 | - $this->query['where'][] = 't.topic_views < 1'; |
|
| 225 | - break; |
|
| 226 | - |
|
| 227 | - case 'read': |
|
| 228 | - // Skip |
|
| 229 | - if (empty($this->config['read_mode'])) { |
|
| 230 | - // Use database |
|
| 231 | - } elseif (2 == $this->config['read_mode']) { |
|
| 232 | - // START irmtfan use read_uid to find the unread posts when the user is logged in |
|
| 233 | - $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
| 234 | - if (!empty($read_uid)) { |
|
| 235 | - $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 . ' '; |
|
| 236 | - $this->query['where'][] = 'r.post_id = t.topic_last_post_id'; |
|
| 237 | - } else { |
|
| 238 | - } |
|
| 239 | - // END irmtfan change criteria to get from uid p.uid = last post submit user id |
|
| 240 | - // User cookie |
|
| 241 | - } elseif (1 == $this->config['read_mode']) { |
|
| 242 | - // START irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
| 243 | - $startdate = !empty($this->vars['since']) ? (time() - newbbGetSinceTime($this->vars['since'])) : 0; |
|
| 244 | - if ($lastvisit = max($GLOBALS['last_visit'], $startdate)) { |
|
| 245 | - $readmode1query = ''; |
|
| 246 | - if ($lastvisit > $startdate) { |
|
| 247 | - $readmode1query = 'p.post_time < ' . $lastvisit; |
|
| 248 | - } |
|
| 249 | - $topics = []; |
|
| 250 | - $topic_lastread = newbbGetCookie('LT', true); |
|
| 251 | - if (count($topic_lastread) > 0) { |
|
| 252 | - foreach ($topic_lastread as $id => $time) { |
|
| 253 | - if ($time > $lastvisit) { |
|
| 254 | - $topics[] = $id; |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - if (count($topics) > 0) { |
|
| 259 | - $topicquery = ' t.topic_id IN (' . implode(',', $topics) . ')'; |
|
| 260 | - // because it should be OR |
|
| 261 | - $readmode1query = !empty($readmode1query) ? '(' . $readmode1query . ' OR ' . $topicquery . ')' : $topicquery; |
|
| 262 | - } |
|
| 263 | - $this->query['where'][] = $readmode1query; |
|
| 264 | - } |
|
| 265 | - // END irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
| 266 | - } |
|
| 267 | - break; |
|
| 268 | - |
|
| 269 | - case 'unread': |
|
| 270 | - // Skip |
|
| 271 | - if (empty($this->config['read_mode'])) { |
|
| 272 | - // Use database |
|
| 273 | - } elseif (2 == $this->config['read_mode']) { |
|
| 274 | - // START irmtfan use read_uid to find the unread posts when the user is logged in |
|
| 275 | - $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
| 276 | - if (!empty($read_uid)) { |
|
| 277 | - $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 . ' '; |
|
| 278 | - $this->query['where'][] = '(r.read_id IS NULL OR r.post_id < t.topic_last_post_id)'; |
|
| 279 | - } else { |
|
| 280 | - } |
|
| 281 | - // END irmtfan change criteria to get from uid p.uid = last post submit user id |
|
| 282 | - // User cookie |
|
| 283 | - } elseif (1 == $this->config['read_mode']) { |
|
| 284 | - // START irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
| 285 | - $startdate = !empty($this->vars['since']) ? (time() - newbbGetSinceTime($this->vars['since'])) : 0; |
|
| 286 | - if ($lastvisit = max($GLOBALS['last_visit'], $startdate)) { |
|
| 287 | - if ($lastvisit > $startdate) { |
|
| 288 | - $this->query['where'][] = 'p.post_time > ' . $lastvisit; |
|
| 289 | - } |
|
| 290 | - $topics = []; |
|
| 291 | - $topic_lastread = newbbGetCookie('LT', true); |
|
| 292 | - if (count($topic_lastread) > 0) { |
|
| 293 | - foreach ($topic_lastread as $id => $time) { |
|
| 294 | - if ($time > $lastvisit) { |
|
| 295 | - $topics[] = $id; |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - if (count($topics) > 0) { |
|
| 300 | - $this->query['where'][] = ' t.topic_id NOT IN (' . implode(',', $topics) . ')'; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - // END irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
| 304 | - } |
|
| 305 | - break; |
|
| 306 | - |
|
| 307 | - case 'pending': |
|
| 308 | - if ($this->userlevel < 2) { |
|
| 309 | - $this->noperm = true; |
|
| 310 | - } else { |
|
| 311 | - $this->query['where'][] = 't.approved = 0'; |
|
| 312 | - } |
|
| 313 | - break; |
|
| 314 | - |
|
| 315 | - case 'deleted': |
|
| 316 | - if ($this->userlevel < 2) { |
|
| 317 | - $this->noperm = true; |
|
| 318 | - } else { |
|
| 319 | - $this->query['where'][] = 't.approved = -1'; |
|
| 320 | - } |
|
| 321 | - break; |
|
| 322 | - |
|
| 323 | - case 'all': // For viewall.php; do not display sticky topics at first |
|
| 324 | - case 'active': // same as 'all' |
|
| 325 | - $this->query['where'][] = 't.approved = 1'; |
|
| 326 | - break; |
|
| 327 | - |
|
| 328 | - default: // irmtfan do nothing |
|
| 329 | - break; |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * @param $var |
|
| 335 | - * @param $val |
|
| 336 | - */ |
|
| 337 | - public function parseVar($var, $val) |
|
| 338 | - { |
|
| 339 | - switch ($var) { |
|
| 340 | - case 'forum': |
|
| 341 | - /** @var Newbb\ForumHandler $forumHandler */ |
|
| 342 | - $forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
| 343 | - // START irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums |
|
| 344 | - // Get accessible forums |
|
| 345 | - $accessForums = $forumHandler->getIdsByValues(array_map('intval', @explode('|', $val))); |
|
| 346 | - // Filter specified forums if any |
|
| 347 | - //if (!empty($val) && $_forums = @explode('|', $val)) { |
|
| 348 | - //$accessForums = array_intersect($accessForums, array_map('intval', $_forums)); |
|
| 349 | - //} |
|
| 350 | - $this->vars['forum'] = $this->setVar('forum', $accessForums); |
|
| 351 | - // END irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums |
|
| 352 | - |
|
| 353 | - if (empty($accessForums)) { |
|
| 354 | - $this->noperm = true; |
|
| 355 | - // 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. |
|
| 356 | - //} elseif (count($accessForums) === 1) { |
|
| 357 | - //$this->query["where"][] = "t.forum_id = " . $accessForums[0]; |
|
| 358 | - } else { |
|
| 359 | - $this->query['where'][] = 't.forum_id IN ( ' . implode(', ', $accessForums) . ' )'; |
|
| 360 | - } |
|
| 361 | - break; |
|
| 362 | - |
|
| 363 | - case 'uid': // irmtfan add multi topic poster |
|
| 364 | - if (-1 !== $val) { |
|
| 365 | - $val = implode(',', array_map('intval', explode(',', $val))); |
|
| 366 | - $this->query['where'][] = 't.topic_poster IN ( ' . $val . ' )'; |
|
| 367 | - } |
|
| 368 | - break; |
|
| 369 | - case 'lastposter': // irmtfan add multi lastposter |
|
| 370 | - if (-1 !== $val) { |
|
| 371 | - $val = implode(',', array_map('intval', explode(',', $val))); |
|
| 372 | - $this->query['where'][] = 'p.uid IN ( ' . $val . ' )'; |
|
| 373 | - } |
|
| 374 | - break; |
|
| 375 | - |
|
| 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'], true)) && 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'], true))) { |
|
| 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 | - |
|
| 394 | - case 'type': |
|
| 395 | - if (!empty($val)) { |
|
| 396 | - $this->query['where'][] = 't.type_id = ' . $val; |
|
| 397 | - } |
|
| 398 | - break; |
|
| 399 | - |
|
| 400 | - case 'status': |
|
| 401 | - // START irmtfan to accept multiple status |
|
| 402 | - $val = explode(',', $val); |
|
| 403 | - // irmtfan - add 'all' to always parse t.approved = 1 |
|
| 404 | - if (0 === count(array_intersect($val, ['all', 'active', 'pending', 'deleted']))) { |
|
| 405 | - $val[] = 'all'; |
|
| 406 | - } |
|
| 407 | - foreach ($val as $key => $status) { |
|
| 408 | - $this->myParseStatus($status); |
|
| 409 | - } |
|
| 410 | - // END irmtfan to accept multiple status |
|
| 411 | - break; |
|
| 412 | - |
|
| 413 | - case 'sort': |
|
| 414 | - if ($sort = $this->getSort($val, 'sort')) { |
|
| 415 | - $this->query['sort'][] = $sort . (empty($this->vars['order']) ? ' DESC' : ' ASC'); |
|
| 416 | - } else { // irmtfan if sort is not in the list |
|
| 417 | - $this->query['sort'][] = 't.topic_last_post_id' . (empty($this->vars['order']) ? ' DESC' : ' ASC'); |
|
| 418 | - } |
|
| 419 | - break; |
|
| 420 | - |
|
| 421 | - default: |
|
| 422 | - break; |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * @return bool |
|
| 428 | - */ |
|
| 429 | - public function parseVars() |
|
| 430 | - { |
|
| 431 | - static $parsed; |
|
| 432 | - // irmtfan - force to parse vars (run against static vars) |
|
| 433 | - if (isset($parsed) && !$this->force) { |
|
| 434 | - return true; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - if (!isset($this->vars['forum'])) { |
|
| 438 | - $this->vars['forum'] = null; |
|
| 439 | - } |
|
| 440 | - //irmtfan parse status for rendering topic correctly - if empty($_GET(status)) it will show all topics include deleted and pendings. 'all' instead of all |
|
| 441 | - if (!isset($this->vars['status'])) { |
|
| 442 | - $this->vars['status'] = 'all'; |
|
| 443 | - } |
|
| 444 | - // 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= |
|
| 445 | - if (empty($this->vars['sort'])) { |
|
| 446 | - $this->vars['sort'] = 'lastpost'; |
|
| 447 | - } // use lastpost instead of sticky |
|
| 448 | - |
|
| 449 | - foreach ($this->vars as $var => $val) { |
|
| 450 | - $this->parseVar($var, $val); |
|
| 451 | - if (empty($val)) { |
|
| 452 | - unset($this->vars[$var]); |
|
| 453 | - } |
|
| 454 | - } |
|
| 455 | - $parsed = true; |
|
| 456 | - |
|
| 457 | - return true; |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * @param null $header |
|
| 462 | - * @param null $var |
|
| 463 | - * @return array|null |
|
| 464 | - */ |
|
| 465 | - public function getSort($header = null, $var = null) |
|
| 466 | - { |
|
| 467 | - $headers = [ |
|
| 468 | - 'topic' => [ |
|
| 469 | - 'title' => _MD_NEWBB_TOPICS, |
|
| 470 | - 'sort' => 't.topic_title' |
|
| 471 | - ], |
|
| 472 | - 'forum' => [ |
|
| 473 | - 'title' => _MD_NEWBB_FORUM, |
|
| 474 | - 'sort' => 't.forum_id' |
|
| 475 | - ], |
|
| 476 | - 'poster' => [ |
|
| 477 | - 'title' => _MD_NEWBB_TOPICPOSTER, /*irmtfan _MD_NEWBB_POSTER to _MD_NEWBB_TOPICPOSTER*/ |
|
| 478 | - 'sort' => 't.topic_poster' |
|
| 479 | - ], |
|
| 480 | - 'replies' => [ |
|
| 481 | - 'title' => _MD_NEWBB_REPLIES, |
|
| 482 | - 'sort' => 't.topic_replies' |
|
| 483 | - ], |
|
| 484 | - 'views' => [ |
|
| 485 | - 'title' => _MD_NEWBB_VIEWS, |
|
| 486 | - 'sort' => 't.topic_views' |
|
| 487 | - ], |
|
| 488 | - 'lastpost' => [ // irmtfan show topic_page_jump_icon smarty |
|
| 489 | - 'title' => _MD_NEWBB_LASTPOST, |
|
| 490 | - /*irmtfan _MD_NEWBB_DATE to _MD_NEWBB_LASTPOSTTIME again change to _MD_LASTPOST*/ |
|
| 491 | - 'sort' => 't.topic_last_post_id' |
|
| 492 | - ], |
|
| 493 | - // START irmtfan add more sorts |
|
| 494 | - 'lastposttime' => [ // irmtfan same as lastpost |
|
| 495 | - 'title' => _MD_NEWBB_LASTPOSTTIME, |
|
| 496 | - 'sort' => 't.topic_last_post_id' |
|
| 497 | - ], |
|
| 498 | - 'lastposter' => [ // irmtfan |
|
| 499 | - 'title' => _MD_NEWBB_POSTER, |
|
| 500 | - 'sort' => 'p.uid',// poster uid |
|
| 501 | - ], |
|
| 502 | - 'lastpostmsgicon' => [ // irmtfan |
|
| 503 | - 'title' => _MD_NEWBB_MESSAGEICON, |
|
| 504 | - 'sort' => 'p.icon',// post message icon |
|
| 505 | - ], |
|
| 506 | - 'ratings' => [ |
|
| 507 | - 'title' => _MD_NEWBB_RATINGS, |
|
| 508 | - 'sort' => 't.rating', // irmtfan t.topic_rating to t.rating |
|
| 509 | - ], |
|
| 510 | - 'votes' => [ |
|
| 511 | - 'title' => _MD_NEWBB_VOTES, |
|
| 512 | - 'sort' => 't.votes' |
|
| 513 | - ], |
|
| 514 | - 'publish' => [ |
|
| 515 | - 'title' => _MD_NEWBB_TOPICTIME, |
|
| 516 | - 'sort' => 't.topic_id' |
|
| 517 | - ], |
|
| 518 | - 'digest' => [ |
|
| 519 | - 'title' => _MD_NEWBB_DIGEST, |
|
| 520 | - 'sort' => 't.digest_time' |
|
| 521 | - ], |
|
| 522 | - 'sticky' => [ |
|
| 523 | - 'title' => _MD_NEWBB_STICKY, |
|
| 524 | - 'sort' => 't.topic_sticky' |
|
| 525 | - ], |
|
| 526 | - 'lock' => [ |
|
| 527 | - 'title' => _MD_NEWBB_LOCK, |
|
| 528 | - 'sort' => 't.topic_status' |
|
| 529 | - ], |
|
| 530 | - 'poll' => [ |
|
| 531 | - 'title' => _MD_NEWBB_POLL_POLL, |
|
| 532 | - 'sort' => 't.poll_id' |
|
| 533 | - ] |
|
| 534 | - ]; |
|
| 535 | - $types = $this->getTypes(); |
|
| 536 | - if (!empty($types)) { |
|
| 537 | - $headers['type'] = [ |
|
| 538 | - 'title' => _MD_NEWBB_TYPE, |
|
| 539 | - 'sort' => 't.type_id' |
|
| 540 | - ]; |
|
| 541 | - } |
|
| 542 | - if (2 == $this->userlevel) { |
|
| 543 | - $headers['approve'] = [ |
|
| 544 | - 'title' => _MD_NEWBB_APPROVE, |
|
| 545 | - 'sort' => 't.approved' |
|
| 546 | - ]; |
|
| 547 | - } |
|
| 548 | - // END irmtfan add more sorts |
|
| 549 | - if (empty($header) && empty($var)) { |
|
| 550 | - return $headers; |
|
| 551 | - } |
|
| 552 | - if (!empty($var) && !empty($header)) { |
|
| 553 | - return @$headers[$header][$var]; |
|
| 554 | - } |
|
| 555 | - if (empty($var)) { |
|
| 556 | - return @$headers[$header]; |
|
| 557 | - } |
|
| 558 | - $ret = null; |
|
| 559 | - foreach (array_keys($headers) as $key) { |
|
| 560 | - $ret[$key] = @$headers[$key][$var]; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - return $ret; |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - // START irmtfan add Display topic headers function |
|
| 567 | - |
|
| 568 | - /** |
|
| 569 | - * @param null $header |
|
| 570 | - * @return array |
|
| 571 | - */ |
|
| 572 | - public function getHeader($header = null) |
|
| 573 | - { |
|
| 574 | - $headersSort = $this->getSort('', 'title'); |
|
| 575 | - // additional headers - important: those cannot be in sort anyway |
|
| 576 | - $headers = array_merge($headersSort, [ |
|
| 577 | - 'attachment' => _MD_NEWBB_TOPICSHASATT, // show attachment smarty |
|
| 578 | - 'read' => _MD_NEWBB_MARK_UNREAD . '|' . _MD_NEWBB_MARK_READ, // read/unread show topic_folder smarty |
|
| 579 | - 'pagenav' => _MD_NEWBB_PAGENAV_DISPLAY, // show topic_page_jump smarty - sort by topic_replies? |
|
| 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 = 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) |
|
| 757 | - { |
|
| 758 | - $status = ''; |
|
| 759 | - if (!$types = $this->getTypes()) { |
|
| 760 | - return true; |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - $args = []; |
|
| 764 | - foreach ($this->vars as $var => $val) { |
|
| 765 | - if ('type' === $var) { |
|
| 766 | - continue; |
|
| 767 | - } |
|
| 768 | - $args[] = "{$var}={$val}"; |
|
| 769 | - } |
|
| 770 | - |
|
| 771 | - foreach ($types as $id => $type) { |
|
| 772 | - $_args = ["type={$id}"]; |
|
| 773 | - $status[$id]['title'] = $type['type_name']; |
|
| 774 | - $status[$id]['link'] = $this->page . '?' . implode('&', array_merge($args, $_args)); |
|
| 775 | - } |
|
| 776 | - $xoopsTpl->assign_by_ref('types', $status); |
|
| 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) |
|
| 806 | - { |
|
| 807 | - $count_topic = $this->getCount(); |
|
| 808 | - if ($count_topic > $this->config['topics_per_page']) { |
|
| 809 | - $args = []; |
|
| 810 | - foreach ($this->vars as $var => $val) { |
|
| 811 | - if ('start' === $var) { |
|
| 812 | - continue; |
|
| 813 | - } |
|
| 814 | - $args[] = "{$var}={$val}"; |
|
| 815 | - } |
|
| 816 | - require_once $GLOBALS['xoops']->path('class/pagenav.php'); |
|
| 817 | - $nav = new \XoopsPageNav($count_topic, $this->config['topics_per_page'], @$this->vars['start'], 'start', implode('&', $args)); |
|
| 818 | - if (isset($GLOBALS['xoopsModuleConfig']['do_rewrite'])) { |
|
| 819 | - $nav->url = formatURL(Request::getString('SERVER_NAME', '', 'SERVER')) . ' /' . $nav->url; |
|
| 820 | - } |
|
| 821 | - if ('select' === $this->config['pagenav_display']) { |
|
| 822 | - $navi = $nav->renderSelect(); |
|
| 823 | - } elseif ('image' === $this->config['pagenav_display']) { |
|
| 824 | - $navi = $nav->renderImageNav(4); |
|
| 825 | - } else { |
|
| 826 | - $navi = $nav->renderNav(4); |
|
| 827 | - } |
|
| 828 | - $xoopsTpl->assign('pagenav', $navi); |
|
| 829 | - } else { |
|
| 830 | - $xoopsTpl->assign('pagenav', ''); |
|
| 831 | - } |
|
| 832 | - } |
|
| 833 | - |
|
| 834 | - /** |
|
| 835 | - * @return int |
|
| 836 | - */ |
|
| 837 | - public function getCount() |
|
| 838 | - { |
|
| 839 | - if ($this->noperm) { |
|
| 840 | - return 0; |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - $selects = []; |
|
| 844 | - $froms = []; |
|
| 845 | - $joins = []; |
|
| 846 | - $wheres = []; |
|
| 847 | - |
|
| 848 | - // topic fields |
|
| 849 | - $selects[] = 'COUNT(*)'; |
|
| 850 | - |
|
| 851 | - $froms[] = $this->handler->db->prefix('newbb_topics') . ' AS t '; |
|
| 852 | - $joins[] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_posts') . ' AS p ON p.post_id = t.topic_last_post_id'; |
|
| 853 | - $wheres[] = '1 = 1'; |
|
| 854 | - |
|
| 855 | - $sql = ' SELECT ' . implode(', ', $selects) . ' FROM ' . implode(', ', $froms) . ' ' . implode(' ', $joins) . (!empty($this->query['join']) ? ' ' . implode(' ', $this->query['join']) : '') . // irmtfan bug fix: Undefined index: join when post_excerpt = 0 |
|
| 856 | - ' WHERE ' . implode(' AND ', $wheres) . ' AND ' . @implode(' AND ', @$this->query['where']); |
|
| 857 | - |
|
| 858 | - if (!$result = $this->handler->db->query($sql)) { |
|
| 859 | - return 0; |
|
| 860 | - } |
|
| 861 | - list($count) = $this->handler->db->fetchRow($result); |
|
| 862 | - |
|
| 863 | - return $count; |
|
| 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(); |
|
| 876 | - |
|
| 877 | - if ($this->noperm) { |
|
| 878 | - if (is_object($xoopsTpl)) { |
|
| 879 | - $xoopsTpl->assign_by_ref('topics', $ret); |
|
| 880 | - |
|
| 881 | - return; |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - return $ret; |
|
| 885 | - } |
|
| 886 | - |
|
| 887 | - $selects = []; |
|
| 888 | - $froms = []; |
|
| 889 | - $joins = []; |
|
| 890 | - $wheres = []; |
|
| 891 | - |
|
| 892 | - // topic fields |
|
| 893 | - $selects[] = 't.*'; |
|
| 894 | - // post fields |
|
| 895 | - $selects[] = 'p.post_time as last_post_time, p.poster_name as last_poster_name, p.icon, p.post_id, p.uid'; |
|
| 896 | - |
|
| 897 | - $froms[] = $this->handler->db->prefix('newbb_topics') . ' AS t '; |
|
| 898 | - $joins[] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_posts') . ' AS p ON p.post_id = t.topic_last_post_id'; |
|
| 899 | - $wheres[] = '1 = 1'; |
|
| 900 | - |
|
| 901 | - if (!empty($this->config['post_excerpt'])) { |
|
| 902 | - $selects[] = 'p.post_karma, p.require_reply, pt.post_text'; |
|
| 903 | - $this->query['join'][] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_posts_text') . ' AS pt ON pt.post_id = t.topic_last_post_id'; |
|
| 904 | - } |
|
| 905 | - //if (empty($this->query["sort"])) $this->query["sort"][] = 't.topic_last_post_id DESC'; // irmtfan commented no need |
|
| 906 | - |
|
| 907 | - $sql = ' SELECT ' . implode(', ', $selects) . ' FROM ' . implode(', ', $froms) . ' ' . implode(' ', $joins) . (!empty($this->query['join']) ? ' ' . implode(' ', $this->query['join']) : '') . // irmtfan bug fix: Undefined index join when post_excerpt = 0 |
|
| 908 | - ' WHERE ' . implode(' AND ', $wheres) . ' AND ' . @implode(' AND ', @$this->query['where']) . ' ORDER BY ' . implode(', ', $this->query['sort']); |
|
| 909 | - |
|
| 910 | - if (!$result = $this->handler->db->query($sql, $this->config['topics_per_page'], @$this->vars['start'])) { |
|
| 911 | - if (is_object($xoopsTpl)) { |
|
| 912 | - $xoopsTpl->assign_by_ref('topics', $ret); |
|
| 913 | - |
|
| 914 | - return; |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - return $ret; |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - require_once dirname(__DIR__) . '/include/functions.render.php'; |
|
| 921 | - require_once dirname(__DIR__) . '/include/functions.session.php'; |
|
| 922 | - require_once dirname(__DIR__) . '/include/functions.time.php'; |
|
| 923 | - require_once dirname(__DIR__) . '/include/functions.read.php'; |
|
| 924 | - require_once dirname(__DIR__) . '/include/functions.topic.php'; |
|
| 925 | - |
|
| 926 | - $sticky = 0; |
|
| 927 | - $topics = []; |
|
| 928 | - $posters = []; |
|
| 929 | - $reads = []; |
|
| 930 | - $types = []; |
|
| 931 | - $forums = []; |
|
| 932 | - $anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']); |
|
| 933 | - |
|
| 934 | - while (false !== ($myrow = $this->handler->db->fetchArray($result))) { |
|
| 935 | - if ($myrow['topic_sticky']) { |
|
| 936 | - ++$sticky; |
|
| 937 | - } |
|
| 938 | - |
|
| 939 | - // ------------------------------------------------------ |
|
| 940 | - // START irmtfan remove topic_icon hardcode smarty |
|
| 941 | - // topic_icon: just regular topic_icon |
|
| 942 | - if (!empty($myrow['icon'])) { |
|
| 943 | - $topic_icon = '<img align="middle" src="' . XOOPS_URL . '/images/subject/' . htmlspecialchars($myrow['icon'], ENT_QUOTES | ENT_HTML5) . '" alt="" />'; |
|
| 944 | - } else { |
|
| 945 | - $topic_icon = '<img align="middle" src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" />'; |
|
| 946 | - } |
|
| 947 | - // END irmtfan remove topic_icon hardcode smarty |
|
| 948 | - |
|
| 949 | - // ------------------------------------------------------ |
|
| 950 | - // rating_img |
|
| 951 | - $rating = number_format($myrow['rating'] / 2, 0); |
|
| 952 | - // irmtfan - add alt key for rating |
|
| 953 | - if ($rating < 1) { |
|
| 954 | - $rating_img = newbbDisplayImage('blank'); |
|
| 955 | - } else { |
|
| 956 | - $rating_img = newbbDisplayImage('rate' . $rating, constant('_MD_NEWBB_RATE' . $rating)); |
|
| 957 | - } |
|
| 958 | - |
|
| 959 | - // ------------------------------------------------------ |
|
| 960 | - // topic_page_jump |
|
| 961 | - $topic_page_jump = ''; |
|
| 962 | - $topic_page_jump_icon = ''; |
|
| 963 | - $totalpages = ceil(($myrow['topic_replies'] + 1) / $this->config['posts_per_page']); |
|
| 964 | - if ($totalpages > 1) { |
|
| 965 | - $topic_page_jump .= ' '; |
|
| 966 | - $append = false; |
|
| 967 | - for ($i = 1; $i <= $totalpages; ++$i) { |
|
| 968 | - if ($i > 3 && $i < $totalpages) { |
|
| 969 | - if (!$append) { |
|
| 970 | - $topic_page_jump .= '...'; |
|
| 971 | - $append = true; |
|
| 972 | - } |
|
| 973 | - } else { |
|
| 974 | - $topic_page_jump .= '[<a href="' . XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'] . '&start=' . (($i - 1) * $this->config['posts_per_page']) . '">' . $i . '</a>]'; |
|
| 975 | - // irmtfan remove here and move |
|
| 976 | - //$topic_page_jump_icon = "<a href='" . XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id=" . $myrow['topic_id'] . "&start=" . (($i - 1) * $this->config['posts_per_page']) . "" . "'>" . newbbDisplayImage('document',_MD_NEWBB_GOTOLASTPOST) . '</a>'; |
|
| 977 | - } |
|
| 978 | - } |
|
| 979 | - } |
|
| 980 | - // irmtfan - move here for both topics with and without pages - change topic_id to post_id |
|
| 981 | - $topic_page_jump_icon = "<a href='" . XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $myrow['topic_last_post_id'] . '' . "'>" . newbbDisplayImage('lastposticon', _MD_NEWBB_GOTOLASTPOST) . '</a>'; |
|
| 982 | - |
|
| 983 | - // ------------------------------------------------------ |
|
| 984 | - // => topic array |
|
| 985 | - |
|
| 986 | - $topic_title = $myts->htmlSpecialChars($myrow['topic_title']); |
|
| 987 | - // irmtfan use topic_title_excerpt for block topic title length |
|
| 988 | - $topic_title_excerpt = $topic_title; |
|
| 989 | - if (!empty($this->config['topic_title_excerpt'])) { |
|
| 990 | - $topic_title_excerpt = xoops_substr($topic_title, 0, $this->config['topic_title_excerpt']); |
|
| 991 | - } |
|
| 992 | - // irmtfan hardcode class commented |
|
| 993 | - //if ($myrow['topic_digest']) { |
|
| 994 | - // $topic_title = "<span class='digest'>" . $topic_title . "</span>"; |
|
| 995 | - //} |
|
| 996 | - |
|
| 997 | - if (empty($this->config['post_excerpt'])) { |
|
| 998 | - $topic_excerpt = ''; |
|
| 999 | - } elseif (($myrow['post_karma'] > 0 || $myrow['require_reply'] > 0) && !newbbIsAdmin($myrow['forum_id'])) { |
|
| 1000 | - $topic_excerpt = ''; |
|
| 1001 | - } else { |
|
| 1002 | - $topic_excerpt = xoops_substr(newbbHtml2text($myts->displayTarea($myrow['post_text'])), 0, $this->config['post_excerpt']); |
|
| 1003 | - $topic_excerpt = str_replace('[', '[', $myts->htmlSpecialChars($topic_excerpt)); |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - $topics[$myrow['topic_id']] = [ |
|
| 1007 | - 'topic_id' => $myrow['topic_id'], |
|
| 1008 | - 'topic_icon' => $topic_icon, |
|
| 1009 | - 'type_id' => $myrow['type_id'], |
|
| 1010 | - 'topic_title_excerpt' => $topic_title_excerpt, |
|
| 1011 | - //irmtfan use topic_title_excerpt |
|
| 1012 | - //'topic_link' => XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'], // . '&forum=' . $myrow['forum_id'], // irmtfan comment |
|
| 1013 | - 'topic_link' => 'viewtopic.php?topic_id=' . $myrow['topic_id'], |
|
| 1014 | - // irmtfan remove hardcode link |
|
| 1015 | - 'rating_img' => $rating_img, |
|
| 1016 | - 'votes' => $myrow['votes'], |
|
| 1017 | - //irmtfan added |
|
| 1018 | - 'topic_page_jump' => $topic_page_jump, |
|
| 1019 | - 'topic_page_jump_icon' => $topic_page_jump_icon, |
|
| 1020 | - 'topic_replies' => $myrow['topic_replies'], |
|
| 1021 | - 'topic_poster_uid' => $myrow['topic_poster'], |
|
| 1022 | - 'topic_poster_name' => !empty($myrow['poster_name']) ? $myts->htmlSpecialChars($myrow['poster_name']) : $anonymous, |
|
| 1023 | - 'topic_views' => $myrow['topic_views'], |
|
| 1024 | - 'topic_time' => newbbFormatTimestamp($myrow['topic_time']), |
|
| 1025 | - 'topic_last_post_id' => $myrow['topic_last_post_id'], |
|
| 1026 | - //irmtfan added |
|
| 1027 | - 'topic_last_posttime' => newbbFormatTimestamp($myrow['last_post_time']), |
|
| 1028 | - 'topic_last_poster_uid' => $myrow['uid'], |
|
| 1029 | - 'topic_last_poster_name' => !empty($myrow['last_poster_name']) ? $myts->htmlSpecialChars($myrow['last_poster_name']) : $anonymous, |
|
| 1030 | - 'topic_forum' => $myrow['forum_id'], |
|
| 1031 | - 'topic_excerpt' => $topic_excerpt, |
|
| 1032 | - 'sticky' => $myrow['topic_sticky'] ? newbbDisplayImage('topic_sticky', _MD_NEWBB_TOPICSTICKY) : '', |
|
| 1033 | - // irmtfan bug fixed |
|
| 1034 | - 'lock' => $myrow['topic_status'] ? newbbDisplayImage('topic_locked', _MD_NEWBB_TOPICLOCK) : '', |
|
| 1035 | - //irmtfan added |
|
| 1036 | - 'digest' => $myrow['topic_digest'] ? newbbDisplayImage('topic_digest', _MD_NEWBB_TOPICDIGEST) : '', |
|
| 1037 | - //irmtfan added |
|
| 1038 | - 'poll' => $myrow['topic_haspoll'] ? newbbDisplayImage('poll', _MD_NEWBB_TOPICHASPOLL) : '', |
|
| 1039 | - //irmtfan added |
|
| 1040 | - 'approve' => $myrow['approved'], |
|
| 1041 | - //irmtfan added |
|
| 1042 | - ]; |
|
| 1043 | - |
|
| 1044 | - /* users */ |
|
| 1045 | - $posters[$myrow['topic_poster']] = 1; |
|
| 1046 | - $posters[$myrow['uid']] = 1; |
|
| 1047 | - // reads |
|
| 1048 | - if (!empty($this->config['read_mode'])) { |
|
| 1049 | - $reads[$myrow['topic_id']] = (1 == $this->config['read_mode']) ? $myrow['last_post_time'] : $myrow['topic_last_post_id']; |
|
| 1050 | - } |
|
| 1051 | - // types |
|
| 1052 | - if (!empty($myrow['type_id'])) { |
|
| 1053 | - //$types[$myrow['type_id']] = 1; |
|
| 1054 | - } |
|
| 1055 | - // forums |
|
| 1056 | - $forums[$myrow['forum_id']] = 1; |
|
| 1057 | - } |
|
| 1058 | - $posters_name = newbbGetUnameFromIds(array_keys($posters), $this->config['show_realname'], true); |
|
| 1059 | - $topic_isRead = newbbIsRead('topic', $reads); |
|
| 1060 | - /* |
|
| 28 | + public $vars = []; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * reference to moduleConfig |
|
| 32 | + */ |
|
| 33 | + public $config; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Current user has no access to current page |
|
| 37 | + */ |
|
| 38 | + private $noperm = false; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * For multiple forums |
|
| 42 | + */ |
|
| 43 | + public $is_multiple = false; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * force to parse vars (run against static vars) irmtfan |
|
| 47 | + */ |
|
| 48 | + public $force = false; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Vistitor's level: 0 - anonymous; 1 - user; 2 - moderator or admin |
|
| 52 | + */ |
|
| 53 | + public $userlevel = 0; |
|
| 54 | + |
|
| 55 | + public $query = []; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * reference to an object handler |
|
| 59 | + */ |
|
| 60 | + private $handler; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Requested page |
|
| 64 | + */ |
|
| 65 | + private $page = 'list.topic.php'; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * query variables |
|
| 69 | + */ |
|
| 70 | + private $args = ['forum', 'uid', 'lastposter', 'type', 'status', 'mode', 'sort', 'order', 'start', 'since']; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Constructor |
|
| 74 | + */ |
|
| 75 | + // public function TopicRenderer() |
|
| 76 | + public function __construct() |
|
| 77 | + { |
|
| 78 | + $this->handler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Access the only instance of this class |
|
| 83 | + * @return TopicRenderer |
|
| 84 | + */ |
|
| 85 | + public static function getInstance() |
|
| 86 | + { |
|
| 87 | + static $instance; |
|
| 88 | + if (null === $instance) { |
|
| 89 | + $instance = new static(); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + return $instance; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + public function init() |
|
| 96 | + { |
|
| 97 | + $this->noperm = false; |
|
| 98 | + $this->query = []; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @param $var |
|
| 103 | + * @param $val |
|
| 104 | + * @return array|int|string |
|
| 105 | + */ |
|
| 106 | + public function setVar($var, $val) |
|
| 107 | + { |
|
| 108 | + switch ($var) { |
|
| 109 | + case 'forum': |
|
| 110 | + if (is_numeric($val)) { |
|
| 111 | + $val = (int)$val; |
|
| 112 | + // START irmtfan - if the forum is array |
|
| 113 | + } elseif (is_array($val)) { |
|
| 114 | + $val = implode('|', $val); |
|
| 115 | + //} elseif (!empty($val)) { |
|
| 116 | + // $val = implode("|", array_map("intval", explode(", ", $val))); |
|
| 117 | + } |
|
| 118 | + // END irmtfan - if the forum is array |
|
| 119 | + break; |
|
| 120 | + |
|
| 121 | + case 'type': |
|
| 122 | + case 'mode': |
|
| 123 | + case 'order': |
|
| 124 | + case 'start': |
|
| 125 | + case 'since': |
|
| 126 | + $val = (int)$val; |
|
| 127 | + break; |
|
| 128 | + |
|
| 129 | + case 'uid': // irmtfan add multi topic poster |
|
| 130 | + case 'lastposter': // irmtfan add multi lastposter |
|
| 131 | + break; |
|
| 132 | + |
|
| 133 | + case 'status': |
|
| 134 | + // START irmtfan to accept multiple status |
|
| 135 | + $val = is_array($val) ? $val : [$val]; |
|
| 136 | + $val = implode(',', $val); |
|
| 137 | + //$val = (in_array($val, array_keys($this->getStatus( $this->userlevel ))) ) ? $val : "all"; //irmtfan no need to check if status is empty or not |
|
| 138 | + //if ($val === "all" && !$this->is_multiple) $val = ""; irmtfan commented because it is done in sort |
|
| 139 | + // END irmtfan to accept multiple status |
|
| 140 | + break; |
|
| 141 | + |
|
| 142 | + default: |
|
| 143 | + break; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return $val; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @param array $vars |
|
| 151 | + */ |
|
| 152 | + public function setVars(array $vars = []) |
|
| 153 | + { |
|
| 154 | + $this->init(); |
|
| 155 | + |
|
| 156 | + foreach ($vars as $var => $val) { |
|
| 157 | + if (!in_array($var, $this->args)) { |
|
| 158 | + continue; |
|
| 159 | + } |
|
| 160 | + $this->vars[$var] = $this->setVar($var, $val); |
|
| 161 | + } |
|
| 162 | + $this->parseVars(); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @param null $status |
|
| 167 | + */ |
|
| 168 | + public function myParseStatus($status = null) |
|
| 169 | + { |
|
| 170 | + switch ($status) { |
|
| 171 | + case 'digest': |
|
| 172 | + $this->query['where'][] = 't.topic_digest = 1'; |
|
| 173 | + break; |
|
| 174 | + |
|
| 175 | + case 'undigest': |
|
| 176 | + $this->query['where'][] = 't.topic_digest = 0'; |
|
| 177 | + break; |
|
| 178 | + |
|
| 179 | + case 'sticky': |
|
| 180 | + $this->query['where'][] = 't.topic_sticky = 1'; |
|
| 181 | + break; |
|
| 182 | + |
|
| 183 | + case 'unsticky': |
|
| 184 | + $this->query['where'][] = 't.topic_sticky = 0'; |
|
| 185 | + break; |
|
| 186 | + |
|
| 187 | + case 'lock': |
|
| 188 | + $this->query['where'][] = 't.topic_status = 1'; |
|
| 189 | + break; |
|
| 190 | + |
|
| 191 | + case 'unlock': |
|
| 192 | + $this->query['where'][] = 't.topic_status = 0'; |
|
| 193 | + break; |
|
| 194 | + |
|
| 195 | + case 'poll': |
|
| 196 | + $this->query['where'][] = 't.topic_haspoll = 1'; |
|
| 197 | + break; |
|
| 198 | + |
|
| 199 | + case 'unpoll': |
|
| 200 | + $this->query['where'][] = 't.topic_haspoll = 0'; |
|
| 201 | + break; |
|
| 202 | + |
|
| 203 | + case 'voted': |
|
| 204 | + $this->query['where'][] = 't.votes > 0'; |
|
| 205 | + break; |
|
| 206 | + |
|
| 207 | + case 'unvoted': |
|
| 208 | + $this->query['where'][] = 't.votes < 1'; |
|
| 209 | + break; |
|
| 210 | + |
|
| 211 | + case 'replied': |
|
| 212 | + $this->query['where'][] = 't.topic_replies > 0'; |
|
| 213 | + break; |
|
| 214 | + |
|
| 215 | + case 'unreplied': |
|
| 216 | + $this->query['where'][] = 't.topic_replies < 1'; |
|
| 217 | + break; |
|
| 218 | + |
|
| 219 | + case 'viewed': |
|
| 220 | + $this->query['where'][] = 't.topic_views > 0'; |
|
| 221 | + break; |
|
| 222 | + |
|
| 223 | + case 'unviewed': |
|
| 224 | + $this->query['where'][] = 't.topic_views < 1'; |
|
| 225 | + break; |
|
| 226 | + |
|
| 227 | + case 'read': |
|
| 228 | + // Skip |
|
| 229 | + if (empty($this->config['read_mode'])) { |
|
| 230 | + // Use database |
|
| 231 | + } elseif (2 == $this->config['read_mode']) { |
|
| 232 | + // START irmtfan use read_uid to find the unread posts when the user is logged in |
|
| 233 | + $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
| 234 | + if (!empty($read_uid)) { |
|
| 235 | + $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 . ' '; |
|
| 236 | + $this->query['where'][] = 'r.post_id = t.topic_last_post_id'; |
|
| 237 | + } else { |
|
| 238 | + } |
|
| 239 | + // END irmtfan change criteria to get from uid p.uid = last post submit user id |
|
| 240 | + // User cookie |
|
| 241 | + } elseif (1 == $this->config['read_mode']) { |
|
| 242 | + // START irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
| 243 | + $startdate = !empty($this->vars['since']) ? (time() - newbbGetSinceTime($this->vars['since'])) : 0; |
|
| 244 | + if ($lastvisit = max($GLOBALS['last_visit'], $startdate)) { |
|
| 245 | + $readmode1query = ''; |
|
| 246 | + if ($lastvisit > $startdate) { |
|
| 247 | + $readmode1query = 'p.post_time < ' . $lastvisit; |
|
| 248 | + } |
|
| 249 | + $topics = []; |
|
| 250 | + $topic_lastread = newbbGetCookie('LT', true); |
|
| 251 | + if (count($topic_lastread) > 0) { |
|
| 252 | + foreach ($topic_lastread as $id => $time) { |
|
| 253 | + if ($time > $lastvisit) { |
|
| 254 | + $topics[] = $id; |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + if (count($topics) > 0) { |
|
| 259 | + $topicquery = ' t.topic_id IN (' . implode(',', $topics) . ')'; |
|
| 260 | + // because it should be OR |
|
| 261 | + $readmode1query = !empty($readmode1query) ? '(' . $readmode1query . ' OR ' . $topicquery . ')' : $topicquery; |
|
| 262 | + } |
|
| 263 | + $this->query['where'][] = $readmode1query; |
|
| 264 | + } |
|
| 265 | + // END irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
| 266 | + } |
|
| 267 | + break; |
|
| 268 | + |
|
| 269 | + case 'unread': |
|
| 270 | + // Skip |
|
| 271 | + if (empty($this->config['read_mode'])) { |
|
| 272 | + // Use database |
|
| 273 | + } elseif (2 == $this->config['read_mode']) { |
|
| 274 | + // START irmtfan use read_uid to find the unread posts when the user is logged in |
|
| 275 | + $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
| 276 | + if (!empty($read_uid)) { |
|
| 277 | + $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 . ' '; |
|
| 278 | + $this->query['where'][] = '(r.read_id IS NULL OR r.post_id < t.topic_last_post_id)'; |
|
| 279 | + } else { |
|
| 280 | + } |
|
| 281 | + // END irmtfan change criteria to get from uid p.uid = last post submit user id |
|
| 282 | + // User cookie |
|
| 283 | + } elseif (1 == $this->config['read_mode']) { |
|
| 284 | + // START irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
| 285 | + $startdate = !empty($this->vars['since']) ? (time() - newbbGetSinceTime($this->vars['since'])) : 0; |
|
| 286 | + if ($lastvisit = max($GLOBALS['last_visit'], $startdate)) { |
|
| 287 | + if ($lastvisit > $startdate) { |
|
| 288 | + $this->query['where'][] = 'p.post_time > ' . $lastvisit; |
|
| 289 | + } |
|
| 290 | + $topics = []; |
|
| 291 | + $topic_lastread = newbbGetCookie('LT', true); |
|
| 292 | + if (count($topic_lastread) > 0) { |
|
| 293 | + foreach ($topic_lastread as $id => $time) { |
|
| 294 | + if ($time > $lastvisit) { |
|
| 295 | + $topics[] = $id; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + if (count($topics) > 0) { |
|
| 300 | + $this->query['where'][] = ' t.topic_id NOT IN (' . implode(',', $topics) . ')'; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + // END irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
|
| 304 | + } |
|
| 305 | + break; |
|
| 306 | + |
|
| 307 | + case 'pending': |
|
| 308 | + if ($this->userlevel < 2) { |
|
| 309 | + $this->noperm = true; |
|
| 310 | + } else { |
|
| 311 | + $this->query['where'][] = 't.approved = 0'; |
|
| 312 | + } |
|
| 313 | + break; |
|
| 314 | + |
|
| 315 | + case 'deleted': |
|
| 316 | + if ($this->userlevel < 2) { |
|
| 317 | + $this->noperm = true; |
|
| 318 | + } else { |
|
| 319 | + $this->query['where'][] = 't.approved = -1'; |
|
| 320 | + } |
|
| 321 | + break; |
|
| 322 | + |
|
| 323 | + case 'all': // For viewall.php; do not display sticky topics at first |
|
| 324 | + case 'active': // same as 'all' |
|
| 325 | + $this->query['where'][] = 't.approved = 1'; |
|
| 326 | + break; |
|
| 327 | + |
|
| 328 | + default: // irmtfan do nothing |
|
| 329 | + break; |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * @param $var |
|
| 335 | + * @param $val |
|
| 336 | + */ |
|
| 337 | + public function parseVar($var, $val) |
|
| 338 | + { |
|
| 339 | + switch ($var) { |
|
| 340 | + case 'forum': |
|
| 341 | + /** @var Newbb\ForumHandler $forumHandler */ |
|
| 342 | + $forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
| 343 | + // START irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums |
|
| 344 | + // Get accessible forums |
|
| 345 | + $accessForums = $forumHandler->getIdsByValues(array_map('intval', @explode('|', $val))); |
|
| 346 | + // Filter specified forums if any |
|
| 347 | + //if (!empty($val) && $_forums = @explode('|', $val)) { |
|
| 348 | + //$accessForums = array_intersect($accessForums, array_map('intval', $_forums)); |
|
| 349 | + //} |
|
| 350 | + $this->vars['forum'] = $this->setVar('forum', $accessForums); |
|
| 351 | + // END irmtfan - get forum Ids by values. parse positive values to forum IDs and negative values to category IDs. value=0 => all valid forums |
|
| 352 | + |
|
| 353 | + if (empty($accessForums)) { |
|
| 354 | + $this->noperm = true; |
|
| 355 | + // 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. |
|
| 356 | + //} elseif (count($accessForums) === 1) { |
|
| 357 | + //$this->query["where"][] = "t.forum_id = " . $accessForums[0]; |
|
| 358 | + } else { |
|
| 359 | + $this->query['where'][] = 't.forum_id IN ( ' . implode(', ', $accessForums) . ' )'; |
|
| 360 | + } |
|
| 361 | + break; |
|
| 362 | + |
|
| 363 | + case 'uid': // irmtfan add multi topic poster |
|
| 364 | + if (-1 !== $val) { |
|
| 365 | + $val = implode(',', array_map('intval', explode(',', $val))); |
|
| 366 | + $this->query['where'][] = 't.topic_poster IN ( ' . $val . ' )'; |
|
| 367 | + } |
|
| 368 | + break; |
|
| 369 | + case 'lastposter': // irmtfan add multi lastposter |
|
| 370 | + if (-1 !== $val) { |
|
| 371 | + $val = implode(',', array_map('intval', explode(',', $val))); |
|
| 372 | + $this->query['where'][] = 'p.uid IN ( ' . $val . ' )'; |
|
| 373 | + } |
|
| 374 | + break; |
|
| 375 | + |
|
| 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'], true)) && 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'], true))) { |
|
| 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 | + |
|
| 394 | + case 'type': |
|
| 395 | + if (!empty($val)) { |
|
| 396 | + $this->query['where'][] = 't.type_id = ' . $val; |
|
| 397 | + } |
|
| 398 | + break; |
|
| 399 | + |
|
| 400 | + case 'status': |
|
| 401 | + // START irmtfan to accept multiple status |
|
| 402 | + $val = explode(',', $val); |
|
| 403 | + // irmtfan - add 'all' to always parse t.approved = 1 |
|
| 404 | + if (0 === count(array_intersect($val, ['all', 'active', 'pending', 'deleted']))) { |
|
| 405 | + $val[] = 'all'; |
|
| 406 | + } |
|
| 407 | + foreach ($val as $key => $status) { |
|
| 408 | + $this->myParseStatus($status); |
|
| 409 | + } |
|
| 410 | + // END irmtfan to accept multiple status |
|
| 411 | + break; |
|
| 412 | + |
|
| 413 | + case 'sort': |
|
| 414 | + if ($sort = $this->getSort($val, 'sort')) { |
|
| 415 | + $this->query['sort'][] = $sort . (empty($this->vars['order']) ? ' DESC' : ' ASC'); |
|
| 416 | + } else { // irmtfan if sort is not in the list |
|
| 417 | + $this->query['sort'][] = 't.topic_last_post_id' . (empty($this->vars['order']) ? ' DESC' : ' ASC'); |
|
| 418 | + } |
|
| 419 | + break; |
|
| 420 | + |
|
| 421 | + default: |
|
| 422 | + break; |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * @return bool |
|
| 428 | + */ |
|
| 429 | + public function parseVars() |
|
| 430 | + { |
|
| 431 | + static $parsed; |
|
| 432 | + // irmtfan - force to parse vars (run against static vars) |
|
| 433 | + if (isset($parsed) && !$this->force) { |
|
| 434 | + return true; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + if (!isset($this->vars['forum'])) { |
|
| 438 | + $this->vars['forum'] = null; |
|
| 439 | + } |
|
| 440 | + //irmtfan parse status for rendering topic correctly - if empty($_GET(status)) it will show all topics include deleted and pendings. 'all' instead of all |
|
| 441 | + if (!isset($this->vars['status'])) { |
|
| 442 | + $this->vars['status'] = 'all'; |
|
| 443 | + } |
|
| 444 | + // 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= |
|
| 445 | + if (empty($this->vars['sort'])) { |
|
| 446 | + $this->vars['sort'] = 'lastpost'; |
|
| 447 | + } // use lastpost instead of sticky |
|
| 448 | + |
|
| 449 | + foreach ($this->vars as $var => $val) { |
|
| 450 | + $this->parseVar($var, $val); |
|
| 451 | + if (empty($val)) { |
|
| 452 | + unset($this->vars[$var]); |
|
| 453 | + } |
|
| 454 | + } |
|
| 455 | + $parsed = true; |
|
| 456 | + |
|
| 457 | + return true; |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * @param null $header |
|
| 462 | + * @param null $var |
|
| 463 | + * @return array|null |
|
| 464 | + */ |
|
| 465 | + public function getSort($header = null, $var = null) |
|
| 466 | + { |
|
| 467 | + $headers = [ |
|
| 468 | + 'topic' => [ |
|
| 469 | + 'title' => _MD_NEWBB_TOPICS, |
|
| 470 | + 'sort' => 't.topic_title' |
|
| 471 | + ], |
|
| 472 | + 'forum' => [ |
|
| 473 | + 'title' => _MD_NEWBB_FORUM, |
|
| 474 | + 'sort' => 't.forum_id' |
|
| 475 | + ], |
|
| 476 | + 'poster' => [ |
|
| 477 | + 'title' => _MD_NEWBB_TOPICPOSTER, /*irmtfan _MD_NEWBB_POSTER to _MD_NEWBB_TOPICPOSTER*/ |
|
| 478 | + 'sort' => 't.topic_poster' |
|
| 479 | + ], |
|
| 480 | + 'replies' => [ |
|
| 481 | + 'title' => _MD_NEWBB_REPLIES, |
|
| 482 | + 'sort' => 't.topic_replies' |
|
| 483 | + ], |
|
| 484 | + 'views' => [ |
|
| 485 | + 'title' => _MD_NEWBB_VIEWS, |
|
| 486 | + 'sort' => 't.topic_views' |
|
| 487 | + ], |
|
| 488 | + 'lastpost' => [ // irmtfan show topic_page_jump_icon smarty |
|
| 489 | + 'title' => _MD_NEWBB_LASTPOST, |
|
| 490 | + /*irmtfan _MD_NEWBB_DATE to _MD_NEWBB_LASTPOSTTIME again change to _MD_LASTPOST*/ |
|
| 491 | + 'sort' => 't.topic_last_post_id' |
|
| 492 | + ], |
|
| 493 | + // START irmtfan add more sorts |
|
| 494 | + 'lastposttime' => [ // irmtfan same as lastpost |
|
| 495 | + 'title' => _MD_NEWBB_LASTPOSTTIME, |
|
| 496 | + 'sort' => 't.topic_last_post_id' |
|
| 497 | + ], |
|
| 498 | + 'lastposter' => [ // irmtfan |
|
| 499 | + 'title' => _MD_NEWBB_POSTER, |
|
| 500 | + 'sort' => 'p.uid',// poster uid |
|
| 501 | + ], |
|
| 502 | + 'lastpostmsgicon' => [ // irmtfan |
|
| 503 | + 'title' => _MD_NEWBB_MESSAGEICON, |
|
| 504 | + 'sort' => 'p.icon',// post message icon |
|
| 505 | + ], |
|
| 506 | + 'ratings' => [ |
|
| 507 | + 'title' => _MD_NEWBB_RATINGS, |
|
| 508 | + 'sort' => 't.rating', // irmtfan t.topic_rating to t.rating |
|
| 509 | + ], |
|
| 510 | + 'votes' => [ |
|
| 511 | + 'title' => _MD_NEWBB_VOTES, |
|
| 512 | + 'sort' => 't.votes' |
|
| 513 | + ], |
|
| 514 | + 'publish' => [ |
|
| 515 | + 'title' => _MD_NEWBB_TOPICTIME, |
|
| 516 | + 'sort' => 't.topic_id' |
|
| 517 | + ], |
|
| 518 | + 'digest' => [ |
|
| 519 | + 'title' => _MD_NEWBB_DIGEST, |
|
| 520 | + 'sort' => 't.digest_time' |
|
| 521 | + ], |
|
| 522 | + 'sticky' => [ |
|
| 523 | + 'title' => _MD_NEWBB_STICKY, |
|
| 524 | + 'sort' => 't.topic_sticky' |
|
| 525 | + ], |
|
| 526 | + 'lock' => [ |
|
| 527 | + 'title' => _MD_NEWBB_LOCK, |
|
| 528 | + 'sort' => 't.topic_status' |
|
| 529 | + ], |
|
| 530 | + 'poll' => [ |
|
| 531 | + 'title' => _MD_NEWBB_POLL_POLL, |
|
| 532 | + 'sort' => 't.poll_id' |
|
| 533 | + ] |
|
| 534 | + ]; |
|
| 535 | + $types = $this->getTypes(); |
|
| 536 | + if (!empty($types)) { |
|
| 537 | + $headers['type'] = [ |
|
| 538 | + 'title' => _MD_NEWBB_TYPE, |
|
| 539 | + 'sort' => 't.type_id' |
|
| 540 | + ]; |
|
| 541 | + } |
|
| 542 | + if (2 == $this->userlevel) { |
|
| 543 | + $headers['approve'] = [ |
|
| 544 | + 'title' => _MD_NEWBB_APPROVE, |
|
| 545 | + 'sort' => 't.approved' |
|
| 546 | + ]; |
|
| 547 | + } |
|
| 548 | + // END irmtfan add more sorts |
|
| 549 | + if (empty($header) && empty($var)) { |
|
| 550 | + return $headers; |
|
| 551 | + } |
|
| 552 | + if (!empty($var) && !empty($header)) { |
|
| 553 | + return @$headers[$header][$var]; |
|
| 554 | + } |
|
| 555 | + if (empty($var)) { |
|
| 556 | + return @$headers[$header]; |
|
| 557 | + } |
|
| 558 | + $ret = null; |
|
| 559 | + foreach (array_keys($headers) as $key) { |
|
| 560 | + $ret[$key] = @$headers[$key][$var]; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + return $ret; |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + // START irmtfan add Display topic headers function |
|
| 567 | + |
|
| 568 | + /** |
|
| 569 | + * @param null $header |
|
| 570 | + * @return array |
|
| 571 | + */ |
|
| 572 | + public function getHeader($header = null) |
|
| 573 | + { |
|
| 574 | + $headersSort = $this->getSort('', 'title'); |
|
| 575 | + // additional headers - important: those cannot be in sort anyway |
|
| 576 | + $headers = array_merge($headersSort, [ |
|
| 577 | + 'attachment' => _MD_NEWBB_TOPICSHASATT, // show attachment smarty |
|
| 578 | + 'read' => _MD_NEWBB_MARK_UNREAD . '|' . _MD_NEWBB_MARK_READ, // read/unread show topic_folder smarty |
|
| 579 | + 'pagenav' => _MD_NEWBB_PAGENAV_DISPLAY, // show topic_page_jump smarty - sort by topic_replies? |
|
| 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 = 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) |
|
| 757 | + { |
|
| 758 | + $status = ''; |
|
| 759 | + if (!$types = $this->getTypes()) { |
|
| 760 | + return true; |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + $args = []; |
|
| 764 | + foreach ($this->vars as $var => $val) { |
|
| 765 | + if ('type' === $var) { |
|
| 766 | + continue; |
|
| 767 | + } |
|
| 768 | + $args[] = "{$var}={$val}"; |
|
| 769 | + } |
|
| 770 | + |
|
| 771 | + foreach ($types as $id => $type) { |
|
| 772 | + $_args = ["type={$id}"]; |
|
| 773 | + $status[$id]['title'] = $type['type_name']; |
|
| 774 | + $status[$id]['link'] = $this->page . '?' . implode('&', array_merge($args, $_args)); |
|
| 775 | + } |
|
| 776 | + $xoopsTpl->assign_by_ref('types', $status); |
|
| 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) |
|
| 806 | + { |
|
| 807 | + $count_topic = $this->getCount(); |
|
| 808 | + if ($count_topic > $this->config['topics_per_page']) { |
|
| 809 | + $args = []; |
|
| 810 | + foreach ($this->vars as $var => $val) { |
|
| 811 | + if ('start' === $var) { |
|
| 812 | + continue; |
|
| 813 | + } |
|
| 814 | + $args[] = "{$var}={$val}"; |
|
| 815 | + } |
|
| 816 | + require_once $GLOBALS['xoops']->path('class/pagenav.php'); |
|
| 817 | + $nav = new \XoopsPageNav($count_topic, $this->config['topics_per_page'], @$this->vars['start'], 'start', implode('&', $args)); |
|
| 818 | + if (isset($GLOBALS['xoopsModuleConfig']['do_rewrite'])) { |
|
| 819 | + $nav->url = formatURL(Request::getString('SERVER_NAME', '', 'SERVER')) . ' /' . $nav->url; |
|
| 820 | + } |
|
| 821 | + if ('select' === $this->config['pagenav_display']) { |
|
| 822 | + $navi = $nav->renderSelect(); |
|
| 823 | + } elseif ('image' === $this->config['pagenav_display']) { |
|
| 824 | + $navi = $nav->renderImageNav(4); |
|
| 825 | + } else { |
|
| 826 | + $navi = $nav->renderNav(4); |
|
| 827 | + } |
|
| 828 | + $xoopsTpl->assign('pagenav', $navi); |
|
| 829 | + } else { |
|
| 830 | + $xoopsTpl->assign('pagenav', ''); |
|
| 831 | + } |
|
| 832 | + } |
|
| 833 | + |
|
| 834 | + /** |
|
| 835 | + * @return int |
|
| 836 | + */ |
|
| 837 | + public function getCount() |
|
| 838 | + { |
|
| 839 | + if ($this->noperm) { |
|
| 840 | + return 0; |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + $selects = []; |
|
| 844 | + $froms = []; |
|
| 845 | + $joins = []; |
|
| 846 | + $wheres = []; |
|
| 847 | + |
|
| 848 | + // topic fields |
|
| 849 | + $selects[] = 'COUNT(*)'; |
|
| 850 | + |
|
| 851 | + $froms[] = $this->handler->db->prefix('newbb_topics') . ' AS t '; |
|
| 852 | + $joins[] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_posts') . ' AS p ON p.post_id = t.topic_last_post_id'; |
|
| 853 | + $wheres[] = '1 = 1'; |
|
| 854 | + |
|
| 855 | + $sql = ' SELECT ' . implode(', ', $selects) . ' FROM ' . implode(', ', $froms) . ' ' . implode(' ', $joins) . (!empty($this->query['join']) ? ' ' . implode(' ', $this->query['join']) : '') . // irmtfan bug fix: Undefined index: join when post_excerpt = 0 |
|
| 856 | + ' WHERE ' . implode(' AND ', $wheres) . ' AND ' . @implode(' AND ', @$this->query['where']); |
|
| 857 | + |
|
| 858 | + if (!$result = $this->handler->db->query($sql)) { |
|
| 859 | + return 0; |
|
| 860 | + } |
|
| 861 | + list($count) = $this->handler->db->fetchRow($result); |
|
| 862 | + |
|
| 863 | + return $count; |
|
| 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(); |
|
| 876 | + |
|
| 877 | + if ($this->noperm) { |
|
| 878 | + if (is_object($xoopsTpl)) { |
|
| 879 | + $xoopsTpl->assign_by_ref('topics', $ret); |
|
| 880 | + |
|
| 881 | + return; |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + return $ret; |
|
| 885 | + } |
|
| 886 | + |
|
| 887 | + $selects = []; |
|
| 888 | + $froms = []; |
|
| 889 | + $joins = []; |
|
| 890 | + $wheres = []; |
|
| 891 | + |
|
| 892 | + // topic fields |
|
| 893 | + $selects[] = 't.*'; |
|
| 894 | + // post fields |
|
| 895 | + $selects[] = 'p.post_time as last_post_time, p.poster_name as last_poster_name, p.icon, p.post_id, p.uid'; |
|
| 896 | + |
|
| 897 | + $froms[] = $this->handler->db->prefix('newbb_topics') . ' AS t '; |
|
| 898 | + $joins[] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_posts') . ' AS p ON p.post_id = t.topic_last_post_id'; |
|
| 899 | + $wheres[] = '1 = 1'; |
|
| 900 | + |
|
| 901 | + if (!empty($this->config['post_excerpt'])) { |
|
| 902 | + $selects[] = 'p.post_karma, p.require_reply, pt.post_text'; |
|
| 903 | + $this->query['join'][] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_posts_text') . ' AS pt ON pt.post_id = t.topic_last_post_id'; |
|
| 904 | + } |
|
| 905 | + //if (empty($this->query["sort"])) $this->query["sort"][] = 't.topic_last_post_id DESC'; // irmtfan commented no need |
|
| 906 | + |
|
| 907 | + $sql = ' SELECT ' . implode(', ', $selects) . ' FROM ' . implode(', ', $froms) . ' ' . implode(' ', $joins) . (!empty($this->query['join']) ? ' ' . implode(' ', $this->query['join']) : '') . // irmtfan bug fix: Undefined index join when post_excerpt = 0 |
|
| 908 | + ' WHERE ' . implode(' AND ', $wheres) . ' AND ' . @implode(' AND ', @$this->query['where']) . ' ORDER BY ' . implode(', ', $this->query['sort']); |
|
| 909 | + |
|
| 910 | + if (!$result = $this->handler->db->query($sql, $this->config['topics_per_page'], @$this->vars['start'])) { |
|
| 911 | + if (is_object($xoopsTpl)) { |
|
| 912 | + $xoopsTpl->assign_by_ref('topics', $ret); |
|
| 913 | + |
|
| 914 | + return; |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + return $ret; |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + require_once dirname(__DIR__) . '/include/functions.render.php'; |
|
| 921 | + require_once dirname(__DIR__) . '/include/functions.session.php'; |
|
| 922 | + require_once dirname(__DIR__) . '/include/functions.time.php'; |
|
| 923 | + require_once dirname(__DIR__) . '/include/functions.read.php'; |
|
| 924 | + require_once dirname(__DIR__) . '/include/functions.topic.php'; |
|
| 925 | + |
|
| 926 | + $sticky = 0; |
|
| 927 | + $topics = []; |
|
| 928 | + $posters = []; |
|
| 929 | + $reads = []; |
|
| 930 | + $types = []; |
|
| 931 | + $forums = []; |
|
| 932 | + $anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']); |
|
| 933 | + |
|
| 934 | + while (false !== ($myrow = $this->handler->db->fetchArray($result))) { |
|
| 935 | + if ($myrow['topic_sticky']) { |
|
| 936 | + ++$sticky; |
|
| 937 | + } |
|
| 938 | + |
|
| 939 | + // ------------------------------------------------------ |
|
| 940 | + // START irmtfan remove topic_icon hardcode smarty |
|
| 941 | + // topic_icon: just regular topic_icon |
|
| 942 | + if (!empty($myrow['icon'])) { |
|
| 943 | + $topic_icon = '<img align="middle" src="' . XOOPS_URL . '/images/subject/' . htmlspecialchars($myrow['icon'], ENT_QUOTES | ENT_HTML5) . '" alt="" />'; |
|
| 944 | + } else { |
|
| 945 | + $topic_icon = '<img align="middle" src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" />'; |
|
| 946 | + } |
|
| 947 | + // END irmtfan remove topic_icon hardcode smarty |
|
| 948 | + |
|
| 949 | + // ------------------------------------------------------ |
|
| 950 | + // rating_img |
|
| 951 | + $rating = number_format($myrow['rating'] / 2, 0); |
|
| 952 | + // irmtfan - add alt key for rating |
|
| 953 | + if ($rating < 1) { |
|
| 954 | + $rating_img = newbbDisplayImage('blank'); |
|
| 955 | + } else { |
|
| 956 | + $rating_img = newbbDisplayImage('rate' . $rating, constant('_MD_NEWBB_RATE' . $rating)); |
|
| 957 | + } |
|
| 958 | + |
|
| 959 | + // ------------------------------------------------------ |
|
| 960 | + // topic_page_jump |
|
| 961 | + $topic_page_jump = ''; |
|
| 962 | + $topic_page_jump_icon = ''; |
|
| 963 | + $totalpages = ceil(($myrow['topic_replies'] + 1) / $this->config['posts_per_page']); |
|
| 964 | + if ($totalpages > 1) { |
|
| 965 | + $topic_page_jump .= ' '; |
|
| 966 | + $append = false; |
|
| 967 | + for ($i = 1; $i <= $totalpages; ++$i) { |
|
| 968 | + if ($i > 3 && $i < $totalpages) { |
|
| 969 | + if (!$append) { |
|
| 970 | + $topic_page_jump .= '...'; |
|
| 971 | + $append = true; |
|
| 972 | + } |
|
| 973 | + } else { |
|
| 974 | + $topic_page_jump .= '[<a href="' . XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'] . '&start=' . (($i - 1) * $this->config['posts_per_page']) . '">' . $i . '</a>]'; |
|
| 975 | + // irmtfan remove here and move |
|
| 976 | + //$topic_page_jump_icon = "<a href='" . XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id=" . $myrow['topic_id'] . "&start=" . (($i - 1) * $this->config['posts_per_page']) . "" . "'>" . newbbDisplayImage('document',_MD_NEWBB_GOTOLASTPOST) . '</a>'; |
|
| 977 | + } |
|
| 978 | + } |
|
| 979 | + } |
|
| 980 | + // irmtfan - move here for both topics with and without pages - change topic_id to post_id |
|
| 981 | + $topic_page_jump_icon = "<a href='" . XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $myrow['topic_last_post_id'] . '' . "'>" . newbbDisplayImage('lastposticon', _MD_NEWBB_GOTOLASTPOST) . '</a>'; |
|
| 982 | + |
|
| 983 | + // ------------------------------------------------------ |
|
| 984 | + // => topic array |
|
| 985 | + |
|
| 986 | + $topic_title = $myts->htmlSpecialChars($myrow['topic_title']); |
|
| 987 | + // irmtfan use topic_title_excerpt for block topic title length |
|
| 988 | + $topic_title_excerpt = $topic_title; |
|
| 989 | + if (!empty($this->config['topic_title_excerpt'])) { |
|
| 990 | + $topic_title_excerpt = xoops_substr($topic_title, 0, $this->config['topic_title_excerpt']); |
|
| 991 | + } |
|
| 992 | + // irmtfan hardcode class commented |
|
| 993 | + //if ($myrow['topic_digest']) { |
|
| 994 | + // $topic_title = "<span class='digest'>" . $topic_title . "</span>"; |
|
| 995 | + //} |
|
| 996 | + |
|
| 997 | + if (empty($this->config['post_excerpt'])) { |
|
| 998 | + $topic_excerpt = ''; |
|
| 999 | + } elseif (($myrow['post_karma'] > 0 || $myrow['require_reply'] > 0) && !newbbIsAdmin($myrow['forum_id'])) { |
|
| 1000 | + $topic_excerpt = ''; |
|
| 1001 | + } else { |
|
| 1002 | + $topic_excerpt = xoops_substr(newbbHtml2text($myts->displayTarea($myrow['post_text'])), 0, $this->config['post_excerpt']); |
|
| 1003 | + $topic_excerpt = str_replace('[', '[', $myts->htmlSpecialChars($topic_excerpt)); |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + $topics[$myrow['topic_id']] = [ |
|
| 1007 | + 'topic_id' => $myrow['topic_id'], |
|
| 1008 | + 'topic_icon' => $topic_icon, |
|
| 1009 | + 'type_id' => $myrow['type_id'], |
|
| 1010 | + 'topic_title_excerpt' => $topic_title_excerpt, |
|
| 1011 | + //irmtfan use topic_title_excerpt |
|
| 1012 | + //'topic_link' => XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'], // . '&forum=' . $myrow['forum_id'], // irmtfan comment |
|
| 1013 | + 'topic_link' => 'viewtopic.php?topic_id=' . $myrow['topic_id'], |
|
| 1014 | + // irmtfan remove hardcode link |
|
| 1015 | + 'rating_img' => $rating_img, |
|
| 1016 | + 'votes' => $myrow['votes'], |
|
| 1017 | + //irmtfan added |
|
| 1018 | + 'topic_page_jump' => $topic_page_jump, |
|
| 1019 | + 'topic_page_jump_icon' => $topic_page_jump_icon, |
|
| 1020 | + 'topic_replies' => $myrow['topic_replies'], |
|
| 1021 | + 'topic_poster_uid' => $myrow['topic_poster'], |
|
| 1022 | + 'topic_poster_name' => !empty($myrow['poster_name']) ? $myts->htmlSpecialChars($myrow['poster_name']) : $anonymous, |
|
| 1023 | + 'topic_views' => $myrow['topic_views'], |
|
| 1024 | + 'topic_time' => newbbFormatTimestamp($myrow['topic_time']), |
|
| 1025 | + 'topic_last_post_id' => $myrow['topic_last_post_id'], |
|
| 1026 | + //irmtfan added |
|
| 1027 | + 'topic_last_posttime' => newbbFormatTimestamp($myrow['last_post_time']), |
|
| 1028 | + 'topic_last_poster_uid' => $myrow['uid'], |
|
| 1029 | + 'topic_last_poster_name' => !empty($myrow['last_poster_name']) ? $myts->htmlSpecialChars($myrow['last_poster_name']) : $anonymous, |
|
| 1030 | + 'topic_forum' => $myrow['forum_id'], |
|
| 1031 | + 'topic_excerpt' => $topic_excerpt, |
|
| 1032 | + 'sticky' => $myrow['topic_sticky'] ? newbbDisplayImage('topic_sticky', _MD_NEWBB_TOPICSTICKY) : '', |
|
| 1033 | + // irmtfan bug fixed |
|
| 1034 | + 'lock' => $myrow['topic_status'] ? newbbDisplayImage('topic_locked', _MD_NEWBB_TOPICLOCK) : '', |
|
| 1035 | + //irmtfan added |
|
| 1036 | + 'digest' => $myrow['topic_digest'] ? newbbDisplayImage('topic_digest', _MD_NEWBB_TOPICDIGEST) : '', |
|
| 1037 | + //irmtfan added |
|
| 1038 | + 'poll' => $myrow['topic_haspoll'] ? newbbDisplayImage('poll', _MD_NEWBB_TOPICHASPOLL) : '', |
|
| 1039 | + //irmtfan added |
|
| 1040 | + 'approve' => $myrow['approved'], |
|
| 1041 | + //irmtfan added |
|
| 1042 | + ]; |
|
| 1043 | + |
|
| 1044 | + /* users */ |
|
| 1045 | + $posters[$myrow['topic_poster']] = 1; |
|
| 1046 | + $posters[$myrow['uid']] = 1; |
|
| 1047 | + // reads |
|
| 1048 | + if (!empty($this->config['read_mode'])) { |
|
| 1049 | + $reads[$myrow['topic_id']] = (1 == $this->config['read_mode']) ? $myrow['last_post_time'] : $myrow['topic_last_post_id']; |
|
| 1050 | + } |
|
| 1051 | + // types |
|
| 1052 | + if (!empty($myrow['type_id'])) { |
|
| 1053 | + //$types[$myrow['type_id']] = 1; |
|
| 1054 | + } |
|
| 1055 | + // forums |
|
| 1056 | + $forums[$myrow['forum_id']] = 1; |
|
| 1057 | + } |
|
| 1058 | + $posters_name = newbbGetUnameFromIds(array_keys($posters), $this->config['show_realname'], true); |
|
| 1059 | + $topic_isRead = newbbIsRead('topic', $reads); |
|
| 1060 | + /* |
|
| 1061 | 1061 | $type_list = array(); |
| 1062 | 1062 | if (count($types) > 0) { |
| 1063 | 1063 | $typeHandler = Newbb\Helper::getInstance()->getHandler('Type'); |
| 1064 | 1064 | $type_list = $typeHandler->getAll(new \Criteria("type_id", "(".implode(", ", array_keys($types)).")", "IN"), null, false); |
| 1065 | 1065 | } |
| 1066 | 1066 | */ |
| 1067 | - $type_list = $this->getTypes(); |
|
| 1068 | - /** @var Newbb\ForumHandler $forumHandler */ |
|
| 1069 | - $forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
| 1070 | - |
|
| 1071 | - if (count($forums) > 0) { |
|
| 1072 | - $forum_list = $forumHandler->getAll(new \Criteria('forum_id', '(' . implode(', ', array_keys($forums)) . ')', 'IN'), ['forum_name', 'hot_threshold'], false); |
|
| 1073 | - } else { |
|
| 1074 | - $forum_list = $forumHandler->getAll(); |
|
| 1075 | - } |
|
| 1076 | - |
|
| 1077 | - foreach (array_keys($topics) as $id) { |
|
| 1078 | - $topics[$id]['topic_read'] = empty($topic_isRead[$id]) ? 0 : 1; // add topic-read/topic-new smarty variable |
|
| 1079 | - $topics[$id]['topic_forum_link'] = '<a href="' . XOOPS_URL . '/modules/newbb/viewforum.php?forum=' . $topics[$id]['topic_forum'] . '">' . $forum_list[$topics[$id]['topic_forum']]['forum_name'] . '</a>'; |
|
| 1080 | - |
|
| 1081 | - //irmtfan use topic_title_excerpt -- add else |
|
| 1082 | - if (!empty($topics[$id]['type_id']) && isset($type_list[$topics[$id]['type_id']])) { |
|
| 1083 | - $topics[$id]['topic_title'] = getTopicTitle($topics[$id]['topic_title_excerpt'], $type_list[$topics[$id]['type_id']]['type_name'], $type_list[$topics[$id]['type_id']]['type_color']); |
|
| 1084 | - } else { |
|
| 1085 | - $topics[$id]['topic_title'] = $topics[$id]['topic_title_excerpt']; |
|
| 1086 | - } |
|
| 1087 | - $topics[$id]['topic_poster'] = !empty($posters_name[$topics[$id]['topic_poster_uid']]) ? $posters_name[$topics[$id]['topic_poster_uid']] : $topics[$id]['topic_poster_name']; |
|
| 1088 | - $topics[$id]['topic_last_poster'] = !empty($posters_name[$topics[$id]['topic_last_poster_uid']]) ? $posters_name[$topics[$id]['topic_last_poster_uid']] : $topics[$id]['topic_last_poster_name']; |
|
| 1089 | - // ------------------------------------------------------ |
|
| 1090 | - // START irmtfan remove hardcodes from topic_folder smarty |
|
| 1091 | - // topic_folder: priority: newhot -> hot/new -> regular |
|
| 1092 | - //list($topic_status, $topic_digest, $topic_replies) = $topics[$id]["stats"]; irmtfan |
|
| 1093 | - // START irmtfan - add topic_folder_text for alt |
|
| 1094 | - //if ($topics[$id]["lock"] === 1) { |
|
| 1095 | - // $topic_folder = 'topic_locked'; |
|
| 1096 | - // $topic_folder_text = _MD_NEWBB_TOPICLOCKED; |
|
| 1097 | - //} else { |
|
| 1098 | - //if ($topic_digest) { |
|
| 1099 | - // $topic_folder = 'topic_digest'; |
|
| 1100 | - // $topic_folder_text = _MD_NEWBB_TOPICDIGEST; |
|
| 1101 | - if ($topics[$id]['topic_replies'] >= $forum_list[$topics[$id]['topic_forum']]['hot_threshold']) { |
|
| 1102 | - $topic_folder = empty($topic_isRead[$id]) ? 'topic_hot_new' : 'topic_hot'; |
|
| 1103 | - $topic_folder_text = empty($topic_isRead[$id]) ? _MD_NEWBB_MORETHAN : _MD_NEWBB_MORETHAN2; |
|
| 1104 | - } else { |
|
| 1105 | - $topic_folder = empty($topic_isRead[$id]) ? 'topic_new' : 'topic'; |
|
| 1106 | - $topic_folder_text = empty($topic_isRead[$id]) ? _MD_NEWBB_NEWPOSTS : _MD_NEWBB_NONEWPOSTS; |
|
| 1107 | - } |
|
| 1108 | - //} |
|
| 1109 | - // END irmtfan remove hardcodes from topic_folder smarty |
|
| 1110 | - $topics[$id]['topic_folder'] = newbbDisplayImage($topic_folder, $topic_folder_text); |
|
| 1111 | - // END irmtfan - add topic_folder_text for alt |
|
| 1112 | - |
|
| 1113 | - unset($topics[$id]['topic_poster_name'], $topics[$id]['topic_last_poster_name']);// irmtfan remove $topics[$id]["stats"] because it is not exist now |
|
| 1114 | - } |
|
| 1115 | - |
|
| 1116 | - if (count($topics) > 0) { |
|
| 1117 | - $sql = ' SELECT DISTINCT topic_id FROM ' . $this->handler->db->prefix('newbb_posts') . " WHERE attachment != ''" . ' AND topic_id IN (' . implode(',', array_keys($topics)) . ')'; |
|
| 1118 | - if ($result = $this->handler->db->query($sql)) { |
|
| 1119 | - while (false !== (list($topic_id) = $this->handler->db->fetchRow($result))) { |
|
| 1120 | - $topics[$topic_id]['attachment'] = ' ' . newbbDisplayImage('attachment', _MD_NEWBB_TOPICSHASATT); |
|
| 1121 | - } |
|
| 1122 | - } |
|
| 1123 | - } |
|
| 1124 | - |
|
| 1125 | - if (is_object($xoopsTpl)) { |
|
| 1126 | - $xoopsTpl->assign_by_ref('sticky', $sticky); |
|
| 1127 | - $xoopsTpl->assign_by_ref('topics', $topics); |
|
| 1128 | - |
|
| 1129 | - return; |
|
| 1130 | - } |
|
| 1131 | - |
|
| 1132 | - return [$topics, $sticky]; |
|
| 1133 | - } |
|
| 1134 | - |
|
| 1135 | - // START irmtfan to create an array from selected keys of an array |
|
| 1136 | - |
|
| 1137 | - /** |
|
| 1138 | - * @param $array |
|
| 1139 | - * @param null $keys |
|
| 1140 | - * @return array |
|
| 1141 | - */ |
|
| 1142 | - public function getFromKeys($array, $keys = null) |
|
| 1143 | - { |
|
| 1144 | - if (empty($keys)) { |
|
| 1145 | - return $array; |
|
| 1146 | - } // all keys |
|
| 1147 | - $keyarr = is_string($keys) ? explode(',', $keys) : $keys; |
|
| 1148 | - $keyarr = array_intersect(array_keys($array), $keyarr); // keys should be in array |
|
| 1149 | - $ret = []; |
|
| 1150 | - foreach ($keyarr as $key) { |
|
| 1151 | - $ret[$key] = $array[$key]; |
|
| 1152 | - } |
|
| 1153 | - |
|
| 1154 | - return $ret; |
|
| 1155 | - } |
|
| 1156 | - // END irmtfan to create an array from selected keys of an array |
|
| 1067 | + $type_list = $this->getTypes(); |
|
| 1068 | + /** @var Newbb\ForumHandler $forumHandler */ |
|
| 1069 | + $forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
| 1070 | + |
|
| 1071 | + if (count($forums) > 0) { |
|
| 1072 | + $forum_list = $forumHandler->getAll(new \Criteria('forum_id', '(' . implode(', ', array_keys($forums)) . ')', 'IN'), ['forum_name', 'hot_threshold'], false); |
|
| 1073 | + } else { |
|
| 1074 | + $forum_list = $forumHandler->getAll(); |
|
| 1075 | + } |
|
| 1076 | + |
|
| 1077 | + foreach (array_keys($topics) as $id) { |
|
| 1078 | + $topics[$id]['topic_read'] = empty($topic_isRead[$id]) ? 0 : 1; // add topic-read/topic-new smarty variable |
|
| 1079 | + $topics[$id]['topic_forum_link'] = '<a href="' . XOOPS_URL . '/modules/newbb/viewforum.php?forum=' . $topics[$id]['topic_forum'] . '">' . $forum_list[$topics[$id]['topic_forum']]['forum_name'] . '</a>'; |
|
| 1080 | + |
|
| 1081 | + //irmtfan use topic_title_excerpt -- add else |
|
| 1082 | + if (!empty($topics[$id]['type_id']) && isset($type_list[$topics[$id]['type_id']])) { |
|
| 1083 | + $topics[$id]['topic_title'] = getTopicTitle($topics[$id]['topic_title_excerpt'], $type_list[$topics[$id]['type_id']]['type_name'], $type_list[$topics[$id]['type_id']]['type_color']); |
|
| 1084 | + } else { |
|
| 1085 | + $topics[$id]['topic_title'] = $topics[$id]['topic_title_excerpt']; |
|
| 1086 | + } |
|
| 1087 | + $topics[$id]['topic_poster'] = !empty($posters_name[$topics[$id]['topic_poster_uid']]) ? $posters_name[$topics[$id]['topic_poster_uid']] : $topics[$id]['topic_poster_name']; |
|
| 1088 | + $topics[$id]['topic_last_poster'] = !empty($posters_name[$topics[$id]['topic_last_poster_uid']]) ? $posters_name[$topics[$id]['topic_last_poster_uid']] : $topics[$id]['topic_last_poster_name']; |
|
| 1089 | + // ------------------------------------------------------ |
|
| 1090 | + // START irmtfan remove hardcodes from topic_folder smarty |
|
| 1091 | + // topic_folder: priority: newhot -> hot/new -> regular |
|
| 1092 | + //list($topic_status, $topic_digest, $topic_replies) = $topics[$id]["stats"]; irmtfan |
|
| 1093 | + // START irmtfan - add topic_folder_text for alt |
|
| 1094 | + //if ($topics[$id]["lock"] === 1) { |
|
| 1095 | + // $topic_folder = 'topic_locked'; |
|
| 1096 | + // $topic_folder_text = _MD_NEWBB_TOPICLOCKED; |
|
| 1097 | + //} else { |
|
| 1098 | + //if ($topic_digest) { |
|
| 1099 | + // $topic_folder = 'topic_digest'; |
|
| 1100 | + // $topic_folder_text = _MD_NEWBB_TOPICDIGEST; |
|
| 1101 | + if ($topics[$id]['topic_replies'] >= $forum_list[$topics[$id]['topic_forum']]['hot_threshold']) { |
|
| 1102 | + $topic_folder = empty($topic_isRead[$id]) ? 'topic_hot_new' : 'topic_hot'; |
|
| 1103 | + $topic_folder_text = empty($topic_isRead[$id]) ? _MD_NEWBB_MORETHAN : _MD_NEWBB_MORETHAN2; |
|
| 1104 | + } else { |
|
| 1105 | + $topic_folder = empty($topic_isRead[$id]) ? 'topic_new' : 'topic'; |
|
| 1106 | + $topic_folder_text = empty($topic_isRead[$id]) ? _MD_NEWBB_NEWPOSTS : _MD_NEWBB_NONEWPOSTS; |
|
| 1107 | + } |
|
| 1108 | + //} |
|
| 1109 | + // END irmtfan remove hardcodes from topic_folder smarty |
|
| 1110 | + $topics[$id]['topic_folder'] = newbbDisplayImage($topic_folder, $topic_folder_text); |
|
| 1111 | + // END irmtfan - add topic_folder_text for alt |
|
| 1112 | + |
|
| 1113 | + unset($topics[$id]['topic_poster_name'], $topics[$id]['topic_last_poster_name']);// irmtfan remove $topics[$id]["stats"] because it is not exist now |
|
| 1114 | + } |
|
| 1115 | + |
|
| 1116 | + if (count($topics) > 0) { |
|
| 1117 | + $sql = ' SELECT DISTINCT topic_id FROM ' . $this->handler->db->prefix('newbb_posts') . " WHERE attachment != ''" . ' AND topic_id IN (' . implode(',', array_keys($topics)) . ')'; |
|
| 1118 | + if ($result = $this->handler->db->query($sql)) { |
|
| 1119 | + while (false !== (list($topic_id) = $this->handler->db->fetchRow($result))) { |
|
| 1120 | + $topics[$topic_id]['attachment'] = ' ' . newbbDisplayImage('attachment', _MD_NEWBB_TOPICSHASATT); |
|
| 1121 | + } |
|
| 1122 | + } |
|
| 1123 | + } |
|
| 1124 | + |
|
| 1125 | + if (is_object($xoopsTpl)) { |
|
| 1126 | + $xoopsTpl->assign_by_ref('sticky', $sticky); |
|
| 1127 | + $xoopsTpl->assign_by_ref('topics', $topics); |
|
| 1128 | + |
|
| 1129 | + return; |
|
| 1130 | + } |
|
| 1131 | + |
|
| 1132 | + return [$topics, $sticky]; |
|
| 1133 | + } |
|
| 1134 | + |
|
| 1135 | + // START irmtfan to create an array from selected keys of an array |
|
| 1136 | + |
|
| 1137 | + /** |
|
| 1138 | + * @param $array |
|
| 1139 | + * @param null $keys |
|
| 1140 | + * @return array |
|
| 1141 | + */ |
|
| 1142 | + public function getFromKeys($array, $keys = null) |
|
| 1143 | + { |
|
| 1144 | + if (empty($keys)) { |
|
| 1145 | + return $array; |
|
| 1146 | + } // all keys |
|
| 1147 | + $keyarr = is_string($keys) ? explode(',', $keys) : $keys; |
|
| 1148 | + $keyarr = array_intersect(array_keys($array), $keyarr); // keys should be in array |
|
| 1149 | + $ret = []; |
|
| 1150 | + foreach ($keyarr as $key) { |
|
| 1151 | + $ret[$key] = $array[$key]; |
|
| 1152 | + } |
|
| 1153 | + |
|
| 1154 | + return $ret; |
|
| 1155 | + } |
|
| 1156 | + // END irmtfan to create an array from selected keys of an array |
|
| 1157 | 1157 | } |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | // START irmtfan use read_uid to find the unread posts when the user is logged in |
| 233 | 233 | $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
| 234 | 234 | if (!empty($read_uid)) { |
| 235 | - $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 . ' '; |
|
| 235 | + $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.' '; |
|
| 236 | 236 | $this->query['where'][] = 'r.post_id = t.topic_last_post_id'; |
| 237 | 237 | } else { |
| 238 | 238 | } |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | if ($lastvisit = max($GLOBALS['last_visit'], $startdate)) { |
| 245 | 245 | $readmode1query = ''; |
| 246 | 246 | if ($lastvisit > $startdate) { |
| 247 | - $readmode1query = 'p.post_time < ' . $lastvisit; |
|
| 247 | + $readmode1query = 'p.post_time < '.$lastvisit; |
|
| 248 | 248 | } |
| 249 | 249 | $topics = []; |
| 250 | 250 | $topic_lastread = newbbGetCookie('LT', true); |
@@ -256,9 +256,9 @@ discard block |
||
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | if (count($topics) > 0) { |
| 259 | - $topicquery = ' t.topic_id IN (' . implode(',', $topics) . ')'; |
|
| 259 | + $topicquery = ' t.topic_id IN ('.implode(',', $topics).')'; |
|
| 260 | 260 | // because it should be OR |
| 261 | - $readmode1query = !empty($readmode1query) ? '(' . $readmode1query . ' OR ' . $topicquery . ')' : $topicquery; |
|
| 261 | + $readmode1query = !empty($readmode1query) ? '('.$readmode1query.' OR '.$topicquery.')' : $topicquery; |
|
| 262 | 262 | } |
| 263 | 263 | $this->query['where'][] = $readmode1query; |
| 264 | 264 | } |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | // START irmtfan use read_uid to find the unread posts when the user is logged in |
| 275 | 275 | $read_uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
| 276 | 276 | if (!empty($read_uid)) { |
| 277 | - $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 . ' '; |
|
| 277 | + $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.' '; |
|
| 278 | 278 | $this->query['where'][] = '(r.read_id IS NULL OR r.post_id < t.topic_last_post_id)'; |
| 279 | 279 | } else { |
| 280 | 280 | } |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | $startdate = !empty($this->vars['since']) ? (time() - newbbGetSinceTime($this->vars['since'])) : 0; |
| 286 | 286 | if ($lastvisit = max($GLOBALS['last_visit'], $startdate)) { |
| 287 | 287 | if ($lastvisit > $startdate) { |
| 288 | - $this->query['where'][] = 'p.post_time > ' . $lastvisit; |
|
| 288 | + $this->query['where'][] = 'p.post_time > '.$lastvisit; |
|
| 289 | 289 | } |
| 290 | 290 | $topics = []; |
| 291 | 291 | $topic_lastread = newbbGetCookie('LT', true); |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | } |
| 298 | 298 | } |
| 299 | 299 | if (count($topics) > 0) { |
| 300 | - $this->query['where'][] = ' t.topic_id NOT IN (' . implode(',', $topics) . ')'; |
|
| 300 | + $this->query['where'][] = ' t.topic_id NOT IN ('.implode(',', $topics).')'; |
|
| 301 | 301 | } |
| 302 | 302 | } |
| 303 | 303 | // END irmtfan fix read_mode = 1 bugs - for all users (member and anon) |
@@ -356,20 +356,20 @@ discard block |
||
| 356 | 356 | //} elseif (count($accessForums) === 1) { |
| 357 | 357 | //$this->query["where"][] = "t.forum_id = " . $accessForums[0]; |
| 358 | 358 | } else { |
| 359 | - $this->query['where'][] = 't.forum_id IN ( ' . implode(', ', $accessForums) . ' )'; |
|
| 359 | + $this->query['where'][] = 't.forum_id IN ( '.implode(', ', $accessForums).' )'; |
|
| 360 | 360 | } |
| 361 | 361 | break; |
| 362 | 362 | |
| 363 | 363 | case 'uid': // irmtfan add multi topic poster |
| 364 | 364 | if (-1 !== $val) { |
| 365 | 365 | $val = implode(',', array_map('intval', explode(',', $val))); |
| 366 | - $this->query['where'][] = 't.topic_poster IN ( ' . $val . ' )'; |
|
| 366 | + $this->query['where'][] = 't.topic_poster IN ( '.$val.' )'; |
|
| 367 | 367 | } |
| 368 | 368 | break; |
| 369 | 369 | case 'lastposter': // irmtfan add multi lastposter |
| 370 | 370 | if (-1 !== $val) { |
| 371 | 371 | $val = implode(',', array_map('intval', explode(',', $val))); |
| 372 | - $this->query['where'][] = 'p.uid IN ( ' . $val . ' )'; |
|
| 372 | + $this->query['where'][] = 'p.uid IN ( '.$val.' )'; |
|
| 373 | 373 | } |
| 374 | 374 | break; |
| 375 | 375 | |
@@ -383,17 +383,17 @@ discard block |
||
| 383 | 383 | } |
| 384 | 384 | // irmtfan digest_time | to accept multiple status |
| 385 | 385 | if (in_array('digest', explode(',', $this->vars['status'], true))) { |
| 386 | - $this->query['where'][] = 't.digest_time > ' . $startdate; |
|
| 386 | + $this->query['where'][] = 't.digest_time > '.$startdate; |
|
| 387 | 387 | } |
| 388 | 388 | // irmtfan - should be >= instead of = |
| 389 | - $this->query['where'][] = 'p.post_time >= ' . $startdate; |
|
| 389 | + $this->query['where'][] = 'p.post_time >= '.$startdate; |
|
| 390 | 390 | // END irmtfan if unread && read_mode = 1 and last_visit > startdate do not add where query |
| 391 | 391 | } |
| 392 | 392 | break; |
| 393 | 393 | |
| 394 | 394 | case 'type': |
| 395 | 395 | if (!empty($val)) { |
| 396 | - $this->query['where'][] = 't.type_id = ' . $val; |
|
| 396 | + $this->query['where'][] = 't.type_id = '.$val; |
|
| 397 | 397 | } |
| 398 | 398 | break; |
| 399 | 399 | |
@@ -412,9 +412,9 @@ discard block |
||
| 412 | 412 | |
| 413 | 413 | case 'sort': |
| 414 | 414 | if ($sort = $this->getSort($val, 'sort')) { |
| 415 | - $this->query['sort'][] = $sort . (empty($this->vars['order']) ? ' DESC' : ' ASC'); |
|
| 415 | + $this->query['sort'][] = $sort.(empty($this->vars['order']) ? ' DESC' : ' ASC'); |
|
| 416 | 416 | } else { // irmtfan if sort is not in the list |
| 417 | - $this->query['sort'][] = 't.topic_last_post_id' . (empty($this->vars['order']) ? ' DESC' : ' ASC'); |
|
| 417 | + $this->query['sort'][] = 't.topic_last_post_id'.(empty($this->vars['order']) ? ' DESC' : ' ASC'); |
|
| 418 | 418 | } |
| 419 | 419 | break; |
| 420 | 420 | |
@@ -485,23 +485,23 @@ discard block |
||
| 485 | 485 | 'title' => _MD_NEWBB_VIEWS, |
| 486 | 486 | 'sort' => 't.topic_views' |
| 487 | 487 | ], |
| 488 | - 'lastpost' => [ // irmtfan show topic_page_jump_icon smarty |
|
| 488 | + 'lastpost' => [// irmtfan show topic_page_jump_icon smarty |
|
| 489 | 489 | 'title' => _MD_NEWBB_LASTPOST, |
| 490 | 490 | /*irmtfan _MD_NEWBB_DATE to _MD_NEWBB_LASTPOSTTIME again change to _MD_LASTPOST*/ |
| 491 | 491 | 'sort' => 't.topic_last_post_id' |
| 492 | 492 | ], |
| 493 | 493 | // START irmtfan add more sorts |
| 494 | - 'lastposttime' => [ // irmtfan same as lastpost |
|
| 494 | + 'lastposttime' => [// irmtfan same as lastpost |
|
| 495 | 495 | 'title' => _MD_NEWBB_LASTPOSTTIME, |
| 496 | 496 | 'sort' => 't.topic_last_post_id' |
| 497 | 497 | ], |
| 498 | - 'lastposter' => [ // irmtfan |
|
| 498 | + 'lastposter' => [// irmtfan |
|
| 499 | 499 | 'title' => _MD_NEWBB_POSTER, |
| 500 | - 'sort' => 'p.uid',// poster uid |
|
| 500 | + 'sort' => 'p.uid', // poster uid |
|
| 501 | 501 | ], |
| 502 | - 'lastpostmsgicon' => [ // irmtfan |
|
| 502 | + 'lastpostmsgicon' => [// irmtfan |
|
| 503 | 503 | 'title' => _MD_NEWBB_MESSAGEICON, |
| 504 | - 'sort' => 'p.icon',// post message icon |
|
| 504 | + 'sort' => 'p.icon', // post message icon |
|
| 505 | 505 | ], |
| 506 | 506 | 'ratings' => [ |
| 507 | 507 | 'title' => _MD_NEWBB_RATINGS, |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | 'sort' => 't.poll_id' |
| 533 | 533 | ] |
| 534 | 534 | ]; |
| 535 | - $types = $this->getTypes(); |
|
| 535 | + $types = $this->getTypes(); |
|
| 536 | 536 | if (!empty($types)) { |
| 537 | 537 | $headers['type'] = [ |
| 538 | 538 | 'title' => _MD_NEWBB_TYPE, |
@@ -575,7 +575,7 @@ discard block |
||
| 575 | 575 | // additional headers - important: those cannot be in sort anyway |
| 576 | 576 | $headers = array_merge($headersSort, [ |
| 577 | 577 | 'attachment' => _MD_NEWBB_TOPICSHASATT, // show attachment smarty |
| 578 | - 'read' => _MD_NEWBB_MARK_UNREAD . '|' . _MD_NEWBB_MARK_READ, // read/unread show topic_folder smarty |
|
| 578 | + 'read' => _MD_NEWBB_MARK_UNREAD.'|'._MD_NEWBB_MARK_READ, // read/unread show topic_folder smarty |
|
| 579 | 579 | 'pagenav' => _MD_NEWBB_PAGENAV_DISPLAY, // show topic_page_jump smarty - sort by topic_replies? |
| 580 | 580 | ]); |
| 581 | 581 | |
@@ -591,7 +591,7 @@ discard block |
||
| 591 | 591 | */ |
| 592 | 592 | public function getStatus($type = null, $status = null) |
| 593 | 593 | { |
| 594 | - $links = [ |
|
| 594 | + $links = [ |
|
| 595 | 595 | //"" => "", /* irmtfan remove empty array */ |
| 596 | 596 | 'all' => _ALL, |
| 597 | 597 | 'digest' => _MD_NEWBB_DIGEST, |
@@ -619,7 +619,7 @@ discard block |
||
| 619 | 619 | |
| 620 | 620 | // all status, for admin |
| 621 | 621 | if ($type > 1) { |
| 622 | - $links = array_merge($links, $links_admin);// irmtfan to accept multiple status |
|
| 622 | + $links = array_merge($links, $links_admin); // irmtfan to accept multiple status |
|
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | return $this->getFromKeys($links, $status); // irmtfan to accept multiple status |
@@ -633,10 +633,10 @@ discard block |
||
| 633 | 633 | { |
| 634 | 634 | $selection = ['action' => $this->page]; |
| 635 | 635 | $selection['vars'] = $this->vars; |
| 636 | - require_once dirname(__DIR__) . '/include/functions.forum.php'; |
|
| 636 | + require_once dirname(__DIR__).'/include/functions.forum.php'; |
|
| 637 | 637 | $forum_selected = empty($this->vars['forum']) ? null : explode('|', @$this->vars['forum']); |
| 638 | 638 | $selection['forum'] = '<select name="forum[]" multiple="multiple">'; |
| 639 | - $selection['forum'] .= '<option value="0">' . _MD_NEWBB_ALL . '</option>'; |
|
| 639 | + $selection['forum'] .= '<option value="0">'._MD_NEWBB_ALL.'</option>'; |
|
| 640 | 640 | $selection['forum'] .= newbbForumSelectBox($forum_selected); |
| 641 | 641 | $selection['forum'] .= '</select>'; |
| 642 | 642 | |
@@ -647,13 +647,13 @@ discard block |
||
| 647 | 647 | throw new \RuntimeException('$sorts must be an array.'); |
| 648 | 648 | } |
| 649 | 649 | foreach ($sorts as $sort => $title) { |
| 650 | - $selection['sort'] .= "<option value='" . $sort . "' " . (($sort == $sort_selected) ? " selected='selected'" : '') . '>' . $title . '</option>'; |
|
| 650 | + $selection['sort'] .= "<option value='".$sort."' ".(($sort == $sort_selected) ? " selected='selected'" : '').'>'.$title.'</option>'; |
|
| 651 | 651 | } |
| 652 | 652 | $selection['sort'] .= '</select>'; |
| 653 | 653 | |
| 654 | 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>'; |
|
| 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 | 657 | $selection['order'] .= '</select>'; |
| 658 | 658 | |
| 659 | 659 | $since = isset($this->vars['since']) ? $this->vars['since'] : $this->config['since_default']; |
@@ -696,10 +696,10 @@ discard block |
||
| 696 | 696 | foreach ($headers as $header => $title) { |
| 697 | 697 | $_args = ["sort={$header}"]; |
| 698 | 698 | if (@$this->vars['sort'] == $header) { |
| 699 | - $_args[] = 'order=' . ((@$this->vars['order'] + 1) % 2); |
|
| 699 | + $_args[] = 'order='.((@$this->vars['order'] + 1) % 2); |
|
| 700 | 700 | } |
| 701 | 701 | $headers_data[$header]['title'] = $title; |
| 702 | - $headers_data[$header]['link'] = $this->page . '?' . implode('&', array_merge($args, $_args)); |
|
| 702 | + $headers_data[$header]['link'] = $this->page.'?'.implode('&', array_merge($args, $_args)); |
|
| 703 | 703 | } |
| 704 | 704 | $xoopsTpl->assign_by_ref('headers', $headers_data); |
| 705 | 705 | } |
@@ -723,7 +723,7 @@ discard block |
||
| 723 | 723 | foreach ($links as $link => $title) { |
| 724 | 724 | $_args = ["status={$link}"]; |
| 725 | 725 | $status[$link]['title'] = $title; |
| 726 | - $status[$link]['link'] = $this->page . '?' . implode('&', array_merge($args, $_args)); |
|
| 726 | + $status[$link]['link'] = $this->page.'?'.implode('&', array_merge($args, $_args)); |
|
| 727 | 727 | } |
| 728 | 728 | $xoopsTpl->assign_by_ref('filters', $status); |
| 729 | 729 | } |
@@ -771,7 +771,7 @@ discard block |
||
| 771 | 771 | foreach ($types as $id => $type) { |
| 772 | 772 | $_args = ["type={$id}"]; |
| 773 | 773 | $status[$id]['title'] = $type['type_name']; |
| 774 | - $status[$id]['link'] = $this->page . '?' . implode('&', array_merge($args, $_args)); |
|
| 774 | + $status[$id]['link'] = $this->page.'?'.implode('&', array_merge($args, $_args)); |
|
| 775 | 775 | } |
| 776 | 776 | $xoopsTpl->assign_by_ref('types', $status); |
| 777 | 777 | } |
@@ -794,7 +794,7 @@ discard block |
||
| 794 | 794 | $status = []; |
| 795 | 795 | $status['title'] = implode(',', $this->getStatus($this->userlevel, $this->vars['status'])); // irmtfan to accept multiple status |
| 796 | 796 | //$status['link'] = $this->page.(empty($this->vars['status']) ? '' : '?status='.$this->vars['status']); |
| 797 | - $status['link'] = $this->page . (empty($args) ? '' : '?' . implode('&', $args)); |
|
| 797 | + $status['link'] = $this->page.(empty($args) ? '' : '?'.implode('&', $args)); |
|
| 798 | 798 | |
| 799 | 799 | $xoopsTpl->assign_by_ref('current', $status); |
| 800 | 800 | } |
@@ -816,7 +816,7 @@ discard block |
||
| 816 | 816 | require_once $GLOBALS['xoops']->path('class/pagenav.php'); |
| 817 | 817 | $nav = new \XoopsPageNav($count_topic, $this->config['topics_per_page'], @$this->vars['start'], 'start', implode('&', $args)); |
| 818 | 818 | if (isset($GLOBALS['xoopsModuleConfig']['do_rewrite'])) { |
| 819 | - $nav->url = formatURL(Request::getString('SERVER_NAME', '', 'SERVER')) . ' /' . $nav->url; |
|
| 819 | + $nav->url = formatURL(Request::getString('SERVER_NAME', '', 'SERVER')).' /'.$nav->url; |
|
| 820 | 820 | } |
| 821 | 821 | if ('select' === $this->config['pagenav_display']) { |
| 822 | 822 | $navi = $nav->renderSelect(); |
@@ -848,12 +848,12 @@ discard block |
||
| 848 | 848 | // topic fields |
| 849 | 849 | $selects[] = 'COUNT(*)'; |
| 850 | 850 | |
| 851 | - $froms[] = $this->handler->db->prefix('newbb_topics') . ' AS t '; |
|
| 852 | - $joins[] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_posts') . ' AS p ON p.post_id = t.topic_last_post_id'; |
|
| 851 | + $froms[] = $this->handler->db->prefix('newbb_topics').' AS t '; |
|
| 852 | + $joins[] = 'LEFT JOIN '.$this->handler->db->prefix('newbb_posts').' AS p ON p.post_id = t.topic_last_post_id'; |
|
| 853 | 853 | $wheres[] = '1 = 1'; |
| 854 | 854 | |
| 855 | - $sql = ' SELECT ' . implode(', ', $selects) . ' FROM ' . implode(', ', $froms) . ' ' . implode(' ', $joins) . (!empty($this->query['join']) ? ' ' . implode(' ', $this->query['join']) : '') . // irmtfan bug fix: Undefined index: join when post_excerpt = 0 |
|
| 856 | - ' WHERE ' . implode(' AND ', $wheres) . ' AND ' . @implode(' AND ', @$this->query['where']); |
|
| 855 | + $sql = ' SELECT '.implode(', ', $selects).' FROM '.implode(', ', $froms).' '.implode(' ', $joins).(!empty($this->query['join']) ? ' '.implode(' ', $this->query['join']) : '').// irmtfan bug fix: Undefined index: join when post_excerpt = 0 |
|
| 856 | + ' WHERE '.implode(' AND ', $wheres).' AND '.@implode(' AND ', @$this->query['where']); |
|
| 857 | 857 | |
| 858 | 858 | if (!$result = $this->handler->db->query($sql)) { |
| 859 | 859 | return 0; |
@@ -894,18 +894,18 @@ discard block |
||
| 894 | 894 | // post fields |
| 895 | 895 | $selects[] = 'p.post_time as last_post_time, p.poster_name as last_poster_name, p.icon, p.post_id, p.uid'; |
| 896 | 896 | |
| 897 | - $froms[] = $this->handler->db->prefix('newbb_topics') . ' AS t '; |
|
| 898 | - $joins[] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_posts') . ' AS p ON p.post_id = t.topic_last_post_id'; |
|
| 897 | + $froms[] = $this->handler->db->prefix('newbb_topics').' AS t '; |
|
| 898 | + $joins[] = 'LEFT JOIN '.$this->handler->db->prefix('newbb_posts').' AS p ON p.post_id = t.topic_last_post_id'; |
|
| 899 | 899 | $wheres[] = '1 = 1'; |
| 900 | 900 | |
| 901 | 901 | if (!empty($this->config['post_excerpt'])) { |
| 902 | 902 | $selects[] = 'p.post_karma, p.require_reply, pt.post_text'; |
| 903 | - $this->query['join'][] = 'LEFT JOIN ' . $this->handler->db->prefix('newbb_posts_text') . ' AS pt ON pt.post_id = t.topic_last_post_id'; |
|
| 903 | + $this->query['join'][] = 'LEFT JOIN '.$this->handler->db->prefix('newbb_posts_text').' AS pt ON pt.post_id = t.topic_last_post_id'; |
|
| 904 | 904 | } |
| 905 | 905 | //if (empty($this->query["sort"])) $this->query["sort"][] = 't.topic_last_post_id DESC'; // irmtfan commented no need |
| 906 | 906 | |
| 907 | - $sql = ' SELECT ' . implode(', ', $selects) . ' FROM ' . implode(', ', $froms) . ' ' . implode(' ', $joins) . (!empty($this->query['join']) ? ' ' . implode(' ', $this->query['join']) : '') . // irmtfan bug fix: Undefined index join when post_excerpt = 0 |
|
| 908 | - ' WHERE ' . implode(' AND ', $wheres) . ' AND ' . @implode(' AND ', @$this->query['where']) . ' ORDER BY ' . implode(', ', $this->query['sort']); |
|
| 907 | + $sql = ' SELECT '.implode(', ', $selects).' FROM '.implode(', ', $froms).' '.implode(' ', $joins).(!empty($this->query['join']) ? ' '.implode(' ', $this->query['join']) : '').// irmtfan bug fix: Undefined index join when post_excerpt = 0 |
|
| 908 | + ' WHERE '.implode(' AND ', $wheres).' AND '.@implode(' AND ', @$this->query['where']).' ORDER BY '.implode(', ', $this->query['sort']); |
|
| 909 | 909 | |
| 910 | 910 | if (!$result = $this->handler->db->query($sql, $this->config['topics_per_page'], @$this->vars['start'])) { |
| 911 | 911 | if (is_object($xoopsTpl)) { |
@@ -917,11 +917,11 @@ discard block |
||
| 917 | 917 | return $ret; |
| 918 | 918 | } |
| 919 | 919 | |
| 920 | - require_once dirname(__DIR__) . '/include/functions.render.php'; |
|
| 921 | - require_once dirname(__DIR__) . '/include/functions.session.php'; |
|
| 922 | - require_once dirname(__DIR__) . '/include/functions.time.php'; |
|
| 923 | - require_once dirname(__DIR__) . '/include/functions.read.php'; |
|
| 924 | - require_once dirname(__DIR__) . '/include/functions.topic.php'; |
|
| 920 | + require_once dirname(__DIR__).'/include/functions.render.php'; |
|
| 921 | + require_once dirname(__DIR__).'/include/functions.session.php'; |
|
| 922 | + require_once dirname(__DIR__).'/include/functions.time.php'; |
|
| 923 | + require_once dirname(__DIR__).'/include/functions.read.php'; |
|
| 924 | + require_once dirname(__DIR__).'/include/functions.topic.php'; |
|
| 925 | 925 | |
| 926 | 926 | $sticky = 0; |
| 927 | 927 | $topics = []; |
@@ -940,9 +940,9 @@ discard block |
||
| 940 | 940 | // START irmtfan remove topic_icon hardcode smarty |
| 941 | 941 | // topic_icon: just regular topic_icon |
| 942 | 942 | if (!empty($myrow['icon'])) { |
| 943 | - $topic_icon = '<img align="middle" src="' . XOOPS_URL . '/images/subject/' . htmlspecialchars($myrow['icon'], ENT_QUOTES | ENT_HTML5) . '" alt="" />'; |
|
| 943 | + $topic_icon = '<img align="middle" src="'.XOOPS_URL.'/images/subject/'.htmlspecialchars($myrow['icon'], ENT_QUOTES | ENT_HTML5).'" alt="" />'; |
|
| 944 | 944 | } else { |
| 945 | - $topic_icon = '<img align="middle" src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" />'; |
|
| 945 | + $topic_icon = '<img align="middle" src="'.XOOPS_URL.'/images/icons/no_posticon.gif" alt="" />'; |
|
| 946 | 946 | } |
| 947 | 947 | // END irmtfan remove topic_icon hardcode smarty |
| 948 | 948 | |
@@ -953,7 +953,7 @@ discard block |
||
| 953 | 953 | if ($rating < 1) { |
| 954 | 954 | $rating_img = newbbDisplayImage('blank'); |
| 955 | 955 | } else { |
| 956 | - $rating_img = newbbDisplayImage('rate' . $rating, constant('_MD_NEWBB_RATE' . $rating)); |
|
| 956 | + $rating_img = newbbDisplayImage('rate'.$rating, constant('_MD_NEWBB_RATE'.$rating)); |
|
| 957 | 957 | } |
| 958 | 958 | |
| 959 | 959 | // ------------------------------------------------------ |
@@ -963,22 +963,22 @@ discard block |
||
| 963 | 963 | $totalpages = ceil(($myrow['topic_replies'] + 1) / $this->config['posts_per_page']); |
| 964 | 964 | if ($totalpages > 1) { |
| 965 | 965 | $topic_page_jump .= ' '; |
| 966 | - $append = false; |
|
| 966 | + $append = false; |
|
| 967 | 967 | for ($i = 1; $i <= $totalpages; ++$i) { |
| 968 | 968 | if ($i > 3 && $i < $totalpages) { |
| 969 | 969 | if (!$append) { |
| 970 | 970 | $topic_page_jump .= '...'; |
| 971 | - $append = true; |
|
| 971 | + $append = true; |
|
| 972 | 972 | } |
| 973 | 973 | } else { |
| 974 | - $topic_page_jump .= '[<a href="' . XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'] . '&start=' . (($i - 1) * $this->config['posts_per_page']) . '">' . $i . '</a>]'; |
|
| 974 | + $topic_page_jump .= '[<a href="'.XOOPS_URL.'/modules/newbb/viewtopic.php?topic_id='.$myrow['topic_id'].'&start='.(($i - 1) * $this->config['posts_per_page']).'">'.$i.'</a>]'; |
|
| 975 | 975 | // irmtfan remove here and move |
| 976 | 976 | //$topic_page_jump_icon = "<a href='" . XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id=" . $myrow['topic_id'] . "&start=" . (($i - 1) * $this->config['posts_per_page']) . "" . "'>" . newbbDisplayImage('document',_MD_NEWBB_GOTOLASTPOST) . '</a>'; |
| 977 | 977 | } |
| 978 | 978 | } |
| 979 | 979 | } |
| 980 | 980 | // irmtfan - move here for both topics with and without pages - change topic_id to post_id |
| 981 | - $topic_page_jump_icon = "<a href='" . XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $myrow['topic_last_post_id'] . '' . "'>" . newbbDisplayImage('lastposticon', _MD_NEWBB_GOTOLASTPOST) . '</a>'; |
|
| 981 | + $topic_page_jump_icon = "<a href='".XOOPS_URL.'/modules/newbb/viewtopic.php?post_id='.$myrow['topic_last_post_id'].''."'>".newbbDisplayImage('lastposticon', _MD_NEWBB_GOTOLASTPOST).'</a>'; |
|
| 982 | 982 | |
| 983 | 983 | // ------------------------------------------------------ |
| 984 | 984 | // => topic array |
@@ -1010,7 +1010,7 @@ discard block |
||
| 1010 | 1010 | 'topic_title_excerpt' => $topic_title_excerpt, |
| 1011 | 1011 | //irmtfan use topic_title_excerpt |
| 1012 | 1012 | //'topic_link' => XOOPS_URL . '/modules/newbb/viewtopic.php?topic_id=' . $myrow['topic_id'], // . '&forum=' . $myrow['forum_id'], // irmtfan comment |
| 1013 | - 'topic_link' => 'viewtopic.php?topic_id=' . $myrow['topic_id'], |
|
| 1013 | + 'topic_link' => 'viewtopic.php?topic_id='.$myrow['topic_id'], |
|
| 1014 | 1014 | // irmtfan remove hardcode link |
| 1015 | 1015 | 'rating_img' => $rating_img, |
| 1016 | 1016 | 'votes' => $myrow['votes'], |
@@ -1069,14 +1069,14 @@ discard block |
||
| 1069 | 1069 | $forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
| 1070 | 1070 | |
| 1071 | 1071 | if (count($forums) > 0) { |
| 1072 | - $forum_list = $forumHandler->getAll(new \Criteria('forum_id', '(' . implode(', ', array_keys($forums)) . ')', 'IN'), ['forum_name', 'hot_threshold'], false); |
|
| 1072 | + $forum_list = $forumHandler->getAll(new \Criteria('forum_id', '('.implode(', ', array_keys($forums)).')', 'IN'), ['forum_name', 'hot_threshold'], false); |
|
| 1073 | 1073 | } else { |
| 1074 | 1074 | $forum_list = $forumHandler->getAll(); |
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | foreach (array_keys($topics) as $id) { |
| 1078 | 1078 | $topics[$id]['topic_read'] = empty($topic_isRead[$id]) ? 0 : 1; // add topic-read/topic-new smarty variable |
| 1079 | - $topics[$id]['topic_forum_link'] = '<a href="' . XOOPS_URL . '/modules/newbb/viewforum.php?forum=' . $topics[$id]['topic_forum'] . '">' . $forum_list[$topics[$id]['topic_forum']]['forum_name'] . '</a>'; |
|
| 1079 | + $topics[$id]['topic_forum_link'] = '<a href="'.XOOPS_URL.'/modules/newbb/viewforum.php?forum='.$topics[$id]['topic_forum'].'">'.$forum_list[$topics[$id]['topic_forum']]['forum_name'].'</a>'; |
|
| 1080 | 1080 | |
| 1081 | 1081 | //irmtfan use topic_title_excerpt -- add else |
| 1082 | 1082 | if (!empty($topics[$id]['type_id']) && isset($type_list[$topics[$id]['type_id']])) { |
@@ -1110,14 +1110,14 @@ discard block |
||
| 1110 | 1110 | $topics[$id]['topic_folder'] = newbbDisplayImage($topic_folder, $topic_folder_text); |
| 1111 | 1111 | // END irmtfan - add topic_folder_text for alt |
| 1112 | 1112 | |
| 1113 | - unset($topics[$id]['topic_poster_name'], $topics[$id]['topic_last_poster_name']);// irmtfan remove $topics[$id]["stats"] because it is not exist now |
|
| 1113 | + unset($topics[$id]['topic_poster_name'], $topics[$id]['topic_last_poster_name']); // irmtfan remove $topics[$id]["stats"] because it is not exist now |
|
| 1114 | 1114 | } |
| 1115 | 1115 | |
| 1116 | 1116 | if (count($topics) > 0) { |
| 1117 | - $sql = ' SELECT DISTINCT topic_id FROM ' . $this->handler->db->prefix('newbb_posts') . " WHERE attachment != ''" . ' AND topic_id IN (' . implode(',', array_keys($topics)) . ')'; |
|
| 1117 | + $sql = ' SELECT DISTINCT topic_id FROM '.$this->handler->db->prefix('newbb_posts')." WHERE attachment != ''".' AND topic_id IN ('.implode(',', array_keys($topics)).')'; |
|
| 1118 | 1118 | if ($result = $this->handler->db->query($sql)) { |
| 1119 | 1119 | while (false !== (list($topic_id) = $this->handler->db->fetchRow($result))) { |
| 1120 | - $topics[$topic_id]['attachment'] = ' ' . newbbDisplayImage('attachment', _MD_NEWBB_TOPICSHASATT); |
|
| 1120 | + $topics[$topic_id]['attachment'] = ' '.newbbDisplayImage('attachment', _MD_NEWBB_TOPICSHASATT); |
|
| 1121 | 1121 | } |
| 1122 | 1122 | } |
| 1123 | 1123 | } |
@@ -44,17 +44,17 @@ |
||
| 44 | 44 | */ |
| 45 | 45 | class Read extends \XoopsObject |
| 46 | 46 | { |
| 47 | - /** |
|
| 48 | - * @internal param $type |
|
| 49 | - */ |
|
| 50 | - public function __construct() |
|
| 51 | - { |
|
| 52 | - // parent::__construct("newbb_reads_" . $type); |
|
| 53 | - parent::__construct(); |
|
| 54 | - $this->initVar('read_id', XOBJ_DTYPE_INT); |
|
| 55 | - $this->initVar('uid', XOBJ_DTYPE_INT); |
|
| 56 | - $this->initVar('read_item', XOBJ_DTYPE_INT); |
|
| 57 | - $this->initVar('post_id', XOBJ_DTYPE_INT); |
|
| 58 | - $this->initVar('read_time', XOBJ_DTYPE_INT); |
|
| 59 | - } |
|
| 47 | + /** |
|
| 48 | + * @internal param $type |
|
| 49 | + */ |
|
| 50 | + public function __construct() |
|
| 51 | + { |
|
| 52 | + // parent::__construct("newbb_reads_" . $type); |
|
| 53 | + parent::__construct(); |
|
| 54 | + $this->initVar('read_id', XOBJ_DTYPE_INT); |
|
| 55 | + $this->initVar('uid', XOBJ_DTYPE_INT); |
|
| 56 | + $this->initVar('read_item', XOBJ_DTYPE_INT); |
|
| 57 | + $this->initVar('post_id', XOBJ_DTYPE_INT); |
|
| 58 | + $this->initVar('read_time', XOBJ_DTYPE_INT); |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -19,80 +19,80 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class Uploader extends \XoopsMediaUploader |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * No admin check for uploads |
|
| 24 | - */ |
|
| 25 | - /** |
|
| 26 | - * Constructor |
|
| 27 | - * |
|
| 28 | - * @param string $uploadDir |
|
| 29 | - * @param array|int|string $allowedMimeTypes |
|
| 30 | - * @param int $maxFileSize |
|
| 31 | - * @param int $maxWidth |
|
| 32 | - * @param int $maxHeight |
|
| 33 | - */ |
|
| 34 | - public function __construct($uploadDir, $allowedMimeTypes = 0, $maxFileSize = 0, $maxWidth = 0, $maxHeight = 0) |
|
| 35 | - { |
|
| 36 | - // $this->XoopsMediaUploader($uploadDir, $allowedMimeTypes, $maxFileSize, $maxWidth, $maxHeight); |
|
| 22 | + /** |
|
| 23 | + * No admin check for uploads |
|
| 24 | + */ |
|
| 25 | + /** |
|
| 26 | + * Constructor |
|
| 27 | + * |
|
| 28 | + * @param string $uploadDir |
|
| 29 | + * @param array|int|string $allowedMimeTypes |
|
| 30 | + * @param int $maxFileSize |
|
| 31 | + * @param int $maxWidth |
|
| 32 | + * @param int $maxHeight |
|
| 33 | + */ |
|
| 34 | + public function __construct($uploadDir, $allowedMimeTypes = 0, $maxFileSize = 0, $maxWidth = 0, $maxHeight = 0) |
|
| 35 | + { |
|
| 36 | + // $this->XoopsMediaUploader($uploadDir, $allowedMimeTypes, $maxFileSize, $maxWidth, $maxHeight); |
|
| 37 | 37 | |
| 38 | - if (!is_array($allowedMimeTypes)) { |
|
| 39 | - if (empty($allowedMimeTypes) || '*' === $allowedMimeTypes) { |
|
| 40 | - $allowedMimeTypes = []; |
|
| 41 | - } else { |
|
| 42 | - $allowedMimeTypes = array_filter(array_map('trim', explode('|', strtolower($allowedMimeTypes)))); |
|
| 43 | - } |
|
| 44 | - } |
|
| 45 | - $_allowedMimeTypes = []; |
|
| 46 | - $extensionToMime = require_once $GLOBALS['xoops']->path('include/mimetypes.inc.php'); |
|
| 47 | - foreach ($allowedMimeTypes as $type) { |
|
| 48 | - if (isset($extensionToMime[$type])) { |
|
| 49 | - $_allowedMimeTypes[] = $extensionToMime[$type]; |
|
| 50 | - } else { |
|
| 51 | - $_allowedMimeTypes[] = $type; |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - parent::__construct($uploadDir, $_allowedMimeTypes, $maxFileSize, $maxWidth, $maxHeight); |
|
| 55 | - } |
|
| 38 | + if (!is_array($allowedMimeTypes)) { |
|
| 39 | + if (empty($allowedMimeTypes) || '*' === $allowedMimeTypes) { |
|
| 40 | + $allowedMimeTypes = []; |
|
| 41 | + } else { |
|
| 42 | + $allowedMimeTypes = array_filter(array_map('trim', explode('|', strtolower($allowedMimeTypes)))); |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | + $_allowedMimeTypes = []; |
|
| 46 | + $extensionToMime = require_once $GLOBALS['xoops']->path('include/mimetypes.inc.php'); |
|
| 47 | + foreach ($allowedMimeTypes as $type) { |
|
| 48 | + if (isset($extensionToMime[$type])) { |
|
| 49 | + $_allowedMimeTypes[] = $extensionToMime[$type]; |
|
| 50 | + } else { |
|
| 51 | + $_allowedMimeTypes[] = $type; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + parent::__construct($uploadDir, $_allowedMimeTypes, $maxFileSize, $maxWidth, $maxHeight); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Set the CheckMediaTypeByExt |
|
| 59 | - * Deprecated |
|
| 60 | - * |
|
| 61 | - * @param bool|string $value |
|
| 62 | - */ |
|
| 63 | - public function setCheckMediaTypeByExt($value = true) |
|
| 64 | - { |
|
| 65 | - } |
|
| 57 | + /** |
|
| 58 | + * Set the CheckMediaTypeByExt |
|
| 59 | + * Deprecated |
|
| 60 | + * |
|
| 61 | + * @param bool|string $value |
|
| 62 | + */ |
|
| 63 | + public function setCheckMediaTypeByExt($value = true) |
|
| 64 | + { |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Set the imageSizeCheck |
|
| 69 | - * Deprecated |
|
| 70 | - * |
|
| 71 | - * @param string $value |
|
| 72 | - */ |
|
| 73 | - public function setImageSizeCheck($value) |
|
| 74 | - { |
|
| 75 | - } |
|
| 67 | + /** |
|
| 68 | + * Set the imageSizeCheck |
|
| 69 | + * Deprecated |
|
| 70 | + * |
|
| 71 | + * @param string $value |
|
| 72 | + */ |
|
| 73 | + public function setImageSizeCheck($value) |
|
| 74 | + { |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Set the fileSizeCheck |
|
| 79 | - * Deprecated |
|
| 80 | - * |
|
| 81 | - * @param string $value |
|
| 82 | - */ |
|
| 83 | - public function setFileSizeCheck($value) |
|
| 84 | - { |
|
| 85 | - } |
|
| 77 | + /** |
|
| 78 | + * Set the fileSizeCheck |
|
| 79 | + * Deprecated |
|
| 80 | + * |
|
| 81 | + * @param string $value |
|
| 82 | + */ |
|
| 83 | + public function setFileSizeCheck($value) |
|
| 84 | + { |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Get the file extension |
|
| 89 | - * |
|
| 90 | - * @return string |
|
| 91 | - */ |
|
| 92 | - public function getExt() |
|
| 93 | - { |
|
| 94 | - $this->ext = strtolower(ltrim(strrchr($this->getMediaName(), '.'), '.')); |
|
| 87 | + /** |
|
| 88 | + * Get the file extension |
|
| 89 | + * |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 92 | + public function getExt() |
|
| 93 | + { |
|
| 94 | + $this->ext = strtolower(ltrim(strrchr($this->getMediaName(), '.'), '.')); |
|
| 95 | 95 | |
| 96 | - return $this->ext; |
|
| 97 | - } |
|
| 96 | + return $this->ext; |
|
| 97 | + } |
|
| 98 | 98 | } |
@@ -39,17 +39,17 @@ |
||
| 39 | 39 | */ |
| 40 | 40 | class Rate extends \XoopsObject |
| 41 | 41 | { |
| 42 | - /** |
|
| 43 | - * |
|
| 44 | - */ |
|
| 45 | - public function __construct() |
|
| 46 | - { |
|
| 47 | - parent::__construct(); |
|
| 48 | - $this->initVar('ratingid', XOBJ_DTYPE_INT); |
|
| 49 | - $this->initVar('topic_id', XOBJ_DTYPE_INT); |
|
| 50 | - $this->initVar('ratinguser', XOBJ_DTYPE_INT); |
|
| 51 | - $this->initVar('rating', XOBJ_DTYPE_INT); |
|
| 52 | - $this->initVar('ratingtimestamp', XOBJ_DTYPE_INT); |
|
| 53 | - $this->initVar('ratinghostname', XOBJ_DTYPE_TXTBOX); |
|
| 54 | - } |
|
| 42 | + /** |
|
| 43 | + * |
|
| 44 | + */ |
|
| 45 | + public function __construct() |
|
| 46 | + { |
|
| 47 | + parent::__construct(); |
|
| 48 | + $this->initVar('ratingid', XOBJ_DTYPE_INT); |
|
| 49 | + $this->initVar('topic_id', XOBJ_DTYPE_INT); |
|
| 50 | + $this->initVar('ratinguser', XOBJ_DTYPE_INT); |
|
| 51 | + $this->initVar('rating', XOBJ_DTYPE_INT); |
|
| 52 | + $this->initVar('ratingtimestamp', XOBJ_DTYPE_INT); |
|
| 53 | + $this->initVar('ratinghostname', XOBJ_DTYPE_TXTBOX); |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -21,98 +21,98 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class UserHandler |
| 23 | 23 | { |
| 24 | - /** @var array */ |
|
| 25 | - public $users = []; |
|
| 26 | - |
|
| 27 | - /** @var bool */ |
|
| 28 | - private $enableGroup; |
|
| 29 | - |
|
| 30 | - /** @var bool */ |
|
| 31 | - private $enableOnline; |
|
| 32 | - |
|
| 33 | - /** @var array */ |
|
| 34 | - private $userlist = []; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @param bool $enableGroup |
|
| 38 | - * @param bool $enableOnline |
|
| 39 | - */ |
|
| 40 | - public function __construct($enableGroup = true, $enableOnline = true) |
|
| 41 | - { |
|
| 42 | - $this->enableGroup = $enableGroup; |
|
| 43 | - $this->enableOnline = $enableOnline; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - public function loadUserInfo() |
|
| 47 | - { |
|
| 48 | - /** @var Newbb\Helper $helper */ |
|
| 49 | - $helper = Newbb\Helper::getInstance(); |
|
| 50 | - $helper->loadLanguage('user'); |
|
| 24 | + /** @var array */ |
|
| 25 | + public $users = []; |
|
| 26 | + |
|
| 27 | + /** @var bool */ |
|
| 28 | + private $enableGroup; |
|
| 29 | + |
|
| 30 | + /** @var bool */ |
|
| 31 | + private $enableOnline; |
|
| 32 | + |
|
| 33 | + /** @var array */ |
|
| 34 | + private $userlist = []; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @param bool $enableGroup |
|
| 38 | + * @param bool $enableOnline |
|
| 39 | + */ |
|
| 40 | + public function __construct($enableGroup = true, $enableOnline = true) |
|
| 41 | + { |
|
| 42 | + $this->enableGroup = $enableGroup; |
|
| 43 | + $this->enableOnline = $enableOnline; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + public function loadUserInfo() |
|
| 47 | + { |
|
| 48 | + /** @var Newbb\Helper $helper */ |
|
| 49 | + $helper = Newbb\Helper::getInstance(); |
|
| 50 | + $helper->loadLanguage('user'); |
|
| 51 | 51 | // @require_once $GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModule']->getVar('dirname', 'n') . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/user.php'); |
| 52 | - if (class_exists('UserLanguage')) { |
|
| 53 | - $handler = new Newbb\UserLanguage(); |
|
| 54 | - } else { |
|
| 55 | - $handler = new User(); |
|
| 56 | - } |
|
| 57 | - foreach (array_keys($this->users) as $uid) { |
|
| 58 | - $this->userlist[$uid] = $handler->getInfo($this->users[$uid]); |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - public function loadUserOnline() |
|
| 63 | - { |
|
| 64 | - if (empty($this->users) || !$this->enableOnline) { |
|
| 65 | - return; |
|
| 66 | - } |
|
| 67 | - require_once dirname(__DIR__) . '/include/functions.render.php'; |
|
| 68 | - $image_online = newbbDisplayImage('online', _MD_NEWBB_ONLINE); |
|
| 69 | - $image_offline = newbbDisplayImage('offline', _MD_NEWBB_OFFLINE); |
|
| 70 | - |
|
| 71 | - /** @var Newbb\OnlineHandler $onlineHandler */ |
|
| 72 | - $onlineHandler = Newbb\Helper::getInstance()->getHandler('Online'); |
|
| 73 | - $onlines = $onlineHandler->checkStatus(array_keys($this->users)); |
|
| 74 | - |
|
| 75 | - foreach (array_keys($this->users) as $uid) { |
|
| 76 | - $this->userlist[$uid]['status'] = empty($onlines[$uid]) ? $image_offline : $image_online; |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - // START irmtfan remove function - no deprecated is needed because just use in this file |
|
| 80 | - // function loadUserGroups() |
|
| 81 | - // { |
|
| 82 | - // return true; |
|
| 83 | - // } |
|
| 84 | - // END irmtfan remove function - no deprecated is needed because just use in this file |
|
| 85 | - |
|
| 86 | - public function loadUserDigest() |
|
| 87 | - { |
|
| 88 | - if (empty($this->users)) { |
|
| 89 | - return; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - $sql = 'SELECT user_digests, uid FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_user_stats') . ' WHERE uid IN( ' . implode(', ', array_keys($this->users)) . ')'; |
|
| 93 | - $result = $GLOBALS['xoopsDB']->query($sql); |
|
| 94 | - while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) { |
|
| 95 | - $this->userlist[$myrow['uid']]['digests'] = (int)$myrow['user_digests']; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - // START irmtfan remove function |
|
| 99 | - // function loadUserRank() |
|
| 100 | - // { |
|
| 101 | - // return true; |
|
| 102 | - // } |
|
| 103 | - // END irmtfan remove function |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @return array |
|
| 107 | - */ |
|
| 108 | - public function getUsers() |
|
| 109 | - { |
|
| 110 | - $this->loadUserInfo(); |
|
| 111 | - $this->loadUserOnline(); |
|
| 112 | - // irmtfan removed $this->loadUserGroups(); |
|
| 113 | - // irmtfan removed $this->loadUserRank(); |
|
| 114 | - $this->loadUserDigest(); |
|
| 115 | - |
|
| 116 | - return $this->userlist; |
|
| 117 | - } |
|
| 52 | + if (class_exists('UserLanguage')) { |
|
| 53 | + $handler = new Newbb\UserLanguage(); |
|
| 54 | + } else { |
|
| 55 | + $handler = new User(); |
|
| 56 | + } |
|
| 57 | + foreach (array_keys($this->users) as $uid) { |
|
| 58 | + $this->userlist[$uid] = $handler->getInfo($this->users[$uid]); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + public function loadUserOnline() |
|
| 63 | + { |
|
| 64 | + if (empty($this->users) || !$this->enableOnline) { |
|
| 65 | + return; |
|
| 66 | + } |
|
| 67 | + require_once dirname(__DIR__) . '/include/functions.render.php'; |
|
| 68 | + $image_online = newbbDisplayImage('online', _MD_NEWBB_ONLINE); |
|
| 69 | + $image_offline = newbbDisplayImage('offline', _MD_NEWBB_OFFLINE); |
|
| 70 | + |
|
| 71 | + /** @var Newbb\OnlineHandler $onlineHandler */ |
|
| 72 | + $onlineHandler = Newbb\Helper::getInstance()->getHandler('Online'); |
|
| 73 | + $onlines = $onlineHandler->checkStatus(array_keys($this->users)); |
|
| 74 | + |
|
| 75 | + foreach (array_keys($this->users) as $uid) { |
|
| 76 | + $this->userlist[$uid]['status'] = empty($onlines[$uid]) ? $image_offline : $image_online; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + // START irmtfan remove function - no deprecated is needed because just use in this file |
|
| 80 | + // function loadUserGroups() |
|
| 81 | + // { |
|
| 82 | + // return true; |
|
| 83 | + // } |
|
| 84 | + // END irmtfan remove function - no deprecated is needed because just use in this file |
|
| 85 | + |
|
| 86 | + public function loadUserDigest() |
|
| 87 | + { |
|
| 88 | + if (empty($this->users)) { |
|
| 89 | + return; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + $sql = 'SELECT user_digests, uid FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_user_stats') . ' WHERE uid IN( ' . implode(', ', array_keys($this->users)) . ')'; |
|
| 93 | + $result = $GLOBALS['xoopsDB']->query($sql); |
|
| 94 | + while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) { |
|
| 95 | + $this->userlist[$myrow['uid']]['digests'] = (int)$myrow['user_digests']; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + // START irmtfan remove function |
|
| 99 | + // function loadUserRank() |
|
| 100 | + // { |
|
| 101 | + // return true; |
|
| 102 | + // } |
|
| 103 | + // END irmtfan remove function |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @return array |
|
| 107 | + */ |
|
| 108 | + public function getUsers() |
|
| 109 | + { |
|
| 110 | + $this->loadUserInfo(); |
|
| 111 | + $this->loadUserOnline(); |
|
| 112 | + // irmtfan removed $this->loadUserGroups(); |
|
| 113 | + // irmtfan removed $this->loadUserRank(); |
|
| 114 | + $this->loadUserDigest(); |
|
| 115 | + |
|
| 116 | + return $this->userlist; |
|
| 117 | + } |
|
| 118 | 118 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | if (empty($this->users) || !$this->enableOnline) { |
| 65 | 65 | return; |
| 66 | 66 | } |
| 67 | - require_once dirname(__DIR__) . '/include/functions.render.php'; |
|
| 67 | + require_once dirname(__DIR__).'/include/functions.render.php'; |
|
| 68 | 68 | $image_online = newbbDisplayImage('online', _MD_NEWBB_ONLINE); |
| 69 | 69 | $image_offline = newbbDisplayImage('offline', _MD_NEWBB_OFFLINE); |
| 70 | 70 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | return; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - $sql = 'SELECT user_digests, uid FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_user_stats') . ' WHERE uid IN( ' . implode(', ', array_keys($this->users)) . ')'; |
|
| 92 | + $sql = 'SELECT user_digests, uid FROM '.$GLOBALS['xoopsDB']->prefix('newbb_user_stats').' WHERE uid IN( '.implode(', ', array_keys($this->users)).')'; |
|
| 93 | 93 | $result = $GLOBALS['xoopsDB']->query($sql); |
| 94 | 94 | while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) { |
| 95 | 95 | $this->userlist[$myrow['uid']]['digests'] = (int)$myrow['user_digests']; |
@@ -48,161 +48,161 @@ |
||
| 48 | 48 | */ |
| 49 | 49 | class ReadtopicHandler extends Newbb\ReadHandler |
| 50 | 50 | { |
| 51 | - /** |
|
| 52 | - * maximum records per forum for one user. |
|
| 53 | - * assigned from $GLOBALS['xoopsModuleConfig']["read_items"] |
|
| 54 | - * |
|
| 55 | - * @var integer |
|
| 56 | - */ |
|
| 57 | - private $items_per_forum; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @param \XoopsDatabase|null $db |
|
| 61 | - */ |
|
| 62 | - public function __construct(\XoopsDatabase $db) |
|
| 63 | - { |
|
| 64 | - parent::__construct($db, 'topic'); |
|
| 65 | - $newbbConfig = newbbLoadConfig(); |
|
| 66 | - $this->items_per_forum = isset($newbbConfig['read_items']) ? (int)$newbbConfig['read_items'] : 100; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * clean orphan items from database |
|
| 71 | - * |
|
| 72 | - * @param string $table_link |
|
| 73 | - * @param string $field_link |
|
| 74 | - * @param string $field_object |
|
| 75 | - * @return bool true on success |
|
| 76 | - */ |
|
| 77 | - public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
|
| 78 | - { |
|
| 79 | - parent::cleanOrphan($this->db->prefix('newbb_posts'), 'post_id'); |
|
| 80 | - |
|
| 81 | - return parent::cleanOrphan($this->db->prefix('newbb_topics'), 'topic_id', 'read_item'); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Clear garbage |
|
| 86 | - * |
|
| 87 | - * Delete all expired and duplicated records |
|
| 88 | - */ |
|
| 89 | - public function clearGarbage() |
|
| 90 | - { |
|
| 91 | - parent::clearGarbage(); |
|
| 92 | - |
|
| 93 | - // TODO: clearItemsExceedMaximumItemsPerForum |
|
| 94 | - return true; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @param int $status |
|
| 99 | - * @param int $forum_id |
|
| 100 | - * @param null $uid |
|
| 101 | - * @return bool |
|
| 102 | - */ |
|
| 103 | - public function setReadItems($status = 0, $forum_id = 0, $uid = null) |
|
| 104 | - { |
|
| 105 | - if (empty($this->mode)) { |
|
| 106 | - return true; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if (1 == $this->mode) { |
|
| 110 | - return $this->setReadItemsCookie($status, $forum_id); |
|
| 111 | - } else { |
|
| 112 | - return $this->setReadItemsDb($status, $forum_id, $uid); |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @param $status |
|
| 118 | - * @param $forum_id |
|
| 119 | - * @return bool |
|
| 120 | - */ |
|
| 121 | - public function setReadItemsCookie($status, $forum_id) |
|
| 122 | - { |
|
| 123 | - $cookie_name = 'LT'; |
|
| 124 | - $cookie_vars = newbbGetCookie($cookie_name, true); |
|
| 125 | - |
|
| 126 | - /** @var Newbb\TopicHandler $itemHandler */ |
|
| 127 | - $itemHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
| 128 | - $criteria = new \CriteriaCompo(new \Criteria('forum_id', $forum_id)); |
|
| 129 | - $criteria->setSort('topic_last_post_id'); |
|
| 130 | - $criteria->setOrder('DESC'); |
|
| 131 | - $criteria->setLimit($this->items_per_forum); |
|
| 132 | - $items = $itemHandler->getIds($criteria); |
|
| 133 | - |
|
| 134 | - foreach ($items as $var) { |
|
| 135 | - if (empty($status)) { |
|
| 136 | - if (isset($cookie_vars[$var])) { |
|
| 137 | - unset($cookie_vars[$var]); |
|
| 138 | - } |
|
| 139 | - } else { |
|
| 140 | - $cookie_vars[$var] = time() /*$items[$var]*/ |
|
| 141 | - ; |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - newbbSetCookie($cookie_name, $cookie_vars); |
|
| 145 | - |
|
| 146 | - return true; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @param $status |
|
| 151 | - * @param $forum_id |
|
| 152 | - * @param $uid |
|
| 153 | - * @return bool |
|
| 154 | - */ |
|
| 155 | - public function setReadItemsDb($status, $forum_id, $uid) |
|
| 156 | - { |
|
| 157 | - if (empty($uid)) { |
|
| 158 | - if (is_object($GLOBALS['xoopsUser'])) { |
|
| 159 | - $uid = $GLOBALS['xoopsUser']->getVar('uid'); |
|
| 160 | - } else { |
|
| 161 | - return false; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** @var Newbb\TopicHandler $itemHandler */ |
|
| 166 | - $itemHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
| 167 | - $criteria_topic = new \CriteriaCompo(new \Criteria('forum_id', $forum_id)); |
|
| 168 | - $criteria_topic->setSort('topic_last_post_id'); |
|
| 169 | - $criteria_topic->setOrder('DESC'); |
|
| 170 | - $criteria_topic->setLimit($this->items_per_forum); |
|
| 171 | - $criteria_sticky = new \CriteriaCompo(new \Criteria('forum_id', $forum_id)); |
|
| 172 | - $criteria_sticky->add(new \Criteria('topic_sticky', 1)); |
|
| 173 | - |
|
| 174 | - if (empty($status)) { |
|
| 175 | - $items_id = $itemHandler->getIds($criteria_topic); |
|
| 176 | - $sticky_id = $itemHandler->getIds($criteria_sticky); |
|
| 177 | - $items = $items_id + $sticky_id; |
|
| 178 | - $criteria = new \CriteriaCompo(new \Criteria('uid', $uid)); |
|
| 179 | - $criteria->add(new \Criteria('read_item', '(' . implode(', ', $items) . ')', 'IN')); |
|
| 180 | - $this->deleteAll($criteria, true); |
|
| 181 | - |
|
| 182 | - return true; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - $itemsObject = $itemHandler->getAll($criteria_topic, ['topic_last_post_id']); |
|
| 186 | - $stickyObject = $itemHandler->getAll($criteria_sticky, ['topic_last_post_id']); |
|
| 187 | - $itemsObject += $stickyObject; |
|
| 188 | - $items = []; |
|
| 189 | - foreach (array_keys($itemsObject) as $key) { |
|
| 190 | - $items[$key] = $itemsObject[$key]->getVar('topic_last_post_id'); |
|
| 191 | - } |
|
| 192 | - unset($itemsObject, $stickyObject); |
|
| 193 | - |
|
| 194 | - foreach (array_keys($items) as $key) { |
|
| 195 | - $this->setReadDb($key, $items[$key], $uid); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - return true; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * |
|
| 203 | - */ |
|
| 204 | - public function synchronization() |
|
| 205 | - { |
|
| 206 | - // return; |
|
| 207 | - } |
|
| 51 | + /** |
|
| 52 | + * maximum records per forum for one user. |
|
| 53 | + * assigned from $GLOBALS['xoopsModuleConfig']["read_items"] |
|
| 54 | + * |
|
| 55 | + * @var integer |
|
| 56 | + */ |
|
| 57 | + private $items_per_forum; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @param \XoopsDatabase|null $db |
|
| 61 | + */ |
|
| 62 | + public function __construct(\XoopsDatabase $db) |
|
| 63 | + { |
|
| 64 | + parent::__construct($db, 'topic'); |
|
| 65 | + $newbbConfig = newbbLoadConfig(); |
|
| 66 | + $this->items_per_forum = isset($newbbConfig['read_items']) ? (int)$newbbConfig['read_items'] : 100; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * clean orphan items from database |
|
| 71 | + * |
|
| 72 | + * @param string $table_link |
|
| 73 | + * @param string $field_link |
|
| 74 | + * @param string $field_object |
|
| 75 | + * @return bool true on success |
|
| 76 | + */ |
|
| 77 | + public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
|
| 78 | + { |
|
| 79 | + parent::cleanOrphan($this->db->prefix('newbb_posts'), 'post_id'); |
|
| 80 | + |
|
| 81 | + return parent::cleanOrphan($this->db->prefix('newbb_topics'), 'topic_id', 'read_item'); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Clear garbage |
|
| 86 | + * |
|
| 87 | + * Delete all expired and duplicated records |
|
| 88 | + */ |
|
| 89 | + public function clearGarbage() |
|
| 90 | + { |
|
| 91 | + parent::clearGarbage(); |
|
| 92 | + |
|
| 93 | + // TODO: clearItemsExceedMaximumItemsPerForum |
|
| 94 | + return true; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @param int $status |
|
| 99 | + * @param int $forum_id |
|
| 100 | + * @param null $uid |
|
| 101 | + * @return bool |
|
| 102 | + */ |
|
| 103 | + public function setReadItems($status = 0, $forum_id = 0, $uid = null) |
|
| 104 | + { |
|
| 105 | + if (empty($this->mode)) { |
|
| 106 | + return true; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if (1 == $this->mode) { |
|
| 110 | + return $this->setReadItemsCookie($status, $forum_id); |
|
| 111 | + } else { |
|
| 112 | + return $this->setReadItemsDb($status, $forum_id, $uid); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @param $status |
|
| 118 | + * @param $forum_id |
|
| 119 | + * @return bool |
|
| 120 | + */ |
|
| 121 | + public function setReadItemsCookie($status, $forum_id) |
|
| 122 | + { |
|
| 123 | + $cookie_name = 'LT'; |
|
| 124 | + $cookie_vars = newbbGetCookie($cookie_name, true); |
|
| 125 | + |
|
| 126 | + /** @var Newbb\TopicHandler $itemHandler */ |
|
| 127 | + $itemHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
| 128 | + $criteria = new \CriteriaCompo(new \Criteria('forum_id', $forum_id)); |
|
| 129 | + $criteria->setSort('topic_last_post_id'); |
|
| 130 | + $criteria->setOrder('DESC'); |
|
| 131 | + $criteria->setLimit($this->items_per_forum); |
|
| 132 | + $items = $itemHandler->getIds($criteria); |
|
| 133 | + |
|
| 134 | + foreach ($items as $var) { |
|
| 135 | + if (empty($status)) { |
|
| 136 | + if (isset($cookie_vars[$var])) { |
|
| 137 | + unset($cookie_vars[$var]); |
|
| 138 | + } |
|
| 139 | + } else { |
|
| 140 | + $cookie_vars[$var] = time() /*$items[$var]*/ |
|
| 141 | + ; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + newbbSetCookie($cookie_name, $cookie_vars); |
|
| 145 | + |
|
| 146 | + return true; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @param $status |
|
| 151 | + * @param $forum_id |
|
| 152 | + * @param $uid |
|
| 153 | + * @return bool |
|
| 154 | + */ |
|
| 155 | + public function setReadItemsDb($status, $forum_id, $uid) |
|
| 156 | + { |
|
| 157 | + if (empty($uid)) { |
|
| 158 | + if (is_object($GLOBALS['xoopsUser'])) { |
|
| 159 | + $uid = $GLOBALS['xoopsUser']->getVar('uid'); |
|
| 160 | + } else { |
|
| 161 | + return false; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** @var Newbb\TopicHandler $itemHandler */ |
|
| 166 | + $itemHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
| 167 | + $criteria_topic = new \CriteriaCompo(new \Criteria('forum_id', $forum_id)); |
|
| 168 | + $criteria_topic->setSort('topic_last_post_id'); |
|
| 169 | + $criteria_topic->setOrder('DESC'); |
|
| 170 | + $criteria_topic->setLimit($this->items_per_forum); |
|
| 171 | + $criteria_sticky = new \CriteriaCompo(new \Criteria('forum_id', $forum_id)); |
|
| 172 | + $criteria_sticky->add(new \Criteria('topic_sticky', 1)); |
|
| 173 | + |
|
| 174 | + if (empty($status)) { |
|
| 175 | + $items_id = $itemHandler->getIds($criteria_topic); |
|
| 176 | + $sticky_id = $itemHandler->getIds($criteria_sticky); |
|
| 177 | + $items = $items_id + $sticky_id; |
|
| 178 | + $criteria = new \CriteriaCompo(new \Criteria('uid', $uid)); |
|
| 179 | + $criteria->add(new \Criteria('read_item', '(' . implode(', ', $items) . ')', 'IN')); |
|
| 180 | + $this->deleteAll($criteria, true); |
|
| 181 | + |
|
| 182 | + return true; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + $itemsObject = $itemHandler->getAll($criteria_topic, ['topic_last_post_id']); |
|
| 186 | + $stickyObject = $itemHandler->getAll($criteria_sticky, ['topic_last_post_id']); |
|
| 187 | + $itemsObject += $stickyObject; |
|
| 188 | + $items = []; |
|
| 189 | + foreach (array_keys($itemsObject) as $key) { |
|
| 190 | + $items[$key] = $itemsObject[$key]->getVar('topic_last_post_id'); |
|
| 191 | + } |
|
| 192 | + unset($itemsObject, $stickyObject); |
|
| 193 | + |
|
| 194 | + foreach (array_keys($items) as $key) { |
|
| 195 | + $this->setReadDb($key, $items[$key], $uid); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + return true; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * |
|
| 203 | + */ |
|
| 204 | + public function synchronization() |
|
| 205 | + { |
|
| 206 | + // return; |
|
| 207 | + } |
|
| 208 | 208 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | use XoopsModules\Newbb; |
| 34 | 34 | |
| 35 | -require_once __DIR__ . '/Read.php'; |
|
| 35 | +require_once __DIR__.'/Read.php'; |
|
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * A handler for read/unread handling |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | $sticky_id = $itemHandler->getIds($criteria_sticky); |
| 177 | 177 | $items = $items_id + $sticky_id; |
| 178 | 178 | $criteria = new \CriteriaCompo(new \Criteria('uid', $uid)); |
| 179 | - $criteria->add(new \Criteria('read_item', '(' . implode(', ', $items) . ')', 'IN')); |
|
| 179 | + $criteria->add(new \Criteria('read_item', '('.implode(', ', $items).')', 'IN')); |
|
| 180 | 180 | $this->deleteAll($criteria, true); |
| 181 | 181 | |
| 182 | 182 | return true; |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | |
| 185 | 185 | $itemsObject = $itemHandler->getAll($criteria_topic, ['topic_last_post_id']); |
| 186 | 186 | $stickyObject = $itemHandler->getAll($criteria_sticky, ['topic_last_post_id']); |
| 187 | - $itemsObject += $stickyObject; |
|
| 187 | + $itemsObject += $stickyObject; |
|
| 188 | 188 | $items = []; |
| 189 | 189 | foreach (array_keys($itemsObject) as $key) { |
| 190 | 190 | $items[$key] = $itemsObject[$key]->getVar('topic_last_post_id'); |