Completed
Push — master ( 583920...a73650 )
by Michael
02:19
created

search.inc.php ➔ presenter_search()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 33
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 21
nc 8
nop 5
dl 0
loc 33
rs 8.439
c 0
b 0
f 0
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
/**
12
 * presenter module for xoops
13
 *
14
 * @copyright       XOOPS Project (http://xoops.org)
15
 * @license         GPL 2.0 or later
16
 * @package         presenter
17
 * @since           2.5.5
18
 * @author          XOOPS Development Team <[email protected]> - <http://xoops.org>
19
 * @version         $Id: 1.0 search.inc.php 11532 Wed 2013/08/28 4:00:27Z XOOPS Development Team $
20
 * @param $queryarray
21
 * @param $andor
22
 * @param $limit
23
 * @param $offset
24
 * @param $userid
25
 * @return array
26
 */
27
function presenter_search($queryarray, $andor, $limit, $offset, $userid)
28
{
29
    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...
30
31
    $sql = "SELECT slides_id, slides_cid FROM " . $xoopsDB->prefix('slides') . " WHERE slides_online = 1";
32
33
    if ($userid != 0) {
34
        $sql .= " AND slides_submitter=" . (int)($userid);
35
    }
36
37
    if (is_array($queryarray) && $count = count($queryarray)) {
38
        $sql .= " AND ((slides_cid LIKE '%$queryarray[0]%' OR slides_uid LIKE '%$queryarray[0]%' OR slides_title LIKE '%$queryarray[0]%' OR slides_content LIKE '%$queryarray[0]%' OR slides_transition_x LIKE '%$queryarray[0]%' OR slides_transition_y LIKE '%$queryarray[0]%' OR slides_transition_z LIKE '%$queryarray[0]%' OR slides_rotation_x LIKE '%$queryarray[0]%' OR slides_rotation_y LIKE '%$queryarray[0]%' OR slides_rotation_z LIKE '%$queryarray[0]%' OR slides_scale_x LIKE '%$queryarray[0]%' OR slides_scale_y LIKE '%$queryarray[0]%' OR slides_scale_z LIKE '%$queryarray[0]%' OR slides_created LIKE '%$queryarray[0]%' OR slides_published LIKE '%$queryarray[0]%' OR slides_position LIKE '%$queryarray[0]%' OR slides_online LIKE '%$queryarray[0]%' OR slides_type LIKE '%$queryarray[0]%' OR slides_notes LIKE '%$queryarray[0]%' OR slides_mp3 LIKE '%$queryarray[0]%' OR slides_time LIKE '%$queryarray[0]%')";
39
40
        for ($i = 1; $i < $count; ++$i) {
41
            $sql .= " $andor ";
42
            $sql .= "(slides_cid LIKE '%$queryarray[$i]%' OR slides_uid LIKE '%$queryarray[$i]%' OR slides_title LIKE '%$queryarray[$i]%' OR slides_content LIKE '%$queryarray[$i]%' OR slides_transition_x LIKE '%$queryarray[$i]%' OR slides_transition_y LIKE '%$queryarray[$i]%' OR slides_transition_z LIKE '%$queryarray[$i]%' OR slides_rotation_x LIKE '%$queryarray[$i]%' OR slides_rotation_y LIKE '%$queryarray[$i]%' OR slides_rotation_z LIKE '%$queryarray[$i]%' OR slides_scale_x LIKE '%$queryarray[$i]%' OR slides_scale_y LIKE '%$queryarray[$i]%' OR slides_scale_z LIKE '%$queryarray[$i]%' OR slides_created LIKE '%$queryarray[$i]%' OR slides_published LIKE '%$queryarray[$i]%' OR slides_position LIKE '%$queryarray[$i]%' OR slides_online LIKE '%$queryarray[$i]%' OR slides_type LIKE '%$queryarray[$i]%' OR slides_notes LIKE '%$queryarray[$i]%' OR slides_mp3 LIKE '%$queryarray[$i]%' OR slides_time LIKE '%$queryarray[0]%')";
43
        }
44
        $sql .= ")";
45
    }
46
47
    $sql .= " ORDER BY slides_id DESC";
48
    $result = $xoopsDB->query($sql, $limit, $offset);
49
    $ret    = array();
50
    $i      = 0;
51
    while ($myrow = $xoopsDB->fetchArray($result)) {
52
        $ret[$i]['image'] = 'images/icons/32/slides_search.png';
53
        $ret[$i]['link']  = 'slides.php?slides_id=' . $myrow['slides_id'];
54
        $ret[$i]['title'] = $myrow['slides_cid'];
55
        ++$i;
56
    }
57
58
    return $ret;
59
}
60