[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

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