problem with $user->add_lang()

Discussion forum for MOD Writers regarding MOD Development.
asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

problem with $user->add_lang()

Post by asinshesq » Thu May 31, 2007 11:31 pm

I'm not sure if this question goes here or in phpbb3 support, but here goes:

The phpbb3 version of my tabulated survey mod adds the following line early on in viewtopic.php (just after session management):

Code: Select all

$user->add_lang('mods/survey');
That line activates the language definitions I use for the tabulated survey mod, and everything normally works fine.

However, if I try to go to bring my browser to viewtopic.php without specifying a topic_id or forum_id, the page whites out rather than giving me the trigger_error message that the requested topic does not exist. The php error log reports the following:

Code: Select all

[31-May-2007 19:19:32] PHP Warning:  strtr() [<a href='function.strtr'>function.strtr</a>]: The second argument is not an array. in C:\Server\Apache2\htdocs\phpBB3_test\includes\session.php on line 1636
[31-May-2007 19:19:32] PHP Warning:  strtr() [<a href='function.strtr'>function.strtr</a>]: The second argument is not an array. in C:\Server\Apache2\htdocs\phpBB3_test\includes\session.php on line 1636
[31-May-2007 19:19:32] PHP Warning:  strtr() [<a href='function.strtr'>function.strtr</a>]: The second argument is not an array. in C:\Server\Apache2\htdocs\phpBB3_test\includes\session.php on line 1636
[31-May-2007 19:19:32] PHP Warning:  file_exists() [<a href='function.file-exists'>function.file-exists</a>]: open_basedir restriction in effect. File(/message_body.html) is not within the allowed path(s): (C:\Server\Apache2\htdocs) in C:\Server\Apache2\htdocs\phpBB3_test\includes\functions_template.php on line 60
[31-May-2007 19:19:32] PHP Fatal error:  template->_tpl_load_file(): File /message_body.html does not exist or is empty in C:\Server\Apache2\htdocs\phpBB3_test\includes\functions_template.php on line 62
When I comment out the $user->add_lang line and try to go to viewtopic.php without a topic_id, the page no longer whites out, so it's clear that the $user->add_lang line is what is causing the problem. I doubt this is relevant, but just in case here's what's in the language/en/mods/survey.php file:

Code: Select all

<?php
/** 
*
* survey [English]
*
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

/**
* DO NOT CHANGE
*/
if (empty($lang) || !is_array($lang))
{
	$lang = array();
}

