• Extensions
  • Luceos' Minis, local extenders simplified

Minis

License Latest Stable Version Total Downloads

A Flarum extension that is not really an extension.

Every Flarum installation comes with a file extend.php which allows you use any Flarum extender without creating a full-fledged extension. For the past several years I have been writing several examples to show people how to use this. I thought it wise to move some of these into their own extension so that you can use these extenders with less code.

Your extend.php lives in the root installation path of Flarum, next to config.php and flarum.

Installation

Install with composer:

composer require luceos/minis:"*"

Updating

composer update luceos/minis:"*"

Extenders

How to use

Inside your extend.php in the Flarum installation path you will see some lines, at the bottom you will find something like:

return [

];

Between the [ and ] you can add the follow extender snippets. I've given examples for each of them.

User - Email

Luceos\Minis\User\Email\RequireDomain - limits the email domains that can sign up.

  new Luceos\Minis\User\Email\RequireDomain('@flarum.org', '@gmail.com'),

Post - Throttle

Luceos\Minis\Post\Throttle\InTag - throttles how fast a user can reply or create discussions in a certain tag

Allow replying and creating discussions only once every five minutes in the tag with slug advertisements.

  (new Luceos\Minis\Post\Throttle\InTag('advertisements'))
    ->op(true)
    ->reply(true)
    ->interval(fn (\Carbon\Carbon $carbon, \Flarum\User\User $user) => $carbon->subMinutes(5)),

Check the Carbon documentation in how to use the interval settings with carbon: https://carbon.nesbot.com/docs/#api-addsub.

Allow creating discussions only once every day in the tag with slug advertisements.

  (new Luceos\Minis\Post\Throttle\InTag('advertisements'))
    ->op(true)
    ->interval(fn (\Carbon\Carbon $carbon, \Flarum\User\User $user) => $carbon->subDay()),

Post - Formatting

Luceos\Minis\Post\Formatting\AllowElement - allows using a html element in the editor/composer

  new Luceos\Minis\Post\Formatting\AllowElement('iframe'),

Links

    luceos That's great

    Can we apply it on multiple tags and disable it for replies like this?

    (new Luceos\Minis\Post\Throttle\InTag('advertisements, introduction, newtag'))
        ->op(true)
        ->reply(false)
        ->interval(fn (\Carbon\Carbon $carbon, \Flarum\User\User $user) => $carbon->subMinutes(5)),
      9 days later

      luceos Getting this error while installing (I'm running 1.8.5)

      Problem 1
          - Root composer.json requires luceos/minis *, found luceos/minis[dev-main, 0.1-beta.1] but it does not match your minimum-stability.

        HD3D oh yeah, use

        composer require luceos/minis:"@beta"

          luceos Thanks a lot @luceos , is there any way to limit 50 discussions per day?

          Getting syntax error and saving the file takes the forum offline:

          Sorry to bother you but can you please help with it? @luceos

          luceos I like the approach Luceos, and the intention is good, but I think it would be more useful for the user if the extension would allow to create these extends from the backend instead of having to go to the extends.php file.

          In WordPress there is an extension that allows you to create "code snippets" that can override the WordPress core. For example if a user wants the reader to not see the admin bar, or wants the classic editor to load instead of Gutenberg, they can just create a code snippet with a pr of lines for each thing and enable/disable as they please.

          The advantage of this is that the code snippet stores the Overide in the database, so there is no need to modify any files locally. This ensures more control over each installation, minimises the risk of breaking the site, and avoids having to install an extension for simple things.

          I've tried to create something like this, but my knowledge of Flarum is not yet ripe for it.

          2 months later

          Hey, @luceos

          I don't know if this discussion is the right place to post this. But, I want to extend my flarum app: just want to add a dynamic button in the profile page.

          I have a custom app: www.myapp.com
          And, a community portal: www.myapp.com/community

          I got SSO working, so the user uses both the products with the same username and profile.

          My custom app has a profile page: www.myapp.com/profile/$username
          Similarly, flarum community also has a profile page: www.myapp.com/community/u/$username

          I want to provide a button in the community profile page that directs you to the custom app's profile page

          Something like this

          The button is dynamic - it will require the username - and public. How can I do this?