Skip to content

Commit

Permalink
Write log retrieval function
Browse files Browse the repository at this point in the history
  • Loading branch information
Pecon committed Feb 17, 2020
1 parent 0a7004d commit 71550a8
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 26 deletions.
26 changes: 0 additions & 26 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1278,30 +1278,4 @@ function bb_parse($text)

return $text;
}

function adminLogParse($log)
{
$return = "";
$lines = explode("\n", $log);

foreach($lines as $line)
{
$words = explode(" ", $line);
$wordCount = count($words);

if($wordCount < 3)
continue;

$return = $return . date("r", intval($words[0]));
$user = findUserByID(intval($words[1]));
$return = $return . " ${user['username']} (${words[1]})";

for($i = 2; $i < $wordCount; $i++)
{
$return = $return . " " . $words[$i];
}
}

return $return;
}
?>
66 changes: 66 additions & 0 deletions logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,76 @@ function addLogMessage()
querySQL($query);
}

// Add a message to just the admin log
function adminLog(string $logMessage)
{
addLogMessage($logMessage, 'admin');
}

// $types should be a valid string for the log type to get, or an array containing valid strings for the log types to get
// Returns array of log entries
function getLogs($types, int $start, int $count)
{
$validTypes = Array('info', 'warning', 'error', 'admin', 'security');

if(is_string($types))
{
$valid = false;

foreach($validTypes as $checkType)
{
if($types === $checkType)
{
$valid = true;
break;
}
}

if(!$valid)
return false;

$sql = "SELECT * FROM `logs` WHERE `logType` = '${types}' ORDER BY `logTime` DESC LIMIT ${start}, ${count};";
}
else if(is_array($types))
{
$valid = true;
foreach($types as $type)
{
if(!$valid)
break;

$valid = false;

foreach($validTypes as $checkType)
{
if($type === $checkType)
{
$valid = true;
break;
}
}
}

if(!$valid)
return false;

foreach($types as $type)
{
if(!isSet($whereClause))
$whereClause = "`logType` = '${type}'";
else
$whereClause .= " OR `logType` = '${type}'"
}
$sql = "SELECT * FROM `logs` WHERE ${whereClause} ORDER BY `logTime` DESC LIMIT ${start}, ${count}";
}

$result = querySQL($sql);

if($result === false)
return false;

$result = $result -> fetch_assoc();
return $result;
}
?>

0 comments on commit 71550a8

Please sign in to comment.