|
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-2016 XOOPS Project (http://xoops.org) |
|
16
|
|
|
* @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html) |
|
17
|
|
|
* @link http://xoops.org/ |
|
18
|
|
|
* @since 1.0.6 |
|
19
|
|
|
* |
|
20
|
|
|
* @param int $cid |
|
21
|
|
|
* @param string $permType |
|
22
|
|
|
* @param bool $redirect |
|
23
|
|
|
* |
|
24
|
|
|
* @return bool |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
View Code Duplication |
function xtubeCheckSearchGroups($cid = 0, $permType = 'XTubeCatPerm', $redirect = false) |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
|
30
|
|
|
// $modulePath = dirname(__DIR__); |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
$groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; |
|
33
|
|
|
$gpermHandler = xoops_getHandler('groupperm'); |
|
34
|
|
|
|
|
35
|
|
|
$moduleHandler = xoops_getHandler('module'); |
|
36
|
|
|
$module = $moduleHandler->getByDirname($moduleDirName); |
|
37
|
|
|
|
|
38
|
|
|
if (!$gpermHandler->checkRight($permType, $cid, $groups, $module->getVar('mid'))) { |
|
39
|
|
|
if (false === $redirect) { |
|
40
|
|
|
return false; |
|
41
|
|
|
} else { |
|
42
|
|
|
redirect_header('index.php', 3, _NOPERM); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
unset($module); |
|
46
|
|
|
|
|
47
|
|
|
return true; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param $queryarray |
|
52
|
|
|
* @param $andor |
|
53
|
|
|
* @param $limit |
|
54
|
|
|
* @param $offset |
|
55
|
|
|
* @param $userid |
|
56
|
|
|
* |
|
57
|
|
|
* @return array |
|
58
|
|
|
*/ |
|
59
|
|
|
function xtubeSearch($queryarray, $andor, $limit, $offset, $userid) |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
|
|
$sql = 'SELECT cid, pid FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_cat'); |
|
62
|
|
|
$result = $GLOBALS['xoopsDB']->query($sql); |
|
63
|
|
|
while (false !== ($_search_group_check = $GLOBALS['xoopsDB']->fetchArray($result))) { |
|
64
|
|
|
$_search_check_array[$_search_group_check['cid']] = $_search_group_check; |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$sql = 'SELECT lid, cid, title, submitter, published, description FROM ' . $GLOBALS['xoopsDB']->prefix('xoopstube_videos'); |
|
68
|
|
|
$sql .= ' WHERE published > 0 AND published <= ' . time() . ' AND ( expired = 0 OR expired > ' . time() . ') AND offline = 0 AND cid > 0'; |
|
69
|
|
|
|
|
70
|
|
|
if ($userid !== 0) { |
|
71
|
|
|
$sql .= ' AND submitter=' . $userid . ' '; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
// because count() returns 1 even if a supplied variable |
|
75
|
|
|
// is not an array, we must check if $querryarray is really an array |
|
76
|
|
|
if (is_array($queryarray) && $count = count($queryarray)) { |
|
77
|
|
|
$sql .= " AND ((title LIKE LOWER('%$queryarray[0]%') OR LOWER(description) LIKE LOWER('%$queryarray[0]%'))"; |
|
78
|
|
|
for ($i = 1; $i < $count; ++$i) { |
|
79
|
|
|
$sql .= " $andor "; |
|
80
|
|
|
$sql .= "(title LIKE LOWER('%$queryarray[$i]%') OR LOWER(description) LIKE LOWER('%$queryarray[$i]%'))"; |
|
81
|
|
|
} |
|
82
|
|
|
$sql .= ') '; |
|
83
|
|
|
} |
|
84
|
|
|
$sql .= 'ORDER BY published DESC'; |
|
85
|
|
|
$result = $GLOBALS['xoopsDB']->query($sql, $limit, $offset); |
|
86
|
|
|
$ret = array(); |
|
87
|
|
|
$i = 0; |
|
88
|
|
|
|
|
89
|
|
|
while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) { |
|
90
|
|
|
// Following is commented out because it can cause a conflict with View Account function (userinfo.php) |
|
91
|
|
|
// if ( false == xtubeCheckSearchGroups( $myrow['cid'] ) ) { |
|
|
|
|
|
|
92
|
|
|
// continue; |
|
93
|
|
|
// } |
|
94
|
|
|
$ret[$i]['image'] = 'assets/images/size2.gif'; |
|
95
|
|
|
$ret[$i]['link'] = 'singlevideo.php?cid=' . $myrow['cid'] . '&lid=' . $myrow['lid']; |
|
96
|
|
|
$ret[$i]['title'] = $myrow['title']; |
|
97
|
|
|
$ret[$i]['time'] = $myrow['published']; |
|
98
|
|
|
$ret[$i]['uid'] = $myrow['submitter']; |
|
99
|
|
|
++$i; |
|
100
|
|
|
} |
|
101
|
|
|
unset($_search_check_array); |
|
102
|
|
|
|
|
103
|
|
|
return $ret; |
|
104
|
|
|
} |
|
105
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.