]> git.mjollnir.org Git - s9y.git/commitdiff
Improve mailentry plugin to send mails to specific category recipients
authorgarvinhicking <garvinhicking>
Mon, 6 Feb 2006 15:20:50 +0000 (15:20 +0000)
committergarvinhicking <garvinhicking>
Mon, 6 Feb 2006 15:20:50 +0000 (15:20 +0000)
docs/NEWS
include/admin/plugins.inc.php
include/functions_entries.inc.php
include/plugin_api.inc.php
plugins/serendipity_event_mailer/UTF-8/lang_de.inc.php
plugins/serendipity_event_mailer/lang_de.inc.php
plugins/serendipity_event_mailer/serendipity_event_mailer.php

index 1399abd56a855b46032adac00ed42cbc2268e482..1fbae730a9f053c65f0def33bc51fa7ef4955708 100644 (file)
--- a/docs/NEWS
+++ b/docs/NEWS
@@ -3,6 +3,11 @@
 Version 1.0-beta2 ()
 ------------------------------------------------------------------------
 
+   * Add new plugin API method "performConfig" for performing expensive
+     configuration options that shall not impact the usual blog
+     performance. Enhance mailentry plugin to send mails depending
+     on the associated category of an entry (garvinhicking)
+
    * Add ability to "preload" specific plugins and SQL entries into
      Serendipity. Just create a plugins/preload.txt file containing
      the plugins to load (one plugin per line, indicate plugin type
index 4ff877685fbd78a899bdf26cad05778eb554c80a..ffe9a3435b1860bfaebb5b56cbfede5fe0342158 100644 (file)
@@ -66,6 +66,11 @@ if (isset($_GET['serendipity']['plugin_to_conf'])) {
 
     $bag  = new serendipity_property_bag;
     $plugin->introspect($bag);
+
+    if (method_exists($plugin, 'performConfig')) {
+        $plugin->performConfig($bag);
+    }
+
     $name = htmlspecialchars($bag->get('name'));
     $desc = htmlspecialchars($bag->get('description'));
 
index 665f573a0b3f5cc57769127e17d510528797f1e5..1b7544e526759ac4e2f27d36e4ac4515ec81c5dd 100644 (file)
@@ -1182,6 +1182,7 @@ function serendipity_updertEntry($entry) {
 
     // Send publish tags if either a new article has been inserted from scratch, or if the entry was previously
     // stored as draft and is now published
+    $entry['categories'] =& $categories;
     if (!serendipity_db_bool($entry['isdraft']) && ($newEntry || serendipity_db_bool($_entry['isdraft']))) {
         serendipity_plugin_api::hook_event('backend_publish', $entry, $newEntry);
     } else {
index c8dee12f118b757d9dd4b89f7d615d12f2dc79ad..55668aa9a592b7d942659aab27accd73f11ed498 100644 (file)
@@ -1114,6 +1114,22 @@ class serendipity_plugin {
         $this->instance = $instance;
     }
 
+/**
+ * Perform configuration routines
+ *
+ * Called by Serendipity when the plugin is being configured.
+ * Can be used to query the database for configuration values that
+ * only need to be available for the global configuration and not
+ * on each page request.
+ *
+ * @access public
+ * @return true
+ */
+    function performConfig(&$bag)
+    {
+        return true;
+    }
+
 /**
  * Perform install routines
  *
index 0182fcc3515499fac15037e2d063c72105380343..5106c293becd6456f24932af671e465b2afd6faf 100644 (file)
@@ -11,3 +11,6 @@
         @define('PLUGIN_EVENT_MAILER_CONVERTP', 'HTML-Paragraphen in Leerzeilen wandeln?');
         @define('PLUGIN_EVENT_MAILER_CONVERTPDESC', 'Fügt einen Zeilenumbruch nach jedem HTML-Paragraphen ein. Besonders hilfreich im Zusammenhang mit der Option "HTML Entfernen", damit der Eintrag später selbst dann Umbrüche enthält, wenn sie nicht manuell eingegeben wurden.');
         @define('PLUGIN_EVENT_MAILER_RECIPIENTS', 'Mail-Empfänger (mehrere Empfänger mit Leerzeichen trennen)');
+        @define('PLUGIN_EVENT_MAILER_NOTSENDDECISION', 'Dieser Eintrage wurde nicht per E-Mail versendet, da diese Option deaktiviert wurde.');
+        @define('PLUGIN_EVENT_MAILER_SENDING', 'Versende');
+        @define('PLUGIN_EVENT_MAILER_ISTOSENDIT', 'Diesen Eintrag per E-Mail versenden');
index d8e0ad972dc670e686502ead001129af221b2821..f8cf9f2ed990cd51775c569a97b7473108b3a312 100644 (file)
@@ -11,3 +11,6 @@
         @define('PLUGIN_EVENT_MAILER_CONVERTP', 'HTML-Paragraphen in Leerzeilen wandeln?');
         @define('PLUGIN_EVENT_MAILER_CONVERTPDESC', 'Fügt einen Zeilenumbruch nach jedem HTML-Paragraphen ein. Besonders hilfreich im Zusammenhang mit der Option "HTML Entfernen", damit der Eintrag später selbst dann Umbrüche enthält, wenn sie nicht manuell eingegeben wurden.');
         @define('PLUGIN_EVENT_MAILER_RECIPIENTS', 'Mail-Empfänger (mehrere Empfänger mit Leerzeichen trennen)');
+        @define('PLUGIN_EVENT_MAILER_NOTSENDDECISION', 'Dieser Eintrage wurde nicht per E-Mail versendet, da diese Option deaktiviert wurde.');
+        @define('PLUGIN_EVENT_MAILER_SENDING', 'Versende');
+        @define('PLUGIN_EVENT_MAILER_ISTOSENDIT', 'Diesen Eintrag per E-Mail versenden');
index 7edd1f2ae36b760cbed32661ad50d24067b48a28..6cb9cbfb0c0f956baad2a3fe7f0b64df12bc31ee 100644 (file)
@@ -11,6 +11,7 @@ include dirname(__FILE__) . '/lang_en.inc.php';
 class serendipity_event_mailer extends serendipity_event
 {
     var $title = PLUGIN_EVENT_MAILER_NAME;
+    var $data  = array();
 
     function introspect(&$propbag)
     {
@@ -20,7 +21,7 @@ class serendipity_event_mailer extends serendipity_event
         $propbag->add('description',   PLUGIN_EVENT_MAILER_DESC);
         $propbag->add('stackable',     false);
         $propbag->add('author',        'Sebastian Nohn, Kristian Koehntopp, Garvin Hicking');
-        $propbag->add('version',       '1.42');
+        $propbag->add('version',       '1.43');
         $propbag->add('requirements',  array(
             'serendipity' => '0.8',
             'smarty'      => '2.6.7',
@@ -32,11 +33,40 @@ class serendipity_event_mailer extends serendipity_event
         ));
         $propbag->add('groups', array('FRONTEND_ENTRY_RELATED'));
 
-        $propbag->add('configuration', array('mailto', 'includelink', 'striptags', 'convertp'));
+        $config = array('mailto', 'includelink', 'striptags', 'convertp');
+        $propbag->add('configuration', $config);
+    }
+
+    function performConfig(&$bag) {
+        if (is_object($bag)) {
+            $conf = $bag->get('configuration');
+        }
+
+        $this->data['categories'] = serendipity_fetchCategories('all');
+        if (!is_array($this->data['categories'])) {
+            return false;
+        }
+        
+        foreach($this->data['categories'] AS $cat) {
+            $conf[] = 'category_' . $cat['categoryid'];
+            $this->data['cat'][$cat['categoryid']] = $cat;
+        }
+        
+        if (is_object($bag)) {
+            $bag->add('configuration', $conf);
+        }
     }
 
     function introspect_config_item($name, &$propbag)
     {
+        if (preg_match('@^category_([0-9]+)$@imsU', $name, $catid)) {
+            $propbag->add('type',        'string');
+            $propbag->add('name',        CATEGORY . " '"  . $this->data['cat'][$catid[1]]['category_name']);
+            $propbag->add('description', PLUGIN_EVENT_MAILER_RECIPIENTDESC);
+            $propbag->add('default', '');
+            return true;
+        }
+
         switch($name) {
             case 'mailto':
                 $propbag->add('type',        'string');
@@ -109,14 +139,36 @@ class serendipity_event_mailer extends serendipity_event
                         $mails = explode(' ', $this->get_config('mailto'));
                         $to = array();
                         foreach($mails AS $mailto) {
-                            $to[] = trim($mailto);
+                            $mailto = trim($mailto);
+                            if (!empty($mailto)) {
+                                $to[] = $mailto;
+                            }
                         }
+                        
+                        $this->performConfig($to);
+                        if (is_array($this->data['cat'])) {
+                            $selected = array();
+                            if (is_array($eventData['categories'])) {
+                                foreach($eventData['categories'] AS $idx => $cid) {
+                                    $selected[$cid] = true;
+                                }
+                            }
+
+                            foreach($this->data['cat'] AS $cid => $cat) {
+                                $mailto = trim($this->get_config('category_' . $cid));
+                                
+                                if (!empty($mailto) && isset($selected[$cid])) {
+                                    $to[] = $mailto;
+                                }
+                            }
+                        }
+
 
                         $mail = array(
-                        'subject' => $eventData['title'],
-                        'body'    => $eventData['body'] . $eventData['extended'],
+                            'subject' => $eventData['title'],
+                            'body'    => $eventData['body'] . $eventData['extended'],
     //                      'from'    => $serendipity['blogTitle'] . ' - ' . $eventData['author'] . ' <' . $serendipity['serendipityEmail'] . '>'
-                        'from'    => $serendipity['serendipityEmail']
+                            'from'    => $serendipity['serendipityEmail']
                         );
 
                         if (isset($serendipity['POST']['properties']['mailto'])) {
@@ -140,7 +192,7 @@ class serendipity_event_mailer extends serendipity_event
                         }
 
                         if (serendipity_db_bool($this->get_config('includelink', false)) == true) {
-                        $mail['body'] = serendipity_archiveURL($eventData['id'], $eventData['title'], 'baseURL', true, array('timestamp' => $eventData['timestamp'])) . "\n\n" . $mail['body'];
+                            $mail['body'] = serendipity_archiveURL($eventData['id'], $eventData['title'], 'baseURL', true, array('timestamp' => $eventData['timestamp'])) . "\n\n" . $mail['body'];
                         }
 
                         foreach($to AS $mailto) {