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 | /** |
||
13 | * XOOPS tag management module |
||
14 | * |
||
15 | * @copyright {@link https://sourceforge.net/projects/xoops/ The XOOPS Project} |
||
16 | * @license {@link https://www.fsf.org/copyleft/gpl.html GNU public license} |
||
17 | * @author Taiwen Jiang <[email protected]> |
||
18 | * @since 1.00 |
||
19 | */ |
||
20 | |||
21 | use XoopsModules\Tag\Constants; |
||
22 | use XoopsModules\Tag\Helper; |
||
23 | |||
24 | defined('XOOPS_ROOT_PATH') || exit('Restricted access'); |
||
25 | |||
26 | function &tag_search(array $queryarray, string $andor, int $limit, int $offset, int $userid, string $sortby = 'tag_term ASC'): array |
||
27 | { |
||
28 | $ret = []; |
||
29 | $count = is_array($queryarray) ? count($queryarray) : 0; |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
30 | if (0 >= $count) { |
||
31 | return $ret; |
||
32 | } |
||
33 | |||
34 | $fields = ['tag_id', 'tag_term']; |
||
35 | $tagHandler = Helper::getInstance()->getHandler('Tag'); |
||
36 | $criteria = new \CriteriaCompo(); |
||
37 | $criteria->setLimit($limit); |
||
38 | $criteria->setStart($offset); |
||
39 | $criteria->add(new \Criteria('tag_status', (string)Constants::STATUS_ACTIVE)); |
||
40 | if ('exact' === $andor) { |
||
41 | $criteria->add(new \Criteria('tag_term', $queryarray[0])); |
||
42 | for ($i = 1; $i < $count; ++$i) { |
||
43 | $criteria->add(new \Criteria('tag_term', $queryarray[$i]), $andor); |
||
44 | } |
||
45 | } else { |
||
46 | $criteria->add(new \Criteria('tag_term', "%{$queryarray[0]}%", 'LIKE')); |
||
47 | for ($i = 1; $i < $count; ++$i) { |
||
48 | $criteria->add(new \Criteria('tag_term', "%{$queryarray[$i]}%", 'LIKE'), $andor); |
||
49 | } |
||
50 | } |
||
51 | if ($sortby) { |
||
52 | $sbArray = explode(' ', $sortby); |
||
53 | if (0 < count($sbArray)) { |
||
54 | $criteria->setSort($sbArray[0]); |
||
55 | if (isset($sbArray[1])) { |
||
56 | $criteria->order = $sbArray[1]; // patch for XOOPS <= 2.5.10, does not set order correctly using setOrder() method |
||
57 | } |
||
58 | } |
||
59 | } |
||
60 | $tagObjArray = $tagHandler->getAll($criteria, $fields); |
||
61 | |||
62 | foreach ($tagObjArray as $tagId => $tagObj) { |
||
63 | $ret[] = [ |
||
64 | 'image' => 'assets/images/tag_search.gif', |
||
65 | 'link' => "view.tag.php?tag={$tagId}", |
||
66 | 'title' => $tagObj->getVar('tag_term'), |
||
67 | ]; |
||
68 | } |
||
69 | |||
70 | return $ret; |
||
71 | } |
||
72 |