1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package Blogs |
4
|
|
|
* @category modules |
5
|
|
|
* @author Nazar Mokrynskyi <[email protected]> |
6
|
|
|
* @copyright Copyright (c) 2011-2016, Nazar Mokrynskyi |
7
|
|
|
* @license MIT License, see license.txt |
8
|
|
|
*/ |
9
|
|
|
namespace cs\modules\Blogs\api\Controller; |
10
|
|
|
use |
11
|
|
|
cs\Config, |
12
|
|
|
cs\ExitException, |
13
|
|
|
cs\Language, |
14
|
|
|
cs\modules\Blogs\Sections; |
15
|
|
|
|
16
|
|
|
trait admin { |
17
|
|
|
static function admin___get_settings () { |
18
|
|
|
$module_data = Config::instance()->module('Blogs'); |
19
|
|
|
return [ |
20
|
|
|
'posts_per_page' => $module_data->posts_per_page, |
21
|
|
|
'max_sections' => $module_data->max_sections, |
22
|
|
|
'enable_comments' => $module_data->enable_comments, |
23
|
|
|
'new_posts_only_from_admins' => $module_data->new_posts_only_from_admins, |
24
|
|
|
'allow_iframes_without_content' => $module_data->allow_iframes_without_content |
25
|
|
|
]; |
26
|
|
|
} |
27
|
|
|
/** |
28
|
|
|
* @param \cs\Request $Request |
29
|
|
|
* |
30
|
|
|
* @throws ExitException |
31
|
|
|
*/ |
32
|
|
|
static function admin___save_settings ($Request) { |
33
|
|
|
$data = $Request->data('posts_per_page', 'max_sections', 'enable_comments', 'new_posts_only_from_admins', 'allow_iframes_without_content'); |
34
|
|
|
if (!$data) { |
35
|
|
|
throw new ExitException(400); |
36
|
|
|
} |
37
|
|
|
if (!Config::instance()->module('Blogs')->set($data)) { |
38
|
|
|
throw new ExitException(500); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
/** |
42
|
|
|
* @param \cs\Request $Request |
43
|
|
|
* |
44
|
|
|
* @return array |
45
|
|
|
* |
46
|
|
|
* @throws ExitException |
47
|
|
|
*/ |
48
|
|
|
static function admin_sections_get ($Request) { |
49
|
|
|
return static::sections_get($Request); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
/** |
52
|
|
|
* @param \cs\Request $Request |
53
|
|
|
* @param \cs\Response $Response |
54
|
|
|
* |
55
|
|
|
* @return array |
|
|
|
|
56
|
|
|
* |
57
|
|
|
* @throws ExitException |
58
|
|
|
*/ |
59
|
|
|
static function admin_sections_post ($Request, $Response) { |
60
|
|
|
$data = $Request->data('title', 'path', 'parent'); |
61
|
|
|
if (!$data) { |
62
|
|
|
throw new ExitException(400); |
63
|
|
|
} |
64
|
|
|
$Sections = Sections::instance(); |
65
|
|
|
$id = $Sections->add($data['parent'], $data['title'], $data['path']); |
66
|
|
|
if (!$id) { |
67
|
|
|
throw new ExitException(Language::instance()->blogs_changes_save_error, 500); |
68
|
|
|
} |
69
|
|
|
$Response->code = 201; |
70
|
|
|
return [ |
71
|
|
|
'id' => $id, |
72
|
|
|
'url' => Config::instance()->base_url().'/Blogs/section/'.$Sections->get($id)['full_path'] |
73
|
|
|
]; |
74
|
|
|
} |
75
|
|
|
/** |
76
|
|
|
* @param \cs\Request $Request |
77
|
|
|
* |
78
|
|
|
* @return array |
|
|
|
|
79
|
|
|
* |
80
|
|
|
* @throws ExitException |
81
|
|
|
*/ |
82
|
|
|
static function admin_sections_put ($Request) { |
83
|
|
|
$id = $Request->route_ids(0); |
84
|
|
|
$data = $Request->data('title', 'path', 'parent'); |
85
|
|
|
if (!$id || !$data) { |
86
|
|
|
throw new ExitException(400); |
87
|
|
|
} |
88
|
|
|
$Sections = Sections::instance(); |
89
|
|
|
if (!$Sections->get($id)) { |
90
|
|
|
throw new ExitException(404); |
91
|
|
|
} |
92
|
|
|
if (!$Sections->set($id, $data['parent'], $data['title'], $data['path'])) { |
93
|
|
|
throw new ExitException(Language::instance()->blogs_changes_save_error, 500); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
/** |
97
|
|
|
* @param \cs\Request $Request |
98
|
|
|
* |
99
|
|
|
* @return array |
|
|
|
|
100
|
|
|
* |
101
|
|
|
* @throws ExitException |
102
|
|
|
*/ |
103
|
|
|
static function admin_sections_delete ($Request) { |
104
|
|
|
$id = $Request->route_ids(0); |
105
|
|
|
if (!$id) { |
106
|
|
|
throw new ExitException(400); |
107
|
|
|
} |
108
|
|
|
$Sections = Sections::instance(); |
109
|
|
|
if (!$Sections->get($id)) { |
110
|
|
|
throw new ExitException(404); |
111
|
|
|
} |
112
|
|
|
if (!$Sections->del($id)) { |
113
|
|
|
throw new ExitException(Language::instance()->blogs_changes_save_error, 500); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.