0
mirror of https://github.com/valentineus/iii-module.git synced 2025-04-29 01:51:25 +03:00
This commit is contained in:
Valentin Popov 2016-09-21 18:12:07 +04:00
parent b9628f189b
commit 07c1b99cb5
6 changed files with 61 additions and 40 deletions

View File

@ -1,12 +1,18 @@
<?php <?php
/** /**
* Function of saving the token in a cookie. * The function returns the current ID.
* When you receive the new value clears all stored cookies. * Returns zero if no ID is stored.
* @param $token - The values of the token.
*/ */
function NewToken($token) { function GetID() {
unset($_COOKIE); // Removes all // Search current ID...
SetCookie("BOT_TOKEN", $token); // Save a new cookie if (isset($_COOKIE['CURRENT_ID'])) {
$id = (int)$_COOKIE['CURRENT_ID'] + 1;
// ...or returns zero
} else {
$id = 0;
}
// We issue results
return $id;
} }
/** /**
@ -33,22 +39,6 @@ function GetSession($token, $bot) {
} }
} }
/**
* 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 function overrides the current ID to
* the specified or the next. If any missing ID * the specified or the next. If any missing ID
@ -67,8 +57,29 @@ function SetID($id) {
$id = 1; $id = 1;
} }
SetCookie('CURRENT_ID', $id, time()+300); // Save the result SetCookie('CURRENT_ID', $id, time()+300); // Save the result
// We issue results return $id; // We issue results
return $id; }
/**
* Cleaning function of the parameter that is passed to it.
* @param $type - Type cleansed.
*/
function ClearingCache($type) {
switch ($type) {
// Clear the cookies
case 'cookies':
foreach ($_COOKIE as $key => $value) {
SetCookie($key, $value, time()-1000);
}
break;
// Clear the POST
case 'post':
$_POST = array();
break;
// ...
default:
break;
}
} }
/** /**

View File

@ -1,8 +1,8 @@
<!-- Beginning footer --> <!-- Beginning footer -->
<footer class="footer"> <footer class="footer">
<div class="container"> <div class="container">
<p class="text-muted"> <p class="text-muted text-center">
<a href="mailto:dev@valentineus.link">dev@valentineus.link</a> With love <i class="glyphicon glyphicon-heart text-danger"></i> from Russia
</p> </p>
</div> </div>
</footer> </footer>

View File

@ -1,8 +1,10 @@
<!-- Start navigation bar --> <!-- Start navigation bar -->
<nav class="navbar navbar-default navbar-fixed-top"> <nav class="navbar navbar-default navbar-fixed-top">
<!-- Loaded banner GitHub -->
<a href="https://github.com/valentineus/Module-III-API"> <a href="https://github.com/valentineus/Module-III-API">
<img class="github-fork"> <img class="github-fork">
</a> </a>
<!-- Filling panel -->
<div class="container"> <div class="container">
<div class="collapse navbar-collapse"> <div class="collapse navbar-collapse">
<!-- The right side of the navigation bar --> <!-- The right side of the navigation bar -->

View File

@ -9,6 +9,7 @@
<div class="col-md-4"> <div class="col-md-4">
<button type="submit" class="btn btn-default">Submit</button> <button type="submit" class="btn btn-default">Submit</button>
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#SettingsModal">Settings</button> <button type="button" class="btn btn-success" data-toggle="modal" data-target="#SettingsModal">Settings</button>
<button type="submit" class="btn btn-danger" name="reset">Reset</button>
</div> </div>
</div><!-- row --> </div><!-- row -->
</form> </form>

View File

@ -1,8 +1,3 @@
<?php
ini_set("display_errors","1");
ini_set("display_startup_errors","1");
ini_set('error_reporting', E_ALL);
?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
@ -20,6 +15,7 @@ ini_set('error_reporting', E_ALL);
<!-- Title --> <!-- Title -->
<title>Testing conversational bot</title> <title>Testing conversational bot</title>
</head> </head>
<body> <body>
<?php // Connect all of the dependencies <?php // Connect all of the dependencies
include("../src/bot.php"); // Class for working with AI include("../src/bot.php"); // Class for working with AI
@ -27,16 +23,27 @@ ini_set('error_reporting', E_ALL);
include("components/navbar.php"); // Connect the navigation bar include("components/navbar.php"); // Connect the navigation bar
include("components/settings.php"); // Connecting a modal window with the settings include("components/settings.php"); // Connecting a modal window with the settings
?> ?>
<!-- Begin page content --> <!-- Begin page content -->
<div class="container"> <div class="container">
<div class="page-header"> <div class="page-header">
<h1>Communication Panel</h1> <h1>Communication Panel</h1>
</div> </div>
<?php <?php
// Treat the reset button
if (isset($_POST['reset'])) {
ClearingCache("cookies"); // We clear all cookies
ClearingCache("post"); // Removes all requests that were not processed
header("Location: " . $_SERVER["REQUEST_URI"]); // Reloading the page
}
// Checking the token initialization // Checking the token initialization
if (isset($_POST['BOT_TOKEN'])) { if (isset($_POST['BOT_TOKEN'])) {
$token = htmlspecialchars($_POST['BOT_TOKEN']); $token = htmlspecialchars($_POST['BOT_TOKEN']);
NewToken($token); ClearingCache("cookies"); // We clear all cookies
SetCookie("BOT_TOKEN", $token); // Save a new cookie
header("Location: " . $_SERVER["REQUEST_URI"]); // Reloading the page
// ...Finding saved token // ...Finding saved token
} elseif (isset($_COOKIE['BOT_TOKEN'])) { } elseif (isset($_COOKIE['BOT_TOKEN'])) {
$token = $_COOKIE['BOT_TOKEN']; $token = $_COOKIE['BOT_TOKEN'];
@ -47,7 +54,8 @@ ini_set('error_reporting', E_ALL);
// Initialize the robot system // Initialize the robot system
define('BOT_TOKEN', $token); define('BOT_TOKEN', $token);
$bot = new Bot(BOT_TOKEN); $bot = new Bot(BOT_TOKEN);
$session = GetSession($token, $bot); // Initialize the session // Initialize the session
$session = GetSession($token, $bot);
if (empty($session)) { // No session? Error! ?> if (empty($session)) { // No session? Error! ?>
<!-- Error Notification --> <!-- Error Notification -->
<div class="alert alert-danger alert-dismissible" role="alert"> <div class="alert alert-danger alert-dismissible" role="alert">
@ -65,16 +73,15 @@ ini_set('error_reporting', E_ALL);
// Processes the message // Processes the message
if (isset($_POST['textarea'])) { if (isset($_POST['textarea'])) {
$currentid = GetID(); // Get the current ID
$currenttext = htmlspecialchars($_POST['textarea']); // Transform text $currenttext = htmlspecialchars($_POST['textarea']); // Transform text
SavingStories($currentid, $currenttext, 'user'); // Keeping your message SavingStories(GetID(), $currenttext, 'user'); // Keeping your message
$currentid = SetID($currentid); // Get next ID $currentid = SetID(GetID()); // Get next ID
SavingStories($currentid, $bot->say($currenttext), 'bot'); // Save bot response SavingStories(SetID($currentid), $bot->say($currenttext), 'bot'); // Save bot response
header("Location: " . $_SERVER["REQUEST_URI"]); // Reloading the page header("Location: " . $_SERVER["REQUEST_URI"]); // Reloading the page
} }
// Connecting the system interface // Connecting the system interface
include("components/communication.php"); // Settings panel include("components/on-board-panel.php"); // Settings panel
include("components/results.php"); // Output messages include("components/results.php"); // Output messages
?> ?>
</div> </div>

File diff suppressed because one or more lines are too long