PS Disable Auto Formatting - Version 0.9.1

Version Description

Download this release

Release Info

Developer jim912
Plugin Icon wp 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

Files changed (3) hide show
  1. js/ps_editor.js +157 -156
  2. ps_disable_auto_formatting.php +17 -9
  3. readme.txt +3 -0
js/ps_editor.js CHANGED
@@ -1,156 +1,157 @@
1
-
2
- switchEditors = {
3
-
4
- mode : '',
5
-
6
- I : function(e) {
7
- return document.getElementById(e);
8
- },
9
-
10
- edInit : function() {
11
- var h = tinymce.util.Cookie.getHash("TinyMCE_content_size"), H = this.I('edButtonHTML'), P = this.I('edButtonPreview');
12
-
13
- // Activate TinyMCE if it's the user's default editor
14
- if ( getUserSetting( 'editor' ) == 'html' ) {
15
- if ( h )
16
- try { this.I('content').style.height = h.ch - 30 + 'px'; } catch(e){};
17
- } else {
18
- try {
19
- this.I("quicktags").style.display = "none";
20
- } catch(e){};
21
- tinyMCE.execCommand("mceAddControl", false, "content");
22
- }
23
- },
24
-
25
- saveCallback : function(el, content, body) {
26
-
27
- if ( tinyMCE.activeEditor.isHidden() )
28
- content = this.I(el).value;
29
- else
30
- content = this.pre_wpautop(content);
31
-
32
- return content;
33
- },
34
-
35
- pre_wpautop : function(content) {
36
- // We have a TON of cleanup to do. Line breaks are already stripped.
37
-
38
- // Protect pre|script tags
39
- content = content.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) {
40
- a = a.replace(/<br ?\/?>[\r\n]*/g, '<wp_temp>');
41
- return a.replace(/<\/?p( [^>]*)?>[\r\n]*/g, '<wp_temp>');
42
- });
43
-
44
- // Pretty it up for the source editor
45
- var blocklist1 = 'blockquote|ul|ol|li|table|thead|tbody|tr|th|td|div|h[1-6]|p';
46
- content = content.replace(new RegExp('\\s*</('+blocklist1+')>\\s*', 'mg'), '</$1>\n');
47
- content = content.replace(new RegExp('\\s*<(('+blocklist1+')[^>]*)>', 'mg'), '\n<$1>');
48
-
49
- // Fix some block element newline issues
50
- content = content.replace(new RegExp('\\s*<div', 'mg'), '\n<div');
51
- content = content.replace(new RegExp('</div>\\s*', 'mg'), '</div>\n');
52
- content = content.replace(new RegExp('\\s*\\[caption([^\\[]+)\\[/caption\\]\\s*', 'gi'), '\n\n[caption$1[/caption]\n\n');
53
- content = content.replace(new RegExp('caption\\]\\n\\n+\\[caption', 'g'), 'caption]\n\n[caption');
54
-
55
- var blocklist2 = 'blockquote|ul|ol|li|table|thead|tr|th|td|h[1-6]|pre';
56
- content = content.replace(new RegExp('\\s*<(('+blocklist2+') ?[^>]*)\\s*>', 'mg'), '\n<$1>');
57
- content = content.replace(new RegExp('\\s*</('+blocklist2+')>\\s*', 'mg'), '</$1>\n');
58
- content = content.replace(new RegExp('<li([^>]*)>', 'g'), '\t<li$1>');
59
-
60
- if ( content.indexOf('<object') != -1 ) {
61
- content = content.replace(new RegExp('\\s*<param([^>]*)>\\s*', 'mg'), "<param$1>");
62
- content = content.replace(new RegExp('\\s*</embed>\\s*', 'mg'), '</embed>');
63
- }
64
-
65
- // Unmark special paragraph closing tags
66
- content = content.replace(new RegExp('</p#>', 'g'), '</p>\n');
67
- content = content.replace(new RegExp('\\s*(<p [^>]+>.*</p>)', 'mg'), '\n$1');
68
-
69
- // put back the line breaks in pre|script
70
- content = content.replace(/<wp_temp>/g, '\n');
71
-
72
- // Hope.
73
- return content;
74
- },
75
-
76
- go : function(id, mode) {
77
- id = id || 'content';
78
- mode = mode || this.mode || '';
79
-
80
- var ed = tinyMCE.get(id) || false;
81
- var qt = this.I('quicktags');
82
- var H = this.I('edButtonHTML');
83
- var P = this.I('edButtonPreview');
84
- var ta = this.I(id);
85
-
86
- if ( 'tinymce' == mode ) {
87
-
88
- if ( ed && ! ed.isHidden() )
89
- return false;
90
-
91
- this.mode = 'html';
92
- ta.style.color = '#fff';
93
-
94
- P.className = 'active';
95
- H.className = '';
96
- edCloseAllTags(); // :-(
97
-
98
- qt.style.display = 'none';
99
-
100
- ta.value = this.wpautop(ta.value);
101
-
102
- if ( ed ) ed.show();
103
- else tinyMCE.execCommand("mceAddControl", false, id);
104
-
105
- setUserSetting( 'editor', 'tinymce' );
106
- } else {
107
- if ( ! ed || ed.isHidden() )
108
- return false;
109
-
110
- this.mode = 'tinymce';
111
- H.className = 'active';
112
- P.className = '';
113
-
114
- ta.style.height = ed.getContentAreaContainer().offsetHeight + 6 + 'px';
115
-
116
- ed.hide();
117
- qt.style.display = 'block';
118
-
119
- ta.style.color = '';
120
- setUserSetting( 'editor', 'html' );
121
- }
122
- return false;
123
- },
124
-
125
- wpautop : function(pee) {
126
- 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]';
127
-
128
- pee = pee + "\n\n";
129
- // pee = pee.replace(new RegExp('<br />\\s*<br />', 'gi'), "\n\n");
130
- pee = pee.replace(new RegExp('(<(?:'+blocklist+')[^>]*>)', 'gi'), "\n$1");
131
- pee = pee.replace(new RegExp('(</(?:'+blocklist+')>)', 'gi'), "$1\n\n");
132
- pee = pee.replace(new RegExp("\\r\\n|\\r", 'g'), "\n");
133
- pee = pee.replace(new RegExp("\\n\\s*\\n+", 'g'), "\n\n");
134
- pee = pee.replace(new RegExp('([\\s\\S]+?)\\n\\n', 'mg'), "<p>$1</p>\n");
135
- // pee = pee.replace(new RegExp('<p>\\s*?</p>', 'gi'), '');
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>\\s*<blockquote([^>]*)>', 'gi'), "<blockquote$1><p>");
139
- pee = pee.replace(new RegExp('</blockquote>\\s*</p>', 'gi'), '</p></blockquote>');
140
- pee = pee.replace(new RegExp('<p>\\s*(</?(?:'+blocklist+')[^>]*>)', 'gi'), "$1");
141
- pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*</p>', 'gi'), "$1");
142
- pee = pee.replace(new RegExp('\\s*\\n', 'gi'), "<br />\n");
143
- pee = pee.replace(new RegExp('(</?(?:'+blocklist+')[^>]*>)\\s*<br />', 'gi'), "$1");
144
- pee = pee.replace(new RegExp('<br />(\\s*</?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)', 'gi'), '$1');
145
- pee = pee.replace(new RegExp('(?:<p>|<br ?/?>)*\\s*\\[caption([^\\[]+)\\[/caption\\]\\s*(?:</p>|<br ?/?>)*', 'gi'), '[caption$1[/caption]');
146
- // pee = pee.replace(new RegExp('^((?:&nbsp;)*)\\s', 'mg'), '$1&nbsp;');
147
-
148
- // Fix the pre|script tags
149
- pee = pee.replace(/<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function(a) {
150
- a = a.replace(/<br ?\/?>[\r\n]*/g, '\n');
151
- return a.replace(/<\/?p( [^>]*)?>[\r\n]*/g, '\n');
152
- });
153
-
154
- return pee;
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/wp_plugin/ps_disable_auto_formatting/
5
  Description: PS Disable Auto Formatting is able to disable function auto formatting (wpautop) and save &lt;p&gt; and &lt;br /&gt; formatted content.
6
- Version: 0.9.0
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 = '20081129';
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
- if ( function_exists( 'mce_version' ) ) {
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 &lt;p&gt; and &lt;br /&gt; 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