PageRenderTime 36ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/source/function/function_search.php

https://github.com/kuaileshike/upload
PHP | 63 lines | 52 code | 5 blank | 6 comment | 10 complexity | 875fdde9bc43cc0253b8684d682417ac MD5 | raw file
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: function_search.php 27661 2012-02-09 04:49:46Z svn_project_zhangjie $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function searchkey($keyword, $field, $returnsrchtxt = 0) {
  12. $srchtxt = '';
  13. if($field && $keyword) {
  14. if(preg_match("(AND|\+|&|\s)", $keyword) && !preg_match("(OR|\|)", $keyword)) {
  15. $andor = ' AND ';
  16. $keywordsrch = '1';
  17. $keyword = preg_replace("/( AND |&| )/is", "+", $keyword);
  18. } else {
  19. $andor = ' OR ';
  20. $keywordsrch = '0';
  21. $keyword = preg_replace("/( OR |\|)/is", "+", $keyword);
  22. }
  23. $keyword = str_replace('*', '%', addcslashes($keyword, '%_'));
  24. $srchtxt = $returnsrchtxt ? $keyword : '';
  25. foreach(explode('+', $keyword) as $text) {
  26. $text = trim(daddslashes($text));
  27. if($text) {
  28. $keywordsrch .= $andor;
  29. $keywordsrch .= str_replace('{text}', $text, $field);
  30. }
  31. }
  32. $keyword = " AND ($keywordsrch)";
  33. }
  34. return $returnsrchtxt ? array($srchtxt, $keyword) : $keyword;
  35. }
  36. function highlight($text, $words, $prepend) {
  37. $text = str_replace('\"', '"', $text);
  38. foreach($words AS $key => $replaceword) {
  39. $text = str_replace($replaceword, '<highlight>'.$replaceword.'</highlight>', $text);
  40. }
  41. return "$prepend$text";
  42. }
  43. function bat_highlight($message, $words, $color = '#ff0000') {
  44. if(!empty($words)) {
  45. $highlightarray = explode(' ', $words);
  46. $sppos = strrpos($message, chr(0).chr(0).chr(0));
  47. if($sppos !== FALSE) {
  48. $specialextra = substr($message, $sppos + 3);
  49. $message = substr($message, 0, $sppos);
  50. }
  51. $message = preg_replace(array("/(^|>)([^<]+)(?=<|$)/sUe", "/<highlight>(.*)<\/highlight>/siU"), array("highlight('\\2', \$highlightarray, '\\1')", "<strong><font color=\"$color\">\\1</font></strong>"), $message);
  52. if($sppos !== FALSE) {
  53. $message = $message.chr(0).chr(0).chr(0).$specialextra;
  54. }
  55. }
  56. return $message;
  57. }
  58. ?>