1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11: 12: 13: 14: 15: 16: 17: 18:
19:
20: function publisher_search($queryarray, $andor, $limit, $offset, $userid, $categories = array(), $sortby = 0, $searchin = "", $extra = "")
21: {
22: $publisher = Publisher::getInstance();
23: $ret = array();
24: if ($queryarray == '' || count($queryarray) == 0) {
25: $hightlight_key = '';
26: } else {
27: $keywords = implode('+', $queryarray);
28: $hightlight_key = "&keywords=" . $keywords;
29: }
30: $itemsObjs = $publisher->getItemHandler()
31: ->getItemsFromSearch($queryarray, $andor, $limit, $offset, $userid, $categories, $sortby, $searchin, $extra);
32: $withCategoryPath = $publisher->getConfig('search_cat_path');
33:
34: $usersIds = array();
35:
36: foreach ($itemsObjs as $obj) {
37: $item['image'] = "images/item_icon.gif";
38: $item['link'] = $obj->getItemUrl();
39: $item['link'] .= (!empty($hightlight_key) && (strpos($item['link'], '.php?') === false)) ? "?" . ltrim($hightlight_key, '&') : $hightlight_key;
40: if ($withCategoryPath) {
41: $item['title'] = $obj->getCategoryPath(false) . " > " . $obj->title();
42: } else {
43: $item['title'] = $obj->title();
44: }
45: $item['time'] = $obj->getVar('datesub');
46: $item['uid'] = $obj->getVar('uid');
47:
48: $text = $obj->body();
49: $sanitized_text = "";
50: $text_i = strtolower($text);
51: $queryarray = is_array($queryarray) ? $queryarray : array($queryarray);
52:
53:
54: foreach ($queryarray as $query) {
55: $pos = strpos($text_i, strtolower($query));
56: $start = max(($pos - 100), 0);
57: $length = strlen($query) + 200;
58: $context = $obj->highlight(XoopsLocale::substr($text, $start, $length, " [...]"), $query);
59: $sanitized_text .= "<p>[...] " . $context . "</p>";
60: }
61:
62:
63: $item['text'] = $sanitized_text;
64: $item['author'] = $obj->getVar('author_alias');
65: $item['datesub'] = $obj->datesub($publisher->getConfig('format_date'));
66: $usersIds[$obj->getVar('uid')] = $obj->getVar('uid');
67: $ret[] = $item;
68: unset($item, $sanitized_text);
69: }
70: $usersNames = XoopsUserUtility::getUnameFromIds($usersIds, $publisher->getConfig('format_realname'), true);
71: foreach ($ret as $key => $item) {
72: if ($item["author"] == '') {
73: $ret[$key]["author"] = @$usersNames[$item["uid"]];
74: }
75: }
76: unset($usersNames, $usersIds);
77: return $ret;
78: }
79: