Skip to content

Commit f0f91e7

Browse files
committed
Bug fix
Finally found and corrected the bug that added mal-formed XML to the template field of the aiml table from the upload script! I also added "Pretty Print" to the download script, to make the downloaded AIML filed easier to read, AND updated the bot_test.aiml file to the "pretty Printed" version.
1 parent 28a1127 commit f0f91e7

File tree

3 files changed

+89
-50
lines changed

3 files changed

+89
-50
lines changed

admin/download.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ function getAIMLByFileName($filename) {
140140
if (!empty($topic)) $fileContent .= "</topic>\n";
141141
}
142142
$fileContent .= "\r\n</aiml>\r\n";
143+
save_file(_DEBUG_PATH_ . 'test.aiml', $fileContent);
144+
$dom = new DOMDocument();
145+
$dom->preserveWhiteSpace = false;
146+
$dom->formatOutput = true;
147+
$dom->loadXML(trim($fileContent));
148+
$fileContent = $dom->saveXML();
143149
$outFile = ltrim($fileContent, "\n\r\n");
144150
#$outFile = iconv("ISO-8859-1", "UTF-8//TRANSLIT", $outFile);
145151
//$outFile = utf8_encode($outFile);

admin/upload.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,9 @@ function parseAIML($fn,$aimlContent, $from_zip = false)
177177
$pattern = str_replace("'", ' ', $pattern);
178178
$that = $category->that;
179179
$template = $category->template->asXML();
180-
$template = ltrim($template,'<template>');
181-
$template = ltrim($template,"\r\n ");
182-
$template = rtrim($template,'</template>');
183-
$template = rtrim($template,"\r\n");
180+
$template = substr($template,10);
181+
$tLen = strlen($template);
182+
$template = substr($template,0, $tLen - 11);
184183
# Strip CRLF and LF from category (Windows/mac/*nix)
185184
$aiml_add = str_replace(array("\r\n", "\n"), '', $fullCategory);
186185
$sql_add = str_replace('[aiml_add]', mysql_real_escape_string($aiml_add), $sql_template);

library/reference/bot_test.aiml

Lines changed: 80 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,81 @@
1-
<?xml version="1.0" encoding="ISO-8859-1"?>
21

