Completed
Push — master ( 6452b0...d576ea )
by Michael
05:58 queued 03:02
created

makepdf.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
// $Id$
3
//  ------------------------------------------------------------------------ //
4
//                XOOPS - PHP Content Management System                      //
5
//                    Copyright (c) 2000 XOOPS.org                           //
6
//                       <http://xoops.org/>                             //
7
//  ------------------------------------------------------------------------ //
8
//  This program is free software; you can redistribute it and/or modify     //
9
//  it under the terms of the GNU General Public License as published by     //
10
//  the Free Software Foundation; either version 2 of the License, or        //
11
//  (at your option) any later version.                                      //
12
//                                                                           //
13
//  You may not change or alter any portion of this comment or credits       //
14
//  of supporting developers from this source code or any supporting         //
15
//  source code which is considered copyrighted (c) material of the          //
16
//  original comment or credit authors.                                      //
17
//                                                                           //
18
//  This program is distributed in the hope that it will be useful,          //
19
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21
//  GNU General Public License for more details.                             //
22
//                                                                           //
23
//  You should have received a copy of the GNU General Public License        //
24
//  along with this program; if not, write to the Free Software              //
25
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26
//  ------------------------------------------------------------------------ //
27
// Author: Kazumi Ono (AKA onokazu)                                          //
28
// URL: http://www.myweb.ne.jp/, http://xoops.org/, http://jp.xoops.org/ //
29
// Project: XOOPS Project                                                    //
30
// ------------------------------------------------------------------------- //
31
32
error_reporting(0);
33
34
include_once __DIR__ . '/header.php';
35
if (!is_file(XOOPS_PATH.'/vendor/tcpdf/tcpdf.php')) {
36
    redirect_header(XOOPS_URL.'/modules/news/index.php',3,'tcpdf_for_xoops not installed');
37
}
38
$myts =& MyTextSanitizer::getInstance();
39
include_once XOOPS_ROOT_PATH.'/modules/news/class/class.newsstory.php';
40
include_once XOOPS_ROOT_PATH.'/modules/news/include/functions.php';
41
$storyid = isset($_GET['storyid']) ? (int)($_GET['storyid']) : 0;
42
43
if (empty($storyid))  {
44
    redirect_header(XOOPS_URL.'/modules/news/index.php',2,_NW_NOSTORY);
45
46
}
47
48
$article = new NewsStory($storyid);
49
// Not yet published
50 View Code Duplication
if ( $article->published() == 0 || $article->published() > time() ) {
51
    redirect_header(XOOPS_URL.'/modules/news/index.php', 2, _NW_NOSTORY);
52
53
}
54
55
// Expired
56
if ( $article->expired() != 0 && $article->expired() < time() ) {
57
    redirect_header(XOOPS_URL.'/modules/news/index.php', 2, _NW_NOSTORY);
58
59
}
60
61
$gperm_handler =& xoops_gethandler('groupperm');
62
if (is_object($xoopsUser)) {
63
    $groups = $xoopsUser->getGroups();
64
} else {
65
    $groups = XOOPS_GROUP_ANONYMOUS;
66
}
67
if (!$gperm_handler->checkRight('news_view', $article->topicid(), $groups, $xoopsModule->getVar('mid'))) {
68
    redirect_header(XOOPS_URL.'/modules/news/index.php', 3, _NOPERM);
69
70
}
71
72
$dateformat = news_getmoduleoption('dateformat');
73
$article_data = $article->hometext() . $article->bodytext();
74
$article_title = $article->title();
75
$article_title = news_html2text($myts->undoHtmlSpecialChars($article_title));
76
$forumdata['topic_title'] = $article_title;
77
$pdf_data['title'] = $article->title();
78
$topic_title = $article->topic_title();
79
$topic_title = news_html2text($myts->undoHtmlSpecialChars($topic_title));
80
$pdf_data['subtitle'] = $topic_title;
81
$pdf_data['subsubtitle'] = $article->subtitle();
82
$pdf_data['date'] = formatTimestamp($article->published(),$dateformat);
83
$pdf_data['filename'] = preg_replace("/[^0-9a-z\-_\.]/i",'', $myts->htmlSpecialChars($article->topic_title()).' - '.$article->title());
84
$hometext = $article->hometext();
85
$bodytext = $article->bodytext();
86
$content = $myts->undoHtmlSpecialChars($hometext) . '<br /><br />' . $myts->undoHtmlSpecialChars($bodytext);
87
$content = str_replace('[pagebreak]','<br /><br />',$content);
88
$pdf_data['content'] = $content;
89
90
$pdf_data['author'] = $article->uname();
91
92
//Other stuff
93
$puff='<br />';
94
$puffer='<br /><br />';
95
96
//create the A4-PDF...
97
$pdf_config['slogan'] = XOOPS_URL.' - '.$xoopsConfig['sitename'].' - '.$xoopsConfig['slogan'];
98
require_once (XOOPS_PATH.'/vendor/tcpdf/tcpdf.php');
99
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, _CHARSET, false);
100
// load $localLanguageOptions array with language specific definitions and apply
101
if (is_file(XOOPS_PATH.'/vendor/tcpdf/config/lang/'.$xoopsConfig['language'].'.php')) {
102
    require_once( XOOPS_PATH.'/vendor/tcpdf/config/lang/'.$xoopsConfig['language'].'.php');
103
} else {
104
    require_once( XOOPS_PATH.'/vendor/tcpdf/config/lang/english.php');
105
}
106
$pdf->setLanguageArray($localLanguageOptions);
107
108
$pdf->SetCreator(PDF_CREATOR);
109
110
$pdf->SetTitle($pdf_data['title']);
111
$pdf->SetAuthor(PDF_AUTHOR);
112
$pdf->SetSubject($pdf_data['author']);
113
$out = PDF_AUTHOR.', '.$pdf_data['author'].', '.$pdf_data['title'].', '.$pdf_data['subtitle'].', '.$pdf_data['subsubtitle'];
114
$pdf->SetKeywords($out);
115
$pdf->SetAutoPageBreak(true,25);
116
$pdf->SetMargins(PDF_MARGIN_LEFT,PDF_MARGIN_TOP,PDF_MARGIN_RIGHT);
117
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
118
$pdf->setHeaderFont(Array(PDF_FONT_NAME_SUB, '', PDF_FONT_SIZE_SUB));
119
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
120
$pdf->setFooterData($tc=array(0,64,0), $lc=array(0,64,128));
121
//$pdf->SetHeaderData('','5',$pdf_config['slogan']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
93% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
122
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, $pdf_config['slogan'], array(0,64,255), array(0,64,128));
123
//set margins
124
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
125
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
126
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
127
128
$pdf->Open();
129
//First page
130
$pdf->AddPage();
131
$pdf->SetXY(24,25);
132
$pdf->SetTextColor(10,60,160);
133
$pdf->SetFont(PDF_FONT_NAME_TITLE,PDF_FONT_STYLE_TITLE,PDF_FONT_SIZE_TITLE);
134
$pdf->WriteHTML($pdf_data['title'].' - '.$pdf_data['subtitle'],K_TITLE_MAGNIFICATION);
135
//$pdf->Line(25,20,190,20);
0 ignored issues
show
Unused Code Comprehensibility introduced by
93% of this comment could be valid code. Did you maybe forget this after debugging?

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.

