1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-06 14:46:56 +02:00

generic meta response methods

This commit is contained in:
secretr
2012-05-11 09:45:35 +00:00
parent 6ca55ce728
commit 498db4ec61

View File

@@ -3408,6 +3408,7 @@ class eResponse
protected $_META_KEYWORDS = array();
protected $_render_mod = array('default' => 'default');
protected $_meta_title_separator = ' - ';
protected $_meta = array();
protected $_title_separator = ' » ';
protected $_content_type = 'html';
protected $_content_type_arr = array(
@@ -3664,6 +3665,52 @@ class eResponse
}
return vartrue($this->_render_mod[$ns], null);
}
/**
* Generic meta information
* Example usage:
* addMeta('og:title', 'My Title');
* addMeta(null, 30, array('http-equiv' => 'refresh'));
* addMeta(null, null, array('http-equiv' => 'refresh', 'content' => 30)); // same as above
* @param string $name 'name' attribute value, or null to avoid it
* @param string $content 'content' attribute value, or null to avoid it
* @param array $extended format 'attribute_name' => 'value'
* @return eResponse
*/
public function addMeta($name = null, $content = null, $extended = array())
{
$attr = array();
if(null !== $name) $attr['name'] = $name;
if(null !== $content) $attr['content'] = $content;
if(!empty($extended))
{
if(!empty($attr)) $attr = array_merge($attr, $extended);
else $attr = $extended;
}
if(!empty($attr)) $this->_meta[] = $attr;
return $this;
}
/**
* Render meta tags, registered via addMeta() method
* @return string
*/
public function renderMeta()
{
$this->_meta = array_unique($this->_meta);
$attrData = '';
foreach ($this->_meta as $attr)
{
foreach ($attr as $p => $v)
{
$attrData .= '<meta';
$attrData .= ' '.preg_replace('/[\w\-]/', '', $p).'="'.str_replace(array('"', '<'), '', $v).'"';
$attrData .= ' />'."\n";
}
}
return $attrData;
}
/**
* Add meta title, description and keywords