[pLog-svn] r2770 - in plugins/trunk: . adminnotifier
adminnotifier/class adminnotifier/class/action
adminnotifier/class/view adminnotifier/templates
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Wed Jan 11 16:16:02 GMT 2006
Author: oscar
Date: 2006-01-11 16:16:02 +0000 (Wed, 11 Jan 2006)
New Revision: 2770
Added:
plugins/trunk/adminnotifier/
plugins/trunk/adminnotifier/class/
plugins/trunk/adminnotifier/class/action/
plugins/trunk/adminnotifier/class/action/adminnotifiershoweventlistaction.class.php
plugins/trunk/adminnotifier/class/action/adminnotifierupdateeventsaction.class.php
plugins/trunk/adminnotifier/class/view/
plugins/trunk/adminnotifier/class/view/admineventlistview.class.php
plugins/trunk/adminnotifier/locale/
plugins/trunk/adminnotifier/pluginadminnotifier.class.php
plugins/trunk/adminnotifier/templates/
plugins/trunk/adminnotifier/templates/eventlist.template
Log:
plugin that allows site administrators to receive an email every certain one of the configured
events occurs. The plugin supports all system events, even though it cannot be used to receive
notifications every time a new user registers via summary.php (because plugins don't work in
the summary)
Added: plugins/trunk/adminnotifier/class/action/adminnotifiershoweventlistaction.class.php
===================================================================
--- plugins/trunk/adminnotifier/class/action/adminnotifiershoweventlistaction.class.php 2006-01-11 15:46:29 UTC (rev 2769)
+++ plugins/trunk/adminnotifier/class/action/adminnotifiershoweventlistaction.class.php 2006-01-11 16:16:02 UTC (rev 2770)
@@ -0,0 +1,26 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/adminnotifier/class/view/admineventlistview.class.php" );
+
+ /**
+ * displays a list of events to be notified (obtained from the global list of
+ * available events
+ */
+ class AdminNotifierShowEventListAction extends SiteAdminAction
+ {
+
+ function AdminNotifierShowEventListAction( $actionInfo, $request )
+ {
+ $this->SiteAdminAction( $actionInfo, $request );
+ }
+
+ function perform()
+ {
+ $this->_view = new AdminEventListView( $this->_blogInfo );
+ $this->setCommonData();
+
+ return( true );
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/adminnotifier/class/action/adminnotifierupdateeventsaction.class.php
===================================================================
--- plugins/trunk/adminnotifier/class/action/adminnotifierupdateeventsaction.class.php 2006-01-11 15:46:29 UTC (rev 2769)
+++ plugins/trunk/adminnotifier/class/action/adminnotifierupdateeventsaction.class.php 2006-01-11 16:16:02 UTC (rev 2770)
@@ -0,0 +1,37 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
+ include_once( PLOG_CLASS_PATH."plugins/adminnotifier/class/view/admineventlistview.class.php" );
+ include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+
+ /**
+ * updates the list of events to be notified
+ */
+ class AdminNotifierUpdateEventsAction extends SiteAdminAction
+ {
+
+ function AdminNotifierUpdateEventsAction( $actionInfo, $request )
+ {
+ $this->SiteAdminAction( $actionInfo, $request );
+ }
+
+ function perform()
+ {
+ // read the data from the form
+ $events = $this->_request->getValue( "event" );
+
+ // save the settings in the db. We save this as global data (in the config table)
+ // because these settings will be common to all administrators
+ $config =& Config::getConfig();
+ $config->setValue( "plugin_adminnotifier_events", $events );
+ $config->save();
+
+ // reload the list
+ $this->_view = new AdminEventListView( $this->_blogInfo );
+ $this->_view->setSuccessMessage( $this->_locale->tr( "admin_notifier_settings_saved_ok" ));
+ $this->setCommonData();
+
+ return( true );
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/adminnotifier/class/view/admineventlistview.class.php
===================================================================
--- plugins/trunk/adminnotifier/class/view/admineventlistview.class.php 2006-01-11 15:46:29 UTC (rev 2769)
+++ plugins/trunk/adminnotifier/class/view/admineventlistview.class.php 2006-01-11 16:16:02 UTC (rev 2770)
@@ -0,0 +1,35 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/view/admin/adminplugintemplatedview.class.php" );
+ include_once( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
+
+ class AdminEventListView extends AdminPluginTemplatedView
+ {
+
+ var $_currentEvents;
+
+ function AdminEventListView( $blogInfo, $currentEvents = Array())
+ {
+ $this->AdminPluginTemplatedView( $blogInfo, "adminnotifier", "eventlist" );
+
+ $this->_currentEvents = $currentEvents;
+ }
+
+ function render()
+ {
+ // get a list with the defined events
+ $events = PluginManager::getDefinedEvents();
+ $this->setValue( "events", $events );
+
+ // and now a list with the events that should trigger notifications
+ $config =& Config::getConfig();
+ $currentEvents = $config->getValue( "plugin_adminnotifier_events", Array());
+ if( !is_array( $currentEvents ))
+ $currentEvents = Array();
+ $this->setValue( "currentEvents", $currentEvents );
+
+ // finally, render the view
+ parent::render();
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/adminnotifier/pluginadminnotifier.class.php
===================================================================
--- plugins/trunk/adminnotifier/pluginadminnotifier.class.php 2006-01-11 15:46:29 UTC (rev 2769)
+++ plugins/trunk/adminnotifier/pluginadminnotifier.class.php 2006-01-11 16:16:02 UTC (rev 2770)
@@ -0,0 +1,129 @@
+<?php
+ include_once( PLOG_CLASS_PATH."class/plugin/pluginbase.class.php" );
+
+ /**
+ * Sends notifications to administrators every time certain configurable events
+ * occur in the system, such as new blogs created, new users created, etc.
+ */
+ class PluginAdminNotifier extends PluginBase
+ {
+
+ function PluginAdminNotifier()
+ {
+ $this->PluginBase();
+
+ $this->id = "adminnotifier";
+ $this->desc = "Sends email notifications to administrations every time certain events occur";
+ $this->author = "The LifeType Project";
+
+ // register our actions
+ $this->registerAdminAction( "eventList", "AdminNotifierShowEventListAction" );
+ $this->registerAdminAction( "updateEvents", "AdminNotifierUpdateEventsAction" );
+
+ // register our menu options
+ $this->addMenuEntry( "/menu/adminSettings", "adminNotifierGroup", "", "", false, true );
+ $this->addMenuEntry( "/menu/adminSettings/adminNotifierGroup", "adminNotifier", "?op=eventList", "", false, true );
+
+ // register our notifications
+ $this->registerEvents();
+ }
+
+ function registerEvents()
+ {
+ // check our configuration and register as many event listeners as necessary
+ include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+ $config =& Config::getConfig();
+ $events = $config->getValue( "plugin_adminnotifier_events" );
+
+ foreach( $events as $eventId => $value ) {
+ // register those that are configured
+ $this->registerNotification( $eventId );
+ }
+ }
+
+ /**
+ * This method processes our event notifications
+ */
+ function process( $eventType, $params )
+ {
+ include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
+
+ // given the event id, let's get its string
+ $events = PluginManager::getDefinedEvents();
+ $eventList = array_flip( $events );
+ $eventName = $eventList[ $eventType ];
+
+ // build the message
+ $rg = $this->blogInfo->getBlogRequestGenerator();
+ $blogLink = $rg->blogLink();
+ $blogName = $this->blogInfo->getBlog();
+ $t = new Timestamp();
+ $timestamp = $t->getTimestamp();
+ $message = "Event: {$eventName}\n
+ \n
+ Generated by blog: {$blogName}\n
+ Link: {$blogLink}\n
+ \n
+ Timestamp: {$timestamp}";
+
+ // send the message to all administrators
+ $this->notifyAdmins( $message );
+ }
+
+ /**
+ * loads all the email addresses of all administrator users
+ * @private
+ * @return An array with email addresses
+ */
+ function getAdminEmailAddresses()
+ {
+ include_once( PLOG_CLASS_PATH."class/database/db.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
+ $prefix = Db::getPrefix();
+ $query = "SELECT DISTINCT u.id AS id, u.user AS user, u.email AS email
+ FROM {$prefix}users u, {$prefix}users_permissions p
+ WHERE p.permission_id = 1 AND u.id = p.user_id AND u.status = ".USER_STATUS_ACTIVE;
+
+ $db =& Db::getDb();
+ $result = $db->Execute( $query );
+ if( !$result )
+ return Array();
+
+ $admins = Array();
+ while( $row = $result->FetchRow()) {
+ $admins[] = $row["email"];
+ }
+
+ return( $admins );
+ }
+
+ /**
+ * Sends the notification email to administrators
+ * @param message The message to be sent to administrator users
+ * @private
+ */
+ function notifyAdmins( $message )
+ {
+ include_once( PLOG_CLASS_PATH."class/mail/emailservice.class.php" );
+ include_once( PLOG_CLASS_PATH."class/mail/emailmessage.class.php" );
+ include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
+
+ // build the message
+ $message = new EmailMessage();
+ $config =& Config::getConfig();
+ $message->setFrom( $config->getValue( "post_notification_source_address" ));
+ $message->setSubject( "LifeType AdminNotifier Notification" );
+ $message->setBody( $message );
+
+ // load all the administrator users
+ foreach( $this->getAdminEmailAddresses() as $emailAddress ) {
+ $message->addTo( $emailAddress );
+ }
+
+ // once the message is ready, send it out
+ $service = new EmailService();
+ return( $service->sendMessage( $message ));
+ }
+ }
+?>
\ No newline at end of file
Added: plugins/trunk/adminnotifier/templates/eventlist.template
===================================================================
--- plugins/trunk/adminnotifier/templates/eventlist.template 2006-01-11 15:46:29 UTC (rev 2769)
+++ plugins/trunk/adminnotifier/templates/eventlist.template 2006-01-11 16:16:02 UTC (rev 2770)
@@ -0,0 +1,30 @@
+{include file="$admintemplatepath/header.template"}
+{include file="$admintemplatepath/navigation.template" showOpt=adminNotifier title=$locale->tr("adminNotifier")}
+
+ <form name="eventList" id="eventList" action="admin.php" method="post">
+ <fieldset class="inputField">
+ <legend>{$locale->tr("eventList")}</legend>
+
+{include file="$admintemplatepath/successmessage.template"}
+{include file="$admintemplatepath/errormessage.template"}
+<div>
+Please select the event that should send a notification email to administrators when triggered.
+</div>
+<br/>
+{foreach from=$events key=event item=eventId}
+<div class="field_checkbox">
+<input class="checkbox" type="checkbox" id="event_{$eventId}" name="event[{$eventId}]" value="1" {if $currentEvents[$eventId] == 1}checked="checked"{/if} /><label for="event_{$eventId}">{$event}</label>
+</div>
+{/foreach}
+
+ </fieldset>
+ <div class="buttons">
+ <input type="hidden" name="op" value="updateEvents" />
+ <input type="reset" name="" value="{$locale->tr("reset")}" />
+ <input type="submit" name="submit" value="{$locale->tr("update")}" />
+ </div>
+
+</form>
+
+{include file="$admintemplatepath/footernavigation.template"}
+{include file="$admintemplatepath/footer.template"}
\ No newline at end of file
More information about the pLog-svn
mailing list