Skip to content

Commit 8258c19

Browse files
committed
fix in search
1 parent 0831422 commit 8258c19

File tree

1 file changed

+41
-30
lines changed

1 file changed

+41
-30
lines changed

gwiki/include/search.inc.php

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,71 @@
11
<?php
22
/**
3-
* include/search.inc.php - search gwiki pages
4-
*
5-
* This file is part of gwiki - geekwright wiki
6-
*
7-
* @copyright Copyright © 2013 geekwright, LLC. All rights reserved.
8-
* @license gwiki/docs/license.txt GNU General Public License (GPL)
9-
* @since 1.0
10-
* @author Richard Griffith <[email protected]>
11-
* @package gwiki
12-
* @version $Id$
13-
*/
14-
function gwiki_search($queryarray, $andor, $limit, $offset, $userid, $prefix=null)
3+
* include/search.inc.php - search gwiki pages
4+
*
5+
* This file is part of gwiki - geekwright wiki
6+
*
7+
* @copyright Copyright © 2013 geekwright, LLC. All rights reserved.
8+
* @license gwiki/docs/license.txt GNU General Public License (GPL)
9+
* @since 1.0
10+
* @author Richard Griffith <[email protected]>
11+
* @package gwiki
12+
* @version $Id$
13+
* @param $queryarray
14+
* @param $andor
15+
* @param $limit
16+
* @param $offset
17+
* @param $userid
18+
* @param null $prefix
19+
* @return array
20+
*/
21+
function gwiki_search($queryarray, $andor, $limit, $offset, $userid, $prefix = null)
1522
{
1623
global $xoopsDB;
1724

18-
$dir = basename( dirname ( dirname( __FILE__ ) ) ) ;
25+
$dir = basename(dirname(__DIR__));
1926

20-
$module_handler = xoops_gethandler('module');
27+
$module_handler = &xoops_gethandler('module');
2128
$module = $module_handler->getByDirname($dir);
22-
$module_id = $module->getVar('mid');
23-
$config_handler = xoops_gethandler('config');
29+
$module_id = $module->getVar('mid');
30+
$config_handler = &xoops_gethandler('config');
2431
$moduleConfig = $config_handler->getConfigsByCat(0, $module->getVar('mid'));
2532

2633
$baseurl = $moduleConfig['searchlink_template'];
27-
$args=implode('+',$queryarray); // template should include '&query='
2834

29-
$pagesetq='';
30-
if (substr_compare($queryarray[count($queryarray)-1],'{pageset=', 0, 9)===0) {
31-
$pageset=array_pop($queryarray);
32-
$pageset=substr($pageset,9,-1);
35+
if ($queryarray == '') {
36+
$args = '';
37+
} else {
38+
$args = implode('+', $queryarray);// template should include '&query='
39+
}
40+
41+
$pagesetq = '';
42+
if (is_array($queryarray) && (count($queryarray) > 1) && substr_compare($queryarray[count($queryarray) - 1], '{pageset=', 0, 9) === 0) {
43+
$pageset = array_pop($queryarray);
44+
$pageset = substr($pageset, 9, -1);
3345
trigger_error($pageset);
34-
$pagesetq=" AND page_set_home = '{$pageset}' ";
46+
$pagesetq = " AND page_set_home = '{$pageset}' ";
3547
}
3648

37-
$sql = "SELECT DISTINCT * FROM ".$xoopsDB->prefix('gwiki_pages')." WHERE active=1 ".$pagesetq;
49+
$sql = "SELECT DISTINCT * FROM " . $xoopsDB->prefix('gwiki_pages') . " WHERE active=1 " . $pagesetq;
3850
if (is_array($queryarray) && ($count = count($queryarray))) {
3951
$sql .= " AND (title LIKE '%$queryarray[0]%' OR search_body LIKE '%$queryarray[0]%' OR meta_keywords LIKE '%$queryarray[0]%' OR meta_description LIKE '%$queryarray[0]%')";
40-
for ($i = 1; $i < $count; $i++) {
52+
for ($i = 1; $i < $count; ++$i) {
4153
$sql .= " $andor (title LIKE '%$queryarray[$i]%' OR search_body LIKE '%$queryarray[$i]%' OR meta_keywords LIKE '%$queryarray[$i]%' OR meta_description LIKE '%$queryarray[$i]%')";
4254
}
4355
} else {
4456
$sql .= " AND uid='$userid'";
4557
}
4658
$sql .= " ORDER BY lastmodified DESC";
4759

48-
$items = array();
60+
$items = array();
4961
$result = $xoopsDB->query($sql, $limit, $offset);
5062
while ($myrow = $xoopsDB->fetchArray($result)) {
5163
$items[] = array(
5264
'title' => $myrow['title'],
53-
'link' => sprintf($baseurl,strtolower($myrow['keyword']),$args),
54-
'time' => $myrow['lastmodified'],
55-
'uid' => $myrow['uid'],
56-
'image' => 'assets/images/search-result-icon.png'
57-
);
65+
'link' => sprintf($baseurl, strtolower($myrow['keyword']), $args),
66+
'time' => $myrow['lastmodified'],
67+
'uid' => $myrow['uid'],
68+
'image' => 'assets/images/search-result-icon.png');
5869
}
5970

6071
return $items;

0 commit comments

Comments
 (0)