Raw HTML - Version 1.4.1

Version Description

  • Tested on the latest Beta version of WordPress (3.2-beta2).
  • Prefer <!--raw-->...<!--/raw--> over <!--start_raw-->...<!--/end_raw-->. The old syntax will continue to work, but you're encouraged to use either [raw] or <!--raw--> in the future as they're more internally consistent (and shorter).
Download this release

Release Info

Developer whiteshadow
Plugin Icon wp plugin Raw HTML
Version 1.4.1
Comparing to
See all releases

Code changes from version 1.4 to 1.4.1

include/formatting-override.php ADDED
@@ -0,0 +1,271 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /*****************************************************
4
+ Disable default formatting on a per-post level
5
+ ******************************************************/
6
+
7
+ require 'screen-options/screen-options.php';
8
+
9
+ //Apply function $func to $content unless it's been disabled for the current post
10
+ function maybe_use_filter($func, $content){
11
+ global $post;
12
+ $setting = get_post_meta($post->ID, '_disable_'.$func, true);
13
+ if ( $setting == '' ){
14
+ $setting = get_post_meta($post->ID, 'disable_'.$func, true);
15
+ }
16
+ if ($setting == '1') {
17
+ return $content;
18
+ } else {
19
+ return $func($content);
20
+ }
21
+ }
22
+
23
+ //Stub filters that replace the WP defaults
24
+ function maybe_wptexturize($content){
25
+ return maybe_use_filter('wptexturize', $content);
26
+ }
27
+
28
+ function maybe_wpautop($content){
29
+ return maybe_use_filter('wpautop', $content);
30
+ }
31
+
32
+ function maybe_convert_chars($content){
33
+ return maybe_use_filter('convert_chars', $content);
34
+ }
35
+
36
+ function maybe_convert_smilies($content){
37
+ return maybe_use_filter('convert_smilies', $content);
38
+ }
39
+
40
+ // Disable default filters and add our conditional filters
41
+ function rawhtml_add_conditional_filters(){
42
+ $filters = array(
43
+ 'the_content' => array(
44
+ 'wpautop',
45
+ 'wptexturize',
46
+ 'convert_chars',
47
+ 'convert_smilies',
48
+ ),
49
+ 'the_excerpt' => array(
50
+ 'wpautop',
51
+ 'wptexturize',
52
+ 'convert_chars',
53
+ 'convert_smilies',
54
+ ),
55
+ );
56
+
57
+ foreach ( $filters as $tag => $functions ){
58
+ foreach ( $functions as $func ){
59
+ if ( remove_filter($tag, $func) ){
60
+ add_filter( $tag, 'maybe_'.$func, 3 );
61
+ };
62
+ }
63
+ }
64
+ }
65
+ add_action('init', 'rawhtml_add_conditional_filters');
66
+
67
+ // Add a custom meta box for per-post settings
68
+ add_action('admin_menu', 'rawhtml_add_custom_box');
69
+ add_action('save_post', 'rawhtml_save_postdata');
70
+
71
+ /* Adds a custom section to the "advanced" Post and Page edit screens */
72
+ function rawhtml_add_custom_box() {
73
+ //WP 2.5+
74
+ if( function_exists( 'add_meta_box' )) {
75
+ foreach( array('post', 'page') as $type ) {
76
+ add_meta_box( 'rawhtml_meta_box', 'Raw HTML', 'rawhtml_meta_box', $type, 'side' );
77
+ }
78
+ }
79
+ }
80
+
81
+ /* Displays the custom box */
82
+ function rawhtml_meta_box(){
83
+ global $post;
84
+ // Use nonce for verification
85
+ echo '<input type="hidden" name="rawhtml_nonce" id="rawhtml_nonce" value="' .
86
+ wp_create_nonce( plugin_basename(RAWHTML_PLUGIN_FILE) ) . '" />';
87
+
88
+ //Output checkboxes
89
+ $fields = array(
90
+ 'disable_wptexturize' => 'Disable wptexturize',
91
+ 'disable_wpautop' => 'Disable automatic paragraphs',
92
+ 'disable_convert_chars' => 'Disable convert_chars',
93
+ 'disable_convert_smilies' => 'Disable smilies',
94
+ );
95
+ $defaults = rawhtml_get_default_settings();
96
+ foreach($fields as $field => $legend){
97
+ $current_setting = get_post_meta($post->ID, '_'.$field, true);
98
+ if ( $current_setting == '' ){
99
+ $current_setting = get_post_meta($post->ID, $field, true);
100
+ }
101
+ if ( $current_setting == '' ){
102
+ $current_setting = $defaults[$field];
103
+ } else {
104
+ $current_setting = (bool)intval($current_setting);
105
+ }
106
+ ?>
107
+ <label for="rawhtml_<?php echo $field; ?>">
108
+ <input type="checkbox" name="rawhtml_<?php echo $field; ?>" id="rawhtml_<?php echo $field; ?>" <?php
109
+ if ($current_setting) echo ' checked="checked"';
110
+ ?>/>
111
+ <?php echo $legend; ?>
112
+ </label>
113
+ <br />
114
+ <?php
115
+ }
116
+ }
117
+
118
+ /* Saves post metadata */
119
+ function rawhtml_save_postdata( $post_id ){
120
+ // verify this came from the our screen and with proper authorization,
121
+ // because save_post can be triggered at other times
122
+
123
+ if ( !isset($_POST['rawhtml_nonce']) ){
124
+ return $post_id;
125
+ }
126
+
127
+ if ( !wp_verify_nonce( $_POST['rawhtml_nonce'], plugin_basename(RAWHTML_PLUGIN_FILE) )) {
128
+ return $post_id;
129
+ }
130
+
131
+ if ( 'page' == $_POST['post_type'] ) {
132
+ if ( !current_user_can( 'edit_page', $post_id ))
133
+ return $post_id;
134
+ } else {
135
+ if ( !current_user_can( 'edit_post', $post_id ))
136
+ return $post_id;
137
+ }
138
+
139
+ // OK, we're authenticated: we need to find and save the data
140
+ $fields = array('disable_wpautop', 'disable_wptexturize', 'disable_convert_chars', 'disable_convert_smilies');
141
+ foreach ( $fields as $field ){
142
+ if ( !empty($_POST['rawhtml_'.$field]) ){
143
+ update_post_meta($post_id, '_'.$field, '1');
144
+ } else {
145
+ update_post_meta($post_id, '_'.$field, '0');
146
+ };
147
+ }
148
+
149
+ return true;
150
+ }
151
+
152
+ //Add our panel to the "Screen Options" box
153
+ add_screen_options_panel(
154
+ 'rawhtml-default-settings', //Panel ID
155
+ 'Raw HTML defaults', //Panel title.
156
+ 'rawhtml_default_settings_panel', //The function that generates panel contents.
157
+ array('post', 'page'), //Pages/screens where the panel is displayed.
158
+ 'rawhtml_save_new_defaults', //The function that gets triggered when settings are submitted/saved.
159
+ true //Auto-submit settings (via AJAX) when they change.
160
+ );
161
+
162
+ /**
163
+ * Retrieve the default settings for our post/page meta box.
164
+ * Settings are saved in user meta.
165
+ *
166
+ * @return array
167
+ */
168
+ function rawhtml_get_default_settings(){
169
+ //By default, all tweaks are disabled
170
+ $defaults = array(
171
+ 'disable_wptexturize' => false,
172
+ 'disable_wpautop' => false,
173
+ 'disable_convert_chars' => false,
174
+ 'disable_convert_smilies' => false,
175
+ );
176
+
177
+ if ( !function_exists('wp_get_current_user') || !function_exists('get_user_meta') ){
178
+ return $defaults;
179
+ }
180
+
181
+ //Get current defaults, if any
182
+ $user = wp_get_current_user();
183
+ $user_defaults = get_user_meta($user->ID, 'rawhtml_defaults', true);
184
+ if ( is_array($user_defaults) ){
185
+ $defaults = array_merge($defaults, $user_defaults);
186
+ }
187
+
188
+ return $defaults;
189
+ }
190
+
191
+ /**
192
+ * Update default settings for our post/page meta box.
193
+ *
194
+ * @param array $new_defaults
195
+ * @return bool True on success, false on failure.
196
+ */
197
+ function rawhtml_set_default_settings($new_defaults){
198
+ if ( !function_exists('wp_get_current_user') || !function_exists('update_user_meta') ){
199
+ return false;
200
+ }
201
+
202
+ //Get current defaults, if any
203
+ $user = wp_get_current_user();
204
+ if ( isset($user) && $user && isset($user->ID) ){
205
+ return update_user_meta($user->ID, 'rawhtml_defaults', $new_defaults);
206
+ } else {
207
+ return false;
208
+ }
209
+ }
210
+
211
+ /**
212
+ * Generate the "Raw HTML defaults" panel for Screen Options.
213
+ *
214
+ * @return string
215
+ */
216
+ function rawhtml_default_settings_panel(){
217
+ $defaults = rawhtml_get_default_settings();
218
+
219
+ //Output checkboxes
220
+ $fields = array(
221
+ 'disable_wptexturize' => 'Disable wptexturize',
222
+ 'disable_wpautop' => 'Disable automatic paragraphs',
223
+ 'disable_convert_chars' => 'Disable convert_chars',
224
+ 'disable_convert_smilies' => 'Disable smilies',
225
+ );
226
+
227
+ $output = '<div class="metabox-prefs">';
228
+ foreach($fields as $field => $legend){
229
+ $esc_field = esc_attr($field);
230
+ $output .= sprintf(
231
+ '<label for="rawhtml_default-%s" style="line-height: 20px;">
232
+ <input type="checkbox" name="rawhtml_default-%s" id="rawhtml_default-%s"%s>
233
+ %s
234
+ </label><br>',
235
+ $esc_field,
236
+ $esc_field,
237
+ $esc_field,
238
+ ($defaults[$field]?' checked="checked"':''),
239
+ $legend
240
+ );
241
+ }
242
+ $output .= "</div>";
243
+
244
+ return $output;
245
+ }
246
+
247
+ /**
248
+ * Process the "Raw HTML defaults" form fields and save new settings
249
+ *
250
+ * @param array $params
251
+ * @return void
252
+ */
253
+ function rawhtml_save_new_defaults($params){
254
+ //Get current defaults
255
+ $defaults = rawhtml_get_default_settings();
256
+
257
+ //Read new values from the submitted form
258
+ foreach($defaults as $field => $old_value){
259
+ if ( isset($params['rawhtml_default-'.$field]) && ($params['rawhtml_default-'.$field] == 'on') ){
260
+ $defaults[$field] = true;
261
+ } else {
262
+ $defaults[$field] = false;
263
+ }
264
+ }
265
+
266
+ //Store the new defaults
267
+ rawhtml_set_default_settings($defaults);
268
+ }
269
+
270
+
271
+ ?>
{screen-options → include/screen-options}/screen-options.js RENAMED
File without changes
{screen-options → include/screen-options}/screen-options.php RENAMED
File without changes
include/tag-handler.php ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**********************************************
4
+ Filter inline blocks of raw HTML
5
+ ***********************************************/
6
+ global $wsh_raw_parts;
7
+ $wsh_raw_parts=array();
8
+
9
+ /**
10
+ * Extract content surrounded by [raw] or other supported tags
11
+ * and replace it with placeholder text.
12
+ *
13
+ * @global $wsh_raw_parts Used to store the extracted content blocks.
14
+ *
15
+ * @param string $text The input content to filter.
16
+ * @param bool $keep_tags Store both the tagged content and the tags themselves. Defaults to false - storing only the content.
17
+ * @return string Filtered content.
18
+ */
19
+ function wsh_extract_exclusions($text, $keep_tags = false){
20
+ global $wsh_raw_parts, $wp_current_filter;
21
+ //Note to self: The regexp version was much shorter, but it had problems with big posts.
22
+
23
+ $tags = array(array('<!--start_raw-->', '<!--end_raw-->'), array('[raw]', '[/raw]'), array('<!--raw-->', '<!--/raw-->'));
24
+
25
+ foreach ($tags as $tag_pair){
26
+ list($start_tag, $end_tag) = $tag_pair;
27
+
28
+ //Find the start tag
29
+ $start = stripos($text, $start_tag, 0);
30
+ while($start !== false){
31
+ $content_start = $start + strlen($start_tag);
32
+
33
+ //find the end tag
34
+ $fin = stripos($text, $end_tag, $content_start);
35
+
36
+ //break if there's no end tag
37
+ if ($fin == false) break;
38
+
39
+ //extract the content between the tags
40
+ $content = substr($text, $content_start,$fin-$content_start);
41
+
42
+ if ( (array_search('get_the_excerpt', $wp_current_filter) !== false) || (array_search('the_excerpt', $wp_current_filter) !== false) ){
43
+ //Strip out the raw blocks when displaying an excerpt
44
+ $replacement = '';
45
+ } else {
46
+ //Store the content and replace it with a marker
47
+ if ( $keep_tags ){
48
+ $wsh_raw_parts[]=$start_tag.$content.$end_tag;
49
+ } else {
50
+ $wsh_raw_parts[]=$content;
51
+ }
52
+ $replacement = "!RAWBLOCK".(count($wsh_raw_parts)-1)."!";
53
+ }
54
+ $text = substr_replace($text, $replacement, $start,
55
+ $fin+strlen($end_tag)-$start
56
+ );
57
+
58
+ //Have we reached the end of the string yet?
59
+ if ($start + strlen($replacement) > strlen($text)) break;
60
+
61
+ //Find the next start tag
62
+ $start = stripos($text, $start_tag, $start + strlen($replacement));
63
+ }
64
+ }
65
+ return $text;
66
+ }
67
+
68
+ /**
69
+ * Replace the placeholders created by wsh_extract_exclusions() with the original content.
70
+ *
71
+ * @global $wsh_raw_parts Used to check if there is anything to insert.
72
+ *
73
+ * @param string $text The input content to filter.
74
+ * @param callback $placholder_callback Optional. The callback that will be used to process each placeholder.
75
+ * @return string Filtered content.
76
+ */
77
+ function wsh_insert_exclusions($text, $placeholder_callback = 'wsh_insertion_callback'){
78
+ global $wsh_raw_parts;
79
+ if(!isset($wsh_raw_parts)) return $text;
80
+ return preg_replace_callback("/!RAWBLOCK(\d+?)!/", $placeholder_callback, $text);
81
+ }
82
+
83
+ /**
84
+ * Regex callback for wsh_insert_exclusions. Returns the extracted content
85
+ * corresponding to a matched placeholder.
86
+ *
87
+ * @global $wsh_raw_parts
88
+ *
89
+ * @param array $matches Regex matches.
90
+ * @return string Replacement string for this match.
91
+ */
92
+ function wsh_insertion_callback($matches){
93
+ global $wsh_raw_parts;
94
+ return $wsh_raw_parts[intval($matches[1])];
95
+ }
96
+
97
+ //Extract the tagged content before WP can get to it, then re-insert it later.
98
+ add_filter('the_content', 'wsh_extract_exclusions', 2);
99
+ add_filter('the_content', 'wsh_insert_exclusions', 1001);
100
+
101
+
102
+ /*
103
+ * WordPress can also mangle code when initializing the post/page editor.
104
+ * To prevent this, we override the the_editor_content filter in almost
105
+ * the same way that we did the_content.
106
+ */
107
+
108
+ function wsh_extract_exclusions_for_editor($text){
109
+ return wsh_extract_exclusions($text, true);
110
+ }
111
+
112
+ function wsh_insert_exclusions_for_editor($text){
113
+ return wsh_insert_exclusions($text, 'wsh_insertion_callback_for_editor');
114
+ }
115
+
116
+ function wsh_insertion_callback_for_editor($matches){
117
+ global $wsh_raw_parts;
118
+ return htmlspecialchars($wsh_raw_parts[intval($matches[1])], ENT_NOQUOTES);
119
+ }
120
+
121
+ add_filter('the_editor_content', 'wsh_extract_exclusions_for_editor', 2);
122
+ add_filter('the_editor_content', 'wsh_insert_exclusions_for_editor', 1001);
123
+
124
+ ?>
raw_html.php CHANGED
@@ -3,356 +3,23 @@
3
  Plugin Name: Raw HTML capability
