2014-02-14 16:02:59 +01:00
|
|
|
<?php
|
|
|
|
|
2014-02-17 21:30:36 +01:00
|
|
|
@(require_once('config.php'));
|
|
|
|
include('version.php');
|
2014-06-21 15:27:18 +02:00
|
|
|
$debug = 1; // Set to 1 in order to enable debug mode (shows sensitive database info), use for troubleshooting
|
2014-02-17 21:30:36 +01:00
|
|
|
$footer = "© Copyright 2014 $wsn. Powered by <a href='http://github.com/cydrobolt/polr'>Polr</a> ver $version build $reldate";
|
2014-02-14 16:02:59 +01:00
|
|
|
//connect to mysql with $mysqli variable
|
2014-06-21 15:27:18 +02:00
|
|
|
$mysqli = new mysqli($host, $user, $passwd, $db) or $wp = 1; //If cannot connect, then set var $wp to 1
|
2014-02-14 16:02:59 +01:00
|
|
|
|
2014-06-21 15:27:18 +02:00
|
|
|
function autoloader($class) {
|
|
|
|
include $class . '.php';
|
|
|
|
}
|
2014-02-14 16:02:59 +01:00
|
|
|
|
2014-06-21 15:27:18 +02:00
|
|
|
spl_autoload_register('autoloader');
|
|
|
|
session_start();
|
|
|
|
|
|
|
|
function sqlrun($query) {
|
2014-02-14 16:02:59 +01:00
|
|
|
global $mysqli;
|
|
|
|
$queryrs = $query;
|
2014-06-21 15:27:18 +02:00
|
|
|
$resultrs = $mysqli->query($queryrs) or showerror();
|
2014-02-14 16:02:59 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-21 15:27:18 +02:00
|
|
|
function sqlex($table, $rowf, $where, $wval) {
|
|
|
|
// Check whether a certain row/column exists
|
|
|
|
// Look at SQLFetch for variable def's
|
|
|
|
global $mysqli; //Import var into function
|
2014-02-14 16:02:59 +01:00
|
|
|
//Sanitize strings
|
2014-06-21 15:27:18 +02:00
|
|
|
$rowfs = $mysqli->real_escape_string($rowf);
|
|
|
|
$tables = $mysqli->real_escape_string($table);
|
|
|
|
$wheres = $mysqli->real_escape_string($where);
|
|
|
|
$wvals = $mysqli->real_escape_string($wval);
|
2014-02-14 16:02:59 +01:00
|
|
|
|
2014-06-21 15:27:18 +02:00
|
|
|
$query = "SELECT $rowfs FROM $tables WHERE $wheres='$wvals'";
|
|
|
|
$result = $mysqli->query($query) or showerror();
|
|
|
|
$numrows = $result->num_rows;
|
|
|
|
if (!$numrows) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-14 16:02:59 +01:00
|
|
|
}
|
2014-06-21 15:27:18 +02:00
|
|
|
function sqlfetch($table, $rowf, $where, $wval) {
|
|
|
|
/*
|
|
|
|
* Fetch a value from the database
|
|
|
|
* Takes 4 arguments:
|
|
|
|
* $table : table in question
|
|
|
|
* $rowf = row to fetch
|
|
|
|
* $where = the 'where' value, as in WHERE $where = $wval
|
|
|
|
* $wval = the value of the $where val ^
|
|
|
|
*/
|
|
|
|
global $mysqli;
|
2014-02-14 16:02:59 +01:00
|
|
|
|
2014-06-21 15:27:18 +02:00
|
|
|
$rowfs = $mysqli->real_escape_string($rowf);
|
|
|
|
$tables = $mysqli->real_escape_string($table);
|
|
|
|
$wheres = $mysqli->real_escape_string($where);
|
|
|
|
$wvals = $mysqli->real_escape_string($wval);
|
2014-02-14 16:02:59 +01:00
|
|
|
|
2014-06-21 15:27:18 +02:00
|
|
|
$query = "SELECT $rowfs FROM $tables WHERE $wheres='$wvals'";
|
|
|
|
$result = $mysqli->query($query) or showerror();
|
|
|
|
$row = mysqli_fetch_assoc($result);
|
|
|
|
return $row[$rowf];
|
2014-02-14 16:02:59 +01:00
|
|
|
}
|
2014-06-21 15:27:18 +02:00
|
|
|
|
|
|
|
function showerror() {
|
|
|
|
//Show an error, and die. If Debug is on, show SQL error message
|
|
|
|
global $debug;
|
|
|
|
global $mysqli;
|
|
|
|
echo "There seems to be a problem :'( *sniff* . Click > <a href='http://webchat.freenode.net/?channels=polr'>here</a> contact an administrator.";
|
|
|
|
if ($debug == 1) {
|
|
|
|
echo "<br>Error:<br>";
|
|
|
|
echo $mysqli->error;
|
|
|
|
}
|
|
|
|
die();
|
2014-02-14 16:02:59 +01:00
|
|
|
}
|
|
|
|
|
2014-06-21 15:27:18 +02:00
|
|
|
|
|
|
|
function filterurl($url) {
|
|
|
|
if (!filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED)) {
|
2014-02-14 16:02:59 +01:00
|
|
|
return false;
|
2014-06-21 15:27:18 +02:00
|
|
|
} else {
|
|
|
|
return true;
|
2014-02-14 16:02:59 +01:00
|
|
|
}
|
2014-06-21 15:27:18 +02:00
|
|
|
}
|
|
|
|
function filteremail($email) {
|
|
|
|
// Validate an email
|
|
|
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2014-02-14 16:02:59 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|