Advertisement
statmanlouie

Untitled

Feb 3rd, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. <?php
  2.  
  3. function dirtysuds_content_taggedtext(){
  4.  
  5. $allowed_taggedtext_tags = array(
  6. 'p' => array(),
  7. 'br' => array(),
  8. 'b' => array(),
  9. 'strong' => array(),
  10. 'i' => array(),
  11. 'em' => array(),
  12. 'li' => array(),
  13. 'span' => array()
  14. );
  15.  
  16. $html_tags = array(
  17. '/&(#60|lt);/',
  18. '/&(#62|gt);/',
  19. '/&#61;/',
  20. '/[\n\r\f]+/',
  21. '/&#[xX]([0-9]{4})\;/',
  22. '/&#([0-9]+)\;/e',
  23. '/([\n\r\f]*<p>|<br[\s\/]*>[\s\t\n\r\f]+|[\s\t]*[\n\r\f]+[\s\t]*)/',
  24. '/<[\/\s]*br[\/\s]*>/',
  25. '/(<b>|<strong>)/',
  26. '/(<i>|<em>)/',
  27. '/<li>/',
  28. '/<\/li>/',
  29. '/<[\/]*(\!|span|p|a)>/',
  30. '/<\/[^\>]+>/',
  31. '/&(#60|lt);/',
  32. '/&#61;/',
  33. '/&(#62|gt);/',
  34. '/([\ ]|&nbsp;)+/',
  35. '/[\t]+[\ \t]*/',
  36. '/[\n\r\f]+/',
  37. '/\xc4([\x81-\xff])/e',
  38. '/\xc5([\x41-\xff])/e',
  39. );
  40.  
  41. $tagged_tags = array(
  42. '<',
  43. '>',
  44. '&',
  45. chr(10),
  46. '<0x$1>',
  47. "'<0x'.str_pad(dechex($1),4,'0',STR_PAD_LEFT).'>'",
  48. "\x0a<pstyle:NormalParagraphStyle>",
  49. '<0x000A>',
  50. '<ct:Bold>',
  51. '<ct:Italic>',
  52. '<bnlt:Bullet>',
  53. '<bnlt:>',
  54. '',
  55. '<ct:>',
  56. '\\<',
  57. chr(97),
  58. '\\>',
  59. ' ',
  60. chr(9),
  61. chr(10),
  62. "'<0x'.str_pad(dechex(ord($1) + 128),4,'0',STR_PAD_LEFT).'>'",
  63. "'<0x'.str_pad(dechex(ord($1) + 192),4,'0',STR_PAD_LEFT).'>'",
  64. );
  65.  
  66. remove_all_filters('loop_end');
  67.  
  68. function spacing() {
  69. echo "<br/>";
  70. }
  71.  
  72. function photo_credit()
  73. {
  74. echo "Photo credit: ";
  75. }
  76.  
  77. function photo_caption()
  78.  
  79. {
  80. echo "Cutline: ";
  81.  
  82. }
  83.  
  84. function suggested_headline() {
  85. echo "Suggested Headline: ";
  86. }
  87.  
  88. function by() {
  89. echo "By ";
  90. }
  91. // $content = photo_credit();
  92. // $content = spacing();
  93. // $content = photo_caption();
  94. // $content = spacing();
  95. $content = suggested_headline();
  96. $content = the_title();
  97. $content = spacing();
  98. $content = by();
  99. $content = the_author();
  100. $content = get_the_content();
  101. $content = strip_shortcodes($content);
  102.  
  103. // Change double line-breaks in the text into HTML paragraphs
  104. $content = wpautop($content);
  105.  
  106. // Strip all HTML except for $allowed_taggedtext_tags
  107. $content = wp_kses($content,$allowed_taggedtext_tags);
  108.  
  109. // Add Smart Quotes
  110. $content = wptexturize($content);
  111.  
  112. $content = trim($content);
  113.  
  114. //Convert special characters to HTML entities
  115.  
  116. $content = mb_convert_encoding($content,'UTF-8',get_bloginfo('charset'));
  117.  
  118. $content = htmlentities($content, ENT_QUOTES, 'UTF-8', false);
  119.  
  120. $content = preg_replace($html_tags,$tagged_tags,$content);
  121.  
  122. $countHtmlNamedEntities = preg_match_all("/\&[a-zA-Z]+;/",$content,$htmlNamedEntities);
  123.  
  124. for ($i=0;$i<$countHtmlNamedEntities;$i++)
  125. $content = str_replace(
  126. $htmlNamedEntities[0][$i],
  127. '<0x'.str_pad(dechex(ord(html_entity_decode($htmlNamedEntities[0][$i]))),4,'0',STR_PAD_LEFT).'>',
  128. $content
  129. );
  130.  
  131. // Some characters did not transcode well
  132. // We will replace them with blocks, so it is obvious that characters are missing
  133.  
  134. $content = strtr(
  135. $content,
  136. array(
  137. '<0x00ff>' => '<0x2588>',
  138. '<0x0026>' => '<0x2588>',
  139. )
  140. );
  141.  
  142. $content = trim($content);
  143. return $content;
  144. }
  145.  
  146. while ( have_posts() ) : the_post();
  147.  
  148. // We don't want any optimization plugins mistaking our output for HTML. Let's turn them off.
  149. ob_end_clean();
  150.  
  151. // We don't want the browser to render the file, only download it. Let's call it a binary file
  152. header('Content-type: binary/text; charset=utf-8');
  153.  
  154. // We need to give the file some sort of name. In this case, the author's last name and the title of the story
  155. // Don't forget to strip the spaces out. This makes it more compatible cross browser
  156.  
  157. header('Content-Disposition: filename='.preg_replace("/[^a-zA-Z0-9\-_]/", "",get_the_author_lastname().'-'.str_replace(' ','_',basename(get_permalink()))).'.txt;');
  158.  
  159.  
  160. ?><ANSI-MAC>
  161. <vsn:7><fset:InDesign-Roman><ctable:=<Black:COLOR:CMYK:Process:0,0,0,1>>
  162. <dps:NormalParagraphStyle=<Nextstyle:NormalParagraphStyle><cs:10.000000><cl:11.000000><ptr:18\,Left\,.\,0\,\;><cf:Times New Roman>><?php
  163. echo dirtysuds_content_taggedtext();
  164. endwhile;
  165. exit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement