Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Auto Link to Two Word terms

meshugymeshugy ✭✭
edited January 2014 in Vanilla 2.0 - 2.8

@peregrine This plugin is great, thanks! Is there a way to get it to autolink to two word terms? I'd like it to create auto links for the titles of books and other products. I tried this but it didn't work:

$wordlinkArray = array(

            "Unaccompanied Django" => "http://www.djangobooks.com/Item/unaccompanied_django");

Comments

  • peregrineperegrine MVP
    edited January 2014

    as is, the plugin only does one word.

    @meshugy with the following change.

    try this

    it may do one word two word phrase and 3 word phrase. - let me know how it works for you.

    in class.autolink.plugin.php

    look for

    $search = '/(\b\p{L}{4,15}\b)/u';

    and change to...

      $search = array('/(\b\p{L}{4,15}\b)/u', '/(\b\p{L}{4,15}\b \b\p{L}{4,15}\b)/u','/(\b\p{L}{4,15}\b \b\p{L}{4,15}\b \b\p{L}{4,15}\b)/u');
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • @meshugy

    @meshugy pitching. Its a fast ball, high and inside, bases loaded. last inning. two outs, two strikes. peregrine swings for the stands. The crowd is breathless...

    and @meshugy is also umpire.

    and ....

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • meshugymeshugy ✭✭
    edited January 2014

    @peregrine Grand Slam! that worked great....

    Now, to win the pennant, here's another problem to fix.

    If some has already posted a url that has an term set to autolink, the plugin will mangle the original url. For example, if I have the term "calendar" set to autolink and there's url posted in the forum like this:

    http://www.djangobooks.com/blog/calendar/
    

    then the autolink changes it to this:

    calendar/" target="_blank" rel="nofollow">http://www.djangobooks.com/blog/calendar/
    

    Is there an easy way to get the plugin to ignore terms already embedded within links?

  • peregrineperegrine MVP
    edited January 2014

    I may have to sit out the pennant.

    let me think about a decent way to rule that out.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • @peregrine I figured this may be a tricky one. It's by no mean essential, but would make the plugin much more useful as I could be much more liberal with the terms I set to autolink. I'll pledge $20 for development of this feature :)

  • peregrineperegrine MVP
    edited January 2014

    @meshugy

    try this see how it works for you

        $search = array('/(\/?\b\p{L}{4,15}\b)/u', '/(\b\p{L}{4,15}\b \b\p{L}{4,15}\b)/u','/(\b\p{L}{4,15}\b \b\p{L}{4,15}\b \b\p{L}{4,15}\b)/u');
    

    it may be the pennnant and a bonus :)

    I haven't tested completely but seems to work.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • well, it's a close game. That change made the "calendar" example work. But I just noticed this link got mangled with the term "tailpiece"

    My user posted this internal link:

    http://www.djangobooks.com/forum/discussion/1622/installing-tailpiece-leather-question
    

    The Autolink plugin changed it to:

    tailpiece-leather-question" target="_blank" rel="nofollow">http://www.djangobooks.com/forum/discussion/1622/installing-tailpiece-leather-question
    
  • peregrineperegrine MVP
    edited January 2014

    @meshugy you're pitching a tough game :) extra innings.

    steroids maybe?

    $search = array('/(\/?-?\b\p{L}{4,15}\b)/u', '/(\b\p{L}{4,15}\b \b\p{L}{4,15}\b)/u','/(\b\p{L}{4,15}\b \b\p{L}{4,15}\b \b\p{L}{4,15}\b)/u');

    resolves the -

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited January 2014

    @meshugy

    here's a better one

    edited:

    $search = array('/(\/?-?\??\=?\b\p{L}{4,15}\b)/u', '/(\b\p{L}{4,15}\b \b\p{L}{4,15}\b)/u','/(\b\p{L}{4,15}\b \b\p{L}{4,15}\b \b\p{L}{4,15}\b)/u');

    for these types as well

    http://www.djangobooks.com/blog/q?calendar

    I'll update the plugin (in a day) once you sign off on whether it is working properly or not with your parameters.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • that fixed the previous scenario, but not this one. The search term "Guzz" is set to autolink. This image link has term "guzz" in the the title:

    <a href="http://shoppingcart.djangobooks.com/Item/guzz-s3-skinny" title="Guzz S3 Skinny Guitar Pick &#40;2 Pack&#41;"></a><img src="http://shoppingcart.djangobooks.com/media/ecom/prodsm/guzz-s3-small.jpg"</a>
    

    You can see the result here: http://www.djangobooks.com/forum/discussion/11852/guzz-s3-skinny-guitar-pick-2-pack

  • peregrineperegrine MVP
    edited January 2014

    @Meshugy hurling too many pitches, peregrine battered. The changeup and @Meshugy throws a knuckleball, peregrine stands frozen like a deer in the headlights, falls from exhaustion and is taken to the dugout

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited January 2014

    @Meshugy

    a simple solution to the title dilemma.

    title="Guzz S3 Skinny Guitar Pick (2 Pack)"

    title="-Guzz S3 Skinny Guitar Pick (2 Pack)"

    just put a dash in front of the items that might be tags in your title.

    I suspect not many users are adding titles to their images on your forum and you can edit your own images with titles and everything will work perfectly with the other mods i gave you.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • @peregrine yes! That works....thanks for all your help.

  • @meshugy

    thanks for the donation and thanks for being a magnanimous umpire and mensch! and ability to bend with some issues.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Uh, this is an interesting plugin i have in my thoughts for some time now. Never tried it. I also have the situation that i would liken to link certain words and phrases into my Wiki.

    @peregrine: May i ask you, if this is a performance heavy task? Because i have a quite big community approximately: 1.400 comments a day.

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
  • peregrineperegrine MVP
    edited January 2014

    @phreak said:
    @peregrine: May i ask you, if this is a performance heavy task? Because i have a quite big community approximately: 1.400 comments a day.

    it doesn't do additional database lookups if you only choose autolinks. but it does parse the body of each discussion. So it would be computational. You would have to give it a try and see if it has any significant impact, I would think not much here.

    however if you choose autolink tags it does a database tag lookup. possibly more impact.

    you would have to give it a try and see if you discern any deleterious impact, since you have the ideal test site with lots of hits.

    that said, I don't think you will see significant impact, but you are the arbiter.

    by the way it doesn't do unicode.

    good luck!

    btw, version 1.4 is now available with the changes requested by meshugy.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.