These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /* |
||
3 | * You may not change or alter any portion of this comment or credits |
||
4 | * of supporting developers from this source code or any supporting source code |
||
5 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||
6 | * |
||
7 | * This program is distributed in the hope that it will be useful, |
||
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
10 | */ |
||
11 | |||
12 | /** |
||
13 | * @copyright XOOPS Project https://xoops.org/ |
||
14 | * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
||
15 | * @package |
||
16 | * @since |
||
17 | * @author XOOPS Development Team, Kazumi Ono (AKA onokazu) |
||
18 | */ |
||
19 | |||
20 | error_reporting(0); |
||
21 | |||
22 | require_once __DIR__ . '/header.php'; |
||
23 | //2.5.8 |
||
24 | require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php'; |
||
25 | |||
26 | $myts = MyTextSanitizer::getInstance(); |
||
27 | require_once XOOPS_ROOT_PATH . '/modules/news/class/class.newsstory.php'; |
||
28 | require_once XOOPS_ROOT_PATH . '/modules/news/class/utility.php'; |
||
29 | $storyid = isset($_GET['storyid']) ? (int)$_GET['storyid'] : 0; |
||
30 | |||
31 | if (empty($storyid)) { |
||
32 | redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_NOSTORY); |
||
33 | } |
||
34 | |||
35 | $article = new NewsStory($storyid); |
||
36 | // Not yet published |
||
37 | View Code Duplication | if (0 == $article->published() || $article->published() > time()) { |
|
0 ignored issues
–
show
|
|||
38 | redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_NOSTORY); |
||
39 | } |
||
40 | |||
41 | // Expired |
||
42 | if (0 != $article->expired() && $article->expired() < time()) { |
||
43 | redirect_header(XOOPS_URL . '/modules/news/index.php', 2, _NW_NOSTORY); |
||
44 | } |
||
45 | |||
46 | $gpermHandler = xoops_getHandler('groupperm'); |
||
47 | if (is_object($xoopsUser)) { |
||
48 | $groups = $xoopsUser->getGroups(); |
||
49 | } else { |
||
50 | $groups = XOOPS_GROUP_ANONYMOUS; |
||
51 | } |
||
52 | if (!$gpermHandler->checkRight('news_view', $article->topicid(), $groups, $xoopsModule->getVar('mid'))) { |
||
53 | redirect_header(XOOPS_URL . '/modules/news/index.php', 3, _NOPERM); |
||
54 | } |
||
55 | |||
56 | $dateformat = NewsUtility::getModuleOption('dateformat'); |
||
57 | $article_data = $article->hometext() . $article->bodytext(); |
||
58 | $article_title = $article->title(); |
||
59 | $article_title = NewsUtility::html2text($myts->undoHtmlSpecialChars($article_title)); |
||
60 | $forumdata['topic_title'] = $article_title; |
||
61 | $pdf_data['title'] = $article->title(); |
||
62 | $topic_title = $article->topic_title(); |
||
63 | $topic_title = NewsUtility::html2text($myts->undoHtmlSpecialChars($topic_title)); |
||
64 | $pdf_data['subtitle'] = $topic_title; |
||
65 | $pdf_data['subsubtitle'] = $article->subtitle(); |
||
66 | $pdf_data['date'] = formatTimestamp($article->published(), $dateformat); |
||
67 | $pdf_data['filename'] = preg_replace("/[^0-9a-z\-_\.]/i", '', $myts->htmlSpecialChars($article->topic_title()) . ' - ' . $article->title()); |
||
68 | $hometext = $article->hometext(); |
||
69 | $bodytext = $article->bodytext(); |
||
70 | $content = $myts->undoHtmlSpecialChars($hometext) . '<br><br>' . $myts->undoHtmlSpecialChars($bodytext); |
||
71 | $content = str_replace('[pagebreak]', '<br><br>', $content); |
||
72 | $pdf_data['content'] = $content; |
||
73 | |||
74 | $pdf_data['author'] = $article->uname(); |
||
75 | |||
76 | //Other stuff |
||
77 | $puff = '<br>'; |
||
78 | $puffer = '<br><br>'; |
||
79 | |||
80 | //create the A4-PDF... |
||
81 | $pdf_config['slogan'] = XOOPS_URL . ' - ' . $xoopsConfig['sitename'] . ' - ' . $xoopsConfig['slogan']; |
||
82 | |||
83 | $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, _CHARSET, false); |
||
84 | |||
85 | //$pdf->setLanguageArray($localLanguageOptions); |
||
86 | |||
87 | $pdf->SetCreator(PDF_CREATOR); |
||
88 | |||
89 | $pdf->SetTitle($pdf_data['title']); |
||
90 | $pdf->SetAuthor(PDF_AUTHOR); |
||
91 | $pdf->SetSubject($pdf_data['author']); |
||
92 | $out = PDF_AUTHOR . ', ' . $pdf_data['author'] . ', ' . $pdf_data['title'] . ', ' . $pdf_data['subtitle'] . ', ' . $pdf_data['subsubtitle']; |
||
93 | $pdf->SetKeywords($out); |
||
94 | $pdf->SetAutoPageBreak(true, 25); |
||
95 | $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); |
||
96 | $pdf->setFooterMargin(PDF_MARGIN_FOOTER); |
||
97 | //$pdf->setHeaderFont(array(PDF_FONT_NAME_SUB, '', PDF_FONT_SIZE_SUB)); |
||
98 | $pdf->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]); |
||
99 | $pdf->setFooterData($tc = [0, 64, 0], $lc = [0, 64, 128]); |
||
100 | //$pdf->SetHeaderData('','5',$pdf_config['slogan']); |
||
101 | $pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $pdf_config['slogan'], [0, 64, 255], [0, 64, 128]); |
||
102 | //set margins |
||
103 | $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); |
||
104 | $pdf->setHeaderMargin(PDF_MARGIN_HEADER); |
||
105 | $pdf->setFooterMargin(PDF_MARGIN_FOOTER); |
||
106 | |||
107 | $pdf->Open(); |
||
108 | //First page |
||
109 | $pdf->AddPage(); |
||
110 | $pdf->SetXY(24, 25); |
||
111 | $pdf->SetTextColor(10, 60, 160); |
||
112 | //$pdf->SetFont(PDF_FONT_NAME_TITLE, PDF_FONT_STYLE_TITLE, PDF_FONT_SIZE_TITLE); |
||
113 | $pdf->writeHTML($pdf_data['title'] . ' - ' . $pdf_data['subtitle'], K_TITLE_MAGNIFICATION); |
||
114 | //$pdf->Line(25,20,190,20); |
||
115 | if ('' !== $pdf_data['subsubtitle']) { |
||
116 | $pdf->writeHTML($puff, K_XSMALL_RATIO); |
||
117 | // $pdf->SetFont(PDF_FONT_NAME_SUBSUB, PDF_FONT_STYLE_SUBSUB, PDF_FONT_SIZE_SUBSUB); |
||
118 | $pdf->writeHTML($pdf_data['subsubtitle'], '1'); |
||
119 | } |
||
120 | $pdf->writeHTML($puff, '0.2'); |
||
121 | //$pdf->SetFont(PDF_FONT_NAME_DATA, PDF_FONT_STYLE_DATA, PDF_FONT_SIZE_DATA); |
||
122 | $out = NEWS_PDF_AUTHOR . ': ' . $pdf_data['author'] . '<br>'; |
||
123 | $pdf->writeHTML($out, '0.2'); |
||
124 | $out = NEWS_PDF_DATE . ': ' . $pdf_data['date'] . '<br>'; |
||
125 | $pdf->writeHTML($out, '0.2'); |
||
126 | $pdf->SetTextColor(0, 0, 0); |
||
127 | $pdf->writeHTML($puffer, '1'); |
||
128 | |||
129 | //$pdf->SetFont(PDF_FONT_NAME_MAIN, PDF_FONT_STYLE_MAIN, PDF_FONT_SIZE_MAIN); |
||
130 | $pdf->writeHTML($pdf_data['content'], $pdf_config['scale']); |
||
131 | |||
132 | //2.5.8 |
||
133 | $pdf->setHeaderFont([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN]); |
||
134 | $pdf->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]); |
||
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 | |||
143 | $pdf->Output(); |
||
144 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.