* @author Juliette Reinders Folmer %1$s Coding Standards
',
$standard,
self::STYLESHEET
);
// Use the correct line endings based on the OS.
return str_replace("\n", PHP_EOL, $output).PHP_EOL;
}//end getFormattedHeader()
/**
* Print the table of contents for the standard.
*
* @deprecated 3.12.0 Use HTML::getFormattedToc() instead.
*
* @codeCoverageIgnore
*
* @return void
*/
protected function printToc()
{
trigger_error(
'The '.__METHOD__.'() method is deprecated. Use "echo '.__CLASS__.'::getFormattedToc()" instead.',
E_USER_DEPRECATED
);
echo $this->getFormattedToc();
}//end printToc()
/**
* Format the table of contents for the standard.
*
* The TOC is just an unordered list of bookmarks to sniffs on the page.
*
* @since 3.12.0 Replaces the deprecated HTML::printToc() method.
*
* @return string
*/
protected function getFormattedToc()
{
// Only show a TOC when there are two or more docs to display.
if (count($this->docFiles) < 2) {
return '';
}
$output = ' Table of Contents
'.PHP_EOL;
$output .= ' '.PHP_EOL;
$listItemTemplate = '
'.PHP_EOL;
return $output;
}//end getFormattedToc()
/**
* Print the footer of the HTML page.
*
* @deprecated 3.12.0 Use HTML::getFormattedFooter() instead.
*
* @codeCoverageIgnore
*
* @return void
*/
protected function printFooter()
{
trigger_error(
'The '.__METHOD__.'() method is deprecated. Use "echo '.__CLASS__.'::getFormattedFooter()" instead.',
E_USER_DEPRECATED
);
echo $this->getFormattedFooter();
}//end printFooter()
/**
* Format the footer of the HTML page.
*
* @since 3.12.0 Replaces the deprecated HTML::printFooter() method.
*
* @return string
*/
protected function getFormattedFooter()
{
// Turn off errors so we don't get timezone warnings if people
// don't have their timezone set.
$errorLevel = error_reporting(0);
$output = sprintf(
' %2$s §
'.PHP_EOL,
$this->titleToAnchor($title),
$title
);
echo $content;
}
}//end processSniff()
/**
* Transform a title to a string which can be used as an HTML anchor.
*
* @param string $title The title.
*
* @since 3.12.0
*
* @return string
*/
private function titleToAnchor($title)
{
// Slugify the text.
$title = strtolower($title);
$title = preg_replace('`[^a-z0-9\._-]`', '-', $title);
if (isset($this->seenAnchors[$title]) === true) {
// Try to find a unique anchor for this title.
for ($i = 2; (isset($this->seenAnchors[$title.'-'.$i]) === true); $i++);
$title .= '-'.$i;
}
// Add to "seen" list.
$this->seenAnchors[$title] = true;
return $title;
}//end titleToAnchor()
/**
* Print a text block found in a standard.
*
* @param \DOMNode $node The DOMNode object for the text block.
*
* @deprecated 3.12.0 Use HTML::getFormattedTextBlock() instead.
*
* @codeCoverageIgnore
*
* @return void
*/
protected function printTextBlock(DOMNode $node)
{
trigger_error(
'The '.__METHOD__.'() method is deprecated. Use "echo '.__CLASS__.'::getFormattedTextBlock()" instead.',
E_USER_DEPRECATED
);
echo $this->getFormattedTextBlock($node);
}//end printTextBlock()
/**
* Format a text block found in a standard.
*
* @param \DOMNode $node The DOMNode object for the text block.
*
* @since 3.12.0 Replaces the deprecated HTML::printTextBlock() method.
*
* @return string
*/
protected function getFormattedTextBlock(DOMNode $node)
{
$content = $node->nodeValue;
if (empty($content) === true) {
return '';
}
$content = trim($content);
$content = htmlspecialchars($content, (ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401));
// Allow only em tags.
$content = str_replace('<em>', '', $content);
$content = str_replace('</em>', '', $content);
$nodeLines = explode("\n", $content);
$lineCount = count($nodeLines);
$lines = [];
for ($i = 0; $i < $lineCount; $i++) {
$currentLine = trim($nodeLines[$i]);
if (isset($nodeLines[($i + 1)]) === false) {
// We're at the end of the text, just add the line.
$lines[] = $currentLine;
} else {
$nextLine = trim($nodeLines[($i + 1)]);
if ($nextLine === '') {
// Next line is a blank line, end the paragraph and start a new one.
// Also skip over the blank line.
$lines[] = $currentLine.'
';
++$i;
} else {
// Next line is not blank, so just add a line break.
$lines[] = $currentLine.'
'.PHP_EOL;
}
}
}
return '
'.implode('', $lines).'
'.PHP_EOL; }//end getFormattedTextBlock() /** * Print a code comparison block found in a standard. * * @param \DOMNode $node The DOMNode object for the code comparison block. * * @deprecated 3.12.0 Use HTML::getFormattedCodeComparisonBlock() instead. * * @codeCoverageIgnore * * @return void */ protected function printCodeComparisonBlock(DOMNode $node) { trigger_error( 'The '.__METHOD__.'() method is deprecated. Use "echo '.__CLASS__.'::getFormattedCodeComparisonBlock()" instead.', E_USER_DEPRECATED ); echo $this->getFormattedCodeComparisonBlock($node); }//end printCodeComparisonBlock() /** * Format a code comparison block found in a standard. * * @param \DOMNode $node The DOMNode object for the code comparison block. * * @since 3.12.0 Replaces the deprecated HTML::printCodeComparisonBlock() method. * * @return string */ protected function getFormattedCodeComparisonBlock(DOMNode $node) { $codeBlocks = $node->getElementsByTagName('code'); $firstCodeElm = $codeBlocks->item(0); $secondCodeElm = $codeBlocks->item(1); if (isset($firstCodeElm, $secondCodeElm) === false) { // Missing at least one code block. return ''; } $firstTitle = $this->formatCodeTitle($firstCodeElm); $first = $this->formatCodeSample($firstCodeElm); $secondTitle = $this->formatCodeTitle($secondCodeElm); $second = $this->formatCodeSample($secondCodeElm); $titleRow = ''; if ($firstTitle !== '' || $secondTitle !== '') { $titleRow .= '