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.

I can't get PremHide to work

This is the type of plugin Im looking for but unfortunately it's not working correct on my forum. Every comments and discussions are hidden if Im not logged in. Im using Version 2.0.18.8.

Also is it possible to change the code to ?

«134

Comments

  • businessdadbusinessdad Stealth contributor MVP
    edited June 2013

    @supaloopa said:
    Every comments and discussions are hidden if Im not logged in. Im using Version 2.0.18.8.

    To help other Users who will look into this, do you mean that all content is hidden, regardless of the fact that it's wrapped in a premhide tag or not?

    Also is it possible to change the code < premhide>< /premhide> to < hide>< /hide> ?

    That's definitely possible, but I reckon you would have to modify the plugin. By the way, the correct tag is prem, not premhide.

  • AdrianAdrian Wandering Spirit Montreal MVP
    edited June 2013

    @businessdad thanks did not catch they were using wrong tags! Thanks. I didn't use "hide"tag to avoid conflicts, but as you mention people can change as needed easily!

  • AdrianAdrian Wandering Spirit Montreal MVP
    edited June 2013

    If OP wants blurred image, on content,above tags that will take a lot more work, so I suggest a generic blurred image.

  • businessdadbusinessdad Stealth contributor MVP

    @adriansonline I'm not sure that @supaloopa used the wrong tag, he might have typed it wrong when he posted the message. Regardless, the plugin should still "behave" if wrong tags exist in the content.

    Out of curiosity, I had a look at the code and I found a couple of issues, perhaps you might be interested in looking into them:

    • You used preg_replace_callback() incorrectly. The callback you pass is not a valid one, and a warning is raised (although it's probably hidden by Vanilla). You should replace the function with preg_replace().
    • I'm not sure that the pattern you use, i.e. /< prem>/, is correct (note: space after opening angle bracket has been added to allow this forum to display it). I believe that ~< prem>(.*?< /prem>~ should be used instead.
    • Minor issue: you should not use call by reference anymore, as it has been deprecated in PHP 5.4.
  • AdrianAdrian Wandering Spirit Montreal MVP
    edited June 2013

    @businessdad as you note the plugin works by searching for "prem" tag and replacing content. It may be that when OP used "premhide" it added the message but did not replace the content. I'll review your other suggestions and update accordingly. I'm self taught PHP so sometimes I pick up bad habits ;)

  • AdrianAdrian Wandering Spirit Montreal MVP

    Okay @businessdad made change to the pattern, but plugin does not work without callback, though, so I am open to other suggestions.

  • To help other Users who will look into this, do you mean that all content is hidden, regardless of the fact that it's wrapped in a premhide tag or not?

    Yes all content is hidden. I might've made a mistake on using the wrong tag, but either way all content is hidden just by enabling the plugin.

  • AdrianAdrian Wandering Spirit Montreal MVP

    Can you upgrade to the new version uploaded and can you use the right tag? Can you also pm me your site so I can look it further as I cannot replicate your issue

  • businessdadbusinessdad Stealth contributor MVP

    @adriansonline said:
    Okay businessdad made change to the pattern, but plugin does not work without callback, though, so I am open to other suggestions.

    I'm not sure what you mean with that. If you use preg_replace you don't need a callback. Anyway, you can't pass array($this) as a callback, as it's not a valid callable.

  • AdrianAdrian Wandering Spirit Montreal MVP

    If I don't use preg_replace_callback the plugin stops working, that is what I meant. As for not a valid callable, I'm not 100% sure what you mean.

  • businessdadbusinessdad Stealth contributor MVP

    @adriansonline Ok, then this is an issue, because the plugin seems to work, but it's not clear why. I would strongly recommend debugging it and replacing preg_replace_callback() with preg_replace(), as I suggested, and using the regular expression I posted above.

    About the "callable"

    I posted a link that describes it in detail. A valid callable can have several formats. The most common ones are a simple function name (i.e. 'MyFunction') or an object method, passed as an array (i.e. array($SomeObj, 'SomeMethod')). That is, you cannot just pass an array like array($this), as it's not a valid callback. It works by coincidence, but it throws a warning.
    If you enable the Debug plugin in your Vanilla, which, if I'm not mistaken, treats warnings as errors, you will probably get an error and the forum won't work anymore.

  • AdrianAdrian Wandering Spirit Montreal MVP
    edited June 2013

    @Businessdad I think I will put a message until I figure how to make it work properly. Thanks for the tips

  • you are lucky it worked at all

    /<prem>(.*?</prem>/ is not a valid pattern. How the hell it work, probably isn't worth getting into, but it will have the change, becuase you can't expect this to work, and won't in most 'sane' cases.

    I presume you mean

    /<prem>(.*?)<\/prem>/

    note the closed parenthesis, and the escaping of /

    or easier written as

    #<prem>(.*?)</prem>#

    grep is your friend.

  • AdrianAdrian Wandering Spirit Montreal MVP
    edited June 2013

    @x00 it seems I have made an error completely. The pattern does not matter as it seems all content is hidden when users are not logged in regardless of shortcode. I think I'm down the rabbit hole a bit further then my PHP/Vanilla skills can help. I need to rethink this. Obviously there is a need for it, so I will try to figure it out. Thanks for the tips @businessdad as well. Lots to learn & consider

  • peregrineperegrine MVP
    edited June 2013

    edited: since you solved it.

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

  • AdrianAdrian Wandering Spirit Montreal MVP
    edited June 2013

    I think I got it working! @peregrine, you helped me with an earlier question to Tim I had found. I was using your login to debug without seeing your post--but your post did confirm I was on the right track. So now it seems to work.

  • Yes you are not pre-parsing it correctly, so it will be stripped by HtmLawed as an invalid tag.

    However you are using a hook which is before the main formatting, so if you get the pattern matching right it should work.

    I think you pattern will also struggle without modifiers depending on the content between the tags.

    grep is your friend.

  • x00x00 MVP
    edited June 2013

    The general principle would be

        $LoginStr = "Please <a href='".SignInUrl($this->SelfUrl)."'>Login </a>To See Premium Content";        
        if ($Session->IsValid()){
            $context = preg_replace($pattern, '\1', $context);
        }else{
            $context = preg_replace($pattern, $LoginStr, $context);
        }
    

    grep is your friend.

  • x00x00 MVP
    edited June 2013

    for the pattern I’d use #<prem>(.*?)</prem>#si

    s (PCRE_DOTALL)

    If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded. This modifier is equivalent to Perl's /s modifier. A negative class such as [^a] always matches a newline character, independent of the setting of this modifier. 
    

    i (PCRE_CASELESS)

    If this modifier is set, letters in the pattern match both upper and lower case letters.
    

    http://php.net/manual/en/reference.pcre.pattern.modifiers.php

    grep is your friend.

  • peregrineperegrine MVP
    edited June 2013

    works for me, easier than using preg_replace_callback - which is a bit of overkill since not much is being done in a callback function.

    nice @x00

        $context = "this is a test <PREM><i>(hidden xxx test)</i> </PREM> shown xxxx <prem> <i>(hidden yyyy text)</i> </prem> shown yyyy <p>";
         echo $context . PHP_EOL ;
         $LoginStr = "<b>Please <a href='". "http://test.com" ."'>Login </a>To See Premium Content</b>";
    
        $pattern = "#<prem>(.*?)</prem>#si";
    
        $context = preg_replace($pattern, $LoginStr, $context);
    
        echo $context;
    

    re if you actually need callbacks in vanilla tip:
    http://vanillaforums.org/discussion/comment/165351/#Comment_165351

    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.