Compare commits

...

31 Commits

Author SHA1 Message Date
Shish
c1c3fbc241 more things 2008-12-14 15:17:55 -08:00
Shish
d4efdc4f6b ignorance is bliss 2008-12-14 15:16:05 -08:00
shish
b03869c59d let's fix 2.0 while we're at it...
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@873 7f39781d-f577-437e-ae19-be835c7a54ca
2008-05-20 03:15:29 +00:00
shish
9898df3e11 backport PHP bu workaround to stable
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@248 7f39781d-f577-437e-ae19-be835c7a54ca
2007-07-08 21:56:50 +00:00
shish
467bb635c4 limit for next / prev search
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@222 7f39781d-f577-437e-ae19-be835c7a54ca
2007-07-05 18:08:05 +00:00
shish
eccd9f590a tag query optimisation, now made simple, because mysql is speshal
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@218 7f39781d-f577-437e-ae19-be835c7a54ca
2007-07-04 15:53:44 +00:00
shish
7fb5b5973f fix single-tag + metadata search
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@215 7f39781d-f577-437e-ae19-be835c7a54ca
2007-07-04 01:22:26 +00:00
shish
8a99bf5e53 fix
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@212 7f39781d-f577-437e-ae19-be835c7a54ca
2007-07-04 01:06:27 +00:00
shish
c3fa6a605c common case optimisation
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@211 7f39781d-f577-437e-ae19-be835c7a54ca
2007-07-04 01:05:54 +00:00
shish
ff7796e670 force thumbnails to be jpeg
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@208 7f39781d-f577-437e-ae19-be835c7a54ca
2007-07-01 18:19:22 +00:00
shish
77e21ad011 pull safe mode check into stable
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@122 7f39781d-f577-437e-ae19-be835c7a54ca
2007-05-18 16:47:41 +00:00
shish
a71485fec8 IM detection is small and handy
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@106 7f39781d-f577-437e-ae19-be835c7a54ca
2007-05-17 01:11:04 +00:00
shish
a8e619b6a2 pull mysql 4.0.X compat stuff from trunk
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@104 7f39781d-f577-437e-ae19-be835c7a54ca
2007-05-16 23:51:57 +00:00
shish
657d607a9d README updated for 2.0.2
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@72 7f39781d-f577-437e-ae19-be835c7a54ca
2007-05-07 13:23:08 +00:00
shish
30c9e4a589 merge 'remove rss from index' changeset
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@71 7f39781d-f577-437e-ae19-be835c7a54ca
2007-05-07 13:19:27 +00:00
shish
43418fd287 default to allowing anon tag editing
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@57 7f39781d-f577-437e-ae19-be835c7a54ca
2007-05-04 21:57:58 +00:00
shish
6a4a79edda no way to disable anon tag editing: fixed
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@56 7f39781d-f577-437e-ae19-be835c7a54ca
2007-05-04 21:55:54 +00:00
shish
cb7e84a346 pull fix for invalid page numbers
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@48 7f39781d-f577-437e-ae19-be835c7a54ca
2007-05-01 13:14:12 +00:00
shish
187de18322 heading support brought to stable, for people who want to pull the rss_images extension from unstable svn
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@46 7f39781d-f577-437e-ae19-be835c7a54ca
2007-05-01 12:44:30 +00:00
shish
0d788d9d61 remove old search code
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@28 7f39781d-f577-437e-ae19-be835c7a54ca
2007-04-28 18:40:50 +00:00
shish
a090d45ce0 minor tweak to search SQL, huge speedup in several cases
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@26 7f39781d-f577-437e-ae19-be835c7a54ca
2007-04-28 16:56:39 +00:00
shish
e0e774a420 use set_x_from_post
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@25 7f39781d-f577-437e-ae19-be835c7a54ca
2007-04-28 15:52:09 +00:00
shish
605a8c206e removed disabled, unstable bits from the stable branch
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@22 7f39781d-f577-437e-ae19-be835c7a54ca
2007-04-27 18:52:55 +00:00
shish
5d6927c975 README updated for 2.0.1
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@21 7f39781d-f577-437e-ae19-be835c7a54ca
2007-04-27 18:49:00 +00:00
shish
ab42847cf8 be more strict about allowed comparisons
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@20 7f39781d-f577-437e-ae19-be835c7a54ca
2007-04-27 18:15:11 +00:00
shish
8d44a83fad search to sql redone, removes an ugly error when search things were incomplete
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@18 7f39781d-f577-437e-ae19-be835c7a54ca
2007-04-27 18:09:55 +00:00
shish
f056d31e26 short tag opening caused problems for people with short tags disabled
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@12 7f39781d-f577-437e-ae19-be835c7a54ca
2007-04-25 16:57:43 +00:00
shish
3914c99d08 remove a bit of code duplication
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@10 7f39781d-f577-437e-ae19-be835c7a54ca
2007-04-24 19:17:13 +00:00
shish
8c792556e6 bug when disabling anonymous comments
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@8 7f39781d-f577-437e-ae19-be835c7a54ca
2007-04-24 16:35:48 +00:00
shish
936d2ab48d merging minor updates from trunk
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@6 7f39781d-f577-437e-ae19-be835c7a54ca
2007-04-21 14:02:15 +00:00
shish
63dd7d8e54 Stabilisation branch for 2.0
git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.0@2 7f39781d-f577-437e-ae19-be835c7a54ca
2007-04-16 12:01:56 +00:00
24 changed files with 257 additions and 513 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.svn
.htaccess
config.php
images
thumbs

