-
-
Notifications
You must be signed in to change notification settings - Fork 251
/
Report.php
150 lines (137 loc) · 4.41 KB
/
Report.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
<?php
/**
* The reporting class for simple report generation.
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/.
*
* @package phpMyFAQ
* @author Thorsten Rinne <thorsten@phpmyfaq.de>
* @author Gustavo Solt <gustavo.solt@mayflower.de>
* @copyright 2011-2022 phpMyFAQ Team
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
* @link https://www.phpmyfaq.de
* @since 2011-02-04
*/
namespace phpMyFAQ;
/**
* Class Report
*
* @package phpMyFAQ
*/
class Report
{
/**
* @var Configuration
*/
private $config;
/**
* Constructor.
*
* @param Configuration $config
*/
public function __construct(Configuration $config)
{
$this->config = $config;
}
/**
* Generates a huge array for the report.
*
* @return array<int, array<mixed>>
*/
public function getReportingData(): array
{
$report = [];
$query = sprintf(
'
SELECT
fd.id AS id,
fd.lang AS lang,
fcr.category_id AS category_id,
c.name as category_name,
c.parent_id as parent_id,
fd.sticky AS sticky,
fd.thema AS question,
fd.author AS original_author,
fd.updated AS updated,
fv.visits AS visits,
u.display_name AS last_author
FROM
%sfaqdata fd
LEFT JOIN
%sfaqcategoryrelations fcr
ON
(fd.id = fcr.record_id AND fd.lang = fcr.record_lang)
LEFT JOIN
%sfaqvisits fv
ON
(fd.id = fv.id AND fd.lang = fv.lang)
LEFT JOIN
%sfaqchanges as fc
ON
(fd.id = fc.id AND fd.lang = fc.lang)
LEFT JOIN
%sfaquserdata as u
ON
(u.user_id = fc.usr)
LEFT JOIN
%sfaqcategories as c
ON
(c.id = fcr.category_id AND c.lang = fcr.record_lang)
ORDER BY
fd.id
ASC',
Database::getTablePrefix(),
Database::getTablePrefix(),
Database::getTablePrefix(),
Database::getTablePrefix(),
Database::getTablePrefix(),
Database::getTablePrefix()
);
$result = $this->config->getDb()->query($query);
$lastId = 0;
while ($row = $this->config->getDb()->fetchObject($result)) {
if ($row->id == $lastId) {
$report[$row->id]['faq_translations'] += 1;
} else {
$report[$row->id] = [
'faq_id' => $row->id,
'faq_language' => $row->lang,
'category_id' => $row->category_id,
'category_parent' => $row->parent_id,
'category_name' => $row->category_name,
'faq_translations' => 0,
'faq_sticky' => $row->sticky,
'faq_question' => $row->question,
'faq_org_author' => $row->original_author,
'faq_updated' => Date::createIsoDate($row->updated),
'faq_visits' => $row->visits,
'faq_last_author' => $row->last_author,
];
}
$lastId = $row->id;
}
return $report;
}
/**
* Convert string to the correct encoding and removes possible
* bad strings to avoid formula injection attacks.
*
* @param string $outputString String to encode.
* @return string Encoded string.
*/
public function convertEncoding(string $outputString = ''): string
{
$outputString = html_entity_decode($outputString, ENT_QUOTES, 'utf-8');
$outputString = str_replace(',', ' ', $outputString);
if (extension_loaded('mbstring')) {
$detected = mb_detect_encoding($outputString);
if ($detected !== 'ASCII') {
$outputString = mb_convert_encoding($outputString, 'UTF-16', $detected);
}
}
$toBeRemoved = ['=', '+', '-', 'HYPERLINK'];
return str_replace($toBeRemoved, '', $outputString);
}
}