From f288592c1a1ea1660e474303e6f72ffea5c5e493 Mon Sep 17 00:00:00 2001 From: Alec Kojaev Date: Sun, 4 Sep 2022 21:23:22 +0300 Subject: [PATCH] Initial commit. --- .gitignore | 5 + .l10nignore | 1 + .php-cs-fixer.dist.php | 18 + CHANGELOG.md | 9 + LICENSES/AGPL-3.0-or-later.txt | 235 +++ LICENSES/CC0-1.0.txt | 121 ++ Makefile | 155 ++ README.md | 73 + appinfo/info.xml | 24 + appinfo/routes.php | 74 + composer.json | 68 + composer.lock | 2019 +++++++++++++++++++ generate-icon.sh | 16 + img/icon.ico | Bin 0 -> 30670 bytes img/icon.svg | 39 + js/settings.js | 42 + l10n/ru.js | 37 + l10n/ru.json | 35 + lib/AppInfo/Application.php | 46 + lib/Calibre/CalibreDB.php | 129 ++ lib/Calibre/CalibreItem.php | 111 + lib/Calibre/ICalibreDB.php | 30 + lib/Calibre/Types/CalibreAuthor.php | 88 + lib/Calibre/Types/CalibreAuthorPrefix.php | 59 + lib/Calibre/Types/CalibreBook.php | 170 ++ lib/Calibre/Types/CalibreBookCriteria.php | 17 + lib/Calibre/Types/CalibreBookFormat.php | 91 + lib/Calibre/Types/CalibreBookId.php | 52 + lib/Calibre/Types/CalibreLanguage.php | 89 + lib/Calibre/Types/CalibrePublisher.php | 83 + lib/Calibre/Types/CalibreSeries.php | 83 + lib/Calibre/Types/CalibreTag.php | 83 + lib/Controller/OpdsController.php | 368 ++++ lib/Controller/SettingsController.php | 33 + lib/FeedBuilder/IOpdsFeedBuilder.php | 50 + lib/FeedBuilder/OpdsFeedBuilder.php | 182 ++ lib/Opds/OpdsApp.php | 57 + lib/Opds/OpdsAttribute.php | 61 + lib/Opds/OpdsAuthor.php | 47 + lib/Opds/OpdsCategory.php | 47 + lib/Opds/OpdsEntry.php | 198 ++ lib/Opds/OpdsLink.php | 47 + lib/Opds/OpdsResponse.php | 262 +++ lib/Opds/OpenSearchResponse.php | 57 + lib/Service/CalibreService.php | 15 + lib/Service/ICalibreService.php | 19 + lib/Service/IOpdsFeedService.php | 22 + lib/Service/ISettingsService.php | 94 + lib/Service/OpdsFeedService.php | 18 + lib/Service/SettingsService.php | 136 ++ lib/Settings/PersonalSettings.php | 27 + lib/Util/MapIterator.php | 126 ++ lib/Util/MimeTypes.php | 62 + lib/Util/mime.types | 18 + phpunit.xml | 32 + psalm.xml | 29 + templates/settings.personal.php | 16 + tests/files/metadata.sql | 641 ++++++ tests/files/test-data.sql | 59 + tests/stubs/CalibreStub.php | 31 + tests/stubs/L10NStub.php | 28 + tests/stubs/LoggerInterfaceStub.php | 46 + tests/stubs/SettingsServiceStub.php | 34 + tests/stubs/StorageStub.php | 74 + tests/stubs/URLGeneratorStub.php | 22 + tests/unit/CalibreTest.php | 353 ++++ tests/unit/OpdsFeedTest.php | 301 +++ tests/unit/OpdsSearchTest.php | 60 + tests/unit/OpdsTest.php | 140 ++ tests/unit/UtilTest.php | 43 + translationfiles/ru/calibre_opds.mo | Bin 0 -> 2796 bytes translationfiles/ru/calibre_opds.po | 171 ++ translationfiles/templates/calibre_opds.pot | 162 ++ 73 files changed, 8290 insertions(+) create mode 100644 .gitignore create mode 100644 .l10nignore create mode 100644 .php-cs-fixer.dist.php create mode 100644 CHANGELOG.md create mode 100644 LICENSES/AGPL-3.0-or-later.txt create mode 100644 LICENSES/CC0-1.0.txt create mode 100644 Makefile create mode 100644 README.md create mode 100644 appinfo/info.xml create mode 100644 appinfo/routes.php create mode 100644 composer.json create mode 100644 composer.lock create mode 100755 generate-icon.sh create mode 100644 img/icon.ico create mode 100644 img/icon.svg create mode 100644 js/settings.js create mode 100644 l10n/ru.js create mode 100644 l10n/ru.json create mode 100644 lib/AppInfo/Application.php create mode 100644 lib/Calibre/CalibreDB.php create mode 100644 lib/Calibre/CalibreItem.php create mode 100644 lib/Calibre/ICalibreDB.php create mode 100644 lib/Calibre/Types/CalibreAuthor.php create mode 100644 lib/Calibre/Types/CalibreAuthorPrefix.php create mode 100644 lib/Calibre/Types/CalibreBook.php create mode 100644 lib/Calibre/Types/CalibreBookCriteria.php create mode 100644 lib/Calibre/Types/CalibreBookFormat.php create mode 100644 lib/Calibre/Types/CalibreBookId.php create mode 100644 lib/Calibre/Types/CalibreLanguage.php create mode 100644 lib/Calibre/Types/CalibrePublisher.php create mode 100644 lib/Calibre/Types/CalibreSeries.php create mode 100644 lib/Calibre/Types/CalibreTag.php create mode 100644 lib/Controller/OpdsController.php create mode 100644 lib/Controller/SettingsController.php create mode 100644 lib/FeedBuilder/IOpdsFeedBuilder.php create mode 100644 lib/FeedBuilder/OpdsFeedBuilder.php create mode 100644 lib/Opds/OpdsApp.php create mode 100644 lib/Opds/OpdsAttribute.php create mode 100644 lib/Opds/OpdsAuthor.php create mode 100644 lib/Opds/OpdsCategory.php create mode 100644 lib/Opds/OpdsEntry.php create mode 100644 lib/Opds/OpdsLink.php create mode 100644 lib/Opds/OpdsResponse.php create mode 100644 lib/Opds/OpenSearchResponse.php create mode 100644 lib/Service/CalibreService.php create mode 100644 lib/Service/ICalibreService.php create mode 100644 lib/Service/IOpdsFeedService.php create mode 100644 lib/Service/ISettingsService.php create mode 100644 lib/Service/OpdsFeedService.php create mode 100644 lib/Service/SettingsService.php create mode 100644 lib/Settings/PersonalSettings.php create mode 100644 lib/Util/MapIterator.php create mode 100644 lib/Util/MimeTypes.php create mode 100644 lib/Util/mime.types create mode 100644 phpunit.xml create mode 100644 psalm.xml create mode 100644 templates/settings.personal.php create mode 100644 tests/files/metadata.sql create mode 100644 tests/files/test-data.sql create mode 100644 tests/stubs/CalibreStub.php create mode 100644 tests/stubs/L10NStub.php create mode 100644 tests/stubs/LoggerInterfaceStub.php create mode 100644 tests/stubs/SettingsServiceStub.php create mode 100644 tests/stubs/StorageStub.php create mode 100644 tests/stubs/URLGeneratorStub.php create mode 100644 tests/unit/CalibreTest.php create mode 100644 tests/unit/OpdsFeedTest.php create mode 100644 tests/unit/OpdsSearchTest.php create mode 100644 tests/unit/OpdsTest.php create mode 100644 tests/unit/UtilTest.php create mode 100644 translationfiles/ru/calibre_opds.mo create mode 100644 translationfiles/ru/calibre_opds.po create mode 100644 translationfiles/templates/calibre_opds.pot diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eca4e2d --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +build/ +vendor/ +.vscode/ +*.cache +.coverage/ diff --git a/.l10nignore b/.l10nignore new file mode 100644 index 0000000..a725465 --- /dev/null +++ b/.l10nignore @@ -0,0 +1 @@ +vendor/ \ No newline at end of file diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..f7bbdd8 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,18 @@ +getFinder() + ->ignoreVCSIgnored(true) + ->notPath('build') + ->notPath('l10n') + ->notPath('src') + ->notPath('vendor') + ->in(__DIR__); +return $config; diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..330cd87 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). + +## [0.0.1] - 2023-10-02 + +Initial release. diff --git a/LICENSES/AGPL-3.0-or-later.txt b/LICENSES/AGPL-3.0-or-later.txt new file mode 100644 index 0000000..0c97efd --- /dev/null +++ b/LICENSES/AGPL-3.0-or-later.txt @@ -0,0 +1,235 @@ +GNU AFFERO GENERAL PUBLIC LICENSE +Version 3, 19 November 2007 + +Copyright (C) 2007 Free Software Foundation, Inc. + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + + Preamble + +The GNU Affero General Public License is a free, copyleft license for software and other kinds of works, specifically designed to ensure cooperation with the community in the case of network server software. + +The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. + +When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. + +Developers that use our General Public Licenses protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License which gives you legal permission to copy, distribute and/or modify the software. + +A secondary benefit of defending all users' freedom is that improvements made in alternate versions of the program, if they receive widespread use, become available for other developers to incorporate. Many developers of free software are heartened and encouraged by the resulting cooperation. However, in the case of software used on network servers, this result may fail to come about. The GNU General Public License permits making a modified version and letting the public access it on a server without ever releasing its source code to the public. + +The GNU Affero General Public License is designed specifically to ensure that, in such cases, the modified source code becomes available to the community. It requires the operator of a network server to provide the source code of the modified version running there to the users of that server. Therefore, public use of a modified version, on a publicly accessible server, gives the public access to the source code of the modified version. + +An older license, called the Affero General Public License and published by Affero, was designed to accomplish similar goals. This is a different license, not a version of the Affero GPL, but Affero has released a new version of the Affero GPL which permits relicensing under this license. + +The precise terms and conditions for copying, distribution and modification follow. + + TERMS AND CONDITIONS + +0. Definitions. + +"This License" refers to version 3 of the GNU Affero General Public License. + +"Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. + +"The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. + +To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. + +A "covered work" means either the unmodified Program or a work based on the Program. + +To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. + +To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. + +An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. + +1. Source Code. +The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. + +A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. + +The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. + +The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those +subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same work. + +2. Basic Permissions. +All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. + +Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. + +3. Protecting Users' Legal Rights From Anti-Circumvention Law. +No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. + +When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. + +4. Conveying Verbatim Copies. +You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. + +You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. + +5. Conveying Modified Source Versions. +You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". + + c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. + +A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. + +6. Conveying Non-Source Forms. +You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: + + a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. + + d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. + +A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. + +"Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. + +If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). + +The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. + +7. Additional Terms. +"Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or authors of the material; or + + e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. + +All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. + +If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. + +8. Termination. + +You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). + +However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. + +Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. + +9. Acceptance Not Required for Having Copies. + +You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. + +10. Automatic Licensing of Downstream Recipients. + +Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. + +An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. + +11. Patents. + +A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". + +A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. + +In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. + +If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. + +A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. + +12. No Surrender of Others' Freedom. + +If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. + +13. Remote Network Interaction; Use with the GNU General Public License. + +Notwithstanding any other provision of this License, if you modify the Program, your modified version must prominently offer all users interacting with it remotely through a computer network (if your version supports such interaction) an opportunity to receive the Corresponding Source of your version by providing access to the Corresponding Source from a network server at no charge, through some standard or customary means of facilitating copying of software. This Corresponding Source shall include the Corresponding Source for any work covered by version 3 of the GNU General Public License that is incorporated pursuant to the following paragraph. + +Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the work with which it is combined will remain governed by version 3 of the GNU General Public License. + +14. Revised Versions of this License. + +The Free Software Foundation may publish revised and/or new versions of the GNU Affero General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation. + +If the Program specifies that a proxy can decide which future versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. + +Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. + +15. Disclaimer of Warranty. + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +16. Limitation of Liability. + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +17. Interpretation of Sections 15 and 16. + +If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. + +END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + +If your software can interact with users remotely through a computer network, you should also make sure that it provides a way for users to get its source. For example, if your program is a web application, its interface could display a "Source" link that leads users to an archive of the code. There are many ways you could offer source, and different solutions will be better for different programs; see section 13 for the specific requirements. + +You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU AGPL, see . diff --git a/LICENSES/CC0-1.0.txt b/LICENSES/CC0-1.0.txt new file mode 100644 index 0000000..0e259d4 --- /dev/null +++ b/LICENSES/CC0-1.0.txt @@ -0,0 +1,121 @@ +Creative Commons Legal Code + +CC0 1.0 Universal + + CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE + LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN + ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS + INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES + REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS + PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM + THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED + HEREUNDER. + +Statement of Purpose + +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator +and subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). + +Certain owners wish to permanently relinquish those rights to a Work for +the purpose of contributing to a commons of creative, cultural and +scientific works ("Commons") that the public can reliably and without fear +of later claims of infringement build upon, modify, incorporate in other +works, reuse and redistribute as freely as possible in any form whatsoever +and for any purposes, including without limitation commercial purposes. +These owners may contribute to the Commons to promote the ideal of a free +culture and the further production of creative, cultural and scientific +works, or to gain reputation or greater distribution for their Work in +part through the use and efforts of others. + +For these and/or other purposes and motivations, and without any +expectation of additional consideration or compensation, the person +associating CC0 with a Work (the "Affirmer"), to the extent that he or she +is an owner of Copyright and Related Rights in the Work, voluntarily +elects to apply CC0 to the Work and publicly distribute the Work under its +terms, with knowledge of his or her Copyright and Related Rights in the +Work and the meaning and intended legal effect of CC0 on those rights. + +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not +limited to, the following: + + i. the right to reproduce, adapt, distribute, perform, display, + communicate, and translate a Work; + ii. moral rights retained by the original author(s) and/or performer(s); +iii. publicity and privacy rights pertaining to a person's image or + likeness depicted in a Work; + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; + v. rights protecting the extraction, dissemination, use and reuse of data + in a Work; + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation + thereof, including any amended or successor version of such + directive); and +vii. other similar, equivalent or corresponding rights throughout the + world based on applicable law or treaty, and any national + implementations thereof. + +2. Waiver. To the greatest extent permitted by, but not in contravention +of, applicable law, Affirmer hereby overtly, fully, permanently, +irrevocably and unconditionally waives, abandons, and surrenders all of +Affirmer's Copyright and Related Rights and associated claims and causes +of action, whether now known or unknown (including existing as well as +future claims and causes of action), in the Work (i) in all territories +worldwide, (ii) for the maximum duration provided by applicable law or +treaty (including future time extensions), (iii) in any current or future +medium and for any number of copies, and (iv) for any purpose whatsoever, +including without limitation commercial, advertising or promotional +purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each +member of the public at large and to the detriment of Affirmer's heirs and +successors, fully intending that such Waiver shall not be subject to +revocation, rescission, cancellation, termination, or any other legal or +equitable action to disrupt the quiet enjoyment of the Work by the public +as contemplated by Affirmer's express Statement of Purpose. + +3. Public License Fallback. Should any part of the Waiver for any reason +be judged legally invalid or ineffective under applicable law, then the +Waiver shall be preserved to the maximum extent permitted taking into +account Affirmer's express Statement of Purpose. In addition, to the +extent the Waiver is so judged Affirmer hereby grants to each affected +person a royalty-free, non transferable, non sublicensable, non exclusive, +irrevocable and unconditional license to exercise Affirmer's Copyright and +Related Rights in the Work (i) in all territories worldwide, (ii) for the +maximum duration provided by applicable law or treaty (including future +time extensions), (iii) in any current or future medium and for any number +of copies, and (iv) for any purpose whatsoever, including without +limitation commercial, advertising or promotional purposes (the +"License"). The License shall be deemed effective as of the date CC0 was +applied by Affirmer to the Work. Should any part of the License for any +reason be judged legally invalid or ineffective under applicable law, such +partial invalidity or ineffectiveness shall not invalidate the remainder +of the License, and in such case Affirmer hereby affirms that he or she +will not (i) exercise any of his or her remaining Copyright and Related +Rights in the Work or (ii) assert any associated claims and causes of +action with respect to the Work, in either case contrary to Affirmer's +express Statement of Purpose. + +4. Limitations and Disclaimers. + + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. + b. Affirmer offers the Work as-is and makes no representations or + warranties of any kind concerning the Work, express, implied, + statutory or otherwise, including without limitation warranties of + title, merchantability, fitness for a particular purpose, non + infringement, or the absence of latent or other defects, accuracy, or + the present or absence of errors, whether or not discoverable, all to + the greatest extent permissible under applicable law. + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without + limitation any person's Copyright and Related Rights in the Work. + Further, Affirmer disclaims responsibility for obtaining any necessary + consents, permissions or other rights required for any use of the + Work. + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to + this CC0 or use of the Work. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3019084 --- /dev/null +++ b/Makefile @@ -0,0 +1,155 @@ +# SPDX-FileCopyrightText: Bernhard Posselt +# SPDX-License-Identifier: AGPL-3.0-or-later + +# Generic Makefile for building and packaging a Nextcloud app which uses npm and +# Composer. +# +# Dependencies: +# * make +# * which +# * curl: used if phpunit and composer are not installed to fetch them from the web +# * tar: for building the archive +# * npm: for building and testing everything JS +# +# If no composer.json is in the app root directory, the Composer step +# will be skipped. The same goes for the package.json which can be located in +# the app root or the js/ directory. +# +# The npm command by launches the npm build script: +# +# npm run build +# +# The npm test command launches the npm test script: +# +# npm run test +# +# The idea behind this is to be completely testing and build tool agnostic. All +# build tools and additional package managers should be installed locally in +# your project, since this won't pollute people's global namespace. +# +# The following npm scripts in your package.json install and update the bower +# and npm dependencies and use gulp as build system (notice how everything is +# run from the node_modules folder): +# +# "scripts": { +# "test": "node node_modules/gulp-cli/bin/gulp.js karma", +# "prebuild": "npm install && node_modules/bower/bin/bower install && node_modules/bower/bin/bower update", +# "build": "node node_modules/gulp-cli/bin/gulp.js" +# }, + +app_name=$(notdir $(CURDIR)) +build_tools_directory=$(CURDIR)/build/tools +source_build_directory=$(CURDIR)/build/artifacts/source +source_package_name=$(source_build_directory)/$(app_name) +appstore_build_directory=$(CURDIR)/build/artifacts/appstore +appstore_package_name=$(appstore_build_directory)/$(app_name) +npm=$(shell which npm 2> /dev/null) +composer=$(shell which composer 2> /dev/null) + +all: build + +# Fetches the PHP and JS dependencies and compiles the JS. If no composer.json +# is present, the composer step is skipped, if no package.json or js/package.json +# is present, the npm step is skipped +.PHONY: build +build: +ifneq (,$(wildcard $(CURDIR)/composer.json)) + make composer +endif +ifneq (,$(wildcard $(CURDIR)/package.json)) + make npm +endif +ifneq (,$(wildcard $(CURDIR)/js/package.json)) + make npm +endif + +# Installs and updates the composer dependencies. If composer is not installed +# a copy is fetched from the web +.PHONY: composer +composer: +ifeq (, $(composer)) + @echo "No composer command available, downloading a copy from the web" + mkdir -p $(build_tools_directory) + curl -sS https://getcomposer.org/installer | php + mv composer.phar $(build_tools_directory) + php $(build_tools_directory)/composer.phar install --prefer-dist +else + composer install --prefer-dist +endif + +# Installs npm dependencies +.PHONY: npm +npm: +ifeq (,$(wildcard $(CURDIR)/package.json)) + cd js && $(npm) run build +else + npm run build +endif + +# Removes the appstore build +.PHONY: clean +clean: + rm -rf ./build + +# Same as clean but also removes dependencies installed by composer, bower and +# npm +.PHONY: distclean +distclean: clean + rm -rf vendor + rm -rf node_modules + rm -rf js/vendor + rm -rf js/node_modules + +# Builds the source and appstore package +.PHONY: dist +dist: + make source + make appstore + +# Builds the source package +.PHONY: source +source: + rm -rf $(source_build_directory) + mkdir -p $(source_build_directory) + tar cvzf $(source_package_name).tar.gz \ + --exclude-vcs \ + --exclude="../$(app_name)/build" \ + --exclude="../$(app_name)/js/node_modules" \ + --exclude="../$(app_name)/node_modules" \ + --exclude="../$(app_name)/*.log" \ + --exclude="../$(app_name)/js/*.log" \ + ../$(app_name) + +# Builds the source package for the app store, ignores php and js tests +.PHONY: appstore +appstore: + rm -rf $(appstore_build_directory) + mkdir -p $(appstore_build_directory) + tar cvzf $(appstore_package_name).tar.gz \ + --exclude-vcs \ + --exclude="../$(app_name)/build" \ + --exclude="../$(app_name)/tests" \ + --exclude="../$(app_name)/Makefile" \ + --exclude="../$(app_name)/*.log" \ + --exclude="../$(app_name)/phpunit*xml" \ + --exclude="../$(app_name)/composer.*" \ + --exclude="../$(app_name)/js/node_modules" \ + --exclude="../$(app_name)/js/tests" \ + --exclude="../$(app_name)/js/test" \ + --exclude="../$(app_name)/js/*.log" \ + --exclude="../$(app_name)/js/package.json" \ + --exclude="../$(app_name)/js/bower.json" \ + --exclude="../$(app_name)/js/karma.*" \ + --exclude="../$(app_name)/js/protractor.*" \ + --exclude="../$(app_name)/package.json" \ + --exclude="../$(app_name)/bower.json" \ + --exclude="../$(app_name)/karma.*" \ + --exclude="../$(app_name)/protractor\.*" \ + --exclude="../$(app_name)/.*" \ + --exclude="../$(app_name)/js/.*" \ + ../$(app_name) + +.PHONY: test +test: composer + $(CURDIR)/vendor/phpunit/phpunit/phpunit -c phpunit.xml +# $(CURDIR)/vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml diff --git a/README.md b/README.md new file mode 100644 index 0000000..36c9e1b --- /dev/null +++ b/README.md @@ -0,0 +1,73 @@ +# Nextcloud Calibre2OPDS app + +The Calibre2OPDS app provides access to user's [Calibre](https://calibre-ebook.com/) library +stored in Nextcloud via [OPDS](https://specs.opds.io/opds-1.2). + +[OpenSearch](https://github.com/dewitt/opensearch) is supported for searching in the library. + +The source code is [available on GitLab](https://gitlab.com/oldnomad/calibre_opds/). + +## Usage + +This app is intended to be used in situation where you are storing your whole +Calibre library directory in your Nextcloud instance. + +The app exposes Calibre library contents as OPDS feeds. If your Nextcloud is at URL +`https://example.com/index.php`, then the root OPDS feed is available at URL +`https://example.com/index.php/apps/calibre_opds/`. + +### Settings + +This app has no administrator settings. + +Personal settings for this app are in settings section "Sharing". The only parameter that +can be modified at the moment is path to Calibre library folder (by default `Books`). + +## OPDS structure + +OPDS generated by this app uses [Dublin Core](https://www.dublincore.org/specifications/dublin-core/dcmi-terms/) +for representing Calibre metadata information. Following representation decisions are made: + +### Dates and timestamps + +- Calibre book record timestamp is represented by Atom tag ``. +- Calibre book record last modification timestamp is represented by Atom tag ``. +- Calibre publication date is represented by Dublin Core attribute `dc:issued`. + +### Book identifiers + +- Calibre book record UUID is represented as an identifier (Dublin core attribute `dc:identifier`) with prefix `urn:uuid:`. +- All other book identifiers are also represented by Dublin Core attribute `dc:identifier`. +- Identifiers with types `uri`, `urn`, and `epubbud` are published as-is. + Identifiers of all other types are prefixed by `urn:id-type:`, where `id-type` is the identifier type. + +### Authors, publishers, series, tags + +- Calibre author link is always represented in subtag `` of Atom tag ``. +- Calibre book publisher is represented by Dublin Core attribute `dc:publisher`. +- Calibre book series is represented by Dublin Core attribute `dc:isPartOf`, referring + to complete list of books in the series. +- Calibre book series index is not represented, since Dublin Core lacks corresponding vocabulary. +- Calibre book tag is represented by Atom tag `` without schema or label. + +### Other metadata + +- Atom tag `` is filled with Calibre book comment. +- Calibre book annotations, ratings, last read positions and custom columns are ignored. + +### Other decisions + +- Feed items are usually sorted in alphabetic order by name or title. The only exception + is book acquisition feed of a series, which is sorted by series index first, followed + by book title. +- All feeds are non-paginated. It is expected that a personal library saved in Nextcloud + is not large enough for pagination to be necessary. However, pagination may be implemented + at a later date. +- Search terms in OpenSearch are interpreted as a case-insensitive + [PCRE](http://www.pcre.org/current/doc/html/pcre2pattern.html) pattern. + Matches are looked for in: + - Book title. + - Book description (Calibre comments). + - Book author names. + - Book series names. + - Book tags. diff --git a/appinfo/info.xml b/appinfo/info.xml new file mode 100644 index 0000000..433295f --- /dev/null +++ b/appinfo/info.xml @@ -0,0 +1,24 @@ + + + calibre_opds + Calibre2OPDS + + 0.0.1 + agpl + Alec Kojaev + Calibre2OPDS + files + tools + https://gitlab.com/oldnomad/calibre_opds/ + https://gitlab.com/oldnomad/calibre_opds/-/issues + https://gitlab.com/oldnomad/calibre_opds.git + + + pdo_sqlite + + + + OCA\Calibre2OPDS\Settings\PersonalSettings + + diff --git a/appinfo/routes.php b/appinfo/routes.php new file mode 100644 index 0000000..c7350b2 --- /dev/null +++ b/appinfo/routes.php @@ -0,0 +1,74 @@ + [ + [ + // Root index + 'name' => 'opds#index', + 'url' => '/' + ], + [ + // Authors by prefix or all authors + 'name' => 'opds#authors', + 'url' => '/authors/{prefix}', + 'defaults' => [ 'prefix' => '' ] + ], + [ + // Prefixes for authors + 'name' => 'opds#author_prefixes', + 'url' => '/author-prefixes/{length}', + 'defaults' => [ 'length' => '1' ] + ], + [ + // Publishers + 'name' => 'opds#publishers', + 'url' => '/publishers' + ], + [ + // Languages + 'name' => 'opds#languages', + 'url' => '/languages' + ], + [ + // Series + 'name' => 'opds#series', + 'url' => '/series' + ], + [ + // Tags + 'name' => 'opds#tags', + 'url' => '/tags' + ], + [ + // Books by criterion (author, publisher, etc) or search result or all books + 'name' => 'opds#books', + 'url' => '/books/{criterion}/{id}', + 'defaults' => [ 'criterion' => '', 'id' => '' ] + ], + [ + // OpenSearch descriptor + 'name' => 'opds#search_xml', + 'url' => '/search.xml' + ], + [ + // Book acquisition + 'name' => 'opds#book_data', + 'url' => '/data/{id}/{type}', + 'requirements' => [ 'id' => '[0-9]+' ] + ], + [ + // Book cover + 'name' => 'opds#book_cover', + 'url' => '/cover/{id}', + 'requirements' => [ 'id' => '[0-9]+' ] + ], + // Settings controller + [ + 'name' => 'settings#settings', + 'url' => '/settings', + 'verb' => 'PUT', + ], + ] +]; diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..04bb6c5 --- /dev/null +++ b/composer.json @@ -0,0 +1,68 @@ +{ + "name": "oldnomad/calibre_opds", + "description": "Simple OPDS server that uses Calibre database as a backend.", + "type": "project", + "keywords": [], + "homepage": "https://gitlab.com/oldnomad/calibre_opds", + "readme": "README.md", + "license": "AGPL-3.0-or-later", + "authors": [ + { + "name": "Alec Kojaev", + "email": "alec@kojaev.name" + } + ], + "autoload": { + "psr-4": { + "OCA\\Calibre2OPDS\\": "lib", + "OCP\\": "vendor/nextcloud/ocp/OCP" + } + }, + "autoload-dev": { + "psr-4": { + "Stubs\\": "tests/stubs" + } + }, + "repositories": [ + { + "type": "package", + "package": { + "name": "nextcloud/translationtool", + "version": "0-dev", + "dist": { + "url": "https://github.com/nextcloud/docker-ci/raw/master/translations/translationtool/translationtool.phar", + "type": "file" + } + } + } + ], + "require-dev": { + "nextcloud/ocp": "^26", + "nextcloud/coding-standard": "^1", + "nextcloud/translationtool": "^0-dev", + "php-parallel-lint/php-parallel-lint": "^1", + "psalm/phar": "^5", + "phpunit/phpunit": "^10" + }, + "scripts": { + "cs": "php-cs-fixer fix --using-cache=no --dry-run --diff", + "lint": "parallel-lint ./appinfo ./lib", + "phpunit": "XDEBUG_MODE=coverage phpunit", + "psalm": "psalm.phar --config=psalm.xml --no-cache", + "tests": [ + "@lint", + "@cs", + "@psalm", + "@phpunit" + ], + "translate:scan": "php ./vendor/nextcloud/translationtool/translationtool.phar create-pot-files", + "translate:generate": "php ./vendor/nextcloud/translationtool/translationtool.phar convert-po-files" + }, + "scripts-descriptions": { + "cs": "Checks that the code conforms to the coding standard.", + "lint": "Runs unit tests.", + "phpunit": "Run all unit tests.", + "psalm": "Runs static analysis.", + "tests": "Runs all available tests." + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..17ee24d --- /dev/null +++ b/composer.lock @@ -0,0 +1,2019 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "3ae10b24f9cff97ed0ff8e534d63c8f7", + "packages": [], + "packages-dev": [ + { + "name": "myclabs/deep-copy", + "version": "1.11.1", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "conflict": { + "doctrine/collections": "<1.6.8", + "doctrine/common": "<2.13.3 || >=3,<3.2.2" + }, + "require-dev": { + "doctrine/collections": "^1.6.8", + "doctrine/common": "^2.13.3 || ^3.2.2", + "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" + }, + "type": "library", + "autoload": { + "files": [ + "src/DeepCopy/deep_copy.php" + ], + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.11.1" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", + "type": "tidelift" + } + ], + "time": "2023-03-08T13:26:56+00:00" + }, + { + "name": "nextcloud/coding-standard", + "version": "v1.1.1", + "source": { + "type": "git", + "url": "https://github.com/nextcloud/coding-standard.git", + "reference": "55def702fb9a37a219511e1d8c6fe8e37164c1fb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nextcloud/coding-standard/zipball/55def702fb9a37a219511e1d8c6fe8e37164c1fb", + "reference": "55def702fb9a37a219511e1d8c6fe8e37164c1fb", + "shasum": "" + }, + "require": { + "php": "^7.3|^8.0", + "php-cs-fixer/shim": "^3.17" + }, + "type": "library", + "autoload": { + "psr-4": { + "Nextcloud\\CodingStandard\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christoph Wurst", + "email": "christoph@winzerhof-wurst.at" + } + ], + "description": "Nextcloud coding standards for the php cs fixer", + "support": { + "issues": "https://github.com/nextcloud/coding-standard/issues", + "source": "https://github.com/nextcloud/coding-standard/tree/v1.1.1" + }, + "time": "2023-06-01T12:05:01+00:00" + }, + { + "name": "nextcloud/ocp", + "version": "v26.0.7", + "source": { + "type": "git", + "url": "https://github.com/nextcloud-deps/ocp.git", + "reference": "c2f4514e717e60c492c4d62031bd84a0cabde52c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/c2f4514e717e60c492c4d62031bd84a0cabde52c", + "reference": "c2f4514e717e60c492c4d62031bd84a0cabde52c", + "shasum": "" + }, + "require": { + "php": "^7.4 || ~8.0 || ~8.1", + "psr/container": "^1.1.1", + "psr/event-dispatcher": "^1.0", + "psr/log": "^1.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "26.0.0-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "AGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Christoph Wurst", + "email": "christoph@winzerhof-wurst.at" + } + ], + "description": "Composer package containing Nextcloud's public API (classes, interfaces)", + "support": { + "issues": "https://github.com/nextcloud-deps/ocp/issues", + "source": "https://github.com/nextcloud-deps/ocp/tree/v26.0.7" + }, + "time": "2023-09-06T00:30:37+00:00" + }, + { + "name": "nextcloud/translationtool", + "version": "0-dev", + "dist": { + "type": "file", + "url": "https://github.com/nextcloud/docker-ci/raw/master/translations/translationtool/translationtool.phar" + }, + "type": "library" + }, + { + "name": "nikic/php-parser", + "version": "v4.17.1", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=7.0" + }, + "require-dev": { + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.9-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v4.17.1" + }, + "time": "2023-08-13T19:53:39+00:00" + }, + { + "name": "phar-io/manifest", + "version": "2.0.3", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "97803eca37d319dfa7826cc2437fc020857acb53" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/97803eca37d319dfa7826cc2437fc020857acb53", + "reference": "97803eca37d319dfa7826cc2437fc020857acb53", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-phar": "*", + "ext-xmlwriter": "*", + "phar-io/version": "^3.0.1", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "support": { + "issues": "https://github.com/phar-io/manifest/issues", + "source": "https://github.com/phar-io/manifest/tree/2.0.3" + }, + "time": "2021-07-20T11:28:43+00:00" + }, + { + "name": "phar-io/version", + "version": "3.2.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "support": { + "issues": "https://github.com/phar-io/version/issues", + "source": "https://github.com/phar-io/version/tree/3.2.1" + }, + "time": "2022-02-21T01:04:05+00:00" + }, + { + "name": "php-cs-fixer/shim", + "version": "v3.34.1", + "source": { + "type": "git", + "url": "https://github.com/PHP-CS-Fixer/shim.git", + "reference": "1798523107e53d081364553cb1627a04e2063cbe" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHP-CS-Fixer/shim/zipball/1798523107e53d081364553cb1627a04e2063cbe", + "reference": "1798523107e53d081364553cb1627a04e2063cbe", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-tokenizer": "*", + "php": "^7.4 || ^8.0" + }, + "replace": { + "friendsofphp/php-cs-fixer": "self.version" + }, + "suggest": { + "ext-dom": "For handling output formats in XML", + "ext-mbstring": "For handling non-UTF8 characters." + }, + "bin": [ + "php-cs-fixer", + "php-cs-fixer.phar" + ], + "type": "application", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Dariusz Rumiński", + "email": "dariusz.ruminski@gmail.com" + } + ], + "description": "A tool to automatically fix PHP code style", + "support": { + "issues": "https://github.com/PHP-CS-Fixer/shim/issues", + "source": "https://github.com/PHP-CS-Fixer/shim/tree/v3.34.1" + }, + "time": "2023-10-03T23:51:46+00:00" + }, + { + "name": "php-parallel-lint/php-parallel-lint", + "version": "v1.3.2", + "source": { + "type": "git", + "url": "https://github.com/php-parallel-lint/PHP-Parallel-Lint.git", + "reference": "6483c9832e71973ed29cf71bd6b3f4fde438a9de" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-parallel-lint/PHP-Parallel-Lint/zipball/6483c9832e71973ed29cf71bd6b3f4fde438a9de", + "reference": "6483c9832e71973ed29cf71bd6b3f4fde438a9de", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": ">=5.3.0" + }, + "replace": { + "grogy/php-parallel-lint": "*", + "jakub-onderka/php-parallel-lint": "*" + }, + "require-dev": { + "nette/tester": "^1.3 || ^2.0", + "php-parallel-lint/php-console-highlighter": "0.* || ^1.0", + "squizlabs/php_codesniffer": "^3.6" + }, + "suggest": { + "php-parallel-lint/php-console-highlighter": "Highlight syntax in code snippet" + }, + "bin": [ + "parallel-lint" + ], + "type": "library", + "autoload": { + "classmap": [ + "./src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Jakub Onderka", + "email": "ahoj@jakubonderka.cz" + } + ], + "description": "This tool check syntax of PHP files about 20x faster than serial check.", + "homepage": "https://github.com/php-parallel-lint/PHP-Parallel-Lint", + "support": { + "issues": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/issues", + "source": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/tree/v1.3.2" + }, + "time": "2022-02-21T12:50:22+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "10.1.7", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "355324ca4980b8916c18b9db29f3ef484078f26e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/355324ca4980b8916c18b9db29f3ef484078f26e", + "reference": "355324ca4980b8916c18b9db29f3ef484078f26e", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-xmlwriter": "*", + "nikic/php-parser": "^4.15", + "php": ">=8.1", + "phpunit/php-file-iterator": "^4.0", + "phpunit/php-text-template": "^3.0", + "sebastian/code-unit-reverse-lookup": "^3.0", + "sebastian/complexity": "^3.0", + "sebastian/environment": "^6.0", + "sebastian/lines-of-code": "^2.0", + "sebastian/version": "^4.0", + "theseer/tokenizer": "^1.2.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.1" + }, + "suggest": { + "ext-pcov": "PHP extension that provides line coverage", + "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "10.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.7" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-10-04T15:34:17+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "4.1.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "a95037b6d9e608ba092da1b23931e537cadc3c3c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a95037b6d9e608ba092da1b23931e537cadc3c3c", + "reference": "a95037b6d9e608ba092da1b23931e537cadc3c3c", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/4.1.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-08-31T06:24:48+00:00" + }, + { + "name": "phpunit/php-invoker", + "version": "4.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-invoker.git", + "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7", + "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "ext-pcntl": "*", + "phpunit/phpunit": "^10.0" + }, + "suggest": { + "ext-pcntl": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Invoke callables with a timeout", + "homepage": "https://github.com/sebastianbergmann/php-invoker/", + "keywords": [ + "process" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-invoker/issues", + "source": "https://github.com/sebastianbergmann/php-invoker/tree/4.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:56:09+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "3.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "0c7b06ff49e3d5072f057eb1fa59258bf287a748" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/0c7b06ff49e3d5072f057eb1fa59258bf287a748", + "reference": "0c7b06ff49e3d5072f057eb1fa59258bf287a748", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "security": "https://github.com/sebastianbergmann/php-text-template/security/policy", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/3.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-08-31T14:07:24+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "6.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/e2a2d67966e740530f4a3343fe2e030ffdc1161d", + "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "source": "https://github.com/sebastianbergmann/php-timer/tree/6.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:57:52+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "10.4.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "9784e877e3700de37475545bdbdce8383ff53d25" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9784e877e3700de37475545bdbdce8383ff53d25", + "reference": "9784e877e3700de37475545bdbdce8383ff53d25", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "ext-xmlwriter": "*", + "myclabs/deep-copy": "^1.10.1", + "phar-io/manifest": "^2.0.3", + "phar-io/version": "^3.0.2", + "php": ">=8.1", + "phpunit/php-code-coverage": "^10.1.5", + "phpunit/php-file-iterator": "^4.0", + "phpunit/php-invoker": "^4.0", + "phpunit/php-text-template": "^3.0", + "phpunit/php-timer": "^6.0", + "sebastian/cli-parser": "^2.0", + "sebastian/code-unit": "^2.0", + "sebastian/comparator": "^5.0", + "sebastian/diff": "^5.0", + "sebastian/environment": "^6.0", + "sebastian/exporter": "^5.1", + "sebastian/global-state": "^6.0.1", + "sebastian/object-enumerator": "^5.0", + "sebastian/recursion-context": "^5.0", + "sebastian/type": "^4.0", + "sebastian/version": "^4.0" + }, + "suggest": { + "ext-soap": "To be able to generate mocks based on WSDL files" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "10.4-dev" + } + }, + "autoload": { + "files": [ + "src/Framework/Assert/Functions.php" + ], + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "security": "https://github.com/sebastianbergmann/phpunit/security/policy", + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.4.0" + }, + "funding": [ + { + "url": "https://phpunit.de/sponsors.html", + "type": "custom" + }, + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit", + "type": "tidelift" + } + ], + "time": "2023-10-06T03:41:22+00:00" + }, + { + "name": "psalm/phar", + "version": "5.15.0", + "source": { + "type": "git", + "url": "https://github.com/psalm/phar.git", + "reference": "19dde3eba5901ff50ca43a5e4c43540f097e0511" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/psalm/phar/zipball/19dde3eba5901ff50ca43a5e4c43540f097e0511", + "reference": "19dde3eba5901ff50ca43a5e4c43540f097e0511", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "conflict": { + "vimeo/psalm": "*" + }, + "bin": [ + "psalm.phar" + ], + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Composer-based Psalm Phar", + "support": { + "issues": "https://github.com/psalm/phar/issues", + "source": "https://github.com/psalm/phar/tree/5.15.0" + }, + "time": "2023-08-21T03:20:52+00:00" + }, + { + "name": "psr/container", + "version": "1.1.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/container.git", + "reference": "513e0666f7216c7459170d56df27dfcefe1689ea" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea", + "reference": "513e0666f7216c7459170d56df27dfcefe1689ea", + "shasum": "" + }, + "require": { + "php": ">=7.4.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Psr\\Container\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common Container Interface (PHP FIG PSR-11)", + "homepage": "https://github.com/php-fig/container", + "keywords": [ + "PSR-11", + "container", + "container-interface", + "container-interop", + "psr" + ], + "support": { + "issues": "https://github.com/php-fig/container/issues", + "source": "https://github.com/php-fig/container/tree/1.1.2" + }, + "time": "2021-11-05T16:50:12+00:00" + }, + { + "name": "psr/event-dispatcher", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/event-dispatcher.git", + "reference": "dbefd12671e8a14ec7f180cab83036ed26714bb0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/event-dispatcher/zipball/dbefd12671e8a14ec7f180cab83036ed26714bb0", + "reference": "dbefd12671e8a14ec7f180cab83036ed26714bb0", + "shasum": "" + }, + "require": { + "php": ">=7.2.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\EventDispatcher\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Standard interfaces for event handling.", + "keywords": [ + "events", + "psr", + "psr-14" + ], + "support": { + "issues": "https://github.com/php-fig/event-dispatcher/issues", + "source": "https://github.com/php-fig/event-dispatcher/tree/1.0.0" + }, + "time": "2019-01-08T18:20:26+00:00" + }, + { + "name": "psr/log", + "version": "1.1.4", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "support": { + "source": "https://github.com/php-fig/log/tree/1.1.4" + }, + "time": "2021-05-03T11:20:27+00:00" + }, + { + "name": "sebastian/cli-parser", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/cli-parser.git", + "reference": "efdc130dbbbb8ef0b545a994fd811725c5282cae" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/efdc130dbbbb8ef0b545a994fd811725c5282cae", + "reference": "efdc130dbbbb8ef0b545a994fd811725c5282cae", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for parsing CLI options", + "homepage": "https://github.com/sebastianbergmann/cli-parser", + "support": { + "issues": "https://github.com/sebastianbergmann/cli-parser/issues", + "source": "https://github.com/sebastianbergmann/cli-parser/tree/2.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:58:15+00:00" + }, + { + "name": "sebastian/code-unit", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit.git", + "reference": "a81fee9eef0b7a76af11d121767abc44c104e503" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/a81fee9eef0b7a76af11d121767abc44c104e503", + "reference": "a81fee9eef0b7a76af11d121767abc44c104e503", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the PHP code units", + "homepage": "https://github.com/sebastianbergmann/code-unit", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit/issues", + "source": "https://github.com/sebastianbergmann/code-unit/tree/2.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:58:43+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "5e3a687f7d8ae33fb362c5c0743794bbb2420a1d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/5e3a687f7d8ae33fb362c5c0743794bbb2420a1d", + "reference": "5e3a687f7d8ae33fb362c5c0743794bbb2420a1d", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/3.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:59:15+00:00" + }, + { + "name": "sebastian/comparator", + "version": "5.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "2db5010a484d53ebf536087a70b4a5423c102372" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/2db5010a484d53ebf536087a70b4a5423c102372", + "reference": "2db5010a484d53ebf536087a70b4a5423c102372", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-mbstring": "*", + "php": ">=8.1", + "sebastian/diff": "^5.0", + "sebastian/exporter": "^5.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "https://github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/comparator/issues", + "security": "https://github.com/sebastianbergmann/comparator/security/policy", + "source": "https://github.com/sebastianbergmann/comparator/tree/5.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-08-14T13:18:12+00:00" + }, + { + "name": "sebastian/complexity", + "version": "3.1.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/complexity.git", + "reference": "68cfb347a44871f01e33ab0ef8215966432f6957" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/68cfb347a44871f01e33ab0ef8215966432f6957", + "reference": "68cfb347a44871f01e33ab0ef8215966432f6957", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.10", + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for calculating the complexity of PHP code units", + "homepage": "https://github.com/sebastianbergmann/complexity", + "support": { + "issues": "https://github.com/sebastianbergmann/complexity/issues", + "security": "https://github.com/sebastianbergmann/complexity/security/policy", + "source": "https://github.com/sebastianbergmann/complexity/tree/3.1.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-09-28T11:50:59+00:00" + }, + { + "name": "sebastian/diff", + "version": "5.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/912dc2fbe3e3c1e7873313cc801b100b6c68c87b", + "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0", + "symfony/process": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "security": "https://github.com/sebastianbergmann/diff/security/policy", + "source": "https://github.com/sebastianbergmann/diff/tree/5.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-05-01T07:48:21+00:00" + }, + { + "name": "sebastian/environment", + "version": "6.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "43c751b41d74f96cbbd4e07b7aec9675651e2951" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/43c751b41d74f96cbbd4e07b7aec9675651e2951", + "reference": "43c751b41d74f96cbbd4e07b7aec9675651e2951", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "suggest": { + "ext-posix": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "https://github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/environment/issues", + "security": "https://github.com/sebastianbergmann/environment/security/policy", + "source": "https://github.com/sebastianbergmann/environment/tree/6.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-04-11T05:39:26+00:00" + }, + { + "name": "sebastian/exporter", + "version": "5.1.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "64f51654862e0f5e318db7e9dcc2292c63cdbddc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/64f51654862e0f5e318db7e9dcc2292c63cdbddc", + "reference": "64f51654862e0f5e318db7e9dcc2292c63cdbddc", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": ">=8.1", + "sebastian/recursion-context": "^5.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "https://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/exporter/issues", + "security": "https://github.com/sebastianbergmann/exporter/security/policy", + "source": "https://github.com/sebastianbergmann/exporter/tree/5.1.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-09-24T13:22:09+00:00" + }, + { + "name": "sebastian/global-state", + "version": "6.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "7ea9ead78f6d380d2a667864c132c2f7b83055e4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/7ea9ead78f6d380d2a667864c132c2f7b83055e4", + "reference": "7ea9ead78f6d380d2a667864c132c2f7b83055e4", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "sebastian/object-reflector": "^3.0", + "sebastian/recursion-context": "^5.0" + }, + "require-dev": { + "ext-dom": "*", + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/global-state/issues", + "security": "https://github.com/sebastianbergmann/global-state/security/policy", + "source": "https://github.com/sebastianbergmann/global-state/tree/6.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-07-19T07:19:23+00:00" + }, + { + "name": "sebastian/lines-of-code", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/lines-of-code.git", + "reference": "649e40d279e243d985aa8fb6e74dd5bb28dc185d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/649e40d279e243d985aa8fb6e74dd5bb28dc185d", + "reference": "649e40d279e243d985aa8fb6e74dd5bb28dc185d", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.10", + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for counting the lines of code in PHP source code", + "homepage": "https://github.com/sebastianbergmann/lines-of-code", + "support": { + "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", + "security": "https://github.com/sebastianbergmann/lines-of-code/security/policy", + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/2.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-08-31T09:25:50+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "5.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "202d0e344a580d7f7d04b3fafce6933e59dae906" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/202d0e344a580d7f7d04b3fafce6933e59dae906", + "reference": "202d0e344a580d7f7d04b3fafce6933e59dae906", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "sebastian/object-reflector": "^3.0", + "sebastian/recursion-context": "^5.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/5.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:08:32+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "24ed13d98130f0e7122df55d06c5c4942a577957" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/24ed13d98130f0e7122df55d06c5c4942a577957", + "reference": "24ed13d98130f0e7122df55d06c5c4942a577957", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-reflector/issues", + "source": "https://github.com/sebastianbergmann/object-reflector/tree/3.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:06:18+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "5.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "05909fb5bc7df4c52992396d0116aed689f93712" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/05909fb5bc7df4c52992396d0116aed689f93712", + "reference": "05909fb5bc7df4c52992396d0116aed689f93712", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "https://github.com/sebastianbergmann/recursion-context", + "support": { + "issues": "https://github.com/sebastianbergmann/recursion-context/issues", + "source": "https://github.com/sebastianbergmann/recursion-context/tree/5.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:05:40+00:00" + }, + { + "name": "sebastian/type", + "version": "4.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/type.git", + "reference": "462699a16464c3944eefc02ebdd77882bd3925bf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/462699a16464c3944eefc02ebdd77882bd3925bf", + "reference": "462699a16464c3944eefc02ebdd77882bd3925bf", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the types of the PHP type system", + "homepage": "https://github.com/sebastianbergmann/type", + "support": { + "issues": "https://github.com/sebastianbergmann/type/issues", + "source": "https://github.com/sebastianbergmann/type/tree/4.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:10:45+00:00" + }, + { + "name": "sebastian/version", + "version": "4.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "c51fa83a5d8f43f1402e3f32a005e6262244ef17" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c51fa83a5d8f43f1402e3f32a005e6262244ef17", + "reference": "c51fa83a5d8f43f1402e3f32a005e6262244ef17", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "support": { + "issues": "https://github.com/sebastianbergmann/version/issues", + "source": "https://github.com/sebastianbergmann/version/tree/4.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-07T11:34:05+00:00" + }, + { + "name": "theseer/tokenizer", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/34a41e998c2183e22995f158c581e7b5e755ab9e", + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "support": { + "issues": "https://github.com/theseer/tokenizer/issues", + "source": "https://github.com/theseer/tokenizer/tree/1.2.1" + }, + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2021-07-28T10:34:58+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": { + "nextcloud/translationtool": 20 + }, + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.3.0" +} diff --git a/generate-icon.sh b/generate-icon.sh new file mode 100755 index 0000000..dabf31a --- /dev/null +++ b/generate-icon.sh @@ -0,0 +1,16 @@ +#!/bin/sh +# +# This requires: +# - librsvg2-bin (for `rsvg-convert`); +# - netpbm (for `pngtopam` and `pamtowinicon`). +# +set -e + +CUR_DIR=$(dirname "$0") +SIZES="256 128 64 32 16" + +cd "$CUR_DIR" +for sz in $SIZES +do + rsvg-convert -f png -w "$sz" -h "$sz" img/icon.svg | pngtopam --alphapam +done | pamtowinicon >img/icon.ico diff --git a/img/icon.ico b/img/icon.ico new file mode 100644 index 0000000000000000000000000000000000000000..9635206d69a3a062ba659cddb6f362cfbd67a6b1 GIT binary patch literal 30670 zcmeHw2|U%y`~RHd9Q#i8EwW~7vt&D!MAD`t#IY3-QbM+KD5NMA}kiBGnNFUbv1fzTX8?QvYY9!#&vuABrzviWmFaA z!aa_)>{Bbq+bx9c=GrYjDl2hx?&76O52@tTnB^p$;q=^B6Tao%u`JJtXP0IbEZQf3 z=u8kYAj#n*{HIh@$+$+vuQAjKs?=HcDyA>3F6DIFjk>mi-bZZ%77FfKhEsA`2K7U7 ziZ$ir#~$MEHW#8qf+W?Rf+OSgxD45({Fm>Hom!xR}mtf%$v9_H~^@p47QwD*^D z16h{gEYocWZPbTUQ7RK(693jRx!*BDVGUy4>U5EE|9*s5V0ZmP5oVtST~2!(GfIJ` z)A>qy+Lgt~5QP#4v#y+)MU%xh#ho2=j3~B2fv&nkK4iLJoh+Aq>j`fvhHt1a zR35m-_UkYbC0>j>C4g4c#`mzDW1=^ zlHE%O!a^ujE%EhK(PPZU#Yrtrws#E)p^pLtruB0_5bY{^^^U1>xvwEMtdI|HaAf%8 z<;wRuLJf>%S^a07qih4odJX;dDrj}fI}SRIZgPpoNLo77W59odx_xEzV@Hv|^BUdh zb;}dx&CB!k-p14qOgLIscdh9*(Sgr_%OQF&HXVP9%r~r+{3e)roECAbr_qZ;rk!o; z!=*1SIku(v^dG0*dQn<@AcY#itt(YkX)n^BqOex;)k(+BrY8;=1Fv8D7?-Z(dHANc z@c6OF<}Dm0K`jIYYxk%{D^(dYIxDLW2z0g&gl4^!>%HnIA?82~J<)$wqfzU;U`IJ0 znQ52$wlG|xAFnOrQ^e7~JUQIiCqRFwkq>34uXwY5J>yV7NA1o#sj_7EWuoWQmtVU5 z++%>vQ`AqZu6O{aiF@FD*E6#E+I5PotMkxWxL&dl#0cXPf9|zOhnxj4Gk{X(qLNr5;oQu}l zpl&&7|C8DkVPTF>5i7RJ$Gu{ zIw}8hcXWcw$@}@1(!QG~E9|t^gh@}cU;aSw;((|?QQbPD?ViTVTvqJ3Am_+h#MgiF zcwFecBhGbprpB*D0}Is^(-kewzDsuEy0=l4p-R_0719$G@04Oh_Z82SyvuT_+}XlN(EoM-Zkny> zrS~U&NV~8!f9j%+t>WHOGEWV7b5hhUIG#}3JDInL)uHu#!d$bw028A3(z^y05gxj| z%{Cn?mDkL|$xR}j8i!nKpUD#GZxzmdLMm7b z{eDK23KGdeJN78ly1s1@d0!&#Ju9Qe^}Vy;24)UfyjLkRx%Ry=`_NL?)i<<=l!_Z< z-DV!EA?fDuP+Waxrk#;67x)*gFZXpBuFlaCkW{E88YZ5qEjXZzEc`NWy~-dsD)w(OF)J)` zn!WxygELilHaEY4E}5T5n$3w+_qzFHQ<7`1+IxyTNUtamKXypARJh(O7}Z_Ud=yO$@Xe7lZa$o_FRb{4JKs1KvXtIjhHXZ#Udhs0T8oWZUu#D` zw?QF2=;$v(^^cyXTJ^hM*s&M!w?$K`*;0t!HuSOaFt@cW za(cSN5+2ZqbQCV)aEo7ZVNXRscXVHJS2=I`LS&v~t4pg|OW9THbzQ&MmfbuSPfDtA zWP7K_i(as*&%?=C^g17ph?~!{%HjTEwseUz{6xwGeZEkWM^9XJ$&}iNmUGCf;a-vz zC)&G!w-UFT+%fLi`pmmg3c_e|My(zRXL4@sz4o$QD#*>aTBxqL2cI9%yI)0;?e=Rr zv~^>ZM6KkS*ZGop93d=vZEAu_9A_pHDNB-~)>1SD6QOz4iFwVpZfee)}A)uuj$!#CMl?!j?SlDOv+e$Lou+Jttj{ zO2!Jzs!gIDaIH0+(d4m$BuJ#FKbgunNcR^pm`KxgXQ7_ETUgFH8SKXWD>HP-M8DbR ze~~npSp=h*C1EF%W(}MxtxbE023s@Q)~pWpOT&|nb@MWcJ(9OKQf^jkU~7uA;_XHS6gD) z+zhufSF6t9B)3SfE@VA_$4cWRs8YPtHkS1+Aq3MiUG<1a$?CR!^LnX#Dq9G&rpSpb zTGXt4@!`OHPcMnP!d5?Ko05zk4>_=ThPu5B9_TVdU0K{ zFH(EcMNXg{8>LtrIW$-0DO7}6i=aTk4$&uI%U|q@nlqoQ%(xhvuC#9sC-U3`^4N{{D(6Y3 zH9~KsiIk}`XQCU^RkMt{&KcU` z7xQ>#t%G$e{!P%EnkpaKMzD@)mQ?%3do`iZv#eS@%65>8NA}Y)ENNt_grrzB&mTL) z+ciZ4>)Cq2eosIBSx>Z`eH}!7&qvvo%4rFs8V~(iMGwV1wT9bUy99O^K;1J^H`pi} zf~Ai@m+E8I2so^l&}%)md-~2Ct}9RVD0q@Y7rsD8uA(X%bl+!tDs>u&LIzOI8nFZG z@XyvG1L&3^v=yDE&UcI1L4v2{T&B~9MJcVAvJO|_fHn7B+GChPr}4REkI}8=d=9U& zb}B7G=BJ;~1IVIzs*m>^&jz)hYUwS<&`!J=Rh;+=(=*TAQMD_arj9FqW40VMSb5jW zWxzz;>z`*Bq;Xr+=Q+#cj>EevVH!+%N|wrGNfj1OO!a|o@AG807qne3rS}TJJPDK{ z;pA>k#TN-X+-hk%I>WsO_n1vRaG`lQG*;)Ytr0}bo8EAnr_;~c(sd*&&r0mcS!|$I zhDe+jbJ%}*H~XMcMh6~{c)vo`pe~`Dwe!3K8IqLa4fksFpr@N*0;}UsCSa;>J_}kI z=hBK|VvD5Tm<_|40|injm_0D%6?kpdLL$dR&6F_1$>nIX7z(U;y;h2>kf+z+r|6fQ zY9|4nLrzkZXIXl!K#PE5APcZn%cs&5Om+Br%}PczW@!TdUN%Fk`McR((HsSWKwENl zMm?l1bFq$UbHF#eJiPlI^kLUj4Lw(=J$C`QdU&=nbsdaI6rPkN;_GZ5EjmzW7(}V< zVD_Pu3r7!u(e*qlRm9t=uwkyPs9#F*;ul~9Y_{?cWaN~yS%d4a34Gj$Ya218jbe=r zt?>gQ=SB`a+zXW*1Q@>biAp;i4L!yLEeoSfjODLacyFa2NNh>*9TLZk;%*020zkS|$y4&}JCw*dsdj2m*YTyTE;CMj%#`Sy9xooBP@^ZbHwsY3MRo(T40FHv&9e#J5-?`&<&(;cFOyQzAA9ED`Mn1=knEVBG`?E~yiW?Z_d1%L z(60IFnnn*w_rD%o=Io0Pm+~p%vdq7_$=7ctV4X$?oqS&Xb_3c|Hh<#8Mn-w9pXu4% zt_FA>1YY84S`_US=7KE@E%*o14kkyY1P~@z=kmb85rKVHINuE~Fh$Htk@X`}mhZu!0 zJlDY&W=*jeBt#E(6X`B-vQ3tGVN9g6x@p_hjrQ!&kRC}1PkVaLR8~2tZTYjqM_sBL z6l$A8W|zho8HwiI+;lfh$-&E{#Bq=s!KqsmY2>1pjdmodvmzQ3-*<1g>o|u`zt_7hjiJIWNc0{W& zTV*0S^lo-mJ@n#Q&P}tCx~82|A&dtfZ$6Zd`6D@=7AFa6Y;E_3YzR z$$ZIhq43azV$LC}^UcC}tW_(VyV&HG>u$B;OMC#MF)KdZ6w-#_O zMzLD{w|P|RO|uTKm@NV3wInuxCDhQksPjbmGKVDshY`P%p@my(vGpdMM-18|!Tol< z`XkMk1W5)NpHI7-;X@0iOIA1znD7iWSm=+3o@|N9W|gi~Lg{hLC^ma1OMR!6i()B6 zT3h6GeDBeHhb*>DA*613xoZDS)6!@Se}C9S7zgu;xxRc`r|%sxJnf|#o^BPXQO=i7 zdmPz>Grk{r;Mf7gpD~Zjvg(({8C++KQDv;p%*FTj6QYrF*syPsc}j1&!EHJHy;yRQ_7v;K&)?DaO})1L z5TiZJ&U@zV@trJZ&rwTVqUmQ>;Owt1yMM>qu|@^Q@SMO3HPo zJQBRhTI0Vwf8mA z0_O$FA$hHoqT23j?x+YhX}t;Y!9r-TvhtcFU-JUA)5@Hy)Tz2?IXz=b5l@it-~!c~ zFHJ=Am?J)LH4P{tK0p0 z8T#RAN9$~9fw(?r`>U(!JiSdGd1yU5NYh=h)B51?ykw)9TRm-XvgJDO=S|*hbS=fK zut!)0#2#^z_2% z)Q)_GW}B99vY+7KiRqg(jJAZouEzHzCmOx5eu0K%`h%jv9}6=SBCFmNXGsktKN?c( zl|8WCDPn)ryRZj5LmFq_H?GRNQy!DoR$$4mJe`_LA6{ub_*V4tqp(~PzL!Ktm*&zQ z0lF-uiIy?GzF@6M*^`&*5z;7JG3ISs85_lfWmvMK^c9N?Yq+Sv1k&V_Y(c1hnfJ~> z;Xd6PDmu0UT9+TGy?qgu>ty;3LG4|{_~DR?>j*l}5Cn_a^G#3ABuD=C>=;qtF=gcJ zxZK$JIzk-RKb{?@+j}p0I4-)hn}^|^x0WJYL*P!n&HCs}7WIq;i>lJDV>M?M&sLo9 z?zZ957hZ?Vb}g1)8g}enjIr731IKn9Gd|ONNKov`=B%X@r8Ay5N$v@IHu2Zf%N)E7 zv-vvGF4VeKyT1xp*?Dro^w-_nR^_zTG3!Dy&h`?y%e6=Sw~c6d;DKl!^1v4$1Bw<- zgJwXpq#crQO!?(X8zlqf;$2A#pPXk6J!m5;rdv-@pz*{-i0_iprIgc7igl&9DCV*C zOEa41rA}lClBX2ohO{a1cS3|{&p3xF61FSR+i1p_Wl=fpMeOs`>LY%+(y@k?Oww9> z*7pGY;tRAmxT?lemXA`3_hsp1D`|au%&0|;vWE7{Gt&dk3zmsiPe?v9?fkC0K}zM# z>-VM1G26o($-N^pk&sH|G3V;IM9`+3sj+sWbkQV9e0h?!9EQB=*TRk{h8n0bLR8=1 zk5_niZ63OQN%Td6Sygo@_ld@f-r`Liomq;_j=!9lAZU0dXp+?yg0gSpT*Og=55@Hz zS3HxCKe|9O89mrkm62!=&NFpt*(&NBsxQ82_UhMcJ1&-{F;5fqSR8x_3HVh;4#k1{ zq)bZ1>3iL3$`1*jnzHxFu0(+W_o%=gmmV?XL@d}UU&0+KW6P)BO`kw?Ab6S$KP$@& zbRgd5)mt`r`T3P|?RH(Fu6N#?E~b_5PtT$l^W*L*N=P3MzA}AC)Yv@v4!&kf(Xuk? z6eUD@=OHmwK7EehJ7PJMKkT~_#7(KMcqQ2C`pvA%(4puKajChAQUTCX(Porpa zF1tt;ets<^nES$YCRZBX=UH(Ida1CC?zQ)QN2vDnx&#&XnunV&w#-I@Asa*Y>@7Q4 zHbXyn{^cUK&dm?0s}5}_iD_72Y?R()b&~dwCC7dGT>0*{1=A^2lyeT6^~yFZ>}=Fk z&04|*t8>g}%-Q_7i{3KhQq@iAJ?KS(@qoZW+nheSGRtg_S1PfnH+b@kZ5*WMb0h|* zF~Z2ZBDV&_?m1i_zvj}O$mF6_v-i;;#tku-M@#8@ahs zk^dW<_!jonMu*&q3w52Hg-8htsL6}_MRz$g@Ts$kFAdE|N{-XU2_I6u^z0`t#M>N`>)Z|| zC7+svyD=fUs_g9@i<_x9A=*6NYul%+W9|~F>m=W7#VJwt7IB5D9c^}26jixn5oK@Ise`z;cewYUxOJp(Zn<%htZx%V;Ypjk z-~8w}KGh4)$KR+liF|)D4uH^QEGdZT#Ab<)z9y z9o!5er*X0Gg&YY#{9%3pkGy?;ZrvN*9D+Odpl2(~vSX~!y3_PQ=;Vc9F0q*Hlru?N zBPk0zpE~3Bq;k-$Ecm=~y6;(uu|8*&S>!)?q7tR1qK>;_cq$pMVkO2O=f20b^F0zG zc@Fc0azCUVpR0MQy;+%Yah`?6JamX-$JxzyjuY(?_n@uRTvdJ5IF3w17jwRchh?Gu z_JwFw;+0I+v+Znq&^1?fJ)XcF<1SCN-Rj03Ojw?)Br*>@JqRNsaF|7clD#YK1`LQX z*JO2Xyh?@wEsI;EFz1Qk?O@;fZ0)7CnHuxZeF06iqxZSh zXY^`h5$np9@CcCtD)!3QbOFO-2l?3D7G1q~Xt-c*3)X{Ut(=S!Zi!*i)!7@W%i?LP zcBbt?QVV@pTk6)`CM-1Kk~i|kAKCwqYH-1bZQAXOkyI+JNzv%U*&|Qpy7_Y0jOUsc zQbnMfako1+X5)k?l0C*y%CA*VTi%{$o7#mdw3P>GD_FAE#6kOF7{BuJd5Xj=Xgns%Ny(qBv->=coty-^}%( zZ*>oK6KtPiN;Ecg-dmtB30BfKf%sCw$sDAEWBM0+2vMBgQ5;ooxZtnIl^r-jtG3oV zaz@-XN;rsfxxV+iX9ra2Vl7pKg}%a9xww-jGESRUXdl4UnHs7w&hFGqI)OHz(hbGr zhs9oJBb(N?dhs=}(p||H?jc$2DON>k4%FO(uLH*WA}xHGm0M!7fu<jmjQTF00s>g7ntE6uKo*(=^DA+?X zPxy8;hnDDaED%uIzj3WFv0 zewB@_=iE~Ab7h1mybmd^+Gm$?`pzQC^6c2*XR`RY=pG&7do{*Hx~{S2y`{)A)73Ef zmz*+RucTW~x*m0H6dI=>YAoL4t=}S-H*R>AC+@~L4L8pIRUWx~bysiH+Z;ZL*TZ=m zq|NW?I^CoVKV#LAj^gjod=;FB0~Kf2-QQJ0F_OFAo;h4m0Vl~Z{_7rF~5e` z*c1i;`v7tS>|aBe3_j@AS9Kf!=FUNAXe&ZYaQ2w1fo4Nm0wD$qLIZGF^eP^qAZTnd z5T+;J8Ylt+%fAXcCLeZobtZ8BI_#Kyu(BUq)UW9$0j|dOQUEiCe>6ow9vNsl=mjX$ zYtWMhXjBg9Tf%<{zkx79-J@~;QQ8vp0`#TyTfjrz{|tT@`$%KZ@jt>lIv*whlO2IA z`nEv9bQ+rjUqb|f2os5a)N4$)zeHHsuhf6g=SF$Jv;-&^Xf)o@X$L67g%IuA;KMtE z{|0^@821*SfbBTyvJX#7*aR)8(^`Bwb@5&LH)3pW09jF^5~18D-m zJZDM)%>aV$0+=yC*cu7gReuEhp!<8~BJ}=q{Ga~@$BgL-Gz&-uh!qI*1;hWX;Xh&j zz>c;00;bO~|Jm<(P!@FJ_g!|KTS11d0 zZv9Qzv1b0w`OgYt*+(4%egp84p-%V@f}bQhhW#$41A-sceV8(TTlm+;AI33uCPIUs zbo)y&3_3RVvGXK23i{i^zlI;y{f8c7(Ea657UuqizYY0^hW;)5{4kaSF=N25{bB4u zWPfY;x9~5PALHByeR%`OC;YAG|0Vkm{`-E|!wr9F&VPEo9`po!zK*{cJJ#I4GXAjN zZSx<4?#~BVL7l801ivg`>5Ur$eo*>uz>fXdiN8Di8{_Y$F$SL>+wa023G;c!{oUZ9 zz3+}6*08h7#xVA)p)AM6EX(;rtqEv>csyb_$R~56SNcI`0)G(vv$47SwYra$!`^cP_DMeiegfR%z-;-~;tvJ|t~N^go9DL&M(-zYylb#f||#_=wnk&-Dkvzih%7_PcQ) zC)gukXFYO10)D`fh3(@@9b@s&&i_dxWBD!&Fnx}H z^l!}9!OjFG1A)ATVf?rJ5cnsK+*A7MJAIg3L_X|yO@0Xcnj?2L1}T7R^qBu%8haNA zW8VkZ;fVOVgjHj^|13YY`_FJs9Ps3WPQQhhc752pUJT>!VaM`T0KwcZ|1QWsFyY7U zv|}>h=eK758GXF}{v3U}|E>jhJO7NZJMsjC`7m(ggA`yBV18?$8M2HtK@r0-`{5V#h{@pl z7{jBHH10!8{}g}Br;mzhAJa6p59L3_l#gl3$96}@=wm*T{ZMaIJp3^|j7&zJkB)~> z#7O?=xc_5*Kl*@cbjdXNOvkikKsMuBUOYhf{zc|9R%B)F9wph_~zey zmntOW#zdCDd-S)rSl$N}|5d}XaPAxn=IYaa6T3sX6!se95z6~j!QUoG7%!|3pA#>y zB@^iZFO1*kgysDXe+4+l3i^!yr+$D;?);YJuX6ql{vxo)YzMr|nLwaOBl~MA#Bc`r zrT0qTEPo+{JlB18<{t-q{eYlP*tdO@U!nbN;+y${?DH|6pJe_iw)*hR=x=m&R2ROP z{}hC3KJolKo`lf#QM`UH`K|m_VBEVt=ZpP@Lq#U&{?XrKI4bX(_=_X7DeQM-zXrZt zfkSOL;{9UyCjPMI6^_P^rC}a417~=x{>AVu{0Y+$s{1|u>R*4h^_TgBu{U;xbEMJy zqXEARLi@gm{6m4i%pVr0y_|Nm8iyI-B{$CaTGXIGnP~9}4{?{-D@4FvouLO#!yfUVx5zrY`>0?Wm3_8(Z@ALV0puplUe5EghVWJgg3S)#`^HFKJYET>=EXRfzx$jH2*Ku=kx@-jn&8Oi0*ISN&YE+utRpR z(H~ih;5(lluuY@)TYp*~*3raIw$vWJ5gyfdEcvJPu{xjXV{MJ4J_kZN(C3lA!xRe` z;9kn|vDAn15tz&{{vgA4sLM5$`j%ifKlL3O!{4ckW&NT4K>a36Z!j`OXxksu$MpC0 z@98hBn`P_az7iGg>MH&DcL$%(na_V?f4EK>bO5%Xe}BLZOfl*LqP2ZS)$sds%7FAo J!peTC_kRWUesTZ+ literal 0 HcmV?d00001 diff --git a/img/icon.svg b/img/icon.svg new file mode 100644 index 0000000..1a64385 --- /dev/null +++ b/img/icon.svg @@ -0,0 +1,39 @@ + + + Icon for Calibre2OPDS + + + + + + + + + + + + + + \ No newline at end of file diff --git a/js/settings.js b/js/settings.js new file mode 100644 index 0000000..2d02b0b --- /dev/null +++ b/js/settings.js @@ -0,0 +1,42 @@ +/** + * Update Calibre2OPDS settings + */ +(function (window, document, $) { + 'use strict'; + + $(document).ready(function () { + var libraryRoot = $('#calibre_opds input[name="calibre_opds_library"]'); + var savedMessage = $('#calibre_opds div[name="calibre_opds_saved"]'); + + var saved = function () { + if (savedMessage.is(':visible')) { + savedMessage.hide(); + } + savedMessage.fadeIn(function () { + setTimeout(function () { + savedMessage.fadeOut(); + }, 5000); + }); + }; + + var submit = function () { + var libraryRootValue = libraryRoot.val(); + var data = { + libraryRoot: libraryRootValue + }; + var url = OC.generateUrl('/apps/calibre_opds/settings'); + $.ajax({ + type: 'PUT', + contentType: 'application/json; charset=utf-8', + url: url, + data: JSON.stringify(data), + dataType: 'json' + }).then(function (data) { + saved(); + libraryRoot.val(libraryRootValue); + }); + }; + + $('#calibre_opds input[type="text"]').blur(submit); + }); +} (window, document, jQuery)); diff --git a/l10n/ru.js b/l10n/ru.js new file mode 100644 index 0000000..ef7c61f --- /dev/null +++ b/l10n/ru.js @@ -0,0 +1,37 @@ +OC.L10N.register( + "calibre_opds", + { + "Nextcloud OPDS Library" : "Библиотека Nextcloud OPDS", + "Authors" : "Авторы", + "All authors" : "Все авторы", + "Publishers" : "Издательства", + "All publishers" : "Все издательства", + "Languages" : "Языки", + "All languages" : "Все языки", + "Series" : "Серии", + "All series" : "Все серии", + "Tags" : "Теги", + "All tags" : "Все теги", + "Books" : "Книги", + "All books" : "Все книги", + "Authors by prefix %1$s" : "Авторы, начинающиеся на %1$s", + "Authors by prefix" : "Авторы по началу имени", + "All books matching: /%1$s/" : "Все книги по поиску: /%1$s/", + "All books by author: %1$s" : "Все книги автора: %1$s", + "All books by publisher: %1$s" : "Все книги издательства: %1$s", + "All books in language: %1$s" : "Все книги на языке: %1$s", + "All books in series: %1$s" : "Все книги в серии: %1$s", + "All books with tag: %1$s" : "Все книги с тегом: %1$s", + "Search" : "Поиск", + "Search books" : "Поиск книг", + "Search books with matching titles, authors, series, or tags." : "Поиск книг по заглавиям, авторам, сериям, и тегам.", + "Authors: %1$s" : "Авторов: %1$s", + "Books: %1$s" : "Книг: %1$s", + "Calibre2OPDS" : "Calibre2OPDS", + "Simple OPDS server that uses Calibre database as a backend." : "Простой OPDS-сервер, использующий библиотеку Calibre в качестве источника.", + "Calibre OPDS library" : "Библиотека Calibre OPDS", + "Publish your Calibre library in OPDS" : "Опубликуйте свою библиотеку в OPDS", + "Library root folder:" : "Корневая папка библиотеки:", + "Saved" : "Сохранено" +}, +"nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 || n%100>14) ? 1 : 2);"); diff --git a/l10n/ru.json b/l10n/ru.json new file mode 100644 index 0000000..121659e --- /dev/null +++ b/l10n/ru.json @@ -0,0 +1,35 @@ +{ "translations": { + "Nextcloud OPDS Library" : "Библиотека Nextcloud OPDS", + "Authors" : "Авторы", + "All authors" : "Все авторы", + "Publishers" : "Издательства", + "All publishers" : "Все издательства", + "Languages" : "Языки", + "All languages" : "Все языки", + "Series" : "Серии", + "All series" : "Все серии", + "Tags" : "Теги", + "All tags" : "Все теги", + "Books" : "Книги", + "All books" : "Все книги", + "Authors by prefix %1$s" : "Авторы, начинающиеся на %1$s", + "Authors by prefix" : "Авторы по началу имени", + "All books matching: /%1$s/" : "Все книги по поиску: /%1$s/", + "All books by author: %1$s" : "Все книги автора: %1$s", + "All books by publisher: %1$s" : "Все книги издательства: %1$s", + "All books in language: %1$s" : "Все книги на языке: %1$s", + "All books in series: %1$s" : "Все книги в серии: %1$s", + "All books with tag: %1$s" : "Все книги с тегом: %1$s", + "Search" : "Поиск", + "Search books" : "Поиск книг", + "Search books with matching titles, authors, series, or tags." : "Поиск книг по заглавиям, авторам, сериям, и тегам.", + "Authors: %1$s" : "Авторов: %1$s", + "Books: %1$s" : "Книг: %1$s", + "Calibre2OPDS" : "Calibre2OPDS", + "Simple OPDS server that uses Calibre database as a backend." : "Простой OPDS-сервер, использующий библиотеку Calibre в качестве источника.", + "Calibre OPDS library" : "Библиотека Calibre OPDS", + "Publish your Calibre library in OPDS" : "Опубликуйте свою библиотеку в OPDS", + "Library root folder:" : "Корневая папка библиотеки:", + "Saved" : "Сохранено" +},"pluralForm" :"nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 || n%100>14) ? 1 : 2);" +} \ No newline at end of file diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php new file mode 100644 index 0000000..b4bde09 --- /dev/null +++ b/lib/AppInfo/Application.php @@ -0,0 +1,46 @@ +registerService(ICalibreService::class, function (ContainerInterface $c): ICalibreService { + /** @var ICalibreService */ + return $c->get(CalibreService::class); + }); + $context->registerService(IOpdsFeedService::class, function (ContainerInterface $c): IOpdsFeedService { + /** @var IOpdsFeedService */ + return $c->get(OpdsFeedService::class); + }); + $context->registerService(ISettingsService::class, function (ContainerInterface $c): ISettingsService { + /** @var ISettingsService */ + return $c->get(SettingsService::class); + }); + } +} diff --git a/lib/Calibre/CalibreDB.php b/lib/Calibre/CalibreDB.php new file mode 100644 index 0000000..fc62750 --- /dev/null +++ b/lib/Calibre/CalibreDB.php @@ -0,0 +1,129 @@ + PDO::ERRMODE_EXCEPTION ]; + if ($readOnly) { + $attr[PDO::SQLITE_ATTR_OPEN_FLAGS] = PDO::SQLITE_OPEN_READONLY; + } + $this->database = new PDO('sqlite:'.$dsn, null, null, $attr); + if (!$readOnly) { + // Following functions are used by some triggers + /** @psalm-suppress TooManyArguments -- Psalm is mistaken about PDO::sqliteCreateFunction() (has 4 args since 7.1.4) */ + $this->database->sqliteCreateFunction('title_sort', function (string $name): string { + return preg_replace('/^(A|The|An)\s+(.*)$/i', '${2}, ${1}', $name, 1); + }, 1, PDO::SQLITE_DETERMINISTIC); + $this->database->sqliteCreateFunction('uuid4', function (): string { + $data = random_bytes(16); + $data[6] = chr(ord($data[6]) & 0x0f | 0x40); + $data[8] = chr(ord($data[8]) & 0x3f | 0x80); + return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); + }, 0); + } + } + + /** + * Open database for a Calibre library. + * + * @param Folder $root library root folder. + * @param bool $readOnly flag to open database as read-only. + * + * @return ICalibreDB database object. + * + * @throws NotFoundException if database file is not found. + * @throws PDOException on database failure. + */ + public static function fromFolder(Folder $root, bool $readOnly = true): ICalibreDB { + $meta = $root->get(self::METADATA_DB); + if (!$meta->isReadable() || $meta->getType() !== FileInfo::TYPE_FILE) { + throw new NotFoundException('Library metadata is not a readable file'); + } + $meta_local = $meta->getStorage()->getLocalFile($meta->getInternalPath()); + if (!is_string($meta_local)) { + throw new NotFoundException('Library metadata cannot be found'); + } + return new self($meta_local, $readOnly); + } + + /** + * Get database PDO interface. + * + * This method should be used only for tests. + * + * @return PDO PDO interface. + */ + public function getDatabase(): PDO { + return $this->database; + } + + /** + * Query the database for a list of result rows. + * + * @param string $sql SQL statement. + * @param array $parameters SQL statement parameters. + * + * @return Traversable list of result rows (associative arrays). + * @throws PDOException on failure. + */ + public function query(string $sql, array $parameters = []): Traversable { + $stmt = $this->database->prepare($sql); + if (!$stmt->execute($parameters)) { + throw new PDOException('execute failure'); + } + $stmt->setFetchMode(PDO::FETCH_ASSOC); + return $stmt; + } + + /** + * Query the database for a single result row. + * + * @param string $sql SQL statement. + * @param array $parameters SQL statement parameters. + * + * @return array|null result row (associative array), or `null` if not found. + * @throws PDOException on failure. + */ + public function querySingle(string $sql, array $parameters = []): ?array { + $stmt = $this->database->prepare($sql); + if (!$stmt->execute($parameters)) { + throw new PDOException('execute failure'); + } + /** @var false|array */ + $row = $stmt->fetch(PDO::FETCH_ASSOC); + return ($row === false) ? null : $row; + } +} diff --git a/lib/Calibre/CalibreItem.php b/lib/Calibre/CalibreItem.php new file mode 100644 index 0000000..3f03c5f --- /dev/null +++ b/lib/Calibre/CalibreItem.php @@ -0,0 +1,111 @@ +data = $this->mangle($db, $data); + } + + /** + * Mangle, if necessary, result row data. + * + * @param ICalibreDB $db Calibre database. + * @param array $data result row data. + * + * @return array mangled data. + */ + protected function mangle(ICalibreDB $db, array $data): array { + return $data; + } + + /** + * Update item name. + * + * @param string $name new item name. + */ + public function setName(string $name): void { + $this->data['name'] = $name; + } + + public function __isset(string $name): bool { + return array_key_exists($name, $this->data); + } + + public function __get(string $name): mixed { + if (array_key_exists($name, $this->data)) { + return $this->data[$name]; + } + $trace = debug_backtrace(); + $file = $trace[0]['file'] ?? '???'; + $line = $trace[0]['line'] ?? '???'; + trigger_error(sprintf('Getting unknown property %s from object of class %s in %s on line %d', + $name, get_class($this), $file, $line), E_USER_ERROR); + return null; + } + + /** + * Parse database timestamp value. + * + * @param mixed $value column value. + * + * @return DateTimeInterface|null timestamp value, or `null` if empty. + */ + protected static function parseTimestamp(mixed $value): ?DateTimeInterface { + if (!is_string($value) || $value === '') { + return null; + } + $timestamp = new DateTimeImmutable($value); + if ($timestamp->getTimestamp() == self::NULL_TIMESTAMP) { + return null; + } + return $timestamp; + } +} diff --git a/lib/Calibre/ICalibreDB.php b/lib/Calibre/ICalibreDB.php new file mode 100644 index 0000000..327bc4d --- /dev/null +++ b/lib/Calibre/ICalibreDB.php @@ -0,0 +1,30 @@ + iterator over results, represented as associative arrays. + */ + public function query(string $sql, array $parameters = []): Traversable; + + /** + * Query the database for a single (first) resulting rows. + * + * @param string $sql SQL statement to execute. + * @param array $parameters parameters for SQL statement. + * @return ?array resulting row, represented as an associative array. + */ + public function querySingle(string $sql, array $parameters = []): ?array; +} diff --git a/lib/Calibre/Types/CalibreAuthor.php b/lib/Calibre/Types/CalibreAuthor.php new file mode 100644 index 0000000..c49cc94 --- /dev/null +++ b/lib/Calibre/Types/CalibreAuthor.php @@ -0,0 +1,88 @@ + list of author entries. + * @throws PDOException on error. + */ + public static function getByPrefix(ICalibreDB $db, string $prefix = ''): Traversable { + $where = ''; + if ($prefix !== '') { + $where = 'where SUBSTR(authors.sort, 1, LENGTH(param)) = param'; + } + return new MapIterator( + $db->query(sprintf(self::SQL_AUTHORS, $where), [$prefix]), + fn (array $row) => new self($db, $row) + ); + } + + /** + * Get authors for a book. + * + * @param ICalibreDB $db Calibre database. + * @param mixed $book_id book ID. + * + * @return Traversable list of author entries. + * @throws PDOException on error. + */ + public static function getByBook(ICalibreDB $db, $book_id): Traversable { + return new MapIterator( + $db->query(sprintf(self::SQL_AUTHORS, 'where bal.book = param'), [$book_id]), + fn (array $row) => new self($db, $row) + ); + } + + /** + * Get author by author ID. + * + * @param ICalibreDB $db Calibre database. + * @param mixed $id author ID. + * + * @return self|null author entry, or `null` if not found. + * @throws PDOException on error. + */ + public static function getById(ICalibreDB $db, $id): ?self { + $data = $db->querySingle(sprintf(self::SQL_AUTHORS, 'where authors.id = param'), [$id]); + return is_null($data) ? null : new self($db, $data); + } +} diff --git a/lib/Calibre/Types/CalibreAuthorPrefix.php b/lib/Calibre/Types/CalibreAuthorPrefix.php new file mode 100644 index 0000000..ec5a93a --- /dev/null +++ b/lib/Calibre/Types/CalibreAuthorPrefix.php @@ -0,0 +1,59 @@ + list of author prefix entries. + * @throws PDOException on error. + */ + public static function getAll(ICalibreDB $db, int $length = 1): Traversable { + return new MapIterator( + $db->query(self::SQL_AUTHOR_PREFIXES, [$length]), + fn (array $row) => new self($db, $row) + ); + } +} diff --git a/lib/Calibre/Types/CalibreBook.php b/lib/Calibre/Types/CalibreBook.php new file mode 100644 index 0000000..d38a8f4 --- /dev/null +++ b/lib/Calibre/Types/CalibreBook.php @@ -0,0 +1,170 @@ +has_cover) { + return null; + } + /** @var string $this->path */ + $filename = $this->path.'/cover.jpg'; + $data = $root->get($filename); + if (!$data->isReadable() || $data->getType() !== FileInfo::TYPE_FILE || !($data instanceof File)) { + return null; + } + return $data; + } + + /** + * Get books, optionally filtered by a criterion. + * + * @param ICalibreDB $db Calibre database. + * @param CalibreBookCriteria|null $criterion optional criterion type. + * @param string $data optional criterion data. + * + * @return Traversable list of book entries. + * @throws PDOException on error. + */ + public static function getByCriterion(ICalibreDB $db, ?CalibreBookCriteria $criterion = null, string $data = ''): Traversable { + $join = ''; + $where = ''; + $sort = ''; + $terms = null; + $params = [$data]; + $filter = null; + switch ($criterion) { + case CalibreBookCriteria::SEARCH: + /* @var string */ + $dataEsc = str_replace('/', '\/', $data); + $terms = '/'.$dataEsc.'/inS'; + $filter = function (CalibreBook $item) use ($terms): bool { + $haystack = [ $item->title, $item->comment ?? '' ]; + /** @var CalibreAuthor $author */ + foreach ($item->authors as $author) { + array_push($haystack, $author->name); + } + /** @var CalibreSeries $series */ + foreach ($item->series as $series) { + array_push($haystack, $series->name); + } + /** @var CalibreTag $tag */ + foreach ($item->tags as $tag) { + array_push($haystack, $tag->name); + } + /** @psalm-suppress MixedArgumentTypeCoercion -- Psalm gets confused about type of $haystack */ + $match = preg_grep($terms, $haystack); + /** @psalm-suppress RedundantConditionGivenDocblockType -- Psalm is mistaken about return type of preg_grep() */ + return $match !== false && count($match) > 0; + }; + $params = []; + break; + case CalibreBookCriteria::AUTHOR: + $where = 'where bal.author = ?'; + $join = 'inner join books_authors_link as bal on books.id = bal.book'; + break; + case CalibreBookCriteria::PUBLISHER: + $where = 'where bpl.publisher = ?'; + $join = 'inner join books_publishers_link as bpl on books.id = bpl.book'; + break; + case CalibreBookCriteria::LANGUAGE: + $where = 'where bll.lang_code = ?'; + $join = 'inner join books_languages_link as bll on books.id = bll.book'; + break; + case CalibreBookCriteria::SERIES: + $where = 'where bsl.series = ?'; + $join = 'inner join books_series_link as bsl on books.id = bsl.book'; + $sort = 'books.series_index,'; + break; + case CalibreBookCriteria::TAG: + $where = 'where btl.tag = ?'; + $join = 'inner join books_tags_link as btl on books.id = btl.book'; + break; + default: + $params = []; + break; + } + return new MapIterator( + $db->query(sprintf(self::SQL_BOOKS, $join, $where, $sort), $params), + fn (array $row) => new self($db, $row), + $filter + ); + } + + /** + * Get book by book ID. + * + * @param ICalibreDB $db Calibre database. + * @param mixed $id book ID. + * + * @return self|null book entry, or `null` if not found. + * @throws PDOException on error. + */ + public static function getById(ICalibreDB $db, $id): ?self { + $data = $db->querySingle(sprintf(self::SQL_BOOKS, '', 'where books.id = ?', ''), [$id]); + return is_null($data) ? null : new self($db, $data); + } +} diff --git a/lib/Calibre/Types/CalibreBookCriteria.php b/lib/Calibre/Types/CalibreBookCriteria.php new file mode 100644 index 0000000..faa1fa7 --- /dev/null +++ b/lib/Calibre/Types/CalibreBookCriteria.php @@ -0,0 +1,17 @@ +path + * @var string $this->name + * @var string $this->format + */ + $filename = $this->path.'/'.$this->name.'.'.strtolower($this->format); + $data = $root->get($filename); + if (!$data->isReadable() || $data->getType() !== FileInfo::TYPE_FILE || !($data instanceof File)) { + return null; + } + return $data; + } + + /** + * Get available data formats for a book. + * + * @param ICalibreDB $db Calibre database. + * @param mixed $book_id book ID. + * + * @return Traversable list of book data entries. + * @throws PDOException on error. + */ + public static function getByBook(ICalibreDB $db, $book_id): Traversable { + return new MapIterator( + $db->query(sprintf(self::SQL_BOOK_DATA, 'where books.id = ?'), [$book_id]), + fn (array $row) => new self($db, $row) + ); + } + + + /** + * Get specific data format for a book. + * + * @param ICalibreDB $db Calibre database. + * @param mixed $book_id book ID. + * @param string $type format name. + * + * @return self|null book data entry, or `null` if not found. + * @throws PDOException on error. + */ + public static function getByBookAndType(ICalibreDB $db, $book_id, string $type): ?self { + $data = $db->querySingle(sprintf(self::SQL_BOOK_DATA, 'where books.id = ? and data.format = ?'), [$book_id, strtoupper($type)]); + return is_null($data) ? null : new self($db, $data); + } +} diff --git a/lib/Calibre/Types/CalibreBookId.php b/lib/Calibre/Types/CalibreBookId.php new file mode 100644 index 0000000..0c71f45 --- /dev/null +++ b/lib/Calibre/Types/CalibreBookId.php @@ -0,0 +1,52 @@ + list of book identifier entries. + * @throws PDOException on error. + */ + public static function getByBook(ICalibreDB $db, $book_id): Traversable { + return new MapIterator( + $db->query(self::SQL_IDENTIFIERS, [$book_id]), + fn (array $row) => new self($db, $row) + ); + } +} diff --git a/lib/Calibre/Types/CalibreLanguage.php b/lib/Calibre/Types/CalibreLanguage.php new file mode 100644 index 0000000..221b237 --- /dev/null +++ b/lib/Calibre/Types/CalibreLanguage.php @@ -0,0 +1,89 @@ + list of language entries. + * @throws PDOException on error. + */ + public static function getAll(ICalibreDB $db): Traversable { + return new MapIterator( + $db->query(sprintf(self::SQL_LANGUAGES, '')), + fn (array $row) => new self($db, $row) + ); + } + + /** + * Get languages for a book. + * + * @param ICalibreDB $db Calibre database. + * @param mixed $book_id book ID. + * + * @return Traversable list of language entries. + * @throws PDOException on error. + */ + public static function getByBook(ICalibreDB $db, $book_id): Traversable { + return new MapIterator( + $db->query(sprintf(self::SQL_LANGUAGES, 'where bll.book = ?'), [$book_id]), + fn (array $row) => new self($db, $row) + ); + } + + /** + * Get language by language ID. + * + * @param ICalibreDB $db Calibre database. + * @param mixed $id language ID. + * + * @return self|null language entry, or `null` if not found. + * @throws PDOException on error. + */ + public static function getById(ICalibreDB $db, $id): ?self { + $data = $db->querySingle(sprintf(self::SQL_LANGUAGES, 'where languages.id = ?'), [$id]); + return is_null($data) ? null : new self($db, $data); + } +} diff --git a/lib/Calibre/Types/CalibrePublisher.php b/lib/Calibre/Types/CalibrePublisher.php new file mode 100644 index 0000000..a3ff768 --- /dev/null +++ b/lib/Calibre/Types/CalibrePublisher.php @@ -0,0 +1,83 @@ + list of publisher entries. + * @throws PDOException on error. + */ + public static function getAll(ICalibreDB $db): Traversable { + return new MapIterator( + $db->query(sprintf(self::SQL_PUBLISHERS, '')), + fn (array $row) => new self($db, $row) + ); + } + + /** + * Get publishers for a book. + * + * @param ICalibreDB $db Calibre database. + * @param mixed $book_id book ID. + * + * @return Traversable list of publisher entries. + * @throws PDOException on error. + */ + public static function getByBook(ICalibreDB $db, $book_id): Traversable { + return new MapIterator( + $db->query(sprintf(self::SQL_PUBLISHERS, 'where bpl.book = ?'), [$book_id]), + fn (array $row) => new self($db, $row) + ); + } + + /** + * Get publisher by publisher ID. + * + * @param ICalibreDB $db Calibre database. + * @param mixed $id publisher ID. + * + * @return self|null publisher entry, or `null` if not found. + * @throws PDOException on error. + */ + public static function getById(ICalibreDB $db, $id): ?self { + $data = $db->querySingle(sprintf(self::SQL_PUBLISHERS, 'where publishers.id = ?'), [$id]); + return is_null($data) ? null : new self($db, $data); + } +} diff --git a/lib/Calibre/Types/CalibreSeries.php b/lib/Calibre/Types/CalibreSeries.php new file mode 100644 index 0000000..199c821 --- /dev/null +++ b/lib/Calibre/Types/CalibreSeries.php @@ -0,0 +1,83 @@ + list of series entries. + * @throws PDOException on error. + */ + public static function getAll(ICalibreDB $db): Traversable { + return new MapIterator( + $db->query(sprintf(self::SQL_SERIES, '')), + fn (array $row) => new self($db, $row) + ); + } + + /** + * Get series for a book. + * + * @param ICalibreDB $db Calibre database. + * @param mixed $book_id book ID. + * + * @return Traversable list of series entries. + * @throws PDOException on error. + */ + public static function getByBook(ICalibreDB $db, $book_id): Traversable { + return new MapIterator( + $db->query(sprintf(self::SQL_SERIES, 'where bsl.book = ?'), [$book_id]), + fn (array $row) => new self($db, $row) + ); + } + + /** + * Get series by series ID. + * + * @param ICalibreDB $db Calibre database. + * @param mixed $id series ID. + * + * @return self|null series entry, or `null` if not found. + * @throws PDOException on error. + */ + public static function getById(ICalibreDB $db, $id): ?self { + $data = $db->querySingle(sprintf(self::SQL_SERIES, 'where series.id = ?'), [$id]); + return is_null($data) ? null : new self($db, $data); + } +} diff --git a/lib/Calibre/Types/CalibreTag.php b/lib/Calibre/Types/CalibreTag.php new file mode 100644 index 0000000..e3ee821 --- /dev/null +++ b/lib/Calibre/Types/CalibreTag.php @@ -0,0 +1,83 @@ + list of tag entries. + * @throws PDOException on error. + */ + public static function getAll(ICalibreDB $db): Traversable { + return new MapIterator( + $db->query(sprintf(self::SQL_TAGS, '')), + fn (array $row) => new self($db, $row) + ); + } + + /** + * Get tags for a book. + * + * @param ICalibreDB $db Calibre database. + * @param mixed $book_id book ID. + * + * @return Traversable list of tag entries. + * @throws PDOException on error. + */ + public static function getByBook(ICalibreDB $db, $book_id): Traversable { + return new MapIterator( + $db->query(sprintf(self::SQL_TAGS, 'where btl.book = ?'), [$book_id]), + fn (array $row) => new self($db, $row) + ); + } + + /** + * Get tag by tag ID. + * + * @param ICalibreDB $db Calibre database. + * @param mixed $id tag ID. + * + * @return self|null tag entry, or `null` if not found. + * @throws PDOException on error. + */ + public static function getById(ICalibreDB $db, $id): ?self { + $data = $db->querySingle(sprintf(self::SQL_TAGS, 'where tags.id = ?'), [$id]); + return is_null($data) ? null : new self($db, $data); + } +} diff --git a/lib/Controller/OpdsController.php b/lib/Controller/OpdsController.php new file mode 100644 index 0000000..bbe9c9d --- /dev/null +++ b/lib/Controller/OpdsController.php @@ -0,0 +1,368 @@ +getAppId(), $request); + $this->calibre = $calibre; + $this->feed = $feed; + $this->settings = $settings; + $this->l = $l; + $this->logger = $logger; + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function index(): Response { + try { + $libPath = $this->settings->getLibraryFolder(); + if (is_null($libPath)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + $lib = $this->calibre->getDatabase($libPath); + $builder = $this->feed->createBuilder('index', $this->request->getParams(), $this->l->t('Nextcloud OPDS Library')); + $builder->addSubsectionItem('authors', 'author_prefixes', $this->l->t('Authors'), $this->l->t('All authors')); + $builder->addSubsectionItem('publishers', 'publishers', $this->l->t('Publishers'), $this->l->t('All publishers')); + $builder->addSubsectionItem('languages', 'languages', $this->l->t('Languages'), $this->l->t('All languages')); + $builder->addSubsectionItem('series', 'series', $this->l->t('Series'), $this->l->t('All series')); + $builder->addSubsectionItem('tags', 'tags', $this->l->t('Tags'), $this->l->t('All tags')); + $builder->addSubsectionItem('books', 'books', $this->l->t('Books'), $this->l->t('All books')); + return $builder->getResponse(); + } catch (Exception $e) { + $this->logger->log(LogLevel::ERROR, 'Exception in '.__FUNCTION__, [ 'exception' => $e ]); + return (new Response())->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); + } + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function authors(string $prefix = ''): Response { + try { + $libPath = $this->settings->getLibraryFolder(); + if (is_null($libPath)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + $lib = $this->calibre->getDatabase($libPath); + if ($prefix === '') { + $title = $this->l->t('Authors'); + } else { + $title = $this->l->t('Authors by prefix %1$s', [$prefix]); + } + $builder = $this->feed->createBuilder('authors', $this->request->getParams(), $title); + foreach (CalibreAuthor::getByPrefix($lib, $prefix) as $item) { + $builder->addNavigationEntry($item); + } + return $builder->getResponse(); + } catch (Exception $e) { + $this->logger->log(LogLevel::ERROR, 'Exception in '.__FUNCTION__, [ 'exception' => $e ]); + return (new Response())->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); + } + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function authorPrefixes(int $length = self::DEFAULT_PREFIX_LENGTH): Response { + try { + $libPath = $this->settings->getLibraryFolder(); + if (is_null($libPath)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + $lib = $this->calibre->getDatabase($libPath); + $length = $length > 0 ? $length : 1; + $builder = $this->feed->createBuilder('author_prefixes', $this->request->getParams(), $this->l->t('Authors by prefix')); + foreach (CalibreAuthorPrefix::getAll($lib, $length) as $item) { + $builder->addNavigationEntry($item); + } + return $builder->getResponse(); + } catch (Exception $e) { + $this->logger->log(LogLevel::ERROR, 'Exception in '.__FUNCTION__, [ 'exception' => $e ]); + return (new Response())->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); + } + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function publishers(): Response { + try { + $libPath = $this->settings->getLibraryFolder(); + if (is_null($libPath)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + $lib = $this->calibre->getDatabase($libPath); + $builder = $this->feed->createBuilder('publishers', $this->request->getParams(), $this->l->t('Publishers')); + foreach (CalibrePublisher::getAll($lib) as $item) { + $builder->addNavigationEntry($item); + } + return $builder->getResponse(); + } catch (Exception $e) { + $this->logger->log(LogLevel::ERROR, 'Exception in '.__FUNCTION__, [ 'exception' => $e ]); + return (new Response())->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); + } + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function languages(): Response { + try { + $libPath = $this->settings->getLibraryFolder(); + if (is_null($libPath)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + $lib = $this->calibre->getDatabase($libPath); + $builder = $this->feed->createBuilder('languages', $this->request->getParams(), $this->l->t('Languages')); + foreach (CalibreLanguage::getAll($lib) as $item) { + $builder->addNavigationEntry($item); + } + return $builder->getResponse(); + } catch (Exception $e) { + $this->logger->log(LogLevel::ERROR, 'Exception in '.__FUNCTION__, [ 'exception' => $e ]); + return (new Response())->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); + } + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function series(): Response { + try { + $libPath = $this->settings->getLibraryFolder(); + if (is_null($libPath)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + $lib = $this->calibre->getDatabase($libPath); + $builder = $this->feed->createBuilder('series', $this->request->getParams(), $this->l->t('Series')); + foreach (CalibreSeries::getAll($lib) as $item) { + $builder->addNavigationEntry($item); + } + return $builder->getResponse(); + } catch (Exception $e) { + $this->logger->log(LogLevel::ERROR, 'Exception in '.__FUNCTION__, [ 'exception' => $e ]); + return (new Response())->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); + } + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function tags(): Response { + try { + $libPath = $this->settings->getLibraryFolder(); + if (is_null($libPath)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + $lib = $this->calibre->getDatabase($libPath); + $builder = $this->feed->createBuilder('tags', $this->request->getParams(), $this->l->t('Tags')); + foreach (CalibreTag::getAll($lib) as $item) { + $builder->addNavigationEntry($item); + } + return $builder->getResponse(); + } catch (Exception $e) { + $this->logger->log(LogLevel::ERROR, 'Exception in '.__FUNCTION__, [ 'exception' => $e ]); + return (new Response())->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); + } + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function books(string $criterion = '', string $id = ''): Response { + try { + $libPath = $this->settings->getLibraryFolder(); + if (is_null($libPath)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + $lib = $this->calibre->getDatabase($libPath); + $title = $this->l->t('All books'); + $upRoute = null; + $upParams = []; + $critCase = CalibreBookCriteria::tryFrom($criterion); + switch ($critCase) { + case 'search': + $title = $this->l->t('All books matching: /%1$s/', [$id]); + break; + case 'author': + $author = CalibreAuthor::getById($lib, $id); + if (is_null($author)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + $title = $this->l->t('All books by author: %1$s', [$author->name]); + $upRoute = 'authors'; + /** @var string $author->sort */ + $upParams = [ 'prefix' => substr($author->sort, 0, intval(self::DEFAULT_PREFIX_LENGTH)) ]; + break; + case 'publisher': + $publisher = CalibrePublisher::getById($lib, $id); + if (is_null($publisher)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + $title = $this->l->t('All books by publisher: %1$s', [$publisher->name]); + $upRoute = 'publishers'; + break; + case 'language': + $language = CalibreLanguage::getById($lib, $id); + if (is_null($language)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + /** @var string $language->code */ + $language->setName($this->settings->getLanguageName($language->code)); + $title = $this->l->t('All books in language: %1$s', [$language->name]); + break; + case 'series': + $series = CalibreSeries::getById($lib, $id); + if (is_null($series)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + $title = $this->l->t('All books in series: %1$s', [$series->name]); + break; + case 'tag': + $tag = CalibreTag::getById($lib, $id); + if (is_null($tag)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + $title = $this->l->t('All books with tag: %1$s', [$tag->name]); + break; + } + $builder = $this->feed->createBuilder('books', $this->request->getParams(), $title, $upRoute, $upParams); + foreach (CalibreBook::getByCriterion($lib, $critCase, $id) as $item) { + $builder->addBookEntry($item); + } + return $builder->getResponse(); + } catch (Exception $e) { + $this->logger->log(LogLevel::ERROR, 'Exception in '.__FUNCTION__, [ 'exception' => $e ]); + return (new Response())->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); + } + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function searchXml(): Response { + try { + $libPath = $this->settings->getLibraryFolder(); + if (is_null($libPath)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + $lib = $this->calibre->getDatabase($libPath); + $resp = new OpenSearchResponse( + /// TRANSLATORS: No more than 16 characters + $this->l->t('Search'), + $this->l->t('Search books'), + $this->l->t('Search books with matching titles, authors, series, or tags.'), + $this->settings->getAppImageLink('icon.ico'), + $this->settings->getAppRouteLink('books', [ + 'criterion' => CalibreBookCriteria::SEARCH->value, + 'id' => OpenSearchResponse::PLACEHOLDER_SEARCH_TERMS + ]) + ); + return $resp; + } catch (Exception $e) { + $this->logger->log(LogLevel::ERROR, 'Exception in '.__FUNCTION__, [ 'exception' => $e ]); + return (new Response())->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); + } + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function bookData(string $id, string $type): Response { + try { + $libPath = $this->settings->getLibraryFolder(); + if (is_null($libPath)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + $lib = $this->calibre->getDatabase($libPath); + $format = CalibreBookFormat::getByBookAndType($lib, $id, $type); + if (is_null($format)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + $file = $format->getDataFile($libPath); + if (is_null($file)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + return (new StreamResponse($file->fopen('r')))->addHeader('Content-Type', MimeTypes::getMimeType($type)); + + } catch (Exception $e) { + $this->logger->log(LogLevel::ERROR, 'Exception in '.__FUNCTION__, [ 'exception' => $e ]); + return (new Response())->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); + } + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function bookCover(string $id): Response { + try { + $libPath = $this->settings->getLibraryFolder(); + if (is_null($libPath)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + $lib = $this->calibre->getDatabase($libPath); + $book = CalibreBook::getById($lib, $id); + if (is_null($book)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + $file = $book->getCoverFile($libPath); + if (is_null($file)) { + return (new Response())->setStatus(Http::STATUS_NOT_FOUND); + } + return (new StreamResponse($file->fopen('r')))->addHeader('Content-Type', MimeTypes::getMimeType('jpg')); + + } catch (Exception $e) { + $this->logger->log(LogLevel::ERROR, 'Exception in '.__FUNCTION__, [ 'exception' => $e ]); + return (new Response())->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); + } + } +} diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php new file mode 100644 index 0000000..dfffcaf --- /dev/null +++ b/lib/Controller/SettingsController.php @@ -0,0 +1,33 @@ +getAppId(), $request); + } + + /** + * @NoAdminRequired + */ + public function settings(string $libraryRoot): array { + try { + $this->settings->setLibrary($libraryRoot); + } catch (PreConditionNotMetException|UnexpectedValueException $e) { + $this->logger->log(LogLevel::ERROR, 'Exception in '.__FUNCTION__, [ 'exception' => $e ]); + } + return [ + 'libraryRoot' => $this->settings->getLibrary() + ]; + } +} diff --git a/lib/FeedBuilder/IOpdsFeedBuilder.php b/lib/FeedBuilder/IOpdsFeedBuilder.php new file mode 100644 index 0000000..bd1201b --- /dev/null +++ b/lib/FeedBuilder/IOpdsFeedBuilder.php @@ -0,0 +1,50 @@ + $value) { + $id .= ':'.$key.'='.$value; + } + $app = new OpdsApp($this->settings->getAppId(), $this->settings->getAppName(), $this->settings->getAppVersion(), $this->settings->getAppWebsite()); + $this->response = new OpdsResponse($app, $id, $title, $this->settings->getAppImageLink('icon.ico')); + $this->response->addLink($this->getRouteLink('start', null, 'index')); + $this->response->addLink($this->getRouteLink('search', OpenSearchResponse::MIME_TYPE_OPENSEARCH, 'search_xml')); + $this->response->addLink($this->getRouteLink('self', null, $selfRoute, $selfParams)); + if (!is_null($upRoute)) { + $this->response->addLink($this->getRouteLink('up', null, $upRoute, $upParams)); + } + } + + private function getRouteLink(string $rel, ?string $mimeType, string $route, array $parameters = []): OpdsLink { + return new OpdsLink($rel, $this->settings->getAppRouteLink($route, $parameters), $mimeType ?? OpdsResponse::MIME_TYPE_ATOM); + } + + public function addSubsectionItem(string $id, string $route, string $title, ?string $summary): self { + $this->response->addEntry((new OpdsEntry($id, $title, $summary))->addLink($this->getRouteLink('subsection', null, $route))); + return $this; + } + + public function addNavigationEntry(CalibreItem $item): self { + /** + * @var string|int $item->id + * @var string $item->name + * @var int $item->count + */ + $rel = 'subsection'; + /** @var ?CalibreBookCriteria */ + $criterion = $item::CRITERION; + if (is_null($criterion)) { + if (!($item instanceof CalibreAuthorPrefix)) { + throw new Exception('invalid navigation item call with class '.get_class($item)); + } + $routeName = 'authors'; + $routeArgs = [ 'prefix' => $item->prefix ]; + $summary = $this->l->t('Authors: %1$s', [$item->count]); + } else { + if ($criterion === CalibreBookCriteria::LANGUAGE) { + /** @var string $item->code */ + $item->setName($this->settings->getLanguageName($item->code)); + } + $routeName = 'books'; + $routeArgs = [ 'criterion' => $criterion->value, 'id' => $item->id ]; + $summary = $this->l->t('Books: %1$s', [$item->count]); + } + /** @var string */ + $uriPrefix = $item::URI; + $this->response->addEntry((new OpdsEntry($uriPrefix.':'.$item->id, $item->name, $summary))->addLink( + $this->getRouteLink($rel, null, $routeName, $routeArgs) + )); + return $this; + } + + public function addBookEntry(CalibreItem $item): self { + /** + * @var int $item->id + * @var string $item->title + * @var ?string $item->comment + * @var ?DateTimeInterface $item->last_modified + * @var ?DateTimeInterface $item->pubdate + * @var ?DateTimeInterface $item->timestamp + * @var ?string $item->uuid + */ + $entry = new OpdsEntry('book:'.$item->id, $item->title, $item->comment); + $entry->setUpdated($item->last_modified); + if (!is_null($item->pubdate)) { + $entry->addAttribute(new OpdsAttribute('dc', 'issued', $item->pubdate)); + } + if (!is_null($item->timestamp)) { + $entry->addAttribute(new OpdsAttribute(null, 'published', $item->timestamp)); + } + if (!is_null($item->uuid) && $item->uuid !== '') { + $entry->addAttribute(new OpdsAttribute('dc', 'identifier', 'urn:uuid:'.$item->uuid)); + } + /** @var CalibreBookId $ident */ + foreach ($item->identifiers as $ident) { + /** + * @var string $ident->type + * @var string $ident->value + */ + if (in_array($ident->type, OpdsResponse::LITERAL_IDENTIFIER_TYPES)) { + $value = $ident->value; + } else { + $value = 'urn:'.$ident->type.':'.$ident->value; + } + $entry->addAttribute(new OpdsAttribute('dc', 'identifier', $value)); + } + /** @var CalibreAuthor $author */ + foreach ($item->authors as $author) { + /** + * @var string $author->name + * @var ?string $author->uri + */ + $entry->addAuthor(new OpdsAuthor($author->name, $author->uri)); + } + /** @var CalibrePublisher $publisher */ + foreach ($item->publishers as $publisher) { + /** @var string $publisher->name */ + $entry->addAttribute(new OpdsAttribute('dc', 'publisher', $publisher->name)); + } + /** @var CalibreLanguage $lang */ + foreach ($item->languages as $lang) { + /** @var string $lang->code */ + $entry->addAttribute(new OpdsAttribute('dc', 'language', $lang->code)); + } + /** @var CalibreSeries $series */ + foreach ($item->series as $series) { + /** @var string $series->id */ + $seriesUrl = $this->settings->getAppRouteLink('books', [ 'criterion' => 'series', 'id' => $series->id ]); + $entry->addAttribute(new OpdsAttribute('dc', 'isPartOf', $seriesUrl)); + } + // TODO: series, series_index + /** @var CalibreTag $tag */ + foreach ($item->tags as $tag) { + /** @var string $tag->name */ + $entry->addCategory(new OpdsCategory($tag->name)); + } + if ($item->has_cover) { + $entry->addLink($this->getRouteLink( + 'http://opds-spec.org/image', + MimeTypes::getMimeType('jpg'), + 'book_cover', [ 'id' => $item->id ] + )); + } + /** @var CalibreBookFormat $fmt */ + foreach ($item->formats as $fmt) { + /** @var string $fmt->format */ + $format = $fmt->format; + $entry->addLink($this->getRouteLink( + 'http://opds-spec.org/acquisition', + MimeTypes::getMimeType($format), + 'book_data', [ 'id' => $item->id, 'type' => $format ] + )); + } + $this->response->addEntry($entry); + return $this; + } + + public function getResponse(): OpdsResponse { + return $this->response; + } +} diff --git a/lib/Opds/OpdsApp.php b/lib/Opds/OpdsApp.php new file mode 100644 index 0000000..47ffade --- /dev/null +++ b/lib/Opds/OpdsApp.php @@ -0,0 +1,57 @@ +appId; + } + + /** + * Get application name. + * + * @return string application name. + */ + public function getAppName(): string { + return $this->appName; + } + + /** + * Get application version. + * + * @return string application version. + */ + public function getAppVersion(): string { + return $this->appVersion; + } + + /** + * Get application home page URL. + * + * @return string application home page URL. + */ + public function getAppWebsite(): string { + return $this->appWebsite; + } +} diff --git a/lib/Opds/OpdsAttribute.php b/lib/Opds/OpdsAttribute.php new file mode 100644 index 0000000..66f0d7d --- /dev/null +++ b/lib/Opds/OpdsAttribute.php @@ -0,0 +1,61 @@ +ns; + } + + /** + * Get tag name. + * + * @return string tag name. + */ + public function getTag(): string { + return $this->tag; + } + + /** + * Get tag contents as a text. + * + * @return string|null tag contents as a text, or `null` if no contents. + */ + public function getValueText(): ?string { + if (is_null($this->value)) { + return null; + } + if ($this->value instanceof DateTimeInterface) { + return $this->value->format('c'); + } + return strval($this->value); + } +} diff --git a/lib/Opds/OpdsAuthor.php b/lib/Opds/OpdsAuthor.php new file mode 100644 index 0000000..c078a1d --- /dev/null +++ b/lib/Opds/OpdsAuthor.php @@ -0,0 +1,47 @@ +name; + } + + /** + * Get author URI. + * + * @return string|null author URI, or `null` if not known. + */ + public function getURI(): ?string { + return $this->uri; + } + + /** + * Get author e-mail. + * + * @return string|null author e-mail, or `null` if not known. + */ + public function getEMail(): ?string { + return $this->email; + } +} diff --git a/lib/Opds/OpdsCategory.php b/lib/Opds/OpdsCategory.php new file mode 100644 index 0000000..66d0dc1 --- /dev/null +++ b/lib/Opds/OpdsCategory.php @@ -0,0 +1,47 @@ +term; + } + + /** + * Get category schema URI. + * + * @return string|null category schema URI, or `null` if not defined. + */ + public function getSchema(): ?string { + return $this->schema; + } + + /** + * Get category label. + * + * @return string|null category label, or `null` if not defined. + */ + public function getLabel(): ?string { + return $this->label; + } +} diff --git a/lib/Opds/OpdsEntry.php b/lib/Opds/OpdsEntry.php new file mode 100644 index 0000000..4e86ab8 --- /dev/null +++ b/lib/Opds/OpdsEntry.php @@ -0,0 +1,198 @@ + + */ + private array $authors; + /** + * List of entry categories. + * + * @var array + */ + private array $categories; + /** + * List of entry links. + * + * @var array + */ + private array $links; + /** + * List of entry simple attributes. + * + * @var array + */ + private array $attributes; + + /** + * Construct an instance. + * + * @param string $id entry ID. + * @param string $title entry title. + * @param string|null $summary entry summary (contents), or `null` if not defined. + */ + public function __construct(string $id, string $title, ?string $summary = null) { + $this->id = $id; + $this->title = $title; + $this->summary = $summary; + $this->updated = null; + $this->authors = []; + $this->categories = []; + $this->links = []; + $this->attributes = []; + } + + /** + * Get entry ID. + * + * @return string entry ID. + */ + public function getId(): string { + return $this->id; + } + + /** + * Get entry title. + * + * @return string entry title. + */ + public function getTitle(): string { + return $this->title; + } + + /** + * Get entry summary (contents). + * + * @return string|null entry summary (contents), or `null` if not defined. + */ + public function getSummary(): ?string { + return $this->summary; + } + + /** + * Set entry "last updated" timestamp. + * + * @param DateTimeInterface|null $updated entry updated timestamp. + * @return self + */ + public function setUpdated(?DateTimeInterface $updated): self { + $this->updated = $updated; + return $this; + } + + /** + * Get entry "last updated" timestamp. + * + * @return DateTimeInterface|null entry updated timestamp. + */ + public function getUpdated(): ?DateTimeInterface { + return $this->updated; + } + + /** + * Add an author for the entry. + * + * @param OpdsAuthor $author entry author. + * @return self + */ + public function addAuthor(OpdsAuthor $author): self { + $this->authors[] = $author; + return $this; + } + + /** + * Get entry authors. + * + * @return array entry authors. + */ + public function getAuthors(): array { + return $this->authors; + } + + /** + * Add a category for the entry. + * + * @param OpdsCategory $cat entry category. + * @return self + */ + public function addCategory(OpdsCategory $cat): self { + $this->categories[] = $cat; + return $this; + } + + /** + * Get entry categories. + * + * @return array entry categories. + */ + public function getCategories(): array { + return $this->categories; + } + + /** + * Add a link for the entry. + * + * @param OpdsLink $link entry link. + * @return self + */ + public function addLink(OpdsLink $link): self { + $this->links[] = $link; + return $this; + } + + /** + * Get entry links. + * + * @return array entry links. + */ + public function getLinks(): array { + return $this->links; + } + + /** + * Add a simple attribute for the entry. + * + * @param OpdsAttribute $attr entry attribute. + * @return self + */ + public function addAttribute(OpdsAttribute $attr): self { + $this->attributes[] = $attr; + return $this; + } + + /** + * Get entry attributes. + * + * @return array entry attributes. + */ + public function getAttributes(): array { + return $this->attributes; + } +} diff --git a/lib/Opds/OpdsLink.php b/lib/Opds/OpdsLink.php new file mode 100644 index 0000000..1a0efc0 --- /dev/null +++ b/lib/Opds/OpdsLink.php @@ -0,0 +1,47 @@ +rel; + } + + /** + * Get link URL. + * + * @return string link URL. + */ + public function getURL(): string { + return $this->url; + } + + /** + * Get link MIME type. + * + * @return string link MIME type. + */ + public function getMimeType(): string { + return $this->mimeType; + } +} diff --git a/lib/Opds/OpdsResponse.php b/lib/Opds/OpdsResponse.php new file mode 100644 index 0000000..7333fdc --- /dev/null +++ b/lib/Opds/OpdsResponse.php @@ -0,0 +1,262 @@ + + */ + private array $links; + /** + * List of feed entries. + * + * @var array + */ + private array $entries; + + /** + * Construct an instance. + * + * @param OpdsApp $app common application attributes. + * @param string $id feed ID. + * @param string $title feed title. + * @param string|null $icon feed icon URL, or `null` if not defined. + */ + public function __construct(private OpdsApp $app, private string $id, private string $title, private ?string $icon = null) { + $this->updated = new DateTimeImmutable(); + $this->links = []; + $this->entries = []; + $this->addHeader('Content-Type', self::MIME_TYPE_ATOM); + } + + /** + * Get common application attributes. + * + * @return OpdsApp common application attributes. + */ + public function getOpdsApp(): OpdsApp { + return $this->app; + } + + /** + * Get feed ID. + * + * @return string feed ID. + */ + public function getId() : string { + return $this->id; + } + + /** + * Get feed title. + * + * @return string feed title. + */ + public function getTitle(): string { + return $this->title; + } + + /** + * Get feed icon URL. + * + * @return string|null feed icon URL, or `null` if not defined. + */ + public function getIconURL(): ?string { + return $this->icon; + } + + /** + * Get feed "last updated" timestamp. + * + * @return DateTimeInterface feed updated timestamp. + */ + public function getUpdated(): DateTimeInterface { + return $this->updated; + } + + /** + * Set feed "last updated" timestamp. + * + * @param DateTimeInterface $updated feed updated timestamp. + * @return self + */ + public function setUpdated(DateTimeInterface $updated): self { + $this->updated = $updated; + return $this; + } + + /** + * Get feed links. + * + * @return Traversable feed links. + */ + public function getLinks(): Traversable { + return new ArrayIterator($this->links); + } + + /** + * Add a link for the feed. + * + * @param OpdsLink $link feed link. + * @return self + */ + public function addLink(OpdsLink $link): self { + $this->links[] = $link; + return $this; + } + + /** + * Get feed entries. + * + * @return Traversable feed entries. + */ + public function getEntries(): Traversable { + return new ArrayIterator($this->entries); + } + + /** + * Add an entry for the feed. + * + * @param OpdsEntry $entry feed entry. + * @return self + */ + public function addEntry(OpdsEntry $entry): self { + $this->entries[] = $entry; + return $this; + } + + /** + * Write a link tag. + * + * @param XMLWriter $xml XML writer. + * @param OpdsLink $link link to write. + */ + private static function writeLink(XMLWriter $xml, OpdsLink $link): void { + $xml->startElement('link'); + $xml->writeAttribute('rel', $link->getRel()); + $xml->writeAttribute('href', $link->getURL()); + $xml->writeAttribute('type', $link->getMimeType()); + $xml->endElement(); + } + + /** + * Write an author tag. + * + * @param XMLWriter $xml XML writer. + * @param OpdsAuthor $author author to write. + */ + private static function writeAuthor(XMLWriter $xml, OpdsAuthor $author): void { + $xml->startElement('author'); + $xml->writeElement('name', $author->getName()); + if (!is_null($author->getURI())) { + $xml->writeElement('uri', $author->getURI()); + } + if (!is_null($author->getEMail())) { + $xml->writeElement('email', $author->getEMail()); + } + $xml->endElement(); + } + + /** + * Write a category tag. + * + * @param XMLWriter $xml XML writer. + * @param OpdsCategory $cat category to write. + */ + private static function writeCategory(XMLWriter $xml, OpdsCategory $cat): void { + $xml->startElement('category'); + $xml->writeAttribute('term', $cat->getTerm()); + $schema = $cat->getSchema(); + if (!is_null($schema)) { + $xml->writeAttribute('schema', $schema); + } + $label = $cat->getLabel(); + if (!is_null($label)) { + $xml->writeAttribute('label', $label); + } + $xml->endElement(); + } + + public function render(): string { + $xml = new XMLWriter(); + $xml->openMemory(); + $xml->setIndent(true); + $xml->startDocument('1.0', 'utf-8'); + $xml->startElementNs(null, 'feed', 'http://www.w3.org/2005/Atom'); + $xml->writeAttributeNs('xmlns', 'dc', null, 'http://purl.org/dc/terms/'); + $xml->writeAttributeNs('xmlns', 'opds', null, 'http://opds-spec.org/2010/catalog'); + $xml->writeElement('id', 'opds:'.$this->id); + foreach ($this->links as $link) { + self::writeLink($xml, $link); + } + $xml->writeElement('title', $this->title); + $xml->writeElement('updated', $this->updated->format('c')); + self::writeAuthor($xml, new OpdsAuthor($this->app->getAppName(), $this->app->getAppWebsite())); + $xml->startElement('generator'); + $xml->writeAttribute('uri', $this->app->getAppWebsite()); + $xml->writeAttribute('version', $this->app->getAppVersion()); + $xml->writeCdata($this->app->getAppName()); + $xml->endElement(); // + if (!is_null($this->icon)) { + $xml->writeElement('icon', $this->icon); + } + foreach ($this->entries as $entry) { + $xml->startElement('entry'); + $xml->writeElement('id', 'opds:'.$entry->getId()); + $xml->writeElement('title', $entry->getTitle()); + $xml->writeElement('updated', ($entry->getUpdated() ?? $this->updated)->format('c')); + foreach ($entry->getAuthors() as $author) { + self::writeAuthor($xml, $author); + } + foreach ($entry->getCategories() as $cat) { + self::writeCategory($xml, $cat); + } + foreach ($entry->getAttributes() as $attr) { + $xml->writeElementNs($attr->getNs(), $attr->getTag(), null, $attr->getValueText()); + } + foreach ($entry->getLinks() as $link) { + self::writeLink($xml, $link); + } + $summary = $entry->getSummary(); + if (!is_null($summary)) { + $xml->startElement('content'); + $xml->writeAttribute('type', 'html'); + $xml->writeCdata($summary); + $xml->endElement(); // + } + $xml->endElement(); // + } + $xml->endElement(); // + $xml->endDocument(); + return $xml->outputMemory(); + } +} diff --git a/lib/Opds/OpenSearchResponse.php b/lib/Opds/OpenSearchResponse.php new file mode 100644 index 0000000..5f92cf2 --- /dev/null +++ b/lib/Opds/OpenSearchResponse.php @@ -0,0 +1,57 @@ +openMemory(); + $xml->setIndent(true); + $xml->startDocument('1.0', 'utf-8'); + $xml->startElementNs(null, 'OpenSearchDescription', 'http://a9.com/-/spec/opensearch/1.1/'); + $xml->writeElement('ShortName', $this->shortName); + if (!is_null($this->longName)) { + $xml->writeElement('LongName', $this->longName); + } + $xml->writeElement('Description', $this->description); + if (!is_null($this->icon)) { + $xml->writeElement('Image', $this->icon); + } + $xml->startElement('Url'); + $xml->writeAttribute('type', OpdsResponse::MIME_TYPE_ATOM); + $xml->writeAttribute('template', $this->template); + $xml->endElement(); // + $xml->endElement(); // + $xml->endDocument(); + return $xml->outputMemory(); + } +} diff --git a/lib/Service/CalibreService.php b/lib/Service/CalibreService.php new file mode 100644 index 0000000..1b8dc75 --- /dev/null +++ b/lib/Service/CalibreService.php @@ -0,0 +1,15 @@ +settings, $this->l, $selfRoute, $selfParams, $title, $upRoute, $upParams); + } +} diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php new file mode 100644 index 0000000..32aa0a1 --- /dev/null +++ b/lib/Service/SettingsService.php @@ -0,0 +1,136 @@ + + */ + private const DEFAULTS = [ + 'library' => 'Books' + ]; + + /** + * Application info array, or `null` if not retrieved yet. + * + * @var null|array + */ + private ?array $appInfo; + + public function __construct(private LoggerInterface $logger, private IConfig $config, private IUserSession $userSession, + private IRootFolder $rootFolder, private IURLGenerator $urlGenerator, private IAppManager $appManager, private IL10N $l) { + $this->appInfo = null; + } + + /** + * Get application info array. + * + * @return array application info array. + */ + private function getAppInfo(): array { + if (!is_null($this->appInfo)) { + return $this->appInfo; + } + /** @var array */ + $this->appInfo = $this->appManager->getAppInfo(Application::APP_ID); + return $this->appInfo; + } + + public function getAppId(): string { + return Application::APP_ID; + } + + public function getAppVersion(): string { + /** @var string */ + return $this->getAppInfo()['version']; + } + + public function getAppName(): string { + /** @var string */ + return $this->getAppInfo()['name']; + } + + public function getAppWebsite(): string { + /** @var string */ + return $this->getAppInfo()['website']; + } + + public function getAppRouteLink(string $route, array $parameters = []): string { + return $this->urlGenerator->linkToRoute(Application::APP_ID.'.opds.'.$route, $parameters); + } + + public function getAppImageLink(string $path): string { + return $this->urlGenerator->imagePath(Application::APP_ID, $path); + } + + public function getLanguageName(string $code): string { + $pref_lang = $this->l->getLocaleCode(); + return locale_get_display_name($code, $pref_lang) ?: '@'.$code; + } + + public function getSettings(): array { + $user = $this->userSession->getUser(); + if (is_null($user)) { + return []; + } + $uid = $user->getUID(); + $keys = array_keys(self::DEFAULTS); + return array_combine($keys, array_map(fn ($k) => $this->config->getUserValue($uid, Application::APP_ID, $k, self::DEFAULTS[$k]), $keys)); + } + + public function getLibraryFolder(): ?Folder { + $user = $this->userSession->getUser(); + $libPath = $this->getLibrary(); + if (is_null($libPath) || is_null($user)) { + return null; + } + try { + $root = $this->rootFolder->getUserFolder($user->getUID())->get($libPath); + if (!$root->isReadable() || $root->getType() !== FileInfo::TYPE_FOLDER || !($root instanceof Folder)) { + throw new NotFoundException('Library root is not a readable folder'); + } + return $root; + } catch (InvalidPathException|NotFoundException|NotPermittedException $e) { + $this->logger->error($e->getMessage(), [ 'exception' => $e ]); + return null; + } + } + + public function getLibrary(): ?string { + $user = $this->userSession->getUser(); + if (is_null($user)) { + return null; + } + return $this->config->getUserValue($user->getUID(), Application::APP_ID, 'library', self::DEFAULTS['library']); + } + + public function setLibrary(string $libraryRoot): bool { + $user = $this->userSession->getUser(); + if (is_null($user)) { + return false; + } + $this->config->setUserValue($user->getUID(), Application::APP_ID, 'library', $libraryRoot); + return true; + } +} diff --git a/lib/Settings/PersonalSettings.php b/lib/Settings/PersonalSettings.php new file mode 100644 index 0000000..5980951 --- /dev/null +++ b/lib/Settings/PersonalSettings.php @@ -0,0 +1,27 @@ +settings->getSettings(); + return new TemplateResponse($this->settings->getAppId(), 'settings.personal', $data); + } + + public function getSection(): string { + return 'sharing'; + } + + public function getPriority(): int { + return 90; + } +} diff --git a/lib/Util/MapIterator.php b/lib/Util/MapIterator.php new file mode 100644 index 0000000..2a27dc6 --- /dev/null +++ b/lib/Util/MapIterator.php @@ -0,0 +1,126 @@ + + */ +class MapIterator implements OuterIterator { + /** + * Inner iterator. + * + * @var Iterator + */ + private Iterator $inner; + /** + * Mapping function. + * + * @var callable(TValueInner):TValue + */ + private $mapper; + /** + * Optional filtering function. + * + * @var null|callable(TValue):bool + */ + private $filter; + /** + * Current value. + * + * @var TValue|null + */ + private $value; + /** + * Flag to show whether current value is already computed. + */ + private bool $hasValue; + + /** + * Construct a mapping iterator. + * + * @param Traversable $inner inner iterator. + * @param callable(TValueInner):TValue $mapper mapping function. + * @param null|callable(TValue):bool $filter optional filtering function. + */ + public function __construct(Traversable $inner, callable $mapper, ?callable $filter = null) { + while ($inner instanceof IteratorAggregate) { + $inner = $inner->getIterator(); + } + if (!($inner instanceof Iterator)) { + throw new Exception('Traversable is neither an Iterator, nor an IteratorAggregate'); + } + $this->inner = $inner; + $this->mapper = $mapper; + $this->filter = $filter; + $this->value = null; + $this->hasValue = false; + } + + private function checkValue(): bool { + if (is_null($this->filter)) { + return true; + } + if (!$this->valid()) { + return true; + } + return call_user_func($this->filter, $this->current()); + } + + /** + * @return null|Iterator + * @psalm-suppress ImplementedReturnTypeMismatch -- Psalm bug, see + */ + public function getInnerIterator(): ?Iterator { + return $this->inner; + } + + /** + * @return TValue + */ + public function current(): mixed { + if (!$this->hasValue) { + $this->value = call_user_func($this->mapper, $this->inner->current()); + $this->hasValue = true; + } + return $this->value; + } + + /** + * @return TKey + */ + public function key(): mixed { + return $this->inner->key(); + } + + public function next(): void { + do { + $this->inner->next(); + $this->hasValue = false; + } while (!$this->checkValue()); + } + + public function rewind(): void { + $this->inner->rewind(); + $this->hasValue = false; + if (!$this->checkValue()) { + $this->next(); + } + } + + public function valid(): bool { + return $this->inner->valid(); + } +} diff --git a/lib/Util/MimeTypes.php b/lib/Util/MimeTypes.php new file mode 100644 index 0000000..a855180 --- /dev/null +++ b/lib/Util/MimeTypes.php @@ -0,0 +1,62 @@ + + */ + private static array $MIME_TYPES = []; + + /** + * Load MIME types from a file. + * + * @param string $filename file to load types from. + * + * @return bool `true` on success, `false` on error. + */ + public static function loadMimeTypes(string $filename = __DIR__.'/mime.types'): bool { + $list = []; + $lines = @file($filename, FILE_IGNORE_NEW_LINES); + if ($lines === false) { + return false; + } + foreach ($lines as $line) { + $line = trim($line); + if (strlen($line) == 0 || $line[0] === '#') { + continue; + } + $parts = preg_split('/\s+/', $line); + if ($parts === false) { + continue; + } + $type = array_shift($parts); + foreach ($parts as $ext) { + $list[strtolower($ext)] = $type; + } + } + self::$MIME_TYPES = array_merge(self::$MIME_TYPES, $list); + return true; + } + + /** + * Get MIME type for an extension. + * + * @param string $type file extension. + * + * @return string MIME type. + */ + public static function getMimeType(string $type): string { + if (count(self::$MIME_TYPES) === 0) { + self::loadMimeTypes(); + } + return self::$MIME_TYPES[strtolower($type)] ?? 'application/octet-stream'; + } +} diff --git a/lib/Util/mime.types b/lib/Util/mime.types new file mode 100644 index 0000000..92b3a93 --- /dev/null +++ b/lib/Util/mime.types @@ -0,0 +1,18 @@ +# Common MIME types for e-books +application/epub+zip epub +application/msword doc +application/pdf pdf +application/postscript ps +application/vnd.amazon.mobi8-ebook azw azw3 kfx +application/vnd.ms-htmlhelp chm +application/vnd.openxmlformats-officedocument.wordprocessingml.document docx +application/vnd.ms-xpsdocument xps oxps +application/x-fictionbook+xml fb2 +application/x-ms-reader lit +image/vnd.djvu djvu +text/rtf rtf +text/plain txt +# Image MIME types +image/jpeg jpg +image/x-icon ico +image/svg+xml svg diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..7ed6e0c --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,32 @@ + + + + + tests/unit + + + + + + + + + + + lib + + + diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..78109ae --- /dev/null +++ b/psalm.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/settings.personal.php b/templates/settings.personal.php new file mode 100644 index 0000000..b25fba5 --- /dev/null +++ b/templates/settings.personal.php @@ -0,0 +1,16 @@ + +
+

