mambax7 /
newbb5
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 | * oledrion |
||
| 14 | * |
||
| 15 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||
| 16 | * @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
||
| 17 | * @author phppp (D.J., [email protected]) |
||
| 18 | */ |
||
| 19 | |||
| 20 | use Xmf\Request; |
||
| 21 | //use tecnickcom\TCPDF; |
||
| 22 | |||
| 23 | // a complete rewrite by irmtfan to enhance: 1- RTL 2- Multilanguage (EMLH and Xlanguage) |
||
| 24 | error_reporting(0); |
||
| 25 | include_once __DIR__ . '/header.php'; |
||
| 26 | |||
| 27 | $attach_id = Request::getString('attachid', '', 'GET'); |
||
| 28 | $forum = Request::getInt('forum', 0, 'GET'); |
||
| 29 | $topic_id = Request::getInt('topic_id', 0, 'GET'); |
||
| 30 | $post_id = Request::getInt('post_id', 0, 'GET'); |
||
| 31 | |||
| 32 | if (!is_file(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php')) { |
||
| 33 | redirect_header(XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/viewtopic.php?topic_id=' . $topic_id, 3, 'TCPDF for Xoops not installed'); |
||
| 34 | } else { |
||
| 35 | require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/tcpdf.php'; |
||
| 36 | } |
||
| 37 | |||
| 38 | if (empty($post_id)) { |
||
| 39 | exit(_MD_NEWBB_ERRORTOPIC); |
||
| 40 | } |
||
| 41 | ///** @var Newbb\PostHandler $postHandler */ |
||
| 42 | //$postHandler = Newbb\Helper::getInstance()->getHandler('Post'); |
||
| 43 | $post = $postHandler->get($post_id); |
||
| 44 | if (!$approved = $post->getVar('approved')) { |
||
| 45 | exit(_MD_NEWBB_NORIGHTTOVIEW); |
||
| 46 | } |
||
| 47 | $post_data = $postHandler->getPostForPDF($post); |
||
| 48 | //$post_edit = $post->displayPostEdit(); //reserve for future versions to display edit records |
||
| 49 | ///** @var Newbb\TopicHandler $topicHandler */ |
||
| 50 | //$topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
||
| 51 | $forumtopic = $topicHandler->getByPost($post_id); |
||
| 52 | $topic_id = $forumtopic->getVar('topic_id'); |
||
| 53 | if (!$approved = $forumtopic->getVar('approved')) { |
||
| 54 | exit(_MD_NEWBB_NORIGHTTOVIEW); |
||
| 55 | } |
||
| 56 | ///** @var Newbb\ForumHandler $forumHandler */ |
||
| 57 | //$forumHandler = Newbb\Helper::getInstance()->getHandler('Forum'); |
||
| 58 | $forum = $forum ?: $forumtopic->getVar('forum_id'); |
||
| 59 | $viewtopic_forum = $forumHandler->get($forum); |
||
| 60 | $parent_forums = []; |
||
| 61 | $parent_forums = $forumHandler->getParents($viewtopic_forum); |
||
| 62 | $pf_title = ''; |
||
| 63 | if ($parent_forums) { |
||
| 64 | foreach ($parent_forums as $p_f) { |
||
| 65 | $pf_title .= $p_f['forum_name'] . ' - '; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | if (!$forumHandler->getPermission($viewtopic_forum)) { |
||
| 69 | exit(_MD_NEWBB_NORIGHTTOACCESS); |
||
| 70 | } |
||
| 71 | if (!$topicHandler->getPermission($viewtopic_forum, $forumtopic->getVar('topic_status'), 'view')) { |
||
| 72 | exit(_MD_NEWBB_NORIGHTTOVIEW); |
||
| 73 | } |
||
| 74 | // irmtfan add pdf permission |
||
| 75 | if (!$topicHandler->getPermission($viewtopic_forum, $forumtopic->getVar('topic_status'), 'pdf')) { |
||
| 76 | exit(_MD_NEWBB_NORIGHTTOPDF); |
||
| 77 | } |
||
| 78 | //$categoryHandler = Newbb\Helper::getInstance()->getHandler('Category'); |
||
|
0 ignored issues
–
show
|
|||
| 79 | $cat = $viewtopic_forum->getVar('cat_id'); |
||
| 80 | $viewtopic_cat = $categoryHandler->get($cat); |
||
| 81 | $GLOBALS['xoopsOption']['pdf_cache'] = 0; |
||
| 82 | $pdf_data['author'] = $myts->undoHtmlSpecialChars($post_data['author']); |
||
| 83 | $pdf_data['title'] = $myts->undoHtmlSpecialChars($post_data['subject']); |
||
| 84 | $content = ''; |
||
| 85 | $content .= '<b>' . $pdf_data['title'] . '</b><br><br>'; |
||
| 86 | $content .= _MD_NEWBB_AUTHORC . ' ' . $pdf_data['author'] . '<br>'; |
||
| 87 | $content .= _MD_NEWBB_POSTEDON . ' ' . formatTimestamp($post_data['date']) . '<br><br><br>'; |
||
| 88 | $content .= $myts->undoHtmlSpecialChars($post_data['text']) . '<br>'; |
||
| 89 | //$content .= $post_edit . '<br>'; //reserve for future versions to display edit records |
||
| 90 | $pdf_data['content'] = str_replace('[pagebreak]', '<br>', $content); |
||
| 91 | $pdf_data['topic_title'] = $forumtopic->getVar('topic_title'); |
||
| 92 | $pdf_data['forum_title'] = $pf_title . $viewtopic_forum->getVar('forum_name'); |
||
| 93 | $pdf_data['cat_title'] = $viewtopic_cat->getVar('cat_title'); |
||
| 94 | $pdf_data['subject'] = _MD_NEWBB_PDF_SUBJECT . ': ' . $pdf_data['topic_title']; |
||
| 95 | $pdf_data['keywords'] = XOOPS_URL . ', ' . 'XOOPS Project, ' . $pdf_data['topic_title']; |
||
| 96 | $pdf_data['HeadFirstLine'] = $GLOBALS['xoopsConfig']['sitename'] . ' - ' . $GLOBALS['xoopsConfig']['slogan']; |
||
| 97 | $pdf_data['HeadSecondLine'] = _MD_NEWBB_FORUMHOME . ' - ' . $pdf_data['cat_title'] . ' - ' . $pdf_data['forum_title'] . ' - ' . $pdf_data['topic_title']; |
||
| 98 | // START irmtfan to implement EMLH by GIJ |
||
| 99 | if (function_exists('easiestml')) { |
||
| 100 | $pdf_data = easiestml($pdf_data); |
||
| 101 | // END irmtfan to implement EMLH by GIJ |
||
| 102 | // START irmtfan to implement Xlanguage by phppp(DJ) |
||
| 103 | } elseif (function_exists('xlanguage_ml')) { |
||
| 104 | $pdf_data = xlanguage_ml($pdf_data); |
||
| 105 | } |
||
| 106 | // END irmtfan to implement Xlanguage by phppp(DJ) |
||
| 107 | |||
| 108 | $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, _CHARSET, false); |
||
| 109 | // load $localLanguageOptions array with language specific definitions and apply |
||
| 110 | //if (is_file(XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/config/lang/' . $GLOBALS['xoopsConfig']['language'] . '.php')) { |
||
| 111 | // require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/config/lang/' . $GLOBALS['xoopsConfig']['language'] . '.php'; |
||
| 112 | //} else { |
||
| 113 | // require_once XOOPS_ROOT_PATH . '/class/libraries/vendor/tecnickcom/tcpdf/config/lang/english.php'; |
||
| 114 | //} |
||
| 115 | // set some language dependent data: |
||
| 116 | $lg = []; |
||
| 117 | $lg['a_meta_charset'] = _CHARSET; |
||
| 118 | //$lg['a_meta_dir'] = _MD_NEWBB_PDF_META_DIR; |
||
| 119 | $lg['a_meta_language'] = _LANGCODE; |
||
| 120 | $lg['w_page'] = _MD_NEWBB_PDF_PAGE2; |
||
| 121 | |||
| 122 | // set some language-dependent strings (optional) |
||
| 123 | $pdf->setLanguageArray($lg); |
||
| 124 | //$pdf->setLanguageArray($localLanguageOptions); |
||
| 125 | // set some language-dependent strings (optional) |
||
| 126 | $pdf->setLanguageArray($lg); |
||
| 127 | //$pdf->setLanguageArray($localLanguageOptions); |
||
| 128 | // START irmtfan hack to add RTL-LTR local |
||
| 129 | // until _RTL added to core 2.6.0 |
||
| 130 | if (!defined('_RTL')) { |
||
| 131 | define('_RTL', false); |
||
| 132 | } |
||
| 133 | $pdf->setRTL(_RTL); |
||
| 134 | // END irmtfan hack to add RTL-LTR local |
||
| 135 | |||
| 136 | // set document information |
||
| 137 | $pdf->SetCreator(PDF_CREATOR); |
||
| 138 | $pdf->SetAuthor(PDF_AUTHOR); |
||
| 139 | $pdf->SetTitle($pdf_data['forum_title'] . ' - ' . $pdf_data['subject']); |
||
| 140 | $pdf->SetSubject($pdf_data['subject']); |
||
| 141 | $pdf->SetKeywords($pdf_data['keywords']); |
||
| 142 | |||
| 143 | //$pdf->SetHeaderData('', '5', $pdf_data['HeadFirstLine'], $pdf_data['HeadSecondLine']); |
||
| 144 | $pdf->setHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $pdf_data['HeadFirstLine'], $pdf_data['HeadSecondLine'], [0, 64, 255], [0, 64, 128]); |
||
| 145 | |||
| 146 | //set margins |
||
| 147 | $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); |
||
| 148 | $pdf->setHeaderMargin(PDF_MARGIN_HEADER); |
||
| 149 | $pdf->setFooterMargin(PDF_MARGIN_FOOTER); |
||
| 150 | |||
| 151 | //set auto page breaks |
||
| 152 | $pdf->SetAutoPageBreak(true, 25); |
||
| 153 | $pdf->setHeaderFont([PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN]); |
||
| 154 | $pdf->setFooterFont([PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA]); |
||
| 155 | $pdf->setFooterData($tc = [0, 64, 0], $lc = [0, 64, 128]); |
||
| 156 | $pdf->Open(); |
||
| 157 | $pdf->AddPage(); |
||
| 158 | |||
| 159 | //$pdf->SetFont(PDF_FONT_NAME_MAIN, PDF_FONT_STYLE_MAIN, PDF_FONT_SIZE_MAIN); |
||
| 160 | $pdf->SetFont('dejavusans', '', 12); |
||
| 161 | $pdf->writeHTML($pdf_data['content'], true, 0); |
||
| 162 | $pdf->Output($pdf_data['topic_title'] . '_' . $post_id . '.pdf', 'I'); |
||
| 163 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.