-
Notifications
You must be signed in to change notification settings - Fork 36
/
contents_controller.php
135 lines (118 loc) · 3.47 KB
/
contents_controller.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
<?php
/**
* Comment Template.
*
* @todo Implement .this needs to be sorted out.
*
* Copyright (c) 2009 Carl Sutton ( dogmatic69 )
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
* @filesource
* @copyright Copyright (c) 2009 Carl Sutton ( dogmatic69 )
* @link http://www.dogmatic.co.za
* @package sort
* @subpackage sort.comments
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @since 0.5a
*/
class ContentsController extends CmsAppController {
var $name = 'Contents';
/**
* Helpers.
*
* @access public
* @var array
*/
var $helpers = array('Filter.Filter');
function beforeFilter(){
parent::beforeFilter();
}
function index() {
$this->Content->recursive = 0;
$this->set('contents', $this->paginate());
}
function view() {
if (!isset($this->params['slug'])) {
$this->Session->setFlash( __('Invalid content selected', true) );
$this->redirect($this->referer());
}
$content = $this->Content->find(
'first',
array(
'conditions' => array(
'or' => array(
'Content.slug' => $this->params['slug']
),
'Content.active' => 1
)
)
);
$this->set(compact('content'));
}
function admin_index() {
$this->paginate = array(
'order' => array(
'Category.title' => 'ASC',
'Content.ordering' => 'ASC'
)
);
$this->Content->recursive = 1;
$contents = $this->paginate(null, $this->Filter->filter);
$filterOptions = $this->Filter->filterOptions;
$filterOptions['fields'] = array(
'title',
'introduction',
'body'
);
$this->set(compact('contents','filterOptions'));
}
function admin_view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid content', true));
$this->redirect(array('action' => 'index'));
}
$this->set('content', $this->Content->read(null, $id));
}
function admin_add() {
if (!empty($this->data)) {
$this->Content->create();
if ($this->Content->saveAll($this->data)) {
$this->Session->setFlash(__('The content has been saved', true));
$this->redirect(array('action' => 'index'));
}else {
$this->Session->setFlash(__('The content could not be saved. Please, try again.', true));
}
}
$categories = array(__('Please select', true)) + $this->Content->Category->generatetreelist();
$groups = array(__('Public', true)) + $this->Content->Group->generatetreelist();
$layouts = $this->Content->Layout->find('list');
$this->set(compact('categories','groups','layouts'));
}
function admin_edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid content', true));
$this->redirect(array('action' => 'index'));
}
if (!empty($this->data)) {
if ($this->Content->saveAll($this->data)) {
$this->Session->setFlash(__('The content has been saved', true));
$this->redirect(array('action' => 'index'));
}else {
$this->Session->setFlash(__('The content could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Content->lock(null, $id);
if ($this->data === false) {
$this->Session->setFlash(__('The content item is currently locked', true));
$this->redirect($this->referer());
}
}
$categories = array(__('Please select', true)) + $this->Content->Category->generatetreelist();
$groups = array(__('Public', true)) + $this->Content->Group->generatetreelist();
$layouts = $this->Content->Layout->find('list');
$this->set(compact('categories','groups','layouts'));
}
}
?>