38 lines
926 B
PHP
38 lines
926 B
PHP
<?php
|
|
|
|
/**
|
|
* Smarty plugin.
|
|
*/
|
|
|
|
/**
|
|
* Smarty {insert_barcode} plugin.
|
|
*
|
|
* Type: function<br>
|
|
* Name: insert_barcode<br>
|
|
* Purpose: inserts inline SVG barcode
|
|
*
|
|
* @param array $params parameters
|
|
* @param Smarty_Internal_Template $smarty
|
|
*
|
|
* @return string
|
|
*/
|
|
function smarty_function_insert_barcode($params, &$smarty)
|
|
{
|
|
if (($params['type'] ?? '') == 'EAN13') {
|
|
$params['code'] = formatEAN($params['code']);
|
|
}
|
|
|
|
try {
|
|
$generator = new Picqer\Barcode\BarcodeGeneratorSVG();
|
|
$result = $generator->getBarcode($params['code'] ?? '', $params['type'] ?? $generator::TYPE_CODE_128, $params['width'] ?? 2, $params['height'] ?? 30);
|
|
} catch (\Picqer\Barcode\Exceptions\BarcodeException $e) {
|
|
$result = '';
|
|
}
|
|
|
|
if (!empty($params['assign'])) {
|
|
$smarty->assign($params['assign'], $result);
|
|
} else {
|
|
return $result;
|
|
}
|
|
}
|