mirror of
				https://github.com/valentineus/iii-module.git
				synced 2025-11-04 04:29:44 +03:00 
			
		
		
		
	Demo in beta mode.
This commit is contained in:
		
							
								
								
									
										106
									
								
								demo/components/class-application.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										106
									
								
								demo/components/class-application.php
									
									
									
									
									
										Normal 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
									
								
								demo/components/communication.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								demo/components/communication.php
									
									
									
									
									
										Normal 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
									
								
								demo/components/footer.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								demo/components/footer.php
									
									
									
									
									
										Normal 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
									
								
								demo/components/navbar.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								demo/components/navbar.php
									
									
									
									
									
										Normal 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
									
								
								demo/components/results.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								demo/components/results.php
									
									
									
									
									
										Normal 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
									
								
								demo/components/settings.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								demo/components/settings.php
									
									
									
									
									
										Normal 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 -->
 | 
			
		||||
		Reference in New Issue
	
	Block a user