Skip to content

Commit b71200b

Browse files
committed
Multiple Minor Bug Fixes
1 parent 2bc63bd commit b71200b

File tree

9 files changed

+165
-58
lines changed

9 files changed

+165
-58
lines changed

README

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,11 @@ your new Program O admin page (e.g. http://www.example.com/ProgramO/admin) and l
6666
the admin credentials you provided during the install process. Then select "Upload AIML"
6767
from the navigation link on the left and upload your AIML files. Then sit back and enjoy your
6868
new bot!
69+
70+
Program O has a WordPress Plugin!
71+
---------------------------------------------------------
72+
If you have a WordPress driven website, and wish to incorporate your Program O chatbot into your
73+
website with a minimum of fuss and hassle, then maybe the Elizaibots plugin is what you need!
74+
Add an Elizaibots chatbot to your wordpress site using the shortcode to embed the bot and conversation
75+
on your blog. Keep your readers amused! Check out http://wordpress.org/plugins/elizaibot-chatbots/
76+
for more details.

admin/upload.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ function processUpload()
285285
}
286286
}
287287
$_SESSION['errorMessage'] = $msg;
288+
return $msg;
288289
}
289290

290291
function getAIML_List()

chatbot/core/aiml/find_aiml.php

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -322,16 +322,13 @@ function score_matches($convoArr, $bot_parent_id, $allrows, $lookingfor, $curren
322322
$allrows[$all]['score'] += $that_pattern_match_general;
323323
$allrows[$all]['track_score'] .= "g";
324324
}
325-
} elseif (($aiml_pattern == "*")&&($aiml_thatpattern!="")) {
326-
327-
325+
}
326+
elseif (($aiml_pattern == "*")&&($aiml_thatpattern!="")) {
328327
if (($aiml_thatpattern_wildcards != '') && (preg_match($aiml_thatpattern_wildcards, $current_thatpattern, $m))) {
329328
$allrows[$all]['score'] += $that_pattern_match;
330329
$allrows[$all]['track_score'][] = "general aiml that pattern match";
331330
}
332-
333-
}
334-
331+
}
335332

336333
//if stored result == default pattern increase score
337334
$aiml_pattern = (IS_MB_ENABLED) ? mb_strtolower($aiml_pattern) : strtolower($aiml_pattern);
@@ -466,14 +463,14 @@ function sort2DArray($opName, $thisArr, $sortByItem, $sortAsc = 1, $limit = 10)
466463
}
467464

