|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
You may not change or alter any portion of this comment or credits |
|
5
|
|
|
of supporting developers from this source code or any supporting source code |
|
6
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
|
7
|
|
|
|
|
8
|
|
|
This program is distributed in the hope that it will be useful, |
|
9
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
11
|
|
|
*/ |
|
12
|
|
|
/** |
|
13
|
|
|
* tdmcreate module. |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ |
|
16
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
17
|
|
|
* |
|
18
|
|
|
* @since 2.5.0 |
|
19
|
|
|
* |
|
20
|
|
|
* @author Txmod Xoops http://www.txmodxoops.org |
|
21
|
|
|
* |
|
22
|
|
|
* @version $Id: UserPdf.php 12258 2014-01-02 09:33:29Z timgno $ |
|
23
|
|
|
*/ |
|
24
|
|
|
defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Class UserPdf. |
|
28
|
|
|
*/ |
|
29
|
|
|
class UserPdf extends TDMCreateFile |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
/* |
|
32
|
|
|
* @var mixed |
|
33
|
|
|
*/ |
|
34
|
|
|
private $usercode = null; |
|
35
|
|
|
|
|
36
|
|
|
/* |
|
37
|
|
|
* @var mixed |
|
38
|
|
|
*/ |
|
39
|
|
|
private $phpcode = null; |
|
40
|
|
|
|
|
41
|
|
|
/* |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
private $xoopscode; |
|
45
|
|
|
|
|
46
|
|
|
/* |
|
47
|
|
|
* @public function constructor |
|
48
|
|
|
* @param null |
|
49
|
|
|
*/ |
|
50
|
|
|
/** |
|
51
|
|
|
* |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct() |
|
54
|
|
|
{ |
|
55
|
|
|
parent::__construct(); |
|
56
|
|
|
$this->xoopscode = TDMCreateXoopsCode::getInstance(); |
|
|
|
|
|
|
57
|
|
|
$this->phpcode = TDMCreatePhpCode::getInstance(); |
|
58
|
|
|
$this->usercode = UserXoopsCode::getInstance(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/* |
|
62
|
|
|
* @static function &getInstance |
|
63
|
|
|
* @param null |
|
64
|
|
|
*/ |
|
65
|
|
|
/** |
|
66
|
|
|
* @return UserPdf |
|
67
|
|
|
*/ |
|
68
|
|
|
public static function &getInstance() |
|
69
|
|
|
{ |
|
70
|
|
|
static $instance = false; |
|
71
|
|
|
if (!$instance) { |
|
72
|
|
|
$instance = new self(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $instance; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/* |
|
79
|
|
|
* @public function write |
|
80
|
|
|
* @param string $module |
|
81
|
|
|
* @param mixed $table |
|
82
|
|
|
* @param string $filename |
|
83
|
|
|
*/ |
|
84
|
|
|
/** |
|
85
|
|
|
* @param $module |
|
86
|
|
|
* @param $table |
|
87
|
|
|
* @param $filename |
|
88
|
|
|
*/ |
|
89
|
|
|
public function write($module, $table, $filename) |
|
90
|
|
|
{ |
|
91
|
|
|
$this->setModule($module); |
|
92
|
|
|
$this->setTable($table); |
|
93
|
|
|
$this->setFileName($filename); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @private function getUserPagesHeader |
|
98
|
|
|
* |
|
99
|
|
|
* @param $moduleDirname |
|
100
|
|
|
* @param $tableName |
|
101
|
|
|
* |
|
102
|
|
|
* @return string |
|
103
|
|
|
*/ |
|
104
|
|
|
private function getUserPdfHeader($moduleDirname, $tableName, $fields, $language) |
|
105
|
|
|
{ |
|
106
|
|
|
$fieldId = $this->xoopscode->getXoopsCodeSaveFieldId($fields); |
|
|
|
|
|
|
107
|
|
|
$ret = $this->getInclude(); |
|
108
|
|
|
$fileExist = $this->phpcode->getPhpCodeFileExists("\$tcpdf = XOOPS_ROOT_PATH.'/Frameworks/tcpdf/tcpdf.php'"); |
|
109
|
|
|
$requireOnce = $this->phpcode->getPhpCodeIncludeDir('$tcpdf', '', true, true, 'require'); |
|
110
|
|
|
$redirectHeader = $this->xoopscode->getXoopsCodeRedirectHeader($tableName, "?{$fieldId}=\${$fieldId}", $numb = '2', "{$language}NO_PDF_LIBRARY"); |
|
|
|
|
|
|
111
|
|
|
$ret .= $this->phpcode->getPhpCodeConditions($fileExist, '', '', $requireOnce, $redirectHeader, $t = ''); |
|
112
|
|
|
$ret .= $this->getCommentLine('Get Instance of Handler'); |
|
113
|
|
|
$ret .= $this->xoopscode->getXoopsHandlerLine($moduleDirname, $tableName); |
|
|
|
|
|
|
114
|
|
|
$ret .= $this->xoopscode->getXoopsCodeGet($tableName, "\$this->getVar('{$fieldId}')", '', true); |
|
|
|
|
|
|
115
|
|
|
|
|
116
|
|
|
return $ret; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/* |
|
120
|
|
|
* @public function getAdminPagesList |
|
121
|
|
|
* @param string $tableName |
|
122
|
|
|
* @param string $language |
|
123
|
|
|
*/ |
|
124
|
|
|
/** |
|
125
|
|
|
* @param $module |
|
126
|
|
|
* @param $tableName |
|
127
|
|
|
* @param $language |
|
128
|
|
|
* |
|
129
|
|
|
* @return string |
|
130
|
|
|
*/ |
|
131
|
|
|
public function getUserPdfTcpdf($moduleDirname, $fields) |
|
132
|
|
|
{ |
|
133
|
|
|
$fieldId = $this->xoopscode->getXoopsCodeSaveFieldId($fields); |
|
|
|
|
|
|
134
|
|
|
$stuModuleDirname = strtoupper($moduleDirname); |
|
135
|
|
|
$ret = ''; |
|
136
|
|
|
foreach (array_keys($fields) as $f) { |
|
137
|
|
|
$fieldName = $fields[$f]->getVar('field_name'); |
|
138
|
|
|
$fieldDefault = $fields[$f]->getVar('field_default'); |
|
139
|
|
|
$fieldElement = $fields[$f]->getVar('field_element'); |
|
140
|
|
|
$getVar = $this->xoopscode->getXoopsCodeGetVar('', 'pdfContent', $fieldName, true); |
|
|
|
|
|
|
141
|
|
|
switch ($fieldElement) { |
|
142
|
|
|
case 2: |
|
143
|
|
|
if (strstr($fieldName, 'title') || strstr($fieldName, 'name') && $fieldDefault == '') { |
|
144
|
|
|
$ret .= $this->phpcode->getPhpCodeStripTags("pdfData['title']", $getVar); |
|
145
|
|
|
} |
|
146
|
|
|
break; |
|
147
|
|
|
case 3: |
|
148
|
|
|
case 4: |
|
149
|
|
|
$ret .= $this->phpcode->getPhpCodeStripTags("pdfData['content']", $getVar); |
|
150
|
|
|
break; |
|
151
|
|
|
case 8: |
|
152
|
|
|
$ret .= $this->xoopscode->getXoopsCodeUnameFromId("pdfData['author']", $getVar); |
|
|
|
|
|
|
153
|
|
|
break; |
|
154
|
|
|
case 15: |
|
155
|
|
|
$ret .= $this->xoopscode->getXoopsCodeFormatTimeStamp("pdfData['date']", $getVar); |
|
|
|
|
|
|
156
|
|
|
break; |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
$ret .= $this->getCommentLine('Get Config'); |
|
160
|
|
|
$ret .= $this->xoopscode->getXoopsCodeEqualsOperator("\$pdfData['creator'] ", "\$GLOBALS['xoopsConfig']['xoops_sitename']"); |
|
|
|
|
|
|
161
|
|
|
$ret .= $this->xoopscode->getXoopsCodeEqualsOperator("\$pdfData['subject'] ", "\$GLOBALS['xoopsConfig']['slogan']"); |
|
|
|
|
|
|
162
|
|
|
$ret .= $this->xoopscode->getXoopsCodeEqualsOperator("\$pdfData['keywords'] ", "\$GLOBALS['xoopsConfig']['keywords']"); |
|
|
|
|
|
|
163
|
|
|
$ret .= $this->getCommentLine('Defines'); |
|
164
|
|
|
$ret .= $this->phpcode->getPhpCodeDefine("{$stuModuleDirname}_CREATOR", "\$pdfData['creator']"); |
|
165
|
|
|
$ret .= $this->phpcode->getPhpCodeDefine("{$stuModuleDirname}_AUTHOR", "\$pdfData['author']"); |
|
166
|
|
|
$ret .= $this->phpcode->getPhpCodeDefine("{$stuModuleDirname}_HEADER_TITLE", "\$pdfData['title']"); |
|
167
|
|
|
$ret .= $this->phpcode->getPhpCodeDefine("{$stuModuleDirname}_HEADER_STRING", "\$pdfData['subject']"); |
|
168
|
|
|
$ret .= $this->phpcode->getPhpCodeDefine("{$stuModuleDirname}_HEADER_LOGO", "'logo.gif'"); |
|
169
|
|
|
$ret .= $this->phpcode->getPhpCodeDefine("{$stuModuleDirname}_IMAGES_PATH", "XOOPS_ROOT_PATH.'/images/'"); |
|
170
|
|
|
$ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$myts ', 'MyTextSanitizer::getInstance()', true); |
|
|
|
|
|
|
171
|
|
|
$ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$content ', "''"); |
|
|
|
|
|
|
172
|
|
|
$ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$content .', "\$myts->undoHtmlSpecialChars(\$pdfData['content'])"); |
|
|
|
|
|
|
173
|
|
|
$ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$content ', '$myts->displayTarea($content)'); |
|
|
|
|
|
|
174
|
|
|
$ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$pdf ', 'new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, _CHARSET, false)'); |
|
|
|
|
|
|
175
|
|
|
$ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$title ', "\$myts->undoHtmlSpecialChars(\$pdfData['title'])"); |
|
|
|
|
|
|
176
|
|
|
$ret .= $this->xoopscode->getXoopsCodeEqualsOperator('$keywords ', "\$myts->undoHtmlSpecialChars(\$pdfData['keywords'])"); |
|
|
|
|
|
|
177
|
|
|
$ret .= $this->xoopscode->getXoopsCodeEqualsOperator("\$pdfData['fontsize'] ", '12'); |
|
|
|
|
|
|
178
|
|
|
$ret .= $this->getCommentLine('For schinese'); |
|
179
|
|
|
$ifLang = $this->getSimpleString("\$pdf->SetFont('gbsn00lp', '', \$pdfData['fontsize']);"); |
|
180
|
|
|
$elseLang = $this->getSimpleString("\$pdf->SetFont(\$pdfData['fontname'], '', \$pdfData['fontsize']);"); |
|
181
|
|
|
$ret .= $this->phpcode->getPhpCodeConditions('_LANGCODE', ' == ', "'cn'", $ifLang, $elseLang); |
|
182
|
|
|
$ret .= $this->getCommentLine('Set document information'); |
|
183
|
|
|
$ret .= $this->getSimpleString("\$pdf->SetCreator(\$pdfData['creator']);"); |
|
184
|
|
|
$ret .= $this->getSimpleString("\$pdf->SetAuthor(\$pdfData['author']);"); |
|
185
|
|
|
$ret .= $this->getSimpleString('$pdf->SetTitle($title);'); |
|
186
|
|
|
$ret .= $this->getSimpleString('$pdf->SetKeywords($keywords);'); |
|
187
|
|
|
$ret .= $this->getCommentLine('Set default header data'); |
|
188
|
|
|
$ret .= $this->getSimpleString("\$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, {$stuModuleDirname}_HEADER_TITLE, {$stuModuleDirname}_HEADER_STRING);"); |
|
189
|
|
|
$ret .= $this->getCommentLine('Set margins'); |
|
190
|
|
|
$ret .= $this->getSimpleString('$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP + 10, PDF_MARGIN_RIGHT);'); |
|
191
|
|
|
$ret .= $this->getCommentLine('Set auto page breaks'); |
|
192
|
|
|
$ret .= $this->getSimpleString('$pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);'); |
|
193
|
|
|
$ret .= $this->getSimpleString('$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);'); |
|
194
|
|
|
$ret .= $this->getSimpleString('$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);'); |
|
195
|
|
|
$ret .= $this->getSimpleString('$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); //set image scale factor'); |
|
196
|
|
|
$ifLang = $this->getSimpleString("\$pdf->setHeaderFont(array('gbsn00lp', '', \$pdfData['fontsize']));"); |
|
197
|
|
|
$ifLang .= $this->getSimpleString("\$pdf->setFooterFont(array('gbsn00lp', '', \$pdfData['fontsize']));"); |
|
198
|
|
|
$elseLang = $this->getSimpleString("\$pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));"); |
|
199
|
|
|
$elseLang .= $this->getSimpleString("\$pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));"); |
|
200
|
|
|
$ret .= $this->phpcode->getPhpCodeConditions('_LANGCODE', ' == ', "'cn'", $ifLang, $elseLang); |
|
201
|
|
|
$ret .= $this->getCommentLine('Set some language-dependent strings (optional)'); |
|
202
|
|
|
$fileExist = $this->phpcode->getPhpCodeFileExists("\$lang = XOOPS_ROOT_PATH.'/Frameworks/tcpdf/lang/eng.php')"); |
|
203
|
|
|
$contIf = $this->phpcode->getPhpCodeIncludeDir('$lang', '', true, false, 'require'); |
|
204
|
|
|
$contIf .= $this->getSimpleString('$pdf->setLanguageArray($l);'); |
|
205
|
|
|
$ret .= $this->phpcode->getPhpCodeConditions("@{$fileExist}", '', '', $contIf); |
|
206
|
|
|
|
|
207
|
|
|
return $ret; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* @private function getUserPdfFooter |
|
212
|
|
|
* |
|
213
|
|
|
* @param $moduleDirname |
|
214
|
|
|
* @param $tableName |
|
215
|
|
|
* |
|
216
|
|
|
* @return string |
|
217
|
|
|
*/ |
|
218
|
|
|
private function getUserPdfFooter($moduleDirname, $tableName) |
|
219
|
|
|
{ |
|
220
|
|
|
$ret = $this->getCommentLine('Initialize document'); |
|
221
|
|
|
$ret .= $this->getSimpleString('$pdf->AliasNbPages();'); |
|
222
|
|
|
$ret .= $this->getCommentLine('Add Page document'); |
|
223
|
|
|
$ret .= $this->getSimpleString('$pdf->AddPage();'); |
|
224
|
|
|
$ret .= $this->getSimpleString("\$pdf->writeHTMLCell(\$w=0, \$h=0, \$x='', \$y='', \$content, \$border=0, \$ln=1, \$fill=0, \$reseth=true, \$align='', \$autopadding=true);"); |
|
225
|
|
|
$ret .= $this->getCommentLine('Pdf Filename'); |
|
226
|
|
|
$ret .= $this->getCommentLine('Output'); |
|
227
|
|
|
$ret .= $this->xoopscode->getXoopsCodeTplAssign('pdfoutput', "\$pdf->Output('{$tableName}.pdf', 'I')"); |
|
|
|
|
|
|
228
|
|
|
$ret .= $this->xoopscode->getXoopsCodeTplDisplay("{$moduleDirname}_pdf.tpl"); |
|
|
|
|
|
|
229
|
|
|
|
|
230
|
|
|
return $ret; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/* |
|
234
|
|
|
* @public function render |
|
235
|
|
|
* @param null |
|
236
|
|
|
*/ |
|
237
|
|
|
/** |
|
238
|
|
|
* @return bool|string |
|
239
|
|
|
*/ |
|
240
|
|
|
public function render() |
|
241
|
|
|
{ |
|
242
|
|
|
$module = $this->getModule(); |
|
243
|
|
|
$table = $this->getTable(); |
|
244
|
|
|
$filename = $this->getFileName(); |
|
245
|
|
|
$moduleDirname = $module->getVar('mod_dirname'); |
|
246
|
|
|
$tableId = $table->getVar('table_id'); |
|
247
|
|
|
$tableMid = $table->getVar('table_mid'); |
|
248
|
|
|
$tableName = $table->getVar('table_name'); |
|
249
|
|
|
$fields = $this->getTableFields($tableMid, $tableId); |
|
250
|
|
|
$language = $this->getLanguage($moduleDirname, 'MA'); |
|
251
|
|
|
$content = $this->getHeaderFilesComments($module, $filename); |
|
252
|
|
|
$content .= $this->getUserPdfHeader($moduleDirname, $tableName, $fields, $language); |
|
253
|
|
|
$content .= $this->getUserPdfTcpdf($moduleDirname, $fields); |
|
254
|
|
|
$content .= $this->getUserPdfFooter($moduleDirname, $tableName); |
|
255
|
|
|
|
|
256
|
|
|
$this->create($moduleDirname, '/', $filename, $content, _AM_TDMCREATE_FILE_CREATED, _AM_TDMCREATE_FILE_NOTCREATED); |
|
257
|
|
|
|
|
258
|
|
|
return $this->renderFile(); |
|
259
|
|
|
} |
|
260
|
|
|
} |
|
261
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.