-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathSitesController.php
181 lines (159 loc) · 6.04 KB
/
SitesController.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
<?php
App::uses('SitesAppController', 'Sites.Controller');
class SitesController extends SitesAppController {
public $name = 'Sites';
public $uses = array('Sites.Site');
public $helpers = array(
'Sites.Sites',
);
public function admin_index() {
$this->set('sites', $this->paginate());
}
public function admin_view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid site'));
$this->redirect(array('action' => 'index'));
}
$this->set('site', $this->Site->read(null, $id));
}
public function admin_add() {
if (!empty($this->request->data)) {
$this->Site->create();
if ($this->Site->saveAll($this->request->data)) {
$this->Session->setFlash(__('The site has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The site could not be saved. Please, try again.'));
}
}
$this->set('title_for_layout', __('Create new Site'));
$this->render('admin_edit');
}
public function admin_edit($id = null) {
if (!$id && empty($this->request->data)) {
$this->Session->setFlash(__('Invalid site'));
$this->redirect(array('action' => 'index'));
}
if (!empty($this->request->data)) {
if ($this->Site->saveAll($this->request->data)) {
$this->Session->setFlash(__('The site has been saved'));
$this->Croogo->redirect(array('action' => 'edit', $this->Site->id));
} else {
$this->Session->setFlash(__('The site could not be saved. Please, try again.'));
}
}
if (empty($this->request->data)) {
$this->Site->contain(array('SiteDomain', 'SiteMeta'));
$this->request->data = $this->Site->read(null, $id);
}
$this->set('title_for_layout', __('Edit Site'));
}
public function admin_delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for site'));
$this->redirect(array('action'=>'index'));
}
if ($this->Site->delete($id)) {
$this->Session->setFlash(__('Site deleted'));
$this->redirect(array('action'=>'index'));
}
$this->Session->setFlash(__('Site was not deleted'));
$this->redirect(array('action' => 'index'));
}
public function admin_setdefault($id = null) {
if (!$id) {
$this->Session->setFlash(__('Setting default failed.'));
$this->redirect(array('action' => 'index'));
} else {
$this->request->data = $this->Site->find('all') ;
foreach ($this->request->data as $key => $site) {
if ($site['Site']['id'] == $id) {
$this->request->data[$key]['Site']['default'] = 1;
} else {
$this->request->data[$key]['Site']['default'] = 0;
}
}
$this->Site->saveAll($this->request->data);
$this->Session->setFlash(__('Site has been set as default.'));
$this->redirect(array('action' => 'index'));
}
}
public function admin_adddomain($id = null) {
if (!$id) {
$this->Session->setFlash(__('No Id has been specified!'));
$this->redirect(array('action' => 'index'));
} else {
$this->Site->SiteDomain->create();
$this->request->data['domain'] = '';
$this->request->data['site_id'] = $id;
unset($this->Site->SiteDomain->validate['domain']);
$this->Site->SiteDomain->save($this->request->data);
$this->Session->setFlash(__('A new domain has been successfully added. You may now enter the desired URL.'));
$this->redirect(array('action' => 'edit', $id, '?' => array(
'domain_id' => $this->Site->SiteDomain->id
)
));
}
}
public function admin_deletedomain($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for site domain'));
$this->redirect(array('controller' => 'sites', 'action' => 'index'));
}
if ($this->Site->SiteDomain->delete($id)) {
$this->Session->setFlash(__('Site domain deleted'));
$this->redirect(array('controller' => 'sites', 'action' => 'index'));
}
$this->Session->setFlash(__('Site domain was not deleted'));
$this->redirect(array('controller' => 'sites', 'action' => 'index'));
}
public function admin_publish_nodes($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for site'));
$this->redirect(array('controller' => 'sites', 'action' => 'index'));
}
if ($this->Site->publish_all($id, $this->Site->Node)) {
$this->Session->setFlash(__('All nodes has been published for this site %d', $id), 'default', array('class' => 'success'));
$this->redirect(array('controller' => 'sites', 'action' => 'index'));
}
$this->Session->setFlash(__('Unable to publish existing nodes'));
$this->redirect(array('controller' => 'sites', 'action' => 'index'));
}
public function admin_publish_blocks($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for site'));
$this->redirect(array('controller' => 'sites', 'action' => 'index'));
}
if ($this->Site->publish_all($id, $this->Site->Block)) {
$this->Session->setFlash(__('All blocks has been published for this site %d', $id), 'default', array('class' => 'success'));
$this->redirect(array('controller' => 'sites', 'action' => 'index'));
}
$this->Session->setFlash(__('Unable to publish existing blocks'));
$this->redirect(array('controller' => 'sites', 'action' => 'index'));
}
public function admin_publish_links($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for site'));
$this->redirect(array('controller' => 'sites', 'action' => 'index'));
}
if ($this->Site->publish_all($id, $this->Site->Link)) {
$this->Session->setFlash(__('All links has been published for this site %d', $id), 'default', array('class' => 'success'));
$this->redirect(array('controller' => 'sites', 'action' => 'index'));
}
$this->Session->setFlash(__('Unable to publish existing links'));
$this->redirect(array('controller' => 'sites', 'action' => 'index'));
}
public function _writeSetting($value) {
$this->Site->updateAll(array('status' => $value));
$this->loadModel('Settings.Setting');
$this->Setting->write('Site.status', $value);
}
public function admin_enable() {
$this->_writeSetting(1);
$this->redirect(array('action' => 'index', 'admin' => true));
}
public function admin_disable() {
$this->_writeSetting(0);
$this->redirect(array('action' => 'index', 'admin' => true));
}
}