1 | <?php declare(strict_types=1); |
||
2 | |||
3 | /** |
||
4 | * File : makepdf.php for publisher |
||
5 | * For tcpdf_for_xoops 2.01 and higher |
||
6 | * Created by montuy337513 / philodenelle - https://www.chg-web.org |
||
7 | */ |
||
8 | |||
9 | use Xmf\Request; |
||
10 | use XoopsModules\Publisher\Helper; |
||
11 | use XoopsModules\Publisher\Utility; |
||
12 | |||
13 | /** @var Helper $helper */ |
||
14 | error_reporting(E_ALL); |
||
15 | |||
16 | require_once __DIR__ . '/header.php'; |
||
17 | |||
18 | $itemId = Request::getInt('itemid', 0, 'GET'); |
||
19 | $itemPageId = Request::getInt('page', -1, 'GET'); |
||
20 | if (0 == $itemId) { |
||
21 | redirect_header('<script>javascript:history.go(-1)</script>', 1, _MD_PUBLISHER_NOITEMSELECTED); |
||
22 | } |
||
23 | |||
24 | //2.5.8 |
||
25 | require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php'; |
||
26 | |||
27 | // Creating the item object for the selected item |
||
28 | $itemObj = $helper->getHandler('Item') |
||
29 | ->get($itemId); |
||
30 | |||
31 | // if the selected item was not found, exit |
||
32 | if (!$itemObj) { |
||
33 | redirect_header('<script>javascript:history.go(-1)</script>', 1, _MD_PUBLISHER_NOITEMSELECTED); |
||
34 | } |
||
35 | |||
36 | // Creating the category object that holds the selected item |
||
37 | $categoryObj = $helper->getHandler('Category') |
||
38 | ->get($itemObj->categoryid()); |
||
39 | |||
40 | // Check user permissions to access that category of the selected item |
||
41 | if (!$itemObj->accessGranted()) { |
||
42 | redirect_header('<script>javascript:history.go(-1)</script>', 1, _NOPERM); |
||
43 | } |
||
44 | |||
45 | $helper->loadLanguage('main'); |
||
46 | |||
47 | $dateformat = $itemObj->getDatesub(); |
||
48 | $sender_inform = sprintf(_MD_PUBLISHER_WHO_WHEN, $itemObj->posterName(), $itemObj->getDatesub()); |
||
49 | $mainImage = $itemObj->getMainImage(); |
||
50 | |||
51 | $content = ''; |
||
52 | if (empty($mainImage['image_path'])) { |
||
53 | $content .= '<img src="' . PUBLISHER_URL . '/assets/images/default_image.jpg" alt="' . $myts->undoHtmlSpecialChars($mainImage['image_name']) . '"><br>'; |
||
54 | } |
||
55 | if ('' != $mainImage['image_path']) { |
||
56 | $content .= '<img src="' . $mainImage['image_path'] . '" alt="' . $myts->undoHtmlSpecialChars($mainImage['image_name']) . '"><br>'; |
||
57 | } |
||
58 | $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>'; |
||
59 | $content .= '<br><span style="color: #CCCCCC; font-weight: bold; font-size: 80%;">' |
||
60 | . _CO_PUBLISHER_CATEGORY |
||
61 | . ' : </span><a href="' |
||
62 | . PUBLISHER_URL |
||
63 | . '/category.php?categoryid=' |
||
64 | . $itemObj->categoryid() |
||
65 | . '" style="color: #CCCCCC; font-weight: bold; font-size: 80%;" title="' |
||
66 | . $myts->undoHtmlSpecialChars($categoryObj->name()) |
||
67 | . '">' |
||
68 | . $myts->undoHtmlSpecialChars($categoryObj->name()) |
||
69 | . '</a>'; |
||
70 | $content .= '<br><span style="font-size: 80%; font-style: italic;">' . $sender_inform . '</span><br>'; |
||
71 | $content .= $itemObj->getBody(); |
||
72 | $content = str_replace('[pagebreak]', '', $content); |
||
73 | |||
74 | // Configuration for TCPDF_for_XOOPS |
||
75 | $pdf_data = [ |
||
76 | 'author' => $itemObj->posterName(), |
||
77 | 'title' => $myts->undoHtmlSpecialChars($categoryObj->name()), |
||
78 | 'page_format' => 'A4', |
||
79 | 'page_orientation' => 'P', |
||
80 | 'unit' => 'mm', |
||
81 | 'rtl' => false, //true if right to left |
||
82 | ]; |
||
83 | |||
84 | $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, _CHARSET, false); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() The type
TCPDF was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
85 | |||
86 | $doc_title = Utility::convertCharset($myts->undoHtmlSpecialChars($itemObj->getTitle())); |
||
87 | $docSubject = $myts->undoHtmlSpecialChars($categoryObj->name()); |
||
88 | |||
89 | $docKeywords = $myts->undoHtmlSpecialChars($itemObj->meta_keywords()); |
||
90 | if (array_key_exists('rtl', $pdf_data)) { |
||
91 | $pdf->setRTL($pdf_data['rtl']); |
||
92 | } |
||
93 | // set document information |
||
94 | $pdf->SetCreator(PDF_CREATOR); |
||
0 ignored issues
–
show
|
|||
95 | $pdf->SetAuthor(PDF_AUTHOR); |
||
0 ignored issues
–
show
|
|||
96 | $pdf->SetTitle($doc_title); |
||
97 | $pdf->SetSubject($docSubject); |
||
98 | //$pdf->SetKeywords(XOOPS_URL . ', '.' by TCPDF_for_XOOPS (chg-web.org), '.$doc_title); |
||
99 | $pdf->SetKeywords($docKeywords); |
||
100 | |||
101 | $firstLine = Utility::convertCharset($GLOBALS['xoopsConfig']['sitename']) . ' (' . XOOPS_URL . ')'; |
||
102 | $secondLine = Utility::convertCharset($GLOBALS['xoopsConfig']['slogan']); |
||
103 | |||
104 | $PDF_HEADER_LOGO = '_blank.png'; |
||
105 | $PDF_HEADER_LOGO_WIDTH = ''; |
||
106 | |||
107 | //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $firstLine, $secondLine); |
||
108 | $pdf->setHeaderData($PDF_HEADER_LOGO, $PDF_HEADER_LOGO_WIDTH, $firstLine, $secondLine); |
||
109 | //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING); |
||
110 | |||
111 | //print : disable the possibility to print the PDF from any PDF viewer. |
||
112 | //modify : prevent the modification of contents of the document by operations other than those controlled by 'fill-forms', 'extract' and 'assemble'; |
||
113 | //copy : prevent the copy or otherwise extract text and graphics from the document; |
||
114 | //annot-forms : Add or modify text annotations, fill in interactive form fields, and, if 'modify' is also set, create or modify interactive form fields (including signature fields); |
||
115 | //fill-forms : Fill in existing interactive form fields (including signature fields), even if 'annot-forms' is not specified; |
||
116 | //extract : Extract text and graphics (in support of accessibility to users with disabilities or for other purposes); |
||
117 | //assemble : Assemble the document (insert, rotate, or delete pages and create bookmarks or thumbnail images), even if 'modify' is not set; |
||
118 | //print-high : Print the document to a representation from which a faithful digital copy of the PDF content could be generated. When this is not set, printing is limited to a low-level representation of the appearance, possibly of degraded quality. |
||
119 | //owner : (inverted logic - only for public-key) when set permits change of encryption and enables all other permissions. |
||
120 | |||
121 | $pdf->SetProtection(['modify', 'copy', 'annot-forms', 'fill-forms', 'extract', 'assemble']); |
||
122 | |||
123 | //set margins |
||
124 | $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); |
||
0 ignored issues
–
show
|
|||
125 | $pdf->setFooterMargin(PDF_MARGIN_FOOTER); |
||
0 ignored issues
–
show
|
|||
126 | //set auto page breaks |
||
127 | $pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM); |
||
0 ignored issues
–
show
|
|||
128 | |||
129 | $pdf->setHeaderMargin(PDF_MARGIN_HEADER); |
||
0 ignored issues
–
show
|
|||
130 | $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set image scale factor |
||
0 ignored issues
–
show
|
|||
131 | |||
132 | //2.5.8 |
||
133 | $pdf->setHeaderFont([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN]); |
||
0 ignored issues
–
show
|
|||
134 | $pdf->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]); |
||
0 ignored issues
–
show
|
|||
135 | |||
136 | $pdf->setFooterData($tc = [0, 64, 0], $lc = [0, 64, 128]); |
||
137 | |||
138 | //initialize document |
||
139 | $pdf->Open(); |
||
140 | $pdf->AddPage(); |
||
141 | $pdf->writeHTML($content, true, 0, true, 0); |
||
142 | $pdf->Output(); |
||
143 |