-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmakepdf.php
185 lines (162 loc) · 6.8 KB
/
makepdf.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
/**
* ****************************************************************************
* userpage - MODULE FOR XOOPS
* Copyright (c) Hervé Thouzard of Instant Zero (http://www.instant-zero.com)
*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @copyright Hervé Thouzard of Instant Zero (http://www.instant-zero.com)
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @package userpage
* @author Hervé Thouzard of Instant Zero (http://www.instant-zero.com)
*
* ****************************************************************************
*/
use XoopsModules\Userpage\Utility;
require __DIR__ . '/header.php';
error_reporting(0);
@$xoopsLogger->activated = false;
require_once XOOPS_ROOT_PATH . '/modules/userpage/fpdf/fpdf.inc.php';
/**
* Internal function used for PDF
* @param mixed $document
* @return string|string[]|null
*/
function userpage_html2text($document)
{
// PHP Manual:: function preg_replace
// $document should contain an HTML document.
// This will remove HTML tags, javascript sections
// and white space. It will also convert some
// common HTML entities to their text equivalent.
$search = [
"'<script[^>]*?>.*?</script>'si", // Strip out javascript
"'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags
"'([\r\n])[\s]+'", // Strip out white space
"'&(quot|#34);'i", // Replace HTML entities
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(\d+);'e",
]; // evaluate as php
$replace = [
'',
'',
'\\1',
'"',
'&',
'<',
'>',
' ',
chr(161),
chr(162),
chr(163),
chr(169),
'chr(\\1)',
];
$text = preg_replace($search, $replace, $document);
return $text;
}
$myts = \MyTextSanitizer::getInstance();
$page_id = isset($_GET['page_id']) ? (int)$_GET['page_id'] : 0;
if (empty($page_id)) {
redirect_header('index.php', 2, _ERRORS);
exit();
}
$userpageHandler = \XoopsModules\Userpage\Helper::getInstance()->getHandler('Page');
$allowhtml = Utility::getModuleOption('allowhtml');
$criteria = new \Criteria('up_pageid', $page_id, '=');
$cnt = $userpageHandler->getCount($criteria);
if ($cnt > 0) {
$pagetbl = $userpageHandler->getObjects($criteria);
$page = $pagetbl[0];
} else { // Page not found
redirect_header(XOOPS_URL . '/index.php', 2, _USERPAGE_PAGE_NOT_FOUND);
exit();
}
$page->setVar('dohtml', $allowhtml);
$pdf_title = $page->getVar('up_title', 'n');
$pdf_content = $page->getVar('up_text', 'n');
$pdf_author = $page->uname();
$pdf_topic_title = $page->getVar('up_title', 'n');
$pdf_title = $page->getVar('up_title', 'n');
$pdf_subtitle = '';
$pdf_subsubtitle = '';
$pdf_author = $page->uname();
$pdf_date = formatTimestamp($page->getVar('up_created'), Utility::getModuleOption('dateformat'));
$pdf_url = $page->getURL();
// ***************************************************************************************************************************************
$pdf_topic_title = userpage_html2text($myts->undoHtmlSpecialChars($pdf_topic_title));
$forumdata['topic_title'] = $pdf_topic_title;
$pdf_data['title'] = $pdf_title;
$pdf_data['subtitle'] = userpage_html2text($pdf_subtitle);
$pdf_data['subsubtitle'] = userpage_html2text($pdf_subsubtitle);
$pdf_data['date'] = $pdf_date;
$pdf_data['content'] = $myts->undoHtmlSpecialChars($pdf_content);
$pdf_data['author'] = $pdf_author;
//Other stuff
$puff = '<br>';
$puffer = '<br><br><br>';
//create the A4-PDF...
$pdf_config['slogan'] = $xoopsConfig['sitename'] . ' - ' . $xoopsConfig['slogan'];
$pdf_config['creator'] = 'USERPAGE - Instant Zero';
$pdf_config['url'] = $pdf_url;
$pdf = new PDF();
if (method_exists($pdf, 'encoding')) {
$pdf->encoding($pdf_data, _CHARSET);
}
$pdf->SetCreator($pdf_config['creator']);
$pdf->SetTitle($pdf_data['title']);
$pdf->SetAuthor($pdf_config['url']);
$pdf->SetSubject($pdf_data['author']);
$out = $pdf_config['url'] . ', ' . $pdf_data['author'] . ', ' . $pdf_data['title'] . ', ' . $pdf_data['subtitle'] . ', ' . $pdf_data['subsubtitle'];
$pdf->SetKeywords($out);
$pdf->SetAutoPageBreak(true, 25);
$pdf->SetMargins($pdf_config['margin']['left'], $pdf_config['margin']['top'], $pdf_config['margin']['right']);
$pdf->Open();
//First page
$pdf->AddPage();
$pdf->SetXY(24, 25);
$pdf->SetTextColor(10, 60, 160);
$pdf->SetFont($pdf_config['font']['slogan']['family'], $pdf_config['font']['slogan']['style'], $pdf_config['font']['slogan']['size']);
$pdf->WriteHTML($pdf_config['slogan'], $pdf_config['scale']);
$pdf->Line(25, 30, 190, 30);
$pdf->SetXY(25, 35);
$pdf->SetFont($pdf_config['font']['title']['family'], $pdf_config['font']['title']['style'], $pdf_config['font']['title']['size']);
$pdf->WriteHTML($pdf_data['title'], $pdf_config['scale']);
if ('' != $pdf_data['subtitle']) {
$pdf->WriteHTML($puff, $pdf_config['scale']);
$pdf->SetFont($pdf_config['font']['subtitle']['family'], $pdf_config['font']['subtitle']['style'], $pdf_config['font']['subtitle']['size']);
$pdf->WriteHTML($pdf_data['subtitle'], $pdf_config['scale']);
}
if ('' != $pdf_data['subsubtitle']) {
$pdf->WriteHTML($puff, $pdf_config['scale']);
$pdf->SetFont($pdf_config['font']['subsubtitle']['family'], $pdf_config['font']['subsubtitle']['style'], $pdf_config['font']['subsubtitle']['size']);
$pdf->WriteHTML($pdf_data['subsubtitle'], $pdf_config['scale']);
}
$pdf->WriteHTML($puff, $pdf_config['scale']);
$pdf->SetFont($pdf_config['font']['author']['family'], $pdf_config['font']['author']['style'], $pdf_config['font']['author']['size']);
$out = USERPAGE_PDF_AUTHOR . ': ';
$out .= $pdf_data['author'];
$pdf->WriteHTML($out, $pdf_config['scale']);
$pdf->WriteHTML($puff, $pdf_config['scale']);
$out = USERPAGE_PDF_DATE;
$out .= $pdf_data['date'];
$pdf->WriteHTML($out, $pdf_config['scale']);
$pdf->WriteHTML($puff, $pdf_config['scale']);
$pdf->SetTextColor(0, 0, 0);
$pdf->WriteHTML($puffer, $pdf_config['scale']);
$pdf->SetFont($pdf_config['font']['content']['family'], $pdf_config['font']['content']['style'], $pdf_config['font']['content']['size']);
$pdf->WriteHTML($pdf_data['content'], $pdf_config['scale']);
$pdf->Output();