Kategorien
Bearbeiten von „FreewarWiki:Bot/Skripts/maplist.php“
Zur Navigation springen
Zur Suche springen
Die Bearbeitung kann rückgängig gemacht werden. Bitte prüfe den Vergleich unten, um sicherzustellen, dass du dies tun möchtest, und veröffentliche dann unten deine Änderungen, um die Bearbeitung rückgängig zu machen.
Aktuelle Version | Dein Text | ||
Zeile 13: | Zeile 13: | ||
error_reporting(E_ALL ^ E_NOTICE); | error_reporting(E_ALL ^ E_NOTICE); | ||
define('TEMPLATE_GET_KEY', 1); | define('TEMPLATE_GET_KEY', 1); | ||
define('TEMPLATE_GET_VALUE', 2); | define('TEMPLATE_GET_VALUE', 2); | ||
define('WIKIURL', 'https://fwwiki.de'); | define('WIKIURL', 'https://fwwiki.de'); | ||
define("BERGFELD", 'http://welt1.freewar.de/freewar/images/map/std.jpg'); | define("BERGFELD", 'http://welt1.freewar.de/freewar/images/map/std.jpg'); | ||
function is_obsolete($wiki_text) | function is_obsolete($wiki_text) { | ||
{ | |||
// Veraltetes Feld=none liefert true! | // Veraltetes Feld=none liefert true! | ||
return (bool)preg_match('/Veraltetes Feld=[^}]+/', $wiki_text); | return (bool)preg_match('/Veraltetes Feld=[^}]+/', $wiki_text); | ||
Zeile 27: | Zeile 26: | ||
// Vorlage beginnt (kann danach aber noch Müll enthalten) | // Vorlage beginnt (kann danach aber noch Müll enthalten) | ||
function get_templates($template, $wiki_text) | function get_templates($template, $wiki_text) { | ||
{ | |||
$pattern = '/\{\{(Vorlage:)?' . preg_quote($template, '/') . '/'; | $pattern = '/\{\{(Vorlage:)?' . preg_quote($template, '/') . '/'; | ||
$templates = preg_split($pattern, $wiki_text); | $templates = preg_split($pattern, $wiki_text); | ||
Zeile 38: | Zeile 36: | ||
// aber Details zu NPCs usw. | // aber Details zu NPCs usw. | ||
function parse_field_article($area) | function parse_field_article($area) { | ||
{ | |||
$fields = array(); | $fields = array(); | ||
Zeile 66: | Zeile 63: | ||
} | } | ||
// Liest zu einem angegebenen Gebiet die unbetretbaren Felder aus dem | // Liest zu einem angegebenen Gebiet die unbetretbaren Felder aus dem | ||
// "Karte:XXX"-Artikel. | // "Karte:XXX"-Artikel. | ||
function parse_map_article($area) | function parse_map_article($area) { | ||
$fields = array(); | |||
// Artikel fetchen | // Artikel fetchen | ||
$field_url = WIKIURL . "/index.php/Karte:" . rawurlencode($area) . "?action=raw"; | $field_url = WIKIURL . "/index.php/Karte:" . rawurlencode($area) . "?action=raw"; | ||
echo "$field_url\n"; | echo "$field_url\n"; | ||
$raw = file_get_contents($field_url); | $raw = file_get_contents($field_url); | ||
return array_map(function ($template_text) use ($area) { | return array_map(function ($template_text) use($area) { | ||
if (!preg_match("/^\|(-?\d+)\|(-?\d+)(\|([^}\|]+))?/", $template_text, $values)) return []; | |||
return [ | |||
'area' => $area, | 'area' => $area, | ||
'accessible' => 0, | 'accessible' => 0, | ||
'pos_x' => $values[1], | 'pos_x' => $values[1], | ||
'pos_y' => $values[2], | 'pos_y' => $values[2], | ||
'npc' => NULL, | 'npc' => NULL, | ||
'url' => isset($values[4]) ? $values[4] : BERGFELD, | 'url' => isset($values[4]) ? $values[4] : BERGFELD, | ||
'passages' => NULL | 'passages' => NULL | ||
]; | ]; | ||
}, array_merge(get_templates("Karte/Unbetretbar", $raw), get_templates("Karte/Rahmenfeld", $raw))); | }, array_merge(get_templates("Karte/Unbetretbar", $raw), get_templates("Karte/Rahmenfeld", $raw))); | ||
Zeile 91: | Zeile 89: | ||
// Verarbeitet Feld-Templates | // Verarbeitet Feld-Templates | ||
function parse_field_template($wiki_text) | function parse_field_template($wiki_text) { | ||
{ | |||
// Standard-Werte | // Standard-Werte | ||
$field = array( | $field = array( | ||
'accessible' => 1, | 'accessible' => 1, | ||
'pos_x' => -10, | 'pos_x' => -10, | ||
'pos_y' => -9, | 'pos_y' => -9, | ||
'npc' => array(), | 'npc' => array(), | ||
'url' => '', | 'url' => '', | ||
'passages' => array() | 'passages' => array() | ||
); | ); | ||
Zeile 110: | Zeile 107: | ||
$field['pos_x'] = (int)$template['X']; | $field['pos_x'] = (int)$template['X']; | ||
$field['pos_y'] = (int)$template['Y']; | $field['pos_y'] = (int)$template['Y']; | ||
$field['url'] = $template['Bild']; | $field['url'] = $template['Bild']; | ||
// Passagen lesen | // Passagen lesen | ||
Zeile 131: | Zeile 128: | ||
// npcs lesen | // npcs lesen | ||
preg_match_all('/\[\[([^]]+)]]/', $template['NPC'], $npc_matches, PREG_PATTERN_ORDER); | preg_match_all('/\[\[([^]]+)\]\]/', $template['NPC'], $npc_matches, PREG_PATTERN_ORDER); | ||
$field['npc'] = $npc_matches[1]; | $field['npc'] = $npc_matches[1]; | ||
Zeile 137: | Zeile 134: | ||
} | } | ||
function parse_template($text) | function parse_template($text) { | ||
{ | |||
$template = array(); | $template = array(); | ||
Zeile 157: | Zeile 153: | ||
for ($i = 1, $length = strlen($text); $i < $length; ++$i) { | for ($i = 1, $length = strlen($text); $i < $length; ++$i) { | ||
if ($text[$i] === '{' && $text[$i + 1] === '{') { // weitere Vorlage | if ($text[$i] === '{' && $text[$i+1] === '{') { // weitere Vorlage | ||
++$depth; | ++$depth; | ||
++$i; | ++$i; | ||
$template[$key] .= '{'; | $template[$key] .= '{'; | ||
} else if ($text[$i] === '}' && $text[$i + 1] === '}') { // geschlossene Vorlage | } else if ($text[$i] === '}' && $text[$i+1] === '}') { // geschlossene Vorlage | ||
if ($depth === 0) { | if ($depth === 0) { | ||
Zeile 170: | Zeile 166: | ||
$template[$key] .= '}'; | $template[$key] .= '}'; | ||
} | } | ||
} else if ($text[$i] === '[' && $text[$i + 1] === '[') { // geöffneter Link | } else if ($text[$i] === '[' && $text[$i+1] === '[') { // geöffneter Link | ||
++$depth; | ++$depth; | ||
++$i; | ++$i; | ||
$template[$key] .= '['; | $template[$key] .= '['; | ||
} else if ($text[$i] === ']' && $text[$i + 1] === ']') { // geschlossener Link | } else if ($text[$i] === ']' && $text[$i+1] === ']') { // geschlossener Link | ||
if ($depth === 0) { | if ($depth === 0) { | ||
Zeile 199: | Zeile 195: | ||
} | } | ||
return array_map('trim', $template); | return array_map('trim',$template); | ||
} | } | ||
// Liste aller Gebiete aus "Katgorie:Felder" bestimmen | // Liste aller Gebiete aus "Katgorie:Felder" bestimmen | ||
preg_match_all("/>Felder:([^<]+)</", | preg_match_all("/>Felder:([^<]+)</", | ||
file_get_contents(WIKIURL . '/index.php/Kategorie:Felder'), $areas); | file_get_contents(WIKIURL.'/index.php/Kategorie:Felder'), $areas); | ||
// Für jedes Gebiet die Felder und die Randfelder ermitteln, | // Für jedes Gebiet die Felder und die Randfelder ermitteln, | ||
Zeile 227: | Zeile 223: | ||
is_null($field['npc']) ? "" : implode('/', $field['npc']), | is_null($field['npc']) ? "" : implode('/', $field['npc']), | ||
$field['url'], | $field['url'], | ||
is_null($field[' | is_null($field['passage']) ? "" : implode('/', $field['passage'])); | ||
} | } | ||
</pre> | </pre> |