Initial commit, also v0.1

This commit is contained in:
Kegan Myers 2013-06-05 23:54:00 -05:00
commit b6470737fc
15 changed files with 532 additions and 0 deletions

26
LICENSE Executable file
View file

@ -0,0 +1,26 @@
Copyright (c) 2013, terribleplan
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Verineu LLC nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

18
README.md Executable file
View file

@ -0,0 +1,18 @@
#Emergency Site Software
========================
A small php software that provides an easy way to create a site like http://emergencycompliment.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
------------
+ Added
- Removed
~ Fixed
0.1 (current)
+ Database interfaces
+ PHP 'database'
+ Main classes
+ Javascript/CSS
+ Placeholders

34
admin.php Executable file
View file

@ -0,0 +1,34 @@
<?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.");
}
$p = null;
$db = new Database();
$authAttempt = false;
if (isset($_POST['login'])) {
if (isset($_POST['user'])) {
if (isset($_POST['pass'])) {
//TODO: Process the user login attempt.
} else {
$authAttempt = true;
}
} else {
$authAttempt = true;
}
}
if ($authAttempt) {
//TODO: Display failed login page
}
if (isset($p)) {
//TODO: Actually handle the user's input.
} else {
//TODO: Display an interface for submitting a "whatever".
}
die("In version 0.3");

92
index.php Executable file
View file

@ -0,0 +1,92 @@
<?php
include_once('settings.php');
include_once('lib/db.php');
include_once('lib/db_'.$settings['db']['type'].'.php');
include_once('lib/color.php');
/* Changelog is in README.md
* TODO list:
*
* 0.2:
* SQLite Database class
* Submission page
*
* 0.3:
* Admin page
*
* 0.4:
* MySQL PDO Database class
*
* 0.5:
* Installer
*
* 0.6:
* Other databases?
*
*/
//initial setup
$db = new database($settings);
$clr = new color($db);
$q = null;
$c = null;
if(isset($_GET['q'])) {
$q = $_GET['q'];
}
if(isset($_GET['c'])) {
$c = $_GET['c'];
} else {
$c = "nocolor";
}
$output = "";
if (isset($q)) {
/* API:
* c= color, nocolor
* assumes nocolor
*/
header('Content-type: application/json');
$output = '{"result":"';
if ($db->ready()) {
$output .= 'success","content":"';
if (is_int($q) && $db->hasPhrase($q)) {
$output .= $db->getPhrase($q);
} else {
$output .= $db->getPhrase(-1);
}
if ($c == 'color') {
$output .= '","color":"' . $clr->rgbCSS();
}
} else {
$output .= 'failure';
}
$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);

21
lib/JQ-LICENSE Executable file
View file

@ -0,0 +1,21 @@
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.

44
lib/color.php Executable file
View file

@ -0,0 +1,44 @@
<?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();
}
}

42
lib/db.php Executable file
View file

@ -0,0 +1,42 @@
<?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);
}

6
lib/db_pdo_mysql.php Executable file
View file

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

42
lib/db_php.php Executable file
View file

@ -0,0 +1,42 @@
<?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));
}
}

5
lib/db_sqlite.php Executable file
View file

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

19
lib/jquery.min.js vendored Executable file

File diff suppressed because one or more lines are too long

35
settings.php Executable file
View file

@ -0,0 +1,35 @@
<?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.");

113
site.css Executable file
View file

@ -0,0 +1,113 @@
@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: 140;
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;
}

13
site.js Executable file
View file

@ -0,0 +1,13 @@
function replaceContent(input) {
$(".content").html(input);
}
function changeColor(input) {
$("body").css("background-color",input);
}
function loadAnother() {
$.getJSON(beg + "index.php?q=-1&c=color", function (data) {
replaceContent(data.content);
changeColor(data.color);
});
return false;
}

22
submit.php Executable file
View file

@ -0,0 +1,22 @@
<?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.");
}
$p = null;
$db = new Database();
if (isset($_POST['p'])) {
$p = $_POST['p'];
}
if (isset($p)) {
//TODO: Actually handle the user's input.
} else {
//TODO: Display an interface for submitting a "whatever".
}
die("In version 0.2");