scorify the PM extension

This commit is contained in:
Shish 2009-01-04 09:38:23 -08:00
parent 85c8875ffe
commit cdde0e072c
3 changed files with 25 additions and 28 deletions

View File

@ -13,22 +13,21 @@ class ET implements Extension {
if(is_null($this->theme)) $this->theme = get_theme_object($this); if(is_null($this->theme)) $this->theme = get_theme_object($this);
if(($event instanceof PageRequestEvent) && $event->page_matches("system_info")) { if(($event instanceof PageRequestEvent) && $event->page_matches("system_info")) {
if($event->user->is_admin()) { if($event->context->user->is_admin()) {
$this->theme->display_info_page($event->page, $this->get_info()); $this->theme->display_info_page($event->page, $this->get_info($event->context));
} }
} }
if($event instanceof UserBlockBuildingEvent) { if($event instanceof UserBlockBuildingEvent) {
if($event->user->is_admin()) { if($event->context->user->is_admin()) {
$event->add_link("System Info", make_link("system_info")); $event->add_link("System Info", make_link("system_info"));
} }
} }
} }
// do it {{{ private function get_info($context) {
private function get_info() { $database = $context->database;
global $database; $config = $context->config;
global $config;
global $_event_listeners; // yay for using secret globals \o/ global $_event_listeners; // yay for using secret globals \o/
$info = array(); $info = array();

View File

@ -6,11 +6,11 @@ class ETTheme extends Themelet {
* *
* $info = an array of ($name => $value) * $info = an array of ($name => $value)
*/ */
public function display_info_page($page, $info) { public function display_info_page(Page $page, $info) {
$page->set_title("System Info"); $page->set_title("System Info");
$page->set_heading("System Info"); $page->set_heading("System Info");
$page->add_block(new NavBlock()); $page->add_block(new NavBlock());
$page->add_block(new Block("Data which is to be sent:", $this->build_data_form($info))); $page->add_block(new Block("Information:", $this->build_data_form($info)));
} }
protected function build_data_form($info) { protected function build_data_form($info) {
@ -44,8 +44,7 @@ EOD;
<textarea name='data' rows='20' cols='80'>$data</textarea> <textarea name='data' rows='20' cols='80'>$data</textarea>
<br><input type='submit' value='Click to send to Shish'> <br><input type='submit' value='Click to send to Shish'>
<br>Your stats are useful so that I know which combinations <br>Your stats are useful so that I know which combinations
of web servers / databases / etc I need to support, of web servers / databases / etc I need to support.
<br>and so that I can get some idea of how people use shimmie generally
</form> </form>
EOD; EOD;
return $html; return $html;

View File

@ -7,7 +7,8 @@
*/ */
class SendPMEvent extends Event { class SendPMEvent extends Event {
public function SendPMEvent($from_id, $from_ip, $to_id, $subject, $message) { public function __construct(RequestContext $reqest, $from_id, $from_ip, $to_id, $subject, $message) {
parent::__construct($request);
$this->from_id = $from_id; $this->from_id = $from_id;
$this->from_ip = $from_ip; $this->from_ip = $from_ip;
$this->to_id = $to_id; $this->to_id = $to_id;
@ -23,9 +24,8 @@ class PM implements Extension {
if(is_null($this->theme)) $this->theme = get_theme_object($this); if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof InitExtEvent) { if($event instanceof InitExtEvent) {
global $config; if($event->context->config->get_int("pm_version") < 1) {
if($config->get_int("pm_version") < 1) { $this->install($event->context);
$this->install();
} }
} }
@ -38,22 +38,22 @@ class PM implements Extension {
*/ */
if($event instanceof UserPageBuildingEvent) { if($event instanceof UserPageBuildingEvent) {
global $user; $user = $event->context->user;
$duser = $event->user; $duser = $event->display_user;
if(!$user->is_anonymous() && !$duser->is_anonymous()) { if(!$user->is_anonymous() && !$duser->is_anonymous()) {
if(($user->id == $duser->id) || $user->is_admin()) { if(($user->id == $duser->id) || $user->is_admin()) {
$this->theme->display_pms($event->page, $this->get_pms($duser)); $this->theme->display_pms($event->context->page, $this->get_pms($duser));
} }
if($user->id != $duser->id) { if($user->id != $duser->id) {
$this->theme->display_composer($event->page, $user, $duser); $this->theme->display_composer($event->context->page, $user, $duser);
} }
} }
} }
if(($event instanceof PageRequestEvent) && $event->page_matches("pm")) { if(($event instanceof PageRequestEvent) && $event->page_matches("pm")) {
global $database; $database = $event->context->database;
global $config; $config = $event->context->config;
global $user; $user = $event->config->user;
if(!$user->is_anonymous()) { if(!$user->is_anonymous()) {
switch($event->get_arg(0)) { switch($event->get_arg(0)) {
case "read": case "read":
@ -91,7 +91,7 @@ class PM implements Extension {
$from_id = $user->id; $from_id = $user->id;
$subject = $_POST["subject"]; $subject = $_POST["subject"];
$message = $_POST["message"]; $message = $_POST["message"];
send_event(new SendPMEvent($from_id, $_SERVER["REMOTE_ADDR"], $to_id, $subject, $message)); send_event(new SendPMEvent($event->context, $from_id, $_SERVER["REMOTE_ADDR"], $to_id, $subject, $message));
$event->page->set_mode("redirect"); $event->page->set_mode("redirect");
$event->page->set_redirect(make_link($_SERVER["REFERER"])); $event->page->set_redirect(make_link($_SERVER["REFERER"]));
break; break;
@ -100,8 +100,7 @@ class PM implements Extension {
} }
if($event instanceof SendPMEvent) { if($event instanceof SendPMEvent) {
global $database; $event->context->database->execute("
$database->execute("
INSERT INTO private_message( INSERT INTO private_message(
from_id, from_ip, to_id, from_id, from_ip, to_id,
sent_date, subject, message) sent_date, subject, message)
@ -112,9 +111,9 @@ class PM implements Extension {
} }
} }
protected function install() { protected function install(RequestContext $context) {
global $database; $database = $context->database;
global $config; $config = $context->config;
// shortcut to latest // shortcut to latest
if($config->get_int("pm_version") < 1) { if($config->get_int("pm_version") < 1) {