mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-07-10 06:36:07 +00:00
Incremental Refactor Templates 3
Incremental Refactor Templates 2
This commit is contained in:
+38
-12
@@ -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);
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user