This repository has been archived by the owner on Sep 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
helpers.php
83 lines (62 loc) · 2.05 KB
/
helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
// adapted from http://www.geekality.net/2011/05/28/php-tail-tackling-large-files/
function tail($filename, $lines = 10, $buffer = 4096)
{
// Open the file
$f = fopen($filename, "rb");
// Jump to last character
fseek($f, -1, SEEK_END);
// Read it and adjust line number if necessary
// (Otherwise the result would be wrong if file doesn't end with a blank line)
if(fread($f, 1) != "\n") $lines -= 1;
// Start reading
$output = '';
$chunk = '';
// While we would like more
while(ftell($f) > 0 && $lines >= 0)
{
// Figure out how far back we should jump
$seek = min(ftell($f), $buffer);
// Do the jump (backwards, relative to where we are)
fseek($f, -$seek, SEEK_CUR);
// Read a chunk and prepend it to our output
$output = ($chunk = fread($f, $seek)).$output;
// Jump back to where we started reading
fseek($f, -mb_strlen($chunk, '8bit'), SEEK_CUR);
// Decrease our line counter
$lines -= substr_count($chunk, "\n");
}
// While we have too many lines
// (Because of buffer size we might have read too many)
while($lines++ < 0)
{
// Find first newline and remove all text before that
$output = substr($output, strpos($output, "\n") + 1);
}
$output = explode("\n",rtrim($output, "\n"));
// Close file and return
fclose($f);
return $output;
}
function translation($string) {
$translation = c::get('logger.translation', false);
if(!$translation) {
$translations = require __DIR__ . DS . 'translations.php';
$language = c::get('logger.language', c::get('panel.language'));
if (! array_key_exists($language, $translations)) {
$language = 'en';
}
$translation = $translations[$language];
}
if(array_key_exists($string, $translation)) {
$string = $translation[$string];
}
return $string;
}
function createLogfile($path) {
try {
$file = f::write($path, '');
} catch(Exception $e) {
throw new Exception('The file could not be created');
}
}