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