1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
| <?php
/***************************************
* http://www.program-o.com
* PROGRAM O
* Version: 2.3.1
* FILE: index.php
* AUTHOR: Elizabeth Perreau and Dave Morton
* DATE: 07-23-2013
* DETAILS: This is the XML GUI interface for Program O
***************************************/
// $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.';
$url = 'http://mon-site.fr/chatbot/conversation_start.php';
$display_template = <<<end_display
<span class="user_name">[user_name]: </span><span class="user_say">[input]</span><br>
<span class="bot_name">[bot_name]: </span><span class="bot_say">[response]</span><br>
end_display;
$post_vars = (!empty($_POST)) ? filter_input_array(INPUT_POST) : array();
$get_vars = (!empty($_GET)) ? filter_input_array(INPUT_GET) : array();
$request_vars = array_merge($get_vars, $post_vars);
$convo_id = (isset ($request_vars['convo_id'])) ? $request_vars['convo_id'] : get_convo_id();
$bot_id = (isset ($request_vars['bot_id'])) ? $request_vars['bot_id'] : 2;
if (!empty ($request_vars))
{
$options = array(
CURLOPT_USERAGENT => 'Program_O_XML_API',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
//CURLOPT_CONNECTTIMEOUT => 3,
);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request_vars);
$data = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXMLElement($data);
$display = '';
$success = $xml->status->success;
if (isset($xml->status->message))
{
$message = (string) $xml->status->message;
$display = 'There was an error in the script. Message = ' . $message;
}
else
{
$user_name = (string) $xml->user_name;
$bot_name = (string) $xml->bot_name;
$chat = $xml->chat;
$lines = $chat->xpath('line');
foreach ($lines as $line)
{
$input = (string) $line->input;
$response = (string) $line->response;
$tmp_row = str_replace('[user_name]', $user_name, $display_template);
$tmp_row = str_replace('[bot_name]', $bot_name, $tmp_row);
$tmp_row = str_replace('[input]', $input, $tmp_row);
$tmp_row = str_replace('[response]', $response, $tmp_row);
$display .= $tmp_row;
}
}
}
function get_convo_id()
{
if (isset($_COOKIE['Program_O_XML_API'])) $convo_id = $_COOKIE['Program_O_XML_API'];
else
{
session_name('Program O XML GUI');
session_start();
$convo_id = session_id();
session_destroy();
}
return $convo_id;
}
?>
<!DOCTYPE html>
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="template/css/foundation.css">
<link rel="stylesheet" href="template/css/foundation-icons.css">
<script src="template/js/vendor/custom.modernizr.js"></script>
<style type="text/css">
h3 {
text-align: center;
}
.user_name {
color: rgb(16, 45, 178);
}
.bot_name {
color: rgb(204, 0, 0);
}
</style>
<script language="javascript">
window.onload = auto_refresh;
function auto_refresh()
{
new Ajax.Updater("chat", "./bot2.php", {parameters:'mode=auto_refresh', evalScripts:true, asynchronous:true})
setTimeout("auto_refresh()",2000);
return true
}
</script>
<!-- <script type="text/javascript">
function refresh() {
$.ajax({
url: "./bot2.php",
success:
function(retour){
$("response").html(retour);
}
});
}
setInterval("refresh()", 1000)
</script> -->
</head>
<body>
<?php include("template/inc/header.inc.php"); ?>
<!-- Main Page Content and Sidebar -->
<div class="row">
<!-- Main Blog Content -->
<div class="large-9 columns">
<article>
<div class="text-justify">
<br>
<div class="row">
<div class="large-11 columns">
<h1>A propos</h1>
<br>
<p>
<body onload="document.forms[0].say.focus();">
<h3>Posez vos questions</h3>
<div id="chat">
<img src="live.png">
<form accept-charset="utf-8" method="get" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<p>
<input type="text" name="say" id="say" />
<input id="bot_id" type="hidden" name="bot_id" value="<?php echo $bot_id ?>">
<input id="convo_id" type="hidden" name="convo_id" value="<?php echo $convo_id ?>">
<input id="format" type="hidden" name="format" value="xml">
<input type="submit" value="Chat" OnClick="auto_refresh()"/>
</p>
</form>
<div id="response">
<?php echo $display ?>
</div>
</div>
</p>
</div>
</div>
</div>
</article>
</div>
<!-- End Main Content -->
<!-- Sidebar -->
<?php include("template/inc/sidebar.inc.php"); ?>
<!-- End Sidebar -->
</div>
<!-- End Main Content and Sidebar -->
<?php include("template/inc/footer.inc.php"); ?>
</body>
</html> |
Partager