Forgot password?
 Create new account
View 214|Reply 10

搜索高亮

[Copy link]

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

hbghlyj Posted at 2022-9-14 11:12:42 |Read mode
Last edited by hbghlyj at 2025-4-6 07:16:02搜索高亮

701

Threads

110K

Posts

910K

Credits

Credits
94157
QQ

Show all posts

kuing Posted at 2022-9-14 14:06:41
要不我给 /kk/zdy3pc.js 加段:
  1.     if (window.location.href.match('highlight')) {
  2.         window.location.href = window.location.href.replace(/&highlight=.*/, '');
  3.     }
Copy the Code

如何?

701

Threads

110K

Posts

910K

Credits

Credits
94157
QQ

Show all posts

kuing Posted at 2022-9-14 14:08:40
或者从搜索那里入手,把搜出来的链接的 &highlight=.* 去掉?

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2022-9-14 21:52:12
kuing 发表于 2022-9-14 07:06
要不我给 /kk/zdy3pc.js 加段:

如何?
这个window.location.href.match('highlight')不如
  1. (new URL(document.location)).searchParams.has('highlight');
Copy the Code

701

Threads

110K

Posts

910K

Credits

Credits
94157
QQ

Show all posts

kuing Posted at 2022-9-14 21:54:11
hbghlyj 发表于 2022-9-14 21:49
打开控制台再刷新,菜单就出来了
不用打开控制台,我刷新了几次,有时出来有时不出。

701

Threads

110K

Posts

910K

Credits

Credits
94157
QQ

Show all posts

kuing Posted at 2022-9-25 03:47:40
hbghlyj 发表于 2022-9-25 03:42
好呀.

它有时还会导致MathJax出错:
不知道改哪里

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2022-9-25 17:42:22

搜索加号

应该是在 upload/source/function/function_search.php
  1. function searchkey($keyword, $field, $returnsrchtxt = 0) {
  2.         $srchtxt = '';
  3.         if($field && $keyword) {
  4.                 if(preg_match("(AND|\+|&|\s)", $keyword) && !preg_match("(OR|\|)", $keyword)) {
  5.                         $andor = ' AND ';
  6.                         $keywordsrch = '1';
  7.                         $keyword = preg_replace("/( AND |&| )/is", "+", $keyword);
  8.                 } else {
  9.                         $andor = ' OR ';
  10.                         $keywordsrch = '0';
  11.                         $keyword = preg_replace("/( OR |\|)/is", "+", $keyword);
  12.                 }
  13.                 $keyword = str_replace('*', '%', addcslashes($keyword, '%_'));
  14.                 $srchtxt = $returnsrchtxt ? $keyword : '';
  15.                 foreach(explode('+', $keyword) as $text) {
  16.                         $text = trim(daddslashes($text));
  17.                         if($text) {
  18.                                 $keywordsrch .= $andor;
  19.                                 $keywordsrch .= str_replace('{text}', $text, $field);
  20.                         }
  21.                 }
  22.                 $keyword = " AND ($keywordsrch)";
  23.         }
  24.         return $returnsrchtxt ? array($srchtxt, $keyword) : $keyword;
  25. }
Copy the Code

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2022-9-25 17:59:24

高亮

我看了一下,好像应该是在 source/function/function_search.php以及 source/module/search/search_forum.php

function bat_highlight(\$message, \$words, \$color = '#ff0000') {
        if(!empty(\$words)) {
                \$highlightarray = explode(' ', \$words);
                \$sppos = strrpos(\$message, chr(0).chr(0).chr(0));
                if(\$sppos !== FALSE) {
                        \$specialextra = substr(\$message, \$sppos + 3);
                        \$message = substr(\$message, 0, \$sppos);
                }
                bat_highlight_callback_highlight_21(\$highlightarray, 1);
                \$message = preg_replace_callback("/(^|>)([^<]+)(?=<|\$)/sU", 'bat_highlight_callback_highlight_21', \$message);
                \$message = preg_replace("/<highlight>(.*)<\/highlight>/siU", "<strong><font color=\"\$color\">\\1</font></strong>", \$message);
                if(\$sppos !== FALSE) {
                        \$message = \$message.chr(0).chr(0).chr(0).\$specialextra;
                }
        }
        return \$message;
}
                foreach(C::t('forum_thread')->fetch_all_by_tid_fid_displayorder(explode(',',\$index['ids']), null, 0, \$orderby, \$start_limit, \$_G['tpp'], '>=', \$ascdesc) as \$thread) {
                        \$thread['subject'] = bat_highlight(\$thread['subject'], \$keyword);
                        \$thread['realtid'] = \$thread['isgroup'] == 1 ? \$thread['closed'] : \$thread['tid'];
                        \$threadlist[\$thread['tid']] = procthread(\$thread, 'dt');
                        \$posttables[\$thread['posttableid']][] = \$thread['tid'];
                }
                if(\$threadlist) {
                        foreach(\$posttables as \$tableid => \$tids) {
                                foreach(C::t('forum_post')->fetch_all_by_tid(\$tableid, \$tids, true, '', 0, 0, 1) as \$post) {
                                        \$threadlist[\$post['tid']]['message'] = bat_highlight(messagecutstr(\$post['message'], 200), \$keyword);
                                }
                        }

                }

701

Threads

110K

Posts

910K

Credits

Credits
94157
QQ

Show all posts

kuing Posted at 2022-9-25 21:32:46

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2022-9-25 21:59:55

原值返回

估计改成原值返回就行了
  1. function bat_highlight($message, $words, $color = '#ff0000') {
  2.     return $message;
  3. }
Copy the Code

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

 Author| hbghlyj Posted at 2022-9-25 22:01:24
比如highlight=res会把$message中的res替换成<strong><font color="#FF0000">res</font></strong>

手机版Mobile version|Leisure Math Forum

2025-4-20 21:29 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list