PageRenderTime 56ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/system/helpers/html_helper.php

https://gitlab.com/ricoru21/py_incidencia
PHP | 436 lines | 232 code | 57 blank | 147 comment | 36 complexity | 5d9bdfbd194ccb2523e4d084c436f548 MD5 | raw file
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 5.1.6 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author ExpressionEngine Dev Team
  9. * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
  10. * @license http://codeigniter.com/user_guide/license.html
  11. * @link http://codeigniter.com
  12. * @since Version 1.0
  13. * @filesource
  14. */
  15. // ------------------------------------------------------------------------
  16. /**
  17. * CodeIgniter HTML Helpers
  18. *
  19. * @package CodeIgniter
  20. * @subpackage Helpers
  21. * @category Helpers
  22. * @author ExpressionEngine Dev Team
  23. * @link http://codeigniter.com/user_guide/helpers/html_helper.html
  24. */
  25. // ------------------------------------------------------------------------
  26. /**
  27. * Heading
  28. *
  29. * Generates an HTML heading tag. First param is the data.
  30. * Second param is the size of the heading tag.
  31. *
  32. * @access public
  33. * @param string
  34. * @param integer
  35. * @return string
  36. */
  37. if ( ! function_exists('heading'))
  38. {
  39. function heading($data = '', $h = '1', $attributes = '')
  40. {
  41. $attributes = ($attributes != '') ? ' '.$attributes : $attributes;
  42. return "<h".$h.$attributes.">".$data."</h".$h.">";
  43. }
  44. }
  45. // ------------------------------------------------------------------------
  46. /**
  47. * Unordered List
  48. *
  49. * Generates an HTML unordered list from an single or multi-dimensional array.
  50. *
  51. * @access public
  52. * @param array
  53. * @param mixed
  54. * @return string
  55. */
  56. if ( ! function_exists('ul'))
  57. {
  58. function ul($list, $attributes = '')
  59. {
  60. return _list('ul', $list, $attributes);
  61. }
  62. }
  63. // ------------------------------------------------------------------------
  64. /**
  65. * Ordered List
  66. *
  67. * Generates an HTML ordered list from an single or multi-dimensional array.
  68. *
  69. * @access public
  70. * @param array
  71. * @param mixed
  72. * @return string
  73. */
  74. if ( ! function_exists('ol'))
  75. {
  76. function ol($list, $attributes = '')
  77. {
  78. return _list('ol', $list, $attributes);
  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 integer
  92. * @return string
  93. */
  94. if ( ! function_exists('_list'))
  95. {
  96. function _list($type = 'ul', $list, $attributes = '', $depth = 0)
  97. {
  98. // If an array wasn't submitted there's nothing to do...
  99. if ( ! is_array($list))
  100. {
  101. return $list;
  102. }
  103. // Set the indentation based on the depth
  104. $out = str_repeat(" ", $depth);
  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. elseif (is_string($attributes) AND strlen($attributes) > 0)
  116. {
  117. $attributes = ' '. $attributes;
  118. }
  119. // Write the opening list tag
  120. $out .= "<".$type.$attributes.">\n";
  121. // Cycle through the list elements. If an array is
  122. // encountered we will recursively call _list()
  123. static $_last_list_item = '';
  124. foreach ($list as $key => $val)
  125. {
  126. $_last_list_item = $key;
  127. $out .= str_repeat(" ", $depth + 2);
  128. $out .= "<li>";
  129. if ( ! is_array($val))
  130. {
  131. $out .= $val;
  132. }
  133. else
  134. {
  135. $out .= $_last_list_item."\n";
  136. $out .= _list($type, $val, '', $depth + 4);
  137. $out .= str_repeat(" ", $depth + 2);
  138. }
  139. $out .= "</li>\n";
  140. }
  141. // Set the indentation for the closing tag
  142. $out .= str_repeat(" ", $depth);
  143. // Write the closing list tag
  144. $out .= "</".$type.">\n";
  145. return $out;
  146. }
  147. }
  148. // ------------------------------------------------------------------------
  149. /**
  150. * Generates HTML BR tags based on number supplied
  151. *
  152. * @access public
  153. * @param integer
  154. * @return string
  155. */
  156. if ( ! function_exists('br'))
  157. {
  158. function br($num = 1)
  159. {
  160. return str_repeat("<br />", $num);
  161. }
  162. }
  163. // ------------------------------------------------------------------------
  164. /**
  165. * Image
  166. *
  167. * Generates an <img /> element
  168. *
  169. * @access public
  170. * @param mixed
  171. * @return string
  172. */
  173. if ( ! function_exists('img'))
  174. {
  175. function img($src = '', $index_page = FALSE)
  176. {
  177. if ( ! is_array($src) )
  178. {
  179. $src = array('src' => $src);
  180. }
  181. // If there is no alt attribute defined, set it to an empty string
  182. if ( ! isset($src['alt']))
  183. {
  184. $src['alt'] = '';
  185. }
  186. $img = '<img';
  187. foreach ($src as $k=>$v)
  188. {
  189. if ($k == 'src' AND strpos($v, '://') === FALSE)
  190. {
  191. $CI =& get_instance();
  192. if ($index_page === TRUE)
  193. {
  194. $img .= ' src="'.$CI->config->site_url($v).'"';
  195. }
  196. else
  197. {
  198. $img .= ' src="'.$CI->config->slash_item('base_url').$v.'"';
  199. }
  200. }
  201. else
  202. {
  203. $img .= " $k=\"$v\"";
  204. }
  205. }
  206. $img .= '/>';
  207. return $img;
  208. }
  209. }
  210. // ------------------------------------------------------------------------
  211. /**
  212. * Doctype
  213. *
  214. * Generates a page document type declaration
  215. *
  216. * Valid options are xhtml-11, xhtml-strict, xhtml-trans, xhtml-frame,
  217. * html4-strict, html4-trans, and html4-frame. Values are saved in the
  218. * doctypes config file.
  219. *
  220. * @access public
  221. * @param string type The doctype to be generated
  222. * @return string
  223. */
  224. if ( ! function_exists('doctype'))
  225. {
  226. function doctype($type = 'xhtml1-strict')
  227. {
  228. global $_doctypes;
  229. if ( ! is_array($_doctypes))
  230. {
  231. if (defined('ENVIRONMENT') AND is_file(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php'))
  232. {
  233. include(APPPATH.'config/'.ENVIRONMENT.'/doctypes.php');
  234. }
  235. elseif (is_file(APPPATH.'config/doctypes.php'))
  236. {
  237. include(APPPATH.'config/doctypes.php');
  238. }
  239. if ( ! is_array($_doctypes))
  240. {
  241. return FALSE;
  242. }
  243. }
  244. if (isset($_doctypes[$type]))
  245. {
  246. return $_doctypes[$type];
  247. }
  248. else
  249. {
  250. return FALSE;
  251. }
  252. }
  253. }
  254. // ------------------------------------------------------------------------
  255. /**
  256. * Link
  257. *
  258. * Generates link to a CSS file
  259. *
  260. * @access public
  261. * @param mixed stylesheet hrefs or an array
  262. * @param string rel
  263. * @param string type
  264. * @param string title
  265. * @param string media
  266. * @param boolean should index_page be added to the css path
  267. * @return string
  268. */
  269. if ( ! function_exists('link_tag'))
  270. {
  271. function link_tag($href = '', $rel = 'stylesheet', $type = 'text/css', $title = '', $media = '', $index_page = FALSE)
  272. {
  273. $CI =& get_instance();
  274. $link = '<link ';
  275. if (is_array($href))
  276. {
  277. foreach ($href as $k=>$v)
  278. {
  279. if ($k == 'href' AND strpos($v, '://') === FALSE)
  280. {
  281. if ($index_page === TRUE)
  282. {
  283. $link .= 'href="'.$CI->config->site_url($v).'" ';
  284. }
  285. else
  286. {
  287. $link .= 'href="'.$CI->config->slash_item('base_url').$v.'" ';
  288. }
  289. }
  290. else
  291. {
  292. $link .= "$k=\"$v\" ";
  293. }
  294. }
  295. $link .= "/>";
  296. }
  297. else
  298. {
  299. if ( strpos($href, '://') !== FALSE)
  300. {
  301. $link .= 'href="'.$href.'" ';
  302. }
  303. elseif ($index_page === TRUE)
  304. {
  305. $link .= 'href="'.$CI->config->site_url($href).'" ';
  306. }
  307. else
  308. {
  309. $link .= 'href="'.$CI->config->slash_item('base_url').$href.'" ';
  310. }
  311. $link .= 'rel="'.$rel.'" type="'.$type.'" ';
  312. if ($media != '')
  313. {
  314. $link .= 'media="'.$media.'" ';
  315. }
  316. if ($title != '')
  317. {
  318. $link .= 'title="'.$title.'" ';
  319. }
  320. $link .= '/>';
  321. }
  322. return $link;
  323. }
  324. }
  325. // ------------------------------------------------------------------------
  326. /**
  327. * Generates meta tags from an array of key/values
  328. *
  329. * @access public
  330. * @param array
  331. * @return string
  332. */
  333. if ( ! function_exists('meta'))
  334. {
  335. function meta($name = '', $content = '', $type = 'name', $newline = "\n")
  336. {
  337. // Since we allow the data to be passes as a string, a simple array
  338. // or a multidimensional one, we need to do a little prepping.
  339. if ( ! is_array($name))
  340. {
  341. $name = array(array('name' => $name, 'content' => $content, 'type' => $type, 'newline' => $newline));
  342. }
  343. else
  344. {
  345. // Turn single array into multidimensional
  346. if (isset($name['name']))
  347. {
  348. $name = array($name);
  349. }
  350. }
  351. $str = '';
  352. foreach ($name as $meta)
  353. {
  354. $type = ( ! isset($meta['type']) OR $meta['type'] == 'name') ? 'name' : 'http-equiv';
  355. $name = ( ! isset($meta['name'])) ? '' : $meta['name'];
  356. $content = ( ! isset($meta['content'])) ? '' : $meta['content'];
  357. $newline = ( ! isset($meta['newline'])) ? "\n" : $meta['newline'];
  358. $str .= '<meta '.$type.'="'.$name.'" content="'.$content.'" />'.$newline;
  359. }
  360. return $str;
  361. }
  362. }
  363. // ------------------------------------------------------------------------
  364. /**
  365. * Generates non-breaking space entities based on number supplied
  366. *
  367. * @access public
  368. * @param integer
  369. * @return string
  370. */
  371. if ( ! function_exists('nbs'))
  372. {
  373. function nbs($num = 1)
  374. {
  375. return str_repeat("&nbsp;", $num);
  376. }
  377. }
  378. /* End of file html_helper.php */
  379. /* Location: ./system/helpers/html_helper.php */