WP Multibyte Patch - Version 1.7

Version Description

Download this release

Release Info

Developer tenpura
Plugin Icon wp plugin WP Multibyte Patch
Version 1.7
Comparing to
See all releases

Code changes from version 1.6.4 to 1.7

ext/ja/class.php CHANGED
@@ -3,9 +3,9 @@
3
  * WP Multibyte Patch Japanese Locale Extension
4
  *
5
  * @package WP_Multibyte_Patch
6
- * @version 1.6.4
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
  */
@@ -15,99 +15,99 @@
15
  *
16
  * @package WP_Multibyte_Patch
17
  */
18
- if(class_exists('multibyte_patch')) :
19
- class multibyte_patch_ext extends multibyte_patch {
20
 
21
  function get_jis_name() {
22
- if(function_exists('mb_list_encodings')) {
23
- $list = "\t" . implode("\t", mb_list_encodings()) . "\t";
24
- return (preg_match("/\tISO-2022-JP-MS\t/i", $list)) ? 'ISO-2022-JP-MS' : 'ISO-2022-JP';
25
  }
26
  else
27
  return 'ISO-2022-JP';
28
  }
29
 
30
- function UTF8toJIS($string) {
31
- return $this->convenc($string, $this->get_jis_name(), 'UTF-8');
32
  }
33
 
34
- function JIStoUTF8($string) {
35
- return $this->convenc($string, 'UTF-8', $this->get_jis_name());
36
  }
37
 
38
- function encode_mimeheader_b_uncut($string = '', $charset = 'UTF-8') {
39
- if(0 == strlen($string) || strlen($string) == mb_strlen($string, $charset))
40
  return $string;
41
 
42
- return "=?$charset?B?" . base64_encode($string) . '?=';
43
  }
44
 
45
- function get_phpmailer_properties($phpmailer) {
46
  $array = (array) $phpmailer;
47
  $new = array();
48
- foreach($array as $key => $value) {
49
- $key = preg_replace("/^\\0[^\\0]+\\0/", "", $key);
50
  $new[$key] = $value;
51
  }
52
  return $new;
53
  }
54
 
55
- function wp_mail($phpmailer) {
56
  $blog_encoding = $this->blog_encoding;
57
 
58
- $phpmailer->FromName = preg_replace("/[\r\n]/", "", trim($phpmailer->FromName));
59
- $phpmailer->FromName = $this->convenc($phpmailer->FromName, 'UTF-8', $blog_encoding);
60
- $phpmailer->Subject = preg_replace("/[\r\n]/", "", trim($phpmailer->Subject));
61
- $phpmailer->Subject = $this->convenc($phpmailer->Subject, 'UTF-8', $blog_encoding);
62
- $phpmailer->Body = $this->convenc($phpmailer->Body, 'UTF-8', $blog_encoding);
63
 
64
- if('UTF-8' == strtoupper(trim($this->conf['mail_mode'])))
65
  $mode = 'UTF-8';
66
- elseif('JIS' == strtoupper(trim($this->conf['mail_mode'])))
67
  $mode = 'JIS';
68
  else { // Check unmappable characters and decide what to do.
69
  $test_str_before = $phpmailer->FromName . $phpmailer->Subject . $phpmailer->Body;
70
- $test_str_after = $this->UTF8toJIS($test_str_before);
71
- $test_str_after = $this->JIStoUTF8($test_str_after);
72
- $mode = ($test_str_after != $test_str_before) ? 'UTF-8' : 'JIS';
73
  }
74
 
75
- $phpmailer_props = $this->get_phpmailer_properties($phpmailer);
76
- $recipient_methods = array('to' => array('add' => 'AddAddress', 'clear' => 'ClearAddresses'), 'cc' => array('add' => 'AddCC', 'clear' => 'ClearCCs'), 'bcc' => array('add' => 'AddBCC', 'clear' => 'ClearBCCs'));
77
 
78
- if('UTF-8' == $mode) {
79
  $phpmailer->CharSet = 'UTF-8';
80
  $phpmailer->Encoding = 'base64';
81
- $phpmailer->AddCustomHeader('Content-Disposition: inline');
82
- $phpmailer->FromName = $this->encode_mimeheader_b_uncut($phpmailer->FromName, 'UTF-8');
83
- $phpmailer->Subject = $this->encode_mimeheader_b_uncut($phpmailer->Subject, 'UTF-8');
84
 
85
- foreach($recipient_methods as $name => $method) {
86
- if(isset($phpmailer_props[$name][0])) {
87
  $phpmailer->{$method['clear']}();
88
- foreach($phpmailer_props[$name] as $recipient) {
89
- $recipient[1] = $this->encode_mimeheader_b_uncut($recipient[1], 'UTF-8');
90
- $phpmailer->{$method['add']}($recipient[0], $recipient[1]);
91
  }
92
  }
93
  }
94
  }
95
- elseif('JIS' == $mode) {
96
  $phpmailer->CharSet = 'ISO-2022-JP';
97
  $phpmailer->Encoding = '7bit';
98
- $phpmailer->FromName = $this->UTF8toJIS($phpmailer->FromName);
99
- $phpmailer->FromName = $this->encode_mimeheader_b_uncut($phpmailer->FromName, 'ISO-2022-JP');
100
- $phpmailer->Subject = $this->UTF8toJIS($phpmailer->Subject);
101
- $phpmailer->Subject = $this->encode_mimeheader_b_uncut($phpmailer->Subject, 'ISO-2022-JP');
102
- $phpmailer->Body = $this->UTF8toJIS($phpmailer->Body);
103
-
104
- foreach($recipient_methods as $name => $method) {
105
- if(isset($phpmailer_props[$name][0])) {
106
  $phpmailer->{$method['clear']}();
107
- foreach($phpmailer_props[$name] as $recipient) {
108
- $recipient[1] = $this->UTF8toJIS($recipient[1]);
109
- $recipient[1] = $this->encode_mimeheader_b_uncut($recipient[1], 'ISO-2022-JP');
110
- $phpmailer->{$method['add']}($recipient[0], $recipient[1]);
111
  }
112
  }
113
  }
@@ -115,52 +115,51 @@ class multibyte_patch_ext extends multibyte_patch {
115
  }
116
 
117
  function process_search_terms() {
118
- global $wpdb;
119
  $blog_encoding = $this->blog_encoding;
120
 
121
- if(isset($_GET['s'])) {
122
- $_GET['s'] = stripslashes($_GET['s']);
123
- $_GET['s'] = mb_convert_kana($_GET['s'], 's', $blog_encoding);
124
- $_GET['s'] = preg_replace("/ +/", " ", $_GET['s']);
125
- $_GET['s'] = $wpdb->escape($_GET['s']);
126
  }
127
  }
128
 
129
- function guess_encoding($string, $encoding = '') {
130
  $guess_list = 'UTF-8, eucJP-win, SJIS-win';
131
 
132
- if(preg_match("/^utf-8$/i", $encoding))
133
  return 'UTF-8';
134
- elseif(preg_match("/^euc-jp$/i", $encoding))
135
  return 'eucJP-win';
136
- elseif(preg_match("/^(sjis|shift_jis)$/i", $encoding))
137
  return 'SJIS-win';
138
- elseif(!$encoding)
139
- return mb_detect_encoding($string, $guess_list);
140
  else
141
  return $encoding;
142
  }
143
 
144
  function admin_custom_css() {
145
- if(empty($this->conf['admin_custom_css_url']))
146
- $url = plugin_dir_url(__FILE__) . 'admin.css';
147
  else
148
  $url = $this->conf['admin_custom_css_url'];
149
 
150
- wp_register_style('wpmp-admin-custom', $url, array(), false);
151
- wp_enqueue_style('wpmp-admin-custom');
152
  }
153
 
154
- function wp_trim_words($text = '', $num_words = 110, $more = '', $original_text = '') {
155
- if('characters' != _x('words', 'word count: words or characters?'))
156
  return $text;
157
 
158
  $text = $original_text;
159
- $text = wp_strip_all_tags($text);
160
- $text = trim(preg_replace("/[\n\r\t ]+/", ' ', $text), ' ');
161
 
162
- if(mb_strlen($text, $this->blog_encoding) > $num_words)
163
- $text = mb_substr($text, 0, $num_words, $this->blog_encoding) . $more;
164
 
165
  return $text;
166
  }
@@ -185,5 +184,3 @@ class multibyte_patch_ext extends multibyte_patch {
185
  }
186
  }
187
  endif;
188
-
189
- ?>
3
  * WP Multibyte Patch Japanese Locale Extension
4
  *
5
  * @package WP_Multibyte_Patch
6
+ * @version 1.7
7
  * @author Seisuke Kuraishi <210pura@gmail.com>
8
+ * @copyright Copyright (c) 2013 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
  */
15
  *
16
  * @package WP_Multibyte_Patch
17
  */
18
+ if ( class_exists( 'multibyte_patch' ) ) :
19
+ class multibyte_patch_ext extends multibyte_patch {
20
 
21
  function get_jis_name() {
22
+ if ( function_exists( 'mb_list_encodings' ) ) {
23
+ $list = "\t" . implode( "\t", mb_list_encodings() ) . "\t";
24
+ return ( preg_match( "/\tISO-2022-JP-MS\t/i", $list ) ) ? 'ISO-2022-JP-MS' : 'ISO-2022-JP';
25
  }
26
  else
27
  return 'ISO-2022-JP';
28
  }
29
 
30
+ function UTF8toJIS( $string ) {
31
+ return $this->convenc( $string, $this->get_jis_name(), 'UTF-8' );
32
  }
33
 
34
+ function JIStoUTF8( $string ) {
35
+ return $this->convenc( $string, 'UTF-8', $this->get_jis_name() );
36
  }
37
 
38
+ function encode_mimeheader_b_uncut( $string = '', $charset = 'UTF-8' ) {
39
+ if ( 0 == strlen( $string ) || strlen( $string ) == mb_strlen( $string, $charset ) )
40
  return $string;
41
 
42
+ return "=?$charset?B?" . base64_encode( $string ) . '?=';
43
  }
44
 
45
+ function get_phpmailer_properties( $phpmailer ) {
46
  $array = (array) $phpmailer;
47
  $new = array();
48
+ foreach ( $array as $key => $value ) {
49
+ $key = preg_replace( "/^\\0[^\\0]+\\0/", "", $key );
50
  $new[$key] = $value;
51
  }
52
  return $new;
53
  }
54
 
55
+ function wp_mail( $phpmailer ) {
56
  $blog_encoding = $this->blog_encoding;
57
 
58
+ $phpmailer->FromName = preg_replace( "/[\r\n]/", "", trim( $phpmailer->FromName ) );
59
+ $phpmailer->FromName = $this->convenc( $phpmailer->FromName, 'UTF-8', $blog_encoding );
60
+ $phpmailer->Subject = preg_replace( "/[\r\n]/", "", trim( $phpmailer->Subject ) );
61
+ $phpmailer->Subject = $this->convenc( $phpmailer->Subject, 'UTF-8', $blog_encoding );
62
+ $phpmailer->Body = $this->convenc( $phpmailer->Body, 'UTF-8', $blog_encoding );
63
 
64
+ if ( 'UTF-8' == strtoupper( trim( $this->conf['mail_mode'] ) ) )
65
  $mode = 'UTF-8';
66
+ elseif ( 'JIS' == strtoupper( trim( $this->conf['mail_mode'] ) ) )
67
  $mode = 'JIS';
68
  else { // Check unmappable characters and decide what to do.
69
  $test_str_before = $phpmailer->FromName . $phpmailer->Subject . $phpmailer->Body;
70
+ $test_str_after = $this->UTF8toJIS( $test_str_before );
71
+ $test_str_after = $this->JIStoUTF8( $test_str_after );
72
+ $mode = ( $test_str_after != $test_str_before ) ? 'UTF-8' : 'JIS';
73
  }
74
 
75
+ $phpmailer_props = $this->get_phpmailer_properties( $phpmailer );
76
+ $recipient_methods = array( 'to' => array( 'add' => 'AddAddress', 'clear' => 'ClearAddresses' ), 'cc' => array( 'add' => 'AddCC', 'clear' => 'ClearCCs' ), 'bcc' => array( 'add' => 'AddBCC', 'clear' => 'ClearBCCs' ) );
77
 
78
+ if ( 'UTF-8' == $mode ) {
79
  $phpmailer->CharSet = 'UTF-8';
80
  $phpmailer->Encoding = 'base64';
81
+ $phpmailer->AddCustomHeader( 'Content-Disposition: inline' );
82
+ $phpmailer->FromName = $this->encode_mimeheader_b_uncut( $phpmailer->FromName, 'UTF-8' );
83
+ $phpmailer->Subject = $this->encode_mimeheader_b_uncut( $phpmailer->Subject, 'UTF-8' );
84
 
85
+ foreach ( $recipient_methods as $name => $method ) {
86
+ if ( isset( $phpmailer_props[$name][0] ) ) {
87
  $phpmailer->{$method['clear']}();
88
+ foreach ( $phpmailer_props[$name] as $recipient ) {
89
+ $recipient[1] = $this->encode_mimeheader_b_uncut( $recipient[1], 'UTF-8' );
90
+ $phpmailer->{$method['add']}( $recipient[0], $recipient[1] );
91
  }
92
  }
93
  }
94
  }
95
+ elseif ( 'JIS' == $mode ) {
96
  $phpmailer->CharSet = 'ISO-2022-JP';
97
  $phpmailer->Encoding = '7bit';
98
+ $phpmailer->FromName = $this->UTF8toJIS( $phpmailer->FromName );
99
+ $phpmailer->FromName = $this->encode_mimeheader_b_uncut( $phpmailer->FromName, 'ISO-2022-JP' );
100
+ $phpmailer->Subject = $this->UTF8toJIS( $phpmailer->Subject );
101
+ $phpmailer->Subject = $this->encode_mimeheader_b_uncut( $phpmailer->Subject, 'ISO-2022-JP' );
102
+ $phpmailer->Body = $this->UTF8toJIS( $phpmailer->Body );
103
+
104
+ foreach ( $recipient_methods as $name => $method ) {
105
+ if ( isset( $phpmailer_props[$name][0] ) ) {
106
  $phpmailer->{$method['clear']}();
107
+ foreach ( $phpmailer_props[$name] as $recipient ) {
108
+ $recipient[1] = $this->UTF8toJIS( $recipient[1] );
109
+ $recipient[1] = $this->encode_mimeheader_b_uncut( $recipient[1], 'ISO-2022-JP' );
110
+ $phpmailer->{$method['add']}( $recipient[0], $recipient[1] );
111
  }
112
  }
113
  }
115
  }
116
 
117
  function process_search_terms() {
 
118
  $blog_encoding = $this->blog_encoding;
119
 
120
+ if ( isset( $_GET['s'] ) ) {
121
+ $_GET['s'] = stripslashes( $_GET['s'] );
122
+ $_GET['s'] = mb_convert_kana( $_GET['s'], 's', $blog_encoding );
123
+ $_GET['s'] = preg_replace( "/ +/", " ", $_GET['s'] );
124
+ $_GET['s'] = wp_slash( $_GET['s'] );
125
  }
126
  }
127
 
128
+ function guess_encoding( $string, $encoding = '' ) {
129
  $guess_list = 'UTF-8, eucJP-win, SJIS-win';
130
 
131
+ if ( preg_match( "/^utf-8$/i", $encoding ) )
132
  return 'UTF-8';
133
+ elseif ( preg_match( "/^euc-jp$/i", $encoding ) )
134
  return 'eucJP-win';
135
+ elseif ( preg_match( "/^(sjis|shift_jis)$/i", $encoding ) )
136
  return 'SJIS-win';
137
+ elseif ( !$encoding )
138
+ return mb_detect_encoding( $string, $guess_list );
139
  else
140
  return $encoding;
141
  }
142
 
143
  function admin_custom_css() {
144
+ if ( empty( $this->conf['admin_custom_css_url'] ) )
145
+ $url = plugin_dir_url( __FILE__ ) . 'admin.css';
146
  else
147
  $url = $this->conf['admin_custom_css_url'];
148
 
149
+ wp_register_style( 'wpmp-admin-custom', $url, array(), false );
150
+ wp_enqueue_style( 'wpmp-admin-custom' );
151
  }
152
 
153
+ function wp_trim_words( $text = '', $num_words = 110, $more = '', $original_text = '' ) {
154
+ if ( 'characters' != _x( 'words', 'word count: words or characters?' ) )
155
  return $text;
156
 
157
  $text = $original_text;
158
+ $text = wp_strip_all_tags( $text );
159
+ $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
160
 
161
+ if ( mb_strlen( $text, $this->blog_encoding ) > $num_words )
162
+ $text = mb_substr( $text, 0, $num_words, $this->blog_encoding ) . $more;
163
 
164
  return $text;
165
  }
184
  }
185
  }
186
  endif;
 
 
js/wplink.js CHANGED
@@ -71,8 +71,7 @@ var wpLink;
71
  width: 480,
72
  height: 'auto',
73
  modal: true,
74
- dialogClass: 'wp-dialog',
75
- zIndex: 300000
76
  });
