/** * Function for inserting topic data when it's first published. * * @since 1.0.0 * @access public * @param object $post * @return void */ function mb_insert_topic_data($post) { /* Hook for before inserting topic data. */ do_action('mb_before_insert_topic_data', $post); /* Get the topic ID. */ $topic_id = mb_get_topic_id($post->ID); /* Get the forum ID. */ $forum_id = mb_get_forum_id($post->post_parent); /* Get the User ID. */ $user_id = mb_get_user_id($post->post_author); /* Get the post date. */ $post_date = $post->post_date; $post_epoch = mysql2date('U', $post_date); /* Update user meta. */ $topic_count = mb_get_user_topic_count($user_id); update_user_meta($user_id, mb_get_user_topic_count_meta_key(), $topic_count + 1); /* Add topic meta. */ mb_set_topic_activity_datetime($topic_id, $post_date); mb_set_topic_activity_epoch($topic_id, $post_epoch); mb_set_topic_voices($topic_id, $user_id); mb_set_topic_voice_count($topic_id, 1); mb_set_topic_reply_count($topic_id, 0); /* If we have a forum ID. */ if (0 < $forum_id) { $topic_count = mb_get_forum_topic_count($forum_id); /* Update forum meta. */ mb_set_forum_activity_datetime($forum_id, $post_date); mb_set_forum_activity_epoch($forum_id, $post_epoch); mb_set_forum_last_topic_id($forum_id, $topic_id); mb_set_forum_topic_count($forum_id, absint($topic_count) + 1); } /* Notify subscribers that there's a new topic. */ mb_notify_subscribers($post); /* Hook for after inserting topic data. */ do_action('mb_after_insert_topic_data', $post); }
/** * Function for inserting reply data when it's first published. * * @since 1.0.0 * @access public * @param object $post * @return void */ function mb_insert_reply_data($post) { /* Hook for before inserting reply data. */ do_action('mb_before_insert_reply_data', $post); /* Get the reply ID. */ $reply_id = mb_get_reply_id($post->ID); /* Get the topic ID. */ $topic_id = mb_get_topic_id($post->post_parent); /* Get the forum ID. */ $forum_id = mb_get_topic_forum_id($topic_id); /* Get the user ID. */ $user_id = mb_get_user_id($post->post_author); /* Get the post date. */ $post_date = $post->post_date; $post_epoch = mysql2date('U', $post_date); /* Update user meta. */ $topic_count = mb_get_user_topic_count($user_id); update_user_meta($user_id, mb_get_user_topic_count_meta_key(), $topic_count + 1); /* Update topic position. */ mb_set_topic_position($topic_id, $post_epoch); /* Update topic meta. */ mb_set_topic_activity_datetime($topic_id, $post_date); mb_set_topic_activity_epoch($topic_id, $post_epoch); mb_set_topic_last_reply_id($topic_id, $reply_id); $voices = mb_get_topic_voices($topic_id); if (!in_array($user_id, $voices)) { $voices[] = $user_id; mb_set_topic_voices($topic_id, $voices); mb_set_topic_voice_count($topic_id, count($voices)); } $topic_reply_count = mb_get_topic_reply_count($topic_id); mb_set_topic_reply_count($topic_id, absint($topic_reply_count) + 1); $forum_reply_count = absint(mb_get_forum_reply_count($forum_id)) + 1; /* Update forum meta. */ mb_set_forum_activity_datetime($forum_id, $post_date); mb_set_forum_activity_epoch($forum_id, $post_epoch); mb_set_forum_last_reply_id($forum_id, $reply_id); mb_set_forum_last_topic_id($forum_id, $topic_id); mb_set_forum_reply_count($forum_id, $forum_reply_count); /* Notify subscribers that there's a new reply. */ mb_notify_subscribers($post); /* Hook for after inserting reply data. */ do_action('mb_after_insert_reply_data', $post); }
/** * Function for inserting forum data when it's first published. * * @since 1.0.0 * @access public * @param object $post * @return void */ function mb_insert_forum_data($post) { /* Hook for before inserting forum data. */ do_action('mb_before_insert_forum_data', $post); /* Get the forum ID. */ $forum_id = mb_get_forum_id($post->ID); /* Get the User ID. */ $user_id = mb_get_user_id($post->post_author); /* Update parent's subforum count. */ if (0 < $post->post_parent) { $count = mb_get_forum_subforum_count($post->post_parent); mb_set_forum_subforum_count($post->post_parent, absint($count) + 1); } /* Update user meta. */ mb_set_user_forum_count($user_id); /* Add forum meta. */ mb_reset_forum_level($forum_id); /* Notify subscribers that there's a new forum. */ mb_notify_subscribers($post); /* Hook for after inserting forum data. */ do_action('mb_after_insert_forum_data', $post); }