Correct way to access images from extension

Discussion forum for Extension Writers regarding Extension Development.
User avatar
Wolfsblvt
Registered User
Posts: 634
Joined: Sun Oct 26, 2014 9:12 pm
Location: Solingen, Germany
Contact:

Re: Correct way to access images from extension

Post by Wolfsblvt »

VSE wrote:use the "all" folder and just point directly to that and not use the user style variable.

you're extension can't have a style folder for every single style created for phpBB.
I had the image globally, but it was a request to have a style specific image. And I am quite sure there are many other use-cases where a style specific image is needed. How should you handle that?

I mean if a person using my extension has a modified style, he has to make sure that the template files are fitting with his style. That was before 3.1 and is now the same. Images ar nothing different, I would say.

One thing I am missing here is the recursive looking such a style system shouldn't just do with template files. If the file don't exist in the specific style folder, it should look in the base style folder, then in "/all", and after that in phpBB base folders in the same order.
If you have a specific extension request and you are willing to pay for, you can write me a PM.
My extensions (Trending: @Mention SystemAdvanced PollsUser Online Time)

»Du kamst zu uns. Deine Stimme kam. Du zeigtest uns die Sterne. Sie funkelten. Wir konnten sehen.«
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5281
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: Correct way to access images from extension

Post by MattF »

For images you are directly making paths to, you need to make them style agnostic. They need to be able to work the same with any style. With your current code, I don't know what it's gonna do in any case where a board has a 3rd party style you haven't added to your extension.

Try using CSS instead (that way the image will be tied to the style where the CSS comes from).

There is no recursive style searching here because in your code you are specifying a direct path to a specific file/folder. But you will get that if you add your images by CSS.

You could also try playing around with the $finder to search for your images at specific paths (like the user style path) and if it exists or not, decide what image to display (ie: https://github.com/phpbb-extensions/pag ... #L202-L211).
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
CentaurAtlas
Registered User
Posts: 50
Joined: Sun Dec 02, 2007 5:39 pm
Contact:

Re: Correct way to access images from extension

Post by CentaurAtlas »

So you would put the image in the
./ext/vendor/extension/styles/all/images/

directory and then access if from there?

Is that preferable to:
./ext/vendor/extension/styles/all/theme/images/ ?

(where 'theme' really is just 'theme' and not a placeholder for something else).
User avatar
Wolfsblvt
Registered User
Posts: 634
Joined: Sun Oct 26, 2014 9:12 pm
Location: Solingen, Germany
Contact:

Re: Correct way to access images from extension

Post by Wolfsblvt »

Hmh. I understand the problem, VSE, of course, but I can't find a real solution. I don't want to make the image globally. I want to make it style dependant. And if the administrator don't have an own style, it should use the default style.

Isn't that the expected behavior for things I include?
If you have a specific extension request and you are willing to pay for, you can write me a PM.
My extensions (Trending: @Mention SystemAdvanced PollsUser Online Time)

»Du kamst zu uns. Deine Stimme kam. Du zeigtest uns die Sterne. Sie funkelten. Wir konnten sehen.«
aleha
Code Contributor
Posts: 61
Joined: Wed Dec 19, 2012 10:42 pm

Re: Correct way to access images from extension

Post by aleha »

Wolfsblvt wrote:Otherwise you have to do what nicofuma said, use an absolute path.
You can easily achieve this with default template vars for the paths. I this in everyone of my extensions, even if I don't need them: advancedpolls - listener.php
I faced the same problem today and went with the absolute path solution.

But do you need to call the path_helper to get the root_path?
I think %core.root_path% suffices. See the boardrules official extension for an example.

https://github.com/phpbb-extensions/boa ... es.yml#L28
https://github.com/phpbb-extensions/boa ... er.php#L72
rxu
Extensions Development Team
Posts: 3430
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: Correct way to access images from extension

Post by rxu »

This topic could help a bit probably viewtopic.php?f=461&t=2291156
User avatar
RiccardoB.
Registered User
Posts: 38
Joined: Sat Nov 27, 2010 9:54 am
Location: Italy
Name: Riccardo
Contact:

Re: Correct way to access images from extension

Post by RiccardoB. »

After a year is this topic still valid or are there new helpers for including images from an extension folder?
Freelance Software Developer for Web, Desktop and Mobile.
User avatar
Sajaki
Registered User
Posts: 1376
Joined: Mon Mar 02, 2009 1:41 pm
Location: Amsterdam
Contact:

Re: Correct way to access images from extension

Post by Sajaki »

i have an image folder in the root of my ext, so i'm not serving them from the themes directory.
so view controller uses an injected path_helper, which is then passed to the view factory.
https://github.com/bbDKP/bbGuild/blob/d ... roller.php

Code: Select all

$this->path_helper	= $path_helper;
$this->ext_path_web	    = $this->path_helper->get_web_root_path($this->ext_path);
$this->ext_path_images	= $this->ext_path_web . 'ext/bbdkp/bbguild/images/';
and then i can just consume it by pre-pending $this->ext_path_images in
https://github.com/bbDKP/bbGuild/blob/d ... r.php#L133

Code: Select all

$classimgurl = $this->navigation->ext_path_images . "roster_classes/" . $class['imagename'] . '.png';
In the html, you then just parse the src field with the php variable. so this solution is fully style agnostic.

hth,
User avatar
MattF
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 5281
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: Correct way to access images from extension

Post by MattF »

I have another approach.

ABBC3 has images located at ext/vse/abbc3/images

The path to the root of my extension is easily defined just as a service parameter:
https://github.com/VSEphpbb/abbc3/blob/ ... es.yml#L13

Then it's easy to use in the class as needed:
https://github.com/VSEphpbb/abbc3/blob/ ... ay.php#L51
Formerly known as VSEMy ExtensionsPlease do not PM me for support.
User avatar
RiccardoB.
Registered User
Posts: 38
Joined: Sat Nov 27, 2010 9:54 am
Location: Italy
Name: Riccardo
Contact:

Re: Correct way to access images from extension

Post by RiccardoB. »

Thanks for the replies,
with this approach the images are not dependent by theme? Am I right?
Is it possible to use different images for at least prosilver and subsilver2?
Freelance Software Developer for Web, Desktop and Mobile.
Post Reply

Return to “Extension Writers Discussion”