mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-12 01:49:53 +01:00
Rewrote remaining plugins to PSR-4, plugins dir is now gone.
This commit is contained in:
@@ -18,7 +18,16 @@ class Base implements ExtensionInterface {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getBlockHandler(string $functionName): ?\Smarty\FunctionHandler\BlockHandlerInterface {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getModifierCallback(string $modifierName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getOutputFilters(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -124,6 +124,19 @@ class Core extends Base {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getBlockHandler(string $blockTagName): ?\Smarty\FunctionHandler\BlockHandlerInterface {
|
||||
switch ($blockTagName) {
|
||||
case 'textformat': return new \Smarty\BlockHandler\TextFormat();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getOutputFilters(): array {
|
||||
return [
|
||||
new \Smarty\Filter\Output\TrimWhitespace(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Smarty spacify modifier plugin
|
||||
* Type: modifier
|
||||
@@ -560,51 +573,7 @@ class Core extends Base {
|
||||
*/
|
||||
private function smarty_modifier_mb_wordwrap($str, $width = 75, $break = "\n", $cut = false)
|
||||
{
|
||||
// break words into tokens using white space as a delimiter
|
||||
$tokens = preg_split('!(\s)!S' . \Smarty\Smarty::$_UTF8_MODIFIER, $str, -1, PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE);
|
||||
$length = 0;
|
||||
$t = '';
|
||||
$_previous = false;
|
||||
$_space = false;
|
||||
foreach ($tokens as $_token) {
|
||||
$token_length = mb_strlen($_token, \Smarty\Smarty::$_CHARSET);
|
||||
$_tokens = array($_token);
|
||||
if ($token_length > $width) {
|
||||
if ($cut) {
|
||||
$_tokens = preg_split(
|
||||
'!(.{' . $width . '})!S' . \Smarty\Smarty::$_UTF8_MODIFIER,
|
||||
$_token,
|
||||
-1,
|
||||
PREG_SPLIT_NO_EMPTY + PREG_SPLIT_DELIM_CAPTURE
|
||||
);
|
||||
}
|
||||
}
|
||||
foreach ($_tokens as $token) {
|
||||
$_space = !!preg_match('!^\s$!S' . \Smarty\Smarty::$_UTF8_MODIFIER, $token);
|
||||
$token_length = mb_strlen($token, \Smarty\Smarty::$_CHARSET);
|
||||
$length += $token_length;
|
||||
if ($length > $width) {
|
||||
// remove space before inserted break
|
||||
if ($_previous) {
|
||||
$t = mb_substr($t, 0, -1, \Smarty\Smarty::$_CHARSET);
|
||||
}
|
||||
if (!$_space) {
|
||||
// add the break before the token
|
||||
if (!empty($t)) {
|
||||
$t .= $break;
|
||||
}
|
||||
$length = $token_length;
|
||||
}
|
||||
} elseif ($token === "\n") {
|
||||
// hard break must reset counters
|
||||
$length = 0;
|
||||
}
|
||||
$_previous = $_space;
|
||||
// add the token
|
||||
$t .= $token;
|
||||
}
|
||||
}
|
||||
return $t;
|
||||
return smarty_mb_wordwrap($str, $width, $break, $cut);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,10 @@ interface ExtensionInterface {
|
||||
|
||||
public function getFunctionHandler(string $functionName): ?\Smarty\FunctionHandler\FunctionHandlerInterface;
|
||||
|
||||
public function getBlockHandler(string $blockTagName): ?\Smarty\FunctionHandler\BlockHandlerInterface;
|
||||
|
||||
public function getModifierCallback(string $modifierName);
|
||||
|
||||
public function getOutputFilters(): array;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user