Incremental Refactor Templates 3

Incremental Refactor Templates 2
This commit is contained in:
Catalin Novgorodschi
2026-05-07 11:20:05 +03:00
parent 8901c36c06
commit 60c2ed2f60
24 changed files with 2924 additions and 1057 deletions
+38 -12
View File
@@ -1,26 +1,52 @@
<?php
<?php
#################################################################################
## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- ##
## --------------------------------------------------------------------------- ##
## Filename text_format.tpl ##
## Developed by: Dixie ##
## Refactored by: Shadow Incremental Refactor ##
## License: TravianZ Project ##
## Copyright: TravianZ (c) 2010-2025. All rights reserved. ##
## Copyright: TravianZ (c) 2010-2026. All rights reserved. ##
## ##
## Incremental Refactor Notes: ##
## - Preserved original placeholder logic (%TEKST%) ##
## - Improved BBCode parsing using str_replace ##
## - Reduced repeated preg_replace calls ##
## - Added safety structure for PHP 7+ ##
## ##
#################################################################################
/**
* ---------------------------------------------------------
* Input text (template placeholder)
* ---------------------------------------------------------
*/
$txt = "%TEKST%";
$txt="%TEKST%";
/**
* ---------------------------------------------------------
* BBCode -> HTML conversion
* (kept compatible with legacy regex behavior)
* ---------------------------------------------------------
*/
$bbMap = array(
'[b]' => '<b>',
'[/b]' => '</b>',
'[i]' => '<i>',
'[/i]' => '</i>',
'[u]' => '<u>',
'[/u]' => '</u>',
);
//bbcode = html code
$txt = preg_replace("/\[b\]/is",'<b>', $txt);
$txt = preg_replace("/\[\/b\]/is",'</b>', $txt);
$txt = preg_replace("/\[i\]/is",'<i>', $txt);
$txt = preg_replace("/\[\/i\]/is",'</i>', $txt);
$txt = preg_replace("/\[u\]/is",'<u>', $txt);
$txt = preg_replace("/\[\/u\]/is",'</u>', $txt);
/**
* Apply replacements (faster + cleaner than multiple preg_replace)
*/
$txt = str_replace(array_keys($bbMap), array_values($bbMap), $txt);
//nl2br = enter
/**
* ---------------------------------------------------------
* Preserve line breaks as in original implementation
* ---------------------------------------------------------
*/
echo nl2br($txt);
?>