$lang = array_merge($lang, array(
	'ADD_SURVEY_EXPLAIN'						=> 'You can ask any number of questions in a survey.  If you leave any question blank, the questions will not be recognized after the first blank question.',
	'ALLOW_CHANGE_ANSWERS'						=> 'Allow users to change their answers?',
	'ALPHABETICAL'								=> 'alphabetical by username',
	'AVERAGE'									=> 'Average',
	'BY_ORDER_OF_RESPONSE'						=> 'in the order that users respond',
	'CAP_RESPONSE'								=> 'If totalling, specify maximum total before users can no longer respond (blank means no cap): &nbsp;&nbsp',
	'CHANGE_YOUR_ANSWERS'						=> 'Change your answers',
	'CHECKBOX_OR_RADIO_BUTTONS'					=> 'checkbox or radio buttons',
	'CLICK_DESIGN_SURVEY'						=> 'Click here to access or hide survey design box',
	'CLICK_RETURN_TOPIC_SURVEY'					=> 'Click %sHere%s to return to the topic where the survey is located',
	'DELETE_SURVEY'								=> 'Delete survey from this post?',
	'DESIGN_A_SURVEY'							=> 'Design a Survey',
	'DROP_DOWN_MENU'							=> 'drop down menu',
	'FILL_OUT_SURVEY'							=> 'Fill out survey',
	'FILL_OUT_SURVEY_FOR_SOMEONE_ELSE'			=> 'Fill out survey for another user',
	'IF_AVERAGE'								=> 'If averaging numbers in responses, specify the number of digits to round to: &nbsp;&nbsp',
	'IF_BY_MATCHING_TEXT'						=> 'If totalling by responses matching text, specify that text: &nbsp;&nbsp',
	'IF_SELECTIONS'								=> 'If checkbox, radio buttons, multiple choice checkboxes<br />or drop down menu, specify selections separated by semicolons<br />(if drop down menu, beginning with semicolon allows user to make no selection): &nbsp;&nbsp',
	'LARGE_TEXT_BLANK'							=> 'large text blank',
	'LINES_TO_SKIP'								=> 'Lines to skip between answers',
	'LIST_NONRESPONDERS'						=> 'List the nonresponders?',
	'MAX_NUMBER_OF_QUESTIONS'					=> 'Max number of questions<br />(change takes effect after click preview)',
	'MULTIPLE_CHOICE_CHECKBOXES'				=> 'multiple choice checkboxes',
	'NO_LC'										=> 'no',
	'NO_SUCH_USER_AUTHORIZED_FOR_SURVEY'		=> 'The user you specified does not exist or is not authorized to take this survey.',
	'NO_SURVEY_ID_SPECIFIED'					=> 'No survey_id specified',
	'NO_SURVEY_TOPIC_ID_SPECIFIED'				=> 'No topic_id specified for the survey',
	'NONRESPONDERS'								=> 'People who haven\'t yet answered',
	'OTHER_USER_ANSWERS_BELOW'					=> '\'s answers are shown below<br />(but you can change them and resubmit if you want)',
	'OTHER_USER_NOT_ANSWERED'					=> 'hasn\'t answered the survey yet<br />(but you can answer for him or her below)',
	'ORDER_TO_SHOW'								=> 'Order to show responders',
	'QUESTION'									=> 'Question',
	'QUESTION_TYPE'								=> 'Question type',
	'RETRIEVE_ANSWERS_FOR_OTHER_USER'			=> 'Retrieve answers for other user',
	'SELECT_GROUP'								=> 'Select the groups that will be allowed to answer this survey',
	'SENDING'									=> 'Sending',
	'SHOW_NONRESPONDERS_CENTER_COLUMN'			=> 'yes, in column that is centered',
	'SHOW_NONRESPONDERS_CENTER_COMMA_SEPARATED'	=> 'yes, in comma separated list that is centered',
	'SHOW_NONRESPONDERS_LEFT_COLUMN'			=> 'yes, in column that is left justified',
	'SHOW_NONRESPONDERS_LEFT_COMMA_SEPARATED'	=> 'yes, in comma separated list that is left justified',
	'SHOULD_RESPONSES_BE_TOTALLED'				=> 'Should the responses be totalled?',
	'SMALL_TEXT_BLANK'							=> 'small text blank',
	'SORRY_ENOUGH_RESPONSES'					=> 'Sorry, but there are already<br />enough responses to this question',
	'SORRY_QUESTION_CAP_HIT'					=> 'Sorry, a question you answered already has enough responses<br />(someone else answered that question just before you did).<br />Please try again.<br /><br />',
	'SORT_BY_FIRST_ANSWER'						=> 'alphabetical by text in first answer',
	'SORT_BY_FIRST_ANSWER_DESCENDING_ORDER'		=> 'reverse alphabetical by text in first answer',
	'SURVEY'									=> 'Survey',
	'SURVEY_CAPTION'							=> 'Survey Caption',
	'SURVEY_HAS_EXPIRED_(NO_MORE_VOTING)'		=> 'Survey has expired...no more voting or changing your vote',
	'SURVEY_HEIGHT'								=> 'Max survey height (in pixels)<br />(adds scroll bars if beyond max)<br />(leave blank for no limit)',
	'SURVEY_LENGTH'								=> 'Number of days to run survey<br />(leave blank for no limit)',
	'TEXT_BOX'									=> 'text box',
//	note that the next line is already picked up in language/en/common.php so I have commented it out here
//	'TOPIC_SURVEY'								=> 'Survey: ',
	'TOTAL'										=> 'Total',
	'TOTAL_OR_AVERAGE'							=> 'Total or average',
	'TOTAL_RESPONSES'							=> 'Total responses',
	'USERNAME_TAKING_SURVEY'					=> 'Username of person for whom user is answering survey',
	'WIDTH_QUESTION'							=> 'Question width (in pixels)<br />(you can leave this blank)',
	'WIDTH_USERNAME'							=> 'Username width (in pixels)<br />(you can leave this blank)<br />note: -1 means no username column',
	'YES_LC'										=> 'yes',
	'YES_BY_AVERAGE_OF_NUMBERS_IN_RESPONSES'	=> 'yes, by average of the numbers in the responses',
	'YES_BY_MATCHING_TEXT'						=> 'yes, by total responses matching specified text',
	'YES_BY_NUMBERS_IN_RESPONSES'				=> 'yes, by total of the numbers in the responses',
	'YES_BY_NUMBER_OF_RESPONSES'				=> 'yes, by number of responses',
));

