@@ -48,105 +48,105 @@ |
||
48 | 48 | */ |
49 | 49 | class ReadForumHandler extends Newbb\ReadHandler |
50 | 50 | { |
51 | - /** |
|
52 | - * @param \XoopsDatabase|null $db |
|
53 | - */ |
|
54 | - public function __construct(\XoopsDatabase $db) |
|
55 | - { |
|
56 | - parent::__construct($db, 'forum'); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * clean orphan items from database |
|
61 | - * |
|
62 | - * @param string $table_link |
|
63 | - * @param string $field_link |
|
64 | - * @param string $field_object |
|
65 | - * @return bool true on success |
|
66 | - */ |
|
67 | - public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
|
68 | - { |
|
69 | - parent::cleanOrphan($this->db->prefix('newbb_posts'), 'post_id'); |
|
70 | - |
|
71 | - return parent::cleanOrphan($this->db->prefix('newbb_forums'), 'forum_id', 'read_item'); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * @param int $status |
|
76 | - * @param null $uid |
|
77 | - * @return bool |
|
78 | - */ |
|
79 | - public function setReadItems($status = 0, $uid = null) |
|
80 | - { |
|
81 | - if (empty($this->mode)) { |
|
82 | - return true; |
|
83 | - } |
|
84 | - |
|
85 | - if (1 == $this->mode) { |
|
86 | - return $this->setReadItemsCookie($status); |
|
87 | - } else { |
|
88 | - return $this->setReadItemsDb($status, $uid); |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * @param $status |
|
94 | - * @param $items |
|
95 | - * @return bool |
|
96 | - */ |
|
97 | - public function setReadItemsCookie($status, $items) |
|
98 | - { |
|
99 | - $cookie_name = 'LF'; |
|
100 | - $items = []; |
|
101 | - if (!empty($status)) { |
|
102 | - /** @var Newbb\ForumHandler $itemHandler */ |
|
103 | - $itemHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
104 | - $items_id = $itemHandler->getIds(); |
|
105 | - foreach ($items_id as $key) { |
|
106 | - $items[$key] = time(); |
|
107 | - } |
|
108 | - } |
|
109 | - newbbSetCookie($cookie_name, $items); |
|
110 | - |
|
111 | - return true; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @param $status |
|
116 | - * @param $uid |
|
117 | - * @return bool |
|
118 | - */ |
|
119 | - public function setReadItemsDb($status, $uid) |
|
120 | - { |
|
121 | - if (empty($uid)) { |
|
122 | - if (is_object($GLOBALS['xoopsUser'])) { |
|
123 | - $uid = $GLOBALS['xoopsUser']->getVar('uid'); |
|
124 | - } else { |
|
125 | - return false; |
|
126 | - } |
|
127 | - } |
|
128 | - if (empty($status)) { |
|
129 | - $this->deleteAll(new \Criteria('uid', $uid)); |
|
130 | - |
|
131 | - return true; |
|
132 | - } |
|
133 | - |
|
134 | - /** @var Newbb\ForumHandler $itemHandler */ |
|
135 | - $itemHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
136 | - $itemsObject = $itemHandler->getAll(null, ['forum_last_post_id']); |
|
137 | - foreach (array_keys($itemsObject) as $key) { |
|
138 | - $this->setReadDb($key, $itemsObject[$key]->getVar('forum_last_post_id'), $uid); |
|
139 | - } |
|
140 | - unset($itemsObject); |
|
141 | - |
|
142 | - return true; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * |
|
147 | - */ |
|
148 | - public function synchronization() |
|
149 | - { |
|
150 | - // return; |
|
151 | - } |
|
51 | + /** |
|
52 | + * @param \XoopsDatabase|null $db |
|
53 | + */ |
|
54 | + public function __construct(\XoopsDatabase $db) |
|
55 | + { |
|
56 | + parent::__construct($db, 'forum'); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * clean orphan items from database |
|
61 | + * |
|
62 | + * @param string $table_link |
|
63 | + * @param string $field_link |
|
64 | + * @param string $field_object |
|
65 | + * @return bool true on success |
|
66 | + */ |
|
67 | + public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
|
68 | + { |
|
69 | + parent::cleanOrphan($this->db->prefix('newbb_posts'), 'post_id'); |
|
70 | + |
|
71 | + return parent::cleanOrphan($this->db->prefix('newbb_forums'), 'forum_id', 'read_item'); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * @param int $status |
|
76 | + * @param null $uid |
|
77 | + * @return bool |
|
78 | + */ |
|
79 | + public function setReadItems($status = 0, $uid = null) |
|
80 | + { |
|
81 | + if (empty($this->mode)) { |
|
82 | + return true; |
|
83 | + } |
|
84 | + |
|
85 | + if (1 == $this->mode) { |
|
86 | + return $this->setReadItemsCookie($status); |
|
87 | + } else { |
|
88 | + return $this->setReadItemsDb($status, $uid); |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * @param $status |
|
94 | + * @param $items |
|
95 | + * @return bool |
|
96 | + */ |
|
97 | + public function setReadItemsCookie($status, $items) |
|
98 | + { |
|
99 | + $cookie_name = 'LF'; |
|
100 | + $items = []; |
|
101 | + if (!empty($status)) { |
|
102 | + /** @var Newbb\ForumHandler $itemHandler */ |
|
103 | + $itemHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
104 | + $items_id = $itemHandler->getIds(); |
|
105 | + foreach ($items_id as $key) { |
|
106 | + $items[$key] = time(); |
|
107 | + } |
|
108 | + } |
|
109 | + newbbSetCookie($cookie_name, $items); |
|
110 | + |
|
111 | + return true; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @param $status |
|
116 | + * @param $uid |
|
117 | + * @return bool |
|
118 | + */ |
|
119 | + public function setReadItemsDb($status, $uid) |
|
120 | + { |
|
121 | + if (empty($uid)) { |
|
122 | + if (is_object($GLOBALS['xoopsUser'])) { |
|
123 | + $uid = $GLOBALS['xoopsUser']->getVar('uid'); |
|
124 | + } else { |
|
125 | + return false; |
|
126 | + } |
|
127 | + } |
|
128 | + if (empty($status)) { |
|
129 | + $this->deleteAll(new \Criteria('uid', $uid)); |
|
130 | + |
|
131 | + return true; |
|
132 | + } |
|
133 | + |
|
134 | + /** @var Newbb\ForumHandler $itemHandler */ |
|
135 | + $itemHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
136 | + $itemsObject = $itemHandler->getAll(null, ['forum_last_post_id']); |
|
137 | + foreach (array_keys($itemsObject) as $key) { |
|
138 | + $this->setReadDb($key, $itemsObject[$key]->getVar('forum_last_post_id'), $uid); |
|
139 | + } |
|
140 | + unset($itemsObject); |
|
141 | + |
|
142 | + return true; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * |
|
147 | + */ |
|
148 | + public function synchronization() |
|
149 | + { |
|
150 | + // return; |
|
151 | + } |
|
152 | 152 | } |
@@ -32,7 +32,7 @@ |
||
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 |
@@ -39,32 +39,32 @@ |
||
39 | 39 | */ |
40 | 40 | class RateHandler extends \XoopsPersistableObjectHandler |
41 | 41 | { |
42 | - /** |
|
43 | - * @param \XoopsDatabase $db |
|
44 | - */ |
|
45 | - public function __construct(\XoopsDatabase $db) |
|
46 | - { |
|
47 | - parent::__construct($db, 'newbb_votedata', Rate::class, 'ratingid', ''); |
|
48 | - } |
|
42 | + /** |
|
43 | + * @param \XoopsDatabase $db |
|
44 | + */ |
|
45 | + public function __construct(\XoopsDatabase $db) |
|
46 | + { |
|
47 | + parent::__construct($db, 'newbb_votedata', Rate::class, 'ratingid', ''); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * |
|
52 | - */ |
|
53 | - public function synchronization() |
|
54 | - { |
|
55 | - // return; |
|
56 | - } |
|
50 | + /** |
|
51 | + * |
|
52 | + */ |
|
53 | + public function synchronization() |
|
54 | + { |
|
55 | + // return; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * clean orphan items from database |
|
60 | - * |
|
61 | - * @param string $table_link |
|
62 | - * @param string $field_link |
|
63 | - * @param string $field_object |
|
64 | - * @return bool true on success |
|
65 | - */ |
|
66 | - public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
|
67 | - { |
|
68 | - return parent::cleanOrphan($this->db->prefix('newbb_topics'), 'topic_id'); |
|
69 | - } |
|
58 | + /** |
|
59 | + * clean orphan items from database |
|
60 | + * |
|
61 | + * @param string $table_link |
|
62 | + * @param string $field_link |
|
63 | + * @param string $field_object |
|
64 | + * @return bool true on success |
|
65 | + */ |
|
66 | + public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
|
67 | + { |
|
68 | + return parent::cleanOrphan($this->db->prefix('newbb_topics'), 'topic_id'); |
|
69 | + } |
|
70 | 70 | } |
@@ -45,11 +45,11 @@ |
||
45 | 45 | */ |
46 | 46 | class ReadForum extends Newbb\Read |
47 | 47 | { |
48 | - /** |
|
49 | - * |
|
50 | - */ |
|
51 | - public function __construct() |
|
52 | - { |
|
53 | - parent::__construct(); |
|
54 | - } |
|
48 | + /** |
|
49 | + * |
|
50 | + */ |
|
51 | + public function __construct() |
|
52 | + { |
|
53 | + parent::__construct(); |
|
54 | + } |
|
55 | 55 | } |
@@ -33,7 +33,7 @@ |
||
33 | 33 | use XoopsModules\Newbb; |
34 | 34 | |
35 | 35 | |
36 | -require_once __DIR__ . '/Read.php'; |
|
36 | +require_once __DIR__.'/Read.php'; |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * A handler for read/unread handling |
@@ -26,72 +26,72 @@ |
||
26 | 26 | */ |
27 | 27 | class Helper extends \Xmf\Module\Helper |
28 | 28 | { |
29 | - public $debug; |
|
29 | + public $debug; |
|
30 | 30 | |
31 | - /** |
|
32 | - * |
|
33 | - * @param bool $debug |
|
34 | - */ |
|
35 | - public function __construct($debug = false) |
|
36 | - { |
|
37 | - $this->debug = $debug; |
|
38 | - $moduleDirName = basename(dirname(__DIR__)); |
|
39 | - parent::__construct($moduleDirName); |
|
40 | - } |
|
31 | + /** |
|
32 | + * |
|
33 | + * @param bool $debug |
|
34 | + */ |
|
35 | + public function __construct($debug = false) |
|
36 | + { |
|
37 | + $this->debug = $debug; |
|
38 | + $moduleDirName = basename(dirname(__DIR__)); |
|
39 | + parent::__construct($moduleDirName); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param bool $debug |
|
44 | - * |
|
45 | - * @return \XoopsModules\Newbb\Helper |
|
46 | - */ |
|
47 | - public static function getInstance($debug = false) |
|
48 | - { |
|
49 | - static $instance; |
|
50 | - if (null === $instance) { |
|
51 | - $instance = new static($debug); |
|
52 | - } |
|
42 | + /** |
|
43 | + * @param bool $debug |
|
44 | + * |
|
45 | + * @return \XoopsModules\Newbb\Helper |
|
46 | + */ |
|
47 | + public static function getInstance($debug = false) |
|
48 | + { |
|
49 | + static $instance; |
|
50 | + if (null === $instance) { |
|
51 | + $instance = new static($debug); |
|
52 | + } |
|
53 | 53 | |
54 | - return $instance; |
|
55 | - } |
|
54 | + return $instance; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @param null|string $name |
|
59 | - * @param null|string $value |
|
60 | - * |
|
61 | - * @return mixed |
|
62 | - */ |
|
63 | - public function setConfig($name = null, $value = null) |
|
64 | - { |
|
65 | - if (null === $this->configs) { |
|
66 | - $this->initConfig(); |
|
67 | - } |
|
68 | - $this->configs[$name] = $value; |
|
69 | - $this->addLog("Setting config '{$name}' : " . $this->configs[$name]); |
|
57 | + /** |
|
58 | + * @param null|string $name |
|
59 | + * @param null|string $value |
|
60 | + * |
|
61 | + * @return mixed |
|
62 | + */ |
|
63 | + public function setConfig($name = null, $value = null) |
|
64 | + { |
|
65 | + if (null === $this->configs) { |
|
66 | + $this->initConfig(); |
|
67 | + } |
|
68 | + $this->configs[$name] = $value; |
|
69 | + $this->addLog("Setting config '{$name}' : " . $this->configs[$name]); |
|
70 | 70 | |
71 | - return $this->configs[$name]; |
|
72 | - } |
|
71 | + return $this->configs[$name]; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function getDirname() |
|
78 | - { |
|
79 | - return $this->dirname; |
|
80 | - } |
|
74 | + /** |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function getDirname() |
|
78 | + { |
|
79 | + return $this->dirname; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Get an Object Handler |
|
84 | - * |
|
85 | - * @param string $name name of handler to load |
|
86 | - * |
|
87 | - * @return bool|\XoopsObjectHandler|\XoopsPersistableObjectHandler |
|
88 | - */ |
|
89 | - public function getHandler($name) |
|
90 | - { |
|
91 | - $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
|
92 | - $class = '\\XoopsModules\\' . ucfirst(strtolower(basename(dirname(__DIR__)))) . '\\' . $name . 'Handler'; |
|
93 | - $ret = new $class($db); |
|
82 | + /** |
|
83 | + * Get an Object Handler |
|
84 | + * |
|
85 | + * @param string $name name of handler to load |
|
86 | + * |
|
87 | + * @return bool|\XoopsObjectHandler|\XoopsPersistableObjectHandler |
|
88 | + */ |
|
89 | + public function getHandler($name) |
|
90 | + { |
|
91 | + $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
|
92 | + $class = '\\XoopsModules\\' . ucfirst(strtolower(basename(dirname(__DIR__)))) . '\\' . $name . 'Handler'; |
|
93 | + $ret = new $class($db); |
|
94 | 94 | |
95 | - return $ret; |
|
96 | - } |
|
95 | + return $ret; |
|
96 | + } |
|
97 | 97 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | $this->initConfig(); |
67 | 67 | } |
68 | 68 | $this->configs[$name] = $value; |
69 | - $this->addLog("Setting config '{$name}' : " . $this->configs[$name]); |
|
69 | + $this->addLog("Setting config '{$name}' : ".$this->configs[$name]); |
|
70 | 70 | |
71 | 71 | return $this->configs[$name]; |
72 | 72 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | public function getHandler($name) |
90 | 90 | { |
91 | 91 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
92 | - $class = '\\XoopsModules\\' . ucfirst(strtolower(basename(dirname(__DIR__)))) . '\\' . $name . 'Handler'; |
|
92 | + $class = '\\XoopsModules\\'.ucfirst(strtolower(basename(dirname(__DIR__)))).'\\'.$name.'Handler'; |
|
93 | 93 | $ret = new $class($db); |
94 | 94 | |
95 | 95 | return $ret; |
@@ -22,570 +22,570 @@ |
||
22 | 22 | */ |
23 | 23 | class TopicHandler extends \XoopsPersistableObjectHandler |
24 | 24 | { |
25 | - /** |
|
26 | - * @param \XoopsDatabase $db |
|
27 | - */ |
|
28 | - public function __construct(\XoopsDatabase $db) |
|
29 | - { |
|
30 | - parent::__construct($db, 'newbb_topics', Topic::class, 'topic_id', 'topic_title'); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @param mixed $id |
|
35 | - * @param null|array $fields |
|
36 | - * @return mixed|null |
|
37 | - */ |
|
38 | - public function get($id = null, $fields = null) //get($id, $var = null) |
|
39 | - { |
|
40 | - $var = $fields; |
|
41 | - $ret = null; |
|
42 | - $tags = $var; |
|
43 | - if (!empty($var) && is_string($var)) { |
|
44 | - $tags = [$var]; |
|
45 | - } |
|
46 | - if (!$topicObject = parent::get($id, $tags)) { |
|
47 | - return $ret; |
|
48 | - } |
|
49 | - $ret = $topicObject; |
|
50 | - if (!empty($var) && is_string($var)) { |
|
51 | - $ret = @$topicObject->getVar($var); |
|
52 | - } |
|
53 | - |
|
54 | - return $ret; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param \XoopsObject $object |
|
59 | - * @param bool $force |
|
60 | - * @return mixed |
|
61 | - */ |
|
62 | - public function insert(\XoopsObject $object, $force = true) |
|
63 | - { |
|
64 | - if (!$object->getVar('topic_time')) { |
|
65 | - $object->setVar('topic_time', time()); |
|
66 | - } |
|
67 | - if (!parent::insert($object, $force) || !$object->getVar('approved')) { |
|
68 | - return $object->getVar('topic_id'); |
|
69 | - } |
|
70 | - |
|
71 | - $newbbConfig = newbbLoadConfig(); |
|
72 | - if (!empty($newbbConfig['do_tag']) |
|
73 | - && @require_once $GLOBALS['xoops']->path('modules/tag/include/functions.php')) { |
|
74 | - if ($tagHandler = tag_getTagHandler()) { |
|
75 | - $tagHandler->updateByItem($object->getVar('topic_tags', 'n'), $object->getVar('topic_id'), 'newbb'); |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - return $object->getVar('topic_id'); |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * @param $object |
|
84 | - * @param bool $force |
|
85 | - * @return bool |
|
86 | - */ |
|
87 | - public function approve($object, $force = false) |
|
88 | - { |
|
89 | - $topic_id = $object->getVar('topic_id'); |
|
90 | - if ($force) { |
|
91 | - $sql = 'UPDATE ' . $this->db->prefix('newbb_topics') . " SET approved = -1 WHERE topic_id = {$topic_id}"; |
|
92 | - } else { |
|
93 | - $sql = 'UPDATE ' . $this->db->prefix('newbb_topics') . " SET approved = 1 WHERE topic_id = {$topic_id}"; |
|
94 | - } |
|
95 | - if (!$result = $this->db->queryF($sql)) { |
|
96 | - //xoops_error($this->db->error()); |
|
97 | - return false; |
|
98 | - } |
|
99 | - $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
100 | - $postsObject = $postHandler->getAll(new \Criteria('topic_id', $topic_id)); |
|
101 | - foreach (array_keys($postsObject) as $post_id) { |
|
102 | - $postHandler->approve($postsObject[$post_id]); |
|
103 | - } |
|
104 | - unset($postsObject); |
|
105 | - $statsHandler = Newbb\Helper::getInstance()->getHandler('Stats'); |
|
106 | - $statsHandler->update($object->getVar('forum_id'), 'topic'); |
|
107 | - |
|
108 | - return true; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * get previous/next topic |
|
113 | - * |
|
114 | - * @param integer $topic_id current topic ID |
|
115 | - * @param integer $action |
|
116 | - * <ul> |
|
117 | - * <li> -1: previous </li> |
|
118 | - * <li> 0: current </li> |
|
119 | - * <li> 1: next </li> |
|
120 | - * </ul> |
|
121 | - * @param integer $forum_id the scope for moving |
|
122 | - * <ul> |
|
123 | - * <li> >0 : inside the forum </li> |
|
124 | - * <li> <= 0: global </li> |
|
125 | - * </ul> |
|
126 | - * @access public |
|
127 | - * @return mixed|null|\XoopsObject |
|
128 | - */ |
|
129 | - public function &getByMove($topic_id, $action, $forum_id = 0) |
|
130 | - { |
|
131 | - $topic = null; |
|
132 | - if (!empty($action)) { |
|
133 | - $sql = 'SELECT * FROM ' . $this->table . ' WHERE 1=1' . (($forum_id > 0) ? ' AND forum_id=' . (int)$forum_id : '') . ' AND topic_id ' . (($action > 0) ? '>' : '<') . (int)$topic_id . ' ORDER BY topic_id ' . (($action > 0) ? 'ASC' : 'DESC') . ' LIMIT 1'; |
|
134 | - if ($result = $this->db->query($sql)) { |
|
135 | - if ($row = $this->db->fetchArray($result)) { |
|
136 | - $topic = $this->create(false); |
|
137 | - $topic->assignVars($row); |
|
138 | - |
|
139 | - return $topic; |
|
140 | - } |
|
141 | - } |
|
142 | - } |
|
143 | - $topic = $this->get($topic_id); |
|
144 | - |
|
145 | - return $topic; |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * @param $post_id |
|
150 | - * @return null|\XoopsObject |
|
151 | - */ |
|
152 | - public function &getByPost($post_id) |
|
153 | - { |
|
154 | - $topic = null; |
|
155 | - $sql = 'SELECT t.* FROM ' . $this->db->prefix('newbb_topics') . ' t, ' . $this->db->prefix('newbb_posts') . ' p |
|
25 | + /** |
|
26 | + * @param \XoopsDatabase $db |
|
27 | + */ |
|
28 | + public function __construct(\XoopsDatabase $db) |
|
29 | + { |
|
30 | + parent::__construct($db, 'newbb_topics', Topic::class, 'topic_id', 'topic_title'); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @param mixed $id |
|
35 | + * @param null|array $fields |
|
36 | + * @return mixed|null |
|
37 | + */ |
|
38 | + public function get($id = null, $fields = null) //get($id, $var = null) |
|
39 | + { |
|
40 | + $var = $fields; |
|
41 | + $ret = null; |
|
42 | + $tags = $var; |
|
43 | + if (!empty($var) && is_string($var)) { |
|
44 | + $tags = [$var]; |
|
45 | + } |
|
46 | + if (!$topicObject = parent::get($id, $tags)) { |
|
47 | + return $ret; |
|
48 | + } |
|
49 | + $ret = $topicObject; |
|
50 | + if (!empty($var) && is_string($var)) { |
|
51 | + $ret = @$topicObject->getVar($var); |
|
52 | + } |
|
53 | + |
|
54 | + return $ret; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param \XoopsObject $object |
|
59 | + * @param bool $force |
|
60 | + * @return mixed |
|
61 | + */ |
|
62 | + public function insert(\XoopsObject $object, $force = true) |
|
63 | + { |
|
64 | + if (!$object->getVar('topic_time')) { |
|
65 | + $object->setVar('topic_time', time()); |
|
66 | + } |
|
67 | + if (!parent::insert($object, $force) || !$object->getVar('approved')) { |
|
68 | + return $object->getVar('topic_id'); |
|
69 | + } |
|
70 | + |
|
71 | + $newbbConfig = newbbLoadConfig(); |
|
72 | + if (!empty($newbbConfig['do_tag']) |
|
73 | + && @require_once $GLOBALS['xoops']->path('modules/tag/include/functions.php')) { |
|
74 | + if ($tagHandler = tag_getTagHandler()) { |
|
75 | + $tagHandler->updateByItem($object->getVar('topic_tags', 'n'), $object->getVar('topic_id'), 'newbb'); |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + return $object->getVar('topic_id'); |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * @param $object |
|
84 | + * @param bool $force |
|
85 | + * @return bool |
|
86 | + */ |
|
87 | + public function approve($object, $force = false) |
|
88 | + { |
|
89 | + $topic_id = $object->getVar('topic_id'); |
|
90 | + if ($force) { |
|
91 | + $sql = 'UPDATE ' . $this->db->prefix('newbb_topics') . " SET approved = -1 WHERE topic_id = {$topic_id}"; |
|
92 | + } else { |
|
93 | + $sql = 'UPDATE ' . $this->db->prefix('newbb_topics') . " SET approved = 1 WHERE topic_id = {$topic_id}"; |
|
94 | + } |
|
95 | + if (!$result = $this->db->queryF($sql)) { |
|
96 | + //xoops_error($this->db->error()); |
|
97 | + return false; |
|
98 | + } |
|
99 | + $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
100 | + $postsObject = $postHandler->getAll(new \Criteria('topic_id', $topic_id)); |
|
101 | + foreach (array_keys($postsObject) as $post_id) { |
|
102 | + $postHandler->approve($postsObject[$post_id]); |
|
103 | + } |
|
104 | + unset($postsObject); |
|
105 | + $statsHandler = Newbb\Helper::getInstance()->getHandler('Stats'); |
|
106 | + $statsHandler->update($object->getVar('forum_id'), 'topic'); |
|
107 | + |
|
108 | + return true; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * get previous/next topic |
|
113 | + * |
|
114 | + * @param integer $topic_id current topic ID |
|
115 | + * @param integer $action |
|
116 | + * <ul> |
|
117 | + * <li> -1: previous </li> |
|
118 | + * <li> 0: current </li> |
|
119 | + * <li> 1: next </li> |
|
120 | + * </ul> |
|
121 | + * @param integer $forum_id the scope for moving |
|
122 | + * <ul> |
|
123 | + * <li> >0 : inside the forum </li> |
|
124 | + * <li> <= 0: global </li> |
|
125 | + * </ul> |
|
126 | + * @access public |
|
127 | + * @return mixed|null|\XoopsObject |
|
128 | + */ |
|
129 | + public function &getByMove($topic_id, $action, $forum_id = 0) |
|
130 | + { |
|
131 | + $topic = null; |
|
132 | + if (!empty($action)) { |
|
133 | + $sql = 'SELECT * FROM ' . $this->table . ' WHERE 1=1' . (($forum_id > 0) ? ' AND forum_id=' . (int)$forum_id : '') . ' AND topic_id ' . (($action > 0) ? '>' : '<') . (int)$topic_id . ' ORDER BY topic_id ' . (($action > 0) ? 'ASC' : 'DESC') . ' LIMIT 1'; |
|
134 | + if ($result = $this->db->query($sql)) { |
|
135 | + if ($row = $this->db->fetchArray($result)) { |
|
136 | + $topic = $this->create(false); |
|
137 | + $topic->assignVars($row); |
|
138 | + |
|
139 | + return $topic; |
|
140 | + } |
|
141 | + } |
|
142 | + } |
|
143 | + $topic = $this->get($topic_id); |
|
144 | + |
|
145 | + return $topic; |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * @param $post_id |
|
150 | + * @return null|\XoopsObject |
|
151 | + */ |
|
152 | + public function &getByPost($post_id) |
|
153 | + { |
|
154 | + $topic = null; |
|
155 | + $sql = 'SELECT t.* FROM ' . $this->db->prefix('newbb_topics') . ' t, ' . $this->db->prefix('newbb_posts') . ' p |
|
156 | 156 | WHERE t.topic_id = p.topic_id AND p.post_id = ' . (int)$post_id; |
157 | - $result = $this->db->query($sql); |
|
158 | - if (!$result) { |
|
159 | - //xoops_error($this->db->error()); |
|
160 | - return $topic; |
|
161 | - } |
|
162 | - $row = $this->db->fetchArray($result); |
|
163 | - $topic = $this->create(false); |
|
164 | - $topic->assignVars($row); |
|
165 | - |
|
166 | - return $topic; |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * @param Topic $topic |
|
171 | - * @param string $type |
|
172 | - * @return mixed |
|
173 | - */ |
|
174 | - public function getPostCount(&$topic, $type = '') |
|
175 | - { |
|
176 | - switch ($type) { |
|
177 | - case 'pending': |
|
178 | - $approved = 0; |
|
179 | - break; |
|
180 | - case 'deleted': |
|
181 | - $approved = -1; |
|
182 | - break; |
|
183 | - default: |
|
184 | - $approved = 1; |
|
185 | - break; |
|
186 | - } |
|
187 | - $criteria = new \CriteriaCompo(new \Criteria('topic_id', $topic->getVar('topic_id'))); |
|
188 | - $criteria->add(new \Criteria('approved', $approved)); |
|
189 | - /** @var Newbb\PostHandler $postHandler */ |
|
190 | - $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
191 | - $count = $postHandler->getCount($criteria); |
|
192 | - |
|
193 | - return $count; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * @param $topic_id |
|
198 | - * @return null|Newbb\Post |
|
199 | - */ |
|
200 | - public function &getTopPost($topic_id) |
|
201 | - { |
|
202 | - $post = null; |
|
203 | - $sql = 'SELECT p.*, t.* FROM ' . $this->db->prefix('newbb_posts') . ' p, |
|
157 | + $result = $this->db->query($sql); |
|
158 | + if (!$result) { |
|
159 | + //xoops_error($this->db->error()); |
|
160 | + return $topic; |
|
161 | + } |
|
162 | + $row = $this->db->fetchArray($result); |
|
163 | + $topic = $this->create(false); |
|
164 | + $topic->assignVars($row); |
|
165 | + |
|
166 | + return $topic; |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * @param Topic $topic |
|
171 | + * @param string $type |
|
172 | + * @return mixed |
|
173 | + */ |
|
174 | + public function getPostCount(&$topic, $type = '') |
|
175 | + { |
|
176 | + switch ($type) { |
|
177 | + case 'pending': |
|
178 | + $approved = 0; |
|
179 | + break; |
|
180 | + case 'deleted': |
|
181 | + $approved = -1; |
|
182 | + break; |
|
183 | + default: |
|
184 | + $approved = 1; |
|
185 | + break; |
|
186 | + } |
|
187 | + $criteria = new \CriteriaCompo(new \Criteria('topic_id', $topic->getVar('topic_id'))); |
|
188 | + $criteria->add(new \Criteria('approved', $approved)); |
|
189 | + /** @var Newbb\PostHandler $postHandler */ |
|
190 | + $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
191 | + $count = $postHandler->getCount($criteria); |
|
192 | + |
|
193 | + return $count; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * @param $topic_id |
|
198 | + * @return null|Newbb\Post |
|
199 | + */ |
|
200 | + public function &getTopPost($topic_id) |
|
201 | + { |
|
202 | + $post = null; |
|
203 | + $sql = 'SELECT p.*, t.* FROM ' . $this->db->prefix('newbb_posts') . ' p, |
|
204 | 204 | ' . $this->db->prefix('newbb_posts_text') . ' t |
205 | 205 | WHERE |
206 | 206 | p.topic_id = ' . $topic_id . ' AND p.pid = 0 |
207 | 207 | AND t.post_id = p.post_id'; |
208 | 208 | |
209 | - $result = $this->db->query($sql); |
|
210 | - if (!$result) { |
|
211 | - //xoops_error($this->db->error()); |
|
212 | - return $post; |
|
213 | - } |
|
214 | - /** @var Newbb\PostHandler $postHandler */ |
|
215 | - $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
216 | - $myrow = $this->db->fetchArray($result); |
|
217 | - /** @var Newbb\Post $post */ |
|
218 | - $post = $postHandler->create(false); |
|
219 | - $post->assignVars($myrow); |
|
220 | - |
|
221 | - return $post; |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * @param $topic_id |
|
226 | - * @return bool |
|
227 | - */ |
|
228 | - public function getTopPostId($topic_id) |
|
229 | - { |
|
230 | - $sql = 'SELECT MIN(post_id) AS post_id FROM ' . $this->db->prefix('newbb_posts') . ' WHERE topic_id = ' . $topic_id . ' AND pid = 0'; |
|
231 | - $result = $this->db->query($sql); |
|
232 | - if (!$result) { |
|
233 | - //xoops_error($this->db->error()); |
|
234 | - return false; |
|
235 | - } |
|
236 | - list($post_id) = $this->db->fetchRow($result); |
|
237 | - |
|
238 | - return $post_id; |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * @param $topic |
|
243 | - * @param string $order |
|
244 | - * @param int $perpage |
|
245 | - * @param $start |
|
246 | - * @param int $post_id |
|
247 | - * @param string $type |
|
248 | - * @return array |
|
249 | - */ |
|
250 | - public function &getAllPosts(&$topic, $order = 'ASC', $perpage = 10, &$start, $post_id = 0, $type = '') |
|
251 | - { |
|
252 | - $ret = []; |
|
253 | - $perpage = ((int)$perpage > 0) ? (int)$perpage : (empty($GLOBALS['xoopsModuleConfig']['posts_per_page']) ? 10 : $GLOBALS['xoopsModuleConfig']['posts_per_page']); |
|
254 | - $start = (int)$start; |
|
255 | - switch ($type) { |
|
256 | - case 'pending': |
|
257 | - $approveCriteria = ' AND p.approved = 0'; |
|
258 | - break; |
|
259 | - case 'deleted': |
|
260 | - $approveCriteria = ' AND p.approved = -1'; |
|
261 | - break; |
|
262 | - default: |
|
263 | - $approveCriteria = ' AND p.approved = 1'; |
|
264 | - break; |
|
265 | - } |
|
266 | - |
|
267 | - if ($post_id) { |
|
268 | - if ('DESC' === $order) { |
|
269 | - $operator_for_position = '>'; |
|
270 | - } else { |
|
271 | - $order = 'ASC'; |
|
272 | - $operator_for_position = '<'; |
|
273 | - } |
|
274 | - //$approveCriteria = ' AND approved = 1'; // any others? |
|
275 | - $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('newbb_posts') . ' AS p WHERE p.topic_id=' . (int)$topic->getVar('topic_id') . $approveCriteria . " AND p.post_id $operator_for_position $post_id"; |
|
276 | - $result = $this->db->query($sql); |
|
277 | - if (!$result) { |
|
278 | - //xoops_error($this->db->error()); |
|
279 | - return $ret; |
|
280 | - } |
|
281 | - list($position) = $this->db->fetchRow($result); |
|
282 | - $start = (int)($position / $perpage) * $perpage; |
|
283 | - } |
|
284 | - |
|
285 | - $sql = 'SELECT p.*, t.* FROM ' . $this->db->prefix('newbb_posts') . ' p, ' . $this->db->prefix('newbb_posts_text') . ' t WHERE p.topic_id=' . $topic->getVar('topic_id') . ' AND p.post_id = t.post_id' . $approveCriteria . " ORDER BY p.post_id $order"; |
|
286 | - $result = $this->db->query($sql, $perpage, $start); |
|
287 | - if (!$result) { |
|
288 | - //xoops_error($this->db->error()); |
|
289 | - return $ret; |
|
290 | - } |
|
291 | - $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
292 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
293 | - $post = $postHandler->create(false); |
|
294 | - $post->assignVars($myrow); |
|
295 | - $ret[$myrow['post_id']] = $post; |
|
296 | - unset($post); |
|
297 | - } |
|
298 | - |
|
299 | - return $ret; |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * @param $postArray |
|
304 | - * @param int $pid |
|
305 | - * @return mixed |
|
306 | - */ |
|
307 | - public function &getPostTree(&$postArray, $pid = 0) |
|
308 | - { |
|
309 | - // require_once $GLOBALS['xoops']->path('modules/newbb/class/Tree.php'); |
|
310 | - $NewBBTree = new Newbb\Tree('newbb_posts'); |
|
311 | - $NewBBTree->setPrefix(' '); |
|
312 | - $NewBBTree->setPostArray($postArray); |
|
313 | - $NewBBTree->getPostTree($postsArray, $pid); |
|
314 | - |
|
315 | - return $postsArray; |
|
316 | - } |
|
317 | - |
|
318 | - /** |
|
319 | - * @param $topic |
|
320 | - * @param $postArray |
|
321 | - * @return mixed |
|
322 | - */ |
|
323 | - public function showTreeItem(&$topic, &$postArray) |
|
324 | - { |
|
325 | - global $viewtopic_users, $myts; |
|
326 | - |
|
327 | - $postArray['post_time'] = newbbFormatTimestamp($postArray['post_time']); |
|
328 | - |
|
329 | - if (!empty($postArray['icon'])) { |
|
330 | - $postArray['icon'] = '<img src="' . XOOPS_URL . '/images/subject/' . htmlspecialchars($postArray['icon'], ENT_QUOTES | ENT_HTML5) . '" alt="" />'; |
|
331 | - } else { |
|
332 | - $postArray['icon'] = '<a name="' . $postArray['post_id'] . '"><img src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" /></a>'; |
|
333 | - } |
|
334 | - |
|
335 | - $postArray['subject'] = '<a href="viewtopic.php?viewmode=thread&topic_id=' . $topic->getVar('topic_id') . '&forum=' . $postArray['forum_id'] . '&post_id=' . $postArray['post_id'] . '">' . $postArray['subject'] . '</a>'; |
|
336 | - |
|
337 | - $isActiveUser = false; |
|
338 | - if (isset($viewtopic_users[$postArray['uid']]['name'])) { |
|
339 | - $postArray['poster'] = $viewtopic_users[$postArray['uid']]['name']; |
|
340 | - if ($postArray['uid'] > 0) { |
|
341 | - $postArray['poster'] = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $postArray['uid'] . '">' . $viewtopic_users[$postArray['uid']]['name'] . '</a>'; |
|
342 | - } |
|
343 | - } else { |
|
344 | - $postArray['poster'] = empty($postArray['poster_name']) ? $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']) : $postArray['poster_name']; |
|
345 | - } |
|
346 | - |
|
347 | - return $postArray; |
|
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * @param $topic |
|
352 | - * @param bool $isApproved |
|
353 | - * @return array |
|
354 | - */ |
|
355 | - public function &getAllPosters(&$topic, $isApproved = true) |
|
356 | - { |
|
357 | - $sql = 'SELECT DISTINCT uid FROM ' . $this->db->prefix('newbb_posts') . ' WHERE topic_id=' . $topic->getVar('topic_id') . ' AND uid>0'; |
|
358 | - if ($isApproved) { |
|
359 | - $sql .= ' AND approved = 1'; |
|
360 | - } |
|
361 | - $result = $this->db->query($sql); |
|
362 | - if (!$result) { |
|
363 | - //xoops_error($this->db->error()); |
|
364 | - return []; |
|
365 | - } |
|
366 | - $ret = []; |
|
367 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
368 | - $ret[] = $myrow['uid']; |
|
369 | - } |
|
370 | - |
|
371 | - return $ret; |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * @param Topic|\XoopsObject $topic |
|
376 | - * @param bool $force |
|
377 | - * @return bool |
|
378 | - */ |
|
379 | - public function delete(\XoopsObject $topic, $force = true) |
|
380 | - { |
|
381 | - $topic_id = is_object($topic) ? $topic->getVar('topic_id') : (int)$topic; |
|
382 | - if (empty($topic_id)) { |
|
383 | - return false; |
|
384 | - } |
|
385 | - $postObject = $this->getTopPost($topic_id); |
|
386 | - /** @var Newbb\PostHandler $postHandler */ |
|
387 | - $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
388 | - $postHandler->delete($postObject, false, $force); |
|
389 | - |
|
390 | - $newbbConfig = newbbLoadConfig(); |
|
391 | - /** @var \XoopsModules\Tag\TagHandler $tagHandler */ |
|
392 | - if (!empty($newbbConfig['do_tag']) && $tagHandler = Tag\Helper::getInstance()->getHandler('Tag')) { //@xoops_getModuleHandler('tag', 'tag', true)) { |
|
393 | - $tagHandler->updateByItem([], $topic_id, 'newbb'); |
|
394 | - } |
|
395 | - |
|
396 | - return true; |
|
397 | - } |
|
398 | - |
|
399 | - // get permission |
|
400 | - // parameter: $type: 'post', 'view', 'reply', 'edit', 'delete', 'addpoll', 'vote', 'attach' |
|
401 | - // $gperm_names = "'forum_can_post', 'forum_can_view', 'forum_can_reply', 'forum_can_edit', 'forum_can_delete', 'forum_can_addpoll', 'forum_can_vote', 'forum_can_attach', 'forum_can_noapprove'"; |
|
402 | - /** |
|
403 | - * @param Newbb\Forum $forum |
|
404 | - * @param int $topic_locked |
|
405 | - * @param string $type |
|
406 | - * @return bool |
|
407 | - */ |
|
408 | - public function getPermission($forum, $topic_locked = 0, $type = 'view') |
|
409 | - { |
|
410 | - static $_cachedTopicPerms; |
|
411 | - require_once dirname(__DIR__) . '/include/functions.user.php'; |
|
412 | - if (newbbIsAdmin($forum)) { |
|
413 | - return true; |
|
414 | - } |
|
415 | - |
|
416 | - $forum_id = is_object($forum) ? $forum->getVar('forum_id') : (int)$forum; |
|
417 | - if ($forum_id < 1) { |
|
418 | - return false; |
|
419 | - } |
|
420 | - |
|
421 | - if ($topic_locked && 'view' !== $type) { |
|
422 | - $permission = false; |
|
423 | - } else { |
|
424 | - /** var Newbb\PermissionHandler $permHandler */ |
|
425 | - $permHandler = Newbb\Helper::getInstance()->getHandler('Permission'); |
|
426 | - $permission = $permHandler->getPermission('forum', $type, $forum_id); |
|
427 | - } |
|
428 | - |
|
429 | - return $permission; |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * clean orphan items from database |
|
434 | - * |
|
435 | - * @param string $table_link |
|
436 | - * @param string $field_link |
|
437 | - * @param string $field_object |
|
438 | - * @return bool true on success |
|
439 | - */ |
|
440 | - public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
|
441 | - { |
|
442 | - $this->deleteAll(new \Criteria('topic_time', 0), true, true); |
|
443 | - parent::cleanOrphan($this->db->prefix('newbb_forums'), 'forum_id'); |
|
444 | - parent::cleanOrphan($this->db->prefix('newbb_posts'), 'topic_id'); |
|
445 | - |
|
446 | - return true; |
|
447 | - } |
|
448 | - |
|
449 | - /** |
|
450 | - * clean expired objects from database |
|
451 | - * |
|
452 | - * @param int $expire time limit for expiration |
|
453 | - * @return bool true on success |
|
454 | - */ |
|
455 | - public function cleanExpires($expire = 0) |
|
456 | - { |
|
457 | - // irmtfan if 0 no cleanup look include/plugin.php |
|
458 | - if (!func_num_args()) { |
|
459 | - $newbbConfig = newbbLoadConfig(); |
|
460 | - $expire = isset($newbbConfig['pending_expire']) ? (int)$newbbConfig['pending_expire'] : 7; |
|
461 | - $expire = $expire * 24 * 3600; // days to seconds |
|
462 | - } |
|
463 | - if (empty($expire)) { |
|
464 | - return false; |
|
465 | - } |
|
466 | - $crit_expire = new \CriteriaCompo(new \Criteria('approved', 0, '<=')); |
|
467 | - $crit_expire->add(new \Criteria('topic_time', time() - (int)$expire, '<')); |
|
468 | - |
|
469 | - return $this->deleteAll($crit_expire, true/*, true*/); |
|
470 | - } |
|
471 | - |
|
472 | - // START irmtfan - rewrite topic synchronization function. add pid sync and remove hard-code db access |
|
473 | - |
|
474 | - /** |
|
475 | - * @param null $object |
|
476 | - * @param bool $force |
|
477 | - * @return bool |
|
478 | - */ |
|
479 | - public function synchronization($object = null, $force = true) |
|
480 | - { |
|
481 | - if (!is_object($object)) { |
|
482 | - $object = $this->get((int)$object); |
|
483 | - } |
|
484 | - if (!is_object($object) || !$object->getVar('topic_id')) { |
|
485 | - return false; |
|
486 | - } |
|
487 | - |
|
488 | - /** @var Newbb\PostHandler $postHandler */ |
|
489 | - $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
490 | - $criteria = new \CriteriaCompo(); |
|
491 | - $criteria->add(new \Criteria('topic_id', $object->getVar('topic_id')), 'AND'); |
|
492 | - $criteria->add(new \Criteria('approved', 1), 'AND'); |
|
493 | - $post_ids = $postHandler->getIds($criteria); |
|
494 | - if (empty($post_ids)) { |
|
495 | - return false; |
|
496 | - } |
|
497 | - $last_post = max($post_ids); |
|
498 | - $top_post = min($post_ids); |
|
499 | - $topic_replies = count($post_ids) - 1; |
|
500 | - if ($object->getVar('topic_last_post_id') != $last_post) { |
|
501 | - $object->setVar('topic_last_post_id', $last_post); |
|
502 | - } |
|
503 | - if ($object->getVar('topic_replies') != $topic_replies) { |
|
504 | - $object->setVar('topic_replies', $topic_replies); |
|
505 | - } |
|
506 | - $b1 = $this->insert($object, $force); |
|
507 | - $criteria->add(new \Criteria('post_id', $top_post, '<>'), 'AND'); |
|
508 | - $criteria->add(new \Criteria('pid', '(' . implode(', ', $post_ids) . ')', 'NOT IN'), 'AND'); |
|
509 | - $b2 = $postHandler->updateAll('pid', $top_post, $criteria, $force); |
|
510 | - $criteria = new \CriteriaCompo(); |
|
511 | - $criteria->add(new \Criteria('post_id', $top_post, '='), 'AND'); |
|
512 | - $b3 = $postHandler->updateAll('pid', 0, $criteria, $force); |
|
513 | - |
|
514 | - return ($b1 && $b2 && $b3); |
|
515 | - } |
|
516 | - // END irmtfan - rewrite topic synchronization function. add pid sync and remove hard-code db access |
|
517 | - // START irmtfan getActivePolls |
|
518 | - /** |
|
519 | - * get all active poll modules in the current xoops installtion. |
|
520 | - * @access public |
|
521 | - * @return array $pollDirs = array($dirname1=>$dirname1, $dirname2=>$dirname2, ...) dirnames of all active poll modules |
|
522 | - */ |
|
523 | - public function getActivePolls() |
|
524 | - { |
|
525 | - $pollDirs = []; |
|
526 | - $allDirs = xoops_getActiveModules(); |
|
527 | - foreach ($allDirs as $dirname) { |
|
528 | - // pollresults.php file is exist in all xoopspoll versions and umfrage versions |
|
529 | - if (file_exists($GLOBALS['xoops']->path('modules/' . $dirname . '/pollresults.php'))) { |
|
530 | - $pollDirs[$dirname] = $dirname; |
|
531 | - } |
|
532 | - } |
|
533 | - |
|
534 | - return $pollDirs; |
|
535 | - } |
|
536 | - // END irmtfan getActivePolls |
|
537 | - |
|
538 | - // START irmtfan findPollModule |
|
539 | - /** |
|
540 | - * find poll module that is in used in the current newbb installtion. |
|
541 | - * @access public |
|
542 | - * @param array $pollDirs dirnames of all active poll modules |
|
543 | - * @return bool|string $dir_def | true | false |
|
544 | - * $dir_def: dirname of poll module that is in used in the current newbb installtion. |
|
545 | - * true: no poll module is installed | newbb has no topic with poll | newbb has no topic |
|
546 | - * false: errors (see below xoops_errors) |
|
547 | - */ |
|
548 | - public function findPollModule(array $pollDirs = []) |
|
549 | - { |
|
550 | - $dir_def = ''; |
|
551 | - if (empty($pollDirs)) { |
|
552 | - $pollDirs = $this->getActivePolls(); |
|
553 | - } |
|
554 | - if (empty($pollDirs)) { |
|
555 | - return true; |
|
556 | - } |
|
557 | - // if only one active poll module still we need to check!!! |
|
558 | - //if(count($pollDirs) === 1) return end($pollDirs); |
|
559 | - $topicPollObjs = $this->getAll(new \Criteria('topic_haspoll', 1), ['topic_id', 'poll_id']); |
|
560 | - if (empty($topicPollObjs)) { |
|
561 | - return true; |
|
562 | - } // no poll or no topic!!! |
|
563 | - foreach ($topicPollObjs as $tObj) { |
|
564 | - $poll_idInMod = 0; |
|
565 | - foreach ($pollDirs as $dirname) { |
|
566 | - $pollObj = $tObj->getPoll($tObj->getVar('poll_id'), $dirname); |
|
567 | - if (is_object($pollObj) && ($pollObj->getVar('poll_id') == $tObj->getVar('poll_id'))) { |
|
568 | - ++$poll_idInMod; |
|
569 | - $dir_def = $dirname; |
|
570 | - } |
|
571 | - } |
|
572 | - // Only one poll module should has this poll_id |
|
573 | - // if 0 there is an error |
|
574 | - if (0 == $poll_idInMod) { |
|
575 | - xoops_error("Error: Cannot find poll module for poll_id='{$tObj->getVar('poll_id')}'"); |
|
576 | - |
|
577 | - return false; |
|
578 | - } |
|
579 | - // if 1 => $dir_def is correct |
|
580 | - if (1 == $poll_idInMod) { |
|
581 | - return $dir_def; |
|
582 | - } |
|
583 | - // if more than 1 continue |
|
584 | - } |
|
585 | - // if there is some topics but no module or more than one module have polls |
|
586 | - xoops_error("Error: Cannot find poll module that is in used in newbb!!! <br\><br\>You should select the correct poll module yourself in newbb > preferences > poll module setting."); |
|
587 | - |
|
588 | - return false; |
|
589 | - } |
|
590 | - // END irmtfan findPollModule |
|
209 | + $result = $this->db->query($sql); |
|
210 | + if (!$result) { |
|
211 | + //xoops_error($this->db->error()); |
|
212 | + return $post; |
|
213 | + } |
|
214 | + /** @var Newbb\PostHandler $postHandler */ |
|
215 | + $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
216 | + $myrow = $this->db->fetchArray($result); |
|
217 | + /** @var Newbb\Post $post */ |
|
218 | + $post = $postHandler->create(false); |
|
219 | + $post->assignVars($myrow); |
|
220 | + |
|
221 | + return $post; |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * @param $topic_id |
|
226 | + * @return bool |
|
227 | + */ |
|
228 | + public function getTopPostId($topic_id) |
|
229 | + { |
|
230 | + $sql = 'SELECT MIN(post_id) AS post_id FROM ' . $this->db->prefix('newbb_posts') . ' WHERE topic_id = ' . $topic_id . ' AND pid = 0'; |
|
231 | + $result = $this->db->query($sql); |
|
232 | + if (!$result) { |
|
233 | + //xoops_error($this->db->error()); |
|
234 | + return false; |
|
235 | + } |
|
236 | + list($post_id) = $this->db->fetchRow($result); |
|
237 | + |
|
238 | + return $post_id; |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * @param $topic |
|
243 | + * @param string $order |
|
244 | + * @param int $perpage |
|
245 | + * @param $start |
|
246 | + * @param int $post_id |
|
247 | + * @param string $type |
|
248 | + * @return array |
|
249 | + */ |
|
250 | + public function &getAllPosts(&$topic, $order = 'ASC', $perpage = 10, &$start, $post_id = 0, $type = '') |
|
251 | + { |
|
252 | + $ret = []; |
|
253 | + $perpage = ((int)$perpage > 0) ? (int)$perpage : (empty($GLOBALS['xoopsModuleConfig']['posts_per_page']) ? 10 : $GLOBALS['xoopsModuleConfig']['posts_per_page']); |
|
254 | + $start = (int)$start; |
|
255 | + switch ($type) { |
|
256 | + case 'pending': |
|
257 | + $approveCriteria = ' AND p.approved = 0'; |
|
258 | + break; |
|
259 | + case 'deleted': |
|
260 | + $approveCriteria = ' AND p.approved = -1'; |
|
261 | + break; |
|
262 | + default: |
|
263 | + $approveCriteria = ' AND p.approved = 1'; |
|
264 | + break; |
|
265 | + } |
|
266 | + |
|
267 | + if ($post_id) { |
|
268 | + if ('DESC' === $order) { |
|
269 | + $operator_for_position = '>'; |
|
270 | + } else { |
|
271 | + $order = 'ASC'; |
|
272 | + $operator_for_position = '<'; |
|
273 | + } |
|
274 | + //$approveCriteria = ' AND approved = 1'; // any others? |
|
275 | + $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('newbb_posts') . ' AS p WHERE p.topic_id=' . (int)$topic->getVar('topic_id') . $approveCriteria . " AND p.post_id $operator_for_position $post_id"; |
|
276 | + $result = $this->db->query($sql); |
|
277 | + if (!$result) { |
|
278 | + //xoops_error($this->db->error()); |
|
279 | + return $ret; |
|
280 | + } |
|
281 | + list($position) = $this->db->fetchRow($result); |
|
282 | + $start = (int)($position / $perpage) * $perpage; |
|
283 | + } |
|
284 | + |
|
285 | + $sql = 'SELECT p.*, t.* FROM ' . $this->db->prefix('newbb_posts') . ' p, ' . $this->db->prefix('newbb_posts_text') . ' t WHERE p.topic_id=' . $topic->getVar('topic_id') . ' AND p.post_id = t.post_id' . $approveCriteria . " ORDER BY p.post_id $order"; |
|
286 | + $result = $this->db->query($sql, $perpage, $start); |
|
287 | + if (!$result) { |
|
288 | + //xoops_error($this->db->error()); |
|
289 | + return $ret; |
|
290 | + } |
|
291 | + $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
292 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
293 | + $post = $postHandler->create(false); |
|
294 | + $post->assignVars($myrow); |
|
295 | + $ret[$myrow['post_id']] = $post; |
|
296 | + unset($post); |
|
297 | + } |
|
298 | + |
|
299 | + return $ret; |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * @param $postArray |
|
304 | + * @param int $pid |
|
305 | + * @return mixed |
|
306 | + */ |
|
307 | + public function &getPostTree(&$postArray, $pid = 0) |
|
308 | + { |
|
309 | + // require_once $GLOBALS['xoops']->path('modules/newbb/class/Tree.php'); |
|
310 | + $NewBBTree = new Newbb\Tree('newbb_posts'); |
|
311 | + $NewBBTree->setPrefix(' '); |
|
312 | + $NewBBTree->setPostArray($postArray); |
|
313 | + $NewBBTree->getPostTree($postsArray, $pid); |
|
314 | + |
|
315 | + return $postsArray; |
|
316 | + } |
|
317 | + |
|
318 | + /** |
|
319 | + * @param $topic |
|
320 | + * @param $postArray |
|
321 | + * @return mixed |
|
322 | + */ |
|
323 | + public function showTreeItem(&$topic, &$postArray) |
|
324 | + { |
|
325 | + global $viewtopic_users, $myts; |
|
326 | + |
|
327 | + $postArray['post_time'] = newbbFormatTimestamp($postArray['post_time']); |
|
328 | + |
|
329 | + if (!empty($postArray['icon'])) { |
|
330 | + $postArray['icon'] = '<img src="' . XOOPS_URL . '/images/subject/' . htmlspecialchars($postArray['icon'], ENT_QUOTES | ENT_HTML5) . '" alt="" />'; |
|
331 | + } else { |
|
332 | + $postArray['icon'] = '<a name="' . $postArray['post_id'] . '"><img src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" /></a>'; |
|
333 | + } |
|
334 | + |
|
335 | + $postArray['subject'] = '<a href="viewtopic.php?viewmode=thread&topic_id=' . $topic->getVar('topic_id') . '&forum=' . $postArray['forum_id'] . '&post_id=' . $postArray['post_id'] . '">' . $postArray['subject'] . '</a>'; |
|
336 | + |
|
337 | + $isActiveUser = false; |
|
338 | + if (isset($viewtopic_users[$postArray['uid']]['name'])) { |
|
339 | + $postArray['poster'] = $viewtopic_users[$postArray['uid']]['name']; |
|
340 | + if ($postArray['uid'] > 0) { |
|
341 | + $postArray['poster'] = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $postArray['uid'] . '">' . $viewtopic_users[$postArray['uid']]['name'] . '</a>'; |
|
342 | + } |
|
343 | + } else { |
|
344 | + $postArray['poster'] = empty($postArray['poster_name']) ? $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']) : $postArray['poster_name']; |
|
345 | + } |
|
346 | + |
|
347 | + return $postArray; |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * @param $topic |
|
352 | + * @param bool $isApproved |
|
353 | + * @return array |
|
354 | + */ |
|
355 | + public function &getAllPosters(&$topic, $isApproved = true) |
|
356 | + { |
|
357 | + $sql = 'SELECT DISTINCT uid FROM ' . $this->db->prefix('newbb_posts') . ' WHERE topic_id=' . $topic->getVar('topic_id') . ' AND uid>0'; |
|
358 | + if ($isApproved) { |
|
359 | + $sql .= ' AND approved = 1'; |
|
360 | + } |
|
361 | + $result = $this->db->query($sql); |
|
362 | + if (!$result) { |
|
363 | + //xoops_error($this->db->error()); |
|
364 | + return []; |
|
365 | + } |
|
366 | + $ret = []; |
|
367 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
368 | + $ret[] = $myrow['uid']; |
|
369 | + } |
|
370 | + |
|
371 | + return $ret; |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * @param Topic|\XoopsObject $topic |
|
376 | + * @param bool $force |
|
377 | + * @return bool |
|
378 | + */ |
|
379 | + public function delete(\XoopsObject $topic, $force = true) |
|
380 | + { |
|
381 | + $topic_id = is_object($topic) ? $topic->getVar('topic_id') : (int)$topic; |
|
382 | + if (empty($topic_id)) { |
|
383 | + return false; |
|
384 | + } |
|
385 | + $postObject = $this->getTopPost($topic_id); |
|
386 | + /** @var Newbb\PostHandler $postHandler */ |
|
387 | + $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
388 | + $postHandler->delete($postObject, false, $force); |
|
389 | + |
|
390 | + $newbbConfig = newbbLoadConfig(); |
|
391 | + /** @var \XoopsModules\Tag\TagHandler $tagHandler */ |
|
392 | + if (!empty($newbbConfig['do_tag']) && $tagHandler = Tag\Helper::getInstance()->getHandler('Tag')) { //@xoops_getModuleHandler('tag', 'tag', true)) { |
|
393 | + $tagHandler->updateByItem([], $topic_id, 'newbb'); |
|
394 | + } |
|
395 | + |
|
396 | + return true; |
|
397 | + } |
|
398 | + |
|
399 | + // get permission |
|
400 | + // parameter: $type: 'post', 'view', 'reply', 'edit', 'delete', 'addpoll', 'vote', 'attach' |
|
401 | + // $gperm_names = "'forum_can_post', 'forum_can_view', 'forum_can_reply', 'forum_can_edit', 'forum_can_delete', 'forum_can_addpoll', 'forum_can_vote', 'forum_can_attach', 'forum_can_noapprove'"; |
|
402 | + /** |
|
403 | + * @param Newbb\Forum $forum |
|
404 | + * @param int $topic_locked |
|
405 | + * @param string $type |
|
406 | + * @return bool |
|
407 | + */ |
|
408 | + public function getPermission($forum, $topic_locked = 0, $type = 'view') |
|
409 | + { |
|
410 | + static $_cachedTopicPerms; |
|
411 | + require_once dirname(__DIR__) . '/include/functions.user.php'; |
|
412 | + if (newbbIsAdmin($forum)) { |
|
413 | + return true; |
|
414 | + } |
|
415 | + |
|
416 | + $forum_id = is_object($forum) ? $forum->getVar('forum_id') : (int)$forum; |
|
417 | + if ($forum_id < 1) { |
|
418 | + return false; |
|
419 | + } |
|
420 | + |
|
421 | + if ($topic_locked && 'view' !== $type) { |
|
422 | + $permission = false; |
|
423 | + } else { |
|
424 | + /** var Newbb\PermissionHandler $permHandler */ |
|
425 | + $permHandler = Newbb\Helper::getInstance()->getHandler('Permission'); |
|
426 | + $permission = $permHandler->getPermission('forum', $type, $forum_id); |
|
427 | + } |
|
428 | + |
|
429 | + return $permission; |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * clean orphan items from database |
|
434 | + * |
|
435 | + * @param string $table_link |
|
436 | + * @param string $field_link |
|
437 | + * @param string $field_object |
|
438 | + * @return bool true on success |
|
439 | + */ |
|
440 | + public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
|
441 | + { |
|
442 | + $this->deleteAll(new \Criteria('topic_time', 0), true, true); |
|
443 | + parent::cleanOrphan($this->db->prefix('newbb_forums'), 'forum_id'); |
|
444 | + parent::cleanOrphan($this->db->prefix('newbb_posts'), 'topic_id'); |
|
445 | + |
|
446 | + return true; |
|
447 | + } |
|
448 | + |
|
449 | + /** |
|
450 | + * clean expired objects from database |
|
451 | + * |
|
452 | + * @param int $expire time limit for expiration |
|
453 | + * @return bool true on success |
|
454 | + */ |
|
455 | + public function cleanExpires($expire = 0) |
|
456 | + { |
|
457 | + // irmtfan if 0 no cleanup look include/plugin.php |
|
458 | + if (!func_num_args()) { |
|
459 | + $newbbConfig = newbbLoadConfig(); |
|
460 | + $expire = isset($newbbConfig['pending_expire']) ? (int)$newbbConfig['pending_expire'] : 7; |
|
461 | + $expire = $expire * 24 * 3600; // days to seconds |
|
462 | + } |
|
463 | + if (empty($expire)) { |
|
464 | + return false; |
|
465 | + } |
|
466 | + $crit_expire = new \CriteriaCompo(new \Criteria('approved', 0, '<=')); |
|
467 | + $crit_expire->add(new \Criteria('topic_time', time() - (int)$expire, '<')); |
|
468 | + |
|
469 | + return $this->deleteAll($crit_expire, true/*, true*/); |
|
470 | + } |
|
471 | + |
|
472 | + // START irmtfan - rewrite topic synchronization function. add pid sync and remove hard-code db access |
|
473 | + |
|
474 | + /** |
|
475 | + * @param null $object |
|
476 | + * @param bool $force |
|
477 | + * @return bool |
|
478 | + */ |
|
479 | + public function synchronization($object = null, $force = true) |
|
480 | + { |
|
481 | + if (!is_object($object)) { |
|
482 | + $object = $this->get((int)$object); |
|
483 | + } |
|
484 | + if (!is_object($object) || !$object->getVar('topic_id')) { |
|
485 | + return false; |
|
486 | + } |
|
487 | + |
|
488 | + /** @var Newbb\PostHandler $postHandler */ |
|
489 | + $postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
|
490 | + $criteria = new \CriteriaCompo(); |
|
491 | + $criteria->add(new \Criteria('topic_id', $object->getVar('topic_id')), 'AND'); |
|
492 | + $criteria->add(new \Criteria('approved', 1), 'AND'); |
|
493 | + $post_ids = $postHandler->getIds($criteria); |
|
494 | + if (empty($post_ids)) { |
|
495 | + return false; |
|
496 | + } |
|
497 | + $last_post = max($post_ids); |
|
498 | + $top_post = min($post_ids); |
|
499 | + $topic_replies = count($post_ids) - 1; |
|
500 | + if ($object->getVar('topic_last_post_id') != $last_post) { |
|
501 | + $object->setVar('topic_last_post_id', $last_post); |
|
502 | + } |
|
503 | + if ($object->getVar('topic_replies') != $topic_replies) { |
|
504 | + $object->setVar('topic_replies', $topic_replies); |
|
505 | + } |
|
506 | + $b1 = $this->insert($object, $force); |
|
507 | + $criteria->add(new \Criteria('post_id', $top_post, '<>'), 'AND'); |
|
508 | + $criteria->add(new \Criteria('pid', '(' . implode(', ', $post_ids) . ')', 'NOT IN'), 'AND'); |
|
509 | + $b2 = $postHandler->updateAll('pid', $top_post, $criteria, $force); |
|
510 | + $criteria = new \CriteriaCompo(); |
|
511 | + $criteria->add(new \Criteria('post_id', $top_post, '='), 'AND'); |
|
512 | + $b3 = $postHandler->updateAll('pid', 0, $criteria, $force); |
|
513 | + |
|
514 | + return ($b1 && $b2 && $b3); |
|
515 | + } |
|
516 | + // END irmtfan - rewrite topic synchronization function. add pid sync and remove hard-code db access |
|
517 | + // START irmtfan getActivePolls |
|
518 | + /** |
|
519 | + * get all active poll modules in the current xoops installtion. |
|
520 | + * @access public |
|
521 | + * @return array $pollDirs = array($dirname1=>$dirname1, $dirname2=>$dirname2, ...) dirnames of all active poll modules |
|
522 | + */ |
|
523 | + public function getActivePolls() |
|
524 | + { |
|
525 | + $pollDirs = []; |
|
526 | + $allDirs = xoops_getActiveModules(); |
|
527 | + foreach ($allDirs as $dirname) { |
|
528 | + // pollresults.php file is exist in all xoopspoll versions and umfrage versions |
|
529 | + if (file_exists($GLOBALS['xoops']->path('modules/' . $dirname . '/pollresults.php'))) { |
|
530 | + $pollDirs[$dirname] = $dirname; |
|
531 | + } |
|
532 | + } |
|
533 | + |
|
534 | + return $pollDirs; |
|
535 | + } |
|
536 | + // END irmtfan getActivePolls |
|
537 | + |
|
538 | + // START irmtfan findPollModule |
|
539 | + /** |
|
540 | + * find poll module that is in used in the current newbb installtion. |
|
541 | + * @access public |
|
542 | + * @param array $pollDirs dirnames of all active poll modules |
|
543 | + * @return bool|string $dir_def | true | false |
|
544 | + * $dir_def: dirname of poll module that is in used in the current newbb installtion. |
|
545 | + * true: no poll module is installed | newbb has no topic with poll | newbb has no topic |
|
546 | + * false: errors (see below xoops_errors) |
|
547 | + */ |
|
548 | + public function findPollModule(array $pollDirs = []) |
|
549 | + { |
|
550 | + $dir_def = ''; |
|
551 | + if (empty($pollDirs)) { |
|
552 | + $pollDirs = $this->getActivePolls(); |
|
553 | + } |
|
554 | + if (empty($pollDirs)) { |
|
555 | + return true; |
|
556 | + } |
|
557 | + // if only one active poll module still we need to check!!! |
|
558 | + //if(count($pollDirs) === 1) return end($pollDirs); |
|
559 | + $topicPollObjs = $this->getAll(new \Criteria('topic_haspoll', 1), ['topic_id', 'poll_id']); |
|
560 | + if (empty($topicPollObjs)) { |
|
561 | + return true; |
|
562 | + } // no poll or no topic!!! |
|
563 | + foreach ($topicPollObjs as $tObj) { |
|
564 | + $poll_idInMod = 0; |
|
565 | + foreach ($pollDirs as $dirname) { |
|
566 | + $pollObj = $tObj->getPoll($tObj->getVar('poll_id'), $dirname); |
|
567 | + if (is_object($pollObj) && ($pollObj->getVar('poll_id') == $tObj->getVar('poll_id'))) { |
|
568 | + ++$poll_idInMod; |
|
569 | + $dir_def = $dirname; |
|
570 | + } |
|
571 | + } |
|
572 | + // Only one poll module should has this poll_id |
|
573 | + // if 0 there is an error |
|
574 | + if (0 == $poll_idInMod) { |
|
575 | + xoops_error("Error: Cannot find poll module for poll_id='{$tObj->getVar('poll_id')}'"); |
|
576 | + |
|
577 | + return false; |
|
578 | + } |
|
579 | + // if 1 => $dir_def is correct |
|
580 | + if (1 == $poll_idInMod) { |
|
581 | + return $dir_def; |
|
582 | + } |
|
583 | + // if more than 1 continue |
|
584 | + } |
|
585 | + // if there is some topics but no module or more than one module have polls |
|
586 | + xoops_error("Error: Cannot find poll module that is in used in newbb!!! <br\><br\>You should select the correct poll module yourself in newbb > preferences > poll module setting."); |
|
587 | + |
|
588 | + return false; |
|
589 | + } |
|
590 | + // END irmtfan findPollModule |
|
591 | 591 | } |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | { |
89 | 89 | $topic_id = $object->getVar('topic_id'); |
90 | 90 | if ($force) { |
91 | - $sql = 'UPDATE ' . $this->db->prefix('newbb_topics') . " SET approved = -1 WHERE topic_id = {$topic_id}"; |
|
91 | + $sql = 'UPDATE '.$this->db->prefix('newbb_topics')." SET approved = -1 WHERE topic_id = {$topic_id}"; |
|
92 | 92 | } else { |
93 | - $sql = 'UPDATE ' . $this->db->prefix('newbb_topics') . " SET approved = 1 WHERE topic_id = {$topic_id}"; |
|
93 | + $sql = 'UPDATE '.$this->db->prefix('newbb_topics')." SET approved = 1 WHERE topic_id = {$topic_id}"; |
|
94 | 94 | } |
95 | 95 | if (!$result = $this->db->queryF($sql)) { |
96 | 96 | //xoops_error($this->db->error()); |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | { |
131 | 131 | $topic = null; |
132 | 132 | if (!empty($action)) { |
133 | - $sql = 'SELECT * FROM ' . $this->table . ' WHERE 1=1' . (($forum_id > 0) ? ' AND forum_id=' . (int)$forum_id : '') . ' AND topic_id ' . (($action > 0) ? '>' : '<') . (int)$topic_id . ' ORDER BY topic_id ' . (($action > 0) ? 'ASC' : 'DESC') . ' LIMIT 1'; |
|
133 | + $sql = 'SELECT * FROM '.$this->table.' WHERE 1=1'.(($forum_id > 0) ? ' AND forum_id='.(int)$forum_id : '').' AND topic_id '.(($action > 0) ? '>' : '<').(int)$topic_id.' ORDER BY topic_id '.(($action > 0) ? 'ASC' : 'DESC').' LIMIT 1'; |
|
134 | 134 | if ($result = $this->db->query($sql)) { |
135 | 135 | if ($row = $this->db->fetchArray($result)) { |
136 | 136 | $topic = $this->create(false); |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | public function &getByPost($post_id) |
153 | 153 | { |
154 | 154 | $topic = null; |
155 | - $sql = 'SELECT t.* FROM ' . $this->db->prefix('newbb_topics') . ' t, ' . $this->db->prefix('newbb_posts') . ' p |
|
155 | + $sql = 'SELECT t.* FROM '.$this->db->prefix('newbb_topics').' t, '.$this->db->prefix('newbb_posts').' p |
|
156 | 156 | WHERE t.topic_id = p.topic_id AND p.post_id = ' . (int)$post_id; |
157 | 157 | $result = $this->db->query($sql); |
158 | 158 | if (!$result) { |
@@ -200,10 +200,10 @@ discard block |
||
200 | 200 | public function &getTopPost($topic_id) |
201 | 201 | { |
202 | 202 | $post = null; |
203 | - $sql = 'SELECT p.*, t.* FROM ' . $this->db->prefix('newbb_posts') . ' p, |
|
204 | - ' . $this->db->prefix('newbb_posts_text') . ' t |
|
203 | + $sql = 'SELECT p.*, t.* FROM '.$this->db->prefix('newbb_posts').' p, |
|
204 | + ' . $this->db->prefix('newbb_posts_text').' t |
|
205 | 205 | WHERE |
206 | - p.topic_id = ' . $topic_id . ' AND p.pid = 0 |
|
206 | + p.topic_id = ' . $topic_id.' AND p.pid = 0 |
|
207 | 207 | AND t.post_id = p.post_id'; |
208 | 208 | |
209 | 209 | $result = $this->db->query($sql); |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | */ |
228 | 228 | public function getTopPostId($topic_id) |
229 | 229 | { |
230 | - $sql = 'SELECT MIN(post_id) AS post_id FROM ' . $this->db->prefix('newbb_posts') . ' WHERE topic_id = ' . $topic_id . ' AND pid = 0'; |
|
230 | + $sql = 'SELECT MIN(post_id) AS post_id FROM '.$this->db->prefix('newbb_posts').' WHERE topic_id = '.$topic_id.' AND pid = 0'; |
|
231 | 231 | $result = $this->db->query($sql); |
232 | 232 | if (!$result) { |
233 | 233 | //xoops_error($this->db->error()); |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | $operator_for_position = '<'; |
273 | 273 | } |
274 | 274 | //$approveCriteria = ' AND approved = 1'; // any others? |
275 | - $sql = 'SELECT COUNT(*) FROM ' . $this->db->prefix('newbb_posts') . ' AS p WHERE p.topic_id=' . (int)$topic->getVar('topic_id') . $approveCriteria . " AND p.post_id $operator_for_position $post_id"; |
|
275 | + $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('newbb_posts').' AS p WHERE p.topic_id='.(int)$topic->getVar('topic_id').$approveCriteria." AND p.post_id $operator_for_position $post_id"; |
|
276 | 276 | $result = $this->db->query($sql); |
277 | 277 | if (!$result) { |
278 | 278 | //xoops_error($this->db->error()); |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | $start = (int)($position / $perpage) * $perpage; |
283 | 283 | } |
284 | 284 | |
285 | - $sql = 'SELECT p.*, t.* FROM ' . $this->db->prefix('newbb_posts') . ' p, ' . $this->db->prefix('newbb_posts_text') . ' t WHERE p.topic_id=' . $topic->getVar('topic_id') . ' AND p.post_id = t.post_id' . $approveCriteria . " ORDER BY p.post_id $order"; |
|
285 | + $sql = 'SELECT p.*, t.* FROM '.$this->db->prefix('newbb_posts').' p, '.$this->db->prefix('newbb_posts_text').' t WHERE p.topic_id='.$topic->getVar('topic_id').' AND p.post_id = t.post_id'.$approveCriteria." ORDER BY p.post_id $order"; |
|
286 | 286 | $result = $this->db->query($sql, $perpage, $start); |
287 | 287 | if (!$result) { |
288 | 288 | //xoops_error($this->db->error()); |
@@ -327,18 +327,18 @@ discard block |
||
327 | 327 | $postArray['post_time'] = newbbFormatTimestamp($postArray['post_time']); |
328 | 328 | |
329 | 329 | if (!empty($postArray['icon'])) { |
330 | - $postArray['icon'] = '<img src="' . XOOPS_URL . '/images/subject/' . htmlspecialchars($postArray['icon'], ENT_QUOTES | ENT_HTML5) . '" alt="" />'; |
|
330 | + $postArray['icon'] = '<img src="'.XOOPS_URL.'/images/subject/'.htmlspecialchars($postArray['icon'], ENT_QUOTES | ENT_HTML5).'" alt="" />'; |
|
331 | 331 | } else { |
332 | - $postArray['icon'] = '<a name="' . $postArray['post_id'] . '"><img src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" /></a>'; |
|
332 | + $postArray['icon'] = '<a name="'.$postArray['post_id'].'"><img src="'.XOOPS_URL.'/images/icons/no_posticon.gif" alt="" /></a>'; |
|
333 | 333 | } |
334 | 334 | |
335 | - $postArray['subject'] = '<a href="viewtopic.php?viewmode=thread&topic_id=' . $topic->getVar('topic_id') . '&forum=' . $postArray['forum_id'] . '&post_id=' . $postArray['post_id'] . '">' . $postArray['subject'] . '</a>'; |
|
335 | + $postArray['subject'] = '<a href="viewtopic.php?viewmode=thread&topic_id='.$topic->getVar('topic_id').'&forum='.$postArray['forum_id'].'&post_id='.$postArray['post_id'].'">'.$postArray['subject'].'</a>'; |
|
336 | 336 | |
337 | 337 | $isActiveUser = false; |
338 | 338 | if (isset($viewtopic_users[$postArray['uid']]['name'])) { |
339 | 339 | $postArray['poster'] = $viewtopic_users[$postArray['uid']]['name']; |
340 | 340 | if ($postArray['uid'] > 0) { |
341 | - $postArray['poster'] = '<a href="' . XOOPS_URL . '/userinfo.php?uid=' . $postArray['uid'] . '">' . $viewtopic_users[$postArray['uid']]['name'] . '</a>'; |
|
341 | + $postArray['poster'] = '<a href="'.XOOPS_URL.'/userinfo.php?uid='.$postArray['uid'].'">'.$viewtopic_users[$postArray['uid']]['name'].'</a>'; |
|
342 | 342 | } |
343 | 343 | } else { |
344 | 344 | $postArray['poster'] = empty($postArray['poster_name']) ? $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']) : $postArray['poster_name']; |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | */ |
355 | 355 | public function &getAllPosters(&$topic, $isApproved = true) |
356 | 356 | { |
357 | - $sql = 'SELECT DISTINCT uid FROM ' . $this->db->prefix('newbb_posts') . ' WHERE topic_id=' . $topic->getVar('topic_id') . ' AND uid>0'; |
|
357 | + $sql = 'SELECT DISTINCT uid FROM '.$this->db->prefix('newbb_posts').' WHERE topic_id='.$topic->getVar('topic_id').' AND uid>0'; |
|
358 | 358 | if ($isApproved) { |
359 | 359 | $sql .= ' AND approved = 1'; |
360 | 360 | } |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | public function getPermission($forum, $topic_locked = 0, $type = 'view') |
409 | 409 | { |
410 | 410 | static $_cachedTopicPerms; |
411 | - require_once dirname(__DIR__) . '/include/functions.user.php'; |
|
411 | + require_once dirname(__DIR__).'/include/functions.user.php'; |
|
412 | 412 | if (newbbIsAdmin($forum)) { |
413 | 413 | return true; |
414 | 414 | } |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | } |
506 | 506 | $b1 = $this->insert($object, $force); |
507 | 507 | $criteria->add(new \Criteria('post_id', $top_post, '<>'), 'AND'); |
508 | - $criteria->add(new \Criteria('pid', '(' . implode(', ', $post_ids) . ')', 'NOT IN'), 'AND'); |
|
508 | + $criteria->add(new \Criteria('pid', '('.implode(', ', $post_ids).')', 'NOT IN'), 'AND'); |
|
509 | 509 | $b2 = $postHandler->updateAll('pid', $top_post, $criteria, $force); |
510 | 510 | $criteria = new \CriteriaCompo(); |
511 | 511 | $criteria->add(new \Criteria('post_id', $top_post, '='), 'AND'); |
@@ -526,7 +526,7 @@ discard block |
||
526 | 526 | $allDirs = xoops_getActiveModules(); |
527 | 527 | foreach ($allDirs as $dirname) { |
528 | 528 | // pollresults.php file is exist in all xoopspoll versions and umfrage versions |
529 | - if (file_exists($GLOBALS['xoops']->path('modules/' . $dirname . '/pollresults.php'))) { |
|
529 | + if (file_exists($GLOBALS['xoops']->path('modules/'.$dirname.'/pollresults.php'))) { |
|
530 | 530 | $pollDirs[$dirname] = $dirname; |
531 | 531 | } |
532 | 532 | } |
@@ -43,672 +43,672 @@ |
||
43 | 43 | */ |
44 | 44 | class Post extends \XoopsObject |
45 | 45 | { |
46 | - //class Post extends \XoopsObject { |
|
47 | - private $attachmentArray = []; |
|
48 | - |
|
49 | - /** |
|
50 | - * |
|
51 | - */ |
|
52 | - public function __construct() |
|
53 | - { |
|
54 | - parent::__construct(); |
|
55 | - |
|
56 | - $this->initVar('post_id', XOBJ_DTYPE_INT); |
|
57 | - $this->initVar('topic_id', XOBJ_DTYPE_INT, 0, true); |
|
58 | - $this->initVar('forum_id', XOBJ_DTYPE_INT, 0, true); |
|
59 | - $this->initVar('post_time', XOBJ_DTYPE_INT, 0, true); |
|
60 | - // $this->initVar('poster_ip', XOBJ_DTYPE_INT, 0); |
|
61 | - $this->initVar('poster_ip', XOBJ_DTYPE_TXTBOX, ''); |
|
62 | - $this->initVar('poster_name', XOBJ_DTYPE_TXTBOX, ''); |
|
63 | - $this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true); |
|
64 | - $this->initVar('pid', XOBJ_DTYPE_INT, 0); |
|
65 | - $this->initVar('dohtml', XOBJ_DTYPE_INT, 0); |
|
66 | - $this->initVar('dosmiley', XOBJ_DTYPE_INT, 1); |
|
67 | - $this->initVar('doxcode', XOBJ_DTYPE_INT, 1); |
|
68 | - $this->initVar('doimage', XOBJ_DTYPE_INT, 1); |
|
69 | - $this->initVar('dobr', XOBJ_DTYPE_INT, 1); |
|
70 | - $this->initVar('uid', XOBJ_DTYPE_INT, 1); |
|
71 | - $this->initVar('icon', XOBJ_DTYPE_TXTBOX, ''); |
|
72 | - $this->initVar('attachsig', XOBJ_DTYPE_INT, 0); |
|
73 | - $this->initVar('approved', XOBJ_DTYPE_INT, 1); |
|
74 | - $this->initVar('post_karma', XOBJ_DTYPE_INT, 0); |
|
75 | - $this->initVar('require_reply', XOBJ_DTYPE_INT, 0); |
|
76 | - $this->initVar('attachment', XOBJ_DTYPE_TXTAREA, ''); |
|
77 | - $this->initVar('post_text', XOBJ_DTYPE_TXTAREA, ''); |
|
78 | - $this->initVar('post_edit', XOBJ_DTYPE_TXTAREA, ''); |
|
79 | - } |
|
80 | - |
|
81 | - // //////////////////////////////////////////////////////////////////////////////////// |
|
82 | - // attachment functions TODO: there should be a file/attachment management class |
|
83 | - /** |
|
84 | - * @return array|mixed|null |
|
85 | - */ |
|
86 | - public function getAttachment() |
|
87 | - { |
|
88 | - if (count($this->attachmentArray)) { |
|
89 | - return $this->attachmentArray; |
|
90 | - } |
|
91 | - $attachment = $this->getVar('attachment'); |
|
92 | - if (empty($attachment)) { |
|
93 | - $this->attachmentArray = []; |
|
94 | - } else { |
|
95 | - $this->attachmentArray = @unserialize(base64_decode($attachment)); |
|
96 | - } |
|
97 | - |
|
98 | - return $this->attachmentArray; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @param $attachKey |
|
103 | - * @return bool |
|
104 | - */ |
|
105 | - public function incrementDownload($attachKey) |
|
106 | - { |
|
107 | - if (!$attachKey) { |
|
108 | - return false; |
|
109 | - } |
|
110 | - $this->attachmentArray[(string)$attachKey]['numDownload']++; |
|
111 | - |
|
112 | - return $this->attachmentArray[(string)$attachKey]['numDownload']; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * @return bool |
|
117 | - */ |
|
118 | - public function saveAttachment() |
|
119 | - { |
|
120 | - $attachmentSave = ''; |
|
121 | - if (is_array($this->attachmentArray) && count($this->attachmentArray) > 0) { |
|
122 | - $attachmentSave = base64_encode(serialize($this->attachmentArray)); |
|
123 | - } |
|
124 | - $this->setVar('attachment', $attachmentSave); |
|
125 | - $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('newbb_posts') . ' SET attachment=' . $GLOBALS['xoopsDB']->quoteString($attachmentSave) . ' WHERE post_id = ' . $this->getVar('post_id'); |
|
126 | - if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) { |
|
127 | - //xoops_error($GLOBALS['xoopsDB']->error()); |
|
128 | - return false; |
|
129 | - } |
|
130 | - |
|
131 | - return true; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * @param array|null $attachArray |
|
136 | - * @return bool |
|
137 | - */ |
|
138 | - public function deleteAttachment($attachArray = null) |
|
139 | - { |
|
140 | - $attachOld = $this->getAttachment(); |
|
141 | - if (!is_array($attachOld) || count($attachOld) < 1) { |
|
142 | - return true; |
|
143 | - } |
|
144 | - $this->attachmentArray = []; |
|
145 | - |
|
146 | - if (null === $attachArray) { |
|
147 | - $attachArray = array_keys($attachOld); |
|
148 | - } // to delete all! |
|
149 | - if (!is_array($attachArray)) { |
|
150 | - $attachArray = [$attachArray]; |
|
151 | - } |
|
152 | - |
|
153 | - foreach ($attachOld as $key => $attach) { |
|
154 | - if (in_array($key, $attachArray)) { |
|
155 | - @unlink($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $attach['name_saved'])); |
|
156 | - @unlink($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/thumbs/' . $attach['name_saved'])); // delete thumbnails |
|
157 | - continue; |
|
158 | - } |
|
159 | - $this->attachmentArray[$key] = $attach; |
|
160 | - } |
|
161 | - $attachmentSave = ''; |
|
162 | - if (is_array($this->attachmentArray) && count($this->attachmentArray) > 0) { |
|
163 | - $attachmentSave = base64_encode(serialize($this->attachmentArray)); |
|
164 | - } |
|
165 | - $this->setVar('attachment', $attachmentSave); |
|
166 | - |
|
167 | - return true; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * @param string $name_saved |
|
172 | - * @param string $nameDisplay |
|
173 | - * @param string $mimetype |
|
174 | - * @param int $numDownload |
|
175 | - * @return bool |
|
176 | - */ |
|
177 | - public function setAttachment($name_saved = '', $nameDisplay = '', $mimetype = '', $numDownload = 0) |
|
178 | - { |
|
179 | - static $counter = 0; |
|
180 | - $this->attachmentArray = $this->getAttachment(); |
|
181 | - if ($name_saved) { |
|
182 | - $key = (string)(time() + $counter++); |
|
183 | - $this->attachmentArray[$key] = [ |
|
184 | - 'name_saved' => $name_saved, |
|
185 | - 'nameDisplay' => empty($nameDisplay) ? $nameDisplay : $name_saved, |
|
186 | - 'mimetype' => $mimetype, |
|
187 | - 'numDownload' => empty($numDownload) ? (int)$numDownload : 0 |
|
188 | - ]; |
|
189 | - } |
|
190 | - $attachmentSave = null; |
|
191 | - if (is_array($this->attachmentArray)) { |
|
192 | - $attachmentSave = base64_encode(serialize($this->attachmentArray)); |
|
193 | - } |
|
194 | - $this->setVar('attachment', $attachmentSave); |
|
195 | - |
|
196 | - return true; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * TODO: refactor |
|
201 | - * @param bool $asSource |
|
202 | - * @return string |
|
203 | - */ |
|
204 | - public function displayAttachment($asSource = false) |
|
205 | - { |
|
206 | - global $xoopsModule; |
|
207 | - |
|
208 | - $post_attachment = ''; |
|
209 | - $attachments = $this->getAttachment(); |
|
210 | - if (is_array($attachments) && count($attachments) > 0) { |
|
211 | - $iconHandler = newbbGetIconHandler(); |
|
212 | - $mime_path = $iconHandler->getPath('mime'); |
|
213 | - require_once dirname(__DIR__) . '/include/functions.image.php'; |
|
214 | - $image_extensions = ['jpg', 'jpeg', 'gif', 'png', 'bmp']; // need improve !!! |
|
215 | - $post_attachment .= '<br><strong>' . _MD_NEWBB_ATTACHMENT . '</strong>:'; |
|
216 | - $post_attachment .= '<br><hr size="1" noshade="noshade" /><br>'; |
|
217 | - foreach ($attachments as $key => $att) { |
|
218 | - $file_extension = ltrim(strrchr($att['name_saved'], '.'), '.'); |
|
219 | - $filetype = $file_extension; |
|
220 | - if (file_exists($GLOBALS['xoops']->path($mime_path . '/' . $filetype . '.gif'))) { |
|
221 | - $icon_filetype = XOOPS_URL . '/' . $mime_path . '/' . $filetype . '.gif'; |
|
222 | - } else { |
|
223 | - $icon_filetype = XOOPS_URL . '/' . $mime_path . '/unknown.gif'; |
|
224 | - } |
|
225 | - $file_size = @filesize($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $att['name_saved'])); |
|
226 | - $file_size = number_format($file_size / 1024, 2) . ' KB'; |
|
227 | - if (in_array(strtolower($file_extension), $image_extensions) |
|
228 | - && $GLOBALS['xoopsModuleConfig']['media_allowed']) { |
|
229 | - $post_attachment .= '<br><img src="' . $icon_filetype . '" alt="' . $filetype . '" /><strong> ' . $att['nameDisplay'] . '</strong> <small>(' . $file_size . ')</small>'; |
|
230 | - $post_attachment .= '<br>' . newbbAttachmentImage($att['name_saved']); |
|
231 | - $isDisplayed = true; |
|
232 | - } else { |
|
233 | - if (empty($GLOBALS['xoopsModuleConfig']['show_userattach'])) { |
|
234 | - $post_attachment .= '<a href="' |
|
235 | - . XOOPS_URL |
|
236 | - . '/modules/' |
|
237 | - . $xoopsModule->getVar('dirname', 'n') |
|
238 | - . '/dl_attachment.php?attachid=' |
|
239 | - . $key |
|
240 | - . '&post_id=' |
|
241 | - . $this->getVar('post_id') |
|
242 | - . '"> <img src="' |
|
243 | - . $icon_filetype |
|
244 | - . '" alt="' |
|
245 | - . $filetype |
|
246 | - . '" /> ' |
|
247 | - . $att['nameDisplay'] |
|
248 | - . '</a> ' |
|
249 | - . _MD_NEWBB_FILESIZE |
|
250 | - . ': ' |
|
251 | - . $file_size |
|
252 | - . '; ' |
|
253 | - . _MD_NEWBB_HITS |
|
254 | - . ': ' |
|
255 | - . $att['numDownload']; |
|
256 | - } elseif ($GLOBALS['xoopsUser'] && $GLOBALS['xoopsUser']->uid() > 0 |
|
257 | - && $GLOBALS['xoopsUser']->isactive()) { |
|
258 | - $post_attachment .= '<a href="' |
|
259 | - . XOOPS_URL |
|
260 | - . '/modules/' |
|
261 | - . $xoopsModule->getVar('dirname', 'n') |
|
262 | - . '/dl_attachment.php?attachid=' |
|
263 | - . $key |
|
264 | - . '&post_id=' |
|
265 | - . $this->getVar('post_id') |
|
266 | - . '"> <img src="' |
|
267 | - . $icon_filetype |
|
268 | - . '" alt="' |
|
269 | - . $filetype |
|
270 | - . '" /> ' |
|
271 | - . $att['nameDisplay'] |
|
272 | - . '</a> ' |
|
273 | - . _MD_NEWBB_FILESIZE |
|
274 | - . ': ' |
|
275 | - . $file_size |
|
276 | - . '; ' |
|
277 | - . _MD_NEWBB_HITS |
|
278 | - . ': ' |
|
279 | - . $att['numDownload']; |
|
280 | - } else { |
|
281 | - $post_attachment .= _MD_NEWBB_SEENOTGUEST; |
|
282 | - } |
|
283 | - } |
|
284 | - $post_attachment .= '<br>'; |
|
285 | - } |
|
286 | - } |
|
287 | - |
|
288 | - return $post_attachment; |
|
289 | - } |
|
290 | - // attachment functions |
|
291 | - // //////////////////////////////////////////////////////////////////////////////////// |
|
292 | - |
|
293 | - /** |
|
294 | - * @param string $poster_name |
|
295 | - * @param string $post_editmsg |
|
296 | - * @return bool |
|
297 | - */ |
|
298 | - public function setPostEdit($poster_name = '', $post_editmsg = '') |
|
299 | - { |
|
300 | - $edit_user = ''; |
|
301 | - if (empty($GLOBALS['xoopsModuleConfig']['recordedit_timelimit']) |
|
302 | - || (time() - $this->getVar('post_time')) < $GLOBALS['xoopsModuleConfig']['recordedit_timelimit'] * 60 |
|
303 | - || $this->getVar('approved') < 1) { |
|
304 | - return true; |
|
305 | - } |
|
306 | - if (is_object($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser']->isActive()) { |
|
307 | - if ($GLOBALS['xoopsModuleConfig']['show_realname'] && $GLOBALS['xoopsUser']->getVar('name')) { |
|
308 | - $edit_user = $GLOBALS['xoopsUser']->getVar('name'); |
|
309 | - } else { |
|
310 | - $edit_user = $GLOBALS['xoopsUser']->getVar('uname'); |
|
311 | - } |
|
312 | - } |
|
313 | - $post_edit = []; |
|
314 | - $post_edit['edit_user'] = $edit_user; // (?) The proper way is to store uid instead of name. |
|
315 | - // However, to save queries when displaying, the current way is ok. |
|
316 | - $post_edit['edit_time'] = time(); |
|
317 | - $post_edit['edit_msg'] = $post_editmsg; |
|
318 | - |
|
319 | - $post_edits = $this->getVar('post_edit'); |
|
320 | - if (!empty($post_edits)) { |
|
321 | - $post_edits = unserialize(base64_decode($post_edits)); |
|
322 | - } |
|
323 | - if (!is_array($post_edits)) { |
|
324 | - $post_edits = []; |
|
325 | - } |
|
326 | - $post_edits[] = $post_edit; |
|
327 | - $post_edit = base64_encode(serialize($post_edits)); |
|
328 | - unset($post_edits); |
|
329 | - $this->setVar('post_edit', $post_edit); |
|
330 | - |
|
331 | - return true; |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * @return bool|string |
|
336 | - */ |
|
337 | - public function displayPostEdit() |
|
338 | - { |
|
339 | - global $myts; |
|
340 | - |
|
341 | - if (empty($GLOBALS['xoopsModuleConfig']['recordedit_timelimit'])) { |
|
342 | - return false; |
|
343 | - } |
|
344 | - |
|
345 | - $post_edit = ''; |
|
346 | - $post_edits = $this->getVar('post_edit'); |
|
347 | - if (!empty($post_edits)) { |
|
348 | - $post_edits = unserialize(base64_decode($post_edits)); |
|
349 | - } |
|
350 | - if (!isset($post_edits) || !is_array($post_edits)) { |
|
351 | - $post_edits = []; |
|
352 | - } |
|
353 | - if (is_array($post_edits) && count($post_edits) > 0) { |
|
354 | - foreach ($post_edits as $postedit) { |
|
355 | - $edit_time = (int)$postedit['edit_time']; |
|
356 | - $edit_user = $postedit['edit_user']; |
|
357 | - $edit_msg = !empty($postedit['edit_msg']) ? $postedit['edit_msg'] : ''; |
|
358 | - // Start irmtfan add option to do only the latest edit when do_latestedit=0 (Alfred) |
|
359 | - if (empty($GLOBALS['xoopsModuleConfig']['do_latestedit'])) { |
|
360 | - $post_edit = ''; |
|
361 | - } |
|
362 | - // End irmtfan add option to do only the latest edit when do_latestedit=0 (Alfred) |
|
363 | - // START hacked by irmtfan |
|
364 | - // display/save all edit records. |
|
365 | - $post_edit .= _MD_NEWBB_EDITEDBY . ' ' . $edit_user . ' ' . _MD_NEWBB_ON . ' ' . formatTimestamp($edit_time) . '<br>'; |
|
366 | - // if reason is not empty |
|
367 | - if ('' !== $edit_msg) { |
|
368 | - $post_edit .= _MD_NEWBB_EDITEDMSG . ' ' . $edit_msg . '<br>'; |
|
369 | - } |
|
370 | - // START hacked by irmtfan |
|
371 | - } |
|
372 | - } |
|
373 | - |
|
374 | - return $post_edit; |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * @return array |
|
379 | - */ |
|
380 | - public function &getPostBody() |
|
381 | - { |
|
382 | - global $viewtopic_users; |
|
383 | - $newbbConfig = newbbLoadConfig(); |
|
384 | - require_once dirname(__DIR__) . '/include/functions.user.php'; |
|
385 | - require_once dirname(__DIR__) . '/include/functions.render.php'; |
|
386 | - |
|
387 | - $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
388 | - /** @var KarmaHandler $karmaHandler */ |
|
389 | - $karmaHandler = Newbb\Helper::getInstance()->getHandler('Karma'); |
|
390 | - $user_karma = $karmaHandler->getUserKarma(); |
|
391 | - |
|
392 | - $post = []; |
|
393 | - $post['attachment'] = false; |
|
394 | - $post_text = newbbDisplayTarea($this->vars['post_text']['value'], $this->getVar('dohtml'), $this->getVar('dosmiley'), $this->getVar('doxcode'), $this->getVar('doimage'), $this->getVar('dobr')); |
|
395 | - if (newbbIsAdmin($this->getVar('forum_id')) || $this->checkIdentity()) { |
|
396 | - $post['text'] = $post_text . '<br>' . $this->displayAttachment(); |
|
397 | - } elseif ($newbbConfig['enable_karma'] && $this->getVar('post_karma') > $user_karma) { |
|
398 | - $post['text'] = sprintf(_MD_NEWBB_KARMA_REQUIREMENT, $user_karma, $this->getVar('post_karma')); |
|
399 | - } elseif ($newbbConfig['allow_require_reply'] && $this->getVar('require_reply') |
|
400 | - && (!$uid || !isset($viewtopic_users[$uid]))) { |
|
401 | - $post['text'] = _MD_NEWBB_REPLY_REQUIREMENT; |
|
402 | - } else { |
|
403 | - $post['text'] = $post_text . '<br>' . $this->displayAttachment(); |
|
404 | - } |
|
405 | - /** @var \XoopsMemberHandler $memberHandler */ |
|
406 | - $memberHandler = xoops_getHandler('member'); |
|
407 | - $eachposter = $memberHandler->getUser($this->getVar('uid')); |
|
408 | - if (is_object($eachposter) && $eachposter->isActive()) { |
|
409 | - if ($newbbConfig['show_realname'] && $eachposter->getVar('name')) { |
|
410 | - $post['author'] = $eachposter->getVar('name'); |
|
411 | - } else { |
|
412 | - $post['author'] = $eachposter->getVar('uname'); |
|
413 | - } |
|
414 | - unset($eachposter); |
|
415 | - } else { |
|
416 | - $post['author'] = $this->getVar('poster_name') ?: $GLOBALS['xoopsConfig']['anonymous']; |
|
417 | - } |
|
418 | - |
|
419 | - $post['subject'] = newbbHtmlspecialchars($this->vars['subject']['value']); |
|
420 | - |
|
421 | - $post['date'] = $this->getVar('post_time'); |
|
422 | - |
|
423 | - return $post; |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
427 | - * @return bool |
|
428 | - */ |
|
429 | - public function isTopic() |
|
430 | - { |
|
431 | - return !$this->getVar('pid'); |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * @param string $action_tag |
|
436 | - * @return bool |
|
437 | - */ |
|
438 | - public function checkTimelimit($action_tag = 'edit_timelimit') |
|
439 | - { |
|
440 | - $newbbConfig = newbbLoadConfig(); |
|
441 | - if (empty($newbbConfig['edit_timelimit'])) { |
|
442 | - return true; |
|
443 | - } |
|
444 | - |
|
445 | - return ($this->getVar('post_time') > time() - $newbbConfig[$action_tag] * 60); |
|
446 | - } |
|
447 | - |
|
448 | - /** |
|
449 | - * @param int $uid |
|
450 | - * @return bool |
|
451 | - */ |
|
452 | - public function checkIdentity($uid = -1) |
|
453 | - { |
|
454 | - $uid = ($uid > -1) ? $uid : (is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0); |
|
455 | - if ($this->getVar('uid') > 0) { |
|
456 | - $user_ok = ($uid == $this->getVar('uid')); |
|
457 | - } else { |
|
458 | - static $user_ip; |
|
459 | - if (!isset($user_ip)) { |
|
460 | - $user_ip = \Xmf\IPAddress::fromRequest()->asReadable(); |
|
461 | - } |
|
462 | - $user_ok = ($user_ip == $this->getVar('poster_ip')); |
|
463 | - } |
|
464 | - |
|
465 | - return $user_ok; |
|
466 | - } |
|
467 | - |
|
468 | - // TODO: cleaning up and merge with post hanldings in viewpost.php |
|
469 | - |
|
470 | - /** |
|
471 | - * @param $isAdmin |
|
472 | - * @return array |
|
473 | - */ |
|
474 | - public function showPost($isAdmin) |
|
475 | - { |
|
476 | - global $xoopsModule, $myts; |
|
477 | - global $forumUrl, $forumImage, $forumObject, $online, $viewmode; |
|
478 | - global $viewtopic_users, $viewtopic_posters, $topicObject, $user_karma; |
|
479 | - global $order, $start, $total_posts, $topic_status; |
|
480 | - static $post_NO = 0; |
|
481 | - static $name_anonymous; |
|
482 | - /** @var TopicHandler $topicHandler */ |
|
483 | - $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
484 | - if (!isset($name_anonymous)) { |
|
485 | - $name_anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']); |
|
486 | - } |
|
487 | - |
|
488 | - require_once dirname(__DIR__) . '/include/functions.time.php'; |
|
489 | - require_once dirname(__DIR__) . '/include/functions.render.php'; |
|
490 | - |
|
491 | - $post_id = $this->getVar('post_id'); |
|
492 | - $topic_id = $this->getVar('topic_id'); |
|
493 | - $forum_id = $this->getVar('forum_id'); |
|
494 | - |
|
495 | - $query_vars = ['status', 'order', 'start', 'mode', 'viewmode']; |
|
496 | - $query_array = []; |
|
497 | - $query_array['topic_id'] = "topic_id={$topic_id}"; |
|
498 | - foreach ($query_vars as $var) { |
|
499 | - if (Request::getString($var, '', 'GET')) { |
|
500 | - $query_array[$var] = "{$var}=" . Request::getString($var, '', 'GET'); |
|
501 | - } |
|
502 | - } |
|
503 | - $page_query = htmlspecialchars(implode('&', array_values($query_array)), ENT_QUOTES | ENT_HTML5); |
|
504 | - |
|
505 | - $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
506 | - |
|
507 | - ++$post_NO; |
|
508 | - if ('desc' === strtolower($order)) { |
|
509 | - $post_no = $total_posts - ($start + $post_NO) + 1; |
|
510 | - } else { |
|
511 | - $post_no = $start + $post_NO; |
|
512 | - } |
|
513 | - |
|
514 | - if ($isAdmin || $this->checkIdentity()) { |
|
515 | - $post_text = $this->getVar('post_text'); |
|
516 | - $post_attachment = $this->displayAttachment(); |
|
517 | - } elseif ($GLOBALS['xoopsModuleConfig']['enable_karma'] && $this->getVar('post_karma') > $user_karma) { |
|
518 | - $post_text = "<div class='karma'>" . sprintf(_MD_NEWBB_KARMA_REQUIREMENT, $user_karma, $this->getVar('post_karma')) . '</div>'; |
|
519 | - $post_attachment = ''; |
|
520 | - } elseif ($GLOBALS['xoopsModuleConfig']['allow_require_reply'] && $this->getVar('require_reply') |
|
521 | - && (!$uid || !in_array($uid, $viewtopic_posters))) { |
|
522 | - $post_text = "<div class='karma'>" . _MD_NEWBB_REPLY_REQUIREMENT . '</div>'; |
|
523 | - $post_attachment = ''; |
|
524 | - } else { |
|
525 | - $post_text = $this->getVar('post_text'); |
|
526 | - $post_attachment = $this->displayAttachment(); |
|
527 | - } |
|
528 | - |
|
529 | - // Hightlight search words |
|
530 | - $post_title = $this->getVar('subject'); |
|
531 | - if ($keywords = Request::getString('keywords', '', 'GET')) { |
|
532 | - //$keywords = $myts->htmlSpecialChars(trim(urldecode(Request::getString('keywords', '', 'GET')))); |
|
533 | - $post_text = Highlighter::apply($keywords, $post_text, '<mark>', '</mark>'); |
|
534 | - $post_title = Highlighter::apply($keywords, $post_title, '<mark>', '</mark>'); |
|
535 | - } |
|
536 | - |
|
537 | - if (isset($viewtopic_users[$this->getVar('uid')])) { |
|
538 | - $poster = $viewtopic_users[$this->getVar('uid')]; |
|
539 | - } else { |
|
540 | - $name = ($post_name = $this->getVar('poster_name')) ? $post_name : $name_anonymous; |
|
541 | - $poster = [ |
|
542 | - 'poster_uid' => 0, |
|
543 | - 'name' => $name, |
|
544 | - 'link' => $name |
|
545 | - ]; |
|
546 | - } |
|
547 | - |
|
548 | - if ($posticon = $this->getVar('icon')) { |
|
549 | - $post_image = '<a name="' . $post_id . '"><img src="' . XOOPS_URL . '/images/subject/' . $posticon . '" alt="" /></a>'; |
|
550 | - } else { |
|
551 | - $post_image = '<a name="' . $post_id . '"><img src="' . XOOPS_URL . '/images/icons/posticon.gif" alt="" /></a>'; |
|
552 | - } |
|
553 | - |
|
554 | - $thread_buttons = []; |
|
555 | - $mod_buttons = []; |
|
556 | - |
|
557 | - if ($isAdmin && ($GLOBALS['xoopsUser'] && $GLOBALS['xoopsUser']->getVar('uid') !== $this->getVar('uid')) |
|
558 | - && $this->getVar('uid') > 0) { |
|
559 | - $mod_buttons['bann']['image'] = newbbDisplayImage('p_bann', _MD_NEWBB_SUSPEND_MANAGEMENT); |
|
560 | - $mod_buttons['bann']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/moderate.php?forum=' . $forum_id . '&uid=' . $this->getVar('uid'); |
|
561 | - $mod_buttons['bann']['name'] = _MD_NEWBB_SUSPEND_MANAGEMENT; |
|
562 | - $thread_buttons['bann']['image'] = newbbDisplayImage('p_bann', _MD_NEWBB_SUSPEND_MANAGEMENT); |
|
563 | - $thread_buttons['bann']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/moderate.php?forum=' . $forum_id . '&uid=' . $this->getVar('uid'); |
|
564 | - $thread_buttons['bann']['name'] = _MD_NEWBB_SUSPEND_MANAGEMENT; |
|
565 | - } |
|
566 | - |
|
567 | - if ($GLOBALS['xoopsModuleConfig']['enable_permcheck']) { |
|
568 | - // /** @var TopicHandler $topicHandler */ |
|
569 | - // $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
570 | - $topic_status = $topicObject->getVar('topic_status'); |
|
571 | - if ($topicHandler->getPermission($forum_id, $topic_status, 'edit')) { |
|
572 | - $edit_ok = ($isAdmin || ($this->checkIdentity() && $this->checkTimelimit('edit_timelimit'))); |
|
573 | - |
|
574 | - if ($edit_ok) { |
|
575 | - $thread_buttons['edit']['image'] = newbbDisplayImage('p_edit', _EDIT); |
|
576 | - $thread_buttons['edit']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}"; |
|
577 | - $thread_buttons['edit']['name'] = _EDIT; |
|
578 | - $mod_buttons['edit']['image'] = newbbDisplayImage('p_edit', _EDIT); |
|
579 | - $mod_buttons['edit']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}"; |
|
580 | - $mod_buttons['edit']['name'] = _EDIT; |
|
581 | - } |
|
582 | - } |
|
583 | - |
|
584 | - if ($topicHandler->getPermission($forum_id, $topic_status, 'delete')) { |
|
585 | - $delete_ok = ($isAdmin || ($this->checkIdentity() && $this->checkTimelimit('delete_timelimit'))); |
|
586 | - |
|
587 | - if ($delete_ok) { |
|
588 | - $thread_buttons['delete']['image'] = newbbDisplayImage('p_delete', _DELETE); |
|
589 | - $thread_buttons['delete']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}"; |
|
590 | - $thread_buttons['delete']['name'] = _DELETE; |
|
591 | - $mod_buttons['delete']['image'] = newbbDisplayImage('p_delete', _DELETE); |
|
592 | - $mod_buttons['delete']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}"; |
|
593 | - $mod_buttons['delete']['name'] = _DELETE; |
|
594 | - } |
|
595 | - } |
|
596 | - if ($topicHandler->getPermission($forum_id, $topic_status, 'reply')) { |
|
597 | - $thread_buttons['reply']['image'] = newbbDisplayImage('p_reply', _MD_NEWBB_REPLY); |
|
598 | - $thread_buttons['reply']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}"; |
|
599 | - $thread_buttons['reply']['name'] = _MD_NEWBB_REPLY; |
|
600 | - |
|
601 | - $thread_buttons['quote']['image'] = newbbDisplayImage('p_quote', _MD_NEWBB_QUOTE); |
|
602 | - $thread_buttons['quote']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}&quotedac=1"; |
|
603 | - $thread_buttons['quote']['name'] = _MD_NEWBB_QUOTE; |
|
604 | - } |
|
605 | - } else { |
|
606 | - $mod_buttons['edit']['image'] = newbbDisplayImage('p_edit', _EDIT); |
|
607 | - $mod_buttons['edit']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}"; |
|
608 | - $mod_buttons['edit']['name'] = _EDIT; |
|
609 | - |
|
610 | - $mod_buttons['delete']['image'] = newbbDisplayImage('p_delete', _DELETE); |
|
611 | - $mod_buttons['delete']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}"; |
|
612 | - $mod_buttons['delete']['name'] = _DELETE; |
|
613 | - |
|
614 | - $thread_buttons['reply']['image'] = newbbDisplayImage('p_reply', _MD_NEWBB_REPLY); |
|
615 | - $thread_buttons['reply']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}"; |
|
616 | - $thread_buttons['reply']['name'] = _MD_NEWBB_REPLY; |
|
617 | - } |
|
618 | - |
|
619 | - if (!$isAdmin && $GLOBALS['xoopsModuleConfig']['reportmod_enabled']) { |
|
620 | - $thread_buttons['report']['image'] = newbbDisplayImage('p_report', _MD_NEWBB_REPORT); |
|
621 | - $thread_buttons['report']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/report.php?{$page_query}"; |
|
622 | - $thread_buttons['report']['name'] = _MD_NEWBB_REPORT; |
|
623 | - } |
|
624 | - |
|
625 | - $thread_action = []; |
|
626 | - // irmtfan add pdf permission |
|
627 | - if (file_exists(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php') |
|
628 | - && $topicHandler->getPermission($forum_id, $topic_status, 'pdf')) { |
|
629 | - $thread_action['pdf']['image'] = newbbDisplayImage('pdf', _MD_NEWBB_PDF); |
|
630 | - $thread_action['pdf']['link'] = XOOPS_URL . '/modules/newbb/makepdf.php?type=post&pageid=0'; |
|
631 | - $thread_action['pdf']['name'] = _MD_NEWBB_PDF; |
|
632 | - $thread_action['pdf']['target'] = '_blank'; |
|
633 | - } |
|
634 | - // irmtfan add print permission |
|
635 | - if ($topicHandler->getPermission($forum_id, $topic_status, 'print')) { |
|
636 | - $thread_action['print']['image'] = newbbDisplayImage('printer', _MD_NEWBB_PRINT); |
|
637 | - $thread_action['print']['link'] = XOOPS_URL . '/modules/newbb/print.php?form=2&forum=' . $forum_id . '&topic_id=' . $topic_id; |
|
638 | - $thread_action['print']['name'] = _MD_NEWBB_PRINT; |
|
639 | - $thread_action['print']['target'] = '_blank'; |
|
640 | - } |
|
641 | - |
|
642 | - if ($GLOBALS['xoopsModuleConfig']['show_sociallinks']) { |
|
643 | - $full_title = $this->getVar('subject'); |
|
644 | - $clean_title = preg_replace('/[^A-Za-z0-9-]+/', '+', $this->getVar('subject')); |
|
645 | - $full_link = XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $post_id; |
|
646 | - |
|
647 | - $thread_action['social_twitter']['image'] = newbbDisplayImage('twitter', _MD_NEWBB_SHARE_TWITTER); |
|
648 | - $thread_action['social_twitter']['link'] = 'http://twitter.com/share?text=' . $clean_title . '&url=' . $full_link; |
|
649 | - $thread_action['social_twitter']['name'] = _MD_NEWBB_SHARE_TWITTER; |
|
650 | - $thread_action['social_twitter']['target'] = '_blank'; |
|
651 | - |
|
652 | - $thread_action['social_facebook']['image'] = newbbDisplayImage('facebook', _MD_NEWBB_SHARE_FACEBOOK); |
|
653 | - $thread_action['social_facebook']['link'] = 'http://www.facebook.com/sharer.php?u=' . $full_link; |
|
654 | - $thread_action['social_facebook']['name'] = _MD_NEWBB_SHARE_FACEBOOK; |
|
655 | - $thread_action['social_facebook']['target'] = '_blank'; |
|
656 | - |
|
657 | - $thread_action['social_gplus']['image'] = newbbDisplayImage('googleplus', _MD_NEWBB_SHARE_GOOGLEPLUS); |
|
658 | - $thread_action['social_gplus']['link'] = 'https://plusone.google.com/_/+1/confirm?hl=en&url=' . $full_link; |
|
659 | - $thread_action['social_gplus']['name'] = _MD_NEWBB_SHARE_GOOGLEPLUS; |
|
660 | - $thread_action['social_gplus']['target'] = '_blank'; |
|
661 | - |
|
662 | - $thread_action['social_linkedin']['image'] = newbbDisplayImage('linkedin', _MD_NEWBB_SHARE_LINKEDIN); |
|
663 | - $thread_action['social_linkedin']['link'] = 'http://www.linkedin.com/shareArticle?mini=true&title=' . $full_title . '&url=' . $full_link; |
|
664 | - $thread_action['social_linkedin']['name'] = _MD_NEWBB_SHARE_LINKEDIN; |
|
665 | - $thread_action['social_linkedin']['target'] = '_blank'; |
|
666 | - |
|
667 | - $thread_action['social_delicious']['image'] = newbbDisplayImage('delicious', _MD_NEWBB_SHARE_DELICIOUS); |
|
668 | - $thread_action['social_delicious']['link'] = 'http://del.icio.us/post?title=' . $full_title . '&url=' . $full_link; |
|
669 | - $thread_action['social_delicious']['name'] = _MD_NEWBB_SHARE_DELICIOUS; |
|
670 | - $thread_action['social_delicious']['target'] = '_blank'; |
|
671 | - |
|
672 | - $thread_action['social_digg']['image'] = newbbDisplayImage('digg', _MD_NEWBB_SHARE_DIGG); |
|
673 | - $thread_action['social_digg']['link'] = 'http://digg.com/submit?phase=2&title=' . $full_title . '&url=' . $full_link; |
|
674 | - $thread_action['social_digg']['name'] = _MD_NEWBB_SHARE_DIGG; |
|
675 | - $thread_action['social_digg']['target'] = '_blank'; |
|
676 | - |
|
677 | - $thread_action['social_reddit']['image'] = newbbDisplayImage('reddit', _MD_NEWBB_SHARE_REDDIT); |
|
678 | - $thread_action['social_reddit']['link'] = 'http://reddit.com/submit?title=' . $full_title . '&url=' . $full_link; |
|
679 | - $thread_action['social_reddit']['name'] = _MD_NEWBB_SHARE_REDDIT; |
|
680 | - $thread_action['social_reddit']['target'] = '_blank'; |
|
681 | - |
|
682 | - $thread_action['social_wong']['image'] = newbbDisplayImage('wong', _MD_NEWBB_SHARE_MRWONG); |
|
683 | - $thread_action['social_wong']['link'] = 'http://www.mister-wong.de/index.php?action=addurl&bm_url=' . $full_link; |
|
684 | - $thread_action['social_wong']['name'] = _MD_NEWBB_SHARE_MRWONG; |
|
685 | - $thread_action['social_wong']['target'] = '_blank'; |
|
686 | - } |
|
687 | - |
|
688 | - $post = [ |
|
689 | - 'post_id' => $post_id, |
|
690 | - 'post_parent_id' => $this->getVar('pid'), |
|
691 | - 'post_date' => newbbFormatTimestamp($this->getVar('post_time')), |
|
692 | - 'post_image' => $post_image, |
|
693 | - 'post_title' => $post_title, |
|
694 | - // irmtfan $post_title to add highlight keywords |
|
695 | - 'post_text' => $post_text, |
|
696 | - 'post_attachment' => $post_attachment, |
|
697 | - 'post_edit' => $this->displayPostEdit(), |
|
698 | - 'post_no' => $post_no, |
|
699 | - 'post_signature' => $this->getVar('attachsig') ? @$poster['signature'] : '', |
|
700 | - // 'poster_ip' => ($isAdmin && $GLOBALS['xoopsModuleConfig']['show_ip']) ? long2ip($this->getVar('poster_ip')) : '', |
|
701 | - 'poster_ip' => ($isAdmin |
|
702 | - && $GLOBALS['xoopsModuleConfig']['show_ip']) ? $this->getVar('poster_ip') : '', |
|
703 | - 'thread_action' => $thread_action, |
|
704 | - 'thread_buttons' => $thread_buttons, |
|
705 | - 'mod_buttons' => $mod_buttons, |
|
706 | - 'poster' => $poster, |
|
707 | - 'post_permalink' => '<a href="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?post_id=' . $post_id . '"></a>' |
|
708 | - ]; |
|
709 | - |
|
710 | - unset($thread_buttons, $mod_buttons, $eachposter); |
|
711 | - |
|
712 | - return $post; |
|
713 | - } |
|
46 | + //class Post extends \XoopsObject { |
|
47 | + private $attachmentArray = []; |
|
48 | + |
|
49 | + /** |
|
50 | + * |
|
51 | + */ |
|
52 | + public function __construct() |
|
53 | + { |
|
54 | + parent::__construct(); |
|
55 | + |
|
56 | + $this->initVar('post_id', XOBJ_DTYPE_INT); |
|
57 | + $this->initVar('topic_id', XOBJ_DTYPE_INT, 0, true); |
|
58 | + $this->initVar('forum_id', XOBJ_DTYPE_INT, 0, true); |
|
59 | + $this->initVar('post_time', XOBJ_DTYPE_INT, 0, true); |
|
60 | + // $this->initVar('poster_ip', XOBJ_DTYPE_INT, 0); |
|
61 | + $this->initVar('poster_ip', XOBJ_DTYPE_TXTBOX, ''); |
|
62 | + $this->initVar('poster_name', XOBJ_DTYPE_TXTBOX, ''); |
|
63 | + $this->initVar('subject', XOBJ_DTYPE_TXTBOX, '', true); |
|
64 | + $this->initVar('pid', XOBJ_DTYPE_INT, 0); |
|
65 | + $this->initVar('dohtml', XOBJ_DTYPE_INT, 0); |
|
66 | + $this->initVar('dosmiley', XOBJ_DTYPE_INT, 1); |
|
67 | + $this->initVar('doxcode', XOBJ_DTYPE_INT, 1); |
|
68 | + $this->initVar('doimage', XOBJ_DTYPE_INT, 1); |
|
69 | + $this->initVar('dobr', XOBJ_DTYPE_INT, 1); |
|
70 | + $this->initVar('uid', XOBJ_DTYPE_INT, 1); |
|
71 | + $this->initVar('icon', XOBJ_DTYPE_TXTBOX, ''); |
|
72 | + $this->initVar('attachsig', XOBJ_DTYPE_INT, 0); |
|
73 | + $this->initVar('approved', XOBJ_DTYPE_INT, 1); |
|
74 | + $this->initVar('post_karma', XOBJ_DTYPE_INT, 0); |
|
75 | + $this->initVar('require_reply', XOBJ_DTYPE_INT, 0); |
|
76 | + $this->initVar('attachment', XOBJ_DTYPE_TXTAREA, ''); |
|
77 | + $this->initVar('post_text', XOBJ_DTYPE_TXTAREA, ''); |
|
78 | + $this->initVar('post_edit', XOBJ_DTYPE_TXTAREA, ''); |
|
79 | + } |
|
80 | + |
|
81 | + // //////////////////////////////////////////////////////////////////////////////////// |
|
82 | + // attachment functions TODO: there should be a file/attachment management class |
|
83 | + /** |
|
84 | + * @return array|mixed|null |
|
85 | + */ |
|
86 | + public function getAttachment() |
|
87 | + { |
|
88 | + if (count($this->attachmentArray)) { |
|
89 | + return $this->attachmentArray; |
|
90 | + } |
|
91 | + $attachment = $this->getVar('attachment'); |
|
92 | + if (empty($attachment)) { |
|
93 | + $this->attachmentArray = []; |
|
94 | + } else { |
|
95 | + $this->attachmentArray = @unserialize(base64_decode($attachment)); |
|
96 | + } |
|
97 | + |
|
98 | + return $this->attachmentArray; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @param $attachKey |
|
103 | + * @return bool |
|
104 | + */ |
|
105 | + public function incrementDownload($attachKey) |
|
106 | + { |
|
107 | + if (!$attachKey) { |
|
108 | + return false; |
|
109 | + } |
|
110 | + $this->attachmentArray[(string)$attachKey]['numDownload']++; |
|
111 | + |
|
112 | + return $this->attachmentArray[(string)$attachKey]['numDownload']; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * @return bool |
|
117 | + */ |
|
118 | + public function saveAttachment() |
|
119 | + { |
|
120 | + $attachmentSave = ''; |
|
121 | + if (is_array($this->attachmentArray) && count($this->attachmentArray) > 0) { |
|
122 | + $attachmentSave = base64_encode(serialize($this->attachmentArray)); |
|
123 | + } |
|
124 | + $this->setVar('attachment', $attachmentSave); |
|
125 | + $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('newbb_posts') . ' SET attachment=' . $GLOBALS['xoopsDB']->quoteString($attachmentSave) . ' WHERE post_id = ' . $this->getVar('post_id'); |
|
126 | + if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) { |
|
127 | + //xoops_error($GLOBALS['xoopsDB']->error()); |
|
128 | + return false; |
|
129 | + } |
|
130 | + |
|
131 | + return true; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * @param array|null $attachArray |
|
136 | + * @return bool |
|
137 | + */ |
|
138 | + public function deleteAttachment($attachArray = null) |
|
139 | + { |
|
140 | + $attachOld = $this->getAttachment(); |
|
141 | + if (!is_array($attachOld) || count($attachOld) < 1) { |
|
142 | + return true; |
|
143 | + } |
|
144 | + $this->attachmentArray = []; |
|
145 | + |
|
146 | + if (null === $attachArray) { |
|
147 | + $attachArray = array_keys($attachOld); |
|
148 | + } // to delete all! |
|
149 | + if (!is_array($attachArray)) { |
|
150 | + $attachArray = [$attachArray]; |
|
151 | + } |
|
152 | + |
|
153 | + foreach ($attachOld as $key => $attach) { |
|
154 | + if (in_array($key, $attachArray)) { |
|
155 | + @unlink($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $attach['name_saved'])); |
|
156 | + @unlink($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/thumbs/' . $attach['name_saved'])); // delete thumbnails |
|
157 | + continue; |
|
158 | + } |
|
159 | + $this->attachmentArray[$key] = $attach; |
|
160 | + } |
|
161 | + $attachmentSave = ''; |
|
162 | + if (is_array($this->attachmentArray) && count($this->attachmentArray) > 0) { |
|
163 | + $attachmentSave = base64_encode(serialize($this->attachmentArray)); |
|
164 | + } |
|
165 | + $this->setVar('attachment', $attachmentSave); |
|
166 | + |
|
167 | + return true; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * @param string $name_saved |
|
172 | + * @param string $nameDisplay |
|
173 | + * @param string $mimetype |
|
174 | + * @param int $numDownload |
|
175 | + * @return bool |
|
176 | + */ |
|
177 | + public function setAttachment($name_saved = '', $nameDisplay = '', $mimetype = '', $numDownload = 0) |
|
178 | + { |
|
179 | + static $counter = 0; |
|
180 | + $this->attachmentArray = $this->getAttachment(); |
|
181 | + if ($name_saved) { |
|
182 | + $key = (string)(time() + $counter++); |
|
183 | + $this->attachmentArray[$key] = [ |
|
184 | + 'name_saved' => $name_saved, |
|
185 | + 'nameDisplay' => empty($nameDisplay) ? $nameDisplay : $name_saved, |
|
186 | + 'mimetype' => $mimetype, |
|
187 | + 'numDownload' => empty($numDownload) ? (int)$numDownload : 0 |
|
188 | + ]; |
|
189 | + } |
|
190 | + $attachmentSave = null; |
|
191 | + if (is_array($this->attachmentArray)) { |
|
192 | + $attachmentSave = base64_encode(serialize($this->attachmentArray)); |
|
193 | + } |
|
194 | + $this->setVar('attachment', $attachmentSave); |
|
195 | + |
|
196 | + return true; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * TODO: refactor |
|
201 | + * @param bool $asSource |
|
202 | + * @return string |
|
203 | + */ |
|
204 | + public function displayAttachment($asSource = false) |
|
205 | + { |
|
206 | + global $xoopsModule; |
|
207 | + |
|
208 | + $post_attachment = ''; |
|
209 | + $attachments = $this->getAttachment(); |
|
210 | + if (is_array($attachments) && count($attachments) > 0) { |
|
211 | + $iconHandler = newbbGetIconHandler(); |
|
212 | + $mime_path = $iconHandler->getPath('mime'); |
|
213 | + require_once dirname(__DIR__) . '/include/functions.image.php'; |
|
214 | + $image_extensions = ['jpg', 'jpeg', 'gif', 'png', 'bmp']; // need improve !!! |
|
215 | + $post_attachment .= '<br><strong>' . _MD_NEWBB_ATTACHMENT . '</strong>:'; |
|
216 | + $post_attachment .= '<br><hr size="1" noshade="noshade" /><br>'; |
|
217 | + foreach ($attachments as $key => $att) { |
|
218 | + $file_extension = ltrim(strrchr($att['name_saved'], '.'), '.'); |
|
219 | + $filetype = $file_extension; |
|
220 | + if (file_exists($GLOBALS['xoops']->path($mime_path . '/' . $filetype . '.gif'))) { |
|
221 | + $icon_filetype = XOOPS_URL . '/' . $mime_path . '/' . $filetype . '.gif'; |
|
222 | + } else { |
|
223 | + $icon_filetype = XOOPS_URL . '/' . $mime_path . '/unknown.gif'; |
|
224 | + } |
|
225 | + $file_size = @filesize($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $att['name_saved'])); |
|
226 | + $file_size = number_format($file_size / 1024, 2) . ' KB'; |
|
227 | + if (in_array(strtolower($file_extension), $image_extensions) |
|
228 | + && $GLOBALS['xoopsModuleConfig']['media_allowed']) { |
|
229 | + $post_attachment .= '<br><img src="' . $icon_filetype . '" alt="' . $filetype . '" /><strong> ' . $att['nameDisplay'] . '</strong> <small>(' . $file_size . ')</small>'; |
|
230 | + $post_attachment .= '<br>' . newbbAttachmentImage($att['name_saved']); |
|
231 | + $isDisplayed = true; |
|
232 | + } else { |
|
233 | + if (empty($GLOBALS['xoopsModuleConfig']['show_userattach'])) { |
|
234 | + $post_attachment .= '<a href="' |
|
235 | + . XOOPS_URL |
|
236 | + . '/modules/' |
|
237 | + . $xoopsModule->getVar('dirname', 'n') |
|
238 | + . '/dl_attachment.php?attachid=' |
|
239 | + . $key |
|
240 | + . '&post_id=' |
|
241 | + . $this->getVar('post_id') |
|
242 | + . '"> <img src="' |
|
243 | + . $icon_filetype |
|
244 | + . '" alt="' |
|
245 | + . $filetype |
|
246 | + . '" /> ' |
|
247 | + . $att['nameDisplay'] |
|
248 | + . '</a> ' |
|
249 | + . _MD_NEWBB_FILESIZE |
|
250 | + . ': ' |
|
251 | + . $file_size |
|
252 | + . '; ' |
|
253 | + . _MD_NEWBB_HITS |
|
254 | + . ': ' |
|
255 | + . $att['numDownload']; |
|
256 | + } elseif ($GLOBALS['xoopsUser'] && $GLOBALS['xoopsUser']->uid() > 0 |
|
257 | + && $GLOBALS['xoopsUser']->isactive()) { |
|
258 | + $post_attachment .= '<a href="' |
|
259 | + . XOOPS_URL |
|
260 | + . '/modules/' |
|
261 | + . $xoopsModule->getVar('dirname', 'n') |
|
262 | + . '/dl_attachment.php?attachid=' |
|
263 | + . $key |
|
264 | + . '&post_id=' |
|
265 | + . $this->getVar('post_id') |
|
266 | + . '"> <img src="' |
|
267 | + . $icon_filetype |
|
268 | + . '" alt="' |
|
269 | + . $filetype |
|
270 | + . '" /> ' |
|
271 | + . $att['nameDisplay'] |
|
272 | + . '</a> ' |
|
273 | + . _MD_NEWBB_FILESIZE |
|
274 | + . ': ' |
|
275 | + . $file_size |
|
276 | + . '; ' |
|
277 | + . _MD_NEWBB_HITS |
|
278 | + . ': ' |
|
279 | + . $att['numDownload']; |
|
280 | + } else { |
|
281 | + $post_attachment .= _MD_NEWBB_SEENOTGUEST; |
|
282 | + } |
|
283 | + } |
|
284 | + $post_attachment .= '<br>'; |
|
285 | + } |
|
286 | + } |
|
287 | + |
|
288 | + return $post_attachment; |
|
289 | + } |
|
290 | + // attachment functions |
|
291 | + // //////////////////////////////////////////////////////////////////////////////////// |
|
292 | + |
|
293 | + /** |
|
294 | + * @param string $poster_name |
|
295 | + * @param string $post_editmsg |
|
296 | + * @return bool |
|
297 | + */ |
|
298 | + public function setPostEdit($poster_name = '', $post_editmsg = '') |
|
299 | + { |
|
300 | + $edit_user = ''; |
|
301 | + if (empty($GLOBALS['xoopsModuleConfig']['recordedit_timelimit']) |
|
302 | + || (time() - $this->getVar('post_time')) < $GLOBALS['xoopsModuleConfig']['recordedit_timelimit'] * 60 |
|
303 | + || $this->getVar('approved') < 1) { |
|
304 | + return true; |
|
305 | + } |
|
306 | + if (is_object($GLOBALS['xoopsUser']) && $GLOBALS['xoopsUser']->isActive()) { |
|
307 | + if ($GLOBALS['xoopsModuleConfig']['show_realname'] && $GLOBALS['xoopsUser']->getVar('name')) { |
|
308 | + $edit_user = $GLOBALS['xoopsUser']->getVar('name'); |
|
309 | + } else { |
|
310 | + $edit_user = $GLOBALS['xoopsUser']->getVar('uname'); |
|
311 | + } |
|
312 | + } |
|
313 | + $post_edit = []; |
|
314 | + $post_edit['edit_user'] = $edit_user; // (?) The proper way is to store uid instead of name. |
|
315 | + // However, to save queries when displaying, the current way is ok. |
|
316 | + $post_edit['edit_time'] = time(); |
|
317 | + $post_edit['edit_msg'] = $post_editmsg; |
|
318 | + |
|
319 | + $post_edits = $this->getVar('post_edit'); |
|
320 | + if (!empty($post_edits)) { |
|
321 | + $post_edits = unserialize(base64_decode($post_edits)); |
|
322 | + } |
|
323 | + if (!is_array($post_edits)) { |
|
324 | + $post_edits = []; |
|
325 | + } |
|
326 | + $post_edits[] = $post_edit; |
|
327 | + $post_edit = base64_encode(serialize($post_edits)); |
|
328 | + unset($post_edits); |
|
329 | + $this->setVar('post_edit', $post_edit); |
|
330 | + |
|
331 | + return true; |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * @return bool|string |
|
336 | + */ |
|
337 | + public function displayPostEdit() |
|
338 | + { |
|
339 | + global $myts; |
|
340 | + |
|
341 | + if (empty($GLOBALS['xoopsModuleConfig']['recordedit_timelimit'])) { |
|
342 | + return false; |
|
343 | + } |
|
344 | + |
|
345 | + $post_edit = ''; |
|
346 | + $post_edits = $this->getVar('post_edit'); |
|
347 | + if (!empty($post_edits)) { |
|
348 | + $post_edits = unserialize(base64_decode($post_edits)); |
|
349 | + } |
|
350 | + if (!isset($post_edits) || !is_array($post_edits)) { |
|
351 | + $post_edits = []; |
|
352 | + } |
|
353 | + if (is_array($post_edits) && count($post_edits) > 0) { |
|
354 | + foreach ($post_edits as $postedit) { |
|
355 | + $edit_time = (int)$postedit['edit_time']; |
|
356 | + $edit_user = $postedit['edit_user']; |
|
357 | + $edit_msg = !empty($postedit['edit_msg']) ? $postedit['edit_msg'] : ''; |
|
358 | + // Start irmtfan add option to do only the latest edit when do_latestedit=0 (Alfred) |
|
359 | + if (empty($GLOBALS['xoopsModuleConfig']['do_latestedit'])) { |
|
360 | + $post_edit = ''; |
|
361 | + } |
|
362 | + // End irmtfan add option to do only the latest edit when do_latestedit=0 (Alfred) |
|
363 | + // START hacked by irmtfan |
|
364 | + // display/save all edit records. |
|
365 | + $post_edit .= _MD_NEWBB_EDITEDBY . ' ' . $edit_user . ' ' . _MD_NEWBB_ON . ' ' . formatTimestamp($edit_time) . '<br>'; |
|
366 | + // if reason is not empty |
|
367 | + if ('' !== $edit_msg) { |
|
368 | + $post_edit .= _MD_NEWBB_EDITEDMSG . ' ' . $edit_msg . '<br>'; |
|
369 | + } |
|
370 | + // START hacked by irmtfan |
|
371 | + } |
|
372 | + } |
|
373 | + |
|
374 | + return $post_edit; |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * @return array |
|
379 | + */ |
|
380 | + public function &getPostBody() |
|
381 | + { |
|
382 | + global $viewtopic_users; |
|
383 | + $newbbConfig = newbbLoadConfig(); |
|
384 | + require_once dirname(__DIR__) . '/include/functions.user.php'; |
|
385 | + require_once dirname(__DIR__) . '/include/functions.render.php'; |
|
386 | + |
|
387 | + $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
388 | + /** @var KarmaHandler $karmaHandler */ |
|
389 | + $karmaHandler = Newbb\Helper::getInstance()->getHandler('Karma'); |
|
390 | + $user_karma = $karmaHandler->getUserKarma(); |
|
391 | + |
|
392 | + $post = []; |
|
393 | + $post['attachment'] = false; |
|
394 | + $post_text = newbbDisplayTarea($this->vars['post_text']['value'], $this->getVar('dohtml'), $this->getVar('dosmiley'), $this->getVar('doxcode'), $this->getVar('doimage'), $this->getVar('dobr')); |
|
395 | + if (newbbIsAdmin($this->getVar('forum_id')) || $this->checkIdentity()) { |
|
396 | + $post['text'] = $post_text . '<br>' . $this->displayAttachment(); |
|
397 | + } elseif ($newbbConfig['enable_karma'] && $this->getVar('post_karma') > $user_karma) { |
|
398 | + $post['text'] = sprintf(_MD_NEWBB_KARMA_REQUIREMENT, $user_karma, $this->getVar('post_karma')); |
|
399 | + } elseif ($newbbConfig['allow_require_reply'] && $this->getVar('require_reply') |
|
400 | + && (!$uid || !isset($viewtopic_users[$uid]))) { |
|
401 | + $post['text'] = _MD_NEWBB_REPLY_REQUIREMENT; |
|
402 | + } else { |
|
403 | + $post['text'] = $post_text . '<br>' . $this->displayAttachment(); |
|
404 | + } |
|
405 | + /** @var \XoopsMemberHandler $memberHandler */ |
|
406 | + $memberHandler = xoops_getHandler('member'); |
|
407 | + $eachposter = $memberHandler->getUser($this->getVar('uid')); |
|
408 | + if (is_object($eachposter) && $eachposter->isActive()) { |
|
409 | + if ($newbbConfig['show_realname'] && $eachposter->getVar('name')) { |
|
410 | + $post['author'] = $eachposter->getVar('name'); |
|
411 | + } else { |
|
412 | + $post['author'] = $eachposter->getVar('uname'); |
|
413 | + } |
|
414 | + unset($eachposter); |
|
415 | + } else { |
|
416 | + $post['author'] = $this->getVar('poster_name') ?: $GLOBALS['xoopsConfig']['anonymous']; |
|
417 | + } |
|
418 | + |
|
419 | + $post['subject'] = newbbHtmlspecialchars($this->vars['subject']['value']); |
|
420 | + |
|
421 | + $post['date'] = $this->getVar('post_time'); |
|
422 | + |
|
423 | + return $post; |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | + * @return bool |
|
428 | + */ |
|
429 | + public function isTopic() |
|
430 | + { |
|
431 | + return !$this->getVar('pid'); |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * @param string $action_tag |
|
436 | + * @return bool |
|
437 | + */ |
|
438 | + public function checkTimelimit($action_tag = 'edit_timelimit') |
|
439 | + { |
|
440 | + $newbbConfig = newbbLoadConfig(); |
|
441 | + if (empty($newbbConfig['edit_timelimit'])) { |
|
442 | + return true; |
|
443 | + } |
|
444 | + |
|
445 | + return ($this->getVar('post_time') > time() - $newbbConfig[$action_tag] * 60); |
|
446 | + } |
|
447 | + |
|
448 | + /** |
|
449 | + * @param int $uid |
|
450 | + * @return bool |
|
451 | + */ |
|
452 | + public function checkIdentity($uid = -1) |
|
453 | + { |
|
454 | + $uid = ($uid > -1) ? $uid : (is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0); |
|
455 | + if ($this->getVar('uid') > 0) { |
|
456 | + $user_ok = ($uid == $this->getVar('uid')); |
|
457 | + } else { |
|
458 | + static $user_ip; |
|
459 | + if (!isset($user_ip)) { |
|
460 | + $user_ip = \Xmf\IPAddress::fromRequest()->asReadable(); |
|
461 | + } |
|
462 | + $user_ok = ($user_ip == $this->getVar('poster_ip')); |
|
463 | + } |
|
464 | + |
|
465 | + return $user_ok; |
|
466 | + } |
|
467 | + |
|
468 | + // TODO: cleaning up and merge with post hanldings in viewpost.php |
|
469 | + |
|
470 | + /** |
|
471 | + * @param $isAdmin |
|
472 | + * @return array |
|
473 | + */ |
|
474 | + public function showPost($isAdmin) |
|
475 | + { |
|
476 | + global $xoopsModule, $myts; |
|
477 | + global $forumUrl, $forumImage, $forumObject, $online, $viewmode; |
|
478 | + global $viewtopic_users, $viewtopic_posters, $topicObject, $user_karma; |
|
479 | + global $order, $start, $total_posts, $topic_status; |
|
480 | + static $post_NO = 0; |
|
481 | + static $name_anonymous; |
|
482 | + /** @var TopicHandler $topicHandler */ |
|
483 | + $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
484 | + if (!isset($name_anonymous)) { |
|
485 | + $name_anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']); |
|
486 | + } |
|
487 | + |
|
488 | + require_once dirname(__DIR__) . '/include/functions.time.php'; |
|
489 | + require_once dirname(__DIR__) . '/include/functions.render.php'; |
|
490 | + |
|
491 | + $post_id = $this->getVar('post_id'); |
|
492 | + $topic_id = $this->getVar('topic_id'); |
|
493 | + $forum_id = $this->getVar('forum_id'); |
|
494 | + |
|
495 | + $query_vars = ['status', 'order', 'start', 'mode', 'viewmode']; |
|
496 | + $query_array = []; |
|
497 | + $query_array['topic_id'] = "topic_id={$topic_id}"; |
|
498 | + foreach ($query_vars as $var) { |
|
499 | + if (Request::getString($var, '', 'GET')) { |
|
500 | + $query_array[$var] = "{$var}=" . Request::getString($var, '', 'GET'); |
|
501 | + } |
|
502 | + } |
|
503 | + $page_query = htmlspecialchars(implode('&', array_values($query_array)), ENT_QUOTES | ENT_HTML5); |
|
504 | + |
|
505 | + $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
506 | + |
|
507 | + ++$post_NO; |
|
508 | + if ('desc' === strtolower($order)) { |
|
509 | + $post_no = $total_posts - ($start + $post_NO) + 1; |
|
510 | + } else { |
|
511 | + $post_no = $start + $post_NO; |
|
512 | + } |
|
513 | + |
|
514 | + if ($isAdmin || $this->checkIdentity()) { |
|
515 | + $post_text = $this->getVar('post_text'); |
|
516 | + $post_attachment = $this->displayAttachment(); |
|
517 | + } elseif ($GLOBALS['xoopsModuleConfig']['enable_karma'] && $this->getVar('post_karma') > $user_karma) { |
|
518 | + $post_text = "<div class='karma'>" . sprintf(_MD_NEWBB_KARMA_REQUIREMENT, $user_karma, $this->getVar('post_karma')) . '</div>'; |
|
519 | + $post_attachment = ''; |
|
520 | + } elseif ($GLOBALS['xoopsModuleConfig']['allow_require_reply'] && $this->getVar('require_reply') |
|
521 | + && (!$uid || !in_array($uid, $viewtopic_posters))) { |
|
522 | + $post_text = "<div class='karma'>" . _MD_NEWBB_REPLY_REQUIREMENT . '</div>'; |
|
523 | + $post_attachment = ''; |
|
524 | + } else { |
|
525 | + $post_text = $this->getVar('post_text'); |
|
526 | + $post_attachment = $this->displayAttachment(); |
|
527 | + } |
|
528 | + |
|
529 | + // Hightlight search words |
|
530 | + $post_title = $this->getVar('subject'); |
|
531 | + if ($keywords = Request::getString('keywords', '', 'GET')) { |
|
532 | + //$keywords = $myts->htmlSpecialChars(trim(urldecode(Request::getString('keywords', '', 'GET')))); |
|
533 | + $post_text = Highlighter::apply($keywords, $post_text, '<mark>', '</mark>'); |
|
534 | + $post_title = Highlighter::apply($keywords, $post_title, '<mark>', '</mark>'); |
|
535 | + } |
|
536 | + |
|
537 | + if (isset($viewtopic_users[$this->getVar('uid')])) { |
|
538 | + $poster = $viewtopic_users[$this->getVar('uid')]; |
|
539 | + } else { |
|
540 | + $name = ($post_name = $this->getVar('poster_name')) ? $post_name : $name_anonymous; |
|
541 | + $poster = [ |
|
542 | + 'poster_uid' => 0, |
|
543 | + 'name' => $name, |
|
544 | + 'link' => $name |
|
545 | + ]; |
|
546 | + } |
|
547 | + |
|
548 | + if ($posticon = $this->getVar('icon')) { |
|
549 | + $post_image = '<a name="' . $post_id . '"><img src="' . XOOPS_URL . '/images/subject/' . $posticon . '" alt="" /></a>'; |
|
550 | + } else { |
|
551 | + $post_image = '<a name="' . $post_id . '"><img src="' . XOOPS_URL . '/images/icons/posticon.gif" alt="" /></a>'; |
|
552 | + } |
|
553 | + |
|
554 | + $thread_buttons = []; |
|
555 | + $mod_buttons = []; |
|
556 | + |
|
557 | + if ($isAdmin && ($GLOBALS['xoopsUser'] && $GLOBALS['xoopsUser']->getVar('uid') !== $this->getVar('uid')) |
|
558 | + && $this->getVar('uid') > 0) { |
|
559 | + $mod_buttons['bann']['image'] = newbbDisplayImage('p_bann', _MD_NEWBB_SUSPEND_MANAGEMENT); |
|
560 | + $mod_buttons['bann']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/moderate.php?forum=' . $forum_id . '&uid=' . $this->getVar('uid'); |
|
561 | + $mod_buttons['bann']['name'] = _MD_NEWBB_SUSPEND_MANAGEMENT; |
|
562 | + $thread_buttons['bann']['image'] = newbbDisplayImage('p_bann', _MD_NEWBB_SUSPEND_MANAGEMENT); |
|
563 | + $thread_buttons['bann']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/moderate.php?forum=' . $forum_id . '&uid=' . $this->getVar('uid'); |
|
564 | + $thread_buttons['bann']['name'] = _MD_NEWBB_SUSPEND_MANAGEMENT; |
|
565 | + } |
|
566 | + |
|
567 | + if ($GLOBALS['xoopsModuleConfig']['enable_permcheck']) { |
|
568 | + // /** @var TopicHandler $topicHandler */ |
|
569 | + // $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
570 | + $topic_status = $topicObject->getVar('topic_status'); |
|
571 | + if ($topicHandler->getPermission($forum_id, $topic_status, 'edit')) { |
|
572 | + $edit_ok = ($isAdmin || ($this->checkIdentity() && $this->checkTimelimit('edit_timelimit'))); |
|
573 | + |
|
574 | + if ($edit_ok) { |
|
575 | + $thread_buttons['edit']['image'] = newbbDisplayImage('p_edit', _EDIT); |
|
576 | + $thread_buttons['edit']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}"; |
|
577 | + $thread_buttons['edit']['name'] = _EDIT; |
|
578 | + $mod_buttons['edit']['image'] = newbbDisplayImage('p_edit', _EDIT); |
|
579 | + $mod_buttons['edit']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}"; |
|
580 | + $mod_buttons['edit']['name'] = _EDIT; |
|
581 | + } |
|
582 | + } |
|
583 | + |
|
584 | + if ($topicHandler->getPermission($forum_id, $topic_status, 'delete')) { |
|
585 | + $delete_ok = ($isAdmin || ($this->checkIdentity() && $this->checkTimelimit('delete_timelimit'))); |
|
586 | + |
|
587 | + if ($delete_ok) { |
|
588 | + $thread_buttons['delete']['image'] = newbbDisplayImage('p_delete', _DELETE); |
|
589 | + $thread_buttons['delete']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}"; |
|
590 | + $thread_buttons['delete']['name'] = _DELETE; |
|
591 | + $mod_buttons['delete']['image'] = newbbDisplayImage('p_delete', _DELETE); |
|
592 | + $mod_buttons['delete']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}"; |
|
593 | + $mod_buttons['delete']['name'] = _DELETE; |
|
594 | + } |
|
595 | + } |
|
596 | + if ($topicHandler->getPermission($forum_id, $topic_status, 'reply')) { |
|
597 | + $thread_buttons['reply']['image'] = newbbDisplayImage('p_reply', _MD_NEWBB_REPLY); |
|
598 | + $thread_buttons['reply']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}"; |
|
599 | + $thread_buttons['reply']['name'] = _MD_NEWBB_REPLY; |
|
600 | + |
|
601 | + $thread_buttons['quote']['image'] = newbbDisplayImage('p_quote', _MD_NEWBB_QUOTE); |
|
602 | + $thread_buttons['quote']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}&quotedac=1"; |
|
603 | + $thread_buttons['quote']['name'] = _MD_NEWBB_QUOTE; |
|
604 | + } |
|
605 | + } else { |
|
606 | + $mod_buttons['edit']['image'] = newbbDisplayImage('p_edit', _EDIT); |
|
607 | + $mod_buttons['edit']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}"; |
|
608 | + $mod_buttons['edit']['name'] = _EDIT; |
|
609 | + |
|
610 | + $mod_buttons['delete']['image'] = newbbDisplayImage('p_delete', _DELETE); |
|
611 | + $mod_buttons['delete']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}"; |
|
612 | + $mod_buttons['delete']['name'] = _DELETE; |
|
613 | + |
|
614 | + $thread_buttons['reply']['image'] = newbbDisplayImage('p_reply', _MD_NEWBB_REPLY); |
|
615 | + $thread_buttons['reply']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}"; |
|
616 | + $thread_buttons['reply']['name'] = _MD_NEWBB_REPLY; |
|
617 | + } |
|
618 | + |
|
619 | + if (!$isAdmin && $GLOBALS['xoopsModuleConfig']['reportmod_enabled']) { |
|
620 | + $thread_buttons['report']['image'] = newbbDisplayImage('p_report', _MD_NEWBB_REPORT); |
|
621 | + $thread_buttons['report']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/report.php?{$page_query}"; |
|
622 | + $thread_buttons['report']['name'] = _MD_NEWBB_REPORT; |
|
623 | + } |
|
624 | + |
|
625 | + $thread_action = []; |
|
626 | + // irmtfan add pdf permission |
|
627 | + if (file_exists(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php') |
|
628 | + && $topicHandler->getPermission($forum_id, $topic_status, 'pdf')) { |
|
629 | + $thread_action['pdf']['image'] = newbbDisplayImage('pdf', _MD_NEWBB_PDF); |
|
630 | + $thread_action['pdf']['link'] = XOOPS_URL . '/modules/newbb/makepdf.php?type=post&pageid=0'; |
|
631 | + $thread_action['pdf']['name'] = _MD_NEWBB_PDF; |
|
632 | + $thread_action['pdf']['target'] = '_blank'; |
|
633 | + } |
|
634 | + // irmtfan add print permission |
|
635 | + if ($topicHandler->getPermission($forum_id, $topic_status, 'print')) { |
|
636 | + $thread_action['print']['image'] = newbbDisplayImage('printer', _MD_NEWBB_PRINT); |
|
637 | + $thread_action['print']['link'] = XOOPS_URL . '/modules/newbb/print.php?form=2&forum=' . $forum_id . '&topic_id=' . $topic_id; |
|
638 | + $thread_action['print']['name'] = _MD_NEWBB_PRINT; |
|
639 | + $thread_action['print']['target'] = '_blank'; |
|
640 | + } |
|
641 | + |
|
642 | + if ($GLOBALS['xoopsModuleConfig']['show_sociallinks']) { |
|
643 | + $full_title = $this->getVar('subject'); |
|
644 | + $clean_title = preg_replace('/[^A-Za-z0-9-]+/', '+', $this->getVar('subject')); |
|
645 | + $full_link = XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $post_id; |
|
646 | + |
|
647 | + $thread_action['social_twitter']['image'] = newbbDisplayImage('twitter', _MD_NEWBB_SHARE_TWITTER); |
|
648 | + $thread_action['social_twitter']['link'] = 'http://twitter.com/share?text=' . $clean_title . '&url=' . $full_link; |
|
649 | + $thread_action['social_twitter']['name'] = _MD_NEWBB_SHARE_TWITTER; |
|
650 | + $thread_action['social_twitter']['target'] = '_blank'; |
|
651 | + |
|
652 | + $thread_action['social_facebook']['image'] = newbbDisplayImage('facebook', _MD_NEWBB_SHARE_FACEBOOK); |
|
653 | + $thread_action['social_facebook']['link'] = 'http://www.facebook.com/sharer.php?u=' . $full_link; |
|
654 | + $thread_action['social_facebook']['name'] = _MD_NEWBB_SHARE_FACEBOOK; |
|
655 | + $thread_action['social_facebook']['target'] = '_blank'; |
|
656 | + |
|
657 | + $thread_action['social_gplus']['image'] = newbbDisplayImage('googleplus', _MD_NEWBB_SHARE_GOOGLEPLUS); |
|
658 | + $thread_action['social_gplus']['link'] = 'https://plusone.google.com/_/+1/confirm?hl=en&url=' . $full_link; |
|
659 | + $thread_action['social_gplus']['name'] = _MD_NEWBB_SHARE_GOOGLEPLUS; |
|
660 | + $thread_action['social_gplus']['target'] = '_blank'; |
|
661 | + |
|
662 | + $thread_action['social_linkedin']['image'] = newbbDisplayImage('linkedin', _MD_NEWBB_SHARE_LINKEDIN); |
|
663 | + $thread_action['social_linkedin']['link'] = 'http://www.linkedin.com/shareArticle?mini=true&title=' . $full_title . '&url=' . $full_link; |
|
664 | + $thread_action['social_linkedin']['name'] = _MD_NEWBB_SHARE_LINKEDIN; |
|
665 | + $thread_action['social_linkedin']['target'] = '_blank'; |
|
666 | + |
|
667 | + $thread_action['social_delicious']['image'] = newbbDisplayImage('delicious', _MD_NEWBB_SHARE_DELICIOUS); |
|
668 | + $thread_action['social_delicious']['link'] = 'http://del.icio.us/post?title=' . $full_title . '&url=' . $full_link; |
|
669 | + $thread_action['social_delicious']['name'] = _MD_NEWBB_SHARE_DELICIOUS; |
|
670 | + $thread_action['social_delicious']['target'] = '_blank'; |
|
671 | + |
|
672 | + $thread_action['social_digg']['image'] = newbbDisplayImage('digg', _MD_NEWBB_SHARE_DIGG); |
|
673 | + $thread_action['social_digg']['link'] = 'http://digg.com/submit?phase=2&title=' . $full_title . '&url=' . $full_link; |
|
674 | + $thread_action['social_digg']['name'] = _MD_NEWBB_SHARE_DIGG; |
|
675 | + $thread_action['social_digg']['target'] = '_blank'; |
|
676 | + |
|
677 | + $thread_action['social_reddit']['image'] = newbbDisplayImage('reddit', _MD_NEWBB_SHARE_REDDIT); |
|
678 | + $thread_action['social_reddit']['link'] = 'http://reddit.com/submit?title=' . $full_title . '&url=' . $full_link; |
|
679 | + $thread_action['social_reddit']['name'] = _MD_NEWBB_SHARE_REDDIT; |
|
680 | + $thread_action['social_reddit']['target'] = '_blank'; |
|
681 | + |
|
682 | + $thread_action['social_wong']['image'] = newbbDisplayImage('wong', _MD_NEWBB_SHARE_MRWONG); |
|
683 | + $thread_action['social_wong']['link'] = 'http://www.mister-wong.de/index.php?action=addurl&bm_url=' . $full_link; |
|
684 | + $thread_action['social_wong']['name'] = _MD_NEWBB_SHARE_MRWONG; |
|
685 | + $thread_action['social_wong']['target'] = '_blank'; |
|
686 | + } |
|
687 | + |
|
688 | + $post = [ |
|
689 | + 'post_id' => $post_id, |
|
690 | + 'post_parent_id' => $this->getVar('pid'), |
|
691 | + 'post_date' => newbbFormatTimestamp($this->getVar('post_time')), |
|
692 | + 'post_image' => $post_image, |
|
693 | + 'post_title' => $post_title, |
|
694 | + // irmtfan $post_title to add highlight keywords |
|
695 | + 'post_text' => $post_text, |
|
696 | + 'post_attachment' => $post_attachment, |
|
697 | + 'post_edit' => $this->displayPostEdit(), |
|
698 | + 'post_no' => $post_no, |
|
699 | + 'post_signature' => $this->getVar('attachsig') ? @$poster['signature'] : '', |
|
700 | + // 'poster_ip' => ($isAdmin && $GLOBALS['xoopsModuleConfig']['show_ip']) ? long2ip($this->getVar('poster_ip')) : '', |
|
701 | + 'poster_ip' => ($isAdmin |
|
702 | + && $GLOBALS['xoopsModuleConfig']['show_ip']) ? $this->getVar('poster_ip') : '', |
|
703 | + 'thread_action' => $thread_action, |
|
704 | + 'thread_buttons' => $thread_buttons, |
|
705 | + 'mod_buttons' => $mod_buttons, |
|
706 | + 'poster' => $poster, |
|
707 | + 'post_permalink' => '<a href="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?post_id=' . $post_id . '"></a>' |
|
708 | + ]; |
|
709 | + |
|
710 | + unset($thread_buttons, $mod_buttons, $eachposter); |
|
711 | + |
|
712 | + return $post; |
|
713 | + } |
|
714 | 714 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | $attachmentSave = base64_encode(serialize($this->attachmentArray)); |
123 | 123 | } |
124 | 124 | $this->setVar('attachment', $attachmentSave); |
125 | - $sql = 'UPDATE ' . $GLOBALS['xoopsDB']->prefix('newbb_posts') . ' SET attachment=' . $GLOBALS['xoopsDB']->quoteString($attachmentSave) . ' WHERE post_id = ' . $this->getVar('post_id'); |
|
125 | + $sql = 'UPDATE '.$GLOBALS['xoopsDB']->prefix('newbb_posts').' SET attachment='.$GLOBALS['xoopsDB']->quoteString($attachmentSave).' WHERE post_id = '.$this->getVar('post_id'); |
|
126 | 126 | if (!$result = $GLOBALS['xoopsDB']->queryF($sql)) { |
127 | 127 | //xoops_error($GLOBALS['xoopsDB']->error()); |
128 | 128 | return false; |
@@ -152,8 +152,8 @@ discard block |
||
152 | 152 | |
153 | 153 | foreach ($attachOld as $key => $attach) { |
154 | 154 | if (in_array($key, $attachArray)) { |
155 | - @unlink($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $attach['name_saved'])); |
|
156 | - @unlink($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/thumbs/' . $attach['name_saved'])); // delete thumbnails |
|
155 | + @unlink($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'].'/'.$attach['name_saved'])); |
|
156 | + @unlink($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'].'/thumbs/'.$attach['name_saved'])); // delete thumbnails |
|
157 | 157 | continue; |
158 | 158 | } |
159 | 159 | $this->attachmentArray[$key] = $attach; |
@@ -210,25 +210,25 @@ discard block |
||
210 | 210 | if (is_array($attachments) && count($attachments) > 0) { |
211 | 211 | $iconHandler = newbbGetIconHandler(); |
212 | 212 | $mime_path = $iconHandler->getPath('mime'); |
213 | - require_once dirname(__DIR__) . '/include/functions.image.php'; |
|
213 | + require_once dirname(__DIR__).'/include/functions.image.php'; |
|
214 | 214 | $image_extensions = ['jpg', 'jpeg', 'gif', 'png', 'bmp']; // need improve !!! |
215 | - $post_attachment .= '<br><strong>' . _MD_NEWBB_ATTACHMENT . '</strong>:'; |
|
215 | + $post_attachment .= '<br><strong>'._MD_NEWBB_ATTACHMENT.'</strong>:'; |
|
216 | 216 | $post_attachment .= '<br><hr size="1" noshade="noshade" /><br>'; |
217 | 217 | foreach ($attachments as $key => $att) { |
218 | 218 | $file_extension = ltrim(strrchr($att['name_saved'], '.'), '.'); |
219 | 219 | $filetype = $file_extension; |
220 | - if (file_exists($GLOBALS['xoops']->path($mime_path . '/' . $filetype . '.gif'))) { |
|
221 | - $icon_filetype = XOOPS_URL . '/' . $mime_path . '/' . $filetype . '.gif'; |
|
220 | + if (file_exists($GLOBALS['xoops']->path($mime_path.'/'.$filetype.'.gif'))) { |
|
221 | + $icon_filetype = XOOPS_URL.'/'.$mime_path.'/'.$filetype.'.gif'; |
|
222 | 222 | } else { |
223 | - $icon_filetype = XOOPS_URL . '/' . $mime_path . '/unknown.gif'; |
|
223 | + $icon_filetype = XOOPS_URL.'/'.$mime_path.'/unknown.gif'; |
|
224 | 224 | } |
225 | - $file_size = @filesize($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'] . '/' . $att['name_saved'])); |
|
226 | - $file_size = number_format($file_size / 1024, 2) . ' KB'; |
|
225 | + $file_size = @filesize($GLOBALS['xoops']->path($GLOBALS['xoopsModuleConfig']['dir_attachments'].'/'.$att['name_saved'])); |
|
226 | + $file_size = number_format($file_size / 1024, 2).' KB'; |
|
227 | 227 | if (in_array(strtolower($file_extension), $image_extensions) |
228 | 228 | && $GLOBALS['xoopsModuleConfig']['media_allowed']) { |
229 | - $post_attachment .= '<br><img src="' . $icon_filetype . '" alt="' . $filetype . '" /><strong> ' . $att['nameDisplay'] . '</strong> <small>(' . $file_size . ')</small>'; |
|
230 | - $post_attachment .= '<br>' . newbbAttachmentImage($att['name_saved']); |
|
231 | - $isDisplayed = true; |
|
229 | + $post_attachment .= '<br><img src="'.$icon_filetype.'" alt="'.$filetype.'" /><strong> '.$att['nameDisplay'].'</strong> <small>('.$file_size.')</small>'; |
|
230 | + $post_attachment .= '<br>'.newbbAttachmentImage($att['name_saved']); |
|
231 | + $isDisplayed = true; |
|
232 | 232 | } else { |
233 | 233 | if (empty($GLOBALS['xoopsModuleConfig']['show_userattach'])) { |
234 | 234 | $post_attachment .= '<a href="' |
@@ -362,10 +362,10 @@ discard block |
||
362 | 362 | // End irmtfan add option to do only the latest edit when do_latestedit=0 (Alfred) |
363 | 363 | // START hacked by irmtfan |
364 | 364 | // display/save all edit records. |
365 | - $post_edit .= _MD_NEWBB_EDITEDBY . ' ' . $edit_user . ' ' . _MD_NEWBB_ON . ' ' . formatTimestamp($edit_time) . '<br>'; |
|
365 | + $post_edit .= _MD_NEWBB_EDITEDBY.' '.$edit_user.' '._MD_NEWBB_ON.' '.formatTimestamp($edit_time).'<br>'; |
|
366 | 366 | // if reason is not empty |
367 | 367 | if ('' !== $edit_msg) { |
368 | - $post_edit .= _MD_NEWBB_EDITEDMSG . ' ' . $edit_msg . '<br>'; |
|
368 | + $post_edit .= _MD_NEWBB_EDITEDMSG.' '.$edit_msg.'<br>'; |
|
369 | 369 | } |
370 | 370 | // START hacked by irmtfan |
371 | 371 | } |
@@ -381,8 +381,8 @@ discard block |
||
381 | 381 | { |
382 | 382 | global $viewtopic_users; |
383 | 383 | $newbbConfig = newbbLoadConfig(); |
384 | - require_once dirname(__DIR__) . '/include/functions.user.php'; |
|
385 | - require_once dirname(__DIR__) . '/include/functions.render.php'; |
|
384 | + require_once dirname(__DIR__).'/include/functions.user.php'; |
|
385 | + require_once dirname(__DIR__).'/include/functions.render.php'; |
|
386 | 386 | |
387 | 387 | $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
388 | 388 | /** @var KarmaHandler $karmaHandler */ |
@@ -393,14 +393,14 @@ discard block |
||
393 | 393 | $post['attachment'] = false; |
394 | 394 | $post_text = newbbDisplayTarea($this->vars['post_text']['value'], $this->getVar('dohtml'), $this->getVar('dosmiley'), $this->getVar('doxcode'), $this->getVar('doimage'), $this->getVar('dobr')); |
395 | 395 | if (newbbIsAdmin($this->getVar('forum_id')) || $this->checkIdentity()) { |
396 | - $post['text'] = $post_text . '<br>' . $this->displayAttachment(); |
|
396 | + $post['text'] = $post_text.'<br>'.$this->displayAttachment(); |
|
397 | 397 | } elseif ($newbbConfig['enable_karma'] && $this->getVar('post_karma') > $user_karma) { |
398 | 398 | $post['text'] = sprintf(_MD_NEWBB_KARMA_REQUIREMENT, $user_karma, $this->getVar('post_karma')); |
399 | 399 | } elseif ($newbbConfig['allow_require_reply'] && $this->getVar('require_reply') |
400 | 400 | && (!$uid || !isset($viewtopic_users[$uid]))) { |
401 | 401 | $post['text'] = _MD_NEWBB_REPLY_REQUIREMENT; |
402 | 402 | } else { |
403 | - $post['text'] = $post_text . '<br>' . $this->displayAttachment(); |
|
403 | + $post['text'] = $post_text.'<br>'.$this->displayAttachment(); |
|
404 | 404 | } |
405 | 405 | /** @var \XoopsMemberHandler $memberHandler */ |
406 | 406 | $memberHandler = xoops_getHandler('member'); |
@@ -485,8 +485,8 @@ discard block |
||
485 | 485 | $name_anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']); |
486 | 486 | } |
487 | 487 | |
488 | - require_once dirname(__DIR__) . '/include/functions.time.php'; |
|
489 | - require_once dirname(__DIR__) . '/include/functions.render.php'; |
|
488 | + require_once dirname(__DIR__).'/include/functions.time.php'; |
|
489 | + require_once dirname(__DIR__).'/include/functions.render.php'; |
|
490 | 490 | |
491 | 491 | $post_id = $this->getVar('post_id'); |
492 | 492 | $topic_id = $this->getVar('topic_id'); |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | $query_array['topic_id'] = "topic_id={$topic_id}"; |
498 | 498 | foreach ($query_vars as $var) { |
499 | 499 | if (Request::getString($var, '', 'GET')) { |
500 | - $query_array[$var] = "{$var}=" . Request::getString($var, '', 'GET'); |
|
500 | + $query_array[$var] = "{$var}=".Request::getString($var, '', 'GET'); |
|
501 | 501 | } |
502 | 502 | } |
503 | 503 | $page_query = htmlspecialchars(implode('&', array_values($query_array)), ENT_QUOTES | ENT_HTML5); |
@@ -515,11 +515,11 @@ discard block |
||
515 | 515 | $post_text = $this->getVar('post_text'); |
516 | 516 | $post_attachment = $this->displayAttachment(); |
517 | 517 | } elseif ($GLOBALS['xoopsModuleConfig']['enable_karma'] && $this->getVar('post_karma') > $user_karma) { |
518 | - $post_text = "<div class='karma'>" . sprintf(_MD_NEWBB_KARMA_REQUIREMENT, $user_karma, $this->getVar('post_karma')) . '</div>'; |
|
518 | + $post_text = "<div class='karma'>".sprintf(_MD_NEWBB_KARMA_REQUIREMENT, $user_karma, $this->getVar('post_karma')).'</div>'; |
|
519 | 519 | $post_attachment = ''; |
520 | 520 | } elseif ($GLOBALS['xoopsModuleConfig']['allow_require_reply'] && $this->getVar('require_reply') |
521 | 521 | && (!$uid || !in_array($uid, $viewtopic_posters))) { |
522 | - $post_text = "<div class='karma'>" . _MD_NEWBB_REPLY_REQUIREMENT . '</div>'; |
|
522 | + $post_text = "<div class='karma'>"._MD_NEWBB_REPLY_REQUIREMENT.'</div>'; |
|
523 | 523 | $post_attachment = ''; |
524 | 524 | } else { |
525 | 525 | $post_text = $this->getVar('post_text'); |
@@ -546,9 +546,9 @@ discard block |
||
546 | 546 | } |
547 | 547 | |
548 | 548 | if ($posticon = $this->getVar('icon')) { |
549 | - $post_image = '<a name="' . $post_id . '"><img src="' . XOOPS_URL . '/images/subject/' . $posticon . '" alt="" /></a>'; |
|
549 | + $post_image = '<a name="'.$post_id.'"><img src="'.XOOPS_URL.'/images/subject/'.$posticon.'" alt="" /></a>'; |
|
550 | 550 | } else { |
551 | - $post_image = '<a name="' . $post_id . '"><img src="' . XOOPS_URL . '/images/icons/posticon.gif" alt="" /></a>'; |
|
551 | + $post_image = '<a name="'.$post_id.'"><img src="'.XOOPS_URL.'/images/icons/posticon.gif" alt="" /></a>'; |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | $thread_buttons = []; |
@@ -557,10 +557,10 @@ discard block |
||
557 | 557 | if ($isAdmin && ($GLOBALS['xoopsUser'] && $GLOBALS['xoopsUser']->getVar('uid') !== $this->getVar('uid')) |
558 | 558 | && $this->getVar('uid') > 0) { |
559 | 559 | $mod_buttons['bann']['image'] = newbbDisplayImage('p_bann', _MD_NEWBB_SUSPEND_MANAGEMENT); |
560 | - $mod_buttons['bann']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/moderate.php?forum=' . $forum_id . '&uid=' . $this->getVar('uid'); |
|
560 | + $mod_buttons['bann']['link'] = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/moderate.php?forum='.$forum_id.'&uid='.$this->getVar('uid'); |
|
561 | 561 | $mod_buttons['bann']['name'] = _MD_NEWBB_SUSPEND_MANAGEMENT; |
562 | 562 | $thread_buttons['bann']['image'] = newbbDisplayImage('p_bann', _MD_NEWBB_SUSPEND_MANAGEMENT); |
563 | - $thread_buttons['bann']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/moderate.php?forum=' . $forum_id . '&uid=' . $this->getVar('uid'); |
|
563 | + $thread_buttons['bann']['link'] = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/moderate.php?forum='.$forum_id.'&uid='.$this->getVar('uid'); |
|
564 | 564 | $thread_buttons['bann']['name'] = _MD_NEWBB_SUSPEND_MANAGEMENT; |
565 | 565 | } |
566 | 566 | |
@@ -573,10 +573,10 @@ discard block |
||
573 | 573 | |
574 | 574 | if ($edit_ok) { |
575 | 575 | $thread_buttons['edit']['image'] = newbbDisplayImage('p_edit', _EDIT); |
576 | - $thread_buttons['edit']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}"; |
|
576 | + $thread_buttons['edit']['link'] = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/edit.php?{$page_query}"; |
|
577 | 577 | $thread_buttons['edit']['name'] = _EDIT; |
578 | 578 | $mod_buttons['edit']['image'] = newbbDisplayImage('p_edit', _EDIT); |
579 | - $mod_buttons['edit']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}"; |
|
579 | + $mod_buttons['edit']['link'] = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/edit.php?{$page_query}"; |
|
580 | 580 | $mod_buttons['edit']['name'] = _EDIT; |
581 | 581 | } |
582 | 582 | } |
@@ -586,55 +586,55 @@ discard block |
||
586 | 586 | |
587 | 587 | if ($delete_ok) { |
588 | 588 | $thread_buttons['delete']['image'] = newbbDisplayImage('p_delete', _DELETE); |
589 | - $thread_buttons['delete']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}"; |
|
589 | + $thread_buttons['delete']['link'] = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/delete.php?{$page_query}"; |
|
590 | 590 | $thread_buttons['delete']['name'] = _DELETE; |
591 | 591 | $mod_buttons['delete']['image'] = newbbDisplayImage('p_delete', _DELETE); |
592 | - $mod_buttons['delete']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}"; |
|
592 | + $mod_buttons['delete']['link'] = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/delete.php?{$page_query}"; |
|
593 | 593 | $mod_buttons['delete']['name'] = _DELETE; |
594 | 594 | } |
595 | 595 | } |
596 | 596 | if ($topicHandler->getPermission($forum_id, $topic_status, 'reply')) { |
597 | 597 | $thread_buttons['reply']['image'] = newbbDisplayImage('p_reply', _MD_NEWBB_REPLY); |
598 | - $thread_buttons['reply']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}"; |
|
598 | + $thread_buttons['reply']['link'] = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/reply.php?{$page_query}"; |
|
599 | 599 | $thread_buttons['reply']['name'] = _MD_NEWBB_REPLY; |
600 | 600 | |
601 | 601 | $thread_buttons['quote']['image'] = newbbDisplayImage('p_quote', _MD_NEWBB_QUOTE); |
602 | - $thread_buttons['quote']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}&quotedac=1"; |
|
602 | + $thread_buttons['quote']['link'] = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/reply.php?{$page_query}&quotedac=1"; |
|
603 | 603 | $thread_buttons['quote']['name'] = _MD_NEWBB_QUOTE; |
604 | 604 | } |
605 | 605 | } else { |
606 | 606 | $mod_buttons['edit']['image'] = newbbDisplayImage('p_edit', _EDIT); |
607 | - $mod_buttons['edit']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/edit.php?{$page_query}"; |
|
607 | + $mod_buttons['edit']['link'] = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/edit.php?{$page_query}"; |
|
608 | 608 | $mod_buttons['edit']['name'] = _EDIT; |
609 | 609 | |
610 | 610 | $mod_buttons['delete']['image'] = newbbDisplayImage('p_delete', _DELETE); |
611 | - $mod_buttons['delete']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/delete.php?{$page_query}"; |
|
611 | + $mod_buttons['delete']['link'] = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/delete.php?{$page_query}"; |
|
612 | 612 | $mod_buttons['delete']['name'] = _DELETE; |
613 | 613 | |
614 | 614 | $thread_buttons['reply']['image'] = newbbDisplayImage('p_reply', _MD_NEWBB_REPLY); |
615 | - $thread_buttons['reply']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/reply.php?{$page_query}"; |
|
615 | + $thread_buttons['reply']['link'] = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/reply.php?{$page_query}"; |
|
616 | 616 | $thread_buttons['reply']['name'] = _MD_NEWBB_REPLY; |
617 | 617 | } |
618 | 618 | |
619 | 619 | if (!$isAdmin && $GLOBALS['xoopsModuleConfig']['reportmod_enabled']) { |
620 | 620 | $thread_buttons['report']['image'] = newbbDisplayImage('p_report', _MD_NEWBB_REPORT); |
621 | - $thread_buttons['report']['link'] = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . "/report.php?{$page_query}"; |
|
621 | + $thread_buttons['report']['link'] = XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname')."/report.php?{$page_query}"; |
|
622 | 622 | $thread_buttons['report']['name'] = _MD_NEWBB_REPORT; |
623 | 623 | } |
624 | 624 | |
625 | 625 | $thread_action = []; |
626 | 626 | // irmtfan add pdf permission |
627 | - if (file_exists(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php') |
|
627 | + if (file_exists(XOOPS_ROOT_PATH.'/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php') |
|
628 | 628 | && $topicHandler->getPermission($forum_id, $topic_status, 'pdf')) { |
629 | 629 | $thread_action['pdf']['image'] = newbbDisplayImage('pdf', _MD_NEWBB_PDF); |
630 | - $thread_action['pdf']['link'] = XOOPS_URL . '/modules/newbb/makepdf.php?type=post&pageid=0'; |
|
630 | + $thread_action['pdf']['link'] = XOOPS_URL.'/modules/newbb/makepdf.php?type=post&pageid=0'; |
|
631 | 631 | $thread_action['pdf']['name'] = _MD_NEWBB_PDF; |
632 | 632 | $thread_action['pdf']['target'] = '_blank'; |
633 | 633 | } |
634 | 634 | // irmtfan add print permission |
635 | 635 | if ($topicHandler->getPermission($forum_id, $topic_status, 'print')) { |
636 | 636 | $thread_action['print']['image'] = newbbDisplayImage('printer', _MD_NEWBB_PRINT); |
637 | - $thread_action['print']['link'] = XOOPS_URL . '/modules/newbb/print.php?form=2&forum=' . $forum_id . '&topic_id=' . $topic_id; |
|
637 | + $thread_action['print']['link'] = XOOPS_URL.'/modules/newbb/print.php?form=2&forum='.$forum_id.'&topic_id='.$topic_id; |
|
638 | 638 | $thread_action['print']['name'] = _MD_NEWBB_PRINT; |
639 | 639 | $thread_action['print']['target'] = '_blank'; |
640 | 640 | } |
@@ -642,45 +642,45 @@ discard block |
||
642 | 642 | if ($GLOBALS['xoopsModuleConfig']['show_sociallinks']) { |
643 | 643 | $full_title = $this->getVar('subject'); |
644 | 644 | $clean_title = preg_replace('/[^A-Za-z0-9-]+/', '+', $this->getVar('subject')); |
645 | - $full_link = XOOPS_URL . '/modules/newbb/viewtopic.php?post_id=' . $post_id; |
|
645 | + $full_link = XOOPS_URL.'/modules/newbb/viewtopic.php?post_id='.$post_id; |
|
646 | 646 | |
647 | 647 | $thread_action['social_twitter']['image'] = newbbDisplayImage('twitter', _MD_NEWBB_SHARE_TWITTER); |
648 | - $thread_action['social_twitter']['link'] = 'http://twitter.com/share?text=' . $clean_title . '&url=' . $full_link; |
|
648 | + $thread_action['social_twitter']['link'] = 'http://twitter.com/share?text='.$clean_title.'&url='.$full_link; |
|
649 | 649 | $thread_action['social_twitter']['name'] = _MD_NEWBB_SHARE_TWITTER; |
650 | 650 | $thread_action['social_twitter']['target'] = '_blank'; |
651 | 651 | |
652 | 652 | $thread_action['social_facebook']['image'] = newbbDisplayImage('facebook', _MD_NEWBB_SHARE_FACEBOOK); |
653 | - $thread_action['social_facebook']['link'] = 'http://www.facebook.com/sharer.php?u=' . $full_link; |
|
653 | + $thread_action['social_facebook']['link'] = 'http://www.facebook.com/sharer.php?u='.$full_link; |
|
654 | 654 | $thread_action['social_facebook']['name'] = _MD_NEWBB_SHARE_FACEBOOK; |
655 | 655 | $thread_action['social_facebook']['target'] = '_blank'; |
656 | 656 | |
657 | 657 | $thread_action['social_gplus']['image'] = newbbDisplayImage('googleplus', _MD_NEWBB_SHARE_GOOGLEPLUS); |
658 | - $thread_action['social_gplus']['link'] = 'https://plusone.google.com/_/+1/confirm?hl=en&url=' . $full_link; |
|
658 | + $thread_action['social_gplus']['link'] = 'https://plusone.google.com/_/+1/confirm?hl=en&url='.$full_link; |
|
659 | 659 | $thread_action['social_gplus']['name'] = _MD_NEWBB_SHARE_GOOGLEPLUS; |
660 | 660 | $thread_action['social_gplus']['target'] = '_blank'; |
661 | 661 | |
662 | 662 | $thread_action['social_linkedin']['image'] = newbbDisplayImage('linkedin', _MD_NEWBB_SHARE_LINKEDIN); |
663 | - $thread_action['social_linkedin']['link'] = 'http://www.linkedin.com/shareArticle?mini=true&title=' . $full_title . '&url=' . $full_link; |
|
663 | + $thread_action['social_linkedin']['link'] = 'http://www.linkedin.com/shareArticle?mini=true&title='.$full_title.'&url='.$full_link; |
|
664 | 664 | $thread_action['social_linkedin']['name'] = _MD_NEWBB_SHARE_LINKEDIN; |
665 | 665 | $thread_action['social_linkedin']['target'] = '_blank'; |
666 | 666 | |
667 | 667 | $thread_action['social_delicious']['image'] = newbbDisplayImage('delicious', _MD_NEWBB_SHARE_DELICIOUS); |
668 | - $thread_action['social_delicious']['link'] = 'http://del.icio.us/post?title=' . $full_title . '&url=' . $full_link; |
|
668 | + $thread_action['social_delicious']['link'] = 'http://del.icio.us/post?title='.$full_title.'&url='.$full_link; |
|
669 | 669 | $thread_action['social_delicious']['name'] = _MD_NEWBB_SHARE_DELICIOUS; |
670 | 670 | $thread_action['social_delicious']['target'] = '_blank'; |
671 | 671 | |
672 | 672 | $thread_action['social_digg']['image'] = newbbDisplayImage('digg', _MD_NEWBB_SHARE_DIGG); |
673 | - $thread_action['social_digg']['link'] = 'http://digg.com/submit?phase=2&title=' . $full_title . '&url=' . $full_link; |
|
673 | + $thread_action['social_digg']['link'] = 'http://digg.com/submit?phase=2&title='.$full_title.'&url='.$full_link; |
|
674 | 674 | $thread_action['social_digg']['name'] = _MD_NEWBB_SHARE_DIGG; |
675 | 675 | $thread_action['social_digg']['target'] = '_blank'; |
676 | 676 | |
677 | 677 | $thread_action['social_reddit']['image'] = newbbDisplayImage('reddit', _MD_NEWBB_SHARE_REDDIT); |
678 | - $thread_action['social_reddit']['link'] = 'http://reddit.com/submit?title=' . $full_title . '&url=' . $full_link; |
|
678 | + $thread_action['social_reddit']['link'] = 'http://reddit.com/submit?title='.$full_title.'&url='.$full_link; |
|
679 | 679 | $thread_action['social_reddit']['name'] = _MD_NEWBB_SHARE_REDDIT; |
680 | 680 | $thread_action['social_reddit']['target'] = '_blank'; |
681 | 681 | |
682 | 682 | $thread_action['social_wong']['image'] = newbbDisplayImage('wong', _MD_NEWBB_SHARE_MRWONG); |
683 | - $thread_action['social_wong']['link'] = 'http://www.mister-wong.de/index.php?action=addurl&bm_url=' . $full_link; |
|
683 | + $thread_action['social_wong']['link'] = 'http://www.mister-wong.de/index.php?action=addurl&bm_url='.$full_link; |
|
684 | 684 | $thread_action['social_wong']['name'] = _MD_NEWBB_SHARE_MRWONG; |
685 | 685 | $thread_action['social_wong']['target'] = '_blank'; |
686 | 686 | } |
@@ -704,7 +704,7 @@ discard block |
||
704 | 704 | 'thread_buttons' => $thread_buttons, |
705 | 705 | 'mod_buttons' => $mod_buttons, |
706 | 706 | 'poster' => $poster, |
707 | - 'post_permalink' => '<a href="' . XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?post_id=' . $post_id . '"></a>' |
|
707 | + 'post_permalink' => '<a href="'.XOOPS_URL.'/modules/'.$xoopsModule->getVar('dirname').'/viewtopic.php?post_id='.$post_id.'"></a>' |
|
708 | 708 | ]; |
709 | 709 | |
710 | 710 | unset($thread_buttons, $mod_buttons, $eachposter); |
@@ -41,555 +41,555 @@ |
||
41 | 41 | */ |
42 | 42 | class PostHandler extends \XoopsPersistableObjectHandler |
43 | 43 | { |
44 | - /** |
|
45 | - * @param \XoopsDatabase $db |
|
46 | - */ |
|
47 | - public function __construct(\XoopsDatabase $db) |
|
48 | - { |
|
49 | - parent::__construct($db, 'newbb_posts', Post::class, 'post_id', 'subject'); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @param mixed $id |
|
54 | - * @param null $var |
|
55 | - * @return null|\XoopsObject |
|
56 | - */ |
|
57 | - public function get($id = null, $var = null) //get($id) |
|
58 | - { |
|
59 | - $id = (int)$id; |
|
60 | - $post = null; |
|
61 | - $sql = 'SELECT p.*, t.* FROM ' . $this->db->prefix('newbb_posts') . ' p LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' t ON p.post_id=t.post_id WHERE p.post_id=' . $id; |
|
62 | - if ($array = $this->db->fetchArray($this->db->query($sql))) { |
|
63 | - $post = $this->create(false); |
|
64 | - $post->assignVars($array); |
|
65 | - } |
|
66 | - |
|
67 | - return $post; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @param int $limit |
|
72 | - * @param int $start |
|
73 | - * @param \CriteriaElement $criteria |
|
74 | - * @param null $fields |
|
75 | - * @param bool $asObject |
|
76 | - * @param int $topic_id |
|
77 | - * @param int $approved |
|
78 | - * @return array |
|
79 | - */ |
|
80 | - // public function getByLimit($topic_id, $limit, $approved = 1) |
|
81 | - public function &getByLimit( |
|
82 | - $limit = 0, |
|
83 | - $start = 0, |
|
84 | - \CriteriaElement $criteria = null, |
|
85 | - $fields = null, |
|
86 | - $asObject = true, |
|
87 | - $topic_id = 0, |
|
88 | - $approved = 1 |
|
89 | - ) { |
|
90 | - $sql = 'SELECT p.*, t.*, tp.topic_status FROM ' |
|
91 | - . $this->db->prefix('newbb_posts') |
|
92 | - . ' p LEFT JOIN ' |
|
93 | - . $this->db->prefix('newbb_posts_text') |
|
94 | - . ' t ON p.post_id=t.post_id LEFT JOIN ' |
|
95 | - . $this->db->prefix('newbb_topics') |
|
96 | - . ' tp ON tp.topic_id=p.topic_id WHERE p.topic_id=' |
|
97 | - . $topic_id |
|
98 | - . ' AND p.approved =' |
|
99 | - . $approved |
|
100 | - . ' ORDER BY p.post_time DESC'; |
|
101 | - $result = $this->db->query($sql, $limit, 0); |
|
102 | - $ret = []; |
|
103 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
104 | - $post = $this->create(false); |
|
105 | - $post->assignVars($myrow); |
|
106 | - |
|
107 | - $ret[$myrow['post_id']] = $post; |
|
108 | - unset($post); |
|
109 | - } |
|
110 | - |
|
111 | - return $ret; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @param Post $post |
|
116 | - * @return mixed |
|
117 | - */ |
|
118 | - public function getPostForPDF(&$post) |
|
119 | - { |
|
120 | - return $post->getPostBody(true); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * @param Post $post |
|
125 | - * @return mixed |
|
126 | - */ |
|
127 | - public function getPostForPrint(&$post) |
|
128 | - { |
|
129 | - return $post->getPostBody(); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @param int|Post|\XoopsObject $post |
|
134 | - * @param bool $force |
|
135 | - * @return bool |
|
136 | - */ |
|
137 | - public function approve(&$post, $force = false) |
|
138 | - { |
|
139 | - if (empty($post)) { |
|
140 | - return false; |
|
141 | - } |
|
142 | - if (is_numeric($post)) { |
|
143 | - $post = $this->get($post); |
|
144 | - } |
|
145 | - |
|
146 | - $wasApproved = $post->getVar('approved'); |
|
147 | - // irmtfan approve post if the approved = 0 (pending) or -1 (deleted) |
|
148 | - if (empty($force) && $wasApproved > 0) { |
|
149 | - return true; |
|
150 | - } |
|
151 | - $post->setVar('approved', 1); |
|
152 | - $this->insert($post, true); |
|
153 | - |
|
154 | - /** @var Newbb\TopicHandler $topicHandler */ |
|
155 | - $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
156 | - $topicObject = $topicHandler->get($post->getVar('topic_id')); |
|
157 | - if ($topicObject->getVar('topic_last_post_id') < $post->getVar('post_id')) { |
|
158 | - $topicObject->setVar('topic_last_post_id', $post->getVar('post_id')); |
|
159 | - } |
|
160 | - if ($post->isTopic()) { |
|
161 | - $topicObject->setVar('approved', 1); |
|
162 | - } else { |
|
163 | - $topicObject->setVar('topic_replies', $topicObject->getVar('topic_replies') + 1); |
|
164 | - } |
|
165 | - $topicHandler->insert($topicObject, true); |
|
166 | - |
|
167 | - /** @var Newbb\ForumHandler $forumHandler */ |
|
168 | - $forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
169 | - $forumObject = $forumHandler->get($post->getVar('forum_id')); |
|
170 | - if ($forumObject->getVar('forum_last_post_id') < $post->getVar('post_id')) { |
|
171 | - $forumObject->setVar('forum_last_post_id', $post->getVar('post_id')); |
|
172 | - } |
|
173 | - $forumObject->setVar('forum_posts', $forumObject->getVar('forum_posts') + 1); |
|
174 | - if ($post->isTopic()) { |
|
175 | - $forumObject->setVar('forum_topics', $forumObject->getVar('forum_topics') + 1); |
|
176 | - } |
|
177 | - $forumHandler->insert($forumObject, true); |
|
178 | - |
|
179 | - // Update user stats |
|
180 | - if ($post->getVar('uid') > 0) { |
|
181 | - /** @var \XoopsMemberHandler $memberHandler */ |
|
182 | - $memberHandler = xoops_getHandler('member'); |
|
183 | - $poster = $memberHandler->getUser($post->getVar('uid')); |
|
184 | - if (is_object($poster) && $post->getVar('uid') == $poster->getVar('uid')) { |
|
185 | - $poster->setVar('posts', $poster->getVar('posts') + 1); |
|
186 | - $res = $memberHandler->insertUser($poster, true); |
|
187 | - unset($poster); |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - // Update forum stats |
|
192 | - /** @var StatsHandler $statsHandler */ |
|
193 | - $statsHandler = Newbb\Helper::getInstance()->getHandler('Stats'); |
|
194 | - $statsHandler->update($post->getVar('forum_id'), 'post'); |
|
195 | - if ($post->isTopic()) { |
|
196 | - $statsHandler->update($post->getVar('forum_id'), 'topic'); |
|
197 | - } |
|
198 | - |
|
199 | - return true; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * @param \XoopsObject $post |
|
204 | - * @param bool $force |
|
205 | - * @return bool |
|
206 | - */ |
|
207 | - public function insert(\XoopsObject $post, $force = true) //insert(&$post, $force = true) |
|
208 | - { |
|
209 | - $topicObject = null; |
|
210 | - // Set the post time |
|
211 | - // The time should be "publish" time. To be adjusted later |
|
212 | - if (!$post->getVar('post_time')) { |
|
213 | - $post->setVar('post_time', time()); |
|
214 | - } |
|
215 | - |
|
216 | - /** @var Newbb\TopicHandler $topicHandler */ |
|
217 | - $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
218 | - // Verify the topic ID |
|
219 | - if ($topic_id = $post->getVar('topic_id')) { |
|
220 | - $topicObject = $topicHandler->get($topic_id); |
|
221 | - // Invalid topic OR the topic is no approved and the post is not top post |
|
222 | - if (!$topicObject// || (!$post->isTopic() && $topicObject->getVar("approved") < 1) |
|
223 | - ) { |
|
224 | - return false; |
|
225 | - } |
|
226 | - } |
|
227 | - if (empty($topic_id)) { |
|
228 | - $post->setVar('topic_id', 0); |
|
229 | - $post->setVar('pid', 0); |
|
230 | - $post->setNew(); |
|
231 | - $topicObject = $topicHandler->create(); |
|
232 | - } |
|
233 | - $textHandler = Newbb\Helper::getInstance()->getHandler('Text'); |
|
234 | - $post_text_vars = ['post_text', 'post_edit', 'dohtml', 'doxcode', 'dosmiley', 'doimage', 'dobr']; |
|
235 | - if ($post->isNew()) { |
|
236 | - if (!$topic_id = $post->getVar('topic_id')) { |
|
237 | - $topicObject->setVar('topic_title', $post->getVar('subject', 'n')); |
|
238 | - $topicObject->setVar('topic_poster', $post->getVar('uid')); |
|
239 | - $topicObject->setVar('forum_id', $post->getVar('forum_id')); |
|
240 | - $topicObject->setVar('topic_time', $post->getVar('post_time')); |
|
241 | - $topicObject->setVar('poster_name', $post->getVar('poster_name')); |
|
242 | - $topicObject->setVar('approved', $post->getVar('approved')); |
|
243 | - |
|
244 | - if (!$topic_id = $topicHandler->insert($topicObject, $force)) { |
|
245 | - $post->deleteAttachment(); |
|
246 | - $post->setErrors('insert topic error'); |
|
247 | - |
|
248 | - //xoops_error($topicObject->getErrors()); |
|
249 | - return false; |
|
250 | - } |
|
251 | - $post->setVar('topic_id', $topic_id); |
|
252 | - |
|
253 | - $pid = 0; |
|
254 | - $post->setVar('pid', 0); |
|
255 | - } elseif (!$post->getVar('pid')) { |
|
256 | - $pid = $topicHandler->getTopPostId($topic_id); |
|
257 | - $post->setVar('pid', $pid); |
|
258 | - } |
|
259 | - |
|
260 | - $textObject = $textHandler->create(); |
|
261 | - foreach ($post_text_vars as $key) { |
|
262 | - $textObject->vars[$key] = $post->vars[$key]; |
|
263 | - } |
|
264 | - $post->destroyVars($post_text_vars); |
|
265 | - |
|
266 | - // if (!$post_id = parent::insert($post, $force)) { |
|
267 | - // return false; |
|
268 | - // } |
|
269 | - |
|
270 | - if (!$post_id = parent::insert($post, $force)) { |
|
271 | - return false; |
|
272 | - } else { |
|
273 | - $post->unsetNew(); |
|
274 | - } |
|
275 | - |
|
276 | - $textObject->setVar('post_id', $post_id); |
|
277 | - if (!$textHandler->insert($textObject, $force)) { |
|
278 | - $this->delete($post); |
|
279 | - $post->setErrors('post text insert error'); |
|
280 | - |
|
281 | - //xoops_error($textObject->getErrors()); |
|
282 | - return false; |
|
283 | - } |
|
284 | - if ($post->getVar('approved') > 0) { |
|
285 | - $this->approve($post, true); |
|
286 | - } |
|
287 | - $post->setVar('post_id', $post_id); |
|
288 | - } else { |
|
289 | - if ($post->isTopic()) { |
|
290 | - if ($post->getVar('subject') !== $topicObject->getVar('topic_title')) { |
|
291 | - $topicObject->setVar('topic_title', $post->getVar('subject', 'n')); |
|
292 | - } |
|
293 | - if ($post->getVar('approved') !== $topicObject->getVar('approved')) { |
|
294 | - $topicObject->setVar('approved', $post->getVar('approved')); |
|
295 | - } |
|
296 | - $topicObject->setDirty(); |
|
297 | - if (!$result = $topicHandler->insert($topicObject, $force)) { |
|
298 | - $post->setErrors('update topic error'); |
|
299 | - |
|
300 | - //xoops_error($topicObject->getErrors()); |
|
301 | - return false; |
|
302 | - } |
|
303 | - } |
|
304 | - $textObject = $textHandler->get($post->getVar('post_id')); |
|
305 | - $textObject->setDirty(); |
|
306 | - foreach ($post_text_vars as $key) { |
|
307 | - $textObject->vars[$key] = $post->vars[$key]; |
|
308 | - } |
|
309 | - $post->destroyVars($post_text_vars); |
|
310 | - if (!$post_id = parent::insert($post, $force)) { |
|
311 | - //xoops_error($post->getErrors()); |
|
312 | - return false; |
|
313 | - } else { |
|
314 | - $post->unsetNew(); |
|
315 | - } |
|
316 | - if (!$textHandler->insert($textObject, $force)) { |
|
317 | - $post->setErrors('update post text error'); |
|
318 | - |
|
319 | - //xoops_error($textObject->getErrors()); |
|
320 | - return false; |
|
321 | - } |
|
322 | - } |
|
323 | - |
|
324 | - return $post->getVar('post_id'); |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * @param \XoopsObject|Post $post |
|
329 | - * @param bool $isDeleteOne |
|
330 | - * @param bool $force |
|
331 | - * @return bool |
|
332 | - */ |
|
333 | - public function delete(\XoopsObject $post, $isDeleteOne = true, $force = false) |
|
334 | - { |
|
335 | - if (!is_object($post) || 0 == $post->getVar('post_id')) { |
|
336 | - return false; |
|
337 | - } |
|
338 | - |
|
339 | - if ($isDeleteOne) { |
|
340 | - if ($post->isTopic()) { |
|
341 | - $criteria = new \CriteriaCompo(new \Criteria('topic_id', $post->getVar('topic_id'))); |
|
342 | - $criteria->add(new \Criteria('approved', 1)); |
|
343 | - $criteria->add(new \Criteria('pid', 0, '>')); |
|
344 | - if ($this->getPostCount($criteria) > 0) { |
|
345 | - return false; |
|
346 | - } |
|
347 | - } |
|
348 | - |
|
349 | - return $this->myDelete($post, $force); |
|
350 | - } else { |
|
351 | - require_once $GLOBALS['xoops']->path('class/xoopstree.php'); |
|
352 | - $mytree = new \XoopsTree($this->db->prefix('newbb_posts'), 'post_id', 'pid'); |
|
353 | - $arr = $mytree->getAllChild($post->getVar('post_id')); |
|
354 | - // irmtfan - delete childs in a reverse order |
|
355 | - for ($i = count($arr) - 1; $i >= 0; $i--) { |
|
356 | - $childpost = $this->create(false); |
|
357 | - $childpost->assignVars($arr[$i]); |
|
358 | - $this->myDelete($childpost, $force); |
|
359 | - unset($childpost); |
|
360 | - } |
|
361 | - $this->myDelete($post, $force); |
|
362 | - } |
|
363 | - |
|
364 | - return true; |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * @param Post|\XoopsObject $post |
|
369 | - * @param bool $force |
|
370 | - * @return bool |
|
371 | - */ |
|
372 | - public function myDelete(Post $post, $force = false) |
|
373 | - { |
|
374 | - global $xoopsModule; |
|
375 | - |
|
376 | - if (!is_object($post) || 0 == $post->getVar('post_id')) { |
|
377 | - return false; |
|
378 | - } |
|
379 | - |
|
380 | - /* Set active post as deleted */ |
|
381 | - if ($post->getVar('approved') > 0 && empty($force)) { |
|
382 | - $sql = 'UPDATE ' . $this->db->prefix('newbb_posts') . ' SET approved = -1 WHERE post_id = ' . $post->getVar('post_id'); |
|
383 | - if (!$result = $this->db->queryF($sql)) { |
|
384 | - } |
|
385 | - /* delete pending post directly */ |
|
386 | - } else { |
|
387 | - $sql = sprintf('DELETE FROM `%s` WHERE post_id = %u', $this->db->prefix('newbb_posts'), $post->getVar('post_id')); |
|
388 | - if (!$result = $this->db->queryF($sql)) { |
|
389 | - $post->setErrors('delete post error: ' . $sql); |
|
390 | - |
|
391 | - return false; |
|
392 | - } |
|
393 | - $post->deleteAttachment(); |
|
394 | - |
|
395 | - $sql = sprintf('DELETE FROM `%s` WHERE post_id = %u', $this->db->prefix('newbb_posts_text'), $post->getVar('post_id')); |
|
396 | - if (!$result = $this->db->queryF($sql)) { |
|
397 | - $post->setErrors('Could not remove post text: ' . $sql); |
|
398 | - |
|
399 | - return false; |
|
400 | - } |
|
401 | - } |
|
402 | - |
|
403 | - if ($post->isTopic()) { |
|
404 | - $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
405 | - /** @var Topic $topicObject */ |
|
406 | - $topicObject = $topicHandler->get($post->getVar('topic_id')); |
|
407 | - if (is_object($topicObject) && $topicObject->getVar('approved') > 0 && empty($force)) { |
|
408 | - $topiccount_toupdate = 1; |
|
409 | - $topicObject->setVar('approved', -1); |
|
410 | - $topicHandler->insert($topicObject); |
|
411 | - xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'thread', $post->getVar('topic_id')); |
|
412 | - } else { |
|
413 | - if (is_object($topicObject)) { |
|
414 | - if ($topicObject->getVar('approved') > 0) { |
|
415 | - xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'thread', $post->getVar('topic_id')); |
|
416 | - } |
|
417 | - |
|
418 | - $poll_id = $topicObject->getVar('poll_id'); |
|
419 | - // START irmtfan poll_module |
|
420 | - $topicObject->deletePoll($poll_id); |
|
421 | - // END irmtfan poll_module |
|
422 | - } |
|
423 | - |
|
424 | - $sql = sprintf('DELETE FROM `%s` WHERE topic_id = %u', $this->db->prefix('newbb_topics'), $post->getVar('topic_id')); |
|
425 | - if (!$result = $this->db->queryF($sql)) { |
|
426 | - //xoops_error($this->db->error()); |
|
427 | - } |
|
428 | - $sql = sprintf('DELETE FROM `%s` WHERE topic_id = %u', $this->db->prefix('newbb_votedata'), $post->getVar('topic_id')); |
|
429 | - if (!$result = $this->db->queryF($sql)) { |
|
430 | - //xoops_error($this->db->error()); |
|
431 | - } |
|
432 | - } |
|
433 | - } else { |
|
434 | - $sql = 'UPDATE ' . $this->db->prefix('newbb_topics') . ' t |
|
44 | + /** |
|
45 | + * @param \XoopsDatabase $db |
|
46 | + */ |
|
47 | + public function __construct(\XoopsDatabase $db) |
|
48 | + { |
|
49 | + parent::__construct($db, 'newbb_posts', Post::class, 'post_id', 'subject'); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @param mixed $id |
|
54 | + * @param null $var |
|
55 | + * @return null|\XoopsObject |
|
56 | + */ |
|
57 | + public function get($id = null, $var = null) //get($id) |
|
58 | + { |
|
59 | + $id = (int)$id; |
|
60 | + $post = null; |
|
61 | + $sql = 'SELECT p.*, t.* FROM ' . $this->db->prefix('newbb_posts') . ' p LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' t ON p.post_id=t.post_id WHERE p.post_id=' . $id; |
|
62 | + if ($array = $this->db->fetchArray($this->db->query($sql))) { |
|
63 | + $post = $this->create(false); |
|
64 | + $post->assignVars($array); |
|
65 | + } |
|
66 | + |
|
67 | + return $post; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @param int $limit |
|
72 | + * @param int $start |
|
73 | + * @param \CriteriaElement $criteria |
|
74 | + * @param null $fields |
|
75 | + * @param bool $asObject |
|
76 | + * @param int $topic_id |
|
77 | + * @param int $approved |
|
78 | + * @return array |
|
79 | + */ |
|
80 | + // public function getByLimit($topic_id, $limit, $approved = 1) |
|
81 | + public function &getByLimit( |
|
82 | + $limit = 0, |
|
83 | + $start = 0, |
|
84 | + \CriteriaElement $criteria = null, |
|
85 | + $fields = null, |
|
86 | + $asObject = true, |
|
87 | + $topic_id = 0, |
|
88 | + $approved = 1 |
|
89 | + ) { |
|
90 | + $sql = 'SELECT p.*, t.*, tp.topic_status FROM ' |
|
91 | + . $this->db->prefix('newbb_posts') |
|
92 | + . ' p LEFT JOIN ' |
|
93 | + . $this->db->prefix('newbb_posts_text') |
|
94 | + . ' t ON p.post_id=t.post_id LEFT JOIN ' |
|
95 | + . $this->db->prefix('newbb_topics') |
|
96 | + . ' tp ON tp.topic_id=p.topic_id WHERE p.topic_id=' |
|
97 | + . $topic_id |
|
98 | + . ' AND p.approved =' |
|
99 | + . $approved |
|
100 | + . ' ORDER BY p.post_time DESC'; |
|
101 | + $result = $this->db->query($sql, $limit, 0); |
|
102 | + $ret = []; |
|
103 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
104 | + $post = $this->create(false); |
|
105 | + $post->assignVars($myrow); |
|
106 | + |
|
107 | + $ret[$myrow['post_id']] = $post; |
|
108 | + unset($post); |
|
109 | + } |
|
110 | + |
|
111 | + return $ret; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @param Post $post |
|
116 | + * @return mixed |
|
117 | + */ |
|
118 | + public function getPostForPDF(&$post) |
|
119 | + { |
|
120 | + return $post->getPostBody(true); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * @param Post $post |
|
125 | + * @return mixed |
|
126 | + */ |
|
127 | + public function getPostForPrint(&$post) |
|
128 | + { |
|
129 | + return $post->getPostBody(); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @param int|Post|\XoopsObject $post |
|
134 | + * @param bool $force |
|
135 | + * @return bool |
|
136 | + */ |
|
137 | + public function approve(&$post, $force = false) |
|
138 | + { |
|
139 | + if (empty($post)) { |
|
140 | + return false; |
|
141 | + } |
|
142 | + if (is_numeric($post)) { |
|
143 | + $post = $this->get($post); |
|
144 | + } |
|
145 | + |
|
146 | + $wasApproved = $post->getVar('approved'); |
|
147 | + // irmtfan approve post if the approved = 0 (pending) or -1 (deleted) |
|
148 | + if (empty($force) && $wasApproved > 0) { |
|
149 | + return true; |
|
150 | + } |
|
151 | + $post->setVar('approved', 1); |
|
152 | + $this->insert($post, true); |
|
153 | + |
|
154 | + /** @var Newbb\TopicHandler $topicHandler */ |
|
155 | + $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
156 | + $topicObject = $topicHandler->get($post->getVar('topic_id')); |
|
157 | + if ($topicObject->getVar('topic_last_post_id') < $post->getVar('post_id')) { |
|
158 | + $topicObject->setVar('topic_last_post_id', $post->getVar('post_id')); |
|
159 | + } |
|
160 | + if ($post->isTopic()) { |
|
161 | + $topicObject->setVar('approved', 1); |
|
162 | + } else { |
|
163 | + $topicObject->setVar('topic_replies', $topicObject->getVar('topic_replies') + 1); |
|
164 | + } |
|
165 | + $topicHandler->insert($topicObject, true); |
|
166 | + |
|
167 | + /** @var Newbb\ForumHandler $forumHandler */ |
|
168 | + $forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
|
169 | + $forumObject = $forumHandler->get($post->getVar('forum_id')); |
|
170 | + if ($forumObject->getVar('forum_last_post_id') < $post->getVar('post_id')) { |
|
171 | + $forumObject->setVar('forum_last_post_id', $post->getVar('post_id')); |
|
172 | + } |
|
173 | + $forumObject->setVar('forum_posts', $forumObject->getVar('forum_posts') + 1); |
|
174 | + if ($post->isTopic()) { |
|
175 | + $forumObject->setVar('forum_topics', $forumObject->getVar('forum_topics') + 1); |
|
176 | + } |
|
177 | + $forumHandler->insert($forumObject, true); |
|
178 | + |
|
179 | + // Update user stats |
|
180 | + if ($post->getVar('uid') > 0) { |
|
181 | + /** @var \XoopsMemberHandler $memberHandler */ |
|
182 | + $memberHandler = xoops_getHandler('member'); |
|
183 | + $poster = $memberHandler->getUser($post->getVar('uid')); |
|
184 | + if (is_object($poster) && $post->getVar('uid') == $poster->getVar('uid')) { |
|
185 | + $poster->setVar('posts', $poster->getVar('posts') + 1); |
|
186 | + $res = $memberHandler->insertUser($poster, true); |
|
187 | + unset($poster); |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + // Update forum stats |
|
192 | + /** @var StatsHandler $statsHandler */ |
|
193 | + $statsHandler = Newbb\Helper::getInstance()->getHandler('Stats'); |
|
194 | + $statsHandler->update($post->getVar('forum_id'), 'post'); |
|
195 | + if ($post->isTopic()) { |
|
196 | + $statsHandler->update($post->getVar('forum_id'), 'topic'); |
|
197 | + } |
|
198 | + |
|
199 | + return true; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * @param \XoopsObject $post |
|
204 | + * @param bool $force |
|
205 | + * @return bool |
|
206 | + */ |
|
207 | + public function insert(\XoopsObject $post, $force = true) //insert(&$post, $force = true) |
|
208 | + { |
|
209 | + $topicObject = null; |
|
210 | + // Set the post time |
|
211 | + // The time should be "publish" time. To be adjusted later |
|
212 | + if (!$post->getVar('post_time')) { |
|
213 | + $post->setVar('post_time', time()); |
|
214 | + } |
|
215 | + |
|
216 | + /** @var Newbb\TopicHandler $topicHandler */ |
|
217 | + $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
218 | + // Verify the topic ID |
|
219 | + if ($topic_id = $post->getVar('topic_id')) { |
|
220 | + $topicObject = $topicHandler->get($topic_id); |
|
221 | + // Invalid topic OR the topic is no approved and the post is not top post |
|
222 | + if (!$topicObject// || (!$post->isTopic() && $topicObject->getVar("approved") < 1) |
|
223 | + ) { |
|
224 | + return false; |
|
225 | + } |
|
226 | + } |
|
227 | + if (empty($topic_id)) { |
|
228 | + $post->setVar('topic_id', 0); |
|
229 | + $post->setVar('pid', 0); |
|
230 | + $post->setNew(); |
|
231 | + $topicObject = $topicHandler->create(); |
|
232 | + } |
|
233 | + $textHandler = Newbb\Helper::getInstance()->getHandler('Text'); |
|
234 | + $post_text_vars = ['post_text', 'post_edit', 'dohtml', 'doxcode', 'dosmiley', 'doimage', 'dobr']; |
|
235 | + if ($post->isNew()) { |
|
236 | + if (!$topic_id = $post->getVar('topic_id')) { |
|
237 | + $topicObject->setVar('topic_title', $post->getVar('subject', 'n')); |
|
238 | + $topicObject->setVar('topic_poster', $post->getVar('uid')); |
|
239 | + $topicObject->setVar('forum_id', $post->getVar('forum_id')); |
|
240 | + $topicObject->setVar('topic_time', $post->getVar('post_time')); |
|
241 | + $topicObject->setVar('poster_name', $post->getVar('poster_name')); |
|
242 | + $topicObject->setVar('approved', $post->getVar('approved')); |
|
243 | + |
|
244 | + if (!$topic_id = $topicHandler->insert($topicObject, $force)) { |
|
245 | + $post->deleteAttachment(); |
|
246 | + $post->setErrors('insert topic error'); |
|
247 | + |
|
248 | + //xoops_error($topicObject->getErrors()); |
|
249 | + return false; |
|
250 | + } |
|
251 | + $post->setVar('topic_id', $topic_id); |
|
252 | + |
|
253 | + $pid = 0; |
|
254 | + $post->setVar('pid', 0); |
|
255 | + } elseif (!$post->getVar('pid')) { |
|
256 | + $pid = $topicHandler->getTopPostId($topic_id); |
|
257 | + $post->setVar('pid', $pid); |
|
258 | + } |
|
259 | + |
|
260 | + $textObject = $textHandler->create(); |
|
261 | + foreach ($post_text_vars as $key) { |
|
262 | + $textObject->vars[$key] = $post->vars[$key]; |
|
263 | + } |
|
264 | + $post->destroyVars($post_text_vars); |
|
265 | + |
|
266 | + // if (!$post_id = parent::insert($post, $force)) { |
|
267 | + // return false; |
|
268 | + // } |
|
269 | + |
|
270 | + if (!$post_id = parent::insert($post, $force)) { |
|
271 | + return false; |
|
272 | + } else { |
|
273 | + $post->unsetNew(); |
|
274 | + } |
|
275 | + |
|
276 | + $textObject->setVar('post_id', $post_id); |
|
277 | + if (!$textHandler->insert($textObject, $force)) { |
|
278 | + $this->delete($post); |
|
279 | + $post->setErrors('post text insert error'); |
|
280 | + |
|
281 | + //xoops_error($textObject->getErrors()); |
|
282 | + return false; |
|
283 | + } |
|
284 | + if ($post->getVar('approved') > 0) { |
|
285 | + $this->approve($post, true); |
|
286 | + } |
|
287 | + $post->setVar('post_id', $post_id); |
|
288 | + } else { |
|
289 | + if ($post->isTopic()) { |
|
290 | + if ($post->getVar('subject') !== $topicObject->getVar('topic_title')) { |
|
291 | + $topicObject->setVar('topic_title', $post->getVar('subject', 'n')); |
|
292 | + } |
|
293 | + if ($post->getVar('approved') !== $topicObject->getVar('approved')) { |
|
294 | + $topicObject->setVar('approved', $post->getVar('approved')); |
|
295 | + } |
|
296 | + $topicObject->setDirty(); |
|
297 | + if (!$result = $topicHandler->insert($topicObject, $force)) { |
|
298 | + $post->setErrors('update topic error'); |
|
299 | + |
|
300 | + //xoops_error($topicObject->getErrors()); |
|
301 | + return false; |
|
302 | + } |
|
303 | + } |
|
304 | + $textObject = $textHandler->get($post->getVar('post_id')); |
|
305 | + $textObject->setDirty(); |
|
306 | + foreach ($post_text_vars as $key) { |
|
307 | + $textObject->vars[$key] = $post->vars[$key]; |
|
308 | + } |
|
309 | + $post->destroyVars($post_text_vars); |
|
310 | + if (!$post_id = parent::insert($post, $force)) { |
|
311 | + //xoops_error($post->getErrors()); |
|
312 | + return false; |
|
313 | + } else { |
|
314 | + $post->unsetNew(); |
|
315 | + } |
|
316 | + if (!$textHandler->insert($textObject, $force)) { |
|
317 | + $post->setErrors('update post text error'); |
|
318 | + |
|
319 | + //xoops_error($textObject->getErrors()); |
|
320 | + return false; |
|
321 | + } |
|
322 | + } |
|
323 | + |
|
324 | + return $post->getVar('post_id'); |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * @param \XoopsObject|Post $post |
|
329 | + * @param bool $isDeleteOne |
|
330 | + * @param bool $force |
|
331 | + * @return bool |
|
332 | + */ |
|
333 | + public function delete(\XoopsObject $post, $isDeleteOne = true, $force = false) |
|
334 | + { |
|
335 | + if (!is_object($post) || 0 == $post->getVar('post_id')) { |
|
336 | + return false; |
|
337 | + } |
|
338 | + |
|
339 | + if ($isDeleteOne) { |
|
340 | + if ($post->isTopic()) { |
|
341 | + $criteria = new \CriteriaCompo(new \Criteria('topic_id', $post->getVar('topic_id'))); |
|
342 | + $criteria->add(new \Criteria('approved', 1)); |
|
343 | + $criteria->add(new \Criteria('pid', 0, '>')); |
|
344 | + if ($this->getPostCount($criteria) > 0) { |
|
345 | + return false; |
|
346 | + } |
|
347 | + } |
|
348 | + |
|
349 | + return $this->myDelete($post, $force); |
|
350 | + } else { |
|
351 | + require_once $GLOBALS['xoops']->path('class/xoopstree.php'); |
|
352 | + $mytree = new \XoopsTree($this->db->prefix('newbb_posts'), 'post_id', 'pid'); |
|
353 | + $arr = $mytree->getAllChild($post->getVar('post_id')); |
|
354 | + // irmtfan - delete childs in a reverse order |
|
355 | + for ($i = count($arr) - 1; $i >= 0; $i--) { |
|
356 | + $childpost = $this->create(false); |
|
357 | + $childpost->assignVars($arr[$i]); |
|
358 | + $this->myDelete($childpost, $force); |
|
359 | + unset($childpost); |
|
360 | + } |
|
361 | + $this->myDelete($post, $force); |
|
362 | + } |
|
363 | + |
|
364 | + return true; |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * @param Post|\XoopsObject $post |
|
369 | + * @param bool $force |
|
370 | + * @return bool |
|
371 | + */ |
|
372 | + public function myDelete(Post $post, $force = false) |
|
373 | + { |
|
374 | + global $xoopsModule; |
|
375 | + |
|
376 | + if (!is_object($post) || 0 == $post->getVar('post_id')) { |
|
377 | + return false; |
|
378 | + } |
|
379 | + |
|
380 | + /* Set active post as deleted */ |
|
381 | + if ($post->getVar('approved') > 0 && empty($force)) { |
|
382 | + $sql = 'UPDATE ' . $this->db->prefix('newbb_posts') . ' SET approved = -1 WHERE post_id = ' . $post->getVar('post_id'); |
|
383 | + if (!$result = $this->db->queryF($sql)) { |
|
384 | + } |
|
385 | + /* delete pending post directly */ |
|
386 | + } else { |
|
387 | + $sql = sprintf('DELETE FROM `%s` WHERE post_id = %u', $this->db->prefix('newbb_posts'), $post->getVar('post_id')); |
|
388 | + if (!$result = $this->db->queryF($sql)) { |
|
389 | + $post->setErrors('delete post error: ' . $sql); |
|
390 | + |
|
391 | + return false; |
|
392 | + } |
|
393 | + $post->deleteAttachment(); |
|
394 | + |
|
395 | + $sql = sprintf('DELETE FROM `%s` WHERE post_id = %u', $this->db->prefix('newbb_posts_text'), $post->getVar('post_id')); |
|
396 | + if (!$result = $this->db->queryF($sql)) { |
|
397 | + $post->setErrors('Could not remove post text: ' . $sql); |
|
398 | + |
|
399 | + return false; |
|
400 | + } |
|
401 | + } |
|
402 | + |
|
403 | + if ($post->isTopic()) { |
|
404 | + $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
|
405 | + /** @var Topic $topicObject */ |
|
406 | + $topicObject = $topicHandler->get($post->getVar('topic_id')); |
|
407 | + if (is_object($topicObject) && $topicObject->getVar('approved') > 0 && empty($force)) { |
|
408 | + $topiccount_toupdate = 1; |
|
409 | + $topicObject->setVar('approved', -1); |
|
410 | + $topicHandler->insert($topicObject); |
|
411 | + xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'thread', $post->getVar('topic_id')); |
|
412 | + } else { |
|
413 | + if (is_object($topicObject)) { |
|
414 | + if ($topicObject->getVar('approved') > 0) { |
|
415 | + xoops_notification_deletebyitem($xoopsModule->getVar('mid'), 'thread', $post->getVar('topic_id')); |
|
416 | + } |
|
417 | + |
|
418 | + $poll_id = $topicObject->getVar('poll_id'); |
|
419 | + // START irmtfan poll_module |
|
420 | + $topicObject->deletePoll($poll_id); |
|
421 | + // END irmtfan poll_module |
|
422 | + } |
|
423 | + |
|
424 | + $sql = sprintf('DELETE FROM `%s` WHERE topic_id = %u', $this->db->prefix('newbb_topics'), $post->getVar('topic_id')); |
|
425 | + if (!$result = $this->db->queryF($sql)) { |
|
426 | + //xoops_error($this->db->error()); |
|
427 | + } |
|
428 | + $sql = sprintf('DELETE FROM `%s` WHERE topic_id = %u', $this->db->prefix('newbb_votedata'), $post->getVar('topic_id')); |
|
429 | + if (!$result = $this->db->queryF($sql)) { |
|
430 | + //xoops_error($this->db->error()); |
|
431 | + } |
|
432 | + } |
|
433 | + } else { |
|
434 | + $sql = 'UPDATE ' . $this->db->prefix('newbb_topics') . ' t |
|
435 | 435 | LEFT JOIN ' . $this->db->prefix('newbb_posts') . ' p ON p.topic_id = t.topic_id |
436 | 436 | SET t.topic_last_post_id = p.post_id |
437 | 437 | WHERE t.topic_last_post_id = ' . $post->getVar('post_id') . ' |
438 | 438 | AND p.post_id = (SELECT MAX(post_id) FROM ' . $this->db->prefix('newbb_posts') . ' WHERE topic_id=t.topic_id)'; |
439 | - if (!$result = $this->db->queryF($sql)) { |
|
440 | - } |
|
441 | - } |
|
442 | - |
|
443 | - $postcount_toupdate = $post->getVar('approved'); |
|
444 | - |
|
445 | - if ($postcount_toupdate > 0) { |
|
446 | - |
|
447 | - // Update user stats |
|
448 | - if ($post->getVar('uid') > 0) { |
|
449 | - /** @var \XoopsMemberHandler $memberHandler */ |
|
450 | - $memberHandler = xoops_getHandler('member'); |
|
451 | - $poster = $memberHandler->getUser($post->getVar('uid')); |
|
452 | - if (is_object($poster) && $post->getVar('uid') == $poster->getVar('uid')) { |
|
453 | - $poster->setVar('posts', $poster->getVar('posts') - 1); |
|
454 | - $res = $memberHandler->insertUser($poster, true); |
|
455 | - unset($poster); |
|
456 | - } |
|
457 | - } |
|
458 | - // irmtfan - just update the pid for approved posts when the post is not topic (pid=0) |
|
459 | - if (!$post->isTopic()) { |
|
460 | - $sql = 'UPDATE ' . $this->db->prefix('newbb_posts') . ' SET pid = ' . $post->getVar('pid') . ' WHERE approved=1 AND pid=' . $post->getVar('post_id'); |
|
461 | - if (!$result = $this->db->queryF($sql)) { |
|
462 | - //xoops_error($this->db->error()); |
|
463 | - } |
|
464 | - } |
|
465 | - } |
|
466 | - |
|
467 | - return true; |
|
468 | - } |
|
469 | - |
|
470 | - // START irmtfan enhance getPostCount when there is join (read_mode = 2) |
|
471 | - |
|
472 | - /** |
|
473 | - * @param null $criteria |
|
474 | - * @param null $join |
|
475 | - * @return int|null |
|
476 | - */ |
|
477 | - public function getPostCount($criteria = null, $join = null) |
|
478 | - { |
|
479 | - // if not join get the count from XOOPS/class/model/stats as before |
|
480 | - if (empty($join)) { |
|
481 | - return parent::getCount($criteria); |
|
482 | - } |
|
483 | - |
|
484 | - $sql = 'SELECT COUNT(*) as count' . ' FROM ' . $this->db->prefix('newbb_posts') . ' AS p' . ' LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' AS t ON t.post_id = p.post_id'; |
|
485 | - // LEFT JOIN |
|
486 | - $sql .= $join; |
|
487 | - // WHERE |
|
488 | - if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
489 | - $sql .= ' ' . $criteria->renderWhere(); |
|
490 | - } |
|
491 | - if (!$result = $this->db->query($sql)) { |
|
492 | - //xoops_error($this->db->error().'<br>'.$sql); |
|
493 | - return null; |
|
494 | - } |
|
495 | - $myrow = $this->db->fetchArray($result); |
|
496 | - $count = $myrow['count']; |
|
497 | - |
|
498 | - return $count; |
|
499 | - } |
|
500 | - // END irmtfan enhance getPostCount when there is join (read_mode = 2) |
|
501 | - /* |
|
439 | + if (!$result = $this->db->queryF($sql)) { |
|
440 | + } |
|
441 | + } |
|
442 | + |
|
443 | + $postcount_toupdate = $post->getVar('approved'); |
|
444 | + |
|
445 | + if ($postcount_toupdate > 0) { |
|
446 | + |
|
447 | + // Update user stats |
|
448 | + if ($post->getVar('uid') > 0) { |
|
449 | + /** @var \XoopsMemberHandler $memberHandler */ |
|
450 | + $memberHandler = xoops_getHandler('member'); |
|
451 | + $poster = $memberHandler->getUser($post->getVar('uid')); |
|
452 | + if (is_object($poster) && $post->getVar('uid') == $poster->getVar('uid')) { |
|
453 | + $poster->setVar('posts', $poster->getVar('posts') - 1); |
|
454 | + $res = $memberHandler->insertUser($poster, true); |
|
455 | + unset($poster); |
|
456 | + } |
|
457 | + } |
|
458 | + // irmtfan - just update the pid for approved posts when the post is not topic (pid=0) |
|
459 | + if (!$post->isTopic()) { |
|
460 | + $sql = 'UPDATE ' . $this->db->prefix('newbb_posts') . ' SET pid = ' . $post->getVar('pid') . ' WHERE approved=1 AND pid=' . $post->getVar('post_id'); |
|
461 | + if (!$result = $this->db->queryF($sql)) { |
|
462 | + //xoops_error($this->db->error()); |
|
463 | + } |
|
464 | + } |
|
465 | + } |
|
466 | + |
|
467 | + return true; |
|
468 | + } |
|
469 | + |
|
470 | + // START irmtfan enhance getPostCount when there is join (read_mode = 2) |
|
471 | + |
|
472 | + /** |
|
473 | + * @param null $criteria |
|
474 | + * @param null $join |
|
475 | + * @return int|null |
|
476 | + */ |
|
477 | + public function getPostCount($criteria = null, $join = null) |
|
478 | + { |
|
479 | + // if not join get the count from XOOPS/class/model/stats as before |
|
480 | + if (empty($join)) { |
|
481 | + return parent::getCount($criteria); |
|
482 | + } |
|
483 | + |
|
484 | + $sql = 'SELECT COUNT(*) as count' . ' FROM ' . $this->db->prefix('newbb_posts') . ' AS p' . ' LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' AS t ON t.post_id = p.post_id'; |
|
485 | + // LEFT JOIN |
|
486 | + $sql .= $join; |
|
487 | + // WHERE |
|
488 | + if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
489 | + $sql .= ' ' . $criteria->renderWhere(); |
|
490 | + } |
|
491 | + if (!$result = $this->db->query($sql)) { |
|
492 | + //xoops_error($this->db->error().'<br>'.$sql); |
|
493 | + return null; |
|
494 | + } |
|
495 | + $myrow = $this->db->fetchArray($result); |
|
496 | + $count = $myrow['count']; |
|
497 | + |
|
498 | + return $count; |
|
499 | + } |
|
500 | + // END irmtfan enhance getPostCount when there is join (read_mode = 2) |
|
501 | + /* |
|
502 | 502 | * TODO: combining viewtopic.php |
503 | 503 | */ |
504 | - /** |
|
505 | - * @param null $criteria |
|
506 | - * @param int $limit |
|
507 | - * @param int $start |
|
508 | - * @param null $join |
|
509 | - * @return array |
|
510 | - */ |
|
511 | - public function getPostsByLimit($criteria = null, $limit = 1, $start = 0, $join = null) |
|
512 | - { |
|
513 | - $ret = []; |
|
514 | - $sql = 'SELECT p.*, t.* ' . ' FROM ' . $this->db->prefix('newbb_posts') . ' AS p' . ' LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' AS t ON t.post_id = p.post_id'; |
|
515 | - if (!empty($join)) { |
|
516 | - $sql .= $join; |
|
517 | - } |
|
518 | - if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
519 | - $sql .= ' ' . $criteria->renderWhere(); |
|
520 | - if ('' !== $criteria->getSort()) { |
|
521 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
522 | - } |
|
523 | - } |
|
524 | - $result = $this->db->query($sql, (int)$limit, (int)$start); |
|
525 | - if (!$result) { |
|
526 | - //xoops_error($this->db->error()); |
|
527 | - return $ret; |
|
528 | - } |
|
529 | - while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
530 | - $post = $this->create(false); |
|
531 | - $post->assignVars($myrow); |
|
532 | - $ret[$myrow['post_id']] = $post; |
|
533 | - unset($post); |
|
534 | - } |
|
535 | - |
|
536 | - return $ret; |
|
537 | - } |
|
538 | - |
|
539 | - /** |
|
540 | - * @return bool |
|
541 | - */ |
|
542 | - public function synchronization() |
|
543 | - { |
|
544 | - //$this->cleanOrphan(); |
|
545 | - return true; |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * clean orphan items from database |
|
550 | - * |
|
551 | - * @param string $table_link |
|
552 | - * @param string $field_link |
|
553 | - * @param string $field_object |
|
554 | - * @return bool true on success |
|
555 | - */ |
|
556 | - public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
|
557 | - { |
|
558 | - $this->deleteAll(new \Criteria('post_time', 0), true, true); |
|
559 | - parent::cleanOrphan($this->db->prefix('newbb_topics'), 'topic_id'); |
|
560 | - parent::cleanOrphan($this->db->prefix('newbb_posts_text'), 'post_id'); |
|
561 | - |
|
562 | - $sql = 'DELETE FROM ' . $this->db->prefix('newbb_posts_text') . ' WHERE (post_id NOT IN ( SELECT DISTINCT post_id FROM ' . $this->table . ') )'; |
|
563 | - if (!$result = $this->db->queryF($sql)) { |
|
564 | - //xoops_error($this->db->error()); |
|
565 | - return false; |
|
566 | - } |
|
567 | - |
|
568 | - return true; |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * clean expired objects from database |
|
573 | - * |
|
574 | - * @param int $expire time limit for expiration |
|
575 | - * @return bool true on success |
|
576 | - */ |
|
577 | - public function cleanExpires($expire = 0) |
|
578 | - { |
|
579 | - // irmtfan if 0 no cleanup look include/plugin.php |
|
580 | - if (!func_num_args()) { |
|
581 | - $newbbConfig = newbbLoadConfig(); |
|
582 | - $expire = isset($newbbConfig['pending_expire']) ? (int)$newbbConfig['pending_expire'] : 7; |
|
583 | - $expire = $expire * 24 * 3600; // days to seconds |
|
584 | - } |
|
585 | - if (empty($expire)) { |
|
586 | - return false; |
|
587 | - } |
|
588 | - $crit_expire = new \CriteriaCompo(new \Criteria('approved', 0, '<=')); |
|
589 | - //if (!empty($expire)) { |
|
590 | - $crit_expire->add(new \Criteria('post_time', time() - (int)$expire, '<')); |
|
591 | - |
|
592 | - //} |
|
593 | - return $this->deleteAll($crit_expire, true/*, true*/); |
|
594 | - } |
|
504 | + /** |
|
505 | + * @param null $criteria |
|
506 | + * @param int $limit |
|
507 | + * @param int $start |
|
508 | + * @param null $join |
|
509 | + * @return array |
|
510 | + */ |
|
511 | + public function getPostsByLimit($criteria = null, $limit = 1, $start = 0, $join = null) |
|
512 | + { |
|
513 | + $ret = []; |
|
514 | + $sql = 'SELECT p.*, t.* ' . ' FROM ' . $this->db->prefix('newbb_posts') . ' AS p' . ' LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' AS t ON t.post_id = p.post_id'; |
|
515 | + if (!empty($join)) { |
|
516 | + $sql .= $join; |
|
517 | + } |
|
518 | + if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
|
519 | + $sql .= ' ' . $criteria->renderWhere(); |
|
520 | + if ('' !== $criteria->getSort()) { |
|
521 | + $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
522 | + } |
|
523 | + } |
|
524 | + $result = $this->db->query($sql, (int)$limit, (int)$start); |
|
525 | + if (!$result) { |
|
526 | + //xoops_error($this->db->error()); |
|
527 | + return $ret; |
|
528 | + } |
|
529 | + while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
530 | + $post = $this->create(false); |
|
531 | + $post->assignVars($myrow); |
|
532 | + $ret[$myrow['post_id']] = $post; |
|
533 | + unset($post); |
|
534 | + } |
|
535 | + |
|
536 | + return $ret; |
|
537 | + } |
|
538 | + |
|
539 | + /** |
|
540 | + * @return bool |
|
541 | + */ |
|
542 | + public function synchronization() |
|
543 | + { |
|
544 | + //$this->cleanOrphan(); |
|
545 | + return true; |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * clean orphan items from database |
|
550 | + * |
|
551 | + * @param string $table_link |
|
552 | + * @param string $field_link |
|
553 | + * @param string $field_object |
|
554 | + * @return bool true on success |
|
555 | + */ |
|
556 | + public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
|
557 | + { |
|
558 | + $this->deleteAll(new \Criteria('post_time', 0), true, true); |
|
559 | + parent::cleanOrphan($this->db->prefix('newbb_topics'), 'topic_id'); |
|
560 | + parent::cleanOrphan($this->db->prefix('newbb_posts_text'), 'post_id'); |
|
561 | + |
|
562 | + $sql = 'DELETE FROM ' . $this->db->prefix('newbb_posts_text') . ' WHERE (post_id NOT IN ( SELECT DISTINCT post_id FROM ' . $this->table . ') )'; |
|
563 | + if (!$result = $this->db->queryF($sql)) { |
|
564 | + //xoops_error($this->db->error()); |
|
565 | + return false; |
|
566 | + } |
|
567 | + |
|
568 | + return true; |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * clean expired objects from database |
|
573 | + * |
|
574 | + * @param int $expire time limit for expiration |
|
575 | + * @return bool true on success |
|
576 | + */ |
|
577 | + public function cleanExpires($expire = 0) |
|
578 | + { |
|
579 | + // irmtfan if 0 no cleanup look include/plugin.php |
|
580 | + if (!func_num_args()) { |
|
581 | + $newbbConfig = newbbLoadConfig(); |
|
582 | + $expire = isset($newbbConfig['pending_expire']) ? (int)$newbbConfig['pending_expire'] : 7; |
|
583 | + $expire = $expire * 24 * 3600; // days to seconds |
|
584 | + } |
|
585 | + if (empty($expire)) { |
|
586 | + return false; |
|
587 | + } |
|
588 | + $crit_expire = new \CriteriaCompo(new \Criteria('approved', 0, '<=')); |
|
589 | + //if (!empty($expire)) { |
|
590 | + $crit_expire->add(new \Criteria('post_time', time() - (int)$expire, '<')); |
|
591 | + |
|
592 | + //} |
|
593 | + return $this->deleteAll($crit_expire, true/*, true*/); |
|
594 | + } |
|
595 | 595 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | { |
59 | 59 | $id = (int)$id; |
60 | 60 | $post = null; |
61 | - $sql = 'SELECT p.*, t.* FROM ' . $this->db->prefix('newbb_posts') . ' p LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' t ON p.post_id=t.post_id WHERE p.post_id=' . $id; |
|
61 | + $sql = 'SELECT p.*, t.* FROM '.$this->db->prefix('newbb_posts').' p LEFT JOIN '.$this->db->prefix('newbb_posts_text').' t ON p.post_id=t.post_id WHERE p.post_id='.$id; |
|
62 | 62 | if ($array = $this->db->fetchArray($this->db->query($sql))) { |
63 | 63 | $post = $this->create(false); |
64 | 64 | $post->assignVars($array); |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $topic_id = 0, |
88 | 88 | $approved = 1 |
89 | 89 | ) { |
90 | - $sql = 'SELECT p.*, t.*, tp.topic_status FROM ' |
|
90 | + $sql = 'SELECT p.*, t.*, tp.topic_status FROM ' |
|
91 | 91 | . $this->db->prefix('newbb_posts') |
92 | 92 | . ' p LEFT JOIN ' |
93 | 93 | . $this->db->prefix('newbb_posts_text') |
@@ -379,14 +379,14 @@ discard block |
||
379 | 379 | |
380 | 380 | /* Set active post as deleted */ |
381 | 381 | if ($post->getVar('approved') > 0 && empty($force)) { |
382 | - $sql = 'UPDATE ' . $this->db->prefix('newbb_posts') . ' SET approved = -1 WHERE post_id = ' . $post->getVar('post_id'); |
|
382 | + $sql = 'UPDATE '.$this->db->prefix('newbb_posts').' SET approved = -1 WHERE post_id = '.$post->getVar('post_id'); |
|
383 | 383 | if (!$result = $this->db->queryF($sql)) { |
384 | 384 | } |
385 | 385 | /* delete pending post directly */ |
386 | 386 | } else { |
387 | 387 | $sql = sprintf('DELETE FROM `%s` WHERE post_id = %u', $this->db->prefix('newbb_posts'), $post->getVar('post_id')); |
388 | 388 | if (!$result = $this->db->queryF($sql)) { |
389 | - $post->setErrors('delete post error: ' . $sql); |
|
389 | + $post->setErrors('delete post error: '.$sql); |
|
390 | 390 | |
391 | 391 | return false; |
392 | 392 | } |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | |
395 | 395 | $sql = sprintf('DELETE FROM `%s` WHERE post_id = %u', $this->db->prefix('newbb_posts_text'), $post->getVar('post_id')); |
396 | 396 | if (!$result = $this->db->queryF($sql)) { |
397 | - $post->setErrors('Could not remove post text: ' . $sql); |
|
397 | + $post->setErrors('Could not remove post text: '.$sql); |
|
398 | 398 | |
399 | 399 | return false; |
400 | 400 | } |
@@ -431,11 +431,11 @@ discard block |
||
431 | 431 | } |
432 | 432 | } |
433 | 433 | } else { |
434 | - $sql = 'UPDATE ' . $this->db->prefix('newbb_topics') . ' t |
|
435 | - LEFT JOIN ' . $this->db->prefix('newbb_posts') . ' p ON p.topic_id = t.topic_id |
|
434 | + $sql = 'UPDATE '.$this->db->prefix('newbb_topics').' t |
|
435 | + LEFT JOIN ' . $this->db->prefix('newbb_posts').' p ON p.topic_id = t.topic_id |
|
436 | 436 | SET t.topic_last_post_id = p.post_id |
437 | - WHERE t.topic_last_post_id = ' . $post->getVar('post_id') . ' |
|
438 | - AND p.post_id = (SELECT MAX(post_id) FROM ' . $this->db->prefix('newbb_posts') . ' WHERE topic_id=t.topic_id)'; |
|
437 | + WHERE t.topic_last_post_id = ' . $post->getVar('post_id').' |
|
438 | + AND p.post_id = (SELECT MAX(post_id) FROM ' . $this->db->prefix('newbb_posts').' WHERE topic_id=t.topic_id)'; |
|
439 | 439 | if (!$result = $this->db->queryF($sql)) { |
440 | 440 | } |
441 | 441 | } |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | } |
458 | 458 | // irmtfan - just update the pid for approved posts when the post is not topic (pid=0) |
459 | 459 | if (!$post->isTopic()) { |
460 | - $sql = 'UPDATE ' . $this->db->prefix('newbb_posts') . ' SET pid = ' . $post->getVar('pid') . ' WHERE approved=1 AND pid=' . $post->getVar('post_id'); |
|
460 | + $sql = 'UPDATE '.$this->db->prefix('newbb_posts').' SET pid = '.$post->getVar('pid').' WHERE approved=1 AND pid='.$post->getVar('post_id'); |
|
461 | 461 | if (!$result = $this->db->queryF($sql)) { |
462 | 462 | //xoops_error($this->db->error()); |
463 | 463 | } |
@@ -481,12 +481,12 @@ discard block |
||
481 | 481 | return parent::getCount($criteria); |
482 | 482 | } |
483 | 483 | |
484 | - $sql = 'SELECT COUNT(*) as count' . ' FROM ' . $this->db->prefix('newbb_posts') . ' AS p' . ' LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' AS t ON t.post_id = p.post_id'; |
|
484 | + $sql = 'SELECT COUNT(*) as count'.' FROM '.$this->db->prefix('newbb_posts').' AS p'.' LEFT JOIN '.$this->db->prefix('newbb_posts_text').' AS t ON t.post_id = p.post_id'; |
|
485 | 485 | // LEFT JOIN |
486 | 486 | $sql .= $join; |
487 | 487 | // WHERE |
488 | 488 | if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
489 | - $sql .= ' ' . $criteria->renderWhere(); |
|
489 | + $sql .= ' '.$criteria->renderWhere(); |
|
490 | 490 | } |
491 | 491 | if (!$result = $this->db->query($sql)) { |
492 | 492 | //xoops_error($this->db->error().'<br>'.$sql); |
@@ -511,14 +511,14 @@ discard block |
||
511 | 511 | public function getPostsByLimit($criteria = null, $limit = 1, $start = 0, $join = null) |
512 | 512 | { |
513 | 513 | $ret = []; |
514 | - $sql = 'SELECT p.*, t.* ' . ' FROM ' . $this->db->prefix('newbb_posts') . ' AS p' . ' LEFT JOIN ' . $this->db->prefix('newbb_posts_text') . ' AS t ON t.post_id = p.post_id'; |
|
514 | + $sql = 'SELECT p.*, t.* '.' FROM '.$this->db->prefix('newbb_posts').' AS p'.' LEFT JOIN '.$this->db->prefix('newbb_posts_text').' AS t ON t.post_id = p.post_id'; |
|
515 | 515 | if (!empty($join)) { |
516 | 516 | $sql .= $join; |
517 | 517 | } |
518 | 518 | if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) { |
519 | - $sql .= ' ' . $criteria->renderWhere(); |
|
519 | + $sql .= ' '.$criteria->renderWhere(); |
|
520 | 520 | if ('' !== $criteria->getSort()) { |
521 | - $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder(); |
|
521 | + $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder(); |
|
522 | 522 | } |
523 | 523 | } |
524 | 524 | $result = $this->db->query($sql, (int)$limit, (int)$start); |
@@ -559,7 +559,7 @@ discard block |
||
559 | 559 | parent::cleanOrphan($this->db->prefix('newbb_topics'), 'topic_id'); |
560 | 560 | parent::cleanOrphan($this->db->prefix('newbb_posts_text'), 'post_id'); |
561 | 561 | |
562 | - $sql = 'DELETE FROM ' . $this->db->prefix('newbb_posts_text') . ' WHERE (post_id NOT IN ( SELECT DISTINCT post_id FROM ' . $this->table . ') )'; |
|
562 | + $sql = 'DELETE FROM '.$this->db->prefix('newbb_posts_text').' WHERE (post_id NOT IN ( SELECT DISTINCT post_id FROM '.$this->table.') )'; |
|
563 | 563 | if (!$result = $this->db->queryF($sql)) { |
564 | 564 | //xoops_error($this->db->error()); |
565 | 565 | return false; |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | //define("NEWBB_HANDLER_PERMISSION_FORUM", 1); |
19 | 19 | |
20 | 20 | if (defined('FORUM_PERM_ITEMS') && class_exists('ForumPermissionHandler')) { |
21 | - exit('access denied'); |
|
21 | + exit('access denied'); |
|
22 | 22 | } |
23 | 23 | // irmtfan add pdf and print permissions. |
24 | 24 | define('FORUM_PERM_ITEMS', 'access,view,post,reply,edit,delete,addpoll,vote,attach,noapprove,type,html,signature,pdf,print'); |
@@ -28,246 +28,246 @@ discard block |
||
28 | 28 | */ |
29 | 29 | class PermissionForumHandler extends PermissionHandler |
30 | 30 | { |
31 | - protected $templateFilename; |
|
31 | + protected $templateFilename; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @param \XoopsDatabase $db |
|
35 | - */ |
|
36 | - public function __construct(\XoopsDatabase $db) |
|
37 | - { |
|
38 | - // $this->PermissionHandler($db); |
|
39 | - parent::__construct($db); |
|
40 | - $this->templateFilename = XOOPS_VAR_PATH . '/configs/newbb_permission_template.php'; |
|
41 | - } |
|
33 | + /** |
|
34 | + * @param \XoopsDatabase $db |
|
35 | + */ |
|
36 | + public function __construct(\XoopsDatabase $db) |
|
37 | + { |
|
38 | + // $this->PermissionHandler($db); |
|
39 | + parent::__construct($db); |
|
40 | + $this->templateFilename = XOOPS_VAR_PATH . '/configs/newbb_permission_template.php'; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param bool $fullname |
|
45 | - * @return array |
|
46 | - */ |
|
47 | - public function getValidPerms($fullname = false) |
|
48 | - { |
|
49 | - static $validPerms = []; |
|
50 | - if (isset($validPerms[(int)$fullname])) { |
|
51 | - return $validPerms[(int)$fullname]; |
|
52 | - } |
|
53 | - $items = array_filter(array_map('trim', explode(',', FORUM_PERM_ITEMS))); |
|
54 | - if (!empty($fullname)) { |
|
55 | - foreach (array_keys($items) as $key) { |
|
56 | - $items[$key] = 'forum_' . $items[$key]; |
|
57 | - } |
|
58 | - } |
|
59 | - $validPerms[(int)$fullname] = $items; |
|
43 | + /** |
|
44 | + * @param bool $fullname |
|
45 | + * @return array |
|
46 | + */ |
|
47 | + public function getValidPerms($fullname = false) |
|
48 | + { |
|
49 | + static $validPerms = []; |
|
50 | + if (isset($validPerms[(int)$fullname])) { |
|
51 | + return $validPerms[(int)$fullname]; |
|
52 | + } |
|
53 | + $items = array_filter(array_map('trim', explode(',', FORUM_PERM_ITEMS))); |
|
54 | + if (!empty($fullname)) { |
|
55 | + foreach (array_keys($items) as $key) { |
|
56 | + $items[$key] = 'forum_' . $items[$key]; |
|
57 | + } |
|
58 | + } |
|
59 | + $validPerms[(int)$fullname] = $items; |
|
60 | 60 | |
61 | - return $items; |
|
62 | - } |
|
61 | + return $items; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param $mid |
|
66 | - * @param int $id |
|
67 | - * @return array |
|
68 | - */ |
|
69 | - public function getValidItems($mid, $id = 0) |
|
70 | - { |
|
71 | - static $suspension = []; |
|
72 | - $full_items = []; |
|
73 | - if (empty($mid)) { |
|
74 | - return $full_items; |
|
75 | - } |
|
64 | + /** |
|
65 | + * @param $mid |
|
66 | + * @param int $id |
|
67 | + * @return array |
|
68 | + */ |
|
69 | + public function getValidItems($mid, $id = 0) |
|
70 | + { |
|
71 | + static $suspension = []; |
|
72 | + $full_items = []; |
|
73 | + if (empty($mid)) { |
|
74 | + return $full_items; |
|
75 | + } |
|
76 | 76 | |
77 | - require_once dirname(__DIR__) . '/include/functions.user.php'; |
|
78 | - $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
79 | - $ip = \Xmf\IPAddress::fromRequest()->asReadable(); |
|
80 | - if (!empty($GLOBALS['xoopsModuleConfig']['enable_usermoderate']) && !isset($suspension[$uid][$id]) |
|
81 | - && !newbbIsAdmin($id)) { |
|
82 | - /** @var Newbb\ModerateHandler $moderateHandler */ |
|
83 | - $moderateHandler = Newbb\Helper::getInstance()->getHandler('Moderate'); |
|
84 | - if (!$moderateHandler->verifyUser($uid, '', $id)) { |
|
85 | - $suspension[$uid][$ip][$id] = 1; |
|
86 | - } else { |
|
87 | - $suspension[$uid][$ip][$id] = 0; |
|
88 | - } |
|
89 | - } |
|
77 | + require_once dirname(__DIR__) . '/include/functions.user.php'; |
|
78 | + $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
|
79 | + $ip = \Xmf\IPAddress::fromRequest()->asReadable(); |
|
80 | + if (!empty($GLOBALS['xoopsModuleConfig']['enable_usermoderate']) && !isset($suspension[$uid][$id]) |
|
81 | + && !newbbIsAdmin($id)) { |
|
82 | + /** @var Newbb\ModerateHandler $moderateHandler */ |
|
83 | + $moderateHandler = Newbb\Helper::getInstance()->getHandler('Moderate'); |
|
84 | + if (!$moderateHandler->verifyUser($uid, '', $id)) { |
|
85 | + $suspension[$uid][$ip][$id] = 1; |
|
86 | + } else { |
|
87 | + $suspension[$uid][$ip][$id] = 0; |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - $items = $this->getValidPerms(); |
|
92 | - foreach ($items as $item) { |
|
93 | - /* skip access for suspended users */ |
|
94 | - //if ( !empty($suspension[$uid][$ip][$id]) && in_array($item, array("post", "reply", "edit", "delete", "addpoll", "vote", "attach", "noapprove", "type")) ) continue; |
|
95 | - if (!empty($suspension[$uid][$ip][$id])) { |
|
96 | - continue; |
|
97 | - } |
|
98 | - $full_items[] = "'forum_{$item}'"; |
|
99 | - } |
|
91 | + $items = $this->getValidPerms(); |
|
92 | + foreach ($items as $item) { |
|
93 | + /* skip access for suspended users */ |
|
94 | + //if ( !empty($suspension[$uid][$ip][$id]) && in_array($item, array("post", "reply", "edit", "delete", "addpoll", "vote", "attach", "noapprove", "type")) ) continue; |
|
95 | + if (!empty($suspension[$uid][$ip][$id])) { |
|
96 | + continue; |
|
97 | + } |
|
98 | + $full_items[] = "'forum_{$item}'"; |
|
99 | + } |
|
100 | 100 | |
101 | - return $full_items; |
|
102 | - } |
|
101 | + return $full_items; |
|
102 | + } |
|
103 | 103 | |
104 | - /* |
|
104 | + /* |
|
105 | 105 | * Returns permissions for a certain type |
106 | 106 | * |
107 | 107 | * @param int $id id of the item (forum, topic or possibly post) to get permissions for |
108 | 108 | * |
109 | 109 | * @return array |
110 | 110 | */ |
111 | - /** |
|
112 | - * @param int|array $id |
|
113 | - * @return bool|array |
|
114 | - */ |
|
115 | - public function getPermissions($id = 0) |
|
116 | - { |
|
117 | - $permissions = []; |
|
118 | - if (is_object($GLOBALS['xoopsModule']) && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) { |
|
119 | - $modid = $GLOBALS['xoopsModule']->getVar('mid'); |
|
120 | - } else { |
|
121 | - /** @var \XoopsModuleHandler $moduleHandler */ |
|
122 | - $moduleHandler = xoops_getHandler('module'); |
|
123 | - $xoopsNewBB = $moduleHandler->getByDirname('newbb'); |
|
124 | - $modid = $xoopsNewBB->getVar('mid'); |
|
125 | - unset($xoopsNewBB); |
|
126 | - } |
|
111 | + /** |
|
112 | + * @param int|array $id |
|
113 | + * @return bool|array |
|
114 | + */ |
|
115 | + public function getPermissions($id = 0) |
|
116 | + { |
|
117 | + $permissions = []; |
|
118 | + if (is_object($GLOBALS['xoopsModule']) && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) { |
|
119 | + $modid = $GLOBALS['xoopsModule']->getVar('mid'); |
|
120 | + } else { |
|
121 | + /** @var \XoopsModuleHandler $moduleHandler */ |
|
122 | + $moduleHandler = xoops_getHandler('module'); |
|
123 | + $xoopsNewBB = $moduleHandler->getByDirname('newbb'); |
|
124 | + $modid = $xoopsNewBB->getVar('mid'); |
|
125 | + unset($xoopsNewBB); |
|
126 | + } |
|
127 | 127 | |
128 | - // Get user's groups |
|
129 | - $groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
130 | - // Create string of groupid's separated by commas, inserted in a set of brackets |
|
131 | - if (count($groups) < 1) { |
|
132 | - return false; |
|
133 | - } |
|
134 | - // Create criteria for getting only the permissions regarding this module and this user's groups |
|
135 | - $criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $modid)); |
|
136 | - $criteria->add(new \Criteria('gperm_groupid', '(' . implode(',', $groups) . ')', 'IN')); |
|
137 | - if ($id) { |
|
138 | - if (is_array($id)) { |
|
139 | - $criteria->add(new \Criteria('gperm_itemid', '(' . implode(',', $id) . ')', 'IN')); |
|
140 | - } else { |
|
141 | - $criteria->add(new \Criteria('gperm_itemid', (int)$id)); |
|
142 | - } |
|
143 | - } |
|
144 | - $gperm_names = implode(', ', $this->getValidItems($modid, $id)); |
|
128 | + // Get user's groups |
|
129 | + $groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : [XOOPS_GROUP_ANONYMOUS]; |
|
130 | + // Create string of groupid's separated by commas, inserted in a set of brackets |
|
131 | + if (count($groups) < 1) { |
|
132 | + return false; |
|
133 | + } |
|
134 | + // Create criteria for getting only the permissions regarding this module and this user's groups |
|
135 | + $criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $modid)); |
|
136 | + $criteria->add(new \Criteria('gperm_groupid', '(' . implode(',', $groups) . ')', 'IN')); |
|
137 | + if ($id) { |
|
138 | + if (is_array($id)) { |
|
139 | + $criteria->add(new \Criteria('gperm_itemid', '(' . implode(',', $id) . ')', 'IN')); |
|
140 | + } else { |
|
141 | + $criteria->add(new \Criteria('gperm_itemid', (int)$id)); |
|
142 | + } |
|
143 | + } |
|
144 | + $gperm_names = implode(', ', $this->getValidItems($modid, $id)); |
|
145 | 145 | |
146 | - // Add criteria for gpermnames |
|
147 | - $criteria->add(new \Criteria('gperm_name', '(' . $gperm_names . ')', 'IN')); |
|
148 | - // Get all permission objects in this module and for this user's groups |
|
149 | - $userpermissions = $this->getObjects($criteria, true); |
|
146 | + // Add criteria for gpermnames |
|
147 | + $criteria->add(new \Criteria('gperm_name', '(' . $gperm_names . ')', 'IN')); |
|
148 | + // Get all permission objects in this module and for this user's groups |
|
149 | + $userpermissions = $this->getObjects($criteria, true); |
|
150 | 150 | |
151 | - // Set the granted permissions to 1 |
|
152 | - foreach ($userpermissions as $gperm_id => $gperm) { |
|
153 | - $permissions[$gperm->getVar('gperm_itemid')][$gperm->getVar('gperm_name')] = 1; |
|
154 | - } |
|
155 | - $userpermissions = null; |
|
156 | - unset($userpermissions); |
|
151 | + // Set the granted permissions to 1 |
|
152 | + foreach ($userpermissions as $gperm_id => $gperm) { |
|
153 | + $permissions[$gperm->getVar('gperm_itemid')][$gperm->getVar('gperm_name')] = 1; |
|
154 | + } |
|
155 | + $userpermissions = null; |
|
156 | + unset($userpermissions); |
|
157 | 157 | |
158 | - // Return the permission array |
|
159 | - return $permissions; |
|
160 | - } |
|
158 | + // Return the permission array |
|
159 | + return $permissions; |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * @param Forum|int $forum |
|
164 | - * @param bool $topic_locked |
|
165 | - * @param bool $isAdmin |
|
166 | - * @return array |
|
167 | - */ |
|
168 | - public function getPermissionTable($forum = 0, $topic_locked = false, $isAdmin = false) |
|
169 | - { |
|
170 | - $perm = []; |
|
162 | + /** |
|
163 | + * @param Forum|int $forum |
|
164 | + * @param bool $topic_locked |
|
165 | + * @param bool $isAdmin |
|
166 | + * @return array |
|
167 | + */ |
|
168 | + public function getPermissionTable($forum = 0, $topic_locked = false, $isAdmin = false) |
|
169 | + { |
|
170 | + $perm = []; |
|
171 | 171 | |
172 | - $forumId = $forum; |
|
173 | - if (is_object($forum)) { |
|
174 | - $forumId = $forum->getVar('forum_id'); |
|
175 | - } |
|
172 | + $forumId = $forum; |
|
173 | + if (is_object($forum)) { |
|
174 | + $forumId = $forum->getVar('forum_id'); |
|
175 | + } |
|
176 | 176 | |
177 | - $permission_set = $this->getPermissions($forumId); |
|
177 | + $permission_set = $this->getPermissions($forumId); |
|
178 | 178 | |
179 | - $permItems = $this->getValidPerms(); |
|
180 | - foreach ($permItems as $item) { |
|
181 | - if ('access' === $item) { |
|
182 | - continue; |
|
183 | - } |
|
184 | - if ($isAdmin |
|
185 | - || (isset($permission_set[$forumId]['forum_' . $item]) |
|
186 | - && (!$topic_locked |
|
187 | - || 'view' === $item))) { |
|
188 | - $perm[] = constant('_MD_NEWBB_CAN_' . strtoupper($item)); |
|
189 | - } else { |
|
190 | - $perm[] = constant('_MD_NEWBB_CANNOT_' . strtoupper($item)); |
|
191 | - } |
|
192 | - } |
|
179 | + $permItems = $this->getValidPerms(); |
|
180 | + foreach ($permItems as $item) { |
|
181 | + if ('access' === $item) { |
|
182 | + continue; |
|
183 | + } |
|
184 | + if ($isAdmin |
|
185 | + || (isset($permission_set[$forumId]['forum_' . $item]) |
|
186 | + && (!$topic_locked |
|
187 | + || 'view' === $item))) { |
|
188 | + $perm[] = constant('_MD_NEWBB_CAN_' . strtoupper($item)); |
|
189 | + } else { |
|
190 | + $perm[] = constant('_MD_NEWBB_CANNOT_' . strtoupper($item)); |
|
191 | + } |
|
192 | + } |
|
193 | 193 | |
194 | - return $perm; |
|
195 | - } |
|
194 | + return $perm; |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * @param $forum_id |
|
199 | - * @return bool |
|
200 | - */ |
|
201 | - public function deleteByForum($forum_id) |
|
202 | - { |
|
203 | - $forum_id = (int)$forum_id; |
|
204 | - if (empty($forum_id)) { |
|
205 | - return false; |
|
206 | - } |
|
207 | - $grouppermHandler = xoops_getHandler('groupperm'); |
|
208 | - $criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid'))); |
|
209 | - $items = $this->getValidPerms(true); |
|
210 | - $criteria->add(new \Criteria('gperm_name', "('" . implode("', '", $items) . "')", 'IN')); |
|
211 | - $criteria->add(new \Criteria('gperm_itemid', $forum_id)); |
|
197 | + /** |
|
198 | + * @param $forum_id |
|
199 | + * @return bool |
|
200 | + */ |
|
201 | + public function deleteByForum($forum_id) |
|
202 | + { |
|
203 | + $forum_id = (int)$forum_id; |
|
204 | + if (empty($forum_id)) { |
|
205 | + return false; |
|
206 | + } |
|
207 | + $grouppermHandler = xoops_getHandler('groupperm'); |
|
208 | + $criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid'))); |
|
209 | + $items = $this->getValidPerms(true); |
|
210 | + $criteria->add(new \Criteria('gperm_name', "('" . implode("', '", $items) . "')", 'IN')); |
|
211 | + $criteria->add(new \Criteria('gperm_itemid', $forum_id)); |
|
212 | 212 | |
213 | - return $grouppermHandler->deleteAll($criteria); |
|
214 | - } |
|
213 | + return $grouppermHandler->deleteAll($criteria); |
|
214 | + } |
|
215 | 215 | |
216 | - /** |
|
217 | - * @param $forum |
|
218 | - * @param int $mid |
|
219 | - * @return bool |
|
220 | - */ |
|
221 | - public function applyTemplate($forum, $mid = 0) |
|
222 | - { |
|
223 | - if (!$perm_template = $this->getTemplate()) { |
|
224 | - return false; |
|
225 | - } |
|
216 | + /** |
|
217 | + * @param $forum |
|
218 | + * @param int $mid |
|
219 | + * @return bool |
|
220 | + */ |
|
221 | + public function applyTemplate($forum, $mid = 0) |
|
222 | + { |
|
223 | + if (!$perm_template = $this->getTemplate()) { |
|
224 | + return false; |
|
225 | + } |
|
226 | 226 | |
227 | - if (empty($mid)) { |
|
228 | - if (is_object($GLOBALS['xoopsModule']) && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) { |
|
229 | - $mid = $GLOBALS['xoopsModule']->getVar('mid'); |
|
230 | - } else { |
|
231 | - /** @var \XoopsModuleHandler $moduleHandler */ |
|
232 | - $moduleHandler = xoops_getHandler('module'); |
|
233 | - $newbb = $moduleHandler->getByDirname('newbb'); |
|
234 | - $mid = $newbb->getVar('mid'); |
|
235 | - unset($newbb); |
|
236 | - } |
|
237 | - } |
|
227 | + if (empty($mid)) { |
|
228 | + if (is_object($GLOBALS['xoopsModule']) && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) { |
|
229 | + $mid = $GLOBALS['xoopsModule']->getVar('mid'); |
|
230 | + } else { |
|
231 | + /** @var \XoopsModuleHandler $moduleHandler */ |
|
232 | + $moduleHandler = xoops_getHandler('module'); |
|
233 | + $newbb = $moduleHandler->getByDirname('newbb'); |
|
234 | + $mid = $newbb->getVar('mid'); |
|
235 | + unset($newbb); |
|
236 | + } |
|
237 | + } |
|
238 | 238 | |
239 | - /** @var \XoopsMemberHandler $memberHandler */ |
|
240 | - $memberHandler = xoops_getHandler('member'); |
|
241 | - $glist = $memberHandler->getGroupList(); |
|
242 | - $perms = $this->getValidPerms(true); |
|
243 | - foreach (array_keys($glist) as $group) { |
|
244 | - foreach ($perms as $perm) { |
|
245 | - if (!empty($perm_template[$group][$perm])) { |
|
246 | - $this->validateRight($perm, $forum, $group, $mid); |
|
247 | - } else { |
|
248 | - $this->deleteRight($perm, $forum, $group, $mid); |
|
249 | - } |
|
250 | - } |
|
251 | - } |
|
239 | + /** @var \XoopsMemberHandler $memberHandler */ |
|
240 | + $memberHandler = xoops_getHandler('member'); |
|
241 | + $glist = $memberHandler->getGroupList(); |
|
242 | + $perms = $this->getValidPerms(true); |
|
243 | + foreach (array_keys($glist) as $group) { |
|
244 | + foreach ($perms as $perm) { |
|
245 | + if (!empty($perm_template[$group][$perm])) { |
|
246 | + $this->validateRight($perm, $forum, $group, $mid); |
|
247 | + } else { |
|
248 | + $this->deleteRight($perm, $forum, $group, $mid); |
|
249 | + } |
|
250 | + } |
|
251 | + } |
|
252 | 252 | |
253 | - return true; |
|
254 | - } |
|
253 | + return true; |
|
254 | + } |
|
255 | 255 | |
256 | - /** |
|
257 | - * @return array|false |
|
258 | - */ |
|
259 | - public function getTemplate() |
|
260 | - { |
|
261 | - $perms = \Xmf\Yaml::readWrapped($this->templateFilename); |
|
262 | - return $perms; |
|
263 | - } |
|
256 | + /** |
|
257 | + * @return array|false |
|
258 | + */ |
|
259 | + public function getTemplate() |
|
260 | + { |
|
261 | + $perms = \Xmf\Yaml::readWrapped($this->templateFilename); |
|
262 | + return $perms; |
|
263 | + } |
|
264 | 264 | |
265 | - /** |
|
266 | - * @param array $perms |
|
267 | - * @return bool |
|
268 | - */ |
|
269 | - public function setTemplate($perms) |
|
270 | - { |
|
271 | - return \Xmf\Yaml::saveWrapped($perms, $this->templateFilename); |
|
272 | - } |
|
265 | + /** |
|
266 | + * @param array $perms |
|
267 | + * @return bool |
|
268 | + */ |
|
269 | + public function setTemplate($perms) |
|
270 | + { |
|
271 | + return \Xmf\Yaml::saveWrapped($perms, $this->templateFilename); |
|
272 | + } |
|
273 | 273 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | { |
38 | 38 | // $this->PermissionHandler($db); |
39 | 39 | parent::__construct($db); |
40 | - $this->templateFilename = XOOPS_VAR_PATH . '/configs/newbb_permission_template.php'; |
|
40 | + $this->templateFilename = XOOPS_VAR_PATH.'/configs/newbb_permission_template.php'; |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | $items = array_filter(array_map('trim', explode(',', FORUM_PERM_ITEMS))); |
54 | 54 | if (!empty($fullname)) { |
55 | 55 | foreach (array_keys($items) as $key) { |
56 | - $items[$key] = 'forum_' . $items[$key]; |
|
56 | + $items[$key] = 'forum_'.$items[$key]; |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | $validPerms[(int)$fullname] = $items; |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | return $full_items; |
75 | 75 | } |
76 | 76 | |
77 | - require_once dirname(__DIR__) . '/include/functions.user.php'; |
|
77 | + require_once dirname(__DIR__).'/include/functions.user.php'; |
|
78 | 78 | $uid = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0; |
79 | 79 | $ip = \Xmf\IPAddress::fromRequest()->asReadable(); |
80 | 80 | if (!empty($GLOBALS['xoopsModuleConfig']['enable_usermoderate']) && !isset($suspension[$uid][$id]) |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | } |
134 | 134 | // Create criteria for getting only the permissions regarding this module and this user's groups |
135 | 135 | $criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $modid)); |
136 | - $criteria->add(new \Criteria('gperm_groupid', '(' . implode(',', $groups) . ')', 'IN')); |
|
136 | + $criteria->add(new \Criteria('gperm_groupid', '('.implode(',', $groups).')', 'IN')); |
|
137 | 137 | if ($id) { |
138 | 138 | if (is_array($id)) { |
139 | - $criteria->add(new \Criteria('gperm_itemid', '(' . implode(',', $id) . ')', 'IN')); |
|
139 | + $criteria->add(new \Criteria('gperm_itemid', '('.implode(',', $id).')', 'IN')); |
|
140 | 140 | } else { |
141 | 141 | $criteria->add(new \Criteria('gperm_itemid', (int)$id)); |
142 | 142 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | $gperm_names = implode(', ', $this->getValidItems($modid, $id)); |
145 | 145 | |
146 | 146 | // Add criteria for gpermnames |
147 | - $criteria->add(new \Criteria('gperm_name', '(' . $gperm_names . ')', 'IN')); |
|
147 | + $criteria->add(new \Criteria('gperm_name', '('.$gperm_names.')', 'IN')); |
|
148 | 148 | // Get all permission objects in this module and for this user's groups |
149 | 149 | $userpermissions = $this->getObjects($criteria, true); |
150 | 150 | |
@@ -182,12 +182,12 @@ discard block |
||
182 | 182 | continue; |
183 | 183 | } |
184 | 184 | if ($isAdmin |
185 | - || (isset($permission_set[$forumId]['forum_' . $item]) |
|
185 | + || (isset($permission_set[$forumId]['forum_'.$item]) |
|
186 | 186 | && (!$topic_locked |
187 | 187 | || 'view' === $item))) { |
188 | - $perm[] = constant('_MD_NEWBB_CAN_' . strtoupper($item)); |
|
188 | + $perm[] = constant('_MD_NEWBB_CAN_'.strtoupper($item)); |
|
189 | 189 | } else { |
190 | - $perm[] = constant('_MD_NEWBB_CANNOT_' . strtoupper($item)); |
|
190 | + $perm[] = constant('_MD_NEWBB_CANNOT_'.strtoupper($item)); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | $grouppermHandler = xoops_getHandler('groupperm'); |
208 | 208 | $criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid'))); |
209 | 209 | $items = $this->getValidPerms(true); |
210 | - $criteria->add(new \Criteria('gperm_name', "('" . implode("', '", $items) . "')", 'IN')); |
|
210 | + $criteria->add(new \Criteria('gperm_name', "('".implode("', '", $items)."')", 'IN')); |
|
211 | 211 | $criteria->add(new \Criteria('gperm_itemid', $forum_id)); |
212 | 212 | |
213 | 213 | return $grouppermHandler->deleteAll($criteria); |
@@ -24,105 +24,105 @@ |
||
24 | 24 | */ |
25 | 25 | class Xmlrss |
26 | 26 | { |
27 | - public $xml_version; |
|
28 | - public $rss_version; |
|
29 | - public $xml_encoding; |
|
27 | + public $xml_version; |
|
28 | + public $rss_version; |
|
29 | + public $xml_encoding; |
|
30 | 30 | |
31 | - public $channel_title; |
|
32 | - public $channel_link; |
|
33 | - public $channel_desc; |
|
34 | - public $channel_lastbuild; |
|
35 | - public $channel_webmaster; |
|
36 | - public $channel_editor; |
|
37 | - public $channel_category; |
|
38 | - public $channel_generator; |
|
39 | - public $channel_language; |
|
31 | + public $channel_title; |
|
32 | + public $channel_link; |
|
33 | + public $channel_desc; |
|
34 | + public $channel_lastbuild; |
|
35 | + public $channel_webmaster; |
|
36 | + public $channel_editor; |
|
37 | + public $channel_category; |
|
38 | + public $channel_generator; |
|
39 | + public $channel_language; |
|
40 | 40 | |
41 | - public $image_title; |
|
42 | - public $image_url; |
|
43 | - public $image_link; |
|
44 | - public $image_description; |
|
45 | - public $image_height; |
|
46 | - public $image_width; |
|
41 | + public $image_title; |
|
42 | + public $image_url; |
|
43 | + public $image_link; |
|
44 | + public $image_description; |
|
45 | + public $image_height; |
|
46 | + public $image_width; |
|
47 | 47 | |
48 | - public $max_items; |
|
49 | - public $max_item_description; |
|
50 | - public $items = []; |
|
48 | + public $max_items; |
|
49 | + public $max_item_description; |
|
50 | + public $items = []; |
|
51 | 51 | |
52 | - /** |
|
53 | - * |
|
54 | - */ |
|
55 | - public function __construct() |
|
56 | - { |
|
57 | - $this->xml_version = '1.0'; |
|
58 | - $this->xml_encoding = empty($GLOBALS['xoopsModuleConfig']['rss_utf8']) ? _CHARSET : 'UTF-8'; |
|
59 | - $this->rss_version = '2.0'; |
|
60 | - $this->image_height = 31; |
|
61 | - $this->image_width = 88; |
|
62 | - $this->max_items = 10; |
|
63 | - $this->max_item_description = 0; |
|
64 | - $this->items = []; |
|
65 | - } |
|
52 | + /** |
|
53 | + * |
|
54 | + */ |
|
55 | + public function __construct() |
|
56 | + { |
|
57 | + $this->xml_version = '1.0'; |
|
58 | + $this->xml_encoding = empty($GLOBALS['xoopsModuleConfig']['rss_utf8']) ? _CHARSET : 'UTF-8'; |
|
59 | + $this->rss_version = '2.0'; |
|
60 | + $this->image_height = 31; |
|
61 | + $this->image_width = 88; |
|
62 | + $this->max_items = 10; |
|
63 | + $this->max_item_description = 0; |
|
64 | + $this->items = []; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * @param $var |
|
69 | - * @param $val |
|
70 | - */ |
|
71 | - public function setVarRss($var, $val) |
|
72 | - { |
|
73 | - $this->$var = $this->cleanup($val); |
|
74 | - } |
|
67 | + /** |
|
68 | + * @param $var |
|
69 | + * @param $val |
|
70 | + */ |
|
71 | + public function setVarRss($var, $val) |
|
72 | + { |
|
73 | + $this->$var = $this->cleanup($val); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * @param $title |
|
78 | - * @param $link |
|
79 | - * @param string $description |
|
80 | - * @param string $label |
|
81 | - * @param int|string $pubdate |
|
82 | - * @return bool |
|
83 | - */ |
|
84 | - public function addItem($title, $link, $description = '', $label = '', $pubdate = 0) |
|
85 | - { |
|
86 | - if (count($this->items) < $this->max_items) { |
|
87 | - if (!empty($label)) { |
|
88 | - $label = '[' . $this->cleanup($label) . ']'; |
|
89 | - } |
|
90 | - if (!empty($description)) { |
|
91 | - $description = $this->cleanup($description, $this->max_item_description); |
|
92 | - //$description .= ' ' . $label; |
|
93 | - } else { |
|
94 | - //$description = $label; |
|
95 | - } |
|
76 | + /** |
|
77 | + * @param $title |
|
78 | + * @param $link |
|
79 | + * @param string $description |
|
80 | + * @param string $label |
|
81 | + * @param int|string $pubdate |
|
82 | + * @return bool |
|
83 | + */ |
|
84 | + public function addItem($title, $link, $description = '', $label = '', $pubdate = 0) |
|
85 | + { |
|
86 | + if (count($this->items) < $this->max_items) { |
|
87 | + if (!empty($label)) { |
|
88 | + $label = '[' . $this->cleanup($label) . ']'; |
|
89 | + } |
|
90 | + if (!empty($description)) { |
|
91 | + $description = $this->cleanup($description, $this->max_item_description); |
|
92 | + //$description .= ' ' . $label; |
|
93 | + } else { |
|
94 | + //$description = $label; |
|
95 | + } |
|
96 | 96 | |
97 | - $title = $this->cleanup($title) . ' ' . $label; |
|
98 | - $pubdate = $this->cleanup($pubdate); |
|
99 | - $this->items[] = [ |
|
100 | - 'title' => $title, |
|
101 | - 'link' => $link, |
|
102 | - 'guid' => $link, |
|
103 | - 'description' => $description, |
|
104 | - 'pubdate' => $pubdate |
|
105 | - ]; |
|
106 | - } |
|
97 | + $title = $this->cleanup($title) . ' ' . $label; |
|
98 | + $pubdate = $this->cleanup($pubdate); |
|
99 | + $this->items[] = [ |
|
100 | + 'title' => $title, |
|
101 | + 'link' => $link, |
|
102 | + 'guid' => $link, |
|
103 | + 'description' => $description, |
|
104 | + 'pubdate' => $pubdate |
|
105 | + ]; |
|
106 | + } |
|
107 | 107 | |
108 | - return true; |
|
109 | - } |
|
108 | + return true; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * @param $text |
|
113 | - * @param int $trim |
|
114 | - * @return mixed|string |
|
115 | - */ |
|
116 | - public function cleanup($text, $trim = 0) |
|
117 | - { |
|
118 | - if ('utf-8' === strtolower($this->xml_encoding) && strncasecmp(_CHARSET, $this->xml_encoding, 5)) { |
|
119 | - $text = \XoopsLocal::convert_encoding($text, 'utf-8'); |
|
120 | - } |
|
121 | - if (!empty($trim)) { |
|
122 | - $text = xoops_substr($text, 0, (int)$trim); |
|
123 | - } |
|
124 | - $text = htmlspecialchars($text, ENT_QUOTES); |
|
111 | + /** |
|
112 | + * @param $text |
|
113 | + * @param int $trim |
|
114 | + * @return mixed|string |
|
115 | + */ |
|
116 | + public function cleanup($text, $trim = 0) |
|
117 | + { |
|
118 | + if ('utf-8' === strtolower($this->xml_encoding) && strncasecmp(_CHARSET, $this->xml_encoding, 5)) { |
|
119 | + $text = \XoopsLocal::convert_encoding($text, 'utf-8'); |
|
120 | + } |
|
121 | + if (!empty($trim)) { |
|
122 | + $text = xoops_substr($text, 0, (int)$trim); |
|
123 | + } |
|
124 | + $text = htmlspecialchars($text, ENT_QUOTES); |
|
125 | 125 | |
126 | - return $text; |
|
127 | - } |
|
126 | + return $text; |
|
127 | + } |
|
128 | 128 | } |