bjori Thu Aug 30 13:54:16 2007 UTC
Modified files: /phd build.php /phd/formats xhtml.php /phd/themes/php phpdotnet.php Log: Add acronym lookup support http://cvs.php.net/viewvc.cgi/phd/build.php?r1=1.24&r2=1.25&diff_format=u Index: phd/build.php diff -u phd/build.php:1.24 phd/build.php:1.25 --- phd/build.php:1.24 Sun Aug 19 13:19:47 2007 +++ phd/build.php Thu Aug 30 13:54:15 2007 @@ -1,5 +1,5 @@ <?php -/* $Id: build.php,v 1.24 2007/08/19 13:19:47 bjori Exp $ */ +/* $Id: build.php,v 1.25 2007/08/30 13:54:15 bjori Exp $ */ function err($no, $str, $file, $line) { global $notify; @@ -79,7 +79,12 @@ require "./themes/$theme/$themename.php"; switch($theme) { case "php": - $themes[$themename] = new $themename($IDs, $OPTIONS["xml_root"]."/phpbook/phpbook-xsl/version.xml"); + $themes[$themename] = new $themename($IDs, + array( + "version" => $OPTIONS["xml_root"]."/phpbook/phpbook-xsl/version.xml", + "acronym" => $OPTIONS["xml_root"]."/entities/acronyms.xml", + ) + ); break; default: $themes[$themename] = new $themename($IDs); http://cvs.php.net/viewvc.cgi/phd/formats/xhtml.php?r1=1.19&r2=1.20&diff_format=u Index: phd/formats/xhtml.php diff -u phd/formats/xhtml.php:1.19 phd/formats/xhtml.php:1.20 --- phd/formats/xhtml.php:1.19 Fri Aug 24 09:10:21 2007 +++ phd/formats/xhtml.php Thu Aug 30 13:54:15 2007 @@ -1,8 +1,9 @@ <?php -/* $Id: xhtml.php,v 1.19 2007/08/24 09:10:21 bjori Exp $ */ +/* $Id: xhtml.php,v 1.20 2007/08/30 13:54:15 bjori Exp $ */ class XHTMLPhDFormat extends PhDFormat { protected $elementmap = array( /* {{{ */ + 'acronym' => 'acronym', 'article' => 'format_container_chunk', 'author' => 'div', 'authorgroup' => 'div', /* DocBook-xsl prints out "by" (i.e. "PHP Manual by ...") */ http://cvs.php.net/viewvc.cgi/phd/themes/php/phpdotnet.php?r1=1.11&r2=1.12&diff_format=u Index: phd/themes/php/phpdotnet.php diff -u phd/themes/php/phpdotnet.php:1.11 phd/themes/php/phpdotnet.php:1.12 --- phd/themes/php/phpdotnet.php:1.11 Sat Aug 25 13:24:10 2007 +++ phd/themes/php/phpdotnet.php Thu Aug 30 13:54:16 2007 @@ -1,8 +1,9 @@ <?php -/* $Id: phpdotnet.php,v 1.11 2007/08/25 13:24:10 bjori Exp $ */ +/* $Id: phpdotnet.php,v 1.12 2007/08/30 13:54:16 bjori Exp $ */ class phpdotnet extends PhDHelper { protected $elementmap = array( + 'acronym' => 'format_suppressed_tags', 'function' => 'format_suppressed_tags', 'link' => 'format_link', 'refpurpose' => 'format_refpurpose', @@ -53,6 +54,7 @@ 'setindex' => 'format_chunk', ); protected $textmap = array( + 'acronym' => 'format_acronym_text', 'function' => 'format_function_text', 'type' => array( /* DEFAULT */ 'format_type_text', @@ -63,15 +65,19 @@ 'titleabbrev' => 'format_suppressed_tags', ); private $versions = array(); + private $acronyms = array(); protected $chunked = true; protected $CURRENT_ID = ""; protected $refname; - public function __construct(array $IDs, $filename, $ext = "php", $chunked = true) { + public function __construct(array $IDs, array $filenames, $ext = "php", $chunked = true) { parent::__construct($IDs, $ext); $this->ext = $ext; - $this->versions = self::generateVersionInfo($filename); + if (isset($filenames["version"], $filenames["acronym"])) { + $this->versions = self::generateVersionInfo($filenames["version"]); + $this->acronyms = self::generateAcronymInfo($filenames["acronym"]); + } $this->chunked = $chunked; } public static function generateVersionInfo($filename) { @@ -102,6 +108,32 @@ $info = $versions; return $versions; } + public static function generateAcronymInfo($filename) { + static $info; + if ($info) { + return $info; + } + $r = new XMLReader; + if (!$r->open($filename)) { + throw new Exception("Could not open $filename"); + } + $acronyms = array(); + 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; + } + } + $info = $acronyms; + return $acronyms; + } public function format_link($open, $name, $attrs, $props) { if ($open) { $content = $fragment = ""; @@ -142,6 +174,17 @@ strtolower($funcname)); return isset($this->versions[$funcname]) ? $this->versions[$funcname] : "No version information available, might be only in CVS"; } + public function acronymInfo($acronym) { + return isset($this->acronyms[$acronym]) ? $this->acronyms[$acronym] : false; + } + + public function format_acronym_text($value, $tag) { + $resolved = $this->acronymInfo($value); + if ($resolved) { + return '<acronym title="' .$resolved. '">' .$value. '</acronym>'; + } + return '<acronym>'.$value.'</acronym>'; + } public function format_refpurpose($open, $tag, $attrs) { if ($open) { return sprintf('<p class="verinfo">(%s)</p><p class="refpurpose">%s â ', $this->versionInfo($this->refname), $this->refname);