forked from mambax7/xnews
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makepdf.php
249 lines (204 loc) · 8.66 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php
/*
* 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 XOOPS Project https://xoops.org/
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
* @package
* @since
* @author XOOPS Development Team
*/
// 19-12-2008
// DNPROSSI - Made a few changes to 1.63
// Corrected UTF-8 problems
// Corrected xlanguage incompatability
//
// Moved /pdf to Frameworks/tcpdf - for more XOOPS like system
// removed file pdf.php called from /news/templates/nw_news_article.html
// changed link to pdf.php in /news/templates/nw_news_article.html
// to module /news/makepdf.php wirh calls to Frameworks/tcpdf
// UPDATED TCPDF to latest - 4.4.006 (2008-12-11)
// ------------------------------------------------------------------------- //
error_reporting(0);
require_once __DIR__ . '/header.php';
if (!is_file(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php')) {
redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?topic_id=' . $topic_id, 3, 'TCPDF for Xoops not installed');
} else {
require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php';
}
require_once XNEWS_MODULE_PATH . '/class/class.newsstory.php';
// Verifications on the article
$storyid = isset($_GET['storyid']) ? (int)$_GET['storyid'] : 0;
if (empty($storyid)) {
redirect_header(XNEWS_MODULE_URL . '/index.php', 3, _MA_NW_NOSTORY);
}
$article = new nw_NewsStory($storyid);
// Not yet published
if (0 == $article->published() || $article->published() > time()) {
redirect_header(XNEWS_MODULE_URL . '/index.php', 3, _MA_NW_NOSTORY);
}
// Expired
if (0 != $article->expired() && $article->expired() < time()) {
redirect_header(XNEWS_MODULE_URL . '/index.php', 3, _MA_NW_NOSTORY);
}
$gpermHandler = xoops_getHandler('groupperm');
if (is_object($xoopsUser)) {
$groups = $xoopsUser->getGroups();
} else {
$groups = XOOPS_GROUP_ANONYMOUS;
}
if (!isset($xoopsModule)) {
$moduleHandler = xoops_getHandler('module');
$xoopsModule = $moduleHandler->getByDirname(XNEWS_MODULE_DIRNAME);
}
if (!$gpermHandler->checkRight('nw_view', $article->topicid(), $groups, $xoopsModule->getVar('mid'))) {
redirect_header(XNEWS_MODULE_URL . '/index.php', 3, _NOPERM);
}
//$filename = XNEWS_MODULE_PATH . '/language/' . $xoopsConfig['language'] . '/main.php';
//if (file_exists($filename)) {
// require_once $filename;
//} else {
// require_once XNEWS_MODULE_PATH . '/language/english/main.php';
//}
//
$storypage = isset($_GET['page']) ? (int)$_GET['page'] : 0;
$dateformat = nw_getmoduleoption('dateformat', NW_MODULE_DIR_NAME);
$hcontent = '';
$pdf_data['title'] = $article->title();
$pdf_data['subtitle'] = $article->topic_title();
$pdf_data['subsubtitle'] = $xoopsModule->name();
$pdf_data['date'] = ': ' . date(_DATESTRING, $article->published());
$memberHandler = xoops_getHandler('member');
$author = $memberHandler->getUser($article->uid());
if ($author->getVar('name')) {
$pdf_data['author'] = $author->getVar('name') . '(' . $author->getVar('uname') . ')';
} else {
$pdf_data['author'] = $author->getVar('uname');
}
ob_start();
$GLOBALS['xoopsTpl']->display('db:nw_news_article_pdf.tpl');
$content = ob_get_contents();
ob_end_clean();
$pdf_data['content'] = $content;
define('PDF_CREATOR', $GLOBALS['xoopsConfig']['sitename']);
define('PDF_AUTHOR', $pdf_data['author']);
define('PDF_HEADER_TITLE', $pdf_data['title']);
define('PDF_HEADER_STRING', $pdf_data['subtitle']);
define('PDF_HEADER_LOGO', 'logo.png');
define('K_PATH_IMAGES', XOOPS_ROOT_PATH . '/images/');
//$filename = XOOPS_ROOT_PATH . '/Frameworks/tcpdf/config/lang/' . _LANGCODE . '.php';
//if (file_exists($filename)) {
// require_once $filename;
//} else {
// require_once XOOPS_ROOT_PATH . '/Frameworks/tcpdf/config/lang/en.php';
//}
$dateformat = $xnews->getConfig('dateformat');
//DNPROSSI Added - xlanguage installed and active
$moduleHandler = xoops_getHandler('module');
$xlanguage = $moduleHandler->getByDirname('xlanguage');
if (is_object($xlanguage) && true === $xlanguage->getVar('isactive')) {
$xlang = true;
} else {
$xlang = false;
}
$tempcontent = $article->title() . ' ' . $article->topic_title() . ' ' . $article->uname() . ' ' . $article->hometext() . ' ' . $article->bodytext();
$multylang = nw_detect_utf8_lang_encoding(urlencode($tempcontent));
$content = '';
$content .= '<b><i><u>'
. $myts->undoHtmlSpecialChars($article->title())
. '</u></i></b><br><b>'
. $myts->undoHtmlSpecialChars($article->topic_title())
. '</b><br>'
. _POSTEDBY
. ' : '
. $myts->undoHtmlSpecialChars($article->uname())
. '<br>'
. _MA_NW_POSTEDON
. ' '
. formatTimestamp($article->published(), $dateformat)
. '<br><br><br>';
//$content .= $myts->undoHtmlSpecialChars($article->hometext()) . '<br><br><br>' . $myts->undoHtmlSpecialChars($article->bodytext());
//$content = str_replace('[pagebreak]','<br>',$content);
$content .= $myts->undoHtmlSpecialChars($article->hometext()) . '<br>' . $myts->undoHtmlSpecialChars($article->bodytext());
$content = str_replace('[pagebreak]', '<tcpdf method="AddPage">', $content);
//DNPROSSI Scan for mixed single-multibyte language in content and use later
//$multylang = nw_detect_utf8_lang_encoding($content);
//DNPROSSI Added - Get correct language and remove tags from text to be sent to PDF
if (true === $xlang) {
require_once XOOPS_ROOT_PATH . '/modules/xlanguage/include/functions.php';
$content = xlanguage_ml($content);
}
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$doc_title = $myts->undoHtmlSpecialChars($article->title());
$doc_keywords = 'XOOPS';
//DNPROSSI ADDED gbsn00lp chinese to tcpdf fonts dir
if (_LANGCODE == 'cn' || 'cn' === $multylang) {
$pdf->SetFont('gbsn00lp', '', 10);
}
if (_LANGCODE === 'fa' || 'fa' === $multylang) {
// RTL direction for persian language
$pdf->setRTL(true);
//$pdf->SetFont('dejavusans', '', 12); almohanad
$pdf->SetFont('almohanad', '', 18);
}
// set document information
//$pdf->SetCreator($pdf_data['author']);
//$pdf->SetAuthor($pdf_data['author']);
//$pdf->SetTitle($pdf_data['title']);
//$pdf->SetSubject($pdf_data['subtitle']);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor(PDF_AUTHOR);
$pdf->SetTitle($doc_title);
$pdf->SetSubject($doc_title);
$pdf->SetKeywords($doc_keywords);
// set default header data
$pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
//$pdf->SetHeaderData('', '', $firstLine, $secondLine);
//$pdf->SetHeaderData('logo_example.png', '25', $firstLine, $secondLine);
//$firstLine = 'Your Site Name';
//$secondLine = 'Any thing you feel writing here';
//$pdf->SetHeaderData('logo_file.png', '25', $firstLine, $secondLine);
//UTF-8 char sample
//$pdf->SetHeaderData(PDF_HEADER_LOGO, '25', 'Éèéàùìò', $multylang);//$article->title());
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP + 10, PDF_MARGIN_RIGHT);
//set auto page breaks
$pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
$pdf->setHeaderMargin(PDF_MARGIN_HEADER);
$pdf->setFooterMargin(PDF_MARGIN_FOOTER);
$pdf->setImageScale(1); //set image scale factor
//DNPROSSI ADDED FOR SCHINESE - PERSIAN
if (_LANGCODE === 'cn' || 'cn' === $multylang) {
$pdf->setHeaderFont(['gbsn00lp', '', 10]);
$pdf->setFooterFont(['gbsn00lp', '', 10]);
} elseif (_LANGCODE === 'fa' || 'fa' === $multylang) {
$pdf->setHeaderFont(['almohanad', '', 18]);
$pdf->setFooterFont(['almohanad', '', 18]);
} else {
$pdf->setHeaderFont([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN]);
$pdf->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]);
}
$pdf->setLanguageArray($l); //set language items
//initialize document
$pdf->AliasNbPages();
// ***** For Testing Purposes
/*$pdf->AddPage();
// print a line using Cell()
*$pdf->Cell(0, 10, K_PATH_URL. ' ---- Path Url', 1, 1, 'C');
$pdf->Cell(0, 10, K_PATH_MAIN. ' ---- Path Main', 1, 1, 'C');
$pdf->Cell(0, 10, K_PATH_FONTS. ' ---- Path Fonts', 1, 1, 'C');
$pdf->Cell(0, 10, K_PATH_IMAGES. ' ---- Path Images', 1, 1, 'C');
*/
// ***** End Test
$pdf->AddPage();
$pdf->writeHTML($content, true, 0);
//Added for buffer error in TCPDF when using chinese charset
ob_end_clean();
$pdf->Output();