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
|
|
|
/** |
13
|
|
|
* SmallWorld |
14
|
|
|
* |
15
|
|
|
* @copyright The XOOPS Project (https://xoops.org) |
16
|
|
|
* @copyright 2011 Culex |
17
|
|
|
* @license GNU GPL (http://www.gnu.org/licenses/gpl-2.0.html/) |
18
|
|
|
* @package SmallWorld |
19
|
|
|
* @since 1.0 |
20
|
|
|
* @author Michael Albertsen (http://culex.dk) <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
use XoopsModules\Smallworld; |
24
|
|
|
|
25
|
|
|
require_once XOOPS_ROOT_PATH . '/modules/smallworld/include/functions.php'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Global search |
29
|
|
|
* |
30
|
|
|
* @param array $queryarray |
31
|
|
|
* @param string $andor |
32
|
|
|
* @param int $limit |
33
|
|
|
* @param int $offset |
34
|
|
|
* @param int $userid |
35
|
|
|
* @param string $sortby |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
function smallworld_search($queryarray, $andor, $limit, $offset, $userid, $sortby = 'created DESC') |
39
|
|
|
{ |
40
|
|
|
$moduleDirName = basename(dirname(__DIR__)); |
|
|
|
|
41
|
|
|
|
42
|
|
|
if (file_exists(XOOPS_ROOT_PATH . '/modules/smallworld/language/' . $GLOBALS['xoopsConfig']['language'] . '/main.php')) { |
43
|
|
|
require_once XOOPS_ROOT_PATH . '/modules/smallworld/language/' . $GLOBALS['xoopsConfig']['language'] . '/main.php'; |
44
|
|
|
} else { |
45
|
|
|
require_once XOOPS_ROOT_PATH . '/modules/smallworld/language/english/main.php'; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$moduleHandler = xoops_getHandler('module'); |
49
|
|
|
$module = $moduleHandler->getByDirname('smallworld'); |
50
|
|
|
$modid = $module->getVar('mid'); |
|
|
|
|
51
|
|
|
$searchparam = ''; |
|
|
|
|
52
|
|
|
$highlight = false; |
53
|
|
|
|
54
|
|
|
$gpermHandler = xoops_getHandler('groupperm'); |
|
|
|
|
55
|
|
|
if ($GLOBALS['xoopsUser'] && ($GLOBALS['xoopsUser'] instanceof \XoopsUser)) { |
|
|
|
|
56
|
|
|
$groups = $GLOBALS['xoopsUser']->getGroups(); |
|
|
|
|
57
|
|
|
$id = $GLOBALS['xoopsUser']->getVar('uid'); |
58
|
|
|
$wall = new Smallworld\WallUpdates(); |
59
|
|
|
$followers = smallworld_array_flatten($wall->getFollowers($id), 0); |
60
|
|
|
} else { |
61
|
|
|
$id = 0; |
62
|
|
|
$groups = XOOPS_GROUP_ANONYMOUS; |
|
|
|
|
63
|
|
|
$followers = []; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
//@todo figure out why this if statement is here both conditions yield the same result |
67
|
|
|
if ($id > 0 && '' != $id) { |
68
|
|
|
$sql = 'SELECT M.msg_id, M.uid_fk, M.message, M.created, M.priv, U.username FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_messages') . ' M, ' . $GLOBALS['xoopsDB']->prefix('smallworld_user') . ' U WHERE M.uid_fk=U.userid'; |
69
|
|
|
} else { |
70
|
|
|
$sql = 'SELECT M.msg_id, M.uid_fk, M.message, M.created, M.priv, U.username FROM ' . $GLOBALS['xoopsDB']->prefix('smallworld_messages') . ' M, ' . $GLOBALS['xoopsDB']->prefix('smallworld_user') . ' U WHERE M.uid_fk=U.userid'; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if (0 != (int)$userid) { |
74
|
|
|
$sql .= ' AND M.uid_fk = ' . $userid . ' '; |
75
|
|
|
} |
76
|
|
|
//@todo this needs to be refactored to address when $queryarray has more than 1 element |
77
|
|
|
if (is_array($queryarray) && $count = count($queryarray)) { |
78
|
|
|
$sql .= " AND (M.message LIKE '%$queryarray[0]%' OR M.message LIKE '%$queryarray[0]%' OR U.username LIKE '%$queryarray[0]%'"; |
79
|
|
|
$sql .= ') '; |
80
|
|
|
// keywords highlighting |
81
|
|
|
if ($highlight) { |
82
|
|
|
$searchparam = '&keywords=' . urlencode(trim(implode(' ', $queryarray))); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
$sql .= 'ORDER BY created DESC'; |
86
|
|
|
$result = $GLOBALS['xoopsDB']->query($sql, $limit, $offset); |
87
|
|
|
$ret = []; |
88
|
|
|
$i = 0; |
89
|
|
|
while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) { |
90
|
|
|
if (in_array($myrow['uid_fk'], $followers) || $myrow['uid_fk'] == $id) { |
91
|
|
|
$ret[$i]['image'] = 'assets/images/smallworld_icn.png'; |
92
|
|
|
$ret[$i]['link'] = 'permalink.php?ownerid=' . $myrow['uid_fk'] . '&updid=' . $myrow['msg_id']; |
93
|
|
|
if (preg_match('/UPLIMAGE/', $myrow['message'])) { |
94
|
|
|
// @todo - figure this out, doesn't look right - title value is overwrittern so 'message' never gets displayed |
95
|
|
|
$ownmsg = str_replace('UPLIMAGE ', '', $myrow['message']); |
96
|
|
|
$ret[$i]['title'] = $ownmsg; |
97
|
|
|
$ret[$i]['title'] = Smallworld\Helper::getInstance()->getHandler('SwUser')->getName($myrow['uid_fk']) . ' -> ' . _SMALLWORLD_GALLERY; |
98
|
|
|
//$ret[$i]['title'] = smallworld_getName($myrow['uid_fk']) . ' -> ' . _SMALLWORLD_GALLERY; |
99
|
|
|
$ret[$i]['title'] = str_replace(['<', '>'], ['<', '>'], $ret[$i]['title']); |
100
|
|
|
} else { |
101
|
|
|
$ret[$i]['title'] = smallworld_shortenText($myrow['message'], 60); |
102
|
|
|
} |
103
|
|
|
$ret[$i]['time'] = $myrow['created']; |
104
|
|
|
$ret[$i]['uid'] = $myrow['uid_fk']; |
105
|
|
|
} else { |
106
|
|
|
--$i; |
107
|
|
|
} |
108
|
|
|
++$i; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
return $ret; |
112
|
|
|
} |
113
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.