set_default

git-svn-id: file:///home/shish/svn/shimmie2/trunk@292 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2007-07-16 12:40:44 +00:00
parent dc23b3bdb4
commit b4e93df363
2 changed files with 16 additions and 7 deletions

View file

@ -66,6 +66,11 @@ class Config {
$this->values[$name] = (($value == 'on' || $value === true) ? 'Y' : 'N');
$this->save($name);
}
public function set_default($name, $value) {
if(is_null($this->get($name))) {
$this->values[$name] = $value;
}
}
public function get_int($name, $default=null) {
// deprecated -- ints should be stored as ints now

View file

@ -1,6 +1,4 @@
<?php
define("TAG_LIST_LENGTH", 15);
define("TAGS_MIN", 3);
class TagList extends Extension {
var $theme = null;
@ -9,6 +7,12 @@ class TagList extends Extension {
public function receive_event($event) {
if($this->theme == null) $this->theme = get_theme_object("tag_list", "TagListTheme");
if(is_a($event, 'InitExtEvent')) {
global $config;
$config->set_default("tag_list_length", 15);
$config->set_default("tags_min", 3);
}
if(is_a($event, 'PageRequestEvent') && ($event->page == "tags")) {
global $page;
@ -33,7 +37,7 @@ class TagList extends Extension {
if(is_a($event, 'PageRequestEvent') && ($event->page == "index")) {
global $config;
global $page;
if($config->get_int('tag_list_length', TAG_LIST_LENGTH) > 0) {
if($config->get_int('tag_list_length') > 0) {
if(isset($_GET['search'])) {
$this->add_refine_block($page, tag_explode($_GET['search']));
}
@ -45,7 +49,7 @@ class TagList extends Extension {
if(is_a($event, 'DisplayingImageEvent')) {
global $config;
if($config->get_int('tag_list_length', TAG_LIST_LENGTH) > 0) {
if($config->get_int('tag_list_length') > 0) {
$this->add_related_block($event->page, $event->image);
}
}
@ -82,7 +86,7 @@ class TagList extends Extension {
global $database;
global $config;
$tags_min = $config->get_int('tags_min', TAGS_MIN);
$tags_min = $config->get_int('tags_min');
$result = $database->Execute(
"SELECT tag,count FROM tags WHERE count > ? ORDER BY tag",
array($tags_min));
@ -106,7 +110,7 @@ class TagList extends Extension {
global $database;
global $config;
$tags_min = $config->get_int('tags_min', TAGS_MIN);
$tags_min = $config->get_int('tags_min');
$result = $database->Execute(
"SELECT tag,count FROM tags WHERE count > ? ORDER BY tag",
array($tags_min));
@ -133,7 +137,7 @@ class TagList extends Extension {
global $database;
global $config;
$tags_min = $config->get_int('tags_min', TAGS_MIN);
$tags_min = $config->get_int('tags_min');
$result = $database->Execute(
"SELECT tag,count FROM tags WHERE count > ? ORDER BY count DESC, tag ASC",
array($tags_min)