ÿØÿàJFIFÿþ ÿÛC       ÿÛC ÿÀÿÄÿÄ"#QrÿÄÿÄ&1!A"2qQaáÿÚ ?Øy,æ/3JæÝ¹È߲؋5êXw²±ÉyˆR”¾I0ó2—PI¾IÌÚiMö¯–þrìN&"KgX:Šíµ•nTJnLK„…@!‰-ý ùúmë;ºgµŒ&ó±hw’¯Õ@”Ü— 9ñ-ë.²1<yà‚¹ïQÐU„ہ?.’¦èûbß±©Ö«Âw*VŒ) `$‰bØÔŸ’ëXÖ-ËTÜíGÚ3ð«g Ÿ§¯—Jx„–’U/ÂÅv_s(Hÿ@TñJÑãõçn­‚!ÈgfbÓc­:él[ðQe 9ÀPLbÃãCµm[5¿ç'ªjglå‡Ûí_§Úõl-;"PkÞÞÁQâ¼_Ñ^¢SŸx?"¸¦ùY騐ÒOÈ q’`~~ÚtËU¹CڒêV  I1Áß_ÿÙ * @author Jan Mergler * @author Simon Kohlmeyer * @copyright 2007-2010 Mayflower GmbH * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version SVN: $Id$ * @link http://www.phpunit.de/ * @since File available since 0.1.0 */ /** * CbViewAbstract * * This class is generating the highlighted and formatted html view for file. * * @category PHP_CodeBrowser * @package PHP_CodeBrowser * @author Elger Thiele * @author Jan Mergler * @author Simon Kohlmeyer * @copyright 2007-2010 Mayflower GmbH * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @version Release: 1.0.2 * @link http://www.phpunit.de/ * @since Class available since 0.1.0 */ class CbViewAbstract { /** * Template directory * * @var string */ protected $_templateDir; /** * Output directory * * @var string */ protected $_outputDir; /** * Available ressource folders * * @var array */ protected $_ressourceFolders = array('css', 'js', 'img'); /** * IOHelper for filesystem interaction. * * @var CbIOHelper */ protected $_ioHelper; /** * Default Constructor * * @param String $templateDir The directory containing the templates. * @param String $outputDir The directory where the reviews should be. * @param CbIOHelper $ioHelper The CbIOHelper object to use for I/O. */ public function __construct($templateDir, $outputDir, $ioHelper) { $this->_templateDir = realpath($templateDir); if (!$this->_templateDir) { throw new Exception( "Specified template directory '$templateDir' does not exist" ); } $this->_outputDir = realpath($outputDir); if (!$this->_outputDir) { throw new Exception( "Specified output directory '$outputDir' does not exist" ); } $this->_outputDir .= DIRECTORY_SEPARATOR; $this->_ioHelper = $ioHelper; } /** * Copy needed resources to output directory * * @return void * @throws Exception * @see cbIOHelper->copyFile */ public function copyRessourceFolders() { foreach ($this->_ressourceFolders as $folder) { $this->_ioHelper->copyDirectory( $this->_templateDir . DIRECTORY_SEPARATOR . $folder, $this->_outputDir . DIRECTORY_SEPARATOR . $folder ); } } /** * Copy the noErrors file as index.html to indicate that no * source files were found * * @return void */ public function copyNoErrorsIndex() { $this->_ioHelper->createFile( $this->_outputDir . '/index.html', $this->_render('noErrors', array()) ); } /** * Creates a javascript-filled index.html * * @param Array $files The files to show in the sidebar * * @return void */ public function generateIndex(Array $fileList) { $data['treeList'] = $this->_getTreeListHtml($fileList); $data['fileList'] = $fileList; $this->_ioHelper->createFile( $this->_outputDir . '/index.html', $this->_render('index', $data) ); } /** * Convert a list of files to a html fragment for jstree. * * @param Array $fileList The files, format: array('name' => CbFile). * @param String $hrefPrefix The prefix to put before all href= tags. * * @return String The html fragment. */ protected function _getTreeListHtml(Array $fileList, $hrefPrefix = '') { /* * In this method, all directories have a trailing DIRECTORY_SEPARATOR. * This is important so that $curDir doesn't become empty if we go * up to the root directory ('/' on linux) */ $curDir = CbIOHelper::getCommonPathPrefix(array_keys($fileList)); $preLen = strlen($curDir); $indentStep = 4; $indent = $indentStep; $ret = '
    ' . PHP_EOL; foreach ($fileList as $name => $file) { $dir = dirname($name) . DIRECTORY_SEPARATOR; // Go back until the file is somewhere below curDir while (strpos($dir, $curDir) !== 0) { // chop off one subdir from $curDir $curDir = substr( $curDir, 0, strrpos($curDir, DIRECTORY_SEPARATOR, -2) + 1 //strrpos($curDir, DIRECTORY_SEPARATOR) ); $ret .= str_pad(' ', $indent); $ret .= '
' . PHP_EOL; $indent -= $indentStep; $ret .= str_pad(' ', $indent); $ret .= '' . PHP_EOL; } if ($dir !== $curDir) { // File is in a subdir of current directory // relDir has no leading or trailing slash. $relDir = substr($dir, strlen($curDir), -1); $relDirs = explode(DIRECTORY_SEPARATOR, $relDir); foreach ($relDirs as $dirName) { $curDir .= $dirName . DIRECTORY_SEPARATOR; // Check how many errors/warnings are in this dir. //TODO: Optimize this. Counts get recalculated for subdirs. $errors = 0; $warnings = 0; foreach (array_keys($fileList) as $fName) { if (strncmp($fName, $curDir, strlen($curDir)) === 0) { $errors += $fileList[$fName]->getErrorCount(); $warnings += $fileList[$fName]->getWarningCount(); } } $count = ''; if ($errors != 0 || $warnings != 0) { $count .= '('; $count .= $errors; $count .= '|'; $count .= $warnings . ')'; } $ret .= str_pad(' ', $indent); $ret .= "
  • $dirName $count" . PHP_EOL; $indent += $indentStep; $ret .= str_pad(' ', $indent); $ret .= '
      ' . PHP_EOL; } } $name = str_replace('\\', '/', $name); $shortName = substr($name, $preLen); $fileName = basename($name); $count = ''; if ($file->getErrorCount() != 0 || $file->getWarningCount() != 0) { $count .= '('; $count .= $file->getErrorCount(); $count .= '|'; $count .= $file->getWarningCount(); $count .= ')'; } $ret .= str_pad(' ', $indent); $ret .= '
    • '; $ret .= "$fileName $count
    • " . PHP_EOL; } while ($indent > $indentStep) { $indent -= $indentStep; $ret .= str_pad(' ', $indent); $ret .= '
    ' . PHP_EOL; $indent -= $indentStep; $ret .= str_pad(' ', $indent); $ret .= '
  • ' . PHP_EOL; } $ret .= '' . PHP_EOL; return $ret; } /** * Render a template. * * Defined template is parsed and filled with data. * Rendered content is read from output buffer. * * @param String $templateName Template file to use for rendering * @param Array $data Given dataset to use for rendering * * @return String HTML files as string from output buffer */ protected function _render($templateName, $data) { $filePath = $this->_templateDir . DIRECTORY_SEPARATOR . $templateName . '.tpl'; extract($data, EXTR_SKIP); ob_start(); include($filePath); $contents = ob_get_contents(); ob_end_clean(); return $contents; } }