-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathIndexController.php
More file actions
201 lines (181 loc) · 6.62 KB
/
IndexController.php
File metadata and controls
201 lines (181 loc) · 6.62 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
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
<?php
/**
* Simple Pages
*
* @copyright Copyright 2008-2012 Roy Rosenzweig Center for History and New Media
* @license http://www.gnu.org/licenses/gpl-3.0.txt GNU GPLv3
*/
/**
* The Simple Pages index controller class.
*
* @package SimplePages
*/
class SimplePages_IndexController extends Omeka_Controller_AbstractActionController
{
public function init()
{
// Set the model class so this controller can perform some functions,
// such as $this->findById()
$this->_helper->db->setDefaultModelName('SimplePagesPage');
}
public function indexAction()
{
// Always go to browse.
$this->_helper->redirector('browse');
return;
}
public function addAction()
{
// Create a new page.
$page = new SimplePagesPage;
// Set the created by user ID.
$page->created_by_user_id = current_user()->id;
$page->template = '';
$page->order = 0;
$form = $this->_getForm($page);
$this->view->form = $form;
$this->_processPageForm($page, $form, 'add');
}
public function editAction()
{
// Get the requested page.
$page = $this->_helper->db->findById();
$form = $this->_getForm($page);
$this->view->form = $form;
$this->_processPageForm($page, $form, 'edit');
}
protected function _getForm($page = null)
{
$formOptions = array('type' => 'simple_pages_page', 'hasPublicPage' => true);
if ($page && $page->exists()) {
$formOptions['record'] = $page;
}
$form = new Omeka_Form_Admin($formOptions);
$form->addElementToEditGroup(
'text', 'title',
array(
'id' => 'simple-pages-title',
'value' => $page->title,
'label' => __('Title'),
'description' => __('Name and heading for the page (required)'),
'required' => true
)
);
$form->addElementToEditGroup(
'text', 'slug',
array(
'id' => 'simple-pages-slug',
'value' => $page->slug,
'label' => __('Slug'),
'description' => __(
'The slug is the part of the URL for this page. A slug '
. 'will be created automatically from the title if one is '
. 'not entered. Letters, numbers, underscores, dashes, and '
. 'forward slashes are allowed.'
)
)
);
$form->addElementToEditGroup(
'checkbox', 'use_tiny_mce',
array(
'id' => 'simple-pages-use-tiny-mce',
'checked' => $page->use_tiny_mce,
'values' => array(1, 0),
'label' => __('Use HTML editor?'),
'description' => __(
'Check this to add an HTML editor bar for easily creating HTML.'
)
)
);
$form->addElementToEditGroup(
'textarea', 'text',
array('id' => 'simple-pages-text',
'cols' => 50,
'rows' => 25,
'value' => $page->text,
'label' => __('Text'),
'description' => __(
'Add content for page. This field supports shortcodes. For a list of available shortcodes, refer to the <a target=_blank href="http://omeka.org/codex/Shortcodes">Omeka Codex</a>.'
)
)
);
$form->addElementToSaveGroup(
'select', 'parent_id',
array(
'id' => 'simple-pages-parent-id',
'multiOptions' => simple_pages_get_parent_options($page),
'value' => $page->parent_id,
'label' => __('Parent'),
'description' => __('The parent page')
)
);
$form->addElementToSaveGroup(
'text', 'order',
array(
'value' => $page->order,
'label' => __('Order'),
'description' => __(
'The order of the page relative to the other pages with '
. 'the same parent'
)
)
);
$form->addElementToSaveGroup(
'checkbox', 'is_published',
array(
'id' => 'simple_pages_is_published',
'values' => array(1, 0),
'checked' => $page->is_published,
'label' => __('Publish this page?'),
'description' => __('Checking this box will make the page public')
)
);
if (class_exists('Omeka_Form_Element_SessionCsrfToken')) {
$form->addElement('sessionCsrfToken', 'csrf_token');
}
$form->addElementToSaveGroup(
'checkbox', 'is_searchable',
array(
'id' => 'simple_pages_is_searchable',
'values' => array(1, 0),
'checked' => $page->is_searchable,
'label' => __('Is this page searchable?'),
'description' => __('Checking this box will make this page searchable')
)
);
return $form;
}
/**
* Process the page edit and edit forms.
*/
private function _processPageForm($page, $form, $action)
{
// Set the page object to the view.
$this->view->simple_pages_page = $page;
if ($this->getRequest()->isPost()) {
if (!$form->isValid($_POST)) {
$this->_helper->_flashMessenger(__('There was an error on the form. Please try again.'), 'error');
return;
}
try {
$page->setPostData($_POST);
if ($page->save()) {
if ('add' == $action) {
$this->_helper->flashMessenger(__('The page "%s" has been added.', $page->title), 'success');
} else if ('edit' == $action) {
$this->_helper->flashMessenger(__('The page "%s" has been edited.', $page->title), 'success');
}
$this->_helper->redirector('browse');
return;
}
// Catch validation errors.
} catch (Omeka_Validate_Exception $e) {
$this->_helper->flashMessenger($e);
}
}
}
protected function _getDeleteSuccessMessage($record)
{
return __('The page "%s" has been deleted.', $record->title);
}
}