PageRenderTime 54ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/usr/plugins/Textile2/Plugin.php

http://typecho.googlecode.com/
PHP | 121 lines | 61 code | 16 blank | 44 comment | 7 complexity | 7e40220bc4bede2aabbd79d2f020c373 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. * This is a wrapper for Jim Riggs' <a href="http://jimandlissa.com/project/textilephp">PHP implementation</a> of <a href="http://bradchoate.com/mt-plugins/textile">Brad Choate's Textile 2</a>. It is feature compatible with the MovableType plugin. <strong>Does not play well with the Markdown, Textile, or Textile 2 plugins that ship with WordPress.</strong> Packaged by <a href="http://idly.org/">Adam Gessaman</a>.
  4. *
  5. * @package Textile 2 (Improved)
  6. * @author Jim Riggs
  7. * @version 2.1.1
  8. * @dependence 9.9.2-*
  9. * @link http://jimandlissa.com/project/textilephp
  10. */
  11. require('Textile2/Textile.php');
  12. class Textile2_Plugin implements Typecho_Plugin_Interface
  13. {
  14. /**
  15. * ??????,??????,??????
  16. *
  17. * @access public
  18. * @return void
  19. * @throws Typecho_Plugin_Exception
  20. */
  21. public static function activate()
  22. {
  23. Typecho_Plugin::factory('Widget_Abstract_Contents')->excerpt = array('Textile2_Plugin', 'parse');
  24. Typecho_Plugin::factory('Widget_Abstract_Contents')->content = array('Textile2_Plugin', 'parse');
  25. Typecho_Plugin::factory('Widget_Abstract_Comments')->content = array('Textile2_Plugin', 'parse');
  26. }
  27. /**
  28. * ??????,??????,??????
  29. *
  30. * @static
  31. * @access public
  32. * @return void
  33. * @throws Typecho_Plugin_Exception
  34. */
  35. public static function deactivate(){}
  36. /**
  37. * ????????
  38. *
  39. * @access public
  40. * @param Typecho_Widget_Helper_Form $form ????
  41. * @return void
  42. */
  43. public static function config(Typecho_Widget_Helper_Form $form)
  44. {
  45. $version = new Typecho_Widget_Helper_Form_Element_Radio('version',
  46. array('MTTextile' => 'MTTextile - includes Brad Choates\' extensions.',
  47. 'Textile' => 'Textile for the Textile purist.'), 'MTTextile',
  48. 'Textile Flavor');
  49. $form->addInput($version->multiMode());
  50. $filters = new Typecho_Widget_Helper_Form_Element_Checkbox('filters',
  51. array('SmartyPants' => 'Apply SmartyPants (provides em and en dashes, and other typographic niceities)',
  52. 'EducateQuotes' => 'Apply Texturize (applies curly quotes)'),
  53. array('SmartyPants', 'EducateQuotes'), 'Text Filters');
  54. $form->addInput($filters->multiMode());
  55. $headerOffset = new Typecho_Widget_Helper_Form_Element_Select('headerOffset',
  56. array('0 (.h1 = .h1)', '1 (.h1 = .h2)', '2 (.h1 = .h3)', '3 (.h1 = .h4)', '4 (.h1 = .h5)', '5 (.h1 = .h6)'),
  57. 0, 'Header Offset');
  58. $form->addInput($headerOffset);
  59. $parsing = new Typecho_Widget_Helper_Form_Element_Checkbox('parsing',
  60. array('ClearLines' => 'Strip extra spaces from the end of each line.',
  61. 'PreserveSpaces' => 'Change double-spaces to the HTML entity for an em-space (&8195;).'),
  62. NULL, 'Parsing Options');
  63. $form->addInput($parsing->multiMode());
  64. $inputEncoding = new Typecho_Widget_Helper_Form_Element_Text('inputEncoding', NULL, Helper::options()->charset,
  65. _t('Input Character Encoding'));
  66. $inputEncoding->input->setAttribute('class', 'mini');
  67. $form->addInput($inputEncoding);
  68. $encoding = new Typecho_Widget_Helper_Form_Element_Text('encoding', NULL, Helper::options()->charset,
  69. _t('Output Character Encoding'));
  70. $encoding->input->setAttribute('class', 'mini');
  71. $form->addInput($encoding);
  72. }
  73. /**
  74. * ?????????
  75. *
  76. * @access public
  77. * @param Typecho_Widget_Helper_Form $form
  78. * @return void
  79. */
  80. public static function personalConfig(Typecho_Widget_Helper_Form $form){}
  81. /**
  82. * ??????
  83. *
  84. * @access public
  85. * @return void
  86. */
  87. public static function parse($text, $widget, $lastResult)
  88. {
  89. $text = empty($lastResult) ? $text : $lastResult;
  90. $settings = Helper::options()->plugin('Textile2');
  91. if ($settings->version == 'Textile') {
  92. $textile = new Textile;
  93. } else {
  94. $textile = new MTLikeTextile;
  95. }
  96. $textile->options['head_offset'] = $settings->headerOffset;
  97. $textile->options['char_encoding'] = $settings->encoding;
  98. $textile->options['input_encoding'] = $settings->inputEncoding;
  99. $textile->options['do_quotes'] = $settings->filters && in_array('EducateQuotes', $settings->filters);
  100. $textile->options['smarty_mode'] = $settings->filters && in_array('SmartyPants', $settings->filters);
  101. $textile->options['trim_spaces'] = $settings->parsing && in_array('ClearLines', $settings->parsing);
  102. $textile->options['preserve_spaces'] = $settings->parsing && in_array('PreserveSpaces', $settings->parsing);
  103. return $textile->process($text);
  104. }
  105. }