forked from psi-4ward/news4ward
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleNews4wardReader.php
More file actions
145 lines (114 loc) · 4 KB
/
Copy pathModuleNews4wardReader.php
File metadata and controls
145 lines (114 loc) · 4 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
<?php if(!defined('TL_ROOT')) die('You cannot access this file directly!');
/**
* News4ward
* a contentelement driven news/blog-system
*
* @author Christoph Wiechert <wio@psitrax.de>
* @copyright 4ward.media GbR <http://www.4wardmedia.de>
* @package news4ward
* @filesource
* @licence LGPL
*/
class ModuleNews4wardReader extends News4ward
{
/**
* Template
* @var string
*/
protected $strTemplate = 'mod_news4ward_reader';
/**
* Display a wildcard in the back end
* @return string
*/
public function generate()
{
if (TL_MODE == 'BE')
{
$objTemplate = new BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### News4ward READER ###';
$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 '';
}
// Read the alias from the url
if(!preg_match("~.*".preg_quote($GLOBALS['objPage']->alias)."/([a-z0-9\._-]+).*~i",$this->Environment->request,$erg))
{
return '';
}
// strip suffix
if(substr($erg[1],-strlen($GLOBALS['TL_CONFIG']['urlSuffix'])) == $GLOBALS['TL_CONFIG']['urlSuffix'])
{
$erg[1] = substr($erg[1],0,-strlen($GLOBALS['TL_CONFIG']['urlSuffix']));
}
$this->alias = $erg[1];
return parent::generate();
}
/**
* Generate module
*/
protected function compile()
{
// Set the item from the auto_item parameter
if ($GLOBALS['TL_CONFIG']['useAutoItem'] && isset($_GET['auto_item']))
{
$this->Input->setGet('items', $this->Input->get('auto_item'));
}
/* build where */
$where = array();
$time = time();
// 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'";
}
// alias
$where[] = 'tl_news4ward_article.alias = "'.mysql_real_escape_string($this->alias).'"';
/* get the item */
$objArticle = $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))->execute();
if(!$objArticle->numRows) return;
$this->parseArticles($objArticle,$this->Template);
// Add keywords and description
if ($this->keywords != '')
{
$GLOBALS['TL_KEYWORDS'] .= (strlen($GLOBALS['TL_KEYWORDS']) ? ', ' : '') . $objArticle->keywords;
}
if ($this->description != '')
{
$GLOBALS['objPage']->description .= (!empty($GLOBALS['objPage']->description) ? ' ': '') . $objArticle->description;
}
// Add Page Title
$GLOBALS['objPage']->title = $objArticle->title;
// Add facebook meta for the teaserimage
if($this->news4ward_useTeaserImageForFacebook && $objArticle->teaserImage && is_file(TL_ROOT.'/'.$objArticle->teaserImage))
{
$GLOBALS['TL_HEAD'][] = '<link rel="image_src" href="'.$this->getImage($objArticle->teaserImage,50,50,'proportional').'" />';
}
// HOOK: add content like comments or related articles
// todo: who needs this hook? theres also News4wardParseArticles HOOK
if(isset($GLOBALS['TL_HOOKS']['News4wardReader']) && is_array($GLOBALS['TL_HOOKS']['News4wardReader']))
{
foreach ($GLOBALS['TL_HOOKS']['News4wardReader'] as $callback)
{
$this->import($callback[0]);
$this->$callback[0]->$callback[1]($objArticle,$this);
}
}
}
}
?>