truthomatic
This commit is contained in:
parent
71999a3065
commit
6baf616692
@ -11,16 +11,38 @@
|
||||
*/
|
||||
|
||||
class SendPMEvent extends Event {
|
||||
public function __construct($from_id, $from_ip, $to_id, $subject, $message) {
|
||||
$this->from_id = $from_id;
|
||||
$this->from_ip = $from_ip;
|
||||
$this->to_id = $to_id;
|
||||
$this->subject = $subject;
|
||||
$this->message = $message;
|
||||
public function __construct($pm) {
|
||||
$this->pm = $pm;
|
||||
}
|
||||
}
|
||||
|
||||
class PM extends SimpleExtension {
|
||||
class PM {
|
||||
public function __construct($from_id=0, $from_ip="0.0.0.0", $to_id=0, $subject="A Message", $message="Some Text", $read=False) {
|
||||
# PHP: the P stands for "really", the H stands for "awful" and the other P stands for "language"
|
||||
if(is_array($from_id)) {
|
||||
$a = $from_id;
|
||||
$this->id = $a["id"];
|
||||
$this->from_id = $a["from_id"];
|
||||
$this->from_ip = $a["from_ip"];
|
||||
$this->to_id = $a["to_id"];
|
||||
$this->sent_date = $a["sent_date"];
|
||||
$this->subject = $a["subject"];
|
||||
$this->message = $a["message"];
|
||||
$this->is_read = undb_bool($a["is_read"]);
|
||||
}
|
||||
else {
|
||||
$this->id = -1;
|
||||
$this->from_id = $from_id;
|
||||
$this->from_ip = $from_ip;
|
||||
$this->to_id = $to_id;
|
||||
$this->subject = $subject;
|
||||
$this->message = $message;
|
||||
$this->is_read = $read;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PrivMsg extends SimpleExtension {
|
||||
public function onInitExt($event) {
|
||||
global $config, $database;
|
||||
|
||||
@ -78,7 +100,7 @@ class PM extends SimpleExtension {
|
||||
else if(($pm["to_id"] == $user->id) || $user->is_admin()) {
|
||||
$from_user = User::by_id(int_escape($pm["from_id"]));
|
||||
$database->get_row("UPDATE private_message SET is_read='Y' WHERE id = ?", array($pm_id));
|
||||
$this->theme->display_message($page, $from_user, $user, $pm);
|
||||
$this->theme->display_message($page, $from_user, $user, new PM($pm));
|
||||
}
|
||||
else {
|
||||
// permission denied
|
||||
@ -105,7 +127,7 @@ class PM extends SimpleExtension {
|
||||
$from_id = $user->id;
|
||||
$subject = $_POST["subject"];
|
||||
$message = $_POST["message"];
|
||||
send_event(new SendPMEvent($from_id, $_SERVER["REMOTE_ADDR"], $to_id, $subject, $message));
|
||||
send_event(new SendPMEvent(new PM($from_id, $_SERVER["REMOTE_ADDR"], $to_id, $subject, $message)));
|
||||
$page->set_mode("redirect");
|
||||
$page->set_redirect($_SERVER["HTTP_REFERER"]);
|
||||
break;
|
||||
@ -124,8 +146,8 @@ class PM extends SimpleExtension {
|
||||
from_id, from_ip, to_id,
|
||||
sent_date, subject, message)
|
||||
VALUES(?, ?, ?, now(), ?, ?)",
|
||||
array($event->from_id, $event->from_ip,
|
||||
$event->to_id, $event->subject, $event->message)
|
||||
array($event->pm->from_id, $event->pm->from_ip,
|
||||
$event->pm->to_id, $event->pm->subject, $event->pm->message)
|
||||
);
|
||||
log_info("pm", "Sent PM to User #{$event->to_id}");
|
||||
}
|
||||
@ -134,12 +156,17 @@ class PM extends SimpleExtension {
|
||||
private function get_pms(User $user) {
|
||||
global $database;
|
||||
|
||||
return $database->get_all("
|
||||
$arr = $database->get_all("
|
||||
SELECT private_message.*,user_from.name AS from_name
|
||||
FROM private_message
|
||||
JOIN users AS user_from ON user_from.id=from_id
|
||||
WHERE to_id = ?
|
||||
", array($user->id));
|
||||
$pms = array();
|
||||
foreach($arr as $pm) {
|
||||
$pms[] = new PM($pm);
|
||||
}
|
||||
return $pms;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
class PMTest extends SCoreWebTestCase {
|
||||
class PrivMsgTest extends SCoreWebTestCase {
|
||||
function testPM() {
|
||||
$this->log_in_as_admin();
|
||||
$this->get_page("user/test");
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class PMTheme extends Themelet {
|
||||
class PrivMsgTheme extends Themelet {
|
||||
public function display_pms(Page $page, $pms) {
|
||||
$html = "
|
||||
<script>
|
||||
@ -14,18 +14,19 @@ class PMTheme extends Themelet {
|
||||
$n = 0;
|
||||
foreach($pms as $pm) {
|
||||
$oe = ($n++ % 2 == 0) ? "even" : "odd";
|
||||
$h_subject = html_escape($pm["subject"]);
|
||||
$h_subject = html_escape($pm->subject);
|
||||
if(strlen(trim($h_subject)) == 0) $h_subject = "(No subject)";
|
||||
$h_from = html_escape($pm["from_name"]);
|
||||
$from_url = make_link("user/".url_escape($pm["from_name"]));
|
||||
$pm_url = make_link("pm/read/".$pm["id"]);
|
||||
$del_url = make_link("pm/delete/".$pm["id"]);
|
||||
$h_date = html_escape($pm["sent_date"]);
|
||||
if($pm["is_read"] == "N") $h_subject = "<b>$h_subject</b>";
|
||||
$from_name = User::by_id($pm->from_id)->name;
|
||||
$h_from = html_escape($from_name);
|
||||
$from_url = make_link("user/".url_escape($from_name));
|
||||
$pm_url = make_link("pm/read/".$pm->id);
|
||||
$del_url = make_link("pm/delete/".$pm->id);
|
||||
$h_date = html_escape($pm->sent_date);
|
||||
if($pm->is_read) $h_subject = "<b>$h_subject</b>";
|
||||
$html .= "<tr class='$oe'><td><a href='$pm_url'>$h_subject</a></td>
|
||||
<td><a href='$from_url'>$h_from</a></td><td>$h_date</td>
|
||||
<td><form action='$del_url'>
|
||||
<input type='hidden' name='q' value='/pm/delete/{$pm["id"]}'>
|
||||
<input type='hidden' name='q' value='/pm/delete/{$pm->id}'>
|
||||
<input type='submit' value='Delete'>
|
||||
</form></td></tr>";
|
||||
}
|
||||
@ -53,12 +54,12 @@ EOD;
|
||||
$page->add_block(new Block("Write a PM", $html, "main", 20));
|
||||
}
|
||||
|
||||
public function display_message(Page $page, User $from, User $to, $pm) {
|
||||
$this->display_composer($page, $to, $from, "Re: ".$pm["subject"]);
|
||||
public function display_message(Page $page, User $from, User $to, PM $pm) {
|
||||
$this->display_composer($page, $to, $from, "Re: ".$pm->subject);
|
||||
$page->set_title("Private Message");
|
||||
$page->set_heading(html_escape($pm["subject"]));
|
||||
$page->set_heading(html_escape($pm->subject));
|
||||
$page->add_block(new NavBlock());
|
||||
$page->add_block(new Block("Message", format_text($pm["message"]), "main", 10));
|
||||
$page->add_block(new Block("Message", format_text($pm->message), "main", 10));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -76,7 +76,7 @@ abstract class BaseConfig implements Config {
|
||||
return $this->get($name, $default);
|
||||
}
|
||||
public function get_bool($name, $default=null) {
|
||||
return ($this->get($name, $default) == 'Y');
|
||||
return undb_bool($this->get($name, $default));
|
||||
}
|
||||
public function get_array($name, $default=array()) {
|
||||
return explode(",", $this->get($name, ""));
|
||||
|
Loading…
x
Reference in New Issue
Block a user