感谢网友@popcorner的贡献,此程序为后台搜索索引生成工具,在论坛根目录执行即可

    1. <?php
    2. /**
    3. * [Discuz!] (C)2001-2099 Comsenz Inc.
    4. * This is NOT a freeware, use is subject to license terms
    5. */
    6. error_reporting(E_ALL);
    7. $sourcedir = './';
    8. chdir($sourcedir);
    9. define('IN_ADMINCP', TRUE);
    10. define('NOROBOT', TRUE);
    11. define('ADMINSCRIPT', basename(__FILE__));
    12. define('CURSCRIPT', 'admin');
    13. define('APPTYPEID', 0);
    14. include './source/class/class_core.php';
    15. include './source/class/class_admincp.php';
    16. include './source/function/function_misc.php';
    17. include './source/function/function_forum.php';
    18. include './source/function/function_admincp.php';
    19. include './source/function/function_cache.php';
    20. $discuz = & discuz_core::instance();
    21. $discuz->init();
    22. $admincp = new discuz_admincp();
    23. $admincp->core = & $discuz;
    24. $admincp->init();
    25. $admincpdir = 'source/admincp/';
    26. $langfile = 'source/language/lang_admincp.php';
    27. $menulangfile = 'source/language/lang_admincp_menu.php';
    28. $searchindex = 'source/language/lang_admincp_searchindex.php';
    29. define('IN_DISCUZ', 1);
    30. define('IN_ADMINCP', 1);
    31. include $menulangfile;
    32. $menulang = $lang;
    33. $_G['siteurl'] = '';
    34. include $langfile;
    35. $lang = $lang + $menulang;
    36. $indexdata = array();
    37. include $sourcedir.'function/function_admincp.php';
    38. include $admincpdir.'admincp_menu.php';
    39. foreach($menu as $topmenu => $leftmenu) {
    40. foreach($leftmenu as $item) {
    41. if(!isset($item[2]) && isset($menulang[$item[0]])) {
    42. list($action, $operation, $do) = explode('_', $item[1]);
    43. $indexdata[] = array('index' => array(
    44. $menulang[$item[0]] => 'action='.$action.($operation ? '&operation='.$operation.($do ? '&do='.$do : '') : '')
    45. ), 'text' => array($menulang[$item[0]]));
    46. }
    47. }
    48. }
    49. $langi = '|'.implode('|', array_keys($lang)).'|';
    50. $dir = opendir($admincpdir);
    51. while($entry = readdir($dir)) {
    52. if($entry != '.' && $entry != '..' && preg_match('/^admincp\_/', $entry)) {
    53. $adminfile = $admincpdir.$entry;
    54. $data = file_get_contents($adminfile);
    55. $data = preg_replace('/\/\/.+?\r/', '', $data);
    56. $data = preg_replace_callback('/\/\*(.+?)\*\//s', 'clearnote', $data);
    57. preg_match_all('#/\*search=\s*(\{.+?\})\s*\*/(.+?)/\*search\*/#is', $data, $search);
    58. if($search) {
    59. foreach($search[0] as $k => $item) {
    60. $search[1][$k] = stripslashes($search[1][$k]);
    61. $titles = json_decode($search[1][$k], 1);
    62. $titlesnew = $titletext = array();
    63. foreach($titles as $title => $url) {
    64. $titlekey = strip_tags(isset($lang[$title]) ? $lang[$title] : $title);
    65. $titlesnew[$titlekey] = $url;
    66. if($titlekey[0] != '_') {
    67. $titletext[] = $titlekey;
    68. }
    69. }
    70. $data = $search[2][$k];
    71. preg_match_all("/(showsetting|showtitle|showtableheader|showtips)\('(\w+)'/", $data, $r);
    72. if($r[2]) {
    73. $l = array();
    74. if($titletext) {
    75. $l[] = implode(' &raquo; ', $titletext);
    76. }
    77. $tm = array();
    78. foreach($r[2] as $i) {
    79. if(in_array($i,$tm)) {
    80. continue;
    81. }
    82. $tm[] = $i;
    83. $l[] = strip_tags($i);
    84. $l[] = strip_tags($lang[$i]);
    85. $preg = '/\|('.preg_quote($i).'_comment)\|/';
    86. preg_match_all($preg, $langi, $lr);
    87. if($lr[1]) {
    88. foreach($lr[1] as $li) {
    89. $l[] = strip_tags($lang[$li]);
    90. }
    91. }
    92. }
    93. $indexdata[] = array('index' => $titlesnew, 'text' => $l);
    94. }
    95. }
    96. }
    97. }
    98. }
    99. $return = '<?php
    100. /**
    101. * [Discuz!] (C)2001-2099 Comsenz Inc.
    102. * This is NOT a freeware, use is subject to license terms
    103. *
    104. * $Id: adminsearchindex2.php 26203 2011-12-05 10:07:49Z monkey $
    105. *
    106. * This file is automatically generate
    107. */
    108. $lang = '.var_export($indexdata, 1).';
    109. ?>';
    110. file_put_contents($searchindex, $return);
    111. echo 'Done!';
    112. function clearnote($s) {
    113. if(!preg_match('/^search/i', $s[1])) {
    114. return '';
    115. } else {
    116. return '/*'.$s[1].'*/';
    117. }
    118. }
    119. function unicode_encode($name) {
    120. $name = iconv('GBK', 'UCS-2', $name);
    121. $len = strlen($name);
    122. $str = '';
    123. for ($i = 0; $i < $len - 1; $i = $i + 2) {
    124. $c = $name[$i];
    125. $c2 = $name[$i + 1];
    126. if (ord($c) > 0) {
    127. $str .= '\u'.base_convert(ord($c), 10, 16).base_convert(ord($c2), 10, 16);
    128. } else {
    129. $str .= $c2;
    130. }
    131. }
    132. return $str;
    133. }