Questions From a Modder New to Extensions

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Questions From a Modder New to Extensions

Post by Haravikk » Tue Sep 29, 2015 6:12 pm

So I'm new to extensions in phpBB 3.1, but have written mods for earlier phpBB versions in the past, but I have a few questions. Sorry if some of these are simple; I've tried looking for answers to them all already, but may have just confused myself and missed the answers, so please don't be too harsh even if I deserve it ;)
  • Changing Template Variables: I know there now lots of great events for appending new template data to existing styles, but what I really need to is change the contents of an existing template variable, but I'm having a tough time figure out where the correct place to do this would be. Of course with modding I'd just do a search for the variable name in the PHP files and just slap in some code, but that's not the way things are done anymore :D
    If it makes the question simpler, the variable I need is available to all templates (i.e- it's a global template variable) and I assume it's one of the modify events but I guess I'm just a little lost, or have missed the one I need. I don't suppose there's an example that does this?
  • Changing HTTP headers: Another one where I'm probably just messing the correct place to do this, but basically I'd like a chance to adjust HTTP headers before certain pages are output. What would be the most efficient way to do this? If possible, I'd like to avoid a single callback for all files, as this would mean I'd have to test against every file I'm interested in, and adjust behaviour accordingly (and some get all the possible variables I may need). Put another way, for viewforum.php I'd like a chance to edit headers using the current forum's data, for viewtopic.php I'd like to do the same using topic data and so-on.
  • Attachment Processing: I want to add improved support for a type of attachments, and would like to generate some extra data once such an attachment is uploaded. Is it possible to do this? I know there are events for after a post has been made, so I'm thinking I need one of these, but I'm unclear about how I get at the attachments I need, and how I would produce an error if one of them is malformed?
Again, apologies if these are actually simple things and I've missed them utterly.

Hopefully I can get a better grasp soon, as I have quite a few mods I'd like to port as extensions, and maybe actually release this time around (most ended up as such a mess I couldn't bring myself to extract them from my own forum and release them for others that might want the same features). Extensions ought to make this much, much easier.

rxu
Extensions Development Team
Posts: 2993
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: Questions From a Modder New to Extensions

Post by rxu » Wed Sep 30, 2015 3:51 pm

First of all, you shouldn't be confused with the event names as those are just names. They don't restrict you in the means they can be used. Thus, all you need is just select an appropriate event comforming your own needs.
In particular:
Haravikk wrote:the variable I need is available to all templates
Haravikk wrote:basically I'd like a chance to adjust HTTP headers before certain pages are output
You can use core.page_header_after for both tasks.
Haravikk wrote:Attachment Processing
Depending on your needs again, f.e. core.parse_attachments_modify_template_data.

Haravikk
Registered User
Posts: 261
Joined: Sat Nov 02, 2002 4:42 pm

Re: Questions From a Modder New to Extensions

Post by Haravikk » Fri Oct 09, 2015 3:19 pm

Thanks for the response, these look suitable for my needs!

I do have a few other questions though:
  • Sharing Code: I'm investigating several mods that I made to a forum but never got round to packaging (as they'd become pretty tightly embedded with the core code) and one thing that they do is share several useful classes that I've created. But I'm wondering what the best way to do this would be with extensions? I was thinking of creating a separate extension for the shared code, but this would mean it would be a library type extension (i.e- it adds nothing to the forums other than the ability to install my other mods), and I'm not clear on the best way to make the shared code available, is there a mechanism for checking for the presence of an extension and then getting a path to it (in case it's renamed or moved or something)?
  • Adding buttons to posts: One of the mods I'll be working on needs to add a button to individual posts (next the report post, quote etc. buttons). I can see that there are events for adding HTML to this section before or after the buttons specified in the template, but is there a way to do this generically? For example; in pro silver a button is an <li> tag containing a span with the button class (wrapped in a link), but if I simply add that myself then it may not be compatible with a style that uses a table, or divs or whatever. Is there a generic template for this type of button somewhere that I can draw upon instead to get a style specific button without having to know any of the details of the style?

rxu
Extensions Development Team
Posts: 2993
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation
Name: Ruslan
Contact:

Re: Questions From a Modder New to Extensions

Post by rxu » Fri Oct 09, 2015 4:56 pm

Haravikk wrote:Sharing Code
Well, if you need an extension which does nothing but sharing its classes/methods, just don't create a listener for it. You can only declare its service(s) and implemet them in any file you want, like helper.php etc. Then, if you enable the ext, you'll be able to use the services you created in it witnin another extensions.
Haravikk wrote:Is there a generic template for this type of button somewhere that I can draw upon instead to get a style specific button without having to know any of the details of the style?
Regrettably, not. You either have to add it for every specific style or just let it go for all styles using all style folder name.

Post Reply

Return to “Extension Writers Discussion”