-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
ModuleNewsletterList.php
129 lines (107 loc) · 3.13 KB
/
ModuleNewsletterList.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/*
* This file is part of Contao.
*
* (c) Leo Feyer
*
* @license LGPL-3.0-or-later
*/
namespace Contao;
use Patchwork\Utf8;
/**
* Front end module "newsletter list".
*
* @property array $nl_channels
*
* @author Leo Feyer <https://github.com/leofeyer>
*/
class ModuleNewsletterList extends Module
{
/**
* Template
* @var string
*/
protected $strTemplate = 'mod_newsletterlist';
/**
* Display a wildcard in the back end
*
* @return string
*/
public function generate()
{
$request = System::getContainer()->get('request_stack')->getCurrentRequest();
if ($request && System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest($request))
{
$objTemplate = new BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### ' . Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['newsletterlist'][0]) . ' ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
return $objTemplate->parse();
}
$this->nl_channels = StringUtil::deserialize($this->nl_channels);
// Return if there are no channels
if (empty($this->nl_channels) || !\is_array($this->nl_channels))
{
return '';
}
return parent::generate();
}
/**
* Generate the module
*/
protected function compile()
{
/** @var PageModel $objPage */
global $objPage;
$arrJumpTo = array();
$arrNewsletter = array();
$strRequest = StringUtil::ampersand(Environment::get('request'));
$objNewsletter = NewsletterModel::findSentByPids($this->nl_channels);
if ($objNewsletter !== null)
{
while ($objNewsletter->next())
{
/** @var NewsletterChannelModel $objTarget */
if (!($objTarget = $objNewsletter->getRelated('pid')) instanceof NewsletterChannelModel)
{
continue;
}
$jumpTo = (int) $objTarget->jumpTo;
// Skip channels without a jumpTo page (see #6521 and #494)
if ($jumpTo < 1)
{
continue;
}
$strUrl = $strRequest;
if (!isset($arrJumpTo[$objTarget->jumpTo]))
{
if (($objJumpTo = $objTarget->getRelated('jumpTo')) instanceof PageModel)
{
/** @var PageModel $objJumpTo */
$arrJumpTo[$objTarget->jumpTo] = $objJumpTo->getFrontendUrl(Config::get('useAutoItem') ? '/%s' : '/items/%s');
}
else
{
$arrJumpTo[$objTarget->jumpTo] = $strUrl;
}
}
$strUrl = $arrJumpTo[$objTarget->jumpTo];
$strAlias = $objNewsletter->alias ?: $objNewsletter->id;
$arrNewsletter[] = array
(
'subject' => $objNewsletter->subject,
'title' => StringUtil::stripInsertTags($objNewsletter->subject),
'href' => sprintf(preg_replace('/%(?!s)/', '%%', $strUrl), $strAlias),
'date' => Date::parse($objPage->dateFormat, $objNewsletter->date),
'datim' => Date::parse($objPage->datimFormat, $objNewsletter->date),
'time' => Date::parse($objPage->timeFormat, $objNewsletter->date),
'channel' => $objNewsletter->pid
);
}
}
$this->Template->newsletters = $arrNewsletter;
}
}
class_alias(ModuleNewsletterList::class, 'ModuleNewsletterList');