requestcontext stuff is messy, go back to globals :(

This commit is contained in:
Shish 2009-05-11 07:04:33 -07:00
parent e592ee4c59
commit bb84a735a2
57 changed files with 407 additions and 477 deletions

View File

@ -10,21 +10,20 @@ class Bookmarks implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if(($event instanceof PageRequestEvent) && $event->page_matches("bookmark")) {
$user = $event->context->user;
if($event->get_arg(0) == "add") {
if(isset($_POST['url'])) {
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("user"));
$page->set_mode("redirect");
$page->set_redirect(make_link("user"));
}
}
else if($event->get_arg(0) == "remove") {
if(isset($_POST['id'])) {
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("user"));
$page->set_mode("redirect");
$page->set_redirect(make_link("user"));
}
}
}

View File

@ -208,7 +208,7 @@ class DanbooruApi implements Extension
// It is also currently broken due to some confusion over file variable ($tmp_filename?)
// Does it exist already?
$existing = Image::by_hash($config, $database, $hash);
$existing = Image::by_hash($hash);
if(!is_null($existing)) {
header("HTTP/1.0 409 Conflict");
header("X-Danbooru-Errors: duplicate");
@ -227,7 +227,7 @@ class DanbooruApi implements Extension
$nevent = new DataUploadEvent($user, $file, $metadata);
send_event($nevent);
// If it went ok, grab the id for the newly uploaded image and pass it in the header
$newimg = Image::by_hash($config, $database, $hash);
$newimg = Image::by_hash($hash);
$newid = make_link("post/view/" . $newimg->id);
// Did we POST or GET this call?
if($_SERVER['REQUEST_METHOD'] == 'POST')
@ -269,21 +269,21 @@ class DanbooruApi implements Extension
$md5list = explode(",",$_GET['md5']);
foreach($md5list as $md5)
{
$results[] = Image::by_hash($config, $database, $md5);
$results[] = Image::by_hash($md5);
}
} elseif(isset($_GET['id']))
{
$idlist = explode(",",$_GET['id']);
foreach($idlist as $id)
{
$results[] = Image::by_id($config, $database, $id);
$results[] = Image::by_id($id);
}
} else
{
$limit = isset($_GET['limit']) ? int_escape($_GET['limit']) : 100;
$start = isset($_GET['offset']) ? int_escape($_GET['offset']) : 0;
$tags = isset($_GET['tags']) ? Tag::explode($_GET['tags']) : array();
$results = Image::find_images($config,$database,$start,$limit,$tags);
$results = Image::find_images($start, $limit, $tags);
}
// Now we have the array $results filled with Image objects
@ -392,12 +392,12 @@ class DanbooruApi implements Extension
$name = $_REQUEST['login'];
$pass = $_REQUEST['password'];
$hash = md5( strtolower($name) . $pass );
$duser = User::by_name_and_hash($config, $database, $name, $hash);
$duser = User::by_name_and_hash($name, $hash);
if(!is_null($duser)) {
$user = $duser;
} else
{
$user = User::by_id($config, $database, $config->get_int("anon_id", 0));
$user = User::by_id($config->get_int("anon_id", 0));
}
}
}

View File

