PluginProbe
User Access Manager / 2.0.12
User Access Manager v2.0.12
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.12, at src/UserAccessManager/Controller/AdminSettingsController.php

273 lines 7.4 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 $configParameters['lock_file_types'],
159 $configParameters['file_pass_type']
160 ];
161
162 $groupedConfigParameters['author'] = [
163 $configParameters['authors_has_access_to_own'],
164 $configParameters['authors_can_add_posts_to_groups'],
165 $configParameters['full_access_role'],
166 ];
167
168 $groupedConfigParameters['other'] = [
169 $configParameters['lock_recursive'],
170 $configParameters['protect_feed'],
171 $configParameters['redirect'],
172 $configParameters['blog_admin_hint'],
173 $configParameters['blog_admin_hint_text'],
174 ];
175
176 return $groupedConfigParameters;
177 }
178
179 /**
180 * Update settings action.
181 */
182 public function updateSettingsAction()
183 {
184 $this->verifyNonce('uamUpdateSettings');
185
186 $newConfigParameters = $this->getRequestParameter('config_parameters');
187 $this->config->setConfigParameters($newConfigParameters);
188
189 if ($this->config->lockFile() === false) {
190 $this->fileHandler->deleteFileProtection();
191 } else {
192 $this->fileHandler->createFileProtection();
193 }
194
195 $this->wordpress->doAction('uam_update_options', $this->config);
196 $this->setUpdateMessage(TXT_UAM_UPDATE_SETTINGS);
197 }
198
199 /**
200 * Checks if the group is a post type.
201 *
202 * @param string $groupKey
203 *
204 * @return bool
205 */
206 public function isPostTypeGroup($groupKey)
207 {
208 $postTypes = $this->getPostTypes();
209
210 return isset($postTypes[$groupKey]);
211 }
212
213 /**
214 * Returns the right translation string.
215 *
216 * @param string $groupKey
217 * @param string $ident
218 * @param bool $description
219 *
220 * @return mixed|string
221 */
222 private function getObjectText($groupKey, $ident, $description = false)
223 {
224 $objects = $this->getPostTypes() + $this->getTaxonomies();
225 $ident .= ($description === true) ? '_DESC' : '';
226
227 if (isset($objects[$groupKey]) === true) {
228 $ident = str_replace(strtoupper($groupKey), 'OBJECT', $ident);
229 $text = constant($ident);
230 $count = substr_count($text, '%s');
231 $arguments = $this->php->arrayFill(0, $count, $objects[$groupKey]->labels->name);
232 return vsprintf($text, $arguments);
233 }
234
235 return constant($ident);
236 }
237
238 /**
239 * @param string $groupKey
240 * @param bool $description
241 *
242 * @return string
243 */
244 public function getSectionText($groupKey, $description = false)
245 {
246 return $this->getObjectText(
247 $groupKey,
248 'TXT_UAM_'.strtoupper($groupKey).'_SETTING',
249 $description
250 );
251 }
252
253 /**
254 * Returns the label for the parameter.
255 *
256 * @param string $groupKey
257 * @param ConfigParameter $configParameter
258 * @param bool $description
259 *
260 * @return string
261 */
262 public function getParameterText($groupKey, ConfigParameter $configParameter, $description = false)
263 {
264 $ident = 'TXT_UAM_'.strtoupper($configParameter->getId());
265
266 return $this->getObjectText(
267 $groupKey,
268 $ident,
269 $description
270 );
271 }
272 }
273