t('Calibre OPDS library')); ?>

+
+

t('Publish your Calibre library in OPDS')); ?>

+

+ +

+
+
+ t('Saved')); ?> +
+
diff --git a/tests/files/metadata.sql b/tests/files/metadata.sql new file mode 100644 index 0000000..356695b --- /dev/null +++ b/tests/files/metadata.sql @@ -0,0 +1,641 @@ +CREATE TABLE authors ( id INTEGER PRIMARY KEY, + name TEXT NOT NULL COLLATE NOCASE, + sort TEXT COLLATE NOCASE, + link TEXT NOT NULL DEFAULT '', + UNIQUE(name) + ); +CREATE TABLE books ( id INTEGER PRIMARY KEY AUTOINCREMENT, + title TEXT NOT NULL DEFAULT 'Unknown' COLLATE NOCASE, + sort TEXT COLLATE NOCASE, + timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + pubdate TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + series_index REAL NOT NULL DEFAULT 1.0, + author_sort TEXT COLLATE NOCASE, + isbn TEXT DEFAULT '' COLLATE NOCASE, + lccn TEXT DEFAULT '' COLLATE NOCASE, + path TEXT NOT NULL DEFAULT '', + flags INTEGER NOT NULL DEFAULT 1, + uuid TEXT, + has_cover BOOL DEFAULT 0, + last_modified TIMESTAMP NOT NULL DEFAULT '2000-01-01 00:00:00+00:00'); +CREATE TABLE books_authors_link ( id INTEGER PRIMARY KEY, + book INTEGER NOT NULL, + author INTEGER NOT NULL, + UNIQUE(book, author) + ); +CREATE TABLE books_languages_link ( id INTEGER PRIMARY KEY, + book INTEGER NOT NULL, + lang_code INTEGER NOT NULL, + item_order INTEGER NOT NULL DEFAULT 0, + UNIQUE(book, lang_code) + ); +CREATE TABLE books_plugin_data(id INTEGER PRIMARY KEY, + book INTEGER NOT NULL, + name TEXT NOT NULL, + val TEXT NOT NULL, + UNIQUE(book,name)); +CREATE TABLE books_publishers_link ( id INTEGER PRIMARY KEY, + book INTEGER NOT NULL, + publisher INTEGER NOT NULL, + UNIQUE(book) + ); +CREATE TABLE books_ratings_link ( id INTEGER PRIMARY KEY, + book INTEGER NOT NULL, + rating INTEGER NOT NULL, + UNIQUE(book, rating) + ); +CREATE TABLE books_series_link ( id INTEGER PRIMARY KEY, + book INTEGER NOT NULL, + series INTEGER NOT NULL, + UNIQUE(book) + ); +CREATE TABLE books_tags_link ( id INTEGER PRIMARY KEY, + book INTEGER NOT NULL, + tag INTEGER NOT NULL, + UNIQUE(book, tag) + ); +CREATE TABLE comments ( id INTEGER PRIMARY KEY, + book INTEGER NOT NULL, + text TEXT NOT NULL COLLATE NOCASE, + UNIQUE(book) + ); +CREATE TABLE conversion_options ( id INTEGER PRIMARY KEY, + format TEXT NOT NULL COLLATE NOCASE, + book INTEGER, + data BLOB NOT NULL, + UNIQUE(format,book) + ); +CREATE TABLE custom_columns ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + label TEXT NOT NULL, + name TEXT NOT NULL, + datatype TEXT NOT NULL, + mark_for_delete BOOL DEFAULT 0 NOT NULL, + editable BOOL DEFAULT 1 NOT NULL, + display TEXT DEFAULT '{}' NOT NULL, + is_multiple BOOL DEFAULT 0 NOT NULL, + normalized BOOL NOT NULL, + UNIQUE(label) + ); +CREATE TABLE data ( id INTEGER PRIMARY KEY, + book INTEGER NOT NULL, + format TEXT NOT NULL COLLATE NOCASE, + uncompressed_size INTEGER NOT NULL, + name TEXT NOT NULL, + UNIQUE(book, format) +); +CREATE TABLE feeds ( id INTEGER PRIMARY KEY, + title TEXT NOT NULL, + script TEXT NOT NULL, + UNIQUE(title) + ); +CREATE TABLE identifiers ( id INTEGER PRIMARY KEY, + book INTEGER NOT NULL, + type TEXT NOT NULL DEFAULT 'isbn' COLLATE NOCASE, + val TEXT NOT NULL COLLATE NOCASE, + UNIQUE(book, type) + ); +CREATE TABLE languages ( id INTEGER PRIMARY KEY, + lang_code TEXT NOT NULL COLLATE NOCASE, + link TEXT NOT NULL DEFAULT '', + UNIQUE(lang_code) + ); +CREATE TABLE library_id ( id INTEGER PRIMARY KEY, + uuid TEXT NOT NULL, + UNIQUE(uuid) + ); +CREATE TABLE metadata_dirtied(id INTEGER PRIMARY KEY, + book INTEGER NOT NULL, + UNIQUE(book)); +CREATE TABLE annotations_dirtied(id INTEGER PRIMARY KEY, + book INTEGER NOT NULL, + UNIQUE(book)); +CREATE TABLE preferences(id INTEGER PRIMARY KEY, + key TEXT NOT NULL, + val TEXT NOT NULL, + UNIQUE(key)); +CREATE TABLE publishers ( id INTEGER PRIMARY KEY, + name TEXT NOT NULL COLLATE NOCASE, + sort TEXT COLLATE NOCASE, + link TEXT NOT NULL DEFAULT '', + UNIQUE(name) + ); +CREATE TABLE ratings ( id INTEGER PRIMARY KEY, + rating INTEGER CHECK(rating > -1 AND rating < 11), + link TEXT NOT NULL DEFAULT '', + UNIQUE (rating) + ); +CREATE TABLE series ( id INTEGER PRIMARY KEY, + name TEXT NOT NULL COLLATE NOCASE, + sort TEXT COLLATE NOCASE, + link TEXT NOT NULL DEFAULT '', + UNIQUE (name) + ); +CREATE TABLE tags ( id INTEGER PRIMARY KEY, + name TEXT NOT NULL COLLATE NOCASE, + link TEXT NOT NULL DEFAULT '', + UNIQUE (name) + ); +CREATE TABLE last_read_positions ( id INTEGER PRIMARY KEY, + book INTEGER NOT NULL, + format TEXT NOT NULL COLLATE NOCASE, + user TEXT NOT NULL, + device TEXT NOT NULL, + cfi TEXT NOT NULL, + epoch REAL NOT NULL, + pos_frac REAL NOT NULL DEFAULT 0, + UNIQUE(user, device, book, format) +); + +CREATE TABLE annotations ( id INTEGER PRIMARY KEY, + book INTEGER NOT NULL, + format TEXT NOT NULL COLLATE NOCASE, + user_type TEXT NOT NULL, + user TEXT NOT NULL, + timestamp REAL NOT NULL, + annot_id TEXT NOT NULL, + annot_type TEXT NOT NULL, + annot_data TEXT NOT NULL, + searchable_text TEXT NOT NULL DEFAULT '', + UNIQUE(book, user_type, user, format, annot_type, annot_id) +); + +CREATE VIRTUAL TABLE annotations_fts USING fts5(searchable_text, content = 'annotations', content_rowid = 'id', tokenize = 'unicode61 remove_diacritics 2'); +CREATE VIRTUAL TABLE annotations_fts_stemmed USING fts5(searchable_text, content = 'annotations', content_rowid = 'id', tokenize = 'porter unicode61 remove_diacritics 2'); + +CREATE TRIGGER annotations_fts_insert_trg AFTER INSERT ON annotations +BEGIN + INSERT INTO annotations_fts(rowid, searchable_text) VALUES (NEW.id, NEW.searchable_text); + INSERT INTO annotations_fts_stemmed(rowid, searchable_text) VALUES (NEW.id, NEW.searchable_text); +END; + +CREATE TRIGGER annotations_fts_delete_trg AFTER DELETE ON annotations +BEGIN + INSERT INTO annotations_fts(annotations_fts, rowid, searchable_text) VALUES('delete', OLD.id, OLD.searchable_text); + INSERT INTO annotations_fts_stemmed(annotations_fts_stemmed, rowid, searchable_text) VALUES('delete', OLD.id, OLD.searchable_text); +END; + +CREATE TRIGGER annotations_fts_update_trg AFTER UPDATE ON annotations +BEGIN + INSERT INTO annotations_fts(annotations_fts, rowid, searchable_text) VALUES('delete', OLD.id, OLD.searchable_text); + INSERT INTO annotations_fts(rowid, searchable_text) VALUES (NEW.id, NEW.searchable_text); + INSERT INTO annotations_fts_stemmed(annotations_fts_stemmed, rowid, searchable_text) VALUES('delete', OLD.id, OLD.searchable_text); + INSERT INTO annotations_fts_stemmed(rowid, searchable_text) VALUES (NEW.id, NEW.searchable_text); +END; + + +CREATE VIEW meta AS + SELECT id, title, + (SELECT sortconcat(bal.id, name) FROM books_authors_link AS bal JOIN authors ON(author = authors.id) WHERE book = books.id) authors, + (SELECT name FROM publishers WHERE publishers.id IN (SELECT publisher from books_publishers_link WHERE book=books.id)) publisher, + (SELECT rating FROM ratings WHERE ratings.id IN (SELECT rating from books_ratings_link WHERE book=books.id)) rating, + timestamp, + (SELECT MAX(uncompressed_size) FROM data WHERE book=books.id) size, + (SELECT concat(name) FROM tags WHERE tags.id IN (SELECT tag from books_tags_link WHERE book=books.id)) tags, + (SELECT text FROM comments WHERE book=books.id) comments, + (SELECT name FROM series WHERE series.id IN (SELECT series FROM books_series_link WHERE book=books.id)) series, + series_index, + sort, + author_sort, + (SELECT concat(format) FROM data WHERE data.book=books.id) formats, + isbn, + path, + lccn, + pubdate, + flags, + uuid + FROM books; +CREATE VIEW tag_browser_authors AS SELECT + id, + name, + (SELECT COUNT(id) FROM books_authors_link WHERE author=authors.id) count, + (SELECT AVG(ratings.rating) + FROM books_authors_link AS tl, books_ratings_link AS bl, ratings + WHERE tl.author=authors.id AND bl.book=tl.book AND + ratings.id = bl.rating AND ratings.rating <> 0) avg_rating, + sort AS sort + FROM authors; +CREATE VIEW tag_browser_filtered_authors AS SELECT + id, + name, + (SELECT COUNT(books_authors_link.id) FROM books_authors_link WHERE + author=authors.id AND books_list_filter(book)) count, + (SELECT AVG(ratings.rating) + FROM books_authors_link AS tl, books_ratings_link AS bl, ratings + WHERE tl.author=authors.id AND bl.book=tl.book AND + ratings.id = bl.rating AND ratings.rating <> 0 AND + books_list_filter(bl.book)) avg_rating, + sort AS sort + FROM authors; +CREATE VIEW tag_browser_filtered_publishers AS SELECT + id, + name, + (SELECT COUNT(books_publishers_link.id) FROM books_publishers_link WHERE + publisher=publishers.id AND books_list_filter(book)) count, + (SELECT AVG(ratings.rating) + FROM books_publishers_link AS tl, books_ratings_link AS bl, ratings + WHERE tl.publisher=publishers.id AND bl.book=tl.book AND + ratings.id = bl.rating AND ratings.rating <> 0 AND + books_list_filter(bl.book)) avg_rating, + name AS sort + FROM publishers; +CREATE VIEW tag_browser_filtered_ratings AS SELECT + id, + rating, + (SELECT COUNT(books_ratings_link.id) FROM books_ratings_link WHERE + rating=ratings.id AND books_list_filter(book)) count, + (SELECT AVG(ratings.rating) + FROM books_ratings_link AS tl, books_ratings_link AS bl, ratings + WHERE tl.rating=ratings.id AND bl.book=tl.book AND + ratings.id = bl.rating AND ratings.rating <> 0 AND + books_list_filter(bl.book)) avg_rating, + rating AS sort + FROM ratings; +CREATE VIEW tag_browser_filtered_series AS SELECT + id, + name, + (SELECT COUNT(books_series_link.id) FROM books_series_link WHERE + series=series.id AND books_list_filter(book)) count, + (SELECT AVG(ratings.rating) + FROM books_series_link AS tl, books_ratings_link AS bl, ratings + WHERE tl.series=series.id AND bl.book=tl.book AND + ratings.id = bl.rating AND ratings.rating <> 0 AND + books_list_filter(bl.book)) avg_rating, + (title_sort(name)) AS sort + FROM series; +CREATE VIEW tag_browser_filtered_tags AS SELECT + id, + name, + (SELECT COUNT(books_tags_link.id) FROM books_tags_link WHERE + tag=tags.id AND books_list_filter(book)) count, + (SELECT AVG(ratings.rating) + FROM books_tags_link AS tl, books_ratings_link AS bl, ratings + WHERE tl.tag=tags.id AND bl.book=tl.book AND + ratings.id = bl.rating AND ratings.rating <> 0 AND + books_list_filter(bl.book)) avg_rating, + name AS sort + FROM tags; +CREATE VIEW tag_browser_publishers AS SELECT + id, + name, + (SELECT COUNT(id) FROM books_publishers_link WHERE publisher=publishers.id) count, + (SELECT AVG(ratings.rating) + FROM books_publishers_link AS tl, books_ratings_link AS bl, ratings + WHERE tl.publisher=publishers.id AND bl.book=tl.book AND + ratings.id = bl.rating AND ratings.rating <> 0) avg_rating, + name AS sort + FROM publishers; +CREATE VIEW tag_browser_ratings AS SELECT + id, + rating, + (SELECT COUNT(id) FROM books_ratings_link WHERE rating=ratings.id) count, + (SELECT AVG(ratings.rating) + FROM books_ratings_link AS tl, books_ratings_link AS bl, ratings + WHERE tl.rating=ratings.id AND bl.book=tl.book AND + ratings.id = bl.rating AND ratings.rating <> 0) avg_rating, + rating AS sort + FROM ratings; +CREATE VIEW tag_browser_series AS SELECT + id, + name, + (SELECT COUNT(id) FROM books_series_link WHERE series=series.id) count, + (SELECT AVG(ratings.rating) + FROM books_series_link AS tl, books_ratings_link AS bl, ratings + WHERE tl.series=series.id AND bl.book=tl.book AND + ratings.id = bl.rating AND ratings.rating <> 0) avg_rating, + (title_sort(name)) AS sort + FROM series; +CREATE VIEW tag_browser_tags AS SELECT + id, + name, + (SELECT COUNT(id) FROM books_tags_link WHERE tag=tags.id) count, + (SELECT AVG(ratings.rating) + FROM books_tags_link AS tl, books_ratings_link AS bl, ratings + WHERE tl.tag=tags.id AND bl.book=tl.book AND + ratings.id = bl.rating AND ratings.rating <> 0) avg_rating, + name AS sort + FROM tags; +CREATE INDEX authors_idx ON books (author_sort COLLATE NOCASE); +CREATE INDEX books_authors_link_aidx ON books_authors_link (author); +CREATE INDEX books_authors_link_bidx ON books_authors_link (book); +CREATE INDEX books_idx ON books (sort COLLATE NOCASE); +CREATE INDEX books_languages_link_aidx ON books_languages_link (lang_code); +CREATE INDEX books_languages_link_bidx ON books_languages_link (book); +CREATE INDEX books_publishers_link_aidx ON books_publishers_link (publisher); +CREATE INDEX books_publishers_link_bidx ON books_publishers_link (book); +CREATE INDEX books_ratings_link_aidx ON books_ratings_link (rating); +CREATE INDEX books_ratings_link_bidx ON books_ratings_link (book); +CREATE INDEX books_series_link_aidx ON books_series_link (series); +CREATE INDEX books_series_link_bidx ON books_series_link (book); +CREATE INDEX books_tags_link_aidx ON books_tags_link (tag); +CREATE INDEX books_tags_link_bidx ON books_tags_link (book); +CREATE INDEX comments_idx ON comments (book); +CREATE INDEX conversion_options_idx_a ON conversion_options (format COLLATE NOCASE); +CREATE INDEX conversion_options_idx_b ON conversion_options (book); +CREATE INDEX custom_columns_idx ON custom_columns (label); +CREATE INDEX data_idx ON data (book); +CREATE INDEX lrp_idx ON last_read_positions (book); +CREATE INDEX annot_idx ON annotations (book); +CREATE INDEX formats_idx ON data (format); +CREATE INDEX languages_idx ON languages (lang_code COLLATE NOCASE); +CREATE INDEX publishers_idx ON publishers (name COLLATE NOCASE); +CREATE INDEX series_idx ON series (name COLLATE NOCASE); +CREATE INDEX tags_idx ON tags (name COLLATE NOCASE); +CREATE TRIGGER books_delete_trg + AFTER DELETE ON books + BEGIN + DELETE FROM books_authors_link WHERE book=OLD.id; + DELETE FROM books_publishers_link WHERE book=OLD.id; + DELETE FROM books_ratings_link WHERE book=OLD.id; + DELETE FROM books_series_link WHERE book=OLD.id; + DELETE FROM books_tags_link WHERE book=OLD.id; + DELETE FROM books_languages_link WHERE book=OLD.id; + DELETE FROM data WHERE book=OLD.id; + DELETE FROM last_read_positions WHERE book=OLD.id; + DELETE FROM annotations WHERE book=OLD.id; + DELETE FROM comments WHERE book=OLD.id; + DELETE FROM conversion_options WHERE book=OLD.id; + DELETE FROM books_plugin_data WHERE book=OLD.id; + DELETE FROM identifiers WHERE book=OLD.id; + END; +CREATE TRIGGER books_insert_trg AFTER INSERT ON books + BEGIN + UPDATE books SET sort=title_sort(NEW.title),uuid=uuid4() WHERE id=NEW.id; + END; +CREATE TRIGGER books_update_trg + AFTER UPDATE ON books + BEGIN + UPDATE books SET sort=title_sort(NEW.title) + WHERE id=NEW.id AND OLD.title <> NEW.title; + END; +CREATE TRIGGER fkc_comments_insert + BEFORE INSERT ON comments + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + END; + END; +CREATE TRIGGER fkc_comments_update + BEFORE UPDATE OF book ON comments + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + END; + END; +CREATE TRIGGER fkc_data_insert + BEFORE INSERT ON data + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + END; + END; +CREATE TRIGGER fkc_data_update + BEFORE UPDATE OF book ON data + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + END; + END; +CREATE TRIGGER fkc_lrp_insert + BEFORE INSERT ON last_read_positions + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + END; + END; +CREATE TRIGGER fkc_lrp_update + BEFORE UPDATE OF book ON last_read_positions + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + END; + END; +CREATE TRIGGER fkc_annot_insert + BEFORE INSERT ON annotations + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + END; + END; +CREATE TRIGGER fkc_annot_update + BEFORE UPDATE OF book ON annotations + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + END; + END; +CREATE TRIGGER fkc_delete_on_authors + BEFORE DELETE ON authors + BEGIN + SELECT CASE + WHEN (SELECT COUNT(id) FROM books_authors_link WHERE author=OLD.id) > 0 + THEN RAISE(ABORT, 'Foreign key violation: authors is still referenced') + END; + END; +CREATE TRIGGER fkc_delete_on_languages + BEFORE DELETE ON languages + BEGIN + SELECT CASE + WHEN (SELECT COUNT(id) FROM books_languages_link WHERE lang_code=OLD.id) > 0 + THEN RAISE(ABORT, 'Foreign key violation: language is still referenced') + END; + END; +CREATE TRIGGER fkc_delete_on_languages_link + BEFORE INSERT ON books_languages_link + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + WHEN (SELECT id from languages WHERE id=NEW.lang_code) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: lang_code not in languages') + END; + END; +CREATE TRIGGER fkc_delete_on_publishers + BEFORE DELETE ON publishers + BEGIN + SELECT CASE + WHEN (SELECT COUNT(id) FROM books_publishers_link WHERE publisher=OLD.id) > 0 + THEN RAISE(ABORT, 'Foreign key violation: publishers is still referenced') + END; + END; +CREATE TRIGGER fkc_delete_on_series + BEFORE DELETE ON series + BEGIN + SELECT CASE + WHEN (SELECT COUNT(id) FROM books_series_link WHERE series=OLD.id) > 0 + THEN RAISE(ABORT, 'Foreign key violation: series is still referenced') + END; + END; +CREATE TRIGGER fkc_delete_on_tags + BEFORE DELETE ON tags + BEGIN + SELECT CASE + WHEN (SELECT COUNT(id) FROM books_tags_link WHERE tag=OLD.id) > 0 + THEN RAISE(ABORT, 'Foreign key violation: tags is still referenced') + END; + END; +CREATE TRIGGER fkc_insert_books_authors_link + BEFORE INSERT ON books_authors_link + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + WHEN (SELECT id from authors WHERE id=NEW.author) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: author not in authors') + END; + END; +CREATE TRIGGER fkc_insert_books_publishers_link + BEFORE INSERT ON books_publishers_link + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + WHEN (SELECT id from publishers WHERE id=NEW.publisher) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: publisher not in publishers') + END; + END; +CREATE TRIGGER fkc_insert_books_ratings_link + BEFORE INSERT ON books_ratings_link + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + WHEN (SELECT id from ratings WHERE id=NEW.rating) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: rating not in ratings') + END; + END; +CREATE TRIGGER fkc_insert_books_series_link + BEFORE INSERT ON books_series_link + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + WHEN (SELECT id from series WHERE id=NEW.series) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: series not in series') + END; + END; +CREATE TRIGGER fkc_insert_books_tags_link + BEFORE INSERT ON books_tags_link + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + WHEN (SELECT id from tags WHERE id=NEW.tag) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: tag not in tags') + END; + END; +CREATE TRIGGER fkc_update_books_authors_link_a + BEFORE UPDATE OF book ON books_authors_link + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + END; + END; +CREATE TRIGGER fkc_update_books_authors_link_b + BEFORE UPDATE OF author ON books_authors_link + BEGIN + SELECT CASE + WHEN (SELECT id from authors WHERE id=NEW.author) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: author not in authors') + END; + END; +CREATE TRIGGER fkc_update_books_languages_link_a + BEFORE UPDATE OF book ON books_languages_link + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + END; + END; +CREATE TRIGGER fkc_update_books_languages_link_b + BEFORE UPDATE OF lang_code ON books_languages_link + BEGIN + SELECT CASE + WHEN (SELECT id from languages WHERE id=NEW.lang_code) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: lang_code not in languages') + END; + END; +CREATE TRIGGER fkc_update_books_publishers_link_a + BEFORE UPDATE OF book ON books_publishers_link + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + END; + END; +CREATE TRIGGER fkc_update_books_publishers_link_b + BEFORE UPDATE OF publisher ON books_publishers_link + BEGIN + SELECT CASE + WHEN (SELECT id from publishers WHERE id=NEW.publisher) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: publisher not in publishers') + END; + END; +CREATE TRIGGER fkc_update_books_ratings_link_a + BEFORE UPDATE OF book ON books_ratings_link + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + END; + END; +CREATE TRIGGER fkc_update_books_ratings_link_b + BEFORE UPDATE OF rating ON books_ratings_link + BEGIN + SELECT CASE + WHEN (SELECT id from ratings WHERE id=NEW.rating) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: rating not in ratings') + END; + END; +CREATE TRIGGER fkc_update_books_series_link_a + BEFORE UPDATE OF book ON books_series_link + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + END; + END; +CREATE TRIGGER fkc_update_books_series_link_b + BEFORE UPDATE OF series ON books_series_link + BEGIN + SELECT CASE + WHEN (SELECT id from series WHERE id=NEW.series) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: series not in series') + END; + END; +CREATE TRIGGER fkc_update_books_tags_link_a + BEFORE UPDATE OF book ON books_tags_link + BEGIN + SELECT CASE + WHEN (SELECT id from books WHERE id=NEW.book) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: book not in books') + END; + END; +CREATE TRIGGER fkc_update_books_tags_link_b + BEFORE UPDATE OF tag ON books_tags_link + BEGIN + SELECT CASE + WHEN (SELECT id from tags WHERE id=NEW.tag) IS NULL + THEN RAISE(ABORT, 'Foreign key violation: tag not in tags') + END; + END; +CREATE TRIGGER series_insert_trg + AFTER INSERT ON series + BEGIN + UPDATE series SET sort=title_sort(NEW.name) WHERE id=NEW.id; + END; +CREATE TRIGGER series_update_trg + AFTER UPDATE ON series + BEGIN + UPDATE series SET sort=title_sort(NEW.name) WHERE id=NEW.id; + END; +pragma user_version=26; diff --git a/tests/files/test-data.sql b/tests/files/test-data.sql new file mode 100644 index 0000000..14f2677 --- /dev/null +++ b/tests/files/test-data.sql @@ -0,0 +1,59 @@ +BEGIN TRANSACTION; + +INSERT INTO books (id, title, pubdate, path, has_cover, series_index, timestamp, last_modified) VALUES + (11, 'The Theory and Practice of Oligarchical Collectivism', '1984-11-07', 'oligarchical_collectivism', 0, 1.0, '', '1949-06-08'), + (12, 'Cicero for Dummies', '2012-12-12', 'dummies_cicero', 1, 100500.0, '2022-02-24 04:00', '2023-09-30 17:18'), + (13, 'Whores of Eroticon 6', '1978-03-08', 'whores_eroticon6', 1, 1.0, '', '2001-05-11 00:00'), + (14, 'Plato for Dummies', '2011-11-11', 'dummies_plato', 1, 100499.0, '', '2023-09-30 17:18'); +INSERT INTO comments (id, book, text) VALUES + (21, 12, 'Simple explanation of Cicero for imbeciles.'); +INSERT INTO identifiers (id, book, type, val) VALUES + (31, 12, 'isbn', '978-0140440997'); +INSERT INTO data (id, book, format, uncompressed_size, name) VALUES + (41, 12, 'EPUB', 123456, 'cicero_for_dummies'); + +INSERT INTO authors (id, name, sort, link) VALUES + (51, 'Aaron Zeroth', 'Zeroth, Aaron', ''), + (52, 'Beth Wildgoose', 'Wildgoose, Beth', 'http://example.com/'), + (53, 'Emmanuel Goldstein', 'Goldstein, Emmanuel', ''), + (54, 'Conrad Trachtenberg','Trachtenberg, Conrad', ''); +INSERT INTO books_authors_link (id, book, author) VALUES + (61, 11, 53), + (62, 12, 52), + (63, 12, 54), + (64, 13, 51), + (65, 14, 52); + +INSERT INTO languages (id, lang_code) VALUES + (71, 'en'), + (72, 'ru'), + (73, 'uk'), + (74, 'enm'), + (75, 'la'); +INSERT INTO books_languages_link (id, book, lang_code) VALUES + (81, 11, 71), + (82, 12, 71), + (83, 12, 75); + +INSERT INTO publishers (id, name) VALUES + (91, 'Megadodo Publications'), + (92, 'Big Brother Books'); +INSERT INTO books_publishers_link (id, book, publisher) VALUES + (101, 11, 92), + (102, 13, 91); + +INSERT INTO series (id, name) VALUES + (111, 'Philosophy For Dummies'); +INSERT INTO books_series_link (id, book, series) VALUES + (122, 12, 111), + (123, 14, 111); + +INSERT INTO tags (id, name, link) VALUES + (131, 'Political theory', 'http://example.com/politics'), + (132, 'Translations', ''); +INSERT INTO books_tags_link (id, book, tag) VALUES + (141, 11, 131), + (142, 12, 131), + (143, 12, 132); + +COMMIT; diff --git a/tests/stubs/CalibreStub.php b/tests/stubs/CalibreStub.php new file mode 100644 index 0000000..c2bae7f --- /dev/null +++ b/tests/stubs/CalibreStub.php @@ -0,0 +1,31 @@ +isSubclassOf(CalibreItem::class)) { + throw new Exception('class '.$cls.' is not a subclass of CalibreItem'); + } + $instConstructor = $instCls->getConstructor(); + $instConstructor->setAccessible(true); + /** @var CalibreItem */ + $inst = $instCls->newInstanceWithoutConstructor(); + $instConstructor->invoke($inst, $db, $data); + if (!is_null($subData)) { + $prop = $instCls->getParentClass()->getProperty('data'); + $prop->setAccessible(true); + $value = $prop->getValue($inst); + $prop->setValue($inst, array_merge($value, $subData)); + } + return $inst; + } +} diff --git a/tests/stubs/L10NStub.php b/tests/stubs/L10NStub.php new file mode 100644 index 0000000..0841eeb --- /dev/null +++ b/tests/stubs/L10NStub.php @@ -0,0 +1,28 @@ +createStub(IL10N::class); + $locale = locale_get_default(); + $l->method('getLocaleCode')->willReturn($locale); + $l->method('getLanguageCode')->willReturn(locale_get_display_language($locale)); + $l->method('t')->willReturnCallback(function (string $text, $parameters = []): string { + return sprintf($text, ...$parameters); + }); + $l->method('n')->willReturnCallback(function (string $text_singular, string $text_plural, int $count, array $parameters = []): string { + return $this->t($text_plural, $parameters); + }); + $l->method('l')->willReturnCallback(function (string $type, $data, array $options = []) { + return $data; + }); + $this->l = $l; + } +} diff --git a/tests/stubs/LoggerInterfaceStub.php b/tests/stubs/LoggerInterfaceStub.php new file mode 100644 index 0000000..8869394 --- /dev/null +++ b/tests/stubs/LoggerInterfaceStub.php @@ -0,0 +1,46 @@ +createStub(LoggerInterface::class); + $logger->method('log')->willReturnCallback($this->emulateLog(...)); + $logger->method('emergency')->willReturnCallback( + fn ($message, array $context) => $this->emulateLog(LogLevel::EMERGENCY, $message, $context) + ); + $logger->method('alert')->willReturnCallback( + fn ($message, array $context) => $this->emulateLog(LogLevel::ALERT, $message, $context) + ); + $logger->method('critical')->willReturnCallback( + fn ($message, array $context) => $this->emulateLog(LogLevel::CRITICAL, $message, $context) + ); + $logger->method('error')->willReturnCallback( + fn ($message, array $context) => $this->log(LogLevel::ERROR, $message, $context) + ); + $logger->method('warning')->willReturnCallback( + fn ($message, array $context) => $this->log(LogLevel::WARNING, $message, $context) + ); + $logger->method('notice')->willReturnCallback( + fn ($message, array $context) => $this->log(LogLevel::NOTICE, $message, $context) + ); + $logger->method('info')->willReturnCallback( + fn ($message, array $context) => $this->log(LogLevel::INFO, $message, $context) + ); + $logger->method('debug')->willReturnCallback( + fn ($message, array $context) => $this->log(LogLevel::DEBUG, $message, $context) + ); + $this->logger = $logger; + } +} diff --git a/tests/stubs/SettingsServiceStub.php b/tests/stubs/SettingsServiceStub.php new file mode 100644 index 0000000..00b9bae --- /dev/null +++ b/tests/stubs/SettingsServiceStub.php @@ -0,0 +1,34 @@ +createStub(ISettingsService::class); + $settings->method('getAppId')->willReturn(self::SETTINGS_APP_ID); + $settings->method('getAppVersion')->willReturn(self::SETTINGS_APP_VERSION); + $settings->method('getAppName')->willReturn(self::SETTINGS_APP_NAME); + $settings->method('getAppWebsite')->willReturn(self::SETTINGS_APP_WEBSITE); + $settings->method('getAppRouteLink')->willReturnCallback(function (string $route, array $parameters) { + return 'app-route:'.$route.'?'.implode('&', array_map(fn ($k, $v) => $k.'='.$v, array_keys($parameters), array_values($parameters))); + }); + $settings->method('getAppImageLink')->willReturnCallback(function (string $path) { + return 'app-img:'.$path; + }); + $settings->method('getLanguageName')->willReturnCallback(function (string $code) { + return '@'.$code; + }); + $this->settings = $settings; + } +} diff --git a/tests/stubs/StorageStub.php b/tests/stubs/StorageStub.php new file mode 100644 index 0000000..8691276 --- /dev/null +++ b/tests/stubs/StorageStub.php @@ -0,0 +1,74 @@ +createStub(IStorage::class); + $storage->method('getLocalFile')->willReturnCallback( + fn (string $filePath): string => $fake ? $path : ($path.'/'.$filePath) + ); + $this->storage = $storage; + } + + private function createStorageNode(string $cls, string $type, string $name, bool $readable): Node { + $node = $this->createStub($cls); + $node->parent = null; + $node->name = $name; + $node->content = null; + $node->method('isReadable')->willReturn($readable); + $node->method('getType')->willReturn($type); + $node->method('getInternalPath')->willReturnCallback(function () use ($node) { + return (is_null($node->parent) ? '' : $node->parent->getInternalPath()).'/'.$node->name; + }); + $node->method('getStorage')->willReturn($this->storage); + return $node; + } + + protected function createFileNode(string $filename, bool $readable = true): File { + $file = $this->createStorageNode(File::class, FileInfo::TYPE_FILE, $filename, $readable); + return $file; + } + + protected function createFolderNode(string $dirname, array $content, bool $readable = true): Folder { + $dir = $this->createStorageNode(Folder::class, FileInfo::TYPE_FOLDER, $dirname, $readable); + $dir->content = $content; + foreach ($dir->content as $sub) { + $sub->parent = $dir; + } + $dir->method('get')->willReturnCallback(function (string $path) use ($dir): Node { + if ($path === '') { + throw new NotFoundException('cannot find file with empty name'); + } + $parts = explode('/', $path, 2); + foreach ($dir->content as $sub) { + if ($sub->name === $parts[0]) { + if (isset($parts[1])) { + if ($sub->getType() !== FileInfo::TYPE_FOLDER) { + throw new NotFoundException('found file, expecting directory'); + } + try { + return $sub->get($parts[1]); + } catch (NotFoundException $e) { + throw new NotFoundException('not found: '.$path, 0, $e); + } + } + return $sub; + } + } + throw new NotFoundException('not found: '.$path); + }); + return $dir; + } +} diff --git a/tests/stubs/URLGeneratorStub.php b/tests/stubs/URLGeneratorStub.php new file mode 100644 index 0000000..a04fbe7 --- /dev/null +++ b/tests/stubs/URLGeneratorStub.php @@ -0,0 +1,22 @@ +createStub(IURLGenerator::class); + $generator->method('linkToRoute')->willReturnCallback(function (string $routeName, array $arguments = []): string { + return 'route:'.$routeName.':'.implode(':', array_map(fn ($k, $v) => $k.'='.$v, array_keys($arguments), array_values($arguments))); + }); + $generator->method('imagePath')->willReturnCallback(function (string $appName, string $file): string { + return 'image-path:'.$appName.':'.$file; + }); + $this->urlGenerator = $generator; + } +} diff --git a/tests/unit/CalibreTest.php b/tests/unit/CalibreTest.php new file mode 100644 index 0000000..ab52d25 --- /dev/null +++ b/tests/unit/CalibreTest.php @@ -0,0 +1,353 @@ +initStorage(':memory:', true); // Trick to force an in-memory database + $this->root = $this->createFolderNode('.', [ + $this->createFileNode('metadata.db'), + $this->createFolderNode('dummies_cicero', [ + $this->createFileNode('cover.jpg'), + $this->createFileNode('cicero_for_dummies.epub') + ]) + ]); + + /** @var CalibreDB */ + $this->db = CalibreDB::fromFolder($this->root, false); + $pdo = $this->db->getDatabase(); + + $ddl = file_get_contents(__DIR__.'/../files/metadata.sql'); + $pdo->exec($ddl); + $ddl = file_get_contents(__DIR__.'/../files/test-data.sql'); + $pdo->exec($ddl); + } + + private function checkDataItem(?array $expected, ?CalibreItem $actual, string $message): void { + if (is_null($expected)) { + $this->assertNull($actual, $message.' -- null check'); + return; + } + $this->assertNotNull($actual, $message.' -- null check'); + foreach ($expected as $key => $expectedValue) { + $msg = $message.' -- key '.$key; + $actualValue = $actual->$key; + if (is_array($expectedValue)) { + $this->checkData($expectedValue, $actualValue, $msg); + } else { + if (is_string($expectedValue) && str_starts_with($expectedValue, '!!time!!')) { + $value = substr($expectedValue, 8); // strlen('!!time!!') === 8 + $expectedValue = new DateTimeImmutable($value); + } + $this->assertEquals($expectedValue, $actualValue, $msg); + } + } + } + + private function checkData(array $expected, Traversable $actual, string $message): void { + reset($expected); + foreach ($actual as $actualItem) { + $this->assertInstanceOf(CalibreItem::class, $actualItem, $message.' -- wrong type'); + $key = key($expected); + $expectedItem = current($expected); + $this->assertFalse($expectedItem === false, $message.' -- result too long'); + $this->checkDataItem($expectedItem, $actualItem, $message.' -- key '.$key); + next($expected); + } + $this->assertTrue(current($expected) === false, $message.' -- result too short'); + } + + public function testAuthorsAll(): void { + $authors = CalibreAuthor::getByPrefix($this->db); + $this->checkData([ + [ 'id' => 53, 'name' => 'Emmanuel Goldstein', 'uri' => '', 'count' => 1 ], + [ 'id' => 54, 'name' => 'Conrad Trachtenberg', 'uri' => '', 'count' => 1 ], + [ 'id' => 52, 'name' => 'Beth Wildgoose', 'uri' => 'http://example.com/', 'count' => 2 ], + [ 'id' => 51, 'name' => 'Aaron Zeroth', 'uri' => '', 'count' => 1 ], + ], $authors, 'Authors (all)'); + } + + public function testAuthorsByPrefix(): void { + $authors = CalibreAuthor::getByPrefix($this->db, 'W'); + $this->checkData([ + [ 'id' => 52 ], + ], $authors, 'Authors by prefix'); + } + + public function testAuthorsByBook(): void { + $authors = CalibreAuthor::getByBook($this->db, 12); + $this->checkData([ + [ 'id' => 54 ], + [ 'id' => 52 ], + ], $authors, 'Authors by book'); + } + + public function testAuthorById(): void { + $author = CalibreAuthor::getById($this->db, 53); + $this->checkDataItem([ 'id' => 53 ], $author, 'Author by id'); + } + + public function testAuthorPrefixes(): void { + $prefixes = CalibreAuthorPrefix::getAll($this->db); + $this->checkData([ + [ 'prefix' => 'G', 'id' => 'G', 'name' => 'G', 'count' => 1 ], + [ 'prefix' => 'T', 'id' => 'T', 'name' => 'T', 'count' => 1 ], + [ 'prefix' => 'W', 'id' => 'W', 'name' => 'W', 'count' => 1 ], + [ 'prefix' => 'Z', 'id' => 'Z', 'name' => 'Z', 'count' => 1 ], + ], $prefixes, 'Author prefixes'); + } + + public function testLanguagesAll(): void { + $languages = CalibreLanguage::getAll($this->db); + $this->checkData([ + [ 'id' => 71, 'code' => 'en', 'count' => 2 ], + [ 'id' => 74, 'code' => 'enm', 'count' => 0 ], + [ 'id' => 75, 'code' => 'la', 'count' => 1 ], + [ 'id' => 72, 'code' => 'ru', 'count' => 0 ], + [ 'id' => 73, 'code' => 'uk', 'count' => 0 ], + ], $languages, 'Languages (all)'); + } + + public function testLanguagesByBook(): void { + $languages = CalibreLanguage::getByBook($this->db, 12); + $this->checkData([ + [ 'code' => 'en' ], + [ 'code' => 'la' ], + ], $languages, 'Languages by book'); + } + + public function testLanguageById(): void { + $language = CalibreLanguage::getById($this->db, 75); + $this->checkDataItem([ 'code' => 'la' ], $language, 'Language by id'); + } + + public function testPublishersAll(): void { + $publishers = CalibrePublisher::getAll($this->db); + $this->checkData([ + [ 'id' => 92, 'name' => 'Big Brother Books', 'count' => 1 ], + [ 'id' => 91, 'name' => 'Megadodo Publications', 'count' => 1 ], + ], $publishers, 'Publishers (all)'); + } + + public function testPublishersByBook(): void { + $publishers = CalibrePublisher::getByBook($this->db, 13); + $this->checkData([ + [ 'name' => 'Megadodo Publications' ] + ], $publishers, 'Publishers by book'); + } + + public function testPublisherById(): void { + $publisher = CalibrePublisher::getById($this->db, 92); + $this->checkDataItem([ 'name' => 'Big Brother Books' ], $publisher, 'Publisher by id'); + } + + public function testSeriesAll(): void { + $series = CalibreSeries::getAll($this->db); + $this->checkData([ + [ 'id' => 111, 'name' => 'Philosophy For Dummies', 'count' => 2 ], + ], $series, 'Series (all)'); + } + + public function testSeriesByBook(): void { + $series = CalibreSeries::getByBook($this->db, 12); + $this->checkData([ + [ 'name' => 'Philosophy For Dummies' ], + ], $series, 'Series by book'); + } + + public function testSeriesById(): void { + $series = CalibreSeries::getById($this->db, 111); + $this->checkDataItem([ 'name' => 'Philosophy For Dummies' ], $series, 'Series by id'); + } + + public function testTagsAll(): void { + $tags = CalibreTag::getAll($this->db); + $this->checkData([ + [ 'id' => 131, 'name' => 'Political theory', 'count' => 2 ], + [ 'id' => 132, 'name' => 'Translations', 'count' => 1 ], + ], $tags, 'Tags (all)'); + } + + public function testTagsByBook(): void { + $tags = CalibreTag::getByBook($this->db, 12); + $this->checkData([ + [ 'id' => 131 ], + [ 'id' => 132 ], + ], $tags, 'Tags by book'); + } + + public function testTagById(): void { + $tag = CalibreTag::getById($this->db, 131); + $this->checkDataItem([ 'name' => 'Political theory' ], $tag, 'Tag by id'); + } + + public function testBookById(): void { + $book = CalibreBook::getById($this->db, 12); + $this->checkDataItem([ + 'id' => 12, + 'title' => 'Cicero for Dummies', + 'pubdate' => '!!time!!2012-12-12', + 'timestamp' => '!!time!!2022-02-24 04:00', + 'last_modified' => '!!time!!2023-09-30 17:18', + 'path' => 'dummies_cicero', + 'has_cover' => true, + 'comment' => 'Simple explanation of Cicero for imbeciles.', + 'authors' => [ + [ 'name' => 'Conrad Trachtenberg' ], + [ 'name' => 'Beth Wildgoose' ], + ], + 'publishers' => [], + 'languages' => [ + [ 'code' => 'en' ], + [ 'code' => 'la' ], + ], + 'series' => [ + [ 'name' => 'Philosophy For Dummies' ], + ], + 'series_index' => 100500.0, + 'tags' => [ + [ 'name' => 'Political theory' ], + [ 'name' => 'Translations' ], + ], + 'formats' => [ + [ 'format' => 'EPUB', 'name' => 'cicero_for_dummies', 'path' => 'dummies_cicero' ], + ], + 'identifiers' => [ + [ 'type' => 'isbn', 'value' => '978-0140440997' ], + ], + ], $book, 'Book by id'); + $coverFile = $book->getCoverFile($this->root); + $this->assertInstanceOf(File::class, $coverFile, 'Book cover file -- class'); + $this->assertEquals('/./dummies_cicero/cover.jpg', $coverFile->getInternalPath(), 'Book cover file -- path'); + } + + public function testBookData(): void { + $format = CalibreBookFormat::getByBookAndType($this->db, 12, 'epub'); + $this->checkDataItem([ + 'format' => 'EPUB', 'name' => 'cicero_for_dummies', 'path' => 'dummies_cicero' + ], $format, 'Book data by book and format'); + $dataFile = $format->getDataFile($this->root); + $this->assertInstanceOf(File::class, $dataFile, 'Book data file -- class'); + $this->assertEquals('/./dummies_cicero/cicero_for_dummies.epub', $dataFile->getInternalPath(), 'Book data file -- path'); + } + + public function testBooksAll(): void { + $books = CalibreBook::getByCriterion($this->db); + $this->checkData([ + [ + 'id' => 12, 'title' => 'Cicero for Dummies', + 'pubdate' => '!!time!!2012-12-12', 'timestamp' => '!!time!!2022-02-24 04:00', 'last_modified' => '!!time!!2023-09-30 17:18', + 'path' => 'dummies_cicero', 'has_cover' => 1, + 'series_index' => 100500.0, + ], + [ + 'id' => 14, 'title' => 'Plato for Dummies', + 'pubdate' => '!!time!!2011-11-11', 'timestamp' => null, 'last_modified' => '!!time!!2023-09-30 17:18', + 'path' => 'dummies_plato', 'has_cover' => 1, + 'series_index' => 100499.0, + ], + [ + 'id' => 11, 'title' => 'The Theory and Practice of Oligarchical Collectivism', + 'pubdate' => '!!time!!1984-11-07', 'timestamp' => null, 'last_modified' => '!!time!!1949-06-08', + 'path' => 'oligarchical_collectivism', 'has_cover' => 0, + 'series_index' => 1.0, + ], + [ + 'id' => 13, 'title' => 'Whores of Eroticon 6', + 'pubdate' => '!!time!!1978-03-08', 'timestamp' => null, 'last_modified' => '!!time!!2001-05-11 00:00', + 'path' => 'whores_eroticon6', 'has_cover' => 1, + ], + ], $books, 'Books (all)'); + } + + public static function selectDataProvider(): array { + return [ + [ CalibreBookCriteria::AUTHOR, '51', [ + [ 'id' => 13, 'title' => 'Whores of Eroticon 6' ], + ], 'author' ], + [ CalibreBookCriteria::PUBLISHER, '92', [ + [ 'id' => 11, 'title' => 'The Theory and Practice of Oligarchical Collectivism' ], + ], 'publisher' ], + [ CalibreBookCriteria::LANGUAGE, '75', [ + [ 'id' => 12, 'title' => 'Cicero for Dummies' ], + ], 'language' ], + [ CalibreBookCriteria::SERIES, '111', [ + [ 'id' => 14, 'title' => 'Plato for Dummies' ], + [ 'id' => 12, 'title' => 'Cicero for Dummies' ], + ], 'series' ], + [ CalibreBookCriteria::TAG, '131', [ + [ 'id' => 12, 'title' => 'Cicero for Dummies' ], + [ 'id' => 11, 'title' => 'The Theory and Practice of Oligarchical Collectivism' ], + ], 'tags' ], + ]; + } + + #[DataProvider('selectDataProvider')] + public function testBooksSelect(CalibreBookCriteria $criterion, string $id, array $expected, string $type): void { + $books = CalibreBook::getByCriterion($this->db, $criterion, $id); + $this->checkData($expected, $books, 'Books by '.$type); + } + + public static function searchDataProvider(): array { + return [ + [ CalibreBookCriteria::SEARCH, 'whore', [ + [ 'id' => 13 ], + ], 'title' ], + [ CalibreBookCriteria::SEARCH, 'imbec', [ + [ 'id' => 12 ], + ], 'comment' ], + [ CalibreBookCriteria::SEARCH, 'zero', [ + [ 'id' => 13 ], + ], 'author' ], + [ CalibreBookCriteria::SEARCH, 'philosophy', [ + [ 'id' => 12 ], + [ 'id' => 14 ], + ], 'series' ], + [ CalibreBookCriteria::SEARCH, 'polit', [ + [ 'id' => 12 ], + [ 'id' => 11 ], + ], 'tags' ], + ]; + } + + #[DataProvider('searchDataProvider')] + public function testBooksSearch(CalibreBookCriteria $criterion, string $term, array $expected, string $type): void { + $books = CalibreBook::getByCriterion($this->db, $criterion, $term); + $this->checkData($expected, $books, 'Books search ('.$type.')'); + } + + public function testUnknownProperty(): void { + $author = CalibreAuthor::getById($this->db, 53); + // NOTE: PHPUnit 10 no longer supports expecting errors. + set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline): bool { + restore_error_handler(); + throw new ErrorException($errstr, $errno, E_USER_ERROR, $errfile, $errline); + }, E_USER_ERROR); + $this->expectException(ErrorException::class); + $this->expectExceptionMessageMatches('/Getting unknown property nonexistent_field from object of class .*/'); + $test = $author->nonexistent_field; + } +} diff --git a/tests/unit/OpdsFeedTest.php b/tests/unit/OpdsFeedTest.php new file mode 100644 index 0000000..10abf86 --- /dev/null +++ b/tests/unit/OpdsFeedTest.php @@ -0,0 +1,301 @@ + 'selfValue' ]; + private const UP_ROUTE = 'up-route'; + private const UP_PARAMS = []; + private const FEED_TITLE = 'feed-title'; + private const EXPECTED_LINKS = [ + [ 'start', 'app-route:index?', OpdsResponse::MIME_TYPE_ATOM ], + [ 'search', 'app-route:search_xml?', OpenSearchResponse::MIME_TYPE_OPENSEARCH ], + [ 'self', 'app-route:self-route?selfParam=selfValue', OpdsResponse::MIME_TYPE_ATOM ], + [ 'up', 'app-route:up-route?', OpdsResponse::MIME_TYPE_ATOM ], + ]; + private const EXPECTED_ENTRIES = [ + [ + 'sect-id1', 'sect-title1', null, null, + null, + null, + [[ 'subsection', 'app-route:sect-route1?' ]] + ], + [ + 'sect-id2', 'sect-title2', 'sect-summary2', null, + null, + null, + [[ 'subsection', 'app-route:sect-route2?' ]] + ], + [ + 'author-prefix:author-prefix-value', 'author-prefix-value', 'Authors: 123', null, + null, + null, + [[ 'subsection', 'app-route:authors?prefix=author-prefix-value' ]] + ], + [ + 'author:author-id', 'author-name', 'Books: 123', null, + null, + null, + [[ 'subsection', 'app-route:books?criterion=author&id=author-id' ]] + ], + [ + 'publisher:publisher-id', 'publisher-name', 'Books: 123', null, + null, + null, + [[ 'subsection', 'app-route:books?criterion=publisher&id=publisher-id' ]] + ], + [ + 'series:series-id', 'series-name', 'Books: 123', null, + null, + null, + [[ 'subsection', 'app-route:books?criterion=series&id=series-id' ]] + ], + [ + 'tag:tag-id', 'tag-name', 'Books: 123', null, + null, + null, + [[ 'subsection', 'app-route:books?criterion=tag&id=tag-id' ]] + ], + [ + 'lang:lang-id', '@lang-code', 'Books: 123', null, + null, + null, + [[ 'subsection', 'app-route:books?criterion=language&id=lang-id' ]] + ], + [ + 'book:book-id', 'book-title', 'book-comment', null, + [ + [ 'author-name1', 'author-uri1' ], + [ 'author-name2', 'author-uri2' ], + ], + [ + [ 'tag-name1' ], + [ 'tag-name2' ], + ], + [ + [ 'http://opds-spec.org/image', 'app-route:book_cover?id=book-id', 'image/jpeg' ], + [ 'http://opds-spec.org/acquisition', 'app-route:book_data?id=book-id&type=format-type1', 'application/octet-stream' ], + [ 'http://opds-spec.org/acquisition', 'app-route:book_data?id=book-id&type=format-type2', 'application/octet-stream' ], + ], + [ + [ 'dc', 'issued', '1980-02-01T00:00:00+00:00' ], + [ null, 'published', '2023-10-01T01:02:00+00:00' ], + [ 'dc', 'identifier', 'urn:uuid:book-uuid' ], + [ 'dc', 'identifier', 'id-uri1' ], + [ 'dc', 'identifier', 'id-urn2' ], + [ 'dc', 'identifier', 'id-epubbud3' ], + [ 'dc', 'identifier', 'urn:id-type4:id-value4' ], + [ 'dc', 'publisher', 'publisher-name1' ], + [ 'dc', 'publisher', 'publisher-name2' ], + [ 'dc', 'language', 'lang-code1' ], + [ 'dc', 'language', 'lang-code2' ], + [ 'dc', 'isPartOf', 'app-route:books?criterion=series&id=series-id1' ], + [ 'dc', 'isPartOf', 'app-route:books?criterion=series&id=series-id2' ], + ], + ], + ]; + + use L10NStub; + use SettingsServiceStub; + use CalibreStub; + + private ICalibreDB $db; + + public function setUp(): void { + $this->initL10N(); + $this->initSettingsService(); + $this->db = $this->createStub(ICalibreDB::class); + } + + public function testOpdsFeed(): void { + $builder = new OpdsFeedBuilder($this->settings, $this->l, + self::SELF_ROUTE, self::SELF_PARAMS, self::FEED_TITLE, + self::UP_ROUTE, self::UP_PARAMS + ); + $builder->addSubsectionItem('sect-id1', 'sect-route1', 'sect-title1', null); + $builder->addSubsectionItem('sect-id2', 'sect-route2', 'sect-title2', 'sect-summary2'); + $builder->addNavigationEntry($this->createCalibreItem(CalibreAuthorPrefix::class, $this->db, [ + 'prefix' => 'author-prefix-value', 'count' => 123 + ])); + $builder->addNavigationEntry($this->createCalibreItem(CalibreAuthor::class, $this->db, [ + 'id' => 'author-id', 'name' => 'author-name', 'uri' => 'author-uri', 'count' => 123 + ])); + $builder->addNavigationEntry($this->createCalibreItem(CalibrePublisher::class, $this->db, [ + 'id' => 'publisher-id', 'name' => 'publisher-name', 'count' => 123 + ])); + $builder->addNavigationEntry($this->createCalibreItem(CalibreSeries::class, $this->db, [ + 'id' => 'series-id', 'name' => 'series-name', 'count' => 123 + ])); + $builder->addNavigationEntry($this->createCalibreItem(CalibreTag::class, $this->db, [ + 'id' => 'tag-id', 'name' => 'tag-name', 'count' => 123 + ])); + $builder->addNavigationEntry($this->createCalibreItem(CalibreLanguage::class, $this->db, [ + 'id' => 'lang-id', 'code' => 'lang-code', 'count' => 123 + ])); + $builder->addBookEntry($this->createCalibreItem(CalibreBook::class, $this->db, [ + 'id' => 'book-id', 'title' => 'book-title', + 'timestamp' => '2023-10-01 01:02', 'pubdate' => '1980-02-01', 'last_modified' => null, + 'series_index' => 1.0, 'uuid' => 'book-uuid', + 'has_cover' => 1, 'path' => 'book-path', + 'comment' => 'book-comment' + ], [ + 'authors' => [ + $this->createCalibreItem(CalibreAuthor::class, $this->db, [ + 'id' => 'author-id1', 'name' => 'author-name1', 'uri' => 'author-uri1' + ]), + $this->createCalibreItem(CalibreAuthor::class, $this->db, [ + 'id' => 'author-id2', 'name' => 'author-name2', 'uri' => 'author-uri2' + ]), + ], + 'publishers' => [ + $this->createCalibreItem(CalibrePublisher::class, $this->db, [ + 'id' => 'publisher-id1', 'name' => 'publisher-name1' + ]), + $this->createCalibreItem(CalibrePublisher::class, $this->db, [ + 'id' => 'publisher-id2', 'name' => 'publisher-name2' + ]), + ], + 'languages' => [ + $this->createCalibreItem(CalibreLanguage::class, $this->db, [ + 'id' => 'lang-id1', 'code' => 'lang-code1' + ]), + $this->createCalibreItem(CalibreLanguage::class, $this->db, [ + 'id' => 'lang-id2', 'code' => 'lang-code2' + ]), + ], + 'series' => [ + $this->createCalibreItem(CalibreSeries::class, $this->db, [ + 'id' => 'series-id1', 'name' => 'series-name1' + ]), + $this->createCalibreItem(CalibreSeries::class, $this->db, [ + 'id' => 'series-id2', 'name' => 'series-name2' + ]), + ], + 'tags' => [ + $this->createCalibreItem(CalibreTag::class, $this->db, [ + 'id' => 'tag-id1', 'name' => 'tag-name1' + ]), + $this->createCalibreItem(CalibreTag::class, $this->db, [ + 'id' => 'tag-id2', 'name' => 'tag-name2' + ]), + ], + 'formats' => [ + $this->createCalibreItem(CalibreBookFormat::class, $this->db, [ + 'path' => 'book-path', 'name' => 'format-name1', 'format' => 'format-type1' + ]), + $this->createCalibreItem(CalibreBookFormat::class, $this->db, [ + 'path' => 'book-path', 'name' => 'format-name2', 'format' => 'format-type2' + ]), + ], + 'identifiers' => [ + $this->createCalibreItem(CalibreBookId::class, $this->db, [ + 'type' => 'uri', 'value' => 'id-uri1' + ]), + $this->createCalibreItem(CalibreBookId::class, $this->db, [ + 'type' => 'urn', 'value' => 'id-urn2' + ]), + $this->createCalibreItem(CalibreBookId::class, $this->db, [ + 'type' => 'epubbud', 'value' => 'id-epubbud3' + ]), + $this->createCalibreItem(CalibreBookId::class, $this->db, [ + 'type' => 'id-type4', 'value' => 'id-value4' + ]), + ], + ])); + $resp = $builder->getResponse(); + + $app = $resp->getOpdsApp(); + $this->assertEquals(self::SETTINGS_APP_ID, $app->getAppId(), 'Feed -- app ID'); + $this->assertEquals(self::SETTINGS_APP_NAME, $app->getAppName(), 'Feed -- app name'); + $this->assertEquals(self::SETTINGS_APP_VERSION, $app->getAppVersion(), 'Feed -- app version'); + $this->assertEquals(self::SETTINGS_APP_WEBSITE, $app->getAppWebsite(), 'Feed -- app website'); + $this->assertEquals('self-route:selfParam=selfValue', $resp->getId(), 'Feed -- feed ID'); + $this->assertEquals(self::FEED_TITLE, $resp->getTitle(), 'Feed -- feed title'); + $this->assertEquals('app-img:icon.ico', $resp->getIconURL(), 'Feed -- feed icon'); + + $expectedLinks = self::EXPECTED_LINKS; + foreach ($resp->getLinks() as $key => $link) { + $this->assertNotEmpty($expectedLinks, 'Feed -- too many links'); + $expected = array_shift($expectedLinks); + $this->assertEquals($expected[0], $link->getRel(), 'Feed -- link '.$key.' -- rel'); + $this->assertEquals($expected[1], $link->getURL(), 'Feed -- link '.$key.' -- URL'); + $this->assertEquals($expected[2], $link->getMimeType(), 'Feed -- link '.$key.' -- MIME type'); + } + $this->assertEmpty($expectedLinks, 'Feed -- not enough links'); + + $expectedEntries = self::EXPECTED_ENTRIES; + foreach ($resp->getEntries() as $key => $entry) { + $this->assertNotEmpty($expectedEntries, 'Feed -- too many entries'); + $expected = array_shift($expectedEntries); + $this->assertEquals($expected[0], $entry->getId(), 'Feed -- entry '.$key.' -- ID'); + $this->assertEquals($expected[1], $entry->getTitle(), 'Feed -- entry '.$key.' -- title'); + $this->assertEquals($expected[2], $entry->getSummary(), 'Feed -- entry '.$key.' -- summary'); + + $expectedUpdated = $expected[3] ?? null; + if (!is_null($expectedUpdated)) { + $expectedUpdated = new DateTimeImmutable($expectedUpdated); + } + $this->assertEquals($expectedUpdated, $entry->getUpdated(), 'Feed -- entry '.$key.' -- updated'); + + $expectedAuthors = $expected[4] ?? []; + foreach ($entry->getAuthors() as $authorKey => $author) { + $this->assertNotEmpty($expectedAuthors, 'Feed -- entry '.$key.' -- too many authors'); + $expectedAuthor = array_shift($expectedAuthors); + $this->assertEquals($expectedAuthor[0], $author->getName(), 'Feed -- entry '.$key.' -- author '.$authorKey.' -- name'); + $this->assertEquals($expectedAuthor[1] ?? null, $author->getURI(), 'Feed -- entry '.$key.' -- author '.$authorKey.' -- URI'); + $this->assertEquals($expectedAuthor[2] ?? null, $author->getEMail(), 'Feed -- entry '.$key.' -- author '.$authorKey.' -- e-mail'); + } + $this->assertEmpty($expectedAuthors, 'Feed -- entry '.$key.' -- not enough authors'); + + $expectedCategories = $expected[5] ?? []; + foreach ($entry->getCategories() as $catKey => $cat) { + $this->assertNotEmpty($expectedCategories, 'Feed -- entry '.$key.' -- too many categories'); + $expectedCat = array_shift($expectedCategories); + $this->assertEquals($expectedCat[0], $cat->getTerm(), 'Feed -- entry '.$key.' -- category '.$catKey.' -- term'); + $this->assertEquals($expectedCat[1] ?? null, $cat->getSchema(), 'Feed -- entry '.$key.' -- category '.$catKey.' -- schema'); + $this->assertEquals($expectedCat[2] ?? null, $cat->getLabel(), 'Feed -- entry '.$key.' -- category '.$catKey.' -- label'); + } + $this->assertEmpty($expectedCategories, 'Feed -- entry '.$key.' -- not enough categories'); + + $expectedLinks = $expected[6] ?? []; + foreach ($entry->getLinks() as $linkKey => $link) { + $this->assertNotEmpty($expectedLinks, 'Feed -- entry '.$key.' -- too many links'); + $expectedLink = array_shift($expectedLinks); + $this->assertEquals($expectedLink[0], $link->getRel(), 'Feed -- entry '.$key.' -- link '.$linkKey.' -- rel'); + $this->assertEquals($expectedLink[1], $link->getURL(), 'Feed -- entry '.$key.' -- link '.$linkKey.' -- URL'); + $this->assertEquals($expectedLink[2] ?? OpdsResponse::MIME_TYPE_ATOM, $link->getMimeType(), 'Feed -- entry '.$key.' -- link '.$linkKey.' -- MIME type'); + } + $this->assertEmpty($expectedLinks, 'Feed -- entry '.$key.' -- not enough links'); + + $expectedAttrs = $expected[7] ?? []; + foreach ($entry->getAttributes() as $attrKey => $attr) { + $this->assertNotEmpty($expectedAttrs, 'Feed -- entry '.$key.' -- too many attributes'); + $expectedAttr = array_shift($expectedAttrs); + $this->assertEquals($expectedAttr[0], $attr->getNs(), 'Feed -- entry '.$key.' -- attr '.$attrKey.' -- NS'); + $this->assertEquals($expectedAttr[1], $attr->getTag(), 'Feed -- entry '.$key.' -- attr '.$attrKey.' -- tag'); + $this->assertEquals($expectedAttr[2] ?? null, $attr->getValueText(), 'Feed -- entry '.$key.' -- attr '.$attrKey.' -- value'); + } + $this->assertEmpty($expectedAttrs, 'Feed -- entry '.$key.' -- not enough attributes'); + } + $this->assertEmpty($expectedEntries, 'Feed -- not enough entries'); + } +} diff --git a/tests/unit/OpdsSearchTest.php b/tests/unit/OpdsSearchTest.php new file mode 100644 index 0000000..10ec786 --- /dev/null +++ b/tests/unit/OpdsSearchTest.php @@ -0,0 +1,60 @@ + + + short-name + long-name + short-name + icon-url + + + EOT; + private const SEARCH_TEMPLATE_XML_MINIMAL = <<<'EOT' + + + short-name + short-name + + + EOT; + + public function testSearchXmlFull(): void { + $search = new OpenSearchResponse( + self::SEARCH_TEMPLATE_SHORT_NAME, + self::SEARCH_TEMPLATE_LONG_NAME, + self::SEARCH_TEMPLATE_DESCRIPTION, + self::SEARCH_TEMPLATE_ICON_URL, + self::SEARCH_TEMPLATE_TEMPLATE + ); + $xml = $search->render(); + $actual = simplexml_load_string($xml, SimpleXMLElement::class, LIBXML_NOBLANKS); + $expected = simplexml_load_string(self::SEARCH_TEMPLATE_XML, SimpleXMLElement::class, LIBXML_NOBLANKS); + $this->assertEquals(dom_import_simplexml($actual), dom_import_simplexml($expected), 'Full search template'); + } + + public function testSearchXmlMinimal(): void { + $search = new OpenSearchResponse( + self::SEARCH_TEMPLATE_SHORT_NAME, + null, + self::SEARCH_TEMPLATE_DESCRIPTION, + null, + self::SEARCH_TEMPLATE_TEMPLATE + ); + $xml = $search->render(); + $actual = simplexml_load_string($xml, SimpleXMLElement::class, LIBXML_NOBLANKS); + $expected = simplexml_load_string(self::SEARCH_TEMPLATE_XML_MINIMAL, SimpleXMLElement::class, LIBXML_NOBLANKS); + $this->assertEquals(dom_import_simplexml($actual), dom_import_simplexml($expected), 'Minimal search template'); + } +} diff --git a/tests/unit/OpdsTest.php b/tests/unit/OpdsTest.php new file mode 100644 index 0000000..42eacdd --- /dev/null +++ b/tests/unit/OpdsTest.php @@ -0,0 +1,140 @@ +summary2' ], + [ 'id3', 'title3', + 'updated' => '2009-02-13 23:31:30+00:00', + 'authors' => [ + [ 'author3-1' ], + [ 'author3-2', null, 'author3-2-email' ], + ], + 'categories' => [ + [ 'cat1-term' ], + [ 'cat2-term', 'cat2-schema' ], + [ 'cat3-term', null, 'cat3-label' ], + ], + 'attributes' => [ + [ 'ext-tag1' ], + [ 'ext-tag2', 'ext-value2' ], + [ 'ext-tag3', 'ext-value3', 'dc' ], + [ 'ext-tag4', '!2009-02-13 23:31:30+00:00' ], + ], + 'links' => [ + [ 'link1-rel', 'link1-url', 'link1-type' ], + ], + ], + ]; + private const RESPONSE_XML = <<<'EOT' + + + opds:response-id + + response-title + 2001-09-09T01:46:40+00:00 + + app-name + app-website + + app-name + response-icon + + opds:id1 + title1 + 2001-09-09T01:46:40+00:00 + + + opds:id2 + title2 + 2001-09-09T01:46:40+00:00 + <b>summary2</b> + + + opds:id3 + title3 + 2009-02-13T23:31:30+00:00 + + author3-1 + + + author3-2 + author3-2-email + + + + + + ext-value2 + ext-value3 + 2009-02-13T23:31:30+00:00 + + + + EOT; + + public function testOpdsResponse(): void { + $app = new OpdsApp(self::APP_ID, self::APP_NAME, self::APP_VERSION, self::APP_WEBSITE); + $this->assertEquals(self::APP_ID, $app->getAppId(), 'App ID'); + $opds = new OpdsResponse($app, self::RESPONSE_ID, self::RESPONSE_TITLE, self::RESPONSE_ICON_URL); + $opds->setUpdated(new DateTimeImmutable(self::RESPONSE_UPDATED)); + $opds->addLink(new OpdsLink(self::LINK_REL, self::LINK_URL, self::LINK_TYPE)); + foreach (self::ENTRIES as $attr) { + $entry = new OpdsEntry($attr[0], $attr[1], $attr[2] ?? null); + if (isset($attr['updated'])) { + $updated = new DateTimeImmutable($attr['updated']); + $entry->setUpdated($updated); + } + foreach ($attr['authors'] ?? [] as $sub) { + $author = new OpdsAuthor($sub[0], $sub[1] ?? null, $sub[2] ?? null); + $entry->addAuthor($author); + } + foreach ($attr['categories'] ?? [] as $sub) { + $category = new OpdsCategory($sub[0], $sub[1] ?? null, $sub[2] ?? null); + $entry->addCategory($category); + } + foreach ($attr['attributes'] ?? [] as $sub) { + $value = $sub[1] ?? null; + if (!is_null($value) && $value[0] === '!') { + $value = new DateTimeImmutable(substr($value, 1)); + } + $attribute = new OpdsAttribute($sub[2] ?? null, $sub[0], $value); + $entry->addAttribute($attribute); + } + foreach ($attr['links'] ?? [] as $sub) { + $link = new OpdsLink($sub[0], $sub[1], $sub[2]); + $entry->addLink($link); + } + $opds->addEntry($entry); + } + $xml = $opds->render(); + $actual = simplexml_load_string($xml, SimpleXMLElement::class, LIBXML_NOBLANKS); + $expected = simplexml_load_string(self::RESPONSE_XML, SimpleXMLElement::class, LIBXML_NOBLANKS); + $this->assertEquals(dom_import_simplexml($actual), dom_import_simplexml($expected), 'Full response'); + } +} diff --git a/tests/unit/UtilTest.php b/tests/unit/UtilTest.php new file mode 100644 index 0000000..00c7f30 --- /dev/null +++ b/tests/unit/UtilTest.php @@ -0,0 +1,43 @@ +assertEquals('application/x-ms-reader', MimeTypes::getMimeType('LIT')); + $this->assertEquals('application/octet-stream', MimeTypes::getMimeType('XXX')); + } + + public function testMapIterator() { + $sample = SplFixedArray::fromArray([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); + $test = iterator_to_array(new MapIterator( + $sample, fn ($v) => $v * $v + )); + $this->assertEquals([0, 1, 4, 9, 16, 25, 36, 49, 64, 81], $test, "Non-filtering iterator"); + + $test = new MapIterator( + $sample, + fn ($v) => $v * $v, + fn ($v): bool => ($v % 3) == 1 + ); + $this->assertInstanceOf(Iterator::class, $test->getInnerIterator(), "Getting inner iterator"); + $this->assertEquals( + [1 => 1, 2 => 4, 4 => 16, 5 => 25, 7 => 49, 8 => 64], + iterator_to_array($test), "Filtering iterator" + ); + $test->rewind(); + $this->assertTrue($test->valid(), "Calling valid() after rewind() on filtering iterator"); + $this->assertEquals(1, $test->current(), "First value on filtering iterator"); + + $test = iterator_to_array(new MapIterator( + $sample, + fn ($v) => $v * $v, + fn ($v): bool => $v > 100 + )); + $this->assertEquals([], $test, "Empty filtering iterator"); + } +} diff --git a/translationfiles/ru/calibre_opds.mo b/translationfiles/ru/calibre_opds.mo new file mode 100644 index 0000000000000000000000000000000000000000..5f10d06eeb28ff1f063a5f319b03d9ae04853731 GIT binary patch literal 2796 zcmaKsU2GIp6vqby#Z~-3LGkmV1w}gBnJo%zSx_h#5LSK#4vim?xlF4{R-Xz{s!I-{spcD{{?CP+FK0cVemPS<_E!t zKo@)vJPob{KLPIozXUVjEVu&v4!jMF!F$0U!8PC?AlWTlW*E!CdqC2$2D~490=yI4 z0+OzNJ%11+`x4j%z5&vC7eVs#1$Zl12g!aK+zx)L=a*npAI2*{Od0*)dBkKNcpt{s zU`#sy1iQfH5O0CcfKP$1g6qKva1;2s9)Ay#-QVEj;7VMc#wK_-xDzBjhro^C5s>`8 z1JZq`LAu9PkmC3QNICljB)b&|0*!CP0P9+fJNHjUmBBP9L?-XU0G|WT(JknQZ@OY!wX5NsCoz?ymsMF-faz38WijX;ZiBwV28#wOlBAzK; zjpUywKU%!(4EZUH--g<{(mN~X40$mvkB%;bdR6+1&FMrUIbL!)mlb6&TOl{ksP4G+wOofb(2$7$NlcZl-JPv8z d5D!WN>WQj@zC3*B@T4@JRyV{lq, YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: Nextcloud 3.14159\n" +"Report-Msgid-Bugs-To: translations\\@example.com\n" +"POT-Creation-Date: 2023-10-07 19:16+0300\n" +"PO-Revision-Date: 2023-10-07 19:20+0300\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: ru\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && " +"n%10<=4 && (n%100<12 || n%100>14) ? 1 : 2);\n" +"X-Generator: Poedit 3.2.2\n" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:62 +msgid "Nextcloud OPDS Library" +msgstr "Библиотека Nextcloud OPDS" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:63 +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:88 +msgid "Authors" +msgstr "Авторы" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:63 +msgid "All authors" +msgstr "Все авторы" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:64 +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:137 +msgid "Publishers" +msgstr "Издательства" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:64 +msgid "All publishers" +msgstr "Все издательства" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:65 +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:159 +msgid "Languages" +msgstr "Языки" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:65 +msgid "All languages" +msgstr "Все языки" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:66 +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:181 +msgid "Series" +msgstr "Серии" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:66 +msgid "All series" +msgstr "Все серии" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:67 +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:203 +msgid "Tags" +msgstr "Теги" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:67 +msgid "All tags" +msgstr "Все теги" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:68 +msgid "Books" +msgstr "Книги" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:68 +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:225 +msgid "All books" +msgstr "Все книги" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:90 +#, php-format +msgid "Authors by prefix %1$s" +msgstr "Авторы, начинающиеся на %1$s" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:115 +msgid "Authors by prefix" +msgstr "Авторы по началу имени" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:231 +#, php-format +msgid "All books matching: /%1$s/" +msgstr "Все книги по поиску: /%1$s/" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:238 +#, php-format +msgid "All books by author: %1$s" +msgstr "Все книги автора: %1$s" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:248 +#, php-format +msgid "All books by publisher: %1$s" +msgstr "Все книги издательства: %1$s" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:258 +#, php-format +msgid "All books in language: %1$s" +msgstr "Все книги на языке: %1$s" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:265 +#, php-format +msgid "All books in series: %1$s" +msgstr "Все книги в серии: %1$s" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:272 +#, php-format +msgid "All books with tag: %1$s" +msgstr "Все книги с тегом: %1$s" + +#. TRANSLATORS: No more than 16 characters +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:299 +msgid "Search" +msgstr "Поиск" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:300 +msgid "Search books" +msgstr "Поиск книг" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:301 +msgid "Search books with matching titles, authors, series, or tags." +msgstr "Поиск книг по заглавиям, авторам, сериям, и тегам." + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/FeedBuilder/OpdsFeedBuilder.php:76 +#, php-format +msgid "Authors: %1$s" +msgstr "Авторов: %1$s" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/FeedBuilder/OpdsFeedBuilder.php:84 +#, php-format +msgid "Books: %1$s" +msgstr "Книг: %1$s" + +#: /home/alec/workspace/calibre2opds-nextcloud/specialAppInfoFakeDummyForL10nScript.php:2 +msgid "Calibre2OPDS" +msgstr "Calibre2OPDS" + +#: /home/alec/workspace/calibre2opds-nextcloud/specialAppInfoFakeDummyForL10nScript.php:3 +msgid "Simple OPDS server that uses Calibre database as a backend." +msgstr "" +"Простой OPDS-сервер, использующий библиотеку Calibre в качестве источника." + +#: /home/alec/workspace/calibre2opds-nextcloud/templates/settings.personal.php:3 +msgid "Calibre OPDS library" +msgstr "Библиотека Calibre OPDS" + +#: /home/alec/workspace/calibre2opds-nextcloud/templates/settings.personal.php:5 +msgid "Publish your Calibre library in OPDS" +msgstr "Опубликуйте свою библиотеку в OPDS" + +#: /home/alec/workspace/calibre2opds-nextcloud/templates/settings.personal.php:8 +msgid "Library root folder:" +msgstr "Корневая папка библиотеки:" + +#: /home/alec/workspace/calibre2opds-nextcloud/templates/settings.personal.php:14 +msgid "Saved" +msgstr "Сохранено" + +#~ msgid "Book authors" +#~ msgstr "Авторы книг" + +#~ msgid "All library books" +#~ msgstr "Все книги библиотеки" diff --git a/translationfiles/templates/calibre_opds.pot b/translationfiles/templates/calibre_opds.pot new file mode 100644 index 0000000..448b7fa --- /dev/null +++ b/translationfiles/templates/calibre_opds.pot @@ -0,0 +1,162 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the Nextcloud package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: Nextcloud 3.14159\n" +"Report-Msgid-Bugs-To: translations\\@example.com\n" +"POT-Creation-Date: 2023-10-07 19:16+0300\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:62 +msgid "Nextcloud OPDS Library" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:63 +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:88 +msgid "Authors" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:63 +msgid "All authors" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:64 +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:137 +msgid "Publishers" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:64 +msgid "All publishers" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:65 +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:159 +msgid "Languages" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:65 +msgid "All languages" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:66 +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:181 +msgid "Series" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:66 +msgid "All series" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:67 +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:203 +msgid "Tags" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:67 +msgid "All tags" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:68 +msgid "Books" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:68 +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:225 +msgid "All books" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:90 +#, php-format +msgid "Authors by prefix %1$s" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:115 +msgid "Authors by prefix" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:231 +#, php-format +msgid "All books matching: /%1$s/" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:238 +#, php-format +msgid "All books by author: %1$s" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:248 +#, php-format +msgid "All books by publisher: %1$s" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:258 +#, php-format +msgid "All books in language: %1$s" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:265 +#, php-format +msgid "All books in series: %1$s" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:272 +#, php-format +msgid "All books with tag: %1$s" +msgstr "" + +#. TRANSLATORS: No more than 16 characters +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:299 +msgid "Search" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:300 +msgid "Search books" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/Controller/OpdsController.php:301 +msgid "Search books with matching titles, authors, series, or tags." +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/FeedBuilder/OpdsFeedBuilder.php:76 +#, php-format +msgid "Authors: %1$s" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/lib/FeedBuilder/OpdsFeedBuilder.php:84 +#, php-format +msgid "Books: %1$s" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/specialAppInfoFakeDummyForL10nScript.php:2 +msgid "Calibre2OPDS" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/specialAppInfoFakeDummyForL10nScript.php:3 +msgid "Simple OPDS server that uses Calibre database as a backend." +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/templates/settings.personal.php:3 +msgid "Calibre OPDS library" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/templates/settings.personal.php:5 +msgid "Publish your Calibre library in OPDS" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/templates/settings.personal.php:8 +msgid "Library root folder:" +msgstr "" + +#: /home/alec/workspace/calibre2opds-nextcloud/templates/settings.personal.php:14 +msgid "Saved" +msgstr ""