make front page a variable, and add support for default values in config->get
git-svn-id: file:///home/shish/svn/shimmie2/trunk@51 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
f6fdc13101
commit
3d2ea2a842
3 changed files with 16 additions and 14 deletions
|
@ -1,13 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
class Config {
|
class Config {
|
||||||
var $values = array(
|
var $values = array();
|
||||||
'image_tlink' => '/thumbs/$id.jpg',
|
|
||||||
'image_ilink' => '/images/$id.$ext',
|
|
||||||
);
|
|
||||||
var $defaults = array(
|
var $defaults = array(
|
||||||
'title' => 'Shimmie', # setup
|
'title' => 'Shimmie', # setup
|
||||||
'version' => 'Shimmie2-0.0.9', // internal
|
'version' => 'Shimmie2-2.0.2', // internal
|
||||||
'db_version' => '2.0.0.9', // this should be managed by upgrade.php
|
'db_version' => '2.0.0.9', // this should be managed by upgrade.php
|
||||||
|
'front_page' => 'index', # setup
|
||||||
'base_href' => './index.php?q=', # setup
|
'base_href' => './index.php?q=', # setup
|
||||||
'data_href' => './', # setup
|
'data_href' => './', # setup
|
||||||
'theme' => 'default', # setup
|
'theme' => 'default', # setup
|
||||||
|
@ -101,19 +99,19 @@ class Config {
|
||||||
$this->save($name);
|
$this->save($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_int($name) {
|
public function get_int($name, $default=null) {
|
||||||
// deprecated -- ints should be stored as ints now
|
// deprecated -- ints should be stored as ints now
|
||||||
return parse_shorthand_int($this->get($name));
|
return parse_shorthand_int($this->get($name, $default));
|
||||||
}
|
}
|
||||||
public function get_string($name) {
|
public function get_string($name, $default=null) {
|
||||||
return $this->get($name);
|
return $this->get($name, $default);
|
||||||
}
|
}
|
||||||
public function get_bool($name) {
|
public function get_bool($name, $default=null) {
|
||||||
// deprecated -- bools should be stored as Y/N now
|
// deprecated -- bools should be stored as Y/N now
|
||||||
return ($this->get($name) == 'Y' || $this->get($name) == '1');
|
return ($this->get($name, $default) == 'Y' || $this->get($name, $default) == '1');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get($name) {
|
public function get($name, $default=null) {
|
||||||
if(isset($this->values[$name])) {
|
if(isset($this->values[$name])) {
|
||||||
return $this->values[$name];
|
return $this->values[$name];
|
||||||
}
|
}
|
||||||
|
@ -121,7 +119,7 @@ class Config {
|
||||||
return $this->defaults[$name];
|
return $this->defaults[$name];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return null;
|
return $default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,6 +124,8 @@ class Setup extends Extension {
|
||||||
$sb = new SetupBlock("General");
|
$sb = new SetupBlock("General");
|
||||||
$sb->add_label("Site title: ");
|
$sb->add_label("Site title: ");
|
||||||
$sb->add_text_option("title");
|
$sb->add_text_option("title");
|
||||||
|
$sb->add_label("<br>Front page: ");
|
||||||
|
$sb->add_text_option("front_page");
|
||||||
$sb->add_label("<br>Base URL: ");
|
$sb->add_label("<br>Base URL: ");
|
||||||
$sb->add_text_option("base_href");
|
$sb->add_text_option("base_href");
|
||||||
$sb->add_label("<br>Data URL: ");
|
$sb->add_label("<br>Data URL: ");
|
||||||
|
@ -139,6 +141,7 @@ class Setup extends Extension {
|
||||||
}
|
}
|
||||||
if(is_a($event, 'ConfigSaveEvent')) {
|
if(is_a($event, 'ConfigSaveEvent')) {
|
||||||
$event->config->set_string_from_post("title");
|
$event->config->set_string_from_post("title");
|
||||||
|
$event->config->set_string_from_post("front_page");
|
||||||
$event->config->set_string_from_post("base_href");
|
$event->config->set_string_from_post("base_href");
|
||||||
$event->config->set_string_from_post("data_href");
|
$event->config->set_string_from_post("data_href");
|
||||||
$event->config->set_string_from_post("contact_link");
|
$event->config->set_string_from_post("contact_link");
|
||||||
|
|
|
@ -246,6 +246,7 @@ function send_event($event) {
|
||||||
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
function _get_query_parts() {
|
function _get_query_parts() {
|
||||||
|
global $config;
|
||||||
if(isset($_GET["q"])) {
|
if(isset($_GET["q"])) {
|
||||||
$path = $_GET["q"];
|
$path = $_GET["q"];
|
||||||
}
|
}
|
||||||
|
@ -253,7 +254,7 @@ function _get_query_parts() {
|
||||||
$path = $_SERVER["PATH_INFO"];
|
$path = $_SERVER["PATH_INFO"];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$path = "index/1";
|
$path = $config->get_string('front_page', 'index');
|
||||||
}
|
}
|
||||||
|
|
||||||
while(strlen($path) > 0 && $path[0] == '/') {
|
while(strlen($path) > 0 && $path[0] == '/') {
|
||||||
|
|
Reference in a new issue