forked from psi-4ward/news4ward
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleNews4wardList.php
More file actions
214 lines (169 loc) · 6.07 KB
/
ModuleNews4wardList.php
File metadata and controls
214 lines (169 loc) · 6.07 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php if(!defined('TL_ROOT')) die('You cannot access this file directly!');
/**
* News4ward
* a contentelement driven news/blog-system
*
* @author Christoph Wiechert <[email protected]>
* @copyright 4ward.media GbR <http://www.4wardmedia.de>
* @package news4ward
* @filesource
* @licence LGPL
*/
class ModuleNews4wardList extends News4ward
{
/**
* Template
* @var string
*/
protected $strTemplate = 'mod_news4ward_list';
/**
* Display a wildcard in the back end
* @return string
*/
public function generate()
{
if (TL_MODE == 'BE')
{
$objTemplate = new BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### News4ward LIST ###';
$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->news_archives = $this->sortOutProtected(deserialize($this->news4ward_archives));
// Return if there are no archives
if (!is_array($this->news_archives) || count($this->news_archives) < 1)
{
return '';
}
return parent::generate();
}
/**
* Generate module
*/
protected function compile()
{
$time = time();
/* build where */
$where = array();
// news archives
$where[] = 'tl_news4ward_article.pid IN('. implode(',', array_map('intval', $this->news_archives)) . ')';
// published
if(!BE_USER_LOGGED_IN)
{
$where[] = "(tl_news4ward_article.start='' OR tl_news4ward_article.start<".$time.") AND (tl_news4ward_article.stop='' OR tl_news4ward_article.stop>".$time.") AND tl_news4ward_article.status='published'";
}
// show only highlighted items?
if($this->news4ward_featured == 'featured')
$where[] = 'tl_news4ward_article.highlight="1"';
elseif($this->news4ward_featured == 'unfeatured')
$where[] = 'tl_news4ward_article.highlight<>"1"';
// HOOK: add filter logic from other modules like tags
if(isset($GLOBALS['TL_HOOKS']['News4wardListFilter']) && is_array($GLOBALS['TL_HOOKS']['News4wardListFilter']))
{
foreach ($GLOBALS['TL_HOOKS']['News4wardListFilter'] as $callback)
{
$this->import($callback[0]);
$tmp = $this->$callback[0]->$callback[1]($this);
if (is_string($tmp) && !empty($tmp))
$where[] = $tmp;
}
}
/* Ordering */
$ordering = array('tl_news4ward_article.sticky DESC');
switch($this->news4ward_order)
{
case 'title ASC': $ordering[] = 'tl_news4ward_article.title'; break;
case 'title DESC': $ordering[] = 'tl_news4ward_article.title DESC'; break;
case 'start ASC': $ordering[] = 'tl_news4ward_article.start'; break;
case 'start DESC': $ordering[] = 'tl_news4ward_article.start DESC'; break;
}
/* Pagination */
$skipFirst = intval($this->skipFirst);
$offset = 0;
$limit = null;
// Maximum number of items
if ($this->news4ward_numberOfItems > 0) $limit = $this->news4ward_numberOfItems;
// Get the total number of items
$objTotal = $this->Database->execute("SELECT COUNT(*) AS total FROM tl_news4ward_article WHERE ".implode(' AND ',$where));
$total = $objTotal->total - $skipFirst;
// Split the results
if ($this->perPage > 0 && (!isset($limit) || $this->news_numberOfItems > $this->perPage))
{
// Adjust the overall limit
if (isset($limit))
{
$total = min($limit, $total);
}
$page = $this->Input->get('page') ? $this->Input->get('page') : 1;
// Check the maximum page number
if ($page > ($total/$this->perPage))
{
$page = ceil($total/$this->perPage);
}
// Limit and offset
$limit = $this->perPage;
$offset = (max($page, 1) - 1) * $this->perPage;
// Overall limit
if ($offset + $limit > $total)
{
$limit = $total - $offset;
}
// Add the pagination menu
$objPagination = new Pagination($total, $this->perPage);
$this->Template->pagination = $objPagination->generate("\n ");
}
/* get the items */
$objArticlesStmt = $this->Database->prepare("
SELECT *, author AS authorId,
(SELECT title FROM tl_news4ward WHERE tl_news4ward.id=tl_news4ward_article.pid) AS archive,
(SELECT jumpTo FROM tl_news4ward WHERE tl_news4ward.id=tl_news4ward_article.pid) AS parentJumpTo,
(SELECT name FROM tl_user WHERE id=author) AS author
FROM tl_news4ward_article
WHERE ".implode(' AND ',$where)
.((count($ordering)) ? ' ORDER BY '.implode(',',$ordering) : ''));
// Limit the result
if (isset($limit))
{
$objArticlesStmt->limit($limit, $offset + $skipFirst);
}
elseif ($skipFirst > 0)
{
$objArticlesStmt->limit(max($total, 1), $skipFirst);
}
$objArticles = $objArticlesStmt->execute();
$this->Template->articles = $this->parseArticles($objArticles);
$this->Template->archives = $this->news_archives;
$this->Template->empty = $GLOBALS['TL_LANG']['MSC']['emptyList'];
// add newsfeeds to page
$this->addNewsfeedsToLayout();
}
/**
* Add Newsfeeds links to the page
* @return void
*/
protected function addNewsfeedsToLayout()
{
if(!$GLOBALS['objPage']->layout)
{
$objLayout = $this->Database->prepare('SELECT news4ward_feeds FROM tl_layout WHERE fallback="1"')->limit(1)->execute();
}
else
{
$objLayout = $this->Database->prepare('SELECT news4ward_feeds FROM tl_layout WHERE id=?')->limit(1)->execute($GLOBALS['objPage']->layout);
}
if(!$objLayout->numRows) return;
$arrNews4wardIDs = deserialize($objLayout->news4ward_feeds,true);
if(empty($arrNews4wardIDs)) return;
$objNews4ward = $this->Database->prepare('SELECT feedBase,alias,format,title FROM tl_news4ward WHERE FIND_IN_SET(id,?) AND makeFeed="1"')->execute(implode(',',$arrNews4wardIDs));
if(!$objNews4ward->numRows) return;
$strTagEnding = ($GLOBALS['objPage']->outputFormat == 'xhtml') ? ' />' : '>';
while($objNews4ward->next())
{
$base = strlen($objNews4ward->feedBase) ? $objNews4ward->feedBase : $this->Environment->base;
$GLOBALS['TL_HEAD'][] = '<link rel="alternate" href="' . $base . $objNews4ward->alias . '.xml" type="application/' . $objNews4ward->format . '+xml" title="' . $objNews4ward->title . '"' . $strTagEnding . "\n";
}
}
}