From: garvinhicking Date: Mon, 6 Feb 2006 15:20:50 +0000 (+0000) Subject: Improve mailentry plugin to send mails to specific category recipients X-Git-Tag: 1.0~115 X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=74c453b52b4c956df5ce924684019caf9229aa63;p=s9y.git Improve mailentry plugin to send mails to specific category recipients --- diff --git a/docs/NEWS b/docs/NEWS index 1399abd..1fbae73 100644 --- 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 diff --git a/include/admin/plugins.inc.php b/include/admin/plugins.inc.php index 4ff8776..ffe9a34 100644 --- a/include/admin/plugins.inc.php +++ b/include/admin/plugins.inc.php @@ -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')); diff --git a/include/functions_entries.inc.php b/include/functions_entries.inc.php index 665f573..1b7544e 100644 --- a/include/functions_entries.inc.php +++ b/include/functions_entries.inc.php @@ -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 { diff --git a/include/plugin_api.inc.php b/include/plugin_api.inc.php index c8dee12..55668aa 100644 --- a/include/plugin_api.inc.php +++ b/include/plugin_api.inc.php @@ -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 * diff --git a/plugins/serendipity_event_mailer/UTF-8/lang_de.inc.php b/plugins/serendipity_event_mailer/UTF-8/lang_de.inc.php index 0182fcc..5106c29 100644 --- a/plugins/serendipity_event_mailer/UTF-8/lang_de.inc.php +++ b/plugins/serendipity_event_mailer/UTF-8/lang_de.inc.php @@ -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'); diff --git a/plugins/serendipity_event_mailer/lang_de.inc.php b/plugins/serendipity_event_mailer/lang_de.inc.php index d8e0ad9..f8cf9f2 100644 --- a/plugins/serendipity_event_mailer/lang_de.inc.php +++ b/plugins/serendipity_event_mailer/lang_de.inc.php @@ -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'); diff --git a/plugins/serendipity_event_mailer/serendipity_event_mailer.php b/plugins/serendipity_event_mailer/serendipity_event_mailer.php index 7edd1f2..6cb9cbf 100644 --- a/plugins/serendipity_event_mailer/serendipity_event_mailer.php +++ b/plugins/serendipity_event_mailer/serendipity_event_mailer.php @@ -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) {