# HG changeset patch # User Matti Hamalainen # Date 1710251278 -7200 # Node ID 78ad0e51b7b5b25e58a35a60ce0e3324eaea06a8 # Parent 4caa26c12052211f47393dc92a0b8c7d9aade628 Improve wizards.txt parser, add functionality for specifying alternative / additional names as some wizards have used more than one. Also other improvements in wizard data handling. diff -r 4caa26c12052 -r 78ad0e51b7b5 src/reformat_wizards.php --- a/src/reformat_wizards.php Mon Mar 11 15:11:16 2024 +0200 +++ b/src/reformat_wizards.php Tue Mar 12 15:47:58 2024 +0200 @@ -38,7 +38,7 @@ // Output each entry in this category foreach ($cat as $name => $data) { - $str = $name.";". + $str = implode("|", $data["names"]).";". (isset($data["countries"]) ? implode("|", $data["countries"]) : "").";". (isset($data["homeURL"]) ? $data["homeURL"] : "").";". (isset($data["imageURL"]) ? $data["imageURL"] : "").";"; diff -r 4caa26c12052 -r 78ad0e51b7b5 www/common.inc.php --- a/www/common.inc.php Mon Mar 11 15:11:16 2024 +0200 +++ b/www/common.inc.php Tue Mar 12 15:47:58 2024 +0200 @@ -460,25 +460,43 @@ } -function mpStoreWizInfoField(&$table, $field, $data) +function mpStoreWizInfoField(&$wizInfo, $field, $data) { $str = trim($data); if (strlen($str) > 0) - $table[$field] = $str; + $wizInfo[$field] = $str; } -function mpStoreWizInfoRecordInfo(&$table, $record) +function mpStoreWizInfoRecordInfo($nline, &$wizInfo, $record) { - $name = trim($record[1]); - if (isset($table[$name])) + // Parse and check names + $allnames = preg_split("/\s*\|\s*/", trim($record[1])); + foreach ($allnames as $name) { - mpError("Item ".$name." is already set!"); + if ($name == "" || + $name != strtoupper(substr($name, 0, 1)).strtolower(substr($name, 1))) + { + mpError("Invalid name in wizard record (line #".$nline."): '".$name."'."); + } + } + + // Use first name as primary "key" + $keyname = $allnames[0]; + if (isset($wizInfo[$keyname])) + { + mpError("Wizard record '".$keyname."' is already set on line #". + $wizInfo[$keyname]["nline"].", vs line #".$nline); return FALSE; } else { - $tmp = ["name" => $name, "areas" => 0]; + $data = [ + "name" => $keyname, + "names" => array_slice($allnames, 1), + "areas" => 0, + "nline" => $nline, + ]; $countries = array_map( function ($item) @@ -492,21 +510,22 @@ })); if (count($countries) > 0) - $tmp["countries"] = $countries; + $data["countries"] = $countries; - mpStoreWizInfoField($tmp, "homeURL", $record[3]); - mpStoreWizInfoField($tmp, "imageURL", $record[4]); - mpStoreWizInfoField($tmp, "desc", $record[5]); + mpStoreWizInfoField($data, "homeURL", $record[3]); + mpStoreWizInfoField($data, "imageURL", $record[4]); + mpStoreWizInfoField($data, "desc", $record[5]); - $table[$name] = $tmp; + $wizInfo[$keyname] = $data; return TRUE; } } -function mpParseWizInfoFile($filename, &$table) +function mpParseWizInfoFile($filename, &$wizInfo) { + $startLine = $nline = 0; if (($file = @fopen($filename, "r")) === false) return FALSE; @@ -514,6 +533,7 @@ while (!feof($file)) { $line = mpChConv(trim(fgets($file))); + $nline++; if (strlen($line) == 0 || $line[0] == "#") continue; @@ -524,7 +544,7 @@ { $record[5] .= " ".trim(substr($line, 0, -1)); $contMode = FALSE; - mpStoreWizInfoRecordInfo($table, $record); + mpStoreWizInfoRecordInfo($startLine, $wizInfo, $record); } else { @@ -532,13 +552,16 @@ } } else - if (preg_match("/^([A-Z][a-z]+);([a-z\|]+)?;(https?:\/\/[^;]+|bat)?;([^;]+)?;([^\$]*)\\\$$/", $line, $record)) - mpStoreWizInfoRecordInfo($table, $record); + if (preg_match("/^([A-Za-z\|]+);([a-z\|]+)?;(https?:\/\/[^;]+|bat)?;([^;]+)?;([^\$]*)\\\$$/", $line, $record)) + mpStoreWizInfoRecordInfo($nline, $wizInfo, $record); else - if (preg_match("/^([A-Z][a-z]+);([a-z\|]+)?;(https?:\/\/[^;]+|bat)?;([^;]+)?;(.*)$/", $line, $record)) + if (preg_match("/^([A-Za-z\|]+);([a-z\|]+)?;(https?:\/\/[^;]+|bat)?;([^;]+)?;(.*)$/", $line, $record)) + { + $startLine = $nline; $contMode = TRUE; + } else - mpError($line); + mpError("Wizard record line #".$nline.": ".$line); } fclose($file); @@ -546,6 +569,18 @@ } +function mpMakeWizInfoAliases($wizInfo) +{ + $aliases = []; + foreach ($wizInfo as $name => $data) + { + foreach ($data["names"] as $nname) + $aliases[$nname] = $name; + } + return $aliases; +} + + function mpReadWizInfoFiles() { $wizInfo = []; diff -r 4caa26c12052 -r 78ad0e51b7b5 www/info.php --- a/www/info.php Mon Mar 11 15:11:16 2024 +0200 +++ b/www/info.php Tue Mar 12 15:47:58 2024 +0200 @@ -53,71 +53,65 @@ } -/* Print table of wizards - */ +// Get area counts foreach ($locTable as $location) { foreach ($location["authors"] as $wiz) { $name = $wiz["name"]; + + // Many wizards do not have an entry in wizard info table if (!isset($wizTable[$name])) - $wizTable[$name] = array("name" => $name, "areas" => 0); + { + $wizTable[$name] = [ + "name" => $name, + "names" => [], + "areas" => 0, + ]; + } + $wizTable[$name]["areas"]++; } } -if (count($wizTable) > 0) -{ - /* Make alphabetically sorted table of wizards - */ - foreach ($wizTable as $alpha => $data) - $alphaTable[$alpha[0]][] = $data; +// Make alphabetically sorted table of wizards +foreach ($wizTable as $name => $data) + $alphaTable[$name[0]][$name] = $data; - ksort($alphaTable, SORT_STRING); +ksort($alphaTable, SORT_STRING); - - /* Print wizards alphabetically per first character of name - */ - $totalWiz = 0; - $maxRow = 6; - foreach ($alphaTable as $alpha => $data) - if (count($data) > 0) - { - usort($data, "wizardSort"); +// Print wizards alphabetically per first character of name +foreach ($alphaTable as $alpha => $data) +if (count($data) > 0) +{ + usort($data, "wizardSort"); - $letter = strtoupper($alpha); - echo "

".$letter."

\n"; - echo "
\n"; - $n = 0; - - foreach ($data as $wizard) - { - $totalWiz++; + $letter = strtoupper($alpha); + echo "

".$letter."

\n"; + echo "
\n"; - echo - "
2 || isset($wizard["desc"])) ? "locWizHasDesc" : "locWizHasNoDesc")."\">". - "".$wizard["name"].""; + foreach ($data as $name => $wizard) + { + echo + "
". + "".$wizard["name"].""; - if ($wizard["areas"] > 0) - echo " (".$wizard["areas"].")"; - - echo "
\n"; - } + if ($wizard["areas"] > 0) + echo " (".$wizard["areas"].")"; echo "
\n"; } - echo "

".$totalWiz." wizards.

\n". - "
\n"; // end of contents div - - // Print out the alpha link index - mpPrintExtraBoxAlphaList("ch", $alphaTable); + echo "
\n"; } -else -{ - echo "

No wizards known!

\n". - "\n"; // end of contents div -} + +echo + "

".count($wizTable)." wizards.

\n". + "\n"; // end of contents div + +// Print out the alpha link index +mpPrintExtraBoxAlphaList("ch", $alphaTable); mpPrintPageFooter(FALSE); ?> \ No newline at end of file diff -r 4caa26c12052 -r 78ad0e51b7b5 www/loc.php --- a/www/loc.php Mon Mar 11 15:11:16 2024 +0200 +++ b/www/loc.php Tue Mar 12 15:47:58 2024 +0200 @@ -111,6 +111,10 @@ $wizTable = mpReadWizInfoFiles(); apcu_store("wizTable", $wizTable, 3600); } + + // Correct aliases + if (isset($wizTable[$authorName])) + $authorName = $wizTable[$authorName]["name"]; } else { @@ -231,20 +235,30 @@ // if (isset($authorName)) { - if (isset($wizTable[$authorName]) && count($wizTable[$authorName]) > 1) + if (isset($wizTable[$authorName])) { + $entry = &$wizTable[$authorName]; + // Profile picture - //$imageURL = $wizImageURL.(qcheck($wizTable[$authorName], "imageURL", $imageName) ? $imageName : "unknown.png"); + //$imageURL = $wizImageURL.(qcheck($entry, "imageURL", $imageName) ? $imageName : "unknown.png"); $imageURL = $wizImageURL."unknown.png"; echo "
\n". - "
\"".$authorName."\"
\n". + "
\"".$entry["name"]."\"
\n". "
\n". - "

".$authorName."

\n"; + "

".$entry["name"]; + + if (count($entry["names"]) > 0) + { + echo " (aka ".implode(" aka ", $entry["names"]).")"; + } + + echo + "

\n"; // Description block - if (qcheck($wizTable[$authorName], "desc", $str)) + if (qcheck($entry, "desc", $str)) { // Handle special tags $str = preg_replace("/\~([A-Z][a-z]+)\~/i", "\${1}", $str); @@ -258,7 +272,7 @@ // Links, etc. echo " [Finger]\n"; - if (qcheck($wizTable[$authorName], "homeURL", $s)) + if (qcheck($entry, "homeURL", $s)) { if ($s == "bat") $s = "https://wiz.bat.org/~".strtolower($authorName)."/"; @@ -266,7 +280,7 @@ echo " [Homepage]\n"; } - if (qcheck($wizTable[$authorName], "countries", $s)) + if (qcheck($entry, "countries", $s)) { echo " [".implode(" | ", array_map( function ($item)