[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php # $Id: serendipity_event_emoticate.php 1847 2007-08-14 11:57:51Z brockhaus $
   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_emoticate extends serendipity_event
  17  {
  18      var $title = PLUGIN_EVENT_EMOTICATE_NAME;
  19  
  20      function introspect(&$propbag)
  21      {
  22          global $serendipity;
  23  
  24          $propbag->add('name',          PLUGIN_EVENT_EMOTICATE_NAME);
  25          $propbag->add('description',   PLUGIN_EVENT_EMOTICATE_DESC);
  26          $propbag->add('stackable',     false);
  27          $propbag->add('author',        'Serendipity Team');
  28          $propbag->add('version',       '1.6');
  29          $propbag->add('requirements',  array(
  30              'serendipity' => '0.8',
  31              'smarty'      => '2.6.7',
  32              'php'         => '4.1.0'
  33          ));
  34          $propbag->add('groups', array('MARKUP'));
  35          $propbag->add('cachable_events', array('frontend_display' => true));
  36          $propbag->add('event_hooks',   array('frontend_display' => true, 'frontend_comment' => true));
  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          $conf_array = array();
  57          foreach($this->markup_elements as $element) {
  58              $conf_array[] = $element['name'];
  59          }
  60          $conf_array[] = 'extension';
  61          $propbag->add('configuration', $conf_array);
  62  
  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 getEmoticons() {
  75          global $serendipity;
  76  
  77          /* Avoid multiple runs of serendipity_getTemplateFile(),
  78             in other words - if we already have a list of smilies, don't bother looking for another */
  79          if (isset($this->smilies) && sizeof($this->smilies) != 0) {
  80              return $this->smilies;
  81          }
  82  
  83          /* Hijack global variable $serendipity['custom_emoticons'] if it exists */
  84          $hijack_file = serendipity_getTemplateFile('emoticons.inc.php', 'serendipityPath');
  85          if (@file_exists($hijack_file)) {
  86              @include $hijack_file; // This file contains $serendipity['custom_emoticons'] and maybe $serendipity['custom_emoticons_regexp']
  87              if (isset($serendipity['custom_emoticons']) && is_array($serendipity['custom_emoticons'])) {
  88                  $this->smilies = $serendipity['custom_emoticons'];
  89                  if (is_array($this->smilies) && (!isset($serendipity['custom_emoticons_regexp']) || !$serendipity['custom_emoticons_regexp'])) {
  90                      foreach($this->smilies AS $key => $val) {
  91                          unset($this->smilies[$key]);
  92                          $this->smilies[preg_quote($key, '/')] = $val;
  93                      }
  94                  }
  95              }
  96          }
  97  
  98          if (!isset($this->smilies)) {
  99              $ext = $this->get_config('extension', 'png');
 100              $this->smilies = array(
 101                  "\:'\("     => serendipity_getTemplateFile('img/emoticons/cry.'.$ext),
 102  
 103                  '\:\-?\)'   => serendipity_getTemplateFile('img/emoticons/smile.'.$ext),
 104  
 105                  '\:\-?\|'   => serendipity_getTemplateFile('img/emoticons/normal.'.$ext),
 106  
 107                  '\:\-?O'    => serendipity_getTemplateFile('img/emoticons/eek.'.$ext),
 108  
 109                  '\:\-?\('   => serendipity_getTemplateFile('img/emoticons/sad.'.$ext),
 110  
 111                  '8\-?\)'    => serendipity_getTemplateFile('img/emoticons/cool.'.$ext),
 112  
 113                  '\:\-?D'    => serendipity_getTemplateFile('img/emoticons/laugh.'.$ext),
 114  
 115                  '\:\-?P'    => serendipity_getTemplateFile('img/emoticons/tongue.'.$ext),
 116  
 117                  ';\-?\)'    => serendipity_getTemplateFile('img/emoticons/wink.'.$ext),
 118              );
 119          }
 120  
 121          return $this->smilies;
 122      }
 123  
 124      function humanReadableEmoticon($key) {
 125          return str_replace(array('-?', '\\'), array('-', ''), $key);
 126      }
 127  
 128      function generate_content(&$title) {
 129          $title = $this->title;
 130      }
 131  
 132      function example() {
 133          $s  = '<table cellspacing="5" style="margin-left: auto; margin-right: auto">';
 134          $s .= '<tr>';
 135          $i = 1;
 136          foreach($this->getEmoticons() as $key => $value) {
 137              $s .= '<td style="text-align: center">' . $this->humanReadableEmoticon($key) . '</td><td><img src="'. $value .'"></td>' . "\n";
 138              if ($i++ % 7 == 0) $s .= '</tr><tr>';
 139          }
 140          $s .= '</tr>';
 141          $s .= '</table>';
 142  
 143          return $s;
 144      }
 145  
 146      function introspect_config_item($name, &$propbag)
 147      {
 148          switch($name) {
 149          case 'extension':
 150              $propbag->add('type', 'string');
 151              $propbag->add('name',        PLUGIN_EVENT_EMOTICATE_EXTENSION);
 152              $propbag->add('description', PLUGIN_EVENT_EMOTICATE_EXTENSION_BLAHBLAH);
 153              $propbag->add('default', 'png');
 154              break;
 155          default:
 156              $propbag->add('type',        'boolean');
 157              $propbag->add('name',        constant($name));
 158              $propbag->add('description', sprintf(APPLY_MARKUP_TO, constant($name)));
 159              $propbag->add('default', 'true');
 160          }
 161          return true;
 162      }
 163  
 164  
 165      function event_hook($event, &$bag, &$eventData) {
 166          global $serendipity;
 167          $hooks = &$bag->get('event_hooks');
 168  
 169          if (isset($hooks[$event])) {
 170              switch($event) {
 171                  case 'frontend_display':
 172  
 173                      foreach ($this->markup_elements as $temp) {
 174                          if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) &&
 175                              !$eventData['properties']['ep_disable_markup_' . $this->instance] &&
 176                              !isset($serendipity['POST']['properties']['disable_markup_' . $this->instance])) {
 177                              $element = &$eventData[$temp['element']];
 178  
 179                              foreach ($this->getEmoticons() as $key => $value) {
 180                                  $element = preg_replace("/([\t\s\.\!>]+|^)" . $key . "([\t\s\!\.\)<]+|\$)/U",
 181                                      "$1<img src=\"$value\" alt=\"" . $this->humanReadableEmoticon($key) . "\" style=\"display: inline; vertical-align: bottom;\" class=\"emoticon\" />$2",
 182                                      $element);
 183                              }
 184                          }
 185                      }
 186                      return true;
 187                      break;
 188  
 189                  case 'frontend_comment':
 190                      if (serendipity_db_bool($this->get_config('COMMENT', true))) {
 191                          echo '<div class="serendipity_commentDirection serendipity_comment_emoticate">' . PLUGIN_EVENT_EMOTICATE_TRANSFORM . '</div>';
 192                      }
 193                      return true;
 194                      break;
 195  
 196                default:
 197                  return false;
 198              }
 199          } else {
 200              return false;
 201          }
 202      }
 203  
 204  }
 205  
 206  /* vim: set sts=4 ts=4 expandtab : */
 207  ?>


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