[3.3.0-b1] ext.php & custom reasons

Discussion forum for Extension Writers regarding Extension Development.
User avatar
3Di
Former Team Member
Posts: 14346
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

[3.3.0-b1] ext.php & custom reasons

Post by 3Di » Thu Oct 24, 2019 5:38 am

As of phpBB 3.3.0-b1 a welcomed new feature has been introduced, see:

Extensions may indicate reasons why they cannot enable - https://tracker.phpbb.com/browse/PHPBB3-15257

Which breaks old methods used in 3.1/3.2, like this

Code: Select all

class ext extends \phpbb\extension\base
{
	/**
	 * Check whether the extension can be enabled.
	 * Provides meaningful(s) error message(s) and the back-link on failure.
	 * CLI compatible.
	 *
	 * @return bool
	 */
	public function is_enableable()
	{
		$is_enableable = true;

		$user = $this->container->get('user');
		$user->add_lang_ext('phpbbstudio/goa', 'ext_require');
		$lang = $user->lang;

		if (!(phpbb_version_compare(PHPBB_VERSION, '3.2.7', '>=') && phpbb_version_compare(PHPBB_VERSION, '4.0.0@dev', '<')))
		{
			$lang['EXTENSION_NOT_ENABLEABLE'] .= '<br>' . $user->lang('ERROR_PHPBB_VERSION', '3.2.7', '4.0.0@dev');
			$is_enableable = false;
		}

		if (!function_exists('curl_version'))
		{
			$lang['EXTENSION_NOT_ENABLEABLE'] .= '<br>' . $user->lang('ERROR_PHP_CURL');
			$is_enableable = false;
		}

		if (!@extension_loaded('intl'))
		{
			$lang['EXTENSION_NOT_ENABLEABLE'] .= '<br>' . $user->lang('ERROR_PHP_INTL');
			$is_enableable = false;
		}

		$url = generate_board_url(false);

		if (!$this->has_ssl($url))
		{
			$lang['EXTENSION_NOT_ENABLEABLE'] .= '<br>' . $user->lang('ERROR_SSL_STREAM');
			$is_enableable = false;
		}

		$user->lang = $lang;

		return $is_enableable;
	}

	/**
	 * Determine if the site is SSL capable
	 *
	 * https://stackoverflow.com/questions/1175096/how-to-find-out-if-youre-using-https-without-serverhttps
	 *
	 * @param  string	$url	The URL of this board
	 * @return bool				True if is capable or false otherwise
	 * @access protected
	 */
	protected function has_ssl($url)
	{
		$domain = parse_url($url, PHP_URL_HOST);
		
		$ch = curl_init('https://' . $domain);
		
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
		curl_setopt($ch, CURLOPT_NOBODY, true);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($ch, CURLOPT_VERBOSE, 0);
		curl_setopt($ch, CURLOPT_HEADER, 1);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);

		curl_exec($ch);

		$header = curl_getinfo($ch, CURLINFO_HTTP_CODE);

		if ($header === 200)
		{
			return true;
		}
		return false;
	}
}
Haven't explored yet how to use the new method, I`d like to know if someone has already tried it and get some snippet as example.

Thanks.
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 | πŸ‘¨β€πŸ«

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

Re: [3.3.0-b1] ext.php & custom reasons

Post by rxu » Thu Oct 24, 2019 4:39 pm

Well, it shouldn't really break BC as you still free to return just true or false in your is_enableable() function.
But if you want you can return a message instead of false, like that (f.e.to get a message described with 'CANT_ENABLE_EXT_BECAUSE_OF_TOO_HIGH_PHPBB_VERSION' in your extension's my_lang_file.php language file

Code: Select all

	public function is_enableable()
	{
		$language= $this->container->get('language');
		$language->add_lang('my_lang_file', $this->extension_name);
		if (phpbb_version_compare(PHPBB_VERSION, '3.2.7', '>='))
		{
			return $language->lang('CANT_ENABLE_EXT_BECAUSE_OF_TOO_HIGH_PHPBB_VERSION');
		}
		
		return true;
	}

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

Re: [3.3.0-b1] ext.php & custom reasons

Post by EA117 » Thu Oct 24, 2019 4:58 pm

Since EXTENSION_NOT_ENABLEABLE is still the message even the updated check_is_enableable() will default to using in absence of a custom message having been returned by the extension, has the new capability actually broken the previous approach being shown?

i.e. The approach shown appears to be that the otherwise uniform EXTENSION_NOT_ENABLEABLE message in the $lang array is being appended with an extension-specific message, so that phpBB will display the custom message when phpBB thinks it's simply displaying EXTENSION_NOT_ENABLEABLE. That approach seems like it would also continue working, even though there is now an option that doesn't require overriding the $lang array.

Agreed with rxu's assertion that it's not broken in terms of how the return value is being checked, either. Note when looking at the code changes, it appears there is also the option to return an array of messages, versus just a single message, versus just true or false.

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

Re: [3.3.0-b1] ext.php & custom reasons

Post by rxu » Thu Oct 24, 2019 5:13 pm

Indeed, you can also do something like

Code: Select all

return [$language->lang('CANT_ENABLE_EXT_BECAUSE_OF_TOO_HIGH_PHPBB_VERSION'), $language->lang('EXT_VERSION_UPGRADE')];
to display several different messages at once.

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

Re: [3.3.0-b1] ext.php & custom reasons

Post by 3Di » Thu Oct 24, 2019 7:12 pm

Ok, I will try again then. Thanks rxu.
rxu wrote: ↑
Thu Oct 24, 2019 4:39 pm
... it shouldn't really break BC ...
Well since that method is not available in 3.2.x I dare to say yes, it breaks BC.
If I use this method in 3.3 I can't use it in 3.2 and quite all of our extensions (say 40/50 included private ones) are 3.2 / 3.3 compatible. Instead if it was I had just to amend once for good all of those, instead of duplicate them all. I don't know If I explained myself. :)

