Merge branch 'branch_2.3' of ssh://marigold.shishnet.org/git/shimmie2 into branch_2.3
This commit is contained in:
		
						commit
						5922fb6f25
					
				
							
								
								
									
										34
									
								
								contrib/ban_words/test.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								contrib/ban_words/test.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,34 @@
 | 
			
		||||
<?php
 | 
			
		||||
class BanWordsTest extends ShimmieWebTestCase {
 | 
			
		||||
	function testWordBan() {
 | 
			
		||||
		$this->log_in_as_admin();
 | 
			
		||||
		$this->get_page("setup");
 | 
			
		||||
		$this->setField("_config_banned_words", "viagra\nporn\n/http:.*\.cn\//");
 | 
			
		||||
		$this->click("Save Settings");
 | 
			
		||||
		$this->log_out();
 | 
			
		||||
 | 
			
		||||
		$this->log_in_as_user();
 | 
			
		||||
		$image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot");
 | 
			
		||||
 | 
			
		||||
		$this->get_page("post/view/$image_id");
 | 
			
		||||
		$this->setField('comment', "kittens and viagra");
 | 
			
		||||
		$this->click("Post Comment");
 | 
			
		||||
		$this->assertTitle("Comment Blocked");
 | 
			
		||||
 | 
			
		||||
		$this->get_page("post/view/$image_id");
 | 
			
		||||
		$this->setField('comment', "some link to http://something.cn/");
 | 
			
		||||
		$this->click("Post Comment");
 | 
			
		||||
		$this->assertTitle("Comment Blocked");
 | 
			
		||||
 | 
			
		||||
		$this->get_page('comment/list');
 | 
			
		||||
		$this->assertTitle('Comments');
 | 
			
		||||
		$this->assertNoText('viagra');
 | 
			
		||||
		$this->assertNoText('http://something.cn/');
 | 
			
		||||
		$this->log_out();
 | 
			
		||||
 | 
			
		||||
		$this->log_in_as_admin();
 | 
			
		||||
		$this->delete_image($image_id);
 | 
			
		||||
		$this->log_out();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
@ -5,46 +5,19 @@
 | 
			
		||||
 * Description: Handle Flash files
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
class FlashFileHandler extends SimpleExtension {
 | 
			
		||||
	public function onDataUpload($event) {
 | 
			
		||||
		if($this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
 | 
			
		||||
			$hash = $event->hash;
 | 
			
		||||
			$ha = substr($hash, 0, 2);
 | 
			
		||||
			if(!move_upload_to_archive($event)) return;
 | 
			
		||||
			send_event(new ThumbnailGenerationEvent($event->hash, $event->type));
 | 
			
		||||
			$image = $this->create_image_from_data("images/$ha/$hash", $event->metadata);
 | 
			
		||||
			if(is_null($image)) {
 | 
			
		||||
				throw new UploadException(
 | 
			
		||||
						"Flash Handler failed to create image object from data. ".
 | 
			
		||||
						"Note: compressed flash files are currently unsupported");
 | 
			
		||||
			}
 | 
			
		||||
			send_event(new ImageAdditionEvent($event->user, $image));
 | 
			
		||||
		}
 | 
			
		||||
class FlashFileHandler extends DataHandlerExtension {
 | 
			
		||||
	protected function create_thumb($hash) {
 | 
			
		||||
		$ha = substr($hash, 0, 2);
 | 
			
		||||
		// FIXME: scale image, as not all boards use 192x192
 | 
			
		||||
		copy("ext/handle_flash/thumb.jpg", "thumbs/$ha/$hash");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function onThumbnailGeneration($event) {
 | 
			
		||||
		if($this->supported_ext($event->type)) {
 | 
			
		||||
			$hash = $event->hash;
 | 
			
		||||
			$ha = substr($hash, 0, 2);
 | 
			
		||||
			// FIXME: scale image, as not all boards use 192x192
 | 
			
		||||
			copy("ext/handle_flash/thumb.jpg", "thumbs/$ha/$hash");
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function onDisplayingImage($event) {
 | 
			
		||||
		global $page;
 | 
			
		||||
		if($this->supported_ext($event->image->ext)) {
 | 
			
		||||
			$this->theme->display_image($event->page, $event->image);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	private function supported_ext($ext) {
 | 
			
		||||
	protected function supported_ext($ext) {
 | 
			
		||||
		$exts = array("swf");
 | 
			
		||||
		return in_array(strtolower($ext), $exts);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private function create_image_from_data($filename, $metadata) {
 | 
			
		||||
	protected function create_image_from_data($filename, $metadata) {
 | 
			
		||||
		global $config;
 | 
			
		||||
 | 
			
		||||
		$image = new Image();
 | 
			
		||||
@ -72,6 +45,17 @@ class FlashFileHandler extends SimpleExtension {
 | 
			
		||||
		return $image;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected function check_contents($file) {
 | 
			
		||||
		if(!file_exists($file)) return false;
 | 
			
		||||
 | 
			
		||||
		$fp = fopen($file, "r");
 | 
			
		||||
		$head = fread($fp, 3);
 | 
			
		||||
		fclose($fp);
 | 
			
		||||
		if(!in_array($head, array("CWS", "FWS"))) return false;
 | 
			
		||||
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private function str_to_binarray($string) {
 | 
			
		||||
		$binary = array();
 | 
			
		||||
		for($j=0; $j<strlen($string); $j++) {
 | 
			
		||||
@ -117,16 +101,6 @@ class FlashFileHandler extends SimpleExtension {
 | 
			
		||||
 | 
			
		||||
		return $bounds;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private function check_contents($file) {
 | 
			
		||||
		if(!file_exists($file)) return false;
 | 
			
		||||
 | 
			
		||||
		$fp = fopen($file, "r");
 | 
			
		||||
		$head = fread($fp, 3);
 | 
			
		||||
		fclose($fp);
 | 
			
		||||
		if(!in_array($head, array("CWS", "FWS"))) return false;
 | 
			
		||||
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
add_event_listener(new FlashFileHandler());
 | 
			
		||||
?>
 | 
			
		||||
 | 
			
		||||
@ -16,7 +16,9 @@ class IcoFileHandler extends SimpleExtension {
 | 
			
		||||
			if(is_null($image)) {
 | 
			
		||||
				throw new UploadException("Icon handler failed to create image object from data");
 | 
			
		||||
			}
 | 
			
		||||
			send_event(new ImageAdditionEvent($event->user, $image));
 | 
			
		||||
			$iae = new ImageAdditionEvent($event->user, $image);
 | 
			
		||||
			send_event($iae);
 | 
			
		||||
			$event->image_id = $iae->image->id;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -27,13 +29,14 @@ class IcoFileHandler extends SimpleExtension {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function onDisplayingImage($event) {
 | 
			
		||||
		global $page;
 | 
			
		||||
		if($this->supported_ext($event->image->ext)) {
 | 
			
		||||
			$this->theme->display_image($event->page, $event->image);
 | 
			
		||||
			$this->theme->display_image($page, $event->image);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public function onPageRequest($event) {
 | 
			
		||||
		global $config, $database;
 | 
			
		||||
		global $config, $database, $page;
 | 
			
		||||
		if($event->page_matches("get_ico")) {
 | 
			
		||||
			$id = int_escape($event->get_arg(0));
 | 
			
		||||
			$image = Image::by_id($id);
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										14
									
								
								contrib/handle_ico/test.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								contrib/handle_ico/test.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
			
		||||
<?php
 | 
			
		||||
class IcoHandlerTest extends ShimmieWebTestCase {
 | 
			
		||||
	function testPixelHander() {
 | 
			
		||||
		$this->log_in_as_user();
 | 
			
		||||
		$image_id = $this->post_image("favicon.ico", "shimmie favicon");
 | 
			
		||||
		$this->assertResponse(302);
 | 
			
		||||
		$this->log_out();
 | 
			
		||||
 | 
			
		||||
		$this->log_in_as_admin();
 | 
			
		||||
		$this->delete_image($image_id);
 | 
			
		||||
		$this->log_out();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
@ -5,42 +5,19 @@
 | 
			
		||||
 * Description: Handle MP3 files
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
class MP3FileHandler implements Extension {
 | 
			
		||||
	var $theme;
 | 
			
		||||
 | 
			
		||||
	public function receive_event(Event $event) {
 | 
			
		||||
		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)) {
 | 
			
		||||
			$hash = $event->hash;
 | 
			
		||||
			$ha = substr($hash, 0, 2);
 | 
			
		||||
			if(!move_upload_to_archive($event)) return;
 | 
			
		||||
			send_event(new ThumbnailGenerationEvent($event->hash, $event->type));
 | 
			
		||||
			$image = $this->create_image_from_data("images/$ha/$hash", $event->metadata);
 | 
			
		||||
			if(is_null($image)) {
 | 
			
		||||
				throw new UploadException("MP3 handler failed to create image object from data");
 | 
			
		||||
			}
 | 
			
		||||
			send_event(new ImageAdditionEvent($event->user, $image));
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if(($event instanceof ThumbnailGenerationEvent) && $this->supported_ext($event->type)) {
 | 
			
		||||
			$hash = $event->hash;
 | 
			
		||||
			$ha = substr($hash, 0, 2);
 | 
			
		||||
			// FIXME: scale image, as not all boards use 192x192
 | 
			
		||||
			copy("ext/handle_mp3/thumb.jpg", "thumbs/$ha/$hash");
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if(($event instanceof DisplayingImageEvent) && $this->supported_ext($event->image->ext)) {
 | 
			
		||||
			$this->theme->display_image($event->page, $event->image);
 | 
			
		||||
		}
 | 
			
		||||
class MP3FileHandler extends DataHandlerExtension {
 | 
			
		||||
	protected function create_thumb($hash) {
 | 
			
		||||
		$ha = substr($hash, 0, 2);
 | 
			
		||||
		// FIXME: scale image, as not all boards use 192x192
 | 
			
		||||
		copy("ext/handle_mp3/thumb.jpg", "thumbs/$ha/$hash");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private function supported_ext($ext) {
 | 
			
		||||
	protected function supported_ext($ext) {
 | 
			
		||||
		$exts = array("mp3");
 | 
			
		||||
		return in_array(strtolower($ext), $exts);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private function create_image_from_data($filename, $metadata) {
 | 
			
		||||
	protected function create_image_from_data($filename, $metadata) {
 | 
			
		||||
		global $config;
 | 
			
		||||
 | 
			
		||||
		$image = new Image();
 | 
			
		||||
@ -59,7 +36,7 @@ class MP3FileHandler implements Extension {
 | 
			
		||||
		return $image;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private function check_contents($file) {
 | 
			
		||||
	protected function check_contents($file) {
 | 
			
		||||
		// FIXME: mp3 magic header?
 | 
			
		||||
		return (file_exists($file));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -20,7 +20,9 @@ class SVGFileHandler implements Extension {
 | 
			
		||||
			if(is_null($image)) {
 | 
			
		||||
				throw new UploadException("SVG handler failed to create image object from data");
 | 
			
		||||
			}
 | 
			
		||||
			send_event(new ImageAdditionEvent($event->user, $image));
 | 
			
		||||
			$iae = new ImageAdditionEvent($event->user, $image);
 | 
			
		||||
			send_event($iae);
 | 
			
		||||
			$event->image_id = $iae->image->id;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if(($event instanceof ThumbnailGenerationEvent) && $this->supported_ext($event->type)) {
 | 
			
		||||
@ -44,20 +46,20 @@ class SVGFileHandler implements Extension {
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if(($event instanceof DisplayingImageEvent) && $this->supported_ext($event->image->ext)) {
 | 
			
		||||
			$this->theme->display_image($event->page, $event->image);
 | 
			
		||||
			global $page;
 | 
			
		||||
			$this->theme->display_image($page, $event->image);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if(($event instanceof PageRequestEvent) && $event->page_matches("get_svg")) {
 | 
			
		||||
			global $config;
 | 
			
		||||
			global $database;
 | 
			
		||||
			global $config, $database, $page;
 | 
			
		||||
			$id = int_escape($event->get_arg(0));
 | 
			
		||||
			$image = Image::by_id($id);
 | 
			
		||||
			$hash = $image->hash;
 | 
			
		||||
			$ha = substr($hash, 0, 2);
 | 
			
		||||
 | 
			
		||||
			$event->page->set_type("image/svg+xml");
 | 
			
		||||
			$event->page->set_mode("data");
 | 
			
		||||
			$event->page->set_data(file_get_contents("images/$ha/$hash"));
 | 
			
		||||
			$page->set_type("image/svg+xml");
 | 
			
		||||
			$page->set_mode("data");
 | 
			
		||||
			$page->set_data(file_get_contents("images/$ha/$hash"));
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										31
									
								
								contrib/handle_svg/test.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								contrib/handle_svg/test.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,31 @@
 | 
			
		||||
<?php
 | 
			
		||||
class SVGHandlerTest extends ShimmieWebTestCase {
 | 
			
		||||
	function testSVGHander() {
 | 
			
		||||
		file_put_contents("test.svg", '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
 | 
			
		||||
<svg
 | 
			
		||||
   xmlns="http://www.w3.org/2000/svg"
 | 
			
		||||
   width="128"
 | 
			
		||||
   height="128"
 | 
			
		||||
   id="svg2"
 | 
			
		||||
   version="1.0">
 | 
			
		||||
  <g id="layer1">
 | 
			
		||||
    <path
 | 
			
		||||
       style="fill:#0000ff;stroke:#213847;stroke-opacity:1"
 | 
			
		||||
       id="path2383"
 | 
			
		||||
       d="M 120.07832,64.983688 A 55.573441,53.092484 0 1 1 8.9314423,64.983688 A 55.573441,53.092484 0 1 1 120.07832,64.983688 z" />
 | 
			
		||||
  </g>
 | 
			
		||||
</svg>');
 | 
			
		||||
 | 
			
		||||
		$this->log_in_as_user();
 | 
			
		||||
		$image_id = $this->post_image("favicon.ico", "shimmie favicon");
 | 
			
		||||
		$this->assertResponse(302);
 | 
			
		||||
		$this->log_out();
 | 
			
		||||
 | 
			
		||||
		$this->log_in_as_admin();
 | 
			
		||||
		$this->delete_image($image_id);
 | 
			
		||||
		$this->log_out();
 | 
			
		||||
 | 
			
		||||
		unlink("test.svg");
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
							
								
								
									
										25
									
								
								contrib/news/test.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								contrib/news/test.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,25 @@
 | 
			
		||||
<?php
 | 
			
		||||
class NewsTest extends ShimmieWebTestCase {
 | 
			
		||||
	function testNews() {
 | 
			
		||||
		$this->log_in_as_admin();
 | 
			
		||||
 | 
			
		||||
		$this->get_page("setup");
 | 
			
		||||
		$this->setField("_config_news_text", "kittens");
 | 
			
		||||
		$this->click("Save Settings");
 | 
			
		||||
 | 
			
		||||
		$this->get_page("post/list");
 | 
			
		||||
		$this->assertText("Note");
 | 
			
		||||
		$this->assertText("kittens");
 | 
			
		||||
 | 
			
		||||
		$this->get_page("setup");
 | 
			
		||||
		$this->setField("_config_news_text", "");
 | 
			
		||||
		$this->click("Save Settings");
 | 
			
		||||
 | 
			
		||||
		$this->get_page("post/list");
 | 
			
		||||
		$this->assertNoText("Note");
 | 
			
		||||
		$this->assertNoText("kittens");
 | 
			
		||||
 | 
			
		||||
		$this->log_out();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
@ -5,9 +5,6 @@ class RSSImagesTest extends ShimmieWebTestCase {
 | 
			
		||||
		$image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot");
 | 
			
		||||
		$this->log_out();
 | 
			
		||||
 | 
			
		||||
		$this->assertTitle("Upload Status");
 | 
			
		||||
		$this->assertText("already has hash");
 | 
			
		||||
 | 
			
		||||
        $this->get_page('rss/images');
 | 
			
		||||
		$this->assertMime("application/rss+xml");
 | 
			
		||||
		$this->assertNoText("Exception");
 | 
			
		||||
@ -16,11 +13,18 @@ class RSSImagesTest extends ShimmieWebTestCase {
 | 
			
		||||
		$this->assertMime("application/rss+xml");
 | 
			
		||||
		$this->assertNoText("Exception");
 | 
			
		||||
 | 
			
		||||
        $this->get_page('rss/images/tagme/1');
 | 
			
		||||
		# FIXME: test that the image is actually found
 | 
			
		||||
        $this->get_page('rss/images/computer/1');
 | 
			
		||||
		$this->assertMime("application/rss+xml");
 | 
			
		||||
		$this->assertNoText("Exception");
 | 
			
		||||
 | 
			
		||||
        $this->get_page('rss/images/tagme/2');
 | 
			
		||||
		# valid tag, invalid page
 | 
			
		||||
        $this->get_page('rss/images/computer/2');
 | 
			
		||||
		$this->assertMime("application/rss+xml");
 | 
			
		||||
		$this->assertNoText("Exception");
 | 
			
		||||
 | 
			
		||||
		# not found
 | 
			
		||||
        $this->get_page('rss/images/waffle/2');
 | 
			
		||||
		$this->assertMime("application/rss+xml");
 | 
			
		||||
		$this->assertNoText("Exception");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -17,7 +17,9 @@ define('ADMIN_PASS', "demo");
 | 
			
		||||
 | 
			
		||||
class ShimmieWebTestCase extends WebTestCase {
 | 
			
		||||
	protected function get_page($page) {
 | 
			
		||||
		$this->get($_SERVER["HTTP_HOST"].'/'.make_link($page));
 | 
			
		||||
		$url = "http://".$_SERVER["HTTP_HOST"].get_base_href().'/'.make_link($page);
 | 
			
		||||
		$url = str_replace("/./", "/", $url);
 | 
			
		||||
		$this->get($url);
 | 
			
		||||
	}
 | 
			
		||||
	protected function log_in_as_user() {
 | 
			
		||||
        $this->get_page('post/list');
 | 
			
		||||
 | 
			
		||||
@ -23,6 +23,8 @@ class WordFilter implements Extension {
 | 
			
		||||
	private function filter($text) {
 | 
			
		||||
		$map = $this->get_map();
 | 
			
		||||
		foreach($map as $search => $replace) {
 | 
			
		||||
			$search = trim($search);
 | 
			
		||||
			$replace = trim($replace);
 | 
			
		||||
			$search = "/\\b$search\\b/i";
 | 
			
		||||
			$text = preg_replace($search, $replace, $text);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,58 @@
 | 
			
		||||
<?php
 | 
			
		||||
class WordFiterTest extends ShimmieWebTestCase {}
 | 
			
		||||
class WordFilterTest extends ShimmieWebTestCase {
 | 
			
		||||
	function testWordFilter() {
 | 
			
		||||
		$this->log_in_as_admin();
 | 
			
		||||
		$this->get_page("setup");
 | 
			
		||||
		$this->setField("_config_word_filter", "whore,nice lady\na duck,a kitten\n white ,\tspace\ninvalid");
 | 
			
		||||
		$this->click("Save Settings");
 | 
			
		||||
		$this->log_out();
 | 
			
		||||
 | 
			
		||||
		$this->log_in_as_user();
 | 
			
		||||
		$image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot");
 | 
			
		||||
		$this->get_page("post/view/$image_id");
 | 
			
		||||
 | 
			
		||||
		# regular
 | 
			
		||||
		$this->setField('comment', "posted by a whore");
 | 
			
		||||
		$this->click("Post Comment");
 | 
			
		||||
		$this->assertText("posted by a nice lady");
 | 
			
		||||
 | 
			
		||||
		# replace all instances
 | 
			
		||||
		$this->setField('comment', "a whore is a whore is a whore");
 | 
			
		||||
		$this->click("Post Comment");
 | 
			
		||||
		$this->assertText("a nice lady is a nice lady is a nice lady");
 | 
			
		||||
 | 
			
		||||
		# still have effect when case is changed
 | 
			
		||||
		$this->setField('comment', "monkey WhorE");
 | 
			
		||||
		$this->click("Post Comment");
 | 
			
		||||
		$this->assertText("monkey nice lady");
 | 
			
		||||
 | 
			
		||||
		# only do whole words
 | 
			
		||||
		$this->setField('comment', "my name is whoretta");
 | 
			
		||||
		$this->click("Post Comment");
 | 
			
		||||
		$this->assertText("my name is whoretta");
 | 
			
		||||
 | 
			
		||||
		# search multiple words
 | 
			
		||||
		$this->setField('comment', "I would like a duck");
 | 
			
		||||
		$this->click("Post Comment");
 | 
			
		||||
		$this->assertText("I would like a kitten");
 | 
			
		||||
 | 
			
		||||
		# test for a line which was entered with extra whitespace
 | 
			
		||||
		$this->setField('comment', "A colour is white");
 | 
			
		||||
		$this->click("Post Comment");
 | 
			
		||||
		$this->assertText("A colour is space");
 | 
			
		||||
 | 
			
		||||
		# don't do anything with invalid lines
 | 
			
		||||
		$this->setField('comment', "The word was invalid");
 | 
			
		||||
		$this->click("Post Comment");
 | 
			
		||||
		$this->assertText("The word was invalid");
 | 
			
		||||
 | 
			
		||||
		$this->log_out();
 | 
			
		||||
 | 
			
		||||
		$this->log_in_as_admin();
 | 
			
		||||
		$this->delete_image($image_id);
 | 
			
		||||
		$this->log_out();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
if(!defined(VERSION)) return;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -72,6 +72,7 @@ class MySQL extends DBEngine {
 | 
			
		||||
		$data = str_replace("SCORE_BOOL_Y", "'Y'", $data);
 | 
			
		||||
		$data = str_replace("SCORE_BOOL_N", "'N'", $data);
 | 
			
		||||
		$data = str_replace("SCORE_BOOL", "ENUM('Y', 'N')", $data);
 | 
			
		||||
		$data = str_replace("SCORE_DATETIME", "DATETIME", $data);
 | 
			
		||||
		$data = str_replace("SCORE_NOW", "\"1970-01-01\"", $data);
 | 
			
		||||
		$ctes = "TYPE=InnoDB DEFAULT CHARSET='utf8'";
 | 
			
		||||
		return "CREATE TABLE $name ($data) $ctes";
 | 
			
		||||
@ -86,6 +87,7 @@ class PostgreSQL extends DBEngine {
 | 
			
		||||
		$data = str_replace("SCORE_BOOL_Y", "'t'", $data);
 | 
			
		||||
		$data = str_replace("SCORE_BOOL_N", "'f'", $data);
 | 
			
		||||
		$data = str_replace("SCORE_BOOL", "BOOL", $data);
 | 
			
		||||
		$data = str_replace("SCORE_DATETIME", "TIMESTAMP", $data);
 | 
			
		||||
		$data = str_replace("SCORE_NOW", "current_time", $data);
 | 
			
		||||
		return "CREATE TABLE $name ($data)";
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -54,4 +54,40 @@ abstract class FormatterExtension implements Extension {
 | 
			
		||||
	abstract public function format($text);
 | 
			
		||||
	abstract public function strip($text);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
abstract class DataHandlerExtension implements Extension {
 | 
			
		||||
	var $theme;
 | 
			
		||||
 | 
			
		||||
	public function receive_event(Event $event) {
 | 
			
		||||
		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)) {
 | 
			
		||||
			$hash = $event->hash;
 | 
			
		||||
			$ha = substr($hash, 0, 2);
 | 
			
		||||
			if(!move_upload_to_archive($event)) return;
 | 
			
		||||
			send_event(new ThumbnailGenerationEvent($event->hash, $event->type));
 | 
			
		||||
			$image = $this->create_image_from_data("images/$ha/$hash", $event->metadata);
 | 
			
		||||
			if(is_null($image)) {
 | 
			
		||||
				throw new UploadException("Data handler failed to create image object from data");
 | 
			
		||||
			}
 | 
			
		||||
			$iae = new ImageAdditionEvent($event->user, $image);
 | 
			
		||||
			send_event($iae);
 | 
			
		||||
			$event->image_id = $iae->image->id;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if(($event instanceof ThumbnailGenerationEvent) && $this->supported_ext($event->type)) {
 | 
			
		||||
			$this->create_thumb($event->hash);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if(($event instanceof DisplayingImageEvent) && $this->supported_ext($event->image->ext)) {
 | 
			
		||||
			global $page;
 | 
			
		||||
			$this->theme->display_image($page, $event->image);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	abstract protected function supported_ext($ext);
 | 
			
		||||
	abstract protected function check_contents($tmpname);
 | 
			
		||||
	abstract protected function create_image_from_data($filename, $metadata);
 | 
			
		||||
	abstract protected function create_thumb($hash);
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
 | 
			
		||||
@ -5,8 +5,64 @@ class AliasEditorTest extends ShimmieWebTestCase {
 | 
			
		||||
		$this->assertTitle("Alias List");
 | 
			
		||||
 | 
			
		||||
		$this->log_in_as_admin();
 | 
			
		||||
 | 
			
		||||
		# test one to one
 | 
			
		||||
        $this->get_page('alias/list');
 | 
			
		||||
		$this->assertTitle("Alias List");
 | 
			
		||||
		$this->setField('oldtag', "test1");
 | 
			
		||||
		$this->setField('newtag', "test2");
 | 
			
		||||
		$this->click("Add");
 | 
			
		||||
		$this->assertText("test1");
 | 
			
		||||
 | 
			
		||||
		$this->get_page("alias/export/aliases.csv");
 | 
			
		||||
		$this->assertText("test1,test2");
 | 
			
		||||
 | 
			
		||||
		$image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "test1");
 | 
			
		||||
		$this->get_page("post/view/$image_id"); # check that the tag has been replaced
 | 
			
		||||
		$this->assertTitle("Image $image_id: test2");
 | 
			
		||||
		$this->get_page("post/list/test1/1"); # searching for an alias should find the master tag
 | 
			
		||||
		$this->assertTitle("Image $image_id: test2");
 | 
			
		||||
		$this->get_page("post/list/test2/1"); # check that searching for the main tag still works
 | 
			
		||||
		$this->assertTitle("Image $image_id: test2");
 | 
			
		||||
		$this->delete_image($image_id);
 | 
			
		||||
 | 
			
		||||
        $this->get_page('alias/list');
 | 
			
		||||
		$this->click("Remove");
 | 
			
		||||
		$this->assertTitle("Alias List");
 | 
			
		||||
		$this->assertNoText("test1");
 | 
			
		||||
 | 
			
		||||
		# test one to many
 | 
			
		||||
        $this->get_page('alias/list');
 | 
			
		||||
		$this->assertTitle("Alias List");
 | 
			
		||||
		$this->setField('oldtag', "onetag");
 | 
			
		||||
		$this->setField('newtag', "multi tag");
 | 
			
		||||
		$this->click("Add");
 | 
			
		||||
		$this->assertText("multi");
 | 
			
		||||
		$this->assertText("tag");
 | 
			
		||||
 | 
			
		||||
		$this->get_page("alias/export/aliases.csv");
 | 
			
		||||
		$this->assertText("onetag,multi tag");
 | 
			
		||||
 | 
			
		||||
		$image_id_1 = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "onetag");
 | 
			
		||||
		$image_id_2 = $this->post_image("ext/simpletest/data/bedroom_workshop.jpg", "onetag");
 | 
			
		||||
		// FIXME: known broken
 | 
			
		||||
		//$this->get_page("post/list/onetag/1"); # searching for an aliased tag should find its aliases
 | 
			
		||||
		//$this->assertTitle("onetag");
 | 
			
		||||
		//$this->assertNoText("No Images Found");
 | 
			
		||||
		$this->get_page("post/list/multi/1");
 | 
			
		||||
		$this->assertTitle("multi");
 | 
			
		||||
		$this->assertNoText("No Images Found");
 | 
			
		||||
		$this->get_page("post/list/multi%20tag/1");
 | 
			
		||||
		$this->assertTitle("multi tag");
 | 
			
		||||
		$this->assertNoText("No Images Found");
 | 
			
		||||
		$this->delete_image($image_id_1);
 | 
			
		||||
		$this->delete_image($image_id_2);
 | 
			
		||||
 | 
			
		||||
        $this->get_page('alias/list');
 | 
			
		||||
		$this->click("Remove");
 | 
			
		||||
		$this->assertTitle("Alias List");
 | 
			
		||||
		$this->assertNoText("test1");
 | 
			
		||||
 | 
			
		||||
		$this->log_out();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -5,43 +5,13 @@
 | 
			
		||||
 * Description: Handle JPG, PNG, GIF, etc files
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
class PixelFileHandler implements Extension {
 | 
			
		||||
	var $theme;
 | 
			
		||||
 | 
			
		||||
	public function receive_event(Event $event) {
 | 
			
		||||
		global $page;
 | 
			
		||||
		if(is_null($this->theme)) $this->theme = get_theme_object($this);
 | 
			
		||||
 | 
			
		||||
		if(($event instanceof DataUploadEvent) && $this->supported_ext($event->type) && $this->check_contents($event->tmpname)) {
 | 
			
		||||
			$hash = $event->hash;
 | 
			
		||||
			$ha = substr($hash, 0, 2);
 | 
			
		||||
			if(!move_upload_to_archive($event)) return;
 | 
			
		||||
			send_event(new ThumbnailGenerationEvent($event->hash, $event->type));
 | 
			
		||||
			$image = $this->create_image_from_data("images/$ha/$hash", $event->metadata);
 | 
			
		||||
			if(is_null($image)) {
 | 
			
		||||
				throw new UploadException("Pixel Handler failed to create image object from data");
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			$iae = new ImageAdditionEvent($event->user, $image);
 | 
			
		||||
			send_event($iae); // this might raise an exception, but all we'd do is re-throw it...
 | 
			
		||||
			$event->image_id = $iae->image->id;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if(($event instanceof ThumbnailGenerationEvent) && $this->supported_ext($event->type)) {
 | 
			
		||||
			$this->create_thumb($event->hash);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if(($event instanceof DisplayingImageEvent) && $this->supported_ext($event->image->ext)) {
 | 
			
		||||
			$this->theme->display_image($page, $event->image);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private function supported_ext($ext) {
 | 
			
		||||
class PixelFileHandler extends DataHandlerExtension {
 | 
			
		||||
	protected function supported_ext($ext) {
 | 
			
		||||
		$exts = array("jpg", "jpeg", "gif", "png");
 | 
			
		||||
		return in_array(strtolower($ext), $exts);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private function create_image_from_data($filename, $metadata) {
 | 
			
		||||
	protected function create_image_from_data($filename, $metadata) {
 | 
			
		||||
		global $config;
 | 
			
		||||
 | 
			
		||||
		$image = new Image();
 | 
			
		||||
@ -62,7 +32,7 @@ class PixelFileHandler implements Extension {
 | 
			
		||||
		return $image;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private function check_contents($file) {
 | 
			
		||||
	protected function check_contents($file) {
 | 
			
		||||
		$valid = Array(IMAGETYPE_PNG, IMAGETYPE_GIF, IMAGETYPE_JPEG);
 | 
			
		||||
		if(!file_exists($file)) return false;
 | 
			
		||||
		$info = getimagesize($file);
 | 
			
		||||
@ -71,7 +41,7 @@ class PixelFileHandler implements Extension {
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private function create_thumb($hash) {
 | 
			
		||||
	protected function create_thumb($hash) {
 | 
			
		||||
		$ha = substr($hash, 0, 2);
 | 
			
		||||
		$inname  = "images/$ha/$hash";
 | 
			
		||||
		$outname = "thumbs/$ha/$hash";
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										14
									
								
								ext/handle_pixel/test.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								ext/handle_pixel/test.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
			
		||||
<?php
 | 
			
		||||
class PixelHandlerTest extends ShimmieWebTestCase {
 | 
			
		||||
	function testPixelHander() {
 | 
			
		||||
		$this->log_in_as_user();
 | 
			
		||||
		$image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot");
 | 
			
		||||
		$this->assertResponse(302);
 | 
			
		||||
		$this->log_out();
 | 
			
		||||
 | 
			
		||||
		$this->log_in_as_admin();
 | 
			
		||||
		$this->delete_image($image_id);
 | 
			
		||||
		$this->log_out();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
@ -48,14 +48,17 @@ class IndexTest extends ShimmieWebTestCase {
 | 
			
		||||
		# regular tag, many results
 | 
			
		||||
        $this->get_page('post/list/computer/1');
 | 
			
		||||
		$this->assertTitle("computer");
 | 
			
		||||
		$this->assertNoText("No Images Found");
 | 
			
		||||
 | 
			
		||||
		# meta tag, many results
 | 
			
		||||
        $this->get_page('post/list/size=640x480/1');
 | 
			
		||||
		$this->assertTitle("size=640x480");
 | 
			
		||||
		$this->assertNoText("No Images Found");
 | 
			
		||||
 | 
			
		||||
		# multiple tags, many results
 | 
			
		||||
        $this->get_page('post/list/computer%20size=640x480/1');
 | 
			
		||||
		$this->assertTitle("computer size=640x480");
 | 
			
		||||
		$this->assertNoText("No Images Found");
 | 
			
		||||
 | 
			
		||||
		# multiple tags, single result; search with one result = direct to image
 | 
			
		||||
		$this->get_page('post/list/screenshot%20computer/1');
 | 
			
		||||
@ -65,6 +68,11 @@ class IndexTest extends ShimmieWebTestCase {
 | 
			
		||||
		$this->get_page('post/list/computer%20-pbx/1');
 | 
			
		||||
		$this->assertTitle(new PatternExpectation("/^Image $image_id_2: /"));
 | 
			
		||||
 | 
			
		||||
		# negative tag alone, should work
 | 
			
		||||
		# FIXME: known broken in mysql
 | 
			
		||||
		//$this->get_page('post/list/-pbx/1');
 | 
			
		||||
		//$this->assertTitle(new PatternExpectation("/^Image $image_id_2: /"));
 | 
			
		||||
 | 
			
		||||
		$this->log_in_as_admin();
 | 
			
		||||
		$this->delete_image($image_id_1);
 | 
			
		||||
		$this->delete_image($image_id_2);
 | 
			
		||||
 | 
			
		||||
@ -150,6 +150,9 @@ class Upload implements Extension {
 | 
			
		||||
			$event = new DataUploadEvent($user, $file['tmp_name'], $metadata);
 | 
			
		||||
			try {
 | 
			
		||||
				send_event($event);
 | 
			
		||||
				if($event->image_id == -1) {
 | 
			
		||||
					throw new UploadException("File type not recognised");
 | 
			
		||||
				}
 | 
			
		||||
				header("X-Shimmie-Image-ID: ".int_escape($event->image_id));
 | 
			
		||||
			}
 | 
			
		||||
			catch(UploadException $ex) {
 | 
			
		||||
 | 
			
		||||
@ -7,14 +7,32 @@ class UploadTest extends ShimmieWebTestCase {
 | 
			
		||||
		$this->assertResponse(302);
 | 
			
		||||
 | 
			
		||||
		$image_id_2 = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "pbx computer screenshot");
 | 
			
		||||
		$this->assertResponse(200);
 | 
			
		||||
		$this->assertTitle("Upload Status");
 | 
			
		||||
		$this->assertText("already has hash");
 | 
			
		||||
 | 
			
		||||
		$image_id_3 = $this->post_image("index.php", "test");
 | 
			
		||||
		$this->assertResponse(200);
 | 
			
		||||
		$this->assertTitle("Upload Status");
 | 
			
		||||
		$this->assertText("File type not recognised");
 | 
			
		||||
 | 
			
		||||
		/*
 | 
			
		||||
		// FIXME: huge.dat is rejected for other reasons; manual testing shows that this works
 | 
			
		||||
		file_put_contents("huge.dat", file_get_contents("ext/simpletest/data/pbx_screenshot.jpg") . str_repeat("U", 1024*1024*3));
 | 
			
		||||
		$image_id_4 = $this->post_image("index.php", "test");
 | 
			
		||||
		$this->assertResponse(200);
 | 
			
		||||
		$this->assertTitle("Upload Status");
 | 
			
		||||
		$this->assertText("File too large");
 | 
			
		||||
		unlink("huge.dat");
 | 
			
		||||
		*/
 | 
			
		||||
 | 
			
		||||
		$this->log_out();
 | 
			
		||||
 | 
			
		||||
		$this->log_in_as_admin();
 | 
			
		||||
		$this->delete_image($image_id_1);
 | 
			
		||||
		$this->delete_image($image_id_2);
 | 
			
		||||
		$this->delete_image($image_id_3); # if these were successfully rejected,
 | 
			
		||||
		//$this->delete_image($image_id_4); # then delete_image is a no-op
 | 
			
		||||
		$this->log_out();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										38
									
								
								install.php
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								install.php
									
									
									
									
									
								
							@ -86,26 +86,52 @@ function do_install() { // {{{
 | 
			
		||||
	}
 | 
			
		||||
	else if(file_exists("auto_install.conf")) {
 | 
			
		||||
		install_process(trim(file_get_contents("auto_install.conf")));
 | 
			
		||||
		unlink("auto_install.conf");
 | 
			
		||||
	}
 | 
			
		||||
	else {
 | 
			
		||||
		begin();
 | 
			
		||||
	}
 | 
			
		||||
} // }}}
 | 
			
		||||
function begin() { // {{{
 | 
			
		||||
	$err = "";
 | 
			
		||||
	$thumberr = "";
 | 
			
		||||
	$dberr = "";
 | 
			
		||||
 | 
			
		||||
	if(check_gd_version() == 0 && check_im_version() == 0) {
 | 
			
		||||
		$gd = "<h3>Error</h3>\nPHP's GD extension seems to be missing, ".
 | 
			
		||||
		$thumberr = "<p>PHP's GD extension seems to be missing, ".
 | 
			
		||||
		      "and imagemagick's \"convert\" command cannot be found - ".
 | 
			
		||||
			  "no thumbnailing engines are available.";
 | 
			
		||||
	}
 | 
			
		||||
	else {
 | 
			
		||||
		$gd = "";
 | 
			
		||||
 | 
			
		||||
	if(!function_exists("mysql_connect")) {
 | 
			
		||||
		$dberr = "<p>PHP's MySQL extension seems to be missing; you may ".
 | 
			
		||||
				"be able to use an unofficial alternative, checking ".
 | 
			
		||||
				"for libraries...";
 | 
			
		||||
		if(!function_exists("pg_connect")) {
 | 
			
		||||
			$dberr .= "<br>PgSQL is missing";
 | 
			
		||||
		}
 | 
			
		||||
		else {
 | 
			
		||||
			$dberr .= "<br>PgSQL is available";
 | 
			
		||||
		}
 | 
			
		||||
		if(!function_exists("sqlite_open")) {
 | 
			
		||||
			$dberr .= "<br>SQLite is missing";
 | 
			
		||||
		}
 | 
			
		||||
		else {
 | 
			
		||||
			$dberr .= "<br>SQLite is available";
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if($thumberr || $dberr) {
 | 
			
		||||
		$err = "<h3>Error</h3>";
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	print <<<EOD
 | 
			
		||||
		<div id="iblock">
 | 
			
		||||
			<h1>Shimmie Installer</h1>
 | 
			
		||||
 | 
			
		||||
			$gd
 | 
			
		||||
			$err
 | 
			
		||||
			$thumberr
 | 
			
		||||
			$dberr
 | 
			
		||||
 | 
			
		||||
			<h3>Install</h3>
 | 
			
		||||
			<form action="install.php" method="POST">
 | 
			
		||||
@ -171,7 +197,7 @@ function create_tables($dsn) { // {{{
 | 
			
		||||
			id SCORE_AIPK,
 | 
			
		||||
			name VARCHAR(32) UNIQUE NOT NULL,
 | 
			
		||||
			pass CHAR(32),
 | 
			
		||||
			joindate DATETIME NOT NULL DEFAULT SCORE_NOW,
 | 
			
		||||
			joindate SCORE_DATETIME NOT NULL DEFAULT SCORE_NOW,
 | 
			
		||||
			admin SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
 | 
			
		||||
			email VARCHAR(128)
 | 
			
		||||
		"));
 | 
			
		||||
@ -186,7 +212,7 @@ function create_tables($dsn) { // {{{
 | 
			
		||||
			source VARCHAR(255),
 | 
			
		||||
			width INTEGER NOT NULL,
 | 
			
		||||
			height INTEGER NOT NULL,
 | 
			
		||||
			posted TIMESTAMP NOT NULL DEFAULT SCORE_NOW,
 | 
			
		||||
			posted SCORE_DATETIME NOT NULL DEFAULT SCORE_NOW,
 | 
			
		||||
			locked SCORE_BOOL NOT NULL DEFAULT SCORE_BOOL_N,
 | 
			
		||||
			INDEX(owner_id),
 | 
			
		||||
			INDEX(width),
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user