/**
  *
  * Creates a new post.
  * This function creates a new post. Also automatically updates all database counters.
  *
  * @author  Martin Helmich
  * @version 2007-07-23
  * @param   int     $topicId     The UID of the topic the new post is to be created in
  * @param   int     $author      The UID of the fe_user creating this post
  * @param   string  $text        The post's text
  * @param   int     $date        The date of post creation as unix timestamp
  * @param   string  $ip          The post author's IP address
  * @param   array   $attachments An array of attachments that are to be attached
  *                               to this post.
  * @param   boolean $noUpdate    Set to TRUE in order to prevent the database counters from
  *                               being updated directly after creating this post. Instead,
  *                               the elements to be updated will be stored in an "update queue"
  *                               and will be updated after all posts/topics have been created.
  *                               This minimizes database load.
  * @param   boolean $subscribe
  * @return  int/boolean          If post creation was successfull, the post's UID is returned,
  *                               otherwise FALSE.
  */
 function create_post($topicId, $author, $text, $date, $ip, $attachments = array(), $noUpdate = false, $subscribe = FALSE)
 {
     $author = intval($author);
     // Retrieve forum uid
     $forumId = $this->getForumUIDByTopic($topicId);
     if ($forumId === false) {
         return false;
     }
     // Generate post record
     $insertArray = array('pid' => $this->getFirstPid(), 'tstamp' => $GLOBALS['EXEC_TIME'], 'crdate' => $GLOBALS['EXEC_TIME'], 'topic_id' => $topicId, 'forum_id' => $forumId, 'poster_id' => $author, 'post_time' => $date, 'poster_ip' => $ip, 'attachment' => is_array($attachments) ? implode(',', $attachments) : '');
     // Include hooks
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['postfactory']['insertPost'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['postfactory']['insertPost'] as $_classRef) {
             $_procObj =& GeneralUtility::getUserObj($_classRef);
             $insertArray = $_procObj->processPostInsertArray($insertArray, $this);
         }
     }
     // Insert post record
     if (!$this->databaseHandle->exec_INSERTquery('tx_mmforum_posts', $insertArray)) {
         return false;
     }
     // Retrieve post uid
     $postId = $this->databaseHandle->sql_insert_id();
     // Update attachment record
     if (is_array($attachments) && count($attachments)) {
         $this->databaseHandle->exec_UPDATEquery('tx_mmforum_attachments', 'uid IN (' . implode(',', $attachments) . ')', array('post_id' => $postId));
     }
     // Generate post text record
     $insertArray = array('pid' => $this->getFirstPid(), 'tstamp' => $GLOBALS['EXEC_TIME'], 'crdate' => $GLOBALS['EXEC_TIME'], 'post_id' => $postId, 'post_text' => $text, 'cache_text' => $text);
     // Include hooks
     if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['postfactory']['insertPostText'])) {
         foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['mm_forum']['postfactory']['insertPostText'] as $_classRef) {
             $_procObj =& GeneralUtility::getUserObj($_classRef);
             $insertArray = $_procObj->processPostTextInsertArray($insertArray, $this);
         }
     }
     // Insert post text record
     if (!$this->databaseHandle->exec_INSERTquery('tx_mmforum_posts_text', $insertArray)) {
         $this->databaseHandle->exec_DELETEquery('tx_mmforum_posts', 'uid = ' . $postId);
         return false;
     }
     // Clear topic for indexing
     if (class_exists('tx_mmforum_indexing')) {
         tx_mmforum_indexing::delete_topic_ind_date($topicId);
     }
     // Send notification email to users who have subscribed this topic
     if ($this->parent != null) {
         // Subscribe to the topic
         if ($subscribe) {
             $this->tx_mmforum_havealook->addSubscription($this->parent, $topicId, $author);
         }
         $this->tx_mmforum_havealook->notifyTopicSubscribers($topicId, $this->parent);
     }
     // Set topic for all users to "not read"
     $this->databaseHandle->exec_DELETEquery('tx_mmforum_postsread', 'topic_id = ' . $topicId);
     // Update topic and forum post counters
     if (!$noUpdate) {
         $this->updateTopicPostCount($topicId);
         $this->updateForumPostCount($forumId);
         $this->updateUserPostCount($author);
     } else {
         $this->updateQueue_addTopic($topicId);
         $this->updateQueue_addForum($forumId);
         $this->updateQueue_addUser($author);
     }
     return $postId;
 }
Example #2
0
 /**
  * Sends an e-mail to users who have subscribed a certain topic.
  * @param  string $content The plugin content
  * @param  array  $conf    The configuration vars
  * @param  int    $topic   The UID of the topic about which the users are
  *                        to be alerted.
  * @return void
  * @deprecated since 0.1.8, please use the direct call to the static function
  */
 function send_newpost_mail($content, $conf, $topicId)
 {
     GeneralUtility::logDeprecatedFunction();
     tx_mmforum_havealook::notifyTopicSubscribers($topicId, $this);
 }