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\modules\Blogs\Sections; |
14
|
|
|
|
15
|
|
|
trait admin { |
16
|
|
|
static function admin___get_settings () { |
17
|
|
|
$module_data = Config::instance()->module('Blogs'); |
18
|
|
|
return [ |
19
|
|
|
'posts_per_page' => $module_data->posts_per_page, |
20
|
|
|
'max_sections' => $module_data->max_sections, |
21
|
|
|
'enable_comments' => $module_data->enable_comments, |
22
|
|
|
'new_posts_only_from_admins' => $module_data->new_posts_only_from_admins, |
23
|
|
|
'allow_iframes_without_content' => $module_data->allow_iframes_without_content |
24
|
|
|
]; |
25
|
|
|
} |
26
|
|
|
/** |
27
|
|
|
* @param \cs\Request $Request |
28
|
|
|
* |
29
|
|
|
* @throws ExitException |
30
|
|
|
*/ |
31
|
|
|
static function admin___save_settings ($Request) { |
32
|
|
|
$data = $Request->data('posts_per_page', 'max_sections', 'enable_comments', 'new_posts_only_from_admins', 'allow_iframes_without_content'); |
33
|
|
|
if (!$data) { |
34
|
|
|
throw new ExitException(400); |
35
|
|
|
} |
36
|
|
|
if (!Config::instance()->module('Blogs')->set($data)) { |
37
|
|
|
throw new ExitException(500); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
/** |
41
|
|
|
* @param \cs\Request $Request |
42
|
|
|
* |
43
|
|
|
* @return array |
44
|
|
|
* |
45
|
|
|
* @throws ExitException |
46
|
|
|
*/ |
47
|
|
|
static function admin_sections_get ($Request) { |
48
|
|
|
$id = $Request->route_ids(0); |
49
|
|
|
$Sections = Sections::instance(); |
50
|
|
|
if ($id) { |
51
|
|
|
$data = $Sections->get($id); |
52
|
|
|
if (!$data) { |
53
|
|
|
throw new ExitException(404); |
54
|
|
|
} |
55
|
|
|
return $data; |
56
|
|
|
} |
57
|
|
|
return $Sections->get_all(); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|