<?php
defined(
'main'
)
or
die
(
'No direct Access to this File!'
);
defined(
'__DIR__'
)
or
define(
'__DIR__'
, dirname(
__FILE__
));
$ckLogin
= false;
$pName
=
'Selfpage Search'
;
$Title
=
$allgAr
[
'title'
].
' :: '
.
$pName
;
$Hmenu
=
$pName
;
$Design
=
new
design(
$Titel
,
$Hmenu
);
$Design
->header();
if
(
$ckLogin
=== true && !loggedin() ) {
wd(
'index.php'
,
'Du darfst diese Suche nicht benutzen!'
);
$Design
->footer(1);
}
echo
'<h2>Suche</h2><hr /><br />'
;
?>
<form method=
"post"
action=
"index.php?selfsearch"
>
<input type=
"text"
name=
"q"
value=
"Suchen..."
onfocus="
if
( this.value ==
'Suchen...'
) {
this.value =
''
;
}
" onblur="
if
( this.value ==
''
) {
this.value =
'Suchen...'
;
}
" style="
width: 200px; font-style: italic; font-weight: bold;" />
<br />
<br />
<input type=
"checkbox"
name=
"i"
/> Begriffe trennen? ( Trennt
die
Begriffe nach Kommas. Nützlich für mehrere Suchbegriffe )
<br />
<input type=
"checkbox"
name=
"b"
/> Treffer hervorheben?
<br />
<input type=
"checkbox"
name=
"fn"
/> Im Dateinamen suchen?
<br />
<br />
<input type=
"submit"
value=
"Suchen!"
/>
</form>
<br />
<hr />
<br />
<?php
if
( isset(
$_REQUEST
[
'q'
]) && !
empty
(
$_REQUEST
[
'q'
]) ) {
$_REQUEST
[
'q'
] = trim(
$_REQUEST
[
'q'
]);
$_REQUEST
[
'q'
] = escape(
$_REQUEST
[
'q'
],
'string'
);
$Search
= isset(
$_REQUEST
[
'i'
]) ? preg_replace(
'/(\s*),(\s*)/'
,
'|'
,
$_REQUEST
[
'q'
]) :
$_REQUEST
[
'q'
];
$Output
=
array
();
$Path
= __DIR__ .
'/selfbp/selfp/'
;
$Dir
= scandir(
$Path
);
foreach
(
$Dir
as
$File
) {
if
(
substr
(
$File
, 0, 1) ==
'.'
||
substr
(
$File
, (
strlen
(
$File
) - 4 ), 4) !==
'.php'
) {
continue
;
}
$Content
=
file_get_contents
(
$Path
.
$File
);
$Content
= preg_replace(
'/(<!--(.*)-->)/Us'
,
''
,
$Content
);
$Content
= preg_replace(
'/<\?php(.*)\?>/'
,
''
,
$Content
);
$Content
=
strip_tags
(
$Content
);
$Matches
= NULL;
$File
=
str_replace
(
'.php'
,
''
,
$File
);
if
( preg_match_all(
'/('
.
$Search
.
')/Uis'
,
$Content
,
$Matches
) || ( isset(
$_REQUEST
[
'fn'
]) && preg_match_all(
'/('
.
$Search
.
')/Uis'
,
$File
) ) ) {
$Content
=
substr
(
$Content
, 0, 255);
$Content
= isset(
$_REQUEST
[
'b'
]) ? preg_replace(
'/('
.
$Search
.
')/Uis'
,
'<b>\1</b>'
,
$Content
) :
$Content
;
$Filename
= isset(
$_REQUEST
[
'b'
]) && isset(
$_REQUEST
[
'fn'
]) ? preg_replace(
'/('
.
$Search
.
')/Uis'
,
'<b>\1</b>'
,
$File
) :
$File
;
$Output
[
$File
] =
$Content
;
echo
'<div class="search_result"><div class="search_info"><b>Datei</b>: <a href="index.php?'
.
$File
.
'">'
.
$Filename
.
'</a>; <b>Treffer</b>: '
.
count
(
$Matches
) .
'</div><div class="search_text" style="padding-left: 25px;">'
.
$Content
.
'</div></div><br />'
;
}
}
$MatchesCount
=
count
(
$Output
);
echo
'<br /><hr />'
;
echo
'<b>Anzahl der Treffer</b>: '
.
$MatchesCount
;
}
$Design
->footer();
?>