示例#1
0
文件: Send.php 项目: jlodom/planworld
 /**
  * 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);
 }
示例#2
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;
     }
 }
示例#3
0
 /**
  * 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);
     }
 }