Revision history for RyeBreadDraftsEventNotification


Revision [19432]

Last edited on 2008-01-28 00:16:01 by JavaWoman [Modified links pointing to docs server]

No Differences

Revision [17821]

Edited on 2007-12-12 11:26:05 by JavaWoman [prevent function references looking as page links]
Additions:
Also, it should probably be called '""NotifyOnEmail""' as there might be additional notify functions created that belong to this family.
Firstly, I have no idea if this is the best place for it to go (as opposed to being added directly in the ""SaveComment()"" function). Secondly, there needs to be a generic event-processing-wrapper of some kind that takes a callback function (such as notify) as a parameter. I'm working on that.
Deletions:
Also, it should probably be called 'NotifyOnEmail' as there might be additional notify functions created that belong to this family.
Firstly, I have no idea if this is the best place for it to go (as opposed to being added directly in the SaveComment function). Secondly, there needs to be a generic event-processing-wrapper of some kind that takes a callback function (such as notify) as a parameter. I'm working on that.


Revision [12282]

Edited on 2005-12-15 15:27:13 by DarTar [using interwiki link for ticket ref]
Additions:
<<[[Ticket:56]]<<
Deletions:
<<**Ticket Ref:** #56<<


Revision [12281]

Edited on 2005-12-15 14:58:36 by RyeBread [added ticket # ref]
Additions:
<<**Ticket Ref:** #56<<


Revision [12152]

Edited on 2005-12-07 13:33:37 by NilsLindenberg [reply to 5)]
Additions:
~& How about a ""{{watch}}"" action instead? --NilsLindenberg


Revision [12151]

Edited on 2005-12-07 13:32:01 by NilsLindenberg [heading + cat.]
Additions:
===== Event Notification Handler =====
----
CategoryUserContributions


Revision [12133]

Edited on 2005-12-06 20:43:27 by RyeBread [proposed, comments and feedback highly appreciated]
Additions:
Add the following to 'addcomment.php', line 18, right after STORE NEW COMMENT
===== 5.) Make handler visible =====
Obviously, I want to make it easy for my users to add watches, so I just hacked the following. It adds a link to the footer.
Add the following to footer.php, line 5 after the 'Edit Page'
echo $this->GetUser() ? "<a href=\"".$this->href("addwatch")."\" title=\"Click to watch this page\">Watch page</a> ::\n" : "";
Now I don't really want to hack footer directly, plus, I want to be able to support adding watches of different types, so I need to eventually construct a separate menu altogether.
===== Conclusion =====
Whenever a user in my wiki comes across a particular page of interest, he or she can click on the "Watch page" link at the bottom, and it will record the request to be notified. Thereafter, whenever somebody leaves a comment on that page, the user will receive an email containing the comment in the body of the message.
===== TODO: =====
- Create an "removewatch" handler.
- Create a form in the user settings page that will allow people to manage their watches and add/remove/edit at will.
Comments/feedback highly desired. Thank you.
:)
Deletions:
Add the following to 'addcomment.php', line 18, right after // store new comment


Revision [12132]

Edited on 2005-12-06 20:34:17 by RyeBread [in progress]
Additions:
===== 4.) Invoke Event Processing somewhere =====
Keeping in mind that I want people to be notified of comments made on pages, I decided to invoke the event processing in the 'addcomment.php' action.
Firstly, I have no idea if this is the best place for it to go (as opposed to being added directly in the SaveComment function). Secondly, there needs to be a generic event-processing-wrapper of some kind that takes a callback function (such as notify) as a parameter. I'm working on that.
Add the following to 'addcomment.php', line 18, right after // store new comment
//trigger watches
$watches_table = $this->config["table_prefix"] . "watches";
$users_table = $this->config["table_prefix"] . "users";
$watch_query = "SELECT " . $users_table . ".email " .
"FROM " . $watches_table . "," . $users_table . " " .
"WHERE " . $watches_table . ".page_tag = '" . $this->tag . "' " .
"AND " . $watches_table . ".watcher = " . $users_table . ".name";
$watches = $this->LoadAll($watch_query);
foreach ($watches as $email) {
if ($email["email"] == '') {
continue;
}
$this->Notify($email["email"], $this->tag . " commented by " . $this->GetUserName(), $body);
}


Revision [12131]

