Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions phpdotnet/phd/Package/PHP/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,31 +336,30 @@ public static function generateAcronymInfo($filename) {
if ($info) {
return $info;
}

if (!is_file($filename)) {
trigger_error(vsprintf("Can't find acronym file (%s), skipping", [$filename]), E_USER_WARNING);
return array();
}

$r = new \XMLReader;
if (!$r->open($filename)) {
throw new \Error(vsprintf('Could not open file for accessing acronym information (%s)', [$filename]));
$useInternalErrors = libxml_use_internal_errors(true);
$entities = simplexml_load_file($filename);
libxml_clear_errors();
libxml_use_internal_errors($useInternalErrors);
if ($entities === false) {
trigger_error(vsprintf("Can't parse acronym file (%s), skipping", [$filename]), E_USER_WARNING);
return [];
}

$acronyms = array();
$k = "";
while ($r->read()) {
if ($r->nodeType != \XMLReader::ELEMENT) {
continue;
}
if ($r->name == "term") {
$r->read();
$k = $r->value;
$acronyms[$k] = "";
} else if ($r->name == "simpara") {
$r->read();
$acronyms[$k] = $r->value;
$acronyms = [];
foreach ($entities as $entity) {
$name = (string) $entity["name"];
if (str_starts_with($name, "acronym.expansion.")) {
$acronyms[substr($name, strlen("acronym.expansion."))] = trim(preg_replace('/\s+/', ' ', (string) $entity));
}
}

ksort($acronyms);
$info = $acronyms;
return $acronyms;
}
Expand Down
13 changes: 11 additions & 2 deletions render.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,21 @@

// This needs to be moved. Preferably into the PHP package.
if (!$conf) {
// Acronym expansions come from the translatable entity file in the
// language checkout (e.g. en/, it/), languages without a
// translated copy fall back to the English one.
$acronymFilename = dirname($config->xmlRoot) . DIRECTORY_SEPARATOR . $config->language
. DIRECTORY_SEPARATOR . 'entities' . DIRECTORY_SEPARATOR . 'entities.acronyms.ent';
if (!is_file($acronymFilename)) {
$acronymFilename = dirname($config->xmlRoot) . DIRECTORY_SEPARATOR . 'en'
. DIRECTORY_SEPARATOR . 'entities' . DIRECTORY_SEPARATOR . 'entities.acronyms.ent';
}
$config->init(array(
"langDir" => __INSTALLDIR__ . DIRECTORY_SEPARATOR . "phpdotnet" . DIRECTORY_SEPARATOR
. "phd" . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR
. "langs" . DIRECTORY_SEPARATOR,
"phpwebVersionFilename" => $config->xmlRoot . DIRECTORY_SEPARATOR . 'version.xml',
"phpwebAcronymFilename" => $config->xmlRoot . DIRECTORY_SEPARATOR . 'entities' . DIRECTORY_SEPARATOR . 'acronyms.xml',
"phpwebAcronymFilename" => $acronymFilename,
"phpwebSourcesFilename" => $config->xmlRoot . DIRECTORY_SEPARATOR . 'sources.xml',
"phpwebHistoryFilename" => $config->xmlRoot . DIRECTORY_SEPARATOR . 'fileModHistory.php',
));
Expand Down Expand Up @@ -108,7 +117,7 @@
$outputHandler->v("Indexing...", VERBOSE_INDEXING);
// Create indexer
$format = new Index($config->indexCache, $config, $outputHandler);

$render->attach($format);

$outputHandler->v("Running full build", VERBOSE_RENDER_STYLE);
Expand Down
23 changes: 23 additions & 0 deletions tests/package/php/acronym_info_001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
Acronym info 001 - Acronyms are read from acronym.expansion.* entity elements
--FILE--
<?php
namespace phpdotnet\phd;

require_once __DIR__ . "/../../setup.php";

$acronyms = Package_PHP_XHTML::generateAcronymInfo(__DIR__ . "/data/entities.acronyms.ent");

var_dump($acronyms);
?>
--EXPECT--
array(4) {
["API"]=>
string(33) "Application Programming Interface"
["CSPRNG"]=>
string(54) "Cryptographically Secure PseudoRandom Number Generator"
["PHP"]=>
string(27) "PHP: Hypertext Preprocessor"
["cURL"]=>
string(18) "Client URL Library"
}
Loading