* * 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; } } ?>