Initial import, 2.0rc1
git-svn-id: file:///home/shish/svn/shimmie2/trunk@1 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
commit
7161656063
57 changed files with 13948 additions and 0 deletions
78
README.txt
Normal file
78
README.txt
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
|
||||||
|
_________.__ .__ .__ ________
|
||||||
|
/ _____/| |__ |__| _____ _____ |__| ____ \_____ \
|
||||||
|
\_____ \ | | \| |/ \ / \| |/ __ \ / ____/
|
||||||
|
/ \| Y \ | Y Y \ Y Y \ \ ___// \
|
||||||
|
/_______ /|___| /__|__|_| /__|_| /__|\___ >_______ \
|
||||||
|
\/ \/ \/ \/ \/ \/
|
||||||
|
|
||||||
|
Shimmie2 Release Candidate
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
Okay, so maybe my estimate of "it should be done within the week" was a bit
|
||||||
|
optimistic... I did get the first 3.5k lines of code done in a week, then
|
||||||
|
another 1k of extensions in another week, but making it all work *properly*
|
||||||
|
took 3 months...
|
||||||
|
|
||||||
|
|
||||||
|
Requirements
|
||||||
|
~~~~~~~~~~~~
|
||||||
|
MySQL 4.1+
|
||||||
|
PHP 5.0+
|
||||||
|
GD or ImageMagick
|
||||||
|
|
||||||
|
PHP 4 support has currently been dropped, because
|
||||||
|
a) It's a pain in the ass to support
|
||||||
|
b) Nobody has told me they want it
|
||||||
|
|
||||||
|
If you want PHP 4 support, mail me, and I'll see if I can get it working for
|
||||||
|
version 2.1...
|
||||||
|
|
||||||
|
|
||||||
|
Installation
|
||||||
|
~~~~~~~~~~~~
|
||||||
|
1) Create a blank database
|
||||||
|
2) Unzip shimmie into a folder on the web host
|
||||||
|
3) Visit the install folder with a web browser
|
||||||
|
4) Enter the location of the database, and choose login details for the first
|
||||||
|
admin of the board
|
||||||
|
5) Click "install". Hopefully you'll end up at the configuration screen; if
|
||||||
|
not, you should be given instructions on how to fix any errors~
|
||||||
|
|
||||||
|
|
||||||
|
Upgrade from 0.8.4
|
||||||
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
BIG NOTE: 0.8.4 is the only version the upgrader supports; please upgrade to
|
||||||
|
that before going any further! Feel free to try other versions, just don't
|
||||||
|
complain when it doesn't work :P
|
||||||
|
|
||||||
|
Upgrade process:
|
||||||
|
1) Make backups of everything. The most important things are your database
|
||||||
|
data, and your images folder. config.php and the thumbs folder are also
|
||||||
|
very helpful.
|
||||||
|
2) Check that your backups actually contain the important data, they aren't
|
||||||
|
just empty files with the right names...
|
||||||
|
3) Create a new, blank database, separate from the old one
|
||||||
|
4) Unzip shimmie2 into a different folder than shimmie1
|
||||||
|
5) Visit the URL of shimmie2
|
||||||
|
6) Full in the old database location, the new database location, and the full
|
||||||
|
path to the old installation folder (the folder where the old "images" and
|
||||||
|
"thumbs" can be found)
|
||||||
|
7) Click "upgrade"
|
||||||
|
8) Wait a couple of minutes while data is copied from the old install into the
|
||||||
|
new one. You may wish to spend these minutes in prayer :P
|
||||||
|
9) Log in with an existing admin account and set things up to taste
|
||||||
|
|
||||||
|
The old installation can now be removed, but you may wish to keep it around
|
||||||
|
until you're sure everything in v2 is working properly~
|
||||||
|
|
||||||
|
|
||||||
|
Contact
|
||||||
|
~~~~~~~
|
||||||
|
http://forum.shishnet.org/viewforum.php?f=6 -- discussion forum
|
||||||
|
http://trac.shishnet.org/shimmie2/ -- bug tracker
|
||||||
|
webmaster at shishnet.org -- email
|
||||||
|
Shish on Freenode -- IRC
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
11
core/block.class.php
Normal file
11
core/block.class.php
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
class Block {
|
||||||
|
var $header;
|
||||||
|
var $body;
|
||||||
|
|
||||||
|
public function Block($header, $body) {
|
||||||
|
$this->header = $header;
|
||||||
|
$this->body = $body;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
128
core/config.class.php
Normal file
128
core/config.class.php
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
<?php
|
||||||
|
class Config {
|
||||||
|
var $values = array(
|
||||||
|
'image_tlink' => '/thumbs/$id.jpg',
|
||||||
|
'image_ilink' => '/images/$id.$ext',
|
||||||
|
);
|
||||||
|
var $defaults = array(
|
||||||
|
'title' => 'Shimmie', # setup
|
||||||
|
'version' => 'Shimmie2-0.0.9', // internal
|
||||||
|
'db_version' => '2.0.0.9', // this should be managed by upgrade.php
|
||||||
|
'base_href' => './index.php?q=', # setup
|
||||||
|
'data_href' => './', # setup
|
||||||
|
'theme' => 'default', # setup
|
||||||
|
'debug_enabled' => true, # hidden
|
||||||
|
'anon_id' => 0, # general
|
||||||
|
'dir_images' => 'images', # general
|
||||||
|
'dir_thumbs' => 'thumbs', # general
|
||||||
|
'index_width' => 3, # index
|
||||||
|
'index_height' => 4, # index
|
||||||
|
'index_tips' => true,
|
||||||
|
'thumb_width' => 192, # index
|
||||||
|
'thumb_height' => 192, # index
|
||||||
|
'thumb_quality' => 75, # index
|
||||||
|
'thumb_gd_mem_limit' => '8MB', # upload
|
||||||
|
'view_scale' => false, # view
|
||||||
|
'tags_default' => 'map', # (ignored)
|
||||||
|
'tags_min' => '2', # tags
|
||||||
|
'upload_count' => 3, # upload
|
||||||
|
'upload_size' => '256KB', # upload
|
||||||
|
'upload_anon' => true, # upload
|
||||||
|
'comment_anon' => true, # comment
|
||||||
|
'comment_window' => 5, # comment
|
||||||
|
'comment_limit' => 3, # comment
|
||||||
|
'comment_count' => 5, # comment
|
||||||
|
'popular_count' => 15, # popular
|
||||||
|
'info_link' => 'http://tags.shishnet.org/wiki/$tag', # popular
|
||||||
|
'login_signup_enabled' => true, # user
|
||||||
|
'login_memory' => 7, # user
|
||||||
|
'image_ilink' => '$base/image/$id.$ext', # view
|
||||||
|
'image_slink' => '', # view
|
||||||
|
'image_tlink' => '$base/thumb/$id.jpg', # view
|
||||||
|
'image_tip' => '$tags // $size // $filesize' # view
|
||||||
|
);
|
||||||
|
|
||||||
|
public function Config() {
|
||||||
|
global $database;
|
||||||
|
$this->values = $database->db->GetAssoc("SELECT name, value FROM config");
|
||||||
|
}
|
||||||
|
public function save($name=null) {
|
||||||
|
global $database;
|
||||||
|
|
||||||
|
if(is_null($name)) {
|
||||||
|
foreach($this->values as $name => $value) {
|
||||||
|
// does "or update" work with sqlite / postgres?
|
||||||
|
$database->db->StartTrans();
|
||||||
|
$database->db->Execute("DELETE FROM config WHERE name = ?", array($name));
|
||||||
|
$database->db->Execute("INSERT INTO config VALUES (?, ?)", array($name, $value));
|
||||||
|
$database->db->CommitTrans();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$database->db->StartTrans();
|
||||||
|
$database->db->Execute("DELETE FROM config WHERE name = ?", array($name));
|
||||||
|
$database->db->Execute("INSERT INTO config VALUES (?, ?)", array($name, $this->values[$name]));
|
||||||
|
$database->db->CommitTrans();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_int($name, $value) {
|
||||||
|
$this->values[$name] = parse_shorthand_int($value);
|
||||||
|
$this->save($name);
|
||||||
|
}
|
||||||
|
public function set_string($name, $value) {
|
||||||
|
$this->values[$name] = $value;
|
||||||
|
$this->save($name);
|
||||||
|
}
|
||||||
|
public function set_bool($name, $value) {
|
||||||
|
$this->values[$name] = (($value == 'on' || $value === true) ? 'Y' : 'N');
|
||||||
|
$this->save($name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_int_from_post($name) {
|
||||||
|
if(isset($_POST[$name])) {
|
||||||
|
$this->values[$name] = $_POST[$name];
|
||||||
|
$this->save($name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function set_string_from_post($name) {
|
||||||
|
if(isset($_POST[$name])) {
|
||||||
|
$this->values[$name] = $_POST[$name];
|
||||||
|
$this->save($name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public function set_bool_from_post($name) {
|
||||||
|
if(isset($_POST[$name]) && ($_POST[$name] == 'on')) {
|
||||||
|
$this->values[$name] = 'Y';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->values[$name] = 'N';
|
||||||
|
}
|
||||||
|
$this->save($name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_int($name) {
|
||||||
|
// deprecated -- ints should be stored as ints now
|
||||||
|
return parse_shorthand_int($this->get($name));
|
||||||
|
}
|
||||||
|
public function get_string($name) {
|
||||||
|
return $this->get($name);
|
||||||
|
}
|
||||||
|
public function get_bool($name) {
|
||||||
|
// deprecated -- bools should be stored as Y/N now
|
||||||
|
return ($this->get($name) == 'Y' || $this->get($name) == '1');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get($name) {
|
||||||
|
if(isset($this->values[$name])) {
|
||||||
|
return $this->values[$name];
|
||||||
|
}
|
||||||
|
else if(isset($this->defaults[$name])) {
|
||||||
|
return $this->defaults[$name];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
342
core/database.class.php
Normal file
342
core/database.class.php
Normal file
|
@ -0,0 +1,342 @@
|
||||||
|
<?php
|
||||||
|
require_once "lib/adodb/adodb.inc.php";
|
||||||
|
|
||||||
|
class Querylet { // {{{
|
||||||
|
var $sql;
|
||||||
|
var $variables;
|
||||||
|
|
||||||
|
public function querylet($sql, $variables=array()) {
|
||||||
|
$this->sql = $sql;
|
||||||
|
$this->variables = $variables;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function append($querylet) {
|
||||||
|
$this->sql .= $querylet->sql;
|
||||||
|
$this->variables = array_merge($this->variables, $querylet->variables);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function append_sql($sql) {
|
||||||
|
$this->sql .= $sql;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add_variable($var) {
|
||||||
|
$this->variables[] = $var;
|
||||||
|
}
|
||||||
|
} // }}}
|
||||||
|
|
||||||
|
class Database {
|
||||||
|
var $db;
|
||||||
|
var $extensions;
|
||||||
|
|
||||||
|
public function Database() {
|
||||||
|
if(is_readable("config.php")) {
|
||||||
|
require_once "config.php";
|
||||||
|
$this->db = NewADOConnection($database_dsn);
|
||||||
|
$this->db->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||||
|
$this->extensions = $this->db->GetAssoc("SELECT name, version FROM extensions");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
header("Location: install.php");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// misc {{{
|
||||||
|
public function count_pages($tags=array()) {
|
||||||
|
global $config;
|
||||||
|
$images_per_page = $config->get_int('index_width') * $config->get_int('index_height');
|
||||||
|
if(count($tags) == 0) {
|
||||||
|
return ceil($this->db->GetOne("SELECT COUNT(*) FROM images") / $images_per_page);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$querylet = $this->build_search_querylet($tags);
|
||||||
|
$result = $this->db->Execute($querylet->sql, $querylet->variables);
|
||||||
|
return ceil($result->RecordCount() / $images_per_page);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// extensions {{{
|
||||||
|
public function set_extension_version($name, $version) {
|
||||||
|
$this->extensions[$name] = $version;
|
||||||
|
$this->db->GetRow("INSERT INTO extensions(name, version) VALUES (?, ?)", array($name, $version));
|
||||||
|
}
|
||||||
|
public function get_extension_version($name) {
|
||||||
|
return (isset($this->extensions[$name]) ? $this->extensions[$name] : -1);
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// tags {{{
|
||||||
|
public function resolve_alias($tag) {
|
||||||
|
$newtag = $this->db->GetOne("SELECT newtag FROM aliases WHERE oldtag=?", array($tag));
|
||||||
|
if(!empty($newtag)) {
|
||||||
|
return $newtag;
|
||||||
|
} else {
|
||||||
|
return $tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sanitise($tag) {
|
||||||
|
return preg_replace("/[\s?*]/", "", $tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_search_querylet($terms) {
|
||||||
|
$tag_search = new Querylet("0");
|
||||||
|
$positive_tag_count = 0;
|
||||||
|
$img_search = new Querylet("");
|
||||||
|
|
||||||
|
foreach($terms as $term) {
|
||||||
|
$negative = false;
|
||||||
|
if((strlen($term) > 0) && ($term[0] == '-')) {
|
||||||
|
$negative = true;
|
||||||
|
$term = substr($term, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
$term = $this->resolve_alias($term);
|
||||||
|
|
||||||
|
if(substr($term, 0, 5) == "size=") {
|
||||||
|
$dim = substr($term, 5);
|
||||||
|
$parts = explode('x', $dim);
|
||||||
|
$args = array(int_escape($parts[0]), int_escape($parts[1]));
|
||||||
|
$img_search->append(new Querylet("AND (width = ? AND height = ?)", $args));
|
||||||
|
}
|
||||||
|
else if(substr($term, 0, 5) == "size>") {
|
||||||
|
$dim = substr($term, 5);
|
||||||
|
$parts = explode('x', $dim);
|
||||||
|
$args = array(int_escape($parts[0]), int_escape($parts[1]));
|
||||||
|
$img_search->append(new Querylet("AND (width > ? AND height > ?)", $args));
|
||||||
|
}
|
||||||
|
else if(substr($term, 0, 5) == "size<") {
|
||||||
|
$dim = substr($term, 5);
|
||||||
|
$parts = explode('x', $dim);
|
||||||
|
$args = array(int_escape($parts[0]), int_escape($parts[1]));
|
||||||
|
$img_search->append(new Querylet("AND (width < ? AND height < ?)", $args));
|
||||||
|
}
|
||||||
|
else if(substr($term, 0, 6) == "ratio=") {
|
||||||
|
$dim = substr($term, 6);
|
||||||
|
$parts = explode(':', $dim);
|
||||||
|
$args = array(int_escape($parts[0]), int_escape($parts[1]));
|
||||||
|
$img_search->append(new Querylet("AND (width / height = ? / ?)", $args));
|
||||||
|
}
|
||||||
|
else if(substr($term, 0, 3) == "id<") {
|
||||||
|
$img_search->append(new Querylet("AND (id < ?)", array(int_escape(substr($term, 3)))));
|
||||||
|
}
|
||||||
|
else if(substr($term, 0, 3) == "id>") {
|
||||||
|
$img_search->append(new Querylet("AND (id > ?)", array(int_escape(substr($term, 3)))));
|
||||||
|
}
|
||||||
|
else if(substr($term, 0, 9) == "filesize<") {
|
||||||
|
$img_search->append(new Querylet("AND (filesize < ?)", array(parse_shorthand_int(substr($term, 9)))));
|
||||||
|
}
|
||||||
|
else if(substr($term, 0, 9) == "filesize>") {
|
||||||
|
$img_search->append(new Querylet("AND (filesize > ?)", array(parse_shorthand_int(substr($term, 9)))));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$term = str_replace("*", "%", $term);
|
||||||
|
$term = str_replace("?", "_", $term);
|
||||||
|
$sign = $negative ? "-" : "+";
|
||||||
|
if($sign == "+") $positive_tag_count++;
|
||||||
|
$tag_search->append(new Querylet(" $sign (tag LIKE ?)", array($term)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$database_fails = false; // MySQL 4.0 fails at subqueries
|
||||||
|
if(count($tag_search->variables) == 0 || $database_fails) {
|
||||||
|
$query = new Querylet("SELECT * FROM images ");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$subquery = new Querylet("
|
||||||
|
SELECT *, SUM({$tag_search->sql}) AS score
|
||||||
|
FROM images
|
||||||
|
LEFT JOIN tags ON tags.image_id = images.id
|
||||||
|
GROUP BY images.id
|
||||||
|
HAVING score = ?",
|
||||||
|
array_merge(
|
||||||
|
$tag_search->variables,
|
||||||
|
array($positive_tag_count)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$query = new Querylet("SELECT * FROM ({$subquery->sql}) AS images ", $subquery->variables);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(count($img_search->variables) > 0) {
|
||||||
|
$query->append_sql("WHERE 1=1 ");
|
||||||
|
$query->append($img_search);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_search_querylet_old($tags) { // {{{
|
||||||
|
$querylet = new Querylet("SELECT images.*, SUM(");
|
||||||
|
|
||||||
|
$tnum = 0;
|
||||||
|
foreach($tags as $tag) {
|
||||||
|
if(($tag != "") && ($tag[0] == '-')) continue;
|
||||||
|
$querylet->append_sql($tnum == 0 ? "(" : " OR ");
|
||||||
|
$querylet->append($this->term_to_querylet($tag));
|
||||||
|
$tnum++;
|
||||||
|
}
|
||||||
|
$min_score = $tnum;
|
||||||
|
if($tnum > 0) $querylet->append_sql(")");
|
||||||
|
|
||||||
|
$tnum = 0;
|
||||||
|
foreach($tags as $tag) {
|
||||||
|
if(($tag == "") || ($tag[0] != '-')) continue;
|
||||||
|
$querylet->append_sql($tnum == 0 ? "-(" : " OR ");
|
||||||
|
$querylet->append($this->term_to_querylet(substr($tag, 1)));
|
||||||
|
$tnum++;
|
||||||
|
}
|
||||||
|
if($tnum > 0) $querylet->append_sql(")");
|
||||||
|
|
||||||
|
$querylet->append_sql(") AS score
|
||||||
|
FROM tags
|
||||||
|
LEFT JOIN images ON image_id=images.id
|
||||||
|
GROUP BY images.id
|
||||||
|
HAVING score >= ?
|
||||||
|
");
|
||||||
|
$querylet->add_variable($min_score);
|
||||||
|
|
||||||
|
return $querylet;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function term_to_querylet($term) {
|
||||||
|
$term = $this->resolve_alias($term);
|
||||||
|
|
||||||
|
if(substr($term, 0, 5) == "size:") {
|
||||||
|
$dim = substr($term, 5);
|
||||||
|
$parts = explode('x', $dim);
|
||||||
|
return new Querylet("(width = ? AND height = ?)", array(int_escape($parts[0]), int_escape($parts[1])));
|
||||||
|
}
|
||||||
|
else if(substr($term, 0, 9) == "size-min:") {
|
||||||
|
$dim = substr($term, 9);
|
||||||
|
$parts = explode('x', $dim);
|
||||||
|
return new Querylet("(width >= ? AND height >= ?)", array(int_escape($parts[0]), int_escape($parts[1])));
|
||||||
|
}
|
||||||
|
else if(substr($term, 0, 9) == "size-max:") {
|
||||||
|
$dim = substr($term, 9);
|
||||||
|
$parts = explode('x', $dim);
|
||||||
|
return new Querylet("(width <= ? AND height <= ?)", array(int_escape($parts[0]), int_escape($parts[1])));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$term = str_replace("*", "%", $term);
|
||||||
|
$term = str_replace("?", "_", $term);
|
||||||
|
return new Querylet("(tag LIKE ?)", array($term));
|
||||||
|
}
|
||||||
|
} // }}}
|
||||||
|
|
||||||
|
public function delete_tags_from_image($image_id) {
|
||||||
|
$this->db->Execute("DELETE FROM tags WHERE image_id=?", array($image_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_tags($image_id, $tags) {
|
||||||
|
$tags = tag_explode($tags);
|
||||||
|
|
||||||
|
$tags = array_map(array($this, 'resolve_alias'), $tags);
|
||||||
|
$tags = array_map(array($this, 'sanitise'), $tags);
|
||||||
|
$tags = array_unique($tags); // remove any duplicate tags
|
||||||
|
|
||||||
|
// delete old
|
||||||
|
$this->delete_tags_from_image($image_id);
|
||||||
|
|
||||||
|
// insert each new tag
|
||||||
|
foreach($tags as $tag) {
|
||||||
|
$this->db->Execute("INSERT INTO tags(image_id, tag) VALUES(?, ?)", array($image_id, $tag));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// images {{{
|
||||||
|
public function get_images($start, $limit, $tags=array()) {
|
||||||
|
$images = array();
|
||||||
|
|
||||||
|
assert($start >= 0);
|
||||||
|
assert($limit > 0);
|
||||||
|
if($start < 0) $start = 0;
|
||||||
|
if($limit < 1) $limit = 1;
|
||||||
|
|
||||||
|
if(count($tags) == 0) {
|
||||||
|
$result = $this->db->Execute("SELECT * FROM images ORDER BY id DESC LIMIT ?,?", array($start, $limit));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$querylet = $this->build_search_querylet($tags);
|
||||||
|
$querylet->append(new Querylet("ORDER BY images.id DESC LIMIT ?,?", array($start, $limit)));
|
||||||
|
$result = $this->db->Execute($querylet->sql, $querylet->variables);
|
||||||
|
}
|
||||||
|
|
||||||
|
while(!$result->EOF) {
|
||||||
|
$images[] = new Image($result->fields);
|
||||||
|
$result->MoveNext();
|
||||||
|
}
|
||||||
|
return $images;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_next_image($id, $tags=array(), $next=true) {
|
||||||
|
if($next) {
|
||||||
|
$gtlt = "<";
|
||||||
|
$dir = "DESC";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$gtlt = ">";
|
||||||
|
$dir = "ASC";
|
||||||
|
}
|
||||||
|
|
||||||
|
if(count($tags) == 0) {
|
||||||
|
$row = $this->db->GetRow("SELECT * FROM images WHERE id $gtlt ? ORDER BY id $dir", array((int)$id));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$tags[] = ($next ? "id<$id" : "id>$id");
|
||||||
|
$dir = ($next ? "DESC" : "ASC");
|
||||||
|
$querylet = $this->build_search_querylet($tags);
|
||||||
|
$querylet->append_sql("ORDER BY id $dir");
|
||||||
|
$row = $this->db->GetRow($querylet->sql, $querylet->variables);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ($row ? new Image($row) : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_prev_image($id, $tags=array()) {
|
||||||
|
return $this->get_next_image($id, $tags, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_image($id) {
|
||||||
|
$image = null;
|
||||||
|
$row = $this->db->GetRow("SELECT * FROM images WHERE id=?", array($id));
|
||||||
|
return ($row ? new Image($row) : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function remove_image($id) {
|
||||||
|
$this->db->Execute("DELETE FROM images WHERE id=?", array($id));
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// users {{{
|
||||||
|
var $SELECT_USER = "SELECT *,time_to_sec(timediff(now(), joindate))/(60*60*24) AS days_old FROM users ";
|
||||||
|
|
||||||
|
public function get_user($a=false, $b=false) {
|
||||||
|
if($b == false) {
|
||||||
|
return $this->get_user_by_id($a);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return $this->get_user_by_name_and_hash($a, $b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_user_session($name, $session) {
|
||||||
|
$row = $this->db->GetRow("{$this->SELECT_USER} WHERE name LIKE ? AND md5(concat(pass, ?)) = ?",
|
||||||
|
array($name, $_SERVER['REMOTE_ADDR'], $session));
|
||||||
|
return $row ? new User($row) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_user_by_id($id) {
|
||||||
|
$row = $this->db->GetRow("{$this->SELECT_USER} WHERE id=?", array($id));
|
||||||
|
return $row ? new User($row) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_user_by_name($name) {
|
||||||
|
$row = $this->db->GetRow("{$this->SELECT_USER} WHERE name=?", array($name));
|
||||||
|
return $row ? new User($row) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_user_by_name_and_hash($name, $hash) {
|
||||||
|
$row = $this->db->GetRow("{$this->SELECT_USER} WHERE name LIKE ? AND pass = ?", array($name, $hash));
|
||||||
|
return $row ? new User($row) : null;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
?>
|
8
core/event.class.php
Normal file
8
core/event.class.php
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Event:
|
||||||
|
* generic parent class
|
||||||
|
*/
|
||||||
|
class Event {
|
||||||
|
}
|
||||||
|
?>
|
14
core/events/configsave.event.php
Normal file
14
core/events/configsave.event.php
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* ConfigSaveEvent:
|
||||||
|
* Sent when the setup screen's 'set' button has been
|
||||||
|
* activated; new config options are in $_POST
|
||||||
|
*/
|
||||||
|
class ConfigSaveEvent extends Event {
|
||||||
|
var $config;
|
||||||
|
|
||||||
|
public function ConfigSaveEvent($config) {
|
||||||
|
$this->config = $config;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
21
core/events/displayingimage.event.php
Normal file
21
core/events/displayingimage.event.php
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* DisplayingImageEvent:
|
||||||
|
* $image
|
||||||
|
*
|
||||||
|
* Sent when an image is ready to display. Extensions who
|
||||||
|
* wish to appear on the "view" page should listen for this,
|
||||||
|
* which only appears when an image actually exists.
|
||||||
|
*/
|
||||||
|
class DisplayingImageEvent extends Event {
|
||||||
|
var $image;
|
||||||
|
|
||||||
|
public function DisplayingImageEvent($image) {
|
||||||
|
$this->image = $image;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_image() {
|
||||||
|
return $this->image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
17
core/events/imagedeletion.event.php
Normal file
17
core/events/imagedeletion.event.php
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* ImageDeletionEvent:
|
||||||
|
* $image_id
|
||||||
|
*
|
||||||
|
* An image is being deleted. Used by things like tags
|
||||||
|
* and comments handlers to clean out related rows in
|
||||||
|
* their tables
|
||||||
|
*/
|
||||||
|
class ImageDeletionEvent extends Event {
|
||||||
|
var $image;
|
||||||
|
|
||||||
|
public function ImageDeletionEvent($image) {
|
||||||
|
$this->image = $image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
10
core/events/initext.event.php
Normal file
10
core/events/initext.event.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* InitExtEvent:
|
||||||
|
* Get extensions to load themselves
|
||||||
|
*/
|
||||||
|
class InitExtEvent extends Event {
|
||||||
|
public function InitExtEvent() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
31
core/events/pagerequest.event.php
Normal file
31
core/events/pagerequest.event.php
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* PageRequestEvent:
|
||||||
|
* $page
|
||||||
|
* $args
|
||||||
|
* get_arg(int)
|
||||||
|
* count_args()
|
||||||
|
*
|
||||||
|
* User requests /view/42 -> an event is generated with
|
||||||
|
* $page="view" and $args=array("42");
|
||||||
|
*
|
||||||
|
* Used for initial page generation triggers
|
||||||
|
*/
|
||||||
|
class PageRequestEvent extends Event {
|
||||||
|
var $page;
|
||||||
|
var $args;
|
||||||
|
|
||||||
|
public function PageRequestEvent($page, $args) {
|
||||||
|
$this->page = $page;
|
||||||
|
$this->args = $args;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_arg($n) {
|
||||||
|
return isset($this->args[$n]) ? $this->args[$n] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function count_args() {
|
||||||
|
return isset($this->args) ? count($this->args) : 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
17
core/events/tagset.event.php
Normal file
17
core/events/tagset.event.php
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* TagSetEvent:
|
||||||
|
* $image_id
|
||||||
|
* $tags
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class TagSetEvent extends Event {
|
||||||
|
var $image_id;
|
||||||
|
var $tags;
|
||||||
|
|
||||||
|
public function TagSetEvent($image_id, $tags) {
|
||||||
|
$this->image_id = $image_id;
|
||||||
|
$this->tags = $tags;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
15
core/events/uploadingimage.event.php
Normal file
15
core/events/uploadingimage.event.php
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* UploadingImageEvent:
|
||||||
|
* $image_id
|
||||||
|
*
|
||||||
|
* An image is being uploaded.
|
||||||
|
*/
|
||||||
|
class UploadingImageEvent extends Event {
|
||||||
|
var $image;
|
||||||
|
|
||||||
|
public function UploadingImageEvent($image) {
|
||||||
|
$this->image = $image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
77
core/ext/admin.ext.php
Normal file
77
core/ext/admin.ext.php
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
<?php
|
||||||
|
/* AdminBuildingEvent {{{
|
||||||
|
*
|
||||||
|
* Sent when the admin page is ready to be added to
|
||||||
|
*/
|
||||||
|
class AdminBuildingEvent extends Event {
|
||||||
|
public function AdminBuildingEvent() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
class AdminPage extends Extension {
|
||||||
|
// event handler {{{
|
||||||
|
public function receive_event($event) {
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "admin")) {
|
||||||
|
global $user;
|
||||||
|
if(!$user->is_admin()) {
|
||||||
|
global $page;
|
||||||
|
$page->set_title("Error");
|
||||||
|
$page->set_heading("Error");
|
||||||
|
$page->add_side_block(new NavBlock(), 0);
|
||||||
|
$page->add_main_block(new Block("Permission Denied", "This page is for admins only"), 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if($event->get_arg(0) == "delete_image") {
|
||||||
|
// FIXME: missing lots of else {complain}
|
||||||
|
if(isset($_POST['image_id'])) {
|
||||||
|
global $database;
|
||||||
|
$image = $database->get_image($_POST['image_id']);
|
||||||
|
if($image) {
|
||||||
|
send_event(new ImageDeletionEvent($image));
|
||||||
|
global $page;
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("index"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
send_event(new AdminBuildingEvent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'DisplayingImageEvent')) {
|
||||||
|
global $user;
|
||||||
|
if($user->is_admin()) {
|
||||||
|
global $page;
|
||||||
|
$page->add_side_block(new Block("Admin", $this->build_del_block($event->image->id)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'AdminBuildingEvent')) {
|
||||||
|
$this->build_page();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// block HTML {{{
|
||||||
|
private function build_del_block($image_id) {
|
||||||
|
$i_image_id = int_escape($image_id);
|
||||||
|
return "
|
||||||
|
<form action='".make_link("admin/delete_image")."' method='POST'>
|
||||||
|
<input type='hidden' name='image_id' value='$i_image_id'>
|
||||||
|
<input type='submit' value='Delete'>
|
||||||
|
</form>
|
||||||
|
";
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// admin page HTML {{{
|
||||||
|
private function build_page() {
|
||||||
|
global $page;
|
||||||
|
$page->set_title("Admin Tools");
|
||||||
|
$page->set_heading("Admin Tools");
|
||||||
|
$page->add_side_block(new NavBlock(), 0);
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
add_event_listener(new AdminPage());
|
||||||
|
?>
|
285
core/ext/image.ext.php
Normal file
285
core/ext/image.ext.php
Normal file
|
@ -0,0 +1,285 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* A class to handle adding / getting / removing image
|
||||||
|
* files from the disk
|
||||||
|
*/
|
||||||
|
class ImageIO extends Extension {
|
||||||
|
// event handling {{{
|
||||||
|
public function receive_event($event) {
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "image")) {
|
||||||
|
$this->send_file($event->get_arg(0), "image");
|
||||||
|
}
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "thumb")) {
|
||||||
|
$this->send_file($event->get_arg(0), "thumb");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'UploadingImageEvent')) {
|
||||||
|
$this->add_image($event->image);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'ImageDeletionEvent')) {
|
||||||
|
$this->remove_image($event->image);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'SetupBuildingEvent')) {
|
||||||
|
$thumbers = array();
|
||||||
|
$thumbers['Built-in GD'] = "gd";
|
||||||
|
$thumbers['ImageMagick'] = "convert";
|
||||||
|
|
||||||
|
$sb = new SetupBlock("Thumbnailing");
|
||||||
|
$sb->add_label("Engine: ");
|
||||||
|
$sb->add_choice_option("thumb_engine", $thumbers);
|
||||||
|
|
||||||
|
$sb->add_label("<br>Size ");
|
||||||
|
$sb->add_int_option("thumb_width");
|
||||||
|
$sb->add_label(" x ");
|
||||||
|
$sb->add_int_option("thumb_height");
|
||||||
|
$sb->add_label(" px at ");
|
||||||
|
$sb->add_int_option("thumb_quality");
|
||||||
|
$sb->add_label(" % quality ");
|
||||||
|
|
||||||
|
$sb->add_label("<br>Max GD memory use: ");
|
||||||
|
$sb->add_shorthand_int_option("thumb_gd_mem_limit");
|
||||||
|
|
||||||
|
$event->panel->add_main_block($sb);
|
||||||
|
}
|
||||||
|
if(is_a($event, 'ConfigSaveEvent')) {
|
||||||
|
$event->config->set_string("thumb_engine", $_POST['thumb_engine']);
|
||||||
|
$event->config->set_int("thumb_width", $_POST['thumb_width']);
|
||||||
|
$event->config->set_int("thumb_height", $_POST['thumb_height']);
|
||||||
|
$event->config->set_int("thumb_quality", $_POST['thumb_quality']);
|
||||||
|
$event->config->set_int("thumb_gd_mem_limit", $_POST['thumb_gd_mem_limit']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// add image {{{
|
||||||
|
private function is_dupe($hash) {
|
||||||
|
global $database;
|
||||||
|
return $database->db->GetRow("SELECT * FROM images WHERE hash=?", array($hash));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function read_file($fname) {
|
||||||
|
$fp = fopen($fname, "r");
|
||||||
|
if(!$fp) return false;
|
||||||
|
|
||||||
|
$data = fread($fp, filesize($fname));
|
||||||
|
fclose($fp);
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function make_thumb($inname, $outname) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$ok = false;
|
||||||
|
|
||||||
|
switch($config->get_string("thumb_engine")) {
|
||||||
|
default:
|
||||||
|
case 'gd':
|
||||||
|
$ok = $this->make_thumb_gd($inname, $outname);
|
||||||
|
break;
|
||||||
|
case 'convert':
|
||||||
|
$ok = $this->make_thumb_convert($inname, $outname);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
// IM thumber {{{
|
||||||
|
private function make_thumb_convert($inname, $outname) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$w = $config->get_int("thumb_width");
|
||||||
|
$h = $config->get_int("thumb_height");
|
||||||
|
$q = $config->get_int("thumb_quality");
|
||||||
|
|
||||||
|
exec("convert $inname -geometry {$w}x{$h} -quality {$q} $outname");
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// GD thumber {{{
|
||||||
|
private function make_thumb_gd($inname, $outname) {
|
||||||
|
global $config;
|
||||||
|
$thumb = $this->get_thumb($inname);
|
||||||
|
return imagejpeg($thumb, $outname, $config->get_int('thumb_quality'));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_memory_limit() {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
// thumbnail generation requires lots of memory
|
||||||
|
$default_limit = 8*1024*1024;
|
||||||
|
$shimmie_limit = parse_shorthand_int($config->get_int("thumb_gd_mem_limit"));
|
||||||
|
if($shimmie_limit < 3*1024*1024) {
|
||||||
|
// we aren't going to fit, override
|
||||||
|
$shimmie_limit = $default_limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
ini_set("memory_limit", $shimmie_limit);
|
||||||
|
$memory = parse_shorthand_int(ini_get("memory_limit"));
|
||||||
|
|
||||||
|
// changing of memory limit is disabled / failed
|
||||||
|
if($memory == -1) {
|
||||||
|
$memory = $default_limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $memory;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_thumb($tmpname) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$info = getimagesize($tmpname);
|
||||||
|
$width = $info[0];
|
||||||
|
$height = $info[1];
|
||||||
|
|
||||||
|
$max_width = $config->get_int('thumb_width');
|
||||||
|
$max_height = $config->get_int('thumb_height');
|
||||||
|
|
||||||
|
$memory_use = (filesize($tmpname)*2) + ($width*$height*4) + (4*1024*1024);
|
||||||
|
$memory_limit = $this->get_memory_limit();
|
||||||
|
|
||||||
|
if($memory_use > $memory_limit) {
|
||||||
|
$thumb = imagecreatetruecolor($max_width, min($max_height, 64));
|
||||||
|
$white = imagecolorallocate($thumb, 255, 255, 255);
|
||||||
|
$black = imagecolorallocate($thumb, 0, 0, 0);
|
||||||
|
imagefill($thumb, 0, 0, $white);
|
||||||
|
imagestring($thumb, 5, 10, 24, "Image Too Large :(", $black);
|
||||||
|
return $thumb;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$image = imagecreatefromstring($this->read_file($tmpname));
|
||||||
|
|
||||||
|
$xscale = ($max_height / $height);
|
||||||
|
$yscale = ($max_width / $width);
|
||||||
|
$scale = ($xscale < $yscale) ? $xscale : $yscale;
|
||||||
|
|
||||||
|
if($scale >= 1) {
|
||||||
|
$thumb = $image;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$thumb = imagecreatetruecolor($width*$scale, $height*$scale);
|
||||||
|
imagecopyresampled(
|
||||||
|
$thumb, $image, 0, 0, 0, 0,
|
||||||
|
$width*$scale, $height*$scale, $width, $height
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return $thumb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
private function add_image($image) {
|
||||||
|
global $page;
|
||||||
|
global $user;
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check for an existing image
|
||||||
|
*/
|
||||||
|
if($row = $this->is_dupe($image->hash)) {
|
||||||
|
$iid = $row['id'];
|
||||||
|
$page->add_main_block(new Block(
|
||||||
|
"Error uploading {$image->filename}",
|
||||||
|
"Image <a href='".make_link("post/view/$iid")."'>$iid</a> ".
|
||||||
|
"already has hash {$image->hash}"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// actually insert the info
|
||||||
|
$database->db->Execute(
|
||||||
|
"INSERT INTO images(owner_id, owner_ip, filename, filesize, hash, ext, width, height, posted) ".
|
||||||
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, now())",
|
||||||
|
array($user->id, $_SERVER['REMOTE_ADDR'], $image->filename, $image->filesize,
|
||||||
|
$image->hash, $image->ext, $image->width, $image->height));
|
||||||
|
$image->id = $database->db->Insert_ID();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If no errors: move the file from the temporary upload
|
||||||
|
* area to the main file store, create a thumbnail, and
|
||||||
|
* insert the image info into the database
|
||||||
|
*/
|
||||||
|
if(!copy($image->temp_filename, $image->get_image_filename())) {
|
||||||
|
$page->add_main_block(new Block("Error uploading {$image->filename}",
|
||||||
|
"The image couldn't be moved from the temporary area to the
|
||||||
|
main data store -- is the web server allowed to write to '".
|
||||||
|
($image->get_image_filename())."'?"));
|
||||||
|
send_event(new ImageDeletionEvent($image->id));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
chmod($image->get_image_filename(), 0644);
|
||||||
|
|
||||||
|
if(!$this->make_thumb($image->get_image_filename(), $image->get_thumb_filename())) {
|
||||||
|
$page->add_main_block(new Block("Error uploading {$image->filename}",
|
||||||
|
"The image thumbnail couldn't be generated -- is the web
|
||||||
|
server allowed to write to '".($image->get_thumb_filename())."'?"));
|
||||||
|
send_event(new ImageDeletionEvent($image->id));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
chmod($image->get_thumb_filename(), 0644);
|
||||||
|
|
||||||
|
send_event(new TagSetEvent($image->id, $image->get_tag_array()));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// fetch image {{{
|
||||||
|
private function send_file($image_id, $type) {
|
||||||
|
global $database;
|
||||||
|
$image = $database->get_image($image_id);
|
||||||
|
|
||||||
|
global $page;
|
||||||
|
if(!is_null($image)) {
|
||||||
|
$page->set_mode("data");
|
||||||
|
if($type == "thumb") {
|
||||||
|
$page->set_type("image/jpeg");
|
||||||
|
$file = $image->get_thumb_filename();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$page->set_type($image->get_mime_type());
|
||||||
|
$file = $image->get_image_filename();
|
||||||
|
}
|
||||||
|
|
||||||
|
$page->set_data(file_get_contents($file));
|
||||||
|
|
||||||
|
if(isset($_SERVER["HTTP_IF_MODIFIED_SINCE"])) {
|
||||||
|
$if_modified_since = preg_replace('/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$if_modified_since = "";
|
||||||
|
}
|
||||||
|
$gmdate_mod = gmdate('D, d M Y H:i:s', filemtime($file)) . ' GMT';
|
||||||
|
|
||||||
|
// FIXME: should be $page->blah
|
||||||
|
if($if_modified_since == $gmdate_mod) {
|
||||||
|
header("HTTP/1.0 304 Not Modified");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
header("Last-Modified: $gmdate_mod");
|
||||||
|
header("Expires: Fri, 2 Sep 2101 12:42:42 GMT"); // War was beginning
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$page->set_title("Not Found");
|
||||||
|
$page->set_heading("Not Found");
|
||||||
|
$page->add_side_block(new Block("Navigation", "<a href='".index."'>Index</a>"), 0);
|
||||||
|
$page->add_main_block(new Block("Image not in database",
|
||||||
|
"The requested image was not found in the database"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// delete image {{{
|
||||||
|
private function remove_image($image) {
|
||||||
|
global $database;
|
||||||
|
$database->remove_image($image->id);
|
||||||
|
|
||||||
|
unlink($image->get_image_filename());
|
||||||
|
unlink($image->get_thumb_filename());
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
add_event_listener(new ImageIO());
|
||||||
|
?>
|
147
core/ext/index.ext.php
Normal file
147
core/ext/index.ext.php
Normal file
|
@ -0,0 +1,147 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Index extends Extension {
|
||||||
|
// event handling {{{
|
||||||
|
public function receive_event($event) {
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "index")) {
|
||||||
|
if($event->get_arg(0) == 'rss') {
|
||||||
|
$this->do_rss();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$search_terms = array();
|
||||||
|
$page_number = 1;
|
||||||
|
|
||||||
|
if($event->count_args() > 0) {
|
||||||
|
$page_number = int_escape($event->get_arg(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isset($_GET['search'])) {
|
||||||
|
$search_terms = explode(' ', $_GET['search']);
|
||||||
|
$query = "search=".html_escape($_GET['search']);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$query = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
global $page;
|
||||||
|
global $config;
|
||||||
|
global $database;
|
||||||
|
|
||||||
|
$total_pages = $database->count_pages($search_terms);
|
||||||
|
$count = $config->get_int('index_width') * $config->get_int('index_height');
|
||||||
|
$images = $database->get_images(($page_number-1)*$count, $count, $search_terms);
|
||||||
|
|
||||||
|
if(count($search_terms) == 0) {
|
||||||
|
$page_title = $config->get_string('title');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$page_title = html_escape($_GET['search']);
|
||||||
|
/*
|
||||||
|
$page_title = "";
|
||||||
|
foreach($search_terms as $term) {
|
||||||
|
$h_term = html_escape($term);
|
||||||
|
$page_title .= "<a href='".make_link("post/list", "search=$h_term")."'>$h_term</a>";
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
$page->set_subheading("Page $page_number / $total_pages");
|
||||||
|
}
|
||||||
|
if($page_number > 1 || count($search_terms) > 0) {
|
||||||
|
// $page_title .= " / $page_number";
|
||||||
|
}
|
||||||
|
|
||||||
|
$page->set_title($page_title);
|
||||||
|
$page->set_heading($page_title);
|
||||||
|
$page->add_side_block(new Block("Navigation", $this->build_navigation($page_number, $total_pages, $search_terms)), 0);
|
||||||
|
$page->add_main_block(new Block("Images", $this->build_table($images, $query)), 10);
|
||||||
|
$page->add_main_block(new Paginator("index", $query, $page_number, $total_pages), 90);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'SetupBuildingEvent')) {
|
||||||
|
$sb = new SetupBlock("Index Options");
|
||||||
|
|
||||||
|
$sb->add_label("Index table size ");
|
||||||
|
$sb->add_int_option("index_width");
|
||||||
|
$sb->add_label(" x ");
|
||||||
|
$sb->add_int_option("index_height");
|
||||||
|
$sb->add_label(" images");
|
||||||
|
|
||||||
|
$sb->add_label("<br>Image tooltip ");
|
||||||
|
$sb->add_text_option("image_tip");
|
||||||
|
|
||||||
|
$event->panel->add_main_block($sb, 20);
|
||||||
|
}
|
||||||
|
if(is_a($event, 'ConfigSaveEvent')) {
|
||||||
|
$event->config->set_int("index_width", $_POST['index_width']);
|
||||||
|
$event->config->set_int("index_height", $_POST['index_height']);
|
||||||
|
$event->config->set_string("image_tip", $_POST['image_tip']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// HTML generation {{{
|
||||||
|
private function build_navigation($page_number, $total_pages, $search_terms) {
|
||||||
|
$prev = $page_number - 1;
|
||||||
|
$next = $page_number + 1;
|
||||||
|
|
||||||
|
$h_tags = html_escape(implode("%20", $search_terms));
|
||||||
|
$query = empty($h_tags) ? null : "search=$h_tags";
|
||||||
|
|
||||||
|
|
||||||
|
$h_prev = ($page_number <= 1) ? "Prev" : "<a href='".make_link("index/$prev", $query)."'>Prev</a>";
|
||||||
|
$h_index = "<a href='".make_link("index")."'>Index</a>";
|
||||||
|
$h_next = ($page_number >= $total_pages) ? "Next" : "<a href='".make_link("index/$next", $query)."'>Next</a>";
|
||||||
|
|
||||||
|
$h_search_string = count($search_terms) == 0 ? "Search" : html_escape(implode(" ", $search_terms));
|
||||||
|
$h_search_link = make_link("index");
|
||||||
|
$h_search = "
|
||||||
|
<p><form action='$h_search_link' method='GET'>
|
||||||
|
<input id='search_input' name='search' type='text'
|
||||||
|
value='$h_search_string' autocomplete='off' />
|
||||||
|
<input type='submit' value='Find' style='display: none;' />
|
||||||
|
</form>
|
||||||
|
<div id='search_completions'></div>";
|
||||||
|
|
||||||
|
return "$h_prev | $h_index | $h_next<br>$h_search";
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_table($images, $query) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$width = $config->get_int('index_width');
|
||||||
|
$height = $config->get_int('index_height');
|
||||||
|
|
||||||
|
$table = "<table>\n";
|
||||||
|
for($i=0; $i<$height; $i++) {
|
||||||
|
$table .= "<tr>\n";
|
||||||
|
for($j=0; $j<$width; $j++) {
|
||||||
|
$image = isset($images[$i*$width+$j]) ? $images[$i*$width+$j] : null;
|
||||||
|
if(!is_null($image)) {
|
||||||
|
$table .= $this->build_thumb($image, $query);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$table .= "\t<td> </td>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$table .= "</tr>\n";
|
||||||
|
}
|
||||||
|
$table .= "</table>\n";
|
||||||
|
|
||||||
|
return $table;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_thumb($image, $query=null) {
|
||||||
|
global $config;
|
||||||
|
$h_view_link = make_link("post/view/{$image->id}", $query);
|
||||||
|
$h_tip = html_escape($image->get_tooltip());
|
||||||
|
$h_thumb_link = $image->get_thumb_link();
|
||||||
|
return "<td><a href='$h_view_link'><img title='$h_tip' alt='$h_tip' src='$h_thumb_link'></a></td>\n";
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// rss {{{
|
||||||
|
private function do_rss() {
|
||||||
|
// TODO: this function
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
add_event_listener(new Index());
|
||||||
|
?>
|
216
core/ext/setup.ext.php
Normal file
216
core/ext/setup.ext.php
Normal file
|
@ -0,0 +1,216 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/* SetupBuildingEvent {{{
|
||||||
|
*
|
||||||
|
* Sent when the setup page is ready to be added to
|
||||||
|
*/
|
||||||
|
class SetupBuildingEvent extends Event {
|
||||||
|
var $panel;
|
||||||
|
|
||||||
|
public function SetupBuildingEvent($panel) {
|
||||||
|
$this->panel = $panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_panel() {
|
||||||
|
return $this->panel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
/* SetupPanel {{{
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class SetupPanel extends Page {
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
/* SetupBlock {{{
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class SetupBlock extends Block {
|
||||||
|
var $header;
|
||||||
|
var $body;
|
||||||
|
|
||||||
|
public function SetupBlock($title) {
|
||||||
|
$this->header = $title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add_label($text) {
|
||||||
|
$this->body .= $text;
|
||||||
|
}
|
||||||
|
public function add_text_option($name) {
|
||||||
|
global $config;
|
||||||
|
$val = $config->get_string($name);
|
||||||
|
$this->body .= "<input type='text' name='$name' value='$val'>\n";
|
||||||
|
}
|
||||||
|
public function add_longtext_option($name) {
|
||||||
|
global $config;
|
||||||
|
$val = $config->get_string($name);
|
||||||
|
$this->body .= "<textarea rows='5' cols='40' name='$name'>$val</textarea>\n";
|
||||||
|
$this->body .= "<!--<br><br><br><br>-->\n"; // setup page auto-layout counts <br> tags
|
||||||
|
}
|
||||||
|
public function add_bool_option($name) {
|
||||||
|
global $config;
|
||||||
|
$checked = $config->get_bool($name) ? " checked" : "";
|
||||||
|
$this->body .= "<input type='checkbox' name='$name'$checked>\n";
|
||||||
|
}
|
||||||
|
public function add_hidden_option($name) {
|
||||||
|
global $config;
|
||||||
|
$val = $config->get_string($name);
|
||||||
|
$this->body .= "<input type='hidden' name='$name' value='$val'>";
|
||||||
|
}
|
||||||
|
public function add_int_option($name) {
|
||||||
|
global $config;
|
||||||
|
$val = $config->get_string($name);
|
||||||
|
$this->body .= "<input type='text' name='$name' value='$val' size='4' style='text-align: center;'>\n";
|
||||||
|
}
|
||||||
|
public function add_shorthand_int_option($name) {
|
||||||
|
global $config;
|
||||||
|
$val = to_shorthand_int($config->get_string($name));
|
||||||
|
$this->body .= "<input type='text' name='$name' value='$val' size='6' style='text-align: center;'>\n";
|
||||||
|
}
|
||||||
|
public function add_choice_option($name, $options) {
|
||||||
|
global $config;
|
||||||
|
$current = $config->get_string($name);
|
||||||
|
|
||||||
|
$html = "<select name='$name'>";
|
||||||
|
foreach($options as $optname => $optval) {
|
||||||
|
if($optval == $current) $selected=" selected";
|
||||||
|
else $selected="";
|
||||||
|
$html .= "<option value='$optval'$selected>$optname</option>\n";
|
||||||
|
}
|
||||||
|
$html .= "</select>";
|
||||||
|
|
||||||
|
$this->body .= $html;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
class Setup extends Extension {
|
||||||
|
// event handling {{{
|
||||||
|
public function receive_event($event) {
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "setup")) {
|
||||||
|
global $user;
|
||||||
|
if(!$user->is_admin()) {
|
||||||
|
global $page;
|
||||||
|
$page->set_title("Error");
|
||||||
|
$page->set_heading("Error");
|
||||||
|
$page->add_side_block(new NavBlock(), 0);
|
||||||
|
$page->add_main_block(new Block("Permission Denied", "This page is for admins only"), 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if($event->get_arg(0) == "save") {
|
||||||
|
global $config;
|
||||||
|
send_event(new ConfigSaveEvent($config));
|
||||||
|
$config->save();
|
||||||
|
|
||||||
|
global $page;
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("setup"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$panel = new SetupPanel();
|
||||||
|
send_event(new SetupBuildingEvent($panel));
|
||||||
|
$this->build_page($panel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'SetupBuildingEvent')) {
|
||||||
|
$themes = array();
|
||||||
|
foreach(glob("themes/*") as $theme_dirname) {
|
||||||
|
$name = str_replace("themes/", "", $theme_dirname);
|
||||||
|
$themes[ucfirst($name)] = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sb = new SetupBlock("General");
|
||||||
|
$sb->add_label("Site title: ");
|
||||||
|
$sb->add_text_option("title");
|
||||||
|
$sb->add_label("<br>Base URL: ");
|
||||||
|
$sb->add_text_option("base_href");
|
||||||
|
$sb->add_label("<br>Data URL: ");
|
||||||
|
$sb->add_text_option("data_href");
|
||||||
|
$sb->add_label("<br>Contact URL: ");
|
||||||
|
$sb->add_text_option("contact_link");
|
||||||
|
$sb->add_label("<br>Theme: ");
|
||||||
|
$sb->add_choice_option("theme", $themes);
|
||||||
|
// $sb->add_label("<br>Anonymous ID: ");
|
||||||
|
// $sb->add_int_option("anon_id", 0, 100000);
|
||||||
|
$sb->add_hidden_option("anon_id");
|
||||||
|
$event->panel->add_main_block($sb, 0);
|
||||||
|
}
|
||||||
|
if(is_a($event, 'ConfigSaveEvent')) {
|
||||||
|
$event->config->set_string("title", $_POST['title']);
|
||||||
|
$event->config->set_string("base_href", $_POST['base_href']);
|
||||||
|
$event->config->set_string("data_href", $_POST['data_href']);
|
||||||
|
$event->config->set_string("contact_link", $_POST['contact_link']);
|
||||||
|
$event->config->set_string("theme", $_POST['theme']);
|
||||||
|
$event->config->set_int("anon_id", $_POST['anon_id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// HTML building {{{
|
||||||
|
private function build_page($panel) {
|
||||||
|
$setupblock_html1 = "";
|
||||||
|
$setupblock_html2 = "";
|
||||||
|
|
||||||
|
ksort($panel->mainblocks);
|
||||||
|
|
||||||
|
/*
|
||||||
|
$flip = true;
|
||||||
|
foreach($panel->mainblocks as $block) {
|
||||||
|
if(is_a($block, 'SetupBlock')) {
|
||||||
|
if($flip) $setupblock_html1 .= $this->sb_to_html($block);
|
||||||
|
else $setupblock_html2 .= $this->sb_to_html($block);
|
||||||
|
$flip = !$flip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Try and keep the two columns even; count the line breaks in
|
||||||
|
* each an calculate where a block would work best
|
||||||
|
*/
|
||||||
|
$len1 = 0;
|
||||||
|
$len2 = 0;
|
||||||
|
foreach($panel->mainblocks as $block) {
|
||||||
|
if(is_a($block, 'SetupBlock')) {
|
||||||
|
$html = $this->sb_to_html($block);
|
||||||
|
$len = count(explode("<br>", $html));
|
||||||
|
if($len1 <= $len2) {
|
||||||
|
$setupblock_html1 .= $this->sb_to_html($block);
|
||||||
|
$len1 += $len;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$setupblock_html2 .= $this->sb_to_html($block);
|
||||||
|
$len2 += $len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$table = "
|
||||||
|
<form action='".make_link("setup/save")."' method='POST'><table>
|
||||||
|
<tr><td>$setupblock_html1</td><td>$setupblock_html2</td></tr>
|
||||||
|
<tr><td colspan='2'><input type='submit' value='Save Settings'></td></tr>
|
||||||
|
</table></form>
|
||||||
|
";
|
||||||
|
|
||||||
|
global $page;
|
||||||
|
$page->set_title("Shimmie Setup");
|
||||||
|
$page->set_heading("Shimmie Setup");
|
||||||
|
$page->add_side_block(new Block("Navigation", $this->build_navigation()), 0);
|
||||||
|
$page->add_main_block(new Block("Setup", $table));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_navigation() {
|
||||||
|
return "
|
||||||
|
<a href='".make_link("index")."'>Index</a>
|
||||||
|
<br><a href='http://trac.shishnet.org/shimmie/wiki/Settings'>Help</a>
|
||||||
|
";
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sb_to_html($block) {
|
||||||
|
return "<div class='setupblock'><b>{$block->header}</b><br>{$block->body}</div>\n";
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
add_event_listener(new Setup());
|
||||||
|
?>
|
97
core/ext/tag_edit.ext.php
Normal file
97
core/ext/tag_edit.ext.php
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class TagEdit extends Extension {
|
||||||
|
// event handling {{{
|
||||||
|
public function receive_event($event) {
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "tags")) {
|
||||||
|
global $page;
|
||||||
|
if($event->get_arg(0) == "set") {
|
||||||
|
global $database;
|
||||||
|
$i_image_id = int_escape($_POST['image_id']);
|
||||||
|
$query = $_POST['query'];
|
||||||
|
$database->set_tags($i_image_id, $_POST['tags']);
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("post/view/$i_image_id", $query));
|
||||||
|
}
|
||||||
|
else if($event->get_arg(0) == "replace") {
|
||||||
|
global $user;
|
||||||
|
if($user->is_admin() && isset($_POST['search']) && isset($_POST['replace'])) {
|
||||||
|
global $page;
|
||||||
|
$this->mass_tag_edit($_POST['search'], $_POST['replace']);
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("admin"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'DisplayingImageEvent')) {
|
||||||
|
global $page;
|
||||||
|
$page->add_main_block(new Block(null, $this->build_tag_editor($event->image)), 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'TagSetEvent')) {
|
||||||
|
global $database;
|
||||||
|
$database->set_tags($event->image_id, $event->tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'ImageDeletionEvent')) {
|
||||||
|
global $database;
|
||||||
|
$database->delete_tags_from_image($event->image->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'AdminBuildingEvent')) {
|
||||||
|
global $page;
|
||||||
|
$page->add_main_block(new Block("Mass Tag Edit", $this->build_mass_tag_edit()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// When an alias is added, oldtag becomes inaccessable
|
||||||
|
if(is_a($event, 'AddAliasEvent')) {
|
||||||
|
$this->mass_tag_edit($event->oldtag, $event->newtag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// edit {{{
|
||||||
|
private function mass_tag_edit($search, $replace) {
|
||||||
|
// FIXME: deal with collisions
|
||||||
|
global $database;
|
||||||
|
$database->db->Execute("UPDATE tags SET tag=? WHERE tag=?", Array($replace, $search));
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// HTML {{{
|
||||||
|
private function build_tag_editor($image) {
|
||||||
|
global $database;
|
||||||
|
|
||||||
|
if(isset($_GET['search'])) {
|
||||||
|
$h_query = "search=".html_escape($_GET['search']);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$h_query = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
$h_tags = html_escape($image->get_tag_list());
|
||||||
|
$i_image_id = int_escape($image->id);
|
||||||
|
|
||||||
|
return "
|
||||||
|
<p><form action='".make_link("tags/set")."' method='POST'>
|
||||||
|
<input type='hidden' name='image_id' value='$i_image_id'>
|
||||||
|
<input type='hidden' name='query' value='$h_query'>
|
||||||
|
<input type='text' size='50' name='tags' value='$h_tags'>
|
||||||
|
<input type='submit' value='Set'>
|
||||||
|
</form>
|
||||||
|
";
|
||||||
|
}
|
||||||
|
private function build_mass_tag_edit() {
|
||||||
|
return "
|
||||||
|
<form action='".make_link("tags/replace")."' method='POST'>
|
||||||
|
<table border='1' style='width: 200px;'>
|
||||||
|
<tr><td>Search</td><td><input type='text' name='search'></tr>
|
||||||
|
<tr><td>Replace</td><td><input type='text' name='replace'></td></tr>
|
||||||
|
<tr><td colspan='2'><input type='submit' value='Replace'></td></tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
";
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
add_event_listener(new TagEdit());
|
||||||
|
?>
|
131
core/ext/upload.ext.php
Normal file
131
core/ext/upload.ext.php
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Upload extends Extension {
|
||||||
|
// event handling {{{
|
||||||
|
public function receive_event($event) {
|
||||||
|
global $page;
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "index")) {
|
||||||
|
if($this->can_upload()) {
|
||||||
|
$page->add_side_block(new Block("Upload", $this->build_upload_block()), 20);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "upload")) {
|
||||||
|
if($this->can_upload()) {
|
||||||
|
global $config;
|
||||||
|
global $page;
|
||||||
|
|
||||||
|
$ok = true;
|
||||||
|
foreach($_FILES as $file) {
|
||||||
|
$ok = $ok & $this->try_upload($file);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->show_result($ok);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$page->set_title("Upload Denied");
|
||||||
|
$page->set_heading("Upload Denied");
|
||||||
|
$page->add_side_block(new NavBlock());
|
||||||
|
$page->add_main_block(new Block("Error", "Anonymous posting is disabled"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'SetupBuildingEvent')) {
|
||||||
|
$sb = new SetupBlock("Upload");
|
||||||
|
$sb->add_label("Max Uploads: ");
|
||||||
|
$sb->add_int_option("upload_count");
|
||||||
|
$sb->add_label("<br>Max size per file: ");
|
||||||
|
$sb->add_shorthand_int_option("upload_size");
|
||||||
|
$sb->add_label("<br>Allow anonymous upoads: ");
|
||||||
|
$sb->add_bool_option("upload_anon");
|
||||||
|
$event->panel->add_main_block($sb, 10);
|
||||||
|
}
|
||||||
|
if(is_a($event, 'ConfigSaveEvent')) {
|
||||||
|
$event->config->set_int("upload_count", $_POST['upload_count']);
|
||||||
|
$event->config->set_int("upload_size", $_POST['upload_size']);
|
||||||
|
$event->config->set_bool("upload_anon", $_POST['upload_anon']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// do things {{{
|
||||||
|
private function can_upload() {
|
||||||
|
global $config, $user;
|
||||||
|
return $config->get_bool("upload_anon") || ($user->id != $config->get_int("anon_id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function try_upload($file) {
|
||||||
|
global $page;
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$ok = false;
|
||||||
|
|
||||||
|
if(!file_exists($file['tmp_name'])) {
|
||||||
|
// this happens normally with blank file boxes
|
||||||
|
}
|
||||||
|
else if(filesize($file['tmp_name']) > $config->get_int('upload_size')) {
|
||||||
|
$page->add_main_block(new Block("Error with ".html_escape($file['name']),
|
||||||
|
"File too large (".filesize($file['tmp_name'])." > ".
|
||||||
|
($config->get_int('upload_size')).")"));
|
||||||
|
}
|
||||||
|
else if(!($info = getimagesize($file['tmp_name']))) {
|
||||||
|
$page->add_main_block(new Block("Error with ".html_escape($file['name']),
|
||||||
|
"PHP doesn't recognise this as an image file"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$image = new Image($file['tmp_name'], $file['name'], $_POST['tags']);
|
||||||
|
|
||||||
|
if($image->is_ok()) {
|
||||||
|
send_event(new UploadingImageEvent($image));
|
||||||
|
$ok = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$page->add_main_block(new Block("Error with ".html_escape($file['name']),
|
||||||
|
"Something is not right!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function show_result($ok) {
|
||||||
|
global $page;
|
||||||
|
|
||||||
|
if($ok) {
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("index"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$page->set_title("Upload Status");
|
||||||
|
$page->set_heading("Upload Status");
|
||||||
|
$page->add_side_block(new NavBlock());
|
||||||
|
$page->add_main_block(new Block("OK?",
|
||||||
|
"If there are no errors here, things should be OK \\o/"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// HTML {{{
|
||||||
|
private function build_upload_block() {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$upload_list = "";
|
||||||
|
for($i=0; $i<$config->get_int('upload_count'); $i++) {
|
||||||
|
if($i == 0) $style = ""; // "style='display:visible'";
|
||||||
|
else $style = "style='display:none'";
|
||||||
|
$upload_list .= "<input accept='image/jpeg,image/png,image/gif' size='10' ".
|
||||||
|
"id='data$i' name='data$i' $style onchange=\"showUp('data".($i+1)."')\" type='file'>\n";
|
||||||
|
}
|
||||||
|
$max_size = $config->get_int('upload_size');
|
||||||
|
$max_kb = (int)($max_size / 1024);
|
||||||
|
// <input type='hidden' name='max_file_size' value='$max_size' />
|
||||||
|
return "
|
||||||
|
<form enctype='multipart/form-data' action='".make_link("upload")."' method='POST'>
|
||||||
|
$upload_list
|
||||||
|
<input id='tagBox' name='tags' type='text' value='tagme' autocomplete='off'>
|
||||||
|
<input type='submit' value='Post'>
|
||||||
|
</form>
|
||||||
|
<div id='upload_completions' style='clear: both;'><small>(Max file size is {$max_kb}KB)</small></div>
|
||||||
|
";
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
add_event_listener(new Upload());
|
||||||
|
?>
|
401
core/ext/user.ext.php
Normal file
401
core/ext/user.ext.php
Normal file
|
@ -0,0 +1,401 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class UserPage extends Extension {
|
||||||
|
// event handling {{{
|
||||||
|
public function receive_event($event) {
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "user")) {
|
||||||
|
global $page;
|
||||||
|
global $user;
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
if($event->get_arg(0) == "login") {
|
||||||
|
if(isset($_POST['user']) && isset($_POST['pass'])) {
|
||||||
|
$this->login();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$page->set_title("Login");
|
||||||
|
$page->set_heading("Login");
|
||||||
|
$page->add_side_block(new NavBlock());
|
||||||
|
$page->add_main_block(new Block("Login There",
|
||||||
|
"There should be a login box to the left"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if($event->get_arg(0) == "logout") {
|
||||||
|
setcookie("shm_session", "", time()+60*60*24*$config->get_int('login_memory'), "/");
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("index"));
|
||||||
|
}
|
||||||
|
else if($event->get_arg(0) == "changepass") {
|
||||||
|
$this->change_password_wrapper();
|
||||||
|
}
|
||||||
|
else if($event->get_arg(0) == "create") {
|
||||||
|
$this->create_user_wrapper();
|
||||||
|
}
|
||||||
|
else if($event->get_arg(0) == "set_more") {
|
||||||
|
$this->set_more_wrapper();
|
||||||
|
}
|
||||||
|
else { // view
|
||||||
|
$duser = ($event->count_args() == 0) ? $user : $database->get_user_by_name($event->get_arg(0));
|
||||||
|
$this->build_user_page($duser);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// user info is shown on all pages
|
||||||
|
if(is_a($event, 'PageRequestEvent')) {
|
||||||
|
global $user;
|
||||||
|
global $page;
|
||||||
|
|
||||||
|
if($user->is_anonymous()) {
|
||||||
|
$page->add_side_block(new Block("Login", $this->build_login_block()), 90);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$page->add_side_block(new Block("User Links", $this->build_links_block()), 90);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'SetupBuildingEvent')) {
|
||||||
|
$sb = new SetupBlock("User Options");
|
||||||
|
$sb->add_label("Login memory: ");
|
||||||
|
$sb->add_int_option("login_memory");
|
||||||
|
$sb->add_label(" days");
|
||||||
|
$sb->add_label("<br>Allow new signups: ");
|
||||||
|
$sb->add_bool_option("login_signup_enabled");
|
||||||
|
$sb->add_label("<br>Terms & Conditions:<br>");
|
||||||
|
$sb->add_longtext_option("login_tac");
|
||||||
|
$event->panel->add_main_block($sb);
|
||||||
|
}
|
||||||
|
if(is_a($event, 'ConfigSaveEvent')) {
|
||||||
|
$event->config->set_int("login_memory", $_POST['login_memory']);
|
||||||
|
$event->config->set_bool("login_signup_enabled", $_POST['login_signup_enabled']);
|
||||||
|
$event->config->set_string("login_tac", $_POST['login_tac']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// Things done *with* the user {{{
|
||||||
|
private function login() {
|
||||||
|
global $page;
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
global $user;
|
||||||
|
|
||||||
|
$name = $_POST['user'];
|
||||||
|
$pass = $_POST['pass'];
|
||||||
|
$addr = $_SERVER['REMOTE_ADDR'];
|
||||||
|
$hash = md5( strtolower($name) . $pass );
|
||||||
|
|
||||||
|
$duser = $database->get_user($name, $hash);
|
||||||
|
if(!is_null($duser)) {
|
||||||
|
$user = $duser;
|
||||||
|
|
||||||
|
setcookie(
|
||||||
|
"shm_user", $name,
|
||||||
|
time()+60*60*24*365, "/"
|
||||||
|
);
|
||||||
|
setcookie(
|
||||||
|
"shm_session", md5($hash.$addr),
|
||||||
|
time()+60*60*24*$config->get_int('login_memory'), "/"
|
||||||
|
);
|
||||||
|
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("user"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$page->set_title("Permission Denied");
|
||||||
|
$page->set_heading("Permission Denied");
|
||||||
|
$page->add_side_block(new NavBlock(), 0);
|
||||||
|
$page->add_main_block(new Block("Error", "No user with those details was found"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function create_user_wrapper() {
|
||||||
|
global $page;
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
if(!$config->get_bool("login_signup_enabled")) {
|
||||||
|
$page->set_title("Signups Disabled");
|
||||||
|
$page->set_heading("Signups Disabled");
|
||||||
|
$page->add_side_block(new NavBlock());
|
||||||
|
$page->add_main_block(new Block("Signups Disabled",
|
||||||
|
"The board admin has disabled the ability to create new accounts~"));
|
||||||
|
}
|
||||||
|
else if(isset($_POST['name']) && isset($_POST['pass1']) && isset($_POST['pass2'])) {
|
||||||
|
$name = trim($_POST['name']);
|
||||||
|
$pass1 = $_POST['pass1'];
|
||||||
|
$pass2 = $_POST['pass2'];
|
||||||
|
|
||||||
|
$page->set_title("Error");
|
||||||
|
$page->set_heading("Error");
|
||||||
|
$page->add_side_block(new NavBlock());
|
||||||
|
if(strlen($name) < 1) {
|
||||||
|
$page->add_main_block(new Block("Error", "Username must be at least 1 character"));
|
||||||
|
}
|
||||||
|
else if($pass1 != $pass2) {
|
||||||
|
$page->add_main_block(new Block("Error", "Passwords don't match"));
|
||||||
|
}
|
||||||
|
else if($database->db->GetRow("SELECT * FROM users WHERE name = ?", array($name))) {
|
||||||
|
$page->add_main_block(new Block("Error", "That username is already taken"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$addr = $_SERVER['REMOTE_ADDR'];
|
||||||
|
$hash = md5( strtolower($name) . $pass1 );
|
||||||
|
$email = isset($_POST['email']) ? $_POST['email'] : null;
|
||||||
|
|
||||||
|
// FIXME: send_event()
|
||||||
|
$database->db->Execute(
|
||||||
|
"INSERT INTO users (name, pass, joindate, email) VALUES (?, ?, now(), ?)",
|
||||||
|
array($name, $hash, $email));
|
||||||
|
|
||||||
|
setcookie("shm_user", $name,
|
||||||
|
time()+60*60*24*365, '/');
|
||||||
|
setcookie("shm_session", md5($hash.$addr),
|
||||||
|
time()+60*60*24*$config->get_int('login_memory'), '/');
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("user"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$page->set_title("Create Account");
|
||||||
|
$page->set_heading("Create Account");
|
||||||
|
$page->add_side_block(new NavBlock());
|
||||||
|
$page->add_main_block(new Block("Signup", $this->build_signup_form()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//}}}
|
||||||
|
// Things do ne *to* the user {{{
|
||||||
|
private function change_password_wrapper() {
|
||||||
|
global $user;
|
||||||
|
global $page;
|
||||||
|
global $database;
|
||||||
|
|
||||||
|
$page->set_title("Error");
|
||||||
|
$page->set_heading("Error");
|
||||||
|
$page->add_side_block(new NavBlock());
|
||||||
|
if($user->is_anonymous()) {
|
||||||
|
$page->add_main_block(new Block("Error", "You aren't logged in"));
|
||||||
|
}
|
||||||
|
else if(isset($_POST['id']) && isset($_POST['name']) &&
|
||||||
|
isset($_POST['pass1']) && isset($_POST['pass2'])) {
|
||||||
|
$name = $_POST['name'];
|
||||||
|
$id = $_POST['id'];
|
||||||
|
$pass1 = $_POST['pass1'];
|
||||||
|
$pass2 = $_POST['pass2'];
|
||||||
|
|
||||||
|
if((!$user->is_admin()) && ($name != $user->name)) {
|
||||||
|
$page->add_main_block(new Block("Error",
|
||||||
|
"You need to be an admin to change other people's passwords"));
|
||||||
|
}
|
||||||
|
else if($pass1 != $pass2) {
|
||||||
|
$page->add_main_block(new Block("Error", "Passwords don't match"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
global $config;
|
||||||
|
$addr = $_SERVER['REMOTE_ADDR'];
|
||||||
|
$hash = md5( strtolower($name) . $pass1 );
|
||||||
|
|
||||||
|
// FIXME: send_event()
|
||||||
|
// FIXME: $duser->set_pass();
|
||||||
|
$database->db->Execute(
|
||||||
|
"UPDATE users SET pass = ? WHERE id = ?",
|
||||||
|
array($hash, $id));
|
||||||
|
|
||||||
|
if($id == $user->id) {
|
||||||
|
setcookie("shm_user", $name,
|
||||||
|
time()+60*60*24*365, '/');
|
||||||
|
setcookie("shm_session", md5($hash.$addr),
|
||||||
|
time()+60*60*24*$config->get_int('login_memory'), '/');
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("user"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("user/{$user->name}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function set_more_wrapper() {
|
||||||
|
global $page;
|
||||||
|
global $user;
|
||||||
|
global $database;
|
||||||
|
|
||||||
|
$page->set_title("Error");
|
||||||
|
$page->set_heading("Error");
|
||||||
|
$page->add_side_block(new NavBlock());
|
||||||
|
if(!$user->is_admin()) {
|
||||||
|
$page->add_main_block(new Block("Not Admin", "Only admins can edit accounts"));
|
||||||
|
}
|
||||||
|
else if(!isset($_POST['id']) || !is_numeric($_POST['id'])) {
|
||||||
|
$page->add_main_block(new Block("No ID Specified",
|
||||||
|
"You need to specify the account number to edit"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$admin = (isset($_POST['admin']) && ($_POST['admin'] == "on"));
|
||||||
|
$enabled = (isset($_POST['enabled']) && ($_POST['enabled'] == "on"));
|
||||||
|
|
||||||
|
$duser = $database->get_user_by_id($_POST['id']);
|
||||||
|
$duser->set_admin($admin);
|
||||||
|
$duser->set_enabled($enabled);
|
||||||
|
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
if($duser->id == $user->id) {
|
||||||
|
$page->set_redirect(make_link("user"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$page->set_redirect(make_link("user/{$duser->name}"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// HTML building {{{
|
||||||
|
private function build_signup_form() {
|
||||||
|
global $config;
|
||||||
|
$tac = $config->get_string("login_tac");
|
||||||
|
|
||||||
|
if(empty($tac)) {
|
||||||
|
$html = "";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$html = "<p>$tac</p>";
|
||||||
|
}
|
||||||
|
$html .= "
|
||||||
|
<form action='".make_link("user/create")."' method='POST'>
|
||||||
|
<table style='width: 300px;' border='1'>
|
||||||
|
<tr><td>Name</td><td><input type='text' name='name'></td></tr>
|
||||||
|
<tr><td>Password</td><td><input type='password' name='pass1'></td></tr>
|
||||||
|
<tr><td>Repeat Password</td><td><input type='password' name='pass2'></td></tr>
|
||||||
|
<tr><td>Email (Optional)</td><td><input type='text' name='email'></td></tr>
|
||||||
|
<tr><td colspan='2'><input type='Submit' value='Create Account'></td></tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
";
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_user_page($duser) {
|
||||||
|
global $page;
|
||||||
|
global $user;
|
||||||
|
if(!is_null($duser)) {
|
||||||
|
$page->set_title("{$duser->name}'s Page");
|
||||||
|
$page->set_heading("{$duser->name}'s Page");
|
||||||
|
$page->add_side_block(new NavBlock(), 0);
|
||||||
|
$page->add_main_block(new Block("Stats", $this->build_stats($duser)));
|
||||||
|
|
||||||
|
if(!$user->is_anonymous()) {
|
||||||
|
if($user->id == $duser->id || $user->is_admin()) {
|
||||||
|
$page->add_main_block(new Block("Options", $this->build_options($duser)));
|
||||||
|
}
|
||||||
|
if($user->is_admin()) {
|
||||||
|
$page->add_main_block(new Block("More Options", $this->build_more_options($duser)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$page->set_title("No Such User");
|
||||||
|
$page->set_heading("No Such User");
|
||||||
|
$page->add_side_block(new NavBlock(), 0);
|
||||||
|
$page->add_main_block(new Block("No User By That ID",
|
||||||
|
"If you typed the ID by hand, try again; if you came from a link on this ".
|
||||||
|
"site, it might be bug report time..."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_stats($duser) {
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$i_days_old = int_escape($duser->get_days_old());
|
||||||
|
$h_join_date = html_escape($duser->join_date);
|
||||||
|
$i_image_count = int_escape($duser->get_image_count());
|
||||||
|
$i_comment_count = int_escape($duser->get_comment_count());
|
||||||
|
|
||||||
|
$i_days_old2 = ($i_days_old == 0) ? 1 : $i_days_old;
|
||||||
|
|
||||||
|
$h_image_rate = sprintf("%3.1f", ($i_image_count / $i_days_old2));
|
||||||
|
$h_comment_rate = sprintf("%3.1f", ($i_comment_count / $i_days_old2));
|
||||||
|
|
||||||
|
return "
|
||||||
|
Join date: $h_join_date ($i_days_old days old)
|
||||||
|
<br>Images uploaded: $i_image_count ($h_image_rate / day)
|
||||||
|
<br>Comments made: $i_comment_count ($h_comment_rate / day)
|
||||||
|
";
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_options($duser) {
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$html = "";
|
||||||
|
$html .= "
|
||||||
|
<form action='".make_link("user/changepass")."' method='POST'>
|
||||||
|
<input type='hidden' name='name' value='{$duser->name}'>
|
||||||
|
<input type='hidden' name='id' value='{$duser->id}'>
|
||||||
|
<table style='width: 300px;' border='1'>
|
||||||
|
<tr><td colspan='2'>Change Password</td></tr>
|
||||||
|
<tr><td>Password</td><td><input type='password' name='pass1'></td></tr>
|
||||||
|
<tr><td>Repeat Password</td><td><input type='password' name='pass2'></td></tr>
|
||||||
|
<tr><td colspan='2'><input type='Submit' value='Change Password'></td></tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
";
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_more_options($duser) {
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$i_user_id = int_escape($duser->id);
|
||||||
|
$h_is_admin = $duser->is_admin() ? " checked" : "";
|
||||||
|
$h_is_enabled = $duser->is_enabled() ? " checked" : "";
|
||||||
|
|
||||||
|
$html = "
|
||||||
|
<form action='".make_link("user/set_more")."' method='POST'>
|
||||||
|
<input type='hidden' name='id' value='$i_user_id'>
|
||||||
|
Admin: <input name='admin' type='checkbox'$h_is_admin>
|
||||||
|
<br>Enabled: <input name='enabled' type='checkbox'$h_is_enabled>
|
||||||
|
<p><input type='submit' value='Set'>
|
||||||
|
</form>
|
||||||
|
";
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_links_block() {
|
||||||
|
global $user;
|
||||||
|
|
||||||
|
$h_name = html_escape($user->name);
|
||||||
|
$html = "Logged in as $h_name";
|
||||||
|
if($user->is_admin()) {
|
||||||
|
$html .= "<br/><a href='".make_link("setup")."'>Board Config</a>";
|
||||||
|
$html .= "<br/><a href='".make_link("admin")."'>Admin</a>";
|
||||||
|
}
|
||||||
|
$html .= "<br/><a href='".make_link("user")."'>User Config</a>";
|
||||||
|
$html .= "<br/><a href='".make_link("user/logout")."'>Log Out</a>";
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_login_block() {
|
||||||
|
global $config;
|
||||||
|
$html = "
|
||||||
|
<form action='".make_link("user/login")."' method='POST'>
|
||||||
|
<table border='1' summary='Login Form'>
|
||||||
|
<tr><td width='70'>Name</td><td width='70'><input type='text' name='user'></td></tr>
|
||||||
|
<tr><td>Password</td><td><input type='password' name='pass'></td></tr>
|
||||||
|
<tr><td colspan='2'><input type='submit' name='gobu' value='Log In'></td></tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
";
|
||||||
|
if($config->get_bool("login_signup_enabled")) {
|
||||||
|
$html .= "<small><a href='".make_link("user/create")."'>Create Account</a></small>";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$html .= "<small>Account creation disabled</small>";
|
||||||
|
}
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
add_event_listener(new UserPage());
|
||||||
|
?>
|
124
core/ext/view.ext.php
Normal file
124
core/ext/view.ext.php
Normal file
|
@ -0,0 +1,124 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class ViewImage extends Extension {
|
||||||
|
// event handling {{{
|
||||||
|
public function receive_event($event) {
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "post") && ($event->get_arg(0) == "view")) {
|
||||||
|
$image_id = int_escape($event->get_arg(1));
|
||||||
|
|
||||||
|
global $database;
|
||||||
|
$image = $database->get_image($image_id);
|
||||||
|
|
||||||
|
if(!is_null($image)) {
|
||||||
|
send_event(new DisplayingImageEvent($image));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
global $page;
|
||||||
|
$page->set_title("Image not found");
|
||||||
|
$page->set_heading("Image not found");
|
||||||
|
$page->add_side_block(new NavBlock(), 0);
|
||||||
|
$page->add_main_block(new Block("Image not found",
|
||||||
|
"No image in the database has the ID #$image_id"), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'DisplayingImageEvent')) {
|
||||||
|
$image = $event->get_image();
|
||||||
|
|
||||||
|
global $page;
|
||||||
|
$page->set_title("Image {$image->id}: ".$image->get_tag_list());
|
||||||
|
$page->set_heading($image->get_tag_list());
|
||||||
|
$page->add_side_block(new Block("Navigation", $this->build_navigation($image->id)), 0);
|
||||||
|
$page->add_main_block(new Block("Image", $this->build_image_view($image)), 0);
|
||||||
|
$page->add_main_block(new Block(null, $this->build_info($image)), 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'SetupBuildingEvent')) {
|
||||||
|
$sb = new SetupBlock("View Options");
|
||||||
|
$sb->add_label("Long link ");
|
||||||
|
$sb->add_text_option("image_ilink");
|
||||||
|
$sb->add_label("<br>Short link ");
|
||||||
|
$sb->add_text_option("image_slink");
|
||||||
|
$sb->add_label("<br>Thumbnail link ");
|
||||||
|
$sb->add_text_option("image_tlink");
|
||||||
|
//$sb->add_label("<br>Zoom by default");
|
||||||
|
//$sb->add_bool_option("view_scale");
|
||||||
|
$event->panel->add_main_block($sb, 30);
|
||||||
|
}
|
||||||
|
if(is_a($event, 'ConfigSaveEvent')) {
|
||||||
|
$event->config->set_string("image_ilink", $_POST['image_ilink']);
|
||||||
|
$event->config->set_string("image_slink", $_POST['image_slink']);
|
||||||
|
$event->config->set_string("image_tlink", $_POST['image_tlink']);
|
||||||
|
//$event->config->set_bool("view_scale", $_POST['view_scale']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// HTML {{{
|
||||||
|
var $pin = null;
|
||||||
|
|
||||||
|
private function build_pin($image_id) {
|
||||||
|
if(!is_null($this->pin)) {
|
||||||
|
return $this->pin;
|
||||||
|
}
|
||||||
|
|
||||||
|
global $database;
|
||||||
|
|
||||||
|
// $next_img = $database->db->GetOne("SELECT id FROM images WHERE id < ? ORDER BY id DESC", array($image_id));
|
||||||
|
// $prev_img = $database->db->GetOne("SELECT id FROM images WHERE id > ? ORDER BY id ASC ", array($image_id));
|
||||||
|
if(isset($_GET['search'])) {
|
||||||
|
$search_terms = explode(' ', $_GET['search']);
|
||||||
|
$query = "search=".html_escape($_GET['search']);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$search_terms = array();
|
||||||
|
$query = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$next = $database->get_next_image($image_id, $search_terms);
|
||||||
|
$prev = $database->get_prev_image($image_id, $search_terms);
|
||||||
|
|
||||||
|
$h_prev = (!is_null($prev) ? "<a href='".make_link("post/view/{$prev->id}", $query)."'>Prev</a>" : "Prev");
|
||||||
|
$h_index = "<a href='".make_link("index")."'>Index</a>";
|
||||||
|
$h_next = (!is_null($next) ? "<a href='".make_link("post/view/{$next->id}", $query)."'>Next</a>" : "Next");
|
||||||
|
|
||||||
|
$this->pin = "$h_prev | $h_index | $h_next";
|
||||||
|
return $this->pin;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_navigation($image_id) {
|
||||||
|
$h_pin = $this->build_pin($image_id);
|
||||||
|
$h_search = "
|
||||||
|
<p><form action='".make_link("index")."' method='GET'>
|
||||||
|
<input id='search_input' name='search' type='text'
|
||||||
|
value='Search' autocomplete='off'>
|
||||||
|
<input type='submit' value='Find' style='display: none;'>
|
||||||
|
</form>
|
||||||
|
<div id='search_completions'></div>";
|
||||||
|
|
||||||
|
return "$h_pin<br>$h_search";
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_image_view($image) {
|
||||||
|
$ilink = $image->get_image_link();
|
||||||
|
return "<img id='main_image' src='$ilink'>";
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_info($image) {
|
||||||
|
$owner = $image->get_owner();
|
||||||
|
$h_owner = html_escape($owner->name);
|
||||||
|
$i_owner_id = int_escape($owner->id);
|
||||||
|
|
||||||
|
$html = "";
|
||||||
|
if(strlen($image->get_short_link()) > 0) {
|
||||||
|
$slink = $image->get_short_link();
|
||||||
|
$html .= "<p>Link: <input size='50' type='text' value='$slink'>";
|
||||||
|
}
|
||||||
|
$html .= "<p>Uploaded by <a href='".make_link("user/$h_owner")."'>$h_owner</a>";
|
||||||
|
$html .= "<p>".$this->build_pin($image->id);
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
add_event_listener(new ViewImage());
|
||||||
|
?>
|
5
core/extension.class.php
Normal file
5
core/extension.class.php
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?php
|
||||||
|
class Extension {
|
||||||
|
public function receive_event($event) {}
|
||||||
|
}
|
||||||
|
?>
|
162
core/image.class.php
Normal file
162
core/image.class.php
Normal file
|
@ -0,0 +1,162 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Image {
|
||||||
|
var $id = null;
|
||||||
|
var $height, $width;
|
||||||
|
var $hash, $filesize;
|
||||||
|
var $filename, $ext;
|
||||||
|
|
||||||
|
public function Image($a=false, $b=false, $c=false) {
|
||||||
|
if($b == false && $c == false) {
|
||||||
|
$this->create_from_row($a);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->create_from_data($a, $b, $c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function create_from_row($row) {
|
||||||
|
$this->id = $row['id'];
|
||||||
|
$this->owner_id = $row['owner_id'];
|
||||||
|
$this->filename = $row['filename'];
|
||||||
|
$this->filesize = $row['filesize'];
|
||||||
|
$this->hash = $row['hash'];
|
||||||
|
$this->ext = $row['ext'];
|
||||||
|
$this->width = $row['width'];
|
||||||
|
$this->height = $row['height'];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function mime_to_ext($mime) {
|
||||||
|
switch($mime) {
|
||||||
|
default:
|
||||||
|
case 'image/jpeg': return "jpg"; break;
|
||||||
|
case 'image/png': return "png"; break;
|
||||||
|
case 'image/gif': return "gif"; break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function create_from_data($tmp, $filename, $tags) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$this->ok = false;
|
||||||
|
$info = "";
|
||||||
|
|
||||||
|
if(!file_exists($tmp)) return;
|
||||||
|
if(filesize($tmp) > $config->get_int('upload_size')) return;
|
||||||
|
if(!($info = getimagesize($tmp))) return;
|
||||||
|
|
||||||
|
$this->width = $info[0];
|
||||||
|
$this->height = $info[1];
|
||||||
|
$this->mime_type = $info['mime'];
|
||||||
|
$this->filename = str_replace("/", "_", $filename); // is this even possible?
|
||||||
|
$this->filesize = filesize($tmp);
|
||||||
|
$this->ext = $this->mime_to_ext($info['mime']);
|
||||||
|
$this->hash = md5_file($tmp);
|
||||||
|
$this->temp_filename = $tmp;
|
||||||
|
|
||||||
|
$this->tag_array = tag_explode($tags);
|
||||||
|
|
||||||
|
$this->ok = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function is_ok() {
|
||||||
|
return $this->ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_owner() {
|
||||||
|
global $database;
|
||||||
|
return $database->get_user($this->owner_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_tag_array() {
|
||||||
|
if(!isset($this->tag_array)) {
|
||||||
|
global $database;
|
||||||
|
$this->tag_array = Array();
|
||||||
|
$row = $database->db->Execute("SELECT * FROM tags WHERE image_id=?", array($this->id));
|
||||||
|
while(!$row->EOF) {
|
||||||
|
$this->tag_array[] = $row->fields['tag'];
|
||||||
|
$row->MoveNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->tag_array;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_tag_list() {
|
||||||
|
return implode(' ', $this->get_tag_array());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_image_link() {
|
||||||
|
global $config;
|
||||||
|
return $this->parse_link_template($config->get_string('image_ilink'), $this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_short_link() {
|
||||||
|
global $config;
|
||||||
|
return $this->parse_link_template($config->get_string('image_slink'), $this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_thumb_link() {
|
||||||
|
global $config;
|
||||||
|
return $this->parse_link_template($config->get_string('image_tlink'), $this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_tooltip() {
|
||||||
|
global $config;
|
||||||
|
return $this->parse_link_template($config->get_string('image_tip'), $this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_image_filename() {
|
||||||
|
global $config;
|
||||||
|
$hash = $this->hash;
|
||||||
|
$ab = substr($hash, 0, 2);
|
||||||
|
$ext = $this->ext;
|
||||||
|
return "images/$ab/$hash";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_thumb_filename() {
|
||||||
|
global $config;
|
||||||
|
$hash = $this->hash;
|
||||||
|
$ab = substr($hash, 0, 2);
|
||||||
|
return "thumbs/$ab/$hash";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_filename() {
|
||||||
|
return $this->filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_mime_type() {
|
||||||
|
return "image/".($this->ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_ext() {
|
||||||
|
return $this->ext;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function parse_link_template($tmpl, $img) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
// don't bother hitting the database if it won't be used...
|
||||||
|
$safe_tags = "";
|
||||||
|
if(strpos($tmpl, '$tags') !== false) { // * stabs dynamically typed languages with a rusty spoon *
|
||||||
|
$safe_tags = preg_replace(
|
||||||
|
"/[^a-zA-Z0-9_\- ]/",
|
||||||
|
"", $img->get_tag_list());
|
||||||
|
}
|
||||||
|
|
||||||
|
$base_href = $config->get_string('base_href');
|
||||||
|
$fname = $img->get_filename();
|
||||||
|
$base_fname = strpos($fname, '.') ? substr($fname, 0, strrpos($fname, '.')) : $fname;
|
||||||
|
|
||||||
|
$tmpl = str_replace('$id', $img->id, $tmpl);
|
||||||
|
$tmpl = str_replace('$hash', $img->hash, $tmpl);
|
||||||
|
$tmpl = str_replace('$tags', $safe_tags, $tmpl);
|
||||||
|
$tmpl = str_replace('$base', $base_href, $tmpl);
|
||||||
|
$tmpl = str_replace('$ext', $img->ext, $tmpl);
|
||||||
|
$tmpl = str_replace('$size', "{$img->width}x{$img->height}", $tmpl);
|
||||||
|
$tmpl = str_replace('$filesize', to_shorthand_int($img->filesize), $tmpl);
|
||||||
|
$tmpl = str_replace('$filename', $base_fname, $tmpl);
|
||||||
|
|
||||||
|
return $tmpl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
11
core/navblock.class.php
Normal file
11
core/navblock.class.php
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
class NavBlock {
|
||||||
|
var $header;
|
||||||
|
var $body;
|
||||||
|
|
||||||
|
public function NavBlock() {
|
||||||
|
$this->header = "Navigation";
|
||||||
|
$this->body = "<a href='".make_link("index")."'>Index</a>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
95
core/page.class.php
Normal file
95
core/page.class.php
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
<?php
|
||||||
|
class Page {
|
||||||
|
var $mode = "page";
|
||||||
|
var $type = "text/html";
|
||||||
|
|
||||||
|
public function set_mode($mode) {
|
||||||
|
$this->mode = $mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_type($type) {
|
||||||
|
$this->type = $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==============================================
|
||||||
|
|
||||||
|
// data
|
||||||
|
var $data = "";
|
||||||
|
|
||||||
|
public function set_data($data) {
|
||||||
|
$this->data = $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==============================================
|
||||||
|
|
||||||
|
// redirect
|
||||||
|
var $redirect = "";
|
||||||
|
|
||||||
|
public function set_redirect($redirect) {
|
||||||
|
$this->redirect = $redirect;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==============================================
|
||||||
|
|
||||||
|
// page
|
||||||
|
var $title = "";
|
||||||
|
var $heading = "";
|
||||||
|
var $subheading = "";
|
||||||
|
var $quicknav = "";
|
||||||
|
var $sideblocks = array();
|
||||||
|
var $mainblocks = array();
|
||||||
|
|
||||||
|
public function set_title($title) {
|
||||||
|
$this->title = $title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_heading($heading) {
|
||||||
|
$this->heading = $heading;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_subheading($subheading) {
|
||||||
|
$this->subheading = $subheading;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add_side_block($block, $position=50) {
|
||||||
|
while(isset($this->sideblocks[$position])) $position++;
|
||||||
|
$this->sideblocks[$position] = $block;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add_main_block($block, $position=50) {
|
||||||
|
while(isset($this->mainblocks[$position])) $position++;
|
||||||
|
$this->mainblocks[$position] = $block;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==============================================
|
||||||
|
|
||||||
|
public function display() {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
header("Content-type: {$this->type}");
|
||||||
|
|
||||||
|
switch($this->mode) {
|
||||||
|
case "page":
|
||||||
|
header("Cache-control: no-cache");
|
||||||
|
ksort($this->sideblocks);
|
||||||
|
ksort($this->mainblocks);
|
||||||
|
$theme = $config->get_string("theme");
|
||||||
|
require_once "themes/$theme/default.php";
|
||||||
|
break;
|
||||||
|
case "data":
|
||||||
|
print $this->data;
|
||||||
|
break;
|
||||||
|
case "redirect":
|
||||||
|
header("Location: {$this->redirect}");
|
||||||
|
print "You should be redirected to <a href='{$this->redirect}'>{$this->redirect}</a>";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
print "Invalid page mode";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
50
core/paginator.class.php
Normal file
50
core/paginator.class.php
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Paginator extends Block {
|
||||||
|
var $header = null;
|
||||||
|
var $body = "";
|
||||||
|
|
||||||
|
public function Paginator($page, $query, $page_number, $total_pages) {
|
||||||
|
$this->body = $this->build_paginator($page_number, $total_pages, $page, $query);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function gen_page_link($base_url, $query, $page, $name) {
|
||||||
|
$link = make_link("$base_url/$page", $query);
|
||||||
|
return "<a href='$link'>$name</a>";
|
||||||
|
}
|
||||||
|
|
||||||
|
private function gen_page_link_block($base_url, $query, $page, $current_page, $name) {
|
||||||
|
$paginator = "";
|
||||||
|
if($page == $current_page) $paginator .= "<b>";
|
||||||
|
$paginator .= $this->gen_page_link($base_url, $query, $page, $name);
|
||||||
|
if($page == $current_page) $paginator .= "</b>";
|
||||||
|
return $paginator;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_paginator($current_page, $total_pages, $base_url, $query) {
|
||||||
|
$next = $current_page + 1;
|
||||||
|
$prev = $current_page - 1;
|
||||||
|
$rand = rand(1, $total_pages);
|
||||||
|
|
||||||
|
$at_start = ($current_page <= 1 || $total_pages <= 1);
|
||||||
|
$at_end = ($current_page >= $total_pages);
|
||||||
|
|
||||||
|
$first_html = $at_start ? "First" : $this->gen_page_link($base_url, $query, 1, "First");
|
||||||
|
$prev_html = $at_start ? "Prev" : $this->gen_page_link($base_url, $query, $prev, "Prev");
|
||||||
|
$random_html = $this->gen_page_link($base_url, $query, $rand, "Random");
|
||||||
|
$next_html = $at_end ? "Next" : $this->gen_page_link($base_url, $query, $next, "Next");
|
||||||
|
$last_html = $at_end ? "Last" : $this->gen_page_link($base_url, $query, $total_pages, "Last");
|
||||||
|
|
||||||
|
$start = $current_page-5 > 1 ? $current_page-5 : 1;
|
||||||
|
$end = $start+10 < $total_pages ? $start+10 : $total_pages;
|
||||||
|
|
||||||
|
$pages = array();
|
||||||
|
foreach(range($start, $end) as $i) {
|
||||||
|
$pages[] = $this->gen_page_link_block($base_url, $query, $i, $current_page, $i);
|
||||||
|
}
|
||||||
|
$pages_html = implode(" | ", $pages);
|
||||||
|
|
||||||
|
return "<p>$first_html | $prev_html | $random_html | $next_html | $last_html".
|
||||||
|
"<br><< $pages_html >></p>";
|
||||||
|
}
|
||||||
|
}
|
64
core/user.class.php
Normal file
64
core/user.class.php
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
class User {
|
||||||
|
var $id;
|
||||||
|
var $name;
|
||||||
|
var $email;
|
||||||
|
var $join_date;
|
||||||
|
var $days_old;
|
||||||
|
var $enabled;
|
||||||
|
var $admin;
|
||||||
|
|
||||||
|
public function User($row) {
|
||||||
|
$this->id = int_escape($row['id']);
|
||||||
|
$this->name = $row['name'];
|
||||||
|
$this->email = $row['email'];
|
||||||
|
$this->join_date = $row['joindate'];
|
||||||
|
$this->days_old = $row['days_old'];
|
||||||
|
$this->enabled = ($row['enabled'] == 'Y');
|
||||||
|
$this->admin = ($row['admin'] == 'Y');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function is_anonymous() {
|
||||||
|
global $config;
|
||||||
|
return ($this->id == $config->get_int('anon_id'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function is_enabled() {
|
||||||
|
return $this->enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_enabled($enabled) {
|
||||||
|
global $database;
|
||||||
|
|
||||||
|
$yn = $enabled ? 'Y' : 'N';
|
||||||
|
$database->db->Execute("UPDATE users SET enabled=? WHERE id=?",
|
||||||
|
array($yn, $this->id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function is_admin() {
|
||||||
|
return $this->admin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set_admin($admin) {
|
||||||
|
global $database;
|
||||||
|
|
||||||
|
$yn = $admin ? 'Y' : 'N';
|
||||||
|
$database->db->Execute("UPDATE users SET admin=? WHERE id=?",
|
||||||
|
array($yn, $this->id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_days_old() {
|
||||||
|
return $this->days_old;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_image_count() {
|
||||||
|
global $database;
|
||||||
|
return $database->db->GetOne("SELECT COUNT(*) AS count FROM images WHERE owner_id=?", $this->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_comment_count() {
|
||||||
|
global $database;
|
||||||
|
return $database->db->GetOne("SELECT COUNT(*) AS count FROM comments WHERE owner_id=?", $this->id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
197
core/util.inc.php
Normal file
197
core/util.inc.php
Normal file
|
@ -0,0 +1,197 @@
|
||||||
|
<?php
|
||||||
|
function html_escape($input) {
|
||||||
|
return htmlentities($input);
|
||||||
|
}
|
||||||
|
|
||||||
|
function int_escape($input) {
|
||||||
|
return (int)$input;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sql_escape($input) {
|
||||||
|
global $database;
|
||||||
|
return $database->db->Quote($input);
|
||||||
|
}
|
||||||
|
|
||||||
|
function make_link($page, $query=null) {
|
||||||
|
global $config;
|
||||||
|
$base = $config->get_string('base_href');
|
||||||
|
|
||||||
|
if(is_null($query)) {
|
||||||
|
return "$base/$page";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(strpos($base, "?")) {
|
||||||
|
return "$base/$page&$query";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "$base/$page?$query";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse_shorthand_int($limit) {
|
||||||
|
if(is_numeric($limit)) {
|
||||||
|
return (int)$limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(preg_match('/^([\d\.]+)([gmk])?b?$/i', "$limit", $m)) {
|
||||||
|
$value = $m[1];
|
||||||
|
if (isset($m[2])) {
|
||||||
|
switch(strtolower($m[2])) {
|
||||||
|
case 'g': $value *= 1024; # fallthrough
|
||||||
|
case 'm': $value *= 1024; # fallthrough
|
||||||
|
case 'k': $value *= 1024; break;
|
||||||
|
default: $value = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (int)$value;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function to_shorthand_int($int) {
|
||||||
|
if($int >= pow(1024, 3)) {
|
||||||
|
return sprintf("%.1fGB", $int / pow(1024, 3));
|
||||||
|
}
|
||||||
|
else if($int >= pow(1024, 2)) {
|
||||||
|
return sprintf("%.1fMB", $int / pow(1024, 2));
|
||||||
|
}
|
||||||
|
else if($int >= 1024) {
|
||||||
|
return sprintf("%.1fKB", $int / 1024);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "$int";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function bbcode2html($text) {
|
||||||
|
$text = trim($text);
|
||||||
|
$text = html_escape($text);
|
||||||
|
# $text = preg_replace("/\[b\](.*?)\[\/b\]/s", "<b>\\1</b>", $text);
|
||||||
|
# $text = preg_replace("/\[i\](.*?)\[\/i\]/s", "<i>\\1</i>", $text);
|
||||||
|
# $text = preg_replace("/\[u\](.*?)\[\/u\]/s", "<u>\\1</u>", $text);
|
||||||
|
$text = str_replace("\n", "\n<br>", $text);
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
function tag_explode($tags) {
|
||||||
|
if(is_string($tags)) {
|
||||||
|
$tags = explode(' ', $tags);
|
||||||
|
}
|
||||||
|
else if(is_array($tags)) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
die("tag_explode only takes strings or arrays");
|
||||||
|
}
|
||||||
|
|
||||||
|
$tags = array_map("trim", $tags);
|
||||||
|
|
||||||
|
foreach($tags as $tag) {
|
||||||
|
if(is_string($tag) && strlen($tag) > 0) {
|
||||||
|
$tag_array[] = $tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(count($tag_array) == 0) {
|
||||||
|
$tag_array = array("tagme");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tag_array;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# $db is the connection object
|
||||||
|
function CountExecs($db, $sql, $inputarray) {
|
||||||
|
global $_execs;
|
||||||
|
# $fp = fopen("sql.log", "a");
|
||||||
|
# fwrite($fp, preg_replace('/\s+/msi', ' ', $sql)."\n");
|
||||||
|
# fclose($fp);
|
||||||
|
if (!is_array($inputarray)) $_execs++;
|
||||||
|
# handle 2-dimensional input arrays
|
||||||
|
else if (is_array(reset($inputarray))) $_execs += sizeof($inputarray);
|
||||||
|
else $_execs++;
|
||||||
|
# in PHP4.4 and PHP5, we need to return a value by reference
|
||||||
|
$null = null; return $null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// internal things
|
||||||
|
|
||||||
|
$_event_listeners = array();
|
||||||
|
|
||||||
|
function add_event_listener($block, $pos=50) {
|
||||||
|
global $_event_listeners;
|
||||||
|
while(isset($_event_listeners[$pos])) {
|
||||||
|
$pos++;
|
||||||
|
}
|
||||||
|
$_event_listeners[$pos] = $block;
|
||||||
|
}
|
||||||
|
|
||||||
|
function send_event($event) {
|
||||||
|
global $_event_listeners;
|
||||||
|
foreach($_event_listeners as $listener) {
|
||||||
|
$listener->receive_event($event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function _get_query_parts() {
|
||||||
|
if(isset($_GET["q"])) {
|
||||||
|
$path = $_GET["q"];
|
||||||
|
}
|
||||||
|
else if(isset($_SERVER["PATH_INFO"])) {
|
||||||
|
$path = $_SERVER["PATH_INFO"];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$path = "index/1";
|
||||||
|
}
|
||||||
|
|
||||||
|
while(strlen($path) > 0 && $path[0] == '/') {
|
||||||
|
$path = substr($path, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return split('/', $path);
|
||||||
|
}
|
||||||
|
function get_page_request() {
|
||||||
|
$args = _get_query_parts();
|
||||||
|
|
||||||
|
if(count($args) == 0) {
|
||||||
|
$page = "index";
|
||||||
|
$args = array();
|
||||||
|
}
|
||||||
|
else if(count($args) == 1) {
|
||||||
|
$page = (strlen($args[0]) > 0 ? $args[0] : "index");
|
||||||
|
$args = array();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$page = $args[0];
|
||||||
|
$args = array_slice($args, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PageRequestEvent($page, $args);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_user() {
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$user = null;
|
||||||
|
if(isset($_COOKIE["shm_user"]) && isset($_COOKIE["shm_session"])) {
|
||||||
|
$tmp_user = $database->get_user_session($_COOKIE["shm_user"], $_COOKIE["shm_session"]);
|
||||||
|
if(!is_null($tmp_user) && $tmp_user->is_enabled()) {
|
||||||
|
$user = $tmp_user;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if(is_null($user)) {
|
||||||
|
$user = $database->get_user($config->get_int("anon_id"));
|
||||||
|
}
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
91
ext/alias_editor.ext.php
Normal file
91
ext/alias_editor.ext.php
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class AddAliasEvent extends Event {
|
||||||
|
var $oldtag;
|
||||||
|
var $newtag;
|
||||||
|
|
||||||
|
public function AddAliasEvent($oldtag, $newtag) {
|
||||||
|
$this->oldtag = $oldtag;
|
||||||
|
$this->newtag = $newtag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AliasEditor extends Extension {
|
||||||
|
// event handler {{{
|
||||||
|
public function receive_event($event) {
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "alias")) {
|
||||||
|
global $user;
|
||||||
|
if($user->is_admin()) {
|
||||||
|
if($event->get_arg(0) == "add") {
|
||||||
|
if(isset($_POST['oldtag']) && isset($_POST['newtag'])) {
|
||||||
|
send_event(new AddAliasEvent($_POST['oldtag'], $_POST['newtag']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if($event->get_arg(0) == "remove") {
|
||||||
|
if(isset($_POST['oldtag'])) {
|
||||||
|
global $database;
|
||||||
|
$database->db->Execute("DELETE FROM aliases WHERE oldtag=?", array($_POST['oldtag']));
|
||||||
|
|
||||||
|
global $page;
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("admin"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'AdminBuildingEvent')) {
|
||||||
|
global $page;
|
||||||
|
$page->add_main_block(new Block("Edit Aliases", $this->build_aliases()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'AddAliasEvent')) {
|
||||||
|
global $database;
|
||||||
|
$database->db->Execute("INSERT INTO aliases(oldtag, newtag) VALUES(?, ?)", array($event->oldtag, $event->newtag));
|
||||||
|
|
||||||
|
global $page;
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("admin"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// admin page HTML {{{
|
||||||
|
private function build_aliases() {
|
||||||
|
global $database;
|
||||||
|
$h_aliases = "";
|
||||||
|
$aliases = $database->db->GetAssoc("SELECT oldtag, newtag FROM aliases");
|
||||||
|
foreach($aliases as $old => $new) {
|
||||||
|
$h_old = html_escape($old);
|
||||||
|
$h_new = html_escape($new);
|
||||||
|
$h_aliases .= "
|
||||||
|
<tr>
|
||||||
|
<td>$h_old</td>
|
||||||
|
<td>$h_new</td>
|
||||||
|
<td>
|
||||||
|
<form action='".make_link("alias/remove")."' method='POST'>
|
||||||
|
<input type='hidden' name='oldtag' value='$h_old'>
|
||||||
|
<input type='submit' value='Remove'>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
";
|
||||||
|
}
|
||||||
|
$html = "
|
||||||
|
<table border='1'>
|
||||||
|
<thead><td>From</td><td>To</td><td>Action</td></thead>
|
||||||
|
$h_aliases
|
||||||
|
<tr>
|
||||||
|
<form action='".make_link("alias/add")."' method='POST'>
|
||||||
|
<td><input type='text' name='oldtag'></td>
|
||||||
|
<td><input type='text' name='newtag'></td>
|
||||||
|
<td><input type='submit' value='Add'></td>
|
||||||
|
</form>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
";
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
add_event_listener(new AliasEditor());
|
||||||
|
?>
|
73
ext/autocomplete.ext.php.disabled
Normal file
73
ext/autocomplete.ext.php.disabled
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class AutoComplete extends Extension {
|
||||||
|
// event handling {{{
|
||||||
|
public function receive_event($event) {
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "index" || $event->page == "view")) {
|
||||||
|
global $page;
|
||||||
|
$page->add_side_block(new Block(null, $this->build_autocomplete_script()));
|
||||||
|
}
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "autocomplete")) {
|
||||||
|
global $page;
|
||||||
|
$page->set_mode("data");
|
||||||
|
$page->set_type("text/plain");
|
||||||
|
$page->set_data($this->get_completions($event->get_arg(0)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// do things {{{
|
||||||
|
private function get_completions($start) {
|
||||||
|
global $database;
|
||||||
|
$tags = $database->db->GetCol("SELECT tag,count(image_id) AS count FROM tags WHERE tag LIKE ? GROUP BY tag ORDER BY count DESC", array($start.'%'));
|
||||||
|
return implode("\n", $tags);
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// html {{{
|
||||||
|
private function build_autocomplete_script() {
|
||||||
|
global $database;
|
||||||
|
$ac_url = html_escape(make_link("autocomplete"));
|
||||||
|
|
||||||
|
return <<<EOD
|
||||||
|
<script>
|
||||||
|
//completion_cache = new array();
|
||||||
|
|
||||||
|
input = byId("search_input");
|
||||||
|
output = byId("search_completions");
|
||||||
|
|
||||||
|
function get_cached_completions(start) {
|
||||||
|
// if(completion_cache[start]) {
|
||||||
|
// return completion_cache[start];
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
return null;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
function get_completions(start) {
|
||||||
|
cached = get_cached_completions(start);
|
||||||
|
if(cached) {
|
||||||
|
output.innerHTML = cached;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ajaxRequest("$ac_url/"+start, function(data) {set_completions(start, data);});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function set_completions(start, data) {
|
||||||
|
// completion_cache[start] = data;
|
||||||
|
output.innerHTML = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
input.onkeyup = function() {
|
||||||
|
if(input.value.length < 3) {
|
||||||
|
output.innerHTML = "";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
get_completions(input.value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
EOD;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
add_event_listener(new AutoComplete());
|
||||||
|
?>
|
102
ext/bulk_add.ext.php
Normal file
102
ext/bulk_add.ext.php
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class BulkAdd extends Extension {
|
||||||
|
// event handler {{{
|
||||||
|
public function receive_event($event) {
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "bulk_add")) {
|
||||||
|
global $user;
|
||||||
|
if($user->is_admin() && isset($_POST['dir'])) {
|
||||||
|
global $page;
|
||||||
|
$page->set_title("Adding folder");
|
||||||
|
$page->set_heading("Adding folder");
|
||||||
|
$page->add_side_block(new NavBlock());
|
||||||
|
$this->add_dir($_POST['dir']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'AdminBuildingEvent')) {
|
||||||
|
global $page;
|
||||||
|
$page->add_main_block(new Block("Bulk Add", $this->build_bulkadd()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// do the adding {{{
|
||||||
|
private function add_image($tmpname, $filename, $tags) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$ok = false;
|
||||||
|
|
||||||
|
if(filesize($tmpname) > $config->get_int('upload_size')) {
|
||||||
|
// $page->add_main_block(new Block("Error with ".html_escape($filename),
|
||||||
|
// "File too large (".filesize($file['tmp_name'])." > ".
|
||||||
|
// ($config->get_int('upload_size')).")"));
|
||||||
|
}
|
||||||
|
else if(!($info = getimagesize($tmpname))) {
|
||||||
|
// $page->add_main_block(new Block("Error with ".html_escape($file['name']),
|
||||||
|
// "PHP doesn't recognise this as an image file"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$image = new Image($tmpname, $filename, $tags);
|
||||||
|
|
||||||
|
if($image->is_ok()) {
|
||||||
|
send_event(new UploadingImageEvent($image));
|
||||||
|
$ok = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function add_dir($base, $subdir="") {
|
||||||
|
global $page;
|
||||||
|
|
||||||
|
if(!is_dir($base)) {
|
||||||
|
$page->add_main_block(new Block("Error", "$base is not a directory"));
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = "";
|
||||||
|
|
||||||
|
$dir = opendir("$base/$subdir");
|
||||||
|
while($filename = readdir($dir)) {
|
||||||
|
$fullpath = "$base/$subdir/$filename";
|
||||||
|
|
||||||
|
if(is_dir($fullpath)) {
|
||||||
|
if($filename[0] != ".") {
|
||||||
|
$this->add_dir($base, "$subdir/$filename");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$tmpfile = $fullpath;
|
||||||
|
$list .= "<br>".html_escape("$subdir/$filename (".str_replace("/", ",", $subdir).")...");
|
||||||
|
if($this->add_image($tmpfile, $filename, str_replace("/", " ", $subdir))) {
|
||||||
|
$list .= "ok\n";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$list .= "failed\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir($dir);
|
||||||
|
|
||||||
|
$page->add_main_block(new Block("Adding $subdir", $list));
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// admin page HTML {{{
|
||||||
|
private function build_bulkadd() {
|
||||||
|
$html = "
|
||||||
|
Add a folder full of images; any subfolders will have their names
|
||||||
|
used as tags for the images within.
|
||||||
|
<br>Note: this is the folder as seen by the server -- you need to
|
||||||
|
upload via FTP or something first.
|
||||||
|
|
||||||
|
<p><form action='".make_link("bulk_add")."' method='POST'>
|
||||||
|
Directory to add: <input type='text' name='dir' size='40'>
|
||||||
|
<input type='submit' value='Add'>
|
||||||
|
</form>
|
||||||
|
";
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
add_event_listener(new BulkAdd());
|
||||||
|
?>
|
386
ext/comment.ext.php
Normal file
386
ext/comment.ext.php
Normal file
|
@ -0,0 +1,386 @@
|
||||||
|
<?php
|
||||||
|
require_once "lib/akismet.class.php";
|
||||||
|
|
||||||
|
/* CommentDeletionEvent {{{
|
||||||
|
* CommentDeletionEvent:
|
||||||
|
* $comment_id
|
||||||
|
*
|
||||||
|
* A comment is being deleted. Maybe used by spam
|
||||||
|
* detectors to get a feel for what should be delted
|
||||||
|
* and what should be kept?
|
||||||
|
*/
|
||||||
|
class CommentDeletionEvent extends Event {
|
||||||
|
var $comment_id;
|
||||||
|
|
||||||
|
public function CommentDeletionEvent($comment_id) {
|
||||||
|
$this->comment_id = $comment_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
class Comment { // {{{
|
||||||
|
public function Comment($row) {
|
||||||
|
$this->owner_id = $row['user_id'];
|
||||||
|
$this->owner_name = $row['user_name'];
|
||||||
|
$this->comment = $row['comment'];
|
||||||
|
$this->comment_id = $row['comment_id'];
|
||||||
|
$this->image_id = $row['image_id'];
|
||||||
|
$this->poster_ip = $row['poster_ip'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function to_html($link_to_image = false) {
|
||||||
|
global $user;
|
||||||
|
|
||||||
|
$i_uid = int_escape($this->owner_id);
|
||||||
|
$h_name = html_escape($this->owner_name);
|
||||||
|
$h_poster_ip = html_escape($this->poster_ip);
|
||||||
|
$h_comment = bbcode2html($this->comment);
|
||||||
|
$i_comment_id = int_escape($this->comment_id);
|
||||||
|
$i_image_id = int_escape($this->image_id);
|
||||||
|
|
||||||
|
$h_userlink = "<a href='".make_link("user/$h_name")."'>$h_name</a>";
|
||||||
|
$h_dellink = $user->is_admin() ?
|
||||||
|
"<br>($h_poster_ip, <a href='".make_link("comment/delete/$i_comment_id/$i_image_id")."'>Del</a>)" : "";
|
||||||
|
$h_imagelink = $link_to_image ? "<a href='".make_link("post/view/$i_image_id")."'>>>></a>\n" : "";
|
||||||
|
return "<p>$h_userlink: $h_comment $h_imagelink $h_dellink</p>";
|
||||||
|
}
|
||||||
|
} // }}}
|
||||||
|
|
||||||
|
class CommentList extends Extension {
|
||||||
|
// event handler {{{
|
||||||
|
public function receive_event($event) {
|
||||||
|
if(is_a($event, 'InitExtEvent')) {
|
||||||
|
global $config;
|
||||||
|
if($config->get_int("ext_comments_version") < 1) {
|
||||||
|
$this->install();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "comment")) {
|
||||||
|
if($event->get_arg(0) == "add") {
|
||||||
|
$this->add_comment_wrapper($_POST['image_id'], $_POST['comment']);
|
||||||
|
}
|
||||||
|
else if($event->get_arg(0) == "delete") {
|
||||||
|
global $user;
|
||||||
|
global $page;
|
||||||
|
if($user->is_admin()) {
|
||||||
|
// FIXME: post, not args
|
||||||
|
if($event->count_args() == 3) {
|
||||||
|
send_event(new CommentDeletionEvent($event->get_arg(1)));
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("post/view/".$event->get_arg(2)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// FIXME: denied message
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if($event->get_arg(0) == "rss") {
|
||||||
|
$this->build_rss();
|
||||||
|
}
|
||||||
|
else if($event->get_arg(0) == "list") {
|
||||||
|
$this->build_page($event->get_arg(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "index")) {
|
||||||
|
global $page;
|
||||||
|
global $config;
|
||||||
|
if($config->get_int("comment_count") > 0) {
|
||||||
|
$page->add_side_block(new Block("Comments", $this->build_recent_comments()), 50);
|
||||||
|
// $page->add_quicknav("Comments", make_link("comments/list"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'DisplayingImageEvent')) {
|
||||||
|
global $page;
|
||||||
|
$page->add_main_block(new Block("Comments",
|
||||||
|
$this->build_image_comments($event->image->id).
|
||||||
|
$this->build_postbox($event->image->id)), 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'ImageDeletionEvent')) {
|
||||||
|
$this->delete_comments($event->image->id);
|
||||||
|
}
|
||||||
|
if(is_a($event, 'CommentDeletionEvent')) {
|
||||||
|
$this->delete_comment($event->comment_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'SetupBuildingEvent')) {
|
||||||
|
$sb = new SetupBlock("Comment Options");
|
||||||
|
$sb->add_label("Allow anonymous comments ");
|
||||||
|
$sb->add_bool_option("comment_anon");
|
||||||
|
$sb->add_label("<br>Limit to ");
|
||||||
|
$sb->add_int_option("comment_limit");
|
||||||
|
$sb->add_label(" comments per ");
|
||||||
|
$sb->add_int_option("comment_window");
|
||||||
|
$sb->add_label(" minutes");
|
||||||
|
$sb->add_label("<br>Show ");
|
||||||
|
$sb->add_int_option("comment_count");
|
||||||
|
$sb->add_label(" recent comments on the index");
|
||||||
|
$sb->add_label("<br>Akismet Key ");
|
||||||
|
$sb->add_text_option("comment_wordpress_key");
|
||||||
|
$event->panel->add_main_block($sb);
|
||||||
|
}
|
||||||
|
if(is_a($event, 'ConfigSaveEvent')) {
|
||||||
|
$event->config->set_bool("comment_anon", $_POST['comment_anon']);
|
||||||
|
$event->config->set_int("comment_limit", $_POST['comment_limit']);
|
||||||
|
$event->config->set_int("comment_window", $_POST['comment_window']);
|
||||||
|
$event->config->set_int("comment_count", $_POST['comment_count']);
|
||||||
|
$event->config->set_string("comment_wordpress_key", $_POST['comment_wordpress_key']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// installer {{{
|
||||||
|
protected function install() {
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
$database->db->Execute("CREATE TABLE `comments` (
|
||||||
|
`id` int(11) NOT NULL auto_increment,
|
||||||
|
`image_id` int(11) NOT NULL,
|
||||||
|
`owner_id` int(11) NOT NULL,
|
||||||
|
`owner_ip` char(16) NOT NULL,
|
||||||
|
`posted` datetime default NULL,
|
||||||
|
`comment` text NOT NULL,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `comments_image_id` (`image_id`)
|
||||||
|
)");
|
||||||
|
$config->set_int("ext_comments_version", 1);
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// page building {{{
|
||||||
|
private function build_rss() {
|
||||||
|
global $page;
|
||||||
|
$page->set_mode("data");
|
||||||
|
$page->set_type("application/rss+xml");
|
||||||
|
|
||||||
|
$rss = "moo"; // FIXME
|
||||||
|
|
||||||
|
$page->set_data($rss);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_page($current_page) {
|
||||||
|
global $page;
|
||||||
|
global $database;
|
||||||
|
|
||||||
|
if(is_null($current_page) || $current_page <= 0) {
|
||||||
|
$current_page = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$threads_per_page = 10;
|
||||||
|
$start = $threads_per_page * ($current_page - 1);
|
||||||
|
|
||||||
|
$get_threads = "
|
||||||
|
SELECT image_id,MAX(posted) AS latest
|
||||||
|
FROM comments
|
||||||
|
GROUP BY image_id
|
||||||
|
ORDER BY latest DESC
|
||||||
|
LIMIT ?,?
|
||||||
|
";
|
||||||
|
$result = $database->db->Execute($get_threads, array($start, $threads_per_page));
|
||||||
|
|
||||||
|
|
||||||
|
$total_pages = (int)($database->db->GetOne("SELECT COUNT(distinct image_id) AS count FROM comments") / 10);
|
||||||
|
|
||||||
|
$page->set_title("Comments");
|
||||||
|
$page->set_heading("Comments");
|
||||||
|
$page->add_side_block(new Block("Navigation", $this->build_navigation($current_page, $total_pages)));
|
||||||
|
$page->add_main_block(new Paginator("comment/list", null, $current_page, $total_pages), 90);
|
||||||
|
|
||||||
|
$n = 10;
|
||||||
|
while(!$result->EOF) {
|
||||||
|
$image = $database->get_image($result->fields["image_id"]);
|
||||||
|
|
||||||
|
$html = "<div style='text-align: left'>";
|
||||||
|
$html .= "<a href='".make_link("post/view/{$image->id}")."'>";
|
||||||
|
$html .= "<img src='".($image->get_thumb_link())."' align='left' style='margin-right: 16px;'></a>";
|
||||||
|
$html .= $this->build_image_comments($image->id);
|
||||||
|
$html .= "</div>";
|
||||||
|
$html .= "<div style='clear:both;'>".($this->build_postbox($image->id))."</div>";
|
||||||
|
|
||||||
|
$page->add_main_block(new Block("{$image->id}: ".($image->get_tag_list()), $html), $n);
|
||||||
|
$n += 1;
|
||||||
|
$result->MoveNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_navigation($page_number, $total_pages) {
|
||||||
|
$prev = $page_number - 1;
|
||||||
|
$next = $page_number + 1;
|
||||||
|
|
||||||
|
$h_prev = ($page_number <= 1) ? "Prev" :
|
||||||
|
"<a href='".make_link("comment/list/$prev")."'>Prev</a>";
|
||||||
|
$h_index = "<a href='".make_link("index")."'>Index</a>";
|
||||||
|
$h_next = ($page_number >= $total_pages) ? "Next" :
|
||||||
|
"<a href='".make_link("comment/list/$next")."'>Next</a>";
|
||||||
|
|
||||||
|
return "$h_prev | $h_index | $h_next";
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_image_comments($image_id) {
|
||||||
|
global $config;
|
||||||
|
$i_image_id = int_escape($image_id);
|
||||||
|
$html = "<div id='image_comments'>";
|
||||||
|
$html .= $this->query_to_html("
|
||||||
|
SELECT
|
||||||
|
users.id as user_id, users.name as user_name,
|
||||||
|
comments.comment as comment, comments.id as comment_id,
|
||||||
|
comments.image_id as image_id, comments.owner_ip as poster_ip
|
||||||
|
FROM comments
|
||||||
|
LEFT JOIN users ON comments.owner_id=users.id
|
||||||
|
WHERE comments.image_id=?
|
||||||
|
ORDER BY comments.id ASC
|
||||||
|
", array($i_image_id));
|
||||||
|
$html .= "</div>";
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_recent_comments() {
|
||||||
|
global $config;
|
||||||
|
$html = $this->query_to_html("
|
||||||
|
SELECT
|
||||||
|
users.id as user_id, users.name as user_name,
|
||||||
|
if(
|
||||||
|
length(comments.comment) > 50,
|
||||||
|
concat(substring(comments.comment, 1, 50), ' ...'),
|
||||||
|
comments.comment
|
||||||
|
) as comment,
|
||||||
|
comments.id as comment_id,
|
||||||
|
comments.image_id as image_id, comments.owner_ip as poster_ip
|
||||||
|
FROM comments
|
||||||
|
LEFT JOIN users ON comments.owner_id=users.id
|
||||||
|
ORDER BY comments.id DESC
|
||||||
|
LIMIT ?
|
||||||
|
", array($config->get_int('comment_count')), true);
|
||||||
|
$html .= "<p><a href='".make_link("comment/list")."'>Full List >>></a>";
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_postbox($image_id) {
|
||||||
|
if($this->can_comment()) {
|
||||||
|
$i_image_id = int_escape($image_id);
|
||||||
|
return "
|
||||||
|
<form action='".make_link("comment/add")."' method='POST'>
|
||||||
|
<input type='hidden' name='image_id' value='$i_image_id' />
|
||||||
|
<textarea name='comment' rows='5' cols='50'></textarea>
|
||||||
|
<br><input type='submit' value='Post' />
|
||||||
|
</form>
|
||||||
|
";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "<p><small>You need to create an account before you can comment</small></p>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function query_to_html($query, $args, $link_to_image=false) {
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$html = "";
|
||||||
|
$result = $database->db->Execute($query, $args);
|
||||||
|
while(!$result->EOF) {
|
||||||
|
$comment = new Comment($result->fields);
|
||||||
|
$html .= $comment->to_html($link_to_image);
|
||||||
|
$result->MoveNext();
|
||||||
|
}
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// add / remove / edit comments {{{
|
||||||
|
private function is_comment_limit_hit() {
|
||||||
|
global $user;
|
||||||
|
global $config;
|
||||||
|
global $database;
|
||||||
|
|
||||||
|
$window = int_escape($config->get_int('comment_window'));
|
||||||
|
$max = int_escape($config->get_int('comment_limit'));
|
||||||
|
|
||||||
|
$result = $database->db->Execute("SELECT * FROM comments WHERE owner_ip = ? ".
|
||||||
|
"AND posted > date_sub(now(), interval ? minute)",
|
||||||
|
Array($_SERVER['REMOTE_ADDR'], $window));
|
||||||
|
$recent_comments = $result->RecordCount();
|
||||||
|
|
||||||
|
return ($recent_comments >= $max);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function is_spam($text) {
|
||||||
|
global $user;
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
if(strlen($config->get_string('comment_wordpress_key')) == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$comment = array(
|
||||||
|
'author' => $user->name,
|
||||||
|
'email' => $user->email,
|
||||||
|
'website' => '',
|
||||||
|
'body' => $text,
|
||||||
|
'permalink' => '',
|
||||||
|
);
|
||||||
|
|
||||||
|
$akismet = new Akismet(
|
||||||
|
'http://www.yourdomain.com/',
|
||||||
|
$config->get_string('comment_wordpress_key'),
|
||||||
|
$comment);
|
||||||
|
|
||||||
|
if($akismet->errorsExist()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return $akismet->isSpam();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function can_comment() {
|
||||||
|
global $config;
|
||||||
|
return ($config->get_bool('comment_anon') || !$user->is_anonymous());
|
||||||
|
}
|
||||||
|
|
||||||
|
private function add_comment_wrapper($image_id, $comment) {
|
||||||
|
global $user;
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
global $page;
|
||||||
|
|
||||||
|
$page->set_title("Error");
|
||||||
|
$page->set_heading("Error");
|
||||||
|
$page->add_side_block(new NavBlock());
|
||||||
|
if(!$config->get_bool('comment_anon') && $user->is_anonymous()) {
|
||||||
|
$page->add_main_block(new Block("Permission Denied", "Anonymous posting has been disabled"));
|
||||||
|
}
|
||||||
|
else if(trim($comment) == "") {
|
||||||
|
$page->add_main_block(new Block("Comment Empty", "Comments need text..."));
|
||||||
|
}
|
||||||
|
else if($this->is_comment_limit_hit()) {
|
||||||
|
$page->add_main_block(new Block("Comment Limit Hit",
|
||||||
|
"You've posted several comments recently; wait a minute and try again..."));
|
||||||
|
}
|
||||||
|
else if($this->is_spam($comment)) {
|
||||||
|
$page->add_main_block(new Block("Spam Detected",
|
||||||
|
"Akismet thinks that your comment is spam. Try rewriting the comment?"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$database->db->Execute(
|
||||||
|
"INSERT INTO comments(image_id, owner_id, owner_ip, posted, comment) ".
|
||||||
|
"VALUES(?, ?, ?, now(), ?)",
|
||||||
|
array($image_id, $user->id, $_SERVER['REMOTE_ADDR'], $comment));
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("post/view/".int_escape($image_id)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function delete_comments($image_id) {
|
||||||
|
global $database;
|
||||||
|
$database->db->Execute("DELETE FROM comments WHERE image_id=?", array($image_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function delete_comment($comment_id) {
|
||||||
|
global $database;
|
||||||
|
$database->db->Execute("DELETE FROM comments WHERE id=?", array($comment_id));
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
add_event_listener(new CommentList());
|
||||||
|
?>
|
51
ext/downtime.ext.php
Normal file
51
ext/downtime.ext.php
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Downtime extends Extension {
|
||||||
|
// event handler {{{
|
||||||
|
public function receive_event($event) {
|
||||||
|
$this->check_downtime($event);
|
||||||
|
|
||||||
|
if(is_a($event, 'SetupBuildingEvent')) {
|
||||||
|
$sb = new SetupBlock("Downtime");
|
||||||
|
$sb->add_label("Disable non-admin access: ");
|
||||||
|
$sb->add_bool_option("downtime");
|
||||||
|
$sb->add_label("<br>");
|
||||||
|
$sb->add_longtext_option("downtime_message");
|
||||||
|
$event->panel->add_main_block($sb);
|
||||||
|
}
|
||||||
|
if(is_a($event, 'ConfigSaveEvent')) {
|
||||||
|
$event->config->set_bool("downtime", $_POST['downtime']);
|
||||||
|
$event->config->set_string("downtime_message", $_POST['downtime_message']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// do things {{{
|
||||||
|
private function check_downtime($event) {
|
||||||
|
global $user;
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
if($config->get_bool("downtime") && !$user->is_admin() &&
|
||||||
|
is_a($event, 'PageRequestEvent') && !$this->is_safe_page($event)) {
|
||||||
|
$msg = $config->get_string("downtime_message");
|
||||||
|
print <<<EOD
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Downtime</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
$msg
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
EOD;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function is_safe_page($event) {
|
||||||
|
if($event->page == "user" && $event->get_arg(0) == "login") return true;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
add_event_listener(new Downtime(), 10);
|
||||||
|
?>
|
90
ext/et.ext.php
Normal file
90
ext/et.ext.php
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class ET extends Extension {
|
||||||
|
// event handler {{{
|
||||||
|
public function receive_event($event) {
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "phone_home")) {
|
||||||
|
global $user;
|
||||||
|
if($user->is_admin()) {
|
||||||
|
$this->phone_home();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'AdminBuildingEvent')) {
|
||||||
|
global $page;
|
||||||
|
$page->add_main_block(new Block("Gather System Info", $this->build_phone_home()), 99);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// do it {{{
|
||||||
|
private function phone_home() {
|
||||||
|
global $page;
|
||||||
|
$page->set_title("System Info");
|
||||||
|
$page->set_heading("System Info");
|
||||||
|
$page->add_side_block(new NavBlock());
|
||||||
|
$page->add_main_block(new Block("Data which is to be sent:", $this->build_data_form()));
|
||||||
|
}
|
||||||
|
private function build_data_form() {
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$data = "";
|
||||||
|
|
||||||
|
$data .= "Optional:\n";
|
||||||
|
$data .= "Add this site to the public shimmie users list: No\n";
|
||||||
|
$data .= "Site title: ".($config->get_string("title"))."\n";
|
||||||
|
$data .= "Theme: ".($config->get_string("theme"))."\n";
|
||||||
|
$data .= "Genre: [please write something here]\n";
|
||||||
|
|
||||||
|
$data .= "\nSystem stats:\n";
|
||||||
|
$data .= "PHP: ".phpversion()."\n";
|
||||||
|
$data .= "OS: ".php_uname()."\n";
|
||||||
|
$data .= "Server: ".($_SERVER["SERVER_SOFTWARE"])."\n";
|
||||||
|
|
||||||
|
include "config.php";
|
||||||
|
$proto = preg_replace("#(.*)://.*#", "$1", $database_dsn);
|
||||||
|
$db = $database->db->ServerInfo();
|
||||||
|
$data .= "Database: $proto / {$db['version']}\n";
|
||||||
|
|
||||||
|
$data .= "\nShimmie stats:\n";
|
||||||
|
$uri = isset($_SERVER['SCRIPT_URI']) ? dirname($_SERVER['SCRIPT_URI']) : "???";
|
||||||
|
$data .= "URL: ".($uri)."\n";
|
||||||
|
$data .= "Version: ".($config->get_string("version"))."\n";
|
||||||
|
$data .= "Images: ".($database->db->GetOne("SELECT COUNT(*) FROM images"))."\n";
|
||||||
|
$data .= "Comments: ".($database->db->GetOne("SELECT COUNT(*) FROM comments"))."\n";
|
||||||
|
$data .= "Users: ".($database->db->GetOne("SELECT COUNT(*) FROM users"))."\n";
|
||||||
|
$data .= "Tags: ".($database->db->GetOne("SELECT COUNT(*) FROM tags"))."\n";
|
||||||
|
|
||||||
|
$html = "
|
||||||
|
<form action='http://shimmie.shishnet.org/register.php' method='POST'>
|
||||||
|
<input type='hidden' name='registration_api' value='1'>
|
||||||
|
<textarea name='data' rows='20' cols='80'>$data</textarea>
|
||||||
|
<br><input type='submit' value='Click to send to Shish'>
|
||||||
|
<br>Your stats are useful so that I know which combinations
|
||||||
|
of web servers / databases / etc I need to support,
|
||||||
|
<br>and so
|
||||||
|
that I can get some idea of how people use shimmie generally
|
||||||
|
</form>
|
||||||
|
";
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// admin page HTML {{{
|
||||||
|
private function build_phone_home() {
|
||||||
|
global $database;
|
||||||
|
$h_bans = "";
|
||||||
|
$html = "
|
||||||
|
This button will gather various bits of information about
|
||||||
|
your system (PHP version, database, etc) which will be
|
||||||
|
useful in debugging~
|
||||||
|
|
||||||
|
<p><form action='".make_link("phone_home")."' method='POST'>
|
||||||
|
<input type='submit' value='Gather Info'>
|
||||||
|
</form>
|
||||||
|
";
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
add_event_listener(new ET());
|
||||||
|
?>
|
169
ext/ipban.ext.php
Normal file
169
ext/ipban.ext.php
Normal file
|
@ -0,0 +1,169 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// RemoveIPBanEvent {{{
|
||||||
|
class RemoveIPBanEvent extends Event {
|
||||||
|
var $ip;
|
||||||
|
|
||||||
|
public function RemoveIPBanEvent($ip) {
|
||||||
|
$this->ip = $ip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// AddIPBanEvent {{{
|
||||||
|
class AddIPBanEvent extends Event {
|
||||||
|
var $ip;
|
||||||
|
var $reason;
|
||||||
|
|
||||||
|
public function AddIPBanEvent($ip, $reason) {
|
||||||
|
$this->ip = $ip;
|
||||||
|
$this->reason = $reason;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
class IPBan extends Extension {
|
||||||
|
// event handler {{{
|
||||||
|
public function receive_event($event) {
|
||||||
|
if(is_a($event, 'InitExtEvent')) {
|
||||||
|
global $config;
|
||||||
|
if($config->get_int("ext_ipban_version") < 1) {
|
||||||
|
$this->install();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->check_ip_ban();
|
||||||
|
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "ip_ban")) {
|
||||||
|
global $user;
|
||||||
|
if($user->is_admin()) {
|
||||||
|
if($event->get_arg(0) == "add") {
|
||||||
|
if(isset($_POST['ip']) && isset($_POST['reason'])) {
|
||||||
|
send_event(new AddIPBanEvent($_POST['ip'], $_POST['reason']));
|
||||||
|
|
||||||
|
global $page;
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("admin"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if($event->get_arg(0) == "remove") {
|
||||||
|
if(isset($_POST['ip'])) {
|
||||||
|
send_event(new RemoveIPBanEvent($_POST['ip']));
|
||||||
|
|
||||||
|
global $page;
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("admin"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'AddIPBanEvent')) {
|
||||||
|
$this->add_ip_ban($event->ip, $event->reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'RemoveIPBanEvent')) {
|
||||||
|
$this->remove_ip_ban($event->ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'AdminBuildingEvent')) {
|
||||||
|
global $page;
|
||||||
|
$page->add_main_block(new Block("Edit IP Bans", $this->build_ip_bans()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// installer {{{
|
||||||
|
protected function install() {
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
$database->db->Execute("CREATE TABLE bans (
|
||||||
|
id int(11) NOT NULL auto_increment,
|
||||||
|
ip char(15) default NULL,
|
||||||
|
date datetime default NULL,
|
||||||
|
end datetime default NULL,
|
||||||
|
reason varchar(255) default NULL,
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
)");
|
||||||
|
$config->set_int("ext_ipban_version", 1);
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// deal with banned person {{{
|
||||||
|
private function check_ip_ban() {
|
||||||
|
$row = $this->get_ip_ban($_SERVER['REMOTE_ADDR']);
|
||||||
|
if($row) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
print "IP <b>{$row['ip']}</b> has been banned because of <b>{$row['reason']}</b>";
|
||||||
|
|
||||||
|
$contact_link = $config->get_string("contact_link");
|
||||||
|
if(!empty($contact_link)) {
|
||||||
|
print "<p><a href='$contact_link'>Contact The Admin</a>";
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// database {{{
|
||||||
|
public function get_bans() {
|
||||||
|
// FIXME: many
|
||||||
|
global $database;
|
||||||
|
$bans = $database->db->GetAll("SELECT * FROM bans");
|
||||||
|
if($bans) {return $bans;}
|
||||||
|
else {return array();}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_ip_ban($ip) {
|
||||||
|
global $database;
|
||||||
|
// yes, this is "? LIKE var", because ? is the thing with matching tokens
|
||||||
|
return $database->db->GetRow("SELECT * FROM bans WHERE ? LIKE ip", array($ip));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add_ip_ban($ip, $reason) {
|
||||||
|
global $database;
|
||||||
|
$database->db->Execute(
|
||||||
|
"INSERT INTO bans (ip, reason, date) VALUES (?, ?, now())",
|
||||||
|
array($ip, $reason));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function remove_ip_ban($ip) {
|
||||||
|
global $database;
|
||||||
|
$database->db->Execute("DELETE FROM bans WHERE ip = ?", array($ip));
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// admin page HTML {{{
|
||||||
|
private function build_ip_bans() {
|
||||||
|
global $database;
|
||||||
|
$h_bans = "";
|
||||||
|
$bans = $this->get_bans();
|
||||||
|
foreach($bans as $ban) {
|
||||||
|
$h_bans .= "
|
||||||
|
<tr>
|
||||||
|
<td>{$ban['ip']}</td>
|
||||||
|
<td>{$ban['reason']}</td>
|
||||||
|
<td>
|
||||||
|
<form action='".make_link("ip_ban/remove")."' method='POST'>
|
||||||
|
<input type='hidden' name='ip' value='{$ban['ip']}'>
|
||||||
|
<input type='submit' value='Remove'>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
";
|
||||||
|
}
|
||||||
|
$html = "
|
||||||
|
<table border='1'>
|
||||||
|
<thead><td>IP</td><td>Reason</td><td>Action</td></thead>
|
||||||
|
$h_bans
|
||||||
|
<tr>
|
||||||
|
<form action='".make_link("ip_ban/add")."' method='POST'>
|
||||||
|
<td><input type='text' name='ip'></td>
|
||||||
|
<td><input type='text' name='reason'></td>
|
||||||
|
<td><input type='submit' value='Ban'></td>
|
||||||
|
</form>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
";
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
add_event_listener(new IPBan(), 10);
|
||||||
|
?>
|
23
ext/news.ext.php
Normal file
23
ext/news.ext.php
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class News extends Extension {
|
||||||
|
public function receive_event($event) {
|
||||||
|
global $page;
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "index")) {
|
||||||
|
global $config;
|
||||||
|
if(strlen($config->get_string("news_text")) > 0) {
|
||||||
|
$page->add_side_block(new Block("Note", $config->get_string("news_text")), 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(is_a($event, 'SetupBuildingEvent')) {
|
||||||
|
$sb = new SetupBlock("News");
|
||||||
|
$sb->add_longtext_option("news_text");
|
||||||
|
$event->panel->add_main_block($sb);
|
||||||
|
}
|
||||||
|
if(is_a($event, 'ConfigSaveEvent')) {
|
||||||
|
$event->config->set_string("news_text", $_POST['news_text']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_event_listener(new News());
|
||||||
|
?>
|
52
ext/notes.ext.php.disabled
Normal file
52
ext/notes.ext.php.disabled
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Notes extends Extension {
|
||||||
|
public function receive_event($event) {
|
||||||
|
if(is_a($event, 'InitExtEvent')) {
|
||||||
|
global $config;
|
||||||
|
if($config->get_int("ext_notes_version") < 1) {
|
||||||
|
$this->install();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'DisplayingImageEvent')) {
|
||||||
|
global $page;
|
||||||
|
$page->add_main_block(new Block(null, $this->make_notes($event->image->id)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function install() {
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
$database->db->Execute("CREATE TABLE `image_notes` (
|
||||||
|
`id` int(11) NOT NULL auto_increment,
|
||||||
|
`image_id` int(11) NOT NULL,
|
||||||
|
`user_id` int(11) NOT NULL,
|
||||||
|
`owner_ip` char(15) NOT NULL,
|
||||||
|
`created_at` datetime NOT NULL,
|
||||||
|
`updated_at` datetime NOT NULL,
|
||||||
|
`version` int(11) DEFAULT 1 NOT NULL,
|
||||||
|
`is_active` enum('Y', 'N') DEFAULT 'Y' NOT NULL,
|
||||||
|
`x` int(11) NOT NULL,
|
||||||
|
`y` int(11) NOT NULL,
|
||||||
|
`w` int(11) NOT NULL,
|
||||||
|
`h` int(11) NOT NULL,
|
||||||
|
`body` text NOT NULL,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
)");
|
||||||
|
$config->set_int("ext_notes_version", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function make_notes($image_id) {
|
||||||
|
global $database;
|
||||||
|
$notes = $database->db->GetAll("SELECT * FROM image_notes WHERE image_id = ?", array($image_id));
|
||||||
|
|
||||||
|
return <<<EOD
|
||||||
|
<script type="text/javascript">
|
||||||
|
img = byId("main_image");
|
||||||
|
</script>
|
||||||
|
EOD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_event_listener(new Notes());
|
||||||
|
?>
|
130
ext/rating.ext.php.disabled
Normal file
130
ext/rating.ext.php.disabled
Normal file
|
@ -0,0 +1,130 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Ratings extends Extension {
|
||||||
|
// event handler {{{
|
||||||
|
public function receive_event($event) {
|
||||||
|
if(is_a($event, 'InitExtEvent')) {
|
||||||
|
global $config;
|
||||||
|
if($config->get_int("ext_ratings_version") < 1) {
|
||||||
|
$this->install();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
if(is_a($event, 'ImageDeletionEvent')) {
|
||||||
|
$this->delete_comments($event->image->id);
|
||||||
|
}
|
||||||
|
if(is_a($event, 'CommentDeletionEvent')) {
|
||||||
|
$this->delete_comment($event->comment_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'SetupBuildingEvent')) {
|
||||||
|
$sb = new SetupBlock("Comment Options");
|
||||||
|
$sb->add_label("Allow anonymous comments ");
|
||||||
|
$sb->add_bool_option("comment_anon");
|
||||||
|
$sb->add_label("<br>Limit to ");
|
||||||
|
$sb->add_int_option("comment_limit", 1, 60);
|
||||||
|
$sb->add_label(" comments per ");
|
||||||
|
$sb->add_int_option("comment_window", 1, 60);
|
||||||
|
$sb->add_label(" minutes");
|
||||||
|
$sb->add_label("<br>Show ");
|
||||||
|
$sb->add_int_option("comment_count", 0, 100);
|
||||||
|
$sb->add_label(" recent comments on the index");
|
||||||
|
$event->panel->add_main_block($sb);
|
||||||
|
}
|
||||||
|
if(is_a($event, 'ConfigSaveEvent')) {
|
||||||
|
$event->config->set_bool("comment_anon", $_POST['comment_anon']);
|
||||||
|
$event->config->set_int("comment_limit", $_POST['comment_limit']);
|
||||||
|
$event->config->set_int("comment_window", $_POST['comment_window']);
|
||||||
|
$event->config->set_int("comment_count", $_POST['comment_count']);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
private function can_comment() {
|
||||||
|
global $config, $user;
|
||||||
|
return $config->get_bool("rate_anon") || ($user->id != $config->get_int("anon_id"));
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// installer {{{
|
||||||
|
protected function install() {
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
$database->db->Execute("CREATE TABLE `image_voters` (
|
||||||
|
`image_id` int(11) NOT NULL,
|
||||||
|
`user_id` int(11) NOT NULL,
|
||||||
|
`vote` tinyint(4) NOT NULL,
|
||||||
|
`voted` datetime NOT NULL,
|
||||||
|
PRIMARY KEY (`image_id`,`user_id`)
|
||||||
|
)");
|
||||||
|
$config->set_int("ext_ratings_version", 1);
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// page building {{{
|
||||||
|
|
||||||
|
private function build_image_rating($image_id) {
|
||||||
|
global $config;
|
||||||
|
$i_image_id = int_escape($image_id);
|
||||||
|
return $this->query_to_html("
|
||||||
|
SELECT
|
||||||
|
users.id as user_id, users.name as user_name,
|
||||||
|
comments.comment as comment, comments.id as comment_id,
|
||||||
|
comments.image_id as image_id, comments.owner_ip as poster_ip
|
||||||
|
FROM comments
|
||||||
|
LEFT JOIN users ON comments.owner_id=users.id
|
||||||
|
WHERE comments.image_id=?
|
||||||
|
ORDER BY comments.id ASC
|
||||||
|
LIMIT ?
|
||||||
|
", array($i_image_id, $config->get_int('recent_count')));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_rater($image_id) {
|
||||||
|
if($this->can_comment()) {
|
||||||
|
$i_image_id = int_escape($image_id);
|
||||||
|
return "
|
||||||
|
<form action='".make_link("rating/vote_up")."' method='POST'>
|
||||||
|
<input type='hidden' name='image_id' value='$i_image_id' />
|
||||||
|
<input type='submit' value='Vote Up' />
|
||||||
|
</form>
|
||||||
|
<form action='".make_link("rating/vote_down")."' method='POST'>
|
||||||
|
<input type='hidden' name='image_id' value='$i_image_id' />
|
||||||
|
<input type='submit' value='Vote Down' />
|
||||||
|
</form>
|
||||||
|
";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return "You need to create an account before you can rate";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// add / remove / edit comments {{{
|
||||||
|
private function add_rating($image_id, $rating) {
|
||||||
|
global $user;
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
global $page;
|
||||||
|
|
||||||
|
$page->set_title("Error");
|
||||||
|
$page->set_heading("Error");
|
||||||
|
if(!$config->get_bool('rating_anon') && $user->is_anonymous()) {
|
||||||
|
$page->add_main_block(new Block("Permission Denied", "Anonymous rating has been disabled"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$i_rating = int_escape($rating);
|
||||||
|
$database->db->Execute(
|
||||||
|
"INSERT INTO image_ratings(image_id, user_id, rating, rated) ".
|
||||||
|
"VALUES(?, ?, ?, now())",
|
||||||
|
array($image_id, $user->id, $i_rating));
|
||||||
|
$page->set_mode("redirect");
|
||||||
|
$page->set_redirect(make_link("post/view/".int_escape($image_id)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function delete_ratings($image_id) {
|
||||||
|
global $database;
|
||||||
|
$database->db->Execute("DELETE FROM image_voters WHERE image_id=?", array($image_id));
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
add_event_listener(new Ratings());
|
||||||
|
?>
|
170
ext/regen_thumb.ext.php
Normal file
170
ext/regen_thumb.ext.php
Normal file
|
@ -0,0 +1,170 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class RegenThumb extends Extension {
|
||||||
|
// event handler {{{
|
||||||
|
public function receive_event($event) {
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "regen_thumb")) {
|
||||||
|
global $user;
|
||||||
|
if($user->is_admin() && isset($_POST['program']) && isset($_POST['image_id'])) {
|
||||||
|
$this->make_thumb($_POST['program'], $_POST['image_id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'DisplayingImageEvent')) {
|
||||||
|
global $page;
|
||||||
|
global $user;
|
||||||
|
if($user->is_admin()) {
|
||||||
|
$page->add_side_block(new Block("Regen Thumb", $this->build_regen_buttons($event->image)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// do things {{{
|
||||||
|
// FIXME: make locations of convert / epeg config variables
|
||||||
|
private function make_thumb($program, $image_id) {
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$i_image_id = int_escape($image_id);
|
||||||
|
$image = $database->get_image($i_image_id);
|
||||||
|
|
||||||
|
$f_image = $this->check_filename($image->get_image_filename());
|
||||||
|
$f_thumb = $this->check_filename($image->get_thumb_filename());
|
||||||
|
|
||||||
|
$w = $config->get_int('thumb_width');
|
||||||
|
$h = $config->get_int('thumb_height');
|
||||||
|
$q = $config->get_int('thumb_quality');
|
||||||
|
|
||||||
|
switch($program) {
|
||||||
|
case 'convert':
|
||||||
|
unlink($f_thumb);
|
||||||
|
exec("convert $f_image -geometry {$w}x{$h} -quality {$q} $f_thumb");
|
||||||
|
break;
|
||||||
|
case 'gd':
|
||||||
|
$this->make_thumb_gd($f_image, $f_thumb);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
global $page;
|
||||||
|
$page->set_title("Thumbnail Regenerated");
|
||||||
|
$page->set_heading("Thumbnail Regenerated");
|
||||||
|
$page->add_side_block(new NavBlock());
|
||||||
|
$page->add_main_block(new Block("Thumbnail", $this->build_thumb_html($image)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_thumb_html($image) {
|
||||||
|
$link = make_link("post/view/".$image->id);
|
||||||
|
$img = $image->get_thumb_link();
|
||||||
|
$html = "<a href='$link'><img src='$img'></a>";
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function check_filename($filename) {
|
||||||
|
$filename = preg_replace("#[^a-zA-Z0-9/\._]#", "", $filename);
|
||||||
|
return $filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// GD thumber {{{
|
||||||
|
private function read_file($fname) {
|
||||||
|
$fp = fopen($fname, "r");
|
||||||
|
if(!$fp) return false;
|
||||||
|
|
||||||
|
$data = fread($fp, filesize($fname));
|
||||||
|
fclose($fp);
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
private function make_thumb_gd($inname, $outname) {
|
||||||
|
global $config;
|
||||||
|
$thumb = $this->get_thumb($inname);
|
||||||
|
return imagejpeg($thumb, $outname, $config->get_int('thumb_quality'));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_memory_limit() {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
// thumbnail generation requires lots of memory
|
||||||
|
$default_limit = 8*1024*1024;
|
||||||
|
$shimmie_limit = parse_shorthand_int($config->get_int("thumb_gd_mem_limit"));
|
||||||
|
if($shimmie_limit < 3*1024*1024) {
|
||||||
|
// we aren't going to fit, override
|
||||||
|
$shimmie_limit = $default_limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
ini_set("memory_limit", $shimmie_limit);
|
||||||
|
$memory = parse_shorthand_int(ini_get("memory_limit"));
|
||||||
|
|
||||||
|
// changing of memory limit is disabled / failed
|
||||||
|
if($memory == -1) {
|
||||||
|
$memory = $default_limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $memory;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_thumb($tmpname) {
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$info = getimagesize($tmpname);
|
||||||
|
$width = $info[0];
|
||||||
|
$height = $info[1];
|
||||||
|
|
||||||
|
$max_width = $config->get_int('thumb_width');
|
||||||
|
$max_height = $config->get_int('thumb_height');
|
||||||
|
|
||||||
|
$memory_use = (filesize($tmpname)*2) + ($width*$height*4) + (4*1024*1024);
|
||||||
|
$memory_limit = $this->get_memory_limit();
|
||||||
|
|
||||||
|
if($memory_use > $memory_limit) {
|
||||||
|
$thumb = imagecreatetruecolor($max_width, min($max_height, 64));
|
||||||
|
$white = imagecolorallocate($thumb, 255, 255, 255);
|
||||||
|
$black = imagecolorallocate($thumb, 0, 0, 0);
|
||||||
|
imagefill($thumb, 0, 0, $white);
|
||||||
|
imagestring($thumb, 5, 10, 24, "Image Too Large :(", $black);
|
||||||
|
return $thumb;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$image = imagecreatefromstring($this->read_file($tmpname));
|
||||||
|
|
||||||
|
$xscale = ($max_height / $height);
|
||||||
|
$yscale = ($max_width / $width);
|
||||||
|
$scale = ($xscale < $yscale) ? $xscale : $yscale;
|
||||||
|
|
||||||
|
if($scale >= 1) {
|
||||||
|
$thumb = $image;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$thumb = imagecreatetruecolor($width*$scale, $height*$scale);
|
||||||
|
imagecopyresampled(
|
||||||
|
$thumb, $image, 0, 0, 0, 0,
|
||||||
|
$width*$scale, $height*$scale, $width, $height
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return $thumb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// page building {{{
|
||||||
|
private function build_regen_buttons($image) {
|
||||||
|
global $user;
|
||||||
|
if($user->is_admin()) {
|
||||||
|
return "
|
||||||
|
<form action='".make_link("regen_thumb")."' method='POST'>
|
||||||
|
<input type='hidden' name='image_id' value='{$image->id}'>
|
||||||
|
<select name='program'>
|
||||||
|
<option value='convert'>ImageMagick</option>
|
||||||
|
<option value='gd'>GD</option>
|
||||||
|
<!-- <option value='epeg'>EPEG (for JPEG only)</option> -->
|
||||||
|
</select>
|
||||||
|
<input type='submit' value='Regenerate'>
|
||||||
|
</form>
|
||||||
|
";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
add_event_listener(new RegenThumb());
|
||||||
|
?>
|
235
ext/tag_list.ext.php
Normal file
235
ext/tag_list.ext.php
Normal file
|
@ -0,0 +1,235 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class TagList extends Extension {
|
||||||
|
// event handling {{{
|
||||||
|
public function receive_event($event) {
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "tags")) {
|
||||||
|
global $page;
|
||||||
|
$page->set_title("Tag List");
|
||||||
|
$page->add_side_block(new Block("Navigation", $this->build_navigation()), 0);
|
||||||
|
|
||||||
|
switch($event->get_arg(0)) {
|
||||||
|
default:
|
||||||
|
case 'map':
|
||||||
|
$page->set_heading("Tag Map");
|
||||||
|
$page->add_main_block(new Block("Tags", $this->build_tag_map()));
|
||||||
|
break;
|
||||||
|
case 'alphabetic':
|
||||||
|
$page->set_heading("Alphabetic Tag List");
|
||||||
|
$page->add_main_block(new Block("Tags", $this->build_tag_alphabetic()));
|
||||||
|
break;
|
||||||
|
case 'popularity':
|
||||||
|
$page->set_heading("Tag List by Popularity");
|
||||||
|
$page->add_main_block(new Block("Tags", $this->build_tag_popularity()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(is_a($event, 'PageRequestEvent') && ($event->page == "index")) {
|
||||||
|
global $config;
|
||||||
|
global $page;
|
||||||
|
if($config->get_int('popular_count') > 0) {
|
||||||
|
$page->add_side_block(new Block("Popular Tags", $this->get_popular_tags()), 60);
|
||||||
|
// $page->add_quicknav("Tags", make_link("tags"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'DisplayingImageEvent')) {
|
||||||
|
global $page;
|
||||||
|
$page->add_side_block(new Block("Related Tags", $this->get_related_tags($event->get_image())), 60);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'SetupBuildingEvent')) {
|
||||||
|
$sb = new SetupBlock("Tag Map Options");
|
||||||
|
$sb->add_label("Ignore tags used fewer than ");
|
||||||
|
$sb->add_int_option("tags_min", 0, 99);
|
||||||
|
$sb->add_label(" times");
|
||||||
|
$event->panel->add_main_block($sb);
|
||||||
|
|
||||||
|
$sb = new SetupBlock("Popular Tag List");
|
||||||
|
$sb->add_label("Show top ");
|
||||||
|
$sb->add_int_option("popular_count", 0, 60);
|
||||||
|
$sb->add_label(" tags");
|
||||||
|
$sb->add_label("<br>Tag info link: ");
|
||||||
|
$sb->add_text_option("info_link", true);
|
||||||
|
$event->panel->add_main_block($sb);
|
||||||
|
}
|
||||||
|
if(is_a($event, 'ConfigSaveEvent')) {
|
||||||
|
$event->config->set_int("tags_min", $_POST['tags_min']);
|
||||||
|
|
||||||
|
$event->config->set_int("popular_count", $_POST['popular_count']);
|
||||||
|
$event->config->set_string("info_link", $_POST['info_link']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// misc {{{
|
||||||
|
private function tag_link($tag) {
|
||||||
|
$h_tag = html_escape($tag);
|
||||||
|
return make_link("index", "search=$h_tag");
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// maps {{{
|
||||||
|
private function build_navigation() {
|
||||||
|
$h_index = "<a href='".make_link("index")."'>Index</a>";
|
||||||
|
$h_map = "<a href='".make_link("tags/map")."'>Map</a>";
|
||||||
|
$h_alphabetic = "<a href='".make_link("tags/alphabetic")."'>Alphabetic</a>";
|
||||||
|
$h_popularity = "<a href='".make_link("tags/popularity")."'>Popularity</a>";
|
||||||
|
return "$h_index<br>$h_map<br>$h_alphabetic<br>$h_popularity";
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_tag_map() {
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$tags_min = $config->get_int('tags_min');
|
||||||
|
$result = $database->db->Execute(
|
||||||
|
"SELECT tag,COUNT(image_id) AS count FROM tags GROUP BY tag HAVING count > ? ORDER BY tag",
|
||||||
|
array($tags_min));
|
||||||
|
|
||||||
|
$html = "";
|
||||||
|
while(!$result->EOF) {
|
||||||
|
$row = $result->fields;
|
||||||
|
$h_tag = html_escape($row['tag']);
|
||||||
|
$count = $row['count'];
|
||||||
|
if($count > 1) {
|
||||||
|
$size = floor(log(log($row['count'] - $tags_min + 1)+1)*1.5*100)/100;
|
||||||
|
$link = $this->tag_link($row['tag']);
|
||||||
|
$html .= " <a style='font-size: ${size}em' href='$link'>$h_tag</a> \n";
|
||||||
|
}
|
||||||
|
$result->MoveNext();
|
||||||
|
}
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_tag_alphabetic() {
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$tags_min = $config->get_int('tags_min');
|
||||||
|
$result = $database->db->Execute(
|
||||||
|
"SELECT tag,COUNT(image_id) AS count FROM tags GROUP BY tag HAVING count > ? ORDER BY tag",
|
||||||
|
array($tags_min));
|
||||||
|
|
||||||
|
$html = "";
|
||||||
|
$lastLetter = 0;
|
||||||
|
while(!$result->EOF) {
|
||||||
|
$row = $result->fields;
|
||||||
|
$h_tag = html_escape($row['tag']);
|
||||||
|
$count = $row['count'];
|
||||||
|
if($lastLetter != strtolower(substr($h_tag, 0, 1))) {
|
||||||
|
$lastLetter = strtolower(substr($h_tag, 0, 1));
|
||||||
|
$html .= "<p>$lastLetter<br>";
|
||||||
|
}
|
||||||
|
$link = $this->tag_link($row['tag']);
|
||||||
|
$html .= "<a href='$link'>$h_tag ($count)</a>\n";
|
||||||
|
$result->MoveNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_tag_popularity() {
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$tags_min = $config->get_int('tags_min');
|
||||||
|
$result = $database->db->Execute(
|
||||||
|
"SELECT tag,COUNT(image_id) AS count FROM tags GROUP BY tag HAVING count > ? ORDER BY count DESC, tag ASC",
|
||||||
|
array($tags_min)
|
||||||
|
);
|
||||||
|
|
||||||
|
$html = "Results grouped by log<sub>e</sub>(n)";
|
||||||
|
$lastLog = 0;
|
||||||
|
while(!$result->EOF) {
|
||||||
|
$row = $result->fields;
|
||||||
|
$h_tag = html_escape($row['tag']);
|
||||||
|
$count = $row['count'];
|
||||||
|
if($lastLog != floor(log($count))) {
|
||||||
|
$lastLog = floor(log($count));
|
||||||
|
$html .= "<p>$lastLog<br>";
|
||||||
|
}
|
||||||
|
$link = $this->tag_link($row['tag']);
|
||||||
|
$html .= "<a href='$link'>$h_tag ($count)</a>\n";
|
||||||
|
$result->MoveNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// get related {{{
|
||||||
|
private function get_related_tags($image) {
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$query = "
|
||||||
|
SELECT COUNT(t3.image_id) as count, t3.tag
|
||||||
|
FROM
|
||||||
|
tags AS t1,
|
||||||
|
tags AS t2,
|
||||||
|
tags AS t3
|
||||||
|
WHERE
|
||||||
|
t1.image_id=?
|
||||||
|
AND t1.tag=t2.tag
|
||||||
|
AND t2.image_id=t3.image_id
|
||||||
|
AND t1.tag != 'tagme'
|
||||||
|
AND t3.tag != 'tagme'
|
||||||
|
GROUP by t3.tag
|
||||||
|
ORDER by count DESC
|
||||||
|
LIMIT ?
|
||||||
|
";
|
||||||
|
|
||||||
|
$n = 0;
|
||||||
|
$html = "";
|
||||||
|
$result = $database->db->Execute($query, array($image->id, $config->get_int('popular_count')));
|
||||||
|
while(!$result->EOF) {
|
||||||
|
$row = $result->fields;
|
||||||
|
$h_tag = html_escape($row['tag']);
|
||||||
|
$count = $row['count'];
|
||||||
|
if($n++) $html .= "<br/>";
|
||||||
|
$link = $this->tag_link($row['tag']);
|
||||||
|
$html .= "<a href='$link'>$h_tag</a>\n";
|
||||||
|
$result->MoveNext();
|
||||||
|
}
|
||||||
|
$result->Close();
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// get popular {{{
|
||||||
|
private function get_popular_tags() {
|
||||||
|
global $database;
|
||||||
|
global $config;
|
||||||
|
|
||||||
|
$query = "
|
||||||
|
SELECT tag, COUNT(image_id) AS count
|
||||||
|
FROM tags
|
||||||
|
GROUP BY tag
|
||||||
|
ORDER BY count DESC
|
||||||
|
LIMIT ?
|
||||||
|
";
|
||||||
|
|
||||||
|
$n = 0;
|
||||||
|
$result = $database->db->Execute($query, array($config->get_int('popular_count')));
|
||||||
|
$html = "";
|
||||||
|
while(!$result->EOF) {
|
||||||
|
$row = $result->fields;
|
||||||
|
$tag = html_escape($row['tag']);
|
||||||
|
$count = $row['count'];
|
||||||
|
if($n++) $html .= "<br/>";
|
||||||
|
$link = $this->tag_link($row['tag']);
|
||||||
|
$html .= "<a href='$link'>$tag ($count)</a>\n";
|
||||||
|
if(!is_null($config->get_string('info_link'))) {
|
||||||
|
$link = str_replace('$tag', $tag, $config->get_string('info_link'));
|
||||||
|
$html .= "<a href='$link'>?</a>\n";
|
||||||
|
}
|
||||||
|
$result->MoveNext();
|
||||||
|
}
|
||||||
|
$result->Close();
|
||||||
|
|
||||||
|
$html .= "<p><a href='".make_link("tags")."'>Full List >>></a>\n";
|
||||||
|
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
}
|
||||||
|
add_event_listener(new TagList());
|
||||||
|
?>
|
57
ext/zoom.ext.php
Normal file
57
ext/zoom.ext.php
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Zoom extends Extension {
|
||||||
|
public function receive_event($event) {
|
||||||
|
if(is_a($event, 'DisplayingImageEvent')) {
|
||||||
|
global $page;
|
||||||
|
$page->add_main_block(new Block(null, $this->make_zoomer()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(is_a($event, 'SetupBuildingEvent')) {
|
||||||
|
$sb = new SetupBlock("Image Zoom");
|
||||||
|
$sb->add_label("Zoom by default: ");
|
||||||
|
$sb->add_bool_option("image_zoom");
|
||||||
|
$event->panel->add_main_block($sb);
|
||||||
|
}
|
||||||
|
if(is_a($event, 'ConfigSaveEvent')) {
|
||||||
|
$event->config->set_bool("image_zoom", $_POST['image_zoom']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function make_zoomer() {
|
||||||
|
global $config;
|
||||||
|
$default = $config->get_bool("image_zoom") ? "scale(img);" : "";
|
||||||
|
return <<<EOD
|
||||||
|
<script type="text/javascript">
|
||||||
|
img = byId("main_image");
|
||||||
|
|
||||||
|
img.onclick = function() {scale(img);};
|
||||||
|
|
||||||
|
msg_div = document.createElement("div");
|
||||||
|
msg_div.id = "msg_div";
|
||||||
|
msg_div.appendChild(document.createTextNode("Note: Image has been scaled to fit the screen; click to enlarge"));
|
||||||
|
msg_div.style.display="none";
|
||||||
|
|
||||||
|
img.parentNode.insertBefore(msg_div, img);
|
||||||
|
|
||||||
|
orig_width = "";
|
||||||
|
|
||||||
|
function scale(img) {
|
||||||
|
if(img.style.width != "90%") {
|
||||||
|
origwidth = img.style.width;
|
||||||
|
img.style.width = "90%";
|
||||||
|
msg_div.style.display = "block";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
img.style.width = origwidth;
|
||||||
|
msg_div.style.display = "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$default
|
||||||
|
</script>
|
||||||
|
EOD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_event_listener(new Zoom());
|
||||||
|
?>
|
BIN
favicon.ico
Normal file
BIN
favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
37
index.php
Normal file
37
index.php
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
assert_options(ASSERT_ACTIVE, 1);
|
||||||
|
assert_options(ASSERT_BAIL, 1);
|
||||||
|
|
||||||
|
if(version_compare(PHP_VERSION, "5.0.0") == -1) {
|
||||||
|
print <<<EOD
|
||||||
|
Currently Shimmie 2 doesn't support versions of PHP lower than 5.0.0. Please
|
||||||
|
either upgrade your PHP, or tell Shish that PHP 4 support is a big deal for
|
||||||
|
you...
|
||||||
|
<!--
|
||||||
|
This version of Shimmie does not support versions lower than 5.0.0, however
|
||||||
|
you can create a version that does by using the u_create_monolith.php script.
|
||||||
|
This will read all the files in core/, events/ and ext/, strip the PHP 5 bits
|
||||||
|
out, and write a file called monolith.php. Monolith contains all the core
|
||||||
|
Shimmie code (not themes or config files), and can be used as a replacement
|
||||||
|
for index.php.
|
||||||
|
-->
|
||||||
|
EOD;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$files = array_merge(glob("core/*.php"), glob("core/*/*.php"), glob("ext/*.php"));
|
||||||
|
|
||||||
|
foreach($files as $filename) {
|
||||||
|
require_once $filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
$database = new Database();
|
||||||
|
$database->db->fnExecute = 'CountExecs';
|
||||||
|
$config = new Config();
|
||||||
|
$page = new Page();
|
||||||
|
$user = get_user();
|
||||||
|
send_event(new InitExtEvent());
|
||||||
|
send_event(get_page_request());
|
||||||
|
$page->display();
|
||||||
|
?>
|
497
install.php
Normal file
497
install.php
Normal file
|
@ -0,0 +1,497 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* install.php (c) Shish 2007
|
||||||
|
*
|
||||||
|
* Initialise the database, check that folder
|
||||||
|
* permissions are set properly, set an admin
|
||||||
|
* account.
|
||||||
|
*
|
||||||
|
* This file should be independant of the database
|
||||||
|
* and other such things that aren't ready yet
|
||||||
|
*/
|
||||||
|
|
||||||
|
// FIXME: should be called from index
|
||||||
|
do_install();
|
||||||
|
assert_options(ASSERT_ACTIVE, 1);
|
||||||
|
assert_options(ASSERT_BAIL, 1);
|
||||||
|
|
||||||
|
// utilities {{{
|
||||||
|
function installer_write_file($fname, $data) {
|
||||||
|
$fp = fopen($fname, "w");
|
||||||
|
if(!$fp) return false;
|
||||||
|
|
||||||
|
fwrite($fp, $data);
|
||||||
|
fclose($fp);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_gd_version() {
|
||||||
|
$gdversion = 0;
|
||||||
|
|
||||||
|
if (function_exists('gd_info')){
|
||||||
|
$gd_info = gd_info();
|
||||||
|
if (substr_count($gd_info['GD Version'], '2.')) {
|
||||||
|
$gdversion = 2;
|
||||||
|
} else if (substr_count($gd_info['GD Version'], '1.')) {
|
||||||
|
$gdversion = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $gdversion;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// init {{{
|
||||||
|
function do_install() {
|
||||||
|
/*
|
||||||
|
* This file lets anyone destroy the database -- disable it
|
||||||
|
* as soon as the admin is done installing for the first time
|
||||||
|
*/
|
||||||
|
if(is_readable("config.php")) {
|
||||||
|
echo "'config.php' exists -- install function is disabled";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
require_once "lib/adodb/adodb.inc.php";
|
||||||
|
|
||||||
|
session_start(); // hold temp stuff in session
|
||||||
|
|
||||||
|
$stage = isset($_GET['stage']) ? $_GET['stage'] : "begin";
|
||||||
|
|
||||||
|
switch($stage) {
|
||||||
|
default: begin(); break;
|
||||||
|
case 'install': install_process(); break;
|
||||||
|
case 'upgrade': upgrade_process(); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function begin() {
|
||||||
|
if(check_gd_version() == 0) {
|
||||||
|
$gd = "<h3>Error</h3>\nPHP's GD extension seems to be missing; ".
|
||||||
|
"you can live without it if you have imagemagick installed...";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$gd = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
print <<<EOD
|
||||||
|
<html>
|
||||||
|
<head><title>Shimmie2 Installer</title></head>
|
||||||
|
<link rel="stylesheet" href="themes/default/style.css">
|
||||||
|
<body>
|
||||||
|
<h1>Shimmie Installer</h1>
|
||||||
|
|
||||||
|
$gd
|
||||||
|
|
||||||
|
<h3>Note</h3>
|
||||||
|
Shimmie is developed with MySQL, and support
|
||||||
|
for it is included. Other databases <i>may</i> work,
|
||||||
|
but you'll need to add the appropriate ADOdb
|
||||||
|
drivers yourself
|
||||||
|
|
||||||
|
<h3>Install</h3>
|
||||||
|
<form action="install.php?stage=install" method="POST">
|
||||||
|
<center>
|
||||||
|
<table>
|
||||||
|
<tr><td>Database</td><td><input type="text" name="database_dsn" size="50"></td></tr>
|
||||||
|
<tr><td>Admin Name:</td><td><input type="text" name="admin_name" size="50"></td></tr>
|
||||||
|
<tr><td>Admin Pass:</td><td><input type="password" name="admin_pass" size="50"></td></tr>
|
||||||
|
<tr><td colspan="2"><input type="submit" value="Next"></td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<p>Databases should be specified like so:
|
||||||
|
<br>ie: protocol://username:password@host/database?options
|
||||||
|
<br>eg: mysql://shimmie:pw123@localhost/shimmie?persist
|
||||||
|
</center>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<h3>Upgrade</h3>
|
||||||
|
<form action="install.php?stage=upgrade" method="POST">
|
||||||
|
<center>
|
||||||
|
<table>
|
||||||
|
<tr><td>Old Database:</td><td><input type="text" size="50" name="old_dsn"></td></tr>
|
||||||
|
<tr><td>New Database:</td><td><input type="text" size="50" name="new_dsn"></td></tr>
|
||||||
|
<tr><td>Old Data Folder:</td><td><input type="text" size="50" name="old_data"></td></tr>
|
||||||
|
<tr><td colspan="2"><input type="submit" value="Next"></td></tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<p>Data folder is where the "images" and "thumbs" folders are stored
|
||||||
|
</center>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
EOD;
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
// common {{{
|
||||||
|
function set_admin_cookie($admin_name, $admin_pass) { // {{{
|
||||||
|
$addr = $_SERVER['REMOTE_ADDR'];
|
||||||
|
$hash = md5(strtolower($admin_name) . $admin_pass);
|
||||||
|
setcookie("shm_user", $admin_name, time()+60*60*24*365);
|
||||||
|
setcookie("shm_session", md5($hash.$addr), time()+60*60*24*7, "/");
|
||||||
|
} // }}}
|
||||||
|
function create_tables($dsn) { // {{{
|
||||||
|
$db = NewADOConnection($dsn);
|
||||||
|
if(!$db) {
|
||||||
|
die("Couldn't connect to \"$dsn\"");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(create_tables_mysql($db)) {
|
||||||
|
$_SESSION['tables_created'] = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
die("Error creating tables");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$db->Close();
|
||||||
|
} // }}}
|
||||||
|
function build_dirs() { // {{{
|
||||||
|
if(!file_exists("images")) @mkdir("images"); // *try* and make default dirs. Ignore any errors --
|
||||||
|
if(!file_exists("thumbs")) @mkdir("thumbs"); // if something is amiss, we'll tell the user later
|
||||||
|
|
||||||
|
if(
|
||||||
|
((!file_exists("images") || !file_exists("thumbs")) && !is_writable("./")) ||
|
||||||
|
(!is_writable("images") || !is_writable("thumbs"))
|
||||||
|
) {
|
||||||
|
print "Shimmie needs two folders in it's directory, 'images' and 'thumbs',
|
||||||
|
and they need to be writable by the PHP user (if you see this error,
|
||||||
|
if probably means the folders are owned by you, and they need to be
|
||||||
|
writable by the web server).
|
||||||
|
|
||||||
|
<p>Once you have created these folders, hit 'refresh' to continue.";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assert(file_exists("images") && is_writable("images"));
|
||||||
|
assert(file_exists("thumbs") && is_writable("thumbs"));
|
||||||
|
|
||||||
|
if(!file_exists("images/ff")) {
|
||||||
|
for($i=0; $i<256; $i++) {
|
||||||
|
mkdir(sprintf("images/%02x", $i));
|
||||||
|
mkdir(sprintf("thumbs/%02x", $i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // }}}
|
||||||
|
function write_config($dsn) { // {{{
|
||||||
|
$file_content .= "<?php \$database_dsn='$dsn'; ?>";
|
||||||
|
|
||||||
|
if(is_writable("./") && installer_write_file("config.php", $file_content)) {
|
||||||
|
assert(file_exists("config.php"));
|
||||||
|
session_destroy();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$h_file_content = htmlentities($file_content);
|
||||||
|
print <<<EOD
|
||||||
|
<html>
|
||||||
|
<head><title>Shimmie2 Installer</title></head>
|
||||||
|
<body>
|
||||||
|
The web server isn't allowed to write to the config file; please copy
|
||||||
|
the text below, save it as 'config.php', and upload it into the shimmie
|
||||||
|
folder manually. Make sure that when you save it, there is no whitespace
|
||||||
|
before the "<?php" or after the "?>"
|
||||||
|
|
||||||
|
<p><textarea cols="80" rows="2">$file_content</textarea>
|
||||||
|
|
||||||
|
<p>One done, <a href='index.php?q=setup'>Continue</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
EOD;
|
||||||
|
session_destroy();
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
} // }}}
|
||||||
|
// }}}
|
||||||
|
// install {{{
|
||||||
|
function install_process() { // {{{
|
||||||
|
if(!isset($_POST['database_dsn']) || !isset($_POST["admin_name"]) || !isset($_POST["admin_pass"])) {
|
||||||
|
die("Install is missing some paramaters (database_dsn, admin_name, or admin_pass)");
|
||||||
|
}
|
||||||
|
else if(strlen($_POST["admin_name"]) < 1 || strlen($_POST["admin_pass"]) < 1) {
|
||||||
|
die("Admin name and password must be at least one character each");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$database_dsn = $_POST['database_dsn'];
|
||||||
|
$admin_name = $_POST["admin_name"];
|
||||||
|
$admin_pass = $_POST["admin_pass"];
|
||||||
|
}
|
||||||
|
|
||||||
|
set_admin_cookie($admin_name, $admin_pass);
|
||||||
|
create_tables($database_dsn);
|
||||||
|
insert_defaults($database_dsn, $admin_name, $admin_pass);
|
||||||
|
build_dirs();
|
||||||
|
write_config($database_dsn);
|
||||||
|
|
||||||
|
header("Location: index.php?q=setup");
|
||||||
|
} // }}}
|
||||||
|
function insert_defaults($dsn, $admin_name, $admin_pass) { // {{{
|
||||||
|
$db = NewADOConnection($dsn);
|
||||||
|
if(!$db) {
|
||||||
|
die("Couldn't connect to \"$dsn\"");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$config_insert = $db->Prepare("INSERT INTO config(name, value) VALUES(?, ?)");
|
||||||
|
$user_insert = $db->Prepare("INSERT INTO users(name, pass, joindate, admin) VALUES(?, ?, now(), ?)");
|
||||||
|
|
||||||
|
if(!$db->GetOne("SELECT * FROM users WHERE name=?", Array('Anonymous'))) {
|
||||||
|
$db->Execute($user_insert, Array('Anonymous', null, 'N'));
|
||||||
|
|
||||||
|
$db->Execute("DELETE FROM config WHERE name=?", Array('anon_id'));
|
||||||
|
$db->Execute($config_insert, Array('anon_id', $db->Insert_ID()));
|
||||||
|
}
|
||||||
|
|
||||||
|
# we can safely delete the user and recreate, hence changing the ID,
|
||||||
|
# because insert_defaults is only called during first installation
|
||||||
|
if($db->GetOne("SELECT * FROM users WHERE name=?", Array($admin_name))) {
|
||||||
|
$db->Execute("DELETE FROM users WHERE name=?", Array($admin_name));
|
||||||
|
}
|
||||||
|
|
||||||
|
$admin_pass = md5(strtolower($admin_name).$admin_pass);
|
||||||
|
$db->Execute($user_insert, Array($admin_name, $admin_pass, 'Y'));
|
||||||
|
|
||||||
|
$db->Close();
|
||||||
|
}
|
||||||
|
} // }}}
|
||||||
|
// }}}
|
||||||
|
// upgrade {{{
|
||||||
|
function upgrade_process() { // {{{
|
||||||
|
if(!isset($_POST['old_dsn']) || !isset($_POST["new_dsn"]) || !isset($_POST["old_data"])) {
|
||||||
|
die("Install is missing some paramaters (old_dsn, new_dsn, or old_data)");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$old_dsn = $_POST['old_dsn'];
|
||||||
|
$new_dsn = $_POST['new_dsn'];
|
||||||
|
$old_data = $_POST['old_data'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!is_readable($old_data)) {die("Can't find \"$old_data\"");}
|
||||||
|
if(!is_readable("$old_data/images")) {die("Can't find \"$old_data/images\"");}
|
||||||
|
if(!is_readable("$old_data/thumbs")) {die("Can't find \"$old_data/thumbs\"");}
|
||||||
|
|
||||||
|
// set_admin_cookie($admin_name, $admin_pass);
|
||||||
|
create_tables($new_dsn);
|
||||||
|
build_dirs();
|
||||||
|
move_data($old_dsn, $new_dsn, $old_data);
|
||||||
|
write_config($new_dsn);
|
||||||
|
|
||||||
|
// header("Location: index.php?q=setup");
|
||||||
|
print "<p>If everything looks OK, <a href='index.php?q=user/login'>continue</a>";
|
||||||
|
} // }}}
|
||||||
|
function move_data($old_dsn, $new_dsn, $old_data) {
|
||||||
|
print("<br>Fetching old data...");
|
||||||
|
$old_db = NewADOConnection($old_dsn);
|
||||||
|
$old_db->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||||
|
# tmpfile & serialize?
|
||||||
|
$anon_id = -1;
|
||||||
|
$users = $old_db->GetAll("SELECT id, name, pass, joindate FROM users");
|
||||||
|
$admins = $old_db->GetCol("SELECT owner_id FROM user_configs WHERE name='isadmin' AND value='true'");
|
||||||
|
$images = $old_db->GetAll("SELECT id, owner_id, owner_ip, filename, hash, ext FROM images");
|
||||||
|
$comments = $old_db->GetAll("SELECT id, image_id, owner_id, owner_ip, posted, comment FROM comments");
|
||||||
|
$tags = $old_db->GetAll("SELECT image_id, tag FROM tags");
|
||||||
|
$old_db->Close();
|
||||||
|
|
||||||
|
$new_db = NewADOConnection($new_dsn);
|
||||||
|
$new_db->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||||
|
|
||||||
|
if($users) {
|
||||||
|
print("<br>Moving users...");
|
||||||
|
$new_db->Execute("DELETE FROM users");
|
||||||
|
$new_db->Execute("
|
||||||
|
INSERT INTO users(id, name, pass, joindate, enabled, admin, email)
|
||||||
|
VALUES(?, ?, ?, ?, 'Y', 'N', '')", $users);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($admins) {
|
||||||
|
print("<br>Setting account flags");
|
||||||
|
$new_db->Execute("UPDATE users SET admin='Y' WHERE id=?", array($admins));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(true) {
|
||||||
|
print("<br>Updating anonymous account...");
|
||||||
|
$anon_id = $new_db->GetOne("SELECT id FROM users WHERE name='Anonymous'");
|
||||||
|
if(!$anon_id) {
|
||||||
|
print("<br><b>Warning</b>: 'Anonymous' not found; creating one");
|
||||||
|
$new_db->Execute("INSERT INTO users(name, pass, joindate) VALUES ('Anonymous', NULL, now())");
|
||||||
|
$anon_id = $new_db->Insert_ID();
|
||||||
|
}
|
||||||
|
|
||||||
|
$new_db->Execute("DELETE FROM config WHERE name=?", array("anon_id"));
|
||||||
|
$new_db->Execute("INSERT INTO config(name, value) VALUES(?, ?)", array('anon_id', $anon_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if($images) {
|
||||||
|
print("<br>Moving images...");
|
||||||
|
$new_db->Execute("DELETE FROM images");
|
||||||
|
$new_db->Execute("
|
||||||
|
INSERT INTO images(id, owner_id, owner_ip, filename, hash, ext, filesize, width, height, source, posted)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, 0, 0, 0, NULL, now())", $images);
|
||||||
|
}
|
||||||
|
|
||||||
|
if($comments) {
|
||||||
|
print("<br>Moving comments...");
|
||||||
|
|
||||||
|
// HAAAAAAAX!
|
||||||
|
// the comments table is installed by an extension, so it won't be
|
||||||
|
// ready when we need it...
|
||||||
|
$new_db->Execute("DROP TABLE comments");
|
||||||
|
$new_db->Execute("DELETE FROM config WHERE name=?", array('ext_comments_version'));
|
||||||
|
|
||||||
|
$new_db->Execute("CREATE TABLE `comments` (
|
||||||
|
`id` int(11) NOT NULL auto_increment,
|
||||||
|
`image_id` int(11) NOT NULL,
|
||||||
|
`owner_id` int(11) NOT NULL,
|
||||||
|
`owner_ip` char(16) NOT NULL,
|
||||||
|
`posted` datetime default NULL,
|
||||||
|
`comment` text NOT NULL,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `comments_image_id` (`image_id`)
|
||||||
|
)");
|
||||||
|
$new_db->Execute("INSERT INTO config(name, value) VALUES(?, ?)", array("ext_comments_version", 1));
|
||||||
|
|
||||||
|
$new_db->Execute("DELETE FROM comments");
|
||||||
|
$new_db->Execute("
|
||||||
|
INSERT INTO comments(id, image_id, owner_id, owner_ip, posted, comment)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?)", $comments);
|
||||||
|
|
||||||
|
print("<br>Setting orphan comments to anonymous...");
|
||||||
|
$orphans = $new_db->GetCol("
|
||||||
|
SELECT comments.id
|
||||||
|
FROM comments
|
||||||
|
LEFT JOIN users ON users.id = comments.owner_id
|
||||||
|
WHERE isnull(users.name)");
|
||||||
|
if($orphans) {
|
||||||
|
foreach($orphans as $orphan) {
|
||||||
|
$new_db->Execute("UPDATE comments SET owner_id=? WHERE id=?", array($anon_id, $orphan));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print("<br>Setting orphan images to anonymous...");
|
||||||
|
$orphans = $new_db->GetCol("
|
||||||
|
SELECT images.id
|
||||||
|
FROM images
|
||||||
|
LEFT JOIN users ON users.id = images.owner_id
|
||||||
|
WHERE isnull(users.name)");
|
||||||
|
if($orphans) {
|
||||||
|
foreach($orphans as $orphan) {
|
||||||
|
$new_db->Execute("UPDATE images SET owner_id=? WHERE id=?", array($anon_id, $orphan));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($tags) {
|
||||||
|
print("<br>Moving tags..");
|
||||||
|
$new_db->Execute("DELETE FROM tags");
|
||||||
|
$new_db->Execute("INSERT INTO tags(image_id, tag) VALUES (?, ?)", $tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
print("<br>Moving files...");
|
||||||
|
$result = $new_db->Execute("SELECT * FROM images");
|
||||||
|
while(!$result->EOF) {
|
||||||
|
$fields = $result->fields;
|
||||||
|
|
||||||
|
$id = $fields['id'];
|
||||||
|
$hash = $fields['hash'];
|
||||||
|
$ext = $fields['ext'];
|
||||||
|
$ab = substr($hash, 0, 2);
|
||||||
|
|
||||||
|
if(file_exists("images/$ab/$hash")) {
|
||||||
|
unlink("images/$ab/$hash");
|
||||||
|
}
|
||||||
|
|
||||||
|
$fname = "$old_data/images/$id.$ext";
|
||||||
|
if(file_exists($fname)) {
|
||||||
|
$size = filesize($fname);
|
||||||
|
$sizekb = (int)($size/1024);
|
||||||
|
$info = getimagesize($fname);
|
||||||
|
if($info) {
|
||||||
|
$width = $info[0];
|
||||||
|
$height = $info[1];
|
||||||
|
|
||||||
|
// print "<br>{$id}: {$width}x{$height}, {$sizekb}KB\n"; // noise
|
||||||
|
$new_db->Execute("UPDATE images SET width=?, height=?, filesize=? WHERE id=?",
|
||||||
|
array($width, $height, $size, $id));
|
||||||
|
}
|
||||||
|
|
||||||
|
copy("$old_data/thumbs/$id.jpg", "thumbs/$ab/$hash");
|
||||||
|
copy("$old_data/images/$id.$ext", "images/$ab/$hash");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
print "<br><b>Warning:</b> $fname not found; dropped from new database";
|
||||||
|
$new_db->Execute("DELETE FROM images WHERE id=?", array($id));
|
||||||
|
}
|
||||||
|
|
||||||
|
$result->MoveNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
$new_db->Close();
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
|
|
||||||
|
// table creation {{{
|
||||||
|
/*
|
||||||
|
* Note: try and keep this as ANSI SQL compliant as possible,
|
||||||
|
* so that we can (in theory) support other databases
|
||||||
|
*/
|
||||||
|
function create_tables_mysql($db) {
|
||||||
|
$db->StartTrans();
|
||||||
|
|
||||||
|
$db->Execute("DROP TABLE IF EXISTS aliases");
|
||||||
|
$db->Execute("CREATE TABLE aliases (
|
||||||
|
oldtag varchar(255) NOT NULL,
|
||||||
|
newtag varchar(255) NOT NULL,
|
||||||
|
PRIMARY KEY (oldtag)
|
||||||
|
)");
|
||||||
|
|
||||||
|
$db->Execute("DROP TABLE IF EXISTS config");
|
||||||
|
$db->Execute("CREATE TABLE config (
|
||||||
|
name varchar(255) NOT NULL,
|
||||||
|
value text,
|
||||||
|
PRIMARY KEY (name)
|
||||||
|
)");
|
||||||
|
|
||||||
|
$db->Execute("DROP TABLE IF EXISTS images");
|
||||||
|
$db->Execute("CREATE TABLE images (
|
||||||
|
id int(11) NOT NULL auto_increment,
|
||||||
|
owner_id int(11) NOT NULL default '0',
|
||||||
|
owner_ip char(16) default NULL,
|
||||||
|
filename varchar(64) NOT NULL default '',
|
||||||
|
filesize int(11) NOT NULL default '0',
|
||||||
|
hash char(32) NOT NULL default '',
|
||||||
|
ext char(4) NOT NULL default '',
|
||||||
|
source varchar(255),
|
||||||
|
width int(11) NOT NULL,
|
||||||
|
height int(11) NOT NULL,
|
||||||
|
posted datetime NOT NULL,
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
UNIQUE (hash)
|
||||||
|
)");
|
||||||
|
|
||||||
|
$db->Execute("DROP TABLE IF EXISTS tags");
|
||||||
|
$db->Execute("CREATE TABLE tags (
|
||||||
|
image_id int(11) NOT NULL default '0',
|
||||||
|
tag varchar(255) NOT NULL default '',
|
||||||
|
UNIQUE KEY image_id (image_id,tag),
|
||||||
|
KEY tags_tag (tag),
|
||||||
|
KEY tags_image_id (image_id)
|
||||||
|
)");
|
||||||
|
|
||||||
|
$db->Execute("DROP TABLE IF EXISTS users");
|
||||||
|
$db->Execute("CREATE TABLE users (
|
||||||
|
id int(11) NOT NULL auto_increment,
|
||||||
|
name varchar(32) NOT NULL,
|
||||||
|
pass char(32) default NULL,
|
||||||
|
joindate datetime NOT NULL,
|
||||||
|
enabled enum('N','Y') NOT NULL default 'Y',
|
||||||
|
admin enum('N','Y') NOT NULL default 'N',
|
||||||
|
email varchar(255) default NULL,
|
||||||
|
PRIMARY KEY (id),
|
||||||
|
UNIQUE (name)
|
||||||
|
)");
|
||||||
|
|
||||||
|
$db->Execute("INSERT INTO config(name, value) VALUES(?, ?)", Array('db_version', '2.0.0.9'));
|
||||||
|
|
||||||
|
return $db->CommitTrans();
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
?>
|
85
lib/adodb/adodb-iterator.inc.php
Normal file
85
lib/adodb/adodb-iterator.inc.php
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
|
||||||
|
Released under both BSD license and Lesser GPL library license.
|
||||||
|
Whenever there is any discrepancy between the two licenses,
|
||||||
|
the BSD license will take precedence.
|
||||||
|
|
||||||
|
Set tabs to 4.
|
||||||
|
|
||||||
|
Declares the ADODB Base Class for PHP5 "ADODB_BASE_RS", and supports iteration with
|
||||||
|
the ADODB_Iterator class.
|
||||||
|
|
||||||
|
$rs = $db->Execute("select * from adoxyz");
|
||||||
|
foreach($rs as $k => $v) {
|
||||||
|
echo $k; print_r($v); echo "<br>";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Iterator code based on http://cvs.php.net/cvs.php/php-src/ext/spl/examples/cachingiterator.inc?login=2
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
class ADODB_Iterator implements Iterator {
|
||||||
|
|
||||||
|
private $rs;
|
||||||
|
|
||||||
|
function __construct($rs)
|
||||||
|
{
|
||||||
|
$this->rs = $rs;
|
||||||
|
}
|
||||||
|
function rewind()
|
||||||
|
{
|
||||||
|
$this->rs->MoveFirst();
|
||||||
|
}
|
||||||
|
|
||||||
|
function valid()
|
||||||
|
{
|
||||||
|
return !$this->rs->EOF;
|
||||||
|
}
|
||||||
|
|
||||||
|
function key()
|
||||||
|
{
|
||||||
|
return $this->rs->_currentRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
function current()
|
||||||
|
{
|
||||||
|
return $this->rs->fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
function next()
|
||||||
|
{
|
||||||
|
$this->rs->MoveNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
function __call($func, $params)
|
||||||
|
{
|
||||||
|
return call_user_func_array(array($this->rs, $func), $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function hasMore()
|
||||||
|
{
|
||||||
|
return !$this->rs->EOF;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ADODB_BASE_RS implements IteratorAggregate {
|
||||||
|
function getIterator() {
|
||||||
|
return new ADODB_Iterator($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* this is experimental - i don't really know what to return... */
|
||||||
|
function __toString()
|
||||||
|
{
|
||||||
|
include_once(ADODB_DIR.'/toexport.inc.php');
|
||||||
|
return _adodb_export($this,',',',',false,true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
1128
lib/adodb/adodb-lib.inc.php
Normal file
1128
lib/adodb/adodb-lib.inc.php
Normal file
File diff suppressed because it is too large
Load diff
16
lib/adodb/adodb-php4.inc.php
Normal file
16
lib/adodb/adodb-php4.inc.php
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
|
||||||
|
Released under both BSD license and Lesser GPL library license.
|
||||||
|
Whenever there is any discrepancy between the two licenses,
|
||||||
|
the BSD license will take precedence.
|
||||||
|
|
||||||
|
Set tabs to 4.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
class ADODB_BASE_RS {
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
1337
lib/adodb/adodb-time.inc.php
Normal file
1337
lib/adodb/adodb-time.inc.php
Normal file
File diff suppressed because it is too large
Load diff
4221
lib/adodb/adodb.inc.php
Normal file
4221
lib/adodb/adodb.inc.php
Normal file
File diff suppressed because it is too large
Load diff
782
lib/adodb/drivers/adodb-mysql.inc.php
Normal file
782
lib/adodb/drivers/adodb-mysql.inc.php
Normal file
|
@ -0,0 +1,782 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved.
|
||||||
|
Released under both BSD license and Lesser GPL library license.
|
||||||
|
Whenever there is any discrepancy between the two licenses,
|
||||||
|
the BSD license will take precedence.
|
||||||
|
Set tabs to 8.
|
||||||
|
|
||||||
|
MySQL code that does not support transactions. Use mysqlt if you need transactions.
|
||||||
|
Requires mysql client. Works on Windows and Unix.
|
||||||
|
|
||||||
|
28 Feb 2001: MetaColumns bug fix - suggested by Freek Dijkstra (phpeverywhere@macfreek.com)
|
||||||
|
*/
|
||||||
|
|
||||||
|
// security - hide paths
|
||||||
|
if (!defined('ADODB_DIR')) die();
|
||||||
|
|
||||||
|
if (! defined("_ADODB_MYSQL_LAYER")) {
|
||||||
|
define("_ADODB_MYSQL_LAYER", 1 );
|
||||||
|
|
||||||
|
class ADODB_mysql extends ADOConnection {
|
||||||
|
var $databaseType = 'mysql';
|
||||||
|
var $dataProvider = 'mysql';
|
||||||
|
var $hasInsertID = true;
|
||||||
|
var $hasAffectedRows = true;
|
||||||
|
var $metaTablesSQL = "SHOW TABLES";
|
||||||
|
var $metaColumnsSQL = "SHOW COLUMNS FROM `%s`";
|
||||||
|
var $fmtTimeStamp = "'Y-m-d H:i:s'";
|
||||||
|
var $hasLimit = true;
|
||||||
|
var $hasMoveFirst = true;
|
||||||
|
var $hasGenID = true;
|
||||||
|
var $isoDates = true; // accepts dates in ISO format
|
||||||
|
var $sysDate = 'CURDATE()';
|
||||||
|
var $sysTimeStamp = 'NOW()';
|
||||||
|
var $hasTransactions = false;
|
||||||
|
var $forceNewConnect = false;
|
||||||
|
var $poorAffectedRows = true;
|
||||||
|
var $clientFlags = 0;
|
||||||
|
var $substr = "substring";
|
||||||
|
var $nameQuote = '`'; /// string to use to quote identifiers and names
|
||||||
|
var $compat323 = false; // true if compat with mysql 3.23
|
||||||
|
|
||||||
|
function ADODB_mysql()
|
||||||
|
{
|
||||||
|
if (defined('ADODB_EXTENSION')) $this->rsPrefix .= 'ext_';
|
||||||
|
}
|
||||||
|
|
||||||
|
function ServerInfo()
|
||||||
|
{
|
||||||
|
$arr['description'] = ADOConnection::GetOne("select version()");
|
||||||
|
$arr['version'] = ADOConnection::_findvers($arr['description']);
|
||||||
|
return $arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
function IfNull( $field, $ifNull )
|
||||||
|
{
|
||||||
|
return " IFNULL($field, $ifNull) "; // if MySQL
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function &MetaTables($ttype=false,$showSchema=false,$mask=false)
|
||||||
|
{
|
||||||
|
$save = $this->metaTablesSQL;
|
||||||
|
if ($showSchema && is_string($showSchema)) {
|
||||||
|
$this->metaTablesSQL .= " from $showSchema";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($mask) {
|
||||||
|
$mask = $this->qstr($mask);
|
||||||
|
$this->metaTablesSQL .= " like $mask";
|
||||||
|
}
|
||||||
|
$ret =& ADOConnection::MetaTables($ttype,$showSchema);
|
||||||
|
|
||||||
|
$this->metaTablesSQL = $save;
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function &MetaIndexes ($table, $primary = FALSE, $owner=false)
|
||||||
|
{
|
||||||
|
// save old fetch mode
|
||||||
|
global $ADODB_FETCH_MODE;
|
||||||
|
|
||||||
|
$false = false;
|
||||||
|
$save = $ADODB_FETCH_MODE;
|
||||||
|
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||||
|
if ($this->fetchMode !== FALSE) {
|
||||||
|
$savem = $this->SetFetchMode(FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get index details
|
||||||
|
$rs = $this->Execute(sprintf('SHOW INDEX FROM %s',$table));
|
||||||
|
|
||||||
|
// restore fetchmode
|
||||||
|
if (isset($savem)) {
|
||||||
|
$this->SetFetchMode($savem);
|
||||||
|
}
|
||||||
|
$ADODB_FETCH_MODE = $save;
|
||||||
|
|
||||||
|
if (!is_object($rs)) {
|
||||||
|
return $false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$indexes = array ();
|
||||||
|
|
||||||
|
// parse index data into array
|
||||||
|
while ($row = $rs->FetchRow()) {
|
||||||
|
if ($primary == FALSE AND $row[2] == 'PRIMARY') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($indexes[$row[2]])) {
|
||||||
|
$indexes[$row[2]] = array(
|
||||||
|
'unique' => ($row[1] == 0),
|
||||||
|
'columns' => array()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$indexes[$row[2]]['columns'][$row[3] - 1] = $row[4];
|
||||||
|
}
|
||||||
|
|
||||||
|
// sort columns by order in the index
|
||||||
|
foreach ( array_keys ($indexes) as $index )
|
||||||
|
{
|
||||||
|
ksort ($indexes[$index]['columns']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $indexes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// if magic quotes disabled, use mysql_real_escape_string()
|
||||||
|
function qstr($s,$magic_quotes=false)
|
||||||
|
{
|
||||||
|
if (!$magic_quotes) {
|
||||||
|
|
||||||
|
if (ADODB_PHPVER >= 0x4300) {
|
||||||
|
if (is_resource($this->_connectionID))
|
||||||
|
return "'".mysql_real_escape_string($s,$this->_connectionID)."'";
|
||||||
|
}
|
||||||
|
if ($this->replaceQuote[0] == '\\'){
|
||||||
|
$s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
|
||||||
|
}
|
||||||
|
return "'".str_replace("'",$this->replaceQuote,$s)."'";
|
||||||
|
}
|
||||||
|
|
||||||
|
// undo magic quotes for "
|
||||||
|
$s = str_replace('\\"','"',$s);
|
||||||
|
return "'$s'";
|
||||||
|
}
|
||||||
|
|
||||||
|
function _insertid()
|
||||||
|
{
|
||||||
|
return ADOConnection::GetOne('SELECT LAST_INSERT_ID()');
|
||||||
|
//return mysql_insert_id($this->_connectionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
function GetOne($sql,$inputarr=false)
|
||||||
|
{
|
||||||
|
if ($this->compat323 == false && strncasecmp($sql,'sele',4) == 0) {
|
||||||
|
$rs =& $this->SelectLimit($sql,1,-1,$inputarr);
|
||||||
|
if ($rs) {
|
||||||
|
$rs->Close();
|
||||||
|
if ($rs->EOF) return false;
|
||||||
|
return reset($rs->fields);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return ADOConnection::GetOne($sql,$inputarr);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function BeginTrans()
|
||||||
|
{
|
||||||
|
if ($this->debug) ADOConnection::outp("Transactions not supported in 'mysql' driver. Use 'mysqlt' or 'mysqli' driver");
|
||||||
|
}
|
||||||
|
|
||||||
|
function _affectedrows()
|
||||||
|
{
|
||||||
|
return mysql_affected_rows($this->_connectionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html
|
||||||
|
// Reference on Last_Insert_ID on the recommended way to simulate sequences
|
||||||
|
var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
|
||||||
|
var $_genSeqSQL = "create table %s (id int not null)";
|
||||||
|
var $_genSeq2SQL = "insert into %s values (%s)";
|
||||||
|
var $_dropSeqSQL = "drop table %s";
|
||||||
|
|
||||||
|
function CreateSequence($seqname='adodbseq',$startID=1)
|
||||||
|
{
|
||||||
|
if (empty($this->_genSeqSQL)) return false;
|
||||||
|
$u = strtoupper($seqname);
|
||||||
|
|
||||||
|
$ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));
|
||||||
|
if (!$ok) return false;
|
||||||
|
return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function GenID($seqname='adodbseq',$startID=1)
|
||||||
|
{
|
||||||
|
// post-nuke sets hasGenID to false
|
||||||
|
if (!$this->hasGenID) return false;
|
||||||
|
|
||||||
|
$savelog = $this->_logsql;
|
||||||
|
$this->_logsql = false;
|
||||||
|
$getnext = sprintf($this->_genIDSQL,$seqname);
|
||||||
|
$holdtransOK = $this->_transOK; // save the current status
|
||||||
|
$rs = @$this->Execute($getnext);
|
||||||
|
if (!$rs) {
|
||||||
|
if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset
|
||||||
|
$u = strtoupper($seqname);
|
||||||
|
$this->Execute(sprintf($this->_genSeqSQL,$seqname));
|
||||||
|
$this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
|
||||||
|
$rs = $this->Execute($getnext);
|
||||||
|
}
|
||||||
|
$this->genID = mysql_insert_id($this->_connectionID);
|
||||||
|
|
||||||
|
if ($rs) $rs->Close();
|
||||||
|
|
||||||
|
$this->_logsql = $savelog;
|
||||||
|
return $this->genID;
|
||||||
|
}
|
||||||
|
|
||||||
|
function &MetaDatabases()
|
||||||
|
{
|
||||||
|
$qid = mysql_list_dbs($this->_connectionID);
|
||||||
|
$arr = array();
|
||||||
|
$i = 0;
|
||||||
|
$max = mysql_num_rows($qid);
|
||||||
|
while ($i < $max) {
|
||||||
|
$db = mysql_tablename($qid,$i);
|
||||||
|
if ($db != 'mysql') $arr[] = $db;
|
||||||
|
$i += 1;
|
||||||
|
}
|
||||||
|
return $arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Format date column in sql string given an input format that understands Y M D
|
||||||
|
function SQLDate($fmt, $col=false)
|
||||||
|
{
|
||||||
|
if (!$col) $col = $this->sysTimeStamp;
|
||||||
|
$s = 'DATE_FORMAT('.$col.",'";
|
||||||
|
$concat = false;
|
||||||
|
$len = strlen($fmt);
|
||||||
|
for ($i=0; $i < $len; $i++) {
|
||||||
|
$ch = $fmt[$i];
|
||||||
|
switch($ch) {
|
||||||
|
|
||||||
|
default:
|
||||||
|
if ($ch == '\\') {
|
||||||
|
$i++;
|
||||||
|
$ch = substr($fmt,$i,1);
|
||||||
|
}
|
||||||
|
/** FALL THROUGH */
|
||||||
|
case '-':
|
||||||
|
case '/':
|
||||||
|
$s .= $ch;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'Y':
|
||||||
|
case 'y':
|
||||||
|
$s .= '%Y';
|
||||||
|
break;
|
||||||
|
case 'M':
|
||||||
|
$s .= '%b';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'm':
|
||||||
|
$s .= '%m';
|
||||||
|
break;
|
||||||
|
case 'D':
|
||||||
|
case 'd':
|
||||||
|
$s .= '%d';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'Q':
|
||||||
|
case 'q':
|
||||||
|
$s .= "'),Quarter($col)";
|
||||||
|
|
||||||
|
if ($len > $i+1) $s .= ",DATE_FORMAT($col,'";
|
||||||
|
else $s .= ",('";
|
||||||
|
$concat = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'H':
|
||||||
|
$s .= '%H';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'h':
|
||||||
|
$s .= '%I';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'i':
|
||||||
|
$s .= '%i';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 's':
|
||||||
|
$s .= '%s';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'a':
|
||||||
|
case 'A':
|
||||||
|
$s .= '%p';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'w':
|
||||||
|
$s .= '%w';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'W':
|
||||||
|
$s .= '%U';
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'l':
|
||||||
|
$s .= '%W';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$s.="')";
|
||||||
|
if ($concat) $s = "CONCAT($s)";
|
||||||
|
return $s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// returns concatenated string
|
||||||
|
// much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator
|
||||||
|
function Concat()
|
||||||
|
{
|
||||||
|
$s = "";
|
||||||
|
$arr = func_get_args();
|
||||||
|
|
||||||
|
// suggestion by andrew005@mnogo.ru
|
||||||
|
$s = implode(',',$arr);
|
||||||
|
if (strlen($s) > 0) return "CONCAT($s)";
|
||||||
|
else return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function OffsetDate($dayFraction,$date=false)
|
||||||
|
{
|
||||||
|
if (!$date) $date = $this->sysDate;
|
||||||
|
|
||||||
|
$fraction = $dayFraction * 24 * 3600;
|
||||||
|
return $date . ' + INTERVAL ' . $fraction.' SECOND';
|
||||||
|
|
||||||
|
// return "from_unixtime(unix_timestamp($date)+$fraction)";
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true or false
|
||||||
|
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||||
|
{
|
||||||
|
if (!empty($this->port)) $argHostname .= ":".$this->port;
|
||||||
|
|
||||||
|
if (ADODB_PHPVER >= 0x4300)
|
||||||
|
$this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
|
||||||
|
$this->forceNewConnect,$this->clientFlags);
|
||||||
|
else if (ADODB_PHPVER >= 0x4200)
|
||||||
|
$this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,
|
||||||
|
$this->forceNewConnect);
|
||||||
|
else
|
||||||
|
$this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword);
|
||||||
|
|
||||||
|
if ($this->_connectionID === false) return false;
|
||||||
|
if ($argDatabasename) return $this->SelectDB($argDatabasename);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true or false
|
||||||
|
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||||
|
{
|
||||||
|
if (!empty($this->port)) $argHostname .= ":".$this->port;
|
||||||
|
|
||||||
|
if (ADODB_PHPVER >= 0x4300)
|
||||||
|
$this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword,$this->clientFlags);
|
||||||
|
else
|
||||||
|
$this->_connectionID = mysql_pconnect($argHostname,$argUsername,$argPassword);
|
||||||
|
if ($this->_connectionID === false) return false;
|
||||||
|
if ($this->autoRollback) $this->RollbackTrans();
|
||||||
|
if ($argDatabasename) return $this->SelectDB($argDatabasename);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||||
|
{
|
||||||
|
$this->forceNewConnect = true;
|
||||||
|
return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
|
||||||
|
}
|
||||||
|
|
||||||
|
function &MetaColumns($table)
|
||||||
|
{
|
||||||
|
$this->_findschema($table,$schema);
|
||||||
|
if ($schema) {
|
||||||
|
$dbName = $this->database;
|
||||||
|
$this->SelectDB($schema);
|
||||||
|
}
|
||||||
|
global $ADODB_FETCH_MODE;
|
||||||
|
$save = $ADODB_FETCH_MODE;
|
||||||
|
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||||
|
|
||||||
|
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
|
||||||
|
$rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
|
||||||
|
|
||||||
|
if ($schema) {
|
||||||
|
$this->SelectDB($dbName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($savem)) $this->SetFetchMode($savem);
|
||||||
|
$ADODB_FETCH_MODE = $save;
|
||||||
|
if (!is_object($rs)) {
|
||||||
|
$false = false;
|
||||||
|
return $false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$retarr = array();
|
||||||
|
while (!$rs->EOF){
|
||||||
|
$fld = new ADOFieldObject();
|
||||||
|
$fld->name = $rs->fields[0];
|
||||||
|
$type = $rs->fields[1];
|
||||||
|
|
||||||
|
// split type into type(length):
|
||||||
|
$fld->scale = null;
|
||||||
|
if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
|
||||||
|
$fld->type = $query_array[1];
|
||||||
|
$fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
|
||||||
|
$fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
|
||||||
|
} elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
|
||||||
|
$fld->type = $query_array[1];
|
||||||
|
$fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
|
||||||
|
} elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) {
|
||||||
|
$fld->type = $query_array[1];
|
||||||
|
$arr = explode(",",$query_array[2]);
|
||||||
|
$fld->enums = $arr;
|
||||||
|
$zlen = max(array_map("strlen",$arr)) - 2; // PHP >= 4.0.6
|
||||||
|
$fld->max_length = ($zlen > 0) ? $zlen : 1;
|
||||||
|
} else {
|
||||||
|
$fld->type = $type;
|
||||||
|
$fld->max_length = -1;
|
||||||
|
}
|
||||||
|
$fld->not_null = ($rs->fields[2] != 'YES');
|
||||||
|
$fld->primary_key = ($rs->fields[3] == 'PRI');
|
||||||
|
$fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
|
||||||
|
$fld->binary = (strpos($type,'blob') !== false);
|
||||||
|
$fld->unsigned = (strpos($type,'unsigned') !== false);
|
||||||
|
|
||||||
|
if (!$fld->binary) {
|
||||||
|
$d = $rs->fields[4];
|
||||||
|
if ($d != '' && $d != 'NULL') {
|
||||||
|
$fld->has_default = true;
|
||||||
|
$fld->default_value = $d;
|
||||||
|
} else {
|
||||||
|
$fld->has_default = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($save == ADODB_FETCH_NUM) {
|
||||||
|
$retarr[] = $fld;
|
||||||
|
} else {
|
||||||
|
$retarr[strtoupper($fld->name)] = $fld;
|
||||||
|
}
|
||||||
|
$rs->MoveNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
$rs->Close();
|
||||||
|
return $retarr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true or false
|
||||||
|
function SelectDB($dbName)
|
||||||
|
{
|
||||||
|
$this->database = $dbName;
|
||||||
|
$this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions
|
||||||
|
if ($this->_connectionID) {
|
||||||
|
return @mysql_select_db($dbName,$this->_connectionID);
|
||||||
|
}
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// parameters use PostgreSQL convention, not MySQL
|
||||||
|
function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs=0)
|
||||||
|
{
|
||||||
|
$offsetStr =($offset>=0) ? ((integer)$offset)."," : '';
|
||||||
|
// jason judge, see http://phplens.com/lens/lensforum/msgs.php?id=9220
|
||||||
|
if ($nrows < 0) $nrows = '18446744073709551615';
|
||||||
|
|
||||||
|
if ($secs)
|
||||||
|
$rs =& $this->CacheExecute($secs,$sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
|
||||||
|
else
|
||||||
|
$rs =& $this->Execute($sql." LIMIT $offsetStr".((integer)$nrows),$inputarr);
|
||||||
|
return $rs;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns queryID or false
|
||||||
|
function _query($sql,$inputarr)
|
||||||
|
{
|
||||||
|
//global $ADODB_COUNTRECS;
|
||||||
|
//if($ADODB_COUNTRECS)
|
||||||
|
return mysql_query($sql,$this->_connectionID);
|
||||||
|
//else return @mysql_unbuffered_query($sql,$this->_connectionID); // requires PHP >= 4.0.6
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Returns: the last error message from previous database operation */
|
||||||
|
function ErrorMsg()
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($this->_logsql) return $this->_errorMsg;
|
||||||
|
if (empty($this->_connectionID)) $this->_errorMsg = @mysql_error();
|
||||||
|
else $this->_errorMsg = @mysql_error($this->_connectionID);
|
||||||
|
return $this->_errorMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Returns: the last error number from previous database operation */
|
||||||
|
function ErrorNo()
|
||||||
|
{
|
||||||
|
if ($this->_logsql) return $this->_errorCode;
|
||||||
|
if (empty($this->_connectionID)) return @mysql_errno();
|
||||||
|
else return @mysql_errno($this->_connectionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true or false
|
||||||
|
function _close()
|
||||||
|
{
|
||||||
|
@mysql_close($this->_connectionID);
|
||||||
|
$this->_connectionID = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Maximum size of C field
|
||||||
|
*/
|
||||||
|
function CharMax()
|
||||||
|
{
|
||||||
|
return 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Maximum size of X field
|
||||||
|
*/
|
||||||
|
function TextMax()
|
||||||
|
{
|
||||||
|
return 4294967295;
|
||||||
|
}
|
||||||
|
|
||||||
|
// "Innox - Juan Carlos Gonzalez" <jgonzalez#innox.com.mx>
|
||||||
|
function MetaForeignKeys( $table, $owner = FALSE, $upper = FALSE, $associative = FALSE )
|
||||||
|
{
|
||||||
|
global $ADODB_FETCH_MODE;
|
||||||
|
if ($ADODB_FETCH_MODE == ADODB_FETCH_ASSOC || $this->fetchMode == ADODB_FETCH_ASSOC) $associative = true;
|
||||||
|
|
||||||
|
if ( !empty($owner) ) {
|
||||||
|
$table = "$owner.$table";
|
||||||
|
}
|
||||||
|
$a_create_table = $this->getRow(sprintf('SHOW CREATE TABLE %s', $table));
|
||||||
|
if ($associative) $create_sql = $a_create_table["Create Table"];
|
||||||
|
else $create_sql = $a_create_table[1];
|
||||||
|
|
||||||
|
$matches = array();
|
||||||
|
|
||||||
|
if (!preg_match_all("/FOREIGN KEY \(`(.*?)`\) REFERENCES `(.*?)` \(`(.*?)`\)/", $create_sql, $matches)) return false;
|
||||||
|
$foreign_keys = array();
|
||||||
|
$num_keys = count($matches[0]);
|
||||||
|
for ( $i = 0; $i < $num_keys; $i ++ ) {
|
||||||
|
$my_field = explode('`, `', $matches[1][$i]);
|
||||||
|
$ref_table = $matches[2][$i];
|
||||||
|
$ref_field = explode('`, `', $matches[3][$i]);
|
||||||
|
|
||||||
|
if ( $upper ) {
|
||||||
|
$ref_table = strtoupper($ref_table);
|
||||||
|
}
|
||||||
|
|
||||||
|
$foreign_keys[$ref_table] = array();
|
||||||
|
$num_fields = count($my_field);
|
||||||
|
for ( $j = 0; $j < $num_fields; $j ++ ) {
|
||||||
|
if ( $associative ) {
|
||||||
|
$foreign_keys[$ref_table][$ref_field[$j]] = $my_field[$j];
|
||||||
|
} else {
|
||||||
|
$foreign_keys[$ref_table][] = "{$my_field[$j]}={$ref_field[$j]}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $foreign_keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------
|
||||||
|
Class Name: Recordset
|
||||||
|
--------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
class ADORecordSet_mysql extends ADORecordSet{
|
||||||
|
|
||||||
|
var $databaseType = "mysql";
|
||||||
|
var $canSeek = true;
|
||||||
|
|
||||||
|
function ADORecordSet_mysql($queryID,$mode=false)
|
||||||
|
{
|
||||||
|
if ($mode === false) {
|
||||||
|
global $ADODB_FETCH_MODE;
|
||||||
|
$mode = $ADODB_FETCH_MODE;
|
||||||
|
}
|
||||||
|
switch ($mode)
|
||||||
|
{
|
||||||
|
case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break;
|
||||||
|
case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break;
|
||||||
|
case ADODB_FETCH_DEFAULT:
|
||||||
|
case ADODB_FETCH_BOTH:
|
||||||
|
default:
|
||||||
|
$this->fetchMode = MYSQL_BOTH; break;
|
||||||
|
}
|
||||||
|
$this->adodbFetchMode = $mode;
|
||||||
|
$this->ADORecordSet($queryID);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _initrs()
|
||||||
|
{
|
||||||
|
//GLOBAL $ADODB_COUNTRECS;
|
||||||
|
// $this->_numOfRows = ($ADODB_COUNTRECS) ? @mysql_num_rows($this->_queryID):-1;
|
||||||
|
$this->_numOfRows = @mysql_num_rows($this->_queryID);
|
||||||
|
$this->_numOfFields = @mysql_num_fields($this->_queryID);
|
||||||
|
}
|
||||||
|
|
||||||
|
function &FetchField($fieldOffset = -1)
|
||||||
|
{
|
||||||
|
if ($fieldOffset != -1) {
|
||||||
|
$o = @mysql_fetch_field($this->_queryID, $fieldOffset);
|
||||||
|
$f = @mysql_field_flags($this->_queryID,$fieldOffset);
|
||||||
|
$o->max_length = @mysql_field_len($this->_queryID,$fieldOffset); // suggested by: Jim Nicholson (jnich@att.com)
|
||||||
|
//$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
|
||||||
|
$o->binary = (strpos($f,'binary')!== false);
|
||||||
|
}
|
||||||
|
else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */
|
||||||
|
$o = @mysql_fetch_field($this->_queryID);
|
||||||
|
$o->max_length = @mysql_field_len($this->_queryID); // suggested by: Jim Nicholson (jnich@att.com)
|
||||||
|
//$o->max_length = -1; // mysql returns the max length less spaces -- so it is unrealiable
|
||||||
|
}
|
||||||
|
|
||||||
|
return $o;
|
||||||
|
}
|
||||||
|
|
||||||
|
function &GetRowAssoc($upper=true)
|
||||||
|
{
|
||||||
|
if ($this->fetchMode == MYSQL_ASSOC && !$upper) $row = $this->fields;
|
||||||
|
else $row =& ADORecordSet::GetRowAssoc($upper);
|
||||||
|
return $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Use associative array to get fields array */
|
||||||
|
function Fields($colname)
|
||||||
|
{
|
||||||
|
// added @ by "Michael William Miller" <mille562@pilot.msu.edu>
|
||||||
|
if ($this->fetchMode != MYSQL_NUM) return @$this->fields[$colname];
|
||||||
|
|
||||||
|
if (!$this->bind) {
|
||||||
|
$this->bind = array();
|
||||||
|
for ($i=0; $i < $this->_numOfFields; $i++) {
|
||||||
|
$o = $this->FetchField($i);
|
||||||
|
$this->bind[strtoupper($o->name)] = $i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $this->fields[$this->bind[strtoupper($colname)]];
|
||||||
|
}
|
||||||
|
|
||||||
|
function _seek($row)
|
||||||
|
{
|
||||||
|
if ($this->_numOfRows == 0) return false;
|
||||||
|
return @mysql_data_seek($this->_queryID,$row);
|
||||||
|
}
|
||||||
|
|
||||||
|
function MoveNext()
|
||||||
|
{
|
||||||
|
//return adodb_movenext($this);
|
||||||
|
//if (defined('ADODB_EXTENSION')) return adodb_movenext($this);
|
||||||
|
if (@$this->fields = mysql_fetch_array($this->_queryID,$this->fetchMode)) {
|
||||||
|
$this->_currentRow += 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!$this->EOF) {
|
||||||
|
$this->_currentRow += 1;
|
||||||
|
$this->EOF = true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _fetch()
|
||||||
|
{
|
||||||
|
$this->fields = @mysql_fetch_array($this->_queryID,$this->fetchMode);
|
||||||
|
return is_array($this->fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _close() {
|
||||||
|
@mysql_free_result($this->_queryID);
|
||||||
|
$this->_queryID = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function MetaType($t,$len=-1,$fieldobj=false)
|
||||||
|
{
|
||||||
|
if (is_object($t)) {
|
||||||
|
$fieldobj = $t;
|
||||||
|
$t = $fieldobj->type;
|
||||||
|
$len = $fieldobj->max_length;
|
||||||
|
}
|
||||||
|
|
||||||
|
$len = -1; // mysql max_length is not accurate
|
||||||
|
switch (strtoupper($t)) {
|
||||||
|
case 'STRING':
|
||||||
|
case 'CHAR':
|
||||||
|
case 'VARCHAR':
|
||||||
|
case 'TINYBLOB':
|
||||||
|
case 'TINYTEXT':
|
||||||
|
case 'ENUM':
|
||||||
|
case 'SET':
|
||||||
|
if ($len <= $this->blobSize) return 'C';
|
||||||
|
|
||||||
|
case 'TEXT':
|
||||||
|
case 'LONGTEXT':
|
||||||
|
case 'MEDIUMTEXT':
|
||||||
|
return 'X';
|
||||||
|
|
||||||
|
// php_mysql extension always returns 'blob' even if 'text'
|
||||||
|
// so we have to check whether binary...
|
||||||
|
case 'IMAGE':
|
||||||
|
case 'LONGBLOB':
|
||||||
|
case 'BLOB':
|
||||||
|
case 'MEDIUMBLOB':
|
||||||
|
return !empty($fieldobj->binary) ? 'B' : 'X';
|
||||||
|
|
||||||
|
case 'YEAR':
|
||||||
|
case 'DATE': return 'D';
|
||||||
|
|
||||||
|
case 'TIME':
|
||||||
|
case 'DATETIME':
|
||||||
|
case 'TIMESTAMP': return 'T';
|
||||||
|
|
||||||
|
case 'INT':
|
||||||
|
case 'INTEGER':
|
||||||
|
case 'BIGINT':
|
||||||
|
case 'TINYINT':
|
||||||
|
case 'MEDIUMINT':
|
||||||
|
case 'SMALLINT':
|
||||||
|
|
||||||
|
if (!empty($fieldobj->primary_key)) return 'R';
|
||||||
|
else return 'I';
|
||||||
|
|
||||||
|
default: return 'N';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class ADORecordSet_ext_mysql extends ADORecordSet_mysql {
|
||||||
|
function ADORecordSet_ext_mysql($queryID,$mode=false)
|
||||||
|
{
|
||||||
|
if ($mode === false) {
|
||||||
|
global $ADODB_FETCH_MODE;
|
||||||
|
$mode = $ADODB_FETCH_MODE;
|
||||||
|
}
|
||||||
|
switch ($mode)
|
||||||
|
{
|
||||||
|
case ADODB_FETCH_NUM: $this->fetchMode = MYSQL_NUM; break;
|
||||||
|
case ADODB_FETCH_ASSOC:$this->fetchMode = MYSQL_ASSOC; break;
|
||||||
|
case ADODB_FETCH_DEFAULT:
|
||||||
|
case ADODB_FETCH_BOTH:
|
||||||
|
default:
|
||||||
|
$this->fetchMode = MYSQL_BOTH; break;
|
||||||
|
}
|
||||||
|
$this->adodbFetchMode = $mode;
|
||||||
|
$this->ADORecordSet($queryID);
|
||||||
|
}
|
||||||
|
|
||||||
|
function MoveNext()
|
||||||
|
{
|
||||||
|
return @adodb_movenext($this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
398
lib/adodb/drivers/adodb-sqlite.inc.php
Normal file
398
lib/adodb/drivers/adodb-sqlite.inc.php
Normal file
|
@ -0,0 +1,398 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
V4.94 23 Jan 2007 (c) 2000-2007 John Lim (jlim#natsoft.com.my). All rights reserved.
|
||||||
|
Released under both BSD license and Lesser GPL library license.
|
||||||
|
Whenever there is any discrepancy between the two licenses,
|
||||||
|
the BSD license will take precedence.
|
||||||
|
|
||||||
|
Latest version is available at http://adodb.sourceforge.net
|
||||||
|
|
||||||
|
SQLite info: http://www.hwaci.com/sw/sqlite/
|
||||||
|
|
||||||
|
Install Instructions:
|
||||||
|
====================
|
||||||
|
1. Place this in adodb/drivers
|
||||||
|
2. Rename the file, remove the .txt prefix.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// security - hide paths
|
||||||
|
if (!defined('ADODB_DIR')) die();
|
||||||
|
|
||||||
|
class ADODB_sqlite extends ADOConnection {
|
||||||
|
var $databaseType = "sqlite";
|
||||||
|
var $replaceQuote = "''"; // string to use to replace quotes
|
||||||
|
var $concat_operator='||';
|
||||||
|
var $_errorNo = 0;
|
||||||
|
var $hasLimit = true;
|
||||||
|
var $hasInsertID = true; /// supports autoincrement ID?
|
||||||
|
var $hasAffectedRows = true; /// supports affected rows for update/delete?
|
||||||
|
var $metaTablesSQL = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name";
|
||||||
|
var $sysDate = "adodb_date('Y-m-d')";
|
||||||
|
var $sysTimeStamp = "adodb_date('Y-m-d H:i:s')";
|
||||||
|
var $fmtTimeStamp = "'Y-m-d H:i:s'";
|
||||||
|
|
||||||
|
function ADODB_sqlite()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
function __get($name)
|
||||||
|
{
|
||||||
|
switch($name) {
|
||||||
|
case 'sysDate': return "'".date($this->fmtDate)."'";
|
||||||
|
case 'sysTimeStamp' : return "'".date($this->sysTimeStamp)."'";
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
function ServerInfo()
|
||||||
|
{
|
||||||
|
$arr['version'] = sqlite_libversion();
|
||||||
|
$arr['description'] = 'SQLite ';
|
||||||
|
$arr['encoding'] = sqlite_libencoding();
|
||||||
|
return $arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
function BeginTrans()
|
||||||
|
{
|
||||||
|
if ($this->transOff) return true;
|
||||||
|
$ret = $this->Execute("BEGIN TRANSACTION");
|
||||||
|
$this->transCnt += 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function CommitTrans($ok=true)
|
||||||
|
{
|
||||||
|
if ($this->transOff) return true;
|
||||||
|
if (!$ok) return $this->RollbackTrans();
|
||||||
|
$ret = $this->Execute("COMMIT");
|
||||||
|
if ($this->transCnt>0)$this->transCnt -= 1;
|
||||||
|
return !empty($ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
function RollbackTrans()
|
||||||
|
{
|
||||||
|
if ($this->transOff) return true;
|
||||||
|
$ret = $this->Execute("ROLLBACK");
|
||||||
|
if ($this->transCnt>0)$this->transCnt -= 1;
|
||||||
|
return !empty($ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
// mark newnham
|
||||||
|
function &MetaColumns($tab)
|
||||||
|
{
|
||||||
|
global $ADODB_FETCH_MODE;
|
||||||
|
$false = false;
|
||||||
|
$save = $ADODB_FETCH_MODE;
|
||||||
|
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
|
||||||
|
if ($this->fetchMode !== false) $savem = $this->SetFetchMode(false);
|
||||||
|
$rs = $this->Execute("PRAGMA table_info('$tab')");
|
||||||
|
if (isset($savem)) $this->SetFetchMode($savem);
|
||||||
|
if (!$rs) {
|
||||||
|
$ADODB_FETCH_MODE = $save;
|
||||||
|
return $false;
|
||||||
|
}
|
||||||
|
$arr = array();
|
||||||
|
while ($r = $rs->FetchRow()) {
|
||||||
|
$type = explode('(',$r['type']);
|
||||||
|
$size = '';
|
||||||
|
if (sizeof($type)==2)
|
||||||
|
$size = trim($type[1],')');
|
||||||
|
$fn = strtoupper($r['name']);
|
||||||
|
$fld = new ADOFieldObject;
|
||||||
|
$fld->name = $r['name'];
|
||||||
|
$fld->type = $type[0];
|
||||||
|
$fld->max_length = $size;
|
||||||
|
$fld->not_null = $r['notnull'];
|
||||||
|
$fld->default_value = $r['dflt_value'];
|
||||||
|
$fld->scale = 0;
|
||||||
|
if ($save == ADODB_FETCH_NUM) $arr[] = $fld;
|
||||||
|
else $arr[strtoupper($fld->name)] = $fld;
|
||||||
|
}
|
||||||
|
$rs->Close();
|
||||||
|
$ADODB_FETCH_MODE = $save;
|
||||||
|
return $arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _init($parentDriver)
|
||||||
|
{
|
||||||
|
|
||||||
|
$parentDriver->hasTransactions = false;
|
||||||
|
$parentDriver->hasInsertID = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _insertid()
|
||||||
|
{
|
||||||
|
return sqlite_last_insert_rowid($this->_connectionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _affectedrows()
|
||||||
|
{
|
||||||
|
return sqlite_changes($this->_connectionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ErrorMsg()
|
||||||
|
{
|
||||||
|
if ($this->_logsql) return $this->_errorMsg;
|
||||||
|
return ($this->_errorNo) ? sqlite_error_string($this->_errorNo) : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
function ErrorNo()
|
||||||
|
{
|
||||||
|
return $this->_errorNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
function SQLDate($fmt, $col=false)
|
||||||
|
{
|
||||||
|
$fmt = $this->qstr($fmt);
|
||||||
|
return ($col) ? "adodb_date2($fmt,$col)" : "adodb_date($fmt)";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function _createFunctions()
|
||||||
|
{
|
||||||
|
@sqlite_create_function($this->_connectionID, 'adodb_date', 'adodb_date', 1);
|
||||||
|
@sqlite_create_function($this->_connectionID, 'adodb_date2', 'adodb_date2', 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// returns true or false
|
||||||
|
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||||
|
{
|
||||||
|
if (!function_exists('sqlite_open')) return null;
|
||||||
|
if (empty($argHostname) && $argDatabasename) $argHostname = $argDatabasename;
|
||||||
|
|
||||||
|
$this->_connectionID = sqlite_open($argHostname);
|
||||||
|
if ($this->_connectionID === false) return false;
|
||||||
|
$this->_createFunctions();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true or false
|
||||||
|
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
|
||||||
|
{
|
||||||
|
if (!function_exists('sqlite_open')) return null;
|
||||||
|
if (empty($argHostname) && $argDatabasename) $argHostname = $argDatabasename;
|
||||||
|
|
||||||
|
$this->_connectionID = sqlite_popen($argHostname);
|
||||||
|
if ($this->_connectionID === false) return false;
|
||||||
|
$this->_createFunctions();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns query ID if successful, otherwise false
|
||||||
|
function _query($sql,$inputarr=false)
|
||||||
|
{
|
||||||
|
$rez = sqlite_query($sql,$this->_connectionID);
|
||||||
|
if (!$rez) {
|
||||||
|
$this->_errorNo = sqlite_last_error($this->_connectionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rez;
|
||||||
|
}
|
||||||
|
|
||||||
|
function &SelectLimit($sql,$nrows=-1,$offset=-1,$inputarr=false,$secs2cache=0)
|
||||||
|
{
|
||||||
|
$offsetStr = ($offset >= 0) ? " OFFSET $offset" : '';
|
||||||
|
$limitStr = ($nrows >= 0) ? " LIMIT $nrows" : ($offset >= 0 ? ' LIMIT 999999999' : '');
|
||||||
|
if ($secs2cache)
|
||||||
|
$rs =& $this->CacheExecute($secs2cache,$sql."$limitStr$offsetStr",$inputarr);
|
||||||
|
else
|
||||||
|
$rs =& $this->Execute($sql."$limitStr$offsetStr",$inputarr);
|
||||||
|
|
||||||
|
return $rs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
This algorithm is not very efficient, but works even if table locking
|
||||||
|
is not available.
|
||||||
|
|
||||||
|
Will return false if unable to generate an ID after $MAXLOOPS attempts.
|
||||||
|
*/
|
||||||
|
var $_genSeqSQL = "create table %s (id integer)";
|
||||||
|
|
||||||
|
function GenID($seq='adodbseq',$start=1)
|
||||||
|
{
|
||||||
|
// if you have to modify the parameter below, your database is overloaded,
|
||||||
|
// or you need to implement generation of id's yourself!
|
||||||
|
$MAXLOOPS = 100;
|
||||||
|
//$this->debug=1;
|
||||||
|
while (--$MAXLOOPS>=0) {
|
||||||
|
@($num = $this->GetOne("select id from $seq"));
|
||||||
|
if ($num === false) {
|
||||||
|
$this->Execute(sprintf($this->_genSeqSQL ,$seq));
|
||||||
|
$start -= 1;
|
||||||
|
$num = '0';
|
||||||
|
$ok = $this->Execute("insert into $seq values($start)");
|
||||||
|
if (!$ok) return false;
|
||||||
|
}
|
||||||
|
$this->Execute("update $seq set id=id+1 where id=$num");
|
||||||
|
|
||||||
|
if ($this->affected_rows() > 0) {
|
||||||
|
$num += 1;
|
||||||
|
$this->genID = $num;
|
||||||
|
return $num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($fn = $this->raiseErrorFn) {
|
||||||
|
$fn($this->databaseType,'GENID',-32000,"Unable to generate unique id after $MAXLOOPS attempts",$seq,$num);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function CreateSequence($seqname='adodbseq',$start=1)
|
||||||
|
{
|
||||||
|
if (empty($this->_genSeqSQL)) return false;
|
||||||
|
$ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));
|
||||||
|
if (!$ok) return false;
|
||||||
|
$start -= 1;
|
||||||
|
return $this->Execute("insert into $seqname values($start)");
|
||||||
|
}
|
||||||
|
|
||||||
|
var $_dropSeqSQL = 'drop table %s';
|
||||||
|
function DropSequence($seqname)
|
||||||
|
{
|
||||||
|
if (empty($this->_dropSeqSQL)) return false;
|
||||||
|
return $this->Execute(sprintf($this->_dropSeqSQL,$seqname));
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns true or false
|
||||||
|
function _close()
|
||||||
|
{
|
||||||
|
return @sqlite_close($this->_connectionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
function &MetaIndexes($table, $primary = FALSE, $owner=false)
|
||||||
|
{
|
||||||
|
$false = false;
|
||||||
|
// save old fetch mode
|
||||||
|
global $ADODB_FETCH_MODE;
|
||||||
|
$save = $ADODB_FETCH_MODE;
|
||||||
|
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
|
||||||
|
if ($this->fetchMode !== FALSE) {
|
||||||
|
$savem = $this->SetFetchMode(FALSE);
|
||||||
|
}
|
||||||
|
$SQL=sprintf("SELECT name,sql FROM sqlite_master WHERE type='index' AND tbl_name='%s'", strtolower($table));
|
||||||
|
$rs = $this->Execute($SQL);
|
||||||
|
if (!is_object($rs)) {
|
||||||
|
if (isset($savem))
|
||||||
|
$this->SetFetchMode($savem);
|
||||||
|
$ADODB_FETCH_MODE = $save;
|
||||||
|
return $false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$indexes = array ();
|
||||||
|
while ($row = $rs->FetchRow()) {
|
||||||
|
if ($primary && preg_match("/primary/i",$row[1]) == 0) continue;
|
||||||
|
if (!isset($indexes[$row[0]])) {
|
||||||
|
|
||||||
|
$indexes[$row[0]] = array(
|
||||||
|
'unique' => preg_match("/unique/i",$row[1]),
|
||||||
|
'columns' => array());
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* There must be a more elegant way of doing this,
|
||||||
|
* the index elements appear in the SQL statement
|
||||||
|
* in cols[1] between parentheses
|
||||||
|
* e.g CREATE UNIQUE INDEX ware_0 ON warehouse (org,warehouse)
|
||||||
|
*/
|
||||||
|
$cols = explode("(",$row[1]);
|
||||||
|
$cols = explode(")",$cols[1]);
|
||||||
|
array_pop($cols);
|
||||||
|
$indexes[$row[0]]['columns'] = $cols;
|
||||||
|
}
|
||||||
|
if (isset($savem)) {
|
||||||
|
$this->SetFetchMode($savem);
|
||||||
|
$ADODB_FETCH_MODE = $save;
|
||||||
|
}
|
||||||
|
return $indexes;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------------------
|
||||||
|
Class Name: Recordset
|
||||||
|
--------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class ADORecordset_sqlite extends ADORecordSet {
|
||||||
|
|
||||||
|
var $databaseType = "sqlite";
|
||||||
|
var $bind = false;
|
||||||
|
|
||||||
|
function ADORecordset_sqlite($queryID,$mode=false)
|
||||||
|
{
|
||||||
|
|
||||||
|
if ($mode === false) {
|
||||||
|
global $ADODB_FETCH_MODE;
|
||||||
|
$mode = $ADODB_FETCH_MODE;
|
||||||
|
}
|
||||||
|
switch($mode) {
|
||||||
|
case ADODB_FETCH_NUM: $this->fetchMode = SQLITE_NUM; break;
|
||||||
|
case ADODB_FETCH_ASSOC: $this->fetchMode = SQLITE_ASSOC; break;
|
||||||
|
default: $this->fetchMode = SQLITE_BOTH; break;
|
||||||
|
}
|
||||||
|
$this->adodbFetchMode = $mode;
|
||||||
|
|
||||||
|
$this->_queryID = $queryID;
|
||||||
|
|
||||||
|
$this->_inited = true;
|
||||||
|
$this->fields = array();
|
||||||
|
if ($queryID) {
|
||||||
|
$this->_currentRow = 0;
|
||||||
|
$this->EOF = !$this->_fetch();
|
||||||
|
@$this->_initrs();
|
||||||
|
} else {
|
||||||
|
$this->_numOfRows = 0;
|
||||||
|
$this->_numOfFields = 0;
|
||||||
|
$this->EOF = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->_queryID;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function &FetchField($fieldOffset = -1)
|
||||||
|
{
|
||||||
|
$fld = new ADOFieldObject;
|
||||||
|
$fld->name = sqlite_field_name($this->_queryID, $fieldOffset);
|
||||||
|
$fld->type = 'VARCHAR';
|
||||||
|
$fld->max_length = -1;
|
||||||
|
return $fld;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _initrs()
|
||||||
|
{
|
||||||
|
$this->_numOfRows = @sqlite_num_rows($this->_queryID);
|
||||||
|
$this->_numOfFields = @sqlite_num_fields($this->_queryID);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Fields($colname)
|
||||||
|
{
|
||||||
|
if ($this->fetchMode != SQLITE_NUM) return $this->fields[$colname];
|
||||||
|
if (!$this->bind) {
|
||||||
|
$this->bind = array();
|
||||||
|
for ($i=0; $i < $this->_numOfFields; $i++) {
|
||||||
|
$o = $this->FetchField($i);
|
||||||
|
$this->bind[strtoupper($o->name)] = $i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->fields[$this->bind[strtoupper($colname)]];
|
||||||
|
}
|
||||||
|
|
||||||
|
function _seek($row)
|
||||||
|
{
|
||||||
|
return sqlite_seek($this->_queryID, $row);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _fetch($ignore_fields=false)
|
||||||
|
{
|
||||||
|
$this->fields = @sqlite_fetch_array($this->_queryID,$this->fetchMode);
|
||||||
|
return !empty($this->fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _close()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
182
lib/adodb/license.txt
Normal file
182
lib/adodb/license.txt
Normal file
|
@ -0,0 +1,182 @@
|
||||||
|
ADOdb is dual licensed using BSD and LGPL.
|
||||||
|
|
||||||
|
In plain English, you do not need to distribute your application in source code form, nor do you need to distribute ADOdb source code, provided you follow the rest of terms of the BSD license.
|
||||||
|
|
||||||
|
For more info about ADOdb, visit http://adodb.sourceforge.net/
|
||||||
|
|
||||||
|
BSD Style-License
|
||||||
|
=================
|
||||||
|
|
||||||
|
Copyright (c) 2000, 2001, 2002, 2003, 2004 John Lim
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
Redistributions of source code must retain the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
of conditions and the following disclaimer in the documentation and/or other materials
|
||||||
|
provided with the distribution.
|
||||||
|
|
||||||
|
Neither the name of the John Lim nor the names of its contributors may be used to
|
||||||
|
endorse or promote products derived from this software without specific prior written
|
||||||
|
permission.
|
||||||
|
|
||||||
|
DISCLAIMER:
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
||||||
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
||||||
|
JOHN LIM OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
==========================================================
|
||||||
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
Version 2.1, February 1999
|
||||||
|
|
||||||
|
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||||
|
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
[This is the first released version of the Lesser GPL. It also counts
|
||||||
|
as the successor of the GNU Library Public License, version 2, hence
|
||||||
|
the version number 2.1.]
|
||||||
|
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users.
|
||||||
|
|
||||||
|
This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it.
|
||||||
|
|
||||||
|
For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights.
|
||||||
|
|
||||||
|
We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library.
|
||||||
|
|
||||||
|
To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others.
|
||||||
|
|
||||||
|
Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license.
|
||||||
|
|
||||||
|
Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs.
|
||||||
|
|
||||||
|
When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library.
|
||||||
|
|
||||||
|
We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances.
|
||||||
|
|
||||||
|
For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License.
|
||||||
|
|
||||||
|
In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system.
|
||||||
|
|
||||||
|
Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run.
|
||||||
|
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you".
|
||||||
|
|
||||||
|
A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables.
|
||||||
|
|
||||||
|
The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".)
|
||||||
|
|
||||||
|
"Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library.
|
||||||
|
|
||||||
|
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does.
|
||||||
|
|
||||||
|
1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library.
|
||||||
|
|
||||||
|
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
|
||||||
|
|
||||||
|
2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
|
||||||
|
a) The modified work must itself be a software library.
|
||||||
|
b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change.
|
||||||
|
c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License.
|
||||||
|
d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful.
|
||||||
|
(For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.)
|
||||||
|
|
||||||
|
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
|
||||||
|
|
||||||
|
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library.
|
||||||
|
|
||||||
|
In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
|
||||||
|
|
||||||
|
3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices.
|
||||||
|
|
||||||
|
Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy.
|
||||||
|
|
||||||
|
This option is useful when you wish to copy part of the code of the Library into a program that is not a library.
|
||||||
|
|
||||||
|
4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange.
|
||||||
|
|
||||||
|
If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code.
|
||||||
|
|
||||||
|
5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License.
|
||||||
|
|
||||||
|
However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables.
|
||||||
|
|
||||||
|
When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law.
|
||||||
|
|
||||||
|
If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.)
|
||||||
|
|
||||||
|
Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself.
|
||||||
|
|
||||||
|
6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications.
|
||||||
|
|
||||||
|
You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things:
|
||||||
|
|
||||||
|
|
||||||
|
a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.)
|
||||||
|
b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with.
|
||||||
|
c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution.
|
||||||
|
d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place.
|
||||||
|
e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy.
|
||||||
|
For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
|
||||||
|
|
||||||
|
It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute.
|
||||||
|
|
||||||
|
7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things:
|
||||||
|
|
||||||
|
|
||||||
|
a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above.
|
||||||
|
b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work.
|
||||||
|
8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
|
||||||
|
|
||||||
|
9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it.
|
||||||
|
|
||||||
|
10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library.
|
||||||
|
|
||||||
|
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances.
|
||||||
|
|
||||||
|
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
|
||||||
|
|
||||||
|
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
|
||||||
|
|
||||||
|
12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
|
||||||
|
|
||||||
|
13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation.
|
||||||
|
|
||||||
|
14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
|
||||||
|
|
||||||
|
NO WARRANTY
|
||||||
|
|
||||||
|
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
356
lib/akismet.class.php
Normal file
356
lib/akismet.class.php
Normal file
|
@ -0,0 +1,356 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* 01.26.2006 12:29:28est
|
||||||
|
*
|
||||||
|
* Akismet PHP4 class
|
||||||
|
*
|
||||||
|
* <b>Usage</b>
|
||||||
|
* <code>
|
||||||
|
* $comment = array(
|
||||||
|
* 'author' => 'viagra-test-123',
|
||||||
|
* 'email' => 'test@example.com',
|
||||||
|
* 'website' => 'http://www.example.com/',
|
||||||
|
* 'body' => 'This is a test comment',
|
||||||
|
* 'permalink' => 'http://yourdomain.com/yourblogpost.url',
|
||||||
|
* );
|
||||||
|
*
|
||||||
|
* $akismet = new Akismet('http://www.yourdomain.com/', 'YOUR_WORDPRESS_API_KEY', $comment);
|
||||||
|
*
|
||||||
|
* if($akismet->isError()) {
|
||||||
|
* echo"Couldn't connected to Akismet server!";
|
||||||
|
* } else {
|
||||||
|
* if($akismet->isSpam()) {
|
||||||
|
* echo"Spam detected";
|
||||||
|
* } else {
|
||||||
|
* echo"yay, no spam!";
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* @author Bret Kuhns {@link www.miphp.net}
|
||||||
|
* @link http://www.miphp.net/blog/view/php4_akismet_class/
|
||||||
|
* @version 0.3.3
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Error constants
|
||||||
|
define("AKISMET_SERVER_NOT_FOUND", 0);
|
||||||
|
define("AKISMET_RESPONSE_FAILED", 1);
|
||||||
|
define("AKISMET_INVALID_KEY", 2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Base class to assist in error handling between Akismet classes
|
||||||
|
class AkismetObject {
|
||||||
|
var $errors = array();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a new error to the errors array in the object
|
||||||
|
*
|
||||||
|
* @param String $name A name (array key) for the error
|
||||||
|
* @param String $string The error message
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
// Set an error in the object
|
||||||
|
function setError($name, $message) {
|
||||||
|
$this->errors[$name] = $message;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a specific error message from the errors array
|
||||||
|
*
|
||||||
|
* @param String $name The name of the error you want
|
||||||
|
* @return mixed Returns a String if the error exists, a false boolean if it does not exist
|
||||||
|
*/
|
||||||
|
function getError($name) {
|
||||||
|
if($this->isError($name)) {
|
||||||
|
return $this->errors[$name];
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all errors in the object
|
||||||
|
*
|
||||||
|
* @return String[]
|
||||||
|
*/
|
||||||
|
function getErrors() {
|
||||||
|
return (array)$this->errors;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a certain error exists
|
||||||
|
*
|
||||||
|
* @param String $name The name of the error you want
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
function isError($name) {
|
||||||
|
return isset($this->errors[$name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if any errors exist
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
function errorsExist() {
|
||||||
|
return (count($this->errors) > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Used by the Akismet class to communicate with the Akismet service
|
||||||
|
class AkismetHttpClient extends AkismetObject {
|
||||||
|
var $akismetVersion = '1.1';
|
||||||
|
var $con;
|
||||||
|
var $host;
|
||||||
|
var $port;
|
||||||
|
var $apiKey;
|
||||||
|
var $blogUrl;
|
||||||
|
var $errors = array();
|
||||||
|
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
function AkismetHttpClient($host, $blogUrl, $apiKey, $port = 80) {
|
||||||
|
$this->host = $host;
|
||||||
|
$this->port = $port;
|
||||||
|
$this->blogUrl = $blogUrl;
|
||||||
|
$this->apiKey = $apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Use the connection active in $con to get a response from the server and return that response
|
||||||
|
function getResponse($request, $path, $type = "post", $responseLength = 1160) {
|
||||||
|
$this->_connect();
|
||||||
|
|
||||||
|
if($this->con && !$this->isError(AKISMET_SERVER_NOT_FOUND)) {
|
||||||
|
$request =
|
||||||
|
strToUpper($type)." /{$this->akismetVersion}/$path HTTP/1.1\r\n" .
|
||||||
|
"Host: ".((!empty($this->apiKey)) ? $this->apiKey."." : null)."{$this->host}\r\n" .
|
||||||
|
"Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n" .
|
||||||
|
"Content-Length: ".strlen($request)."\r\n" .
|
||||||
|
"User-Agent: Akismet PHP4 Class\r\n" .
|
||||||
|
"\r\n" .
|
||||||
|
$request
|
||||||
|
;
|
||||||
|
$response = "";
|
||||||
|
|
||||||
|
@fwrite($this->con, $request);
|
||||||
|
|
||||||
|
while(!feof($this->con)) {
|
||||||
|
$response .= @fgets($this->con, $responseLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = explode("\r\n\r\n", $response, 2);
|
||||||
|
return $response[1];
|
||||||
|
} else {
|
||||||
|
$this->setError(AKISMET_RESPONSE_FAILED, "The response could not be retrieved.");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->_disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Connect to the Akismet server and store that connection in the instance variable $con
|
||||||
|
function _connect() {
|
||||||
|
if(!($this->con = @fsockopen($this->host, $this->port))) {
|
||||||
|
$this->setError(AKISMET_SERVER_NOT_FOUND, "Could not connect to akismet server.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Close the connection to the Akismet server
|
||||||
|
function _disconnect() {
|
||||||
|
@fclose($this->con);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// The controlling class. This is the ONLY class the user should instantiate in
|
||||||
|
// order to use the Akismet service!
|
||||||
|
class Akismet extends AkismetObject {
|
||||||
|
var $apiPort = 80;
|
||||||
|
var $akismetServer = 'rest.akismet.com';
|
||||||
|
var $akismetVersion = '1.1';
|
||||||
|
var $http;
|
||||||
|
|
||||||
|
var $ignore = array(
|
||||||
|
'HTTP_COOKIE',
|
||||||
|
'HTTP_X_FORWARDED_FOR',
|
||||||
|
'HTTP_X_FORWARDED_HOST',
|
||||||
|
'HTTP_MAX_FORWARDS',
|
||||||
|
'HTTP_X_FORWARDED_SERVER',
|
||||||
|
'REDIRECT_STATUS',
|
||||||
|
'SERVER_PORT',
|
||||||
|
'PATH',
|
||||||
|
'DOCUMENT_ROOT',
|
||||||
|
'SERVER_ADMIN',
|
||||||
|
'QUERY_STRING',
|
||||||
|
'PHP_SELF'
|
||||||
|
);
|
||||||
|
|
||||||
|
var $blogUrl = "";
|
||||||
|
var $apiKey = "";
|
||||||
|
var $comment = array();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* Set instance variables, connect to Akismet, and check API key
|
||||||
|
*
|
||||||
|
* @param String $blogUrl The URL to your own blog
|
||||||
|
* @param String $apiKey Your wordpress API key
|
||||||
|
* @param String[] $comment A formatted comment array to be examined by the Akismet service
|
||||||
|
*/
|
||||||
|
function Akismet($blogUrl, $apiKey, $comment) {
|
||||||
|
$this->blogUrl = $blogUrl;
|
||||||
|
$this->apiKey = $apiKey;
|
||||||
|
|
||||||
|
// Populate the comment array with information needed by Akismet
|
||||||
|
$this->comment = $comment;
|
||||||
|
$this->_formatCommentArray();
|
||||||
|
|
||||||
|
if(!isset($this->comment['user_ip'])) {
|
||||||
|
$this->comment['user_ip'] = ($_SERVER['REMOTE_ADDR'] != getenv('SERVER_ADDR')) ? $_SERVER['REMOTE_ADDR'] : getenv('HTTP_X_FORWARDED_FOR');
|
||||||
|
}
|
||||||
|
if(!isset($this->comment['user_agent'])) {
|
||||||
|
$this->comment['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
|
||||||
|
}
|
||||||
|
if(!isset($this->comment['referrer'])) {
|
||||||
|
$this->comment['referrer'] = $_SERVER['HTTP_REFERER'];
|
||||||
|
}
|
||||||
|
$this->comment['blog'] = $blogUrl;
|
||||||
|
|
||||||
|
// Connect to the Akismet server and populate errors if they exist
|
||||||
|
$this->http = new AkismetHttpClient($this->akismetServer, $blogUrl, $apiKey);
|
||||||
|
if($this->http->errorsExist()) {
|
||||||
|
$this->errors = array_merge($this->errors, $this->http->getErrors());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the API key is valid
|
||||||
|
if(!$this->_isValidApiKey($apiKey)) {
|
||||||
|
$this->setError(AKISMET_INVALID_KEY, "Your Akismet API key is not valid.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query the Akismet and determine if the comment is spam or not
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
function isSpam() {
|
||||||
|
$response = $this->http->getResponse($this->_getQueryString(), 'comment-check');
|
||||||
|
|
||||||
|
return ($response == "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Submit this comment as an unchecked spam to the Akismet server
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function submitSpam() {
|
||||||
|
$this->http->getResponse($this->_getQueryString(), 'submit-spam');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Submit a false-positive comment as "ham" to the Akismet server
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function submitHam() {
|
||||||
|
$this->http->getResponse($this->_getQueryString(), 'submit-ham');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check with the Akismet server to determine if the API key is valid
|
||||||
|
*
|
||||||
|
* @access Protected
|
||||||
|
* @param String $key The Wordpress API key passed from the constructor argument
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
function _isValidApiKey($key) {
|
||||||
|
$keyCheck = $this->http->getResponse("key=".$this->apiKey."&blog=".$this->blogUrl, 'verify-key');
|
||||||
|
|
||||||
|
return ($keyCheck == "valid");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format the comment array in accordance to the Akismet API
|
||||||
|
*
|
||||||
|
* @access Protected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function _formatCommentArray() {
|
||||||
|
$format = array(
|
||||||
|
'type' => 'comment_type',
|
||||||
|
'author' => 'comment_author',
|
||||||
|
'email' => 'comment_author_email',
|
||||||
|
'website' => 'comment_author_url',
|
||||||
|
'body' => 'comment_content'
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach($format as $short => $long) {
|
||||||
|
if(isset($this->comment[$short])) {
|
||||||
|
$this->comment[$long] = $this->comment[$short];
|
||||||
|
unset($this->comment[$short]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a query string for use with HTTP requests
|
||||||
|
*
|
||||||
|
* @access Protected
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
function _getQueryString() {
|
||||||
|
foreach($_SERVER as $key => $value) {
|
||||||
|
if(!in_array($key, $this->ignore)) {
|
||||||
|
if($key == 'REMOTE_ADDR') {
|
||||||
|
$this->comment[$key] = $this->comment['user_ip'];
|
||||||
|
} else {
|
||||||
|
$this->comment[$key] = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$query_string = '';
|
||||||
|
|
||||||
|
foreach($this->comment as $key => $data) {
|
||||||
|
if(is_string($data)) {
|
||||||
|
$query_string .= $key . '=' . urlencode(stripslashes($data)) . '&';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
67
scripts/libshish.js
Normal file
67
scripts/libshish.js
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
function addEvent(obj, event, func, capture){
|
||||||
|
if (obj.addEventListener){
|
||||||
|
obj.addEventListener(event, func, capture);
|
||||||
|
} else if (obj.attachEvent){
|
||||||
|
obj.attachEvent("on"+event, func);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function byId(id) {
|
||||||
|
return document.getElementById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function getHTTPObject() {
|
||||||
|
if (window.XMLHttpRequest){
|
||||||
|
return new XMLHttpRequest();
|
||||||
|
}
|
||||||
|
else if(window.ActiveXObject){
|
||||||
|
return new ActiveXObject("Microsoft.XMLHTTP");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function ajaxRequest(url, callback) {
|
||||||
|
var http = getHTTPObject();
|
||||||
|
http.open("GET", url, true);
|
||||||
|
http.onreadystatechange = function() {
|
||||||
|
if(http.readyState == 4) callback(http.responseText);
|
||||||
|
}
|
||||||
|
http.send(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* get, set, and delete cookies */
|
||||||
|
function getCookie( name ) {
|
||||||
|
var start = document.cookie.indexOf( name + "=" );
|
||||||
|
var len = start + name.length + 1;
|
||||||
|
if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if ( start == -1 ) return null;
|
||||||
|
var end = document.cookie.indexOf( ";", len );
|
||||||
|
if ( end == -1 ) end = document.cookie.length;
|
||||||
|
return unescape( document.cookie.substring( len, end ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
function setCookie( name, value, expires, path, domain, secure ) {
|
||||||
|
var today = new Date();
|
||||||
|
today.setTime( today.getTime() );
|
||||||
|
if ( expires ) {
|
||||||
|
expires = expires * 1000 * 60 * 60 * 24;
|
||||||
|
}
|
||||||
|
var expires_date = new Date( today.getTime() + (expires) );
|
||||||
|
document.cookie = name+"="+escape( value ) +
|
||||||
|
( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
|
||||||
|
( ( path ) ? ";path=" + path : "" ) +
|
||||||
|
( ( domain ) ? ";domain=" + domain : "" ) +
|
||||||
|
( ( secure ) ? ";secure" : "" );
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteCookie( name, path, domain ) {
|
||||||
|
if ( getCookie( name ) ) document.cookie = name + "=" +
|
||||||
|
( ( path ) ? ";path=" + path : "") +
|
||||||
|
( ( domain ) ? ";domain=" + domain : "" ) +
|
||||||
|
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
|
||||||
|
}
|
||||||
|
|
131
scripts/shimmie.js
Normal file
131
scripts/shimmie.js
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
var defaultTexts = new Array();
|
||||||
|
|
||||||
|
window.onload = function(e) {
|
||||||
|
var sections=get_sections();
|
||||||
|
for(var i=0;i<sections.length;i++) toggle(sections[i]);
|
||||||
|
|
||||||
|
// initAjax("searchBox", "search_completions");
|
||||||
|
// initAjax("tagBox", "upload_completions");
|
||||||
|
initGray("search_input", "Search");
|
||||||
|
initGray("commentBox", "Comment");
|
||||||
|
initGray("tagBox", "tagme");
|
||||||
|
|
||||||
|
// if we're going to show with JS, hide with JS first
|
||||||
|
pass_confirm = byId("pass_confirm");
|
||||||
|
if(pass_confirm) {
|
||||||
|
pass_confirm.style.display = "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function endWord(sentance) {
|
||||||
|
words = sentance.split(" ");
|
||||||
|
return words[words.length-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
var resultCache = new Array();
|
||||||
|
resultCache[""] = new Array();
|
||||||
|
|
||||||
|
function complete(boxname, text) {
|
||||||
|
box = byId(boxname);
|
||||||
|
words = box.value.split(" ");
|
||||||
|
box.value = "";
|
||||||
|
for(n=0; n<words.length-1; n++) {
|
||||||
|
box.value += words[n]+" ";
|
||||||
|
}
|
||||||
|
box.value += text+" ";
|
||||||
|
box.focus();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fillCompletionZone(boxname, areaname, results) {
|
||||||
|
byId(areaname).innerHTML = "";
|
||||||
|
for(i=0; i<results.length; i++) {
|
||||||
|
byId(areaname).innerHTML += "<br><a href=\"#\" onclick=\"complete('"+boxname+"', '"+results[i]+"');\">"+results[i]+"</a>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function initAjax(boxname, areaname) {
|
||||||
|
var box = byId(boxname);
|
||||||
|
if(!box) return;
|
||||||
|
|
||||||
|
addEvent(
|
||||||
|
box,
|
||||||
|
"keyup",
|
||||||
|
function f() {
|
||||||
|
starter = endWord(box.value);
|
||||||
|
|
||||||
|
if(resultCache[starter]) {
|
||||||
|
fillCompletionZone(boxname, areaname, resultCache[starter]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ajaxRequest(
|
||||||
|
"ajax.php?start="+starter,
|
||||||
|
function g(text) {
|
||||||
|
resultCache[starter] = text.split("\n");
|
||||||
|
fillCompletionZone(boxname, areaname, resultCache[starter]);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function initGray(boxname, text) {
|
||||||
|
var box = byId(boxname);
|
||||||
|
if(!box) return;
|
||||||
|
|
||||||
|
addEvent(box, "focus", function f() {cleargray(box, text);}, false);
|
||||||
|
addEvent(box, "blur", function f() {setgray(box, text);}, false);
|
||||||
|
|
||||||
|
if(box.value == text) {
|
||||||
|
box.style.color = "#999";
|
||||||
|
box.style.textAlign = "center";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
box.style.color = "#000";
|
||||||
|
box.style.textAlign = "left";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function cleargray(box, text) {
|
||||||
|
if(box.value == text) {
|
||||||
|
box.value = "";
|
||||||
|
box.style.color = "#000";
|
||||||
|
box.style.textAlign = "left";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function setgray(box, text) {
|
||||||
|
if(box.value == "") {
|
||||||
|
box.style.textAlign = "center";
|
||||||
|
box.style.color = "gray";
|
||||||
|
box.value = text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showUp(elem) {
|
||||||
|
e = document.getElementById(elem)
|
||||||
|
if(!e) return;
|
||||||
|
e.style.display = "";
|
||||||
|
// alert(e.type+": "+e.value);
|
||||||
|
if(e.value.match(/^http|^ftp/)) {
|
||||||
|
e.type = "text";
|
||||||
|
alert("Box is web upload");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function check_int(box, min, max) {
|
||||||
|
check(box, (box.value >= min && box.value <= max));
|
||||||
|
}
|
||||||
|
|
||||||
|
function check(box, bool) {
|
||||||
|
if(bool) {
|
||||||
|
box.style.background = "#AFA";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
box.style.background = "#FAA";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
99
themes/default/default.php
Normal file
99
themes/default/default.php
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
<?
|
||||||
|
global $config;
|
||||||
|
$base_href = $config->get_string('base_href');
|
||||||
|
$data_href = $config->get_string('data_href');
|
||||||
|
$contact_link = $config->get_string('contact_link');
|
||||||
|
|
||||||
|
function block_to_html($block) {
|
||||||
|
$h = $block->header;
|
||||||
|
$b = $block->body;
|
||||||
|
$i = str_replace(' ', '_', $h);
|
||||||
|
$html = "";
|
||||||
|
if(!is_null($h)) $html .= "\n<h3 id='$i-toggle' onclick=\"toggle('$i')\">$h</h3>\n";
|
||||||
|
if(!is_null($b)) $html .= "<div id='$i'>$b</div>\n";
|
||||||
|
return $html;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sideblock_html = "";
|
||||||
|
foreach($this->sideblocks as $block) {
|
||||||
|
$sideblock_html .= block_to_html($block);
|
||||||
|
}
|
||||||
|
|
||||||
|
$mainblock_html = "";
|
||||||
|
foreach($this->mainblocks as $block) {
|
||||||
|
$mainblock_html .= block_to_html($block);
|
||||||
|
}
|
||||||
|
|
||||||
|
$scripts = glob("scripts/*.js");
|
||||||
|
$script_html = "";
|
||||||
|
foreach($scripts as $script) {
|
||||||
|
$script_html .= "\t\t<script src='$data_href/$script' type='text/javascript'></script>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if($config->get_bool('debug_enabled')) {
|
||||||
|
if(function_exists('memory_get_usage')) {
|
||||||
|
$i_mem = sprintf("%5.2f", ((memory_get_usage()+512)/1024)/1024);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$i_mem = "???";
|
||||||
|
}
|
||||||
|
if(function_exists('getrusage')) {
|
||||||
|
$ru = getrusage();
|
||||||
|
$i_utime = sprintf("%5.2f", ($ru["ru_utime.tv_sec"]*1e6+$ru["ru_utime.tv_usec"])/1000000);
|
||||||
|
$i_stime = sprintf("%5.2f", ($ru["ru_stime.tv_sec"]*1e6+$ru["ru_stime.tv_usec"])/1000000);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$i_utime = "???";
|
||||||
|
$i_stime = "???";
|
||||||
|
}
|
||||||
|
$i_files = count(get_included_files());
|
||||||
|
global $_execs;
|
||||||
|
$debug = "<br>Took $i_utime + $i_stime seconds and {$i_mem}MB of RAM";
|
||||||
|
$debug .= "; Used $i_files files and $_execs queries";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$debug = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
global $config;
|
||||||
|
$version = $config->get_string('version');
|
||||||
|
|
||||||
|
$contact = empty($contact_link) ? "" : "<br><a href='$contact_link'>Contact</a>";
|
||||||
|
|
||||||
|
if(empty($this->subheading)) {
|
||||||
|
$subheading = "";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$subheading = "<div id='subtitle'>{$this->subheading}</div>";
|
||||||
|
}
|
||||||
|
|
||||||
|
print <<<EOD
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>{$this->title}</title>
|
||||||
|
<link rel="stylesheet" href="$data_href/themes/default/style.css" type="text/css">
|
||||||
|
<script src='$data_href/themes/default/sidebar.js' type='text/javascript'></script>
|
||||||
|
$script_html
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>{$this->heading}</h1>
|
||||||
|
$subheading
|
||||||
|
|
||||||
|
<div id="nav">$sideblock_html</div>
|
||||||
|
<div id="body">$mainblock_html</div>
|
||||||
|
|
||||||
|
<div id="footer">
|
||||||
|
<hr>
|
||||||
|
Images © their respective owners,
|
||||||
|
<a href="http://trac.shishnet.org/shimmie2/">$version</a> ©
|
||||||
|
<a href="http://www.shishnet.org/">Shish</a> 2007,
|
||||||
|
based on the <a href="http://trac.shishnet.org/shimmie2/wiki/DanbooruRipoff">Danbooru</a> concept.
|
||||||
|
$debug
|
||||||
|
$contact
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
EOD;
|
||||||
|
?>
|
83
themes/default/sidebar.js
Normal file
83
themes/default/sidebar.js
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
/*
|
||||||
|
* This script shamelessly stolen from wakachan.org d(^_^)b
|
||||||
|
*/
|
||||||
|
|
||||||
|
var cookie_name="shimmie_sidebar";
|
||||||
|
var default_sections=["upload", "edit_tags"];
|
||||||
|
|
||||||
|
function toggle(id)
|
||||||
|
{
|
||||||
|
var e=document.getElementById(id);
|
||||||
|
if(!e) return;
|
||||||
|
if(e.style.display)
|
||||||
|
{
|
||||||
|
remove_section(id);
|
||||||
|
e.style.display="";
|
||||||
|
|
||||||
|
var e2 = document.getElementById(id+"-toggle");
|
||||||
|
if(e2) {
|
||||||
|
e2.style.color = "#000";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
add_section(id);
|
||||||
|
e.style.display="none";
|
||||||
|
|
||||||
|
var e2 = document.getElementById(id+"-toggle");
|
||||||
|
if(e2) {
|
||||||
|
e2.style.color = "#AAA";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function add_section(id)
|
||||||
|
{
|
||||||
|
var sections=get_sections();
|
||||||
|
for(var i=0;i<sections.length;i++) if(sections[i]==id) return;
|
||||||
|
sections.push(id);
|
||||||
|
set_sections(sections);
|
||||||
|
}
|
||||||
|
|
||||||
|
function remove_section(id)
|
||||||
|
{
|
||||||
|
var sections=get_sections();
|
||||||
|
var new_sections=new Array();
|
||||||
|
for(var i=0;i<sections.length;i++) if(sections[i]!=id) new_sections.push(sections[i]);
|
||||||
|
set_sections(new_sections);
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_sections()
|
||||||
|
{
|
||||||
|
var cookie=get_cookie(cookie_name);
|
||||||
|
if(cookie) return cookie.split(/,/);
|
||||||
|
else return default_sections;
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_sections(sections) { set_cookie(cookie_name,sections.join(","),365); }
|
||||||
|
|
||||||
|
function get_cookie(name)
|
||||||
|
{
|
||||||
|
with(document.cookie)
|
||||||
|
{
|
||||||
|
var index=indexOf(name+"=");
|
||||||
|
if(index==-1) return '';
|
||||||
|
index=indexOf("=",index)+1;
|
||||||
|
var endstr=indexOf(";",index);
|
||||||
|
if(endstr==-1) endstr=length;
|
||||||
|
return unescape(substring(index,endstr));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function set_cookie(name,value,days)
|
||||||
|
{
|
||||||
|
if(days)
|
||||||
|
{
|
||||||
|
var date=new Date();
|
||||||
|
date.setTime(date.getTime()+(days*24*60*60*1000));
|
||||||
|
var expires="; expires="+date.toGMTString();
|
||||||
|
}
|
||||||
|
else expires="";
|
||||||
|
document.cookie=name+"="+value+expires+"; path=/";
|
||||||
|
}
|
||||||
|
|
146
themes/default/style.css
Normal file
146
themes/default/style.css
Normal file
|
@ -0,0 +1,146 @@
|
||||||
|
|
||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* things common to all pages *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
BODY {
|
||||||
|
background: #EEE;
|
||||||
|
font-family: "Arial", sans-serif;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
H1, H3 {
|
||||||
|
border: 1px solid black;
|
||||||
|
background: #DDD;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
H1 {
|
||||||
|
margin-top: 0px;
|
||||||
|
margin-bottom: 0px;
|
||||||
|
padding: 2px;
|
||||||
|
}
|
||||||
|
H1 A {
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
H3 {
|
||||||
|
margin-top: 32px;
|
||||||
|
padding: 1px;
|
||||||
|
}
|
||||||
|
THEAD {
|
||||||
|
background: #DEDEDE;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
TD {
|
||||||
|
vertical-align: top;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
#subtitle {
|
||||||
|
width: 256px;
|
||||||
|
font-size: 0.75em;
|
||||||
|
margin: auto;
|
||||||
|
text-align: center;
|
||||||
|
border: 1px solid black;
|
||||||
|
border-top: none;
|
||||||
|
background: #DDD;
|
||||||
|
}
|
||||||
|
#body SELECT {width: 150px;}
|
||||||
|
/*
|
||||||
|
TD INPUT {width: 100%;}
|
||||||
|
TD SELECT {width: 100%;}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#footer {
|
||||||
|
clear: both;
|
||||||
|
padding-top: 8px;
|
||||||
|
font-size: 0.7em;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
*[onclick] {cursor: pointer;}
|
||||||
|
IMG {border: none;}
|
||||||
|
FORM {margin: 0px;}
|
||||||
|
A {text-decoration: none;}
|
||||||
|
A:hover {text-decoration: underline;}
|
||||||
|
|
||||||
|
|
||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* the navigation bar, and all it's blocks *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#nav {
|
||||||
|
width: 150px;
|
||||||
|
float: left;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 0.9em;
|
||||||
|
}
|
||||||
|
#nav TABLE {
|
||||||
|
width: 150px;
|
||||||
|
}
|
||||||
|
#nav TD {
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
#nav INPUT {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0px;
|
||||||
|
}
|
||||||
|
#nav SELECT {
|
||||||
|
width: 100%;
|
||||||
|
padding: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#comments P {
|
||||||
|
text-align: left;
|
||||||
|
width: 150px;
|
||||||
|
max-width: 150px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* the main part of each page *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#body {
|
||||||
|
margin-left: 160px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
#body TABLE {
|
||||||
|
width: 90%;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
|
* specific page types *
|
||||||
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
|
#pagelist {
|
||||||
|
margin-top: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#tagmap A {
|
||||||
|
padding: 8px 4px 8px 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#image_comments {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.setupblock {
|
||||||
|
border: 1px solid #AAA;
|
||||||
|
padding: 8px;
|
||||||
|
margin: 16px;
|
||||||
|
width: 350px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.helpable {
|
||||||
|
border-bottom: 1px dashed gray;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ok {
|
||||||
|
background: #AFA;
|
||||||
|
}
|
||||||
|
.bad {
|
||||||
|
background: #FAA;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue