[BETA] Filter by country - version 1.0.8

A place for Extension Authors to post and receive feedback on Extensions still in development. No Extensions within this forum should be used within a live environment!
Anti-Spam Guide
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: Extensions Development rules

IMPORTANT FOR NEEDED EVENTS!!!
If you need an event for your extension please read this for the steps to follow to request the event(s)
User avatar
EA117
Registered User
Posts: 1050
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: [BETA] Filter by country - version 1.0.8

Post by EA117 » Wed Oct 30, 2019 11:16 pm

Forgive me for not being an extension writer, and not explaining this in a way that comes through more clearly. I did not intend to take up this much of your time.

I mean for Filter by Country to do something like subscribe to the core.page_header event, and then do nothing more than set a template variable containing the country code that Filter by Country had determined "represents the country this connection is from." For example, in the core.page_header event handler function the code might look something like:

Code: Select all

	$this->template->assign_vars(array(
			'FILTER_BY_COUNTRY_ISO' => $country_code,
		));
Access to the template ostensibly involves adding \phpbb\template\template to the event listener constructor, and tracking this instance in a member like the $this->template variable used in this example.

The point being that it's not you who will generate any HTML or decide how this information gets used. You're making the FILTER_BY_COUNTRY_ISO variable available for any templates to reference, if and when they are interested in using this information.

Whether the templates use it at all, or what they might use it for, and/or whether and how it might get displayed is entirely up to the template that decides to consume it. And of course, this variable doesn't exist at all (and templates simply get a blank value) on any system where Filter by Country isn't even installed.

i.e. Just a way to "share" the determined country information with the templates, in case they can make use of it.

User avatar
3Di
Former Team Member
Posts: 14358
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: [BETA] Filter by country - version 1.0.8

Post by 3Di » Wed Oct 30, 2019 11:25 pm

Code not used within the extension is not validated.

It is possible to make another extension which hooks this one to create such template variable.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
EA117
Registered User
Posts: 1050
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: [BETA] Filter by country - version 1.0.8

Post by EA117 » Wed Oct 30, 2019 11:39 pm

3Di wrote:
Wed Oct 30, 2019 11:25 pm
Code not used within the extension is not validated.
Guess I don't understand the intention of the statement. The code described is going to be "used within the extension"... it will fire every time the core.page_header event fires. The code must indeed be correct, and I certainly would have expected should be validated since it's being executed. We're not talking about "dead code" or "an unreachable code path" from the extension's perspective.

User avatar
3Di
Former Team Member
Posts: 14358
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: [BETA] Filter by country - version 1.0.8

Post by 3Di » Wed Oct 30, 2019 11:43 pm

EA117 wrote:
Wed Oct 30, 2019 11:39 pm
3Di wrote:
Wed Oct 30, 2019 11:25 pm
Code not used within the extension is not validated.
Guess I don't understand the intention of the statement.
Shortly: if FILTER_BY_COUNTRY_ISO is not used somewhere within the extension then shouldn't be there since IT IS dead code.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
EA117
Registered User
Posts: 1050
Joined: Wed Aug 15, 2018 3:23 am
Contact:

Re: [BETA] Filter by country - version 1.0.8

Post by EA117 » Thu Oct 31, 2019 12:09 am

3Di wrote:
Wed Oct 30, 2019 11:43 pm
Shortly: if FILTER_BY_COUNTRY_ISO is not used somewhere within the extension then shouldn't be there since IT IS dead code.
Well, it certainly doesn't sound right. No caller of template->assign_vars() is ever "guaranteed" that their particular variable will actually be used by any given template. It sounds more like we're saying at best there must be a test which references the template variable, in order to validate it's being set correctly? Rather than "every template variable created must exist for use by the extension's own templates, or else it is invalid."

Otherwise, how does one ever write an extension whose pure intention is to make a new template variable available? i.e. To expose information that phpBB does not already expose to templates on it's own?" The extension itself isn't what "needs" that info... the purpose of having to write an extension was in making that info available to templates.

Regardless, whichever statement ends up being true regarding template variables, this still sounds like a hurdle that is easy enough to clear. e.g. Filter by Country could simply add a reference to the variable in the ADM style templates. To satisfy any "check whether the template variable is used" which might be considered mandatory, regardless of how arbitrarily.

User avatar
3Di
Former Team Member
Posts: 14358
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: [BETA] Filter by country - version 1.0.8

Post by 3Di » Thu Oct 31, 2019 12:17 am

What could be done is provide event(s) (in this case a PHP event) for other extensions writers to hook at.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

User avatar
MarkDHamill
Registered User
Posts: 3940
Joined: Fri Aug 02, 2002 12:36 am
Location: Florence, MA USA
Contact:

Re: [BETA] Filter by country - version 1.0.8

Post by MarkDHamill » Mon Nov 04, 2019 1:34 am

I think it was 3Di who made the suggestion to look at an array of possible HTTP headers for IP addresses. I have a client willing to test the extension on his forum. Looks like I can't assume that these headers will contain IP addresses.
Admin log with filter by country IP errors
Admin log with filter by country IP errors
So I'll need to not capture these errors anymore.
Get the latest versions of my Digests and Smartfeed extensions.
Need phpBB services or a phpBB consultant? I offer most phpBB services.

User avatar
3Di
Former Team Member
Posts: 14358
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: [BETA] Filter by country - version 1.0.8

Post by 3Di » Mon Nov 04, 2019 2:07 am

MarkDHamill wrote:
Mon Nov 04, 2019 1:34 am
I think it was 3Di who made the suggestion to look at an array of possible HTTP headers for IP addresses.
Yes, and I linked you to a topic (stack overflow) where you can see how to implement the IP evaluation, in loops.
Ofcourse you need to adapt it to the current phpBB core code which already has those functions implemented on purpose.

Just as a remind, coding questions are better to ask in the devoted venue like Ext Writers Forum since I highly doubt you are likely to get appropriated feedback here, that's your own ext-dev topic. My 2 €urocents.
Please PM me only to request paid works. Thx.
Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user
Extensions, Scripts, MOD porting, Update/Upgrades
👨‍🏫 | Take a tour to | The Studio | 👨‍🏫

Post Reply

Return to “Extensions in Development”