# Composer package from Smarty Extended This is an updated package for [smarty\smarty](https://github.com/smarty-php/smarty/) Adds: - translation block - label and pos for checkboxes and radio buttons For local install only ## Setup from central composer Setup from gitea internal servers ```sh composer config repositories.git.egplusww.jp.Composer composer https://git.egplusww.jp/api/packages/Composer/composer ``` Alternative setup composer local zip file repot: `composer config repositories.composer.egplusww.jp composer http://composer.egplusww.jp` > [!notice] > Requires mbstring extension installed, will not use the symfony/polyfill-mbstring ## Install package `composer require egrajp/smarty-extended:^5` ## How to update 1) Alternative is to checkout master branch from git 1) Located in `Smarty/Smarty-git/src/` 2) Run `git pull smarty master` 2) Copy the `src/` folder as is over the `Smarty/Smarty-Extended/src` folder 3) From the `update/` folder copy 1) copy over the following into `src/BlockHandler/`: 1) T.php 2) copy over the following into `src/FunctionHandler`: 1) Popup.php 2) PopupInit.php 3) Upate the global `src/Extensions/DefaultExtension.php`: 1) `getFunctionHandler`: popup_init, popup 2) `getBlockHandler`: t 4) check either `src/FunctionHander/HtmlCheckboxes.php`, `src/FunctionHander/HtmlOptions.php` and `src/FunctionHander/HtmlBase.php` have changed 1) Update and leep the label/pos changes 4) Create new release version as official relase number ## Test After any update run `tools/phpunit` to test the compare output, also a visual check can be done by accessing the `test/` folder - Translations should work - pos/label names for checkbox/options should work - get var output should work - plugin test load should work ### For intelephense users when phpunit was installed as phar Intelephense cannot directly access the phar file, if phpunit was installed as a phar file (eg via phive) then the following commands must be used to setup the intelephense parser In the base folder: ```sh php -r "(new Phar('/path/to/phive/folder/.phive/phars/phpunit-X.Y.Z.phar'))->extractTo('tools-libs/phpunit');" // Example, must point to the .phar file itself php -r "(new Phar('/storage/home/clemens/.phive/phars/phpunit-11.5.46.phar'))->extractTo('tools-libs/phpunit');" ``` Then open the vscode settings and set for the Folder (if multiple folders are in the workspace) or the Workspace the following setting ```txt "intelephense.environment.includePaths": [ "/tools-libs/phpunit/" ] ``` ## Updated files (different from master) ### New - `src/BlockHandler/T.php` - `src/FunctionHandler/Popup.php` - `src/FunctionHandler/PopupInit.php` ### Changed - `src/FunctionHander/HtmlBase.php` ```diff diff --git i/src/FunctionHandler/HtmlBase.php w/src/FunctionHandler/HtmlBase.php index 99f8e6c..99a82a6 100644 --- i/src/FunctionHandler/HtmlBase.php +++ w/src/FunctionHandler/HtmlBase.php @@ -16,6 +16,7 @@ class HtmlBase extends Base { * @param $labels * @param $label_ids * @param bool $escape + * @param $pos [default=''] * * @return string */ @@ -30,7 +31,8 @@ class HtmlBase extends Base { $separator, $labels, $label_ids, - $escape = true + $escape = true, + $pos = '' ) { $_output = ''; @@ -83,7 +85,7 @@ class HtmlBase extends Base { } $_output .= ' or   * - output (optional) - the output next to each checkbox + * - pos (optional) - position entry into the [] for multi checkboxes * - assign (optional) - assign the output as an array to this variable * - escape (optional) - escape the content (not value), defaults to true * @@ -50,6 +51,7 @@ $labels = true; $label_ids = false; $output = null; + $pos = null; $extra = ''; foreach ($params as $_key => $_val) { switch ($_key) { @@ -111,6 +113,9 @@ ); $options = (array)$_val; break; + case 'pos': + $$_key = array_values((array)$_val); + break; case 'strict': case 'assign': break; @@ -145,6 +150,7 @@ $_html_result = []; if (isset($options)) { foreach ($options as $_key => $_val) { + $_pos = isset($pos[ $_key ]) ? $pos[ $_key ] : ''; $_html_result[] = $this->getHtmlForInput( 'checkbox', @@ -157,12 +163,14 @@ $separator, $labels, $label_ids, - $_pos, - $escape + $escape, + $_pos ); } } else { foreach ($values as $_i => $_key) { $_val = isset($output[$_i]) ? $output[$_i] : ''; + $_pos = isset($pos[ $_i ]) ? $pos[ $_i ] : ''; $_html_result[] = $this->getHtmlForInput( 'checkbox', @@ -175,6 +183,7 @@ $separator, $labels, $label_ids, - $_pos, - $escape + $escape, + $_pos ); } ``` - `src/FunctionHander/HtmlOptions.php` ```diff --- Smarty/Smarty-git/src/FunctionHandler/HtmlOptions.php 2024-04-16 18:06:25.299206501 +0900 +++ core_data/composer-packages/Smarty-Extended/src/FunctionHandler/HtmlOptions.php 2024-07-26 11:51:13.287320709 +0900 @@ -17,6 +17,7 @@ * - selected (optional) - string default not set * - output (required) - if not options supplied) - array * - id (optional) - string default not set + * - label (optional) - label strinng to set * - class (optional) - string default not set * * @author Monte Ohrt @@ -40,6 +41,7 @@ $output = null; $id = null; $class = null; + $label = true; $extra = ''; foreach ($params as $_key => $_val) { switch ($_key) { @@ -89,6 +91,11 @@ $selected = smarty_function_escape_special_chars((string)$_val); } break; + case 'label': + if ($_val == 'true' || $_val == 'false') { + $$_key = (string)$_val; + } + break; case 'strict': break; case 'disabled': @@ -124,12 +131,12 @@ $_idx = 0; if (isset($options)) { foreach ($options as $_key => $_val) { - $_html_result .= $this->output($_key, $_val, $selected, $id, $class, $_idx); + $_html_result .= $this->output($_key, $_val, $selected, $id, $class, $label, $_idx); } } else { foreach ($values as $_i => $_key) { $_val = $output[$_i] ?? ''; - $_html_result .= $this->output($_key, $_val, $selected, $id, $class, $_idx); + $_html_result .= $this->output($_key, $_val, $selected, $id, $class, $label, $_idx); } } if (!empty($name)) { @@ -149,15 +156,20 @@ * @param $selected * @param $id * @param $class + * @param $label * @param $idx * * @return string */ - private function output($key, $value, $selected, $id, $class, &$idx) + private function output($key, $value, $selected, $id, $class, $label, &$idx) { if (!is_array($value)) { $_key = smarty_function_escape_special_chars($key); - $_html_result = '