Пример #1
0
function CreatePost($poster, $mimeDecodedEmail, $post_id, &$is_reply, $config, $postmodifiers)
{
    $fulldebug = IsDebugMode();
    $fulldebugdump = false;
    extract($config);
    $attachments = array("html" => array(), "cids" => array(), "image_files" => array());
    if (array_key_exists('message-id', $mimeDecodedEmail->headers)) {
        DebugEcho("Message Id is :" . htmlentities($mimeDecodedEmail->headers["message-id"]));
        if ($fulldebugdump) {
            DebugDump($mimeDecodedEmail);
        }
    }
    filter_PreferedText($mimeDecodedEmail, $prefer_text_type);
    if ($fulldebugdump) {
        DebugDump($mimeDecodedEmail);
    }
    $content = GetContent($mimeDecodedEmail, $attachments, $post_id, $poster, $config);
    if ($fulldebug) {
        DebugEcho("the content is {$content}");
    }
    $subject = GetSubject($mimeDecodedEmail, $content, $config);
    filter_RemoveSignature($content, $config);
    if ($fulldebug) {
        DebugEcho("post sig: {$content}");
    }
    $post_excerpt = tag_Excerpt($content, $config);
    if ($fulldebug) {
        DebugEcho("post excerpt: {$content}");
    }
    $postAuthorDetails = getPostAuthorDetails($subject, $content, $mimeDecodedEmail);
    if ($fulldebug) {
        DebugEcho("post author: {$content}");
    }
    $message_date = NULL;
    if (array_key_exists("date", $mimeDecodedEmail->headers) && !empty($mimeDecodedEmail->headers["date"])) {
        $cte = "";
        $cs = "";
        if (property_exists($mimeDecodedEmail, 'content-transfer-encoding') && array_key_exists('content-transfer-encoding', $mimeDecodedEmail->headers)) {
            $cte = $mimeDecodedEmail->headers["content-transfer-encoding"];
        }
        if (property_exists($mimeDecodedEmail, 'ctype_parameters') && array_key_exists('charset', $mimeDecodedEmail->ctype_parameters)) {
            $cs = $mimeDecodedEmail->ctype_parameters["charset"];
        }
        $message_date = HandleMessageEncoding($cte, $cs, $mimeDecodedEmail->headers["date"], $message_encoding, $message_dequote);
    }
    $message_date = tag_Date($content, $message_date);
    list($post_date, $post_date_gmt, $delay) = filter_Delay($content, $message_date, $time_offset);
    if ($fulldebug) {
        DebugEcho("post date: {$content}");
    }
    filter_Ubb2HTML($content);
    if ($fulldebug) {
        DebugEcho("post ubb: {$content}");
    }
    $post_categories = tag_Categories($subject, $default_post_category, $category_match);
    if ($fulldebug) {
        DebugEcho("post category: {$content}");
    }
    $post_tags = tag_Tags($content, $default_post_tags);
    if ($fulldebug) {
        DebugEcho("post tag: {$content}");
    }
    $comment_status = tag_AllowCommentsOnPost($content);
    if ($fulldebug) {
        DebugEcho("post comment: {$content}");
    }
    $post_status = tag_Status($content, $post_status);
    if ($fulldebug) {
        DebugEcho("post status: {$content}");
    }
    if ($converturls) {
        $content = filter_Videos($content, $shortcode);
        //videos first so linkify doesn't mess with them
        if ($fulldebug) {
            DebugEcho("post video: {$content}");
        }
        $content = filter_Linkify($content);
        if ($fulldebug) {
            DebugEcho("post linkify: {$content}");
        }
    }
    filter_VodafoneHandler($content, $attachments, $config);
    if ($fulldebug) {
        DebugEcho("post vodafone: {$content}");
    }
    filter_ReplaceImageCIDs($content, $attachments, $config);
    if ($fulldebug) {
        DebugEcho("post cid: {$content}");
    }
    $customImages = tag_CustomImageField($content, $attachments, $config);
    if ($fulldebug) {
        DebugEcho("post custom: {$content}");
    }
    $post_type = tag_PostType($subject, $postmodifiers, $config);
    if ($fulldebug) {
        DebugEcho("post type: {$content}");
    }
    $id = GetParentPostForReply($subject);
    if (empty($id)) {
        $id = $post_id;
        $is_reply = false;
        if ($add_meta == 'yes') {
            if ($wrap_pre == 'yes') {
                $content = $postAuthorDetails['content'] . "<pre>\n" . $content . "</pre>\n";
                $content = "<pre>\n" . $content . "</pre>\n";
            } else {
                $content = $postAuthorDetails['content'] . $content;
                $content = $content;
            }
        } else {
            if ($wrap_pre == 'yes') {
                $content = "<pre>\n" . $content . "</pre>\n";
            }
        }
    } else {
        DebugEcho("Reply detected");
        $is_reply = true;
        // strip out quoted content
        $lines = explode("\n", $content);
        $newContents = '';
        foreach ($lines as $line) {
            if (preg_match("/^>.*/i", $line) == 0 && preg_match("/^(from|subject|to|date):.*?/i", $line) == 0 && preg_match("/^-+.*?(from|subject|to|date).*?/i", $line) == 0 && preg_match("/^on.*?wrote:\$/i", $line) == 0 && preg_match("/^-+\\s*forwarded\\s*message\\s*-+/i", $line) == 0) {
                $newContents .= "{$line}\n";
            }
        }
        $content = $newContents;
        wp_delete_post($post_id);
    }
    if ($delay != 0 && $post_status == 'publish') {
        $post_status = 'future';
    }
    filter_Newlines($content, $config);
    if ($fulldebug) {
        DebugEcho("post newline: {$content}");
    }
    filter_Start($content, $config);
    if ($fulldebug) {
        DebugEcho("post start: {$content}");
    }
    filter_End($content, $config);
    if ($fulldebug) {
        DebugEcho("post end: {$content}");
    }
    filter_ReplaceImagePlaceHolders($content, $attachments["html"], $config, $id, $config['image_placeholder'], true);
    if ($fulldebug) {
        DebugEcho("post body img: {$content}");
    }
    if ($post_excerpt) {
        filter_ReplaceImagePlaceHolders($post_excerpt, $attachments["html"], $config, $id, "#eimg%#", false);
        if ($fulldebug) {
            DebugEcho("post excerpt img: {$content}");
        }
    }
    DebugEcho("excerpt: {$post_excerpt}");
    if (trim($subject) == "") {
        $subject = $default_title;
        DebugEcho("post parsing subject is blank using: {$default_title}");
    }
    $details = array('post_author' => $poster, 'comment_author' => $postAuthorDetails['author'], 'comment_author_url' => $postAuthorDetails['comment_author_url'], 'user_ID' => $postAuthorDetails['user_ID'], 'email_author' => $postAuthorDetails['email'], 'post_date' => $post_date, 'post_date_gmt' => $post_date_gmt, 'post_content' => $content, 'post_title' => $subject, 'post_type' => $post_type, 'ping_status' => get_option('default_ping_status'), 'post_category' => $post_categories, 'tags_input' => $post_tags, 'comment_status' => $comment_status, 'post_name' => sanitize_title($subject), 'post_excerpt' => $post_excerpt, 'ID' => $id, 'customImages' => $customImages, 'post_status' => $post_status);
    return $details;
}
Пример #2
0
 public function test_tag_Date()
 {
     $c = "";
     $this->assertEquals(null, tag_Date($c, null, 0));
     $this->assertEquals("", $c);
     $c = "date:";
     $this->assertEquals(null, tag_Date($c, null, 0));
     $this->assertEquals("date:", $c);
     $c = "date: nothing";
     $this->assertEquals(null, tag_Date($c, null, 0));
     $this->assertEquals("date: nothing", $c);
     $c = "date: 1";
     $this->assertEquals(null, tag_Date($c, null, 0));
     $this->assertEquals("date: 1", $c);
     $c = "date: 12/31/2013";
     $this->assertEquals("2013-12-31", tag_Date($c, null, 0));
     $this->assertEquals("", $c);
     $c = "date:12/31/2013";
     $this->assertEquals("2013-12-31", tag_Date($c, null, 0));
     $this->assertEquals("", $c);
     $c = "Date: 12/31/2013";
     $this->assertEquals("2013-12-31", tag_Date($c, null, 0));
     $this->assertEquals("", $c);
     $c = "DATE: 12/31/2013";
     $this->assertEquals("2013-12-31", tag_Date($c, null, 0));
     $this->assertEquals("", $c);
     $c = "date: 31-12-2013";
     $this->assertEquals("2013-12-31", tag_Date($c, null, 0));
     $this->assertEquals("", $c);
     $c = "date: 31.12.2013";
     $this->assertEquals("2013-12-31", tag_Date($c, null, 0));
     $this->assertEquals("", $c);
     $c = "date: Dec 31, 2013";
     $this->assertEquals("2013-12-31", tag_Date($c, null, 0));
     $this->assertEquals("", $c);
     $c = "date: 12/31/2013\nstuff";
     $this->assertEquals("2013-12-31", tag_Date($c, null, 0));
     $this->assertEquals("\nstuff", $c);
     $c = "date: Dec 31, 2013 14:22";
     $this->assertEquals("2013-12-31 14:22:00", tag_Date($c, null, 0));
     $this->assertEquals("", $c);
     $c = "stuff\n\ndate: Dec 31, 2013 14:22\n\nmorestuff";
     $this->assertEquals("2013-12-31 14:22:00", tag_Date($c, null, 0));
     $this->assertEquals("stuff\n\n\n\nmorestuff", $c);
     $c = "<p>stuff</p><p>date: Dec 31, 2013 14:22</p><p>morestuff</p>";
     $this->assertEquals("2013-12-31 14:22:00", tag_Date($c, null, 0));
     $this->assertEquals("<p>stuff</p><p></p><p>morestuff</p>", $c);
 }