Version 0.2

This commit is contained in:
Kegan Myers 2013-08-18 17:14:09 -05:00
parent 1196b27e38
commit 8d4f29428b
25 changed files with 650 additions and 317 deletions

View file

@ -1,21 +0,0 @@
Copyright 2013 jQuery Foundation and other contributors
http://jquery.com/
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -1,19 +1,37 @@
#Emergency Site Software
------------
A small php software that provides an easy way to create a site like http://emergencycompliment.com/.
[Reference implementation](http://emergencysitesoftware.com/).
License
------------
The source code of this project is available under a New BSD License except for lib/jquery.min.js, which is provided under the original MIT License.
Text of this project's license is available in LICENSE, and text of jQuery's license is available in JQ-LICENSE.
Changelog
------------
##License
The source code of this project is available under a New BSD License.
##News
###Aug 18 2013
An update including a working MySQL (PDO) implementation is in the works and should be
pushed as early as tomorrow. (This update will not include an admin interface or a
submission interface, that will take a bit more testing. It will allow you to use
something like PHPMyAdmin to edit entries)
##Changelog
[+] Added
[ ] Removed
[~] Fixed
0.1 (current)
[-] Removed
[~] Fixed
###0.2 (current)
[~] Cleaning
[~] Refactoring
[~] Rewriting
[-] Placeholders
###0.1
[+] Database interfaces
[+] PHP 'database'
[+] Main classes
[+] Javascript/CSS
[+] Placeholders

View file

@ -1,11 +1,6 @@
<?php
include_once('settings.php');
include_once('lib/db.php');
include_once('lib/db_'.$settings['db']['type'].'.php');
if (!Database::$wri || !$settings['db']['subm']) {
die("Submissions are currently disabled.");
}
die("Not implemented yet");
require('include.php');
$p = null;
$db = new Database();
@ -30,5 +25,4 @@ if (isset($p)) {
//TODO: Actually handle the user's input.
} else {
//TODO: Display an interface for submitting a "whatever".
}
die("In version 0.3");
}

10
ess-include.php Executable file
View file

@ -0,0 +1,10 @@
<?php
//Handle cloudflare
//(should be improved if possible)
if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
}
define('ESS_SERVERSIDE_LOCATION', dirname(__FILE__) . '/');
require_once(ESS_SERVERSIDE_LOCATION . 'ess-settings.php');
require_once(ESS_SERVERSIDE_LOCATION . 'lib/ess-classes.php');
require_once(ESS_SERVERSIDE_LOCATION . 'lib/ess-db_' . ESS_DB_TYPE . '.php');

34
ess-settings.php Executable file
View file

@ -0,0 +1,34 @@
<?php
/* By removing the following line you agree to the license. */
die("You must edit settings.php before you can use this software.");
define('ESS_NAME', 'Emergency Site Software');
define('ESS_LOCATION_PERMANENT', 'http://emergencysitesoftware.com/');
define('ESS_LOCATION_RELATIVE', '/');
define('ESS_EXTENSION_JS', '.js');
define('ESS_EXTENSION_CSS', '.css');
define('ESS_TAGLINE', 'A steady stream of code to host a simple website with.');
define('ESS_EXIT_TEXT', 'Show me <br /> the c0de.');
define('ESS_EXIT_LINK', 'https://github.com/terribleplan/emergencysite');
define('ESS_MORETEXT', 'I want to know <br /> more.');
define('ESS_SUBMITLINK', '/submit.php');
define('ESS_DB_TYPE', 'php');
define('ESS_DB_HOST', 'localhost');
define('ESS_DB_PORT', 3306);
define('ESS_DB_FILE', 'EsS.sqlite');
define('ESS_DB_USER', 'EmSiSo');
define('ESS_DB_PASS', 'DaBaPas');
define('ESS_DB_DATABASE', 'EmergSite');
define('ESS_DB_PREFIX', 'ESS_');
define('ESS_DB_ALLOWSUBMIT', false);
define('ESS_DB_TBL_USERS', ESS_DB_PREFIX . 'users');
define('ESS_DB_TBL_COLORS', ESS_DB_PREFIX . 'colors');
define('ESS_DB_TBL_PHRASES', ESS_DB_PREFIX . 'phrases');
define('ESS_DB_TBL_SUBMITTED', ESS_DB_PREFIX . 'submitted');

