It would be beneficial to not have case sensitivity on terms, either switched off completely or per term.

For example, if ALinks is doing all my internal links in nodes, I want it to pick up all of the following regardless of case:

  • Contact Us
  • Contact us
  • contact us

Would it be possible to get this implemented?

CommentFileSizeAuthor
#7 alinks_update_20070613.tgz3.88 KBniklp

Comments

tic2000’s picture

It's on my todo list. My time unfortunately doesn't allow me to develop this module as much as I want to.

niklp’s picture

If you tell me roughly what needs doing, I will have a go at implementing it.

tic2000’s picture

You have to change line 117 of the alinks.module file form

$alink_text[] = '$\\' . $alink_start_boundary . preg_quote($word['alink_text'], '$') . '\\' . $alink_end_boundary . '$';

to

$alink_text[] = '$\\' . $alink_start_boundary . preg_quote($word['alink_text'], '$') . '\\' . $alink_end_boundary . '$i';
?>
and you will have a case insensitive replace for every alink you enter. I don't do this easy change cause I want to add this option when adding the link so you can have alinks there are case sensitive and alinks that are not. It's not hard to implement but I don't have the time do to it right now.
tic2000’s picture

It seems that I "lost" the to code in the previous post. Here it is

$alink_text[] = '$\\' . $alink_start_boundary . preg_quote($word['alink_text'], '$') . '\\' . $alink_end_boundary . '$i';
niklp’s picture

Is it just the addition of the i?

This seems fairly simple so hopefully I will have time to play with this soon. Also might try sorting out the external link thing too.

tic2000’s picture

Yes, it's just the addition of the i.
I hope that this weekend I'll have the time to add new features to this module.

niklp’s picture

Status: Active » Needs review
StatusFileSize
new3.88 KB

I have implemented the case sensitivity switching this module! :)

There is an awkward caveat though - I'm not sure if it can be got round or not? As it stands, case sensitivity will be retained as per before if that option is taken; however, if case sensitivity is switched off, all link-replaced text will be replaced with the *exact* text from the alink Phrase. So, I have a case insensitive alink, "Purple People Eater". Anywhere that you write "purple people eater" (or similar), it will be replaced by the capitalised version. In this case, not so bad, but there are foreseeable instances where this would not be the best option - e.g. "contact us" - sometimes this wants to be at the start of a sentence, sometimes not - capitalised, not capitalised... hmmm...

I've attached the alinks.* module files as a zipped attachment for tic2000 to resubmit as a new version (no CVS access). Suggest you wait until this is "proper" before use - I've given it only basic testing so far.

"Must have this" users can overwrite the files (alinks.install, alinks.module) in the module directory, run update.php and get going. This wouldn't be an official version though, so don't! :p

tic2000’s picture

Status: Needs review » Active

Thanks for your try NikLP, it was almost perfect. Apart the "awkward caveat" there is another error that make the html code broke on some links.
Anyway, powered by your desire to have this feature and give that to others too I've released a new alinks version that incorporates this feature and one more on top of it.
Enjoy it and let me know if any problems arise.

tic2000’s picture

Version: » 5.x-1.3-3

Forgot to say that the release, hopefully, has no caveat. If you use the case insensitive option the text remains the same. So if you have "contact us" as an alink, all "Contact Us", "contact us", "Contact us" and so forward will be replaced with links but the text remains exactly the same ("Contact Us", etc.)

niklp’s picture

Good lad! :)

Any chance you can drop a few notes here to explain how you got round the caveat? :) I know it's probably easy but it might help some budding Drupal programmer (or me, for that matter!)

Thanks dude!

niklp’s picture

PS I *really* don't think that the sensitivity checkbox is the right way round - surely people are more likely to want to have the link case-insensitive?

Whether or not this is a compatibility error, I don't think this is right. There are many more likely cases of requiring insensitivity than sensitivity, IMO.

What do you think?

tic2000’s picture

I did it this way just cause regexp it's by default case sensitive, so i felt like is the right way to do. Gives more consistency with the php code for me.
And about the solution for the caveat

  $alink_text[] = '$\\' . $alink_start_boundary . '(' . preg_quote($word['alink_text'], '$') . ')\\' . $alink_end_boundary . '$' . $alink_case_insensivity;
  $alink_url[] = '<a href="' . check_url($word['alink_url']) . '" class="alinks-link" title="' . check_plain($word['url_title']) . '">\1</a>';

Adding the round brackets in the first line of code and replacing preg_quote($word['alink_text'] with \1 in the second line of code did the trick.

tic2000’s picture

Status: Active » Fixed
niklp’s picture

Cool, thanks for the tips there.

I still think that there is a usability problem here: it doesn't matter what regexp default behaviour is; most people don't even know what that is, so who cares? Users are going to slap words in there randomly and expect it to match. The likelihood of someone needing it to be case-sensitive is VERY LOW compared to the other way around. I strongly recommend this behaviour is reversed. Likewise the table header notation, this is just plain wrong now...! ;)

Anonymous’s picture

Status: Fixed » Closed (fixed)