<?
    require("merziablog.php");
    $usualreader = isset($_COOKIE['usualreader']);
    if (!$usualreader) setUsualReaderCookie();
    if (!isset($_GET['i'])) {
        header("Location: /");
        exit;
    }
    $pagename = trim($_GET['i']);
    $pagename = rtrim($pagename,"/");
    $pagename = preg_replace('/(.*?)(\.html)?$/e',"'\\1'",$pagename);
    $postid = intval($pagename);
    $accessbyid = true;
    if (strlen($pagename)) {
        $row = mysqlQueryResult("SELECT id FROM blogentry WHERE name=",$pagename);
        if ($row) {
            $postid = $row['id'];
            $accessbyid = false;
        }
    }
    $title = blogPostTitleById($postid);
    if ($title !== false) {
        # Emit a permanently moved if needed
        $row = mysqlQueryResult("SELECT name FROM blogentry WHERE id=",$postid);
        if ($accessbyid && strlen($row['name'])) {
            header("HTTP/1.1 301 Moved Permanently");
            header("Location: ".permaLink($row));
            exit;
        }
        incrementPostVisit($postid);
    }
    Config("title",$title);
    include("header.php");
?>
<?
$flags = 0;
if (isset($_GET['pc'])) {
    $previewcode = readSecureId($_GET['pc'],"preview");
    if ($previewcode == $postid) $flags = POST_PREVIEW;
}
if (showBlogPost($postid,$flags)==0) {
    echo("<b>Post non esistente</b>");
    include("footer.php");
    exit;
}
if (!$usualreader) include("rssad.php");
?>
<h4>Comments</h4>
<?
if ($postid < 234) {
    showBlogPostComments($postid);
} else {
    $row = mysqlQueryResult("SELECT name FROM blogentry WHERE id=",$postid);
    $row['id'] = $postid;
    $plink = permaLink($row); 
?>
<div id="disqus_thread_outdiv">
<div id="disqus_thread"></div>
</div>
<script type="text/javascript">
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
    var disqus_shortname = 'antirezweblog'; // required: replace example with your forum shortname

    // The following are highly recommended additional parameters. Remove the slashes in front to use.
    var disqus_identifier = 'antirez_weblog_<?=$postid?>';
    var disqus_url = '<?=$plink?>';

    /* * * DON'T EDIT BELOW THIS LINE * * */
    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>
<? } ?>

<? if ($postid < 234) { /* ?>
<form id="f" method="post" action="/addblogcomment.php" onsubmit="return sillyCheck()">
<div id="postcomment">
<b>Send a comment</b><br/><br/>
<table>
<tr>
<td>name</td>
<td><input type="text" name="name" size="50" value="<?fillForm("commentdata","name")?>" /></td>
</tr>
<tr>
<td valign="top">comment body</td>
<td><textarea name="body" rows="5" cols="55"></textarea></td>
</tr>
<tr>
<td colspan="2">Write <b>limone</b> here if you are human -&gt;
<input type="text" name="silly" size="6" value="<?fillForm("commentdata","silly")?>" /><img style="vertical-align: bottom;" src="/limone.png" alt="citrix antispam" /> <small style="color:#666666;">citrix antispam</small></td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="submit" name="doit" value="Send comment" />
</td>
</tr>
</table>
<input type="hidden" name="postid" value="<?echo($postid)?>" />
</div>
</form>
<? */
echo("<b>comments closed</b>");
} ?>

<script type="text/javascript">
function sillyCheck() {
    var f = document.getElementById('f');
    if (f.silly.value != "limone") {
        alert("You must write 'limone' where specified!");
        return false;
    }
    return true;
}
</script>

<?
    include("footer.php")
?>
