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

100 lines
3.3KB

  1. <?php
  2. /**
  3. * @version $Id: actionsearch_class.php 1 8:26 2010年7月12日Z tianya $
  4. * @package DedeCMS.Administrator
  5. * @copyright Copyright (c) 2007 - 2018, DesDev, Inc.
  6. * @copyright Copyright (c) 2020, DedeBIZ.COM
  7. * @license https://www.dedebiz.com/license/v6
  8. * @link https://www.dedebiz.com
  9. */
  10. class ActionSearch
  11. {
  12. var $keyword;
  13. var $asarray = array();
  14. var $result = array();
  15. function __construct($keyword)
  16. {
  17. $this->asarray = $this->GetSearchstr();
  18. $this->keyword = $keyword;
  19. }
  20. //初始化系统
  21. function ActionSearch($keyword){
  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. $this->searchkeyword();
  31. return $this->result;
  32. }
  33. /**
  34. * 遍历功能配置项进行关键词匹配
  35. *
  36. * @return void
  37. */
  38. function searchkeyword(){
  39. $i = 0; //数组序列索引
  40. foreach ($this->asarray as $key=>$value)
  41. {
  42. //对二级项目进行匹配
  43. if(is_array($this->asarray[$key]['soniterm']))
  44. {
  45. foreach ($this->asarray[$key]['soniterm'] as $k=> $val)
  46. {
  47. //进行权限判断
  48. if(TestPurview($val['purview']))
  49. {
  50. //如果有操作权限
  51. if($this->_strpos($val['title'], $this->keyword) !== false || $this->_strpos($val['description'], $this->keyword)!== false)
  52. {
  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. if(is_array($text))
  75. {
  76. foreach ($text as $key => $value) {
  77. if($key == 'title' || $key == 'description')
  78. {
  79. //仅对title,description进行数组替换
  80. $text[$key] = str_replace($this->keyword,'<font color="red">'.$this->keyword.'</font>',$text[$key]);
  81. }
  82. }
  83. } else {
  84. $text = str_replace($this->keyword,'<font color="red">'.$this->keyword.'</font>',$text);
  85. }
  86. return $text;
  87. }
  88. function _strpos($string,$find)
  89. {
  90. if (function_exists('stripos')) return stripos($string,$find);
  91. return strpos($string,$find);
  92. }
  93. }