forked from Delo-Design/radicalform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistoryradicalform.php
159 lines (138 loc) · 4.7 KB
/
historyradicalform.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
/**
* @package Joomla.Plugin
* @subpackage System.Radicalform
*
* @copyright Copyright 2018 Progreccor
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die('Restricted access');
class JFormFieldHistoryradicalform extends JFormField {
private function getCSV($file, $delimiter = ';')
{
$a = [];
if (file_exists($file) && ($handle = fopen($file, 'r')) !== false)
{
while (($data = fgetcsv($handle, 200000, $delimiter)) !== false)
{
$a[] = $data;
}
fclose($handle);
}
return $a;
}
function getInput() {
$params=$this->form->getData()->get("params");
$config = JFactory::getConfig();
$site_offset = $config->get('offset'); //get offset of joomla time like asia/kolkata
$log_path = str_replace('\\', '/', JFactory::getConfig()->get('log_path'));
$data = $this->getCSV($log_path . '/plg_system_radicalform.php', "\t");
if(count($data)>0)
{
for ($i = 0; $i < 6; $i++)
{
if (count($data[$i]) < 4 || $data[$i][0][0] == '#')
{
unset($data[$i]);
}
}
}
$data = array_reverse($data);
$cnt = count($data);
if ($cnt)
{
$html= "<p>".JText::_('PLG_RADICALFORM_HISTORY_SIZE')."<span style='color: green; font-weight: bold'>".filesize($log_path . '/plg_system_radicalform.php')."</span> ".JText::_('PLG_RADICALFORM_HISTORY_BYTE')."</p>";
$html.="<p><button class='btn btn-danger' id='historyclear'>".JText::_('PLG_RADICALFORM_HISTORY_CLEAR')."</button></p>";
$html.="<br><br>";
$html.= '<table class="table table-striped table-bordered adminlist" style="max-width: 900px"><thead><tr>';
$html.= '<th width="5%">' . JText::_('PLG_RADICALFORM_HISTORY_TIME') . '</th>';
$html.= '<th width="5%">' . JText::_('PLG_RADICALFORM_HISTORY_DATE') . '</th>';
$html.= '<th width="5%">' . JText::_('PLG_RADICALFORM_HISTORY_IP') . '</th>';
$html.= '<th>' . JText::_('PLG_RADICALFORM_HISTORY_MESSAGE') . '</th>';
$html.= '</tr></thead><tbody>';
foreach ($data as $i => $item)
{
$json = json_decode($item[2], true);
if(is_array($json))
{
// new format of log file
$json_result = json_last_error() === JSON_ERROR_NONE;
$itog = "";
if (!$params->hiddeninfo)
{
unset($json["reffer"]);
unset($json["resolution"]);
unset($json["url"]);
unset($json["pagetitle"]);
}
foreach ($json as $key => $record)
{
if (is_array($record))
{
$record = implode($params->glue, $record);
}
$itog .= JText::_($key) . ": <b>" . $record . "</b><br />";
}
$jdate=JFactory::getDate($item[0]);
$timezone = new DateTimeZone( $site_offset );
$jdate->setTimezone($timezone);
$html .= '<tr class="row' . ($i % 2) . '">' .
'<td class="nowrap">'. $jdate->format('H:i:s',true) . '</td>' .
'<td>' . $jdate->format('Y-m-d',true) . '</td>' .
'<td><a href="http://whois.domaintools.com/' . $item[1] . '" target="_blank">' . $item[1] . '</a></td>';
if (isset($item[3]) && $item[3] == "WARNING")
{
$html .= '<td style="max-width: 700px; overflow: hidden; color: #9f2620;">' . ($json_result ? '' . $itog . '' : htmlspecialchars($item[2])) . '</td>' .
'</tr>';
}
else
{
$html .= '<td style="max-width: 700px; overflow: hidden;">' . ($json_result ? '' . $itog . '' : htmlspecialchars($item[2])) . '</td>' .
'</tr>';
}
}
else
{
// old log file format
$json = json_decode($item[3], true);
$json_result = json_last_error() === JSON_ERROR_NONE;
$itog = "";
if (!$params->hiddeninfo)
{
unset($json["reffer"]);
unset($json["resolution"]);
unset($json["url"]);
}
foreach ($json as $key => $record)
{
if (is_array($record))
{
$record = implode($params->glue, $record);
}
$itog .= JText::_($key) . ": <b>" . $record . "</b><br />";
}
$html .= '<tr class="row' . ($i % 2) . '">' .
'<td class="nowrap">' . $item[0] . '</td>' .
'<td>' . $item[1] . '</td>' .
'<td><a href="http://whois.domaintools.com/' . $item[2] . '" target="_blank">' . $item[2] . '</a></td>';
if (isset($item[4]) && $item[4] == "WARNING")
{
$html .= '<td style="max-width: 700px; overflow: hidden; color: #9f2620;">' . ($json_result ? '' . $itog . '' : htmlspecialchars($item[3])) . '</td>' .
'</tr>';
}
else
{
$html .= '<td style="max-width: 700px; overflow: hidden;">' . ($json_result ? '' . $itog . '' : htmlspecialchars($item[3])) . '</td>' .
'</tr>';
}
}
}
$html.= '</tbody></table>';
}
else
{
$html = '<div class="alert">' . JText::_('PLG_RADICALFORM_HISTORY_EMPTY') . '</div>';
}
return $html;
}
}