@@ -19,16 +19,16 @@ |
||
19 | 19 | */ |
20 | 20 | class Userstats extends \XoopsObject |
21 | 21 | { |
22 | - /** |
|
23 | - * |
|
24 | - */ |
|
25 | - public function __construct() |
|
26 | - { |
|
27 | - parent::__construct(); |
|
28 | - $this->initVar('uid', XOBJ_DTYPE_INT); |
|
29 | - $this->initVar('user_topics', XOBJ_DTYPE_INT); |
|
30 | - $this->initVar('user_digests', XOBJ_DTYPE_INT); |
|
31 | - $this->initVar('user_posts', XOBJ_DTYPE_INT); |
|
32 | - $this->initVar('user_lastpost', XOBJ_DTYPE_INT); |
|
33 | - } |
|
22 | + /** |
|
23 | + * |
|
24 | + */ |
|
25 | + public function __construct() |
|
26 | + { |
|
27 | + parent::__construct(); |
|
28 | + $this->initVar('uid', XOBJ_DTYPE_INT); |
|
29 | + $this->initVar('user_topics', XOBJ_DTYPE_INT); |
|
30 | + $this->initVar('user_digests', XOBJ_DTYPE_INT); |
|
31 | + $this->initVar('user_posts', XOBJ_DTYPE_INT); |
|
32 | + $this->initVar('user_lastpost', XOBJ_DTYPE_INT); |
|
33 | + } |
|
34 | 34 | } |
@@ -61,7 +61,7 @@ |
||
61 | 61 | } |
62 | 62 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
63 | 63 | $grouppermHandler = xoops_getHandler('groupperm'); |
64 | - $criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid'))); |
|
64 | + $criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid'))); |
|
65 | 65 | $criteria->add(new \Criteria('gperm_name', 'category_access')); |
66 | 66 | $criteria->add(new \Criteria('gperm_itemid', $cat_id)); |
67 | 67 |
@@ -23,82 +23,82 @@ |
||
23 | 23 | */ |
24 | 24 | class PermissionCategoryHandler extends Newbb\PermissionHandler |
25 | 25 | { |
26 | - /** |
|
27 | - * @param \XoopsDatabase $db |
|
28 | - */ |
|
29 | - public function __construct(\XoopsDatabase $db = null) |
|
30 | - { |
|
31 | - // $this->PermissionHandler($db); |
|
32 | - parent::__construct($db); |
|
33 | - } |
|
26 | + /** |
|
27 | + * @param \XoopsDatabase $db |
|
28 | + */ |
|
29 | + public function __construct(\XoopsDatabase $db = null) |
|
30 | + { |
|
31 | + // $this->PermissionHandler($db); |
|
32 | + parent::__construct($db); |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param $mid |
|
37 | - * @param int $id |
|
38 | - * @return array |
|
39 | - */ |
|
40 | - public function getValidItems($mid, $id = 0) |
|
41 | - { |
|
42 | - $full_items = []; |
|
43 | - if (empty($mid)) { |
|
44 | - return $full_items; |
|
45 | - } |
|
35 | + /** |
|
36 | + * @param $mid |
|
37 | + * @param int $id |
|
38 | + * @return array |
|
39 | + */ |
|
40 | + public function getValidItems($mid, $id = 0) |
|
41 | + { |
|
42 | + $full_items = []; |
|
43 | + if (empty($mid)) { |
|
44 | + return $full_items; |
|
45 | + } |
|
46 | 46 | |
47 | - $full_items[] = "'category_access'"; |
|
47 | + $full_items[] = "'category_access'"; |
|
48 | 48 | |
49 | - return $full_items; |
|
50 | - } |
|
49 | + return $full_items; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param $cat_id |
|
54 | - * @return bool |
|
55 | - */ |
|
56 | - public function deleteByCategory($cat_id) |
|
57 | - { |
|
58 | - $cat_id = (int)$cat_id; |
|
59 | - if (empty($cat_id)) { |
|
60 | - return false; |
|
61 | - } |
|
62 | - /** @var \XoopsGroupPermHandler $grouppermHandler */ |
|
63 | - $grouppermHandler = xoops_getHandler('groupperm'); |
|
64 | - $criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid'))); |
|
65 | - $criteria->add(new \Criteria('gperm_name', 'category_access')); |
|
66 | - $criteria->add(new \Criteria('gperm_itemid', $cat_id)); |
|
52 | + /** |
|
53 | + * @param $cat_id |
|
54 | + * @return bool |
|
55 | + */ |
|
56 | + public function deleteByCategory($cat_id) |
|
57 | + { |
|
58 | + $cat_id = (int)$cat_id; |
|
59 | + if (empty($cat_id)) { |
|
60 | + return false; |
|
61 | + } |
|
62 | + /** @var \XoopsGroupPermHandler $grouppermHandler */ |
|
63 | + $grouppermHandler = xoops_getHandler('groupperm'); |
|
64 | + $criteria = new \CriteriaCompo(new \Criteria('gperm_modid', $GLOBALS['xoopsModule']->getVar('mid'))); |
|
65 | + $criteria->add(new \Criteria('gperm_name', 'category_access')); |
|
66 | + $criteria->add(new \Criteria('gperm_itemid', $cat_id)); |
|
67 | 67 | |
68 | - return $grouppermHandler->deleteAll($criteria); |
|
69 | - } |
|
68 | + return $grouppermHandler->deleteAll($criteria); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @param $category |
|
73 | - * @param array $groups |
|
74 | - * @return bool |
|
75 | - */ |
|
76 | - public function setCategoryPermission($category, array $groups = []) |
|
77 | - { |
|
78 | - if (is_object($GLOBALS['xoopsModule']) && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) { |
|
79 | - $mid = $GLOBALS['xoopsModule']->getVar('mid'); |
|
80 | - } else { |
|
81 | - /** @var \XoopsModuleHandler $moduleHandler */ |
|
82 | - $moduleHandler = xoops_getHandler('module'); |
|
83 | - $newbb = $moduleHandler->getByDirname('newbb'); |
|
84 | - $mid = $newbb->getVar('mid'); |
|
85 | - } |
|
86 | - if (empty($groups)) { |
|
87 | - /** @var \XoopsMemberHandler $memberHandler */ |
|
88 | - $memberHandler = xoops_getHandler('member'); |
|
89 | - $glist = $memberHandler->getGroupList(); |
|
90 | - $groups = array_keys($glist); |
|
91 | - } |
|
92 | - $ids = $this->getGroupIds('category_access', $category, $mid); |
|
93 | - $ids_add = array_diff($groups, $ids); |
|
94 | - $ids_rmv = array_diff($ids, $groups); |
|
95 | - foreach ($ids_add as $group) { |
|
96 | - $this->addRight('category_access', $category, $group, $mid); |
|
97 | - } |
|
98 | - foreach ($ids_rmv as $group) { |
|
99 | - $this->deleteRight('category_access', $category, $group, $mid); |
|
100 | - } |
|
71 | + /** |
|
72 | + * @param $category |
|
73 | + * @param array $groups |
|
74 | + * @return bool |
|
75 | + */ |
|
76 | + public function setCategoryPermission($category, array $groups = []) |
|
77 | + { |
|
78 | + if (is_object($GLOBALS['xoopsModule']) && 'newbb' === $GLOBALS['xoopsModule']->getVar('dirname')) { |
|
79 | + $mid = $GLOBALS['xoopsModule']->getVar('mid'); |
|
80 | + } else { |
|
81 | + /** @var \XoopsModuleHandler $moduleHandler */ |
|
82 | + $moduleHandler = xoops_getHandler('module'); |
|
83 | + $newbb = $moduleHandler->getByDirname('newbb'); |
|
84 | + $mid = $newbb->getVar('mid'); |
|
85 | + } |
|
86 | + if (empty($groups)) { |
|
87 | + /** @var \XoopsMemberHandler $memberHandler */ |
|
88 | + $memberHandler = xoops_getHandler('member'); |
|
89 | + $glist = $memberHandler->getGroupList(); |
|
90 | + $groups = array_keys($glist); |
|
91 | + } |
|
92 | + $ids = $this->getGroupIds('category_access', $category, $mid); |
|
93 | + $ids_add = array_diff($groups, $ids); |
|
94 | + $ids_rmv = array_diff($ids, $groups); |
|
95 | + foreach ($ids_add as $group) { |
|
96 | + $this->addRight('category_access', $category, $group, $mid); |
|
97 | + } |
|
98 | + foreach ($ids_rmv as $group) { |
|
99 | + $this->deleteRight('category_access', $category, $group, $mid); |
|
100 | + } |
|
101 | 101 | |
102 | - return true; |
|
103 | - } |
|
102 | + return true; |
|
103 | + } |
|
104 | 104 | } |
@@ -17,229 +17,229 @@ |
||
17 | 17 | */ |
18 | 18 | trait FilesManagement |
19 | 19 | { |
20 | - /** |
|
21 | - * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
|
22 | - * |
|
23 | - * @param string $folder The full path of the directory to check |
|
24 | - * |
|
25 | - * @return void |
|
26 | - */ |
|
27 | - public static function createFolder($folder) |
|
28 | - { |
|
29 | - try { |
|
30 | - if (!file_exists($folder)) { |
|
31 | - if (!is_dir($folder) && !mkdir($folder) && !is_dir($folder)) { |
|
32 | - throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
33 | - } |
|
34 | - |
|
35 | - file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
36 | - } |
|
37 | - } catch (\Exception $e) { |
|
38 | - echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
39 | - } |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * @param $file |
|
44 | - * @param $folder |
|
45 | - * @return bool |
|
46 | - */ |
|
47 | - public static function copyFile($file, $folder) |
|
48 | - { |
|
49 | - return copy($file, $folder); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @param $src |
|
54 | - * @param $dst |
|
55 | - */ |
|
56 | - public static function recurseCopy($src, $dst) |
|
57 | - { |
|
58 | - $dir = opendir($src); |
|
59 | - // @mkdir($dst); |
|
60 | - if (!@mkdir($dst) && !is_dir($dst)) { |
|
61 | - throw new \RuntimeException('The directory ' . $dst . ' could not be created.'); |
|
62 | - } |
|
63 | - while (false !== ($file = readdir($dir))) { |
|
64 | - if (('.' !== $file) && ('..' !== $file)) { |
|
65 | - if (is_dir($src . '/' . $file)) { |
|
66 | - self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
|
67 | - } else { |
|
68 | - copy($src . '/' . $file, $dst . '/' . $file); |
|
69 | - } |
|
70 | - } |
|
71 | - } |
|
72 | - closedir($dir); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * |
|
77 | - * Remove files and (sub)directories |
|
78 | - * |
|
79 | - * @param string $src source directory to delete |
|
80 | - * |
|
81 | - * @uses \Xmf\Module\Helper::getHelper() |
|
82 | - * @uses \Xmf\Module\Helper::isUserAdmin() |
|
83 | - * |
|
84 | - * @return bool true on success |
|
85 | - */ |
|
86 | - public static function deleteDirectory($src) |
|
87 | - { |
|
88 | - // Only continue if user is a 'global' Admin |
|
89 | - if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
90 | - return false; |
|
91 | - } |
|
92 | - |
|
93 | - $success = true; |
|
94 | - // remove old files |
|
95 | - $dirInfo = new \SplFileInfo($src); |
|
96 | - // validate is a directory |
|
97 | - if ($dirInfo->isDir()) { |
|
98 | - $fileList = array_diff(scandir($src, SCANDIR_SORT_NONE), ['..', '.']); |
|
99 | - foreach ($fileList as $k => $v) { |
|
100 | - $fileInfo = new \SplFileInfo("{$src}/{$v}"); |
|
101 | - if ($fileInfo->isDir()) { |
|
102 | - // recursively handle subdirectories |
|
103 | - if (!$success = self::deleteDirectory($fileInfo->getRealPath())) { |
|
104 | - break; |
|
105 | - } |
|
106 | - } else { |
|
107 | - // delete the file |
|
108 | - if (!($success = unlink($fileInfo->getRealPath()))) { |
|
109 | - break; |
|
110 | - } |
|
111 | - } |
|
112 | - } |
|
113 | - // now delete this (sub)directory if all the files are gone |
|
114 | - if ($success) { |
|
115 | - $success = rmdir($dirInfo->getRealPath()); |
|
116 | - } |
|
117 | - } else { |
|
118 | - // input is not a valid directory |
|
119 | - $success = false; |
|
120 | - } |
|
121 | - return $success; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * |
|
126 | - * Recursively remove directory |
|
127 | - * |
|
128 | - * @todo currently won't remove directories with hidden files, should it? |
|
129 | - * |
|
130 | - * @param string $src directory to remove (delete) |
|
131 | - * |
|
132 | - * @return bool true on success |
|
133 | - */ |
|
134 | - public static function rrmdir($src) |
|
135 | - { |
|
136 | - // Only continue if user is a 'global' Admin |
|
137 | - if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
138 | - return false; |
|
139 | - } |
|
140 | - |
|
141 | - // If source is not a directory stop processing |
|
142 | - if (!is_dir($src)) { |
|
143 | - return false; |
|
144 | - } |
|
145 | - |
|
146 | - $success = true; |
|
147 | - |
|
148 | - // Open the source directory to read in files |
|
149 | - $iterator = new \DirectoryIterator($src); |
|
150 | - foreach ($iterator as $fObj) { |
|
151 | - if ($fObj->isFile()) { |
|
152 | - $filename = $fObj->getPathname(); |
|
153 | - $fObj = null; // clear this iterator object to close the file |
|
154 | - if (!unlink($filename)) { |
|
155 | - return false; // couldn't delete the file |
|
156 | - } |
|
157 | - } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
158 | - // Try recursively on directory |
|
159 | - self::rrmdir($fObj->getPathname()); |
|
160 | - } |
|
161 | - } |
|
162 | - $iterator = null; // clear iterator Obj to close file/directory |
|
163 | - return rmdir($src); // remove the directory & return results |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Recursively move files from one directory to another |
|
168 | - * |
|
169 | - * @param string $src - Source of files being moved |
|
170 | - * @param string $dest - Destination of files being moved |
|
171 | - * |
|
172 | - * @return bool true on success |
|
173 | - */ |
|
174 | - public static function rmove($src, $dest) |
|
175 | - { |
|
176 | - // Only continue if user is a 'global' Admin |
|
177 | - if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
178 | - return false; |
|
179 | - } |
|
180 | - |
|
181 | - // If source is not a directory stop processing |
|
182 | - if (!is_dir($src)) { |
|
183 | - return false; |
|
184 | - } |
|
185 | - |
|
186 | - // If the destination directory does not exist and could not be created stop processing |
|
187 | - if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) { |
|
188 | - return false; |
|
189 | - } |
|
190 | - |
|
191 | - // Open the source directory to read in files |
|
192 | - $iterator = new \DirectoryIterator($src); |
|
193 | - foreach ($iterator as $fObj) { |
|
194 | - if ($fObj->isFile()) { |
|
195 | - rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
196 | - } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
197 | - // Try recursively on directory |
|
198 | - self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
199 | - // rmdir($fObj->getPath()); // now delete the directory |
|
200 | - } |
|
201 | - } |
|
202 | - $iterator = null; // clear iterator Obj to close file/directory |
|
203 | - return rmdir($src); // remove the directory & return results |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * Recursively copy directories and files from one directory to another |
|
208 | - * |
|
209 | - * @param string $src - Source of files being moved |
|
210 | - * @param string $dest - Destination of files being moved |
|
211 | - * |
|
212 | - * @uses \Xmf\Module\Helper::getHelper() |
|
213 | - * @uses \Xmf\Module\Helper::isUserAdmin() |
|
214 | - * |
|
215 | - * @return bool true on success |
|
216 | - */ |
|
217 | - public static function rcopy($src, $dest) |
|
218 | - { |
|
219 | - // Only continue if user is a 'global' Admin |
|
220 | - if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
221 | - return false; |
|
222 | - } |
|
223 | - |
|
224 | - // If source is not a directory stop processing |
|
225 | - if (!is_dir($src)) { |
|
226 | - return false; |
|
227 | - } |
|
228 | - |
|
229 | - // If the destination directory does not exist and could not be created stop processing |
|
230 | - if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) { |
|
231 | - return false; |
|
232 | - } |
|
233 | - |
|
234 | - // Open the source directory to read in files |
|
235 | - $iterator = new \DirectoryIterator($src); |
|
236 | - foreach ($iterator as $fObj) { |
|
237 | - if ($fObj->isFile()) { |
|
238 | - copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
239 | - } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
240 | - self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
241 | - } |
|
242 | - } |
|
243 | - return true; |
|
244 | - } |
|
20 | + /** |
|
21 | + * Function responsible for checking if a directory exists, we can also write in and create an index.html file |
|
22 | + * |
|
23 | + * @param string $folder The full path of the directory to check |
|
24 | + * |
|
25 | + * @return void |
|
26 | + */ |
|
27 | + public static function createFolder($folder) |
|
28 | + { |
|
29 | + try { |
|
30 | + if (!file_exists($folder)) { |
|
31 | + if (!is_dir($folder) && !mkdir($folder) && !is_dir($folder)) { |
|
32 | + throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
|
33 | + } |
|
34 | + |
|
35 | + file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
36 | + } |
|
37 | + } catch (\Exception $e) { |
|
38 | + echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
39 | + } |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * @param $file |
|
44 | + * @param $folder |
|
45 | + * @return bool |
|
46 | + */ |
|
47 | + public static function copyFile($file, $folder) |
|
48 | + { |
|
49 | + return copy($file, $folder); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @param $src |
|
54 | + * @param $dst |
|
55 | + */ |
|
56 | + public static function recurseCopy($src, $dst) |
|
57 | + { |
|
58 | + $dir = opendir($src); |
|
59 | + // @mkdir($dst); |
|
60 | + if (!@mkdir($dst) && !is_dir($dst)) { |
|
61 | + throw new \RuntimeException('The directory ' . $dst . ' could not be created.'); |
|
62 | + } |
|
63 | + while (false !== ($file = readdir($dir))) { |
|
64 | + if (('.' !== $file) && ('..' !== $file)) { |
|
65 | + if (is_dir($src . '/' . $file)) { |
|
66 | + self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
|
67 | + } else { |
|
68 | + copy($src . '/' . $file, $dst . '/' . $file); |
|
69 | + } |
|
70 | + } |
|
71 | + } |
|
72 | + closedir($dir); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * |
|
77 | + * Remove files and (sub)directories |
|
78 | + * |
|
79 | + * @param string $src source directory to delete |
|
80 | + * |
|
81 | + * @uses \Xmf\Module\Helper::getHelper() |
|
82 | + * @uses \Xmf\Module\Helper::isUserAdmin() |
|
83 | + * |
|
84 | + * @return bool true on success |
|
85 | + */ |
|
86 | + public static function deleteDirectory($src) |
|
87 | + { |
|
88 | + // Only continue if user is a 'global' Admin |
|
89 | + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
90 | + return false; |
|
91 | + } |
|
92 | + |
|
93 | + $success = true; |
|
94 | + // remove old files |
|
95 | + $dirInfo = new \SplFileInfo($src); |
|
96 | + // validate is a directory |
|
97 | + if ($dirInfo->isDir()) { |
|
98 | + $fileList = array_diff(scandir($src, SCANDIR_SORT_NONE), ['..', '.']); |
|
99 | + foreach ($fileList as $k => $v) { |
|
100 | + $fileInfo = new \SplFileInfo("{$src}/{$v}"); |
|
101 | + if ($fileInfo->isDir()) { |
|
102 | + // recursively handle subdirectories |
|
103 | + if (!$success = self::deleteDirectory($fileInfo->getRealPath())) { |
|
104 | + break; |
|
105 | + } |
|
106 | + } else { |
|
107 | + // delete the file |
|
108 | + if (!($success = unlink($fileInfo->getRealPath()))) { |
|
109 | + break; |
|
110 | + } |
|
111 | + } |
|
112 | + } |
|
113 | + // now delete this (sub)directory if all the files are gone |
|
114 | + if ($success) { |
|
115 | + $success = rmdir($dirInfo->getRealPath()); |
|
116 | + } |
|
117 | + } else { |
|
118 | + // input is not a valid directory |
|
119 | + $success = false; |
|
120 | + } |
|
121 | + return $success; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * |
|
126 | + * Recursively remove directory |
|
127 | + * |
|
128 | + * @todo currently won't remove directories with hidden files, should it? |
|
129 | + * |
|
130 | + * @param string $src directory to remove (delete) |
|
131 | + * |
|
132 | + * @return bool true on success |
|
133 | + */ |
|
134 | + public static function rrmdir($src) |
|
135 | + { |
|
136 | + // Only continue if user is a 'global' Admin |
|
137 | + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
138 | + return false; |
|
139 | + } |
|
140 | + |
|
141 | + // If source is not a directory stop processing |
|
142 | + if (!is_dir($src)) { |
|
143 | + return false; |
|
144 | + } |
|
145 | + |
|
146 | + $success = true; |
|
147 | + |
|
148 | + // Open the source directory to read in files |
|
149 | + $iterator = new \DirectoryIterator($src); |
|
150 | + foreach ($iterator as $fObj) { |
|
151 | + if ($fObj->isFile()) { |
|
152 | + $filename = $fObj->getPathname(); |
|
153 | + $fObj = null; // clear this iterator object to close the file |
|
154 | + if (!unlink($filename)) { |
|
155 | + return false; // couldn't delete the file |
|
156 | + } |
|
157 | + } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
158 | + // Try recursively on directory |
|
159 | + self::rrmdir($fObj->getPathname()); |
|
160 | + } |
|
161 | + } |
|
162 | + $iterator = null; // clear iterator Obj to close file/directory |
|
163 | + return rmdir($src); // remove the directory & return results |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Recursively move files from one directory to another |
|
168 | + * |
|
169 | + * @param string $src - Source of files being moved |
|
170 | + * @param string $dest - Destination of files being moved |
|
171 | + * |
|
172 | + * @return bool true on success |
|
173 | + */ |
|
174 | + public static function rmove($src, $dest) |
|
175 | + { |
|
176 | + // Only continue if user is a 'global' Admin |
|
177 | + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
178 | + return false; |
|
179 | + } |
|
180 | + |
|
181 | + // If source is not a directory stop processing |
|
182 | + if (!is_dir($src)) { |
|
183 | + return false; |
|
184 | + } |
|
185 | + |
|
186 | + // If the destination directory does not exist and could not be created stop processing |
|
187 | + if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) { |
|
188 | + return false; |
|
189 | + } |
|
190 | + |
|
191 | + // Open the source directory to read in files |
|
192 | + $iterator = new \DirectoryIterator($src); |
|
193 | + foreach ($iterator as $fObj) { |
|
194 | + if ($fObj->isFile()) { |
|
195 | + rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
196 | + } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
197 | + // Try recursively on directory |
|
198 | + self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
199 | + // rmdir($fObj->getPath()); // now delete the directory |
|
200 | + } |
|
201 | + } |
|
202 | + $iterator = null; // clear iterator Obj to close file/directory |
|
203 | + return rmdir($src); // remove the directory & return results |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * Recursively copy directories and files from one directory to another |
|
208 | + * |
|
209 | + * @param string $src - Source of files being moved |
|
210 | + * @param string $dest - Destination of files being moved |
|
211 | + * |
|
212 | + * @uses \Xmf\Module\Helper::getHelper() |
|
213 | + * @uses \Xmf\Module\Helper::isUserAdmin() |
|
214 | + * |
|
215 | + * @return bool true on success |
|
216 | + */ |
|
217 | + public static function rcopy($src, $dest) |
|
218 | + { |
|
219 | + // Only continue if user is a 'global' Admin |
|
220 | + if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) { |
|
221 | + return false; |
|
222 | + } |
|
223 | + |
|
224 | + // If source is not a directory stop processing |
|
225 | + if (!is_dir($src)) { |
|
226 | + return false; |
|
227 | + } |
|
228 | + |
|
229 | + // If the destination directory does not exist and could not be created stop processing |
|
230 | + if (!is_dir($dest) && !mkdir($dest) && !is_dir($dest)) { |
|
231 | + return false; |
|
232 | + } |
|
233 | + |
|
234 | + // Open the source directory to read in files |
|
235 | + $iterator = new \DirectoryIterator($src); |
|
236 | + foreach ($iterator as $fObj) { |
|
237 | + if ($fObj->isFile()) { |
|
238 | + copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
239 | + } elseif (!$fObj->isDot() && $fObj->isDir()) { |
|
240 | + self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
241 | + } |
|
242 | + } |
|
243 | + return true; |
|
244 | + } |
|
245 | 245 | } |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | throw new \RuntimeException(sprintf('Unable to create the %s directory', $folder)); |
33 | 33 | } |
34 | 34 | |
35 | - file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>'); |
|
35 | + file_put_contents($folder.'/index.html', '<script>history.go(-1);</script>'); |
|
36 | 36 | } |
37 | 37 | } catch (\Exception $e) { |
38 | 38 | echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
@@ -58,14 +58,14 @@ discard block |
||
58 | 58 | $dir = opendir($src); |
59 | 59 | // @mkdir($dst); |
60 | 60 | if (!@mkdir($dst) && !is_dir($dst)) { |
61 | - throw new \RuntimeException('The directory ' . $dst . ' could not be created.'); |
|
61 | + throw new \RuntimeException('The directory '.$dst.' could not be created.'); |
|
62 | 62 | } |
63 | 63 | while (false !== ($file = readdir($dir))) { |
64 | 64 | if (('.' !== $file) && ('..' !== $file)) { |
65 | - if (is_dir($src . '/' . $file)) { |
|
66 | - self::recurseCopy($src . '/' . $file, $dst . '/' . $file); |
|
65 | + if (is_dir($src.'/'.$file)) { |
|
66 | + self::recurseCopy($src.'/'.$file, $dst.'/'.$file); |
|
67 | 67 | } else { |
68 | - copy($src . '/' . $file, $dst . '/' . $file); |
|
68 | + copy($src.'/'.$file, $dst.'/'.$file); |
|
69 | 69 | } |
70 | 70 | } |
71 | 71 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | self::rrmdir($fObj->getPathname()); |
160 | 160 | } |
161 | 161 | } |
162 | - $iterator = null; // clear iterator Obj to close file/directory |
|
162 | + $iterator = null; // clear iterator Obj to close file/directory |
|
163 | 163 | return rmdir($src); // remove the directory & return results |
164 | 164 | } |
165 | 165 | |
@@ -192,14 +192,14 @@ discard block |
||
192 | 192 | $iterator = new \DirectoryIterator($src); |
193 | 193 | foreach ($iterator as $fObj) { |
194 | 194 | if ($fObj->isFile()) { |
195 | - rename($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
195 | + rename($fObj->getPathname(), "{$dest}/".$fObj->getFilename()); |
|
196 | 196 | } elseif (!$fObj->isDot() && $fObj->isDir()) { |
197 | 197 | // Try recursively on directory |
198 | - self::rmove($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
198 | + self::rmove($fObj->getPathname(), "{$dest}/".$fObj->getFilename()); |
|
199 | 199 | // rmdir($fObj->getPath()); // now delete the directory |
200 | 200 | } |
201 | 201 | } |
202 | - $iterator = null; // clear iterator Obj to close file/directory |
|
202 | + $iterator = null; // clear iterator Obj to close file/directory |
|
203 | 203 | return rmdir($src); // remove the directory & return results |
204 | 204 | } |
205 | 205 | |
@@ -235,9 +235,9 @@ discard block |
||
235 | 235 | $iterator = new \DirectoryIterator($src); |
236 | 236 | foreach ($iterator as $fObj) { |
237 | 237 | if ($fObj->isFile()) { |
238 | - copy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
238 | + copy($fObj->getPathname(), "{$dest}/".$fObj->getFilename()); |
|
239 | 239 | } elseif (!$fObj->isDot() && $fObj->isDir()) { |
240 | - self::rcopy($fObj->getPathname(), "{$dest}/" . $fObj->getFilename()); |
|
240 | + self::rcopy($fObj->getPathname(), "{$dest}/".$fObj->getFilename()); |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | return true; |
@@ -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 |
@@ -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 = null) |
|
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 = null) |
|
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 | } |
@@ -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 | } |
@@ -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 |
@@ -11,42 +11,42 @@ |
||
11 | 11 | */ |
12 | 12 | class KarmaHandler |
13 | 13 | { |
14 | - /** |
|
15 | - * @param null $user |
|
16 | - * @return int |
|
17 | - */ |
|
18 | - public function getUserKarma($user = null) |
|
19 | - { |
|
20 | - $user = (null === $user) ? $GLOBALS['xoopsUser'] : $user; |
|
14 | + /** |
|
15 | + * @param null $user |
|
16 | + * @return int |
|
17 | + */ |
|
18 | + public function getUserKarma($user = null) |
|
19 | + { |
|
20 | + $user = (null === $user) ? $GLOBALS['xoopsUser'] : $user; |
|
21 | 21 | |
22 | - return $this->calculateUserKarma($user); |
|
23 | - } |
|
22 | + return $this->calculateUserKarma($user); |
|
23 | + } |
|
24 | 24 | |
25 | - /** |
|
26 | - * Placeholder for calculating user karma |
|
27 | - * @param \XoopsUser $user |
|
28 | - * @return int |
|
29 | - */ |
|
30 | - public function calculateUserKarma($user) |
|
31 | - { |
|
32 | - if (!is_object($user)) { |
|
33 | - $user_karma = 0; |
|
34 | - } else { |
|
35 | - $user_karma = $user->getVar('posts') * 50; |
|
36 | - } |
|
25 | + /** |
|
26 | + * Placeholder for calculating user karma |
|
27 | + * @param \XoopsUser $user |
|
28 | + * @return int |
|
29 | + */ |
|
30 | + public function calculateUserKarma($user) |
|
31 | + { |
|
32 | + if (!is_object($user)) { |
|
33 | + $user_karma = 0; |
|
34 | + } else { |
|
35 | + $user_karma = $user->getVar('posts') * 50; |
|
36 | + } |
|
37 | 37 | |
38 | - return $user_karma; |
|
39 | - } |
|
38 | + return $user_karma; |
|
39 | + } |
|
40 | 40 | |
41 | - public function updateUserKarma() |
|
42 | - { |
|
43 | - } |
|
41 | + public function updateUserKarma() |
|
42 | + { |
|
43 | + } |
|
44 | 44 | |
45 | - public function writeUserKarma() |
|
46 | - { |
|
47 | - } |
|
45 | + public function writeUserKarma() |
|
46 | + { |
|
47 | + } |
|
48 | 48 | |
49 | - public function readUserKarma() |
|
50 | - { |
|
51 | - } |
|
49 | + public function readUserKarma() |
|
50 | + { |
|
51 | + } |
|
52 | 52 | } |
@@ -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; |
@@ -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 | } |
@@ -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 = null) |
|
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 = null) |
|
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 | } |
@@ -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); |
@@ -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 (null === $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 (null === $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 | } |