Root Path with Includes

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
david63
Registered User
Posts: 16561
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Root Path with Includes

Post by david63 » Sat Apr 04, 2015 7:44 am

I have the following code within my listener file

Code: Select all

	if (!class_exists('parse_message'))
		{
			include($this->root_path . 'includes/message_parser.' . $this->phpEx);
		}
This is fine and is not a problem. However the first thing that message parser does is to include includes/bbcode.php - the only problem is that $phpbb_root_path and $phpEx are not valid and a not found error is returned.

If I add global $phpbb_root_path, $phpEx; to the message parser file then the problem goes away (not a practical solution I know). Altenativly if I add

Code: Select all

if (!class_exists('bbcode'))
		{
			include($this->root_path . 'includes/bbcode.' . $this->phpEx);
		}
before my previous include then that solves the problem but is that the correct way, or am I missing something?
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

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

Re: Root Path with Includes

Post by rxu » Sat Apr 04, 2015 9:53 am

Where is the listener getting called (couldn't find core.report_post_submit event anywhere)?

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

Re: Root Path with Includes

Post by david63 » Sat Apr 04, 2015 10:12 am

rxu wrote:Where is the listener getting called (couldn't find core.report_post_submit event anywhere)?
It's an extension that I am working on that will require a new event adding - but it would be in report.php around line 290
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

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

Re: Root Path with Includes

Post by rxu » Sat Apr 04, 2015 10:32 am

Both vars are defined in report.php, so it shouldn't be bringing any issues, weird. Are you getting error about failed to open stream?

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

Re: Root Path with Includes

Post by david63 » Sat Apr 04, 2015 10:36 am

Full error message is

Code: Select all

[phpBB Debug] PHP Notice: in file [ROOT]/includes/message_parser.php on line 24: Undefined variable: phpbb_root_path
[phpBB Debug] PHP Notice: in file [ROOT]/includes/message_parser.php on line 24: Undefined variable: phpEx
[phpBB Debug] PHP Warning: in file [ROOT]/includes/message_parser.php on line 24: include(includes/bbcode.): failed to open stream: No such file or directory
[phpBB Debug] PHP Warning: in file [ROOT]/includes/message_parser.php on line 24: include(): Failed opening 'includes/bbcode.' for inclusion (include_path='.;C:/php/pear')

Fatal error: Class 'bbcode' not found in C:\htdocs\phpbb312_dev\includes\message_parser.php on line 32
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

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

Re: Root Path with Includes

Post by rxu » Sat Apr 04, 2015 11:35 am

Nah, global $phpbb_root_path, $phpEx; seems to be the solution. I wonder if it's worth to adjust message_parser.php by adding to the header

Code: Select all

$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
as it can become the common problem for extension authors.

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

Re: Root Path with Includes

Post by david63 » Sat Apr 04, 2015 11:48 am

Presumably either of those options will be a core change - are you doing the bug report or do you want me to do it?

Is this likely to be an issue with any other includes?
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

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

Re: Root Path with Includes

Post by rxu » Sat Apr 04, 2015 12:00 pm

david63 wrote:are you doing the bug report or do you want me to do it?
Either way is good, I can file a ticket about that + PR.
david63 wrote:Is this likely to be an issue with any other includes?
Well, I didn't investigate all phpBB files regarding this issue but in most cases the core is performing 'includes' within functions, so that $phpbb_root_path and $phpEx are defined.message_parser.php performs the include outside of any functions/methods, so there's a possibility for those vars to be undefined.

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

Re: Root Path with Includes

Post by david63 » Sat Apr 04, 2015 12:12 pm

Bug report here
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

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

Re: Root Path with Includes

Post by rxu » Sat Apr 04, 2015 5:23 pm

Adding $phpbb_root_path and $phpEx definitions to the message_parser.php is breaking the tests, since tests overriding the vars values with their own.

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

Re: Root Path with Includes

Post by david63 » Sat Apr 04, 2015 5:59 pm

Do we have a "plan B"?
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

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

Re: Root Path with Includes

Post by rxu » Sat Apr 04, 2015 6:30 pm

Not yet. Test failing looks unrelated to the changes made, I think we should sort out the cause of that (time-related: https://travis-ci.org/rxu/phpbb3/jobs/57157584).

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

Re: Root Path with Includes

Post by VSE » Sun Apr 05, 2015 6:52 am

You're gonna have to use global $phpbb_root_path and $phpEx if you want to include an "old" class like the message parser which is not part of the new framework (symfony, dependency injection, services, etc).
Dictated but not read.
Official phpBB Extensions My Extensions & MODs
Please do not PM me for support.

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

Re: Root Path with Includes

Post by rxu » Sun Apr 05, 2015 8:14 am

VSE wrote:You're gonna have to use global $phpbb_root_path and $phpEx if you want to include an "old" class like the message parser
The idea was placing global right in the message_parser.php, but it magically breaks the tests: https://travis-ci.org/rxu/phpbb3/builds/57157583

EDIT: it looks like they've fixed timezones DST issue and now the build is passing. Nice.

Post Reply

Return to “Extension Writers Discussion”