Fix the "addHeader($tag, $attributes, $text)" methods to not ignore the $text parameter

Also support closing tags with no text content given

Conflicts:
	lib/private/template.php
This commit is contained in:
Lukas Reschke 2014-10-28 11:15:58 +01:00
parent 7466ff09bb
commit 510d0b2cf3
6 changed files with 31 additions and 39 deletions

View File

@ -21,15 +21,7 @@
<?php foreach ($_['jsfiles'] as $jsfile): ?> <?php foreach ($_['jsfiles'] as $jsfile): ?>
<script type="text/javascript" src="<?php print_unescaped($jsfile); ?>"></script> <script type="text/javascript" src="<?php print_unescaped($jsfile); ?>"></script>
<?php endforeach; ?> <?php endforeach; ?>
<?php foreach ($_['headers'] as $header): ?> <?php print_unescaped($_['headers']); ?>
<?php
print_unescaped('<'.$header['tag'].' ');
foreach ($header['attributes'] as $name => $value) {
print_unescaped("$name='$value' ");
};
print_unescaped('/>');
?>
<?php endforeach; ?>
</head> </head>
<body id="body-public"> <body id="body-public">
<noscript><div id="nojavascript"><div><?php print_unescaped($l->t('This application requires JavaScript for correct operation. Please <a href="http://enable-javascript.com/" target="_blank">enable JavaScript</a> and reload the page.')); ?></div></div></noscript> <noscript><div id="nojavascript"><div><?php print_unescaped($l->t('This application requires JavaScript for correct operation. Please <a href="http://enable-javascript.com/" target="_blank">enable JavaScript</a> and reload the page.')); ?></div></div></noscript>

View File

@ -22,16 +22,7 @@
<?php foreach($_['jsfiles'] as $jsfile): ?> <?php foreach($_['jsfiles'] as $jsfile): ?>
<script type="text/javascript" src="<?php print_unescaped($jsfile); ?>"></script> <script type="text/javascript" src="<?php print_unescaped($jsfile); ?>"></script>
<?php endforeach; ?> <?php endforeach; ?>
<?php print_unescaped($_['headers']); ?>
<?php foreach($_['headers'] as $header): ?>
<?php
print_unescaped('<'.$header['tag'].' ');
foreach($header['attributes'] as $name=>$value) {
print_unescaped("$name='$value' ");
};
print_unescaped('/>');
?>
<?php endforeach; ?>
</head> </head>
<body id="<?php p($_['bodyid']);?>"> <body id="<?php p($_['bodyid']);?>">
<noscript><div id="nojavascript"><div><?php print_unescaped($l->t('This application requires JavaScript for correct operation. Please <a href="http://enable-javascript.com/" target="_blank">enable JavaScript</a> and reload the page.')); ?></div></div></noscript> <noscript><div id="nojavascript"><div><?php print_unescaped($l->t('This application requires JavaScript for correct operation. Please <a href="http://enable-javascript.com/" target="_blank">enable JavaScript</a> and reload the page.')); ?></div></div></noscript>

View File

@ -29,15 +29,7 @@
<?php foreach($_['jsfiles'] as $jsfile): ?> <?php foreach($_['jsfiles'] as $jsfile): ?>
<script type="text/javascript" src="<?php print_unescaped($jsfile); ?>"></script> <script type="text/javascript" src="<?php print_unescaped($jsfile); ?>"></script>
<?php endforeach; ?> <?php endforeach; ?>
<?php foreach($_['headers'] as $header): ?> <?php print_unescaped($_['headers']); ?>
<?php
print_unescaped('<'.$header['tag'].' ');
foreach($header['attributes'] as $name=>$value) {
print_unescaped("$name='$value' ");
};
print_unescaped('/>');
?>
<?php endforeach; ?>
</head> </head>
<body id="<?php p($_['bodyid']);?>"> <body id="<?php p($_['bodyid']);?>">
<noscript><div id="nojavascript"><div><?php print_unescaped($l->t('This application requires JavaScript for correct operation. Please <a href="http://enable-javascript.com/" target="_blank">enable JavaScript</a> and reload the page.')); ?></div></div></noscript> <noscript><div id="nojavascript"><div><?php print_unescaped($l->t('This application requires JavaScript for correct operation. Please <a href="http://enable-javascript.com/" target="_blank">enable JavaScript</a> and reload the page.')); ?></div></div></noscript>

View File

@ -158,10 +158,15 @@ class OC_Template extends \OC\Template\Base {
* Add a custom element to the header * Add a custom element to the header
* @param string $tag tag name of the element * @param string $tag tag name of the element
* @param array $attributes array of attributes for the element * @param array $attributes array of attributes for the element
* @param string $text the text content for the element * @param string $text the text content for the element. If $text is null then the
* element will be written as empty element. So use "" to get a closing tag.
*/ */
public function addHeader( $tag, $attributes, $text='') { public function addHeader($tag, $attributes, $text=null) {
$this->headers[]=array('tag'=>$tag,'attributes'=>$attributes, 'text'=>$text); $this->headers[]= array(
'tag' => $tag,
'attributes' => $attributes,
'text' => $text
);
} }
/** /**
@ -178,12 +183,22 @@ class OC_Template extends \OC\Template\Base {
$page = new OC_TemplateLayout($this->renderas, $this->app); $page = new OC_TemplateLayout($this->renderas, $this->app);
// Add custom headers // Add custom headers
$page->assign('headers', $this->headers, false); $headers = '';
foreach(OC_Util::$headers as $header) { foreach(OC_Util::$headers as $header) {
$page->append('headers', $header); $headers .= '<'.OC_Util::sanitizeHTML($header['tag']);
foreach($header['attributes'] as $name=>$value) {
$headers .= ' "'.OC_Util::sanitizeHTML($name).'"="'.OC_Util::sanitizeHTML($value).'"';
}
if ($header['text'] !== null) {
$headers .= '>'.OC_Util::sanitizeHTML($header['text']).'</'.OC_Util::sanitizeHTML($header['tag']).'>';
} else {
$headers .= '/>';
}
} }
$page->assign( "content", $data, false ); $page->assign('headers', $headers, false);
$page->assign('content', $data, false );
return $page->fetchPage(); return $page->fetchPage();
} }
else{ else{

View File

@ -370,13 +370,13 @@ class OC_Util {
/** /**
* Add a custom element to the header * Add a custom element to the header
* * If $text is null then the element will be written as empty element.
* So use "" to get a closing tag.
* @param string $tag tag name of the element * @param string $tag tag name of the element
* @param array $attributes array of attributes for the element * @param array $attributes array of attributes for the element
* @param string $text the text content for the element * @param string $text the text content for the element
* @return void
*/ */
public static function addHeader($tag, $attributes, $text = '') { public static function addHeader($tag, $attributes, $text=null) {
self::$headers[] = array( self::$headers[] = array(
'tag' => $tag, 'tag' => $tag,
'attributes' => $attributes, 'attributes' => $attributes,

View File

@ -138,12 +138,14 @@ class Util {
/** /**
* Add a custom element to the header * Add a custom element to the header
* If $text is null then the element will be written as empty element.
* So use "" to get a closing tag.
* @param string $tag tag name of the element * @param string $tag tag name of the element
* @param array $attributes array of attributes for the element * @param array $attributes array of attributes for the element
* @param string $text the text content for the element * @param string $text the text content for the element
*/ */
public static function addHeader( $tag, $attributes, $text='') { public static function addHeader($tag, $attributes, $text=null) {
\OC_Util::addHeader( $tag, $attributes, $text ); \OC_Util::addHeader($tag, $attributes, $text);
} }
/** /**