Demo in beta mode.

This commit is contained in:
Valentin Popov committed 2016-09-21 06:40:03 +04:00
1 parent 288980ceb3
commit b9628f189b
14 files changed
+267 -205

No files matched your search

+106
View File
@@ -0,0 +1,106 @@
<?php
/**
* Function of saving the token in a cookie.
* When you receive the new value clears all stored cookies.
* @param $token - The values of the token.
*/
function NewToken($token) {
unset($_COOKIE); // Removes all
SetCookie("BOT_TOKEN", $token); // Save a new cookie
}
/**
* Session initialization function.
* Searches saved session, producing a new
* init or returns zero on failure.
* @param $token - The values of the token.
* @param $bot - Initialized bot.
*/
function GetSession($token, $bot) {
// Search the old session
if (isset($_COOKIE['BOT_SESSION'])) {
$session = $bot->session($_COOKIE['BOT_SESSION']);
} else { // Open a new one
$session = $bot->session();
SetCookie("BOT_SESSION", $session);
}
// We issue results
if (isset($session)) {
return $session;
} else {
return 0;
}
}
/**
* The function returns the current ID.
* Returns zero if no ID is stored.
*/
function GetID() {
// Search current ID...
if (isset($_COOKIE['CURRENT_ID'])) {
$id = (int)$_COOKIE['CURRENT_ID'] + 1;
// ...or returns zero
} else {
$id = 0;
}
// We issue results
return $id;
}
/**
* The function overrides the current ID to
* the specified or the next. If any missing ID
* returns the one.
* @param $id - Current ID.
*/
function SetID($id) {
// Process the specified ID...
if (isset($id)) {
$id = $id + 1;
// ...Or are saved...
} elseif (isset($_COOKIE['CURRENT_ID'])) {
$id = (int)$_COOKIE['CURRENT_ID'] + 1;
// ...Or return one
} else {
$id = 1;
}
SetCookie('CURRENT_ID', $id, time()+300); // Save the result
// We issue results
return $id;
}
/**
* The function maintains a history of conversations,
* using a database of cookie files.
* @param $currentid - Message ID.
* @param $textarea - Message text.
* @param $type - Who said (Man / Bot).
*/
function SavingStories($currentid, $textarea, $type) {
// We form an array with values
$cookie = array(
'type' => $type,
'textarea' => $textarea,
'time' => time());
// Save by encoding in JSON-string
SetCookie("TALK".$currentid, json_encode($cookie), time()+60);
}
/**
* Function line formation.
* @param $id - Variable Message ID.
*/
function ShowRecord($id) {
for ($i=0; $i < $id; $i++) {
if (isset($_COOKIE['TALK'.$i])) {
$cookie = json_decode($_COOKIE['TALK'.$i], true);
echo("<tr>");
echo("<td>".$cookie['type']."</td>");
echo("<td>".$cookie['textarea']."</td>");
echo("<td>".date("H:i:s", $cookie['time'])."</td>");
echo("</tr>");
}
}
} ?>
+16
View File
@@ -0,0 +1,16 @@
<!-- Home side panel -->
<form class="form-horizontal" method="post">
<div class="row">
<!-- Text field -->
<div class="col-md-8">
<input class="form-control" type="text" name="textarea" value="">
</div>
<!-- Control buttons -->
<div class="col-md-4">
<button type="submit" class="btn btn-default">Submit</button>
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#SettingsModal">Settings</button>
</div>
</div><!-- row -->
</form>
<br/>
<!-- End side panel -->
+9
View File
@@ -0,0 +1,9 @@
<!-- Beginning footer -->
<footer class="footer">
<div class="container">
<p class="text-muted">
<a href="mailto:dev@valentineus.link">dev@valentineus.link</a>
</p>
</div>
</footer>
<!-- End footer -->
+24
View File
@@ -0,0 +1,24 @@
<!-- Start navigation bar -->
<nav class="navbar navbar-default navbar-fixed-top">
<a href="https://github.com/valentineus/Module-III-API">
<img class="github-fork">
</a>
<div class="container">
<div class="collapse navbar-collapse">
<!-- The right side of the navigation bar -->
<ul class="nav navbar-nav navbar-right">
<li>
<p class="navbar-text"><?php
// Check the ability to use Cookie
if (SetCookie("TestCookie", "Success")) { ?>
<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
<?php } else { ?>
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
<?php }
?> Cookie</p>
</li>
</ul><!-- navbar-right -->
</div>
</div><!-- container -->
</nav>
<!-- End navigation bar -->
+12
View File
@@ -0,0 +1,12 @@
<div class="row">
<div class="col-md-12">
<table class="table table-striped">
<tr>
<th>#</th>
<th>Text</th>
<th>Date</th>
</tr>
<?php ShowRecord(GetID()); ?>
</table>
</div>
</div>
+24
View File
@@ -0,0 +1,24 @@
<!-- Start pop-up window for the settings -->
<div class="modal fade" id="SettingsModal" tabindex="-1" role="dialog" aria-labelledby="SettingsModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form class="form-horizontal" method="post">
<div class="modal-body">
<!-- Elements of a modal window -->
<div class="form-group">
<label for="inputPassword" class="col-sm-2 control-label">ID:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="inputPassword" name="BOT_TOKEN" placeholder="109cd867-0ef3-4473-af71-7543a9b2fccd">
</div>
</div>
</div>
<!-- The window control buttons -->
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-success">Save changes</button>
</div>
</form>
</div><!-- modal-content -->
</div><!-- modal-dialog -->
</div>
<!-- End pop-up window for the settings -->
+83
View File
@@ -0,0 +1,83 @@
<?php
ini_set("display_errors","1");
ini_set("display_startup_errors","1");
ini_set('error_reporting', E_ALL);
?>
<!DOCTYPE html>
<html>
<head>
<!-- Connecting library jQuery -->
<script src="https://code.jquery.com/jquery-3.1.0.slim.min.js" integrity="sha256-cRpWjoSOw5KcyIOaZNo4i6fZ9tKPhYYb6i5T9RSVJG8=" crossorigin="anonymous"></script>
<!-- Connecting library Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<!-- Custom styles -->
<link href="style.css" rel="stylesheet">
<!-- Meta -->
<meta charset="utf-8">
<meta name="robots" content="NONE">
<!-- Title -->
<title>Testing conversational bot</title>
</head>
<body>
<?php // Connect all of the dependencies
include("../src/bot.php"); // Class for working with AI
include("components/class-application.php"); // Class to work with application logic
include("components/navbar.php"); // Connect the navigation bar
include("components/settings.php"); // Connecting a modal window with the settings
?>
<!-- Begin page content -->
<div class="container">
<div class="page-header">
<h1>Communication Panel</h1>
</div>
<?php
// Checking the token initialization
if (isset($_POST['BOT_TOKEN'])) {
$token = htmlspecialchars($_POST['BOT_TOKEN']);
NewToken($token);
// ...Finding saved token
} elseif (isset($_COOKIE['BOT_TOKEN'])) {
$token = $_COOKIE['BOT_TOKEN'];
}
// The next step - checking/initialize the session with the bot.
if (isset($token)) {
// Initialize the robot system
define('BOT_TOKEN', $token);
$bot = new Bot(BOT_TOKEN);
$session = GetSession($token, $bot); // Initialize the session
if (empty($session)) { // No session? Error! ?>
<!-- Error Notification -->
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<strong>Error!</strong> Failed to create a session!
</div>
<?php }
} else { // Nope token? A warning! ?>
<!-- Error Notification -->
<div class="alert alert-warning alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<strong>Attention!</strong> No token: Required to check the settings!
</div>
<?php }
// Processes the message
if (isset($_POST['textarea'])) {
$currentid = GetID(); // Get the current ID
$currenttext = htmlspecialchars($_POST['textarea']); // Transform text
SavingStories($currentid, $currenttext, 'user'); // Keeping your message
$currentid = SetID($currentid); // Get next ID
SavingStories($currentid, $bot->say($currenttext), 'bot'); // Save bot response
header("Location: ".$_SERVER["REQUEST_URI"]); // Reloading the page
}
// Connecting the system interface
include("components/communication.php"); // Settings panel
include("components/results.php"); // Output messages
?>
</div>
<?php include("components/footer.php"); // Connect the bottom panel ?>
</body>
</html>
+40
View File
@@ -0,0 +1,40 @@
html {
position: relative;
min-height: 100%;
}
body {
margin-bottom: 60px;
}
body > .container {
padding: 60px 15px 0;
}
textarea.form-control {
resize: none;
}
.footer {
background-color: #f5f5f5;
position: absolute;
height: 60px;
width: 100%;
bottom: 0;
}
.container .text-muted {
margin: 20px 0;
}
/* Loaded one icon from GitHub */
.github-fork {
background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJUAAACVCAYAAABRorhPAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAHEFJREFUeNrsXWlwVNeVPg1aQCtowTaoJdSL1NrQhlgk7CSTmSR2pmpScWYs/0jAmYDzY5I4M7anagIkBqdSjrHH2K6UESJge2oMSZxMqmaM4wWDCcggQIAkJIGNrR3tG0JgS+p53319u1+/XtVPS7d0DzzU3WqJ061P3zn3nHO/q7NarSRsaqaTjN+0XYts12LpClNd4bgiIqMTV+qN/2U2GU2RERHU1t5OLa3tQfF6YmNjKMNsIu5Xc0vrswM9zbukT01I16Tto9V2m2y35Rtu8BMmIDIjgApXXhGRUcnRcckHc7Itpvj4eDr2wYf0+eefB81rys3JIu7Xndtjzw/0tvxK8fqmbAJUMwOoCP4xPCIq+Z5VxoOrUlYao6OjqaGhKWgAFSP5k6JfRdyv27fH9g72tjyj9fsKUE0voCIUoJIAtXRF3PK7KouK8o0TkxN05ux5Gh0dDYrXs2jRIiouLiDu182R4ZclQO1RPMWquJxCns/vLeAyI4CKlAF1d2VmZoZp2bJ4amr6mEZGRmhycjIoAJWRYSLu19DgwG/6uj97zpYz+QKST3DpRKI+rYCK5Ax1zypDZW5uthE/gubWNursvBEUryc6OorycrOJ+9XW1rpvqK8NgLojXYjLX9iucUWiPumGuTwm6oKpZgBQMfEr9mdkmI3JyUl04eLloAEULDPDTNwvCVD7JUDtVYHHE4j8Zh+RU00zoFalmg6k6vWGmJhoulx7JWiScpQN0lL1xP0auzVaOdTf9qKNkcYVzDShApR1KoASoJoBhirIX2MIW7y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ABq3qz+tLResC8vUVqeV1dfYKMi3n+tXO+cOv0R+/jo1u87PY4dLxhnAeAALLj1vUe20eZHHnXJodSAQuuluCifuF/BsnN4wYBKS3PYbDYbl0OUoukaS7S9C987r/r4v2wkheTNCuXlDzp9xa9tA3bIuZ584jEaHhqRN4CqciidqjmMATvuV39fX8j38kIKVAGPr6QYD6xfV2JaJq3Uzp2rod6+PvJJUVbnVR9/GEz1MzZVQKxvhzyKz0GxMCcZVoXo5fmah8Is+bqSYuJ+dXXdWFAMNeeJupakvGRtkenuu++md9495odOuXqUxXn3C+ewcsUkJ1ivrv4Kq1Hh9re+/bBfZYO1xQXE/QrpeahQXP1pGQHWp6QYkpOS6NPmFlUvLzBAKR5hIEIYxEeyVdftmgdeywYxrLnM/Qq2Xt68B5UWhsKAHXSYzlafV7VeyGdNilfSsWkByTcef0MKa7zFolP8ixyKaSBIYCIOI6e8yZmhMGDH/Rq9eTNoK+XzElRaxDKMhnQjJJzP11x0Mw/lu8hJbBfMBnr10D5HSUECFFZ0KBXoOEh0KogpXFYzFLZRYecw92u+jK+EDKgCBdSKe9IqiwoLjRPj43T908+ox6fwvXOY4yJjfEsVWAj77+QV3U8ZsDYzYDXYAaQeVXEHKFTIiwoLiPt148aNedMcDonip9Z9eclJCVQrJc7dPoXvnWekOEMhlD3x+GM29ZWPWP0JdSjMQOFzrx6ssIVEslfKHWDSKcpRygE7I3G/Ojs75+W0QdCWFLT08goL8k2xMbFUc7GWbVLwp2yg1IniN9Eg5iMq2P2C+SdWKrLine truncated
background-size: cover;
position: absolute;
height: 149px;
width: 149px;
border: 0;
left: 0;
top: 0;
}