-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHTMLTemplate.php
245 lines (213 loc) · 7.11 KB
/
HTMLTemplate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <[email protected]>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* @since 1.5
*/
abstract class HTMLTemplateCore
{
public $title;
public $date;
public $available_in_your_account = true;
/** @var Smarty */
public $smarty;
/** @var Shop */
public $shop;
/**
* Returns the template's HTML header.
*
* @return string HTML header
*/
public function getHeader()
{
$this->assignCommonHeaderData();
return $this->smarty->fetch($this->getTemplate('header'));
}
/**
* Returns the template's HTML footer.
*
* @return string HTML footer
*/
public function getFooter()
{
$shop_address = $this->getShopAddress();
$id_shop = (int) $this->shop->id;
$this->smarty->assign(array(
'available_in_your_account' => $this->available_in_your_account,
'shop_address' => $shop_address,
'shop_fax' => Configuration::get('PS_SHOP_FAX', null, null, $id_shop),
'shop_phone' => Configuration::get('PS_SHOP_PHONE', null, null, $id_shop),
'shop_email' => Configuration::get('PS_SHOP_EMAIL', null, null, $id_shop),
'free_text' => Configuration::get('PS_INVOICE_FREE_TEXT', (int) Context::getContext()->language->id, null, $id_shop),
));
return $this->smarty->fetch($this->getTemplate('footer'));
}
/**
* Returns the shop address.
*
* @return string
*/
protected function getShopAddress()
{
$shop_address = '';
$shop_address_obj = $this->shop->getAddress();
if (isset($shop_address_obj) && $shop_address_obj instanceof Address) {
$shop_address = AddressFormat::generateAddress($shop_address_obj, array(), ' - ', ' ');
}
return $shop_address;
}
/**
* Returns the invoice logo.
*/
protected function getLogo()
{
$id_shop = (int) $this->shop->id;
$invoiceLogo = Configuration::get('PS_LOGO_INVOICE', null, null, $id_shop);
if ($invoiceLogo && file_exists(_PS_IMG_DIR_ . $invoiceLogo)) {
return $invoiceLogo;
}
$logo = Configuration::get('PS_LOGO', null, null, $id_shop);
if ($logo && file_exists(_PS_IMG_DIR_ . $logo)) {
return $logo;
}
return null;
}
/**
* Assign common header data to smarty variables.
*/
public function assignCommonHeaderData()
{
$this->setShopId();
$id_shop = (int) $this->shop->id;
$shop_name = Configuration::get('PS_SHOP_NAME', null, null, $id_shop);
$logo = $this->getLogo();
$width = 0;
$height = 0;
if (!empty($logo)) {
list($width, $height) = getimagesize(_PS_IMG_DIR_ . $logo);
}
// Limit the height of the logo for the PDF render
$maximum_height = 100;
if ($height > $maximum_height) {
$ratio = $maximum_height / $height;
$height *= $ratio;
$width *= $ratio;
}
$this->smarty->assign(array(
'logo_path' => Tools::getShopProtocol() . Tools::getMediaServer(_PS_IMG_) . _PS_IMG_ . $logo,
'img_ps_dir' => Tools::getShopProtocol() . Tools::getMediaServer(_PS_IMG_) . _PS_IMG_,
'img_update_time' => Configuration::get('PS_IMG_UPDATE_TIME'),
'date' => $this->date,
'title' => $this->title,
'shop_name' => $shop_name,
'shop_details' => Configuration::get('PS_SHOP_DETAILS', null, null, (int) $id_shop),
'width_logo' => $width,
'height_logo' => $height,
));
}
/**
* Assign hook data.
*
* @param ObjectModel $object generally the object used in the constructor
*/
public function assignHookData($object)
{
$template = ucfirst(str_replace('HTMLTemplate', '', get_class($this)));
$hook_name = 'displayPDF' . $template;
$this->smarty->assign(array(
'HOOK_DISPLAY_PDF' => Hook::exec($hook_name, array('object' => $object)),
));
}
/**
* Returns the template's HTML content.
*
* @return string HTML content
*/
abstract public function getContent();
/**
* Returns the template filename.
*
* @return string filename
*/
abstract public function getFilename();
/**
* Returns the template filename when using bulk rendering.
*
* @return string filename
*/
abstract public function getBulkFilename();
/**
* If the template is not present in the theme directory, it will return the default template
* in _PS_PDF_DIR_ directory.
*
* @param $template_name
*
* @return string
*/
protected function getTemplate($template_name)
{
$template = false;
$default_template = rtrim(_PS_PDF_DIR_, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $template_name . '.tpl';
$overridden_template = _PS_ALL_THEMES_DIR_ . $this->shop->theme->getName() . DIRECTORY_SEPARATOR . 'pdf' . DIRECTORY_SEPARATOR . $template_name . '.tpl';
if (file_exists($overridden_template)) {
$template = $overridden_template;
} elseif (file_exists($default_template)) {
$template = $default_template;
}
return $template;
}
/**
* Translation method.
*
* @param string $string
*
* @return string translated text
*/
protected static function l($string)
{
return Translate::getPdfTranslation($string);
}
protected function setShopId()
{
if (isset($this->order) && Validate::isLoadedObject($this->order)) {
$id_shop = (int) $this->order->id_shop;
} else {
$id_shop = (int) Context::getContext()->shop->id;
}
$this->shop = new Shop($id_shop);
if (Validate::isLoadedObject($this->shop)) {
Shop::setContext(Shop::CONTEXT_SHOP, (int) $this->shop->id);
}
}
/**
* Returns the template's HTML pagination block.
*
* @return string HTML pagination block
*/
public function getPagination()
{
return $this->smarty->fetch($this->getTemplate('pagination'));
}
}