setup themed
git-svn-id: file:///home/shish/svn/shimmie2/trunk@324 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
0e49266a01
commit
35d47b972b
@ -123,16 +123,15 @@ class SetupBlock extends Block {
|
|||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
class Setup extends Extension {
|
class Setup extends Extension {
|
||||||
|
var $theme;
|
||||||
// event handling {{{
|
// event handling {{{
|
||||||
public function receive_event($event) {
|
public function receive_event($event) {
|
||||||
|
if(is_null($this->theme)) $this->theme = get_theme_object("setup", "SetupTheme");
|
||||||
|
|
||||||
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "setup")) {
|
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "setup")) {
|
||||||
global $user;
|
global $user;
|
||||||
if(!$user->is_admin()) {
|
if(!$user->is_admin()) {
|
||||||
global $page;
|
$this->theme->display_not_admin($event->page);
|
||||||
$page->set_title("Error");
|
|
||||||
$page->set_heading("Error");
|
|
||||||
$page->add_block(new NavBlock());
|
|
||||||
$page->add_block(new Block("Permission Denied", "This page is for admins only"));
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if($event->get_arg(0) == "save") {
|
if($event->get_arg(0) == "save") {
|
||||||
@ -147,7 +146,7 @@ class Setup extends Extension {
|
|||||||
else {
|
else {
|
||||||
$panel = new SetupPanel();
|
$panel = new SetupPanel();
|
||||||
send_event(new SetupBuildingEvent($panel));
|
send_event(new SetupBuildingEvent($panel));
|
||||||
$this->build_page($panel);
|
$this->theme->display_page($event->page, $panel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,7 +165,6 @@ class Setup extends Extension {
|
|||||||
$sb->add_text_option("base_href", "<br>Base URL: ");
|
$sb->add_text_option("base_href", "<br>Base URL: ");
|
||||||
$sb->add_text_option("contact_link", "<br>Contact URL: ");
|
$sb->add_text_option("contact_link", "<br>Contact URL: ");
|
||||||
$sb->add_choice_option("theme", $themes, "<br>Theme: ");
|
$sb->add_choice_option("theme", $themes, "<br>Theme: ");
|
||||||
// $sb->add_int_option("anon_id", "<br>Anonymous ID: "); // FIXME: create advanced options page
|
|
||||||
$event->panel->add_block($sb);
|
$event->panel->add_block($sb);
|
||||||
}
|
}
|
||||||
if(is_a($event, 'ConfigSaveEvent')) {
|
if(is_a($event, 'ConfigSaveEvent')) {
|
||||||
@ -190,71 +188,6 @@ class Setup extends Extension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }}}
|
|
||||||
// HTML building {{{
|
|
||||||
private function build_page($panel) {
|
|
||||||
$setupblock_html1 = "";
|
|
||||||
$setupblock_html2 = "";
|
|
||||||
|
|
||||||
usort($panel->blocks, "blockcmp");
|
|
||||||
|
|
||||||
/*
|
|
||||||
$flip = true;
|
|
||||||
foreach($panel->mainblocks as $block) {
|
|
||||||
if(is_a($block, 'SetupBlock')) {
|
|
||||||
if($flip) $setupblock_html1 .= $this->sb_to_html($block);
|
|
||||||
else $setupblock_html2 .= $this->sb_to_html($block);
|
|
||||||
$flip = !$flip;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Try and keep the two columns even; count the line breaks in
|
|
||||||
* each an calculate where a block would work best
|
|
||||||
*/
|
|
||||||
$len1 = 0;
|
|
||||||
$len2 = 0;
|
|
||||||
foreach($panel->blocks as $block) {
|
|
||||||
if(is_a($block, 'SetupBlock')) {
|
|
||||||
$html = $this->sb_to_html($block);
|
|
||||||
$len = count(explode("<br>", $html))+1;
|
|
||||||
if($len1 <= $len2) {
|
|
||||||
$setupblock_html1 .= $this->sb_to_html($block);
|
|
||||||
$len1 += $len;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$setupblock_html2 .= $this->sb_to_html($block);
|
|
||||||
$len2 += $len;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$table = "
|
|
||||||
<form action='".make_link("setup/save")."' method='POST'><table>
|
|
||||||
<tr><td>$setupblock_html1</td><td>$setupblock_html2</td></tr>
|
|
||||||
<tr><td colspan='2'><input type='submit' value='Save Settings'></td></tr>
|
|
||||||
</table></form>
|
|
||||||
";
|
|
||||||
|
|
||||||
global $page;
|
|
||||||
$page->set_title("Shimmie Setup");
|
|
||||||
$page->set_heading("Shimmie Setup");
|
|
||||||
$page->add_block(new Block("Navigation", $this->build_navigation(), "left", 0));
|
|
||||||
$page->add_block(new Block("Setup", $table));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function build_navigation() {
|
|
||||||
return "
|
|
||||||
<a href='".make_link("index")."'>Index</a>
|
|
||||||
<br><a href='http://trac.shishnet.org/shimmie/wiki/Settings'>Help</a>
|
|
||||||
";
|
|
||||||
}
|
|
||||||
|
|
||||||
private function sb_to_html($block) {
|
|
||||||
return "<div class='setupblock'><b>{$block->header}</b><br>{$block->body}</div>\n";
|
|
||||||
}
|
|
||||||
// }}}
|
|
||||||
}
|
}
|
||||||
add_event_listener(new Setup());
|
add_event_listener(new Setup());
|
||||||
?>
|
?>
|
||||||
|
73
ext/setup/theme.php
Normal file
73
ext/setup/theme.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class SetupTheme extends Themelet {
|
||||||
|
public function display_not_admin($page) {
|
||||||
|
$page->set_title("Error");
|
||||||
|
$page->set_heading("Error");
|
||||||
|
$page->add_block(new NavBlock());
|
||||||
|
$page->add_block(new Block("Permission Denied", "This page is for admins only"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function display_page($page, $panel) {
|
||||||
|
$setupblock_html1 = "";
|
||||||
|
$setupblock_html2 = "";
|
||||||
|
|
||||||
|
usort($panel->blocks, "blockcmp");
|
||||||
|
|
||||||
|
/*
|
||||||
|
$flip = true;
|
||||||
|
foreach($panel->mainblocks as $block) {
|
||||||
|
if(is_a($block, 'SetupBlock')) {
|
||||||
|
if($flip) $setupblock_html1 .= $this->sb_to_html($block);
|
||||||
|
else $setupblock_html2 .= $this->sb_to_html($block);
|
||||||
|
$flip = !$flip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Try and keep the two columns even; count the line breaks in
|
||||||
|
* each an calculate where a block would work best
|
||||||
|
*/
|
||||||
|
$len1 = 0;
|
||||||
|
$len2 = 0;
|
||||||
|
foreach($panel->blocks as $block) {
|
||||||
|
if(is_a($block, 'SetupBlock')) {
|
||||||
|
$html = $this->sb_to_html($block);
|
||||||
|
$len = count(explode("<br>", $html))+1;
|
||||||
|
if($len1 <= $len2) {
|
||||||
|
$setupblock_html1 .= $this->sb_to_html($block);
|
||||||
|
$len1 += $len;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$setupblock_html2 .= $this->sb_to_html($block);
|
||||||
|
$len2 += $len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$table = "
|
||||||
|
<form action='".make_link("setup/save")."' method='POST'><table>
|
||||||
|
<tr><td>$setupblock_html1</td><td>$setupblock_html2</td></tr>
|
||||||
|
<tr><td colspan='2'><input type='submit' value='Save Settings'></td></tr>
|
||||||
|
</table></form>
|
||||||
|
";
|
||||||
|
|
||||||
|
$page->set_title("Shimmie Setup");
|
||||||
|
$page->set_heading("Shimmie Setup");
|
||||||
|
$page->add_block(new Block("Navigation", $this->build_navigation(), "left", 0));
|
||||||
|
$page->add_block(new Block("Setup", $table));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function build_navigation() {
|
||||||
|
return "
|
||||||
|
<a href='".make_link("index")."'>Index</a>
|
||||||
|
<br><a href='http://trac.shishnet.org/shimmie/wiki/Settings'>Help</a>
|
||||||
|
";
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sb_to_html($block) {
|
||||||
|
return "<div class='setupblock'><b>{$block->header}</b><br>{$block->body}</div>\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
Loading…
x
Reference in New Issue
Block a user