PageRenderTime 68ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/helpers/html.php

https://github.com/MilkZoft/zan
PHP | 351 lines | 315 code | 36 blank | 0 comment | 46 complexity | 6db8739b184c2495829399c92ea98517 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. if (!defined("ACCESS")) {
  3. die("Error: You don't have permission to access here...");
  4. }
  5. if (!function_exists("a")) {
  6. function a($text, $URL = null, $external = false, $attributes = false)
  7. {
  8. $attrs = null;
  9. if (is_array($attributes)) {
  10. foreach ($attributes as $attribute => $value) {
  11. $attrs .= ' '. strtolower($attribute) .'="'. $value .'"';
  12. }
  13. }
  14. if (is_null($URL)) {
  15. return '<a name="'. $text .'"></a>';
  16. } elseif (!$URL) {
  17. return '<a'. $attrs .'>'. $text .'</a>';
  18. } elseif ($external) {
  19. return '<a target="_blank" href="'. $URL .'"'. $attrs .'>'. $text .'</a>';
  20. } else {
  21. return '<a href="'. $URL .'"'. $attrs .'>'. $text .'</a>';
  22. }
  23. }
  24. }
  25. if (!function_exists("body")) {
  26. function body($open = true)
  27. {
  28. return ($open) ? "<body>" : "</body>";
  29. }
  30. }
  31. if (!function_exists("bold")) {
  32. function bold($text, $br = true)
  33. {
  34. $HTML = '<span class="Bold">'. $text .'</span>';
  35. return ($br === true) ? $HTML .'<br />' : $HTML;
  36. }
  37. }
  38. if (!function_exists("br")) {
  39. function br($jumps = 1)
  40. {
  41. $br = null;
  42. for ($i = 0; $i < $jumps; $i++) {
  43. $br .= "<br />";
  44. }
  45. return $br;
  46. }
  47. }
  48. if (!function_exists("char")) {
  49. function char($char, $repeat = 1)
  50. {
  51. $HTML = null;
  52. for ($i = 0; $i <= $repeat; $i++) {
  53. $HTML .= $char;
  54. }
  55. return $HTML;
  56. }
  57. }
  58. if (!function_exists("deleteImg")) {
  59. function deleteImg($HTML)
  60. {
  61. return preg_replace("/<img[^<>]*/>/", "", $HTML);
  62. }
  63. }
  64. if (!function_exists("div")) {
  65. function div($ID, $type = "id", $style = null, $content = null)
  66. {
  67. if (!$ID) {
  68. return '</div>';
  69. } elseif (!$type) {
  70. return '<div class="'. $ID .'">'. $content .'</div>';
  71. } elseif ($type === "id") {
  72. return '<div id="'. $ID .'">';
  73. } elseif ($type === "id/class") {
  74. return '<div id="'. $ID .'" class="'. $style .'">';
  75. } elseif ($type === "class") {
  76. return '<div class="'. $ID .'">';
  77. } elseif ($type) {
  78. return '<div id="'. $ID .'">'. $content .'</div>';
  79. }
  80. }
  81. }
  82. if (!function_exists("docType")) {
  83. function docType($type = "HTML5")
  84. {
  85. return ($type === "HTML5") ? '<!DOCTYPE html>' : '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xHTML1/DTD/xHTML1-strict.dtd">';
  86. }
  87. }
  88. if (!function_exists("getHTMLDecode")) {
  89. function getHTMLDecode($HTML)
  90. {
  91. return html_entity_decode($HTML);
  92. }
  93. }
  94. if (!function_exists("getFavicon")) {
  95. function getFavicon()
  96. {
  97. return '<link rel="shortcut icon" href="'. path("www/lib/images/favicon.ico", true) .'" />';
  98. }
  99. }
  100. if (!function_exists("h1")) {
  101. function h1($text)
  102. {
  103. return "<h1>$text</h1>";
  104. }
  105. }
  106. if (!function_exists("h2")) {
  107. function h2($text)
  108. {
  109. return "<h2>$text</h2>";
  110. }
  111. }
  112. if (!function_exists("h3")) {
  113. function h3($text)
  114. {
  115. return "<h3>$text</h3>";
  116. }
  117. }
  118. if (!function_exists("head")) {
  119. function head($open = true)
  120. {
  121. return ($open) ? "<head>" : "</head>";
  122. }
  123. }
  124. if (!function_exists("HTML")) {
  125. function HTML($open = true)
  126. {
  127. return ($open) ? '<html lang="'. _get("webLang") .'" xml:lang="'. _get("webLang") .'">' : '</html>';
  128. }
  129. }
  130. if (!function_exists("img")) {
  131. function img($src, $attributes = null)
  132. {
  133. $attrs = null;
  134. if (is_array($attributes)) {
  135. foreach ($attributes as $attribute => $value) {
  136. $attrs .= ' '. $attribute .'="'. $value .'"';
  137. }
  138. }
  139. return '<img src="'. $src .'"'. $attrs .' />';
  140. }
  141. }
  142. if (!function_exists("li")) {
  143. function li($list, $open = null)
  144. {
  145. $HTML = null;
  146. if (isMultiArray($list)) {
  147. foreach ($list as $li) {
  148. $class = (isset($li["class"])) ? ' class="'. $li["class"] .'"' : null;
  149. if (isset($li["item"]) and strlen($li["item"]) > 1) {
  150. $HTML .= '<li'. $class .'>'. $li["item"] .'</li>';
  151. }
  152. }
  153. } elseif (is_array($list)) {
  154. for ($i = 0; $i <= count($list) - 1; $i++) {
  155. $HTML .= char("\t", 2) .'<li>'. $list[$i] .'</li>';
  156. }
  157. } elseif ($list and $open) {
  158. $HTML .= "<li>". $list;
  159. } elseif ($open === false) {
  160. $HTML .= "</li>";
  161. } else {
  162. $HTML .= '<li>'. $list .'</li>';
  163. }
  164. return $HTML;
  165. }
  166. }
  167. if (!function_exists("loadCSS")) {
  168. function loadCSS($CSS)
  169. {
  170. return '<link rel="stylesheet" href="'. _get("webURL") ."/". $CSS .'" type="text/css" media="all" />';
  171. }
  172. }
  173. if (!function_exists("loadScript")) {
  174. function loadScript($js, $application = null, $external = false)
  175. {
  176. if (file_exists($js)) {
  177. return '<script type="text/javascript" src="'. _get("webURL") ."/". $js .'"></script>';
  178. } if ($external) {
  179. return '<script type="text/javascript" src="'. $js .'"></script>';
  180. } else {
  181. if (isset($application)) {
  182. if (file_exists($file)) {
  183. return '<script type="text/javascript" src="'. _get("webURL") .'/www/applications/'. $application .'/views/js/'. $js .'.js"></script>';
  184. }
  185. }
  186. }
  187. }
  188. }
  189. if (!function_exists("openUl")) {
  190. function openUl($ID = null, $class = null)
  191. {
  192. $ID = (!is_null($ID)) ? ' id="'. $ID .'"': null;
  193. $class = (!is_null($class)) ? ' class="'. $class .'"' : null;
  194. return '<ul'. $ID . $class .'>' ;
  195. }
  196. }
  197. if (!function_exists("closeUl")) {
  198. function closeUl()
  199. {
  200. return '</ul>';
  201. }
  202. }
  203. if (!function_exists("p")) {
  204. function p($text, $class = null)
  205. {
  206. if (is_string($text)) {
  207. if (is_null($class)) {
  208. return '<p>'. $text .'</p>';
  209. } else {
  210. return '<p class="'. $class .'">'. $text .'</p>' ;
  211. }
  212. } elseif ($text === true) {
  213. if (is_null($class)) {
  214. return '<p>';
  215. } else {
  216. return '<p class="'. $class .'">';
  217. }
  218. } else {
  219. return '</p>';
  220. }
  221. }
  222. }
  223. if (!function_exists("small")) {
  224. function small($text)
  225. {
  226. return '<span class="small">'. $text .'</span>';
  227. }
  228. }
  229. if (!function_exists("span")) {
  230. function span($class, $value, $ID = false)
  231. {
  232. if ($ID) {
  233. return '<span id="'. $ID .'"'. (!is_null($class) ? ' class="'. $class .'"' : null) .'>'. $value .'</span>';
  234. }
  235. return '<span class="'. $class .'">'. $value .'</span>';
  236. }
  237. }
  238. if (!function_exists("ul")) {
  239. function ul($list, $ID = null, $class = null)
  240. {
  241. $ID = (!is_null($ID)) ? ' id="'.$ID.'"' : null;
  242. $class = (!is_null($class)) ? ' class="'. $class .'"' : null;
  243. $HTML = '<ul'. $ID . $class .'>';
  244. if (isMultiArray($list)) {
  245. foreach ($list as $li) {
  246. $class = (isset($li["class"])) ? ' class="'. $li["class"] .'"' : null;
  247. $HTML .= '<li' . $class . '>'. $li["item"] .'</li>' ;
  248. }
  249. } elseif (is_array($list)) {
  250. for ($i = 0; $i <= count($list) - 1; $i++) {
  251. $HTML .= '<li>'. $list[$i] .'</li>';
  252. }
  253. }
  254. return $HTML .'</ul>' ;
  255. }
  256. }
  257. if (!function_exists("htmlTag")) {
  258. function htmlTag($tag = null, $attributes = true, $content = null)
  259. {
  260. if (is_null($tag)) {
  261. return null;
  262. }
  263. if ($attributes === true) {
  264. return "<$tag>";
  265. } elseif ($attributes === false) {
  266. return "</$tag>";
  267. } elseif (is_array($attributes)) {
  268. $HTML = "<$tag";
  269. foreach ($attributes as $attribute => $value) {
  270. $HTML .= " $attribute = \"$value\"";
  271. }
  272. $HTML .= ">";
  273. if (! is_null($content)) {
  274. $HTML .= "$content</$tag>";
  275. } elseif ($content === false) {
  276. $HTML .= "</$tag>";
  277. }
  278. return $HTML;
  279. } else {
  280. return "<$tag>$attributes</$tag>";
  281. }
  282. }
  283. }
  284. if (!function_exists("image")) {
  285. function image($source, $class = null, $ID = false, $attributes = false)
  286. {
  287. $class = !is_null($class) ? ' class="'. $class .'"' : null;
  288. $attrs = '';
  289. if (is_array($attributes)) {
  290. foreach ($attributes as $attribute => $value) {
  291. if ($attribute !== "p") {
  292. $attrs .= " $attribute = \"$value\"";
  293. } else {
  294. $$attribute = $value;
  295. }
  296. }
  297. }
  298. $HTML = ($ID) ? '<img id="'. $ID .'"'. $class .' src="'. $source .'" />' : '<img'. $class .' src="'. $source .'" />';
  299. return (isset($p) and $p === true) ? p($HTML) : $HTML;
  300. }
  301. }