a tiny mvc framework for php using php-activerecord
at master 43 lines 819 B view raw
1<?php 2/* 3 global helpers available everywhere, not an extension of Helper 4*/ 5 6/* alias htmlspecialchars() to something smaller */ 7function h($text) { 8 return htmlspecialchars($text); 9} 10 11function array_last(&$array) { 12 if (empty($array)) 13 return NULL; 14 else 15 return $array[count($array) - 1]; 16} 17 18/* html helpers escape html with h() everywhere, but for instances where raw 19 * html needs to be printed, send it with raw("text") and it will not get 20 * escaped */ 21class Raw { 22 public $raw; 23 public function __construct($text) { 24 $this->raw = $text; 25 } 26 public function __toString() { 27 return $this->raw; 28 } 29} 30 31/* return a Raw object */ 32function raw($text) { 33 return new Raw($text); 34} 35 36function raw_or_h($text) { 37 if (is_object($text) && get_class($text) == "Raw") 38 return (string)$text; 39 else 40 return h($text); 41} 42 43?>