class HTML { /** * @var boolean Для XHTML */ public static $strict = TRUE; /** * echo HTML::chars($value); * * @param string $value * @param boolean $double_encode * @param string $charset * @return string */ public static function chars($value, $double_encode = TRUE, $charset = 'utf-8') { return $value !== '' && self::$strict ? htmlspecialchars( (string) $value, ENT_QUOTES, $charset, $double_encode) : $value; } /** * echo HTML::to_unicode($value) * * @param string $value * @param boolean $encode * @return string */ public static function to_unicode($value = '', $encode = TRUE) { $ansi = array( '№', ' ', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я', 'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я' ); $unicod = array( '\u2116', '\u0020', '\u0410', '\u0411', '\u0412', '\u0413', '\u0414', '\u0415', '\u0401', '\u0416', '\u0417', '\u0418', '\u0419', '\u041A', '\u041B', '\u041C', '\u041D', '\u041E', '\u041F', '\u0420', '\u0421', '\u0422', '\u0423', '\u0424', '\u0425', '\u0426', '\u0427', '\u0428', '\u0429', '\u042A', '\u042B', '\u042C', '\u042D', '\u042E', '\u042F', '\u0430', '\u0431', '\u0432', '\u0433', '\u0434', '\u0435', '\u0451', '\u0436', '\u0437', '\u0438', '\u0439', '\u043A', '\u043B', '\u043C', '\u043D', '\u043E', '\u043F', '\u0440', '\u0441', '\u0442', '\u0443', '\u0444', '\u0445', '\u0446', '\u0447', '\u0448', '\u0449', '\u044A', '\u044B', '\u044C', '\u044D', '\u044E', '\u044F' ); return ($encode) ? str_replace($ansi, $unicod, $value) : str_replace($unicod, $ansi, $value); } /** * echo HTML::mailto($email, 'text', 'id'); * * @param string $email * @param string $title * @param string $id * @return string */ public static function mailto($email, $title = NULL, $id = 'output_em_text') { $out = ''; if ($email !== '') { $email = self::chars( (string) $email); $email = str_replace(array('@', '.'), array('&', '*'), $email); $title = self::chars( (string) $title); $title = (($title == '') ? 'x' : '"' .self::to_unicode($title) .'"'); $out = '<a href="mailto::' .$email .'">' .$title .'</a>' .'<script type="text/javascript">' .'/*<![CDATA[*/' .'var e=document.getElementById("' .$id .'");' .'var x="' .$email .'";' .'x=x.replace("&","@");' .'x=x.replace(/\*/g,".");' .'e.href=e.href+x;' .'e.innerHTML=' .$title .';' .'/*]]>*/' .'</script>'; } return $out; } } |