diff --git a/author.php b/author.php index 61c2e34..b498658 100644 --- a/author.php +++ b/author.php @@ -10,40 +10,40 @@ require_once('base.php'); class Author extends Base { 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 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"; - + public $id; public $name; public $sort; - + public function __construct($pid, $pname) { $this->id = $pid; $this->name = $pname; } - + public function getUri () { return "?page=".parent::PAGE_AUTHOR_DETAIL."&id=$this->id"; } - + public function getEntryId () { return self::ALL_AUTHORS_ID.":".$this->id; } - + public static function getEntryIdByLetter ($startingLetter) { return self::ALL_AUTHORS_ID.":letter:".$startingLetter; } public static function getCount() { $nAuthors = parent::getDb ()->query('select count(*) from authors')->fetchColumn(); - $entry = new Entry (localize("authors.title"), self::ALL_AUTHORS_ID, - str_format (localize("authors.alphabetical", $nAuthors), $nAuthors), "text", + $entry = new Entry (localize("authors.title"), self::ALL_AUTHORS_ID, + str_format (localize("authors.alphabetical", $nAuthors), $nAuthors), "text", array ( new LinkNavigation ("?page=".parent::PAGE_ALL_AUTHORS))); return $entry; } - + public static function getAllAuthorsByFirstLetter() { $result = parent::getDb ()->query('select substr (upper (sort), 1, 1) as title, count(*) as count from authors @@ -52,40 +52,40 @@ order by substr (upper (sort), 1, 1)'); $entryArray = array(); while ($post = $result->fetchObject ()) { - array_push ($entryArray, new Entry ($post->title, Author::getEntryIdByLetter ($post->title), - str_format (localize("authorword", $post->count), $post->count), "text", + array_push ($entryArray, new Entry ($post->title, Author::getEntryIdByLetter ($post->title), + str_format (localize("authorword", $post->count), $post->count), "text", array ( new LinkNavigation ("?page=".parent::PAGE_AUTHORS_FIRST_LETTER."&id=". rawurlencode ($post->title))))); } return $entryArray; } - + public static function getAuthorsByStartingLetter($letter) { return self::getEntryArray (self::SQL_AUTHORS_BY_FIRST_LETTER, array ($letter . "%")); } - + public static function getAllAuthors() { return self::getEntryArray (self::SQL_ALL_AUTHORS, array ()); } - + public static function getEntryArray ($query, $params) { list ($totalNumber, $result) = parent::executeQuery ($query, self::AUTHOR_COLUMNS, "", $params, -1); $entryArray = array(); while ($post = $result->fetchObject ()) { $author = new Author ($post->id, $post->sort); - array_push ($entryArray, new Entry ($post->sort, $author->getEntryId (), - str_format (localize("bookword", $post->count), $post->count), "text", + array_push ($entryArray, new Entry ($post->sort, $author->getEntryId (), + str_format (localize("bookword", $post->count), $post->count), "text", array ( new LinkNavigation ($author->getUri ())))); } return $entryArray; } - + public static function getAuthorById ($authorId) { $result = parent::getDb ()->prepare('select sort from authors where id = ?'); $result->execute (array ($authorId)); return new Author ($authorId, $result->fetchColumn ()); } - + public static function getAuthorByBookId ($bookId) { $result = parent::getDb ()->prepare('select authors.id as id, authors.sort as sort from authors, books_authors_link diff --git a/base.php b/base.php index c23e100..25f7a10 100644 --- a/base.php +++ b/base.php @@ -896,7 +896,7 @@ abstract class Base const COMPATIBILITY_XML_ALDIKO = "aldiko"; private static $db = NULL; - + public static function isMultipleDatabaseEnabled () { global $config; return is_array ($config['calibre_directory']); @@ -935,7 +935,7 @@ abstract class Base public static function getDbFileName ($database = NULL) { return self::getDbDirectory ($database) .'metadata.db'; } - + private static function error () { header("location: checkconfig.php?err=1"); exit(); @@ -962,7 +962,7 @@ abstract class Base public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL) { $totalResult = -1; - + if (is_null ($numberPerPage)) { $numberPerPage = getCurrentOption ("max_item_per_page"); } diff --git a/book.php b/book.php index e539920..271dfda 100644 --- a/book.php +++ b/book.php @@ -17,8 +17,8 @@ require_once('data.php'); require_once('resources/php-epub-meta/epub.php'); // Silly thing because PHP forbid string concatenation in class const -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 +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 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_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_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 SQL_BOOKS_LEFT_JOIN = SQL_BOOKS_LEFT_JOIN; const SQL_BOOKS_ALL = SQL_BOOKS_ALL; 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_QUERY = SQL_BOOKS_QUERY; const SQL_BOOKS_RECENT = SQL_BOOKS_RECENT; - + public $id; public $title; public $timestamp; @@ -81,7 +81,7 @@ class Book extends Base { public $languages = NULL; public $format = array (); - + public function __construct($line) { $this->id = $line->id; $this->title = $line->title; @@ -99,19 +99,19 @@ class Book extends Base { } $this->rating = $line->rating; } - + public function getEntryId () { return self::ALL_BOOKS_UUID.":".$this->uuid; } - + public static function getEntryIdByLetter ($startingLetter) { return self::ALL_BOOKS_ID.":letter:".$startingLetter; } - + public function getUri () { return "?page=".parent::PAGE_BOOK_DETAIL."&id=$this->id"; } - + public function getContentArray () { global $config; $i = 0; @@ -146,7 +146,7 @@ class Book extends Base { $link = new LinkNavigation ($serie->getUri ()); $su = $link->hrefXhtml (); } - + return array ("id" => $this->id, "hasCover" => $this->hasCover, "preferedData" => $preferedData, @@ -160,13 +160,13 @@ class Book extends Base { "seriesName" => $sn, "seriesIndex" => $this->seriesIndex, "seriesCompleteName" => $scn, - "seriesurl" => $su); - + "seriesurl" => $su); + } public function getFullContentArray () { global $config; $out = $this->getContentArray (); - + $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 ["content"] = $this->getComment (false); @@ -192,47 +192,47 @@ class Book extends Base { ; return $out; } - + public function getDetailUrl ($permalink = false) { $urlParam = $this->getUri (); if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB)); - return 'index.php' . $urlParam; + return 'index.php' . $urlParam; } - + public function getTitle () { return $this->title; } - + public function getAuthors () { if (is_null ($this->authors)) { $this->authors = Author::getAuthorByBookId ($this->id); } return $this->authors; } - + public static function getFilterString () { $filter = getURLParam ("tag", NULL); if (empty ($filter)) return ""; - + $exists = true; if (preg_match ("/^!(.*)$/", $filter, $matches)) { $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 . "')"; - + if (!$exists) { $result = "not " . $result; } - + return "and " . $result; } - + public function getAuthorsName () { return implode (", ", array_map (function ($author) { return $author->name; }, $this->getAuthors ())); } - + public function getPublisher () { if (is_null ($this->publisher)) { $this->publisher = Publisher::getPublisherByBookId ($this->id); @@ -246,7 +246,7 @@ class Book extends Base { } return $this->serie; } - + public function getLanguages () { $lang = array (); $result = parent::getDb ()->prepare('select languages.lang_code @@ -261,11 +261,11 @@ class Book extends Base { } return implode (", ", $lang); } - + public function getTags () { if (is_null ($this->tags)) { $this->tags = array (); - + $result = parent::getDb ()->prepare('select tags.id as id, name from books_tags_link, tags where tag = tags.id @@ -279,16 +279,16 @@ class Book extends Base { } return $this->tags; } - + public function getDatas () { if (is_null ($this->datas)) { $this->datas = array (); - + $result = parent::getDb ()->prepare('select id, format, name from data where book = ?'); $result->execute (array ($this->id)); - + while ($post = $result->fetchObject ()) { array_push ($this->datas, new Data ($post, $this)); @@ -296,7 +296,7 @@ class Book extends Base { } return $this->datas; } - + public function GetMostInterestingDataToSendToKindle () { $bestFormatForKindle = array ("EPUB", "PDF", "MOBI"); @@ -311,7 +311,7 @@ class Book extends Base { } return $bestData; } - + public function getDataById ($idData) { foreach ($this->getDatas () as $data) { @@ -322,11 +322,11 @@ class Book extends Base { return NULL; } - + public function getTagsName () { return implode (", ", array_map (function ($tag) { return $tag->name; }, $this->getTags ())); } - + public function getRating () { if (is_null ($this->rating) || $this->rating == 0) { return ""; @@ -340,7 +340,7 @@ class Book extends Base { } return $retour; } - + public function getPubDate () { if (is_null ($this->pubdate) || ($this->pubdate <= -58979923200)) { return ""; @@ -349,7 +349,7 @@ class Book extends Base { return date ("Y", $this->pubdate); } } - + public function getComment ($withSerie = true) { $addition = ""; $se = $this->getSerie (); @@ -365,7 +365,7 @@ class Book extends Base { return $addition . htmlspecialchars ($this->comment); } } - + public function getDataFormat ($format) { foreach ($this->getDatas () as $data) { @@ -376,7 +376,7 @@ class Book extends Base { } return NULL; } - + public function getFilePath ($extension, $idData = NULL, $relative = false) { $file = NULL; @@ -400,16 +400,16 @@ class Book extends Base { return $this->path."/".$file; } } - + public function getUpdatedEpub ($idData) { global $config; $data = $this->getDataById ($idData); - + try { $epub = new EPub ($data->getLocalPath ()); - + $epub->Title ($this->title); $authorArray = array (); foreach ($this->getAuthors() as $author) { @@ -436,18 +436,18 @@ class Book extends Base { echo "Exception : " . $e->getMessage(); } } - + public function getLinkArray () { $linkArray = array(); - + 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_THUMBNAIL_TYPE, "cover.jpg", NULL)); } - + foreach ($this->getDatas () as $data) { if ($data->isKnownType ()) @@ -455,26 +455,26 @@ class Book extends Base { array_push ($linkArray, $data->getDataLink (Link::OPDS_ACQUISITION_TYPE, $data->format)); } } - + foreach ($this->getAuthors () as $author) { array_push ($linkArray, new LinkNavigation ($author->getUri (), "related", str_format (localize ("bookentry.author"), localize ("splitByLetter.book.other"), $author->name))); } - + $serie = $this->getSerie (); if (!is_null ($serie)) { array_push ($linkArray, new LinkNavigation ($serie->getUri (), "related", str_format (localize ("content.series.data"), $this->seriesIndex, $serie->name))); } - + return $linkArray; } - - public function getEntry () { - return new EntryBook ($this->getTitle (), $this->getEntryId (), - $this->getComment (), "text/html", + + public function getEntry () { + return new EntryBook ($this->getTitle (), $this->getEntryId (), + $this->getComment (), "text/html", $this->getLinkArray (), $this); } - + public static function getBookCount($database = NULL) { $nBooks = parent::getDb ($database)->query('select count(*) from books')->fetchColumn(); return $nBooks; @@ -484,21 +484,21 @@ class Book extends Base { global $config; $nBooks = parent::getDb ()->query('select count(*) from books')->fetchColumn(); $result = array(); - $entry = new Entry (localize ("allbooks.title"), - self::ALL_BOOKS_ID, - str_format (localize ("allbooks.alphabetical", $nBooks), $nBooks), "text", + $entry = new Entry (localize ("allbooks.title"), + self::ALL_BOOKS_ID, + str_format (localize ("allbooks.alphabetical", $nBooks), $nBooks), "text", array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS))); array_push ($result, $entry); if ($config['cops_recentbooks_limit'] > 0) { - $entry = new Entry (localize ("recent.title"), - self::ALL_RECENT_BOOKS_ID, - str_format (localize ("recent.list"), $config['cops_recentbooks_limit']), "text", + $entry = new Entry (localize ("recent.title"), + self::ALL_RECENT_BOOKS_ID, + str_format (localize ("recent.list"), $config['cops_recentbooks_limit']), "text", array ( new LinkNavigation ("?page=".parent::PAGE_ALL_RECENT_BOOKS))); array_push ($result, $entry); } return $result; } - + public static function getBooksByAuthor($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) { return self::getEntryArray (self::SQL_BOOKS_BY_PUBLISHER, array ($publisherId), $n); } - + public static function getBooksBySeries($serieId, $n) { return self::getEntryArray (self::SQL_BOOKS_BY_SERIE, array ($serieId), $n); } - + public static function getBooksByTag($tagId, $n) { return self::getEntryArray (self::SQL_BOOKS_BY_TAG, array ($tagId), $n); } - + public static function getBooksByLanguage($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)); return self::getEntryArray ($query, array ($id), $n); } - + public static function getBookById($bookId) { $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ' from books ' . self::SQL_BOOKS_LEFT_JOIN . ' @@ -536,7 +536,7 @@ where books.id = ?'); } return NULL; } - + public static function getBookByDataId($dataId) { $result = parent::getDb ()->prepare('select ' . self::BOOK_COLUMNS . ', data.name, data.format from data, books ' . self::SQL_BOOKS_LEFT_JOIN . ' @@ -552,7 +552,7 @@ where data.book = books.id and data.id = ?'); } return NULL; } - + public static function getBooksByQuery($query, $n, $database = NULL) { return self::getEntryArray (self::SQL_BOOKS_QUERY, $query, $n, $database); } @@ -570,17 +570,17 @@ order by substr (upper (sort), 1, 1)"); $entryArray = array(); while ($post = $result->fetchObject ()) { - array_push ($entryArray, new Entry ($post->title, Book::getEntryIdByLetter ($post->title), - str_format (localize("bookword", $post->count), $post->count), "text", + array_push ($entryArray, new Entry ($post->title, Book::getEntryIdByLetter ($post->title), + str_format (localize("bookword", $post->count), $post->count), "text", array ( new LinkNavigation ("?page=".parent::PAGE_ALL_BOOKS_LETTER."&id=". rawurlencode ($post->title))))); } return $entryArray; } - + public static function getBooksByStartingLetter($letter, $n, $database = NULL, $numberPerPage = NULL) { 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) { list ($totalNumber, $result) = parent::executeQuery ($query, self::BOOK_COLUMNS, self::getFilterString (), $params, $n, $database, $numberPerPage); $entryArray = array(); @@ -592,7 +592,7 @@ order by substr (upper (sort), 1, 1)"); return array ($entryArray, $totalNumber); } - + public static function getAllRecentBooks() { global $config; $entryArray = self::getEntryArray (self::SQL_BOOKS_RECENT . $config['cops_recentbooks_limit'], array (), -1); @@ -611,11 +611,11 @@ function getJson ($complete = false) { $qid = getURLParam ("id"); $n = getURLParam ("n", "1"); $database = GetUrlParam (DB); - + if ($search) { $out = array (); $pagequery = Base::PAGE_OPENSEARCH_QUERY; - + // Special case when no databases were chosen, we search on all databases if (is_array ($config['calibre_directory']) && $multi === "1") { $i = 0; @@ -632,7 +632,7 @@ function getJson ($complete = false) { } return $out; } - + $arrayPublisher = Publisher::getAllPublishersByQuery ($query); $arrayTag = Tag::getAllTagsByQuery ($query, 1, NULL, 5); @@ -643,9 +643,9 @@ function getJson ($complete = false) { $arrayBook = Book::getBooksByStartingLetter ('%' . $query, 1, NULL, 5); - foreach (array ("book" => $arrayBook, - "author" => $arrayAuthor, - "series" => $arraySeries, + foreach (array ("book" => $arrayBook, + "author" => $arrayAuthor, + "series" => $arraySeries, "tag" => $arrayTag, "publisher" => $arrayPublisher) as $key => $array) { $i = 0; @@ -678,10 +678,10 @@ function getJson ($complete = false) { } return $out; } - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $out = array ( "title" => $currentPage->title); $entries = array (); foreach ($currentPage->entryArray as $entry) { @@ -711,7 +711,7 @@ function getJson ($complete = false) { $out ["maxPage"] = $currentPage->getMaxPage (); $out ["currentPage"] = $currentPage->n; } - if (!is_null (getURLParam ("complete")) || $complete) { + if (!is_null (getURLParam ("complete")) || $complete) { $out ["c"] = array ("version" => VERSION, "i18n" => array ( "coverAlt" => localize("i18n.coversection"), "authorsTitle" => localize("authors.title"), @@ -754,17 +754,17 @@ function getJson ($complete = false) { if ($currentPage->containsBook ()) { $out ["containsBook"] = 1; } - + $out["abouturl"] = "index.php" . addURLParameter ("?page=16", DB, $database); - + if ($page == Base::PAGE_ABOUT) { $temp = preg_replace ("/\About COPS\<\/h1\>/", "

About COPS " . VERSION . "

", file_get_contents('about.html')); $out ["fullhtml"] = $temp; } - + $out ["homeurl"] = "index.php"; if ($page != Base::PAGE_INDEX && !is_null ($database)) $out ["homeurl"] = $out ["homeurl"] . "?" . addURLParameter ("", DB, $database); - + return $out; } diff --git a/checkconfig.php b/checkconfig.php index aac84bc..456ec77 100644 --- a/checkconfig.php +++ b/checkconfig.php @@ -8,12 +8,12 @@ * @author Sébastien Lucas * */ - + require_once ("config.php"); require_once ("base.php"); - + header ("Content-Type:text/html; charset=UTF-8"); - + $err = getURLParam ("err", -1); $full = getURLParam ("full"); $error = NULL; @@ -51,7 +51,7 @@

Check if GD is properly installed and loaded

-

Check if Sqlite is properly installed and loaded

-

Check if libxml is properly installed and loaded

-

Check if the rendering will be done on client side or server side

-

- $database) { +foreach (Base::getDbList () as $name => $database) { ?>

Check if Calibre database path is not an URL

@@ -114,12 +114,12 @@ foreach (Base::getDbList () as $name => $database) {

Check if Calibre database file exists and is readable

-
  • Value of \$config['calibre_directory'] in config_local.php
  • Value of open_basedir in your php.ini
  • @@ -133,7 +133,7 @@ Please check

    Check if Calibre database file can be opened with PHP

    -

    Check if Calibre database file contains at least some of the needed tables

    - query("select count(*) FROM sqlite_master WHERE type='table' AND name in ('books', 'authors', 'tags', 'series')")->fetchColumn(); @@ -165,7 +165,7 @@ Please check

    Check if all Calibre books are found

    - prepare("select books.path || '/' || data.name || '.' || lower (format) as fullpath from data join books on data.book = books.id"); diff --git a/config_default.php b/config_default.php index 5ebcb41..5d49f6d 100644 --- a/config_default.php +++ b/config_default.php @@ -8,7 +8,7 @@ if (!isset($config)) $config = array(); - + /* * The directory containing calibre's metadata.db file, with sub-directories * 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'] = './'; - + /* * SPECIFIC TO NGINX * The internal directory set in nginx config file * Leave empty if you don't know what you're doing */ - $config['calibre_internal_directory'] = ''; + $config['calibre_internal_directory'] = ''; /* * Full URL prefix (with trailing /) * usefull especially for Opensearch where a full URL is often required * For example Mantano, Aldiko and Marvin require it. */ - $config['cops_full_url'] = ''; - + $config['cops_full_url'] = ''; + /* * Number of recent books to show */ - $config['cops_recentbooks_limit'] = '50'; - + $config['cops_recentbooks_limit'] = '50'; + /* * Catalog's author name */ @@ -56,12 +56,12 @@ * Catalog's title */ $config['cops_title_default'] = "COPS"; - + /* * Catalog's subtitle */ - $config['cops_subtitle_default'] = ""; - + $config['cops_subtitle_default'] = ""; + /* * Wich header to use when downloading books outside the web directory * Possible values are : @@ -70,12 +70,12 @@ * No value (default) : Let PHP handle the download */ $config['cops_x_accel_redirect'] = ""; - + /* * Height of thumbnail image for OPDS */ $config['cops_opds_thumbnail_height'] = "164"; - + /* * Height of thumbnail image for HTML */ @@ -93,21 +93,21 @@ * 0 : disable */ $config['cops_show_icons'] = "1"; - + /* - * Default timezone + * Default timezone * Check following link for other timezones : * http://www.php.net/manual/en/timezones.php */ $config['default_timezone'] = "Europe/Paris"; - + /* * Prefered format for HTML catalog * The two first will be displayed in book entries * The other only appear in book detail */ $config['cops_prefered_format'] = array ("EPUB", "PDF", "AZW3", "AZW", "MOBI", "CBR", "CBZ"); - + /* * use URL rewriting for downloading of ebook in HTML catalog * See Github wiki for more information @@ -115,7 +115,7 @@ * 0 : disable */ $config['cops_use_url_rewriting'] = "0"; - + /* * generate a invalid OPDS stream to allow bad OPDS client to use search * Example of non compliant OPDS client : Moon+ Reader @@ -123,63 +123,63 @@ * 1 : enable support for non compliant OPDS client * 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 * -1 unlimited */ - $config['cops_max_item_per_page'] = "-1"; + $config['cops_max_item_per_page'] = "-1"; /* * split authors by first letter * 1 : Yes * 0 : No */ - $config['cops_author_split_first_letter'] = "1"; + $config['cops_author_split_first_letter'] = "1"; /* * split titles by first letter * 1 : Yes * 0 : No */ - $config['cops_titles_split_first_letter'] = "1"; - + $config['cops_titles_split_first_letter'] = "1"; + /* * Enable the Lightboxes (for popups) * 1 : Yes (enable) * 0 : No */ - $config['cops_use_fancyapps'] = "1"; - + $config['cops_use_fancyapps'] = "1"; + /* * Update Epub metadata before download * 1 : Yes (enable) * 0 : No */ $config['cops_update_epub-metadata'] = "0"; - + /* * Filter on tags to book list * 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 want to see every books" => "", * * Example : array ("All" => "", "Unread" => "!Read", "Read" => "Read") */ $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 * - * 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 */ $config['cops_calibre_custom_column'] = array (); - + /* * Rename .epub to .kepub.epub if downloaded from a Kobo eReader * The ebook will then be recognized a Kepub so with chaptered paging, statistics, ... @@ -189,10 +189,10 @@ */ $config['cops_provide_kepub'] = "0"; - /* + /* * 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 : * $config['cops_mail_configuration'] = array( "smtp.host" => "smtp.free.fr", @@ -211,14 +211,14 @@ * ); */ $config['cops_mail_configuration'] = NULL; - + /* * Use filter in HTML catalog * 1 : Yes (enable) * 0 : No */ $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, ...). * 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") */ $config['cops_thumbnail_handling'] = ""; - + /* * 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). diff --git a/customcolumn.php b/customcolumn.php index bc91502..dc9769b 100644 --- a/customcolumn.php +++ b/customcolumn.php @@ -10,52 +10,52 @@ require_once('base.php'); class CustomColumn extends Base { const ALL_CUSTOMS_ID = "cops:custom"; - + public $id; public $name; public $customId; - + public function __construct($pid, $pname, $pcustomId) { $this->id = $pid; $this->name = $pname; $this->customId = $pcustomId; } - + public function getUri () { return "?page=".parent::PAGE_CUSTOM_DETAIL."&custom={$this->customId}&id={$this->id}"; } - + public function getEntryId () { return self::ALL_CUSTOMS_ID.":".$this->customId.":".$this->id; } - + public static function getTableName ($customId) { return "custom_column_{$customId}"; } - + public static function getTableLinkName ($customId) { return "books_custom_column_{$customId}_link"; } - + public static function getTableLinkColumn ($customId) { return "value"; } - + public static function getAllCustomsId ($customId) { return self::ALL_CUSTOMS_ID . ":" . $customId; } - + public static function getUriAllCustoms ($customId) { return "?page=" . parent::PAGE_ALL_CUSTOMS . "&custom={$customId}"; } - + public static function getAllTitle ($customId) { $result = parent::getDb ()->prepare('select name from custom_columns where id = ?'); $result->execute (array ($customId)); $post = $result->fetchObject (); return $post->name; } - + public static function getCustomId ($lookup) { $result = parent::getDb ()->prepare('select id from custom_columns where label = ?'); $result->execute (array ($lookup)); @@ -67,12 +67,12 @@ class CustomColumn extends Base { public static function getCount($customId) { $nCustoms = parent::getDb ()->query('select count(*) from ' . self::getTableName ($customId))->fetchColumn(); - $entry = new Entry (self::getAllTitle ($customId), self::getAllCustomsId ($customId), - str_format (localize("tags.alphabetical", $nCustoms), $nCustoms), "text", + $entry = new Entry (self::getAllTitle ($customId), self::getAllCustomsId ($customId), + str_format (localize("tags.alphabetical", $nCustoms), $nCustoms), "text", array ( new LinkNavigation (self::getUriAllCustoms ($customId)))); return $entry; } - + public static function getCustomById ($customId, $id) { $result = parent::getDb ()->prepare('select id, value as name from ' . self::getTableName ($customId) . ' where id = ?'); $result->execute (array ($id)); @@ -81,7 +81,7 @@ class CustomColumn extends Base { } return NULL; } - + public static function getAllCustoms($customId) { $result = parent::getDb ()->query(str_format ('select {0}.id as id, {0}.value as name, count(*) as count from {0}, {1} @@ -92,8 +92,8 @@ order by {0}.value', self::getTableName ($customId), self::getTableLinkName ($cu while ($post = $result->fetchObject ()) { $customColumn = new CustomColumn ($post->id, $post->name, $customId); - array_push ($entryArray, new Entry ($customColumn->name, $customColumn->getEntryId (), - str_format (localize("bookword", $post->count), $post->count), "text", + array_push ($entryArray, new Entry ($customColumn->name, $customColumn->getEntryId (), + str_format (localize("bookword", $post->count), $post->count), "text", array ( new LinkNavigation ($customColumn->getUri ())))); } return $entryArray; diff --git a/data.php b/data.php index 4866d45..4e91f94 100644 --- a/data.php +++ b/data.php @@ -15,7 +15,7 @@ class Data extends Base { public $realFormat; public $extension; public $book; - + public static $mimetypes = array( 'azw' => 'application/x-mobipocket-ebook', 'azw3' => 'application/x-mobipocket-ebook', @@ -44,7 +44,7 @@ class Data extends Base { 'xpgt' => 'application/adobe-page-template+xml', 'zip' => 'application/zip' ); - + public function __construct($post, $book = null) { $this->id = $post->id; $this->name = $post->name; @@ -53,11 +53,11 @@ class Data extends Base { $this->extension = strtolower ($this->realFormat); $this->book = $book; } - + public function isKnownType () { return array_key_exists ($this->extension, self::$mimetypes); } - + public function getMimeType () { if ($this->isKnownType ()) { return self::$mimetypes [$this->extension]; @@ -65,11 +65,11 @@ class Data extends Base { return "application/octet-stream"; } } - + public function getFilename () { return $this->name . "." . strtolower ($this->format); } - + public function getUpdatedFilename () { return $this->book->getAuthorsName () . " - " . $this->book->title; } @@ -81,18 +81,18 @@ class Data extends Base { public function getUpdatedFilenameKepub () { return $this->getUpdatedFilename () . ".kepub.epub"; } - + public function getDataLink ($rel, $title = NULL) { return self::getLink ($this->book, $this->extension, $this->getMimeType (), $rel, $this->getFilename (), $this->id, $title); } - + public function getLocalPath () { return $this->book->path . "/" . $this->getFilename (); } - + public function getHtmlLink () { global $config; - + if ($config['cops_use_url_rewriting'] == "1") { $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; } } - + public static function getLink ($book, $type, $mime, $rel, $filename, $idData, $title = NULL, $height = NULL) { global $config; - + $urlParam = addURLParameter("", "data", $idData); - + if (preg_match ('/^\//', Base::getDbDirectory ()) || // Linux / preg_match ('/^\w\:/', Base::getDbDirectory ()) || // Windows X: $rel == Link::OPDS_THUMBNAIL_TYPE || @@ -137,8 +137,8 @@ class Data extends Base { } $urlParam = addURLParameter($urlParam, "id", $book->id); if (!is_null (GetUrlParam (DB))) $urlParam = addURLParameter ($urlParam, DB, GetUrlParam (DB)); - if ($config['cops_thumbnail_handling'] != "1" && - !empty ($config['cops_thumbnail_handling']) && + if ($config['cops_thumbnail_handling'] != "1" && + !empty ($config['cops_thumbnail_handling']) && $rel == Link::OPDS_THUMBNAIL_TYPE) { return new Link ($config['cops_thumbnail_handling'], $mime, $rel, $title); } else { diff --git a/feed.php b/feed.php index 7949990..80450aa 100644 --- a/feed.php +++ b/feed.php @@ -14,7 +14,7 @@ require_once ("tag.php"); require_once ("book.php"); require_once ("OPDS_renderer.php"); - + header ("Content-Type:application/xml"); $page = getURLParam ("page", Base::PAGE_INDEX); $query = getURLParam ("query"); @@ -22,9 +22,9 @@ if ($query) $page = Base::PAGE_OPENSEARCH_QUERY; $qid = getURLParam ("id"); - + $OPDSRender = new OPDSRenderer (); - + switch ($page) { case Base::PAGE_OPENSEARCH : echo $OPDSRender->getOpenSearch (); diff --git a/fetch.php b/fetch.php index 0b4cfdd..b1fa18f 100644 --- a/fetch.php +++ b/fetch.php @@ -1,11 +1,11 @@ with integration/modification by Sébastien Lucas */ - + require_once ("config.php"); require_once ("book.php"); require_once ("data.php"); @@ -16,7 +16,7 @@ function notFound () { $_SERVER['REDIRECT_STATUS'] = 404; } - + global $config; $expires = 60*60*24*14; header("Pragma: public"); @@ -33,12 +33,12 @@ function notFound () { { $book = Book::getBookById($bookId); } - + if (!$book) { notFound (); - return; + return; } - + if ($book && ($type == "jpg" || empty ($config['calibre_internal_directory']))) { if ($type == "jpg") { $file = $book->getFilePath ($type); @@ -50,7 +50,7 @@ function notFound () { return; } } - + switch ($type) { case "jpg": @@ -123,12 +123,12 @@ function notFound () { } else { header('Content-Disposition: attachment; filename="' . basename ($file) . '"'); } - + $dir = $config['calibre_internal_directory']; if (empty ($config['calibre_internal_directory'])) { $dir = Base::getDbDirectory (); } - + if (empty ($config['cops_x_accel_redirect'])) { $filename = $dir . $file; $fp = fopen($filename, 'rb'); diff --git a/getJSON.php b/getJSON.php index 5b8f69f..4dfb269 100644 --- a/getJSON.php +++ b/getJSON.php @@ -6,7 +6,7 @@ * @author SĂ©bastien Lucas * */ - + require_once ("config.php"); require_once ("base.php"); require_once ("author.php"); @@ -15,9 +15,9 @@ require_once ("language.php"); require_once ("customcolumn.php"); require_once ("book.php"); - + header ("Content-Type:application/json;charset=utf-8"); - - + + echo json_encode (getJson ()); diff --git a/index.php b/index.php index b123250..505f848 100644 --- a/index.php +++ b/index.php @@ -6,7 +6,7 @@ * @author Sébastien Lucas * */ - + require_once ("config.php"); require_once ("base.php"); require_once ("author.php"); @@ -17,20 +17,20 @@ require_once ("customcolumn.php"); require_once ("book.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 (preg_match("/(MantanoReader|FBReader|Stanza|Aldiko|Moon+ Reader)/", $_SERVER['HTTP_USER_AGENT'])) { header("location: feed.php"); exit (); } - + $page = getURLParam ("page", Base::PAGE_INDEX); $query = getURLParam ("query"); $qid = getURLParam ("id"); $n = getURLParam ("n", "1"); $database = GetUrlParam (DB); - + // 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. if (is_array ($config['calibre_directory']) && is_null ($database)) { @@ -43,7 +43,7 @@ } else { $test = Base::getDb (); } - + header ("Content-Type:text/html;charset=utf-8"); ?> @@ -55,7 +55,7 @@ - + COPS @@ -69,7 +69,7 @@ - + " /> @@ -77,12 +77,12 @@ diff --git a/language.php b/language.php index c40cac6..8acb627 100644 --- a/language.php +++ b/language.php @@ -10,23 +10,23 @@ require_once('base.php'); class language extends Base { const ALL_LANGUAGES_ID = "cops:languages"; - + public $id; public $lang_code; - + public function __construct($pid, $plang_code) { $this->id = $pid; $this->lang_code = $plang_code; } - + public function getUri () { return "?page=".parent::PAGE_LANGUAGE_DETAIL."&id=$this->id"; } - + public function getEntryId () { return self::ALL_LANGUAGES_ID.":".$this->id; } - + public static function getLanguageString ($code) { $string = localize("languages.".$code); if (preg_match ("/^languages/", $string)) { @@ -38,12 +38,12 @@ class language extends Base { public static function getCount() { $nLanguages = parent::getDb ()->query('select count(*) from languages')->fetchColumn(); if ($nLanguages == 0) return NULL; - $entry = new Entry (localize("languages.title"), self::ALL_LANGUAGES_ID, - str_format (localize("languages.alphabetical", $nLanguages), $nLanguages), "text", + $entry = new Entry (localize("languages.title"), self::ALL_LANGUAGES_ID, + str_format (localize("languages.alphabetical", $nLanguages), $nLanguages), "text", array ( new LinkNavigation ("?page=".parent::PAGE_ALL_LANGUAGES))); return $entry; } - + public static function getLanguageById ($languageId) { $result = parent::getDb ()->prepare('select id, lang_code from languages where id = ?'); $result->execute (array ($languageId)); @@ -52,7 +52,7 @@ class language extends Base { } return NULL; } - + public static function getAllLanguages() { @@ -65,8 +65,8 @@ order by languages.lang_code'); while ($post = $result->fetchObject ()) { $language = new Language ($post->id, $post->lang_code); - array_push ($entryArray, new Entry (Language::getLanguageString ($language->lang_code), $language->getEntryId (), - str_format (localize("bookword", $post->count), $post->count), "text", + array_push ($entryArray, new Entry (Language::getLanguageString ($language->lang_code), $language->getEntryId (), + str_format (localize("bookword", $post->count), $post->count), "text", array ( new LinkNavigation ($language->getUri ())))); } return $entryArray; diff --git a/phpunit.xml b/phpunit.xml index 76618b0..03b4fe3 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,5 +1,5 @@ - + diff --git a/sendtomail.php b/sendtomail.php index 690c20a..a2b4752 100644 --- a/sendtomail.php +++ b/sendtomail.php @@ -55,7 +55,7 @@ foreach (explode (";", $emailDest) as $emailAddress) { $mail->AddAttachment($data->getLocalPath ()); -$mail->IsHTML(false); +$mail->IsHTML(false); $mail->Subject = 'Sent by COPS'; $mail->Body = 'Sent by COPS'; diff --git a/serie.php b/serie.php index 7de137f..31e113a 100644 --- a/serie.php +++ b/serie.php @@ -10,19 +10,19 @@ require_once('base.php'); class Serie extends Base { const ALL_SERIES_ID = "cops:series"; - + public $id; public $name; - + public function __construct($pid, $pname) { $this->id = $pid; $this->name = $pname; } - + public function getUri () { return "?page=".parent::PAGE_SERIE_DETAIL."&id=$this->id"; } - + public function getEntryId () { return self::ALL_SERIES_ID.":".$this->id; } @@ -30,12 +30,12 @@ class Serie extends Base { public static function getCount() { $nSeries = parent::getDb ()->query('select count(*) from series')->fetchColumn(); if ($nSeries == 0) return NULL; - $entry = new Entry (localize("series.title"), self::ALL_SERIES_ID, - str_format (localize("series.alphabetical", $nSeries), $nSeries), "text", + $entry = new Entry (localize("series.title"), self::ALL_SERIES_ID, + str_format (localize("series.alphabetical", $nSeries), $nSeries), "text", array ( new LinkNavigation ("?page=".parent::PAGE_ALL_SERIES))); return $entry; } - + public static function getSerieByBookId ($bookId) { $result = parent::getDb ()->prepare('select series.id as id, name from books_series_link, series @@ -46,7 +46,7 @@ where series.id = series and book = ?'); } return NULL; } - + public static function getSerieById ($serieId) { $result = parent::getDb ()->prepare('select id, name from series where id = ?'); $result->execute (array ($serieId)); @@ -55,7 +55,7 @@ where series.id = series and book = ?'); } return NULL; } - + public static function getAllSeries() { $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 @@ -66,13 +66,13 @@ order by series.sort'); while ($post = $result->fetchObject ()) { $serie = new Serie ($post->id, $post->sort); - array_push ($entryArray, new Entry ($serie->name, $serie->getEntryId (), - str_format (localize("bookword", $post->count), $post->count), "text", + array_push ($entryArray, new Entry ($serie->name, $serie->getEntryId (), + str_format (localize("bookword", $post->count), $post->count), "text", array ( new LinkNavigation ($serie->getUri ())))); } return $entryArray; } - + 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 from series, books_series_link @@ -84,8 +84,8 @@ order by series.sort'); while ($post = $result->fetchObject ()) { $serie = new Serie ($post->id, $post->sort); - array_push ($entryArray, new Entry ($serie->name, $serie->getEntryId (), - str_format (localize("bookword", $post->count), $post->count), "text", + array_push ($entryArray, new Entry ($serie->name, $serie->getEntryId (), + str_format (localize("bookword", $post->count), $post->count), "text", array ( new LinkNavigation ($serie->getUri ())))); } return $entryArray; diff --git a/tag.php b/tag.php index 38fd2a4..c3dfc92 100644 --- a/tag.php +++ b/tag.php @@ -10,19 +10,19 @@ require_once('base.php'); class tag extends Base { const ALL_TAGS_ID = "cops:tags"; - + public $id; public $name; - + public function __construct($pid, $pname) { $this->id = $pid; $this->name = $pname; } - + public function getUri () { return "?page=".parent::PAGE_TAG_DETAIL."&id=$this->id"; } - + public function getEntryId () { return self::ALL_TAGS_ID.":".$this->id; } @@ -30,12 +30,12 @@ class tag extends Base { public static function getCount() { $nTags = parent::getDb ()->query('select count(*) from tags')->fetchColumn(); if ($nTags == 0) return NULL; - $entry = new Entry (localize("tags.title"), self::ALL_TAGS_ID, - str_format (localize("tags.alphabetical", $nTags), $nTags), "text", + $entry = new Entry (localize("tags.title"), self::ALL_TAGS_ID, + str_format (localize("tags.alphabetical", $nTags), $nTags), "text", array ( new LinkNavigation ("?page=".parent::PAGE_ALL_TAGS))); return $entry; } - + public static function getTagById ($tagId) { $result = parent::getDb ()->prepare('select id, name from tags where id = ?'); $result->execute (array ($tagId)); @@ -44,7 +44,7 @@ class tag extends Base { } return NULL; } - + public static function getAllTags() { $result = parent::getDb ()->query('select tags.id as id, tags.name as name, count(*) as count from tags, books_tags_link @@ -55,13 +55,13 @@ order by tags.name'); while ($post = $result->fetchObject ()) { $tag = new Tag ($post->id, $post->name); - array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (), - str_format (localize("bookword", $post->count), $post->count), "text", + array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (), + str_format (localize("bookword", $post->count), $post->count), "text", array ( new LinkNavigation ($tag->getUri ())))); } return $entryArray; } - + 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"; $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 ()) { $tag = new Tag ($post->id, $post->name); - array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (), - str_format (localize("bookword", $post->count), $post->count), "text", + array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (), + str_format (localize("bookword", $post->count), $post->count), "text", array ( new LinkNavigation ($tag->getUri ())))); } return array ($entryArray, $totalNumber); diff --git a/test/Sauce.php b/test/Sauce.php index db778eb..1b44465 100644 --- a/test/Sauce.php +++ b/test/Sauce.php @@ -55,7 +55,7 @@ class Cops extends Sauce\Sausage\WebDriverTestCase 'platform' => 'Linux' ) ) - // run Mobile Browser on Android + // run Mobile Browser on Android // array( // 'browserName' => 'Android', // 'desiredCapabilities' => array( @@ -63,7 +63,7 @@ class Cops extends Sauce\Sausage\WebDriverTestCase // 'platform' => 'Linux', // ) // ) - + // run Chrome locally //array( //'browserName' => 'chrome', @@ -81,7 +81,7 @@ class Cops extends Sauce\Sausage\WebDriverTestCase } parent::setUp (); } - + public function setUpPage() { if (isset ($_SERVER["TRAVIS_JOB_NUMBER"])) { @@ -89,25 +89,25 @@ class Cops extends Sauce\Sausage\WebDriverTestCase } else { $this->url('http://cops-demo.slucas.fr/index.php'); } - + $driver = $this; $title_test = function($value) use ($driver) { $text = $driver->byXPath('//h1')->text (); return $text == $value; }; - + $this->spinAssert("Home Title", $title_test, [ "COPS DEMO" ]); } - + public function string_to_ascii($string) { $ascii = NULL; - + for ($i = 0; $i < strlen($string); $i++) { $ascii += ord($string[$i]); } - + 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->click (); - + $this->spinAssert("Author Title", $title_test, [ "AUTHORS" ]); } - + public function testCog() - { + { $cog = $this->byId ("searchImage"); - + $search = $this->byName ("query"); $this->assertFalse ($search->displayed ()); - + $cog->click (); - + $search = $this->byName ("query"); $this->assertTrue ($search->displayed ()); } diff --git a/test/baseTest.php b/test/baseTest.php index 423930d..c678f5d 100644 --- a/test/baseTest.php +++ b/test/baseTest.php @@ -10,42 +10,42 @@ require_once (dirname(__FILE__) . "/config_test.php"); require_once (dirname(__FILE__) . "/../base.php"); class BaseTest extends PHPUnit_Framework_TestCase -{ +{ public function testAddURLParameter () { $this->assertEquals ("?db=0", addURLParameter ("?", "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")); } - + public function testLocalize () { $this->assertEquals ("Authors", localize ("authors.title")); - + $this->assertEquals ("unknow.key", localize ("unknow.key")); } - + public function testLocalizeFr () { $_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)); - + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en"; localize ("authors.title", -1, true); } - + public function testLocalizeUnknown () { $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "aa"; $this->assertEquals ("Authors", localize ("authors.title", -1, true)); - + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "en"; localize ("authors.title", -1, true); } - + public function testBaseFunction () { global $config; - + $this->assertFalse (Base::isMultipleDatabaseEnabled ()); $this->assertEquals (array ("" => dirname(__FILE__) . "/BaseWithSomeBooks/"), Base::getDbList ()); diff --git a/test/bookTest.php b/test/bookTest.php index a817a2f..ddce41f 100644 --- a/test/bookTest.php +++ b/test/bookTest.php @@ -11,70 +11,70 @@ require_once (dirname(__FILE__) . "/../book.php"); /* Publishers: -id:2 (2 books) Macmillan and Co. London: Lewis Caroll -id:3 (2 books) D. Appleton and Company Alexander Dumas -id:4 (1 book) Macmillan Publishers USA: Jack London -id:5 (1 book) Pierson's Magazine: H. G. Wells +id:2 (2 books) Macmillan and Co. London: Lewis Caroll +id:3 (2 books) D. Appleton and Company Alexander Dumas +id:4 (1 book) Macmillan Publishers USA: Jack London +id:5 (1 book) Pierson's Magazine: H. G. Wells id:6 (8 books) Strand Magazine: Arthur Conan Doyle */ class BookTest extends PHPUnit_Framework_TestCase -{ +{ public function testGetBookCount () { $this->assertEquals (14, Book::getBookCount ()); } - + public function testGetCount () { $entryArray = Book::getCount (); $this->assertEquals (2, count($entryArray)); - + $entryAllBooks = $entryArray [0]; $this->assertEquals ("Alphabetical index of the 14 books", $entryAllBooks->content); - + $entryRecentBooks = $entryArray [1]; $this->assertEquals ("50 most recent books", $entryRecentBooks->content); - + } - + public function testGetCountRecent () { global $config; - $config['cops_recentbooks_limit'] = 0; + $config['cops_recentbooks_limit'] = 0; $entryArray = Book::getCount (); - + $this->assertEquals (1, count($entryArray)); - - $config['cops_recentbooks_limit'] = 2; + + $config['cops_recentbooks_limit'] = 2; $entryArray = Book::getCount (); - + $entryRecentBooks = $entryArray [1]; $this->assertEquals ("2 most recent books", $entryRecentBooks->content); - - $config['cops_recentbooks_limit'] = 50; + + $config['cops_recentbooks_limit'] = 50; } - + public function testGetBooksByAuthor () { // All book by Arthur Conan Doyle global $config; - + $config['cops_max_item_per_page'] = 5; list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 1); $this->assertEquals (5, count($entryArray)); $this->assertEquals (8, $totalNumber); - + list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, 2); $this->assertEquals (3, count($entryArray)); $this->assertEquals (8, $totalNumber); - + $config['cops_max_item_per_page'] = -1; list ($entryArray, $totalNumber) = Book::getBooksByAuthor (1, -1); $this->assertEquals (8, count($entryArray)); $this->assertEquals (-1, $totalNumber); } - + public function testGetBooksBySeries () { // All book from the Sherlock Holmes series @@ -82,10 +82,10 @@ class BookTest extends PHPUnit_Framework_TestCase $this->assertEquals (7, count($entryArray)); $this->assertEquals (-1, $totalNumber); } - + public function testGetBooksByPublisher () { - // All books from Strand Magazine + // All books from Strand Magazine list ($entryArray, $totalNumber) = Book::getBooksByPublisher (6, -1); $this->assertEquals (8, count($entryArray)); $this->assertEquals (-1, $totalNumber); @@ -98,7 +98,7 @@ class BookTest extends PHPUnit_Framework_TestCase $this->assertEquals (14, count($entryArray)); $this->assertEquals (-1, $totalNumber); } - + public function testGetBooksByLanguage () { // All english book (= all books) @@ -106,14 +106,14 @@ class BookTest extends PHPUnit_Framework_TestCase $this->assertEquals (14, count($entryArray)); $this->assertEquals (-1, $totalNumber); } - + public function testGetAllBooks () { // All books by first letter $entryArray = Book::getAllBooks (); $this->assertCount (9, $entryArray); } - + public function testGetBooksByStartingLetter () { // All books by first letter @@ -121,26 +121,26 @@ class BookTest extends PHPUnit_Framework_TestCase $this->assertEquals (-1, $totalNumber); $this->assertCount (3, $entryArray); } - - public function testGetBookByDataId () + + public function testGetBookByDataId () { $book = Book::getBookByDataId (17); - + $this->assertEquals ("Alice's Adventures in Wonderland", $book->getTitle ()); } - + public function testGetAllRecentBooks () { // All recent books global $config; - + $config['cops_recentbooks_limit'] = 2; - + $entryArray = Book::getAllRecentBooks (); $this->assertCount (2, $entryArray); - + $config['cops_recentbooks_limit'] = 50; - + $entryArray = Book::getAllRecentBooks (); $this->assertCount (14, $entryArray); } @@ -162,7 +162,7 @@ class BookTest extends PHPUnit_Framework_TestCase $this->assertEquals ("★★★★☆", $book->getRating ()); $this->assertEquals ("Strand Magazine", $book->getPublisher()->name); } - + public function testGetMostInterestingDataToSendToKindle () { // Get Alice (available as MOBI, PDF, EPUB in that order) @@ -176,11 +176,11 @@ class BookTest extends PHPUnit_Framework_TestCase $data = $book->GetMostInterestingDataToSendToKindle (); $this->assertEquals ("EPUB", $data->format); } - + public function testGetDataById () { global $config; - + // Get Alice MOBI=>17, PDF=>19, EPUB=>20 $book = Book::getBookById(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.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 ()); - + $config['cops_use_url_rewriting'] = "1"; $config['cops_provide_kepub'] = "1"; $_SERVER["HTTP_USER_AGENT"] = "Kobo"; @@ -200,35 +200,35 @@ class BookTest extends PHPUnit_Framework_TestCase $config['cops_use_url_rewriting'] = "0"; $this->assertEquals ("fetch.php?data=20&type=epub&id=17", $data->getHtmlLink ()); } - + public function testTypeaheadSearch () { $_GET["query"] = "fic"; $_GET["search"] = "1"; - + $array = getJson (); - + $this->assertCount (3, $array); $this->assertEquals ("2 tags", $array[0]["title"]); $this->assertEquals ("Fiction", $array[1]["title"]); $this->assertEquals ("Science Fiction", $array[2]["title"]); - + $_GET["query"] = "car"; $_GET["search"] = "1"; - + $array = getJson (); - + $this->assertCount (4, $array); $this->assertEquals ("1 book", $array[0]["title"]); $this->assertEquals ("A Study in Scarlet", $array[1]["title"]); $this->assertEquals ("1 author", $array[2]["title"]); $this->assertEquals ("Carroll, Lewis", $array[3]["title"]); - + $_GET["query"] = "art"; $_GET["search"] = "1"; - + $array = getJson (); - + $this->assertCount (4, $array); $this->assertEquals ("1 author", $array[0]["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 ("Macmillan and Co. London", $array[1]["title"]); $this->assertEquals ("Macmillan Publishers USA", $array[2]["title"]); - + $_GET["query"] = NULL; $_GET["search"] = NULL; } - + public function testTypeaheadSearchMultiDatabase () { global $config; $_GET["query"] = "art"; $_GET["search"] = "1"; $_GET["multi"] = "1"; - + $config['calibre_directory'] = array ("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/", "One book" => dirname(__FILE__) . "/BaseWithOneBook/"); - + $array = getJson (); - + $this->assertCount (4, $array); $this->assertEquals ("Some books", $array[0]["title"]); $this->assertEquals ("No book", $array[1]["title"]); @@ -270,9 +270,9 @@ class BookTest extends PHPUnit_Framework_TestCase $_GET["query"] = NULL; $_GET["search"] = NULL; } - + public function tearDown () { Base::clearDb (); } - + } \ No newline at end of file diff --git a/test/pageMultidatabaseTest.php b/test/pageMultidatabaseTest.php index 0988e3f..cf373f9 100644 --- a/test/pageMultidatabaseTest.php +++ b/test/pageMultidatabaseTest.php @@ -10,7 +10,7 @@ require_once (dirname(__FILE__) . "/config_test.php"); require_once (dirname(__FILE__) . "/../book.php"); class PageMultiDatabaseTest extends PHPUnit_Framework_TestCase -{ +{ public function testPageIndex () { global $config; @@ -20,10 +20,10 @@ class PageMultiDatabaseTest extends PHPUnit_Framework_TestCase $query = NULL; $qid = NULL; $n = "1"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ($config['cops_title_default'], $currentPage->title); $this->assertCount (2, $currentPage->entryArray); $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->assertFalse ($currentPage->ContainsBook ()); } - + public function testPageSearchXXX () { global $config; @@ -42,10 +42,10 @@ class PageMultiDatabaseTest extends PHPUnit_Framework_TestCase $query = "art"; $qid = NULL; $n = "1"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Search result for *art*", $currentPage->title); $this->assertCount (2, $currentPage->entryArray); $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->assertFalse ($currentPage->ContainsBook ()); } - + public static function tearDownAfterClass () { Base::clearDb (); } diff --git a/test/pageTest.php b/test/pageTest.php index 4d6a58b..91c858f 100644 --- a/test/pageTest.php +++ b/test/pageTest.php @@ -10,7 +10,7 @@ require_once (dirname(__FILE__) . "/config_test.php"); require_once (dirname(__FILE__) . "/../book.php"); class PageTest extends PHPUnit_Framework_TestCase -{ +{ public function testPageIndex () { global $config; @@ -18,10 +18,10 @@ class PageTest extends PHPUnit_Framework_TestCase $query = NULL; $qid = NULL; $n = "1"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ($config['cops_title_default'], $currentPage->title); $this->assertCount (7, $currentPage->entryArray); $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->assertFalse ($currentPage->ContainsBook ()); } - + public function testPageIndexWithCustomColumn () { global $config; @@ -48,125 +48,125 @@ class PageTest extends PHPUnit_Framework_TestCase $query = NULL; $qid = NULL; $n = "1"; - + $config['cops_calibre_custom_column'] = array ("type1"); - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertCount (8, $currentPage->entryArray); $this->assertEquals ("Type1", $currentPage->entryArray [5]->title); $this->assertEquals ("Alphabetical index of the 2 tags", $currentPage->entryArray [5]->content); - + $config['cops_calibre_custom_column'] = array ("type2"); - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertCount (8, $currentPage->entryArray); $this->assertEquals ("Type2", $currentPage->entryArray [5]->title); $this->assertEquals ("Alphabetical index of the 3 tags", $currentPage->entryArray [5]->content); - + $config['cops_calibre_custom_column'] = array ("type4"); - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertCount (8, $currentPage->entryArray); $this->assertEquals ("Type4", $currentPage->entryArray [5]->title); $this->assertEquals ("Alphabetical index of the 2 tags", $currentPage->entryArray [5]->content); - + $config['cops_calibre_custom_column'] = array ("type1", "type2", "type4"); - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertCount (10, $currentPage->entryArray); - + $config['cops_calibre_custom_column'] = array (); } - + public function testPageAllCustom () { $page = Base::PAGE_ALL_CUSTOMS; $query = NULL; $qid = NULL; $n = "1"; - + $_GET ["custom"] = "1"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Type4", $currentPage->title); $this->assertCount (2, $currentPage->entryArray); $this->assertEquals ("SeriesLike", $currentPage->entryArray [0]->title); $this->assertFalse ($currentPage->ContainsBook ()); - + $_GET ["custom"] = "2"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Type2", $currentPage->title); $this->assertCount (3, $currentPage->entryArray); $this->assertEquals ("tag1", $currentPage->entryArray [0]->title); $this->assertFalse ($currentPage->ContainsBook ()); - + $_GET ["custom"] = "3"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Type1", $currentPage->title); $this->assertCount (2, $currentPage->entryArray); $this->assertEquals ("other", $currentPage->entryArray [0]->title); $this->assertFalse ($currentPage->ContainsBook ()); - + $_GET ["custom"] = NULL; } - + public function testPageCustomDetail () { $page = Base::PAGE_CUSTOM_DETAIL; $query = NULL; $qid = "1"; $n = "1"; - + $_GET ["custom"] = "1"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("SeriesLike", $currentPage->title); $this->assertCount (2, $currentPage->entryArray); $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); $this->assertTrue ($currentPage->ContainsBook ()); - + $_GET ["custom"] = "2"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("tag1", $currentPage->title); $this->assertCount (2, $currentPage->entryArray); $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); $this->assertTrue ($currentPage->ContainsBook ()); - + $_GET ["custom"] = "3"; $qid = "2"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("other", $currentPage->title); $this->assertCount (1, $currentPage->entryArray); $this->assertEquals ("A Study in Scarlet", $currentPage->entryArray [0]->title); $this->assertTrue ($currentPage->ContainsBook ()); - + $_GET ["custom"] = NULL; } - + public function testPageAllAuthors () { global $config; @@ -174,44 +174,44 @@ class PageTest extends PHPUnit_Framework_TestCase $query = NULL; $qid = NULL; $n = "1"; - + $config['cops_author_split_first_letter'] = "0"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Authors", $currentPage->title); $this->assertCount (5, $currentPage->entryArray); $this->assertEquals ("Carroll, Lewis", $currentPage->entryArray [0]->title); $this->assertFalse ($currentPage->ContainsBook ()); - + $config['cops_author_split_first_letter'] = "1"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Authors", $currentPage->title); $this->assertCount (4, $currentPage->entryArray); $this->assertEquals ("C", $currentPage->entryArray [0]->title); $this->assertFalse ($currentPage->ContainsBook ()); } - + public function testPageAuthorsFirstLetter () { $page = Base::PAGE_AUTHORS_FIRST_LETTER; $query = NULL; $qid = "C"; $n = "1"; - + // Author Lewis Carroll $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("1 author starting with C", $currentPage->title); $this->assertCount (1, $currentPage->entryArray); $this->assertFalse ($currentPage->ContainsBook ()); } - + public function testPageAuthorsDetail () { global $config; @@ -220,47 +220,47 @@ class PageTest extends PHPUnit_Framework_TestCase $qid = "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 - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Doyle, Arthur Conan", $currentPage->title); $this->assertEquals (4, $currentPage->getMaxPage ()); $this->assertCount (2, $currentPage->entryArray); $this->assertTrue ($currentPage->ContainsBook ()); $this->assertTrue ($currentPage->IsPaginated ()); $this->assertNull ($currentPage->getPrevLink ()); - + // Last page - $config['cops_max_item_per_page'] = 5; + $config['cops_max_item_per_page'] = 5; $n = "2"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Doyle, Arthur Conan", $currentPage->title); $this->assertEquals (2, $currentPage->getMaxPage ()); $this->assertCount (3, $currentPage->entryArray); $this->assertTrue ($currentPage->ContainsBook ()); $this->assertTrue ($currentPage->IsPaginated ()); $this->assertNull ($currentPage->getNextLink ()); - + // No pagination - $config['cops_max_item_per_page'] = -1; - + $config['cops_max_item_per_page'] = -1; + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Doyle, Arthur Conan", $currentPage->title); $this->assertCount (8, $currentPage->entryArray); $this->assertTrue ($currentPage->ContainsBook ()); $this->assertFalse ($currentPage->IsPaginated ()); } - + public function testPageAllBooks () { global $config; @@ -268,19 +268,19 @@ class PageTest extends PHPUnit_Framework_TestCase $query = NULL; $qid = NULL; $n = "1"; - - $config['cops_titles_split_first_letter'] = 0; + + $config['cops_titles_split_first_letter'] = 0; $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("All books", $currentPage->title); $this->assertCount (14, $currentPage->entryArray); $this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title); $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [1]->title); $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->InitializeContent (); @@ -291,48 +291,48 @@ class PageTest extends PHPUnit_Framework_TestCase $this->assertEquals ("C", $currentPage->entryArray [1]->title); $this->assertFalse ($currentPage->ContainsBook ()); } - + public function testPageAllBooksByLetter () { $page = Base::PAGE_ALL_BOOKS_LETTER; $query = NULL; $qid = "C"; $n = "1"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("2 books starting with C", $currentPage->title); $this->assertCount (2, $currentPage->entryArray); $this->assertEquals ("The Call of the Wild", $currentPage->entryArray [0]->title); $this->assertTrue ($currentPage->ContainsBook ()); } - + public function testPageAllSeries () { $page = Base::PAGE_ALL_SERIES; $query = NULL; $qid = NULL; $n = "1"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Series", $currentPage->title); $this->assertCount (3, $currentPage->entryArray); $this->assertEquals ("D'Artagnan Romances", $currentPage->entryArray [0]->title); $this->assertFalse ($currentPage->ContainsBook ()); } - + public function testPageSeriesDetail () { $page = Base::PAGE_SERIE_DETAIL; $query = NULL; $qid = "1"; - $n = "1"; + $n = "1"; $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Sherlock Holmes", $currentPage->title); $this->assertCount (7, $currentPage->entryArray); $this->assertEquals ("A Study in Scarlet", $currentPage->entryArray [0]->title); @@ -345,10 +345,10 @@ class PageTest extends PHPUnit_Framework_TestCase $query = NULL; $qid = NULL; $n = "1"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Publishers", $currentPage->title); $this->assertCount (5, $currentPage->entryArray); $this->assertEquals ("D. Appleton and Company", $currentPage->entryArray [0]->title); @@ -361,10 +361,10 @@ class PageTest extends PHPUnit_Framework_TestCase $query = NULL; $qid = "6"; $n = "1"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Strand Magazine", $currentPage->title); $this->assertCount (8, $currentPage->entryArray); $this->assertEquals ("The Return of Sherlock Holmes", $currentPage->entryArray [0]->title); @@ -378,26 +378,26 @@ class PageTest extends PHPUnit_Framework_TestCase $query = NULL; $qid = NULL; $n = "1"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Tags", $currentPage->title); $this->assertCount (10, $currentPage->entryArray); $this->assertEquals ("Action & Adventure", $currentPage->entryArray [0]->title); $this->assertFalse ($currentPage->ContainsBook ()); } - + public function testPageTagDetail () { $page = Base::PAGE_TAG_DETAIL; $query = NULL; $qid = "1"; $n = "1"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Fiction", $currentPage->title); $this->assertCount (14, $currentPage->entryArray); $this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title); @@ -410,107 +410,107 @@ class PageTest extends PHPUnit_Framework_TestCase $query = NULL; $qid = NULL; $n = "1"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Languages", $currentPage->title); $this->assertCount (1, $currentPage->entryArray); $this->assertEquals ("English", $currentPage->entryArray [0]->title); $this->assertFalse ($currentPage->ContainsBook ()); } - + public function testPageLanguageDetail () { $page = Base::PAGE_LANGUAGE_DETAIL; $query = NULL; $qid = "1"; $n = "1"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("English", $currentPage->title); $this->assertCount (14, $currentPage->entryArray); $this->assertEquals ("The Adventures of Sherlock Holmes", $currentPage->entryArray [0]->title); $this->assertTrue ($currentPage->ContainsBook ()); } - + public function testPageRecent () { $page = Base::PAGE_ALL_RECENT_BOOKS; $query = NULL; $qid = NULL; $n = "1"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Recent additions", $currentPage->title); $this->assertCount (14, $currentPage->entryArray); $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); $this->assertTrue ($currentPage->ContainsBook ()); - + // Test facets - + $_GET["tag"] = "Historical"; $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Recent additions", $currentPage->title); $this->assertCount (2, $currentPage->entryArray); $this->assertEquals ("Twenty Years After", $currentPage->entryArray [0]->title); $this->assertTrue ($currentPage->ContainsBook ()); - + $_GET["tag"] = "!Romance"; $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Recent additions", $currentPage->title); $this->assertCount (12, $currentPage->entryArray); $this->assertEquals ("Alice's Adventures in Wonderland", $currentPage->entryArray [0]->title); $this->assertTrue ($currentPage->ContainsBook ()); - + $_GET["tag"] = NULL; } - + public function testPageBookDetail () { $page = Base::PAGE_BOOK_DETAIL; $query = NULL; $qid = "2"; $n = "1"; - + $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("The Return of Sherlock Holmes", $currentPage->title); $this->assertCount (0, $currentPage->entryArray); $this->assertFalse ($currentPage->ContainsBook ()); } - + public function testPageSearch () { $page = Base::PAGE_OPENSEARCH_QUERY; $query = "alice"; $qid = NULL; $n = "1"; - + // Only books returned $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Search result for *alice*", $currentPage->title); $this->assertCount (2, $currentPage->entryArray); $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->assertTrue ($currentPage->ContainsBook ()); - + // Match Lewis Caroll & Scarlet $query = "car"; $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Search result for *car*", $currentPage->title); $this->assertCount (3, $currentPage->entryArray); $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->assertTrue ($currentPage->ContainsBook ()); } - + public function testPageSearchScopeAuthors () { $page = Base::PAGE_OPENSEARCH_QUERY; $qid = NULL; $n = "1"; $_GET ["scope"] = "author"; - + // Match Lewis Carroll $query = "car"; $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Search result for *car* in authors", $currentPage->title); $this->assertCount (1, $currentPage->entryArray); $this->assertEquals ("Carroll, Lewis", $currentPage->entryArray [0]->title); $this->assertFalse ($currentPage->ContainsBook ()); - + $_GET ["scope"] = NULL; } - + public function testPageSearchScopeSeries () { $page = Base::PAGE_OPENSEARCH_QUERY; $qid = NULL; $n = "1"; $_GET ["scope"] = "series"; - + // Match Holmes $query = "hol"; $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Search result for *hol* in series", $currentPage->title); $this->assertCount (1, $currentPage->entryArray); $this->assertEquals ("Sherlock Holmes", $currentPage->entryArray [0]->title); $this->assertFalse ($currentPage->ContainsBook ()); - + $_GET ["scope"] = NULL; } - + public function testPageSearchScopeBooks () { $page = Base::PAGE_OPENSEARCH_QUERY; $qid = NULL; $n = "1"; $_GET ["scope"] = "book"; - + // Match Holmes $query = "hol"; $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Search result for *hol* in books", $currentPage->title); $this->assertCount (4, $currentPage->entryArray); $this->assertTrue ($currentPage->ContainsBook ()); - + $_GET ["scope"] = NULL; } - + public function testPageSearchScopePublishers () { $page = Base::PAGE_OPENSEARCH_QUERY; $qid = NULL; $n = "1"; $_GET ["scope"] = "publisher"; - + // Match Holmes $query = "millan"; $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Search result for *millan* in publishers", $currentPage->title); $this->assertCount (2, $currentPage->entryArray); $this->assertEquals ("Macmillan and Co. London", $currentPage->entryArray [0]->title); $this->assertFalse ($currentPage->ContainsBook ()); - + $_GET ["scope"] = NULL; } - + public function testPageSearchScopeTags () { $page = Base::PAGE_OPENSEARCH_QUERY; $qid = NULL; $n = "1"; $_GET ["scope"] = "tag"; - + // Match Holmes $query = "fic"; $currentPage = Page::getPage ($page, $qid, $query, $n); $currentPage->InitializeContent (); - + $this->assertEquals ("Search result for *fic* in tags", $currentPage->title); $this->assertCount (2, $currentPage->entryArray); $this->assertFalse ($currentPage->ContainsBook ()); - + $_GET ["scope"] = NULL; } } \ No newline at end of file