f7faa504f86a210be8979e8f9718ae689f077d4e
The correct place is at the EGRA github org, reference original in the description. Update the require part for the composer json file with this new information
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
- update the original composer for ^5
- Located in
Smarty/Smarty-Composer/vendor/smarty/smarty/src/
- Located in
- Alternative is to checkout master branch from git
- Located in
Smarty/Smarty-git/src/
- Located in
- copy over the following into
src/BlockHandler/:- T.php
- copy over the following into
src/FunctionHandler:- Popup.php
- PopupInit.php
- Upate the global
src/Extensions/DefaultExtension.php:getFunctionHandler: popup_init, popupgetBlockHandler: t
- check either
src/FunctionHander/HtmlCheckboxes.phpandsrc/FunctionHander/HtmlOptions.phphave changed- Update and leep the label/pos changes
- Create new release version as official relase number
Updated files (different from master)
New
src/BlockHandler/T.phpsrc/FunctionHandler/Popup.phpsrc/FunctionHandler/PopupInit.php
Changed
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
* - 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
);
}
} 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
);
}
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;
Description
Based on original Smarty, Version 4.x
https://github.com/smarty-php/smarty/tree/master
Extended with translation block and checkbox/radio labels and index positions
Languages
PHP
89.2%
JavaScript
4.9%
Yacc
4.3%
Smarty
1.2%
Shell
0.4%