| 1 | <?php
|
|---|
| 2 | /*
|
|---|
| 3 | Plugin Name: Text Control
|
|---|
| 4 | Plugin URI: http://dev.wp-plugins.org/wiki/TextControl
|
|---|
| 5 | Description: Take total control of how your blog formats text: Textile 1+2, Markdown, AutoP, nl2br, SmartyPant, and Texturize. Blog wide, individual posts, and defaults for comments.
|
|---|
| 6 | Author: Jeff Minard
|
|---|
| 7 | Version: 2.0b1
|
|---|
| 8 | Author URI: http://thecodepro.com/
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | // Hey!
|
|---|
| 12 | // Get outta here! All configuration is done in WordPress
|
|---|
| 13 | // Check the "options > Text Control Config" in your admin section
|
|---|
| 14 |
|
|---|
| 15 | function tc_post($text) {
|
|---|
| 16 | global $id;
|
|---|
| 17 |
|
|---|
| 18 | /* Start with the default values */
|
|---|
| 19 | $do_text = get_option('tc_post_format');
|
|---|
| 20 | $do_char = get_option('tc_post_encoding');
|
|---|
| 21 |
|
|---|
| 22 | /* Now for the updated format that will take precedence */
|
|---|
| 23 | if ( get_post_meta($id, '_tc_post_format', true) ) {
|
|---|
| 24 | $do_text = get_post_meta($id, '_tc_post_format', true);
|
|---|
| 25 | }
|
|---|
| 26 | if( get_post_meta($id, '_tc_post_encoding', true) ) {
|
|---|
| 27 | $do_char = get_post_meta($id, '_tc_post_encoding', true);
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | $text = tc_post_process($text, $do_text, $do_char);
|
|---|
| 31 |
|
|---|
| 32 | return $text;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | function tc_comment($text) {
|
|---|
| 36 |
|
|---|
| 37 | $do_text = get_option('tc_comment_format');
|
|---|
| 38 | $do_char = get_option('tc_comment_encoding');
|
|---|
| 39 |
|
|---|
| 40 | $text = tc_post_process($text, $do_text, $do_char);
|
|---|
| 41 |
|
|---|
| 42 | return $text;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | function tc_post_process($text, $do_text='', $do_char='') {
|
|---|
| 46 |
|
|---|
| 47 | if($do_text == 'textile2') {
|
|---|
| 48 | require_once('text-control/textile2.php');
|
|---|
| 49 | $t = new Textile();
|
|---|
| 50 | $text = $t->process($text);
|
|---|
| 51 |
|
|---|
| 52 | } else if($do_text == 'textile1') {
|
|---|
| 53 | require_once('text-control/textile1.php');
|
|---|
| 54 | $text = textile($text);
|
|---|
| 55 |
|
|---|
| 56 | } else if($do_text == 'markdown') {
|
|---|
| 57 | require_once('text-control/markdown.php');
|
|---|
| 58 | $text = Markdown($text);
|
|---|
| 59 |
|
|---|
| 60 | } else if($do_text == 'wpautop') {
|
|---|
| 61 | $text = wpautop($text);
|
|---|
| 62 |
|
|---|
| 63 | } else if($do_text == 'nl2br') {
|
|---|
| 64 | $text = nl2br($text);
|
|---|
| 65 |
|
|---|
| 66 | } else if($do_text == 'none') {
|
|---|
| 67 | $text = $text;
|
|---|
| 68 |
|
|---|
| 69 | } else {
|
|---|
| 70 | $text = wpautop($text);
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | if($do_char == 'smartypants') {
|
|---|
| 74 | require_once('text-control/smartypants.php');
|
|---|
| 75 | $text = SmartyPants($text);
|
|---|
| 76 |
|
|---|
| 77 | } else if($do_char == 'wptexturize') {
|
|---|
| 78 | $text = wptexturize($text);
|
|---|
| 79 |
|
|---|
| 80 | } else if($do_char == 'none') {
|
|---|
| 81 | $text = $text;
|
|---|
| 82 |
|
|---|
| 83 | } else {
|
|---|
| 84 | $text = wptexturize($text);
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | return $text;
|
|---|
| 88 |
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 | remove_filter('the_content', 'wpautop');
|
|---|
| 93 | remove_filter('the_content', 'wptexturize');
|
|---|
| 94 | add_filter('the_content', 'tc_post');
|
|---|
| 95 |
|
|---|
| 96 | remove_filter('the_excerpt', 'wpautop');
|
|---|
| 97 | remove_filter('the_excerpt', 'wptexturize');
|
|---|
| 98 | add_filter('the_excerpt', 'tc_post');
|
|---|
| 99 |
|
|---|
| 100 | remove_filter('comment_text', 'wpautop', 30);
|
|---|
| 101 | remove_filter('comment_text', 'wptexturize');
|
|---|
| 102 | add_filter('comment_text', 'tc_comment');
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 | function tc_post_option_page() {
|
|---|
| 107 | global $wpdb;
|
|---|
| 108 | ?>
|
|---|
| 109 |
|
|---|
| 110 | <div class="wrap">
|
|---|
| 111 | <h2>Text Control Settings</h2>
|
|---|
| 112 | <p>Set up the default settings for your blog text formatting.</p>
|
|---|
| 113 |
|
|---|
| 114 | <?php
|
|---|
| 115 |
|
|---|
| 116 | if( $_POST['tc_post_format'] && $_POST['tc_post_encoding'] ) {
|
|---|
| 117 | // set the post formatting options
|
|---|
| 118 | update_option('tc_post_format', $_POST['tc_post_format']);
|
|---|
| 119 | update_option('tc_post_encoding', $_POST['tc_post_encoding']);
|
|---|
| 120 |
|
|---|
| 121 | echo '<div class="updated"><p>Post/Excerpt formatting updated.</p></div>';
|
|---|
| 122 |
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | if( $_POST['tc_comment_format'] && $_POST['tc_comment_encoding'] ) {
|
|---|
| 126 | // set the comment formatting options
|
|---|
| 127 | update_option('tc_comment_format', $_POST['tc_comment_format']);
|
|---|
| 128 | update_option('tc_comment_encoding', $_POST['tc_comment_encoding']);
|
|---|
| 129 |
|
|---|
| 130 | echo '<div class="updated"><p>Comment formatting updated.</p></div>';
|
|---|
| 131 |
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | ?>
|
|---|
| 135 |
|
|---|
| 136 | <form method="post">
|
|---|
| 137 | <fieldset class="options">
|
|---|
| 138 | <legend>Posts & Excerpts</legend>
|
|---|
| 139 |
|
|---|
| 140 | <p>These will set up what the blog parses posts with by default unless over ridden on a per-post basis.</p>
|
|---|
| 141 |
|
|---|
| 142 | <?php
|
|---|
| 143 |
|
|---|
| 144 | $do_text = get_option('tc_post_format');
|
|---|
| 145 | $do_char = get_option('tc_post_encoding');
|
|---|
| 146 |
|
|---|
| 147 | ?>
|
|---|
| 148 | <select name="tc_post_format">
|
|---|
| 149 | <option value="wpautop"<?php if($do_text == 'wpautop' OR $do_text == ''){ echo(' selected="selected"');}?>>Default (wpautop)</option>
|
|---|
| 150 | <option value="textile1"<?php if($do_text == 'textile1'){ echo(' selected="selected"');}?>>Textile 1</option>
|
|---|
| 151 | <option value="textile2"<?php if($do_text == 'textile2'){ echo(' selected="selected"');}?>>Textile 2</option>
|
|---|
| 152 | <option value="markdown"<?php if($do_text == 'markdown'){ echo(' selected="selected"');}?>>Markdown</option>
|
|---|
| 153 | <option value="nl2br"<?php if($do_text == 'nl2br'){ echo(' selected="selected"');}?>>nl2br</option>
|
|---|
| 154 | <option value="none"<?php if($do_text == 'none'){ echo(' selected="selected"');}?>>No Formatting</option>
|
|---|
| 155 | </select>
|
|---|
| 156 |
|
|---|
| 157 | <select name="tc_post_encoding">
|
|---|
| 158 | <option value="wptexturize"<?php if($do_char == 'wptexturize'){ echo(' selected="selected"');}?>>Default (wptexturize)</option>
|
|---|
| 159 | <option value="smartypants"<?php if($do_char == 'smartypants'){ echo(' selected="selected"');}?>>Smarty Pants</option>
|
|---|
| 160 | <option value="none"<?php if($do_char == 'none'){ echo(' selected="selected"');}?>>No Character Encoding</option>
|
|---|
| 161 | </select>
|
|---|
| 162 |
|
|---|
| 163 | <input type="submit" value="Change Default Post/Excerpt Formatting" />
|
|---|
| 164 |
|
|---|
| 165 | </fieldset>
|
|---|
| 166 | </form>
|
|---|
| 167 |
|
|---|
| 168 | <form method="post">
|
|---|
| 169 | <fieldset class="options">
|
|---|
| 170 | <legend>Comments</legend>
|
|---|
| 171 | <p>All comments will be processed with these:</p>
|
|---|
| 172 |
|
|---|
| 173 | <form method="post">
|
|---|
| 174 |
|
|---|
| 175 | <?php
|
|---|
| 176 |
|
|---|
| 177 | $do_text = get_option('tc_comment_format');
|
|---|
| 178 | $do_char = get_option('tc_comment_encoding');
|
|---|
| 179 |
|
|---|
| 180 | ?>
|
|---|
| 181 | <select name="tc_comment_format">
|
|---|
| 182 | <option value="wpautop"<?php if($do_text == 'wpautop' OR $do_text == ''){ echo(' selected="selected"');}?>>Default (wpautop)</option>
|
|---|
| 183 | <option value="textile1"<?php if($do_text == 'textile1'){ echo(' selected="selected"');}?>>Textile 1</option>
|
|---|
| 184 | <option value="textile2"<?php if($do_text == 'textile2'){ echo(' selected="selected"');}?>>Textile 2</option>
|
|---|
| 185 | <option value="markdown"<?php if($do_text == 'markdown'){ echo(' selected="selected"');}?>>Markdown</option>
|
|---|
| 186 | <option value="nl2br"<?php if($do_text == 'nl2br'){ echo(' selected="selected"');}?>>nl2br</option>
|
|---|
| 187 | <option value="none"<?php if($do_text == 'none'){ echo(' selected="selected"');}?>>No Formatting</option>
|
|---|
| 188 | </select>
|
|---|
| 189 |
|
|---|
| 190 | <select name="tc_comment_encoding">
|
|---|
| 191 | <option value="wptexturize"<?php if($do_char == 'wptexturize'){ echo(' selected="selected"');}?>>Default (wptexturize)</option>
|
|---|
| 192 | <option value="smartypants"<?php if($do_char == 'smartypants'){ echo(' selected="selected"');}?>>Smarty Pants</option>
|
|---|
| 193 | <option value="none"<?php if($do_char == 'none'){ echo(' selected="selected"');}?>>No Character Encoding</option>
|
|---|
| 194 | </select>
|
|---|
| 195 |
|
|---|
| 196 | <input type="submit" value="Change Default Comment Formatting" />
|
|---|
| 197 |
|
|---|
| 198 | </fieldset>
|
|---|
| 199 | </form>
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 | </div>
|
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 | <?php
|
|---|
| 206 |
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | function tc_post_add_options() {
|
|---|
| 210 | add_options_page('Text Control Formatting Options', 'Text Control Config', 8, __FILE__, 'tc_post_option_page');
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | add_action('admin_menu', 'tc_post_add_options');
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 | add_filter('edit_post', 'tc_post_edit_post');
|
|---|
| 220 | add_filter('publish_post', 'tc_post_edit_post');
|
|---|
| 221 | add_filter('admin_footer', 'tc_post_admin_footer');
|
|---|
| 222 |
|
|---|
| 223 | function tc_post_edit_post($id) {
|
|---|
| 224 | global $wpdb, $id;
|
|---|
| 225 |
|
|---|
| 226 | if(!isset($id)) $id = $_REQUEST['post_ID'];
|
|---|
| 227 |
|
|---|
| 228 | if( $id && $_POST['tc_post_i_format'] && $_POST['tc_post_i_encoding'] ){
|
|---|
| 229 |
|
|---|
| 230 | $qry = "DELETE FROM {$wpdb->postmeta} WHERE Post_ID = {$id} AND meta_key = '_tc_post_format';";
|
|---|
| 231 | $wpdb->query($qry);
|
|---|
| 232 |
|
|---|
| 233 | $qry = "DELETE FROM {$wpdb->postmeta} WHERE Post_ID = {$id} AND meta_key = '_tc_post_encoding';";
|
|---|
| 234 | $wpdb->query($qry);
|
|---|
| 235 |
|
|---|
| 236 | $qry = "INSERT INTO {$wpdb->postmeta} (Post_ID, meta_key, meta_value) VALUES ({$id}, '_tc_post_format', '$_POST[tc_post_i_format]');";
|
|---|
| 237 | $wpdb->query($qry);
|
|---|
| 238 |
|
|---|
| 239 | $qry = "INSERT INTO {$wpdb->postmeta} (Post_ID, meta_key, meta_value) VALUES ({$id}, '_tc_post_encoding', '$_POST[tc_post_i_encoding]');";
|
|---|
| 240 | $wpdb->query($qry);
|
|---|
| 241 |
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | }
|
|---|
| 245 |
|
|---|
| 246 | function tc_post_admin_footer($content) {
|
|---|
| 247 | global $id;
|
|---|
| 248 |
|
|---|
| 249 | if(!isset($id)) $id = $_REQUEST['post'];
|
|---|
| 250 |
|
|---|
| 251 | // Are we on the right page?
|
|---|
| 252 | if(preg_match('|post.php|i', $_SERVER['SCRIPT_NAME']) && $_REQUEST['action'] == 'edit' )
|
|---|
| 253 | {
|
|---|
| 254 | if(isset($_REQUEST['post'])) {
|
|---|
| 255 |
|
|---|
| 256 | $do_text = get_option('tc_post_format');
|
|---|
| 257 | $do_char = get_option('tc_post_encoding');
|
|---|
| 258 |
|
|---|
| 259 | if ( get_post_meta($id, '_tc_post_format', true) ) {
|
|---|
| 260 | $do_text = get_post_meta($id, '_tc_post_format', true);
|
|---|
| 261 | }
|
|---|
| 262 | if( get_post_meta($id, '_tc_post_encoding', true) ) {
|
|---|
| 263 | $do_char = get_post_meta($id, '_tc_post_encoding', true);
|
|---|
| 264 | }
|
|---|
| 265 |
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | ?>
|
|---|
| 269 | <div id="mtspp">
|
|---|
| 270 | <fieldset class="options">
|
|---|
| 271 | <legend>Text Control</legend>
|
|---|
| 272 | <p>Format this post with:
|
|---|
| 273 |
|
|---|
| 274 | <select name="tc_post_i_format">
|
|---|
| 275 | <option value="wpautop"<?php if($do_text == 'wpautop' OR $do_text == ''){ echo(' selected="selected"');}?>>Default (wpautop)</option>
|
|---|
| 276 | <option value="textile1"<?php if($do_text == 'textile1'){ echo(' selected="selected"');}?>>Textile 1</option>
|
|---|
| 277 | <option value="textile2"<?php if($do_text == 'textile2'){ echo(' selected="selected"');}?>>Textile 2</option>
|
|---|
| 278 | <option value="markdown"<?php if($do_text == 'markdown'){ echo(' selected="selected"');}?>>Markdown</option>
|
|---|
| 279 | <option value="nl2br"<?php if($do_text == 'nl2br'){ echo(' selected="selected"');}?>>nl2br</option>
|
|---|
| 280 | <option value="none"<?php if($do_text == 'none'){ echo(' selected="selected"');}?>>No Formatting</option>
|
|---|
| 281 | </select>
|
|---|
| 282 |
|
|---|
| 283 | <select name="tc_post_i_encoding">
|
|---|
| 284 | <option value="wptexturize"<?php if($do_char == 'wptexturize'){ echo(' selected="selected"');}?>>Default (wptexturize)</option>
|
|---|
| 285 | <option value="smartypants"<?php if($do_char == 'smartypants'){ echo(' selected="selected"');}?>>Smarty Pants</option>
|
|---|
| 286 | <option value="none"<?php if($do_char == 'none'){ echo(' selected="selected"');}?>>No Character Encoding</option>
|
|---|
| 287 | </select>
|
|---|
| 288 |
|
|---|
| 289 | <!--<input type="submit" value="Change Post Formatting" />-->
|
|---|
| 290 | </p>
|
|---|
| 291 |
|
|---|
| 292 | </fieldset>
|
|---|
| 293 | </div>
|
|---|
| 294 | <script language="JavaScript" type="text/javascript"><!--
|
|---|
| 295 | var placement = document.getElementById("titlediv");
|
|---|
| 296 | var substitution = document.getElementById("mtspp");
|
|---|
| 297 | var mozilla = document.getElementById&&!document.all;
|
|---|
| 298 | if(mozilla)
|
|---|
| 299 | placement.parentNode.appendChild(substitution);
|
|---|
| 300 | else placement.parentElement.appendChild(substitution);
|
|---|
| 301 | //--></script>
|
|---|
| 302 | <?php
|
|---|
| 303 |
|
|---|
| 304 |
|
|---|
| 305 | }
|
|---|
| 306 | }
|
|---|
| 307 |
|
|---|
| 308 | ?> |
|---|