<?php
//observe for poll submission
if((int)$_POST['poll'] > 0)
{
$pid = (int)$_POST['poll'];
$answer = (int)$_POST['answer'];
$ip = $site->ip();
$stamp = time();
$mysql->insert("fs_poll_votes", "poll_id,answer_id,ip,stamp", "$pid,$answer,$ip,$stamp");
//set poll cookie
setcookie('poll', $pid.'|'.$_COOKIE['poll'], strtotime("+14 days"), "/");
//redirect
header("Location: #results".$_POST['poll']);
exit;
}
//check for polls, replaces images with poll code
$active = settings('polls_enabled');
if(strstr($mainhtml, 'class="poll"') || strstr($mainhtml, 'class=poll'))
{
preg_match_all('/<img[^>]+>/i', $mainhtml, $allImages);
if(is_array($allImages[0]))
{
foreach($allImages[0] as $key => $image)
{
if(strstr($image, 'poll'))
{
list($junk, $id) = explode("?id=", $image);
$poll_content = ($active['polls_enabled'] == 'y') ? $site->show_poll($id) : '';
$mainhtml = str_replace($image, $poll_content, $mainhtml);
}
}
}
//load prototype in head if it hasnt already
if(!strstr($mainhtml, '/prototype/'))
{
$mainhtml = str_replace("</head>", '<style>.validation-advice{font-weight:bold;}</style><script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/prototype/1.7.0.0/prototype.js"></script><script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/scriptaculous/1.8.3/scriptaculous.js?load=effects"></script><script type="text/javascript" src="/inc/blog/src/validation.js"></script>
<script type="text/javascript">function anibars(pollid){var section=(pollid)?$$(\'div.pollbar\'+pollid+\'\'):$$(\'div.pollbar\');section.each(function(bar){var width=bar.style.width;bar.style.width=\'0\';$(bar.id).morph(\'width:\'+width+\';\');});}document.observe("dom:loaded", function(){anibars();});</script></head>', $mainhtml);
}
}
?>