[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php # $Id: serendipity_event_s9ymarkup.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_s9ymarkup extends serendipity_event
  17  {
  18      var $title = PLUGIN_EVENT_S9YMARKUP_NAME;
  19  
  20      function introspect(&$propbag)
  21      {
  22          global $serendipity;
  23  
  24          $propbag->add('name',          PLUGIN_EVENT_S9YMARKUP_NAME);
  25          $propbag->add('description',   PLUGIN_EVENT_S9YMARKUP_DESC);
  26          $propbag->add('stackable',     false);
  27          $propbag->add('author',        'Serendipity Team');
  28          $propbag->add('version',       '1.3');
  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, 'frontend_comment' => 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          foreach($this->markup_elements as $element) {
  59              $conf_array[] = $element['name'];
  60          }
  61          $propbag->add('configuration', $conf_array);
  62      }
  63  
  64      function install() {
  65          serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
  66      }
  67  
  68      function uninstall() {
  69          serendipity_plugin_api::hook_event('backend_cache_purge', $this->title);
  70          serendipity_plugin_api::hook_event('backend_cache_entries', $this->title);
  71      }
  72  
  73      function generate_content(&$title) {
  74          $title = $this->title;
  75      }
  76  
  77  
  78      function introspect_config_item($name, &$propbag)
  79      {
  80          $propbag->add('type',        'boolean');
  81          $propbag->add('name',        constant($name));
  82          $propbag->add('description', sprintf(APPLY_MARKUP_TO, constant($name)));
  83          $propbag->add('default', 'true');
  84          return true;
  85      }
  86  
  87  
  88      function event_hook($event, &$bag, &$eventData) {
  89          global $serendipity;
  90  
  91          $hooks = &$bag->get('event_hooks');
  92  
  93          if (isset($hooks[$event])) {
  94              switch($event) {
  95                  case 'frontend_display':
  96  
  97                      foreach ($this->markup_elements as $temp) {
  98                          if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) &&
  99                              !$eventData['properties']['ep_disable_markup_' . $this->instance] &&
 100                              !isset($serendipity['POST']['properties']['disable_markup_' . $this->instance])) {
 101                              $element = $temp['element'];
 102                              $eventData[$element] = $this->_s9y_markup($eventData[$element]);
 103                          }
 104                      }
 105                      return true;
 106                      break;
 107  
 108                  case 'frontend_comment':
 109                      if (serendipity_db_bool($this->get_config('COMMENT', true))) {
 110                          echo '<div class="serendipity_commentDirection serendipity_comment_s9ymarkup">' . PLUGIN_EVENT_S9YMARKUP_TRANSFORM . '</div>';
 111                      }
 112                      return true;
 113                      break;
 114  
 115                  default:
 116                      return false;
 117              }
 118          } else {
 119              return false;
 120          }
 121      }
 122  
 123  
 124      function _s9y_markup($text) {
 125          $text = str_replace('\_', chr(1), $text);
 126          $text = preg_replace('/#([[:alnum:]]+?)#/','&\1;',$text);
 127          $text = preg_replace('/\b_([\S ]+?)_\b/','<u>\1</u>',$text);
 128          $text = str_replace(chr(1), '\_', $text);
 129  
 130          // bold
 131          $text = str_replace('\*',chr(1),$text);
 132          $text = str_replace('**',chr(2),$text);
 133          $text = preg_replace('/(\S)\*(\S)/','\1' . chr(1) . '\2',$text);
 134          $text = preg_replace('/\B\*([^*]+)\*\B/','<strong>\1</strong>',$text);
 135          $text = str_replace(chr(2),'**',$text);
 136          $text = str_replace(chr(1),'\*',$text);
 137  
 138          // $text = preg_replace('/\|([0-9a-fA-F]+?)\|([\S ]+?)\|/','<font color="\1">\2</font>',$text);
 139          $text = preg_replace('/\^([[:alnum:]]+?)\^/','<sup>\1</sup>',$text);
 140          $text = preg_replace('/\@([[:alnum:]]+?)\@/','<sub>\1</sub>',$text);
 141          $text = preg_replace('/([\\\])([*#_|^@%])/', '\2', $text);
 142  
 143          return $text;
 144  
 145      }
 146  }
 147  
 148  /* vim: set sts=4 ts=4 expandtab : */
 149  ?>


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