[eluser]echoDreamz[/eluser]
Needed a very simple way to add meta tags on the fly to my CI header view (since I use alot of database generated content and redirects). I came up with this.
Please let me know what you think about it.
Code:
<?php
/**
* echoDreamz Metatag Class
*
* -----------------------------------------------------
* Provides very simple means of managing and displaying
* multiple HTML META tags.
* -----------------------------------------------------
*
* @package CodeIgniter
* @subpackage Libraries
* @author Chris York (echoDreamz)
* @copyright Copyright (c) 2008 - 2009 By echoDreamz
* @link http://www.echodreamz.com
* @since v1.0.0 | CodeIgniter v1.7.2
*/
/**
* Disallow direct script access
*/
if (!defined('BASEPATH'))
{
exit('<strong>Denied!</strong> Direct script access is not allowed!');
}
/**
* Metatag class
*
* ----------------------------------------------------
* See above ^^ for details about this class
* ----------------------------------------------------
*
* @package CodeIgniter
* @subpackage Libraries
* @author Chris York (echoDreamz)
* @category Library
*/
final class Metatag
{
/**
* Stored CI meta() returns
*
* @access Private
* @var Array
*/
private $_meta_entries = array();
/**
* Metatag class constructor
*
* @access Public
*/
public function __construct()
{
// Obtain the CI base instance
$CI =& get_instance();
/**
* Load the HTML helper methods
* We are specifically wanting the meta() method.
*/
$CI->load->helper('html');
}
/**
* Assign a new META tag to the stack
*
* @access Public
* @param Mixed $name META tag name
* @param Mixed $content META tag content
* @param String $type META tag type (name, http-equiv etc.)
*/
public function assign($name, $content, $type = 'name')
{
$this->_meta_entries[] = meta($name, $content, $type, '');
}
/**
* Generates the final output of META tags to the master CI view
*
* @access Public
* @param String $newline Newline char
* @return String
*/
public function generate($newline = PHP_EOL)
{
// Insure we have something to return... Else return nothing!
if (count($this->_meta_entries) === 0)
{
return '';
}
return implode($this->_meta_entries, $newline);
}
}
/* End Metatag.php */
/* File Version: 1.0.5 | October 3rd 2009 */