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