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.

Signature to strip [A]-tags

phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP
edited July 2013 in Vanilla 2.0 - 2.8

Hi everybody,

I'm looking for a way so the signature addon strips all [a] tags.
Users on my board (pregnancy) regulary add so called tickers creating thousends of external links to the signature.

Everyone ever accomplished this?

Thanx for info

  • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
  • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
Tagged:

Comments

  • do you want text only sigs?

    in that case change the line

    $Sender->UserSignature = Gdn_Format::Html($UserSig);
    

    to

    $Sender->UserSignature = Gdn_Format::Text($UserSig);
    

    grep is your friend.

  • phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP

    @x00: Thanx for your return on my question. I don't want text-only signatures. HTML should be possible as a lot of users are using images. These images come usually linked as they come from generator websites (those links point back to generator website, creating thousends of links back for every comment of the user). So i just want the [a] tags and everything inside stripped.

    One quickfix for now could be if someone could name me a way where "nofollow" is added to every [a]-tag.

    Thanx for help.

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited July 2013

    Have you tried something like this ?

    jQuery(document).ready(function () {
    
    $('.MessageList .UserSignature img a').attr('rel', 'nofollow');
    $('.MessageList a').attr('rel', 'nofollow');
        });
    
    
  • do you want the link totally removed or just make it non clickable.

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

  • phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP

    I want it to be removed.

    • 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 July 2013

    @phreak to replace links with Link Removed in italics

    try this:

    replace this in class signatures plugin

       // Don't show empty sigs, brah
             if ($UserSig == '') return;
    
             $Sender->UserSignature = Gdn_Format::Html($UserSig);
             $Display = $Sender->FetchView($this->GetView('usersig.php'));
             unset($Sender->UserSignature);
             echo $Display;
          }
       }
    

    with this

          // Don't show empty sigs, brah
             if ($UserSig == '') return;
    
             $Sender->UserSignature = Gdn_Format::Html($UserSig);
             $Display = $Sender->FetchView($this->GetView('usersig.php'));
             unset($Sender->UserSignature);
    
             $pattern[0] = '/(<a.*<\/a>)/si';
             $pattern[1] =  '|(&lt;a.*&lt;/a>)|si';
             $pattern[2] =  '|<a.*&lt;/a>)|si';
             $pattern[2] =  '|(&lt;a.*</a>)|si';
             $StrippedLinks = preg_replace($pattern, "<i>Link Removed</i>", $Display);
    
    
    
             echo $StrippedLinks;
          }
       }
    

    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 July 2013

    add this if you also want to remove things like blah.ie www.mytest.com that are not links

    I created this pattern it seemed to work for most.

    $pattern[3] = '|(([A-Za-z0-9-_/]+[\.]){1,2}[A-Za-z0-9-_/]+)|si';

    I impressed myself at least :).

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

  • phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP

    @peregrine: Wow thanx for the snippet. It removes the image completely and write "Link removed" below. That is not exactly what i wanted to reach. My need would be that the picture stays but the link gets removed. Usually people put images with links around them in the signature. The links are not needed they come as a kind of search engine optimization and the user do not really interact with the link, but the picture is important to them.

    Is it possible to keep the image but strip the link meaning [a href=""][img src="" /][/a] becomes only [img src="" /]?

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
  • you are trying to do something quite difficult. You can remove anchors but, removing urls it has to differentiate between an image url and a url to link a site. In reality these could be identical.

    what you could is strip all all remote urls not in an image tag. this is quite a complex regpx, because look behinds cannot be variable length, so you must first parse all the images so they are in predictable form, then replace urls with a negative look behind to ensure it is not an image.

    grep is your friend.

  • phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP

    Mmh, i understand. I initially thought that it would be possible by doing following or i thought Vanilla has the tools on board to do it like this.

    1.) Strip everything behind "<a" till and including the next ">"
    2.) Strip "<a"
    3.) Strip

    But maybe there are way smarter ways to do this.

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
  • x00x00 MVP
    edited July 2013
    $UserSig = preg_replace('`(<img )(.*?)(src=[\'"]?[^\'"]*[\'"])([^>]*?>)`i', '\1\3 \2\4',$UserSig);
    $UserSig = preg_replace('`(?<!(\<img src=[\'"]))(([a-z-9\+\.]*)://[\@a-z0-9\x21\x23-\x27\x2a-\x2e\x3a\x3b\/;\x3f-\x7a\x7e\x3d]+)`i', '',$UserSig);
    $Sender->UserSignature = Gdn_Format::Html($UserSig);
    

    this is probably a bit more than you usually get from free help, so consider this a gift.

    Note img src which are not always wrapped in quote will always be stripped, but that is is their problem, it is a redundant form anyway.

    grep is your friend.

  • phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP
    edited July 2013

    Thanx @x00, can you also tell me where to insert the code, i tried it in several places in the claa php and it didn't work.

    Also your commentary feels like your mean that giving help code wise to that extend is like beeing exploitet a little, so you are open to outline this as a gift. I hope you still consider me a valuable member to this small community also giving back in support, free badges and so on. I take that gift as valuable to one that is not only exploiting the community like a come by>want>and go-user. :)

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
  • It is not against you, I'll just protecting myself against other people , who will take this gift as free reign to ask me to do work for them for free.

    I'm not saying you are exploitative. I'm just saying the modification to existing functionality (not to do with me), is on the fringes of help you expect to be free. This is true of any user.

    Primary support, is one thing to do things were the functionality already exists.

    It is just more and more people expecting a "how do I do this?" question answered and it is actually a lot of work they are expecting, it is more than existing functionality, and it is not as trivial as they seem to think.

    I am also one random guy, nobody is under any obligation, your contribution is your contribution an my contribution is my contribution, we can only collaborate with applicable skills.. Obviously by helping out, it does help my cause somewhat, but I have to balance that out by not getting too carried away.

    And maybe I don't get it right first time, I'm now under an implied obligation, to sort out this problem for the questioner, when I have little time to do that. Rather than giving pointer, or suggestion so they can actually try an understand it.

    This is something I had to draw on a fair bit of experience to be able to do, and I had to test it. I didn't know it was going to work first time. It is more than a pointer. That is why I’m saying it is a gift.

    Now back on topic. In the original code you had

    $Sender->UserSignature = Gdn_Format::Html($UserSig);
    $Display = $Sender->FetchView($this->GetView('usersig.php'));
    unset($Sender->UserSignature);
    

    substitute with

    $UserSig = preg_replace('`(<img )(.*?)(src=[\'"]?[^\'"]*[\'"])([^>]*?>)`i', '\1\3 \2\4',$UserSig);
    $UserSig = preg_replace('`(?<!(\<img src=[\'"]))(([a-z-9\+\.]*)://[\@a-z0-9\x21\x23-\x27\x2a-\x2e\x3a\x3b\/;\x3f-\x7a\x7e\x3d]+)`i', '',$UserSig);
    $Sender->UserSignature = Gdn_Format::Html($UserSig);
    $Display = $Sender->FetchView($this->GetView('usersig.php'));
    unset($Sender->UserSignature);
    

    grep is your friend.

  • btw this strip anything vaguely like a absolute url form a sig, except a specific format of image. It doesn't attempt to prettify or remove tags, it doesn't care about tags. You would think upon seeing that it doesn't work the spammer would abandon this strategy.

    grep is your friend.

  • x00x00 MVP
    edited July 2013

    if you want to strip all a tags you can have an additional line

    $UserSig = preg_replace('`</?a([ ][^>]*)?>`i', '',$UserSig);
    

    grep is your friend.

Sign In or Register to comment.