PluginProbe
User Access Manager / 2.0.9
User Access Manager v2.0.9
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.9, at src/UserAccessManager/Controller/AdminSettingsController.php

276 lines 7.5 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 $this->config->setConfigParameters($newConfigParameters);
191
192 if ($this->config->lockFile() === false) {
193 $this->fileHandler->deleteFileProtection();
194 } else {
195 $this->fileHandler->createFileProtection();
196 }
197
198 $this->wordpress->doAction('uam_update_options', $this->config);
199 $this->setUpdateMessage(TXT_UAM_UPDATE_SETTINGS);
200 }
201
202 /**
203 * Checks if the group is a post type.
204 *
205 * @param string $groupKey
206 *
207 * @return bool
208 */
209 public function isPostTypeGroup($groupKey)
210 {
211 $postTypes = $this->getPostTypes();
212
213 return isset($postTypes[$groupKey]);
214 }
215
216 /**
217 * Returns the right translation string.
218 *
219 * @param string $groupKey
220 * @param string $ident
221 * @param bool $description
222 *
223 * @return mixed|string
224 */
225 private function getObjectText($groupKey, $ident, $description = false)
226 {
227 $objects = $this->getPostTypes() + $this->getTaxonomies();
228 $ident .= ($description === true) ? '_DESC' : '';
229
230 if (isset($objects[$groupKey]) === true) {
231 $ident = str_replace(strtoupper($groupKey), 'OBJECT', $ident);
232 $text = constant($ident);
233 $count = substr_count($text, '%s');
234 $arguments = $this->php->arrayFill(0, $count, $objects[$groupKey]->labels->name);
235 return vsprintf($text, $arguments);
236 }
237
238 return constant($ident);
239 }
240
241 /**
242 * @param string $groupKey
243 * @param bool $description
244 *
245 * @return string
246 */
247 public function getSectionText($groupKey, $description = false)
248 {
249 return $this->getObjectText(
250 $groupKey,
251 'TXT_UAM_'.strtoupper($groupKey).'_SETTING',
252 $description
253 );
254 }
255
256 /**
257 * Returns the label for the parameter.
258 *
259 * @param string $groupKey
260 * @param ConfigParameter $configParameter
261 * @param bool $description
262 *
263 * @return string
264 */
265 public function getParameterText($groupKey, ConfigParameter $configParameter, $description = false)
266 {
267 $ident = 'TXT_UAM_'.strtoupper($configParameter->getId());
268
269 return $this->getObjectText(
270 $groupKey,
271 $ident,
272 $description
273 );
274 }
275 }
276