From da30c88776ec9331112aa83b6f30398116309beb Mon Sep 17 00:00:00 2001 From: shish Date: Mon, 16 Jul 2007 13:15:56 +0000 Subject: [PATCH] more set_default git-svn-id: file:///home/shish/svn/shimmie2/trunk@293 7f39781d-f577-437e-ae19-be835c7a54ca --- core/config.class.php | 37 +++++++++++++++++-------------------- ext/comment/main.php | 5 +++++ ext/image/main.php | 8 ++++++++ ext/index/main.php | 7 +++++++ ext/tag_list/main.php | 5 +++-- ext/upload/main.php | 16 ++++++++++------ ext/upload/theme.php | 4 ++-- ext/user/main.php | 14 ++++++++++---- ext/view/main.php | 10 ++++------ 9 files changed, 66 insertions(+), 40 deletions(-) diff --git a/core/config.class.php b/core/config.class.php index 17c6c192..74567251 100644 --- a/core/config.class.php +++ b/core/config.class.php @@ -4,26 +4,8 @@ class Config { var $defaults = array( 'title' => 'Shimmie', # setup 'version' => 'Shimmie2-2.0.3', // internal - 'front_page' => 'index', # setup 'base_href' => './index.php?q=', # setup 'data_href' => './', # setup - 'index_width' => 3, # index - 'index_height' => 4, # index - 'index_tips' => true, - 'thumb_width' => 192, # index - 'thumb_height' => 192, # index - 'thumb_quality' => 75, # index - 'thumb_mem_limit' => '8MB', # upload - '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://en.wikipedia.org/wiki/$tag', # popular - 'login_signup_enabled' => true, # user 'image_ilink' => '$base/image/$id.$ext', # view 'image_slink' => '', # view 'image_tlink' => '$base/thumb/$id.jpg', # view @@ -66,11 +48,22 @@ class Config { $this->values[$name] = (($value == 'on' || $value === true) ? 'Y' : 'N'); $this->save($name); } - public function set_default($name, $value) { + + public function set_default_int($name, $value) { + if(is_null($this->get($name))) { + $this->values[$name] = parse_shorthand_int($value); + } + } + public function set_default_string($name, $value) { if(is_null($this->get($name))) { $this->values[$name] = $value; } } + public function set_default_bool($name, $value) { + if(is_null($this->get($name))) { + $this->values[$name] = (($value == 'on' || $value === true) ? 'Y' : 'N'); + } + } public function get_int($name, $default=null) { // deprecated -- ints should be stored as ints now @@ -81,7 +74,11 @@ class Config { } public function get_bool($name, $default=null) { // deprecated -- bools should be stored as Y/N now - return ($this->get($name, $default) == 'Y' || $this->get($name, $default) == '1'); + return ( + $this->get($name, $default) == 'Y' || + $this->get($name, $default) == '1' || + $this->get($name, $default) === true + ); } private function get($name, $default=null) { diff --git a/ext/comment/main.php b/ext/comment/main.php index b92e37b7..8871b565 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -59,6 +59,11 @@ class CommentList extends Extension { if(is_a($event, 'InitExtEvent')) { global $config; + $config->set_default_bool('comment_anon', true); + $config->set_default_int('comment_window', 5); + $config->set_default_int('comment_limit', 3); + $config->set_default_int('comment_count', 5); + if($config->get_int("ext_comments_version") < 1) { $this->install(); } diff --git a/ext/image/main.php b/ext/image/main.php index 5dbfc6d3..03df47e4 100644 --- a/ext/image/main.php +++ b/ext/image/main.php @@ -6,6 +6,14 @@ class ImageIO extends Extension { // event handling {{{ public function receive_event($event) { + if(is_a($event, 'InitExtEvent')) { + global $config; + $config->set_default_int('thumb_width', 192); + $config->set_default_int('thumb_height', 192); + $config->set_default_int('thumb_quality', 75); + $config->set_default_int('thumb_mem_limit', '8MB'); + } + if(is_a($event, 'PageRequestEvent')) { $num = $event->get_arg(0); $matches = array(); diff --git a/ext/index/main.php b/ext/index/main.php index ac87fb19..947ac310 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -6,6 +6,13 @@ class Index extends Extension { public function receive_event($event) { if(is_null($this->theme)) $this->theme = get_theme_object("index", "IndexTheme"); + if(is_a($event, 'InitExtEvent')) { + global $config; + $config->set_default_int("index_width", 3); + $config->set_default_int("index_height", 4); + $config->set_default_bool("index_tips", true); + } + if(is_a($event, 'PageRequestEvent') && (($event->page == "index") || ($event->page == "post" && $event->get_arg(0) == "list"))) { if($event->page == "post") array_shift($event->args); diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index 5cf35d44..dd371b6a 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -9,8 +9,9 @@ class TagList extends Extension { if(is_a($event, 'InitExtEvent')) { global $config; - $config->set_default("tag_list_length", 15); - $config->set_default("tags_min", 3); + $config->set_default_int("tag_list_length", 15); + $config->set_default_int("tags_min", 3); + $config->set_default_string("info_link", 'http://en.wikipedia.org/wiki/$tag'); } if(is_a($event, 'PageRequestEvent') && ($event->page == "tags")) { diff --git a/ext/upload/main.php b/ext/upload/main.php index 2e01b192..1918327b 100644 --- a/ext/upload/main.php +++ b/ext/upload/main.php @@ -1,14 +1,18 @@ theme)) $this->theme = get_theme_object("upload", "UploadTheme"); + if(is_a($event, 'InitExtEvent')) { + global $config; + $config->set_default_int('upload_count', 3); + $config->set_default_int('upload_size', '256KB'); + $config->set_default_bool('upload_anon', false); + } + if(is_a($event, 'PageRequestEvent') && ($event->page == "index")) { if($this->can_upload()) { $this->theme->display_block($event->page_object); @@ -43,7 +47,7 @@ class Upload extends Extension { // do things {{{ private function can_upload() { global $config, $user; - return $config->get_bool("upload_anon", false) || !$user->is_anonymous(); + return $config->get_bool("upload_anon") || !$user->is_anonymous(); } private function try_upload($file) { @@ -56,10 +60,10 @@ class Upload extends Extension { // this happens normally with blank file boxes $ok = true; } - else if(filesize($file['tmp_name']) > $config->get_int('upload_size', UPLOAD_DEFAULT_MAX_SIZE)) { + else if(filesize($file['tmp_name']) > $config->get_int('upload_size')) { $this->theme->display_upload_error($page, "Error with ".html_escape($file['name']), "File too large (".filesize($file['tmp_name'])." > ". - ($config->get_int('upload_size', UPLOAD_DEFAULT_MAX_SIZE)).")"); + ($config->get_int('upload_size')).")"); } else if(!($info = getimagesize($file['tmp_name']))) { $this->theme->display_upload_error($page, "Error with ".html_escape($file['name']), diff --git a/ext/upload/theme.php b/ext/upload/theme.php index 70549381..440f4cc8 100644 --- a/ext/upload/theme.php +++ b/ext/upload/theme.php @@ -25,13 +25,13 @@ class UploadTheme extends Themelet { global $config; $upload_list = ""; - for($i=0; $i<$config->get_int('upload_count', UPLOAD_DEFAULT_COUNT); $i++) { + for($i=0; $i<$config->get_int('upload_count'); $i++) { if($i == 0) $style = ""; // "style='display:visible'"; else $style = "style='display:none'"; $upload_list .= "\n"; } - $max_size = $config->get_int('upload_size', UPLOAD_DEFAULT_MAX_SIZE); + $max_size = $config->get_int('upload_size'); $max_kb = (int)($max_size / 1024); // return " diff --git a/ext/user/main.php b/ext/user/main.php index 50d1832e..7f570308 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -17,6 +17,12 @@ class UserBlockBuildingEvent extends Event { class UserPage extends Extension { // event handling {{{ public function receive_event($event) { + if(is_a($event, 'InitExtEvent')) { + global $config; + $config->set_default_bool("login_signup_enabled", true); + $config->set_default_int("login_memory", 365); + } + if(is_a($event, 'PageRequestEvent') && ($event->page == "user")) { global $page; global $user; @@ -36,7 +42,7 @@ class UserPage extends Extension { } } else if($event->get_arg(0) == "logout") { - setcookie("shm_session", "", time()+60*60*24*$config->get_int('login_memory', 365), "/"); + setcookie("shm_session", "", time()+60*60*24*$config->get_int('login_memory'), "/"); $page->set_mode("redirect"); $page->set_redirect(make_link("index")); } @@ -103,7 +109,7 @@ class UserPage extends Extension { ); setcookie( "shm_session", md5($hash.$addr), - time()+60*60*24*$config->get_int('login_memory', 365), "/" + time()+60*60*24*$config->get_int('login_memory'), "/" ); $page->set_mode("redirect"); @@ -159,7 +165,7 @@ class UserPage extends Extension { setcookie("shm_user", $name, time()+60*60*24*365, '/'); setcookie("shm_session", md5($hash.$addr), - time()+60*60*24*$config->get_int('login_memory', 365), '/'); + time()+60*60*24*$config->get_int('login_memory'), '/'); $page->set_mode("redirect"); $page->set_redirect(make_link("user")); } @@ -213,7 +219,7 @@ class UserPage extends Extension { setcookie("shm_user", $name, time()+60*60*24*365, '/'); setcookie("shm_session", md5($hash.$addr), - time()+60*60*24*$config->get_int('login_memory', 365), '/'); + time()+60*60*24*$config->get_int('login_memory'), '/'); $page->set_mode("redirect"); $page->set_redirect(make_link("user")); } diff --git a/ext/view/main.php b/ext/view/main.php index 82803597..0b31b378 100644 --- a/ext/view/main.php +++ b/ext/view/main.php @@ -1,8 +1,11 @@ theme)) $this->theme = get_theme_object("view", "ViewTheme"); + if(is_a($event, 'PageRequestEvent') && ($event->page == "post") && ($event->get_arg(0) == "view")) { $image_id = int_escape($event->get_arg(1)); @@ -13,12 +16,7 @@ class ViewImage extends Extension { send_event(new DisplayingImageEvent($image, $event->page_object)); } else { - global $page; - $page->set_title("Image not found"); - $page->set_heading("Image not found"); - $page->add_block(new NavBlock()); - $page->add_block(new Block("Image not found", - "No image in the database has the ID #$image_id")); + $this->theme->display_image_not_found($event->page_object, $image_id); } }