Guest User

Untitled

a guest
Mar 18th, 2011
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.54 KB | None | 0 0
  1. <?php
  2. class Html_Title
  3. {
  4.     private $data = array();
  5.     private $separator;
  6.     private static $instance;
  7.  
  8.     public static function getInstance($separator = ' / ')
  9.     {
  10.         if (!self::$instance)
  11.         {
  12.             $class = __CLASS__;
  13.  
  14.             self::$instance = new $class($separator);
  15.         }
  16.  
  17.         return self::$instance;
  18.     }
  19.  
  20.     private function __construct($separator)
  21.     {
  22.         $this->separator = $separator;
  23.     }
  24.  
  25.     public function getCountElements()
  26.     {
  27.         return count($this->data);
  28.     }
  29.  
  30.     /**
  31.      * Добавляет элемент хлебных крошек title
  32.      *
  33.      * @param mixed
  34.      * @return void
  35.      */
  36.     public function add()
  37.     {
  38.         foreach (func_get_args() as $value)
  39.         {
  40.             if (is_object($value) && $value instanceof Cover_Array)
  41.             {
  42.                 $value = $value->getData();
  43.             }
  44.  
  45.             if (is_array($value))
  46.             {
  47.                 foreach ($value as $element)
  48.                 {
  49.                     if ($element = strip_tags($element))
  50.                     {
  51.                         $this->data[] = $element;
  52.                     }
  53.                 }
  54.             }
  55.             else
  56.             {
  57.                 if ($value = strip_tags($value))
  58.                 {
  59.                     $this->data[] = $value;
  60.                 }
  61.             }
  62.         }
  63.  
  64.         return $this;
  65.     }
  66.  
  67.     /**
  68.      * Удаляет элемент хлебных крошек title
  69.      * под индексом $i.
  70.      *
  71.      * @param int
  72.      * @return void
  73.      */
  74.     public function deleteByIndex($i)
  75.     {
  76.         unset($this->data[$i]);
  77.     }
  78.  
  79.     /**
  80.      * Возвращает элемент хлебных крошек title
  81.      * под индексом $i.
  82.      *
  83.      * @param int
  84.      * @return string
  85.      */
  86.     public function getByIndex($i)
  87.     {
  88.         return isset($this->data[$i]) ? $this->data[$i] : NULL;
  89.     }
  90.  
  91.     /**
  92.      * Возвращает строку для подстановки в тег html title
  93.      *
  94.      * @param string
  95.      * @return void
  96.      */
  97.     public function getTitle()
  98.     {
  99.         return htmlspecialchars(implode($this->separator, array_reverse($this->data)), ENT_QUOTES);
  100.     }
  101.  
  102.     /**
  103.      * Возвращает html-код элемента управления.
  104.      *
  105.      * @param void
  106.      * @return string
  107.      */
  108.     public function getHtml()
  109.     {
  110.         return '<title>'.$this->getTitle().'</title>';
  111.     }
  112. }
  113. ?>
Advertisement
Add Comment
Please, Sign In to add comment