merge changes from master
This commit is contained in:
		
						commit
						2bdfec3e76
					
				@ -208,7 +208,7 @@ class DanbooruApi implements Extension
 | 
				
			|||||||
				// It is also currently broken due to some confusion over file variable ($tmp_filename?)
 | 
									// It is also currently broken due to some confusion over file variable ($tmp_filename?)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				// Does it exist already?
 | 
									// Does it exist already?
 | 
				
			||||||
				$existing = Image::by_hash($config, $database, $hash);
 | 
									$existing = Image::by_hash($hash);
 | 
				
			||||||
				if(!is_null($existing)) {
 | 
									if(!is_null($existing)) {
 | 
				
			||||||
					header("HTTP/1.0 409 Conflict");
 | 
										header("HTTP/1.0 409 Conflict");
 | 
				
			||||||
					header("X-Danbooru-Errors: duplicate");
 | 
										header("X-Danbooru-Errors: duplicate");
 | 
				
			||||||
@ -227,7 +227,7 @@ class DanbooruApi implements Extension
 | 
				
			|||||||
					$nevent = new DataUploadEvent($user, $file, $metadata);
 | 
										$nevent = new DataUploadEvent($user, $file, $metadata);
 | 
				
			||||||
					send_event($nevent);
 | 
										send_event($nevent);
 | 
				
			||||||
					// If it went ok, grab the id for the newly uploaded image and pass it in the header
 | 
										// 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);
 | 
										$newid = make_link("post/view/" . $newimg->id);
 | 
				
			||||||
					// Did we POST or GET this call?
 | 
										// Did we POST or GET this call?
 | 
				
			||||||
					if($_SERVER['REQUEST_METHOD'] == 'POST')
 | 
										if($_SERVER['REQUEST_METHOD'] == 'POST')
 | 
				
			||||||
@ -269,21 +269,21 @@ class DanbooruApi implements Extension
 | 
				
			|||||||
				$md5list = explode(",",$_GET['md5']);
 | 
									$md5list = explode(",",$_GET['md5']);
 | 
				
			||||||
				foreach($md5list as $md5)
 | 
									foreach($md5list as $md5)
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					$results[] = Image::by_hash($config, $database, $md5);
 | 
										$results[] = Image::by_hash($md5);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			} elseif(isset($_GET['id']))
 | 
								} elseif(isset($_GET['id']))
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				$idlist = explode(",",$_GET['id']);
 | 
									$idlist = explode(",",$_GET['id']);
 | 
				
			||||||
				foreach($idlist as $id)
 | 
									foreach($idlist as $id)
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					$results[] = Image::by_id($config, $database, $id);
 | 
										$results[] = Image::by_id($id);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			} else
 | 
								} else
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				$limit = isset($_GET['limit']) ? int_escape($_GET['limit']) : 100;
 | 
									$limit = isset($_GET['limit']) ? int_escape($_GET['limit']) : 100;
 | 
				
			||||||
				$start = isset($_GET['offset']) ? int_escape($_GET['offset']) : 0;
 | 
									$start = isset($_GET['offset']) ? int_escape($_GET['offset']) : 0;
 | 
				
			||||||
				$tags = isset($_GET['tags']) ? Tag::explode($_GET['tags']) : array();
 | 
									$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
 | 
								// Now we have the array $results filled with Image objects
 | 
				
			||||||
