Конечный вариант с поиском по комментариях тем,постов,профилей пользователей,описаний тем с учетом прав доступа и не срабатывании при пустом поле поиска, работает отлично:
Код: Выделить всё
<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup(array('posting', 'search','mods/searchinlang'));
//$bb_code = request_var('bbc', '');
$submit = request_var('submit', false);
$submit2 = request_var('submit2', false);
$submit3 = request_var('submit3', false);
$start = request_var('s', 0);
$term = request_var('term', '', true);
$term2 = request_var('term2', '', true);
$term3 = request_var('term3', '', true);
global $config, $phpbb_root_path, $phpEx, $template, $db, $user, $cache, $auth;
if ($submit)
{
if($auth->acl_get('u_seecom'))
{
$sql = 'SELECT * FROM '. COMMENTS_TABLE .' WHERE text '.$db-> sql_like_expression( $db-> any_char. $term . $db-> any_char ).' COLLATE utf8_general_ci';
$result = $db->sql_query($sql);
if ($term != '')
{
while ($row = $db->sql_fetchrow($result))
{
$text = generate_text_for_display($row['text'], $row['bbcode_uid'], $row['bbcode_bitfield'], $row['bbcode_options']);
$template->assign_block_vars('row', array(
'COMMENT_ID' => $row['id'],
'POST_ID' => $row['post_id'],
'POST_URL' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'p=' . $row['post_id'] . '#p' . $row['post_id']),
'COMMENT' => censor_text($text),
'COMMENT_TIME' => $user->format_date($row['comment_time']),
));
}
}
}
}
if ($submit2)
{
if ($auth->acl_get('u_viewprofile'))
{
$sql = 'SELECT * FROM '. WALL_TABLE .' WHERE wall_text '.$db-> sql_like_expression( $db-> any_char. $term2 . $db-> any_char ).'COLLATE utf8_general_ci';
$result = $db->sql_query($sql);
if ($term2 != '')
{
while ($row2 = $db->sql_fetchrow($result))
{
$template->assign_block_vars('row2', array(
'U_USER' => append_sid("{$phpbb_root_path}memberlist.$phpEx","mode=viewprofile&u=".$row2['wall_user_id']),
'U_POSTER' => append_sid("{$phpbb_root_path}memberlist.$phpEx","mode=viewprofile&u=".$row2['wall_poster_id']),
'WALL_USER_ID' => $row2['wall_user_id'],
'WALL_POSTER_ID' => $row2['wall_poster_id'],
'WALL_COMMENT_TEXT' => censor_text($row2['wall_text']),
'WALL_COMMENT_TIME' => $user->format_date($row2['wall_time']),
));
}
}
}
}
if ($submit3)
{
$sql = 'SELECT * FROM '. TOPICS_TABLE .' WHERE topic_desc '.$db-> sql_like_expression( $db-> any_char. $term3 . $db-> any_char ).'COLLATE utf8_general_ci';
$result = $db->sql_query($sql);
if ($term3 != '')
{
while ($row3 = $db->sql_fetchrow($result))
{
if($auth->acl_get('f_read',$row3['forum_id']))
{
$template->assign_block_vars('row3', array(
'U_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $row3['topic_id'] ),
'U_POSTER' => append_sid("{$phpbb_root_path}memberlist.$phpEx","mode=viewprofile&u=".$row3['topic_poster']),
'TOPIC_POSTER_ID' => $row3['topic_poster'],
'TOPIC_DESC' => censor_text(parse_topic_desc($row3['topic_desc'])),
'TOPIC_TITLE' => censor_text($row3['topic_title']),
'TOPIC_TIME' => $user->format_date($row3['topic_time']),
));
}
}
}
}
$template->assign_vars(array(
'S_ACTION' => append_sid("{$phpbb_root_path}searchin.$phpEx"),
));
// Output the page
page_header($user->lang['SEARCH_IN']);
$template->set_filenames(array(
'body' => 'searchin.html')
);
page_footer();
?>
Код: Выделить всё
<!-- INCLUDE overall_header.html -->
<form action="{S_ACTION}" method="post">
<table class="tablebg" width="100%" cellspacing="1" cellpadding="4" border="0">
<tr>
<td class="row1" width="30%">
<b><a id="SCTP">{L_SEARCH_IN_COMMENTS_OF_TOPICS_AND_POSTS}:</a> </b>
</td>
<td class="row1">
<input type="text" name="term" size="35" /><input type="submit" name="submit" value="{L_SUBMIT}" class="btnmain"/>
</td>
</tr>
<tr>
<td class="row1">
<b><a id="SCUP">{L_SEARCH_IN_COMMENTS_OF_USERS_PROFILES}:</a> </b>
</td>
<td class="row1">
<input type="text" name="term2" size="35"/><input type="submit" name="submit2" value="{L_SUBMIT}" class="btnmain"/>
</td>
</tr>
<tr>
<td class="row1">
<b><a id="STD">{L_SEARCH_BY_TOPIC_DESCRIPTION}:</a> </b>
</td>
<td class="row1">
<input type="text" name="term3" size="35"/><input type="submit" name="submit3" value="{L_SUBMIT}" class="btnmain"/>
</td>
</tr>
</table>
</form>
<!-- IF not S_IS_BOT and S_USER_LOGGED_IN -->
<!-- IF .row -->
<table class="tablebg" width="100%" cellspacing="1" cellpadding="4" border="0">
<tr>
<th width="80px">{L_COMMENT_ID}</th>
<th width="80px" >{L_POST_ID}</th>
<th >{L_COMMENT}</th>
<th width="140px" >{L_COMMENT_TIME}</th>
</tr>
<!-- BEGIN row -->
<tr>
<td class="row1" align="center">{row.COMMENT_ID}</td>
<td class="row1" align="center"><a href="{row.POST_URL}" target="_blank">{row.POST_ID}</a></td>
<td class="row1" >{row.COMMENT}</td>
<td class="row1" align="center"><b>{row.COMMENT_TIME}</b></td>
</tr>
<!-- END row -->
</table>
<!-- ENDIF -->
<!-- IF .row2 -->
<table class="tablebg" width="100%" cellspacing="1" cellpadding="4" border="0">
<tr>
<th width="80px">{L_WALL_USER_ID}</th>
<th width="80px" >{L_WALL_POSTER_ID}</th>
<th >{L_WALL_COMMENT}</th>
<th width="140px" >{L_WALL_COMMENT_TIME}</th>
</tr>
<!-- BEGIN row2 -->
<tr>
<td class="row1" align="center"><a href="{row2.U_USER}" target="_blank"> {row2.WALL_USER_ID}</a></td>
<td class="row1" align="center"><a href="{row2.U_POSTER}" target="_blank">{row2.WALL_POSTER_ID}</a></td>
<td class="row1" >{row2.WALL_COMMENT_TEXT}</td>
<td class="row1" align="center"><b>{row2.WALL_COMMENT_TIME}</b></td>
</tr>
<!-- END row2 -->
</table>
<!-- ENDIF -->
<!-- IF .row3 -->
<table class="tablebg" width="100%" cellspacing="1" cellpadding="4" border="0">
<tr>
<th >{L_TOPIC_TITLE}</th>
<th >{L_TOPIC_DESC}</th>
<th width="140px">{L_TOPIC_POSTER}</th>
<th width="140px" >{L_TOPIC_TIME}</th>
</tr>
<!-- BEGIN row3 -->
<tr>
<td class="row1" ><a href="{row3.U_TOPIC}" target="_blank"> {row3.TOPIC_TITLE}</a></td>
<td class="row1" >{row3.TOPIC_DESC}</td>
<td class="row1" align="center"><a href="{row3.U_POSTER}" target="_blank">{row3.TOPIC_POSTER_ID}</a></td>
<td class="row1" align="center"><b>{row3.TOPIC_TIME}</b></td>
</tr>
<!-- END row3 -->
</table>
<!-- ENDIF -->
<!-- ENDIF -->
{L_SEARCH_IN_ACCESS}
<!-- INCLUDE overall_footer.html -->