/** * Return the page output (HTML / Raw) * * @param array $headers Output headers * * @return string|\DOMDocument */ public function getOutput(array &$headers = array()) { $this->_prepareOptions(); $this->_prepareSearch(); $this->_prepareTree(); // Raw output? switch ($this->_options->get(Opt::OUTPUT_TYPE)) { case Opt::OUTPUT_TYPE_RAW: $headers['Content-type'] = 'text/plain; charset=UTF-8'; $current_file = $this->_search->getCurrentFile(false); if ($this->_search->isCurrentFileValid() && is_file($current_file)) { $file_encoder = new FileEncoder($current_file); $output = $file_encoder->getFileContents(); } else { $output = 'Your current selection is not valid.'; } break; case Opt::OUTPUT_TYPE_DOM: $headers['Content-type'] = 'text/html; charset=UTF-8'; $this->_tree->buildTree(); $this->_preparePage(); $output = $this->_page->getDOMDocument(); break; default: $output = 'No valid output type set.'; } return $output; }
/** * Return the current file * * @param bool $strip_root_dir * * @return string */ public function getCurrentFile($strip_root_dir = false) { $file = ''; $current_file = $this->_options->get(Opt::FILE_CURRENT); if ($this->isCurrentFileValid()) { if (!empty($strip_root_dir)) { $file = preg_replace("#^{$this->getRootDir()}(" . DIRECTORY_SEPARATOR . "|\$)#", '', $current_file); } else { $file = $current_file; } } return $file; }