[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/plugins/serendipity_event_textile/ -> serendipity_event_textile.php (source)

   1  <?php # $Id: serendipity_event_textile.php 1528 2006-12-01 08:58:47Z garvinhicking $
   2  
   3  require_once  S9Y_INCLUDE_PATH . 'plugins/serendipity_event_textile/textile.php';
   4  
   5  
   6  if (IN_serendipity !== true) {
   7      die ("Don't hack!");
   8  }
   9  
  10  // Probe for a language include with constants. Still include defines later on, if some constants were missing
  11  $probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
  12  if (file_exists($probelang)) {
  13      include $probelang;
  14  }
  15  
  16  include dirname(__FILE__) . '/lang_en.inc.php';
  17  
  18  class serendipity_event_textile extends serendipity_event
  19  {
  20      var $title = PLUGIN_EVENT_TEXTILE_NAME;
  21  
  22      function introspect(&$propbag)
  23      {
  24          global $serendipity;
  25  
  26          $propbag->add('name',          PLUGIN_EVENT_TEXTILE_NAME);
  27          $propbag->add('description',   PLUGIN_EVENT_TEXTILE_DESC);
  28          $propbag->add('stackable',     false);
  29          $propbag->add('author',        'Serendipity Team');
  30          $propbag->add('version',       '1.4');
  31          $propbag->add('requirements',  array(
  32              'serendipity' => '0.8',
  33              'smarty'      => '2.6.7',
  34              'php'         => '4.1.0'
  35          ));
  36          $propbag->add('cachable_events', array('frontend_display' => true));
  37          $propbag->add('event_hooks',   array('frontend_display' => true, 'frontend_comment' => true));
  38          $propbag->add('groups', array('MARKUP'));
  39  
  40          $propbag->add('preserve_tags',
  41            array(
  42              'php',
  43              'output',
  44              'name'
  45            )
  46          );
  47  
  48          $this->markup_elements = array(
  49              array(
  50                'name'     => 'ENTRY_BODY',
  51                'element'  => 'body',
  52              ),
  53              array(
  54                'name'     => 'EXTENDED_BODY',
  55                'element'  => 'extended',
  56              ),
  57              array(
  58                'name'     => 'COMMENT',
  59                'element'  => 'comment',
  60              ),
  61              array(
  62                'name'     => 'HTML_NUGGET',
  63                'element'  => 'html_nugget',
  64              )
  65          );
  66  
  67          $conf_array = array();
  68          foreach($this->markup_elements as $element) {
  69              $conf_array[] = $element['name'];
  70          }
  71          $propbag->add('configuration', $conf_array);
  72      }
  73  
  74  
  75      function generate_content(&$title) {
  76          $title = $this->title;
  77      }
  78  
  79      function install() {
  80          serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
  81      }
  82  
  83      function uninstall() {
  84          serendipity_plugin_api::hook_event('backend_cache_purge', $this->title);
  85          serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
  86      }
  87  
  88      function introspect_config_item($name, &$propbag)
  89      {
  90          $propbag->add('type',        'boolean');
  91          $propbag->add('name',        constant($name));
  92          $propbag->add('description', sprintf(APPLY_MARKUP_TO, constant($name)));
  93          $propbag->add('default', 'true');
  94          return true;
  95      }
  96  
  97  
  98      function event_hook($event, &$bag, &$eventData) {
  99          global $serendipity;
 100  
 101          $hooks = &$bag->get('event_hooks');
 102  
 103          if (isset($hooks[$event])) {
 104              switch($event) {
 105                case 'frontend_display':
 106  
 107                  $preserve_tags = &$bag->get('preserve_tags');
 108  
 109                  foreach ($this->markup_elements as $temp) {
 110                      if (serendipity_db_bool($this->get_config($temp['name'], true))) {
 111                          if ($eventData['properties']['ep_disable_markup_' . $this->instance] ||
 112                              isset($serendipity['POST']['properties']['disable_markup_' . $this->instance])) {
 113                              continue;
 114                          }
 115                          $element = $temp['element'];
 116  
 117          /* find all the tags and store them in $blocks */
 118  
 119                          $blocks = array();
 120                          foreach($preserve_tags as $tag) {
 121                              if (preg_match_all('/(<'.$tag.'[^>]?>.*<\/'.$tag.'>)/msU', $eventData[$element], $matches )) {
 122                                  foreach($matches[1] as $match) {
 123                                      $blocks[] = $match;
 124                                  }
 125                              }
 126                          }
 127  
 128          /* replace all the blocks with some code */
 129  
 130                          foreach($blocks as $id=>$block) {
 131                              $eventData[$element] = str_replace($block, '@BLOCK::'.$id.'@', $eventData[$element]);
 132                          }
 133  
 134          /* textile it */
 135  
 136                          $eventData[$element] = textile($eventData[$element]);
 137  
 138          /* each block will now be "<code>BLOCK::2</code>"
 139           * so look for those place holders and replace
 140           * them with the original blocks */
 141  
 142                          if (preg_match_all('/<code>BLOCK::(\d+)<\/code>/', $eventData[$element], $matches )) {
 143                              foreach($matches[1] as $key=>$match) {
 144                                  $eventData[$element] = str_replace($matches[0][$key], $blocks[$match], $eventData[$element]);
 145                              }
 146                          }
 147  
 148          /* post-process each block */
 149  
 150                          foreach($preserve_tags as $tag) {
 151                              $method = '_process_tag_' . $tag;
 152                              if (method_exists($this,$method)) {
 153                                  if (preg_match_all('/<'.$tag.'[^>]?>(.*)<\/'.$tag.'>/msU', $eventData[$element], $matches )) {
 154                                      foreach($matches[1] as $key=>$match) {
 155                                          $eventData[$element] = str_replace($matches[0][$key], $this->$method($match), $eventData[$element]);
 156                                      }
 157                                  }
 158                              }
 159                          }
 160  
 161          /* end textile processing */
 162  
 163                      }
 164                  }
 165                  return true;
 166  
 167                  case 'frontend_comment':
 168                      if (serendipity_db_bool($this->get_config('COMMENT', true))) {
 169                          echo '<div class="serendipity_commentDirection serendipity_comment_textile">' . PLUGIN_EVENT_TEXTILE_TRANSFORM . '</div>';
 170                      }
 171                      return true;
 172                      break;
 173  
 174                  default:
 175                    return false;
 176              }
 177  
 178          } else {
 179  
 180              return false;
 181  
 182          }
 183  
 184      }
 185  
 186      function _process_tag_php($text) {
 187  
 188          $code = "<?php\n" . trim($text) . "\n?>";
 189  
 190          # Using OB, as highlight_string() only supports
 191          # returning the result from 4.2.0
 192  
 193          ob_start();
 194          highlight_string($code);
 195          $highlighted = ob_get_contents();
 196          ob_end_clean();
 197  
 198          # Fix output to use CSS classes and wrap well
 199  
 200          $highlighted = '<p><div class="phpcode">' . str_replace(
 201              array(
 202                  '&nbsp;',
 203                  '<br />',
 204                  '<font color="',
 205                  '</font>',
 206                  "\n ",
 207                  'Ê '
 208              ),
 209              array(
 210                  ' ',
 211                  "<br />\n",
 212                  '<span class="',
 213                  '</span>',
 214                  "\n&#160;",
 215                  '&#160; '
 216              ),
 217              $highlighted
 218          ) . '</div></p>';
 219  
 220          return $highlighted;
 221  
 222      }
 223  
 224  
 225      function _process_tag_output($text) {
 226          return '<p><pre class="output">' . $text . '</pre></p>';
 227      }
 228  
 229      function _process_tag_name($text) {
 230          return '<a name="'. $text . '"></a>';
 231      }
 232  
 233  }
 234  
 235  /* vim: set sts=4 ts=4 expandtab : */


Généré le : Sat Nov 24 09:00:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics