-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome-helper.php
75 lines (65 loc) · 2.29 KB
/
home-helper.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
<?php
/*
* Project: Update API
* Author: Vontainment
* URL: https://vontainment.com
* File: home-helper.php
* Description: WordPress Update API
*/
function generateHostsTableRow($lineNumber, $domain, $key)
{
return '<tr>
<form method="post">
<input type="hidden" name="id" value="' . $lineNumber . '">
<td><input class="hosts-domain" type="text" name="domain" value="' . $domain . '"></td>
<td><input class="hosts-key" type="text" name="key" value="' . $key . '"></td>
<td>
<input class="hosts-submit" type="submit" name="update_entry" value="Update">
<input class="hosts-submit" type="submit" name="delete_entry" value="Delete">
</td>
</form>
</tr>';
}
$hostsFile = '../HOSTS';
$entries = file($hostsFile, FILE_IGNORE_NEW_LINES);
$hostsTableHtml = '';
if (count($entries) > 0) {
$halfCount = ceil(count($entries) / 2);
$entriesColumn1 = array_slice($entries, 0, $halfCount);
$entriesColumn2 = array_slice($entries, $halfCount);
$hostsTableHtml .= '<div class="row"><div class="column">
<table>
<thead>
<tr>
<th>Domain</th>
<th>Key</th>
<th>Actions</th>
</tr>
</thead>
<tbody>';
foreach ($entriesColumn1 as $lineNumber => $entry) {
$fields = explode(' ', $entry);
$domain = isset($fields[0]) ? $fields[0] : '';
$key = isset($fields[1]) ? $fields[1] : '';
$hostsTableHtml .= generateHostsTableRow($lineNumber, $domain, $key);
}
$hostsTableHtml .= '</tbody></table></div><div class="column">
<table>
<thead>
<tr>
<th>Domain</th>
<th>Key</th>
<th>Actions</th>
</tr>
</thead>
<tbody>';
foreach ($entriesColumn2 as $lineNumber => $entry) {
$fields = explode(' ', $entry);
$domain = isset($fields[0]) ? $fields[0] : '';
$key = isset($fields[1]) ? $fields[1] : '';
$hostsTableHtml .= generateHostsTableRow($lineNumber, $domain, $key);
}
$hostsTableHtml .= '</tbody></table></div></div>';
} else {
$hostsTableHtml = "No entries found.";
}