4
  Plugin URI: http://w-shadow.com/blog/2007/12/13/raw-html-in-wordpress/
5
  Description: Lets you enter raw HTML in your posts. You can also enable/disable smart quotes and other automatic formatting on a per-post basis.
6
- Version: 1.4
7
  Author: Janis Elsts
8
  Author URI: http://w-shadow.com/blog/
9
  */
10
 
11
  /*
12
  Created by Janis Elsts (email : whiteshadow@w-shadow.com)
13
- It's LGPL.
14
  */
15
 
16
- include 'screen-options/screen-options.php';
17
 
18
- /**********************************************
19
- Filter inline blocks of raw HTML
20
- ***********************************************/
21
- global $wsh_raw_parts;
22
- $wsh_raw_parts=array();
23
 
24
- function wsh_extraction_callback($matches){
25
- global $wsh_raw_parts;
26
- $wsh_raw_parts[]=$matches[1];
27
- return "!RAWBLOCK".(count($wsh_raw_parts)-1)."!";
28
- }
29
-
30
- function wsh_extract_exclusions($text){
31
- global $wsh_raw_parts, $wp_current_filter;
32
-
33
- $tags = array(array('<!--start_raw-->', '<!--end_raw-->'), array('[RAW]', '[/RAW]'));
34
-
35
- foreach ($tags as $tag_pair){
36
- list($start_tag, $end_tag) = $tag_pair;
37
-
38
- //Find the start tag
39
- $start = stripos($text, $start_tag, 0);
40
- while($start !== false){
41
- $content_start = $start + strlen($start_tag);
42
-
43
- //find the end tag
44
- $fin = stripos($text, $end_tag, $content_start);
45
-
46
- //break if there's no end tag
47
- if ($fin == false) break;
48
-
49
- //extract the content between the tags
50
- $content = substr($text, $content_start,$fin-$content_start);
51
-
52
- if ( (array_search('get_the_excerpt', $wp_current_filter) !== false) || (array_search('the_excerpt', $wp_current_filter) !== false) ){
53
- //Strip out the raw blocks when displaying an excerpt
54
- $replacement = '';
55
- } else {
56
- //Store the content and replace it with a marker
57
- $wsh_raw_parts[]=$content;
58
- $replacement = "!RAWBLOCK".(count($wsh_raw_parts)-1)."!";
59
- }
60
- $text = substr_replace($text, $replacement, $start,
61
- $fin+strlen($end_tag)-$start
62
- );
63
-
64
- //Have we reached the end of the string yet?
65
- if ($start + strlen($replacement) > strlen($text)) break;
66
-
67
- //Find the next start tag
68
- $start = stripos($text, $start_tag, $start + strlen($replacement));
69
- }
70
- }
71
- return $text;
72
- /*
73
- //The regexp version is much shorter, but it has problems with big posts :
74
- return preg_replace_callback("/(?:<!--\s*start_raw\s*-->|\[RAW\])(.*?)(?:<!--\s*end_raw\s*-->|\[\/RAW\])/is",
75
- "wsh_extraction_callback", $text);
76
- // */
77
- }
78
-
79
- function wsh_insertion_callback($matches){
80
- global $wsh_raw_parts;
81
- return $wsh_raw_parts[intval($matches[1])];
82
- }
83
-
84
- function wsh_insert_exclusions($text){
85
- global $wsh_raw_parts;
86
- if(!isset($wsh_raw_parts)) return $text;
87
- return preg_replace_callback("/!RAWBLOCK(\d+?)!/", "wsh_insertion_callback", $text);
88
- }
89
-
90
- add_filter('the_content', 'wsh_extract_exclusions', 2);
91
- add_filter('the_content', 'wsh_insert_exclusions', 1001);
92
-
93
- /*****************************************************
94
- Disable default formatting on a per-post level
95
- ******************************************************/
96
-
97
- //Apply function $func to $content unless it's been disabled for the current post
98
- function maybe_use_filter($func, $content){
99
- global $post;
100
- $setting = get_post_meta($post->ID, '_disable_'.$func, true);
101
- if ( $setting == '' ){
102
- $setting = get_post_meta($post->ID, 'disable_'.$func, true);
103
- }
104
- if ($setting == '1') {
105
- return $content;
106
- } else {
107
- return $func($content);
108
- }
109
- }
110
-
111
- //Stub filters that replace the WP defaults
112
- function maybe_wptexturize($content){
113
- return maybe_use_filter('wptexturize', $content);
114
- }
115
-
116
- function maybe_wpautop($content){
117
- return maybe_use_filter('wpautop', $content);
118
- }
119
-
120
- function maybe_convert_chars($content){
121
- return maybe_use_filter('convert_chars', $content);
122
- }
123
-
124
- function maybe_convert_smilies($content){
125
- return maybe_use_filter('convert_smilies', $content);
126
- }
127
-
128
- // Disable default filters and add our conditional filters
129
- function rawhtml_add_conditional_filters(){
130
- $filters = array(
131
- 'the_content' => array(
132
- 'wpautop',
133
- 'wptexturize',
134
- 'convert_chars',
135
- 'convert_smilies',
136
- ),
137
- 'the_excerpt' => array(
138
- 'wpautop',
139
- 'wptexturize',
140
- 'convert_chars',
141
- 'convert_smilies',
142
- ),
143
- );
144
-
145
- foreach ( $filters as $tag => $functions ){
146
- foreach ( $functions as $func ){
147
- if ( remove_filter($tag, $func) ){
148
- add_filter( $tag, 'maybe_'.$func, 3 );
149
- };
150
- }
151
- }
152
- }
153
- add_action('init', 'rawhtml_add_conditional_filters');
154
-
155
- // Add a custom meta box for per-post settings
156
- add_action('admin_menu', 'rawhtml_add_custom_box');
157
- add_action('save_post', 'rawhtml_save_postdata');
158
-
159
- /* Adds a custom section to the "advanced" Post and Page edit screens */
160
- function rawhtml_add_custom_box() {
161
- //WP 2.5+
162
- if( function_exists( 'add_meta_box' )) {
163
- foreach( array('post', 'page') as $type ) {
164
- add_meta_box( 'rawhtml_meta_box', 'Raw HTML', 'rawhtml_meta_box', $type, 'side' );
165
- }
166
- }
167
- }
168
-
169
- /* Displays the custom box */
170
- function rawhtml_meta_box(){
171
- global $post;
172
- // Use nonce for verification
173
- echo '<input type="hidden" name="rawhtml_nonce" id="rawhtml_nonce" value="' .
174
- wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
175
-
176
- //Output checkboxes
177
- $fields = array(
178
- 'disable_wptexturize' => 'Disable wptexturize',
179
- 'disable_wpautop' => 'Disable automatic paragraphs',
180
- 'disable_convert_chars' => 'Disable convert_chars',
181
- 'disable_convert_smilies' => 'Disable smilies',
182
- );
183
- $defaults = rawhtml_get_default_settings();
184
- foreach($fields as $field => $legend){
185
- $current_setting = get_post_meta($post->ID, '_'.$field, true);
186
- if ( $current_setting == '' ){
187
- $current_setting = get_post_meta($post->ID, $field, true);
188
- }
189
- if ( $current_setting == '' ){
190
- $current_setting = $defaults[$field];
191
- } else {
192
- $current_setting = (bool)intval($current_setting);
193
- }
194
- ?>
195
- <label for="rawhtml_<?php echo $field; ?>">
196
- <input type="checkbox" name="rawhtml_<?php echo $field; ?>" id="rawhtml_<?php echo $field; ?>" <?php
197
- if ($current_setting) echo ' checked="checked"';
198
- ?>/>
199
- <?php echo $legend; ?>
200
- </label>
201
- <br />
202
- <?php
203
- }
204
- }
205
-
206
- /* Saves post metadata */
207
- function rawhtml_save_postdata( $post_id ){
208
- // verify this came from the our screen and with proper authorization,
209
- // because save_post can be triggered at other times
210
-
211
- if ( !isset($_POST['rawhtml_nonce']) ){
212
- return $post_id;
213
- }
214
-
215
- if ( !wp_verify_nonce( $_POST['rawhtml_nonce'], plugin_basename(__FILE__) )) {
216
- return $post_id;
217
- }
218
-
219
- if ( 'page' == $_POST['post_type'] ) {
220
- if ( !current_user_can( 'edit_page', $post_id ))
221
- return $post_id;
222
- } else {
223
- if ( !current_user_can( 'edit_post', $post_id ))
224
- return $post_id;
225
- }
226
-
227
- // OK, we're authenticated: we need to find and save the data
228
- $fields = array('disable_wpautop', 'disable_wptexturize', 'disable_convert_chars', 'disable_convert_smilies');
229
- foreach ( $fields as $field ){
230
- if ( !empty($_POST['rawhtml_'.$field]) ){
231
- update_post_meta($post_id, '_'.$field, '1');
232
- } else {
233
- update_post_meta($post_id, '_'.$field, '0');
234
- };
235
- }
236
-
237
- return true;
238
- }
239
-
240
- //Add our panel to the "Screen Options" box
241
- add_screen_options_panel(
242
- 'rawhtml-default-settings', //Panel ID
243
- 'Raw HTML defaults', //Panel title.
244
- 'rawhtml_default_settings_panel', //The function that generates panel contents.
245
- array('post', 'page'), //Pages/screens where the panel is displayed.
246
- 'rawhtml_save_new_defaults', //The function that gets triggered when settings are submitted/saved.
247
- true //Auto-submit settings (via AJAX) when they change.
248
- );
249
-
250
- /**
251
- * Retrieve the default settings for our post/page meta box.
252
- * Settings are saved in user meta.
253
- *
254
- * @return array
255
- */
256
- function rawhtml_get_default_settings(){
257
- //By default, all tweaks are disabled
258
- $defaults = array(
259
- 'disable_wptexturize' => false,
260
- 'disable_wpautop' => false,
261
- 'disable_convert_chars' => false,
262
- 'disable_convert_smilies' => false,
263
- );
264
-
265
- if ( !function_exists('wp_get_current_user') || !function_exists('get_user_meta') ){
266
- return $defaults;
267
- }
268
-
269
- //Get current defaults, if any
270
- $user = wp_get_current_user();
271
- $user_defaults = get_user_meta($user->ID, 'rawhtml_defaults', true);
272
- if ( is_array($user_defaults) ){
273
- $defaults = array_merge($defaults, $user_defaults);
274
- }
275
-
276
- return $defaults;
277
- }
278
-
279
- /**
280
- * Update default settings for our post/page meta box.
281
- *
282
- * @param array $new_defaults
283
- * @return bool True on success, false on failure.
284
- */
285
- function rawhtml_set_default_settings($new_defaults){
286
- if ( !function_exists('wp_get_current_user') || !function_exists('update_user_meta') ){
287
- return false;
288
- }
289
-
290
- //Get current defaults, if any
291
- $user = wp_get_current_user();
292
- if ( isset($user) && $user && isset($user->ID) ){
293
- return update_user_meta($user->ID, 'rawhtml_defaults', $new_defaults);
294
- } else {
295
- return false;
296
- }
297
- }
298
-
299
- /**
300
- * Generate the "Raw HTML defaults" panel for Screen Options.
301
- *
302
- * @return string
303
- */
304
- function rawhtml_default_settings_panel(){
305
- $defaults = rawhtml_get_default_settings();
306
-
307
- //Output checkboxes
308
- $fields = array(
309
- 'disable_wptexturize' => 'Disable wptexturize',
310
- 'disable_wpautop' => 'Disable automatic paragraphs',
311
- 'disable_convert_chars' => 'Disable convert_chars',
312
- 'disable_convert_smilies' => 'Disable smilies',
313
- );
314
-
315
- $output = '<div class="metabox-prefs">';
316
- foreach($fields as $field => $legend){
317
- $esc_field = esc_attr($field);
318
- $output .= sprintf(
319
- '<label for="rawhtml_default-%s" style="line-height: 20px;">
320
- <input type="checkbox" name="rawhtml_default-%s" id="rawhtml_default-%s"%s>
321
- %s
322
- </label><br>',
323
- $esc_field,
324
- $esc_field,
325
- $esc_field,
326
- ($defaults[$field]?' checked="checked"':''),
327
- $legend
328
- );
329
- }
330
- $output .= "</div>";
331
-
332
- return $output;
333
- }
334
-
335
- /**
336
- * Process the "Raw HTML defaults" form fields and save new settings
337
- *
338
- * @param array $params
339
- * @return void
340
- */
341
- function rawhtml_save_new_defaults($params){
342
- //Get current defaults
343
- $defaults = rawhtml_get_default_settings();
344
-
345
- //Read new values from the submitted form
346
- foreach($defaults as $field => $old_value){
347
- if ( isset($params['rawhtml_default-'.$field]) && ($params['rawhtml_default-'.$field] == 'on') ){
348
- $defaults[$field] = true;
349
- } else {
350
- $defaults[$field] = false;
351
- }
352
- }
353
-
354
- //Store the new defaults
355
- rawhtml_set_default_settings($defaults);
356
  }
