PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/core/extensions/helpers/tag.php

https://github.com/argordmel/Daily-Content-Manager
PHP | 105 lines | 39 code | 8 blank | 58 comment | 3 complexity | 2d67fa5181f3dcd7327ec8f9e85f0728 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. * KumbiaPHP web & app Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://wiki.kumbiaphp.com/Licencia
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@kumbiaphp.com so we can send you a copy immediately.
  14. *
  15. * Helper Tag
  16. *
  17. * Helper base para creacion de Tags
  18. *
  19. * @category KumbiaPHP
  20. * @package Helpers
  21. * @copyright Copyright (c) 2005-2010 KumbiaPHP Team (http://www.kumbiaphp.com)
  22. * @license http://wiki.kumbiaphp.com/Licencia New BSD License
  23. */
  24. class Tag
  25. {
  26. /**
  27. * Hojas de estilo
  28. *
  29. * @var array
  30. **/
  31. protected static $_css = array();
  32. /**
  33. * Convierte los argumentos de un metodo de parametros por nombre a un string con los atributos
  34. *
  35. * @param array $params argumentos a convertir
  36. * @return string
  37. */
  38. public static function getAttrs($params)
  39. {
  40. $data = '';
  41. foreach($params as $k => $v) {
  42. $data .= " $k=\"$v\"";
  43. }
  44. return $data;
  45. }
  46. /**
  47. * Crea un tag
  48. *
  49. * @param string $tag nombre de tag
  50. * @param string $content contenido interno
  51. * @param string $attrs atributos para el tag
  52. * @return string
  53. **/
  54. public static function create($tag, $content = NULL, $attrs = NULL)
  55. {
  56. if(is_array($attrs)) {
  57. $attrs = self::getAttrs($attrs);
  58. }
  59. if(is_null($content)) {
  60. echo "<$tag $attrs />";
  61. }
  62. echo "<$tag $attrs>$content</$tag>";
  63. }
  64. /**
  65. * Incluye un archivo javascript
  66. *
  67. * @param string $src archivo javascript
  68. * @param boolean $cache indica si se usa cache de navegador
  69. */
  70. public static function js($src, $cache = TRUE)
  71. {
  72. $src = "javascript/$src.js";
  73. if(!$cache) {
  74. $src .= '?nocache=' . uniqid();
  75. }
  76. return '<script type="text/javascript" src="' . PUBLIC_PATH . $src . '"></script>';
  77. }
  78. /**
  79. * Incluye un archivo de css
  80. *
  81. * @param string $src archivo css
  82. * @param string $media medio de la hoja de estilo
  83. */
  84. public static function css($src, $media = 'screen')
  85. {
  86. self::$_css[] = array('src' => $src, 'media' => $media);
  87. }
  88. /**
  89. * Obtiene el array de hojas de estilo
  90. *
  91. * @return array
  92. */
  93. public static function getCss()
  94. {
  95. return self::$_css;
  96. }
  97. }