/** * array Online::getOnlineUsers () * Returns a list of all users who are currently online. */ function getOnlineUsers() { $dbh = Planworld::_connect(); $query = "SELECT users.username, online.last_access, online.login, online.what FROM users, online WHERE users.id = online.uid ORDER BY last_access DESC"; /* execute the query */ $result = $dbh->query($query); if (isset($result) && !DB::isError($result)) { $return = array(); while ($row = $result->fetchRow()) { $return[] = array('name' => $row['username'], 'lastAccess' => (int) $row['last_access'], 'login' => (int) $row['login'], 'what' => $row['what']); } return $return; } else { return PLANWORLD_ERROR; } }
/** * 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); }
function previewPlan(&$user, $plan) { $timestamp = mktime(); /* format the journalled plan */ if ($this->getPreference('journal')) { if (!($divider = $this->getPreference('journal_divider'))) { $divider = PW_DIVIDER; } if ($this->getPreference('journal_order') == 'new') { // show current plan $tmp = Planworld::getDisplayDivider($divider, $timestamp) . "\n" . $plan . "\n"; // show archived plans for ($i = 0; $i < $this->getPreference('journal_entries'); $i++) { list($ts, $txt) = Archive::getEntryByIndex($this->userID, $i); if ($ts == 0) { break; } $tmp .= Planworld::getDisplayDivider($divider, $ts) . "\n"; $tmp .= $txt . "\n"; } $plan = $tmp; } else { $tmp = ''; for ($i = $this->getPreference('journal_entries') - 1; $i >= 0; $i--) { list($ts, $txt) = Archive::getEntryByIndex($this->userID, $i); if ($ts == 0) { break; } $tmp .= Planworld::getDisplayDivider($divider, $ts) . "\n"; $tmp .= $txt . "\n"; } // show current plan $tmp .= Planworld::getDisplayDivider($divider, $timestamp) . "\n" . $plan . "\n"; $plan = $tmp; } } return $this->displayPlan($user, $plan); }
#!/usr/local/bin/php -q <?php /** * $Id: cache.php,v 1.7 2002/03/03 22:19:51 seth Exp $ * XML-RPC cache: updates LastUpdate and LastLogin for all remote * users on planwatches. */ $_base = dirname(__FILE__) . '/../'; require_once $_base . 'config.php'; require_once $_base . 'lib/Planworld.php'; // display errors in a readable format (since this is run from cron) ini_set('html_errors', 'off'); $dbh = Planworld::_connect(); $query = "SELECT DISTINCT users.username FROM planwatch, users WHERE planwatch.w_uid=users.id AND users.remote='Y'"; $result = $dbh->query($query); $hosts = array(); while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) { list($user, $host) = split('@', $row['username']); if (!in_array($host, $hosts)) { $hosts[] = $host; } if (!isset(${$host})) { ${$host} = array(); } array_push(${$host}, $user); } foreach ($hosts as $host) { Planworld::getLastUpdate(${$host}, $host); Planworld::getLastLogin(${$host}, $host); }
function sendPost($params) { $argToken =& $params[0]; $otherPartyUsername =& $params[1]; $sendMessage =& $params[2]; $sendConfirm = false; $tokenObject = new NodeToken(); $tokenObject->retrieveToken($argToken); if ($tokenObject->valid) { $sourceUserId = $tokenObject->uid; $otherPartyUid = Planworld::nameToId($otherPartyUsername); Send::sendMessage($sourceUserId, $otherPartyUid, $sendMessage); /* The sendMessage function currently has no return code, so we fake it.*/ $sendConfirm = true; statusCode(201); } else { $sendConfirm = false; statusCode(401); } return $sendConfirm; /* Please see the API notes towards bottom for ways in which this function will change soon. */ }
function getReferences(&$user, $order = 'd', $dir = 'd') { $dbh = Planworld::_connect(); /* direction to sort */ if ($dir == 'a') { $dir = 'ASC'; } else { $dir = 'DESC'; } /* attribute to sort by */ switch ($order) { case 'l': $order = 'last_update'; break; case 'u': $order = 'username'; break; default: $order = 'referenced'; } if (is_int($user)) { $query = "SELECT s_uid, referenced, username, last_update FROM snoop,users WHERE uid={$user} AND users.id=s_uid ORDER BY {$order} {$dir}"; } else { if (is_string($user)) { $query = "SELECT s_uid, referenced, users.username, users.last_update FROM snoop,users,users as u2 WHERE uid=u2.id AND u2.username='******' AND users.id=s_uid ORDER BY {$order} {$dir}"; } else { if (is_object($user)) { $query = "SELECT s_uid, referenced, username, last_update FROM snoop,users WHERE uid=" . $user->getUserID() . " AND users.id=s_uid ORDER BY {$order} {$dir}"; } } } /* execute the query */ $result = $dbh->query($query); if (isset($result) && !DB::isError($result)) { $return = array(); if (date('n-j') == '4-1') { /* April fool's easter egg */ $uid = Planworld::getRandomUser(); $return[] = array("userID" => $uid, "userName" => Planworld::idToName($uid), "date" => mktime(0, 0, 0, 4, 1, date('Y')), "lastUpdate" => Planworld::getLastUpdate($uid)); } while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) { $return[] = array("userID" => (int) $row['s_uid'], "userName" => $row['username'], "date" => (int) $row['referenced'], "lastUpdate" => (int) $row['last_update']); } return $return; } else { return PLANWORLD_ERROR; } }
/** * void add ($uid) * Adds $uid to this user's planwatch. */ function add($uid) { /* no need to fill this entry, as the planwatch will probably be reloaded before it's used */ if (is_int($uid)) { $query = "INSERT INTO planwatch (w_uid, uid) VALUES ({$uid}," . $this->user->getUserID() . ")"; } else { $query = "INSERT INTO planwatch (w_uid, uid) VALUES (" . Planworld::nameToID($uid) . "," . $this->user->getUserID() . ")"; } $this->dbh->query($query); }
function NodeToken() { $this->dbh =& Planworld::_connect(); $this->valid = false; }
function remove($list) { if (empty($list)) { return; } else { $dbh = Planworld::_connect(); if (is_array($list)) { $query = "DELETE FROM news WHERE"; $query .= " id=" . $list[0]; for ($i = 1; $i < count($list); $i++) { $query .= " OR id=" . $list[$i]; } } else { $query = "DELETE FROM news WHERE id={$list}"; } Planworld::query($query); } }
/** * bool Archive::hasPublicEntries ($uid) * returns whether $uid has any public entries */ function hasPublicEntries($uid) { $dbh =& Planworld::_connect(); /* construct the query */ if (is_string($uid)) { // $query = "SELECT COUNT(*) AS size FROM archive, users WHERE archive.uid=users.id AND users.username='******' AND archive.pub='Y'"; $query = "SELECT archive_size_pub AS size FROM users WHERE username='******'"; } else { if (is_int($uid)) { // $query = "SELECT COUNT(*) AS size FROM archive WHERE archive.uid={$uid} AND archive.pub='Y'"; $query = "SELECT archive_size_pub AS size FROM users WHERE id={$uid}"; } else { if (is_object($uid)) { // $query = "SELECT COUNT(*) AS size FROM archive WHERE archive.uid=" . $uid->getUserID() . " AND archive.pub='Y'"; $query = "SELECT archive_size_pub AS size FROM users WHERE username=" . $uid->getUserID(); } } } /* execute the query */ $result = $dbh->query($query); if (isset($result) && !DB::isError($result)) { if ($result->numRows($result) < 1) { return ARCHIVE_EMPTY; } $row = $result->fetchRow(); if (DB::isError($row)) { return ARCHIVE_ERROR; } if ($row['size'] > 0) { return true; } else { return false; } } else { return ARCHIVE_ERROR; } }
/* update this user's last login */ $_user->setLastLogin(mktime()); /* update this user's last known ip address */ $_user->setLastIP($_SERVER['REMOTE_ADDR']); /* save it to prevent planwatch weirdness */ $_user->save(); /* create an object representing the target user (or a string representing the page) */ if (isset($_GET['id'])) { $section = str_replace(' ', '', $_GET['id']); if ($section == $_user->getUsername()) { $_target =& $_user; } else { if (Planworld::isValidUser($section)) { $_target = User::factory($section); } else { if ($section == 'random') { $_target = User::factory(Planworld::getRandomUser()); } else { $_target = $section; } } } /* force fetching of update / login times if the target user is remote */ if (is_object($_target) && $_target->getType() == 'planworld') { $_target->forceUpdate(); } } /* update the current status of online users (including this one) */ Online::clearIdle(); Online::updateUser($_user, $_target); }
function get($id) { $dbh = Planworld::_connect(); $query = "SELECT cookies.id, quote, author, username, approved FROM cookies LEFT JOIN users ON cookies.s_uid=users.id WHERE cookies.id={$id}"; /* execute the query */ $result = $dbh->query($query); if (isset($result) && !DB::isError($result)) { if ($row = $result->fetchRow()) { return array('id' => $row['id'], 'quote' => $row['quote'], 'author' => $row['author'], 'credit' => $row['username'], 'approved' => $row['approved'] == 'Y' ? true : false); } else { return false; } } else { return PLANWORLD_ERROR; } }
/** * Return formatted plan contents for display. * @param user User viewing plan. * @public * @returns Plan */ function displayPlan(&$user, $plan = null, $ts = null) { $plan_txt = $this->getPlan($user, $ts); $out = ''; if (!$user->planwatch->inPlanwatch($this)) { $out .= "<tt><a href=\"" . PW_URL_BASE . "add.php?add=" . $this->username . ";trans=t\" title=\"Add " . $this->username . " to my planwatch\">(Add to my planwatch)</a></tt><br />\n"; } else { $out .= "<tt><a href=\"" . PW_URL_BASE . "add.php?add=" . $this->username . ";trans=t;remove=t\" title=\"Remove " . $this->username . " from my planwatch\">(Remove from my planwatch)</a></tt><br />\n"; } $out .= "<tt>Login name: {$this->username}"; /* user doesn't exist */ if (!$this->isUser() || $this->lastLogin == 0 && $this->lastUpdate == 0) { $out .= "<br />\n"; $out .= "Last login: ???<br />\n"; $out .= "Last update: ???<br />\n"; $out .= "Plan:<br />\n"; $out .= "[Sorry, could not find \"{$this->username}\"]</tt>\n"; } else { if ($this->lastUpdate == 0) { $out .= " (<a href=\"#\" onclick=\"return send('" . $this->username . "');\" title=\"send to " . $this->username . "\">send</a>)<br />\n"; } else { $out .= " (<a href=\"#\" onclick=\"return send('" . $this->username . "');\" title=\"send to " . $this->username . "\">send</a>)<br />\n"; $out .= "Last login: "******"<br />\n"; $out .= "Last updated: " . Planworld::getDisplayDate($this->lastUpdate) . "<br />\n"; if (isset($ts)) { $out .= "Date posted: " . Planworld::getDisplayDate($ts) . "<br />\n"; } $out .= "Plan:</tt>\n"; if (empty($plan_txt)) { $plan_txt = "<tt><br />\n[No plan]</tt>"; } /* only wordwrap if a text plan */ if (Planworld::isText($plan_txt)) { $out .= Planworld::addLinks(wordwrap($plan_txt, 76, "\n", 1), $user->getUsername(), $this->host); } else { $out .= Planworld::addLinks($plan_txt, $user->getUsername(), $this->host); } } } return $out; }
/** * int Stats::getNumArchiveEntries () * Returns the number of archive entries. */ function getNumArchiveEntries() { $dbh = Planworld::_connect(); $query = "SELECT COUNT(*) AS count FROM archive"; return (int) Planworld::query($query, 'count'); }
function xmlrpc_clientUsersWhois($method_name, $params) { $argToken =& $params[0]; $tokenObject = new NodeToken(); $tokenObject->retrieveToken($argToken); $whoisList = array(); if ($tokenObject->valid) { $databaseConnection =& Planworld::_connect(); $queryUsers = "SELECT DISTINCT users.username FROM users"; $queryResultUsers = $databaseConnection->query($queryUsers); $userRow = $queryResultUsers->fetchRow(); while ($userRow) { $whoisList[] = $userRow['username']; $userRow = $queryResultUsers->fetchRow(); } } else { $whoList[] = false; } return $whoisList; }