PluginProbe
User Access Manager / 1.1.1
User Access Manager v1.1.1
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/UamUserGroup.class.php +461 -952 1.0 → 1.1.1 View file →
@@ -34,34 +34,12 @@
34 34 protected $readAccess = null;
35 35 protected $writeAccess = null;
36 36 protected $ipRange = null;
37 37 protected $roles = array();
38 - protected $users = array(
39 - 'real' => -1,
40 - 'full' => -1
41 - );
42 - protected $singleUsers = array();
43 - protected $categories = array(
44 - 'real' => -1,
45 - 'full' => -1
46 - );
47 - protected $singleCategories = array();
48 - protected $posts = array(
49 - 'real' => -1,
50 - 'full' => -1
51 - );
52 - protected $singlePosts = array();
53 - protected $pages = array(
54 - 'real' => -1,
55 - 'full' => -1
56 - );
57 - protected $files = array(
58 - 'real' => -1,
59 - 'full' => -1
60 - );
61 - private $_assignedUsers = null;
62 - private $_assignedCategories = null;
63 - private $_assignedPosts = null;
38 + protected $objects = null;
39 + protected $singleObjects = null;
40 + private $_assignedObjects = null;
41 + protected $plObjects = array();
64 42
65 43 /**
66 44 * Consturtor
67 45 *
@@ -69,12 +47,21 @@
69 47 * @param integer $id The id of the user group.
70 48 *
71 49 * @return null
72 50 */
73 - function __construct(&$uamAccessHandler, $id = null)
51 + public function __construct(&$uamAccessHandler, $id = null)
74 52 {
75 53 $this->accessHandler = $uamAccessHandler;
76 54
55 + //Create default values for the objects.
56 + foreach ($this->getAllObjectTypes() as $objectType) {
57 + $this->objects[$objectType] = array(
58 + 'real' => -1,
59 + 'full' => -1
60 + );
61 + $this->_assignedObjects[$objectType] = null;
62 + }
63 +
77 64 if ($id !== null) {
78 65 global $wpdb;
79 66
80 67 $this->id = $id;
@@ -80,10 +67,10 @@
80 67 $this->id = $id;
81 68
82 69 $dbUsergroup = $wpdb->get_row(
83 70 "SELECT *
84 - FROM " . DB_ACCESSGROUP . "
85 - WHERE ID = " . $this->id . "
71 + FROM ".DB_ACCESSGROUP."
72 + WHERE ID = ".$this->getId()."
86 73 LIMIT 1",
87 74 ARRAY_A
88 75 );
89 76
@@ -99,9 +86,9 @@
99 86 * Returns the user access handler object.
100 87 *
101 88 * @return object
102 89 */
103 - function &getAccessHandler()
90 + public function &getAccessHandler()
104 91 {
105 92 return $this->accessHandler;
106 93 }
107 94
@@ -109,9 +96,9 @@
109 96 * Deletes the user group.
110 97 *
111 98 * @return null
112 99 */
113 - function delete()
100 + public function delete()
114 101 {
115 102 if ($this->id == null) {
116 103 return false;
117 104 }
@@ -122,12 +109,11 @@
122 109 "DELETE FROM " . DB_ACCESSGROUP . "
123 110 WHERE ID = $this->id LIMIT 1"
124 111 );
125 112
126 - $this->_deleteRolesFromDb();
127 - $this->_deletePostByTypeFromDb('all');
128 - $this->_deleteCategoriesFromDb();
129 - $this->_deleteUsersFromDb();
113 + foreach ($this->getAllObjectTypes() as $objectType) {
114 + $this->_deleteObjectsFromDb($objectType);
115 + }
130 116 }
131 117
132 118 /**
133 119 * Saves the user group.
@@ -133,9 +119,9 @@
133 119 * Saves the user group.
134 120 *
135 121 * @return null;
136 122 */
137 - function save()
123 + public function save()
138 124 {
139 125 global $wpdb;
140 126
141 127 if ($this->id == null) {
@@ -169,75 +155,22 @@
169 155 ip_range = '" . $this->ipRange . "'
170 156 WHERE ID = " . $this->id
171 157 );
172 158
173 - $this->getPosts();
174 - $this->getPages();
175 - $this->getFiles();
176 - $this->getRoles();
177 - $this->getCategories();
178 - $this->getUsers();
179 -
180 - $this->_deletePostByTypeFromDb('all');
181 - $this->_deleteRolesFromDb();
182 - $this->_deleteCategoriesFromDb();
183 - $this->_deleteUsersFromDb();
159 + foreach ($this->getAllObjectTypes() as $objectType) {
160 + //Load to object
161 + $this->getObjectsFromType($objectType);
162 + //Delete form database
163 + $this->_deleteObjectsFromDb($objectType);
164 + }
184 165 }
185 166
186 - foreach ($this->getUsers() as $userKey => $user) {
187 - $wpdb->query(
188 - "INSERT INTO " . DB_ACCESSGROUP_TO_USER . " (
189 - group_id,
190 - user_id
191 - )
192 - VALUES(
193 - '" . $this->id . "',
194 - '" . $userKey . "'
195 - )"
196 - );
167 + foreach ($this->getAllObjectTypes() as $objectType) {
168 + foreach ($this->getObjectsFromType($objectType) as $key => $object) {
169 + $sql = sprintf($this->_getSqlQuery($objectType, 'insert'), trim($key));
170 + $wpdb->query($sql);
171 + }
197 172 }
198 -
199 - foreach ($this->getCategories() as $categoryKey => $category) {
200 - $wpdb->query(
201 - "INSERT INTO " . DB_ACCESSGROUP_TO_CATEGORY . " (
202 - group_id,
203 - category_id
204 - )
205 - VALUES(
206 - '" . $this->id . "',
207 - '" . $categoryKey . "'
208 - )"
209 - );
210 - }
211 -
212 - foreach ($this->getRoles() as $roleKey => $role) {
213 - $wpdb->query(
214 - "INSERT INTO " . DB_ACCESSGROUP_TO_ROLE . " (
215 - group_id,
216 - role_name
217 - )
218 - VALUES(
219 - '" . $this->id . "',
220 - '" . $roleKey . "'
221 - )"
222 - );
223 - }
224 -
225 - $allPosts
226 - = array_merge($this->getPosts(), $this->getPages(), $this->getFiles());
227 -
228 - foreach ($allPosts as $post) {
229 - $wpdb->query(
230 - "INSERT INTO " . DB_ACCESSGROUP_TO_POST . " (
231 - group_id,
232 - post_id
233 - )
234 - VALUES(
235 - '" . $this->id . "',
236 - '" . $post->ID . "'
237 - )"
238 - );
239 - }
240 173 }
241 174
242 175
243 176 /*
@@ -248,9 +181,9 @@
248 181 * Returns the group id.
249 182 *
250 183 * @return integer
251 184 */
252 - function getId()
185 + public function getId()
253 186 {
254 187 return $this->id;
255 188 }
256 189
@@ -258,9 +191,9 @@
258 191 * Returns the group name.
259 192 *
260 193 * @return string
261 194 */
262 - function getGroupName()
195 + public function getGroupName()
263 196 {
264 197 return $this->groupName;
265 198 }
266 199
@@ -270,9 +203,9 @@
270 203 * @param string $groupName The new group name.
271 204 *
272 205 * @return null
273 206 */
274 - function setGroupName($groupName)
207 + public function setGroupName($groupName)
275 208 {
276 209 $this->groupName = $groupName;
277 210 }
278 211
@@ -280,9 +213,9 @@
280 213 * Returns the group description.
281 214 *
282 215 * @return string
283 216 */
284 - function getGroupDesc()
217 + public function getGroupDesc()
285 218 {
286 219 return $this->groupDesc;
287 220 }
288 221
@@ -292,9 +225,9 @@
292 225 * @param string $groupDesc The new group description.
293 226 *
294 227 * @return null
295 228 */
296 - function setGroupDesc($groupDesc)
229 + public function setGroupDesc($groupDesc)
297 230 {
298 231 $this->groupDesc = $groupDesc;
299 232 }
300 233
@@ -302,9 +235,9 @@
302 235 * Returns the read access.
303 236 *
304 237 * @return string
305 238 */
306 - function getReadAccess()
239 + public function getReadAccess()
307 240 {
308 241 return $this->readAccess;
309 242 }
310 243
@@ -314,9 +247,9 @@
314 247 * @param string $readAccess The read access.
315 248 *
316 249 * @return null
317 250 */
318 - function setReadAccess($readAccess)
251 + public function setReadAccess($readAccess)
319 252 {
320 253 $this->readAccess = $readAccess;
321 254 }
322 255
@@ -324,9 +257,9 @@
324 257 * Returns the write access.
325 258 *
326 259 * @return string
327 260 */
328 - function getWriteAccess()
261 + public function getWriteAccess()
329 262 {
330 263 return $this->writeAccess;
331 264 }
332 265
@@ -336,9 +269,9 @@
336 269 * @param string $writeAccess The wirte access.
337 270 *
338 271 * @return null
339 272 */
340 - function setWriteAccess($writeAccess)
273 + public function setWriteAccess($writeAccess)
341 274 {
342 275 $this->writeAccess = $writeAccess;
343 276 }
344 277
@@ -348,9 +281,9 @@
348 281 * @param string $type The return type.
349 282 *
350 283 * @return array
351 284 */
352 - function getIpRange($type = null)
285 + public function getIpRange($type = null)
353 286 {
354 287 if ($type == 'string') {
355 288 return $this->ipRange;
356 289 }
@@ -370,9 +303,9 @@
370 303 * @param string $ipRange The new ip range.
371 304 *
372 305 * @return null
373 306 */
374 - function setIpRange($ipRange)
307 + public function setIpRange($ipRange)
375 308 {
376 309 if (is_array($ipRange)) {
377 310 $ipRange = implode(';', $ipRange);
378 311 }
@@ -379,320 +312,221 @@
379 312
380 313 $this->ipRange = $ipRange;
381 314 }
382 315
316 + /**
317 + * Returns all objects types.
318 + *
319 + * @return array
320 + */
321 + public function getAllObjectTypes()
322 + {
323 + return $this->getAccessHandler()->getAllObjectTypes();
324 + }
325 +
383 326
384 327 /*
385 - * Group roles functions.
328 + * Meta functions.
386 329 */
387 330
388 331 /**
389 - * Returns the roles in the group
332 + * Magic method getter.
390 333 *
391 - * @return array
334 + * @param string $name The name of the function
335 + * @param array $arguments The arguments for the function
336 + *
337 + * @return mixed
392 338 */
393 - function getRoles()
339 + public function __call($name, $arguments)
394 340 {
395 - if ($this->id == null) {
396 - return array();
397 - }
341 + $uam = $this->getAccessHandler()->getUserAccessManager();
342 +
343 + $action = '';
398 344
399 - if ($this->roles != array()) {
400 - return $this->roles;
345 + if ($uam->startsWith($name, 'add')) {
346 + $prefix = 'add';
347 + } elseif ($uam->startsWith($name, 'remove')) {
348 + $prefix = 'remove';
349 + } elseif ($uam->startsWith($name, 'isMember')) {
350 + $prefix = 'isMember';
401 351 }
402 352
403 - global $wpdb;
353 + $objectType = str_replace($prefix, '', $name);
354 + $objectType = strtolower($objectType);
404 355
405 - $dbRoles = $wpdb->get_results(
406 - "SELECT *
407 - FROM " . DB_ACCESSGROUP_TO_ROLE . "
408 - WHERE group_id = " . $this->id,
409 - ARRAY_A
410 - );
356 + $objectId = $arguments[0];
411 357
412 - if (isset($dbRoles)) {
413 - foreach ($dbRoles as $dbRole) {
414 - $this->roles[trim($dbRole['role_name'])] = $dbRole;
415 - }
358 + if ($prefix == 'add') {
359 + return $this->addObject(
360 + $objectType,
361 + $objectId
362 + );
363 + } elseif ($prefix == 'remove') {
364 + return $this->removeObject(
365 + $objectType,
366 + $objectId
367 + );
368 + } elseif ($prefix == 'ismember') {
369 + $withInfo = $arguments[1];
370 +
371 + return $this->objectIsMember(
372 + $objectType,
373 + $objectId,
374 + $withInfo
375 + );
416 376 }
417 -
418 - return $this->roles;
419 377 }
420 378
421 379 /**
422 - * Adds a role to the role group.
380 + * Returns the sql query.
423 381 *
424 - * @param integer $roleName The role name which should be added.
382 + * @param string $objectType The object type.
383 + * @param string $action The sql action.
425 384 *
426 - * @return null
385 + * @return string
427 386 */
428 - function addRole($roleName)
387 + private function _getSqlQuery($objectType, $action)
429 388 {
430 - $this->getRoles();
389 + $sql = '';
431 390
432 - /**
433 - * $this->roles[$roleName] = &get_role($roleName);
434 - * Makes trouble, but why?
435 - * Error: "Notice: Only variable references should be returned by reference"
436 - */
437 -
438 - $this->roles[$roleName] = array('role_name' => $roleName);
391 + if ($action == 'select') {
392 + $sql = "SELECT object_id as id
393 + FROM ".DB_ACCESSGROUP_TO_OBJECT."
394 + WHERE group_id = ".$this->getId()."
395 + AND object_type = '".$objectType ."'";
396 + } elseif ($action == 'delete') {
397 + $sql = "DELETE FROM ".DB_ACCESSGROUP_TO_OBJECT."
398 + WHERE group_id = ".$this->getId()."
399 + AND object_type = '".$objectType ."'";
400 + } elseif ($action == 'insert') {
401 + $sql = "INSERT INTO ".DB_ACCESSGROUP_TO_OBJECT." (
402 + group_id,
403 + object_id,
404 + object_type
405 + ) VALUES (
406 + '".$this->getId()."',
407 + '%s',
408 + '".$objectType."'
409 + )";
410 + }
411 +
412 + return $sql;
439 413 }
440 414
441 415 /**
442 - * Removes a role from the role group.
416 + * Adds a object of the given type.
443 417 *
444 - * @param integer $roleName The role name which should be removed.
418 + * @param string $objectType The object type.
419 + * @param integer $objectId The object id.
445 420 *
446 421 * @return null
447 422 */
448 - function removeRole($roleName)
449 - {
450 - $this->getRoles();
451 - unset($this->roles[$roleName]);
452 - }
453 -
454 - /**
455 - * Unsets the roles.
456 - *
457 - * @param boolean $plusRemove If true also database entrys will remove.
458 - *
459 - * @return null;
460 - */
461 - function unsetRoles($plusRemove = false)
423 + public function addObject($objectType, $objectId)
462 424 {
463 - if ($plusRemove) {
464 - $this->_deleteRolesFromDb();
425 + if (!in_array($objectType, $this->getAllObjectTypes())) {
426 + return;
465 427 }
466 -
467 - $this->roles = array();
468 - }
469 -
470 - /**
471 - * Removes all roles from the user group.
472 - *
473 - * @return null
474 - */
475 - private function _deleteRolesFromDb()
476 - {
477 - if ($this->id == null) {
478 - return false;
479 - }
480 428
481 - global $wpdb;
429 + $this->getAccessHandler()->unsetUserGroupsForObject();
430 + $this->getObjectsFromType($objectType);
482 431
483 - $wpdb->query(
484 - "DELETE FROM " . DB_ACCESSGROUP_TO_ROLE . "
485 - WHERE group_id = ".$this->id
486 - );
487 - }
488 -
489 -
490 - /*
491 - * Group users functions.
492 - */
493 -
494 - /**
495 - * Returns the assigned users.
496 - *
497 - * @return array
498 - */
499 - private function _getAssignedUsers()
500 - {
501 - if ($this->_assignedUsers !== null) {
502 - return $this->_assignedUsers;
503 - }
504 -
505 - global $wpdb;
432 + $object = new stdClass;
433 + $object->id = $objectId;
506 434
507 - $dbUsers = $wpdb->get_results(
508 - "SELECT user_id
509 - FROM " . DB_ACCESSGROUP_TO_USER . "
510 - WHERE group_id = " . $this->id . "
511 - ORDER BY user_id"
512 - );
435 + $this->objects[$objectType]['real'][$objectId] = $object;
436 + $this->objects[$objectType]['full'] = -1;
513 437
514 - $this->_assignedUsers = array();
515 -
516 - foreach ($dbUsers as $dbUser) {
517 - $this->_assignedUsers[$dbUser->user_id] = $dbUser->user_id;
518 - }
519 -
520 - return $this->_assignedUsers;
438 + $this->_assignedObjects[$objectType][$objectId] = $objectId;
521 439 }
522 440
523 - /**
524 - * Checks it the user is assigned to the group.
525 - *
526 - * @param integer $userId The user id.
527 - *
528 - * @return boolean
529 - */
530 - private function _isUserAssignedToGroup($userId)
531 - {
532 - if (array_key_exists($userId, $this->_getAssignedUsers())) {
533 - return true;
534 - } else {
535 - return false;
536 - }
537 - }
538 -
539 441 /**
540 - * Returns a single user.
442 + * Removes a object of the given type.
541 443 *
542 - * @param object $user The user.
543 - * @param string $type The return type. Can be real or full.
444 + * @param string $objectType The object type.
445 + * @param integer $objectId The object id.
544 446 *
545 - * @return object
447 + * @return null
546 448 */
547 - private function _getSingleUser($user, $type)
449 + public function removeObject($objectType, $objectId)
548 450 {
549 - if (!isset($user->ID)) {
550 - return null;
451 + if (!in_array($objectType, $this->getAllObjectTypes())) {
452 + return;
551 453 }
552 454
553 - if (isset($this->singleUsers[$user->ID])) {
554 - return $this->singleUsers[$user->ID];
555 - }
455 + $this->getAccessHandler()->unsetUserGroupsForObject();
456 + $this->getObjectsFromType($objectType);
556 457
557 - $isRecursiveMember = array();
458 + unset($this->objects[$objectType]['real'][$objectId]);
459 + $this->objects[$objectType]['full'] = -1;
558 460
559 - if ($type == 'full') {
560 - global $wpdb;
561 -
562 - $curUserdata = get_userdata($user->ID);
563 -
564 - if (isset($curUserdata->{$wpdb->prefix . "capabilities"})) {
565 - $capabilities = $curUserdata->{$wpdb->prefix . "capabilities"};
566 - } else {
567 - $capabilities = null;
568 - }
569 -
570 - $role = is_array($capabilities) ?
571 - array_keys($capabilities) : 'norole';
572 -
573 - if (array_key_exists($role[0], $this->getRoles())
574 - ) {
575 - $isRecursiveMember
576 - = array('byRole' => array());
577 - $isRecursiveMember['byRole'][]
578 - = $role[0];
579 - }
580 - }
581 -
582 - if ($this->_isUserAssignedToGroup($user->ID)
583 - || $isRecursiveMember != array()
584 - ) {
585 - if ($isRecursiveMember != array()) {
586 - $user->recursiveMember = $isRecursiveMember;
587 - }
588 -
589 - $this->singleUsers[$user->ID] = $user;
590 - } else {
591 - $this->singleUsers[$user->ID] = null;
592 - }
593 -
594 - return $this->singleUsers[$user->ID];
461 + unset($this->singleObjects[$objectType][$objectId]);
462 + unset($this->_assignedObjects[$objectType][$objectId]);
595 463 }
596 464
597 465 /**
598 - * Returns the users in the group
466 + * Returns the assigned objects.
599 467 *
600 - * @param string $type The return type. Can be real or full.
468 + * @param string $objectType The object type.
601 469 *
602 470 * @return array
603 471 */
604 - function getUsers($type = 'real')
472 + private function _getAssignedObjects($objectType)
605 473 {
606 - if ($this->id == null) {
607 - return array();
474 + if ($this->_assignedObjects[$objectType] !== null) {
475 + return $this->_assignedObjects[$objectType];
608 476 }
477 +
478 + global $wpdb;
479 +
480 + $dbObjects = $wpdb->get_results(
481 + $this->_getSqlQuery($objectType, 'select')
482 + );
609 483
610 - if ($type != 'real'
611 - && $type != 'full'
612 - ) {
613 - return array();
614 - }
484 + $this->_assignedObjects[$objectType] = array();
615 485
616 - if ($this->users[$type] != -1) {
617 - return $this->users[$type];
618 - } else {
619 - $this->users[$type] = array();
486 + foreach ($dbObjects as $dbObject) {
487 + $this->_assignedObjects[$objectType][$dbObject->id]
488 + = $dbObject->id;
620 489 }
621 490
622 - global $wpdb;
623 -
624 - if ($type == 'real') {
625 - $dbUsers = $wpdb->get_results(
626 - "SELECT user_id as ID
627 - FROM " . DB_ACCESSGROUP_TO_USER . "
628 - WHERE group_id = " . $this->id . "
629 - ORDER BY user_id",
630 - ARRAY_A
631 - );
632 - } elseif ($type == 'full') {
633 - $dbUsers = $wpdb->get_results(
634 - "SELECT ID, user_nicename
635 - FROM $wpdb->users
636 - ORDER BY user_nicename"
637 - );
638 - }
639 -
640 - if (isset($dbUsers)) {
641 - foreach ($dbUsers as $dbUser) {
642 - $user = $this->_getSingleUser($dbUser, $type);
643 -
644 - if ($user !== null) {
645 - $this->users[$type][$user->ID] = $user;
646 - }
647 - }
648 - }
649 -
650 - return $this->users[$type];
491 + return $this->_assignedObjects[$objectType];
651 492 }
652 493
653 494 /**
654 - * Adds a user to the user group.
495 + * Checks if the object is assigned to the group.
655 496 *
656 - * @param integer $userID The user id which should be added.
497 + * @param string $objectType The object type.
498 + * @param integer $objectId The object id.
657 499 *
658 - * @return null
500 + * @return boolean
659 501 */
660 - function addUser($userID)
661 - {
662 - $this->getUsers();
663 - $this->users['real'][$userID] = get_userdata($userID);
664 - $this->users['full'] = -1;
502 + private function _isObjectAssignedToGroup($objectType, $objectId)
503 + {
504 + return array_key_exists(
505 + $objectId,
506 + $this->_getAssignedObjects($objectType)
507 + );
665 508 }
666 509
667 510 /**
668 - * Removes a user from the user group.
511 + * Unsets the ojects.
669 512 *
670 - * @param integer $userID The user id which should be removed.
671 - *
672 - * @return null
673 - */
674 - function removeUser($userID)
675 - {
676 - $this->getUsers();
677 - unset($this->users['real'][$userID]);
678 - $this->users['full'] = -1;
679 - }
680 -
681 - /**
682 - * Unsets the users.
683 - *
513 + * @param string $objectType The object type.
684 514 * @param boolean $plusRemove If true also database entrys will remove.
685 515 *
686 516 * @return null;
687 517 */
688 - function unsetUsers($plusRemove = false)
518 + public function unsetObjects($objectType, $plusRemove = false)
689 519 {
520 + if (!in_array($objectType, $this->getAllObjectTypes())) {
521 + return;
522 + }
523 +
690 524 if ($plusRemove) {
691 - $this->_deleteUsersFromDb();
525 + $this->_deleteObjectsFromDb($objectType);
692 526 }
693 -
694 - $this->users = array(
527 +
528 + $this->objects[$objectType] = array(
695 529 'real' => array(),
696 530 'full' => array(),
697 531 );
698 532 }
@@ -697,40 +531,47 @@
697 531 );
698 532 }
699 533
700 534 /**
701 - * Removes all users from the user group.
535 + * Removes all objects from the user group.
702 536 *
537 + * @param string $objectType The object type.
538 + *
703 539 * @return null
704 540 */
705 - private function _deleteUsersFromDb()
541 + private function _deleteObjectsFromDb($objectType)
706 542 {
707 - global $wpdb;
543 + if (isset($this->id)) {
544 + global $wpdb;
708 545
709 - $wpdb->query(
710 - "DELETE FROM " . DB_ACCESSGROUP_TO_USER . "
711 - WHERE group_id = ".$this->id
712 - );
546 + $wpdb->query(
547 + $this->_getSqlQuery($objectType, 'delete')
548 + );
549 + }
713 550 }
714 551
715 - /**
716 - * Checks if the given user is a member of the group.
552 + /**
553 + * Checks if the given object is a member of the group.
717 554 *
718 - * @param interger $userId The id of the user which should be checked.
719 - * @param boolean $withInfo If true then we return additional infos.
555 + * @param string $objectType The object type.
556 + * @param interger $objectId The id of the object which should be checked.
557 + * @param boolean $withInfo If true then we return additional infos.
720 558 *
721 559 * @return boolean
722 560 */
723 - function userIsMember($userId, $withInfo = false)
561 + public function objectIsMember($objectType, $objectId, $withInfo = false)
724 562 {
725 - $user->ID = $userId;
726 - $user = $this->_getSingleUser($user, 'full');
563 + if (!in_array($objectType, $this->getAllObjectTypes())) {
564 + return;
565 + }
727 566
728 - if ($user !== null) {
729 - if (isset($user->recursiveMember)
567 + $object = $this->_getSingleObject($objectType, $objectId, 'full');
568 +
569 + if ($object !== null) {
570 + if (isset($object->recursiveMember)
730 571 && $withInfo
731 572 ) {
732 - return $user->recursiveMember;
573 + return $object->recursiveMember;
733 574 }
734 575
735 576 return true;
736 577 }
@@ -737,722 +578,390 @@
737 578
738 579 return false;
739 580 }
740 581
741 -
742 - /*
743 - * Group categories functions.
744 - */
745 -
746 582 /**
747 - * Returns the assigned categories.
583 + * Returns all objects of the given type.
748 584 *
585 + * @param string $objectType The object type.
586 + * @param string $type The return type, could be real or full.
587 + *
749 588 * @return array
750 589 */
751 - private function _getAssignedCategories()
590 + function getObjectsFromType($objectType, $type = 'real')
752 591 {
753 - if ($this->_assignedCategories !== null) {
754 - return $this->_assignedCategories;
592 + if (!in_array($objectType, $this->getAllObjectTypes())) {
593 + return;
755 594 }
756 -
595 +
596 + if ($this->id == null) {
597 + return array();
598 + }
599 +
600 + if ($type != 'real'
601 + && $type != 'full'
602 + ) {
603 + return array();
604 + }
605 +
606 + if ($this->objects[$objectType][$type] != -1) {
607 + return $this->objects[$objectType][$type];
608 + } else {
609 + $this->objects[$objectType][$type] = array();
610 + }
611 +
757 612 global $wpdb;
758 613
759 - $dbCategories = $wpdb->get_results(
760 - "SELECT *
761 - FROM " . DB_ACCESSGROUP_TO_CATEGORY . "
762 - WHERE group_id = " . $this->id . "
763 - ORDER BY category_id"
614 + $dbObjects = $wpdb->get_results(
615 + $this->_getSqlQuery($objectType, 'select')
764 616 );
765 617
766 - $this->_assignedCategories = array();
618 + foreach ($dbObjects as $dbObject) {
619 + $object = $this->_getSingleObject($objectType, $dbObject->id, $type);
620 +
621 + if ($object !== null) {
622 + $this->objects[$objectType][$type][$object->id] = $object;
623 + }
624 + }
767 625
768 - foreach ($dbCategories as $dbCategory) {
769 - $this->_assignedCategories[$dbCategory->category_id]
770 - = $dbCategory->category_id;
626 + if ($type == 'full'
627 + && $objectType != 'post'
628 + && $objectType != 'page'
629 + && $objectType != 'attachment'
630 + && $objectType != 'role'
631 + ) {
632 + if ($objectType == 'category') {
633 + $this->objects[$objectType][$type]
634 + = $this->getFullCategories($this->objects[$objectType][$type]);
635 + } elseif ($objectType == 'user') {
636 + $this->objects[$objectType][$type] = $this->getFullUsers();
637 + } else {
638 + $plObject = $this->getAccessHandler()->getPlObject($objectType);
639 + $this->objects[$objectType][$type]
640 + = $plObject['reference']->{$plObject['getFullObjects']}(
641 + $this->objects[$objectType][$type],
642 + &$this
643 + );
644 + }
771 645 }
772 646
773 - return $this->_assignedCategories;
647 + return $this->objects[$objectType][$type];
774 648 }
775 649
776 - /**
777 - * Checks it the category is assigned to the group.
778 - *
779 - * @param integer $categoryId The category id.
780 - *
781 - * @return boolean
782 - */
783 - private function _isCategoryAssignedToGroup($categoryId)
784 - {
785 - if (array_key_exists($categoryId, $this->_getAssignedCategories())) {
786 - return true;
787 - } else {
788 - return false;
789 - }
790 - }
791 -
792 650 /**
793 - * Returns a single category.
651 + * Returns a single object.
794 652 *
795 - * @param object $category The category.
796 - * @param string $type The return type. Can be real or full.
653 + * @param string $objectType The object type.
654 + * @param interger $objectId The id of the object which should be checked.
655 + * @param string $type The return type. Can be real or full.
797 656 *
798 657 * @return object
799 658 */
800 - private function _getSingleCategory($category, $type)
659 + private function _getSingleObject($objectType, $objectId, $type)
801 660 {
802 - if (!isset($category->term_id)) {
803 - return null;
661 + if (isset($this->singleObjects[$objectType][$objectId])) {
662 + return $this->singleObjects[$objectType][$objectId];
804 663 }
805 664
806 - if (isset($this->singleCategories[$category->term_id])) {
807 - return $this->singleCategories[$category->term_id];
808 - }
809 -
810 665 $isRecursiveMember = array();
811 666
812 - $userAccessManager = $this->getAccessHandler()->getUserAccessManager();
813 - $uamOptions = $userAccessManager->getAdminOptions();
814 -
815 - if ($uamOptions['lock_recursive'] == 'true'
816 - && $type == 'full'
667 + if ($type == 'full'
668 + && $objectType != 'role'
817 669 ) {
818 - if ($category->parent != 0) {
819 - $parentCategory = get_post($category->parent);
820 -
821 - $parentCategory = $this->_getSingleCategory(
822 - $parentCategory,
823 - $type
824 - );
825 -
826 - if ($parentCategory !== null) {
827 - if (isset($parentCategory->recursiveMember)) {
828 - $isRecursiveMember['byCategory'][]
829 - = $parentCategory;
830 - } else {
831 - $isRecursiveMember['byCategory'][]
832 - = $parentCategory->term_id;
833 - }
834 - }
670 + if ($objectType == 'post'
671 + || $objectType == 'page'
672 + || $objectType == 'attachment'
673 + ) {
674 + $isRecursiveMember = $this->_getFullPost($objectType, $objectId);
675 + } else if ($objectType == 'category') {
676 + $isRecursiveMember = $this->_getFullCategory($objectId);
677 + } else if ($objectType == 'user') {
678 + $isRecursiveMember = $this->_getFullUser($objectId);
679 + } else {
680 + $isRecursiveMember = $this->_getFullPlObject($objectType, $objectId);
835 681 }
836 682 }
837 -
838 - if ($this->_isCategoryAssignedToGroup($category->term_id)
683 +
684 + if ($this->_isObjectAssignedToGroup($objectType, $objectId)
839 685 || $isRecursiveMember != array()
840 686 ) {
687 + $object = new stdClass;
688 + $object->id = $objectId;
689 +
841 690 if ($isRecursiveMember != array()) {
842 - $category->recursiveMember = $isRecursiveMember;
691 + $object->recursiveMember = $isRecursiveMember;
843 692 }
844 693
845 - $this->singleCategories[$category->term_id] = $category;
694 + $this->singleObjects[$objectType][$objectId] = $object;
846 695 } else {
847 - $this->singleCategories[$category->term_id] = null;
696 + $this->singleObjects[$objectType][$objectId] = null;
848 697 }
849 698
850 - return $this->singleCategories[$category->term_id];
699 + return $this->singleObjects[$objectType][$objectId];
851 700 }
701 +
852 702
703 + /*
704 + * Group users functions.
705 + */
706 +
853 707 /**
854 - * Returns the categories in the group
708 + * Returns a single user.
855 709 *
856 - * @param string $type The return type. Can be real or full.
710 + * @param integer $objectId The object id.
857 711 *
858 - * @return array
712 + * @return object
859 713 */
860 - function getCategories($type = 'real')
714 + private function _getFullUser($objectId)
861 715 {
862 - if ($this->id == null) {
863 - return array();
864 - }
716 + $isRecursiveMember = array();
865 717
866 - if ($type != 'real'
867 - && $type != 'full'
868 - ) {
869 - return array();
870 - }
871 -
872 - if ($this->categories[$type] != -1) {
873 - return $this->categories[$type];
874 - } else {
875 - $this->categories[$type] = array();
876 - }
877 -
878 718 global $wpdb;
879 - $userAccessManager = $this->getAccessHandler()->getUserAccessManager();
880 - $uamOptions = $userAccessManager->getAdminOptions();
881 719
882 - $dbCategories = $wpdb->get_results(
883 - "SELECT *
884 - FROM " . DB_ACCESSGROUP_TO_CATEGORY . "
885 - WHERE group_id = " . $this->id . "
886 - ORDER BY category_id",
887 - ARRAY_A
888 - );
720 + $curUserdata = get_userdata($objectId);
889 721
890 - if (isset($dbCategories)) {
891 - foreach ($dbCategories as $dbCategorie) {
892 - $category = get_category($dbCategorie['category_id']);
893 -
894 - if ($category != null) {
895 - if ($uamOptions['lock_recursive'] == 'true'
896 - && $type == 'full'
897 - ) {
898 - //We have to remove the filter to get all categories
899 - $removeSucc = remove_filter(
900 - 'get_terms',
901 - array(
902 - $this->getAccessHandler()->getUserAccessManager(),
903 - 'showCategory'
904 - )
905 - );
906 -
907 - if ($removeSucc) {
908 - $args = array(
909 - 'child_of' => $category->term_id,
910 - 'hide_empty' => false
911 - );
912 -
913 - $categoryChilds = get_categories($args);
914 -
915 - add_filter(
916 - 'get_terms',
917 - array(&$userAccessManager, 'showCategory')
918 - );
919 -
920 - foreach ($categoryChilds as $categoryChild) {
921 - $categoryChild->recursiveMember
922 - = array('byCategory' => array());
923 - $categoryChild->recursiveMember['byCategory'][]
924 - = $category->term_id;
925 - $this->categories[$type][$categoryChild->term_id]
926 - = $categoryChild;
927 - }
928 - }
929 - }
930 -
931 - $this->categories[$type][$category->term_id] = $category;
932 - }
933 - }
722 + if (isset($curUserdata->{$wpdb->prefix . "capabilities"})) {
723 + $capabilities = $curUserdata->{$wpdb->prefix . "capabilities"};
724 + } else {
725 + $capabilities = null;
934 726 }
935 727
936 - return $this->categories[$type];
937 - }
938 -
939 - /**
940 - * Adds a category to the category group.
941 - *
942 - * @param integer $categoryID The category id which should be added.
943 - *
944 - * @return null
945 - */
946 - function addCategory($categoryID)
947 - {
948 - $this->getCategories();
949 - $this->categories['real'][$categoryID] = get_category($categoryID);
950 - $this->categories['full'] = -1;
951 - }
952 -
953 - /**
954 - * Removes a category from the category group.
955 - *
956 - * @param integer $categoryID The category id which should be removed.
957 - *
958 - * @return null
959 - */
960 - function removeCategory($categoryID)
961 - {
962 - $this->getCategories();
963 - unset($this->categories['real'][$categoryID]);
964 - $this->categories['full'] = -1;
965 - }
966 -
967 - /**
968 - * Unsets the categories.
969 - *
970 - * @param boolean $plusRemove If true also database entrys will remove.
971 - *
972 - * @return null;
973 - */
974 - function unsetCategories($plusRemove = false)
975 - {
976 - if ($plusRemove) {
977 - $this->_deleteCategoriesFromDb();
978 - }
728 + $role = is_array($capabilities) ?
729 + array_keys($capabilities) : array('norole');
979 730
980 - $this->categories = array(
981 - 'real' => array(),
982 - 'full' => array(),
983 - );
984 - }
985 -
986 - /**
987 - * Removes all categories from the user group.
988 - *
989 - * @return null
990 - */
991 - private function _deleteCategoriesFromDb()
992 - {
993 - global $wpdb;
994 -
995 - $wpdb->query(
996 - "DELETE FROM " . DB_ACCESSGROUP_TO_CATEGORY . "
997 - WHERE group_id = ".$this->id
998 - );
999 - }
1000 -
1001 - /**
1002 - * Checks if the given post is a member of the group.
1003 - *
1004 - * @param interger $categoryId The id of the post which should be checked.
1005 - * @param boolean $withInfo If true then we return additional infos.
1006 - *
1007 - * @return boolean
1008 - */
1009 - function categoryIsMember($categoryId, $withInfo = false)
1010 - {
1011 - $category = get_category($categoryId);
1012 - $category = $this->_getSingleCategory($category, 'full');
1013 -
1014 - if ($category !== null) {
1015 - if (isset($category->recursiveMember)
1016 - && $withInfo
1017 - ) {
1018 - return $category->recursiveMember;
1019 - }
731 + if (array_key_exists($role[0], $this->getObjectsFromType('role'))
732 + ) {
733 + $roleObject->name = $role[0];
1020 734
1021 - return true;
735 + $isRecursiveMember = array('role' => array());
736 + $isRecursiveMember['role'][] = $roleObject;
1022 737 }
1023 738
1024 - /*$categories = $this->getCategories('full');
1025 -
1026 - if (array_key_exists($categoryId, $categories)) {
1027 - if (isset($categories[$categoryId]->recursiveMember)
1028 - && $withInfo
1029 - ) {
1030 - return $categories[$categoryId]->recursiveMember;
1031 - }
1032 -
1033 - return true;
1034 - }*/
1035 -
1036 - return false;
739 + return $isRecursiveMember;
1037 740 }
1038 741
1039 -
1040 - /*
1041 - * Group posts functions.
1042 - */
1043 -
1044 742 /**
1045 - * Returns the assigned posts
743 + * Returns the users in the group
1046 744 *
1047 745 * @return array
1048 746 */
1049 - private function _getAssignedPosts()
747 + public function getFullUsers()
1050 748 {
1051 - if ($this->_assignedPosts !== null) {
1052 - return $this->_assignedPosts;
1053 - }
1054 -
1055 749 global $wpdb;
1056 750
1057 - $dbPosts = $wpdb->get_results(
1058 - "SELECT post_id
1059 - FROM " . DB_ACCESSGROUP_TO_POST . "
1060 - WHERE group_id = " . $this->id
751 + $dbUsers = $wpdb->get_results(
752 + "SELECT ID, user_nicename
753 + FROM ".$wpdb->users
1061 754 );
1062 755
1063 - $this->_assignedPosts = array();
756 + $fullUsers = array();
1064 757
1065 - foreach ($dbPosts as $dbPost) {
1066 - $this->_assignedPosts[$dbPost->post_id] = $dbPost->post_id;
758 + if (isset($dbUsers)) {
759 + foreach ($dbUsers as $dbUser) {
760 + $user = $this->_getSingleObject('user', $dbUser->ID, 'full');
761 +
762 + if ($user !== null) {
763 + $fullUsers[$user->id] = $user;
764 + }
765 + }
1067 766 }
1068 767
1069 - return $this->_assignedPosts;
768 + return $fullUsers;
1070 769 }
1071 770
1072 - /**
1073 - * Checks it the post is assigned to the group.
1074 - *
1075 - * @param integer $postId The post id.
1076 - *
1077 - * @return boolean
771 +
772 + /*
773 + * Group categories functions.
1078 774 */
1079 - private function _isPostAssignedToGroup($postId)
1080 - {
1081 - if (array_key_exists($postId, $this->_getAssignedPosts())) {
1082 - return true;
1083 - } else {
1084 - return false;
1085 - }
1086 - }
1087 775
1088 776 /**
1089 - * Returns the membership of a single post.
777 + * Returns a single category.
1090 778 *
1091 - * @param object $post The post object.
1092 - * @param string $type The return type.
1093 - * @param string $postType The post type needed for the intern representation.
779 + * @param integer $objectId The object id.
1094 780 *
1095 781 * @return object
1096 782 */
1097 - function _getSinglePost($post, $type, $postType)
783 + private function _getFullCategory($objectId)
1098 784 {
1099 - if (!isset($post->ID)) {
1100 - return null;
1101 - }
1102 -
1103 - if (isset($this->singlePosts[$post->ID])) {
1104 - return $this->singlePosts[$post->ID];
1105 - }
1106 -
785 + $category = get_category($objectId);
786 +
1107 787 $isRecursiveMember = array();
1108 788
1109 - $userAccessManager = &$this->getAccessHandler()->getUserAccessManager();
789 + $userAccessManager = $this->getAccessHandler()->getUserAccessManager();
1110 790 $uamOptions = $userAccessManager->getAdminOptions();
1111 -
1112 - if ($type == 'full') {
1113 - foreach ($this->getCategories('full') as $category) {
1114 - if (in_category($category->cat_ID, $post->ID)) {
1115 - $isRecursiveMember['byCategory'][] = $category->cat_ID;
1116 - //break;
1117 - }
1118 - }
1119 791
1120 - if (($postType == 'page'
1121 - || $postType == 'file')
1122 - && $uamOptions['lock_recursive'] == 'true'
792 + if ($uamOptions['lock_recursive'] == 'true') {
793 + if (isset($category->parent)
794 + && !is_null($category->parent)
1123 795 ) {
1124 - if ($post->post_parent != 0) {
1125 - $parentPost = get_post($post->post_parent);
796 + $parentCategory = $this->_getSingleObject(
797 + 'category',
798 + $category->parent,
799 + 'full'
800 + );
801 +
802 + if ($parentCategory !== null) {
803 + $curCategory = get_category($objectId);
804 + $parentCategory->name = $curCategory->name;
1126 805
1127 - $parentPost = $this->_getSinglePost(
1128 - $parentPost,
1129 - $type,
1130 - $parentPost->post_type
1131 - );
1132 -
1133 - if ($parentPost !== null) {
1134 - if (isset($parentPost->recursiveMember)) {
1135 - $isRecursiveMember['byPost'][]
1136 - = $parentPost;
1137 - } else {
1138 - $isRecursiveMember['byPost'][]
1139 - = $parentPost->ID;
1140 - }
806 + if (isset($parentCategory->recursiveMember)) {
807 + $isRecursiveMember['category'][]
808 + = $parentCategory;
809 + } else {
810 + $isRecursiveMember['category'][]
811 + = $parentCategory;
1141 812 }
1142 813 }
1143 814 }
1144 815 }
1145 816
1146 - if ($this->_isPostAssignedToGroup($post->ID)
1147 - || $isRecursiveMember != array()
1148 - ) {
1149 - if ($isRecursiveMember != array()) {
1150 - $post->recursiveMember = $isRecursiveMember;
1151 - }
1152 - $this->singlePosts[$post->ID] = $post;
1153 - } else {
1154 - $this->singlePosts[$post->ID] = null;
1155 - }
1156 -
1157 - return $this->singlePosts[$post->ID];
817 + return $isRecursiveMember;
1158 818 }
1159 819
1160 820 /**
1161 - * Returns the posts by the given type in the group
821 + * Returns the categories in the group
1162 822 *
1163 - * @param string $postType The type of the post.
1164 - * @param string $type The return type. Can be real or full.
823 + * @param string $categories The real categories.
1165 824 *
1166 825 * @return array
1167 826 */
1168 - private function _getPostByType($postType, $type)
827 + public function getFullCategories($categories)
1169 828 {
1170 - if ($type != 'real'
1171 - && $type != 'full'
1172 - ) {
1173 - return array();
1174 - }
1175 -
1176 - if ($postType == 'file') {
1177 - $wpType = 'attachment';
1178 - } else {
1179 - $wpType = $postType;
1180 - }
1181 -
1182 - if ($this->{$postType.'s'}[$type] != -1) {
1183 - return $this->{$postType.'s'}[$type];
1184 - } else {
1185 - $this->{$postType.'s'}[$type] = array();
1186 - }
1187 -
1188 - global $wpdb;
829 + $userAccessManager = $this->getAccessHandler()->getUserAccessManager();
830 + $uamOptions = $userAccessManager->getAdminOptions();
1189 831
1190 - $posts = $wpdb->get_results(
1191 - "SELECT ID, post_parent
1192 - FROM $wpdb->posts
1193 - WHERE post_type = '".$wpType."'"
1194 - );
1195 -
1196 - if (isset($posts)) {
1197 - foreach ($posts as $post) {
1198 - $post = $this->_getSinglePost($post, $type, $postType);
1199 -
1200 - if ($post !== null) {
1201 - $this->{$postType.'s'}[$type][$post->ID] = $post;
832 + foreach ($categories as $category) {
833 + if ($category != null) {
834 + if ($uamOptions['lock_recursive'] == 'true') {
835 + //We have to remove the filter to get all categories
836 + $removeSucc = remove_filter(
837 + 'get_terms',
838 + array(
839 + $this->getAccessHandler()->getUserAccessManager(),
840 + 'showCategory'
841 + )
842 + );
843 +
844 + if ($removeSucc) {
845 + $args = array(
846 + 'child_of' => $category->id,
847 + 'hide_empty' => false
848 + );
849 +
850 + $categoryChilds = get_categories($args);
851 +
852 + add_filter(
853 + 'get_terms',
854 + array(&$userAccessManager, 'showCategory')
855 + );
856 +
857 +
858 + foreach ($categoryChilds as $categoryChild) {
859 + $curCategoryChild = new stdClass();
860 + $curCategoryChild->id = $categoryChild->term_id;
861 + $curCategoryChild->name = $categoryChild->name;
862 +
863 + $curCategoryChild->recursiveMember
864 + = array('category' => array());
865 + $curCategoryChild->recursiveMember['category'][]
866 + = $curCategoryChild;
867 + $categories[$curCategoryChild->id]
868 + = $curCategoryChild;
869 + }
870 + }
1202 871 }
872 +
873 + $categories[$category->id] = $category;
1203 874 }
1204 875 }
1205 876
1206 - return $this->{$postType.'s'}[$type];
877 + return $categories;
1207 878 }
1208 879
880 +
881 + /*
882 + * Group posts functions.
883 + */
884 +
1209 885 /**
1210 - * Removes all post of all types from the user group.
886 + * Returns the membership of a single post.
1211 887 *
1212 - * @param string $postType The type which should be deleted.
888 + * @param string $postType The post type needed for the intern representation.
889 + * @param integer $objectId The object id.
1213 890 *
1214 - * @return null;
891 + * @return object
1215 892 */
1216 - private function _deletePostByTypeFromDb($postType)
893 + private function _getFullPost($postType, $objectId)
1217 894 {
1218 - if ($this->id == null) {
1219 - return false;
1220 - }
895 + $post = get_post($objectId);
1221 896
1222 - global $wpdb;
897 + $isRecursiveMember = array();
1223 898
1224 - if ($postType == 'all') {
1225 - $wpdb->query(
1226 - "DELETE FROM " . DB_ACCESSGROUP_TO_POST . "
1227 - WHERE group_id = ".$this->id
1228 - );
1229 - } else {
1230 - if ($type == 'post') {
1231 - $curPostTypes = $this->getPosts();
1232 - } elseif ($type == 'page') {
1233 - $curPostTypes = $this->getPages();
1234 - } elseif ($type == 'file') {
1235 - $curPostTypes = $this->getFiles();
899 + $userAccessManager = $this->getAccessHandler()->getUserAccessManager();
900 + $uamOptions = $userAccessManager->getAdminOptions();
901 +
902 + foreach ($this->getObjectsFromType('category', 'full') as $category) {
903 + if (in_category($category->id, $post->ID)) {
904 + $categoryObject = get_category($category->id);
905 + $category->name = $categoryObject->name;
906 +
907 + $isRecursiveMember['category'][] = $category;
1236 908 }
1237 -
1238 - foreach ($curPostTypes as $id => $post) {
1239 - $wpdb->query(
1240 - "DELETE FROM " . DB_ACCESSGROUP_TO_POST . "
1241 - WHERE group_id = ".$this->id."
1242 - AND post_id = ".$id."
1243 - LIMIT 1"
1244 - );
1245 - }
1246 909 }
1247 - }
910 +
911 + if (($postType == 'page'
912 + || $postType == 'attachment')
913 + && $uamOptions['lock_recursive'] == 'true'
914 + && $post->post_parent != 0
915 + ) {
916 + $parentPost = $this->_getSingleObject(
917 + $postType,
918 + $post->post_parent,
919 + 'full'
920 + );
1248 921
1249 - /**
1250 - * Returns the pages in the group
1251 - *
1252 - * @param string $type The return type. Can be real or full.
1253 - *
1254 - * @return array
1255 - */
1256 - function getPosts($type = 'real')
1257 - {
1258 - return $this->_getPostByType('post', $type);
1259 - }
1260 -
1261 - /**
1262 - * Adds a post to the post group.
1263 - *
1264 - * @param integer $postID The post id which should be added.
1265 - *
1266 - * @return null
1267 - */
1268 - function addPost($postID)
1269 - {
1270 - $this->getPosts();
1271 - $this->posts['real'][$postID] = get_post($postID);
1272 - $this->posts['full'] = -1;
1273 - }
1274 -
1275 - /**
1276 - * Removes a post from the post group.
1277 - *
1278 - * @param integer $postID The post id which should be removed.
1279 - *
1280 - * @return null
1281 - */
1282 - function removePost($postID)
1283 - {
1284 - $this->getPosts();
1285 - unset($this->posts['real'][$postID]);
1286 - $this->posts['full'] = -1;
1287 - }
1288 -
1289 - /**
1290 - * Unsets the posts.
1291 - *
1292 - * @param boolean $plusRemove If true also database entrys will remove.
1293 - *
1294 - * @return null;
1295 - */
1296 - function unsetPosts($plusRemove = false)
1297 - {
1298 - if ($plusRemove) {
1299 - $this->_deletePostByTypeFromDb('post');
922 + if ($parentPost !== null) {
923 + $postObject = get_post($parentPost->id);
924 + $parentPost->name = $postObject->post_title;
925 +
926 + $isRecursiveMember['post'][] = $parentPost;
927 + }
1300 928 }
1301 -
1302 - $this->posts = array(
1303 - 'real' => array(),
1304 - 'full' => array(),
1305 - );;
929 +
930 + return $isRecursiveMember;
1306 931 }
932 +
1307 933
1308 - /**
1309 - * Returns the pages in the group
1310 - *
1311 - * @param string $type The return type. Can be real or full.
1312 - *
1313 - * @return array
934 + /*
935 + * Group pluggable objects functions.
1314 936 */
1315 - function getPages($type = 'real')
1316 - {
1317 - return $this->_getPostByType('page', $type);
1318 - }
1319 937
1320 938 /**
1321 - * Adds a page to the page group.
939 + * Returns a the recursive membership for a pluggable object.
1322 940 *
1323 - * @param integer $pageID The page id which should be added.
941 + * @param string $objectType The pluggable object type.
942 + * @param integer $objectId The object id.
1324 943 *
1325 - * @return null
1326 - */
1327 - function addPage($pageID)
1328 - {
1329 - $this->getPages();
1330 - $this->pages['real'][$pageID] = get_post($pageID);
1331 - $this->pages['full'] = -1;
1332 - }
1333 -
1334 - /**
1335 - * Removes a page from the page group.
1336 - *
1337 - * @param integer $pageID The page id which should be removed.
1338 - *
1339 - * @return null
1340 - */
1341 - function removePage($pageID)
1342 - {
1343 - $this->getPages();
1344 - unset($this->pages['real'][$pageID]);
1345 - $this->pages['full'] = -1;
1346 - }
1347 -
1348 - /**
1349 - * Unsets the pages.
1350 - *
1351 - * @param boolean $plusRemove If true also database entrys will remove.
1352 - *
1353 - * @return null;
1354 - */
1355 - function unsetPages($plusRemove = false)
1356 - {
1357 - if ($plusRemove) {
1358 - $this->_deletePostByTypeFromDb('page');
1359 - }
1360 -
1361 - $this->pages = array(
1362 - 'real' => array(),
1363 - 'full' => array(),
1364 - );;
1365 - }
1366 -
1367 - /**
1368 - * Returns the files in the group
1369 - *
1370 - * @param string $type The return type. Can be real or full.
1371 - *
1372 944 * @return array
1373 945 */
1374 - function getFiles($type = 'real')
946 + private function _getFullPlObject($objectType, $objectId)
1375 947 {
1376 - return $this->_getPostByType('file', $type);
1377 - }
1378 -
1379 - /**
1380 - * Adds a file to the file group.
1381 - *
1382 - * @param integer $fileID The file id which should be added.
1383 - *
1384 - * @return null
1385 - */
1386 - function addFile($fileID)
1387 - {
1388 - $this->getFiles();
1389 - $this->files['real'][$fileID] = get_post($fileID);
1390 - $this->files['full'] = -1;
1391 - }
1392 -
1393 - /**
1394 - * Removes a file from the file group.
1395 - *
1396 - * @param integer $fileID The file id which should be removed.
1397 - *
1398 - * @return null
1399 - */
1400 - function removeFile($fileID)
1401 - {
1402 - $this->getFiles();
1403 - unset($this->files['real'][$fileID]);
1404 - $this->files['full'] = -1;
1405 - }
1406 -
1407 - /**
1408 - * Unsets the files.
1409 - *
1410 - * @param boolean $plusRemove If true also database entrys will remove.
1411 - *
1412 - * @return null;
1413 - */
1414 - function unsetFiles($plusRemove = false)
1415 - {
1416 - if ($plusRemove) {
1417 - $this->_deletePostByTypeFromDb('file');
1418 - }
948 + $isRecursiveMember = array();
1419 949
1420 - $this->files = array(
1421 - 'real' => array(),
1422 - 'full' => array(),
1423 - );
1424 - }
1425 -
1426 - /**
1427 - * Checks if the given post is a member of the group.
1428 - *
1429 - * @param interger $postId The id of the post which should be checked.
1430 - * @param boolean $withInfo If true then we return additional infos.
1431 - *
1432 - * @return boolean
1433 - */
1434 - function postIsMember($postId, $withInfo = false)
1435 - {
1436 - $post = get_post($postId);
950 + $plObject = $this->getAccessHandler()->getPlObject($objectType);
1437 951
1438 - if ($post->post_type == 'attachment') {
1439 - $postType = 'file';
1440 - } else {
1441 - $postType = $post->post_type;
1442 - }
1443 -
1444 - $post = $this->_getSinglePost($post, 'full', $postType);
1445 -
1446 - if ($post !== null) {
1447 - if (isset($post->recursiveMember)
1448 - && $withInfo
1449 - ) {
1450 - return $post->recursiveMember;
952 + if (isset($plObject['reference'])
953 + && isset($plObject['getFull'])
954 + ) {
955 + $plRecMember = $plObject['reference']->{$plObject['getFull']}(
956 + $objectId,
957 + &$this
958 + );
959 +
960 + if (is_array($plRecMember)) {
961 + $isRecursiveMember = $plRecMember;
1451 962 }
1452 -
1453 - return true;
1454 963 }
1455 -
1456 - return false;
964 +
965 + return $isRecursiveMember;
1457 966 }
1458 967 }