View File

@ -6,12 +6,22 @@
/_______ /|___| /__|__|_| /__|_| /__|\___ >_______ \
\/ \/ \/ \/ \/ \/
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...
Shimmie2 -- 2.0.X Series
~~~~~~~~~~~~~~~~~~~~~~~~
Changes in 2.0.2:
* $page->add_header() function pulled from development, as it's small,
and allows people to use development extensions (eg RSS)
* minor SQL tweak, huge speedup in several (but not all) cases
* ability to disable anonymous tag editing
* various internal fixes
Changes in 2.0.1:
* Disabling anonymous comments doesn't break things
* When Shimmie is in downtime mode, there's a big notice in the sidebar
* A short opening tag (<?) was replaced with a long one (<?php), so people
with short tags disabled no longer see random PHP code
* Metadata searching was improved (see wiki -> user guide -> searching)
* Misc minor code cleanups
Requirements
@ -54,7 +64,7 @@ Upgrade process:
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
6) Fill 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"
@ -75,4 +85,12 @@ Shish on Freenode -- IRC
Old News
~~~~~~~~
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...

View File

@ -25,6 +25,7 @@ class Config {
'view_scale' => false, # view
'tags_default' => 'map', # (ignored)
'tags_min' => '2', # tags
'tag_edit_anon' => true, # tags
'upload_count' => 3, # upload
'upload_size' => '256KB', # upload
'upload_anon' => true, # upload

View File

@ -92,41 +92,22 @@ class Database {
$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));
$matches = array();
if(preg_match("/size(<|>|<=|>=|=)(\d+)x(\d+)/", $term, $matches)) {
$cmp = $matches[1];
$args = array(int_escape($matches[2]), int_escape($matches[3]));
$img_search->append(new Querylet("AND (width $cmp ? AND height $cmp ?)", $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(preg_match("/ratio(<|>|<=|>=|=)(\d+):(\d+)/", $term, $matches)) {
$cmp = $matches[1];
$args = array(int_escape($matches[2]), int_escape($matches[3]));
$img_search->append(new Querylet("AND (width / height $cmp ? / ?)", $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 if(preg_match("/(filesize|id)(<|>|<=|>=|=)([\dKMGB]+)/i", $term, $matches)) {
$col = $matches[1];
$cmp = $matches[2];
$val = parse_shorthand_int($matches[3]);
$img_search->append(new Querylet("AND ($col $cmp $val)"));
}
else {
$term = str_replace("*", "%", $term);
@ -140,12 +121,30 @@ class Database {
$database_fails = false; // MySQL 4.0 fails at subqueries
if(count($tag_search->variables) == 0 || $database_fails) {
$query = new Querylet("SELECT * FROM images ");
if(strlen($img_search->sql) > 0) {
$query->append_sql("WHERE 1=1 ");
$query->append($img_search);
}
}
else if(count($tag_search->variables) == 1 && $positive_tag_count == 1) {
$query = new Querylet(
"SELECT *,UNIX_TIMESTAMP(posted) AS posted_timestamp FROM tags, images WHERE tag LIKE ? AND tags.image_id = images.id ",
$tag_search->variables);
if(strlen($img_search->sql) > 0) {
$query->append($img_search);
}
}
else {
$s_tag_array = array_map("sql_escape", $tag_search->variables);
$s_tag_list = join(', ', $s_tag_array);
$subquery = new Querylet("
SELECT *, SUM({$tag_search->sql}) AS score
FROM images
LEFT JOIN tags ON tags.image_id = images.id
WHERE tags.tag IN ({$s_tag_list})
GROUP BY images.id
HAVING score = ?",
array_merge(
@ -154,74 +153,16 @@ class Database {
)
);
$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);
if(strlen($img_search->sql) > 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));
}
@ -231,7 +172,7 @@ class Database {
$tags = array_map(array($this, 'resolve_alias'), $tags);
$tags = array_map(array($this, 'sanitise'), $tags);
$tags = array_unique($tags); // remove any duplicate tags
$tags = array_iunique($tags); // remove any duplicate tags
// delete old
$this->delete_tags_from_image($image_id);
@ -278,13 +219,13 @@ class Database {
}
if(count($tags) == 0) {
$row = $this->db->GetRow("SELECT * FROM images WHERE id $gtlt ? ORDER BY id $dir", array((int)$id));
$row = $this->db->GetRow("SELECT * FROM images WHERE id $gtlt ? ORDER BY id $dir LIMIT 1", 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");
$querylet->append_sql("ORDER BY id $dir LIMIT 1");
$row = $this->db->GetRow($querylet->sql, $querylet->variables);
}
@ -306,7 +247,7 @@ class Database {
}
// }}}
// users {{{
var $SELECT_USER = "SELECT *,time_to_sec(timediff(now(), joindate))/(60*60*24) AS days_old FROM users ";
var $SELECT_USER = "SELECT *,(unix_timestamp(now()) - unix_timestamp(joindate))/(60*60*24) AS days_old FROM users ";
public function get_user($a=false, $b=false) {
if($b == false) {

View File

@ -44,11 +44,11 @@ class ImageIO extends Extension {
$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']);
$event->config->set_string_from_post("thumb_engine");
$event->config->set_int_from_post("thumb_width");
$event->config->set_int_from_post("thumb_height");
$event->config->set_int_from_post("thumb_quality");
$event->config->set_int_from_post("thumb_gd_mem_limit");
}
}
// }}}
@ -94,7 +94,7 @@ class ImageIO extends Extension {
$h = $config->get_int("thumb_height");
$q = $config->get_int("thumb_quality");
exec("convert $inname -geometry {$w}x{$h} -quality {$q} $outname");
exec("convert {$inname}[0] -geometry {$w}x{$h} -quality {$q} jpg:$outname");
return true;
}
@ -106,28 +106,6 @@ class ImageIO extends Extension {
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;
@ -139,7 +117,7 @@ class ImageIO extends Extension {
$max_height = $config->get_int('thumb_height');
$memory_use = (filesize($tmpname)*2) + ($width*$height*4) + (4*1024*1024);
$memory_limit = $this->get_memory_limit();
$memory_limit = get_memory_limit();
if($memory_use > $memory_limit) {
$thumb = imagecreatetruecolor($max_width, min($max_height, 64));

View File

@ -4,57 +4,53 @@ 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();
$search_terms = array();
$page_number = 1;
if($event->count_args() > 0) {
$page_number = int_escape($event->get_arg(0));
if($page_number == 0) $page_number = 1; // invalid -> 0
}
if(isset($_GET['search'])) {
$search_terms = explode(' ', $_GET['search']);
$query = "search=".html_escape($_GET['search']);
}
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);
$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')) {
@ -72,9 +68,9 @@ class Index extends Extension {
$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']);
$event->config->set_int_from_post("index_width");
$event->config->set_int_from_post("index_height");
$event->config->set_string_from_post("image_tip");
}
}
// }}}
@ -137,11 +133,6 @@ class Index extends Extension {
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());
?>

View File

@ -138,12 +138,12 @@ class Setup extends Extension {
$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']);
$event->config->set_string_from_post("title");
$event->config->set_string_from_post("base_href");
$event->config->set_string_from_post("data_href");
$event->config->set_string_from_post("contact_link");
$event->config->set_string_from_post("theme");
$event->config->set_int_from_post("anon_id");
}
}
// }}}

View File

@ -3,15 +3,23 @@
class TagEdit extends Extension {
// event handling {{{
public function receive_event($event) {
if(is_a($event, 'PageRequestEvent') && ($event->page == "tags")) {
if(is_a($event, 'PageRequestEvent') && ($event->page == "tag_edit")) {
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));
if($this->can_tag()) {
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 {
$page->set_title("Tag Edit Denied");
$page->set_heading("Tag Edit Denied");
$page->add_side_block(new NavBlock());
$page->add_main_block(new Block("Error", "Anonymous tag editing is disabled"));
}
}
else if($event->get_arg(0) == "replace") {
global $user;
@ -48,6 +56,22 @@ class TagEdit extends Extension {
if(is_a($event, 'AddAliasEvent')) {
$this->mass_tag_edit($event->oldtag, $event->newtag);
}
if(is_a($event, 'SetupBuildingEvent')) {
$sb = new SetupBlock("Tag Editing");
$sb->add_label("Allow anonymous editing: ");
$sb->add_bool_option("tag_edit_anon");
$event->panel->add_main_block($sb);
}
if(is_a($event, 'ConfigSaveEvent')) {
$event->config->set_bool_from_post("tag_edit_anon");
}
}
// }}}
// do things {{{
private function can_tag() {
global $config, $user;
return $config->get_bool("tag_edit_anon") || !$user->is_anonymous();
}
// }}}
// edit {{{
@ -72,7 +96,7 @@ class TagEdit extends Extension {
$i_image_id = int_escape($image->id);
return "
<p><form action='".make_link("tags/set")."' method='POST'>
<p><form action='".make_link("tag_edit/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'>
@ -82,7 +106,7 @@ class TagEdit extends Extension {
}
private function build_mass_tag_edit() {
return "
<form action='".make_link("tags/replace")."' method='POST'>
<form action='".make_link("tag_edit/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>

View File

@ -40,9 +40,9 @@ class Upload extends Extension {
$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']);
$event->config->set_int_from_post("upload_count");
$event->config->set_int_from_post("upload_size");
$event->config->set_bool_from_post("upload_anon");
}
}
// }}}

View File

@ -66,9 +66,9 @@ class UserPage extends Extension {
$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']);
$event->config->set_int_from_post("login_memory");
$event->config->set_bool_from_post("login_signup_enabled");
$event->config->set_string_from_post("login_tac");
}
}
// }}}

View File

@ -41,15 +41,12 @@ class ViewImage extends Extension {
$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']);
$event->config->set_string_from_post("image_ilink");
$event->config->set_string_from_post("image_slink");
$event->config->set_string_from_post("image_tlink");
}
}
// }}}

View File

@ -39,6 +39,7 @@ class Page {
var $heading = "";
var $subheading = "";
var $quicknav = "";
var $headers = array();
var $sideblocks = array();
var $mainblocks = array();
@ -54,6 +55,11 @@ class Page {
$this->subheading = $subheading;
}
public function add_header($line, $position=50) {
while(isset($this->headers[$position])) $position++;
$this->headers[$position] = $line;
}
public function add_side_block($block, $position=50) {
while(isset($this->sideblocks[$position])) $position++;
$this->sideblocks[$position] = $block;

View File

@ -65,6 +65,28 @@ function to_shorthand_int($int) {
}
}
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;
}
function bbcode2html($text) {
$text = trim($text);
$text = html_escape($text);
@ -101,8 +123,22 @@ function tag_explode($tags) {
return $tag_array;
}
// case insensetive uniqueness
function array_iunique($array) {
$ok = array();
foreach($array as $element) {
$found = false;
foreach($ok as $existing) {
if(strtolower($element) == strtolower($existing)) {
$found = true; break;
}
}
if(!$found) {
$ok[] = $element;
}
}
return $ok;
}
# $db is the connection object
@ -134,7 +170,9 @@ function add_event_listener($block, $pos=50) {
function send_event($event) {
global $_event_listeners;
foreach($_event_listeners as $listener) {
$my_event_listeners = $_event_listeners;
ksort($my_event_listeners);
foreach($my_event_listeners as $listener) {
$listener->receive_event($event);
}
}

View File

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

View File

@ -122,11 +122,11 @@ class CommentList extends Extension {
$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']);
$event->config->set_bool_from_post("comment_anon");
$event->config->set_int_from_post("comment_limit");
$event->config->set_int_from_post("comment_window");
$event->config->set_int_from_post("comment_count");
$event->config->set_string_from_post("comment_wordpress_key");
}
}
// }}}
@ -335,6 +335,7 @@ class CommentList extends Extension {
private function can_comment() {
global $config;
global $user;
return ($config->get_bool('comment_anon') || !$user->is_anonymous());
}

View File

@ -14,8 +14,16 @@ class Downtime extends Extension {
$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']);
$event->config->set_bool_from_post("downtime");
$event->config->set_string_from_post("downtime_message");
}
if(is_a($event, 'PageRequestEvent')) {
global $config;
if($config->get_bool("downtime")) {
global $page;
$page->add_side_block(new Block("Downtime", "<span style='font-size: 1.5em'><b>DOWNTIME MODE IS ON!</b></span>"), 0);
}
}
}
// }}}

View File

@ -15,7 +15,7 @@ class News extends Extension {
$event->panel->add_main_block($sb);
}
if(is_a($event, 'ConfigSaveEvent')) {
$event->config->set_string("news_text", $_POST['news_text']);
$event->config->set_string_from_post("news_text");
}
}
}

View File

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

View File

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

View File

@ -38,7 +38,7 @@ class RegenThumb extends Extension {
switch($program) {
case 'convert':
unlink($f_thumb);
exec("convert $f_image -geometry {$w}x{$h} -quality {$q} $f_thumb");
exec("convert {$f_image}[0] -geometry {$w}x{$h} -quality {$q} jpg:$f_thumb");
break;
case 'gd':
$this->make_thumb_gd($f_image, $f_thumb);
@ -83,28 +83,6 @@ class RegenThumb extends Extension {
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;
@ -116,7 +94,7 @@ class RegenThumb extends Extension {
$max_height = $config->get_int('thumb_height');
$memory_use = (filesize($tmpname)*2) + ($width*$height*4) + (4*1024*1024);
$memory_limit = $this->get_memory_limit();
$memory_limit = get_memory_limit();
if($memory_use > $memory_limit) {
$thumb = imagecreatetruecolor($max_width, min($max_height, 64));

View File

@ -54,10 +54,10 @@ class TagList extends Extension {
$event->panel->add_main_block($sb);
}
if(is_a($event, 'ConfigSaveEvent')) {
$event->config->set_int("tags_min", $_POST['tags_min']);
$event->config->set_int_from_post("tags_min");
$event->config->set_int("popular_count", $_POST['popular_count']);
$event->config->set_string("info_link", $_POST['info_link']);
$event->config->set_int_from_post("popular_count");
$event->config->set_string_from_post("info_link");
}
}
// }}}

View File

@ -14,7 +14,7 @@ class Zoom extends Extension {
$event->panel->add_main_block($sb);
}
if(is_a($event, 'ConfigSaveEvent')) {
$event->config->set_bool("image_zoom", $_POST['image_zoom']);
$event->config->set_bool_from_post("image_zoom");
}
}

View File

@ -248,6 +248,13 @@ function insert_defaults($dsn, $admin_name, $admin_pass) { // {{{
$admin_pass = md5(strtolower($admin_name).$admin_pass);
$db->Execute($user_insert, Array($admin_name, $admin_pass, 'Y'));
if(!ini_get('safe_mode')) {
$convert_check = exec("convert");
if(!empty($convert_check)) {
$db->Execute($config_insert, Array('thumb_engine', 'convert'));
}
}
$db->Close();
}

View File

@ -1,4 +1,4 @@
<?
<?php
global $config;
$base_href = $config->get_string('base_href');
$data_href = $config->get_string('data_href');
@ -14,6 +14,11 @@ function block_to_html($block) {
return $html;
}
$header_html = "";
foreach($this->headers as $line) {
$header_html .= "\t\t$line";
}
$sideblock_html = "";
foreach($this->sideblocks as $block) {
$sideblock_html .= block_to_html($block);
@ -73,6 +78,7 @@ print <<<EOD
<head>
<title>{$this->title}</title>
<link rel="stylesheet" href="$data_href/themes/default/style.css" type="text/css">
$header_html
<script src='$data_href/themes/default/sidebar.js' type='text/javascript'></script>
$script_html
</head>