/** * Clear this user's plan. * @returns void */ function clearPlan() { $refs = Snoop::_getReferences($this->getPlan($this)); /* delete one's plan */ $this->dbh->query("DELETE FROM plans WHERE uid=" . $this->userID); /* update the last update time */ $this->dbh->query("UPDATE users SET last_update=" . mktime() . " WHERE id=" . $this->userID); /* clear snoop references */ Snoop::clearReferences($this->userID); $hosts = array(); foreach ($refs[1] as $r) { if (!strstr($r, '@')) { continue; } list($user, $host) = split('@', $r); if (!in_array($host, $hosts)) { $hosts[] = $host; Snoop::clearRemoteReferences(Planworld::getNodeInfo($host), $this->username); } } }
/** * void Snoop::process ($user, $new, $old) * Find new / removed snoop references in $user's plan. */ function process(&$user, $new, $old) { /* find references in old plan */ // $old_matches = Snoop::_getReferences($old); $dbh = Planworld::_connect(); $old_matches = $dbh->getCol("SELECT username FROM snoop, users WHERE snoop.uid = users.id AND s_uid = {$user->getUserID()}"); /* find references in new plan */ $new_matches = Snoop::_getReferences($new); /* find differences */ $users_to_add = Snoop::snoop_diff($new_matches[1], $old_matches); $users_to_del = Snoop::snoop_diff($old_matches, $new_matches[1]); $success = true; foreach ($users_to_add as $u) { if (strstr($u, '@')) { list($username, $host) = explode('@', $u); } $sid = Planworld::nameToID($u); if (!isset($host) && $sid > 0) { /* valid local user */ $success = $success && Snoop::addReference($user->getUserID(), $sid); } else { if (isset($host) && ($node = Planworld::getNodeInfo($host))) { /* remote planworld user */ unset($host); /* JLO2 4/12/10 Required to stop permasnoops after calling remote users. */ if ($node['Version'] < 2) { Snoop::_call($node, 'snoop.addReference', array($username, $user->getUsername() . '@' . PW_NAME)); } else { Snoop::_call($node, 'planworld.snoop.add', array($username, $user->getUsername() . '@' . PW_NAME)); } } } } foreach ($users_to_del as $u) { if (strstr($u, '@')) { list($username, $host) = explode('@', $u); } $sid = Planworld::nameToID($u); if (!isset($host) && $sid > 0) { /* valid local user */ $success = $success && Snoop::removeReference($user->getUserID(), $sid); } else { if (isset($host) && ($node = Planworld::getNodeInfo($host))) { /* remote planworld user */ unset($host); /* JLO2 4/12/10 Required to stop permasnoops after calling remote users. */ if ($node['Version'] < 2) { Snoop::_call($node, 'snoop.removeReference', array($username, $user->getUsername() . '@' . PW_NAME)); } else { Snoop::_call($node, 'planworld.snoop.remove', array($username, $user->getUsername() . '@' . PW_NAME)); } } } } return $success; }