PluginProbe
User Access Manager / 2.0.8
User Access Manager v2.0.8
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
user-access-manager / src / UserAccessManager / Controller / AdminSettingsController.php

AdminSettingsController.php in User Access Manager 2.0.8, at src/UserAccessManager/Controller/AdminSettingsController.php

282 lines 7.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * AdminSettingsController.php
4 *
5 * The AdminSettingsController class file.
6 *
7 * PHP versions 5
8 *
9 * @author Alexander Schneider <alexanderschneider85@gmail.com>
10 * @copyright 2008-2017 Alexander Schneider
11 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 * @version SVN: $id$
13 * @link http://wordpress.org/extend/plugins/user-access-manager/
14 */
15 namespace UserAccessManager\Controller;
16
17 use UserAccessManager\Config\Config;
18 use UserAccessManager\Config\ConfigParameter;
19 use UserAccessManager\FileHandler\FileHandler;
20 use UserAccessManager\ObjectHandler\ObjectHandler;
21 use UserAccessManager\Wrapper\Php;
22 use UserAccessManager\Wrapper\Wordpress;
23
24 class AdminSettingsController extends Controller
25 {
26 /**
27 * @var string
28 */
29 protected $template = 'AdminSettings.php';
30
31 /**
32 * @var ObjectHandler
33 */
34 private $objectHandler;
35
36 /**
37 * @var FileHandler
38 */
39 private $fileHandler;
40
41 /**
42 * AdminSettingsController constructor.
43 *
44 * @param Php $php
45 * @param Wordpress $wordpress
46 * @param Config $config
47 * @param ObjectHandler $objectHandler
48 * @param FileHandler $fileHandler
49 */
50 public function __construct(
51 Php $php,
52 Wordpress $wordpress,
53 Config $config,
54 ObjectHandler $objectHandler,
55 FileHandler $fileHandler
56 ) {
57 parent::__construct($php, $wordpress, $config);
58 $this->objectHandler = $objectHandler;
59 $this->fileHandler = $fileHandler;
60 }
61
62 /**
63 * Returns true if the server is a nginx server.
64 *
65 * @return bool
66 */
67 public function isNginx()
68 {
69 return $this->wordpress->isNginx();
70 }
71
72 /**
73 * Returns the pages.
74 *
75 * @return array
76 */
77 public function getPages()
78 {
79 $pages = $this->wordpress->getPages('sort_column=menu_order');
80 return is_array($pages) !== false ? $pages : [];
81 }
82
83 /**
84 * Returns the config parameters.
85 *
86 * @return \UserAccessManager\Config\ConfigParameter[]
87 */
88 public function getConfigParameters()
89 {
90 return $this->config->getConfigParameters();
91 }
92
93 /**
94 * Returns the post types as object.
95 *
96 * @return \WP_Post_Type[]
97 */
98 private function getPostTypes()
99 {
100 return $this->wordpress->getPostTypes(['public' => true], 'objects');
101 }
102
103 /**
104 * Returns the taxonomies as objects.
105 *
106 * @return \WP_Taxonomy[]
107 */
108 private function getTaxonomies()
109 {
110 return $this->wordpress->getTaxonomies(['public' => true], 'objects');
111 }
112
113 /**
114 * Returns the grouped config parameters.
115 *
116 * @return array
117 */
118 public function getGroupedConfigParameters()
119 {
120 $configParameters = $this->config->getConfigParameters();
121
122 $groupedConfigParameters = [];
123 $postTypes = $this->getPostTypes();
124
125 foreach ($postTypes as $postType => $postTypeObject) {
126 if ($postType === ObjectHandler::ATTACHMENT_OBJECT_TYPE) {
127 continue;
128 }
129
130 $groupedConfigParameters[$postType] = [
131 $configParameters["hide_{$postType}"],
132 $configParameters["hide_{$postType}_title"],
133 $configParameters["{$postType}_title"],
134 $configParameters["{$postType}_content"],
135 $configParameters["hide_{$postType}_comment"],
136 $configParameters["{$postType}_comment_content"],
137 $configParameters["{$postType}_comments_locked"]
138 ];
139
140 if ($postType === 'post') {
141 $groupedConfigParameters[$postType][] = $configParameters["show_{$postType}_content_before_more"];
142 }
143 }
144
145 $taxonomies = $this->getTaxonomies();
146
147 foreach ($taxonomies as $taxonomy => $taxonomyObject) {
148 if ($taxonomy === ObjectHandler::POST_FORMAT_TYPE) {
149 continue;
150 }
151
152 $groupedConfigParameters[$taxonomy][] = $configParameters["hide_empty_{$taxonomy}"];
153 }
154
155 $groupedConfigParameters['file'] = [
156 $configParameters['lock_file'],
157 $configParameters['download_type']
158 ];
159
160 $groupedConfigParameters['author'] = [
161 $configParameters['authors_has_access_to_own'],
162 $configParameters['authors_can_add_posts_to_groups'],
163 $configParameters['full_access_role'],
164 ];
165
166 $groupedConfigParameters['other'] = [
167 $configParameters['lock_recursive'],
168 $configParameters['protect_feed'],
169 $configParameters['redirect'],
170 $configParameters['blog_admin_hint'],
171 $configParameters['blog_admin_hint_text'],
172 ];
173
174 if ($this->config->isPermalinksActive() === true) {
175 $groupedConfigParameters['file'][] = $configParameters['lock_file_types'];
176 $groupedConfigParameters['file'][] = $configParameters['file_pass_type'];
177 }
178
179 return $groupedConfigParameters;
180 }
181
182 /**
183 * Update settings action.
184 */
185 public function updateSettingsAction()
186 {
187 $this->verifyNonce('uamUpdateSettings');
188
189 $newConfigParameters = $this->getRequestParameter('config_parameters');
190 $newConfigParameters = array_map(
191 function ($entry) {
192 return htmlentities(str_replace('\\', '', $entry));
193 },
194 $newConfigParameters
195 );
196 $this->config->setConfigParameters($newConfigParameters);
197
198 if ($this->config->lockFile() === false) {
199 $this->fileHandler->deleteFileProtection();
200 } else {
201 $this->fileHandler->createFileProtection();
202 }
203
204 $this->wordpress->doAction('uam_update_options', $this->config);
205 $this->setUpdateMessage(TXT_UAM_UPDATE_SETTINGS);
206 }
207
208 /**
209 * Checks if the group is a post type.
210 *
211 * @param string $groupKey
212 *
213 * @return bool
214 */
215 public function isPostTypeGroup($groupKey)
216 {
217 $postTypes = $this->getPostTypes();
218
219 return isset($postTypes[$groupKey]);
220 }
221
222 /**
223 * Returns the right translation string.
224 *
225 * @param string $groupKey
226 * @param string $ident
227 * @param bool $description
228 *
229 * @return mixed|string
230 */
231 private function getObjectText($groupKey, $ident, $description = false)
232 {
233 $objects = $this->getPostTypes() + $this->getTaxonomies();
234 $ident .= ($description === true) ? '_DESC' : '';
235
236 if (isset($objects[$groupKey]) === true) {
237 $ident = str_replace(strtoupper($groupKey), 'OBJECT', $ident);
238 $text = constant($ident);
239 $count = substr_count($text, '%s');
240 $arguments = $this->php->arrayFill(0, $count, $objects[$groupKey]->labels->name);
241 return vsprintf($text, $arguments);
242 }
243
244 return constant($ident);
245 }
246
247 /**
248 * @param string $groupKey
249 * @param bool $description
250 *
251 * @return string
252 */
253 public function getSectionText($groupKey, $description = false)
254 {
255 return $this->getObjectText(
256 $groupKey,
257 'TXT_UAM_'.strtoupper($groupKey).'_SETTING',
258 $description
259 );
260 }
261
262 /**
263 * Returns the label for the parameter.
264 *
265 * @param string $groupKey
266 * @param ConfigParameter $configParameter
267 * @param bool $description
268 *
269 * @return string
270 */
271 public function getParameterText($groupKey, ConfigParameter $configParameter, $description = false)
272 {
273 $ident = 'TXT_UAM_'.strtoupper($configParameter->getId());
274
275 return $this->getObjectText(
276 $groupKey,
277 $ident,
278 $description
279 );
280 }
281 }
282