renaming includes and views

This commit is contained in:
rootcoma 2013-12-04 21:16:40 -08:00
parent 4052eeaac3
commit 9594b8ae5f
22 changed files with 152 additions and 1618 deletions

View File

@ -3,4 +3,4 @@ require_once('includes/autoload.php');
$container->setTitle('About');
$container->setCurrentPage('about.php');
$container->render('about.php');
$container->render('about.html.php');

View File

@ -3,7 +3,6 @@ include 'config.php';
function autoloadIncludes($class) {
include 'config.php';
$class = lcfirst($class);
$filename = $class . ".php";
if(file_exists($config['libLocation'] . $filename)) {
require_once($config['libLocation'] . $filename);

View File

@ -1,57 +0,0 @@
<?php
class Bootstrap
{
public $storage;
public $config;
public $login;
public $title = '';
public $currentPage = '';
public function __construct($config) {
$this->config = $config;
$this->storage = new Storage($this->config['dbLocation']);
$this->login = new Login($this->storage);
}
public function render($page, $values=array()) {
$viewVars = array();
$viewVars['title'] = $this->title;
if($this->title != '') {
$viewVars['title'] .= ' &middot; ';
}
$viewVars['currentPage'] = $this->currentPage;
$container = $this;
include($this->config['viewLocation'] . 'header.php');
include($this->config['viewLocation'] . $page);
include($this->config['viewLocation'] . 'footer.php');
}
public function setTitle($title) {
$this->title = $title;
}
public function setCurrentPage($currentPage) {
$this->currentPage = $currentPage;
}
public function getTitle() {
return $this->title;
}
public function getCurrentPage() {
return $this->currentPage;
}
public function getLogin() {
return $this->login;
}
public function getStorage() {
return $this->storage;
}
public function getConfig() {
return $this->config;
}
}

View File

@ -1,107 +0,0 @@
<?php
class Login
{
protected $storage;
protected $loggedIn = false;
protected $user = null;
public function __construct($storage) {
$this->storage=$storage;
$this->startSession();
$this->checkLoggedIn();
}
protected function startSession() {
session_start();
}
protected function endSession() {
session_destroy();
}
protected function checkSessionLoggedIn() {
if(!isset($_SESSION['username']) || !isset($_SESSION['loggedIn']) || !isset($_SESSION['capability'])) {
return false;
}
if(!empty($_SESSION['username']) && $_SESSION['loggedIn']) {
return true;
}
return false;
}
protected function checkLoggedIn() {
$this->loggedIn = $this->checkSessionLoggedIn();
if($this->isLoggedIn()) {
$this->createUser($_SESSION['username'], $_SESSION['capability']);
}
}
protected function hashPassword($salt, $password) {
return sha1($salt . $password);
}
protected function createUser($username, $capabilities) {
$this->user = new User($username, $capabilities);
}
protected function ircToLower($str) {
$ircLowerSymbols = array("\\"=>"|", "["=>"{", "]"=>"}", "~"=>"^");
$str = strtr($str, $ircLowerSymbols);
$str = strtolower($str);
return $str;
}
public function isLoggedIn() {
return $this->loggedIn;
}
public function getUser() {
return $this->user;
}
public function login($username, $password) {
if($this->isLoggedIn()) {
return true;
}
$usernameCanonical = $this->ircToLower($username);
// Storage get salt, hashedPassword, capabilities for user
$results = $this->storage->getLoginByUsernameCanonical($usernameCanonical);
if(count($results) < 1) {
return false;
}
$result = $results[0];
$username = $result['username'];
$salt = $result['salt'];
$targetPassword = $result['password'];
$capability = $result['capability'];
$isHashed = $result['is_hashed'];
$hashPassword = $password;
if($isHashed) {
$hashPassword = $this->hashPassword($salt, $password);
}
if($targetPassword == $hashPassword) {
$_SESSION['username'] = $username;
$_SESSION['loggedIn'] = true;
$_SESSION['capability'] = $capability;
$this->loggedIn = true;
$this->createUser($username, $capability);
return true;
}
return false;
}
public function logout() {
$_SESSION = array();
$this->endSession();
$this->loggedIn = false;
$this->user = null;
}
}

View File

@ -1,156 +0,0 @@
<?php
class Paginator
{
protected $key = 'page';
protected $target = '';
protected $next = '&raquo;';
protected $previous = '&laquo;';
protected $crumbs = 5;
protected $resultsPerPage = 10;
protected $currentPage;
protected $totalResults;
public function __construct($currentPage, $totalResults, $resultsPerPage=null, $key=null, $target=null) {
$this->currentPage = $currentPage;
$this->totalResults = $totalResults;
if(!is_null($key)) {
$this->key = $key;
}
if(!is_null($resultsPerPage)) {
$this->resultsPerPage = $resultsPerPage;
}
if(!is_null($target)) {
$this->target = $target;
} else {
$this->target = $this->getCurrentURI();
}
}
protected function getCurrentURI() {
return $_SERVER['REQUEST_URI'];
}
protected function replacePageVariable($uri, $pageNumber) {
$pathInfo = parse_url($uri);
if(array_key_exists('query', $pathInfo)) {
$queryString = $pathInfo['query'];
} else {
$queryString = '';
}
parse_str($queryString, $queryArray);
$queryArray[$this->key] = $pageNumber;
if($pageNumber == 1) {
unset($queryArray[$this->key]);
}
$queryString = http_build_query($queryArray);
$new = $pathInfo['path'];
if($queryString != ''){
$new .= '?' . $queryString;
}
return $new;
}
protected function getMaxPages() {
if($this->totalResults==0) {
return 1;
}
$max = intval($this->totalResults / $this->resultsPerPage);
if($this->totalResults % $this->resultsPerPage > 0) {
$max++;
}
return intval($max);
}
public function paginate() {
echo '<div class="pagination"><ul>';
$startCrumb = $this->currentPage - ($this->crumbs-1)/2;
if($startCrumb < 1) {
$startCrumb = 1;
}
$endCrumb = $startCrumb + $this->crumbs-1;
if($endCrumb > $this->getMaxPages()) {
$endCrumb = $this->getMaxPages();
}
while($endCrumb - $startCrumb < $this->crumbs - 1) {
if($startCrumb <= 1) {
break;
}
$startCrumb--;
}
$startDots = false;
if($startCrumb > 1) {
$startDots = true;
}
$endDots = false;
if($endCrumb < $this->getMaxPages()) {
$endDots = true;
}
if($this->currentPage > 1) {
echo '<li>';
echo '<a href="';
if($this->currentPage > $this->getMaxPages()) {
echo $this->replacePageVariable($this->target, $this->getMaxPages());
} else {
echo $this->replacePageVariable($this->target, $this->currentPage-1);
}
echo '">';
} else {
echo '<li class="disabled"><span>';
}
echo $this->previous;
if($this->currentPage > 1) {
echo '</a></li>';
} else {
echo '</span></li>';
}
if($startDots){
echo '<li class="disabled"><span>...</span></li>';
}
for($i=$startCrumb;$i<=$endCrumb;$i++) {
if($i!=$this->currentPage){
echo '<li>';
echo '<a href="';
echo $this->replacePageVariable($this->target, $i);
echo '">';
} else {
echo '<li class="active"><span>';
}
echo $i;
if($i!=$this->currentPage){
echo '</a></li>';
} else {
echo '</span></li>';
}
}
if($endDots){
echo '<li class="disabled"><span>...</span></li>';
}
if($this->currentPage < $this->getMaxPages()) {
echo '<li>';
echo '<a href="';
if($this->currentPage < 1) {
echo $this->replacePageVariable($this->target, 1);
} else {
echo $this->replacePageVariable($this->target, $this->currentPage+1);
}
echo '">';
} else {
echo '<li class="disabled"><span>';
}
echo $this->next;
if($this->currentPage < $this->getMaxPages()) {
echo '</a></li>';
} else {
echo '</span></li>';
}
echo '</ul></div>';
}
}

View File

@ -1,492 +0,0 @@
<?php
class Storage
{
protected $dbLocation;
protected $dbType;
protected $db = null;
public function __construct($dbLocation, $dbType='sqlite:') {
$this->dbLocation = $dbLocation;
$this->dbType = $dbType;
$this->connect();
}
public function connect() {
if(is_null($this->db)) {
try {
$this->db = new PDO($this->dbType . $this->dbLocation);
if(!$this->db) {
$this->db = null;
throw new StorageConnectionException();
}
} catch (Exception $e) {
$this->db = null;
}
}
}
public function close() {
$this->db = null;
}
protected function ircToLower($str) {
$ircLowerSymbols = array("\\"=>"|", "["=>"{", "]"=>"}", "~"=>"^");
$str = strtr($str, $ircLowerSymbols);
$str = strtolower($str);
return $str;
}
public function getLoginByUsernameCanonical($usernameCanonical) {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
$q = $this->db->prepare('SELECT *
FROM trivialogin
WHERE username_canonical=:username
LIMIT 1');
if ($q === false) {
throw new StorageSchemaException();
}
$q->execute(array(':username'=>$usernameCanonical));
$result = $q->fetchAll();
return $result;
}
public function getTimeSinceLastPlayed($usernameCanonical) {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
$q = $this->db->prepare('SELECT last_updated
FROM triviauserlog
WHERE username_canonical=:username
ORDER BY last_updated DESC
LIMIT 1');
if ($q === false) {
throw new StorageSchemaException();
}
$q->execute(array(':username'=>$usernameCanonical));
$result = $q->fetchAll();
return $result;
}
public function getTopDeletions($page, $max) {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
if($page < 1) {
$page = 1;
}
if($max < 1) {
$max = 1;
}
$q = $this->db->prepare('SELECT td.*, tq.question as question
FROM triviadelete td
INNER JOIN triviaquestion tq
ON tq.id=td.line_num
ORDER BY id DESC LIMIT :offset, :maxResults');
if ($q === false) {
throw new StorageSchemaException();
}
$q->execute(array(':offset'=>($page-1) * $max, ':maxResults'=>$max));
$result = $q->fetchAll();
return $result;
}
public function getCountDeletions() {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
$q = $this->db->query('SELECT count(id) FROM triviadelete');
if ($q === false) {
throw new StorageSchemaException();
}
$result = $q->fetchColumn();
return $result;
}
public function getTopReports($page, $max) {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
if($page < 1) {
$page = 1;
}
if($max < 1) {
$max = 1;
}
$q = $this->db->prepare('SELECT tr.*, tq.question as original
FROM triviareport tr
INNER JOIN triviaquestion tq
ON tq.id=question_num
ORDER BY id DESC LIMIT :offset, :maxResults');
if ($q === false) {
throw new StorageSchemaException();
}
$q->execute(array(':offset'=>($page-1) * $max, ':maxResults'=>$max));
$result = $q->fetchAll();
return $result;
}
public function getCountReports() {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
$q = $this->db->query('SELECT count(id) FROM triviareport');
if ($q === false) {
throw new StorageSchemaException();
}
$result = $q->fetchColumn();
return $result;
}
public function getTopNewQuestions($page, $max) {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
if($page < 1) {
$page = 1;
}
if($max < 1) {
$max = 1;
}
$q = $this->db->prepare('SELECT tq.* FROM triviatemporaryquestion tq ORDER BY tq.id DESC LIMIT :offset, :maxResults');
if ($q === false) {
throw new StorageSchemaException();
}
$q->execute(array(':offset'=>($page-1) * $max, ':maxResults'=>$max));
$result = $q->fetchAll();
return $result;
}
public function getCountNewQuestions() {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
$q = $this->db->query('SELECT count(id) FROM triviatemporaryquestion');
if ($q === false) {
throw new StorageSchemaException();
}
$result = $q->fetchColumn();
return $result;
}
public function getTopEdits($page, $max) {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
if($page < 1) {
$page = 1;
}
if($max < 1) {
$max = 1;
}
$q = $this->db->prepare('SELECT te.*, tq.question as original
FROM triviaedit te
INNER JOIN triviaquestion tq
ON tq.id=question_id
ORDER BY id DESC LIMIT :offset, :maxResults');
if ($q === false) {
throw new StorageSchemaException();
}
$q->execute(array(':offset'=>($page-1) * $max, ':maxResults'=>$max));
$result = $q->fetchAll();
return $result;
}
public function getCountEdits() {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
$q = $this->db->query('SELECT count(id) FROM triviaedit');
if ($q === false) {
throw new StorageSchemaException();
}
$result = $q->fetchColumn();
return $result;
}
public function getDayTopScores($page=1, $max=10) {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
if($page < 1) {
$page = 1;
}
if($max < 1) {
$max = 1;
}
$day = date('j');
$month = date('m');
$year = date('Y');
$q = $this->db->prepare("SELECT username,
sum(points_made) as points
FROM triviauserlog
WHERE day=:day
AND year=:year
AND month=:month
GROUP BY username_canonical
ORDER BY points DESC
LIMIT :offset, :maxResults");
if ($q === false) {
throw new StorageSchemaException();
}
$q->execute(array(':offset'=>($page-1) * $max, ':maxResults'=>$max, ':day'=>$day, ':year'=>$year, ':month'=>$month));
$result = $q->fetchAll();
return $result;
}
public function getCountDayTopScores() {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
$day = date('j');
$month = date('m');
$year = date('Y');
$q = $this->db->prepare('SELECT count(distinct(username_canonical))
FROM triviauserlog
WHERE day=:day
AND year=:year
AND month=:month');
if ($q === false) {
throw new StorageSchemaException();
}
$q->execute(array(':day'=>$day, ':year'=>$year, ':month'=>$month));
$result = $q->fetchColumn();
return $result;
}
protected function generateWeekSqlClause() {
$sqlClause = '';
$day = date('N')-1;
$week = new DateTime();
$interval = new DateInterval('P'.$day.'D');
$week->sub($interval);
$interval = new DateInterval('P1D');
for($i=0;$i<7;$i++) {
if($i>0) {
$sqlClause .= ' or ';
}
$sqlClause .= '(day=' . $week->format('j') .
' and month=' . $week->format('n') .
' and year=' . $week->format('Y') .
')';
$week->add($interval);
}
return $sqlClause;
}
public function getWeekTopScores($page=1, $max=10) {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
if($page < 1) {
$page = 1;
}
if($max < 1) {
$max = 1;
}
$sqlClause = $this->generateWeekSqlClause();
$q = $this->db->prepare("SELECT username, sum(points_made) as points FROM triviauserlog WHERE $sqlClause GROUP BY username_canonical ORDER BY points DESC LIMIT :offset, :maxResults");
if ($q === false) {
throw new StorageSchemaException();
}
$q->execute(array(':offset'=>($page-1) * $max, ':maxResults'=>$max));
$result = $q->fetchAll();
return $result;
}
public function getCountWeekTopScores() {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
$sqlClause = $this->generateWeekSqlClause();
$q = $this->db->query('SELECT count(distinct(username_canonical))
FROM triviauserlog
WHERE $sqlClause');
if ($q === false) {
throw new StorageSchemaException();
}
$result = $q->fetchColumn();
return $result;
}
public function getMonthTopScores($page=1, $max=10) {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
if($page < 1) {
$page = 1;
}
if($max < 1) {
$max = 1;
}
$month = date('m');
$year = date('Y');
$q = $this->db->prepare("SELECT username, sum(points_made) as points FROM triviauserlog WHERE year=:year AND month=:month GROUP BY username_canonical ORDER BY points DESC LIMIT :offset, :maxResults");
if ($q === false) {
throw new StorageSchemaException();
}
$q->execute(array(':offset'=>($page-1) * $max, ':maxResults'=>$max, ':year'=>$year, ':month'=>$month));
$result = $q->fetchAll();
return $result;
}
public function getCountMonthTopScores() {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
$month = date('m');
$year = date('Y');
$q = $this->db->prepare('SELECT count(distinct(username_canonical))
FROM triviauserlog
WHERE year=:year
AND month=:month');
if ($q === false) {
throw new StorageSchemaException();
}
$q->execute(array(':year'=>$year, ':month'=>$month));
$result = $q->fetchColumn();
return $result;
}
public function getYearTopScores($page=1, $max=10) {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
if($page < 1) {
$page = 1;
}
if($max < 1) {
$max = 1;
}
$year = date('Y');
$q = $this->db->prepare("SELECT username, sum(points_made) as points FROM triviauserlog WHERE year=:year GROUP BY username_canonical ORDER BY points DESC LIMIT :offset, :maxResults");
if ($q === false) {
throw new StorageSchemaException();
}
$q->execute(array(':offset'=>($page-1) * $max, ':maxResults'=>$max, ':year'=>$year));
$result = $q->fetchAll();
return $result;
}
public function getCountYearTopScores() {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
$year = date('Y');
$q = $this->db->prepare('SELECT count(distinct(username_canonical))
FROM triviauserlog
WHERE year=:year');
if ($q === false) {
throw new StorageSchemaException();
}
$q->execute(array(':year'=>$year));
$result = $q->fetchColumn();
return $result;
}
public function getUserLikeUsernameCanonical($usernameCanonical, $page, $max) {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
if($page < 1) {
$page = 1;
}
if($max < 1) {
$max = 1;
}
$q = $this->db->prepare('select
tl.username,
sum(tl.points_made) as points,
sum(tl.num_answered) as total
from triviauserlog tl
where tl.username_canonical like :username
group by tl.username_canonical
limit :offset, :maxResults
');
if ($q === false) {
throw new StorageSchemaException();
}
$likeString = '%'.$this->escapeLikeQuery($usernameCanonical).'%';
$q->execute(array(':offset'=>($page-1) * $max, ':maxResults'=>$max, ':username'=>$likeString));
$result = $q->fetchAll();
return $result;
}
public function getCountUserLikeUsernameCanonical($usernameCanonical) {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
$q = $this->db->prepare('select
count(distinct(tl.username_canonical))
from triviauserlog tl
where tl.username_canonical like :username
');
if ($q === false) {
throw new StorageSchemaException();
}
$likeString = '%'.$this->escapeLikeQuery($usernameCanonical).'%';
$q->execute(array(':username'=>$likeString));
$result = $q->fetchColumn();
return $result;
}
public function getRecentAskedQuestions() {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
$q = $this->db->query('SELECT asked_at, channel, round_num, question, line_num FROM triviagameslog ORDER BY id DESC LIMIT 10');
if ($q === false) {
throw new StorageSchemaException();
}
$result = $q->fetchAll();
return $result;
}
public function getUserProfileInformation($usernameCanonical) {
if(!$this->isConnected()) {
throw new StorageConnectionException();
}
$q = $this->db->prepare('select
tl.username as usrname,
sum(tl2.t * (tl2.n / (select sum(num_answered) from triviauserlog where username_canonical=:username))) as count,
sum(tl2.p * (tl2.n / (select sum(num_answered) from triviauserlog where username_canonical=:username))) as score,
(select sum(points_made) from triviauserlog t3 where username_canonical=:username) as points,
(select sum(num_answered) from triviauserlog t4 where username_canonical=:username) as q_asked,
(select num_editted from triviausers where username_canonical=:username) as num_e,
(select num_editted_accepted from triviausers where username_canonical=:username) as num_e_accepted,
(select num_questions_added from triviausers where username_canonical=:username) as num_q,
(select num_questions_accepted from triviausers where username_canonical=:username) as num_q_accepted,
(select num_reported from triviausers where username_canonical=:username) as num_r,
(select highest_streak from triviausers where username_canonical=:username) as highest_streak
from (select tl3.id as id2, tl3.average_time * 1.0 as t, tl3.average_score * 1.0 as p, tl3.num_answered * 1.0 as n from triviauserlog tl3) tl2
inner join triviauserlog tl
on tl.username_canonical=:username
and tl.id=tl2.id2
limit 1');
if ($q === false) {
throw new StorageSchemaException();
}
$q->execute(array(':username'=>$usernameCanonical));
$result = $q->fetchAll();
return $result;
}
public function isConnected() {
if(is_null($this->db)) {
return false;
}
return true;
}
protected function escapeLikeQuery($s) {
$translations = array("%"=>"\\%", "_"=>"\\_");
return strtr($s, $translations);
}
}
class StorageException extends Exception { }
class StorageSchemaException extends StorageException { }
class StorageConnectionException extends StorageException { }

View File

@ -1,19 +0,0 @@
<?php
class User
{
protected $username;
protected $capabilty;
public function __construct($username, $capabilty) {
$this->username = $username;
$this->capabilty = $capabilty;
}
public function getUsername() {
return $this->username;
}
public function getCapability() {
return $this->capabilty;
}
}

View File

@ -21,4 +21,4 @@ $values['errors'] = $errors;
$container->setTitle('Home');
$container->setCurrentPage('index.php');
$container->render('home.php', $values);
$container->render('home.html.php', $values);

View File

@ -120,4 +120,4 @@ $values['lastSeen'] = $lastSeen;
$container->setTitle($username);
$container->setCurrentPage('profile.php');
$container->render('profile.php', $values);
$container->render('profile.html.php', $values);

View File

@ -1,7 +1,100 @@
<?php
require_once('includes/autoload.php');
$storage = $container->getStorage();
function getPageVariable($name) {
if(array_key_exists($name, $_GET)) {
$page = $_GET[$name];
}
if(!isset($page)) {
$page = 1;
}
if($page < 1) {
$page = 1;
}
return $page;
}
$reportPage = getPageVariable('rp');
$editPage = getPageVariable('ep');
$newPage = getPageVariable('np');
$deletePage = getPageVariable('dp');
$maxResults = 5;
$reportResultCount = 0;
$reportResult = array();
$reportErrors = array();
try {
$reportResult = $storage->getTopReports($reportPage, $maxResults);
$reportResultCount = $storage->getCountReports();
} catch(StorageSchemaException $e) {
$reportErrors[] = "Error: Database schema is not queryable";
} catch(StorageConnectionException $e) {
$reportErrors[] = "Error: Database is not available";
}
$editResultCount = 0;
$editResult = array();
$editErrors = array();
try {
$editResult = $storage->getTopEdits($editPage, $maxResults);
$editResultCount = $storage->getCountEdits();
} catch(StorageSchemaException $e) {
$editErrors[] = "Error: Database schema is not queryable";
} catch(StorageConnectionException $e) {
$editErrors[] = "Error: Database is not available";
}
$newResultCount = 0;
$newResult = array();
$newErrors = array();
try {
$newResult = $storage->getTopNewQuestions($newPage, $maxResults);
$newResultCount = $storage->getCountNewQuestions();
} catch(StorageSchemaException $e) {
$newErrors[] = "Error: Database schema is not queryable";
} catch(StorageConnectionException $e) {
$newErrors[] = "Error: Database is not available";
}
$deleteResultCount = 0;
$deleteResult = array();
$deleteErrors = array();
try {
$deleteResult = $storage->getTopDeletions($deletePage, $maxResults);
$deleteResultCount = $storage->getCountDeletions();
} catch(StorageSchemaException $e) {
$deleteErrors[] = "Error: Database schema is not queryable";
} catch(StorageConnectionException $e) {
$deleteErrors[] = "Error: Database is not available";
}
$values = array();
$values['maxResults'] = $maxResults;
$values['reportResultCount'] = $reportResultCount;
$values['reportResult'] = $reportResult;
$values['reportErrors'] = $reportErrors;
$values['reportPage'] = $reportPage;
$values['editResultCount'] = $editResultCount;
$values['editResult'] = $editResult;
$values['editErrors'] = $editErrors;
$values['editPage'] = $editPage;
$values['newResultCount'] = $newResultCount;
$values['newResult'] = $newResult;
$values['newErrors'] = $newErrors;
$values['newPage'] = $newPage;
$values['deleteResultCount'] = $deleteResultCount;
$values['deleteResult'] = $deleteResult;
$values['deleteErrors'] = $deleteErrors;
$values['deletePage'] = $deletePage;
$container->setTitle('Reports');
$container->setCurrentPage('reports.php');
$container->render('reports.php');
$container->render('reports.html.php', $values);

View File

@ -1,7 +1,59 @@
<?php
require_once('includes/autoload.php');
$storage = $container->getStorage();
$dayResult = array();
$dayErrors = array();
try {
$dayResult = $storage->getDayTopScores(1, 10);
} catch(StorageSchemaException $e) {
$dayErrors[] = "Error: Database schema is not queryable";
} catch(StorageConnectionException $e) {
$dayErrors[] = "Error: Database is not available";
}
$weekResult = array();
$weekErrors = array();
try {
$weekResult = $storage->getWeekTopScores(1, 10);
} catch(StorageSchemaException $e) {
$weekErrors[] = "Error: Database schema is not queryable";
} catch(StorageConnectionException $e) {
$weekErrors[] = "Error: Database is not available";
}
$monthResult = array();
$monthErrors = array();
try {
$monthResult = $storage->getMonthTopScores(1, 10);
} catch(StorageSchemaException $e) {
$monthErrors[] = "Error: Database schema is not queryable";
} catch(StorageConnectionException $e) {
$monthErrors[] = "Error: Database is not available";
}
$yearResult = array();
$yearErrors = array();
try {
$yearResult = $storage->getYearTopScores(1, 10);
} catch(StorageSchemaException $e) {
$yearErrors[] = "Error: Database schema is not queryable";
} catch(StorageConnectionException $e) {
$yearErrors[] = "Error: Database is not available";
}
$values = array();
$values['dayResult'] = $dayResult;
$values['dayErrors'] = $dayErrors;
$values['weekResult'] = $weekResult;
$values['weekErrors'] = $weekErrors;
$values['monthResult'] = $monthResult;
$values['monthErrors'] = $monthErrors;
$values['yearResult'] = $yearResult;
$values['yearErrors'] = $yearErrors;
$container->setTitle('Stats');
$container->setCurrentPage('stats.php');
$container->render('stats.php');
$container->render('stats.html.php', $values);

View File

@ -60,4 +60,4 @@ $values['errors'] = $errors;
$container->setTitle('Top Scores for ' . $timeDesc);
$container->setCurrentPage('top.php');
$container->render('top.php', $values);
$container->render('top.html.php', $values);

View File

@ -57,4 +57,4 @@ $values['errors'] = $errors;
$container->setTitle('Players');
$container->setCurrentPage('user.php');
$container->render('user.php', $values);
$container->render('user.html.php', $values);

View File

@ -1,17 +0,0 @@
<div class="hero-unit">
<h1>About TriviaTime</h1>
<p>We are <a href="irc://irc.freenode.net/#trivialand">#trivialand</a> on Freenode. Come join us!</p>
</div>
<div class="row">
<div class="span12">
<h2>About</h2>
<p>TriviaTime is a feature-packed trivia plugin developed by the Trivialand channel on Freenode, written in Python for <a href="https://github.com/jamessan/Supybot">Supybot</a> with a built-in website generator. Be the first to answer the question to score points. On KAOS, it's a team effort to get all the answers before the time runs out. As you play you'll earn badges and level up.</p>
</div>
</div>
<div class="row">
<div class="span12">
<h2>Source</h2>
<p>The source code is available on <a target="_blank" href="https://github.com/tannn/TriviaTime">GitHub</a>, be sure to check it out.
Fork us and contribute!</p>
</div>
</div>

View File

@ -1,12 +0,0 @@
<div class="footer">
<p>&copy; Trivialand 2013 - <a target="_blank" href="https://github.com/tannn/TriviaTime">GitHub</a></p>
</div>
</div> <!-- /container -->
<script src="http://codeorigin.jquery.com/jquery-2.0.3.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/triviatime.js"></script>
</body>
</html>

View File

@ -1,38 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title><?php echo $viewVars['title']; ?>TriviaTime</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link href="css/bootstrap.css" rel="stylesheet">
<link href="css/triviatime.css" rel="stylesheet">
<link href="css/bootstrap-responsive.css" rel="stylesheet">
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<button class="btn btn-navbar collapsed" data-toggle="collapse" data-target=".nav-collapse" type="button">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a href="index.php" class="brand">TriviaTime</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li<?php if($viewVars['currentPage']=='index.php') { echo ' class="active"'; } ?>><a href="index.php">Home</a></li>
<li<?php if($viewVars['currentPage']=='stats.php') { echo ' class="active"'; } ?>><a href="stats.php">Stats</a></li>
<li<?php if($viewVars['currentPage']=='user.php') { echo ' class="active"'; } ?>><a href="user.php">Players</a></li>
<li<?php if($viewVars['currentPage']=='reports.php') { echo ' class="active"'; } ?>><a href="reports.php">Reports</a></li>
<li<?php if($viewVars['currentPage']=='about.php') { echo ' class="active"'; } ?>><a href="about.php">About</a></li>
</ul>
</div>
</div>
</div>
</div><!-- /.navbar -->
<div class="container">

View File

@ -1,36 +0,0 @@
<div class="hero-unit">
<h1>Home</h1>
<p>Get the latest stats for players and updates.</p>
</div>
<div class="row">
<div class="span12">
<h2>Latest questions asked</h2>
<?php
foreach($values['errors'] as $error) {
echo "<div class='alert alert-error'>$error</div>";
}
?>
<table class="table modal-table">
<thead>
<tr>
<th>Round #</th>
<th>Channel</th>
<th>Question</th>
<th>Question #</th>
</tr>
</thead>
<tbody>
<?php
foreach($values['result'] as $res) {
echo '<tr>';
echo '<td>' . $res['round_num'] . '</td>';
echo '<td>' . $res['channel'] . '</td>';
echo '<td class="breakable">' . $res['question'] . '</td>';
echo '<td>' . $res['line_num'] . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
</div>

View File

@ -1,124 +0,0 @@
<?php
$userProfile = $values['userProfile'];
$errors = $values['errors'];
$username = $values['username'];
$usernameCanonical = $values['usernameCanonical'];
$lastSeen = $values['lastSeen'];
?>
<div class="row profile-header">
<div class="span12">
<h1><?php echo $userProfile['usrname']; ?></h1>
<p>Profile and stats.</p>
</div>
</div>
<?php
if(count($errors) > 0) {
echo '<div class="row">
<div class="span12">';
foreach($errors as $error) {
echo "<div class='alert alert-error'>$error</div>";
}
echo ' </div>
</div>
';
}
?>
<div class="row">
<div class="span6">
<h2>Last seen</h2>
<p>
<?php
if($userProfile['usrname'] != 'Not found') {
echo $lastSeen;
}
?>
</p>
</div>
<div span="span6">
<h2>Highest Streak</h2>
<p>
<?php
if($userProfile['usrname'] != 'Not found') {
echo number_format($userProfile['highest_streak'],0);
}
?>
</p>
</div>
</div>
<div class="row">
<div class="span6">
<h2>Averages</h2>
<table class="table">
<thead>
<tr>
<th>Average Time/Question*</th>
<th>Average Points/Question*</th>
</tr>
</thead>
<tbody>
<?php
if($userProfile['usrname'] != 'Not found') {
echo '<tr>';
echo '<td>' . number_format($userProfile['count'],2) . '</td>';
echo '<td>' . number_format($userProfile['score'],2) . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
<div class="span6">
<h2>Totals</h2>
<table class="table">
<thead>
<tr>
<th>Total Points</th>
<th>Number Answered*</th>
</tr>
</thead>
<tbody>
<?php
if($userProfile['usrname'] != 'Not found') {
echo '<tr>';
echo '<td>' . number_format($userProfile['points'],0) . '</td>';
echo '<td>' . number_format($userProfile['q_asked'],0) . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="span12">
<h2>Contributions</h2>
<table class="table">
<thead>
<tr>
<th>Reports Made</th>
<th>Edits (Made/Accepted)</th>
<th>Questions (Made/Accepted)</th>
</tr>
</thead>
<tbody>
<?php
if($userProfile['usrname'] != 'Not found') {
echo '<tr>';
echo '<td>' . number_format($userProfile['num_r'],0) . '</td>';
echo '<td>' . number_format($userProfile['num_e'],0) . '/' . number_format($userProfile['num_e_accepted'],0) . '</td>';
echo '<td>' . number_format($userProfile['num_q'],0) . '/' . number_format($userProfile['num_q_accepted'],0) . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="span12">
<p>* These stats do not include KAOS</p>
</div>
</div>

View File

@ -1,271 +0,0 @@
<?php
$storage = $container->getStorage();
if(array_key_exists('rp', $_GET)) {
$reportPage = $_GET['rp'];
}
if(!isset($reportPage)) {
$reportPage = 1;
}
if($reportPage < 1) {
$reportPage = 1;
}
if(array_key_exists('ep', $_GET)) {
$editPage = $_GET['ep'];
}
if(!isset($editPage)) {
$editPage = 1;
}
if($editPage < 1) {
$editPage = 1;
}
if(array_key_exists('np', $_GET)) {
$newPage = $_GET['np'];
}
if(!isset($newPage)) {
$newPage = 1;
}
if($newPage < 1) {
$newPage = 1;
}
if(array_key_exists('dp', $_GET)) {
$deletePage = $_GET['dp'];
}
if(!isset($deletePage)) {
$deletePage = 1;
}
if($deletePage < 1) {
$deletePage = 1;
}
$maxResults = 5;
?>
<div class="hero-unit">
<h1>Reports</h1>
<p>The reports and edits that are currently pending.</p>
<p>
</p>
</div>
<div class="row">
<div class="span12">
<h2>Reports</h2>
<?php
$resultCount = 0;
$result = array();
try {
$result = $storage->getTopReports($reportPage, $maxResults);
$resultCount = $storage->getCountReports();
} catch(StorageSchemaException $e) {
echo "<div class='alert alert-error'>Error: Database schema is not queryable</div>";
} catch(StorageConnectionException $e) {
echo "<div class='alert alert-error'>Error: Database is not available</div>";
}
?>
<table class="table modal-table">
<thead>
<tr>
<th>Report #</th>
<th class="hidden-phone">Username</th>
<th>Question #</th>
<th>Question</th>
<th>Report Text</th>
</tr>
</thead>
<tbody>
<?php
foreach($result as $res) {
echo '<tr>';
echo '<td>' . $res['id'] . '</td>';
echo '<td class="hidden-phone">' . $res['username'] . '</td>';
echo '<td>' . $res['question_num'] . '</td>';
echo '<td class="breakable">' . $res['original'] . '</td>';
echo '<td class="breakable">' . $res['report_text'] . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<?php
$pagination = new Paginator($reportPage, $resultCount, $maxResults, 'rp');
$pagination->paginate();
?>
</div>
</div>
<div class="row">
<div class="span12">
<h2>Edits</h2>
<?php
$resultCount = 0;
$result = array();
try {
$result = $storage->getTopEdits($editPage, $maxResults);
$resultCount = $storage->getCountEdits();
} catch(StorageSchemaException $e) {
echo "<div class='alert alert-error'>Error: Database schema is not queryable</div>";
} catch(StorageConnectionException $e) {
echo "<div class='alert alert-error'>Error: Database is not available</div>";
}
?>
<table class="table modal-table">
<thead>
<tr>
<th>Edit #</th>
<th class="hidden-phone">Username</th>
<th>New Question</th>
<th>Old Question</th>
<th>Question #</th>
</tr>
</thead>
<tbody>
<?php
foreach($result as $res) {
$isItalic = false;
$splitNew = explode('*', $res['question']);
$splitOld = explode('*', $res['original']);
$differenceString = '';
for($y=0;$y<sizeof($splitNew);$y++){
if($y>0) {
$isItalic = false;
$differenceString .= '</u>';
$differenceString .= '*';
}
$brokenNew = str_split($splitNew[$y]);
if(!array_key_exists($y, $splitOld)){
$splitOld[$y] = '*';
}
$brokenOld = str_split($splitOld[$y]);
for($i=0;$i<sizeof($brokenNew);$i++) {
if(!array_key_exists($i, $brokenOld)||!array_key_exists($i, $brokenNew)) {
if($isItalic==false){
$isItalic = true;
$differenceString .= '<u>';
}
} else if($brokenNew[$i]=='*') {
$isItalic = false;
$differenceString .= '</u>';
} else if($brokenNew[$i]!=$brokenOld[$i]) {
if($isItalic==false){
$isItalic = true;
$differenceString .= '<u>';
}
} else if($brokenNew[$i]==$brokenOld[$i]&&$isItalic==true) {
$isItalic = false;
$differenceString .= '</u>';
}
$differenceString.=$brokenNew[$i];
}
}
if($isItalic==true) {
$differenceString .= '</u>';
}
echo '<tr>';
echo '<td>' . $res['id'] . '</td>';
echo '<td class="hidden-phone">' . $res['username'] . '</td>';
echo '<td class="breakable">' . $differenceString . '</td>';
echo '<td class="breakable">' . $res['original'] . '</td>';
echo '<td>' . $res['question_id'] . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<?php
$pagination = new Paginator($editPage, $resultCount, $maxResults, 'ep');
$pagination->paginate();
?>
</div>
</div>
<div class="row">
<div class="span12">
<h2>Added Questions</h2>
<?php
$resultCount = 0;
$result = array();
try {
$result = $storage->getTopNewQuestions($newPage, $maxResults);
$resultCount = $storage->getCountNewQuestions();
} catch(StorageSchemaException $e) {
echo "<div class='alert alert-error'>Error: Database schema is not queryable</div>";
} catch(StorageConnectionException $e) {
echo "<div class='alert alert-error'>Error: Database is not available</div>";
}
?>
<table class="table modal-table">
<thead>
<tr>
<th>#</th>
<th>Author</th>
<th>New Question</th>
</tr>
</thead>
<tbody>
<?php
foreach($result as $res) {
echo '<tr>';
echo '<td>' . $res['id'] . '</td>';
echo '<td>' . $res['username'] . '</td>';
echo '<td class="breakable">' . $res['question'] . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<?php
$pagination = new Paginator($newPage, $resultCount, $maxResults, 'np');
$pagination->paginate();
?>
</div>
</div>
<div class="row">
<div class="span12">
<h2>Pending Deletions</h2>
<?php
$resultCount = 0;
$result = array();
try {
$result = $storage->getTopDeletions($deletePage, $maxResults);
$resultCount = $storage->getCountDeletions();
} catch(StorageSchemaException $e) {
echo "<div class='alert alert-error'>Error: Database schema is not queryable</div>";
} catch(StorageConnectionException $e) {
echo "<div class='alert alert-error'>Error: Database is not available</div>";
}
?>
<table class="table modal-table">
<thead>
<tr>
<th>#</th>
<th class="hidden-phone">Username</th>
<th>New Question</th>
<th>Question #</th>
</tr>
</thead>
<tbody>
<?php
foreach($result as $res) {
echo '<tr>';
echo '<td>' . $res['id'] . '</td>';
echo '<td class="hidden-phone">' . $res['username'] . '</td>';
echo '<td class="breakable">' . $res['question'] . '</td>';
echo '<td>' . $res['line_num'] . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<?php
$pagination = new Paginator($deletePage, $resultCount, $maxResults, 'dp');
$pagination->paginate();
?>
</div>
</div>

View File

@ -1,152 +0,0 @@
<?php
$storage = $container->getStorage();
?>
<div class="hero-unit">
<h1>Stats</h1>
<p>Stats are updated continuously and instantly.</p>
<p>
</p>
</div>
<div class="row">
<div class="span6">
<h2>Todays Top Scores</h2>
<?php
$result = array();
try {
$result = $storage->getDayTopScores(1, 10);
} catch(StorageSchemaException $e) {
echo "<div class='alert alert-error'>Error: Database schema is not queryable</div>";
} catch(StorageConnectionException $e) {
echo "<div class='alert alert-error'>Error: Database is not available</div>";
}
?>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Username</th>
<th>Points</th>
</tr>
</thead>
<tbody>
<?php
foreach($result as $key=>$res) {
echo '<tr>';
echo '<td>' . ($key+1) . '</td>';
echo '<td><a href="profile.php?username=' . rawurlencode($res['username']) . '">' . $res['username'] . '</a></td>';
echo '<td>' . number_format($res['points'],0) . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<p><a class="btn btn-info btn-block" href="top.php">View all</a></p>
</div>
<div class="span6">
<h2>Week Top Scores</h2>
<?php
$result = array();
try {
$result = $storage->getWeekTopScores(1, 10);
} catch(StorageSchemaException $e) {
echo "<div class='alert alert-error'>Error: Database schema is not queryable</div>";
} catch(StorageConnectionException $e) {
echo "<div class='alert alert-error'>Error: Database is not available</div>";
}
?>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Username</th>
<th>Points</th>
</tr>
</thead>
<tbody>
<?php
foreach($result as $key=>$res) {
echo '<tr>';
echo '<td>' . ($key+1) . '</td>';
echo '<td><a href="profile.php?username=' . rawurlencode($res['username']) . '">' . $res['username'] . '</a></td>';
echo '<td>' . number_format($res['points'],0) . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<p><a class="btn btn-info btn-block" href="top.php?t=w">View all</a></p>
</div>
</div>
<div class="row">
<div class="span6">
<h2>Month Top Scores</h2>
<?php
$result = array();
try {
$result = $storage->getMonthTopScores(1, 10);
} catch(StorageSchemaException $e) {
echo "<div class='alert alert-error'>Error: Database schema is not queryable</div>";
} catch(StorageConnectionException $e) {
echo "<div class='alert alert-error'>Error: Database is not available</div>";
}
?>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Username</th>
<th>Points</th>
</tr>
</thead>
<tbody>
<?php
foreach($result as $key=>$res) {
echo '<tr>';
echo '<td>' . ($key+1) . '</td>';
echo '<td><a href="profile.php?username=' . rawurlencode($res['username']) . '">' . $res['username'] . '</a></td>';
echo '<td>' . number_format($res['points'],0) . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<p><a class="btn btn-info btn-block" href="top.php?t=m">View all</a></p>
</div>
<div class="span6">
<h2>Year Top Scores</h2>
<?php
$result = array();
try {
$result = $storage->getYearTopScores(1, 10);
} catch(StorageSchemaException $e) {
echo "<div class='alert alert-error'>Error: Database schema is not queryable</div>";
} catch(StorageConnectionException $e) {
echo "<div class='alert alert-error'>Error: Database is not available</div>";
}
?>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Username</th>
<th>Points</th>
</tr>
</thead>
<tbody>
<?php
foreach($result as $key=>$res) {
echo '<tr>';
echo '<td>' . ($key+1) . '</td>';
echo '<td><a href="profile.php?username=' . rawurlencode($res['username']) . '">' . $res['username'] . '</a></td>';
echo '<td>' . number_format($res['points'],0) . '</td>';
echo '</tr>';
}
$storage->close();
?>
</tbody>
</table>
<p><a class="btn btn-info btn-block" href="top.php?t=y">View all</a></p>
</div>
</div>

View File

@ -1,52 +0,0 @@
<div class="hero-unit">
<h1>Top Scores</h1>
<p>Player rankings.</p>
</div>
<div class="row">
<div class="span12">
<ul class="nav nav-pills">
<li<?php if($values['timespan']=='d') { echo ' class="active"'; } ?>><a href="top.php?t=d">Day</a></li>
<li<?php if($values['timespan']=='w') { echo ' class="active"'; } ?>><a href="top.php?t=w">Week</a></li>
<li<?php if($values['timespan']=='m') { echo ' class="active"'; } ?>><a href="top.php?t=m">Month</a></li>
<li<?php if($values['timespan']=='y') { echo ' class="active"'; } ?>><a href="top.php?t=y">Year</a></li>
</ul>
</div>
</div>
<div class="row">
<div class="span6">
<h2>Top Scores for <?php echo $values['timeDesc']; ?></h2>
<?php
foreach($values['errors'] as $error) {
echo "<div class='alert alert-error'>$error</div>";
}
?>
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Username</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<?php
$currentRank = ($values['page']-1)*$values['maxResults'] + 1;
foreach($values['result'] as $res) {
echo '<tr>';
echo '<td>' . $currentRank . '</td>';
echo '<td><a href="profile.php?username=' . rawurlencode($res['username']) . '">' . $res['username'] . '</a></td>';
echo '<td>' . number_format($res['points'],0) . '</td>';
echo '</tr>';
$currentRank++;
}
?>
</tbody>
</table>
<?php
$pagination = new Paginator($values['page'], $values['resultCount'], $values['maxResults']);
$pagination->paginate();
?>
</div>
<div class="offset6"></div>
</div>

View File

@ -1,77 +0,0 @@
<?php
$username = $values['username'];
$usernameCanonical = $values['usernameCanonical'];
$page = $values['page'];
$maxResults = $values['maxResults'];
$usersCount = $values['usersCount'];
$users = $values['users'];
$errors = $values['errors'];
?>
<div class="hero-unit">
<h1>Players</h1>
<p>Show stats for players.</p>
<p>
</p>
</div>
<div class="row">
<div class="span12">
<h2>Search</h2>
<form method="get">
Username: <input name="username" value="<?php echo $username; ?>"></input>
<input type="submit"></input>
</form>
<?php
if(count($errors) != 0) {
foreach($errors as $error) {
echo "<div class='alert alert-error'>$error</div>";
}
}
if($usersCount==0) {
echo "<div class='alert alert-error'>User not found.</div>";
$users = array();
}
if($usernameCanonical=='') {
echo "<div class='alert alert-info'>Enter a username above to search for stats.</div>";
}
?>
</div>
</div>
<div class="row">
<div class="span12">
<h2>Player data</h2>
<table class="table">
<thead>
<tr>
<th>Username</th>
<th>Total Points</th>
<th>Question Answered*</th>
</tr>
</thead>
<tbody>
<?php
foreach($users as $res) {
echo '<tr>';
echo '<td><a href="profile.php?username=' . rawurlencode($res['username']) . '">' . $res['username'] . '</a></td>';
echo '<td>' . number_format($res['points'],0) . '</td>';
echo '<td>' . number_format($res['total'],0) . '</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<?php
$pagination = new Paginator($page, $usersCount, $maxResults);
$pagination->paginate();
?>
</div>
</div>
<div class="row">
<div class="span12">
<p>* These stats do not include KAOS</p>
</div>
</div>