Search highlighting breaks auto-linking
Reported by Rick Guyer | February 27th, 2010 @ 08:47 PM | in 0.8
When searching, search term highlighting breaks URL, email, and Twitter (# and @) links.
To reproduce, search for "couch" in a timeline containing @mcurry and look for tweets on Feb 24-26th with:
URL: http://20couch.com
Email: matt@20couch.com
Twitter links: #20couch or @20couch
Expected behavior would be for the links to work and the search terms to be correctly highlighted within the links.
Comments and changes to this ticket
-

Matt Curry March 1st, 2010 @ 02:55 PM
- Assigned user set to Matt Curry
- State changed from new to open
- Milestone cleared.
-

Matt Curry March 1st, 2010 @ 04:17 PM
- Milestone set to 1.10
I don't think I'm smart enough to fix this one :(
-

Rick Guyer March 1st, 2010 @ 04:45 PM
In SiteHelper::enhanceText, $text = $this->Text->autoLink($text); should come first. Then hashtags, usernames, and then search items, but each of those last three should only occur outside of HTML tags. The regexes need some lookaheads/lookbehinds or something similar. I may be able to come up with something.
-

Rick Guyer March 1st, 2010 @ 05:01 PM
$text = $this->Text->highlight($text, $this->data['Item']['search'], '\1', true);
This does the trick if I put it after links, hashtags and usernames. Please note, hashtags and usernames will still break links if # or @ exist within .
-

Rick Guyer March 1st, 2010 @ 05:03 PM
that line doesn't display correctly. Here is the correct line.
$text = $this->Text->highlight($text, $this->data['Item']['search'], '<span class="search-word">\1</span>', true); -

Rick Guyer March 1st, 2010 @ 06:07 PM
Replacing SiteHelper::enhanceText() with this should resolve this ticket (#30) along with #31 and possibly #20.
function enhanceText($text) { //links $text = $this->Text->autoLink($text); //hashtags $text = preg_replace('/(?<=^|\s)#(\w+)/', '<a href="http://twitter.com/search?q=%23$1">$0</a>', $text); //usernames $text = preg_replace('/(?<=^|\s)@(\w+)/', '<a href="http://twitter.com/$1">$0</a>', $text); //highlight search terms if (!empty($this->data['Item']['search'])) { $text = $this->Text->highlight($text, $this->data['Item']['search'], '<span class="search-word">\1</span>', true); } //images foreach($this->_imgSites as $regex => $html) { preg_match_all($regex, $text, $matches); if (!empty($matches[1])) { $matches = array_unique($matches[1]); $text .= '<br />'; foreach($matches as $match) { $text .= sprintf($html, $match, $match); } } } return $text; } -

Matt Curry March 2nd, 2010 @ 04:00 AM
- Milestone changed from 1.10 to 0.8
Awesome. I'm going to add this to the next version and see how it goes. Thanks for taking the time to figure this all out. I didn't know about Cake's Text::highlight method.
-

Matt Curry March 4th, 2010 @ 01:23 AM
- State changed from open to resolved
Implemented your code for 0.8 so far so good. Thanks again.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป