Wedge

Public area => The Pub => Plugins => Topic started by: CerealGuy on February 8th, 2014, 02:36 PM

Title: [Plugin] HideMod v1 (old)
Post by: CerealGuy on February 8th, 2014, 02:36 PM

This is the old version, there is now v2.0. To get the old version, check out the v1 branch in the repository.
https://github.com/C3realGuy/Wedge-Hide/tree/v1




Here we go, first Plugin from me <_<.
First i'm not that good and experienced coder but i like wedge and its quite fun to play with it. Therefore i thought to create a small plugin. It's still alpha and not recommend for public usage because there are still some bad bugs ^^ But perhaps someone is interested in it. It's really not finished because im struggling with some problems with which some of you perhaps can help me :blush:.
But first github url :D
https://github.com/C3realGuy/we_HideMod

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? I understood some basic things of that xml block but just discovered that before/after stuff which is not what i need. I need to decide whether the user is allowed to see it or not ^^ Therefore a param in the bbcodeblock which links to a function or something like that would be very nice and surely cool for other plugins

The next problem is that there's no hook in the quickquode stuff which allows to look into the hidden code ^^

If i could fix one of those two problems it would be perhaps ready for "real" use.

Of course any feedback is welcome except for "hide mods are stupid and a foolish thing because of...". I know that there are people who don't like it because of the useless spam posts and stuff but also a lot people like it :eheheh:

Posted: February 4th, 2014, 09:01 PM

A small update: looked again into hooks and stuff and found post_bbc_parse. Sounds right but for some reasons it doesnt works like i supposed it would. And we would need a sqlquery to discover which postid this post has and bbcode would also work in Shoutbox/PM?! Where it's kinda useless :D And for some reasons first posts seems to be cached or the hook doesnt get called whats not good for this type of plugin ^^ ManagePlugins --> knownHooks is quiet interesting ;)
Posted: February 5th, 2014, 05:47 PM

Nobody any ideas? :sob:
Title: Re: [Plugin] HideMod
Post by: live627 on February 9th, 2014, 02:15 AM
Ideas about what? Which hook to use? The one in parse_bbc. Hook or XML? Probably hook.

Will explain later, gotta run right now.
Title: Re: [Plugin] HideMod
Post by: CerealGuy on February 15th, 2014, 05:56 PM
Added a custom hook in the corefiles whick makes it working properly.
Interesed? Have a look at it :D
https://github.com/C3realGuy/we_HideMod
Title: Re: [Plugin] HideMod
Post by: CerealGuy on March 6th, 2014, 12:37 PM
UPDATE:
I changed from display_post_done to post_bbc_parse.
The upside is now, that the bbc is parsed properly everywhere, not only if someone views posts in forum. Also posts are correctly processed via showposts in profile or if you use the search. Im pretty happy with this solution, thanks to @Nao :)

PS: Is it possible to change this topic or create a new one? Cant edit my posts and im not happy with the informations about that plugin. They are too old ^^
Title: Re: [Plugin] HideMod
Post by: CerealGuy on March 14th, 2014, 07:54 PM
UPDATE:
Now reloads page on like if post contains hide and disables unlike on posts with [hide]. Plugin should be ready for "real" use. Therefore i would like to edit the Thread :)
Title: Re: [Plugin] HideMod
Post by: Nao on March 15th, 2014, 12:17 AM
Hmm, that would imply giving you moderator permissions for this board... :^^;:

Too bad there aren't per-topic permissions available, ah ah...
Title: Re: [Plugin] HideMod
Post by: Farjo on March 15th, 2014, 01:21 PM
Why not switch on the modify own post permission?
Title: Re: [Plugin] HideMod
Post by: Nao on March 15th, 2014, 01:58 PM
No, the grace period applies to that. Only the modify all posts permission is exempted.

That would require adding a 'bypass grace period' permission, I guess.
Title: Re: [Plugin] HideMod
Post by: Farjo on March 15th, 2014, 04:45 PM
So perhaps, in the short term, it's easier for CerealGuy to open a new topic? Then permissions etc can be discussed later.
Title: Re: [Plugin] HideMod
Post by: Nao on March 27th, 2014, 10:51 PM
Quote from Nao on March 15th, 2014, 01:58 PM
That would require adding a 'bypass grace period' permission, I guess.
Done!

I need to test it, though...
Anyone wants to have permission to edit their own posts forever? :P

Gave permission to CerealGuy, in case he wants to confirm it works!
Title: Re: [Plugin] HideMod
Post by: CerealGuy on March 28th, 2014, 11:13 PM
Quote from Nao on March 27th, 2014, 10:51 PM
Quote from Nao on March 15th, 2014, 01:58 PM
That would require adding a 'bypass grace period' permission, I guess.
Done!

I need to test it, though...
Anyone wants to have permission to edit their own posts forever? :P

Gave permission to CerealGuy, in case he wants to confirm it works!
Aaand im not able to edit it or i dont see the option...
Title: Re: [Plugin] HideMod
Post by: Nao on March 29th, 2014, 03:28 PM
Oh... Bugger.
Title: Re: [Plugin] HideMod
Post by: Nao on March 31st, 2014, 04:10 PM
This one's fixed... I broke the rest of Wedge by fixing it, though... :lol:
Well, technically I was trying to fix topic privacy, and it backfired because of a logic loop. I'm trying to find a solution for that. I'll get back to you guys when I find it... If I do!
Title: Re: [Plugin] HideMod
Post by: Nao on April 1st, 2014, 08:05 PM
Fixed... I think, eh! ;)
Title: Re: [Plugin] HideMod
Post by: Maxx on April 1st, 2014, 08:08 PM
Scary stuff... I break stuff all the time..I hope it's me anyway.. Where did they get the saying I was beside myself? :)

regards,
Maxx
Title: Re: [Plugin] HideMod
Post by: Nao 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...
Title: Re: [Plugin] HideMod
Post by: Maxx 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)!
regards,
Maxx
Title: Re: [Plugin] HideMod
Post by: CerealGuy 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]
  <bbcodes>
    <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>
    <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>
    </bbcode>
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.