Guest User

Untitled

a guest
Feb 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.69 KB | None | 0 0
  1. <?php # $Id: serendipity_event_nl2br.php 966 2006-02-21 12:36:55Z garvinhicking $
  2.  
  3. // Probe for a language include with constants. Still include defines later on, if some constants were missing
  4. $probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
  5. if (file_exists($probelang)) {
  6. include $probelang;
  7. }
  8.  
  9. include dirname(__FILE__) . '/lang_en.inc.php';
  10.  
  11. class serendipity_event_nl2br extends serendipity_event
  12. {
  13. var $title = PLUGIN_EVENT_NL2BR_NAME;
  14.  
  15. function introspect(&$propbag)
  16. {
  17. global $serendipity;
  18.  
  19. $propbag->add('name', PLUGIN_EVENT_NL2BR_NAME);
  20. $propbag->add('description', PLUGIN_EVENT_NL2BR_DESC);
  21. $propbag->add('stackable', false);
  22. $propbag->add('author', 'Serendipity Team');
  23. $propbag->add('version', '1.5');
  24. $propbag->add('requirements', array(
  25. 'serendipity' => '0.8',
  26. 'smarty' => '2.6.7',
  27. 'php' => '4.1.0'
  28. ));
  29. $propbag->add('cachable_events', array('frontend_display' => true));
  30. $propbag->add('event_hooks', array('frontend_display' => true));
  31. $propbag->add('groups', array('MARKUP'));
  32.  
  33. $this->markup_elements = array(
  34. array(
  35. 'name' => 'ENTRY_BODY',
  36. 'element' => 'body',
  37. ),
  38. array(
  39. 'name' => 'EXTENDED_BODY',
  40. 'element' => 'extended',
  41. ),
  42. array(
  43. 'name' => 'COMMENT',
  44. 'element' => 'comment',
  45. ),
  46. array(
  47. 'name' => 'HTML_NUGGET',
  48. 'element' => 'html_nugget',
  49. )
  50. );
  51.  
  52. $conf_array = array();
  53. $conf_array[] = 'isolate';
  54. foreach($this->markup_elements as $element) {
  55. $conf_array[] = $element['name'];
  56. }
  57. $propbag->add('configuration', $conf_array);
  58. }
  59.  
  60. function install() {
  61. serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
  62. }
  63.  
  64. function uninstall() {
  65. serendipity_plugin_api::hook_event('backend_cache_purge', $this->title);
  66. serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
  67. }
  68.  
  69. function generate_content(&$title) {
  70. $title = $this->title;
  71. }
  72.  
  73. function introspect_config_item($name, &$propbag)
  74. {
  75. switch($name) {
  76. case 'isolate':
  77. $propbag->add('type', 'string');
  78. $propbag->add('name', PLUGIN_EVENT_NL2BR_ISOLATE_TAGS);
  79. $propbag->add('description', PLUGIN_EVENT_NL2BR_ISOLATE_TAGS_DESC);
  80. $propbag->add('default', '');
  81. break;
  82.  
  83. default:
  84. $propbag->add('type', 'boolean');
  85. $propbag->add('name', constant($name));
  86. $propbag->add('description', sprintf(APPLY_MARKUP_TO, constant($name)));
  87. $propbag->add('default', 'true');
  88. }
  89. return true;
  90. }
  91.  
  92. function isolate($src, $regexp = NULL) {
  93. if($regexp) return preg_replace_callback($regexp, array($this, 'isolate'), $src);
  94. global $_buf;
  95. $_buf[] = $src[0];
  96. return "\001" . (count($_buf) - 1);
  97. }
  98.  
  99. function restore($text) {
  100. global $_buf;
  101. return preg_replace('~\001(\d+)~e', '$_buf[$1]', $text);
  102. }
  103.  
  104. function event_hook($event, &$bag, &$eventData) {
  105. global $serendipity;
  106. static $isolate = null;
  107. global $_buf;
  108.  
  109. $hooks = &$bag->get('event_hooks');
  110.  
  111. if (isset($hooks[$event])) {
  112. switch($event) {
  113. case 'frontend_display':
  114. if ($isolate === null) {
  115. $isolate = $this->get_config('isolate');
  116. $tags = (array)explode(',', $isolate);
  117. $isolate = array();
  118. foreach($tags AS $tag) {
  119. $tag = trim($tag);
  120. if (!empty($tag)) {
  121. $isolate[] = $tag;
  122. }
  123. }
  124. if (count($isolate) < 1) {
  125. $isolate = false;
  126. }
  127. }
  128.  
  129. foreach ($this->markup_elements as $temp) {
  130. if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) &&
  131. !$eventData['properties']['ep_disable_markup_' . $this->instance] &&
  132. !isset($serendipity['POST']['properties']['disable_markup_' . $this->instance]) &&
  133. !$eventData['properties']['ep_no_nl2br'] &&
  134. !isset($serendipity['POST']['properties']['ep_no_nl2br'])) {
  135.  
  136. $element = $temp['element'];
  137. if ($isolate) {
  138. $eventData[$element] = $this->isolate($eventData[$element], '~[<\[](textarea|pre|geshi).*?[>\]].*?[<\[]/\1[>\]]~si');
  139. $eventData[$element] = nl2br($eventData[$element]);
  140. $eventData[$element] = $this->restore($eventData[$element]);
  141. }else{
  142. $eventData[$element] = nl2br($eventData[$element]);
  143. }
  144. }
  145. }
  146. return true;
  147. break;
  148.  
  149. default:
  150. return false;
  151. }
  152.  
  153. } else {
  154. return false;
  155. }
  156. }
  157. }
  158.  
  159. /* vim: set sts=4 ts=4 expandtab : */
  160. ?>
Add Comment
Please, Sign In to add comment