Browse code

Add full message tokens

Benjamin Roth authored on04/04/2023 16:12:58
Showing3 changed files
... ...
@@ -37,13 +37,16 @@ $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['contao']['news_submitted']
37 37
     (
38 38
         'member_firstname', // The firstname of the recipient
39 39
         'member_lastname', // The lastname of the recipient
40
-        'news_topics' // The titles of all new news
40
+        'news_topics', // The titles of all new news
41
+        'news_full' // The titles of all new news
41 42
     ),
42 43
     'email_html'    => array
43 44
     (
44 45
         'member_firstname', // The firstname of the recipient
45 46
         'member_lastname', // The lastname of the recipient
46 47
         'news_topics_html', // The titles of all new news
47
-        'news_topics' // The titles of all new news
48
+        'news_full_html', // The titles of all new news
49
+        'news_topics', // The titles of all new news
50
+        'news_full' // The titles of all new news
48 51
     )
49 52
 );
... ...
@@ -13,6 +13,8 @@ declare(strict_types=1);
13 13
 namespace vonRotenberg\NewsmailerBundle\Cron;
14 14
 
15 15
 use Contao\Config;
16
+use Contao\ContentModel;
17
+use Contao\Controller;
16 18
 use Contao\CoreBundle\Monolog\ContaoContext;
17 19
 use Contao\CoreBundle\ServiceAnnotation\CronJob;
18 20
 use Contao\Date;
... ...
@@ -51,6 +53,8 @@ class SendNewsNotificationJob
51 53
 
52 54
         if ($Archives !== null)
53 55
         {
56
+            list($admin_name,$admin_email) = StringUtil::splitFriendlyEmail(Config::get('adminEmail'));
57
+
54 58
             while ($Archives->next())
55 59
             {
56 60
                 $Archive = $Archives->current();
... ...
@@ -83,10 +87,22 @@ class SendNewsNotificationJob
83 87
                             $arrNewsIds = array();
84 88
                             foreach ($News->iterateAssociative() as $item)
85 89
                             {
90
+                                $strText = '';
91
+                                $objContentElement = ContentModel::findPublishedByPidAndTable($item['id'], 'tl_news');
92
+
93
+                                if ($objContentElement !== null)
94
+                                {
95
+                                    while ($objContentElement->next())
96
+                                    {
97
+                                        $strText .= Controller::getContentElement($objContentElement->current());
98
+                                    }
99
+                                }
86 100
                                 $arrRow = array(
87 101
                                     'date' => date('d.m.Y',$item['date']),
88 102
                                     'headline' => $item['headline'],
89
-                                    'teaser' => $item['teaser'] ? StringUtil::substr(strip_tags(str_ireplace(array('<br />','<br>','<br/>','</p>','<p>'),' ',$item['teaser'])),128) : ''
103
+                                    'teaser' => $item['teaser'] ? StringUtil::substr(strip_tags(str_ireplace(array('<br />','<br>','<br/>','</p>','<p>'),' ',$item['teaser'])),128) : '',
104
+                                    'text_plain' => $strText ? strip_tags(str_ireplace(array('<br />','<br>','<br/>','</p>','<p>'),' ',$strText)) : strip_tags(str_ireplace(array('<br />','<br>','<br/>','</p>','<p>'),' ',$item['teaser'])),
105
+                                    'text_html' => $strText ?: $item['teaser']
90 106
                                 );
91 107
 
92 108
                                 if (($objJumpTo = $Archive->getRelated('jumpTo')) !== null)
... ...
@@ -99,6 +115,8 @@ class SendNewsNotificationJob
99 115
 
100 116
                                 $arrNewsPlain[] = date('d.m.Y',$item['date']).' - '.$item['headline'];
101 117
                                 $arrNewsHtml[] = '<div style="margin-bottom: 15px;"><h3>'.$arrRow['date'].' '.$arrRow['headline'].'</h3><p>'.$arrRow['teaser'].'</p>'. ($arrRow['url'] ? '<p><a href="'.$arrRow['url'].'">&raquo; Ganze Nachricht lesen...</a></p>' : '') .'</div>';
118
+                                $arrNewsFullPlain[] = date('d.m.Y',$item['date']).' - '.$item['headline'] . "\n" . $arrRow['text_plain'];
119
+                                $arrNewsFullHtml[] = '<div style="margin-bottom: 15px;"><h3>'.$arrRow['date'].' '.$arrRow['headline'].'</h3>' . $arrRow['text_html'] . ($arrRow['url'] ? '<p><a href="'.$arrRow['url'].'">&raquo; Ganze Nachricht lesen...</a></p>' : '') .'</div>';
102 120
 
103 121
                                 $arrNewsIds[] = $item['id'];
104 122
                             }
... ...
@@ -119,7 +137,10 @@ class SendNewsNotificationJob
119 137
                                     'member_lastname' => $Members->lastname,
120 138
                                     'news_topics'       => implode("\n",$arrNewsPlain),
121 139
                                     'news_topics_html'  => "<ul>\n<li>".str_replace('%%_TOKEN_%%',$strToken,implode("</li>\n<li>",$arrNewsHtml))."</li>\n</ul>",
122
-                                    'member_login_token'  => $strToken
140
+                                    'news_full' => implode("\n",$arrNewsFullPlain),
141
+                                    'news_full_html' => implode("",$arrNewsFullHtml),
142
+                                    'member_login_token'  => $strToken,
143
+                                    'admin_email'  => $admin_email,
123 144
                                 ),
124 145
                                     $GLOBALS['TL_LANGUAGE']);
