Revisiting the Ajax thing.

4 views
Skip to first unread message

Kashgarinn

unread,
Jul 15, 2010, 8:02:33 AM7/15/10
to ccTiddly
Hi there.

I was recently just browsing this forum and found my old thread on
ajaxing the wiki, and I'm still interested in seeing if it's
possible. I didn't really understand what you meant by 1.8+
supporting Jquery, but I googled it a bit, and it does support ajaxing
in a nicer way so that's great.

The implementation I was thinking is that when somebody else has added
or edited a tiddler, a popup alert similar to the error alert with
different colors pops up with the name of the tiddler and username of
person.

As the user has to instigate the request, I was thinking that the
mouseover function over a tiddler would be the best choice to use from
the user, as it happens pretty often that a user mouses over a
tiddler.

Regarding the information from the server regarding the new/edited
tiddler, I'm seeing really only 1 option.. that the new/edited tiddler
gets updated into the wiki so you can click on the link and see the
changes instantly, how to do that, I have no idea, but that's the best
implementation for the user, so he doesn't have to completely open the
wiki again just to see the changes.

I'm not even sure that this is possible.. injecting updated/new
tiddlers via Ajax into the wiki sounds complicated, and what if the
tiddler is already on the screen, and not hidden in the background?
What if the tiddler is already being edited?

If I'm already in Lala wonderland of brainstorming, then I'd love if
CCTW used google wave protocol to solve the editing problems, seeing 2
people editing at once would be awesome.

I'm thinking I'll try something very simple..

So this is what I'm thinking would happen:
1) user A mouses overs a tiddler
2) a check for if an ajax function is already in motion, if no ajax
query is in place, an ajax request to the server queries new tiddlers
since last time, if no time, since user logged in, and creates a new
time to check for next time
3) the php script grabs the time and queries the SQL server with
tiddlers modified since that time.
4) a modified popup alert pops up to show any changes from other
users.

hopefully I'll have time to fiddle with this this, this sounds
doable.. I'll just have to hunt down how to do it.

K.

Kashgarinn

unread,
Aug 2, 2010, 10:06:30 PM8/2/10
to ccTiddly
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.

Kashgarinn

unread,
Aug 3, 2010, 5:54:31 AM8/3/10
to ccTiddly
I'm seeing a few problems with the timestamp being very accurate, and
the 'modified' time in the database being at the minute interval.

I'm wondering how easy/hard would it be to change the time being kept
in the 'modified' field of a tiddler on the server to a more accurate
one? Anyone know?

S.

Kashgarinn

unread,
Aug 5, 2010, 7:16:47 PM8/5/10
to ccTiddly
Hi there, I was able to do this plugin so that the tiddler gets
automatically added to the store, so technically no need to refresh
when other people update the wiki.

Here's the plugin: http://sthor.tiddlyspot.com/#AjaxPluginForCCTW

There's still stuff I need to do, it's not importing the whole updated
tiddler, a few fields are missing, but it's good enough that modifier,
tags, and content gets updated, which is good enough until people
refresh.

I'd appreciate if someone can try out the plugin and let me know if it
works for them.

Regards,
S.
Reply all
Reply to author
Forward
0 new messages