1
|
|
|
<?php declare(strict_types=1); |
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
|
|
|
* @category Module |
13
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
14
|
|
|
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
15
|
|
|
* @author Marcello Brandão aka Suico, Mamba, LioMJ <https://xoops.org> |
16
|
|
|
*/ |
17
|
|
|
/** |
18
|
|
|
* Protection against inclusion outside the site |
19
|
|
|
*/ |
20
|
|
|
if (!defined('XOOPS_ROOT_PATH')) { |
21
|
|
|
exit('XOOPS root path not defined'); |
22
|
|
|
} |
23
|
|
|
/** |
24
|
|
|
* Return search results and show images on userinfo page |
25
|
|
|
* |
26
|
|
|
* @param array $queryarray the terms to look |
27
|
|
|
* @param string $andor the conector between the terms to be looked |
28
|
|
|
* @param int $limit The number of maximum results |
29
|
|
|
* @param int $offset from wich register start |
30
|
|
|
* @param int $userid from which user to look |
31
|
|
|
* @return array with all results |
32
|
|
|
*/ |
33
|
|
|
function suico_search( |
34
|
|
|
$queryarray, |
35
|
|
|
$andor, |
36
|
|
|
$limit, |
37
|
|
|
$offset, |
38
|
|
|
$userid |
39
|
|
|
) { |
40
|
|
|
global $xoopsDB, $module; |
41
|
|
|
//getting the url to the uploads directory |
42
|
|
|
$moduleHandler = xoops_getHandler('module'); |
43
|
|
|
$modulo = $moduleHandler->getByDirname('suico'); |
|
|
|
|
44
|
|
|
/** @var \XoopsConfigHandler $configHandler */ |
45
|
|
|
$configHandler = xoops_getHandler('config'); |
46
|
|
|
$moduleConfig = $configHandler->getConfigsByCat(0, $modulo->getVar('mid')); |
|
|
|
|
47
|
|
|
$path_uploadimages = XOOPS_UPLOAD_URL; |
48
|
|
|
$ret = []; |
49
|
|
|
$sql = 'SELECT image_id, title, caption, date_created, uid_owner, filename FROM ' . $xoopsDB->prefix( |
50
|
|
|
'suico_images' |
51
|
|
|
) . ' WHERE '; |
52
|
|
|
if (0 !== $userid) { |
53
|
|
|
$sql .= '(uid_owner =' . (int)$userid . ')'; |
54
|
|
|
} |
55
|
|
|
// because count() returns 1 even if a supplied variable |
56
|
|
|
// is not an array, we must check if $querryarray is really an array |
57
|
|
|
$count = count($queryarray); |
58
|
|
|
if ($count > 0 && is_array($queryarray)) { |
59
|
|
|
$sql .= " ((title LIKE '%" . $queryarray[0] . "%')"; |
60
|
|
|
for ($i = 1; $i < $count; ++$i) { |
61
|
|
|
$sql .= " {$andor} "; |
62
|
|
|
$sql .= "(title LIKE '%" . $queryarray[$i] . "%')"; |
63
|
|
|
} |
64
|
|
|
$sql .= ') '; |
65
|
|
|
} |
66
|
|
|
$sql .= 'ORDER BY image_id DESC'; |
67
|
|
|
//echo $sql; |
68
|
|
|
//printr($xoopsModules); |
69
|
|
|
$result = $xoopsDB->query($sql, $limit, $offset); |
70
|
|
|
$i = 0; |
71
|
|
|
$stringofimage = 'images/search.png">'; |
72
|
|
|
while (false !== ($myrow = $xoopsDB->fetchArray($result))) { |
73
|
|
|
if (0 !== $userid) { |
74
|
|
|
if ($limit > 5) { |
75
|
|
|
$ret[$i]['image'] = "assets/images/search.png'><a href='" |
76
|
|
|
. XOOPS_URL |
77
|
|
|
. '/modules/suico/album.php?uid=' |
78
|
|
|
. $myrow['uid_owner'] |
79
|
|
|
. "'><img src='" |
80
|
|
|
. $path_uploadimages |
81
|
|
|
. '/suico/images/thumb_' |
82
|
|
|
. $myrow['filename'] |
83
|
|
|
. "'></a><br>" |
84
|
|
|
. '<img src=' |
85
|
|
|
. XOOPS_URL |
86
|
|
|
. '/modules/suico/images/search.png'; |
87
|
|
|
$ret[$i]['link'] = 'album.php?uid=' . $myrow['uid_owner']; |
88
|
|
|
$ret[$i]['title'] = $myrow['title']; |
89
|
|
|
//$ret[$i]['time'] = $myrow['date_created']; |
90
|
|
|
$ret[$i]['uid'] = $myrow['uid_owner']; |
91
|
|
|
} else { |
92
|
|
|
$stringofimage .= '<a href="' . XOOPS_URL . '/modules/suico/album.php?uid=' . $myrow['uid_owner'] . '" title="' . $myrow['title'] . '"><img src="' . $path_uploadimages . '/suico/images/thumb_' . $myrow['filename'] . '"></a> '; |
93
|
|
|
} |
94
|
|
|
} else { |
95
|
|
|
$ret[$i]['image'] = "assets/images/search.png'><a href='" |
96
|
|
|
. XOOPS_URL |
97
|
|
|
. '/modules/suico/album.php?uid=' |
98
|
|
|
. $myrow['uid_owner'] |
99
|
|
|
. "'><img src='" |
100
|
|
|
. $path_uploadimages |
101
|
|
|
. '/suico/images/thumb_' |
102
|
|
|
. $myrow['filename'] |
103
|
|
|
. "'></a><br>" |
104
|
|
|
. "<img src='" |
105
|
|
|
. XOOPS_URL |
106
|
|
|
. '/modules/suico/images/search.png'; |
107
|
|
|
$ret[$i]['link'] = 'album.php?uid=' . $myrow['uid_owner']; |
108
|
|
|
$ret[$i]['title'] = $myrow['title']; |
109
|
|
|
//$ret[$i]['time'] = $myrow['date_created']; |
110
|
|
|
$ret[$i]['uid'] = $myrow['uid_owner']; |
111
|
|
|
} |
112
|
|
|
$i++; |
113
|
|
|
} |
114
|
|
|
if (0 !== $userid && $i > 0) { |
115
|
|
|
if ($limit < 6) { |
116
|
|
|
$ret = []; |
117
|
|
|
$ret[0]['title'] = 'See its album'; |
118
|
|
|
$ret[0]['time'] = time(); |
119
|
|
|
$ret[0]['uid'] = $userid; |
120
|
|
|
$ret[0]['link'] = 'album.php?uid=' . $userid; |
121
|
|
|
$stringofimage .= '<img src="' . XOOPS_URL . '/modules/suico/assets/images/search.png'; |
122
|
|
|
$ret[0]['image'] = $stringofimage; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
return $ret; |
127
|
|
|
} |
128
|
|
|
|