"Hide" shortcode

(Maestro Magnifico) #1

On my forum there’s a topic where guys make giveaways. And post authors decide themselves to who they want to giveaway their stuff. For this we have [hide]text[/hide] shortcode now (we’re on phpBB currently, gonna migrate soon) that hides text from guests by default. But also authors can specify how many posts users should have to see their hidden text. Like this: [hide=200]text[/hide]. It’s very handy for givaways and it would be cool to have this functional in Discourse. Otherwise I’ll have to write a JS crutch that will rip off hidden text after is was loaded on page and we all understand how easily this method can be hacked.

Customize BBcodes from admin panel
(Sam Saffron) #2

One sec, can you explain this a bit more, never heard of shortcodes before.

Can you describe this in a bit more detail and link to an example.

(Jens Maier) #3

I think “shortcode” is just another term for BB-code.

And the feature he wants is a bbcode that emits

  • if there is no parameter and the current user is registered and activated or if there is a parameter and the current user has written at least this many posts: its contents,
  • in all other cases: nothing.

Since Discourse caches the cooked post, a Discourse-specific version of this feature would either be significantly harder to write (replace tag content with clickable placeholder, fill in hidden content async on click with permission check on server), or would be laughably insecure (content present in cooked post, hidden via CSS, revealed by JS).

(Maestro Magnifico) #4

I’m not sure how you calling this. In Wordpress it’s shortcodes, in phpBB it’s BBcodes. Your spoiler plugin is a thing I’m talking about. Here’s plugin that we use, you can see examples there. It also can give access to text to a certain group but guys from my forum didn’t found this handy, so I’m not sure about benefit of this part.

(Jeff Atwood) #5

Yes, @zogstrip is working on this using the HTML 5.1 features <element> and <detail>

<details>: The Details disclosure element - HTML | MDN

[details=the summary]blablabal[/details]

will generate

<summary>the summary</summary>

It almost works now, but the tags are only supported on Chrome and Safari…

(Sam Saffron) #6

Reading through the plugin linked this is slightly different to spoiler, its about giving permission to certain groups to read parts of a post.

Technically building that is a nightmare wrapped in a nightmare.

(Sigurður Guðbrandsson) #7

I figure the least nightmarish way to go would be to add a model and a controller that pull the hidden code through ember’s ajax somehow.

Writing this would truly be a nightmare, but it’s a worthy challenge as a plugin for anyone who isn’t busy for a couple of weeks or so…

… not me though :wink:

(Jeff Atwood) #8

Oh yes we’re not doing that at all. That is not even on the radar. If that’s the case just have them post in a category that only allows trust level 1 or trust level 2 users or higher (or a group)…

But hidden text, with a summary, has been requested many times and we’re about to do it.

(Jacob Chapel) #9

That actually makes sense IMO. If the goal is to prevent guests or users under a certain level, having a category that they can only see is the way to go. It is a bit more cumbersome but serves the purpose and avoids disappointing guests who won’t even know they are missing out.

If need be, the posts with the code could be in the private category, and can be linked to from the public thread.

Is there a polyfill? Saw this but only glanced at it: Making A Complete Polyfill For The HTML5 Details Element — Smashing Magazine

(Kane York) #10

I investigated the polyfills available, and they don’t work for our usecase (needing to re-apply it to a just-inserted section of dom). @zogstrip is writing a custom one, I believe?

(Maestro Magnifico) #11

Why do you need HTML5 for this? Here’s an example of a spoiler working with HTML4 and JS. I made same one using jQuery for my old forum.

We need this only for one topic. But I guess I’ll have to split it into 3-4 now and make a category for each one. Sounds obesity thought.

(Régis Hanol) #12

Actually it’s HTML 5.1. And since this will be standard, we’d rather have a small polyfill in the meantime than implement a custom element :wink:

Here's an example

of the plugin in use :wink:

(Jacob Chapel) #13

Where’s the plugin so I can install it?

(Régis Hanol) #14

Sorry, I forgot to link to the topic :smile:

(Maestro Magnifico) #15

If this is not supported by FireFox and IE yet, then I think it’s better way to use JS for now. Considering that HTML 5.1 approach is not much easier than JS one.

(Jacob Chapel) #16

See post above you. Install that and you have what you want, it uses JS for browsers that don’t support it.

(Jeff Atwood) #17