PDA

View Full Version : How does vBulletin make $vbphrase available to JavaScript?


nerbert
11-11-2014, 12:55 AM
Does anyone know how vBulletin passes phrases to JavaScript? For now I'm using a php file called with a script tag. Here's a sample of the code:


<?php
require_once('./global.php');
header('Content-type: text/javascript');
header('Pragma:'); // VBIV-8269
header('Cache-control: max-age=31536000');
header('Expires: ' . gmdate("D, d M Y H:i:s", TIMENOW + 31536000) . ' GMT');
define('VB_AREA', 'AdminCP');
define('THIS_SCRIPT', 'phrases');
?>

fmPhrase = {
fm_no_dir : '<?php echo $vbphrase['fm_no_dir']; ?>',
fm_no_file : '<?php echo $vbphrase['fm_no_file']; ?>',
fm_not_mult : '<?php echo $vbphrase['fm_not_mult']; ?>',
fm_not_on_dir : '<?php echo $vbphrase['fm_not_on_dir']; ?>',
fm_if_you_attempt : '<?php echo $vbphrase['fm_if_you_attempt']; ?>',
fm_these_files : '<?php echo $vbphrase['fm_these_files']; ?>',
// etc
}



If it was just a few phrases it could be handled with a short inline script in the head but there are dozens of phrases and settings and it's tiresome and tedious enough to phrase a project without having to add another pair to the phrase object every time.

Could someone point me to the file or function that handles this?

kh99
11-11-2014, 09:53 AM
I'm not 100% sure, but I don't think there is any "magic" way of doing it. I think the phrases are written into the output either as js string constants or as html text which a js function then manipulates (like with the menus).

nerbert
11-11-2014, 01:18 PM
See includes/xml/js_safe_phrases.xml.

That seems to be part of some system that does what I want but I have no idea what file or function calls this.

kh99
11-11-2014, 02:47 PM
Hmm...didn't know that existed. But looking at the code in adminfunctions_language.php that uses that file, it looks like it's just a list of phrases that are adjusted for use in javascript (fetch_js_safe_string() in adminfunctions.php is called on each one to do some replacements). But other than that it doesn't seem to help. I checked where one of the phrases was used and it's for the ckeditor, and they seem to be output as a js function call that creates the editor.