?>
I can try to track this down but I figured if anyone else knows off the top of his or her head what's going on that will save me a lot of time. Any ideas?

coppro
Registered User
Posts: 84
Joined: Wed May 16, 2007 3:10 am

Re: problem with $user->add_lang()

Post by coppro » Fri Jun 01, 2007 2:06 am

I encountered this myself. It seems that you must call $user->add_lang() at some point after $user->setup() is called... but calling setup twice seems to lead to issues. My solution was to put it into the file I included, but you may not have that ability (tip: don't forget to use "global $user" if it might get included inside a function).

asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Re: problem with $user->add_lang()

Post by asinshesq » Fri Jun 01, 2007 2:18 am

Thanks, I can't check that now since I'm not around my files but that sounds promising. I'll check it tomorrow and post back about whether that does the trick.

asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Re: problem with $user->add_lang()

Post by asinshesq » Fri Jun 01, 2007 2:43 am

Actually, I managed to snealk a peak and that did the trick. Thanks!

But I'm not sure that fix will always be easy to make...it could get pretty awkward if you have different setup lines interlaced with places where you need to add a language file. (For example, viewtopic has a number of different places where it uses setup before exiting...it's easy to imagine running afoul of things in that file.)

Anyone know if there's a more general way around this?

coppro
Registered User
Posts: 84
Joined: Wed May 16, 2007 3:10 am

Re: problem with $user->add_lang()

Post by coppro » Fri Jun 01, 2007 2:45 am

If nessecary, I guess you could put setup() at the start and then replace the other calls with add_lang()

User avatar
christhatsme
Registered User
Posts: 1811
Joined: Sun Jan 16, 2005 10:42 am
Location: London, UK

Re: problem with $user->add_lang()

Post by christhatsme » Fri Jun 01, 2007 7:58 am

setup sets up the users lang, so you can't set it up twice, but since you can add a language to it, based on what the users setup was... Seems logical to me... :roll:
All MOD downloads should be back now - Sorry for that and serious lack of support! - If anyone wants to take over or help with any of my MODs the offer would be apreciated as I have little time for phpBB Modding recently!

Again very sorry for not supporting these MODs recently.

asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Re: problem with $user->add_lang()

Post by asinshesq » Fri Jun 01, 2007 10:16 am

christhatsme wrote:setup sets up the users lang, so you can't set it up twice, but since you can add a language to it, based on what the users setup was... Seems logical to me... :roll:
Logical but highly awkward. And I just realized I have an even worse problem in posting.php.

The problem comes because phpbb3RC1 sometimes scatters $user->setup multiple times throughout a file. For example, in posting.php $user->setup appears in lines 88, 127, 139, 150 and 1334. I realize things are arranged so that the script never encounters $user->setup more than once (each of those appearances is in a path where the script ends through a trigger_errror or redirect before another is executed), but if I need to insert $user->add_lang('mods/survey') somewhere in the middle, how can I safely do it? Am I stuck with the idea that I can't have a separate language and I instead need to move my mod's language variables to the language/en/common.php?

User avatar
christhatsme
Registered User
Posts: 1811
Joined: Sun Jan 16, 2005 10:42 am
Location: London, UK

Re: problem with $user->add_lang()

Post by christhatsme » Fri Jun 01, 2007 11:05 am

I think it would probably be easiest in this case to use common.php

posting.php wasn't well thought of in structure regarding language, I agree with you it is high awkward after taking a glance at it...
All MOD downloads should be back now - Sorry for that and serious lack of support! - If anyone wants to take over or help with any of my MODs the offer would be apreciated as I have little time for phpBB Modding recently!

Again very sorry for not supporting these MODs recently.

asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Re: problem with $user->add_lang()

Post by asinshesq » Fri Jun 01, 2007 11:25 am

christhatsme wrote:I think it would probably be easiest in this case to use common.php

posting.php wasn't well thought of in structure regarding language, I agree with you it is high awkward after taking a glance at it...
Thanks for confirming what I thought.

This mod has 65 language variables and the language file is 6 KB. If I add those to common.php (which gets called even when I don't need those variables), will that cause an appreciable drag on large boards? Or is that kind of thing lost in the rounding?

User avatar
christhatsme
Registered User
Posts: 1811
Joined: Sun Jan 16, 2005 10:42 am
Location: London, UK

Re: problem with $user->add_lang()

Post by christhatsme » Fri Jun 01, 2007 11:52 am

6kb isn't massive, yes it would be nice to avoid it, but its not the end of the world.
All MOD downloads should be back now - Sorry for that and serious lack of support! - If anyone wants to take over or help with any of my MODs the offer would be apreciated as I have little time for phpBB Modding recently!

Again very sorry for not supporting these MODs recently.

coppro
Registered User
Posts: 84
Joined: Wed May 16, 2007 3:10 am

Re: problem with $user->add_lang()

Post by coppro » Fri Jun 01, 2007 7:27 pm

Adding it to common.php is precisely what cause my error beforehand. :(

User avatar
christhatsme
Registered User
Posts: 1811
Joined: Sun Jan 16, 2005 10:42 am
Location: London, UK

Re: problem with $user->add_lang()

Post by christhatsme » Fri Jun 01, 2007 7:55 pm

coppro wrote:Adding it to common.php is precisely what cause my error beforehand. :(
You obviously made a mistake then :P
All MOD downloads should be back now - Sorry for that and serious lack of support! - If anyone wants to take over or help with any of my MODs the offer would be apreciated as I have little time for phpBB Modding recently!

Again very sorry for not supporting these MODs recently.

User avatar
poyntesm
Registered User
Posts: 1671
Joined: Tue Jan 18, 2005 11:19 am
Location: Dublin, Ireland
Contact:

Re: problem with $user->add_lang()

Post by poyntesm » Fri Jun 01, 2007 8:38 pm

Just a comment, if phpBB group went to the trouble of calling setup in the correct place then maybe your MOD should add the add_lang in the correct places too?

asinshesq
Registered User
Posts: 6266
Joined: Sun Feb 22, 2004 9:34 pm
Location: NYC
Name: Alan

Re: problem with $user->add_lang()

Post by asinshesq » Fri Jun 01, 2007 9:00 pm

poyntesm wrote:Just a comment, if phpBB group went to the trouble of calling setup in the correct place then maybe your MOD should add the add_lang in the correct places too?
Depending on the phpbb page in question and the mod, there are instances where there is no correct place to put it (unless you at the same time change where the already existing setup lines are).

Some phpbb3 pages have setup lines scattered throughout the page in multiple places, often just before a trigger_error (so phpbb3 never itself runs into the problem of double execution). But imagine setup lines before trigger errors at the beginning, middle and near the end of a page. And imagine that your mod needs to go in the middle somewhere. In that case, you can't stick in a user_lang line because if the script ever hits one of those trigger errors later in the script you've got a problem. The alternative is for the mod to muck with the user_setup lines (have one upfront and change all the remaining ones to user_lang lines) but that's not a very clean answer.

I would have thought that a clean phpbb3 page would strive to have the setup at the beginning (with added user_lang lines later on where needed). Not sure why they didn't do it that way (though I'm sure the developers had a good reason for it).

User avatar
christhatsme
Registered User
Posts: 1811
Joined: Sun Jan 16, 2005 10:42 am
Location: London, UK

Re: problem with $user->add_lang()

Post by christhatsme » Fri Jun 01, 2007 9:13 pm

to be honest it is a mess, it needs clearing up or MOD authoring in that file (which there will be a lot of) will be hell
All MOD downloads should be back now - Sorry for that and serious lack of support! - If anyone wants to take over or help with any of my MODs the offer would be apreciated as I have little time for phpBB Modding recently!

Again very sorry for not supporting these MODs recently.

Locked

Return to “[3.0.x] MOD Writers Discussion”