The above method is used also by other extension writers afaik.
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
Marc
Development Team Leader
Development Team Leader
Posts: 5413
Joined: Tue Oct 30, 2007 10:57 pm
Location: Munich, Germany
Name: Marc
Contact:

Re: [3.3.0-b1] ext.php & custom reasons

Post by Marc » Thu Oct 24, 2019 7:40 pm

Which method are you referring to?is_enableable() is available in 3.2 and I think the sample code rxu provided should be compatible with both 3.2 and 3.3?

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

Re: [3.3.0-b1] ext.php & custom reasons

Post by 3Di » Thu Oct 24, 2019 7:49 pm

Marc wrote: ↑
Thu Oct 24, 2019 7:40 pm
Which method are you referring to?is_enableable() is available in 3.2 and I think the sample code rxu provided should be compatible with both 3.2 and 3.3?
I meant method as "my (our) way to carry on things", not function(), more a bad translation than nothing, sorry.
I am appending my own language key onto the core's normal error message language key, which is not the same as the new method does it (function) in a different way.
And I am not sure it will be, compatible, at a first glance.

See this long discussion, is a bit long so we can start from here: viewtopic.php?p=14720796#p14720796
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
Marc
Development Team Leader
Development Team Leader
Posts: 5413
Joined: Tue Oct 30, 2007 10:57 pm
Location: Munich, Germany
Name: Marc
Contact:

Re: [3.3.0-b1] ext.php & custom reasons

Post by Marc » Thu Oct 24, 2019 7:56 pm

From a quick glance I'd say have a separate language file for overriding those and then only load it when the phpBB version is not 3.3?

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

Re: [3.3.0-b1] ext.php & custom reasons

Post by 3Di » Thu Oct 24, 2019 7:58 pm

Quite ugly?
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
VSE
Extensions Development Coordinator
Extensions Development Coordinator
Posts: 4933
Joined: Sat Jan 17, 2009 9:37 am
Location: Los Angeles, CA
Name: Matt Friedman
Contact:

Re: [3.3.0-b1] ext.php & custom reasons

Post by VSE » Sun Oct 27, 2019 12:12 am

You could also, probably, just check in your is_enableable if the PHPBB_VERSION is greater than 3.3.0. If it is, return an error message array, otherwise just return the normal booleans expected in 3.1 and 3.2.

So in other words, 3.3 users will get to see a message. 3.1 and 3.2 users don't. Just another reason to push the community forward.
Dictated but not read.
Official phpBB Extensions β˜… My Extensions & MODs
Please do not PM me for support.

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

Re: [3.3.0-b1] ext.php & custom reasons

Post by 3Di » Sun Oct 27, 2019 3:19 am

As I said at Discord,
IMHO this new improvement should be back-ported to 3.2.x, adding to it an optional flag so to do not break anything.
Who wants to use it is welcome to, use the way many writers are used to otherwise. And deprecate it in 4.0, like many other stuffs.

Just 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 | πŸ‘¨β€πŸ«

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

Re: [3.3.0-b1] ext.php & custom reasons

Post by VSE » Sun Oct 27, 2019 7:13 pm

I just did this to use it in 3.3 (without affecting 3.2 or 3.1)

Basically:

Code: Select all

public function is_enableable()
{
	$enableable =  phpbb_version_compare(PHP_VERSION, '7.2', '>=');
	if (!$enableable && phpbb_version_compare(PHPBB_VERSION, '3.3.0-dev', '>='))
	{
		return ['You need PHP 7.2'];
	}
	return $enableable;
}
Dictated but not read.
Official phpBB Extensions β˜… My Extensions & MODs
Please do not PM me for support.

User avatar
david63
Registered User
Posts: 16661
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: [3.3.0-b1] ext.php & custom reasons

Post by david63 » Sun Oct 27, 2019 9:43 pm

I have not tried this yet but just a quick question - does this work the same with cli?
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

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

Re: [3.3.0-b1] ext.php & custom reasons

Post by VSE » Sun Oct 27, 2019 11:09 pm

david63 wrote: ↑
Sun Oct 27, 2019 9:43 pm
I have not tried this yet but just a quick question - does this work the same with cli?
It should. However the CLI implementation has been borked in 3.3. So extensions will just be enabled even if they are not supposed to be, via the CLI. A fix will need to be made. https://github.com/phpbb/phpbb/pull/5721
Dictated but not read.
Official phpBB Extensions β˜… My Extensions & MODs
Please do not PM me for support.

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

Re: [3.3.0-b1] ext.php & custom reasons

Post by 3Di » Mon Nov 04, 2019 6:49 am

Well, all of this does not help in my case.
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 β€œExtension Writers Discussion”