Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: spiros on December 17, 2012, 06:28:56 AM

Title: Strange highlight class in search results subjects
Post by: spiros on December 17, 2012, 06:28:56 AM
Strange highlight class in search results subjects

If you check the actual topics there is nothing dodgy there:
http://www.translatum.gr/forum/index.php?topic=49571.msg197904#msg197904
http://www.translatum.gr/forum/index.php?topic=204152.msg398432#msg398432
Title: Re: Strange highlight class in search results subjects
Post by: Chas Large on January 15, 2013, 08:53:11 AM
Sorry for the delay in responding. Not sure why no-one else has bothered to reply before now  :-\

Do you have a mod installed for changing the URLs into something more SEO friendly Pretty URLS? perhaps, it may be that the search is finding the class in the code to change the URL display from the CSS but it's not seen on the screen as it's background coding.

Maybe the database needs changing to UTF-8 due to foreign characters being used.

Just guesswork on my part as I've never seen anything like this before.
Title: Re: Strange highlight class in search results subjects
Post by: spiros on September 19, 2014, 04:36:33 PM
Yes, it is a modification to change search results.

This is from Search.php (check out the strong class="highlight">$1 bit)

// Fix the international characters in the keyword too.
$query = strtr($smcFunc['htmlspecialchars']($query), array('\\\'' => '\''));

$body_highlighted = preg_replace('/((<[^>]*)|' . preg_quote(strtr($query, array('\'' => '&#039;')), '/') . ')/ie' . ($context['utf8'] ? 'u' : ''), "'\$2' == '\$1' ? stripslashes('\$1') : '<strong class=\"highlight\">\$1</strong>'", $body_highlighted);
$subject_highlighted = preg_replace('/(' . preg_quote($query, '/') . ')/i' . ($context['utf8'] ? 'u' : ''), '<strong class="highlight">$1</strong>', $subject_highlighted);
}

$output['matches'][] = array(
'id' => $message['id_msg'],
'attachment' => loadAttachmentContext($message['id_msg']),
'alternate' => $counter % 2,
'member' => &$memberContext[$message['id_member']],
'icon' => $message['icon'],
'icon_url' => $settings[$context['icon_sources'][$message['icon']]] . '/post/' . $message['icon'] . '.gif',
'subject' => $message['subject'],
'subject_highlighted' => $subject_highlighted,
'time' => timeformat($message['poster_time']),
'timestamp' => forum_time(true, $message['poster_time']),
'counter' => $counter,
'modified' => array(
'time' => timeformat($message['modified_time']),
'timestamp' => forum_time(true, $message['modified_time']),
'name' => $message['modified_name']
),
'body' => $message['body'],
'body_highlighted' => $body_highlighted,
'start' => 'msg' . $message['id_msg']
);
$counter++;

return $output;
}


And this from Search.template.php

foreach ($topic['matches'] as $message)
{
$str_summary .= '<a style="color: blue;" href="#goto_' . $counter . '">' . $message['subject_highlighted'] . '</a><br/>';

$str .= '<br />
<div class="quoteheader" style="margin-left: 20px;"><a href="' . $scripturl . '?topic=' . $topic['id'] . '.msg' . $message['id'] . '#msg' . $message['id'] . '">' . $message['subject_highlighted'] . '</a> ' . $txt[525] . ' ' . $message['member']['link'] . '</div>';

if ($message['body_highlighted'] != '')
$str .= '
<blockquote class="bbc_standard_quote" style="margin-left: 20px;">' . $message['body_highlighted'] . '</blockquote>';
}
      

I am not sure what I need to do in order to maintain the highlighting in search results but get rid of the actual text that pops up.
Title: Re: Strange highlight class in search results subjects
Post by: Arantor on September 19, 2014, 08:17:38 PM
Known SMF bug.
Title: Re: Strange highlight class in search results subjects
Post by: spiros on September 20, 2014, 03:45:25 AM
Unresolvable?
Title: Re: Strange highlight class in search results subjects
Post by: Arantor on September 20, 2014, 08:00:25 AM
It's been known for at least 2 years...
Title: Re: Strange highlight class in search results subjects
Post by: Night09 on September 20, 2014, 08:14:21 AM
Why not just revert to the default search code? I dont see any difference in yours to normal results apart from the error in the middle.

What Mod did you use or is it a custom one off code job?
Title: Re: Strange highlight class in search results subjects
Post by: Arantor on September 20, 2014, 08:27:24 AM
Because it wouldn't solve the problem?

This is a known bug even in stock SMF and fixing it is... interesting.
Title: Re: Strange highlight class in search results subjects
Post by: Night09 on September 20, 2014, 08:40:32 AM
Quote from: Arantor on September 20, 2014, 08:27:24 AM
Because it wouldn't solve the problem?

This is a known bug even in stock SMF and fixing it is... interesting.

I was thinking that because his default code is way different to the forums. It is a wierd error though the way chops the actual word in half and not because of something not slashed out,
Title: Re: Strange highlight class in search results subjects
Post by: Arantor on September 20, 2014, 08:41:46 AM
Nope, it's a known bug in SMF 2.0 and has been for at least a couple of years. I've spent time trying to fix it but I can't think of a good way to do it reliably.
Title: Re: Strange highlight class in search results subjects
Post by: Night09 on September 20, 2014, 08:47:13 AM
Quote from: Arantor on September 20, 2014, 08:41:46 AM
Nope, it's a known bug in SMF 2.0 and has been for at least a couple of years. I've spent time trying to fix it but I can't think of a good way to do it reliably.

Headstart on 3.0? :P
Title: Re: Strange highlight class in search results subjects
Post by: Arantor on September 20, 2014, 08:48:42 AM
Nah, it's still in 2.1.

What's happening is that it replaces the original word with <strong class="highlight">word</strong> and subsequent words end up replacing *inside* that HTML.
Title: Re: Strange highlight class in search results subjects
Post by: spiros on January 14, 2016, 02:49:10 AM
I have installed Sphinx, and the same bug still appears...
Title: Re: Strange highlight class in search results subjects
Post by: Kindred on January 14, 2016, 10:23:58 AM
Quote from: Arantor on September 20, 2014, 08:48:42 AM
Nah, it's still in 2.1.

What's happening is that it replaces the original word with <strong class="highlight">word</strong> and subsequent words end up replacing *inside* that HTML.
Title: Re: Strange highlight class in search results subjects
Post by: spiros on January 14, 2016, 10:31:38 AM
Strange that it is so hard to fix :)