Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...) http://blog.slucas.fr/en/oss/calibre-opds-php-server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.5KB

  1. <?php
  2. /**
  3. * COPS (Calibre OPDS PHP Server) class file
  4. *
  5. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  6. * @author Sébastien Lucas <sebastien@slucas.fr>
  7. */
  8. require_once('base.php');
  9. class language extends Base {
  10. const ALL_LANGUAGES_ID = "calibre:languages";
  11. public $id;
  12. public $lang_code;
  13. public function __construct($pid, $plang_code) {
  14. $this->id = $pid;
  15. $this->lang_code = $plang_code;
  16. }
  17. public function getUri () {
  18. return "?page=".parent::PAGE_LANGUAGE_DETAIL."&id=$this->id";
  19. }
  20. public function getEntryId () {
  21. return self::ALL_LANGUAGES_ID.":".$this->id;
  22. }
  23. public static function getLanguageString ($code) {
  24. $string = localize("languages.".$code);
  25. if (preg_match ("/^languages/", $string)) {
  26. return $code;
  27. }
  28. return $string;
  29. }
  30. public static function getCount() {
  31. $nLanguages = parent::getDb ()->query('select count(*) from languages')->fetchColumn();
  32. if ($nLanguages == 0) return NULL;
  33. $entry = new Entry (localize("languages.title"), self::ALL_LANGUAGES_ID,
  34. str_format (localize("languages.alphabetical", $nLanguages), $nLanguages), "text non",
  35. array ( new LinkNavigation ("?page=".parent::PAGE_ALL_LANGUAGES)));
  36. return $entry;
  37. }
  38. public static function getLanguageById ($languageId) {
  39. $result = parent::getDb ()->prepare('select id, lang_code from languages where id = ?');
  40. $result->execute (array ($languageId));
  41. if ($post = $result->fetchObject ()) {
  42. return new Language ($post->id, Language::getLanguageString ($post->lang_code));
  43. }
  44. return NULL;
  45. }
  46. public static function getAllLanguages() {
  47. $result = parent::getDb ()->query('select languages.id as id, languages.lang_code as lang_code, count(*) as count
  48. from languages, books_languages_link
  49. where languages.id = books_languages_link.lang_code
  50. group by languages.id, books_languages_link.lang_code
  51. order by languages.lang_code');
  52. $entryArray = array();
  53. while ($post = $result->fetchObject ())
  54. {
  55. $language = new Language ($post->id, $post->lang_code);
  56. array_push ($entryArray, new Entry (Language::getLanguageString ($language->lang_code), $language->getEntryId (),
  57. str_format (localize("bookword", $post->count), $post->count), "text non",
  58. array ( new LinkNavigation ($language->getUri ()))));
  59. }
  60. return $entryArray;
  61. }
  62. }