Mercurial > hg > batmud > maputils
changeset 2741:91698e217f84
Import PHP utility for reformatting wizards.txt
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 08 Mar 2024 15:22:27 +0200 |
parents | 7b35e4eadbcc |
children | 822588370149 |
files | src/reformat_wizards.php |
diffstat | 1 files changed, 77 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/reformat_wizards.php Fri Mar 08 15:22:27 2024 +0200 @@ -0,0 +1,77 @@ +#!/usr/bin/php +<?php +require "common.inc.php"; + + +function mpWriteWizInfoFile($filename, &$table) +{ + $categories = []; + + foreach ($table as $name => $data) + { + $score = 0; + + if (isset($data["countries"])) $score++; + if (isset($data["desc"])) $score++; + if (isset($data["homeURL"])) $score++; + + $categories[$score][$name] = $data; + } + + krsort($categories, SORT_NUMERIC); + + if (($file = @fopen($filename, "w")) === false) + return FALSE; + + fwrite($file, + "# Information about coders/wizards. Format of this file:\n". + "# name;[3-letter country code];[http://homepageURL|bat];[https?://pictureURL|image.jpg];[freeform description]\$\n\n"); + + foreach ($categories as $id => $cat) + { + if ($id == 0) + ksort($cat, SORT_STRING); + + foreach ($cat as $name => $data) + { + if ($id > 0) + { + if (isset($data["desc"]) && strlen($data["desc"]) > 0) + $str = "\n\t".wordwrap($data["desc"], 68, "\n\t", false); + else + $str = ""; + + $str .= "\n\t\$\n\n"; + } + else + { + $str = "\$\n"; + } + + fwrite($file, + $name.";". + (isset($data["countries"]) ? implode("|", $data["countries"]) : "").";". + (isset($data["homeURL"]) ? $data["homeURL"] : "").";". + (isset($data["imageURL"]) ? $data["imageURL"] : "").";".$str); + } + fwrite($file, "\n#########################################################\n\n"); + } + + fclose($file); + return TRUE; +} + + +// Prevent non-cli execution +if (php_sapi_name() != "cli" || !empty($_SERVER["REMOTE_ADDR"])) + die("You can only run this script as a commandline application.\n"); + +if (count($argv) < 2) +{ + die("Usage: ".$argv[0]." <output wizards.txt>\n"); +} + +$table = mpReadWizInfoFiles(); +mpWriteWizInfoFile($argv[1], $table); + +?>