goodbye, global config defaults~

git-svn-id: file:///home/shish/svn/shimmie2/trunk@294 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2007-07-16 14:09:12 +00:00
parent da30c88776
commit 3084446c2e
8 changed files with 35 additions and 34 deletions

View file

@ -1,16 +1,6 @@
<?php
class Config {
var $values = array();
var $defaults = array(
'title' => 'Shimmie', # setup
'version' => 'Shimmie2-2.0.3', // internal
'base_href' => './index.php?q=', # setup
'data_href' => './', # setup
'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;
@ -74,20 +64,13 @@ 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' ||
$this->get($name, $default) === true
);
return ($this->get($name, $default) == 'Y' || $this->get($name, $default) == '1');
}
private function get($name, $default=null) {
if(isset($this->values[$name])) {
return $this->values[$name];
}
else if(isset($this->defaults[$name])) {
return $this->defaults[$name];
}
else {
return $default;
}

View file

@ -92,22 +92,22 @@ class Image {
public function get_image_link() {
global $config;
return $this->parse_link_template($config->get_string('image_ilink'));
return $this->parse_link_template($config->get_string('image_ilink', '$base/image/$id.$ext'));
}
public function get_short_link() {
global $config;
return $this->parse_link_template($config->get_string('image_slink'));
return $this->parse_link_template($config->get_string('image_slink', ''));
}
public function get_thumb_link() {
global $config;
return $this->parse_link_template($config->get_string('image_tlink'));
return $this->parse_link_template($config->get_string('image_tlink', '$base/thumb/$id.jpg'));
}
public function get_tooltip() {
global $config;
return $this->parse_link_template($config->get_string('image_tip'));
return $this->parse_link_template($config->get_string('image_tip', '$tags // $size // $filesize'));
}
public function get_image_filename() {

View file

@ -92,7 +92,7 @@ function tag_explode($tags) {
function make_link($page, $query=null) {
global $config;
$base = $config->get_string('base_href');
$base = $config->get_string('base_href', './index.php?q=');
if(is_null($query)) {
return "$base/$page";

View file

@ -4,7 +4,7 @@ class LoadExtData extends Extension {
if(is_a($event, 'PageRequestEvent')) {
global $page, $config;
$data_href = $config->get_string("data_href");
$data_href = $config->get_string("data_href", './');
foreach(glob("ext/*/style.css") as $css_file) {
$page->add_header("<link rel='stylesheet' href='$data_href/$css_file' type='text/css'>");

View file

@ -20,7 +20,7 @@ class Upgrade extends Extension {
$config->set_int("db_version", 2);
}
if($config->get_int("db_version") == 2) {
if($config->get_int("db_version") <= 2) {
$database->Execute("CREATE TABLE layout (
title varchar(64) primary key not null,
section varchar(32) not null default \"left\",

View file

@ -1,5 +1,6 @@
<?php
define("DEBUG", true);
define("VERSION", '2.0.3-svn');
if(DEBUG) {
error_reporting(E_ALL);

View file

@ -482,10 +482,18 @@ function create_tables_mysql($db) {
$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),
id int not null auto_increment primary key,
tag varchar(64) not null unique,
count int not null default 0,
KEY tags_count(count)
)");
$db->Execute("DROP TABLE IF EXISTS image_tags");
$db->Execute("CREATE TABLE image_tags (
image_id int NOT NULL default 0,
tag_id int NOT NULL default 0,
UNIQUE KEY image_id_tag_id (image_id,tag_id),
KEY tags_tag_id (tag_id),
KEY tags_image_id (image_id)
)");
@ -502,7 +510,17 @@ function create_tables_mysql($db) {
UNIQUE (name)
)");
$db->Execute("INSERT INTO config(name, value) VALUES(?, ?)", Array('db_version', '2.0.0.9'));
$db->Execute("DROP TABLE IF EXISTS layout");
$database->Execute("CREATE TABLE layout (
title varchar(64) primary key not null,
section varchar(32) not null default \"left\",
position int not null default 50,
visible enum('Y', 'N') default 'Y' not null
)");
$db->Execute("INSERT INTO config(name, value) VALUES(?, ?)", Array('title', 'Shimmie'));
$db->Execute("INSERT INTO config(name, value) VALUES(?, ?)", Array('db_version', 5));
$db->Execute("INSERT INTO config(name, value) VALUES(?, ?)", Array('front_page', 'index'));
return $db->CommitTrans();
}

View file

@ -3,11 +3,10 @@
class Layout {
function display_page($page) {
global $config;
$theme_name = $config->get_string('theme');
$base_href = $config->get_string('base_href');
$data_href = $config->get_string('data_href');
$theme_name = $config->get_string('theme', 'default');
$data_href = $config->get_string('data_href', './');
$contact_link = $config->get_string('contact_link');
$version = $config->get_string('version');
$version = "Shimmie-".VERSION;
$header_html = "";
foreach($page->headers as $line) {