From f8765de7a940aaa4cac5d97e9356aa800519007b Mon Sep 17 00:00:00 2001
From: Shish <shish@shishnet.org>
Date: Tue, 26 Jan 2010 13:38:08 +0000
Subject: [PATCH] Turn the QR Code extension into a SimpleExtension, trim the
 boilerplate

---
 contrib/qr_code/main.php  | 31 +++----------------------------
 contrib/qr_code/theme.php | 10 ++++------
 2 files changed, 7 insertions(+), 34 deletions(-)

diff --git a/contrib/qr_code/main.php b/contrib/qr_code/main.php
index f500866c..3d698e79 100644
--- a/contrib/qr_code/main.php
+++ b/contrib/qr_code/main.php
@@ -6,34 +6,9 @@
  * 				Based on Artanis's Link to Image Extension <artanis.00@gmail.com>
  * 				Includes QRcode Perl CGI & PHP scripts ver. 0.50 [http://www.swetake.com/qr/qr_cgi_e.html]
  */
-class QRImage implements Extension {
-	var $theme;
-
-	public function receive_event(Event $event) {
-		global $config, $database, $page, $user;
-		if(is_null($this->theme)) $this->theme = get_theme_object($this);
-			if(($event instanceof DisplayingImageEvent)) {
-				$this->theme->links_block($page, $this->data($event->image));
-			}
-		
-	}
-
-	private function hostify($str) {
-		$str = str_replace(" ", "%20", $str);
-		if(strpos($str, "ttp://") > 0) {
-			return $str;
-		}
-		else {
-			return "http://" . $_SERVER["HTTP_HOST"] . $str;
-		}
-	}
-	
-	private function data($image) {
-		global $config;
-		$i_image_id = int_escape($image->id);
-		return array(
-			'image_src'	=> $this->hostify('/image/'.$i_image_id));
+class QRImage extends SimpleExtension {
+	public function onDisplayingImage($event) {
+		$this->theme->links_block(make_http(make_link('image/'.$event->image->id)));
 	}
 }
-add_event_listener(new QRImage());
 ?>
diff --git a/contrib/qr_code/theme.php b/contrib/qr_code/theme.php
index c9428e09..7dbd2eb1 100644
--- a/contrib/qr_code/theme.php
+++ b/contrib/qr_code/theme.php
@@ -1,12 +1,10 @@
 <?php
 class QRImageTheme extends Themelet {
-	public function links_block(Page $page, $data) {
-		$image_src = $data['image_src'];
-		global $config, $user;
-		$base_href = $config->get_string('base_href');
-		$data_href = get_base_href();
+	public function links_block($link) {
+		global $page;
+		$base_href = get_base_href();
 		$page->add_block( new Block(
-			"QR Code","<img src='".$data_href."/ext/qr_code/qr_img.php?d=".$image_src."&s=3' />","left",50));
+			"QR Code","<img src='$base_href/ext/qr_code/qr_img.php?d=$link&s=3' />","left",50));
 	}
 }
 ?>