Version Description
Download this release
Release Info
Developer | jim912 |
Plugin | PS Disable Auto Formatting |
Version | 1.0.7 |
Comparing to | |
See all releases |
Code changes from version 1.0.6 to 1.0.7
- js/330/ps_editor.js +170 -0
- ps_disable_auto_formatting.php +310 -307
- readme.txt +4 -2
js/330/ps_editor.js
ADDED
@@ -0,0 +1,170 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
var switchEditors = {
|
3 |
+
|
4 |
+
switchto: function(el) {
|
5 |
+
var aid = el.id, l = aid.length, id = aid.substr(0, l - 5), mode = aid.substr(l - 4);
|
6 |
+
|
7 |
+
this.go(id, mode);
|
8 |
+
},
|
9 |
+
|
10 |
+
go: function(id, mode) { // mode can be 'html', 'tmce', or 'toggle'
|
11 |
+
id = id || 'content';
|
12 |
+
mode = mode || 'toggle';
|
13 |
+
|
14 |
+
var t = this, ed = tinyMCE.get(id), wrap_id, txtarea_el, dom = tinymce.DOM;
|
15 |
+
|
16 |
+
wrap_id = 'wp-'+id+'-wrap';
|
17 |
+
txtarea_el = dom.get(id);
|
18 |
+
|
19 |
+
if ( 'toggle' == mode ) {
|
20 |
+
if ( ed && !ed.isHidden() )
|
21 |
+
mode = 'html';
|
22 |
+
else
|
23 |
+
mode = 'tmce';
|
24 |
+
}
|
25 |
+
|
26 |
+
if ( 'tmce' == mode || 'tinymce' == mode ) {
|
27 |
+
if ( ed && ! ed.isHidden() )
|
28 |
+
return false;
|
29 |
+
|
30 |
+
if ( typeof(QTags) != 'undefined' )
|
31 |
+
QTags.closeAllTags(id);
|
32 |
+
|
33 |
+
if ( tinyMCEPreInit.mceInit[id] && tinyMCEPreInit.mceInit[id].wpautop )
|
34 |
+
txtarea_el.value = t.wpautop( txtarea_el.value );
|
35 |
+
|
36 |
+
if ( ed ) {
|
37 |
+
ed.show();
|
38 |
+
} else {
|
39 |
+
ed = new tinymce.Editor(id, tinyMCEPreInit.mceInit[id]);
|
40 |
+
ed.render();
|
41 |
+
}
|
42 |
+
|
43 |
+
dom.removeClass(wrap_id, 'html-active');
|
44 |
+
dom.addClass(wrap_id, 'tmce-active');
|
45 |
+
setUserSetting('editor', 'tinymce');
|
46 |
+
|
47 |
+
} else if ( 'html' == mode ) {
|
48 |
+
|
49 |
+
if ( ed && ed.isHidden() )
|
50 |
+
return false;
|
51 |
+
|
52 |
+
if ( ed ) {
|
53 |
+
txtarea_el.style.height = ed.getContentAreaContainer().offsetHeight + 20 + 'px';
|
54 |
+
ed.hide();
|
55 |
+
}
|
56 |
+
|
57 |
+
dom.removeClass(wrap_id, 'tmce-active');
|
58 |
+
dom.addClass(wrap_id, 'html-active');
|
59 |
+
setUserSetting('editor', 'html');
|
60 |
+
}
|
61 |
+
return false;
|
62 |
+
},
|
63 |
+
|
64 |
+
_wp_Nop : function(content) {
|
65 |
+
var blocklist1, blocklist2;
|
66 |
+
|
67 |
+
// Protect pre|script tags
|
68 |
+
if ( content.indexOf('<pre') != -1 || content.indexOf('<script') != -1 ) {
|
69 |
+
content = content.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) {
|
70 |
+
a = a.replace(/<br ?\/?>(\r\n|\n)?/g, '<wp_temp>');
|
71 |
+
return a.replace(/<\/?p( [^>]*)?>(\r\n|\n)?/g, '<wp_temp>');
|
72 |
+
});
|
73 |
+
}
|
74 |
+
|
75 |
+
// Pretty it up for the source editor
|
76 |
+
var blocklist1 = 'blockquote|ul|ol|li|table|thead|tbody|tr|th|td|div|h[1-6]|p';
|
77 |
+
content = content.replace(new RegExp('\\s*</('+blocklist1+')>\\s*', 'mg'), '</$1>\n');
|
78 |
+
content = content.replace(new RegExp('\\s*<(('+blocklist1+')[^>]*)>', 'mg'), '\n<$1>');
|
79 |
+
|
80 |
+
content = content.replace(new RegExp('<p( [^>]*)?>[\\s\\n]*<(/?script[^>]*)>', 'mg'), '\n<$2>');
|
81 |
+
content = content.replace(new RegExp('<(/?script[^>]*)>[\\s\\n]*</p>', 'mg'), '\n<$1>');
|
82 |
+
|
83 |
+
// Fix some block element newline issues
|
84 |
+
content = content.replace(new RegExp('\\s*<div', 'mg'), '\n<div');
|
85 |
+
content = content.replace(new RegExp('</div>\\s*', 'mg'), '</div>\n');
|
86 |
+
content = content.replace(new RegExp('\\s*\\[caption([^\\[]+)\\[/caption\\]\\s*', 'gi'), '\n\n[caption$1[/caption]\n\n');
|
87 |
+
content = content.replace(new RegExp('caption\\]\\n\\n+\\[caption', 'g'), 'caption]\n\n[caption');
|
88 |
+
|
89 |
+
var blocklist2 = 'blockquote|ul|ol|li|table|thead|tr|th|td|h[1-6]|pre';
|
90 |
+
content = content.replace(new RegExp('\\s*<(('+blocklist2+') ?[^>]*)\\s*>', 'mg'), '\n<$1>');
|
91 |
+
content = content.replace(new RegExp('\\s*</('+blocklist2+')>\\s*', 'mg'), '</$1>\n');
|
92 |
+
content = content.replace(new RegExp('<li([^>]*)>', 'g'), '\t<li$1>');
|
93 |
+
|
94 |
+
if ( content.indexOf('<object') != -1 ) {
|
95 |
+
content = content.replace(new RegExp('\\s*<param([^>]*)>\\s*', 'mg'), "<param$1>");
|
96 |
+
content = content.replace(new RegExp('\\s*</embed>\\s*', 'mg'), '</embed>');
|
97 |
+
}
|
98 |
+
|
99 |
+
// Unmark special paragraph closing tags
|
100 |
+
content = content.replace(new RegExp('</p#>', 'g'), '</p>\n');
|
101 |
+
content = content.replace(new RegExp('\\s*(<p [^>]+>.*</p>)', 'mg'), '\n$1');
|
102 |
+
content = content.replace(new RegExp('<p>\\s*</p>', 'mg'), "<p> </p>\n");
|
103 |
+
|
104 |
+
// put back the line breaks in pre|script
|
105 |
+
content = content.replace(/<wp_temp>/g, '\n');
|
106 |
+
|
107 |
+
return content;
|
108 |
+
},
|
109 |
+
|
110 |
+
_wp_Autop : function(pee) {
|
111 |
+
// filtered when switching html to visual
|
112 |
+
var blocklist = 'table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6]|script';
|
113 |
+
var blocklist2 = 'table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|h[1-6]|script';
|
114 |
+
pee = pee + "\n\n";
|
115 |
+
pee = pee.replace(new RegExp('(<(?:'+blocklist+')[^>]*>)', 'gi'), "\n$1");
|
116 |
+
pee = pee.replace(new RegExp('(</(?:'+blocklist+')>)', 'gi'), "$1\n\n");
|
117 |
+
pee = pee.replace(new RegExp("\\r\\n|\\r", 'g'), "\n");
|
118 |
+
pee = pee.replace(new RegExp("\\n\\s*\\n+", 'g'), "\n\n");
|
119 |
+
pee = pee.replace(new RegExp('([\\s\\S]+?)\\n\\n', 'mg'), "<p>$1</p>\n");
|
120 |
+
pee = pee.replace(new RegExp('<p( [^>]*)?>[\\s\\n]*</p>', 'mg'), "<p$1> </p>\n");
|
121 |
+
pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')[^>]*>)\\s*</p>', 'gi'), "$1");
|
122 |
+
pee = pee.replace(new RegExp("<p>(<li.+?)</p>", 'gi'), "$1");
|
123 |
+
pee = pee.replace(new RegExp("<p ?[^>]*>(<!--(.*)?-->)", 'gi'), "$1");
|
124 |
+
pee = pee.replace(new RegExp("(<!--(.*)?-->)</p>", 'gi'), "$1");
|
125 |
+
pee = pee.replace(new RegExp('<p>\\s*<blockquote([^>]*)>', 'gi'), "<blockquote$1><p>");
|
126 |
+
pee = pee.replace(new RegExp('</blockquote>\\s*</p>', 'gi'), '</p></blockquote>');
|
127 |
+
pee = pee.replace(new RegExp('<p>[\\s\\n]*(<(?:'+blocklist+')[^>]*>)', 'gi'), "$1");
|
128 |
+
pee = pee.replace(new RegExp('<p>[\\s\\n]*(</(?:'+blocklist2+')[^>]*>)', 'gi'), "$1");
|
129 |
+
pee = pee.replace(new RegExp('(<(?:'+blocklist2+')[^>]*>)[\\s\\n]*</p>', 'gi'), "$1");
|
130 |
+
pee = pee.replace(new RegExp('(</(?:'+blocklist+')[^>]*>)[\\s\\n]*</p>', 'gi'), "$1");
|
131 |
+
pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*<br />', 'gi'), "$1");
|
132 |
+
pee = pee.replace(new RegExp('<br />(\\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)', 'gi'), '$1');
|
133 |
+
pee = pee.replace(new RegExp('(?:<p>|<br ?/?>)*\\s*\\[caption([^\\[]+)\\[/caption\\]\\s*(?:</p>|<br ?/?>)*', 'gi'), '[caption$1[/caption]');
|
134 |
+
|
135 |
+
// Fix the pre|script tags
|
136 |
+
pee = pee.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) {
|
137 |
+
a = a.replace(/<br ?\/?>[\r\n]*/g, '\n');
|
138 |
+
return a.replace(/<\/?p( [^>]*)?>[\r\n]*/g, '\n');
|
139 |
+
});
|
140 |
+
|
141 |
+
return pee;
|
142 |
+
},
|
143 |
+
|
144 |
+
pre_wpautop : function(content) {
|
145 |
+
var t = this, o = { o: t, data: content, unfiltered: content },
|
146 |
+
q = typeof(jQuery) != 'undefined';
|
147 |
+
|
148 |
+
if ( q )
|
149 |
+
jQuery('body').trigger('beforePreWpautop', [o]);
|
150 |
+
o.data = t._wp_Nop(o.data);
|
151 |
+
if ( q )
|
152 |
+
jQuery('body').trigger('afterPreWpautop', [o]);
|
153 |
+
|
154 |
+
return o.data;
|
155 |
+
},
|
156 |
+
|
157 |
+
wpautop : function(pee) {
|
158 |
+
var t = this, o = { o: t, data: pee, unfiltered: pee },
|
159 |
+
q = typeof(jQuery) != 'undefined';
|
160 |
+
|
161 |
+
if ( q )
|
162 |
+
jQuery('body').trigger('beforeWpautop', [o]);
|
163 |
+
o.data = t._wp_Autop(o.data);
|
164 |
+
if ( q )
|
165 |
+
jQuery('body').trigger('afterWpautop', [o]);
|
166 |
+
|
167 |
+
return o.data;
|
168 |
+
}
|
169 |
+
}
|
170 |
+
|
ps_disable_auto_formatting.php
CHANGED
@@ -1,307 +1,310 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Plugin Name: PS Disable Auto Formatting
|
4 |
-
Plugin URI: http://www.web-strategy.jp/wp_plugin/ps_disable_auto_formatting/
|
5 |
-
Description: PS Disable Auto Formatting is able to disable function auto formatting (wpautop) and save <p> and <br /> formatted content.
|
6 |
-
Version: 1.0.
|
7 |
-
Author: Hitoshi Omagari
|
8 |
-
Author URI: http://www.web-strategy.jp/
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
'
|
16 |
-
'
|
17 |
-
'
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
add_action( '
|
28 |
-
|
29 |
-
add_filter( '
|
30 |
-
|
31 |
-
add_action( 'media_buttons', array( &$this, '
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
}
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
$
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
$this->
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
}
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
}
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
}
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
$
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
$error_mes = __(
|
194 |
-
break;
|
195 |
-
}
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
$
|
201 |
-
}
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
<?php
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
</
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
$
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: PS Disable Auto Formatting
|
4 |
+
Plugin URI: http://www.web-strategy.jp/wp_plugin/ps_disable_auto_formatting/
|
5 |
+
Description: PS Disable Auto Formatting is able to disable function auto formatting (wpautop) and save <p> and <br /> formatted content.
|
6 |
+
Version: 1.0.7
|
7 |
+
Author: Hitoshi Omagari
|
8 |
+
Author URI: http://www.web-strategy.jp/
|
9 |
+
License: GPLv2 or later
|
10 |
+
*/
|
11 |
+
|
12 |
+
class ps_disable_auto_formatting {
|
13 |
+
|
14 |
+
var $setting_items = array(
|
15 |
+
'content formatting' => 'the_content',
|
16 |
+
'comment formatting' => 'comment_text',
|
17 |
+
'excerpt formatting' => 'the_excerpt',
|
18 |
+
'term description formatting' => 'term_description',
|
19 |
+
);
|
20 |
+
|
21 |
+
var $mce_version = '20080121';
|
22 |
+
|
23 |
+
function __construct() {
|
24 |
+
global $wp_version;
|
25 |
+
|
26 |
+
if ( version_compare( $wp_version, '2.5', '>=' ) ) {
|
27 |
+
add_action( 'init' , array( &$this, 'disable_auto_formatting_init' ) );
|
28 |
+
add_action( 'admin_menu' , array( &$this, 'add_disable_formatting_setting_page') );
|
29 |
+
add_filter( 'print_scripts_array' , array( &$this, 'rewrite_default_script' ) );
|
30 |
+
add_filter( 'wp_insert_post_data' , array( &$this, 'formatting_quickpress_post' ) );
|
31 |
+
add_action( 'media_buttons' , array( &$this, 'check_edit_mode_and_add_richedit_pre' ), 9 );
|
32 |
+
add_action( 'media_buttons' , array( &$this, 'delete_filtering_wp_richedit_pre' ) );
|
33 |
+
} else {
|
34 |
+
add_action('admin_notices' , array( &$this, 'version_too_old' ) );
|
35 |
+
}
|
36 |
+
}
|
37 |
+
|
38 |
+
|
39 |
+
function ps_disable_auto_formatting() {
|
40 |
+
$this->__construct();
|
41 |
+
}
|
42 |
+
|
43 |
+
|
44 |
+
function disable_auto_formatting_init() {
|
45 |
+
$locale = get_locale();
|
46 |
+
$lang_file = dirname( __file__ ) . '/language/ps_disable_auto_formatting-' . $locale . '.mo';
|
47 |
+
|
48 |
+
if ( file_exists( $lang_file ) ) {
|
49 |
+
load_textdomain( 'ps_disable_auto_formatting', $lang_file );
|
50 |
+
}
|
51 |
+
|
52 |
+
$this->option_settings = get_option( 'ps_disable_auto_formatting' );
|
53 |
+
|
54 |
+
if ( $this->option_settings === false ) {
|
55 |
+
$this->set_default_settings();
|
56 |
+
$this->option_settings = get_option( 'ps_disable_auto_formatting' );
|
57 |
+
} elseif ( ! $this->option_settings ) {
|
58 |
+
$this->option_settings = array();
|
59 |
+
}
|
60 |
+
$this->delete_default_filters();
|
61 |
+
}
|
62 |
+
|
63 |
+
|
64 |
+
function delete_default_filters() {
|
65 |
+
global $wp_filter;
|
66 |
+
|
67 |
+
foreach ( $this->option_settings as $hook ) {
|
68 |
+
if ( $hook == 'comment_text' ) {
|
69 |
+
$priority = 30;
|
70 |
+
} else {
|
71 |
+
$priority = 10;
|
72 |
+
}
|
73 |
+
remove_filter( $hook, 'wpautop', $priority );
|
74 |
+
if ( $hook == 'the_content' ) {
|
75 |
+
foreach ( array_keys( $wp_filter['the_content'][10] ) as $hook_name ) {
|
76 |
+
if ( strpos( $hook_name, 'tam_contact_form_sevenwpautop_substitute' ) !== false ) {
|
77 |
+
remove_filter( 'the_content', $hook_name );
|
78 |
+
}
|
79 |
+
}
|
80 |
+
}
|
81 |
+
}
|
82 |
+
}
|
83 |
+
|
84 |
+
|
85 |
+
function set_default_settings() {
|
86 |
+
$default = array( 'the_content' );
|
87 |
+
update_option( 'ps_disable_auto_formatting', $default );
|
88 |
+
}
|
89 |
+
|
90 |
+
|
91 |
+
function rewrite_default_script( $todo ) {
|
92 |
+
global $wp_version, $wp_scripts;
|
93 |
+
|
94 |
+
if ( version_compare( $wp_version, '3.2', '>' ) ) {
|
95 |
+
$scripyt_src = get_option( 'siteurl' ) . '/' . str_replace( str_replace( '\\', '/', ABSPATH ), '', str_replace( '\\', '/', dirname( __file__ ) ) ) . '/js/330/ps_editor.js';
|
96 |
+
} elseif ( version_compare( $wp_version, '2.8', '>=' ) ) {
|
97 |
+
$scripyt_src = get_option( 'siteurl' ) . '/' . str_replace( str_replace( '\\', '/', ABSPATH ), '', str_replace( '\\', '/', dirname( __file__ ) ) ) . '/js/280/ps_editor.js';
|
98 |
+
} elseif ( version_compare( $wp_version, '2.7', '>=' ) ) {
|
99 |
+
$scripyt_src = get_option( 'siteurl' ) . '/' . str_replace( str_replace( '\\', '/', ABSPATH ), '', str_replace( '\\', '/', dirname( __file__ ) ) ) . '/js/270/ps_editor.js';
|
100 |
+
} else {
|
101 |
+
$scripyt_src = get_option( 'siteurl' ) . '/' . str_replace( str_replace( '\\', '/', ABSPATH ), '', str_replace( '\\', '/', dirname( __file__ ) ) ) . '/js/250/ps_editor.js';
|
102 |
+
if ( version_compare( $wp_version, '2.6', '>=' ) ) {
|
103 |
+
$wp_scripts->registered['editor_functions']->src = $scripyt_src;
|
104 |
+
} else {
|
105 |
+
$wp_scripts->scripts['editor_functions']->src = $scripyt_src;
|
106 |
+
}
|
107 |
+
}
|
108 |
+
$wp_scripts->add( 'ps_editor', $scripyt_src, false, $this->mce_version );
|
109 |
+
$key = array_search( 'editor', $todo );
|
110 |
+
if ( $key !== false ) {
|
111 |
+
if ( version_compare( $wp_version, '2.7', '>=' ) ) {
|
112 |
+
$todo[$key] = 'ps_editor';
|
113 |
+
} else {
|
114 |
+
unset( $todo[$key] );
|
115 |
+
}
|
116 |
+
}
|
117 |
+
return $todo;
|
118 |
+
}
|
119 |
+
|
120 |
+
|
121 |
+
function formatting_quickpress_post( $data ) {
|
122 |
+
global $action;
|
123 |
+
|
124 |
+
if ( in_array( $action, array( 'post-quickpress-publish', 'post-quickpress-save' ) ) ) {
|
125 |
+
if ( empty( $_POST['quickpress_post_ID'] ) ) {
|
126 |
+
$data['post_content'] = wpautop( $data['post_content'] );
|
127 |
+
}
|
128 |
+
}
|
129 |
+
return $data;
|
130 |
+
}
|
131 |
+
|
132 |
+
|
133 |
+
function delete_filtering_wp_richedit_pre() {
|
134 |
+
remove_filter( 'the_editor_content', 'wp_richedit_pre' );
|
135 |
+
}
|
136 |
+
|
137 |
+
|
138 |
+
function check_edit_mode_and_add_richedit_pre() {
|
139 |
+
global $wp_filter;
|
140 |
+
if ( isset( $wp_filter['the_editor_content'][10]['wp_richedit_pre'] ) ) {
|
141 |
+
add_filter( 'the_editor_content', array( &$this, 'ps_richedit_pre' ) );
|
142 |
+
}
|
143 |
+
}
|
144 |
+
|
145 |
+
|
146 |
+
function ps_richedit_pre( $text ) {
|
147 |
+
if ( empty($text) ) return apply_filters('richedit_pre', '');
|
148 |
+
|
149 |
+
$output = convert_chars($text);
|
150 |
+
$output = htmlspecialchars($output, ENT_NOQUOTES);
|
151 |
+
|
152 |
+
return apply_filters('richedit_pre', $output);
|
153 |
+
}
|
154 |
+
|
155 |
+
|
156 |
+
function add_disable_formatting_setting_page() {
|
157 |
+
add_options_page( 'PS Disable Auto Formatting', __( 'Auto Formatting', 'ps_disable_auto_formatting' ), 'manage_options', basename( __FILE__ ), array( &$this, 'output_disable_formatting_setting_page') );
|
158 |
+
}
|
159 |
+
|
160 |
+
|
161 |
+
function output_disable_formatting_setting_page() {
|
162 |
+
global $wpdb, $wp_error;
|
163 |
+
if( isset( $_POST['_wpnonce'] ) && $_POST['_wpnonce'] ) {
|
164 |
+
check_admin_referer();
|
165 |
+
|
166 |
+
if ( isset( $_POST['batch_formatting'] ) && $_POST['batch_formatting'] ) {
|
167 |
+
if ( $_POST['allow_batch_formatting'] ) {
|
168 |
+
$time_limit = sprintf( '%04d-%02d-%02d %02d:%02d:00', $_POST['aa'], $_POST['mm'], $_POST['jj'], $_POST['hh'], $_POST['mn'] );
|
169 |
+
$sql = "
|
170 |
+
SELECT `ID`
|
171 |
+
FROM $wpdb->posts
|
172 |
+
WHERE `post_status` IN ( 'publish', 'draft', 'pending' )
|
173 |
+
AND `post_type` IN ( 'post', 'page' )
|
174 |
+
AND `post_modified` < '$time_limit'
|
175 |
+
";
|
176 |
+
$formatting_posts = $wpdb->get_results( $sql, ARRAY_A );
|
177 |
+
$formatted_posts = array();
|
178 |
+
|
179 |
+
if ( $formatting_posts ) {
|
180 |
+
foreach ( $formatting_posts as $row ) {
|
181 |
+
$data = array();
|
182 |
+
$post = get_post( $row['ID'] );
|
183 |
+
$data['post_content'] = wpautop( $post->post_content );
|
184 |
+
if ( $post->post_content_filtered ) {
|
185 |
+
$data['post_content_filtered'] = wpautop( $post->post_content_filtered );
|
186 |
+
}
|
187 |
+
$data['post_modified_gmt'] = current_time( 'mysql', 1 );
|
188 |
+
$data['post_modified'] = current_time( 'mysql' );
|
189 |
+
|
190 |
+
do_action( 'pre_post_update', $post->ID );
|
191 |
+
if ( false === $wpdb->update( $wpdb->posts, $data, array( 'ID' => $post->ID ) ) ) {
|
192 |
+
if ( $wp_error ) {
|
193 |
+
$error_mes = new WP_Error('db_update_error', __('Could not update post in the database'), $wpdb->last_error);
|
194 |
+
break;
|
195 |
+
} else {
|
196 |
+
$error_mes = __( 'Database is not found.', 'ps_disable_auto_formatting' );
|
197 |
+
break;
|
198 |
+
}
|
199 |
+
}
|
200 |
+
$formatted_posts[] = $row['ID'];
|
201 |
+
}
|
202 |
+
if ( ! $error_mes ) {
|
203 |
+
$batch_ret = true;
|
204 |
+
}
|
205 |
+
} else {
|
206 |
+
$error_mes = __( 'No formatting post or page exists.', 'ps_disable_auto_formatting' );
|
207 |
+
}
|
208 |
+
} else {
|
209 |
+
$error_mes = __( 'Require checked allow batch formatting.', 'ps_disable_auto_formatting' );
|
210 |
+
}
|
211 |
+
} else {
|
212 |
+
if ( isset( $_POST['ps_disable_auto_formatting'] ) ) {
|
213 |
+
$post_data = stripslashes_deep( $_POST['ps_disable_auto_formatting'] );
|
214 |
+
} else {
|
215 |
+
$post_data = array();
|
216 |
+
}
|
217 |
+
foreach ( $post_data as $key => $func ) {
|
218 |
+
if ( ! in_array( $func, $this->setting_items) ) {
|
219 |
+
unset( $_POST['ps_disable_auto_formatting'][$key] );
|
220 |
+
}
|
221 |
+
}
|
222 |
+
$ret = update_option( 'ps_disable_auto_formatting', $post_data );
|
223 |
+
if ( $ret ) {
|
224 |
+
$this->option_settings = get_option( 'ps_disable_auto_formatting' );
|
225 |
+
}
|
226 |
+
}
|
227 |
+
}
|
228 |
+
|
229 |
+
?>
|
230 |
+
<div class=wrap>
|
231 |
+
<?php if ( function_exists( 'screen_icon' ) ) { screen_icon(); } ?>
|
232 |
+
<h2><?php _e( 'Auto Formatting', 'ps_disable_auto_formatting' ); ?></h2>
|
233 |
+
<?php if ( isset( $ret ) && $ret ) { ?>
|
234 |
+
<div id="message" class="updated">
|
235 |
+
<p><?php _e('The settings has changed successfully.', 'ps_disable_auto_formatting' );?></p>
|
236 |
+
</div>
|
237 |
+
<?php } elseif ( isset( $batch_ret ) && $batch_ret ) { ?>
|
238 |
+
<div id="message" class="updated">
|
239 |
+
<p><?php printf( __( 'Batch fomatting process has completed. total %d posts formatted.', 'ps_disable_auto_formatting' ), count( $formatting_posts ) );?></p>
|
240 |
+
</div>
|
241 |
+
<?php } elseif ( isset( $error_mes ) && $error_mes ) { ?>
|
242 |
+
<div id="notice" class="error">
|
243 |
+
<p><?php echo wp_specialchars( $error_mes ); ?></p>
|
244 |
+
</div>
|
245 |
+
<?php } elseif ( isset( $_POST['ps_disable_auto_formatting'] ) && $_POST['ps_disable_auto_formatting'] && isset( $ret ) && ! $ret ) { ?>
|
246 |
+
<div id="notice" class="error">
|
247 |
+
<p><?php _e('The settings has not been changed. There were no changes or failed to update the data base.', 'ps_disable_auto_formatting' );?></p>
|
248 |
+
</div>
|
249 |
+
<?php } ?>
|
250 |
+
<form method="post" action="">
|
251 |
+
<?php wp_nonce_field(); ?>
|
252 |
+
<table class="form-table">
|
253 |
+
<?php foreach( $this->setting_items as $id => $func ) { ?>
|
254 |
+
<tr>
|
255 |
+
<th><?php _e( $id, 'ps_disable_auto_formatting' ); ?></th>
|
256 |
+
<td>
|
257 |
+
<input type="checkbox" id="ps_disable_auto_formatting_<?php echo $func ?>" name="ps_disable_auto_formatting[]" value="<?php echo $func ?>"<?php if ( in_array( $func, $this->option_settings ) ) { echo ' checked="checked"'; } ?> />
|
258 |
+
<label for="ps_disable_auto_formatting_<?php echo $func ?>"><?php _e( 'disable', 'ps_disable_auto_formatting' ); ?></label>
|
259 |
+
</td>
|
260 |
+
</tr>
|
261 |
+
<?php } ?>
|
262 |
+
</table>
|
263 |
+
<p class="submit">
|
264 |
+
<input type="submit" name="ps_disable_auto_formatting_submit" class="button-primary" value="<?php _e( 'Save Changes' ); ?>" />
|
265 |
+
</p>
|
266 |
+
<?php if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) ) { ?>
|
267 |
+
<h3><?php _e( 'Batch formatting for past posts' ,'ps_disable_auto_formatting' ); ?></h3>
|
268 |
+
<?php _e( '<p>To make it display the same as the format before run this plug-in,
|
269 |
+
automatic operation process to the specified period of the posts.<br />
|
270 |
+
Even if some unexpected errors occur, the data is restorable because
|
271 |
+
rivision on the processed post is made.<br />
|
272 |
+
This process is safe even if you do two or more times, perhaps. We cannot assure though.<br />
|
273 |
+
* It is strongly recommended to take the <a href="http://codex.wordpress.org/Backing_Up_Your_Database" title="Backing Up Your Database">backup your database</a> before processing.</p>' ,'ps_disable_auto_formatting' ); ?>
|
274 |
+
<table class="form-table">
|
275 |
+
<tr>
|
276 |
+
<th><?php _e( 'Formatting before' ,'ps_disable_auto_formatting' ); ?></th>
|
277 |
+
<td>
|
278 |
+
<?php global $comment; $comment->comment_date = current_time( 'mysql' ); touch_time( 0, 0, 0, 1 ); ?><br />
|
279 |
+
<?php _e( '* Formatting posts and pages are modified before this time.' ,'ps_disable_auto_formatting' ); ?>
|
280 |
+
</td>
|
281 |
+
</tr>
|
282 |
+
</table>
|
283 |
+
<div>
|
284 |
+
<span class="submit"><input type="submit" name="batch_formatting" value="<?php _e( 'Batch formatting', 'ps_disable_auto_formatting' ); ?>" /></span>
|
285 |
+
<input type="checkbox" id="allow_batch_formatting" name="allow_batch_formatting" value="1" />
|
286 |
+
<label for="allow_batch_formatting"><?php _e( 'Allow batch formatting', 'ps_disable_auto_formatting' ); ?></label>
|
287 |
+
</div>
|
288 |
+
<?php } ?>
|
289 |
+
</form>
|
290 |
+
<p><?php _e( 'If you have any problems or find a bug in this plugin, please <a href="http://www.web-strategy.jp/wp_plugin/ps_disable_auto_formatting/#postcomment">report to us</a>.' , 'ps_disable_auto_formatting' ); ?></p>
|
291 |
+
</div>
|
292 |
+
<?php
|
293 |
+
}
|
294 |
+
|
295 |
+
|
296 |
+
function version_too_old() {
|
297 |
+
global $wp_version;
|
298 |
+
echo '<div class="updated fade"><p>' . sprintf( __( 'Sorry, Your WordPress (version %s) is old to use PS Disable Auto Formatting plugin. Please upgrade to version 2.5 or higher.', 'ps_disable_auto_formatting' ), $wp_version ) . '</p></div>';
|
299 |
+
$active_plugins = get_option('active_plugins');
|
300 |
+
$search_plugin = str_replace( str_replace( '\\', '/', ABSPATH . PLUGINDIR . '/' ), '', str_replace( '\\', '/', __file__ ) );
|
301 |
+
$key = array_search( $search_plugin, $active_plugins );
|
302 |
+
if ( $key !== false ) {
|
303 |
+
unset( $active_plugins[$key] );
|
304 |
+
}
|
305 |
+
update_option( 'active_plugins', $active_plugins );
|
306 |
+
}
|
307 |
+
|
308 |
+
} // class end
|
309 |
+
|
310 |
+
$ps_disable_auto_formatting =& new ps_disable_auto_formatting();
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: jim912
|
3 |
Tags: auto formatting, formatting, format, paragraph, linebreak, wpautop
|
4 |
Requires at least: 2.5
|
5 |
-
Tested up to: 3.
|
6 |
-
Stable tag: 1.0.
|
7 |
|
8 |
Stops the automatic forming and the HTML tag removal in the html mode of WordPress, and generates a natural paragraph and changing line.
|
9 |
|
@@ -65,6 +65,8 @@ To prevent the operational error, the batch processing is not done if there is n
|
|
65 |
Please check "Permit batch formatting" check box.
|
66 |
|
67 |
== Changelog ==
|
|
|
|
|
68 |
* **1.0.6**
|
69 |
* fix : bug fix
|
70 |
* **1.0.5**
|
2 |
Contributors: jim912
|
3 |
Tags: auto formatting, formatting, format, paragraph, linebreak, wpautop
|
4 |
Requires at least: 2.5
|
5 |
+
Tested up to: 3.3
|
6 |
+
Stable tag: 1.0.7
|
7 |
|
8 |
Stops the automatic forming and the HTML tag removal in the html mode of WordPress, and generates a natural paragraph and changing line.
|
9 |
|
65 |
Please check "Permit batch formatting" check box.
|
66 |
|
67 |
== Changelog ==
|
68 |
+
* **1.0.7**
|
69 |
+
* Compatible with WordPress 3.3
|
70 |
* **1.0.6**
|
71 |
* fix : bug fix
|
72 |
* **1.0.5**
|