Ha! I got it working like I wanted it to :D
Here's the code for the plugin which you put in a tiddler tagged with
systemConfig:
=================================================
Story.prototype.onTiddlerMouseOver_orig =
Story.prototype.onTiddlerMouseOver;
Story.prototype.onTiddlerMouseOver = function(e)
{
config.extensions.ajaxplugin();
return Story.prototype.onTiddlerMouseOver_orig.apply(this);
}
timeStamp01 = new Date()
config.extensions.ajaxplugin = function ()
{
updateMsg = function ()
{
$.post(window.url+"ajax.php",{ time:
timeStamp01.convertToYYYYMMDDHHMM() }, function(xml)
{
if($("status",xml).text() == "2") return;
$("message",xml).each(function(id)
{
message = $("message",xml).get(id);
displayMessage("Tiddler updated:");
displayMessage($("author",message).text()+" - "+$
("title",message).text());
displayMessage("You need to refresh to see the changes");
});
});
}
timeStamp02 = new Date();
if(timeStamp02-timeStamp01 > 5000)
{
updateMsg();
timeStamp01 = timeStamp02;
}
}
====================================
Here's the code you put in a .php file which you put in the same
folder as the wiki:
====================================
<?php
$dbhost = "127.0.0.1";
$dbuser = ""; //fill this in
$dbpass = ""; //fill this in
$dbname = ""; //fill this in
$display_num = 5;
error_reporting(E_ALL);
$dbconn = mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($dbname,$dbconn);
foreach($_POST as $key => $value)
$$key = mysql_real_escape_string($value, $dbconn);
$result = mysql_query("SELECT title,modifier,modified,revision
FROM tiddler
WHERE modified>$time
ORDER BY id DESC
LIMIT $display_num",$dbconn);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
die($message);
}
if(mysql_num_rows($result) == 0) $status_code = 2;
else $status_code = 1;
echo "<?xml version=\"1.0\"?>\n";
echo "<response>\n";
echo "\t<status>$status_code</status>\n";
echo "\t<time>".time()."</time>\n";
if($status_code == 1)
{
while($message = mysql_fetch_array($result))
{
$message['title'] =
htmlspecialchars(stripslashes($message['title']));
echo "\t<message>\n";
echo "\t\t<author>$message[modifier]</author>\n";
echo "\t\t<title>$message[title]</title>\n";
echo "\t</message>\n";
}
}
echo "</response>";
?>
========================================
It would be nice if I could remove the need to manually add the
database information, I can probably just load one of the other php
files and reference the info there, I'll tinker with that.
I got all of the code from this example:
http://articles.sitepoint.com/article/ajax-jquery/3
- I couldn't have done this by myself.
- Now I'm wondering if there's some way to just inject the new/updated
tiddler instead of just letting people know to "refresh now". I'll
have to think about that, not exactly sure how to reference the
overwrite of the tiddler with new info, probably possible though.
Regards,
S.