mambax7 /
publisher
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | /* |
||
| 5 | You may not change or alter any portion of this comment or credits |
||
| 6 | of supporting developers from this source code or any supporting source code |
||
| 7 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, |
||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 12 | */ |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @copyright The XUUPS Project http://sourceforge.net/projects/xuups/ |
||
| 16 | * @license http://www.fsf.org/copyleft/gpl.html GNU public license |
||
| 17 | * @since 1.0 |
||
| 18 | * @author trabis <[email protected]> |
||
| 19 | */ |
||
| 20 | |||
| 21 | use XoopsModules\Publisher\{Helper, |
||
| 22 | Item, |
||
| 23 | ItemHandler |
||
| 24 | }; |
||
| 25 | |||
| 26 | require_once __DIR__ . '/common.php'; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param string|array $queryArray |
||
| 30 | * @param $andor |
||
| 31 | * @param $limit |
||
| 32 | * @param $offset |
||
| 33 | * @param $userid |
||
| 34 | * @param array $categories |
||
| 35 | * @param int $sortby |
||
| 36 | * @param string $searchin |
||
| 37 | * @param string $extra |
||
| 38 | * |
||
| 39 | * @return array |
||
| 40 | */ |
||
| 41 | function publisher_search($queryArray, $andor, $limit, $offset, $userid, $categories = [], $sortby = 0, $searchin = '', $extra = '') |
||
| 42 | { |
||
| 43 | $helper = Helper::getInstance(); |
||
| 44 | $ret = $item = []; |
||
| 45 | if ('' == $queryArray || (is_array($queryArray) && 0 === count($queryArray))) { |
||
| 46 | $hightlightKey = ''; |
||
| 47 | } else { |
||
| 48 | $keywords = implode('+', $queryArray); |
||
| 49 | $hightlightKey = '&keywords=' . $keywords; |
||
| 50 | } |
||
| 51 | /** @var ItemHandler $itemHandler */ |
||
| 52 | $itemHandler = $helper->getHandler('Item'); |
||
| 53 | $itemsObjs = $itemHandler->getItemsFromSearch($queryArray, $andor, $limit, $offset, $userid, $categories, $sortby, $searchin, $extra); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 54 | $withCategoryPath = $helper->getConfig('search_cat_path'); |
||
| 55 | //xoops_load("xoopslocal"); |
||
| 56 | $usersIds = []; |
||
| 57 | /** @var Item $obj */ |
||
| 58 | if (0 !== count($itemsObjs)) { |
||
| 59 | foreach ($itemsObjs as $obj) { |
||
| 60 | $item['image'] = 'assets/images/item_icon.gif'; |
||
| 61 | $item['link'] = $obj->getItemUrl(); |
||
| 62 | $item['link'] .= (!empty($hightlightKey) && (false === mb_strpos($item['link'], '.php?'))) ? '?' . ltrim($hightlightKey, '&') : $hightlightKey; |
||
| 63 | if ($withCategoryPath) { |
||
| 64 | $item['title'] = $obj->getCategoryPath(false) . ' > ' . $obj->getTitle(); |
||
| 65 | } else { |
||
| 66 | $item['title'] = $obj->getTitle(); |
||
| 67 | } |
||
| 68 | $item['time'] = $obj->getVar('datesub'); //must go has unix timestamp |
||
| 69 | $item['uid'] = $obj->uid(); |
||
| 70 | //"Fulltext search/highlight |
||
| 71 | $text = $obj->getBody(); |
||
| 72 | $sanitizedText = ''; |
||
| 73 | $textLower = mb_strtolower($text); |
||
| 74 | $queryArray = is_array($queryArray) ? $queryArray : [$queryArray]; |
||
| 75 | |||
| 76 | if ('' != $queryArray[0] && count($queryArray) > 0) { |
||
| 77 | foreach ($queryArray as $query) { |
||
| 78 | $pos = mb_stripos($textLower, $query); //xoops_local("strpos", $textLower, mb_strtolower($query)); |
||
| 79 | $start = max($pos - 100, 0); |
||
| 80 | $length = mb_strlen($query) + 200; //xoops_local("strlen", $query) + 200; |
||
| 81 | $context = $obj->highlight(xoops_substr($text, $start, $length, ' [...]'), $query); |
||
| 82 | $sanitizedText .= '<p>[...] ' . $context . '</p>'; |
||
| 83 | } |
||
| 84 | } |
||
| 85 | //End of highlight |
||
| 86 | $item['text'] = $sanitizedText; |
||
| 87 | $item['author'] = $obj->author_alias(); |
||
| 88 | $item['datesub'] = $obj->getDatesub($helper->getConfig('format_date')); |
||
| 89 | $objUid = $obj->uid(); |
||
| 90 | $usersIds[$objUid] = $objUid; |
||
| 91 | $ret[] = $item; |
||
| 92 | unset($item, $sanitizedText); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | xoops_load('XoopsUserUtility'); |
||
| 96 | $usersNames = \XoopsUserUtility::getUnameFromIds($usersIds, $helper->getConfig('format_realname'), true); |
||
| 97 | foreach ($ret as $key => $item) { |
||
| 98 | if ('' == $item['author']) { |
||
| 99 | $ret[$key]['author'] = $usersNames[$item['uid']] ?? ''; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | unset($usersNames, $usersIds); |
||
| 103 | |||
| 104 | return $ret; |
||
| 105 | } |
||
| 106 |