示例#1
0
 /**
  * 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;
     }
 }
示例#2
0
文件: User.php 项目: jlodom/planworld
 /**
  * Constructor.
  * @param uid User to initialize.
  * @public
  * @returns bool
  */
 function User($uid)
 {
     /* establish a database connection */
     $this->dbh =& Planworld::_connect();
     $this->type = 'local';
     if (is_string($uid)) {
         $this->username = $uid;
     } else {
         if (is_int($uid)) {
             $this->userID = (int) $uid;
         }
     }
     /* check if this user exists */
     if (isset($this->userID) || $this->isUser()) {
         $this->load();
     }
 }
示例#3
0
 /**
  * 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();
 }
示例#4
0
文件: Send.php 项目: jlodom/planworld
 /**
  * Return all messages between $uid and $to_uid
  */
 function getMessages($uid, $to_uid)
 {
     $dbh = Planworld::_connect();
     $query = "UPDATE send SET seen=" . mktime() . " WHERE uid={$to_uid} AND to_uid={$uid} AND seen=0";
     $dbh->query($query);
     $query = "SELECT uid, to_uid, sent, message FROM send WHERE (uid={$uid} AND to_uid={$to_uid}) OR (uid={$to_uid} AND to_uid={$uid}) ORDER BY sent ASC";
     $result = $dbh->query($query);
     if (isset($result) && !DB::isError($result)) {
         $return = array();
         while ($row = $result->fetchRow()) {
             if (preg_match("/^(\\[fwd:.+\\])(.*)\$/", $row['message'], $matches)) {
                 $message = "<span class=\"forward\">{$matches[1]}</span>{$matches[2]}";
             } else {
                 $message = $row['message'];
             }
             $return[] = array("uid" => (int) $row['uid'], "to_uid" => (int) $row['to_uid'], "sent" => (int) $row['sent'], "message" => $message);
         }
         return $return;
     } else {
         return PLANWORLD_ERROR;
     }
 }
