I am using the XTemplate class. It uses registered globals. I have to rewrite partof it so it does not use registered globals. Here is the code from XTemplate where it uses registered globals. Does anyone have an answer on how to rewrite this to use not registered globals. Here goes. I guess maybe I do an array. Lets see what you guys say.
Here are the variables.
class XTemplate {
/**
* Properties
*/
/**
* Raw contents of the template file
*
* @access public
* @var string
*/
public $filecontents = '';
/**
* Unparsed blocks
*
* @access public
* @var array
*/
public $blocks = array();
/**
* Parsed blocks
*
* @var unknown_type
*/
public $parsed_blocks = array();
/**
* Preparsed blocks (for file includes)
*
* @access public
* @var array
*/
public $preparsed_blocks = array();
/**
* Block parsing order for recursive parsing
* (Sometimes reverse :)
*
* @access public
* @var array
*/
public $block_parse_order = array();
/**
* Store sub-block names
* (For fast resetting)
*
* @access public
* @var array
*/
public $sub_blocks = array();
/**
* Variables array
*
* @access public
* @var array
*/
public $vars = array();
/**
* File variables array
*
* @access public
* @var array
*/
public $filevars = array();
/**
* Filevars' parent block
*
* @access public
* @var array
*/
public $filevar_parent = array();
/**
* File caching during duration of script
* e.g. files only cached to speed {FILE "filename"} repeats
*
* @access public
* @var array
*/
public $filecache = array();
/**
* Location of template files
*
* @access public
* @var string
*/
public $tpldir = '';
/**
* Filenames lookup table
*
* @access public
* @var null
*/
public $files = null;
/**
* Template filename
*
* @access public
* @var string
*/
public $filename = '';
// moved to setup method so uses the tag_start & end_delims
/**
* RegEx for file includes
*
* "/\{FILE\s*\"([^\"]+)\"\s*\}/m";
*
* @access public
* @var string
*/
public $file_delim = '';
/**
* RegEx for file include variable
*
* "/\{FILE\s*\{([A-Za-z0-9\._]+?)\}\s*\}/m";
*
* @access public
* @var string
*/
public $filevar_delim = '';
/**
* RegEx for file includes with newlines
*
* "/^\s*\{FILE\s*\{([A-Za-z0-9\._]+?)\}\s*\}\s*\n/m";
*
* @access public
* @var string
*/
public $filevar_delim_nl = '';
/**
* Template block start delimiter
*
* @access public
* @var string
*/
public $block_start_delim = '<!-- ';
/**
* Template block end delimiter
*
* @access public
* @var string
*/
public $block_end_delim = '-->';
/**
* Template block start word
*
* @access public
* @var string
*/
public $block_start_word = 'BEGIN:';
/**
* Template block end word
*
* The last 3 properties and this make the delimiters look like:
* @example <!-- BEGIN: block_name -->
* if you use the default syntax.
*
* @access public
* @var string
*/
public $block_end_word = 'END:';
/**
* Template tag start delimiter
*
* This makes the delimiters look like:
* @example {tagname}
* if you use the default syntax.
*
* @access public
* @var string
*/
public $tag_start_delim = '{';
/**
* Template tag end delimiter
*
* This makes the delimiters look like:
* @example {tagname}
* if you use the default syntax.
*
* @access public
* @var string
*/
public $tag_end_delim = '}';
/* this makes the delimiters look like: {tagname} if you use my syntax. */
/**
* Regular expression element for comments within tags and blocks
*
* @example {tagname#My Comment}
* @example {tagname #My Comment}
* @example <!-- BEGIN: blockname#My Comment -->
* @example <!-- BEGIN: blockname #My Comment -->
*
* @access public
* @var string
*/
public $comment_preg = '( ?#.*?)?';
/**
* Default main template block name
*
* @access public
* @var string
*/
public $mainblock = 'main';
/**
* Script output type
*
* @access public
* @var string
*/
public $output_type = 'HTML';
/**
* Debug mode
*
* @access public
* @var boolean
*/
public $debug = false;
/**
* Null string for unassigned vars
*
* @access protected
* @var array
*/
protected $_null_string = array('' => '');
/**
* Null string for unassigned blocks
*
* @access protected
* @var array
*/
protected $_null_block = array('' => '');
/**
* Errors
*
* @access protected
* @var string
*/
protected $_error = '';
/**
* Auto-reset sub blocks
*
* @access protected
* @var boolean
*/
protected $_autoreset = true;
/**
* Set to FALSE to generate errors if a non-existant blocks is referenced
*
* @author NW
* @since 2002/10/17
* @access protected
* @var boolean
*/
protected $_ignore_missing_blocks = true;
Here is the function.
/**
* scans global variables and assigns to PHP array
*
* @access public
*/
public function scan_globals () {
reset($GLOBALS);
foreach ($GLOBALS as $k => $v) {
$GLOB[$k] = $v;
}
/**
* Access global variables as:
* @example {PHP._SERVER.HTTP_HOST}
* in your template!
*/
$this->assign('PHP', $GLOB);
}