• Extensions
  • FriendsOfFlarum upload, the intelligent file attachment extension

I'm trying to make a custom template that I want to put in the extend.php. Can anyone help me how I can do that? I've opened the wiki and read how is a template defined by extending an interface but I believe that is for extensions. I am a Java developer and can program, I'm just not familiar with PHP.

Basically what I want to do is to create a template that will generate the following text:
[$file->base_name]($file->url)

I guess I should add the following to the extend.php

use FoF\Upload\Contracts\Template;
use FoF\Upload\File;

class MyTemplate implements Template
{
    public function tag(): string
    {
        return 'filenamelink';
    }

    public function name(): string
    {
        return 'Filename link';
    }

    public function description(): string
    {
        return 'Generates a link with the filename as text';
    }

    public function preview(File $file): string
    {
        return '[' . $file->base_name . '](' . $file->url . ')';
    }
}

However I don't know how to register that template. According to the wiki, I should register it from a service provider.

I have the following in the extend.php:

return [
    // Register extenders here to customize your forum!
    (new FoF\Sitemap\Extend\RemoveResource(FoF\Sitemap\Resources\User::class))
];

Can I extend it like this:

use Flarum\Foundation\AbstractServiceProvider;
use FoF\Upload\Helpers\Util;

class MyServiceProvider extends AbstractServiceProvider
{
    public function register()
    {
        $this->container->make(Util::class)->addRenderTemplate($this->container->make(MyTemplate::class));
    }
}

return [
    // Register extenders here to customize your forum!
    (new FoF\Sitemap\Extend\RemoveResource(FoF\Sitemap\Resources\User::class)),
    (new Extend\ServiceProvider())
        ->register(MyServiceProvider::class),
];

Or ultimately to produce the following extend.php:

<?php

/*
 * This file is part of Flarum.
 *
 * For detailed copyright and license information, please view the
 * LICENSE file that was distributed with this source code.
 */

use Flarum\Extend;
use FoF\Upload\Contracts\Template;
use FoF\Upload\File;
use Flarum\Foundation\AbstractServiceProvider;
use FoF\Upload\Helpers\Util;

class MyTemplate implements Template
{
    public function tag(): string
    {
        return 'filenamelink';
    }

    public function name(): string
    {
        return 'Filename link';
    }

    public function description(): string
    {
        return 'Generates a link with the filename as text';
    }

    public function preview(File $file): string
    {
        return '[' . $file->base_name . '](' . $file->url . ')';
    }
}

class MyServiceProvider extends AbstractServiceProvider
{
    public function register()
    {
        $this->container->make(Util::class)->addRenderTemplate($this->container->make(MyTemplate::class));
    }
}

return [
    // Register extenders here to customize your forum!
    (new FoF\Sitemap\Extend\RemoveResource(FoF\Sitemap\Resources\User::class)),
    (new Extend\ServiceProvider())
        ->register(MyServiceProvider::class),
];

Is that the proper code?

    OK, I can confirm the above is working 🙂 Just tested it. But please let me know if it is not good for some reason and should be done in some other way.

    CyberGene I have not tested your code but it looks right. Everything can indeed be placed in extend.php.

    If there's any error saying a class doesn't exist, make sure no use statements are missing.

    Does the Watermark images feature requires imagick or something?
    I only have GD and I can't enable "Upload your watermark image".

      rdn I don't see any code that would disable that button in the extension.

      Maybe it's custom CSS or another extension that prevents you from interacting with the input field?

      • rdn likes this.

      Please help! It not showing as Download anymore and this is very important for us

      I'll leave that specific feature disabled for now, as I don't need the watermark option.
      Just want to report the issue.

      Thanks for the answer.

      We can't upload PDF, Zip etc Files anymore? Did you change anything? How can we solve this problem?

        Yolo we didn't. Last release, 1.1.0, is from almost a month ago.

          Yolo We can't upload PDF, Zip etc Files anymore? Did you change anything? How can we solve this problem?

          luceos Yolo we didn't. Last release, 1.1.0, is from almost a month ago.

          Same Issue here! Could it be that something does not fit with the gpx-preview plugin?

            how are you attaching the file via fof/upload or just linking via markup? - what kind of errors are you encountering if any.

            We will need way more information in order to help you. Start with the output of php flarum info and explain what might have changed from your end lately, how upload is configured etc.
            You can also dm me on discord, I can take a look when I have spare time.

            Merged 3 posts from Uploading Zip / PDF not working.

            tom23 same for you. Post more information please. This is not enough to go on.

            5 days later

            I don't know if I'm just an idiot, but I really can't figure out this MIMETYPES stuff. Sorry!

            Can someone spell out exactly how to approve pdf, doc, docx, pptx, ppt, m4a, mp3, jpg, and png?