Uploaded image for project: 'phpBB'
  1. phpBB
  2. PHPBB-11217

Prefix for template values to give back value URL encoded

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Trivial Trivial
    • 3.1.0-a1
    • 3.0.11
    • Template Engine
    • None
    • PHP 5.3.8

      Right now we have in /includes/functions_template.php in function compile_var_tags() the ability to prefix a template variable with LA_ to mask/encode the output for a JavaScript string:

      		// Handle addslashed language variables prefixed with LA_
      		// If a template variable already exist, it will be used in favor of it...
      		if (strpos($text_blocks, '{LA_') !== false)
      		{
      			$text_blocks = preg_replace('#\{LA_([A-Z0-9\-_]+)\}#', "<?php echo ((isset(\$this->_rootref['LA_\\1'])) ? \$this->_rootref['LA_\\1'] : ((isset(\$this->_rootref['L_\\1'])) ? addslashes(\$this->_rootref['L_\\1']) : ((isset(\$user->lang['\\1'])) ? addslashes(\$user->lang['\\1']) : '{ \\1 }'))); ?>", $text_blocks);
      		}

      There should also be a prefix for URL encoding a value, so users don't have to modify PHP files when needing any value to be put into another URL.

      My suggestion:

      		// Handle URL encoded language variables prefixed with LU_
      		// If a template variable already exist, it will be used in favor of it...
      		if (strpos($text_blocks, '{LU_') !== false)
      		{
      			$text_blocks = preg_replace('#\{LU_([A-Z0-9\-_]+)\}#', "<?php echo ((isset(\$this->_rootref['LU_\\1'])) ? \$this->_rootref['LU_\\1'] : ((isset(\$this->_rootref['L_\\1'])) ? urlencode(\$this->_rootref['L_\\1']) : ((isset(\$user->lang['\\1'])) ? urlencode(\$user->lang['\\1']) : '{ \\1 }'))); ?>", $text_blocks);
      		}

      Inspired by https://www.phpbb.com/community/viewtopic.php?f=71&t=2165668

            EXreaction EXreaction [X] (Inactive)
            AmigoJack AmigoJack
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: