forked from XoopsModules25x/publisher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makepdf.php
126 lines (103 loc) · 4.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
<?php
/**
* File : makepdf.php for publisher
* For tcpdf_for_xoops 2.01 and higher
* Created by montuy337513 / philodenelle - http://www.chg-web.org
*/
use Xmf\Request;
error_reporting(E_ALL);
require_once __DIR__ . '/header.php';
$itemid = Request::getInt('itemid', 0, 'GET');
$item_page_id = Request::getInt('page', -1, 'GET');
if ($itemid == 0) {
redirect_header('javascript:history.go(-1)', 1, _MD_PUBLISHER_NOITEMSELECTED);
}
//2.5.8
require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php';
// Creating the item object for the selected item
$itemObj = $publisher->getHandler('item')->get($itemid);
// if the selected item was not found, exit
if (!$itemObj) {
redirect_header('javascript:history.go(-1)', 1, _MD_PUBLISHER_NOITEMSELECTED);
}
// Creating the category object that holds the selected item
$categoryObj = $publisher->getHandler('category')->get($itemObj->categoryid());
// Check user permissions to access that category of the selected item
if (!$itemObj->accessGranted()) {
redirect_header('javascript:history.go(-1)', 1, _NOPERM);
}
xoops_loadLanguage('main', PUBLISHER_DIRNAME);
$dateformat = $itemObj->getDatesub();
$sender_inform = sprintf(_MD_PUBLISHER_WHO_WHEN, $itemObj->posterName(), $itemObj->getDatesub());
$mainImage = $itemObj->getMainImage();
$content = '';
if ($mainImage['image_path'] != '') {
$content .= '<img src="' . $mainImage['image_path'] . '" alt="' . $myts->undoHtmlSpecialChars($mainImage['image_name']) . '"/><br>';
}
$content .= '<a href="'
. PUBLISHER_URL
. '/item.php?itemid='
. $itemid
. '" style="text-decoration: none; color: black; font-size: 120%;" title="'
. $myts->undoHtmlSpecialChars($itemObj->getTitle())
. '">'
. $myts->undoHtmlSpecialChars($itemObj->getTitle())
. '</a>';
$content .= '<br><span style="color: #CCCCCC; font-weight: bold; font-size: 80%;">'
. _CO_PUBLISHER_CATEGORY
. ' : </span><a href="'
. PUBLISHER_URL
. '/category.php?categoryid='
. $itemObj->categoryid()
. '" style="color: #CCCCCC; font-weight: bold; font-size: 80%;" title="'
. $myts->undoHtmlSpecialChars($categoryObj->name())
. '">'
. $myts->undoHtmlSpecialChars($categoryObj->name())
. '</a>';
$content .= '<br><span style="font-size: 80%; font-style: italic;">' . $sender_inform . '</span><br>';
$content .= $itemObj->getBody();
$content = str_replace('[pagebreak]', '', $content);
// Configuration for TCPDF_for_XOOPS
$pdf_data = array(
'author' => $itemObj->posterName(),
'title' => $myts->undoHtmlSpecialChars($categoryObj->name()),
'page_format' => 'A4',
'page_orientation' => 'P',
'unit' => 'mm',
'rtl' => false //true if right to left
);
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, _CHARSET, false);
$doc_title = PublisherUtility::convertCharset($myts->undoHtmlSpecialChars($itemObj->getTitle()));
$docSubject = $myts->undoHtmlSpecialChars($categoryObj->name());
$docKeywords = $myts->undoHtmlSpecialChars($itemObj->meta_keywords());
if (array_key_exists('rtl', $pdf_data)) {
$pdf->setRTL($pdf_data['rtl']);
}
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor(PDF_AUTHOR);
$pdf->SetTitle($doc_title);
$pdf->SetSubject($docSubject);
//$pdf->SetKeywords(XOOPS_URL . ', '.' by TCPDF_for_XOOPS (chg-web.org), '.$doc_title);
$pdf->SetKeywords($docKeywords);
$firstLine = PublisherUtility::convertCharset($GLOBALS['xoopsConfig']['sitename']) . ' (' . XOOPS_URL . ')';
$secondLine = PublisherUtility::convertCharset($GLOBALS['xoopsConfig']['slogan']);
//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $firstLine, $secondLine);
$pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $firstLine, $secondLine, array(0, 64, 255), array(0, 64, 128));
//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->setFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
$pdf->setHeaderMargin(PDF_MARGIN_HEADER);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set image scale factor
//2.5.8
$pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->setFooterData($tc = array(0, 64, 0), $lc = array(0, 64, 128));
//initialize document
$pdf->Open();
$pdf->AddPage();
$pdf->writeHTML($content, true, 0, true, 0);
$pdf->Output();