thurfin la clarté dans la confusion | Bonjour,
j'ai voulu installer sur les pages persos de sfr phpwebgallerie afin de mettre en ligne des photos. Le problème c'est que sfr vérouille la fonction PREG_REPLACE( /e) pour de soit disantes raisons de sécurité et le site renvoie une erreur lorsque on essaye d'y accéder. Pour le moment j'ai désactiver le /e ce qui rend le site accessible mais avec un résultat dég (la fonction est dans un script gérant les templates). Il y'aurait t'il donc un moyen de contourner le problème en reprogrammant le bou de code afin de ne pas faire appel à la fonction preg_replace /e ? (voir ci dessous)
Merci d'avance.
Code :
- function compile($code, $do_not_echo = false, $retvar = '')
- {
- // PWG specific : communication between template and $lang
- $code = preg_replace('/\{lang:([^}]+)\}/e', "l10n('$1')", $code);
- // PWG specific : expand themeconf.inc.php variables
- $code = preg_replace('/\{themeconf:([^}]+)\}/e', '$this->get_themeconf(\'$1\')', $code);
- $code = preg_replace('/\{pwg_root\}/e', "get_root_url()", $code);
- // replace \ with \\ and then ' with \'.
- $code = str_replace('\\', '\\\\', $code);
- $code = str_replace('\'', '\\\'', $code);
- // change template varrefs into PHP varrefs
- // This one will handle varrefs WITH namespaces
- $varrefs = array();
- preg_match_all('#\{(([a-z0-9\-_]+?\.)+?)([a-z0-9\-_]+?)\}#is', $code, $varrefs);
- $varcount = sizeof($varrefs[1]);
- for ($i = 0; $i < $varcount; $i++)
- {
- $namespace = $varrefs[1][$i];
- $varname = $varrefs[3][$i];
- $new = $this->generate_block_varref($namespace, $varname);
- $code = str_replace($varrefs[0][$i], $new, $code);
- }
- // This will handle the remaining root-level varrefs
- $code = preg_replace('#\{([a-z0-9\-_]*?)\}#is', '\' . ( ( isset($this->_tpldata[\'.\'][0][\'\1\']) ) ? $this->_tpldata[\'.\'][0][\'\1\'] : \'\' ) . \'', $code);
- // Break it up into lines.
- $code_lines = explode("\n", $code);
- $block_nesting_level = 0;
- $block_names = array();
- $block_names[0] = ".";
- // Second: prepend echo ', append ' . "\n"; to each line.
- $line_count = sizeof($code_lines);
- for ($i = 0; $i < $line_count; $i++)
- {
- $code_lines[$i] = chop($code_lines[$i]);
- if (preg_match('#<!-- BEGIN (.*?) -->#', $code_lines[$i], $m))
- {
- $n[0] = $m[0];
- $n[1] = $m[1];
- // Added: dougk_ff7-Keeps templates from bombing if begin is on
- // the same line as end.. I think. :)
- if ( preg_match('#<!-- END (.*?) -->#', $code_lines[$i], $n) )
- {
- $block_nesting_level++;
- $block_names[$block_nesting_level] = $m[1];
- if ($block_nesting_level < 2)
- {
- // Block is not nested.
- $code_lines[$i] = '$_' . $n[1] . '_count = ( isset($this->_tpldata[\'' . $n[1] . '.\']) ) ? sizeof($this->_tpldata[\'' . $n[1] . '.\']) : 0;';
- $code_lines[$i] .= "\n" . 'for ($_' . $n[1] . '_i = 0; $_' . $n[1] . '_i < $_' . $n[1] . '_count; $_' . $n[1] . '_i++)';
- $code_lines[$i] .= "\n" . '{';
- }
- else
- {
- // This block is nested.
- // Generate a namespace string for this block.
- $namespace = implode('.', $block_names);
- // strip leading period from root level..
- $namespace = substr($namespace, 2);
- // Get a reference to the data array for this block that depends on the
- // current indices of all parent blocks.
- $varref = $this->generate_block_data_ref($namespace, false);
- // Create the for loop code to iterate over this block.
- $code_lines[$i] = '$_' . $n[1] . '_count = ( isset(' . $varref . ') ) ? sizeof(' . $varref . ') : 0;';
- $code_lines[$i] .= "\n" . 'for ($_' . $n[1] . '_i = 0; $_' . $n[1] . '_i < $_' . $n[1] . '_count; $_' . $n[1] . '_i++)';
- $code_lines[$i] .= "\n" . '{';
- }
- // We have the end of a block.
- unset($block_names[$block_nesting_level]);
- $block_nesting_level--;
- $code_lines[$i] .= '} // END ' . $n[1];
- $m[0] = $n[0];
- $m[1] = $n[1];
- }
- else
- {
- // We have the start of a block.
- $block_nesting_level++;
- $block_names[$block_nesting_level] = $m[1];
- if ($block_nesting_level < 2)
- {
- // Block is not nested.
- $code_lines[$i] = '$_' . $m[1] . '_count = ( isset($this->_tpldata[\'' . $m[1] . '.\']) ) ? sizeof($this->_tpldata[\'' . $m[1] . '.\']) : 0;';
- $code_lines[$i] .= "\n" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1] . '_count; $_' . $m[1] . '_i++)';
- $code_lines[$i] .= "\n" . '{';
- }
- else
- {
- // This block is nested.
- // Generate a namespace string for this block.
- $namespace = implode('.', $block_names);
- // strip leading period from root level..
- $namespace = substr($namespace, 2);
- // Get a reference to the data array for this block that
- // depends on the current indices of all parent blocks.
- $varref = $this->generate_block_data_ref($namespace, false);
- // Create the for loop code to iterate over this block.
- $code_lines[$i] = '$_' . $m[1] . '_count = ( isset(' . $varref . ') ) ? sizeof(' . $varref . ') : 0;';
- $code_lines[$i] .= "\n" . 'for ($_' . $m[1] . '_i = 0; $_' . $m[1] . '_i < $_' . $m[1] . '_count; $_' . $m[1] . '_i++)';
- $code_lines[$i] .= "\n" . '{';
- }
- }
- }
- else if (preg_match('#<!-- END (.*?) -->#', $code_lines[$i], $m))
- {
- // We have the end of a block.
- unset($block_names[$block_nesting_level]);
- $block_nesting_level--;
- $code_lines[$i] = '} // END ' . $m[1];
- }
- else
- {
- // We have an ordinary line of code.
- if (!$do_not_echo)
- {
- $code_lines[$i] = 'echo \'' . $code_lines[$i] . '\' . "\\n";';
- }
- else
- {
- $code_lines[$i] = '$' . $retvar . '.= \'' . $code_lines[$i] . '\' . "\\n";';
- }
- }
- }
- // Bring it back into a single string of lines of code.
- $code = implode("\n", $code_lines);
- return $code ;
- }
|
|