|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Pierre-Henry Soria <[email protected]> |
|
4
|
|
|
* @copyright (c) 2012-2018, Pierre-Henry Soria. All Rights Reserved. |
|
5
|
|
|
* @license GNU General Public License; See PH7.LICENSE.txt and PH7.COPYRIGHT.txt in the root directory. |
|
6
|
|
|
* @package PH7 / App / System / Module / Admin / Controller |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace PH7; |
|
10
|
|
|
|
|
11
|
|
|
use PH7\Framework\Core\License; |
|
12
|
|
|
use PH7\Framework\Layout\Html\Design; |
|
13
|
|
|
use PH7\Framework\Mvc\Model\DbConfig; |
|
14
|
|
|
use PH7\Framework\Mvc\Router\Uri; |
|
15
|
|
|
use PH7\Framework\Navigation\Page; |
|
16
|
|
|
use PH7\Framework\Security\CSRF\Token as SecurityToken; |
|
17
|
|
|
use PH7\Framework\Translate\Lang; |
|
18
|
|
|
use PH7\Framework\Url\Header; |
|
19
|
|
|
|
|
20
|
|
|
class SettingController extends Controller |
|
21
|
|
|
{ |
|
22
|
|
|
const ADS_PER_PAGE = 10; |
|
23
|
|
|
|
|
24
|
|
|
public function index() |
|
25
|
|
|
{ |
|
26
|
|
|
Header::redirect( |
|
27
|
|
|
Uri::get(PH7_ADMIN_MOD, 'setting', 'general') |
|
28
|
|
|
); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function general() |
|
32
|
|
|
{ |
|
33
|
|
|
// Add Css Style for Tabs |
|
34
|
|
|
$this->design->addCss( |
|
35
|
|
|
PH7_LAYOUT . PH7_TPL . PH7_TPL_NAME . PH7_SH . PH7_CSS, |
|
36
|
|
|
'tabs.css' |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
$this->view->page_title = $this->view->h1_title = t('General Settings'); |
|
40
|
|
|
$this->output(); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function resetColor() |
|
44
|
|
|
{ |
|
45
|
|
|
if ((new SecurityToken)->checkUrl()) { |
|
46
|
|
|
$this->resetColorFields(); |
|
47
|
|
|
|
|
48
|
|
|
$sMsg = t('Colors successfully reset!'); |
|
49
|
|
|
$sMsgType = Design::SUCCESS_TYPE; |
|
50
|
|
|
} else { |
|
51
|
|
|
$sMsg = Form::errorTokenMsg(); |
|
52
|
|
|
$sMsgType = Design::ERROR_TYPE; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
Header::redirect( |
|
56
|
|
|
Uri::get(PH7_ADMIN_MOD, 'setting', 'general') . '#p=design', |
|
57
|
|
|
$sMsg, |
|
58
|
|
|
$sMsgType |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function ads() |
|
63
|
|
|
{ |
|
64
|
|
|
$oPage = new Page; |
|
65
|
|
|
$sTable = AdsCore::getTable(); |
|
66
|
|
|
$iTotalAds = (new AdsCoreModel)->total($sTable); |
|
67
|
|
|
|
|
68
|
|
|
$this->view->total_pages = $oPage->getTotalPages($iTotalAds, self::ADS_PER_PAGE); |
|
69
|
|
|
$this->view->current_page = $oPage->getCurrentPage(); |
|
70
|
|
|
unset($oPage, $sTable); |
|
71
|
|
|
|
|
72
|
|
|
// Add JS file for the ads form |
|
73
|
|
|
$this->design->addJs( |
|
74
|
|
|
PH7_LAYOUT . PH7_SYS . PH7_MOD . $this->registry->module . PH7_SH . PH7_TPL . PH7_TPL_MOD_NAME . PH7_SH . PH7_JS, |
|
75
|
|
|
'common.js' |
|
76
|
|
|
); |
|
77
|
|
|
|
|
78
|
|
|
$this->view->page_title = $this->view->h1_title = t('Banner Settings'); |
|
79
|
|
|
$this->view->h4_title = nt('%n% Banner', '%n% Banners', $iTotalAds); |
|
80
|
|
|
$this->output(); |
|
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function addAds() |
|
85
|
|
|
{ |
|
86
|
|
|
$this->view->page_title = $this->view->h1_title = t('Add a New Banner'); |
|
87
|
|
|
$this->output(); |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function analyticsApi() |
|
91
|
|
|
{ |
|
92
|
|
|
$this->view->page_title = $this->view->h1_title = t('Analytics API Code'); |
|
93
|
|
|
$this->output(); |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function style() |
|
97
|
|
|
{ |
|
98
|
|
|
$this->view->page_title = $this->view->h1_title = t('Style Code Injection'); |
|
99
|
|
|
$this->output(); |
|
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function script() |
|
103
|
|
|
{ |
|
104
|
|
|
$this->view->page_title = $this->view->h1_title = t('JavaScript Code Injection'); |
|
105
|
|
|
$this->output(); |
|
|
|
|
|
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function metaMain() |
|
109
|
|
|
{ |
|
110
|
|
|
// divShow.js for the Language Menu List |
|
111
|
|
|
$this->design->addJs(PH7_STATIC . PH7_JS, 'divShow.js'); |
|
112
|
|
|
|
|
113
|
|
|
$this->view->page_title = $this->view->h1_title = t('Meta Tags - Settings'); |
|
114
|
|
|
|
|
115
|
|
|
if ($this->langNameFromUrlDoesNotExist()) { |
|
116
|
|
|
Header::redirect( |
|
117
|
|
|
Uri::get( |
|
118
|
|
|
PH7_ADMIN_MOD, |
|
119
|
|
|
'setting', |
|
120
|
|
|
'metamain', |
|
121
|
|
|
PH7_LANG_NAME, |
|
122
|
|
|
false |
|
123
|
|
|
) |
|
124
|
|
|
); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
$this->output(); |
|
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function license() |
|
131
|
|
|
{ |
|
132
|
|
|
$this->view->page_title = $this->view->h1_title = t('License Key'); |
|
133
|
|
|
|
|
134
|
|
|
if ($this->httpRequest->getExists('set_msg')) { |
|
135
|
|
|
$aData = $this->getLicStatusMsg(); |
|
136
|
|
|
$this->design->setFlashMsg($aData['msg'], ($aData['is_err'] ? 'error' : 'success')); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
$this->output(); |
|
|
|
|
|
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
private function resetColorFields() |
|
143
|
|
|
{ |
|
144
|
|
|
$aColorFields = [ |
|
145
|
|
|
'backgroundColor', |
|
146
|
|
|
'textColor', |
|
147
|
|
|
'linkColor', |
|
148
|
|
|
'footerLinkColor', |
|
149
|
|
|
'linkHoverColor' |
|
150
|
|
|
]; |
|
151
|
|
|
|
|
152
|
|
|
foreach ($aColorFields as $sFieldName) { |
|
153
|
|
|
DbConfig::setSetting('', $sFieldName); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
DbConfig::clearCache(); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Get the status and the message for the license key. |
|
161
|
|
|
* |
|
162
|
|
|
* @return array ['is_err' => BOOLEAN, 'msg' => STRING]; |
|
163
|
|
|
*/ |
|
164
|
|
|
private function getLicStatusMsg() |
|
165
|
|
|
{ |
|
166
|
|
|
$bIsErr = true; // Set default value |
|
167
|
|
|
|
|
168
|
|
|
switch (PH7_LICENSE_STATUS) { |
|
169
|
|
|
case License::ACTIVE_STATUS: |
|
170
|
|
|
$sMsg = t('Hurrah! Your License Key has been successfully enabled!'); |
|
171
|
|
|
$bIsErr = false; |
|
172
|
|
|
break; |
|
173
|
|
|
|
|
174
|
|
|
case License::INVALID_STATUS: |
|
175
|
|
|
$sMsg = t('Oops! Your license key is Invalid.'); |
|
176
|
|
|
break; |
|
177
|
|
|
|
|
178
|
|
|
case License::EXPIRED_STATUS: |
|
179
|
|
|
$sMsg = t('Oops! Your license key is Expired.'); |
|
180
|
|
|
break; |
|
181
|
|
|
|
|
182
|
|
|
case License::SUSPENDED_STATUS: |
|
183
|
|
|
$sMsg = t('We are sorry, but your license key is Suspended.'); |
|
184
|
|
|
break; |
|
185
|
|
|
|
|
186
|
|
|
default: |
|
187
|
|
|
$sMsg = t('Oops! We have received an invalid response from the server. Please try again later.'); |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
return ['is_err' => $bIsErr, 'msg' => $sMsg]; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
private function langNameFromUrlDoesNotExist() |
|
194
|
|
|
{ |
|
195
|
|
|
$aLangs = $this->file->getDirList(PH7_PATH_APP_LANG); |
|
196
|
|
|
|
|
197
|
|
|
return !in_array(substr($this->httpRequest->currentUrl(), -Lang::LANG_FOLDER_LENGTH), $aLangs, true); |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.