php class UnnamedController extends BaseController public function ind

  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
<?php
class UnnamedController extends BaseController {
public function indexAction() {
$this->view->pidor = true;
}
public function authAction() {
$form = new Contrario\Forms\RifiksForm();
if ($this->request->isPost() and $this->security->checkToken()) {
if ($form->isValid($this->request->getPost()) and $this->request->getPost('password') == $this->config->application->password) {
$this->session->set('password', $this->request->getPost('password'));
$this->response->redirect('rifiks');
$this->view->disable();
}
else {
$this->response->redirect('rifiks');
$this->view->disable();
}
}
else {
$this->response->redirect('rifiks');
$this->view->disable();
}
}
public function autAction() {
$form = new Contrario\Forms\RifiksForm();
$this->view->form = $form;
}
public function exitAction() {
$this->session->remove('password');
$this->response->redirect();
$this->view->disable();
}
public function addAction() {
$form = new Contrario\Forms\AddForm();
$this->view->form = $form;
}
public function addPAction() {
$form = new Contrario\Forms\AddForm();
if ($this->request->isPost() and $this->security->checkToken()) {
if ($form->isValid($this->request->getPost())) {
foreach ($this->request->getUploadedFiles() as $file2) $file=$file2;
$file->getName = time().$file->getName();
if(in_array(strtolower($file->getExtension()), ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'ico']) and in_array($file->getRealType(), ['image/jpg', 'image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/ico'])) {
$blog = new Blogs();
$blog->name = $this->request->getPost('name', 'string');
$blog->text = $this->request->getPost('text', 'string');
$blog->time = (string) \Contrario\Carbon::now();
$blog->autor = 1;
$blog->preview = $file->getName;
$blog->category = $this->request->getPost('category', 'int');
if($blog->save()) {
foreach ($this->cached->queryKeys() as $key) $this->cached->delete($key);
$file->moveTo($_SERVER['DOCUMENT_ROOT'].'/public/images/previews/'.$file->getName);
$this->response->redirect();
$this->view->disable();
}
else foreach ($blog->getMessages() as $message) {
$this->flash->error($message);
$this->response->redirect('rifiks/add');
$this->view->disable();
}
}
else {
$this->flash->error("Расширение выгруженного файла не соотвествует условию. (['jpg', 'jpeg', 'png', 'gif', 'bmp', 'ico'])");
$this->response->redirect('rifiks/add');
$this->view->disable();
}
}
else {
foreach ($form->getMessages() as $message) {
$this->flash->error($message);
}
$this->response->redirect('rifiks/add');
$this->view->disable();
}
}
else {
$this->response->redirect();
$this->view->disable();
}
}
public function editBlogsAction(){
$this->view->setVars([
'blogs' => Blogs::find()
]);
}
public function editBlogAction(){
$form = new Contrario\Forms\EditBlogForm();
$blog = Blogs::findFirstById($this->dispatcher->getParam('blog'));
if(!$blog){
$this->response->redirect('rifiks/editBlogs/');
$this->view->disable();
}
$this->view->setVars([
'blog' => $blog
]);
$this->view->form = $form;
}
public function editBlogYAction(){
$form = new Contrario\Forms\EditBlogForm();
if ($this->request->isPost() and $this->security->checkToken()) {
if ($form->isValid($this->request->getPost())) {
$file = $this->request->getUploadedFiles()[0];
$file->getName = time().$file->getName();
$blog = Blogs::findFirstById($this->request->getPost('id', 'int'));
$blog->name = $this->request->getPost('name', 'string');
$blog->text = $this->request->getPost('text', 'string');
if($file){
if(in_array(strtolower($file->getExtension()), ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'ico']) and in_array($file->getRealType(), ['image/jpg', 'image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/ico'])){
unlink($_SERVER['DOCUMENT_ROOT'].'/public/images/previews/'.$blog->preview);
$blog->preview = $file->getName;
$file->moveTo($_SERVER['DOCUMENT_ROOT'].'/public/images/previews/'.$file->getName);
}
else {
$this->flash->error('Ошибка загрузки файла, файл имеет неверное расширение, ну или это шелл.');
$this->response->redirect('rifiks/editBlog/'.$this->request->getPost('id', 'int').'/');
$this->view->disable();
}
}
$blog->category = $this->request->getPost('category', 'int');
if($blog->save()) {
foreach ($this->cached->queryKeys() as $key) $this->cached->delete($key);
$this->response->redirect('blog/'.$this->request->getPost('id', 'int').'/');
$this->view->disable();
}
else foreach ($blog->getMessages() as $message) {
$this->flash->error($message);
$this->response->redirect('rifiks/editBlog/'.$this->request->getPost('id', 'int').'/');
$this->view->disable();
}
}
else {
foreach ($form->getMessages() as $message) $this->flash->error($message);
$this->response->redirect('rifiks/editBlog/'.$this->request->getPost('id', 'int').'/');
$this->view->disable();
}
}
}
public function AddCategoryAction(){
$form = new Contrario\Forms\AddCategoryForm();
$this->view->form = $form;
}
public function AddCAction(){
$form = new Contrario\Forms\AddCategoryForm();
if ($this->request->isPost() and $this->security->checkToken()) {
if ($form->isValid($this->request->getPost())) {
$category = new Categories();
$category->name = $this->request->getPost('name', 'string');
$category->text = $this->request->getPost('text', 'string');
if($category->save()) {
$this->cached->delete('categories.cache');
$this->response->redirect();
$this->view->disable();
}
else foreach ($category->getMessages() as $message) {
$this->flash->error($message);
$this->response->redirect('rifiks/addCategory');
$this->view->disable();
}
}
else {
foreach ($form->getMessages() as $message) $this->flash->error($message);
$this->response->redirect('rifiks/addCategory');
$this->view->disable();
}
}
}
public function editCategoriesAction(){
$this->view->setVars([
'categories' => Categories::find()
]);
}
public function editCategoryAction(){
$form = new Contrario\Forms\EditCategoryForm();
$category = Categories::findFirstById($this->dispatcher->getParam('category'));
if(!$category){
$this->response->redirect('rifiks/editCategories/');
$this->view->disable();
}
$this->view->setVars([
'category' => $category,
'blogs' => Blogs::findByCategory($this->dispatcher->getParam('category'))
]);
$this->view->form = $form;
}
public function editCategoryNAction(){
$form = new Contrario\Forms\EditCategoryForm();
if ($this->request->isPost() and $this->security->checkToken()) {
if ($form->isValid($this->request->getPost())) {
$category = Categories::findFirstById($this->request->getPost('id', 'int'));
$category->name = $this->request->getPost('name', 'string');
$category->text = $this->request->getPost('text', 'string');
if($category->save()) {
foreach ($this->cached->queryKeys() as $key) $this->cached->delete($key);
$this->response->redirect('category/'.$this->request->getPost('id', 'int').'/');
$this->view->disable();
}
else foreach ($blog->getMessages() as $message) {
$this->flash->error($message);
$this->response->redirect('rifiks/editCategory/'.$this->request->getPost('id', 'int').'/');
$this->view->disable();
}
}
else {
foreach ($form->getMessages() as $message) $this->flash->error($message);
$this->response->redirect('rifiks/editCategory/'.$this->request->getPost('id', 'int').'/');
$this->view->disable();
}
}
}
public function cacheDeleteAction(){
foreach ($this->cached->queryKeys() as $key) $this->cached->delete($key);
$this->response->redirect('rifiks');
$this->view->disable();
}
}