国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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