summaryrefslogtreecommitdiffstats
path: root/system/helpers/html_helper.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/helpers/html_helper.php')
-rw-r--r--system/helpers/html_helper.php311
1 files changed, 143 insertions, 168 deletions
diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php
index b64b60650..6fabf9c05 100644
--- a/system/helpers/html_helper.php
+++ b/system/helpers/html_helper.php
@@ -1,66 +1,73 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* CodeIgniter
*
- * An open source application development framework for PHP 5.1.6 or newer
+ * An open source application development framework for PHP 5.2.4 or newer
+ *
+ * NOTICE OF LICENSE
+ *
+ * Licensed under the Open Software License version 3.0
+ *
+ * This source file is subject to the Open Software License (OSL 3.0) that is
+ * bundled with this package in the files license.txt / license.rst. It is
+ * also available through the world wide web at this URL:
+ * http://opensource.org/licenses/OSL-3.0
+ * If you did not receive a copy of the license and are unable to obtain it
+ * through the world wide web, please send an email to
+ * licensing@ellislab.com so we can send you a copy immediately.
*
* @package CodeIgniter
- * @author ExpressionEngine Dev Team
- * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
- * @license http://codeigniter.com/user_guide/license.html
+ * @author EllisLab Dev Team
+ * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
+ * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/
-// ------------------------------------------------------------------------
-
/**
* CodeIgniter HTML Helpers
*
* @package CodeIgniter
* @subpackage Helpers
* @category Helpers
- * @author ExpressionEngine Dev Team
+ * @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/helpers/html_helper.html
*/
// ------------------------------------------------------------------------
-/**
- * Heading
- *
- * Generates an HTML heading tag. First param is the data.
- * Second param is the size of the heading tag.
- *
- * @access public
- * @param string
- * @param integer
- * @return string
- */
if ( ! function_exists('heading'))
{
+ /**
+ * Heading
+ *
+ * Generates an HTML heading tag.
+ *
+ * @param string content
+ * @param int heading level
+ * @param string
+ * @return string
+ */
function heading($data = '', $h = '1', $attributes = '')
{
- $attributes = ($attributes != '') ? ' '.$attributes : $attributes;
- return "<h".$h.$attributes.">".$data."</h".$h.">";
+ return '<h'.$h.($attributes !== '' ? ' ' : '').$attributes.'>'.$data.'</h'.$h.'>';
}
}
// ------------------------------------------------------------------------
-/**
- * Unordered List
- *
- * Generates an HTML unordered list from an single or multi-dimensional array.
- *
- * @access public
- * @param array
- * @param mixed
- * @return string
- */
if ( ! function_exists('ul'))
{
+ /**
+ * Unordered List
+ *
+ * Generates an HTML unordered list from an single or multi-dimensional array.
+ *
+ * @param array
+ * @param mixed
+ * @return string
+ */
function ul($list, $attributes = '')
{
return _list('ul', $list, $attributes);
@@ -69,18 +76,17 @@ if ( ! function_exists('ul'))
// ------------------------------------------------------------------------
-/**
- * Ordered List
- *
- * Generates an HTML ordered list from an single or multi-dimensional array.
- *
- * @access public
- * @param array
- * @param mixed
- * @return string
- */
if ( ! function_exists('ol'))
{
+ /**
+ * Ordered List
+ *
+ * Generates an HTML ordered list from an single or multi-dimensional array.
+ *
+ * @param array
+ * @param mixed
+ * @return string
+ */
function ol($list, $attributes = '')
{
return _list('ol', $list, $attributes);
@@ -89,20 +95,19 @@ if ( ! function_exists('ol'))
// ------------------------------------------------------------------------
-/**
- * Generates the list
- *
- * Generates an HTML ordered list from an single or multi-dimensional array.
- *
- * @access private
- * @param string
- * @param mixed
- * @param mixed
- * @param integer
- * @return string
- */
if ( ! function_exists('_list'))
{
+ /**
+ * Generates the list
+ *
+ * Generates an HTML ordered list from an single or multi-dimensional array.
+ *
+ * @param string
+ * @param mixed
+ * @param mixed
+ * @param int
+ * @return string
+ */
function _list($type = 'ul', $list, $attributes = '', $depth = 0)
{
// If an array wasn't submitted there's nothing to do...
@@ -112,7 +117,7 @@ if ( ! function_exists('_list'))
}
// Set the indentation based on the depth
- $out = str_repeat(" ", $depth);
+ $out = str_repeat(' ', $depth);
// Were any attributes submitted? If so generate a string
if (is_array($attributes))
@@ -120,17 +125,17 @@ if ( ! function_exists('_list'))
$atts = '';
foreach ($attributes as $key => $val)
{
- $atts .= ' ' . $key . '="' . $val . '"';
+ $atts .= ' '.$key.'="'.$val.'"';
}
$attributes = $atts;
}
- elseif (is_string($attributes) AND strlen($attributes) > 0)
+ elseif (is_string($attributes) && strlen($attributes) > 0)
{
- $attributes = ' '. $attributes;
+ $attributes = ' '.$attributes;
}
// Write the opening list tag
- $out .= "<".$type.$attributes.">\n";
+ $out .= '<'.$type.$attributes.">\n";
// Cycle through the list elements. If an array is
// encountered we will recursively call _list()
@@ -140,8 +145,7 @@ if ( ! function_exists('_list'))
{
$_last_list_item = $key;
- $out .= str_repeat(" ", $depth + 2);
- $out .= "<li>";
+ $out .= str_repeat(' ', $depth + 2).'<li>';
if ( ! is_array($val))
{
@@ -149,54 +153,46 @@ if ( ! function_exists('_list'))
}
else
{
- $out .= $_last_list_item."\n";
- $out .= _list($type, $val, '', $depth + 4);
- $out .= str_repeat(" ", $depth + 2);
+ $out .= $_last_list_item."\n"._list($type, $val, '', $depth + 4).str_repeat(' ', $depth + 2);
}
$out .= "</li>\n";
}
- // Set the indentation for the closing tag
- $out .= str_repeat(" ", $depth);
-
- // Write the closing list tag
- $out .= "</".$type.">\n";
-
- return $out;
+ // Set the indentation for the closing tag and apply it
+ return $out.str_repeat(' ', $depth).'</'.$type.">\n";
}
}
// ------------------------------------------------------------------------
-/**
- * Generates HTML BR tags based on number supplied
- *
- * @access public
- * @param integer
- * @return string
- */
if ( ! function_exists('br'))
{
+ /**
+ * Generates HTML BR tags based on number supplied
+ *
+ * @param int
+ * @return string
+ */
function br($num = 1)
{
- return str_repeat("<br />", $num);
+ return str_repeat('<br />', $num);
}
}
// ------------------------------------------------------------------------
-/**
- * Image
- *
- * Generates an <img /> element
- *
- * @access public
- * @param mixed
- * @return string
- */
if ( ! function_exists('img'))
{
+ /**
+ * Image
+ *
+ * Generates an <img /> element
+ *
+ * @param mixed
+ * @param bool
+ * @return string
+ */
function img($src = '', $index_page = FALSE)
{
if ( ! is_array($src) )
@@ -212,10 +208,9 @@ if ( ! function_exists('img'))
$img = '<img';
- foreach ($src as $k=>$v)
+ foreach ($src as $k => $v)
{
-
- if ($k == 'src' AND strpos($v, '://') === FALSE)
+ if ($k === 'src' && strpos($v, '://') === FALSE)
{
$CI =& get_instance();
@@ -230,40 +225,37 @@ if ( ! function_exists('img'))
}
else
{
- $img .= " $k=\"$v\"";
+ $img .= ' '.$k.'="'.$v.'"';
}
}
- $img .= '/>';
-
- return $img;
+ return $img.'/>';
}
}
// ------------------------------------------------------------------------
-/**
- * Doctype
- *
- * Generates a page document type declaration
- *
- * Valid options are xhtml-11, xhtml-strict, xhtml-trans, xhtml-frame,
- * html4-strict, html4-trans, and html4-frame. Values are saved in the
- * doctypes config file.
- *
- * @access public
- * @param string type The doctype to be generated
- * @return string
- */
if ( ! function_exists('doctype'))
{
+ /**
+ * Doctype
+ *
+ * Generates a page document type declaration
+ *
+ * Examples of valid options: html5, xhtml-11, xhtml-strict, xhtml-trans,
+ * xhtml-frame, html4-strict, html4-trans, and html4-frame.
+ * All values are saved in the doctypes config file.
+ *
+ * @param string type The doctype to be generated
+ * @return string
+ */
function doctype($type = 'xhtml1-strict')
{
global $_doctypes;
if ( ! is_array($_doctypes))
{
- if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'))
+ if (defined('ENVIRONMENT') && is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'))
{
include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php');
}
@@ -278,46 +270,37 @@ if ( ! function_exists('doctype'))
}
}
- if (isset($_doctypes[$type]))
- {
- return $_doctypes[$type];
- }
- else
- {
- return FALSE;
- }
+ return isset($_doctypes[$type]) ? $_doctypes[$type] : FALSE;
}
}
// ------------------------------------------------------------------------
-/**
- * Link
- *
- * Generates link to a CSS file
- *
- * @access public
- * @param mixed stylesheet hrefs or an array
- * @param string rel
- * @param string type
- * @param string title
- * @param string media
- * @param boolean should index_page be added to the css path
- * @return string
- */
if ( ! function_exists('link_tag'))
{
+ /**
+ * Link
+ *
+ * Generates link to a CSS file
+ *
+ * @param mixed stylesheet hrefs or an array
+ * @param string rel
+ * @param string type
+ * @param string title
+ * @param string media
+ * @param bool should index_page be added to the css path
+ * @return string
+ */
function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE)
{
$CI =& get_instance();
-
$link = '<link ';
if (is_array($href))
{
- foreach ($href as $k=>$v)
+ foreach ($href as $k => $v)
{
- if ($k == 'href' AND strpos($v, '://') === FALSE)
+ if ($k === 'href' && strpos($v, '://') === FALSE)
{
if ($index_page === TRUE)
{
@@ -330,15 +313,13 @@ if ( ! function_exists('link_tag'))
}
else
{
- $link .= "$k=\"$v\" ";
+ $link .= $k.'="'.$v.'" ';
}
}
-
- $link .= "/>";
}
else
{
- if ( strpos($href, '://') !== FALSE)
+ if (strpos($href, '://') !== FALSE)
{
$link .= 'href="'.$href.'" ';
}
@@ -353,35 +334,34 @@ if ( ! function_exists('link_tag'))
$link .= 'rel="'.$rel.'" type="'.$type.'" ';
- if ($media != '')
+ if ($media !== '')
{
$link .= 'media="'.$media.'" ';
}
- if ($title != '')
+ if ($title !== '')
{
$link .= 'title="'.$title.'" ';
}
-
- $link .= '/>';
}
-
- return $link;
+ return $link."/>\n";
}
}
// ------------------------------------------------------------------------
-/**
- * Generates meta tags from an array of key/values
- *
- * @access public
- * @param array
- * @return string
- */
if ( ! function_exists('meta'))
{
+ /**
+ * Generates meta tags from an array of key/values
+ *
+ * @param array
+ * @param string
+ * @param string
+ * @param string
+ * @return string
+ */
function meta($name = '', $content = '', $type = 'name', $newline = "\n")
{
// Since we allow the data to be passes as a string, a simple array
@@ -390,22 +370,19 @@ if ( ! function_exists('meta'))
{
$name = array(array('name' => $name, 'content' => $content, 'type' => $type, 'newline' => $newline));
}
- else
+ elseif (isset($name['name']))
{
// Turn single array into multidimensional
- if (isset($name['name']))
- {
- $name = array($name);
- }
+ $name = array($name);
}
$str = '';
foreach ($name as $meta)
{
- $type = ( ! isset($meta['type']) OR $meta['type'] == 'name') ? 'name' : 'http-equiv';
- $name = ( ! isset($meta['name'])) ? '' : $meta['name'];
- $content = ( ! isset($meta['content'])) ? '' : $meta['content'];
- $newline = ( ! isset($meta['newline'])) ? "\n" : $meta['newline'];
+ $type = ( ! isset($meta['type']) OR $meta['type'] === 'name') ? 'name' : 'http-equiv';
+ $name = isset($meta['name']) ? $meta['name'] : '';
+ $content = isset($meta['content']) ? $meta['content'] : '';
+ $newline = isset($meta['newline']) ? $meta['newline'] : "\n";
$str .= '<meta '.$type.'="'.$name.'" content="'.$content.'" />'.$newline;
}
@@ -416,21 +393,19 @@ if ( ! function_exists('meta'))
// ------------------------------------------------------------------------
-/**
- * Generates non-breaking space entities based on number supplied
- *
- * @access public
- * @param integer
- * @return string
- */
if ( ! function_exists('nbs'))
{
+ /**
+ * Generates non-breaking space entities based on number supplied
+ *
+ * @param int
+ * @return string
+ */
function nbs($num = 1)
{
- return str_repeat("&nbsp;", $num);
+ return str_repeat('&nbsp;', $num);
}
}
-
/* End of file html_helper.php */
/* Location: ./system/helpers/html_helper.php */ \ No newline at end of file