示例#5
0
#!/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);
}
示例#6
0
function watchlistGet($params)
{
    /* CLEANUP: 1) Figure out a way to redirect queries.
    						2) Check for valid token.
    						3) More comments and overall code improvement.
    
    	/* Grab arguments and generate variables and objects from them. */
    $argToken =& $params[0];
    $tokenObject = new NodeToken();
    $tokenObject->retrieveToken($argToken);
    if ($tokenObject->valid) {
        $sourceUserId = $tokenObject->uid;
        $sourceUserName = $tokenObject->usernameFromUid($sourceUserId);
        $sourceUserObject = User::factory($sourceUserName);
        /* Proposed Algorithm:
        			Get Watchlist. Build a temporary table of usernames to user ids.
        			Build a table of all these users with the above values.
        			Fill in the first 4 values.
        			Get all snoops and iterate, matching for users above.
        			If found, fill in. If not found, new table row.
        			Get all sends sent and iterate as above.
        			Get all sends received and iterate as above.	
        		
        		
        			Fields:
        			userName, inWatchList, lastUpdate, lastView, groupName, snoopDate, sendTo, sendToRead, sendFrom, sendFromRead 
        		*/
        $databaseConnection =& Planworld::_connect();
        $masterList = array();
        /* _Watchlist Section_
        		Query based on first loadWatchList query in the Planworld class. The differences are 1) g.uid = p.uid in WHERE clause to guarantee single results. 2) u.username required in ORDER BY just because.	*/
        $queryMainList = "SELECT DISTINCT u.username AS userName, u.last_update AS lastUpdate, p.last_view AS lastView, g.name AS groupName FROM (pw_groups AS g, planwatch AS p, users AS u) WHERE p.uid=" . $sourceUserId . " AND p.w_uid=u.id AND g.gid=p.gid ORDER BY g.pos, g.name, u.username";
        $queryResultMainList = $databaseConnection->query($queryMainList);
        /* Create an array for the users in the watchlist. We will append to this array with snoop and send as needed. */
        $watchListCounter = 0;
        $watchListRow = $queryResultMainList->fetchRow();
        while ($watchListRow) {
            $tempArray = array('userName' => false, 'inWatchList' => false, 'lastUpdate' => false, 'lastView' => false, 'groupName' => false, 'snoopDate' => false, 'sendTo' => false, 'sendToRead' => false, 'sendFrom' => false, 'sendFromRead' => false);
            $tempArray['userName'] = $watchListRow['userName'];
            $tempArray['inWatchList'] = true;
            $tempArray['lastUpdate'] = $watchListRow['lastUpdate'];
            $tempArray['lastView'] = $watchListRow['lastView'];
            $tempArray['groupName'] = $watchListRow['groupName'];
            $masterList[$watchListCounter] = $tempArray;
            $watchListCounter++;
            $watchListRow = $queryResultMainList->fetchRow();
            unset($tempArray);
        }
        /* _Snoop Section_	*/
        $snoopList = Snoop::getReferences($sourceUserObject, 'd', 'd');
        if (empty($snoopList) || !is_array($snoopList)) {
            $snoopList = null;
        } else {
            foreach ($snoopList as $snoopEntry) {
                $currentSnoopUsername = $snoopEntry['userName'];
                $currentSnoopDate = $snoopEntry['date'];
                $currentSnoopLastUpdate = $snoopEntry['lastUpdate'];
                $currentSnoopLastView = false;
                $isInMasterList = false;
                $snoopCounter = 0;
                foreach ($masterList as $masterListRow) {
                    /* The user is already in the list. */
                    if (strcasecmp($masterListRow['userName'], $currentSnoopUsername) == 0) {
                        $masterList[$snoopCounter]['snoopDate'] = $currentSnoopDate;
                        $isInMasterList = true;
                    } else {
                        /* This bit is costly, but useful down the line if we have to expand. */
                        $queryforSnoopSnitch = "SELECT DISTINCT snitch.last_view AS snoopView FROM snitch WHERE snitch.s_uid = " . $sourceUserId . " AND snitch.uid = " . $tokenObject->uidFromUsername($currentSnoopUsername) . "";
                        $queryforSnoopSnitchResult = $databaseConnection->query($queryforSnoopSnitch);
                        $queryforSnoopSnitchRow = $queryforSnoopSnitchResult->fetchRow();
                        $currentSnoopLastView = $queryforSnoopSnitchRow['snoopView'];
                    }
                    $snoopCounter++;
                }
                /* This user is not in the list already. */
                if ($isInMasterList == false) {
                    $tempArray = array('userName' => $currentSnoopUsername, 'inWatchList' => false, 'lastUpdate' => $currentSnoopLastUpdate, 'lastView' => $currentSnoopLastView, 'groupName' => false, 'snoopDate' => $currentSnoopLastUpdate, 'sendTo' => false, 'sendToRead' => false, 'sendFrom' => false, 'sendFromRead' => false);
                    $masterList[$watchListCounter] = $tempArray;
                    $watchListCounter++;
                    unset($tempArray);
                }
            }
        }
        /* _Send Section_ 
        		Some of this is new for version 3.
        		We want 1) If a conversation exists. 2) The last time both parties wrote a message. 3) The last time both parties read a message.
        		*/
        $queryToSend = "SELECT DISTINCT u.username AS userName, s.sent AS sendTo, s.seen AS sendToRead FROM (users AS u, send AS s) WHERE s.uid = " . $sourceUserId . " AND s.to_uid = u.id ORDER BY s.sent";
        $queryResultToSend = $databaseConnection->query($queryToSend);
        $sendCounter = 0;
        $sendToRow = $queryResultToSend->fetchRow();
        while ($sendToRow) {
            $isInMasterList = false;
            $sendCounter = 0;
            $currentSendUserName = $sendToRow['userName'];
            foreach ($masterList as $masterListRow) {
                /* The user is already in the list. */
                if (strcasecmp($masterListRow['userName'], $currentSendUserName) == 0) {
                    $isInMasterList = true;
                    $masterList[$sendCounter]['sendTo'] = $sendToRow['sendTo'];
                    $masterList[$sendCounter]['sendToRead'] = $sendToRow['sendToRead'];
                }
                $sendCounter++;
            }
            if ($isInMasterList == false) {
                $tempArray = array('userName' => $currentSendUserName, 'inWatchList' => false, 'lastUpdate' => false, 'lastView' => false, 'lastView' => false, 'groupName' => false, 'snoopDate' => false, 'sendTo' => $sendToRow['sendTo'], 'sendToRead' => $sendToRow['sendToRead'], 'sendFrom' => false, 'sendFromRead' => false);
                $masterList[$watchListCounter] = $tempArray;
                $watchListCounter++;
                unset($tempArray);
            }
            $sendToRow = $queryResultToSend->fetchRow();
        }
        $queryFromSend = "SELECT DISTINCT u.username AS userName, s.sent AS sendFrom, s.seen AS sendFromRead FROM (users AS u, send AS s) WHERE s.to_uid = " . $sourceUserId . " AND s.uid = u.id ORDER BY s.sent";
        $queryResultFromSend = $databaseConnection->query($queryFromSend);
        $sendCounter = 0;
        $sendFromRow = $queryResultFromSend->fetchRow();
        while ($sendFromRow) {
            $isInMasterList = false;
            $sendCounter = 0;
            $currentSendUserName = $sendFromRow['userName'];
            foreach ($masterList as $masterListRow) {
                /* The user is already in the list. */
                if (strcasecmp($masterListRow['userName'], $currentSendUserName) == 0) {
                    $isInMasterList = true;
                    $masterList[$sendCounter]['sendFrom'] = $sendFromRow['sendFrom'];
                    $masterList[$sendCounter]['sendFromRead'] = $sendFromRow['sendFromRead'];
                }
                $sendCounter++;
            }
            if ($isInMasterList == false) {
                $tempArray = array('userName' => $currentSendUserName, 'inWatchList' => false, 'lastUpdate' => false, 'lastView' => false, 'lastView' => false, 'groupName' => false, 'snoopDate' => false, 'sendTo' => false, 'sendToRead' => false, 'sendFrom' => $sendFromRow['sendFrom'], 'sendFromRead' => $sendFromRow['sendFromRead']);
                $masterList[$watchListCounter] = $tempArray;
                $watchListCounter++;
                unset($tempArray);
            }
            $sendFromRow = $queryResultFromSend->fetchRow();
        }
    } else {
        $masterList = false;
        statusCode(401);
    }
    return $masterList;
}
示例#7
0
 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;
     }
 }
示例#8
0
 /**
  * void save ()
  * Saves planwatch data.
  */
 function save()
 {
     if ($this->changed) {
         $this->dbh = Planworld::_connect();
         foreach ($this->planwatch as $u => $entry) {
             if (isset($entry[3]) && $entry[3]) {
                 /* entry was changed; let's save it */
                 $query = "UPDATE planwatch SET last_view=" . $entry[1] . " WHERE uid=" . $this->user->getUserID() . " AND w_uid=" . Planworld::nameToID($u);
                 $this->dbh->query($query);
             }
         }
     }
 }
示例#9
0
 function NodeToken()
 {
     $this->dbh =& Planworld::_connect();
     $this->valid = false;
 }
示例#10
0
 /**
  * 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;
     }
 }
示例#11
0
文件: News.php 项目: jlodom/planworld
 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);
     }
 }
示例#12
0
 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;
     }
 }
示例#13
0
 /**
  * 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');
 }
示例#14
0
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;
}