$1"; $pattern[] = "/\[i\](.*?)\[\/i\]/is"; $replace[] = "$1"; $pattern[] = "/\[u\](.*?)\[\/u\]/is"; $replace[] = "$1"; /* Unit placeholders tid1 - tid50 */ for ($i = 1; $i <= 50; $i++) { $pattern[] = "/\[tid{$i}\]/"; $replace[] = "" . constant("U{$i}") . ""; } /* Hero */ $pattern[] = "/\[hero\]/"; $replace[] = "" . U0 . ""; /* Resources */ $resourceMap = [ 'lumber' => [1, LUMBER], 'clay' => [2, CLAY], 'iron' => [3, IRON], 'crop' => [4, CROP], ]; foreach ($resourceMap as $tag => $data) { [$id, $name] = $data; $pattern[] = "/\[" . $tag . "\]/"; $replace[] = "{$name}"; } /* Smilies & emoticons */ $smilies = [ "/\*aha\*/" => "*aha*", "/\*angry\*/" => "*angry*", "/\*cool\*/" => "*cool*", "/\*cry\*/" => "*cry*", "/\*cute\*/" => "*cute*", "/\*depressed\*/" => "*depressed*", "/\*eek\*/" => "*eek*", "/\*ehem\*/" => "*ehem*", "/\*emotional\*/" => "*emotional*", "/:D/" => ":D", "/:\)/" => ":)", "/\*hit\*/" => "*hit*", "/\*hmm\*/" => "*hmm*", "/\*hmpf\*/" => "*hmpf*", "/\*hrhr\*/" => "*hrhr*", "/\*huh\*/" => "*huh*", "/\*lazy\*/" => "*lazy*", "/\*love\*/" => "*love*", "/\*nocomment\*/" => "*nocomment*", "/\*noemotion\*/" => "*noemotion*", "/\*notamused\*/" => "*notamused*", "/\*pout\*/" => "*pout*", "/\*redface\*/" => "*redface*", "/\*rolleyes\*/" => "*rolleyes*", "/:\(/" => ":(", "/\*shy\*/" => "*shy*", "/\*smile\*/" => "*smile*", "/\*tongue\*/" => "*tongue*", "/\*veryangry\*/" => "*veryangry*", "/\*veryhappy\*/" => "*veryhappy*", "/;\)/" => ";)", ]; foreach ($smilies as $k => $v) { $pattern[] = $k; $replace[] = $v; } /* Message cleanup */ $input = preg_replace('/\[message\]/', '', $input); $input = preg_replace('/\[\/message\]/', '', $input); /* Apply BBCode/static replacements */ $bbcoded = preg_replace($pattern, $replace, $input); /** * ------------------------------------------------------------------------- * CALLBACK REPLACEMENTS (dynamic database-driven content) * ------------------------------------------------------------------------- */ /* Alliance */ $bbcoded = preg_replace_callback( "/\[alliance(\d{0,20})\]([^\]]*)\[\/alliance\d{0,20}\]/is", function ($matches) { global $database; $aname = $database->getAllianceName($matches[2]); if (!empty($aname)) { return "{$aname}"; } return "Alliance not found!"; }, $bbcoded ); /* Player */ $bbcoded = preg_replace_callback( "/\[player(\d{0,20})\]([^\]]*)\[\/player\d{0,20}\]/is", function ($matches) { global $database; $uname = $database->getUserField((int)$matches[2], "username", 0); if (!empty($uname) && $uname !== "[?]") { return "{$uname}"; } return "Player not found!"; }, $bbcoded ); /* Report */ $bbcoded = preg_replace_callback( "/\[report(\d{0,20})\]([^\]]*)\[\/report\d{0,20}\]/is", function ($matches) { global $database; $reportID = $matches[1] > 0 ? $matches[1] : $matches[2]; $report = $database->getNotice2((int)$reportID, null, false); if (!empty($report)) { return "{$report['topic']}"; } return "Report not found!"; }, $bbcoded ); /* Coordinates */ $bbcoded = preg_replace_callback( "/\[coor(\d{0,20})\]([^\]]*)\[\/coor\d{0,20}\]/is", function ($matches) { global $generator, $database; $coordinates = explode("|", $matches[2]); $wRef = $database->getVilWref($coordinates[0], $coordinates[1]); $cwref = $generator->getMapCheck($wRef); $state = $database->getVillageType($wRef); if ($state > 0) { $name = $database->getVillageState($wRef) ? $database->getVillageField($wRef, 'name') : ABANDVALLEY; } else { $name = $database->getOasisInfo($wRef)['name'] ?? ''; } if (!empty($name)) { return "{$name} ({$coordinates[0]}|{$coordinates[1]})"; } return "Village not found!"; }, $bbcoded ); /* Final cleanup safety */ $bbcoded = preg_replace('/\[message\]/', '', $bbcoded); $bbcoded = preg_replace('/\[\/message\]/', '', $bbcoded); ?>