... | ... |
@@ -35,7 +35,7 @@ class NewsNotifications extends \System |
35 | 35 |
$time = \Date::floorToMinute(); |
36 | 36 |
|
37 | 37 |
// Do we have new news items |
38 |
- $News = \Database::getInstance()->prepare("SELECT id, headline, date FROM tl_news WHERE pid = ? AND nc_sent != '1' AND (start='' OR start<='$time') AND (stop='' OR stop>'" . ($time + 60) . "') AND published='1' ORDER BY date DESC, time DESC") |
|
38 |
+ $News = \Database::getInstance()->prepare("SELECT id, alias, headline, date, teaser FROM tl_news WHERE pid = ? AND nc_sent != '1' AND (start='' OR start<='$time') AND (stop='' OR stop>'" . ($time + 60) . "') AND published='1' ORDER BY date DESC, time DESC") |
|
39 | 39 |
->execute($Archive->id); |
40 | 40 |
|
41 | 41 |
// Load groups and notification models if we have news to share |
... | ... |
@@ -57,20 +57,41 @@ class NewsNotifications extends \System |
57 | 57 |
if ($Members !== null) |
58 | 58 |
{ |
59 | 59 |
$arrNews = array(); |
60 |
+ $arrNewsPlain = array(); |
|
60 | 61 |
$News->reset(); |
61 | 62 |
while ($News->next()) |
62 | 63 |
{ |
63 |
- $arrNews[] = date('d.m.Y',$News->date)." - ".$News->headline; |
|
64 |
+ $arrRow = array( |
|
65 |
+ 'date' => date('d.m.Y',$News->date), |
|
66 |
+ 'headline' => $News->headline, |
|
67 |
+ 'teaser' => \Contao\StringUtil::substr(strip_tags(str_ireplace(array('<br />','<br>','<br/>','</p>','<p>'),' ',$News->teaser)),128) |
|
68 |
+ ); |
|
69 |
+ |
|
70 |
+ if (($objJumpTo = $Archive->getRelated('jumpTo')) !== null) |
|
71 |
+ { |
|
72 |
+ $objJumpTo->loadDetails(); |
|
73 |
+ $arrRow['url'] = ($objJumpTo->rootUseSSL ? 'https://' : 'http://') . $objJumpTo->domain . TL_PATH . '/' . \Controller::generateFrontendUrl($objJumpTo->row(),((\Config::get('useAutoItem') && !\Config::get('disableAlias')) ? '/' : '/items/') . ((!\Config::get('disableAlias') && $News->alias != '') ? $News->alias : $News->id)); |
|
74 |
+ } |
|
75 |
+ |
|
76 |
+ $arrNews[] = $arrRow; |
|
77 |
+ |
|
78 |
+ $arrNewsPlain[] = date('d.m.Y',$News->date).' - '.$News->headline; |
|
79 |
+ $arrNewsHtml[] = '<div style="margin-bottom: 15px;"><h3>'.$arrRow['date'].' '.$arrRow['headline'].'</h3><p>'.$arrRow['teaser'].'</p>'. ($arrRow['url'] ? '<p><a href="'.$arrRow['url'].'">» Neuigkeit lesen...</a></p>' : '') .'</div>'; |
|
64 | 80 |
} |
65 | 81 |
while ($Members->next()) |
66 | 82 |
{ |
83 |
+ if (!$Members->nc_news_subscribe) |
|
84 |
+ { |
|
85 |
+ continue; |
|
86 |
+ } |
|
87 |
+ |
|
67 | 88 |
$Notification->send(array |
68 | 89 |
( |
69 | 90 |
'member_email' => $Members->email, |
70 | 91 |
'member_firstname' => $Members->firstname, |
71 | 92 |
'member_lastname' => $Members->lastname, |
72 |
- 'news_topics' => implode("\n",$arrNews), |
|
73 |
- 'news_topics_html' => "<ul>\n<li>".implode("</li>\n<li>",$arrNews)."</li>\n</ul>" |
|
93 |
+ 'news_topics' => implode("\n",$arrNewsPlain), |
|
94 |
+ 'news_topics_html' => "<ul>\n<li>".implode("</li>\n<li>",$arrNewsHtml)."</li>\n</ul>" |
|
74 | 95 |
), |
75 | 96 |
$GLOBALS['TL_LANGUAGE']); |
76 | 97 |
} |
77 | 98 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,72 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+/** |
|
4 |
+ * News notification extension for Contao |
|
5 |
+ * |
|
6 |
+ * Copyright (c) 2016 Benjamin Roth |
|
7 |
+ * |
|
8 |
+ * @link http://www.esales-media.de |
|
9 |
+ * @license commercial |
|
10 |
+ */ |
|
11 |
+ |
|
12 |
+/** |
|
13 |
+ * Palettes |
|
14 |
+ */ |
|
15 |
+ |
|
16 |
+$GLOBALS['TL_DCA']['tl_member']['palettes']['default'] = str_replace(array(',email,','email;'),array(',email,nc_news_subscribe,',',email,nc_news_subscribe;'),$GLOBALS['TL_DCA']['tl_member']['palettes']['default']); |
|
17 |
+ |
|
18 |
+ |
|
19 |
+/** |
|
20 |
+ * Fields |
|
21 |
+ */ |
|
22 |
+ |
|
23 |
+$GLOBALS['TL_DCA']['tl_member']['fields']['nc_news_subscribe'] = array |
|
24 |
+( |
|
25 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_member']['nc_news_subscribe'], |
|
26 |
+ 'exclude' => true, |
|
27 |
+ 'inputType' => 'checkbox', |
|
28 |
+ 'eval' => array('tl_class'=>'w50 m12', 'doNotCopy'=>true, 'feEditable'=>true, 'feViewable'=>true, 'feGroup'=>'contact'), |
|
29 |
+ 'save_callback' => array |
|
30 |
+ ( |
|
31 |
+ array('tl_member_eSM_nc_news', 'setNcNewsChangedate'), |
|
32 |
+ ), |
|
33 |
+ 'sql' => "char(1) NOT NULL default '1'" |
|
34 |
+); |
|
35 |
+ |
|
36 |
+$GLOBALS['TL_DCA']['tl_member']['fields']['nc_news_subscribe_changed'] = array |
|
37 |
+( |
|
38 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_member']['nc_news_subscribe_changed'], |
|
39 |
+ 'eval' => array('rgxp'=>'datim'), |
|
40 |
+ 'sql' => "int(10) unsigned NOT NULL default '0'" |
|
41 |
+); |
|
42 |
+ |
|
43 |
+ |
|
44 |
+/** |
|
45 |
+ * Provide miscellaneous methods that are used by the data configuration array. |
|
46 |
+ * |
|
47 |
+ * @author Benjamin Roth <http://www.esales-media.de> |
|
48 |
+ */ |
|
49 |
+class tl_member_eSM_nc_news extends \Backend |
|
50 |
+{ |
|
51 |
+ |
|
52 |
+ public function __construct() |
|
53 |
+ { |
|
54 |
+ parent::__construct(); |
|
55 |
+ $this->import('BackendUser', 'User'); |
|
56 |
+ } |
|
57 |
+ |
|
58 |
+ /** |
|
59 |
+ * Reset field |
|
60 |
+ * |
|
61 |
+ * @return array |
|
62 |
+ */ |
|
63 |
+ public function setNcNewsChangedate($varValue, DataContainer $dc) |
|
64 |
+ { |
|
65 |
+ if ($varValue != $dc->activeRecord->nc_news_subscribe) |
|
66 |
+ { |
|
67 |
+ \Database::getInstance()->prepare("UPDATE tl_member SET nc_news_subscribe_changed=? WHERE id=?")->execute(array(time(),$dc->id)); |
|
68 |
+ } |
|
69 |
+ |
|
70 |
+ return $varValue; |
|
71 |
+ } |
|
72 |
+} |
|
0 | 73 |
\ No newline at end of file |
... | ... |
@@ -10,10 +10,121 @@ |
10 | 10 |
*/ |
11 | 11 |
|
12 | 12 |
/** |
13 |
+ * Palettes |
|
14 |
+ */ |
|
15 |
+ |
|
16 |
+$GLOBALS['TL_DCA']['tl_news']['palettes']['default'] = str_replace(array('{publish_legend}','{publish_legend:hide}'),array('{nc_legend:hide},nc_sent,nc_testmail;{publish_legend}','{nc_legend:hide},nc_sent,nc_testmail;{publish_legend:hide}'),$GLOBALS['TL_DCA']['tl_news']['palettes']['default']); |
|
17 |
+ |
|
18 |
+ |
|
19 |
+/** |
|
13 | 20 |
* Fields |
14 | 21 |
*/ |
15 | 22 |
|
16 | 23 |
$GLOBALS['TL_DCA']['tl_news']['fields']['nc_sent'] = array |
17 | 24 |
( |
25 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_news']['nc_sent'], |
|
26 |
+ 'exclude' => true, |
|
27 |
+ 'inputType' => 'checkbox', |
|
28 |
+ 'eval' => array('doNotCopy'=>true), |
|
18 | 29 |
'sql' => "char(1) NOT NULL default ''" |
19 | 30 |
); |
31 |
+ |
|
32 |
+$GLOBALS['TL_DCA']['tl_news']['fields']['nc_testmail'] = array |
|
33 |
+( |
|
34 |
+ 'label' => &$GLOBALS['TL_LANG']['tl_news']['nc_testmail'], |
|
35 |
+ 'exclude' => true, |
|
36 |
+ 'inputType' => 'checkbox', |
|
37 |
+ 'eval' => array('doNotSaveEmpty'=>true), |
|
38 |
+ 'load_callback' => array |
|
39 |
+ ( |
|
40 |
+ array('tl_news_eSM_nc_news', 'loadTestmail'), |
|
41 |
+ ), |
|
42 |
+ 'save_callback' => array |
|
43 |
+ ( |
|
44 |
+ array('tl_news_eSM_nc_news', 'sendTestmail'), |
|
45 |
+ ), |
|
46 |
+); |
|
47 |
+ |
|
48 |
+ |
|
49 |
+/** |
|
50 |
+ * Provide miscellaneous methods that are used by the data configuration array. |
|
51 |
+ * |
|
52 |
+ * @author Benjamin Roth <http://www.esales-media.de> |
|
53 |
+ */ |
|
54 |
+class tl_news_eSM_nc_news extends \Backend |
|
55 |
+{ |
|
56 |
+ |
|
57 |
+ public function __construct() |
|
58 |
+ { |
|
59 |
+ parent::__construct(); |
|
60 |
+ $this->import('BackendUser', 'User'); |
|
61 |
+ } |
|
62 |
+ |
|
63 |
+ /** |
|
64 |
+ * Reset field |
|
65 |
+ * |
|
66 |
+ * @return array |
|
67 |
+ */ |
|
68 |
+ public function loadTestmail($varValue, DataContainer $dc) |
|
69 |
+ { |
|
70 |
+ return ''; |
|
71 |
+ } |
|
72 |
+ |
|
73 |
+ /** |
|
74 |
+ * Reset field |
|
75 |
+ * |
|
76 |
+ * @return array |
|
77 |
+ */ |
|
78 |
+ public function sendTestmail($varValue, DataContainer $dc) |
|
79 |
+ { |
|
80 |
+ if ($varValue) |
|
81 |
+ { |
|
82 |
+ $News = \Contao\NewsModel::findByPk($dc->id); |
|
83 |
+ |
|
84 |
+ if ($News !== null && ($Archive = $News->getRelated('pid')) !== null && ($Notification = \NotificationCenter\Model\Notification::findByPk($Archive->nc_notification)) !== null) |
|
85 |
+ { |
|
86 |
+ $arrRow = array( |
|
87 |
+ 'date' => date('d.m.Y',$News->date), |
|
88 |
+ 'headline' => $News->headline, |
|
89 |
+ 'teaser' => \Contao\StringUtil::substr(strip_tags(str_ireplace(array('<br />','<br>','<br/>','</p>','<p>'),' ',$News->teaser)),128) |
|
90 |
+ ); |
|
91 |
+ |
|
92 |
+ if (($objJumpTo = $Archive->getRelated('jumpTo')) !== null) |
|
93 |
+ { |
|
94 |
+ $objJumpTo->loadDetails(); |
|
95 |
+ $arrRow['url'] = ($objJumpTo->rootUseSSL ? 'https://' : 'http://') . $objJumpTo->domain . TL_PATH . '/' . \Controller::generateFrontendUrl($objJumpTo->row(),((\Config::get('useAutoItem') && !\Config::get('disableAlias')) ? '/' : '/items/') . ((!\Config::get('disableAlias') && $News->alias != '') ? $News->alias : $News->id)).'?ltoken=%%_TOKEN_%%'; |
|
96 |
+ } |
|
97 |
+ |
|
98 |
+ |
|
99 |
+ $arrNewsPlain[] = date('d.m.Y',$News->date).' - '.$News->headline; |
|
100 |
+ $arrNewsHtml[] = '<div style="margin-bottom: 15px;"><h3>'.$arrRow['date'].' '.$arrRow['headline'].'</h3><p>'.$arrRow['teaser'].'</p>'. ($arrRow['url'] ? '<p><a href="'.$arrRow['url'].'">» Neuigkeit lesen...</a></p>' : '') .'</div>'; |
|
101 |
+ |
|
102 |
+ // User |
|
103 |
+ if (($Member = \MemberModel::findActiveByEmailAndUsername($this->User->email)) !== null) |
|
104 |
+ { |
|
105 |
+ $strLastname = $Member->firstname; |
|
106 |
+ $strFirstname = $Member->lastname; |
|
107 |
+ $strToken = \TokenLogin::getOrRenewUserToken($Member); |
|
108 |
+ } else { |
|
109 |
+ $arrSplitName = explode(" ", $this->User->name); |
|
110 |
+ $strLastname = array_pop($arrSplitName); |
|
111 |
+ $strFirstname = implode(" ", $arrSplitName); |
|
112 |
+ $strToken = ''; |
|
113 |
+ } |
|
114 |
+ |
|
115 |
+ $Notification->send(array |
|
116 |
+ ( |
|
117 |
+ 'member_email' => $this->User->email, |
|
118 |
+ 'member_firstname' => $strFirstname, |
|
119 |
+ 'member_lastname' => $strLastname, |
|
120 |
+ 'news_topics' => implode("\n",$arrNewsPlain), |
|
121 |
+ 'news_topics_html' => "<ul>\n<li>".str_replace('%%_TOKEN_%%',$strToken,implode("</li>\n<li>",$arrNewsHtml))."</li>\n</ul>", |
|
122 |
+ 'member_login_token' => $strToken |
|
123 |
+ ), |
|
124 |
+ $GLOBALS['TL_LANGUAGE']); |
|
125 |
+ |
|
126 |
+ Message::addConfirmation($GLOBALS['TL_LANG']['tl_news']['MSC']['nc_news_testletter']); |
|
127 |
+ } |
|
128 |
+ } |
|
129 |
+ } |
|
130 |
+} |
20 | 131 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,23 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+/** |
|
4 |
+ * News notification extension for Contao |
|
5 |
+ * |
|
6 |
+ * Copyright (c) 2016 Benjamin Roth |
|
7 |
+ * |
|
8 |
+ * @link http://www.esales-media.de |
|
9 |
+ * @license commercial |
|
10 |
+ */ |
|
11 |
+ |
|
12 |
+/** |
|
13 |
+ * Fields |
|
14 |
+ */ |
|
15 |
+ |
|
16 |
+$GLOBALS['TL_LANG']['tl_member']['nc_news_subscribe'][0] = 'Benachrichtigungen'; |
|
17 |
+$GLOBALS['TL_LANG']['tl_member']['nc_news_subscribe'][1] = 'Benachrichtigungen per E-Mail über neue News-Artikel.'; |
|
18 |
+$GLOBALS['TL_LANG']['tl_member']['nc_news_subscribe_changed'][0] = 'News-Benachrichtigungen Änderungsdatum'; |
|
19 |
+$GLOBALS['TL_LANG']['tl_member']['nc_news_subscribe_changed'][1] = 'Zeit, wann das News-Benachrichtigungsabo zuletzt geändert wurde.'; |
|
20 |
+ |
|
21 |
+/** |
|
22 |
+ * Legends |
|
23 |
+ */ |
0 | 24 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,29 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+/** |
|
4 |
+ * News notification extension for Contao |
|
5 |
+ * |
|
6 |
+ * Copyright (c) 2016 Benjamin Roth |
|
7 |
+ * |
|
8 |
+ * @link http://www.esales-media.de |
|
9 |
+ * @license commercial |
|
10 |
+ */ |
|
11 |
+ |
|
12 |
+/** |
|
13 |
+ * Fields |
|
14 |
+ */ |
|
15 |
+ |
|
16 |
+$GLOBALS['TL_LANG']['tl_news']['nc_sent'][0] = 'Benachrichtigung gesendet'; |
|
17 |
+$GLOBALS['TL_LANG']['tl_news']['nc_sent'][1] = 'Es wurde bereits eine Benachrichtung an ausgewählte Mitgliedergruppen versendet. Zum erneuten senden, Haken entfernen.'; |
|
18 |
+$GLOBALS['TL_LANG']['tl_news']['nc_testmail'][0] = 'Testbenachrichtigung senden'; |
|
19 |
+$GLOBALS['TL_LANG']['tl_news']['nc_testmail'][1] = 'Es wird eine Testbenachrichtigung an den momentan eingeloggten Backend-User gesendet.'; |
|
20 |
+ |
|
21 |
+/** |
|
22 |
+ * Legends |
|
23 |
+ */ |
|
24 |
+$GLOBALS['TL_LANG']['tl_news']['nc_legend'] = 'Benachrichtigungen'; |
|
25 |
+ |
|
26 |
+/** |
|
27 |
+ * Misc |
|
28 |
+ */ |
|
29 |
+$GLOBALS['TL_LANG']['tl_news']['MSC']['nc_news_testletter'] = 'Die Testbenachrichtigung wurde versendet.'; |