Ejemplo n.º 1
0
 /**
  * http Content-Type
  * @param  string $value  meta value
  * @param  mixed  $attr   Extra attributes
  * @return array          Tag data
  */
 protected static function _contentType($value, $attrs = array())
 {
     if (false === strpos($value, 'charset')) {
         if ($data = HeadsContainer::get('meta', '_charset')) {
             $value = trim($value, ' ;') . '; charset=' . $data[0]['attrs']['charset'];
         }
     }
     $attrs['http-equiv'] = 'Content-Type';
     $attrs['content'] = $value;
     return self::data(__FUNCTION__, $attrs);
 }
Ejemplo n.º 2
0
 /**
  * Get duplicate value
  * @param  string $category  Container category name
  * @param  string $key       Container key name
  * @param  array $attr       Extra attributes
  * @param  mixed $value      If array to string
  * @return array
  */
 protected static function duplicate($category, $key, $attr, $value)
 {
     $key = self::key($key);
     if (is_string($value)) {
         $value = str_replace(array(' ,', ', '), ',', $value);
         $value = explode(',', $value);
     }
     if ($datas = HeadsContainer::get($category, $key)) {
         $current = $datas[0]['attrs'][$attr];
         $current = explode(',', $current);
         $value = array_merge($current, $value);
     }
     $value = array_filter($value);
     $value = array_unique($value);
     $value = implode(',', $value);
     return $value;
 }
Ejemplo n.º 3
0
 /**
  * Get head html
  * @param  array  $options  Build option
  * @return string           heads HTML
  */
 public static function html(array $options = array())
 {
     $datas = HeadsContainer::datas();
     $htmls = array();
     // charset is always on top
     if ($charset = HeadsContainer::get('meta', 'charset')) {
         $attr = array();
         foreach ($charset[0]['attrs'] as $name => $val) {
             $attr[] = $name . '="' . htmlspecialchars($val, ENT_QUOTES) . '"';
         }
         $htmls['charset'][] = '<' . $charset[0]['tag'] . ' ' . implode(' ', $attr) . '>';
     }
     foreach ($datas as $type => $values) {
         $htmls[$type] = array();
         foreach ($values as $key => $rows) {
             // charset is always on top
             if ('meta' === $type && 'charset' === $key) {
                 continue;
             }
             foreach ($rows as $row) {
                 $attr = array();
                 foreach ($row['attrs'] as $name => $val) {
                     if (!is_scalar($val)) {
                         $attr[] = $name . '=""';
                     } else {
                         $attr[] = $name . '="' . htmlspecialchars($val, ENT_QUOTES) . '"';
                     }
                 }
                 $htmls[$type][] = '<' . $row['tag'] . ' ' . implode(' ', $attr) . '>';
             }
         }
     }
     if (empty($htmls)) {
         return;
     }
     $indent = self::option('indent');
     if (!empty($options['indent'])) {
         $indent = $options['indent'];
     }
     $break = self::option('break');
     if (!empty($options['break'])) {
         $break = $options['break'];
     }
     $html = $break;
     foreach (array_merge(array('charset'), self::option('order')) as $type) {
         if (!empty($htmls[$type])) {
             $html .= $indent . implode($break . $indent, $htmls[$type]) . $break;
         }
     }
     return $html;
 }