[RFC|Merged] Extensions

These requests for comments/change have lead to an implemented feature that has been successfully merged into the 3.1/Ascraeus branch. Everything listed in this forum will be available in phpBB 3.1.
Post Reply
User avatar
Pony99CA
Registered User
Posts: 986
Joined: Sun Feb 08, 2009 2:35 am
Location: Hollister, CA
Contact:

Re: [RFC|Merged] Extensions

Post by Pony99CA »

imkingdavid wrote:There is the event overall_header_head_append that comes right before the </head> tag in overall_header.html. You can use this to add something like <link href="{T_THEME_PATH}/mystyle.css" rel="stylesheet" type="text/css">.
When I tried something like that in phpBB 3.0, it didn't work properly; I had to add my CSS file in the phpBB CSS file. Has that been fixed?

Steve
Silicon Valley Pocket PC (http://www.svpocketpc.com)
Creator of manage_bots and spoof_user (ask me)
Need hosting for a small forum with full cPanel & MySQL access? Contact me or PM me.

Blitze
Registered User
Posts: 17
Joined: Thu Feb 22, 2007 5:08 pm

Re: [RFC|Merged] Extensions

Post by Blitze »

I also have similar questions:

1.) If my extension requires it, how do I add a CSS or JavaScript file in acp?
2.) If my extension adds new permission masks, how do you add the permission language file from my extension?

User avatar
imkingdavid
Registered User
Posts: 1050
Joined: Thu Jul 30, 2009 12:06 pm

Re: [RFC|Merged] Extensions

Post by imkingdavid »

Pony99CA wrote:When I tried something like that in phpBB 3.0, it didn't work properly; I had to add my CSS file in the phpBB CSS file. Has that been fixed?
I wasn't aware it doesn't work in 3.0. I just tested it in my extension in 3.1 and it works for me using a template event containing a <link ...> tag to load a custom stylesheet included in the extension's style folder.
Blitze wrote:I also have similar questions:

1.) If my extension requires it, how do I add a CSS or JavaScript file in acp?
2.) If my extension adds new permission masks, how do you add the permission language file from my extension?
  1. The ACP overall_header.html file has a similar event to the one in the normal overall_header.html file: acp_overall_header_head_append
  2. I am not sure off the top of my head if there is any autoloading on language files. What I would do is listen for the core.user_setup event and add the file myself manually (there may be a better one, as the core.user_setup event is run on every page, but ultimately it needs to be an event loaded after $user->setup(), so the language array is created, and before the language strings are needed).
I do custom MODs. PM for a quote!
View My: MODs | Portfolio
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.

Blitze
Registered User
Posts: 17
Joined: Thu Feb 22, 2007 5:08 pm

Re: [RFC|Merged] Extensions

Post by Blitze »

I think that these are all things that need to be well thought out, cleaned up, and added to the documentation on how to create extensions for phpBB 3.1. Since core.user_setup runs on every page it probably isn't ideal, as this is only needed when setting permissions. Do we need a different event here?

Likewise, it appears to me that template events are 'universal/global' i.e. if I install a blog extension that adds JavaScript/CSS using the overall_header_head template event and I also install an album extension that also adds JavaScript/CSS using the overall_header_head template event, it seems to me that the JavaScript/CSS from the blog will be added even when I'm viewing the album, and vice versa.

If the above is true, does this then mean that the expectation is that when an extension author uses the template events, he/she needs to also have something like <-- IF S_BLOG --> within their template file to limit when the script is actually added? Would it be better to have a function that can be called within an extension to add scripts?

sajaki
Registered User
Posts: 86
Joined: Mon Jun 21, 2010 8:28 pm

Re: [RFC|Merged] Extensions

Post by sajaki »

imkingdavid wrote:You are welcome to take a look at the code for my topic prefixes extension. This is an example of using both PHP and Template events.
while phpbb 3.1 will require 5.3.3, your extension requires 5.4. is this intentional ?

User avatar
imkingdavid
Registered User
Posts: 1050
Joined: Thu Jul 30, 2009 12:06 pm

Re: [RFC|Merged] Extensions

Post by imkingdavid »

Blitze wrote:I think that these are all things that need to be well thought out, cleaned up, and added to the documentation on how to create extensions for phpBB 3.1. Since core.user_setup runs on every page it probably isn't ideal, as this is only needed when setting permissions. Do we need a different event here?
I did a little bit of looking around and here's what I found (in includes/functions_module.php:

Code: Select all

    /**
    * Add custom MOD info language file
    */
    function add_mod_info($module_class)
    {
        global $user, $phpEx;

        global $phpbb_extension_manager;

        $finder = $phpbb_extension_manager->get_finder();

        $lang_files = $finder
            ->prefix('info_' . strtolower($module_class) . '_')
            ->suffix(".$phpEx")
            ->extension_directory('/language/' . $user->lang_name)
            ->core_path('language/' . $user->lang_name . '/mods/')
            ->find();

        foreach ($lang_files as $lang_file => $ext_name)
        {
            $user->add_lang_ext($ext_name, $lang_file);
        }
    }
It appears to me like this automatically loads language files that look like ./ext/foo/bar/language/en/info_acp_foo.php. This is similar to the way it currently loads MOD language files located in ./language/en/mods/info_acp_foo.php. Note that this is done in the acp, so if you need the language strings elsewhere you'll need to load them manually at some point. An event may be needed for that, but I'm not sure.
Blitze wrote:Likewise, it appears to me that template events are 'universal/global' i.e. if I install a blog extension that adds JavaScript/CSS using the overall_header_head template event and I also install an album extension that also adds JavaScript/CSS using the overall_header_head template event, it seems to me that the JavaScript/CSS from the blog will be added even when I'm viewing the album, and vice versa.

If the above is true, does this then mean that the expectation is that when an extension author uses the template events, he/she needs to also have something like <-- IF S_BLOG --> within their template file to limit when the script is actually added? Would it be better to have a function that can be called within an extension to add scripts?
Yes, events are global (both template events and PHP events); any time a given event is fired, all listeners that listen for that event will be executed. Therefore, an event in a globally included template file will be applied globally. I'm not sure there's a good way around doing that, other than what you suggested (putting a template conditional around it).
sajaki wrote:
imkingdavid wrote:You are welcome to take a look at the code for my topic prefixes extension. This is an example of using both PHP and Template events.
while phpbb 3.1 will require 5.3.3, your extension requires 5.4. is this intentional ?
Yes. I am using a few things that are introduced in 5.4, so the extension will not work in 5.3.3. I would rather take advantage of those features now rather than changing later on at some arbitrary point when I feel like more people have PHP 5.4. Also, I find that people don't upgrade their PHP version until they have to, and I don't mind that the use of my extensions could be the motivation some people need for staying up to date. I have also found, from my experience, that most hosts that care about their users either already have upgraded the default PHP version to 5.4 or at least provide the ability for individual hosting accounts to use 5.4.

Unfortunately, this means that some people will be unable to use my extensions until they update their PHP version. Regardless, the reason I linked to the extension here was for people to be able to look at the code. I didn't mention it in the post in which included the link, but the extension itself is not actually ready for public testing yet; there is no UI for managing prefixes, either in the ACP or on the end-user side. So at the moment, it's not worth going through the trouble of installing it unless you just want to play around with it some.

Anyway, I realize that this topic is not meant for discussion of my extension specifically, so we should probably focus on the broader extension concept than on the specific extension to which I linked.
I do custom MODs. PM for a quote!
View My: MODs | Portfolio
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.

Blitze
Registered User
Posts: 17
Joined: Thu Feb 22, 2007 5:08 pm

Re: [RFC|Merged] Extensions

Post by Blitze »

Ok, I have put in this PR to automatically add permission language files from extensions

Blitze
Registered User
Posts: 17
Joined: Thu Feb 22, 2007 5:08 pm

Re: [RFC|Merged] Extensions

Post by Blitze »

Are there any plans to fix the relative path issue before 3.1 alpha?

User avatar
imkingdavid
Registered User
Posts: 1050
Joined: Thu Jul 30, 2009 12:06 pm

Re: [RFC|Merged] Extensions

Post by imkingdavid »

Blitze wrote:Are there any plans to fix the relative path issue before 3.1 alpha?
It would be nice, but right now it's not considered a blocker so I'm not sure it's going to get done by then. Being realistic, if I have to do everything in this comment I doubt it will be done any time soon at all. I simply don't have time to do all that right now. The patch in that PR basically works, though I'm sure it may have a few scenarios where it doesn't work perfectly.
I do custom MODs. PM for a quote!
View My: MODs | Portfolio
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.

aleha
Registered User
Posts: 143
Joined: Tue Mar 26, 2013 2:19 am

Re: [RFC|Merged] Extensions

Post by aleha »

In ACP, will the name of the tab for extension settings remain as .MODS?

Post Reply