Completed
Push — master ( c39b68...a1acf8 )
by Michael
03:03
created

search.inc.php ➔ tdmdownloads_search()   C

Complexity

Conditions 8
Paths 10

Size

Total Lines 45
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 8
eloc 29
c 2
b 0
f 1
nc 10
nop 5
dl 0
loc 45
rs 5.3846
1
<?php
2
/**
3
 * TDMDownload
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright   Gregory Mage (Aka Mage)
13
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @author      Gregory Mage (Aka Mage)
15
 */
16
17
function tdmdownloads_search($queryarray, $andor, $limit, $offset, $userid)
18
{
19
    global $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
20
21
    $sql = "SELECT lid, cid, title, description, submitter, date FROM ".$xoopsDB->prefix("tdmdownloads_downloads")." WHERE status != 0";
22
23
    if ( $userid != 0 ) {
24
        $sql .= " AND submitter=".intval($userid)." ";
25
    }
26
    require_once XOOPS_ROOT_PATH.'/modules/TDMDownloads/include/functions.php';
27
    $categories = TDMDownloads_MygetItemIds('tdmdownloads_view', 'TDMDownloads');
28
    if(is_array($categories) && count($categories) > 0) {
29
        $sql .= ' AND cid IN ('.implode(',', $categories).') ';
30
    } else {
31
        return null;
32
    }
33
34
    if ( is_array($queryarray) && $count = count($queryarray) )
35
    {
36
        $sql .= " AND ((title LIKE '%$queryarray[0]%' OR description LIKE '%$queryarray[0]%')";
37
38
        for($i=1;$i<$count;$i++)
39
        {
40
            $sql .= " $andor ";
41
            $sql .= "(title LIKE '%$queryarray[$i]%' OR description LIKE '%$queryarray[$i]%')";
42
        }
43
        $sql .= ")";
44
    }
45
46
    $sql .= " ORDER BY date DESC";
47
    $result = $xoopsDB->query($sql,$limit,$offset);
48
    $ret = array();
49
    $i = 0;
50
    while($myrow = $xoopsDB->fetchArray($result))
51
    {
52
        $ret[$i]["image"] = "images/deco/tdmdownloads_search.png";
53
        $ret[$i]["link"] = "singlefile.php?cid=".$myrow["cid"]."&lid=".$myrow["lid"]."";
54
        $ret[$i]["title"] = $myrow["title"];
55
        $ret[$i]["time"] = $myrow["date"];
56
        $ret[$i]["uid"] = $myrow["submitter"];
57
        $i++;
58
    }
59
60
    return $ret;
61
}
62