Files
Smarty-Extended/ReadMe.md
Clemens Schwaighofer 856a88d891 Update to Smarty 5.7.0
Fix tests for translations, where missing in the po/mo files
Add original and post translation for compare for outside and inside smarty translation

Update documentation and only keep the git update path, the others are deprecated

Update phpunit to v11 and update tests according to this, including updated test template data file

Add the tools folder to git ignore
2026-01-07 10:06:39 +09:00

13 KiB

Composer package from Smarty Extended

This is an updated package for smarty\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

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:

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

"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 --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 .= '<input type="' . $inputType . '" name="' . $name;
                if ($ismultiselect) {
-                       $_output .= '[]';
+                       $_output .= '[' . $pos . ']';
                }
                $_output .= '" value="' . $value . '"';
                if ($labels && $label_ids) {
  • src/FunctionHander/HtmlCheckboxes.php
--- Smarty/Smarty-git/src/FunctionHandler/HtmlCheckboxes.php   2024-04-16 18:06:25.299206501 +0900
+++ core_data/composer-packages/Smarty-Extended/src/FunctionHandler/HtmlCheckboxes.php      2024-07-26 11:48:23.698784159 +0900
@@ -24,6 +24,7 @@
  * - checked    (optional) - array default not set
  * - separator  (optional) - ie <br> or &nbsp;
  * - 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
--- 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 <monte at ohrt dot com>
@@ -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 = '<option value="' . $_key . '"';
+                       $_html_result = '<option'
+                               . ($label == 'true' ?
+                                       ' label="' . smarty_function_escape_special_chars($value) . '"' : ''
+                               )
+                               . ' value="' . $_key . '"';
                        if (is_array($selected)) {
                                if (isset($selected[ $_key ])) {
                                        $_html_result .= ' selected="selected"';
@@ -192,6 +204,7 @@
                                        $selected,
                                        !empty($id) ? ($id . '-' . $idx) : null,
                                        $class,
+                                       $label,
                                        $_idx
                                );
                        $idx++;
@@ -209,11 +222,11 @@
         *
         * @return string
         */
-       private function getHtmlForOptGroup($key, $values, $selected, $id, $class, &$idx)
+       private function getHtmlForOptGroup($key, $values, $selected, $id, $class, $label, &$idx)
        {
                $optgroup_html = '<optgroup label="' . smarty_function_escape_special_chars($key) . '">' . "\n";
                foreach ($values as $key => $value) {
-                       $optgroup_html .= $this->output($key, $value, $selected, $id, $class, $idx);
+                       $optgroup_html .= $this->output($key, $value, $selected, $id, $class, $label, $idx);
                }
                $optgroup_html .= "</optgroup>\n";
                return $optgroup_html;

Updated

  • src/Extensions/DefaultExtension.php
--- Smarty/Smarty-git/src/Extension/DefaultExtension.php       2024-07-19 18:44:16.158700904 +0900
+++ core_data/composer-packages/Smarty-Extended/src/Extension/DefaultExtension.php  2024-07-26 17:38:18.257179379 +0900
@@ -94,6 +94,8 @@
                        case 'html_table': $this->functionHandlers[$functionName] = new \Smarty\FunctionHandler\HtmlTable(); break;
                        case 'mailto': $this->functionHandlers[$functionName] = new \Smarty\FunctionHandler\Mailto(); break;
                        case 'math': $this->functionHandlers[$functionName] = new \Smarty\FunctionHandler\Math(); break;
+                       case 'popup_init': $this->functionHandlers[$functionName] = new \Smarty\FunctionHandler\PopupInit(); break;
+                       case 'popup': $this->functionHandlers[$functionName] = new \Smarty\FunctionHandler\Popup(); break;
                }

                return $this->functionHandlers[$functionName] ?? null;
@@ -103,6 +105,7 @@

                switch ($blockTagName) {
                        case 'textformat': $this->blockHandlers[$blockTagName] = new \Smarty\BlockHandler\TextFormat(); break;
+                       case 't': $this->blockHandlers[$blockTagName] = new \Smarty\BlockHandler\T(); break;
                }

                return $this->blockHandlers[$blockTagName] ?? null;