You are not logged in.
Configuration: Xinha0.96b2 - Apache 2.2 - PHP 5.2
If, for any reason, you need to use global variables with Xinha (for example if you need to redirect your session's save path, like in an old post of mine, and use a global for it), you may have issues with these, especially with xinha_read_passed_data().
In fact, xinha_read_passed_data() is called out of your own includes, when it's called through Xinha's own files (backend, editor...). So if you declared globals in others scripts, these variables won't be declared on Xinha's own requests (because it doesn't care about your files, naturally).
A quick fix for this lack of globals is to use the $_REQUEST's subarray "backend_data" (referred by $bk in the code) created in xinha_pass_to_php_backend() to carry the globals you need, because this function is only called once, when you include your configuration file (and there you theoretically have all your scripts loaded, and so should be your globals). This array will be retrieved by xinha_read_passed_data(), when the function is called directly by Xinha, outside of all your scripts.
To illustrate, I needed to have a global $xinha_dir_root to specify the session's save path. Here is the basics of my root object file:
$xinha_dir_root=""; //general declaration
class racine {
public function __construct() {
$xinha_dir_root="C:/mon/chemin"; //give a value according to the object's attributes
...
}
public function entete() {
...
echo '<script type="text/javascript" src="'.$anotherRootThatWeDontCareAbout.'/Xinha/XinhaCore.js"></script>';
global $xinha_dir_root; //retrieves the global value for use in this method
include("../Xinha/my_config.php");
...
}
...
}
//launcher for the program
$a=new racine();
$a->entete();
As we include("../Xinha/my_config.php"), which is a pure hard-coded file (I mean no function in it to lower the variables' scope), our variables follow the move, so we can use our $xinha_dir_root anywhere in the file.
Then the configuration file (my_config.php) may include contrib/php-xinha.php. For example, with the ExtendedFileManager plugin or the ImageManager plugin. We have, somewhere in php-xinha.php:
require_once '../Xinha/contrib/php-xinha.php';
xinha_pass_to_php_backend($IMConfig);
I don't use other plugins but I guess they could use these lines as well, where $IMConfig would represent an array of option/value pairs. The file php-xinha.php is a pure function-coded file (in opposition to my_config, php-xinha is only a collection of functions, so the variables' scope depends on when functions are called, i.e. if our other scripts - and our global variables! - have already been declared on functions' calls). As we just saw, the function xinha_pass_to_php_backend() is called once and for all in the config file, which is always loaded after our scripts are run. So we have our globals declared when we run xinha_pass_to_php_backend(), but we may not when we run xinha_read_passed_data(). Therefore we use the "link" between these two functions: $_REQUEST['backend_data'], which is prepared by xinha_pass_to_php_backend(), and which is read by xinha_read_passed_data(). In our example:
function xinha_pass_to_php_backend($Data, $KeyLocation = 'Xinha:BackendKey', $ReturnPHP = FALSE) {
global $xinha_dir_root; //here we got it already declared from root object
...
$bk['DIR_ROOT']=$xinha_dir_root; //so we can use it, it's not empty
$bk['session_name'] = session_name();
$bk['key_location'] = $KeyLocation;
...
}
...
function xinha_read_passed_data() {
if(isset($_REQUEST['backend_data']) && is_array($_REQUEST['backend_data'])) {
$bk = $_REQUEST['backend_data'];
session_name($bk['session_name']);
session_save_path($bk['DIR_ROOT'] . '/my/folder/tmp'); //we get the global's value through backend_data
...
}
There you found a (dirty) way to retrieve your own globals inside xinha_read_passed_data(). Dirty but easy to build...
Have fun!
Offline