Smarty v5 update test, initial code setup
This commit is contained in:
2
test/cache/.gitignore
vendored
Normal file
2
test/cache/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
27
test/includes/locale/ja_JP.frontend.UTF-8.po
Normal file
27
test/includes/locale/ja_JP.frontend.UTF-8.po
Normal file
@@ -0,0 +1,27 @@
|
||||
# Project Name here
|
||||
# Language Name here
|
||||
# Copyright (C) 2012 E-GRAPHICS Japan
|
||||
# This file is distributed under the same license as the PACKAGE package.
|
||||
# Clemens Schwaigher <clemens.schwaighofer@e-graphics.com>, 2012/5/31
|
||||
#
|
||||
# to craete: msgfmt -o ja.mo messages.po
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Test for Smarty 3\n"
|
||||
"Report-Msgid-Bugs-To: clemens.schwaighofer@e-graphics.com\n"
|
||||
"POT-Creation-Date: 2012-05-31 14:27+0900\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: E-GRAPHICS Japan <info.japan@e-graphics.com>\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
msgid "Original"
|
||||
msgstr "Translated"
|
||||
|
||||
msgid "Original with string: %1"
|
||||
msgstr "Translated with string: %1"
|
||||
|
||||
#msgid ""
|
||||
#msgstr ""
|
||||
BIN
test/includes/locale/ja_JP/LC_MESSAGES/frontend.mo
Normal file
BIN
test/includes/locale/ja_JP/LC_MESSAGES/frontend.mo
Normal file
Binary file not shown.
95
test/includes/templates/frontend/test.full.tpl
Normal file
95
test/includes/templates/frontend/test.full.tpl
Normal file
@@ -0,0 +1,95 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<title>{$HTML_TITLE}</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset={$DEFAULT_ENCODING}">
|
||||
{popup_init src="./js/overlib/overlib.js"}
|
||||
</head>
|
||||
<body>
|
||||
BASE: {$BASE}<br>
|
||||
<hr>
|
||||
<div>
|
||||
SMARTY_TEST: {$SMARTY_TEST}
|
||||
</div>
|
||||
<div>
|
||||
TEST INSTALL {$TEST_INSTALL}
|
||||
</div>
|
||||
<div>
|
||||
MERGE DATA: {$adm_set}
|
||||
</div>
|
||||
<div {popup width="250" caption="Info v5" text="Text block<br>Control<br>SMARTY 5" bgcolor="#ece86d" fgcolor="#ecb96d" capcolor="black"}>This is a test for Smarty 5</div>
|
||||
<div {popup width="250" caption="Info" text="Text block<br>Control"} style="border: 1px solid black; margin: 5px 0 5px 0; padding: 5px;">
|
||||
POPUP HERE (hover mouse)
|
||||
</div>
|
||||
<div>
|
||||
<b>Outside translation test</b><br>
|
||||
TRANSLATION CLASS (OUT): {$TRANSLATE_TEST}<br>
|
||||
TRANSLATION CLASS (OUT FUNCTION): {$TRANSLATE_TEST_FUNCTION}<br>
|
||||
TRANSLATION CLASS (SMARTY): {$TRANSLATE_TEST_SMARTY}<br>
|
||||
</div>
|
||||
<div>
|
||||
<b>Translate Test with replace:</b><br>
|
||||
ORIGINAL: Original with string: %1 ({$replace})<br>
|
||||
TRANSLATED: {t 1=$replace}Original with string: %1{/t}<br>
|
||||
TRANSLATED (escape): {t escape=on 1=$replace}Original with string: %1{/t}<br>
|
||||
{capture assign="extra_title"}{t}INPUT TEST{/t}{/capture}
|
||||
Capture test: {$extra_title}<br>
|
||||
{section name=plural_test start=0 loop=3}
|
||||
Plural test {$smarty.section.plural_test.index}: {t count=$smarty.section.plural_test.index plural="multi"}single{/t}<br>
|
||||
{/section}
|
||||
</div>
|
||||
<div>
|
||||
<b>Plugin Test:</b><br>
|
||||
ORIGINAL: Original with string: %1 ({$replace})<br>
|
||||
TRANSLATED: {tp 1=$replace}Original with string: %1{/tp}<br>
|
||||
</div>
|
||||
<div>
|
||||
<b>Variable variables:</b><br>
|
||||
Test: {$test}<br>
|
||||
Foo: {$foo}<br>
|
||||
{assign var="bar" value="test"}
|
||||
vFoo ($test = $foo = bar): {$test|getvar}<br>
|
||||
vFoo ($bar = $test = foo): {$bar|getvar}
|
||||
</div>
|
||||
<div class="jq-container">
|
||||
<div id="jq-test" class="jp-test">
|
||||
<div id="test-div" class="test-div">
|
||||
Some content here or asdfasdfasf
|
||||
</div>
|
||||
<div id="translate-div">
|
||||
TRANSLATION SMARTY: {t}I should be translated{/t}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="loop-test">
|
||||
<div><b>LOOP TEST</b></div>
|
||||
{section name=page_list start=1 loop=$loop_start+1}
|
||||
<div>LOOP OUTPUT: {$smarty.section.page_list.index}</div>
|
||||
{/section}
|
||||
</div>
|
||||
<div>
|
||||
<select id="drop_down_test" name="drop_down_test">
|
||||
{html_options options=$drop_down_test selected=$drop_down_test_selected}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<select id="drop_down_test_nested" name="drop_down_test_nested">
|
||||
{html_options options=$drop_down_test_nested selected=$drop_down_test_nested_selected}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
{html_radios name="radio_test" options=$radio_test selected=$radio_test_selected}
|
||||
</div>
|
||||
<div>
|
||||
{html_checkboxes name="checkbox_test" options=$checkbox_test selected=$checkbox_test_selected}
|
||||
</div>
|
||||
<div>
|
||||
{html_checkboxes name="checkbox_test_pos" options=$checkbox_test selected=$checkbox_test_pos_selected pos=$checkbox_test_pos}
|
||||
</div>
|
||||
<div>
|
||||
{$lang_ex}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
90
test/includes/templates/frontend/test.simple.tpl
Normal file
90
test/includes/templates/frontend/test.simple.tpl
Normal file
@@ -0,0 +1,90 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<title>{$HTML_TITLE}</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset={$DEFAULT_ENCODING}">
|
||||
</head>
|
||||
<body>
|
||||
BASE: {$BASE}<br>
|
||||
<hr>
|
||||
<div>
|
||||
SMARTY_TEST: {$SMARTY_TEST}
|
||||
</div>
|
||||
<div>
|
||||
TEST INSTALL {$TEST_INSTALL}
|
||||
</div>
|
||||
<div>
|
||||
MERGE DATA: {$adm_set}
|
||||
</div>
|
||||
<div>
|
||||
<b>Outside translation test</b><br>
|
||||
TRANSLATION CLASS (OUT): {$TRANSLATE_TEST}<br>
|
||||
TRANSLATION CLASS (OUT FUNCTION): {$TRANSLATE_TEST_FUNCTION}<br>
|
||||
TRANSLATION CLASS (SMARTY): {$TRANSLATE_TEST_SMARTY}<br>
|
||||
</div>
|
||||
<div>
|
||||
<b>Translate Test with replace:</b><br>
|
||||
ORIGINAL: Original with string: %1 ({$replace})<br>
|
||||
TRANSLATED: {t 1=$replace}Original with string: %1{/t}<br>
|
||||
TRANSLATED (escape): {t escape=on 1=$replace}Original with string: %1{/t}<br>
|
||||
{capture assign="extra_title"}{t}INPUT TEST{/t}{/capture}
|
||||
Capture test: {$extra_title}<br>
|
||||
{section name=plural_test start=0 loop=3}
|
||||
Plural test {$smarty.section.plural_test.index}: {t count=$smarty.section.plural_test.index plural="multi"}single{/t}<br>
|
||||
{/section}
|
||||
</div>
|
||||
<div>
|
||||
<b>Plugin Test:</b><br>
|
||||
ORIGINAL: Original with string: %1 ({$replace})<br>
|
||||
TRANSLATED: {tp 1=$replace}Original with string: %1{/tp}<br>
|
||||
</div>
|
||||
<div>
|
||||
<b>Variable variables:</b><br>
|
||||
Test: {$test}<br>
|
||||
Foo: {$foo}<br>
|
||||
{assign var="bar" value="test"}
|
||||
vFoo ($test = $foo = bar): {$test|getvar}<br>
|
||||
vFoo ($bar = $test = foo): {$bar|getvar}
|
||||
</div>
|
||||
<div class="jq-container">
|
||||
<div id="jq-test" class="jp-test">
|
||||
<div id="test-div" class="test-div">
|
||||
Some content here or asdfasdfasf
|
||||
</div>
|
||||
<div id="translate-div">
|
||||
TRANSLATION SMARTY: {t}I should be translated{/t}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="loop-test">
|
||||
<div><b>LOOP TEST</b></div>
|
||||
{section name=page_list start=1 loop=$loop_start+1}
|
||||
<div>LOOP OUTPUT: {$smarty.section.page_list.index}</div>
|
||||
{/section}
|
||||
</div>
|
||||
<div>
|
||||
<select id="drop_down_test" name="drop_down_test">
|
||||
{html_options options=$drop_down_test selected=$drop_down_test_selected}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<select id="drop_down_test_nested" name="drop_down_test_nested">
|
||||
{html_options options=$drop_down_test_nested selected=$drop_down_test_nested_selected}
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
{html_radios name="radio_test" options=$radio_test selected=$radio_test_selected}
|
||||
</div>
|
||||
<div>
|
||||
{html_checkboxes name="checkbox_test" options=$checkbox_test selected=$checkbox_test_selected}
|
||||
</div>
|
||||
<div>
|
||||
{html_checkboxes name="checkbox_test_pos" options=$checkbox_test selected=$checkbox_test_pos_selected pos=$checkbox_test_pos}
|
||||
</div>
|
||||
<div>
|
||||
{$lang_ex}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
124
test/index.php
Normal file
124
test/index.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php // phpcs:ignore PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* AUTOR: Clemens Schwaighofer
|
||||
* CREATED: 2024/7/22
|
||||
* DESCRIPTION:
|
||||
* Smarty 5 Test: Just base call
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require "../vendor/autoload.php";
|
||||
|
||||
define('BASE', str_replace('/configs', '', __DIR__) . DIRECTORY_SEPARATOR);
|
||||
|
||||
# public \CoreLibs\Language\L10n $l10n;
|
||||
|
||||
$locale = 'ja_JP.UTF-8';
|
||||
$domain = 'frontend';
|
||||
$locale_path = 'includes/locale/';
|
||||
$encoding = 'UTF-8';
|
||||
|
||||
$l10n = new \CoreLibs\Language\L10n(
|
||||
$locale,
|
||||
$domain,
|
||||
$locale_path,
|
||||
$encoding
|
||||
);
|
||||
|
||||
$locale = $l10n->getLocaleAsArray();
|
||||
\CoreLibs\Language\L10n::loadFunctions();
|
||||
_setlocale(LC_MESSAGES, $locale['locale']);
|
||||
_textdomain($locale['domain']);
|
||||
_bindtextdomain($locale['domain'], $locale['path']);
|
||||
_bind_textdomain_codeset($locale['domain'], $locale['encoding']);
|
||||
|
||||
$template_name = "test.full.tpl";
|
||||
// $template_name = "test.simple.tpl";
|
||||
|
||||
$CACHE_ID = 'SmartyV5Test';
|
||||
$COMPILE_ID = 'SmartyV5Test';
|
||||
|
||||
// $smarty = \Smarty::__construct();
|
||||
$smarty = new \Smarty\Smarty();
|
||||
$smarty->setTemplateDir('includes/templates/frontend');
|
||||
$smarty->setConfigDir('configs');
|
||||
$smarty->setCompileDir('templates_c');
|
||||
$smarty->setCacheDir('cache');
|
||||
|
||||
$smarty->setEscapeHtml(true);
|
||||
$smarty->registerPlugin(\Smarty\Smarty::PLUGIN_MODIFIER, 'getvar', [&$smarty, 'getTemplateVars']);
|
||||
|
||||
require 'plugins/block.t.php';
|
||||
$smarty->registerPlugin(\Smarty\Smarty::PLUGIN_BLOCK, 'tp', 'smarty_block_t');
|
||||
|
||||
// $smarty->testInstall();
|
||||
|
||||
$CONTENT_DATA = [
|
||||
// 'TEST_INSTALL' => $smarty->testInstall(),
|
||||
'HTML_TITLE' => 'Smarty v5 tst',
|
||||
// smarty test
|
||||
'SMARTY_TEST' => 'Test Data',
|
||||
'TRANSLATE_TEST' => $l10n->__('Are we translated?'),
|
||||
'TRANSLATE_TEST_FUNCTION' => _gettext('Are we translated?'),
|
||||
'TRANSLATE_TEST_SMARTY' => $l10n->__('Are we translated?'),
|
||||
'replace' => 'Replaced',
|
||||
// variable variables
|
||||
'test' => 'foo',
|
||||
'foo' => 'bar',
|
||||
// loop
|
||||
'loop_start' => 5,
|
||||
// drop down test with optgroups
|
||||
'drop_down_test' => [
|
||||
'foo' => 'Foo',
|
||||
'bar' => 'Bar',
|
||||
'foobar' => 'Foo Bar',
|
||||
],
|
||||
'drop_down_test_selected' => 'bar',
|
||||
'drop_down_test_nested' => [
|
||||
'' => '選択してください',
|
||||
'4/25(木)' => [
|
||||
'4/25(木) 11:00-11:50' => '4/25(木) 11:00-11:50',
|
||||
'4/25(木) 12:20-13:00' => '4/25(木) 12:20-13:00'
|
||||
],
|
||||
'4/26(金)' => [
|
||||
'4/26(金) 11:00-11:50' => '4/26(金) 11:00-11:50',
|
||||
'4/26(金) 12:20-13:00' => '4/26(金) 12:20-13:00'
|
||||
],
|
||||
'4/27(土)' => [
|
||||
'4/27(土) 11:00-11:50' => '4/27(土) 11:00-11:50',
|
||||
'4/27(土) 12:20-13:00' => '4/27(土) 12:20-13:00'
|
||||
],
|
||||
],
|
||||
'drop_down_test_nested_selected' => '',
|
||||
'radio_test' => [
|
||||
'0' => 'On',
|
||||
'1' => 'Off',
|
||||
'-1' => 'Undefined'
|
||||
],
|
||||
'radio_test_selected' => -1,
|
||||
'checkbox_test' => [
|
||||
'0' => 'On',
|
||||
'1' => 'Off',
|
||||
'-1' => 'Undefined'
|
||||
],
|
||||
'checkbox_test_pos' => [
|
||||
'0' => 'A',
|
||||
'1' => 'B'
|
||||
],
|
||||
'checkbox_test_selected' => ['1', '-1'],
|
||||
'checkbox_test_pos_selected' => ['0', '-1'],
|
||||
];
|
||||
|
||||
foreach ($CONTENT_DATA as $key => $value) {
|
||||
$smarty->assign($key, $value);
|
||||
}
|
||||
|
||||
$smarty->display(
|
||||
$template_name,
|
||||
$CACHE_ID,
|
||||
$COMPILE_ID
|
||||
);
|
||||
|
||||
// __END__
|
||||
1491
test/js/overlib/overlib.js
Normal file
1491
test/js/overlib/overlib.js
Normal file
File diff suppressed because it is too large
Load Diff
206
test/plugins/block.t.php
Normal file
206
test/plugins/block.t.php
Normal file
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* smarty-gettext.php - Gettext support for smarty
|
||||
*
|
||||
* To register as a smarty block function named 't', use:
|
||||
* $smarty->register_block('t', 'smarty_translate');
|
||||
*
|
||||
* NOTE: native php support for conext sensitive does not exist
|
||||
* Those jumps are disabled
|
||||
*
|
||||
* @package smarty-gettext
|
||||
* @version $Id: block.t.php 4738 2022-05-06 01:28:48Z clemens $
|
||||
* @link http://smarty-gettext.sf.net/
|
||||
* @author Sagi Bashari <sagi@boom.org.il>
|
||||
* @copyright 2004 Sagi Bashari
|
||||
* @copyright Elan Ruusamäe
|
||||
* @copyright 2024 Clemens Schwaighofer
|
||||
*/
|
||||
|
||||
/**
|
||||
* Replaces arguments in a string with their values.
|
||||
* Arguments are represented by % followed by their number.
|
||||
*
|
||||
* @param string $str Source string
|
||||
* @param mixed mixed Arguments, can be passed in an array or through single variables.
|
||||
* @return string Modified string
|
||||
*/
|
||||
function smarty_gettext_strarg($str/*, $varargs... */)
|
||||
{
|
||||
$tr = [];
|
||||
$p = 0;
|
||||
|
||||
$nargs = func_num_args();
|
||||
for ($i = 1; $i < $nargs; $i++) {
|
||||
$arg = func_get_arg($i);
|
||||
|
||||
if (is_array($arg)) {
|
||||
foreach ($arg as $aarg) {
|
||||
$tr['%' . ++$p] = $aarg;
|
||||
}
|
||||
} else {
|
||||
$tr['%' . ++$p] = $arg;
|
||||
}
|
||||
}
|
||||
|
||||
return strtr($str, $tr);
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty block function, provides gettext support for smarty.
|
||||
*
|
||||
* The block content is the text that should be translated.
|
||||
*
|
||||
* Any parameter that is sent to the function will be represented as %n in the translation text,
|
||||
* where n is 1 for the first parameter. The following parameters are reserved:
|
||||
* - escape - sets escape mode:
|
||||
* - 'html' for HTML escaping, this is the default.
|
||||
* - 'js' for javascript escaping.
|
||||
* - 'url' for url escaping.
|
||||
* - 'no'/'off'/0 - turns off escaping
|
||||
* - plural - The plural version of the text (2nd parameter of ngettext())
|
||||
* - count - The item count for plural mode (3rd parameter of ngettext())
|
||||
* - domain - Textdomain to be used, default if skipped (dgettext() instead of gettext())
|
||||
* - context - gettext context. reserved for future use.
|
||||
*
|
||||
*/
|
||||
|
||||
// cs modified: __ calls instead of direct gettext calls
|
||||
|
||||
function smarty_block_t($params, $text)
|
||||
{
|
||||
if (!isset($text)) {
|
||||
return $text;
|
||||
}
|
||||
|
||||
$escape = 'html';
|
||||
$plural = null;
|
||||
$count = null;
|
||||
$domain = null;
|
||||
$context = null;
|
||||
|
||||
foreach ($params as $_key => $_value) {
|
||||
switch ($_key) {
|
||||
// set escape mode, default html escape
|
||||
case 'escape':
|
||||
$escape = (string)$_value;
|
||||
break;
|
||||
// set plural parameters 'plural' and 'count'.
|
||||
case 'plural':
|
||||
$plural = $_value;
|
||||
break;
|
||||
// set count, only for plural, else ignored
|
||||
case 'count':
|
||||
$count = $_value;
|
||||
break;
|
||||
// get domain param
|
||||
case 'domain':
|
||||
$domain = (string)$_value;
|
||||
break;
|
||||
// get context param
|
||||
case 'context':
|
||||
$context = (string)$_value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// use plural if required parameters are set
|
||||
if (isset($count) && isset($plural)) {
|
||||
if (isset($domain) && isset($context)) {
|
||||
if (is_callable('_dnpgettext')) {
|
||||
$text = _dnpgettext($domain, $context, $text, $plural, $count);
|
||||
}/* elseif (is_callable('dnpgettext')) {
|
||||
$text = dnpgettext($domain, $context, $text, $plural, $count);
|
||||
} */
|
||||
} elseif (isset($domain)) {
|
||||
if (is_callable('_dngettext')) {
|
||||
$text = _dngettext($domain, $text, $plural, $count);
|
||||
} elseif (is_callable('dngettext')) {
|
||||
$text = dngettext($domain, $text, $plural, $count);
|
||||
}
|
||||
} elseif (isset($context)) {
|
||||
if (is_callable('_npgettext')) {
|
||||
$text = _npgettext($context, $text, $plural, $count);
|
||||
}/* elseif (is_callable('npgettext')) {
|
||||
$text = npgettext($context, $text, $plural, $count);
|
||||
} */
|
||||
} else {
|
||||
if (is_callable('_ngettext')) {
|
||||
$text = _ngettext($text, $plural, $count);
|
||||
} elseif (is_callable('ngettext')) {
|
||||
$text = ngettext($text, $plural, $count);
|
||||
}
|
||||
}
|
||||
} else { // use normal
|
||||
if (isset($domain) && isset($context)) {
|
||||
if (is_callable('_dpgettext')) {
|
||||
$text = _dpgettext($domain, $context, $text);
|
||||
}/* elseif (is_callable('dpgettext')) {
|
||||
$text = dpgettext($domain, $context, $text);
|
||||
} */
|
||||
} elseif (isset($domain)) {
|
||||
if (is_callable('_dgettext')) {
|
||||
$text = _dgettext($domain, $text);
|
||||
} elseif (is_callable('dpgettext')) {
|
||||
$text = dgettext($domain, $text);
|
||||
}
|
||||
} elseif (isset($context)) {
|
||||
if (is_callable('_pgettext')) {
|
||||
$text = _pgettext($context, $text);
|
||||
}/* elseif (is_callable('pgettext')) {
|
||||
$text = pgettext($context, $text);
|
||||
} */
|
||||
} else {
|
||||
if (is_callable('_gettext')) {
|
||||
$text = _gettext($text);
|
||||
} elseif (is_callable('gettext')) {
|
||||
$text = gettext($text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// run strarg if there are parameters
|
||||
if (count($params)) {
|
||||
$text = smarty_gettext_strarg($text, $params);
|
||||
}
|
||||
|
||||
switch ($escape) {
|
||||
case 'html':
|
||||
// default
|
||||
$text = nl2br(htmlspecialchars($text));
|
||||
break;
|
||||
case 'javascript':
|
||||
case 'js':
|
||||
// javascript escape
|
||||
$text = strtr(
|
||||
$text,
|
||||
[
|
||||
'\\' => '\\\\',
|
||||
"'" => "\\'",
|
||||
'"' => '\\"',
|
||||
"\r" => '\\r',
|
||||
"\n" => '\\n',
|
||||
'</' => '<\/'
|
||||
]
|
||||
);
|
||||
break;
|
||||
case 'url':
|
||||
// url escape
|
||||
$text = urlencode($text);
|
||||
break;
|
||||
// below is a list for explicit OFF
|
||||
case 'no':
|
||||
case 'off':
|
||||
case 'false':
|
||||
case '0':
|
||||
case 0:
|
||||
// explicit OFF
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
// __END__
|
||||
124
test/plugins/function.popup.php
Normal file
124
test/plugins/function.popup.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty plugin
|
||||
* @package Smarty
|
||||
* @subpackage plugins
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Smarty {popup} function plugin
|
||||
*
|
||||
* Type: function<br>
|
||||
* Name: popup<br>
|
||||
* Purpose: make text pop up in windows via overlib
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @author 2024 Clemens Schwaighofer <gullevek at gullevek dot org>
|
||||
* @param array
|
||||
* @param Smarty
|
||||
* @return string
|
||||
*/
|
||||
function smarty_function_popup($params, &$smarty)
|
||||
{
|
||||
$append = '';
|
||||
foreach ($params as $_key => $_value) {
|
||||
switch ($_key) {
|
||||
case 'text':
|
||||
case 'trigger':
|
||||
case 'function':
|
||||
case 'inarray':
|
||||
$$_key = (string)$_value;
|
||||
if ($_key == 'function' || $_key == 'inarray') {
|
||||
$append .= ',' . strtoupper($_key) . ",'$_value'";
|
||||
}
|
||||
break;
|
||||
|
||||
case 'caption':
|
||||
case 'closetext':
|
||||
case 'status':
|
||||
$append .= ',' . strtoupper($_key) . ",'" . str_replace("'", "\'", $_value) . "'";
|
||||
break;
|
||||
|
||||
case 'fgcolor':
|
||||
case 'bgcolor':
|
||||
case 'textcolor':
|
||||
case 'capcolor':
|
||||
case 'closecolor':
|
||||
case 'textfont':
|
||||
case 'captionfont':
|
||||
case 'closefont':
|
||||
case 'fgbackground':
|
||||
case 'bgbackground':
|
||||
case 'caparray':
|
||||
case 'capicon':
|
||||
case 'background':
|
||||
case 'frame':
|
||||
$append .= ',' . strtoupper($_key) . ",'$_value'";
|
||||
break;
|
||||
|
||||
case 'textsize':
|
||||
case 'captionsize':
|
||||
case 'closesize':
|
||||
case 'width':
|
||||
case 'height':
|
||||
case 'border':
|
||||
case 'offsetx':
|
||||
case 'offsety':
|
||||
case 'snapx':
|
||||
case 'snapy':
|
||||
case 'fixx':
|
||||
case 'fixy':
|
||||
case 'padx':
|
||||
case 'pady':
|
||||
case 'timeout':
|
||||
case 'delay':
|
||||
$append .= ',' . strtoupper($_key) . ",$_value";
|
||||
break;
|
||||
|
||||
case 'sticky':
|
||||
case 'left':
|
||||
case 'right':
|
||||
case 'center':
|
||||
case 'above':
|
||||
case 'below':
|
||||
case 'noclose':
|
||||
case 'autostatus':
|
||||
case 'autostatuscap':
|
||||
case 'fullhtml':
|
||||
case 'hauto':
|
||||
case 'vauto':
|
||||
case 'mouseoff':
|
||||
case 'followmouse':
|
||||
case 'closeclick':
|
||||
if ($_value) {
|
||||
$append .= ',' . strtoupper($_key);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$smarty->trigger_error("[popup] unknown parameter $_key", E_USER_WARNING);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($text) && !isset($inarray) && empty($function)) {
|
||||
$smarty->trigger_error("overlib: attribute 'text' or 'inarray' or 'function' required");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (empty($trigger)) {
|
||||
$trigger = "onmouseover";
|
||||
}
|
||||
|
||||
$retval = $trigger
|
||||
. '="return overlib(\'' . preg_replace(array("!'!", "![\r\n]!"), array("\'", '\r'), $text) . '\'';
|
||||
$retval .= $append . ');"';
|
||||
if ($trigger == 'onmouseover') {
|
||||
$retval .= ' onmouseout="nd();"';
|
||||
}
|
||||
|
||||
|
||||
return $retval;
|
||||
}
|
||||
|
||||
// __END__
|
||||
44
test/plugins/function.popup_init.php
Normal file
44
test/plugins/function.popup_init.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Smarty plugin
|
||||
* @package Smarty
|
||||
* @subpackage plugins
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Smarty {popup_init} function plugin
|
||||
*
|
||||
* Type: function<br>
|
||||
* Name: popup_init<br>
|
||||
* Purpose: initialize overlib
|
||||
* @author Monte Ohrt <monte at ohrt dot com>
|
||||
* @author 2024 Clemens Schwaighofer <gullevek at gullevek dot org>
|
||||
* @param array
|
||||
* @param Smarty
|
||||
* @return string
|
||||
*/
|
||||
function smarty_function_popup_init($params, &$smarty)
|
||||
{
|
||||
/* $zindex = 1000;
|
||||
|
||||
if (!empty($params['zindex'])) {
|
||||
$zindex = $params['zindex'];
|
||||
} */
|
||||
|
||||
if (!empty($params['src'])) {
|
||||
return str_replace(
|
||||
[/*"{ZINDEX}", */"{SCRIPT_SOURCE}"],
|
||||
[/*$zindex, */$params['src']],
|
||||
// <!-- <div id="overDiv" style="position:absolute; visibility:hidden; z-index:{ZINDEX};"></div> -->
|
||||
<<<HTML
|
||||
<script type="text/javascript" language="JavaScript" src="{SCRIPT_SOURCE}"></script>
|
||||
HTML
|
||||
);
|
||||
} else {
|
||||
$smarty->trigger_error("popup_init: missing src parameter");
|
||||
}
|
||||
}
|
||||
|
||||
// __END__
|
||||
136
test/src/index.php
Normal file
136
test/src/index.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php // phpcs:ignore PSR1.Files.SideEffects
|
||||
|
||||
// v3 modified (used)
|
||||
define('DIR', __DIR__ . '/');
|
||||
define('BASE', str_replace('/src', '', __DIR__) . '/');
|
||||
define('ROOT', getcwd() . '/');
|
||||
define('INCLUDES', 'includes/');
|
||||
define('CONTENT_PATH', 'frontend/');
|
||||
define('LIB', 'lib/');
|
||||
define('LANG', 'lang/');
|
||||
define('LOCALE', 'locale/');
|
||||
define('LAYOUT', 'layout/');
|
||||
define('CSS', 'css/');
|
||||
define('JS', 'js/');
|
||||
define('FONT', 'font/');
|
||||
define('IMAGES', 'images/');
|
||||
define('CACHE', 'cache/');
|
||||
define('TEMPLATES', 'templates/');
|
||||
define('TEMPLATES_C', 'templates_c/');
|
||||
//
|
||||
define('ENCODING', 'UTF-8');
|
||||
define('DEFAULT_LANG', 'en_US');
|
||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||
define('DEFAULT_ENCODING', 'UTF-8');
|
||||
// enable to test translation
|
||||
// define('SITE_LOCALE', 'ja_JP.UTF-8');
|
||||
//
|
||||
define('G_TITLE', '');
|
||||
define('PAGE_WIDTH', '100%');
|
||||
define('ADMIN_STYLESHEET', 'edit.css');
|
||||
define('ADMIN_JAVASCRIPT', 'edit.js');
|
||||
define('STYLESHEET', '');
|
||||
define('JAVASCRIPT', '');
|
||||
define('MASTER_TEMPLATE_NAME', '');
|
||||
define('SITE_LANG', '');
|
||||
//
|
||||
define('USE_PROTOTYPE', false);
|
||||
define('USE_JQUERY', false);
|
||||
define('USE_SCRIPTACULOUS', false);
|
||||
//
|
||||
define('CACHE_ID', 'Smart4Test_Cache');
|
||||
define('COMPILE_ID', 'Smart4Test_Compile');
|
||||
|
||||
require '../vendor/autoload.php';
|
||||
|
||||
// require("Class.Smarty.Extend4.php");
|
||||
// require(LIBS . "Class.l10n.php");
|
||||
|
||||
$DATA['lang_ex'] = "Get Encoding: <pre>" . print_r(\CoreLibs\Language\GetLocale::setLocale(), true) . "</pre>";
|
||||
|
||||
$locale = \CoreLibs\Language\GetLocale::setLocale();
|
||||
$l10n = new \CoreLibs\Language\L10n(
|
||||
$locale['locale'],
|
||||
$locale['domain'],
|
||||
$locale['path'],
|
||||
);
|
||||
// we can pass $l10n to smarty here too
|
||||
$smarty_ml = new \CoreLibs\Template\SmartyExtend($l10n, $locale);
|
||||
$smarty_ml->template_dir = '../' . INCLUDES . TEMPLATES . CONTENT_PATH;
|
||||
|
||||
$language = DEFAULT_LOCALE;
|
||||
$encoding = DEFAULT_ENCODING;
|
||||
$domain = 'messages.' . $encoding;
|
||||
$locale_path = BASE . INCLUDES . LANG;
|
||||
// alternative l10n test
|
||||
$loader = new PhpMyAdmin\MoTranslator\Loader();
|
||||
// Set locale
|
||||
$loader->setlocale($language);
|
||||
// Set default text domain
|
||||
$loader->textdomain($domain);
|
||||
// Set path where to look for a domain
|
||||
$loader->bindtextdomain($domain, $locale_path);
|
||||
// Get translator
|
||||
$translator = $loader->getTranslator();
|
||||
// some translation
|
||||
$DATA['translation_test'] = $translator->gettext('Original');
|
||||
|
||||
$DATA['DEFAULT_ENCODING'] = DEFAULT_ENCODING;
|
||||
$DATA['HTML_TITLE'] = 'Smarty Test Template';
|
||||
$DATA['BASE'] = BASE;
|
||||
$DATA['translate'] = 'Original';
|
||||
$DATA['translate_out'] = $l10n->__($DATA['translate']);
|
||||
$DATA['test'] = 'foo';
|
||||
$DATA['foo'] = 'bar';
|
||||
$DATA['replace'] = 'Replaced';
|
||||
$DATA['loop_start'] = 5;
|
||||
$DATA['drop_down_test'] = [
|
||||
'foo' => 'Foo',
|
||||
'bar' => 'Bar',
|
||||
'foobar' => 'Foo Bar',
|
||||
];
|
||||
$DATA['drop_down_test_selected'] = 'bar';
|
||||
$DATA['drop_down_test_nested'] = [
|
||||
'' => '選択してください',
|
||||
'4/25(木)' => [
|
||||
'4/25(木) 11:00-11:50' => '4/25(木) 11:00-11:50',
|
||||
'4/25(木) 12:20-13:00' => '4/25(木) 12:20-13:00'
|
||||
],
|
||||
'4/26(金)' => [
|
||||
'4/26(金) 11:00-11:50' => '4/26(金) 11:00-11:50',
|
||||
'4/26(金) 12:20-13:00' => '4/26(金) 12:20-13:00'
|
||||
],
|
||||
'4/27(土)' => [
|
||||
'4/27(土) 11:00-11:50' => '4/27(土) 11:00-11:50',
|
||||
'4/27(土) 12:20-13:00' => '4/27(土) 12:20-13:00'
|
||||
],
|
||||
];
|
||||
$DATA['drop_down_test_nested_selected'] = '';
|
||||
$DATA['radio_test'] = [
|
||||
'0' => 'On',
|
||||
'1' => 'Off',
|
||||
'-1' => 'Undefined'
|
||||
];
|
||||
$DATA['radio_test_selected'] = -1;
|
||||
$DATA['checkbox_test'] = [
|
||||
'0' => 'On',
|
||||
'1' => 'Off',
|
||||
'-1' => 'Undefined'
|
||||
];
|
||||
$DATA['checkbox_test_pos'] = [
|
||||
'0' => 'A',
|
||||
'1' => 'B'
|
||||
];
|
||||
$DATA['checkbox_test_selected'] = '';
|
||||
|
||||
// smarty part
|
||||
$smarty_ml->setCompileDir(BASE . TEMPLATES_C);
|
||||
$smarty_ml->setCacheDir(BASE . CACHE);
|
||||
|
||||
foreach ($DATA as $key => $value) {
|
||||
$smarty_ml->assign($key, $value);
|
||||
}
|
||||
// content (text) is array in templates
|
||||
$smarty_ml->display('test.tpl');
|
||||
|
||||
// __END__
|
||||
1491
test/src/overlib.js
Normal file
1491
test/src/overlib.js
Normal file
File diff suppressed because it is too large
Load Diff
50
test/src/translate.php
Normal file
50
test/src/translate.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php // phpcs:ignore PSR1.Files.SideEffects
|
||||
|
||||
define('DIR', __DIR__ . '/');
|
||||
define('BASE', str_replace('/src', '', __DIR__) . '/');
|
||||
define('ROOT', getcwd() . '/');
|
||||
define('CONTENT_PATH', 'frontend/');
|
||||
define('INCLUDES', 'includes/');
|
||||
define('LANG', 'lang/');
|
||||
define('LOCALE', 'locale/');
|
||||
//
|
||||
define('ENCODING', 'UTF-8');
|
||||
define('DEFAULT_LANG', 'en_US');
|
||||
define('DEFAULT_LOCALE', 'en_US.UTF-8');
|
||||
define('DEFAULT_ENCODING', 'UTF-8');
|
||||
|
||||
require '../vendor/autoload.php';
|
||||
|
||||
$locale = \CoreLibs\Language\GetLocale::setLocale();
|
||||
$l10n = new \CoreLibs\Language\L10n(
|
||||
$locale['locale'],
|
||||
$locale['domain'],
|
||||
$locale['path'],
|
||||
);
|
||||
|
||||
$language = DEFAULT_LOCALE;
|
||||
$encoding = DEFAULT_ENCODING;
|
||||
$domain = str_replace('/', '', CONTENT_PATH) . '.' . $encoding;
|
||||
$locale_path = BASE . INCLUDES . LOCALE;
|
||||
// PATH: ja_JP or JA / LC_MESSAGES / frontend . UTF-8 .mo
|
||||
// alternative l10n test
|
||||
$loader = new PhpMyAdmin\MoTranslator\Loader();
|
||||
// Set locale
|
||||
$set_locale = $loader->setlocale($language);
|
||||
print "LOCALE: " . $language . " => " . $set_locale . "<br>";
|
||||
// Set default text domain
|
||||
$loader->textdomain($domain);
|
||||
// Set path where to look for a domain
|
||||
$loader->bindtextdomain($domain, $locale_path);
|
||||
// Get translator ($domain override)
|
||||
$translator = $loader->getTranslator();
|
||||
// some translation
|
||||
$translate = 'Original';
|
||||
$translated_mot = $translator->gettext($translate);
|
||||
$translated_l10n = $l10n->__($translate);
|
||||
|
||||
echo "ORIGINAL: " . $translate . "<br>";
|
||||
echo "TRANSLATED (MOT): " . $translated_mot . "<br>";
|
||||
echo "TRANSLATED (L10N): " . $translated_l10n . "<br>";
|
||||
|
||||
// __END__
|
||||
2
test/templates_c/.gitignore
vendored
Normal file
2
test/templates_c/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
2
test/tmp/.gitignore
vendored
Normal file
2
test/tmp/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
Reference in New Issue
Block a user