国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
3.1KB

  1. <?php
  2. /**
  3. * @version $Id: actionsearch_class.php 1 8:26 2010年7月12日Z tianya $
  4. * @package DedeBIZ.Administrator
  5. * @copyright Copyright (c) 2021, DedeBIZ.COM
  6. * @license https://www.dedebiz.com/license
  7. * @link https://www.dedebiz.com
  8. */
  9. class ActionSearch
  10. {
  11. var $keyword;
  12. var $asarray = array();
  13. var $result = array();
  14. function __construct($keyword)
  15. {
  16. $this->asarray = $this->GetSearchstr();
  17. $this->keyword = $keyword;
  18. }
  19. //初始化系统
  20. function ActionSearch($keyword)
  21. {
  22. $this->__construct($keyword);
  23. }
  24. function GetSearchstr()
  25. {
  26. require_once(dirname(__FILE__) . "/inc/inc_action_info.php");
  27. return is_array($actionSearch) ? $actionSearch : array();
  28. }
  29. function search()
  30. {
  31. $this->searchkeyword();
  32. return $this->result;
  33. }
  34. /**
  35. * 遍历功能配置项进行关键词匹配
  36. *
  37. * @return void
  38. */
  39. function searchkeyword()
  40. {
  41. $i = 0; //数组序列索引
  42. foreach ($this->asarray as $key => $value) {
  43. //对二级项目进行匹配
  44. if (is_array($this->asarray[$key]['soniterm'])) {
  45. foreach ($this->asarray[$key]['soniterm'] as $k => $val) {
  46. //进行权限判断
  47. if (TestPurview($val['purview'])) {
  48. //如果有操作权限
  49. if ($this->_strpos($val['title'], $this->keyword) !== false || $this->_strpos($val['description'], $this->keyword) !== false) {
  50. //一级项目匹配
  51. $this->result[$i]['toptitle'] = $this->redColorKeyword($this->asarray[$key]['toptitle']);
  52. $this->result[$i]['title'] = $this->redColorKeyword($this->asarray[$key]['title']);
  53. $this->result[$i]['description'] = $this->redColorKeyword($this->asarray[$key]['description']);
  54. //二级项目匹配
  55. $this->result[$i]['soniterm'][] = $this->redColorKeyword($val);
  56. }
  57. }
  58. }
  59. }
  60. $i++;
  61. }
  62. }
  63. /**
  64. * 加亮关键词
  65. *
  66. * @access public
  67. * @param string $text 关键词
  68. * @return string
  69. */
  70. function redColorKeyword($text)
  71. {
  72. if (is_array($text)) {
  73. foreach ($text as $key => $value) {
  74. if ($key == 'title' || $key == 'description') {
  75. //仅对title,description进行数组替换
  76. $text[$key] = str_replace($this->keyword, '<font color="red">' . $this->keyword . '</font>', $text[$key]);
  77. }
  78. }
  79. } else {
  80. $text = str_replace($this->keyword, '<font color="red">' . $this->keyword . '</font>', $text);
  81. }
  82. return $text;
  83. }
  84. function _strpos($string, $find)
  85. {
  86. if (function_exists('stripos')) return stripos($string, $find);
  87. return strpos($string, $find);
  88. }
  89. }