Index: /gs2-extensions/afrepo/trunk/src/src/AFRepo.GSDLEXT.class.php.in
===================================================================
--- /gs2-extensions/afrepo/trunk/src/src/AFRepo.GSDLEXT.class.php.in	(revision 27316)
+++ /gs2-extensions/afrepo/trunk/src/src/AFRepo.GSDLEXT.class.php.in	(revision 27317)
@@ -6,5 +6,5 @@
  * 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 
+ * The audio is expected to be in subdirectories of the 'audio-files' directory, and 
  * for example purposes can be named in such a way that the example 
  * PathClassifier classifier can get meanining from it.
@@ -13,4 +13,10 @@
 class AFRepo extends AFRepoBase {
 	private $allfiles;
+
+	public function AFRepo() 
+	{
+	  $this->audio_files_dir = "audio-files";
+	  $this->af_prefix = getcwd() . "/" . $this->audio_files_dir;
+	}
 
 	public function getName() {
@@ -36,10 +42,172 @@
 	}
 
-	public function getAllFiles() {
+	/**
+	 * getAudioPath
+	 * Return the path to the audio links in this repository (without a trailing 
+	 * slash)
+	 */
+	public function getAudioPath() {
+		return realpath("audio-ids");
+	}
+
+
+	protected function remove_audio_files_prefix($full_filepath) {
+#	  echo "full filepath = " . $full_filepath . "\n";
+#	  echo "af prefix = " . $this->af_prefix . "\n";
+
+	  $af_prefix_len = strlen($this->af_prefix);
+	  $filepath = $full_filepath; 
+
+	  if (substr($filepath, 0, $af_prefix_len) == $this->af_prefix) {
+	    $filepath = substr($filepath, $af_prefix_len);
+	  } 
+
+#	  echo "** filepath = " . $filepath . "\n";
+
+	  return $filepath;
+	}
+
+
+	/**
+	 * fileInRepo
+	 * Return true if the audiofile with the given path (canonical or symlink) 
+	 * is in the repository or false if not
+	 */
+	public function fileInRepo($full_filepath) {
+	  $realpath = realpath($full_filepath);
+	  if ($realpath === false) {
+	    trigger_error("file '$filepath' does not exist on disk or is a broken symlink", E_USER_WARNING);
+	    return false;
+	  }
+
+	  return array_key_exists($full_filepath, $this->getAllFiles());
+	}
+
+
+	/**
+	 * filePathToId
+	 * Return the ID of the audiofile with the given path (which can be 
+	 * canonical or a symlink)
+	 */
+	public function filePathToId($full_filepath) {
+	  if (!$this->fileInRepo($full_filepath)) {
+	    throw new Exception("file with path '$filepath' is not in the repository");
+	  }
+
+	  $hash_filepath = "salami:/" . $this->remove_audio_files_prefix($full_filepath);
+
+##	  echo "Hashing on: " . $hash_filepath . "\n";
+
+	  $id = md5($hash_filepath);
+	  return $id;
+	}
+
+
+
+	// recursive method to delete things from the links directory according to the 
+	// options
+	function getAllCollectionFilesRec($collection, $path) {
+
+	  echo "Processing directory: " . $path . "\n";
+
+	  $dir = dir($path);
+
+	  while (($entry = $dir->read()) !== false) {
+
+	    if ($entry == "." || $entry == "..") {
+	      continue;
+	    }
+
+	    $fullpath = $path . "/" . $entry;
+
+	    $isdir = false;
+	    if (is_link($fullpath)) {
+
+	      $realpath = readlink($fullpath);
+
+	      // follow potential chain of sym-links
+	      while (is_link($realpath)) {
+		$realpath = readlink($realpath);
+	      }
+
+	      $isdir = is_dir($realpath);
+	    }
+	    else {
+	      $isdir = is_dir($fullpath);
+	    }
+
+
+	    if ($isdir) {
+
+	      $this->getAllCollectionFilesRec($collection,$fullpath);
+	    } 
+	    else {
+	      // assume it is a file
+##	      echo "Adding file: " . $fullpath . "\n";
+	      $this->allfiles[$fullpath] = true;
+	    }
+	  }
+
+	  $dir->close();
+	  
+	}
+	
+	
+	public function getAllFiles() 
+	{
+	  if (!is_null($this->allfiles)) {
+	    return $this->allfiles;
+	  }
+	  
+	  $this->allfiles = array();
+
+##	  $path = realpath($this->audio_files_dir);	  
+	  $path = $this->af_prefix;
+	  $dir  = dir($path);
+	  
+	  while (($file = $dir->read()) !== false) {
+
+	    if ($file[0] == ".") {
+	      // skip all dot files and dirs
+	      continue;
+	    }
+
+	    $fullpath = $path . "/" . $file;
+
+	    $isdir = false;
+	    if (is_link($fullpath)) {
+
+	      $realpath = readlink($fullpath);
+
+	      // follow potential chain of sym-links
+	      while (is_link($realpath)) {
+		$realpath = readlink($realpath);
+	      }
+
+	      $isdir = is_dir($realpath);
+	    }
+	    else {
+	      $isdir = is_dir($fullpath);
+	    }
+
+	    if ($isdir) {
+
+	      // recursively work through each collection directory
+	      $this->getAllCollectionFilesRec($file, $fullpath);
+	    }
+	  }
+
+	  $dir->close();
+	  
+	  return $this->allfiles;
+	}
+
+
+	public function getAllFilesOLD() {
 		if (!is_null($this->allfiles))
 			return $this->allfiles;
 
 		$this->allfiles = array();
-		$path = realpath("import-mp3");
+		$path = realpath("audio-files");
 		$dir = dir($path);
 		while (($file = $dir->read()) !== false) {
Index: /gs2-extensions/afrepo/trunk/src/src/CASCADE-MAKE.sh
===================================================================
--- /gs2-extensions/afrepo/trunk/src/src/CASCADE-MAKE.sh	(revision 27316)
+++ /gs2-extensions/afrepo/trunk/src/src/CASCADE-MAKE.sh	(revision 27317)
@@ -36,33 +36,6 @@
 
 echo ""
-echo "What about Override apache settings ?????"
-echo "****** Test to see if 'audiofiles' exists => generate message if not? ==> auto run cmd ???"
+echo "****** Test to see if 'audio-files' exists => generate message if not? ==> auto run cmd ???"
 
+./INSTALL-PHP.sh
 
-protocol=http
-hostname=`hostname`
-port=`egrep "^Listen" $GEXTAMP_INSTALLED/conf/httpd.conf | awk '{print $2}'`
-
-f4store_port=`echo $port+1 | bc`
-
-has_afrepo_conf=`egrep "^Include conf/httpd-afrepo.conf" "$GEXTAMP_INSTALLED/conf/httpd.conf"`
-
-if [ "x$has_afrepo_conf" = "x" ] ; then
-  # Not currently in file => append it
-
-  echo "Include conf/httpd-afrepo.conf" >> "$GEXTAMP_INSTALLED/conf/httpd.conf"
-fi
-
-cat "httpd-afrepo.conf.in" \
-  | sed "s%@4store-http-prefix@%$protocol://$hostname:$f4store_port%g" > "$GEXTAMP_INSTALLED/conf/httpd-afrepo.conf"
-
-
-cat "AFRepo.GSDLEXT.class.php.in" \
-  | sed "s%@afrepo-http-prefix@%$protocol://$hostname:$port%g" \
-  | sed "s%@4store-http-prefix@%$protocol://$hostname:$f4store_port%g" > "$GEXTAMP_INSTALLED/htdocs/afrepo/AFRepo.class.php"
-
-cat DONE.txt \
-  | sed "s%@GEXTAMP_INSTALLED@%$GEXTAMP_INSTALLED%g" \
-  | sed "s%@4store-port@%$f4store_port%g" \
-  | sed "s%@afrepo-http-prefix@%$protocol://$hostname:$port%g" 
-
Index: /gs2-extensions/afrepo/trunk/src/src/INSTALL-PHP.sh
===================================================================
--- /gs2-extensions/afrepo/trunk/src/src/INSTALL-PHP.sh	(revision 27317)
+++ /gs2-extensions/afrepo/trunk/src/src/INSTALL-PHP.sh	(revision 27317)
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+
+# Edit the following two lines as appropriate
+protocol=http
+hostname=`hostname`
+
+port=`egrep "^Listen" $GEXTAMP_INSTALLED/conf/httpd.conf | awk '{print $2}'`
+
+f4store_port=`echo $port+1 | bc`
+
+has_afrepo_conf=`egrep "^Include conf/httpd-afrepo.conf" "$GEXTAMP_INSTALLED/conf/httpd.conf"`
+
+if [ "x$has_afrepo_conf" = "x" ] ; then
+  # Not currently in file => append it
+
+  echo ""
+  echo "** Appending 'httpd-afrepo.conf' to main Apache config file"
+  echo "Include conf/httpd-afrepo.conf" >> "$GEXTAMP_INSTALLED/conf/httpd.conf"
+fi
+
+cat "httpd-afrepo.conf.in" \
+  | sed "s%@4store-http-prefix@%$protocol://$hostname:$f4store_port%g" > "$GEXTAMP_INSTALLED/conf/httpd-afrepo.conf"
+
+
+echo ""
+echo "** Regenerating AFRepo.class.php"
+cat "AFRepo.GSDLEXT.class.php.in" \
+  | sed "s%@afrepo-http-prefix@%$protocol://$hostname:$port%g" \
+  | sed "s%@4store-http-prefix@%$protocol://$hostname:$f4store_port%g" > "$GEXTAMP_INSTALLED/htdocs/afrepo/AFRepo.class.php"
+
+
+cat DONE.txt \
+  | sed "s%@GEXTAMP_INSTALLED@%$GEXTAMP_INSTALLED%g" \
+  | sed "s%@4store-port@%$f4store_port%g" \
+  | sed "s%@afrepo-http-prefix@%$protocol://$hostname:$port%g" 
+
