10.
加入搜尋
- 先至後台區塊管理,啟用XOOPS的搜尋區塊。
- 在xoops_version.php中加入搜尋設定(記得更新模組):
//---搜尋---//
$modversion['hasSearch'] = 1;
$modversion['search']['file'] = "include/search.php";
$modversion['search']['func'] = "tad_signup_search";
- 編輯 include/search.php,並根據提示修改之。
<?php
function tad_signup_search($queryarray, $andor, $limit, $offset, $userid)
{
global $xoopsDB;
if (get_magic_quotes_gpc()) {
foreach ($queryarray as $k => $v) {
$arr[$k] = addslashes($v);
}
$queryarray = $arr;
}
$sql = "SELECT `action_id`,`title`,`action_date`, `uid` FROM " . $xoopsDB->prefix("actions") . " WHERE `enable`=1";
if ($userid != 0) {
$sql .= " AND uid=" . $userid . " ";
}
if (is_array($queryarray) && $count = count($queryarray)) {
$sql .= " AND ((`title` LIKE '%{$queryarray[0]}%' OR `content` LIKE '%{$queryarray[0]}%' )";
for ($i = 1; $i < $count; $i++) {
$sql .= " $andor ";
$sql .= "(`title` LIKE '%{$queryarray[$i]}%' OR `content` LIKE '%{$queryarray[$i]}%' )";
}
$sql .= ") ";
}
$sql .= "ORDER BY `action_date` DESC";
$result = $xoopsDB->query($sql, $limit, $offset);
$ret = array();
$i = 0;
while ($myrow = $xoopsDB->fetchArray($result)) {
$ret[$i]['image'] = "images/search.png";
$ret[$i]['link'] = "index.php?action_id=" . $myrow['action_id'];
$ret[$i]['title'] = $myrow['title'];
$ret[$i]['time'] = strtotime($myrow['action_date']);
$ret[$i]['uid'] = $myrow['uid'];
$i++;
}
return $ret;
}
- 圖示請準備16x16的圖示,並存為 images/search.png。(可至 https://www.flaticon.com 下載)