/** * Save a SimpleXMLElement as XML file. * * @param string $fileName The filename of XML file * @param SimpleXMLElement $resource The XML resource * * @return void */ public function saveXML($fileName, SimpleXMLElement $resource) { $domSXE = dom_import_simplexml($resource); $dom = new DOMDocument('1.0'); $dom->appendChild($dom->importNode($domSXE, true)); $dom->formatOutput = true; $this->cbFDHandler->createFile($fileName, $dom->saveXML()); }
/** * Save rendered file to output directory * * @param array $data Dataset information used for rendering * @param string $fileName The filename of analyzed file * * @return void * @see cbFDHandler::createFile */ private function _generateView($data, $fileName) { $this->_cbFDHandler->createFile($this->_outputDir . DIRECTORY_SEPARATOR . $fileName, $this->_render('page', $data)); }
/** * Generate javascript highlighted source for HTML files. * * @param string $fileName The filename where source should be highlighted * @param arry $errors The error list for this files as highlight base * * @return string * @see cbFDHandler::loadFile */ public function getHighlightedSource($fileName, $errors, $projectSource) { ob_start(); $code = $this->cbFDHandler->loadFile($projectSource . '/' . $fileName); ini_set('highlight.comment', 'comment'); ini_set('highlight.default', 'default'); ini_set('highlight.keyword', 'keyword'); ini_set('highlight.string', 'string'); ini_set('highlight.html', 'html'); $code = highlight_string($code, true); $code = str_replace(array(' ', '&', '<br />', '<span style="color: '), array(' ', '&', "\n", '<span class="'), substr($code, 33, -15)); $code = trim($code); $code = str_replace("\r", "\n", $code); $code = preg_replace("!\n\n\n+!", "\n\n", $code); $lines = explode("\n", $code); $previous = false; // Output Listing echo " <ol class=\"code\">\n"; foreach ($lines as $key => $line) { if (substr($line, 0, 7) == '</span>') { $previous = false; $line = substr($line, 7); } if (empty($line)) { $line = ' '; } if ($previous) { $line = "<span class=\"{$previous}\">" . $line; } // Set Previous Style if (strpos($line, '<span') !== false) { switch (substr($line, strrpos($line, '<span') + 13, 1)) { case 'c': $previous = 'comment'; break; case 'd': $previous = 'default'; break; case 'k': $previous = 'keyword'; break; case 's': $previous = 'string'; break; } } // Unset Previous Style Unless Span Continues if (substr($line, -7) == '</span>') { $previous = false; } elseif ($previous) { $line .= '</span>'; } $num = $key + 1; $classname = 'white'; $classnameEven = 'even'; $prefix = ''; $suffix = ''; $max = 0; $min = count($lines); $singleRow = false; foreach ($errors as $error) { if ($error['line'] <= $num && $error['to-line'] >= $num) { if ($max <= (int) $error['to-line']) { $max = (int) $error['to-line']; } if ($min >= (int) $error['line']) { $min = (int) $error['line']; } $classnameEven = 'transparent'; $classname = 'transparent'; if ((int) $error['line'] == $num) { $prefix = sprintf('<li id="line-%s-%s" class="%s" ><ul>', $error['line'], $error['to-line'], $prefix != '' ? 'moreErrors' : $error['source']); } if ((int) $error['to-line'] == $num) { $suffix = "</ul></li>"; } } } if ($num < $max && $min == $num) { $suffix = ''; } echo sprintf('%s<li id="line-%d" class="%s"> <a name="line-%d"></a> <code>%s</code></li>%s' . "\n", $prefix, $num, $key % 2 ? $classnameEven : $classname, $num, $line, $suffix); } echo "</ol>\n"; $contents = ob_get_contents(); ob_end_clean(); return $contents; }