Exemplo n.º 1
0
 /**
  *   Formats the result as html and returns it.
  *
  *   @param array    $arResult   The result you get from PhpGtkDoc_Search2::find()
  *   @param string   $strPrefix  The prefix to put before the file names
  *   @param string   $strFilter  The type filter (pass e.g. "method" to find methods only)
  *
  *   @return string      Nicely formatted ascii output
  */
 public static function format($arResult, $strPrefix = '', $strFilter = '')
 {
     $strOutput = '';
     foreach ($arResult as $nLevel => $arLevel) {
         $strLevelOutput = '';
         foreach ($arLevel as $strType => $arFiles) {
             if ($strFilter != '' && $strType != $strFilter) {
                 continue;
             }
             $strLevelOutput .= '<h4>' . self::$arTypeTitles[$strType] . "</h4>\r\n";
             $strLevelOutput .= '<ul>';
             foreach ($arFiles as $strFile) {
                 $strLevelOutput .= '<li><a href="' . htmlspecialchars($strPrefix . $strFile) . '">' . htmlspecialchars(PhpGtkDoc_Search2::getFileTitle($strFile, $strType)) . "</a></li>\r\n";
             }
             $strLevelOutput .= '</ul>';
         }
         if ($strLevelOutput != '') {
             $strOutput .= '<h3>' . self::$arLevelTitles[$nLevel] . "</h3>\r\n" . $strLevelOutput;
         }
     }
     return $strOutput;
 }
Exemplo n.º 2
0
set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/include/');
$strResult = null;
$strError = null;
$strSearch = null;
$strSelectedType = '';
if (isset($_REQUEST['q']) && $_REQUEST['q'] != '') {
    require_once 'PhpGtkDoc/Search2.php';
    require_once 'PhpGtkDoc/Search2/Result/Html.php';
    $strIndexFile = dirname(__FILE__) . '/include/PhpGtkDoc/index.search';
    $strDocumentationDir = 'manual/en/';
    if (isset($_REQUEST['type']) && isset($arTypes[$_REQUEST['type']])) {
        $strSelectedType = $_REQUEST['type'];
    }
    $strSearch = preg_replace('/[^a-zA-Z0-9_ ]/', '', $_REQUEST['q']);
    try {
        $arResults = PhpGtkDoc_Search2::find($strSearch, $strIndexFile);
        $strResult = PhpGtkDoc_Search2_Result_Html::format($arResults, $strDocumentationDir, $strSelectedType);
        if ($strResult == '') {
            $strResult = '<p>Your search for "' . $strSearch . '" didn\'t return any results.</p>';
        }
    } catch (Exception $e) {
        $strError = $e->getMessage();
    }
}
commonHeader('Search results');
if ($strError !== null) {
    echo '<h2>Error</h2>';
    echo $strError;
}
if ($strResult !== null) {
    echo '<h2>PHP-GTK 2 manual search results for "' . $strSearch . '"</h2>';