mambax7 /
newbb5
| 1 | <?php namespace XoopsModules\Newbb; |
||||
| 2 | |||||
| 3 | // |
||||
| 4 | // ------------------------------------------------------------------------ // |
||||
| 5 | // XOOPS - PHP Content Management System // |
||||
| 6 | // Copyright (c) 2000-2016 XOOPS.org // |
||||
| 7 | // <https://xoops.org/> // |
||||
| 8 | // ------------------------------------------------------------------------ // |
||||
| 9 | // This program is free software; you can redistribute it and/or modify // |
||||
| 10 | // it under the terms of the GNU General Public License as published by // |
||||
| 11 | // the Free Software Foundation; either version 2 of the License, or // |
||||
| 12 | // (at your option) any later version. // |
||||
| 13 | // // |
||||
| 14 | // You may not change or alter any portion of this comment or credits // |
||||
| 15 | // of supporting developers from this source code or any supporting // |
||||
| 16 | // source code which is considered copyrighted (c) material of the // |
||||
| 17 | // original comment or credit authors. // |
||||
| 18 | // // |
||||
| 19 | // This program is distributed in the hope that it will be useful, // |
||||
| 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
||||
| 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
||||
| 22 | // GNU General Public License for more details. // |
||||
| 23 | // // |
||||
| 24 | // You should have received a copy of the GNU General Public License // |
||||
| 25 | // along with this program; if not, write to the Free Software // |
||||
| 26 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
||||
| 27 | // ------------------------------------------------------------------------ // |
||||
| 28 | // Author: phppp (D.J., [email protected]) // |
||||
| 29 | // URL: https://xoops.org // |
||||
| 30 | // Project: Article Project // |
||||
| 31 | // ------------------------------------------------------------------------ // |
||||
| 32 | |||||
| 33 | use Xmf\Highlighter; |
||||
| 34 | use Xmf\Request; |
||||
| 35 | use XoopsModules\Newbb; |
||||
| 36 | |||||
| 37 | // defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
||||
| 38 | |||||
| 39 | defined('NEWBB_FUNCTIONS_INI') || include $GLOBALS['xoops']->path('modules/newbb/include/functions.ini.php'); |
||||
| 40 | |||||
| 41 | /** |
||||
| 42 | * Class Post |
||||
| 43 | */ |
||||
| 44 | class Post extends \XoopsObject |
||||
|
0 ignored issues
–
show
|
|||||
| 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); |
||||
|
0 ignored issues
–
show
|
|||||
| 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, ''); |
||||
|
0 ignored issues
–
show
|
|||||
| 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, ''); |
||||
|
0 ignored issues
–
show
|
|||||
| 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'; |
||||
|
0 ignored issues
–
show
|
|||||
| 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>'; |
||||
|
0 ignored issues
–
show
The function
formatTimestamp was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 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 __DIR__ . '/../include/functions.user.php'; |
||||
| 385 | require_once __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'); |
||||
|
0 ignored issues
–
show
The function
xoops_getHandler was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 407 | $eachposter = $memberHandler->getUser($this->getVar('uid')); |
||||
| 408 | if (is_object($eachposter) && $eachposter->isActive()) { |
||||
| 409 | if ($newbbConfig['show_realname'] && $eachposter->getVar('name')) { |
||||
| 410 | $post['author'] = $eachposter->getVar('name'); |
||||
| 411 | } else { |
||||
| 412 | $post['author'] = $eachposter->getVar('uname'); |
||||
| 413 | } |
||||
| 414 | unset($eachposter); |
||||
| 415 | } else { |
||||
| 416 | $post['author'] = $this->getVar('poster_name') ?: $GLOBALS['xoopsConfig']['anonymous']; |
||||
| 417 | } |
||||
| 418 | |||||
| 419 | $post['subject'] = newbbHtmlspecialchars($this->vars['subject']['value']); |
||||
| 420 | |||||
| 421 | $post['date'] = $this->getVar('post_time'); |
||||
| 422 | |||||
| 423 | return $post; |
||||
| 424 | } |
||||
| 425 | |||||
| 426 | /** |
||||
| 427 | * @return bool |
||||
| 428 | */ |
||||
| 429 | public function isTopic() |
||||
| 430 | { |
||||
| 431 | return !$this->getVar('pid'); |
||||
| 432 | } |
||||
| 433 | |||||
| 434 | /** |
||||
| 435 | * @param string $action_tag |
||||
| 436 | * @return bool |
||||
| 437 | */ |
||||
| 438 | public function checkTimelimit($action_tag = 'edit_timelimit') |
||||
| 439 | { |
||||
| 440 | $newbbConfig = newbbLoadConfig(); |
||||
| 441 | if (empty($newbbConfig['edit_timelimit'])) { |
||||
| 442 | return true; |
||||
| 443 | } |
||||
| 444 | |||||
| 445 | return ($this->getVar('post_time') > time() - $newbbConfig[$action_tag] * 60); |
||||
| 446 | } |
||||
| 447 | |||||
| 448 | /** |
||||
| 449 | * @param int $uid |
||||
| 450 | * @return bool |
||||
| 451 | */ |
||||
| 452 | public function checkIdentity($uid = -1) |
||||
| 453 | { |
||||
| 454 | $uid = ($uid > -1) ? $uid : (is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getVar('uid') : 0); |
||||
| 455 | if ($this->getVar('uid') > 0) { |
||||
| 456 | $user_ok = ($uid == $this->getVar('uid')); |
||||
| 457 | } else { |
||||
| 458 | static $user_ip; |
||||
| 459 | if (!isset($user_ip)) { |
||||
| 460 | $user_ip = \Xmf\IPAddress::fromRequest()->asReadable(); |
||||
| 461 | } |
||||
| 462 | $user_ok = ($user_ip == $this->getVar('poster_ip')); |
||||
| 463 | } |
||||
| 464 | |||||
| 465 | return $user_ok; |
||||
| 466 | } |
||||
| 467 | |||||
| 468 | // TODO: cleaning up and merge with post hanldings in viewpost.php |
||||
| 469 | |||||
| 470 | /** |
||||
| 471 | * @param $isAdmin |
||||
| 472 | * @return array |
||||
| 473 | */ |
||||
| 474 | public function showPost($isAdmin) |
||||
| 475 | { |
||||
| 476 | global $xoopsModule, $myts; |
||||
| 477 | global $forumUrl, $forumImage, $forumObject, $online, $viewmode; |
||||
| 478 | global $viewtopic_users, $viewtopic_posters, $topicObject, $user_karma; |
||||
| 479 | global $order, $start, $total_posts, $topic_status; |
||||
| 480 | static $post_NO = 0; |
||||
| 481 | static $name_anonymous; |
||||
| 482 | /** @var TopicHandler $topicHandler */ |
||||
| 483 | $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
||||
| 484 | if (!isset($name_anonymous)) { |
||||
| 485 | $name_anonymous = $myts->htmlSpecialChars($GLOBALS['xoopsConfig']['anonymous']); |
||||
| 486 | } |
||||
| 487 | |||||
| 488 | require_once __DIR__ . '/../include/functions.time.php'; |
||||
| 489 | require_once __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>'; |
||||
|
0 ignored issues
–
show
|
|||||
| 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); |
||||
|
0 ignored issues
–
show
|
|||||
| 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); |
||||
|
0 ignored issues
–
show
|
|||||
| 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') |
||||
|
0 ignored issues
–
show
|
|||||
| 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 | } |
||||
| 715 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths