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.

65 lines
2.0KB

  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 tag extends Base {
  10. const ALL_TAGS_ID = "calibre:tags";
  11. public $id;
  12. public $name;
  13. public function __construct($pid, $pname) {
  14. $this->id = $pid;
  15. $this->name = $pname;
  16. }
  17. public function getUri () {
  18. return "?page=".parent::PAGE_TAG_DETAIL."&id=$this->id";
  19. }
  20. public function getEntryId () {
  21. return self::ALL_TAGS_ID.":".$this->id;
  22. }
  23. public static function getCount() {
  24. $nTags = parent::getDb ()->query('select count(*) from tags')->fetchColumn();
  25. if ($nTags == 0) return NULL;
  26. $entry = new Entry (localize("tags.title"), self::ALL_TAGS_ID,
  27. str_format (localize("tags.alphabetical", $nTags), $nTags), "text",
  28. array ( new LinkNavigation ("?page=".parent::PAGE_ALL_TAGS)));
  29. return $entry;
  30. }
  31. public static function getTagById ($tagId) {
  32. $result = parent::getDb ()->prepare('select id, name from tags where id = ?');
  33. $result->execute (array ($tagId));
  34. if ($post = $result->fetchObject ()) {
  35. return new Tag ($post->id, $post->name);
  36. }
  37. return NULL;
  38. }
  39. public static function getAllTags() {
  40. $result = parent::getDb ()->query('select tags.id as id, tags.name as name, count(*) as count
  41. from tags, books_tags_link
  42. where tags.id = tag
  43. group by tags.id, tags.name
  44. order by tags.name');
  45. $entryArray = array();
  46. while ($post = $result->fetchObject ())
  47. {
  48. $tag = new Tag ($post->id, $post->name);
  49. array_push ($entryArray, new Entry ($tag->name, $tag->getEntryId (),
  50. str_format (localize("bookword", $post->count), $post->count), "text",
  51. array ( new LinkNavigation ($tag->getUri ()))));
  52. }
  53. return $entryArray;
  54. }
  55. }