Subversion-Projekte lars-tiefland.ci

Revision

Revision 2242 | Revision 2257 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
68 lars 1
<?php
2
/**
3
 * CodeIgniter
4
 *
5
 * An open source application development framework for PHP
6
 *
7
 * This content is released under the MIT License (MIT)
8
 *
2254 lars 9
 * Copyright (c) 2014 - 2017, British Columbia Institute of Technology
68 lars 10
 *
11
 * Permission is hereby granted, free of charge, to any person obtaining a copy
12
 * of this software and associated documentation files (the "Software"), to deal
13
 * in the Software without restriction, including without limitation the rights
14
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
 * copies of the Software, and to permit persons to whom the Software is
16
 * furnished to do so, subject to the following conditions:
17
 *
18
 * The above copyright notice and this permission notice shall be included in
19
 * all copies or substantial portions of the Software.
20
 *
21
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
 * THE SOFTWARE.
28
 *
29
 * @package	CodeIgniter
30
 * @author	EllisLab Dev Team
31
 * @copyright	Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
2254 lars 32
 * @copyright	Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
68 lars 33
 * @license	http://opensource.org/licenses/MIT	MIT License
34
 * @link	https://codeigniter.com
35
 * @since	Version 1.0.0
36
 * @filesource
37
 */
38
defined('BASEPATH') OR exit('No direct script access allowed');
39
 
40
/**
41
 * CodeIgniter HTML Helpers
42
 *
43
 * @package		CodeIgniter
44
 * @subpackage	Helpers
45
 * @category	Helpers
46
 * @author		EllisLab Dev Team
47
 * @link		https://codeigniter.com/user_guide/helpers/html_helper.html
48
 */
49
 
50
// ------------------------------------------------------------------------
51
 
52
if ( ! function_exists('heading'))
53
{
54
	/**
55
	 * Heading
56
	 *
57
	 * Generates an HTML heading tag.
58
	 *
59
	 * @param	string	content
60
	 * @param	int	heading level
61
	 * @param	string
62
	 * @return	string
63
	 */
64
	function heading($data = '', $h = '1', $attributes = '')
65
	{
66
		return '<h'.$h._stringify_attributes($attributes).'>'.$data.'</h'.$h.'>';
67
	}
68
}
69
 
70
// ------------------------------------------------------------------------
71
 
72
if ( ! function_exists('ul'))
73
{
74
	/**
75
	 * Unordered List
76
	 *
77
	 * Generates an HTML unordered list from an single or multi-dimensional array.
78
	 *
79
	 * @param	array
80
	 * @param	mixed
81
	 * @return	string
82
	 */
83
	function ul($list, $attributes = '')
84
	{
85
		return _list('ul', $list, $attributes);
86
	}
87
}
88
 
89
// ------------------------------------------------------------------------
90
 
91
if ( ! function_exists('ol'))
92
{
93
	/**
94
	 * Ordered List
95
	 *
96
	 * Generates an HTML ordered list from an single or multi-dimensional array.
97
	 *
98
	 * @param	array
99
	 * @param	mixed
100
	 * @return	string
101
	 */
102
	function ol($list, $attributes = '')
103
	{
104
		return _list('ol', $list, $attributes);
105
	}
106
}
107
 
108
// ------------------------------------------------------------------------
109
 
