1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17:
18:
19: class SearchSearchForm extends Xoops\Form\ThemeForm
20: {
21: 22: 23: 24: 25:
26: public function __construct($obj = null)
27: {
28: }
29:
30: public function getSearchFrom($andor, $queries, $mids, $mid)
31: {
32: $xoops = \Xoops::getInstance();
33: $search = \Xoops::getModuleHelper('search');
34:
35: parent::__construct(_MD_SEARCH, 'search', 'index.php', 'get');
36:
37:
38: $this->addElement(new Xoops\Form\Text(_MD_SEARCH_KEYWORDS, 'query', 30, 255, htmlspecialchars(stripslashes($this->queryArrayToString($queries)), ENT_QUOTES)), true);
39: $type_select = new Xoops\Form\Select(_MD_SEARCH_TYPE, 'andor', $andor);
40: $type_select->addOptionArray(array(
41: 'AND' => _MD_SEARCH_ALL, 'OR' => _MD_SEARCH_ANY
42: ));
43: $this->addElement($type_select);
44: if (!empty($mids)) {
45: $mods_checkbox = new Xoops\Form\Checkbox(_MD_SEARCH_SEARCHIN, 'mids[]', $mids);
46: } else {
47: $mods_checkbox = new Xoops\Form\Checkbox(_MD_SEARCH_SEARCHIN, 'mids[]', $mid);
48: }
49: if (empty($modules)) {
50: $gperm_handler = $xoops->getHandlerGroupPermission();
51: $available_modules = $gperm_handler->getItemIds('module_read', $xoops->getUserGroups());
52: $available_plugins = \Xoops\Module\Plugin::getPlugins('search');
53:
54:
55: $criteria = new CriteriaCompo();
56: $criteria->add(new Criteria('dirname', "('" . implode("','", array_keys($available_plugins)) . "')", 'IN'));
57: if (isset($available_modules) && !empty($available_modules)) {
58: $criteria->add(new Criteria('mid', '(' . implode(',', $available_modules) . ')', 'IN'));
59: }
60: $module_handler = $xoops->getHandlerModule();
61: $mods_checkbox->addOptionArray($module_handler->getNameList($criteria));
62: } else {
63:
64: $module_array = array();
65: foreach ($modules as $mid => $module) {
66: $module_array[$mid] = $module->getVar('name');
67: }
68: $mods_checkbox->addOptionArray($module_array);
69: }
70: $this->addElement($mods_checkbox);
71: if ($search->getConfig('keyword_min') > 0) {
72: $this->addElement(new Xoops\Form\Label(_MD_SEARCH_SEARCHRULE, sprintf(_MD_SEARCH_KEYIGNORE, $search->getConfig('keyword_min'))));
73: }
74: $this->addElement(new Xoops\Form\Hidden('action', 'results'));
75: $this->addElement(new Xoops\Form\Token('id'));
76: $this->addElement(new Xoops\Form\Button('', 'submit', _MD_SEARCH, 'submit'));
77: return $this;
78: }
79:
80: 81: 82: 83: 84: 85: 86: 87:
88: private function queryArrayToString($queries)
89: {
90: $query = '';
91: foreach ($queries as $term) {
92: if (false === strpos($term, ' ')) {
93: $query .= $term . ' ';
94: } else {
95: $query .= '"' . $term . '" ';
96: }
97: }
98: $query = trim($query);
99: return $query;
100: }
101: }
102: