From 510d0b2cf3c108447f42fcb119560175134fb0f6 Mon Sep 17 00:00:00 2001 From: Lukas Reschke Date: Tue, 28 Oct 2014 11:15:58 +0100 Subject: [PATCH] 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 --- core/templates/layout.base.php | 10 +--------- core/templates/layout.guest.php | 11 +---------- core/templates/layout.user.php | 10 +--------- lib/private/template.php | 27 +++++++++++++++++++++------ lib/private/util.php | 6 +++--- lib/public/util.php | 6 ++++-- 6 files changed, 31 insertions(+), 39 deletions(-) diff --git a/core/templates/layout.base.php b/core/templates/layout.base.php index 3325bc9165..2b496c2324 100644 --- a/core/templates/layout.base.php +++ b/core/templates/layout.base.php @@ -21,15 +21,7 @@ - - $value) { - print_unescaped("$name='$value' "); - }; - print_unescaped('/>'); - ?> - + diff --git a/core/templates/layout.guest.php b/core/templates/layout.guest.php index 0ad2ea4d80..763af4dc1d 100644 --- a/core/templates/layout.guest.php +++ b/core/templates/layout.guest.php @@ -22,16 +22,7 @@ - - - $value) { - print_unescaped("$name='$value' "); - }; - print_unescaped('/>'); - ?> - + diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php index 6164d16ac1..9f94344b21 100644 --- a/core/templates/layout.user.php +++ b/core/templates/layout.user.php @@ -29,15 +29,7 @@ - - $value) { - print_unescaped("$name='$value' "); - }; - print_unescaped('/>'); - ?> - + diff --git a/lib/private/template.php b/lib/private/template.php index fe0cde53ff..9ad9d5466d 100644 --- a/lib/private/template.php +++ b/lib/private/template.php @@ -158,10 +158,15 @@ class OC_Template extends \OC\Template\Base { * Add a custom element to the header * @param string $tag tag name of 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='') { - $this->headers[]=array('tag'=>$tag,'attributes'=>$attributes, 'text'=>$text); + public function addHeader($tag, $attributes, $text=null) { + $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); // Add custom headers - $page->assign('headers', $this->headers, false); + $headers = ''; 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']).''; + } else { + $headers .= '/>'; + } } - $page->assign( "content", $data, false ); + $page->assign('headers', $headers, false); + + $page->assign('content', $data, false ); return $page->fetchPage(); } else{ diff --git a/lib/private/util.php b/lib/private/util.php index 6cd982c222..b949406690 100644 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -370,13 +370,13 @@ class OC_Util { /** * 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 array $attributes array of attributes 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( 'tag' => $tag, 'attributes' => $attributes, diff --git a/lib/public/util.php b/lib/public/util.php index 4c4a84af24..e40fdcfae7 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -138,12 +138,14 @@ class Util { /** * 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 array $attributes array of attributes for the element * @param string $text the text content for the element */ - public static function addHeader( $tag, $attributes, $text='') { - \OC_Util::addHeader( $tag, $attributes, $text ); + public static function addHeader($tag, $attributes, $text=null) { + \OC_Util::addHeader($tag, $attributes, $text); } /**