cvs: phd /themes/pear peartheme.php
| From: | Brett Bieber | Date: | Wed, 05 Nov 2008 19:11:17 +0000 |
| Subject: | cvs: phd /themes/pear peartheme.php | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-2416@lists.php.net to get a copy of this message | ||
saltybeagle Wed Nov 5 19:11:17 2008 UTC
Modified files:
/phd/themes/pear peartheme.php
Log:
CS fixes, add a few docblocks, change double quotes to single where no variable expansion was used
giving around 9% speedup for the pearweb build. :-D
http://cvs.php.net/viewvc.cgi/phd/themes/pear/peartheme.php?r1=1.18&r2=1.19&diff_format=u Index: phd/themes/pear/peartheme.php diff -u phd/themes/pear/peartheme.php:1.18 phd/themes/pear/peartheme.php:1.19 --- phd/themes/pear/peartheme.php:1.18 Mon Nov 3 20:34:45 2008 +++ phd/themes/pear/peartheme.php Wed Nov 5 19:11:16 2008 @@ -230,7 +230,7 @@ */ public $ext = null; - protected $lang = "en"; + protected $lang = 'en'; /** * If whitespace should be trimmed. @@ -242,24 +242,32 @@ */ public $trim = false; - protected $CURRENT_ID = ""; + protected $CURRENT_ID = ''; /* Current Chunk settings */ protected $cchunk = array(); /* Default Chunk settings */ protected $dchunk = array( - "fieldsynopsis" => array( - "modifier" => "public", + 'fieldsynopsis' => array( + 'modifier' => 'public', ), - "container_chunk" => null, - "qandaentry" => array( + 'container_chunk' => null, + 'qandaentry' => array( ), - "examples" => 0, - "verinfo" => false, - "refname" => array(), + 'examples' => 0, + 'verinfo' => false, + 'refname' => array(), ); - public function __construct(array $IDs, $ext = "php", $chunked = true) { + /** + * Constructor + * + * @param array $IDs Array of elements + * @param string $ext Filename extension to use + * @param bool $chunked whether or not to chunk the output + */ + public function __construct(array $IDs, $ext = 'php', $chunked = true) + { parent::__construct($IDs, $ext); $this->ext = $ext; $this->chunked = $chunked; @@ -277,34 +285,36 @@ return preg_replace('#<p>\\s*</p>#s', '', $str); } - public function format_chunk($open, $name, $attrs, $props) { + public function format_chunk($open, $name, $attrs, $props) + { $id = null; - if (isset($attrs[PhDReader::XMLNS_XML]["id"])) { - $this->CURRENT_ID = $id = $attrs[PhDReader::XMLNS_XML]["id"]; + if (isset($attrs[PhDReader::XMLNS_XML]['id'])) { + $this->CURRENT_ID = $id = $attrs[PhDReader::XMLNS_XML]['id']; } - if ($props["isChunk"]) { + if ($props['isChunk']) { $this->cchunk = $this->dchunk; } - if (isset($props["lang"])) { - $this->lang = $props["lang"]; + if (isset($props['lang'])) { + $this->lang = $props['lang']; } - if ($name == "refentry") { - if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"])) { - $this->cchunk["verinfo"] = !($attrs[PhDReader::XMLNS_DOCBOOK]["role"] == "noversion"); + if ($name == 'refentry') { + if (isset($attrs[PhDReader::XMLNS_DOCBOOK]['role'])) { + $this->cchunk['verinfo'] = !($attrs[PhDReader::XMLNS_DOCBOOK]['role'] == 'noversion'); } else { - $this->cchunk["verinfo"] = true; + $this->cchunk['verinfo'] = true; } } - if ($name == "legalnotice") { + if ($name == 'legalnotice') { if ($open) { - return '<div class="' . $name . '" ' . ($id ? "id=\"{$id}\"" : "") . '">'; + return '<div class="' . $name . '" ' . ($id ? "id=\"{$id}\"" : '') . '">'; } return "</div>\n"; } return false; } - public function format_container_chunk($open, $name, $attrs, $props) { + public function format_container_chunk($open, $name, $attrs, $props) + { if (!isset($attrs[PhDReader::XMLNS_XML]['id'])) { if ($open) { return "<div class=\"{$name}\">"; @@ -312,13 +322,13 @@ return "</div>\n"; } } - $this->CURRENT_ID = $id = $attrs[PhDReader::XMLNS_XML]["id"]; + $this->CURRENT_ID = $id = $attrs[PhDReader::XMLNS_XML]['id']; if (!$open) { return "</div>\n"; } - if ($props["isChunk"]) { + if ($props['isChunk']) { $this->cchunk = $this->dchunk; } @@ -330,7 +340,7 @@ if ($toc) { $toc = "<div class=\"TOC\">\n" . $toc . "</div>\n"; } - $this->cchunk["container_chunk"] = $toc; + $this->cchunk['container_chunk'] = $toc; return "<div class=\"{$name}\" id=\"{$id}\">"; } @@ -340,12 +350,24 @@ return $this->format->format_div($open, $name, $attrs, $props); } - public function format_exception_chunk($open, $name, $attrs, $props) { - return $this->format_container_chunk($open, "reference", $attrs, $props); + public function format_exception_chunk($open, $name, $attrs, $props) + { + return $this->format_container_chunk($open, 'reference', $attrs, $props); } - public function format_root_chunk($open, $name, $attrs, $props) { - $this->CURRENT_ID = $id = $attrs[PhDReader::XMLNS_XML]["id"]; + /** + * Formatting for the root element of a chunk. + * + * @param bool $open Whether we should open or close this element. + * @param string $name Name of the element + * @param array $attrs Attributes present for the element. Array keys are the attribute namespaces. + * @param array $props Associative array of additional properties + * + * @return string + */ + public function format_root_chunk($open, $name, $attrs, $props) + { + $this->CURRENT_ID = $id = $attrs[PhDReader::XMLNS_XML]['id']; if ($open) { return "<div class=\"{$name}\">"; } @@ -361,30 +383,41 @@ return $content; } - public function format_link($open, $name, $attrs, $props) { + /** + * Format a link for an element + * + * @param bool $open If the link should be opened. + * @param string $name Name of the element. + * @param array $attrs Attributes present for the element. Array keys are the attribute namespaces. + * @param array $props Properties + * + * @return string + */ + public function format_link($open, $name, $attrs, $props) + { if ($open) { - $content = $fragment = ""; + $content = $fragment = ''; $class = $name; - if(isset($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"])) { - $linkto = $attrs[PhDReader::XMLNS_DOCBOOK]["linkend"]; + if (isset($attrs[PhDReader::XMLNS_DOCBOOK]['linkend'])) { + $linkto = $attrs[PhDReader::XMLNS_DOCBOOK]['linkend']; $id = $href = PhDHelper::getFilename($linkto); if ($id != $linkto) { $fragment = "#$linkto"; } if ($this->chunked) { - $href .= ".".$this->ext; + $href .= '.'.$this->ext; } - } elseif(isset($attrs[PhDReader::XMLNS_XLINK]["href"])) { - $href = $attrs[PhDReader::XMLNS_XLINK]["href"]; - $class .= " external"; + } elseif (isset($attrs[PhDReader::XMLNS_XLINK]['href'])) { + $href = $attrs[PhDReader::XMLNS_XLINK]['href']; + $class .= ' external'; } - if ($name == "xref") { + if ($name == 'xref') { if ($this->chunked) { $link = $href; } else { - $link = "#"; + $link = '#'; if (isset($linkto)) { $link .= $linkto; } else { @@ -392,17 +425,17 @@ } } return '<a href="' . htmlspecialchars($link). '" class="' .$class. '">' .($content.PhDHelper::getDescription($id, false)). '</a>'; - } elseif ($props["empty"]) { + } elseif ($props['empty']) { if ($this->chunked) { - $link = ""; + $link = ''; } else { - $link = "#"; + $link = '#'; } return '<a href="' .$link.$href.$fragment. '" class="' .$class. '">' .$content.$href.$fragment. '</a>'; } else { if ($this->chunked) { $link = $href.$fragment; - } elseif(isset($linkto)) { + } elseif (isset($linkto)) { if ($fragment) { $link = $fragment; } else { @@ -414,34 +447,37 @@ return '<a href="' .htmlspecialchars($link). '" class="' .$class. '">' .$content; } } - return "</a>"; + return '</a>'; } - public function format_container_chunk_title($open, $name, $attrs) { + public function format_container_chunk_title($open, $name, $attrs) + { if ($open) { - return "<h1>"; + return '<h1>'; } - $ret = ""; - if ($this->cchunk["container_chunk"]) { - $ret = $this->cchunk["container_chunk"]; - $this->cchunk["container_chunk"] = null; + $ret = ''; + if ($this->cchunk['container_chunk']) { + $ret = $this->cchunk['container_chunk']; + $this->cchunk['container_chunk'] = null; } return "</h1>\n" .$ret; } - public function transformFromMap($open, $tag, $name, $attrs, $props) { + public function transformFromMap($open, $tag, $name, $attrs, $props) + { if ($open) { - $idstr = ""; - if (isset($attrs[PhDReader::XMLNS_XML]["id"])) { - $id = $attrs[PhDReader::XMLNS_XML]["id"]; + $idstr = ''; + if (isset($attrs[PhDReader::XMLNS_XML]['id'])) { + $id = $attrs[PhDReader::XMLNS_XML]['id']; $idstr = ' id="' .$id. '" name="' .$id. '"'; } - return '<' .$tag. ' class="' .$name. '"' . $idstr. '>' . ($props["empty"] ? "</{$tag}>" : ""); + return '<' .$tag. ' class="' .$name. '"' . $idstr. '>' . ($props['empty'] ? "</{$tag}>" : ''); } return '</' .$tag. '>'; } - public function format_para_informaltable($open, $name, $attrs, $props) { + public function format_para_informaltable($open, $name, $attrs, $props) + { if ($open) { return $this->format->escapePara() . $this->format_table($open, $name, $attrs, $props); @@ -449,13 +485,14 @@ return $this->format_table($open, $name, $attrs, $props) . $this->format->restorePara(); } - public function format_programlisting($open, $name, $attrs) { + public function format_programlisting($open, $name, $attrs) + { if ($open) { $this->trim = true; - if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"])) { - $this->role = $attrs[PhDReader::XMLNS_DOCBOOK]["role"]; + if (isset($attrs[PhDReader::XMLNS_DOCBOOK]['role'])) { + $this->role = $attrs[PhDReader::XMLNS_DOCBOOK]['role']; } else { - $this->role = "default"; + $this->role = 'default'; } return $this->format->escapePara() @@ -466,19 +503,29 @@ return "</pre>\n" . $this->format->restorePara(); } - public function format_programlisting_text($value, $tag) { + /** + * Format the text within a program listing section. + * + * @param string $value Value of the text to format. + * @param unknown_type $tag + * + * @return string + */ + public function format_programlisting_text($value, $tag) + { switch($this->role) { - case "php": - if ( strrpos($value, "<?php") || strrpos($value, "?>") ) + case 'php': + if ( strrpos($value, '<?php') || strrpos($value, '?>') ) return highlight_string(trim($value), 1); else return highlight_string("<?php\n" . trim($value) . "\n?>", 1); break; default: - return htmlspecialchars($value, ENT_QUOTES, "UTF-8"); + return htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); } } - public function format_screen($open, $name, $attrs) { + public function format_screen($open, $name, $attrs) + { if ($open) { return $this->format->escapePara() . '<pre class="screen" style="background-color:#EEE; width: 100%">'; @@ -514,55 +561,62 @@ } if (!$this->role) { return str_replace( - array("\n", " "), array("<br/>", " "), - htmlspecialchars($str, ENT_QUOTES, "UTF-8") + array("\n", ' '), array('<br />', ' '), + htmlspecialchars($str, ENT_QUOTES, 'UTF-8') ); } switch ($this->role) { - case 'php': - if (strrpos($str, '<?php') || strrpos($str, '?>')) { - $str = highlight_string(trim($str), 1); - } else { - $str = highlight_string("<?php\n" . trim($str) . "\n?>", 1); - } - break; - default: - $str = htmlspecialchars($str, ENT_QUOTES, "UTF-8"); - break; + case 'php': + if (strrpos($str, '<?php') || strrpos($str, '?>')) { + $str = highlight_string(trim($str), 1); + } else { + $str = highlight_string("<?php\n" . trim($str) . "\n?>", 1); + } + break; + default: + $str = htmlspecialchars($str, ENT_QUOTES, 'UTF-8'); + break; } return $str; } - public function format_suppressed_tags($open, $name, $attrs) { + public function format_suppressed_tags($open, $name, $attrs) + { /* Ignore it */ - return ""; + return ''; } - public function format_suppressed_text($value, $tag) { + public function format_suppressed_text($value, $tag) + { /* Suppress any content */ - return ""; + return ''; } - public function format_surname($open, $name, $attrs) { + public function format_surname($open, $name, $attrs) + { /* Add a space before it, so firstname and surname are separated */ return ' '; } - public function format_subtitle($open, $name, $attrs) { + public function format_subtitle($open, $name, $attrs) + { if ($open) return '<p><font color="red">'; return '</font></p>'; } - public function format_editedby($open, $name, $attrs, $props) { - if ($open) - return "<h2 class=\"EDITEDBY\">" . $this->autogen("editedby", $props["lang"]) . "</h2>"; + public function format_editedby($open, $name, $attrs, $props) + { + if ($open) { + return '<h2 class="EDITEDBY">' . $this->autogen('editedby', $props['lang']) . '</h2>'; + } } - public function format_copyright($open, $name, $attrs) { + public function format_copyright($open, $name, $attrs) + { if ($open) { if ($this->chunked) { return '<p class="'.$name.'"><a href="copyright.' . $this->ext . '">Copyright</a> © '; @@ -573,48 +627,55 @@ return '</p>'; } - public function format_comment($open, $name, $attrs) { + public function format_comment($open, $name, $attrs) + { if ($open) { return '<!-- '; } return '-->'; } - public function format_holder($open, $name, $attrs, $props) { + public function format_holder($open, $name, $attrs, $props) + { if ($open) - return $this->autogen("by", $props["lang"]) . " "; + return $this->autogen('by', $props['lang']) . " "; } - public function format_year($value) { - return $value . ", "; + public function format_year($value) + { + return $value . ', '; } - public function format_admonition($open, $name, $attrs, $props) { + public function format_admonition($open, $name, $attrs, $props) + { if ($open) { return $this->format->escapePara() - . '<blockquote class="' . $name . '"><b>'.$this->autogen($name, $props["lang"]). ': </b>'; + . '<blockquote class="' . $name . '"><b>'.$this->autogen($name, $props['lang']). ': </b>'; } return "</blockquote>\n" . $this->format->restorePara(); } - public function format_table($open, $name, $attrs, $props) { + public function format_table($open, $name, $attrs, $props) + { if ($open) { return $this->format->escapePara() . '<table border="1" class="'.$name.'">'; } return "</table>\n" . $this->format->restorePara(); } - public function format_entry($open, $name, $attrs, $props) { + public function format_entry($open, $name, $attrs, $props) + { if ($open) { if ($props['empty']) { return '<td></td>'; } return '<td>'; } - return "</td>"; + return '</td>'; } - public function format_th_entry($open, $name, $attrs) { + public function format_th_entry($open, $name, $attrs) + { if ($open) { $colspan = PhDFormat::colspan($attrs[PhDReader::XMLNS_DOCBOOK]); return '<th colspan="' .((int)$colspan). '">'; @@ -622,30 +683,34 @@ return '</th>'; } - public function format_table_title($open, $name, $attrs, $props) { - if ($props["empty"]) - return ""; + public function format_table_title($open, $name, $attrs, $props) + { + if ($props['empty']) + return ''; if ($open) { return '<caption><b>'; } return '</b></caption>'; } - public function format_userinput($open, $name, $attrs, $props) { + public function format_userinput($open, $name, $attrs, $props) + { if ($open) { return '<tt class="'.$name.'"><b>'; } - return "</b></tt>"; + return '</b></tt>'; } - function format_replaceable($open, $name, $attrs, $props) { + public function format_replaceable($open, $name, $attrs, $props) + { if ($open) { return '<tt class="'.$name.'"><i>'; } - return "</i></tt>"; + return '</i></tt>'; } - public function format_warning($open, $name, $attrs, $props) { + public function format_warning($open, $name, $attrs, $props) + { if ($open) { return $this->format->escapePara() . '<div class="warning" style="border: 3px double black; padding: 5px">' . "\n"; @@ -653,17 +718,19 @@ return "</div>\n" . $this->format->restorePara(); } - public function format_warning_title($open, $name, $attrs, $props) { + public function format_warning_title($open, $name, $attrs, $props) + { if ($open) { return '<strong class="warning_title" style="display:block; text-align: center; width:100%">'; } return "</strong>\n"; } - public function format_warning_para($open, $name, $attrs, $props) { + public function format_warning_para($open, $name, $attrs, $props) + { if ($open) { if (!$props['sibling']) { - return '<strong>' . $this->autogen("warning", $props["lang"]) . "</strong>\n" + return '<strong>' . $this->autogen('warning', $props['lang']) . "</strong>\n" . '<p>'; } return '<p>'; @@ -671,68 +738,82 @@ return "</p>\n"; } - public function format_refname_function_text($value) { - $this->cchunk["refname"][] = '<b class="function">' . $this->format->TEXT($value . '()') . '</b>'; + public function format_refname_function_text($value) + { + $this->cchunk['refname'][] = '<b class="function">' . $this->format->TEXT($value . '()') . '</b>'; return false; } - public function format_refname_classname_text($value) { - $this->cchunk["refname"][] = '<b class="classname">' . $this->format->TEXT($value) . '</b>'; + public function format_refname_classname_text($value) + { + $this->cchunk['refname'][] = '<b class="classname">' . $this->format->TEXT($value) . '</b>'; return false; } - public function format_refpurpose($open, $tag, $attrs) { + public function format_refpurpose($open, $tag, $attrs) + { if ($open) { - $refnames = implode(' ', $this->cchunk["refname"]); + $refnames = implode(' ', $this->cchunk['refname']); return '<div class="refnamediv">'. $refnames. ' -- '; } return "</div>\n"; } - public function format_refname_text($value, $tag) { - $this->cchunk["refname"][] = $this->format->TEXT($value); + + public function format_refname_text($value, $tag) + { + $this->cchunk['refname'][] = $this->format->TEXT($value); return false; } - public function format_function_text($value) { + public function format_function_text($value) + { return $this->format->TEXT($value."()"); } - public function format_paramdef($open, $name, $attrs, $props) { - if ($open && $props["sibling"] == 'paramdef') + public function format_paramdef($open, $name, $attrs, $props) + { + if ($open && $props['sibling'] == 'paramdef') { return ' , '; + } return false; } - public function format_funcdef($open, $name, $attrs, $props) { - if (!$open) + public function format_funcdef($open, $name, $attrs, $props) + { + if (!$open) { return ' ( '; + } return false; } - public function format_funcprototype($open, $name, $attrs, $props) { + public function format_funcprototype($open, $name, $attrs, $props) + { if ($open) { return '<p><code class="' . $name . '">'; } - else return ")</code></p>"; + return ')</code></p>'; } - public function format_uri($open, $name, $attrs, $props) { + public function format_uri($open, $name, $attrs, $props) + { if ($open) { return '<font color="red">'; } - else return "</font>"; + return '</font>'; } - public function format_refsynopsisdiv($open, $name, $attrs, $props) { + public function format_refsynopsisdiv($open, $name, $attrs, $props) + { if ($open) { return '<h2 class="refsynopsisdiv">Synopsis</h2>'; } return ''; } - public function format_guimenu($open, $name, $attrs, $props) { + public function format_guimenu($open, $name, $attrs, $props) + { if ($open) { - if ($props["sibling"]) + if ($props['sibling']) return '-><span class="guimenu"><i>'; return '<span class="guimenu"><i>'; } @@ -744,14 +825,21 @@ return $this->format->format_dl($open, $name, $attrs, $props); } - /* FIXME: This function is a crazy performance killer */ - public function qandaset($stream) { + /** + * FIXME: This function is a crazy performance killer + * + * @param resource $stream Stream containing the contents of a Q&A section + * + * @return string + */ + public function qandaset($stream) + { $xml = stream_get_contents($stream); $old = libxml_use_internal_errors(true); - $doc = new DOMDocument("1.0", "UTF-8"); + $doc = new DOMDocument('1.0', 'UTF-8'); $doc->preserveWhitespace = false; - $doc->loadXML(html_entity_decode(str_replace("&", "&amp;", "<div>$xml</div>"), ENT_QUOTES, "UTF-8")); + $doc->loadXML(html_entity_decode(str_replace('&', '&amp;', "<div>$xml</div>"), ENT_QUOTES, 'UTF-8')); if ($err = libxml_get_errors()) { print_r($err); libxml_clear_errors(); @@ -763,34 +851,41 @@ $nlist = $xpath->query("//div/dl/dt/strong"); $ret = '<div class="qandaset"><ol class="qandaset_questions">'; $i = 0; - foreach($nlist as $node) { - $ret .= '<li><a href="#' .($this->cchunk["qandaentry"][$i++]). '">' .($node->textContent). '</a></li>'; + foreach ($nlist as $node) { + $ret .= '<li><a href="#' .($this->cchunk['qandaentry'][$i++]). '">' .($node->textContent). '</a></li>'; } return $ret.'</ol>'.$xml.'</div>'; } - public function format_qandaentry($open, $name, $attrs) { + + public function format_qandaentry($open, $name, $attrs) + { if ($open) { - $this->cchunk["qandaentry"][] = $this->CURRENT_ID . ".entry" . count($this->cchunk["qandaentry"]); + $this->cchunk['qandaentry'][] = $this->CURRENT_ID . ".entry" . count($this->cchunk['qandaentry']); return '<dl>'; } return '</dl>'; } - public function format_answer($open, $name, $attrs) { + + public function format_answer($open, $name, $attrs) + { if ($open) { - return '<dd><a name="' .end($this->cchunk["qandaentry"]).'"></a>'; + return '<dd><a name="' .end($this->cchunk['qandaentry']).'"></a>'; } - return "</dd>"; + return '</dd>'; } - public function format_question($open, $name, $attrs) { + + public function format_question($open, $name, $attrs) + { if ($open) { return '<dt><strong>'; } return '</strong></dt>'; } - public function format_emphasis($open, $name, $attrs) { - if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"]) && $attrs[PhDReader::XMLNS_DOCBOOK]["role"] == "bold") + public function format_emphasis($open, $name, $attrs) + { + if (isset($attrs[PhDReader::XMLNS_DOCBOOK]['role']) && $attrs[PhDReader::XMLNS_DOCBOOK]['role'] == "bold") $role = "b"; else $role = "i"; if ($open) { @@ -799,30 +894,35 @@ return "</{$role}>"; } - public function format_glossterm($open, $name, $attrs) { + public function format_glossterm($open, $name, $attrs) + { if ($open) { return '<dt><b>'; } - return "</b></dt>"; + return '</b></dt>'; } - public function format_glossdef($open, $name, $attrs) { + public function format_glossdef($open, $name, $attrs) + { if ($open) { return '<dd><p>'; } - return "</p></dd>"; + return '</p></dd>'; } - public function format_calloutlist($open, $name, $attrs) { + public function format_calloutlist($open, $name, $attrs) + { if ($open) { - $this->cchunk["callouts"] = 0; + $this->cchunk['callouts'] = 0; return $this->format->escapePara() . '<table>'; } return '</table>' . $this->format->restorePara(); } - public function format_callout($open, $name, $attrs) { + + public function format_callout($open, $name, $attrs) + { if ($open) { - return '<tr><td><a href="#'.$attrs[PhDReader::XMLNS_DOCBOOK]["arearefs"].'">(' .++$this->cchunk["callouts"]. ')</a></td><td>'; + return '<tr><td><a href="#'.$attrs[PhDReader::XMLNS_DOCBOOK]['arearefs'].'">(' .++$this->cchunk['callouts']. ')</a></td><td>'; } return "</td></tr>\n"; }
http://cvs.php.net/viewvc.cgi/phd/themes/pear/peartheme.php?r1=1.18&r2=1.19&diff_format=u Index: phd/themes/pear/peartheme.php diff -u phd/themes/pear/peartheme.php:1.18 phd/themes/pear/peartheme.php:1.19 --- phd/themes/pear/peartheme.php:1.18 Mon Nov 3 20:34:45 2008 +++ phd/themes/pear/peartheme.php Wed Nov 5 19:11:16 2008 @@ -230,7 +230,7 @@ */ public $ext = null; - protected $lang = "en"; + protected $lang = 'en'; /** * If whitespace should be trimmed. @@ -242,24 +242,32 @@ */ public $trim = false; - protected $CURRENT_ID = ""; + protected $CURRENT_ID = ''; /* Current Chunk settings */ protected $cchunk = array(); /* Default Chunk settings */ protected $dchunk = array( - "fieldsynopsis" => array( - "modifier" => "public", + 'fieldsynopsis' => array( + 'modifier' => 'public', ), - "container_chunk" => null, - "qandaentry" => array( + 'container_chunk' => null, + 'qandaentry' => array( ), - "examples" => 0, - "verinfo" => false, - "refname" => array(), + 'examples' => 0, + 'verinfo' => false, + 'refname' => array(), ); - public function __construct(array $IDs, $ext = "php", $chunked = true) { + /** + * Constructor + * + * @param array $IDs Array of elements + * @param string $ext Filename extension to use + * @param bool $chunked whether or not to chunk the output + */ + public function __construct(array $IDs, $ext = 'php', $chunked = true) + { parent::__construct($IDs, $ext); $this->ext = $ext; $this->chunked = $chunked; @@ -277,34 +285,36 @@ return preg_replace('#<p>\\s*</p>#s', '', $str); } - public function format_chunk($open, $name, $attrs, $props) { + public function format_chunk($open, $name, $attrs, $props) + { $id = null; - if (isset($attrs[PhDReader::XMLNS_XML]["id"])) { - $this->CURRENT_ID = $id = $attrs[PhDReader::XMLNS_XML]["id"]; + if (isset($attrs[PhDReader::XMLNS_XML]['id'])) { + $this->CURRENT_ID = $id = $attrs[PhDReader::XMLNS_XML]['id']; } - if ($props["isChunk"]) { + if ($props['isChunk']) { $this->cchunk = $this->dchunk; } - if (isset($props["lang"])) { - $this->lang = $props["lang"]; + if (isset($props['lang'])) { + $this->lang = $props['lang']; } - if ($name == "refentry") { - if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"])) { - $this->cchunk["verinfo"] = !($attrs[PhDReader::XMLNS_DOCBOOK]["role"] == "noversion"); + if ($name == 'refentry') { + if (isset($attrs[PhDReader::XMLNS_DOCBOOK]['role'])) { + $this->cchunk['verinfo'] = !($attrs[PhDReader::XMLNS_DOCBOOK]['role'] == 'noversion'); } else { - $this->cchunk["verinfo"] = true; + $this->cchunk['verinfo'] = true; } } - if ($name == "legalnotice") { + if ($name == 'legalnotice') { if ($open) { - return '<div class="' . $name . '" ' . ($id ? "id=\"{$id}\"" : "") . '">'; + return '<div class="' . $name . '" ' . ($id ? "id=\"{$id}\"" : '') . '">'; } return "</div>\n"; } return false; } - public function format_container_chunk($open, $name, $attrs, $props) { + public function format_container_chunk($open, $name, $attrs, $props) + { if (!isset($attrs[PhDReader::XMLNS_XML]['id'])) { if ($open) { return "<div class=\"{$name}\">"; @@ -312,13 +322,13 @@ return "</div>\n"; } } - $this->CURRENT_ID = $id = $attrs[PhDReader::XMLNS_XML]["id"]; + $this->CURRENT_ID = $id = $attrs[PhDReader::XMLNS_XML]['id']; if (!$open) { return "</div>\n"; } - if ($props["isChunk"]) { + if ($props['isChunk']) { $this->cchunk = $this->dchunk; } @@ -330,7 +340,7 @@ if ($toc) { $toc = "<div class=\"TOC\">\n" . $toc . "</div>\n"; } - $this->cchunk["container_chunk"] = $toc; + $this->cchunk['container_chunk'] = $toc; return "<div class=\"{$name}\" id=\"{$id}\">"; } @@ -340,12 +350,24 @@ return $this->format->format_div($open, $name, $attrs, $props); } - public function format_exception_chunk($open, $name, $attrs, $props) { - return $this->format_container_chunk($open, "reference", $attrs, $props); + public function format_exception_chunk($open, $name, $attrs, $props) + { + return $this->format_container_chunk($open, 'reference', $attrs, $props); } - public function format_root_chunk($open, $name, $attrs, $props) { - $this->CURRENT_ID = $id = $attrs[PhDReader::XMLNS_XML]["id"]; + /** + * Formatting for the root element of a chunk. + * + * @param bool $open Whether we should open or close this element. + * @param string $name Name of the element + * @param array $attrs Attributes present for the element. Array keys are the attribute namespaces. + * @param array $props Associative array of additional properties + * + * @return string + */ + public function format_root_chunk($open, $name, $attrs, $props) + { + $this->CURRENT_ID = $id = $attrs[PhDReader::XMLNS_XML]['id']; if ($open) { return "<div class=\"{$name}\">"; } @@ -361,30 +383,41 @@ return $content; } - public function format_link($open, $name, $attrs, $props) { + /** + * Format a link for an element + * + * @param bool $open If the link should be opened. + * @param string $name Name of the element. + * @param array $attrs Attributes present for the element. Array keys are the attribute namespaces. + * @param array $props Properties + * + * @return string + */ + public function format_link($open, $name, $attrs, $props) + { if ($open) { - $content = $fragment = ""; + $content = $fragment = ''; $class = $name; - if(isset($attrs[PhDReader::XMLNS_DOCBOOK]["linkend"])) { - $linkto = $attrs[PhDReader::XMLNS_DOCBOOK]["linkend"]; + if (isset($attrs[PhDReader::XMLNS_DOCBOOK]['linkend'])) { + $linkto = $attrs[PhDReader::XMLNS_DOCBOOK]['linkend']; $id = $href = PhDHelper::getFilename($linkto); if ($id != $linkto) { $fragment = "#$linkto"; } if ($this->chunked) { - $href .= ".".$this->ext; + $href .= '.'.$this->ext; } - } elseif(isset($attrs[PhDReader::XMLNS_XLINK]["href"])) { - $href = $attrs[PhDReader::XMLNS_XLINK]["href"]; - $class .= " external"; + } elseif (isset($attrs[PhDReader::XMLNS_XLINK]['href'])) { + $href = $attrs[PhDReader::XMLNS_XLINK]['href']; + $class .= ' external'; } - if ($name == "xref") { + if ($name == 'xref') { if ($this->chunked) { $link = $href; } else { - $link = "#"; + $link = '#'; if (isset($linkto)) { $link .= $linkto; } else { @@ -392,17 +425,17 @@ } } return '<a href="' . htmlspecialchars($link). '" class="' .$class. '">' .($content.PhDHelper::getDescription($id, false)). '</a>'; - } elseif ($props["empty"]) { + } elseif ($props['empty']) { if ($this->chunked) { - $link = ""; + $link = ''; } else { - $link = "#"; + $link = '#'; } return '<a href="' .$link.$href.$fragment. '" class="' .$class. '">' .$content.$href.$fragment. '</a>'; } else { if ($this->chunked) { $link = $href.$fragment; - } elseif(isset($linkto)) { + } elseif (isset($linkto)) { if ($fragment) { $link = $fragment; } else { @@ -414,34 +447,37 @@ return '<a href="' .htmlspecialchars($link). '" class="' .$class. '">' .$content; } } - return "</a>"; + return '</a>'; } - public function format_container_chunk_title($open, $name, $attrs) { + public function format_container_chunk_title($open, $name, $attrs) + { if ($open) { - return "<h1>"; + return '<h1>'; } - $ret = ""; - if ($this->cchunk["container_chunk"]) { - $ret = $this->cchunk["container_chunk"]; - $this->cchunk["container_chunk"] = null; + $ret = ''; + if ($this->cchunk['container_chunk']) { + $ret = $this->cchunk['container_chunk']; + $this->cchunk['container_chunk'] = null; } return "</h1>\n" .$ret; } - public function transformFromMap($open, $tag, $name, $attrs, $props) { + public function transformFromMap($open, $tag, $name, $attrs, $props) + { if ($open) { - $idstr = ""; - if (isset($attrs[PhDReader::XMLNS_XML]["id"])) { - $id = $attrs[PhDReader::XMLNS_XML]["id"]; + $idstr = ''; + if (isset($attrs[PhDReader::XMLNS_XML]['id'])) { + $id = $attrs[PhDReader::XMLNS_XML]['id']; $idstr = ' id="' .$id. '" name="' .$id. '"'; } - return '<' .$tag. ' class="' .$name. '"' . $idstr. '>' . ($props["empty"] ? "</{$tag}>" : ""); + return '<' .$tag. ' class="' .$name. '"' . $idstr. '>' . ($props['empty'] ? "</{$tag}>" : ''); } return '</' .$tag. '>'; } - public function format_para_informaltable($open, $name, $attrs, $props) { + public function format_para_informaltable($open, $name, $attrs, $props) + { if ($open) { return $this->format->escapePara() . $this->format_table($open, $name, $attrs, $props); @@ -449,13 +485,14 @@ return $this->format_table($open, $name, $attrs, $props) . $this->format->restorePara(); } - public function format_programlisting($open, $name, $attrs) { + public function format_programlisting($open, $name, $attrs) + { if ($open) { $this->trim = true; - if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"])) { - $this->role = $attrs[PhDReader::XMLNS_DOCBOOK]["role"]; + if (isset($attrs[PhDReader::XMLNS_DOCBOOK]['role'])) { + $this->role = $attrs[PhDReader::XMLNS_DOCBOOK]['role']; } else { - $this->role = "default"; + $this->role = 'default'; } return $this->format->escapePara() @@ -466,19 +503,29 @@ return "</pre>\n" . $this->format->restorePara(); } - public function format_programlisting_text($value, $tag) { + /** + * Format the text within a program listing section. + * + * @param string $value Value of the text to format. + * @param unknown_type $tag + * + * @return string + */ + public function format_programlisting_text($value, $tag) + { switch($this->role) { - case "php": - if ( strrpos($value, "<?php") || strrpos($value, "?>") ) + case 'php': + if ( strrpos($value, '<?php') || strrpos($value, '?>') ) return highlight_string(trim($value), 1); else return highlight_string("<?php\n" . trim($value) . "\n?>", 1); break; default: - return htmlspecialchars($value, ENT_QUOTES, "UTF-8"); + return htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); } } - public function format_screen($open, $name, $attrs) { + public function format_screen($open, $name, $attrs) + { if ($open) { return $this->format->escapePara() . '<pre class="screen" style="background-color:#EEE; width: 100%">'; @@ -514,55 +561,62 @@ } if (!$this->role) { return str_replace( - array("\n", " "), array("<br/>", " "), - htmlspecialchars($str, ENT_QUOTES, "UTF-8") + array("\n", ' '), array('<br />', ' '), + htmlspecialchars($str, ENT_QUOTES, 'UTF-8') ); } switch ($this->role) { - case 'php': - if (strrpos($str, '<?php') || strrpos($str, '?>')) { - $str = highlight_string(trim($str), 1); - } else { - $str = highlight_string("<?php\n" . trim($str) . "\n?>", 1); - } - break; - default: - $str = htmlspecialchars($str, ENT_QUOTES, "UTF-8"); - break; + case 'php': + if (strrpos($str, '<?php') || strrpos($str, '?>')) { + $str = highlight_string(trim($str), 1); + } else { + $str = highlight_string("<?php\n" . trim($str) . "\n?>", 1); + } + break; + default: + $str = htmlspecialchars($str, ENT_QUOTES, 'UTF-8'); + break; } return $str; } - public function format_suppressed_tags($open, $name, $attrs) { + public function format_suppressed_tags($open, $name, $attrs) + { /* Ignore it */ - return ""; + return ''; } - public function format_suppressed_text($value, $tag) { + public function format_suppressed_text($value, $tag) + { /* Suppress any content */ - return ""; + return ''; } - public function format_surname($open, $name, $attrs) { + public function format_surname($open, $name, $attrs) + { /* Add a space before it, so firstname and surname are separated */ return ' '; } - public function format_subtitle($open, $name, $attrs) { + public function format_subtitle($open, $name, $attrs) + { if ($open) return '<p><font color="red">'; return '</font></p>'; } - public function format_editedby($open, $name, $attrs, $props) { - if ($open) - return "<h2 class=\"EDITEDBY\">" . $this->autogen("editedby", $props["lang"]) . "</h2>"; + public function format_editedby($open, $name, $attrs, $props) + { + if ($open) { + return '<h2 class="EDITEDBY">' . $this->autogen('editedby', $props['lang']) . '</h2>'; + } } - public function format_copyright($open, $name, $attrs) { + public function format_copyright($open, $name, $attrs) + { if ($open) { if ($this->chunked) { return '<p class="'.$name.'"><a href="copyright.' . $this->ext . '">Copyright</a> © '; @@ -573,48 +627,55 @@ return '</p>'; } - public function format_comment($open, $name, $attrs) { + public function format_comment($open, $name, $attrs) + { if ($open) { return '<!-- '; } return '-->'; } - public function format_holder($open, $name, $attrs, $props) { + public function format_holder($open, $name, $attrs, $props) + { if ($open) - return $this->autogen("by", $props["lang"]) . " "; + return $this->autogen('by', $props['lang']) . " "; } - public function format_year($value) { - return $value . ", "; + public function format_year($value) + { + return $value . ', '; } - public function format_admonition($open, $name, $attrs, $props) { + public function format_admonition($open, $name, $attrs, $props) + { if ($open) { return $this->format->escapePara() - . '<blockquote class="' . $name . '"><b>'.$this->autogen($name, $props["lang"]). ': </b>'; + . '<blockquote class="' . $name . '"><b>'.$this->autogen($name, $props['lang']). ': </b>'; } return "</blockquote>\n" . $this->format->restorePara(); } - public function format_table($open, $name, $attrs, $props) { + public function format_table($open, $name, $attrs, $props) + { if ($open) { return $this->format->escapePara() . '<table border="1" class="'.$name.'">'; } return "</table>\n" . $this->format->restorePara(); } - public function format_entry($open, $name, $attrs, $props) { + public function format_entry($open, $name, $attrs, $props) + { if ($open) { if ($props['empty']) { return '<td></td>'; } return '<td>'; } - return "</td>"; + return '</td>'; } - public function format_th_entry($open, $name, $attrs) { + public function format_th_entry($open, $name, $attrs) + { if ($open) { $colspan = PhDFormat::colspan($attrs[PhDReader::XMLNS_DOCBOOK]); return '<th colspan="' .((int)$colspan). '">'; @@ -622,30 +683,34 @@ return '</th>'; } - public function format_table_title($open, $name, $attrs, $props) { - if ($props["empty"]) - return ""; + public function format_table_title($open, $name, $attrs, $props) + { + if ($props['empty']) + return ''; if ($open) { return '<caption><b>'; } return '</b></caption>'; } - public function format_userinput($open, $name, $attrs, $props) { + public function format_userinput($open, $name, $attrs, $props) + { if ($open) { return '<tt class="'.$name.'"><b>'; } - return "</b></tt>"; + return '</b></tt>'; } - function format_replaceable($open, $name, $attrs, $props) { + public function format_replaceable($open, $name, $attrs, $props) + { if ($open) { return '<tt class="'.$name.'"><i>'; } - return "</i></tt>"; + return '</i></tt>'; } - public function format_warning($open, $name, $attrs, $props) { + public function format_warning($open, $name, $attrs, $props) + { if ($open) { return $this->format->escapePara() . '<div class="warning" style="border: 3px double black; padding: 5px">' . "\n"; @@ -653,17 +718,19 @@ return "</div>\n" . $this->format->restorePara(); } - public function format_warning_title($open, $name, $attrs, $props) { + public function format_warning_title($open, $name, $attrs, $props) + { if ($open) { return '<strong class="warning_title" style="display:block; text-align: center; width:100%">'; } return "</strong>\n"; } - public function format_warning_para($open, $name, $attrs, $props) { + public function format_warning_para($open, $name, $attrs, $props) + { if ($open) { if (!$props['sibling']) { - return '<strong>' . $this->autogen("warning", $props["lang"]) . "</strong>\n" + return '<strong>' . $this->autogen('warning', $props['lang']) . "</strong>\n" . '<p>'; } return '<p>'; @@ -671,68 +738,82 @@ return "</p>\n"; } - public function format_refname_function_text($value) { - $this->cchunk["refname"][] = '<b class="function">' . $this->format->TEXT($value . '()') . '</b>'; + public function format_refname_function_text($value) + { + $this->cchunk['refname'][] = '<b class="function">' . $this->format->TEXT($value . '()') . '</b>'; return false; } - public function format_refname_classname_text($value) { - $this->cchunk["refname"][] = '<b class="classname">' . $this->format->TEXT($value) . '</b>'; + public function format_refname_classname_text($value) + { + $this->cchunk['refname'][] = '<b class="classname">' . $this->format->TEXT($value) . '</b>'; return false; } - public function format_refpurpose($open, $tag, $attrs) { + public function format_refpurpose($open, $tag, $attrs) + { if ($open) { - $refnames = implode(' ', $this->cchunk["refname"]); + $refnames = implode(' ', $this->cchunk['refname']); return '<div class="refnamediv">'. $refnames. ' -- '; } return "</div>\n"; } - public function format_refname_text($value, $tag) { - $this->cchunk["refname"][] = $this->format->TEXT($value); + + public function format_refname_text($value, $tag) + { + $this->cchunk['refname'][] = $this->format->TEXT($value); return false; } - public function format_function_text($value) { + public function format_function_text($value) + { return $this->format->TEXT($value."()"); } - public function format_paramdef($open, $name, $attrs, $props) { - if ($open && $props["sibling"] == 'paramdef') + public function format_paramdef($open, $name, $attrs, $props) + { + if ($open && $props['sibling'] == 'paramdef') { return ' , '; + } return false; } - public function format_funcdef($open, $name, $attrs, $props) { - if (!$open) + public function format_funcdef($open, $name, $attrs, $props) + { + if (!$open) { return ' ( '; + } return false; } - public function format_funcprototype($open, $name, $attrs, $props) { + public function format_funcprototype($open, $name, $attrs, $props) + { if ($open) { return '<p><code class="' . $name . '">'; } - else return ")</code></p>"; + return ')</code></p>'; } - public function format_uri($open, $name, $attrs, $props) { + public function format_uri($open, $name, $attrs, $props) + { if ($open) { return '<font color="red">'; } - else return "</font>"; + return '</font>'; } - public function format_refsynopsisdiv($open, $name, $attrs, $props) { + public function format_refsynopsisdiv($open, $name, $attrs, $props) + { if ($open) { return '<h2 class="refsynopsisdiv">Synopsis</h2>'; } return ''; } - public function format_guimenu($open, $name, $attrs, $props) { + public function format_guimenu($open, $name, $attrs, $props) + { if ($open) { - if ($props["sibling"]) + if ($props['sibling']) return '-><span class="guimenu"><i>'; return '<span class="guimenu"><i>'; } @@ -744,14 +825,21 @@ return $this->format->format_dl($open, $name, $attrs, $props); } - /* FIXME: This function is a crazy performance killer */ - public function qandaset($stream) { + /** + * FIXME: This function is a crazy performance killer + * + * @param resource $stream Stream containing the contents of a Q&A section + * + * @return string + */ + public function qandaset($stream) + { $xml = stream_get_contents($stream); $old = libxml_use_internal_errors(true); - $doc = new DOMDocument("1.0", "UTF-8"); + $doc = new DOMDocument('1.0', 'UTF-8'); $doc->preserveWhitespace = false; - $doc->loadXML(html_entity_decode(str_replace("&", "&amp;", "<div>$xml</div>"), ENT_QUOTES, "UTF-8")); + $doc->loadXML(html_entity_decode(str_replace('&', '&amp;', "<div>$xml</div>"), ENT_QUOTES, 'UTF-8')); if ($err = libxml_get_errors()) { print_r($err); libxml_clear_errors(); @@ -763,34 +851,41 @@ $nlist = $xpath->query("//div/dl/dt/strong"); $ret = '<div class="qandaset"><ol class="qandaset_questions">'; $i = 0; - foreach($nlist as $node) { - $ret .= '<li><a href="#' .($this->cchunk["qandaentry"][$i++]). '">' .($node->textContent). '</a></li>'; + foreach ($nlist as $node) { + $ret .= '<li><a href="#' .($this->cchunk['qandaentry'][$i++]). '">' .($node->textContent). '</a></li>'; } return $ret.'</ol>'.$xml.'</div>'; } - public function format_qandaentry($open, $name, $attrs) { + + public function format_qandaentry($open, $name, $attrs) + { if ($open) { - $this->cchunk["qandaentry"][] = $this->CURRENT_ID . ".entry" . count($this->cchunk["qandaentry"]); + $this->cchunk['qandaentry'][] = $this->CURRENT_ID . ".entry" . count($this->cchunk['qandaentry']); return '<dl>'; } return '</dl>'; } - public function format_answer($open, $name, $attrs) { + + public function format_answer($open, $name, $attrs) + { if ($open) { - return '<dd><a name="' .end($this->cchunk["qandaentry"]).'"></a>'; + return '<dd><a name="' .end($this->cchunk['qandaentry']).'"></a>'; } - return "</dd>"; + return '</dd>'; } - public function format_question($open, $name, $attrs) { + + public function format_question($open, $name, $attrs) + { if ($open) { return '<dt><strong>'; } return '</strong></dt>'; } - public function format_emphasis($open, $name, $attrs) { - if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["role"]) && $attrs[PhDReader::XMLNS_DOCBOOK]["role"] == "bold") + public function format_emphasis($open, $name, $attrs) + { + if (isset($attrs[PhDReader::XMLNS_DOCBOOK]['role']) && $attrs[PhDReader::XMLNS_DOCBOOK]['role'] == "bold") $role = "b"; else $role = "i"; if ($open) { @@ -799,30 +894,35 @@ return "</{$role}>"; } - public function format_glossterm($open, $name, $attrs) { + public function format_glossterm($open, $name, $attrs) + { if ($open) { return '<dt><b>'; } - return "</b></dt>"; + return '</b></dt>'; } - public function format_glossdef($open, $name, $attrs) { + public function format_glossdef($open, $name, $attrs) + { if ($open) { return '<dd><p>'; } - return "</p></dd>"; + return '</p></dd>'; } - public function format_calloutlist($open, $name, $attrs) { + public function format_calloutlist($open, $name, $attrs) + { if ($open) { - $this->cchunk["callouts"] = 0; + $this->cchunk['callouts'] = 0; return $this->format->escapePara() . '<table>'; } return '</table>' . $this->format->restorePara(); } - public function format_callout($open, $name, $attrs) { + + public function format_callout($open, $name, $attrs) + { if ($open) { - return '<tr><td><a href="#'.$attrs[PhDReader::XMLNS_DOCBOOK]["arearefs"].'">(' .++$this->cchunk["callouts"]. ')</a></td><td>'; + return '<tr><td><a href="#'.$attrs[PhDReader::XMLNS_DOCBOOK]['arearefs'].'">(' .++$this->cchunk['callouts']. ')</a></td><td>'; } return "</td></tr>\n"; }