国内流行的内容管理系统(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.

93 lines
3.1KB

  1. <?php
  2. /**
  3. * @version $id:actionsearch_class.php 8:26 2010年7月12日 tianya $
  4. * @package DedeBIZ.Administrator
  5. * @copyright Copyright (c) 2022 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. if (is_null($value)) {
  44. continue;
  45. }
  46. //对二级项目进行匹配
  47. if (is_array($this->asarray[$key]['soniterm'])) {
  48. foreach ($this->asarray[$key]['soniterm'] as $k => $val) {
  49. //进行权限判断
  50. if (TestPurview($val['purview'])) {
  51. //如果有操作权限
  52. if ($this->_strpos($val['title'], $this->keyword) !== false || $this->_strpos($val['description'], $this->keyword) !== false) {
  53. //一级项目匹配
  54. $this->result[$i]['toptitle'] = $this->redColorKeyword($this->asarray[$key]['toptitle']);
  55. $this->result[$i]['title'] = $this->redColorKeyword($this->asarray[$key]['title']);
  56. $this->result[$i]['description'] = $this->redColorKeyword($this->asarray[$key]['description']);
  57. //二级项目匹配
  58. $this->result[$i]['soniterm'][] = $this->redColorKeyword($val);
  59. }
  60. }
  61. }
  62. }
  63. $i++;
  64. }
  65. }
  66. /**
  67. * 加亮关键词
  68. *
  69. * @access public
  70. * @param string $text 关键词
  71. * @return string
  72. */
  73. function redColorKeyword($text)
  74. {
  75. if (is_array($text)) {
  76. foreach ($text as $key => $value) {
  77. if ($key == 'title' || $key == 'description') {
  78. //仅对title,description进行数组替换
  79. $text[$key] = str_replace($this->keyword, '<span class="text-danger">'.$this->keyword.'</span>', $text[$key]);
  80. }
  81. }
  82. } else {
  83. $text = str_replace($this->keyword, '<span class="text-danger">'.$this->keyword.'</span>', $text);
  84. }
  85. return $text;
  86. }
  87. function _strpos($string, $find)
  88. {
  89. if (function_exists('stripos')) return stripos($string, $find);
  90. return strpos($string, $find);
  91. }
  92. }
  93. ?>