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; } }
/* 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); }