Utilities::bookPath PHP Method

bookPath() static public method

Works around a strange feature of Calibre where middle components of names are capitalized, eg "Aliette de Bodard" -> "Aliette De Bodard". The directory name uses the capitalized form, the book path stored in the DB uses the original form.
static public bookPath ( string $cd, string $bp, string $file ) : string
$cd string Calibre library directory
$bp string book path, as stored in the DB
$file string file name
return string the filesystem path to the book file
    static function bookPath($cd, $bp, $file)
    {
        try {
            $path = $cd . '/' . $bp . '/' . $file;
            stat($path);
        } catch (Exception $e) {
            $p = explode("/", $bp);
            $path = $cd . '/' . ucwords($p[0]) . '/' . $p[1] . '/' . $file;
        }
        return $path;
    }

Usage Example

Exemplo n.º 1
0
 function testBookPath()
 {
     $this->assertEqual('tests/fixtures/lib2/Gotthold Ephraim Lessing/Lob der Faulheit (1)/Lob der Faulheit - Gotthold Ephraim Lessing.epub', Utilities::bookPath('tests/fixtures/lib2', 'Gotthold Ephraim Lessing/Lob der Faulheit (1)', 'Lob der Faulheit - Gotthold Ephraim Lessing.epub'));
 }
All Usage Examples Of Utilities::bookPath