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.

71 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 = "cops: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. // str_format (localize("languages.alphabetical", count(array))
  32. return parent::getCountGeneric ("languages", self::ALL_LANGUAGES_ID, parent::PAGE_ALL_LANGUAGES);
  33. }
  34. public static function getLanguageById ($languageId) {
  35. $result = parent::getDb ()->prepare('select id, lang_code from languages where id = ?');
  36. $result->execute (array ($languageId));
  37. if ($post = $result->fetchObject ()) {
  38. return new Language ($post->id, Language::getLanguageString ($post->lang_code));
  39. }
  40. return NULL;
  41. }
  42. public static function getAllLanguages() {
  43. $result = parent::getDb ()->query('select languages.id as id, languages.lang_code as lang_code, count(*) as count
  44. from languages, books_languages_link
  45. where languages.id = books_languages_link.lang_code
  46. group by languages.id, books_languages_link.lang_code
  47. order by languages.lang_code');
  48. $entryArray = array();
  49. while ($post = $result->fetchObject ())
  50. {
  51. $language = new Language ($post->id, $post->lang_code);
  52. array_push ($entryArray, new Entry (Language::getLanguageString ($language->lang_code), $language->getEntryId (),
  53. str_format (localize("bookword", $post->count), $post->count), "text",
  54. array ( new LinkNavigation ($language->getUri ())), "", $post->count));
  55. }
  56. return $entryArray;
  57. }
  58. }