Browse code

Updates

Benjamin Roth authored on16/03/2023 13:33:40
Showing3 changed files
... ...
@@ -14,7 +14,24 @@ $GLOBALS['NOTIFICATION_CENTER']['NOTIFICATION_TYPE']['contao']['news_submitted']
14 14
 (
15 15
     'recipients'    => array
16 16
     (
17
-        'member_email' // The email address of the recipient
17
+        'member_email', // The email address of the recipient
18
+        'admin_email' // The email address of the recipient
19
+    ),
20
+    'email_sender_address'    => array
21
+    (
22
+        'member_email', // The email address of the recipient
23
+        'admin_email' // The email address of the recipient
24
+    ),
25
+    'email_sender_name'    => array
26
+    (
27
+        'member_email', // The email address of the recipient
28
+        'admin_email' // The email address of the recipient
29
+    ),
30
+    'email_subject'        => array
31
+    (
32
+        'domain',
33
+        'member_email',
34
+        'admin_email'
18 35
     ),
19 36
     'email_text'    => array
20 37
     (
... ...
@@ -22,6 +22,15 @@
22 22
                 <source>Notifications</source>
23 23
                 <target>Benachrichtigungen</target>
24 24
             </trans-unit>
25
+
26
+            <trans-unit id="tl_news.MSC.nc_news_testletter">
27
+                <source>A test notification has been sent to %s.</source>
28
+                <target>Eine Testbenachrichtigung wurde versendet an %s.</target>
29
+            </trans-unit>
30
+            <trans-unit id="tl_news.MSC.nc_news_testletter_error">
31
+                <source>A test notification could not be sent.</source>
32
+                <target>Eine Testmeldung konnte nicht gesendet werden.</target>
33
+            </trans-unit>
25 34
         </body>
26 35
     </file>
27 36
 </xliff>
... ...
@@ -12,10 +12,14 @@ declare(strict_types=1);
12 12
 
13 13
 namespace vonRotenberg\NewsmailerBundle\EventListener;
14 14
 
15
+use Contao\BackendUser;
15 16
 use Contao\Config;
16 17
 use Contao\CoreBundle\ServiceAnnotation\Callback;
17 18
 use Contao\DataContainer;
19
+use Contao\Message;
18 20
 use Contao\NewsModel;
21
+use Contao\StringUtil;
22
+use Contao\System;
19 23
 use NotificationCenter\Model\Notification;
20 24
 
21 25
 class NewsSendTestmailListener
... ...
@@ -33,9 +37,11 @@ class NewsSendTestmailListener
33 37
      */
34 38
     public function onSaveCallback($varValue, DataContainer $dc)
35 39
     {
36
-        if ($varValue)
40
+        if ($varValue && System::getContainer()->get('contao.security.token_checker')->hasBackendUser())
37 41
         {
38 42
             $News = NewsModel::findByPk($dc->id);
43
+            $User = BackendUser::getInstance();
44
+            list($admin_name,$admin_email) = StringUtil::splitFriendlyEmail(Config::get('adminEmail'));
39 45
 
40 46
             if ($News !== null && ($Archive = $News->getRelated('pid')) !== null && ($Notification = Notification::findByPk($Archive->nc_notification)) !== null)
41 47
             {
... ...
@@ -50,41 +56,48 @@ class NewsSendTestmailListener
50 56
                     $arrRow['url'] = $objJumpTo->getAbsoluteUrl(Config::get('useAutoItem') ? '/%s' : '/items/%s').'?ltoken=%%_TOKEN_%%';
51 57
                 }
52 58
 
53
-
54 59
                 $arrNewsPlain[] = date('d.m.Y',$News->date).' - '.$News->headline;
55 60
                 $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>';
56 61
 
57 62
                 // User
58
-                $strEmail = $this->User->email;
59
-                if (($Member = \MemberModel::findActiveByEmailAndUsername($this->User->email)) !== null)
63
+                $strEmail = $User->email;
64
+                if (($Member = \MemberModel::findActiveByEmailAndUsername($strEmail)) !== null)
60 65
                 {
61 66
                     $strLastname = $Member->firstname;
62 67
                     $strFirstname = $Member->lastname;
63
-                    if ($Member->nc_news_additionalEmail)
68
+                    /*if ($Member->nc_news_additionalEmail)
64 69
                     {
65 70
                         $strEmail .= ','.$Member->nc_news_additionalEmail;
66
-                    }
67
-                    $strToken = \TokenLogin::getOrRenewUserToken($Member);
71
+                    }*/
72
+//                    $strToken = \TokenLogin::getOrRenewUserToken($Member);
73
+                    $strToken = '';
68 74
                 } else {
69
-                    $arrSplitName = explode(" ", $this->User->name);
75
+                    $arrSplitName = explode(" ", $User->name);
70 76
                     $strLastname = array_pop($arrSplitName);
71 77
                     $strFirstname = implode(" ", $arrSplitName);
72 78
                     $strToken = '';
73 79
                 }
74 80
 
75
-                $Notification->send(array
81
+                if ($Notification->send(array
76 82
                 (
77 83
                     'member_email'      => $strEmail,
78 84
                     'member_firstname' => $strFirstname,
79 85
                     'member_lastname' => $strLastname,
80 86
                     'news_topics'       => implode("\n",$arrNewsPlain),
81 87
                     'news_topics_html'  => "<ul>\n<li>".str_replace('%%_TOKEN_%%',$strToken,implode("</li>\n<li>",$arrNewsHtml))."</li>\n</ul>",
82
-                    'member_login_token'  => $strToken
88
+                    'member_login_token'  => $strToken,
89
+                    'admin_email'  => $admin_email,
83 90
                 ),
84
-                    $GLOBALS['TL_LANGUAGE']);
91
+                    $GLOBALS['TL_LANGUAGE']))
92
+                {
93
+                    Message::addConfirmation(sprintf($GLOBALS['TL_LANG']['tl_news']['MSC']['nc_news_testletter'],$strEmail));
94
+                } else {
95
+                    Message::addError($GLOBALS['TL_LANG']['tl_news']['MSC']['nc_news_testletter_error']);
96
+                }
85 97
 
86
-                Message::addConfirmation($GLOBALS['TL_LANG']['tl_news']['MSC']['nc_news_testletter']);
87 98
             }
88 99
         }
100
+
101
+        return null;
89 102
     }
90 103
 }