PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/wordpress3.4.2/wp-content/plugins/wp-multibyte-patch/ext/ja/class.php

https://bitbucket.org/ch3tag/mothers
PHP | 189 lines | 144 code | 28 blank | 17 comment | 22 complexity | 618b629ea56de14da7621f2790100d35 MD5 | raw file
  1. <?php
  2. /**
  3. * WP Multibyte Patch Japanese Locale Extension
  4. *
  5. * @package WP_Multibyte_Patch
  6. * @version 1.6.3
  7. * @author Seisuke Kuraishi <210pura@gmail.com>
  8. * @copyright Copyright (c) 2012 Seisuke Kuraishi, Tinybit Inc.
  9. * @license http://opensource.org/licenses/gpl-2.0.php GPLv2
  10. * @link http://eastcoder.com/code/wp-multibyte-patch/
  11. */
  12. /**
  13. * This class extends multibyte_patch.
  14. *
  15. * @package WP_Multibyte_Patch
  16. */
  17. if(class_exists('multibyte_patch')) :
  18. class multibyte_patch_ext extends multibyte_patch {
  19. function get_jis_name() {
  20. if(function_exists('mb_list_encodings')) {
  21. $list = "\t" . implode("\t", mb_list_encodings()) . "\t";
  22. return (preg_match("/\tISO-2022-JP-MS\t/i", $list)) ? 'ISO-2022-JP-MS' : 'ISO-2022-JP';
  23. }
  24. else
  25. return 'ISO-2022-JP';
  26. }
  27. function UTF8toJIS($string) {
  28. return $this->convenc($string, $this->get_jis_name(), 'UTF-8');
  29. }
  30. function JIStoUTF8($string) {
  31. return $this->convenc($string, 'UTF-8', $this->get_jis_name());
  32. }
  33. function encode_mimeheader_b_uncut($string = '', $charset = 'UTF-8') {
  34. if(0 == strlen($string) || strlen($string) == mb_strlen($string, $charset))
  35. return $string;
  36. return "=?$charset?B?" . base64_encode($string) . '?=';
  37. }
  38. function get_phpmailer_properties($phpmailer) {
  39. $array = (array) $phpmailer;
  40. $new = array();
  41. foreach($array as $key => $value) {
  42. $key = preg_replace("/^\\0[^\\0]+\\0/", "", $key);
  43. $new[$key] = $value;
  44. }
  45. return $new;
  46. }
  47. function wp_mail($phpmailer) {
  48. $blog_encoding = $this->blog_encoding;
  49. $phpmailer->FromName = preg_replace("/[\r\n]/", "", trim($phpmailer->FromName));
  50. $phpmailer->FromName = $this->convenc($phpmailer->FromName, 'UTF-8', $blog_encoding);
  51. $phpmailer->Subject = preg_replace("/[\r\n]/", "", trim($phpmailer->Subject));
  52. $phpmailer->Subject = $this->convenc($phpmailer->Subject, 'UTF-8', $blog_encoding);
  53. $phpmailer->Body = $this->convenc($phpmailer->Body, 'UTF-8', $blog_encoding);
  54. if('UTF-8' == strtoupper(trim($this->conf['mail_mode'])))
  55. $mode = 'UTF-8';
  56. elseif('JIS' == strtoupper(trim($this->conf['mail_mode'])))
  57. $mode = 'JIS';
  58. else { // Check unmappable characters and decide what to do.
  59. $test_str_before = $phpmailer->FromName . $phpmailer->Subject . $phpmailer->Body;
  60. $test_str_after = $this->UTF8toJIS($test_str_before);
  61. $test_str_after = $this->JIStoUTF8($test_str_after);
  62. $mode = ($test_str_after != $test_str_before) ? 'UTF-8' : 'JIS';
  63. }
  64. $phpmailer_props = $this->get_phpmailer_properties($phpmailer);
  65. $recipient_methods = array('to' => array('add' => 'AddAddress', 'clear' => 'ClearAddresses'), 'cc' => array('add' => 'AddCC', 'clear' => 'ClearCCs'), 'bcc' => array('add' => 'AddBCC', 'clear' => 'ClearBCCs'));
  66. if('UTF-8' == $mode) {
  67. $phpmailer->CharSet = 'UTF-8';
  68. $phpmailer->Encoding = 'base64';
  69. $phpmailer->AddCustomHeader('Content-Disposition: inline');
  70. $phpmailer->FromName = $this->encode_mimeheader_b_uncut($phpmailer->FromName, 'UTF-8');
  71. $phpmailer->Subject = $this->encode_mimeheader_b_uncut($phpmailer->Subject, 'UTF-8');
  72. foreach($recipient_methods as $name => $method) {
  73. if(isset($phpmailer_props[$name][0])) {
  74. $phpmailer->{$method['clear']}();
  75. foreach($phpmailer_props[$name] as $recipient) {
  76. $recipient[1] = $this->encode_mimeheader_b_uncut($recipient[1], 'UTF-8');
  77. $phpmailer->{$method['add']}($recipient[0], $recipient[1]);
  78. }
  79. }
  80. }
  81. }
  82. elseif('JIS' == $mode) {
  83. $phpmailer->CharSet = 'ISO-2022-JP';
  84. $phpmailer->Encoding = '7bit';
  85. $phpmailer->FromName = $this->UTF8toJIS($phpmailer->FromName);
  86. $phpmailer->FromName = $this->encode_mimeheader_b_uncut($phpmailer->FromName, 'ISO-2022-JP');
  87. $phpmailer->Subject = $this->UTF8toJIS($phpmailer->Subject);
  88. $phpmailer->Subject = $this->encode_mimeheader_b_uncut($phpmailer->Subject, 'ISO-2022-JP');
  89. $phpmailer->Body = $this->UTF8toJIS($phpmailer->Body);
  90. foreach($recipient_methods as $name => $method) {
  91. if(isset($phpmailer_props[$name][0])) {
  92. $phpmailer->{$method['clear']}();
  93. foreach($phpmailer_props[$name] as $recipient) {
  94. $recipient[1] = $this->UTF8toJIS($recipient[1]);
  95. $recipient[1] = $this->encode_mimeheader_b_uncut($recipient[1], 'ISO-2022-JP');
  96. $phpmailer->{$method['add']}($recipient[0], $recipient[1]);
  97. }
  98. }
  99. }
  100. }
  101. }
  102. function process_search_terms() {
  103. global $wpdb;
  104. $blog_encoding = $this->blog_encoding;
  105. if(isset($_GET['s'])) {
  106. $_GET['s'] = stripslashes($_GET['s']);
  107. $_GET['s'] = mb_convert_kana($_GET['s'], 's', $blog_encoding);
  108. $_GET['s'] = preg_replace("/ +/", " ", $_GET['s']);
  109. $_GET['s'] = $wpdb->escape($_GET['s']);
  110. }
  111. }
  112. function guess_encoding($string, $encoding = '') {
  113. $guess_list = 'UTF-8, eucJP-win, SJIS-win';
  114. if(preg_match("/^utf-8$/i", $encoding))
  115. return 'UTF-8';
  116. elseif(preg_match("/^euc-jp$/i", $encoding))
  117. return 'eucJP-win';
  118. elseif(preg_match("/^(sjis|shift_jis)$/i", $encoding))
  119. return 'SJIS-win';
  120. elseif(!$encoding)
  121. return mb_detect_encoding($string, $guess_list);
  122. else
  123. return $encoding;
  124. }
  125. function admin_custom_css() {
  126. if(empty($this->conf['admin_custom_css_url']))
  127. $url = plugin_dir_url(__FILE__) . 'admin.css';
  128. else
  129. $url = $this->conf['admin_custom_css_url'];
  130. wp_register_style('wpmp-admin-custom', $url, array(), false);
  131. wp_enqueue_style('wpmp-admin-custom');
  132. }
  133. function wp_trim_words($text = '', $num_words = 110, $more = '', $original_text = '') {
  134. if('characters' != _x('words', 'word count: words or characters?'))
  135. return $text;
  136. $text = $original_text;
  137. $text = wp_strip_all_tags($text);
  138. $text = trim(preg_replace("/[\n\r\t ]+/", ' ', $text), ' ');
  139. if(mb_strlen($text, $this->blog_encoding) > $num_words)
  140. $text = mb_substr($text, 0, $num_words, $this->blog_encoding) . $more;
  141. return $text;
  142. }
  143. function __construct() {
  144. // mbstring functions are always required for ja.
  145. $this->mbfunctions_required = true;
  146. $this->conf['patch_wp_mail'] = true;
  147. $this->conf['patch_incoming_trackback'] = true;
  148. $this->conf['patch_incoming_pingback'] = true;
  149. $this->conf['patch_process_search_terms'] = true;
  150. $this->conf['patch_admin_custom_css'] = true;
  151. $this->conf['patch_force_character_count'] = true;
  152. $this->conf['patch_force_twentytwelve_open_sans_off'] = true;
  153. $this->conf['patch_wp_trim_words'] = true;
  154. // auto, JIS, UTF-8
  155. $this->conf['mail_mode'] = 'JIS';
  156. $this->conf['admin_custom_css_url'] = '';
  157. parent::__construct();
  158. }
  159. }
  160. endif;
  161. ?>