@ -10,6 +10,7 @@ class Downtime implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof SetupBuildingEvent) {
@ -20,16 +21,15 @@ class Downtime implements Extension {
}
if($event instanceof PageRequestEvent) {
if($event->context->config->get_bool("downtime")) {
if($config->get_bool("downtime")) {
$this->check_downtime($event);
$this->theme->display_notification($event->page);
$this->theme->display_notification($page);
}
}
}
private function check_downtime(PageRequestEvent $event) {
$user = $event->context->user;
$config = $event->context->config;
global $user, $config;
if($config->get_bool("downtime") && !$user->is_admin() &&
($event instanceof PageRequestEvent) && !$this->is_safe_page($event)) {

View File

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

View File

@ -29,19 +29,19 @@ class Featured implements Extension {
$id = int_escape($_POST['image_id']);
if($id > 0) {
$config->set_int("featured_id", $id);
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("post/view/$id"));
$page->set_mode("redirect");
$page->set_redirect(make_link("post/view/$id"));
}
}
}
if($event instanceof PostListBuildingEvent) {
global $config, $database;
global $config, $page;
$fid = $config->get_int("featured_id");
if($fid > 0) {
$image = Image::by_id($config, $database, $fid);
$image = Image::by_id($fid);
if(!is_null($image)) {
$this->theme->display_featured($event->page, $image);
$this->theme->display_featured($page, $image);
}
}
}

View File

@ -35,7 +35,7 @@ class IcoFileHandler implements Extension {
global $config;
global $database;
$id = int_escape($event->get_arg(0));
$image = Image::by_id($config, $database, $id);
$image = Image::by_id($id);
$hash = $image->hash;
$ha = substr($hash, 0, 2);

View File

@ -51,7 +51,7 @@ class SVGFileHandler implements Extension {
global $config;
global $database;
$id = int_escape($event->get_arg(0));
$image = Image::by_id($config, $database, $id);
$image = Image::by_id($id);
$hash = $image->hash;
$ha = substr($hash, 0, 2);

View File

@ -18,12 +18,13 @@ class Home implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if(($event instanceof PageRequestEvent) && $event->page_matches("home"))
{
// this is a request to display this page so output the page.
$this->output_pages($event->page);
$this->output_pages($page);
}
if($event instanceof SetupBuildingEvent)
{

View File

@ -34,18 +34,16 @@ class ImageBan implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof InitExtEvent) {
global $config;
if($config->get_int("ext_imageban_version") < 1) {
$this->install();
}
}
if($event instanceof DataUploadEvent) {
global $database;
$row = $database->db->GetRow("SELECT * FROM image_bans WHERE hash = ?", $event->hash);
if($row) {
log_info("image_hash_ban", "Blocked image ({$event->hash})");
@ -54,23 +52,20 @@ class ImageBan implements Extension {
}
if(($event instanceof PageRequestEvent) && $event->page_matches("image_hash_ban")) {
if($event->user->is_admin()) {
if($user->is_admin()) {
if($event->get_arg(0) == "add") {
if(isset($_POST['hash']) && isset($_POST['reason'])) {
send_event(new AddImageHashBanEvent($_POST['hash'], $_POST['reason']));
global $page;
$page->set_mode("redirect");
$page->set_redirect(make_link("admin"));
}
if(isset($_POST['image_id'])) {
global $config;
global $database;
$image = Image::by_id($config, $database, int_escape($_POST['image_id']));
$image = Image::by_id(int_escape($_POST['image_id']));
if($image) {
send_event(new ImageDeletionEvent($image));
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("post/list"));
$page->set_mode("redirect");
$page->set_redirect(make_link("post/list"));
}
}
}
@ -78,7 +73,6 @@ class ImageBan implements Extension {
if(isset($_POST['hash'])) {
send_event(new RemoveImageHashBanEvent($_POST['hash']));
global $page;
$page->set_mode("redirect");
$page->set_redirect(make_link("admin"));
}
@ -88,13 +82,13 @@ class ImageBan implements Extension {
if($event->count_args() == 2) {
$page_num = int_escape($event->get_arg(1));
}
$this->theme->display_Image_hash_Bans($event->page, $page_num, $this->get_image_hash_bans($page_num));
$this->theme->display_Image_hash_Bans($page, $page_num, $this->get_image_hash_bans($page_num));
}
}
}
if($event instanceof UserBlockBuildingEvent) {
if($event->user->is_admin()) {
if($user->is_admin()) {
$event->add_link("Image Bans", make_link("image_hash_ban/list/1"));
}
}
@ -108,7 +102,7 @@ class ImageBan implements Extension {
}
if($event instanceof ImageAdminBlockBuildingEvent) {
if($event->user->is_admin()) {
if($user->is_admin()) {
$event->add_part($this->theme->get_buttons_html($event->image));
}
}

View File

@ -1,4 +1,8 @@
<?php
class ImageHashBanTest extends WebTestCase {}
if(!defined(VERSION)) return;
class ImageHashBanUnitTest extends UnitTestCase {
public function _broken_testUploadFailsWhenBanned() {
$ihb = new ImageHashBan();

View File

@ -38,10 +38,10 @@ class IPBan implements Extension {
var $theme;
// event handler {{{
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof InitExtEvent) {
global $config;
if($config->get_int("ext_ipban_version") < 5) {
$this->install();
}
@ -50,7 +50,6 @@ class IPBan implements Extension {
}
if(($event instanceof PageRequestEvent) && $event->page_matches("ip_ban")) {
global $user;
if($user->is_admin()) {
if($event->get_arg(0) == "add") {
if(isset($_POST['ip']) && isset($_POST['reason']) && isset($_POST['end'])) {
@ -58,40 +57,38 @@ class IPBan implements Extension {
else $end = $_POST['end'];
send_event(new AddIPBanEvent($_POST['ip'], $_POST['reason'], $end));
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("ip_ban/list"));
$page->set_mode("redirect");
$page->set_redirect(make_link("ip_ban/list"));
}
}
else if($event->get_arg(0) == "remove") {
if(isset($_POST['id'])) {
send_event(new RemoveIPBanEvent($_POST['id']));
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("ip_ban/list"));
$page->set_mode("redirect");
$page->set_redirect(make_link("ip_ban/list"));
}
}
else if($event->get_arg(0) == "list") {
$bans = (isset($_GET["all"])) ? $this->get_bans() : $this->get_active_bans();
$this->theme->display_bans($event->page, $bans);
$this->theme->display_bans($page, $bans);
}
}
else {
$this->theme->display_permission_denied($event->page);
$this->theme->display_permission_denied($page);
}
}
if($event instanceof UserBlockBuildingEvent) {
if($event->user->is_admin()) {
if($user->is_admin()) {
$event->add_link("IP Bans", make_link("ip_ban/list"));
}
}
if($event instanceof AddIPBanEvent) {
global $user;
$this->add_ip_ban($event->ip, $event->reason, $event->end, $user);
}
if($event instanceof RemoveIPBanEvent) {
global $database;
$database->Execute("DELETE FROM bans WHERE id = ?", array($event->id));
}
}
@ -173,7 +170,7 @@ class IPBan implements Extension {
(strstr($row['ip'], '/') && ip_in_range($remote, $row['ip'])) ||
($row['ip'] == $remote)
) {
$admin = User::by_id($config, $database, $row['banner_id']);
$admin = User::by_id($row['banner_id']);
$date = date("Y-m-d", $row['end_timestamp']);
print "IP <b>{$row['ip']}</b> has been banned until <b>$date</b> by <b>{$admin->name}</b> because of <b>{$row['reason']}</b>";

View File

@ -8,13 +8,14 @@ class LinkImage implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if(($event instanceof DisplayingImageEvent)) {
global $config;
$data_href = get_base_href();
$event->page->add_header("<link rel='stylesheet' href='$data_href/ext/link_image/_style.css' type='text/css'>",0);
$this->theme->links_block($event->page,$this->data($event->image));
if(($event instanceof DisplayingImageEvent)) {
$data_href = get_base_href();
$page->add_header("<link rel='stylesheet' href='$data_href/ext/link_image/_style.css' type='text/css'>",0);
$this->theme->links_block($page, $this->data($event->image));
}
if($event instanceof SetupBuildingEvent) {
$sb = new SetupBlock("Link to Image");
@ -22,7 +23,6 @@ class LinkImage implements Extension {
$event->panel->add_block($sb);
}
if($event instanceof InitExtEvent) {
global $config;
//just set default if empty.
$config->set_default_string("ext_link-img_text-link_format",
'$title - $id ($ext $size $filesize)');

View File

@ -12,11 +12,12 @@ class News implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof PostListBuildingEvent) {
if(strlen($event->context->config->get_string("news_text")) > 0) {
$this->theme->display_news($event->page, $event->context->config->get_string("news_text"));
if(strlen($config->get_string("news_text")) > 0) {
$this->theme->display_news($page, $config->get_string("news_text"));
}
}

View File

@ -12,19 +12,18 @@ class Notes implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof InitExtEvent) {
global $config;
if($config->get_int("ext_notes_version") < 1) {
$this->install();
}
}
if($event instanceof DisplayingImageEvent) {
global $database;
$notes = $database->get_all("SELECT * FROM image_notes WHERE image_id = ?", array($event->image->id));
$this->theme->display_notes($event->page, $notes);
$this->theme->display_notes($page, $notes);
}
}

View File

@ -23,42 +23,40 @@ class NumericScore implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof InitExtEvent) {
global $config;
if($config->get_int("ext_numeric_score_version", 0) < 1) {
$this->install();
}
}
if($event instanceof DisplayingImageEvent) {
global $user;
if(!$user->is_anonymous()) {
$html = $this->theme->get_voter_html($event->image);
$event->page->add_block(new Block("Image Score", $html, "left", 20));
$page->add_block(new Block("Image Score", $html, "left", 20));
}
}
if(($event instanceof PageRequestEvent) && $event->page_matches("numeric_score_vote")) {
if(!$event->user->is_anonymous()) {
if(!$user->is_anonymous()) {
$image_id = int_escape($_POST['image_id']);
$char = $_POST['vote'];
$score = 0;
if($char == "up") $score = 1;
else if($char == "down") $score = -1;
if($score != 0) send_event(new NumericScoreSetEvent($image_id, $event->user, $score));
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("post/view/$image_id"));
if($score != 0) send_event(new NumericScoreSetEvent($image_id, $user, $score));
$page->set_mode("redirect");
$page->set_redirect(make_link("post/view/$image_id"));
}
}
if($event instanceof NumericScoreSetEvent) {
$this->add_vote($event->image_id, $event->user->id, $event->score);
$this->add_vote($event->image_id, $user->id, $event->score);
}
if($event instanceof ImageDeletionEvent) {
global $database;
$database->execute("DELETE FROM numeric_score_votes WHERE image_id=?", array($event->image->id));
}
@ -74,7 +72,6 @@ class NumericScore implements Extension {
$event->set_querylet(new Querylet("numeric_score $cmp $score"));
}
if(preg_match("/^favou?rite$/", $event->term, $matches)) {
global $user;
$event->set_querylet(new Querylet("images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=1)", array($user->id)));
}
}

View File

@ -12,8 +12,9 @@
*/
class PicLens implements Extension {
public function receive_event(Event $event) {
global $page;
if($event instanceof PageRequestEvent) {
$event->page->add_header("<script type=\"text/javascript\" src=\"http://lite.piclens.com/current/piclens.js\"></script>");
$page->add_header("<script type=\"text/javascript\" src=\"http://lite.piclens.com/current/piclens.js\"></script>");
}
if($event instanceof PostListBuildingEvent) {
$foo='
@ -21,7 +22,7 @@ class PicLens implements Extension {
<img src="http://lite.piclens.com/images/PicLensButton.png"
alt="PicLens" width="16" height="12" border="0"
align="absmiddle"></a>';
$event->page->add_block(new Block("PicLens", $foo, "left", 20));
$page->add_block(new Block("PicLens", $foo, "left", 20));
}
}
}

View File

@ -11,8 +11,7 @@
*/
class SendPMEvent extends Event {
public function __construct(RequestContext $reqest, $from_id, $from_ip, $to_id, $subject, $message) {
parent::__construct($request);
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;
@ -25,51 +24,49 @@ class PM implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof InitExtEvent) {
if($event->context->config->get_int("pm_version") < 1) {
$this->install($event->context);
if($config->get_int("pm_version") < 1) {
$this->install();
}
}
/*
if($event instanceof UserBlockBuildingEvent) {
if(!$event->user->is_anonymous()) {
if(!$user->is_anonymous()) {
$event->add_link("Private Messages", make_link("pm"));
}
}
*/
if($event instanceof UserPageBuildingEvent) {
$user = $event->context->user;
$duser = $event->display_user;
if(!$user->is_anonymous() && !$duser->is_anonymous()) {
if(($user->id == $duser->id) || $user->is_admin()) {
$this->theme->display_pms($event->context->page, $this->get_pms($duser));
$this->theme->display_pms($page, $this->get_pms($duser));
}
if($user->id != $duser->id) {
$this->theme->display_composer($event->context->page, $user, $duser);
$this->theme->display_composer($page, $user, $duser);
}
}
}
if(($event instanceof PageRequestEvent) && $event->page_matches("pm")) {
$database = $event->context->database;
$config = $event->context->config;
$user = $event->config->user;
if(!$user->is_anonymous()) {
switch($event->get_arg(0)) {
case "read":
$pm_id = int_escape($event->get_arg(1));
$pm = $database->get_row("SELECT * FROM private_message WHERE id = ?", array($pm_id));
if(is_null($pm)) {
$this->theme->display_error($event->page, "No such PM", "There is no PM #$pm_id");
$this->theme->display_error($page, "No such PM", "There is no PM #$pm_id");
}
else if(($pm["to_id"] == $user->id) || $user->is_admin()) {
$from_user = User::by_id($config, $database, int_escape($pm["from_id"]));
$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($event->page, $from_user, $event->user, $pm);
$this->theme->display_message($page, $from_user, $user, $pm);
}
else {
// permission denied
@ -79,13 +76,13 @@ class PM implements Extension {
$pm_id = int_escape($event->get_arg(1));
$pm = $database->get_row("SELECT * FROM private_message WHERE id = ?", array($pm_id));
if(is_null($pm)) {
$this->theme->display_error($event->page, "No such PM", "There is no PM #$pm_id");
$this->theme->display_error($page, "No such PM", "There is no PM #$pm_id");
}
else if(($pm["to_id"] == $user->id) || $user->is_admin()) {
$database->execute("DELETE FROM private_message WHERE id = ?", array($pm_id));
log_info("pm", "Deleted PM #$pm_id");
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("user"));
$page->set_mode("redirect");
$page->set_redirect(make_link("user"));
}
else {
// permission denied
@ -96,16 +93,16 @@ class PM implements Extension {
$from_id = $user->id;
$subject = $_POST["subject"];
$message = $_POST["message"];
send_event(new SendPMEvent($event->context, $from_id, $_SERVER["REMOTE_ADDR"], $to_id, $subject, $message));
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link($_SERVER["REFERER"]));
send_event(new SendPMEvent($from_id, $_SERVER["REMOTE_ADDR"], $to_id, $subject, $message));
$page->set_mode("redirect");
$page->set_redirect(make_link($_SERVER["REFERER"]));
break;
}
}
}
if($event instanceof SendPMEvent) {
$event->context->database->execute("
$database->execute("
INSERT INTO private_message(
from_id, from_ip, to_id,
sent_date, subject, message)
@ -117,9 +114,8 @@ class PM implements Extension {
}
}
protected function install(RequestContext $context) {
$database = $context->database;
$config = $context->config;
protected function install() {
global $config, $database;
// shortcut to latest
if($config->get_int("pm_version") < 1) {

View File

@ -23,12 +23,10 @@ class RandomImage implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if(($event instanceof PageRequestEvent) && $event->page_matches("random_image")) {
global $config;
global $database;
if($event->count_args() == 1) {
$action = $event->get_arg(0);
$search_terms = array();
@ -37,18 +35,18 @@ class RandomImage implements Extension {
$action = $event->get_arg(0);
$search_terms = explode(' ', $event->get_arg(1));
}
$image = Image::by_random($config, $database, $search_terms);
$image = Image::by_random($search_terms);
if($event->get_arg(0) == "download") {
if(!is_null($image)) {
$event->page->set_mode("data");
$event->page->set_type("image/jpeg");
$event->page->set_data(file_get_contents($image->get_image_filename()));
$page->set_mode("data");
$page->set_type("image/jpeg");
$page->set_data(file_get_contents($image->get_image_filename()));
}
}
if($event->get_arg(0) == "view") {
if(!is_null($image)) {
send_event(new DisplayingImageEvent($image, $event->page));
send_event(new DisplayingImageEvent($image, $page));
}
}
}
@ -60,11 +58,10 @@ class RandomImage implements Extension {
}
if($event instanceof PostListBuildingEvent) {
global $config, $database;
if($config->get_bool("show_random_block")) {
$image = Image::by_random($config, $database, $event->search_terms);
$image = Image::by_random($event->search_terms);
if(!is_null($image)) {
$this->theme->display_random($event->page, $image);
$this->theme->display_random($page, $image);
}
}
}

View File

@ -20,15 +20,14 @@ class Ratings implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof InitExtEvent) {
global $config;
if($config->get_int("ext_ratings2_version") < 2) {
$this->install();
}
global $config;
$config->set_default_string("ext_rating_anon_privs", 'sq');
$config->set_default_string("ext_rating_user_privs", 'sq');
}
@ -38,14 +37,12 @@ class Ratings implements Extension {
}
if($event instanceof ImageInfoBoxBuildingEvent) {
global $user;
if($user->is_admin()) {
$event->add_part($this->theme->get_rater_html($event->image->id, $event->image->rating), 80);
}
}
if($event instanceof ImageInfoSetEvent) {
global $user;
if($user->is_admin()) {
send_event(new RatingSetEvent($event->image->id, $user, $_POST['rating']));
}
@ -70,7 +67,6 @@ class Ratings implements Extension {
if($event instanceof SearchTermParseEvent) {
$matches = array();
if(is_null($event->term) && $this->no_rating_query($event->context)) {
global $user, $config;
if($user->is_anonymous()) {
$sqes = $config->get_string("ext_rating_anon_privs");
}

View File

@ -23,7 +23,7 @@ class RegenThumb implements Extension {
if($user->is_admin() && isset($_POST['image_id'])) {
global $config;
global $database;
$image = Image::by_id($config, $database, int_escape($_POST['image_id']));
$image = Image::by_id(int_escape($_POST['image_id']));
send_event(new ThumbnailGenerationEvent($image->hash, $image->ext));
$this->theme->display_results($event->page, $image);
}

View File

@ -33,11 +33,10 @@ class ReportImage implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof InitExtEvent) {
global $config;
$config->set_default_bool('report_image_show_thumbs', true);
if($config->get_int("ext_report_image_version") < 1) {
@ -46,33 +45,31 @@ class ReportImage implements Extension {
}
if(($event instanceof PageRequestEvent) && $event->page_matches("image_report")) {
global $user;
if($event->get_arg(0) == "add") {
if(isset($_POST['image_id']) && isset($_POST['reason'])) {
$image_id = int_escape($_POST['image_id']);
send_event(new AddReportedImageEvent($image_id, $event->user->id, $_POST['reason']));
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("post/view/$image_id"));
send_event(new AddReportedImageEvent($image_id, $user->id, $_POST['reason']));
$page->set_mode("redirect");
$page->set_redirect(make_link("post/view/$image_id"));
}
}
else if($event->get_arg(0) == "remove") {
if(isset($_POST['id'])) {
if($event->user->is_admin()) {
if($user->is_admin()) {
send_event(new RemoveReportedImageEvent($_POST['id']));
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("image_report/list"));
$page->set_mode("redirect");
$page->set_redirect(make_link("image_report/list"));
}
}
}
else if($event->get_arg(0) == "list") {
if($event->user->is_admin()) {
$this->theme->display_reported_images($event->page, $this->get_reported_images());
if($user->is_admin()) {
$this->theme->display_reported_images($page, $this->get_reported_images());
}
}
}
if($event instanceof AddReportedImageEvent) {
global $database;
$database->Execute(
"INSERT INTO image_reports(image_id, reporter_id, reason)
VALUES (?, ?, ?)",
@ -80,13 +77,12 @@ class ReportImage implements Extension {
}
if($event instanceof RemoveReportedImageEvent) {
global $database;
$database->Execute("DELETE FROM image_reports WHERE id = ?", array($event->id));
}
if($event instanceof DisplayingImageEvent) {
if($event->context->config->get_bool('report_image_anon') || !$event->context->user->is_anonymous()) {
$this->theme->display_image_banner($event->page, $event->image);
if($config->get_bool('report_image_anon') || !$user->is_anonymous()) {
$this->theme->display_image_banner($page, $event->image);
}
}
@ -98,13 +94,12 @@ class ReportImage implements Extension {
}
if($event instanceof UserBlockBuildingEvent) {
if($event->user->is_admin()) {
if($user->is_admin()) {
$event->add_link("Reported Images", make_link("image_report/list"));
}
}
if($event instanceof ImageDeletionEvent) {
global $database;
$database->Execute("DELETE FROM image_reports WHERE image_id = ?", array($event->image->id));
}
}
@ -126,7 +121,7 @@ class ReportImage implements Extension {
}
public function get_reported_images() {
global $database;
global $config, $database;
$all_reports = $database->get_all("
SELECT image_reports.*, users.name AS reporter_name
FROM image_reports
@ -135,9 +130,8 @@ class ReportImage implements Extension {
$reports = array();
foreach($all_reports as $report) {
global $database, $config;
$image_id = int_escape($report['image_id']);
$image = Image::by_id($config, $database, $image_id);
$image = Image::by_id($image_id);
if(is_null($image)) {
send_event(new RemoveReportedImageEvent($report['id']));
continue;

View File

@ -9,9 +9,9 @@
class RSS_Images implements Extension {
// event handling {{{
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if($event instanceof PostListBuildingEvent) {
global $page;
global $config;
$title = $config->get_string('title');
if(count($event->search_terms) > 0) {
@ -26,9 +26,6 @@ class RSS_Images implements Extension {
}
if(($event instanceof PageRequestEvent) && $event->page_matches("rss/images")) {
global $config;
global $database;
$page_number = 0;
$search_terms = array();
@ -45,7 +42,7 @@ class RSS_Images implements Extension {
$page_number = int_escape($event->get_arg(1));
}
$images = Image::find_images($config, $database, ($page_number-1)*10, 10, $search_terms);
$images = Image::find_images(($page_number-1)*10, 10, $search_terms);
$this->do_rss($images, $search_terms, $page_number);
}
}

View File

@ -25,19 +25,20 @@ class SimpleSCoreTest implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if(($event instanceof PageRequestEvent) && $event->page_matches("test")) {
$event->page->set_title("Test Results");
$event->page->set_heading("Test Results");
$event->page->add_block(new NavBlock());
$page->set_title("Test Results");
$page->set_heading("Test Results");
$page->add_block(new NavBlock());
$all = new TestFinder($event->get_arg(0));
$all->run(new SCoreReporter($event->page));
$all->run(new SCoreReporter($page));
}
if($event instanceof UserBlockBuildingEvent) {
if($event->user->is_admin()) {
if($user->is_admin()) {
$event->add_link("Run Tests", make_link("test/all"));
}
}

View File

@ -1,8 +1,10 @@
<?php
#require_once('lib/simpletest/autorun.php');
require_once('simpletest/web_tester.php');
#require_once('simpletest/unit_tester.php'); # unit tests require shimmie to be running
require_once('simpletest/reporter.php');
chdir("../../");
require_once('config.php');
class SectionReporter extends TextReporter {
@ -11,7 +13,6 @@ class SectionReporter extends TextReporter {
print "\n** $name\n";
}
}
// }}} */
class AllTests extends TestSuite {
function AllTests() {

View File

@ -10,10 +10,11 @@
*/
class SiteDescription implements Extension {
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if($event instanceof PageRequestEvent) {
if(strlen($event->context->config->get_string("site_description")) > 0) {
$description = $event->context->config->get_string("site_description");
$event->context->page->add_header("<meta name=\"description\" content=\"$description\">");
if(strlen($config->get_string("site_description")) > 0) {
$description = $config->get_string("site_description");
$page->add_header("<meta name=\"description\" content=\"$description\">");
}
}

View File

@ -9,11 +9,11 @@ class Tag_History implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if(($event instanceof InitExtEvent)) {
// shimmie is being installed so call install to create the table.
global $config;
if($config->get_int("ext_tag_history_version") < 3) {
$this->install();
}
@ -24,7 +24,6 @@ class Tag_History implements Extension {
if($event->get_arg(0) == "revert")
{
// this is a request to revert to a previous version of the tags
global $config, $user;
if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) {
$this->process_revert_request($_POST['revert']);
}
@ -33,16 +32,16 @@ class Tag_History implements Extension {
{
// must be an attempt to view a tag history
$image_id = int_escape($event->get_arg(0));
$this->theme->display_history_page($event->page, $image_id, $this->get_tag_history_from_id($image_id));
$this->theme->display_history_page($page, $image_id, $this->get_tag_history_from_id($image_id));
}
else {
$this->theme->display_global_page($event->page, $this->get_global_tag_history());
$this->theme->display_global_page($page, $this->get_global_tag_history());
}
}
if(($event instanceof DisplayingImageEvent))
{
// handle displaying a link on the view page
$this->theme->display_history_link($event->page, $event->image->id);
$this->theme->display_history_link($page, $event->image->id);
}
if(($event instanceof ImageDeletionEvent))
{

View File

@ -44,7 +44,7 @@ class WikiPage {
public function get_owner() {
global $config;
global $database;
return User::by_id($config, $database, $this->owner_id);
return User::by_id($this->owner_id);
}
public function is_locked() {

View File

@ -1,4 +1,8 @@
<?php
class WordFiterTest extends WebTestCase {}
if(!defined(VERSION)) return;
class WordFilterUnitTest extends UnitTestCase {
public function testURL() {
$this->assertEqual(

View File

@ -10,11 +10,11 @@ class Zoom implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if($this->theme == null) $this->theme = get_theme_object($this);
if($event instanceof DisplayingImageEvent) {
global $config;
$this->theme->display_zoomer($event->page, $event->image, $config->get_bool("image_zoom", false));
$this->theme->display_zoomer($page, $event->image, $config->get_bool("image_zoom", false));
}
if($event instanceof SetupBuildingEvent) {

View File

@ -4,11 +4,7 @@
* generic parent class
*/
abstract class Event {
var $context;
public function __construct(RequestContext $context) {
$this->context = $context;
}
public function __construct() {}
}
@ -32,12 +28,9 @@ class PageRequestEvent extends Event {
var $part_count;
public function __construct(RequestContext $context, $args) {
parent::__construct($context);
public function __construct($args) {
$this->args = $args;
$this->arg_count = count($args);
$this->page = $context->page;
$this->user = $context->user;
}
public function page_matches($name) {
@ -105,8 +98,7 @@ class LogEvent extends Event {
var $message;
var $time;
public function __construct($context, $section, $priority, $message) {
parent::__construct($context);
public function __construct($section, $priority, $message) {
$this->section = $section;
$this->priority = $priority;
$this->message = $message;
@ -114,8 +106,9 @@ class LogEvent extends Event {
// this should be an extension
/*
global $user;
$ftime = date("Y-m-d H:i:s", $this->time);
$username = $context->user->name;
$username = $user->name;
$ip = $_SERVER['REMOTE_ADDR'];
$fp = fopen("shimmie.log", "a");
fputs($fp, "$ftime\t$section/$priority\t$username/$ip\t$message\n");

View File

@ -15,9 +15,6 @@
* sound file, or any other supported upload type.
*/
class Image {
var $config;
var $database;
var $id = null;
var $height, $width;
var $hash, $filesize;
@ -30,12 +27,6 @@ class Image {
* Constructors and other instance creators
*/
public function Image($row=null) {
global $config;
global $database;
$this->config = $config;
$this->database = $database;
if(!is_null($row)) {
foreach($row as $name => $value) {
// FIXME: some databases use table.name rather than name
@ -45,37 +36,43 @@ class Image {
}
}
public static function by_id(Config $config, Database $database, $id) {
public static function by_id($id) {
assert(is_numeric($id));
global $database;
$image = null;
$row = $database->get_row("SELECT * FROM images WHERE images.id=?", array($id));
return ($row ? new Image($row) : null);
}
public static function by_hash(Config $config, Database $database, $hash) {
public static function by_hash($hash) {
assert(is_string($hash));
global $database;
$image = null;
$row = $database->db->GetRow("SELECT images.* FROM images WHERE hash=?", array($hash));
return ($row ? new Image($row) : null);
}
public static function by_random(Config $config, Database $database, $tags=array()) {
$max = Image::count_images($config, $database, $tags);
public static function by_random($tags=array()) {
assert(is_array($tags));
$max = Image::count_images($tags);
$rand = mt_rand(0, $max-1);
$set = Image::find_images($config, $database, $rand, 1, $tags);
$set = Image::find_images($rand, 1, $tags);
if(count($set) > 0) return $set[0];
else return null;
}
public static function find_images(Config $config, Database $database, $start, $limit, $tags=array()) {
$images = array();
public static function find_images($start, $limit, $tags=array()) {
assert(is_numeric($start));
assert(is_numeric($limit));
assert(is_array($tags));
global $database;
$images = array();
if($start < 0) $start = 0;
if($limit < 1) $limit = 1;
$querylet = Image::build_search_querylet($config, $database, $tags);
$querylet = Image::build_search_querylet($tags);
$querylet->append(new Querylet("ORDER BY images.id DESC LIMIT ? OFFSET ?", array($limit, $start)));
$result = $database->execute($querylet->sql, $querylet->variables);
@ -89,20 +86,24 @@ class Image {
/*
* Image-related utility functions
*/
public static function count_images(Config $config, Database $database, $tags=array()) {
public static function count_images($tags=array()) {
assert(is_array($tags));
global $database;
if(count($tags) == 0) {
return $database->db->GetOne("SELECT COUNT(*) FROM images");
}
else {
$querylet = Image::build_search_querylet($config, $database, $tags);
$querylet = Image::build_search_querylet($tags);
$result = $database->execute($querylet->sql, $querylet->variables);
return $result->RecordCount();
}
}
public static function count_pages(Config $config, Database $database, $tags=array()) {
public static function count_pages($tags=array()) {
assert(is_array($tags));
global $config, $database;
$images_per_page = $config->get_int('index_width') * $config->get_int('index_height');
return ceil(Image::count_images($config, $database, $tags) / $images_per_page);
return ceil(Image::count_images($tags) / $images_per_page);
}
@ -112,6 +113,7 @@ class Image {
public function get_next($tags=array(), $next=true) {
assert(is_array($tags));
assert(is_bool($next));
global $database;
if($next) {
$gtlt = "<";
@ -123,13 +125,13 @@ class Image {
}
if(count($tags) == 0) {
$row = $this->database->db->GetRow("SELECT images.* FROM images WHERE images.id $gtlt {$this->id} ORDER BY images.id $dir LIMIT 1");
$row = $database->db->GetRow("SELECT images.* FROM images WHERE images.id $gtlt {$this->id} ORDER BY images.id $dir LIMIT 1");
}
else {
$tags[] = "id$gtlt{$this->id}";
$querylet = Image::build_search_querylet($this->config, $this->database, $tags);
$querylet = Image::build_search_querylet($tags);
$querylet->append_sql(" ORDER BY images.id $dir LIMIT 1");
$row = $this->database->db->GetRow($querylet->sql, $querylet->variables);
$row = $database->db->GetRow($querylet->sql, $querylet->variables);
}
return ($row ? new Image($row) : null);
@ -140,23 +142,24 @@ class Image {
}
public function get_owner() {
return User::by_id($this->config, $this->database, $this->owner_id);
return User::by_id($this->owner_id);
}
public function get_tag_array() {
$cached = $this->database->cache->get("image-{$this->id}-tags");
global $database;
$cached = $database->cache->get("image-{$this->id}-tags");
if($cached) return $cached;
if(!isset($this->tag_array)) {
$this->tag_array = Array();
$row = $this->database->Execute("SELECT tag FROM image_tags JOIN tags ON image_tags.tag_id = tags.id WHERE image_id=? ORDER BY tag", array($this->id));
$row = $database->Execute("SELECT tag FROM image_tags JOIN tags ON image_tags.tag_id = tags.id WHERE image_id=? ORDER BY tag", array($this->id));
while(!$row->EOF) {
$this->tag_array[] = $row->fields['tag'];
$row->MoveNext();
}
}
$this->database->cache->set("image-{$this->id}-tags", $this->tag_array);
$database->cache->set("image-{$this->id}-tags", $this->tag_array);
return $this->tag_array;
}
@ -165,11 +168,11 @@ class Image {
}
public function get_image_link() {
$c = $this->config;
if(strlen($c->get_string('image_ilink')) > 0) {
global $config;
if(strlen($config->get_string('image_ilink')) > 0) {
return $this->parse_link_template($c->get_string('image_ilink'));
}
else if($c->get_bool('nice_urls', false)) {
else if($config->get_bool('nice_urls', false)) {
return $this->parse_link_template(make_link('_images/$hash/$id - $tags.$ext'));
}
else {
@ -178,15 +181,16 @@ class Image {
}
public function get_short_link() {
return $this->parse_link_template($this->config->get_string('image_slink'));
global $config;
return $this->parse_link_template($config->get_string('image_slink'));
}
public function get_thumb_link() {
$c = $this->config;
if(strlen($c->get_string('image_tlink')) > 0) {
global $config;
if(strlen($config->get_string('image_tlink')) > 0) {
return $this->parse_link_template($c->get_string('image_tlink'));
}
else if($c->get_bool('nice_urls', false)) {
else if($config->get_bool('nice_urls', false)) {
return $this->parse_link_template(make_link('_thumbs/$hash/thumb.jpg'));
}
else {
@ -229,18 +233,21 @@ class Image {
}
public function set_source($source) {
global $database;
if(empty($source)) $source = null;
$this->database->execute("UPDATE images SET source=? WHERE id=?", array($source, $this->id));
$database->execute("UPDATE images SET source=? WHERE id=?", array($source, $this->id));
}
public function delete_tags_from_image() {
$this->database->execute(
global $database;
$database->execute(
"UPDATE tags SET count = count - 1 WHERE id IN ".
"(SELECT tag_id FROM image_tags WHERE image_id = ?)", array($this->id));
$this->database->execute("DELETE FROM image_tags WHERE image_id=?", array($this->id));
$database->execute("DELETE FROM image_tags WHERE image_id=?", array($this->id));
}
public function set_tags($tags) {
global $database;
$tags = Tag::resolve_list($tags);
assert(is_array($tags));
@ -251,32 +258,32 @@ class Image {
// insert each new tags
foreach($tags as $tag) {
$id = $this->database->db->GetOne(
$id = $database->db->GetOne(
"SELECT id FROM tags WHERE tag = ?",
array($tag));
if(empty($id)) {
// a new tag
$this->database->execute(
$database->execute(
"INSERT INTO tags(tag) VALUES (?)",
array($tag));
$this->database->execute(
$database->execute(
"INSERT INTO image_tags(image_id, tag_id)
VALUES(?, (SELECT id FROM tags WHERE tag = ?))",
array($this->id, $tag));
}
else {
// user of an existing tag
$this->database->execute(
$database->execute(
"INSERT INTO image_tags(image_id, tag_id) VALUES(?, ?)",
array($this->id, $id));
}
$this->database->execute(
$database->execute(
"UPDATE tags SET count = count + 1 WHERE tag = ?",
array($tag));
}
log_info("core-image", "Tags for Image #{$this->id} set to: ".implode(" ", $tags));
$this->database->cache->delete("image-{$this->id}-tags");
$database->cache->delete("image-{$this->id}-tags");
}
@ -284,8 +291,9 @@ class Image {
* Other actions
*/
public function delete() {
$this->delete_tags_from_image();
$this->database->execute("DELETE FROM images WHERE id=?", array($this->id));
global $database;
$delete_tags_from_image();
$database->execute("DELETE FROM images WHERE id=?", array($this->id));
log_info("core-image", "Deleted Image #{$image->id} ({$image->hash})");
unlink($this->get_image_filename());
@ -293,6 +301,8 @@ class Image {
}
public function parse_link_template($tmpl, $_escape="url_escape") {
global $config;
// don't bother hitting the database if it won't be used...
$safe_tags = "";
if(strpos($tmpl, '$tags') !== false) { // * stabs dynamically typed languages with a rusty spoon *
@ -301,7 +311,7 @@ class Image {
"", $this->get_tag_list());
}
$base_href = $this->config->get_string('base_href');
$base_href = $config->get_string('base_href');
$fname = $this->get_filename();
$base_fname = strpos($fname, '.') ? substr($fname, 0, strrpos($fname, '.')) : $fname;
@ -313,7 +323,7 @@ class Image {
$tmpl = str_replace('$size', "{$this->width}x{$this->height}", $tmpl);
$tmpl = str_replace('$filesize', to_shorthand_int($this->filesize), $tmpl);
$tmpl = str_replace('$filename', $_escape($base_fname), $tmpl);
$tmpl = str_replace('$title', $_escape($this->config->get_string("title")), $tmpl);
$tmpl = str_replace('$title', $_escape($config->get_string("title")), $tmpl);
$plte = new ParseLinkTemplateEvent($tmpl, $this);
send_event($plte);
@ -322,16 +332,20 @@ class Image {
return $tmpl;
}
private static function build_search_querylet(Config $config, Database $database, $terms) {
private static function build_search_querylet($terms) {
assert(is_array($terms));
global $database;
if($database->engine->name == "mysql")
return Image::build_ugly_search_querylet($config, $database, $terms);
return Image::build_ugly_search_querylet($terms);
else
return Image::build_accurate_search_querylet($config, $database, $terms);
return Image::build_accurate_search_querylet($terms);
}
// this method is simple, fast and accurate; but mysql chokes on it
// because it uses subqueries
private static function build_accurate_search_querylet(Config $config, Database $database, $terms) {
private static function build_accurate_search_querylet($terms) {
global $config, $database;
$tag_querylets = array();
$img_querylets = array();
$positive_tag_count = 0;
@ -483,7 +497,9 @@ class Image {
}
// this function exists because mysql is a turd.
private static function build_ugly_search_querylet(Config $config, Database $database, $terms) {
private static function build_ugly_search_querylet($terms) {
global $config, $database;
$tag_querylets = array();
$img_querylets = array();
$positive_tag_count = 0;

View File

@ -70,7 +70,9 @@ class GenericPage {
// ==============================================
public function display($context) {
public function display() {
global $page;
header("Content-type: {$this->type}");
header("X-Powered-By: SCore-".SCORE_VERSION);
@ -79,7 +81,7 @@ class GenericPage {
header("Cache-control: no-cache");
usort($this->blocks, "blockcmp");
$layout = new Layout();
$layout->display_page($context);
$layout->display_page($page);
break;
case "data":
if(!is_null($this->filename)) {

View File

@ -1,11 +0,0 @@
<?php
/*
* The context for a request, should be used instead of global variables
*/
class RequestContext {
var $database;
var $config;
var $user;
var $page;
}
?>

View File

@ -21,10 +21,7 @@ class User {
* $user = User::by_name($config, $database, "bob"); *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
public function User(Config $config, Database $database, $row) {
$this->config = $config;
$this->database = $database;
public function User($row) {
$this->id = int_escape($row['id']);
$this->name = $row['name'];
$this->email = $row['email'];
@ -32,32 +29,36 @@ class User {
$this->admin = ($row['admin'] == 'Y');
}
public static function by_session(Config $config, Database $database, $name, $session) {
public static function by_session($name, $session) {
global $config, $database;
$row = $database->get_row(
"SELECT * FROM users WHERE name = ? AND md5(concat(pass, ?)) = ?",
array($name, get_session_ip($config), $session)
);
return is_null($row) ? null : new User($config, $database, $row);
return is_null($row) ? null : new User($row);
}
public static function by_id(Config $config, Database $database, $id) {
public static function by_id($id) {
assert(is_numeric($id));
global $database;
$row = $database->get_row("SELECT * FROM users WHERE id = ?", array($id));
return is_null($row) ? null : new User($config, $database, $row);
return is_null($row) ? null : new User($row);
}
public static function by_name(Config $config, Database $database, $name) {
public static function by_name($name) {
assert(is_string($name));
global $database;
$row = $database->get_row("SELECT * FROM users WHERE name = ?", array($name));
return is_null($row) ? null : new User($config, $database, $row);
return is_null($row) ? null : new User($row);
}
public static function by_name_and_hash(Config $config, Database $database, $name, $hash) {
public static function by_name_and_hash($name, $hash) {
assert(is_string($name));
assert(is_string($hash));
assert(strlen($hash) == 32);
global $database;
$row = $database->get_row("SELECT * FROM users WHERE name = ? AND pass = ?", array($name, $hash));
return is_null($row) ? null : new User($config, $database, $row);
return is_null($row) ? null : new User($row);
}
@ -67,7 +68,8 @@ class User {
public function is_anonymous() {
return ($this->id == $this->config->get_int('anon_id'));
global $config;
return ($this->id == $config->get_int('anon_id'));
}
public function is_admin() {
@ -76,14 +78,16 @@ class User {
public function set_admin($admin) {
assert(is_bool($admin));
global $database;
$yn = $admin ? 'Y' : 'N';
$this->database->Execute("UPDATE users SET admin=? WHERE id=?", array($yn, $this->id));
$database->Execute("UPDATE users SET admin=? WHERE id=?", array($yn, $this->id));
log_info("core-user", "Made {$this->name} admin=$yn");
}
public function set_password($password) {
global $database;
$hash = md5(strtolower($this->name) . $password);
$this->database->Execute("UPDATE users SET pass=? WHERE id=?", array($hash, $this->id));
$database->Execute("UPDATE users SET pass=? WHERE id=?", array($hash, $this->id));
log_info("core-user", "Set password for {$this->name}");
}
}

View File

@ -227,8 +227,7 @@ define("LOG_DEBUG", 10);
define("LOG_NOTSET", 0);
function log_msg($section, $priority, $message) {
global $context;
send_event(new LogEvent($context, $section, $priority, $message));
send_event(new LogEvent($section, $priority, $message));
}
function log_info($section, $message) {
@ -456,26 +455,28 @@ function _get_query_parts() {
}
}
function _get_page_request($context) {
function _get_page_request() {
global $config;
$args = _get_query_parts();
if(count($args) == 0 || strlen($args[0]) == 0) {
$args = split('/', $context->config->get_string('front_page'));
$args = split('/', $config->get_string('front_page'));
}
return new PageRequestEvent($context, $args);
return new PageRequestEvent($args);
}
function _get_user($config, $database) {
function _get_user() {
global $config, $database;
$user = null;
if(isset($_COOKIE["shm_user"]) && isset($_COOKIE["shm_session"])) {
$tmp_user = User::by_session($config, $database, $_COOKIE["shm_user"], $_COOKIE["shm_session"]);
$tmp_user = User::by_session($_COOKIE["shm_user"], $_COOKIE["shm_session"]);
if(!is_null($tmp_user)) {
$user = $tmp_user;
}
}
if(is_null($user)) {
$user = User::by_id($config, $database, $config->get_int("anon_id", 0));
$user = User::by_id($config->get_int("anon_id", 0));
}
assert(!is_null($user));
return $user;

View File

@ -15,34 +15,33 @@ class AdminPage implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if(($event instanceof PageRequestEvent) && $event->page_matches("admin")) {
if(!$event->user->is_admin()) {
$this->theme->display_permission_denied($event->page);
if(!$user->is_admin()) {
$this->theme->display_permission_denied($page);
}
else {
if($event->get_arg(0) == "delete_image") {
// FIXME: missing lots of else {complain}
if(isset($_POST['image_id'])) {
global $config;
global $database;
$image = Image::by_id($config, $database, $_POST['image_id']);
$image = Image::by_id($_POST['image_id']);
if($image) {
send_event(new ImageDeletionEvent($image));
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("post/list"));
$page->set_mode("redirect");
$page->set_redirect(make_link("post/list"));
}
}
}
else {
send_event(new AdminBuildingEvent($event->page));
send_event(new AdminBuildingEvent($page));
}
}
}
if(($event instanceof PageRequestEvent) && $event->page_matches("admin_utils")) {
if($event->user->is_admin()) {
if($user->is_admin()) {
log_info("admin", "Util: {$_POST['action']}");
set_time_limit(0);
$redirect = false;
@ -61,30 +60,30 @@ class AdminPage implements Extension {
$redirect = true;
break;
case 'database dump':
$this->dbdump($event->page);
$this->dbdump($page);
break;
}
if($redirect) {
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("admin"));
$page->set_mode("redirect");
$page->set_redirect(make_link("admin"));
}
}
}
if($event instanceof ImageAdminBlockBuildingEvent) {
if($event->user->is_admin()) {
if($user->is_admin()) {
$event->add_part($this->theme->get_deleter_html($event->image->id));
}
}
if($event instanceof AdminBuildingEvent) {
$this->theme->display_page($event->page);
$this->theme->display_form($event->page);
$this->theme->display_page($page);
$this->theme->display_form($page);
}
if($event instanceof UserBlockBuildingEvent) {
if($event->user->is_admin()) {
if($user->is_admin()) {
$event->add_link("Board Admin", make_link("admin"));
}
}

View File

@ -16,64 +16,62 @@ class AliasEditor implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if(($event instanceof PageRequestEvent) && $event->page_matches("alias")) {
if($event->get_arg(0) == "add") {
if($event->user->is_admin()) {
if($user->is_admin()) {
if(isset($_POST['oldtag']) && isset($_POST['newtag'])) {
try {
$aae = new AddAliasEvent($_POST['oldtag'], $_POST['newtag']);
send_event($aae);
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("alias/list"));
$page->set_mode("redirect");
$page->set_redirect(make_link("alias/list"));
}
catch(AddAliasException $ex) {
$this->theme->display_error($event->page, "Error adding alias", $ex->getMessage());
$this->theme->display_error($page, "Error adding alias", $ex->getMessage());
}
}
}
}
else if($event->get_arg(0) == "remove") {
if($event->user->is_admin()) {
if($user->is_admin()) {
if(isset($_POST['oldtag'])) {
global $database;
$database->Execute("DELETE FROM aliases WHERE oldtag=?", array($_POST['oldtag']));
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("alias/list"));
$page->set_mode("redirect");
$page->set_redirect(make_link("alias/list"));
}
}
}
else if($event->get_arg(0) == "list") {
global $database;
$this->theme->display_aliases($event->page,
$this->theme->display_aliases($page,
$database->db->GetAssoc("SELECT oldtag, newtag FROM aliases ORDER BY newtag"),
$event->user->is_admin());
$user->is_admin());
}
else if($event->get_arg(0) == "export") {
global $database;
$event->page->set_mode("data");
$event->page->set_type("text/plain");
$event->page->set_data($this->get_alias_csv($database));
$page->set_mode("data");
$page->set_type("text/plain");
$page->set_data($this->get_alias_csv($database));
}
else if($event->get_arg(0) == "import") {
if($event->user->is_admin()) {
if($user->is_admin()) {
print_r($_FILES);
if(count($_FILES) > 0) {
global $database;
$tmp = $_FILES['alias_file']['tmp_name'];
$contents = file_get_contents($tmp);
$this->add_alias_csv($database, $contents);
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("alias/list"));
$page->set_mode("redirect");
$page->set_redirect(make_link("alias/list"));
}
else {
$this->theme->display_error($event->page, "No File Specified", "You have to upload a file");
$this->theme->display_error($page, "No File Specified", "You have to upload a file");
}
}
else {
$this->theme->display_error($event->page, "Admins Only", "Only admins can edit the alias list");
$this->theme->display_error($page, "Admins Only", "Only admins can edit the alias list");
}
}
}
@ -90,7 +88,7 @@ class AliasEditor implements Extension {
}
if($event instanceof UserBlockBuildingEvent) {
if($event->user->is_admin()) {
if($user->is_admin()) {
$event->add_link("Alias Editor", make_link("alias/list"));
}
}

View File

@ -1,4 +1,8 @@
<?php
class BBCodeTest extends WebTestCase {}
if(!defined(VERSION)) return;
class BBCodeUnitTest extends UnitTestCase {
public function testBasics() {
$this->assertEqual(

View File

@ -58,6 +58,8 @@ class CommentList implements Extension {
var $theme;
// event handler {{{
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof InitExtEvent) {
@ -76,32 +78,32 @@ class CommentList implements Extension {
if($event->get_arg(0) == "add") {
if(isset($_POST['image_id']) && isset($_POST['comment'])) {
try {
$cpe = new CommentPostingEvent($_POST['image_id'], $event->user, $_POST['comment']);
$cpe = new CommentPostingEvent($_POST['image_id'], $user, $_POST['comment']);
send_event($cpe);
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("post/view/".int_escape($_POST['image_id'])));
$page->set_mode("redirect");
$page->set_redirect(make_link("post/view/".int_escape($_POST['image_id'])));
}
catch(CommentPostingException $ex) {
$this->theme->display_error($event->page, "Comment Blocked", $ex->getMessage());
$this->theme->display_error($page, "Comment Blocked", $ex->getMessage());
}
}
}
else if($event->get_arg(0) == "delete") {
if($event->user->is_admin()) {
if($user->is_admin()) {
// FIXME: post, not args
if($event->count_args() == 3) {
send_event(new CommentDeletionEvent($event->get_arg(1)));
$event->page->set_mode("redirect");
$page->set_mode("redirect");
if(!empty($_SERVER['HTTP_REFERER'])) {
$event->page->set_redirect($_SERVER['HTTP_REFERER']);
$page->set_redirect($_SERVER['HTTP_REFERER']);
}
else {
$event->page->set_redirect(make_link("post/view/".$event->get_arg(2)));
$page->set_redirect(make_link("post/view/".$event->get_arg(2)));
}
}
}
else {
$this->theme->display_permission_denied($event->page);
$this->theme->display_permission_denied($page);
}
}
else if($event->get_arg(0) == "list") {
@ -110,19 +112,18 @@ class CommentList implements Extension {
}
if($event instanceof PostListBuildingEvent) {
global $config;
$cc = $config->get_int("comment_count");
if($cc > 0) {
$recent = $this->get_recent_comments($cc);
if(count($recent) > 0) {
$this->theme->display_recent_comments($event->page, $recent);
$this->theme->display_recent_comments($page, $recent);
}
}
}
if($event instanceof DisplayingImageEvent) {
$this->theme->display_comments(
$event->page,
$page,
$this->get_comments($event->image->id),
$this->can_comment(),
$event->image->id);
@ -228,7 +229,7 @@ class CommentList implements Extension {
$n = 10;
while(!$result->EOF) {
$image = Image::by_id($config, $database, $result->fields["image_id"]);
$image = Image::by_id($result->fields["image_id"]);
$comments = $this->get_comments($image->id);
$this->theme->add_comment_list($page, $image, $comments, $n, $this->can_comment());
$n += 1;
@ -361,7 +362,7 @@ class CommentList implements Extension {
if(!$config->get_bool('comment_anon') && $user->is_anonymous()) {
throw new CommentPostingException("Anonymous posting has been disabled");
}
else if(is_null(Image::by_id($config, $database, $image_id))) {
else if(is_null(Image::by_id($image_id))) {
throw new CommentPostingException("The image does not exist");
}
else if(trim($comment) == "") {

View File

@ -72,38 +72,39 @@ class ExtManager implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if(($event instanceof PageRequestEvent) && $event->page_matches("ext_manager")) {
if($event->user->is_admin()) {
if($user->is_admin()) {
if($event->get_arg(0) == "set") {
if(is_writable("ext")) {
$this->set_things($_POST);
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("ext_manager"));
$page->set_mode("redirect");
$page->set_redirect(make_link("ext_manager"));
}
else {
$this->theme->display_error($event->page, "File Operation Failed",
$this->theme->display_error($page, "File Operation Failed",
"The extension folder isn't writable by the web server :(");
}
}
else {
$this->theme->display_table($event->page, $this->get_extensions());
$this->theme->display_table($page, $this->get_extensions());
}
}
else {
$this->theme->display_permission_denied($event->page);
$this->theme->display_permission_denied($page);
}
}
if(($event instanceof PageRequestEvent) && $event->page_matches("ext_doc")) {
$ext = $event->get_arg(0);
$info = new ExtensionInfo("contrib/$ext/main.php");
$this->theme->display_doc($event->page, $info);
$this->theme->display_doc($page, $info);
}
if($event instanceof UserBlockBuildingEvent) {
if($event->user->is_admin()) {
if($user->is_admin()) {
$event->add_link("Extension Manager", make_link("ext_manager"));
}
}

View File

@ -3,7 +3,7 @@
class Handle404 implements Extension {
public function receive_event(Event $event) {
if($event instanceof PageRequestEvent) {
$page = $event->page;
global $page;
// hax.
if($page->mode == "page" && (!isset($page->blocks) || $this->count_main($page->blocks) == 0)) {
$h_pagename = html_escape(implode('/', $event->args));

View File

@ -9,6 +9,7 @@ class PixelFileHandler implements Extension {
var $theme;
public function receive_event(Event $event) {
global $page;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if(($event instanceof DataUploadEvent) && $this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
@ -30,7 +31,7 @@ class PixelFileHandler implements Extension {
}
if(($event instanceof DisplayingImageEvent) && $this->supported_ext($event->image->ext)) {
$this->theme->display_image($event->page, $event->image);
$this->theme->display_image($page, $event->image);
}
}

View File

@ -168,7 +168,7 @@ class ImageIO implements Extension {
/*
* Check for an existing image
*/
$existing = Image::by_hash($config, $database, $image->hash);
$existing = Image::by_hash($image->hash);
if(!is_null($existing)) {
$handler = $config->get_string("upload_collision_handler");
if($handler == "merge") {
@ -204,7 +204,7 @@ class ImageIO implements Extension {
private function send_file($image_id, $type) {
global $config;
global $database;
$image = Image::by_id($config, $database, $image_id);
$image = Image::by_id($image_id);
global $page;
if(!is_null($image)) {

View File

@ -27,12 +27,9 @@ class SearchTermParseEvent extends Event {
}
class PostListBuildingEvent extends Event {
var $page = null;
var $search_terms = null;
public function __construct(RequestContext $context, $search) {
parent::__construct($context);
$this->page = $context->page;
public function __construct($search) {
$this->search_terms = $search;
}
}
@ -41,10 +38,10 @@ class Index implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof InitExtEvent) {
global $config;
$config->set_default_int("index_width", 3);
$config->set_default_int("index_height", 4);
$config->set_default_bool("index_tips", true);
@ -54,12 +51,12 @@ class Index implements Extension {
if(isset($_GET['search'])) {
$search = url_escape(trim($_GET['search']));
if(empty($search)) {
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("post/list/1"));
$page->set_mode("redirect");
$page->set_redirect(make_link("post/list/1"));
}
else {
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("post/list/$search/1"));
$page->set_mode("redirect");
$page->set_redirect(make_link("post/list/$search/1"));
}
return;
}
@ -77,25 +74,22 @@ class Index implements Extension {
if($page_number == 0) $page_number = 1; // invalid -> 0
global $config;
global $database;
$total_pages = Image::count_pages($config, $database, $search_terms);
$total_pages = Image::count_pages($search_terms);
$count = $config->get_int('index_width') * $config->get_int('index_height');
$images = Image::find_images($config, $database, ($page_number-1)*$count, $count, $search_terms);
$images = Image::find_images(($page_number-1)*$count, $count, $search_terms);
if(count($search_terms) == 0 && count($images) == 0 && $page_number == 0) {
$this->theme->display_intro($event->page);
$this->theme->display_intro($page);
}
else if(count($search_terms) > 0 && count($images) == 1) {
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("post/view/{$images[0]->id}"));
$page->set_mode("redirect");
$page->set_redirect(make_link("post/view/{$images[0]->id}"));
}
else {
send_event(new PostListBuildingEvent($event->context, $search_terms));
send_event(new PostListBuildingEvent($search_terms));
$this->theme->set_page($page_number, $total_pages, $search_terms);
$this->theme->display_page($event->page, $images);
$this->theme->display_page($page, $images);
}
}

View File

@ -139,10 +139,10 @@ class Setup implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof InitExtEvent) {
global $config;
$config->set_default_string("title", "Shimmie");
$config->set_default_string("front_page", "post/list");
$config->set_default_string("main_page", "post/list");
@ -151,33 +151,29 @@ class Setup implements Extension {
}
if(($event instanceof PageRequestEvent) && $event->page_matches("nicetest")) {
$event->page->set_mode("data");
$event->page->set_data("ok");
$page->set_mode("data");
$page->set_data("ok");
}
if(($event instanceof PageRequestEvent) && $event->page_matches("setup")) {
global $user;
if(!$user->is_admin()) {
$this->theme->display_permission_denied($event->page);
$this->theme->display_permission_denied($page);
}
else {
if($event->get_arg(0) == "save") {
global $config;
send_event(new ConfigSaveEvent($config));
$config->save();
global $page;
$page->set_mode("redirect");
$page->set_redirect(make_link("setup"));
}
else if($event->get_arg(0) == "advanced") {
global $config;
$this->theme->display_advanced($event->page, $config->values);
$this->theme->display_advanced($page, $config->values);
}
else {
$panel = new SetupPanel();
send_event(new SetupBuildingEvent($panel));
$this->theme->display_page($event->page, $panel);
$this->theme->display_page($page, $panel);
}
}
}
@ -234,22 +230,23 @@ class Setup implements Extension {
}
if($event instanceof ConfigSaveEvent) {
global $config;
foreach($_POST as $_name => $junk) {
if(substr($_name, 0, 6) == "_type_") {
$name = substr($_name, 6);
$type = $_POST["_type_$name"];
$value = isset($_POST["_config_$name"]) ? $_POST["_config_$name"] : null;
switch($type) {
case "string": $event->config->set_string($name, $value); break;
case "int": $event->config->set_int($name, $value); break;
case "bool": $event->config->set_bool($name, $value); break;
case "string": $config->set_string($name, $value); break;
case "int": $config->set_int($name, $value); break;
case "bool": $config->set_bool($name, $value); break;
}
}
}
}
if($event instanceof UserBlockBuildingEvent) {
if($event->user->is_admin()) {
if($user->is_admin()) {
$event->add_link("Board Config", make_link("setup"));
}
}

View File

@ -36,16 +36,14 @@ class TagEdit implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if(($event instanceof PageRequestEvent) && $event->page_matches("tag_edit")) {
global $page;
if($event->get_arg(0) == "replace") {
global $user;
if($user->is_admin() && isset($_POST['search']) && isset($_POST['replace'])) {
$search = $_POST['search'];
$replace = $_POST['replace'];
global $page;
$this->mass_tag_edit($search, $replace);
$page->set_mode("redirect");
$page->set_redirect(make_link("admin"));
@ -61,7 +59,7 @@ class TagEdit implements Extension {
}
}
else {
$this->theme->display_error($event->page, "Error", "Anonymous tag editing is disabled");
$this->theme->display_error($page, "Error", "Anonymous tag editing is disabled");
}
}
@ -78,7 +76,7 @@ class TagEdit implements Extension {
}
if($event instanceof AdminBuildingEvent) {
$this->theme->display_mass_editor($event->page);
$this->theme->display_mass_editor($page);
}
// When an alias is added, oldtag becomes inaccessable
@ -87,8 +85,6 @@ class TagEdit implements Extension {
}
if($event instanceof ImageInfoBoxBuildingEvent) {
global $user;
global $config;
if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) {
$event->add_part($this->theme->get_tag_editor_html($event->image), 40);
}
@ -130,7 +126,7 @@ class TagEdit implements Extension {
$search_forward = $search_set;
if($last_id >= 0) $search_forward[] = "id<$last_id";
$images = Image::find_images($config, $database, 0, 100, $search_forward);
$images = Image::find_images(0, 100, $search_forward);
if(count($images) == 0) break;
foreach($images as $image) {

View File

@ -5,10 +5,10 @@ class TagList implements Extension {
// event handling {{{
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if($this->theme == null) $this->theme = get_theme_object($this);
if($event instanceof InitExtEvent) {
global $config;
$config->set_default_int("tag_list_length", 15);
$config->set_default_int("tags_min", 3);
$config->set_default_string("info_link", 'http://en.wikipedia.org/wiki/$tag');
@ -16,8 +16,6 @@ class TagList implements Extension {
}
if(($event instanceof PageRequestEvent) && $event->page_matches("tags")) {
global $page;
$this->theme->set_navigation($this->build_navigation());
switch($event->get_arg(0)) {
default:
@ -42,25 +40,23 @@ class TagList implements Extension {
}
if($event instanceof PostListBuildingEvent) {
global $config;
if($config->get_int('tag_list_length') > 0) {
if(!empty($event->search_terms)) {
$this->add_refine_block($event->page, $event->search_terms);
$this->add_refine_block($page, $event->search_terms);
}
else {
$this->add_popular_block($event->page);
$this->add_popular_block($page);
}
}
}
if($event instanceof DisplayingImageEvent) {
global $config;
if($config->get_int('tag_list_length') > 0) {
if($config->get_string('tag_list_image_type') == 'related') {
$this->add_related_block($event->page, $event->image);
$this->add_related_block($page, $event->image);
}
else {
$this->add_tags_block($event->page, $event->image);
$this->add_tags_block($page, $event->image);
}
}
}
@ -192,7 +188,7 @@ class TagList implements Extension {
if($n%3==0) $html .= "<tr>";
$h_tag = html_escape($row['tag']);
$link = $this->tag_link($row['tag']);
$image = Image::by_random($config, $database, array($row['tag']));
$image = Image::by_random(array($row['tag']));
if(is_null($image)) continue; // one of the popular tags has no images
$thumb = $image->get_thumb_link();
$html .= "<td><a href='$link'><img src='$thumb'><br>$h_tag</a></td>\n";

View File

@ -3,13 +3,12 @@
class Upgrade implements Extension {
public function receive_event(Event $event) {
if($event instanceof InitExtEvent) {
$this->do_things($event->context);
$this->do_things();
}
}
private function do_things($context) {
$config = $context->config;
$database = $context->database;
private function do_things() {
global $config, $database;
if(!is_numeric($config->get_string("db_version"))) {
$config->set_int("db_version", 2);

View File

@ -30,6 +30,7 @@ class Upload implements Extension {
var $theme;
// event handling {{{
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
$is_full = (disk_free_space(realpath("./images/")) < 100*1024*1024);
@ -45,10 +46,10 @@ class Upload implements Extension {
global $user;
if($this->can_upload($user)) {
if($is_full) {
$this->theme->display_full($event->page);
$this->theme->display_full($page);
}
else {
$this->theme->display_block($event->page);
$this->theme->display_block($page);
}
}
}
@ -57,7 +58,6 @@ class Upload implements Extension {
if(count($_FILES) + count($_POST) > 0) {
$tags = Tag::explode($_POST['tags']);
$source = isset($_POST['source']) ? $_POST['source'] : null;
global $user;
if($this->can_upload($user)) {
$ok = true;
foreach($_FILES as $file) {
@ -69,10 +69,10 @@ class Upload implements Extension {
}
}
$this->theme->display_upload_status($event->page, $ok);
$this->theme->display_upload_status($page, $ok);
}
else {
$this->theme->display_permission_denied($event->page);
$this->theme->display_permission_denied($page);
}
}
else if(!empty($_GET['url'])) {
@ -84,15 +84,15 @@ class Upload implements Extension {
$tags = Tag::explode($_GET['tags']);
}
$ok = $this->try_transload($url, $tags, $url);
$this->theme->display_upload_status($event->page, $ok);
$this->theme->display_upload_status($page, $ok);
}
else {
$this->theme->display_permission_denied($event->page);
$this->theme->display_permission_denied($page);
}
}
else {
if(!$is_full) {
$this->theme->display_page($event->page);
$this->theme->display_page($page);
}
}
}

View File

@ -2,12 +2,6 @@
class UserBlockBuildingEvent extends Event {
var $parts = array();
var $user = null;
public function __construct(RequestContext $context) {
parent::__construct($context);
$this->user = $context->user;
}
public function add_link($name, $link, $position=50) {
while(isset($this->parts[$position])) $position++;
@ -18,8 +12,7 @@ class UserBlockBuildingEvent extends Event {
class UserPageBuildingEvent extends Event {
var $display_user;
public function __construct(RequestContext $context, User $display_user) {
parent::__construct($context);
public function __construct(User $display_user) {
$this->display_user = $display_user;
}
}
@ -29,8 +22,7 @@ class UserCreationEvent extends Event {
var $password;
var $email;
public function __construct(RequestContext $context, $name, $pass, $email) {
parent::__construct($context);
public function __construct($name, $pass, $email) {
$this->username = $name;
$this->password = $pass;
$this->email = $email;
@ -44,19 +36,16 @@ class UserPage implements Extension {
// event handling {{{
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if($event instanceof InitExtEvent) {
$event->context->config->set_default_bool("login_signup_enabled", true);
$event->context->config->set_default_int("login_memory", 365);
$config->set_default_bool("login_signup_enabled", true);
$config->set_default_int("login_memory", 365);
}
if(($event instanceof PageRequestEvent) && $event->page_matches("user_admin")) {
$user = $event->context->user;
$database = $event->context->database;
$config = $event->context->config;
$page = $event->context->page;
if($event->get_arg(0) == "login") {
if(isset($_POST['user']) && isset($_POST['pass'])) {
$this->login($page);
@ -86,7 +75,7 @@ class UserPage implements Extension {
}
else {
try {
$uce = new UserCreationEvent($event->context, $_POST['name'], $_POST['pass1'], $_POST['email']);
$uce = new UserCreationEvent($_POST['name'], $_POST['pass1'], $_POST['email']);
send_event($uce);
$this->set_login_cookie($uce->username, $uce->password);
$page->set_mode("redirect");
@ -102,14 +91,9 @@ class UserPage implements Extension {
}
}
if(($event instanceof PageRequestEvent) && $event->page_matches("user")) {
$user = $event->context->user;
$config = $event->context->config;
$database = $event->context->database;
$page = $event->context->page;
$display_user = ($event->count_args() == 0) ? $user : User::by_name($config, $database, $event->get_arg(0));
$display_user = ($event->count_args() == 0) ? $user : User::by_name($event->get_arg(0));
if(!is_null($display_user)) {
send_event(new UserPageBuildingEvent($event->context, $display_user));
send_event(new UserPageBuildingEvent($display_user));
}
else {
$this->theme->display_error($page, "No Such User",
@ -119,31 +103,25 @@ class UserPage implements Extension {
}
if($event instanceof UserPageBuildingEvent) {
global $user;
global $config;
$this->theme->display_user_page($event->context->page, $event->display_user, $user);
$this->theme->display_user_page($page, $event->display_user, $user);
if($user->id == $event->display_user->id) {
$ubbe = new UserBlockBuildingEvent($event->context);
$ubbe = new UserBlockBuildingEvent();
send_event($ubbe);
ksort($ubbe->parts);
$this->theme->display_user_links($event->context->page, $event->context->user, $ubbe->parts);
$this->theme->display_user_links($page, $user, $ubbe->parts);
}
if(($user->is_admin() || $user->id == $event->display_user->id) && ($user->id != $config->get_int('anon_id'))) {
$this->theme->display_ip_list($event->context->page, $this->count_upload_ips($event->display_user), $this->count_comment_ips($event->display_user));
$this->theme->display_ip_list($page, $this->count_upload_ips($event->display_user), $this->count_comment_ips($event->display_user));
}
}
// user info is shown on all pages
if($event instanceof PageRequestEvent) {
$user = $event->context->user;
$database = $event->context->database;
$page = $event->context->page;
if($user->is_anonymous()) {
$this->theme->display_login_block($page);
}
else {
$ubbe = new UserBlockBuildingEvent($event->context);
$ubbe = new UserBlockBuildingEvent();
send_event($ubbe);
ksort($ubbe->parts);
$this->theme->display_user_block($page, $user, $ubbe->parts);
@ -172,7 +150,7 @@ class UserPage implements Extension {
if(preg_match("/^(poster|user)=(.*)$/i", $event->term, $matches)) {
global $config;
global $database;
$user = User::by_name($config, $database, $matches[2]);
$user = User::by_name($matches[2]);
if(!is_null($user)) {
$user_id = $user->id;
}
@ -190,15 +168,13 @@ class UserPage implements Extension {
// }}}
// Things done *with* the user {{{
private function login($page) {
global $database;
global $config;
global $user;
$name = $_POST['user'];
$pass = $_POST['pass'];
$hash = md5(strtolower($name) . $pass);
$duser = User::by_name_and_hash($config, $database, $name, $hash);
$duser = User::by_name_and_hash($name, $hash);
if(!is_null($duser)) {
$user = $duser;
$this->set_login_cookie($name, $pass);
@ -279,7 +255,7 @@ class UserPage implements Extension {
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
$duser = User::by_id($config, $database, $id);
$duser = User::by_id($id);
if((!$user->is_admin()) && ($duser->name != $user->name)) {
$page->add_block(new Block("Error",
@ -325,7 +301,7 @@ class UserPage implements Extension {
else {
$admin = (isset($_POST['admin']) && ($_POST['admin'] == "on"));
$duser = User::by_id($config, $database, $_POST['id']);
$duser = User::by_id($_POST['id']);
$duser->set_admin($admin);
$page->set_mode("redirect");

View File

@ -123,7 +123,7 @@ class UserPageTheme extends Themelet {
global $config;
$h_join_date = html_escape($duser->join_date);
$i_image_count = Image::count_images($config, $database, array("user_id={$duser->id}"));
$i_image_count = Image::count_images(array("user_id={$duser->id}"));
$i_comment_count = Comment::count_comments_by_user($duser);
#$h_image_rate = sprintf("%3.1f", ($i_image_count / $i_days_old2));

View File

@ -11,10 +11,8 @@
class DisplayingImageEvent extends Event {
var $image, $page, $context;
public function __construct(RequestContext $context, Image $image) {
parent::__construct($context);
public function __construct(Image $image) {
$this->image = $image;
$this->page = $context->page;
}
public function get_image() {
@ -65,14 +63,13 @@ class ViewImage implements Extension {
var $theme;
public function receive_event(Event $event) {
global $config, $database, $page, $user;
if(is_null($this->theme)) $this->theme = get_theme_object($this);
if(is_a($event, 'PageRequestEvent') && (
$event->page_matches("post/prev") ||
$event->page_matches("post/next")
)) {
global $config;
global $database;
$image_id = int_escape($event->get_arg(0));
if(isset($_GET['search'])) {
@ -84,7 +81,7 @@ class ViewImage implements Extension {
$query = null;
}
$image = Image::by_id($config, $database, $image_id);
$image = Image::by_id($image_id);
if($event->page_matches("post/next")) {
$image = $image->get_next($search_terms);
}
@ -93,50 +90,46 @@ class ViewImage implements Extension {
}
if(!is_null($image)) {
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("post/view/{$image->id}", $query));
$page->set_mode("redirect");
$page->set_redirect(make_link("post/view/{$image->id}", $query));
}
else {
$this->theme->display_error($event->page, "Image not found", "No more images");
$this->theme->display_error($page, "Image not found", "No more images");
}
}
if(($event instanceof PageRequestEvent) && $event->page_matches("post/view")) {
$image_id = int_escape($event->get_arg(0));
global $database;
global $config;
$image = Image::by_id($config, $database, $image_id);
$image = Image::by_id($image_id);
if(!is_null($image)) {
send_event(new DisplayingImageEvent($event->context, $image));
$iabbe = new ImageAdminBlockBuildingEvent($image, $event->user);
send_event(new DisplayingImageEvent($image));
$iabbe = new ImageAdminBlockBuildingEvent($image, $user);
send_event($iabbe);
ksort($iabbe->parts);
$this->theme->display_admin_block($event->page, $iabbe->parts);
$this->theme->display_admin_block($page, $iabbe->parts);
}
else {
$this->theme->display_error($event->page, "Image not found", "No image in the database has the ID #$image_id");
$this->theme->display_error($page, "Image not found", "No image in the database has the ID #$image_id");
}
}
if(($event instanceof PageRequestEvent) && $event->page_matches("post/set")) {
global $config, $database;
$image_id = int_escape($_POST['image_id']);
send_event(new ImageInfoSetEvent(Image::by_id($config, $database, $image_id)));
send_event(new ImageInfoSetEvent(Image::by_id($image_id)));
$query = $_POST['query'];
$event->page->set_mode("redirect");
$event->page->set_redirect(make_link("post/view/$image_id", $query));
$page->set_mode("redirect");
$page->set_redirect(make_link("post/view/$image_id", $query));
}
if($event instanceof DisplayingImageEvent) {
global $user;
$iibbe = new ImageInfoBoxBuildingEvent($event->get_image(), $user);
send_event($iibbe);
ksort($iibbe->parts);
$this->theme->display_page($event->page, $event->get_image(), $iibbe->parts);
$this->theme->display_page($page, $event->get_image(), $iibbe->parts);
}
}
}

View File

@ -55,14 +55,9 @@ try {
// start the page generation waterfall
$page = new Page();
$user = _get_user($config, $database);
$context = new RequestContext();
$context->page = $page;
$context->user = $user;
$context->database = $database;
$context->config = $config;
send_event(new InitExtEvent($context));
send_event(_get_page_request($context));
$context->page->display($context);
send_event(new InitExtEvent());
send_event(_get_page_request());
$page->display();
// for databases which support transactions

View File

@ -42,9 +42,8 @@ Tips
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
class Layout {
public function display_page($context) {
$page = $context->page;
$config = $context->config;
public function display_page($page) {
global $config;
$theme_name = $config->get_string('theme');
$base_href = $config->get_string('base_href');

View File

@ -1,9 +1,8 @@
<?php
class Layout {
function display_page($context) {
$page = $context->page;
$config = $context->config;
function display_page($page) {
global $config;
$theme_name = $config->get_string('theme', 'default');
$data_href = get_base_href();

View File

@ -1,9 +1,8 @@
<?php
class Layout {
function display_page($context) {
$page = $context->page;
$config = $context->config;
function display_page($page) {
global $config;
$theme_name = $config->get_string('theme', 'default');
$data_href = get_base_href();

View File

@ -1,9 +1,8 @@
<?php
class Layout {
function display_page($context) {
$page = $context->page;
$config = $context->config;
function display_page($page) {
global $config;
$theme_name = $config->get_string('theme', 'default');
$data_href = get_base_href();