first commit
This commit is contained in:
commit
9bbf3caafb
39 changed files with 6490 additions and 0 deletions
11
.htaccess
Normal file
11
.htaccess
Normal file
|
@ -0,0 +1,11 @@
|
|||
DirectoryIndex index.html
|
||||
AddCharset UTF-8 .html
|
||||
AddCharset UTF-8 .php
|
||||
|
||||
<IfModule mod_headers.c>
|
||||
<Files *.html>
|
||||
Header add Pragma "no-cache"
|
||||
Header add Cache-Control "no-cache"
|
||||
Header unset Vary
|
||||
</Files>
|
||||
</IfModule>
|
23
.svn/all-wcprops
Normal file
23
.svn/all-wcprops
Normal file
|
@ -0,0 +1,23 @@
|
|||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 21
|
||||
/svn/!svn/ver/1/trunk
|
||||
END
|
||||
imgboard.php
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 35
|
||||
/svn/!svn/ver/10/trunk/imgboard.php
|
||||
END
|
||||
.htaccess
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 31
|
||||
/svn/!svn/ver/4/trunk/.htaccess
|
||||
END
|
||||
favicon.ico
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 33
|
||||
/svn/!svn/ver/7/trunk/favicon.ico
|
||||
END
|
145
.svn/entries
Normal file
145
.svn/entries
Normal file
|
@ -0,0 +1,145 @@
|
|||
10
|
||||
|
||||
dir
|
||||
1
|
||||
https://tinyib.googlecode.com/svn/trunk
|
||||
https://tinyib.googlecode.com/svn
|
||||
|
||||
|
||||
|
||||
2009-04-28T06:13:22.144594Z
|
||||
1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ac9068a4-33bb-11de-8a2e-13aa1706fec1
|
||||
|
||||
thumb
|
||||
dir
|
||||
|
||||
src
|
||||
dir
|
||||
|
||||
css
|
||||
dir
|
||||
|
||||
res
|
||||
dir
|
||||
|
||||
inc
|
||||
dir
|
||||
|
||||
imgboard.php
|
||||
file
|
||||
10
|
||||
|
||||
|
||||
|
||||
2009-09-19T21:46:36.687500Z
|
||||
cbd0009edf136e903db25ef38fe53ae1
|
||||
2009-09-19T21:48:28.690807Z
|
||||
10
|
||||
tslocum
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
11975
|
||||
|
||||
.htaccess
|
||||
file
|
||||
4
|
||||
|
||||
|
||||
|
||||
2009-08-10T14:35:37.140625Z
|
||||
39d69df67a127e3914df8916452324c4
|
||||
2009-09-04T03:12:19.723445Z
|
||||
4
|
||||
tslocum
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
225
|
||||
|
||||
favicon.ico
|
||||
file
|
||||
7
|
||||
|
||||
|
||||
|
||||
2009-08-15T04:35:52.000000Z
|
||||
c07f4742f5123d08c9b3f379042c9658
|
||||
2009-09-16T19:10:07.306932Z
|
||||
7
|
||||
tslocum
|
||||
has-props
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
1150
|
||||
|
5
.svn/prop-base/favicon.ico.svn-base
Normal file
5
.svn/prop-base/favicon.ico.svn-base
Normal file
|
@ -0,0 +1,5 @@
|
|||
K 13
|
||||
svn:mime-type
|
||||
V 24
|
||||
application/octet-stream
|
||||
END
|
11
.svn/text-base/.htaccess.svn-base
Normal file
11
.svn/text-base/.htaccess.svn-base
Normal file
|
@ -0,0 +1,11 @@
|
|||
DirectoryIndex index.html
|
||||
AddCharset UTF-8 .html
|
||||
AddCharset UTF-8 .php
|
||||
|
||||
<IfModule mod_headers.c>
|
||||
<Files *.html>
|
||||
Header add Pragma "no-cache"
|
||||
Header add Cache-Control "no-cache"
|
||||
Header unset Vary
|
||||
</Files>
|
||||
</IfModule>
|
BIN
.svn/text-base/favicon.ico.svn-base
Normal file
BIN
.svn/text-base/favicon.ico.svn-base
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
348
.svn/text-base/imgboard.php.svn-base
Normal file
348
.svn/text-base/imgboard.php.svn-base
Normal file
|
@ -0,0 +1,348 @@
|
|||
<?php
|
||||
# TinyIB
|
||||
#
|
||||
# http://tinyib.googlecode.com/
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set("display_errors", 1);
|
||||
session_start();
|
||||
|
||||
if (get_magic_quotes_gpc()) {
|
||||
foreach ($_GET as $key => $val) { $_GET[$key] = stripslashes($val); }
|
||||
foreach ($_POST as $key => $val) { $_POST[$key] = stripslashes($val); }
|
||||
}
|
||||
if (get_magic_quotes_runtime()) { set_magic_quotes_runtime(0); }
|
||||
|
||||
$tinyib = array();
|
||||
$tinyib['board'] = "b"; // Identifier for this board using only letters and numbers
|
||||
$tinyib['boarddescription'] = "TinyIB"; // Displayed in the logo area
|
||||
$tinyib['maxthreads'] = 100; // Set this to limit the number of threads allowed before discarding older threads. 0 to disable
|
||||
$tinyib['logo'] = ""; // Logo HTML
|
||||
$tinyib['tripseed'] = ""; // Text to use when generating secure tripcodes
|
||||
$tinyib['adminpassword'] = ""; // Text entered at the manage prompt to gain administrator access
|
||||
$tinyib['modpassword'] = ""; // Same as above, but only has access to delete posts. Blank ("") to disable
|
||||
$tinyib['databasemode'] = "flatfile"; // flatfile or mysql
|
||||
|
||||
// mysql settings
|
||||
$mysql_host = "localhost";
|
||||
$mysql_username = "";
|
||||
$mysql_password = "";
|
||||
$mysql_database = "";
|
||||
$mysql_posts_table = $tinyib['board'] . "_posts";
|
||||
$mysql_bans_table = "bans";
|
||||
|
||||
function fancyDie($message) {
|
||||
die('<span style="color: red;font-size: 1.5em;font-family: Helvetica;">' . $message . '</span>');
|
||||
}
|
||||
|
||||
// Check directories are writable by the script
|
||||
$writedirs = array("res", "src", "thumb");
|
||||
if ($tinyib['databasemode'] == 'flatfile') { $writedirs[] = "inc/flatfile"; }
|
||||
foreach ($writedirs as $dir) {
|
||||
if (!is_writable($dir)) {
|
||||
fancyDie("Directory '" . $dir . "' can not be written to! Please modify its permissions.");
|
||||
}
|
||||
}
|
||||
|
||||
$includes = array("inc/functions.php", "inc/html.php");
|
||||
if ($tinyib['databasemode'] == 'flatfile') {
|
||||
$includes[] = 'inc/database_flatfile.php';
|
||||
} elseif ($tinyib['databasemode'] == 'mysql') {
|
||||
$includes[] = 'inc/database_mysql.php';
|
||||
} else {
|
||||
fancyDie("Unknown database mode specificed");
|
||||
}
|
||||
|
||||
foreach ($includes as $include) {
|
||||
include $include;
|
||||
}
|
||||
|
||||
if ($tinyib['tripseed'] == '' || $tinyib['adminpassword'] == '') {
|
||||
fancyDie('$tinyib[\'tripseed\'] and $tinyib[\'adminpassword\'] still need to be configured!');
|
||||
}
|
||||
|
||||
$redirect = true;
|
||||
// Check if the request is to make a post
|
||||
if (isset($_POST["message"]) || isset($_POST["file"])) {
|
||||
$ban = banByIP($_SERVER['REMOTE_ADDR']);
|
||||
if ($ban) {
|
||||
if ($ban['expire'] == 0 || $ban['expire'] > time()) {
|
||||
$expire = ($ban['expire'] > 0) ? ('Your ban will expire ' . date('y/m/d(D)H:i:s', $ban['expire'])) : 'The ban on your IP address is permanent and will not expire.';
|
||||
$reason = ($ban['reason'] == '') ? '' : ('<br>The reason provided was: ' . $ban['reason']);
|
||||
fancyDie('Sorry, it appears that you have been banned from posting on this image board. ' . $expire . $reason);
|
||||
} else {
|
||||
clearExpiredBans();
|
||||
}
|
||||
}
|
||||
|
||||
$parent = "0";
|
||||
if (isset($_POST["parent"])) {
|
||||
if ($_POST["parent"] != "0") {
|
||||
if (!threadExistsByID($_POST['parent'])) {
|
||||
fancyDie("Invalid parent thread ID supplied, unable to create post.");
|
||||
}
|
||||
|
||||
$parent = $_POST["parent"];
|
||||
}
|
||||
}
|
||||
|
||||
$lastpost = lastPostByIP();
|
||||
if ($lastpost) {
|
||||
if ((time() - $lastpost['timestamp']) < 30) {
|
||||
fancyDie("Please wait a moment before posting again. You will be able to make another post in " . (30 - (time() - $lastpost['timestamp'])) . " seconds.");
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen($_POST["message"]) > 8000) {
|
||||
fancyDie("Please shorten your message, or post it in multiple parts. Your message is " . strlen($_POST["message"]) . " characters long, and the maximum allowed is 8000.");
|
||||
}
|
||||
|
||||
$post = newPost();
|
||||
$post['parent'] = $parent;
|
||||
$post['ip'] = $_SERVER['REMOTE_ADDR'];
|
||||
|
||||
$nt = nameAndTripcode($_POST["name"]);
|
||||
$post['name'] = $nt[0];
|
||||
$post['tripcode'] = $nt[1];
|
||||
|
||||
$post['name'] = cleanString(substr($post['name'], 0, 75));
|
||||
$post['email'] = cleanString(str_replace('"', '"', substr($_POST["email"], 0, 75)));
|
||||
$post['subject'] = cleanString(substr($_POST["subject"], 0, 75));
|
||||
$post['message'] = str_replace("\n", "<br>", colorQuote(cleanString(rtrim($_POST["message"]))));
|
||||
if ($_POST['password'] != '') { $post['password'] = md5(md5($_POST['password'])); } else { $post['password'] = ''; }
|
||||
$post['nameblock'] = nameBlock($post['name'], $post['tripcode'], $post['email'], time());
|
||||
|
||||
if (isset($_FILES['file'])) {
|
||||
if ($_FILES['file']['name'] != "") {
|
||||
switch ($_FILES['file']['error']) {
|
||||
case UPLOAD_ERR_OK:
|
||||
break;
|
||||
case UPLOAD_ERR_FORM_SIZE:
|
||||
fancyDie("That file is larger than 2 MB.");
|
||||
break;
|
||||
case UPLOAD_ERR_INI_SIZE:
|
||||
fancyDie("The uploaded file exceeds the upload_max_filesize directive (" . ini_get('upload_max_filesize') . ") in php.ini.");
|
||||
break;
|
||||
case UPLOAD_ERR_PARTIAL:
|
||||
fancyDie("The uploaded file was only partially uploaded.");
|
||||
break;
|
||||
case UPLOAD_ERR_NO_FILE:
|
||||
fancyDie("No file was uploaded.");
|
||||
break;
|
||||
case UPLOAD_ERR_NO_TMP_DIR:
|
||||
fancyDie("Missing a temporary folder.");
|
||||
break;
|
||||
case UPLOAD_ERR_CANT_WRITE:
|
||||
fancyDie("Failed to write file to disk");
|
||||
break;
|
||||
default:
|
||||
fancyDie("Unable to save the uploaded file.");
|
||||
}
|
||||
|
||||
if (!is_file($_FILES['file']['tmp_name']) || !is_readable($_FILES['file']['tmp_name'])) {
|
||||
fancyDie("File transfer failure. Please retry the submission.");
|
||||
}
|
||||
|
||||
$post['file_original'] = substr(htmlentities($_FILES['file']['name'], ENT_QUOTES), 0, 50);
|
||||
$post['file_hex'] = md5_file($_FILES['file']['tmp_name']);
|
||||
$post['file_size'] = $_FILES['file']['size'];
|
||||
$post['file_size_formatted'] = convertBytes($post['file_size']);
|
||||
$file_type = strtolower(preg_replace('/.*(\..+)/', '\1', $_FILES['file']['name'])); if ($file_type == '.jpeg') { $file_type = '.jpg'; }
|
||||
$file_name = time() . mt_rand(1, 99);
|
||||
$post['thumb'] = $file_name . "s" . $file_type;
|
||||
$post['file'] = $file_name . $file_type;
|
||||
$thumb_location = "thumb/" . $post['thumb'];
|
||||
$file_location = "src/" . $post['file'];
|
||||
|
||||
if(function_exists("mime_content_type")) {
|
||||
$file_mime = mime_content_type($_FILES['file']['tmp_name']);
|
||||
} else {
|
||||
$file_mime = "image/jpeg"; // It is highly recommended you use PHP 4.3.0 or later!
|
||||
}
|
||||
|
||||
if (($file_type == '.jpg' || $file_type == '.gif' || $file_type == '.png') && ($file_mime == "image/jpeg" || $file_mime == "image/gif" || $file_mime == "image/png")) {
|
||||
if (!@getimagesize($_FILES['file']['tmp_name'])) {
|
||||
fancyDie("Failed to read the size of the uploaded file. Please retry the submission.");
|
||||
}
|
||||
} else {
|
||||
fancyDie("Only GIF, JPG, and PNG files are allowed.");
|
||||
}
|
||||
|
||||
|
||||
$hexmatches = postsByHex($post['file_hex']);
|
||||
if (count($hexmatches) > 0) {
|
||||
foreach ($hexmatches as $hexmatch) {
|
||||
if ($hexmatch["parent"] == "0") {
|
||||
$goto = $hexmatch["id"];
|
||||
} else {
|
||||
$goto = $hexmatch["parent"];
|
||||
}
|
||||
fancyDie("Duplicate file uploaded. That file has already been posted <a href=\"res/" . $goto . ".html#" . $hexmatch["id"] . "\">here</a>.");
|
||||
}
|
||||
}
|
||||
|
||||
if (!move_uploaded_file($_FILES['file']['tmp_name'], $file_location)) {
|
||||
fancyDie("Could not copy uploaded file.");
|
||||
}
|
||||
|
||||
if ($_FILES['file']['size'] != filesize($file_location)) {
|
||||
fancyDie("File transfer failure. Please go back and try again.");
|
||||
}
|
||||
|
||||
$file_imagesize = getimagesize($file_location);
|
||||
$post['image_width'] = $file_imagesize[0];
|
||||
$post['image_height'] = $file_imagesize[1];
|
||||
|
||||
if ($post['image_width'] > 250 || $post['image_height'] > 250) {
|
||||
$width = 250;
|
||||
$height = 250;
|
||||
} else {
|
||||
$width = $post['image_width'];
|
||||
$height = $post['image_height'];
|
||||
}
|
||||
if (!createThumbnail($file_location, $thumb_location, $width, $height)) {
|
||||
fancyDie("Could not create thumbnail.");
|
||||
}
|
||||
|
||||
$thumbsize = getimagesize($thumb_location);
|
||||
$post['thumb_width'] = $thumbsize[0];
|
||||
$post['thumb_height'] = $thumbsize[1];
|
||||
}
|
||||
}
|
||||
|
||||
if ($post['file'] == '') { // No file uploaded
|
||||
if ($post['parent'] == '0') {
|
||||
fancyDie("An image is required to start a thread.");
|
||||
}
|
||||
if (str_replace('<br>', '', $post['message']) == "") {
|
||||
fancyDie("Please enter a message and/or upload an image to make a reply.");
|
||||
}
|
||||
}
|
||||
|
||||
$post['id'] = insertPost($post);
|
||||
trimThreads();
|
||||
echo 'Updating thread page...<br>';
|
||||
if ($post['parent'] != '0') {
|
||||
rebuildThread($post['parent']);
|
||||
|
||||
if (strtolower($post['email']) != "sage") {
|
||||
bumpThreadByID($post['parent']);
|
||||
}
|
||||
} else {
|
||||
rebuildThread($post['id']);
|
||||
}
|
||||
|
||||
echo 'Updating thread index...<br>';
|
||||
rebuildIndexes();
|
||||
// Check if the request is to delete a post and/or its associated image
|
||||
} elseif (isset($_GET['delete']) && !isset($_GET['manage'])) {
|
||||
if (isset($_POST['delete'])) {
|
||||
$post = postByID($_POST['delete']);
|
||||
if ($post) {
|
||||
if ($post['password'] != '' && md5(md5($_POST['password'])) == $post['password']) {
|
||||
deletePostByID($post['id']);
|
||||
if ($post['parent'] == 0) { threadUpdated($post['id']); } else { threadUpdated($post['parent']); }
|
||||
echo 'Post successfully deleted.';
|
||||
} else {
|
||||
fancyDie('Invalid password.');
|
||||
}
|
||||
} else {
|
||||
fancyDie('Sorry, an invalid post identifier was sent. Please go back, refresh the page, and try again.');
|
||||
}
|
||||
} else {
|
||||
fancyDie('Tick the box next to a post and click "Delete" to delete it.');
|
||||
}
|
||||
$redirect = false;
|
||||
// Check if the request is to access the management area
|
||||
} elseif (isset($_GET["manage"])) {
|
||||
$text = ""; $onload = ""; $navbar = " ";
|
||||
$redirect = false; $loggedin = false; $isadmin = false;
|
||||
$returnlink = basename($_SERVER['PHP_SELF']);
|
||||
|
||||
list($loggedin, $isadmin) = manageCheckLogIn();
|
||||
|
||||
if ($loggedin) {
|
||||
if ($isadmin) {
|
||||
if (isset($_GET["rebuildall"])) {
|
||||
$allthreads = allThreads();
|
||||
foreach ($allthreads as $thread) {
|
||||
rebuildThread($thread["id"]);
|
||||
}
|
||||
rebuildIndexes();
|
||||
$text .= "Rebuilt board.";
|
||||
} elseif (isset($_GET["bans"])) {
|
||||
clearExpiredBans();
|
||||
|
||||
if (isset($_POST['ip'])) {
|
||||
if ($_POST['ip'] != '') {
|
||||
$banexists = banByIP($_POST['ip']);
|
||||
if ($banexists) {
|
||||
fancyDie('Sorry, there is already a ban on record for that IP address.');
|
||||
}
|
||||
|
||||
$ban = array();
|
||||
$ban['ip'] = $_POST['ip'];
|
||||
$ban['expire'] = ($_POST['expire'] > 0) ? (time() + $_POST['expire']) : 0;
|
||||
$ban['reason'] = $_POST['reason'];
|
||||
|
||||
insertBan($ban);
|
||||
$text .= '<b>Successfully added a ban record for ' . $ban['ip'] . '</b><br>';
|
||||
}
|
||||
} elseif (isset($_GET['lift'])) {
|
||||
$ban = banByID($_GET['lift']);
|
||||
if ($ban) {
|
||||
deleteBanByID($_GET['lift']);
|
||||
$text .= '<b>Successfully lifted ban on ' . $ban['ip'] . '</b><br>';
|
||||
}
|
||||
}
|
||||
|
||||
$onload = manageOnLoad('bans');
|
||||
$text .= manageBanForm();
|
||||
$text .= manageBansTable();
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_GET["delete"])) {
|
||||
$post = postByID($_GET['delete']);
|
||||
if ($post) {
|
||||
deletePostByID($post['id']);
|
||||
rebuildIndexes();
|
||||
if ($post['parent'] > 0) {
|
||||
rebuildThread($post['parent']);
|
||||
}
|
||||
$text .= '<b>Post No.' . $post['id'] . ' successfully deleted.</b>';
|
||||
} else {
|
||||
fancyDie("Sorry, there doesn't appear to be a post with that ID.");
|
||||
}
|
||||
} elseif (isset($_GET["moderate"])) {
|
||||
if ($_GET['moderate'] > 0) {
|
||||
$post = postByID($_GET['moderate']);
|
||||
if ($post) {
|
||||
$text .= manageModeratePost($post);
|
||||
} else {
|
||||
fancyDie("Sorry, there doesn't appear to be a post with that ID.");
|
||||
}
|
||||
} else {
|
||||
$onload = manageOnLoad('moderate');
|
||||
$text .= manageModeratePostForm();
|
||||
}
|
||||
} elseif (isset($_GET["logout"])) {
|
||||
$_SESSION['tinyib'] = '';
|
||||
session_destroy();
|
||||
die('--> --> --><meta http-equiv="refresh" content="0;url=' . $returnlink . '?manage">');
|
||||
}
|
||||
} else {
|
||||
$onload = manageOnLoad('login');
|
||||
$text .= manageLogInForm();
|
||||
}
|
||||
|
||||
echo managePage($text, $onload);
|
||||
} elseif (!file_exists('index.html') || count(allThreads()) == 0) {
|
||||
rebuildIndexes();
|
||||
}
|
||||
|
||||
if ($redirect) {
|
||||
echo '--> --> --><meta http-equiv="refresh" content="0;url=index.html">';
|
||||
}
|
||||
|
||||
?>
|
23
css/.svn/all-wcprops
Normal file
23
css/.svn/all-wcprops
Normal file
|
@ -0,0 +1,23 @@
|
|||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 25
|
||||
/svn/!svn/ver/2/trunk/css
|
||||
END
|
||||
burichan.css
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 38
|
||||
/svn/!svn/ver/2/trunk/css/burichan.css
|
||||
END
|
||||
global.css
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 36
|
||||
/svn/!svn/ver/8/trunk/css/global.css
|
||||
END
|
||||
futaba.css
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 36
|
||||
/svn/!svn/ver/2/trunk/css/futaba.css
|
||||
END
|
137
css/.svn/entries
Normal file
137
css/.svn/entries
Normal file
|
@ -0,0 +1,137 @@
|
|||
10
|
||||
|
||||
dir
|
||||
2
|
||||
https://tinyib.googlecode.com/svn/trunk/css
|
||||
https://tinyib.googlecode.com/svn
|
||||
|
||||
|
||||
|
||||
2009-04-29T14:47:23.189190Z
|
||||
2
|
||||
tslocum
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
0
|
||||
|
||||
burichan.css
|
||||
file
|
||||
|
||||
|
||||
|
||||
|
||||
2009-09-05T06:40:39.781250Z
|
||||
7cd5a3a7d6fe2481ff27bb4acf7faee6
|
||||
2009-04-29T14:47:23.189190Z
|
||||
2
|
||||
tslocum
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
2669
|
||||
|
||||
global.css
|
||||
file
|
||||
8
|
||||
|
||||
|
||||
|
||||
2009-09-18T00:14:15.812500Z
|
||||
87a4674b421f90774b19e2cea188b4ef
|
||||
2009-09-18T00:25:02.232167Z
|
||||
8
|
||||
tslocum
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
1108
|
||||
|
||||
futaba.css
|
||||
file
|
||||
|
||||
|
||||
|
||||
|
||||
2009-03-01T11:57:17.593750Z
|
||||
833be8071c404d80a6887e82e82e3cb2
|
||||
2009-04-29T14:47:23.189190Z
|
||||
2
|
||||
tslocum
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
1942
|
||||
|
181
css/.svn/text-base/burichan.css.svn-base
Normal file
181
css/.svn/text-base/burichan.css.svn-base
Normal file
|
@ -0,0 +1,181 @@
|
|||
html, body {
|
||||
font-size:12pt;
|
||||
background:#EEF2FF;
|
||||
color:#000000;
|
||||
}
|
||||
a {
|
||||
background:inherit;
|
||||
color:#34345C;
|
||||
text-decoration:none;
|
||||
font-family:sans-serif;
|
||||
}
|
||||
a:visited {
|
||||
background:inherit;
|
||||
color:#34345C;
|
||||
text-decoration:none;
|
||||
font-family:sans-serif;
|
||||
}
|
||||
a:hover {
|
||||
color:#DD0000;
|
||||
background:inherit;
|
||||
font-family:sans-serif;
|
||||
}
|
||||
.filesize a {
|
||||
text-decoration:underline;
|
||||
}
|
||||
.filesize a:visited {
|
||||
text-decoration:underline;
|
||||
}
|
||||
.adminbar {
|
||||
text-align:right;
|
||||
background:inherit;
|
||||
clear:both;
|
||||
float:right;
|
||||
}
|
||||
.logo {
|
||||
clear:both;
|
||||
text-align:center;
|
||||
background:inherit;
|
||||
font-size:24pt;
|
||||
color:#AF0A0F;
|
||||
width:100%;
|
||||
}
|
||||
.replymode {
|
||||
background:#0010E0;
|
||||
color:#FFFFFF;
|
||||
width:100%;
|
||||
}
|
||||
.catalogmode {
|
||||
background:#0040E0;
|
||||
color:#FFFFFF;
|
||||
width:100%;
|
||||
}
|
||||
.postarea {
|
||||
background:inherit;
|
||||
}
|
||||
.rules {
|
||||
/*font-size:0.7em;*/
|
||||
width: 468px;
|
||||
font-size: 10px;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
.rules li {
|
||||
margin-left: 1em;
|
||||
/*text-indent: 0em;*/
|
||||
}
|
||||
.postblock {
|
||||
background:#9988EE;
|
||||
color:#000000;
|
||||
font-weight:800;
|
||||
}
|
||||
.footer {
|
||||
text-align:center;
|
||||
font-size:10px;
|
||||
font-family:sans-serif;
|
||||
}
|
||||
.passvalid {
|
||||
background:#9988EE;
|
||||
text-align:center;
|
||||
width:100%;
|
||||
color:#ffffff;
|
||||
}
|
||||
.dellist {
|
||||
background:inherit;
|
||||
text-align:center;
|
||||
}
|
||||
.delbuttons {
|
||||
background:inherit;
|
||||
text-align:center;
|
||||
padding-bottom:4px;
|
||||
}
|
||||
.managehead {
|
||||
background:#0F8FE1;
|
||||
color:#000000;
|
||||
font-family:sans-serif;
|
||||
font-size:14px;
|
||||
padding:0px;
|
||||
}
|
||||
.postlists {
|
||||
background:#FFFFFF;
|
||||
width:100%;
|
||||
padding:0px;
|
||||
color:#000000;
|
||||
}
|
||||
.row1 {
|
||||
background:#9AD2F6;
|
||||
font-family:sans-serif;
|
||||
font-size:12px;
|
||||
color:#000000;
|
||||
}
|
||||
.row2 {
|
||||
background:#FFFFFF;
|
||||
font-family:sans-serif;
|
||||
font-size:12px;
|
||||
color:#000000;
|
||||
}
|
||||
.unkfunc {
|
||||
color:#789922;
|
||||
}
|
||||
.filesize {
|
||||
font-size:12px;
|
||||
font-family:sans-serif;
|
||||
text-decoration:underline;
|
||||
/*padding-left:3em;*/
|
||||
}
|
||||
.filetitle {
|
||||
background:inherit;
|
||||
font-size:18px;
|
||||
font-family:serif;
|
||||
color:#0F0C5D;
|
||||
font-weight:800;
|
||||
}
|
||||
.postername {
|
||||
background:inherit;
|
||||
font-size:12px;
|
||||
font-family:serif;
|
||||
color:#117743;
|
||||
font-weight:800;
|
||||
}
|
||||
.oldpost {
|
||||
background:inherit;
|
||||
font-size:18px;
|
||||
font-family:serif;
|
||||
color:#0F0C5D;
|
||||
font-weight:800;
|
||||
}
|
||||
.omittedposts {
|
||||
background:inherit;
|
||||
font-size:18px;
|
||||
font-family:serif;
|
||||
color:#070707;
|
||||
font-weight:800;
|
||||
}
|
||||
.reply {
|
||||
background:#D6DAF0;
|
||||
color:#000000;
|
||||
font-family:serif;
|
||||
}
|
||||
.replyhl {
|
||||
background: #D6BAD0;
|
||||
color: #000000;
|
||||
}
|
||||
.replytitle {
|
||||
background:inherit;
|
||||
font-size:18px;
|
||||
font-family:serif;
|
||||
color:#0F0C5D;
|
||||
font-weight:800;
|
||||
}
|
||||
.commentpostername {
|
||||
background:inherit;
|
||||
font-size:12px;
|
||||
font-family:serif;
|
||||
color:#117743;
|
||||
font-weight:800;
|
||||
}
|
||||
.thumbnailmsg {
|
||||
background:inherit;
|
||||
font-size:9px;
|
||||
font-family:sans-serif;
|
||||
color:#000000;
|
||||
}
|
150
css/.svn/text-base/futaba.css.svn-base
Normal file
150
css/.svn/text-base/futaba.css.svn-base
Normal file
|
@ -0,0 +1,150 @@
|
|||
html, body {
|
||||
background:#FFFFEE;
|
||||
color:#800000;
|
||||
}
|
||||
a {
|
||||
color:#0000EE;
|
||||
}
|
||||
a:hover {
|
||||
color:#DD0000;
|
||||
}
|
||||
.reflink a:hover{
|
||||
font-weight: bold;
|
||||
}
|
||||
.adminbar {
|
||||
text-align:right;
|
||||
clear:both;
|
||||
float:right;
|
||||
}
|
||||
.logo {
|
||||
clear:both;
|
||||
text-align:center;
|
||||
font-size:2em;
|
||||
color:#800000;
|
||||
width:100%;
|
||||
}
|
||||
.replymode {
|
||||
background:#E04000;
|
||||
text-align:center;
|
||||
padding:2px;
|
||||
color:#FFFFFF;
|
||||
width:100%;
|
||||
}
|
||||
.catalogmode {
|
||||
background:#0040E0;
|
||||
text-align:center;
|
||||
padding:2px;
|
||||
color:#FFFFFF;
|
||||
width:100%;
|
||||
}
|
||||
.rules {
|
||||
/*font-size:0.7em;*/
|
||||
width: 468px;
|
||||
font-size: 10px;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
.rules li {
|
||||
margin-left: 1em;
|
||||
/*text-indent: 0em;*/
|
||||
}
|
||||
.postblock {
|
||||
background:#EEAA88;
|
||||
color:#800000;
|
||||
font-weight:800;
|
||||
}
|
||||
.footer {
|
||||
text-align:center;
|
||||
font-size:12px;
|
||||
font-family:serif;
|
||||
}
|
||||
.passvalid {
|
||||
background:#EEAA88;
|
||||
text-align:center;
|
||||
width:100%;
|
||||
color:#ffffff;
|
||||
}
|
||||
.dellist {
|
||||
font-weight: bold;
|
||||
text-align:center;
|
||||
}
|
||||
.delbuttons {
|
||||
text-align:center;
|
||||
padding-bottom:4px;
|
||||
|
||||
}
|
||||
.managehead {
|
||||
background:#AAAA66;
|
||||
color:#400000;
|
||||
padding:0px;
|
||||
}
|
||||
.postlists {
|
||||
background:#FFFFFF;
|
||||
width:100%;
|
||||
padding:0px;
|
||||
color:#800000;
|
||||
}
|
||||
.row1 {
|
||||
background:#EEEECC;
|
||||
color:#800000;
|
||||
}
|
||||
.row2 {
|
||||
background:#DDDDAA;
|
||||
color:#800000;
|
||||
}
|
||||
.unkfunc {
|
||||
background:inherit;
|
||||
color:#789922;
|
||||
}
|
||||
.filesize {
|
||||
text-decoration:none;
|
||||
}
|
||||
.filetitle {
|
||||
background:inherit;
|
||||
font-size:1.2em;
|
||||
color:#CC1105;
|
||||
font-weight:800;
|
||||
}
|
||||
.postername {
|
||||
color:#117743;
|
||||
font-weight:bold;
|
||||
}
|
||||
.postertrip {
|
||||
color:#228854;
|
||||
}
|
||||
.oldpost {
|
||||
color:#CC1105;
|
||||
font-weight:800;
|
||||
}
|
||||
.omittedposts {
|
||||
color:#707070;
|
||||
}
|
||||
.reply {
|
||||
background: #F0E0D6;
|
||||
color: #800000;
|
||||
}
|
||||
.replyhl {
|
||||
background: #F0C0B0;
|
||||
color: #800000;
|
||||
}
|
||||
.replytitle {
|
||||
font-size: 1.2em;
|
||||
color:#CC1105;
|
||||
font-weight:800;
|
||||
}
|
||||
.commentpostername {
|
||||
color:#117743;
|
||||
font-weight:800;
|
||||
}
|
||||
.thumbnailmsg {
|
||||
font-size: small;
|
||||
color:#800000;
|
||||
}
|
||||
|
||||
.abbrev {
|
||||
color:#707070;
|
||||
}
|
||||
.highlight {
|
||||
background:#F0E0D6;
|
||||
color:#800000;
|
||||
border: 2px dashed #EEAA88;
|
||||
}
|
83
css/.svn/text-base/global.css.svn-base
Normal file
83
css/.svn/text-base/global.css.svn-base
Normal file
|
@ -0,0 +1,83 @@
|
|||
body {
|
||||
margin: 0;
|
||||
padding: 8px;
|
||||
margin-bottom: auto;
|
||||
}
|
||||
|
||||
blockquote blockquote {
|
||||
margin-left: 0em;
|
||||
}
|
||||
|
||||
form {
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
.postarea {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.postarea table {
|
||||
margin: 0px auto;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.aa {
|
||||
white-space: pre;
|
||||
text-align: left;
|
||||
font-family: IPAMonaPGothic, Mona, 'MS PGothic', YOzFontAA97 !important;
|
||||
}
|
||||
|
||||
.thumb {
|
||||
border: none;
|
||||
float: left;
|
||||
margin: 2px 20px;
|
||||
}
|
||||
|
||||
.nothumb {
|
||||
float: left;
|
||||
background: #eee;
|
||||
border: 2px dashed #aaa;
|
||||
text-align: center;
|
||||
margin: 2px 20px;
|
||||
padding: 1em 0.5em 1em 0.5em;
|
||||
}
|
||||
|
||||
.reply blockquote, blockquote :last-child {
|
||||
margin-bottom: 0em;
|
||||
}
|
||||
|
||||
.reflink a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.reflink a:hover{
|
||||
color: #800000;
|
||||
}
|
||||
|
||||
.reply .filesize {
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
.userdelete {
|
||||
float: right;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.doubledash {
|
||||
vertical-align: top;
|
||||
clear: both;
|
||||
float: left;
|
||||
font-size: 1.75em;
|
||||
}
|
||||
|
||||
.moderator {
|
||||
color: #FF0000;
|
||||
}
|
||||
|
||||
.managebutton {
|
||||
font-size: 15px;
|
||||
height: 28px;
|
||||
margin: 0.2em;
|
||||
}
|
181
css/burichan.css
Normal file
181
css/burichan.css
Normal file
|
@ -0,0 +1,181 @@
|
|||
html, body {
|
||||
font-size:12pt;
|
||||
background:#EEF2FF;
|
||||
color:#000000;
|
||||
}
|
||||
a {
|
||||
background:inherit;
|
||||
color:#34345C;
|
||||
text-decoration:none;
|
||||
font-family:sans-serif;
|
||||
}
|
||||
a:visited {
|
||||
background:inherit;
|
||||
color:#34345C;
|
||||
text-decoration:none;
|
||||
font-family:sans-serif;
|
||||
}
|
||||
a:hover {
|
||||
color:#DD0000;
|
||||
background:inherit;
|
||||
font-family:sans-serif;
|
||||
}
|
||||
.filesize a {
|
||||
text-decoration:underline;
|
||||
}
|
||||
.filesize a:visited {
|
||||
text-decoration:underline;
|
||||
}
|
||||
.adminbar {
|
||||
text-align:right;
|
||||
background:inherit;
|
||||
clear:both;
|
||||
float:right;
|
||||
}
|
||||
.logo {
|
||||
clear:both;
|
||||
text-align:center;
|
||||
background:inherit;
|
||||
font-size:24pt;
|
||||
color:#AF0A0F;
|
||||
width:100%;
|
||||
}
|
||||
.replymode {
|
||||
background:#0010E0;
|
||||
color:#FFFFFF;
|
||||
width:100%;
|
||||
}
|
||||
.catalogmode {
|
||||
background:#0040E0;
|
||||
color:#FFFFFF;
|
||||
width:100%;
|
||||
}
|
||||
.postarea {
|
||||
background:inherit;
|
||||
}
|
||||
.rules {
|
||||
/*font-size:0.7em;*/
|
||||
width: 468px;
|
||||
font-size: 10px;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
.rules li {
|
||||
margin-left: 1em;
|
||||
/*text-indent: 0em;*/
|
||||
}
|
||||
.postblock {
|
||||
background:#9988EE;
|
||||
color:#000000;
|
||||
font-weight:800;
|
||||
}
|
||||
.footer {
|
||||
text-align:center;
|
||||
font-size:10px;
|
||||
font-family:sans-serif;
|
||||
}
|
||||
.passvalid {
|
||||
background:#9988EE;
|
||||
text-align:center;
|
||||
width:100%;
|
||||
color:#ffffff;
|
||||
}
|
||||
.dellist {
|
||||
background:inherit;
|
||||
text-align:center;
|
||||
}
|
||||
.delbuttons {
|
||||
background:inherit;
|
||||
text-align:center;
|
||||
padding-bottom:4px;
|
||||
}
|
||||
.managehead {
|
||||
background:#0F8FE1;
|
||||
color:#000000;
|
||||
font-family:sans-serif;
|
||||
font-size:14px;
|
||||
padding:0px;
|
||||
}
|
||||
.postlists {
|
||||
background:#FFFFFF;
|
||||
width:100%;
|
||||
padding:0px;
|
||||
color:#000000;
|
||||
}
|
||||
.row1 {
|
||||
background:#9AD2F6;
|
||||
font-family:sans-serif;
|
||||
font-size:12px;
|
||||
color:#000000;
|
||||
}
|
||||
.row2 {
|
||||
background:#FFFFFF;
|
||||
font-family:sans-serif;
|
||||
font-size:12px;
|
||||
color:#000000;
|
||||
}
|
||||
.unkfunc {
|
||||
color:#789922;
|
||||
}
|
||||
.filesize {
|
||||
font-size:12px;
|
||||
font-family:sans-serif;
|
||||
text-decoration:underline;
|
||||
/*padding-left:3em;*/
|
||||
}
|
||||
.filetitle {
|
||||
background:inherit;
|
||||
font-size:18px;
|
||||
font-family:serif;
|
||||
color:#0F0C5D;
|
||||
font-weight:800;
|
||||
}
|
||||
.postername {
|
||||
background:inherit;
|
||||
font-size:12px;
|
||||
font-family:serif;
|
||||
color:#117743;
|
||||
font-weight:800;
|
||||
}
|
||||
.oldpost {
|
||||
background:inherit;
|
||||
font-size:18px;
|
||||
font-family:serif;
|
||||
color:#0F0C5D;
|
||||
font-weight:800;
|
||||
}
|
||||
.omittedposts {
|
||||
background:inherit;
|
||||
font-size:18px;
|
||||
font-family:serif;
|
||||
color:#070707;
|
||||
font-weight:800;
|
||||
}
|
||||
.reply {
|
||||
background:#D6DAF0;
|
||||
color:#000000;
|
||||
font-family:serif;
|
||||
}
|
||||
.replyhl {
|
||||
background: #D6BAD0;
|
||||
color: #000000;
|
||||
}
|
||||
.replytitle {
|
||||
background:inherit;
|
||||
font-size:18px;
|
||||
font-family:serif;
|
||||
color:#0F0C5D;
|
||||
font-weight:800;
|
||||
}
|
||||
.commentpostername {
|
||||
background:inherit;
|
||||
font-size:12px;
|
||||
font-family:serif;
|
||||
color:#117743;
|
||||
font-weight:800;
|
||||
}
|
||||
.thumbnailmsg {
|
||||
background:inherit;
|
||||
font-size:9px;
|
||||
font-family:sans-serif;
|
||||
color:#000000;
|
||||
}
|
150
css/futaba.css
Normal file
150
css/futaba.css
Normal file
|
@ -0,0 +1,150 @@
|
|||
html, body {
|
||||
background:#FFFFEE;
|
||||
color:#800000;
|
||||
}
|
||||
a {
|
||||
color:#0000EE;
|
||||
}
|
||||
a:hover {
|
||||
color:#DD0000;
|
||||
}
|
||||
.reflink a:hover{
|
||||
font-weight: bold;
|
||||
}
|
||||
.adminbar {
|
||||
text-align:right;
|
||||
clear:both;
|
||||
float:right;
|
||||
}
|
||||
.logo {
|
||||
clear:both;
|
||||
text-align:center;
|
||||
font-size:2em;
|
||||
color:#800000;
|
||||
width:100%;
|
||||
}
|
||||
.replymode {
|
||||
background:#E04000;
|
||||
text-align:center;
|
||||
padding:2px;
|
||||
color:#FFFFFF;
|
||||
width:100%;
|
||||
}
|
||||
.catalogmode {
|
||||
background:#0040E0;
|
||||
text-align:center;
|
||||
padding:2px;
|
||||
color:#FFFFFF;
|
||||
width:100%;
|
||||
}
|
||||
.rules {
|
||||
/*font-size:0.7em;*/
|
||||
width: 468px;
|
||||
font-size: 10px;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
.rules li {
|
||||
margin-left: 1em;
|
||||
/*text-indent: 0em;*/
|
||||
}
|
||||
.postblock {
|
||||
background:#EEAA88;
|
||||
color:#800000;
|
||||
font-weight:800;
|
||||
}
|
||||
.footer {
|
||||
text-align:center;
|
||||
font-size:12px;
|
||||
font-family:serif;
|
||||
}
|
||||
.passvalid {
|
||||
background:#EEAA88;
|
||||
text-align:center;
|
||||
width:100%;
|
||||
color:#ffffff;
|
||||
}
|
||||
.dellist {
|
||||
font-weight: bold;
|
||||
text-align:center;
|
||||
}
|
||||
.delbuttons {
|
||||
text-align:center;
|
||||
padding-bottom:4px;
|
||||
|
||||
}
|
||||
.managehead {
|
||||
background:#AAAA66;
|
||||
color:#400000;
|
||||
padding:0px;
|
||||
}
|
||||
.postlists {
|
||||
background:#FFFFFF;
|
||||
width:100%;
|
||||
padding:0px;
|
||||
color:#800000;
|
||||
}
|
||||
.row1 {
|
||||
background:#EEEECC;
|
||||
color:#800000;
|
||||
}
|
||||
.row2 {
|
||||
background:#DDDDAA;
|
||||
color:#800000;
|
||||
}
|
||||
.unkfunc {
|
||||
background:inherit;
|
||||
color:#789922;
|
||||
}
|
||||
.filesize {
|
||||
text-decoration:none;
|
||||
}
|
||||
.filetitle {
|
||||
background:inherit;
|
||||
font-size:1.2em;
|
||||
color:#CC1105;
|
||||
font-weight:800;
|
||||
}
|
||||
.postername {
|
||||
color:#117743;
|
||||
font-weight:bold;
|
||||
}
|
||||
.postertrip {
|
||||
color:#228854;
|
||||
}
|
||||
.oldpost {
|
||||
color:#CC1105;
|
||||
font-weight:800;
|
||||
}
|
||||
.omittedposts {
|
||||
color:#707070;
|
||||
}
|
||||
.reply {
|
||||
background: #F0E0D6;
|
||||
color: #800000;
|
||||
}
|
||||
.replyhl {
|
||||
background: #F0C0B0;
|
||||
color: #800000;
|
||||
}
|
||||
.replytitle {
|
||||
font-size: 1.2em;
|
||||
color:#CC1105;
|
||||
font-weight:800;
|
||||
}
|
||||
.commentpostername {
|
||||
color:#117743;
|
||||
font-weight:800;
|
||||
}
|
||||
.thumbnailmsg {
|
||||
font-size: small;
|
||||
color:#800000;
|
||||
}
|
||||
|
||||
.abbrev {
|
||||
color:#707070;
|
||||
}
|
||||
.highlight {
|
||||
background:#F0E0D6;
|
||||
color:#800000;
|
||||
border: 2px dashed #EEAA88;
|
||||
}
|
83
css/global.css
Normal file
83
css/global.css
Normal file
|
@ -0,0 +1,83 @@
|
|||
body {
|
||||
margin: 0;
|
||||
padding: 8px;
|
||||
margin-bottom: auto;
|
||||
}
|
||||
|
||||
blockquote blockquote {
|
||||
margin-left: 0em;
|
||||
}
|
||||
|
||||
form {
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
.postarea {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.postarea table {
|
||||
margin: 0px auto;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.aa {
|
||||
white-space: pre;
|
||||
text-align: left;
|
||||
font-family: IPAMonaPGothic, Mona, 'MS PGothic', YOzFontAA97 !important;
|
||||
}
|
||||
|
||||
.thumb {
|
||||
border: none;
|
||||
float: left;
|
||||
margin: 2px 20px;
|
||||
}
|
||||
|
||||
.nothumb {
|
||||
float: left;
|
||||
background: #eee;
|
||||
border: 2px dashed #aaa;
|
||||
text-align: center;
|
||||
margin: 2px 20px;
|
||||
padding: 1em 0.5em 1em 0.5em;
|
||||
}
|
||||
|
||||
.reply blockquote, blockquote :last-child {
|
||||
margin-bottom: 0em;
|
||||
}
|
||||
|
||||
.reflink a {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.reflink a:hover{
|
||||
color: #800000;
|
||||
}
|
||||
|
||||
.reply .filesize {
|
||||
margin-left: 20px;
|
||||
}
|
||||
|
||||
.userdelete {
|
||||
float: right;
|
||||
text-align: center;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.doubledash {
|
||||
vertical-align: top;
|
||||
clear: both;
|
||||
float: left;
|
||||
font-size: 1.75em;
|
||||
}
|
||||
|
||||
.moderator {
|
||||
color: #FF0000;
|
||||
}
|
||||
|
||||
.managebutton {
|
||||
font-size: 15px;
|
||||
height: 28px;
|
||||
margin: 0.2em;
|
||||
}
|
BIN
favicon.ico
Normal file
BIN
favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
348
imgboard.php
Normal file
348
imgboard.php
Normal file
|
@ -0,0 +1,348 @@
|
|||
<?php
|
||||
# TinyIB
|
||||
#
|
||||
# http://tinyib.googlecode.com/
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set("display_errors", 1);
|
||||
session_start();
|
||||
|
||||
if (get_magic_quotes_gpc()) {
|
||||
foreach ($_GET as $key => $val) { $_GET[$key] = stripslashes($val); }
|
||||
foreach ($_POST as $key => $val) { $_POST[$key] = stripslashes($val); }
|
||||
}
|
||||
if (get_magic_quotes_runtime()) { set_magic_quotes_runtime(0); }
|
||||
|
||||
$tinyib = array();
|
||||
$tinyib['board'] = "b"; // Identifier for this board using only letters and numbers
|
||||
$tinyib['boarddescription'] = "TinyIB"; // Displayed in the logo area
|
||||
$tinyib['maxthreads'] = 100; // Set this to limit the number of threads allowed before discarding older threads. 0 to disable
|
||||
$tinyib['logo'] = ""; // Logo HTML
|
||||
$tinyib['tripseed'] = ""; // Text to use when generating secure tripcodes
|
||||
$tinyib['adminpassword'] = ""; // Text entered at the manage prompt to gain administrator access
|
||||
$tinyib['modpassword'] = ""; // Same as above, but only has access to delete posts. Blank ("") to disable
|
||||
$tinyib['databasemode'] = "flatfile"; // flatfile or mysql
|
||||
|
||||
// mysql settings
|
||||
$mysql_host = "localhost";
|
||||
$mysql_username = "";
|
||||
$mysql_password = "";
|
||||
$mysql_database = "";
|
||||
$mysql_posts_table = $tinyib['board'] . "_posts";
|
||||
$mysql_bans_table = "bans";
|
||||
|
||||
function fancyDie($message) {
|
||||
die('<span style="color: red;font-size: 1.5em;font-family: Helvetica;">' . $message . '</span>');
|
||||
}
|
||||
|
||||
// Check directories are writable by the script
|
||||
$writedirs = array("res", "src", "thumb");
|
||||
if ($tinyib['databasemode'] == 'flatfile') { $writedirs[] = "inc/flatfile"; }
|
||||
foreach ($writedirs as $dir) {
|
||||
if (!is_writable($dir)) {
|
||||
fancyDie("Directory '" . $dir . "' can not be written to! Please modify its permissions.");
|
||||
}
|
||||
}
|
||||
|
||||
$includes = array("inc/functions.php", "inc/html.php");
|
||||
if ($tinyib['databasemode'] == 'flatfile') {
|
||||
$includes[] = 'inc/database_flatfile.php';
|
||||
} elseif ($tinyib['databasemode'] == 'mysql') {
|
||||
$includes[] = 'inc/database_mysql.php';
|
||||
} else {
|
||||
fancyDie("Unknown database mode specificed");
|
||||
}
|
||||
|
||||
foreach ($includes as $include) {
|
||||
include $include;
|
||||
}
|
||||
|
||||
if ($tinyib['tripseed'] == '' || $tinyib['adminpassword'] == '') {
|
||||
fancyDie('$tinyib[\'tripseed\'] and $tinyib[\'adminpassword\'] still need to be configured!');
|
||||
}
|
||||
|
||||
$redirect = true;
|
||||
// Check if the request is to make a post
|
||||
if (isset($_POST["message"]) || isset($_POST["file"])) {
|
||||
$ban = banByIP($_SERVER['REMOTE_ADDR']);
|
||||
if ($ban) {
|
||||
if ($ban['expire'] == 0 || $ban['expire'] > time()) {
|
||||
$expire = ($ban['expire'] > 0) ? ('Your ban will expire ' . date('y/m/d(D)H:i:s', $ban['expire'])) : 'The ban on your IP address is permanent and will not expire.';
|
||||
$reason = ($ban['reason'] == '') ? '' : ('<br>The reason provided was: ' . $ban['reason']);
|
||||
fancyDie('Sorry, it appears that you have been banned from posting on this image board. ' . $expire . $reason);
|
||||
} else {
|
||||
clearExpiredBans();
|
||||
}
|
||||
}
|
||||
|
||||
$parent = "0";
|
||||
if (isset($_POST["parent"])) {
|
||||
if ($_POST["parent"] != "0") {
|
||||
if (!threadExistsByID($_POST['parent'])) {
|
||||
fancyDie("Invalid parent thread ID supplied, unable to create post.");
|
||||
}
|
||||
|
||||
$parent = $_POST["parent"];
|
||||
}
|
||||
}
|
||||
|
||||
$lastpost = lastPostByIP();
|
||||
if ($lastpost) {
|
||||
if ((time() - $lastpost['timestamp']) < 30) {
|
||||
fancyDie("Please wait a moment before posting again. You will be able to make another post in " . (30 - (time() - $lastpost['timestamp'])) . " seconds.");
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen($_POST["message"]) > 8000) {
|
||||
fancyDie("Please shorten your message, or post it in multiple parts. Your message is " . strlen($_POST["message"]) . " characters long, and the maximum allowed is 8000.");
|
||||
}
|
||||
|
||||
$post = newPost();
|
||||
$post['parent'] = $parent;
|
||||
$post['ip'] = $_SERVER['REMOTE_ADDR'];
|
||||
|
||||
$nt = nameAndTripcode($_POST["name"]);
|
||||
$post['name'] = $nt[0];
|
||||
$post['tripcode'] = $nt[1];
|
||||
|
||||
$post['name'] = cleanString(substr($post['name'], 0, 75));
|
||||
$post['email'] = cleanString(str_replace('"', '"', substr($_POST["email"], 0, 75)));
|
||||
$post['subject'] = cleanString(substr($_POST["subject"], 0, 75));
|
||||
$post['message'] = str_replace("\n", "<br>", colorQuote(cleanString(rtrim($_POST["message"]))));
|
||||
if ($_POST['password'] != '') { $post['password'] = md5(md5($_POST['password'])); } else { $post['password'] = ''; }
|
||||
$post['nameblock'] = nameBlock($post['name'], $post['tripcode'], $post['email'], time());
|
||||
|
||||
if (isset($_FILES['file'])) {
|
||||
if ($_FILES['file']['name'] != "") {
|
||||
switch ($_FILES['file']['error']) {
|
||||
case UPLOAD_ERR_OK:
|
||||
break;
|
||||
case UPLOAD_ERR_FORM_SIZE:
|
||||
fancyDie("That file is larger than 2 MB.");
|
||||
break;
|
||||
case UPLOAD_ERR_INI_SIZE:
|
||||
fancyDie("The uploaded file exceeds the upload_max_filesize directive (" . ini_get('upload_max_filesize') . ") in php.ini.");
|
||||
break;
|
||||
case UPLOAD_ERR_PARTIAL:
|
||||
fancyDie("The uploaded file was only partially uploaded.");
|
||||
break;
|
||||
case UPLOAD_ERR_NO_FILE:
|
||||
fancyDie("No file was uploaded.");
|
||||
break;
|
||||
case UPLOAD_ERR_NO_TMP_DIR:
|
||||
fancyDie("Missing a temporary folder.");
|
||||
break;
|
||||
case UPLOAD_ERR_CANT_WRITE:
|
||||
fancyDie("Failed to write file to disk");
|
||||
break;
|
||||
default:
|
||||
fancyDie("Unable to save the uploaded file.");
|
||||
}
|
||||
|
||||
if (!is_file($_FILES['file']['tmp_name']) || !is_readable($_FILES['file']['tmp_name'])) {
|
||||
fancyDie("File transfer failure. Please retry the submission.");
|
||||
}
|
||||
|
||||
$post['file_original'] = substr(htmlentities($_FILES['file']['name'], ENT_QUOTES), 0, 50);
|
||||
$post['file_hex'] = md5_file($_FILES['file']['tmp_name']);
|
||||
$post['file_size'] = $_FILES['file']['size'];
|
||||
$post['file_size_formatted'] = convertBytes($post['file_size']);
|
||||
$file_type = strtolower(preg_replace('/.*(\..+)/', '\1', $_FILES['file']['name'])); if ($file_type == '.jpeg') { $file_type = '.jpg'; }
|
||||
$file_name = time() . mt_rand(1, 99);
|
||||
$post['thumb'] = $file_name . "s" . $file_type;
|
||||
$post['file'] = $file_name . $file_type;
|
||||
$thumb_location = "thumb/" . $post['thumb'];
|
||||
$file_location = "src/" . $post['file'];
|
||||
|
||||
if(function_exists("mime_content_type")) {
|
||||
$file_mime = mime_content_type($_FILES['file']['tmp_name']);
|
||||
} else {
|
||||
$file_mime = "image/jpeg"; // It is highly recommended you use PHP 4.3.0 or later!
|
||||
}
|
||||
|
||||
if (($file_type == '.jpg' || $file_type == '.gif' || $file_type == '.png') && ($file_mime == "image/jpeg" || $file_mime == "image/gif" || $file_mime == "image/png")) {
|
||||
if (!@getimagesize($_FILES['file']['tmp_name'])) {
|
||||
fancyDie("Failed to read the size of the uploaded file. Please retry the submission.");
|
||||
}
|
||||
} else {
|
||||
fancyDie("Only GIF, JPG, and PNG files are allowed.");
|
||||
}
|
||||
|
||||
|
||||
$hexmatches = postsByHex($post['file_hex']);
|
||||
if (count($hexmatches) > 0) {
|
||||
foreach ($hexmatches as $hexmatch) {
|
||||
if ($hexmatch["parent"] == "0") {
|
||||
$goto = $hexmatch["id"];
|
||||
} else {
|
||||
$goto = $hexmatch["parent"];
|
||||
}
|
||||
fancyDie("Duplicate file uploaded. That file has already been posted <a href=\"res/" . $goto . ".html#" . $hexmatch["id"] . "\">here</a>.");
|
||||
}
|
||||
}
|
||||
|
||||
if (!move_uploaded_file($_FILES['file']['tmp_name'], $file_location)) {
|
||||
fancyDie("Could not copy uploaded file.");
|
||||
}
|
||||
|
||||
if ($_FILES['file']['size'] != filesize($file_location)) {
|
||||
fancyDie("File transfer failure. Please go back and try again.");
|
||||
}
|
||||
|
||||
$file_imagesize = getimagesize($file_location);
|
||||
$post['image_width'] = $file_imagesize[0];
|
||||
$post['image_height'] = $file_imagesize[1];
|
||||
|
||||
if ($post['image_width'] > 250 || $post['image_height'] > 250) {
|
||||
$width = 250;
|
||||
$height = 250;
|
||||
} else {
|
||||
$width = $post['image_width'];
|
||||
$height = $post['image_height'];
|
||||
}
|
||||
if (!createThumbnail($file_location, $thumb_location, $width, $height)) {
|
||||
fancyDie("Could not create thumbnail.");
|
||||
}
|
||||
|
||||
$thumbsize = getimagesize($thumb_location);
|
||||
$post['thumb_width'] = $thumbsize[0];
|
||||
$post['thumb_height'] = $thumbsize[1];
|
||||
}
|
||||
}
|
||||
|
||||
if ($post['file'] == '') { // No file uploaded
|
||||
if ($post['parent'] == '0') {
|
||||
fancyDie("An image is required to start a thread.");
|
||||
}
|
||||
if (str_replace('<br>', '', $post['message']) == "") {
|
||||
fancyDie("Please enter a message and/or upload an image to make a reply.");
|
||||
}
|
||||
}
|
||||
|
||||
$post['id'] = insertPost($post);
|
||||
trimThreads();
|
||||
echo 'Updating thread page...<br>';
|
||||
if ($post['parent'] != '0') {
|
||||
rebuildThread($post['parent']);
|
||||
|
||||
if (strtolower($post['email']) != "sage") {
|
||||
bumpThreadByID($post['parent']);
|
||||
}
|
||||
} else {
|
||||
rebuildThread($post['id']);
|
||||
}
|
||||
|
||||
echo 'Updating thread index...<br>';
|
||||
rebuildIndexes();
|
||||
// Check if the request is to delete a post and/or its associated image
|
||||
} elseif (isset($_GET['delete']) && !isset($_GET['manage'])) {
|
||||
if (isset($_POST['delete'])) {
|
||||
$post = postByID($_POST['delete']);
|
||||
if ($post) {
|
||||
if ($post['password'] != '' && md5(md5($_POST['password'])) == $post['password']) {
|
||||
deletePostByID($post['id']);
|
||||
if ($post['parent'] == 0) { threadUpdated($post['id']); } else { threadUpdated($post['parent']); }
|
||||
echo 'Post successfully deleted.';
|
||||
} else {
|
||||
fancyDie('Invalid password.');
|
||||
}
|
||||
} else {
|
||||
fancyDie('Sorry, an invalid post identifier was sent. Please go back, refresh the page, and try again.');
|
||||
}
|
||||
} else {
|
||||
fancyDie('Tick the box next to a post and click "Delete" to delete it.');
|
||||
}
|
||||
$redirect = false;
|
||||
// Check if the request is to access the management area
|
||||
} elseif (isset($_GET["manage"])) {
|
||||
$text = ""; $onload = ""; $navbar = " ";
|
||||
$redirect = false; $loggedin = false; $isadmin = false;
|
||||
$returnlink = basename($_SERVER['PHP_SELF']);
|
||||
|
||||
list($loggedin, $isadmin) = manageCheckLogIn();
|
||||
|
||||
if ($loggedin) {
|
||||
if ($isadmin) {
|
||||
if (isset($_GET["rebuildall"])) {
|
||||
$allthreads = allThreads();
|
||||
foreach ($allthreads as $thread) {
|
||||
rebuildThread($thread["id"]);
|
||||
}
|
||||
rebuildIndexes();
|
||||
$text .= "Rebuilt board.";
|
||||
} elseif (isset($_GET["bans"])) {
|
||||
clearExpiredBans();
|
||||
|
||||
if (isset($_POST['ip'])) {
|
||||
if ($_POST['ip'] != '') {
|
||||
$banexists = banByIP($_POST['ip']);
|
||||
if ($banexists) {
|
||||
fancyDie('Sorry, there is already a ban on record for that IP address.');
|
||||
}
|
||||
|
||||
$ban = array();
|
||||
$ban['ip'] = $_POST['ip'];
|
||||
$ban['expire'] = ($_POST['expire'] > 0) ? (time() + $_POST['expire']) : 0;
|
||||
$ban['reason'] = $_POST['reason'];
|
||||
|
||||
insertBan($ban);
|
||||
$text .= '<b>Successfully added a ban record for ' . $ban['ip'] . '</b><br>';
|
||||
}
|
||||
} elseif (isset($_GET['lift'])) {
|
||||
$ban = banByID($_GET['lift']);
|
||||
if ($ban) {
|
||||
deleteBanByID($_GET['lift']);
|
||||
$text .= '<b>Successfully lifted ban on ' . $ban['ip'] . '</b><br>';
|
||||
}
|
||||
}
|
||||
|
||||
$onload = manageOnLoad('bans');
|
||||
$text .= manageBanForm();
|
||||
$text .= manageBansTable();
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_GET["delete"])) {
|
||||
$post = postByID($_GET['delete']);
|
||||
if ($post) {
|
||||
deletePostByID($post['id']);
|
||||
rebuildIndexes();
|
||||
if ($post['parent'] > 0) {
|
||||
rebuildThread($post['parent']);
|
||||
}
|
||||
$text .= '<b>Post No.' . $post['id'] . ' successfully deleted.</b>';
|
||||
} else {
|
||||
fancyDie("Sorry, there doesn't appear to be a post with that ID.");
|
||||
}
|
||||
} elseif (isset($_GET["moderate"])) {
|
||||
if ($_GET['moderate'] > 0) {
|
||||
$post = postByID($_GET['moderate']);
|
||||
if ($post) {
|
||||
$text .= manageModeratePost($post);
|
||||
} else {
|
||||
fancyDie("Sorry, there doesn't appear to be a post with that ID.");
|
||||
}
|
||||
} else {
|
||||
$onload = manageOnLoad('moderate');
|
||||
$text .= manageModeratePostForm();
|
||||
}
|
||||
} elseif (isset($_GET["logout"])) {
|
||||
$_SESSION['tinyib'] = '';
|
||||
session_destroy();
|
||||
die('--> --> --><meta http-equiv="refresh" content="0;url=' . $returnlink . '?manage">');
|
||||
}
|
||||
} else {
|
||||
$onload = manageOnLoad('login');
|
||||
$text .= manageLogInForm();
|
||||
}
|
||||
|
||||
echo managePage($text, $onload);
|
||||
} elseif (!file_exists('index.html') || count(allThreads()) == 0) {
|
||||
rebuildIndexes();
|
||||
}
|
||||
|
||||
if ($redirect) {
|
||||
echo '--> --> --><meta http-equiv="refresh" content="0;url=index.html">';
|
||||
}
|
||||
|
||||
?>
|
29
inc/.svn/all-wcprops
Normal file
29
inc/.svn/all-wcprops
Normal file
|
@ -0,0 +1,29 @@
|
|||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 25
|
||||
/svn/!svn/ver/4/trunk/inc
|
||||
END
|
||||
database_mysql.php
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 44
|
||||
/svn/!svn/ver/9/trunk/inc/database_mysql.php
|
||||
END
|
||||
database_flatfile.php
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 47
|
||||
/svn/!svn/ver/9/trunk/inc/database_flatfile.php
|
||||
END
|
||||
html.php
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 35
|
||||
/svn/!svn/ver/10/trunk/inc/html.php
|
||||
END
|
||||
functions.php
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 40
|
||||
/svn/!svn/ver/10/trunk/inc/functions.php
|
||||
END
|
167
inc/.svn/entries
Normal file
167
inc/.svn/entries
Normal file
|
@ -0,0 +1,167 @@
|
|||
10
|
||||
|
||||
dir
|
||||
4
|
||||
https://tinyib.googlecode.com/svn/trunk/inc
|
||||
https://tinyib.googlecode.com/svn
|
||||
|
||||
|
||||
|
||||
2009-09-04T03:12:19.723445Z
|
||||
4
|
||||
tslocum
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ac9068a4-33bb-11de-8a2e-13aa1706fec1
|
||||
|
||||
database_mysql.php
|
||||
file
|
||||
9
|
||||
|
||||
|
||||
|
||||
2009-09-18T00:50:30.703125Z
|
||||
b5d356351b1fbdb2c5cbeda9241f8aa4
|
||||
2009-09-18T00:52:50.403559Z
|
||||
9
|
||||
tslocum
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
7779
|
||||
|
||||
database_flatfile.php
|
||||
file
|
||||
9
|
||||
|
||||
|
||||
|
||||
2009-09-18T00:50:36.359375Z
|
||||
cb80ffc18b07448097139faedd300a3e
|
||||
2009-09-18T00:52:50.403559Z
|
||||
9
|
||||
tslocum
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
8666
|
||||
|
||||
flatfile
|
||||
dir
|
||||
|
||||
html.php
|
||||
file
|
||||
10
|
||||
|
||||
|
||||
|
||||
2009-09-19T21:41:25.296875Z
|
||||
b555bd0497f886c2d3fedeeb1ba99680
|
||||
2009-09-19T21:48:28.690807Z
|
||||
10
|
||||
tslocum
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
14016
|
||||
|
||||
functions.php
|
||||
file
|
||||
10
|
||||
|
||||
|
||||
|
||||
2009-09-19T21:44:49.156250Z
|
||||
8fa43669064f3502daee0fed9cf209e6
|
||||
2009-09-19T21:48:28.690807Z
|
||||
10
|
||||
tslocum
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
7687
|
||||
|
254
inc/.svn/text-base/database_flatfile.php.svn-base
Normal file
254
inc/.svn/text-base/database_flatfile.php.svn-base
Normal file
|
@ -0,0 +1,254 @@
|
|||
<?php
|
||||
if (!isset($tinyib)) { die(''); }
|
||||
|
||||
# Post Structure
|
||||
define('POSTS_FILE', '.posts');
|
||||
define('POST_ID', 0);
|
||||
define('POST_PARENT', 1);
|
||||
define('POST_TIMESTAMP', 2);
|
||||
define('POST_BUMPED', 3);
|
||||
define('POST_IP', 4);
|
||||
define('POST_NAME', 5);
|
||||
define('POST_TRIPCODE', 6);
|
||||
define('POST_EMAIL', 7);
|
||||
define('POST_NAMEBLOCK', 8);
|
||||
define('POST_SUBJECT', 9);
|
||||
define('POST_MESSAGE', 10);
|
||||
define('POST_PASSWORD', 11);
|
||||
define('POST_FILE', 12);
|
||||
define('POST_FILE_HEX', 13);
|
||||
define('POST_FILE_ORIGINAL', 14);
|
||||
define('POST_FILE_SIZE', 15);
|
||||
define('POST_FILE_SIZE_FORMATTED', 16);
|
||||
define('POST_IMAGE_WIDTH', 17);
|
||||
define('POST_IMAGE_HEIGHT', 18);
|
||||
define('POST_THUMB', 19);
|
||||
define('POST_THUMB_WIDTH', 20);
|
||||
define('POST_THUMB_HEIGHT', 21);
|
||||
|
||||
# Ban Structure
|
||||
define('BANS_FILE', '.bans');
|
||||
define('BAN_ID', 0);
|
||||
define('BAN_IP', 1);
|
||||
define('BAN_TIMESTAMP', 2);
|
||||
define('BAN_EXPIRE', 3);
|
||||
define('BAN_REASON', 4);
|
||||
|
||||
require_once 'flatfile/flatfile.php';
|
||||
$db = new Flatfile();
|
||||
$db->datadir = 'inc/flatfile/';
|
||||
|
||||
# Post Functions
|
||||
function uniquePosts() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
function postByID($id) {
|
||||
return convertPostsToSQLStyle($GLOBALS['db']->selectWhere(POSTS_FILE, new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON), 1), true);
|
||||
}
|
||||
|
||||
function threadExistsByID($id) {
|
||||
$compClause = new AndWhereClause();
|
||||
$compClause->add(new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON));
|
||||
$compClause->add(new SimpleWhereClause(POST_PARENT, '=', 0, INTEGER_COMPARISON));
|
||||
|
||||
return count($GLOBALS['db']->selectWhere(POSTS_FILE, $compClause, 1)) > 0;
|
||||
}
|
||||
|
||||
function insertPost($newpost) {
|
||||
$post = array();
|
||||
$post[POST_ID] = '0';
|
||||
$post[POST_PARENT] = $newpost['parent'];
|
||||
$post[POST_TIMESTAMP] = time();
|
||||
$post[POST_BUMPED] = time();
|
||||
$post[POST_IP] = $newpost['ip'];
|
||||
$post[POST_NAME] = $newpost['name'];
|
||||
$post[POST_TRIPCODE] = $newpost['tripcode'];
|
||||
$post[POST_EMAIL] = $newpost['email'];
|
||||
$post[POST_NAMEBLOCK] = $newpost['nameblock'];
|
||||
$post[POST_SUBJECT] = $newpost['subject'];
|
||||
$post[POST_MESSAGE] = $newpost['message'];
|
||||
$post[POST_PASSWORD] = $newpost['password'];
|
||||
$post[POST_FILE] = $newpost['file'];
|
||||
$post[POST_FILE_HEX] = $newpost['file_hex'];
|
||||
$post[POST_FILE_ORIGINAL] = $newpost['file_original'];
|
||||
$post[POST_FILE_SIZE] = $newpost['file_size'];
|
||||
$post[POST_FILE_SIZE_FORMATTED] = $newpost['file_size_formatted'];
|
||||
$post[POST_IMAGE_WIDTH] = $newpost['image_width'];
|
||||
$post[POST_IMAGE_HEIGHT] = $newpost['image_height'];
|
||||
$post[POST_THUMB] = $newpost['thumb'];
|
||||
$post[POST_THUMB_WIDTH] = $newpost['thumb_width'];
|
||||
$post[POST_THUMB_HEIGHT] = $newpost['thumb_height'];
|
||||
$post[POST_THUMB_HEIGHT] = $newpost['thumb_height'];
|
||||
|
||||
return $GLOBALS['db']->insertWithAutoId(POSTS_FILE, POST_ID, $post);
|
||||
}
|
||||
|
||||
function bumpThreadByID($id) {
|
||||
$rows = $GLOBALS['db']->selectWhere(POSTS_FILE, new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON), 1);
|
||||
if (count($rows) > 0) {
|
||||
foreach ($rows as $post) {
|
||||
$post[POST_BUMPED] = time();
|
||||
$GLOBALS['db']->updateRowById(POSTS_FILE, POST_ID, $post);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function countThreads() {
|
||||
$rows = $GLOBALS['db']->selectWhere(POSTS_FILE, new SimpleWhereClause(POST_PARENT, '=', 0, INTEGER_COMPARISON));
|
||||
return count($rows);
|
||||
}
|
||||
|
||||
function convertPostsToSQLStyle($posts, $singlepost=false) {
|
||||
$newposts = array();
|
||||
foreach ($posts as $oldpost) {
|
||||
$post = newPost();
|
||||
$post['id'] = $oldpost[POST_ID];
|
||||
$post['parent'] = $oldpost[POST_PARENT];
|
||||
$post['timestamp'] = $oldpost[POST_TIMESTAMP];
|
||||
$post['bumped'] = $oldpost[POST_BUMPED];
|
||||
$post['ip'] = $oldpost[POST_IP];
|
||||
$post['name'] = $oldpost[POST_NAME];
|
||||
$post['tripcode'] = $oldpost[POST_TRIPCODE];
|
||||
$post['email'] = $oldpost[POST_EMAIL];
|
||||
$post['nameblock'] = $oldpost[POST_NAMEBLOCK];
|
||||
$post['subject'] = $oldpost[POST_SUBJECT];
|
||||
$post['message'] = $oldpost[POST_MESSAGE];
|
||||
$post['password'] = $oldpost[POST_PASSWORD];
|
||||
$post['file'] = $oldpost[POST_FILE];
|
||||
$post['file_hex'] = $oldpost[POST_FILE_HEX];
|
||||
$post['file_original'] = $oldpost[POST_FILE_ORIGINAL];
|
||||
$post['file_size'] = $oldpost[POST_FILE_SIZE];
|
||||
$post['file_size_formatted'] = $oldpost[POST_FILE_SIZE_FORMATTED];
|
||||
$post['image_width'] = $oldpost[POST_IMAGE_WIDTH];
|
||||
$post['image_height'] = $oldpost[POST_IMAGE_HEIGHT];
|
||||
$post['thumb'] = $oldpost[POST_THUMB];
|
||||
$post['thumb_width'] = $oldpost[POST_THUMB_WIDTH];
|
||||
$post['thumb_height'] = $oldpost[POST_THUMB_HEIGHT];
|
||||
|
||||
if ($post['parent'] == '') {
|
||||
$post['parent'] = '0';
|
||||
}
|
||||
|
||||
if ($singlepost) { return $post; }
|
||||
$newposts[] = $post;
|
||||
}
|
||||
return $newposts;
|
||||
}
|
||||
|
||||
function allThreads() {
|
||||
$rows = $GLOBALS['db']->selectWhere(POSTS_FILE, new SimpleWhereClause(POST_PARENT, '=', 0, INTEGER_COMPARISON), -1, new OrderBy(POST_BUMPED, DESCENDING, INTEGER_COMPARISON));
|
||||
return convertPostsToSQLStyle($rows);
|
||||
}
|
||||
|
||||
function postsInThreadByID($id) {
|
||||
$compClause = new OrWhereClause();
|
||||
$compClause->add(new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON));
|
||||
$compClause->add(new SimpleWhereClause(POST_PARENT, '=', $id, INTEGER_COMPARISON));
|
||||
|
||||
$rows = $GLOBALS['db']->selectWhere(POSTS_FILE, $compClause, -1, new OrderBy(POST_ID, ASCENDING, INTEGER_COMPARISON));
|
||||
return convertPostsToSQLStyle($rows);
|
||||
}
|
||||
|
||||
function latestRepliesInThreadByID($id) {
|
||||
$rows = $GLOBALS['db']->selectWhere(POSTS_FILE, new SimpleWhereClause(POST_PARENT, '=', $id, INTEGER_COMPARISON), 3, new OrderBy(POST_ID, DESCENDING, INTEGER_COMPARISON));
|
||||
return convertPostsToSQLStyle($rows);
|
||||
}
|
||||
|
||||
function postsByHex($hex) {
|
||||
$rows = $GLOBALS['db']->selectWhere(POSTS_FILE, new SimpleWhereClause(POST_FILE_HEX, '=', $hex, STRING_COMPARISON), 1);
|
||||
return convertPostsToSQLStyle($rows);
|
||||
}
|
||||
|
||||
function deletePostByID($id) {
|
||||
$posts = postsInThreadByID($id);
|
||||
foreach ($posts as $post) {
|
||||
if ($post['id'] != $id) {
|
||||
deletePostImages($post);
|
||||
$GLOBALS['db']->deleteWhere(POSTS_FILE, new SimpleWhereClause(POST_ID, '=', $post['id'], INTEGER_COMPARISON));
|
||||
} else {
|
||||
$thispost = $post;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($thispost)) {
|
||||
deletePostImages($thispost);
|
||||
$GLOBALS['db']->deleteWhere(POSTS_FILE, new SimpleWhereClause(POST_ID, '=', $thispost['id'], INTEGER_COMPARISON));
|
||||
}
|
||||
}
|
||||
|
||||
function trimThreads() {
|
||||
global $tinyib;
|
||||
if ($tinyib['maxthreads'] > 0) {
|
||||
$numthreads = countThreads();
|
||||
if ($numthreads > $tinyib['maxthreads']) {
|
||||
$allthreads = allThreads();
|
||||
for ($i=$tinyib['maxthreads'];$i<$numthreads;$i++) {
|
||||
deletePostByID($allthreads[$i]['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function lastPostByIP() {
|
||||
$rows = $GLOBALS['db']->selectWhere(POSTS_FILE, new SimpleWhereClause(POST_IP, '=', $_SERVER['REMOTE_ADDR'], STRING_COMPARISON), 1, new OrderBy(POST_ID, DESCENDING, INTEGER_COMPARISON));
|
||||
return convertPostsToSQLStyle($rows, true);
|
||||
}
|
||||
|
||||
# Ban Functions
|
||||
function banByID($id) {
|
||||
return convertBansToSQLStyle($GLOBALS['db']->selectWhere(BANS_FILE, new SimpleWhereClause(BAN_ID, '=', $id, INTEGER_COMPARISON), 1), true);
|
||||
}
|
||||
|
||||
function banByIP($ip) {
|
||||
return convertBansToSQLStyle($GLOBALS['db']->selectWhere(BANS_FILE, new SimpleWhereClause(BAN_IP, '=', $ip, STRING_COMPARISON), 1), true);
|
||||
}
|
||||
|
||||
function allBans() {
|
||||
$rows = $GLOBALS['db']->selectWhere(BANS_FILE, NULL, -1, new OrderBy(BAN_TIMESTAMP, DESCENDING, INTEGER_COMPARISON));
|
||||
return convertBansToSQLStyle($rows);
|
||||
}
|
||||
|
||||
function convertBansToSQLStyle($bans, $singleban=false) {
|
||||
$newbans = array();
|
||||
foreach ($bans as $oldban) {
|
||||
$ban = array();
|
||||
$ban['id'] = $oldban[BAN_ID];
|
||||
$ban['ip'] = $oldban[BAN_IP];
|
||||
$ban['timestamp'] = $oldban[BAN_TIMESTAMP];
|
||||
$ban['expire'] = $oldban[BAN_EXPIRE];
|
||||
$ban['reason'] = $oldban[BAN_REASON];
|
||||
|
||||
if ($singleban) { return $ban; }
|
||||
$newbans[] = $ban;
|
||||
}
|
||||
return $newbans;
|
||||
}
|
||||
|
||||
function insertBan($newban) {
|
||||
$ban = array();
|
||||
$ban[BAN_ID] = '0';
|
||||
$ban[BAN_IP] = $newban['ip'];
|
||||
$ban[BAN_TIMESTAMP] = time();
|
||||
$ban[BAN_EXPIRE] = $newban['expire'];
|
||||
$ban[BAN_REASON] = $newban['reason'];
|
||||
|
||||
return $GLOBALS['db']->insertWithAutoId(BANS_FILE, BAN_ID, $ban);
|
||||
}
|
||||
|
||||
function clearExpiredBans() {
|
||||
$compClause = new AndWhereClause();
|
||||
$compClause->add(new SimpleWhereClause(BAN_EXPIRE, '>', 0, INTEGER_COMPARISON));
|
||||
$compClause->add(new SimpleWhereClause(BAN_EXPIRE, '<=', time(), INTEGER_COMPARISON));
|
||||
|
||||
$bans = $GLOBALS['db']->selectWhere(BANS_FILE, $compClause, -1);
|
||||
foreach ($bans as $ban) {
|
||||
deleteBanByID($ban[BAN_ID]);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteBanByID($id) {
|
||||
$GLOBALS['db']->deleteWhere(BANS_FILE, new SimpleWhereClause(BAN_ID, '=', $id, INTEGER_COMPARISON));
|
||||
}
|
||||
|
||||
?>
|
195
inc/.svn/text-base/database_mysql.php.svn-base
Normal file
195
inc/.svn/text-base/database_mysql.php.svn-base
Normal file
|
@ -0,0 +1,195 @@
|
|||
<?php
|
||||
if (!isset($tinyib)) { die(''); }
|
||||
|
||||
$link = mysql_connect($mysql_host, $mysql_username, $mysql_password);
|
||||
if (!$link) {
|
||||
fancyDie("Could not connect to database: " . mysql_error());
|
||||
}
|
||||
$db_selected = mysql_select_db($mysql_database, $link);
|
||||
if (!$db_selected) {
|
||||
fancyDie("Could not select database: " . mysql_error());
|
||||
}
|
||||
|
||||
// Create the posts table if it does not exist
|
||||
if (mysql_num_rows(mysql_query("SHOW TABLES LIKE '" . $mysql_posts_table . "'")) == 0) {
|
||||
mysql_query("CREATE TABLE `" . $mysql_posts_table . "` (
|
||||
`id` mediumint(7) unsigned NOT NULL auto_increment,
|
||||
`parent` mediumint(7) unsigned NOT NULL,
|
||||
`timestamp` int(20) NOT NULL,
|
||||
`bumped` int(20) NOT NULL,
|
||||
`ip` varchar(15) NOT NULL,
|
||||
`name` varchar(75) NOT NULL,
|
||||
`tripcode` varchar(10) NOT NULL,
|
||||
`email` varchar(75) NOT NULL,
|
||||
`nameblock` varchar(255) NOT NULL,
|
||||
`subject` varchar(75) NOT NULL,
|
||||
`message` text NOT NULL,
|
||||
`password` varchar(255) NOT NULL,
|
||||
`file` varchar(75) NOT NULL,
|
||||
`file_hex` varchar(75) NOT NULL,
|
||||
`file_original` varchar(255) NOT NULL,
|
||||
`file_size` int(20) unsigned NOT NULL default '0',
|
||||
`file_size_formatted` varchar(75) NOT NULL,
|
||||
`image_width` smallint(5) unsigned NOT NULL default '0',
|
||||
`image_height` smallint(5) unsigned NOT NULL default '0',
|
||||
`thumb` varchar(255) NOT NULL,
|
||||
`thumb_width` smallint(5) unsigned NOT NULL default '0',
|
||||
`thumb_height` smallint(5) unsigned NOT NULL default '0',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `parent` (`parent`),
|
||||
KEY `bumped` (`bumped`)
|
||||
) ENGINE=MyISAM");
|
||||
}
|
||||
|
||||
// Create the bans table if it does not exist
|
||||
if (mysql_num_rows(mysql_query("SHOW TABLES LIKE '" . $mysql_bans_table . "'")) == 0) {
|
||||
mysql_query("CREATE TABLE `" . $mysql_bans_table . "` (
|
||||
`id` mediumint(7) unsigned NOT NULL auto_increment,
|
||||
`ip` varchar(15) NOT NULL,
|
||||
`timestamp` int(20) NOT NULL,
|
||||
`expire` int(20) NOT NULL,
|
||||
`reason` text NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `ip` (`ip`)
|
||||
) ENGINE=MyISAM");
|
||||
}
|
||||
|
||||
# Post Functions
|
||||
function uniquePosts() {
|
||||
$row = mysql_fetch_row(mysql_query("SELECT COUNT(DISTINCT(`ip`)) FROM " . $GLOBALS['mysql_posts_table']));
|
||||
return $row[0];
|
||||
}
|
||||
|
||||
function postByID($id) {
|
||||
$result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `id` = '" . mysql_real_escape_string($id) . "' LIMIT 1");
|
||||
while ($post = mysql_fetch_assoc($result)) {
|
||||
return $post;
|
||||
}
|
||||
}
|
||||
|
||||
function threadExistsByID($id) {
|
||||
return mysql_result(mysql_query("SELECT COUNT(*) FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `id` = '" . mysql_real_escape_string($id) . "' AND `parent` = 0 LIMIT 1"), 0, 0) > 0;
|
||||
}
|
||||
|
||||
function insertPost($post) {
|
||||
mysql_query("INSERT INTO `" . $GLOBALS['mysql_posts_table'] . "` (`parent`, `timestamp`, `bumped`, `ip`, `name`, `tripcode`, `email`, `nameblock`, `subject`, `message`, `password`, `file`, `file_hex`, `file_original`, `file_size`, `file_size_formatted`, `image_width`, `image_height`, `thumb`, `thumb_width`, `thumb_height`) VALUES (" . $post['parent'] . ", " . time() . ", " . time() . ", '" . $_SERVER['REMOTE_ADDR'] . "', '" . mysql_real_escape_string($post['name']) . "', '" . mysql_real_escape_string($post['tripcode']) . "', '" . mysql_real_escape_string($post['email']) . "', '" . mysql_real_escape_string($post['nameblock']) . "', '" . mysql_real_escape_string($post['subject']) . "', '" . mysql_real_escape_string($post['message']) . "', '" . mysql_real_escape_string($post['password']) . "', '" . $post['file'] . "', '" . $post['file_hex'] . "', '" . mysql_real_escape_string($post['file_original']) . "', " . $post['file_size'] . ", '" . $post['file_size_formatted'] . "', " . $post['image_width'] . ", " . $post['image_height'] . ", '" . $post['thumb'] . "', " . $post['thumb_width'] . ", " . $post['thumb_height'] . ")");
|
||||
return mysql_insert_id();
|
||||
}
|
||||
|
||||
function bumpThreadByID($id) {
|
||||
mysql_query("UPDATE `" . $GLOBALS['mysql_posts_table'] . "` SET `bumped` = " . time() . " WHERE `id` = " . $id . " LIMIT 1");
|
||||
}
|
||||
|
||||
function countThreads() {
|
||||
return mysql_result(mysql_query("SELECT COUNT(*) FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `parent` = 0"), 0, 0);
|
||||
}
|
||||
|
||||
function allThreads() {
|
||||
$threads = array();
|
||||
$result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `parent` = 0 ORDER BY `bumped` DESC");
|
||||
while ($thread = mysql_fetch_assoc($result)) {
|
||||
$threads[] = $thread;
|
||||
}
|
||||
return $threads;
|
||||
}
|
||||
|
||||
function postsInThreadByID($id) {
|
||||
$posts = array();
|
||||
$result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `id` = " . $id . " OR `parent` = " . $id . " ORDER BY `id` ASC");
|
||||
while ($post = mysql_fetch_assoc($result)) {
|
||||
$posts[] = $post;
|
||||
}
|
||||
return $posts;
|
||||
}
|
||||
|
||||
function latestRepliesInThreadByID($id) {
|
||||
$posts = array();
|
||||
$replies = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `parent` = " . $id . " ORDER BY `id` DESC LIMIT 3");
|
||||
while ($post = mysql_fetch_assoc($replies)) {
|
||||
$posts[] = $post;
|
||||
}
|
||||
return $posts;
|
||||
}
|
||||
|
||||
function postsByHex($hex) {
|
||||
$posts = array();
|
||||
$result = mysql_query("SELECT `id`, `parent` FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `file_hex` = '" . mysql_real_escape_string($hex) . "' LIMIT 1");
|
||||
while ($post = mysql_fetch_assoc($result)) {
|
||||
$posts[] = $post;
|
||||
}
|
||||
return $posts;
|
||||
}
|
||||
|
||||
function deletePostByID($id) {
|
||||
$posts = postsInThreadByID($id);
|
||||
foreach ($posts as $post) {
|
||||
if ($post['id'] != $id) {
|
||||
deletePostImages($post);
|
||||
mysql_query("DELETE FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `id` = " . $post['id'] . " LIMIT 1");
|
||||
} else {
|
||||
$thispost = $post;
|
||||
}
|
||||
} if (isset($thispost)) {
|
||||
deletePostImages($thispost);
|
||||
mysql_query("DELETE FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `id` = " . $thispost['id'] . " LIMIT 1");
|
||||
}
|
||||
}
|
||||
|
||||
function trimThreads() {
|
||||
global $tinyib;
|
||||
if ($tinyib['maxthreads'] > 0) {
|
||||
$result = mysql_query("SELECT `id` FROM `b_posts` WHERE `parent` = 0 ORDER BY `bumped` DESC LIMIT " . $tinyib['maxthreads']. ", 10");
|
||||
while ($post = mysql_fetch_assoc($result)) {
|
||||
deletePostByID($post['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function lastPostByIP() {
|
||||
$replies = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `ip` = '" . $_SERVER['REMOTE_ADDR'] . "' ORDER BY `id` DESC LIMIT 1");
|
||||
while ($post = mysql_fetch_assoc($replies)) {
|
||||
return $post;
|
||||
}
|
||||
}
|
||||
|
||||
# Ban Functions
|
||||
function banByID($id) {
|
||||
$result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_bans_table'] . "` WHERE `id` = '" . mysql_real_escape_string($id) . "' LIMIT 1");
|
||||
while ($ban = mysql_fetch_assoc($result)) {
|
||||
return $ban;
|
||||
}
|
||||
}
|
||||
|
||||
function banByIP($ip) {
|
||||
$result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_bans_table'] . "` WHERE `ip` = '" . mysql_real_escape_string($ip) . "' LIMIT 1");
|
||||
while ($ban = mysql_fetch_assoc($result)) {
|
||||
return $ban;
|
||||
}
|
||||
}
|
||||
|
||||
function allBans() {
|
||||
$bans = array();
|
||||
$result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_bans_table'] . "` ORDER BY `timestamp` DESC");
|
||||
while ($ban = mysql_fetch_assoc($result)) {
|
||||
$bans[] = $ban;
|
||||
}
|
||||
return $bans;
|
||||
}
|
||||
|
||||
function insertBan($ban) {
|
||||
mysql_query("INSERT INTO `" . $GLOBALS['mysql_bans_table'] . "` (`ip`, `timestamp`, `expire`, `reason`) VALUES ('" . mysql_real_escape_string($ban['ip']) . "', " . time() . ", '" . mysql_real_escape_string($ban['expire']) . "', '" . mysql_real_escape_string($ban['reason']) . "')");
|
||||
return mysql_insert_id();
|
||||
}
|
||||
|
||||
function clearExpiredBans() {
|
||||
$result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_bans_table'] . "` WHERE `expire` > 0 AND `expire` <= " . time());
|
||||
while ($ban = mysql_fetch_assoc($result)) {
|
||||
mysql_query("DELETE FROM `" . $GLOBALS['mysql_bans_table'] . "` WHERE `id` = " . $ban['id'] . " LIMIT 1");
|
||||
}
|
||||
}
|
||||
|
||||
function deleteBanByID($id) {
|
||||
mysql_query("DELETE FROM `" . $GLOBALS['mysql_bans_table'] . "` WHERE `id` = " . mysql_real_escape_string($id) . " LIMIT 1");
|
||||
}
|
||||
|
||||
?>
|
262
inc/.svn/text-base/functions.php.svn-base
Normal file
262
inc/.svn/text-base/functions.php.svn-base
Normal file
|
@ -0,0 +1,262 @@
|
|||
<?php
|
||||
if (!isset($tinyib)) { die(''); }
|
||||
|
||||
function cleanString($string) {
|
||||
$search = array("<", ">");
|
||||
$replace = array("<", ">");
|
||||
|
||||
return str_replace($search, $replace, $string);
|
||||
}
|
||||
|
||||
function threadUpdated($id) {
|
||||
rebuildThread($id);
|
||||
rebuildIndexes();
|
||||
}
|
||||
|
||||
function newPost() {
|
||||
return array('parent' => '0',
|
||||
'timestamp' => '0',
|
||||
'bumped' => '0',
|
||||
'ip' => '',
|
||||
'name' => '',
|
||||
'tripcode' => '',
|
||||
'email' => '',
|
||||
'nameblock' => '',
|
||||
'subject' => '',
|
||||
'message' => '',
|
||||
'password' => '',
|
||||
'file' => '',
|
||||
'file_hex' => '',
|
||||
'file_original' => '',
|
||||
'file_size' => '0',
|
||||
'file_size_formatted' => '',
|
||||
'image_width' => '0',
|
||||
'image_height' => '0',
|
||||
'thumb' => '',
|
||||
'thumb_width' => '0',
|
||||
'thumb_height' => '0');
|
||||
}
|
||||
|
||||
function convertBytes($number) {
|
||||
$len = strlen($number);
|
||||
if ($len < 4) {
|
||||
return sprintf("%dB", $number);
|
||||
} elseif ($len <= 6) {
|
||||
return sprintf("%0.2fKB", $number/1024);
|
||||
} elseif ($len <= 9) {
|
||||
return sprintf("%0.2fMB", $number/1024/1024);
|
||||
}
|
||||
|
||||
return sprintf("%0.2fGB", $number/1024/1024/1024);
|
||||
}
|
||||
|
||||
function nameAndTripcode($name) {
|
||||
global $tinyib;
|
||||
|
||||
if (ereg("(#|!)(.*)", $name, $regs)) {
|
||||
$cap = $regs[2];
|
||||
$cap_full = '#' . $regs[2];
|
||||
|
||||
if (function_exists('mb_convert_encoding')) {
|
||||
$recoded_cap = mb_convert_encoding($cap, 'SJIS', 'UTF-8');
|
||||
if ($recoded_cap != '') {
|
||||
$cap = $recoded_cap;
|
||||
}
|
||||
}
|
||||
|
||||
if (strpos($name, '#') === false) {
|
||||
$cap_delimiter = '!';
|
||||
} elseif (strpos($name, '!') === false) {
|
||||
$cap_delimiter = '#';
|
||||
} else {
|
||||
$cap_delimiter = (strpos($name, '#') < strpos($name, '!')) ? '#' : '!';
|
||||
}
|
||||
|
||||
if (ereg("(.*)(" . $cap_delimiter . ")(.*)", $cap, $regs_secure)) {
|
||||
$cap = $regs_secure[1];
|
||||
$cap_secure = $regs_secure[3];
|
||||
$is_secure_trip = true;
|
||||
} else {
|
||||
$is_secure_trip = false;
|
||||
}
|
||||
|
||||
$tripcode = "";
|
||||
if ($cap != "") {
|
||||
/* From Futabally */
|
||||
$cap = strtr($cap, "&", "&");
|
||||
$cap = strtr($cap, ",", ", ");
|
||||
$salt = substr($cap."H.", 1, 2);
|
||||
$salt = ereg_replace("[^\.-z]", ".", $salt);
|
||||
$salt = strtr($salt, ":;<=>?@[\\]^_`", "ABCDEFGabcdef");
|
||||
$tripcode = substr(crypt($cap, $salt), -10);
|
||||
}
|
||||
|
||||
if ($is_secure_trip) {
|
||||
if ($cap != "") {
|
||||
$tripcode .= "!";
|
||||
}
|
||||
|
||||
$tripcode .= "!" . substr(md5($cap_secure . $tinyib['tripcodeseed']), 2, 10);
|
||||
}
|
||||
|
||||
return array(ereg_replace("(" . $cap_delimiter . ")(.*)", "", $name), $tripcode);
|
||||
}
|
||||
|
||||
return array($name, "");
|
||||
}
|
||||
|
||||
function nameBlock($name, $tripcode, $email, $timestamp) {
|
||||
$output = "";
|
||||
|
||||
if ($name == "" && $tripcode == "") {
|
||||
$output .= "Anonymous";
|
||||
} else {
|
||||
$output .= $name;
|
||||
}
|
||||
|
||||
if ($tripcode != "") {
|
||||
$output .= '</span><span class="postertrip">!' . $tripcode;
|
||||
}
|
||||
|
||||
if ($email != "") {
|
||||
$output = '<a href="mailto:' . $email . '">' . $output . '</a>';
|
||||
}
|
||||
|
||||
return '<span class="postername">' . $output . '</span> ' . date('y/m/d(D)H:i:s', $timestamp);
|
||||
}
|
||||
|
||||
function writePage($filename, $contents) {
|
||||
global $tinyib;
|
||||
|
||||
$tempfile = tempnam('res/', $tinyib['board'] . 'tmp'); /* Create the temporary file */
|
||||
$fp = fopen($tempfile, 'w');
|
||||
fwrite($fp, $contents);
|
||||
fclose($fp);
|
||||
/* If we aren't able to use the rename function, try the alternate method */
|
||||
if (!@rename($tempfile, $filename)) {
|
||||
copy($tempfile, $filename);
|
||||
unlink($tempfile);
|
||||
}
|
||||
|
||||
chmod($filename, 0664); /* it was created 0600 */
|
||||
}
|
||||
|
||||
function fixLinksInRes($html) {
|
||||
$search = array(' href="css/', ' href="src/', ' href="thumb/', ' href="res/', ' href="imgboard.php', ' href="favicon.ico', 'src="thumb/', ' action="imgboard.php');
|
||||
$replace = array(' href="../css/', ' href="../src/', ' href="../thumb/', ' href="../res/', ' href="../imgboard.php', ' href="../favicon.ico', 'src="../thumb/', ' action="../imgboard.php');
|
||||
|
||||
return str_replace($search, $replace, $html);
|
||||
}
|
||||
|
||||
function colorQuote($message) {
|
||||
if (substr($message, -1, 1) != "\n") { $message .= "\n"; }
|
||||
return preg_replace('/^(>[^\>](.*))\n/m', '<span class="unkfunc">\\1</span>' . "\n", $message);
|
||||
}
|
||||
|
||||
function deletePostImages($post) {
|
||||
if ($post['file'] != '') { @unlink('src/' . $post['file']); }
|
||||
if ($post['thumb'] != '') { @unlink('thumb/' . $post['thumb']); }
|
||||
}
|
||||
|
||||
function manageCheckLogIn() {
|
||||
global $tinyib;
|
||||
$loggedin = false; $isadmin = false;
|
||||
if (isset($_POST['password'])) {
|
||||
if ($_POST['password'] == $tinyib['adminpassword']) {
|
||||
$_SESSION['tinyib'] = $tinyib['adminpassword'];
|
||||
} elseif ($tinyib['modpassword'] != '' && $_POST['password'] == $tinyib['modpassword']) {
|
||||
$_SESSION['tinyib'] = $tinyib['modpassword'];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_SESSION['tinyib'])) {
|
||||
if ($_SESSION['tinyib'] == $tinyib['adminpassword']) {
|
||||
$loggedin = true;
|
||||
$isadmin = true;
|
||||
} elseif ($tinyib['modpassword'] != '' && $_SESSION['tinyib'] == $tinyib['modpassword']) {
|
||||
$loggedin = true;
|
||||
}
|
||||
}
|
||||
|
||||
return array($loggedin, $isadmin);
|
||||
}
|
||||
|
||||
function createThumbnail($name, $filename, $new_w, $new_h) {
|
||||
$system=explode(".", $filename);
|
||||
$system = array_reverse($system);
|
||||
if (preg_match("/jpg|jpeg/", $system[0])) {
|
||||
$src_img=imagecreatefromjpeg($name);
|
||||
} else if (preg_match("/png/", $system[0])) {
|
||||
$src_img=imagecreatefrompng($name);
|
||||
} else if (preg_match("/gif/", $system[0])) {
|
||||
$src_img=imagecreatefromgif($name);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$src_img) {
|
||||
fancyDie("Unable to read uploaded file during thumbnailing. A common cause for this is an incorrect extension when the file is actually of a different type.");
|
||||
}
|
||||
$old_x = imageSX($src_img);
|
||||
$old_y = imageSY($src_img);
|
||||
if ($old_x > $old_y) {
|
||||
$percent = $new_w / $old_x;
|
||||
} else {
|
||||
$percent = $new_h / $old_y;
|
||||
}
|
||||
$thumb_w = round($old_x * $percent);
|
||||
$thumb_h = round($old_y * $percent);
|
||||
|
||||
$dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
|
||||
fastImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
|
||||
|
||||
if (preg_match("/png/", $system[0])) {
|
||||
if (!imagepng($dst_img, $filename)) {
|
||||
return false;
|
||||
}
|
||||
} else if (preg_match("/jpg|jpeg/", $system[0])) {
|
||||
if (!imagejpeg($dst_img, $filename, 70)) {
|
||||
return false;
|
||||
}
|
||||
} else if (preg_match("/gif/", $system[0])) {
|
||||
if (!imagegif($dst_img, $filename)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
imagedestroy($dst_img);
|
||||
imagedestroy($src_img);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function fastImageCopyResampled(&$dst_image, &$src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3) {
|
||||
//Author: Tim Eckel - Date: 12/17/04 - Project: FreeRingers.net - Freely distributable.
|
||||
if (empty($src_image) || empty($dst_image)) { return false; }
|
||||
|
||||
if ($quality <= 1) {
|
||||
$temp = imagecreatetruecolor ($dst_w + 1, $dst_h + 1);
|
||||
imagecopyresized ($temp, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h);
|
||||
imagecopyresized ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h);
|
||||
imagedestroy ($temp);
|
||||
} elseif ($quality < 5 && (($dst_w * $quality) < $src_w || ($dst_h * $quality) < $src_h)) {
|
||||
|
||||
$tmp_w = $dst_w * $quality;
|
||||
$tmp_h = $dst_h * $quality;
|
||||
$temp = imagecreatetruecolor ($tmp_w + 1, $tmp_h + 1);
|
||||
|
||||
imagecopyresized ($temp, $src_image, $dst_x * $quality, $dst_y * $quality, $src_x, $src_y, $tmp_w + 1, $tmp_h + 1, $src_w, $src_h);
|
||||
|
||||
imagecopyresampled ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h);
|
||||
|
||||
imagedestroy ($temp);
|
||||
|
||||
} else {
|
||||
imagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
?>
|
461
inc/.svn/text-base/html.php.svn-base
Normal file
461
inc/.svn/text-base/html.php.svn-base
Normal file
|
@ -0,0 +1,461 @@
|
|||
<?php
|
||||
if (!isset($tinyib)) { die(''); }
|
||||
|
||||
function buildPost($post, $isrespage) {
|
||||
$return = "";
|
||||
$threadid = ($post['parent'] == 0) ? $post['id'] : $post['parent'];
|
||||
$postlink = ($isrespage) ? ($threadid . '.html#' . $post['id']) : ('res/' . $threadid . '.html#' . $post['id']);
|
||||
|
||||
if ($post["parent"] != 0) {
|
||||
$return .= <<<EOF
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="doubledash">
|
||||
¨
|
||||
</td>
|
||||
<td class="reply" id="reply${post["id"]}">
|
||||
EOF;
|
||||
} elseif ($post["file"] != "") {
|
||||
$return .= <<<EOF
|
||||
<span class="filesize">File: <a href="src/${post["file"]}">${post["file"]}</a>–(${post["file_size_formatted"]}, ${post["image_width"]}x${post["image_height"]}, ${post["file_original"]})</span>
|
||||
<br>
|
||||
<a target="_blank" href="src/${post["file"]}">
|
||||
<span id="thumb${post['id']}"><img src="thumb/${post["thumb"]}" alt="${post["id"]}" class="thumb" width="${post["thumb_width"]}" height="${post["thumb_height"]}"></span>
|
||||
</a>
|
||||
EOF;
|
||||
}
|
||||
|
||||
$return .= <<<EOF
|
||||
<a name="${post['id']}"></a>
|
||||
<label>
|
||||
<input type="checkbox" name="delete" value="${post['id']}">
|
||||
EOF;
|
||||
|
||||
if ($post["subject"] != "") {
|
||||
$return .= " <span class=\"filetitle\">${post["subject"]}</span> ";
|
||||
}
|
||||
|
||||
$return .= <<<EOF
|
||||
${post["nameblock"]}
|
||||
</label>
|
||||
<span class="reflink">
|
||||
<a href="$postlink">No.${post["id"]}</a>
|
||||
</span>
|
||||
EOF;
|
||||
|
||||
if ($post['parent'] != 0 && $post["file"] != "") {
|
||||
$return .= <<<EOF
|
||||
<br>
|
||||
<span class="filesize"><a href="src/${post["file"]}">${post["file"]}</a>–(${post["file_size_formatted"]}, ${post["image_width"]}x${post["image_height"]}, ${post["file_original"]})</span>
|
||||
<br>
|
||||
<a target="_blank" href="src/${post["file"]}">
|
||||
<span id="thumb${post["id"]}"><img src="thumb/${post["thumb"]}" alt="${post["id"]}" class="thumb" width="${post["thumb_width"]}" height="${post["thumb_height"]}"></span>
|
||||
</a>
|
||||
EOF;
|
||||
}
|
||||
|
||||
if ($post['parent'] == 0 && !$isrespage) {
|
||||
$return .= " [<a href=\"res/${post["id"]}.html\">Reply</a>]";
|
||||
}
|
||||
|
||||
$return .= <<<EOF
|
||||
<blockquote>
|
||||
${post["message"]}
|
||||
</blockquote>
|
||||
EOF;
|
||||
|
||||
if ($post['parent'] == 0) {
|
||||
if (!$isrespage && $post["omitted"] > 0) {
|
||||
$return .= '<span class="omittedposts">' . $post['omitted'] . ' post';
|
||||
if ($post["omitted"] != "1") {
|
||||
$return .= "s";
|
||||
}
|
||||
$return .= ' omitted. Click Reply to view.</span>';
|
||||
}
|
||||
} else {
|
||||
$return .= <<<EOF
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
EOF;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
function buildPage($htmlposts, $parent, $pages=-1, $thispage=0) {
|
||||
global $tinyib;
|
||||
$managelink = basename($_SERVER['PHP_SELF']) . "?manage";
|
||||
|
||||
$postingmode = "";
|
||||
$pagenavigator = "";
|
||||
if ($parent == 0) {
|
||||
$previous = ($thispage == 1) ? "index" : $thispage - 1;
|
||||
$next = $thispage + 1;
|
||||
|
||||
$pagelinks = ($thispage == 0) ? "<td>Previous</td>" : '<td><form method="get" action="' . $previous . '.html"><input value="Previous" type="submit"></form></td>';
|
||||
|
||||
$pagelinks .= "<td>";
|
||||
for ($i = 0;$i <= $pages;$i++) {
|
||||
if ($thispage == $i) {
|
||||
$pagelinks .= '[' . $i . '] ';
|
||||
} else {
|
||||
$href = ($i == 0) ? "index" : $i;
|
||||
$pagelinks .= '[<a href="' . $href . '.html">' . $i . '</a>] ';
|
||||
}
|
||||
}
|
||||
$pagelinks .= "</td>";
|
||||
|
||||
$pagelinks .= ($pages <= $thispage) ? "<td>Next</td>" : '<td><form method="get" action="' . $next . '.html"><input value="Next" type="submit"></form></td>';
|
||||
|
||||
$pagenavigator = <<<EOF
|
||||
<table border="1">
|
||||
<tbody>
|
||||
<tr>
|
||||
$pagelinks
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
EOF;
|
||||
} else {
|
||||
$postingmode = '[<a href="../">Return</a>]<div class="replymode">Posting mode: Reply</div> ';
|
||||
}
|
||||
|
||||
$unique_posts_html = '';
|
||||
$unique_posts = uniquePosts();
|
||||
if ($unique_posts > 0) {
|
||||
$unique_posts_html = "<li>Currently $unique_posts unique user posts.</li>";
|
||||
}
|
||||
|
||||
return <<<EOF
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>
|
||||
${tinyib['boarddescription']}
|
||||
</title>
|
||||
<link rel="shortcut icon" href="favicon.ico">
|
||||
<link rel="stylesheet" type="text/css" href="css/global.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/futaba.css" title="Futaba">
|
||||
<link rel="alternate stylesheet" type="text/css" href="css/burichan.css" title="Burichan">
|
||||
<meta http-equiv="pragma" content="no-cache">
|
||||
<meta http-equiv="expires" content="-1">
|
||||
</head>
|
||||
<body>
|
||||
<div class="adminbar">
|
||||
[<a href="$managelink">Manage</a>]
|
||||
</div>
|
||||
<div class="logo">
|
||||
${tinyib['logo']}
|
||||
${tinyib['boarddescription']}
|
||||
</div>
|
||||
<hr width="90%" size="1">
|
||||
$postingmode
|
||||
<div class="postarea">
|
||||
<form name="postform" id="postform" action="imgboard.php" method="post" enctype="multipart/form-data">
|
||||
<input type="hidden" name="MAX_FILE_SIZE" value="2097152">
|
||||
<input type="hidden" name="parent" value="$parent">
|
||||
<table class="postform">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="postblock">
|
||||
Name
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="name" size="28" maxlength="75" accesskey="n">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="postblock">
|
||||
E-mail
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="email" size="28" maxlength="75" accesskey="e">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="postblock">
|
||||
Subject
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="subject" size="40" maxlength="75" accesskey="s">
|
||||
<input type="submit" value="Submit" accesskey="z">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="postblock">
|
||||
Message
|
||||
</td>
|
||||
<td>
|
||||
<textarea name="message" cols="48" rows="4" accesskey="m"></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="postblock">
|
||||
File
|
||||
</td>
|
||||
<td>
|
||||
<input type="file" name="file" size="35" accesskey="f">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="postblock">
|
||||
Password
|
||||
</td>
|
||||
<td>
|
||||
<input type="password" name="password" size="8" accesskey="p"> (for post and file deletion)
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" class="rules">
|
||||
<ul style="margin-left: 0; margin-top: 0; margin-bottom: 0; padding-left: 0;">
|
||||
<li>Supported file types are: GIF, JPG, PNG</li>
|
||||
<li>Maximum file size allowed is 2 MB.</li>
|
||||
<li>Images greater than 250x250 pixels will be thumbnailed.</li>
|
||||
$unique_posts_html
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
<hr>
|
||||
<form id="delform" action="imgboard.php?delete" method="post">
|
||||
<input type="hidden" name="board" value="${tinyib['board']}">
|
||||
$htmlposts
|
||||
<table class="userdelete">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
Delete Post<br>Password <input type="password" name="password" size="8"> <input name="deletepost" value="Delete" type="submit">
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
$pagenavigator
|
||||
<br>
|
||||
<div class="footer" style="clear: both;">
|
||||
- <a href="http://www.2chan.net" target="_top">futaba</a> + <a href="http://www.1chan.net" target="_top">futallaby</a> + <a href="http://code.google.com/p/tinyib/" target="_top">tinyib</a> -
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
EOF;
|
||||
}
|
||||
|
||||
function rebuildIndexes() {
|
||||
global $mysql_posts_table;
|
||||
|
||||
$htmlposts = "";
|
||||
$page = 0;
|
||||
$i = 0;
|
||||
$pages = ceil(countThreads() / 10) - 1;
|
||||
$threads = allThreads();
|
||||
foreach ($threads as $thread) {
|
||||
$htmlreplies = array();
|
||||
$replies = latestRepliesInThreadByID($thread['id']);
|
||||
foreach ($replies as $reply) {
|
||||
$htmlreplies[] = buildPost($reply, False);
|
||||
}
|
||||
if (count($htmlreplies) == 3) {
|
||||
$thread["omitted"] = (count(postsInThreadByID($thread['id'])) - 4);
|
||||
} else {
|
||||
$thread["omitted"] = 0;
|
||||
}
|
||||
|
||||
$htmlposts .= buildPost($thread, False);
|
||||
|
||||
$htmlposts .= implode("", array_reverse($htmlreplies));
|
||||
|
||||
$htmlposts .= "<br clear=\"left\">\n" .
|
||||
"<hr>";
|
||||
$i += 1;
|
||||
if ($i == 10) {
|
||||
$file = ($page == 0) ? "index.html" : $page . ".html";
|
||||
writePage($file, buildPage($htmlposts, 0, $pages, $page));
|
||||
|
||||
$page += 1;
|
||||
$i = 0;
|
||||
$htmlposts = "";
|
||||
}
|
||||
}
|
||||
|
||||
if ($page == 0 || $htmlposts != "") {
|
||||
$file = ($page == 0) ? "index.html" : $page . ".html";
|
||||
writePage($file, buildPage($htmlposts, 0, $pages, $page));
|
||||
}
|
||||
}
|
||||
|
||||
function rebuildThread($id) {
|
||||
global $mysql_posts_table;
|
||||
|
||||
$htmlposts = "";
|
||||
$posts = postsInThreadByID($id);
|
||||
foreach ($posts as $post) {
|
||||
$htmlposts .= buildPost($post, True);
|
||||
}
|
||||
|
||||
$htmlposts .= "<br clear=\"left\">\n" .
|
||||
"<hr>";
|
||||
|
||||
writePage("res/" . $id . ".html", fixLinksInRes(buildPage($htmlposts, $id)));
|
||||
}
|
||||
|
||||
function manageNavBar() {
|
||||
global $loggedin, $isadmin;
|
||||
if (!$loggedin) { return ''; }
|
||||
$text = '';
|
||||
$text .= ($isadmin) ? '<a href="?manage&bans">bans</a> · ' : '';
|
||||
$text .= '<a href="?manage&moderate">moderate post</a> · ';
|
||||
$text .= ($isadmin) ? '<a href="?manage&rebuildall">rebuild all</a> · ' : '';
|
||||
$text .= '<a href="?manage&logout">log out</a>';
|
||||
return $text;
|
||||
}
|
||||
|
||||
function managePage($text, $onload='') {
|
||||
global $tinyib, $returnlink;
|
||||
|
||||
$navbar = manageNavBar();
|
||||
return <<<EOF
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>
|
||||
${tinyib['boarddescription']}
|
||||
</title>
|
||||
<meta http-equiv="pragma" content="no-cache">
|
||||
<meta http-equiv="expires" content="-1">
|
||||
<link rel="shortcut icon" href="favicon.ico">
|
||||
<link rel="stylesheet" type="text/css" href="css/global.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/futaba.css" title="Futaba">
|
||||
<link rel="alternate stylesheet" type="text/css" href="css/burichan.css" title="Burichan">
|
||||
</head>
|
||||
<body$onload>
|
||||
<div class="adminbar">
|
||||
[<a href="$returnlink">Return</a>]
|
||||
</div>
|
||||
<div class="logo">
|
||||
${tinyib['logo']}
|
||||
${tinyib['boarddescription']}
|
||||
</div>
|
||||
<hr width="90%" size="1">
|
||||
<div class="replymode">Manage mode</div>
|
||||
<div style="text-align: center;font-size: small;">$navbar</div>
|
||||
$text
|
||||
<hr>
|
||||
<div class="footer" style="clear: both;">
|
||||
- <a href="http://www.2chan.net" target="_top">futaba</a> + <a href="http://www.1chan.net" target="_top">futallaby</a> + <a href="http://code.google.com/p/tinyib/" target="_top">tinyib</a> -
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
EOF;
|
||||
}
|
||||
|
||||
function manageOnLoad($page) {
|
||||
switch ($page) {
|
||||
case 'login':
|
||||
return ' onload="document.tinyib.password.focus();"';
|
||||
case 'moderate':
|
||||
return ' onload="document.tinyib.moderate.focus();"';
|
||||
case 'bans':
|
||||
return ' onload="document.tinyib.ip.focus();"';
|
||||
}
|
||||
}
|
||||
|
||||
function manageLogInForm() {
|
||||
return <<<EOF
|
||||
<form id="tinyib" name="tinyib" method="post" action="?manage">
|
||||
<fieldset>
|
||||
<legend align="center">Please enter an administrator or moderator password</legend>
|
||||
<div style="text-align: center;">
|
||||
<input type="password" id="password" name="password"><br>
|
||||
<input type="submit" value="Submit" class="managebutton">
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
<br>
|
||||
EOF;
|
||||
}
|
||||
|
||||
function manageBanForm() {
|
||||
return <<<EOF
|
||||
<form id="tinyib" name="tinyib" method="post" action="?manage&bans">
|
||||
<fieldset>
|
||||
<legend>Ban an IP address from posting</legend>
|
||||
<label for="ip">IP Address:</label> <input type="text" name="ip" id="ip" value="${_GET['bans']}"> <input type="submit" value="Submit" class="managebutton"><br>
|
||||
<label for="expire">Expire(sec):</label> <input type="text" name="expire" id="expire" value="0"> <small><a href="#" onclick="document.tinyib.expire.value='3600';return false;">1hr</a> <a href="#" onclick="document.tinyib.expire.value='86400';return false;">1d</a> <a href="#" onclick="document.tinyib.expire.value='172800';return false;">2d</a> <a href="#" onclick="document.tinyib.expire.value='604800';return false;">1w</a> <a href="#" onclick="document.tinyib.expire.value='1209600';return false;">2w</a> <a href="#" onclick="document.tinyib.expire.value='2592000';return false;">30d</a> <a href="#" onclick="document.tinyib.expire.value='0';return false;">never</a></small><br>
|
||||
<label for="reason">Reason: </label> <input type="text" name="reason" id="reason"> <small>(optional)</small>
|
||||
<legend>
|
||||
</fieldset>
|
||||
</form><br>
|
||||
EOF;
|
||||
}
|
||||
|
||||
function manageBansTable() {
|
||||
$text = '';
|
||||
$allbans = allBans();
|
||||
if (count($allbans) > 0) {
|
||||
$text .= '<table border="1"><tr><th>IP Address</th><th>Set At</th><th>Expires</th><th>Reason Provided</th><th> </th></tr>';
|
||||
foreach ($allbans as $ban) {
|
||||
$expire = ($ban['expire'] > 0) ? date('y/m/d(D)H:i:s', $ban['expire']) : 'Never';
|
||||
$reason = ($ban['reason'] == '') ? ' ' : htmlentities($ban['reason']);
|
||||
$text .= '<tr><td>' . $ban['ip'] . '</td><td>' . date('y/m/d(D)H:i:s', $ban['timestamp']) . '</td><td>' . $expire . '</td><td>' . $reason . '</td><td><a href="?manage&bans&lift=' . $ban['id'] . '">lift</a></td></tr>';
|
||||
}
|
||||
$text .= '</table>';
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
function manageModeratePostForm() {
|
||||
return <<<EOF
|
||||
<form id="tinyib" name="tinyib" method="get" action="?">
|
||||
<input type="hidden" name="manage" value="">
|
||||
<fieldset>
|
||||
<legend>Moderate a post</legend>
|
||||
<label for="moderate">Post ID:</label> <input type="text" name="moderate" id="moderate"> <input type="submit" value="Submit" class="managebutton"><br>
|
||||
<legend>
|
||||
</fieldset>
|
||||
</form><br>
|
||||
EOF;
|
||||
}
|
||||
|
||||
function manageModeratePost($post) {
|
||||
global $isadmin;
|
||||
$ban = banByIP($post['ip']);
|
||||
$ban_disabled = (!$ban && $isadmin) ? '' : ' disabled';
|
||||
$ban_disabled_info = (!$ban) ? '' : (' A ban record already exists for ' . $post['ip']);
|
||||
$post_html = buildPost($post, true);
|
||||
return <<<EOF
|
||||
<fieldset>
|
||||
<legend>Moderating post No.${post['id']}</legend>
|
||||
|
||||
<div style="float: right;clear: both;">
|
||||
<fieldset>
|
||||
<legend>Post</legend>
|
||||
$post_html
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<fieldset>
|
||||
<legend>Action</legend>
|
||||
<form method="get" action="?">
|
||||
<input type="hidden" name="manage" value="">
|
||||
<input type="hidden" name="delete" value="${post['id']}">
|
||||
<input type="submit" value="Delete Post" class="managebutton">
|
||||
</form>
|
||||
<br>
|
||||
<form method="get" action="?">
|
||||
<input type="hidden" name="manage" value="">
|
||||
<input type="hidden" name="bans" value="${post['ip']}">
|
||||
<input type="submit" value="Ban Poster" class="managebutton"$ban_disabled>$ban_disabled_info
|
||||
</form>
|
||||
</fieldset>
|
||||
|
||||
</fieldset>
|
||||
<br>
|
||||
EOF;
|
||||
}
|
||||
?>
|
254
inc/database_flatfile.php
Normal file
254
inc/database_flatfile.php
Normal file
|
@ -0,0 +1,254 @@
|
|||
<?php
|
||||
if (!isset($tinyib)) { die(''); }
|
||||
|
||||
# Post Structure
|
||||
define('POSTS_FILE', '.posts');
|
||||
define('POST_ID', 0);
|
||||
define('POST_PARENT', 1);
|
||||
define('POST_TIMESTAMP', 2);
|
||||
define('POST_BUMPED', 3);
|
||||
define('POST_IP', 4);
|
||||
define('POST_NAME', 5);
|
||||
define('POST_TRIPCODE', 6);
|
||||
define('POST_EMAIL', 7);
|
||||
define('POST_NAMEBLOCK', 8);
|
||||
define('POST_SUBJECT', 9);
|
||||
define('POST_MESSAGE', 10);
|
||||
define('POST_PASSWORD', 11);
|
||||
define('POST_FILE', 12);
|
||||
define('POST_FILE_HEX', 13);
|
||||
define('POST_FILE_ORIGINAL', 14);
|
||||
define('POST_FILE_SIZE', 15);
|
||||
define('POST_FILE_SIZE_FORMATTED', 16);
|
||||
define('POST_IMAGE_WIDTH', 17);
|
||||
define('POST_IMAGE_HEIGHT', 18);
|
||||
define('POST_THUMB', 19);
|
||||
define('POST_THUMB_WIDTH', 20);
|
||||
define('POST_THUMB_HEIGHT', 21);
|
||||
|
||||
# Ban Structure
|
||||
define('BANS_FILE', '.bans');
|
||||
define('BAN_ID', 0);
|
||||
define('BAN_IP', 1);
|
||||
define('BAN_TIMESTAMP', 2);
|
||||
define('BAN_EXPIRE', 3);
|
||||
define('BAN_REASON', 4);
|
||||
|
||||
require_once 'flatfile/flatfile.php';
|
||||
$db = new Flatfile();
|
||||
$db->datadir = 'inc/flatfile/';
|
||||
|
||||
# Post Functions
|
||||
function uniquePosts() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
function postByID($id) {
|
||||
return convertPostsToSQLStyle($GLOBALS['db']->selectWhere(POSTS_FILE, new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON), 1), true);
|
||||
}
|
||||
|
||||
function threadExistsByID($id) {
|
||||
$compClause = new AndWhereClause();
|
||||
$compClause->add(new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON));
|
||||
$compClause->add(new SimpleWhereClause(POST_PARENT, '=', 0, INTEGER_COMPARISON));
|
||||
|
||||
return count($GLOBALS['db']->selectWhere(POSTS_FILE, $compClause, 1)) > 0;
|
||||
}
|
||||
|
||||
function insertPost($newpost) {
|
||||
$post = array();
|
||||
$post[POST_ID] = '0';
|
||||
$post[POST_PARENT] = $newpost['parent'];
|
||||
$post[POST_TIMESTAMP] = time();
|
||||
$post[POST_BUMPED] = time();
|
||||
$post[POST_IP] = $newpost['ip'];
|
||||
$post[POST_NAME] = $newpost['name'];
|
||||
$post[POST_TRIPCODE] = $newpost['tripcode'];
|
||||
$post[POST_EMAIL] = $newpost['email'];
|
||||
$post[POST_NAMEBLOCK] = $newpost['nameblock'];
|
||||
$post[POST_SUBJECT] = $newpost['subject'];
|
||||
$post[POST_MESSAGE] = $newpost['message'];
|
||||
$post[POST_PASSWORD] = $newpost['password'];
|
||||
$post[POST_FILE] = $newpost['file'];
|
||||
$post[POST_FILE_HEX] = $newpost['file_hex'];
|
||||
$post[POST_FILE_ORIGINAL] = $newpost['file_original'];
|
||||
$post[POST_FILE_SIZE] = $newpost['file_size'];
|
||||
$post[POST_FILE_SIZE_FORMATTED] = $newpost['file_size_formatted'];
|
||||
$post[POST_IMAGE_WIDTH] = $newpost['image_width'];
|
||||
$post[POST_IMAGE_HEIGHT] = $newpost['image_height'];
|
||||
$post[POST_THUMB] = $newpost['thumb'];
|
||||
$post[POST_THUMB_WIDTH] = $newpost['thumb_width'];
|
||||
$post[POST_THUMB_HEIGHT] = $newpost['thumb_height'];
|
||||
$post[POST_THUMB_HEIGHT] = $newpost['thumb_height'];
|
||||
|
||||
return $GLOBALS['db']->insertWithAutoId(POSTS_FILE, POST_ID, $post);
|
||||
}
|
||||
|
||||
function bumpThreadByID($id) {
|
||||
$rows = $GLOBALS['db']->selectWhere(POSTS_FILE, new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON), 1);
|
||||
if (count($rows) > 0) {
|
||||
foreach ($rows as $post) {
|
||||
$post[POST_BUMPED] = time();
|
||||
$GLOBALS['db']->updateRowById(POSTS_FILE, POST_ID, $post);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function countThreads() {
|
||||
$rows = $GLOBALS['db']->selectWhere(POSTS_FILE, new SimpleWhereClause(POST_PARENT, '=', 0, INTEGER_COMPARISON));
|
||||
return count($rows);
|
||||
}
|
||||
|
||||
function convertPostsToSQLStyle($posts, $singlepost=false) {
|
||||
$newposts = array();
|
||||
foreach ($posts as $oldpost) {
|
||||
$post = newPost();
|
||||
$post['id'] = $oldpost[POST_ID];
|
||||
$post['parent'] = $oldpost[POST_PARENT];
|
||||
$post['timestamp'] = $oldpost[POST_TIMESTAMP];
|
||||
$post['bumped'] = $oldpost[POST_BUMPED];
|
||||
$post['ip'] = $oldpost[POST_IP];
|
||||
$post['name'] = $oldpost[POST_NAME];
|
||||
$post['tripcode'] = $oldpost[POST_TRIPCODE];
|
||||
$post['email'] = $oldpost[POST_EMAIL];
|
||||
$post['nameblock'] = $oldpost[POST_NAMEBLOCK];
|
||||
$post['subject'] = $oldpost[POST_SUBJECT];
|
||||
$post['message'] = $oldpost[POST_MESSAGE];
|
||||
$post['password'] = $oldpost[POST_PASSWORD];
|
||||
$post['file'] = $oldpost[POST_FILE];
|
||||
$post['file_hex'] = $oldpost[POST_FILE_HEX];
|
||||
$post['file_original'] = $oldpost[POST_FILE_ORIGINAL];
|
||||
$post['file_size'] = $oldpost[POST_FILE_SIZE];
|
||||
$post['file_size_formatted'] = $oldpost[POST_FILE_SIZE_FORMATTED];
|
||||
$post['image_width'] = $oldpost[POST_IMAGE_WIDTH];
|
||||
$post['image_height'] = $oldpost[POST_IMAGE_HEIGHT];
|
||||
$post['thumb'] = $oldpost[POST_THUMB];
|
||||
$post['thumb_width'] = $oldpost[POST_THUMB_WIDTH];
|
||||
$post['thumb_height'] = $oldpost[POST_THUMB_HEIGHT];
|
||||
|
||||
if ($post['parent'] == '') {
|
||||
$post['parent'] = '0';
|
||||
}
|
||||
|
||||
if ($singlepost) { return $post; }
|
||||
$newposts[] = $post;
|
||||
}
|
||||
return $newposts;
|
||||
}
|
||||
|
||||
function allThreads() {
|
||||
$rows = $GLOBALS['db']->selectWhere(POSTS_FILE, new SimpleWhereClause(POST_PARENT, '=', 0, INTEGER_COMPARISON), -1, new OrderBy(POST_BUMPED, DESCENDING, INTEGER_COMPARISON));
|
||||
return convertPostsToSQLStyle($rows);
|
||||
}
|
||||
|
||||
function postsInThreadByID($id) {
|
||||
$compClause = new OrWhereClause();
|
||||
$compClause->add(new SimpleWhereClause(POST_ID, '=', $id, INTEGER_COMPARISON));
|
||||
$compClause->add(new SimpleWhereClause(POST_PARENT, '=', $id, INTEGER_COMPARISON));
|
||||
|
||||
$rows = $GLOBALS['db']->selectWhere(POSTS_FILE, $compClause, -1, new OrderBy(POST_ID, ASCENDING, INTEGER_COMPARISON));
|
||||
return convertPostsToSQLStyle($rows);
|
||||
}
|
||||
|
||||
function latestRepliesInThreadByID($id) {
|
||||
$rows = $GLOBALS['db']->selectWhere(POSTS_FILE, new SimpleWhereClause(POST_PARENT, '=', $id, INTEGER_COMPARISON), 3, new OrderBy(POST_ID, DESCENDING, INTEGER_COMPARISON));
|
||||
return convertPostsToSQLStyle($rows);
|
||||
}
|
||||
|
||||
function postsByHex($hex) {
|
||||
$rows = $GLOBALS['db']->selectWhere(POSTS_FILE, new SimpleWhereClause(POST_FILE_HEX, '=', $hex, STRING_COMPARISON), 1);
|
||||
return convertPostsToSQLStyle($rows);
|
||||
}
|
||||
|
||||
function deletePostByID($id) {
|
||||
$posts = postsInThreadByID($id);
|
||||
foreach ($posts as $post) {
|
||||
if ($post['id'] != $id) {
|
||||
deletePostImages($post);
|
||||
$GLOBALS['db']->deleteWhere(POSTS_FILE, new SimpleWhereClause(POST_ID, '=', $post['id'], INTEGER_COMPARISON));
|
||||
} else {
|
||||
$thispost = $post;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($thispost)) {
|
||||
deletePostImages($thispost);
|
||||
$GLOBALS['db']->deleteWhere(POSTS_FILE, new SimpleWhereClause(POST_ID, '=', $thispost['id'], INTEGER_COMPARISON));
|
||||
}
|
||||
}
|
||||
|
||||
function trimThreads() {
|
||||
global $tinyib;
|
||||
if ($tinyib['maxthreads'] > 0) {
|
||||
$numthreads = countThreads();
|
||||
if ($numthreads > $tinyib['maxthreads']) {
|
||||
$allthreads = allThreads();
|
||||
for ($i=$tinyib['maxthreads'];$i<$numthreads;$i++) {
|
||||
deletePostByID($allthreads[$i]['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function lastPostByIP() {
|
||||
$rows = $GLOBALS['db']->selectWhere(POSTS_FILE, new SimpleWhereClause(POST_IP, '=', $_SERVER['REMOTE_ADDR'], STRING_COMPARISON), 1, new OrderBy(POST_ID, DESCENDING, INTEGER_COMPARISON));
|
||||
return convertPostsToSQLStyle($rows, true);
|
||||
}
|
||||
|
||||
# Ban Functions
|
||||
function banByID($id) {
|
||||
return convertBansToSQLStyle($GLOBALS['db']->selectWhere(BANS_FILE, new SimpleWhereClause(BAN_ID, '=', $id, INTEGER_COMPARISON), 1), true);
|
||||
}
|
||||
|
||||
function banByIP($ip) {
|
||||
return convertBansToSQLStyle($GLOBALS['db']->selectWhere(BANS_FILE, new SimpleWhereClause(BAN_IP, '=', $ip, STRING_COMPARISON), 1), true);
|
||||
}
|
||||
|
||||
function allBans() {
|
||||
$rows = $GLOBALS['db']->selectWhere(BANS_FILE, NULL, -1, new OrderBy(BAN_TIMESTAMP, DESCENDING, INTEGER_COMPARISON));
|
||||
return convertBansToSQLStyle($rows);
|
||||
}
|
||||
|
||||
function convertBansToSQLStyle($bans, $singleban=false) {
|
||||
$newbans = array();
|
||||
foreach ($bans as $oldban) {
|
||||
$ban = array();
|
||||
$ban['id'] = $oldban[BAN_ID];
|
||||
$ban['ip'] = $oldban[BAN_IP];
|
||||
$ban['timestamp'] = $oldban[BAN_TIMESTAMP];
|
||||
$ban['expire'] = $oldban[BAN_EXPIRE];
|
||||
$ban['reason'] = $oldban[BAN_REASON];
|
||||
|
||||
if ($singleban) { return $ban; }
|
||||
$newbans[] = $ban;
|
||||
}
|
||||
return $newbans;
|
||||
}
|
||||
|
||||
function insertBan($newban) {
|
||||
$ban = array();
|
||||
$ban[BAN_ID] = '0';
|
||||
$ban[BAN_IP] = $newban['ip'];
|
||||
$ban[BAN_TIMESTAMP] = time();
|
||||
$ban[BAN_EXPIRE] = $newban['expire'];
|
||||
$ban[BAN_REASON] = $newban['reason'];
|
||||
|
||||
return $GLOBALS['db']->insertWithAutoId(BANS_FILE, BAN_ID, $ban);
|
||||
}
|
||||
|
||||
function clearExpiredBans() {
|
||||
$compClause = new AndWhereClause();
|
||||
$compClause->add(new SimpleWhereClause(BAN_EXPIRE, '>', 0, INTEGER_COMPARISON));
|
||||
$compClause->add(new SimpleWhereClause(BAN_EXPIRE, '<=', time(), INTEGER_COMPARISON));
|
||||
|
||||
$bans = $GLOBALS['db']->selectWhere(BANS_FILE, $compClause, -1);
|
||||
foreach ($bans as $ban) {
|
||||
deleteBanByID($ban[BAN_ID]);
|
||||
}
|
||||
}
|
||||
|
||||
function deleteBanByID($id) {
|
||||
$GLOBALS['db']->deleteWhere(BANS_FILE, new SimpleWhereClause(BAN_ID, '=', $id, INTEGER_COMPARISON));
|
||||
}
|
||||
|
||||
?>
|
195
inc/database_mysql.php
Normal file
195
inc/database_mysql.php
Normal file
|
@ -0,0 +1,195 @@
|
|||
<?php
|
||||
if (!isset($tinyib)) { die(''); }
|
||||
|
||||
$link = mysql_connect($mysql_host, $mysql_username, $mysql_password);
|
||||
if (!$link) {
|
||||
fancyDie("Could not connect to database: " . mysql_error());
|
||||
}
|
||||
$db_selected = mysql_select_db($mysql_database, $link);
|
||||
if (!$db_selected) {
|
||||
fancyDie("Could not select database: " . mysql_error());
|
||||
}
|
||||
|
||||
// Create the posts table if it does not exist
|
||||
if (mysql_num_rows(mysql_query("SHOW TABLES LIKE '" . $mysql_posts_table . "'")) == 0) {
|
||||
mysql_query("CREATE TABLE `" . $mysql_posts_table . "` (
|
||||
`id` mediumint(7) unsigned NOT NULL auto_increment,
|
||||
`parent` mediumint(7) unsigned NOT NULL,
|
||||
`timestamp` int(20) NOT NULL,
|
||||
`bumped` int(20) NOT NULL,
|
||||
`ip` varchar(15) NOT NULL,
|
||||
`name` varchar(75) NOT NULL,
|
||||
`tripcode` varchar(10) NOT NULL,
|
||||
`email` varchar(75) NOT NULL,
|
||||
`nameblock` varchar(255) NOT NULL,
|
||||
`subject` varchar(75) NOT NULL,
|
||||
`message` text NOT NULL,
|
||||
`password` varchar(255) NOT NULL,
|
||||
`file` varchar(75) NOT NULL,
|
||||
`file_hex` varchar(75) NOT NULL,
|
||||
`file_original` varchar(255) NOT NULL,
|
||||
`file_size` int(20) unsigned NOT NULL default '0',
|
||||
`file_size_formatted` varchar(75) NOT NULL,
|
||||
`image_width` smallint(5) unsigned NOT NULL default '0',
|
||||
`image_height` smallint(5) unsigned NOT NULL default '0',
|
||||
`thumb` varchar(255) NOT NULL,
|
||||
`thumb_width` smallint(5) unsigned NOT NULL default '0',
|
||||
`thumb_height` smallint(5) unsigned NOT NULL default '0',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `parent` (`parent`),
|
||||
KEY `bumped` (`bumped`)
|
||||
) ENGINE=MyISAM");
|
||||
}
|
||||
|
||||
// Create the bans table if it does not exist
|
||||
if (mysql_num_rows(mysql_query("SHOW TABLES LIKE '" . $mysql_bans_table . "'")) == 0) {
|
||||
mysql_query("CREATE TABLE `" . $mysql_bans_table . "` (
|
||||
`id` mediumint(7) unsigned NOT NULL auto_increment,
|
||||
`ip` varchar(15) NOT NULL,
|
||||
`timestamp` int(20) NOT NULL,
|
||||
`expire` int(20) NOT NULL,
|
||||
`reason` text NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `ip` (`ip`)
|
||||
) ENGINE=MyISAM");
|
||||
}
|
||||
|
||||
# Post Functions
|
||||
function uniquePosts() {
|
||||
$row = mysql_fetch_row(mysql_query("SELECT COUNT(DISTINCT(`ip`)) FROM " . $GLOBALS['mysql_posts_table']));
|
||||
return $row[0];
|
||||
}
|
||||
|
||||
function postByID($id) {
|
||||
$result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `id` = '" . mysql_real_escape_string($id) . "' LIMIT 1");
|
||||
while ($post = mysql_fetch_assoc($result)) {
|
||||
return $post;
|
||||
}
|
||||
}
|
||||
|
||||
function threadExistsByID($id) {
|
||||
return mysql_result(mysql_query("SELECT COUNT(*) FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `id` = '" . mysql_real_escape_string($id) . "' AND `parent` = 0 LIMIT 1"), 0, 0) > 0;
|
||||
}
|
||||
|
||||
function insertPost($post) {
|
||||
mysql_query("INSERT INTO `" . $GLOBALS['mysql_posts_table'] . "` (`parent`, `timestamp`, `bumped`, `ip`, `name`, `tripcode`, `email`, `nameblock`, `subject`, `message`, `password`, `file`, `file_hex`, `file_original`, `file_size`, `file_size_formatted`, `image_width`, `image_height`, `thumb`, `thumb_width`, `thumb_height`) VALUES (" . $post['parent'] . ", " . time() . ", " . time() . ", '" . $_SERVER['REMOTE_ADDR'] . "', '" . mysql_real_escape_string($post['name']) . "', '" . mysql_real_escape_string($post['tripcode']) . "', '" . mysql_real_escape_string($post['email']) . "', '" . mysql_real_escape_string($post['nameblock']) . "', '" . mysql_real_escape_string($post['subject']) . "', '" . mysql_real_escape_string($post['message']) . "', '" . mysql_real_escape_string($post['password']) . "', '" . $post['file'] . "', '" . $post['file_hex'] . "', '" . mysql_real_escape_string($post['file_original']) . "', " . $post['file_size'] . ", '" . $post['file_size_formatted'] . "', " . $post['image_width'] . ", " . $post['image_height'] . ", '" . $post['thumb'] . "', " . $post['thumb_width'] . ", " . $post['thumb_height'] . ")");
|
||||
return mysql_insert_id();
|
||||
}
|
||||
|
||||
function bumpThreadByID($id) {
|
||||
mysql_query("UPDATE `" . $GLOBALS['mysql_posts_table'] . "` SET `bumped` = " . time() . " WHERE `id` = " . $id . " LIMIT 1");
|
||||
}
|
||||
|
||||
function countThreads() {
|
||||
return mysql_result(mysql_query("SELECT COUNT(*) FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `parent` = 0"), 0, 0);
|
||||
}
|
||||
|
||||
function allThreads() {
|
||||
$threads = array();
|
||||
$result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `parent` = 0 ORDER BY `bumped` DESC");
|
||||
while ($thread = mysql_fetch_assoc($result)) {
|
||||
$threads[] = $thread;
|
||||
}
|
||||
return $threads;
|
||||
}
|
||||
|
||||
function postsInThreadByID($id) {
|
||||
$posts = array();
|
||||
$result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `id` = " . $id . " OR `parent` = " . $id . " ORDER BY `id` ASC");
|
||||
while ($post = mysql_fetch_assoc($result)) {
|
||||
$posts[] = $post;
|
||||
}
|
||||
return $posts;
|
||||
}
|
||||
|
||||
function latestRepliesInThreadByID($id) {
|
||||
$posts = array();
|
||||
$replies = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `parent` = " . $id . " ORDER BY `id` DESC LIMIT 3");
|
||||
while ($post = mysql_fetch_assoc($replies)) {
|
||||
$posts[] = $post;
|
||||
}
|
||||
return $posts;
|
||||
}
|
||||
|
||||
function postsByHex($hex) {
|
||||
$posts = array();
|
||||
$result = mysql_query("SELECT `id`, `parent` FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `file_hex` = '" . mysql_real_escape_string($hex) . "' LIMIT 1");
|
||||
while ($post = mysql_fetch_assoc($result)) {
|
||||
$posts[] = $post;
|
||||
}
|
||||
return $posts;
|
||||
}
|
||||
|
||||
function deletePostByID($id) {
|
||||
$posts = postsInThreadByID($id);
|
||||
foreach ($posts as $post) {
|
||||
if ($post['id'] != $id) {
|
||||
deletePostImages($post);
|
||||
mysql_query("DELETE FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `id` = " . $post['id'] . " LIMIT 1");
|
||||
} else {
|
||||
$thispost = $post;
|
||||
}
|
||||
} if (isset($thispost)) {
|
||||
deletePostImages($thispost);
|
||||
mysql_query("DELETE FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `id` = " . $thispost['id'] . " LIMIT 1");
|
||||
}
|
||||
}
|
||||
|
||||
function trimThreads() {
|
||||
global $tinyib;
|
||||
if ($tinyib['maxthreads'] > 0) {
|
||||
$result = mysql_query("SELECT `id` FROM `b_posts` WHERE `parent` = 0 ORDER BY `bumped` DESC LIMIT " . $tinyib['maxthreads']. ", 10");
|
||||
while ($post = mysql_fetch_assoc($result)) {
|
||||
deletePostByID($post['id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function lastPostByIP() {
|
||||
$replies = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_posts_table'] . "` WHERE `ip` = '" . $_SERVER['REMOTE_ADDR'] . "' ORDER BY `id` DESC LIMIT 1");
|
||||
while ($post = mysql_fetch_assoc($replies)) {
|
||||
return $post;
|
||||
}
|
||||
}
|
||||
|
||||
# Ban Functions
|
||||
function banByID($id) {
|
||||
$result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_bans_table'] . "` WHERE `id` = '" . mysql_real_escape_string($id) . "' LIMIT 1");
|
||||
while ($ban = mysql_fetch_assoc($result)) {
|
||||
return $ban;
|
||||
}
|
||||
}
|
||||
|
||||
function banByIP($ip) {
|
||||
$result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_bans_table'] . "` WHERE `ip` = '" . mysql_real_escape_string($ip) . "' LIMIT 1");
|
||||
while ($ban = mysql_fetch_assoc($result)) {
|
||||
return $ban;
|
||||
}
|
||||
}
|
||||
|
||||
function allBans() {
|
||||
$bans = array();
|
||||
$result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_bans_table'] . "` ORDER BY `timestamp` DESC");
|
||||
while ($ban = mysql_fetch_assoc($result)) {
|
||||
$bans[] = $ban;
|
||||
}
|
||||
return $bans;
|
||||
}
|
||||
|
||||
function insertBan($ban) {
|
||||
mysql_query("INSERT INTO `" . $GLOBALS['mysql_bans_table'] . "` (`ip`, `timestamp`, `expire`, `reason`) VALUES ('" . mysql_real_escape_string($ban['ip']) . "', " . time() . ", '" . mysql_real_escape_string($ban['expire']) . "', '" . mysql_real_escape_string($ban['reason']) . "')");
|
||||
return mysql_insert_id();
|
||||
}
|
||||
|
||||
function clearExpiredBans() {
|
||||
$result = mysql_query("SELECT * FROM `" . $GLOBALS['mysql_bans_table'] . "` WHERE `expire` > 0 AND `expire` <= " . time());
|
||||
while ($ban = mysql_fetch_assoc($result)) {
|
||||
mysql_query("DELETE FROM `" . $GLOBALS['mysql_bans_table'] . "` WHERE `id` = " . $ban['id'] . " LIMIT 1");
|
||||
}
|
||||
}
|
||||
|
||||
function deleteBanByID($id) {
|
||||
mysql_query("DELETE FROM `" . $GLOBALS['mysql_bans_table'] . "` WHERE `id` = " . mysql_real_escape_string($id) . " LIMIT 1");
|
||||
}
|
||||
|
||||
?>
|
17
inc/flatfile/.svn/all-wcprops
Normal file
17
inc/flatfile/.svn/all-wcprops
Normal file
|
@ -0,0 +1,17 @@
|
|||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 34
|
||||
/svn/!svn/ver/4/trunk/inc/flatfile
|
||||
END
|
||||
flatfile.php
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 47
|
||||
/svn/!svn/ver/4/trunk/inc/flatfile/flatfile.php
|
||||
END
|
||||
flatfile_utils.php
|
||||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 53
|
||||
/svn/!svn/ver/4/trunk/inc/flatfile/flatfile_utils.php
|
||||
END
|
96
inc/flatfile/.svn/entries
Normal file
96
inc/flatfile/.svn/entries
Normal file
|
@ -0,0 +1,96 @@
|
|||
10
|
||||
|
||||
dir
|
||||
4
|
||||
https://tinyib.googlecode.com/svn/trunk/inc/flatfile
|
||||
https://tinyib.googlecode.com/svn
|
||||
|
||||
|
||||
|
||||
2009-09-04T03:12:19.723445Z
|
||||
4
|
||||
tslocum
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
ac9068a4-33bb-11de-8a2e-13aa1706fec1
|
||||
|
||||
flatfile.php
|
||||
file
|
||||
|
||||
|
||||
|
||||
|
||||
2009-09-03T11:01:16.531250Z
|
||||
fcd5201bd7830f959ddcbc5a70f98ee3
|
||||
2009-09-04T03:12:19.723445Z
|
||||
4
|
||||
tslocum
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
24710
|
||||
|
||||
flatfile_utils.php
|
||||
file
|
||||
|
||||
|
||||
|
||||
|
||||
2009-09-03T11:01:30.500000Z
|
||||
c8752fda2a2921df5c6855c91a5b83a6
|
||||
2009-09-04T03:12:19.723445Z
|
||||
4
|
||||
tslocum
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
3218
|
||||
|
807
inc/flatfile/.svn/text-base/flatfile.php.svn-base
Normal file
807
inc/flatfile/.svn/text-base/flatfile.php.svn-base
Normal file
|
@ -0,0 +1,807 @@
|
|||
<?php
|
||||
/*
|
||||
Copyright (c) 2005 Luke Plant <L.Plant.98@cantab.net>
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Simple but powerful flatfile database
|
||||
* See http://lukeplant.me.uk/resources/flatfile/ for documentation and examples
|
||||
*
|
||||
* @tutorial flatfile.pkg
|
||||
* @package flatfile
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
|
||||
require_once('flatfile_utils.php');
|
||||
|
||||
/** Used to indicate the default comparison should be done, which is STRING_COMPARISON in the absence of a schema, or whatever the schema specifies if one has been added */
|
||||
define('DEFAULT_COMPARISON', '');
|
||||
/** Used to indicate a comparison should be done as a string comparison */
|
||||
define('STRING_COMPARISON', 'strcmp');
|
||||
/** Used to indicate a comparison should be done as an integer comparison */
|
||||
define('INTEGER_COMPARISON', 'intcmp');
|
||||
/** Used to indicate a comparison should be done as a numeric (float) comparison */
|
||||
define('NUMERIC_COMPARISON', 'numcmp');
|
||||
|
||||
/** Indicates ascending order */
|
||||
define('ASCENDING', 1);
|
||||
/** Indicates descending order */
|
||||
define('DESCENDING', -1);
|
||||
|
||||
$comparison_type_for_col_type = array(
|
||||
INT_COL => INTEGER_COMPARISON,
|
||||
DATE_COL => INTEGER_COMPARISON, // assume Unix timestamps
|
||||
STRING_COL => STRING_COMPARISON,
|
||||
FLOAT_COL => NUMERIC_COMPARISON
|
||||
);
|
||||
|
||||
function get_comparison_type_for_col_type($coltype)
|
||||
{
|
||||
global $comparison_type_for_col_type;
|
||||
return $comparison_type_for_col_type[$coltype];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides simple but powerful flatfile database storage and retrieval
|
||||
*
|
||||
* Includes equivalents to SELECT * FROM table WHERE..., DELETE WHERE ...
|
||||
* UPDATE and more. All files are stored in the {@link Flatfile::$datadir $datadir} directory,
|
||||
* and table names are just filenames in that directory. Subdirectories
|
||||
* can be used just by specifying a table name that includes the directory name.
|
||||
* @package flatfile
|
||||
*/
|
||||
class Flatfile {
|
||||
/** @access private */
|
||||
var $tables;
|
||||
|
||||
/** @access private */
|
||||
var $schemata;
|
||||
|
||||
/** The directory to store files in.
|
||||
* @var string
|
||||
*/
|
||||
var $datadir;
|
||||
|
||||
function Flatfile()
|
||||
{
|
||||
$this->schemata = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all rows from a table
|
||||
* @param string $tablename The table to get rows from
|
||||
* @return array The table as an array of rows, where each row is an array of columns
|
||||
*/
|
||||
function selectAll ($tablename) {
|
||||
if (!isset($this->tables[$tablename]))
|
||||
$this->loadTable($tablename);
|
||||
return $this->tables[$tablename];
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects rows from a table that match the specified criteria
|
||||
*
|
||||
* This simulates the following SQL query:
|
||||
* <pre>
|
||||
* SELECT LIMIT $limit * FROM $tablename
|
||||
* WHERE $whereclause
|
||||
* ORDER BY $orderBy [ASC | DESC] [, $orderBy2 ...]
|
||||
* </pre>
|
||||
*
|
||||
* @param string $tablename The table (file) to get the data from
|
||||
* @param object $whereClause Either a {@link WhereClause WhereClause} object to do selection of rows, or NULL to select all
|
||||
* @param mixed $limit Specifies limits for the rows returned:
|
||||
* - use -1 or omitted to return all rows
|
||||
* - use an integer n to return the first n rows
|
||||
* - use a two item array ($startrow, $endrow) to return rows $startrow to $endrow - 1 (zero indexed)
|
||||
* - use a two item array ($startrow, -1) to return rows $startrow to the end (zero indexed)
|
||||
* @param mixed $orderBy Either an {@link OrderBy} object or an array of them, defining the sorting that should be applied (if an array, then the first object in the array is the first key to sort on etc). Use NULL for no sorting.
|
||||
* @return array The matching data, as an array of rows, where each row is an array of columns
|
||||
*/
|
||||
function selectWhere ($tablename, $whereClause, $limit = -1, $orderBy = NULL) {
|
||||
if (!isset($this->tables[$tablename]))
|
||||
$this->loadTable($tablename);
|
||||
|
||||
$table = $this->selectAll($tablename); // Get a copy
|
||||
|
||||
$schema = $this->getSchema($tablename);
|
||||
if ($orderBy !== NULL)
|
||||
usort($table, $this->getOrderByFunction($orderBy, $schema));
|
||||
|
||||
$results = array();
|
||||
$count = 0;
|
||||
|
||||
if ($limit == -1)
|
||||
$limit = array(0, -1);
|
||||
else if (!is_array($limit))
|
||||
$limit = array(0, $limit);
|
||||
|
||||
foreach ($table as $row) {
|
||||
if ($whereClause === NULL || $whereClause->testRow($row, $schema)) {
|
||||
if ($count >= $limit[0])
|
||||
$results[] = $row;
|
||||
++$count;
|
||||
if (($count >= $limit[1]) && ($limit[1] != -1))
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select a row using a unique ID
|
||||
* @param string $tablename The table to get data from
|
||||
* @param string $idField The index of the field containing the ID
|
||||
* @param string $id The ID to search for
|
||||
* @return array The row of the table as an array
|
||||
*/
|
||||
function selectUnique ($tablename, $idField, $id) {
|
||||
$result = $this->selectWhere($tablename, new SimpleWhereClause($idField, '=', $id));
|
||||
if (count($result) > 0)
|
||||
return $result[0];
|
||||
else
|
||||
return array();
|
||||
}
|
||||
|
||||
/*
|
||||
* To correctly write a file, and not overwrite the changes
|
||||
* another process is making, we need to:
|
||||
* - get a lock for writing
|
||||
* - read its contents from disc
|
||||
* - modify the contents in memory
|
||||
* - write the contents
|
||||
* - release lock
|
||||
* Because opening for writing truncates the file, we must get
|
||||
* the lock on a different file. getLock and releaseLock
|
||||
* are helper functions to allow us to do this with little fuss
|
||||
*/
|
||||
|
||||
/** Get a lock for writing a file
|
||||
* @access private
|
||||
*/
|
||||
function getLock ($tablename)
|
||||
{
|
||||
ignore_user_abort(true);
|
||||
$fp = fopen($this->datadir . $tablename.'.lock','w');
|
||||
if (!flock($fp, LOCK_EX)) {
|
||||
// log error?
|
||||
}
|
||||
$this->loadTable($tablename);
|
||||
return $fp;
|
||||
}
|
||||
|
||||
/** Release a lock
|
||||
* @access private
|
||||
*/
|
||||
function releaseLock ($lockfp)
|
||||
{
|
||||
flock($lockfp, LOCK_UN);
|
||||
ignore_user_abort(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a row with an automatically generated ID
|
||||
*
|
||||
* The autogenerated ID will be the highest ID in the column so far plus one. The
|
||||
* supplied row should include all fields required for the table, and the
|
||||
* ID field it contains will just be ignored
|
||||
*
|
||||
* @param string $tablename The table to insert data into
|
||||
* @param int $idField The index of the field which is the ID field
|
||||
* @param array $newRow The new row to add to the table
|
||||
* @return int The newly assigned ID
|
||||
*/
|
||||
function insertWithAutoId ($tablename, $idField, $newRow)
|
||||
{
|
||||
$lockfp = $this->getLock($tablename);
|
||||
$rows = $this->selectWhere($tablename, null, 1,
|
||||
new OrderBy($idField, DESCENDING, INTEGER_COMPARISON));
|
||||
if ($rows) {
|
||||
$newId = $rows[0][$idField] + 1;
|
||||
} else {
|
||||
$newId = 1;
|
||||
}
|
||||
$newRow[$idField] = $newId;
|
||||
$this->tables[$tablename][] = $newRow;
|
||||
$this->writeTable($tablename);
|
||||
$this->releaseLock($lockfp);
|
||||
return $newId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a row in a table
|
||||
*
|
||||
* @param string $tablename The table to insert data into
|
||||
* @param array $newRow The new row to add to the table
|
||||
*/
|
||||
function insert ($tablename, $newRow)
|
||||
{
|
||||
$lockfp = $this->getLock($tablename);
|
||||
$this->tables[$tablename][] = $newRow;
|
||||
$this->writeTable($tablename);
|
||||
$this->releaseLock($lockfp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing row using a unique ID
|
||||
*
|
||||
* @param string $tablename The table to update
|
||||
* @param int $idField The index of the field which is the ID field
|
||||
* @param array $updatedRow The updated row to add to the table
|
||||
*/
|
||||
function updateRowById ($tablename, $idField, $updatedRow)
|
||||
{
|
||||
$this->updateSetWhere($tablename, $updatedRow,
|
||||
new SimpleWhereClause($idField, '=', $updatedRow[$idField]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates fields in a table for rows that match the provided criteria
|
||||
*
|
||||
* $newFields can be a complete row or it can be a sparsely populated
|
||||
* hashtable of values (where the keys are integers which are the column
|
||||
* indexes to update)
|
||||
*
|
||||
* @param string $tablename The table to update
|
||||
* @param array $newFields A hashtable (with integer keys) of fields to update
|
||||
* @param WhereClause $whereClause The criteria or NULL to update all rows
|
||||
*/
|
||||
function updateSetWhere ($tablename, $newFields, $whereClause)
|
||||
{
|
||||
$schema = $this->getSchema($tablename);
|
||||
$lockfp = $this->getLock($tablename);
|
||||
for ($i = 0; $i < count($this->tables[$tablename]); ++$i) {
|
||||
if ($whereClause === NULL ||
|
||||
$whereClause->testRow($this->tables[$tablename][$i], $schema)) {
|
||||
foreach ($newFields as $k => $v)
|
||||
{
|
||||
$this->tables[$tablename][$i][$k] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->writeTable($tablename);
|
||||
$this->releaseLock($lockfp);
|
||||
$this->loadTable($tablename);
|
||||
}
|
||||
/**
|
||||
* Deletes all rows in a table that match specified criteria
|
||||
*
|
||||
* @param string $tablename The table to alter
|
||||
* @param object $whereClause. {@link WhereClause WhereClause} object that will select
|
||||
* rows to be deleted. All rows are deleted if $whereClause === NULL
|
||||
*/
|
||||
function deleteWhere ($tablename, $whereClause) {
|
||||
$schema = $this->getSchema($tablename);
|
||||
$lockfp = $this->getLock($tablename);
|
||||
for ($i = count($this->tables[$tablename]) - 1; $i >= 0 ; --$i) {
|
||||
if ($whereClause === NULL ||
|
||||
$whereClause->testRow($this->tables[$tablename][$i], $schema)) {
|
||||
unset($this->tables[$tablename][$i]);
|
||||
}
|
||||
}
|
||||
$this->writeTable($tablename);
|
||||
$this->releaseLock($lockfp);
|
||||
$this->loadTable($tablename); // reset array indexes
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all rows in a table
|
||||
*
|
||||
* @param string $tablename The table to alter
|
||||
*/
|
||||
function deleteAll ($tablename) {
|
||||
$this->deleteWhere($tablename, NULL);
|
||||
}
|
||||
|
||||
/**#@+
|
||||
* @access private
|
||||
*/
|
||||
|
||||
/** Gets a function that can be passed to usort to do the ORDER BY clause
|
||||
* @param mixed $orderBy Either an OrderBy object or an array of them
|
||||
* @return string function name
|
||||
*/
|
||||
function getOrderByFunction ($orderBy, $rowSchema = null)
|
||||
{
|
||||
$orderer = new Orderer($orderBy, $rowSchema);
|
||||
return array(&$orderer, 'compare');
|
||||
}
|
||||
|
||||
function loadTable ($tablename) {
|
||||
$filedata = @file($this->datadir . $tablename);
|
||||
$table = array();
|
||||
if (is_array($filedata)) {
|
||||
foreach ($filedata as $line) {
|
||||
$line = rtrim($line, "\n");
|
||||
$table[] = explode("\t", $line);
|
||||
}
|
||||
}
|
||||
$this->tables[$tablename] = $table;
|
||||
}
|
||||
|
||||
function writeTable ($tablename) {
|
||||
$output = '';
|
||||
|
||||
foreach ($this->tables[$tablename] as $row) {
|
||||
$keys = array_keys($row);
|
||||
rsort($keys, SORT_NUMERIC);
|
||||
$max = $keys[0];
|
||||
for ($i = 0; $i <= $max; ++$i) {
|
||||
if ($i > 0) $output .= "\t";
|
||||
$data = (empty($row[$i]) ? '' : $row[$i]);
|
||||
$output .= str_replace(array("\t","\r","\n"), array(''), $data);
|
||||
}
|
||||
$output .= "\n";
|
||||
}
|
||||
$fp = @fopen($this->datadir . $tablename, "w");
|
||||
fwrite($fp, $output, strlen($output));
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
/**#@-*/
|
||||
/**
|
||||
* Adds a schema definition to the DB for a specified regular expression
|
||||
*
|
||||
* Schemas are optional, and are only used for automatically determining
|
||||
* the comparison types that should be used when sorting and selecting.
|
||||
*
|
||||
* @param string $fileregex A regular expression used to match filenames
|
||||
* @param string $rowSchema An array specifying the column types for data
|
||||
* files that match the regex, using constants defined in flatfile_utils.php
|
||||
*/
|
||||
function addSchema($fileregex, $rowSchema)
|
||||
{
|
||||
array_push($this->schemata, array($fileregex, $rowSchema));
|
||||
}
|
||||
|
||||
/** Retrieves the schema for a given filename */
|
||||
function getSchema($filename)
|
||||
{
|
||||
foreach ($this->schemata as $rowSchemaPair)
|
||||
{
|
||||
$fileregex = $rowSchemaPair[0];
|
||||
if (preg_match($fileregex, $filename))
|
||||
{
|
||||
return $rowSchemaPair[1];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/////////////////////////// UTILITY FUNCTIONS ////////////////////////////////////
|
||||
|
||||
/**
|
||||
* equivalent of strcmp for comparing integers, used internally for sorting and comparing
|
||||
*/
|
||||
function intcmp ($a, $b)
|
||||
{
|
||||
return (int)$a - (int)$b;
|
||||
}
|
||||
|
||||
/**
|
||||
* equivalent of strcmp for comparing floats, used internally for sorting and comparing
|
||||
*/
|
||||
function numcmp ($a, $b)
|
||||
{
|
||||
return (float)$a - (float)$b;
|
||||
}
|
||||
|
||||
/////////////////////////// WHERE CLAUSE CLASSES ////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Used to test rows in a database table, like the WHERE clause in an SQL statement.
|
||||
*
|
||||
* @abstract
|
||||
* @package flatfile
|
||||
*/
|
||||
class WhereClause
|
||||
{
|
||||
/**
|
||||
* Tests a table row object
|
||||
* @abstract
|
||||
* @param array $row The row to test
|
||||
* @param array $rowSchema An optional array specifying the schema of the table, using the INT_COL, STRING_COL etc constants
|
||||
* @return bool True if the $row passes the WhereClause
|
||||
* selection criteria, false otherwise
|
||||
*/
|
||||
function testRow ($row, $rowSchema = null) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Negates a where clause
|
||||
* @package flatfile
|
||||
*/
|
||||
class NotWhere extends WhereClause
|
||||
{
|
||||
/** @access private */
|
||||
var $clause;
|
||||
|
||||
/**
|
||||
* Contructs a new NotWhere object
|
||||
*
|
||||
* The constructed WhereClause will return the negation
|
||||
* of the WhereClause object passed in when testing rows.
|
||||
* @param WhereClause $whereclause The WhereClause object to negate
|
||||
*/
|
||||
function NotWhere ($whereclause)
|
||||
{
|
||||
$this->clause = $whereclause;
|
||||
}
|
||||
|
||||
function testRow ($row, $rowSchema = null) {
|
||||
return !$this->clause->testRow($row, $rowSchema);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements a single WHERE clause that does simple comparisons of a field
|
||||
* with a value.
|
||||
*
|
||||
* @package flatfile
|
||||
*/
|
||||
class SimpleWhereClause extends WhereClause
|
||||
{
|
||||
/**#@+
|
||||
* @access private
|
||||
*/
|
||||
var $field;
|
||||
var $operator;
|
||||
var $value;
|
||||
var $compare_type;
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Creates a new {@link WhereClause WhereClause} object that does a comparison
|
||||
* of a field and a value.
|
||||
*
|
||||
* This will be the most commonly used type of WHERE clause. It can do comparisons
|
||||
* of the sort "$tablerow[$field] operator $value"
|
||||
* where 'operator' is one of:<br>
|
||||
* - = (equals)
|
||||
* - != (not equals)
|
||||
* - > (greater than)
|
||||
* - < (less than)
|
||||
* - >= (greater than or equal to)
|
||||
* - <= (less than or equal to)
|
||||
* There are 3 pre-defined constants (STRING_COMPARISON, NUMERIC COMPARISON and
|
||||
* INTEGER_COMPARISON) that modify the behaviour of these operators to do the comparison
|
||||
* as strings, floats and integers respectively. Howevers, these constants are
|
||||
* just the names of functions that do the comparison (the first being the builtin
|
||||
* function {@link strcmp strcmp()}, so you can supply your own function here to customise the
|
||||
* behaviour of this class.
|
||||
*
|
||||
* @param int $field The index (in the table row) of the field to test
|
||||
* @param string $operator The comparison operator, one of "=", "!=", "<", ">", "<=", ">="
|
||||
* @param mixed $value The value to compare to.
|
||||
* @param string $compare_type The comparison method to use - either
|
||||
* STRING_COMPARISON (default), NUMERIC COMPARISON or INTEGER_COMPARISON
|
||||
*
|
||||
*/
|
||||
function SimpleWhereClause ($field, $operator, $value, $compare_type = DEFAULT_COMPARISON)
|
||||
{
|
||||
$this->field = $field;
|
||||
$this->operator = $operator;
|
||||
$this->value = $value;
|
||||
$this->compare_type = $compare_type;
|
||||
}
|
||||
|
||||
function testRow ($tablerow, $rowSchema = null) {
|
||||
if ($this->field < 0)
|
||||
return TRUE;
|
||||
|
||||
$cmpfunc = $this->compare_type;
|
||||
if ($cmpfunc == DEFAULT_COMPARISON)
|
||||
{
|
||||
if ($rowSchema != null)
|
||||
{
|
||||
$cmpfunc = get_comparison_type_for_col_type($rowSchema[$this->field]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$cmpfunc = STRING_COMPARISON;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->field >= count($tablerow)) {
|
||||
$dbval = "";
|
||||
} else {
|
||||
$dbval = $tablerow[$this->field];
|
||||
}
|
||||
$cmp = $cmpfunc($dbval, $this->value);
|
||||
if ($this->operator == '=')
|
||||
return ($cmp == 0);
|
||||
else if ($this->operator == '!=')
|
||||
return ($cmp != 0);
|
||||
else if ($this->operator == '>')
|
||||
return ($cmp > 0);
|
||||
else if ($this->operator == '<')
|
||||
return ($cmp < 0);
|
||||
else if ($this->operator == '<=')
|
||||
return ($cmp <= 0);
|
||||
else if ($this->operator == '>=')
|
||||
return ($cmp >= 0);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link WhereClause WhereClause} class to work like a SQL 'LIKE' clause
|
||||
* @package flatfile
|
||||
*/
|
||||
class LikeWhereClause extends WhereClause
|
||||
{
|
||||
/**
|
||||
* Creates a new LikeWhereClause
|
||||
*
|
||||
* @param int $field Index of the field to look at
|
||||
* @param string $value Value to look for. Supports using '%' as a
|
||||
* wildcard, and is case insensitve. e.g. 'test%' will match 'TESTS' and 'Testing'
|
||||
*/
|
||||
|
||||
function LikeWhereClause ($field, $value)
|
||||
{
|
||||
$this->field = $field;
|
||||
$this->regexp = '/^' . str_replace('%','.*', preg_quote($value)) . '$/i';
|
||||
}
|
||||
|
||||
function testRow ($tablerow) {
|
||||
return preg_match($this->regexp, $tablerow[$this->field]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@link WhereClause WhereClause} class to match a value from a list of items
|
||||
* @package flatfile
|
||||
*/
|
||||
class ListWhereClause extends WhereClause {
|
||||
|
||||
/** @access private */
|
||||
var $field;
|
||||
/** @access private */
|
||||
var $list;
|
||||
/** @access private */
|
||||
var $compareAs;
|
||||
|
||||
/**
|
||||
* Creates a new ListWhereClause object
|
||||
*
|
||||
* The resulting WhereClause will pass rows (return true) if the value of the specified
|
||||
* field is in the array.
|
||||
*
|
||||
* @param int $field Field to match
|
||||
* @param array $list List of items
|
||||
* @param string $compare_type Comparison type, string by default.
|
||||
*/
|
||||
function ListWhereClause ($field, $list, $compare_type = DEFAULT_COMPARISON) {
|
||||
$this->list = $list;
|
||||
$this->field = (int)$field;
|
||||
$this->compareAs = $compare_type;
|
||||
}
|
||||
|
||||
function testRow ($tablerow, $rowSchema = null) {
|
||||
$func = $this->compareAs;
|
||||
if ($func == DEFAULT_COMPARISON)
|
||||
{
|
||||
if ($rowSchema)
|
||||
{
|
||||
$func = get_comparison_type_for_col_type($rowSchema[$this->field]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$func = STRING_COMPARISON;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->list as $item)
|
||||
{
|
||||
if ($func($tablerow[$this->field], $item) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract class that combines zero or more {@link WhereClause WhereClause} objects
|
||||
* together.
|
||||
* @package flatfile
|
||||
*/
|
||||
class CompositeWhereClause extends WhereClause
|
||||
{
|
||||
/**
|
||||
* @var array Stores the child clauses
|
||||
* @access protected
|
||||
*/
|
||||
var $clauses = array();
|
||||
|
||||
/**
|
||||
* Add a {@link WhereClause WhereClause} to the list of clauses to be used for testing
|
||||
* @param WhereClause $whereClause The WhereClause object to add
|
||||
*/
|
||||
function add ($whereClause)
|
||||
{
|
||||
$this->clauses[] = $whereClause;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link CompositeWhereClause CompositeWhereClause} that does an OR on all its
|
||||
* child WhereClauses.
|
||||
*
|
||||
* Use the {@link CompositeWhereClause::add() add()} method and/or the constructor
|
||||
* to add WhereClause objects
|
||||
* to the list of clauses to check. The testRow function of the resulting object
|
||||
* will then return true if any of its child clauses return true (and returns
|
||||
* false if no clauses have been added for consistency).
|
||||
* @package flatfile
|
||||
*/
|
||||
class OrWhereClause extends CompositeWhereClause
|
||||
{
|
||||
function testRow ($tablerow, $rowSchema = null) {
|
||||
foreach ($this->clauses as $clause) {
|
||||
if ($clause->testRow($tablerow, $rowSchema))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new OrWhereClause
|
||||
* @param WhereClause $whereClause,... optional unlimited list of WhereClause objects to be added
|
||||
*/
|
||||
function OrWhereClause() {
|
||||
$this->clauses = func_get_args();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link CompositeWhereClause CompositeWhereClause} that does an AND on all its
|
||||
* child WhereClauses.
|
||||
*
|
||||
* Use the {@link CompositeWhereClause::add() add()} method to add WhereClause objects
|
||||
* to the list of clauses to check. The testRow function of the resulting object
|
||||
* will then return false if any of its child clauses return false (and returns
|
||||
* true if no clauses have been added for consistency).
|
||||
* @package flatfile
|
||||
*/
|
||||
class AndWhereClause extends CompositeWhereClause
|
||||
{
|
||||
function testRow ($tablerow, $rowSchema = null) {
|
||||
foreach ($this->clauses as $clause) {
|
||||
if (!$clause->testRow($tablerow, $rowSchema))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AndWhereClause
|
||||
* @param WhereClause $whereClause,... optional unlimited list of WhereClause objects to be added
|
||||
*/
|
||||
function AndWhereClause() {
|
||||
$this->clauses = func_get_args();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////// ORDER BY CLASSES ////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Stores information about an ORDER BY clause
|
||||
*
|
||||
* Can be passed to selectWhere to order the output. It is easiest to use
|
||||
* the constructor to set the fields, rather than setting each individually
|
||||
* @package flatfile
|
||||
*/
|
||||
class OrderBy {
|
||||
/** @var int Index of field to order by */
|
||||
var $field;
|
||||
/** @var int Order type - ASCENDING or DESCENDING */
|
||||
var $orderType;
|
||||
/** @var string Comparison type - usually either DEFAULT_COMPARISON, STRING_COMPARISON, INTEGER_COMPARISION, or NUMERIC_COMPARISON*/
|
||||
var $compareAs;
|
||||
|
||||
/** Creates a new OrderBy structure
|
||||
*
|
||||
* The $compareAs parameter can be supplied using one of the pre-defined constants, but
|
||||
* this is actually implemented by defining the constants as names of functions to do the
|
||||
* comparison. You can therefore supply the name of any function that works like
|
||||
* {@link strcmp strcmp()} to implement custom ordering.
|
||||
* @param int $field The index of the field to order by
|
||||
* @param int $orderType ASCENDING or DESCENDING
|
||||
* @param int $compareAs Comparison type: DEFAULT_COMPARISON, STRING_COMPARISON, INTEGER_COMPARISION,
|
||||
* or NUMERIC_COMPARISON, or the name of a user defined function that you want to use for doing the comparison.
|
||||
*/
|
||||
function OrderBy($field, $orderType, $compareAs = DEFAULT_COMPARISON)
|
||||
{
|
||||
$this->field = $field;
|
||||
$this->orderType = $orderType;
|
||||
$this->compareAs = $compareAs;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the sorting defined by an array of OrderBy objects. This class
|
||||
* is used by {@link Flatfile::selectWhere()}
|
||||
* @access private
|
||||
* @package flatfile
|
||||
*/
|
||||
class Orderer {
|
||||
/**
|
||||
* @var array Stores the OrderBy objects
|
||||
* @access private
|
||||
*/
|
||||
var $orderByList;
|
||||
|
||||
/**
|
||||
* Creates new Orderer that will provide a sort function
|
||||
* @param mixed $orderBy An OrderBy object or an array of them
|
||||
* @param array $rowSchema Option row schema
|
||||
*/
|
||||
function Orderer($orderBy, $rowSchema = null) {
|
||||
if (!is_array($orderBy))
|
||||
$orderBy = array($orderBy);
|
||||
if ($rowSchema)
|
||||
{
|
||||
// Fix the comparison types
|
||||
foreach ($orderBy as $index => $discard)
|
||||
{
|
||||
$item =& $orderBy[$index]; // PHP4
|
||||
if ($item->compareAs == DEFAULT_COMPARISON)
|
||||
{
|
||||
$item->compareAs = get_comparison_type_for_col_type($rowSchema[$item->field]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->orderByList = $orderBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two table rows using the comparisons defined by the OrderBy
|
||||
* objects. This function is of the type that can be used passed to usort().
|
||||
*/
|
||||
function compare($row1, $row2) {
|
||||
return $this->compare_priv($row1, $row2, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*/
|
||||
function compare_priv($row1, $row2, $index)
|
||||
{
|
||||
$orderBy = $this->orderByList[$index];
|
||||
$cmpfunc = $orderBy->compareAs;
|
||||
if ($cmpfunc == DEFAULT_COMPARISON)
|
||||
{
|
||||
$cmpfunc = STRING_COMPARISON;
|
||||
}
|
||||
$cmp = $orderBy->orderType * $cmpfunc($row1[$orderBy->field], $row2[$orderBy->field]);
|
||||
if($cmp == 0) {
|
||||
if ($index == (count($this->orderByList) - 1))
|
||||
return 0;
|
||||
else
|
||||
return $this->compare_priv($row1, $row2, $index + 1);
|
||||
} else
|
||||
return $cmp;
|
||||
}
|
||||
}
|
||||
?>
|
112
inc/flatfile/.svn/text-base/flatfile_utils.php.svn-base
Normal file
112
inc/flatfile/.svn/text-base/flatfile_utils.php.svn-base
Normal file
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
// Utilities for flatfile functions
|
||||
|
||||
/** Constant to indicating a column holding floating point numbers */
|
||||
define('FLOAT_COL', 'float');
|
||||
/** Constant to indicating a column holding integers */
|
||||
define('INT_COL', 'int');
|
||||
/** Constant to indicating a column holding strings */
|
||||
define('STRING_COL', 'string');
|
||||
/** Constant to indicating a column holding unix timestamps */
|
||||
define('DATE_COL', 'date');
|
||||
|
||||
|
||||
/** EXPERIMENTAL: Encapsulates info about a column in a flatfile DB */
|
||||
class Column
|
||||
{
|
||||
/**
|
||||
* Create a new column object
|
||||
*/
|
||||
function Column($index, $type)
|
||||
{
|
||||
$this->index = $index;
|
||||
$this->type = $type;
|
||||
}
|
||||
}
|
||||
|
||||
/** EXPERIMENTAL: Represent a column that is a foreign key. Used for temporarily building tables array */
|
||||
class JoinColumn
|
||||
{
|
||||
function JoinColumn($index, $tablename, $columnname)
|
||||
{
|
||||
$this->index = $index;
|
||||
$this->tablename = $tablename;
|
||||
$this->columnname = $columnname;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* EXPERIMENTAL: Utilities for handling definitions of tables.
|
||||
*/
|
||||
class TableUtils
|
||||
{
|
||||
/**
|
||||
* Finds JoinColumns in an array of tables, and adds 'type' fields by looking up the columns
|
||||
*
|
||||
* @param tables This should be an associative array containing 'tablename' => tabledefinition
|
||||
* tabledefinition is itself an associativive array of 'COLUMN_NAME_CONSTANT' => columndefintion
|
||||
* COLUMN_NAME_CONSTANT should be a unique constant within the table, and
|
||||
* column definition should be a Column object or JoinColumn object
|
||||
*/
|
||||
function resolveJoins(&$tables)
|
||||
{
|
||||
foreach ($tables as $tablename => $discard)
|
||||
{
|
||||
// PHP4 compatible: can't do : foreach ($tables as $tablename => &$tabledef)
|
||||
// and strangely, if we do
|
||||
// foreach ($tables as $tablename => &$tabledef)
|
||||
// $tabledef =& $tables[$tablename];
|
||||
// then we get bugs
|
||||
$tabledef =& $tables[$tablename];
|
||||
foreach ($tabledef as $colname => $discard)
|
||||
{
|
||||
$coldef =& $tabledef[$colname]; // PHP4 compatible
|
||||
if (is_a($coldef, 'JoinColumn') or is_subclass_of($coldef, 'JoinColumn'))
|
||||
{
|
||||
TableUtils::resolveColumnJoin($coldef, $tables);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @access private */
|
||||
function resolveColumnJoin(&$columndef, &$tables)
|
||||
{
|
||||
// Doesn't work if the column it is joined to is also
|
||||
// a JoinColumn, but I can't think of ever wanting to do that
|
||||
$columndef->type = $tables[$columndef->tablename][$columndef->columnname]->type;
|
||||
}
|
||||
|
||||
/** Uses 'define' to create global constants for all the column names */
|
||||
function createDefines(&$tables)
|
||||
{
|
||||
foreach ($tables as $tablename => $discard)
|
||||
{
|
||||
$tabledef = &$tables[$tablename]; // PHP4 compatible
|
||||
foreach ($tabledef as $colname => $discard)
|
||||
{
|
||||
$coldef = &$tabledef[$colname];
|
||||
define(strtoupper($tablename) . '_' . $colname, $coldef->index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a 'row schema' for a given table definition.
|
||||
*
|
||||
* A row schema is just an array of the column types for a table,
|
||||
* using the constants defined above.
|
||||
*/
|
||||
function createRowSchema(&$tabledef)
|
||||
{
|
||||
$row_schema = array();
|
||||
foreach ($tabledef as $colname => $coldef)
|
||||
{
|
||||
$row_schema[$coldef->index] = $coldef->type;
|
||||
}
|
||||
return $row_schema;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
807
inc/flatfile/flatfile.php
Normal file
807
inc/flatfile/flatfile.php
Normal file
|
@ -0,0 +1,807 @@
|
|||
<?php
|
||||
/*
|
||||
Copyright (c) 2005 Luke Plant <L.Plant.98@cantab.net>
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Simple but powerful flatfile database
|
||||
* See http://lukeplant.me.uk/resources/flatfile/ for documentation and examples
|
||||
*
|
||||
* @tutorial flatfile.pkg
|
||||
* @package flatfile
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
*/
|
||||
|
||||
require_once('flatfile_utils.php');
|
||||
|
||||
/** Used to indicate the default comparison should be done, which is STRING_COMPARISON in the absence of a schema, or whatever the schema specifies if one has been added */
|
||||
define('DEFAULT_COMPARISON', '');
|
||||
/** Used to indicate a comparison should be done as a string comparison */
|
||||
define('STRING_COMPARISON', 'strcmp');
|
||||
/** Used to indicate a comparison should be done as an integer comparison */
|
||||
define('INTEGER_COMPARISON', 'intcmp');
|
||||
/** Used to indicate a comparison should be done as a numeric (float) comparison */
|
||||
define('NUMERIC_COMPARISON', 'numcmp');
|
||||
|
||||
/** Indicates ascending order */
|
||||
define('ASCENDING', 1);
|
||||
/** Indicates descending order */
|
||||
define('DESCENDING', -1);
|
||||
|
||||
$comparison_type_for_col_type = array(
|
||||
INT_COL => INTEGER_COMPARISON,
|
||||
DATE_COL => INTEGER_COMPARISON, // assume Unix timestamps
|
||||
STRING_COL => STRING_COMPARISON,
|
||||
FLOAT_COL => NUMERIC_COMPARISON
|
||||
);
|
||||
|
||||
function get_comparison_type_for_col_type($coltype)
|
||||
{
|
||||
global $comparison_type_for_col_type;
|
||||
return $comparison_type_for_col_type[$coltype];
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides simple but powerful flatfile database storage and retrieval
|
||||
*
|
||||
* Includes equivalents to SELECT * FROM table WHERE..., DELETE WHERE ...
|
||||
* UPDATE and more. All files are stored in the {@link Flatfile::$datadir $datadir} directory,
|
||||
* and table names are just filenames in that directory. Subdirectories
|
||||
* can be used just by specifying a table name that includes the directory name.
|
||||
* @package flatfile
|
||||
*/
|
||||
class Flatfile {
|
||||
/** @access private */
|
||||
var $tables;
|
||||
|
||||
/** @access private */
|
||||
var $schemata;
|
||||
|
||||
/** The directory to store files in.
|
||||
* @var string
|
||||
*/
|
||||
var $datadir;
|
||||
|
||||
function Flatfile()
|
||||
{
|
||||
$this->schemata = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all rows from a table
|
||||
* @param string $tablename The table to get rows from
|
||||
* @return array The table as an array of rows, where each row is an array of columns
|
||||
*/
|
||||
function selectAll ($tablename) {
|
||||
if (!isset($this->tables[$tablename]))
|
||||
$this->loadTable($tablename);
|
||||
return $this->tables[$tablename];
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects rows from a table that match the specified criteria
|
||||
*
|
||||
* This simulates the following SQL query:
|
||||
* <pre>
|
||||
* SELECT LIMIT $limit * FROM $tablename
|
||||
* WHERE $whereclause
|
||||
* ORDER BY $orderBy [ASC | DESC] [, $orderBy2 ...]
|
||||
* </pre>
|
||||
*
|
||||
* @param string $tablename The table (file) to get the data from
|
||||
* @param object $whereClause Either a {@link WhereClause WhereClause} object to do selection of rows, or NULL to select all
|
||||
* @param mixed $limit Specifies limits for the rows returned:
|
||||
* - use -1 or omitted to return all rows
|
||||
* - use an integer n to return the first n rows
|
||||
* - use a two item array ($startrow, $endrow) to return rows $startrow to $endrow - 1 (zero indexed)
|
||||
* - use a two item array ($startrow, -1) to return rows $startrow to the end (zero indexed)
|
||||
* @param mixed $orderBy Either an {@link OrderBy} object or an array of them, defining the sorting that should be applied (if an array, then the first object in the array is the first key to sort on etc). Use NULL for no sorting.
|
||||
* @return array The matching data, as an array of rows, where each row is an array of columns
|
||||
*/
|
||||
function selectWhere ($tablename, $whereClause, $limit = -1, $orderBy = NULL) {
|
||||
if (!isset($this->tables[$tablename]))
|
||||
$this->loadTable($tablename);
|
||||
|
||||
$table = $this->selectAll($tablename); // Get a copy
|
||||
|
||||
$schema = $this->getSchema($tablename);
|
||||
if ($orderBy !== NULL)
|
||||
usort($table, $this->getOrderByFunction($orderBy, $schema));
|
||||
|
||||
$results = array();
|
||||
$count = 0;
|
||||
|
||||
if ($limit == -1)
|
||||
$limit = array(0, -1);
|
||||
else if (!is_array($limit))
|
||||
$limit = array(0, $limit);
|
||||
|
||||
foreach ($table as $row) {
|
||||
if ($whereClause === NULL || $whereClause->testRow($row, $schema)) {
|
||||
if ($count >= $limit[0])
|
||||
$results[] = $row;
|
||||
++$count;
|
||||
if (($count >= $limit[1]) && ($limit[1] != -1))
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select a row using a unique ID
|
||||
* @param string $tablename The table to get data from
|
||||
* @param string $idField The index of the field containing the ID
|
||||
* @param string $id The ID to search for
|
||||
* @return array The row of the table as an array
|
||||
*/
|
||||
function selectUnique ($tablename, $idField, $id) {
|
||||
$result = $this->selectWhere($tablename, new SimpleWhereClause($idField, '=', $id));
|
||||
if (count($result) > 0)
|
||||
return $result[0];
|
||||
else
|
||||
return array();
|
||||
}
|
||||
|
||||
/*
|
||||
* To correctly write a file, and not overwrite the changes
|
||||
* another process is making, we need to:
|
||||
* - get a lock for writing
|
||||
* - read its contents from disc
|
||||
* - modify the contents in memory
|
||||
* - write the contents
|
||||
* - release lock
|
||||
* Because opening for writing truncates the file, we must get
|
||||
* the lock on a different file. getLock and releaseLock
|
||||
* are helper functions to allow us to do this with little fuss
|
||||
*/
|
||||
|
||||
/** Get a lock for writing a file
|
||||
* @access private
|
||||
*/
|
||||
function getLock ($tablename)
|
||||
{
|
||||
ignore_user_abort(true);
|
||||
$fp = fopen($this->datadir . $tablename.'.lock','w');
|
||||
if (!flock($fp, LOCK_EX)) {
|
||||
// log error?
|
||||
}
|
||||
$this->loadTable($tablename);
|
||||
return $fp;
|
||||
}
|
||||
|
||||
/** Release a lock
|
||||
* @access private
|
||||
*/
|
||||
function releaseLock ($lockfp)
|
||||
{
|
||||
flock($lockfp, LOCK_UN);
|
||||
ignore_user_abort(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a row with an automatically generated ID
|
||||
*
|
||||
* The autogenerated ID will be the highest ID in the column so far plus one. The
|
||||
* supplied row should include all fields required for the table, and the
|
||||
* ID field it contains will just be ignored
|
||||
*
|
||||
* @param string $tablename The table to insert data into
|
||||
* @param int $idField The index of the field which is the ID field
|
||||
* @param array $newRow The new row to add to the table
|
||||
* @return int The newly assigned ID
|
||||
*/
|
||||
function insertWithAutoId ($tablename, $idField, $newRow)
|
||||
{
|
||||
$lockfp = $this->getLock($tablename);
|
||||
$rows = $this->selectWhere($tablename, null, 1,
|
||||
new OrderBy($idField, DESCENDING, INTEGER_COMPARISON));
|
||||
if ($rows) {
|
||||
$newId = $rows[0][$idField] + 1;
|
||||
} else {
|
||||
$newId = 1;
|
||||
}
|
||||
$newRow[$idField] = $newId;
|
||||
$this->tables[$tablename][] = $newRow;
|
||||
$this->writeTable($tablename);
|
||||
$this->releaseLock($lockfp);
|
||||
return $newId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a row in a table
|
||||
*
|
||||
* @param string $tablename The table to insert data into
|
||||
* @param array $newRow The new row to add to the table
|
||||
*/
|
||||
function insert ($tablename, $newRow)
|
||||
{
|
||||
$lockfp = $this->getLock($tablename);
|
||||
$this->tables[$tablename][] = $newRow;
|
||||
$this->writeTable($tablename);
|
||||
$this->releaseLock($lockfp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing row using a unique ID
|
||||
*
|
||||
* @param string $tablename The table to update
|
||||
* @param int $idField The index of the field which is the ID field
|
||||
* @param array $updatedRow The updated row to add to the table
|
||||
*/
|
||||
function updateRowById ($tablename, $idField, $updatedRow)
|
||||
{
|
||||
$this->updateSetWhere($tablename, $updatedRow,
|
||||
new SimpleWhereClause($idField, '=', $updatedRow[$idField]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates fields in a table for rows that match the provided criteria
|
||||
*
|
||||
* $newFields can be a complete row or it can be a sparsely populated
|
||||
* hashtable of values (where the keys are integers which are the column
|
||||
* indexes to update)
|
||||
*
|
||||
* @param string $tablename The table to update
|
||||
* @param array $newFields A hashtable (with integer keys) of fields to update
|
||||
* @param WhereClause $whereClause The criteria or NULL to update all rows
|
||||
*/
|
||||
function updateSetWhere ($tablename, $newFields, $whereClause)
|
||||
{
|
||||
$schema = $this->getSchema($tablename);
|
||||
$lockfp = $this->getLock($tablename);
|
||||
for ($i = 0; $i < count($this->tables[$tablename]); ++$i) {
|
||||
if ($whereClause === NULL ||
|
||||
$whereClause->testRow($this->tables[$tablename][$i], $schema)) {
|
||||
foreach ($newFields as $k => $v)
|
||||
{
|
||||
$this->tables[$tablename][$i][$k] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->writeTable($tablename);
|
||||
$this->releaseLock($lockfp);
|
||||
$this->loadTable($tablename);
|
||||
}
|
||||
/**
|
||||
* Deletes all rows in a table that match specified criteria
|
||||
*
|
||||
* @param string $tablename The table to alter
|
||||
* @param object $whereClause. {@link WhereClause WhereClause} object that will select
|
||||
* rows to be deleted. All rows are deleted if $whereClause === NULL
|
||||
*/
|
||||
function deleteWhere ($tablename, $whereClause) {
|
||||
$schema = $this->getSchema($tablename);
|
||||
$lockfp = $this->getLock($tablename);
|
||||
for ($i = count($this->tables[$tablename]) - 1; $i >= 0 ; --$i) {
|
||||
if ($whereClause === NULL ||
|
||||
$whereClause->testRow($this->tables[$tablename][$i], $schema)) {
|
||||
unset($this->tables[$tablename][$i]);
|
||||
}
|
||||
}
|
||||
$this->writeTable($tablename);
|
||||
$this->releaseLock($lockfp);
|
||||
$this->loadTable($tablename); // reset array indexes
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all rows in a table
|
||||
*
|
||||
* @param string $tablename The table to alter
|
||||
*/
|
||||
function deleteAll ($tablename) {
|
||||
$this->deleteWhere($tablename, NULL);
|
||||
}
|
||||
|
||||
/**#@+
|
||||
* @access private
|
||||
*/
|
||||
|
||||
/** Gets a function that can be passed to usort to do the ORDER BY clause
|
||||
* @param mixed $orderBy Either an OrderBy object or an array of them
|
||||
* @return string function name
|
||||
*/
|
||||
function getOrderByFunction ($orderBy, $rowSchema = null)
|
||||
{
|
||||
$orderer = new Orderer($orderBy, $rowSchema);
|
||||
return array(&$orderer, 'compare');
|
||||
}
|
||||
|
||||
function loadTable ($tablename) {
|
||||
$filedata = @file($this->datadir . $tablename);
|
||||
$table = array();
|
||||
if (is_array($filedata)) {
|
||||
foreach ($filedata as $line) {
|
||||
$line = rtrim($line, "\n");
|
||||
$table[] = explode("\t", $line);
|
||||
}
|
||||
}
|
||||
$this->tables[$tablename] = $table;
|
||||
}
|
||||
|
||||
function writeTable ($tablename) {
|
||||
$output = '';
|
||||
|
||||
foreach ($this->tables[$tablename] as $row) {
|
||||
$keys = array_keys($row);
|
||||
rsort($keys, SORT_NUMERIC);
|
||||
$max = $keys[0];
|
||||
for ($i = 0; $i <= $max; ++$i) {
|
||||
if ($i > 0) $output .= "\t";
|
||||
$data = (empty($row[$i]) ? '' : $row[$i]);
|
||||
$output .= str_replace(array("\t","\r","\n"), array(''), $data);
|
||||
}
|
||||
$output .= "\n";
|
||||
}
|
||||
$fp = @fopen($this->datadir . $tablename, "w");
|
||||
fwrite($fp, $output, strlen($output));
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
/**#@-*/
|
||||
/**
|
||||
* Adds a schema definition to the DB for a specified regular expression
|
||||
*
|
||||
* Schemas are optional, and are only used for automatically determining
|
||||
* the comparison types that should be used when sorting and selecting.
|
||||
*
|
||||
* @param string $fileregex A regular expression used to match filenames
|
||||
* @param string $rowSchema An array specifying the column types for data
|
||||
* files that match the regex, using constants defined in flatfile_utils.php
|
||||
*/
|
||||
function addSchema($fileregex, $rowSchema)
|
||||
{
|
||||
array_push($this->schemata, array($fileregex, $rowSchema));
|
||||
}
|
||||
|
||||
/** Retrieves the schema for a given filename */
|
||||
function getSchema($filename)
|
||||
{
|
||||
foreach ($this->schemata as $rowSchemaPair)
|
||||
{
|
||||
$fileregex = $rowSchemaPair[0];
|
||||
if (preg_match($fileregex, $filename))
|
||||
{
|
||||
return $rowSchemaPair[1];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/////////////////////////// UTILITY FUNCTIONS ////////////////////////////////////
|
||||
|
||||
/**
|
||||
* equivalent of strcmp for comparing integers, used internally for sorting and comparing
|
||||
*/
|
||||
function intcmp ($a, $b)
|
||||
{
|
||||
return (int)$a - (int)$b;
|
||||
}
|
||||
|
||||
/**
|
||||
* equivalent of strcmp for comparing floats, used internally for sorting and comparing
|
||||
*/
|
||||
function numcmp ($a, $b)
|
||||
{
|
||||
return (float)$a - (float)$b;
|
||||
}
|
||||
|
||||
/////////////////////////// WHERE CLAUSE CLASSES ////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Used to test rows in a database table, like the WHERE clause in an SQL statement.
|
||||
*
|
||||
* @abstract
|
||||
* @package flatfile
|
||||
*/
|
||||
class WhereClause
|
||||
{
|
||||
/**
|
||||
* Tests a table row object
|
||||
* @abstract
|
||||
* @param array $row The row to test
|
||||
* @param array $rowSchema An optional array specifying the schema of the table, using the INT_COL, STRING_COL etc constants
|
||||
* @return bool True if the $row passes the WhereClause
|
||||
* selection criteria, false otherwise
|
||||
*/
|
||||
function testRow ($row, $rowSchema = null) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Negates a where clause
|
||||
* @package flatfile
|
||||
*/
|
||||
class NotWhere extends WhereClause
|
||||
{
|
||||
/** @access private */
|
||||
var $clause;
|
||||
|
||||
/**
|
||||
* Contructs a new NotWhere object
|
||||
*
|
||||
* The constructed WhereClause will return the negation
|
||||
* of the WhereClause object passed in when testing rows.
|
||||
* @param WhereClause $whereclause The WhereClause object to negate
|
||||
*/
|
||||
function NotWhere ($whereclause)
|
||||
{
|
||||
$this->clause = $whereclause;
|
||||
}
|
||||
|
||||
function testRow ($row, $rowSchema = null) {
|
||||
return !$this->clause->testRow($row, $rowSchema);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements a single WHERE clause that does simple comparisons of a field
|
||||
* with a value.
|
||||
*
|
||||
* @package flatfile
|
||||
*/
|
||||
class SimpleWhereClause extends WhereClause
|
||||
{
|
||||
/**#@+
|
||||
* @access private
|
||||
*/
|
||||
var $field;
|
||||
var $operator;
|
||||
var $value;
|
||||
var $compare_type;
|
||||
/**#@-*/
|
||||
|
||||
/**
|
||||
* Creates a new {@link WhereClause WhereClause} object that does a comparison
|
||||
* of a field and a value.
|
||||
*
|
||||
* This will be the most commonly used type of WHERE clause. It can do comparisons
|
||||
* of the sort "$tablerow[$field] operator $value"
|
||||
* where 'operator' is one of:<br>
|
||||
* - = (equals)
|
||||
* - != (not equals)
|
||||
* - > (greater than)
|
||||
* - < (less than)
|
||||
* - >= (greater than or equal to)
|
||||
* - <= (less than or equal to)
|
||||
* There are 3 pre-defined constants (STRING_COMPARISON, NUMERIC COMPARISON and
|
||||
* INTEGER_COMPARISON) that modify the behaviour of these operators to do the comparison
|
||||
* as strings, floats and integers respectively. Howevers, these constants are
|
||||
* just the names of functions that do the comparison (the first being the builtin
|
||||
* function {@link strcmp strcmp()}, so you can supply your own function here to customise the
|
||||
* behaviour of this class.
|
||||
*
|
||||
* @param int $field The index (in the table row) of the field to test
|
||||
* @param string $operator The comparison operator, one of "=", "!=", "<", ">", "<=", ">="
|
||||
* @param mixed $value The value to compare to.
|
||||
* @param string $compare_type The comparison method to use - either
|
||||
* STRING_COMPARISON (default), NUMERIC COMPARISON or INTEGER_COMPARISON
|
||||
*
|
||||
*/
|
||||
function SimpleWhereClause ($field, $operator, $value, $compare_type = DEFAULT_COMPARISON)
|
||||
{
|
||||
$this->field = $field;
|
||||
$this->operator = $operator;
|
||||
$this->value = $value;
|
||||
$this->compare_type = $compare_type;
|
||||
}
|
||||
|
||||
function testRow ($tablerow, $rowSchema = null) {
|
||||
if ($this->field < 0)
|
||||
return TRUE;
|
||||
|
||||
$cmpfunc = $this->compare_type;
|
||||
if ($cmpfunc == DEFAULT_COMPARISON)
|
||||
{
|
||||
if ($rowSchema != null)
|
||||
{
|
||||
$cmpfunc = get_comparison_type_for_col_type($rowSchema[$this->field]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$cmpfunc = STRING_COMPARISON;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->field >= count($tablerow)) {
|
||||
$dbval = "";
|
||||
} else {
|
||||
$dbval = $tablerow[$this->field];
|
||||
}
|
||||
$cmp = $cmpfunc($dbval, $this->value);
|
||||
if ($this->operator == '=')
|
||||
return ($cmp == 0);
|
||||
else if ($this->operator == '!=')
|
||||
return ($cmp != 0);
|
||||
else if ($this->operator == '>')
|
||||
return ($cmp > 0);
|
||||
else if ($this->operator == '<')
|
||||
return ($cmp < 0);
|
||||
else if ($this->operator == '<=')
|
||||
return ($cmp <= 0);
|
||||
else if ($this->operator == '>=')
|
||||
return ($cmp >= 0);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link WhereClause WhereClause} class to work like a SQL 'LIKE' clause
|
||||
* @package flatfile
|
||||
*/
|
||||
class LikeWhereClause extends WhereClause
|
||||
{
|
||||
/**
|
||||
* Creates a new LikeWhereClause
|
||||
*
|
||||
* @param int $field Index of the field to look at
|
||||
* @param string $value Value to look for. Supports using '%' as a
|
||||
* wildcard, and is case insensitve. e.g. 'test%' will match 'TESTS' and 'Testing'
|
||||
*/
|
||||
|
||||
function LikeWhereClause ($field, $value)
|
||||
{
|
||||
$this->field = $field;
|
||||
$this->regexp = '/^' . str_replace('%','.*', preg_quote($value)) . '$/i';
|
||||
}
|
||||
|
||||
function testRow ($tablerow) {
|
||||
return preg_match($this->regexp, $tablerow[$this->field]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@link WhereClause WhereClause} class to match a value from a list of items
|
||||
* @package flatfile
|
||||
*/
|
||||
class ListWhereClause extends WhereClause {
|
||||
|
||||
/** @access private */
|
||||
var $field;
|
||||
/** @access private */
|
||||
var $list;
|
||||
/** @access private */
|
||||
var $compareAs;
|
||||
|
||||
/**
|
||||
* Creates a new ListWhereClause object
|
||||
*
|
||||
* The resulting WhereClause will pass rows (return true) if the value of the specified
|
||||
* field is in the array.
|
||||
*
|
||||
* @param int $field Field to match
|
||||
* @param array $list List of items
|
||||
* @param string $compare_type Comparison type, string by default.
|
||||
*/
|
||||
function ListWhereClause ($field, $list, $compare_type = DEFAULT_COMPARISON) {
|
||||
$this->list = $list;
|
||||
$this->field = (int)$field;
|
||||
$this->compareAs = $compare_type;
|
||||
}
|
||||
|
||||
function testRow ($tablerow, $rowSchema = null) {
|
||||
$func = $this->compareAs;
|
||||
if ($func == DEFAULT_COMPARISON)
|
||||
{
|
||||
if ($rowSchema)
|
||||
{
|
||||
$func = get_comparison_type_for_col_type($rowSchema[$this->field]);
|
||||
}
|
||||
else
|
||||
{
|
||||
$func = STRING_COMPARISON;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->list as $item)
|
||||
{
|
||||
if ($func($tablerow[$this->field], $item) == 0)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract class that combines zero or more {@link WhereClause WhereClause} objects
|
||||
* together.
|
||||
* @package flatfile
|
||||
*/
|
||||
class CompositeWhereClause extends WhereClause
|
||||
{
|
||||
/**
|
||||
* @var array Stores the child clauses
|
||||
* @access protected
|
||||
*/
|
||||
var $clauses = array();
|
||||
|
||||
/**
|
||||
* Add a {@link WhereClause WhereClause} to the list of clauses to be used for testing
|
||||
* @param WhereClause $whereClause The WhereClause object to add
|
||||
*/
|
||||
function add ($whereClause)
|
||||
{
|
||||
$this->clauses[] = $whereClause;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link CompositeWhereClause CompositeWhereClause} that does an OR on all its
|
||||
* child WhereClauses.
|
||||
*
|
||||
* Use the {@link CompositeWhereClause::add() add()} method and/or the constructor
|
||||
* to add WhereClause objects
|
||||
* to the list of clauses to check. The testRow function of the resulting object
|
||||
* will then return true if any of its child clauses return true (and returns
|
||||
* false if no clauses have been added for consistency).
|
||||
* @package flatfile
|
||||
*/
|
||||
class OrWhereClause extends CompositeWhereClause
|
||||
{
|
||||
function testRow ($tablerow, $rowSchema = null) {
|
||||
foreach ($this->clauses as $clause) {
|
||||
if ($clause->testRow($tablerow, $rowSchema))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new OrWhereClause
|
||||
* @param WhereClause $whereClause,... optional unlimited list of WhereClause objects to be added
|
||||
*/
|
||||
function OrWhereClause() {
|
||||
$this->clauses = func_get_args();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link CompositeWhereClause CompositeWhereClause} that does an AND on all its
|
||||
* child WhereClauses.
|
||||
*
|
||||
* Use the {@link CompositeWhereClause::add() add()} method to add WhereClause objects
|
||||
* to the list of clauses to check. The testRow function of the resulting object
|
||||
* will then return false if any of its child clauses return false (and returns
|
||||
* true if no clauses have been added for consistency).
|
||||
* @package flatfile
|
||||
*/
|
||||
class AndWhereClause extends CompositeWhereClause
|
||||
{
|
||||
function testRow ($tablerow, $rowSchema = null) {
|
||||
foreach ($this->clauses as $clause) {
|
||||
if (!$clause->testRow($tablerow, $rowSchema))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AndWhereClause
|
||||
* @param WhereClause $whereClause,... optional unlimited list of WhereClause objects to be added
|
||||
*/
|
||||
function AndWhereClause() {
|
||||
$this->clauses = func_get_args();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////// ORDER BY CLASSES ////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Stores information about an ORDER BY clause
|
||||
*
|
||||
* Can be passed to selectWhere to order the output. It is easiest to use
|
||||
* the constructor to set the fields, rather than setting each individually
|
||||
* @package flatfile
|
||||
*/
|
||||
class OrderBy {
|
||||
/** @var int Index of field to order by */
|
||||
var $field;
|
||||
/** @var int Order type - ASCENDING or DESCENDING */
|
||||
var $orderType;
|
||||
/** @var string Comparison type - usually either DEFAULT_COMPARISON, STRING_COMPARISON, INTEGER_COMPARISION, or NUMERIC_COMPARISON*/
|
||||
var $compareAs;
|
||||
|
||||
/** Creates a new OrderBy structure
|
||||
*
|
||||
* The $compareAs parameter can be supplied using one of the pre-defined constants, but
|
||||
* this is actually implemented by defining the constants as names of functions to do the
|
||||
* comparison. You can therefore supply the name of any function that works like
|
||||
* {@link strcmp strcmp()} to implement custom ordering.
|
||||
* @param int $field The index of the field to order by
|
||||
* @param int $orderType ASCENDING or DESCENDING
|
||||
* @param int $compareAs Comparison type: DEFAULT_COMPARISON, STRING_COMPARISON, INTEGER_COMPARISION,
|
||||
* or NUMERIC_COMPARISON, or the name of a user defined function that you want to use for doing the comparison.
|
||||
*/
|
||||
function OrderBy($field, $orderType, $compareAs = DEFAULT_COMPARISON)
|
||||
{
|
||||
$this->field = $field;
|
||||
$this->orderType = $orderType;
|
||||
$this->compareAs = $compareAs;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements the sorting defined by an array of OrderBy objects. This class
|
||||
* is used by {@link Flatfile::selectWhere()}
|
||||
* @access private
|
||||
* @package flatfile
|
||||
*/
|
||||
class Orderer {
|
||||
/**
|
||||
* @var array Stores the OrderBy objects
|
||||
* @access private
|
||||
*/
|
||||
var $orderByList;
|
||||
|
||||
/**
|
||||
* Creates new Orderer that will provide a sort function
|
||||
* @param mixed $orderBy An OrderBy object or an array of them
|
||||
* @param array $rowSchema Option row schema
|
||||
*/
|
||||
function Orderer($orderBy, $rowSchema = null) {
|
||||
if (!is_array($orderBy))
|
||||
$orderBy = array($orderBy);
|
||||
if ($rowSchema)
|
||||
{
|
||||
// Fix the comparison types
|
||||
foreach ($orderBy as $index => $discard)
|
||||
{
|
||||
$item =& $orderBy[$index]; // PHP4
|
||||
if ($item->compareAs == DEFAULT_COMPARISON)
|
||||
{
|
||||
$item->compareAs = get_comparison_type_for_col_type($rowSchema[$item->field]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->orderByList = $orderBy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares two table rows using the comparisons defined by the OrderBy
|
||||
* objects. This function is of the type that can be used passed to usort().
|
||||
*/
|
||||
function compare($row1, $row2) {
|
||||
return $this->compare_priv($row1, $row2, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*/
|
||||
function compare_priv($row1, $row2, $index)
|
||||
{
|
||||
$orderBy = $this->orderByList[$index];
|
||||
$cmpfunc = $orderBy->compareAs;
|
||||
if ($cmpfunc == DEFAULT_COMPARISON)
|
||||
{
|
||||
$cmpfunc = STRING_COMPARISON;
|
||||
}
|
||||
$cmp = $orderBy->orderType * $cmpfunc($row1[$orderBy->field], $row2[$orderBy->field]);
|
||||
if($cmp == 0) {
|
||||
if ($index == (count($this->orderByList) - 1))
|
||||
return 0;
|
||||
else
|
||||
return $this->compare_priv($row1, $row2, $index + 1);
|
||||
} else
|
||||
return $cmp;
|
||||
}
|
||||
}
|
||||
?>
|
112
inc/flatfile/flatfile_utils.php
Normal file
112
inc/flatfile/flatfile_utils.php
Normal file
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
|
||||
// Utilities for flatfile functions
|
||||
|
||||
/** Constant to indicating a column holding floating point numbers */
|
||||
define('FLOAT_COL', 'float');
|
||||
/** Constant to indicating a column holding integers */
|
||||
define('INT_COL', 'int');
|
||||
/** Constant to indicating a column holding strings */
|
||||
define('STRING_COL', 'string');
|
||||
/** Constant to indicating a column holding unix timestamps */
|
||||
define('DATE_COL', 'date');
|
||||
|
||||
|
||||
/** EXPERIMENTAL: Encapsulates info about a column in a flatfile DB */
|
||||
class Column
|
||||
{
|
||||
/**
|
||||
* Create a new column object
|
||||
*/
|
||||
function Column($index, $type)
|
||||
{
|
||||
$this->index = $index;
|
||||
$this->type = $type;
|
||||
}
|
||||
}
|
||||
|
||||
/** EXPERIMENTAL: Represent a column that is a foreign key. Used for temporarily building tables array */
|
||||
class JoinColumn
|
||||
{
|
||||
function JoinColumn($index, $tablename, $columnname)
|
||||
{
|
||||
$this->index = $index;
|
||||
$this->tablename = $tablename;
|
||||
$this->columnname = $columnname;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* EXPERIMENTAL: Utilities for handling definitions of tables.
|
||||
*/
|
||||
class TableUtils
|
||||
{
|
||||
/**
|
||||
* Finds JoinColumns in an array of tables, and adds 'type' fields by looking up the columns
|
||||
*
|
||||
* @param tables This should be an associative array containing 'tablename' => tabledefinition
|
||||
* tabledefinition is itself an associativive array of 'COLUMN_NAME_CONSTANT' => columndefintion
|
||||
* COLUMN_NAME_CONSTANT should be a unique constant within the table, and
|
||||
* column definition should be a Column object or JoinColumn object
|
||||
*/
|
||||
function resolveJoins(&$tables)
|
||||
{
|
||||
foreach ($tables as $tablename => $discard)
|
||||
{
|
||||
// PHP4 compatible: can't do : foreach ($tables as $tablename => &$tabledef)
|
||||
// and strangely, if we do
|
||||
// foreach ($tables as $tablename => &$tabledef)
|
||||
// $tabledef =& $tables[$tablename];
|
||||
// then we get bugs
|
||||
$tabledef =& $tables[$tablename];
|
||||
foreach ($tabledef as $colname => $discard)
|
||||
{
|
||||
$coldef =& $tabledef[$colname]; // PHP4 compatible
|
||||
if (is_a($coldef, 'JoinColumn') or is_subclass_of($coldef, 'JoinColumn'))
|
||||
{
|
||||
TableUtils::resolveColumnJoin($coldef, $tables);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** @access private */
|
||||
function resolveColumnJoin(&$columndef, &$tables)
|
||||
{
|
||||
// Doesn't work if the column it is joined to is also
|
||||
// a JoinColumn, but I can't think of ever wanting to do that
|
||||
$columndef->type = $tables[$columndef->tablename][$columndef->columnname]->type;
|
||||
}
|
||||
|
||||
/** Uses 'define' to create global constants for all the column names */
|
||||
function createDefines(&$tables)
|
||||
{
|
||||
foreach ($tables as $tablename => $discard)
|
||||
{
|
||||
$tabledef = &$tables[$tablename]; // PHP4 compatible
|
||||
foreach ($tabledef as $colname => $discard)
|
||||
{
|
||||
$coldef = &$tabledef[$colname];
|
||||
define(strtoupper($tablename) . '_' . $colname, $coldef->index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a 'row schema' for a given table definition.
|
||||
*
|
||||
* A row schema is just an array of the column types for a table,
|
||||
* using the constants defined above.
|
||||
*/
|
||||
function createRowSchema(&$tabledef)
|
||||
{
|
||||
$row_schema = array();
|
||||
foreach ($tabledef as $colname => $coldef)
|
||||
{
|
||||
$row_schema[$coldef->index] = $coldef->type;
|
||||
}
|
||||
return $row_schema;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
262
inc/functions.php
Normal file
262
inc/functions.php
Normal file
|
@ -0,0 +1,262 @@
|
|||
<?php
|
||||
if (!isset($tinyib)) { die(''); }
|
||||
|
||||
function cleanString($string) {
|
||||
$search = array("<", ">");
|
||||
$replace = array("<", ">");
|
||||
|
||||
return str_replace($search, $replace, $string);
|
||||
}
|
||||
|
||||
function threadUpdated($id) {
|
||||
rebuildThread($id);
|
||||
rebuildIndexes();
|
||||
}
|
||||
|
||||
function newPost() {
|
||||
return array('parent' => '0',
|
||||
'timestamp' => '0',
|
||||
'bumped' => '0',
|
||||
'ip' => '',
|
||||
'name' => '',
|
||||
'tripcode' => '',
|
||||
'email' => '',
|
||||
'nameblock' => '',
|
||||
'subject' => '',
|
||||
'message' => '',
|
||||
'password' => '',
|
||||
'file' => '',
|
||||
'file_hex' => '',
|
||||
'file_original' => '',
|
||||
'file_size' => '0',
|
||||
'file_size_formatted' => '',
|
||||
'image_width' => '0',
|
||||
'image_height' => '0',
|
||||
'thumb' => '',
|
||||
'thumb_width' => '0',
|
||||
'thumb_height' => '0');
|
||||
}
|
||||
|
||||
function convertBytes($number) {
|
||||
$len = strlen($number);
|
||||
if ($len < 4) {
|
||||
return sprintf("%dB", $number);
|
||||
} elseif ($len <= 6) {
|
||||
return sprintf("%0.2fKB", $number/1024);
|
||||
} elseif ($len <= 9) {
|
||||
return sprintf("%0.2fMB", $number/1024/1024);
|
||||
}
|
||||
|
||||
return sprintf("%0.2fGB", $number/1024/1024/1024);
|
||||
}
|
||||
|
||||
function nameAndTripcode($name) {
|
||||
global $tinyib;
|
||||
|
||||
if (ereg("(#|!)(.*)", $name, $regs)) {
|
||||
$cap = $regs[2];
|
||||
$cap_full = '#' . $regs[2];
|
||||
|
||||
if (function_exists('mb_convert_encoding')) {
|
||||
$recoded_cap = mb_convert_encoding($cap, 'SJIS', 'UTF-8');
|
||||
if ($recoded_cap != '') {
|
||||
$cap = $recoded_cap;
|
||||
}
|
||||
}
|
||||
|
||||
if (strpos($name, '#') === false) {
|
||||
$cap_delimiter = '!';
|
||||
} elseif (strpos($name, '!') === false) {
|
||||
$cap_delimiter = '#';
|
||||
} else {
|
||||
$cap_delimiter = (strpos($name, '#') < strpos($name, '!')) ? '#' : '!';
|
||||
}
|
||||
|
||||
if (ereg("(.*)(" . $cap_delimiter . ")(.*)", $cap, $regs_secure)) {
|
||||
$cap = $regs_secure[1];
|
||||
$cap_secure = $regs_secure[3];
|
||||
$is_secure_trip = true;
|
||||
} else {
|
||||
$is_secure_trip = false;
|
||||
}
|
||||
|
||||
$tripcode = "";
|
||||
if ($cap != "") {
|
||||
/* From Futabally */
|
||||
$cap = strtr($cap, "&", "&");
|
||||
$cap = strtr($cap, ",", ", ");
|
||||
$salt = substr($cap."H.", 1, 2);
|
||||
$salt = ereg_replace("[^\.-z]", ".", $salt);
|
||||
$salt = strtr($salt, ":;<=>?@[\\]^_`", "ABCDEFGabcdef");
|
||||
$tripcode = substr(crypt($cap, $salt), -10);
|
||||
}
|
||||
|
||||
if ($is_secure_trip) {
|
||||
if ($cap != "") {
|
||||
$tripcode .= "!";
|
||||
}
|
||||
|
||||
$tripcode .= "!" . substr(md5($cap_secure . $tinyib['tripcodeseed']), 2, 10);
|
||||
}
|
||||
|
||||
return array(ereg_replace("(" . $cap_delimiter . ")(.*)", "", $name), $tripcode);
|
||||
}
|
||||
|
||||
return array($name, "");
|
||||
}
|
||||
|
||||
function nameBlock($name, $tripcode, $email, $timestamp) {
|
||||
$output = "";
|
||||
|
||||
if ($name == "" && $tripcode == "") {
|
||||
$output .= "Anonymous";
|
||||
} else {
|
||||
$output .= $name;
|
||||
}
|
||||
|
||||
if ($tripcode != "") {
|
||||
$output .= '</span><span class="postertrip">!' . $tripcode;
|
||||
}
|
||||
|
||||
if ($email != "") {
|
||||
$output = '<a href="mailto:' . $email . '">' . $output . '</a>';
|
||||
}
|
||||
|
||||
return '<span class="postername">' . $output . '</span> ' . date('y/m/d(D)H:i:s', $timestamp);
|
||||
}
|
||||
|
||||
function writePage($filename, $contents) {
|
||||
global $tinyib;
|
||||
|
||||
$tempfile = tempnam('res/', $tinyib['board'] . 'tmp'); /* Create the temporary file */
|
||||
$fp = fopen($tempfile, 'w');
|
||||
fwrite($fp, $contents);
|
||||
fclose($fp);
|
||||
/* If we aren't able to use the rename function, try the alternate method */
|
||||
if (!@rename($tempfile, $filename)) {
|
||||
copy($tempfile, $filename);
|
||||
unlink($tempfile);
|
||||
}
|
||||
|
||||
chmod($filename, 0664); /* it was created 0600 */
|
||||
}
|
||||
|
||||
function fixLinksInRes($html) {
|
||||
$search = array(' href="css/', ' href="src/', ' href="thumb/', ' href="res/', ' href="imgboard.php', ' href="favicon.ico', 'src="thumb/', ' action="imgboard.php');
|
||||
$replace = array(' href="../css/', ' href="../src/', ' href="../thumb/', ' href="../res/', ' href="../imgboard.php', ' href="../favicon.ico', 'src="../thumb/', ' action="../imgboard.php');
|
||||
|
||||
return str_replace($search, $replace, $html);
|
||||
}
|
||||
|
||||
function colorQuote($message) {
|
||||
if (substr($message, -1, 1) != "\n") { $message .= "\n"; }
|
||||
return preg_replace('/^(>[^\>](.*))\n/m', '<span class="unkfunc">\\1</span>' . "\n", $message);
|
||||
}
|
||||
|
||||
function deletePostImages($post) {
|
||||
if ($post['file'] != '') { @unlink('src/' . $post['file']); }
|
||||
if ($post['thumb'] != '') { @unlink('thumb/' . $post['thumb']); }
|
||||
}
|
||||
|
||||
function manageCheckLogIn() {
|
||||
global $tinyib;
|
||||
$loggedin = false; $isadmin = false;
|
||||
if (isset($_POST['password'])) {
|
||||
if ($_POST['password'] == $tinyib['adminpassword']) {
|
||||
$_SESSION['tinyib'] = $tinyib['adminpassword'];
|
||||
} elseif ($tinyib['modpassword'] != '' && $_POST['password'] == $tinyib['modpassword']) {
|
||||
$_SESSION['tinyib'] = $tinyib['modpassword'];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_SESSION['tinyib'])) {
|
||||
if ($_SESSION['tinyib'] == $tinyib['adminpassword']) {
|
||||
$loggedin = true;
|
||||
$isadmin = true;
|
||||
} elseif ($tinyib['modpassword'] != '' && $_SESSION['tinyib'] == $tinyib['modpassword']) {
|
||||
$loggedin = true;
|
||||
}
|
||||
}
|
||||
|
||||
return array($loggedin, $isadmin);
|
||||
}
|
||||
|
||||
function createThumbnail($name, $filename, $new_w, $new_h) {
|
||||
$system=explode(".", $filename);
|
||||
$system = array_reverse($system);
|
||||
if (preg_match("/jpg|jpeg/", $system[0])) {
|
||||
$src_img=imagecreatefromjpeg($name);
|
||||
} else if (preg_match("/png/", $system[0])) {
|
||||
$src_img=imagecreatefrompng($name);
|
||||
} else if (preg_match("/gif/", $system[0])) {
|
||||
$src_img=imagecreatefromgif($name);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$src_img) {
|
||||
fancyDie("Unable to read uploaded file during thumbnailing. A common cause for this is an incorrect extension when the file is actually of a different type.");
|
||||
}
|
||||
$old_x = imageSX($src_img);
|
||||
$old_y = imageSY($src_img);
|
||||
if ($old_x > $old_y) {
|
||||
$percent = $new_w / $old_x;
|
||||
} else {
|
||||
$percent = $new_h / $old_y;
|
||||
}
|
||||
$thumb_w = round($old_x * $percent);
|
||||
$thumb_h = round($old_y * $percent);
|
||||
|
||||
$dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
|
||||
fastImageCopyResampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
|
||||
|
||||
if (preg_match("/png/", $system[0])) {
|
||||
if (!imagepng($dst_img, $filename)) {
|
||||
return false;
|
||||
}
|
||||
} else if (preg_match("/jpg|jpeg/", $system[0])) {
|
||||
if (!imagejpeg($dst_img, $filename, 70)) {
|
||||
return false;
|
||||
}
|
||||
} else if (preg_match("/gif/", $system[0])) {
|
||||
if (!imagegif($dst_img, $filename)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
imagedestroy($dst_img);
|
||||
imagedestroy($src_img);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function fastImageCopyResampled(&$dst_image, &$src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $quality = 3) {
|
||||
//Author: Tim Eckel - Date: 12/17/04 - Project: FreeRingers.net - Freely distributable.
|
||||
if (empty($src_image) || empty($dst_image)) { return false; }
|
||||
|
||||
if ($quality <= 1) {
|
||||
$temp = imagecreatetruecolor ($dst_w + 1, $dst_h + 1);
|
||||
imagecopyresized ($temp, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w + 1, $dst_h + 1, $src_w, $src_h);
|
||||
imagecopyresized ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $dst_w, $dst_h);
|
||||
imagedestroy ($temp);
|
||||
} elseif ($quality < 5 && (($dst_w * $quality) < $src_w || ($dst_h * $quality) < $src_h)) {
|
||||
|
||||
$tmp_w = $dst_w * $quality;
|
||||
$tmp_h = $dst_h * $quality;
|
||||
$temp = imagecreatetruecolor ($tmp_w + 1, $tmp_h + 1);
|
||||
|
||||
imagecopyresized ($temp, $src_image, $dst_x * $quality, $dst_y * $quality, $src_x, $src_y, $tmp_w + 1, $tmp_h + 1, $src_w, $src_h);
|
||||
|
||||
imagecopyresampled ($dst_image, $temp, 0, 0, 0, 0, $dst_w, $dst_h, $tmp_w, $tmp_h);
|
||||
|
||||
imagedestroy ($temp);
|
||||
|
||||
} else {
|
||||
imagecopyresampled ($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
?>
|
461
inc/html.php
Normal file
461
inc/html.php
Normal file
|
@ -0,0 +1,461 @@
|
|||
<?php
|
||||
if (!isset($tinyib)) { die(''); }
|
||||
|
||||
function buildPost($post, $isrespage) {
|
||||
$return = "";
|
||||
$threadid = ($post['parent'] == 0) ? $post['id'] : $post['parent'];
|
||||
$postlink = ($isrespage) ? ($threadid . '.html#' . $post['id']) : ('res/' . $threadid . '.html#' . $post['id']);
|
||||
|
||||
if ($post["parent"] != 0) {
|
||||
$return .= <<<EOF
|
||||
<table>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="doubledash">
|
||||
¨
|
||||
</td>
|
||||
<td class="reply" id="reply${post["id"]}">
|
||||
EOF;
|
||||
} elseif ($post["file"] != "") {
|
||||
$return .= <<<EOF
|
||||
<span class="filesize">File: <a href="src/${post["file"]}">${post["file"]}</a>–(${post["file_size_formatted"]}, ${post["image_width"]}x${post["image_height"]}, ${post["file_original"]})</span>
|
||||
<br>
|
||||
<a target="_blank" href="src/${post["file"]}">
|
||||
<span id="thumb${post['id']}"><img src="thumb/${post["thumb"]}" alt="${post["id"]}" class="thumb" width="${post["thumb_width"]}" height="${post["thumb_height"]}"></span>
|
||||
</a>
|
||||
EOF;
|
||||
}
|
||||
|
||||
$return .= <<<EOF
|
||||
<a name="${post['id']}"></a>
|
||||
<label>
|
||||
<input type="checkbox" name="delete" value="${post['id']}">
|
||||
EOF;
|
||||
|
||||
if ($post["subject"] != "") {
|
||||
$return .= " <span class=\"filetitle\">${post["subject"]}</span> ";
|
||||
}
|
||||
|
||||
$return .= <<<EOF
|
||||
${post["nameblock"]}
|
||||
</label>
|
||||
<span class="reflink">
|
||||
<a href="$postlink">No.${post["id"]}</a>
|
||||
</span>
|
||||
EOF;
|
||||
|
||||
if ($post['parent'] != 0 && $post["file"] != "") {
|
||||
$return .= <<<EOF
|
||||
<br>
|
||||
<span class="filesize"><a href="src/${post["file"]}">${post["file"]}</a>–(${post["file_size_formatted"]}, ${post["image_width"]}x${post["image_height"]}, ${post["file_original"]})</span>
|
||||
<br>
|
||||
<a target="_blank" href="src/${post["file"]}">
|
||||
<span id="thumb${post["id"]}"><img src="thumb/${post["thumb"]}" alt="${post["id"]}" class="thumb" width="${post["thumb_width"]}" height="${post["thumb_height"]}"></span>
|
||||
</a>
|
||||
EOF;
|
||||
}
|
||||
|
||||
if ($post['parent'] == 0 && !$isrespage) {
|
||||
$return .= " [<a href=\"res/${post["id"]}.html\">Reply</a>]";
|
||||
}
|
||||
|
||||
$return .= <<<EOF
|
||||
<blockquote>
|
||||
${post["message"]}
|
||||
</blockquote>
|
||||
EOF;
|
||||
|
||||
if ($post['parent'] == 0) {
|
||||
if (!$isrespage && $post["omitted"] > 0) {
|
||||
$return .= '<span class="omittedposts">' . $post['omitted'] . ' post';
|
||||
if ($post["omitted"] != "1") {
|
||||
$return .= "s";
|
||||
}
|
||||
$return .= ' omitted. Click Reply to view.</span>';
|
||||
}
|
||||
} else {
|
||||
$return .= <<<EOF
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
EOF;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
function buildPage($htmlposts, $parent, $pages=-1, $thispage=0) {
|
||||
global $tinyib;
|
||||
$managelink = basename($_SERVER['PHP_SELF']) . "?manage";
|
||||
|
||||
$postingmode = "";
|
||||
$pagenavigator = "";
|
||||
if ($parent == 0) {
|
||||
$previous = ($thispage == 1) ? "index" : $thispage - 1;
|
||||
$next = $thispage + 1;
|
||||
|
||||
$pagelinks = ($thispage == 0) ? "<td>Previous</td>" : '<td><form method="get" action="' . $previous . '.html"><input value="Previous" type="submit"></form></td>';
|
||||
|
||||
$pagelinks .= "<td>";
|
||||
for ($i = 0;$i <= $pages;$i++) {
|
||||
if ($thispage == $i) {
|
||||
$pagelinks .= '[' . $i . '] ';
|
||||
} else {
|
||||
$href = ($i == 0) ? "index" : $i;
|
||||
$pagelinks .= '[<a href="' . $href . '.html">' . $i . '</a>] ';
|
||||
}
|
||||
}
|
||||
$pagelinks .= "</td>";
|
||||
|
||||
$pagelinks .= ($pages <= $thispage) ? "<td>Next</td>" : '<td><form method="get" action="' . $next . '.html"><input value="Next" type="submit"></form></td>';
|
||||
|
||||
$pagenavigator = <<<EOF
|
||||
<table border="1">
|
||||
<tbody>
|
||||
<tr>
|
||||
$pagelinks
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
EOF;
|
||||
} else {
|
||||
$postingmode = '[<a href="../">Return</a>]<div class="replymode">Posting mode: Reply</div> ';
|
||||
}
|
||||
|
||||
$unique_posts_html = '';
|
||||
$unique_posts = uniquePosts();
|
||||
if ($unique_posts > 0) {
|
||||
$unique_posts_html = "<li>Currently $unique_posts unique user posts.</li>";
|
||||
}
|
||||
|
||||
return <<<EOF
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>
|
||||
${tinyib['boarddescription']}
|
||||
</title>
|
||||
<link rel="shortcut icon" href="favicon.ico">
|
||||
<link rel="stylesheet" type="text/css" href="css/global.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/futaba.css" title="Futaba">
|
||||
<link rel="alternate stylesheet" type="text/css" href="css/burichan.css" title="Burichan">
|
||||
<meta http-equiv="pragma" content="no-cache">
|
||||
<meta http-equiv="expires" content="-1">
|
||||
</head>
|
||||
<body>
|
||||
<div class="adminbar">
|
||||
[<a href="$managelink">Manage</a>]
|
||||
</div>
|
||||
<div class="logo">
|
||||
${tinyib['logo']}
|
||||
${tinyib['boarddescription']}
|
||||
</div>
|
||||
<hr width="90%" size="1">
|
||||
$postingmode
|
||||
<div class="postarea">
|
||||
<form name="postform" id="postform" action="imgboard.php" method="post" enctype="multipart/form-data">
|
||||
<input type="hidden" name="MAX_FILE_SIZE" value="2097152">
|
||||
<input type="hidden" name="parent" value="$parent">
|
||||
<table class="postform">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="postblock">
|
||||
Name
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="name" size="28" maxlength="75" accesskey="n">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="postblock">
|
||||
E-mail
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="email" size="28" maxlength="75" accesskey="e">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="postblock">
|
||||
Subject
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="subject" size="40" maxlength="75" accesskey="s">
|
||||
<input type="submit" value="Submit" accesskey="z">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="postblock">
|
||||
Message
|
||||
</td>
|
||||
<td>
|
||||
<textarea name="message" cols="48" rows="4" accesskey="m"></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="postblock">
|
||||
File
|
||||
</td>
|
||||
<td>
|
||||
<input type="file" name="file" size="35" accesskey="f">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="postblock">
|
||||
Password
|
||||
</td>
|
||||
<td>
|
||||
<input type="password" name="password" size="8" accesskey="p"> (for post and file deletion)
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" class="rules">
|
||||
<ul style="margin-left: 0; margin-top: 0; margin-bottom: 0; padding-left: 0;">
|
||||
<li>Supported file types are: GIF, JPG, PNG</li>
|
||||
<li>Maximum file size allowed is 2 MB.</li>
|
||||
<li>Images greater than 250x250 pixels will be thumbnailed.</li>
|
||||
$unique_posts_html
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
<hr>
|
||||
<form id="delform" action="imgboard.php?delete" method="post">
|
||||
<input type="hidden" name="board" value="${tinyib['board']}">
|
||||
$htmlposts
|
||||
<table class="userdelete">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
Delete Post<br>Password <input type="password" name="password" size="8"> <input name="deletepost" value="Delete" type="submit">
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
$pagenavigator
|
||||
<br>
|
||||
<div class="footer" style="clear: both;">
|
||||
- <a href="http://www.2chan.net" target="_top">futaba</a> + <a href="http://www.1chan.net" target="_top">futallaby</a> + <a href="http://code.google.com/p/tinyib/" target="_top">tinyib</a> -
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
EOF;
|
||||
}
|
||||
|
||||
function rebuildIndexes() {
|
||||
global $mysql_posts_table;
|
||||
|
||||
$htmlposts = "";
|
||||
$page = 0;
|
||||
$i = 0;
|
||||
$pages = ceil(countThreads() / 10) - 1;
|
||||
$threads = allThreads();
|
||||
foreach ($threads as $thread) {
|
||||
$htmlreplies = array();
|
||||
$replies = latestRepliesInThreadByID($thread['id']);
|
||||
foreach ($replies as $reply) {
|
||||
$htmlreplies[] = buildPost($reply, False);
|
||||
}
|
||||
if (count($htmlreplies) == 3) {
|
||||
$thread["omitted"] = (count(postsInThreadByID($thread['id'])) - 4);
|
||||
} else {
|
||||
$thread["omitted"] = 0;
|
||||
}
|
||||
|
||||
$htmlposts .= buildPost($thread, False);
|
||||
|
||||
$htmlposts .= implode("", array_reverse($htmlreplies));
|
||||
|
||||
$htmlposts .= "<br clear=\"left\">\n" .
|
||||
"<hr>";
|
||||
$i += 1;
|
||||
if ($i == 10) {
|
||||
$file = ($page == 0) ? "index.html" : $page . ".html";
|
||||
writePage($file, buildPage($htmlposts, 0, $pages, $page));
|
||||
|
||||
$page += 1;
|
||||
$i = 0;
|
||||
$htmlposts = "";
|
||||
}
|
||||
}
|
||||
|
||||
if ($page == 0 || $htmlposts != "") {
|
||||
$file = ($page == 0) ? "index.html" : $page . ".html";
|
||||
writePage($file, buildPage($htmlposts, 0, $pages, $page));
|
||||
}
|
||||
}
|
||||
|
||||
function rebuildThread($id) {
|
||||
global $mysql_posts_table;
|
||||
|
||||
$htmlposts = "";
|
||||
$posts = postsInThreadByID($id);
|
||||
foreach ($posts as $post) {
|
||||
$htmlposts .= buildPost($post, True);
|
||||
}
|
||||
|
||||
$htmlposts .= "<br clear=\"left\">\n" .
|
||||
"<hr>";
|
||||
|
||||
writePage("res/" . $id . ".html", fixLinksInRes(buildPage($htmlposts, $id)));
|
||||
}
|
||||
|
||||
function manageNavBar() {
|
||||
global $loggedin, $isadmin;
|
||||
if (!$loggedin) { return ''; }
|
||||
$text = '';
|
||||
$text .= ($isadmin) ? '<a href="?manage&bans">bans</a> · ' : '';
|
||||
$text .= '<a href="?manage&moderate">moderate post</a> · ';
|
||||
$text .= ($isadmin) ? '<a href="?manage&rebuildall">rebuild all</a> · ' : '';
|
||||
$text .= '<a href="?manage&logout">log out</a>';
|
||||
return $text;
|
||||
}
|
||||
|
||||
function managePage($text, $onload='') {
|
||||
global $tinyib, $returnlink;
|
||||
|
||||
$navbar = manageNavBar();
|
||||
return <<<EOF
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>
|
||||
${tinyib['boarddescription']}
|
||||
</title>
|
||||
<meta http-equiv="pragma" content="no-cache">
|
||||
<meta http-equiv="expires" content="-1">
|
||||
<link rel="shortcut icon" href="favicon.ico">
|
||||
<link rel="stylesheet" type="text/css" href="css/global.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/futaba.css" title="Futaba">
|
||||
<link rel="alternate stylesheet" type="text/css" href="css/burichan.css" title="Burichan">
|
||||
</head>
|
||||
<body$onload>
|
||||
<div class="adminbar">
|
||||
[<a href="$returnlink">Return</a>]
|
||||
</div>
|
||||
<div class="logo">
|
||||
${tinyib['logo']}
|
||||
${tinyib['boarddescription']}
|
||||
</div>
|
||||
<hr width="90%" size="1">
|
||||
<div class="replymode">Manage mode</div>
|
||||
<div style="text-align: center;font-size: small;">$navbar</div>
|
||||
$text
|
||||
<hr>
|
||||
<div class="footer" style="clear: both;">
|
||||
- <a href="http://www.2chan.net" target="_top">futaba</a> + <a href="http://www.1chan.net" target="_top">futallaby</a> + <a href="http://code.google.com/p/tinyib/" target="_top">tinyib</a> -
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
EOF;
|
||||
}
|
||||
|
||||
function manageOnLoad($page) {
|
||||
switch ($page) {
|
||||
case 'login':
|
||||
return ' onload="document.tinyib.password.focus();"';
|
||||
case 'moderate':
|
||||
return ' onload="document.tinyib.moderate.focus();"';
|
||||
case 'bans':
|
||||
return ' onload="document.tinyib.ip.focus();"';
|
||||
}
|
||||
}
|
||||
|
||||
function manageLogInForm() {
|
||||
return <<<EOF
|
||||
<form id="tinyib" name="tinyib" method="post" action="?manage">
|
||||
<fieldset>
|
||||
<legend align="center">Please enter an administrator or moderator password</legend>
|
||||
<div style="text-align: center;">
|
||||
<input type="password" id="password" name="password"><br>
|
||||
<input type="submit" value="Submit" class="managebutton">
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
<br>
|
||||
EOF;
|
||||
}
|
||||
|
||||
function manageBanForm() {
|
||||
return <<<EOF
|
||||
<form id="tinyib" name="tinyib" method="post" action="?manage&bans">
|
||||
<fieldset>
|
||||
<legend>Ban an IP address from posting</legend>
|
||||
<label for="ip">IP Address:</label> <input type="text" name="ip" id="ip" value="${_GET['bans']}"> <input type="submit" value="Submit" class="managebutton"><br>
|
||||
<label for="expire">Expire(sec):</label> <input type="text" name="expire" id="expire" value="0"> <small><a href="#" onclick="document.tinyib.expire.value='3600';return false;">1hr</a> <a href="#" onclick="document.tinyib.expire.value='86400';return false;">1d</a> <a href="#" onclick="document.tinyib.expire.value='172800';return false;">2d</a> <a href="#" onclick="document.tinyib.expire.value='604800';return false;">1w</a> <a href="#" onclick="document.tinyib.expire.value='1209600';return false;">2w</a> <a href="#" onclick="document.tinyib.expire.value='2592000';return false;">30d</a> <a href="#" onclick="document.tinyib.expire.value='0';return false;">never</a></small><br>
|
||||
<label for="reason">Reason: </label> <input type="text" name="reason" id="reason"> <small>(optional)</small>
|
||||
<legend>
|
||||
</fieldset>
|
||||
</form><br>
|
||||
EOF;
|
||||
}
|
||||
|
||||
function manageBansTable() {
|
||||
$text = '';
|
||||
$allbans = allBans();
|
||||
if (count($allbans) > 0) {
|
||||
$text .= '<table border="1"><tr><th>IP Address</th><th>Set At</th><th>Expires</th><th>Reason Provided</th><th> </th></tr>';
|
||||
foreach ($allbans as $ban) {
|
||||
$expire = ($ban['expire'] > 0) ? date('y/m/d(D)H:i:s', $ban['expire']) : 'Never';
|
||||
$reason = ($ban['reason'] == '') ? ' ' : htmlentities($ban['reason']);
|
||||
$text .= '<tr><td>' . $ban['ip'] . '</td><td>' . date('y/m/d(D)H:i:s', $ban['timestamp']) . '</td><td>' . $expire . '</td><td>' . $reason . '</td><td><a href="?manage&bans&lift=' . $ban['id'] . '">lift</a></td></tr>';
|
||||
}
|
||||
$text .= '</table>';
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
function manageModeratePostForm() {
|
||||
return <<<EOF
|
||||
<form id="tinyib" name="tinyib" method="get" action="?">
|
||||
<input type="hidden" name="manage" value="">
|
||||
<fieldset>
|
||||
<legend>Moderate a post</legend>
|
||||
<label for="moderate">Post ID:</label> <input type="text" name="moderate" id="moderate"> <input type="submit" value="Submit" class="managebutton"><br>
|
||||
<legend>
|
||||
</fieldset>
|
||||
</form><br>
|
||||
EOF;
|
||||
}
|
||||
|
||||
function manageModeratePost($post) {
|
||||
global $isadmin;
|
||||
$ban = banByIP($post['ip']);
|
||||
$ban_disabled = (!$ban && $isadmin) ? '' : ' disabled';
|
||||
$ban_disabled_info = (!$ban) ? '' : (' A ban record already exists for ' . $post['ip']);
|
||||
$post_html = buildPost($post, true);
|
||||
return <<<EOF
|
||||
<fieldset>
|
||||
<legend>Moderating post No.${post['id']}</legend>
|
||||
|
||||
<div style="float: right;clear: both;">
|
||||
<fieldset>
|
||||
<legend>Post</legend>
|
||||
$post_html
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<fieldset>
|
||||
<legend>Action</legend>
|
||||
<form method="get" action="?">
|
||||
<input type="hidden" name="manage" value="">
|
||||
<input type="hidden" name="delete" value="${post['id']}">
|
||||
<input type="submit" value="Delete Post" class="managebutton">
|
||||
</form>
|
||||
<br>
|
||||
<form method="get" action="?">
|
||||
<input type="hidden" name="manage" value="">
|
||||
<input type="hidden" name="bans" value="${post['ip']}">
|
||||
<input type="submit" value="Ban Poster" class="managebutton"$ban_disabled>$ban_disabled_info
|
||||
</form>
|
||||
</fieldset>
|
||||
|
||||
</fieldset>
|
||||
<br>
|
||||
EOF;
|
||||
}
|
||||
?>
|
5
res/.svn/all-wcprops
Normal file
5
res/.svn/all-wcprops
Normal file
|
@ -0,0 +1,5 @@
|
|||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 25
|
||||
/svn/!svn/ver/2/trunk/res
|
||||
END
|
35
res/.svn/entries
Normal file
35
res/.svn/entries
Normal file
|
@ -0,0 +1,35 @@
|
|||
10
|
||||
|
||||
dir
|
||||
2
|
||||
https://tinyib.googlecode.com/svn/trunk/res
|
||||
https://tinyib.googlecode.com/svn
|
||||
|
||||
|
||||
|
||||
2009-04-29T14:47:23.189190Z
|
||||
2
|
||||
tslocum
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
0
|
||||
|
5
src/.svn/all-wcprops
Normal file
5
src/.svn/all-wcprops
Normal file
|
@ -0,0 +1,5 @@
|
|||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 25
|
||||
/svn/!svn/ver/2/trunk/src
|
||||
END
|
35
src/.svn/entries
Normal file
35
src/.svn/entries
Normal file
|
@ -0,0 +1,35 @@
|
|||
10
|
||||
|
||||
dir
|
||||
2
|
||||
https://tinyib.googlecode.com/svn/trunk/src
|
||||
https://tinyib.googlecode.com/svn
|
||||
|
||||
|
||||
|
||||
2009-04-29T14:47:23.189190Z
|
||||
2
|
||||
tslocum
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
0
|
||||
|
5
thumb/.svn/all-wcprops
Normal file
5
thumb/.svn/all-wcprops
Normal file
|
@ -0,0 +1,5 @@
|
|||
K 25
|
||||
svn:wc:ra_dav:version-url
|
||||
V 27
|
||||
/svn/!svn/ver/2/trunk/thumb
|
||||
END
|
35
thumb/.svn/entries
Normal file
35
thumb/.svn/entries
Normal file
|
@ -0,0 +1,35 @@
|
|||
10
|
||||
|
||||
dir
|
||||
2
|
||||
https://tinyib.googlecode.com/svn/trunk/thumb
|
||||
https://tinyib.googlecode.com/svn
|
||||
|
||||
|
||||
|
||||
2009-04-29T14:47:23.189190Z
|
||||
2
|
||||
tslocum
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
0
|
||||
|
Loading…
Reference in a new issue