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.

67 lines
2.3KB

  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 getCount() {
  24. $nLanguages = parent::getDb ()->query('select count(*) from languages')->fetchColumn();
  25. if ($nLanguages == 0) return NULL;
  26. $entry = new Entry (localize("languages.title"), self::ALL_LANGUAGES_ID,
  27. str_format (localize("languages.alphabetical", $nLanguages), $nLanguages), "text non",
  28. array ( new LinkNavigation ("?page=".parent::PAGE_ALL_LANGUAGES)));
  29. return $entry;
  30. }
  31. public static function getLanguageById ($languageId) {
  32. $result = parent::getDb ()->prepare('select id, lang_code from languages where id = ?');
  33. $result->execute (array ($languageId));
  34. if ($post = $result->fetchObject ()) {
  35. return new Language ($post->id, localize("languages.".$post->lang_code));
  36. }
  37. return NULL;
  38. }
  39. public static function getAllLanguages() {
  40. $result = parent::getDb ()->query('select languages.id as id, languages.lang_code as lang_code, count(*) as count
  41. from languages, books_languages_link
  42. where languages.id = books_languages_link.lang_code
  43. group by languages.id, books_languages_link.lang_code
  44. order by languages.lang_code');
  45. $entryArray = array();
  46. while ($post = $result->fetchObject ())
  47. {
  48. $language = new Language ($post->id, $post->lang_code);
  49. array_push ($entryArray, new Entry (localize("languages.".$language->lang_code), $language->getEntryId (),
  50. str_format (localize("bookword", $post->count), $post->count), "text non",
  51. array ( new LinkNavigation ($language->getUri ()))));
  52. }
  53. return $entryArray;
  54. }
  55. }