1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\Controller\Admin; |
4
|
|
|
|
5
|
|
|
use Apps\Model\Admin\Main\EntityDeleteRoute; |
6
|
|
|
use Apps\Model\Admin\Main\FormAddRoute; |
7
|
|
|
use Apps\Model\Admin\Main\FormSettings; |
8
|
|
|
use Extend\Core\Arch\AdminAppController; |
9
|
|
|
use Ffcms\Core\App; |
10
|
|
|
use Ffcms\Core\Exception\SyntaxException; |
11
|
|
|
use Ffcms\Core\Helper\FileSystem\File; |
12
|
|
|
use Ffcms\Core\Helper\Type\Arr; |
13
|
|
|
use Ffcms\Core\Helper\Type\Integer; |
14
|
|
|
use Ffcms\Core\Helper\Type\Str; |
15
|
|
|
|
16
|
|
|
class Main extends AdminAppController |
17
|
|
|
{ |
18
|
|
|
public function __construct() |
19
|
|
|
{ |
20
|
|
|
parent::__construct(false); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Index page of admin dashboard |
25
|
|
|
*/ |
26
|
|
|
public function actionIndex() |
27
|
|
|
{ |
28
|
|
|
$this->response = App::$View->render('index', [ |
29
|
|
|
|
30
|
|
|
]); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Manage settings in web |
35
|
|
|
*/ |
36
|
|
View Code Duplication |
public function actionSettings() |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$model = new FormSettings(); |
39
|
|
|
|
40
|
|
|
if ($model->send()) { |
41
|
|
|
if ($model->validate()) { |
42
|
|
|
if ($model->makeSave()) { |
43
|
|
|
// show message about successful save and take system some time ;) |
44
|
|
|
$this->response = App::$View->render('settings_save'); |
45
|
|
|
return; |
46
|
|
|
} else { |
47
|
|
|
App::$Session->getFlashBag()->add('error', __('Configuration file is not writable! Check /Private/Config/ dir and files')); |
48
|
|
|
} |
49
|
|
|
} else { |
50
|
|
|
App::$Session->getFlashBag()->add('error', __('Validation of form data is failed!')); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$this->response = App::$View->render('settings', [ |
55
|
|
|
'model' => $model // no $model->export() there |
|
|
|
|
56
|
|
|
]); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Manage files via elFinder |
61
|
|
|
*/ |
62
|
|
|
public function actionFiles() |
63
|
|
|
{ |
64
|
|
|
$this->response = App::$View->render('files', [ |
65
|
|
|
'connector' => App::$Alias->scriptUrl . '/api/main/files?lang=' . App::$Request->getLanguage() |
66
|
|
|
]); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Show antivirus |
71
|
|
|
*/ |
72
|
|
|
public function actionAntivirus() |
73
|
|
|
{ |
74
|
|
|
$this->response = App::$View->render('antivirus'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function actionDebugcookie() |
78
|
|
|
{ |
79
|
|
|
$cookieProperty = App::$Properties->get('debug'); |
80
|
|
|
//App::$Request->cookies->add([$cookieProperty['cookie']['key'] => $cookieProperty['cookie']['value']]); todo: fix me |
|
|
|
|
81
|
|
|
setcookie($cookieProperty['cookie']['key'], $cookieProperty['cookie']['value'], Integer::MAX, '/', null, null, true); |
82
|
|
|
App::$Response->redirect('/'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* List available routes |
87
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
88
|
|
|
*/ |
89
|
|
|
public function actionRouting() |
90
|
|
|
{ |
91
|
|
|
$routingMap = App::$Properties->getAll('Routing'); |
92
|
|
|
|
93
|
|
|
$this->response = App::$View->render('routing', [ |
94
|
|
|
'routes' => $routingMap |
95
|
|
|
]); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Show add form for routing |
100
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
101
|
|
|
*/ |
102
|
|
|
public function actionAddroute() |
103
|
|
|
{ |
104
|
|
|
$model = new FormAddRoute(); |
105
|
|
|
|
106
|
|
|
if (!File::exist('/Private/Config/Routing.php') || !File::writable('/Private/Config/Routing.php')) { |
107
|
|
|
App::$Session->getFlashBag()->add('error', __('Routing configuration file is not allowed to write: /Private/Config/Routing.php')); |
108
|
|
|
} elseif ($model->send() && $model->validate()) { |
109
|
|
|
$model->save(); |
110
|
|
|
App::$Response->redirect('main/routing'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
$this->response = App::$View->render('add_route', [ |
114
|
|
|
'model' => $model |
115
|
|
|
]); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Delete scheme route |
120
|
|
|
* @throws SyntaxException |
121
|
|
|
*/ |
122
|
|
|
public function actionDeleteroute() |
123
|
|
|
{ |
124
|
|
|
$type = (string)App::$Request->query->get('type'); |
125
|
|
|
$loader = (string)App::$Request->query->get('loader'); |
126
|
|
|
$source = Str::lowerCase((string)App::$Request->query->get('path')); |
127
|
|
|
|
128
|
|
|
$model = new EntityDeleteRoute($type, $loader, $source); |
129
|
|
|
if ($model->send()) { |
130
|
|
|
$model->make(); |
131
|
|
|
App::$Response->redirect('main/routing'); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
$this->response = App::$View->render('delete_route', [ |
135
|
|
|
'model' => $model |
136
|
|
|
]); |
137
|
|
|
} |
138
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.