Skip to content

Commit d1a05b0

Browse files
committed
Buf Gixes (something different for a change)
Fixed the following bugs: 1.) If the install script encountered certain errors, only the message "Installation Failed!" was displayed. 2.) Some entries in the debug array were being overwritten by later entries that had the same generated index. 3.) In the function parse_condition_tag(), mixed content AIML wasn't being parsed.
1 parent 856ad6a commit d1a05b0

File tree

6 files changed

+62
-12
lines changed

6 files changed

+62
-12
lines changed

admin/default.page.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ <h3>Help...</h3>
720720
<tr>
721721
<td>
722722
<label for="aimlfile">File:</label>
723-
<input type="file" id="aimlfile" name="aimlfile" />&nbsp; &nbsp;
723+
<input type="file" id="aimlfile" name="aimlfile" onchange="checkSize();" />&nbsp; &nbsp;
724724
</td>
725725
<td>
726726
<input type="checkbox" id="clearDB" name="clearDB" />&nbsp; &nbsp;

admin/upload.php

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,29 @@ function showHide() {
4444
alert('display = ' + display);
4545
}
4646
}
47+
function checkSize(){
48+
var file_upload = document.getElementById('aimlfile');
49+
if (!file_upload.files) return false;
50+
var fileSize = file_upload.files[0].size;//.fileSize;
51+
var fileName = file_upload.files[0].name;//.fileSize;
52+
if (fileSize > 2000000){
53+
showError("The file " + fileName + " exceeds the file size limit of 2MB. Please choose a different file.")
54+
file_upload.value = null;
55+
}
56+
var fileType = file_upload.files[0].type;//.fileSize;
57+
//showError('The file type is ' + file_upload.files[0].type);
58+
if (fileType != 'text/aiml' && fileType != 'application/x-zip-compressed') {
59+
//showError("The file " + fileName + " is neither an AIML file, nor a zip archive. Please select another file.")
60+
//file_upload.value = null;
61+
}
62+
}
63+
function showError(msg){
64+
var errorDiv = document.getElementById("errMsg");
65+
var closeButton = '<div class="closeButton" id="closeButton" onclick="closeStatus(\'errMsg\')" title="Click to hide">&nbsp;</div>';
66+
errorDiv.innerHTML = closeButton + msg;
67+
errorDiv.style.display = 'block';
68+
69+
}
4770
//-->
4871
</script>
4972
endScript;
@@ -208,10 +231,10 @@ function parseAIML($fn,$aimlContent, $from_zip = false)
208231
catch (Exception $e)
209232
{
210233
$trace = print_r($e->getTrace(), true);
211-
file_put_contents(_LOG_PATH_ . 'error.trace.log', $trace . "\nEnd Trace\n\n", FILE_APPEND);
234+
//file_put_contents(_LOG_PATH_ . 'error.trace.log', $trace . "\nEnd Trace\n\n", FILE_APPEND);
212235
$success = false;
213236
$_SESSION['failCount']++;
214-
$msg = "There was a problem adding file $fileName to the database. Please refer to the message below to correct the problem and try again.";
237+
$msg = "There was a problem adding file $fileName to the database. Please refer to the message below to correct the problem and try again.<br>\n" . $e->getMessage();
215238
$msg = libxml_display_errors($msg);
216239
}
217240
return $msg;
@@ -362,6 +385,9 @@ function processZip($fileName)
362385
if(!$fp)
363386
{
364387
$out .= "Processing for $curName failed.<br />\n";
388+
$bad_aiml_files = (!isset($bad_aiml_files)) ? array() : $bad_aiml_files;
389+
$bad_aiml_files[] = $curName;
390+
$_SESSION['bad_aiml_files'] = $curName;
365391
}
366392
else
367393
{
@@ -378,6 +404,16 @@ function processZip($fileName)
378404
$zip->close();
379405
$failCount = $_SESSION['failCount'];
380406
$out .= "<br />\nUpload complete. $numFiles files were processed, and $failCount files encountered errors.<br />\n";
407+
if (isset($_SESSION['bad_aiml_files']))
408+
{
409+
$out .= "<br />\nThe following AIML files encountered errors:<br />\n";
410+
foreach ($_SESSION['bad_aiml_files'] as $fn)
411+
{
412+
$out .= "$fn, ";
413+
}
414+
$out = rtrim($out, ', ') . "<br .>\nPlease test each of these files independently, to locate the errors within.";
415+
unset($_SESSION['bad_aiml_files']);
416+
}
381417
}
382418
else
383419
{

chatbot/addons/word_censor/word_censor.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
**/
2020
function run_censor($convoArr)
2121
{
22-
if (!isset ($_SESSION['programo_bigArray']['censor']))
22+
if (!isset ($_SESSION['pgo_word_censor']))
2323
{
2424
initialise_censor($convoArr['conversation']['bot_id']);
2525
}
@@ -30,7 +30,6 @@ function run_censor($convoArr)
3030
/**
3131
* function intialise_censor()
3232
* A function to build session array containing the words from the censor list in the db
33-
3433
**/
3534
function initialise_censor($bot_id)
3635
{
@@ -39,7 +38,10 @@ function initialise_censor($bot_id)
3938
$result = db_query($sql, $con);
4039
while ($row = mysql_fetch_assoc($result))
4140
{
42-
$_SESSION['programo_bigArray']['censor'][base64_encode("/\b" . $row['word_to_censor'] . "\b/i")] = base64_encode("/\b" . $row['replace_with'] . "\b/i");
41+
$index = "/\b{$row['word_to_censor']}\b/i";
42+
$index = $row['word_to_censor'];
43+
$value = $row['replace_with'];
44+
$_SESSION['pgo_word_censor'][$index] = $value;
4345
}
4446
mysql_free_result($result);
4547
}
@@ -52,9 +54,9 @@ function initialise_censor($bot_id)
5254
**/
5355
function censor_words($output)
5456
{
55-
foreach ($_SESSION['programo_bigArray']['censor'] as $find => $replace)
57+
foreach ($_SESSION['pgo_word_censor'] as $find => $replace)
5658
{
57-
$output = preg_replace(base64_decode($find), base64_decode($replace), $output);
59+
$output = preg_replace("/\b$find\b/i", $replace, $output);
5860
}
5961
return $output;
6062
}

chatbot/core/aiml/parse_aiml_as_XML.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ function parse_condition_tag($convoArr, $element, $parentName, $level)
528528
runDebug(__FILE__, __FUNCTION__, __LINE__, "search string = $path", 4);
529529
$choice = $element->xpath($path);
530530
$pick = $choice[0];
531-
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Found a match. Pick = ' . print_r($choice, true), 4);
531+
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Found a match. Pick = ' . print_r($pick, true), 4);
532532
}
533533
else // nothing matches
534534
{
@@ -538,7 +538,11 @@ function parse_condition_tag($convoArr, $element, $parentName, $level)
538538
$children = (is_object($pick)) ? $pick->children() : null;
539539
if (!empty ($children))
540540
{
541-
$response = parseTemplateRecursive($convoArr, $children, $level + 1);
541+
foreach ($children as $child)
542+
{
543+
$response[] = parseTemplateRecursive($convoArr, $child, $level + 1);
544+
}
545+
runDebug(__FILE__, __FUNCTION__, __LINE__, "Response = " . print_r($response, true), 4);
542546
}
543547
else
544548
{

install/install_programo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function Save()
167167
}
168168
else
169169
$out = getSection('InstallError', $page_template);
170-
return $out;
170+
return $out . $_SESSION['errorMessage'];
171171
}
172172

173173
function install_error($msg, $err, $sql)

library/error_functions.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,16 @@ function runDebug($fileName, $functionName, $line, $info, $level = 0)
9393
outputDebug($fileName, $functionName, $line, $info);
9494
}
9595
list($usec, $sec) = explode(' ', microtime());
96+
$usecD = $usec / 1000;
97+
$usecD = str_replace('0.000', '', $usecD);
9698
//build timestamp index for the debug array
97-
$index = date('d-m-Y H:i:s') . ltrim($usec, '0') . "[$level][$debug_level] - Elapsed: $elapsed_time milliseconds";
99+
$index = date('d-m-Y H:i:s.') . $usecD . "[$level][$debug_level] - Elapsed: $elapsed_time milliseconds";
100+
101+
//If there's already an index in the debug array with the same value, just add a space, to make a new, unique index that is visually identical.
102+
while (array_key_exists($index, $debugArr))
103+
{
104+
$index .= ' ';
105+
}
98106
//mem_tracer($fileName, $functionName, $line); # only uncomment this to trace memory leaks!
99107
//add to array
100108
$debugArr[$index]['fileName'] = basename($fileName);

0 commit comments

Comments
 (0)