XOOPS  2.6.0
search.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  */
11 
20 {
26  public function __construct($obj = null)
27  {
28  }
29 
30  public function getSearchFrom($andor, $queries, $mids, $mid)
31  {
34  // create form
35  parent::__construct(_MD_SEARCH, 'search', 'index.php', 'get');
36 
37  // create form elements
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 //, 'exact' => _MD_SEARCH_EXACT
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->getHandlerGroupperm();
51  $available_modules = $gperm_handler->getItemIds('module_read', $xoops->getUserGroups());
52  $available_plugins = \Xoops\Module\Plugin::getPlugins('search');
53 
54  //todo, would be nice to have the module ids availabe also
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  /* @var $module XoopsModule */
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 
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 }
$mid
Definition: index.php:39
if(!empty($available_plugins)) $module_array[0]
Definition: main.php:62
const _MD_SEARCH_ALL
Definition: main.php:26
const _MD_SEARCH_SEARCHIN
Definition: main.php:33
static getInstance()
Definition: Xoops.php:160
addElement(Element $formElement, $required=false)
Definition: Form.php:206
$query
Definition: index.php:37
getSearchFrom($andor, $queries, $mids, $mid)
Definition: search.php:30
$xoops
Definition: search.php:29
$queries
Definition: index.php:44
__construct($obj=null)
Definition: search.php:26
const _MD_SEARCH_KEYIGNORE
Definition: main.php:35
$search
Definition: index.php:28
$gperm_handler
$available_modules
Definition: index.php:65
const _MD_SEARCH_SEARCHRULE
Definition: main.php:36
$module
Definition: main.php:52
const _MD_SEARCH_TYPE
Definition: main.php:32
const _MD_SEARCH_KEYWORDS
Definition: main.php:31
const _MD_SEARCH
Definition: main.php:19
$available_plugins
Definition: main.php:56
$modules
Definition: userinfo.php:185
$criteria
$andor
Definition: index.php:38
$module_handler
Definition: main.php:55
$mids
Definition: index.php:42
const _MD_SEARCH_ANY
Definition: main.php:25
queryArrayToString($queries)
Definition: search.php:88