110
if ( ! function_exists('_list'))
111
{
112
	/**
113
	 * Generates the list
114
	 *
115
	 * Generates an HTML ordered list from an single or multi-dimensional array.
116
	 *
117
	 * @param	string
118
	 * @param	mixed
119
	 * @param	mixed
120
	 * @param	int
121
	 * @return	string
122
	 */
123
	function _list($type = 'ul', $list = array(), $attributes = '', $depth = 0)
124
	{
125
		// If an array wasn't submitted there's nothing to do...
126
		if ( ! is_array($list))
127
		{
128
			return $list;
129
		}
130
 
131
		// Set the indentation based on the depth
132
		$out = str_repeat(' ', $depth)
133
			// Write the opening list tag
134
			.'<'.$type._stringify_attributes($attributes).">\n";
135
 
136
 
137
		// Cycle through the list elements.  If an array is
138
		// encountered we will recursively call _list()
139
 
140
		static $_last_list_item = '';
141
		foreach ($list as $key => $val)
142
		{
143
			$_last_list_item = $key;
144
 
145
			$out .= str_repeat(' ', $depth + 2).'<li>';
146
 
147
			if ( ! is_array($val))
148
			{
149
				$out .= $val;
150
			}
151
			else
152
			{
153
				$out .= $_last_list_item."\n"._list($type, $val, '', $depth + 4).str_repeat(' ', $depth + 2);
154
			}
155
 
156
			$out .= "</li>\n";
157
		}
158
 
159
		// Set the indentation for the closing tag and apply it
160
		return $out.str_repeat(' ', $depth).'</'.$type.">\n";
161
	}
162
}
163
 
164
// ------------------------------------------------------------------------
165
 
166
if ( ! function_exists('img'))
167
{
168
	/**
169
	 * Image
170
	 *
171
	 * Generates an <img /> element
172
	 *
173
	 * @param	mixed
174
	 * @param	bool
175
	 * @param	mixed
176
	 * @return	string
177
	 */
178
	function img($src = '', $index_page = FALSE, $attributes = '')
179
	{
180
		if ( ! is_array($src) )
181
		{
182
			$src = array('src' => $src);
183
		}
184
 
185
		// If there is no alt attribute defined, set it to an empty string
186
		if ( ! isset($src['alt']))
187
		{
188
			$src['alt'] = '';
189
		}
190
 
191
		$img = '<img';
192
 
193
		foreach ($src as $k => $v)
194
		{
2107 lars 195
			if ($k === 'src' && ! preg_match('#^(data:[a-z,;])|(([a-z]+:)?(?<!data:)//)#i', $v))
68 lars 196
			{
197
				if ($index_page === TRUE)
198
				{
199
					$img .= ' src="'.get_instance()->config->site_url($v).'"';
200
				}
201
				else
202
				{
2254 lars 203
					$img .= ' src="'.get_instance()->config->slash_item('base_url').$v.'"';
68 lars 204
				}
205
			}
206
			else
207
			{
208
				$img .= ' '.$k.'="'.$v.'"';
209
			}
210
		}
211
 
212
		return $img._stringify_attributes($attributes).' />';
213
	}
214
}
215
 
216
// ------------------------------------------------------------------------
217
 
218
if ( ! function_exists('doctype'))
219
{
220
	/**
221
	 * Doctype
222
	 *
223
	 * Generates a page document type declaration
224
	 *
225
	 * Examples of valid options: html5, xhtml-11, xhtml-strict, xhtml-trans,
226
	 * xhtml-frame, html4-strict, html4-trans, and html4-frame.
227
	 * All values are saved in the doctypes config file.
228
	 *
229
	 * @param	string	type	The doctype to be generated
230
	 * @return	string
231
	 */
232
	function doctype($type = 'xhtml1-strict')
233
	{
234
		static $doctypes;
235
 
236
		if ( ! is_array($doctypes))
237
		{
238
			if (file_exists(APPPATH.'config/doctypes.php'))
239
			{
240
				include(APPPATH.'config/doctypes.php');
241
			}
242
 
243
			if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'))
244
			{
245
				include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php');
246
			}
247
 
248
			if (empty($_doctypes) OR ! is_array($_doctypes))
249
			{
250
				$doctypes = array();
251
				return FALSE;
252
			}
253
 
254
			$doctypes = $_doctypes;
255
		}
256
 
257
		return isset($doctypes[$type]) ? $doctypes[$type] : FALSE;
258
	}
259
}
260
 
261
// ------------------------------------------------------------------------
262
 
263
if ( ! function_exists('link_tag'))
264
{
265
	/**
266
	 * Link
267
	 *
268
	 * Generates link to a CSS file
269
	 *
270
	 * @param	mixed	stylesheet hrefs or an array
271
	 * @param	string	rel
272
	 * @param	string	type
273
	 * @param	string	title
274
	 * @param	string	media
275
	 * @param	bool	should index_page be added to the css path
276
	 * @return	string
277
	 */
278
	function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE)
279
	{
280
		$CI =& get_instance();
281
		$link = '<link ';
282
 
283
		if (is_array($href))
284
		{
285
			foreach ($href as $k => $v)
286
			{
287
				if ($k === 'href' && ! preg_match('#^([a-z]+:)?//#i', $v))
288
				{
289
					if ($index_page === TRUE)
290
					{
291
						$link .= 'href="'.$CI->config->site_url($v).'" ';
292
					}
293
					else
294
					{
2254 lars 295
						$link .= 'href="'.$CI->config->slash_item('base_url').$v.'" ';
68 lars 296
					}
297
				}
298
				else
299
				{
300
					$link .= $k.'="'.$v.'" ';
301
				}
302
			}
303
		}
304
		else
305
		{
306
			if (preg_match('#^([a-z]+:)?//#i', $href))
307
			{
308
				$link .= 'href="'.$href.'" ';
309
			}
310
			elseif ($index_page === TRUE)
311
			{
312
				$link .= 'href="'.$CI->config->site_url($href).'" ';
313
			}
314
			else
315
			{
2254 lars 316
				$link .= 'href="'.$CI->config->slash_item('base_url').$href.'" ';
68 lars 317
			}
318
 
319
			$link .= 'rel="'.$rel.'" type="'.$type.'" ';
320
 
321
			if ($media !== '')
322
			{
323
				$link .= 'media="'.$media.'" ';
324
			}
325
 
326
			if ($title !== '')
327
			{
328
				$link .= 'title="'.$title.'" ';
329
			}
330
		}
331
 
332
		return $link."/>\n";
333
	}
334
}
335
 
336
// ------------------------------------------------------------------------
337
 
338
if ( ! function_exists('meta'))
339
{
340
	/**
341
	 * Generates meta tags from an array of key/values
342
	 *
343
	 * @param	array
344
	 * @param	string
345
	 * @param	string
346
	 * @param	string
347
	 * @return	string
348
	 */
349
	function meta($name = '', $content = '', $type = 'name', $newline = "\n")
350
	{
351
		// Since we allow the data to be passes as a string, a simple array
352
		// or a multidimensional one, we need to do a little prepping.
353
		if ( ! is_array($name))
354
		{
355
			$name = array(array('name' => $name, 'content' => $content, 'type' => $type, 'newline' => $newline));
356
		}
357
		elseif (isset($name['name']))
358
		{
359
			// Turn single array into multidimensional
360
			$name = array($name);
361
		}
362
 
363
		$str = '';
364
		foreach ($name as $meta)
365
		{
366
			$type		= (isset($meta['type']) && $meta['type'] !== 'name')	? 'http-equiv' : 'name';
367
			$name		= isset($meta['name'])					? $meta['name'] : '';
368
			$content	= isset($meta['content'])				? $meta['content'] : '';
369
			$newline	= isset($meta['newline'])				? $meta['newline'] : "\n";
370
 
371
			$str .= '<meta '.$type.'="'.$name.'" content="'.$content.'" />'.$newline;
372
		}
373
 
374
		return $str;
375
	}
376
}
377
 
378
// ------------------------------------------------------------------------
379
 
380
if ( ! function_exists('br'))
381
{
382
	/**
383
	 * Generates HTML BR tags based on number supplied
384
	 *
385
	 * @deprecated	3.0.0	Use str_repeat() instead
386
	 * @param	int	$count	Number of times to repeat the tag
387
	 * @return	string
388
	 */
389
	function br($count = 1)
390
	{
391
		return str_repeat('<br />', $count);
392
	}
393
}
394
 
395
// ------------------------------------------------------------------------
396
 
397
if ( ! function_exists('nbs'))
398
{
399
	/**
400
	 * Generates non-breaking space entities based on number supplied
401
	 *
402
	 * @deprecated	3.0.0	Use str_repeat() instead
403
	 * @param	int
404
	 * @return	string
405
	 */
406
	function nbs($num = 1)
407
	{
408
		return str_repeat('&nbsp;', $num);
409
	}
410
}