Commit d7eb9531 authored by Chris Graham's avatar Chris Graham
Browse files

Fixed MANTIS-4449 (Newsletter and Comcode tweaks)

parent dda86513
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -21,6 +21,12 @@ class comcode_to_text_test_set extends cms_test_case
    public function testComcodeToText()
    {
        $text = '
[list]
[*]A
[*]B
[*]C
[/list]

[title]header 1[/title]

under header 1
@@ -48,11 +54,21 @@ blah[/indent]
[random a="Want"]1233[/random]

[abbr="Cascading Style Sheets"]CSS[/abbr]

{+START,IF_NON_EMPTY,foo}bar{+END}

{+START,IF_EMPTY,foo}bar{+END}

{$SITE_NAME}
';

        $got = strip_comcode($text);

        $expected = '
 - A
 - B
 - C

header 1
========

@@ -81,7 +97,10 @@ box contents
Want

CSS (Cascading Style Sheets)
';

bar

' . get_site_name();

        $ok = trim($got) == trim($expected);
        $this->assertTrue($ok);
+33 −0
Original line number Diff line number Diff line
@@ -38,6 +38,39 @@ class newsletter_test_set extends cms_test_case
        $this->assertTrue('Thanks' == get_translated_text($GLOBALS['SITE_DB']->query_select_value('newsletters', 'title', array('id' => $this->news_id))));
    }

    public function testVariableSubstitution()
    {
        // Comcode to plain text...

        $message = 'abc {forename} {surname} {name} {email_address} {sendid} {123}';
        $subject = 'def {forename}';
        $forename = 'ghi';
        $surname = 'jkl';
        $name = 'mno';
        $email_address = 'pqr@example.com';
        $sendid = 'stu';
        $hash = 'vwx';
        $extra_mappings = array(
            '123' => 'yz'
        );

        $wrapped = do_template('NEWSLETTER_DEFAULT_FCOMCODE', array('CONTENT' => $message, 'LANG' => fallback_lang(), 'SUBJECT' => $subject), null, false, null, '.txt', 'text');

        $newsletter_message_substituted = newsletter_variable_substitution($wrapped->evaluate(), $subject, $forename, $surname, $name, $email_address, $sendid, $hash, $extra_mappings);

        require_code('mail');
        $rendered = comcode_to_clean_text($newsletter_message_substituted);

        $expected = "abc ghi jkl mno pqr@example.com stu yz\n\n-------------------------\n\nYou can unsubscribe from this newsletter at: http://localhost/composr-copy/newsletter/unsub/tu.htm?hash=vwx";
        $this->assertTrue($rendered == $expected);

        // Comcode to HTML...

        $rendered = static_evaluate_tempcode(comcode_to_tempcode($newsletter_message_substituted));
        $expected = "abc ghi jkl mno pqr@example.com stu yz<br /><br /><br /><hr />\n<span style=\"  font-size: 0.8em;\">You can unsubscribe from this newsletter at: <a class=\"user_link\" href=\"http://localhost/composr-copy/newsletter/unsub/tu.htm?hash=vwx\" target=\"_top\">http://localhost/composr-copy/newsletter/unsub/tu.htm?hash=vwx</a></span><br /><br />";
        $this->assertTrue($rendered == $expected);
    }

    public function tearDown()
    {
        delete_newsletter($this->news_id);
+2 −2
Original line number Diff line number Diff line
@@ -163,8 +163,8 @@ CREATE_PERIODIC_FOR=The very next periodic e-mail sent includes
CREATE_PERIODIC_FOR_ALL=All content until now (and will send on first valid date)
CREATE_PERIODIC_FOR_FUTURE=Only future content (and will send on second valid date &ndash; i.e. after one cycle)
SOME_NEWSLETTER_TARGETS_KNOWN=Approximately {1} {1|person has|people have} been manually pre-selected for newsletter receipt. There is no need to choose additional groups/newsletters to send to, although you may.
NEWSLETTER_UNSUBSCRIBE_NEWSLETTER=You can unsubscribe from this newsletter at: {1}
NEWSLETTER_UNSUBSCRIBE_MEMBER=You are receiving this e-mail because you have a member account set to &ldquo;Receive newsletters and other site updates&rdquo;. You can change your settings at: {1}
NEWSLETTER_UNSUBSCRIBE_NEWSLETTER=You can unsubscribe from this newsletter at: [url="{1}"]{1}[/url]
NEWSLETTER_UNSUBSCRIBE_MEMBER=You are receiving this e-mail because you have a member account set to &ldquo;Receive newsletters and other site updates&rdquo;. You can change your settings at: [url="{1}"]{1}[/url]
DOMAIN_STATISTICS=E-mail provider statistics (showing {1} of {2} domains)
NEWSLETTER_PREVIEW_SUBJECT={1} (PREVIEW)
CONFIG_OPTION_dual_format_newsletters=Whether newsletters should be sent in both an HTML and a text version. This will require some extra consideration when you author newsletters (the text version is based on stripped-down Comcode, so you will need to use Comcode to layout the newsletter).
+0 −8
Original line number Diff line number Diff line
@@ -266,14 +266,6 @@ function comcode_to_clean_text($message_plain, $for_extract = false, $tags_to_pr
        $message_plain = str_replace('{$SITE_NAME}', get_site_name(), $message_plain);
        $message_plain = str_replace('{$SITE_NAME*}', get_site_name(), $message_plain);

        if (stripos($message_plain, '{') !== false) {
            // Remove directives etc
            do {
                $before = $message_plain;
                $message_plain = preg_replace('#\{([^|\}\{]*)\}#', '', $message_plain);
            } while ($message_plain != $before);
        }

        if (strpos($message_plain, '{') !== false) {
            $message_plain = static_evaluate_tempcode(template_to_tempcode($message_plain, 0, false, '', null, null, true));
        }