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

99 lines
3.2KB

  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) 2020, DedeBIZ.COM
  6. * @license https://www.dedebiz.com/license/v6
  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. $this->__construct($keyword);
  22. }
  23. function GetSearchstr()
  24. {
  25. require_once(dirname(__FILE__)."/inc/inc_action_info.php");
  26. return is_array($actionSearch)? $actionSearch : array();
  27. }
  28. function search(){
  29. $this->searchkeyword();
  30. return $this->result;
  31. }
  32. /**
  33. * 遍历功能配置项进行关键词匹配
  34. *
  35. * @return void
  36. */
  37. function searchkeyword(){
  38. $i = 0; //数组序列索引
  39. foreach ($this->asarray as $key=>$value)
  40. {
  41. //对二级项目进行匹配
  42. if(is_array($this->asarray[$key]['soniterm']))
  43. {
  44. foreach ($this->asarray[$key]['soniterm'] as $k=> $val)
  45. {
  46. //进行权限判断
  47. if(TestPurview($val['purview']))
  48. {
  49. //如果有操作权限
  50. if($this->_strpos($val['title'], $this->keyword) !== false || $this->_strpos($val['description'], $this->keyword)!== false)
  51. {
  52. //一级项目匹配
  53. $this->result[$i]['toptitle'] = $this->redColorKeyword($this->asarray[$key]['toptitle']);
  54. $this->result[$i]['title'] = $this->redColorKeyword($this->asarray[$key]['title']);
  55. $this->result[$i]['description'] = $this->redColorKeyword($this->asarray[$key]['description']);
  56. //二级项目匹配
  57. $this->result[$i]['soniterm'][] = $this->redColorKeyword($val);
  58. }
  59. }
  60. }
  61. }
  62. $i++;
  63. }
  64. }
  65. /**
  66. * 加亮关键词
  67. *
  68. * @access public
  69. * @param string $text 关键词
  70. * @return string
  71. */
  72. function redColorKeyword($text){
  73. if(is_array($text))
  74. {
  75. foreach ($text as $key => $value) {
  76. if($key == 'title' || $key == 'description')
  77. {
  78. //仅对title,description进行数组替换
  79. $text[$key] = str_replace($this->keyword,'<font color="red">'.$this->keyword.'</font>',$text[$key]);
  80. }
  81. }
  82. } else {
  83. $text = str_replace($this->keyword,'<font color="red">'.$this->keyword.'</font>',$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. }