less global user, more event->user
git-svn-id: file:///home/shish/svn/shimmie2/trunk@478 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
6993bc2fdf
commit
88336cc323
13 changed files with 41 additions and 46 deletions
|
@ -9,13 +9,12 @@
|
|||
|
||||
class AdminUtils extends Extension {
|
||||
var $theme;
|
||||
// event handler {{{
|
||||
|
||||
public function receive_event($event) {
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object("admin_utils", "AdminUtilsTheme");
|
||||
|
||||
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "admin_utils")) {
|
||||
global $user;
|
||||
if($user->is_admin()) {
|
||||
if($event->user->is_admin()) {
|
||||
set_time_limit(0);
|
||||
|
||||
switch($_POST['action']) {
|
||||
|
@ -40,8 +39,7 @@ class AdminUtils extends Extension {
|
|||
$this->theme->display_form($page);
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
// do things {{{
|
||||
|
||||
private function lowercase_all_tags() {
|
||||
global $database;
|
||||
$database->execute("UPDATE tags SET tag=lower(tag)");
|
||||
|
@ -66,7 +64,6 @@ class AdminUtils extends Extension {
|
|||
}
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
add_event_listener(new AdminUtils());
|
||||
?>
|
||||
|
|
|
@ -18,9 +18,8 @@ class EventLog extends Extension {
|
|||
}
|
||||
|
||||
if(is_a($event, 'PageRequestEvent') && $event->page_name == "event_log") {
|
||||
global $user;
|
||||
global $database;
|
||||
if($user->is_admin()) {
|
||||
if($event->user->is_admin()) {
|
||||
if(isset($_POST['action'])) {
|
||||
switch($_POST['action']) {
|
||||
case 'clear':
|
||||
|
@ -68,9 +67,8 @@ class EventLog extends Extension {
|
|||
}
|
||||
|
||||
global $user; // bad
|
||||
// TODO: log comments, uploads
|
||||
if(is_a($event, 'UploadingImageEvent')) {
|
||||
$this->add_to_log($user, 'Uploading Image', "Uploaded a new image");
|
||||
$this->add_to_log($event->user, 'Uploading Image', "Uploaded a new image");
|
||||
}
|
||||
if(is_a($event, 'CommentPostingEvent')) {
|
||||
$this->add_to_log($event->user, 'Comment Posting', "Posted a comment on image #{$event->image_id}");
|
||||
|
|
|
@ -15,11 +15,13 @@ class PageRequestEvent extends Event {
|
|||
var $page_name;
|
||||
var $args;
|
||||
var $page;
|
||||
var $user;
|
||||
|
||||
public function PageRequestEvent($page_name, $args, $page) {
|
||||
public function PageRequestEvent($page_name, $args, $page, $user) {
|
||||
$this->page_name = $page_name;
|
||||
$this->args = $args;
|
||||
$this->page = $page;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function get_arg($n) {
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
*/
|
||||
class UploadingImageEvent extends Event {
|
||||
var $image;
|
||||
var $ok;
|
||||
var $user;
|
||||
|
||||
public function UploadingImageEvent($image) {
|
||||
public function UploadingImageEvent($image, $user) {
|
||||
$this->image = $image;
|
||||
$this->ok = false;
|
||||
$this->user = $user;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -404,7 +404,7 @@ function _get_query_parts() {
|
|||
return $parts;
|
||||
}
|
||||
|
||||
function _get_page_request($page) {
|
||||
function _get_page_request($page, $user) {
|
||||
global $config;
|
||||
$args = _get_query_parts();
|
||||
|
||||
|
@ -422,7 +422,7 @@ function _get_page_request($page) {
|
|||
$args = array_slice($args, 1);
|
||||
}
|
||||
|
||||
return new PageRequestEvent($page_name, $args, $page);
|
||||
return new PageRequestEvent($page_name, $args, $page, $user);
|
||||
}
|
||||
|
||||
function _get_user() {
|
||||
|
|
|
@ -14,13 +14,11 @@ class AdminBuildingEvent extends Event {
|
|||
class AdminPage extends Extension {
|
||||
var $theme;
|
||||
|
||||
// event handler {{{
|
||||
public function receive_event($event) {
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object("admin", "AdminPageTheme");
|
||||
|
||||
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "admin")) {
|
||||
global $user;
|
||||
if(!$user->is_admin()) {
|
||||
if(!$event->user->is_admin()) {
|
||||
$this->theme->display_error($event->page, "Permission Denied", "This page is for admins only");
|
||||
}
|
||||
else {
|
||||
|
@ -59,7 +57,6 @@ class AdminPage extends Extension {
|
|||
}
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
}
|
||||
add_event_listener(new AdminPage());
|
||||
?>
|
||||
|
|
|
@ -17,20 +17,18 @@ class AliasEditor extends Extension {
|
|||
if(is_null($this->theme)) $this->theme = get_theme_object("alias_editor", "AliasEditorTheme");
|
||||
|
||||
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "alias")) {
|
||||
global $user;
|
||||
if($event->get_arg(0) == "add") {
|
||||
if($user->is_admin()) {
|
||||
if($event->user->is_admin()) {
|
||||
if(isset($_POST['oldtag']) && isset($_POST['newtag'])) {
|
||||
send_event(new AddAliasEvent($_POST['oldtag'], $_POST['newtag']));
|
||||
|
||||
global $page;
|
||||
$event->page->set_mode("redirect");
|
||||
$event->page->set_redirect(make_link("alias/list"));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if($event->get_arg(0) == "remove") {
|
||||
if($user->is_admin()) {
|
||||
if($event->user->is_admin()) {
|
||||
if(isset($_POST['oldtag'])) {
|
||||
global $database;
|
||||
$database->Execute("DELETE FROM aliases WHERE oldtag=?", array($_POST['oldtag']));
|
||||
|
@ -42,7 +40,7 @@ class AliasEditor extends Extension {
|
|||
}
|
||||
else if($event->get_arg(0) == "list") {
|
||||
global $database;
|
||||
$this->theme->display_aliases($event->page, $database->db->GetAssoc("SELECT oldtag, newtag FROM aliases"), $user->is_admin());
|
||||
$this->theme->display_aliases($event->page, $database->db->GetAssoc("SELECT oldtag, newtag FROM aliases"), $event->user->is_admin());
|
||||
}
|
||||
else if($event->get_arg(0) == "export") {
|
||||
$event->page->set_mode("data");
|
||||
|
|
|
@ -2,13 +2,12 @@
|
|||
|
||||
class BulkAdd extends Extension {
|
||||
var $theme;
|
||||
// event handler {{{
|
||||
|
||||
public function receive_event($event) {
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object("bulk_add", "BulkAddTheme");
|
||||
|
||||
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "bulk_add")) {
|
||||
global $user;
|
||||
if($user->is_admin() && isset($_POST['dir'])) {
|
||||
if($event->user->is_admin() && isset($_POST['dir'])) {
|
||||
set_time_limit(0);
|
||||
|
||||
$this->add_dir($_POST['dir']);
|
||||
|
@ -21,7 +20,7 @@ class BulkAdd extends Extension {
|
|||
$this->theme->display_admin_block($page);
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
// do the adding {{{
|
||||
private function add_image($tmpname, $filename, $tags) {
|
||||
global $config;
|
||||
|
|
|
@ -68,12 +68,10 @@ class CommentList extends Extension {
|
|||
|
||||
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "comment")) {
|
||||
if($event->get_arg(0) == "add") {
|
||||
global $user;
|
||||
send_event(new CommentPostingEvent($_POST['image_id'], $user, $_POST['comment']));
|
||||
send_event(new CommentPostingEvent($_POST['image_id'], $event->user, $_POST['comment']));
|
||||
}
|
||||
else if($event->get_arg(0) == "delete") {
|
||||
global $user;
|
||||
if($user->is_admin()) {
|
||||
if($event->user->is_admin()) {
|
||||
// FIXME: post, not args
|
||||
if($event->count_args() == 3) {
|
||||
send_event(new CommentDeletionEvent($event->get_arg(1)));
|
||||
|
|
|
@ -6,7 +6,9 @@ class Downtime extends Extension {
|
|||
public function receive_event($event) {
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object("downtime", "DowntimeTheme");
|
||||
|
||||
$this->check_downtime($event);
|
||||
if(is_a($event, 'InitExtEvent')) {
|
||||
$this->check_downtime($event);
|
||||
}
|
||||
|
||||
if(is_a($event, 'SetupBuildingEvent')) {
|
||||
$sb = new SetupBlock("Downtime");
|
||||
|
@ -14,6 +16,7 @@ class Downtime extends Extension {
|
|||
$sb->add_longtext_option("downtime_message", "<br>");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
|
||||
if(is_a($event, 'PageRequestEvent')) {
|
||||
global $config;
|
||||
if($config->get_bool("downtime")) {
|
||||
|
|
|
@ -2,13 +2,12 @@
|
|||
|
||||
class ET extends Extension {
|
||||
var $theme;
|
||||
// event handler {{{
|
||||
|
||||
public function receive_event($event) {
|
||||
if(is_null($this->theme)) $this->theme = get_theme_object("et", "ETTheme");
|
||||
|
||||
if(is_a($event, 'PageRequestEvent') && ($event->page_name == "system_info")) {
|
||||
global $user;
|
||||
if($user->is_admin()) {
|
||||
if($event->user->is_admin()) {
|
||||
$this->theme->display_info_page($event->page, $this->get_info());
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +18,7 @@ class ET extends Extension {
|
|||
}
|
||||
}
|
||||
}
|
||||
// }}}
|
||||
|
||||
// do it {{{
|
||||
private function get_info() {
|
||||
global $database;
|
||||
|
|
|
@ -14,7 +14,8 @@ class Upload extends Extension {
|
|||
}
|
||||
|
||||
if(is_a($event, 'PostListBuildingEvent')) {
|
||||
if($this->can_upload()) {
|
||||
global $user;
|
||||
if($this->can_upload($user)) {
|
||||
$this->theme->display_block($event->page);
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +24,8 @@ class Upload extends Extension {
|
|||
if(count($_FILES) + count($_POST) > 0) {
|
||||
$tags = tag_explode($_POST['tags']);
|
||||
$source = isset($_POST['source']) ? $_POST['source'] : null;
|
||||
if($this->can_upload()) {
|
||||
global $user;
|
||||
if($this->can_upload($user)) {
|
||||
$ok = true;
|
||||
foreach($_FILES as $file) {
|
||||
$ok = $ok & $this->try_upload($file, $tags, $source);
|
||||
|
@ -61,9 +63,9 @@ class Upload extends Extension {
|
|||
}
|
||||
// }}}
|
||||
// do things {{{
|
||||
private function can_upload() {
|
||||
global $config, $user;
|
||||
return $config->get_bool("upload_anon") || !$user->is_anonymous();
|
||||
private function can_upload($user) {
|
||||
global $config;
|
||||
return ($config->get_bool("upload_anon") || !$user->is_anonymous());
|
||||
}
|
||||
|
||||
private function try_upload($file, $tags, $source) {
|
||||
|
@ -91,7 +93,8 @@ class Upload extends Extension {
|
|||
$image = new Image($file['tmp_name'], $file['name'], $tags, $source);
|
||||
|
||||
if($image->is_ok()) {
|
||||
$event = new UploadingImageEvent($image);
|
||||
global $user;
|
||||
$event = new UploadingImageEvent($user, $image);
|
||||
send_event($event);
|
||||
$ok = !$event->vetoed;
|
||||
if(!$ok) {
|
||||
|
@ -170,7 +173,8 @@ class Upload extends Extension {
|
|||
$image = new Image($tmp_filename, basename($url), $tags, $source);
|
||||
|
||||
if($image->is_ok()) {
|
||||
$event = new UploadingImageEvent($image);
|
||||
global $user;
|
||||
$event = new UploadingImageEvent($user, $image);
|
||||
send_event($event);
|
||||
$ok = !$event->vetoed;
|
||||
if(!$ok) {
|
||||
|
|
|
@ -45,6 +45,6 @@ foreach($themelets as $filename) {
|
|||
$page = new Page();
|
||||
$user = _get_user();
|
||||
send_event(new InitExtEvent());
|
||||
send_event(_get_page_request($page));
|
||||
send_event(_get_page_request($page, $user));
|
||||
$page->display();
|
||||
?>
|
||||
|
|
Reference in a new issue