<?php
/* configuration */
$dsn = 'sqlite:/tmp/comicschat2.sqlite'; // PDO DSN
$heroesDirPath = './img/heroes-demo/'; // path to images directory (avatars)
/* init */
require './comicschat.lib.php';
/* main */
try {
$book = new ComicBook (array (
'dsn' => $dsn,
'heroesDirPath' => $heroesDirPath,
));
$httpPath = parse_url ('http://' . $_SERVER ['SERVER_NAME'] . $_SERVER ['REQUEST_URI']);
$httpPath = 'http://' . $httpPath ['host'] . $httpPath ['path'];
if (!empty ($_POST)) {
$book->write ($_POST);
header ('Location: ' . $httpPath);
exit;
}
else {
$pageCount = $book->countPages ();
if (isset ($_GET ['g']))
$book->selectPages ($_GET ['g']);
$pageNumbers = $book->pageNumbers ();
if (($previousPage = $pageNumbers ? reset ($pageNumbers) - 1 : 0) < 1) $previousPage = null;
if (($nextPage = $pageNumbers ? end ($pageNumbers) + 1: 1) > $pageCount) $nextPage = $pageCount > 0 ? $pageCount : null;
$heroes = $book->listHeroes ();
$iterator = $book->getIterator ();
}
}
catch (PageNotExists $e) {
header ('HTTP/1.0 404 Not Found');
echo '<html><head><title>ComicBook Error</title></head><body><h1>ComicBook Error</h1><p>PAGE NO. <strong>' . $e->pageNumber . '</strong> DOES NOT EXIST</p></body></html>';
exit;
}
catch (Exception $e) {
echo 'SORRY. UNKNOWN ERROR OCCURED';
exit;
}
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-2">
<title>Comics chat</title>
<link rel="stylesheet" href="main.css" type="text/css" />
<script src="main.js" type="text/javascript"></script>
</head>
<body>
<div class="pageControl">
<a href="<?php echo $pageNumbers ? '?g=' . reset ($pageNumbers) : $httpPath ?>"><img src="img/arrowL.gif" alt="" title="na zaèátek" /><img src="img/arrowL.gif" alt="" title="na zaèátek" /></a> <a href="<?php echo $previousPage ? '?g=' . $previousPage : $httpPath ?>"><img src="img/arrowL.gif" alt="" title="na pøedchozí stránku" /></a> <button onclick="fold('form');document.getElementById('formText').focus()" type="button"><img src="img/littleBubble.gif" alt="" title="pøispìt" /></button> <a href="<?php echo $nextPage ? '?g=' . $nextPage : $httpPath ?>"><img src="img/arrowR.gif" alt="" title="na následující stránku" /></a> <a href="<?php echo $httpPath ?>"><img src="img/arrowR.gif" alt="" title="na poslední stránku" /><img src="img/arrowR.gif" alt="" title="na poslední stránku" /></a>
<a class="right">- <?php echo ($pageNumbers ? implode (', ', $pageNumbers) : 0) . '/' . $pageCount ?> -</a>
</div>
<div class="page">
<?php foreach ($iterator as $panel) {
if ($panel ['part'] == ComicBook::FIRST) $panel ['bubbleText'] .= ' ...';
else if ($panel ['part'] == ComicBook::INNER) $panel ['bubbleText'] = '... ' . $panel ['bubbleText'] . ' ...';
else if ($panel ['part'] == ComicBook::LAST) $panel ['bubbleText'] = '... ' . $panel ['bubbleText'];
$panelInfo = $book->getPanelInfo ($panel ['panelType']); ?>
<div class="win <?php echo 'x'.$panelInfo ['lx'].' y'.$panelInfo ['ly'].' w'.$panelInfo ['width'].' s'.$panelInfo ['height'] ?>"><div class="bubble"><div class="ru"><div class="ld"><div class="rd"><div class="content"><?php echo ($panel ['part'] == ComicBook::LAST || $panel ['part'] == ComicBook::INNER ? '... ' : '') . $panel ['bubbleText'] . ($panel ['part'] == ComicBook::FIRST || $panel ['part'] == ComicBook::INNER ? ' ...' : '') ?></div></div></div></div></div><div class="voice"> </div><img src="img/heroes-demo/<?php echo $panel ['hero'] ?>" class="hero" /></div>
<?php } ?>
</div>
<form action="<?php echo $httpPath ?>" method="post">
<div class="folder" id="form">
<div class="input">
<input type="hidden" id="hero" name="hero" value="1.gif" />
<button type="button" onclick="fold('heroList')"><img id="heroImage" src="img/heroes-demo/<?php echo reset ($heroes) ?>" alt="" /></button>
<textarea id="formText" name="text" cols="77" rows="17"></textarea>
</div>
<div class="control">
<button onclick="fold('form')" type="button">× zavøít</button>
<button type="submit">odeslat >></button>
</div>
<div class="folder" id="heroList">
<?php foreach ($heroes as $hero) { ?>
<button type="button" onclick="setHero('<?php echo $hero ?>');fold('heroList');document.getElementById('formText').focus()"><img src="img/heroes-demo/<?php echo $hero ?>" alt="" /></button>
<?php } ?></div>
</div>
</form>
</body>
</html>