Completed
Push — master ( 8ca430...3024c9 )
by Michael
03:12
created

include/search.inc.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * Module: XoopsTube
5
 *
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * PHP version 5
11
 *
12
 * @category        Module
13
 * @package         Xoopstube
14
 * @author          XOOPS Development Team
15
 * @copyright       2001-2013 The XOOPS Project
16
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
17
 * @version         $Id$
18
 * @link            http://sourceforge.net/projects/xoops/
19
 * @since           1.0.6
20
 *
21
 * @param int    $cid
22
 * @param string $permType
23
 * @param bool   $redirect
24
 *
25
 * @return bool
26
 */
27
28 View Code Duplication
function xtubeCheckSearchGroups($cid = 0, $permType = 'XTubeCatPerm', $redirect = false)
29
{
30
    global $xoopsUser;
31
32
    $mydirname = basename(dirname(__DIR__));
33
//    $mydirpath = dirname(__DIR__);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
34
35
    $groups        = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
36
    $gperm_handler = & xoops_gethandler('groupperm');
37
38
    $module_handler = & xoops_gethandler('module');
39
    $module         = & $module_handler->getByDirname($mydirname);
40
41
    if (!$gperm_handler->checkRight($permType, $cid, $groups, $module->getVar('mid'))) {
42
        if ($redirect == false) {
43
            return false;
44
        } else {
45
            redirect_header('index.php', 3, _NOPERM);
46
            exit();
47
        }
48
    }
49
    unset($module);
50
51
    return true;
52
}
53
54
/**
55
 * @param $queryarray
56
 * @param $andor
57
 * @param $limit
58
 * @param $offset
59
 * @param $userid
60
 *
61
 * @return array
62
 */
63
function xtubeSearch($queryarray, $andor, $limit, $offset, $userid)
64
{
65
    global $xoopsDB, $xoopsUser;
66
67
    $sql    = "SELECT cid, pid FROM " . $xoopsDB->prefix('xoopstube_cat');
68
    $result = $xoopsDB->query($sql);
69
    while ($_search_group_check = $xoopsDB->fetchArray($result)) {
70
        $_search_check_array[$_search_group_check['cid']] = $_search_group_check;
71
    }
72
73
    $sql = "SELECT lid, cid, title, submitter, published, description FROM " . $xoopsDB->prefix('xoopstube_videos');
74
    $sql .= " WHERE published > 0 AND published <= " . time() . " AND ( expired = 0 OR expired > " . time() . ") AND offline = 0 AND cid > 0";
75
76
    if ($userid != 0) {
77
        $sql .= " AND submitter=" . $userid . " ";
78
    }
79
80
    // because count() returns 1 even if a supplied variable
81
    // is not an array, we must check if $querryarray is really an array
82
    if (is_array($queryarray) && $count = count($queryarray)) {
83
        $sql .= " AND ((title LIKE LOWER('%$queryarray[0]%') OR LOWER(description) LIKE LOWER('%$queryarray[0]%'))";
84
        for ($i = 1; $i < $count; ++$i) {
85
            $sql .= " $andor ";
86
            $sql .= "(title LIKE LOWER('%$queryarray[$i]%') OR LOWER(description) LIKE LOWER('%$queryarray[$i]%'))";
87
        }
88
        $sql .= ") ";
89
    }
90
    $sql .= "ORDER BY published DESC";
91
    $result = $xoopsDB->query($sql, $limit, $offset);
92
    $ret    = array();
93
    $i      = 0;
94
95
    while ($myrow = $xoopsDB->fetchArray($result)) {
96
// Following is commented out because it can cause a conflict with View Account function (userinfo.php)
97
//        if ( false == xtubeCheckSearchGroups( $myrow['cid'] ) ) {
98
//            continue;
99
//        }
100
        $ret[$i]['image'] = 'assets/images/size2.gif';
101
        $ret[$i]['link']  = 'singlevideo.php?cid=' . $myrow['cid'] . '&amp;lid=' . $myrow['lid'];
102
        $ret[$i]['title'] = $myrow['title'];
103
        $ret[$i]['time']  = $myrow['published'];
104
        $ret[$i]['uid']   = $myrow['submitter'];
105
        ++$i;
106
    }
107
    unset($_search_check_array);
108
109
    return $ret;
110
}
111