@ -392,12 +392,12 @@ class DanbooruApi implements Extension
 | 
				
			|||||||
			$name = $_REQUEST['login'];
 | 
								$name = $_REQUEST['login'];
 | 
				
			||||||
			$pass = $_REQUEST['password'];
 | 
								$pass = $_REQUEST['password'];
 | 
				
			||||||
			$hash = md5( strtolower($name) . $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)) {
 | 
								if(!is_null($duser)) {
 | 
				
			||||||
				$user = $duser;
 | 
									$user = $duser;
 | 
				
			||||||
			} else
 | 
								} else
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				$user = User::by_id($config, $database, $config->get_int("anon_id", 0));
 | 
									$user = User::by_id($config->get_int("anon_id", 0));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -10,6 +10,7 @@ class Downtime implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof SetupBuildingEvent) {
 | 
							if($event instanceof SetupBuildingEvent) {
 | 
				
			||||||
@ -20,16 +21,15 @@ class Downtime implements Extension {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof PageRequestEvent) {
 | 
							if($event instanceof PageRequestEvent) {
 | 
				
			||||||
			if($event->context->config->get_bool("downtime")) {
 | 
								if($config->get_bool("downtime")) {
 | 
				
			||||||
				$this->check_downtime($event);
 | 
									$this->check_downtime($event);
 | 
				
			||||||
				$this->theme->display_notification($event->page);
 | 
									$this->theme->display_notification($page);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private function check_downtime(PageRequestEvent $event) {
 | 
						private function check_downtime(PageRequestEvent $event) {
 | 
				
			||||||
		$user = $event->context->user;
 | 
							global $user, $config;
 | 
				
			||||||
		$config = $event->context->config;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($config->get_bool("downtime") && !$user->is_admin() &&
 | 
							if($config->get_bool("downtime") && !$user->is_admin() &&
 | 
				
			||||||
				($event instanceof PageRequestEvent) && !$this->is_safe_page($event)) {
 | 
									($event instanceof PageRequestEvent) && !$this->is_safe_page($event)) {
 | 
				
			||||||
 | 
				
			|||||||
@ -16,24 +16,24 @@ class ET implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(($event instanceof PageRequestEvent) && $event->page_matches("system_info")) {
 | 
							if(($event instanceof PageRequestEvent) && $event->page_matches("system_info")) {
 | 
				
			||||||
			if($event->context->user->is_admin()) {
 | 
								if($user->is_admin()) {
 | 
				
			||||||
				$this->theme->display_info_page($event->page, $this->get_info($event->context));
 | 
									$this->theme->display_info_page($page, $this->get_info());
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof UserBlockBuildingEvent) {
 | 
							if($event instanceof UserBlockBuildingEvent) {
 | 
				
			||||||
			if($event->context->user->is_admin()) {
 | 
								if($user->is_admin()) {
 | 
				
			||||||
				$event->add_link("System Info", make_link("system_info"));
 | 
									$event->add_link("System Info", make_link("system_info"));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private function get_info($context) {
 | 
						private function get_info() {
 | 
				
			||||||
		$database = $context->database;
 | 
							global $config, $database;
 | 
				
			||||||
		$config = $context->config;
 | 
					 | 
				
			||||||
		global $_event_listeners; // yay for using secret globals \o/
 | 
							global $_event_listeners; // yay for using secret globals \o/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$info = array();
 | 
							$info = array();
 | 
				
			||||||
 | 
				
			|||||||
@ -29,19 +29,19 @@ class Featured implements Extension {
 | 
				
			|||||||
				$id = int_escape($_POST['image_id']);
 | 
									$id = int_escape($_POST['image_id']);
 | 
				
			||||||
				if($id > 0) {
 | 
									if($id > 0) {
 | 
				
			||||||
					$config->set_int("featured_id", $id);
 | 
										$config->set_int("featured_id", $id);
 | 
				
			||||||
					$event->page->set_mode("redirect");
 | 
										$page->set_mode("redirect");
 | 
				
			||||||
					$event->page->set_redirect(make_link("post/view/$id"));
 | 
										$page->set_redirect(make_link("post/view/$id"));
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof PostListBuildingEvent) {
 | 
							if($event instanceof PostListBuildingEvent) {
 | 
				
			||||||
			global $config, $database;
 | 
								global $config, $page;
 | 
				
			||||||
			$fid = $config->get_int("featured_id");
 | 
								$fid = $config->get_int("featured_id");
 | 
				
			||||||
			if($fid > 0) {
 | 
								if($fid > 0) {
 | 
				
			||||||
				$image = Image::by_id($config, $database, $fid);
 | 
									$image = Image::by_id($fid);
 | 
				
			||||||
				if(!is_null($image)) {
 | 
									if(!is_null($image)) {
 | 
				
			||||||
					$this->theme->display_featured($event->page, $image);
 | 
										$this->theme->display_featured($page, $image);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -35,7 +35,7 @@ class IcoFileHandler implements Extension {
 | 
				
			|||||||
			global $config;
 | 
								global $config;
 | 
				
			||||||
			global $database;
 | 
								global $database;
 | 
				
			||||||
			$id = int_escape($event->get_arg(0));
 | 
								$id = int_escape($event->get_arg(0));
 | 
				
			||||||
			$image = Image::by_id($config, $database, $id);
 | 
								$image = Image::by_id($id);
 | 
				
			||||||
			$hash = $image->hash;
 | 
								$hash = $image->hash;
 | 
				
			||||||
			$ha = substr($hash, 0, 2);
 | 
								$ha = substr($hash, 0, 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -51,7 +51,7 @@ class SVGFileHandler implements Extension {
 | 
				
			|||||||
			global $config;
 | 
								global $config;
 | 
				
			||||||
			global $database;
 | 
								global $database;
 | 
				
			||||||
			$id = int_escape($event->get_arg(0));
 | 
								$id = int_escape($event->get_arg(0));
 | 
				
			||||||
			$image = Image::by_id($config, $database, $id);
 | 
								$image = Image::by_id($id);
 | 
				
			||||||
			$hash = $image->hash;
 | 
								$hash = $image->hash;
 | 
				
			||||||
			$ha = substr($hash, 0, 2);
 | 
								$ha = substr($hash, 0, 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -18,12 +18,13 @@ class Home implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(($event instanceof PageRequestEvent) && $event->page_matches("home"))
 | 
							if(($event instanceof PageRequestEvent) && $event->page_matches("home"))
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			// this is a request to display this page so output the page.
 | 
								// 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)
 | 
							if($event instanceof SetupBuildingEvent)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
 | 
				
			|||||||
@ -34,18 +34,16 @@ class ImageBan implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof InitExtEvent) {
 | 
							if($event instanceof InitExtEvent) {
 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
			if($config->get_int("ext_imageban_version") < 1) {
 | 
								if($config->get_int("ext_imageban_version") < 1) {
 | 
				
			||||||
				$this->install();
 | 
									$this->install();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof DataUploadEvent) {
 | 
							if($event instanceof DataUploadEvent) {
 | 
				
			||||||
			global $database;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			$row = $database->db->GetRow("SELECT * FROM image_bans WHERE hash = ?", $event->hash);
 | 
								$row = $database->db->GetRow("SELECT * FROM image_bans WHERE hash = ?", $event->hash);
 | 
				
			||||||
			if($row) {
 | 
								if($row) {
 | 
				
			||||||
				log_info("image_hash_ban", "Blocked image ({$event->hash})");
 | 
									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 instanceof PageRequestEvent) && $event->page_matches("image_hash_ban")) {
 | 
				
			||||||
			if($event->user->is_admin()) {
 | 
								if($user->is_admin()) {
 | 
				
			||||||
				if($event->get_arg(0) == "add") {
 | 
									if($event->get_arg(0) == "add") {
 | 
				
			||||||
					if(isset($_POST['hash']) && isset($_POST['reason'])) {
 | 
										if(isset($_POST['hash']) && isset($_POST['reason'])) {
 | 
				
			||||||
						send_event(new AddImageHashBanEvent($_POST['hash'], $_POST['reason']));
 | 
											send_event(new AddImageHashBanEvent($_POST['hash'], $_POST['reason']));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
						global $page;
 | 
					 | 
				
			||||||
						$page->set_mode("redirect");
 | 
											$page->set_mode("redirect");
 | 
				
			||||||
						$page->set_redirect(make_link("admin"));
 | 
											$page->set_redirect(make_link("admin"));
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					if(isset($_POST['image_id'])) {
 | 
										if(isset($_POST['image_id'])) {
 | 
				
			||||||
						global $config;
 | 
											$image = Image::by_id(int_escape($_POST['image_id']));
 | 
				
			||||||
						global $database;
 | 
					 | 
				
			||||||
						$image = Image::by_id($config, $database, int_escape($_POST['image_id']));
 | 
					 | 
				
			||||||
						if($image) {
 | 
											if($image) {
 | 
				
			||||||
							send_event(new ImageDeletionEvent($image));
 | 
												send_event(new ImageDeletionEvent($image));
 | 
				
			||||||
							$event->page->set_mode("redirect");
 | 
												$page->set_mode("redirect");
 | 
				
			||||||
							$event->page->set_redirect(make_link("post/list"));
 | 
												$page->set_redirect(make_link("post/list"));
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
@ -78,7 +73,6 @@ class ImageBan implements Extension {
 | 
				
			|||||||
					if(isset($_POST['hash'])) {
 | 
										if(isset($_POST['hash'])) {
 | 
				
			||||||
						send_event(new RemoveImageHashBanEvent($_POST['hash']));
 | 
											send_event(new RemoveImageHashBanEvent($_POST['hash']));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
						global $page;
 | 
					 | 
				
			||||||
						$page->set_mode("redirect");
 | 
											$page->set_mode("redirect");
 | 
				
			||||||
						$page->set_redirect(make_link("admin"));
 | 
											$page->set_redirect(make_link("admin"));
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
@ -88,13 +82,13 @@ class ImageBan implements Extension {
 | 
				
			|||||||
					if($event->count_args() == 2) {
 | 
										if($event->count_args() == 2) {
 | 
				
			||||||
						$page_num = int_escape($event->get_arg(1));
 | 
											$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 instanceof UserBlockBuildingEvent) {
 | 
				
			||||||
			if($event->user->is_admin()) {
 | 
								if($user->is_admin()) {
 | 
				
			||||||
				$event->add_link("Image Bans", make_link("image_hash_ban/list/1"));
 | 
									$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 instanceof ImageAdminBlockBuildingEvent) {
 | 
				
			||||||
			if($event->user->is_admin()) {
 | 
								if($user->is_admin()) {
 | 
				
			||||||
				$event->add_part($this->theme->get_buttons_html($event->image));
 | 
									$event->add_part($this->theme->get_buttons_html($event->image));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,8 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
 | 
					class ImageHashBanTest extends WebTestCase {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(!defined(VERSION)) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ImageHashBanUnitTest extends UnitTestCase {
 | 
					class ImageHashBanUnitTest extends UnitTestCase {
 | 
				
			||||||
	public function _broken_testUploadFailsWhenBanned() {
 | 
						public function _broken_testUploadFailsWhenBanned() {
 | 
				
			||||||
		$ihb = new ImageHashBan();
 | 
							$ihb = new ImageHashBan();
 | 
				
			||||||
 | 
				
			|||||||
@ -38,10 +38,10 @@ class IPBan implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
// event handler {{{
 | 
					// event handler {{{
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof InitExtEvent) {
 | 
							if($event instanceof InitExtEvent) {
 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
			if($config->get_int("ext_ipban_version") < 5) {
 | 
								if($config->get_int("ext_ipban_version") < 5) {
 | 
				
			||||||
				$this->install();
 | 
									$this->install();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@ -50,7 +50,6 @@ class IPBan implements Extension {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(($event instanceof PageRequestEvent) && $event->page_matches("ip_ban")) {
 | 
							if(($event instanceof PageRequestEvent) && $event->page_matches("ip_ban")) {
 | 
				
			||||||
			global $user;
 | 
					 | 
				
			||||||
			if($user->is_admin()) {
 | 
								if($user->is_admin()) {
 | 
				
			||||||
				if($event->get_arg(0) == "add") {
 | 
									if($event->get_arg(0) == "add") {
 | 
				
			||||||
					if(isset($_POST['ip']) && isset($_POST['reason']) && isset($_POST['end'])) {
 | 
										if(isset($_POST['ip']) && isset($_POST['reason']) && isset($_POST['end'])) {
 | 
				
			||||||
@ -58,40 +57,38 @@ class IPBan implements Extension {
 | 
				
			|||||||
						else $end = $_POST['end'];
 | 
											else $end = $_POST['end'];
 | 
				
			||||||
						send_event(new AddIPBanEvent($_POST['ip'], $_POST['reason'], $end));
 | 
											send_event(new AddIPBanEvent($_POST['ip'], $_POST['reason'], $end));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
						$event->page->set_mode("redirect");
 | 
											$page->set_mode("redirect");
 | 
				
			||||||
						$event->page->set_redirect(make_link("ip_ban/list"));
 | 
											$page->set_redirect(make_link("ip_ban/list"));
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				else if($event->get_arg(0) == "remove") {
 | 
									else if($event->get_arg(0) == "remove") {
 | 
				
			||||||
					if(isset($_POST['id'])) {
 | 
										if(isset($_POST['id'])) {
 | 
				
			||||||
						send_event(new RemoveIPBanEvent($_POST['id']));
 | 
											send_event(new RemoveIPBanEvent($_POST['id']));
 | 
				
			||||||
						$event->page->set_mode("redirect");
 | 
											$page->set_mode("redirect");
 | 
				
			||||||
						$event->page->set_redirect(make_link("ip_ban/list"));
 | 
											$page->set_redirect(make_link("ip_ban/list"));
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				else if($event->get_arg(0) == "list") {
 | 
									else if($event->get_arg(0) == "list") {
 | 
				
			||||||
					$bans = (isset($_GET["all"])) ? $this->get_bans() : $this->get_active_bans();
 | 
										$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 {
 | 
								else {
 | 
				
			||||||
				$this->theme->display_permission_denied($event->page);
 | 
									$this->theme->display_permission_denied($page);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof UserBlockBuildingEvent) {
 | 
							if($event instanceof UserBlockBuildingEvent) {
 | 
				
			||||||
			if($event->user->is_admin()) {
 | 
								if($user->is_admin()) {
 | 
				
			||||||
				$event->add_link("IP Bans", make_link("ip_ban/list"));
 | 
									$event->add_link("IP Bans", make_link("ip_ban/list"));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof AddIPBanEvent) {
 | 
							if($event instanceof AddIPBanEvent) {
 | 
				
			||||||
			global $user;
 | 
					 | 
				
			||||||
			$this->add_ip_ban($event->ip, $event->reason, $event->end, $user);
 | 
								$this->add_ip_ban($event->ip, $event->reason, $event->end, $user);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof RemoveIPBanEvent) {
 | 
							if($event instanceof RemoveIPBanEvent) {
 | 
				
			||||||
			global $database;
 | 
					 | 
				
			||||||
			$database->Execute("DELETE FROM bans WHERE id = ?", array($event->id));
 | 
								$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'])) ||
 | 
									(strstr($row['ip'], '/') && ip_in_range($remote, $row['ip'])) ||
 | 
				
			||||||
				($row['ip'] == $remote)
 | 
									($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']);
 | 
									$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>";
 | 
									print "IP <b>{$row['ip']}</b> has been banned until <b>$date</b> by <b>{$admin->name}</b> because of <b>{$row['reason']}</b>";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -8,13 +8,14 @@ class LinkImage implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
			if(($event instanceof 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) {
 | 
								if($event instanceof SetupBuildingEvent) {
 | 
				
			||||||
				$sb = new SetupBlock("Link to Image");
 | 
									$sb = new SetupBlock("Link to Image");
 | 
				
			||||||
@ -22,7 +23,6 @@ class LinkImage implements Extension {
 | 
				
			|||||||
				$event->panel->add_block($sb);
 | 
									$event->panel->add_block($sb);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if($event instanceof InitExtEvent) {
 | 
								if($event instanceof InitExtEvent) {
 | 
				
			||||||
				global $config;
 | 
					 | 
				
			||||||
				//just set default if empty.
 | 
									//just set default if empty.
 | 
				
			||||||
				$config->set_default_string("ext_link-img_text-link_format",
 | 
									$config->set_default_string("ext_link-img_text-link_format",
 | 
				
			||||||
										'$title - $id ($ext $size $filesize)');
 | 
															'$title - $id ($ext $size $filesize)');
 | 
				
			||||||
 | 
				
			|||||||
@ -12,11 +12,12 @@ class News implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof PostListBuildingEvent) {
 | 
							if($event instanceof PostListBuildingEvent) {
 | 
				
			||||||
			if(strlen($event->context->config->get_string("news_text")) > 0) {
 | 
								if(strlen($config->get_string("news_text")) > 0) {
 | 
				
			||||||
				$this->theme->display_news($event->page, $event->context->config->get_string("news_text"));
 | 
									$this->theme->display_news($page, $config->get_string("news_text"));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -23,42 +23,40 @@ class NumericScore implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof InitExtEvent) {
 | 
							if($event instanceof InitExtEvent) {
 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
			if($config->get_int("ext_numeric_score_version", 0) < 1) {
 | 
								if($config->get_int("ext_numeric_score_version", 0) < 1) {
 | 
				
			||||||
				$this->install();
 | 
									$this->install();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof DisplayingImageEvent) {
 | 
							if($event instanceof DisplayingImageEvent) {
 | 
				
			||||||
			global $user;
 | 
					 | 
				
			||||||
			if(!$user->is_anonymous()) {
 | 
								if(!$user->is_anonymous()) {
 | 
				
			||||||
				$html = $this->theme->get_voter_html($event->image);
 | 
									$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 instanceof PageRequestEvent) && $event->page_matches("numeric_score_vote")) {
 | 
				
			||||||
			if(!$event->user->is_anonymous()) {
 | 
								if(!$user->is_anonymous()) {
 | 
				
			||||||
				$image_id = int_escape($_POST['image_id']);
 | 
									$image_id = int_escape($_POST['image_id']);
 | 
				
			||||||
				$char = $_POST['vote'];
 | 
									$char = $_POST['vote'];
 | 
				
			||||||
				$score = 0;
 | 
									$score = 0;
 | 
				
			||||||
				if($char == "up") $score = 1;
 | 
									if($char == "up") $score = 1;
 | 
				
			||||||
				else if($char == "down") $score = -1;
 | 
									else if($char == "down") $score = -1;
 | 
				
			||||||
				if($score != 0) send_event(new NumericScoreSetEvent($image_id, $event->user, $score));
 | 
									if($score != 0) send_event(new NumericScoreSetEvent($image_id, $user, $score));
 | 
				
			||||||
				$event->page->set_mode("redirect");
 | 
									$page->set_mode("redirect");
 | 
				
			||||||
				$event->page->set_redirect(make_link("post/view/$image_id"));
 | 
									$page->set_redirect(make_link("post/view/$image_id"));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof NumericScoreSetEvent) {
 | 
							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) {
 | 
							if($event instanceof ImageDeletionEvent) {
 | 
				
			||||||
			global $database;
 | 
					 | 
				
			||||||
			$database->execute("DELETE FROM numeric_score_votes WHERE image_id=?", array($event->image->id));
 | 
								$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"));
 | 
									$event->set_querylet(new Querylet("numeric_score $cmp $score"));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if(preg_match("/^favou?rite$/", $event->term, $matches)) {
 | 
								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)));
 | 
									$event->set_querylet(new Querylet("images.id in (SELECT image_id FROM numeric_score_votes WHERE user_id=? AND score=1)", array($user->id)));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -12,8 +12,9 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class PicLens implements Extension {
 | 
					class PicLens implements Extension {
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $page;
 | 
				
			||||||
		if($event instanceof PageRequestEvent) {
 | 
							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) {
 | 
							if($event instanceof PostListBuildingEvent) {
 | 
				
			||||||
			$foo='
 | 
								$foo='
 | 
				
			||||||
@ -21,7 +22,7 @@ class PicLens implements Extension {
 | 
				
			|||||||
				<img src="http://lite.piclens.com/images/PicLensButton.png"
 | 
									<img src="http://lite.piclens.com/images/PicLensButton.png"
 | 
				
			||||||
					alt="PicLens" width="16" height="12" border="0"
 | 
										alt="PicLens" width="16" height="12" border="0"
 | 
				
			||||||
					align="absmiddle"></a>';
 | 
										align="absmiddle"></a>';
 | 
				
			||||||
			$event->page->add_block(new Block("PicLens", $foo, "left", 20));
 | 
								$page->add_block(new Block("PicLens", $foo, "left", 20));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -11,8 +11,7 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SendPMEvent extends Event {
 | 
					class SendPMEvent extends Event {
 | 
				
			||||||
	public function __construct(RequestContext $reqest, $from_id, $from_ip, $to_id, $subject, $message) {
 | 
						public function __construct($from_id, $from_ip, $to_id, $subject, $message) {
 | 
				
			||||||
		parent::__construct($request);
 | 
					 | 
				
			||||||
		$this->from_id = $from_id;
 | 
							$this->from_id = $from_id;
 | 
				
			||||||
		$this->from_ip = $from_ip;
 | 
							$this->from_ip = $from_ip;
 | 
				
			||||||
		$this->to_id = $to_id;
 | 
							$this->to_id = $to_id;
 | 
				
			||||||
@ -25,51 +24,49 @@ class PM implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof InitExtEvent) {
 | 
							if($event instanceof InitExtEvent) {
 | 
				
			||||||
			if($event->context->config->get_int("pm_version") < 1) {
 | 
								if($config->get_int("pm_version") < 1) {
 | 
				
			||||||
				$this->install($event->context);
 | 
									$this->install();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		if($event instanceof UserBlockBuildingEvent) {
 | 
							if($event instanceof UserBlockBuildingEvent) {
 | 
				
			||||||
			if(!$event->user->is_anonymous()) {
 | 
								if(!$user->is_anonymous()) {
 | 
				
			||||||
				$event->add_link("Private Messages", make_link("pm"));
 | 
									$event->add_link("Private Messages", make_link("pm"));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		*/
 | 
							*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof UserPageBuildingEvent) {
 | 
							if($event instanceof UserPageBuildingEvent) {
 | 
				
			||||||
			$user = $event->context->user;
 | 
					 | 
				
			||||||
			$duser = $event->display_user;
 | 
								$duser = $event->display_user;
 | 
				
			||||||
			if(!$user->is_anonymous() && !$duser->is_anonymous()) {
 | 
								if(!$user->is_anonymous() && !$duser->is_anonymous()) {
 | 
				
			||||||
				if(($user->id == $duser->id) || $user->is_admin()) {
 | 
									if(($user->id == $duser->id) || $user->is_admin()) {
 | 
				
			||||||
					$this->theme->display_pms($event->context->page, $this->get_pms($duser));
 | 
										$this->theme->display_pms($page, $this->get_pms($duser));
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if($user->id != $duser->id) {
 | 
									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")) {
 | 
							if(($event instanceof PageRequestEvent) && $event->page_matches("pm")) {
 | 
				
			||||||
			$database = $event->context->database;
 | 
					 | 
				
			||||||
			$config = $event->context->config;
 | 
					 | 
				
			||||||
			$user = $event->config->user;
 | 
					 | 
				
			||||||
			if(!$user->is_anonymous()) {
 | 
								if(!$user->is_anonymous()) {
 | 
				
			||||||
				switch($event->get_arg(0)) {
 | 
									switch($event->get_arg(0)) {
 | 
				
			||||||
					case "read":
 | 
										case "read":
 | 
				
			||||||
						$pm_id = int_escape($event->get_arg(1));
 | 
											$pm_id = int_escape($event->get_arg(1));
 | 
				
			||||||
						$pm = $database->get_row("SELECT * FROM private_message WHERE id = ?", array($pm_id));
 | 
											$pm = $database->get_row("SELECT * FROM private_message WHERE id = ?", array($pm_id));
 | 
				
			||||||
						if(is_null($pm)) {
 | 
											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()) {
 | 
											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));
 | 
												$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 {
 | 
											else {
 | 
				
			||||||
							// permission denied
 | 
												// permission denied
 | 
				
			||||||
@ -79,13 +76,13 @@ class PM implements Extension {
 | 
				
			|||||||
						$pm_id = int_escape($event->get_arg(1));
 | 
											$pm_id = int_escape($event->get_arg(1));
 | 
				
			||||||
						$pm = $database->get_row("SELECT * FROM private_message WHERE id = ?", array($pm_id));
 | 
											$pm = $database->get_row("SELECT * FROM private_message WHERE id = ?", array($pm_id));
 | 
				
			||||||
						if(is_null($pm)) {
 | 
											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()) {
 | 
											else if(($pm["to_id"] == $user->id) || $user->is_admin()) {
 | 
				
			||||||
							$database->execute("DELETE FROM private_message WHERE id = ?", array($pm_id));
 | 
												$database->execute("DELETE FROM private_message WHERE id = ?", array($pm_id));
 | 
				
			||||||
							log_info("pm", "Deleted PM #$pm_id");
 | 
												log_info("pm", "Deleted PM #$pm_id");
 | 
				
			||||||
							$event->page->set_mode("redirect");
 | 
												$page->set_mode("redirect");
 | 
				
			||||||
							$event->page->set_redirect(make_link("user"));
 | 
												$page->set_redirect(make_link("user"));
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
						else {
 | 
											else {
 | 
				
			||||||
							// permission denied
 | 
												// permission denied
 | 
				
			||||||
@ -96,16 +93,16 @@ class PM implements Extension {
 | 
				
			|||||||
						$from_id = $user->id;
 | 
											$from_id = $user->id;
 | 
				
			||||||
						$subject = $_POST["subject"];
 | 
											$subject = $_POST["subject"];
 | 
				
			||||||
						$message = $_POST["message"];
 | 
											$message = $_POST["message"];
 | 
				
			||||||
						send_event(new SendPMEvent($event->context, $from_id, $_SERVER["REMOTE_ADDR"], $to_id, $subject, $message));
 | 
											send_event(new SendPMEvent($from_id, $_SERVER["REMOTE_ADDR"], $to_id, $subject, $message));
 | 
				
			||||||
						$event->page->set_mode("redirect");
 | 
											$page->set_mode("redirect");
 | 
				
			||||||
						$event->page->set_redirect(make_link($_SERVER["REFERER"]));
 | 
											$page->set_redirect(make_link($_SERVER["REFERER"]));
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof SendPMEvent) {
 | 
							if($event instanceof SendPMEvent) {
 | 
				
			||||||
			$event->context->database->execute("
 | 
								$database->execute("
 | 
				
			||||||
					INSERT INTO private_message(
 | 
										INSERT INTO private_message(
 | 
				
			||||||
						from_id, from_ip, to_id,
 | 
											from_id, from_ip, to_id,
 | 
				
			||||||
						sent_date, subject, message)
 | 
											sent_date, subject, message)
 | 
				
			||||||
@ -117,9 +114,8 @@ class PM implements Extension {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	protected function install(RequestContext $context) {
 | 
						protected function install() {
 | 
				
			||||||
		$database = $context->database;
 | 
							global $config, $database;
 | 
				
			||||||
		$config = $context->config;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// shortcut to latest
 | 
							// shortcut to latest
 | 
				
			||||||
		if($config->get_int("pm_version") < 1) {
 | 
							if($config->get_int("pm_version") < 1) {
 | 
				
			||||||
 | 
				
			|||||||
@ -23,12 +23,10 @@ class RandomImage implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(($event instanceof PageRequestEvent) && $event->page_matches("random_image")) {
 | 
							if(($event instanceof PageRequestEvent) && $event->page_matches("random_image")) {
 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
			global $database;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if($event->count_args() == 1) {
 | 
								if($event->count_args() == 1) {
 | 
				
			||||||
				$action = $event->get_arg(0);
 | 
									$action = $event->get_arg(0);
 | 
				
			||||||
				$search_terms = array();
 | 
									$search_terms = array();
 | 
				
			||||||
@ -37,18 +35,18 @@ class RandomImage implements Extension {
 | 
				
			|||||||
				$action = $event->get_arg(0);
 | 
									$action = $event->get_arg(0);
 | 
				
			||||||
				$search_terms = explode(' ', $event->get_arg(1));
 | 
									$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($event->get_arg(0) == "download") {
 | 
				
			||||||
				if(!is_null($image)) {
 | 
									if(!is_null($image)) {
 | 
				
			||||||
					$event->page->set_mode("data");
 | 
										$page->set_mode("data");
 | 
				
			||||||
					$event->page->set_type("image/jpeg");
 | 
										$page->set_type("image/jpeg");
 | 
				
			||||||
					$event->page->set_data(file_get_contents($image->get_image_filename()));
 | 
										$page->set_data(file_get_contents($image->get_image_filename()));
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if($event->get_arg(0) == "view") {
 | 
								if($event->get_arg(0) == "view") {
 | 
				
			||||||
				if(!is_null($image)) {
 | 
									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) {
 | 
							if($event instanceof PostListBuildingEvent) {
 | 
				
			||||||
			global $config, $database;
 | 
					 | 
				
			||||||
			if($config->get_bool("show_random_block")) {
 | 
								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)) {
 | 
									if(!is_null($image)) {
 | 
				
			||||||
					$this->theme->display_random($event->page, $image);
 | 
										$this->theme->display_random($page, $image);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -20,15 +20,14 @@ class Ratings implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof InitExtEvent) {
 | 
							if($event instanceof InitExtEvent) {
 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
			if($config->get_int("ext_ratings2_version") < 2) {
 | 
								if($config->get_int("ext_ratings2_version") < 2) {
 | 
				
			||||||
				$this->install();
 | 
									$this->install();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
			$config->set_default_string("ext_rating_anon_privs", 'sq');
 | 
								$config->set_default_string("ext_rating_anon_privs", 'sq');
 | 
				
			||||||
			$config->set_default_string("ext_rating_user_privs", 'sq');
 | 
								$config->set_default_string("ext_rating_user_privs", 'sq');
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@ -38,14 +37,12 @@ class Ratings implements Extension {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof ImageInfoBoxBuildingEvent) {
 | 
							if($event instanceof ImageInfoBoxBuildingEvent) {
 | 
				
			||||||
			global $user;
 | 
					 | 
				
			||||||
			if($user->is_admin()) {
 | 
								if($user->is_admin()) {
 | 
				
			||||||
				$event->add_part($this->theme->get_rater_html($event->image->id, $event->image->rating), 80);
 | 
									$event->add_part($this->theme->get_rater_html($event->image->id, $event->image->rating), 80);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof ImageInfoSetEvent) {
 | 
							if($event instanceof ImageInfoSetEvent) {
 | 
				
			||||||
			global $user;
 | 
					 | 
				
			||||||
			if($user->is_admin()) {
 | 
								if($user->is_admin()) {
 | 
				
			||||||
				send_event(new RatingSetEvent($event->image->id, $user, $_POST['rating']));
 | 
									send_event(new RatingSetEvent($event->image->id, $user, $_POST['rating']));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@ -70,7 +67,6 @@ class Ratings implements Extension {
 | 
				
			|||||||
		if($event instanceof SearchTermParseEvent) {
 | 
							if($event instanceof SearchTermParseEvent) {
 | 
				
			||||||
			$matches = array();
 | 
								$matches = array();
 | 
				
			||||||
			if(is_null($event->term) && $this->no_rating_query($event->context)) {
 | 
								if(is_null($event->term) && $this->no_rating_query($event->context)) {
 | 
				
			||||||
				global $user, $config;
 | 
					 | 
				
			||||||
				if($user->is_anonymous()) {
 | 
									if($user->is_anonymous()) {
 | 
				
			||||||
					$sqes = $config->get_string("ext_rating_anon_privs");
 | 
										$sqes = $config->get_string("ext_rating_anon_privs");
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
				
			|||||||
@ -23,7 +23,7 @@ class RegenThumb implements Extension {
 | 
				
			|||||||
			if($user->is_admin() && isset($_POST['image_id'])) {
 | 
								if($user->is_admin() && isset($_POST['image_id'])) {
 | 
				
			||||||
				global $config;
 | 
									global $config;
 | 
				
			||||||
				global $database;
 | 
									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));
 | 
									send_event(new ThumbnailGenerationEvent($image->hash, $image->ext));
 | 
				
			||||||
				$this->theme->display_results($event->page, $image);
 | 
									$this->theme->display_results($event->page, $image);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
				
			|||||||
@ -33,11 +33,10 @@ class ReportImage implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof InitExtEvent) {
 | 
							if($event instanceof InitExtEvent) {
 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			$config->set_default_bool('report_image_show_thumbs', true);
 | 
								$config->set_default_bool('report_image_show_thumbs', true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if($config->get_int("ext_report_image_version") < 1) {
 | 
								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")) {
 | 
							if(($event instanceof PageRequestEvent) && $event->page_matches("image_report")) {
 | 
				
			||||||
			global $user;
 | 
					 | 
				
			||||||
			if($event->get_arg(0) == "add") {
 | 
								if($event->get_arg(0) == "add") {
 | 
				
			||||||
				if(isset($_POST['image_id']) && isset($_POST['reason'])) {
 | 
									if(isset($_POST['image_id']) && isset($_POST['reason'])) {
 | 
				
			||||||
					$image_id = int_escape($_POST['image_id']);
 | 
										$image_id = int_escape($_POST['image_id']);
 | 
				
			||||||
					send_event(new AddReportedImageEvent($image_id, $event->user->id, $_POST['reason']));
 | 
										send_event(new AddReportedImageEvent($image_id, $user->id, $_POST['reason']));
 | 
				
			||||||
					$event->page->set_mode("redirect");
 | 
										$page->set_mode("redirect");
 | 
				
			||||||
					$event->page->set_redirect(make_link("post/view/$image_id"));
 | 
										$page->set_redirect(make_link("post/view/$image_id"));
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else if($event->get_arg(0) == "remove") {
 | 
								else if($event->get_arg(0) == "remove") {
 | 
				
			||||||
				if(isset($_POST['id'])) {
 | 
									if(isset($_POST['id'])) {
 | 
				
			||||||
					if($event->user->is_admin()) {
 | 
										if($user->is_admin()) {
 | 
				
			||||||
						send_event(new RemoveReportedImageEvent($_POST['id']));
 | 
											send_event(new RemoveReportedImageEvent($_POST['id']));
 | 
				
			||||||
						$event->page->set_mode("redirect");
 | 
											$page->set_mode("redirect");
 | 
				
			||||||
						$event->page->set_redirect(make_link("image_report/list"));
 | 
											$page->set_redirect(make_link("image_report/list"));
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else if($event->get_arg(0) == "list") {
 | 
								else if($event->get_arg(0) == "list") {
 | 
				
			||||||
				if($event->user->is_admin()) {
 | 
									if($user->is_admin()) {
 | 
				
			||||||
					$this->theme->display_reported_images($event->page, $this->get_reported_images());
 | 
										$this->theme->display_reported_images($page, $this->get_reported_images());
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof AddReportedImageEvent) {
 | 
							if($event instanceof AddReportedImageEvent) {
 | 
				
			||||||
			global $database;
 | 
					 | 
				
			||||||
			$database->Execute(
 | 
								$database->Execute(
 | 
				
			||||||
					"INSERT INTO image_reports(image_id, reporter_id, reason)
 | 
										"INSERT INTO image_reports(image_id, reporter_id, reason)
 | 
				
			||||||
					VALUES (?, ?, ?)",
 | 
										VALUES (?, ?, ?)",
 | 
				
			||||||
@ -80,13 +77,12 @@ class ReportImage implements Extension {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof RemoveReportedImageEvent) {
 | 
							if($event instanceof RemoveReportedImageEvent) {
 | 
				
			||||||
			global $database;
 | 
					 | 
				
			||||||
			$database->Execute("DELETE FROM image_reports WHERE id = ?", array($event->id));
 | 
								$database->Execute("DELETE FROM image_reports WHERE id = ?", array($event->id));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof DisplayingImageEvent) {
 | 
							if($event instanceof DisplayingImageEvent) {
 | 
				
			||||||
			if($event->context->config->get_bool('report_image_anon') || !$event->context->user->is_anonymous()) {
 | 
								if($config->get_bool('report_image_anon') || !$user->is_anonymous()) {
 | 
				
			||||||
				$this->theme->display_image_banner($event->page, $event->image);
 | 
									$this->theme->display_image_banner($page, $event->image);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -98,13 +94,12 @@ class ReportImage implements Extension {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof UserBlockBuildingEvent) {
 | 
							if($event instanceof UserBlockBuildingEvent) {
 | 
				
			||||||
			if($event->user->is_admin()) {
 | 
								if($user->is_admin()) {
 | 
				
			||||||
				$event->add_link("Reported Images", make_link("image_report/list"));
 | 
									$event->add_link("Reported Images", make_link("image_report/list"));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof ImageDeletionEvent) {
 | 
							if($event instanceof ImageDeletionEvent) {
 | 
				
			||||||
			global $database;
 | 
					 | 
				
			||||||
			$database->Execute("DELETE FROM image_reports WHERE image_id = ?", array($event->image->id));
 | 
								$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() {
 | 
						public function get_reported_images() {
 | 
				
			||||||
		global $database;
 | 
							global $config, $database;
 | 
				
			||||||
		$all_reports = $database->get_all("
 | 
							$all_reports = $database->get_all("
 | 
				
			||||||
			SELECT image_reports.*, users.name AS reporter_name
 | 
								SELECT image_reports.*, users.name AS reporter_name
 | 
				
			||||||
			FROM image_reports
 | 
								FROM image_reports
 | 
				
			||||||
@ -135,9 +130,8 @@ class ReportImage implements Extension {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		$reports = array();
 | 
							$reports = array();
 | 
				
			||||||
		foreach($all_reports as $report) {
 | 
							foreach($all_reports as $report) {
 | 
				
			||||||
			global $database, $config;
 | 
					 | 
				
			||||||
			$image_id = int_escape($report['image_id']);
 | 
								$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)) {
 | 
								if(is_null($image)) {
 | 
				
			||||||
				send_event(new RemoveReportedImageEvent($report['id']));
 | 
									send_event(new RemoveReportedImageEvent($report['id']));
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
 | 
				
			|||||||
@ -9,9 +9,9 @@
 | 
				
			|||||||
class RSS_Images implements Extension {
 | 
					class RSS_Images implements Extension {
 | 
				
			||||||
// event handling {{{
 | 
					// event handling {{{
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof PostListBuildingEvent) {
 | 
							if($event instanceof PostListBuildingEvent) {
 | 
				
			||||||
			global $page;
 | 
					 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
			$title = $config->get_string('title');
 | 
								$title = $config->get_string('title');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if(count($event->search_terms) > 0) {
 | 
								if(count($event->search_terms) > 0) {
 | 
				
			||||||
@ -26,9 +26,6 @@ class RSS_Images implements Extension {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(($event instanceof PageRequestEvent) && $event->page_matches("rss/images")) {
 | 
							if(($event instanceof PageRequestEvent) && $event->page_matches("rss/images")) {
 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
			global $database;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			$page_number = 0;
 | 
								$page_number = 0;
 | 
				
			||||||
			$search_terms = array();
 | 
								$search_terms = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -45,7 +42,7 @@ class RSS_Images implements Extension {
 | 
				
			|||||||
				$page_number = int_escape($event->get_arg(1));
 | 
									$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);
 | 
								$this->do_rss($images, $search_terms, $page_number);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -25,19 +25,20 @@ class SimpleSCoreTest implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(($event instanceof PageRequestEvent) && $event->page_matches("test")) {
 | 
							if(($event instanceof PageRequestEvent) && $event->page_matches("test")) {
 | 
				
			||||||
			$event->page->set_title("Test Results");
 | 
								$page->set_title("Test Results");
 | 
				
			||||||
			$event->page->set_heading("Test Results");
 | 
								$page->set_heading("Test Results");
 | 
				
			||||||
			$event->page->add_block(new NavBlock());
 | 
								$page->add_block(new NavBlock());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$all = new TestFinder($event->get_arg(0));
 | 
								$all = new TestFinder($event->get_arg(0));
 | 
				
			||||||
			$all->run(new SCoreReporter($event->page));
 | 
								$all->run(new SCoreReporter($page));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof UserBlockBuildingEvent) {
 | 
							if($event instanceof UserBlockBuildingEvent) {
 | 
				
			||||||
			if($event->user->is_admin()) {
 | 
								if($user->is_admin()) {
 | 
				
			||||||
				$event->add_link("Run Tests", make_link("test/all"));
 | 
									$event->add_link("Run Tests", make_link("test/all"));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,8 +1,10 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
#require_once('lib/simpletest/autorun.php');
 | 
					#require_once('lib/simpletest/autorun.php');
 | 
				
			||||||
require_once('simpletest/web_tester.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');
 | 
					require_once('simpletest/reporter.php');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					chdir("../../");
 | 
				
			||||||
require_once('config.php');
 | 
					require_once('config.php');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SectionReporter extends TextReporter {
 | 
					class SectionReporter extends TextReporter {
 | 
				
			||||||
@ -11,7 +13,6 @@ class SectionReporter extends TextReporter {
 | 
				
			|||||||
		print "\n** $name\n";
 | 
							print "\n** $name\n";
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
// }}} */
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
class AllTests extends TestSuite {
 | 
					class AllTests extends TestSuite {
 | 
				
			||||||
	function AllTests() {
 | 
						function AllTests() {
 | 
				
			||||||
 | 
				
			|||||||
@ -10,10 +10,11 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class SiteDescription implements Extension {
 | 
					class SiteDescription implements Extension {
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if($event instanceof PageRequestEvent) {
 | 
							if($event instanceof PageRequestEvent) {
 | 
				
			||||||
			if(strlen($event->context->config->get_string("site_description")) > 0) {
 | 
								if(strlen($config->get_string("site_description")) > 0) {
 | 
				
			||||||
				$description = $event->context->config->get_string("site_description");
 | 
									$description = $config->get_string("site_description");
 | 
				
			||||||
				$event->context->page->add_header("<meta name=\"description\" content=\"$description\">");
 | 
									$page->add_header("<meta name=\"description\" content=\"$description\">");
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -9,11 +9,11 @@ class Tag_History implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(($event instanceof InitExtEvent)) {
 | 
							if(($event instanceof InitExtEvent)) {
 | 
				
			||||||
			// shimmie is being installed so call install to create the table.
 | 
								// shimmie is being installed so call install to create the table.
 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
			if($config->get_int("ext_tag_history_version") < 3) {
 | 
								if($config->get_int("ext_tag_history_version") < 3) {
 | 
				
			||||||
				$this->install();
 | 
									$this->install();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@ -24,7 +24,6 @@ class Tag_History implements Extension {
 | 
				
			|||||||
			if($event->get_arg(0) == "revert")
 | 
								if($event->get_arg(0) == "revert")
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				// this is a request to revert to a previous version of the tags
 | 
									// 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()) {
 | 
									if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) {
 | 
				
			||||||
					$this->process_revert_request($_POST['revert']);
 | 
										$this->process_revert_request($_POST['revert']);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
@ -33,16 +32,16 @@ class Tag_History implements Extension {
 | 
				
			|||||||
			{
 | 
								{
 | 
				
			||||||
				// must be an attempt to view a tag history
 | 
									// must be an attempt to view a tag history
 | 
				
			||||||
				$image_id = int_escape($event->get_arg(0));
 | 
									$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 {
 | 
								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))
 | 
							if(($event instanceof DisplayingImageEvent))
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			// handle displaying a link on the view page
 | 
								// 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))
 | 
							if(($event instanceof ImageDeletionEvent))
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
 | 
				
			|||||||
@ -44,7 +44,7 @@ class WikiPage {
 | 
				
			|||||||
	public function get_owner() {
 | 
						public function get_owner() {
 | 
				
			||||||
		global $config;
 | 
							global $config;
 | 
				
			||||||
		global $database;
 | 
							global $database;
 | 
				
			||||||
		return User::by_id($config, $database, $this->owner_id);
 | 
							return User::by_id($this->owner_id);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function is_locked() {
 | 
						public function is_locked() {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,8 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
 | 
					class WordFiterTest extends WebTestCase {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(!defined(VERSION)) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class WordFilterUnitTest extends UnitTestCase {
 | 
					class WordFilterUnitTest extends UnitTestCase {
 | 
				
			||||||
	public function testURL() {
 | 
						public function testURL() {
 | 
				
			||||||
		$this->assertEqual(
 | 
							$this->assertEqual(
 | 
				
			||||||
 | 
				
			|||||||
@ -10,11 +10,11 @@ class Zoom implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if($this->theme == null) $this->theme = get_theme_object($this);
 | 
							if($this->theme == null) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof DisplayingImageEvent) {
 | 
							if($event instanceof DisplayingImageEvent) {
 | 
				
			||||||
			global $config;
 | 
								$this->theme->display_zoomer($page, $event->image, $config->get_bool("image_zoom", false));
 | 
				
			||||||
			$this->theme->display_zoomer($event->page, $event->image, $config->get_bool("image_zoom", false));
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof SetupBuildingEvent) {
 | 
							if($event instanceof SetupBuildingEvent) {
 | 
				
			||||||
 | 
				
			|||||||
@ -4,11 +4,7 @@
 | 
				
			|||||||
 * generic parent class
 | 
					 * generic parent class
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
abstract class Event {
 | 
					abstract class Event {
 | 
				
			||||||
	var $context;
 | 
						public function __construct() {}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	public function __construct(RequestContext $context) {
 | 
					 | 
				
			||||||
		$this->context = $context;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -32,12 +28,9 @@ class PageRequestEvent extends Event {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	var $part_count;
 | 
						var $part_count;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function __construct(RequestContext $context, $args) {
 | 
						public function __construct($args) {
 | 
				
			||||||
		parent::__construct($context);
 | 
					 | 
				
			||||||
		$this->args = $args;
 | 
							$this->args = $args;
 | 
				
			||||||
		$this->arg_count = count($args);
 | 
							$this->arg_count = count($args);
 | 
				
			||||||
		$this->page = $context->page;
 | 
					 | 
				
			||||||
		$this->user = $context->user;
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function page_matches($name) {
 | 
						public function page_matches($name) {
 | 
				
			||||||
@ -105,8 +98,7 @@ class LogEvent extends Event {
 | 
				
			|||||||
	var $message;
 | 
						var $message;
 | 
				
			||||||
	var $time;
 | 
						var $time;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function __construct($context, $section, $priority, $message) {
 | 
						public function __construct($section, $priority, $message) {
 | 
				
			||||||
		parent::__construct($context);
 | 
					 | 
				
			||||||
		$this->section = $section;
 | 
							$this->section = $section;
 | 
				
			||||||
		$this->priority = $priority;
 | 
							$this->priority = $priority;
 | 
				
			||||||
		$this->message = $message;
 | 
							$this->message = $message;
 | 
				
			||||||
@ -114,8 +106,9 @@ class LogEvent extends Event {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		// this should be an extension
 | 
							// this should be an extension
 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
 | 
							global $user;
 | 
				
			||||||
		$ftime = date("Y-m-d H:i:s", $this->time);
 | 
							$ftime = date("Y-m-d H:i:s", $this->time);
 | 
				
			||||||
		$username = $context->user->name;
 | 
							$username = $user->name;
 | 
				
			||||||
		$ip = $_SERVER['REMOTE_ADDR'];
 | 
							$ip = $_SERVER['REMOTE_ADDR'];
 | 
				
			||||||
		$fp = fopen("shimmie.log", "a");
 | 
							$fp = fopen("shimmie.log", "a");
 | 
				
			||||||
		fputs($fp, "$ftime\t$section/$priority\t$username/$ip\t$message\n");
 | 
							fputs($fp, "$ftime\t$section/$priority\t$username/$ip\t$message\n");
 | 
				
			||||||
 | 
				
			|||||||
@ -15,9 +15,6 @@
 | 
				
			|||||||
 * sound file, or any other supported upload type.
 | 
					 * sound file, or any other supported upload type.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
class Image {
 | 
					class Image {
 | 
				
			||||||
	var $config;
 | 
					 | 
				
			||||||
	var $database;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	var $id = null;
 | 
						var $id = null;
 | 
				
			||||||
	var $height, $width;
 | 
						var $height, $width;
 | 
				
			||||||
	var $hash, $filesize;
 | 
						var $hash, $filesize;
 | 
				
			||||||
@ -30,12 +27,6 @@ class Image {
 | 
				
			|||||||
	 * Constructors and other instance creators
 | 
						 * Constructors and other instance creators
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function Image($row=null) {
 | 
						public function Image($row=null) {
 | 
				
			||||||
		global $config;
 | 
					 | 
				
			||||||
		global $database;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		$this->config = $config;
 | 
					 | 
				
			||||||
		$this->database = $database;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		if(!is_null($row)) {
 | 
							if(!is_null($row)) {
 | 
				
			||||||
			foreach($row as $name => $value) {
 | 
								foreach($row as $name => $value) {
 | 
				
			||||||
				// FIXME: some databases use table.name rather than name
 | 
									// 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));
 | 
							assert(is_numeric($id));
 | 
				
			||||||
 | 
							global $database;
 | 
				
			||||||
		$image = null;
 | 
							$image = null;
 | 
				
			||||||
		$row = $database->get_row("SELECT * FROM images WHERE images.id=?", array($id));
 | 
							$row = $database->get_row("SELECT * FROM images WHERE images.id=?", array($id));
 | 
				
			||||||
		return ($row ? new Image($row) : null);
 | 
							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));
 | 
							assert(is_string($hash));
 | 
				
			||||||
 | 
							global $database;
 | 
				
			||||||
		$image = null;
 | 
							$image = null;
 | 
				
			||||||
		$row = $database->db->GetRow("SELECT images.* FROM images WHERE hash=?", array($hash));
 | 
							$row = $database->db->GetRow("SELECT images.* FROM images WHERE hash=?", array($hash));
 | 
				
			||||||
		return ($row ? new Image($row) : null);
 | 
							return ($row ? new Image($row) : null);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public static function by_random(Config $config, Database $database, $tags=array()) {
 | 
						public static function by_random($tags=array()) {
 | 
				
			||||||
		$max = Image::count_images($config, $database, $tags);
 | 
							assert(is_array($tags));
 | 
				
			||||||
 | 
							$max = Image::count_images($tags);
 | 
				
			||||||
		$rand = mt_rand(0, $max-1);
 | 
							$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];
 | 
							if(count($set) > 0) return $set[0];
 | 
				
			||||||
		else return null;
 | 
							else return null;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public static function find_images(Config $config, Database $database, $start, $limit, $tags=array()) {
 | 
						public static function find_images($start, $limit, $tags=array()) {
 | 
				
			||||||
		$images = array();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		assert(is_numeric($start));
 | 
							assert(is_numeric($start));
 | 
				
			||||||
		assert(is_numeric($limit));
 | 
							assert(is_numeric($limit));
 | 
				
			||||||
 | 
							assert(is_array($tags));
 | 
				
			||||||
 | 
							global $database;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$images = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($start < 0) $start = 0;
 | 
							if($start < 0) $start = 0;
 | 
				
			||||||
		if($limit < 1) $limit = 1;
 | 
							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)));
 | 
							$querylet->append(new Querylet("ORDER BY images.id DESC LIMIT ? OFFSET ?", array($limit, $start)));
 | 
				
			||||||
		$result = $database->execute($querylet->sql, $querylet->variables);
 | 
							$result = $database->execute($querylet->sql, $querylet->variables);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -89,20 +86,24 @@ class Image {
 | 
				
			|||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * Image-related utility functions
 | 
						 * 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) {
 | 
							if(count($tags) == 0) {
 | 
				
			||||||
			return $database->db->GetOne("SELECT COUNT(*) FROM images");
 | 
								return $database->db->GetOne("SELECT COUNT(*) FROM images");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else {
 | 
							else {
 | 
				
			||||||
			$querylet = Image::build_search_querylet($config, $database, $tags);
 | 
								$querylet = Image::build_search_querylet($tags);
 | 
				
			||||||
			$result = $database->execute($querylet->sql, $querylet->variables);
 | 
								$result = $database->execute($querylet->sql, $querylet->variables);
 | 
				
			||||||
			return $result->RecordCount();
 | 
								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');
 | 
							$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) {
 | 
						public function get_next($tags=array(), $next=true) {
 | 
				
			||||||
		assert(is_array($tags));
 | 
							assert(is_array($tags));
 | 
				
			||||||
		assert(is_bool($next));
 | 
							assert(is_bool($next));
 | 
				
			||||||
 | 
							global $database;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($next) {
 | 
							if($next) {
 | 
				
			||||||
			$gtlt = "<";
 | 
								$gtlt = "<";
 | 
				
			||||||
@ -123,13 +125,13 @@ class Image {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(count($tags) == 0) {
 | 
							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 {
 | 
							else {
 | 
				
			||||||
			$tags[] = "id$gtlt{$this->id}";
 | 
								$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");
 | 
								$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);
 | 
							return ($row ? new Image($row) : null);
 | 
				
			||||||
@ -140,23 +142,24 @@ class Image {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function get_owner() {
 | 
						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() {
 | 
						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($cached) return $cached;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(!isset($this->tag_array)) {
 | 
							if(!isset($this->tag_array)) {
 | 
				
			||||||
			$this->tag_array = 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) {
 | 
								while(!$row->EOF) {
 | 
				
			||||||
				$this->tag_array[] = $row->fields['tag'];
 | 
									$this->tag_array[] = $row->fields['tag'];
 | 
				
			||||||
				$row->MoveNext();
 | 
									$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;
 | 
							return $this->tag_array;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -165,11 +168,11 @@ class Image {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function get_image_link() {
 | 
						public function get_image_link() {
 | 
				
			||||||
		$c = $this->config;
 | 
							global $config;
 | 
				
			||||||
		if(strlen($c->get_string('image_ilink')) > 0) {
 | 
							if(strlen($config->get_string('image_ilink')) > 0) {
 | 
				
			||||||
			return $this->parse_link_template($c->get_string('image_ilink'));
 | 
								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'));
 | 
								return $this->parse_link_template(make_link('_images/$hash/$id - $tags.$ext'));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else {
 | 
							else {
 | 
				
			||||||
@ -178,15 +181,16 @@ class Image {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function get_short_link() {
 | 
						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() {
 | 
						public function get_thumb_link() {
 | 
				
			||||||
		$c = $this->config;
 | 
							global $config;
 | 
				
			||||||
		if(strlen($c->get_string('image_tlink')) > 0) {
 | 
							if(strlen($config->get_string('image_tlink')) > 0) {
 | 
				
			||||||
			return $this->parse_link_template($c->get_string('image_tlink'));
 | 
								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'));
 | 
								return $this->parse_link_template(make_link('_thumbs/$hash/thumb.jpg'));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else {
 | 
							else {
 | 
				
			||||||
@ -229,18 +233,21 @@ class Image {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function set_source($source) {
 | 
						public function set_source($source) {
 | 
				
			||||||
 | 
							global $database;
 | 
				
			||||||
		if(empty($source)) $source = null;
 | 
							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() {
 | 
						public function delete_tags_from_image() {
 | 
				
			||||||
		$this->database->execute(
 | 
							global $database;
 | 
				
			||||||
 | 
							$database->execute(
 | 
				
			||||||
				"UPDATE tags SET count = count - 1 WHERE id IN ".
 | 
									"UPDATE tags SET count = count - 1 WHERE id IN ".
 | 
				
			||||||
				"(SELECT tag_id FROM image_tags WHERE image_id = ?)", array($this->id));
 | 
									"(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) {
 | 
						public function set_tags($tags) {
 | 
				
			||||||
 | 
							global $database;
 | 
				
			||||||
		$tags = Tag::resolve_list($tags);
 | 
							$tags = Tag::resolve_list($tags);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		assert(is_array($tags));
 | 
							assert(is_array($tags));
 | 
				
			||||||
@ -251,32 +258,32 @@ class Image {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		// insert each new tags
 | 
							// insert each new tags
 | 
				
			||||||
		foreach($tags as $tag) {
 | 
							foreach($tags as $tag) {
 | 
				
			||||||
			$id = $this->database->db->GetOne(
 | 
								$id = $database->db->GetOne(
 | 
				
			||||||
					"SELECT id FROM tags WHERE tag = ?",
 | 
										"SELECT id FROM tags WHERE tag = ?",
 | 
				
			||||||
					array($tag));
 | 
										array($tag));
 | 
				
			||||||
			if(empty($id)) {
 | 
								if(empty($id)) {
 | 
				
			||||||
				// a new tag
 | 
									// a new tag
 | 
				
			||||||
				$this->database->execute(
 | 
									$database->execute(
 | 
				
			||||||
						"INSERT INTO tags(tag) VALUES (?)",
 | 
											"INSERT INTO tags(tag) VALUES (?)",
 | 
				
			||||||
						array($tag));
 | 
											array($tag));
 | 
				
			||||||
				$this->database->execute(
 | 
									$database->execute(
 | 
				
			||||||
						"INSERT INTO image_tags(image_id, tag_id)
 | 
											"INSERT INTO image_tags(image_id, tag_id)
 | 
				
			||||||
						VALUES(?, (SELECT id FROM tags WHERE tag = ?))",
 | 
											VALUES(?, (SELECT id FROM tags WHERE tag = ?))",
 | 
				
			||||||
						array($this->id, $tag));
 | 
											array($this->id, $tag));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else {
 | 
								else {
 | 
				
			||||||
				// user of an existing tag
 | 
									// user of an existing tag
 | 
				
			||||||
				$this->database->execute(
 | 
									$database->execute(
 | 
				
			||||||
						"INSERT INTO image_tags(image_id, tag_id) VALUES(?, ?)",
 | 
											"INSERT INTO image_tags(image_id, tag_id) VALUES(?, ?)",
 | 
				
			||||||
						array($this->id, $id));
 | 
											array($this->id, $id));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			$this->database->execute(
 | 
								$database->execute(
 | 
				
			||||||
					"UPDATE tags SET count = count + 1 WHERE tag = ?",
 | 
										"UPDATE tags SET count = count + 1 WHERE tag = ?",
 | 
				
			||||||
					array($tag));
 | 
										array($tag));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		log_info("core-image", "Tags for Image #{$this->id} set to: ".implode(" ", $tags));
 | 
							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
 | 
						 * Other actions
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public function delete() {
 | 
						public function delete() {
 | 
				
			||||||
		$this->delete_tags_from_image();
 | 
							global $database;
 | 
				
			||||||
		$this->database->execute("DELETE FROM images WHERE id=?", array($this->id));
 | 
							$delete_tags_from_image();
 | 
				
			||||||
 | 
							$database->execute("DELETE FROM images WHERE id=?", array($this->id));
 | 
				
			||||||
		log_info("core-image", "Deleted Image #{$image->id} ({$image->hash})");
 | 
							log_info("core-image", "Deleted Image #{$image->id} ({$image->hash})");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		unlink($this->get_image_filename());
 | 
							unlink($this->get_image_filename());
 | 
				
			||||||
@ -293,6 +301,8 @@ class Image {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function parse_link_template($tmpl, $_escape="url_escape") {
 | 
						public function parse_link_template($tmpl, $_escape="url_escape") {
 | 
				
			||||||
 | 
							global $config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// don't bother hitting the database if it won't be used...
 | 
							// don't bother hitting the database if it won't be used...
 | 
				
			||||||
		$safe_tags = "";
 | 
							$safe_tags = "";
 | 
				
			||||||
		if(strpos($tmpl, '$tags') !== false) { // * stabs dynamically typed languages with a rusty spoon *
 | 
							if(strpos($tmpl, '$tags') !== false) { // * stabs dynamically typed languages with a rusty spoon *
 | 
				
			||||||
@ -301,7 +311,7 @@ class Image {
 | 
				
			|||||||
					"", $this->get_tag_list());
 | 
										"", $this->get_tag_list());
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$base_href = $this->config->get_string('base_href');
 | 
							$base_href = $config->get_string('base_href');
 | 
				
			||||||
		$fname = $this->get_filename();
 | 
							$fname = $this->get_filename();
 | 
				
			||||||
		$base_fname = strpos($fname, '.') ? substr($fname, 0, strrpos($fname, '.')) : $fname;
 | 
							$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('$size', "{$this->width}x{$this->height}", $tmpl);
 | 
				
			||||||
		$tmpl = str_replace('$filesize', to_shorthand_int($this->filesize), $tmpl);
 | 
							$tmpl = str_replace('$filesize', to_shorthand_int($this->filesize), $tmpl);
 | 
				
			||||||
		$tmpl = str_replace('$filename', $_escape($base_fname), $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);
 | 
							$plte = new ParseLinkTemplateEvent($tmpl, $this);
 | 
				
			||||||
		send_event($plte);
 | 
							send_event($plte);
 | 
				
			||||||
@ -322,16 +332,20 @@ class Image {
 | 
				
			|||||||
		return $tmpl;
 | 
							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")
 | 
							if($database->engine->name == "mysql")
 | 
				
			||||||
			return Image::build_ugly_search_querylet($config, $database, $terms);
 | 
								return Image::build_ugly_search_querylet($terms);
 | 
				
			||||||
		else
 | 
							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
 | 
						// this method is simple, fast and accurate; but mysql chokes on it
 | 
				
			||||||
	// because it uses subqueries
 | 
						// 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();
 | 
							$tag_querylets = array();
 | 
				
			||||||
		$img_querylets = array();
 | 
							$img_querylets = array();
 | 
				
			||||||
		$positive_tag_count = 0;
 | 
							$positive_tag_count = 0;
 | 
				
			||||||
@ -483,7 +497,9 @@ class Image {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// this function exists because mysql is a turd.
 | 
						// 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();
 | 
							$tag_querylets = array();
 | 
				
			||||||
		$img_querylets = array();
 | 
							$img_querylets = array();
 | 
				
			||||||
		$positive_tag_count = 0;
 | 
							$positive_tag_count = 0;
 | 
				
			||||||
 | 
				
			|||||||
@ -70,7 +70,9 @@ class GenericPage {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// ==============================================
 | 
						// ==============================================
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function display($context) {
 | 
						public function display() {
 | 
				
			||||||
 | 
							global $page;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		header("Content-type: {$this->type}");
 | 
							header("Content-type: {$this->type}");
 | 
				
			||||||
		header("X-Powered-By: SCore-".SCORE_VERSION);
 | 
							header("X-Powered-By: SCore-".SCORE_VERSION);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -79,7 +81,7 @@ class GenericPage {
 | 
				
			|||||||
				header("Cache-control: no-cache");
 | 
									header("Cache-control: no-cache");
 | 
				
			||||||
				usort($this->blocks, "blockcmp");
 | 
									usort($this->blocks, "blockcmp");
 | 
				
			||||||
				$layout = new Layout();
 | 
									$layout = new Layout();
 | 
				
			||||||
				$layout->display_page($context);
 | 
									$layout->display_page($page);
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			case "data":
 | 
								case "data":
 | 
				
			||||||
				if(!is_null($this->filename)) {
 | 
									if(!is_null($this->filename)) {
 | 
				
			||||||
 | 
				
			|||||||
@ -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;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
?>
 | 
					 | 
				
			||||||
@ -21,10 +21,7 @@ class User {
 | 
				
			|||||||
	*    $user = User::by_name($config, $database, "bob");         *
 | 
						*    $user = User::by_name($config, $database, "bob");         *
 | 
				
			||||||
	* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 | 
						* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function User(Config $config, Database $database, $row) {
 | 
						public function User($row) {
 | 
				
			||||||
		$this->config = $config;
 | 
					 | 
				
			||||||
		$this->database = $database;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		$this->id = int_escape($row['id']);
 | 
							$this->id = int_escape($row['id']);
 | 
				
			||||||
		$this->name = $row['name'];
 | 
							$this->name = $row['name'];
 | 
				
			||||||
		$this->email = $row['email'];
 | 
							$this->email = $row['email'];
 | 
				
			||||||
@ -32,32 +29,36 @@ class User {
 | 
				
			|||||||
		$this->admin = ($row['admin'] == 'Y');
 | 
							$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(
 | 
							$row = $database->get_row(
 | 
				
			||||||
				"SELECT * FROM users WHERE name = ? AND md5(concat(pass, ?)) = ?",
 | 
									"SELECT * FROM users WHERE name = ? AND md5(concat(pass, ?)) = ?",
 | 
				
			||||||
				array($name, get_session_ip($config), $session)
 | 
									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));
 | 
							assert(is_numeric($id));
 | 
				
			||||||
 | 
							global $database;
 | 
				
			||||||
		$row = $database->get_row("SELECT * FROM users WHERE id = ?", array($id));
 | 
							$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));
 | 
							assert(is_string($name));
 | 
				
			||||||
 | 
							global $database;
 | 
				
			||||||
		$row = $database->get_row("SELECT * FROM users WHERE name = ?", array($name));
 | 
							$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($name));
 | 
				
			||||||
		assert(is_string($hash));
 | 
							assert(is_string($hash));
 | 
				
			||||||
		assert(strlen($hash) == 32);
 | 
							assert(strlen($hash) == 32);
 | 
				
			||||||
 | 
							global $database;
 | 
				
			||||||
		$row = $database->get_row("SELECT * FROM users WHERE name = ? AND pass = ?", array($name, $hash));
 | 
							$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() {
 | 
						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() {
 | 
						public function is_admin() {
 | 
				
			||||||
@ -76,14 +78,16 @@ class User {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	public function set_admin($admin) {
 | 
						public function set_admin($admin) {
 | 
				
			||||||
		assert(is_bool($admin));
 | 
							assert(is_bool($admin));
 | 
				
			||||||
 | 
							global $database;
 | 
				
			||||||
		$yn = $admin ? 'Y' : 'N';
 | 
							$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");
 | 
							log_info("core-user", "Made {$this->name} admin=$yn");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function set_password($password) {
 | 
						public function set_password($password) {
 | 
				
			||||||
 | 
							global $database;
 | 
				
			||||||
		$hash = md5(strtolower($this->name) . $password);
 | 
							$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}");
 | 
							log_info("core-user", "Set password for {$this->name}");
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -227,8 +227,7 @@ define("LOG_DEBUG", 10);
 | 
				
			|||||||
define("LOG_NOTSET", 0);
 | 
					define("LOG_NOTSET", 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function log_msg($section, $priority, $message) {
 | 
					function log_msg($section, $priority, $message) {
 | 
				
			||||||
	global $context;
 | 
						send_event(new LogEvent($section, $priority, $message));
 | 
				
			||||||
	send_event(new LogEvent($context, $section, $priority, $message));
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function log_info($section, $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();
 | 
						$args = _get_query_parts();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if(count($args) == 0 || strlen($args[0]) == 0) {
 | 
						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;
 | 
						$user = null;
 | 
				
			||||||
	if(isset($_COOKIE["shm_user"]) && isset($_COOKIE["shm_session"])) {
 | 
						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)) {
 | 
							if(!is_null($tmp_user)) {
 | 
				
			||||||
			$user = $tmp_user;
 | 
								$user = $tmp_user;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if(is_null($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));
 | 
						assert(!is_null($user));
 | 
				
			||||||
	return $user;
 | 
						return $user;
 | 
				
			||||||
 | 
				
			|||||||
@ -15,34 +15,33 @@ class AdminPage implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(($event instanceof PageRequestEvent) && $event->page_matches("admin")) {
 | 
							if(($event instanceof PageRequestEvent) && $event->page_matches("admin")) {
 | 
				
			||||||
			if(!$event->user->is_admin()) {
 | 
								if(!$user->is_admin()) {
 | 
				
			||||||
				$this->theme->display_permission_denied($event->page);
 | 
									$this->theme->display_permission_denied($page);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else {
 | 
								else {
 | 
				
			||||||
				if($event->get_arg(0) == "delete_image") {
 | 
									if($event->get_arg(0) == "delete_image") {
 | 
				
			||||||
					// FIXME: missing lots of else {complain}
 | 
										// FIXME: missing lots of else {complain}
 | 
				
			||||||
					if(isset($_POST['image_id'])) {
 | 
										if(isset($_POST['image_id'])) {
 | 
				
			||||||
						global $config;
 | 
											$image = Image::by_id($_POST['image_id']);
 | 
				
			||||||
						global $database;
 | 
					 | 
				
			||||||
						$image = Image::by_id($config, $database, $_POST['image_id']);
 | 
					 | 
				
			||||||
						if($image) {
 | 
											if($image) {
 | 
				
			||||||
							send_event(new ImageDeletionEvent($image));
 | 
												send_event(new ImageDeletionEvent($image));
 | 
				
			||||||
							$event->page->set_mode("redirect");
 | 
												$page->set_mode("redirect");
 | 
				
			||||||
							$event->page->set_redirect(make_link("post/list"));
 | 
												$page->set_redirect(make_link("post/list"));
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				else {
 | 
									else {
 | 
				
			||||||
					send_event(new AdminBuildingEvent($event->page));
 | 
										send_event(new AdminBuildingEvent($page));
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(($event instanceof PageRequestEvent) && $event->page_matches("admin_utils")) {
 | 
							if(($event instanceof PageRequestEvent) && $event->page_matches("admin_utils")) {
 | 
				
			||||||
			if($event->user->is_admin()) {
 | 
								if($user->is_admin()) {
 | 
				
			||||||
				log_info("admin", "Util: {$_POST['action']}");
 | 
									log_info("admin", "Util: {$_POST['action']}");
 | 
				
			||||||
				set_time_limit(0);
 | 
									set_time_limit(0);
 | 
				
			||||||
				$redirect = false;
 | 
									$redirect = false;
 | 
				
			||||||
@ -61,30 +60,30 @@ class AdminPage implements Extension {
 | 
				
			|||||||
						$redirect = true;
 | 
											$redirect = true;
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
					case 'database dump':
 | 
										case 'database dump':
 | 
				
			||||||
						$this->dbdump($event->page);
 | 
											$this->dbdump($page);
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if($redirect) {
 | 
									if($redirect) {
 | 
				
			||||||
					$event->page->set_mode("redirect");
 | 
										$page->set_mode("redirect");
 | 
				
			||||||
					$event->page->set_redirect(make_link("admin"));
 | 
										$page->set_redirect(make_link("admin"));
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof ImageAdminBlockBuildingEvent) {
 | 
							if($event instanceof ImageAdminBlockBuildingEvent) {
 | 
				
			||||||
			if($event->user->is_admin()) {
 | 
								if($user->is_admin()) {
 | 
				
			||||||
				$event->add_part($this->theme->get_deleter_html($event->image->id));
 | 
									$event->add_part($this->theme->get_deleter_html($event->image->id));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof AdminBuildingEvent) {
 | 
							if($event instanceof AdminBuildingEvent) {
 | 
				
			||||||
			$this->theme->display_page($event->page);
 | 
								$this->theme->display_page($page);
 | 
				
			||||||
			$this->theme->display_form($event->page);
 | 
								$this->theme->display_form($page);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof UserBlockBuildingEvent) {
 | 
							if($event instanceof UserBlockBuildingEvent) {
 | 
				
			||||||
			if($event->user->is_admin()) {
 | 
								if($user->is_admin()) {
 | 
				
			||||||
				$event->add_link("Board Admin", make_link("admin"));
 | 
									$event->add_link("Board Admin", make_link("admin"));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -16,64 +16,62 @@ class AliasEditor implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(($event instanceof PageRequestEvent) && $event->page_matches("alias")) {
 | 
							if(($event instanceof PageRequestEvent) && $event->page_matches("alias")) {
 | 
				
			||||||
			if($event->get_arg(0) == "add") {
 | 
								if($event->get_arg(0) == "add") {
 | 
				
			||||||
				if($event->user->is_admin()) {
 | 
									if($user->is_admin()) {
 | 
				
			||||||
					if(isset($_POST['oldtag']) && isset($_POST['newtag'])) {
 | 
										if(isset($_POST['oldtag']) && isset($_POST['newtag'])) {
 | 
				
			||||||
						try {
 | 
											try {
 | 
				
			||||||
							$aae = new AddAliasEvent($_POST['oldtag'], $_POST['newtag']);
 | 
												$aae = new AddAliasEvent($_POST['oldtag'], $_POST['newtag']);
 | 
				
			||||||
							send_event($aae);
 | 
												send_event($aae);
 | 
				
			||||||
							$event->page->set_mode("redirect");
 | 
												$page->set_mode("redirect");
 | 
				
			||||||
							$event->page->set_redirect(make_link("alias/list"));
 | 
												$page->set_redirect(make_link("alias/list"));
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
						catch(AddAliasException $ex) {
 | 
											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") {
 | 
								else if($event->get_arg(0) == "remove") {
 | 
				
			||||||
				if($event->user->is_admin()) {
 | 
									if($user->is_admin()) {
 | 
				
			||||||
					if(isset($_POST['oldtag'])) {
 | 
										if(isset($_POST['oldtag'])) {
 | 
				
			||||||
						global $database;
 | 
					 | 
				
			||||||
						$database->Execute("DELETE FROM aliases WHERE oldtag=?", array($_POST['oldtag']));
 | 
											$database->Execute("DELETE FROM aliases WHERE oldtag=?", array($_POST['oldtag']));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
						$event->page->set_mode("redirect");
 | 
											$page->set_mode("redirect");
 | 
				
			||||||
						$event->page->set_redirect(make_link("alias/list"));
 | 
											$page->set_redirect(make_link("alias/list"));
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else if($event->get_arg(0) == "list") {
 | 
								else if($event->get_arg(0) == "list") {
 | 
				
			||||||
				global $database;
 | 
									$this->theme->display_aliases($page,
 | 
				
			||||||
				$this->theme->display_aliases($event->page,
 | 
					 | 
				
			||||||
						$database->db->GetAssoc("SELECT oldtag, newtag FROM aliases ORDER BY newtag"),
 | 
											$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") {
 | 
								else if($event->get_arg(0) == "export") {
 | 
				
			||||||
				global $database;
 | 
									$page->set_mode("data");
 | 
				
			||||||
				$event->page->set_mode("data");
 | 
									$page->set_type("text/plain");
 | 
				
			||||||
				$event->page->set_type("text/plain");
 | 
									$page->set_data($this->get_alias_csv($database));
 | 
				
			||||||
				$event->page->set_data($this->get_alias_csv($database));
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else if($event->get_arg(0) == "import") {
 | 
								else if($event->get_arg(0) == "import") {
 | 
				
			||||||
				if($event->user->is_admin()) {
 | 
									if($user->is_admin()) {
 | 
				
			||||||
					print_r($_FILES);
 | 
										print_r($_FILES);
 | 
				
			||||||
					if(count($_FILES) > 0) {
 | 
										if(count($_FILES) > 0) {
 | 
				
			||||||
						global $database;
 | 
											global $database;
 | 
				
			||||||
						$tmp = $_FILES['alias_file']['tmp_name'];
 | 
											$tmp = $_FILES['alias_file']['tmp_name'];
 | 
				
			||||||
						$contents = file_get_contents($tmp);
 | 
											$contents = file_get_contents($tmp);
 | 
				
			||||||
						$this->add_alias_csv($database, $contents);
 | 
											$this->add_alias_csv($database, $contents);
 | 
				
			||||||
						$event->page->set_mode("redirect");
 | 
											$page->set_mode("redirect");
 | 
				
			||||||
						$event->page->set_redirect(make_link("alias/list"));
 | 
											$page->set_redirect(make_link("alias/list"));
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					else {
 | 
										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 {
 | 
									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 instanceof UserBlockBuildingEvent) {
 | 
				
			||||||
			if($event->user->is_admin()) {
 | 
								if($user->is_admin()) {
 | 
				
			||||||
				$event->add_link("Alias Editor", make_link("alias/list"));
 | 
									$event->add_link("Alias Editor", make_link("alias/list"));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,8 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
 | 
					class BBCodeTest extends WebTestCase {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if(!defined(VERSION)) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class BBCodeUnitTest extends UnitTestCase {
 | 
					class BBCodeUnitTest extends UnitTestCase {
 | 
				
			||||||
	public function testBasics() {
 | 
						public function testBasics() {
 | 
				
			||||||
		$this->assertEqual(
 | 
							$this->assertEqual(
 | 
				
			||||||
 | 
				
			|||||||
@ -58,6 +58,8 @@ class CommentList implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
// event handler {{{
 | 
					// event handler {{{
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof InitExtEvent) {
 | 
							if($event instanceof InitExtEvent) {
 | 
				
			||||||
@ -76,32 +78,32 @@ class CommentList implements Extension {
 | 
				
			|||||||
			if($event->get_arg(0) == "add") {
 | 
								if($event->get_arg(0) == "add") {
 | 
				
			||||||
				if(isset($_POST['image_id']) && isset($_POST['comment'])) {
 | 
									if(isset($_POST['image_id']) && isset($_POST['comment'])) {
 | 
				
			||||||
					try {
 | 
										try {
 | 
				
			||||||
						$cpe = new CommentPostingEvent($_POST['image_id'], $event->user, $_POST['comment']);
 | 
											$cpe = new CommentPostingEvent($_POST['image_id'], $user, $_POST['comment']);
 | 
				
			||||||
						send_event($cpe);
 | 
											send_event($cpe);
 | 
				
			||||||
						$event->page->set_mode("redirect");
 | 
											$page->set_mode("redirect");
 | 
				
			||||||
						$event->page->set_redirect(make_link("post/view/".int_escape($_POST['image_id'])));
 | 
											$page->set_redirect(make_link("post/view/".int_escape($_POST['image_id'])));
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					catch(CommentPostingException $ex) {
 | 
										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") {
 | 
								else if($event->get_arg(0) == "delete") {
 | 
				
			||||||
				if($event->user->is_admin()) {
 | 
									if($user->is_admin()) {
 | 
				
			||||||
					// FIXME: post, not args
 | 
										// FIXME: post, not args
 | 
				
			||||||
					if($event->count_args() == 3) {
 | 
										if($event->count_args() == 3) {
 | 
				
			||||||
						send_event(new CommentDeletionEvent($event->get_arg(1)));
 | 
											send_event(new CommentDeletionEvent($event->get_arg(1)));
 | 
				
			||||||
						$event->page->set_mode("redirect");
 | 
											$page->set_mode("redirect");
 | 
				
			||||||
						if(!empty($_SERVER['HTTP_REFERER'])) {
 | 
											if(!empty($_SERVER['HTTP_REFERER'])) {
 | 
				
			||||||
							$event->page->set_redirect($_SERVER['HTTP_REFERER']);
 | 
												$page->set_redirect($_SERVER['HTTP_REFERER']);
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
						else {
 | 
											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 {
 | 
									else {
 | 
				
			||||||
					$this->theme->display_permission_denied($event->page);
 | 
										$this->theme->display_permission_denied($page);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else if($event->get_arg(0) == "list") {
 | 
								else if($event->get_arg(0) == "list") {
 | 
				
			||||||
@ -110,19 +112,18 @@ class CommentList implements Extension {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof PostListBuildingEvent) {
 | 
							if($event instanceof PostListBuildingEvent) {
 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
			$cc = $config->get_int("comment_count");
 | 
								$cc = $config->get_int("comment_count");
 | 
				
			||||||
			if($cc > 0) {
 | 
								if($cc > 0) {
 | 
				
			||||||
				$recent = $this->get_recent_comments($cc);
 | 
									$recent = $this->get_recent_comments($cc);
 | 
				
			||||||
				if(count($recent) > 0) {
 | 
									if(count($recent) > 0) {
 | 
				
			||||||
					$this->theme->display_recent_comments($event->page, $recent);
 | 
										$this->theme->display_recent_comments($page, $recent);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof DisplayingImageEvent) {
 | 
							if($event instanceof DisplayingImageEvent) {
 | 
				
			||||||
			$this->theme->display_comments(
 | 
								$this->theme->display_comments(
 | 
				
			||||||
					$event->page,
 | 
										$page,
 | 
				
			||||||
					$this->get_comments($event->image->id),
 | 
										$this->get_comments($event->image->id),
 | 
				
			||||||
					$this->can_comment(),
 | 
										$this->can_comment(),
 | 
				
			||||||
					$event->image->id);
 | 
										$event->image->id);
 | 
				
			||||||
@ -228,7 +229,7 @@ class CommentList implements Extension {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		$n = 10;
 | 
							$n = 10;
 | 
				
			||||||
		while(!$result->EOF) {
 | 
							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);
 | 
								$comments = $this->get_comments($image->id);
 | 
				
			||||||
			$this->theme->add_comment_list($page, $image, $comments, $n, $this->can_comment());
 | 
								$this->theme->add_comment_list($page, $image, $comments, $n, $this->can_comment());
 | 
				
			||||||
			$n += 1;
 | 
								$n += 1;
 | 
				
			||||||
@ -361,7 +362,7 @@ class CommentList implements Extension {
 | 
				
			|||||||
		if(!$config->get_bool('comment_anon') && $user->is_anonymous()) {
 | 
							if(!$config->get_bool('comment_anon') && $user->is_anonymous()) {
 | 
				
			||||||
			throw new CommentPostingException("Anonymous posting has been disabled");
 | 
								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");
 | 
								throw new CommentPostingException("The image does not exist");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		else if(trim($comment) == "") {
 | 
							else if(trim($comment) == "") {
 | 
				
			||||||
 | 
				
			|||||||
@ -72,38 +72,39 @@ class ExtManager implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(($event instanceof PageRequestEvent) && $event->page_matches("ext_manager")) {
 | 
							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($event->get_arg(0) == "set") {
 | 
				
			||||||
					if(is_writable("ext")) {
 | 
										if(is_writable("ext")) {
 | 
				
			||||||
						$this->set_things($_POST);
 | 
											$this->set_things($_POST);
 | 
				
			||||||
						$event->page->set_mode("redirect");
 | 
											$page->set_mode("redirect");
 | 
				
			||||||
						$event->page->set_redirect(make_link("ext_manager"));
 | 
											$page->set_redirect(make_link("ext_manager"));
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					else {
 | 
										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 :(");
 | 
												"The extension folder isn't writable by the web server :(");
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				else {
 | 
									else {
 | 
				
			||||||
					$this->theme->display_table($event->page, $this->get_extensions());
 | 
										$this->theme->display_table($page, $this->get_extensions());
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else {
 | 
								else {
 | 
				
			||||||
				$this->theme->display_permission_denied($event->page);
 | 
									$this->theme->display_permission_denied($page);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(($event instanceof PageRequestEvent) && $event->page_matches("ext_doc")) {
 | 
							if(($event instanceof PageRequestEvent) && $event->page_matches("ext_doc")) {
 | 
				
			||||||
			$ext = $event->get_arg(0);
 | 
								$ext = $event->get_arg(0);
 | 
				
			||||||
			$info = new ExtensionInfo("contrib/$ext/main.php");
 | 
								$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 instanceof UserBlockBuildingEvent) {
 | 
				
			||||||
			if($event->user->is_admin()) {
 | 
								if($user->is_admin()) {
 | 
				
			||||||
				$event->add_link("Extension Manager", make_link("ext_manager"));
 | 
									$event->add_link("Extension Manager", make_link("ext_manager"));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -3,7 +3,7 @@
 | 
				
			|||||||
class Handle404 implements Extension {
 | 
					class Handle404 implements Extension {
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
		if($event instanceof PageRequestEvent) {
 | 
							if($event instanceof PageRequestEvent) {
 | 
				
			||||||
			$page = $event->page;
 | 
								global $page;
 | 
				
			||||||
			// hax.
 | 
								// hax.
 | 
				
			||||||
			if($page->mode == "page" && (!isset($page->blocks) || $this->count_main($page->blocks) == 0)) {
 | 
								if($page->mode == "page" && (!isset($page->blocks) || $this->count_main($page->blocks) == 0)) {
 | 
				
			||||||
				$h_pagename = html_escape(implode('/', $event->args));
 | 
									$h_pagename = html_escape(implode('/', $event->args));
 | 
				
			||||||
 | 
				
			|||||||
@ -9,6 +9,7 @@ class PixelFileHandler implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $page;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(($event instanceof DataUploadEvent) && $this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
 | 
							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)) {
 | 
							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);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -168,7 +168,7 @@ class ImageIO implements Extension {
 | 
				
			|||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * Check for an existing image
 | 
							 * Check for an existing image
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		$existing = Image::by_hash($config, $database, $image->hash);
 | 
							$existing = Image::by_hash($image->hash);
 | 
				
			||||||
		if(!is_null($existing)) {
 | 
							if(!is_null($existing)) {
 | 
				
			||||||
			$handler = $config->get_string("upload_collision_handler");
 | 
								$handler = $config->get_string("upload_collision_handler");
 | 
				
			||||||
			if($handler == "merge") {
 | 
								if($handler == "merge") {
 | 
				
			||||||
@ -204,7 +204,7 @@ class ImageIO implements Extension {
 | 
				
			|||||||
	private function send_file($image_id, $type) {
 | 
						private function send_file($image_id, $type) {
 | 
				
			||||||
		global $config;
 | 
							global $config;
 | 
				
			||||||
		global $database;
 | 
							global $database;
 | 
				
			||||||
		$image = Image::by_id($config, $database, $image_id);
 | 
							$image = Image::by_id($image_id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		global $page;
 | 
							global $page;
 | 
				
			||||||
		if(!is_null($image)) {
 | 
							if(!is_null($image)) {
 | 
				
			||||||
 | 
				
			|||||||
@ -27,12 +27,9 @@ class SearchTermParseEvent extends Event {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PostListBuildingEvent extends Event {
 | 
					class PostListBuildingEvent extends Event {
 | 
				
			||||||
	var $page = null;
 | 
					 | 
				
			||||||
	var $search_terms = null;
 | 
						var $search_terms = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function __construct(RequestContext $context, $search) {
 | 
						public function __construct($search) {
 | 
				
			||||||
		parent::__construct($context);
 | 
					 | 
				
			||||||
		$this->page = $context->page;
 | 
					 | 
				
			||||||
		$this->search_terms = $search;
 | 
							$this->search_terms = $search;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -41,10 +38,10 @@ class Index implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof InitExtEvent) {
 | 
							if($event instanceof InitExtEvent) {
 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
			$config->set_default_int("index_width", 3);
 | 
								$config->set_default_int("index_width", 3);
 | 
				
			||||||
			$config->set_default_int("index_height", 4);
 | 
								$config->set_default_int("index_height", 4);
 | 
				
			||||||
			$config->set_default_bool("index_tips", true);
 | 
								$config->set_default_bool("index_tips", true);
 | 
				
			||||||
@ -54,12 +51,12 @@ class Index implements Extension {
 | 
				
			|||||||
			if(isset($_GET['search'])) {
 | 
								if(isset($_GET['search'])) {
 | 
				
			||||||
				$search = url_escape(trim($_GET['search']));
 | 
									$search = url_escape(trim($_GET['search']));
 | 
				
			||||||
				if(empty($search)) {
 | 
									if(empty($search)) {
 | 
				
			||||||
					$event->page->set_mode("redirect");
 | 
										$page->set_mode("redirect");
 | 
				
			||||||
					$event->page->set_redirect(make_link("post/list/1"));
 | 
										$page->set_redirect(make_link("post/list/1"));
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				else {
 | 
									else {
 | 
				
			||||||
					$event->page->set_mode("redirect");
 | 
										$page->set_mode("redirect");
 | 
				
			||||||
					$event->page->set_redirect(make_link("post/list/$search/1"));
 | 
										$page->set_redirect(make_link("post/list/$search/1"));
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@ -77,25 +74,22 @@ class Index implements Extension {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
			if($page_number == 0) $page_number = 1; // invalid -> 0
 | 
								if($page_number == 0) $page_number = 1; // invalid -> 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			global $config;
 | 
								$total_pages = Image::count_pages($search_terms);
 | 
				
			||||||
			global $database;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			$total_pages = Image::count_pages($config, $database, $search_terms);
 | 
					 | 
				
			||||||
			$count = $config->get_int('index_width') * $config->get_int('index_height');
 | 
								$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) {
 | 
								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) {
 | 
								else if(count($search_terms) > 0 && count($images) == 1) {
 | 
				
			||||||
				$event->page->set_mode("redirect");
 | 
									$page->set_mode("redirect");
 | 
				
			||||||
				$event->page->set_redirect(make_link("post/view/{$images[0]->id}"));
 | 
									$page->set_redirect(make_link("post/view/{$images[0]->id}"));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else {
 | 
								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->set_page($page_number, $total_pages, $search_terms);
 | 
				
			||||||
				$this->theme->display_page($event->page, $images);
 | 
									$this->theme->display_page($page, $images);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -139,10 +139,10 @@ class Setup implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof InitExtEvent) {
 | 
							if($event instanceof InitExtEvent) {
 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
			$config->set_default_string("title", "Shimmie");
 | 
								$config->set_default_string("title", "Shimmie");
 | 
				
			||||||
			$config->set_default_string("front_page", "post/list");
 | 
								$config->set_default_string("front_page", "post/list");
 | 
				
			||||||
			$config->set_default_string("main_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")) {
 | 
							if(($event instanceof PageRequestEvent) && $event->page_matches("nicetest")) {
 | 
				
			||||||
			$event->page->set_mode("data");
 | 
								$page->set_mode("data");
 | 
				
			||||||
			$event->page->set_data("ok");
 | 
								$page->set_data("ok");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(($event instanceof PageRequestEvent) && $event->page_matches("setup")) {
 | 
							if(($event instanceof PageRequestEvent) && $event->page_matches("setup")) {
 | 
				
			||||||
			global $user;
 | 
					 | 
				
			||||||
			if(!$user->is_admin()) {
 | 
								if(!$user->is_admin()) {
 | 
				
			||||||
				$this->theme->display_permission_denied($event->page);
 | 
									$this->theme->display_permission_denied($page);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else {
 | 
								else {
 | 
				
			||||||
				if($event->get_arg(0) == "save") {
 | 
									if($event->get_arg(0) == "save") {
 | 
				
			||||||
					global $config;
 | 
					 | 
				
			||||||
					send_event(new ConfigSaveEvent($config));
 | 
										send_event(new ConfigSaveEvent($config));
 | 
				
			||||||
					$config->save();
 | 
										$config->save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					global $page;
 | 
					 | 
				
			||||||
					$page->set_mode("redirect");
 | 
										$page->set_mode("redirect");
 | 
				
			||||||
					$page->set_redirect(make_link("setup"));
 | 
										$page->set_redirect(make_link("setup"));
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				else if($event->get_arg(0) == "advanced") {
 | 
									else if($event->get_arg(0) == "advanced") {
 | 
				
			||||||
					global $config;
 | 
										$this->theme->display_advanced($page, $config->values);
 | 
				
			||||||
					$this->theme->display_advanced($event->page, $config->values);
 | 
					 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				else {
 | 
									else {
 | 
				
			||||||
					$panel = new SetupPanel();
 | 
										$panel = new SetupPanel();
 | 
				
			||||||
					send_event(new SetupBuildingEvent($panel));
 | 
										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) {
 | 
							if($event instanceof ConfigSaveEvent) {
 | 
				
			||||||
 | 
								global $config;
 | 
				
			||||||
			foreach($_POST as $_name => $junk) {
 | 
								foreach($_POST as $_name => $junk) {
 | 
				
			||||||
				if(substr($_name, 0, 6) == "_type_") {
 | 
									if(substr($_name, 0, 6) == "_type_") {
 | 
				
			||||||
					$name = substr($_name, 6);
 | 
										$name = substr($_name, 6);
 | 
				
			||||||
					$type = $_POST["_type_$name"];
 | 
										$type = $_POST["_type_$name"];
 | 
				
			||||||
					$value = isset($_POST["_config_$name"]) ? $_POST["_config_$name"] : null;
 | 
										$value = isset($_POST["_config_$name"]) ? $_POST["_config_$name"] : null;
 | 
				
			||||||
					switch($type) {
 | 
										switch($type) {
 | 
				
			||||||
						case "string": $event->config->set_string($name, $value); break;
 | 
											case "string": $config->set_string($name, $value); break;
 | 
				
			||||||
						case "int":    $event->config->set_int($name, $value);    break;
 | 
											case "int":    $config->set_int($name, $value);    break;
 | 
				
			||||||
						case "bool":   $event->config->set_bool($name, $value);   break;
 | 
											case "bool":   $config->set_bool($name, $value);   break;
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof UserBlockBuildingEvent) {
 | 
							if($event instanceof UserBlockBuildingEvent) {
 | 
				
			||||||
			if($event->user->is_admin()) {
 | 
								if($user->is_admin()) {
 | 
				
			||||||
				$event->add_link("Board Config", make_link("setup"));
 | 
									$event->add_link("Board Config", make_link("setup"));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -36,16 +36,14 @@ class TagEdit implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(($event instanceof PageRequestEvent) && $event->page_matches("tag_edit")) {
 | 
							if(($event instanceof PageRequestEvent) && $event->page_matches("tag_edit")) {
 | 
				
			||||||
			global $page;
 | 
					 | 
				
			||||||
			if($event->get_arg(0) == "replace") {
 | 
								if($event->get_arg(0) == "replace") {
 | 
				
			||||||
				global $user;
 | 
					 | 
				
			||||||
				if($user->is_admin() && isset($_POST['search']) && isset($_POST['replace'])) {
 | 
									if($user->is_admin() && isset($_POST['search']) && isset($_POST['replace'])) {
 | 
				
			||||||
					$search = $_POST['search'];
 | 
										$search = $_POST['search'];
 | 
				
			||||||
					$replace = $_POST['replace'];
 | 
										$replace = $_POST['replace'];
 | 
				
			||||||
					global $page;
 | 
					 | 
				
			||||||
					$this->mass_tag_edit($search, $replace);
 | 
										$this->mass_tag_edit($search, $replace);
 | 
				
			||||||
					$page->set_mode("redirect");
 | 
										$page->set_mode("redirect");
 | 
				
			||||||
					$page->set_redirect(make_link("admin"));
 | 
										$page->set_redirect(make_link("admin"));
 | 
				
			||||||
@ -61,7 +59,7 @@ class TagEdit implements Extension {
 | 
				
			|||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else {
 | 
								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) {
 | 
							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
 | 
							// When an alias is added, oldtag becomes inaccessable
 | 
				
			||||||
@ -87,8 +85,6 @@ class TagEdit implements Extension {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof ImageInfoBoxBuildingEvent) {
 | 
							if($event instanceof ImageInfoBoxBuildingEvent) {
 | 
				
			||||||
			global $user;
 | 
					 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
			if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) {
 | 
								if($config->get_bool("tag_edit_anon") || !$user->is_anonymous()) {
 | 
				
			||||||
				$event->add_part($this->theme->get_tag_editor_html($event->image), 40);
 | 
									$event->add_part($this->theme->get_tag_editor_html($event->image), 40);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@ -130,7 +126,7 @@ class TagEdit implements Extension {
 | 
				
			|||||||
			$search_forward = $search_set;
 | 
								$search_forward = $search_set;
 | 
				
			||||||
			if($last_id >= 0) $search_forward[] = "id<$last_id";
 | 
								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;
 | 
								if(count($images) == 0) break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			foreach($images as $image) {
 | 
								foreach($images as $image) {
 | 
				
			||||||
 | 
				
			|||||||
@ -5,10 +5,10 @@ class TagList implements Extension {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// event handling {{{
 | 
					// event handling {{{
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if($this->theme == null) $this->theme = get_theme_object($this);
 | 
							if($this->theme == null) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof InitExtEvent) {
 | 
							if($event instanceof InitExtEvent) {
 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
			$config->set_default_int("tag_list_length", 15);
 | 
								$config->set_default_int("tag_list_length", 15);
 | 
				
			||||||
			$config->set_default_int("tags_min", 3);
 | 
								$config->set_default_int("tags_min", 3);
 | 
				
			||||||
			$config->set_default_string("info_link", 'http://en.wikipedia.org/wiki/$tag');
 | 
								$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")) {
 | 
							if(($event instanceof PageRequestEvent) && $event->page_matches("tags")) {
 | 
				
			||||||
			global $page;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			$this->theme->set_navigation($this->build_navigation());
 | 
								$this->theme->set_navigation($this->build_navigation());
 | 
				
			||||||
			switch($event->get_arg(0)) {
 | 
								switch($event->get_arg(0)) {
 | 
				
			||||||
				default:
 | 
									default:
 | 
				
			||||||
@ -42,25 +40,23 @@ class TagList implements Extension {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof PostListBuildingEvent) {
 | 
							if($event instanceof PostListBuildingEvent) {
 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
			if($config->get_int('tag_list_length') > 0) {
 | 
								if($config->get_int('tag_list_length') > 0) {
 | 
				
			||||||
				if(!empty($event->search_terms)) {
 | 
									if(!empty($event->search_terms)) {
 | 
				
			||||||
					$this->add_refine_block($event->page, $event->search_terms);
 | 
										$this->add_refine_block($page, $event->search_terms);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				else {
 | 
									else {
 | 
				
			||||||
					$this->add_popular_block($event->page);
 | 
										$this->add_popular_block($page);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof DisplayingImageEvent) {
 | 
							if($event instanceof DisplayingImageEvent) {
 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
			if($config->get_int('tag_list_length') > 0) {
 | 
								if($config->get_int('tag_list_length') > 0) {
 | 
				
			||||||
				if($config->get_string('tag_list_image_type') == 'related') {
 | 
									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 {
 | 
									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>";
 | 
								if($n%3==0) $html .= "<tr>";
 | 
				
			||||||
			$h_tag = html_escape($row['tag']);
 | 
								$h_tag = html_escape($row['tag']);
 | 
				
			||||||
			$link = $this->tag_link($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
 | 
								if(is_null($image)) continue; // one of the popular tags has no images
 | 
				
			||||||
			$thumb = $image->get_thumb_link();
 | 
								$thumb = $image->get_thumb_link();
 | 
				
			||||||
			$html .= "<td><a href='$link'><img src='$thumb'><br>$h_tag</a></td>\n";
 | 
								$html .= "<td><a href='$link'><img src='$thumb'><br>$h_tag</a></td>\n";
 | 
				
			||||||
 | 
				
			|||||||
@ -3,13 +3,12 @@
 | 
				
			|||||||
class Upgrade implements Extension {
 | 
					class Upgrade implements Extension {
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
		if($event instanceof InitExtEvent) {
 | 
							if($event instanceof InitExtEvent) {
 | 
				
			||||||
			$this->do_things($event->context);
 | 
								$this->do_things();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	private function do_things($context) {
 | 
						private function do_things() {
 | 
				
			||||||
		$config = $context->config;
 | 
							global $config, $database;
 | 
				
			||||||
		$database = $context->database;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(!is_numeric($config->get_string("db_version"))) {
 | 
							if(!is_numeric($config->get_string("db_version"))) {
 | 
				
			||||||
			$config->set_int("db_version", 2);
 | 
								$config->set_int("db_version", 2);
 | 
				
			||||||
 | 
				
			|||||||
@ -30,6 +30,7 @@ class Upload implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
// event handling {{{
 | 
					// event handling {{{
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$is_full = (disk_free_space(realpath("./images/")) < 100*1024*1024);
 | 
							$is_full = (disk_free_space(realpath("./images/")) < 100*1024*1024);
 | 
				
			||||||
@ -45,10 +46,10 @@ class Upload implements Extension {
 | 
				
			|||||||
			global $user;
 | 
								global $user;
 | 
				
			||||||
			if($this->can_upload($user)) {
 | 
								if($this->can_upload($user)) {
 | 
				
			||||||
				if($is_full) {
 | 
									if($is_full) {
 | 
				
			||||||
					$this->theme->display_full($event->page);
 | 
										$this->theme->display_full($page);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				else {
 | 
									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) {
 | 
								if(count($_FILES) + count($_POST) > 0) {
 | 
				
			||||||
				$tags = Tag::explode($_POST['tags']);
 | 
									$tags = Tag::explode($_POST['tags']);
 | 
				
			||||||
				$source = isset($_POST['source']) ? $_POST['source'] : null;
 | 
									$source = isset($_POST['source']) ? $_POST['source'] : null;
 | 
				
			||||||
				global $user;
 | 
					 | 
				
			||||||
				if($this->can_upload($user)) {
 | 
									if($this->can_upload($user)) {
 | 
				
			||||||
					$ok = true;
 | 
										$ok = true;
 | 
				
			||||||
					foreach($_FILES as $file) {
 | 
										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 {
 | 
									else {
 | 
				
			||||||
					$this->theme->display_permission_denied($event->page);
 | 
										$this->theme->display_permission_denied($page);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else if(!empty($_GET['url'])) {
 | 
								else if(!empty($_GET['url'])) {
 | 
				
			||||||
@ -84,15 +84,15 @@ class Upload implements Extension {
 | 
				
			|||||||
						$tags = Tag::explode($_GET['tags']);
 | 
											$tags = Tag::explode($_GET['tags']);
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
					$ok = $this->try_transload($url, $tags, $url);
 | 
										$ok = $this->try_transload($url, $tags, $url);
 | 
				
			||||||
					$this->theme->display_upload_status($event->page, $ok);
 | 
										$this->theme->display_upload_status($page, $ok);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				else {
 | 
									else {
 | 
				
			||||||
					$this->theme->display_permission_denied($event->page);
 | 
										$this->theme->display_permission_denied($page);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else {
 | 
								else {
 | 
				
			||||||
				if(!$is_full) {
 | 
									if(!$is_full) {
 | 
				
			||||||
					$this->theme->display_page($event->page);
 | 
										$this->theme->display_page($page);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
				
			|||||||
@ -2,12 +2,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class UserBlockBuildingEvent extends Event {
 | 
					class UserBlockBuildingEvent extends Event {
 | 
				
			||||||
	var $parts = array();
 | 
						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) {
 | 
						public function add_link($name, $link, $position=50) {
 | 
				
			||||||
		while(isset($this->parts[$position])) $position++;
 | 
							while(isset($this->parts[$position])) $position++;
 | 
				
			||||||
@ -18,8 +12,7 @@ class UserBlockBuildingEvent extends Event {
 | 
				
			|||||||
class UserPageBuildingEvent extends Event {
 | 
					class UserPageBuildingEvent extends Event {
 | 
				
			||||||
	var $display_user;
 | 
						var $display_user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function __construct(RequestContext $context, User $display_user) {
 | 
						public function __construct(User $display_user) {
 | 
				
			||||||
		parent::__construct($context);
 | 
					 | 
				
			||||||
		$this->display_user = $display_user;
 | 
							$this->display_user = $display_user;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -29,8 +22,7 @@ class UserCreationEvent extends Event {
 | 
				
			|||||||
	var $password;
 | 
						var $password;
 | 
				
			||||||
	var $email;
 | 
						var $email;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function __construct(RequestContext $context, $name, $pass, $email) {
 | 
						public function __construct($name, $pass, $email) {
 | 
				
			||||||
		parent::__construct($context);
 | 
					 | 
				
			||||||
		$this->username = $name;
 | 
							$this->username = $name;
 | 
				
			||||||
		$this->password = $pass;
 | 
							$this->password = $pass;
 | 
				
			||||||
		$this->email = $email;
 | 
							$this->email = $email;
 | 
				
			||||||
@ -44,19 +36,16 @@ class UserPage implements Extension {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// event handling {{{
 | 
					// event handling {{{
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof InitExtEvent) {
 | 
							if($event instanceof InitExtEvent) {
 | 
				
			||||||
			$event->context->config->set_default_bool("login_signup_enabled", true);
 | 
								$config->set_default_bool("login_signup_enabled", true);
 | 
				
			||||||
			$event->context->config->set_default_int("login_memory", 365);
 | 
								$config->set_default_int("login_memory", 365);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(($event instanceof PageRequestEvent) && $event->page_matches("user_admin")) {
 | 
							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($event->get_arg(0) == "login") {
 | 
				
			||||||
				if(isset($_POST['user']) && isset($_POST['pass'])) {
 | 
									if(isset($_POST['user']) && isset($_POST['pass'])) {
 | 
				
			||||||
					$this->login($page);
 | 
										$this->login($page);
 | 
				
			||||||
@ -86,7 +75,7 @@ class UserPage implements Extension {
 | 
				
			|||||||
				}
 | 
									}
 | 
				
			||||||
				else {
 | 
									else {
 | 
				
			||||||
					try {
 | 
										try {
 | 
				
			||||||
						$uce = new UserCreationEvent($event->context, $_POST['name'], $_POST['pass1'], $_POST['email']);
 | 
											$uce = new UserCreationEvent($_POST['name'], $_POST['pass1'], $_POST['email']);
 | 
				
			||||||
						send_event($uce);
 | 
											send_event($uce);
 | 
				
			||||||
						$this->set_login_cookie($uce->username, $uce->password);
 | 
											$this->set_login_cookie($uce->username, $uce->password);
 | 
				
			||||||
						$page->set_mode("redirect");
 | 
											$page->set_mode("redirect");
 | 
				
			||||||
@ -102,14 +91,9 @@ class UserPage implements Extension {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if(($event instanceof PageRequestEvent) && $event->page_matches("user")) {
 | 
							if(($event instanceof PageRequestEvent) && $event->page_matches("user")) {
 | 
				
			||||||
			$user = $event->context->user;
 | 
								$display_user = ($event->count_args() == 0) ? $user : User::by_name($event->get_arg(0));
 | 
				
			||||||
			$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));
 | 
					 | 
				
			||||||
			if(!is_null($display_user)) {
 | 
								if(!is_null($display_user)) {
 | 
				
			||||||
				send_event(new UserPageBuildingEvent($event->context, $display_user));
 | 
									send_event(new UserPageBuildingEvent($display_user));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else {
 | 
								else {
 | 
				
			||||||
				$this->theme->display_error($page, "No Such User",
 | 
									$this->theme->display_error($page, "No Such User",
 | 
				
			||||||
@ -119,31 +103,25 @@ class UserPage implements Extension {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof UserPageBuildingEvent) {
 | 
							if($event instanceof UserPageBuildingEvent) {
 | 
				
			||||||
			global $user;
 | 
								$this->theme->display_user_page($page, $event->display_user, $user);
 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
			$this->theme->display_user_page($event->context->page, $event->display_user, $user);
 | 
					 | 
				
			||||||
			if($user->id == $event->display_user->id) {
 | 
								if($user->id == $event->display_user->id) {
 | 
				
			||||||
				$ubbe = new UserBlockBuildingEvent($event->context);
 | 
									$ubbe = new UserBlockBuildingEvent();
 | 
				
			||||||
				send_event($ubbe);
 | 
									send_event($ubbe);
 | 
				
			||||||
				ksort($ubbe->parts);
 | 
									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'))) {
 | 
								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
 | 
							// user info is shown on all pages
 | 
				
			||||||
		if($event instanceof PageRequestEvent) {
 | 
							if($event instanceof PageRequestEvent) {
 | 
				
			||||||
			$user = $event->context->user;
 | 
					 | 
				
			||||||
			$database = $event->context->database;
 | 
					 | 
				
			||||||
			$page = $event->context->page;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
			if($user->is_anonymous()) {
 | 
								if($user->is_anonymous()) {
 | 
				
			||||||
				$this->theme->display_login_block($page);
 | 
									$this->theme->display_login_block($page);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else {
 | 
								else {
 | 
				
			||||||
				$ubbe = new UserBlockBuildingEvent($event->context);
 | 
									$ubbe = new UserBlockBuildingEvent();
 | 
				
			||||||
				send_event($ubbe);
 | 
									send_event($ubbe);
 | 
				
			||||||
				ksort($ubbe->parts);
 | 
									ksort($ubbe->parts);
 | 
				
			||||||
				$this->theme->display_user_block($page, $user, $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)) {
 | 
								if(preg_match("/^(poster|user)=(.*)$/i", $event->term, $matches)) {
 | 
				
			||||||
				global $config;
 | 
									global $config;
 | 
				
			||||||
				global $database;
 | 
									global $database;
 | 
				
			||||||
				$user = User::by_name($config, $database, $matches[2]);
 | 
									$user = User::by_name($matches[2]);
 | 
				
			||||||
				if(!is_null($user)) {
 | 
									if(!is_null($user)) {
 | 
				
			||||||
					$user_id = $user->id;
 | 
										$user_id = $user->id;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
@ -190,15 +168,13 @@ class UserPage implements Extension {
 | 
				
			|||||||
// }}}
 | 
					// }}}
 | 
				
			||||||
// Things done *with* the user {{{
 | 
					// Things done *with* the user {{{
 | 
				
			||||||
	private function login($page)  {
 | 
						private function login($page)  {
 | 
				
			||||||
		global $database;
 | 
					 | 
				
			||||||
		global $config;
 | 
					 | 
				
			||||||
		global $user;
 | 
							global $user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$name = $_POST['user'];
 | 
							$name = $_POST['user'];
 | 
				
			||||||
		$pass = $_POST['pass'];
 | 
							$pass = $_POST['pass'];
 | 
				
			||||||
		$hash = md5(strtolower($name) . $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)) {
 | 
							if(!is_null($duser)) {
 | 
				
			||||||
			$user = $duser;
 | 
								$user = $duser;
 | 
				
			||||||
			$this->set_login_cookie($name, $pass);
 | 
								$this->set_login_cookie($name, $pass);
 | 
				
			||||||
@ -279,7 +255,7 @@ class UserPage implements Extension {
 | 
				
			|||||||
			$pass1 = $_POST['pass1'];
 | 
								$pass1 = $_POST['pass1'];
 | 
				
			||||||
			$pass2 = $_POST['pass2'];
 | 
								$pass2 = $_POST['pass2'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$duser = User::by_id($config, $database, $id);
 | 
								$duser = User::by_id($id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if((!$user->is_admin()) && ($duser->name != $user->name)) {
 | 
								if((!$user->is_admin()) && ($duser->name != $user->name)) {
 | 
				
			||||||
				$page->add_block(new Block("Error",
 | 
									$page->add_block(new Block("Error",
 | 
				
			||||||
@ -325,7 +301,7 @@ class UserPage implements Extension {
 | 
				
			|||||||
		else {
 | 
							else {
 | 
				
			||||||
			$admin = (isset($_POST['admin']) && ($_POST['admin'] == "on"));
 | 
								$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);
 | 
								$duser->set_admin($admin);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$page->set_mode("redirect");
 | 
								$page->set_mode("redirect");
 | 
				
			||||||
 | 
				
			|||||||
@ -123,7 +123,7 @@ class UserPageTheme extends Themelet {
 | 
				
			|||||||
		global $config;
 | 
							global $config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$h_join_date = html_escape($duser->join_date);
 | 
							$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);
 | 
							$i_comment_count = Comment::count_comments_by_user($duser);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		#$h_image_rate = sprintf("%3.1f", ($i_image_count / $i_days_old2));
 | 
							#$h_image_rate = sprintf("%3.1f", ($i_image_count / $i_days_old2));
 | 
				
			||||||
 | 
				
			|||||||
@ -11,10 +11,8 @@
 | 
				
			|||||||
class DisplayingImageEvent extends Event {
 | 
					class DisplayingImageEvent extends Event {
 | 
				
			||||||
	var $image, $page, $context;
 | 
						var $image, $page, $context;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function __construct(RequestContext $context, Image $image) {
 | 
						public function __construct(Image $image) {
 | 
				
			||||||
		parent::__construct($context);
 | 
					 | 
				
			||||||
		$this->image = $image;
 | 
							$this->image = $image;
 | 
				
			||||||
		$this->page = $context->page;
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function get_image() {
 | 
						public function get_image() {
 | 
				
			||||||
@ -65,14 +63,13 @@ class ViewImage implements Extension {
 | 
				
			|||||||
	var $theme;
 | 
						var $theme;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function receive_event(Event $event) {
 | 
						public function receive_event(Event $event) {
 | 
				
			||||||
 | 
							global $config, $database, $page, $user;
 | 
				
			||||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
							if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(is_a($event, 'PageRequestEvent') && (
 | 
							if(is_a($event, 'PageRequestEvent') && (
 | 
				
			||||||
			$event->page_matches("post/prev") ||
 | 
								$event->page_matches("post/prev") ||
 | 
				
			||||||
			$event->page_matches("post/next")
 | 
								$event->page_matches("post/next")
 | 
				
			||||||
		)) {
 | 
							)) {
 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
			global $database;
 | 
					 | 
				
			||||||
			$image_id = int_escape($event->get_arg(0));
 | 
								$image_id = int_escape($event->get_arg(0));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if(isset($_GET['search'])) {
 | 
								if(isset($_GET['search'])) {
 | 
				
			||||||
@ -84,7 +81,7 @@ class ViewImage implements Extension {
 | 
				
			|||||||
				$query = null;
 | 
									$query = null;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$image = Image::by_id($config, $database, $image_id);
 | 
								$image = Image::by_id($image_id);
 | 
				
			||||||
			if($event->page_matches("post/next")) {
 | 
								if($event->page_matches("post/next")) {
 | 
				
			||||||
				$image = $image->get_next($search_terms);
 | 
									$image = $image->get_next($search_terms);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@ -93,50 +90,46 @@ class ViewImage implements Extension {
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if(!is_null($image)) {
 | 
								if(!is_null($image)) {
 | 
				
			||||||
				$event->page->set_mode("redirect");
 | 
									$page->set_mode("redirect");
 | 
				
			||||||
				$event->page->set_redirect(make_link("post/view/{$image->id}", $query));
 | 
									$page->set_redirect(make_link("post/view/{$image->id}", $query));
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else {
 | 
								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")) {
 | 
							if(($event instanceof PageRequestEvent) && $event->page_matches("post/view")) {
 | 
				
			||||||
			$image_id = int_escape($event->get_arg(0));
 | 
								$image_id = int_escape($event->get_arg(0));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			global $database;
 | 
								$image = Image::by_id($image_id);
 | 
				
			||||||
			global $config;
 | 
					 | 
				
			||||||
			$image = Image::by_id($config, $database, $image_id);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if(!is_null($image)) {
 | 
								if(!is_null($image)) {
 | 
				
			||||||
				send_event(new DisplayingImageEvent($event->context, $image));
 | 
									send_event(new DisplayingImageEvent($image));
 | 
				
			||||||
				$iabbe = new ImageAdminBlockBuildingEvent($image, $event->user);
 | 
									$iabbe = new ImageAdminBlockBuildingEvent($image, $user);
 | 
				
			||||||
				send_event($iabbe);
 | 
									send_event($iabbe);
 | 
				
			||||||
				ksort($iabbe->parts);
 | 
									ksort($iabbe->parts);
 | 
				
			||||||
				$this->theme->display_admin_block($event->page, $iabbe->parts);
 | 
									$this->theme->display_admin_block($page, $iabbe->parts);
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else {
 | 
								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")) {
 | 
							if(($event instanceof PageRequestEvent) && $event->page_matches("post/set")) {
 | 
				
			||||||
			global $config, $database;
 | 
					 | 
				
			||||||
			$image_id = int_escape($_POST['image_id']);
 | 
								$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'];
 | 
								$query = $_POST['query'];
 | 
				
			||||||
			$event->page->set_mode("redirect");
 | 
								$page->set_mode("redirect");
 | 
				
			||||||
			$event->page->set_redirect(make_link("post/view/$image_id", $query));
 | 
								$page->set_redirect(make_link("post/view/$image_id", $query));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if($event instanceof DisplayingImageEvent) {
 | 
							if($event instanceof DisplayingImageEvent) {
 | 
				
			||||||
			global $user;
 | 
					 | 
				
			||||||
			$iibbe = new ImageInfoBoxBuildingEvent($event->get_image(), $user);
 | 
								$iibbe = new ImageInfoBoxBuildingEvent($event->get_image(), $user);
 | 
				
			||||||
			send_event($iibbe);
 | 
								send_event($iibbe);
 | 
				
			||||||
			ksort($iibbe->parts);
 | 
								ksort($iibbe->parts);
 | 
				
			||||||
			$this->theme->display_page($event->page, $event->get_image(), $iibbe->parts);
 | 
								$this->theme->display_page($page, $event->get_image(), $iibbe->parts);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										11
									
								
								index.php
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								index.php
									
									
									
									
									
								
							@ -55,14 +55,9 @@ try {
 | 
				
			|||||||
	// start the page generation waterfall
 | 
						// start the page generation waterfall
 | 
				
			||||||
	$page = new Page();
 | 
						$page = new Page();
 | 
				
			||||||
	$user = _get_user($config, $database);
 | 
						$user = _get_user($config, $database);
 | 
				
			||||||
	$context = new RequestContext();
 | 
						send_event(new InitExtEvent());
 | 
				
			||||||
	$context->page = $page;
 | 
						send_event(_get_page_request());
 | 
				
			||||||
	$context->user = $user;
 | 
						$page->display();
 | 
				
			||||||
	$context->database = $database;
 | 
					 | 
				
			||||||
	$context->config = $config;
 | 
					 | 
				
			||||||
	send_event(new InitExtEvent($context));
 | 
					 | 
				
			||||||
	send_event(_get_page_request($context));
 | 
					 | 
				
			||||||
	$context->page->display($context);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// for databases which support transactions
 | 
						// for databases which support transactions
 | 
				
			||||||
 | 
				
			|||||||
@ -42,9 +42,8 @@ Tips
 | 
				
			|||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 | 
					* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Layout {
 | 
					class Layout {
 | 
				
			||||||
	public function display_page($context) {
 | 
						public function display_page($page) {
 | 
				
			||||||
		$page = $context->page;
 | 
							global $config;
 | 
				
			||||||
		$config = $context->config;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$theme_name = $config->get_string('theme');
 | 
							$theme_name = $config->get_string('theme');
 | 
				
			||||||
		$base_href = $config->get_string('base_href');
 | 
							$base_href = $config->get_string('base_href');
 | 
				
			||||||
 | 
				
			|||||||
@ -1,9 +1,8 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Layout {
 | 
					class Layout {
 | 
				
			||||||
	function display_page($context) {
 | 
						function display_page($page) {
 | 
				
			||||||
		$page = $context->page;
 | 
							global $config;
 | 
				
			||||||
		$config = $context->config;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$theme_name = $config->get_string('theme', 'default');
 | 
							$theme_name = $config->get_string('theme', 'default');
 | 
				
			||||||
		$data_href = get_base_href();
 | 
							$data_href = get_base_href();
 | 
				
			||||||
 | 
				
			|||||||
@ -1,9 +1,8 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Layout {
 | 
					class Layout {
 | 
				
			||||||
	function display_page($context) {
 | 
						function display_page($page) {
 | 
				
			||||||
		$page = $context->page;
 | 
							global $config;
 | 
				
			||||||
		$config = $context->config;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$theme_name = $config->get_string('theme', 'default');
 | 
							$theme_name = $config->get_string('theme', 'default');
 | 
				
			||||||
		$data_href = get_base_href();
 | 
							$data_href = get_base_href();
 | 
				
			||||||
 | 
				
			|||||||
@ -1,9 +1,8 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Layout {
 | 
					class Layout {
 | 
				
			||||||
	function display_page($context) {
 | 
						function display_page($page) {
 | 
				
			||||||
		$page = $context->page;
 | 
							global $config;
 | 
				
			||||||
		$config = $context->config;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$theme_name = $config->get_string('theme', 'default');
 | 
							$theme_name = $config->get_string('theme', 'default');
 | 
				
			||||||
		$data_href = get_base_href();
 | 
							$data_href = get_base_href();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user