summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2016-01-11 12:20:12 +0100
committerAndrey Andreev <narf@devilix.net>2016-01-11 12:20:12 +0100
commit8f1047ff6bc961159a7103e7be02e6cc459d925e (patch)
tree1a346869a5f3500f1423dcf7b58ae6c82da1a8ca
parent85ce9ab3f569450396a6f0688b2f047f58527598 (diff)
Polish changes from PR #4269
-rw-r--r--system/helpers/html_helper.php28
-rw-r--r--tests/codeigniter/helpers/html_helper_test.php32
-rw-r--r--user_guide_src/source/helpers/html_helper.rst12
3 files changed, 50 insertions, 22 deletions
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php
index 5cc994ff1..becd9a00c 100644
--- a/system/helpers/html_helper.php
+++ b/system/helpers/html_helper.php
@@ -359,17 +359,31 @@ if ( ! function_exists('meta'))
// Turn single array into multidimensional
$name = array($name);
}
- $allowed_type = array('charset', 'http-equiv', 'name', 'property');
+
+ $allowed_types = array('charset', 'http-equiv', 'name', 'property');
$str = '';
foreach ($name as $meta)
{
- $meta['type'] = isset($meta['type']) ? (($meta['type'] === 'equiv') ? 'http-equiv' : $meta['type']) : ''; // backward compatibility
- $type = in_array($meta['type'], $allowed_type) ? $meta['type'] : 'name';
- $name = isset($meta['name']) ? $meta['name'] : '';
- $content = isset($meta['content']) ? $meta['content'] : '';
- $newline = isset($meta['newline']) ? $meta['newline'] : "\n";
+ // This is to preserve BC with pre-3.1 versions where only
+ // 'http-equiv' (default) and 'name' were supported.
+ if (isset($meta['type']))
+ {
+ if ($meta['type'] === 'equiv')
+ {
+ $meta['type'] === 'http-equiv';
+ }
+ elseif ( ! in_array($meta['type'], $allowed_types, TRUE))
+ {
+ $meta['type'] = 'name';
+ }
+ }
+
+ $type = isset($meta['type']) ? $meta['type'] : 'name';
+ $name = isset($meta['name']) ? $meta['name'] : '';
+ $content = isset($meta['content']) ? $meta['content'] : '';
+ $newline = isset($meta['newline']) ? $meta['newline'] : "\n";
- $str .= '<meta '.$type.'="'.$name.(($type === 'charset')?'':'" content="'.$content).'" />'.$newline;
+ $str .= '<meta '.$type.'="'.$name.($type === 'charset' ? '' : '" content="'.$content).'" />'.$newline;
}
return $str;
diff --git a/tests/codeigniter/helpers/html_helper_test.php b/tests/codeigniter/helpers/html_helper_test.php
index 0b9655bf5..029f3f4cd 100644
--- a/tests/codeigniter/helpers/html_helper_test.php
+++ b/tests/codeigniter/helpers/html_helper_test.php
@@ -81,16 +81,24 @@ EOH;
public function test_meta()
{
- $this->assertEquals("<meta name=\"test\" content=\"foo\" />\n", meta('test', 'foo'));
-
- $expect = "<meta name=\"foo\" content=\"\" />\n";
-
- $this->assertEquals($expect, meta(array('name' => 'foo')));
-
- $expect = "<meta charset=\"foo\" />\n";
-
- $this->assertEquals($expect, meta(array('name' => 'foo', 'type' => 'charset')));
-
+ $this->assertEquals(
+ "<meta name=\"test\" content=\"foo\" />\n",
+ meta('test', 'foo')
+ );
+
+ $this->assertEquals(
+ "<meta name=\"foo\" content=\"\" />\n",
+ meta(array('name' => 'foo'))
+ );
+
+ $this->assertEquals(
+ "<meta charset=\"foo\" />\n",
+ meta(array('name' => 'foo', 'type' => 'charset'))
+ );
+
+ $this->assertEquals(
+ "<meta charset=\"foo\" />\n",
+ meta(array('name' => 'foo', 'type' => 'charset'))
+ );
}
-
-}
+} \ No newline at end of file
diff --git a/user_guide_src/source/helpers/html_helper.rst b/user_guide_src/source/helpers/html_helper.rst
index fffb2cab4..a19924dde 100644
--- a/user_guide_src/source/helpers/html_helper.rst
+++ b/user_guide_src/source/helpers/html_helper.rst
@@ -310,6 +310,11 @@ The following functions are available:
'content' => 'no-cache'
),
array(
+ 'name' => 'Content-Type',
+ 'type' => 'http-equiv',
+ 'content' => 'text/html; charset=utf-8'
+ ),
+ array(
'name' => 'UTF-8',
'type' => 'charset'
)
@@ -321,21 +326,22 @@ The following functions are available:
// <meta name="description" content="My Great Site" />
// <meta name="keywords" content="love, passion, intrigue, deception" />
// <meta name="robots" content="no-cache" />
+ // <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
// <meta charset="UTF-8" />
-.. php:function:: doctype([$type = 'html5'])
+.. php:function:: doctype([$type = 'xhtml1-strict'])
:param string $type: Doctype name
:returns: HTML DocType tag
:rtype: string
- Helps you generate document type declarations, or DTD's. HTML 5
+ Helps you generate document type declarations, or DTD's. XHTML 1.0
is used by default, but many doctypes are available.
Example::
- echo doctype(); // <!DOCTYPE html>
+ echo doctype(); // <!DOCTYPE PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
echo doctype('html4-trans'); // <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">