function getThreads($sSort, $iNumber, $iOffset = 0, $iTimestamp = 0, $a_iOldThreads = array()) { // H?mta arrayen fr?n datak?llan $oData =& ExternalStorage::createInstance(); if (FALSE === ($a_oListThreads = $oData->getLatestListThreads($sSort, $iNumber, $iOffset))) { trigger_error("11: " . $oData->getErrorMsg(), E_USER_WARNING); return FALSE; } foreach (array_keys($a_oListThreads) as $iThread) { if ($a_oListThreads[$iThread]->getLastPostTimestamp() >= $iTimestamp) { $a_oListThreads[$iThread]->setNew(TRUE); } } foreach (array_keys($a_iOldThreads) as $key) { if ($a_oListThreads[$key]) { if ($a_iOldThreads[$key] == $a_oListThreads[$key]->getNumberPosts()) { $a_oListThreads[$key]->setNew(FALSE); } else { unset($a_iOldThreads[$key]); } } } // Returnera arrayen return $a_oListThreads; }
function Post($oUser, $sText, $iThreadID) { // Tryck in grejset i membervarsen $this->sText = $sText; $this->oUser = $oUser; $this->iPostID = 0; $this->iErrCode = 0; $this->sErrMsg = ""; $this->oData =& ExternalStorage::createInstance(); $this->iThread = $iThreadID; // Skapa timestamp $this->iCreatedTimestamp = time(); // Vi är färdiga return NULL; }
function Thread($mRubrikOrID, $oUser = NULL) { // Initiera membervas $this->oUser = ""; $this->iCreatedTimestamp = 0; $this->iReads = 0; $this->iPosts = 0; $this->oData =& ExternalStorage::createInstance(); $this->iErrorNo = 0; $this->sErrorMsg = ""; $this->sRubrik = ""; $this->iThreadID = 0; if (is_numeric($mRubrikOrID)) { // Vi ska ladda en sparad tråd // Ställ in ID't $this->iThreadID = $mRubrikOrID; // Ladda från databasen if (!$this->oData->loadThread($this)) { trigger_error("8: " . $this->oData->getErrorMsg(), E_USER_WARNING); return FALSE; } } else { // Skapa en ny tråd // Kolla så att vi har en giltig user if (!is_a($oUser, "User")) { trigger_error("6", E_USER_WARNING); return FALSE; } // Tryck in i membervarsen $this->sRubrik = $mRubrikOrID; $this->oUser = $oUser; $this->iCreatedTimestamp = time(); // Spara i databasen if (!($this->iThreadID = $this->oData->saveThread($this))) { trigger_error("7: " . $this->oData->getErrorMsg(), E_USER_WARNING); return FALSE; } } // Returnera return NULL; }
function logOn($sPassword) { // Databasinstans $oData =& ExternalStorage::createInstance(); // Jämför lösenord if (!(md5($sPassword) == $this->sPassword)) { trigger_error("33", E_USER_WARNING); return FALSE; } // Märk som inloggad if (!$oData->markOnline($this->iID)) { trigger_error("34: " . $oData->getErrorMsg, E_USER_WARNING); return FALSE; } // Lokalt $this->bOnline = TRUE; $this->iNumberLogins++; // Returnera return TRUE; }
// Loopa igenom sessioner while (!(FALSE === ($sFile = readdir($rDir)))) { if (fnmatch("sess_*", $sFile)) { if ($sTemp = file_get_contents($sDir . "/" . $sFile)) { // Finns iValid? if (!(substr($sTemp, -25, 14) == "iValidUntil|i:")) { trigger_error("48", E_USER_WARNING); } if (substr($sTemp, -11, -1) < time()) { // Tiden har löpt ut // Ta fram oUser if (!($sTemp = substr($sTemp, 6, strrpos($sTemp, "}") - 6))) { trigger_error("48", E_USER_WARNING); } if (!($sTemp = substr($sTemp, 0, strrpos($sTemp, "}") + 1))) { trigger_error("48", E_USER_WARNING); } // Deserialisera $oUser = unserialize($sTemp); // Fixa egen oData, han verkar inte ?verleve deserialiseringen $oData = ExternalStorage::createInstance(); $oData->markOffline($oUser->getID()); // Logga ut //if (!($oUser->logOff())) // trigger_error("49: ".$oUser->getErrorMsg(), E_USER_WARNING); // Ta bort fil unlink($sDir . "/" . $sFile); } } } }