/** * Multibyte wrapper for strftime. * * Handles utf8_encoding the result of strftime when necessary. * * @param string $format Format string. * @param int $date Timestamp to format. * @return string formatted string with correct encoding. */ protected function _strftime($format, $date) { $format = strftime($format, $date); $encoding = Configure::read('App.encoding'); if (!empty($encoding) && $encoding === 'UTF-8') { if (function_exists('mb_check_encoding')) { $valid = mb_check_encoding($format, $encoding); } else { $valid = !Multibyte::checkMultibyte($format); } if (!$valid) { $format = utf8_encode($format); } } return $format; }
/** * Prepare a string for mail transport, using the provided encoding * * @param string $string value to encode * @param string $charset charset to use for encoding. defaults to UTF-8 * @param string $newline * @return string * @access public * @static * @TODO: add support for 'Q'('Quoted Printable') encoding */ function mimeEncode($string, $charset = null, $newline = "\r\n") { if (!Multibyte::checkMultibyte($string) && strlen($string) < 75) { return $string; } if (empty($charset)) { $charset = Configure::read('App.encoding'); } $charset = strtoupper($charset); $start = '=?' . $charset . '?B?'; $end = '?='; $spacer = $end . $newline . ' ' . $start; $length = 75 - strlen($start) - strlen($end); $length = $length - $length % 4; if ($charset == 'UTF-8') { $parts = array(); $maxchars = floor($length * 3 / 4); while (strlen($string) > $maxchars) { $i = $maxchars; $test = ord($string[$i]); while ($test >= 128 && $test <= 191) { $i--; $test = ord($string[$i]); } $parts[] = base64_encode(substr($string, 0, $i)); $string = substr($string, $i); } $parts[] = base64_encode($string); $string = implode($spacer, $parts); } else { $string = chunk_split(base64_encode($string), $length, $spacer); $string = preg_replace('/' . preg_quote($spacer) . '$/', '', $string); } return $start . $string . $end; }