示例#1
0
 /**
  * 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;
 }
示例#2
0
文件: User.php 项目: jlodom/planworld
 /**
  * Return formatted plan contents for display.
  * @param user User viewing plan.
  * @param plan Plan to display (if previewing).
  * @public
  * @returns Plan
  */
 function displayPlan(&$user, $plan = null, $ts = null)
 {
     $out = '<!-- ' . $this->getUserID() . '-->';
     if (!$user->planwatch->inPlanwatch($this) && !isset($plan)) {
         $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 {
         if (!isset($plan)) {
             $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: <strong>{$this->username}</strong>";
     if ($this->isUser() && $this->isSharedFor($user)) {
         $out .= " (<a href=\"" . PW_URL_INDEX . "?id=edit_plan;u={$this->username}\">edit</a>)";
     }
     $out .= " (<a href=\"#\" onclick=\"return send('" . $this->username . "');\" title=\"send to " . $this->username . "\">send</a>)<br />\n";
     /* user doesn't exist */
     if (!$this->isUser() || $this->lastLogin == 0 && $this->lastUpdate == 0) {
         $out .= "Last login: ???<br />\n";
         $out .= "Last update: ???<br />\n";
         $out .= "Plan:<br />\n";
         $out .= "[Sorry, could not find \"{$this->username}\"]</tt>\n";
         return $out;
     } else {
         if ($this->lastUpdate == 0) {
             $out .= "Last login: "******"<br />\n";
             $out .= "Last update: Never<br />\n";
             $out .= "Plan:<br />\n";
             $out .= "[No Plan]</tt>\n";
             return $out;
         }
     }
     $out .= "Last login: "******"<br />\n";
     $out .= "Last updated: " . Planworld::getDisplayDate($this->lastUpdate);
     if (Archive::hasPublicEntries($this->userID) || $user->getUserID() == $this->userID) {
         $out .= " (<a href=\"" . PW_URL_INDEX . "?id=archiving;u=" . $this->username . "\" title=\"Archives\">archives</a>)";
     }
     $out .= "<br />\n";
     if (isset($ts)) {
         $out .= "Date posted: " . Planworld::getDisplayDate($ts);
         if ($name = Archive::getName($this->userID, $ts)) {
             $out .= ' (<strong>' . Archive::getName($this->userID, $ts) . '</strong>)';
         }
         $out .= "<br />\n";
     }
     $out .= "Plan:</tt>\n";
     /* assemble text of plan */
     if (!isset($plan)) {
         $plan_txt = $this->getPlan($user, $ts);
     } else {
         // plan was passed as a parameter (probably previewing)
         $plan_txt = $plan;
     }
     /* only wordwrap if a text plan */
     if (preg_match('/^\\<pre\\>(.*)\\<\\/pre\\>\\s*$/misD', $plan_txt)) {
         $out .= Planworld::addLinks(wordwrap($plan_txt, 76, "\n", 1), $user->getUsername());
     } else {
         $out .= Planworld::addLinks($plan_txt, $user->getUsername());
     }
     return $out;
 }
示例#3
0
function xmlrpc_clientWatchedList($method_name, $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);
    $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 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 AND g.uid = p.uid 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();
    }
    /* _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 = Planworld::getDisplayDate($snoopEntry['lastUpdate']);
            $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;
                }
                $snoopCounter++;
            }
            /* This user is not in the list already. */
            if ($isInMasterList == false) {
                $tempArray = array('userName' => $currentSnoopUsername, 'inWatchList' => false, 'lastUpdate' => $currentSnoopLastUpdate, 'lastView' => false, 'groupName' => false, 'snoopDate' => $currentSnoopLastUpdate, 'sendTo' => false, 'sendToRead' => false, 'sendFrom' => false, 'sendFromRead' => false);
                $masterList[$watchListCounter] = $tempArray;
                $watchListCounter++;
            }
        }
    }
    /* _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) {
                $masterList[$sendCounter]['sendTo'] = $sendToRow['sendTo'];
                $masterList[$sendCounter]['sendToRead'] = $sendToRow['sendToRead'];
                $isInMasterList = true;
            }
            $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++;
        }
        $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) {
                $masterList[$sendCounter]['sendFrom'] = $sendFromRow['sendFrom'];
                $masterList[$sendCounter]['sendFromRead'] = $sendFromRow['sendFromRead'];
                $isInMasterList = true;
            }
            $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++;
        }
        $sendFromRow = $queryResultFromSend->fetchRow();
    }
    return $masterList;
}