Completed
Push — master ( 812d3d...c578fd )
by Michael
01:56
created

search.inc.php ➔ gwiki_search()   C

Complexity

Conditions 9
Paths 16

Size

Total Lines 50
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 34
nc 16
nop 6
dl 0
loc 50
rs 6
c 0
b 0
f 0
1
<?php
2
/**
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
 * @param        $queryarray
13
 * @param        $andor
14
 * @param        $limit
15
 * @param        $offset
16
 * @param        $userid
17
 * @param  null  $prefix
18
 * @return array
19
 */
20
function gwiki_search($queryarray, $andor, $limit, $offset, $userid, $prefix = null)
0 ignored issues
show
Unused Code introduced by
The parameter $prefix is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
{
22
    global $xoopsDB;
23
24
    $dir = basename(dirname(__DIR__));
25
    $moduleHelper = Xmf\Module\Helper::getHelper($dir);
26
27
    $baseurl = $moduleHelper->getConfig('searchlink_template');
28
29
    if ($queryarray === '') {
30
        $args       = '';
31
    } else {
32
        $args = implode('+', $queryarray);// template should include '&query='
33
    }
34
35
    $pagesetq = '';
36
    if (is_array($queryarray) && (count($queryarray) > 1)
37
        && substr_compare($queryarray[count($queryarray) - 1], '{pageset=', 0, 9) === 0
38
    ) {
39
        $pageset = array_pop($queryarray);
40
        $pageset = substr($pageset, 9, -1);
41
        trigger_error($pageset);
42
        $pagesetq = " AND page_set_home = '{$pageset}' ";
43
    }
44
45
    $sql = 'SELECT DISTINCT * FROM ' . $xoopsDB->prefix('gwiki_pages') . ' WHERE active=1 ' . $pagesetq;
46
    if (is_array($queryarray) && ($count = count($queryarray))) {
47
        $sql .= " AND (title LIKE '%$queryarray[0]%' OR search_body LIKE '%$queryarray[0]%' OR meta_keywords LIKE '%$queryarray[0]%' OR meta_description LIKE '%$queryarray[0]%')";
48
        for ($i = 1; $i < $count; ++$i) {
49
            $sql .= " $andor (title LIKE '%$queryarray[$i]%' OR search_body LIKE '%$queryarray[$i]%' OR meta_keywords LIKE '%$queryarray[$i]%' OR meta_description LIKE '%$queryarray[$i]%')";
50
        }
51
    } else {
52
        $sql .= " AND uid='$userid'";
53
    }
54
    $sql .= ' ORDER BY lastmodified DESC';
55
56
    $items  = array();
57
    $result = $xoopsDB->query($sql, $limit, $offset);
58
    while ($myrow = $xoopsDB->fetchArray($result)) {
59
        $items[] = array(
60
            'title' => $myrow['title'],
61
            'link'  => sprintf($baseurl, strtolower($myrow['keyword']), $args),
62
            'time'  => $myrow['lastmodified'],
63
            'uid'   => $myrow['uid'],
64
            'image' => 'assets/images/search-result-icon.png'
65
        );
66
    }
67
68
    return $items;
69
}
70