Skip to content

Commit

Permalink
Add v0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
seblucas committed May 28, 2012
1 parent 7a80f18 commit ec2bf99
Show file tree
Hide file tree
Showing 17 changed files with 249 additions and 45 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
0.0.4 - 20120523
* More code refactoring to simplify code.
* Changed OPDS Page id to match Calibre2Opds
* Add icons to author, serie, tags and recent items (there is config item to disable it)
* Fixed author URL
* Added publishing date (works on Mantano)
* Added Tags support

0.0.3 - 20120507
* Fixed many things blocking opensearch from working
* There was a bug introduced in 0.0.2
Expand Down
18 changes: 14 additions & 4 deletions OPDS_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function getOpenSearch () {
return $xml->outputMemory(true);
}

private function startXmlDocument ($title) {
private function startXmlDocument ($title, $idPage) {
self::getXmlStream ()->startDocument('1.0','UTF-8');
self::getXmlStream ()->startElement ("feed");
self::getXmlStream ()->writeAttribute ("xmlns", "http://www.w3.org/2005/Atom");
Expand All @@ -80,7 +80,14 @@ private function startXmlDocument ($title) {
self::getXmlStream ()->text ($title);
self::getXmlStream ()->endElement ();
self::getXmlStream ()->startElement ("id");
self::getXmlStream ()->text ($_SERVER['REQUEST_URI']);
if ($idPage)
{
self::getXmlStream ()->text ($idPage);
}
else
{
self::getXmlStream ()->text ($_SERVER['REQUEST_URI']);
}
self::getXmlStream ()->endElement ();
self::getXmlStream ()->startElement ("updated");
self::getXmlStream ()->text (self::getUpdatedTime ());
Expand Down Expand Up @@ -159,7 +166,7 @@ private function renderEntry ($entry) {
self::getXmlStream ()->text ($author->name);
self::getXmlStream ()->endElement ();
self::getXmlStream ()->startElement ("uri");
self::getXmlStream ()->text ($author->getUri ());
self::getXmlStream ()->text ("feed.php" . $author->getUri ());
self::getXmlStream ()->endElement ();
self::getXmlStream ()->endElement ();
}
Expand All @@ -173,12 +180,15 @@ private function renderEntry ($entry) {
self::getXmlStream ()->startElement ("dcterms:issued");
self::getXmlStream ()->text (date ("Y-m-d", $entry->book->pubdate));
self::getXmlStream ()->endElement ();
self::getXmlStream ()->startElement ("published");
self::getXmlStream ()->text (date ("Y-m-d", $entry->book->pubdate) . "T08:08:08Z");
self::getXmlStream ()->endElement ();
}

}

public function render ($page) {
self::startXmlDocument ($page->title);
self::startXmlDocument ($page->title, $page->idPage);
if ($page->query)
{
self::getXmlStream ()->startElement ("opensearch:totalResults");
Expand Down
4 changes: 2 additions & 2 deletions author.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public static function getAllAuthors() {
return $entryArray;
}

public static function getAuthorName ($authorId) {
public static function getAuthorById ($authorId) {
$result = parent::getDb ()->prepare('select sort from authors where id = ?');
$result->execute (array ($authorId));
return $result->fetchColumn ();
return new Author ($authorId, $result->fetchColumn ());
}

public static function getAuthorByBookId ($bookId) {
Expand Down
88 changes: 80 additions & 8 deletions base.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ function getURLParam ($name, $default = NULL) {

class Link
{
const OPDS_THUMBNAIL_TYPE = "http://opds-spec.org/image/thumbnail";
const OPDS_IMAGE_TYPE = "http://opds-spec.org/image";
const OPDS_ACQUISITION_TYPE = "http://opds-spec.org/acquisition";
const OPDS_NAVIGATION_TYPE = "application/atom+xml;profile=opds-catalog;kind=navigation";

public $href;
public $type;
public $rel;
Expand All @@ -34,10 +39,8 @@ public function hrefXhtml () {

class LinkNavigation extends Link
{
const OPDS_NAVIGATION_TYPE = "application/atom+xml;profile=opds-catalog;kind=navigation";

public function __construct($phref, $prel = NULL, $ptitle = NULL) {
parent::__construct ($phref, self::OPDS_NAVIGATION_TYPE, $prel, $ptitle);
parent::__construct ($phref, Link::OPDS_NAVIGATION_TYPE, $prel, $ptitle);
$this->href = $_SERVER["SCRIPT_NAME"] . $this->href;
}
}
Expand All @@ -53,6 +56,15 @@ class Entry
public $localUpdated;
private static $updated = NULL;

public static $icons = array(
Author::ALL_AUTHORS_ID => 'images/author.png',
Serie::ALL_SERIES_ID => 'images/serie.png',
Book::ALL_RECENT_BOOKS_ID => 'images/recent.png',
Tag::ALL_TAGS_ID => 'images/tag.png',
"calibre:books$" => 'images/allbook.png',
"calibre:books:letter" => 'images/allbook.png'
);

public function getUpdatedTime () {
if (!is_null ($this->localUpdated)) {
return date (DATE_ATOM, $this->localUpdated);
Expand All @@ -64,11 +76,23 @@ public function getUpdatedTime () {
}

public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray) {
global $config;
$this->title = $ptitle;
$this->id = $pid;
$this->content = $pcontent;
$this->contentType = $pcontentType;
$this->linkArray = $plinkArray;

if ($config['cops_show_icons'] == 1)
{
foreach (self::$icons as $reg => $image)
{
if (preg_match ("/" . $reg . "/", $pid)) {
array_push ($this->linkArray, new Link ($image, "image/png", Link::OPDS_THUMBNAIL_TYPE));
break;
}
}
}
}
}

Expand All @@ -84,7 +108,15 @@ public function __construct($ptitle, $pid, $pcontent, $pcontentType, $plinkArray

public function getCoverThumbnail () {
foreach ($this->linkArray as $link) {
if ($link->rel == "http://opds-spec.org/image/thumbnail")
if ($link->rel == Link::OPDS_THUMBNAIL_TYPE)
return $link->hrefXhtml ();
}
return null;
}

public function getCover () {
foreach ($this->linkArray as $link) {
if ($link->rel == Link::OPDS_IMAGE_TYPE)
return $link->hrefXhtml ();
}
return null;
Expand All @@ -106,6 +138,10 @@ public static function getPage ($pageId, $id, $query)
return new PageAllAuthors ($id, $query);
case Base::PAGE_AUTHOR_DETAIL :
return new PageAuthorDetail ($id, $query);
case Base::PAGE_ALL_TAGS :
return new PageAllTags ($id, $query);
case Base::PAGE_TAG_DETAIL :
return new PageTagDetail ($id, $query);
case Base::PAGE_ALL_SERIES :
return new PageAllSeries ($id, $query);
case Base::PAGE_ALL_BOOKS :
Expand All @@ -120,7 +156,9 @@ public static function getPage ($pageId, $id, $query)
return new PageQueryResult ($id, $query);
break;
default:
return new Page ($id, $query);
$page = new Page ($id, $query);
$page->idPage = "cops:catalog";
return $page;
}
}

Expand All @@ -135,6 +173,7 @@ public function InitializeContent ()
$this->title = $config['cops_title_default'];
array_push ($this->entryArray, Author::getCount());
array_push ($this->entryArray, Serie::getCount());
array_push ($this->entryArray, Tag::getCount());
$this->entryArray = array_merge ($this->entryArray, Book::getCount());
}

Expand All @@ -146,33 +185,60 @@ public function InitializeContent ()
{
$this->title = "All authors";
$this->entryArray = Author::getAllAuthors();
$this->idPage = Author::ALL_AUTHORS_ID;
}
}

class PageAuthorDetail extends Page
{
public function InitializeContent ()
{
$this->title = Author::getAuthorName ($this->idGet);
$author = Author::getAuthorById ($this->idGet);
$this->idPage = $author->getEntryId ();
$this->title = $author->name;
$this->entryArray = Book::getBooksByAuthor ($this->idGet);
}
}

class PageAllTags extends Page
{
public function InitializeContent ()
{
$this->title = "All tags";
$this->entryArray = Tag::getAllTags();
$this->idPage = Tag::ALL_TAGS_ID;
}
}

class PageTagDetail extends Page
{
public function InitializeContent ()
{
$tag = Tag::getTagById ($this->idGet);
$this->idPage = $tag->getEntryId ();
$this->title = $tag->name;
$this->entryArray = Book::getBooksByTag ($this->idGet);
}
}

class PageAllSeries extends Page
{
public function InitializeContent ()
{
$this->title = "All series";
$this->entryArray = Serie::getAllSeries();
$this->idPage = Serie::ALL_SERIES_ID;
}
}

class PageSerieDetail extends Page
{
public function InitializeContent ()
{
$this->title = "Series : " . Serie::getSerieById ($this->idGet)->name;
$serie = Serie::getSerieById ($this->idGet);
$this->title = "Series : " . $serie->name;
$this->entryArray = Book::getBooksBySeries ($this->idGet);
$this->idPage = $serie->getEntryId ();
}
}

Expand All @@ -182,6 +248,7 @@ public function InitializeContent ()
{
$this->title = "All books by starting letter";
$this->entryArray = Book::getAllBooks ();
$this->idPage = Book::ALL_BOOKS_ID;
}
}

Expand All @@ -191,6 +258,7 @@ public function InitializeContent ()
{
$this->title = "All books starting by " . $this->idGet;
$this->entryArray = Book::getBooksByStartingLetter ($this->idGet);
$this->idPage = Book::getEntryIdByLetter ($this->idGet);
}
}

Expand All @@ -200,14 +268,15 @@ public function InitializeContent ()
{
$this->title = "Most recent books";
$this->entryArray = Book::getAllRecentBooks ();
$this->idPage = Book::ALL_RECENT_BOOKS_ID;
}
}

class PageQueryResult extends Page
{
public function InitializeContent ()
{
$this->title = "Search result for query <" . $this->query . ">";
$this->title = "Search result for query *" . $this->query . "*";
$this->entryArray = Book::getBooksByQuery ($this->query);
}
}
Expand All @@ -225,6 +294,9 @@ abstract class Base
const PAGE_OPENSEARCH = "8";
const PAGE_OPENSEARCH_QUERY = "9";
const PAGE_ALL_RECENT_BOOKS = "10";
const PAGE_ALL_TAGS = "11";
const PAGE_TAG_DETAIL = "12";

const COMPATIBILITY_XML_ALDIKO = "aldiko";

private static $db = NULL;
Expand Down
Loading

0 comments on commit ec2bf99

Please sign in to comment.