[27290] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | /**
|
---|
| 4 | * Bart Nagel <[email protected]>
|
---|
| 5 | *
|
---|
| 6 | * AFRepo top-level class to slot in with the Greenstone extension framework
|
---|
| 7 | *
|
---|
| 8 | * The audio is expected to be in subdirectories of the 'import-mp3' directory, and
|
---|
| 9 | * for example purposes can be named in such a way that the example
|
---|
| 10 | * PathClassifier classifier can get meanining from it.
|
---|
| 11 | */
|
---|
| 12 |
|
---|
| 13 | class AFRepo extends AFRepoBase {
|
---|
| 14 | private $allfiles;
|
---|
| 15 |
|
---|
| 16 | public function getName() {
|
---|
| 17 | return "Salami 4Store audio repository";
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | public function getURIPrefix() {
|
---|
| 21 | return "@afrepo-http-prefix@/afrepo/";
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | /* Done this way, can talk to the 4store server directly
|
---|
| 25 | rather than relying on proxying through the PHP-based 'afrepo' server */
|
---|
| 26 | public function getTrippleStoreURIPrefix() {
|
---|
| 27 | return "@afrepo-http-prefix@/4store/";
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | public function getSparqlEndpoint() {
|
---|
| 31 | return $this->getTrippleStoreURIPrefix() . "sparql/";
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | public function getDataEndpoint() {
|
---|
| 35 | return $this->getTrippleStoreURIPrefix() . "data/";
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | public function getAllFiles() {
|
---|
| 39 | if (!is_null($this->allfiles))
|
---|
| 40 | return $this->allfiles;
|
---|
| 41 |
|
---|
| 42 | $this->allfiles = array();
|
---|
| 43 | $path = realpath("import-mp3");
|
---|
| 44 | $dir = dir($path);
|
---|
| 45 | while (($file = $dir->read()) !== false) {
|
---|
| 46 | if ($file[0] != "." && is_dir($path . "/" . $file)) {
|
---|
| 47 | $subdir = dir($path . "/" . $file);
|
---|
| 48 | while (($subfile = $subdir->read()) !== false) {
|
---|
| 49 | if ($subfile[0] != "." && is_file($path . "/" . $file . "/" . $subfile))
|
---|
| 50 | $this->allfiles[$path . "/" . $file . "/" . $subfile] = true;
|
---|
| 51 | }
|
---|
| 52 | $subdir->close();
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 | $dir->close();
|
---|
| 56 |
|
---|
| 57 | return $this->allfiles;
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | public function getSongFiles($id) {
|
---|
| 61 | $filepath = $this->idToLinkPath($id);
|
---|
| 62 | $origfilepath = realpath($filepath);
|
---|
| 63 |
|
---|
| 64 | if ($origfilepath === false)
|
---|
| 65 | return array();
|
---|
| 66 |
|
---|
| 67 | // is it a clip?
|
---|
| 68 | if (preg_match('%\.clip\..{1,4}$%', $origfilepath)) {
|
---|
| 69 | // does full version exist?
|
---|
| 70 | $fullpath = preg_replace('%\.clip%', "", $origfilepath);
|
---|
| 71 | if (file_exists($fullpath))
|
---|
| 72 | return array($fullpath, $origfilepath);
|
---|
| 73 | return array($origfilepath);
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | // it's a full song. does clip exist?
|
---|
| 77 | $clippath = preg_replace('%(\..{1,4})$%', '.clip\1', $origfilepath);
|
---|
| 78 | if (file_exists($clippath))
|
---|
| 79 | return array($origfilepath, $clippath);
|
---|
| 80 | return array($origfilepath);
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | public function haveMetadataPermission() {
|
---|
| 84 | return true;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | public function haveAudioPermission() {
|
---|
| 88 | return ipInRange($_SERVER["REMOTE_ADDR"], "127.0.0.0/8");
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | public function getMBID($id) {
|
---|
| 92 | $classifiers = array(
|
---|
| 93 | new TagClassifier(),
|
---|
| 94 | new EchonestClassifier(),
|
---|
| 95 | new PathClassifier(),
|
---|
| 96 | );
|
---|
| 97 | foreach ($classifiers as $classifier)
|
---|
| 98 | if ($classifier->available() && $classifier->hasMBID($id))
|
---|
| 99 | return $classifier->getMBID($id);
|
---|
| 100 | return null;
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | ?>
|
---|