<?php defined('SYSPATH') or die('No direct script access.');
/*
* Class representing a head object
* Implements singleton through the instance method
* @author M.Wells
* @url www.ninjapenguin.co.uk
*/
class Head
{
private static $obj = NULL;
private static $theHead = "";
private static $title = "";
function __construct() {}
/*
* Factory function to implement singleton pattern for this object
*/
public static function instance()
{
(self::$obj === null) AND self::$obj = new Head;
return self::$obj;
}
/*
* Function to write to the head
* @param String Data to write to the head
*/
protected static function write($data)
{
self::$theHead .= $data;
return self::$obj;
}
/**
* Function to add the title to the head
*/
public static function title($title)
{
self::$title = "<title>".$title."</title>";
return self::$obj;
}
/*
* Shorthand to write javascript
*/
public static function js($data)
{
self::write('<script type="text/javascript">'.$data.'</script>');
return self::$obj;
}
/*
* shorthand to write a style
*/
public static function style($data)
{
self::write('<style type="text/css">'.$data.'</style>');
return self::$obj;
}
/*
* Shorthand to include an external javascript file
*/
public static function incJs($src)
{
self::write('<script type="text/javascript" src="'.url::base().$src.'"></script>');
return self::$obj;
}
/*
* Shorthand to include a CSS file
*/
public static function incCss($src)
{
self::write('<link rel="stylesheet" type="text/css" href="'.url::base().$src.'" />');
return self::$obj;
}
/*
* Function to return the head content
*/
public static function get()
{
return self::$theHead;
}
/*
* Returns the head string if the object is output
*/
public function __toString()
{
//Format the head here!
return self::$title."\n\t".Head::get();
}
}