blob: a11d23e15a1d3951f1f6fb5fcda0015595ba774b [file] [log] [blame]
Derek Allardd2df9bc2007-04-15 17:41:17 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
Derek Allard3d879d52008-01-18 19:41:32 +00008 * @author ExpressionEngine Dev Team
Derek Allardd2df9bc2007-04-15 17:41:17 +00009 * @copyright Copyright (c) 2006, EllisLab, Inc.
Derek Jones7a9193a2008-01-21 18:39:20 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
Derek Allardd2df9bc2007-04-15 17:41:17 +000012 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * CodeIgniter HTML Helpers
20 *
21 * @package CodeIgniter
22 * @subpackage Helpers
23 * @category Helpers
Derek Allard3d879d52008-01-18 19:41:32 +000024 * @author ExpressionEngine Dev Team
Derek Jones7a9193a2008-01-21 18:39:20 +000025 * @link http://codeigniter.com/user_guide/helpers/html_helper.html
Derek Allardd2df9bc2007-04-15 17:41:17 +000026 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * Heading
32 *
33 * Generates an HTML heading tag. First param is the data.
34 * Second param is the size of the heading tag.
35 *
36 * @access public
37 * @param string
38 * @param integer
39 * @return string
40 */
41function heading($data = '', $h = '1')
42{
43 return "<h".$h.">".$data."</h".$h.">";
44}
45
46// ------------------------------------------------------------------------
47
48/**
49 * Unordered List
50 *
51 * Generates an HTML unordered list from an single or multi-dimensional array.
52 *
53 * @access public
54 * @param array
55 * @param mixed
56 * @return string
57 */
58function ul($list, $attributes = '')
59{
60 return _list('ul', $list, $attributes);
61}
62
63// ------------------------------------------------------------------------
64
65/**
66 * Ordered List
67 *
68 * Generates an HTML ordered list from an single or multi-dimensional array.
69 *
70 * @access public
71 * @param array
72 * @param mixed
73 * @return string
74 */
75function ol($list, $attributes = '')
76{
77 return _list('ol', $list, $attributes);
78}
79
80// ------------------------------------------------------------------------
81
82/**
83 * Generates the list
84 *
85 * Generates an HTML ordered list from an single or multi-dimensional array.
86 *
87 * @access private
88 * @param string
89 * @param mixed
90 * @param mixed
91 * @param intiger
92 * @return string
93 */
94function _list($type = 'ul', $list, $attributes = '', $depth = 0)
95{
96 // If an array wasn't submitted there's nothing to do...
97 if ( ! is_array($list))
98 {
99 return $list;
100 }
101
102 // Set the indentation based on the depth
103 $out = str_repeat(" ", $depth);
104
105 // Were any attributes submitted? If so generate a string
106 if (is_array($attributes))
107 {
108 $atts = '';
109 foreach ($attributes as $key => $val)
110 {
111 $atts .= ' ' . $key . '="' . $val . '"';
112 }
113 $attributes = $atts;
114 }
115
116 // Write the opening list tag
117 $out .= "<".$type.$attributes.">\n";
118
119 // Cycle through the list elements. If an array is
120 // encountered we will recursively call _list()
121
122 static $_last_list_item = '';
123 foreach ($list as $key => $val)
124 {
125 $_last_list_item = $key;
126
127 $out .= str_repeat(" ", $depth + 2);
128 $out .= "<li>";
129
130 if ( ! is_array($val))
131 {
132 $out .= $val;
133 }
134 else
135 {
136 $out .= $_last_list_item."\n";
137 $out .= _list($type, $val, '', $depth + 4);
138 $out .= str_repeat(" ", $depth + 2);
139 }
140
141 $out .= "</li>\n";
142 }
143
144 // Set the indentation for the closing tag
145 $out .= str_repeat(" ", $depth);
146
147 // Write the closing list tag
148 $out .= "</".$type.">\n";
149
150 return $out;
151}
152
153// ------------------------------------------------------------------------
154
155/**
156 * Generates HTML BR tags based on number supplied
157 *
158 * @access public
159 * @param integer
160 * @return string
161 */
162function br($num = 1)
163{
164 return str_repeat("<br />", $num);
165}
166
167// ------------------------------------------------------------------------
168
169/**
170 * Generates non-breaking space entities based on number supplied
171 *
172 * @access public
173 * @param integer
174 * @return string
175 */
176function nbs($num = 1)
177{
178 return str_repeat("&nbsp;", $num);
179}
180
181// ------------------------------------------------------------------------
182
183/**
184 * Generates meta tags from an array of key/values
185 *
186 * @access public
187 * @param array
188 * @return string
189 */
190function meta($meta = array(), $newline = "\n")
191{
192 $str = '';
193 foreach ($meta as $key => $val)
194 {
195 $str .= '<meta http-equiv="'.$key.'" content="'.$val.'" />'.$newline;
196 }
197
198 return $str;
199}
200
201
202
203
adminb0dd10f2006-08-25 17:25:49 +0000204?>