Instagram feed plugin and asset path issue

I have a site where I use the GitHub - genxbe/kirby3-instagram: Fetch instagram photos without the need for app aproval plugin.

All is generally working well, and I have used this plugin on a different site before without issues.

The difference on this project is that I’ve added a “custom folder setup

So now, my actual asset folder is at public/assets, whereas the instagram assets get downloaded to /assets on the root.

I’ve tried to specify in the config a subfolder, but then I get a php error when fetching “No such file or directory”:

'genxbe.instagram' => [
        'client_id' => 'x',
        'client_secret' => 'x',
        'assetFolder' => 'public/assets/instagram', // or assets/instagram, or just instagram
        +++
    ],

I’ve also tried specifying the asset folder specifically in the index.php roots with no luck:

'assets'   => $base . '/public/assets'

It’s fetching fine, I’d just like it to fetch it to the correct asset folder. What am I doing wrong? :see_no_evil:

I would’ve thought that’s what is needed. Based on the plugin using that root: kirby3-instagram/classes/Instagram.php at master · genxbe/kirby3-instagram · GitHub

How does your custom setup look like exactly?

My index.php setup is like this:

$kirby = new Kirby([
    'roots' => [
        'index'    => __DIR__,
        'base'     => $base    = dirname(__DIR__),
        'content'  => $base . '/content',
        'site'     => $base . '/site',
        'storage'  => $storage = $base . '/storage',
        'accounts' => $storage . '/accounts',
        'cache'    => $storage . '/cache',
        'sessions' => $storage . '/sessions',
        'assets'   => $base . '/public/assets' // also tried with a trailing /
        ]
    ]);

And the config like this:

'genxbe.instagram' => [
        'client_id' => 'x',
        'client_secret' => 'x',
        'assetFolder' => 'instagram', 
        'mediaFolder' => 'media',
        'db' => 'instagram.json',
    ],

This current setup works, but saves to an “assets” folder on the top level (above /public, not within it).

If I change to something like this, I just get php errors running the fetch.

'assetFolder' => 'public/assets/instagram', 
'mediaFolder' => 'public/assets/instagram/media',
'db' => 'public/assets/instagram/instagram.json',

Some relevant added information:
It’s on kirby 4, and I know the plugin isn’t directly compatible. But I’ve used it on another site (also Kirby 4) with no problems. I’ve just added a simple:

define("DS", '/'); in the instagram.php plugin file to solve that issue.

This has also just been tested locally this far, using Laravel Herd.

Feeling kind of dumb here, but of course it was wrong with the config above mentioning /public after $base, because the actual index.php resides within the public folder.

Herd kind of picks up automatically that /public is the web-facing url (I guess through a Kirby Valet driver?)

But when I just go directly to the fetch-method in the plugin, and dd() the $kirby()->root(), I get the path without the /public folder, which further causes the issues.

Meaning, this section from line 135 in Instagram.php:

$path = kirby()->root('assets').DS.option('genxbe.instagram.assetFolder').DS.option('genxbe.instagram.mediaFolder');

…does not include the /public anywhere.

I guess the path forward now either would be to edit the code within the plugin accordingly, or to try to make adjustments to the Herd Driver? It seems like it uses default Kirby-paths instead of the ones I’ve created in public/index.php.

Any tips on direction would be appreciated :slight_smile:

Not sure I can follow you, cause yes the index.php is in the public folder, but

'base'     => $base    = dirname(__DIR__),

also moves one hierarchy up again. Shouldn’t then the paths match?

Thanks @distantnative, of course you are right – I just couldn’t read the paths properly.

So I’ve localized the problem now.

Because I’m running the following file for fetching (in the console):
php site/plugins/kirby3-instagram/fetch.php

It doesn’t use the kirby bootstrap that I’ve set up in public/index.php. It makes its own $kirby file within the fetch.php file in the plugin.

This just ends up using default paths, and that becomes an /assets folder at the top root level.

If I modify the $kirby = new Kirby with the correct paths within the fetch.php, I get the results I want. Not very elegant though, as I would like to be able to reuse the plugin code regardless of folder-setup.

What would be a more elegant way? Could I instead of creating a new $kirby in the fetch.php file, try to inherit from the index.php $kirby in any way?

working fetch.php $kirby code:

$kirby = new Kirby([
    'roots' => [
        'assets'   => realpath(__DIR__ . '/../../../') . '/public/assets',
    ]
]);

You could put the roots array in a separate file and require that file both in fetch.php and index.php to pass to the Kirby instance.

1 Like