Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * Return the filepath
  *
  * @param bool $strip_root_dir
  *
  * @return string
  */
 public function getFilePath($strip_root_dir = false)
 {
     $root_dir = $this->_search->getRootDir();
     if (!empty($root_dir) && !empty($strip_root_dir)) {
         $root_dir = preg_quote($root_dir, "#");
         $filepath = preg_replace("#^{$root_dir}(" . DIRECTORY_SEPARATOR . "|\$)#", '', $this->_filepath);
     } else {
         $filepath = $this->_filepath;
     }
     return $filepath ?: '';
 }
Exemplo n.º 3
0
 /**
  * @param string $query_string
  * @param string $url_path
  *
  * @return string
  */
 private function getModifiedQueryString($query_string, $url_path)
 {
     $query_vars = $this->search->getOptions()->get(Opt::BASE_PARAMS);
     if (!empty($query_string)) {
         parse_str($query_string, $parsed_vars);
         $query_vars = array_merge($query_vars, $parsed_vars);
     }
     if (isset($query_vars['q'])) {
         $query_vars['tmd_q'] = $query_vars['q'];
         unset($query_vars['q']);
     }
     $query_vars['tmd_f'] = $url_path;
     unset($query_vars['tmd_r']);
     if (isset($query_vars['raw'])) {
         $query_vars['tmd_r'] = '1';
         unset($query_vars['raw']);
     }
     ksort($query_vars, SORT_STRING);
     return http_build_query($query_vars);
 }