Make lexicon.php parse Patchouli codes (#3074)

This commit is contained in:
Al Winfy authored and Vincent Lee committed 2019-12-27 17:36:22 -06:00
1 parent dac02cccd6
commit 6dbb46ee22
1 file changed
+19 -6
+19 -6
View File
@@ -14,6 +14,19 @@
<?php
$file = file_get_contents('https://raw.githubusercontent.com/Vazkii/Botania/master/src/main/resources/assets/botania/lang/en_us.json');
$json = json_decode($file, true);
$default_keys = [
'botania_corporea_request' => 'c',
'curios.open.desc' => 'k',
'left' => 'a',
'right' => 'w',
'sprint' => 'CTRL'
];
$replacements = array_merge(array_combine(array_map("quote_keys", array_keys($default_keys)), array_values($default_keys)), [
'/\$\((br|p)\)/' => "<br />",
'/\$\(li\)/' => " &bull; ",
'/\$\(([0-9a-o])\)([^$]+)(?:\$\([0r]?\)|(?=<)|$)/' => "<span class='mc-color-$1'>$2</span>",
'/\$\(l:([^)]+)\)([^$]+)\$\(\/l\)/' => "<a href='$1'>$2</a>"
]);
$opened_div = false;
@@ -21,20 +34,17 @@
foreach($json as $key => $value) {
$entry_match = match_entry($key);
$page_match = match_page($key, $current_entry);
if(sizeof($entry_match) > 0) {
$current_entry = $entry_match[1];
if($opened_div)
echo('</div>');
echo("<br><a href='#$current_entry' class='entry-bookmark glyphicon glyphicon-bookmark' title='Permalink'></a> <b id='$current_entry-fake'>$value</b><div class='entry-text'>");
echo("\n");
$opened_div = true;
}
if(sizeof($page_match) > 0) {
$page = preg_replace('/&(.)((?:[^&])+)(?:(?:&(?:0|r))|$)/', "<span class='mc-color-$1'>$2</span>", $value) . '<br>';
$no_control = preg_replace('/&./', '', $value);
$page = preg_replace(array_keys($replacements), array_values($replacements), $value) . '<br />';
$no_control = preg_replace('/\$\(.\)/', '', $value);
if(strlen($no_control) > 50) {
echo($page);
echo("\n");
@@ -57,4 +67,7 @@
function match_page($key, $entry_name) {
return match("botania\.page\.$entry_name\d+", $key);
}
?>
function quote_keys($key) {
return "/\\$\\(k:$key\\)/";
}
?>