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: class PageSearchPlugin extends PluginAbstract implements SearchPluginInterface
24: {
25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42:
43: public function search($queryArray, $andor, $limit, $offset, $userid)
44: {
45: $andor = strtolower($andor)==='and' ? 'and' : 'or';
46:
47: $qb = \Xoops::getInstance()->db()->createXoopsQueryBuilder();
48: $eb = $qb->expr();
49: $qb ->select('DISTINCT *')
50: ->fromPrefix('page_content')
51: ->where($eb->neq('content_status', '0'))
52: ->orderBy('content_create', 'DESC')
53: ->setFirstResult($offset)
54: ->setMaxResults($limit);
55: if (is_array($queryArray) && !empty($queryArray)) {
56: $queryParts = array();
57: foreach ($queryArray as $i => $q) {
58: $qterm = ':qterm' . $i;
59: $qb->setParameter($qterm, '%' . $q . '%', \PDO::PARAM_STR);
60: $queryParts[] = $eb -> orX(
61: $eb->like('content_title', $qterm),
62: $eb->like('content_text', $qterm),
63: $eb->like('content_shorttext', $qterm)
64: );
65: }
66: if ($andor === 'and') {
67: $qb->andWhere(call_user_func_array(array($eb, "andX"), $queryParts));
68: } else {
69: $qb->andWhere(call_user_func_array(array($eb, "orX"), $queryParts));
70: }
71: } else {
72: $qb->setParameter(':uid', (int) $userid, \PDO::PARAM_INT);
73: $qb->andWhere($eb->eq('content_author', ':uid'));
74: }
75:
76: $myts = \Xoops\Core\Text\Sanitizer::getInstance();
77: $items = array();
78: $result = $qb->execute();
79: while ($myrow = $result->fetch(\PDO::FETCH_ASSOC)) {
80: $content = $myrow["content_shorttext"] . "<br /><br />" . $myrow["content_text"];
81: $content = $myts->displayTarea($content);
82: $items[] = array(
83: 'title' => $myrow['content_title'],
84: 'content' => Metagen::getSearchSummary($content, $queryArray),
85: 'link' => "viewpage.php?id=" . $myrow["content_id"],
86: 'time' => $myrow['content_create'],
87: 'uid' => $myrow['content_author'],
88: 'image' => 'images/logo_small.png',
89: );
90: }
91: return $items;
92: }
93: }
94: