Esempio n. 1
0
 /**
  * Sets the input xml file to be parsed
  *
  * @access  public
  * @param   string  $file  Filename(full path)
  * @return  mixed   True on success or error on failure
  */
 function setInputFile($file)
 {
     require_once PEAR_PATH . 'HTTP/Request.php';
     $httpRequest = new HTTP_Request($file, $this->_params);
     $httpRequest->setMethod(HTTP_REQUEST_METHOD_GET);
     $resRequest = $httpRequest->sendRequest();
     if (PEAR::isError($resRequest)) {
         return $resRequest;
     } elseif ($httpRequest->getResponseCode() != 200) {
         return $this->raiseError('HTTP response error', HTTP_REQUEST_ERROR_RESPONSE);
     }
     $data = trim($httpRequest->getResponseBody());
     if (version_compare(PHP_VERSION, '5.0.0', '<')) {
         if (preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/m', $data, $matches)) {
             $srcenc = strtoupper($matches[1]);
             if (!in_array($srcenc, $this->_validEncodings)) {
                 if (function_exists('iconv')) {
                     $data = @iconv($srcenc, 'UTF-8', $data);
                 } elseif (function_exists('mb_list_encodings') && in_array($srcenc, array_map('strtoupper', mb_list_encodings()))) {
                     $data = @mb_convert_encoding($data, 'UTF-8', $srcenc);
                 }
             }
         }
     }
     $this->setInputString($data);
     return true;
 }
 function __construct()
 {
     $this->name = strtolower(get_class($this));
     $this->text_domain = $this->name;
     $this->skip_next_call = false;
     $this->charset = get_bloginfo('charset');
     $this->load_options();
     // Carefully support multibyte languages
     if (extension_loaded('mbstring') && function_exists('mb_list_encodings')) {
         $this->mb = in_array($this->charset, mb_list_encodings());
     }
     //load_plugin_textdomain($this->text_domain, PLUGINDIR . '/advanced-excerpt/');
     // __FILE__ doesn't seem to work
     /*
     $file = ABSPATH . PLUGINDIR . '/advanced-excerpt/advanced-excerpt.php';
     register_activation_hook($file, array(
       &$this,
       'install'
     ));
     */
     if (!get_option($this->name . '_length')) {
         $this->install();
         // WPCOM only add options if options don't exists
     }
     //register_deactivation_hook($file, array(&$this, 'uninstall'));
     add_action('admin_menu', array(&$this, 'add_pages'));
     // Replace the default filter (see /wp-includes/default-filters.php)
     remove_filter('get_the_excerpt', 'wp_trim_excerpt');
     add_filter('get_the_excerpt', array(&$this, 'filter'));
 }
Esempio n. 3
0
/**
 * Create a web friendly URL slug from a string.
 * 
 * Although supported, transliteration is discouraged because
 *     1) most web browsers support UTF-8 characters in URLs
 *     2) transliteration causes a loss of information
 *
 * @author Sean Murphy <*****@*****.**>
 * @copyright Copyright 2012 Sean Murphy. All rights reserved.
 * @license http://creativecommons.org/publicdomain/zero/1.0/
 *
 * @param string $str
 * @param array $options
 * @return string
 */