Edited on 2005-12-06 20:29:21 by RyeBread [in progress]
Deletions:
//$help = $this->Notify("[email protected]", "watch added", $watcher);
//$this->SetRedirectMessage($help);


Revision [12130]

Edited on 2005-12-06 20:28:12 by RyeBread [in progress]
Additions:
===== 3.) Create 'notify' base function =====
In wikka.php, I added this function at line 972 before MAINTENANCE
//COMMUNICATION
function Notify($to = "", $subject = "", $body = "", $altbody = "")
{
<insert your specific mailing code here>
Obviously, how you send mail is dependent on your server setup. I don't use the default mail() function. Instead, I have phpmailer setup, and I use it on an SMTP configuration. If somebody wants to see what I wrote for this function that uses phpmailer, let me know.
Also, it should probably be called 'NotifyOnEmail' as there might be additional notify functions created that belong to this family.


Revision [12129]

Edited on 2005-12-06 20:21:09 by RyeBread [in progress]
Additions:
===== 2.) Create 'addwatch' handler =====
Create a file called addwatch.php in your handlers directory. Add this code:
%%(php)
<?php
/**
* Creates a watch on this page for a watcher.
*
* Usage: append /addwatch to the URL of the page
*
* This handler registers a watch in the database on this page
* for a watcher. Watches can be used to generate events when
* certain things are done to a page. (i.e. email a user when a page
* is commented on.)
*
* @package Handlers
* @subpackage
* @name addwatch
*
* @author {@link http://wikka.jsnx.com/RyeBread RyeBread} - original idea and code - Dec.06.2005
* @copyright Copyright © 2005, Ryan Jarvis
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
* @version 0.1
* @since Wikka 1.1.6.X
*
* @todo
* 1. Allow handler to take in params specifying what kind of watch should be made
* 2. Enable setting of watcher that isn't a user (i.e. a wikiping server).
*/
do {

if (!$this->page) {
$this->SetRedirectMessage("Found no page for this handler.");
break;
}

if (!$this->GetUser()) {
$this->SetRedirectMessage("You must be registered to add a watch.");
break;
}

//TODO: get type of watch from a param
//passed into the handler.
//
//get type of watch
$type = "comment";

//check if watch type is valid
$validity = $this->Query("SHOW COLUMNS FROM " . $this->config["table_prefix"] . "watches LIKE '" . $type . "'");
if (mysql_num_rows($validity) == 0) {
$this->SetRedirectMessage("Watch type is invalid.");
break;
}

//get page name
$tag = $this->GetPageTag();

//TODO: optionally specify the id of the
//watcher instead of assuming user name.
//
//get watcher
$watcher = $this->GetUserName();

//register watch in database
$existing = $this->Query(
"SELECT * FROM " . $this->config["table_prefix"] . "watches " .
"WHERE page_tag = '" . mysql_real_escape_string($tag) . "'" .
"AND watcher = '" . mysql_real_escape_string($watcher) . "'");

if (mysql_num_rows($existing) == 0 ) {
$this->Query(
"INSERT INTO " . $this->config["table_prefix"] . "watches SET ".
"page_tag = '" . mysql_real_escape_string($tag) . "', " .
"watcher = '" . mysql_real_escape_string($watcher) . "', " .
$type . " = 'Y'");

$this->SetRedirectMessage("You are now watching this page for " . $type . "s.");
break;
}

if (mysql_result($existing, 0, $type) == 'Y') {
$this->SetRedirectMessage("You are already watching this page for " . $type . "s.");
} else {
$this->Query(
"UPDATE " . $this->config["table_prefix"] . "watches SET ".
"page_tag = '" . mysql_real_escape_string($tag) . "', " .
"watcher = '" . mysql_real_escape_string($watcher) . "', " .
$type . " = 'Y'");
$this->SetRedirectMessage("You are now watching this page for " . $type . "s.");
}

mysql_free_result($existing);

} while (0);
//$help = $this->Notify("[email protected]", "watch added", $watcher);
//$this->SetRedirectMessage($help);
$this->Redirect($this->Href());
?>
As it stands right now, when a registered user invokes this handler on a page, the wikka_watches table will be updated to indicate that this user wants to be notified whenever this page is commented on.
Deletions:


Revision [12128]

The oldest known version of this page was created on 2005-12-06 20:15:53 by RyeBread [in progress]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki