Skip to content

Instantly share code, notes, and snippets.

@mhawksey mhawksey/tw-evs.php
Created Apr 21, 2010

Embed
What would you like to do?
TwEVS PHP version
<?php
/*
Name: TwEVS
URI: http://www.rsc-ne-scotland.org.uk/mashe/twevs/
Description: Turn twitter into a cheap electronic voting system. Ask the audience to tweet a custom hashtag with their response (i.e. A, B or C or Yes/No etc) then run the pipe entering the hashtag (you should use a different hashtag for each question).
Author: Martin Hawksey
Author URI: http://www.rsc-ne-scotland.org.uk/mashe
Version: 1.0
*/
/* Copyright 2009 Martin Hawksey (email : martin.hawksey@gmail.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
if (isset($_GET['tag'])){
require_once('scripts/simplepie.php');
$rss = new SimplePie();
$url = "http://search.twitter.com/search.atom?q=%23".$_GET['tag'];
$pgA = array();
for ($x=1; $x<=1; $x++){
$pgA[] = $url."&page=".$x."&rpp=100";
}
$i = array();
$rss->set_feed_url($pgA);
$rss->enable_cache(false);
$rss->init();
$rss->handle_content_type();
foreach ($rss->get_items() as $item) {
$i[] = preg_replace('/.*#'.$_GET['tag'].'(.*)/i','$1', strtoupper($item->get_content()));
}
if (isset($i)){
$v = array_count_values($i);
ksort($v);
$chd = implode(',',$v);
$v = array_reverse($v);
$l = "|";
foreach($v as $key => $value){
$l .= $key."+[".$value."]|";
}
$l = str_replace(" ","",$l);
$l = str_replace("</B></A>","",$l);
$barHeight=round(420/sizeof($v));
$url = "http://chart.apis.google.com/chart?chtt=Results+for+%23".$_GET['tag']."&chts=000000,20&chs=600x500&cht=bhs&chd=t:".$chd."&chds=0,".array_sum($v)."&chxt=x,y&chxl=1:$l&chbh=".$barHeight;
}
}
function TinyURL($u){
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,"http://tinyurl.com/api-create.php?url=".$u);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Results for #<?php echo $_GET['tag'];?></title>
</head>
<body>
<?php
if (isset($_GET['tag'])){
?>
<img src="<?php echo $url;?>"><br>
<a href="<?php echo TinyURL($url);?>">Chart Link</a> | <a href="http://www.rsc-ne-scotland.org.uk/mashe/twevs/indexv2.php">Another poll</a><?php
} else { ?>
<form action="" method="get"><input name="tag" type="text"><input name="submit" type="submit"></form>
<?php } ?><br><br>
<small>
Created by <a href="http://www.google.com/profiles/m.hawksey">m.hawksey</a> at
<a href="http://www.rsc-ne-scotland.ac.uk/">JISC RSC Scotland North & East</a></small>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.