[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php # $Id: serendipity_event_mailer.php 1791 2007-07-20 09:20:03Z 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_mailer extends serendipity_event
  17  {
  18      var $title = PLUGIN_EVENT_MAILER_NAME;
  19      var $data  = array();
  20  
  21      function introspect(&$propbag)
  22      {
  23          global $serendipity;
  24  
  25          $propbag->add('name',          PLUGIN_EVENT_MAILER_NAME);
  26          $propbag->add('description',   PLUGIN_EVENT_MAILER_DESC);
  27          $propbag->add('stackable',     false);
  28          $propbag->add('author',        'Sebastian Nohn, Kristian Koehntopp, Garvin Hicking');
  29          $propbag->add('version',       '1.47');
  30          $propbag->add('requirements',  array(
  31              'serendipity' => '0.8',
  32              'smarty'      => '2.6.7',
  33              'php'         => '4.1.0'
  34          ));
  35          $propbag->add('event_hooks',    array(
  36              'backend_publish' => true,
  37              'backend_display' => true,
  38          ));
  39          $propbag->add('groups', array('FRONTEND_ENTRY_RELATED'));
  40  
  41          $config = array('what', 'mailto', 'includelink', 'striptags', 'convertp');
  42          $propbag->add('configuration', $config);
  43      }
  44  
  45      function performConfig(&$bag) {
  46          if (is_object($bag)) {
  47              $conf = $bag->get('configuration');
  48          }
  49  
  50          $this->data['categories'] = serendipity_fetchCategories('all');
  51          if (!is_array($this->data['categories'])) {
  52              return false;
  53          }
  54  
  55          foreach($this->data['categories'] AS $cat) {
  56              $conf[] = 'category_' . $cat['categoryid'];
  57              $this->data['cat'][$cat['categoryid']] = $cat;
  58          }
  59  
  60          if (is_object($bag)) {
  61              $bag->add('configuration', $conf);
  62          }
  63      }
  64  
  65      function introspect_config_item($name, &$propbag)
  66      {
  67          if (preg_match('@^category_([0-9]+)$@imsU', $name, $catid)) {
  68              $parent = '';
  69              if ($this->data['cat'][$catid[1]]['parentid'] > 0) {
  70                  $parent = " '" . $this->data['cat'][$this->data['cat'][$catid[1]]['parentid']]['category_name'] . "' -";
  71              }
  72              $propbag->add('type',        'string');
  73              $propbag->add('name',        CATEGORY . $parent . " '"  . $this->data['cat'][$catid[1]]['category_name'] . "'");
  74              $propbag->add('description', PLUGIN_EVENT_MAILER_RECIPIENTDESC);
  75              $propbag->add('default', '');
  76              return true;
  77          }
  78  
  79          switch($name) {
  80              case 'what':
  81                  $propbag->add('type',        'select');
  82                  $propbag->add('name',        CONTENT);
  83                  $propbag->add('description', '');
  84                  $propbag->add('select_values',
  85                      array(
  86                          'all'      => ENTRY_BODY . ' + ' . EXTENDED_BODY,
  87                          'body'     => ENTRY_BODY,
  88                          'extended' => EXTENDED_BODY,
  89                          'none'     => NONE
  90                      )
  91                  );
  92                  $propbag->add('default',     'all');
  93                  break;
  94  
  95              case 'mailto':
  96                  $propbag->add('type',        'string');
  97                  $propbag->add('name',        PLUGIN_EVENT_MAILER_RECIPIENT);
  98                  $propbag->add('description', PLUGIN_EVENT_MAILER_RECIPIENTDESC);
  99                  $propbag->add('default', '');
 100                  break;
 101  
 102              case 'includelink':
 103                  $propbag->add('type',        'boolean');
 104                  $propbag->add('name',        PLUGIN_EVENT_MAILER_LINK);
 105                  $propbag->add('description', PLUGIN_EVENT_MAILER_LINKDESC);
 106                  $propbag->add('default',     'false');
 107                  break;
 108  
 109              case 'striptags':
 110                  $propbag->add('type',        'boolean');
 111                  $propbag->add('name',        PLUGIN_EVENT_MAILER_STRIPTAGS);
 112                  $propbag->add('description', PLUGIN_EVENT_MAILER_STRIPTAGSDESC);
 113                  $propbag->add('default',     'false');
 114                  break;
 115  
 116              case 'convertp':
 117                  $propbag->add('type',        'boolean');
 118                  $propbag->add('name',        PLUGIN_EVENT_MAILER_CONVERTP);
 119                  $propbag->add('description', PLUGIN_EVENT_MAILER_CONVERTPDESC);
 120                  $propbag->add('default',     'false');
 121                  break;
 122  
 123              default:
 124                  break;
 125          }
 126  
 127          return true;
 128      }
 129  
 130      function generate_content(&$title) {
 131          $title = $this->title;
 132      }
 133  
 134      function event_hook($event, &$bag, &$eventData) {
 135          global $serendipity;
 136  
 137          $hooks = &$bag->get('event_hooks');
 138  
 139          if (isset($hooks[$event])) {
 140              switch($event) {
 141                  case 'backend_display':
 142                      if (isset($serendipity['POST']['properties']['mailto'])) {
 143                          $mailto = $serendipity['POST']['properties']['mailto'];
 144                      } else {
 145                          $mailto = $this->get_config('mailto');
 146                      }
 147  
 148  ?>
 149                      <fieldset style="margin: 5px">
 150                          <legend><?php echo PLUGIN_EVENT_MAILER_NAME; ?></legend>
 151                              <input class="input_checkbox" type="checkbox" name="serendipity[properties][sendentry]" id="properties_sendentry" value="true" checked="checked" />
 152                              <label title="<?php echo PLUGIN_EVENT_MAILER_SENDING; ?>" for="properties_sendentry">&nbsp;<?php echo PLUGIN_EVENT_MAILER_ISTOSENDIT; ?></label><br />
 153                              <label title="<?php echo PLUGIN_EVENT_MAILER_RECIPIENT; ?>" for="properties_mailto">&nbsp;<?php echo PLUGIN_EVENT_MAILER_RECIPIENTS; ?>&nbsp;&nbsp;</label>&nbsp;
 154                              <input class="input_textbox" type="text" name="serendipity[properties][mailto]" id="properties_mailto" value="<?php echo htmlspecialchars($mailto); ?>" />
 155                      </fieldset>
 156  <?php
 157                      break;
 158  
 159                  case 'backend_publish':
 160                      if (isset($serendipity['POST']['properties']) && !isset($serendipity['POST']['properties']['sendentry'])) {
 161                          echo PLUGIN_EVENT_MAILER_NOTSENDDECISION . '<br />';
 162                      } else {
 163                          $mails = explode(' ', $this->get_config('mailto'));
 164                          $to = array();
 165                          foreach($mails AS $mailto) {
 166                              $mailto = trim($mailto);
 167                              if (!empty($mailto)) {
 168                                  $to[] = $mailto;
 169                              }
 170                          }
 171  
 172                          $this->performConfig($to);
 173                          if (is_array($this->data['cat'])) {
 174                              $selected = array();
 175                              if (is_array($eventData['categories'])) {
 176                                  foreach($eventData['categories'] AS $idx => $cid) {
 177                                      $selected[$cid] = true;
 178                                  }
 179                              }
 180  
 181                              foreach($this->data['cat'] AS $cid => $cat) {
 182                                  $mailto = trim($this->get_config('category_' . $cid));
 183  
 184                                  if (!empty($mailto) && isset($selected[$cid])) {
 185                                      $tos = explode(' ', $mailto);
 186                                      foreach($tos AS $mailtopart) {
 187                                          $to[] = trim($mailtopart);
 188                                      }
 189                                  }
 190                              }
 191                          }
 192  
 193  
 194                          $mail = array(
 195                              'subject' => $eventData['title'],
 196                              'body'    => $eventData['body'] . $eventData['extended'],
 197      //                      'from'    => $serendipity['blogTitle'] . ' - ' . $eventData['author'] . ' <' . $serendipity['serendipityEmail'] . '>'
 198                              'from'    => $serendipity['serendipityEmail']
 199                          );
 200  
 201                          switch($this->get_config('what')) {
 202                              case 'all':
 203                                  $mail['body']     = $eventData['body'] . $eventData['extended'];
 204                              case 'body':
 205                                  $mail['body']     = $eventData['body'];
 206                                  break;
 207                              case 'extended':
 208                                  $mail['body']     = $eventData['extended'];
 209                                  break;
 210                              case 'none':
 211                                  $mail['body']     = '';
 212                          }
 213  
 214                          if (isset($serendipity['POST']['properties']['mailto'])) {
 215                              $mails = explode(' ', $serendipity['POST']['properties']['mailto']);
 216                              foreach($mails as $mailto) {
 217                                  $mailto = trim($mailto);
 218                                  if (!in_array($mailto, $to)) {
 219                                      $to[] = $mailto;
 220                                  }
 221                              }
 222                          }
 223  
 224                          if (serendipity_db_bool($this->get_config('convertp', false)) == true) {
 225                              $mail['body'] = str_replace('</p>', "</p>\n", $mail['body']);
 226                          }
 227  
 228                          if (serendipity_db_bool($this->get_config('striptags', false)) == true) {
 229                              $mail['body'] = preg_replace('§<a[^>]+href=["\']([^"\']*)["\'][^>]*>([^<]*)</a>§i', "$2 [$1]", $mail['body']);
 230                              $mail['body'] = preg_replace('§<img[^>]+src=["\']([^"\']*)["\'][^>]*>§i', "[" . IMAGE . ": $1]", $mail['body']);
 231                              $mail['body'] = strip_tags($mail['body']);
 232                          }
 233  
 234                          if (serendipity_db_bool($this->get_config('includelink', false)) == true) {
 235                              $mail['body'] = serendipity_archiveURL($eventData['id'], $eventData['title'], 'baseURL', true, array('timestamp' => $eventData['timestamp'])) . "\n\n" . $mail['body'];
 236                          }
 237  
 238                          foreach($to AS $mailto) {
 239                              if (!empty($mailto)) {
 240                                  echo htmlspecialchars($mailto) . '...<br />';
 241                                  serendipity_sendMail($mailto, $mail['subject'], $mail['body'], $mail['from']);
 242                              }
 243                          }
 244                      }
 245                      return true;
 246                      break;
 247  
 248                  default:
 249                      return false;
 250                      break;
 251              }
 252          } else {
 253              return false;
 254          }
 255      }
 256  }
 257  
 258  /* 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