1 | <?php |
||
2 | /** |
||
3 | * File : makepdf.php for publisher |
||
4 | * For tcpdf_for_xoops 2.01 and higher |
||
5 | * Created by montuy337513 / philodenelle - http://www.chg-web.org |
||
6 | */ |
||
7 | |||
8 | use Xmf\Request; |
||
9 | use XoopsModules\Publisher; |
||
10 | |||
11 | error_reporting(E_ALL); |
||
12 | |||
13 | require_once __DIR__ . '/header.php'; |
||
14 | |||
15 | $itemid = Request::getInt('itemid', 0, 'GET'); |
||
16 | $item_page_id = Request::getInt('page', -1, 'GET'); |
||
17 | if (0 == $itemid) { |
||
18 | redirect_header('<script>javascript:history.go(-1)</script>', 1, _MD_PUBLISHER_NOITEMSELECTED); |
||
19 | } |
||
20 | |||
21 | //2.5.8 |
||
22 | require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php'; |
||
23 | |||
24 | // Creating the item object for the selected item |
||
25 | $itemObj = $helper->getHandler('Item')->get($itemid); |
||
26 | |||
27 | // if the selected item was not found, exit |
||
28 | if (!$itemObj) { |
||
29 | redirect_header('<script>javascript:history.go(-1)</script>', 1, _MD_PUBLISHER_NOITEMSELECTED); |
||
30 | } |
||
31 | |||
32 | // Creating the category object that holds the selected item |
||
33 | $categoryObj = $helper->getHandler('Category')->get($itemObj->categoryid()); |
||
34 | |||
35 | // Check user permissions to access that category of the selected item |
||
36 | if (!$itemObj->accessGranted()) { |
||
37 | redirect_header('<script>javascript:history.go(-1)</script>', 1, _NOPERM); |
||
38 | } |
||
39 | |||
40 | $helper->loadLanguage('main'); |
||
41 | |||
42 | $dateformat = $itemObj->getDatesub(); |
||
43 | $sender_inform = sprintf(_MD_PUBLISHER_WHO_WHEN, $itemObj->posterName(), $itemObj->getDatesub()); |
||
44 | $mainImage = $itemObj->getMainImage(); |
||
45 | |||
46 | $content = ''; |
||
47 | if ('' != $mainImage['image_path']) { |
||
48 | $content .= '<img src="' . $mainImage['image_path'] . '" alt="' . $myts->undoHtmlSpecialChars($mainImage['image_name']) . '"><br>'; |
||
49 | } |
||
50 | $content .= '<a href="' . PUBLISHER_URL . '/item.php?itemid=' . $itemid . '" style="text-decoration: none; color: #000000; font-size: 120%;" title="' . $myts->undoHtmlSpecialChars($itemObj->getTitle()) . '">' . $myts->undoHtmlSpecialChars($itemObj->getTitle()) . '</a>'; |
||
51 | $content .= '<br><span style="color: #CCCCCC; font-weight: bold; font-size: 80%;">' |
||
52 | . _CO_PUBLISHER_CATEGORY |
||
53 | . ' : </span><a href="' |
||
54 | . PUBLISHER_URL |
||
55 | . '/category.php?categoryid=' |
||
56 | . $itemObj->categoryid() |
||
57 | . '" style="color: #CCCCCC; font-weight: bold; font-size: 80%;" title="' |
||
58 | . $myts->undoHtmlSpecialChars($categoryObj->name()) |
||
59 | . '">' |
||
60 | . $myts->undoHtmlSpecialChars($categoryObj->name()) |
||
61 | . '</a>'; |
||
62 | $content .= '<br><span style="font-size: 80%; font-style: italic;">' . $sender_inform . '</span><br>'; |
||
63 | $content .= $itemObj->getBody(); |
||
64 | $content = str_replace('[pagebreak]', '', $content); |
||
65 | |||
66 | // Configuration for TCPDF_for_XOOPS |
||
67 | $pdf_data = [ |
||
68 | 'author' => $itemObj->posterName(), |
||
69 | 'title' => $myts->undoHtmlSpecialChars($categoryObj->name()), |
||
70 | 'page_format' => 'A4', |
||
71 | 'page_orientation' => 'P', |
||
72 | 'unit' => 'mm', |
||
73 | 'rtl' => false, //true if right to left |
||
74 | ]; |
||
75 | |||
76 | $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, _CHARSET, false); |
||
77 | |||
78 | $doc_title = Publisher\Utility::convertCharset($myts->undoHtmlSpecialChars($itemObj->getTitle())); |
||
79 | $docSubject = $myts->undoHtmlSpecialChars($categoryObj->name()); |
||
80 | |||
81 | $docKeywords = $myts->undoHtmlSpecialChars($itemObj->meta_keywords()); |
||
82 | if (array_key_exists('rtl', $pdf_data)) { |
||
83 | $pdf->setRTL($pdf_data['rtl']); |
||
84 | } |
||
85 | // set document information |
||
86 | $pdf->SetCreator(PDF_CREATOR); |
||
87 | $pdf->SetAuthor(PDF_AUTHOR); |
||
88 | $pdf->SetTitle($doc_title); |
||
89 | $pdf->SetSubject($docSubject); |
||
90 | //$pdf->SetKeywords(XOOPS_URL . ', '.' by TCPDF_for_XOOPS (chg-web.org), '.$doc_title); |
||
91 | $pdf->SetKeywords($docKeywords); |
||
92 | |||
93 | $firstLine = Publisher\Utility::convertCharset($GLOBALS['xoopsConfig']['sitename']) . ' (' . XOOPS_URL . ')'; |
||
94 | $secondLine = Publisher\Utility::convertCharset($GLOBALS['xoopsConfig']['slogan']); |
||
95 | |||
96 | //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $firstLine, $secondLine); |
||
97 | $pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $firstLine, $secondLine, [0, 64, 255], [0, 64, 128]); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
98 | |||
99 | //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING); |
||
100 | |||
101 | //set margins |
||
102 | $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); |
||
103 | $pdf->setFooterMargin(PDF_MARGIN_FOOTER); |
||
104 | //set auto page breaks |
||
105 | $pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM); |
||
106 | |||
107 | $pdf->setHeaderMargin(PDF_MARGIN_HEADER); |
||
108 | $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set image scale factor |
||
109 | |||
110 | //2.5.8 |
||
111 | $pdf->setHeaderFont([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN]); |
||
112 | $pdf->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]); |
||
113 | |||
114 | $pdf->setFooterData($tc = [0, 64, 0], $lc = [0, 64, 128]); |
||
115 | |||
116 | //initialize document |
||
117 | $pdf->Open(); |
||
118 | $pdf->AddPage(); |
||
119 | $pdf->writeHTML($content, true, 0, true, 0); |
||
120 | $pdf->Output(); |
||
121 |