125 146
                             }
... ...
@@ -14,6 +14,8 @@ namespace vonRotenberg\NewsmailerBundle\EventListener;
14 14
 
15 15
 use Contao\BackendUser;
16 16
 use Contao\Config;
17
+use Contao\ContentModel;
18
+use Contao\Controller;
17 19
 use Contao\CoreBundle\ServiceAnnotation\Callback;
18 20
 use Contao\DataContainer;
19 21
 use Contao\Message;
... ...
@@ -45,10 +47,23 @@ class NewsSendTestmailListener
45 47
 
46 48
             if ($News !== null && ($Archive = $News->getRelated('pid')) !== null && ($Notification = Notification::findByPk($Archive->nc_notification)) !== null)
47 49
             {
50
+                $strText = '';
51
+                $objContentElement = ContentModel::findPublishedByPidAndTable($News->id, 'tl_news');
52
+
53
+                if ($objContentElement !== null)
54
+                {
55
+                    while ($objContentElement->next())
56
+                    {
57
+                        $strText .= Controller::getContentElement($objContentElement->current());
58
+                    }
59
+                }
60
+
48 61
                 $arrRow = array(
49 62
                     'date' => date('d.m.Y',$News->date),
50 63
                     'headline' => $News->headline,
51
-                    'teaser' => $News->teaser ? StringUtil::substr(strip_tags(str_ireplace(array('<br />','<br>','<br/>','</p>','<p>'),' ',$News->teaser)),128) : ''
64
+                    'teaser' => $News->teaser ? StringUtil::substr(strip_tags(str_ireplace(array('<br />','<br>','<br/>','</p>','<p>'),' ',$News->teaser)),128) : '',
65
+                    'text_plain' => $strText ? strip_tags(str_ireplace(array('<br />','<br>','<br/>','</p>','<p>'),' ',$strText)) : strip_tags(str_ireplace(array('<br />','<br>','<br/>','</p>','<p>'),' ',$News->teaser)),
66
+                    'text_html' => $strText ?: $News->teaser
52 67
                 );
53 68
 
54 69
                 if (($objJumpTo = $Archive->getRelated('jumpTo')) !== null)
... ...
@@ -59,6 +74,8 @@ class NewsSendTestmailListener
59 74
 
60 75
                 $arrNewsPlain[] = date('d.m.Y',$News->date).' - '.$News->headline;
61 76
                 $arrNewsHtml[] = '<div style="margin-bottom: 15px;"><h3>'.$arrRow['date'].' '.$arrRow['headline'].'</h3><p>'.$arrRow['teaser'].'</p>'. ($arrRow['url'] ? '<p><a href="'.$arrRow['url'].'">&raquo; Ganze Nachricht lesen...</a></p>' : '') .'</div>';
77
+                $arrNewsFullPlain[] = date('d.m.Y',$News->date).' - '.$News->headline . "\n" . $arrRow['text_plain'];
78
+                $arrNewsFullHtml[] = '<div style="margin-bottom: 15px;"><h3>'.$arrRow['date'].' '.$arrRow['headline'].'</h3>' . $arrRow['text_html'] . ($arrRow['url'] ? '<p><a href="'.$arrRow['url'].'">&raquo; Ganze Nachricht lesen...</a></p>' : '') .'</div>';
62 79
 
63 80
                 // User
64 81
                 $strEmail = $User->email;
... ...
@@ -86,6 +103,8 @@ class NewsSendTestmailListener
86 103
                     'member_lastname' => $strLastname,
87 104
                     'news_topics'       => implode("\n",$arrNewsPlain),
88 105
                     'news_topics_html'  => "<ul>\n<li>".str_replace('%%_TOKEN_%%',$strToken,implode("</li>\n<li>",$arrNewsHtml))."</li>\n</ul>",
106
+                    'news_full' => implode("\n",$arrNewsFullPlain),
107
+                    'news_full_html' => implode("",$arrNewsFullHtml),
89 108
                     'member_login_token'  => $strToken,
90 109
                     'admin_email'  => $admin_email,
91 110
                 ),