-
Notifications
You must be signed in to change notification settings - Fork 0
/
Content.php
executable file
·398 lines (341 loc) · 12.9 KB
/
Content.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
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
<?php
/**
* Content Module
* @author Christopher Troup <chris@norex.ca>
* @package Modules
* @version 2.0
*/
/**
* Content management for the CMS.
*
* Add, edit and delete user editable content pages.
* @package Modules
* @subpackage Content
*/
class Module_Content extends Module {
public $version = '$Id: Content.php 6649 2008-07-31 16:48:27Z chris $';
/**
* Return a string containing the admin interface for the Content Module
*
* @return string
*/
public function getAdminInterface() {
include ('include/CMSPage.php');
$this->smarty->assign('hasRestriction',$this->hasRestriction());
switch ( @$_REQUEST ['section']) {
case 'viewLayers' :
switch ( @$_REQUEST ['action']) {
case 'deleteRev' :
$this->deleteRev ( $_REQUEST ['id'] );
$this->topLevelInterface ();
break;
default :
$this->viewLayers ( $_REQUEST ['id'] );
break;
}
break;
case 'deletePage' :
$page = new CMSPage($_REQUEST ['id']);
$page->delete();
$this->topLevelInterface ();
break;
case 'wizard' :
if (@isset ( $_REQUEST ['wizardStep'] )) {
$this->startWizard ( @$_REQUEST ['wizardStep'] + 1);
} else {
$this->startWizard ();
}
break;
case 'templates':
$this->addJS('/modules/Content/js/admin.js');
require_once ('include/ContentTemplate.php');
$templates = ContentTemplate::getAllContentTemplates();
$this->smarty->assign('templates', $templates);
return $this->smarty->fetch('admin/content_templates.tpl');
break;
case 'addEdit' :
switch ( @$_REQUEST ['action']) {
case 'createRev' :
$this->createRev ( $_REQUEST ['id'] );
break;
case 'updatePage' :
$this->updateRev ();
$this->topLevelInterface ();
break;
case 'editMeta':
$this->getMetaEditor(@$_REQUEST['id']);
$this->template = 'admin/content_addedit.tpl';
if (isset($_REQUEST['submit'])) {
$this->topLevelInterface ();
}
break;
}
break;
case 'toggle':
$page = new CMSPage($_REQUEST['id']);
if ($page->getAccess() == 'public') {
$page->setAccess('restricted');
$page->save();
} else {
$page->setAccess('public');
$page->save();
}
$this->topLevelInterface();
break;
default :
switch ( @$_REQUEST ['action']) {
default :
$this->topLevelInterface ();
break;
}
}
return $this->smarty->fetch ( $this->template );
}
public function getUserInterface($params = null) {
include ('include/CMSPage.php');
$this->smarty->assign('hasRestriction',$this->hasRestriction());
$page = new CMSPage($_REQUEST ['page']);
$rev = $page->getActiveRevisions($_SESSION ['lang']);
if($page->getAccess() != 'public' && $this->hasRestriction()){
$auth_container = new User();
$auth = new Auth($auth_container, null, 'authInlineHTML');
$auth->start();
if (!$auth->checkAuth()) {
return authInlineHTML();
} else if($page->getAccess() != 'public' && $_SESSION['authenticated_user']->hasPerm('membersaccess')){
$this->smarty->assign ('content_perms', true);
} else {
$this->smarty->assign ('content_perms', false);
}
} else {
$this->smarty->assign('content_perms', true);
}
$metaData = $rev->getMetaData();
$this->smarty->assign ( 'content', $rev );
$this->setMetaDescription($metaData['description']);
$this->setMetaTitle($metaData['title']);
$this->setMetaKeywords($metaData['keywords']);
$this->setPageTitle($rev->getPageTitle());
return $this->smarty->fetch ( 'db:content.tpl' );
}
protected function topLevelInterface() {
if ($this->user->hasPerm ( 'viewcontentadmin' )) {
$pages = CMSPage::getContentPages();
$this->smarty->assign ( 'pages', $pages );
$this->template = 'admin/content.tpl';
}
}
protected function viewLayers($id) {
$this->smarty->assign ( 'parent_id', $_REQUEST ['id'] );
$this->template = 'admin/content_layers.tpl';
}
public function toggleStatus($id) {
$status = $this->db->query_fetch ( 'select status, parent_id, locale_id from content_page_data where id=' . $id );
$sql = 'update content_page_data set status=0 where parent_id=' . $status ['parent_id'] . ' and locale_id=' . $status ['locale_id'];
$this->db->query ( $sql );
if ($status ['status'] == 1) {
$status = 0;
} else {
$status = 1;
}
$sql = 'update content_page_data set status=' . $status . ' where id=' . $id;
$this->db->query ( $sql );
$this->template = 'admin/content.tpl';
}
protected function createRev($id) {
if ($this->user->hasPerm ( 'editcontent' )) {
$rev = new CMSPageRevision($id);
$newRev = $rev->createRevision();
/*
$sql = 'insert into content_page_data (parent_id, content, status, page_title, locale_id) (select parent_id, content, status, page_title, locale_id from content_page_data where id=' . $id . ')';
$this->db->query ( $sql );
$newRevID = $this->db->lastInsertedID ();
$sql = 'update content_page_data set status=0 where id=' . $newRevID;
$this->db->query ( $sql );
$sql = 'select content_page_data.*, l.id as lid, l.display_name from content_page_data, `locale` l WHERE content_page_data.id=' . $newRevID . ' AND l.id=content_page_data.locale_id';
$newRev = $this->db->query_fetch ( $sql );
*/
$form = $newRev->getAddEditForm ( );
//$renderer = new HTML_QuickForm_Renderer_ArraySmarty ( $this->smarty );
//$form->accept ( $renderer );
$this->smarty->assign ( 'form', $form );
$this->smarty->assign ( 'page', $newRev );
$this->template = 'admin/content_addedit.tpl';
}
}
protected function updateRev() {
$rev = new CMSPageRevision($_REQUEST ['id']);
$form = $rev->getAddEditForm();
if (isset ( $_REQUEST ['submit'] )) {
$this->setActiveRev ( $_REQUEST ['id'] );
}
}
public function setActiveRev($id) {
$sql = 'select * from content_page_data where id=' . $id;
$result = $this->db->query_fetch ( $sql );
$sql = 'update content_page_data set status=0 where parent_id=' . $result ['parent_id'] . ' and locale_id=' . $result ['locale_id'];
$this->db->query ( $sql );
$sql = 'update content_page_data set status=1 where id=' . $id;
$this->db->query ( $sql );
}
protected function startWizard($step = 1) {
$this->template = 'admin/create_page_wizard.tpl';
$this->smarty->assign('step', $step);
switch ($step) {
case 1:
$page = new CMSPage();
$form = $page->getForm();
$form->addRule('urlkey', 'Key already used', new validCKey(), null);
$form->removeElement ( 'section' );
$form->removeElement ( 'action' );
$form->_constantValues = array ( );
$form->addElement ( 'hidden', 'section' );
$defaultValues ['section'] = 'wizard';
$form->addElement ( 'hidden', 'wizardStep' );
$defaultValues ['wizardStep'] = $step;
$form->setDefaults ( $defaultValues );
$this->smarty->assign('form', $form);
break;
case 2:
$page = new CMSPage();
$page->setStatus(true);
$page->setAccess('public');
$form = $page->getForm();
$_SESSION['wizard_page_id'] = $page->getId();
$this->addJS('/modules/Content/js/admin.js');
require_once ('include/ContentTemplate.php');
$templates = ContentTemplate::getAllContentTemplates();
$this->smarty->assign('templates', $templates);
$this->template = 'admin/content_templates.tpl';
//return $this->smarty->fetch('admin/content_templates.tpl');
break;
case 3:
require_once ('include/ContentTemplate.php');
$layer = new CMSPageRevision();
$template = new ContentTemplate($_REQUEST['template_id']);
$layer->setContent($template->getContent());
$layer->setParentId($_SESSION['wizard_page_id']);
$form = $layer->getAddEditForm();
$form->removeElement ( 'section' );
$form->removeElement ( 'action' );
$form->_constantValues = array ( );
$form->addElement ( 'hidden', 'section' );
$defaultValues ['section'] = 'wizard';
$form->addElement ( 'hidden', 'parent_id' );
$defaultValues ['parent_id'] = $_SESSION['wizard_page_id'];
$form->addElement ( 'hidden', 'wizardStep' );
$defaultValues ['wizardStep'] = $step;
$form->setConstants ( array ('wizardStep' => $step ) );
$defaultValues ['language'] = 1;
$form->setDefaults ( $defaultValues );
$this->smarty->assign('form', $form);
break;
case 4:
$layer = new CMSPageRevision();
$layer->setParentId($_REQUEST['parent_id']);
$form = $layer->getAddEditForm();
$this->topLevelInterface();
}
}
public function contentForm($newRev = null) {
$form = new Form ( 'page_addedit', 'POST', '/admin/Content', '', array ('class' => 'admin' ) );
$form->addElement ( 'text', 'title', 'Page Title', array ('value' => $newRev->getPageTitle() ) );
$sql = 'select * from locale order by display_name';
$rows = $this->db->query_fetch_all ( $sql );
$languages = array ( );
foreach ( $rows as $language ) {
$languages [$language ['id']] = $language ['display_name'];
}
$form->addElement ( 'select', 'language', 'Language', $languages );
$form->addElement ( 'text', 'access', 'Page Access' );
$defaultValues ['language'] = array ($newRev->getLocaleId() );
$defaultValues ['access'] = $newRev->getAccess();
$form->setDefaults ( $defaultValues );
$form->setConstants ( array ('action' => 'updatePage', 'id' => $newRev->getId(), 'section' => 'addEdit' ) );
$form->addElement ( 'hidden', 'id' );
$form->addElement ( 'hidden', 'section' );
$form->addElement ( 'hidden', 'action' );
$oQFElement = HTML_Quickform::createElement ( 'tinymce', 'editor', 'Content' );
//$oQFElement->setFCKProps ( '/core/fckeditor/', 'Default', '100%', '500', array ('SkinPath' => 'editor/skins/office2003/', 'DefaultLanguage' => 'en', 'StylesXmlPath' => '/core/fckeditor/fckstyles.xml', 'UseBROnCarriageReturn' => 'true', 'StartupFocus' => 'false',
// 'CustomConfigurationsPath' => 'config.js', 'EditorAreaCSS' => 'fck_editorarea.css' ) );
$oQFElement->setValue ( $newRev->getContent() );
$form->addElement ( $oQFElement );
$form->addElement ( 'submit', 'submit', 'Save and auto-publish', array ('id' => 'submit' ) );
$form->addElement ( 'submit', 'submit_leavestatus', 'Save (but don\'t publish)' );
$form->applyFilter ( 'urlkey', 'title' );
$form->addRule ( 'title', 'Please enter a Page Title', 'required', null, 'client' );
$form->addRule ( 'editor', 'Please enter some Page Content', 'required', null, 'client' );
return $form;
}
public function deleteRev($id) {
$sql = 'delete from content_page_data where id=' . $id;
$this->db->query ( $sql );
}
public static function hasRestriction(){
$opts = Config::getModuleOptions('Content');
if(@$opts['restrictedpages']){
return true;
} else {
return false;
}
}
public static function linkHandler($id) {
$sql = 'select page_name from content_pages where id=' . $id;
$page = Database::singleton ()->query_fetch ( $sql );
return '/Content/' . $page ['page_name'];
}
public static function linkType() {
return 'Content Page';
}
public static function getValidLinks() {
$sql = 'select id as `key`, page_name as value from content_pages where status=1';
$pages = Database::singleton ()->query_fetch_all ( $sql );
return $pages;
}
public function &getSoapInterface(&$server, $ns) {
$server->register('Module_Content.linkType', // method name
array(), // input parameters
array('return' => 'xsd:string'), // output parameters
$ns);
return $server;
}
public function getMetaEditor($id){
$pageR = new CMSPageRevision($id);
$page = new CMSPage($pageR->getParentId());
$form = $page->getForm();
$form->removeElement ( 'section' );
$form->removeElement ( 'action' );
$form->removeElement ( 'id' );
$form->_constantValues = array ( );
$form->addElement ( 'hidden', 'section' );
$defaultValues ['section'] = 'addEdit';
$form->addElement ( 'hidden', 'action' );
$defaultValues ['action'] = 'editMeta';
$form->addElement ( 'hidden', 'id' );
$defaultValues ['id'] = $pageR->getId();
$metadata = $pageR->getMetaData();
$defaultValues['metatitle'] = $metadata['title'];
$defaultValues['metadesc'] = $metadata['description'];
$defaultValues['metakeywords'] = $metadata['keywords'];
$defaultValues['urlkey'] = $page->getPageName();
$form->setDefaults($defaultValues);
$this->smarty->assign('form', $form);
if ($form->validate() && (isset($_REQUEST['submit']))){
$metadata = array('title'=>$form->exportValue('metatitle'),'description'=>$form->exportValue('metadesc'),'keywords'=>$form->exportValue('metakeywords'));
$pageR->setMetaData($metadata);
$pageR->save();
$this->topLevelInterface();
}
}
}
require_once 'HTML/QuickForm/Rule.php';
class validCKey extends HTML_QuickForm_Rule {
function validate($value) {
$sql = 'select `page_name` from content_pages where `page_name` = "'.e($value).'"';
$result = DataBase::singleton()->query_fetch($sql);
if($result) {
return false;
}
return true;
}
}