public function handleFile(&$file) { // Filter berücksichtigen if (strlen($this->filter) == 0 or preg_match("/({$this->filter})/{$this->i}", $file)) { parent::handleFile($file); } }
/** * verarbeitet gefundene Dateien * * @param string $file */ protected function handleFile(&$file) { // TS der letzten Änderung vergleichen $mtimeComparison = $this->compareMtime($this->mtime, filemtime($file)); if (!in_array($mtimeComparison, $this->mtimeOperator)) { return; } parent::handleFile($file); }
/** * Returns a list of users who have referenced this user's plan. * @public * @returns array */ function getSnoopRefs() { // no object variable needs to be instantiated (unless shared) as this needs // to be reloaded each time and is only relevant to the user include_once dirname(__FILE__) . '/Snoop.php'; return Snoop::getRefs($this); }
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; }
/** * void Snoop::process ($user, $new, $old) * Find new / removed snoop references in $user's plan. */ function process(&$user, $new, $old) { /* find references in old plan */ // $old_matches = Snoop::_getReferences($old); $dbh = Planworld::_connect(); $old_matches = $dbh->getCol("SELECT username FROM snoop, users WHERE snoop.uid = users.id AND s_uid = {$user->getUserID()}"); /* find references in new plan */ $new_matches = Snoop::_getReferences($new); /* find differences */ $users_to_add = Snoop::snoop_diff($new_matches[1], $old_matches); $users_to_del = Snoop::snoop_diff($old_matches, $new_matches[1]); $success = true; foreach ($users_to_add as $u) { if (strstr($u, '@')) { list($username, $host) = explode('@', $u); } $sid = Planworld::nameToID($u); if (!isset($host) && $sid > 0) { /* valid local user */ $success = $success && Snoop::addReference($user->getUserID(), $sid); } else { if (isset($host) && ($node = Planworld::getNodeInfo($host))) { /* remote planworld user */ unset($host); /* JLO2 4/12/10 Required to stop permasnoops after calling remote users. */ if ($node['Version'] < 2) { Snoop::_call($node, 'snoop.addReference', array($username, $user->getUsername() . '@' . PW_NAME)); } else { Snoop::_call($node, 'planworld.snoop.add', array($username, $user->getUsername() . '@' . PW_NAME)); } } } } foreach ($users_to_del as $u) { if (strstr($u, '@')) { list($username, $host) = explode('@', $u); } $sid = Planworld::nameToID($u); if (!isset($host) && $sid > 0) { /* valid local user */ $success = $success && Snoop::removeReference($user->getUserID(), $sid); } else { if (isset($host) && ($node = Planworld::getNodeInfo($host))) { /* remote planworld user */ unset($host); /* JLO2 4/12/10 Required to stop permasnoops after calling remote users. */ if ($node['Version'] < 2) { Snoop::_call($node, 'snoop.removeReference', array($username, $user->getUsername() . '@' . PW_NAME)); } else { Snoop::_call($node, 'planworld.snoop.remove', array($username, $user->getUsername() . '@' . PW_NAME)); } } } } return $success; }
/** * void load () * Loads planwatch data into this object. */ function load($sort = null) { /* assemble the query */ $query = "SELECT u.username, u.id, p.last_view, u.last_update, g.name AS name, g.gid AS gid, g.uid AS owner, m.seen AS hasmessage FROM (pw_groups AS g, planwatch AS p, users AS u) LEFT JOIN message AS m ON (m.uid=p.w_uid AND m.to_uid=p.uid) WHERE p.uid=" . $this->user->getUserID() . " AND p.w_uid=u.id AND g.gid=p.gid ORDER BY g.pos, g.name,"; if (!isset($sort)) { $sort = $this->user->getWatchOrder(); } switch ($sort) { case 'alph': $query .= "u.username"; break; case 'newest': $query .= "u.last_update DESC, u.username"; break; case 'old': $query .= "u.last_update, u.username"; break; default: $query .= "u.username"; } /* execute the query */ $result = $this->dbh->query($query); if (isset($result) && !DB::isError($result)) { $this->planwatch = array(); $this->groupData = array(); // initalize send group to display first $this->groupData['Stalkernet'] = array(); $this->groupData['Send'] = array(); // reset this; groups may have changed ?! $this->groups = array(); while ($row = $result->fetchRow()) { /* assemble the array */ $user = addslashes($row['username']); $group =& $row['name']; /* create the (non-group) entry */ $this->planwatch[$user] = array((int) $row['id'], (int) $row['last_update'], (int) $row['last_view'], false, isset($row['hasmessage']) && $row['hasmessage'] == 0 ? true : false); /* create a pointer to this entry within the appropriate group */ $this->groupData[$group][$user] =& $this->planwatch[$user]; /* if it's new, increment the number of new plans */ if ($row['last_update'] > $row['last_view']) { $this->numNew++; } } } /* get snoop group */ foreach (Snoop::getReferences($this->user) as $u) { $username = $u['userName']; if (!isset($this->planwatch[$username])) { /* create a new entry if one doesn't already exist */ $this->planwatch[$username] = array($u['userID'], $u['lastUpdate'], 9999999999.0); } else { $this->planwatch[$username]['count'] = 2; } $this->groupData['Snoop'][$username] =& $this->planwatch[$username]; } /* get send group */ $query = "SELECT u.username, u.id, u.last_update FROM users AS u INNER JOIN message ON u.id=message.uid LEFT JOIN online ON message.uid=online.uid WHERE message.to_uid=" . $this->user->getUserID() . " AND message.seen=0 ORDER BY username"; /* execute the query */ $result = $this->dbh->query($query); if (isset($result) && !DB::isError($result)) { while ($row = $result->fetchrow()) { $username = $row['username']; if (!isset($this->planwatch[$username])) { $this->planwatch[$username] = array($row['id'], $row['last_update'], 9999999999.0, false, true); } else { if (isset($this->groupData['Snoop'][$username])) { $this->planwatch[$username]['count'] = 3; } else { $this->planwatch[$username]['count'] = 2; } } $this->groupData['Stalkernet'][$username] =& $this->planwatch[$username]; } } /* get secondary send group */ $query = "SELECT username, id, last_update, sent, seen FROM send, users WHERE send.uid=users.id AND to_uid=" . $this->user->getUserID() . " AND seen=0 ORDER BY username"; $result = $this->dbh->query($query); if (isset($result) && !DB::isError($result)) { while ($row = $result->fetchrow()) { $username = $row['username']; if (!isset($this->planwatch[$username])) { $this->planwatch[$username] = array($row['id'], $row['last_update'], 9999999999.0, false, true); } else { if (isset($this->groupData['Snoop'][$username])) { $this->planwatch[$username]['count'] = 3; } else { $this->planwatch[$username]['count'] = 2; } } $this->groupData['Send'][$username] =& $this->planwatch[$username]; } } if (empty($this->groupData['Stalkernet'])) { unset($this->groupData['Stalkernet']); } if (empty($this->groupData['Send'])) { unset($this->groupData['Send']); } $this->changed = false; }