/** * Post-parser * * Use this method in case you want to alter the parsed bbcode. * The newline placeholders are still available and any remaining will be removed in the last step before output * * Example: you want the "img" bbcode to use database images instead of user URLs. * You'd go and change the tag so that it only accepts digits like [img=123456] * and replace any occurence with a unique placeholder like {IMG|ID}. * Now the post-parser gets into play: you preg_match_all() out all your placeholders, * grab the images in a single query from the database and replace them with their respective <img> tag * or whatever replacement and any corrupt id with a placeholder image. Profit! * * @param string $bbcode bbcode * * @return string postparsed bbcode */ public function post($bbcode) { $skills_search = []; $skills_search_id = []; $skillsets = []; $pattern = '/\\{(?<type>[A-Z]+)(?:\\|)(?<content>[^\\}]*)\\}/'; if (preg_match_all($pattern, $bbcode, $matches, PREG_SET_ORDER) > 0) { # var_dump($matches); $st = new SkillTranscoder(); // collect all skills foreach ($matches as $key => $match) { switch ($match['type']) { case 'BUILD': $_skills = explode('|', explode('#', $match['content'])[2]); $skills_search = array_merge($skills_search, $_skills); $build = new Build(); $build->skill_search = $_skills; $build->pcre_match = $match[0]; $skillsets[] = $build; break; case 'BUILDCODE': $build = new Build(explode('|', $match['content'])[1]); $build->pcre_match = $match[0]; $build = $st->set_template($build)->decode()->get_template(); $skills_search_id = array_merge($skills_search_id, $build->skills); $skillsets[] = $build; break; case 'SKILL': $skills_search[] = explode('|', $match['content'])[0]; break; } } $skills_search_id = array_unique($skills_search_id); $sql = 'SELECT * FROM gw1_skilldata WHERE id in(' . substr(str_repeat('?,', count($skills_search_id)), 0, -1) . ')'; $x = $this->gwdb->prepared($sql, $skills_search_id); var_dump($x); } return $bbcode; }
* @created 06.11.2015 * @author Smiley <*****@*****.**> * @copyright 2015 Smiley * @license MIT */ require_once '../vendor/autoload.php'; use chillerlan\GW1Database\Equipment\Set; use chillerlan\GW1Database\Equipment\EquipmentTranscoder; use chillerlan\GW1Database\Pawned\Team; use chillerlan\GW1Database\Pawned\PawnedTranscoder; use chillerlan\GW1Database\Skills\Build; use chillerlan\GW1Database\Skills\SkillTranscoder; // skill template $st = new SkillTranscoder(); $skills = new Build('OQdCA8wkpTeGbji4b2PwDAPF'); $skills = $st->set_template($skills)->decode()->get_template(); var_dump($skills); $skills = $st->encode()->get_template(); var_dump($skills); // equipment template $et = new EquipmentTranscoder(); $equipment = new Set('Pg5hhmZ9phOzriUhhpI904yUkhl/YKyl0BMFZYNLmi0C'); $equipment = $et->set_template($equipment)->decode()->get_template(); var_dump($equipment); $equipment = $et->encode()->get_template(); var_dump($equipment); // paw·ned² template $pt = new PawnedTranscoder(); $pwnd = new Team('pwnd0000?download paw·ned² @ www.gw-tactics.de Copyright numma_cway aka Redeemer >YOwVS85BTRA6M4OIQ0kHQxldOsPk5JWEMZYE8EMJYd8EMJYn8EMJY77EMJYRRFSaCjkC0KJPcZQcTKl UAACAgAA2VGFuawpkb3dubG9hZGVkIGZyb20gaHR0cDovL3d3dy5nd2NvbS5kZQZOQZDAswzQqDuNmOT