XOOPSの検索結果に本文から検索キーワードの周辺を抜粋して表示する改造です。
ただし、XOOPS本体の改造に加えてモジュール側での対応も必要になります。
変更の必要なファイルをZIPにしました。ダウンロード⇒
search_context_for_206j.zip
※ユーザー情報のテンプレートとスタイルシートは含まれていませんので、下記を参考に適宜変更してください。
HypCommonFunc Class のページを参考にして、XOOPSにHypCommonFunc Class を組み込む。
155行目あたりと213行目あたりの
echo "</small><br />\n";
の下に以下を挿入(2箇所)
if (!empty($results[$i]['context']))
{
echo "<div class=\"context\">".$results[$i]['context']."</div>";
}
以上でXOOPS本体側の改造は終わりです。
次はモジュール側です。
Function全体を記しておきます。DL(右クリックで保存)⇒
search.inc.php
function newbb_search($queryarray, $andor, $limit, $offset, $userid){
global $xoopsDB;
$sql = "SELECT p.post_id,p.topic_id,p.forum_id,p.post_time,p.uid,p.subject,p.nohtml,p.nosmiley,t.post_text FROM ".$xoopsDB->prefix("bb_posts")." p LEFT JOIN ".$xoopsDB->prefix("bb_posts_text")." t ON t.post_id=p.post_id LEFT JOIN ".$xoopsDB->prefix("bb_forums")." f ON f.forum_id=p.forum_id WHERE f.forum_type=0";
if ( $userid != 0 ) {
$sql .= " AND p.uid=".$userid." ";
}
// because count() returns 1 even if a supplied variable
// is not an array, we must check if $querryarray is really an array
if ( is_array($queryarray) && $count = count($queryarray) ) {
$sql .= " AND ((p.subject LIKE '%$queryarray[0]%' OR t.post_text LIKE '%$queryarray[0]%')";
for($i=1;$i<$count;$i++){
$sql .= " $andor ";
$sql .= "(p.subject LIKE '%$queryarray[$i]%' OR t.post_text LIKE '%$queryarray[$i]%')";
}
$sql .= ") ";
}
$sql .= "ORDER BY p.post_time DESC";
$result = $xoopsDB->query($sql,$limit,$offset);
$ret = array();
$i = 0;
$myts =& MyTextSanitizer::getInstance();
while($myrow = $xoopsDB->fetchArray($result)){
$ret[$i]['link'] = "viewtopic.php?topic_id=".$myrow['topic_id']."&forum=".$myrow['forum_id']."&post_id=".$myrow['post_id']."#forumpost".$myrow['post_id'];
$ret[$i]['title'] = $myrow['subject'];
$ret[$i]['time'] = $myrow['post_time'];
$ret[$i]['uid'] = $myrow['uid'];
$context =strip_tags($myts->displayTarea($myrow['post_text'],$myrow['nohtml'],$myrow['nosmiley'],1));
$ret[$i]['context'] = xoops_make_context($context,$queryarray);
$i++;
}
return $ret;
}
?>
Function全体を記しておきます。DL(右クリックで保存)⇒
search_0.inc.php
function news_search($queryarray, $andor, $limit, $offset, $userid){
global $xoopsDB;
$sql = "SELECT storyid,uid,title,created,hometext,bodytext,nohtml,nosmiley FROM ".$xoopsDB->prefix("stories")." WHERE published>0 AND published<=".time()."";
if ( $userid != 0 ) {
$sql .= " AND uid=".$userid." ";
}
// because count() returns 1 even if a supplied variable
// is not an array, we must check if $querryarray is really an array
if ( is_array($queryarray) && $count = count($queryarray) ) {
$sql .= " AND ((hometext LIKE '%$queryarray[0]%' OR bodytext LIKE '%$queryarray[0]%' OR title LIKE '%$queryarray[0]%')";
for($i=1;$i<$count;$i++){
$sql .= " $andor ";
$sql .= "(hometext LIKE '%$queryarray[$i]%' OR bodytext LIKE '%$queryarray[$i]%' OR title LIKE '%$queryarray[$i]%')";
}
$sql .= ") ";
}
$sql .= "ORDER BY created DESC";
$result = $xoopsDB->query($sql,$limit,$offset);
$ret = array();
$i = 0;
$myts =& MyTextSanitizer::getInstance();
while($myrow = $xoopsDB->fetchArray($result)){
$ret[$i]['image'] = "images/forum.gif";
$ret[$i]['link'] = "article.php?storyid=".$myrow['storyid']."";
$ret[$i]['title'] = $myrow['title'];
$ret[$i]['time'] = $myrow['created'];
$ret[$i]['uid'] = $myrow['uid'];
$context = $myrow['hometext'].$myrow['bodytext'];
$context =strip_tags($myts->displayTarea($context,$myrow['nohtml'],$myrow['nosmiley'],1));
$ret[$i]['context'] = xoops_make_context($context,$queryarray);
$i++;
}
return $ret;
}
Function全体を記しておきます。DL(右クリックで保存)⇒
xoops_search.inc.php
function wiki_search($queryarray, $andor, $limit, $offset, $userid){
global $xoopsDB,$xoopsUser;
include (XOOPS_ROOT_PATH."/modules/pukiwiki/cache/config.php");
$X_uid = $X_admin = 0;
if ( $xoopsUser ) {
$xoopsModule = XoopsModule::getByDirname("pukiwiki");
if ( $xoopsUser->isAdmin($xoopsModule->mid()) ) {
$X_admin = 1;
}
$X_uid = $xoopsUser->uid();
}
$nocheck=false;
$nolisting=true;
$where_base = "p.name NOT LIKE ':config/%' AND p.name != 'RenameLog'";
if ($nocheck || $X_admin)
$where = "";
else
{
$where = "(p.vaids LIKE '%all%') OR (p.vgids LIKE '%&3&%')";
if ($X_uid) $where .= " OR (p.uid = $X_uid) OR (p.vaids LIKE '%&{$X_uid}&%')";
foreach(pukiwikimod_X_get_groups() as $gid)
{
$where .= " OR (p.vgids LIKE '%&{$gid}&%')";
}
}
if ($where)
$where_base = "($where_base) AND ($where)";
$sql = "SELECT p.id,p.name,p.editedtime,p.vaids,p.vgids,p.uid,p.title,t.plain FROM ".$xoopsDB->prefix("pukiwikimod_pginfo")." p LEFT JOIN ".$xoopsDB->prefix("pukiwikimod_plain")." t ON t.pgid=p.id WHERE ($where_base) ";
if ( $userid != 0 ) {
$sql .= "AND (p.uid=".$userid.") ";
}
// because count() returns 1 even if a supplied variable
// is not an array, we must check if $querryarray is really an array
if ( is_array($queryarray) && $count = count($queryarray) ) {
$sql .= "AND ((p.name LIKE '%$queryarray[0]%' OR t.plain LIKE '%$queryarray[0]%')";
for($i=1;$i<$count;$i++){
$sql .= " $andor ";
$sql .= "(p.name LIKE '%$queryarray[$i]%' OR t.plain LIKE '%$queryarray[$i]%')";
}
$sql .= ") ";
}
$sql .= "ORDER BY p.editedtime DESC";
$result = $xoopsDB->query($sql,$limit,$offset);
$ret = array();
$i = 0;
if (!$queryarray) $queryarray = array();
$word_url = rawurlencode(join(' ',$queryarray));
while($myrow = $xoopsDB->fetchArray($result)){
$title = ($myrow['title'])? " [".$myrow['title']."]" : "";
$page_url = rawurlencode($myrow['name']);
if ($use_static_url)
$ret[$i]['link'] = $myrow['id'].".html";
else
$ret[$i]['link'] = "index.php?cmd=read&page=$page_url&word=$word_url";
$ret[$i]['title'] = htmlspecialchars($myrow['name'].$title, ENT_QUOTES);
$ret[$i]['image'] = "image/search.gif";
$ret[$i]['time'] = $myrow['editedtime'];
$ret[$i]['uid'] = $myrow['uid'];
$ret[$i]['page'] = $myrow['name'];
if (!empty($myrow['plain']))
{
$ret[$i]['context'] = xoops_make_context($myrow['plain'],$queryarray);
}
$i++;
}
return $ret;
}
<{if $user_ownpage == true}>
<form name="usernav" action="user.php" method="post">
<br /><br />
<table width="70%" align="center" border="0">
<tr align="center">
<td><input type="button" value="<{$lang_editprofile}>" onclick="location='edituser.php'" />
<input type="button" value="<{$lang_avatar}>" onclick="location='edituser.php?op=avatarform'" />
<input type="button" value="<{$lang_inbox}>" onclick="location='viewpmsg.php'" />
<{if $user_candelete == true}>
<input type="button" value="<{$lang_deleteaccount}>" onclick="location='user.php?op=delete'" />
<{/if}>
<input type="button" value="<{$lang_logout}>" onclick="location='user.php?op=logout'" /></td>
</tr>
</table>
</form>
<br /><br />
<{elseif $xoops_isadmin != false}>
<br /><br />
<table width="70%" align="center" border="0">
<tr align="center">
<td><input type="button" value="<{$lang_editprofile}>" onclick="location='<{$xoops_url}>/modules/system/admin.php?fct=users&uid=<{$user_uid}>&op=modifyUser'" />
<input type="button" value="<{$lang_deleteaccount}>" onclick="location='<{$xoops_url}>/modules/system/admin.php?fct=users&op=delUser&uid=<{$user_uid}>'" />
</tr>
</table>
<br /><br />
<{/if}>
<table width="100%" border="0" cellspacing="5">
<tr valign="top">
<td width="50%">
<table class="outer" cellpadding="4" cellspacing="1" width="100%">
<tr>
<th colspan="2" align="center"><{$lang_allaboutuser}></th>
</tr>
<tr valign="top">
<td class="head"><{$lang_avatar}></td>
<td align="center" class="even"><img src="<{$user_avatarurl}>" alt="Avatar" /></td>
</tr>
<tr>
<td class="head"><{$lang_realname}></td>
<td align="center" class="odd"><{$user_realname}></td>
</tr>
<tr>
<td class="head"><{$lang_website}></td>
<td class="even"><{$user_websiteurl}></td>
</tr>
<tr valign="top">
<td class="head"><{$lang_email}></td>
<td class="odd"><{$user_email}></td>
</tr>
<tr valign="top">
<td class="head"><{$lang_privmsg}></td>
<td class="even"><{$user_pmlink}></td>
</tr>
<tr valign="top">
<td class="head"><{$lang_icq}></td>
<td class="odd"><{$user_icq}></td>
</tr>
<tr valign="top">
<td class="head"><{$lang_aim}></td>
<td class="even"><{$user_aim}></td>
</tr>
<tr valign="top">
<td class="head"><{$lang_yim}></td>
<td class="odd"><{$user_yim}></td>
</tr>
<tr valign="top">
<td class="head"><{$lang_msnm}></td>
<td class="even"><{$user_msnm}></td>
</tr>
<tr valign="top">
<td class="head"><{$lang_location}></td>
<td class="odd"><{$user_location}></td>
</tr>
<tr valign="top">
<td class="head"><{$lang_occupation}></td>
<td class="even"><{$user_occupation}></td>
</tr>
<tr valign="top">
<td class="head"><{$lang_interest}></td>
<td class="odd"><{$user_interest}></td>
</tr>
<tr valign="top">
<td class="head"><{$lang_extrainfo}></td>
<td class="even"><{$user_extrainfo}></td>
</tr>
</table>
</td>
<td width="50%">
<table class="outer" cellpadding="4" cellspacing="1" width="100%">
<tr valign="top">
<th colspan="2" align="center"><{$lang_statistics}></th>
</tr>
<tr valign="top">
<td class="head"><{$lang_membersince}></td>
<td align="center" class="even"><{$user_joindate}></td>
</tr>
<tr valign="top">
<td class="head"><{$lang_rank}></td>
<td align="center" class="odd"><{$user_rankimage}><br /><{$user_ranktitle}></td>
</tr>
<tr valign="top">
<td class="head"><{$lang_posts}></td>
<td align="center" class="even"><{$user_posts}></td>
</tr>
<tr valign="top">
<td class="head"><{$lang_lastlogin}></td>
<td align="center" class="odd"><{$user_lastlogin}></td>
</tr>
</table>
<br />
<table class="outer" cellpadding="4" cellspacing="1" width="100%">
<tr valign="top">
<th colspan="2" align="center"><{$lang_signature}></th>
</tr>
<tr valign="top">
<td class="even"><{$user_signature}></td>
</tr>
</table>
</td>
</tr>
</table>
<!-- start module search results loop -->
<{foreach item=module from=$modules}>
<p>
<h4><{$module.name}></h4>
<!-- start results item loop -->
<{foreach item=result from=$module.results}>
<img src="<{$result.image}>" alt="<{$module.name}>" /><b><a href="<{$result.link}>"><{$result.title}></a></b><br /><small>(<{$result.time}>)</small><br />
<{if ($result.context)}>
<div class="context"><{$result.context}></div>
<{/if}>
<{/foreach}>
<!-- end results item loop -->
<{$module.showall_link}>
</p>
<{/foreach}>
<!-- end module search results loop -->
XOOPSルート/xoops.css
または
テーマディレクトリ/style.css
に追加する。
(例)
div.context{
border: blue 1px dotted;
color:#444444;
background-color:#FFFFEE;
padding: 3px 10px;
margin: 5px 5px 5px 25px;
font-size: 100%;
text-align: left;
line-height: 130%;
word-break: break-all;
}
| Page name: | XOOPS/検索結果に本文抜粋 [ Sended pings(0) ] | |
| Author: | nao-pon | - 2005/10/30 14:55:12 JST(1341d) |
| Last edit: | nao-pon | - 2005/10/30 14:55:12 JST(1341d) |
| Editers: | 登録ユーザー | |
| Back Link: | 通りすがりさん(52d) news(63d) user(303d) コメント(401d) 通りすがりさん(995d) XOOPS(1119d) HypCommonFunc(1183d) xoops_search.inc.php バグ修正(1854d) | |
| Poster | Thread | ||
|---|---|---|---|
| kenken | Posted: 2005-10-29 7:21 Updated: 2005-10-30 14:55 |
||
常連さん ![]() ![]() Joined: 2003-5-5 From: Posts: 31 |
ご無沙汰してます。このハック,喜んで利用させていただいています。
ってエラーが表示されます。どこか変更しなければならないところがあるでしょうか? よろしくお願いします。 |
||
|
|
|
|
ログイン
メインメニュー
Home
新着情報
フォーラム
UsersWiki
xpWiki::Dev
Wiki [自由帳]
Recent View
View List
書籍情報
写メールBBS
たぐめも
ダウンロード
箱庭諸島
リンク集
カレンダー
お問い合わせ
サイトマップ
参照元情報
イメージマネージャ
|
"ぽちっ"としてね☆
最新のページ
ブックマーク
新着トラックバック
サイト内 Wiki
☆ 検索 ☆
オンライン状況
サイト情報
現在ページのQRコード
参照元情報