<?php
# Copyright by: Manuel Staechele
# Support: www.ilch.de
defined (
'main'
)
or
die
(
'no direct access'
);
function
getmicrotime() {
list(
$usec
,
$sec
) =
explode
(
" "
,microtime());
return
((float)
$usec
+ (float)
$sec
);
}
$search_time_start
= getmicrotime();
function
search_mark(
$text
,
$such
) {
#
$text
= BBcode(
$text
);
$serar
=
explode
(
' '
,
$such
);
$text
=
strip_tags
(
$text
);
$text
=
stripslashes
(
$text
);
$rte
=
''
;
$tleng
= 30;
foreach
(
$serar
as
$v
) {
$firs
=
strpos
(
strtolower
(
$text
),
strtolower
(
$v
));
$begi
= ((
$firs
-
$tleng
) < 0 ? 0 :
$firs
-
$tleng
);
$leng
=
strlen
(
$text
);
$ende
= ((
$firs
+
strlen
(
$v
) +
$tleng
) >
$leng
?
$leng
:
$firs
+
strlen
(
$v
) +
$tleng
);
$ttxt
=
substr
(
$text
,
$begi
,(
$ende
-
$begi
));
$rte
.=
' ... '
.preg_replace(
"/"
.
$v
.
"/si"
,
'<b>'
.
$v
.
'</b>'
,
$ttxt
);
}
return
(
$rte
);
}
function
texts_escape_name (
$n
) {
$n
=
strtolower
(
$n
);
$n
= preg_replace(
"/[^a-z0-9\ ]/"
,
""
,
$n
);
$n
= preg_replace(
"/\s+/"
,
"-"
,
$n
);
return
(
$n
);
}
function
search_finduser() {
$tpl
=
new
tpl (
'search_finduser'
);
$tpl
->out(0);
if
( isset (
$_POST
[
'sub'
] ) AND !
empty
(
$_POST
[
'name'
]) ) {
$name
=
str_replace
(
'*'
,
"%"
, escape(
$_POST
[
'name'
],
'string'
));
$q
=
"SELECT name,name FROM prefix_user WHERE name like '"
.
$name
.
"'"
;
$tpl
->set (
'username'
,dbliste(
''
,
$tpl
,
'username'
,
$q
));
$tpl
->out(1);
}
$tpl
->out(2);
}
$such
=
''
;
if
(
$menu
->get(1) !=
''
) {
$such
=
$menu
->get(1);
}
elseif
(isset(
$_REQUEST
[
'search'
])) {
$such
=
$_REQUEST
[
'search'
];
}
$such
= escape(
$such
,
'string'
);
$page
= 1;
if
(isset(
$_GET
[
'page'
]) AND preg_match(
"/^-p\d+$/"
,
$_GET
[
'page'
])) {
$page
=
str_replace
(
'-p'
,
''
,
$_GET
[
'page'
]);
}
$limit
=
$allgAr
[
'Fpanz'
];
$anfang
= (
$page
- 1) *
$limit
;
if
(
$menu
->get(1) ==
'finduser'
) {
$design
=
new
design (
'Finduser'
,
''
, 0 );
$design
->header();
search_finduser();
$design
->footer(1);
}
if
(
$such
==
'augt'
OR
$such
==
'aeit'
OR
$such
==
'aubt'
) {
include
'include/contents/forum/search.php'
;
exit
;
}
$snac
=
'Suche'
;
if
( isset(
$_REQUEST
[
'search'
]) ) {
$snac
=
'nach: '
.
stripslashes
(
$such
);
}
$opts
=
array
(
'search_forum'
=> 1,
'search_news'
=> 0,
'search_texts'
=> 1,
'search_downloads'
=> 0,
'sort_datum'
=> 0,
'sort_relevanz'
=> 1,
'opt_own'
=> 0,
'opt_titel'
=> 0,
'opt_oldposts'
=> 0
);
foreach
(
$opts
as
$k
=>
$v
) {
if
(isset(
$_GET
[
$k
]) AND (
$_GET
[
$k
] == 0 OR
$_GET
[
$k
] == 1)) {
$opts
[
$k
] =
$_GET
[
$k
];
}
}
$title
=
$allgAr
[
'title'
].
' :: Suchen :: '
.htmlentities(
$snac
);
$hmenu
=
array
(
array
(
'?search'
=>
'Suchen'
), htmlentities(
$snac
));
$design
=
new
design (
$title
,
$hmenu
);
$design
->header();
$tpl
=
new
tpl (
'search'
);
$tpl
->set (
'size'
, 30);
foreach
(
$opts
as
$k
=>
$v
) {
$tpl
->set(
$k
,
$v
);
}
$tpl
->set_out(
'search'
,escape_for_fields(
stripslashes
(
$such
)),0);
if
(
empty
(
$such
)) {
$design
->footer(1);
}
function
search_get_sort(
$sorts
,
$opts
) {
$sort
=
''
;
if
(
$opts
[
'sort_datum'
] == 1 ||
$opts
[
'sort_relevanz'
] == 1) {
if
(
$opts
[
'sort_datum'
] == 1) {
$sort
.=
$sorts
[
'sort_datum'
];
}
if
(
$opts
[
'sort_relevanz'
] == 1) {
if
(!
empty
(
$sort
)) {
$sort
.=
", "
;
}
$sort
.=
$sorts
[
'sort_relevanz'
];
}
$sort
=
" ORDER BY "
.
$sort
;
}
return
$sort
;
}
function
search_news(
$such
,
$opts
) {
$sorts
=
array
(
'sort_datum'
=>
"time DESC"
,
'sort_relevanz'
=>
"match(news_title, news_text) against ('"
.
$such
.
"') DESC"
,
);
$query_news
= "SELECT
news_title
as
titel,
news_id
as
id,
news_time
as
time
FROM prefix_news
WHERE match(news_title, news_text) against (
'".$such."'
IN BOOLEAN MODE)";
$query_news
.= search_get_sort(
$sorts
,
$opts
);
$e
= db_query(
$query_news
)
or
die
(mysql_error());
$anzahl
= db_num_rows(
$e
);
if
(
$anzahl
== 0) {
echo
'0 Treffer'
;
return
false;
}
echo
$anzahl
.
' Treffer<table id="search_table_news" style="display: none;">'
;
while
(
$r
= db_fetch_assoc(
$e
)) {
echo
'<tr>'
;
echo
'<td><a href="news-'
.
$r
[
'id'
].
'.html">'
.
$r
[
'titel'
].
'</a></td>'
;
echo
'</tr>'
;
}
echo
'</table>'
;
return
$anzahl
;
}
function
search_forum(
$such
,
$opts
) {
$sorts
=
array
(
'sort_datum'
=>
"prefix_posts.time DESC"
,
'sort_relevanz'
=>
"match(txt) against ('"
.
$such
.
"') DESC"
,
);
$query_forum
= "SELECT
prefix_topics.fid
as
fid,
prefix_topics.name
as
titel,
prefix_forums.name
as
fname,
prefix_topics.id
as
id,
prefix_posts.time
as
time,
prefix_posts.id
as
pid,
prefix_posts.tpos,
match(txt) against (
'".$such."'
)
as
relevanz
FROM prefix_posts
LEFT JOIN prefix_topics ON prefix_topics.id = prefix_posts.tid
LEFT JOIN prefix_forums ON prefix_forums.id = prefix_topics.fid";
$query_forum
.=
" WHERE (prefix_forums.view >= "
.
$_SESSION
[
'authright'
].
" OR prefix_forums.reply >= "
.
$_SESSION
[
'authright'
].
" OR prefix_forums.start >= "
.
$_SESSION
[
'authright'
].
") "
.(
$opts
[
'opt_oldposts'
] == 0 ?
' AND prefix_posts.time > UNIX_TIMESTAMP(TIMESTAMPADD(YEAR, -1, NOW())) '
:
''
)."
AND match(txt) against (
'".$such."'
IN BOOLEAN MODE)";
if
(
$opts
[
'opt_own'
] == 1) {
$query_forum
.=
"AND prefix_posts.erstid = "
.
$_SESSION
[
'authid'
];
}
$query_forum
.=
" GROUP BY prefix_topics.id"
;
$query_forum
.= search_get_sort(
$sorts
,
$opts
);
$query_forum
.=
" LIMIT 100"
;
echo
'<!-- '
.
$query_forum
.
' -->'
;
$e
= db_query(
$query_forum
)
or
die
(mysql_error());
$anzahl
= db_num_rows(
$e
);
if
(
$anzahl
== 0) {
echo
'0 Treffer'
;
return
false;
}
echo
$anzahl
.
' Treffer<div id="search_table_forum" style="display: none;"><table cellpadding="4" cellspacing="1" class="border">'
;
echo
'<tr class="Cdark"><th>Relevanz</th><th>Datum</th><th>Thema</th></tr>'
;
while
(
$r
= db_fetch_assoc(
$e
)) {
echo
'<tr class="Cmite">'
;
echo
'<td>'
.
round
(
$r
[
'relevanz'
],2).
'</td>'
;
echo
'<td>'
.
date
(
'd. M Y'
,
$r
[
'time'
]).
'</td>'
;
echo
'<td><a href="forum-showposts-'
.
$r
[
'id'
].
'.html#'
.
$r
[
'pid'
].
'">'
.
$r
[
'titel'
].
'</a></td>'
;
echo
'</tr>'
;
}
echo
'</table></div>'
;
return
$anzahl
;
}
function
search_texts(
$such
,
$opts
) {
$sorts
=
array
(
'sort_datum'
=>
"datum DESC"
,
'sort_relevanz'
=>
"match(`name`,`text`) against ('"
.
$such
.
"') DESC"
,
);
$query_texts
= "SELECT
name AS titel,
id,
UNIX_TIMESTAMP(datum)
as
time
FROM prefix_texts
WHERE match(`name`,`text`) against (
'".$such."'
IN BOOLEAN MODE)";
$query_texts
.= search_get_sort(
$sorts
,
$opts
);
$e
= db_query(
$query_texts
)
or
die
(mysql_error());
$anzahl
= db_num_rows(
$e
);
if
(
$anzahl
== 0) {
echo
'0 Treffer'
;
return
false;
}
echo
$anzahl
.
' Treffer<table id="search_table_texts" style="display: none;">'
;
while
(
$r
= db_fetch_assoc(
$e
)) {
echo
'<tr>'
;
echo
'<td><a href="texts-s'
.
$r
[
'id'
].
'-'
.texts_escape_name(
$r
[
'titel'
]).
'.html">'
.
$r
[
'titel'
].
'</a></td>'
;
echo
'</tr>'
;
}
echo
'</table>'
;
return
$anzahl
;
}
function
search_downloads(
$such
,
$opts
) {
$sorts
=
array
(
'sort_datum'
=>
"time DESC"
,
'sort_relevanz'
=>
" match(`descl`,`desc`,`name`,`version`) against ('"
.
$such
.
"') DESC"
,
);
$query_downloads
= "SELECT
CONCAT( name,
' '
, version ) AS titel,
id,
UNIX_TIMESTAMP(time)
as
time
FROM prefix_downloads
WHERE match(`descl`,`desc`,`name`,`version`) against (
'".$such."'
IN BOOLEAN MODE)";
$query_downloads
.= search_get_sort(
$sorts
,
$opts
);
$e
= db_query(
$query_downloads
)
or
die
(mysql_error());
$anzahl
= db_num_rows(
$e
);
if
(
$anzahl
== 0) {
echo
'0 Treffer'
;
return
false;
}
echo
$anzahl
.
' Treffer<table id="search_table_downloads" style="display: none;">'
;
while
(
$r
= db_fetch_assoc(
$e
)) {
echo
'<tr>'
;
echo
'<td><a href="downloads-show-'
.
$r
[
'id'
].
'.html">'
.
$r
[
'titel'
].
'</a></td>'
;
echo
'</tr>'
;
}
echo
'</table>'
;
return
$anzahl
;
}
$oneOpen
= false;
$toOpen
=
''
;
if
(
$opts
[
'search_forum'
] == 1) {
echo
'<fieldset><legend><a href="javascript:show_search_table(\'forum\');">Forum</a></legend>'
;
$anz
= search_forum(
$such
,
$opts
);
echo
'</fieldset>'
;
if
(!
$oneOpen
and
$anz
) {
$toOpen
=
'forum'
;
$oneOpen
= true;
}
}
if
(
$opts
[
'search_texts'
] == 1) {
echo
'<fieldset><legend><a href="javascript:show_search_table(\'texts\');">Texts</a></legend>'
;
$anz
= search_texts(
$such
,
$opts
);
echo
'</fieldset>'
;
if
(!
$oneOpen
and
$anz
) {
$toOpen
=
'texts'
;
$oneOpen
= true;
}
}
if
(
$opts
[
'search_downloads'
] == 1) {
echo
'<fieldset><legend><a href="javascript:show_search_table(\'downloads\');">Downloads</a></legend>'
;
$anz
= search_downloads(
$such
,
$opts
);
echo
'</fieldset>'
;
if
(!
$oneOpen
and
$anz
) {
$toOpen
=
'downloads'
;
$oneOpen
= true;
}
}
if
(
$opts
[
'search_news'
] == 1) {
echo
'<fieldset><legend><a href="javascript:show_search_table(\'news\');">News</a></legend>'
;
$anz
= search_news(
$such
,
$opts
);
echo
'</fieldset>'
;
if
(!
$oneOpen
and
$anz
) {
$toOpen
=
'news'
;
$oneOpen
= true;
}
}
echo
<<<HTML
<script>
$(document).ready(
function
() {
var
first_search_table =
'{$toOpen}'
;
if
(first_search_table !=
''
) { show_search_table(first_search_table); }
});
</script>
HTML;
$design
->footer();
?>