此程序为后台搜索索引生成工具,在论坛根目录执行即可

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