XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
LegacySearchService.class.php
1<?php
10
11if (!defined('XOOPS_ROOT_PATH')) {
12 exit();
13}
14
16{
17 public function getPropertyDefinition()
18 {
19 $ret = [
20 S_PUBLIC_VAR('int mid'),
21 S_PUBLIC_VAR('string name')
22 ];
23
24 return $ret;
25 }
26}
27
29{
30 public function getClassName()
31 {
32 return 'Legacy_SearchModule';
33 }
34}
35
36
38{
39 public function getPropertyDefinition()
40 {
41 $ret = [
42 S_PUBLIC_VAR('string image'),
43 S_PUBLIC_VAR('string link'),
44 S_PUBLIC_VAR('string title'),
45 S_PUBLIC_VAR('int uid'),
46 S_PUBLIC_VAR('int time')
47 ];
48
49 return $ret;
50 }
51}
52
54{
55 public function getClassName()
56 {
57 return 'Legacy_SearchItem';
58 }
59}
60
62{
63 public function getPropertyDefinition()
64 {
65 $ret = [
66 S_PUBLIC_VAR('int mid'),
67 S_PUBLIC_VAR('string name'),
68 S_PUBLIC_VAR('int has_more'),
69 S_PUBLIC_VAR('Legacy_SearchItemArray results'),
70 S_PUBLIC_VAR('string showall_link')
71 ];
72
73 return $ret;
74 }
75}
76
78{
79 public function getClassName()
80 {
81 return 'Legacy_SearchModuleResult';
82 }
83}
84
86{
87 public function getClassName()
88 {
89 return 'int';
90 }
91}
92
94{
95 public function getClassName()
96 {
97 return 'string';
98 }
99}
100
105{
106 public $mServiceName = 'Legacy_SearchService';
107 public $mNameSpace = 'Legacy';
108 public $mClassName = 'Legacy_SearchService';
109
110 public function prepare()
111 {
112 $this->addType('Legacy_SearchModule');
113 $this->addType('Legacy_SearchModuleArray');
114 $this->addType('Legacy_SearchItem');
115 $this->addType('Legacy_SearchItemArray');
116 $this->addType('Legacy_SearchModuleResult');
117 $this->addType('Legacy_SearchModuleResultArray');
118 $this->addType('Legacy_ArrayOfInt');
119 $this->addType('Legacy_ArrayOfString');
120
121 $this->addFunction(S_PUBLIC_FUNC('Legacy_SearchItemArray searchItems(int mid, Legacy_ArrayOfString queries, string andor, int maxhit, int start)'));
122 $this->addFunction(S_PUBLIC_FUNC('Legacy_SearchItemArray searchItemsOfUser(int mid, int uid, int maxhit, int start)'));
123 $this->addFunction(S_PUBLIC_FUNC('Legacy_SearchModuleArray getActiveModules()'));
124 }
125
126 public function getActiveModules()
127 {
128 //
129 // At first, get active module IDs.
130 //
131 static $ret;
132 if (isset($ret)) {
133 return $ret;
134 }
135
136 $handler =& xoops_gethandler('module');
137
138 $criteria = new CriteriaCompo();
139 $criteria->add(new Criteria('isactive', 1));
140 $criteria->add(new Criteria('hassearch', 1));
141
142 // shortcut for speedup
143 $db = $handler->db;
144
145 $sort = $criteria->getSort();
146 $sql = 'SELECT mid,name FROM '.$db->prefix('modules').' '.$criteria->renderWhere().
147 ($sort?' ORDER BY '.$sort.' '.$criteria->getOrder():' ORDER BY weight '.$criteria->getOrder().', mid ASC');
148
149 $result = $db->query($sql);
150
151 $handler =& xoops_gethandler('groupperm');
152 $groupArr = Legacy_SearchUtils::getUserGroups();
153
154 $ret = [];
155 while ([$mid, $name] = $db->fetchRow($result)) {
156 if ($handler->checkRight('module_read', $mid, $groupArr)) {
157 $ret[] = ['mid' => $mid, 'name' => $name];
158 }
159 }
160
161 return $ret;
162 }
163
164 public function searchItems()
165 {
166 //
167 // TODO Need validation
168 //
169 $root =& XCube_Root::getSingleton();
170 $request =& $root->mContext->mRequest;
171
172 return $this->_searchItems((int)$request->getRequest('mid'), $request->getRequest('queries'), $request->getRequest('andor'), (int)$request->getRequest('maxhit'), (int)$request->getRequest('start'), 0);
173 }
174
175 public function searchItemsOfUser()
176 {
177 //
178 // TODO Need validation
179 //
180 $root =& XCube_Root::getSingleton();
181 $request =& $root->mContext->mRequest;
182
183 return $this->_searchItems((int)$request->getRequest('mid'), null, 'and', (int)$request->getRequest('maxhit'), (int)$request->getRequest('start'), (int)$request->getRequest('uid'));
184 }
185
196 private function _searchItems($mid, $queries, $andor, $max_hit, $start, $uid)
197 {
198 $ret = [];
199
200 static $moduleArr;
201 if (!isset($moduleArr)) {
202 $moduleArr = [];
203 foreach ($this->getActiveModules() as $mod) {
204 $moduleArr[$mod['mid']] = $mod['name'];
205 }
206 }
207
208 if (!isset($moduleArr[$mid])) {
209 return $ret;
210 }
211
212 static $timezone;
213 if (!isset($timezone)) {
214 $root =& XCube_Root::getSingleton();
215 $timezone = $root->mContext->getXoopsConfig('server_TZ') * 3600;
216 }
217
218 $handler =& xoops_gethandler('module');
219 $xoopsModule =& $handler->get($mid);
220 if (!is_object($xoopsModule)) {
221 return $ret;
222 }
223
224 if (!$xoopsModule->get('isactive') || !$xoopsModule->get('hassearch')) {
225 return $ret;
226 }
227
228 $module =& Legacy_Utils::createModule($xoopsModule, false);
229 $results = $module->doLegacyGlobalSearch($queries, $andor, $max_hit, $start, $uid);
230
231 if (is_array($results) && count($results) > 0) {
232 foreach (array_keys($results) as $key) {
233 $timeval =& $results[$key]['time'];
234 //
235 // TODO If this service will come to web service, we should
236 // change format from unixtime to string by timeoffset.
237 //
238 if ($timeval) {
239 $timeval -= $timezone;
240 }
241 }
242 }
243
244 return $results;
245 }
246}
247
249{
250 public static function getUserGroups()
251 {
252 $root =& XCube_Root::getSingleton();
253 $user =& $root->mController->mRoot->mContext->mXoopsUser;
254 $groups = [];
255
256 if (!is_object($user)) {
257 $groups = XOOPS_GROUP_ANONYMOUS;
258 } else {
259 $groups = $user->getGroups();
260 }
261
262 return $groups;
263 }
264}