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.
Options

Auo link plugin

Hello,

some strings auto link while others do not , anyone know of this ?

Comments

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    Can you provide examples?

  • Options

    http://www.nzgirls.kiwi/discussion/72/nz-massage-parlours

    Half don't auto link , all are set in .php file

  • Options
    rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    Running private forum on Vanilla 2.1.11 VBS3 theme. I also see the random effect.
    Here are the definitions within the plugin code:

    $wordlinkArray = array(
                "google" => "http://www.google.com",
                "apple" => "http://www.apple.com",
                "ibm" => "http://www.ibm.com",
                "facebook" => "http://www.facebook.com",
                "twitter" => "http://www.twitter.com",
                "vanilla" => "http://www.vanilla.org",
                "hp" => "http://www.hp.com",
                "motorola" => "http://www.motorola.com",
                );  
    

    Here is a sample test discussion body (there are no html tags in the text):

    ibm apple google ibm motorola facebook twitter vanilla ibm hp ibm.

    And here is the resulting discussion display:

    ibm apple google ibm motorola facebook twitter vanilla ibm hp ibm.

  • Options
    rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭
    edited July 2015

    Thanks @vrijvlinder, I didn't see that file - I wrongly assumed that the description in the forum is all I needed and then proceeded directly to class.autolink.plugin.php to set it up.
    But that brings up at least two follow up observations/questions:

    1. I presume the 4-character minimum is designed to prevent false positives since tagging by users is uncontrolled. But the url links are only set by the admin, in which case the risk for false positive is minimal. So for example, if I wanted to support "IBM" and "HP", which are shorted than 4 characters, while limiting the tagging autolinks to more than 3 characters, how would I do that (and I admit not being a programmer, I don't understand how the search function works in the code).

    2. I also have the PrefixDiscussion plugin modified to search prefixes across the title and discussion body (not the comments). Is this a bad approach as now I have two different plugins that search content before displaying the discussion list (or perhaps I don;t understand how the system works and there is really no double-search)?

  • Options
    rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    Somehow there is some formatting error above - the two questions both have #1, the second appears as a nested question...

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    The function to look at is this one:

        protected function WordFind(&$text) {
           // $search = '/(\b\p{L}{4,15}\b)/u';
           $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');
            $text = preg_replace_callback($search, array($this, 'LinkWord'), $text);
            return $text;
        }
    

    It mainly consists of three lines of code and if you look at them, you'll see that there is more than one time {4,15} in the second line. That's where you have to make changes.


    Each plugin will fire up extra, so if you have a plugin that auto links, another replaces smilies, another one that does other markup, they are all fired one after the other. It might be faster if you are able to do all this replacements in one loop, but that a) isn't always possible and b) would make each function hard to maintain and c) wouldn't speed up your page significantly.

    Each plugin has its own function and if you would mix up your version of PrefixDiscussion and AutoLink, you would have to overwork your version if the author of one of those plugins releases a new version with bugfixes or other improvements.

  • Options
    rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    Thanks @R_J , so I won't concern myself with the performance and stick to the functionality. I even see the 4 and 15 in the code you included (though I don't pretend to understand it). But if I change 4 to 2 there will be many false positives because users can tag anything at will, so how do I change it to 2 only for urls but keep the 4 for urls?

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    @rbrahmson said:
    how do I change it to 2 only for urls but keep the 4 for urls?

    Sorry, I do not understand and I think I wouldn't be able to tell you so. But you can find it out yourself, I guess: there are only three regexes in the code.
    (\/?-?\??\=?\b\p{L}{4,15}\b)
    (\b\p{L}{4,15}\b \b\p{L}{4,15}\b)
    (\b\p{L}{4,15}\b \b\p{L}{4,15}\b \b\p{L}{4,15}\b)

    You can get try them with an example text and find out what each of there regexes stand for by using some regex helper like that: https://regex101.com/

  • Options
    rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    @R_J , I fully understand that if I change the "4" to "2" then the plugin will autolink 2-character words and thus HP and IBM urls will work. Alas, the plugin also a autolinks tagged words, and since many forum users can add tags at will, there will be a lot of false autolinks (e.g. people will create tags like "do" and then that word will be auto-linked all over the place). Having 4-character minimum minimizes that risk.

    Now to my question, given how the plugin is designed, it seems to my unprofessional eyes that logic change may be required, beyond my minimal skills. I am basically asking "how could the plugin require 4-character minimum for tagged words while 2 for urls".

    I am now in the process of duplicating the plugin, calling a second version with a different name, and changing the second to support 2-characters. My intent is to use the second to urls only and the first for tags only. I don't know if this would work, but even if it does, it looks like a kluge...

  • Options
    rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    @peregrine -I appreciate your suggestions and I will definitely search for readme files from now on. It may have been obvious to you (I mean the programmer community) but was not to the unprofessional and therefore your above list of suggestions/mini-guide is most welcome!

    As to the specific plugin at hand - I also appreciate your note on the performance hit. Fortunately our contemplated forum for which I've been asked to evaluate Vanilla will be made up of small number of users and posts - nothing like what I gather from the participants in this forum. So I can live with the performance hit.

    I will certainly look at the coding hints you mentioned, but just in case some other poor soul like me is interested (possibly the gentleman who started this discussion), as an interim solution I duplicated the plugin, called it by a different name, made the appropriate changes to form variables as well, and modified the number from 4 to 2. I then set the original plugin to search for tags only (which will work on tags greater than 4 characters), and the new one on URLs only (which will match URL keywords on 2-15 characters). That is probably a worse solution from a performance point of view, a real quick and dirty solution, but it works.

  • Options
    rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    And a short follow up: Going further with @Peregrine's suggestion, I went and played with the code. The first method to change the SQL didn't work. This is what I did:

    $MyTags = $MyTagsModel->SQL
                    ->Select('Name')
                    ->From('Tag')
                    ->Where('LENGTH(Name) > 3')
                    ->Get()
                    ->ResultArray();
    

    That returned no rows even though I had rows with tags longer than 3. I'm not sure why.

    I then went to the second option, and it worked flawlessly:

    foreach ($MyTags as $VTag) {
                  if (strlen($VTag['Name']) > 3) {
                  array_push($TagArray, $VTag['Name']);
                  }
            }
    

    Thus I was able to do it all in one modified plugin, and discarded the temporary 2-plugin method. Again, thank you @Peregrine!

  • Options
    peregrineperegrine MVP
    edited July 2015

    @rbrahmson said:
    And a short follow up: Going further with Peregrine's suggestion, I went and played with the code. The first method to change the SQL didn't work. This is what I did:

    $MyTags = $MyTagsModel->SQL
                    ->Select('Name')
                    ->From('Tag')
                    ->Where('LENGTH(Name) > 3')
                    ->Get()
                    ->ResultArray();
    

    That returned no rows even though I had rows with tags longer than 3. I'm not sure why.

    because you have incorrect syntax, it should be like this

            $MyTags = $MyTagsModel->SQL
                    ->Select('Name')
                    ->From('Tag')
                    ->Where("Length('Name')>",3)
                    ->Get()
                    ->ResultArray();
    

    that said, one would need to test which is faster. option1 (restrict via sql) vs option2 (ignoring sql and during loop and population of tagarray )

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

  • Options
    rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    Thanks again @peregrine, my mentor! When you say that I should check the performance I'm sure you are directing me to some new mountain of knowledge. So first let me say that we're running in a shared hosted environment where we can't install products so I won't be able to install any monitoring tools. BTW, I'm running under PHP Version 5.4.40.

    So I searched a little bit and found this bit of code which I could add to the plugin and check which works faster:

    $before = microtime(true);
      <<<the plugin code to measure>>>
    $after = microtime(true);
    echo ($after-$before)/$i . " sec/serialize\n";
    

    I could easily do that, but I'm not convinced that running on a shared server this would be reflecting much, and how many times do I have to do that to get enough samples that I can average and rely on.
    I probably need to replace the "echo" with something that writes to a log file.

    This entire performance research is more educational than practical since my forum is small and neither methods would affect performance, but now I got curious...

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    @peregrine certainly not only knows about log files, but already has shared his knowledge!vanillaforums.org/discussion/26786/tutorial-how-to-enable-a-debug-log-and-collect-debugging-information

    To your question how often you have to test that: the higher the better. Try to loop it as many times before you get a timeout.

    I agree that a shared hosting server is a bad test environment. Why don't you create a local copy of your forum so that you can really test things without having to fear you break something?

Sign In or Register to comment.