/
feeds.php
182 lines (158 loc) · 5.5 KB
/
feeds.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
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
<?php
namespace Concrete\Controller\SinglePage\Dashboard\Pages;
use Concrete\Core\Area\Area;
use Concrete\Core\Attribute\Key\CollectionKey;
use Concrete\Core\Page\Controller\DashboardPageController;
use Concrete\Core\Page\Feed;
use Concrete\Core\Page\Type\Type;
use Core;
class Feeds extends DashboardPageController
{
public function view()
{
$this->set('feeds', Feed::getList());
}
public function feed_updated()
{
$this->set('success', t('Feed Updated.'));
$this->view();
}
public function feed_deleted()
{
$this->set('success', t('Feed Deleted.'));
$this->view();
}
public function feed_added()
{
$this->set('success', t('Feed Added.'));
$this->view();
}
protected function validatePageRequest($token)
{
if (!$this->token->validate($token)) {
$this->error->add($this->token->getErrorMessage());
}
$sec = Core::make('helper/security');
$vs = Core::make('helper/validation/strings');
$handle = $sec->sanitizeString($this->request->request->get('pfHandle'));
$title = $sec->sanitizeString($this->request->request->get('pfTitle'));
$description = $sec->sanitizeString($this->request->request->get('pfDescription'));
if (!$title) {
$this->error->add(t('You must specify a valid title.'));
}
if (!$description) {
$this->error->add(t('You must specify a valid description.'));
}
if (!$vs->handle($handle)) {
$this->error->add(t('A valid handle must contain no punctuation or spaces.'));
}
}
protected function loadFeedFromRequest(\Concrete\Core\Entity\Page\Feed $pf = null)
{
if (!$pf) {
$pf = new \Concrete\Core\Entity\Page\Feed();
}
$pf->setTitle($this->post('pfTitle'));
$pf->setDescription($this->post('pfDescription'));
$pf->setHandle($this->post('pfHandle'));
$pf->setPageTypeID($this->post('ptID'));
$pf->setCustomTopicAttributeKeyHandle($this->post('customTopicAttributeKeyHandle'));
$customTopicTreeNodeID = $this->post('customTopicAttributeKeyHandle') ? $this->post('customTopicTreeNodeID') : 0;
$pf->setCustomTopicTreeNodeID($customTopicTreeNodeID);
$pf->setParentID(intval($this->post('cParentID')));
$pf->setIncludeAllDescendents($this->post('pfIncludeAllDescendents'));
$pf->setDisplayAliases($this->post('pfDisplayAliases'));
$pf->setIconFileID($this->post('iconFID'));
$pf->setDisplayFeaturedOnly($this->post('pfDisplayFeaturedOnly'));
if ($this->post('pfContentToDisplay') == 'A') {
$pf->displayAreaContent($this->post('pfAreaHandleToDisplay'));
} else {
$pf->displayShortDescriptionContent();
}
if ($this->post('ignorePermissions')) {
$pf->setCheckPagePermissions(false);
} else {
$pf->setCheckPagePermissions(true);
}
return $pf;
}
public function add_feed()
{
$this->validatePageRequest('add_feed');
if (!$this->error->has()) {
$pf = $this->loadFeedFromRequest();
$pf->save();
$this->redirect('/dashboard/pages/feeds', 'feed_added');
}
$this->add();
}
public function delete_feed()
{
$pfID = $this->request->request->get('pfID');
if (Core::make('helper/validation/numbers')->integer($pfID)) {
if ($pfID > 0) {
$feed = Feed::getByID($pfID);
}
}
if (!is_object($feed)) {
$this->error->add(t('Invalid feed.'));
}
if (!$this->token->validate('delete_feed')) {
$this->error->add($this->token->getErrorMessage());
}
if (!$this->error->has()) {
$feed->delete();
$this->redirect('/dashboard/pages/feeds', 'feed_deleted');
}
$this->edit($pfID);
}
public function edit_feed($pfID = null)
{
$this->validatePageRequest('edit_feed');
$this->edit($pfID);
$pf = Feed::getByID($pfID);
if (!$this->error->has()) {
$pf = $this->loadFeedFromRequest($pf);
$pf->save();
$this->redirect('/dashboard/pages/feeds', 'feed_updated');
}
}
public function add()
{
$pageTypes = ['0' => t('** No Filtering')];
$types = Type::getList();
foreach ($types as $type) {
$pageTypes[$type->getPageTypeID()] = $type->getPageTypeDisplayName();
}
$this->set('pageTypes', $pageTypes);
$attributeKeys = [];
$keys = CollectionKey::getList();
foreach ($keys as $ak) {
if ($ak->getAttributeTypeHandle() == 'topics') {
$attributeKeys[] = $ak;
}
}
$this->set('topicAttributes', $attributeKeys);
$areas = Area::getHandleList();
$select = [];
foreach ($areas as $handle) {
$select[$handle] = $handle;
}
$this->set('areas', $select);
$this->requireAsset('core/topics');
}
public function edit($pfID = null)
{
if (Core::make('helper/validation/numbers')->integer($pfID)) {
if ($pfID > 0) {
$feed = Feed::getByID($pfID);
}
}
if (!is_object($feed)) {
$this->redirect('/dashboard/pages/feeds');
}
$this->feed = $feed;
$this->set('feed', $feed);
$this->add();
}
}