forked from KodiCMS-Kohana/cms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layout.php
203 lines (164 loc) · 4.16 KB
/
layout.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
<?php defined( 'SYSPATH' ) or die( 'No direct access allowed.' );
/**
* @package KodiCMS
* @category Controller
* @author butschster <butschster@gmail.com>
* @link http://kodicms.ru
* @copyright (c) 2012-2014 butschster
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt
*/
class KodiCMS_Controller_Layout extends Controller_System_Backend {
public function before()
{
if ($this->request->action() == 'edit' AND ACL::check('layout.view'))
{
$this->allowed_actions[] = 'edit';
}
parent::before();
$this->breadcrumbs
->add(__('Layouts'), Route::get('backend')->uri(array('controller' => 'layout')));
}
public function action_index()
{
$this->set_title(__('Layouts'), FALSE);
$this->template->content = View::factory('layout/index', array(
'layouts' => Model_File_Layout::find_all()
));
}
public function action_add()
{
// check if trying to save
if (Request::current()->method() == Request::POST)
{
return $this->_add();
}
Assets::package('ace');
$this->set_title(__('Add layout'));
// check if user have already enter something
$layout = Flash::get('post_data');
if (empty($layout))
{
$layout = new Model_File_Layout;
}
$this->template->content = View::factory('layout/edit', array(
'action' => 'add',
'layout' => $layout
));
}
protected function _add()
{
$data = $this->request->post();
$layout = new Model_File_Layout($data['name']);
$layout->content = $data['content'];
Flash::set('post_data', $layout);
try
{
$status = $layout->save();
}
catch (Validation_Exception $e)
{
Messages::errors($e->errors('validation'));
$this->go_back();
}
Kohana::$log->add(Log::INFO, 'Layout :name has been added by :user!', array(
':name' => $layout->name
))->write();
Messages::success(__('Layout has been saved!'));
Observer::notify('layout_after_add', $layout);
Session::instance()->delete('post_data');
// save and quit or save and continue editing?
if ($this->request->post('commit') !== NULL)
{
$this->go();
}
else
{
$this->go(array('action' => 'edit', 'id' => $layout->name));
}
}
public function action_edit()
{
$layout_name = $this->request->param('id');
$layout = new Model_File_Layout($layout_name);
if (!$layout->is_exists())
{
if (($found_file = $layout->find_file()) !== FALSE)
{
$layout = new Model_File_Layout($found_file);
}
else
{
Messages::errors(__('Layout not found!'));
$this->go();
}
}
$this->set_title($layout_name);
// check if trying to save
if (Request::current()->method() == Request::POST AND ACL::check('layout.edit'))
{
return $this->_edit($layout);
}
Assets::package('ace');
$this->template->content = View::factory('layout/edit', array(
'action' => 'edit',
'layout' => $layout
));
}
protected function _edit($layout)
{
$data = $this->request->post();
$layout->name = $data['name'];
$layout->content = $data['content'];
try
{
$status = $layout->save();
}
catch (Validation_Exception $e)
{
Messages::errors($e->errors('validation'));
$this->go_back();
}
Kohana::$log->add(Log::INFO, 'Layout :name has been edited by :user', array(
':name' => $layout->name
))->write();
Messages::success(__('Layout has been saved!'));
Observer::notify('layout_after_edit', $layout);
// save and quit or save and continue editing?
if ($this->request->post('commit') !== NULL)
{
$this->go();
}
else
{
$this->go_back();
}
}
public function action_delete()
{
$this->auto_render = FALSE;
$layout_name = $this->request->param('id');
$layout = new Model_File_Layout($layout_name);
// find the user to delete
if (!$layout->is_used())
{
if ($layout->delete())
{
Kohana::$log->add(Log::INFO, 'Layout :name has been deleted by :user', array(
':name' => $layout_name
))->write();
Messages::success(__('Layout has been deleted!'));
Observer::notify('layout_after_delete', $layout_name);
}
else
{
Messages::errors(__('Something went wrong!'));
}
}
else
{
Messages::errors(__('Layout is used! It CAN NOT be deleted!'));
}
$this->go();
}
}
// end LayoutController class