/class/xml/rpc/search.php

https://gitlab.com/VoyaTrax/vtCMS · PHP · 295 lines · 259 code · 9 blank · 27 comment · 79 complexity · 0e307592f09964a5caf0d54375135c3d MD5 · raw file

  1. <?php
  2. // $Id: search.php 1290 2008-02-10 13:09:25Z phppp $
  3. // ------------------------------------------------------------------------ //
  4. // XOOPS - PHP Content Management System //
  5. // Copyright (c) 2000 XOOPS.org //
  6. // <http://www.xoops.org/> //
  7. // ------------------------------------------------------------------------ //
  8. // This program is free software; you can redistribute it and/or modify //
  9. // it under the terms of the GNU General Public License as published by //
  10. // the Free Software Foundation; either version 2 of the License, or //
  11. // (at your option) any later version. //
  12. // //
  13. // You may not change or alter any portion of this comment or credits //
  14. // of supporting developers from this source code or any supporting //
  15. // source code which is considered copyrighted (c) material of the //
  16. // original comment or credit authors. //
  17. // //
  18. // This program is distributed in the hope that it will be useful, //
  19. // but WITHOUT ANY WARRANTY; without even the implied warranty of //
  20. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
  21. // GNU General Public License for more details. //
  22. // //
  23. // You should have received a copy of the GNU General Public License //
  24. // along with this program; if not, write to the Free Software //
  25. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
  26. // ------------------------------------------------------------------------ //
  27. $xoopsOption['pagetype'] = "search";
  28. include 'mainfile.php';
  29. $config_handler =& xoops_gethandler('config');
  30. $xoopsConfigSearch =& $config_handler->getConfigsByCat(XOOPS_CONF_SEARCH);
  31. if ($xoopsConfigSearch['enable_search'] != 1) {
  32. header('Location: '.XOOPS_URL.'/index.php');
  33. exit();
  34. }
  35. $action = "search";
  36. if (!empty($_GET['action'])) {
  37. $action = $_GET['action'];
  38. } elseif (!empty($_POST['action'])) {
  39. $action = $_POST['action'];
  40. }
  41. $query = "";
  42. if (!empty($_GET['query'])) {
  43. $query = $_GET['query'];
  44. } elseif (!empty($_POST['query'])) {
  45. $query = $_POST['query'];
  46. }
  47. $andor = "AND";
  48. if (!empty($_GET['andor'])) {
  49. $andor = $_GET['andor'];
  50. } elseif (!empty($_POST['andor'])) {
  51. $andor = $_POST['andor'];
  52. }
  53. $mid = $uid = $start = 0;
  54. if ( !empty($_GET['mid']) ) {
  55. $mid = intval($_GET['mid']);
  56. } elseif ( !empty($_POST['mid']) ) {
  57. $mid = intval($_POST['mid']);
  58. }
  59. if (!empty($_GET['uid'])) {
  60. $uid = intval($_GET['uid']);
  61. } elseif (!empty($_POST['uid'])) {
  62. $uid = intval($_POST['uid']);
  63. }
  64. if (!empty($_GET['start'])) {
  65. $start = intval($_GET['start']);
  66. } elseif (!empty($_POST['start'])) {
  67. $start = intval($_POST['start']);
  68. }
  69. $queries = array();
  70. if ($action == "results") {
  71. if ($query == "") {
  72. redirect_header("search.php",1,_SR_PLZENTER);
  73. exit();
  74. }
  75. } elseif ($action == "showall") {
  76. if ($query == "" || empty($mid)) {
  77. redirect_header("search.php",1,_SR_PLZENTER);
  78. exit();
  79. }
  80. } elseif ($action == "showallbyuser") {
  81. if (empty($mid) || empty($uid)) {
  82. redirect_header("search.php",1,_SR_PLZENTER);
  83. exit();
  84. }
  85. }
  86. $groups = is_object($xoopsUser) ? $xoopsUser -> getGroups() : XOOPS_GROUP_ANONYMOUS;
  87. $gperm_handler = & xoops_gethandler( 'groupperm' );
  88. $available_modules = $gperm_handler->getItemIds('module_read', $groups);
  89. if ($action == 'search') {
  90. include XOOPS_ROOT_PATH.'/header.php';
  91. include 'include/searchform.php';
  92. $search_form->display();
  93. include XOOPS_ROOT_PATH.'/footer.php';
  94. exit();
  95. }
  96. if ( $andor != "OR" && $andor != "exact" && $andor != "AND" ) {
  97. $andor = "AND";
  98. }
  99. $myts =& MyTextSanitizer::getInstance();
  100. if ($action != 'showallbyuser') {
  101. if ( $andor != "exact" ) {
  102. $ignored_queries = array(); // holds kewords that are shorter than allowed minmum length
  103. $temp_queries = preg_split('/[\s,]+/', $query);
  104. foreach ($temp_queries as $q) {
  105. $q = trim($q);
  106. if (strlen($q) >= $xoopsConfigSearch['keyword_min']) {
  107. $queries[] = $myts->addSlashes($q);
  108. } else {
  109. $ignored_queries[] = $myts->addSlashes($q);
  110. }
  111. }
  112. if (count($queries) == 0) {
  113. redirect_header('search.php', 2, sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min']));
  114. exit();
  115. }
  116. } else {
  117. $query = trim($query);
  118. if (strlen($query) < $xoopsConfigSearch['keyword_min']) {
  119. redirect_header('search.php', 2, sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min']));
  120. exit();
  121. }
  122. $queries = array($myts->addSlashes($query));
  123. }
  124. }
  125. switch ($action) {
  126. case "results":
  127. $module_handler =& xoops_gethandler('module');
  128. $criteria = new CriteriaCompo(new Criteria('hassearch', 1));
  129. $criteria->add(new Criteria('isactive', 1));
  130. $criteria->add(new Criteria('mid', "(".implode(',', $available_modules).")", 'IN'));
  131. $modules = $module_handler->getObjects($criteria, true);
  132. $mids = isset($_REQUEST['mids']) ? $_REQUEST['mids'] : array();
  133. if (empty($mids) || !is_array($mids)) {
  134. unset($mids);
  135. $mids = array_keys($modules);
  136. }
  137. include XOOPS_ROOT_PATH."/header.php";
  138. echo "<h3>"._SR_SEARCHRESULTS."</h3>\n";
  139. echo _SR_KEYWORDS.':';
  140. if ($andor != 'exact') {
  141. foreach ($queries as $q) {
  142. echo ' <b>'.htmlspecialchars(stripslashes($q)).'</b>';
  143. }
  144. if (!empty($ignored_queries)) {
  145. echo '<br />';
  146. printf(_SR_IGNOREDWORDS, $xoopsConfigSearch['keyword_min']);
  147. foreach ($ignored_queries as $q) {
  148. echo ' <b>'.htmlspecialchars(stripslashes($q)).'</b>';
  149. }
  150. }
  151. } else {
  152. echo ' "<b>'.htmlspecialchars(stripslashes($queries[0])).'</b>"';
  153. }
  154. echo '<br />';
  155. foreach ($mids as $mid) {
  156. $mid = intval($mid);
  157. if ( in_array($mid, $available_modules) ) {
  158. $module =& $modules[$mid];
  159. $results = $module->search($queries, $andor, 5, 0);
  160. echo "<h4>".$myts->makeTboxData4Show($module->getVar('name'))."</h4>";
  161. $count = count($results);
  162. if (!is_array($results) || $count == 0) {
  163. echo "<p>"._SR_NOMATCH."</p>";
  164. } else {
  165. for ($i = 0; $i < $count; $i++) {
  166. if (isset($results[$i]['image']) && $results[$i]['image'] != "") {
  167. echo "<img src='modules/".$module->getVar('dirname')."/".$results[$i]['image']."' alt='".$myts->makeTboxData4Show($module->getVar('name'))."' />&nbsp;";
  168. } else {
  169. echo "<img src='images/icons/posticon2.gif' alt='".$myts->makeTboxData4Show($module->getVar('name'))."' width='26' height='26' />&nbsp;";
  170. }
  171. if (!preg_match("/^http[s]*:\/\//i", $results[$i]['link'])) {
  172. $results[$i]['link'] = "modules/".$module->getVar('dirname')."/".$results[$i]['link'];
  173. }
  174. echo "<b><a href='".$results[$i]['link']."'>".$myts->makeTboxData4Show($results[$i]['title'])."</a></b><br />\n";
  175. echo "<small>";
  176. $results[$i]['uid'] = @intval($results[$i]['uid']);
  177. if ( !empty($results[$i]['uid']) ) {
  178. $uname = XoopsUser::getUnameFromId($results[$i]['uid']);
  179. echo "&nbsp;&nbsp;<a href='".XOOPS_URL."/userinfo.php?uid=".$results[$i]['uid']."'>".$uname."</a>\n";
  180. }
  181. echo !empty($results[$i]['time']) ? " (". formatTimestamp(intval($results[$i]['time'])).")" : "";
  182. echo "</small><br />\n";
  183. }
  184. if ( $count >= 5 ) {
  185. $search_url = XOOPS_URL.'/search.php?query='.urlencode(stripslashes(implode(' ', $queries)));
  186. $search_url .= "&mid=$mid&action=showall&andor=$andor";
  187. echo '<br /><a href="'.htmlspecialchars($search_url).'">'._SR_SHOWALLR.'</a></p>';
  188. }
  189. }
  190. }
  191. unset($results);
  192. unset($module);
  193. }
  194. include "include/searchform.php";
  195. $search_form->display();
  196. break;
  197. case "showall":
  198. case 'showallbyuser':
  199. include XOOPS_ROOT_PATH."/header.php";
  200. $module_handler =& xoops_gethandler('module');
  201. $module =& $module_handler->get($mid);
  202. $results =& $module->search($queries, $andor, 20, $start, $uid);
  203. $count = count($results);
  204. if (is_array($results) && $count > 0) {
  205. $next_results =& $module->search($queries, $andor, 1, $start + 20, $uid);
  206. $next_count = count($next_results);
  207. $has_next = false;
  208. if (is_array($next_results) && $next_count == 1) {
  209. $has_next = true;
  210. }
  211. echo "<h4>"._SR_SEARCHRESULTS."</h4>\n";
  212. if ($action == 'showall') {
  213. echo _SR_KEYWORDS.':';
  214. if ($andor != 'exact') {
  215. foreach ($queries as $q) {
  216. echo ' <b>'.htmlspecialchars(stripslashes($q)).'</b>';
  217. }
  218. } else {
  219. echo ' "<b>'.htmlspecialchars(stripslashes($queries[0])).'</b>"';
  220. }
  221. echo '<br />';
  222. }
  223. // printf(_SR_FOUND,$count);
  224. // echo "<br />";
  225. printf(_SR_SHOWING, $start+1, $start + $count);
  226. echo "<h5>".$myts->makeTboxData4Show($module->getVar('name'))."</h5>";
  227. for ($i = 0; $i < $count; $i++) {
  228. if (isset($results[$i]['image']) && $results[$i]['image'] != '') {
  229. echo "<img src='modules/".$module->getVar('dirname')."/".$results[$i]['image']."' alt='".$myts->makeTboxData4Show($module->getVar('name'))."' />&nbsp;";
  230. } else {
  231. echo "<img src='images/icons/posticon2.gif' alt='".$myts->makeTboxData4Show($module->name())."' width='26' height='26' />&nbsp;";
  232. }
  233. if (!preg_match("/^http[s]*:\/\//i", $results[$i]['link'])) {
  234. $results[$i]['link'] = "modules/".$module->getVar('dirname')."/".$results[$i]['link'];
  235. }
  236. echo "<b><a href='".$results[$i]['link']."'>".$myts->makeTboxData4Show($results[$i]['title'])."</a></b><br />\n";
  237. echo "<small>";
  238. $results[$i]['uid'] = @intval($results[$i]['uid']);
  239. if ( !empty($results[$i]['uid']) ) {
  240. $uname = XoopsUser::getUnameFromId($results[$i]['uid']);
  241. echo "&nbsp;&nbsp;<a href='".XOOPS_URL."/userinfo.php?uid=".$results[$i]['uid']."'>".$uname."</a>\n";
  242. }
  243. echo !empty($results[$i]['time']) ? " (". formatTimestamp(intval($results[$i]['time'])).")" : "";
  244. echo "</small><br />\n";
  245. }
  246. echo '
  247. <table>
  248. <tr>
  249. ';
  250. $search_url = XOOPS_URL.'/search.php?query='.urlencode(stripslashes(implode(' ', $queries)));
  251. $search_url .= "&mid=$mid&action=$action&andor=$andor";
  252. if ($action=='showallbyuser') {
  253. $search_url .= "&uid=$uid";
  254. }
  255. if ( $start > 0 ) {
  256. $prev = $start - 20;
  257. echo '<td align="left">
  258. ';
  259. $search_url_prev = $search_url."&start=$prev";
  260. echo '<a href="'.htmlspecialchars($search_url_prev).'">'._SR_PREVIOUS.'</a></td>
  261. ';
  262. }
  263. echo '<td>&nbsp;&nbsp;</td>
  264. ';
  265. if (false != $has_next) {
  266. $next = $start + 20;
  267. $search_url_next = $search_url."&start=$next";
  268. echo '<td align="right"><a href="'.htmlspecialchars($search_url_next).'">'._SR_NEXT.'</a></td>
  269. ';
  270. }
  271. echo '
  272. </tr>
  273. </table>
  274. <p>
  275. ';
  276. } else {
  277. echo '<p>'._SR_NOMATCH.'</p>';
  278. }
  279. include "include/searchform.php";
  280. $search_form->display();
  281. echo '</p>
  282. ';
  283. break;
  284. }
  285. include XOOPS_ROOT_PATH."/footer.php";
  286. ?>