/** * Creates a poll. * This static function handles the saving of a newly created * poll into the database. This includes storing the poll record * itself as well as creating the regarding answering possibilities. * * @param array $data The poll data array * @param tx_mmforum_base $pObj * @return int The newly created poll's UID * @version 2007-05-25 */ function createPoll($data, $pObj) { $defACount = $pObj->conf['polls.']['minAnswers']; if (!$pObj->conf['polls.']['enable']) { return $pObj->pi_getLL('poll.disabled'); } if (!tx_mmforum_polls::getMayCreatePoll($pObj)) { return $pObj->pi_getLL('poll.restricted'); } if (strlen(trim($data['question'])) == 0) { return $pObj->pi_getLL('poll.noQuestion'); } $answerCount = 0; foreach ($data['answer']['new'] as $answer) { if (strlen(trim($answer)) > 0) { $answerCount++; } } if ($answerCount < $defACount) { return sprintf($pObj->pi_getLL('poll.noAnswers'), $defACount); } if ($data['expires']['act']) { $expDate = mktime($data['expires']['hour'], $data['expires']['minute'], 0, $data['expires']['month'], $data['expires']['day'], $data['expires']['year']); } else { $expDate = 0; } $pollInsertData = array('pid' => $pObj->getStoragePID(), 'tstamp' => $GLOBALS['EXEC_TIME'], 'crdate' => $GLOBALS['EXEC_TIME'], 'crfeuser_id' => $GLOBALS['TSFE']->fe_user->user['uid'], 'votes' => 0, 'question' => trim($data['question']), 'endtime' => $expDate); $this->databaseHandle->exec_INSERTquery('tx_mmforum_polls', $pollInsertData); $poll_id = $this->databaseHandle->sql_insert_id(); foreach ($data['answer']['new'] as $answer) { $answer = trim($answer); if (strlen($answer) == 0) { continue; } $answerInsertData = array('pid' => $pObj->getStoragePID(), 'tstamp' => $GLOBALS['EXEC_TIME'], 'crdate' => $GLOBALS['EXEC_TIME'], 'poll_id' => $poll_id, 'votes' => 0, 'answer' => $answer); $this->databaseHandle->exec_INSERTquery('tx_mmforum_polls_answers', $answerInsertData); } return $poll_id; }
/** * Displays the form for editing an existing post. Regular users can only edit their own * posts if they have not been answered yet. Moderators and administrators can edit all * posts, regardless if they have been answered or not. * @param string $content The plugin content * @param array $conf The plugin's configuration vars * @return string The content */ function post_edit($content, $conf) { $postId = intval($this->piVars['pid']); $this->generateToken(); // Get topic UID $res = $this->databaseHandle->exec_SELECTquery('*', 'tx_mmforum_posts', 'deleted=0 AND hidden=0 AND uid=' . $postId . $this->getStoragePIDQuery()); $row = $this->databaseHandle->sql_fetch_assoc($res); $topicId = $row['topic_id']; $forumId = $row['forum_id']; // Determine, if edited post is the last post in topic $res = $this->databaseHandle->exec_SELECTquery('MAX(post_time)', 'tx_mmforum_posts', 'deleted=0 AND hidden=0 AND topic_id=' . $topicId . $this->getStoragePIDQuery()); list($lastpostdate) = $this->databaseHandle->sql_fetch_row($res); // Determine if edited post is the first post in topic $res = $this->databaseHandle->exec_SELECTquery('uid', 'tx_mmforum_posts', 'deleted=0 AND hidden=0 AND topic_id=' . $topicId . ' ' . $this->getStoragePIDQuery(), '', 'post_time ASC'); list($firstPostId) = $this->databaseHandle->sql_fetch_row($res); $firstPost = $postId === intval($firstPostId); // Load topic data $res = $this->databaseHandle->exec_SELECTquery('*', 'tx_mmforum_topics', 'deleted=0 AND hidden=0 AND uid=' . $topicId . $this->getStoragePIDQuery()); $topicData = $this->databaseHandle->sql_fetch_assoc($res); $previewContent = ''; if ($row['poster_id'] == $GLOBALS['TSFE']->fe_user->user['uid'] && $lastpostdate == $row['post_time'] && $topicData['closed_flag'] != 1 or $this->getIsAdmin() or $this->getIsMod($row['forum_id'])) { //Check CSRF Attacks if ($GLOBALS["TSFE"]->fe_user->getKey('ses', "token") == $this->piVars['token'] || $this->piVars['token'] == false) { $content .= $this->errorMessage($this->conf, $this->pi_getLL('newPost.quote.error')); return $this->new_post($content, $conf); } if ($this->piVars['button'] == $this->pi_getLL('newPost.save')) { // Write changes to database $updateArray = array('post_text' => $this->piVars['message'], 'tstamp' => $GLOBALS['EXEC_TIME']); $res = $this->databaseHandle->exec_UPDATEquery('tx_mmforum_posts_text', 'post_id=' . $postId, $updateArray); // check for attachments that should be deleted if ($this->piVars['attachment_delete']) { foreach ($this->piVars['attachment_delete'] as $attachementId => $delete) { $attachementId = intval($attachementId); $this->databaseHandle->exec_UPDATEquery('tx_mmforum_attachments', 'uid=' . $attachementId, array('deleted' => 1, 'tstamp' => $GLOBALS['EXEC_TIME'])); $this->databaseHandle->exec_UPDATEquery('tx_mmforum_posts', 'uid=' . $attachementId, array('attachment' => 0, 'tstamp' => $GLOBALS['EXEC_TIME'])); $attachments = GeneralUtility::intExplode(',', $row['attachment']); unset($attachments[array_search($attachementId, $attachments)]); $row['attachment'] = implode(',', $attachments); } $this->databaseHandle->exec_UPDATEquery('tx_mmforum_posts', 'uid=' . $postId, array('attachment' => $row['attachment'])); } // Check for new file uploads / attachments if ($_FILES['tx_mmforum_pi1_attachment_1']['size'] > 0) { $res = $this->performAttachmentUpload(); if (!is_array($res)) { $content .= $res; unset($this->piVars['button']); return $this->post_edit($content, $conf); } else { $attachmentIds = $res; $attachments = GeneralUtility::intExplode(',', $row['attachment']); $attachments = tx_mmforum_tools::processArray_numeric($attachments); $updateData = array('attachment' => implode(',', array_merge($attachments, $attachmentIds))); $this->databaseHandle->exec_UPDATEquery('tx_mmforum_posts', 'uid = ' . $postId, $updateData); // Update attachment records with the post ID (as this is not set within the performAttachmentUpload) if (count($attachmentIds)) { $this->databaseHandle->exec_UPDATEquery('tx_mmforum_attachments', 'uid IN (' . implode(',', $attachmentIds) . ')', array('post_id' => $postId)); } } } else { $attachmentIds = null; } if ($this->conf['polls.']['enable']) { if ($this->piVars['enable_poll'] == '1' && $firstPost) { $pollObj = GeneralUtility::makeInstance('tx_mmforum_polls'); /* @var $pollObj tx_mmforum_polls */ if ($topicData['poll_id'] > 0) { $res = $pollObj->editPoll($topicData['poll_id'], $this->piVars['poll'], $this); if ($res) { $content .= $this->errorMessage($this->conf, $res); unset($this->piVars['button']); return $this->post_edit($content, $conf); } } else { $pollId = $pollObj->createPoll($this->piVars['poll'], $this); if (!is_numeric($pollId)) { $content .= $this->errorMessage($this->conf, $pollId); unset($this->piVars['button']); return $this->post_edit($content, $conf); } $this->databaseHandle->exec_UPDATEquery('tx_mmforum_topics', 'uid=' . $topicId, array('poll_id' => $pollId, 'tstamp' => $GLOBALS['EXEC_TIME'])); } } else { if ($firstPost && $topicData['poll_id'] > 0) { $pollObj = GeneralUtility::makeInstance('tx_mmforum_polls'); $pollObj->deletePoll($topicData['poll_id'], $topicData['uid']); } } } if ($this->piVars['title'] and $this->getIsMod($row['forum_id']) || $this->getIsAdmin() || $firstPost && $row['poster_id'] == $GLOBALS['TSFE']->fe_user->user['uid']) { $updateArray = array('topic_title' => $this->piVars['title'], 'tstamp' => $GLOBALS['EXEC_TIME']); $res = $this->databaseHandle->exec_UPDATEquery('tx_mmforum_topics', 'uid=' . $topicId, $updateArray); } // If the editing user is no admin or mod, the change is logged in the database if (!$this->getIsMod($row['forum_id']) && !$this->getIsAdmin()) { $this->databaseHandle->exec_UPDATEquery('tx_mmforum_posts', 'uid=' . $postId, array('edit_count' => intval($row['edit_count']) + 1, 'edit_time' => $GLOBALS['EXEC_TIME'])); } // Clearing for new indexing tx_mmforum_indexing::delete_topic_ind_date($topicId); $linkParams[$this->prefixId] = array('action' => 'list_post', 'tid' => $topicId, 'pid' => $this->piVars['pid']); if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['forum']['postEdit_linkParams'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['forum']['postEdit_linkParams'] as $classRef) { $procObj =& GeneralUtility::getUserObj($classRef); $linkParams = $procObj->postEdit_linkParams($linkParams, $this); } } $link = $this->pi_getPageLink($GLOBALS['TSFE']->id, '', $linkParams); HttpUtility::redirect($link . '#pid' . $postId); } else { // Display post preview if ($this->piVars['button'] == $this->pi_getLL('newPost.preview')) { if ($this->piVars['enable_poll'] == '1' && $this->conf['polls.']['enable']) { $content .= tx_mmforum_polls::displayPreview($this->piVars['poll'], $this); } $template = $this->cObj->fileResource($conf['template.']['list_post']); $template = $this->cObj->getSubpart($template, "###LIST_POSTS###"); $template = $this->cObj->substituteSubpart($template, '###ATTACHMENT_SECTION###', ''); $posttext = $this->piVars['message']; $posttext = $this->tx_mmforum_postparser->main($this, $conf, $posttext, 'textparser'); $marker['###POSTOPTIONS###'] = ''; $marker['###SOLVEDOPTION###'] = ''; $marker['###POSTMENU###'] = ''; $marker['###POSTUSER###'] = $this->ident_user($row['poster_id'], $conf); $marker['###POSTTEXT###'] = $posttext; $marker['###ANKER###'] = ''; $marker['###POSTANCHOR###'] = ''; $marker['###POSTDATE###'] = $this->pi_getLL('post.writtenOn') . ': ' . $this->formatDate($topicData['topic_time']); $marker['###POSTRATING###'] = ''; // Include hooks if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['forum']['editPost_INpreviewMarker'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['forum']['editPost_INpreviewMarker'] as $classRef) { $procObj =& GeneralUtility::getUserObj($classRef); $marker = $procObj->editPost_INpreviewMarker($marker, $this); } } $previewTemplate = $this->cObj->fileResource($conf['template.']['new_post']); $previewTemplate = $this->cObj->getSubpart($previewTemplate, '###PREVIEW###'); $previewMarker = array("###TOPIC_TITLE###" => $this->escape($this->piVars['topicname']), "###LABEL_PREVIEW###" => $this->pi_getLL('newTopic.preview'), "###PREVIEW_POST###" => $this->cObj->substituteMarkerArrayCached($template, $marker)); // Include hooks if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['forum']['editPost_previewMarker'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['forum']['editPost_previewMarker'] as $classRef) { $procObj =& GeneralUtility::getUserObj($classRef); $previewMarker = $procObj->editPost_previewMarker($previewMarker, $this); } } $previewContent = $this->cObj->substituteMarkerArrayCached($previewTemplate, $previewMarker); } $template = $this->cObj->fileResource($conf['template.']['new_post']); $template = $this->cObj->getSubpart($template, stristr($template, '###NEWTOPIC###') === false ? '###NEWPOST###' : '###NEWTOPIC###'); // compatibility: typo in template file fixed. was 'NEWTOPIC' $attachments = GeneralUtility::intExplode(',', $row['attachment']); $attachments = tx_mmforum_tools::processArray_numeric($attachments); $attachCount = count($attachments); if ($attachCount == $this->conf['attachments.']['maxCount'] || !$this->conf['attachments.']['enable']) { $template = $this->cObj->substituteSubpart($template, "###ATTACHMENT_SECTION###", ''); } else { $attachDiff = $this->conf['attachments.']['maxCount'] - $attachCount; $aTemplate = $this->cObj->getSubpart($template, '###ATTACHMENT_FIELD###'); $aContent = ''; for ($i = 1; $i <= $attachDiff; $i++) { $aMarker = array('###ATTACHMENT_NO###' => $i); $aContent .= $this->cObj->substituteMarkerArray($aTemplate, $aMarker); } $marker = array('###LABEL_ATTACHMENT###' => $this->pi_getLL('newPost.attachment'), '###MAXFILESIZE###' => $this->conf['attachments.']['maxFileSize']); // Maximum file size $mFileSize = $this->conf['attachments.']['maxFileSize'] . ' B'; if ($this->conf['attachments.']['maxFileSize'] >= 1024) { $mFileSize = round($this->conf['attachments.']['maxFileSize'] / 1024, 2) . ' KB'; } if ($this->conf['attachments.']['maxFileSize'] >= 1024 * 1024) { $mFileSize = round($this->conf['attachments.']['maxFileSize'] / (1024 * 1024), 2) . ' MB'; } $marker['###MAXFILESIZE_TEXT###'] = sprintf($this->pi_getLL('newPost.maxFileSize'), $mFileSize); $marker['###MAXFILESIZE_TEXT###'] = $this->cObj->stdWrap($marker['###MAXFILESIZE_TEXT###'], $this->conf['attachments.']['maxFileSize_stdWrap.']); $marker['###TOKEN###'] = $GLOBALS["TSFE"]->fe_user->getKey('ses', "token"); $template = $this->cObj->substituteMarkerArray($template, $marker); $template = $this->cObj->substituteSubpart($template, '###ATTACHMENT_FIELD###', $aContent); } $marker = array(); if (strlen($row['attachment']) == 0) { $template = $this->cObj->substituteSubpart($template, '###ATTACHMENT_EDITSECTION###', ''); } else { $aRes = $this->databaseHandle->exec_SELECTquery('*', 'tx_mmforum_attachments', 'uid IN (' . $row['attachment'] . ') AND deleted=0', '', 'uid ASC'); $marker['###LABEL_ATTACHMENT###'] = $this->pi_getLL('newPost.attachment'); $aTemplate = $this->cObj->getSubpart($template, '###ATTACHMENT_EDITFIELD###'); $aContent = ''; while ($attachment = $this->databaseHandle->sql_fetch_assoc($aRes)) { $size = $attachment['file_size'] . ' ' . $this->pi_getLL('attachment.bytes'); if ($attachment['file_size'] > 1024) { $size = round($attachment['file_size'] / 1024, 2) . ' ' . $this->pi_getLL('attachment.kilobytes'); } if ($attachment['file_size'] > 1048576) { $size = round($attachment['file_size'] / 1048576, 2) . ' ' . $this->pi_getLL('attachment.megabytes'); } $aMarker['###LABEL_DELETEATTACHMENT###'] = $this->pi_getLL('attachment.delete'); $sAttachment = $attachment['file_name'] . ' (' . $this->pi_getLL('attachment.type') . ': ' . $attachment['file_type'] . ', ' . $this->pi_getLL('attachment.size') . ': ' . $size . '), ' . $attachment['downloads'] . ' ' . $this->pi_getLL('attachment.downloads'); $sAttachment = $this->escape($sAttachment); $sAttachment = $this->cObj->stdWrap($sAttachment, $this->conf['attachments.']['attachmentEditLabel_stdWrap.']); $aMarker['###ATTACHMENT_DATA###'] = $sAttachment; $aMarker['###ATTACHMENT_UID###'] = $attachment['uid']; $aContent .= $this->cObj->substituteMarkerArray($aTemplate, $aMarker); } $template = $this->cObj->substituteSubpart($template, '###ATTACHMENT_EDITFIELD###', $aContent); } if ($firstPost && $this->conf['polls.']['enable']) { $pollObj = GeneralUtility::makeInstance('tx_mmforum_polls'); if ($topicData['poll_id'] == 0) { $marker['###POLL###'] = $pollObj->display_createForm($this->piVars['poll'] ? $this->piVars['poll'] : array(), $this); $marker['###ENABLE_POLL###'] = $this->piVars['enable_poll'] ? 'checked="checked"' : ''; $marker['###POLLDIV_STYLE###'] = $this->piVars['enable_poll'] ? '' : 'style="display:none;"'; $marker['###LABEL_POLL_CE###'] = $this->pi_getLL('poll.postattach.new'); $marker['###DISABLE_POLL###'] = ''; $marker['###DISABLE_POLL_VAR###'] = 0; $marker['###CALLPOLLJS###'] = $this->conf['callpolljs']; } else { $pollEnabled = $pollObj->getMayEditPoll($topicData['poll_id'], $this); $marker['###POLL###'] = $pollObj->display_editForm($topicData['poll_id'], $this->piVars['poll'] ? $this->piVars['poll'] : array(), $this); $marker['###ENABLE_POLL###'] = 'checked="checked"'; $marker['###POLLDIV_STYLE###'] = ''; $marker['###LABEL_POLL_CE###'] = $this->pi_getLL('poll.postattach.edit'); $marker['###DISABLE_POLL###'] = $pollEnabled ? '' : 'disabled="disabled"'; $marker['###DISABLE_POLL_VAR###'] = $pollEnabled ? 0 : 1; $marker['###CALLPOLLJS###'] = $this->conf['callpolljs']; } $marker['###LABEL_POLL###'] = $this->pi_getLL('poll.postattach'); } else { $template = $this->cObj->substituteSubpart($template, '###POLL_SECTION###', ''); } $res = $this->databaseHandle->exec_SELECTquery('post_text', 'tx_mmforum_posts_text', 'post_id=' . $postId); list($posttext) = $this->databaseHandle->sql_fetch_row($res); $res = $this->databaseHandle->exec_SELECTquery('topic_title', 'tx_mmforum_topics', 'uid=' . $topicId); list($title) = $this->databaseHandle->sql_fetch_row($res); $marker['###POSTTEXT###'] = $this->piVars['message'] ? $this->escape($this->piVars['message']) : $this->escape($posttext); if ($this->getIsMod($row['forum_id']) || $this->getIsAdmin()) { $marker['###POSTTITLE###'] = '<input type="text" name="tx_mmforum_pi1[title]" size="50" value="' . $this->escape($title) . '" style="width:80%;"></div>'; } else { if ($firstPost && $row['poster_id'] == $GLOBALS['TSFE']->fe_user->user['uid']) { $marker['###POSTTITLE###'] = '<input type="text" name="tx_mmforum_pi1[title]" size="50" value="' . $this->escape($title) . '" style="width:80%;"></div>'; } else { $marker['###POSTTITLE###'] = $this->escape($title); } } $marker['###OLDPOSTTEXT###'] = ''; $marker['###SMILIES###'] = $this->show_smilie_db($conf); $marker['###SOLVEDOPTION###'] = ''; $marker['###ACTION###'] = htmlspecialchars($this->pi_getPageLink($GLOBALS['TSFE']->id, '', array($this->prefixId => array('action' => 'post_edit', 'pid' => $postId)))); $marker['###LABEL_SEND###'] = $this->pi_getLL('newPost.save'); $marker['###LABEL_PREVIEW###'] = $this->pi_getLL('newPost.preview'); $marker['###LABEL_RESET###'] = $this->pi_getLL('newPost.reset'); $marker['###LABEL_ATTENTION###'] = $this->pi_getLL('newPost.attention'); $marker['###LABEL_NOTECODESAMPLES###'] = $this->pi_getLL('newPost.codeSamples'); $marker['###TOPICICON###'] = $this->getTopicIcon($topicData); $marker['###TOPICTITLE###'] = $this->escape($topicData['topic_title']); // no have-a-look on post edit $template = $this->cObj->substituteSubpart($template, '###HAVEALOOK_SECTION###', ''); $bbCodeButtons_template = $this->cObj->getSubpart($template, '###BBCODEBUTTONS###'); if (empty($conf['jQueryEditorJavaScript'])) { $bbCodeButtons = $this->generateBBCodeButtons($bbCodeButtons_template); } else { $bbCodeButtons = stristr($bbCodeButtons_template, '<td>') ? '<td></td>' : ''; } $template = $this->cObj->substituteSubpart($template, '###BBCODEBUTTONS###', $bbCodeButtons); $template = str_replace('###POLLJAVASCRIPT###', $this->conf['polljavascript'], $template); if ($this->conf['disableRootline']) { $template = $this->cObj->substituteSubpart($template, '###ROOTLINE_CONTAINER###', ''); } else { $marker['###FORUMPATH###'] = $this->get_forum_path($forumId, $topicId); } } } else { $template = $this->cObj->fileResource($conf['template.']['error']); $marker = array('###ERROR###' => $this->pi_getLL('editPost.noAccess')); } // Include hooks if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['forum']['editPost_formMarker'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['forum']['editPost_formMarker'] as $classRef) { $procObj =& GeneralUtility::getUserObj($classRef); $marker = $procObj->editPost_formMarker($marker, $this); } } $marker['###STARTJAVASCRIPT###'] = $this->includeEditorJavaScript(); $marker['###POST_PREVIEW###'] = (string) $previewContent; $content .= $this->cObj->substituteMarkerArrayCached($template, $marker); return $content; }