468465
/**
469-
* function get_highest_score_rows()
466+
* function get_highest_scoring_row()
470467
* This function takes all the relevant and scored aiml results
471468
* and saves the highest scoring rows
472469
* @param array $allrows - all the results
473470
* @param string $lookingfor - the user input
474471
* @return array bestResponseArr - best response and its parts (topic etc)
475472
**/
476-
function get_highest_score_rows($allrows, $lookingfor)
473+
function get_highest_scoring_row($allrows, $lookingfor)
477474
{
478475
$bestResponse = array();
479476
$last_high_score = 0;
@@ -590,6 +587,16 @@ function get_convo_var($convoArr, $index_1, $index_2 = '', $index_3 = '', $index
590587
return $value;
591588
}
592589

590+
591+
592+
/**
593+
* Function: get_client_property()
594+
* Summary: Extracts a value from the the client properties subarray within the main conversation array
595+
* @param Array $convoArr - the main conversation array
596+
* @param String $name - the key of the value to extract from client properties
597+
* @return String $response - the value of the client property
598+
**/
599+
593600
function get_client_property($convoArr, $name)
594601
{
595602
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Rummaging through the DB and stuff for a client property.', 2);
@@ -692,7 +699,7 @@ function get_aiml_to_parse($convoArr)
692699
//score the relevant matches
693700
$allrows = score_matches($convoArr, $bot_parent_id, $allrows, $lookingfor, $current_thatpattern, $current_topic, $aiml_pattern);
694701
//get the highest
695-
$allrows = get_highest_score_rows($allrows, $lookingfor);
702+
$allrows = get_highest_scoring_row($allrows, $lookingfor);
696703
//READY FOR v2.5 do not uncomment will not work
697704
//check if this is an unknown input and place in the unknown_inputs tbl if true
698705
//check_and_add_unknown_inputs($allrows,$convoArr);
@@ -755,7 +762,7 @@ function find_aiml_matches($convoArr)
755762
$aiml_pattern = $convoArr['conversation']['default_aiml_pattern'];
756763
#$lookingfor = get_convo_var($convoArr,"aiml","lookingfor");
757764
$convoArr['aiml']['lookingfor'] = str_replace(' ', ' ', $convoArr['aiml']['lookingfor']);
758-
$lookingfor = strtoupper(mysql_real_escape_string($convoArr['aiml']['lookingfor']));
765+
$lookingfor = trim(strtoupper(mysql_real_escape_string($convoArr['aiml']['lookingfor'])));
759766
//get the first and last words of the cleaned user input
760767
$lastInputWord = get_last_word($lookingfor);
761768
$firstInputWord = get_first_word($lookingfor);
@@ -823,14 +830,11 @@ function find_aiml_matches($convoArr)
823830
//loop through results
824831
while ($row = mysql_fetch_assoc($result))
825832
{
826-
$allrows[$i]['aiml_id'] = $row['id'];
827-
$allrows[$i]['bot_id'] = $row['bot_id'];
828-
$allrows[$i]['pattern'] = $row['pattern'];
829-
$allrows[$i]['thatpattern'] = $row['thatpattern'];
830-
$allrows[$i]['topic'] = $row['topic'];
831-
$allrows[$i]['score'] = 0;
832-
$allrows[$i]['track_score'] = '';
833-
$i++;
833+
$row['aiml_id'] = $row['id'];
834+
$row['score'] = 0;
835+
$row['track_score'] = '';
836+
$allrows[] = $row;
837+
834838
$mu = memory_get_usage(true);
835839
if ($mu >= MEM_TRIGGER)
836840
{
@@ -852,6 +856,11 @@ function find_aiml_matches($convoArr)
852856
return $allrows;
853857
}
854858

859+
/** get_topic()
860+
* Extracts the current topic directly from the database
861+
* @param Array $convoArr - the conversation array
862+
* returns String $retval - the topic
863+
**/
855864
function get_topic($convoArr)
856865
{
857866
global $con,$dbn;

chatbot/core/aiml/parse_aiml_as_XML.php

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ function implode_recursive($glue, $input, $file = 'unknown', $function = 'unknow
8383
trigger_error("Input not array! Error originated in $file, function $function, line $line. Input = " . print_r($input, true));
8484
return $input;
8585
}
86+
elseif (is_string($input)) return $input;
87+
runDebug(__FILE__, __FUNCTION__, __LINE__,'The variable $input is of type ' . gettype($input), 4);
8688
foreach ($input as $index => $element)
8789
{
8890
if (empty ($element))
@@ -288,15 +290,15 @@ function parse_get_tag($convoArr, $element, $parentName, $level)
288290
$response = $row['value'];
289291
}
290292
else {
291-
$response = 'undefined';
293+
$response = 'undefined';
292294
}
293-
mysql_free_result($result);
295+
mysql_free_result($result);
294296
}
295297
runDebug(__FILE__, __FUNCTION__, __LINE__, "The value for $var_name is $response.", 4);
296298
return $response;
297299
}
298300

299-
function parse_set_tag($convoArr, $element, $parentName, $level)
301+
function parse_set_tag(&$convoArr, $element, $parentName, $level)
300302
{
301303
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Parsing the SET tag.', 2);
302304
global $con, $dbn, $user_name, $remember_up_to;
@@ -314,8 +316,8 @@ function parse_set_tag($convoArr, $element, $parentName, $level)
314316
if ($var_name == 'name')
315317
{
316318
$user_name = $var_value;
317-
$sql = "UPDATE `$dbn`.`users` set `user_name` = '$var_value' where `id` = $user_id;";
318-
$sql = mysql_real_escape_string($sql);
319+
$escaped_var_value = mysql_real_escape_string($var_value);
320+
$sql = "UPDATE `$dbn`.`users` set `user_name` = '$escaped_var_value' where `id` = $user_id;";
319321
runDebug(__FILE__, __FUNCTION__, __LINE__, "Updating user name in the DB. SQL:\n$sql", 3);
320322
$result = db_query($sql, $con) or trigger_error('Error setting user name in ' . __FILE__ . ', function ' . __FUNCTION__ . ', line ' . __LINE__ . ' - Error message: ' . mysql_error());
321323
$numRows = mysql_affected_rows();
@@ -355,11 +357,12 @@ function parse_set_tag($convoArr, $element, $parentName, $level)
355357
$result = db_query($sql, $con) or trigger_error('Error saving to db in ' . __FILE__ . ', function ' . __FUNCTION__ . ', line ' . __LINE__ . ' - Error message: ' . mysql_error());
356358
$rowCount = mysql_affected_rows();
357359
$response = $var_value;
360+
$convoArr['client_properties'][$var_name] = $var_value;
358361
runDebug(__FILE__, __FUNCTION__, __LINE__, "Value for $var_name has ben set. Returning $var_value.", 4);
359362
return $response;
360363
}
361364

362-
function parse_think_tag($convoArr, $element, $parentName, $level)
365+
function parse_think_tag(&$convoArr, $element, $parentName, $level)
363366
{
364367
runDebug(__FILE__, __FUNCTION__, __LINE__, 'I\'m considering parsing a THINK tag.', 2);
365368
$response_string = tag_to_string($convoArr, $element, $parentName, $level, 'element');
@@ -467,7 +470,6 @@ function parse_condition_tag($convoArr, $element, $parentName, $level)
467470
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Parsing a CONDITION tag.', 2);
468471
global $error_response;
469472
$response = array();
470-
$attrName = $element['name'];
471473
$attributes = (array)$element->attributes();
472474
$attributesArray = (isset($attributes['@attributes'])) ? $attributes['@attributes'] : array();
473475
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Element attributes:' . print_r($attributesArray, true), 4);
@@ -502,6 +504,7 @@ function parse_condition_tag($convoArr, $element, $parentName, $level)
502504
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Parsing a CONDITION tag with 2 attributes.', 4);
503505
$condition_name = (string)$element['name'];
504506
$test_value = get_client_property($convoArr, $condition_name);
507+
$test_value = trim($test_value);
505508
switch (true)
506509
{
507510
case (isset($element['value'])):
@@ -521,14 +524,42 @@ function parse_condition_tag($convoArr, $element, $parentName, $level)
521524
}
522525
elseif (array_key_exists('name', $attributesArray)) // this ~SHOULD~ just trigger if the NAME value is present, and ~NOT~ NAME and (VALUE|CONTAINS|EXISTS)
523526
{
524-
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Parsing a CONDITION tag with only the NAME attribute.', 4);
527+
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Parsing a CONDITION tag with only the NAME attribute', 4);
525528
$condition_name = (string)$element['name'];
526529
$test_value = get_client_property($convoArr, $condition_name);
527-
$path = "li[@value=\"$test_value\"]|li[not(@*)]";
530+
//$path = "li[@name=*][not(@value)]|li[not(@*)]";
531+
$path = "li[@name]|li[not(@*)]";
532+
//trigger_error("path = $path");
528533
runDebug(__FILE__, __FUNCTION__, __LINE__, "search string = $path", 4);
529534
$choice = $element->xpath($path);
530-
$pick = $choice[0];
531-
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Found a match. Pick = ' . print_r($pick, true), 4);
535+
runDebug(__FILE__, __FUNCTION__, __LINE__,'Choices = ' . print_r($choice, true), 4);
536+
if (count($choice) != 0)
537+
{
538+
$test_value = rtrim($test_value);
539+
runDebug(__FILE__, __FUNCTION__, __LINE__,'parent XML = ' . $element->asXML(), 4);
540+
foreach ($choice as $pick)
541+
{
542+
$testVarName = (string)$pick['name'];
543+
$testVarValue = get_client_property($convoArr, $testVarName);
544+
$testVarValue = trim($testVarValue);
545+
runDebug(__FILE__, __FUNCTION__, __LINE__,"Checking to see if $testVarValue ($testVarName) is equal to $test_value.", 4);
546+
if (strtolower($testVarValue) == strtolower($test_value))
547+
{
548+
runDebug(__FILE__, __FUNCTION__, __LINE__,'Pick XML = ' . $pick->asXML(), 4);
549+
break;
550+
}
551+
}
552+
//$pick = $choice[0];
553+
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Found a match. Pick = ' . print_r($pick, true), 4);
554+
}
555+
else
556+
{
557+
$path = "li[@value=\"$test_value\"]|li[not(@*)]";
558+
runDebug(__FILE__, __FUNCTION__, __LINE__, "search string = $path", 4);
559+
$choice = $element->xpath($path);
560+
$pick = $choice[0];
561+
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Found a match. Pick = ' . print_r($pick, true), 4);
562+
}
532563
}
533564
else // nothing matches
534565
{
@@ -778,7 +809,7 @@ function parse_eval_tag($convoArr, $element, $parentName, $level)
778809
* @return (string) $response_string
779810
*/
780811

781-
function tag_to_string($convoArr, $element, $parentName, $level, $type = 'element')
812+
function tag_to_string(&$convoArr, $element, $parentName, $level, $type = 'element')
782813
{
783814
runDebug(__FILE__, __FUNCTION__, __LINE__, "converting the $parentName tag into text.", 2);
784815
$response = array();

chatbot/core/conversation/intialise_conversation.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ function load_that($convoArr)
629629
}
630630
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Inputs returned:' . print_r($tmpInputRows, true), 1);
631631
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Loading previous responses into the ~THAT~ array.', 4);
632-
array_reverse($tmpThatRows);
632+
$tmpThatRows = array_reverse($tmpThatRows);
633633
foreach ($tmpThatRows as $row)
634634
{
635635
$row = str_replace($puncuation, '.', $row);
@@ -644,7 +644,7 @@ function load_that($convoArr)
644644
$convoArr = push_on_front_convoArr('that', $value, $convoArr);
645645
}
646646
runDebug(__FILE__, __FUNCTION__, __LINE__, 'Loading previous user inputs into the ~INPUT~ array.', 4);
647-
array_reverse($tmpInputRows);
647+
$tmpInputRows = array_reverse($tmpInputRows);
648648
foreach ($tmpInputRows as $row)
649649
{
650650
$row = str_replace($puncuation, '.', $row);

gui/jquery/index.php

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
***************************************/
1111
$cookie_name = 'Program_O_JSON_GUI';
1212
$convo_id = (isset($_COOKIE[$cookie_name])) ? $_COOKIE[$cookie_name] : get_convo_id();
13-
$bot_id = (isset($_COOKIE['bot_id'])) ? $_COOKIE['bot_id'] : 1;
13+
$bot_id = (isset($_COOKIE['bot_id'])) ? $_COOKIE['bot_id'] : 1; // 1
1414
setcookie('bot_id', $bot_id);
15-
$display = '';
15+
$display = 'Please make sure that you edit this file to change the value of the variable $url in this file to reflect the correct URL address of your chatbot, and to remove this message.' . PHP_EOL;
16+
#$display = '';
1617
$url = 'http://localhost/Program-O/Program-O/chatbot/conversation_start.php';
17-
$display = 'Make sure that you edit this file to change the value of $url below to reflect the correct address, and to remove this message.' . PHP_EOL;
18-
$url = 'http://www.example.com/programo/chatbot/conversation_start.php';
18+
$url = 'http://api.program-o.com/v2.3.1/chatbot/';
19+
$url = 'chat.php';
1920

2021
function get_convo_id()
2122
{
@@ -56,7 +57,7 @@ function get_convo_id()
5657
.bot_name {
5758
color: rgb(204, 0, 0);
5859
}
59-
#shameless_plug {
60+
#shameless_plug, #urlwarning {
6061
position: absolute;
6162
right: 10px;
6263
bottom: 10px;
@@ -67,6 +68,33 @@ function get_convo_id()
6768
padding: 5px;
6869
border-radius: 5px;
6970
}
71+
#urlwarning {
72+
right: auto;
73+
left: 10px;
74+
width: 50%;
75+
font-size: large;
76+
font-weight: bold;
77+
background-color: white;
78+
}
79+
.leftside {
80+
text-align: right;
81+
float: left;
82+
width: 48%;
83+
}
84+
.rightside {
85+
text-align: left;
86+
float: right;
87+
width: 48%;
88+
}
89+
.centerthis {
90+
width: 90%;
91+
}
92+
#chatdiv {
93+
margin-top: 20px;
94+
text-align: center;
95+
width: 100%;
96+
}
97+
7098
</style>
7199
</head>
72100
<body>
@@ -77,28 +105,32 @@ function get_convo_id()
77105
Program O Forums</a> to ask for assistance.
78106
</p>
79107
<div class="centerthis">
108+
<div class="rightside">
80109
<div class="manspeech"><div class="triangle-border bottom blue"><div class="botsay">Hey!</div></div></div>
81-
<div class="dogspeech"><div class="triangle-border bottom orange"><div class="usersay">&nbsp;</div></div></div>
82110
<div class="man"></div>
111+
</div>
112+
<div class="leftside">
113+
<div class="dogspeech"><div class="triangle-border-right bottom orange"><div class="usersay">&nbsp;</div></div></div><br />
83114
<div class="dog"></div>
115+
</div>
84116
</div>
85117
<div class="clearthis"></div>
86118
<div class="centerthis">
87119
<form method="post" name="talkform" id="talkform" action="index.php">
88-
<p>
89-
<label>Say:</label>
90-
<input type="text" name="say" id="say"/>
120+
<div id="chatdiv">
121+
<label for="submit">Say:</label>
122+
<input type="text" name="say" id="say" size="60"/>
91123
<input type="submit" name="submit" id="submit" class="submit" value="say" />
92124
<input type="hidden" name="convo_id" id="convo_id" value="<?php echo $convo_id;?>" />
93125
<input type="hidden" name="bot_id" id="bot_id" value="<?php echo $bot_id;?>" />
94126
<input type="hidden" name="format" id="format" value="json" />
95-
</p>
127+
</div>
96128
</form>
97129
</div>
98130
<div id="shameless_plug">
99131
To get your very own chatbot, visit <a href="http://www.program-o.com">program-o.com</a>!
100132
</div>
101-
<?php echo $display ?>
133+
<div id="urlwarning"><?php echo $display ?></div>
102134
<script type="text/javascript" src="jquery-1.3.min.js"></script>
103135
<script type="text/javascript" >
104136
$(document).ready(function() {

0 commit comments

Comments
 (0)