Index: /gs2-extensions/afrepo/trunk/src/src/AFRepo.GSDLEXT.class.php.in
===================================================================
--- /gs2-extensions/afrepo/trunk/src/src/AFRepo.GSDLEXT.class.php.in	(revision 27290)
+++ /gs2-extensions/afrepo/trunk/src/src/AFRepo.GSDLEXT.class.php.in	(revision 27290)
@@ -0,0 +1,104 @@
+<?php
+
+/**
+ * Bart Nagel <bjn@ecs.soton.ac.uk>
+ *
+ * AFRepo top-level class to slot in with the Greenstone extension framework
+ *
+ * The audio is expected to be in subdirectories of the 'import-mp3' directory, and 
+ * for example purposes can be named in such a way that the example 
+ * PathClassifier classifier can get meanining from it.
+ */
+
+class AFRepo extends AFRepoBase {
+	private $allfiles;
+
+	public function getName() {
+		return "Salami 4Store audio repository";
+	}
+
+	public function getURIPrefix() {
+		return "@afrepo-http-prefix@/afrepo/";
+	}
+
+	/* Done this way, can talk to the 4store server directly
+           rather than relying on proxying through the PHP-based 'afrepo' server */
+	public function getTrippleStoreURIPrefix() {
+		return "@afrepo-http-prefix@/4store/";
+	}
+
+	public function getSparqlEndpoint() {
+		return $this->getTrippleStoreURIPrefix() . "sparql/";
+	}
+
+	public function getDataEndpoint() {
+		return $this->getTrippleStoreURIPrefix() . "data/";
+	}
+
+	public function getAllFiles() {
+		if (!is_null($this->allfiles))
+			return $this->allfiles;
+
+		$this->allfiles = array();
+		$path = realpath("import-mp3");
+		$dir = dir($path);
+		while (($file = $dir->read()) !== false) {
+			if ($file[0] != "." && is_dir($path . "/" . $file)) {
+				$subdir = dir($path . "/" . $file);
+				while (($subfile = $subdir->read()) !== false) {
+					if ($subfile[0] != "." && is_file($path . "/" . $file . "/" . $subfile))
+						$this->allfiles[$path . "/" . $file . "/" . $subfile] = true;
+				}
+				$subdir->close();
+			}
+		}
+		$dir->close();
+
+		return $this->allfiles;
+	}
+
+	public function getSongFiles($id) {
+		$filepath = $this->idToLinkPath($id);
+		$origfilepath = realpath($filepath);
+
+		if ($origfilepath === false)
+			return array();
+
+		// is it a clip?
+		if (preg_match('%\.clip\..{1,4}$%', $origfilepath)) {
+			// does full version exist?
+			$fullpath = preg_replace('%\.clip%', "", $origfilepath);
+			if (file_exists($fullpath))
+				return array($fullpath, $origfilepath);
+			return array($origfilepath);
+		}
+
+		// it's a full song. does clip exist?
+		$clippath = preg_replace('%(\..{1,4})$%', '.clip\1', $origfilepath);
+		if (file_exists($clippath))
+			return array($origfilepath, $clippath);
+		return array($origfilepath);
+	}
+
+	public function haveMetadataPermission() {
+		return true;
+	}
+
+	public function haveAudioPermission() {
+		return ipInRange($_SERVER["REMOTE_ADDR"], "127.0.0.0/8");
+	}
+
+	public function getMBID($id) {
+		$classifiers = array(
+			new TagClassifier(),
+			new EchonestClassifier(),
+			new PathClassifier(),
+		);
+		foreach ($classifiers as $classifier)
+			if ($classifier->available() && $classifier->hasMBID($id))
+				return $classifier->getMBID($id);
+		return null;
+	}
+}
+
+?>
Index: /gs2-extensions/afrepo/trunk/src/src/httpd-afrepo.conf.in
===================================================================
--- /gs2-extensions/afrepo/trunk/src/src/httpd-afrepo.conf.in	(revision 27290)
+++ /gs2-extensions/afrepo/trunk/src/src/httpd-afrepo.conf.in	(revision 27290)
@@ -0,0 +1,30 @@
+
+
+<IfModule php5_module>
+
+	<Location />
+		AddType text/html .php .phps
+		AddHandler application/x-httpd-php .php
+		AddHandler application/x-httpd-php-source .phps
+	</Location>
+
+	<Directory "/afrepo">
+		AllowOverride All
+	</Directory>
+
+</IfModule>
+
+ProxyPass /4store/data @4store-http-prefix@/data
+ProxyPassReverse /4store/data @4store-http-prefix@/data
+
+ProxyPass /4store/sparql @4store-http-prefix@/sparql
+ProxyPassReverse /4store/sparql @4store-http-prefix@/sparql
+
+ProxyPass /4store/test @4store-http-prefix@/test
+ProxyPassReverse /4store/test @4store-http-prefix@/test
+
+ProxyPass /4store/status @4store-http-prefix@/status
+ProxyPassReverse /4store/status @4store-http-prefix@/status
+
+RewriteEngine on
+RewriteRule ^/afrepo/[0-9a-f]{32}_?$ /afrepo/webrequest.php
