This repository has been archived by the owner on Aug 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
functions.class.php
104 lines (90 loc) · 3.76 KB
/
functions.class.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
class ProcessClass {
public $processed;
public $when;
private $config;
public function __construct() {
if(file_exists('config.ini')) {
$this->config = parse_ini_file('config.ini');
} else {
die('Cant open config.ini');
}
$this->when =(isset($_GET['w']))?$_GET['w']:"null";
$this->server =(isset($_GET['s']))?$_GET['s']:"null";
$this->processed['shots']=$this->ShotsProcess();
$this->processed['log']=$this->LogProcess();
$this->processed['actual_server']=$this->server;
$this->processed['actual_when']=$this->when;
$this->LinkActivate($this->when, $this->server);
}
public function ShotsProcess() {
$dirs = $this->config['ss_dir'];
$dirs = explode(",", $dirs);
$onedir = preg_grep('/'.$this->server.'/',$dirs);
$dir = array_shift( $onedir );
//var_dump($dir);die();
$count=0;
// Getting the directory list
if ($handle = opendir($dir)) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
$timestamp = filemtime($dir.'/'.$entry);
if ($this->when=="today") {
$terms = date('Ymd') == date('Ymd', $timestamp);
} elseif ($this->when=="hour") {
$terms = strtotime('-1 hour') < $timestamp;
} elseif($this->when=="all") {
$terms = true;
} else { $terms = false; }
if ($terms) {
$retval[$count]['name'] = $entry;
$retval[$count]['path'] = str_replace("#", "%23", $entry);
$retval[$count]['date'] = $timestamp;
$retval[$count]['size'] = filesize($dir.'/'.$entry);
}
}
$count++;
}
closedir($handle);
}
if (!empty($retval)) {
// Sort by time descending
foreach ($retval as $key => $part) {
$sort[$key] = $part['date'];
}
array_multisort($sort, SORT_DESC, $retval);
// Convert to writeable html
$out = "<ul class='thumbs'>";
foreach ($retval as $a) {
$out .= '<li>
<img src="'.$dir.'/'.$a['path'].'" class="img-thumbnail">
<br/><b>'.substr($a['name'],0,-8).'</b> #'.substr($a['name'],-8,-4).' @ '.date("Y.m.d. H:i:s", $a['date']).' | '.round($a['size']/1024).'kB</li>';
}
$out .= "</ul>";
} else { $out = "No data here"; }
return $out;
}
public function LogProcess() {
$file = file_get_contents($this->config['log_file']);
return $file;
}
public function LinkActivate($w=null,$s=null) {
if ($w=="hour") { $this->processed['active_hour'] = "active";}
if ($w=="today") { $this->processed['active_today'] = "active";}
if ($w=="all") { $this->processed['active_all'] = "active";}
if ($s=="tdm") { $this->processed['active_tdm'] = "active";}
if ($s=="sd") { $this->processed['active_sd'] = "active";}
}
public function render($file) {
$output = file_get_contents($file);
preg_match_all("/(?<=\{{ )(.*?)(?=\ }})/", $output, $values);
foreach($values[0] as $v) {
if (isset($this->config[$v])) {
$output = str_replace("{{ $v }}", $this->config[$v], $output);
} elseif (isset($this->processed[$v])) {
$output = str_replace("{{ $v }}", $this->processed[$v], $output);
}
}
return $output;
}
}