357
 
358
  ?>
3
  Plugin Name: Raw HTML capability
4
  Plugin URI: http://w-shadow.com/blog/2007/12/13/raw-html-in-wordpress/
5
  Description: Lets you enter raw HTML in your posts. You can also enable/disable smart quotes and other automatic formatting on a per-post basis.
6
+ Version: 1.4.1
7
  Author: Janis Elsts
8
  Author URI: http://w-shadow.com/blog/
9
  */
10
 
11
  /*
12
  Created by Janis Elsts (email : whiteshadow@w-shadow.com)
13
+ Licensed under the LGPL.
14
  */
15
 
16
+ define('RAWHTML_PLUGIN_FILE', __FILE__);
17
 
18
+ require 'include/tag-handler.php';
19
+ require 'include/formatting-override.php';
 
 
 
20
 
21
+ if ( is_admin() && file_exists(dirname(__FILE__).'/editor-plugin/init.php') ){
22
+ require 'editor-plugin/init.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  }
24
 
25
  ?>
readme.txt CHANGED
@@ -1,15 +1,19 @@
1
  === Raw HTML ===
2
  Contributors: whiteshadow
3
- Tags: posts, formatting, javascript, html, css, code
4
- Requires at least: 2.6
5
- Tested up to: 3.1
6
- Stable tag: 1.4
7
 
8
  Lets you use raw HTML or any other code in your posts. You can also disable smart quotes and other automatic formatting on a per-post basis.
9
 
10
  == Description ==
11
 
12
- This plugin lets you use raw HTML or any other code in your posts. One way to use it is to wrap a part of your post in special tags (below) to prevent WordPress from converting newlines to HTML paragraphs, escaping apostrophes and so on. This is very useful if you need to add a CSS block or JavaScript to your post.
 
 
 
 
13
 
14
  RawHTML will also add some new checkboxes to the "Edit" screen that let you disable certain WP filters on a per-post basis. This way you can :
15
 
@@ -18,24 +22,27 @@ RawHTML will also add some new checkboxes to the "Edit" screen that let you disa
18
  * Disable image smilies.
19
  * Disable convert_chars (this filter converts ampersands to HTML entities and "fixes" some Unicode characters).
20
 
21
- **Using the plugin**
 
 
22
 
23
- To prevent a part of your post or page from being filtered by WordPress, wrap it in `<!--start_raw-->...<!--end_raw-->` or `[RAW]...[/RAW]` tags. These two versions work exactly the same, but the latter may be handy if you're using the visual editor (not recommended).
24
 
25
  *Example :*
26
 
27
- `<!--start_raw-->
28
  This
29
 
30
  is
31
 
32
- a 'test'!
33
- <!--end_raw-->`
 
 
34
 
35
  **Notes**
36
 
37
- * I strongly recommend to turn off the visual editor when you want to edit a post that contains raw HTML/JS/CSS.
38
- * Personally, I prefer the `<!--start_raw-->...<!--end_raw-->` syntax. These tags are formed as HTML comments, which means they won't be visible to your visitors even if you deactivate the Raw HTML plugin. On the other hand. the `[RAW]...[/RAW]` tags would show up.
39
 
40
  == Installation ==
41
 
@@ -55,8 +62,12 @@ Open to the post editor and click the "Screen Options" button in the top-right p
55
 
56
  == Changelog ==
57
 
 
 
 
 
58
  = 1.4 =
59
- * To decrease UI clutter, post-level settings now use hidden custom fields.
60
 
61
  = 1.3 =
62
  * Added a new panel to the "Screen Options" box that lest you auto-enable specific RawHTML settings (e.g. "Disable automatic paragraphs") for all new or updated posts.
1
  === Raw HTML ===
2
  Contributors: whiteshadow
3
+ Tags: posts, formatting, javascript, html, css, code, disable
4
+ Requires at least: 2.8
5
+ Tested up to: 3.2.1
6
+ Stable tag: 1.4.1
7
 
8
  Lets you use raw HTML or any other code in your posts. You can also disable smart quotes and other automatic formatting on a per-post basis.
9
 
10
  == Description ==
11
 
12
+ Lets you disable automatic formatting like smart quotes and automatic paragraphs, and use raw HTML/JS/CSS code in your posts without WordPress messing it up.
13
+
14
+ [Upgrade to Pro version](http://wpplugins.com/plugin/850/raw-html-pro/)
15
+
16
+ With this plugin, you can wrap any part of your post in [raw]...[/raw] tags to prevent WordPress from converting newlines to HTML paragraphs, replacing apostrophes with typographic quotes and so on. This is very useful if you need to add a CSS block or JavaScript to your post.
17
 
18
  RawHTML will also add some new checkboxes to the "Edit" screen that let you disable certain WP filters on a per-post basis. This way you can :
19
 
22
  * Disable image smilies.
23
  * Disable convert_chars (this filter converts ampersands to HTML entities and "fixes" some Unicode characters).
24
 
25
+ Note: The free version only supports the HTML editor. Use [the premium version](http://wpplugins.com/plugin/850/raw-html-pro/) if you want to be able to switch between HTML and the Visual editor without WordPress mangling your content.
26
+
27
+ **Usage**
28
 
29
+ To prevent a part of your post or page from being filtered by WordPress, wrap it in `[raw]...[/raw]` or `<!--raw-->...<!--/raw-->` tags. These two versions work exactly the same, except that the latter won't be visible to your visitors even if you deactivate Raw HTML.
30
 
31
  *Example :*
32
 
33
+ `<!--raw-->
34
  This
35
 
36
  is
37
 
38
+ a "test"!
39
+ <!--/raw-->`
40
+
41
+ In this case, the tags will prevent WordPress from inserting paragraph breaks between "This", "is" and "a "test"", as well as ensure that the double quotes arround "test" are not converted to typographic (curly) quotes.
42
 
43
  **Notes**
44
 
45
+ Personally, I prefer the `<!--raw-->...<!--/raw-->` syntax. These tags are formed as HTML comments, which means they won't be visible to your visitors even if you deactivate the Raw HTML plugin. On the other hand. the `[raw]...[/raw]` tags would show up.
 
46
 
47
  == Installation ==
48
 
62
 
63
  == Changelog ==
64
 
65
+ = 1.4.1 =
66
+ * Tested on the latest Beta version of WordPress (3.2-beta2).
67
+ * Prefer `<!--raw-->...<!--/raw-->` over `<!--start_raw-->...<!--/end_raw-->`. The old syntax will continue to work, but you're encouraged to use either [raw] or `<!--raw-->` in the future as they're more internally consistent (and shorter).
68
+
69
  = 1.4 =
70
+ * To decrease UI clutter, post-level settings now use hidden custom fields.
71
 
72
  = 1.3 =
73
  * Added a new panel to the "Screen Options" box that lest you auto-enable specific RawHTML settings (e.g. "Disable automatic paragraphs") for all new or updated posts.