77
  }
78
 
@@ -114,8 +113,7 @@ var wpLink;
114
  inputs.url.val( ed.dom.getAttrib(e, 'href') );
115
  inputs.title.val( ed.dom.getAttrib(e, 'title') );
116
  // Set open in new tab.
117
- if ( "_blank" == ed.dom.getAttrib(e, 'target') )
118
- inputs.openInNewTab.prop('checked', true);
119
  // Update save prompt.
120
  inputs.submit.val( wpLinkL10n.update );
121
 
71
  width: 480,
72
  height: 'auto',
73
  modal: true,
74
+ dialogClass: 'wp-dialog'
 
75
  });
76
  }
77
 
113
  inputs.url.val( ed.dom.getAttrib(e, 'href') );
114
  inputs.title.val( ed.dom.getAttrib(e, 'title') );
115
  // Set open in new tab.
116
+ inputs.openInNewTab.prop('checked', ( "_blank" == ed.dom.getAttrib( e, 'target' ) ) );
 
117
  // Update save prompt.
118
  inputs.submit.val( wpLinkL10n.update );
119
 
js/wplink.min.js CHANGED
@@ -1 +1 @@
1
- var wpLink;(function(f){var b={},e={},d,a,c;wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",init:function(){b.dialog=f("#wp-link");b.submit=f("#wp-link-submit");b.url=f("#url-field");b.nonce=f("#_ajax_linking_nonce");b.title=f("#link-title-field");b.openInNewTab=f("#link-target-checkbox");b.search=f("#search-field");e.search=new a(f("#search-results"));e.recent=new a(f("#most-recent-results"));e.elements=f(".query-results",b.dialog);b.dialog.keydown(wpLink.keydown);b.dialog.keyup(wpLink.keyup);b.submit.click(function(g){g.preventDefault();wpLink.update()});f("#wp-link-cancel").click(function(g){g.preventDefault();wpLink.close()});f("#internal-toggle").click(wpLink.toggleInternalLinking);e.elements.bind("river-select",wpLink.updateFields);b.search.keyup(wpLink.searchInternalLinks);b.dialog.bind("wpdialogrefresh",wpLink.refresh);b.dialog.bind("wpdialogbeforeopen",wpLink.beforeOpen);b.dialog.bind("wpdialogclose",wpLink.onClose)},beforeOpen:function(){wpLink.range=null;if(!wpLink.isMCE()&&document.selection){wpLink.textarea.focus();wpLink.range=document.selection.createRange()}},open:function(){if(!wpActiveEditor){return}this.textarea=f("#"+wpActiveEditor).get(0);if(!b.dialog.data("wpdialog")){b.dialog.wpdialog({title:wpLinkL10n.title,width:480,height:"auto",modal:true,dialogClass:"wp-dialog",zIndex:300000})}b.dialog.wpdialog("open")},isMCE:function(){return tinyMCEPopup&&(d=tinyMCEPopup.editor)&&!d.isHidden()},refresh:function(){e.search.refresh();e.recent.refresh();if(wpLink.isMCE()){wpLink.mceRefresh()}else{wpLink.setDefaultValues()}b.url.focus()[0].select();if(!e.recent.ul.children().length){e.recent.ajax()}},mceRefresh:function(){var g;d=tinyMCEPopup.editor;tinyMCEPopup.restoreSelection();if(g=d.dom.getParent(d.selection.getNode(),"A")){b.url.val(d.dom.getAttrib(g,"href"));b.title.val(d.dom.getAttrib(g,"title"));if("_blank"==d.dom.getAttrib(g,"target")){b.openInNewTab.prop("checked",true)}b.submit.val(wpLinkL10n.update)}else{wpLink.setDefaultValues()}tinyMCEPopup.storeSelection()},close:function(){if(wpLink.isMCE()){tinyMCEPopup.close()}else{b.dialog.wpdialog("close")}},onClose:function(){if(!wpLink.isMCE()){wpLink.textarea.focus();if(wpLink.range){wpLink.range.moveToBookmark(wpLink.range.getBookmark());wpLink.range.select()}}},getAttrs:function(){return{href:b.url.val(),title:b.title.val(),target:b.openInNewTab.prop("checked")?"_blank":""}},update:function(){if(wpLink.isMCE()){wpLink.mceUpdate()}else{wpLink.htmlUpdate()}},htmlUpdate:function(){var i,j,k,h,l,g=wpLink.textarea;if(!g){return}i=wpLink.getAttrs();if(!i.href||i.href=="http://"){return}j='<a href="'+i.href+'"';if(i.title){j+=' title="'+i.title+'"'}if(i.target){j+=' target="'+i.target+'"'}j+=">";if(document.selection&&wpLink.range){g.focus();wpLink.range.text=j+wpLink.range.text+"</a>";wpLink.range.moveToBookmark(wpLink.range.getBookmark());wpLink.range.select();wpLink.range=null}else{if(typeof g.selectionStart!=="undefined"){k=g.selectionStart;h=g.selectionEnd;selection=g.value.substring(k,h);j=j+selection+"</a>";l=k+j.length;if(k==h){l-="</a>".length}g.value=g.value.substring(0,k)+j+g.value.substring(h,g.value.length);g.selectionStart=g.selectionEnd=l}}wpLink.close();g.focus()},mceUpdate:function(){var h=tinyMCEPopup.editor,i=wpLink.getAttrs(),j,g;tinyMCEPopup.restoreSelection();j=h.dom.getParent(h.selection.getNode(),"A");if(!i.href||i.href=="http://"){if(j){tinyMCEPopup.execCommand("mceBeginUndoLevel");g=h.selection.getBookmark();h.dom.remove(j,1);h.selection.moveToBookmark(g);tinyMCEPopup.execCommand("mceEndUndoLevel");wpLink.close()}return}tinyMCEPopup.execCommand("mceBeginUndoLevel");if(j==null){h.getDoc().execCommand("unlink",false,null);tinyMCEPopup.execCommand("mceInsertLink",false,"#mce_temp_url#",{skip_undo:1});tinymce.each(h.dom.select("a"),function(k){if(h.dom.getAttrib(k,"href")=="#mce_temp_url#"){j=k;h.dom.setAttribs(j,i)}});if(f(j).text()=="#mce_temp_url#"){h.dom.remove(j);j=null}}else{h.dom.setAttribs(j,i)}if(j&&(j.childNodes.length!=1||j.firstChild.nodeName!="IMG")){h.focus();h.selection.select(j);h.selection.collapse(0);tinyMCEPopup.storeSelection()}tinyMCEPopup.execCommand("mceEndUndoLevel");wpLink.close()},updateFields:function(i,h,g){b.url.val(h.children(".item-permalink").val());b.title.val(h.hasClass("no-title")?"":h.children(".item-title").text());if(g&&g.type=="click"){b.url.focus()}},setDefaultValues:function(){b.url.val("http://");b.title.val("");b.submit.val(wpLinkL10n.save)},searchInternalLinks:function(){var h=f(this),i,g=h.val();if(g.length>1){e.recent.hide();e.search.show();if(wpLink.lastSearch==g){return}wpLink.lastSearch=g;i=h.parent().find(".spinner").show();e.search.change(g);e.search.ajax(function(){i.hide()})}else{e.search.hide();e.recent.show()}},next:function(){e.search.next();e.recent.next()},prev:function(){e.search.prev();e.recent.prev()},keydown:function(i){var h,g=f.ui.keyCode;switch(i.which){case g.UP:h="prev";case g.DOWN:h=h||"next";clearInterval(wpLink.keyInterval);wpLink[h]();wpLink.keyInterval=setInterval(wpLink[h],wpLink.keySensitivity);break;default:return}i.preventDefault()},keyup:function(h){var g=f.ui.keyCode;switch(h.which){case g.ESCAPE:h.stopImmediatePropagation();if(!f(document).triggerHandler("wp_CloseOnEscape",[{event:h,what:"wplink",cb:wpLink.close}])){wpLink.close()}return false;break;case g.UP:case g.DOWN:clearInterval(wpLink.keyInterval);break;default:return}h.preventDefault()},delayedCallback:function(i,g){var l,k,j,h;if(!g){return i}setTimeout(function(){if(k){return i.apply(h,j)}l=true},g);return function(){if(l){return i.apply(this,arguments)}j=arguments;h=this;k=true}},toggleInternalLinking:function(h){var g=f("#search-panel"),i=b.dialog.wpdialog("widget"),k=!g.is(":visible"),j=f(window);f(this).toggleClass("toggle-arrow-active",k);b.dialog.height("auto");g.slideToggle(300,function(){setUserSetting("wplink",k?"1":"0");b[k?"search":"url"].focus();var l=j.scrollTop(),o=i.offset().top,m=o+i.outerHeight(),n=m-j.height();if(n>l){i.animate({top:n<o?o-n:l},200)}});h.preventDefault()}};a=function(i,h){var g=this;this.element=i;this.ul=i.children("ul");this.waiting=i.find(".river-waiting");this.change(h);this.refresh();i.scroll(function(){g.maybeLoad()});i.delegate("li","click",function(j){g.select(f(this),j)})};f.extend(a.prototype,{refresh:function(){this.deselect();this.visible=this.element.is(":visible")},show:function(){if(!this.visible){this.deselect();this.element.show();this.visible=true}},hide:function(){this.element.hide();this.visible=false},select:function(h,k){var j,i,l,g;if(h.hasClass("unselectable")||h==this.selected){return}this.deselect();this.selected=h.addClass("selected");j=h.outerHeight();i=this.element.height();l=h.position().top;g=this.element.scrollTop();if(l<0){this.element.scrollTop(g+l)}else{if(l+j>i){this.element.scrollTop(g+l-i+j)}}this.element.trigger("river-select",[h,k,this])},deselect:function(){if(this.selected){this.selected.removeClass("selected")}this.selected=false},prev:function(){if(!this.visible){return}var g;if(this.selected){g=this.selected.prev("li");if(g.length){this.select(g)}}},next:function(){if(!this.visible){return}var g=this.selected?this.selected.next("li"):f("li:not(.unselectable):first",this.element);if(g.length){this.select(g)}},ajax:function(j){var h=this,i=this.query.page==1?0:wpLink.minRiverAJAXDuration,g=wpLink.delayedCallback(function(k,l){h.process(k,l);if(j){j(k,l)}},i);this.query.ajax(g)},change:function(g){if(this.query&&this._search==g){return}this._search=g;this.query=new c(g);this.element.scrollTop(0)},process:function(h,l){var i="",j=true,g="",k=l.page==1;if(!h){if(k){i+='<li class="unselectable"><span class="item-title"><em>'+wpLinkL10n.noMatchesFound+"</em></span></li>"}}else{f.each(h,function(){g=j?"alternate":"";g+=this["title"]?"":" no-title";i+=g?'<li class="'+g+'">':"<li>";i+='<input type="hidden" class="item-permalink" value="'+this["permalink"]+'" />';i+='<span class="item-title">';i+=this["title"]?this["title"]:wpLinkL10n.noTitle;i+='</span><span class="item-info">'+this["info"]+"</span></li>";j=!j})}this.ul[k?"html":"append"](i)},maybeLoad:function(){var h=this,i=this.element,g=i.scrollTop()+i.height();if(!this.query.ready()||g<this.ul.height()-wpLink.riverBottomThreshold){return}setTimeout(function(){var j=i.scrollTop(),k=j+i.height();if(!h.query.ready()||k<h.ul.height()-wpLink.riverBottomThreshold){return}h.waiting.show();i.scrollTop(j+h.waiting.outerHeight());h.ajax(function(){h.waiting.hide()})},wpLink.timeToTriggerRiver)}});c=function(g){this.page=1;this.allLoaded=false;this.querying=false;this.search=g};f.extend(c.prototype,{ready:function(){return !(this.querying||this.allLoaded)},ajax:function(i){var g=this,h={action:"wp-link-ajax",page:this.page,_ajax_linking_nonce:b.nonce.val()};if(this.search){h.search=this.search}this.querying=true;f.post(ajaxurl,h,function(j){g.page++;g.querying=false;g.allLoaded=!j;i(j,h)},"json")}});f(document).ready(wpLink.init)})(jQuery);
1
+ var wpLink;(function(f){var b={},e={},d,a,c;wpLink={timeToTriggerRiver:150,minRiverAJAXDuration:200,riverBottomThreshold:5,keySensitivity:100,lastSearch:"",textarea:"",init:function(){b.dialog=f("#wp-link");b.submit=f("#wp-link-submit");b.url=f("#url-field");b.nonce=f("#_ajax_linking_nonce");b.title=f("#link-title-field");b.openInNewTab=f("#link-target-checkbox");b.search=f("#search-field");e.search=new a(f("#search-results"));e.recent=new a(f("#most-recent-results"));e.elements=f(".query-results",b.dialog);b.dialog.keydown(wpLink.keydown);b.dialog.keyup(wpLink.keyup);b.submit.click(function(g){g.preventDefault();wpLink.update()});f("#wp-link-cancel").click(function(g){g.preventDefault();wpLink.close()});f("#internal-toggle").click(wpLink.toggleInternalLinking);e.elements.bind("river-select",wpLink.updateFields);b.search.keyup(wpLink.searchInternalLinks);b.dialog.bind("wpdialogrefresh",wpLink.refresh);b.dialog.bind("wpdialogbeforeopen",wpLink.beforeOpen);b.dialog.bind("wpdialogclose",wpLink.onClose)},beforeOpen:function(){wpLink.range=null;if(!wpLink.isMCE()&&document.selection){wpLink.textarea.focus();wpLink.range=document.selection.createRange()}},open:function(){if(!wpActiveEditor){return}this.textarea=f("#"+wpActiveEditor).get(0);if(!b.dialog.data("wpdialog")){b.dialog.wpdialog({title:wpLinkL10n.title,width:480,height:"auto",modal:true,dialogClass:"wp-dialog"})}b.dialog.wpdialog("open")},isMCE:function(){return tinyMCEPopup&&(d=tinyMCEPopup.editor)&&!d.isHidden()},refresh:function(){e.search.refresh();e.recent.refresh();if(wpLink.isMCE()){wpLink.mceRefresh()}else{wpLink.setDefaultValues()}b.url.focus()[0].select();if(!e.recent.ul.children().length){e.recent.ajax()}},mceRefresh:function(){var g;d=tinyMCEPopup.editor;tinyMCEPopup.restoreSelection();if(g=d.dom.getParent(d.selection.getNode(),"A")){b.url.val(d.dom.getAttrib(g,"href"));b.title.val(d.dom.getAttrib(g,"title"));b.openInNewTab.prop("checked",("_blank"==d.dom.getAttrib(g,"target")));b.submit.val(wpLinkL10n.update)}else{wpLink.setDefaultValues()}tinyMCEPopup.storeSelection()},close:function(){if(wpLink.isMCE()){tinyMCEPopup.close()}else{b.dialog.wpdialog("close")}},onClose:function(){if(!wpLink.isMCE()){wpLink.textarea.focus();if(wpLink.range){wpLink.range.moveToBookmark(wpLink.range.getBookmark());wpLink.range.select()}}},getAttrs:function(){return{href:b.url.val(),title:b.title.val(),target:b.openInNewTab.prop("checked")?"_blank":""}},update:function(){if(wpLink.isMCE()){wpLink.mceUpdate()}else{wpLink.htmlUpdate()}},htmlUpdate:function(){var i,j,k,h,l,g=wpLink.textarea;if(!g){return}i=wpLink.getAttrs();if(!i.href||i.href=="http://"){return}j='<a href="'+i.href+'"';if(i.title){j+=' title="'+i.title+'"'}if(i.target){j+=' target="'+i.target+'"'}j+=">";if(document.selection&&wpLink.range){g.focus();wpLink.range.text=j+wpLink.range.text+"</a>";wpLink.range.moveToBookmark(wpLink.range.getBookmark());wpLink.range.select();wpLink.range=null}else{if(typeof g.selectionStart!=="undefined"){k=g.selectionStart;h=g.selectionEnd;selection=g.value.substring(k,h);j=j+selection+"</a>";l=k+j.length;if(k==h){l-="</a>".length}g.value=g.value.substring(0,k)+j+g.value.substring(h,g.value.length);g.selectionStart=g.selectionEnd=l}}wpLink.close();g.focus()},mceUpdate:function(){var h=tinyMCEPopup.editor,i=wpLink.getAttrs(),j,g;tinyMCEPopup.restoreSelection();j=h.dom.getParent(h.selection.getNode(),"A");if(!i.href||i.href=="http://"){if(j){tinyMCEPopup.execCommand("mceBeginUndoLevel");g=h.selection.getBookmark();h.dom.remove(j,1);h.selection.moveToBookmark(g);tinyMCEPopup.execCommand("mceEndUndoLevel");wpLink.close()}return}tinyMCEPopup.execCommand("mceBeginUndoLevel");if(j==null){h.getDoc().execCommand("unlink",false,null);tinyMCEPopup.execCommand("mceInsertLink",false,"#mce_temp_url#",{skip_undo:1});tinymce.each(h.dom.select("a"),function(k){if(h.dom.getAttrib(k,"href")=="#mce_temp_url#"){j=k;h.dom.setAttribs(j,i)}});if(f(j).text()=="#mce_temp_url#"){h.dom.remove(j);j=null}}else{h.dom.setAttribs(j,i)}if(j&&(j.childNodes.length!=1||j.firstChild.nodeName!="IMG")){h.focus();h.selection.select(j);h.selection.collapse(0);tinyMCEPopup.storeSelection()}tinyMCEPopup.execCommand("mceEndUndoLevel");wpLink.close()},updateFields:function(i,h,g){b.url.val(h.children(".item-permalink").val());b.title.val(h.hasClass("no-title")?"":h.children(".item-title").text());if(g&&g.type=="click"){b.url.focus()}},setDefaultValues:function(){b.url.val("http://");b.title.val("");b.submit.val(wpLinkL10n.save)},searchInternalLinks:function(){var h=f(this),i,g=h.val();if(g.length>1){e.recent.hide();e.search.show();if(wpLink.lastSearch==g){return}wpLink.lastSearch=g;i=h.parent().find(".spinner").show();e.search.change(g);e.search.ajax(function(){i.hide()})}else{e.search.hide();e.recent.show()}},next:function(){e.search.next();e.recent.next()},prev:function(){e.search.prev();e.recent.prev()},keydown:function(i){var h,g=f.ui.keyCode;switch(i.which){case g.UP:h="prev";case g.DOWN:h=h||"next";clearInterval(wpLink.keyInterval);wpLink[h]();wpLink.keyInterval=setInterval(wpLink[h],wpLink.keySensitivity);break;default:return}i.preventDefault()},keyup:function(h){var g=f.ui.keyCode;switch(h.which){case g.ESCAPE:h.stopImmediatePropagation();if(!f(document).triggerHandler("wp_CloseOnEscape",[{event:h,what:"wplink",cb:wpLink.close}])){wpLink.close()}return false;break;case g.UP:case g.DOWN:clearInterval(wpLink.keyInterval);break;default:return}h.preventDefault()},delayedCallback:function(i,g){var l,k,j,h;if(!g){return i}setTimeout(function(){if(k){return i.apply(h,j)}l=true},g);return function(){if(l){return i.apply(this,arguments)}j=arguments;h=this;k=true}},toggleInternalLinking:function(h){var g=f("#search-panel"),i=b.dialog.wpdialog("widget"),k=!g.is(":visible"),j=f(window);f(this).toggleClass("toggle-arrow-active",k);b.dialog.height("auto");g.slideToggle(300,function(){setUserSetting("wplink",k?"1":"0");b[k?"search":"url"].focus();var l=j.scrollTop(),o=i.offset().top,m=o+i.outerHeight(),n=m-j.height();if(n>l){i.animate({top:n<o?o-n:l},200)}});h.preventDefault()}};a=function(i,h){var g=this;this.element=i;this.ul=i.children("ul");this.waiting=i.find(".river-waiting");this.change(h);this.refresh();i.scroll(function(){g.maybeLoad()});i.delegate("li","click",function(j){g.select(f(this),j)})};f.extend(a.prototype,{refresh:function(){this.deselect();this.visible=this.element.is(":visible")},show:function(){if(!this.visible){this.deselect();this.element.show();this.visible=true}},hide:function(){this.element.hide();this.visible=false},select:function(h,k){var j,i,l,g;if(h.hasClass("unselectable")||h==this.selected){return}this.deselect();this.selected=h.addClass("selected");j=h.outerHeight();i=this.element.height();l=h.position().top;g=this.element.scrollTop();if(l<0){this.element.scrollTop(g+l)}else{if(l+j>i){this.element.scrollTop(g+l-i+j)}}this.element.trigger("river-select",[h,k,this])},deselect:function(){if(this.selected){this.selected.removeClass("selected")}this.selected=false},prev:function(){if(!this.visible){return}var g;if(this.selected){g=this.selected.prev("li");if(g.length){this.select(g)}}},next:function(){if(!this.visible){return}var g=this.selected?this.selected.next("li"):f("li:not(.unselectable):first",this.element);if(g.length){this.select(g)}},ajax:function(j){var h=this,i=this.query.page==1?0:wpLink.minRiverAJAXDuration,g=wpLink.delayedCallback(function(k,l){h.process(k,l);if(j){j(k,l)}},i);this.query.ajax(g)},change:function(g){if(this.query&&this._search==g){return}this._search=g;this.query=new c(g);this.element.scrollTop(0)},process:function(h,l){var i="",j=true,g="",k=l.page==1;if(!h){if(k){i+='<li class="unselectable"><span class="item-title"><em>'+wpLinkL10n.noMatchesFound+"</em></span></li>"}}else{f.each(h,function(){g=j?"alternate":"";g+=this["title"]?"":" no-title";i+=g?'<li class="'+g+'">':"<li>";i+='<input type="hidden" class="item-permalink" value="'+this["permalink"]+'" />';i+='<span class="item-title">';i+=this["title"]?this["title"]:wpLinkL10n.noTitle;i+='</span><span class="item-info">'+this["info"]+"</span></li>";j=!j})}this.ul[k?"html":"append"](i)},maybeLoad:function(){var h=this,i=this.element,g=i.scrollTop()+i.height();if(!this.query.ready()||g<this.ul.height()-wpLink.riverBottomThreshold){return}setTimeout(function(){var j=i.scrollTop(),k=j+i.height();if(!h.query.ready()||k<h.ul.height()-wpLink.riverBottomThreshold){return}h.waiting.show();i.scrollTop(j+h.waiting.outerHeight());h.ajax(function(){h.waiting.hide()})},wpLink.timeToTriggerRiver)}});c=function(g){this.page=1;this.allLoaded=false;this.querying=false;this.search=g};f.extend(c.prototype,{ready:function(){return !(this.querying||this.allLoaded)},ajax:function(i){var g=this,h={action:"wp-link-ajax",page:this.page,_ajax_linking_nonce:b.nonce.val()};if(this.search){h.search=this.search}this.querying=true;f.post(ajaxurl,h,function(j){g.page++;g.querying=false;g.allLoaded=!j;i(j,h)},"json")}});f(document).ready(wpLink.init)})(jQuery);
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === WP Multibyte Patch ===
2
  Contributors: tenpura
3
  Tags: multibyte,i18n,wp-multibyte-patch,Japanese
4
- Requires at least: 3.5
5
- Tested up to: 3.5
6
- Stable tag: 1.6.4
7
 
8
  Multibyte functionality enhancement for the WordPress Japanese package.
9
 
1
  === WP Multibyte Patch ===
2
  Contributors: tenpura
3
  Tags: multibyte,i18n,wp-multibyte-patch,Japanese
4
+ Requires at least: 3.6
5
+ Tested up to: 3.6
6
+ Stable tag: 1.7
7
 
8
  Multibyte functionality enhancement for the WordPress Japanese package.
9
 
wp-multibyte-patch.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: WP Multibyte Patch
4
  Description: Multibyte functionality enhancement for the WordPress Japanese package.
5
- Version: 1.6.4
6
  Plugin URI: http://eastcoder.com/code/wp-multibyte-patch/
7
  Author: Seisuke Kuraishi
8
  Author URI: http://tinybit.co.jp/
@@ -15,9 +15,9 @@ Domain Path: /languages
15
  * Multibyte functionality enhancement for the WordPress Japanese package.
16
  *
17
  * @package WP_Multibyte_Patch
18
- * @version 1.6.4
19
  * @author Seisuke Kuraishi <210pura@gmail.com>
20
- * @copyright Copyright (c) 2012 Seisuke Kuraishi, Tinybit Inc.
21
  * @license http://opensource.org/licenses/gpl-2.0.php GPLv2
22
  * @link http://eastcoder.com/code/wp-multibyte-patch/
23
  */
@@ -30,7 +30,7 @@ class multibyte_patch {
30
  // Do not edit this section. Use wpmp-config.php instead.
31
  var $conf = array(
32
  'excerpt_mblength' => 110,
33
- 'excerpt_more' => ' [...]',
34
  'comment_excerpt_mblength' => 40,
35
  'dashboard_recent_drafts_mblength' => 40,
36
  'patch_wp_mail' => false,
@@ -46,10 +46,11 @@ class multibyte_patch {
46
  'patch_word_count_js' => true,
47
  'patch_force_character_count' => false,
48
  'patch_force_twentytwelve_open_sans_off' => false,
 
49
  'patch_sanitize_file_name' => true,
50
  'patch_bp_create_excerpt' => false,
51
  'bp_excerpt_mblength' => 110,
52
- 'bp_excerpt_more' => ' [...]'
53
  );
54
 
55
  var $blog_encoding = 'UTF-8';
@@ -59,246 +60,246 @@ class multibyte_patch {
59
  var $debug_suffix = '';
60
  var $textdomain = 'wp-multibyte-patch';
61
  var $lang_dir = 'languages';
62
- var $required_version = '3.5';
63
  var $query_based_vars = array();
64
 
65
  // For fallback purpose only. (1.6)
66
- function guess_encoding($string, $encoding = '') {
67
  $blog_encoding = $this->blog_encoding;
68
 
69
- if(!$encoding && seems_utf8($string))
70
  return 'UTF-8';
71
- elseif(!$encoding)
72
  return $blog_encoding;
73
  else
74
  return $encoding;
75
  }
76
 
77
  // For fallback purpose only. (1.6)
78
- function convenc($string, $to_encoding, $from_encoding = '') {
79
  $blog_encoding = $this->blog_encoding;
80
 
81
- if('' == $from_encoding)
82
  $from_encoding = $blog_encoding;
83
 
84
- if(strtoupper($to_encoding) == strtoupper($from_encoding))
85
  return $string;
86
  else
87
- return mb_convert_encoding($string, $to_encoding, $from_encoding);
88
  }
89
 
90
- function incoming_trackback($commentdata) {
91
- global $wpdb;
92
-
93
- if('trackback' != $commentdata['comment_type'])
94
  return $commentdata;
95
 
96
- if(false === $this->conf['patch_incoming_trackback'])
97
  return $commentdata;
98
 
99
- $title = isset($_POST['title']) ? stripslashes($_POST['title']) : '';
100
- $excerpt = isset($_POST['excerpt']) ? stripslashes($_POST['excerpt']) : '';
101
- $blog_name = isset($_POST['blog_name']) ? stripslashes($_POST['blog_name']) : '';
102
  $blog_encoding = $this->blog_encoding;
103
 
104
- $from_encoding = isset($_POST['charset']) ? $_POST['charset'] : '';
105
 
106
- if(!$from_encoding)
107
- $from_encoding = (preg_match("/^.*charset=([a-zA-Z0-9\-_]+).*$/i", $_SERVER['CONTENT_TYPE'], $matched)) ? $matched[1] : '';
108
 
109
- $from_encoding = str_replace(array(',', ' '), '', strtoupper(trim($from_encoding)));
110
- $from_encoding = $this->guess_encoding($excerpt . $title . $blog_name, $from_encoding);
111
 
112
- $title = $this->convenc($title, $blog_encoding, $from_encoding);
113
- $blog_name = $this->convenc($blog_name, $blog_encoding, $from_encoding);
114
- $excerpt = $this->convenc($excerpt, $blog_encoding, $from_encoding);
115
 
116
- $title = strip_tags($title);
117
- $excerpt = strip_tags($excerpt);
118
 
119
- $title = (strlen($title) > 250) ? mb_strcut($title, 0, 250, $blog_encoding) . '...' : $title;
120
- $excerpt = (strlen($excerpt) > 255) ? mb_strcut($excerpt, 0, 252, $blog_encoding) . '...' : $excerpt;
121
 
122
- $commentdata['comment_author'] = $wpdb->escape($blog_name);
123
- $commentdata['comment_content'] = $wpdb->escape("<strong>$title</strong>\n\n$excerpt");
124
 
125
  return $commentdata;
126
  }
127
 
128
- function pre_remote_source($linea, $pagelinkedto) {
129
  $this->pingback_ping_linea = $linea;
130
  $this->pingback_ping_pagelinkedto = $pagelinkedto;
131
  return $linea;
132
  }
133
 
134
- function incoming_pingback($commentdata) {
135
- global $wpdb;
136
-
137
- if('pingback' != $commentdata['comment_type'])
138
  return $commentdata;
139
 
140
- if(false === $this->conf['patch_incoming_pingback'])
141
  return $commentdata;
142
 
143
  $pagelinkedto = $this->pingback_ping_pagelinkedto;
144
  $linea = $this->pingback_ping_linea;
145
 
146
- $linea = preg_replace("/" . preg_quote('<!DOC', '/') . "/i", '<DOC', $linea);
147
- $linea = preg_replace("/[\r\n\t ]+/", ' ', $linea);
148
- $linea = preg_replace("/<\/*(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/i", "\n\n", $linea);
149
 
150
- preg_match('|<title>([^<]*?)</title>|is', $linea, $matchtitle);
151
  $title = $matchtitle[1];
152
 
153
- preg_match("/<meta[^<>]+charset=\"*([a-zA-Z0-9\-_]+)\"*[^<>]*>/i", $linea, $matches);
154
- $charset = isset($matches[1]) ? $matches[1] : '';
155
- $from_encoding = $this->guess_encoding(strip_tags($linea), $charset);
156
  $blog_encoding = $this->blog_encoding;
157
 
158
- $linea = strip_tags($linea, '<a>');
159
- $linea = $this->convenc($linea, $blog_encoding, $from_encoding);
160
- $p = explode("\n\n", $linea);
161
 
162
- foreach ($p as $para) {
163
- if(strpos($para, $pagelinkedto) !== false && preg_match("/^([^<>]*)(\<a[^<>]+[\"']" . preg_quote($pagelinkedto, '/') . "[\"'][^<>]*\>)([^<>]+)(\<\/a\>)(.*)$/i", $para, $context))
164
  break;
165
  }
166
 
167
- if(!$context)
168
  return $commentdata;
169
 
170
- $context[1] = strip_tags($context[1]);
171
- $context[5] = strip_tags($context[5]);
172
  $len_max = 250;
173
- $len_c3 = strlen($context[3]);
174
 
175
- if($len_c3 > $len_max) {
176
- $excerpt = mb_strcut($context[3], 0, 250, $blog_encoding);
177
  } else {
178
- $len_c1 = strlen($context[1]);
179
- $len_c5 = strlen($context[5]);
180
  $len_left = $len_max - $len_c3;
181
- $len_left_even = ceil($len_left / 2);
182
 
183
- if($len_left_even > $len_c1) {
184
- $context[5] = mb_strcut($context[5], 0, $len_left - $len_c1, $blog_encoding);
185
  }
186
- elseif($len_left_even > $len_c5) {
187
  $context[1] .= "\t\t\t\t\t\t";
188
- $context[1] = mb_strcut($context[1], $len_c1 - ($len_left - $len_c5), $len_c1 + 6, $blog_encoding);
189
- $context[1] = preg_replace("/\t*$/", '', $context[1]);
190
  }
191
  else {
192
  $context[1] .= "\t\t\t\t\t\t";
193
- $context[1] = mb_strcut($context[1], $len_c1 - $len_left_even, $len_c1 + 6, $blog_encoding);
194
- $context[1] = preg_replace("/\t*$/", '', $context[1]);
195
- $context[5] = mb_strcut($context[5], 0, $len_left_even, $blog_encoding);
196
  }
197
 
198
  $excerpt = $context[1] . $context[3] . $context[5];
199
  }
200
 
201
- $commentdata['comment_content'] = '[...] ' . esc_html($excerpt) . ' [...]';
202
- $commentdata['comment_content'] = $wpdb->escape($commentdata['comment_content']);
203
- $commentdata['comment_author'] = $this->convenc($title, $blog_encoding, $from_encoding);
204
- $commentdata['comment_author'] = $wpdb->escape($commentdata['comment_author']);
205
 
206
  return $commentdata;
207
  }
208
 
209
- function preprocess_comment($commentdata) {
210
- if($commentdata['comment_type'] == 'trackback')
211
- return $this->incoming_trackback($commentdata);
212
- elseif($commentdata['comment_type'] == 'pingback')
213
- return $this->incoming_pingback($commentdata);
214
  else
215
  return $commentdata;
216
  }
217
 
218
- function trim_multibyte_excerpt($text = '', $length = 110, $more = ' [...]', $encoding = 'UTF-8') {
219
- $text = strip_shortcodes($text);
220
- $text = str_replace(']]>', ']]&gt;', $text);
221
- $text = strip_tags($text);
222
- $text = trim(preg_replace("/[\n\r\t ]+/", ' ', $text), ' ');
223
 
224
- if($this->mb_strlen($text, $encoding) > $length)
225
- $text = mb_substr($text, 0, $length, $encoding) . $more;
226
 
227
  return $text;
228
  }
229
 
230
- function bp_create_excerpt($text = '') {
231
- return $this->trim_multibyte_excerpt($text, $this->conf['bp_excerpt_mblength'], $this->conf['bp_excerpt_more'], $this->blog_encoding);
232
  }
233
 
234
- function bp_get_activity_content_body($content = '') {
235
- return preg_replace("/<a [^<>]+>([^<>]+)<\/a>(" . preg_quote($this->conf['bp_excerpt_more'], '/') . "<\/p>)$/", "$1$2", $content);
236
  }
237
 
238
  // param $excerpt could already be truncated to 20 words or less by the original get_comment_excerpt() function.
239
- function get_comment_excerpt($excerpt = '') {
240
- $excerpt = preg_replace("/\.\.\.$/", '', $excerpt);
241
  $blog_encoding = $this->blog_encoding;
242
 
243
- if($this->mb_strlen($excerpt, $blog_encoding) > $this->conf['comment_excerpt_mblength'])
244
- $excerpt = mb_substr($excerpt, 0, $this->conf['comment_excerpt_mblength'], $blog_encoding) . '...';
245
 
246
  return $excerpt;
247
  }
248
 
249
  function excerpt_mblength() {
250
- if(isset($this->query_based_vars['excerpt_mblength']) && (int) $this->query_based_vars['excerpt_mblength'])
251
  $length = (int) $this->query_based_vars['excerpt_mblength'];
252
  else
253
  $length = (int) $this->conf['excerpt_mblength'];
254
 
255
- return apply_filters('excerpt_mblength', $length);
256
  }
257
 
258
  function excerpt_more() {
259
- if(isset($this->query_based_vars['excerpt_more']))
260
  return $this->query_based_vars['excerpt_more'];
261
  else
262
  return $this->conf['excerpt_more'];
263
  }
264
 
265
- function sanitize_file_name($name) {
266
- $info = pathinfo($name);
267
- $ext = !empty($info['extension']) ? '.' . $info['extension'] : '';
268
- $name = str_replace($ext, '', $name);
269
- $name_enc = rawurlencode($name);
270
- $name = ($name == $name_enc) ? $name . $ext : md5($name) . $ext;
271
  return $name;
272
  }
273
 
274
- function wplink_js(&$scripts) {
275
- $scripts->add('wplink', plugin_dir_url(__FILE__) . "js/wplink{$this->debug_suffix}.js", array('jquery', 'wpdialogs'), false, 1 );
276
  }
277
 
278
- function word_count_js(&$scripts) {
279
- $scripts->add('word-count', plugin_dir_url(__FILE__) . "js/word-count{$this->debug_suffix}.js", array('jquery'), false, 1);
280
  }
281
 
282
- function force_character_count($translations = '', $text = '', $context = '') {
283
- if('word count: words or characters?' == $context && 'words' == $text)
284
  return 'characters';
285
  return $translations;
286
  }
287
 
288
  function force_twentytwelve_open_sans_off() {
289
- wp_dequeue_style('twentytwelve-fonts');
 
 
 
 
290
  }
291
 
292
  function wp_dashboard_recent_drafts( $drafts = false ) {
293
  if ( !$drafts ) {
294
  $drafts_query = new WP_Query( array(
295
- 'post_type' => 'post',
296
- 'post_status' => 'draft',
297
- 'author' => $GLOBALS['current_user']->ID,
298
- 'posts_per_page' => 5,
299
- 'orderby' => 'modified',
300
- 'order' => 'DESC'
301
- ) );
302
  $drafts =& $drafts_query->posts;
303
  }
304
 
@@ -307,115 +308,120 @@ class multibyte_patch {
307
  foreach ( $drafts as $draft ) {
308
  $url = get_edit_post_link( $draft->ID );
309
  $title = _draft_or_post_title( $draft->ID );
310
- $item = "<h4><a href='$url' title='" . sprintf( __( 'Edit &#8220;%s&#8221;' ), esc_attr( $title ) ) . "'>" . esc_html($title) . "</a> <abbr title='" . get_the_time(__('Y/m/d g:i:s A'), $draft) . "'>" . get_the_time( get_option( 'date_format' ), $draft ) . '</abbr></h4>';
311
- $item .= '<p>' . $this->trim_multibyte_excerpt($draft->post_content, $this->conf['dashboard_recent_drafts_mblength'], $more = '&hellip;', $this->blog_encoding) . '</p>';
312
  $list[] = $item;
313
  }
314
- ?>
315
  <ul>
316
  <li><?php echo join( "</li>\n<li>", $list ); ?></li>
317
  </ul>
318
- <p class="textright"><a href="edit.php?post_status=draft" ><?php _e('View all'); ?></a></p>
319
  <?php
320
  } else {
321
- _e('There are no drafts at the moment');
322
  }
323
  }
324
 
325
  function dashboard_recent_drafts() {
326
  global $wp_meta_boxes;
327
- if(!empty($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']['callback']))
328
- $wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']['callback'] = array($this, 'wp_dashboard_recent_drafts');
329
  }
330
 
331
  function query_based_settings() {
332
- $is_query_funcs = array('is_feed', 'is_404', 'is_search', 'is_tax', 'is_front_page', 'is_home', 'is_attachment', 'is_single', 'is_page', 'is_category', 'is_tag', 'is_author', 'is_date', 'is_archive', 'is_paged');
333
 
334
- foreach($is_query_funcs as $func) {
335
- if(isset($this->conf['excerpt_mblength.' . $func]) && !isset($this->query_based_vars['excerpt_mblength']) && $func())
336
  $this->query_based_vars['excerpt_mblength'] = $this->conf['excerpt_mblength.' . $func];
337
 
338
- if(isset($this->conf['excerpt_more.' . $func]) && !isset($this->query_based_vars['excerpt_more']) && $func())
339
  $this->query_based_vars['excerpt_more'] = $this->conf['excerpt_more.' . $func];
340
  }
341
  }
342
 
343
  // The fallback only works with UTF-8 blog.
344
- function mb_strlen($str = '', $encoding = 'UTF-8') {
345
- if($this->has_mb_strlen)
346
- return mb_strlen($str, $encoding);
347
  else
348
- return preg_match_all("/./us", $str, $match);
349
  }
350
 
351
  function filters_after_setup_theme() {
352
  // add filter
353
- if(false !== $this->conf['patch_force_character_count'] && 'characters' != _x('words', 'word count: words or characters?'))
354
- add_filter('gettext_with_context', array($this, 'force_character_count'), 10, 3);
 
 
 
 
 
 
 
 
355
  }
356
 
357
  function filters() {
358
  // add filter
359
- add_filter('preprocess_comment', array($this, 'preprocess_comment'), 99);
360
 
361
- if(false !== $this->conf['patch_incoming_pingback'])
362
- add_filter('pre_remote_source', array($this, 'pre_remote_source'), 10, 2);
363
 
364
- if(false !== $this->conf['patch_wp_trim_excerpt']) {
365
- add_filter('excerpt_length', array($this, 'excerpt_mblength'), 99);
366
- add_filter('excerpt_more', array($this, 'excerpt_more'), 9);
367
  }
368
 
369
- if(false !== $this->conf['patch_get_comment_excerpt'])
370
- add_filter('get_comment_excerpt', array($this, 'get_comment_excerpt'));
371
 
372
- if(false !== $this->conf['patch_sanitize_file_name'])
373
- add_filter('sanitize_file_name', array($this, 'sanitize_file_name'));
374
 
375
- if(false !== $this->conf['patch_bp_create_excerpt']) {
376
- add_filter('bp_create_excerpt', array($this, 'bp_create_excerpt'), 99);
377
- add_filter('bp_get_activity_content_body', array($this, 'bp_get_activity_content_body'), 99);
378
  }
379
 
380
- if(method_exists($this, 'wp_trim_words') && false !== $this->conf['patch_wp_trim_words'])
381
- add_filter('wp_trim_words', array($this, 'wp_trim_words'), 99, 4);
382
 
383
  // add action
384
- add_action('wp', array($this, 'query_based_settings'));
385
 
386
- if(method_exists($this, 'process_search_terms') && false !== $this->conf['patch_process_search_terms'])
387
- add_action('sanitize_comment_cookies', array($this, 'process_search_terms'));
388
 
389
- if(method_exists($this, 'wp_mail') && false !== $this->conf['patch_wp_mail'])
390
- add_action('phpmailer_init', array($this, 'wp_mail'));
391
 
392
- if(method_exists($this, 'admin_custom_css') && false !== $this->conf['patch_admin_custom_css']) {
393
- add_action('admin_enqueue_scripts', array($this, 'admin_custom_css'), 99);
394
- add_action('customize_controls_enqueue_scripts', array($this, 'admin_custom_css'), 99);
395
  }
396
 
397
- if(false !== $this->conf['patch_wplink_js'])
398
- add_action('wp_default_scripts', array($this, 'wplink_js'), 9);
399
-
400
- if(false !== $this->conf['patch_word_count_js'])
401
- add_action('wp_default_scripts', array($this, 'word_count_js'), 9);
402
 
403
- if(false !== $this->conf['patch_dashboard_recent_drafts'])
404
- add_action('wp_dashboard_setup', array($this, 'dashboard_recent_drafts'));
405
 
406
- if(false !== $this->conf['patch_force_twentytwelve_open_sans_off'] && 'twentytwelve' == get_template())
407
- add_action('wp_enqueue_scripts', array($this, 'force_twentytwelve_open_sans_off'), 99);
408
 
409
- add_action('after_setup_theme', array($this, 'filters_after_setup_theme'), 99);
410
  }
411
 
412
  function mbfunctions_exist() {
413
  return (
414
- function_exists('mb_convert_encoding') &&
415
- function_exists('mb_convert_kana') &&
416
- function_exists('mb_detect_encoding') &&
417
- function_exists('mb_strcut') &&
418
- function_exists('mb_strlen')
419
  ) ? true : false;
420
  }
421
 
@@ -423,62 +429,58 @@ class multibyte_patch {
423
  global $wp_version;
424
  $required_version = $this->required_version;
425
 
426
- if(version_compare(substr($wp_version, 0, strlen($required_version)), $required_version, '<')) {
427
- deactivate_plugins(__FILE__);
428
- exit(sprintf(__('Sorry, WP Multibyte Patch requires WordPress %s or later.', 'wp-multibyte-patch'), $required_version));
429
  }
430
- elseif(!$this->has_mbfunctions && $this->mbfunctions_required) {
431
- deactivate_plugins(__FILE__);
432
- exit(__('Sorry, WP Multibyte Patch requires <a href="http://www.php.net/manual/en/mbstring.installation.php" target="_blank">mbstring</a> functions.', 'wp-multibyte-patch'));
433
  }
434
  }
435
 
436
  function load_conf() {
437
  $wpmp_conf = array();
438
 
439
- if(file_exists(WP_CONTENT_DIR . '/wpmp-config.php'))
440
- require_once(WP_CONTENT_DIR . '/wpmp-config.php');
441
 
442
- if(is_multisite()) {
443
  $blog_id = get_current_blog_id();
444
- if(file_exists(WP_CONTENT_DIR . '/wpmp-config-blog-' . $blog_id . '.php'))
445
- require_once(WP_CONTENT_DIR . '/wpmp-config-blog-' . $blog_id . '.php');
446
  }
447
 
448
- $this->conf = array_merge($this->conf, $wpmp_conf);
449
  }
450
 
451
  function __construct() {
452
  $this->load_conf();
453
- $this->blog_encoding = get_option('blog_charset');
454
 
455
  // mbstring functions are required for non UTF-8 blog.
456
- if(!preg_match("/^utf-?8$/i", $this->blog_encoding))
457
  $this->mbfunctions_required = true;
458
 
459
  $this->has_mbfunctions = $this->mbfunctions_exist();
460
- $this->has_mb_strlen = function_exists('mb_strlen');
461
- $this->debug_suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
462
 
463
- load_textdomain($this->textdomain, plugin_dir_path(__FILE__) . $this->lang_dir . '/' . $this->textdomain . '-' . get_locale() . '.mo');
464
- register_activation_hook(__FILE__, array($this, 'activation_check'));
465
  $this->filters();
466
  }
467
  }
468
 
469
- if(defined('WP_PLUGIN_URL')) {
470
- global $wpmp;
471
-
472
- if(file_exists(dirname(__FILE__) . '/ext/' . get_locale() . '/class.php')) {
473
- require_once(dirname(__FILE__) . '/ext/' . get_locale() . '/class.php');
474
- $wpmp = new multibyte_patch_ext();
475
  }
476
- elseif(file_exists(dirname(__FILE__) . '/ext/default/class.php')) {
477
- require_once(dirname(__FILE__) . '/ext/default/class.php');
478
- $wpmp = new multibyte_patch_ext();
479
  }
480
  else
481
- $wpmp = new multibyte_patch();
482
  }
483
-
484
- ?>
2
  /*
3
  Plugin Name: WP Multibyte Patch
4
  Description: Multibyte functionality enhancement for the WordPress Japanese package.
5
+ Version: 1.7
6
  Plugin URI: http://eastcoder.com/code/wp-multibyte-patch/
7
  Author: Seisuke Kuraishi
8
  Author URI: http://tinybit.co.jp/
15
  * Multibyte functionality enhancement for the WordPress Japanese package.
16
  *
17
  * @package WP_Multibyte_Patch
18
+ * @version 1.7
19
  * @author Seisuke Kuraishi <210pura@gmail.com>
20
+ * @copyright Copyright (c) 2013 Seisuke Kuraishi, Tinybit Inc.
21
  * @license http://opensource.org/licenses/gpl-2.0.php GPLv2
22
  * @link http://eastcoder.com/code/wp-multibyte-patch/
23
  */
30
  // Do not edit this section. Use wpmp-config.php instead.
31
  var $conf = array(
32
  'excerpt_mblength' => 110,
33
+ 'excerpt_more' => ' [&hellip;]',
34
  'comment_excerpt_mblength' => 40,
35
  'dashboard_recent_drafts_mblength' => 40,
36
  'patch_wp_mail' => false,
46
  'patch_word_count_js' => true,
47
  'patch_force_character_count' => false,
48
  'patch_force_twentytwelve_open_sans_off' => false,
49
+ 'patch_force_twentythirteen_google_fonts_off' => false,
50
  'patch_sanitize_file_name' => true,
51
  'patch_bp_create_excerpt' => false,
52
  'bp_excerpt_mblength' => 110,
53
+ 'bp_excerpt_more' => ' [&hellip;]'
54
  );
55
 
56
  var $blog_encoding = 'UTF-8';
60
  var $debug_suffix = '';
61
  var $textdomain = 'wp-multibyte-patch';
62
  var $lang_dir = 'languages';
63
+ var $required_version = '3.6';
64
  var $query_based_vars = array();
65
 
66
  // For fallback purpose only. (1.6)
67
+ function guess_encoding( $string, $encoding = '' ) {
68
  $blog_encoding = $this->blog_encoding;
69
 
70
+ if ( !$encoding && seems_utf8( $string ) )
71
  return 'UTF-8';
72
+ elseif ( !$encoding )
73
  return $blog_encoding;
74
  else
75
  return $encoding;
76
  }
77
 
78
  // For fallback purpose only. (1.6)
79
+ function convenc( $string, $to_encoding, $from_encoding = '' ) {
80
  $blog_encoding = $this->blog_encoding;
81
 
82
+ if ( '' == $from_encoding )
83
  $from_encoding = $blog_encoding;
84
 
85
+ if ( strtoupper( $to_encoding ) == strtoupper( $from_encoding ) )
86
  return $string;
87
  else
88
+ return mb_convert_encoding( $string, $to_encoding, $from_encoding );
89
  }
90
 
91
+ function incoming_trackback( $commentdata ) {
92
+ if ( 'trackback' != $commentdata['comment_type'] )
 
 
93
  return $commentdata;
94
 
95
+ if ( false === $this->conf['patch_incoming_trackback'] )
96
  return $commentdata;
97
 
98
+ $title = isset( $_POST['title'] ) ? wp_unslash( $_POST['title'] ) : '';
99
+ $excerpt = isset( $_POST['excerpt'] ) ? wp_unslash( $_POST['excerpt'] ) : '';
100
+ $blog_name = isset( $_POST['blog_name'] ) ? wp_unslash( $_POST['blog_name'] ) : '';
101
  $blog_encoding = $this->blog_encoding;
102
 
103
+ $from_encoding = isset( $_POST['charset'] ) ? $_POST['charset'] : '';
104
 
105
+ if ( !$from_encoding )
106
+ $from_encoding = ( preg_match( "/^.*charset=([a-zA-Z0-9\-_]+).*$/i", $_SERVER['CONTENT_TYPE'], $matched ) ) ? $matched[1] : '';
107
 
108
+ $from_encoding = str_replace( array( ',', ' ' ), '', strtoupper( trim( $from_encoding ) ) );
109
+ $from_encoding = $this->guess_encoding( $excerpt . $title . $blog_name, $from_encoding );
110
 
111
+ $title = $this->convenc( $title, $blog_encoding, $from_encoding );
112
+ $blog_name = $this->convenc( $blog_name, $blog_encoding, $from_encoding );
113
+ $excerpt = $this->convenc( $excerpt, $blog_encoding, $from_encoding );
114
 
115
+ $title = strip_tags( $title );
116
+ $excerpt = strip_tags( $excerpt );
117
 
118
+ $title = ( strlen( $title ) > 250 ) ? mb_strcut( $title, 0, 250, $blog_encoding ) . '&#8230;' : $title;
119
+ $excerpt = ( strlen( $excerpt ) > 255 ) ? mb_strcut( $excerpt, 0, 252, $blog_encoding ) . '&#8230;' : $excerpt;
120
 
121
+ $commentdata['comment_author'] = wp_slash( $blog_name );
122
+ $commentdata['comment_content'] = wp_slash( "<strong>$title</strong>\n\n$excerpt" );
123
 
124
  return $commentdata;
125
  }
126
 
127
+ function pre_remote_source( $linea, $pagelinkedto ) {
128
  $this->pingback_ping_linea = $linea;
129
  $this->pingback_ping_pagelinkedto = $pagelinkedto;
130
  return $linea;
131
  }
132
 
133
+ function incoming_pingback( $commentdata ) {
134
+ if ( 'pingback' != $commentdata['comment_type'] )
 
 
135
  return $commentdata;
136
 
137
+ if ( false === $this->conf['patch_incoming_pingback'] )
138
  return $commentdata;
139
 
140
  $pagelinkedto = $this->pingback_ping_pagelinkedto;
141
  $linea = $this->pingback_ping_linea;
142
 
143
+ $linea = preg_replace( "/" . preg_quote( '<!DOC', '/' ) . "/i", '<DOC', $linea );
144
+ $linea = preg_replace( "/[\r\n\t ]+/", ' ', $linea );
145
+ $linea = preg_replace( "/<\/*(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/i", "\n\n", $linea );
146
 
147
+ preg_match( '|<title>([^<]*?)</title>|is', $linea, $matchtitle );
148
  $title = $matchtitle[1];
149
 
150
+ preg_match( "/<meta[^<>]+charset=\"*([a-zA-Z0-9\-_]+)\"*[^<>]*>/i", $linea, $matches );
151
+ $charset = isset( $matches[1] ) ? $matches[1] : '';
152
+ $from_encoding = $this->guess_encoding( strip_tags( $linea ), $charset );
153
  $blog_encoding = $this->blog_encoding;
154
 
155
+ $linea = strip_tags( $linea, '<a>' );
156
+ $linea = $this->convenc( $linea, $blog_encoding, $from_encoding );
157
+ $p = explode( "\n\n", $linea );
158
 
159
+ foreach ( $p as $para ) {
160
+ if ( strpos( $para, $pagelinkedto ) !== false && preg_match( "/^([^<>]*)(\<a[^<>]+[\"']" . preg_quote( $pagelinkedto, '/' ) . "[\"'][^<>]*\>)([^<>]+)(\<\/a\>)(.*)$/i", $para, $context ) )
161
  break;
162
  }
163
 
164
+ if ( !$context )
165
  return $commentdata;
166
 
167
+ $context[1] = strip_tags( $context[1] );
168
+ $context[5] = strip_tags( $context[5] );
169
  $len_max = 250;
170
+ $len_c3 = strlen( $context[3] );
171
 
172
+ if ( $len_c3 > $len_max ) {
173
+ $excerpt = mb_strcut( $context[3], 0, 250, $blog_encoding );
174
  } else {
175
+ $len_c1 = strlen( $context[1] );
176
+ $len_c5 = strlen( $context[5] );
177
  $len_left = $len_max - $len_c3;
178
+ $len_left_even = ceil( $len_left / 2 );
179
 
180
+ if ( $len_left_even > $len_c1 ) {
181
+ $context[5] = mb_strcut( $context[5], 0, $len_left - $len_c1, $blog_encoding );
182
  }
183
+ elseif ( $len_left_even > $len_c5 ) {
184
  $context[1] .= "\t\t\t\t\t\t";
185
+ $context[1] = mb_strcut( $context[1], $len_c1 - ( $len_left - $len_c5 ), $len_c1 + 6, $blog_encoding );
186
+ $context[1] = preg_replace( "/\t*$/", '', $context[1] );
187
  }
188
  else {
189
  $context[1] .= "\t\t\t\t\t\t";
190
+ $context[1] = mb_strcut( $context[1], $len_c1 - $len_left_even, $len_c1 + 6, $blog_encoding );
191
+ $context[1] = preg_replace( "/\t*$/", '', $context[1] );
192
+ $context[5] = mb_strcut( $context[5], 0, $len_left_even, $blog_encoding );
193
  }
194
 
195
  $excerpt = $context[1] . $context[3] . $context[5];
196
  }
197
 
198
+ $commentdata['comment_content'] = '[&#8230;] ' . esc_html( $excerpt ) . ' [&#8230;]';
199
+ $commentdata['comment_content'] = wp_slash( $commentdata['comment_content'] );
200
+ $commentdata['comment_author'] = $this->convenc( $title, $blog_encoding, $from_encoding );
201
+ $commentdata['comment_author'] = wp_slash( $commentdata['comment_author'] );
202
 
203
  return $commentdata;
204
  }
205
 
206
+ function preprocess_comment( $commentdata ) {
207
+ if ( $commentdata['comment_type'] == 'trackback' )
208
+ return $this->incoming_trackback( $commentdata );
209
+ elseif ( $commentdata['comment_type'] == 'pingback' )
210
+ return $this->incoming_pingback( $commentdata );
211
  else
212
  return $commentdata;
213
  }
214
 
215
+ function trim_multibyte_excerpt( $text = '', $length = 110, $more = ' [&hellip;]', $encoding = 'UTF-8' ) {
216
+ $text = strip_shortcodes( $text );
217
+ $text = str_replace( ']]>', ']]&gt;', $text );
218
+ $text = strip_tags( $text );
219
+ $text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
220
 
221
+ if ( $this->mb_strlen( $text, $encoding ) > $length )
222
+ $text = mb_substr( $text, 0, $length, $encoding ) . $more;
223
 
224
  return $text;
225
  }
226
 
227
+ function bp_create_excerpt( $text = '' ) {
228
+ return $this->trim_multibyte_excerpt( $text, $this->conf['bp_excerpt_mblength'], $this->conf['bp_excerpt_more'], $this->blog_encoding );
229
  }
230
 
231
+ function bp_get_activity_content_body( $content = '' ) {
232
+ return preg_replace( "/<a [^<>]+>([^<>]+)<\/a>(" . preg_quote( $this->conf['bp_excerpt_more'], '/' ) . "<\/p>)$/", "$1$2", $content );
233
  }
234
 
235
  // param $excerpt could already be truncated to 20 words or less by the original get_comment_excerpt() function.
236
+ function get_comment_excerpt( $excerpt = '' ) {
237
+ $excerpt = preg_replace( "/\.\.\.$/", '', $excerpt );
238
  $blog_encoding = $this->blog_encoding;
239
 
240
+ if ( $this->mb_strlen( $excerpt, $blog_encoding ) > $this->conf['comment_excerpt_mblength'] )
241
+ $excerpt = mb_substr( $excerpt, 0, $this->conf['comment_excerpt_mblength'], $blog_encoding ) . '&hellip;';
242
 
243
  return $excerpt;
244
  }
245
 
246
  function excerpt_mblength() {
247
+ if ( isset( $this->query_based_vars['excerpt_mblength'] ) && (int) $this->query_based_vars['excerpt_mblength'] )
248
  $length = (int) $this->query_based_vars['excerpt_mblength'];
249
  else
250
  $length = (int) $this->conf['excerpt_mblength'];
251
 
252
+ return apply_filters( 'excerpt_mblength', $length );
253
  }
254
 
255
  function excerpt_more() {
256
+ if ( isset( $this->query_based_vars['excerpt_more'] ) )
257
  return $this->query_based_vars['excerpt_more'];
258
  else
259
  return $this->conf['excerpt_more'];
260
  }
261
 
262
+ function sanitize_file_name( $name ) {
263
+ $info = pathinfo( $name );
264
+ $ext = !empty( $info['extension'] ) ? '.' . $info['extension'] : '';
265
+ $name = str_replace( $ext, '', $name );
266
+ $name_enc = rawurlencode( $name );
267
+ $name = ( $name == $name_enc ) ? $name . $ext : md5( $name ) . $ext;
268
  return $name;
269
  }
270
 
271
+ function wplink_js( &$scripts ) {
272
+ $scripts->add( 'wplink', plugin_dir_url( __FILE__ ) . "js/wplink{$this->debug_suffix}.js", array( 'jquery', 'wpdialogs' ), false, 1 );
273
  }
274
 
275
+ function word_count_js( &$scripts ) {
276
+ $scripts->add( 'word-count', plugin_dir_url( __FILE__ ) . "js/word-count{$this->debug_suffix}.js", array( 'jquery' ), false, 1 );
277
  }
278
 
279
+ function force_character_count( $translations = '', $text = '', $context = '' ) {
280
+ if ( 'word count: words or characters?' == $context && 'words' == $text )
281
  return 'characters';
282
  return $translations;
283
  }
284
 
285
  function force_twentytwelve_open_sans_off() {
286
+ wp_dequeue_style( 'twentytwelve-fonts' );
287
+ }
288
+
289
+ function force_twentythirteen_google_fonts_off() {
290
+ wp_dequeue_style( 'twentythirteen-fonts' );
291
  }
292
 
293
  function wp_dashboard_recent_drafts( $drafts = false ) {
294
  if ( !$drafts ) {
295
  $drafts_query = new WP_Query( array(
296
+ 'post_type' => 'post',
297
+ 'post_status' => 'draft',
298
+ 'author' => $GLOBALS['current_user']->ID,
299
+ 'posts_per_page' => 5,
300
+ 'orderby' => 'modified',
301
+ 'order' => 'DESC'
302
+ ) );
303
  $drafts =& $drafts_query->posts;
304
  }
305
 
308
  foreach ( $drafts as $draft ) {
309
  $url = get_edit_post_link( $draft->ID );
310
  $title = _draft_or_post_title( $draft->ID );
311
+ $item = "<h4><a href='$url' title='" . sprintf( __( 'Edit &#8220;%s&#8221;' ), esc_attr( $title ) ) . "'>" . esc_html( $title ) . "</a> <abbr title='" . get_the_time( __( 'Y/m/d g:i:s A' ), $draft ) . "'>" . get_the_time( get_option( 'date_format' ), $draft ) . '</abbr></h4>';
312
+ $item .= '<p>' . $this->trim_multibyte_excerpt( $draft->post_content, $this->conf['dashboard_recent_drafts_mblength'], $more = '&hellip;', $this->blog_encoding ) . '</p>';
313
  $list[] = $item;
314
  }
315
+ ?>
316
  <ul>
317
  <li><?php echo join( "</li>\n<li>", $list ); ?></li>
318
  </ul>
319
+ <p class="textright"><a href="edit.php?post_status=draft" ><?php _e( 'View all' ); ?></a></p>
320
  <?php
321
  } else {
322
+ _e( 'There are no drafts at the moment' );
323
  }
324
  }
325
 
326
  function dashboard_recent_drafts() {
327
  global $wp_meta_boxes;
328
+ if ( !empty( $wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']['callback'] ) )
329
+ $wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']['callback'] = array( $this, 'wp_dashboard_recent_drafts' );
330
  }
331
 
332
  function query_based_settings() {
333
+ $is_query_funcs = array( 'is_feed', 'is_404', 'is_search', 'is_tax', 'is_front_page', 'is_home', 'is_attachment', 'is_single', 'is_page', 'is_category', 'is_tag', 'is_author', 'is_date', 'is_archive', 'is_paged' );
334
 
335
+ foreach ( $is_query_funcs as $func ) {
336
+ if ( isset( $this->conf['excerpt_mblength.' . $func] ) && !isset( $this->query_based_vars['excerpt_mblength'] ) && $func() )
337
  $this->query_based_vars['excerpt_mblength'] = $this->conf['excerpt_mblength.' . $func];
338
 
339
+ if ( isset( $this->conf['excerpt_more.' . $func] ) && !isset( $this->query_based_vars['excerpt_more'] ) && $func() )
340
  $this->query_based_vars['excerpt_more'] = $this->conf['excerpt_more.' . $func];
341
  }
342
  }
343
 
344
  // The fallback only works with UTF-8 blog.
345
+ function mb_strlen( $str = '', $encoding = 'UTF-8' ) {
346
+ if ( $this->has_mb_strlen )
347
+ return mb_strlen( $str, $encoding );
348
  else
349
+ return preg_match_all( "/./us", $str, $match );
350
  }
351
 
352
  function filters_after_setup_theme() {
353
  // add filter
354
+ if ( false !== $this->conf['patch_force_character_count'] && 'characters' != _x( 'words', 'word count: words or characters?' ) )
355
+ add_filter( 'gettext_with_context', array( $this, 'force_character_count' ), 10, 3 );
356
+
357
+ if ( false !== $this->conf['patch_force_twentytwelve_open_sans_off'] && 'twentytwelve' == get_template() )
358
+ add_action( 'wp_enqueue_scripts', array( $this, 'force_twentytwelve_open_sans_off' ), 99 );
359
+
360
+ if ( false !== $this->conf['patch_force_twentythirteen_google_fonts_off'] && 'twentythirteen' == get_template() ) {
361
+ add_action( 'wp_enqueue_scripts', array( $this, 'force_twentythirteen_google_fonts_off' ), 99 );
362
+ add_action( 'admin_print_styles-appearance_page_custom-header', array( $this, 'force_twentythirteen_google_fonts_off' ), 99 );
363
+ }
364
  }
365
 
366
  function filters() {
367
  // add filter
368
+ add_filter( 'preprocess_comment', array( $this, 'preprocess_comment' ), 99 );
369
 
370
+ if ( false !== $this->conf['patch_incoming_pingback'] )
371
+ add_filter( 'pre_remote_source', array( $this, 'pre_remote_source' ), 10, 2 );
372
 
373
+ if ( false !== $this->conf['patch_wp_trim_excerpt'] ) {
374
+ add_filter( 'excerpt_length', array( $this, 'excerpt_mblength' ), 99 );
375
+ add_filter( 'excerpt_more', array( $this, 'excerpt_more' ), 9 );
376
  }
377
 
378
+ if ( false !== $this->conf['patch_get_comment_excerpt'] )
379
+ add_filter( 'get_comment_excerpt', array( $this, 'get_comment_excerpt' ) );
380
 
381
+ if ( false !== $this->conf['patch_sanitize_file_name'] )
382
+ add_filter( 'sanitize_file_name', array( $this, 'sanitize_file_name' ) );
383
 
384
+ if ( false !== $this->conf['patch_bp_create_excerpt'] ) {
385
+ add_filter( 'bp_create_excerpt', array( $this, 'bp_create_excerpt' ), 99 );
386
+ add_filter( 'bp_get_activity_content_body', array( $this, 'bp_get_activity_content_body' ), 99 );
387
  }
388
 
389
+ if ( method_exists( $this, 'wp_trim_words' ) && false !== $this->conf['patch_wp_trim_words'] )
390
+ add_filter( 'wp_trim_words', array( $this, 'wp_trim_words' ), 99, 4 );
391
 
392
  // add action
393
+ add_action( 'wp', array( $this, 'query_based_settings' ) );
394
 
395
+ if ( method_exists( $this, 'process_search_terms' ) && false !== $this->conf['patch_process_search_terms'] )
396
+ add_action( 'sanitize_comment_cookies', array( $this, 'process_search_terms' ) );
397
 
398
+ if ( method_exists( $this, 'wp_mail' ) && false !== $this->conf['patch_wp_mail'] )
399
+ add_action( 'phpmailer_init', array( $this, 'wp_mail' ) );
400
 
401
+ if ( method_exists( $this, 'admin_custom_css' ) && false !== $this->conf['patch_admin_custom_css'] ) {
402
+ add_action( 'admin_enqueue_scripts', array( $this, 'admin_custom_css' ), 99 );
403
+ add_action( 'customize_controls_enqueue_scripts', array( $this, 'admin_custom_css' ), 99 );
404
  }
405
 
406
+ if ( false !== $this->conf['patch_wplink_js'] )
407
+ add_action( 'wp_default_scripts', array( $this, 'wplink_js' ), 9 );
 
 
 
408
 
409
+ if ( false !== $this->conf['patch_word_count_js'] )
410
+ add_action( 'wp_default_scripts', array( $this, 'word_count_js' ), 9 );
411
 
412
+ if ( false !== $this->conf['patch_dashboard_recent_drafts'] )
413
+ add_action( 'wp_dashboard_setup', array( $this, 'dashboard_recent_drafts' ) );
414
 
415
+ add_action( 'after_setup_theme', array( $this, 'filters_after_setup_theme' ), 99 );
416
  }
417
 
418
  function mbfunctions_exist() {
419
  return (
420
+ function_exists( 'mb_convert_encoding' ) &&
421
+ function_exists( 'mb_convert_kana' ) &&
422
+ function_exists( 'mb_detect_encoding' ) &&
423
+ function_exists( 'mb_strcut' ) &&
424
+ function_exists( 'mb_strlen' )
425
  ) ? true : false;
426
  }
427
 
429
  global $wp_version;
430
  $required_version = $this->required_version;
431
 
432
+ if ( version_compare( substr( $wp_version, 0, strlen( $required_version ) ), $required_version, '<' ) ) {
433
+ deactivate_plugins( __FILE__ );
434
+ exit( sprintf( __( 'Sorry, WP Multibyte Patch requires WordPress %s or later.', 'wp-multibyte-patch' ), $required_version ) );
435
  }
436
+ elseif ( !$this->has_mbfunctions && $this->mbfunctions_required ) {
437
+ deactivate_plugins( __FILE__ );
438
+ exit( __( 'Sorry, WP Multibyte Patch requires <a href="http://www.php.net/manual/en/mbstring.installation.php" target="_blank">mbstring</a> functions.', 'wp-multibyte-patch' ) );
439
  }
440
  }
441
 
442
  function load_conf() {
443
  $wpmp_conf = array();
444
 
445
+ if ( file_exists( WP_CONTENT_DIR . '/wpmp-config.php' ) )
446
+ require_once WP_CONTENT_DIR . '/wpmp-config.php';
447
 
448
+ if ( is_multisite() ) {
449
  $blog_id = get_current_blog_id();
450
+ if ( file_exists( WP_CONTENT_DIR . '/wpmp-config-blog-' . $blog_id . '.php' ) )
451
+ require_once WP_CONTENT_DIR . '/wpmp-config-blog-' . $blog_id . '.php';
452
  }
453
 
454
+ $this->conf = array_merge( $this->conf, $wpmp_conf );
455
  }
456
 
457
  function __construct() {
458
  $this->load_conf();
459
+ $this->blog_encoding = get_option( 'blog_charset' );
460
 
461
  // mbstring functions are required for non UTF-8 blog.
462
+ if ( !preg_match( "/^utf-?8$/i", $this->blog_encoding ) )
463
  $this->mbfunctions_required = true;
464
 
465
  $this->has_mbfunctions = $this->mbfunctions_exist();
466
+ $this->has_mb_strlen = function_exists( 'mb_strlen' );
467
+ $this->debug_suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
468
 
469
+ load_textdomain( $this->textdomain, plugin_dir_path( __FILE__ ) . $this->lang_dir . '/' . $this->textdomain . '-' . get_locale() . '.mo' );
470
+ register_activation_hook( __FILE__, array( $this, 'activation_check' ) );
471
  $this->filters();
472
  }
473
  }
474
 
475
+ if ( defined( 'WP_PLUGIN_URL' ) ) {
476
+ if ( file_exists( dirname( __FILE__ ) . '/ext/' . get_locale() . '/class.php' ) ) {
477
+ require_once dirname( __FILE__ ) . '/ext/' . get_locale() . '/class.php';
478
+ $GLOBALS['wpmp'] = new multibyte_patch_ext();
 
 
479
  }
480
+ elseif ( file_exists( dirname( __FILE__ ) . '/ext/default/class.php' ) ) {
481
+ require_once dirname( __FILE__ ) . '/ext/default/class.php';
482
+ $GLOBALS['wpmp'] = new multibyte_patch_ext();
483
  }
484
  else
485
+ $GLOBALS['wpmp'] = new multibyte_patch();
486
  }
 
 
wpmp-config-sample-ja.php CHANGED
@@ -30,7 +30,7 @@ $wpmp_conf['excerpt_mblength'] = 110;
30
  * この設定は the_excerpt() とその関連の抜粋系関数に適用されます。
31
  * この設定は $wpmp_conf['patch_wp_trim_excerpt'] が false の場合は無効となります。
32
  */
33
- $wpmp_conf['excerpt_more'] = ' [...]';
34
 
35
  /**
36
  * get_comment_excerpt() 抜粋の最大文字数
@@ -80,7 +80,7 @@ $wpmp_conf['bp_excerpt_mblength'] = 110;
80
  * この設定は BuddyPress の bp_create_excerpt() (アクティビティストリームの抜粋で利用) に適用されます。
81
  * この設定は $wpmp_conf['patch_bp_create_excerpt'] が false の場合は無効となります。
82
  */
83
- $wpmp_conf['bp_excerpt_more'] = ' [...]';
84
 
85
 
86
  /* 機能を個別に有効化、無効化できます。有効化するには true を、無効化するには false を指定してください。 */
@@ -97,6 +97,6 @@ $wpmp_conf['patch_wplink_js'] = true;
97
  $wpmp_conf['patch_word_count_js'] = true;
98
  $wpmp_conf['patch_force_character_count'] = true;
99
  $wpmp_conf['patch_force_twentytwelve_open_sans_off'] = true;
 
100
  $wpmp_conf['patch_sanitize_file_name'] = true;
101
  $wpmp_conf['patch_bp_create_excerpt'] = false;
102
-
30
  * この設定は the_excerpt() とその関連の抜粋系関数に適用されます。
31
  * この設定は $wpmp_conf['patch_wp_trim_excerpt'] が false の場合は無効となります。
32
  */
33
+ $wpmp_conf['excerpt_more'] = ' [&hellip;]';
34
 
35
  /**
36
  * get_comment_excerpt() 抜粋の最大文字数
80
  * この設定は BuddyPress の bp_create_excerpt() (アクティビティストリームの抜粋で利用) に適用されます。
81
  * この設定は $wpmp_conf['patch_bp_create_excerpt'] が false の場合は無効となります。
82
  */
83
+ $wpmp_conf['bp_excerpt_more'] = ' [&hellip;]';
84
 
85
 
86
  /* 機能を個別に有効化、無効化できます。有効化するには true を、無効化するには false を指定してください。 */
97
  $wpmp_conf['patch_word_count_js'] = true;
98
  $wpmp_conf['patch_force_character_count'] = true;
99
  $wpmp_conf['patch_force_twentytwelve_open_sans_off'] = true;
100
+ $wpmp_conf['patch_force_twentythirteen_google_fonts_off'] = false;
101
  $wpmp_conf['patch_sanitize_file_name'] = true;
102
  $wpmp_conf['patch_bp_create_excerpt'] = false;
 
wpmp-load.php CHANGED
@@ -11,6 +11,5 @@
11
 
12
  /**
13
  */
14
- if(!defined('WP_INSTALLING') && defined('WPMU_PLUGIN_DIR') && defined('WPMU_PLUGIN_URL'))
15
- require_once(WPMU_PLUGIN_DIR . '/wp-multibyte-patch/wp-multibyte-patch.php');
16
- ?>
11
 
12
  /**
13
  */
14
+ if ( !defined( 'WP_INSTALLING' ) && defined( 'WPMU_PLUGIN_DIR' ) && defined( 'WPMU_PLUGIN_URL' ) )
15
+ require_once WPMU_PLUGIN_DIR . '/wp-multibyte-patch/wp-multibyte-patch.php';