mirror of
https://github.com/e107inc/e107.git
synced 2025-08-22 14:13:03 +02:00
Search Fixes. Forum search upgraded to v2.x spec.
This commit is contained in:
@@ -4,10 +4,143 @@ if (!defined('e107_INIT')) { exit(); }
|
||||
e107::lan('forum', "search", true);
|
||||
//include_lan(e_PLUGIN.'forum/languages/'.e_LANGUAGE.'/'.e_LANGUAGE.'_search.php');
|
||||
|
||||
class forum_search extends e_search // include plugin-folder in the name.
|
||||
{
|
||||
|
||||
function config()
|
||||
{
|
||||
|
||||
$sql = e107::getDb();
|
||||
$catList = array();
|
||||
|
||||
$catList[] = array('id' => 'all', 'title' => LAN_PLUGIN_FORUM_ALLFORUMS);
|
||||
|
||||
if ($sql ->gen("SELECT f.forum_id, f.forum_name FROM #forum AS f LEFT JOIN #forum AS fp ON fp.forum_id = f.forum_parent "))
|
||||
{
|
||||
while($row = $sql->fetch())
|
||||
{
|
||||
$catList[] = array('id' => $row['forum_id'], 'title' => $row['forum_name']);
|
||||
}
|
||||
}
|
||||
|
||||
$matchList = array(
|
||||
0 => array('id' => 0, 'title' => FOR_SCH_LAN_4),
|
||||
1 => array('id' => 1, 'title' => LAN_SEARCH_54)
|
||||
);
|
||||
|
||||
$search = array(
|
||||
'name' => LAN_PLUGIN_FORUM_NAME,
|
||||
// 'table' => 'forum',
|
||||
'table' => 'forum_thread AS t LEFT JOIN #user AS u ON t.thread_user = u.user_id
|
||||
LEFT JOIN #forum AS f ON t.thread_forum_id = f.forum_id
|
||||
LEFT JOIN #forum AS fp ON f.forum_parent = fp.forum_id
|
||||
LEFT JOIN #forum_post AS p ON p.post_thread = t.thread_id',
|
||||
|
||||
'advanced' => array(
|
||||
'forum' => array('type' => 'dropdown', 'text' => FOR_SCH_LAN_2, 'list'=>$catList),
|
||||
'date' => array('type' => 'date', 'text' => LAN_DATE_POSTED),
|
||||
'author'=> array('type' => 'author', 'text' => LAN_SEARCH_61),
|
||||
'match'=> array('type' => 'dropdown', 'text' => LAN_SEARCH_61, 'list'=>$matchList)
|
||||
),
|
||||
|
||||
'return_fields' => array('t.thread_id', 't.thread_name', 'p.post_id', 'p.post_entry', 't.thread_forum_id', 't.thread_datestamp', 't.thread_user', 'u.user_id', 'u.user_name', 'f.forum_class', 'f.forum_id', 'f.forum_name', 'f.forum_sef'),
|
||||
'search_fields' => array('t.thread_name'=>'1.2', 'p.post_entry'=>'0.6'), // fields and weights.
|
||||
|
||||
'order' => array('thread_datestamp' => DESC),
|
||||
'refpage' => 'forum'
|
||||
);
|
||||
|
||||
|
||||
return $search;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Compile Database data for output */
|
||||
function compile($row)
|
||||
{
|
||||
$tp = e107::getParser();
|
||||
|
||||
|
||||
|
||||
$res = array();
|
||||
|
||||
/* $res['link'] = e_PLUGIN."chatbox_menu/chat.php?".$row['cb_id'].".fs";
|
||||
$res['pre_title'] = LAN_SEARCH_7;
|
||||
$res['title'] = $user[2];
|
||||
$res['summary'] = $row['cb_message'];
|
||||
$res['detail'] = $tp->toDate($row['cb_datestamp'], "long");*/
|
||||
|
||||
$datestamp = $tp->toDate($row['thread_datestamp'], "long");
|
||||
|
||||
if ($row['thread_parent'])
|
||||
{
|
||||
$title = $row['parent_name'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$title = $row['thread_name'];
|
||||
}
|
||||
|
||||
$link_id = $row['thread_id'];
|
||||
|
||||
//<a href='user.php?id.".$row['user_id']."'>".$row['user_name']."</a>
|
||||
$uparams = array('id' => $row['user_id'], 'name' => $row['user_name']);
|
||||
$link = e107::getUrl()->create('user/profile/view', $uparams);
|
||||
$userlink = "<a href='".$link."'>".$row['user_name']."</a>";
|
||||
|
||||
$row['thread_sef'] = eHelper::title2sef($row['thread_name'],'dashl');
|
||||
|
||||
$res['link'] = e107::url('forum','topic', $row, array('query'=>array('f'=>'post','id'=>$row['post_id']))); // e_PLUGIN."forum/forum_viewtopic.php?".$link_id.".post";
|
||||
$res['pre_title'] = $title ? FOR_SCH_LAN_5.": " : "";
|
||||
$res['title'] = $title ? $title : LAN_SEARCH_9;
|
||||
$res['pre_summary'] = "<div class='smalltext'><a href='".e107::url('forum','forum',$row)."'>".$row['forum_name']."</a></div>";
|
||||
$res['summary'] = $row['post_entry'];
|
||||
$res['detail'] = LAN_SEARCH_7.$userlink.LAN_SEARCH_8.$datestamp;
|
||||
|
||||
return $res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Optional - Advanced Where
|
||||
* @param $parm - data returned from $_GET (ie. advanced fields included. in this case 'date' and 'author' )
|
||||
*/
|
||||
function where($parm='')
|
||||
{
|
||||
$tp = e107::getParser();
|
||||
|
||||
$qry = " f.forum_parent != 0 AND fp.forum_class IN (".USERCLASS_LIST.") AND f.forum_class IN (".USERCLASS_LIST.") AND ";
|
||||
|
||||
if (!empty($parm['forum']) && is_numeric($parm['forum']))
|
||||
{
|
||||
$qry .= " f.forum_id='".$parm['forum']."' AND";
|
||||
}
|
||||
|
||||
if (!empty($parm['time']) && is_numeric($parm['time']))
|
||||
{
|
||||
$qry .= " t.thread_datestamp ".($parm['on'] == 'new' ? '>=' : '<=')." '".(time() - $parm['time'])."' AND";
|
||||
}
|
||||
|
||||
if (!empty($parm['author']))
|
||||
{
|
||||
$qry .= " (u.user_id = '".$tp -> toDB($parm['author'])."' OR u.user_name = '".$tp -> toDB($parm['author'])."') AND";
|
||||
}
|
||||
|
||||
return $qry;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
$search_info[] = array(
|
||||
'sfile' => e_PLUGIN.'forum/search/search_parser.php',
|
||||
'qtype' => LAN_PLUGIN_FORUM_NAME,
|
||||
'refpage' => 'forum',
|
||||
'advanced' => e_PLUGIN.'forum/search/search_advanced.php',
|
||||
'id' => 'forum'
|
||||
);
|
||||
);*/
|
||||
|
@@ -829,8 +829,16 @@ class e107ForumThread
|
||||
$postInfo = $forum->postGet($postId,'post');
|
||||
$postNum = $forum->postGetPostNum($postInfo['post_thread'], $postId);
|
||||
$postPage = ceil($postNum / $forum->prefs->get('postspage'));
|
||||
$url = e107::getUrl()->create('forum/thread/view', array('id' => $postInfo['post_thread'], 'name' => $postInfo['thread_name'], 'page' => $postPage), 'full=1&encode=0');
|
||||
header('location: '.$url);
|
||||
|
||||
$url = e107::url('forum', 'topic', $postInfo, array(
|
||||
'query' => array(
|
||||
'p' => $postPage, // proper page number
|
||||
),
|
||||
'fragment' => 'post-' . $postId, // jump page to post
|
||||
'mode'=>'full'
|
||||
));
|
||||
|
||||
e107::redirect($url);
|
||||
exit;
|
||||
break;
|
||||
|
||||
|
@@ -90,7 +90,10 @@ if($results = $sql->gen($qry))
|
||||
),
|
||||
'fragment' => 'post-' . $row['post_id'], // jump page to post
|
||||
));
|
||||
|
||||
|
||||
//FIXME Use f=post/id query.
|
||||
|
||||
|
||||
$text .= "<li>";
|
||||
|
||||
if ($menu_pref['newforumposts_title'])
|
||||
|
@@ -1,44 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* e107 website system
|
||||
*
|
||||
* Copyright (C) 2008-2009 e107 Inc (e107.org)
|
||||
* Released under the terms and conditions of the
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
||||
*
|
||||
*
|
||||
*
|
||||
* $Source: /cvs_backup/e107_0.8/e107_plugins/forum/search/search_advanced.php,v $
|
||||
* $Revision$
|
||||
* $Date$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
if (!defined('e107_INIT')) { exit; }
|
||||
|
||||
$advanced['forum']['type'] = 'dropdown';
|
||||
$advanced['forum']['text'] = FOR_SCH_LAN_2.':';
|
||||
$advanced['forum']['list'][] = array('id' => 'all', 'title' => LAN_PLUGIN_FORUM_ALLFORUMS);
|
||||
|
||||
$advanced_caption['id'] = 'forum';
|
||||
$advanced_caption['title']['all'] = LAN_PLUGIN_FORUM_ALLFORUMS;
|
||||
|
||||
if ($sql -> db_Select_gen("SELECT f.forum_id, f.forum_name FROM #forum AS f LEFT JOIN #forum AS fp ON fp.forum_id = f.forum_parent WHERE f.forum_parent != 0 AND fp.forum_class IN (".USERCLASS_LIST.") AND f.forum_class IN (".USERCLASS_LIST.")")) {
|
||||
while ($row = $sql -> db_Fetch()) {
|
||||
$advanced['forum']['list'][] = array('id' => $row['forum_id'], 'title' => $row['forum_name']);
|
||||
$advanced_caption['title'][$row['forum_id']] = LAN_PLUGIN_FORUM_NAME.' -> '.$row['forum_name'];
|
||||
}
|
||||
}
|
||||
|
||||
$advanced['date']['type'] = 'date';
|
||||
$advanced['date']['text'] = LAN_DATE_POSTED.':';
|
||||
|
||||
$advanced['author']['type'] = 'author';
|
||||
$advanced['author']['text'] = LAN_SEARCH_61.':';
|
||||
|
||||
$advanced['match']['type'] = 'dropdown';
|
||||
$advanced['match']['text'] = LAN_SEARCH_52.':';
|
||||
$advanced['match']['list'][] = array('id' => 0, 'title' => FOR_SCH_LAN_4);
|
||||
$advanced['match']['list'][] = array('id' => 1, 'title' => LAN_SEARCH_54);
|
||||
|
||||
?>
|
@@ -1,80 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* e107 website system
|
||||
*
|
||||
* Copyright (C) 2008-2013 e107 Inc (e107.org)
|
||||
* Released under the terms and conditions of the
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
||||
*
|
||||
*/
|
||||
|
||||
if (!defined('e107_INIT')) { exit; }
|
||||
|
||||
// advanced
|
||||
$advanced_where = "";
|
||||
if (isset($_GET['forum']) && is_numeric($_GET['forum'])) {
|
||||
$advanced_where .= " f.forum_id='".$_GET['forum']."' AND";
|
||||
}
|
||||
|
||||
if (isset($_GET['time']) && is_numeric($_GET['time'])) {
|
||||
$advanced_where .= " t.thread_datestamp ".($_GET['on'] == 'new' ? '>=' : '<=')." '".(time() - $_GET['time'])."' AND";
|
||||
}
|
||||
|
||||
if (isset($_GET['author']) && $_GET['author'] != '') {
|
||||
$advanced_where .= " (u.user_id = '".$tp -> toDB($_GET['author'])."' OR u.user_name = '".$tp -> toDB($_GET['author'])."') AND";
|
||||
}
|
||||
|
||||
if (isset($_GET['match']) && $_GET['match']) {
|
||||
$search_fields = array('t.thread_name');
|
||||
} else {
|
||||
$search_fields = array('t.thread_name', 'p.post_entry');
|
||||
}
|
||||
|
||||
// basic
|
||||
$return_fields = 't.thread_id, t.thread_name, p.post_entry, t.thread_forum_id, t.thread_datestamp, t.thread_user, u.user_id, u.user_name, f.forum_class, f.forum_id, f.forum_name';
|
||||
$weights = array('1.2', '0.6');
|
||||
$no_results = LAN_198;
|
||||
|
||||
$where = "f.forum_class REGEXP '".e_CLASS_REGEXP."' AND fp.forum_class REGEXP '".e_CLASS_REGEXP."' AND".$advanced_where;
|
||||
$order = array('thread_datestamp' => DESC);
|
||||
$table = "forum_thread AS t LEFT JOIN #user AS u ON t.thread_user = u.user_id
|
||||
LEFT JOIN #forum AS f ON t.thread_forum_id = f.forum_id
|
||||
LEFT JOIN #forum AS fp ON f.forum_parent = fp.forum_id
|
||||
LEFT JOIN #forum_post AS p ON p.post_thread = t.thread_id
|
||||
|
||||
";
|
||||
|
||||
$ps = $sch -> parsesearch($table, $return_fields, $search_fields, $weights, 'search_forum', $no_results, $where, $order);
|
||||
$text .= $ps['text'];
|
||||
$results = $ps['results'];
|
||||
|
||||
function search_forum($row)
|
||||
{
|
||||
global $con;
|
||||
$datestamp = $con -> convert_date($row['thread_datestamp'], "long");
|
||||
if ($row['thread_parent'])
|
||||
{
|
||||
$title = $row['parent_name'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$title = $row['thread_name'];
|
||||
}
|
||||
|
||||
$link_id = $row['thread_id'];
|
||||
|
||||
//<a href='user.php?id.".$row['user_id']."'>".$row['user_name']."</a>
|
||||
$uparams = array('id' => $row['user_id'], 'name' => $row['user_name']);
|
||||
$link = e107::getUrl()->create('user/profile/view', $uparams);
|
||||
$userlink = "<a href='".$link."'><b>".$row['user_name']."</b></a>";
|
||||
$res['link'] = e_PLUGIN."forum/forum_viewtopic.php?".$link_id.".post";
|
||||
$res['pre_title'] = $title ? FOR_SCH_LAN_5.": " : "";
|
||||
$res['title'] = $title ? $title : LAN_SEARCH_9;
|
||||
$res['pre_summary'] = "<div class='smalltext' style='padding: 2px 0px'><a href='".e_PLUGIN."forum/forum.php'>".LAN_PLUGIN_FORUM_NAME."</a> -> <a href='".e_PLUGIN."forum/forum_viewforum.php?".$row['forum_id']."'>".$row['forum_name']."</a></div>";
|
||||
$res['summary'] = $row['post_entry'];
|
||||
$res['detail'] = LAN_SEARCH_7.$userlink.LAN_SEARCH_8.$datestamp;
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user