'User Links' block is no longer hard coded

git-svn-id: file:///home/shish/svn/shimmie2/trunk@79 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2007-05-08 21:01:51 +00:00
parent ea9da95c7b
commit c25427a5d1
3 changed files with 39 additions and 7 deletions

View file

@ -51,6 +51,12 @@ class AdminPage extends Extension {
if(is_a($event, 'AdminBuildingEvent')) {
$this->build_page();
}
if(is_a($event, 'UserBlockBuildingEvent')) {
if($event->user->is_admin()) {
$event->add_link("Board Admin", make_link("admin"));
}
}
}
// }}}
// block HTML {{{

View file

@ -166,6 +166,12 @@ class Setup extends Extension {
$event->config->set_string_from_post("theme");
$event->config->set_int_from_post("anon_id");
}
if(is_a($event, 'UserBlockBuildingEvent')) {
if($event->user->is_admin()) {
$event->add_link("Board Config", make_link("setup"));
}
}
}
// }}}
// HTML building {{{

View file

@ -1,5 +1,19 @@
<?php
class UserBlockBuildingEvent extends Event {
var $parts = array();
var $user = null;
public function UserBlockBuildingEvent($user) {
$this->user = $user;
}
public function add_link($name, $link, $position=50) {
while(isset($this->parts[$position])) $position++;
$this->parts[$position] = "<a href='$link'>$name</a>";
}
}
class UserPage extends Extension {
// event handling {{{
public function receive_event($event) {
@ -66,6 +80,11 @@ class UserPage extends Extension {
$event->config->set_bool_from_post("login_signup_enabled");
$event->config->set_string_from_post("login_tac");
}
if(is_a($event, 'UserBlockBuildingEvent')) {
$event->add_link("User Config", make_link("user"));
$event->add_link("Log Out", make_link("user/logout"));
}
}
// }}}
// Things done *with* the user {{{
@ -361,14 +380,15 @@ class UserPage extends Extension {
private function build_links_block() {
global $user;
$ubbe = new UserBlockBuildingEvent($user);
send_event($ubbe);
$h_name = html_escape($user->name);
$html = "Logged in as $h_name";
if($user->is_admin()) {
$html .= "<br/><a href='".make_link("setup")."'>Board Config</a>";
$html .= "<br/><a href='".make_link("admin")."'>Admin</a>";
}
$html .= "<br/><a href='".make_link("user")."'>User Config</a>";
$html .= "<br/><a href='".make_link("user/logout")."'>Log Out</a>";
$html = "Logged in as $h_name<br>";
$html .= join("\n<br/>", $ubbe->parts);
return $html;
}