Extension

Developer
Supported

Crosslinking

ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From Yuri Salimovskiy

     

You must be logged in to post.

Picking up fragments instead of whole words?

Support Request

MacObserver
MacObserver

We just turned on Crosslinking in our production environment and are noticing some odd behavior. It appears to be linking fragments of words that are keywords we set, but that appear inside other keywords. For example, we have “tip” set up as a crosslink keyword, but on this page it is adding a hyperllink to the word: “multiple” in the sentence:

Mr. Jobs’s stance is that cross-compilers dilute the iPhone’s value because developers can release the same app on multiple devices,

i assume that this is not intended behavior?

Yuri Salimovskiy
# 1
Developer
Yuri Salimovskiy

That seems incorrect indeed. Can you try adding

'/[a-zA-Z]+'.$link->keyword.'[a-zA-Z]+/i'

around line 326 in ext.crosslinking.php

Adam Christianson
# 2
Adam Christianson

Yuri,
Thanks for the quick response. That seems to fix this one instance yes, but the actual fix might need to be larger. If you take a look at this page and then the text for the entry titled “3 Quick Tips to Make Print and Save Dialogs Bigger and Better” (near the bottom of the page), you’ll see we have a Crosslinking term set for “quick tip” and it’s still being applied to the text “quick tips” on the page. Your fix only excludes instances when their are extra characters before AND after the crosslink term.

Also, in testing your fix I noticed that you might be able to clean up a number of your regex queries in that exclusion array. You have a number that are targeting different parameters:

/src=("|\')[^"\']*'.$link->keyword.'[^"\']*("|\')/i',
'/alt=("
|\')[^"\']*'.$link->keyword.'[^"\']*("|\')/i',
'/title=("|\')[^"\']*'.$link->keyword.'[^"\']*("|\')/i',
'
/value=("|\')[^"\']*'.$link->keyword.'[^"\']*("|\')/i',
'/rel=("
|\')[^"\']*'.$link->keyword.'[^"\']*("|\')/i',
'/content=("|\')[^"\']*'.$link->keyword.'[^"\']*("|\')/i

I would assume in general that you’d want to exclude crosslinking for a term that might appear inside “ANY” HTML tag parameter, so could you use a more general regex like this to capture all those instances?

'/.*=("|\')[^"\'](.*?)'.$link->keyword.'(.*?)[^"\']*("|\')/i', 

You’d have to test it of course, but it seems this one line may be able to be used in place of the multiple lines.

Yuri Salimovskiy
# 3
Developer
Yuri Salimovskiy

Thank you for suggestion. I will have to test it out, but looks like it should work.

Regarding your problem, try replacing the line I posted above with 2 lines:

'/[a-zA-Z]*'.$link->keyword.'[a-zA-Z]+/i',
'/[a-zA-Z]+'.$link->keyword.'[a-zA-Z]*/i'