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.