| 1 |
<?php |
| 2 |
/** |
| 3 |
* UamConfig.php |
| 4 |
* |
| 5 |
* The UamConfig class file. |
| 6 |
* |
| 7 |
* PHP versions 5 |
| 8 |
* |
| 9 |
* @category UserAccessManager |
| 10 |
* @package UserAccessManager |
| 11 |
* @author Alexander Schneider <alexanderschneider85@googlemail.com> |
| 12 |
* @copyright 2008-2016 Alexander Schneider |
| 13 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 |
| 14 |
* @version SVN: $Id$ |
| 15 |
* @link http://wordpress.org/extend/plugins/user-access-manager/ |
| 16 |
*/ |
| 17 |
|
| 18 |
/** |
| 19 |
* The config class. |
| 20 |
* |
| 21 |
* @category UserAccessManager |
| 22 |
* @package UserAccessManager |
| 23 |
* @author Alexander Schneider <alexanderschneider85@gmail.com> |
| 24 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 |
| 25 |
* @link http://wordpress.org/extend/plugins/user-access-manager/ |
| 26 |
*/ |
| 27 |
class UamConfig |
| 28 |
{ |
| 29 |
const ADMIN_OPTIONS_NAME = 'uamAdminOptions'; |
| 30 |
protected $_aAdminOptions = null; |
| 31 |
protected $_aWpOptions = array(); |
| 32 |
|
| 33 |
/** |
| 34 |
* Returns the WordPress options. |
| 35 |
* |
| 36 |
* @param string $sOption |
| 37 |
* |
| 38 |
* @return mixed |
| 39 |
*/ |
| 40 |
public function getWpOption($sOption) |
| 41 |
{ |
| 42 |
if (!isset($this->_aWpOptions[$sOption])) { |
| 43 |
$this->_aWpOptions[$sOption] = get_option($sOption); |
| 44 |
} |
| 45 |
|
| 46 |
return $this->_aWpOptions[$sOption]; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Returns the string value of a string option. |
| 51 |
* |
| 52 |
* @param string $sOptionName |
| 53 |
* |
| 54 |
* @return string |
| 55 |
*/ |
| 56 |
protected function _getStringOption($sOptionName) |
| 57 |
{ |
| 58 |
$aOptions = $this->getAdminOptions(); |
| 59 |
return isset($aOptions[$sOptionName]) ? (string)$aOptions[$sOptionName] : ''; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Returns the boolean value for an boolean option. |
| 64 |
* |
| 65 |
* @param string $sOptionName |
| 66 |
* |
| 67 |
* @return bool |
| 68 |
*/ |
| 69 |
protected function _getBooleanOption($sOptionName) |
| 70 |
{ |
| 71 |
$aOptions = $this->getAdminOptions(); |
| 72 |
return (isset($aOptions[$sOptionName]) && $aOptions[$sOptionName] === 'true'); |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Returns the current settings |
| 77 |
* |
| 78 |
* @return array |
| 79 |
*/ |
| 80 |
public function getAdminOptions() |
| 81 |
{ |
| 82 |
if ($this->_aAdminOptions === null) { |
| 83 |
$aUamAdminOptions = array( |
| 84 |
'hide_post_title' => 'false', |
| 85 |
'post_title' => __('No rights!', 'user-access-manager'), |
| 86 |
'post_content' => __( |
| 87 |
'Sorry you have no rights to view this post!', |
| 88 |
'user-access-manager' |
| 89 |
), |
| 90 |
'hide_post' => 'false', |
| 91 |
'hide_post_comment' => 'false', |
| 92 |
'post_comment_content' => __( |
| 93 |
'Sorry no rights to view comments!', |
| 94 |
'user-access-manager' |
| 95 |
), |
| 96 |
'post_comments_locked' => 'false', |
| 97 |
'hide_page_title' => 'false', |
| 98 |
'page_title' => __('No rights!', 'user-access-manager'), |
| 99 |
'page_content' => __( |
| 100 |
'Sorry you have no rights to view this page!', |
| 101 |
'user-access-manager' |
| 102 |
), |
| 103 |
'hide_page' => 'false', |
| 104 |
'hide_page_comment' => 'false', |
| 105 |
'page_comment_content' => __( |
| 106 |
'Sorry no rights to view comments!', |
| 107 |
'user-access-manager' |
| 108 |
), |
| 109 |
'page_comments_locked' => 'false', |
| 110 |
'redirect' => 'false', |
| 111 |
'redirect_custom_page' => '', |
| 112 |
'redirect_custom_url' => '', |
| 113 |
'lock_recursive' => 'true', |
| 114 |
'authors_has_access_to_own' => 'true', |
| 115 |
'authors_can_add_posts_to_groups' => 'false', |
| 116 |
'lock_file' => 'false', |
| 117 |
'file_pass_type' => 'random', |
| 118 |
'lock_file_types' => 'all', |
| 119 |
'download_type' => 'fopen', |
| 120 |
'locked_file_types' => 'zip,rar,tar,gz', |
| 121 |
'not_locked_file_types' => 'gif,jpg,jpeg,png', |
| 122 |
'blog_admin_hint' => 'true', |
| 123 |
'blog_admin_hint_text' => '[L]', |
| 124 |
'hide_empty_categories' => 'true', |
| 125 |
'protect_feed' => 'true', |
| 126 |
'show_post_content_before_more' => 'false', |
| 127 |
'full_access_role' => 'administrator' |
| 128 |
); |
| 129 |
|
| 130 |
$aUamOptions = $this->getWpOption(self::ADMIN_OPTIONS_NAME); |
| 131 |
|
| 132 |
if (!empty($aUamOptions)) { |
| 133 |
foreach ($aUamOptions as $sKey => $mOption) { |
| 134 |
$aUamAdminOptions[$sKey] = $mOption; |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
update_option(self::ADMIN_OPTIONS_NAME, $aUamAdminOptions); |
| 139 |
$this->_aAdminOptions = $aUamAdminOptions; |
| 140 |
} |
| 141 |
|
| 142 |
return $this->_aAdminOptions; |
| 143 |
} |
| 144 |
|
| 145 |
/** |
| 146 |
* Returns the option value if the option exists otherwise true. |
| 147 |
* |
| 148 |
* @param string $sOptionName |
| 149 |
* |
| 150 |
* @return bool |
| 151 |
*/ |
| 152 |
protected function _hideObject($sOptionName) |
| 153 |
{ |
| 154 |
$aOptions = $this->getAdminOptions(); |
| 155 |
|
| 156 |
if (isset($aOptions[$sOptionName])) { |
| 157 |
return $this->_getBooleanOption($sOptionName); |
| 158 |
} |
| 159 |
|
| 160 |
return true; |
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* @param string $sObjectType |
| 165 |
* |
| 166 |
* @return bool |
| 167 |
*/ |
| 168 |
public function hideObjectType($sObjectType) |
| 169 |
{ |
| 170 |
return $this->_hideObject('hide_'.$sObjectType); |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* @param string $sObjectType |
| 175 |
* |
| 176 |
* @return bool |
| 177 |
*/ |
| 178 |
public function hideObjectTypeTitle($sObjectType) |
| 179 |
{ |
| 180 |
return $this->_hideObject('hide_'.$sObjectType.'_title'); |
| 181 |
} |
| 182 |
|
| 183 |
/** |
| 184 |
* @param string $sObjectType |
| 185 |
* |
| 186 |
* @return bool |
| 187 |
*/ |
| 188 |
public function hideObjectTypeComments($sObjectType) |
| 189 |
{ |
| 190 |
return $this->_hideObject($sObjectType.'_comments_locked'); |
| 191 |
} |
| 192 |
|
| 193 |
/** |
| 194 |
* @param string $sObjectType |
| 195 |
* |
| 196 |
* @return string |
| 197 |
*/ |
| 198 |
public function getObjectTypeTitle($sObjectType) |
| 199 |
{ |
| 200 |
return $this->_getStringOption($sObjectType.'_title'); |
| 201 |
} |
| 202 |
|
| 203 |
/** |
| 204 |
* @param string $sObjectType |
| 205 |
* |
| 206 |
* @return string |
| 207 |
*/ |
| 208 |
public function getObjectTypeContent($sObjectType) |
| 209 |
{ |
| 210 |
return $this->_getStringOption($sObjectType.'_content'); |
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
* @param string $sObjectType |
| 215 |
* |
| 216 |
* @return string |
| 217 |
*/ |
| 218 |
public function getObjectTypeCommentContent($sObjectType) |
| 219 |
{ |
| 220 |
return $this->_getStringOption($sObjectType . '_comment_content'); |
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* @return bool |
| 225 |
*/ |
| 226 |
public function hidePostTitle() |
| 227 |
{ |
| 228 |
return $this->_getBooleanOption('hide_post_title'); |
| 229 |
} |
| 230 |
|
| 231 |
/** |
| 232 |
* @return string |
| 233 |
*/ |
| 234 |
public function getPostTitle() |
| 235 |
{ |
| 236 |
return $this->_getStringOption('post_title'); |
| 237 |
} |
| 238 |
|
| 239 |
/** |
| 240 |
* @return string |
| 241 |
*/ |
| 242 |
public function getPostContent() |
| 243 |
{ |
| 244 |
return $this->_getStringOption('post_content'); |
| 245 |
} |
| 246 |
|
| 247 |
/** |
| 248 |
* @return bool |
| 249 |
*/ |
| 250 |
public function hidePost() |
| 251 |
{ |
| 252 |
return $this->_getBooleanOption('hide_post'); |
| 253 |
} |
| 254 |
|
| 255 |
/** |
| 256 |
* @return bool |
| 257 |
*/ |
| 258 |
public function hidePostComment() |
| 259 |
{ |
| 260 |
return $this->_getBooleanOption('hide_post_comment'); |
| 261 |
} |
| 262 |
|
| 263 |
/** |
| 264 |
* @return string |
| 265 |
*/ |
| 266 |
public function getPostCommentContent() |
| 267 |
{ |
| 268 |
return $this->_getStringOption('post_comment_content'); |
| 269 |
} |
| 270 |
|
| 271 |
/** |
| 272 |
* @return bool |
| 273 |
*/ |
| 274 |
public function isPostCommentsLocked() |
| 275 |
{ |
| 276 |
return $this->_getBooleanOption('post_comments_locked'); |
| 277 |
} |
| 278 |
|
| 279 |
/** |
| 280 |
* @return bool |
| 281 |
*/ |
| 282 |
public function hidePageTitle() |
| 283 |
{ |
| 284 |
return $this->_getBooleanOption('hide_page_title'); |
| 285 |
} |
| 286 |
|
| 287 |
/** |
| 288 |
* @return string |
| 289 |
*/ |
| 290 |
public function getPageTitle() |
| 291 |
{ |
| 292 |
return $this->_getStringOption('page_title'); |
| 293 |
} |
| 294 |
|
| 295 |
/** |
| 296 |
* @return string |
| 297 |
*/ |
| 298 |
public function getPageContent() |
| 299 |
{ |
| 300 |
return $this->_getStringOption('page_content'); |
| 301 |
} |
| 302 |
|
| 303 |
/** |
| 304 |
* @return bool |
| 305 |
*/ |
| 306 |
public function hidePage() |
| 307 |
{ |
| 308 |
return $this->_getBooleanOption('hide_page'); |
| 309 |
} |
| 310 |
|
| 311 |
/** |
| 312 |
* @return bool |
| 313 |
*/ |
| 314 |
public function hidePageComment() |
| 315 |
{ |
| 316 |
return $this->_getBooleanOption('hide_page_comment'); |
| 317 |
} |
| 318 |
|
| 319 |
/** |
| 320 |
* @return string |
| 321 |
*/ |
| 322 |
public function getPageCommentContent() |
| 323 |
{ |
| 324 |
return $this->_getStringOption('page_comment_content'); |
| 325 |
} |
| 326 |
|
| 327 |
/** |
| 328 |
* @return bool |
| 329 |
*/ |
| 330 |
public function isPageCommentsLocked() |
| 331 |
{ |
| 332 |
return $this->_getBooleanOption('page_comments_locked'); |
| 333 |
} |
| 334 |
|
| 335 |
/** |
| 336 |
* @return string |
| 337 |
*/ |
| 338 |
public function getRedirect() |
| 339 |
{ |
| 340 |
return $this->_getStringOption('redirect'); |
| 341 |
} |
| 342 |
|
| 343 |
/** |
| 344 |
* @return string |
| 345 |
*/ |
| 346 |
public function getRedirectCustomPage() |
| 347 |
{ |
| 348 |
return $this->_getStringOption('redirect_custom_page'); |
| 349 |
} |
| 350 |
|
| 351 |
/** |
| 352 |
* @return string |
| 353 |
*/ |
| 354 |
public function getRedirectCustomUrl() |
| 355 |
{ |
| 356 |
return $this->_getStringOption('redirect_custom_url'); |
| 357 |
} |
| 358 |
|
| 359 |
/** |
| 360 |
* @return bool |
| 361 |
*/ |
| 362 |
public function lockRecursive() |
| 363 |
{ |
| 364 |
return $this->_getBooleanOption('lock_recursive'); |
| 365 |
} |
| 366 |
|
| 367 |
/** |
| 368 |
* @return bool |
| 369 |
*/ |
| 370 |
public function authorsHasAccessToOwn() |
| 371 |
{ |
| 372 |
return $this->_getBooleanOption('authors_has_access_to_own'); |
| 373 |
} |
| 374 |
|
| 375 |
/** |
| 376 |
* @return bool |
| 377 |
*/ |
| 378 |
public function authorsCanAddPostsToGroups() |
| 379 |
{ |
| 380 |
return $this->_getBooleanOption('authors_can_add_posts_to_groups'); |
| 381 |
} |
| 382 |
|
| 383 |
/** |
| 384 |
* @return bool |
| 385 |
*/ |
| 386 |
public function lockFile() |
| 387 |
{ |
| 388 |
return $this->_getBooleanOption('lock_file'); |
| 389 |
} |
| 390 |
|
| 391 |
/** |
| 392 |
* @return string |
| 393 |
*/ |
| 394 |
public function getFilePassType() |
| 395 |
{ |
| 396 |
return $this->_getStringOption('file_pass_type'); |
| 397 |
} |
| 398 |
|
| 399 |
/** |
| 400 |
* @return string |
| 401 |
*/ |
| 402 |
public function getLockFileTypes() |
| 403 |
{ |
| 404 |
return $this->_getStringOption('lock_file_types'); |
| 405 |
} |
| 406 |
|
| 407 |
/** |
| 408 |
* @return string |
| 409 |
*/ |
| 410 |
public function getDownloadType() |
| 411 |
{ |
| 412 |
return $this->_getStringOption('download_type'); |
| 413 |
} |
| 414 |
|
| 415 |
/** |
| 416 |
* @return string |
| 417 |
*/ |
| 418 |
public function getLockedFileTypes() |
| 419 |
{ |
| 420 |
return $this->_getStringOption('locked_file_types'); |
| 421 |
} |
| 422 |
|
| 423 |
/** |
| 424 |
* @return string |
| 425 |
*/ |
| 426 |
public function getNotLockedFileTypes() |
| 427 |
{ |
| 428 |
return $this->_getStringOption('not_locked_file_types'); |
| 429 |
} |
| 430 |
|
| 431 |
/** |
| 432 |
* @return bool |
| 433 |
*/ |
| 434 |
public function blogAdminHint() |
| 435 |
{ |
| 436 |
return $this->_getBooleanOption('blog_admin_hint'); |
| 437 |
} |
| 438 |
|
| 439 |
/** |
| 440 |
* @return string |
| 441 |
*/ |
| 442 |
public function getBlogAdminHintText() |
| 443 |
{ |
| 444 |
return $this->_getStringOption('blog_admin_hint_text'); |
| 445 |
} |
| 446 |
|
| 447 |
/** |
| 448 |
* @return bool |
| 449 |
*/ |
| 450 |
public function hideEmptyCategories() |
| 451 |
{ |
| 452 |
return $this->_getBooleanOption('hide_empty_categories'); |
| 453 |
} |
| 454 |
|
| 455 |
/** |
| 456 |
* @return bool |
| 457 |
*/ |
| 458 |
public function protectFeed() |
| 459 |
{ |
| 460 |
return $this->_getBooleanOption('protect_feed'); |
| 461 |
} |
| 462 |
|
| 463 |
/** |
| 464 |
* @return bool |
| 465 |
*/ |
| 466 |
public function showPostContentBeforeMore() |
| 467 |
{ |
| 468 |
return $this->_getBooleanOption('show_post_content_before_more'); |
| 469 |
} |
| 470 |
|
| 471 |
/** |
| 472 |
* @return string |
| 473 |
*/ |
| 474 |
public function getFullAccessRole() |
| 475 |
{ |
| 476 |
return $this->_getStringOption('full_access_role'); |
| 477 |
} |
| 478 |
} |