« [Plugin] CountLikes
[Plugin] HideMod v1 (old)


  • Dadman with a boy
  • Posts: 16,079
[Plugin] Re: HideMod
« Reply #15, on April 1st, 2014, 08:15 PM »
It's been a long week, for me... :-/

I still have 15+ PMs left to read, for instance. Same for e-mails. Argh...

[Plugin] Re: HideMod
« Reply #16, on April 1st, 2014, 08:17 PM »
I could imagine, ya gonna tack a break?
Wedge, can Nao come out and play? :)

If mine let it burn (PM)!


  • Posts: 343
[Plugin] Re: HideMod
« Reply #17, on January 22nd, 2017, 12:05 PM »
Quote from CerealGuy on February 8th, 2014, 02:36 PM
Im using the display_post_done hook to replace the hide(-reply) stuff and check if user is allowed to do so. But perhaps the bbcode stuff in plugin-info.xml is bether?
Quite an old one, but I finally found a solution for this and wanna share it with you.
The Problem with my first approach was that i used regexes to figure out where my
bbc tags for hide & hide-reply where. So I didn't drop in the normal bbc parsing wedge
does and did it just after everything was already parsed. This is a thing which definetly
can be done, but it has many downsides. For example you have to handle every "special"
cases the wedge bbc parser handles already again. Like bbc tags inside a code tag etc.
And you have to make sure that your regex really works in every case :lol:
All in all it would be better to just inject it somehow in the normal bbc parsing process.
And it's possible, even when you want to do more complex stuff like in this plugin.
The key to glory is the validate-func which allows us to inject php code in the normal bbc
parsing process. Because the most bbc tags only add some html before or after and don't
care about who's viewing this post (we do, because we want to determine if the current user
is allowed to watch the content in the hide tag or not).
I guess the purpose of the validate-func was to validate anything related to the tag in more
complex use cases. Eg. validating complex urls or stuff like that. But we can also modify the
part of the message containing the bbc tag, and that's what we want to do.
All you need to do is adding a php file to your plugin with a function which gets called by the
validate-func eval block. And you need to add the bbcodes to your plugin-info.xml:
Code: [Select]
    <bbcode tag="hide" type="unparsed_content" block-level="no">
      <content>HIDDEN CONTENT: Like to see</content>
      <validate-func>loadPluginSource('CerealGuy:HideModv2', 'src/Hide'); validate_hide_bbc($tag, $data, $disabled);</validate-func>
    <bbcode tag="hide-reply" type="unparsed_content" block-level="no">
      <content>HIDDEN CONTENT: Reply to see</content>
      <validate-func>loadPluginSource('CerealGuy:HideModv2', 'src/Hide'); validate_hide_reply_bbc($tag, $data, $disabled);</validate-func>
As you see, i call plugin function named "validate_hide_bcc" (or "validate_hide_reply_bbc") with three arguments.
If you catch them in your function header as referenced variables, you are free to modify all values of them. Play around with them, you will understand what's where easily.
Sounds straight forward, but there was still a hurdle to clear. The Problem was that I didn't know of which type my bbc tags have to be. With some types just nothing happend, with some others it got parsed at some times and sometimes not. Don't ask me why, i didn't understand the differences and purposes of those types. Maybe someone knows this stuff @Nao? :whistle:.
Anyways finally i found the right one, "unparsed_content".
This was a small background report about stuff which took me quite some time to figure out. Maybe it helps somebody.

Tl;dr: If you want to do more complex stuff with bbc tags, add them via plugin-info.xml and use the validate-func to inject your own code. Setting the type of your custom bbc tags to "unparsed_content" did work for me best, other types didn't work out that good.

« [Plugin] CountLikes