[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php # $Id: serendipity_plugin_comments.php 1803 2007-07-27 11:22:30Z brockhaus $
   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_plugin_comments extends serendipity_plugin
  12  {
  13      var $title = COMMENTS;
  14  
  15      function introspect(&$propbag)
  16      {
  17          global $serendipity;
  18  
  19          $this->title = $this->get_config('title', $this->title);
  20  
  21          $propbag->add('name',          COMMENTS);
  22          $propbag->add('description',   PLUGIN_COMMENTS_BLAHBLAH);
  23          $propbag->add('stackable',     true);
  24          $propbag->add('author',        'Garvin Hicking, Tadashi Jokagi, Judebert, G. Brockhaus');
  25          $propbag->add('version',       '1.11');
  26          $propbag->add('requirements',  array(
  27              'serendipity' => '0.8',
  28              'smarty'      => '2.6.7',
  29              'php'         => '4.1.0'
  30          ));
  31          $propbag->add('groups', array('FRONTEND_VIEWS'));
  32          $propbag->add('configuration', array(
  33                                               'title',
  34                                               'wordwrap',
  35                                               'max_chars',
  36                                               'max_entries',
  37                                               'dateformat',
  38                                               'viewmode'));
  39      }
  40  
  41      function introspect_config_item($name, &$propbag)
  42      {
  43          switch($name) {
  44              case 'viewmode':
  45                  $types = array(
  46                      'comments'   => COMMENTS,
  47                      'trackbacks' => TRACKBACKS,
  48                      'all'        => COMMENTS . ' + ' . TRACKBACKS
  49                  );
  50                  $propbag->add('type',        'select');
  51                  $propbag->add('name',        TYPE);
  52                  $propbag->add('description', '');
  53                  $propbag->add('select_values', $types);
  54                  $propbag->add('default',     'all');
  55                  break;
  56  
  57              case 'title':
  58                  $propbag->add('type',        'string');
  59                  $propbag->add('name',        TITLE);
  60                  $propbag->add('description', '');
  61                  $propbag->add('default',     COMMENTS);
  62                  break;
  63  
  64              case 'wordwrap':
  65                  $propbag->add('type', 'string');
  66                  $propbag->add('name', PLUGIN_COMMENTS_WORDWRAP);
  67                  $propbag->add('description', PLUGIN_COMMENTS_WORDWRAP_BLAHBLAH);
  68                  $propbag->add('default', 30);
  69                  break;
  70  
  71              case 'max_chars':
  72                  $propbag->add('type', 'string');
  73                  $propbag->add('name', PLUGIN_COMMENTS_MAXCHARS);
  74                  $propbag->add('description', PLUGIN_COMMENTS_MAXCHARS_BLAHBLAH);
  75                  $propbag->add('default', 120);
  76                  break;
  77  
  78              case 'max_entries':
  79                  $propbag->add('type', 'string');
  80                  $propbag->add('name', PLUGIN_COMMENTS_MAXENTRIES);
  81                  $propbag->add('description', PLUGIN_COMMENTS_MAXENTRIES_BLAHBLAH);
  82                  $propbag->add('default', 15);
  83                  break;
  84  
  85              case 'dateformat':
  86                  $propbag->add('type', 'string');
  87                  $propbag->add('name', GENERAL_PLUGIN_DATEFORMAT);
  88                  $propbag->add('description', sprintf(GENERAL_PLUGIN_DATEFORMAT_BLAHBLAH, '%a, %d.%m.%Y %H:%M'));
  89                  $propbag->add('default', '%a, %d.%m.%Y %H:%M');
  90                  break;
  91  
  92              default:
  93                      return false;
  94          }
  95          return true;
  96      }
  97  
  98      function generate_content(&$title)
  99      {
 100          global $serendipity;
 101          $title       = $this->get_config('title', $this->title);
 102          $max_entries = $this->get_config('max_entries');
 103          $max_chars   = $this->get_config('max_chars');
 104          $wordwrap    = $this->get_config('wordwrap');
 105          $dateformat  = $this->get_config('dateformat');
 106  
 107          if (!$max_entries || !is_numeric($max_entries) || $max_entries < 1) {
 108              $max_entries = 15;
 109          }
 110  
 111          if (!$max_chars || !is_numeric($max_chars) || $max_chars < 1) {
 112              $max_chars = 120;
 113          }
 114  
 115          if (!$wordwrap || !is_numeric($wordwrap) || $wordwrap < 1) {
 116              $wordwrap = 30;
 117          }
 118  
 119          if (!$dateformat || strlen($dateformat) < 1) {
 120              $dateformat = '%a, %d.%m.%Y %H:%M';
 121          }
 122  
 123          $viewtype = '';
 124          if ($this->get_config('viewmode') == 'comments') {
 125              $viewtype .= ' AND c.type = \'NORMAL\'';
 126          } elseif ($this->get_config('viewmode') == 'trackbacks') {
 127              $viewtype .= ' AND c.type = \'TRACKBACK\'';
 128          }
 129  
 130          $q = 'SELECT    c.body              AS comment,
 131                          c.timestamp         AS stamp,
 132                          c.author            AS user,
 133                          e.title             AS subject,
 134                          e.timestamp         AS entrystamp,
 135                          e.id                AS entry_id,
 136                          c.id                AS comment_id,
 137                          c.type              AS comment_type,
 138                          c.url               AS comment_url,
 139                          c.title             AS comment_title,
 140                          c.email             AS comment_email
 141                  FROM    '.$serendipity['dbPrefix'].'comments AS c,
 142                          '.$serendipity['dbPrefix'].'entries  AS e
 143                 WHERE    e.id = c.entry_id
 144                   AND    NOT (c.type = \'TRACKBACK\' AND c.author = \'' . serendipity_db_escape_string($serendipity['blogTitle']) . '\' AND c.title != \'\')
 145                   AND    c.status = \'approved\'
 146                          ' . $viewtype . '
 147              ORDER BY    c.timestamp DESC
 148              LIMIT ' . $max_entries;
 149          $sql = serendipity_db_query($q);
 150  
 151          if ($sql && is_array($sql)) {
 152              foreach($sql AS $key => $row) {
 153                  if (function_exists('mb_strimwidth')) {
 154                      $comment = mb_strimwidth(strip_tags($row['comment']), 0, $max_chars, " [...]", LANG_CHARSET);
 155                  } else {
 156                      $comments = wordwrap(strip_tags($row['comment']), $max_chars, '@@@', 1);
 157                      $aComment = explode('@@@', $comments);
 158                      $comment  = $aComment[0];
 159                      if (count($aComment) > 1) {
 160                          $comment .= ' [...]';
 161                      }
 162                  }
 163  
 164                  if ($row['comment_type'] == 'TRACKBACK' && $row['comment_url'] != '') {
 165                      $user = '<a class="highlight" href="' . htmlspecialchars(strip_tags($row['comment_url'])) . '" title="' . htmlspecialchars(strip_tags($row['comment_title'])) . '">' . htmlspecialchars(strip_tags($row['user'])) . '</a>';
 166                  } else {
 167                      $user = htmlspecialchars(strip_tags($row['user']));
 168                  }
 169  
 170                  $user = trim($user);
 171                  if (empty($user))
 172                  {
 173                      $user = PLUGIN_COMMENTS_ANONYMOUS;
 174                  }
 175  
 176                  if (function_exists('mb_strimwidth')) {
 177                      $pos = 0;
 178                      $parts = array();
 179                      $enc = LANG_CHARSET;
 180                      $comment_len = mb_strlen($comment, $enc);
 181                      while ($pos < $comment_len) {
 182                          $part = mb_strimwidth($comment, $pos, $wordwrap, '', $enc);
 183                          $pos += mb_strlen($part, $enc);
 184                          $parts[] = $part;
 185                      }
 186                      $comment = implode("\n", $parts);
 187                  } else {
 188                      $comment = wordwrap($comment, $wordwrap, "\n", 1);
 189                  }
 190                  $entry = array('comment' => $comment,
 191                                 'email'   => $row['comment_email'],
 192                                 'url'     => $row['comment_url'],
 193                                 'author'  => $row['user']);
 194                                 
 195                  // Let's help the BBCOde plugin a bit:
 196                  if (class_exists('serendipity_event_bbcode')) {
 197                      $entry['comment'] = preg_replace('@((\[.*)[\n\r]+(.*\]))+@imsU', '\2\3', $entry['comment']);
 198                      $entry['comment'] = preg_replace('@((\[.+\].*)[\r\n]+(.*\[/.+\]))+@imsU', '\2\3', $entry['comment']);
 199                  }
 200                  $addData = array('from' => 'serendipity_plugin_comments:generate_content');
 201                  serendipity_plugin_api::hook_event('frontend_display', $entry, $addData);
 202  
 203                  printf(
 204                    '<div class="plugin_comment_wrap">' . PLUGIN_COMMENTS_ABOUT . '</div>',
 205  
 206                    '<span class="plugin_comment_author">' . $user . '</span>',
 207                    ' <a class="highlight" href="' . serendipity_archiveURL($row['entry_id'], $row['subject'], 'baseURL', true, array('timestamp' => $row['entrystamp'])) .'#c' . $row['comment_id'] . '" title="' . htmlspecialchars($row['subject']) . '">'
 208                        . htmlspecialchars($row['subject'])
 209                        . '</a><br />' . "\n"
 210                        . '<span class="plugin_comment_date">' . htmlspecialchars(serendipity_strftime($dateformat, $row['stamp'])) . '</span><br />' . "\n"
 211                        . '<span class="plugin_comment_body">' . strip_tags($entry['comment'], '<br /><img><a>') . '</span>'
 212                        . '<br /><br /><br />' . "\n\n"
 213                  );
 214              }
 215          }
 216      }
 217  }
 218  
 219  /* 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