Esempio n. 1
0
function message_on_preview(&$api)
{
    include dirname(__FILE__) . '/message_controller.class.php';
    $parent_id = (int) $_POST['parent_id'];
    $may_quote = (int) $_POST['may_quote'];
    $controller = new MessageController($api);
    $user = $api->user();
    $message = new Message(message_get_new_posting($api), $api);
    message_init_posting_from_post_data($message);
    // Check the posting for completeness.
    $err = $message->check_complete();
    if ($err) {
        $controller->add_hint(new \hint\Error($err));
        return $controller->show_compose($message, $parent_id, $may_quote);
    }
    // Make sure that the username is not in use.
    if ($user->is_anonymous() && !$api->userdb()->username_is_available($message->get_username())) {
        $err = _('The entered username is not available.');
        $controller->add_hint(new \hint\Error($err));
        return $controller->show_compose($message, $parent_id, $may_quote);
    }
    // Success.
    /* Plugin hook: on_message_preview_print
     *   Called before the HTML for the posting preview is produced.
     *   Args: posting: The posting that is about to be previewed.
     */
    $api->eventbus()->emit('on_message_preview_print', $api, $message);
    $api->breadcrumbs()->add_text(_('Preview'));
    $controller->show_preview($message, $parent_id, $may_quote);
}