-
Notifications
You must be signed in to change notification settings - Fork 0
/
Functions.php
60 lines (50 loc) · 1.35 KB
/
Functions.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
<?php
class Functions {
public static function escape($input)
{
return htmlspecialchars(strip_tags($input));
}
public static function bindAll($values, $stmt, $exceptions = [])
{
foreach ($values as $key => $value) {
$paramName = is_numeric($key) ? $key + 1 : ':' . $key;
$type = isset($exceptions[$key]) ? $exceptions[$key] : gettype($value);
switch ($type) {
case 'boolean':
$typeConst = PDO::PARAM_BOOL;
break;
case 'NULL':
$typeConst = PDO::PARAM_NULL;
break;
case 'integer':
$typeConst = PDO::PARAM_INT;
break;
case 'double':
case 'string':
$typeConst = PDO::PARAM_STR;
break;
}
$stmt->bindValue($paramName, $value, $typeConst);
}
}
public static function renderTable($content, $headers = [], $exceptions = [])
{
$html = '';
if (!empty($headers)) {
$html .= '<tr class="table-headers">';
foreach ($headers as $key => $header) {
$html .= "<th class=\"table-header $key\">" . self::escape($header) . '</th>';
}
$html .= '</tr>';
}
foreach ($content as $row) {
$html .= '<tr class="park">';
foreach ($row as $key => $column) {
if (in_array($key, $exceptions, true)) continue;
$html .= "<td class=\"$key text-collapse\"><span class=\"content-text\">" . self::escape($column) . '</span></td>';
}
$html .= '</tr>';
}
return $html;
}
}