Has anyone succeed to fix the date/time fromat handling in ProgramE?
Php is capable of that, I don't know why ProgramE variant is limited to just a long date format result when you ask about a day, a month or a year (all the other AIML interpreters don't seem to have this limitation).
After going through the hardcores of ProgramN and ProgramD trying to figure out how they did it, I realized they didn't use php at all, so the patch won't apply.
So,
I've tried a bit to change the getftime() function but I don't know how to get the attribute (which is entered in the AIML 1.0.1 set templates like <date format="%B"/>).
Actually, how do I get the value "%B" from the bot_dstore table (or from the template array), so I can pass it to the functions bellow:
In respond.php:
function handlenode($xmlnode,$inputstar,$thatstar,$topicstar){
.... }
elseif (strtoupper($xmlnode["tag"])=="DATE"){
return getfdate($date_format); // this is where I need to get the "%B" value
}
...
Then, in util.php (suppose $date_format is "%B")
function getfdate($date_format){
return strftime($date_format,strtotime(date('D, d M Y H:i:s')));
}
Can someone tell me how do I get the value %B in respond.php file (handlenode function) so I can easily pass it to util.php getfdate?
I tried $xmlnode["attributes"] and a few other similar things, but all I got where "Array" in output.
Any idea would be appreciated!
PS: Anne? Any plans for a new version, now that php5/mysql5 and utf-8 are out and become so broad around?
Ciprian M.
Logged In: YES
user_id=1363553
Originator: YES
Never mind, I did it myself...
Here is the fix:
1. In respond.php:
Search for this in handlenod function:
elseif (strtoupper($xmlnode["tag"])=="DATE"){
return getfdate();
}
######################### End of search #########################
Replace with:
elseif (strtoupper($xmlnode["tag"])=="DATE"){
// return getfdate(); // Deprecated
$mynode=upperkeysarray($xmlnode["attributes"]);
$date_format=$mynode["FORMAT"];
return getfdate($date_format);
}
################## End of replace - Save file #################
2. In util.php
Search for getfdate function:
function getfdate(){
return date("D M j G:i:s T Y");
}
######################### End of search #########################
Replace with:
function getfdate($date_format){
// Set the US specific date/time format
if (eregi("win", PHP_OS)) {
setlocale(LC_TIME, "eng-usa.UTF-8", "eng-usa");
} else {
setlocale(LC_TIME, "en_US.UTF-8", "enu.UTF-8", "usa.UTF-8", "enu_enu.UTF-8", "English-usa.UTF-8");
}
if ($date_format == "") $date_format = "%A, %d of %B %Y %H:%M:%S (%z)"; // for non-formatted <date/> tags
return strftime($date_format);
}
#################### End of replace - Save file #################
That's all! It just enabled ProgramE for tens of interesting AIMLs like, whatday_eng, whatday_us, onthisday, daystoxmas, seasons aso, files that were useless for PE before.
Notes: The locale thing...
if (eregi("win", PHP_OS)) {
setlocale(LC_TIME, "eng-usa.UTF-8", "eng-usa");
} else {
setlocale(LC_TIME, "en_US.UTF-8", "enu.UTF-8", "usa.UTF-8", "enu_enu.UTF-8", "English-usa.UTF-8");
}
... is to make sure that the data passed from patterns to the interpreter is in English, otherwise month names and day names won't be recognized correctly by bot. Of course, you can ignore the lines above.
I needed this patch with set_locale coz phpMyChat-Plus is utf-8 multilangual, and each language sets its own locale. You should remove the ".UTF-8" if your pages are ISO encoded.
Optionally, if you wish, you change it to Uk like:
// Set the UK specific date/time format
if (eregi("win", PHP_OS)) {
setlocale(LC_ALL, "eng-eng.UTF-8", "eng-eng");
} else {
setlocale(LC_ALL, "en_GB.UTF-8", "en_GB.UTF-8@euro", "eng.UTF-8", "uk.UTF-8", "eng_eng.UTF-8", "English-uk.UTF-8");
}
I hope you'll like this fix and find it useful for your own bot masterpieces :)
All the best!
Ciprian Murariu
(btw... I am the phpMyChat-Plus developer)