/** * Import all attachments for this post * @param disPost $post * @param array $prow * @return array */ public function importAttachments(disPost $post, array $prow = array()) { $ast = $this->pdo->query(' SELECT * FROM ' . $this->getFullTableName('attachments') . ' WHERE `ID_MSG` = ' . $prow['ID_MSG'] . ' '); if (!$ast) { return array(); } $aIdx = 0; while ($arow = $ast->fetch(PDO::FETCH_ASSOC)) { $this->log('Adding attachment: ' . $arow['filename']); /** @var disPostAttachment $attachment */ $attachment = $this->modx->newObject('disPostAttachment'); $attachment->fromArray(array('post' => $post->get('id'), 'board' => $post->get('board'), 'filename' => $arow['filename'], 'filesize' => $arow['size'], 'downloads' => $arow['downloads'], 'integrated_id' => $arow['ID_ATTACH'], 'integrated_data' => $this->modx->toJSON(array('filename' => $arow['filename'], 'file_hash' => $arow['file_hash'], 'width' => $arow['width'], 'height' => $arow['height'], 'attachmentType' => $arow['attachmentType'], 'ID_MEMBER' => $arow['ID_MEMBER'], 'ID_MESSAGE' => !empty($arow['ID_MESSAGE']) ? $arow['ID_MESSAGE'] : 0, 'ID_THUMB' => $arow['ID_THUMB'])))); if ($this->config['live']) { $attachment->save(); } $aIdx++; } $ast->closeCursor(); }
public function setUp() { parent::setUp(); $this->post = $this->modx->newObject('disPost'); $this->post->fromArray(array('id' => 12345, 'title' => 'Unit Test Parser Post'), '', true, true); $this->post->loadParser(); $this->parser =& $this->post->parser; }
public function process() { $this->setPlaceholders($this->thread->toArray()); if ($this->post->remove()) { $this->discuss->logActivity('message_post_remove', $this->post->toArray(), $this->post->getUrl()); $posts = $this->thread->getMany('Posts'); if (count($posts) <= 0) { $url = $this->discuss->request->makeUrl('messages'); } else { $url = $this->discuss->request->makeUrl('messages/view', array('thread' => $this->thread->get('id'))); } $this->modx->sendRedirect($url); } }
/** * Send a spam report via email * @return void */ public function report() { $author = $this->post->getOne('Author'); /* setup default properties */ $subject = $this->modx->getOption('subject', $this->scriptProperties, $this->modx->getOption('discuss.email_reported_post_subject', null, 'Reported Post: [[+title]]')); $subject = str_replace('[[+title]]', $this->post->get('title'), $subject); $tpl = $this->modx->getOption('tpl', $this->scriptProperties, $this->modx->getOption('discuss.email_reported_post_chunk', null, 'emails/disReportedEmail')); /* build post url */ $url = $this->post->getUrl(); /* setup email properties */ $emailProperties = array_merge($this->scriptProperties, $this->post->toArray()); $emailProperties['tpl'] = $tpl; $emailProperties['title'] = $this->post->get('title'); if ($author) { $emailProperties['author'] = $author->get('username'); } $emailProperties['reporter'] = $this->discuss->user->get('username'); $emailProperties['url'] = $url; $emailProperties['forum_title'] = $this->modx->getOption('discuss.forum_title'); $emailProperties['message'] = nl2br(strip_tags($this->scriptProperties['message'])); /* send reported email */ $moderators = $this->thread->getModerators(); /** @var disUser $moderator */ foreach ($moderators as $moderator) { $sent = $this->discuss->sendEmail($moderator->get('email'), $moderator->get('username'), $subject, $emailProperties); } unset($emailProperties); $this->discuss->logActivity('post_report', $this->post->toArray(), $this->post->getUrl()); /* redirect to thread */ $this->modx->sendRedirect($url); }
/** * Handle Quote functionality that will append the quoted post into the initial message * @return void */ public function handleQuote() { if (empty($_POST) && !empty($this->scriptProperties['quote'])) { $message = str_replace(array('[', ']'), array('[', ']'), $this->post->br2nl($this->post->get('message'))); $message = '[quote author=' . $this->author->get('username') . ' date=' . strtotime($this->post->get('createdon')) . ']' . $message . '[/quote]' . "\n"; $this->setPlaceholder('message', $message); } elseif (empty($_POST) && empty($this->scriptProperties['quote'])) { $this->setPlaceholder('message', ''); } }
public function process() { if (!$this->post->remove(array(), true, true)) { $this->modx->log(modX::LOG_LEVEL_ERROR, '[Discuss] Could not remove post: ' . print_r($this->post->toArray(), true)); } else { $this->discuss->logActivity('post_spam_remove', $this->post->toArray(), $this->post->getUrl()); } if ($this->thread->get('post_first') == $this->post->get('id')) { $redirectTo = $this->discuss->request->makeUrl('board', array('board' => $this->post->get('board'))); } else { $redirectTo = $this->thread->getUrl(); } $this->modx->sendRedirect($redirectTo); }
public function getBreadcrumbs() { /* build breadcrumbs */ $trail = ''; if (empty($this->board)) { $this->board = $this->thread->getOne('Board'); } if ($this->board) { $default = array(); if (!empty($this->options['showTitleInBreadcrumbs'])) { $default[] = array('text' => $this->modx->lexicon('discuss.modify_post_header', array('post' => $this->post->get('title'))), 'active' => true); } $this->board->buildBreadcrumbs($default, true); $trail = $this->board->get('trail'); } return $trail; }
public function process() { if (!$this->post->remove(array(), true)) { $this->modx->log(modX::LOG_LEVEL_ERROR, '[Discuss] Could not remove post: ' . print_r($this->post->toArray(), true)); } else { $this->discuss->logActivity('post_remove', $this->post->toArray(), $this->post->getUrl()); } /* If the thread no longer exists (last post in thread was removed), redirect to the board instead of thread */ if ($this->modx->getCount('disThread', $this->thread->get('id')) < 1) { $redirectTo = $this->discuss->request->makeUrl('board', array('board' => $this->post->get('board'))); } else { $redirectTo = $this->thread->getUrl(); } $this->modx->sendRedirect($redirectTo); }
/** * Get the last post of the thread and set it as a placeholder * @return void */ public function getLastPost() { $this->lastPost = $this->thread->getOne('LastPost'); $lastPostArray = $this->lastPost->toArray('lastPost.'); $this->setPlaceholders($lastPostArray); }
public function getBreadcrumbs() { $trail = array(array('url' => $this->discuss->request->makeUrl(), 'text' => $this->modx->getOption('discuss.forum_title')), array('text' => $this->modx->lexicon('discuss.messages'), 'url' => $this->discuss->request->makeUrl('messages')), array('text' => $this->post->get('title'), 'url' => $this->discuss->request->makeUrl('messages/view', array('thread' => $this->thread->get('id')))), array('text' => $this->modx->lexicon('discuss.modify'), 'active' => true)); return $trail; }