Version Description
Download this release
Release Info
Developer | jim912 |
Plugin | PS Disable Auto Formatting |
Version | 0.9.1 |
Comparing to | |
See all releases |
Code changes from version 0.9.0 to 0.9.1
- js/ps_editor.js +157 -156
- ps_disable_auto_formatting.php +17 -9
- readme.txt +3 -0
js/ps_editor.js
CHANGED
@@ -1,156 +1,157 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
content = content.replace(new RegExp('\\s
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
content = content.replace(new RegExp('\\s
|
53 |
-
content = content.replace(new RegExp('
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
content = content.replace(new RegExp('
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
var
|
83 |
-
var
|
84 |
-
var
|
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 |
-
ed.
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
pee = pee
|
131 |
-
pee = pee.replace(new RegExp('(
|
132 |
-
pee = pee.replace(new RegExp(
|
133 |
-
pee = pee.replace(new RegExp("\\
|
134 |
-
pee = pee.replace(new RegExp(
|
135 |
-
|
136 |
-
pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')[^>]*>)\\s*</p>', 'gi'), "$1");
|
137 |
-
pee = pee.replace(new RegExp("<p>(<li.+?)</p>", 'gi'), "$1");
|
138 |
-
pee = pee.replace(new RegExp(
|
139 |
-
pee = pee.replace(new RegExp(
|
140 |
-
pee = pee.replace(new RegExp('<p>\\s
|
141 |
-
pee = pee.replace(new RegExp('
|
142 |
-
pee = pee.replace(new RegExp('\\s
|
143 |
-
pee = pee.replace(new RegExp('(
|
144 |
-
pee = pee.replace(new RegExp('<
|
145 |
-
pee = pee.replace(new RegExp('(
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
}
|
|
1 |
+
switchEditors = {
|
2 |
+
|
3 |
+
mode : '',
|
4 |
+
|
5 |
+
I : function(e) {
|
6 |
+
return document.getElementById(e);
|
7 |
+
},
|
8 |
+
|
9 |
+
edInit : function() {
|
10 |
+
var h = tinymce.util.Cookie.getHash("TinyMCE_content_size"), H = this.I('edButtonHTML'), P = this.I('edButtonPreview');
|
11 |
+
|
12 |
+
// Activate TinyMCE if it's the user's default editor
|
13 |
+
if ( getUserSetting( 'editor' ) == 'html' ) {
|
14 |
+
if ( h )
|
15 |
+
try { this.I('content').style.height = h.ch - 30 + 'px'; } catch(e){};
|
16 |
+
} else {
|
17 |
+
try {
|
18 |
+
this.I("quicktags").style.display = "none";
|
19 |
+
} catch(e){};
|
20 |
+
tinyMCE.execCommand("mceAddControl", false, "content");
|
21 |
+
}
|
22 |
+
},
|
23 |
+
|
24 |
+
saveCallback : function(el, content, body) {
|
25 |
+
|
26 |
+
if ( tinyMCE.activeEditor.isHidden() )
|
27 |
+
content = this.I(el).value;
|
28 |
+
else
|
29 |
+
content = this.pre_wpautop(content);
|
30 |
+
|
31 |
+
return content;
|
32 |
+
},
|
33 |
+
|
34 |
+
pre_wpautop : function(content) {
|
35 |
+
// We have a TON of cleanup to do. Line breaks are already stripped.
|
36 |
+
|
37 |
+
// Protect pre|script tags
|
38 |
+
content = content.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) {
|
39 |
+
a = a.replace(/<br ?\/?>[\r\n]*/g, '<wp_temp>');
|
40 |
+
return a.replace(/<\/?p( [^>]*)?>[\r\n]*/g, '<wp_temp>');
|
41 |
+
});
|
42 |
+
|
43 |
+
// Pretty it up for the source editor
|
44 |
+
var blocklist1 = 'blockquote|ul|ol|li|table|thead|tbody|tr|th|td|div|h[1-6]|p';
|
45 |
+
content = content.replace(new RegExp('\\s*</('+blocklist1+')>\\s*', 'mg'), '</$1>\n');
|
46 |
+
content = content.replace(new RegExp('\\s*<(('+blocklist1+')[^>]*)>', 'mg'), '\n<$1>');
|
47 |
+
|
48 |
+
content = content.replace(new RegExp('<p ?[^>]*>[\\s\\n]*<(/?script[^>]*)>', 'mg'), '\n<$1>');
|
49 |
+
content = content.replace(new RegExp('<(/?script[^>]*)>[\\s\\n]*</p>', 'mg'), '\n<$1>');
|
50 |
+
|
51 |
+
// Fix some block element newline issues
|
52 |
+
content = content.replace(new RegExp('\\s*<div', 'mg'), '\n<div');
|
53 |
+
content = content.replace(new RegExp('</div>\\s*', 'mg'), '</div>\n');
|
54 |
+
content = content.replace(new RegExp('\\s*\\[caption([^\\[]+)\\[/caption\\]\\s*', 'gi'), '\n\n[caption$1[/caption]\n\n');
|
55 |
+
content = content.replace(new RegExp('caption\\]\\n\\n+\\[caption', 'g'), 'caption]\n\n[caption');
|
56 |
+
|
57 |
+
var blocklist2 = 'blockquote|ul|ol|li|table|thead|tr|th|td|h[1-6]|pre';
|
58 |
+
content = content.replace(new RegExp('\\s*<(('+blocklist2+') ?[^>]*)\\s*>', 'mg'), '\n<$1>');
|
59 |
+
content = content.replace(new RegExp('\\s*</('+blocklist2+')>\\s*', 'mg'), '</$1>\n');
|
60 |
+
content = content.replace(new RegExp('<li([^>]*)>', 'g'), '\t<li$1>');
|
61 |
+
|
62 |
+
if ( content.indexOf('<object') != -1 ) {
|
63 |
+
content = content.replace(new RegExp('\\s*<param([^>]*)>\\s*', 'mg'), "<param$1>");
|
64 |
+
content = content.replace(new RegExp('\\s*</embed>\\s*', 'mg'), '</embed>');
|
65 |
+
}
|
66 |
+
|
67 |
+
// Unmark special paragraph closing tags
|
68 |
+
content = content.replace(new RegExp('</p#>', 'g'), '</p>\n');
|
69 |
+
content = content.replace(new RegExp('\\s*(<p [^>]+>.*</p>)', 'mg'), '\n$1');
|
70 |
+
|
71 |
+
// put back the line breaks in pre|script
|
72 |
+
content = content.replace(/<wp_temp>/g, '\n');
|
73 |
+
|
74 |
+
// Hope.
|
75 |
+
return content;
|
76 |
+
},
|
77 |
+
|
78 |
+
go : function(id, mode) {
|
79 |
+
id = id || 'content';
|
80 |
+
mode = mode || this.mode || '';
|
81 |
+
|
82 |
+
var ed = tinyMCE.get(id) || false;
|
83 |
+
var qt = this.I('quicktags');
|
84 |
+
var H = this.I('edButtonHTML');
|
85 |
+
var P = this.I('edButtonPreview');
|
86 |
+
var ta = this.I(id);
|
87 |
+
|
88 |
+
if ( 'tinymce' == mode ) {
|
89 |
+
|
90 |
+
if ( ed && ! ed.isHidden() )
|
91 |
+
return false;
|
92 |
+
|
93 |
+
this.mode = 'html';
|
94 |
+
ta.style.color = '#fff';
|
95 |
+
|
96 |
+
P.className = 'active';
|
97 |
+
H.className = '';
|
98 |
+
edCloseAllTags(); // :-(
|
99 |
+
|
100 |
+
qt.style.display = 'none';
|
101 |
+
|
102 |
+
ta.value = this.wpautop(ta.value);
|
103 |
+
|
104 |
+
if ( ed ) ed.show();
|
105 |
+
else tinyMCE.execCommand("mceAddControl", false, id);
|
106 |
+
|
107 |
+
setUserSetting( 'editor', 'tinymce' );
|
108 |
+
} else {
|
109 |
+
if ( ! ed || ed.isHidden() )
|
110 |
+
return false;
|
111 |
+
|
112 |
+
this.mode = 'tinymce';
|
113 |
+
H.className = 'active';
|
114 |
+
P.className = '';
|
115 |
+
|
116 |
+
ta.style.height = ed.getContentAreaContainer().offsetHeight + 6 + 'px';
|
117 |
+
|
118 |
+
ed.hide();
|
119 |
+
qt.style.display = 'block';
|
120 |
+
|
121 |
+
ta.style.color = '';
|
122 |
+
setUserSetting( 'editor', 'html' );
|
123 |
+
}
|
124 |
+
return false;
|
125 |
+
},
|
126 |
+
|
127 |
+
wpautop : function(pee) {
|
128 |
+
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';
|
129 |
+
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';
|
130 |
+
pee = pee + "\n\n";
|
131 |
+
pee = pee.replace(new RegExp('(<(?:'+blocklist+')[^>]*>)', 'gi'), "\n$1");
|
132 |
+
pee = pee.replace(new RegExp('(</(?:'+blocklist+')>)', 'gi'), "$1\n\n");
|
133 |
+
pee = pee.replace(new RegExp("\\r\\n|\\r", 'g'), "\n");
|
134 |
+
pee = pee.replace(new RegExp("\\n\\s*\\n+", 'g'), "\n\n");
|
135 |
+
pee = pee.replace(new RegExp('([\\s\\S]+?)\\n\\n', 'mg'), "<p>$1</p>\n");
|
136 |
+
pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')[^>]*>)\\s*</p>', 'gi'), "$1");
|
137 |
+
pee = pee.replace(new RegExp("<p>(<li.+?)</p>", 'gi'), "$1");
|
138 |
+
pee = pee.replace(new RegExp("<p ?[^>]*>(<!--(.*)?-->)", 'gi'), "$1");
|
139 |
+
pee = pee.replace(new RegExp("(<!--(.*)?-->)</p>", 'gi'), "$1");
|
140 |
+
pee = pee.replace(new RegExp('<p>\\s*<blockquote([^>]*)>', 'gi'), "<blockquote$1><p>");
|
141 |
+
pee = pee.replace(new RegExp('</blockquote>\\s*</p>', 'gi'), '</p></blockquote>');
|
142 |
+
pee = pee.replace(new RegExp('<p>[\\s\\n]*(<(?:'+blocklist+')[^>]*>)', 'gi'), "$1");
|
143 |
+
pee = pee.replace(new RegExp('<p>[\\s\\n]*(</(?:'+blocklist2+')[^>]*>)', 'gi'), "$1");
|
144 |
+
pee = pee.replace(new RegExp('(<(?:'+blocklist2+')[^>]*>)[\\s\\n]*</p>', 'gi'), "$1");
|
145 |
+
pee = pee.replace(new RegExp('(</(?:'+blocklist+')[^>]*>)[\\s\\n]*</p>', 'gi'), "$1");
|
146 |
+
pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*<br />', 'gi'), "$1");
|
147 |
+
pee = pee.replace(new RegExp('<br />(\\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)', 'gi'), '$1');
|
148 |
+
pee = pee.replace(new RegExp('(?:<p>|<br ?/?>)*\\s*\\[caption([^\\[]+)\\[/caption\\]\\s*(?:</p>|<br ?/?>)*', 'gi'), '[caption$1[/caption]');
|
149 |
+
|
150 |
+
// Fix the pre|script tags
|
151 |
+
pee = pee.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) {
|
152 |
+
a = a.replace(/<br ?\/?>[\r\n]*/g, '\n');
|
153 |
+
return a.replace(/<\/?p( [^>]*)?>[\r\n]*/g, '\n');
|
154 |
+
});
|
155 |
+
return pee;
|
156 |
+
}
|
157 |
+
}
|
ps_disable_auto_formatting.php
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: PS Disable Auto Formatting
|
4 |
-
Plugin URI: http://www.web-strategy.jp/
|
5 |
Description: PS Disable Auto Formatting is able to disable function auto formatting (wpautop) and save <p> and <br /> formatted content.
|
6 |
-
Version: 0.9.
|
7 |
Author: Hitoshi Omagari
|
8 |
Author URI: http://www.web-strategy.jp/
|
9 |
*/
|
@@ -18,7 +18,7 @@ var $setting_items = array(
|
|
18 |
'term description formatting' => 'term_description',
|
19 |
);
|
20 |
|
21 |
-
var $mce_version = '
|
22 |
|
23 |
function __construct() {
|
24 |
global $wp_version;
|
@@ -27,6 +27,7 @@ function __construct() {
|
|
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 |
} else {
|
31 |
add_action('admin_notices', array( &$this, 'version_too_old' ) );
|
32 |
}
|
@@ -89,12 +90,7 @@ function set_default_settings() {
|
|
89 |
function rewrite_default_script( $todo ) {
|
90 |
global $wp_scripts;
|
91 |
|
92 |
-
|
93 |
-
$mce_version = mce_version();
|
94 |
-
} else {
|
95 |
-
$mce_version = $this->mce_version;
|
96 |
-
}
|
97 |
-
$wp_scripts->add( 'ps_editor', get_option( 'home' ) . '/' . str_replace( str_replace( '\\', '/', ABSPATH ), '', str_replace( '\\', '/', dirname( __file__ ) ) ) . '/js/ps_editor.js', false, $mce_version );
|
98 |
|
99 |
$key = array_search( 'editor', $todo );
|
100 |
if ( $key !== false ) {
|
@@ -104,6 +100,18 @@ function rewrite_default_script( $todo ) {
|
|
104 |
}
|
105 |
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
function add_disable_formatting_setting_page() {
|
108 |
if ( function_exists( 'add_options_page' ) ) {
|
109 |
add_options_page( 'PS Disable Auto Formatting',
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: PS Disable Auto Formatting
|
4 |
+
Plugin URI: http://www.web-strategy.co.jp/
|
5 |
Description: PS Disable Auto Formatting is able to disable function auto formatting (wpautop) and save <p> and <br /> formatted content.
|
6 |
+
Version: 0.9.1
|
7 |
Author: Hitoshi Omagari
|
8 |
Author URI: http://www.web-strategy.jp/
|
9 |
*/
|
18 |
'term description formatting' => 'term_description',
|
19 |
);
|
20 |
|
21 |
+
var $mce_version = '20090120';
|
22 |
|
23 |
function __construct() {
|
24 |
global $wp_version;
|
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 |
} else {
|
32 |
add_action('admin_notices', array( &$this, 'version_too_old' ) );
|
33 |
}
|
90 |
function rewrite_default_script( $todo ) {
|
91 |
global $wp_scripts;
|
92 |
|
93 |
+
$wp_scripts->add( 'ps_editor', get_option( 'home' ) . '/' . str_replace( str_replace( '\\', '/', ABSPATH ), '', str_replace( '\\', '/', dirname( __file__ ) ) ) . '/js/ps_editor.js', false, $this->mce_version );
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
$key = array_search( 'editor', $todo );
|
96 |
if ( $key !== false ) {
|
100 |
}
|
101 |
|
102 |
|
103 |
+
function formatting_quickpress_post( $data ) {
|
104 |
+
global $action;
|
105 |
+
|
106 |
+
if ( in_array( $action, array( 'post-quickpress-publish', 'post-quickpress-save' ) ) ) {
|
107 |
+
if ( empty( $_POST['quickpress_post_ID'] ) ) {
|
108 |
+
$data['post_content'] = wpautop( $data['post_content'] );
|
109 |
+
}
|
110 |
+
}
|
111 |
+
return $data;
|
112 |
+
}
|
113 |
+
|
114 |
+
|
115 |
function add_disable_formatting_setting_page() {
|
116 |
if ( function_exists( 'add_options_page' ) ) {
|
117 |
add_options_page( 'PS Disable Auto Formatting',
|
readme.txt
CHANGED
@@ -24,6 +24,9 @@ And when editing in the visual mode, it achieves to generate natural changing li
|
|
24 |
* Batch formatting to all articles that you have already posted.
|
25 |
|
26 |
= Version History =
|
|
|
|
|
|
|
27 |
* **0.9.0**
|
28 |
* Public release
|
29 |
|
24 |
* Batch formatting to all articles that you have already posted.
|
25 |
|
26 |
= Version History =
|
27 |
+
* **0.9.1**
|
28 |
+
* bugfix : disappearing paragraph element with swithing mode in some browsers
|
29 |
+
* compatible with quickpress
|
30 |
* **0.9.0**
|
31 |
* Public release
|
32 |
|