more set_default

git-svn-id: file:///home/shish/svn/shimmie2/trunk@293 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2007-07-16 13:15:56 +00:00
parent b4e93df363
commit da30c88776
9 changed files with 66 additions and 40 deletions

View file

@ -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) {

View file

@ -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();
}

View file

@ -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();

View file

@ -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);

View file

@ -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")) {

View file

@ -1,14 +1,18 @@
<?php
define("UPLOAD_DEFAULT_MAX_SIZE", 256000);
define("UPLOAD_DEFAULT_COUNT", 3);
class Upload extends Extension {
var $theme;
// event handling {{{
public function receive_event($event) {
if(is_null($this->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'])." &gt; ".
($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']),

View file

@ -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 .= "<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', UPLOAD_DEFAULT_MAX_SIZE);
$max_size = $config->get_int('upload_size');
$max_kb = (int)($max_size / 1024);
// <input type='hidden' name='max_file_size' value='$max_size' />
return "

View file

@ -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"));
}

View file

@ -1,8 +1,11 @@
<?php
class ViewImage extends Extension {
var $theme;
// event handling {{{
public function receive_event($event) {
if(is_null($this->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);
}
}