3-
<!--
4-
Copyright ©2011/2013 Dave Morton
5-
6-
Permission is hereby granted, free of charge, to any person
7-
obtaining a copy of this software and associated documentation
8-
files (the "Software"), to deal in the Software without
9-
restriction, including without limitation the rights to use,
10-
copy, modify, merge, publish, distribute, sublicense, and/or sell
11-
copies of the Software, and to permit persons to whom the
12-
Software is furnished to do so, subject to the following
13-
conditions:
14-
15-
The above copyright notice and this permission notice shall be
16-
included in all copies or substantial portions of the Software.
17-
18-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25-
OTHER DEALINGS IN THE SOFTWARE.
26-
27-
Complies with the AIML 1.0.1 Standard
28-
as adopted by the ALICE A.I. Foundation.
29-
Last modified 02-18-2013
30-
file: bot_test.aiml
31-
32-
-->
33-
<aiml version="1.01">
34-
<category><pattern>AIML TEST SENTENCE *</pattern><template>Only the first letter of the following should be capitalized: "<sentence><star /></sentence>"</template></category>
35-
<category><pattern>AIML TEST FORMAL *</pattern><template>Every word should be capitalized here: "<formal><star /></formal>"</template></category>
36-
<category><pattern>AIML TEST SRAI *</pattern><template>Running SRAI test on <star />: <br /><srai><star /></srai></template></category>
37-
<category><pattern>AIML TEST BOT PROPERTY *</pattern><template>The bot property <star /> is <bot name="*" />.</template></category>
38-
<category><pattern>AIML TEST UPPERCASE *</pattern><template>The following should all be in capital letters: "<uppercase><star /></uppercase>"</template></category>
39-
<category><pattern>AIML TEST HTML</pattern><template>Testing HTML tag parsing:<br />Link tag: <a href="http://www.geekcavecreations.com" target="_blank">Geek Cave Creations</a><br /><b>BOLD</b><br /><i>italic</i><br /><s>strikethrough</s><br /><u>underline</u><sub>subscript</sub><br /><sup>superscript</sup><br /><big>BIG</big><br /><strong>STRONG</strong><small>small</small><br />Unordered list:<br /><ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li></ul><br />Ordered list:<br /><ol> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li></ol><br />Test complete.</template></category>
40-
<category><pattern>AIML TEST SR *</pattern><template>Running SR test on <star />: <br/><sr/></template></category>
41-
<category><pattern>AIML TEST ID</pattern><template>Your user ID is <id />.</template></category>
42-
<category><pattern>AIML TEST VERSION</pattern><template><version /></template></category>
43-
<category><pattern>AIML TEST CONDITION *</pattern><template><b>Testing Condition tag with NAME and VALUE attributes:</b><br /><condition name="gender" value="female"> attractive.</condition><condition name="gender" value="male"> handsome.</condition><br /><b>Testing Condition tag with only NAME attribute:</b><br /><condition name="gender"><li value="female"> attractive.</li><li value="male"> handsome.</li></condition><br /><b>Testing Condition tag with no attributes:</b><br /><condition><li name="gender" value="female"> attractive.</li><li name="gender" value="male"> handsome.</li></condition><br />Testing complete.</template></category>
44-
<category><pattern> AIML TEST SET * TO *</pattern><template><think><set name="*"><star index="2" /></set></think>The value of <star /> has been set to <star index="2" />.</template></category>
45-
<category><pattern> AIML TEST GET *</pattern><template>The value of <star /> is <get name="*" />.</template></category>
46-
<category><pattern>AIML TEST LOWERCASE *</pattern><template>The following should all be in lower case letters: "<lowercase><star /></lowercase>"</template></category>
47-
</aiml>
2+
<?xml version="1.0" encoding="UTF-8"?>
3+
<!-- Copyright ©2013 Dave Morton -->
4+
<!-- Permission is hereby granted, free of charge, to any person -->
5+
<!-- obtaining a copy of this software and associated documentation -->
6+
<!-- files (the "Software"), to deal in the Software without -->
7+
<!-- restriction, including without limitation the rights to use, -->
8+
<!-- copy, modify, merge, publish, distribute, sublicense, and/or sell -->
9+
<!-- copies of the Software, and to permit persons to whom the -->
10+
<!-- Software is furnished to do so, subject to the following -->
11+
<!-- conditions: -->
12+
<!-- The above copyright notice and this permission notice shall be -->
13+
<!-- included in all copies or substantial portions of the Software. -->
14+
<!-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -->
15+
<!-- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -->
16+
<!-- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -->
17+
<!-- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -->
18+
<!-- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -->
19+
<!-- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -->
20+
<!-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -->
21+
<!-- OTHER DEALINGS IN THE SOFTWARE. -->
22+
<!-- Complies with the AIML 1.0 Standard -->
23+
<!-- as adopted by the ALICE A.I. Foundation. -->
24+
<!-- Last modified 08-29-2013 -->
25+
<!-- file: bot_test.aiml -->
26+
<aiml version="1.0">
27+
<category>
28+
<pattern>AIML TEST SENTENCE *</pattern>
29+
<template>Only the first letter of the following should be capitalized: "<sentence><star/></sentence>"</template>
30+
</category>
31+
<category>
32+
<pattern>AIML TEST FORMAL *</pattern>
33+
<template>Every word should be capitalized here: "<formal><star/></formal>"</template>
34+
</category>
35+
<category>
36+
<pattern>AIML TEST SRAI *</pattern>
37+
<template>Running SRAI test on <star/>: <br/><srai><star/></srai></template>
38+
</category>
39+
<category>
40+
<pattern>AIML TEST BOT PROPERTY *</pattern>
41+
<template>The bot property <star/> is <bot name="*"/>.</template>
42+
</category>
43+
<category>
44+
<pattern>AIML TEST UPPERCASE *</pattern>
45+
<template>The following should all be in capital letters: "<uppercase><star/></uppercase>"</template>
46+
</category>
47+
<category>
48+
<pattern>AIML TEST HTML</pattern>
49+
<template>Testing HTML tag parsing:<br/>Link tag: <a href="http://www.geekcavecreations.com" target="_blank">Geek Cave Creations</a><br/><b>BOLD</b><br/><i>italic</i><br/><s>strikethrough</s><br/><u>underline</u><sub>subscript</sub><br/><sup>superscript</sup><br/><big>BIG</big><br/><strong>STRONG</strong><small>small</small><br/>Unordered list:<br/><ul><li>Item 1</li><li>Item 2</li><li>Item 3</li></ul><br/>Ordered list:<br/><ol><li>Item 1</li><li>Item 2</li><li>Item 3</li></ol><br/>Test complete.</template>
50+
</category>
51+
<category>
52+
<pattern>AIML TEST SR *</pattern>
53+
<template>Running SR test on <star/>: <br/><sr/></template>
54+
</category>
55+
<category>
56+
<pattern>AIML TEST ID</pattern>
57+
<template>Your user ID is <id/>.</template>
58+
</category>
59+
<category>
60+
<pattern>AIML TEST VERSION</pattern>
61+
<template>
62+
<version/>
63+
</template>
64+
</category>
65+
<category>
66+
<pattern>AIML TEST CONDITION *</pattern>
67+
<template><b>Testing Condition tag with NAME and VALUE attributes:</b><br/><condition name="gender" value="female"> attractive.</condition><condition name="gender" value="male"> handsome.</condition><br/><b>Testing Condition tag with only NAME attribute:</b><br/><condition name="gender"><li value="female"> attractive.</li><li value="male"> handsome.</li></condition><br/><b>Testing Condition tag with no attributes:</b><br/><condition><li name="gender" value="female"> attractive.</li><li name="gender" value="male"> handsome.</li></condition><br/>Testing complete.</template>
68+
</category>
69+
<category>
70+
<pattern> AIML TEST SET * TO *</pattern>
71+
<template><think><set name="*"><star index="2"/></set></think>The value of <star/> has been set to <star index="2"/>.</template>
72+
</category>
73+
<category>
74+
<pattern> AIML TEST GET *</pattern>
75+
<template>The value of <star/> is <get name="*"/>.</template>
76+
</category>
77+
<category>
78+
<pattern>AIML TEST LOWERCASE *</pattern>
79+
<template>The following should all be in lower case letters: "<lowercase><star/></lowercase>"</template>
80+
</category>
81+
</aiml>

0 commit comments

Comments
 (0)