Created
September 13, 2010 20:52
-
-
Save anonymous/578029 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function apci_groups_user_is_groupmate($op, $user = NULL) { | |
| switch ($op) { | |
| case 'cache' : | |
| // insert code here to return the cache_id name | |
| if (arg(0) == 'user' && is_numeric(arg(1))) { | |
| $uid = arg(1); | |
| } | |
| elseif (arg(0) == 'node' && is_numeric(arg(1))) { | |
| $uid = _vr_get_author(arg(1)); | |
| } | |
| if (!isset($uid)) { | |
| return NULL; | |
| } | |
| if ($uid == $user->uid) { | |
| return FALSE; | |
| } | |
| return "apci_groups_user_is_groupmate:$user->uid:$uid"; | |
| break; | |
| case 'process' : | |
| // insert code here to evaluate the context | |
| if (arg(0) == 'user' && is_numeric(arg(1))) { | |
| $uid = arg(1); | |
| } | |
| elseif (arg(0) == 'node' && is_numeric(arg(1))) { | |
| $uid = _vr_get_author(arg(1)); | |
| } | |
| if (!isset($uid)) { | |
| return FALSE; | |
| } | |
| if ($uid == $user->uid) { | |
| return FALSE; | |
| } | |
| return _apci_groups_users_in_same_group($user->uid, $uid); | |
| break; | |
| } | |
| } | |
| /** | |
| * Helper function for determining whether or not users are in the same group | |
| */ | |
| function _apci_groups_users_in_same_group($uid1, $uid2) { | |
| static $friends = array(); | |
| if (isset($frields[$uid1][$uid2])) { | |
| return $friends[$uid1][$uid2]; | |
| } | |
| $sql = 'SELECT n.nid, oru.uid AS uid1, oru2.uid AS uid2 FROM node n LEFT JOIN og_rap_uid oru ON n.nid = oru.nid LEFT JOIN og_rap orap ON oru.rid = orap.rid LEFT JOIN og_rap_uid oru2 ON n.nid = oru2.nid LEFT JOIN og_rap orap2 ON oru2.rid = orap2.rid WHERE orap.type = "participant" AND orap2.type = "participant" AND oru.uid = %d AND oru2.uid = %d'; | |
| $resource = db_query($query, $uid1, $uid2); | |
| if (!empty(db_fetch_array($resource))) { | |
| $friends[$uid1][$uid2] = TRUE; | |
| } | |
| else { | |
| $friends[$uid1][$uid2] = FALSE; | |
| } | |
| return $friends[$uid1][$uid2]; | |
| } | |
| /** | |
| * Helper function for determining the author of a node. | |
| */ | |
| function _apci_groups_get_author($nid) { | |
| static $node = array(); | |
| if (isset($node[$nid])) { | |
| return $node[$nid]; | |
| } | |
| $sql = "SELECT n.uid FROM {node} n WHERE n.nid = %d LIMIT 1"; | |
| $resource = db_query($sql, $nid); | |
| if ($result = db_result($resource)) { | |
| $node[$nid] = $result; | |
| return $result; | |
| } | |
| $node[$nid] = FALSE; | |
| return $node[$nid]; | |
| } | |
| /** | |
| * Wrapper if() statement to protect against duplicate function names. | |
| */ | |
| if (!function_exists('_vr_get_author')) { | |
| function _vr_get_author($nid) { | |
| return _apci_groups_get_author($nid); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment