1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: if (!defined('XOOPS_ROOT_PATH')) exit();
12:
13: require_once XOOPS_MODULE_PATH . "/legacy/forms/SearchResultsForm.class.php";
14:
15: define('LEGACY_SEARCH_RESULT_MAXHIT', 5);
16: define('LEGACY_SEARCH_SHOWALL_MAXHIT', 20);
17:
18: class Legacy_SearchResultsAction extends Legacy_Action
19: {
20: var $mActionForm = null;
21: var $mSearchResults = array();
22: var $mModules = array();
23:
24: var $mConfig = array();
25:
26: function prepare(&$controller, &$xoopsUser)
27: {
28: $root =& $controller->mRoot;
29: $root->mLanguageManager->loadPageTypeMessageCatalog('search');
30: $root->mLanguageManager->loadModuleMessageCatalog('legacy');
31:
32: $handler =& xoops_gethandler('config');
33: $this->mConfig =& $handler->getConfigsByCat(XOOPS_CONF_SEARCH);
34:
35: $this->_setupActionForm();
36: }
37:
38: function _setupActionForm()
39: {
40: $this->mActionForm =new Legacy_SearchResultsForm($this->mConfig['keyword_min']);
41: $this->mActionForm->prepare();
42: }
43:
44: function hasPermission(&$controller, &$xoopsUser)
45: {
46: if ($this->mConfig['enable_search'] != 1) {
47: $controller->executeRedirect(XOOPS_URL . '/', 3, _MD_LEGACY_ERROR_SEARCH_NOT_ENABLED);
48: return false;
49: }
50: return true;
51: }
52:
53: function _getMaxHit()
54: {
55: return LEGACY_SEARCH_RESULT_MAXHIT;
56: }
57:
58: function getDefaultView(&$controller, &$xoopsUser)
59: {
60: $root =& $controller->mRoot;
61: $service =& $root->mServiceManager->getService("LegacySearch");
62:
63: if (is_object($service)) {
64: $client =& $root->mServiceManager->createClient($service);
65: $this->mModules = $client->call('getActiveModules', array());
66: }
67:
68: $this->mActionForm->fetch();
69: $this->mActionForm->validate();
70:
71: if ($this->mActionForm->hasError()) {
72: return LEGACY_FRAME_VIEW_INDEX;
73: }
74:
75:
76:
77:
78: if (is_object($service)) {
79: $this->mActionForm->update($params);
80:
81: $handler =& xoops_gethandler('module');
82: foreach ($this->_getSelectedMids() as $mid) {
83: $t_module =& $handler->get($mid);
84: if (is_object($t_module)) {
85: $module = array();
86:
87: $module['mid'] = $mid;
88: $module['name'] = $t_module->get('name');
89:
90: $params['mid'] = $mid;
91: $module['results'] = $this->_doSearch($client, $xoopsUser, $params);
92:
93: if (count($module['results']) > 0) {
94: $module['has_more'] = (count($module['results']) >= $this->_getMaxHit()) ? true : false;
95: $this->mSearchResults[] = $module;
96: }
97: }
98: }
99: }
100: else {
101: return LEGACY_FRAME_VIEW_ERROR;
102: }
103:
104: return LEGACY_FRAME_VIEW_INDEX;
105: }
106:
107: function _doSearch(&$client, &$xoopsUser, &$params)
108: {
109: $root =& XCube_Root::getSingleton();
110: $timezone = $root->mContext->getXoopsConfig('server_TZ') * 3600;
111:
112: $results = $client->call('searchItems', $params);
113:
114: return $results;
115: }
116:
117: function execute(&$controller, &$xoopsUser)
118: {
119: return $this->getDefaultView($controller, $xoopsUser);
120: }
121:
122: function executeViewIndex(&$controller, &$xoopsUser, &$render)
123: {
124: $render->setTemplateName($this->_getTemplateName());
125:
126: $render->setAttribute('actionForm', $this->mActionForm);
127:
128: $render->setAttribute('searchResults', $this->mSearchResults);
129: $render->setAttribute('moduleArr', $this->mModules);
130:
131:
132:
133:
134:
135: $render->setAttribute('selectedMidArr', $this->_getSelectedMids());
136: $render->setAttribute('searchRuleMessage', @sprintf(_SR_KEYTOOSHORT, $this->mConfig['keyword_min']));
137: }
138:
139: function _getTemplateName()
140: {
141: return "legacy_search_results.html";
142: }
143:
144: function _getSelectedMids()
145: {
146: $ret = $this->mActionForm->get('mids');
147: if (!count($ret)) {
148: foreach ($this->mModules as $module) {
149: $ret[] = $module['mid'];
150: }
151: }
152:
153: return $ret;
154: }
155:
156: function executeViewError(&$controller, &$xoopsUser, &$render)
157: {
158: $controller->executeForward(XOOPS_URL . '/');
159: }
160: }
161:
162: ?>
163: