|
1
|
|
|
<?php |
|
2
|
|
|
class Intraface_modules_cms_PageGateway |
|
3
|
|
|
{ |
|
4
|
|
|
protected $db; |
|
5
|
|
|
protected $kernel; |
|
6
|
|
|
protected $dbquery; |
|
7
|
|
|
protected $cmssite; |
|
8
|
|
|
protected $values; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* |
|
12
|
|
|
* @var array page status types |
|
13
|
|
|
*/ |
|
14
|
|
|
public $status_types = array( |
|
15
|
|
|
0 => 'draft', |
|
16
|
|
|
1 => 'published' |
|
17
|
|
|
); |
|
18
|
|
|
|
|
19
|
3 |
|
function __construct($kernel, DB_Sql $db) |
|
20
|
|
|
{ |
|
21
|
3 |
|
$this->kernel = $kernel; |
|
22
|
3 |
|
$this->db = $db; |
|
23
|
3 |
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Returns the possible page types |
|
27
|
|
|
* |
|
28
|
|
|
* @return array possible page types |
|
29
|
|
|
*/ |
|
30
|
3 |
|
public function getTypes() |
|
31
|
|
|
{ |
|
32
|
|
|
return array( |
|
33
|
3 |
|
1 => 'page', |
|
34
|
3 |
|
2 => 'article', |
|
35
|
3 |
|
3 => 'news'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
3 |
View Code Duplication |
function getDBQuery() |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
3 |
|
if ($this->dbquery) { |
|
41
|
3 |
|
return $this->dbquery; |
|
42
|
|
|
} |
|
43
|
|
|
return ($this->dbquery = new Intraface_DBQuery($this->kernel, 'cms_page', 'cms_page.intranet_id = '.$this->kernel->intranet->get('id').' AND cms_page.active = 1 AND site_id = ' . $this->cmssite->get('id'))); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
3 |
|
function setDBQuery($dbquery) |
|
47
|
|
|
{ |
|
48
|
3 |
|
$this->dbquery = $dbquery; |
|
49
|
3 |
|
} |
|
50
|
|
|
|
|
51
|
3 |
View Code Duplication |
function findById($id) |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
$this->db->query("SELECT id, site_id FROM cms_page WHERE id = " . (int)$id . " AND intranet_id = " . $this->kernel->intranet->get('id')); |
|
54
|
3 |
|
if (!$this->db->nextRecord()) { |
|
55
|
|
|
return false; |
|
56
|
|
|
} |
|
57
|
|
|
$site = new CMS_Site($this->kernel, $this->db->f('site_id')); |
|
58
|
|
|
$object = new CMS_Page($site, (int)$id); |
|
59
|
|
|
return $object; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
function findBySiteIdAndIdentifier($site_id, $identifier) |
|
63
|
|
|
{ |
|
64
|
|
|
$identifier = strip_tags($identifier); |
|
65
|
|
|
|
|
66
|
|
View Code Duplication |
if (!empty($identifier)) { |
|
67
|
|
|
$this->db->query("SELECT site_id, id FROM cms_page WHERE identifier = '" . $identifier . "' AND intranet_id = " . $this->kernel->intranet->get('id') . " AND active = 1 AND site_id = " . $site_id); |
|
68
|
|
|
} else { |
|
69
|
|
|
// @todo choose the default page - vi skal lige have noget med publish og expire date her ogs� |
|
70
|
|
|
$this->db->query("SELECT site_id, id FROM cms_page WHERE intranet_id = " . $this->kernel->intranet->get('id') . " AND active = 1 AND status_key = 1 AND site_id = " . $site_id . " ORDER BY position ASC LIMIT 1"); |
|
71
|
|
|
} |
|
72
|
|
|
if (!$this->db->nextRecord()) { |
|
73
|
|
|
$this->db->query("SELECT site_id, id FROM cms_page WHERE id = " . (int)$identifier . " AND intranet_id = " . $this->kernel->intranet->get('id') . " AND active = 1 AND site_id = " . $site_id); |
|
74
|
|
|
if (!$this->db->nextRecord()) { |
|
75
|
|
|
return false; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
return new CMS_Page(new CMS_Site($this->kernel, $this->db->f('site_id')), $this->db->f('id')); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* |
|
83
|
|
|
* @param $site |
|
84
|
|
|
* @param object $page CMS_Page used when finding submenu in XMLRPC/shop/Server0030.php method getPage |
|
85
|
|
|
* @todo remove $page parameter and find another way to generate submenu |
|
86
|
|
|
* @return unknown_type |
|
87
|
|
|
*/ |
|
88
|
3 |
|
function findAllBySite($site, $page = null) |
|
89
|
|
|
{ |
|
90
|
3 |
|
$this->cmssite = $site; |
|
91
|
3 |
|
$pages = array(); |
|
|
|
|
|
|
92
|
|
|
|
|
93
|
3 |
|
if ($this->getDBQuery()->checkFilter('type') && $this->getDBQuery()->getFilter('page') == 'all') { |
|
|
|
|
|
|
94
|
|
|
// no condition isset |
|
95
|
|
|
// $sql_type = ""; |
|
|
|
|
|
|
96
|
|
|
} else { |
|
97
|
|
|
// with int it will never be a fake searcy |
|
98
|
3 |
|
$type = $this->getDBQuery()->getFilter('type'); |
|
99
|
3 |
|
if ($type == '') { |
|
100
|
3 |
|
$type = 'page'; // Standard |
|
101
|
3 |
|
} |
|
102
|
|
|
|
|
103
|
3 |
|
if ($type != 'all') { |
|
104
|
3 |
|
$type_key = array_search($type, $this->getTypes()); |
|
105
|
3 |
|
if ($type_key === false) { |
|
106
|
|
|
throw new Exception("Invalid type '".$type."' set with CMS_PAGE::dbquery::setFilter('type') in CMS_Page::getList"); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
3 |
|
$this->getDBQuery()->setCondition("type_key = ".$type_key); |
|
110
|
3 |
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
|
|
114
|
|
|
// hvis en henter siderne uden for systemet |
|
115
|
3 |
|
$sql_expire = ''; |
|
|
|
|
|
|
116
|
3 |
|
$sql_publish = ''; |
|
|
|
|
|
|
117
|
|
|
// @todo This need to be corrected |
|
118
|
3 |
|
if (!is_object($this->kernel->user)) { |
|
119
|
|
|
$this->getDBQuery()->setCondition("(date_expire > NOW() OR date_expire = '0000-00-00 00:00:00') AND (date_publish < NOW() AND status_key > 0 AND hidden = 0)"); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
3 |
|
switch ($this->getDBQuery()->getFilter('type')) { |
|
123
|
3 |
|
case 'page': |
|
124
|
|
|
$this->getDBQuery()->setSorting("position ASC"); |
|
125
|
|
|
break; |
|
126
|
3 |
|
case 'news': |
|
127
|
|
|
$this->getDBQuery()->setSorting("date_publish DESC"); |
|
128
|
|
|
break; |
|
129
|
3 |
|
case 'article': |
|
130
|
1 |
|
$this->getDBQuery()->setSorting("position, date_publish DESC"); |
|
131
|
1 |
|
break; |
|
132
|
3 |
|
default: |
|
133
|
3 |
|
$this->getDBQuery()->setSorting("date_publish DESC"); |
|
134
|
3 |
|
break; |
|
135
|
3 |
|
} |
|
136
|
|
|
|
|
137
|
|
|
// rekursiv funktion til at vise siderne |
|
138
|
3 |
|
$pages = array(); |
|
139
|
3 |
|
$go = true; |
|
|
|
|
|
|
140
|
3 |
|
$n = 0; // level |
|
141
|
|
|
// $o = 0; // |
|
|
|
|
|
|
142
|
3 |
|
$i = 0; // page counter |
|
143
|
|
|
// $level = 1; |
|
|
|
|
|
|
144
|
3 |
|
$cmspage = array(); |
|
145
|
3 |
|
$cmspage[0] = new DB_Sql; |
|
146
|
|
|
|
|
147
|
|
|
// Benyttes til undersider. |
|
148
|
3 |
|
$dbquery_original = clone $this->getDBQuery(); |
|
149
|
3 |
|
$dbquery_original->storeResult('', '', 'toplevel'); // sikre at der ikke bliver gemt ved undermenuer. |
|
150
|
|
|
|
|
151
|
|
|
|
|
152
|
3 |
|
$keywords = $this->getDBQuery()->getKeyword(); |
|
153
|
3 |
|
if (isset($keywords) && is_array($keywords) && count($keywords) > 0 && $type == 'page') { |
|
|
|
|
|
|
154
|
|
|
// If we are looking for pages, and there is keywords, we probaly want from more than one level |
|
155
|
|
|
// So we add nothing about level to condition. |
|
156
|
3 |
|
} elseif ($this->getDBQuery()->checkFilter('level') && $type == 'page') { // $level == 'sublevel' && |
|
|
|
|
|
|
157
|
|
|
|
|
158
|
|
|
// Til at finde hele menuen p� valgt level. |
|
159
|
|
|
$page_tree = $page->get('page_tree'); |
|
160
|
|
|
$level = (int)$this->getDBQuery()->getFilter('level'); |
|
161
|
|
|
if (isset($page_tree[$level - 1]) && is_array($page_tree[$level - 1])) { |
|
162
|
|
|
$child_of_id = $page_tree[$level - 1]['id']; |
|
163
|
|
|
} else { |
|
164
|
|
|
$child_of_id = 0; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
$this->getDBQuery()->setCondition('child_of_id = '.$child_of_id); |
|
168
|
|
|
// $cmspage[0]->query("SELECT *, DATE_FORMAT(date_publish, '%d-%m-%Y') AS date_publish_dk FROM cms_page WHERE active=1 AND child_of_id = ".$this->id. $sql_expire . $sql_publish . " ORDER BY id"); |
|
|
|
|
|
|
169
|
|
|
} else { |
|
170
|
3 |
|
$this->getDBQuery()->setCondition('child_of_id = 0'); |
|
171
|
|
|
// $cmspage[0]->query("SELECT *, DATE_FORMAT(date_publish, '%d-%m-%Y') AS date_publish_dk FROM cms_page WHERE ".$sql_type." site_id = " . $this->cmssite->get('id') . " AND child_of_id = 0 AND active = 1 " . $sql_expire . $sql_publish . $sql_order); |
|
|
|
|
|
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
3 |
|
$cmspage[0] = $this->getDBQuery()->getRecordset("cms_page.id, title, identifier, status_key, navigation_name, date_publish, child_of_id, pic_id, description, DATE_FORMAT(date_publish, '%d-%m-%Y') AS date_publish_dk", '', false); // |
|
175
|
|
|
|
|
176
|
3 |
|
while (true) { |
|
177
|
3 |
|
while ($cmspage[$n]->nextRecord()) { |
|
178
|
1 |
|
$pages[$i]['id'] = $cmspage[$n]->f('id'); |
|
179
|
|
|
|
|
180
|
1 |
|
$pages[$i]['title'] = $cmspage[$n]->f('title'); |
|
181
|
1 |
|
$pages[$i]['identifier'] = $cmspage[$n]->f('identifier'); |
|
182
|
1 |
|
$pages[$i]['navigation_name'] = $cmspage[$n]->f('navigation_name'); |
|
183
|
1 |
|
$pages[$i]['date_publish_dk'] = $cmspage[$n]->f('date_publish_dk'); |
|
184
|
1 |
|
$pages[$i]['date_publish'] = $cmspage[$n]->f('date_publish'); |
|
185
|
1 |
|
$pages[$i]['child_of_id'] = $cmspage[$n]->f('child_of_id'); |
|
186
|
1 |
|
$pages[$i]['level'] = $n; |
|
187
|
|
|
|
|
188
|
1 |
|
if (empty($pages[$i]['identifier'])) { |
|
189
|
|
|
$pages[$i]['identifier'] = $pages[$i]['id']; |
|
190
|
|
|
} |
|
191
|
1 |
|
if (empty($pages[$i]['navigation_name'])) { |
|
192
|
|
|
$pages[$i]['navigation_name'] = $pages[$i]['title']; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
1 |
|
$pages[$i]['status'] = $this->status_types[$cmspage[$n]->f('status_key')]; |
|
196
|
|
|
|
|
197
|
|
|
// @todo hvad er det her til |
|
198
|
1 |
|
$pages[$i]['new_status'] = 'published'; |
|
199
|
1 |
|
if ($pages[$i]['status'] == 'published') { |
|
200
|
|
|
$pages[$i]['new_status'] = 'draft'; |
|
201
|
|
|
} |
|
202
|
|
|
// hertil slut |
|
203
|
|
|
|
|
204
|
|
|
// denne b�r laves om til picture - og s� f�r man alle nyttige oplysninger ud |
|
205
|
1 |
|
$pages[$i]['pic_id'] = $cmspage[$n]->f('pic_id'); |
|
206
|
1 |
|
$pages[$i]['picture'] = $this->getPicture($cmspage[$n]->f('pic_id')); |
|
207
|
|
|
|
|
208
|
|
|
//$pages[$i]['picture'] = $cmspage[$n]->f('pic_id'); |
|
|
|
|
|
|
209
|
1 |
|
$pages[$i]['description'] = $cmspage[$n]->f('description'); |
|
210
|
|
|
|
|
211
|
|
|
// til google sitemaps |
|
212
|
|
|
// sp�rgsm�let er om vi ikke skal starte et objekt op for hver pages |
|
213
|
|
|
|
|
214
|
1 |
|
$pages[$i]['url'] = $this->cmssite->get('url') . $pages[$i]['identifier'] . '/'; |
|
215
|
1 |
|
$pages[$i]['url_self'] = $pages[$i]['identifier'] . '/'; |
|
216
|
1 |
|
$pages[$i]['changefreq'] = 'weekly'; |
|
217
|
1 |
|
$pages[$i]['priority'] = 0.5; |
|
218
|
|
|
|
|
219
|
1 |
|
$i++; |
|
220
|
|
|
// $o = $n + 1; |
|
|
|
|
|
|
221
|
|
|
|
|
222
|
1 |
|
if ($this->getDBQuery()->getFilter('type') == 'page' and $this->getDBQuery()->getFilter('level') == 'alllevels') { |
|
|
|
|
|
|
223
|
|
|
$dbquery[$n + 1] = clone $dbquery_original; |
|
|
|
|
|
|
224
|
|
|
$dbquery[$n + 1]->setCondition("child_of_id = ".$cmspage[$n]->f("id")); |
|
|
|
|
|
|
225
|
|
|
$cmspage[$n + 1] = $dbquery[$n + 1]->getRecordset("id, title, identifier, navigation_name, date_publish, child_of_id, pic_id, status_key, description, DATE_FORMAT(date_publish, '%d-%m-%Y') AS date_publish_dk", '', false); |
|
226
|
|
|
|
|
227
|
|
|
// if (!array_key_exists($n + 1, $cmspage) OR !is_object($cmspage[$n + 1])) { |
|
|
|
|
|
|
228
|
|
|
// $cmspage[$n + 1] = new DB_Sql; |
|
|
|
|
|
|
229
|
|
|
//} |
|
230
|
|
|
// $cmspage[$n + 1]->query("SELECT *, DATE_FORMAT(date_publish, '%d-%m-%Y') AS date_publish_dk FROM cms_page WHERE active=1 AND child_of_id = ".$cmspage[$n]->f("id"). $sql_expire . $sql_publish . " ORDER BY id"); |
|
|
|
|
|
|
231
|
|
|
|
|
232
|
|
|
if ($cmspage[$n + 1]->numRows() != 0) { |
|
233
|
|
|
$n++; |
|
234
|
|
|
continue; |
|
235
|
|
|
} |
|
236
|
|
|
} |
|
237
|
1 |
|
} |
|
238
|
|
|
|
|
239
|
3 |
|
if ($n == 0) { |
|
240
|
3 |
|
break; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
$n--; |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
3 |
|
return $pages; |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
1 |
View Code Duplication |
function getPicture($pic_id) |
|
|
|
|
|
|
250
|
|
|
{ |
|
251
|
1 |
|
$shared_filehandler = $this->kernel->useModule('filemanager'); |
|
252
|
1 |
|
$shared_filehandler->includeFile('AppendFile.php'); |
|
253
|
|
|
|
|
254
|
1 |
|
$tmp_filehandler = new FileHandler($this->kernel, $pic_id); |
|
255
|
1 |
|
$this->value['picture']['id'] = $pic_id; |
|
|
|
|
|
|
256
|
1 |
|
$this->value['picture']['original']['icon_uri'] = $tmp_filehandler->get('icon_uri'); |
|
|
|
|
|
|
257
|
1 |
|
$this->value['picture']['original']['name'] = $tmp_filehandler->get('file_name'); |
|
|
|
|
|
|
258
|
1 |
|
$this->value['picture']['original']['width'] = $tmp_filehandler->get('width'); |
|
|
|
|
|
|
259
|
1 |
|
$this->value['picture']['original']['height'] = $tmp_filehandler->get('height'); |
|
|
|
|
|
|
260
|
1 |
|
$this->value['picture']['original']['file_uri'] = $tmp_filehandler->get('file_uri'); |
|
|
|
|
|
|
261
|
|
|
|
|
262
|
1 |
|
if ($tmp_filehandler->get('is_image')) { |
|
263
|
|
|
$tmp_filehandler->createInstance(); |
|
264
|
|
|
$instances = $tmp_filehandler->instance->getList('include_hidden'); |
|
265
|
|
|
foreach ($instances as $instance) { |
|
266
|
|
|
$this->value['picture'][$instance['name']]['file_uri'] = $instance['file_uri']; |
|
|
|
|
|
|
267
|
|
|
$this->value['picture'][$instance['name']]['name'] = $instance['name']; |
|
|
|
|
|
|
268
|
|
|
$this->value['picture'][$instance['name']]['width'] = $instance['width']; |
|
|
|
|
|
|
269
|
|
|
$this->value['picture'][$instance['name']]['height'] = $instance['height']; |
|
|
|
|
|
|
270
|
|
|
} |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
1 |
|
return $this->value['picture']; |
|
|
|
|
|
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
/** |
|
277
|
|
|
* Returns the possible page types but with a binary index |
|
278
|
|
|
* |
|
279
|
|
|
* @return array possible page types with binary index |
|
280
|
|
|
*/ |
|
281
|
|
|
public static function getTypesWithBinaryIndex() |
|
282
|
|
|
{ |
|
283
|
|
|
return array( |
|
284
|
|
|
1 => 'page', |
|
285
|
|
|
2 => 'article', |
|
286
|
|
|
4 => 'news'); |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
function get($key) |
|
290
|
|
|
{ |
|
291
|
|
|
return $this->values[$key]; |
|
292
|
|
|
} |
|
293
|
|
|
} |
|
294
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.