PluginProbe
User Access Manager / 1.2.6.9
User Access Manager v1.2.6.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 / class / UserAccessManager.class.php

UserAccessManager.class.php in User Access Manager 1.2.6.9, at class/UserAccessManager.class.php

2,368 lines 69.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * UserAccessManager.class.php
4 *
5 * The UserAccessManager class file.
6 *
7 * PHP versions 5
8 *
9 * @category UserAccessManager
10 * @package UserAccessManager
11 * @author Alexander Schneider <alexanderschneider85@googlemail.com>
12 * @copyright 2008-2013 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 user user access manager 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 UserAccessManager
28 {
29 protected $_blAtAdminPanel = false;
30 protected $_sAdminOptionsName = "uamAdminOptions";
31 protected $_sUamVersion = "1.2.6.9";
32 protected $_sUamDbVersion = "1.3";
33 protected $_aAdminOptions = null;
34 protected $_oAccessHandler = null;
35 protected $_aPostUrls = array();
36 protected $_aMimeTypes = null;
37 protected $_aCache = array();
38 protected $_aPosts = array();
39 protected $_aCategories = array();
40 protected $_aWpOptions = array();
41
42 /**
43 * Constructor.
44 */
45 public function __construct()
46 {
47 do_action('uam_init', $this);
48 }
49
50 /**
51 * Returns the admin options name for the uam.
52 *
53 * @return string
54 */
55 public function getAdminOptionsName()
56 {
57 return $this->_sAdminOptionsName;
58 }
59
60 /**
61 * Flushes the cache.
62 */
63 public function flushCache()
64 {
65 $this->_aCache = array();
66 }
67
68 /**
69 * Adds the variable to the cache.
70 *
71 * @param string $sKey The cache key
72 * @param mixed $mValue The value.
73 */
74 public function addToCache($sKey, $mValue)
75 {
76 $this->_aCache[$sKey] = $mValue;
77 }
78
79 /**
80 * Returns a value from the cache by the given key.
81 *
82 * @param string $sKey
83 *
84 * @return mixed
85 */
86 public function getFromCache($sKey)
87 {
88 if (isset($this->_aCache[$sKey])) {
89 return $this->_aCache[$sKey];
90 }
91
92 return null;
93 }
94
95 public function getWpOption($sOption)
96 {
97 if (!isset($this->_aWpOptions[$sOption])) {
98 $this->_aWpOptions[$sOption] = get_option($sOption);
99 }
100
101 return $this->_aWpOptions[$sOption];
102 }
103
104 /**
105 * Returns a post.
106 *
107 * @param string $sId The post id.
108 *
109 * @return mixed
110 */
111 public function getPost($sId)
112 {
113 if (!isset($this->_aPosts[$sId])) {
114 $this->_aPosts[$sId] = get_post($sId);
115 }
116
117 return $this->_aPosts[$sId];
118 }
119
120 /**
121 * Returns a category.
122 *
123 * @param string $sId The category id.
124 *
125 * @return mixed
126 */
127 public function getCategory($sId)
128 {
129 if (!isset($this->_aCategories[$sId])) {
130 $this->_aCategories[$sId] = get_category($sId);
131 }
132
133 return $this->_aCategories[$sId];
134 }
135
136 /**
137 * Returns all blog of the network.
138 *
139 * @return array()
140 */
141 protected function _getBlogIds()
142 {
143 /**
144 * @var wpdb $wpdb
145 */
146 global $wpdb;
147 $aBlogIds = array();
148
149 if (is_multisite()) {
150 $aBlogIds = $wpdb->get_col(
151 "SELECT blog_id
152 FROM ".$wpdb->blogs
153 );
154 }
155
156 return $aBlogIds;
157 }
158
159 /**
160 * Installs the user access manager.
161 *
162 * @return null;
163 */
164 public function install()
165 {
166 global $wpdb;
167 $aBlogIds = $this->_getBlogIds();
168
169 if (isset($_GET['networkwide'])
170 && ((int)$_GET['networkwide'] === 1)
171 ) {
172 $iCurrentBlogId = $wpdb->blogid;
173
174 foreach ($aBlogIds as $iBlogId) {
175 switch_to_blog($iBlogId);
176 $this->_installUam();
177 }
178
179 switch_to_blog($iCurrentBlogId);
180
181 return null;
182 }
183
184 $this->_installUam();
185 }
186
187 /**
188 * Creates the needed tables at the database and adds the options
189 *
190 * @return null;
191 */
192 protected function _installUam()
193 {
194 /**
195 * @var wpdb $wpdb
196 */
197 global $wpdb;
198 include_once ABSPATH.'wp-admin/includes/upgrade.php';
199
200 $sCharsetCollate = $this->_getCharset();
201
202 $sDbAccessGroupTable = $wpdb->prefix.'uam_accessgroups';
203
204 $sDbUserGroup = $wpdb->get_var(
205 "SHOW TABLES
206 LIKE '".$sDbAccessGroupTable."'"
207 );
208
209 if ($sDbUserGroup != $sDbAccessGroupTable) {
210 dbDelta(
211 "CREATE TABLE ".$sDbAccessGroupTable." (
212 ID int(11) NOT NULL auto_increment,
213 groupname tinytext NOT NULL,
214 groupdesc text NOT NULL,
215 read_access tinytext NOT NULL,
216 write_access tinytext NOT NULL,
217 ip_range mediumtext NULL,
218 PRIMARY KEY (ID)
219 ) $sCharsetCollate;"
220 );
221 }
222
223 $sDbAccessGroupToObjectTable = $wpdb->prefix.'uam_accessgroup_to_object';
224
225 $sDbAccessGroupToObject = $wpdb->get_var(
226 "SHOW TABLES
227 LIKE '".$sDbAccessGroupToObjectTable."'"
228 );
229
230 if ($sDbAccessGroupToObject != $sDbAccessGroupToObjectTable) {
231 dbDelta(
232 "CREATE TABLE " . $sDbAccessGroupToObjectTable . " (
233 object_id VARCHAR(64) NOT NULL,
234 object_type varchar(64) NOT NULL,
235 group_id int(11) NOT NULL,
236 PRIMARY KEY (object_id,object_type,group_id)
237 ) $sCharsetCollate;"
238 );
239 }
240
241 add_option("uam_db_version", $this->_sUamDbVersion);
242 }
243
244 /**
245 * Checks if a database update is necessary.
246 *
247 * @return boolean
248 */
249 public function isDatabaseUpdateNecessary()
250 {
251 global $wpdb;
252 $sBlogIds = $this->_getBlogIds();
253
254 if ($sBlogIds !== array()
255 && is_super_admin()
256 ) {
257 $iCurrentBlogId = $wpdb->blogid;
258
259 foreach ($sBlogIds as $iBlogId) {
260 switch_to_blog($iBlogId);
261 $sCurrentDbVersion = $this->getWpOption("uam_db_version");
262
263 if (version_compare($sCurrentDbVersion, $this->_sUamDbVersion, '<')) {
264 switch_to_blog($iCurrentBlogId);
265 return true;
266 }
267 }
268
269 switch_to_blog($iCurrentBlogId);
270 }
271
272 $sCurrentDbVersion = $this->getWpOption("uam_db_version");
273 return version_compare($sCurrentDbVersion, $this->_sUamDbVersion, '<');
274 }
275
276 /**
277 * Updates the user access manager if an old version was installed.
278 *
279 * @param boolean $blNetworkWide If true update network wide
280 *
281 * @return null;
282 */
283 public function update($blNetworkWide)
284 {
285 global $wpdb;
286 $aBlogIds = $this->_getBlogIds();
287
288 if ($blNetworkWide
289 && $aBlogIds !== array()
290 ) {
291 $iCurrentBlogId = $wpdb->blogid;
292
293 foreach ($aBlogIds as $iBlogId) {
294 switch_to_blog($iBlogId);
295 $this->_installUam();
296 $this->_updateUam();
297 }
298
299 switch_to_blog($iCurrentBlogId);
300 } else {
301 $this->_updateUam();
302 }
303 }
304
305 /**
306 * Updates the user access manager if an old version was installed.
307 *
308 * @return null;
309 */
310 protected function _updateUam()
311 {
312 /**
313 * @var wpdb $wpdb
314 */
315 global $wpdb;
316 $sCurrentDbVersion = $this->getWpOption("uam_db_version");
317
318 if (empty($sCurrentDbVersion)) {
319 $this->install();
320 }
321
322 if (!$this->getWpOption('uam_version') || version_compare($this->getWpOption('uam_version'), "1.0", '<')) {
323 delete_option('allow_comments_locked');
324 }
325
326 $sDbAccessGroup = $wpdb->prefix.'uam_accessgroups';
327
328 $sDbUserGroup = $wpdb->get_var(
329 "SHOW TABLES
330 LIKE '".$sDbAccessGroup."'"
331 );
332
333 if (version_compare($sCurrentDbVersion, $this->_sUamDbVersion, '<')) {
334 $sCharsetCollate = $this->_getCharset();
335
336 if (version_compare($sCurrentDbVersion, "1.0", '<=')) {
337 if ($sDbUserGroup == $sDbAccessGroup) {
338 $wpdb->query(
339 "ALTER TABLE ".$sDbAccessGroup."
340 ADD read_access TINYTEXT NOT NULL DEFAULT '',
341 ADD write_access TINYTEXT NOT NULL DEFAULT '',
342 ADD ip_range MEDIUMTEXT NULL DEFAULT ''"
343 );
344
345 $wpdb->query(
346 "UPDATE ".$sDbAccessGroup."
347 SET read_access = 'group',
348 write_access = 'group'"
349 );
350
351 $sDbIpRange = $wpdb->get_var(
352 "SHOW columns
353 FROM ".$sDbAccessGroup."
354 LIKE 'ip_range'"
355 );
356
357 if ($sDbIpRange != 'ip_range') {
358 $wpdb->query(
359 "ALTER TABLE ".$sDbAccessGroup."
360 ADD ip_range MEDIUMTEXT NULL DEFAULT ''"
361 );
362 }
363 }
364
365 $sDbAccessGroupToObject = $wpdb->prefix.'uam_accessgroup_to_object';
366 $sDbAccessGroupToPost = $wpdb->prefix.'uam_accessgroup_to_post';
367 $sDbAccessGroupToUser = $wpdb->prefix.'uam_accessgroup_to_user';
368 $sDbAccessGroupToCategory = $wpdb->prefix.'uam_accessgroup_to_category';
369 $sDbAccessGroupToRole = $wpdb->prefix.'uam_accessgroup_to_role';
370
371 $wpdb->query(
372 "ALTER TABLE '{$sDbAccessGroupToObject}'
373 CHANGE 'object_id' 'object_id' VARCHAR(64)
374 ".$sCharsetCollate
375 );
376
377 $aObjectTypes = $this->getAccessHandler()->getObjectTypes();
378
379 foreach ($aObjectTypes as $sObjectType) {
380 $sAddition = '';
381
382 if ($this->getAccessHandler()->isPostableType($sObjectType)) {
383 $sDbIdName = 'post_id';
384 $sDatabase = $sDbAccessGroupToPost.', '.$wpdb->posts;
385 $sAddition = " WHERE post_id = ID
386 AND post_type = '".$sObjectType."'";
387 } elseif ($sObjectType == 'category') {
388 $sDbIdName = 'category_id';
389 $sDatabase = $sDbAccessGroupToCategory;
390 } elseif ($sObjectType == 'user') {
391 $sDbIdName = 'user_id';
392 $sDatabase = $sDbAccessGroupToUser;
393 } elseif ($sObjectType == 'role') {
394 $sDbIdName = 'role_name';
395 $sDatabase = $sDbAccessGroupToRole;
396 } else {
397 continue;
398 }
399
400 $sFullDatabase = $sDatabase.$sAddition;
401
402 $sSql = "SELECT {$sDbIdName} as id, group_id as groupId
403 FROM {$sFullDatabase}";
404
405 $aDbObjects = $wpdb->get_results($sSql);
406
407 foreach ($aDbObjects as $oDbObject) {
408 $sSql = "INSERT INTO {$sDbAccessGroupToObject} (
409 group_id,
410 object_id,
411 object_type
412 )
413 VALUES(
414 '{$oDbObject->groupId}',
415 '{$oDbObject->id}',
416 '{$sObjectType}'
417 )";
418
419 $wpdb->query($sSql);
420 }
421 }
422
423 $wpdb->query(
424 "DROP TABLE {$sDbAccessGroupToPost},
425 {$sDbAccessGroupToUser},
426 {$sDbAccessGroupToCategory},
427 {$sDbAccessGroupToRole}"
428 );
429 }
430
431 if (version_compare($sCurrentDbVersion, "1.2", '<=')) {
432 $sDbAccessGroupToObject = $wpdb->prefix.'uam_accessgroup_to_object';
433
434 $sSql = "
435 ALTER TABLE `{$sDbAccessGroupToObject}`
436 CHANGE `object_id` `object_id` VARCHAR(64) NOT NULL,
437 CHANGE `object_type` `object_type` VARCHAR(64) NOT NULL";
438
439 $wpdb->query($sSql);
440 }
441
442 update_option('uam_db_version', $this->_sUamDbVersion);
443 }
444 }
445
446 /**
447 * Clean up wordpress if the plugin will be uninstalled.
448 *
449 * @return null
450 */
451 public function uninstall()
452 {
453 /**
454 * @var wpdb $wpdb
455 */
456 global $wpdb;
457
458 $wpdb->query(
459 "DROP TABLE ".DB_ACCESSGROUP.",
460 ".DB_ACCESSGROUP_TO_OBJECT
461 );
462
463 delete_option($this->_sAdminOptionsName);
464 delete_option('uam_version');
465 delete_option('uam_db_version');
466 $this->deleteHtaccessFiles();
467 }
468
469 /**
470 * Returns the database charset.
471 *
472 * @return string
473 */
474 protected function _getCharset()
475 {
476 global $wpdb;
477 $sCharsetCollate = '';
478
479 $sMySlqVersion = $wpdb->get_var("SELECT VERSION() as mysql_version");
480
481 if (version_compare($sMySlqVersion, '4.1.0', '>=')) {
482 if (!empty($wpdb->charset)) {
483 $sCharsetCollate = "DEFAULT CHARACTER SET $wpdb->charset";
484 }
485
486 if (!empty($wpdb->collate)) {
487 $sCharsetCollate.= " COLLATE $wpdb->collate";
488 }
489 }
490
491 return $sCharsetCollate;
492 }
493
494 /**
495 * Remove the htaccess file if the plugin is deactivated.
496 *
497 * @return null
498 */
499 public function deactivate()
500 {
501 $this->deleteHtaccessFiles();
502 }
503
504 /**
505 * Returns the current user.
506 *
507 * @return WP_User
508 */
509 public function getCurrentUser()
510 {
511 if (!function_exists('get_userdata')) {
512 include_once ABSPATH.'wp-includes/pluggable.php';
513 }
514
515 //Force user information
516 return wp_get_current_user();
517 }
518
519 /**
520 * Returns the full supported mine types.
521 *
522 * @return array
523 */
524 protected function _getMimeTypes()
525 {
526 if ($this->_aMimeTypes === null) {
527 $aMimeTypes = get_allowed_mime_types();
528 $aFullMimeTypes = array();
529
530 foreach ($aMimeTypes as $sExtensions => $sMineType) {
531 $aExtension = explode('|', $sExtensions);
532
533 foreach ($aExtension as $sExtension) {
534 $aFullMimeTypes[$sExtension] = $sMineType;
535 }
536 }
537
538 $this->_aMimeTypes = $aFullMimeTypes;
539 }
540
541 return $this->_aMimeTypes;
542 }
543
544 /**
545 * @param string $sFileTypes The file types which should be cleaned up.
546 *
547 * @return string
548 */
549 protected function _cleanUpFileTypesForHtaccess($sFileTypes)
550 {
551 $aValidFileTypes = array();
552 $aFileTypes = explode(',', $sFileTypes);
553 $aMimeTypes = $this->_getMimeTypes();
554
555 foreach ($aFileTypes as $sFileType) {
556 $sCleanFileType = trim($sFileType);
557
558 if (isset($aMimeTypes[$sCleanFileType])) {
559 $aValidFileTypes[$sCleanFileType] = $sCleanFileType;
560 }
561 }
562
563 return implode('|', $aValidFileTypes);
564 }
565
566 /**
567 * Creates a htaccess file.
568 *
569 * @param string $sDir The destination directory.
570 * @param string $sObjectType The object type.
571 *
572 * @return null.
573 */
574 public function createHtaccess($sDir = null, $sObjectType = null)
575 {
576 if ($sDir === null) {
577 $aWordpressUploadDir = wp_upload_dir();
578
579 if (empty($aWordpressUploadDir['error'])) {
580 $sDir = $aWordpressUploadDir['basedir'] . "/";
581 }
582 }
583
584 if ($sObjectType === null) {
585 $sObjectType = 'attachment';
586 }
587
588 if ($sDir !== null) {
589 if (!$this->isPermalinksActive()) {
590 $sAreaName = "WP-Files";
591 $aUamOptions = $this->getAdminOptions();
592
593 // make .htaccess and .htpasswd
594 $sHtaccessTxt = "";
595
596 if ($aUamOptions['lock_file_types'] == 'selected') {
597 $sFileTypes = $this->_cleanUpFileTypesForHtaccess($aUamOptions['locked_file_types']);
598 $sHtaccessTxt .= "<FilesMatch '\.(".$sFileTypes.")'>\n";
599 } elseif ($aUamOptions['lock_file_types'] == 'not_selected') {
600 $sFileTypes = $this->_cleanUpFileTypesForHtaccess($aUamOptions['not_locked_file_types']);
601 $sHtaccessTxt .= "<FilesMatch '^\.(".$sFileTypes.")'>\n";
602 }
603
604 $sHtaccessTxt .= "AuthType Basic" . "\n";
605 $sHtaccessTxt .= "AuthName \"" . $sAreaName . "\"" . "\n";
606 $sHtaccessTxt .= "AuthUserFile " . $sDir . ".htpasswd" . "\n";
607 $sHtaccessTxt .= "require valid-user" . "\n";
608
609 if ($aUamOptions['lock_file_types'] == 'selected'
610 || $aUamOptions['lock_file_types'] == 'not_selected'
611 ) {
612 $sHtaccessTxt.= "</FilesMatch>\n";
613 }
614 } else {
615 $aHomeRoot = parse_url(home_url());
616 if (isset($aHomeRoot['path'])) {
617 $aHomeRoot = trailingslashit($aHomeRoot['path']);
618 } else {
619 $aHomeRoot = '/';
620 }
621
622 $sHtaccessTxt = "<IfModule mod_rewrite.c>\n";
623 $sHtaccessTxt .= "RewriteEngine On\n";
624 $sHtaccessTxt .= "RewriteBase ".$aHomeRoot."\n";
625 $sHtaccessTxt .= "RewriteRule ^index\.php$ - [L]\n";
626 $sHtaccessTxt .= "RewriteRule (.*) ";
627 $sHtaccessTxt .= $aHomeRoot."index.php?uamfiletype=".$sObjectType."&uamgetfile=$1 [L]\n";
628 $sHtaccessTxt .= "</IfModule>\n";
629 }
630
631 // save files
632 $oFileHandler = fopen($sDir.".htaccess", "w");
633 fwrite($oFileHandler, $sHtaccessTxt);
634 fclose($oFileHandler);
635 }
636 }
637
638 /**
639 * Creates a htpasswd file.
640 *
641 * @param boolean $blCreateNew Force to create new file.
642 * @param string $sDir The destination directory.
643 *
644 * @return null
645 */
646 public function createHtpasswd($blCreateNew = false, $sDir = null)
647 {
648 $oCurrentUser = $this->getCurrentUser();
649 if (!function_exists('get_userdata')) {
650 include_once ABSPATH.'wp-includes/pluggable.php';
651 }
652
653 $aUamOptions = $this->getAdminOptions();
654
655 // get url
656 if ($sDir === null) {
657 $aWordpressUploadDir = wp_upload_dir();
658
659 if (empty($aWordpressUploadDir['error'])) {
660 $sDir = $aWordpressUploadDir['basedir'] . "/";
661 }
662 }
663
664 if ($sDir !== null) {
665 $oUserData = get_userdata($oCurrentUser->ID);
666
667 if (!file_exists($sDir.".htpasswd") || $blCreateNew) {
668 if ($aUamOptions['file_pass_type'] == 'random') {
669 $sPassword = md5($this->getRandomPassword());
670 } else {
671 $sPassword = $oUserData->user_pass;
672 }
673
674 $sUser = $oUserData->user_login;
675
676 // make .htpasswd
677 $sHtpasswdTxt = "$sUser:" . $sPassword . "\n";
678
679 // save file
680 $oFileHandler = fopen($sDir.".htpasswd", "w");
681 fwrite($oFileHandler, $sHtpasswdTxt);
682 fclose($oFileHandler);
683 }
684 }
685 }
686
687 /**
688 * Deletes the htaccess files.
689 *
690 * @param string $sDir The destination directory.
691 *
692 * @return null
693 */
694 public function deleteHtaccessFiles($sDir = null)
695 {
696 if ($sDir === null) {
697 $aWordpressUploadDir = wp_upload_dir();
698
699 if (empty($aWordpressUploadDir['error'])) {
700 $sDir = $aWordpressUploadDir['basedir'] . "/";
701 }
702 }
703
704 if ($sDir !== null) {
705 if (file_exists($sDir.".htaccess")) {
706 unlink($sDir.".htaccess");
707 }
708
709 if (file_exists($sDir.".htpasswd")) {
710 unlink($sDir.".htpasswd");
711 }
712 }
713 }
714
715 /**
716 * Generates and returns a random password.
717 *
718 * @return string
719 */
720 public function getRandomPassword()
721 {
722 //create password
723 $aArray = array();
724 $iLength = 16;
725
726 // numbers
727 for ($i = 48; $i < 58; $i++) {
728 $aArray[] = chr($i);
729 }
730
731 // small
732 for ($i = 97; $i < 122; $i++) {
733 $aArray[] = chr($i);
734 }
735
736 // capitals
737 for ($i = 65; $i < 90; $i++) {
738 $aArray[] = chr($i);
739 }
740
741 mt_srand((double)microtime() * 1000000);
742 $sPassword = '';
743
744 for ($i = 1; $i <= $iLength; $i++) {
745 $iRandomNumber = mt_rand(0, count($aArray) - 1);
746 $sPassword .= $aArray[$iRandomNumber];
747 }
748
749 return $sPassword;
750 }
751
752 /**
753 * Returns the current settings
754 *
755 * @return array
756 */
757 public function getAdminOptions()
758 {
759 if ($this->_aAdminOptions === null) {
760 $aUamAdminOptions = array(
761 'hide_post_title' => 'false',
762 'post_title' => __('No rights!', 'user-access-manager'),
763 'post_content' => __(
764 'Sorry you have no rights to view this post!',
765 'user-access-manager'
766 ),
767 'hide_post' => 'false',
768 'hide_post_comment' => 'false',
769 'post_comment_content' => __(
770 'Sorry no rights to view comments!',
771 'user-access-manager'
772 ),
773 'post_comments_locked' => 'false',
774 'hide_page_title' => 'false',
775 'page_title' => __('No rights!', 'user-access-manager'),
776 'page_content' => __(
777 'Sorry you have no rights to view this page!',
778 'user-access-manager'
779 ),
780 'hide_page' => 'false',
781 'hide_page_comment' => 'false',
782 'page_comment_content' => __(
783 'Sorry no rights to view comments!',
784 'user-access-manager'
785 ),
786 'page_comments_locked' => 'false',
787 'redirect' => 'false',
788 'redirect_custom_page' => '',
789 'redirect_custom_url' => '',
790 'lock_recursive' => 'true',
791 'authors_has_access_to_own' => 'true',
792 'authors_can_add_posts_to_groups' => 'false',
793 'lock_file' => 'false',
794 'file_pass_type' => 'random',
795 'lock_file_types' => 'all',
796 'download_type' => 'fopen',
797 'locked_file_types' => 'zip,rar,tar,gz',
798 'not_locked_file_types' => 'gif,jpg,jpeg,png',
799 'blog_admin_hint' => 'true',
800 'blog_admin_hint_text' => '[L]',
801 'hide_empty_categories' => 'true',
802 'protect_feed' => 'true',
803 'show_post_content_before_more' => 'false',
804 'full_access_role' => 'administrator'
805 );
806
807 $aUamOptions = $this->getWpOption($this->_sAdminOptionsName);
808
809 if (!empty($aUamOptions)) {
810 foreach ($aUamOptions as $sKey => $mOption) {
811 $aUamAdminOptions[$sKey] = $mOption;
812 }
813 }
814
815 update_option($this->_sAdminOptionsName, $aUamAdminOptions);
816 $this->_aAdminOptions = $aUamAdminOptions;
817 }
818
819 return $this->_aAdminOptions;
820 }
821
822 /**
823 * Returns the content of the excluded php file.
824 *
825 * @param string $sFileName The file name
826 * @param integer $iObjectId The _iId if needed.
827 * @param string $sObjectType The object type if needed.
828 *
829 * @return string
830 */
831 public function getIncludeContents($sFileName, $iObjectId = null, $sObjectType = null)
832 {
833 if (is_file($sFileName)) {
834 ob_start();
835 include $sFileName;
836 $sContents = ob_get_contents();
837 ob_end_clean();
838
839 return $sContents;
840 }
841
842 return '';
843 }
844
845 /**
846 * Returns the access handler object.
847 *
848 * @return UamAccessHandler
849 */
850 public function &getAccessHandler()
851 {
852 if ($this->_oAccessHandler == null) {
853 $this->_oAccessHandler = new UamAccessHandler($this);
854 }
855
856 return $this->_oAccessHandler;
857 }
858
859 /**
860 * Returns the current version of the user access manager.
861 *
862 * @return string
863 */
864 public function getVersion()
865 {
866 return $this->_sUamVersion;
867 }
868
869 /**
870 * Returns true if a user is at the admin panel.
871 *
872 * @return boolean
873 */
874 public function atAdminPanel()
875 {
876 return $this->_blAtAdminPanel;
877 }
878
879 /**
880 * Sets the atAdminPanel var to true.
881 *
882 * @return null
883 */
884 public function setAtAdminPanel()
885 {
886 $this->_blAtAdminPanel = true;
887 }
888
889
890 /*
891 * Helper functions.
892 */
893
894 /**
895 * Checks if a string starts with the given needle.
896 *
897 * @param string $sHaystack The haystack.
898 * @param string $sNeedle The needle.
899 *
900 * @return boolean
901 */
902 public function startsWith($sHaystack, $sNeedle)
903 {
904 return strpos($sHaystack, $sNeedle) === 0;
905 }
906
907
908 /*
909 * Functions for the admin panel content.
910 */
911
912 /**
913 * The function for the wp_print_styles action.
914 *
915 * @return null
916 */
917 public function addStyles()
918 {
919 wp_enqueue_style(
920 'UserAccessManagerAdmin',
921 UAM_URLPATH . "css/uamAdmin.css",
922 array() ,
923 '1.0',
924 'screen'
925 );
926
927 wp_enqueue_style(
928 'UserAccessManagerLoginForm',
929 UAM_URLPATH . "css/uamLoginForm.css",
930 array() ,
931 '1.0',
932 'screen'
933 );
934 }
935
936 /**
937 * The function for the wp_print_scripts action.
938 *
939 * @return null
940 */
941 public function addScripts()
942 {
943 wp_enqueue_script(
944 'UserAccessManagerFunctions',
945 UAM_URLPATH . 'js/functions.js',
946 array('jquery')
947 );
948 }
949
950 /**
951 * Prints the admin page.
952 *
953 * @return null
954 */
955 public function printAdminPage()
956 {
957 if (isset($_GET['page'])) {
958 $sAdminPage = $_GET['page'];
959
960 if ($sAdminPage == 'uam_settings') {
961 include UAM_REALPATH."tpl/adminSettings.php";
962 } elseif ($sAdminPage == 'uam_usergroup') {
963 include UAM_REALPATH."tpl/adminGroup.php";
964 } elseif ($sAdminPage == 'uam_setup') {
965 include UAM_REALPATH."tpl/adminSetup.php";
966 } elseif ($sAdminPage == 'uam_about') {
967 include UAM_REALPATH."tpl/about.php";
968 }
969 }
970 }
971
972 /**
973 * Shows the error if the user has no rights to edit the content.
974 *
975 * @return null
976 */
977 public function noRightsToEditContent()
978 {
979 $blNoRights = false;
980
981 if (isset($_GET['post']) && is_numeric($_GET['post'])) {
982 $oPost = $this->getPost($_GET['post']);
983 $blNoRights = !$this->getAccessHandler()->checkObjectAccess( $oPost->post_type, $oPost->ID );
984 }
985
986 if (isset($_GET['attachment_id']) && is_numeric($_GET['attachment_id']) && !$blNoRights) {
987 $oPost = $this->getPost($_GET['attachment_id']);
988 $blNoRights = !$this->getAccessHandler()->checkObjectAccess($oPost->post_type, $oPost->ID);
989 }
990
991 if (isset($_GET['tag_ID']) && is_numeric($_GET['tag_ID']) && !$blNoRights) {
992 $blNoRights = !$this->getAccessHandler()->checkObjectAccess('category', $_GET['tag_ID']);
993 }
994
995 if ($blNoRights) {
996 wp_die(TXT_UAM_NO_RIGHTS);
997 }
998 }
999
1000 /**
1001 * The function for the wp_dashboard_setup action.
1002 * Removes widgets to which a user should not have access.
1003 *
1004 * @return null
1005 */
1006 public function setupAdminDashboard()
1007 {
1008 global $wp_meta_boxes;
1009
1010 if (!$this->getAccessHandler()->checkUserAccess('manage_user_groups')) {
1011 unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
1012 }
1013 }
1014
1015 /**
1016 * The function for the update_option_permalink_structure action.
1017 *
1018 * @return null
1019 */
1020 public function updatePermalink()
1021 {
1022 $this->createHtaccess();
1023 $this->createHtpasswd();
1024 }
1025
1026
1027 /*
1028 * Meta functions
1029 */
1030
1031 /**
1032 * Saves the object data to the database.
1033 *
1034 * @param string $sObjectType The object type.
1035 * @param integer $iObjectId The _iId of the object.
1036 * @param array $aUserGroups The new usergroups for the object.
1037 *
1038 * @return null
1039 */
1040 protected function _saveObjectData($sObjectType, $iObjectId, $aUserGroups = null)
1041 {
1042 $oUamAccessHandler = $this->getAccessHandler();
1043 $oUamOptions = $this->getAdminOptions();
1044 $aFormData = array();
1045
1046 if (isset($_POST['uam_update_groups'])) {
1047 $aFormData = $_POST;
1048 } elseif (isset($_GET['uam_update_groups'])) {
1049 $aFormData = $_GET;
1050 }
1051
1052 if (isset($aFormData['uam_update_groups'])
1053 && ($oUamAccessHandler->checkUserAccess('manage_user_groups')
1054 || $oUamOptions['authors_can_add_posts_to_groups'] == 'true')
1055 ) {
1056 if ($aUserGroups === null) {
1057 $aUserGroups = (isset($aFormData['uam_usergroups']) && is_array($aFormData['uam_usergroups']))
1058 ? $aFormData['uam_usergroups'] : array();
1059 }
1060
1061 $aAddUserGroups = array_flip($aUserGroups);
1062 $aRemoveUserGroups = $oUamAccessHandler->getUserGroupsForObject($sObjectType, $iObjectId);
1063 $aUamUserGroups = $oUamAccessHandler->getUserGroups();
1064 $blRemoveOldAssignments = true;
1065
1066 if (isset($aFormData['uam_bulk_type'])) {
1067 $sBulkType = $aFormData['uam_bulk_type'];
1068
1069 if ($sBulkType === 'add') {
1070 $blRemoveOldAssignments = false;
1071 } elseif ($sBulkType === 'remove') {
1072 $aRemoveUserGroups = $aAddUserGroups;
1073 $aAddUserGroups = array();
1074 }
1075 }
1076
1077 foreach ($aUamUserGroups as $sGroupId => $oUamUserGroup) {
1078 if (isset($aRemoveUserGroups[$sGroupId])) {
1079 $oUamUserGroup->removeObject($sObjectType, $iObjectId);
1080 }
1081
1082 if (isset($aAddUserGroups[$sGroupId])) {
1083 $oUamUserGroup->addObject($sObjectType, $iObjectId);
1084 }
1085
1086 $oUamUserGroup->save($blRemoveOldAssignments);
1087 }
1088 }
1089 }
1090
1091
1092 /*
1093 * Functions for the post actions.
1094 */
1095
1096 /**
1097 * The function for the manage_posts_columns and
1098 * the manage_pages_columns filter.
1099 *
1100 * @param array $aDefaults The table headers.
1101 *
1102 * @return array
1103 */
1104 public function addPostColumnsHeader($aDefaults)
1105 {
1106 $aDefaults['uam_access'] = __('Access', 'user-access-manager');
1107 return $aDefaults;
1108 }
1109
1110 /**
1111 * The function for the manage_users_custom_column action.
1112 *
1113 * @param string $sColumnName The column name.
1114 * @param integer $iId The _iId.
1115 *
1116 * @return string
1117 */
1118 public function addPostColumn($sColumnName, $iId)
1119 {
1120 if ($sColumnName == 'uam_access') {
1121 $oPost = $this->getPost($iId);
1122 echo $this->getIncludeContents(UAM_REALPATH.'tpl/objectColumn.php', $oPost->ID, $oPost->post_type);
1123 }
1124 }
1125
1126 /**
1127 * The function for the uma_post_access metabox.
1128 *
1129 * @param object $oPost The post.
1130 *
1131 * @return null;
1132 */
1133 public function editPostContent($oPost)
1134 {
1135 $iObjectId = $oPost->ID;
1136 include UAM_REALPATH.'tpl/postEditForm.php';
1137 }
1138
1139 public function addBulkAction($sColumnName)
1140 {
1141 if ($sColumnName == 'uam_access') {
1142 include UAM_REALPATH.'tpl/bulkEditForm.php';
1143 }
1144 }
1145
1146 /**
1147 * The function for the save_post action.
1148 *
1149 * @param mixed $mPostParam The post _iId or a array of a post.
1150 *
1151 * @return null
1152 */
1153 public function savePostData($mPostParam)
1154 {
1155 if (is_array($mPostParam)) {
1156 $oPost = $this->getPost($mPostParam['ID']);
1157 } else {
1158 $oPost = $this->getPost($mPostParam);
1159 }
1160
1161 $iPostId = $oPost->ID;
1162 $sPostType = $oPost->post_type;
1163
1164 if ($sPostType == 'revision') {
1165 $iPostId = $oPost->post_parent;
1166 $oParentPost = $this->getPost($iPostId);
1167 $sPostType = $oParentPost->post_type;
1168 }
1169
1170 $this->_saveObjectData($sPostType, $iPostId);
1171 }
1172
1173 /**
1174 * The function for the attachment_fields_to_save filter.
1175 * We have to use this because the attachment actions work
1176 * not in the way we need.
1177 *
1178 * @param object $oAttachment The attachment _iId.
1179 *
1180 * @return object
1181 */
1182 public function saveAttachmentData($oAttachment)
1183 {
1184 $this->savePostData($oAttachment['ID']);
1185
1186 return $oAttachment;
1187 }
1188
1189 /**
1190 * The function for the delete_post action.
1191 *
1192 * @param integer $iPostId The post _iId.
1193 *
1194 * @return null
1195 */
1196 public function removePostData($iPostId)
1197 {
1198 /**
1199 * @var wpdb $wpdb
1200 */
1201 global $wpdb;
1202 $oPost = $this->getPost($iPostId);
1203
1204 $wpdb->query(
1205 "DELETE FROM " . DB_ACCESSGROUP_TO_OBJECT . "
1206 WHERE object_id = '".$iPostId."'
1207 AND object_type = '".$oPost->post_type."'"
1208 );
1209 }
1210
1211 /**
1212 * The function for the media_meta action.
1213 *
1214 * @param string $sMeta The meta.
1215 * @param object $oPost The post.
1216 *
1217 * @return string
1218 */
1219 public function showMediaFile($sMeta = '', $oPost = null)
1220 {
1221 $sContent = $sMeta;
1222 $sContent .= '</td></tr><tr>';
1223 $sContent .= '<th class="label">';
1224 $sContent .= '<label>'.TXT_UAM_SET_UP_USERGROUPS.'</label>';
1225 $sContent .= '</th>';
1226 $sContent .= '<td class="field">';
1227 $sContent .= $this->getIncludeContents(UAM_REALPATH.'tpl/postEditForm.php', $oPost->ID);
1228
1229 return $sContent;
1230 }
1231
1232
1233 /*
1234 * Functions for the user actions.
1235 */
1236
1237 /**
1238 * The function for the manage_users_columns filter.
1239 *
1240 * @param array $aDefaults The table headers.
1241 *
1242 * @return array
1243 */
1244 public function addUserColumnsHeader($aDefaults)
1245 {
1246 $aDefaults['uam_access'] = __('uam user groups');
1247 return $aDefaults;
1248 }
1249
1250 /**
1251 * The function for the manage_users_custom_column action.
1252 *
1253 * @param string $sReturn The normal return value.
1254 * @param string $sColumnName The column name.
1255 * @param integer $iId The _iId.
1256 *
1257 * @return string|null
1258 */
1259 public function addUserColumn($sReturn, $sColumnName, $iId)
1260 {
1261 if ($sColumnName == 'uam_access') {
1262 return $this->getIncludeContents(UAM_REALPATH.'tpl/userColumn.php', $iId, 'user');
1263 }
1264
1265 return $sReturn;
1266 }
1267
1268 /**
1269 * The function for the edit_user_profile action.
1270 *
1271 * @return null
1272 */
1273 public function showUserProfile()
1274 {
1275 echo $this->getIncludeContents(UAM_REALPATH.'tpl/userProfileEditForm.php');
1276 }
1277
1278 /**
1279 * The function for the profile_update action.
1280 *
1281 * @param integer $iUserId The user _iId.
1282 *
1283 * @return null
1284 */
1285 public function saveUserData($iUserId)
1286 {
1287 $this->_saveObjectData('user', $iUserId);
1288 }
1289
1290 /**
1291 * The function for the delete_user action.
1292 *
1293 * @param integer $iUserId The user _iId.
1294 *
1295 * @return null
1296 */
1297 public function removeUserData($iUserId)
1298 {
1299 /**
1300 * @var wpdb $wpdb
1301 */
1302 global $wpdb;
1303
1304 $wpdb->query(
1305 "DELETE FROM " . DB_ACCESSGROUP_TO_OBJECT . "
1306 WHERE object_id = ".$iUserId."
1307 AND object_type = 'user'"
1308 );
1309 }
1310
1311
1312 /*
1313 * Functions for the category actions.
1314 */
1315
1316 /**
1317 * The function for the manage_categories_columns filter.
1318 *
1319 * @param array $aDefaults The table headers.
1320 *
1321 * @return array
1322 */
1323 public function addCategoryColumnsHeader($aDefaults)
1324 {
1325 $aDefaults['uam_access'] = __('Access', 'user-access-manager');
1326 return $aDefaults;
1327 }
1328
1329 /**
1330 * The function for the manage_categories_custom_column action.
1331 *
1332 * @param string $sEmpty An empty string from wordpress? What the hell?!?
1333 * @param string $sColumnName The column name.
1334 * @param integer $iId The _iId.
1335 *
1336 * @return string|null
1337 */
1338 public function addCategoryColumn($sEmpty, $sColumnName, $iId)
1339 {
1340 if ($sColumnName == 'uam_access') {
1341 return $this->getIncludeContents(UAM_REALPATH.'tpl/objectColumn.php', $iId, 'category');
1342 }
1343
1344 return null;
1345 }
1346
1347 /**
1348 * The function for the edit_category_form action.
1349 *
1350 * @param object $oCategory The category.
1351 *
1352 * @return null
1353 */
1354 public function showCategoryEditForm($oCategory)
1355 {
1356 include UAM_REALPATH.'tpl/categoryEditForm.php';
1357 }
1358
1359 /**
1360 * The function for the edit_category action.
1361 *
1362 * @param integer $iCategoryId The category _iId.
1363 *
1364 * @return null
1365 */
1366 public function saveCategoryData($iCategoryId)
1367 {
1368 $this->_saveObjectData('category', $iCategoryId);
1369 }
1370
1371 /**
1372 * The function for the delete_category action.
1373 *
1374 * @param integer $iCategoryId The _iId of the category.
1375 *
1376 * @return null
1377 */
1378 public function removeCategoryData($iCategoryId)
1379 {
1380 /**
1381 * @var wpdb $wpdb
1382 */
1383 global $wpdb;
1384
1385 $wpdb->query(
1386 "DELETE FROM " . DB_ACCESSGROUP_TO_OBJECT . "
1387 WHERE object_id = ".$iCategoryId."
1388 AND object_type = 'category'"
1389 );
1390 }
1391
1392
1393 /*
1394 * Functions for the pluggable object actions.
1395 */
1396
1397 /**
1398 * The function for the pluggable save action.
1399 *
1400 * @param string $sObjectType The name of the pluggable object.
1401 * @param integer $iObjectId The pluggable object _iId.
1402 * @param array $aUserGroups The user groups for the object.
1403 *
1404 * @return null
1405 */
1406 public function savePlObjectData($sObjectType, $iObjectId, $aUserGroups = null)
1407 {
1408 $this->_saveObjectData($sObjectType, $iObjectId, $aUserGroups);
1409 }
1410
1411 /**
1412 * The function for the pluggable remove action.
1413 *
1414 * @param string $sObjectName The name of the pluggable object.
1415 * @param integer $iObjectId The pluggable object _iId.
1416 *
1417 * @return null
1418 */
1419 public function removePlObjectData($sObjectName, $iObjectId)
1420 {
1421 /**
1422 * @var wpdb $wpdb
1423 */
1424 global $wpdb;
1425
1426 $wpdb->query(
1427 "DELETE FROM " . DB_ACCESSGROUP_TO_OBJECT . "
1428 WHERE object_id = ".$iObjectId."
1429 AND object_type = ".$sObjectName
1430 );
1431 }
1432
1433 /**
1434 * Returns the group selection form for pluggable _aObjects.
1435 *
1436 * @param string $sObjectType The object type.
1437 * @param integer $iObjectId The _iId of the object.
1438 * @param string $aGroupsFormName The name of the form which contains the groups.
1439 *
1440 * @return string;
1441 */
1442 public function showPlGroupSelectionForm($sObjectType, $iObjectId, $aGroupsFormName = null)
1443 {
1444 $sFileName = UAM_REALPATH.'tpl/groupSelectionForm.php';
1445 $aUamUserGroups = $this->getAccessHandler()->getUserGroups();
1446 $aUserGroupsForObject = $this->getAccessHandler()->getUserGroupsForObject($sObjectType, $iObjectId);
1447
1448 if (is_file($sFileName)) {
1449 ob_start();
1450 include $sFileName;
1451 $sContents = ob_get_contents();
1452 ob_end_clean();
1453
1454 return $sContents;
1455 }
1456
1457 return '';
1458 }
1459
1460 /**
1461 * Returns the column for a pluggable object.
1462 *
1463 * @param string $sObjectType The object type.
1464 * @param integer $iObjectId The object _iId.
1465 *
1466 * @return string
1467 */
1468 public function getPlColumn($sObjectType, $iObjectId)
1469 {
1470 return $this->getIncludeContents(UAM_REALPATH.'tpl/objectColumn.php', $iObjectId, $sObjectType);
1471 }
1472
1473
1474 /*
1475 * Functions for the blog content.
1476 */
1477
1478 /**
1479 * Manipulates the wordpress query object to filter content.
1480 *
1481 * @param object $oWpQuery The wordpress query object.
1482 *
1483 * @return null
1484 */
1485 public function parseQuery($oWpQuery)
1486 {
1487 $aUamOptions = $this->getAdminOptions();
1488
1489 if ($aUamOptions['hide_post'] == 'true') {
1490 $oUamAccessHandler = $this->getAccessHandler();
1491 $aExcludedPosts = $oUamAccessHandler->getExcludedPosts();
1492
1493 if (count($aExcludedPosts) > 0) {
1494 $oWpQuery->query_vars['post__not_in'] = array_merge(
1495 $oWpQuery->query_vars['post__not_in'],
1496 $aExcludedPosts
1497 );
1498 }
1499 }
1500 }
1501
1502 /**
1503 * Modifies the content of the post by the given settings.
1504 *
1505 * @param object $oPost The current post.
1506 *
1507 * @return object|null
1508 */
1509 protected function _getPost($oPost)
1510 {
1511 $aUamOptions = $this->getAdminOptions();
1512 $oUamAccessHandler = $this->getAccessHandler();
1513
1514 $sPostType = $oPost->post_type;
1515
1516 if ($this->getAccessHandler()->isPostableType($sPostType) && $sPostType != 'post' && $sPostType != 'page') {
1517 $sPostType = 'post';
1518 } elseif ($sPostType != 'post' && $sPostType != 'page') {
1519 return $oPost;
1520 }
1521
1522 if ($aUamOptions['hide_'.$sPostType] == 'true' || $this->atAdminPanel()) {
1523 if ($oUamAccessHandler->checkObjectAccess($oPost->post_type, $oPost->ID)) {
1524 $oPost->post_title .= $this->adminOutput($oPost->post_type, $oPost->ID);
1525 return $oPost;
1526 }
1527 } else {
1528 if (!$oUamAccessHandler->checkObjectAccess($oPost->post_type, $oPost->ID)) {
1529 $oPost->isLocked = true;
1530
1531 $sUamPostContent = $aUamOptions[$sPostType.'_content'];
1532 $sUamPostContent = str_replace("[LOGIN_FORM]", $this->getLoginBarHtml(), $sUamPostContent);
1533
1534 if ($aUamOptions['hide_'.$sPostType.'_title'] == 'true') {
1535 $oPost->post_title = $aUamOptions[$sPostType.'_title'];
1536 }
1537
1538 if ($aUamOptions[$sPostType.'_comments_locked'] == 'false') {
1539 $oPost->comment_status = 'close';
1540 }
1541
1542 if ($aUamOptions['show_post_content_before_more'] == 'true'
1543 && $sPostType == "post"
1544 && preg_match('/<!--more(.*?)?-->/', $oPost->post_content, $aMatches)
1545 ) {
1546 $oPost->post_content = explode($aMatches[0], $oPost->post_content, 2);
1547 $sUamPostContent = $oPost->post_content[0] . " " . $sUamPostContent;
1548 }
1549
1550 $oPost->post_content = stripslashes($sUamPostContent);
1551 }
1552
1553 $oPost->post_title .= $this->adminOutput($oPost->post_type, $oPost->ID);
1554
1555 return $oPost;
1556 }
1557
1558 return null;
1559 }
1560
1561 /**
1562 * The function for the the_posts filter.
1563 *
1564 * @param array $aPosts The posts.
1565 *
1566 * @return array
1567 */
1568 public function showPost($aPosts = array())
1569 {
1570 $aShowPosts = array();
1571 $aUamOptions = $this->getAdminOptions();
1572
1573 if (!is_feed() || ($aUamOptions['protect_feed'] == 'true' && is_feed())) {
1574 foreach ($aPosts as $iPostId) {
1575 if ($iPostId !== null) {
1576 $oPost = $this->_getPost($iPostId);
1577
1578 if ($oPost !== null) {
1579 $aShowPosts[] = $oPost;
1580 }
1581 }
1582 }
1583
1584 $aPosts = $aShowPosts;
1585 }
1586
1587 return $aPosts;
1588 }
1589
1590 /**
1591 * The function for the posts_where_paged filter.
1592 *
1593 * @param string $sSql The where sql statement.
1594 *
1595 * @return string
1596 */
1597 public function showPostSql($sSql)
1598 {
1599 $oUamAccessHandler = $this->getAccessHandler();
1600 $aUamOptions = $this->getAdminOptions();
1601
1602 if ($aUamOptions['hide_post'] == 'true') {
1603 global $wpdb;
1604 $aExcludedPosts = $oUamAccessHandler->getExcludedPosts();
1605
1606 if (count($aExcludedPosts) > 0) {
1607 $sExcludedPostsStr = implode(",", $aExcludedPosts);
1608 $sSql .= " AND $wpdb->posts.ID NOT IN($sExcludedPostsStr) ";
1609 }
1610 }
1611
1612 return $sSql;
1613 }
1614
1615 /**
1616 * The function for the wp_get_nav_menu_items filter.
1617 *
1618 * @param array $aItems The menu item.
1619 *
1620 * @return array
1621 */
1622 public function showCustomMenu($aItems)
1623 {
1624 $aShowItems = array();
1625
1626 foreach ($aItems as $oItem) {
1627 if ($oItem->object == 'post' || $oItem->object == 'page') {
1628 $oObject = $this->getPost($oItem->object_id);
1629
1630 if ($oObject !== null) {
1631 $oPost = $this->_getPost($oObject);
1632
1633 if ($oPost !== null) {
1634 if (isset($oPost->isLocked)) {
1635 $oItem->title = $oPost->post_title;
1636 }
1637
1638 $oItem->title .= $this->adminOutput($oItem->object, $oItem->object_id);
1639 $aShowItems[] = $oItem;
1640 }
1641 }
1642 } elseif ($oItem->object == 'category') {
1643 $oObject = $this->getCategory($oItem->object_id);
1644 $oCategory = $this->_getTerm('category', $oObject);
1645
1646 if ($oCategory !== null && !$oCategory->isEmpty) {
1647 $oItem->title .= $this->adminOutput($oItem->object, $oItem->object_id);
1648 $aShowItems[] = $oItem;
1649 }
1650 } else {
1651 $aShowItems[] = $oItem;
1652 }
1653 }
1654
1655 return $aShowItems;
1656 }
1657
1658 /**
1659 * The function for the comments_array filter.
1660 *
1661 * @param array $aComments The comments.
1662 *
1663 * @return array
1664 */
1665 public function showComment($aComments = array())
1666 {
1667 $aShowComments = array();
1668 $aUamOptions = $this->getAdminOptions();
1669 $oUamAccessHandler = $this->getAccessHandler();
1670
1671 foreach ($aComments as $oComment) {
1672 $oPost = $this->getPost($oComment->comment_post_ID);
1673 $sPostType = $oPost->post_type;
1674
1675 if ($aUamOptions['hide_'.$sPostType.'_comment'] == 'true'
1676 || $aUamOptions['hide_'.$sPostType] == 'true'
1677 || $this->atAdminPanel()
1678 ) {
1679 if ($oUamAccessHandler->checkObjectAccess($oPost->post_type, $oPost->ID)) {
1680 $aShowComments[] = $oComment;
1681 }
1682 } else {
1683 if (!$oUamAccessHandler->checkObjectAccess($oPost->post_type, $oPost->ID)) {
1684 $oComment->comment_content = $aUamOptions[$sPostType.'_comment_content'];
1685 }
1686
1687 $aShowComments[] = $oComment;
1688 }
1689 }
1690
1691 $aComments = $aShowComments;
1692
1693 return $aComments;
1694 }
1695
1696 /**
1697 * The function for the get_pages filter.
1698 *
1699 * @param array $aPages The pages.
1700 *
1701 * @return array
1702 */
1703 public function showPage($aPages = array())
1704 {
1705 $aShowPages = array();
1706 $aUamOptions = $this->getAdminOptions();
1707 $oUamAccessHandler = $this->getAccessHandler();
1708
1709 foreach ($aPages as $oPage) {
1710 if ($aUamOptions['hide_page'] == 'true'
1711 || $this->atAdminPanel()
1712 ) {
1713 if ($oUamAccessHandler->checkObjectAccess($oPage->post_type, $oPage->ID)) {
1714 $oPage->post_title .= $this->adminOutput(
1715 $oPage->post_type,
1716 $oPage->ID
1717 );
1718 $aShowPages[] = $oPage;
1719 }
1720 } else {
1721 if (!$oUamAccessHandler->checkObjectAccess($oPage->post_type, $oPage->ID)) {
1722 if ($aUamOptions['hide_page_title'] == 'true') {
1723 $oPage->post_title = $aUamOptions['page_title'];
1724 }
1725
1726 $oPage->post_content = $aUamOptions['page_content'];
1727 }
1728
1729 $oPage->post_title .= $this->adminOutput($oPage->post_type, $oPage->ID);
1730 $aShowPages[] = $oPage;
1731 }
1732 }
1733
1734 $aPages = $aShowPages;
1735
1736 return $aPages;
1737 }
1738
1739 /**
1740 * Modifies the content of the term by the given settings.
1741 *
1742 * @param string $sTermType The type of the term.
1743 * @param object $oTerm The current term.
1744 *
1745 * @return object|null
1746 */
1747 protected function _getTerm($sTermType, $oTerm)
1748 {
1749 $aUamOptions = $this->getAdminOptions();
1750 $oUamAccessHandler = $this->getAccessHandler();
1751
1752 $oTerm->isEmpty = false;
1753
1754 $oTerm->name .= $this->adminOutput('term', $oTerm->term_id);
1755
1756 if ($sTermType == 'post_tag'
1757 || ( $sTermType == 'category' || $sTermType == $oTerm->taxonomy)
1758 && $oUamAccessHandler->checkObjectAccess('category', $oTerm->term_id)
1759 ) {
1760 if ($this->atAdminPanel() == false
1761 && ($aUamOptions['hide_post'] == 'true'
1762 || $aUamOptions['hide_page'] == 'true')
1763 ) {
1764 $iTermRequest = $oTerm->term_id;
1765 $sTermRequestType = $sTermType;
1766
1767 if ($sTermType == 'post_tag') {
1768 $iTermRequest = $oTerm->slug;
1769 $sTermRequestType = 'tag';
1770 }
1771
1772 $aArgs = array(
1773 'numberposts' => - 1,
1774 $sTermRequestType => $iTermRequest
1775 );
1776
1777 $aTermPosts = get_posts($aArgs);
1778 $oTerm->count = count($aTermPosts);
1779
1780 if (isset($aTermPosts)) {
1781 foreach ($aTermPosts as $oPost) {
1782 if ($aUamOptions['hide_'.$oPost->post_type] == 'true'
1783 && !$oUamAccessHandler->checkObjectAccess($oPost->post_type, $oPost->ID)
1784 ) {
1785 $oTerm->count--;
1786 }
1787 }
1788 }
1789
1790 //For post_tags
1791 if ($sTermType == 'post_tag' && $oTerm->count <= 0) {
1792 return null;
1793 }
1794
1795 //For categories
1796 if ($oTerm->count <= 0
1797 && $aUamOptions['hide_empty_categories'] == 'true'
1798 && ($oTerm->taxonomy == "term"
1799 || $oTerm->taxonomy == "category")
1800 ) {
1801 $oTerm->isEmpty = true;
1802 }
1803
1804 if ($aUamOptions['lock_recursive'] == 'false') {
1805 $oCurCategory = $oTerm;
1806
1807 while ($oCurCategory->parent != 0) {
1808 $oCurCategory = get_term($oCurCategory->parent, 'category');
1809
1810 if ($oUamAccessHandler->checkObjectAccess('term', $oCurCategory->term_id)) {
1811 $oTerm->parent = $oCurCategory->term_id;
1812 break;
1813 }
1814 }
1815 }
1816 }
1817
1818 return $oTerm;
1819 }
1820
1821 return null;
1822 }
1823
1824 /**
1825 * The function for the get_terms filter.
1826 *
1827 * @param array $aTerms The terms.
1828 * @param array $aArgs The given arguments.
1829 *
1830 * @return array
1831 */
1832 public function showTerms($aTerms = array(), $aArgs = array())
1833 {
1834 $aShowTerms = array();
1835
1836 foreach ($aTerms as $oTerm) {
1837 if (!is_object($oTerm)) {
1838 return $aTerms;
1839 }
1840
1841 if ($oTerm->taxonomy == 'category' || $oTerm->taxonomy == 'post_tag') {
1842 $oTerm = $this->_getTerm($oTerm->taxonomy, $oTerm);
1843 }
1844
1845 if ($oTerm !== null && (!isset($oTerm->isEmpty) || !$oTerm->isEmpty)) {
1846 $aShowTerms[$oTerm->term_id] = $oTerm;
1847 }
1848 }
1849
1850 foreach ($aTerms as $sKey => $oTerm) {
1851 if (!isset($aShowTerms[$oTerm->term_id])) {
1852 unset($aTerms[$sKey]);
1853 }
1854 }
1855
1856 return $aTerms;
1857 }
1858
1859 /**
1860 * The function for the get_previous_post_where and
1861 * the get_next_post_where filter.
1862 *
1863 * @param string $sSql The current sql string.
1864 *
1865 * @return string
1866 */
1867 public function showNextPreviousPost($sSql)
1868 {
1869 $oUamAccessHandler = $this->getAccessHandler();
1870 $aUamOptions = $this->getAdminOptions();
1871
1872 if ($aUamOptions['hide_post'] == 'true') {
1873 $aExcludedPosts = $oUamAccessHandler->getExcludedPosts();
1874
1875 if (count($aExcludedPosts) > 0) {
1876 $sExcludedPosts = implode(",", $aExcludedPosts);
1877 $sSql.= " AND p.ID NOT IN($sExcludedPosts) ";
1878 }
1879 }
1880
1881 return $sSql;
1882 }
1883
1884 /**
1885 * Returns the admin hint.
1886 *
1887 * @param string $sObjectType The object type.
1888 * @param integer $iObjectId The object _iId we want to check.
1889 *
1890 * @return string
1891 */
1892 public function adminOutput($sObjectType, $iObjectId)
1893 {
1894 $sOutput = "";
1895
1896 if (!$this->atAdminPanel()) {
1897 $aUamOptions = $this->getAdminOptions();
1898
1899 if ($aUamOptions['blog_admin_hint'] == 'true') {
1900 $oCurrentUser = $this->getCurrentUser();
1901
1902 $oUserData = get_userdata($oCurrentUser->ID);
1903
1904 if (!isset($oUserData->user_level)) {
1905 return $sOutput;
1906 }
1907
1908 $oUamAccessHandler = $this->getAccessHandler();
1909
1910 if ($oUamAccessHandler->userIsAdmin($oCurrentUser->ID)
1911 && count($oUamAccessHandler->getUserGroupsForObject($sObjectType, $iObjectId)) > 0
1912 ) {
1913 $sOutput .= $aUamOptions['blog_admin_hint_text'];
1914 }
1915 }
1916 }
1917
1918 return $sOutput;
1919 }
1920
1921 /**
1922 * The function for the edit_post_link filter.
1923 *
1924 * @param string $sLink The edit link.
1925 * @param integer $iPostId The _iId of the post.
1926 *
1927 * @return string
1928 */
1929 public function showGroupMembership($sLink, $iPostId)
1930 {
1931 $oUamAccessHandler = $this->getAccessHandler();
1932 $aGroups = $oUamAccessHandler->getUserGroupsForObject('post', $iPostId);
1933
1934 if (count($aGroups) > 0) {
1935 $sLink .= ' | '.TXT_UAM_ASSIGNED_GROUPS.': ';
1936
1937 foreach ($aGroups as $oGroup) {
1938 $sLink .= htmlentities($oGroup->getGroupName()).', ';
1939 }
1940
1941 $sLink = rtrim($sLink, ', ');
1942 }
1943
1944 return $sLink;
1945 }
1946
1947 /**
1948 * Returns the login bar.
1949 *
1950 * @return string
1951 */
1952 public function getLoginBarHtml()
1953 {
1954 if (!is_user_logged_in()) {
1955 return $this->getIncludeContents(UAM_REALPATH.'tpl/loginBar.php');
1956 }
1957
1958 return '';
1959 }
1960
1961
1962 /*
1963 * Functions for the redirection and files.
1964 */
1965
1966 /**
1967 * Returns true if permalinks are active otherwise false.
1968 *
1969 * @return boolean
1970 */
1971 public function isPermalinksActive()
1972 {
1973 $sPermalinkStructure = $this->getWpOption('permalink_structure');
1974
1975 if (empty($sPermalinkStructure)) {
1976 return false;
1977 } else {
1978 return true;
1979 }
1980 }
1981
1982 /**
1983 * Redirects to a page or to content.
1984 *
1985 * @param string $sHeaders The headers which are given from wordpress.
1986 * @param object $oPageParams The params of the current page.
1987 *
1988 * @return string
1989 */
1990 public function redirect($sHeaders, $oPageParams)
1991 {
1992 $oUamOptions = $this->getAdminOptions();
1993
1994 if (isset($_GET['uamgetfile']) && isset($_GET['uamfiletype'])) {
1995 $sFileUrl = $_GET['uamgetfile'];
1996 $sFileType = $_GET['uamfiletype'];
1997 $this->getFile($sFileType, $sFileUrl);
1998 } elseif (!$this->atAdminPanel() && $oUamOptions['redirect'] !== 'false') {
1999 $oObject = null;
2000
2001 if (isset($oPageParams->query_vars['p'])) {
2002 $oObject = $this->getPost($oPageParams->query_vars['p']);
2003 $oObjectType = $oObject->post_type;
2004 $iObjectId = $oObject->ID;
2005 } elseif (isset($oPageParams->query_vars['page_id'])) {
2006 $oObject = $this->getPost($oPageParams->query_vars['page_id']);
2007 $oObjectType = $oObject->post_type;
2008 $iObjectId = $oObject->ID;
2009 } elseif (isset($oPageParams->query_vars['cat_id'])) {
2010 $oObject = $this->getCategory($oPageParams->query_vars['cat_id']);
2011 $oObjectType = 'category';
2012 $iObjectId = $oObject->term_id;
2013 } elseif (isset($oPageParams->query_vars['name'])) {
2014 global $wpdb;
2015
2016 $sQuery = $wpdb->prepare(
2017 "SELECT ID
2018 FROM {$wpdb->posts}
2019 WHERE post_name = %s
2020 AND post_type IN ('post', 'page')",
2021 $oPageParams->query_vars['name']
2022 );
2023
2024 $sObjectId = $wpdb->get_var($sQuery);
2025
2026 if ($sObjectId) {
2027 $oObject = get_post($sObjectId);
2028 }
2029
2030 if ($oObject !== null) {
2031 $oObjectType = $oObject->post_type;
2032 $iObjectId = $oObject->ID;
2033 }
2034 } elseif (isset($oPageParams->query_vars['pagename'])) {
2035 $oObject = get_page_by_title($oPageParams->query_vars['pagename']);
2036
2037 if ($oObject !== null) {
2038 $oObjectType = $oObject->post_type;
2039 $iObjectId = $oObject->ID;
2040 }
2041 }
2042
2043 if ($oObject === null || $oObject !== null && isset($oObjectType) && isset($iObjectId)
2044 && !$this->getAccessHandler()->checkObjectAccess($oObjectType, $iObjectId)
2045 ) {
2046 $this->redirectUser($oObject);
2047 }
2048 }
2049
2050 return $sHeaders;
2051 }
2052
2053 /**
2054 * Returns the current url.
2055 *
2056 * @return string
2057 */
2058 public function getCurrentUrl()
2059 {
2060 if (!isset($_SERVER['REQUEST_URI'])) {
2061 $sServerRequestUri = $_SERVER['PHP_SELF'];
2062 } else {
2063 $sServerRequestUri = $_SERVER['REQUEST_URI'];
2064 }
2065
2066 $sSecure = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
2067 $aProtocols = explode("/", strtolower($_SERVER["SERVER_PROTOCOL"]));
2068 $sProtocol = $aProtocols[0].$sSecure;
2069 $sPort = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
2070
2071 return $sProtocol."://".$_SERVER['SERVER_NAME'].$sPort.$sServerRequestUri;
2072 }
2073
2074 /**
2075 * Redirects the user to his destination.
2076 *
2077 * @param object $oObject The current object we want to access.
2078 *
2079 * @return null
2080 */
2081 public function redirectUser($oObject = null)
2082 {
2083 global $wp_query;
2084
2085 $blPostToShow = false;
2086 $aPosts = $wp_query->get_posts();
2087
2088 if ($oObject === null && isset($aPosts)) {
2089 foreach ($aPosts as $oPost) {
2090 if ($this->getAccessHandler()->checkObjectAccess($oPost->post_type, $oPost->ID)) {
2091 $blPostToShow = true;
2092 break;
2093 }
2094 }
2095 }
2096
2097 if (!$blPostToShow) {
2098 $aUamOptions = $this->getAdminOptions();
2099 $sPermalink = null;
2100
2101 if ($aUamOptions['redirect'] == 'custom_page') {
2102 $oPost = $this->getPost($aUamOptions['redirect_custom_page']);
2103 $sUrl = $oPost->guid;
2104 $sPermalink = get_page_link($oPost);
2105 } elseif ($aUamOptions['redirect'] == 'custom_url') {
2106 $sUrl = $aUamOptions['redirect_custom_url'];
2107 } else {
2108 $sUrl = home_url('/');
2109 }
2110
2111 if ($sUrl != $this->getCurrentUrl() && $sPermalink != $this->getCurrentUrl()) {
2112 wp_redirect($sUrl);
2113 exit;
2114 }
2115 }
2116 }
2117
2118 /**
2119 * Delivers the content of the requested file.
2120 *
2121 * @param string $sObjectType The type of the requested file.
2122 * @param string $sObjectUrl The file url.
2123 *
2124 * @return null
2125 */
2126 public function getFile($sObjectType, $sObjectUrl)
2127 {
2128 $oObject = $this->_getFileSettingsByType($sObjectType, $sObjectUrl);
2129
2130 if ($oObject === null) {
2131 return null;
2132 }
2133
2134 $sFile = null;
2135
2136 if ($this->getAccessHandler()->checkObjectAccess($oObject->type, $oObject->id)) {
2137 $sFile = $oObject->file;
2138 } elseif ($oObject->isImage) {
2139 $sFile = UAM_REALPATH.'gfx/noAccessPic.png';
2140 } else {
2141 wp_die(TXT_UAM_NO_RIGHTS);
2142 }
2143
2144 //Deliver content
2145 if (file_exists($sFile)) {
2146 $sFileName = basename($sFile);
2147
2148 /*
2149 * This only for compatibility
2150 * mime_content_type has been deprecated as the PECL extension file info
2151 * provides the same functionality (and more) in a much cleaner way.
2152 */
2153 $sFileExt = strtolower(array_pop(explode('.', $sFileName)));
2154 $aMimeTypes = $this->_getMimeTypes();
2155
2156 if (function_exists('finfo_open')) {
2157 $sFileInfo = finfo_open(FILEINFO_MIME);
2158 $sFileMimeType = finfo_file($sFileInfo, $sFile);
2159 finfo_close($sFileInfo);
2160 } elseif (function_exists('mime_content_type')) {
2161 $sFileMimeType = mime_content_type($sFile);
2162 } elseif (isset($aMimeTypes[$sFileExt])) {
2163 $sFileMimeType = $aMimeTypes[$sFileExt];
2164 } else {
2165 $sFileMimeType = 'application/octet-stream';
2166 }
2167
2168 header('Content-Description: File Transfer');
2169 header('Content-Type: '.$sFileMimeType);
2170
2171 if (!$oObject->isImage) {
2172 $sBaseName = str_replace(' ', '_', basename($sFile));
2173 header('Content-Disposition: attachment; filename="'.$sBaseName.'"');
2174 }
2175
2176 header('Content-Transfer-Encoding: binary');
2177 header('Content-Length: '.filesize($sFile));
2178
2179 $aUamOptions = $this->getAdminOptions();
2180
2181 if ($aUamOptions['download_type'] == 'fopen'
2182 && !$oObject->isImage
2183 ) {
2184 $oHandler = fopen($sFile, 'r');
2185
2186 //TODO find better solution (prevent '\n' / '0A')
2187 ob_clean();
2188 flush();
2189
2190 while (!feof($oHandler)) {
2191 if (!ini_get('safe_mode')) {
2192 set_time_limit(30);
2193 }
2194
2195 echo fread($oHandler, 1024);
2196 }
2197
2198 exit;
2199 } else {
2200 ob_clean();
2201 flush();
2202 readfile($sFile);
2203 exit;
2204 }
2205 } else {
2206 wp_die(TXT_UAM_FILE_NOT_FOUND_ERROR);
2207 }
2208 }
2209
2210 /**
2211 * Returns the file object by the given type and url.
2212 *
2213 * @param string $sObjectType The type of the requested file.
2214 * @param string $sObjectUrl The file url.
2215 *
2216 * @return object|null
2217 */
2218 protected function _getFileSettingsByType($sObjectType, $sObjectUrl)
2219 {
2220 $oObject = null;
2221
2222 if ($sObjectType == 'attachment') {
2223 $aUploadDir = wp_upload_dir();
2224
2225 $sMultiPath = str_replace(ABSPATH, '/', $aUploadDir['basedir']);
2226 $sMultiPath = str_replace('/files', $sMultiPath, $aUploadDir['baseurl']);
2227
2228 if ($this->isPermalinksActive()) {
2229 $sObjectUrl = $sMultiPath.'/'.$sObjectUrl;
2230 }
2231
2232 $oPost = $this->getPost($this->getPostIdByUrl($sObjectUrl));
2233
2234 if ($oPost !== null
2235 && $oPost->post_type == 'attachment'
2236 ) {
2237 $oObject = new stdClass();
2238 $oObject->id = $oPost->ID;
2239 $oObject->isImage = wp_attachment_is_image($oPost->ID);
2240 $oObject->type = $sObjectType;
2241 $oObject->file = $aUploadDir['basedir'].str_replace($sMultiPath, '', $sObjectUrl );
2242 }
2243 } else {
2244 $aPlObject = $this->getAccessHandler()->getPlObject($sObjectType);
2245
2246 if (isset($aPlObject) && isset($aPlObject['getFileObject'])) {
2247 $oObject = $aPlObject['reference']->{$aPlObject['getFileObject']}($sObjectUrl);
2248 }
2249 }
2250
2251 return $oObject;
2252 }
2253
2254 /**
2255 * Returns the url for a locked file.
2256 *
2257 * @param string $sUrl The base url.
2258 * @param integer $iId The _iId of the file.
2259 *
2260 * @return string
2261 */
2262 public function getFileUrl($sUrl, $iId)
2263 {
2264 $aUamOptions = $this->getAdminOptions();
2265
2266 if (!$this->isPermalinksActive() && $aUamOptions['lock_file'] == 'true') {
2267 $oPost = &$this->getPost($iId);
2268 $aType = explode("/", $oPost->post_mime_type);
2269 $sType = $aType[1];
2270 $aFileTypes = explode(',', $aUamOptions['locked_file_types']);
2271
2272 if ($aUamOptions['lock_file_types'] == 'all' || in_array($sType, $aFileTypes)) {
2273 $sUrl = home_url('/').'?uamfiletype=attachment&uamgetfile='.$sUrl;
2274 }
2275 }
2276
2277 return $sUrl;
2278 }
2279
2280 /**
2281 * Returns the post by the given url.
2282 *
2283 * @param string $sUrl The url of the post(attachment).
2284 *
2285 * @return object The post.
2286 */
2287 public function getPostIdByUrl($sUrl)
2288 {
2289 if (isset($this->_aPostUrls[$sUrl])) {
2290 return $this->_aPostUrls[$sUrl];
2291 }
2292
2293 $this->_aPostUrls[$sUrl] = null;
2294
2295 //Filter edit string
2296 $sNewUrl = preg_split("/-e[0-9]{1,}/", $sUrl);
2297
2298 if (count($sNewUrl) == 2) {
2299 $sNewUrl = $sNewUrl[0].$sNewUrl[1];
2300 } else {
2301 $sNewUrl = $sNewUrl[0];
2302 }
2303
2304 //Filter size
2305 $sNewUrl = preg_split("/-[0-9]{1,}x[0-9]{1,}/", $sNewUrl);
2306
2307 if (count($sNewUrl) == 2) {
2308 $sNewUrl = $sNewUrl[0].$sNewUrl[1];
2309 } else {
2310 $sNewUrl = $sNewUrl[0];
2311 }
2312
2313 /**
2314 * @var wpdb $wpdb
2315 */
2316 global $wpdb;
2317
2318 $sSql = $wpdb->prepare(
2319 "SELECT ID
2320 FROM ".$wpdb->prefix."posts
2321 WHERE guid = %s
2322 LIMIT 1",
2323 $sNewUrl
2324 );
2325
2326 $oDbPost = $wpdb->get_row($sSql);
2327
2328 if ($oDbPost) {
2329 $this->_aPostUrls[$sUrl] = $oDbPost->ID;
2330 }
2331
2332 return $this->_aPostUrls[$sUrl];
2333 }
2334
2335 /**
2336 * Caches the urls for the post for a later lookup.
2337 *
2338 * @param string $sUrl The url of the post.
2339 * @param object $oPost The post object.
2340 *
2341 * @return null
2342 */
2343 public function cachePostLinks($sUrl, $oPost)
2344 {
2345 $this->_aPostUrls[$sUrl] = $oPost->ID;
2346 return $sUrl;
2347 }
2348
2349 /**
2350 * Filter for Yoast SEO Plugin
2351 *
2352 * Hides the url from the site map if the user is not allowed
2353 *
2354 * @param string $url
2355 * @param string $type
2356 * @param object $object
2357 * @return false|string
2358 */
2359 function wp_seo_url($url, $type, $object)
2360 {
2361 $uaManager = new UserAccessManager();
2362 $handler = $uaManager->getAccessHandler();
2363 if($handler->checkObjectAccess($type, $object->ID)){
2364 return $url;
2365 }
2366 return false;
2367 }
2368 }