Loading history...
136
if ($pdf_data['subsubtitle'] != '') {
137
    $pdf->WriteHTML($puff, K_XSMALL_RATIO);
138
    $pdf->SetFont(PDF_FONT_NAME_SUBSUB, PDF_FONT_STYLE_SUBSUB, PDF_FONT_SIZE_SUBSUB);
139
    $pdf->WriteHTML($pdf_data['subsubtitle'], '1');
140
}
141
$pdf->WriteHTML($puff,'0.2');
142
$pdf->SetFont(PDF_FONT_NAME_DATA,PDF_FONT_STYLE_DATA,PDF_FONT_SIZE_DATA);
143
$out = NEWS_PDF_AUTHOR.': '.$pdf_data['author'].'<br />';
144
$pdf->WriteHTML($out,'0.2');
145
$out = NEWS_PDF_DATE.': '. $pdf_data['date'].'<br />';
146
$pdf->WriteHTML($out,'0.2');
147
$pdf->SetTextColor(0,0,0);
148
$pdf->WriteHTML($puffer,'1');
149
150
$pdf->SetFont(PDF_FONT_NAME_MAIN,PDF_FONT_STYLE_MAIN, PDF_FONT_SIZE_MAIN);
151
$pdf->WriteHTML($pdf_data['content'],$pdf_config['scale']);
152
153
$pdf->Output();
154