Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: nanotube/supybot-bitcoin-marketmonitor
base: 490ae20096
...
head fork: nanotube/supybot-bitcoin-marketmonitor
compare: 2f71831c4b
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Feb 14, 2012
Daniel Folkinshteyn OTCWebsite: add json api to viewgpg.php f15e19f
Daniel Folkinshteyn OTCWebsite: add json api for viewratingdetail.php 2f71831
View
28 OTCWebsite/querytojson.php
@@ -0,0 +1,28 @@
+<?php
+# Thanks to http://code-slim-jim.blogspot.com/2011/07/php-sqlite-to-json-converter-page.html
+# for the nice snippet.
+function jsonOutput($query)
+{
+ $ofirst = true;
+ print "[\n";
+ foreach ($query as $row)
+ {
+ if($ofirst) $ofirst = false;
+ else print ",\n";
+
+ $first = true;
+ print "{";
+ foreach ($row as $key => $value)
+ {
+ if($first) $first = false;
+ else print ",";
+ if(is_numeric($value))
+ print '"' . $key . '": ' . $value;
+ else
+ print '"' . $key . '": "' . $value . '"';
+ }
+ print "}";
+ }
+ print "\n]\n";
+}
+?>
View
56 OTCWebsite/viewgpg.php
@@ -1,9 +1,3 @@
-<!DOCTYPE html>
-<?php
- $pagetitle = "#bitcoin-otc gpg key data";
- include("header.php");
-?>
-
<?php
$sortby = isset($_GET["sortby"]) ? $_GET["sortby"] : "nick";
$validkeys = array('id', 'nick', 'registered_at', 'keyid', 'fingerprint');
@@ -15,7 +9,42 @@
if (!in_array($sortorder, $validorders)) $sortorder = "ASC";
$nickfilter = isset($_GET["nick"]) ? $_GET["nick"] : "";
- $nickfilter = html_entity_decode($nickfilter)
+ $nickfilter = html_entity_decode($nickfilter);
+
+ $outformat = isset($_GET["outformat"]) ? $_GET["outformat"] : "";
+ $outformat = html_entity_decode($outformat);
+?>
+<?php
+ try { $db = new PDO('sqlite:./otc/GPG.db'); }
+ catch (PDOException $e) { die($e->getMessage()); }
+?>
+<?php
+ $queryfilter = array();
+ if ($nickfilter != "") $queryfilter[] = "nick LIKE '" . sqlite_escape_string($nickfilter) . "'";
+ if (sizeof($queryfilter) != 0) {
+ $queryfilter = " WHERE " . join(' AND ', $queryfilter);
+ }
+ else {
+ $queryfilter = "";
+ }
+?>
+<?php
+ include('querytojson.php');
+ if ($outformat == 'json'){
+ $sql = 'SELECT * FROM users ' . $queryfilter;
+ if (!$query = $db->Query($sql, PDO::FETCH_ASSOC))
+ echo "[]";
+ else
+ jsonOutput($query);
+ exit();
+ }
+?>
+
+<!DOCTYPE html>
+
+<?php
+ $pagetitle = "#bitcoin-otc gpg key data";
+ include("header.php");
?>
<div class="breadcrumbs">
@@ -37,11 +66,6 @@
<tr>
<?php
- try { $db = new PDO('sqlite:./otc/GPG.db'); }
- catch (PDOException $e) { die($e->getMessage()); }
-?>
-
-<?php
foreach ($validkeys as $key) $sortorders[$key] = array('order' => 'ASC', 'linktext' => str_replace("_", " ", $key));
if ($sortorder == 'ASC') $sortorders[$sortby]["order"] = 'DESC';
$sortorders["registered_at"]["othertext"] = "(UTC)";
@@ -51,14 +75,6 @@
?>
</tr>
<?php
- $queryfilter = array();
- if ($nickfilter != "") $queryfilter[] = "nick LIKE '" . sqlite_escape_string($nickfilter) . "'";
- if (sizeof($queryfilter) != 0) {
- $queryfilter = " WHERE " . join(' AND ', $queryfilter);
- }
- else {
- $queryfilter = "";
- }
$sql = 'SELECT * FROM users ' . $queryfilter . 'ORDER BY ' . sqlite_escape_string($sortby) . ' COLLATE NOCASE ' . sqlite_escape_string($sortorder);
if (!$query = $db->Query($sql))
echo "<tr><td>No users found</td></tr>\n";
View
26 OTCWebsite/viewratingdetail.php
@@ -1,5 +1,3 @@
-<!DOCTYPE html>
-
<?php
//error_reporting(-1); ini_set('display_errors', 1);
$sortby = isset($_GET["sortby"]) ? $_GET["sortby"] : "rating";
@@ -16,8 +14,30 @@
if (!in_array($type, $validvalues)) $type = "RECV";
$nick = isset($_GET["nick"]) ? $_GET["nick"] : "";
$nick = html_entity_decode($nick);
+ $outformat = isset($_GET["outformat"]) ? $_GET["outformat"] : "";
+ $outformat = html_entity_decode($outformat);
+?>
+<?php
+ try { $db = new PDO('sqlite:./otc/RatingSystem.db'); }
+ catch (PDOException $e) { die($e->getMessage()); }
+
+ include('querytojson.php');
+ if ($outformat == 'json'){
+ $signqueries = array('ANY' => ' ', 'POS' => ' AND ratings.rating > 0', 'NEG' => ' AND ratings.rating < 0');
+ $typequeries = array('RECV' => 'users2.nick LIKE ? AND users2.id = ratings.rated_user_id AND users.id = ratings.rater_user_id', 'SENT' => 'users.nick LIKE ? AND users.id = ratings.rater_user_id AND users2.id = ratings.rated_user_id');
+ $sql = "SELECT ratings.id as id, users.nick as rater_nick, users2.nick as rated_nick, ratings.created_at as created_at, ratings.rating as rating, ratings.notes as notes from users, users as users2, ratings WHERE " . $typequeries[$type] . $signqueries[$sign];
+ $sth = $db->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
+ $sth->setFetchMode(PDO::FETCH_ASSOC);
+ $sth->execute(array($nick));
+ if (!$sth) echo "[]";
+ else jsonOutput($sth);
+ exit();
+ }
+
?>
+<!DOCTYPE html>
+
<?php
$pagetitle = "Rating Details for User '" . htmlentities($nick) . "'";
include("header.php");
@@ -50,8 +70,6 @@
$typequeries = array('RECV' => 'users.id = ratings.rated_user_id', 'SENT' => 'users.id = ratings.rater_user_id');
$signqueries = array('ANY' => ' ', 'POS' => ' AND ratings.rating > 0', 'NEG' => ' AND ratings.rating < 0');
- try { $db = new PDO('sqlite:./otc/RatingSystem.db'); }
- catch (PDOException $e) { die($e->getMessage()); }
$sql = "SELECT count(*) as ratingcount, sum(rating) as ratingsum FROM users, ratings WHERE users.nick LIKE ? AND " . $typequeries[$type] . $signqueries[$sign];
$sth = $db->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY));
if (!$sth->execute(array($nick))) echo "<li>No positive ratings found</li>\n";

No commit comments for this range

Something went wrong with that request. Please try again.