summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Adam <sebastien.adam.webdev@gmail.com>2015-11-25 18:25:17 +0100
committerSébastien Adam <sebastien.adam.webdev@gmail.com>2015-11-25 18:25:17 +0100
commitfd70fa5ff7cec722a69f3e720a962aea3dec03fe (patch)
treee4dbe851751e8adfbdfb0f9a3c44d0385017a1fd
parentbb5184e9b84f5f3c56ae82bfded1cbc2d00cade1 (diff)
HTML Helper - meta(): now can generate HTML meta charset & Open Graph property
-rw-r--r--system/helpers/html_helper.php9
-rw-r--r--user_guide_src/source/helpers/html_helper.rst12
2 files changed, 11 insertions, 10 deletions
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php
index 28fbe00be..4e25f8c9b 100644
--- a/system/helpers/html_helper.php
+++ b/system/helpers/html_helper.php
@@ -338,7 +338,7 @@ if ( ! function_exists('link_tag'))
if ( ! function_exists('meta'))
{
/**
- * Generates meta tags from an array of key/values
+ * Generates meta tags from an array of key/values, compatible with html5 and open graph
*
* @param array
* @param string
@@ -359,13 +359,14 @@ if ( ! function_exists('meta'))
// Turn single array into multidimensional
$name = array($name);
}
-
+ $allowed_type = array('charset', 'http-equiv', 'name', 'property');
$str = '';
foreach ($name as $meta)
{
- $type = (isset($meta['type']) && $meta['type'] !== 'name') ? 'http-equiv' : 'name';
+ $meta['type'] = (isset($meta['type']) && ($meta['type'] == 'equiv')) ? 'http-equiv' : $meta['type']; // backward compatibility
+ $type = (isset($meta['type']) && in_array($meta['type'], $allowed_type))? $meta['type'] : 'name';
$name = isset($meta['name']) ? $meta['name'] : '';
- $content = isset($meta['content']) ? $meta['content'] : '';
+ $content = (isset($meta['content']) && $type != 'charset') ? $meta['content'] : '';
$newline = isset($meta['newline']) ? $meta['newline'] : "\n";
$str .= '<meta '.$type.'="'.$name.'" content="'.$content.'" />'.$newline;
diff --git a/user_guide_src/source/helpers/html_helper.rst b/user_guide_src/source/helpers/html_helper.rst
index 2c748bea0..1445b3bf0 100644
--- a/user_guide_src/source/helpers/html_helper.rst
+++ b/user_guide_src/source/helpers/html_helper.rst
@@ -285,9 +285,9 @@ The following functions are available:
echo meta('description', 'My Great site');
// Generates: <meta name="description" content="My Great Site" />
- echo meta('Content-type', 'text/html; charset=utf-8', 'equiv');
- // Note the third parameter. Can be "equiv" or "name"
- // Generates: <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+ echo meta('refresh', '30', 'http-equiv');
+ // Note the third parameter. Can be "charset", "http-equiv", "name" or "property"
+ // Generates: <meta http-equiv="refresh" content="30" />
echo meta(array('name' => 'robots', 'content' => 'no-cache'));
// Generates: <meta name="robots" content="no-cache" />
@@ -310,8 +310,8 @@ The following functions are available:
'content' => 'no-cache'
),
array(
- 'name' => 'Content-type',
- 'content' => 'text/html; charset=utf-8', 'type' => 'equiv'
+ 'name' => 'UTF-8',
+ 'type' => 'charset'
)
);
@@ -321,7 +321,7 @@ 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 = 'xhtml1-strict'])