/** * Constructor. * @param uid User to initialize. * @public * @returns bool */ function RemoteUser($uid, $nodeinfo = null) { /* establish a database connection */ $this->dbh =& Planworld::_connect(); $this->type = 'planworld'; $this->username = $uid; list($this->localname, $this->host) = split('@', $this->username); if (isset($nodeinfo)) { $this->nodeinfo = $nodeinfo; } else { $this->nodeinfo = Planworld::getNodeInfo($host); } /* check if this user exists */ if (!$this->isUser()) { $this->valid = true; $this->userID = Planworld::addUser($this->username); } $this->load(); }
/** * Send a message from $uid to $to_uid */ function sendMessage($uid, $to_uid, $message) { if (Planworld::isRemoteUser($to_uid)) { list($to_user, $host) = split("@", Planworld::idToName($to_uid)); $from_user = Planworld::idToName($uid) . "@" . PW_NAME; $nodeinfo = Planworld::getNodeInfo($host); // make xml-rpc call xu_rpc_http_concise(array('method' => 'planworld.send.sendMessage', 'args' => array($from_user, $to_user, $message), 'host' => $nodeinfo['Hostname'], 'uri' => $nodeinfo['Path'], 'port' => $nodeinfo['Port'], 'debug' => 0)); $query = "INSERT INTO send (uid, to_uid, sent, seen, message) VALUES ({$uid}, {$to_uid}, " . mktime() . ", " . mktime() . ", '" . htmlentities(strip_tags(addslashes($message))) . "')"; } else { $fwd = Planworld::getPreference($to_uid, 'send_forward'); if ($fwd) { // forward the message if necessary $fwd_uid = Planworld::nameToId($fwd); error_log("forwarding to {$fwd_uid} ({$fwd})"); if (Planworld::isRemoteUser($fwd_uid)) { $fwd_message = "[fwd:" . Planworld::idToName($to_uid) . "@" . PW_NAME . "] " . $message; list($to_user, $host) = split("@", $fwd); if (!Planworld::isRemoteUser($uid)) { $from_user = Planworld::idToName($uid) . "@" . PW_NAME; } else { $from_user = Planworld::idToName($uid); list($f_user, $f_host) = split('@', $from_user); if ($f_host == $host) { $from_user = $f_user; } } $nodeinfo = Planworld::getNodeInfo($host); // make xml-rpc call xu_rpc_http_concise(array('method' => 'planworld.send.sendMessage', 'args' => array($from_user, $to_user, $fwd_message), 'host' => $nodeinfo['Hostname'], 'uri' => $nodeinfo['Path'], 'port' => $nodeinfo['Port'], 'debug' => 0)); } else { $fwd_message = "[fwd:" . Planworld::idToName($to_uid) . "] " . $message; Planworld::query("INSERT INTO send (uid, to_uid, sent, message) VALUES ({$uid}, {$fwd_uid}, " . mktime() . ", '" . htmlentities(strip_tags(addslashes($fwd_message))) . "')"); } } $query = "INSERT INTO send (uid, to_uid, sent, message) VALUES ({$uid}, {$to_uid}, " . mktime() . ", '" . htmlentities(strip_tags(addslashes($message))) . "')"; } Planworld::query($query); }
/** * 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; }
/** * string Archive::getEntry ($uid, $ts) * fetch an entry from $uid's archives with timestamp $ts */ function getEntry($uid, $ts) { if (Planworld::isRemoteUser($uid)) { list($username, $host) = split('@', Planworld::idToName($uid)); $nodeinfo = Planworld::getNodeInfo($host); if ($nodeinfo['Version'] >= 2) { return Archive::_call($nodeinfo, 'planworld.archive.get', array($username, $ts)); } } else { return Archive::_get('content', $uid, $ts); } }