function url_slug($str, $options = array())
{
    // Make sure string is in UTF-8 and strip invalid UTF-8 characters
    $str = html_entity_decode($str, ENT_COMPAT, 'UTF-8');
    $str = mb_convert_encoding((string) $str, 'UTF-8', mb_list_encodings());
    $str = preg_replace("/&#\\d+;/i", '', $str);
    //удаление не преобразованных элементов
    $defaults = array('delimiter' => '-', 'limit' => null, 'lowercase' => true, 'replacements' => array(), 'transliterate' => false);
    // Merge options
    $options = array_merge($defaults, $options);
    $char_map = array('À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'AE', 'Ç' => 'C', 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ð' => 'D', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ő' => 'O', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ű' => 'U', 'Ý' => 'Y', 'Þ' => 'TH', 'ß' => 'ss', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'ae', 'ç' => 'c', 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'd', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ő' => 'o', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 'ű' => 'u', 'ý' => 'y', 'þ' => 'th', 'ÿ' => 'y', '©' => '(c)', 'Α' => 'A', 'Β' => 'B', 'Γ' => 'G', 'Δ' => 'D', 'Ε' => 'E', 'Ζ' => 'Z', 'Η' => 'H', 'Θ' => '8', 'Ι' => 'I', 'Κ' => 'K', 'Λ' => 'L', 'Μ' => 'M', 'Ν' => 'N', 'Ξ' => '3', 'Ο' => 'O', 'Π' => 'P', 'Ρ' => 'R', 'Σ' => 'S', 'Τ' => 'T', 'Υ' => 'Y', 'Φ' => 'F', 'Χ' => 'X', 'Ψ' => 'PS', 'Ω' => 'W', 'Ά' => 'A', 'Έ' => 'E', 'Ί' => 'I', 'Ό' => 'O', 'Ύ' => 'Y', 'Ή' => 'H', 'Ώ' => 'W', 'Ϊ' => 'I', 'Ϋ' => 'Y', 'α' => 'a', 'β' => 'b', 'γ' => 'g', 'δ' => 'd', 'ε' => 'e', 'ζ' => 'z', 'η' => 'h', 'θ' => '8', 'ι' => 'i', 'κ' => 'k', 'λ' => 'l', 'μ' => 'm', 'ν' => 'n', 'ξ' => '3', 'ο' => 'o', 'π' => 'p', 'ρ' => 'r', 'σ' => 's', 'τ' => 't', 'υ' => 'y', 'φ' => 'f', 'χ' => 'x', 'ψ' => 'ps', 'ω' => 'w', 'ά' => 'a', 'έ' => 'e', 'ί' => 'i', 'ό' => 'o', 'ύ' => 'y', 'ή' => 'h', 'ώ' => 'w', 'ς' => 's', 'ϊ' => 'i', 'ΰ' => 'y', 'ϋ' => 'y', 'ΐ' => 'i', 'Ş' => 'S', 'İ' => 'I', 'Ç' => 'C', 'Ü' => 'U', 'Ö' => 'O', 'Ğ' => 'G', 'ş' => 's', 'ı' => 'i', 'ç' => 'c', 'ü' => 'u', 'ö' => 'o', 'ğ' => 'g', 'А' => 'A', 'Б' => 'B', 'В' => 'V', 'Г' => 'G', 'Д' => 'D', 'Е' => 'E', 'Ё' => 'Yo', 'Ж' => 'Zh', 'З' => 'Z', 'И' => 'I', 'Й' => 'J', 'К' => 'K', 'Л' => 'L', 'М' => 'M', 'Н' => 'N', 'О' => 'O', 'П' => 'P', 'Р' => 'R', 'С' => 'S', 'Т' => 'T', 'У' => 'U', 'Ф' => 'F', 'Х' => 'H', 'Ц' => 'C', 'Ч' => 'Ch', 'Ш' => 'Sh', 'Щ' => 'Sh', 'Ъ' => '', 'Ы' => 'Y', 'Ь' => '', 'Э' => 'E', 'Ю' => 'Yu', 'Я' => 'Ya', 'а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', 'ё' => 'yo', 'ж' => 'zh', 'з' => 'z', 'и' => 'i', 'й' => 'j', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'u', 'ф' => 'f', 'х' => 'h', 'ц' => 'c', 'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sh', 'ъ' => '', 'ы' => 'y', 'ь' => '', 'э' => 'e', 'ю' => 'yu', 'я' => 'ya', 'Є' => 'Ye', 'І' => 'I', 'Ї' => 'Yi', 'Ґ' => 'G', 'є' => 'ye', 'і' => 'i', 'ї' => 'yi', 'ґ' => 'g', 'Č' => 'C', 'Ď' => 'D', 'Ě' => 'E', 'Ň' => 'N', 'Ř' => 'R', 'Š' => 'S', 'Ť' => 'T', 'Ů' => 'U', 'Ž' => 'Z', 'č' => 'c', 'ď' => 'd', 'ě' => 'e', 'ň' => 'n', 'ř' => 'r', 'š' => 's', 'ť' => 't', 'ů' => 'u', 'ž' => 'z', 'Ą' => 'A', 'Ć' => 'C', 'Ę' => 'e', 'Ł' => 'L', 'Ń' => 'N', 'Ó' => 'o', 'Ś' => 'S', 'Ź' => 'Z', 'Ż' => 'Z', 'ą' => 'a', 'ć' => 'c', 'ę' => 'e', 'ł' => 'l', 'ń' => 'n', 'ó' => 'o', 'ś' => 's', 'ź' => 'z', 'ż' => 'z', 'Ā' => 'A', 'Č' => 'C', 'Ē' => 'E', 'Ģ' => 'G', 'Ī' => 'i', 'Ķ' => 'k', 'Ļ' => 'L', 'Ņ' => 'N', 'Š' => 'S', 'Ū' => 'u', 'Ž' => 'Z', 'ā' => 'a', 'č' => 'c', 'ē' => 'e', 'ģ' => 'g', 'ī' => 'i', 'ķ' => 'k', 'ļ' => 'l', 'ņ' => 'n', 'š' => 's', 'ū' => 'u', 'ž' => 'z');
    // Make custom replacements
    $str = preg_replace(array_keys($options['replacements']), $options['replacements'], $str);
    // Transliterate characters to ASCII
    if ($options['transliterate']) {
        $str = str_replace(array_keys($char_map), $char_map, $str);
    }
    // Replace non-alphanumeric characters with our delimiter
    $str = preg_replace('/[^\\p{L}\\p{Nd}]+/u', $options['delimiter'], $str);
    // Remove duplicate delimiters
    $str = preg_replace('/(' . preg_quote($options['delimiter'], '/') . '){2,}/', '$1', $str);
    // Truncate slug to max. characters
    $str = mb_substr($str, 0, $options['limit'] ? $options['limit'] : mb_strlen($str, 'UTF-8'), 'UTF-8');
    // Remove delimiter from ends
    $str = trim($str, $options['delimiter']);
    return $options['lowercase'] ? mb_strtolower($str, 'UTF-8') : $str;
}
Esempio n. 4
0
 /**
  * Setup callback
  *
  * @param AppModel $model
  * @param array $config
  */
 function setup(&$model, $config = array())
 {
     if (true === empty($config)) {
         $config = array();
     }
     // Merge user settings with default
     $settings = am($this->defaultSettings, $config);
     foreach ($settings as $mode) {
         if (true === $mode['useMbstring'] && false !== $mode['convertTo']) {
             if (false === function_exists('mb_convert_encoding')) {
                 trigger_error('Sorry, your PHP version does not support mbstring functions. Please read notes at http://php.net/mbstring', E_USER_ERROR);
             }
             // Check if we have a list of all valid encodings supported by PHP
             if (true === empty($this->validEncodings)) {
                 // Build the list of valid encodings
                 $this->validEncodings = mb_list_encodings();
             }
             // Check if we have valid encodings in our list
             if (false === array_search($mode['convertTo'], $this->validEncodings)) {
                 trigger_error('Invalid target encoding for "' . $model->name . '::find" - ' . $mode['convertTo'] . ' is not valid!', E_USER_ERROR);
             }
         }
     }
     $this->settings[$model->name] = $settings;
 }
Esempio n. 5
0
 public function __toString()
 {
     $string = $this->text_to_transform;
     // Make sure string is in UTF-8 and strip invalid UTF-8 characters
     $string = mb_convert_encoding((string) $string, 'UTF-8', mb_list_encodings());
     // Make custom replacements
     $string = preg_replace(array_keys($this->replacements), $this->replacements, $string);
     // Transliterate characters to ASCII
     if ($this->transliterate) {
         $string = str_replace(array_keys($this->charMap), $this->charMap, $string);
     }
     // Replace non-alphanumeric characters with our delimiter
     $string = preg_replace('/[^\\p{L}\\p{Nd}]+/u', $this->delimiter, $string);
     // Remove duplicate delimiters
     $string = preg_replace('/(' . preg_quote($this->delimiter, '/') . '){2,}/', '$1', $string);
     // Truncate slug to max. characters
     if ($this->limit) {
         $string = mb_substr($string, 0, $this->limit, 'UTF-8');
     }
     // Remove delimiter from ends
     $string = trim($string, $this->delimiter);
     // lowercase
     if ($this->lowercase) {
         $string = mb_strtolower($string, 'UTF-8');
     }
     return $string;
 }
Esempio n. 6
0
 public static function slugify($string, $delimiter = '-', $transliterate = False, $hexaAccentClean = False, $lowercase = True, $limit = NULL, $replacements = array())
 {
     // Make sure string is in UTF-8 and strip invalid UTF-8 characters
     $string = mb_convert_encoding((string) $string, 'UTF-8', mb_list_encodings());
     // Make custom replacements
     $string = preg_replace(array_keys($replacements), $replacements, $string);
     // Transliterate characters to ASCII
     if ($transliterate) {
         $string = str_replace(array_keys(self::$charMap), self::$charMap, $string);
     }
     // Replace non-alphanumeric characters with our delimiter
     $string = preg_replace('/[^\\p{L}\\p{Nd}]+/u', $delimiter, $string);
     if ($hexaAccentClean) {
         $string = self::hexaAccentCleaning($string);
     }
     // Remove duplicate delimiters
     $string = preg_replace('/(' . preg_quote($delimiter, '/') . '){2,}/', '$1', $string);
     // Truncate slug to max. characters
     if ($limit) {
         $string = mb_substr($string, 0, $limit, 'UTF-8');
     }
     // Remove delimiter from ends
     $string = trim($string, $delimiter);
     return $lowercase ? mb_strtolower($string, 'UTF-8') : $string;
 }
Esempio n. 7
0
 /**
  * Make url from a string
  *
  * @param string $str
  * @param array $options
  * @return string
  */
 function url($str = '', $options = array())
 {
     /**
      * Make sure string is in UTF-8 and strip invalid UTF-8 characters
      */
     if (!function_exists('mb_list_encodings')) {
         $list_encodings = $this->mb_list_encodings_m();
     } else {
         $list_encodings = mb_list_encodings();
     }
     $str = mb_convert_encoding((string) $str, 'UTF-8', $list_encodings);
     $defaults = array('delimiter' => '-', 'limit' => null, 'lowercase' => true, 'replacements' => array(), 'transliterate' => true);
     // Merge options
     $options = array_merge($defaults, $options);
     // Make custom replacements
     $str = preg_replace(array_keys($options['replacements']), $options['replacements'], $str);
     //replace char nokia to utf-8
     $str = $this->NokiaFixer($str);
     // Transliterate characters to ASCII
     if ($options['transliterate']) {
         $str = $this->translate2en($str);
     }
     // Replace non-alphanumeric characters with our delimiter
     $str = preg_replace('/[^\\p{L}\\p{Nd}]+/u', $options['delimiter'], $str);
     // Remove duplicate delimiters
     $str = preg_replace('/(' . preg_quote($options['delimiter'], '/') . '){2,}/', '$1', $str);
     // Truncate slug to max. characters
     $str = mb_substr($str, 0, $options['limit'] ? $options['limit'] : mb_strlen($str, 'UTF-8'), 'UTF-8');
     // Remove delimiter from ends
     $str = trim($str, $options['delimiter']);
     return $options['lowercase'] ? mb_strtolower($str, 'UTF-8') : $str;
 }
 /**
  * Return converted Response'body
  *
  * @param string       $body
  * @param string|array $metadata 'content-type'
  * $param $remains
  *
  * @return mixed
  */
 public final function convert($body, $metadata = array(), $remains = null)
 {
     if (is_string($metadata)) {
         $ctype = $metadata;
     } elseif (is_array($metadata)) {
         $ctype = isset($metadata['content-type']) ? $metadata['content-type'] : null;
     } else {
         $ctype = null;
     }
     $body = $this->_initBody($body);
     $encoding_from = $this->_encodingFrom($body, $ctype);
     // if not avilable for mbstring, using iconv
     if (!in_array($encoding_from, mb_list_encodings())) {
         $body = @iconv($encoding_from, 'UTF-8', $body);
         if (isset($remains)) {
             foreach ($remains as $k => $v) {
                 $remains[$k] = @iconv($encoding_from, 'UTF-8', $v);
             }
             return array($body, $remains);
         }
         return $body;
     }
     if (isset($remains)) {
         @mb_convert_variables('UTF-8', $encoding_from, $body, $remains);
         return array($body, $remains);
     } else {
         $body = mb_convert_encoding($body, 'UTF-8', $encoding_from);
         return $body;
     }
 }
Esempio n. 9
0
 function utf8()
 {
     $this->charsets = array("ASMO-708" => "Arabic", "BIG5" => "Chinese Traditional", "CP1026" => "IBM EBCDIC (Turkish Latin-5)", "cp866" => "Cyrillic (DOS)", "CP870" => "IBM EBCDIC (Multilingual Latin-2)", "CISO2022JP" => "Japanese (JIS-Allow 1 byte Kana)", "DOS-720" => "Arabic (DOS)", "DOS-862" => "Hebrew (DOS)", "EBCDIC-CP-US" => "IBM EBCDIC (US-Canada)", "EUC-CN" => "Chinese Simplified (EUC)", "EUC-JP" => "Japanese (EUC)", "EUC-KR" => "Korean (EUC)", "GB2312" => "Chinese Simplified (GB2312)", "HZ-GB-2312" => "Chinese Simplified (HZ)", "IBM437" => "OEM United States", "IBM737" => "Greek (DOS)", "IBM775" => "Baltic (DOS)", "IBM850" => "Western European (DOS)", "IBM852" => "Central European (DOS)", "IBM857" => "Turkish (DOS)", "IBM861" => "Icelandic (DOS)", "IBM869" => "Greek, Modern (DOS)", "ISO-2022-JP" => "Japanese (JIS)", "ISO-2022-JP" => "Japanese (JIS-Allow 1 byte Kana - SO/SI)", "ISO-2022-KR" => "Korean (ISO)", "ISO-8859-1" => "Western European (ISO)", "ISO-8859-15" => "Latin 9 (ISO)", "ISO-8859-2" => "Central European (ISO)", "ISO-8859-3" => "Latin 3 (ISO)", "ISO-8859-4" => "Baltic (ISO)", "ISO-8859-5" => "Cyrillic (ISO)", "ISO-8859-6" => "Arabic (ISO)", "ISO-8859-7" => "Greek (ISO)", "ISO-8859-8" => "Hebrew (ISO-Visual)", "ISO-8859-8-i" => "Hebrew (ISO-Logical)", "ISO-8859-9" => "Turkish (ISO)", "JOHAB" => "Korean (Johab)", "KOi8-R" => "Cyrillic (KOI8-R)", "KOi8-U" => "Cyrillic (KOI8-U)", "KS_C_5601-1987" => "Korean", "MACINTOSH" => "Western European (MAC)", "SHIFT_JIS" => "Japanese (Shift-JIS)", "UNICODE" => "Unicode", "UNICODEFFFE" => "Unicode (Big-Endian)", "US-ASCII" => "US-ASCII", "UTF-7" => "Unicode (UTF-7)", "UTF-8" => "Unicode (UTF-8)", "WINDOWS-1250" => "Central European (Windows)", "WINDOWS-1251" => "Cyrillic (Windows)", "WINDOWS-1252" => "Western European (Windows)", "WINDOWS-1253" => "Greek (Windows)", "WINDOWS-1254" => "Turkish (Windows)", "WINDOWS-1255" => "Hebrew (Windows)", "WINDOWS-1256" => "Arabic (Windows)", "WINDOWS-1257" => "Baltic (Windows)", "WINDOWS-1258" => "Vietnamese (Windows)", "WINDOWS-874" => "Thai (Windows)");
     // prune the list to supported character sets
     $this->iconv_sets = array();
     $this->mb_sets = array();
     if (function_exists('mb_convert_encoding')) {
         if (function_exists('mb_list_encodings')) {
             $list = mb_list_encodings();
         } else {
             $list = array("pass", "auto", "byte2be", "byte2le", "byte4be", "byte4le", "BASE64", "UUENCODE", "HTML-ENTITIES", "Quoted-Printable", "7bit", "8bit", "UCS-4", "UCS-4BE", "UCS-4LE", "UCS-2", "UCS-2BE", "UCS-2LE", "UTF-32", "UTF-32BE", "UTF-32LE", "UTF-16", "UTF-16BE", "UTF-16LE", "UTF-8", "UTF-7", "UTF7-IMAP", "ASCII", "EUC-JP", "SJIS", "eucJP-win", "SJIS-win", "CP51932", "JIS", "ISO-2022-JP", "ISO-2022-JP-MS", "Windows-1252", "ISO-8859-1", "ISO-8859-2", "ISO-8859-3", "ISO-8859-4", "ISO-8859-5", "ISO-8859-6", "ISO-8859-7", "ISO-8859-8", "ISO-8859-9", "ISO-8859-10", "ISO-8859-13", "ISO-8859-14", "ISO-8859-15", "ISO-8859-16", "EUC-CN", "CP936", "HZ", "EUC-TW", "BIG-5", "EUC-KR", "UHC", "ISO-2022-KR", "Windows-1251", "CP866", "KOI8-R", "ArmSCII-8");
         }
         foreach ($this->charsets as $key => $encoding) {
             if (in_array($key, $list)) {
                 $this->mb_sets[$key] = $encoding;
             }
         }
     }
     if (function_exists('iconv')) {
         foreach ($this->charsets as $key => $encoding) {
             if (@iconv("UTF-8", $key, "UTF-8") !== false) {
                 $this->iconv_sets[$key] = $encoding;
             }
         }
     }
     $this->validsets = array_merge($this->mb_sets, $this->iconv_sets);
 }
Esempio n. 10
0
 /**
  * Sets the chunker's character encoding
  *
  * @param  string|null  $encoding  the chunker's character encoding
  * @throws  InvalidArgumentException  if $encoding is not an supported charset;
  *     the special string 'auto'; or, null
  * @since  0.1.0
  */
 public function setEncoding($encoding)
 {
     if (!is_string($encoding) || !in_array($encoding, mb_list_encodings())) {
         throw new \InvalidArgumentException(__METHOD__ . "() expects parameter one, encoding, to be a valid " . "character encoding name");
     }
     $this->encoding = $encoding;
     return $this;
 }
Esempio n. 11
0
 /**
  * get all built-in encodings as array
  * @return array $ary
  */
 public static function getEncodingsAry()
 {
     static $ary = null;
     if (!$ary) {
         $ary = mb_list_encodings();
     }
     return $ary;
 }
Esempio n. 12
0
 /**
  * Constructor
  * 
  */
 public function __construct($init_array = NULL)
 {
     // build the valid encodings once for mime decoding
     // could cache this even further up the chain
     $this->valid_mb_encoding_array = array_flip(array_change_key_case(array_flip(mb_list_encodings())));
     // call the parent constructor
     parent::__construct($init_array);
 }
Esempio n. 13
0
 function get_jis_name()
 {
     if (function_exists('mb_list_encodings')) {
         $list = "\t" . implode("\t", mb_list_encodings()) . "\t";
         return preg_match("/\tISO-2022-JP-MS\t/i", $list) ? 'ISO-2022-JP-MS' : 'ISO-2022-JP';
     } else {
         return 'ISO-2022-JP';
     }
 }
Esempio n. 14
0
 /**
  * Initializes the class with the given parameters.
  *
  * The constructor accepts the following options:
  *
  * - `encoding` (string, default=string "UTF-8") Encoding to use
  *
  * @param array $params RequestBlock configuration options
  * @param Content $contentBlock ContentBlock of request
  * @throws InvalidArgumentException
  */
 public function __construct(array $params, Content $contentBlock)
 {
     $defaults = ['encoding' => 'UTF-8'];
     $config = array_merge($defaults, $params);
     if (!in_array($config['encoding'], mb_list_encodings())) {
         throw new InvalidArgumentException('Requested encoding is not supported');
     }
     $this->controlBlock = new ControlBlock($config);
     $this->operationBlock = new OperationBlock($config, $contentBlock);
 }
 static private function getEncoding($string, $encoding) {
     if (!ArrayHelper::in_arrayi($encoding, \mb_list_encodings())) {
         if (strpos(strtolower($encoding), strtolower('Windows-125')) !== false) {
             $encoding = 'Windows-1252';
         } else {
             $encoding = \mb_detect_encoding($string);
         }
     }
     return $encoding;
 }
 /**
  * @param string $value
  * @param string $charset
  *
  * @return bool
  */
 public static function isCharset($value, $charset)
 {
     $available = \mb_list_encodings();
     $charset = \is_array($charset) ? $charset : array($charset);
     $charsetList = \array_filter($charset, function ($charsetName) use($available) {
         return \in_array($charsetName, $available, true);
     });
     $detectedEncoding = \mb_detect_encoding($value, $charset, true);
     return \in_array($detectedEncoding, $charsetList, true);
 }
Esempio n. 17
0
 /**
  * @return void
  */
 protected static function buildEncodings()
 {
     $encodings = mb_list_encodings();
     foreach ($encodings as $encoding) {
         self::addEncoding($encoding);
         foreach (mb_encoding_aliases($encoding) as $encoding) {
             self::addEncoding($encoding);
         }
     }
 }
Esempio n. 18
0
 /**
  * Indique si l'encodage passé en paramètre est valide ou pas.
  * 
  * @param string $sEncodingToTest Nom de l'encodage à tester.
  * @return boolean Retourne TRUE si l'encodade passé en paramètre est valide, sinon FALSE.
  */
 protected static function isValidEncoding($sEncodingToTest)
 {
     $aValidEncodings = mb_list_encodings();
     foreach ($aValidEncodings as $sValidEncoding) {
         if (strtolower($sEncodingToTest) == strtolower($sValidEncoding)) {
             return $sValidEncoding;
         }
     }
     return false;
 }
Esempio n. 19
0
 /**
  * Slugify a string
  * 
  * @param string $string the string to slugify
  * 
  * @return string
  */
 public function slugify($string)
 {
     // Convert string to UTF-8
     $string = mb_convert_encoding((string) $string, 'UTF-8', mb_list_encodings());
     $string = strtr($string, $this->rules);
     $string = preg_replace($this->pattern, $this->separator, $string);
     $string = mb_strtolower($string);
     $string = trim($string, $this->separator);
     return $string;
 }
 public function __construct($defaultEncoding = 'UTF-8')
 {
     if (!function_exists('mb_convert_encoding')) {
         throw new ExtensionMissingException('mb');
     }
     if (null === self::$encodings) {
         self::$encodings = array_change_key_case(array_flip(mb_list_encodings()), CASE_LOWER);
     }
     $this->assertSupported($defaultEncoding);
     $this->defaultEncoding = $defaultEncoding;
 }
Esempio n. 21
0
 function __construct($str, $encoding = "auto")
 {
     if (!is_string($str)) {
         throw new \InvalidArgumentException("\$str is not string");
     }
     if (!in_array($encoding, mb_list_encodings())) {
         throw new \InvalidArgumentException("{$encoding} is not a known encoding");
     }
     $this->str = $str;
     $this->encoding = $encoding;
 }
Esempio n. 22
0
 public function __construct($sEncoding)
 {
     if (!is_string($sEncoding)) {
         throw ExceptionType::invalidArgument("Argument #1 doit être une chaîne de caractères.", Exception::FROM_HANDLER);
     }
     $bValidEncoding = Encoding::isValidEncoding($sEncoding);
     if (!$bValidEncoding) {
         throw ExceptionType::domain("L'encodage passé en paramètre ({$sEncoding}) n'est pas valide. Il doit correspondre à l'un des encodages suivants : " . implode(', ', mb_list_encodings()), Exception::FROM_HANDLER);
     }
     $this->_sFinalEncoding = $bValidEncoding;
 }
Esempio n. 23
0
 /**
  * Get a list of supported character encodings
  *
  * @return string[]
  */
 public static function getSupportedEncodings()
 {
     if (static::$encodings === null) {
         static::$encodings = array_map('strtoupper', mb_list_encodings());
         // FIXME: Converting € (UTF-8) to ISO-8859-16 gives a wrong result
         $indexIso885916 = array_search('ISO-8859-16', static::$encodings, true);
         if ($indexIso885916 !== false) {
             unset(static::$encodings[$indexIso885916]);
         }
     }
     return static::$encodings;
 }
 function __construct($pageSize = array(0, 0, 612, 792), $isUnicode = false, $fontcache = '', $tmp = '')
 {
     $this->isUnicode = $isUnicode;
     $this->fontcache = $fontcache;
     $this->tmp = $tmp;
     $this->newDocument($pageSize);
     $this->compressionReady = function_exists('gzcompress');
     if (in_array('Windows-1252', mb_list_encodings())) {
         self::$targetEncoding = 'Windows-1252';
     }
     $this->setFontFamily('init');
 }
Esempio n. 25
0
 public function toCode($input, $parent = null)
 {
     $available = mb_list_encodings();
     $this->args = array_map('strtoupper', $this->args);
     $this->args = (array) array_filter($this->args, function ($c) use($available) {
         return in_array($c, $available, true);
     });
     if (empty($this->args)) {
         throw new \InvalidArgumentException("@Charset expects valid encodings");
     }
     return parent::toCode($input, $parent);
 }
 /**
  * Set up object properties.
  */
 public function __construct()
 {
     $stylesheet_url = preg_replace('/(^http[s]?:)/', '', esc_url(home_url('main-sitemap.xsl')));
     $this->stylesheet = '<?xml-stylesheet type="text/xsl" href="' . $stylesheet_url . '"?>';
     $this->charset = get_bloginfo('charset');
     $this->output_charset = $this->charset;
     $this->timezone = new WPSEO_Sitemap_Timezone();
     if ('UTF-8' !== $this->charset && function_exists('mb_list_encodings') && in_array($this->charset, mb_list_encodings(), true)) {
         $this->output_charset = 'UTF-8';
     }
     $this->needs_conversion = $this->output_charset !== $this->charset;
 }
Esempio n. 27
0
 public function __construct($charset)
 {
     $available = mb_list_encodings();
     $charset = is_array($charset) ? $charset : array($charset);
     $charset = array_filter($charset, function ($c) use($available) {
         return in_array($c, $available, true);
     });
     if (!$charset) {
         throw new ComponentException('Invalid charset');
     }
     $this->charset = $charset;
 }
Esempio n. 28
0
 protected function perform($target, $target_name, $opt_list)
 {
     // basedir
     if (isset($opt_list['basedir'])) {
         $basedir = realpath(end($opt_list['basedir']));
     } else {
         $basedir = getcwd();
     }
     // skelfile
     if (isset($opt_list['skelfile'])) {
         $skelfile = end($opt_list['skelfile']);
     } else {
         $skelfile = null;
     }
     // locale
     $ctl = Ethna_Controller::getInstance();
     if (isset($opt_list['locale'])) {
         $locale = end($opt_list['locale']);
         if (!preg_match('/^[A-Za-z_]+$/', $locale)) {
             return Ethna::raiseError("You specified locale, but invalid : {$locale}", 'usage');
         }
     } else {
         if ($ctl instanceof Ethna_Controller) {
             $locale = $ctl->getLocale();
         } else {
             $locale = 'ja_JP';
         }
     }
     // encoding
     if (isset($opt_list['encoding'])) {
         $encoding = end($opt_list['encoding']);
         if (function_exists('mb_list_encodings')) {
             $supported_enc = mb_list_encodings();
             if (!in_array($encoding, $supported_enc)) {
                 return Ethna::raiseError("Unknown Encoding : {$encoding}", 'usage');
             }
         }
     } else {
         if ($ctl instanceof Ethna_Controller) {
             $encoding = $ctl->getClientEncoding();
         } else {
             $encoding = 'UTF-8';
         }
     }
     $r = Ethna_Generator::generate($target, $basedir, $target_name, $skelfile, $locale, $encoding);
     if (Ethna::isError($r)) {
         printf("error occurred while generating skelton. please see also following error message(s)\n\n");
         return $r;
     }
     $true = true;
     return $true;
 }
Esempio n. 29
0
 /**
  * Chinese 的悉构函数
  *
  * 详细说明
  * @形参      字符串 $source_lang 为需要转换的字符串的原编码
  *            字符串 $target_lang 为转换的目标编码
  *            字符串 $SourceText 为等待转换的字符串
  * @访问      公开
  * @返回值    无
  * @throws
  */
 function Chinese($dir = './')
 {
     $this->config['codetable_dir'] = $dir . "includes/codetable/";
     if (function_exists('iconv')) {
         $this->iconv_enabled = true;
     }
     if (PHP_VERSION >= '5.0' && function_exists('mb_convert_encoding') && function_exists('mb_list_encodings')) {
         $encodings = mb_list_encodings();
         if (in_array('UTF-8', $encodings) == true && in_array('BIG-5', $encodings) == true && in_array('CP936', $encodings) == true) {
             $this->mbstring_enabled = true;
         }
     }
 }
Esempio n. 30
0
 /**
  * Sets the charset for the style sheet.
  *
  * @param string $charset
  * @return $this
  */
 public function setCharset($charset)
 {
     if (is_string($charset)) {
         if (in_array($charset, mb_list_encodings())) {
             $this->charset = $charset;
         } else {
             throw new \InvalidArgumentException("Invalid value '" . $charset . "' for argument 'charset' given. Charset not supported.");
         }
     } else {
         throw new \InvalidArgumentException("Invalid type '" . gettype($charset) . "' for argument 'charset' given.");
     }
     return $this;
 }