Remove trailing spaces

This commit is contained in:
Sébastien Lucas 2013-12-05 10:52:51 +01:00
parent 9f5f00e114
commit 0f09ef5f8c
21 changed files with 478 additions and 478 deletions

View file

@ -10,40 +10,40 @@ require_once('base.php');
class Author extends Base { class Author extends Base {
const ALL_AUTHORS_ID = "cops:authors"; const ALL_AUTHORS_ID = "cops:authors";
const AUTHOR_COLUMNS = "authors.id as id, authors.name as name, authors.sort as sort, count(*) as count"; const AUTHOR_COLUMNS = "authors.id as id, authors.name as name, authors.sort as sort, count(*) as count";
const SQL_AUTHORS_BY_FIRST_LETTER = "select {0} from authors, books_authors_link where author = authors.id and upper (authors.sort) like ? group by authors.id, authors.name, authors.sort order by sort"; const SQL_AUTHORS_BY_FIRST_LETTER = "select {0} from authors, books_authors_link where author = authors.id and upper (authors.sort) like ? group by authors.id, authors.name, authors.sort order by sort";
const SQL_ALL_AUTHORS = "select {0} from authors, books_authors_link where author = authors.id group by authors.id, authors.name, authors.sort order by sort"; const SQL_ALL_AUTHORS = "select {0} from authors, books_authors_link where author = authors.id group by authors.id, authors.name, authors.sort order by sort";
public $id; public $id;
public $name; public $name;
public $sort; public $sort;
public function __construct($pid, $pname) { public function __construct($pid, $pname) {
$this->id = $pid; $this->id = $pid;
$this->name = $pname; $this->name = $pname;
} }
public function getUri () { public function getUri () {
return "?page=".parent::PAGE_AUTHOR_DETAIL."&id=$this->id"; return "?page=".parent::PAGE_AUTHOR_DETAIL."&id=$this->id";
} }
public function getEntryId () { public function getEntryId () {
return self::ALL_AUTHORS_ID.":".$this->id; return self::ALL_AUTHORS_ID.":".$this->id;
} }
public static function getEntryIdByLetter ($startingLetter) { public static function getEntryIdByLetter ($startingLetter) {
return self::ALL_AUTHORS_ID.":letter:".$startingLetter; return self::ALL_AUTHORS_ID.":letter:".$startingLetter;
} }
public static function getCount() { public static function getCount() {
$nAuthors = parent::getDb ()->query('select count(*) from authors')->fetchColumn(); $nAuthors = parent::getDb ()->query('select count(*) from authors')->fetchColumn();
$entry = new Entry (localize("authors.title"), self::ALL_AUTHORS_ID, $entry = new Entry (localize("authors.title"), self::ALL_AUTHORS_ID,
str_format (localize("authors.alphabetical", $nAuthors), $nAuthors), "text", str_format (localize("authors.alphabetical", $nAuthors), $nAuthors), "text",
array ( new LinkNavigation ("?page=".parent::PAGE_ALL_AUTHORS))); array ( new LinkNavigation ("?page=".parent::PAGE_ALL_AUTHORS)));
return $entry; return $entry;
} }
public static function getAllAuthorsByFirstLetter() { public static function getAllAuthorsByFirstLetter() {
$result = parent::getDb ()->query('select substr (upper (sort), 1, 1) as title, count(*) as count $result = parent::getDb ()->query('select substr (upper (sort), 1, 1) as title, count(*) as count
from authors from authors
@ -52,40 +52,40 @@ order by substr (upper (sort), 1, 1)');
$entryArray = array(); $entryArray = array();
while ($post = $result->fetchObject ()) while ($post = $result->fetchObject ())
{ {
array_push ($entryArray, new Entry ($post->title, Author::getEntryIdByLetter ($post->title), array_push ($entryArray, new Entry ($post->title, Author::getEntryIdByLetter ($post->title),
str_format (localize("authorword", $post->count), $post->count), "text", str_format (localize("authorword", $post->count), $post->count), "text",
array ( new LinkNavigation ("?page=".parent::PAGE_AUTHORS_FIRST_LETTER."&id=". rawurlencode ($post->title))))); array ( new LinkNavigation ("?page=".parent::PAGE_AUTHORS_FIRST_LETTER."&id=". rawurlencode ($post->title)))));
} }
return $entryArray; return $entryArray;
} }
public static function getAuthorsByStartingLetter($letter) { public static function getAuthorsByStartingLetter($letter) {
return self::getEntryArray (self::SQL_AUTHORS_BY_FIRST_LETTER, array ($letter . "%")); return self::getEntryArray (self::SQL_AUTHORS_BY_FIRST_LETTER, array ($letter . "%"));
} }
public static function getAllAuthors() { public static function getAllAuthors() {
return self::getEntryArray (self::SQL_ALL_AUTHORS, array ()); return self::getEntryArray (self::SQL_ALL_AUTHORS, array ());
} }
public static function getEntryArray ($query, $params) { public static function getEntryArray ($query, $params) {
list ($totalNumber, $result) = parent::executeQuery ($query, self::AUTHOR_COLUMNS, "", $params, -1); list ($totalNumber, $result) = parent::executeQuery ($query, self::AUTHOR_COLUMNS, "", $params, -1);
$entryArray = array(); $entryArray = array();
while ($post = $result->fetchObject ()) while ($post = $result->fetchObject ())
{ {
$author = new Author ($post->id, $post->sort); $author = new Author ($post->id, $post->sort);
array_push ($entryArray, new Entry ($post->sort, $author->getEntryId (), array_push ($entryArray, new Entry ($post->sort, $author->getEntryId (),
str_format (localize("bookword", $post->count), $post->count), "text", str_format (localize("bookword", $post->count), $post->count), "text",
array ( new LinkNavigation ($author->getUri ())))); array ( new LinkNavigation ($author->getUri ()))));
} }
return $entryArray; return $entryArray;
} }
public static function getAuthorById ($authorId) { public static function getAuthorById ($authorId) {
$result = parent::getDb ()->prepare('select sort from authors where id = ?'); $result = parent::getDb ()->prepare('select sort from authors where id = ?');
$result->execute (array ($authorId)); $result->execute (array ($authorId));
return new Author ($authorId, $result->fetchColumn ()); return new Author ($authorId, $result->fetchColumn ());
} }
public static function getAuthorByBookId ($bookId) { public static function getAuthorByBookId ($bookId) {
$result = parent::getDb ()->prepare('select authors.id as id, authors.sort as sort $result = parent::getDb ()->prepare('select authors.id as id, authors.sort as sort
from authors, books_authors_link from authors, books_authors_link

View file

@ -896,7 +896,7 @@ abstract class Base
const COMPATIBILITY_XML_ALDIKO = "aldiko"; const COMPATIBILITY_XML_ALDIKO = "aldiko";
private static $db = NULL; private static $db = NULL;
public static function isMultipleDatabaseEnabled () { public static function isMultipleDatabaseEnabled () {
global $config; global $config;
return is_array ($config['calibre_directory']); return is_array ($config['calibre_directory']);
@ -935,7 +935,7 @@ abstract class Base
public static function getDbFileName ($database = NULL) { public static function getDbFileName ($database = NULL) {
return self::getDbDirectory ($database) .'metadata.db'; return self::getDbDirectory ($database) .'metadata.db';
} }
private static function error () { private static function error () {
header("location: checkconfig.php?err=1"); header("location: checkconfig.php?err=1");
exit(); exit();
@ -962,7 +962,7 @@ abstract class Base
public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) { public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) {
$totalResult = -1; $totalResult = -1;
if (is_null ($numberPerPage)) { if (is_null ($numberPerPage)) {
$numberPerPage = getCurrentOption ("max_item_per_page"); $numberPerPage = getCurrentOption ("max_item_per_page");
} }

170
book.php
View file

@ -17,8 +17,8 @@ require_once('data.php');
require_once('resources/php-epub-meta/epub.php'); require_once('resources/php-epub-meta/epub.php');
// Silly thing because PHP forbid string concatenation in class const // Silly thing because PHP forbid string concatenation in class const
define ('SQL_BOOKS_LEFT_JOIN', "left outer join comments on comments.book = books.id define ('SQL_BOOKS_LEFT_JOIN', "left outer join comments on comments.book = books.id
left outer join books_ratings_link on books_ratings_link.book = books.id left outer join books_ratings_link on books_ratings_link.book = books.id
left outer join ratings on books_ratings_link.rating = ratings.id "); left outer join ratings on books_ratings_link.rating = ratings.id ");
define ('SQL_BOOKS_ALL', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " order by books.sort "); define ('SQL_BOOKS_ALL', "select {0} from books " . SQL_BOOKS_LEFT_JOIN . " order by books.sort ");
define ('SQL_BOOKS_BY_PUBLISHER', "select {0} from books_publishers_link, books " . SQL_BOOKS_LEFT_JOIN . " define ('SQL_BOOKS_BY_PUBLISHER', "select {0} from books_publishers_link, books " . SQL_BOOKS_LEFT_JOIN . "
@ -49,7 +49,7 @@ class Book extends Base {
const ALL_BOOKS_ID = "cops:books"; const ALL_BOOKS_ID = "cops:books";
const ALL_RECENT_BOOKS_ID = "cops:recentbooks"; const ALL_RECENT_BOOKS_ID = "cops:recentbooks";
const BOOK_COLUMNS = "books.id as id, books.title as title, text as comment, path, timestamp, pubdate, series_index, uuid, has_cover, ratings.rating"; const BOOK_COLUMNS = "books.id as id, books.title as title, text as comment, path, timestamp, pubdate, series_index, uuid, has_cover, ratings.rating";
const SQL_BOOKS_LEFT_JOIN = SQL_BOOKS_LEFT_JOIN; const SQL_BOOKS_LEFT_JOIN = SQL_BOOKS_LEFT_JOIN;
const SQL_BOOKS_ALL = SQL_BOOKS_ALL; const SQL_BOOKS_ALL = SQL_BOOKS_ALL;
const SQL_BOOKS_BY_PUBLISHER = SQL_BOOKS_BY_PUBLISHER; const SQL_BOOKS_BY_PUBLISHER = SQL_BOOKS_BY_PUBLISHER;
@ -61,7 +61,7 @@ class Book extends Base {
const SQL_BOOKS_BY_CUSTOM = SQL_BOOKS_BY_CUSTOM; const SQL_BOOKS_BY_CUSTOM = SQL_BOOKS_BY_CUSTOM;
const SQL_BOOKS_QUERY = SQL_BOOKS_QUERY; const SQL_BOOKS_QUERY = SQL_BOOKS_QUERY;
const SQL_BOOKS_RECENT = SQL_BOOKS_RECENT; const SQL_BOOKS_RECENT = SQL_BOOKS_RECENT;
public $id; public $id;
public $title; public $title;
public $timestamp; public $timestamp;
@ -81,7 +81,7 @@ class Book extends Base {
public $languages = NULL; public $languages = NULL;
public $format = array (); public $format = array ();
public function __construct($line) { public function __construct($line) {
$this->id = $line->id; $this->id = $line->id;
$this->title = $line->title; $this->title = $line->title;
@ -99,19 +99,19 @@ class Book extends Base {
} }
$this->rating = $line->rating; $this->rating = $line->rating;
} }
public function getEntryId () { public function getEntryId () {
return self::ALL_BOOKS_UUID.":".$this->uuid; return self::ALL_BOOKS_UUID.":".$this->uuid;
} }
public static function getEntryIdByLetter ($startingLetter) { public static function getEntryIdByLetter ($startingLetter) {
return self::ALL_BOOKS_ID.":letter:".$startingLetter; return self::ALL_BOOKS_ID.":letter:".$startingLetter;
} }
public function getUri () { public function getUri () {
return "?page=".parent::PAGE_BOOK_DETAIL."&id=$this->id"; return "?page=".parent::PAGE_BOOK_DETAIL."&id=$this->id";
} }
public function getContentArray () { public function getContentArray () {
global $config; global $config;
$i = 0; $i = 0;
@ -146,7 +146,7 @@ class Book extends Base {
$link = new LinkNavigation ($serie->getUri ()); $link = new LinkNavigation ($serie->getUri ());
$su = $link->hrefXhtml (); $su = $link->hrefXhtml ();
} }
return array ("id" => $this->id, return array ("id" => $this->id,
"hasCover" => $this->hasCover, "hasCover" => $this->hasCover,
"preferedData" => $preferedData, "preferedData" => $preferedData,
@ -160,13 +160,13 @@ class Book extends Base {
"seriesName" => $sn, "seriesName" => $sn,
"seriesIndex" => $this->seriesIndex, "seriesIndex" => $this->seriesIndex,
"seriesCompleteName" => $scn, "seriesCompleteName" => $scn,
"seriesurl" => $su); "seriesurl" => $su);
} }
public function getFullContentArray () { public function getFullContentArray () {
global $config; global $config;
$out = $this->getContentArray (); $out = $this->getContentArray ();
$out ["coverurl"] = Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", NULL)->hrefXhtml (); $out ["coverurl"] = Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", NULL)->hrefXhtml ();
$out ["thumbnailurl"] = Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", NULL, NULL, $config['cops_html_thumbnail_height'] * 2)->hrefXhtml (); $out ["thumbnailurl"] = Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", NULL, NULL, $config['cops_html_thumbnail_height'] * 2)->hrefXhtml ();
$out ["content"] = $this->getComment (false); $out ["content"] = $this->getComment (false);
@ -192,47 +192,47 @@ class Book extends Base {
; ;
return $out; return $out;
} }
public function getDetailUrl ($permalink = false) { public function getDetailUrl ($permalink = false) {
$urlParam = $this->getUri (); $urlParam = $this->getUri ();
if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB)); if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB));
return 'index.php' . $urlParam; return 'index.php' . $urlParam;
} }
public function getTitle () { public function getTitle () {
return $this->title; return $this->title;
} }
public function getAuthors () { public function getAuthors () {
if (is_null ($this->authors)) { if (is_null ($this->authors)) {
$this->authors = Author::getAuthorByBookId ($this->id); $this->authors = Author::getAuthorByBookId ($this->id);
} }
return $this->authors; return $this->authors;
} }
public static function getFilterString () { public static function getFilterString () {
$filter = getURLParam ("tag", NULL); $filter = getURLParam ("tag", NULL);
if (empty ($filter)) return ""; if (empty ($filter)) return "";
$exists = true; $exists = true;
if (preg_match ("/^!(.*)$/", $filter, $matches)) { if (preg_match ("/^!(.*)$/", $filter, $matches)) {
$exists = false; $exists = false;
$filter = $matches[1]; $filter = $matches[1];
} }
$result = "exists (select null from books_tags_link, tags where books_tags_link.book = books.id and books_tags_link.tag = tags.id and tags.name = '" . $filter . "')"; $result = "exists (select null from books_tags_link, tags where books_tags_link.book = books.id and books_tags_link.tag = tags.id and tags.name = '" . $filter . "')";
if (!$exists) { if (!$exists) {
$result = "not " . $result; $result = "not " . $result;
} }
return "and " . $result; return "and " . $result;
} }
public function getAuthorsName () { public function getAuthorsName () {
return implode (", ", array_map (function ($author) { return $author->name; }, $this->getAuthors ())); return implode (", ", array_map (function ($author) { return $author->name; }, $this->getAuthors ()));
} }
public function getPublisher () { public function getPublisher () {
if (is_null ($this->publisher)) { if (is_null ($this->publisher)) {
$this->publisher = Publisher::getPublisherByBookId ($this->id); $this->publisher = Publisher::getPublisherByBookId ($this->id);
@ -246,7 +246,7 @@ class Book extends Base {
} }
return $this->serie; return $this->serie;
} }
public function getLanguages () { public function getLanguages () {
$lang = array (); $lang = array ();
$result = parent::getDb ()->prepare('select languages.lang_code $result = parent::getDb ()->prepare('select languages.lang_code
@ -261,11 +261,11 @@ class Book extends Base {
} }
return implode (", ", $lang); return implode (", ", $lang);
} }
public function getTags () { public function getTags () {
if (is_null ($this->tags)) { if (is_null ($this->tags)) {
$this->tags = array (); $this->tags = array ();
$result = parent::getDb ()->prepare('select tags.id as id, name $result = parent::getDb ()->prepare('select tags.id as id, name
from books_tags_link, tags from books_tags_link, tags
where tag = tags.id where tag = tags.id
@ -279,16 +279,16 @@ class Book extends Base {
} }
return $this->tags; return $this->tags;
} }
public function getDatas () public function getDatas ()
{ {
if (is_null ($this->datas)) { if (is_null ($this->datas)) {
$this->datas = array (); $this->datas = array ();
$result = parent::getDb ()->prepare('select id, format, name $result = parent::getDb ()->prepare('select id, format, name
from data where book = ?'); from data where book = ?');
$result->execute (array ($this->id)); $result->execute (array ($this->id));
while ($post = $result->fetchObject ()) while ($post = $result->fetchObject ())
{ {
array_push ($this->datas, new Data ($post, $this)); array_push ($this->datas, new Data ($post, $this));
@ -296,7 +296,7 @@ class Book extends Base {
} }
return $this->datas; return $this->datas;
} }
public function GetMostInterestingDataToSendToKindle () public function GetMostInterestingDataToSendToKindle ()
{ {
$bestFormatForKindle = array ("EPUB", "PDF", "MOBI"); $bestFormatForKindle = array ("EPUB", "PDF", "MOBI");
@ -311,7 +311,7 @@ class Book extends Base {
} }
return $bestData; return $bestData;
} }
public function getDataById ($idData) public function getDataById ($idData)
{ {
foreach ($this->getDatas () as $data) { foreach ($this->getDatas () as $data) {
@ -322,11 +322,11 @@ class Book extends Base {
return NULL; return NULL;
} }
public function getTagsName () { public function getTagsName () {
return implode (", ", array_map (function ($tag) { return $tag->name; }, $this->getTags ())); return implode (", ", array_map (function ($tag) { return $tag->name; }, $this->getTags ()));
} }
public function getRating () { public function getRating () {
if (is_null ($this->rating) || $this->rating == 0) { if (is_null ($this->rating) || $this->rating == 0) {
return ""; return "";
@ -340,7 +340,7 @@ class Book extends Base {
} }
return $retour; return $retour;
} }
public function getPubDate () { public function getPubDate () {
if (is_null ($this->pubdate) || ($this->pubdate <= -58979923200)) { if (is_null ($this->pubdate) || ($this->pubdate <= -58979923200)) {
return ""; return "";
@ -349,7 +349,7 @@ class Book extends Base {
return date ("Y", $this->pubdate); return date ("Y", $this->pubdate);
} }
} }
public function getComment ($withSerie = true) { public function getComment ($withSerie = true) {
$addition = ""; $addition = "";
$se = $this->getSerie (); $se = $this->getSerie ();
@ -365,7 +365,7 @@ class Book extends Base {
return $addition . htmlspecialchars ($this->comment); return $addition . htmlspecialchars ($this->comment);
} }
} }
public function getDataFormat ($format) { public function getDataFormat ($format) {
foreach ($this->getDatas () as $data) foreach ($this->getDatas () as $data)
{ {
@ -376,7 +376,7 @@ class Book extends Base {
} }
return NULL; return NULL;
} }
public function getFilePath ($extension, $idData = NULL, $relative = false) public function getFilePath ($extension, $idData = NULL, $relative = false)
{ {
$file = NULL; $file = NULL;
@ -400,16 +400,16 @@ class Book extends Base {
return $this->path."/".$file; return $this->path."/".$file;
} }
} }
public function getUpdatedEpub ($idData) public function getUpdatedEpub ($idData)
{ {
global $config; global $config;
$data = $this->getDataById ($idData); $data = $this->getDataById ($idData);
try try
{ {
$epub = new EPub ($data->getLocalPath ()); $epub = new EPub ($data->getLocalPath ());
$epub->Title ($this->title); $epub->Title ($this->title);
$authorArray = array (); $authorArray = array ();
foreach ($this->getAuthors() as $author) { foreach ($this->getAuthors() as $author) {
@ -436,18 +436,18 @@ class Book extends Base {
echo "Exception : " . $e->getMessage(); echo "Exception : " . $e->getMessage();
} }
} }
public function getLinkArray () public function getLinkArray ()
{ {
$linkArray = array(); $linkArray = array();
if ($this->hasCover) if ($this->hasCover)
{ {
array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", NULL)); array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_IMAGE_TYPE, "cover.jpg", NULL));
array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", NULL)); array_push ($linkArray, Data::getLink ($this, "jpg", "image/jpeg", Link::OPDS_THUMBNAIL_TYPE, "cover.jpg", NULL));
} }
foreach ($this->getDatas () as $data) foreach ($this->getDatas () as $data)
{ {
if ($data->isKnownType ()) if ($data->isKnownType ())
@ -455,26 +455,26 @@ class Book extends Base {
array_push ($linkArray, $data->getDataLink (Link::OPDS_ACQUISITION_TYPE, $data->format)); array_push ($linkArray, $data->getDataLink (Link::OPDS_ACQUISITION_TYPE, $data->format));
} }
} }
foreach ($this->getAuthors () as $author) { foreach ($this->getAuthors () as $author) {
array_push ($linkArray, new LinkNavigation ($author->getUri (), "related", str_format (localize ("bookentry.author"), localize ("splitByLetter.book.other"), $author->name))); array_push ($linkArray, new LinkNavigation ($author->getUri (), "related", str_format (localize ("bookentry.author"), localize ("splitByLetter.book.other"), $author->name)));
} }
$serie = $this->getSerie (); $serie = $this->getSerie ();
if (!is_null ($serie)) { if (!is_null ($serie)) {
array_push ($linkArray, new LinkNavigation ($serie->getUri (), "related", str_format (localize ("content.series.data"), $this->seriesIndex, $serie->name))); array_push ($linkArray, new LinkNavigation ($serie->getUri (), "related", str_format (localize ("content.series.data"), $this->seriesIndex, $serie->name)));
} }
return $linkArray; return $linkArray;
} }
public function getEntry () { public function getEntry () {
return new EntryBook ($this->getTitle (), $this->getEntryId (), return new EntryBook ($this->getTitle (), $this->getEntryId (),
$this->getComment (), "text/html", $this->getComment (), "text/html",
$this->getLinkArray (), $this); $this->getLinkArray (), $this);
} }
public static function getBookCount($database = NULL) { public static function getBookCount($database = NULL) {
$nBooks = parent::getDb ($database)->query('select count(*) from books')->fetchColumn(); $nBooks = parent::getDb ($database)->query('select count(*) from books')->fetchColumn();
return $nBooks; return $nBooks;
@ -484,21 +484,21 @@ class Book extends Base {
global $config; global $config;
$nBooks = parent::getDb ()->query('select count(*) from books')->fetchColumn(); $nBooks = parent::getDb ()->query('select count(*) from books')->fetchColumn();
$result = array(); $result = array();
$entry = new Entry (localize ("allbooks.title"), $entry = new Entry (localize ("allbooks.title"),
self::ALL_BOOKS_ID, self::ALL_BOOKS_ID,
str_format (localize ("allbooks.alphabetical", $nBooks), $nBooks), "text", str_format (localize ("allbooks.alphabetical", $nBooks), $nBooks), "text",
array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS))); array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS)));
array_push ($result, $entry); array_push ($result, $entry);
if ($config['cops_recentbooks_limit'] > 0) { if ($config['cops_recentbooks_limit'] > 0) {
$entry = new Entry (localize ("recent.title"), $entry = new Entry (localize ("recent.title"),
self::ALL_RECENT_BOOKS_ID, self::ALL_RECENT_BOOKS_ID,
str_format (localize ("recent.list"), $config['cops_recentbooks_limit']), "text", str_format (localize ("recent.list"), $config['cops_recentbooks_limit']), "text",
array ( new LinkNavigation ("?page=".parent::PAGE_ALL_RECENT_BOOKS))); array ( new LinkNavigation ("?page=".parent::PAGE_ALL_RECENT_BOOKS)));
array_push ($result, $entry); array_push ($result, $entry);
} }
return $result; return $result;
} }
public static function getBooksByAuthor($authorId, $n) { public static function getBooksByAuthor($authorId, $n) {
return self::getEntryArray (self::SQL_BOOKS_BY_AUTHOR, array ($authorId), $n); return self::getEntryArray (self::SQL_BOOKS_BY_AUTHOR, array ($authorId), $n);
} }
@ -506,15 +506,15 @@ class Book extends Base {
public static function getBooksByPublisher($publisherId, $n) { public static function getBooksByPublisher($publisherId, $n) {
return self::getEntryArray (self::SQL_BOOKS_BY_PUBLISHER, array ($publisherId), $n); return self::getEntryArray (self::SQL_BOOKS_BY_PUBLISHER, array ($publisherId), $n);
} }
public static function getBooksBySeries($serieId, $n) { public static function getBooksBySeries($serieId, $n) {
return self::getEntryArray (self::SQL_BOOKS_BY_SERIE, array ($serieId), $n); return self::getEntryArray (self::SQL_BOOKS_BY_SERIE, array ($serieId), $n);
} }
public static function getBooksByTag($tagId, $n) { public static function getBooksByTag($tagId, $n) {
return self::getEntryArray (self::SQL_BOOKS_BY_TAG, array ($tagId), $n); return self::getEntryArray (self::SQL_BOOKS_BY_TAG, array ($tagId), $n);
} }
public static function getBooksByLanguage($languageId, $n) { public static function getBooksByLanguage($languageId, $n) {
return self::getEntryArray (self::SQL_BOOKS_BY_LANGUAGE, array ($languageId), $n); return self::getEntryArray (self::SQL_BOOKS_BY_LANGUAGE, array ($languageId), $n);
} }
@ -523,7 +523,7 @@ class Book extends Base {
$query = str_format (self::SQL_BOOKS_BY_CUSTOM, "{0}", "{1}", CustomColumn::getTableLinkName ($customId), CustomColumn::getTableLinkColumn ($customId)); $query = str_format (self::SQL_BOOKS_BY_CUSTOM, "{0}", "{1}", CustomColumn::getTableLinkName ($customId), CustomColumn::getTableLinkColumn ($customId));
return self::getEntryArray ($query, array ($id), $n); return self::getEntryArray ($query, array ($id), $n);
} }
public static function getBookById($bookId) { public static function getBookById($bookId) {
$result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ' $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . '
from books ' . self::SQL_BOOKS_LEFT_JOIN . ' from books ' . self::SQL_BOOKS_LEFT_JOIN . '
@ -536,7 +536,7 @@ where books.id = ?');
} }
return NULL; return NULL;
} }
public static function getBookByDataId($dataId) { public static function getBookByDataId($dataId) {
$result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ', data.name, data.format $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ', data.name, data.format
from data, books ' . self::SQL_BOOKS_LEFT_JOIN . ' from data, books ' . self::SQL_BOOKS_LEFT_JOIN . '
@ -552,7 +552,7 @@ where data.book = books.id and data.id = ?');
} }
return NULL; return NULL;
} }
public static function getBooksByQuery($query, $n, $database = NULL) { public static function getBooksByQuery($query, $n, $database = NULL) {
return self::getEntryArray (self::SQL_BOOKS_QUERY, $query, $n, $database); return self::getEntryArray (self::SQL_BOOKS_QUERY, $query, $n, $database);
} }
@ -570,17 +570,17 @@ order by substr (upper (sort), 1, 1)");
$entryArray = array(); $entryArray = array();
while ($post = $result->fetchObject ()) while ($post = $result->fetchObject ())
{ {
array_push ($entryArray, new Entry ($post->title, Book::getEntryIdByLetter ($post->title), array_push ($entryArray, new Entry ($post->title, Book::getEntryIdByLetter ($post->title),
str_format (localize("bookword", $post->count), $post->count), "text", str_format (localize("bookword", $post->count), $post->count), "text",
array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS_LETTER."&id=". rawurlencode ($post->title))))); array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS_LETTER."&id=". rawurlencode ($post->title)))));
} }
return $entryArray; return $entryArray;
} }
public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) { public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) {
return self::getEntryArray (self::SQL_BOOKS_BY_FIRST_LETTER, array ($letter . "%"), $n, $database, $numberPerPage); return self::getEntryArray (self::SQL_BOOKS_BY_FIRST_LETTER, array ($letter . "%"), $n, $database, $numberPerPage);
} }
public static function getEntryArray ($query, $params, $n, $database = NULL, $numberPerPage = NULL) { public static function getEntryArray ($query, $params, $n, $database = NULL, $numberPerPage = NULL) {
list ($totalNumber, $result) = parent::executeQuery ($query, self::BOOK_COLUMNS, self::getFilterString (), $params, $n, $database, $numberPerPage); list ($totalNumber, $result) = parent::executeQuery ($query, self::BOOK_COLUMNS, self::getFilterString (), $params, $n, $database, $numberPerPage);
$entryArray = array(); $entryArray = array();
@ -592,7 +592,7 @@ order by substr (upper (sort), 1, 1)");
return array ($entryArray, $totalNumber); return array ($entryArray, $totalNumber);
} }
public static function getAllRecentBooks() { public static function getAllRecentBooks() {
global $config; global $config;
$entryArray = self::getEntryArray (self::SQL_BOOKS_RECENT . $config['cops_recentbooks_limit'], array (), -1); $entryArray = self::getEntryArray (self::SQL_BOOKS_RECENT . $config['cops_recentbooks_limit'], array (), -1);
@ -611,11 +611,11 @@ function getJson ($complete = false) {
$qid = getURLParam ("id"); $qid = getURLParam ("id");
$n = getURLParam ("n", "1"); $n = getURLParam ("n", "1");
$database = GetUrlParam (DB); $database = GetUrlParam (DB);
if ($search) { if ($search) {
$out = array (); $out = array ();
$pagequery = Base::PAGE_OPENSEARCH_QUERY; $pagequery = Base::PAGE_OPENSEARCH_QUERY;
// Special case when no databases were chosen, we search on all databases // Special case when no databases were chosen, we search on all databases
if (is_array ($config['calibre_directory']) && $multi === "1") { if (is_array ($config['calibre_directory']) && $multi === "1") {
$i = 0; $i = 0;
@ -632,7 +632,7 @@ function getJson ($complete = false) {
} }
return $out; return $out;
} }
$arrayPublisher = Publisher::getAllPublishersByQuery ($query); $arrayPublisher = Publisher::getAllPublishersByQuery ($query);
$arrayTag = Tag::getAllTagsByQuery ($query, 1, NULL, 5); $arrayTag = Tag::getAllTagsByQuery ($query, 1, NULL, 5);
@ -643,9 +643,9 @@ function getJson ($complete = false) {
$arrayBook = Book::getBooksByStartingLetter ('%' . $query, 1, NULL, 5); $arrayBook = Book::getBooksByStartingLetter ('%' . $query, 1, NULL, 5);
foreach (array ("book" => $arrayBook, foreach (array ("book" => $arrayBook,
"author" => $arrayAuthor, "author" => $arrayAuthor,
"series" => $arraySeries, "series" => $arraySeries,
"tag" => $arrayTag, "tag" => $arrayTag,
"publisher" => $arrayPublisher) as $key => $array) { "publisher" => $arrayPublisher) as $key => $array) {
$i = 0; $i = 0;
@ -678,10 +678,10 @@ function getJson ($complete = false) {
} }
return $out; return $out;
} }
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$out = array ( "title" => $currentPage->title); $out = array ( "title" => $currentPage->title);
$entries = array (); $entries = array ();
foreach ($currentPage->entryArray as $entry) { foreach ($currentPage->entryArray as $entry) {
@ -711,7 +711,7 @@ function getJson ($complete = false) {
$out ["maxPage"] = $currentPage->getMaxPage (); $out ["maxPage"] = $currentPage->getMaxPage ();
$out ["currentPage"] = $currentPage->n; $out ["currentPage"] = $currentPage->n;
} }
if (!is_null (getURLParam ("complete")) || $complete) { if (!is_null (getURLParam ("complete")) || $complete) {
$out ["c"] = array ("version" => VERSION, "i18n" => array ( $out ["c"] = array ("version" => VERSION, "i18n" => array (
"coverAlt" => localize("i18n.coversection"), "coverAlt" => localize("i18n.coversection"),
"authorsTitle" => localize("authors.title"), "authorsTitle" => localize("authors.title"),
@ -754,17 +754,17 @@ function getJson ($complete = false) {
if ($currentPage->containsBook ()) { if ($currentPage->containsBook ()) {
$out ["containsBook"] = 1; $out ["containsBook"] = 1;
} }
$out["abouturl"] = "index.php" . addURLParameter ("?page=16", DB, $database); $out["abouturl"] = "index.php" . addURLParameter ("?page=16", DB, $database);
if ($page == Base::PAGE_ABOUT) { if ($page == Base::PAGE_ABOUT) {
$temp = preg_replace ("/\<h1\>About COPS\<\/h1\>/", "<h1>About COPS " . VERSION . "</h1>", file_get_contents('about.html')); $temp = preg_replace ("/\<h1\>About COPS\<\/h1\>/", "<h1>About COPS " . VERSION . "</h1>", file_get_contents('about.html'));
$out ["fullhtml"] = $temp; $out ["fullhtml"] = $temp;
} }
$out ["homeurl"] = "index.php"; $out ["homeurl"] = "index.php";
if ($page != Base::PAGE_INDEX && !is_null ($database)) $out ["homeurl"] = $out ["homeurl"] . "?" . addURLParameter ("", DB, $database); if ($page != Base::PAGE_INDEX && !is_null ($database)) $out ["homeurl"] = $out ["homeurl"] . "?" . addURLParameter ("", DB, $database);
return $out; return $out;
} }

View file

@ -8,12 +8,12 @@
* @author Sébastien Lucas <sebastien@slucas.fr> * @author Sébastien Lucas <sebastien@slucas.fr>
* *
*/ */
require_once ("config.php"); require_once ("config.php");
require_once ("base.php"); require_once ("base.php");
header ("Content-Type:text/html; charset=UTF-8"); header ("Content-Type:text/html; charset=UTF-8");
$err = getURLParam ("err", -1); $err = getURLParam ("err", -1);
$full = getURLParam ("full"); $full = getURLParam ("full");
$error = NULL; $error = NULL;
@ -51,7 +51,7 @@
<article class="frontpage"> <article class="frontpage">
<h2>Check if GD is properly installed and loaded</h2> <h2>Check if GD is properly installed and loaded</h2>
<h4> <h4>
<?php <?php
if (extension_loaded('gd') && function_exists('gd_info')) { if (extension_loaded('gd') && function_exists('gd_info')) {
echo "OK"; echo "OK";
} else { } else {
@ -63,7 +63,7 @@
<article class="frontpage"> <article class="frontpage">
<h2>Check if Sqlite is properly installed and loaded</h2> <h2>Check if Sqlite is properly installed and loaded</h2>
<h4> <h4>
<?php <?php
if (extension_loaded('pdo_sqlite')) { if (extension_loaded('pdo_sqlite')) {
echo "OK"; echo "OK";
} else { } else {
@ -75,7 +75,7 @@
<article class="frontpage"> <article class="frontpage">
<h2>Check if libxml is properly installed and loaded</h2> <h2>Check if libxml is properly installed and loaded</h2>
<h4> <h4>
<?php <?php
if (extension_loaded('libxml')) { if (extension_loaded('libxml')) {
echo "OK"; echo "OK";
} else { } else {
@ -87,7 +87,7 @@
<article class="frontpage"> <article class="frontpage">
<h2>Check if the rendering will be done on client side or server side</h2> <h2>Check if the rendering will be done on client side or server side</h2>
<h4> <h4>
<?php <?php
if (useServerSideRendering ()) { if (useServerSideRendering ()) {
echo "Server side rendering"; echo "Server side rendering";
} else { } else {
@ -96,9 +96,9 @@
?> ?>
</h4> </h4>
</article> </article>
<?php <?php
$i = 0; $i = 0;
foreach (Base::getDbList () as $name => $database) { foreach (Base::getDbList () as $name => $database) {
?> ?>
<article class="frontpage"> <article class="frontpage">
<h2>Check if Calibre database path is not an URL</h2> <h2>Check if Calibre database path is not an URL</h2>
@ -114,12 +114,12 @@ foreach (Base::getDbList () as $name => $database) {
</article> </article>
<article class="frontpage"> <article class="frontpage">
<h2>Check if Calibre database file exists and is readable</h2> <h2>Check if Calibre database file exists and is readable</h2>
<?php <?php
if (is_readable (Base::getDbFileName ($i))) { if (is_readable (Base::getDbFileName ($i))) {
echo "{$name} OK"; echo "{$name} OK";
} else { } else {
echo "{$name} File " . Base::getDbFileName ($i) . " not found, echo "{$name} File " . Base::getDbFileName ($i) . " not found,
Please check Please check
<ul> <ul>
<li>Value of \$config['calibre_directory'] in config_local.php</li> <li>Value of \$config['calibre_directory'] in config_local.php</li>
<li>Value of <a href='http://php.net/manual/en/ini.core.php#ini.open-basedir'>open_basedir</a> in your php.ini</li> <li>Value of <a href='http://php.net/manual/en/ini.core.php#ini.open-basedir'>open_basedir</a> in your php.ini</li>
@ -133,7 +133,7 @@ Please check
<article class="frontpage"> <article class="frontpage">
<h2>Check if Calibre database file can be opened with PHP</h2> <h2>Check if Calibre database file can be opened with PHP</h2>
<h4> <h4>
<?php <?php
try { try {
$db = new PDO('sqlite:'. Base::getDbFileName ($i)); $db = new PDO('sqlite:'. Base::getDbFileName ($i));
echo "{$name} OK"; echo "{$name} OK";
@ -146,7 +146,7 @@ Please check
<article class="frontpage"> <article class="frontpage">
<h2>Check if Calibre database file contains at least some of the needed tables</h2> <h2>Check if Calibre database file contains at least some of the needed tables</h2>
<h4> <h4>
<?php <?php
try { try {
$db = new PDO('sqlite:'. Base::getDbFileName ($i)); $db = new PDO('sqlite:'. Base::getDbFileName ($i));
$count = $db->query("select count(*) FROM sqlite_master WHERE type='table' AND name in ('books', 'authors', 'tags', 'series')")->fetchColumn(); $count = $db->query("select count(*) FROM sqlite_master WHERE type='table' AND name in ('books', 'authors', 'tags', 'series')")->fetchColumn();
@ -165,7 +165,7 @@ Please check
<article class="frontpage"> <article class="frontpage">
<h2>Check if all Calibre books are found</h2> <h2>Check if all Calibre books are found</h2>
<h4> <h4>
<?php <?php
try { try {
$db = new PDO('sqlite:'. Base::getDbFileName ($i)); $db = new PDO('sqlite:'. Base::getDbFileName ($i));
$result = $db->prepare("select books.path || '/' || data.name || '.' || lower (format) as fullpath from data join books on data.book = books.id"); $result = $db->prepare("select books.path || '/' || data.name || '.' || lower (format) as fullpath from data join books on data.book = books.id");

View file

@ -8,7 +8,7 @@
if (!isset($config)) if (!isset($config))
$config = array(); $config = array();
/* /*
* The directory containing calibre's metadata.db file, with sub-directories * The directory containing calibre's metadata.db file, with sub-directories
* containing all the formats. * containing all the formats.
@ -17,26 +17,26 @@
* $config['calibre_directory'] = array ("My database name" => "/home/directory/calibre1/", "My other database name" => "/home/directory/calibre2/"); * $config['calibre_directory'] = array ("My database name" => "/home/directory/calibre1/", "My other database name" => "/home/directory/calibre2/");
*/ */
$config['calibre_directory'] = './'; $config['calibre_directory'] = './';
/* /*
* SPECIFIC TO NGINX * SPECIFIC TO NGINX
* The internal directory set in nginx config file * The internal directory set in nginx config file
* Leave empty if you don't know what you're doing * Leave empty if you don't know what you're doing
*/ */
$config['calibre_internal_directory'] = ''; $config['calibre_internal_directory'] = '';
/* /*
* Full URL prefix (with trailing /) * Full URL prefix (with trailing /)
* usefull especially for Opensearch where a full URL is often required * usefull especially for Opensearch where a full URL is often required
* For example Mantano, Aldiko and Marvin require it. * For example Mantano, Aldiko and Marvin require it.
*/ */
$config['cops_full_url'] = ''; $config['cops_full_url'] = '';
/* /*
* Number of recent books to show * Number of recent books to show
*/ */
$config['cops_recentbooks_limit'] = '50'; $config['cops_recentbooks_limit'] = '50';
/* /*
* Catalog's author name * Catalog's author name
*/ */
@ -56,12 +56,12 @@
* Catalog's title * Catalog's title
*/ */
$config['cops_title_default'] = "COPS"; $config['cops_title_default'] = "COPS";
/* /*
* Catalog's subtitle * Catalog's subtitle
*/ */
$config['cops_subtitle_default'] = ""; $config['cops_subtitle_default'] = "";
/* /*
* Wich header to use when downloading books outside the web directory * Wich header to use when downloading books outside the web directory
* Possible values are : * Possible values are :
@ -70,12 +70,12 @@
* No value (default) : Let PHP handle the download * No value (default) : Let PHP handle the download
*/ */
$config['cops_x_accel_redirect'] = ""; $config['cops_x_accel_redirect'] = "";
/* /*
* Height of thumbnail image for OPDS * Height of thumbnail image for OPDS
*/ */
$config['cops_opds_thumbnail_height'] = "164"; $config['cops_opds_thumbnail_height'] = "164";
/* /*
* Height of thumbnail image for HTML * Height of thumbnail image for HTML
*/ */
@ -93,21 +93,21 @@
* 0 : disable * 0 : disable
*/ */
$config['cops_show_icons'] = "1"; $config['cops_show_icons'] = "1";
/* /*
* Default timezone * Default timezone
* Check following link for other timezones : * Check following link for other timezones :
* http://www.php.net/manual/en/timezones.php * http://www.php.net/manual/en/timezones.php
*/ */
$config['default_timezone'] = "Europe/Paris"; $config['default_timezone'] = "Europe/Paris";
/* /*
* Prefered format for HTML catalog * Prefered format for HTML catalog
* The two first will be displayed in book entries * The two first will be displayed in book entries
* The other only appear in book detail * The other only appear in book detail
*/ */
$config['cops_prefered_format'] = array ("EPUB", "PDF", "AZW3", "AZW", "MOBI", "CBR", "CBZ"); $config['cops_prefered_format'] = array ("EPUB", "PDF", "AZW3", "AZW", "MOBI", "CBR", "CBZ");
/* /*
* use URL rewriting for downloading of ebook in HTML catalog * use URL rewriting for downloading of ebook in HTML catalog
* See Github wiki for more information * See Github wiki for more information
@ -115,7 +115,7 @@
* 0 : disable * 0 : disable
*/ */
$config['cops_use_url_rewriting'] = "0"; $config['cops_use_url_rewriting'] = "0";
/* /*
* generate a invalid OPDS stream to allow bad OPDS client to use search * generate a invalid OPDS stream to allow bad OPDS client to use search
* Example of non compliant OPDS client : Moon+ Reader * Example of non compliant OPDS client : Moon+ Reader
@ -123,63 +123,63 @@
* 1 : enable support for non compliant OPDS client * 1 : enable support for non compliant OPDS client
* 0 : always generate valid OPDS code * 0 : always generate valid OPDS code
*/ */
$config['cops_generate_invalid_opds_stream'] = "0"; $config['cops_generate_invalid_opds_stream'] = "0";
/* /*
* Max number of items per page * Max number of items per page
* -1 unlimited * -1 unlimited
*/ */
$config['cops_max_item_per_page'] = "-1"; $config['cops_max_item_per_page'] = "-1";
/* /*
* split authors by first letter * split authors by first letter
* 1 : Yes * 1 : Yes
* 0 : No * 0 : No
*/ */
$config['cops_author_split_first_letter'] = "1"; $config['cops_author_split_first_letter'] = "1";
/* /*
* split titles by first letter * split titles by first letter
* 1 : Yes * 1 : Yes
* 0 : No * 0 : No
*/ */
$config['cops_titles_split_first_letter'] = "1"; $config['cops_titles_split_first_letter'] = "1";
/* /*
* Enable the Lightboxes (for popups) * Enable the Lightboxes (for popups)
* 1 : Yes (enable) * 1 : Yes (enable)
* 0 : No * 0 : No
*/ */
$config['cops_use_fancyapps'] = "1"; $config['cops_use_fancyapps'] = "1";
/* /*
* Update Epub metadata before download * Update Epub metadata before download
* 1 : Yes (enable) * 1 : Yes (enable)
* 0 : No * 0 : No
*/ */
$config['cops_update_epub-metadata'] = "0"; $config['cops_update_epub-metadata'] = "0";
/* /*
* Filter on tags to book list * Filter on tags to book list
* Only works with the OPDS catalog * Only works with the OPDS catalog
* Usage : array ("I only want to see books using the tag : Tag1" => "Tag1", * Usage : array ("I only want to see books using the tag : Tag1" => "Tag1",
* "I only want to see books not using the tag : Tag1" => "!Tag1", * "I only want to see books not using the tag : Tag1" => "!Tag1",
* "I want to see every books" => "", * "I want to see every books" => "",
* *
* Example : array ("All" => "", "Unread" => "!Read", "Read" => "Read") * Example : array ("All" => "", "Unread" => "!Read", "Read" => "Read")
*/ */
$config['cops_books_filter'] = array (); $config['cops_books_filter'] = array ();
/* /*
* Custom Columns to add as an array containing the lookup names * Custom Columns to add as an array containing the lookup names
* configured in Calibre * configured in Calibre
* *
* For example : array ("genre", "mycolumn"); * For example : array ("genre", "mycolumn");
* *
* Note that for now only the first, second and forth type of custom columns are supported * Note that for now only the first, second and forth type of custom columns are supported
*/ */
$config['cops_calibre_custom_column'] = array (); $config['cops_calibre_custom_column'] = array ();
/* /*
* Rename .epub to .kepub.epub if downloaded from a Kobo eReader * Rename .epub to .kepub.epub if downloaded from a Kobo eReader
* The ebook will then be recognized a Kepub so with chaptered paging, statistics, ... * The ebook will then be recognized a Kepub so with chaptered paging, statistics, ...
@ -189,10 +189,10 @@
*/ */
$config['cops_provide_kepub'] = "0"; $config['cops_provide_kepub'] = "0";
/* /*
* Enable and configure Send To Kindle (or Email) feature. * Enable and configure Send To Kindle (or Email) feature.
* *
* Don't forget to authorize the sender email you configured in your Kindle's Approved Personal Document E-mail List. * Don't forget to authorize the sender email you configured in your Kindle's Approved Personal Document E-mail List.
* *
* If you want to use a simple smtp server (provided by your ISP for example), you can configure it like that : * If you want to use a simple smtp server (provided by your ISP for example), you can configure it like that :
* $config['cops_mail_configuration'] = array( "smtp.host" => "smtp.free.fr", * $config['cops_mail_configuration'] = array( "smtp.host" => "smtp.free.fr",
@ -211,14 +211,14 @@
* ); * );
*/ */
$config['cops_mail_configuration'] = NULL; $config['cops_mail_configuration'] = NULL;
/* /*
* Use filter in HTML catalog * Use filter in HTML catalog
* 1 : Yes (enable) * 1 : Yes (enable)
* 0 : No * 0 : No
*/ */
$config['cops_html_tag_filter'] = "0"; $config['cops_html_tag_filter'] = "0";
/* /*
* Thumbnails are generated on-the-fly so it can be problematic on servers with slow CPU (Raspberry Pi, Dockstar, Piratebox, ...). * Thumbnails are generated on-the-fly so it can be problematic on servers with slow CPU (Raspberry Pi, Dockstar, Piratebox, ...).
* This configuration item allow to customize how thumbnail will be generated * This configuration item allow to customize how thumbnail will be generated
@ -227,7 +227,7 @@
* any url : Send a constant image as the thumbnail (you can try "images/bookcover.png") * any url : Send a constant image as the thumbnail (you can try "images/bookcover.png")
*/ */
$config['cops_thumbnail_handling'] = ""; $config['cops_thumbnail_handling'] = "";
/* /*
* Contains a list of user agent for browsers not compatible with client side rendering * Contains a list of user agent for browsers not compatible with client side rendering
* For now : Kindle, Sony PRS-T1, Sony PRS-T2, All Cybook devices (maybe a little extreme). * For now : Kindle, Sony PRS-T1, Sony PRS-T2, All Cybook devices (maybe a little extreme).

View file

@ -10,52 +10,52 @@ require_once('base.php');
class CustomColumn extends Base { class CustomColumn extends Base {
const ALL_CUSTOMS_ID = "cops:custom"; const ALL_CUSTOMS_ID = "cops:custom";
public $id; public $id;
public $name; public $name;
public $customId; public $customId;
public function __construct($pid, $pname, $pcustomId) { public function __construct($pid, $pname, $pcustomId) {
$this->id = $pid; $this->id = $pid;
$this->name = $pname; $this->name = $pname;
$this->customId = $pcustomId; $this->customId = $pcustomId;
} }
public function getUri () { public function getUri () {
return "?page=".parent::PAGE_CUSTOM_DETAIL."&custom={$this->customId}&id={$this->id}"; return "?page=".parent::PAGE_CUSTOM_DETAIL."&custom={$this->customId}&id={$this->id}";
} }
public function getEntryId () { public function getEntryId () {
return self::ALL_CUSTOMS_ID.":".$this->customId.":".$this->id; return self::ALL_CUSTOMS_ID.":".$this->customId.":".$this->id;
} }
public static function getTableName ($customId) { public static function getTableName ($customId) {
return "custom_column_{$customId}"; return "custom_column_{$customId}";
} }
public static function getTableLinkName ($customId) { public static function getTableLinkName ($customId) {
return "books_custom_column_{$customId}_link"; return "books_custom_column_{$customId}_link";
} }
public static function getTableLinkColumn ($customId) { public static function getTableLinkColumn ($customId) {
return "value"; return "value";
} }
public static function getAllCustomsId ($customId) { public static function getAllCustomsId ($customId) {
return self::ALL_CUSTOMS_ID . ":" . $customId; return self::ALL_CUSTOMS_ID . ":" . $customId;
} }
public static function getUriAllCustoms ($customId) { public static function getUriAllCustoms ($customId) {
return "?page=" . parent::PAGE_ALL_CUSTOMS . "&custom={$customId}"; return "?page=" . parent::PAGE_ALL_CUSTOMS . "&custom={$customId}";
} }
public static function getAllTitle ($customId) { public static function getAllTitle ($customId) {
$result = parent::getDb ()->prepare('select name from custom_columns where id = ?'); $result = parent::getDb ()->prepare('select name from custom_columns where id = ?');
$result->execute (array ($customId)); $result->execute (array ($customId));
$post = $result->fetchObject (); $post = $result->fetchObject ();
return $post->name; return $post->name;
} }
public static function getCustomId ($lookup) { public static function getCustomId ($lookup) {
$result = parent::getDb ()->prepare('select id from custom_columns where label = ?'); $result = parent::getDb ()->prepare('select id from custom_columns where label = ?');
$result->execute (array ($lookup)); $result->execute (array ($lookup));
@ -67,12 +67,12 @@ class CustomColumn extends Base {
public static function getCount($customId) { public static function getCount($customId) {
$nCustoms = parent::getDb ()->query('select count(*) from ' . self::getTableName ($customId))->fetchColumn(); $nCustoms = parent::getDb ()->query('select count(*) from ' . self::getTableName ($customId))->fetchColumn();
$entry = new Entry (self::getAllTitle ($customId), self::getAllCustomsId ($customId), $entry = new Entry (self::getAllTitle ($customId), self::getAllCustomsId ($customId),
str_format (localize("tags.alphabetical", $nCustoms), $nCustoms), "text", str_format (localize("tags.alphabetical", $nCustoms), $nCustoms), "text",
array ( new LinkNavigation (self::getUriAllCustoms ($customId)))); array ( new LinkNavigation (self::getUriAllCustoms ($customId))));
return $entry; return $entry;
} }
public static function getCustomById ($customId, $id) { public static function getCustomById ($customId, $id) {
$result = parent::getDb ()->prepare('select id, value as name from ' . self::getTableName ($customId) . ' where id = ?'); $result = parent::getDb ()->prepare('select id, value as name from ' . self::getTableName ($customId) . ' where id = ?');
$result->execute (array ($id)); $result->execute (array ($id));
@ -81,7 +81,7 @@ class CustomColumn extends Base {
} }
return NULL; return NULL;
} }
public static function getAllCustoms($customId) { public static function getAllCustoms($customId) {
$result = parent::getDb ()->query(str_format ('select {0}.id as id, {0}.value as name, count(*) as count $result = parent::getDb ()->query(str_format ('select {0}.id as id, {0}.value as name, count(*) as count
from {0}, {1} from {0}, {1}
@ -92,8 +92,8 @@ order by {0}.value', self::getTableName ($customId), self::getTableLinkName ($cu
while ($post = $result->fetchObject ()) while ($post = $result->fetchObject ())
{ {
$customColumn = new CustomColumn ($post->id, $post->name, $customId); $customColumn = new CustomColumn ($post->id, $post->name, $customId);
array_push ($entryArray, new Entry ($customColumn->name, $customColumn->getEntryId (), array_push ($entryArray, new Entry ($customColumn->name, $customColumn->getEntryId (),
str_format (localize("bookword", $post->count), $post->count), "text", str_format (localize("bookword", $post->count), $post->count), "text",
array ( new LinkNavigation ($customColumn->getUri ())))); array ( new LinkNavigation ($customColumn->getUri ()))));
} }
return $entryArray; return $entryArray;

View file

@ -15,7 +15,7 @@ class Data extends Base {
public $realFormat; public $realFormat;
public $extension; public $extension;
public $book; public $book;
public static $mimetypes = array( public static $mimetypes = array(
'azw' => 'application/x-mobipocket-ebook', 'azw' => 'application/x-mobipocket-ebook',
'azw3' => 'application/x-mobipocket-ebook', 'azw3' => 'application/x-mobipocket-ebook',
@ -44,7 +44,7 @@ class Data extends Base {
'xpgt' => 'application/adobe-page-template+xml', 'xpgt' => 'application/adobe-page-template+xml',
'zip' => 'application/zip' 'zip' => 'application/zip'
); );
public function __construct($post, $book = null) { public function __construct($post, $book = null) {
$this->id = $post->id; $this->id = $post->id;
$this->name = $post->name; $this->name = $post->name;
@ -53,11 +53,11 @@ class Data extends Base {
$this->extension = strtolower ($this->realFormat); $this->extension = strtolower ($this->realFormat);
$this->book = $book; $this->book = $book;
} }
public function isKnownType () { public function isKnownType () {
return array_key_exists ($this->extension, self::$mimetypes); return array_key_exists ($this->extension, self::$mimetypes);
} }
public function getMimeType () { public function getMimeType () {
if ($this->isKnownType ()) { if ($this->isKnownType ()) {
return self::$mimetypes [$this->extension]; return self::$mimetypes [$this->extension];
@ -65,11 +65,11 @@ class Data extends Base {
return "application/octet-stream"; return "application/octet-stream";
} }
} }
public function getFilename () { public function getFilename () {
return $this->name . "." . strtolower ($this->format); return $this->name . "." . strtolower ($this->format);
} }
public function getUpdatedFilename () { public function getUpdatedFilename () {
return $this->book->getAuthorsName () . " - " . $this->book->title; return $this->book->getAuthorsName () . " - " . $this->book->title;
} }
@ -81,18 +81,18 @@ class Data extends Base {
public function getUpdatedFilenameKepub () { public function getUpdatedFilenameKepub () {
return $this->getUpdatedFilename () . ".kepub.epub"; return $this->getUpdatedFilename () . ".kepub.epub";
} }
public function getDataLink ($rel, $title = NULL) { public function getDataLink ($rel, $title = NULL) {
return self::getLink ($this->book, $this->extension, $this->getMimeType (), $rel, $this->getFilename (), $this->id, $title); return self::getLink ($this->book, $this->extension, $this->getMimeType (), $rel, $this->getFilename (), $this->id, $title);
} }
public function getLocalPath () { public function getLocalPath () {
return $this->book->path . "/" . $this->getFilename (); return $this->book->path . "/" . $this->getFilename ();
} }
public function getHtmlLink () { public function getHtmlLink () {
global $config; global $config;
if ($config['cops_use_url_rewriting'] == "1") if ($config['cops_use_url_rewriting'] == "1")
{ {
$database = ""; $database = "";
@ -108,13 +108,13 @@ class Data extends Base {
return self::getLink ($this->book, $this->extension, $this->getMimeType (), NULL, $this->getFilename (), $this->id, NULL)->href; return self::getLink ($this->book, $this->extension, $this->getMimeType (), NULL, $this->getFilename (), $this->id, NULL)->href;
} }
} }
public static function getLink ($book, $type, $mime, $rel, $filename, $idData, $title = NULL, $height = NULL) public static function getLink ($book, $type, $mime, $rel, $filename, $idData, $title = NULL, $height = NULL)
{ {
global $config; global $config;
$urlParam = addURLParameter("", "data", $idData); $urlParam = addURLParameter("", "data", $idData);
if (preg_match ('/^\//', Base::getDbDirectory ()) || // Linux / if (preg_match ('/^\//', Base::getDbDirectory ()) || // Linux /
preg_match ('/^\w\:/', Base::getDbDirectory ()) || // Windows X: preg_match ('/^\w\:/', Base::getDbDirectory ()) || // Windows X:
$rel == Link::OPDS_THUMBNAIL_TYPE || $rel == Link::OPDS_THUMBNAIL_TYPE ||
@ -137,8 +137,8 @@ class Data extends Base {
} }
$urlParam = addURLParameter($urlParam, "id", $book->id); $urlParam = addURLParameter($urlParam, "id", $book->id);
if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB)); if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB));
if ($config['cops_thumbnail_handling'] != "1" && if ($config['cops_thumbnail_handling'] != "1" &&
!empty ($config['cops_thumbnail_handling']) && !empty ($config['cops_thumbnail_handling']) &&
$rel == Link::OPDS_THUMBNAIL_TYPE) { $rel == Link::OPDS_THUMBNAIL_TYPE) {
return new Link ($config['cops_thumbnail_handling'], $mime, $rel, $title); return new Link ($config['cops_thumbnail_handling'], $mime, $rel, $title);
} else { } else {

View file

@ -14,7 +14,7 @@
require_once ("tag.php"); require_once ("tag.php");
require_once ("book.php"); require_once ("book.php");
require_once ("OPDS_renderer.php"); require_once ("OPDS_renderer.php");
header ("Content-Type:application/xml"); header ("Content-Type:application/xml");
$page = getURLParam ("page", Base::PAGE_INDEX); $page = getURLParam ("page", Base::PAGE_INDEX);
$query = getURLParam ("query"); $query = getURLParam ("query");
@ -22,9 +22,9 @@
if ($query) if ($query)
$page = Base::PAGE_OPENSEARCH_QUERY; $page = Base::PAGE_OPENSEARCH_QUERY;
$qid = getURLParam ("id"); $qid = getURLParam ("id");
$OPDSRender = new OPDSRenderer (); $OPDSRender = new OPDSRenderer ();
switch ($page) { switch ($page) {
case Base::PAGE_OPENSEARCH : case Base::PAGE_OPENSEARCH :
echo $OPDSRender->getOpenSearch (); echo $OPDSRender->getOpenSearch ();

View file

@ -1,11 +1,11 @@
<?php <?php
/** /**
* COPS (Calibre OPDS PHP Server) * COPS (Calibre OPDS PHP Server)
* *
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html) * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Gordon Page <gordon@incero.com> with integration/modification by Sébastien Lucas <sebastien@slucas.fr> * @author Gordon Page <gordon@incero.com> with integration/modification by Sébastien Lucas <sebastien@slucas.fr>
*/ */
require_once ("config.php"); require_once ("config.php");
require_once ("book.php"); require_once ("book.php");
require_once ("data.php"); require_once ("data.php");
@ -16,7 +16,7 @@ function notFound () {
$_SERVER['REDIRECT_STATUS'] = 404; $_SERVER['REDIRECT_STATUS'] = 404;
} }
global $config; global $config;
$expires = 60*60*24*14; $expires = 60*60*24*14;
header("Pragma: public"); header("Pragma: public");
@ -33,12 +33,12 @@ function notFound () {
{ {
$book = Book::getBookById($bookId); $book = Book::getBookById($bookId);
} }
if (!$book) { if (!$book) {
notFound (); notFound ();
return; return;
} }
if ($book && ($type == "jpg" || empty ($config['calibre_internal_directory']))) { if ($book && ($type == "jpg" || empty ($config['calibre_internal_directory']))) {
if ($type == "jpg") { if ($type == "jpg") {
$file = $book->getFilePath ($type); $file = $book->getFilePath ($type);
@ -50,7 +50,7 @@ function notFound () {
return; return;
} }
} }
switch ($type) switch ($type)
{ {
case "jpg": case "jpg":
@ -123,12 +123,12 @@ function notFound () {
} else { } else {
header('Content-Disposition: attachment; filename="' . basename ($file) . '"'); header('Content-Disposition: attachment; filename="' . basename ($file) . '"');
} }
$dir = $config['calibre_internal_directory']; $dir = $config['calibre_internal_directory'];
if (empty ($config['calibre_internal_directory'])) { if (empty ($config['calibre_internal_directory'])) {
$dir = Base::getDbDirectory (); $dir = Base::getDbDirectory ();
} }
if (empty ($config['cops_x_accel_redirect'])) { if (empty ($config['cops_x_accel_redirect'])) {
$filename = $dir . $file; $filename = $dir . $file;
$fp = fopen($filename, 'rb'); $fp = fopen($filename, 'rb');

View file

@ -6,7 +6,7 @@
* @author Sébastien Lucas <sebastien@slucas.fr> * @author Sébastien Lucas <sebastien@slucas.fr>
* *
*/ */
require_once ("config.php"); require_once ("config.php");
require_once ("base.php"); require_once ("base.php");
require_once ("author.php"); require_once ("author.php");
@ -15,9 +15,9 @@
require_once ("language.php"); require_once ("language.php");
require_once ("customcolumn.php"); require_once ("customcolumn.php");
require_once ("book.php"); require_once ("book.php");
header ("Content-Type:application/json;charset=utf-8"); header ("Content-Type:application/json;charset=utf-8");
echo json_encode (getJson ()); echo json_encode (getJson ());

View file

@ -6,7 +6,7 @@
* @author Sébastien Lucas <sebastien@slucas.fr> * @author Sébastien Lucas <sebastien@slucas.fr>
* *
*/ */
require_once ("config.php"); require_once ("config.php");
require_once ("base.php"); require_once ("base.php");
require_once ("author.php"); require_once ("author.php");
@ -17,20 +17,20 @@
require_once ("customcolumn.php"); require_once ("customcolumn.php");
require_once ("book.php"); require_once ("book.php");
require_once ("resources/doT-php/doT.php"); require_once ("resources/doT-php/doT.php");
// If we detect that an OPDS reader try to connect try to redirect to feed.php // If we detect that an OPDS reader try to connect try to redirect to feed.php
if (preg_match("/(MantanoReader|FBReader|Stanza|Aldiko|Moon+ Reader)/", $_SERVER['HTTP_USER_AGENT'])) { if (preg_match("/(MantanoReader|FBReader|Stanza|Aldiko|Moon+ Reader)/", $_SERVER['HTTP_USER_AGENT'])) {
header("location: feed.php"); header("location: feed.php");
exit (); exit ();
} }
$page = getURLParam ("page", Base::PAGE_INDEX); $page = getURLParam ("page", Base::PAGE_INDEX);
$query = getURLParam ("query"); $query = getURLParam ("query");
$qid = getURLParam ("id"); $qid = getURLParam ("id");
$n = getURLParam ("n", "1"); $n = getURLParam ("n", "1");
$database = GetUrlParam (DB); $database = GetUrlParam (DB);
// Access the database ASAP to be sure it's readable, redirect if that's not the case. // Access the database ASAP to be sure it's readable, redirect if that's not the case.
// It has to be done before any header is sent. // It has to be done before any header is sent.
if (is_array ($config['calibre_directory']) && is_null ($database)) { if (is_array ($config['calibre_directory']) && is_null ($database)) {
@ -43,7 +43,7 @@
} else { } else {
$test = Base::getDb (); $test = Base::getDb ();
} }
header ("Content-Type:text/html;charset=utf-8"); header ("Content-Type:text/html;charset=utf-8");
?><!DOCTYPE html> ?><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"> <html xmlns="http://www.w3.org/1999/xhtml">
@ -55,7 +55,7 @@
<link rel="apple-touch-icon" sizes="72x72" href="./icons/icon72.png" /> <link rel="apple-touch-icon" sizes="72x72" href="./icons/icon72.png" />
<link rel="apple-touch-icon" sizes="114x114" href="./icons/icon114.png" /> <link rel="apple-touch-icon" sizes="114x114" href="./icons/icon114.png" />
<link rel="apple-touch-icon" sizes="144x144" href="./icons/icon144.png" /> <link rel="apple-touch-icon" sizes="144x144" href="./icons/icon144.png" />
<title>COPS</title> <title>COPS</title>
<script type="text/javascript" src="<?php echo getUrlWithVersion("resources/jQuery/jquery-1.10.2.min.js") ?>"></script> <script type="text/javascript" src="<?php echo getUrlWithVersion("resources/jQuery/jquery-1.10.2.min.js") ?>"></script>
@ -69,7 +69,7 @@
<script type="text/javascript" src="<?php echo getUrlWithVersion("resources/typeahead/typeahead.js") ?>"></script> <script type="text/javascript" src="<?php echo getUrlWithVersion("resources/typeahead/typeahead.js") ?>"></script>
<?php } ?> <?php } ?>
<script type="text/javascript" src="<?php echo getUrlWithVersion("util.js") ?>"></script> <script type="text/javascript" src="<?php echo getUrlWithVersion("util.js") ?>"></script>
<link rel="related" href="<?php echo $config['cops_full_url'] ?>feed.php" type="application/atom+xml;profile=opds-catalog" title="<?php echo $config['cops_title_default']; ?>" /> <link rel="related" href="<?php echo $config['cops_full_url'] ?>feed.php" type="application/atom+xml;profile=opds-catalog" title="<?php echo $config['cops_title_default']; ?>" />
<link rel="icon" type="image/vnd.microsoft.icon" href="<?php echo $config['cops_icon']; ?>" /> <link rel="icon" type="image/vnd.microsoft.icon" href="<?php echo $config['cops_icon']; ?>" />
<link rel='stylesheet' type='text/css' href='https://fonts.googleapis.com/css?family=Open+Sans:400,300italic,800,300,400italic,600,600italic,700,700italic,800italic&subset=latin,cyrillic' /> <link rel='stylesheet' type='text/css' href='https://fonts.googleapis.com/css?family=Open+Sans:400,300italic,800,300,400italic,600,600italic,700,700italic,800italic&subset=latin,cyrillic' />
<link rel="stylesheet" type="text/css" href="<?php echo getUrlWithVersion("resources/normalize/normalize.css") ?>" /> <link rel="stylesheet" type="text/css" href="<?php echo getUrlWithVersion("resources/normalize/normalize.css") ?>" />
@ -77,12 +77,12 @@
<link rel="stylesheet" type="text/css" href="<?php echo getUrlWithVersion(getCurrentCss ()) ?>" media="screen" /> <link rel="stylesheet" type="text/css" href="<?php echo getUrlWithVersion(getCurrentCss ()) ?>" media="screen" />
<?php if (!useServerSideRendering ()) { ?> <?php if (!useServerSideRendering ()) { ?>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
// Handler for .ready() called. // Handler for .ready() called.
var url = "<?php echo "getJSON.php?" . addURLParameter (getQueryString (), "complete", 1); ?>"; var url = "<?php echo "getJSON.php?" . addURLParameter (getQueryString (), "complete", 1); ?>";
$.when($.get('templates/default/header.html'), $.when($.get('templates/default/header.html'),
$.get('templates/default/footer.html'), $.get('templates/default/footer.html'),
$.get('templates/default/bookdetail.html'), $.get('templates/default/bookdetail.html'),
@ -91,26 +91,26 @@
$.get('templates/default/suggestion.html'), $.get('templates/default/suggestion.html'),
$.getJSON(url)).done(function(header, footer, bookdetail, main, page, suggestion, data){ $.getJSON(url)).done(function(header, footer, bookdetail, main, page, suggestion, data){
templateBookDetail = doT.template (bookdetail [0]); templateBookDetail = doT.template (bookdetail [0]);
var defMain = { var defMain = {
bookdetail: bookdetail [0] bookdetail: bookdetail [0]
}; };
templateMain = doT.template (main [0], undefined, defMain); templateMain = doT.template (main [0], undefined, defMain);
var defPage = { var defPage = {
header: header [0], header: header [0],
footer: footer [0], footer: footer [0],
main : main [0], main : main [0],
bookdetail: bookdetail [0] bookdetail: bookdetail [0]
}; };
templatePage = doT.template (page [0], undefined, defPage); templatePage = doT.template (page [0], undefined, defPage);
templateSuggestion = doT.template (suggestion [0]); templateSuggestion = doT.template (suggestion [0]);
currentData = data [0]; currentData = data [0];
updatePage (data [0]); updatePage (data [0]);
cache.put (url, data [0]); cache.put (url, data [0]);
if (isPushStateEnabled) { if (isPushStateEnabled) {
@ -118,10 +118,10 @@
} }
handleLinks (); handleLinks ();
}); });
}); });
</script> </script>
<?php } ?> <?php } ?>

View file

@ -10,23 +10,23 @@ require_once('base.php');
class language extends Base { class language extends Base {
const ALL_LANGUAGES_ID = "cops:languages"; const ALL_LANGUAGES_ID = "cops:languages";
public $id; public $id;
public $lang_code; public $lang_code;
public function __construct($pid, $plang_code) { public function __construct($pid, $plang_code) {
$this->id = $pid; $this->id = $pid;
$this->lang_code = $plang_code; $this->lang_code = $plang_code;
} }
public function getUri () { public function getUri () {
return "?page=".parent::PAGE_LANGUAGE_DETAIL."&id=$this->id"; return "?page=".parent::PAGE_LANGUAGE_DETAIL."&id=$this->id";
} }
public function getEntryId () { public function getEntryId () {
return self::ALL_LANGUAGES_ID.":".$this->id; return self::ALL_LANGUAGES_ID.":".$this->id;
} }
public static function getLanguageString ($code) { public static function getLanguageString ($code) {
$string = localize("languages.".$code); $string = localize("languages.".$code);
if (preg_match ("/^languages/", $string)) { if (preg_match ("/^languages/", $string)) {
@ -38,12 +38,12 @@ class language extends Base {
public static function getCount() { public static function getCount() {
$nLanguages = parent::getDb ()->query('select count(*) from languages')->fetchColumn(); $nLanguages = parent::getDb ()->query('select count(*) from languages')->fetchColumn();
if ($nLanguages == 0) return NULL; if ($nLanguages == 0) return NULL;
$entry = new Entry (localize("languages.title"), self::ALL_LANGUAGES_ID, $entry = new Entry (localize("languages.title"), self::ALL_LANGUAGES_ID,
str_format (localize("languages.alphabetical", $nLanguages), $nLanguages), "text", str_format (localize("languages.alphabetical", $nLanguages), $nLanguages), "text",
array ( new LinkNavigation ("?page=".parent::PAGE_ALL_LANGUAGES))); array ( new LinkNavigation ("?page=".parent::PAGE_ALL_LANGUAGES)));
return $entry; return $entry;
} }
public static function getLanguageById ($languageId) { public static function getLanguageById ($languageId) {
$result = parent::getDb ()->prepare('select id, lang_code from languages where id = ?'); $result = parent::getDb ()->prepare('select id, lang_code from languages where id = ?');
$result->execute (array ($languageId)); $result->execute (array ($languageId));
@ -52,7 +52,7 @@ class language extends Base {
} }
return NULL; return NULL;
} }
public static function getAllLanguages() { public static function getAllLanguages() {
@ -65,8 +65,8 @@ order by languages.lang_code');
while ($post = $result->fetchObject ()) while ($post = $result->fetchObject ())
{ {
$language = new Language ($post->id, $post->lang_code); $language = new Language ($post->id, $post->lang_code);
array_push ($entryArray, new Entry (Language::getLanguageString ($language->lang_code), $language->getEntryId (), array_push ($entryArray, new Entry (Language::getLanguageString ($language->lang_code), $language->getEntryId (),
str_format (localize("bookword", $post->count), $post->count), "text", str_format (localize("bookword", $post->count), $post->count), "text",
array ( new LinkNavigation ($language->getUri ())))); array ( new LinkNavigation ($language->getUri ()))));
} }
return $entryArray; return $entryArray;

View file

@ -1,5 +1,5 @@
<phpunit> <phpunit>
<filter> <filter>
<whitelist addUncoveredFilesFromWhitelist="true"> <whitelist addUncoveredFilesFromWhitelist="true">
<!-- this is the path of the files included in your clover report --> <!-- this is the path of the files included in your clover report -->

View file

@ -55,7 +55,7 @@ foreach (explode (";", $emailDest) as $emailAddress) {
$mail->AddAttachment($data->getLocalPath ()); $mail->AddAttachment($data->getLocalPath ());
$mail->IsHTML(false); $mail->IsHTML(false);
$mail->Subject = 'Sent by COPS'; $mail->Subject = 'Sent by COPS';
$mail->Body = 'Sent by COPS'; $mail->Body = 'Sent by COPS';

View file

@ -10,19 +10,19 @@ require_once('base.php');
class Serie extends Base { class Serie extends Base {
const ALL_SERIES_ID = "cops:series"; const ALL_SERIES_ID = "cops:series";
public $id; public $id;
public $name; public $name;
public function __construct($pid, $pname) { public function __construct($pid, $pname) {
$this->id = $pid; $this->id = $pid;
$this->name = $pname; $this->name = $pname;
} }
public function getUri () { public function getUri () {
return "?page=".parent::PAGE_SERIE_DETAIL."&id=$this->id"; return "?page=".parent::PAGE_SERIE_DETAIL."&id=$this->id";
} }
public function getEntryId () { public function getEntryId () {
return self::ALL_SERIES_ID.":".$this->id; return self::ALL_SERIES_ID.":".$this->id;
} }
@ -30,12 +30,12 @@ class Serie extends Base {
public static function getCount() { public static function getCount() {
$nSeries = parent::getDb ()->query('select count(*) from series')->fetchColumn(); $nSeries = parent::getDb ()->query('select count(*) from series')->fetchColumn();
if ($nSeries == 0) return NULL; if ($nSeries == 0) return NULL;
$entry = new Entry (localize("series.title"), self::ALL_SERIES_ID, $entry = new Entry (localize("series.title"), self::ALL_SERIES_ID,
str_format (localize("series.alphabetical", $nSeries), $nSeries), "text", str_format (localize("series.alphabetical", $nSeries), $nSeries), "text",
array ( new LinkNavigation ("?page=".parent::PAGE_ALL_SERIES))); array ( new LinkNavigation ("?page=".parent::PAGE_ALL_SERIES)));
return $entry; return $entry;
} }
public static function getSerieByBookId ($bookId) { public static function getSerieByBookId ($bookId) {
$result = parent::getDb ()->prepare('select series.id as id, name $result = parent::getDb ()->prepare('select series.id as id, name
from books_series_link, series from books_series_link, series
@ -46,7 +46,7 @@ where series.id = series and book = ?');
} }
return NULL; return NULL;
} }
public static function getSerieById ($serieId) { public static function getSerieById ($serieId) {
$result = parent::getDb ()->prepare('select id, name from series where id = ?'); $result = parent::getDb ()->prepare('select id, name from series where id = ?');
$result->execute (array ($serieId)); $result->execute (array ($serieId));
@ -55,7 +55,7 @@ where series.id = series and book = ?');
} }
return NULL; return NULL;
} }
public static function getAllSeries() { public static function getAllSeries() {
$result = parent::getDb ()->query('select series.id as id, series.name as name, series.sort as sort, count(*) as count $result = parent::getDb ()->query('select series.id as id, series.name as name, series.sort as sort, count(*) as count
from series, books_series_link from series, books_series_link
@ -66,13 +66,13 @@ order by series.sort');
while ($post = $result->fetchObject ()) while ($post = $result->fetchObject ())
{ {
$serie = new Serie ($post->id, $post->sort); $serie = new Serie ($post->id, $post->sort);
array_push ($entryArray, new Entry ($serie->name, $serie->getEntryId (), array_push ($entryArray, new Entry ($serie->name, $serie->getEntryId (),
str_format (localize("bookword", $post->count), $post->count), "text", str_format (localize("bookword", $post->count), $post->count), "text",
array ( new LinkNavigation ($serie->getUri ())))); array ( new LinkNavigation ($serie->getUri ()))));
} }
return $entryArray; return $entryArray;
} }
public static function getAllSeriesByQuery($query) { public static function getAllSeriesByQuery($query) {
$result = parent::getDb ()->prepare('select series.id as id, series.name as name, series.sort as sort, count(*) as count $result = parent::getDb ()->prepare('select series.id as id, series.name as name, series.sort as sort, count(*) as count
from series, books_series_link from series, books_series_link
@ -84,8 +84,8 @@ order by series.sort');
while ($post = $result->fetchObject ()) while ($post = $result->fetchObject ())
{ {
$serie = new Serie ($post->id, $post->sort); $serie = new Serie ($post->id, $post->sort);
array_push ($entryArray, new Entry ($serie->name, $serie->getEntryId (), array_push ($entryArray, new Entry ($serie->name, $serie->getEntryId (),
str_format (localize("bookword", $post->count), $post->count), "text", str_format (localize("bookword", $post->count), $post->count), "text",
array ( new LinkNavigation ($serie->getUri ())))); array ( new LinkNavigation ($serie->getUri ()))));
} }
return $entryArray; return $entryArray;

26
tag.php
View file

@ -10,19 +10,19 @@ require_once('base.php');
class tag extends Base { class tag extends Base {
const ALL_TAGS_ID = "cops:tags"; const ALL_TAGS_ID = "cops:tags";
public $id; public $id;
public $name; public $name;
public function __construct($pid, $pname) { public function __construct($pid, $pname) {
$this->id = $pid; $this->id = $pid;
$this->name = $pname; $this->name = $pname;
} }
public function getUri () { public function getUri () {
return "?page=".parent::PAGE_TAG_DETAIL."&id=$this->id"; return "?page=".parent::PAGE_TAG_DETAIL."&id=$this->id";
} }
public function getEntryId () { public function getEntryId () {
return self::ALL_TAGS_ID.":".$this->id; return self::ALL_TAGS_ID.":".$this->id;
} }
@ -30,12 +30,12 @@ class tag extends Base {
public static function getCount() { public static function getCount() {
$nTags = parent::getDb ()->query('select count(*) from tags')->fetchColumn(); $nTags = parent::getDb ()->query('select count(*) from tags')->fetchColumn();
if ($nTags == 0) return NULL; if ($nTags == 0) return NULL;
$entry = new Entry (localize("tags.title"), self::ALL_TAGS_ID, $entry = new Entry (localize("tags.title"), self::ALL_TAGS_ID,
str_format (localize("tags.alphabetical", $nTags), $nTags), "text", str_format (localize("tags.alphabetical", $nTags), $nTags), "text",
array ( new LinkNavigation ("?page=".parent::PAGE_ALL_TAGS))); array ( new LinkNavigation ("?page=".parent::PAGE_ALL_TAGS)));
return $entry; return $entry;
} }
public static function getTagById ($tagId) { public static function getTagById ($tagId) {
$result = parent::getDb ()->prepare('select id, name from tags where id = ?'); $result = parent::getDb ()->prepare('select id, name from tags where id = ?');
$result->execute (array ($tagId)); $result->execute (array ($tagId));
@ -44,7 +44,7 @@ class tag extends Base {
} }
return NULL; return NULL;
} }
public static function getAllTags() { public static function getAllTags() {
$result = parent::getDb ()->query('select tags.id as id, tags.name as name, count(*) as count $result = parent::getDb ()->query('select tags.id as id, tags.name as name, count(*) as count
from tags, books_tags_link from tags, books_tags_link
@ -55,13 +55,13 @@ order by tags.name');
while ($post = $result->fetchObject ()) while ($post = $result->fetchObject ())
{ {
$tag = new Tag ($post->id, $post->name); $tag = new Tag ($post->id, $post->name);
array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (), array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (),
str_format (localize("bookword", $post->count), $post->count), "text", str_format (localize("bookword", $post->count), $post->count), "text",
array ( new LinkNavigation ($tag->getUri ())))); array ( new LinkNavigation ($tag->getUri ()))));
} }
return $entryArray; return $entryArray;
} }
public static function getAllTagsByQuery($query, $n, $database = NULL, $numberPerPage = NULL) { public static function getAllTagsByQuery($query, $n, $database = NULL, $numberPerPage = NULL) {
$columns = "tags.id as id, tags.name as name, (select count(*) from books_tags_link where tags.id = tag) as count"; $columns = "tags.id as id, tags.name as name, (select count(*) from books_tags_link where tags.id = tag) as count";
$sql = 'select {0} from tags where tags.name like ? {1} order by tags.name'; $sql = 'select {0} from tags where tags.name like ? {1} order by tags.name';
@ -70,8 +70,8 @@ order by tags.name');
while ($post = $result->fetchObject ()) while ($post = $result->fetchObject ())
{ {
$tag = new Tag ($post->id, $post->name); $tag = new Tag ($post->id, $post->name);
array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (), array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (),
str_format (localize("bookword", $post->count), $post->count), "text", str_format (localize("bookword", $post->count), $post->count), "text",
array ( new LinkNavigation ($tag->getUri ())))); array ( new LinkNavigation ($tag->getUri ()))));
} }
return array ($entryArray, $totalNumber); return array ($entryArray, $totalNumber);

View file

@ -55,7 +55,7 @@ class Cops extends Sauce\Sausage\WebDriverTestCase
'platform' => 'Linux' 'platform' => 'Linux'
) )
) )
// run Mobile Browser on Android // run Mobile Browser on Android
// array( // array(
// 'browserName' => 'Android', // 'browserName' => 'Android',
// 'desiredCapabilities' => array( // 'desiredCapabilities' => array(
@ -63,7 +63,7 @@ class Cops extends Sauce\Sausage\WebDriverTestCase
// 'platform' => 'Linux', // 'platform' => 'Linux',
// ) // )
// ) // )
// run Chrome locally // run Chrome locally
//array( //array(
//'browserName' => 'chrome', //'browserName' => 'chrome',
@ -81,7 +81,7 @@ class Cops extends Sauce\Sausage\WebDriverTestCase
} }
parent::setUp (); parent::setUp ();
} }
public function setUpPage() public function setUpPage()
{ {
if (isset ($_SERVER["TRAVIS_JOB_NUMBER"])) { if (isset ($_SERVER["TRAVIS_JOB_NUMBER"])) {
@ -89,25 +89,25 @@ class Cops extends Sauce\Sausage\WebDriverTestCase
} else { } else {
$this->url('http://cops-demo.slucas.fr/index.php'); $this->url('http://cops-demo.slucas.fr/index.php');
} }
$driver = $this; $driver = $this;
$title_test = function($value) use ($driver) { $title_test = function($value) use ($driver) {
$text = $driver->byXPath('//h1')->text (); $text = $driver->byXPath('//h1')->text ();
return $text == $value; return $text == $value;
}; };
$this->spinAssert("Home Title", $title_test, [ "COPS DEMO" ]); $this->spinAssert("Home Title", $title_test, [ "COPS DEMO" ]);
} }
public function string_to_ascii($string) public function string_to_ascii($string)
{ {
$ascii = NULL; $ascii = NULL;
for ($i = 0; $i < strlen($string); $i++) for ($i = 0; $i < strlen($string); $i++)
{ {
$ascii += ord($string[$i]); $ascii += ord($string[$i]);
} }
return mb_detect_encoding($string) . "X" . $ascii; return mb_detect_encoding($string) . "X" . $ascii;
} }
@ -121,19 +121,19 @@ class Cops extends Sauce\Sausage\WebDriverTestCase
$author = $this->byXPath ('//h2[contains(text(), "Authors")]'); $author = $this->byXPath ('//h2[contains(text(), "Authors")]');
$author->click (); $author->click ();
$this->spinAssert("Author Title", $title_test, [ "AUTHORS" ]); $this->spinAssert("Author Title", $title_test, [ "AUTHORS" ]);
} }
public function testCog() public function testCog()
{ {
$cog = $this->byId ("searchImage"); $cog = $this->byId ("searchImage");
$search = $this->byName ("query"); $search = $this->byName ("query");
$this->assertFalse ($search->displayed ()); $this->assertFalse ($search->displayed ());
$cog->click (); $cog->click ();
$search = $this->byName ("query"); $search = $this->byName ("query");
$this->assertTrue ($search->displayed ()); $this->assertTrue ($search->displayed ());
} }

View file

@ -10,42 +10,42 @@ require_once (dirname(__FILE__) . "/config_test.php");
require_once (dirname(__FILE__) . "/../base.php"); require_once (dirname(__FILE__) . "/../base.php");
class BaseTest extends PHPUnit_Framework_TestCase class BaseTest extends PHPUnit_Framework_TestCase
{ {
public function testAddURLParameter () public function testAddURLParameter ()
{ {
$this->assertEquals ("?db=0", addURLParameter ("?", "db", "0")); $this->assertEquals ("?db=0", addURLParameter ("?", "db", "0"));
$this->assertEquals ("?key=value&db=0", addURLParameter ("?key=value", "db", "0")); $this->assertEquals ("?key=value&db=0", addURLParameter ("?key=value", "db", "0"));
$this->assertEquals ("?key=value&otherKey=&db=0", addURLParameter ("?key=value&otherKey", "db", "0")); $this->assertEquals ("?key=value&otherKey=&db=0", addURLParameter ("?key=value&otherKey", "db", "0"));
} }
public function testLocalize () public function testLocalize ()
{ {
$this->assertEquals ("Authors", localize ("authors.title")); $this->assertEquals ("Authors", localize ("authors.title"));
$this->assertEquals ("unknow.key", localize ("unknow.key")); $this->assertEquals ("unknow.key", localize ("unknow.key"));
} }
public function testLocalizeFr () public function testLocalizeFr ()
{ {
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = "fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3"; $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3";
$this->assertEquals ("Auteurs", localize ("authors.title", -1, true)); $this->assertEquals ("Auteurs", localize ("authors.title", -1, true));
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en"; $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en";
localize ("authors.title", -1, true); localize ("authors.title", -1, true);
} }
public function testLocalizeUnknown () public function testLocalizeUnknown ()
{ {
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = "aa"; $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "aa";
$this->assertEquals ("Authors", localize ("authors.title", -1, true)); $this->assertEquals ("Authors", localize ("authors.title", -1, true));
$_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en"; $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en";
localize ("authors.title", -1, true); localize ("authors.title", -1, true);
} }
public function testBaseFunction () { public function testBaseFunction () {
global $config; global $config;
$this->assertFalse (Base::isMultipleDatabaseEnabled ()); $this->assertFalse (Base::isMultipleDatabaseEnabled ());
$this->assertEquals (array ("" => dirname(__FILE__) . "/BaseWithSomeBooks/"), Base::getDbList ()); $this->assertEquals (array ("" => dirname(__FILE__) . "/BaseWithSomeBooks/"), Base::getDbList ());

View file

@ -11,70 +11,70 @@ require_once (dirname(__FILE__) . "/../book.php");
/* /*
Publishers: Publishers:
id:2 (2 books) Macmillan and Co. London: Lewis Caroll id:2 (2 books) Macmillan and Co. London: Lewis Caroll
id:3 (2 books) D. Appleton and Company Alexander Dumas id:3 (2 books) D. Appleton and Company Alexander Dumas
id:4 (1 book) Macmillan Publishers USA: Jack London id:4 (1 book) Macmillan Publishers USA: Jack London
id:5 (1 book) Pierson's Magazine: H. G. Wells id:5 (1 book) Pierson's Magazine: H. G. Wells
id:6 (8 books) Strand Magazine: Arthur Conan Doyle id:6 (8 books) Strand Magazine: Arthur Conan Doyle
*/ */
class BookTest extends PHPUnit_Framework_TestCase class BookTest extends PHPUnit_Framework_TestCase
{ {
public function testGetBookCount () public function testGetBookCount ()
{ {
$this->assertEquals (14, Book::getBookCount ()); $this->assertEquals (14, Book::getBookCount ());
} }
public function testGetCount () public function testGetCount ()
{ {
$entryArray = Book::getCount (); $entryArray = Book::getCount ();
$this->assertEquals (2, count($entryArray)); $this->assertEquals (2, count($entryArray));
$entryAllBooks = $entryArray [0]; $entryAllBooks = $entryArray [0];
$this->assertEquals ("Alphabetical index of the 14 books", $entryAllBooks->content); $this->assertEquals ("Alphabetical index of the 14 books", $entryAllBooks->content);
$entryRecentBooks = $entryArray [1]; $entryRecentBooks = $entryArray [1];
$this->assertEquals ("50 most recent books", $entryRecentBooks->content); $this->assertEquals ("50 most recent books", $entryRecentBooks->content);
} }
public function testGetCountRecent () public function testGetCountRecent ()
{ {
global $config; global $config;
$config['cops_recentbooks_limit'] = 0; $config['cops_recentbooks_limit'] = 0;
$entryArray = Book::getCount (); $entryArray = Book::getCount ();
$this->assertEquals (1, count($entryArray)); $this->assertEquals (1, count($entryArray));
$config['cops_recentbooks_limit'] = 2; $config['cops_recentbooks_limit'] = 2;
$entryArray = Book::getCount (); $entryArray = Book::getCount ();
$entryRecentBooks = $entryArray [1]; $entryRecentBooks = $entryArray [1];
$this->assertEquals ("2 most recent books", $entryRecentBooks->content); $this->assertEquals ("2 most recent books", $entryRecentBooks->content);
$config['cops_recentbooks_limit'] = 50; $config['cops_recentbooks_limit'] = 50;
} }
public function testGetBooksByAuthor () public function testGetBooksByAuthor ()
{ {
// All book by Arthur Conan Doyle // All book by Arthur Conan Doyle
global $config; global $config;
$config['cops_max_item_per_page'] = 5; $config['cops_max_item_per_page'] = 5;
list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 1); list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 1);
$this->assertEquals (5, count($entryArray)); $this->assertEquals (5, count($entryArray));
$this->assertEquals (8, $totalNumber); $this->assertEquals (8, $totalNumber);
list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 2); list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 2);
$this->assertEquals (3, count($entryArray)); $this->assertEquals (3, count($entryArray));
$this->assertEquals (8, $totalNumber); $this->assertEquals (8, $totalNumber);
$config['cops_max_item_per_page'] = -1; $config['cops_max_item_per_page'] = -1;
list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, -1); list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, -1);
$this->assertEquals (8, count($entryArray)); $this->assertEquals (8, count($entryArray));
$this->assertEquals (-1, $totalNumber); $this->assertEquals (-1, $totalNumber);
} }
public function testGetBooksBySeries () public function testGetBooksBySeries ()
{ {
// All book from the Sherlock Holmes series // All book from the Sherlock Holmes series
@ -82,10 +82,10 @@ class BookTest extends PHPUnit_Framework_TestCase
$this->assertEquals (7, count($entryArray)); $this->assertEquals (7, count($entryArray));
$this->assertEquals (-1, $totalNumber); $this->assertEquals (-1, $totalNumber);
} }
public function testGetBooksByPublisher () public function testGetBooksByPublisher ()
{ {
// All books from Strand Magazine // All books from Strand Magazine
list ($entryArray, $totalNumber) = Book::getBooksByPublisher (6, -1); list ($entryArray, $totalNumber) = Book::getBooksByPublisher (6, -1);
$this->assertEquals (8, count($entryArray)); $this->assertEquals (8, count($entryArray));
$this->assertEquals (-1, $totalNumber); $this->assertEquals (-1, $totalNumber);
@ -98,7 +98,7 @@ class BookTest extends PHPUnit_Framework_TestCase
$this->assertEquals (14, count($entryArray)); $this->assertEquals (14, count($entryArray));
$this->assertEquals (-1, $totalNumber); $this->assertEquals (-1, $totalNumber);
} }
public function testGetBooksByLanguage () public function testGetBooksByLanguage ()
{ {
// All english book (= all books) // All english book (= all books)
@ -106,14 +106,14 @@ class BookTest extends PHPUnit_Framework_TestCase
$this->assertEquals (14, count($entryArray)); $this->assertEquals (14, count($entryArray));
$this->assertEquals (-1, $totalNumber); $this->assertEquals (-1, $totalNumber);
} }
public function testGetAllBooks () public function testGetAllBooks ()
{ {
// All books by first letter // All books by first letter
$entryArray = Book::getAllBooks (); $entryArray = Book::getAllBooks ();
$this->assertCount (9, $entryArray); $this->assertCount (9, $entryArray);
} }
public function testGetBooksByStartingLetter () public function testGetBooksByStartingLetter ()
{ {
// All books by first letter // All books by first letter
@ -121,26 +121,26 @@ class BookTest extends PHPUnit_Framework_TestCase
$this->assertEquals (-1, $totalNumber); $this->assertEquals (-1, $totalNumber);
$this->assertCount (3, $entryArray); $this->assertCount (3, $entryArray);
} }
public function testGetBookByDataId () public function testGetBookByDataId ()
{ {
$book = Book::getBookByDataId (17); $book = Book::getBookByDataId (17);
$this->assertEquals ("Alice's Adventures in Wonderland", $book->getTitle ()); $this->assertEquals ("Alice's Adventures in Wonderland", $book->getTitle ());
} }
public function testGetAllRecentBooks () public function testGetAllRecentBooks ()
{ {
// All recent books // All recent books
global $config; global $config;
$config['cops_recentbooks_limit'] = 2; $config['cops_recentbooks_limit'] = 2;
$entryArray = Book::getAllRecentBooks (); $entryArray = Book::getAllRecentBooks ();
$this->assertCount (2, $entryArray); $this->assertCount (2, $entryArray);
$config['cops_recentbooks_limit'] = 50; $config['cops_recentbooks_limit'] = 50;
$entryArray = Book::getAllRecentBooks (); $entryArray = Book::getAllRecentBooks ();
$this->assertCount (14, $entryArray); $this->assertCount (14, $entryArray);
} }
@ -162,7 +162,7 @@ class BookTest extends PHPUnit_Framework_TestCase
$this->assertEquals ("&#9733;&#9733;&#9733;&#9733;&#9734;", $book->getRating ()); $this->assertEquals ("&#9733;&#9733;&#9733;&#9733;&#9734;", $book->getRating ());
$this->assertEquals ("Strand Magazine", $book->getPublisher()->name); $this->assertEquals ("Strand Magazine", $book->getPublisher()->name);
} }
public function testGetMostInterestingDataToSendToKindle () public function testGetMostInterestingDataToSendToKindle ()
{ {
// Get Alice (available as MOBI, PDF, EPUB in that order) // Get Alice (available as MOBI, PDF, EPUB in that order)
@ -176,11 +176,11 @@ class BookTest extends PHPUnit_Framework_TestCase
$data = $book->GetMostInterestingDataToSendToKindle (); $data = $book->GetMostInterestingDataToSendToKindle ();
$this->assertEquals ("EPUB", $data->format); $this->assertEquals ("EPUB", $data->format);
} }
public function testGetDataById () public function testGetDataById ()
{ {
global $config; global $config;
// Get Alice MOBI=>17, PDF=>19, EPUB=>20 // Get Alice MOBI=>17, PDF=>19, EPUB=>20
$book = Book::getBookById(17); $book = Book::getBookById(17);
$data = $book->getDataById (17); $data = $book->getDataById (17);
@ -190,7 +190,7 @@ class BookTest extends PHPUnit_Framework_TestCase
$this->assertEquals ("Carroll, Lewis - Alice's Adventures in Wonderland.epub", $data->getUpdatedFilenameEpub ()); $this->assertEquals ("Carroll, Lewis - Alice's Adventures in Wonderland.epub", $data->getUpdatedFilenameEpub ());
$this->assertEquals ("Carroll, Lewis - Alice's Adventures in Wonderland.kepub.epub", $data->getUpdatedFilenameKepub ()); $this->assertEquals ("Carroll, Lewis - Alice's Adventures in Wonderland.kepub.epub", $data->getUpdatedFilenameKepub ());
$this->assertEquals (dirname(__FILE__) . "/BaseWithSomeBooks/Lewis Carroll/Alice's Adventures in Wonderland (17)/Alice's Adventures in Wonderland - Lewis Carroll.epub", $data->getLocalPath ()); $this->assertEquals (dirname(__FILE__) . "/BaseWithSomeBooks/Lewis Carroll/Alice's Adventures in Wonderland (17)/Alice's Adventures in Wonderland - Lewis Carroll.epub", $data->getLocalPath ());
$config['cops_use_url_rewriting'] = "1"; $config['cops_use_url_rewriting'] = "1";
$config['cops_provide_kepub'] = "1"; $config['cops_provide_kepub'] = "1";
$_SERVER["HTTP_USER_AGENT"] = "Kobo"; $_SERVER["HTTP_USER_AGENT"] = "Kobo";
@ -200,35 +200,35 @@ class BookTest extends PHPUnit_Framework_TestCase
$config['cops_use_url_rewriting'] = "0"; $config['cops_use_url_rewriting'] = "0";
$this->assertEquals ("fetch.php?data=20&type=epub&id=17", $data->getHtmlLink ()); $this->assertEquals ("fetch.php?data=20&type=epub&id=17", $data->getHtmlLink ());
} }
public function testTypeaheadSearch () public function testTypeaheadSearch ()
{ {
$_GET["query"] = "fic"; $_GET["query"] = "fic";
$_GET["search"] = "1"; $_GET["search"] = "1";
$array = getJson (); $array = getJson ();
$this->assertCount (3, $array); $this->assertCount (3, $array);
$this->assertEquals ("2 tags", $array[0]["title"]); $this->assertEquals ("2 tags", $array[0]["title"]);
$this->assertEquals ("Fiction", $array[1]["title"]); $this->assertEquals ("Fiction", $array[1]["title"]);
$this->assertEquals ("Science Fiction", $array[2]["title"]); $this->assertEquals ("Science Fiction", $array[2]["title"]);
$_GET["query"] = "car"; $_GET["query"] = "car";
$_GET["search"] = "1"; $_GET["search"] = "1";
$array = getJson (); $array = getJson ();
$this->assertCount (4, $array); $this->assertCount (4, $array);
$this->assertEquals ("1 book", $array[0]["title"]); $this->assertEquals ("1 book", $array[0]["title"]);
$this->assertEquals ("A Study in Scarlet", $array[1]["title"]); $this->assertEquals ("A Study in Scarlet", $array[1]["title"]);
$this->assertEquals ("1 author", $array[2]["title"]); $this->assertEquals ("1 author", $array[2]["title"]);
$this->assertEquals ("Carroll, Lewis", $array[3]["title"]); $this->assertEquals ("Carroll, Lewis", $array[3]["title"]);
$_GET["query"] = "art"; $_GET["query"] = "art";
$_GET["search"] = "1"; $_GET["search"] = "1";
$array = getJson (); $array = getJson ();
$this->assertCount (4, $array); $this->assertCount (4, $array);
$this->assertEquals ("1 author", $array[0]["title"]); $this->assertEquals ("1 author", $array[0]["title"]);
$this->assertEquals ("Doyle, Arthur Conan", $array[1]["title"]); $this->assertEquals ("Doyle, Arthur Conan", $array[1]["title"]);
@ -244,23 +244,23 @@ class BookTest extends PHPUnit_Framework_TestCase
$this->assertEquals ("2 publishers", $array[0]["title"]); $this->assertEquals ("2 publishers", $array[0]["title"]);
$this->assertEquals ("Macmillan and Co. London", $array[1]["title"]); $this->assertEquals ("Macmillan and Co. London", $array[1]["title"]);
$this->assertEquals ("Macmillan Publishers USA", $array[2]["title"]); $this->assertEquals ("Macmillan Publishers USA", $array[2]["title"]);
$_GET["query"] = NULL; $_GET["query"] = NULL;
$_GET["search"] = NULL; $_GET["search"] = NULL;
} }
public function testTypeaheadSearchMultiDatabase () public function testTypeaheadSearchMultiDatabase ()
{ {
global $config; global $config;
$_GET["query"] = "art"; $_GET["query"] = "art";
$_GET["search"] = "1"; $_GET["search"] = "1";
$_GET["multi"] = "1"; $_GET["multi"] = "1";
$config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/", $config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/",
"One book" => dirname(__FILE__) . "/BaseWithOneBook/"); "One book" => dirname(__FILE__) . "/BaseWithOneBook/");
$array = getJson (); $array = getJson ();
$this->assertCount (4, $array); $this->assertCount (4, $array);
$this->assertEquals ("Some books", $array[0]["title"]); $this->assertEquals ("Some books", $array[0]["title"]);
$this->assertEquals ("No book", $array[1]["title"]); $this->assertEquals ("No book", $array[1]["title"]);
@ -270,9 +270,9 @@ class BookTest extends PHPUnit_Framework_TestCase
$_GET["query"] = NULL; $_GET["query"] = NULL;
$_GET["search"] = NULL; $_GET["search"] = NULL;
} }
public function tearDown () { public function tearDown () {
Base::clearDb (); Base::clearDb ();
} }
} }

View file

@ -10,7 +10,7 @@ require_once (dirname(__FILE__) . "/config_test.php");
require_once (dirname(__FILE__) . "/../book.php"); require_once (dirname(__FILE__) . "/../book.php");
class PageMultiDatabaseTest extends PHPUnit_Framework_TestCase class PageMultiDatabaseTest extends PHPUnit_Framework_TestCase
{ {
public function testPageIndex () public function testPageIndex ()
{ {
global $config; global $config;
@ -20,10 +20,10 @@ class PageMultiDatabaseTest extends PHPUnit_Framework_TestCase
$query = NULL; $query = NULL;
$qid = NULL; $qid = NULL;
$n = "1"; $n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ($config['cops_title_default'], $currentPage->title); $this->assertEquals ($config['cops_title_default'], $currentPage->title);
$this->assertCount (2, $currentPage->entryArray); $this->assertCount (2, $currentPage->entryArray);
$this->assertEquals ("Some books", $currentPage->entryArray [0]->title); $this->assertEquals ("Some books", $currentPage->entryArray [0]->title);
@ -32,7 +32,7 @@ class PageMultiDatabaseTest extends PHPUnit_Framework_TestCase
$this->assertEquals ("1 book", $currentPage->entryArray [1]->content); $this->assertEquals ("1 book", $currentPage->entryArray [1]->content);
$this->assertFalse ($currentPage->ContainsBook ()); $this->assertFalse ($currentPage->ContainsBook ());
} }
public function testPageSearchXXX () public function testPageSearchXXX ()
{ {
global $config; global $config;
@ -42,10 +42,10 @@ class PageMultiDatabaseTest extends PHPUnit_Framework_TestCase
$query = "art"; $query = "art";
$qid = NULL; $qid = NULL;
$n = "1"; $n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Search result for *art*", $currentPage->title); $this->assertEquals ("Search result for *art*", $currentPage->title);
$this->assertCount (2, $currentPage->entryArray); $this->assertCount (2, $currentPage->entryArray);
$this->assertEquals ("Some books", $currentPage->entryArray [0]->title); $this->assertEquals ("Some books", $currentPage->entryArray [0]->title);
@ -54,7 +54,7 @@ class PageMultiDatabaseTest extends PHPUnit_Framework_TestCase
$this->assertEquals ("1 book", $currentPage->entryArray [1]->content); $this->assertEquals ("1 book", $currentPage->entryArray [1]->content);
$this->assertFalse ($currentPage->ContainsBook ()); $this->assertFalse ($currentPage->ContainsBook ());
} }
public static function tearDownAfterClass () { public static function tearDownAfterClass () {
Base::clearDb (); Base::clearDb ();
} }

View file

@ -10,7 +10,7 @@ require_once (dirname(__FILE__) . "/config_test.php");
require_once (dirname(__FILE__) . "/../book.php"); require_once (dirname(__FILE__) . "/../book.php");
class PageTest extends PHPUnit_Framework_TestCase class PageTest extends PHPUnit_Framework_TestCase
{ {
public function testPageIndex () public function testPageIndex ()
{ {
global $config; global $config;
@ -18,10 +18,10 @@ class PageTest extends PHPUnit_Framework_TestCase
$query = NULL; $query = NULL;
$qid = NULL; $qid = NULL;
$n = "1"; $n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ($config['cops_title_default'], $currentPage->title); $this->assertEquals ($config['cops_title_default'], $currentPage->title);
$this->assertCount (7, $currentPage->entryArray); $this->assertCount (7, $currentPage->entryArray);
$this->assertEquals ("Authors", $currentPage->entryArray [0]->title); $this->assertEquals ("Authors", $currentPage->entryArray [0]->title);
@ -40,7 +40,7 @@ class PageTest extends PHPUnit_Framework_TestCase
$this->assertEquals ("50 most recent books", $currentPage->entryArray [6]->content); $this->assertEquals ("50 most recent books", $currentPage->entryArray [6]->content);
$this->assertFalse ($currentPage->ContainsBook ()); $this->assertFalse ($currentPage->ContainsBook ());
} }
public function testPageIndexWithCustomColumn () public function testPageIndexWithCustomColumn ()
{ {
global $config; global $config;
@ -48,125 +48,125 @@ class PageTest extends PHPUnit_Framework_TestCase
$query = NULL; $query = NULL;
$qid = NULL; $qid = NULL;
$n = "1"; $n = "1";
$config['cops_calibre_custom_column'] = array ("type1"); $config['cops_calibre_custom_column'] = array ("type1");
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertCount (8, $currentPage->entryArray); $this->assertCount (8, $currentPage->entryArray);
$this->assertEquals ("Type1", $currentPage->entryArray [5]->title); $this->assertEquals ("Type1", $currentPage->entryArray [5]->title);
$this->assertEquals ("Alphabetical index of the 2 tags", $currentPage->entryArray [5]->content); $this->assertEquals ("Alphabetical index of the 2 tags", $currentPage->entryArray [5]->content);
$config['cops_calibre_custom_column'] = array ("type2"); $config['cops_calibre_custom_column'] = array ("type2");
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertCount (8, $currentPage->entryArray); $this->assertCount (8, $currentPage->entryArray);
$this->assertEquals ("Type2", $currentPage->entryArray [5]->title); $this->assertEquals ("Type2", $currentPage->entryArray [5]->title);
$this->assertEquals ("Alphabetical index of the 3 tags", $currentPage->entryArray [5]->content); $this->assertEquals ("Alphabetical index of the 3 tags", $currentPage->entryArray [5]->content);
$config['cops_calibre_custom_column'] = array ("type4"); $config['cops_calibre_custom_column'] = array ("type4");
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertCount (8, $currentPage->entryArray); $this->assertCount (8, $currentPage->entryArray);
$this->assertEquals ("Type4", $currentPage->entryArray [5]->title); $this->assertEquals ("Type4", $currentPage->entryArray [5]->title);
$this->assertEquals ("Alphabetical index of the 2 tags", $currentPage->entryArray [5]->content); $this->assertEquals ("Alphabetical index of the 2 tags", $currentPage->entryArray [5]->content);
$config['cops_calibre_custom_column'] = array ("type1", "type2", "type4"); $config['cops_calibre_custom_column'] = array ("type1", "type2", "type4");
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertCount (10, $currentPage->entryArray); $this->assertCount (10, $currentPage->entryArray);
$config['cops_calibre_custom_column'] = array (); $config['cops_calibre_custom_column'] = array ();
} }
public function testPageAllCustom () public function testPageAllCustom ()
{ {
$page = Base::PAGE_ALL_CUSTOMS; $page = Base::PAGE_ALL_CUSTOMS;
$query = NULL; $query = NULL;
$qid = NULL; $qid = NULL;
$n = "1"; $n = "1";
$_GET ["custom"] = "1"; $_GET ["custom"] = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Type4", $currentPage->title); $this->assertEquals ("Type4", $currentPage->title);
$this->assertCount (2, $currentPage->entryArray); $this->assertCount (2, $currentPage->entryArray);
$this->assertEquals ("SeriesLike", $currentPage->entryArray [0]->title); $this->assertEquals ("SeriesLike", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ()); $this->assertFalse ($currentPage->ContainsBook ());
$_GET ["custom"] = "2"; $_GET ["custom"] = "2";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Type2", $currentPage->title); $this->assertEquals ("Type2", $currentPage->title);
$this->assertCount (3, $currentPage->entryArray); $this->assertCount (3, $currentPage->entryArray);
$this->assertEquals ("tag1", $currentPage->entryArray [0]->title); $this->assertEquals ("tag1", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ()); $this->assertFalse ($currentPage->ContainsBook ());
$_GET ["custom"] = "3"; $_GET ["custom"] = "3";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Type1", $currentPage->title); $this->assertEquals ("Type1", $currentPage->title);
$this->assertCount (2, $currentPage->entryArray); $this->assertCount (2, $currentPage->entryArray);
$this->assertEquals ("other", $currentPage->entryArray [0]->title); $this->assertEquals ("other", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ()); $this->assertFalse ($currentPage->ContainsBook ());
$_GET ["custom"] = NULL; $_GET ["custom"] = NULL;
} }
public function testPageCustomDetail () public function testPageCustomDetail ()
{ {
$page = Base::PAGE_CUSTOM_DETAIL; $page = Base::PAGE_CUSTOM_DETAIL;
$query = NULL; $query = NULL;
$qid = "1"; $qid = "1";
$n = "1"; $n = "1";
$_GET ["custom"] = "1"; $_GET ["custom"] = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("SeriesLike", $currentPage->title); $this->assertEquals ("SeriesLike", $currentPage->title);
$this->assertCount (2, $currentPage->entryArray); $this->assertCount (2, $currentPage->entryArray);
$this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title);
$this->assertTrue ($currentPage->ContainsBook ()); $this->assertTrue ($currentPage->ContainsBook ());
$_GET ["custom"] = "2"; $_GET ["custom"] = "2";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("tag1", $currentPage->title); $this->assertEquals ("tag1", $currentPage->title);
$this->assertCount (2, $currentPage->entryArray); $this->assertCount (2, $currentPage->entryArray);
$this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title);
$this->assertTrue ($currentPage->ContainsBook ()); $this->assertTrue ($currentPage->ContainsBook ());
$_GET ["custom"] = "3"; $_GET ["custom"] = "3";
$qid = "2"; $qid = "2";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("other", $currentPage->title); $this->assertEquals ("other", $currentPage->title);
$this->assertCount (1, $currentPage->entryArray); $this->assertCount (1, $currentPage->entryArray);
$this->assertEquals ("A Study in Scarlet", $currentPage->entryArray [0]->title); $this->assertEquals ("A Study in Scarlet", $currentPage->entryArray [0]->title);
$this->assertTrue ($currentPage->ContainsBook ()); $this->assertTrue ($currentPage->ContainsBook ());
$_GET ["custom"] = NULL; $_GET ["custom"] = NULL;
} }
public function testPageAllAuthors () public function testPageAllAuthors ()
{ {
global $config; global $config;
@ -174,44 +174,44 @@ class PageTest extends PHPUnit_Framework_TestCase
$query = NULL; $query = NULL;
$qid = NULL; $qid = NULL;
$n = "1"; $n = "1";
$config['cops_author_split_first_letter'] = "0"; $config['cops_author_split_first_letter'] = "0";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Authors", $currentPage->title); $this->assertEquals ("Authors", $currentPage->title);
$this->assertCount (5, $currentPage->entryArray); $this->assertCount (5, $currentPage->entryArray);
$this->assertEquals ("Carroll, Lewis", $currentPage->entryArray [0]->title); $this->assertEquals ("Carroll, Lewis", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ()); $this->assertFalse ($currentPage->ContainsBook ());
$config['cops_author_split_first_letter'] = "1"; $config['cops_author_split_first_letter'] = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Authors", $currentPage->title); $this->assertEquals ("Authors", $currentPage->title);
$this->assertCount (4, $currentPage->entryArray); $this->assertCount (4, $currentPage->entryArray);
$this->assertEquals ("C", $currentPage->entryArray [0]->title); $this->assertEquals ("C", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ()); $this->assertFalse ($currentPage->ContainsBook ());
} }
public function testPageAuthorsFirstLetter () public function testPageAuthorsFirstLetter ()
{ {
$page = Base::PAGE_AUTHORS_FIRST_LETTER; $page = Base::PAGE_AUTHORS_FIRST_LETTER;
$query = NULL; $query = NULL;
$qid = "C"; $qid = "C";
$n = "1"; $n = "1";
// Author Lewis Carroll // Author Lewis Carroll
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("1 author starting with C", $currentPage->title); $this->assertEquals ("1 author starting with C", $currentPage->title);
$this->assertCount (1, $currentPage->entryArray); $this->assertCount (1, $currentPage->entryArray);
$this->assertFalse ($currentPage->ContainsBook ()); $this->assertFalse ($currentPage->ContainsBook ());
} }
public function testPageAuthorsDetail () public function testPageAuthorsDetail ()
{ {
global $config; global $config;
@ -220,47 +220,47 @@ class PageTest extends PHPUnit_Framework_TestCase
$qid = "1"; $qid = "1";
$n = "1"; $n = "1";
$_SERVER['QUERY_STRING'] = "page=" . Base::PAGE_AUTHOR_DETAIL . "&id=1&n=1"; $_SERVER['QUERY_STRING'] = "page=" . Base::PAGE_AUTHOR_DETAIL . "&id=1&n=1";
$config['cops_max_item_per_page'] = 2; $config['cops_max_item_per_page'] = 2;
// First page // First page
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Doyle, Arthur Conan", $currentPage->title); $this->assertEquals ("Doyle, Arthur Conan", $currentPage->title);
$this->assertEquals (4, $currentPage->getMaxPage ()); $this->assertEquals (4, $currentPage->getMaxPage ());
$this->assertCount (2, $currentPage->entryArray); $this->assertCount (2, $currentPage->entryArray);
$this->assertTrue ($currentPage->ContainsBook ()); $this->assertTrue ($currentPage->ContainsBook ());
$this->assertTrue ($currentPage->IsPaginated ()); $this->assertTrue ($currentPage->IsPaginated ());
$this->assertNull ($currentPage->getPrevLink ()); $this->assertNull ($currentPage->getPrevLink ());
// Last page // Last page
$config['cops_max_item_per_page'] = 5; $config['cops_max_item_per_page'] = 5;
$n = "2"; $n = "2";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Doyle, Arthur Conan", $currentPage->title); $this->assertEquals ("Doyle, Arthur Conan", $currentPage->title);
$this->assertEquals (2, $currentPage->getMaxPage ()); $this->assertEquals (2, $currentPage->getMaxPage ());
$this->assertCount (3, $currentPage->entryArray); $this->assertCount (3, $currentPage->entryArray);
$this->assertTrue ($currentPage->ContainsBook ()); $this->assertTrue ($currentPage->ContainsBook ());
$this->assertTrue ($currentPage->IsPaginated ()); $this->assertTrue ($currentPage->IsPaginated ());
$this->assertNull ($currentPage->getNextLink ()); $this->assertNull ($currentPage->getNextLink ());
// No pagination // No pagination
$config['cops_max_item_per_page'] = -1; $config['cops_max_item_per_page'] = -1;
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Doyle, Arthur Conan", $currentPage->title); $this->assertEquals ("Doyle, Arthur Conan", $currentPage->title);
$this->assertCount (8, $currentPage->entryArray); $this->assertCount (8, $currentPage->entryArray);
$this->assertTrue ($currentPage->ContainsBook ()); $this->assertTrue ($currentPage->ContainsBook ());
$this->assertFalse ($currentPage->IsPaginated ()); $this->assertFalse ($currentPage->IsPaginated ());
} }
public function testPageAllBooks () public function testPageAllBooks ()
{ {
global $config; global $config;
@ -268,19 +268,19 @@ class PageTest extends PHPUnit_Framework_TestCase
$query = NULL; $query = NULL;
$qid = NULL; $qid = NULL;
$n = "1"; $n = "1";
$config['cops_titles_split_first_letter'] = 0; $config['cops_titles_split_first_letter'] = 0;
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("All books", $currentPage->title); $this->assertEquals ("All books", $currentPage->title);
$this->assertCount (14, $currentPage->entryArray); $this->assertCount (14, $currentPage->entryArray);
$this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title); $this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title);
$this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [1]->title); $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [1]->title);
$this->assertTrue ($currentPage->ContainsBook ()); $this->assertTrue ($currentPage->ContainsBook ());
$config['cops_titles_split_first_letter'] = 1; $config['cops_titles_split_first_letter'] = 1;
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
@ -291,48 +291,48 @@ class PageTest extends PHPUnit_Framework_TestCase
$this->assertEquals ("C", $currentPage->entryArray [1]->title); $this->assertEquals ("C", $currentPage->entryArray [1]->title);
$this->assertFalse ($currentPage->ContainsBook ()); $this->assertFalse ($currentPage->ContainsBook ());
} }
public function testPageAllBooksByLetter () public function testPageAllBooksByLetter ()
{ {
$page = Base::PAGE_ALL_BOOKS_LETTER; $page = Base::PAGE_ALL_BOOKS_LETTER;
$query = NULL; $query = NULL;
$qid = "C"; $qid = "C";
$n = "1"; $n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("2 books starting with C", $currentPage->title); $this->assertEquals ("2 books starting with C", $currentPage->title);
$this->assertCount (2, $currentPage->entryArray); $this->assertCount (2, $currentPage->entryArray);
$this->assertEquals ("The Call of the Wild", $currentPage->entryArray [0]->title); $this->assertEquals ("The Call of the Wild", $currentPage->entryArray [0]->title);
$this->assertTrue ($currentPage->ContainsBook ()); $this->assertTrue ($currentPage->ContainsBook ());
} }
public function testPageAllSeries () public function testPageAllSeries ()
{ {
$page = Base::PAGE_ALL_SERIES; $page = Base::PAGE_ALL_SERIES;
$query = NULL; $query = NULL;
$qid = NULL; $qid = NULL;
$n = "1"; $n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Series", $currentPage->title); $this->assertEquals ("Series", $currentPage->title);
$this->assertCount (3, $currentPage->entryArray); $this->assertCount (3, $currentPage->entryArray);
$this->assertEquals ("D'Artagnan Romances", $currentPage->entryArray [0]->title); $this->assertEquals ("D'Artagnan Romances", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ()); $this->assertFalse ($currentPage->ContainsBook ());
} }
public function testPageSeriesDetail () public function testPageSeriesDetail ()
{ {
$page = Base::PAGE_SERIE_DETAIL; $page = Base::PAGE_SERIE_DETAIL;
$query = NULL; $query = NULL;
$qid = "1"; $qid = "1";
$n = "1"; $n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Sherlock Holmes", $currentPage->title); $this->assertEquals ("Sherlock Holmes", $currentPage->title);
$this->assertCount (7, $currentPage->entryArray); $this->assertCount (7, $currentPage->entryArray);
$this->assertEquals ("A Study in Scarlet", $currentPage->entryArray [0]->title); $this->assertEquals ("A Study in Scarlet", $currentPage->entryArray [0]->title);
@ -345,10 +345,10 @@ class PageTest extends PHPUnit_Framework_TestCase
$query = NULL; $query = NULL;
$qid = NULL; $qid = NULL;
$n = "1"; $n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Publishers", $currentPage->title); $this->assertEquals ("Publishers", $currentPage->title);
$this->assertCount (5, $currentPage->entryArray); $this->assertCount (5, $currentPage->entryArray);
$this->assertEquals ("D. Appleton and Company", $currentPage->entryArray [0]->title); $this->assertEquals ("D. Appleton and Company", $currentPage->entryArray [0]->title);
@ -361,10 +361,10 @@ class PageTest extends PHPUnit_Framework_TestCase
$query = NULL; $query = NULL;
$qid = "6"; $qid = "6";
$n = "1"; $n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Strand Magazine", $currentPage->title); $this->assertEquals ("Strand Magazine", $currentPage->title);
$this->assertCount (8, $currentPage->entryArray); $this->assertCount (8, $currentPage->entryArray);
$this->assertEquals ("The Return of Sherlock Holmes", $currentPage->entryArray [0]->title); $this->assertEquals ("The Return of Sherlock Holmes", $currentPage->entryArray [0]->title);
@ -378,26 +378,26 @@ class PageTest extends PHPUnit_Framework_TestCase
$query = NULL; $query = NULL;
$qid = NULL; $qid = NULL;
$n = "1"; $n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Tags", $currentPage->title); $this->assertEquals ("Tags", $currentPage->title);
$this->assertCount (10, $currentPage->entryArray); $this->assertCount (10, $currentPage->entryArray);
$this->assertEquals ("Action & Adventure", $currentPage->entryArray [0]->title); $this->assertEquals ("Action & Adventure", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ()); $this->assertFalse ($currentPage->ContainsBook ());
} }
public function testPageTagDetail () public function testPageTagDetail ()
{ {
$page = Base::PAGE_TAG_DETAIL; $page = Base::PAGE_TAG_DETAIL;
$query = NULL; $query = NULL;
$qid = "1"; $qid = "1";
$n = "1"; $n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Fiction", $currentPage->title); $this->assertEquals ("Fiction", $currentPage->title);
$this->assertCount (14, $currentPage->entryArray); $this->assertCount (14, $currentPage->entryArray);
$this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title); $this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title);
@ -410,107 +410,107 @@ class PageTest extends PHPUnit_Framework_TestCase
$query = NULL; $query = NULL;
$qid = NULL; $qid = NULL;
$n = "1"; $n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Languages", $currentPage->title); $this->assertEquals ("Languages", $currentPage->title);
$this->assertCount (1, $currentPage->entryArray); $this->assertCount (1, $currentPage->entryArray);
$this->assertEquals ("English", $currentPage->entryArray [0]->title); $this->assertEquals ("English", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ()); $this->assertFalse ($currentPage->ContainsBook ());
} }
public function testPageLanguageDetail () public function testPageLanguageDetail ()
{ {
$page = Base::PAGE_LANGUAGE_DETAIL; $page = Base::PAGE_LANGUAGE_DETAIL;
$query = NULL; $query = NULL;
$qid = "1"; $qid = "1";
$n = "1"; $n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("English", $currentPage->title); $this->assertEquals ("English", $currentPage->title);
$this->assertCount (14, $currentPage->entryArray); $this->assertCount (14, $currentPage->entryArray);
$this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title); $this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title);
$this->assertTrue ($currentPage->ContainsBook ()); $this->assertTrue ($currentPage->ContainsBook ());
} }
public function testPageRecent () public function testPageRecent ()
{ {
$page = Base::PAGE_ALL_RECENT_BOOKS; $page = Base::PAGE_ALL_RECENT_BOOKS;
$query = NULL; $query = NULL;
$qid = NULL; $qid = NULL;
$n = "1"; $n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Recent additions", $currentPage->title); $this->assertEquals ("Recent additions", $currentPage->title);
$this->assertCount (14, $currentPage->entryArray); $this->assertCount (14, $currentPage->entryArray);
$this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title);
$this->assertTrue ($currentPage->ContainsBook ()); $this->assertTrue ($currentPage->ContainsBook ());
// Test facets // Test facets
$_GET["tag"] = "Historical"; $_GET["tag"] = "Historical";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Recent additions", $currentPage->title); $this->assertEquals ("Recent additions", $currentPage->title);
$this->assertCount (2, $currentPage->entryArray); $this->assertCount (2, $currentPage->entryArray);
$this->assertEquals ("Twenty Years After", $currentPage->entryArray [0]->title); $this->assertEquals ("Twenty Years After", $currentPage->entryArray [0]->title);
$this->assertTrue ($currentPage->ContainsBook ()); $this->assertTrue ($currentPage->ContainsBook ());
$_GET["tag"] = "!Romance"; $_GET["tag"] = "!Romance";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Recent additions", $currentPage->title); $this->assertEquals ("Recent additions", $currentPage->title);
$this->assertCount (12, $currentPage->entryArray); $this->assertCount (12, $currentPage->entryArray);
$this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title);
$this->assertTrue ($currentPage->ContainsBook ()); $this->assertTrue ($currentPage->ContainsBook ());
$_GET["tag"] = NULL; $_GET["tag"] = NULL;
} }
public function testPageBookDetail () public function testPageBookDetail ()
{ {
$page = Base::PAGE_BOOK_DETAIL; $page = Base::PAGE_BOOK_DETAIL;
$query = NULL; $query = NULL;
$qid = "2"; $qid = "2";
$n = "1"; $n = "1";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("The Return of Sherlock Holmes", $currentPage->title); $this->assertEquals ("The Return of Sherlock Holmes", $currentPage->title);
$this->assertCount (0, $currentPage->entryArray); $this->assertCount (0, $currentPage->entryArray);
$this->assertFalse ($currentPage->ContainsBook ()); $this->assertFalse ($currentPage->ContainsBook ());
} }
public function testPageSearch () public function testPageSearch ()
{ {
$page = Base::PAGE_OPENSEARCH_QUERY; $page = Base::PAGE_OPENSEARCH_QUERY;
$query = "alice"; $query = "alice";
$qid = NULL; $qid = NULL;
$n = "1"; $n = "1";
// Only books returned // Only books returned
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Search result for *alice*", $currentPage->title); $this->assertEquals ("Search result for *alice*", $currentPage->title);
$this->assertCount (2, $currentPage->entryArray); $this->assertCount (2, $currentPage->entryArray);
$this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title);
$this->assertEquals ("Through the Looking Glass (And What Alice Found There)", $currentPage->entryArray [1]->title); $this->assertEquals ("Through the Looking Glass (And What Alice Found There)", $currentPage->entryArray [1]->title);
$this->assertTrue ($currentPage->ContainsBook ()); $this->assertTrue ($currentPage->ContainsBook ());
// Match Lewis Caroll & Scarlet // Match Lewis Caroll & Scarlet
$query = "car"; $query = "car";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Search result for *car*", $currentPage->title); $this->assertEquals ("Search result for *car*", $currentPage->title);
$this->assertCount (3, $currentPage->entryArray); $this->assertCount (3, $currentPage->entryArray);
$this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title);
@ -518,102 +518,102 @@ class PageTest extends PHPUnit_Framework_TestCase
$this->assertEquals ("Through the Looking Glass (And What Alice Found There)", $currentPage->entryArray [2]->title); $this->assertEquals ("Through the Looking Glass (And What Alice Found There)", $currentPage->entryArray [2]->title);
$this->assertTrue ($currentPage->ContainsBook ()); $this->assertTrue ($currentPage->ContainsBook ());
} }
public function testPageSearchScopeAuthors () public function testPageSearchScopeAuthors ()
{ {
$page = Base::PAGE_OPENSEARCH_QUERY; $page = Base::PAGE_OPENSEARCH_QUERY;
$qid = NULL; $qid = NULL;
$n = "1"; $n = "1";
$_GET ["scope"] = "author"; $_GET ["scope"] = "author";
// Match Lewis Carroll // Match Lewis Carroll
$query = "car"; $query = "car";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Search result for *car* in authors", $currentPage->title); $this->assertEquals ("Search result for *car* in authors", $currentPage->title);
$this->assertCount (1, $currentPage->entryArray); $this->assertCount (1, $currentPage->entryArray);
$this->assertEquals ("Carroll, Lewis", $currentPage->entryArray [0]->title); $this->assertEquals ("Carroll, Lewis", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ()); $this->assertFalse ($currentPage->ContainsBook ());
$_GET ["scope"] = NULL; $_GET ["scope"] = NULL;
} }
public function testPageSearchScopeSeries () public function testPageSearchScopeSeries ()
{ {
$page = Base::PAGE_OPENSEARCH_QUERY; $page = Base::PAGE_OPENSEARCH_QUERY;
$qid = NULL; $qid = NULL;
$n = "1"; $n = "1";
$_GET ["scope"] = "series"; $_GET ["scope"] = "series";
// Match Holmes // Match Holmes
$query = "hol"; $query = "hol";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Search result for *hol* in series", $currentPage->title); $this->assertEquals ("Search result for *hol* in series", $currentPage->title);
$this->assertCount (1, $currentPage->entryArray); $this->assertCount (1, $currentPage->entryArray);
$this->assertEquals ("Sherlock Holmes", $currentPage->entryArray [0]->title); $this->assertEquals ("Sherlock Holmes", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ()); $this->assertFalse ($currentPage->ContainsBook ());
$_GET ["scope"] = NULL; $_GET ["scope"] = NULL;
} }
public function testPageSearchScopeBooks () public function testPageSearchScopeBooks ()
{ {
$page = Base::PAGE_OPENSEARCH_QUERY; $page = Base::PAGE_OPENSEARCH_QUERY;
$qid = NULL; $qid = NULL;
$n = "1"; $n = "1";
$_GET ["scope"] = "book"; $_GET ["scope"] = "book";
// Match Holmes // Match Holmes
$query = "hol"; $query = "hol";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Search result for *hol* in books", $currentPage->title); $this->assertEquals ("Search result for *hol* in books", $currentPage->title);
$this->assertCount (4, $currentPage->entryArray); $this->assertCount (4, $currentPage->entryArray);
$this->assertTrue ($currentPage->ContainsBook ()); $this->assertTrue ($currentPage->ContainsBook ());
$_GET ["scope"] = NULL; $_GET ["scope"] = NULL;
} }
public function testPageSearchScopePublishers () public function testPageSearchScopePublishers ()
{ {
$page = Base::PAGE_OPENSEARCH_QUERY; $page = Base::PAGE_OPENSEARCH_QUERY;
$qid = NULL; $qid = NULL;
$n = "1"; $n = "1";
$_GET ["scope"] = "publisher"; $_GET ["scope"] = "publisher";
// Match Holmes // Match Holmes
$query = "millan"; $query = "millan";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Search result for *millan* in publishers", $currentPage->title); $this->assertEquals ("Search result for *millan* in publishers", $currentPage->title);
$this->assertCount (2, $currentPage->entryArray); $this->assertCount (2, $currentPage->entryArray);
$this->assertEquals ("Macmillan and Co. London", $currentPage->entryArray [0]->title); $this->assertEquals ("Macmillan and Co. London", $currentPage->entryArray [0]->title);
$this->assertFalse ($currentPage->ContainsBook ()); $this->assertFalse ($currentPage->ContainsBook ());
$_GET ["scope"] = NULL; $_GET ["scope"] = NULL;
} }
public function testPageSearchScopeTags () public function testPageSearchScopeTags ()
{ {
$page = Base::PAGE_OPENSEARCH_QUERY; $page = Base::PAGE_OPENSEARCH_QUERY;
$qid = NULL; $qid = NULL;
$n = "1"; $n = "1";
$_GET ["scope"] = "tag"; $_GET ["scope"] = "tag";
// Match Holmes // Match Holmes
$query = "fic"; $query = "fic";
$currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage = Page::getPage ($page, $qid, $query, $n);
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
$this->assertEquals ("Search result for *fic* in tags", $currentPage->title); $this->assertEquals ("Search result for *fic* in tags", $currentPage->title);
$this->assertCount (2, $currentPage->entryArray); $this->assertCount (2, $currentPage->entryArray);
$this->assertFalse ($currentPage->ContainsBook ()); $this->assertFalse ($currentPage->ContainsBook ());
$_GET ["scope"] = NULL; $_GET ["scope"] = NULL;
} }
} }