// PDF override
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@14342 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
+15
-13
@@ -184,24 +184,26 @@ class TranslateCore
|
||||
global $_LANGPDF;
|
||||
|
||||
$iso = Context::getContext()->language->iso_code;
|
||||
if (!Validate::isLanguageIsoCode($iso))
|
||||
throw PrestaShopException('Invalid iso lang!');
|
||||
|
||||
$filename = _PS_THEME_DIR_.'pdf/lang/'.$iso.'.php';
|
||||
if (!Validate::isLangIsoCode($iso))
|
||||
Tools::displayError(sprintf('Invalid iso lang (%s)', Tools::safeOutput($iso)));
|
||||
|
||||
if (Tools::file_exists_cache($filename))
|
||||
@include_once($filename);
|
||||
$override_i18n_file = _PS_THEME_DIR_.'pdf/lang/'.$iso.'.php';
|
||||
$i18n_file = _PS_TRANSLATIONS_DIR_.$iso.'/pdf.php';
|
||||
if (file_exists($override_i18n_file))
|
||||
$i18n_file = $override_i18n_file;
|
||||
|
||||
$key = 'PDF'.md5($string);
|
||||
$lang_array = $_LANGPDF;
|
||||
if (!include($i18n_file))
|
||||
Tools::displayError(sprintf('Cannot include PDF translation language file : %s', $i18n_file));
|
||||
|
||||
$msg = $string;
|
||||
if (is_array($lang_array) && key_exists($key, $lang_array))
|
||||
$msg = $lang_array[$key];
|
||||
elseif (is_array($lang_array) && key_exists(Tools::strtolower($key), $lang_array))
|
||||
$msg = $lang_array[Tools::strtolower($key)];
|
||||
if (!isset($_LANGPDF) || !is_array($_LANGPDF))
|
||||
return str_replace('"', '"', $string);
|
||||
|
||||
return $msg;
|
||||
$key = md5(str_replace('\'', '\\\'', $string));
|
||||
|
||||
$str = (key_exists('PDF'.$key, $_LANGPDF) ? $_LANGPDF['PDF'.$key] : $string);
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -177,27 +177,7 @@ abstract class HTMLTemplateCore
|
||||
*/
|
||||
protected static function l($string)
|
||||
{
|
||||
$iso = Context::getContext()->language->iso_code;
|
||||
|
||||
if (!Validate::isLangIsoCode($iso))
|
||||
Tools::displayError(sprintf('Invalid iso lang (%s)', Tools::safeOutput($iso)));
|
||||
|
||||
$override_i18n_file = _PS_THEME_DIR_.'pdf/lang/'.$iso.'.php';
|
||||
$i18n_file = _PS_TRANSLATIONS_DIR_.$iso.'/pdf.php';
|
||||
if (file_exists($override_i18n_file))
|
||||
$i18n_file = $override_i18n_file;
|
||||
|
||||
if (!include($i18n_file))
|
||||
Tools::displayError(sprintf('Cannot include PDF translation language file : %s', $i18n_file));
|
||||
|
||||
if (!isset($_LANGPDF) || !is_array($_LANGPDF))
|
||||
return str_replace('"', '"', $string);
|
||||
|
||||
$key = md5(str_replace('\'', '\\\'', $string));
|
||||
|
||||
$str = (key_exists('PDF'.$key, $_LANGPDF) ? $_LANGPDF['PDF'.$key] : $string);
|
||||
|
||||
return $str;
|
||||
return Translate::getPdfTranslation($string);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ class HTMLTemplateDeliverySlipCore extends HTMLTemplate
|
||||
'order_invoice' => $this->order_invoice
|
||||
));
|
||||
|
||||
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/delivery-slip.tpl');
|
||||
return $this->smarty->fetch($this->getTemplate('delivery-slip'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -71,7 +71,7 @@ class HTMLTemplateOrderReturnCore extends HTMLTemplate
|
||||
'invoice_address' => $formatted_invoice_address,
|
||||
'shop_address' => AddressFormat::generateAddress($this->address, array(), '<br />', ' ')
|
||||
));
|
||||
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/order-return.tpl');
|
||||
return $this->smarty->fetch($this->getTemplate('order-return'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,3 +92,4 @@ class HTMLTemplateOrderReturnCore extends HTMLTemplate
|
||||
return 'invoices.pdf';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice
|
||||
'tax_tab' => '',
|
||||
));
|
||||
|
||||
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/order-slip.tpl');
|
||||
return $this->smarty->fetch($this->getTemplate('order-slip'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,4 +130,5 @@ class HTMLTemplateOrderSlipCore extends HTMLTemplateInvoice
|
||||
{
|
||||
return 'order-slip-'.sprintf('%06d', $this->order_slip->id).'.pdf';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,8 @@ class HTMLTemplateSupplyOrderFormCore extends HTMLTemplate
|
||||
'tax_order_summary' => $tax_order_summary,
|
||||
'currency' => $currency,
|
||||
));
|
||||
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/supply-order.tpl');
|
||||
|
||||
return $this->smarty->fetch($this->getTemplate('supply-order'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,7 +136,7 @@ class HTMLTemplateSupplyOrderFormCore extends HTMLTemplate
|
||||
'shop_name' => $shop_name
|
||||
));
|
||||
|
||||
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/supply-order-header.tpl');
|
||||
return $this->smarty->fetch($this->getTemplate('supply-order-header'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,7 +156,7 @@ class HTMLTemplateSupplyOrderFormCore extends HTMLTemplate
|
||||
'shop_details' => Configuration::get('PS_SHOP_DETAILS'),
|
||||
'free_text' => $free_text,
|
||||
));
|
||||
return $this->smarty->fetch(_PS_THEME_DIR_.'/pdf/supply-order-footer.tpl');
|
||||
return $this->smarty->fetch($this->getTemplate('supply-order-footer'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -188,3 +189,4 @@ class HTMLTemplateSupplyOrderFormCore extends HTMLTemplate
|
||||
$supply_order->total_ti = Tools::ps_round($supply_order->total_ti, 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -260,16 +260,26 @@ class AdminInvoicesControllerCore extends AdminController
|
||||
'name' => 'invoice'
|
||||
)
|
||||
);
|
||||
$d = dir(_PS_THEME_DIR_.'/pdf/');
|
||||
while (false !== ($entry = $d->read()))
|
||||
|
||||
$templates_override = $this->getInvoicesModelsFromDir(_PS_THEME_DIR_.'pdf/');
|
||||
$templates_default = $this->getInvoicesModelsFromDir(_PS_PDF_DIR_);
|
||||
|
||||
foreach (array_merge($templates_default, $templates_override) as $template)
|
||||
{
|
||||
if (preg_match('`^(invoice-[a-z0-9]+)\.tpl$`', $entry, $matches))
|
||||
$models[] = array(
|
||||
'value' => $matches[1],
|
||||
'name' => $matches[1]
|
||||
);
|
||||
$template_name = basename($template, '.tpl');
|
||||
$models[] = array('value' => $template_name, 'name' => $template_name);
|
||||
}
|
||||
$d->close();
|
||||
return $models;
|
||||
}
|
||||
|
||||
protected function getInvoicesModelsFromDir($directory)
|
||||
{
|
||||
$templates = array();
|
||||
|
||||
if (is_dir($directory))
|
||||
$templates = glob($directory.'invoice-*.tpl');
|
||||
|
||||
return $templates;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user