View file

@ -19,7 +19,7 @@ body {
width: 400px;
height: 80px;
padding-top: 20px;
padding-bottom: 20px;left: 50%;
padding-bottom: 20px;left: 50%;
}
.bottom span {
float: left;
@ -47,7 +47,7 @@ body {
}
.corner {
float: left;
width: 140;
width: 140px;
min-height: 1px;
margin-left: 20px;
height: 67px;
@ -90,14 +90,14 @@ body {
margin-bottom: 10px;
margin-top: 10px;
height: 40px;
font-size: 30px
font-size:
30px
}
.top {
.top{
height: 67px;
width: 960px;
}
.submit {
.submit{
font-weight: bold;
display: block;
line-height: 15px;

View file

@ -1,11 +1,11 @@
function replaceContent(input) {
$(".content").html(input);
$(".content")[0].innerHTML = input;
}
function changeColor(input) {
$("body").css("background-color",input);
document.body.style.background = input;
}
function loadAnother() {
$.getJSON(beg + "index.php?q=-1&c=color", function (data) {
h(beg + "index.php?q=-1&c=color", function (data) {
replaceContent(data.content);
changeColor(data.color);
});

1
ess-site.min.css vendored Executable file
View file

@ -0,0 +1 @@
@CHARSET "ISO-8859-1";a{color:white;text-decoration:none;}body{color:white;font-size:14px;height:100%;line-height:20px;margin:0px;width:100%;font-family:helvetica,arial,sans-serif;}.bottom{margin-left:-200px;bottom:0px;position:absolute;width:400px;height:80px;padding-top:20px;padding-bottom:20px;left: 50%;}.bottom span{float:left;display:inline-block;position:relative;width:50%;font-size:23px;font-weight:bold;}.bottom a{display:block;position:relative;text-align:center;}.content{padding-top:40px;float:left;font-size:72px;font-weight:bold;line-height:80px;width:620px}.content a{border-bottom:4px solid white;}.corner{float:left;width:140px;min-height:1px;margin-left:20px;height:67px;}.done{border-right:thin solid white;box-sizing:border-box;float:left;font-size:23px;font-weight:bold;height:40px;position:relative;width:200px;}.main{position:relative;min-height:100%;overflow:hidden;margin:0 auto;width:940px;}.more{border-left:thin solid white;box-sizing:border-box;float:left;font-size:23px;font-weight:bold;height:40px;position:relative;width:200px;}.title{height:60px;float:left;width:780px;}.title h2{text-rendering:optimizelegibility;line-height:40px;margin-bottom:10px;margin-top:10px;height:40px;font-size: 30px}.top{height:67px;width:960px;}.submit{font-weight:bold;display:block;line-height:15px;padding-top:17px;width:65px;text-align:right;}.share{background-size:32px 32px;padding:32px;left:80px;top:-2px;}

1
ess-site.min.js vendored Executable file
View file

@ -0,0 +1 @@
function replaceContent(e){$(".content")[0].innerHTML=e}function changeColor(e){document.body.style.background=e}function loadAnother(){h(beg+"index.php?q=-1&c=color",function(e){replaceContent(e.content);changeColor(e.color)});return false}

138
index.php
View file

@ -1,92 +1,98 @@
<?php
include_once('settings.php');
include_once('lib/db.php');
include_once('lib/db_'.$settings['db']['type'].'.php');
include_once('lib/color.php');
/*
* You should have recieved a copy of the BSD 3-clause license with this file.
* If you cannot find a file named LICENSE it can be obtained from the github
* repository:
* https://github.com/terribleplan/emergencysite/blob/master/LICENSE
*/
require_once('ess-include.php');
/* Changelog is in README.md
* TODO list:
*
* 0.2:
* SQLite Database class
* Submission page
*
*
* 0.3:
* Admin page
*
* Submission page
*
* 0.4:
* MySQL PDO Database class
*
* 0.5:
* Installer
*
* 0.6:
* Other databases?
*
* More databases
*
*/
//initial setup
$db = new database($settings);
$clr = new color($db);
$db = new Database();
$clr = $db->randomColor();
$q = null;
$c = null;
if(isset($_GET['q'])) {
if (isset($_GET['q'])) {
$q = $_GET['q'];
}
if(isset($_GET['c'])) {
$c = $_GET['c'];
} else {
$c = "nocolor";
if (isset($_GET['c'])) {
if ($_GET['c'] === 'color') {
$c = 'color';
} else {
$c = 'nocolor';
}
}
$output = "";
if (isset($q)) {
/* API:
* c= color, nocolor
* assumes nocolor
*/
// API: c=color, <anything else>
header('Content-type: application/json');
$output = '{"result":"';
if ($db->ready()) {
$phrase = $db->getPhrase(-1);
$output .= 'success","content":"';
if (is_int($q) && $db->hasPhrase($q)) {
$output .= $db->getPhrase($q);
if (is_int($q)) {
$phrase = $db->getPhrase($q);
} else {
$output .= $db->getPhrase(-1);
$phrase = $db->getPhrase(-1);
}
$output .= $phrase->getPhrase();
$output .= '","id":"';
$output .= $phrase->getID();
if ($phrase->getError() !== false) {
$output .= '","nf-error":"';
$output .= $phrase->getError();
}
if ($c == 'color') {
$output .= '","color":"' . $clr->rgbCSS();
}
} else {
$output .= 'failure';
}
}
$output .= '"}';
die($output);
} else {
$output = "<html>\n<head>\n\t<title>" . strtolower($settings['type']) . " : " .
$settings['tagline']."</title>\n\t<meta property=\"og:title\" content=\"" . $settings['type'] .
"\"/>\n\t<meta property=\"og:type\" content=\"website\" />\n\t<meta property=\"og:description\" content=\"" .
$settings['tagline'] . "\" />\n\t<meta property=\"og:url\" content=\"" . $settings['pmloc']."\" />\n" .
"\t<script src=\"lib/jquery.min.js\"></script>\n\t<script src=\"site.js\"></script>\n\t<script type=\"text/javascript\">var beg =\"" .
$settings['relloc'] . "\";</script>\n\t<link rel=\"stylesheet\" type=\"text/css\" href=\"site.css\">\n\t<style type=\"text/css\">body{background-color:" .
$clr->html() . ";}</style>\n</head>\n<body>\n\t<div class=\"main\">\n\t\t<div class=\"top\">\n\t\t\t<div class=\"title\"><h2>" .
strtolower($settings['type']) . "</h2></div>\n\t\t\t<div class=\"corner\">\n\t\t\t\t<div class=\"submit\"><a href=\"" .
$settings['submitlink'] . "\">submit your own</a></div>\n\t\t\t\t<div class=\"share\"></div>\n\t\t\t</div>\n\t</div>\n\t\t<div class=\"content\">" .
$db->getPhrase(-1) . "</div>\n\t\t<div class=\"bottom\">\n\t\t\t<div class=\"done\"><a href=\"" . $settings['exitlink'] .
"\">".$settings['exittext'] . "</a></div>\n\t\t\t<div class=\"more\"><a href=\"#\" onclick=\"loadAnother();\">" .
$settings['moretext'] . "</a></div>\n\t\t</div>\n\t</div>\n</body>\n</html>";
}
die ($output);
?>
<html>
<head>
<title><?php print(strtolower(ESS_NAME)); ?> : <?php print(ESS_TAGLINE); ?></title>
<meta property="og:title" content="<?php print(ESS_NAME); ?>" />
<meta property="og:type" content="website" />
<meta property="og:description\" content="<?php print(ESS_TAGLINE); ?>" />
<meta property="og:url" content="<?php print(ESS_LOCATION_PERMANENT); ?>" />
<script src="<?php print(ESS_LOCATION_PERMANENT); ?>lib/ess-140medley<?php print(ESS_EXTENSION_JS); ?>" type="text/javascript"></script>
<script src="<?php print(ESS_LOCATION_PERMANENT); ?>lib/ess-json2<?php print(ESS_EXTENSION_JS); ?>" type="text/javascript"></script>
<script type="text/javascript">var beg = '<?php print(ESS_LOCATION_PERMANENT); ?>';</script>
<script src="<?php print(ESS_LOCATION_PERMANENT); ?>ess-site<?php print(ESS_EXTENSION_JS); ?>" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="<?php print(ESS_LOCATION_PERMANENT); ?>ess-site<?php print(ESS_EXTENSION_CSS); ?>">
<style type="text/css">body{background-color:<?php print($clr->html()); ?>;}</style>
</head>
<body>
<div class="main">
<div class="top">
<div class="title">
<h2><?php print(strtolower(ESS_NAME)); ?></h2>
</div>
<div class="corner">
<div class="submit"><a href="<?php print(ESS_SUBMITLINK); ?>">submit your own</a></div>
<div class="share"></div>
</div>
</div>
<div class="content"><?php print($db->getPhrase(-1)->getPhrase()); ?></div>
<div class="bottom">
<div class="done"><a href="<?php print(ESS_EXIT_LINK); ?>"><?php print(ESS_EXIT_TEXT); ?></a></div>
<div class="more"><a href="#" onclick="loadAnother();"><?php print(ESS_MORETEXT); ?></a></div>
</div>
</div>
</body>
</html>
<?php
die();
}

View file

@ -1,44 +0,0 @@
<?php
class color {
var $cur = null;
function __construct(&$db) {
$this->cur = $db->getColor();
}
function rgbIntArray(){
return $this->cur;
}
function rgbHexArray() {
return array(
dechex($this->cur[0]),
dechex($this->cur[1]),
dechex($this->cur[2])
);
}
function rgbCSS() {
$t = $this->cur;
return "rgb(" . $this->cur[0] . "," . $this->cur[1] . "," .
$this->cur[2] . ")";
}
function html() {
$r = "#";
if ($this->cur[0] < 16)
$r .= "0";
$r .= dechex($this->cur[0]);
if ($this->cur[1] < 16)
$r .= "0";
$r .= dechex($this->cur[1]);
if ($this->cur[2] < 16)
$r .= "0";
$r .= dechex($this->cur[2]);
return $r;
}
function newColor(){
$this->cur = $dtb->getColor();
}
}

View file

@ -1,42 +0,0 @@
<?php
interface ReadableDatabase {
// if this allowed interfaces to have variables
// your db class MUST define this
// public static $wri;
/**
* Function should return a random color.
*/
function getColor();
/**
* Function should return the specified or a random phrase.
*/
function getPhrase($number=-1);
/**
* Function tells if we can store submissions.
*/
function canWrite();
/**
* Returns true if the database can be read from (and write if it supports it).
*/
function ready();
}
interface WritableDatabase {
/**
* Function stores a submission into the submitted table.
* It is up to the implementing class
*/
function storeSubmission($submission, $clientIP);
/**
* Function moves a submission into the approved table.
*/
function approveSubmission($id);
}

View file

@ -1,6 +0,0 @@
<?php
die("Database not implemented until 0.4.");
//SELECT * FROM table WHERE key >= FLOOR(RAND()*MAX(id)) LIMIT 1
class Database implements ReadableDatabase, WritableDatabase {
}

View file

@ -1,42 +0,0 @@
<?php
class Database implements ReadableDatabase {
public static $wri = false;
private $cont, $colo, $sets;
function __construct(&$settings) {
$this->cont=array(
0=>'This software is distributed under a BSD license.',
1=>'This software is still under development.',
2=>'This software is open source.',
3=>'This software is awesomesauce.',
4=>'This software can be downloaded from github.',
);
$this->colo = array(
array(0,128,255), //blue
array(255,0,128), //magenta
array(1,223,58), //green
array(255,191,0), //oragnge-yellow
);
$this->sets = $settings;
}
function getPhrase($number=-1) {
$tc = count($this->cont) - 1;
if ($number > -1 && $number <= $tc) {
return $this->cont[$number];
}
return $this->cont[rand(0,$tc)];
}
function getColor() {
return $this->colo[rand(0,count($this->colo)-1)];
}
function canWrite() {
return self::$wri;
}
function ready() {
return (isset($this->cont) && isset($this->colo));
}
}

View file

@ -1,5 +0,0 @@
<?php
die("Database not implemented until 0.2.");
class database implements ReadableDatabase, WritableDatabase {
}

71
lib/ess-140medley.js Executable file
View file

@ -0,0 +1,71 @@
/* 140 medley
* Technically this not longer conforms to the 140 bytes rule, but i like to think it is done in the spirit of the challenge.
* (c) 2013 - TerriblePlan
* Licensed under the terms of the BSD license
* This file is "forked" from https://github.com/honza/140medley
* This is a micro-framework or a collection of small, helpful utilities for common javascript tasks.
* - create DOM elements - m();
* - DOM selector - $();
* - Get cross-browser xhr - j();
* - Execute things when browser is ready - r();
*/
function m(e, t, n) {
t = document;
n = t.createElement("p");
n.innerHTML = e;
e = t.createDocumentFragment();
while (t = n.firstChild)
e.appendChild(t);
return e;
};
function $(e, t) {
e = e.match(/^(\W)?(.*)/);
return (t || document)["getElement"
+ (e[1] ? e[1] == "#" ? "ById" : "sByClassName" : "sByTagName")]
(e[2]);
};
function j(e) {
for (e = 0; e < 4; e++)
try {
return e ? new ActiveXObject(
[ , "Msxml2", "Msxml3", "Microsoft" ][e] + ".XMLHTTP")
: new XMLHttpRequest;
} catch (t) {
}
};
var re = [], rl;
function r(e) {
var t = "complete";
if (document.readyState !== t)
if (rl === 1)
re.push(e);
else {
rl = 1;
re.push(e);
var n = setInterval(function() {
if (document.readyState !== t)
return;
clearInterval(n);
while (re.length)
re.shift()();
re = null
}, 50);
}
else
e();
};
function h(u, c) {
var q = j();
q.open("GET", u, true);
q.onreadystatechange = function() {
if (q.readyState == 4)
if (q.status == 200)
c(JSON.parse(q.responseText));
}
q.send();
}

1
lib/ess-140medley.min.js vendored Executable file
View file

@ -0,0 +1 @@
function m(e,t,n){t=document;n=t.createElement("p");n.innerHTML=e;e=t.createDocumentFragment();while(t=n.firstChild)e.appendChild(t);return e}function $(e,t){e=e.match(/^(\W)?(.*)/);return(t||document)["getElement"+(e[1]?e[1]=="#"?"ById":"sByClassName":"sByTagName")](e[2])}function j(e){for(e=0;e<4;e++)try{return e?new ActiveXObject([,"Msxml2","Msxml3","Microsoft"][e]+".XMLHTTP"):new XMLHttpRequest}catch(t){}}function r(e){var t="complete";if(document.readyState!==t)if(rl===1)re.push(e);else{rl=1;re.push(e);var n=setInterval(function(){if(document.readyState!==t)return;clearInterval(n);while(re.length)re.shift()();re=null},50)}else e()}function h(e,t){var n=j();n.open("GET",e,true);n.onreadystatechange=function(){if(n.readyState==4)if(n.status==200)t(JSON.parse(n.responseText))};n.send()}var re=[],rl;

122
lib/ess-classes.php Executable file
View file

@ -0,0 +1,122 @@
<?php
class Color {
private $color = false, $id = false;
function __construct($id, $color) {
$this->color = $color;
$this->id = $id;
}
function rgbIntArray(){
return $this->color;
}
function rgbHexArray() {
return array(dechex($this->color[0]), dechex($this->color[1]), dechex($this->color[2]));
}
function rgbCSS() {
return "rgb(" . $this->color[0] . "," . $this->color[1] . "," .
$this->color[2] . ")";
}
function html() {
$r = "#";
if ($this->color[0] < 16)
$r .= "0";
$r .= dechex($this->color[0]);
if ($this->color[1] < 16)
$r .= "0";
$r .= dechex($this->color[1]);
if ($this->color[2] < 16)
$r .= "0";
$r .= dechex($this->color[2]);
return $r;
}
}
class Phrase {
private $phrase = false, $id = false, $error = false;
function __construct($id, $phrase, $error=false) {
if ($error !== false) {
if ($error === true) {
$this->error = 'Generic';
} else {
$this->error = $error;
}
}
$this->id = $id;
$this->phrase = $phrase;
}
public function getError() {
return $this->error;
}
public function getID() {
return $this->id;
}
public function getPhrase() {
return $this->phrase;
}
}
interface ReadableDatabase {
/**
* Should connect to the database and get ready for queries.
*/
function __construct();
/**
* Function should return a random color.
*/
public function randomColor();
/**
* Function should return the specified or a random phrase.
*/
public function getPhrase($id=-1);
/**
*
*/
public function randomPhraseID();
/**
* Returns true if the database can be read from (and write if it supports it).
*/
public function ready();
}
interface WritableDatabase {
/**
* Function stores a submission into the submitted table.
* It is up to the implementing class
*/
public function storeSubmission($submission, $clientIP);
/**
* Function moves a submission into the approved table.
*/
public function approveSubmission($id);
/**
* Function drops a submission from the database table.
*/
public function removeSubmission($id);
/**
* Function drops a phrase from the database.
*/
public function removePhrase($id);
/**
* Function adds a color to the proper table
*/
public function addColor($color);
/**
* Deletes the color with $id from the proper table
*/
public function removeColor($id);
}

76
lib/ess-db_pdo_mysql.php Executable file
View file

@ -0,0 +1,76 @@
<?php
class Database implements ReadableDatabase {
//connection
private $conn = null, $ready = false;
//statements
private $stm1 = null, $stm2 = null, $stm3 = null, $stm4 = null;
function __construct() {
try {
$this->conn = new PDO("mysql:host=" . ESS_DB_HOST . "dbname=" . ESS_DB_DATABASE . ";charset=utf8", ESS_DB_USER, ESS_DB_PASS);
$this->ready = true;
} catch (PDOException $e) {
}
}
function randomColor() {
try{
if ($this->stm2 === null) {
$this->stm2 = $this->conn->prepare("SELECT * FROM " . ESS_DB_TBL_COLORS . " ORDER BY RAND() LIMIT 1");
}
$ta = $this->stm2->fetch(PDO::FETCH_ASSOC);
if ($ta !== false) {
return $ta['id'];
}
} catch (PDOException $e) {
}
return false;
}
function getPhrase($id=-1) {
try{
if ($id >= 0) {
try{
if ($this->stm1 === null) {
$this->stm1 = $this->conn->prepare("SELECT * FROM " . ESS_DB_TBL_PHRASES . " WHERE id = ? LIMIT 1");
}
$this->stm1->execute(array($id));
$ta = $this->stm1->fetch(PDO::FETCH_ASSOC);
if ($ta !== false) {
return new Phrase($ta['id'], $ta['phrase']);
}
} catch (PDOException $e) {
}
}
if ($this->stm3 === null) {
$this->stm3 = $this->conn->prepare("SELECT * FROM " . ESS_DB_TBL_PHRASES . " ORDER BY RAND() LIMIT 1");
}
$this->stm3->execute();
$ta = $this->stm3->fetch(PDO::FETCH_ASSOC);
if ($ta !== false) {
return new Phrase($ta['id'], $ta['phrase']);
}
} catch (PDOException $e) {
}
return false;
}
function randomPhraseID() {
try{
if ($this->stm3 === null) {
$this->stm3 = $this->conn->prepare("SELECT * FROM " . ESS_DB_TBL_PHRASES . " ORDER BY RAND() LIMIT 1");
}
$this->stm3->execute();
$ta = $this->stm3->fetch(PDO::FETCH_ASSOC);
if ($ta !== false) {
return $ta['id'];
}
} catch (PDOException $e) {
}
return false;
}
function ready() {
return ($this->conn->ready && $this->PDO !== false && $this->PDO !== null);
}
}

45
lib/ess-db_php.php Executable file
View file

@ -0,0 +1,45 @@
<?php
/*
* This is enough for a small site, such as the reference implementation. If
* you want advansed features such as submissions and administration, then you
* should use a different database driver.
*/
class Database implements ReadableDatabase {
private $cont, $colo, $numcont, $numcolo;
function __construct() {
$this->cont=array(
0=>'This software is distributed under a BSD license.',
1=>'This software is still under development.',
2=>'This software is awesomesauce.',
3=>'This software can be downloaded from <a href="http://github.com/terribleplan/emergencysite">github</a>.',
);
$this->colo = array(
array(0,128,255), //blue
array(255,0,128), //magenta
array(1,223,58), //green
array(255,191,0) //oragnge-yellow
);
$this->numcont = count($this->cont);
$this->numcolo = count($this->colo);
}
function randomColor() {
$id = rand(0, $this->numcolo-1);
return new Color($id, $this->colo[$id]);
}
function getPhrase($id=-1) {
if ($id >= 0 && $id < $this->numcont) {
return new Phrase($id, $this->cont[$id]);
}
return $this->getPhrase($this->randomPhraseID());
}
function randomPhraseID() {
return rand(0, $this->numcont-1);
}
function ready() {
return (isset($this->cont) && isset($this->colo));
}
}

173
lib/ess-json2.js Executable file
View file

@ -0,0 +1,173 @@
if (typeof JSON !== 'object') {
JSON = {};
}
(function () {
'use strict';
function f(n) {
return n < 10 ? '0' + n : n;
}
if (typeof Date.prototype.toJSON !== 'function') {
Date.prototype.toJSON = function () {
return isFinite(this.valueOf()) ? this.getUTCFullYear() + '-' +
f(this.getUTCMonth() + 1) + '-' +
f(this.getUTCDate()) + 'T' +
f(this.getUTCHours()) + ':' +
f(this.getUTCMinutes()) + ':' +
f(this.getUTCSeconds()) + 'Z' : null;
};
String.prototype.toJSON =
Number.prototype.toJSON =
Boolean.prototype.toJSON = function () {
return this.valueOf();
};
}
var cx =
/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
escapable =
/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
gap, indent, meta = {
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"': '\\"',
'\\': '\\\\'
}, rep;
function quote(string) {
escapable.lastIndex = 0;
return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
var c = meta[a];
return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(
16)).slice(-4);
}) + '"' : '"' + string + '"';
}
function str(key, holder) {
var i, k, v, length, mind = gap,
partial, value = holder[key];
if (value && typeof value === 'object' &&
typeof value.toJSON === 'function') {
value = value.toJSON(key);
}
if (typeof rep === 'function') {
value = rep.call(holder, key, value);
}
switch (typeof value) {
case 'string':
return quote(value);
case 'number':
return isFinite(value) ? String(value) : 'null';
case 'boolean':
case 'null':
return String(value);
case 'object':
if (!value) {
return 'null';
}
gap += indent;
partial = [];
if (Object.prototype.toString.apply(value) === '[object Array]') {
length = value.length;
for (i = 0; i < length; i += 1) {
partial[i] = str(i, value) || 'null';
}
v = partial.length === 0 ? '[]' : gap ? '[\n' + gap + partial.join(',\n' +
gap) + '\n' + mind + ']' : '[' + partial.join(',') + ']';
gap = mind;
return v;
}
if (rep && typeof rep === 'object') {
length = rep.length;
for (i = 0; i < length; i += 1) {
if (typeof rep[i] === 'string') {
k = rep[i];
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
}
}
}
} else {
for (k in value) {
if (Object.prototype.hasOwnProperty.call(value, k)) {
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
}
}
}
}
v = partial.length === 0 ? '{}' : gap ? '{\n' + gap + partial.join(',\n' +
gap) + '\n' + mind + '}' : '{' + partial.join(',') + '}';
gap = mind;
return v;
}
}
if (typeof JSON.stringify !== 'function') {
JSON.stringify = function (value, replacer, space) {
var i;
gap = '';
indent = '';
if (typeof space === 'number') {
for (i = 0; i < space; i += 1) {
indent += ' ';
}
} else if (typeof space === 'string') {
indent = space;
}
rep = replacer;
if (replacer && typeof replacer !== 'function' &&
(typeof replacer !== 'object' ||
typeof replacer.length !== 'number')) {
throw new Error('JSON.stringify');
}
return str('', {
'': value
});
};
}
if (typeof JSON.parse !== 'function') {
JSON.parse = function (text, reviver) {
var j;
function walk(holder, key) {
var k, v, value = holder[key];
if (value && typeof value === 'object') {
for (k in value) {
if (Object.prototype.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if (v !== undefined) {
value[k] = v;
} else {
delete value[k];
}
}
}
}
return reviver.call(holder, key, value);
}
text = String(text);
cx.lastIndex = 0;
if (cx.test(text)) {
text = text.replace(cx, function (a) {
return '\\u' +
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
});
}
if (/^[\],:{}\s]*$/
.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@')
.replace(
/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']')
.replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
j = eval('(' + text + ')');
return typeof reviver === 'function' ? walk({
'': j
}, '') : j;
}
throw new SyntaxError('JSON.parse');
};
}
}());

1
lib/ess-json2.min.js vendored Executable file
View file

@ -0,0 +1 @@
if(typeof JSON!=="object"){JSON={}}(function(){"use strict";function f(e){return e<10?"0"+e:e}function quote(e){escapable.lastIndex=0;return escapable.test(e)?'"'+e.replace(escapable,function(e){var t=meta[e];return typeof t==="string"?t:"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function str(e,t){var n,r,i,s,o=gap,u,a=t[e];if(a&&typeof a==="object"&&typeof a.toJSON==="function"){a=a.toJSON(e)}if(typeof rep==="function"){a=rep.call(t,e,a)}switch(typeof a){case"string":return quote(a);case"number":return isFinite(a)?String(a):"null";case"boolean":case"null":return String(a);case"object":if(!a){return"null"}gap+=indent;u=[];if(Object.prototype.toString.apply(a)==="[object Array]"){s=a.length;for(n=0;n<s;n+=1){u[n]=str(n,a)||"null"}i=u.length===0?"[]":gap?"[\n"+gap+u.join(",\n"+gap)+"\n"+o+"]":"["+u.join(",")+"]";gap=o;return i}if(rep&&typeof rep==="object"){s=rep.length;for(n=0;n<s;n+=1){if(typeof rep[n]==="string"){r=rep[n];i=str(r,a);if(i){u.push(quote(r)+(gap?": ":":")+i)}}}}else{for(r in a){if(Object.prototype.hasOwnProperty.call(a,r)){i=str(r,a);if(i){u.push(quote(r)+(gap?": ":":")+i)}}}}i=u.length===0?"{}":gap?"{\n"+gap+u.join(",\n"+gap)+"\n"+o+"}":"{"+u.join(",")+"}";gap=o;return i}}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;if(typeof JSON.stringify!=="function"){JSON.stringify=function(e,t,n){var r;gap="";indent="";if(typeof n==="number"){for(r=0;r<n;r+=1){indent+=" "}}else if(typeof n==="string"){indent=n}rep=t;if(t&&typeof t!=="function"&&(typeof t!=="object"||typeof t.length!=="number")){throw new Error("JSON.stringify")}return str("",{"":e})}}if(typeof JSON.parse!=="function"){JSON.parse=function(text,reviver){function walk(e,t){var n,r,i=e[t];if(i&&typeof i==="object"){for(n in i){if(Object.prototype.hasOwnProperty.call(i,n)){r=walk(i,n);if(r!==undefined){i[n]=r}else{delete i[n]}}}}return reviver.call(e,t,i)}var j;text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(e){return"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){j=eval("("+text+")");return typeof reviver==="function"?walk({"":j},""):j}throw new SyntaxError("JSON.parse")}}})()

19
lib/jquery.min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -1,35 +0,0 @@
<?php
$settings = array(
'type' => 'Emergency Site Software',
'pmloc'=>'https://emergencysitesoftware.com/',
'relloc' => '/',
'tagline' => 'A steady stream of code to host a simple website with.',
'exittext' => ' Thanks! <br /> Goodbye.',
'moretext' => ' I want to know <br /> more.',
'exitlink' => 'http://google.com/',
'submitlink' => 'mailto:submit@emergencysitesoftware.com',
'db' => array(
'type' => 'php',
'host' => 'localhost',
'file' => 'EsS.sqlite',
'user' => 'EmSiSo',
'pass' => 'DaBaPas',
'datb' => 'EmergSite',
'prfx' => 'ESS_',
'subm' => false,
'tabl' => array(
'users' => 'users',
'colors' => 'colors',
'phrases' => 'phrases',
'submitted' => 'submitted'
),
'encr' => array(
'useEncryption' => false,
'encryptionKey' => 'thisIsAWeakSauceEncryptionKey',
'useSalt' => false,
'salt' => 'thisSaltIsSpoiled'
),
),
);
/* By removing the following line you agree to the license. */
die("You must edit settings.php before you can use this software.");

View file

@ -1,11 +1,6 @@
<?php
include_once('settings.php');
include_once('lib/db.php');
include_once('lib/db_'.$settings['db']['type'].'.php');
if (!Database::$wri || !$settings['db']['subm']) {
die("Submissions are currently disabled.");
}
die("Not implemented yet");
require('include.php');
$p = null;
$db = new Database();
@ -18,5 +13,4 @@ if (isset($p)) {
//TODO: Actually handle the user's input.
} else {
//TODO: Display an interface for submitting a "whatever".
}
die("In version 0.2");
}