pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

PHP pastebin - collaborative debugging tool View Help


Posted by _ck_ on Tue 2 Sep 19:48
report abuse | download | new post

  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.0b3mod
  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. // Arrays for the select tags we use often
  16. $format_select = array( 'wpautop' => 'Default (wpautop)',
  17.                         'textile1' => 'Textile 1',
  18.                         'textile2' => 'Textile 2',
  19.                         'markdown' => 'Markdown',
  20.                         'nl2br' => 'nl2br',
  21.                         'none' => 'No Formatting'
  22.                         );
  23.  
  24. $encoding_select = array(
  25.                         'wptexturize' => 'Default (wptexturize)',
  26.                         'smartypants' => 'Smarty Pants',
  27.                         'none' => 'No Character Encoding'
  28.                         );
  29.  
  30. function output_selects($dotext, $dochar, $format_var, $encoding_var) {
  31.         global $format_select, $encoding_select;
  32.  
  33.         echo('<select name="' . $format_var . '">' . "\n");
  34.         foreach ($format_select AS $formatkey => $formatval)
  35.                 echo('<option value="' . $formatkey . '"' . (($dotext == $formatkey) ? ' selected="selected"' : '') . '>' . $formatval . "</option>\n");
  36.         echo("</select>\n");
  37.  
  38.         echo('<select name="' . $encoding_var . '">' . "\n");
  39.         foreach ($encoding_select AS $encodingkey => $encodingval)
  40.                 echo('<option value="' . $encodingkey . '"' . (($dochar == $encodingkey) ? ' selected="selected"' : '') . '>' . $encodingval . "</option>\n");
  41.         echo("</select>\n");
  42. }
  43.  
  44. function tc_post($text) {
  45.         global $id;
  46.        
  47.         // Check if meta data already exists, otherwise use the defaults
  48.         $do_text = get_post_meta($id, '_tc_post_format', true);
  49.         if (!$do_text) $do_text = get_option('tc_post_format');
  50.  
  51.         $do_char =  get_post_meta($id, '_tc_post_encoding', true);
  52.         if (!$do_char) $do_char = get_option('tc_post_encoding');
  53.  
  54.         $text = tc_post_process($text, $do_text, $do_char);
  55.        
  56.         return $text;
  57. }
  58.  
  59. function tc_comment($text) {
  60.        
  61.         $do_text = get_option('tc_comment_format');
  62.         $do_char = get_option('tc_comment_encoding');
  63.        
  64.         $text = tc_post_process($text, $do_text, $do_char);
  65.        
  66.         return $text;
  67. }
  68.  
  69. function tc_post_process($text, $do_text='', $do_char='') {
  70.        
  71.         if($do_text == 'textile2') {
  72.                 require_once('text-control/textile2.php');
  73.                 $t = new Textile();
  74.                 $text = $t->process($text);
  75.                
  76.         } else if($do_text == 'textile1') {
  77.                 require_once('text-control/textile1.php');
  78.                 $text = textile($text);
  79.                
  80.         } else if($do_text == 'markdown') {
  81.                 require_once('text-control/markdown.php');
  82.                 $text = Markdown($text);
  83.                
  84.         } else if($do_text == 'wpautop') {
  85.                 $text = wpautop($text);
  86.                
  87.         } else if($do_text == 'nl2br') {
  88.                 $text = nl2br($text);
  89.                
  90.         } else if($do_text == 'none') {
  91.                 $text = $text;
  92.                
  93.         } else {
  94.                 $text = wpautop($text);
  95.         }
  96.        
  97.         if($do_char == 'smartypants') {
  98.                 require_once('text-control/smartypants.php');
  99.                 $text = SmartyPants($text);
  100.                
  101.         } else if($do_char == 'wptexturize') {
  102.                 $text = wptexturize($text);
  103.                
  104.         } else if($do_char == 'none') {
  105.                 $text = $text;
  106.                
  107.         } else {
  108.                 $text = wptexturize($text);
  109.         }
  110.        
  111.         return $text;
  112.        
  113. }
  114.  
  115.  
  116. remove_filter('the_content', 'wpautop');
  117. remove_filter('the_content', 'wptexturize');
  118. add_filter('the_content', 'tc_post');
  119.  
  120. remove_filter('the_excerpt', 'wpautop');
  121. remove_filter('the_excerpt', 'wptexturize');
  122. add_filter('the_excerpt', 'tc_post');
  123.  
  124. remove_filter('comment_text', 'wpautop', 30);
  125. remove_filter('comment_text', 'wptexturize');
  126. add_filter('comment_text', 'tc_comment');
  127.  
  128.  
  129.  
  130. function tc_post_option_page() {
  131.         global $wpdb;
  132. ?>
  133.  
  134. <div class="wrap">
  135.         <h2>Text Control Settings</h2>
  136.         <p>Set up the default settings for your blog text formatting.</p>
  137.        
  138.         <?php
  139.        
  140.         if( $_POST['tc_post_format'] && $_POST['tc_post_encoding'] ) {
  141.                 // set the post formatting options
  142.                 update_option('tc_post_format', $_POST['tc_post_format']);
  143.                 update_option('tc_post_encoding', $_POST['tc_post_encoding']);
  144.                
  145.                 echo '<div class="updated"><p>Post/Excerpt formatting updated.</p></div>';
  146.                
  147.         }
  148.        
  149.         if( $_POST['tc_comment_format'] && $_POST['tc_comment_encoding'] ) {
  150.                 // set the comment formatting options
  151.                 update_option('tc_comment_format', $_POST['tc_comment_format']);
  152.                 update_option('tc_comment_encoding', $_POST['tc_comment_encoding']);
  153.                
  154.                 echo '<div class="updated"><p>Comment formatting updated.</p></div>';
  155.                
  156.         }
  157.        
  158.         ?>
  159.        
  160.         <form method="post">
  161.         <fieldset class="options">
  162.                 <legend>Posts &amp; Excerpts</legend>
  163.                
  164.                 <p>These will set up what the blog parses posts with by default unless over ridden on a per-post basis.</p>
  165.                
  166.                 <?php
  167.                
  168.                 $do_text = get_option('tc_post_format');
  169.                 $do_char = get_option('tc_post_encoding');
  170.                
  171.                 output_selects($do_text, $do_char, 'tc_post_format', 'tc_post_encoding');
  172.                 ?>
  173.                         <input type="submit" value="Change Default Post/Excerpt Formatting" />
  174.                        
  175.         </fieldset>
  176.         </form>
  177.        
  178.         <form method="post">
  179.         <fieldset class="options">
  180.                 <legend>Comments</legend>
  181.                 <p>All comments will be processed with these:</p>
  182.                
  183.                 <form method="post">
  184.                
  185.                 <?php
  186.                
  187.                 $do_text = get_option('tc_comment_format');
  188.                 $do_char = get_option('tc_comment_encoding');
  189.  
  190.                 output_selects($do_text, $do_char, 'tc_comment_format', 'tc_comment_encoding');
  191.                
  192.                 ?>
  193.                         <input type="submit" value="Change Default Comment Formatting" />
  194.                        
  195.         </fieldset>
  196.         </form>
  197.        
  198.        
  199. </div>
  200.  
  201.  
  202. <?php
  203.  
  204. }
  205.  
  206. function tc_post_add_options() {
  207.          add_options_page('Text Control Formatting Options', 'Text Control', 8, __FILE__, 'tc_post_option_page');
  208. }
  209.  
  210. add_action('admin_menu', 'tc_post_add_options');
  211.  
  212. add_action('edit_post', 'tc_post_edit_post');
  213. add_action('save_post', 'tc_post_edit_post');
  214. add_action('publish_post', 'tc_post_edit_post');
  215. add_action('publish_page', 'tc_post_edit_post');
  216.  
  217.  
  218. add_action('simple_edit_form', 'tc_post_options');
  219. add_action('edit_form_advanced', 'tc_post_options');
  220. add_action('edit_page_form', 'tc_post_options');
  221.  
  222.  
  223. function tc_post_edit_post($id) {
  224.         if ($_POST['tc_post_i_format']) {
  225.                 $format_stored = update_post_meta($id, '_tc_post_format', $_POST['tc_post_i_format']);
  226.                 if (!$format_stored) add_post_meta($id, '_tc_post_format', $_POST['tc_post_i_format']);
  227.         }
  228.  
  229.         if ($_POST['tc_post_i_encoding']) {
  230.                 $encode_stored = update_post_meta($id, '_tc_post_encoding', $_POST['tc_post_i_encoding']);
  231.                 if (!$encode_stored) add_post_meta($id, '_tc_post_encoding', $_POST['tc_post_i_encoding']);
  232.         }
  233. }
  234.  
  235. function tc_post_options($content) {   
  236.         $post_ID = (isset($_GET['post']))  ? intval($_GET['post']) : intval($_POST['post_ID']);
  237.        
  238.         // Check if meta data already exists, otherwise use the defaults
  239.        
  240.         $do_text = get_post_meta($post_ID, '_tc_post_format', true);
  241.         if (!$do_text) $do_text = get_option('tc_post_format');
  242.  
  243.         $do_char =  get_post_meta($post_ID, '_tc_post_encoding', true);
  244.         if (!$do_char) $do_char = get_option('tc_post_encoding');
  245.  
  246.         ?>
  247.                         <fieldset class="options">
  248.                                 <legend>Text Control</legend>
  249.                                 <p>Format this post with:
  250.                                
  251.         <?php
  252.                 output_selects($do_text, $do_char, 'tc_post_i_format', 'tc_post_i_encoding');
  253.         ?>
  254.                                 </p>
  255.                                        
  256.                         </fieldset>
  257.         <?php
  258. }
  259.  
  260. ?>

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post