init
This commit is contained in:
parent
8609ec189a
commit
f00db09e35
674
LICENSE
674
LICENSE
|
@ -1,674 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is 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. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
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.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
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 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. Use with the GNU Affero General Public License.
|
||||
|
||||
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 Affero 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 special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU 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 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 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 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.
|
||||
|
||||
{one line to give the program's name and a brief idea of what it does.}
|
||||
Copyright (C) {year} {name of author}
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
{project} Copyright (C) {year} {fullname}
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
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 GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
49
README.md
49
README.md
|
@ -1,49 +0,0 @@
|
|||
# Dotclear REST API
|
||||
|
||||
Plugin to serve a Rest/JSON API on Dotclear.
|
||||
|
||||
This is a work in progress. API definitions and specifications are not stables. Its will be more exhaustive.
|
||||
|
||||
Real time code repository is https://bitbucket.org/gnieark/dc-rest-api
|
||||
|
||||
# Install:
|
||||
|
||||
Make a zip of this repository, rename it "rest.zip" and install it on your Dotclear Blog via the admin interface.
|
||||
|
||||
Or
|
||||
|
||||
hg clone https://bitbucket.org/gnieark/dc-rest-api /path/to/dotclear/plugins/rest
|
||||
|
||||
# Known bugs
|
||||
|
||||
If your dotclear use the query_strings URLS and there are some filters in query...
|
||||
So URL is somthing like index.php?rest/{something}/{someting}?filter1=value1
|
||||
The integrated Swaggers API fails to generate the correct URL. However API Works.
|
||||
|
||||
|
||||
# License
|
||||
|
||||
Dotclear rest/json plugin.
|
||||
|
||||
Copyright (C) [Gnieark](https://blog-du-grouik.tinad.fr/)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU 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 General Public License for more details.
|
||||
|
||||
# Third-party code
|
||||
|
||||
## Dotclear
|
||||
The content management system Dotclear http://dotclear.org/ licensed under
|
||||
GNU GENERAL PUBLIC LICENSE Version 2, June 1991
|
||||
|
||||
|
||||
## SwaggerUI
|
||||
Documentation and the tool to test the API is a third party code integrated on this plugin:
|
||||
Swagger-UI https://github.com/swagger-api/swagger-ui Licensed under the Apache License, Version 2.0
|
|
@ -1,9 +0,0 @@
|
|||
<?php
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')) { return; }
|
||||
|
||||
$_menu['Blog']->addItem(__('Rest API'),
|
||||
'plugin.php?p=rest',
|
||||
urldecode(dcPage::getPF('rest/rest_api.png')),
|
||||
preg_match('/plugin.php\?p=rest(&.*)?$/',$_SERVER['REQUEST_URI']),
|
||||
$core->auth->check('contentadmin',$core->blog->id));
|
23
_define.php
23
_define.php
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
# -- BEGIN LICENSE BLOCK ---------------------------------------
|
||||
#
|
||||
# This file is part of Dotclear 2.
|
||||
#
|
||||
# Copyright (c) 2003-2017 Dotclear
|
||||
# Licensed under the GPL version 2.0 license.
|
||||
# See LICENSE file or
|
||||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
#
|
||||
# -- END LICENSE BLOCK -----------------------------------------
|
||||
if (!defined('DC_RC_PATH')) { return; }
|
||||
|
||||
$this->registerModule(
|
||||
/* Name */ "rest",
|
||||
/* Description*/ "A JSON/REST API for Dotclear",
|
||||
/* Author */ "Gnieark",
|
||||
/* Version */ '0.0.5',
|
||||
array(
|
||||
'permissions' => 'usage,contentadmin',
|
||||
'type' => 'plugin',
|
||||
)
|
||||
);
|
34
_prepend.php
34
_prepend.php
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
global $__autoload;
|
||||
|
||||
$__autoload['ApiKey'] = dirname(__FILE__).'/inc/class.rest.key.php';
|
||||
$__autoload['RestDocumentation'] = dirname(__FILE__).'/inc/class.rest.documentation.php';
|
||||
$__autoload['restAuth'] = dirname(__FILE__).'/inc/class.rest.auth.php';
|
||||
$__autoload['restDcNameSpace'] = dirname(__FILE__).'/inc/class.rest.DcNameSpace.php';
|
||||
$__autoload['RestCategories'] = dirname(__FILE__).'/inc/class.rest.categories.php';
|
||||
$__autoload['RestQuery'] = dirname(__FILE__).'/inc/class.rest.query.php';
|
||||
$__autoload['RestQueryGetBlogs'] = dirname(__FILE__).'/inc/class.rest.query.get.blogs.php';
|
||||
$__autoload['RestQueryGetBlog'] = dirname(__FILE__).'/inc/class.rest.query.get.blog.php';
|
||||
$__autoload['RestQueryGetSpecs'] = dirname(__FILE__).'/inc/class.rest.query.get.specs.php';
|
||||
$__autoload['RestQueryPostBlogs'] = dirname(__FILE__).'/inc/class.rest.query.post.blogs.php';
|
||||
$__autoload['ResQueryPatchBlogs'] = dirname(__FILE__).'/inc/class.rest.query.patch.blogs.php';
|
||||
$__autoload['ResQueryPutBlogs'] = dirname(__FILE__).'/inc/class.rest.query.put.blogs.php';
|
||||
$__autoload['ResQueryDeleteBlogs'] = dirname(__FILE__).'/inc/class.rest.query.delete.blogs.php';
|
||||
$__autoload['RestQueryGetBlogSettings'] = dirname(__FILE__).'/inc/class.rest.query.get.blog.settings.php';
|
||||
$__autoload['RestQueryPostBlogSettings'] = dirname(__FILE__).'/inc/class.rest.query.post.blog.settings.php';
|
||||
$__autoload['RestQueryDeleteBlogSettings'] = dirname(__FILE__).'/inc/class.rest.query.delete.blog.settings.php';
|
||||
$__autoload['RestQueryGetPosts'] = dirname(__FILE__).'/inc/class.rest.query.get.posts.php';
|
||||
$__autoload['RestQueryGetPost'] = dirname(__FILE__).'/inc/class.rest.query.get.post.php';
|
||||
$__autoload['RestQueryPostPost'] = dirname(__FILE__).'/inc/class.rest.query.post.post.php';
|
||||
$__autoload['RestQueryGetCategories'] = dirname(__FILE__).'/inc/class.rest.query.get.categories.php';
|
||||
$__autoload['RestQueryPatchCategories'] = dirname(__FILE__).'/inc/class.rest.query.patch.categories.php';
|
||||
$__autoload['RestQueryPostCategories'] = dirname(__FILE__).'/inc/class.rest.query.post.categories.php';
|
||||
$__autoload['RestQueryDeleteCategories'] = dirname(__FILE__).'/inc/class.rest.query.delete.categories.php';
|
||||
$__autoload['RestQueryPostMetas'] = dirname(__FILE__).'/inc/class.rest.query.post.metas.php';
|
||||
$__autoload['RestQueryGetMetas'] = dirname(__FILE__).'/inc/class.rest.query.get.metas.php';
|
||||
$__autoload['RestQueryGetPostMetas'] = dirname(__FILE__).'/inc/class.rest.query.get.post.metas.php';
|
||||
$__autoload['RestQueryDeletePostMeta'] = dirname(__FILE__).'/inc/class.rest.query.delete.post.meta.php';
|
||||
$__autoload['ResQueryPatchMeta'] = dirname(__FILE__).'/inc/class.rest.query.patch.metas.php';
|
||||
$__autoload['RestQueryGetComments'] = dirname(__FILE__).'/inc/class.rest.query.get.comments.php';
|
||||
$__autoload['RestQueryDeleteComments'] = dirname(__FILE__).'/inc/class.rest.query.delete.comments.php';
|
||||
|
166
_public.php
166
_public.php
|
@ -1,166 +0,0 @@
|
|||
<?php
|
||||
if (!defined('DC_RC_PATH')) { return; }
|
||||
|
||||
$core->url->register('rest','rest','^rest(?:/(.*))?$',array('rest','getResponse'));
|
||||
class rest extends dcUrlHandlers
|
||||
{
|
||||
|
||||
/**
|
||||
* Create the "good" RestQuery instance
|
||||
* Input: $httpMethod: String (POST/GET/PATCH etc...)
|
||||
* $args Url arguments
|
||||
* $user dcAuth object
|
||||
* $body Body of the input query. String
|
||||
* Output: object RestQuery
|
||||
*/
|
||||
private function restFactoryQuery($httpMethod,$args,$body){
|
||||
//définir la methode API (pas HTML) appelée
|
||||
switch($httpMethod){
|
||||
case "GET":
|
||||
if($args == 'blogs')
|
||||
return new RestQueryGetBlogs();
|
||||
elseif( $args == "specs")
|
||||
return new RestQueryGetSpecs($args);
|
||||
elseif(preg_match('/^specs\/(.*)$/', $args ))
|
||||
return new RestQueryGetSpecs($args);
|
||||
elseif(preg_match('/^blogs\/(.*)$/', $args ))
|
||||
return new RestQueryGetBlog($args);
|
||||
elseif($args == "documentation")
|
||||
return new RestDocumentation($args);
|
||||
elseif(preg_match('/^documentation\/(.*)$/', $args ))
|
||||
return new RestDocumentation($args);
|
||||
elseif(preg_match('/^(.*)\/settings$/', $args ))
|
||||
return new RestQueryGetBlogSettings($args);
|
||||
elseif(preg_match('/^(.*)\/settings\/(.*)$/', $args ))
|
||||
return new RestQueryGetBlogSettings($args);
|
||||
elseif(preg_match('/^(.*)\/posts$/', $args ))
|
||||
return new RestQueryGetPosts($args);
|
||||
elseif(preg_match('/^(.*)\/post\/(.*)$/', $args ))
|
||||
return new RestQueryGetPost($args);
|
||||
elseif(preg_match('/^(.*)\/metas$/', $args ))
|
||||
return new RestQueryGetMetas($args);
|
||||
elseif(preg_match('/^(.*)\/categories$/', $args ))
|
||||
return new RestQueryGetCategories($args);
|
||||
elseif(preg_match('/^(.*)\/categories\/(.*)$/', $args ))
|
||||
return new RestQueryGetCategories($args);
|
||||
elseif(preg_match('/^(.*)\/metas\/(.*)$/', $args ))
|
||||
return new RestQueryGetPostMetas($args);
|
||||
elseif(preg_match('/^(.*)\/comments\/(.*)$/', $args ))
|
||||
return new RestQueryGetComments($args);
|
||||
elseif(preg_match('/^(.*)\/comments$/', $args ))
|
||||
return new RestQueryGetComments($args);
|
||||
|
||||
|
||||
break;
|
||||
case "POST":
|
||||
if($args == 'blogs')
|
||||
return new RestQueryPostBlogs($body);
|
||||
elseif(preg_match('/^(.*)\/settings\/(.*)$/', $args ))
|
||||
return new RestQueryPostBlogSettings($args,$body);
|
||||
elseif(preg_match('/^(.*)\/post$/', $args ))
|
||||
return new RestQueryPostPost($args,$body);
|
||||
elseif(preg_match('/^(.*)\/categories$/', $args ))
|
||||
return new RestQueryPostCategories($args,$body);
|
||||
elseif(preg_match('/^(.*)\/metas$/', $args ))
|
||||
return new RestQueryPostMetas($args,$body);
|
||||
break;
|
||||
case "PUT":
|
||||
if(preg_match('/^blogs\/(.*)$/', $args )){
|
||||
return new ResQueryPutBlogs($args,$body);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case "PATCH":
|
||||
if(preg_match('/^blogs\/(.*)$/', $args ))
|
||||
return new ResQueryPatchBlogs($args,$body);
|
||||
elseif(preg_match('/^(.*)\/(.*)\/meta\/(.*)$/', $args ))
|
||||
return new ResQueryPatchMeta($args,$body);
|
||||
elseif(preg_match('/^(.*)\/categories\/(.*)$/', $args ))
|
||||
return new RestQueryPatchCategories($args,$body);
|
||||
break;
|
||||
|
||||
case "DELETE":
|
||||
if(preg_match('/^blogs\/(.*)$/', $args ))
|
||||
return new ResQueryDeleteBlogs($args,$body);
|
||||
elseif(preg_match('/^(.*)\/settings\/(.*)$/', $args ))
|
||||
return new RestQueryDeleteBlogSettings($args);
|
||||
elseif(preg_match('/^(.*)\/(.*)\/metas$/', $args ))
|
||||
return new RestQueryDeletePostMeta($args);
|
||||
elseif(preg_match('/^(.*)\/(.*)\/meta\/(.*)$/', $args ))
|
||||
return new RestQueryDeletePostMeta($args);
|
||||
elseif(preg_match('/^(.*)\/categories\/(.*)$/', $args ))
|
||||
return new RestQueryDeleteCategories($args,$body);
|
||||
elseif(preg_match('/^(.*)\/comments\/(.*)$/', $args ))
|
||||
return new RestQueryDeleteComments($args,$body);
|
||||
elseif(preg_match('/^(.*)\/comments$/', $args ))
|
||||
return new RestQueryDeleteComments($args,$body);
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return new RestQuery(); //will return a 404
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Serve the Query response With the headers and the body
|
||||
*/
|
||||
public static function getResponse($args)
|
||||
{
|
||||
global $core;
|
||||
$active = (boolean)$core->blog->settings->rest->rest_active;
|
||||
if (!$active){
|
||||
self::p404();
|
||||
return;
|
||||
}
|
||||
|
||||
//coors headers
|
||||
if($core->blog->settings->rest->rest_send_cors_headers){
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE');
|
||||
header('Access-Control-Allow-Headers: Content-Type, authorization, x_dc_key');
|
||||
}
|
||||
|
||||
|
||||
//user authentification (facultative at this step)
|
||||
$apiKey = rest::get_api_key_sended();
|
||||
//$user = false;
|
||||
if($apiKey){
|
||||
$core->auth = new restAuth($core);
|
||||
if($core->auth->checkUser('','',$apiKey) === false){
|
||||
header('Content-Type: application/json');
|
||||
header(RestQuery::get_full_code_header(403));
|
||||
echo json_encode(array(
|
||||
"error" => "Wrong API Key",
|
||||
"code" => 403
|
||||
));
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
$core->auth = false;
|
||||
}
|
||||
$r = rest::restFactoryQuery($_SERVER['REQUEST_METHOD'],$args,file_get_contents('php://input'));
|
||||
header($r->get_full_code_header());
|
||||
if(is_array($r->response_message)){
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($r->response_message);
|
||||
}else{
|
||||
echo $r->response_message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function get_api_key_sended()
|
||||
{
|
||||
//to do: test it with nginx
|
||||
$headers = apache_request_headers();
|
||||
if(isset($headers['x_dc_key'])){
|
||||
return $headers['x_dc_key'];
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,232 +0,0 @@
|
|||
swagger: '2.0'
|
||||
info:
|
||||
title: Dotclear API
|
||||
description: Manage your(s) blogs with this API
|
||||
version: 0.0.2
|
||||
host: dotclear.localhost
|
||||
schemes:
|
||||
- http
|
||||
basePath: /dotclear/index.php?rest
|
||||
produces:
|
||||
- application/json
|
||||
paths:
|
||||
|
||||
/blogs:
|
||||
get:
|
||||
summary: Get list of availables blogs
|
||||
parameters:
|
||||
- name: x_dc_key
|
||||
in: header
|
||||
required: false
|
||||
type: string
|
||||
responses:
|
||||
'200':
|
||||
description: array serving blogs properties
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
default:
|
||||
description: Unexpected error
|
||||
schema:
|
||||
$ref: '#/definitions/Error'
|
||||
post:
|
||||
summary: Create a new blog
|
||||
parameters:
|
||||
- name: x_dc_key
|
||||
in: header
|
||||
type: string
|
||||
required: true
|
||||
- name: blog
|
||||
in: body
|
||||
description: The blog you want to create
|
||||
schema:
|
||||
$ref: '#/definitions/blog'
|
||||
required: true
|
||||
responses:
|
||||
'201':
|
||||
description: 'Success, array containing the new blog''s identifiant'
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
blog_id:
|
||||
type: integer
|
||||
message:
|
||||
type: string
|
||||
default:
|
||||
description: Unexpected error
|
||||
schema:
|
||||
$ref: '#/definitions/Error'
|
||||
'/blogs/{blog-id}':
|
||||
get:
|
||||
summary: Get a blog poperties
|
||||
parameters:
|
||||
- name: x_dc_key
|
||||
in: header
|
||||
type: string
|
||||
required: false
|
||||
- name: blog-id
|
||||
in: path
|
||||
type: string
|
||||
required: true
|
||||
responses:
|
||||
'200':
|
||||
description: 'Core blog properties. use {blog_id}/settings methods for more settings.'
|
||||
schema:
|
||||
$ref: '#/definitions/blogProperties'
|
||||
'404':
|
||||
description: this blog id does not exists
|
||||
default:
|
||||
description: Unexpected error
|
||||
schema:
|
||||
$ref: '#/definitions/Error'
|
||||
patch:
|
||||
summary: Update part of blog properties
|
||||
parameters:
|
||||
- name: x_dc_key
|
||||
in: header
|
||||
type: string
|
||||
required: true
|
||||
- name: blog-id
|
||||
in: path
|
||||
type: string
|
||||
required: true
|
||||
- name: blog
|
||||
in: body
|
||||
description: This list of parameters is not exhaustive
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/blogProperties'
|
||||
responses:
|
||||
'200':
|
||||
description: array containing the edited blog's identifiant
|
||||
schema:
|
||||
$ref: '#/definitions/Ids'
|
||||
'404':
|
||||
description: this blog id does not exists
|
||||
default:
|
||||
description: Unexpected error
|
||||
schema:
|
||||
$ref: '#/definitions/Error'
|
||||
put:
|
||||
summary: 'Overwrite blog Properties (if an optional parameter is not set, his value will be erased by the default value)'
|
||||
parameters:
|
||||
- name: x_dc_key
|
||||
in: header
|
||||
type: string
|
||||
required: true
|
||||
- name: blog-id
|
||||
in: path
|
||||
type: string
|
||||
required: true
|
||||
- name: blog
|
||||
in: body
|
||||
description: This list of parameters is not exhaustive
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/blogPropertiesPut'
|
||||
responses:
|
||||
'200':
|
||||
description: array containing the edited blog's identifiant
|
||||
schema:
|
||||
$ref: '#/definitions/Ids'
|
||||
'404':
|
||||
description: this blog id does not exists
|
||||
default:
|
||||
description: Unexpected error
|
||||
schema:
|
||||
$ref: '#/definitions/Error'
|
||||
delete:
|
||||
summary: Delete this blog
|
||||
parameters:
|
||||
- name: x_dc_key
|
||||
in: header
|
||||
type: string
|
||||
required: true
|
||||
- name: blog-id
|
||||
in: path
|
||||
type: string
|
||||
required: true
|
||||
responses:
|
||||
'200':
|
||||
description: array containing the deleted blog's identifiant
|
||||
schema:
|
||||
$ref: '#/definitions/Ids'
|
||||
'404':
|
||||
description: this blog id does not exists
|
||||
default:
|
||||
description: Unexpected error
|
||||
schema:
|
||||
$ref: '#/definitions/Error'
|
||||
|
||||
definitions:
|
||||
blog:
|
||||
type: object
|
||||
required:
|
||||
- blog_id
|
||||
- blog_name
|
||||
- blog_url
|
||||
properties:
|
||||
blog_id:
|
||||
type: string
|
||||
blog_name:
|
||||
type: string
|
||||
blog_url:
|
||||
type: string
|
||||
blog_desc:
|
||||
type: string
|
||||
lang:
|
||||
type: string
|
||||
blog_timezone:
|
||||
type: string
|
||||
url_scan:
|
||||
type: string
|
||||
enum:
|
||||
- query_string
|
||||
- path_info
|
||||
Ids:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
description: New blog id
|
||||
blogPropertiesPut:
|
||||
required:
|
||||
- blog_id
|
||||
- blog_name
|
||||
- blog_url
|
||||
- blog_desc
|
||||
type: object
|
||||
properties:
|
||||
blog_id:
|
||||
type: string
|
||||
blog_name:
|
||||
type: string
|
||||
blog_url:
|
||||
type: string
|
||||
blog_desc:
|
||||
type: string
|
||||
blogProperties:
|
||||
type: object
|
||||
properties:
|
||||
blog_id:
|
||||
type: string
|
||||
blog_name:
|
||||
type: string
|
||||
blog_url:
|
||||
type: string
|
||||
blog_desc:
|
||||
type: string
|
||||
|
||||
Error:
|
||||
type: object
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
format: int32
|
||||
message:
|
||||
type: string
|
||||
fields:
|
||||
type: string
|
|
@ -1,150 +0,0 @@
|
|||
swagger: '2.0'
|
||||
info:
|
||||
title: Dotclear API
|
||||
description: Manage your(s) blogs with this API
|
||||
version: 0.0.2
|
||||
host: dotclear.localhost
|
||||
schemes:
|
||||
- http
|
||||
basePath: /dotclear/index.php?rest
|
||||
produces:
|
||||
- application/json
|
||||
paths:
|
||||
|
||||
'/{blog_id}/settings':
|
||||
get:
|
||||
summary: 'Get the about:config'
|
||||
description: Get all parameters
|
||||
parameters:
|
||||
- name: x_dc_key
|
||||
in: header
|
||||
type: string
|
||||
required: true
|
||||
- name: blog_id
|
||||
in: path
|
||||
type: string
|
||||
required: true
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
'404':
|
||||
description: this blog id does not exists
|
||||
default:
|
||||
description: Unexpected error
|
||||
schema:
|
||||
$ref: '#/definitions/Error'
|
||||
'/{blog_id}/settings/{name_space}':
|
||||
get:
|
||||
summary: Get the settings inside the name-space
|
||||
description: same
|
||||
parameters:
|
||||
- name: x_dc_key
|
||||
in: header
|
||||
type: string
|
||||
required: true
|
||||
- name: blog_id
|
||||
in: path
|
||||
type: string
|
||||
required: true
|
||||
- name: name_space
|
||||
in: path
|
||||
type: string
|
||||
required: true
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
'404':
|
||||
description: this blog id does not exists
|
||||
default:
|
||||
description: Unexpected error
|
||||
schema:
|
||||
$ref: '#/definitions/Error'
|
||||
post:
|
||||
summary: Create or edit a new namespace and or a new setting'
|
||||
description: 'Let body empty if you just want to create a namespace without setting. Note that if the setting already exists, it will be erased. So, PUT and PATCH methods are useless.'
|
||||
parameters:
|
||||
- name: x_dc_key
|
||||
in: header
|
||||
type: string
|
||||
required: true
|
||||
- name: blog_id
|
||||
in: path
|
||||
type: string
|
||||
required: true
|
||||
- name: name_space
|
||||
in: path
|
||||
type: string
|
||||
required: true
|
||||
- name: setting
|
||||
description: 'Can be empty, Can pass many settings. [{"id":"string","type":"string","value":"string","value_change":"string Optional","global":"bool optional"},{"id2":...}]'
|
||||
in: body
|
||||
schema:
|
||||
$ref: '#/definitions/settings'
|
||||
responses:
|
||||
'201':
|
||||
description: OK
|
||||
default:
|
||||
description: Unexpected error
|
||||
schema:
|
||||
$ref: '#/definitions/Error'
|
||||
'/{blog_id}/settings/{name_space}/{setting_id}':
|
||||
get:
|
||||
summary: Get value and type for one setting'
|
||||
description: ''
|
||||
parameters:
|
||||
- name: x_dc_key
|
||||
in: header
|
||||
type: string
|
||||
required: true
|
||||
- name: blog_id
|
||||
in: path
|
||||
type: string
|
||||
required: true
|
||||
- name: name_space
|
||||
in: path
|
||||
type: string
|
||||
required: true
|
||||
- name: setting_id
|
||||
in: path
|
||||
type: string
|
||||
required: true
|
||||
responses:
|
||||
'200':
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/OneSetting'
|
||||
default:
|
||||
description: Unexpected error
|
||||
schema:
|
||||
$ref: '#/definitions/Error'
|
||||
|
||||
|
||||
definitions:
|
||||
|
||||
OneSetting:
|
||||
type: object
|
||||
properties:
|
||||
ns:
|
||||
type: string
|
||||
value:
|
||||
type: string
|
||||
type:
|
||||
type: string
|
||||
label:
|
||||
type: string
|
||||
global:
|
||||
type: boolean
|
||||
settings:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
Error:
|
||||
type: object
|
||||
properties:
|
||||
code:
|
||||
type: integer
|
||||
format: int32
|
||||
message:
|
||||
type: string
|
||||
fields:
|
||||
type: string
|
|
@ -1,55 +0,0 @@
|
|||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "Dotclear API",
|
||||
"description": "Manage your(s) blogs with this API",
|
||||
"version": "0.0.2"
|
||||
},
|
||||
"host": "dotclear.localhost",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"basePath": "/dotclear/index.php?rest",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"paths": {
|
||||
"/specs": {
|
||||
"get": {
|
||||
"summary": "Get this API SWAGGER documentation",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "swagger.json",
|
||||
"schema": {
|
||||
"title": "doc",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"Error": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"fields": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,350 +0,0 @@
|
|||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "Dotclear API",
|
||||
"description": "Manage your(s) blogs with this API",
|
||||
"version": "0.0.2"
|
||||
},
|
||||
"host": "dotclear.localhost",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"basePath": "/dotclear/index.php?rest",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"paths": {
|
||||
"/blogs": {
|
||||
"get": {
|
||||
"summary": "Get list of availables blogs",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"required": false,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "array serving blogs properties",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"summary": "Create a new blog",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "blog",
|
||||
"in": "body",
|
||||
"description": "The blog you want to create",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/blog"
|
||||
},
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "Success, array containing the new blog's identifiant",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer"
|
||||
},
|
||||
"blog_id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/blogs/{blog-id}": {
|
||||
"get": {
|
||||
"summary": "Get a blog poperties",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Core blog properties. use {blog_id}/settings methods for more settings.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/blogProperties"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "this blog id does not exists"
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"patch": {
|
||||
"summary": "Update part of blog properties",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "blog",
|
||||
"in": "body",
|
||||
"description": "This list of parameters is not exhaustive",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/blogProperties"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "array containing the edited blog's identifiant",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Ids"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "this blog id does not exists"
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"summary": "Overwrite blog Properties (if an optional parameter is not set, his value will be erased by the default value)",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "blog",
|
||||
"in": "body",
|
||||
"description": "This list of parameters is not exhaustive",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/blogPropertiesPut"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "array containing the edited blog's identifiant",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Ids"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "this blog id does not exists"
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"summary": "Delete this blog",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "array containing the deleted blog's identifiant",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Ids"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "this blog id does not exists"
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"blog": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"blog_id",
|
||||
"blog_name",
|
||||
"blog_url"
|
||||
],
|
||||
"properties": {
|
||||
"blog_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"blog_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"blog_url": {
|
||||
"type": "string"
|
||||
},
|
||||
"blog_desc": {
|
||||
"type": "string"
|
||||
},
|
||||
"lang": {
|
||||
"type": "string"
|
||||
},
|
||||
"blog_timezone": {
|
||||
"type": "string"
|
||||
},
|
||||
"url_scan": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"query_string",
|
||||
"path_info"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"Ids": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"description": "New blog id"
|
||||
}
|
||||
}
|
||||
},
|
||||
"blogPropertiesPut": {
|
||||
"required": [
|
||||
"blog_id",
|
||||
"blog_name",
|
||||
"blog_url",
|
||||
"blog_desc"
|
||||
],
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"blog_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"blog_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"blog_url": {
|
||||
"type": "string"
|
||||
},
|
||||
"blog_desc": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"blogProperties": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"blog_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"blog_name": {
|
||||
"type": "string"
|
||||
},
|
||||
"blog_url": {
|
||||
"type": "string"
|
||||
},
|
||||
"blog_desc": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Error": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"fields": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,363 +0,0 @@
|
|||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "Dotclear API Categories Method",
|
||||
"description": "Search Create Update Delete Categories",
|
||||
"version": "0.0.2"
|
||||
},
|
||||
"host": "dotclear.localhost",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"basePath": "/dotclear/index.php?rest",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"paths": {
|
||||
"/{blog-id}/categories": {
|
||||
"get": {
|
||||
"summary": "Get list of available categories",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "filters",
|
||||
"in": "query",
|
||||
"type": "string",
|
||||
"required": false,
|
||||
"description": "UrlEncoded filters Separate each of them by a space ( \"+\" once urlencoded). Values are between double quotes Sample cat_title%3D%22SearchedTitle%22+cat_url%3D%22searched%2Furl%22 Available keys are \"cat_title\",\"cat_url\",\"cat_desc\", \"cat_level\",\"cat_parent_id\",\"cat_position\""
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "array containing the categories properties",
|
||||
"schema": {
|
||||
"title": "categories",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/category"
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"summary": "Create a new category",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "properties",
|
||||
"in": "body",
|
||||
"description": "cat_position is facultative. If unset, the new category will have the last cat_position. If setted and position_permute false or unsetted; It will shift the following categories.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/new_category"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "array containing the created category id",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Ids"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/{blog-id}/categories/{cat-id}": {
|
||||
"get": {
|
||||
"summary": "Get one category properties",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "cat-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "array containing the created category properties",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/category"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"patch": {
|
||||
"summary": "Update some attributes",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "cat-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "category",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/patch_category"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "array containing the modified category id",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Ids"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"summary": "Delete a category",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "cat-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "options",
|
||||
"in": "body",
|
||||
"description": "By default, all posts and subcategories contained on the deleted s one will be setted on the parent. If the category was a top level one, posts will be setted with no category, and subcategories will become top levels cat. However you can choose to put all of them on another category, or to delete them.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/delete_category"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "array containing Sucess message",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/success"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"Ids": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"description": "New blog id"
|
||||
}
|
||||
}
|
||||
},
|
||||
"category": {
|
||||
"type": "object",
|
||||
"description": "about the cat_position: The first position is 0. It's the relative postions with the same parent's child.",
|
||||
"properties": {
|
||||
"cat_id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"level": {
|
||||
"type": "integer"
|
||||
},
|
||||
"cat_title": {
|
||||
"type": "string"
|
||||
},
|
||||
"cat_url": {
|
||||
"type": "string"
|
||||
},
|
||||
"cat_desc": {
|
||||
"type": "string"
|
||||
},
|
||||
"cat_level": {
|
||||
"type": "integer"
|
||||
},
|
||||
"cat_parent_id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"cat_position": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"new_category": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"cat_title"
|
||||
],
|
||||
"properties": {
|
||||
"cat_title": {
|
||||
"type": "string"
|
||||
},
|
||||
"cat_url": {
|
||||
"type": "string"
|
||||
},
|
||||
"cat_desc": {
|
||||
"type": "string"
|
||||
},
|
||||
"cat_parent_id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"cat_position": {
|
||||
"type": "integer"
|
||||
},
|
||||
"position_permute": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"temporary": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"patch_category": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"cat_title": {
|
||||
"type": "string"
|
||||
},
|
||||
"cat_url": {
|
||||
"type": "string"
|
||||
},
|
||||
"cat_desc": {
|
||||
"type": "string"
|
||||
},
|
||||
"cat_parent_id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"cat_position": {
|
||||
"type": "integer"
|
||||
},
|
||||
"permute": {
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
},
|
||||
"temporary": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete_category": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"move_childs_on_cat_id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"delete_childs": {
|
||||
"default": false,
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Error": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"fields": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"success": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,508 +0,0 @@
|
|||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "Dotclear API Comments methods",
|
||||
"description": "Search Create Update Delete comments",
|
||||
"version": "0.0.2"
|
||||
},
|
||||
"host": "dotclear.localhost",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"basePath": "/dotclear/index.php?rest",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"paths": {
|
||||
"/{blog-id}/comments": {
|
||||
"get": {
|
||||
"summary": "Get list of comments",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "filters",
|
||||
"in": "query",
|
||||
"type": "string",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "limits",
|
||||
"in": "query",
|
||||
"type": "string",
|
||||
"required": false
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "array containing the categories properties",
|
||||
"schema": {
|
||||
"title": "list of comments",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/comments"
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"summary": "Delete a list of comments",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "list",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/list"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "array containing the categories properties",
|
||||
"schema": {
|
||||
"title": "list of comments",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/comments"
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/{blog-id}/{post-id}/comments": {
|
||||
"get": {
|
||||
"summary": "Get list of comments for the given post",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "post-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "filters",
|
||||
"in": "query",
|
||||
"type": "string",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "limits",
|
||||
"in": "query",
|
||||
"type": "string",
|
||||
"required": false
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "array containing the categories properties",
|
||||
"schema": {
|
||||
"title": "list of comments",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/comments"
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"summary": "Create a new comment",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "post-id",
|
||||
"in": "path",
|
||||
"type": "integer",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "properties",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/new_comment"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "array containing the created category id",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Ids"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/{blog-id}/comments/{comment-id}": {
|
||||
"get": {
|
||||
"summary": "Get one comment properties",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "comment-id",
|
||||
"in": "path",
|
||||
"type": "integer",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "array containing the created category properties",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/comments"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"patch": {
|
||||
"summary": "Update some attributes",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "comment-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "cmooent",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/patch_comment"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "array containing the modified category id",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Ids"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"summary": "Delete a comment",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "comment-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "array containing Sucess message",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/success"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"Ids": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"description": "New blog id"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Error": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"fields": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"list": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"patch_comment": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"comment_dt": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_tz": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_upddt": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_author": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_email": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_site": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_content": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_words": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_ip": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_status": {
|
||||
"type": "integer"
|
||||
},
|
||||
"comment_spam_status": {
|
||||
"type": "integer"
|
||||
},
|
||||
"comment_spam_filter": {
|
||||
"type": "integer"
|
||||
},
|
||||
"comment_trackback": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"new_comment": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"comment_dt": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_tz": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_upddt": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_author": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_email": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_site": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_content": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_words": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_ip": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_status": {
|
||||
"type": "integer"
|
||||
},
|
||||
"comment_spam_status": {
|
||||
"type": "integer"
|
||||
},
|
||||
"comment_spam_filter": {
|
||||
"type": "integer"
|
||||
},
|
||||
"comment_trackback": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"comments": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"comment_id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"post_id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"comment_dt": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_tz": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_upddt": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_author": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_email": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_site": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_content": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_words": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_ip": {
|
||||
"type": "string"
|
||||
},
|
||||
"comment_status": {
|
||||
"type": "integer"
|
||||
},
|
||||
"comment_spam_status": {
|
||||
"type": "integer"
|
||||
},
|
||||
"comment_spam_filter": {
|
||||
"type": "integer"
|
||||
},
|
||||
"comment_trackback": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"success": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,360 +0,0 @@
|
|||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "Dotclear API",
|
||||
"description": "Manage your(s) blogs with this API",
|
||||
"version": "0.0.2"
|
||||
},
|
||||
"host": "dotclear.localhost",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"basePath": "/dotclear/index.php?rest",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"paths": {
|
||||
"/{blog-id}/metas": {
|
||||
"post": {
|
||||
"summary": "Create a new Postr meta",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "properties",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/new_meta"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "New meta id",
|
||||
"schema": {
|
||||
"title": "categories",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"get": {
|
||||
"summary": "get metas",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "post_id",
|
||||
"in": "query",
|
||||
"type": "string",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "meta_type",
|
||||
"in": "query",
|
||||
"type": "string",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "meta_id",
|
||||
"in": "query",
|
||||
"type": "string",
|
||||
"required": false
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "metas",
|
||||
"schema": {
|
||||
"title": "Metas",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/meta"
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/{blog-id}/{post-id}/metas": {
|
||||
"get": {
|
||||
"summary": "get metas for a post",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "post-id",
|
||||
"in": "path",
|
||||
"type": "integer",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Metas properties",
|
||||
"schema": {
|
||||
"title": "categories",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/meta"
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"summary": "Delete all metas for a given post",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "post-id",
|
||||
"in": "path",
|
||||
"type": "integer",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "succes messqge",
|
||||
"schema": {
|
||||
"title": "success message",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/metas"
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/{blog-id}/{post-id}/meta/{meta-id}": {
|
||||
"delete": {
|
||||
"summary": "Delete a meta for a given POST",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "post-id",
|
||||
"in": "path",
|
||||
"type": "integer",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "meta-id",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "confirmqtion",
|
||||
"schema": {
|
||||
"title": "categories",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/metas"
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"patch": {
|
||||
"summary": "Delete the meta with the given id and recreate one",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "post-id",
|
||||
"in": "path",
|
||||
"type": "integer",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "meta-id",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "meta",
|
||||
"in": "body",
|
||||
"description": "This list of parameters is not exhaustive",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/new_meta"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "confirmqtion",
|
||||
"schema": {
|
||||
"title": "categories",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/metas"
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"new_meta": {
|
||||
"required": [
|
||||
"meta_id",
|
||||
"meta_type",
|
||||
"post_id"
|
||||
],
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"meta_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"meta_type": {
|
||||
"type": "string"
|
||||
},
|
||||
"post_id": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"metas": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"meta": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"count": {
|
||||
"type": "integer"
|
||||
},
|
||||
"meta_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"meta_type": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"Error": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"fields": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,586 +0,0 @@
|
|||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "Dotclear API - manage posts",
|
||||
"description": "SCRUD Posts entrys",
|
||||
"version": "0.0.2"
|
||||
},
|
||||
"host": "dotclear.localhost",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"basePath": "/dotclear/index.php?rest",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"paths": {
|
||||
"/{blog-id}/posts": {
|
||||
"get": {
|
||||
"summary": "Get list of posts",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "limit-start",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"type": "integer"
|
||||
},
|
||||
{
|
||||
"name": "limit-count",
|
||||
"in": "query",
|
||||
"type": "integer",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "cat_id",
|
||||
"in": "query",
|
||||
"type": "string",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "post_status",
|
||||
"type": "string",
|
||||
"in": "query",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "password",
|
||||
"type": "string",
|
||||
"in": "query",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "post_selected",
|
||||
"type": "boolean",
|
||||
"in": "query",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "post_open_comment",
|
||||
"type": "boolean",
|
||||
"in": "query",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "post_open_tb",
|
||||
"type": "boolean",
|
||||
"in": "query",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "post_month",
|
||||
"type": "string",
|
||||
"in": "query",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "post_year",
|
||||
"type": "string",
|
||||
"in": "query",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "post_lang",
|
||||
"type": "string",
|
||||
"in": "query",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "post_format",
|
||||
"type": "string",
|
||||
"in": "query",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "sortby",
|
||||
"type": "string",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"description": "If many, separate them by a comma"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "list of posts",
|
||||
"schema": {
|
||||
"title": "posts",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/dc_post"
|
||||
}
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/{blog-id}/post": {
|
||||
"post": {
|
||||
"summary": "Create a new post",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "properties",
|
||||
"in": "body",
|
||||
"description": "Some non required fields you don't define will be set (default value) by the API. You can post many posts once by putting them on an array like [{'post_title':'blah',...},{'post_title':'bluh',...}]",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/new_dc_post"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Id of newly created post",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Ids"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/{blog-id}/post/{post-id}": {
|
||||
"get": {
|
||||
"summary": "Get a post entry",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "post-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "fields",
|
||||
"in": "query",
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
},
|
||||
"required": false,
|
||||
"description": "Fields you want to get. If unset, all available fields will be get."
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "The post values",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dc_post"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"patch": {
|
||||
"summary": "Not yet developed Update part of a post entry's properties",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "post-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "properties",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dc_post"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "array containing the updated post's id",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Ids"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "this post does not exists"
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"put": {
|
||||
"summary": "Not yet developed Update full blog properties. Unsetted parameters will be erased",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "post-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "properties",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/new_dc_post"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "array containing the updated post's id",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Ids"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "this post does not exists"
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"summary": "Not yet developed Delete the post",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "blog-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "post-id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "array containing the deleted post's id",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Ids"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "this post does not exists"
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"Ids": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "integer",
|
||||
"description": "New blog id"
|
||||
}
|
||||
}
|
||||
},
|
||||
"new_dc_post": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"post_format",
|
||||
"post_status",
|
||||
"post_content",
|
||||
"post_title"
|
||||
],
|
||||
"properties": {
|
||||
"post_title": {
|
||||
"type": "string"
|
||||
},
|
||||
"post_format": {
|
||||
"type": "string",
|
||||
"description": "generally 'xhtml' or 'wiki'. If you put another value, not managed by Dotclear or a plugin, Fill in the post_content_xhtml field."
|
||||
},
|
||||
"post_content": {
|
||||
"type": "string",
|
||||
"description": "The content on WhatYouWant format"
|
||||
},
|
||||
"post_content_xhtml": {
|
||||
"type": "string",
|
||||
"description": "If post_format is wiki or xhtml and not set, It will be generated from post_content"
|
||||
},
|
||||
"post_status": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"Pending",
|
||||
"Scheduled",
|
||||
"Unpublished",
|
||||
"Published"
|
||||
]
|
||||
},
|
||||
"cat_id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"new_cat_title": {
|
||||
"type": "string",
|
||||
"description": "If creating a new category, this is the only required cat_ field. If given cat_id must not be given"
|
||||
},
|
||||
"new_cat_parent_id": {
|
||||
"type": "integer",
|
||||
"description": "Only if new_cat_id is given"
|
||||
},
|
||||
"new_cat_position": {
|
||||
"type": "integer",
|
||||
"description": "the new cat position relative to the brothers (same level) categories"
|
||||
},
|
||||
"new_cat_desc": {
|
||||
"type": "string",
|
||||
"description": "the new category description."
|
||||
},
|
||||
"new_cat_url": {
|
||||
"type": "string",
|
||||
"description": "the new category url"
|
||||
},
|
||||
"post_dt": {
|
||||
"type": "string",
|
||||
"description": "\\'YY-MM-dd hh:mm:ss\\' If not set, Current dateTime will be used."
|
||||
},
|
||||
"post_password": {
|
||||
"type": "string",
|
||||
"description": "Don\\'t set that value if your new post won\\'t be protected"
|
||||
},
|
||||
"post_url": {
|
||||
"type": "string",
|
||||
"description": "If not set, will be created using the date and the post_titlke"
|
||||
},
|
||||
"post_lang": {
|
||||
"type": "string",
|
||||
"description": "If not set, User lang will be used"
|
||||
},
|
||||
"post_excerpt": {
|
||||
"type": "string"
|
||||
},
|
||||
"post_excerpt_xhtml": {
|
||||
"type": "string",
|
||||
"description": "If post_format is wiki or xhtml, It will be generated from post_excerpt"
|
||||
},
|
||||
"post_notes": {
|
||||
"type": "string"
|
||||
},
|
||||
"post_selected": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"post_open_comment": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"post_open_tb": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"post_tags": {
|
||||
"type": "array",
|
||||
"description": "post tags"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dc_post": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"post_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"post_title": {
|
||||
"type": "string"
|
||||
},
|
||||
"post_format": {
|
||||
"type": "string",
|
||||
"description": "generally 'xhtml' or 'wiki'. If you put another value, not managed by Dotclear or a plugin, Fill in the post_content_xhtml field."
|
||||
},
|
||||
"post_content": {
|
||||
"type": "string",
|
||||
"description": "The content on WhatYouWant format"
|
||||
},
|
||||
"post_content_xhtml": {
|
||||
"type": "string",
|
||||
"description": "If post_format is wiki or xhtml and not set, It will be generated from post_content"
|
||||
},
|
||||
"post_status": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"Pending",
|
||||
"Scheduled",
|
||||
"Unpublished",
|
||||
"Published"
|
||||
]
|
||||
},
|
||||
"cat_id": {
|
||||
"type": "integer"
|
||||
},
|
||||
"new_cat_id": {
|
||||
"type": "string",
|
||||
"description": "If creating a new category, this is the only required cat_ field. If given cat_id must not be given"
|
||||
},
|
||||
"new_cat_parent_id": {
|
||||
"type": "integer",
|
||||
"description": "Only if new_cat_id is given"
|
||||
},
|
||||
"new_cat_desc": {
|
||||
"type": "string",
|
||||
"description": "the new category description."
|
||||
},
|
||||
"new_cat_url": {
|
||||
"type": "string",
|
||||
"description": "the new category url"
|
||||
},
|
||||
"post_dt": {
|
||||
"type": "string",
|
||||
"description": "\\'YY-MM-dd hh:mm:ss\\' If not set, Current dateTime will be used."
|
||||
},
|
||||
"post_password": {
|
||||
"type": "string",
|
||||
"description": "Don\\'t set that value if your new post won\\'t be protected"
|
||||
},
|
||||
"post_url": {
|
||||
"type": "string",
|
||||
"description": "If not set, will be created using the date and the post_titlke"
|
||||
},
|
||||
"post_lang": {
|
||||
"type": "string",
|
||||
"description": "If not set, User lang will be used"
|
||||
},
|
||||
"post_excerpt": {
|
||||
"type": "string"
|
||||
},
|
||||
"post_excerpt_xhtml": {
|
||||
"type": "string",
|
||||
"description": "If post_format is wiki or xhtml, It will be generated from post_excerpt"
|
||||
},
|
||||
"post_notes": {
|
||||
"type": "string"
|
||||
},
|
||||
"post_selected": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"post_open_comment": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"post_open_tb": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"post_tags": {
|
||||
"type": "array",
|
||||
"description": "post tags"
|
||||
},
|
||||
"nb_comment": {
|
||||
"type": "integer"
|
||||
},
|
||||
"nb_trackback": {
|
||||
"type": "integer"
|
||||
},
|
||||
"post_firstpub": {
|
||||
"type": "string"
|
||||
},
|
||||
"metas": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"Error": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"fields": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,224 +0,0 @@
|
|||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "Dotclear API",
|
||||
"description": "Manage your(s) blogs with this API",
|
||||
"version": "0.0.2"
|
||||
},
|
||||
"host": "dotclear.localhost",
|
||||
"schemes": [
|
||||
"http"
|
||||
],
|
||||
"basePath": "/dotclear/index.php?rest",
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"paths": {
|
||||
"/{blog_id}/settings": {
|
||||
"get": {
|
||||
"summary": "Get the about:config",
|
||||
"description": "Get all parameters",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "blog_id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
},
|
||||
"404": {
|
||||
"description": "this blog id does not exists"
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/{blog_id}/settings/{name_space}": {
|
||||
"get": {
|
||||
"summary": "Get the settings inside the name-space",
|
||||
"description": "same",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "blog_id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "name_space",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
},
|
||||
"404": {
|
||||
"description": "this blog id does not exists"
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"summary": "Create or edit a new namespace and or a new setting'",
|
||||
"description": "Let body empty if you just want to create a namespace without setting. Note that if the setting already exists, it will be erased. So, PUT and PATCH methods are useless.",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "blog_id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "name_space",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "setting",
|
||||
"description": "Can be empty, Can pass many settings. [{\"id\":\"string\",\"type\":\"string\",\"value\":\"string\",\"value_change\":\"string Optional\",\"global\":\"bool optional\"},{\"id2\":...}]",
|
||||
"in": "body",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/settings"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"201": {
|
||||
"description": "OK"
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/{blog_id}/settings/{name_space}/{setting_id}": {
|
||||
"get": {
|
||||
"summary": "Get value and type for one setting'",
|
||||
"description": "",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "x_dc_key",
|
||||
"in": "header",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "blog_id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "name_space",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"name": "setting_id",
|
||||
"in": "path",
|
||||
"type": "string",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/OneSetting"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"description": "Unexpected error",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"OneSetting": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"ns": {
|
||||
"type": "string"
|
||||
},
|
||||
"value": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string"
|
||||
},
|
||||
"label": {
|
||||
"type": "string"
|
||||
},
|
||||
"global": {
|
||||
"type": "boolean"
|
||||
}
|
||||
}
|
||||
},
|
||||
"settings": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object"
|
||||
}
|
||||
},
|
||||
"Error": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"message": {
|
||||
"type": "string"
|
||||
},
|
||||
"fields": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 445 B |
Binary file not shown.
Before Width: | Height: | Size: 1.1 KiB |
|
@ -1,94 +0,0 @@
|
|||
<?php
|
||||
if (!defined('DC_RC_PATH')) { return; }
|
||||
?><!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Swagger UI</title>
|
||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
|
||||
<link rel="stylesheet" type="text/css" href="index.php?pf=rest/documentation/swagger-ui-dist/swagger-ui.css" >
|
||||
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
|
||||
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
|
||||
<style>
|
||||
html
|
||||
{
|
||||
box-sizing: border-box;
|
||||
overflow: -moz-scrollbars-vertical;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
*,
|
||||
*:before,
|
||||
*:after
|
||||
{
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
body {
|
||||
margin:0;
|
||||
background: #fafafa;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0">
|
||||
<defs>
|
||||
<symbol viewBox="0 0 20 20" id="unlocked">
|
||||
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="locked">
|
||||
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="close">
|
||||
<path d="M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="large-arrow">
|
||||
<path d="M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="large-arrow-down">
|
||||
<path d="M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z"/>
|
||||
</symbol>
|
||||
|
||||
|
||||
<symbol viewBox="0 0 24 24" id="jump-to">
|
||||
<path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 24 24" id="expand">
|
||||
<path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/>
|
||||
</symbol>
|
||||
|
||||
</defs>
|
||||
</svg>
|
||||
|
||||
<div id="swagger-ui"></div>
|
||||
|
||||
<script src="index.php?pf=rest/documentation/swagger-ui-dist/swagger-ui-bundle.js"> </script>
|
||||
<script src="index.php?pf=rest/documentation/swagger-ui-dist/swagger-ui-standalone-preset.js"> </script>
|
||||
<script>
|
||||
window.onload = function() {
|
||||
// Build a system
|
||||
const ui = SwaggerUIBundle({
|
||||
url: "<?php echo $core->blog->url.$core->url->getBase('rest'); ?>/specs",
|
||||
dom_id: '#swagger-ui',
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis,
|
||||
SwaggerUIStandalonePreset
|
||||
],
|
||||
plugins: [
|
||||
SwaggerUIBundle.plugins.DownloadUrl
|
||||
],
|
||||
layout: "StandaloneLayout"
|
||||
})
|
||||
|
||||
window.ui = ui
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -1,53 +0,0 @@
|
|||
<!doctype html>
|
||||
<html lang="en-US">
|
||||
<body onload="run()">
|
||||
</body>
|
||||
</html>
|
||||
<script>
|
||||
'use strict';
|
||||
function run () {
|
||||
var oauth2 = window.opener.swaggerUIRedirectOauth2;
|
||||
var sentState = oauth2.state;
|
||||
var isValid, qp, arr;
|
||||
|
||||
qp = (window.location.hash || location.search).substring(1);
|
||||
|
||||
arr = qp.split("&")
|
||||
arr.forEach(function (v,i,_arr) { _arr[i] = '"' + v.replace('=', '":"') + '"';})
|
||||
qp = qp ? JSON.parse('{' + arr.join() + '}',
|
||||
function (key, value) {
|
||||
return key === "" ? value : decodeURIComponent(value)
|
||||
}
|
||||
) : {}
|
||||
|
||||
isValid = qp.state === sentState
|
||||
|
||||
if (oauth2.auth.schema.get("flow") === "accessCode" && !oauth2.auth.code) {
|
||||
if (!isValid) {
|
||||
oauth2.errCb({
|
||||
authId: oauth2.auth.name,
|
||||
source: "auth",
|
||||
level: "warning",
|
||||
message: "Authorization may be unsafe, passed state was changed in server Passed state wasn't returned from auth server"
|
||||
});
|
||||
}
|
||||
|
||||
if (qp.code) {
|
||||
delete oauth2.state;
|
||||
oauth2.auth.code = qp.code;
|
||||
oauth2.callback(oauth2.auth);
|
||||
} else {
|
||||
oauth2.errCb({
|
||||
authId: oauth2.auth.name,
|
||||
source: "auth",
|
||||
level: "error",
|
||||
message: "Authorization failed: no accessCode received from the server"
|
||||
});
|
||||
}
|
||||
} else {
|
||||
oauth2.callback({auth: oauth2.auth, token: qp, isValid: isValid});
|
||||
}
|
||||
window.close();
|
||||
}
|
||||
|
||||
</script>
|
File diff suppressed because one or more lines are too long
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"swagger-ui-bundle.js","sources":["webpack:///swagger-ui-bundle.js"],"mappings":"AAAA;AAu/FA;AA6+FA;;;;;;;;;;;;;;;;;;;;;;;;;;AAoTA;;;;;;AAoIA;AAi7FA;AAmtCA;AAi0IA;AA2pJA;AA+uFA;AA2rGA;AAgiFA;AA0rFA;AAk9CA;AA2hDA;AA4rCA;AAi6EA;;;;;AA2gCA;AA02JA;;;;;;;;;;;;;;AAuyEA;AA4mIA;AAquJA;AAwsHA;AA2mGA;AAiiEA;AAq4DA;AA+2DA;AAqlBA;;;;;;AAilFA;AAs1FA;;;;;AAy3CA;AA2qFA;AAw2CA;AAwkCA;AAs/CA;AA4kFA;AAy1FA;;;;;;;;;AAm5CA;AA2zIA;AAk4DA;AAolDA","sourceRoot":""}
|
File diff suppressed because one or more lines are too long
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"swagger-ui-standalone-preset.js","sources":["webpack:///swagger-ui-standalone-preset.js"],"mappings":"AAAA;;;;;AA4QA;AAitGA","sourceRoot":""}
|
File diff suppressed because one or more lines are too long
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"swagger-ui.css","sources":[],"mappings":"","sourceRoot":""}
|
File diff suppressed because one or more lines are too long
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"swagger-ui.js","sources":["webpack:///swagger-ui.js"],"mappings":"AAAA;;;;;;AAyxCA;AAoyHA;AAuxHA;AAy4FA;AA2sCA;AAmgCA;AA0iCA;AA+3BA","sourceRoot":""}
|
|
@ -1,12 +0,0 @@
|
|||
<?php
|
||||
class restDcNameSpace extends dcNamespace
|
||||
{
|
||||
//this function is private on the parent class
|
||||
public function settingExists($id,$global=false)
|
||||
{
|
||||
$array = $global ? 'global' : 'local';
|
||||
return isset($this->{$array.'_settings'}[$id]);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
<?php
|
||||
|
||||
class restAuth extends dcAuth
|
||||
{
|
||||
# L'utilisateur n'a pas le droit de changer son mot de passe
|
||||
protected $allow_pass_change = false;
|
||||
|
||||
/**
|
||||
* Méthode de vérification de la clef d'api_key
|
||||
* Remplace la méthode chekUser (id: password)
|
||||
* Only use $user_key (all others parameters are for compatibility with the parent function)
|
||||
* input: $user_key STRING
|
||||
* output: boolean
|
||||
*/
|
||||
|
||||
public function checkUser($user_id, $pwd = NULL, $user_key = NULL, $check_blog = true)
|
||||
{
|
||||
|
||||
global $core;
|
||||
|
||||
$hashedKey = $core->auth->crypt($user_key);
|
||||
//Check for the user api key
|
||||
$sqlStr = " SELECT setting_id
|
||||
FROM dc_setting
|
||||
WHERE setting_ns='rest'
|
||||
AND setting_id LIKE 'rest_key_%'
|
||||
AND setting_value = '".$core->con->escape($hashedKey)."';";
|
||||
|
||||
try {
|
||||
$rs = $core->con->select($sqlStr);
|
||||
} catch (Exception $e) {
|
||||
$err = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($rs->isEmpty()) {
|
||||
sleep(rand(2,5));
|
||||
return false;
|
||||
}
|
||||
|
||||
//get the user ID from the previous query
|
||||
$userId = explode("_", $rs->setting_id)[2];
|
||||
|
||||
//get USER infos
|
||||
|
||||
$strReq = 'SELECT user_id, user_super, user_pwd, user_change_pwd, '.
|
||||
'user_name, user_firstname, user_displayname, user_email, '.
|
||||
'user_url, user_default_blog, user_options, '.
|
||||
'user_lang, user_tz, user_post_status, user_creadt, user_upddt '.
|
||||
'FROM '.$core->con->escapeSystem($this->user_table).' '.
|
||||
"WHERE user_id = '".$core->con->escape($userId)."'";
|
||||
|
||||
try {
|
||||
$rs = $core->con->select($strReq);
|
||||
} catch (Exception $e) {
|
||||
$err = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($rs->isEmpty()) {
|
||||
sleep(rand(2,5));
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->user_id = $rs->user_id;
|
||||
$this->user_change_pwd = (boolean) $rs->user_change_pwd;
|
||||
$this->user_admin = (boolean) $rs->user_super;
|
||||
$this->user_info['user_pwd'] = $rs->user_pwd;
|
||||
$this->user_info['user_name'] = $rs->user_name;
|
||||
$this->user_info['user_firstname'] = $rs->user_firstname;
|
||||
$this->user_info['user_displayname'] = $rs->user_displayname;
|
||||
$this->user_info['user_email'] = $rs->user_email;
|
||||
$this->user_info['user_url'] = $rs->user_url;
|
||||
$this->user_info['user_default_blog'] = $rs->user_default_blog;
|
||||
$this->user_info['user_lang'] = $rs->user_lang;
|
||||
$this->user_info['user_tz'] = $rs->user_tz;
|
||||
$this->user_info['user_post_status'] = $rs->user_post_status;
|
||||
$this->user_info['user_creadt'] = $rs->user_creadt;
|
||||
$this->user_info['user_upddt'] = $rs->user_upddt;
|
||||
$this->user_info['user_cn'] = dcUtils::getUserCN($rs->user_id, $rs->user_name,
|
||||
$rs->user_firstname, $rs->user_displayname);
|
||||
|
||||
//$this->user_options = array_merge($this->core->userDefaults(),$rs->options());
|
||||
$this->user_prefs = new dcPrefs($this->core,$this->user_id);
|
||||
return true;
|
||||
}
|
||||
|
||||
//return user permission for all blogs
|
||||
//[blog_id] => permission
|
||||
public function getAllPermissions()
|
||||
{
|
||||
global $core;
|
||||
|
||||
//conserve the value
|
||||
static $blogs = false;
|
||||
|
||||
if($blogs !== false){
|
||||
return $blogs;
|
||||
}
|
||||
|
||||
|
||||
if ($this->user_admin) { //user_admin == super admin
|
||||
$strReq = 'SELECT blog_id '.
|
||||
'from '.$this->blog_table;
|
||||
$rs = $core->con->select($strReq);
|
||||
while ($rs->fetch())
|
||||
{
|
||||
$blogs[$rs->blog_id] = 'admin';
|
||||
}
|
||||
return $blogs;
|
||||
}
|
||||
$strReq = 'SELECT blog_id, permissions '.
|
||||
'FROM '.$this->perm_table.' '.
|
||||
"WHERE user_id = '".$this->con->escape($this->user_id)."' ".
|
||||
"AND (permissions LIKE '%|usage|%' OR permissions LIKE '%|admin|%' OR permissions LIKE '%|contentadmin|%') ";
|
||||
|
||||
$rs = $this->con->select($strReq);
|
||||
while ($rs->fetch()){
|
||||
$blogs[$rs->blog_id] = $this->parsePermissions($rs->permissions);
|
||||
}
|
||||
return $blogs;
|
||||
}
|
||||
}
|
|
@ -1,817 +0,0 @@
|
|||
<?php
|
||||
|
||||
class RestCategories
|
||||
{
|
||||
/*
|
||||
* Don't expose Nested tree algorithm via the API
|
||||
* First goal of this class is to convert structure id|left|right
|
||||
* to - a less optimized but simpliest - way of use id|parent_id|position
|
||||
*/
|
||||
|
||||
/*
|
||||
* base structure is
|
||||
mysql> describe dc_category;
|
||||
+--------------+--------------+------+-----+---------+-------+
|
||||
| Field | Type | Null | Key | Default | Extra |
|
||||
+--------------+--------------+------+-----+---------+-------+
|
||||
| cat_id | bigint(20) | NO | PRI | NULL | |
|
||||
| blog_id | varchar(32) | NO | MUL | NULL | |
|
||||
| cat_title | varchar(255) | NO | | NULL | |
|
||||
| cat_url | varchar(255) | NO | MUL | NULL | |
|
||||
| cat_desc | longtext | YES | | NULL | |
|
||||
| cat_position | int(11) | YES | | 0 Unused (by dotclear) field
|
||||
| cat_lft | int(11) | YES | | NULL | |
|
||||
| cat_rgt | int(11) | YES | | NULL | |
|
||||
+--------------+--------------+------+-----+---------+-------+
|
||||
8 rows in set (0.00 sec)
|
||||
*/
|
||||
|
||||
public $cats; //Array structured like:
|
||||
|
||||
/* [
|
||||
{
|
||||
"cat_id": 4,
|
||||
"cat_title": "trololo",
|
||||
"cat_url": "trololo",
|
||||
"cat_desc": "",
|
||||
"cat_level": 0,
|
||||
"cat_parent_id": null,
|
||||
"cat_position": 0
|
||||
},
|
||||
{
|
||||
"cat_id": 6,
|
||||
"cat_title": "child",
|
||||
"cat_url": "trololo/child",
|
||||
"cat_desc": "",
|
||||
"cat_level": 1,
|
||||
"cat_parent_id": 4,
|
||||
"cat_position": 0
|
||||
},
|
||||
*/
|
||||
protected $catsLftRgt;
|
||||
protected $blog_id;
|
||||
protected $core;
|
||||
protected $table;
|
||||
protected $con;
|
||||
|
||||
|
||||
protected function getNextInsertCatId(){
|
||||
$sql = "SELECT max(cat_id) as nextId FROM ".$this->table." ;";
|
||||
$rs = $this->con->select($sql);
|
||||
$rs->fetch();
|
||||
return (int)($rs->nextId) +1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* build part of url like
|
||||
* parent/sub/category
|
||||
*/
|
||||
protected function generateCatUrl($title,$cat_lft){
|
||||
|
||||
//Select all parents
|
||||
$sql = "SELECT cat_title
|
||||
FROM " .$this->table . "
|
||||
WHERE blog_id='". $this->con->escape($this->blog_id) . "'
|
||||
AND cat_lft < '" . $cat_lft ."'
|
||||
AND cat_rgt > '" . $cat_lft ."'
|
||||
ORDER BY cat_lft ASC";
|
||||
|
||||
$rs = $this->con->select($sql);
|
||||
$urlParts =array();
|
||||
while($rs->fetch()){
|
||||
$urlParts[] = text::tidyURL($rs->cat_title,false);
|
||||
}
|
||||
$urlParts[] = text::tidyURL($title);
|
||||
return implode("/",$urlParts);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* $params keys can be:
|
||||
* 'cat_title','cat_url','cat_desc',
|
||||
* 'cat_parent_id','cat_position','temporary'
|
||||
*/
|
||||
public function updateCategory($cat_id,$params){
|
||||
$valuesToChange = array();
|
||||
if(isset($params['cat_title'])){
|
||||
$valuesToChange[] = "cat_title = '". $this->con->escape($params['cat_title']) . "'";
|
||||
}
|
||||
if(isset($params['cat_url'])){
|
||||
$valuesToChange[] = "cat_url = '". $this->con->escape($params['cat_url']). "'";
|
||||
}
|
||||
if(isset($params['cat_desc'])){
|
||||
$valuesToChange[] = "cat_desc = '". $this->con->escape($params['cat_desc']). "'";
|
||||
}
|
||||
|
||||
if(count($valuesToChange) > 0){
|
||||
//do the update
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET ".implode(",",$valuesToChange)."
|
||||
WHERE blog_id='". $this->con->escape($this->blog_id) . "'
|
||||
AND cat_id= '". $this->con->escape($cat_id)."';";
|
||||
$this->con->execute($sql);
|
||||
}
|
||||
|
||||
if(
|
||||
(isset($params['cat_position']))
|
||||
OR (isset($params['cat_parent_id']))
|
||||
){
|
||||
//changement de position
|
||||
$cat_position = (isset($params['cat_position']))? $params['cat_position'] : null;
|
||||
$cat_parent_id = (isset($params['cat_parent_id']))? $params['cat_parent_id'] : null;
|
||||
$permute=(isset($params['permute']))? $params['permute']:false;
|
||||
$this->changePosition($cat_id,$cat_parent_id,$cat_position,$permute);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* return the actual cat_left for a parent and a position given
|
||||
* If cat is a top level one. set $parent to null
|
||||
* in position doesn't exists the last position will be returned
|
||||
* IN $parent_id: integer, $position: integer
|
||||
* OUT: integer
|
||||
*/
|
||||
protected function getCatLeft($parent_id,$position){
|
||||
|
||||
if((is_null($parent_id)) && (is_null($position))){
|
||||
//on met la categorie après la dernière position
|
||||
$sql = "SELECT max(cat_rgt) AS max FROM ".$this->table."
|
||||
WHERE blog_id='". $this->con->escape($this->blog_id) . "';";
|
||||
$rs = $this->con->select($sql);
|
||||
if($rs->max == null){
|
||||
return 1; //it's the first category, there's no other
|
||||
}else{
|
||||
return $rs->max + 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(!is_null($position)){
|
||||
foreach($this->catsLftRgt as $cat){
|
||||
if(($cat['cat_parent_id'] == $parent_id)
|
||||
&&($cat['cat_position'] == $position)){
|
||||
return $cat['cat_lft'];
|
||||
}
|
||||
}
|
||||
}
|
||||
//position not found return the parent cat_rgt
|
||||
$sql = "SELECT cat_rgt FROM ".$this->table."
|
||||
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
|
||||
AND cat_id='". $this->con->escape($parent_id)."';";
|
||||
|
||||
$rs = $this->con->select($sql);
|
||||
if(!$rs->cat_rgt){
|
||||
//ce cas ne devrait jamais se produire
|
||||
error_log("something wrong on RestCategories::getCatLeft ".$parent_id."|".$position);
|
||||
return false;
|
||||
}else{
|
||||
return $rs->cat_rgt;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* permute two categories positions
|
||||
*/
|
||||
public function permutePosition($cat1_id,$cat2_id){
|
||||
$twoCats = array();
|
||||
foreach($this->calsLftRgt as $cat){
|
||||
if(($cat['cat_id'] == $cat1_id)
|
||||
||($cat['cat_id'] == $cat2_id))
|
||||
{
|
||||
$twoCats[] = $cat;
|
||||
}
|
||||
}
|
||||
if(count($twoCats) <> 2){
|
||||
//At least one of the two cats was not found
|
||||
return false;
|
||||
}
|
||||
|
||||
if($twoCats[0]['cat_lft'] > $twoCats[1]['cat_lft']){
|
||||
//inverser l'ordre
|
||||
$twoCats[2] = $twoCats[0];
|
||||
$twoCats[0] = $twoCats[1];
|
||||
$twoCats[1] = $twoCats[2];
|
||||
unset($twoCats[2]);
|
||||
}
|
||||
try{
|
||||
$this->con->begin();
|
||||
|
||||
//grow or reduce cat1 parents, if not the sames
|
||||
if($twoCats[0]['cat_parent_id'] <> $twoCats[1]['cat_parent_id']){
|
||||
|
||||
$dif = $twoCats[1]['cat_rgt'] - $twoCats[1]['cat_lft']
|
||||
- $twoCats[0]['cat_rgt'] + $twoCats[0]['cat_lft'];
|
||||
if($dif > 0){
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_rgt = cat_rgt + ".$dif."
|
||||
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
|
||||
AND cat_lft < ".$twoCats[0]['cat_lft']."
|
||||
AND cat_rgt > ".$twoCats[0]['cat_lft'].";";
|
||||
$this->con->execute($sql);
|
||||
}elseif($dif < 0){
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_rgt = cat_rgt - ".abs($dif)."
|
||||
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
|
||||
AND cat_lft < ".$twoCats[0]['cat_lft']."
|
||||
AND cat_rgt > ".$twoCats[0]['cat_lft'].";";
|
||||
$this->con->execute($sql);
|
||||
|
||||
}else{
|
||||
//dif == 0 do nothing
|
||||
}
|
||||
}
|
||||
|
||||
//shift cat
|
||||
if($dif > 0){
|
||||
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_lft = cat_lft + ".$dif.",
|
||||
cat_rgt = cat_rgt + ".$dif."
|
||||
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
|
||||
AND cat_lft > ".$twoCats[0]['cat_lft'].";";
|
||||
$this->con->execute($sql);
|
||||
|
||||
}elseif($dif < 0){
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_lft = cat_lft + ".$dif.",
|
||||
cat_rgt = cat_rgt + ".$dif."
|
||||
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
|
||||
AND cat_lft > ".$twoCats[0]['cat_lft'].";";
|
||||
$this->con->execute($sql);
|
||||
}else{
|
||||
//dif == 0 do nothing
|
||||
}
|
||||
|
||||
//mémoriser le nouveau cat_lft de la cat 2
|
||||
$sql = "SELECT cat_lft,cat_rgt FROM ".$this->table."
|
||||
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
|
||||
AND cat_id='".$this->con->escape($cat2_id)."'";
|
||||
$rs = $this->con->select($sql);
|
||||
$rs->fetch();
|
||||
$cat2_cat_lft = $rs->cat_lft;
|
||||
$cat2_cat_rgt = $rs->cat_rgt;
|
||||
|
||||
//déplacer la cat 2
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_lft=".$twoCats[0]['cat_lft'].",
|
||||
cat_rgt=". (int)($twoCats[0]['cat_lft'] + $twoCats[1]['cat_rgt'] - $twoCats[1]['cat_lft'])."
|
||||
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
|
||||
AND cat_id='".$this->con->escape($cat2_id)."'";
|
||||
$this->con->execute($sql);
|
||||
|
||||
//faire la place autour
|
||||
//grow parents
|
||||
//grow or reduce cat2 parents, if not the sames
|
||||
if($twoCats[0]['cat_parent_id'] <> $twoCats[1]['cat_parent_id']){
|
||||
|
||||
$dif = $twoCats[0]['cat_rgt'] - $twoCats[0]['cat_lft']
|
||||
- $twoCats[1]['cat_rgt'] + $twoCats[1]['cat_lft'];
|
||||
if($dif > 0){
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_rgt = cat_rgt + ".$dif."
|
||||
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
|
||||
AND cat_lft < ".$cat2_cat_lft."
|
||||
AND cat_rgt > ".$cat2_cat_lft.";";
|
||||
$this->con->execute($sql);
|
||||
}elseif($dif < 0){
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_rgt = cat_rgt - ".abs($dif)."
|
||||
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
|
||||
AND cat_lft < ".$cat2_cat_lft."
|
||||
AND cat_rgt > ".$cat2_cat_lft.";";
|
||||
$this->con->execute($sql);
|
||||
|
||||
}else{
|
||||
//dif == 0 do nothing
|
||||
}
|
||||
}
|
||||
//décaler
|
||||
if($dif > 0){
|
||||
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_lft = cat_lft + ".$dif.",
|
||||
cat_rgt = cat_rgt + ".$dif."
|
||||
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
|
||||
AND cat_lft > ".$cat2_cat_lft.";";
|
||||
$this->con->execute($sql);
|
||||
|
||||
}elseif($dif < 0){
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_lft = cat_lft + ".$dif.",
|
||||
cat_rgt = cat_rgt + ".$dif."
|
||||
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
|
||||
AND cat_lft > ".$cat2_cat_lft.";";
|
||||
$this->con->execute($sql);
|
||||
}else{
|
||||
//dif == 0 do nothing
|
||||
}
|
||||
//move cat 2
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_lft=".$cat2_cat_lft.",
|
||||
cat_rgt=". (int)($cat2_cat_lft + $twoCats[0]['cat_rgt'] - $twoCats[0]['cat_lft'])."
|
||||
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
|
||||
AND cat_id='".$this->con->escape($cat2_id)."'";
|
||||
$this->con->execute($sql);
|
||||
$this->con->commit();
|
||||
}catch (Exception $e) {
|
||||
$this->con->rollback();
|
||||
error_log($e);
|
||||
return false;
|
||||
}
|
||||
|
||||
//refresh the array after changes
|
||||
$this->__construct($this->core);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Change the categorie position
|
||||
* Facultative: $permute -> will permute position with an existing category
|
||||
* else shift if needed brother categories
|
||||
*/
|
||||
public function changePosition($cat_id, $new_parent_id, $new_cat_position, $permute = false){
|
||||
if($permute){
|
||||
//find the cat_id
|
||||
|
||||
|
||||
return $this->permute($cat_id, $new_parent_id, $new_cat_position);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$this->con->begin();
|
||||
$currentCatKey = array_search($cat_id, array_column($this->catsLftRgt, 'cat_id'));
|
||||
if(!$currentCatKey){
|
||||
return false;
|
||||
}
|
||||
$currentCat = $this->catsLftRgt[$currentCatKey];
|
||||
$currentCatWidth = $currentCat['cat_rgt'] - $currentCat['cat_lft'] + 1;
|
||||
|
||||
if($new_parent_id == null){
|
||||
$new_parent_id = $currentCat["cat_parent_id"];
|
||||
}
|
||||
|
||||
if($new_parent_id !== null){
|
||||
$parentCatKey = array_search($new_parent_id, array_column($this->catsLftRgt, 'cat_id'));
|
||||
$parentCat = $this->catsLftRgt[$parentCatKey];
|
||||
}
|
||||
|
||||
//find the future cat_lft
|
||||
$new_cat_left = $this->getCatLeft($new_parent_id,$new_cat_position);
|
||||
|
||||
//reduce actuals parents
|
||||
if(!is_null($currentCat['cat_parent_id'])){
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_rgt = cat_rgt - ".$currentCatWidth."
|
||||
WHERE blog_id='". $this->con->escape($this->blog_id) . "'
|
||||
AND cat_lft < ".$currentCat['cat_lft']."
|
||||
AND cat_rgt > ".$currentCat['cat_lft'].";";
|
||||
$this->con->execute($sql);
|
||||
}
|
||||
|
||||
//shift all
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_lft = cat_lft - ".$currentCatWidth.",
|
||||
cat_rgt = cat_rgt - ".$currentCatWidth."
|
||||
WHERE blog_id='". $this->con->escape($this->blog_id) . "'
|
||||
AND cat_lft > " . $currentCat['cat_lft'].";";
|
||||
$this->con->execute($sql);
|
||||
|
||||
//augmenter les nouveaux parents
|
||||
if(!is_null($new_parent_id)){
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_rgt = cat_rgt + ".$currentCatWidth."
|
||||
WHERE blog_id='". $this->con->escape($this->blog_id) . "'
|
||||
AND cat_lft < ".$new_cat_left."
|
||||
AND cat_rgt > ".$new_cat_left.";";
|
||||
$this->con->execute($sql);
|
||||
}
|
||||
|
||||
//tout décaler again
|
||||
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_lft = cat_lft + ".$currentCatWidth.",
|
||||
cat_rgt = cat_rgt + ".$currentCatWidth."
|
||||
WHERE blog_id='". $this->con->escape($this->blog_id) . "'
|
||||
AND cat_lft >= ".$new_cat_left.";";
|
||||
$this->con->execute($sql);
|
||||
|
||||
//enregistrer les nouveaux cat_lft et cat_rgt
|
||||
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_lft ='".$new_cat_left."',
|
||||
cat_rgt ='". ($new_cat_left + $currentCatWidth -1) . "'
|
||||
WHERE blog_id='". $this->con->escape($this->blog_id) . "'
|
||||
AND cat_id='".$currentCat['cat_id']."';";
|
||||
$this->con->execute($sql);
|
||||
|
||||
$this->con->commit();
|
||||
//refresh the array after changes
|
||||
$this->__construct($this->core);
|
||||
return true;
|
||||
}catch (Exception $e) {
|
||||
$this->con->rollback();
|
||||
error_log($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function addCategory($params){
|
||||
// /!\ cat_id is cat_title
|
||||
if(!isset($params['cat_title'])){ //the only mandatory field
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->con->writeLock($this->table);
|
||||
try
|
||||
{
|
||||
|
||||
if(isset($params['cat_position'])){
|
||||
$cat_position = $params['cat_position'];
|
||||
}else{
|
||||
$cat_position = null;
|
||||
}
|
||||
if(isset($params['cat_parent_id'])){
|
||||
$cat_parent_id = $params['cat_parent_id'];
|
||||
//tester s'il existe
|
||||
if($this->getCatProperties($cat_parent_id) === false){
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
$cat_parent_id = null;
|
||||
}
|
||||
$cat_lft = $this->getCatLeft($cat_parent_id,$cat_position);
|
||||
|
||||
//add +2 on parents cat-rgt to grown them
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_rgt = cat_rgt + 2
|
||||
WHERE blog_id='". $this->con->escape($this->blog_id) . "'
|
||||
AND cat_lft < '" . $cat_lft . "'
|
||||
AND cat_rgt >= '" . $cat_lft . "';";
|
||||
|
||||
$this->con->execute($sql);
|
||||
|
||||
//Add +2 on cat_lft and cat_rgt when cat_lft is > in order to shift cats
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_rgt = cat_rgt + 2,
|
||||
cat_lft = cat_lft + 2
|
||||
WHERE blog_id='". $this->con->escape($this->blog_id) . "'
|
||||
AND cat_lft >= '" . $cat_lft . "';";
|
||||
$this->con->execute($sql);
|
||||
|
||||
//Let's insert the new catégorie:
|
||||
if(empty($params['cat_url'])){
|
||||
$new_cat_url = $this->generateCatUrl($params['cat_title'], $cat_lft);
|
||||
}else{
|
||||
$new_cat_url = $params['cat_url'];
|
||||
}
|
||||
|
||||
$new_cat_id = $this->getNextInsertCatId();
|
||||
$cur = $this->con->openCursor($this->core->prefix.'category');
|
||||
$cur->cat_id = $this->getNextInsertCatId();
|
||||
$cur->blog_id = $this->con->escape($this->blog_id);
|
||||
$cur->cat_title = $params['cat_title'];
|
||||
$cur->cat_url = $new_cat_url;
|
||||
if(isset($params['cat_desc'])){
|
||||
$cur->cat_desc = $params['cat_desc'];
|
||||
}else{
|
||||
$cur->cat_desc = "";
|
||||
}
|
||||
$cur->cat_lft = $cat_lft;
|
||||
$cur->cat_rgt = $cat_lft + 1;
|
||||
|
||||
$this->core->callBehavior('coreBeforeCategoryCreate',$this->core,$cur);
|
||||
|
||||
if($cur->insert()){
|
||||
$this->con->unlock();
|
||||
|
||||
$this->core->callBehavior('coreAfterCategoryCreate',$this->core,$cur);
|
||||
|
||||
return $new_cat_id;
|
||||
}else{
|
||||
$this->con->unlock();
|
||||
//refresh the array after changes
|
||||
$this->__construct($this->core);
|
||||
return false;
|
||||
}
|
||||
}catch (Exception $e) {
|
||||
$this->con->unlock();
|
||||
error_log($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Return filtered categories
|
||||
*/
|
||||
public function getCats($filters){
|
||||
$cats = array();
|
||||
foreach($this->cats as $cat){
|
||||
$ok = true;
|
||||
foreach($filters as $key => $value){
|
||||
if($value !== $cat[$key]){
|
||||
$ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($ok){
|
||||
$cats[] = $cat;
|
||||
}
|
||||
}
|
||||
return $cats;
|
||||
}
|
||||
public function getCatProperties($cat_id){
|
||||
foreach($this->cats as $cat){
|
||||
if($cat['cat_id'] == $cat_id){
|
||||
return $cat;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function moveChilds($cat_from_id,$cat_dest_id,$deleteOriginCat = false)
|
||||
{
|
||||
|
||||
//$cat_from ne doit pas être null
|
||||
if(is_null($cat_from_id)){
|
||||
return false;
|
||||
}
|
||||
|
||||
//Si cat_dest_id est null, l'user veut transformer les enfants en categories de premier niveau
|
||||
if(is_null($cat_dest_id)){
|
||||
//to do
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$sql = "SELECT cat_lft,cat_rgt
|
||||
FROM ".$this->table."
|
||||
WHERE blog_id='".$this->con->escape($this->blog_id)."'
|
||||
AND cat_id='".$this->con->escape($this->$cat_from_id)."';";
|
||||
$rs = $this->con->execute($sql);
|
||||
$rs->fetch();
|
||||
$origin_cat_lft = $rs->cat_lft;
|
||||
$origin_cat_rgt = $rs->cat_rgt;
|
||||
|
||||
$sql = "SELECT cat_lft,cat_rgt
|
||||
FROM ".$this->table."
|
||||
WHERE blog_id='".$this->con->escape($this->blog_id)."'
|
||||
AND cat_id='".$this->con->escape($this->$cat_dest_id)."';";
|
||||
$rs = $this->con->execute($sql);
|
||||
$rs->fetch();
|
||||
$dest_cat_lft = $rs->cat_lft;
|
||||
$dest_cat_rgt = $rs->cat_rgt;
|
||||
|
||||
//la categorie de destination ne peut pas être un enfant de celle d'origine
|
||||
if(($origin_cat_lft < $dest_cat_lft) && ($origin_cat_rgt < $dest_cat_lft)){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$this->con->begin();
|
||||
try{
|
||||
//agrandir la categorie de destination
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_rgt = cat_rgt + ".(int)( $origin_cat_rgt - $origin_cat_lft )."
|
||||
WHERE blog_id='".$this->con->escape($this->blog_id)."'
|
||||
AND cat_id='".$this->con->escape($this->$cat_dest_id)."';";
|
||||
$this->con->execute($sql);
|
||||
|
||||
//déplacer tout ce qui doit l'être suite à cet aggrandissement
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_lft = cat_lft + ".(int)( $origin_cat_rgt - $origin_cat_lft )."
|
||||
cat_rgt = cat_rgt + ".(int)( $origin_cat_rgt - $origin_cat_lft )."
|
||||
WHERE blog_id='".$this->con->escape($this->blog_id)."'
|
||||
AND cat_lft >".$dest_cat_rgt.";";
|
||||
$this->con->execute($sql);
|
||||
|
||||
//si la categorie d'origine était après, elle vient d'etre déplacée
|
||||
//mettre à jour sa position
|
||||
if($origin_cat_lft > $dest_cat_lft){
|
||||
$of= $origin_cat_lft;
|
||||
$origin_cat_lft = $origin_cat_rgt;
|
||||
$origin_cat_rgt = $origin_cat_rgt + $origin_cat_rgt - $of;
|
||||
}
|
||||
|
||||
//déplacer les categories enfants
|
||||
|
||||
if($dest_cat_rgt > $origin_cat_lft){
|
||||
//addition
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_lft = cat_lft + ".(int)($dest_cat_rgt - $origin_cat_lft).",
|
||||
cat_rgt = cat_rgt + ".(int)($dest_cat_rgt - $origin_cat_lft)."
|
||||
WHERE blog_id='".$this->con->escape($this->blog_id)."'
|
||||
AND cat_lft BETWEEN ".$origin_cat_lft." AND ".$origin_cat_rgt.";";
|
||||
$this->con->execute($sql);
|
||||
|
||||
}else{
|
||||
//soustraction
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_lft = cat_lft - ".(int)($origin_cat_lft - $dest_cat_rgt).",
|
||||
cat_rgt = cat_rgt + ".(int)($origin_cat_lft - $dest_cat_rgt)."
|
||||
WHERE blog_id='".$this->con->escape($this->blog_id)."'
|
||||
AND cat_lft BETWEEN ".$origin_cat_lft." AND ".$origin_cat_rgt.";";
|
||||
$this->con->execute($sql);
|
||||
}
|
||||
|
||||
$dest_cat_rgt = $dest_cat_rgt + $origin_cat_rgt - $origin_cat_lft;
|
||||
|
||||
if($deleteOriginCat){
|
||||
$sql = "DELETE FROM ".$this->table."
|
||||
WHERE blog_id='".$this->con->escape($this->blog_id)."'
|
||||
AND cat_id='".$this->con->escape($this->$cat_from_id)."';";
|
||||
$this->con->execute($sql);
|
||||
$unShiftSteps = $origin_cat_rgt - $origin_cat_rgt + 1;
|
||||
|
||||
}else{
|
||||
//reduire la cat d'origine
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_rgt= cat_lft + 1
|
||||
WHERE blog_id='".$this->con->escape($this->blog_id)."'
|
||||
AND cat_id='".$this->con->escape($this->$cat_from_id)."';";
|
||||
$this->con->execute($sql);
|
||||
$unShiftSteps = $origin_cat_rgt - $origin_cat_rgt - 1;
|
||||
}
|
||||
//Décaller
|
||||
$sql = "UPDATE ".$this->table."
|
||||
SET cat_lft = cat_lft - ". $unShiftSteps .",
|
||||
cat_rgt = cat_rgt - ". $unShiftSteps ."
|
||||
WHERE blog_id='".$this->con->escape($this->blog_id)."'
|
||||
AND cat_lft > ".$origin_cat_lft.";";
|
||||
$this->con->execute($sql);
|
||||
|
||||
$this->con->commit();
|
||||
}catch (Exception $e) {
|
||||
$this->con->rollback();
|
||||
error_log($e);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function getCatLftRgt($cat_id){
|
||||
foreach($this->catsLftRgt as $cat){
|
||||
if($cat['cat_id'] == $cat_id){
|
||||
return $cat;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
* Delete the given category
|
||||
* And reorganize the orders of the categories
|
||||
* /!\ this function does not care about chields posts
|
||||
*/
|
||||
public function deleteCategory($cat_id,$deleteSubs = false)
|
||||
{
|
||||
$this->con->begin();
|
||||
try{
|
||||
if($deleteSubs){
|
||||
//delete subs cats
|
||||
$sql = "DELETE subs.* FROM
|
||||
".$this->table." AS subs,
|
||||
".$this->table." AS parent
|
||||
WHERE subs.blog_id='".$this->con->escape($this->blog_id)."'
|
||||
AND parent.cat_id='".$this->con->escape($cat_id)."'
|
||||
AND subs.cat_lft BETWEEN parent.cat_lft AND parent.cat_rgt;";
|
||||
$this->con->execute($sql);
|
||||
//unshift followin cats before delete it
|
||||
$sql = "UPDATE
|
||||
".$this->table." followings,
|
||||
".$this->table." parent
|
||||
SET
|
||||
followings.cat_lft = followings.cat_lft - parent.cat_lft - 1,
|
||||
followings.cat_rgt = followings.cat_rgt - parent.cat_lft - 1
|
||||
WHERE
|
||||
followings.blog_id='".$this->con->escape($this->blog_id)."'
|
||||
AND parent.cat_id='".$this->con->escape($cat_id)."'
|
||||
AND followings.cat_lft > parent.cat_lft;";
|
||||
$this->con->execute($sql);
|
||||
}else{
|
||||
//chields cats will be upped
|
||||
//unshift cats
|
||||
$sql = "UPDATE
|
||||
".$this->table." cats,
|
||||
".$this->table." parent
|
||||
SET
|
||||
cats.cat_lft = CASE WHEN cats.cat_lft BETWEEN parent.cat_lft AND parent.cat_rgt THEN cats.cat_lft - 1
|
||||
WHEN cats.cat_lft > parent.cat_rgt THEN cats.cat_lft - 2
|
||||
ELSE cats.cat_lft
|
||||
END,
|
||||
cats.cat_rgt = CASE WHEN cats.cat_lft BETWEEN parent.cat_lft AND parent.cat_rgt THEN cats.cat_rgt - 1
|
||||
WHEN cats.cat_lft > parent.cat_rgt THEN cats.cat_rgt - 2
|
||||
ELSE cats.cat_rgt
|
||||
END
|
||||
WHERE
|
||||
cats.blog_id='".$this->con->escape($this->blog_id)."'
|
||||
AND parent.cat_id='".$this->con->escape($cat_id)."'
|
||||
AND cats.cat_lft > parent.cat_lft;";
|
||||
|
||||
$this->con->execute($sql);
|
||||
}
|
||||
//simply del the cat
|
||||
$sql = "
|
||||
DELETE FROM ".$this->table."
|
||||
WHERE blog_id='" . $this->con->escape($this->blog_id) . "'
|
||||
AND cat_id='". $this->con->escape($cat_id)."';";
|
||||
$this->con->execute($sql);
|
||||
$this->con->commit();
|
||||
return true;
|
||||
|
||||
}catch (Exception $e) {
|
||||
$this->con->rollback();
|
||||
error_log($e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public function cat_titleExists($cat_title){
|
||||
foreach($this->cats as $cat){
|
||||
if($cat['cat_title'] == $cat_title){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
public function __construct($core)
|
||||
{
|
||||
/*
|
||||
* Create all the categories tree on an array
|
||||
*/
|
||||
$this->core =& $core;
|
||||
$this->con =& $core->con;
|
||||
$this->blog_id = $core->blog->id;
|
||||
$this->table = $core->prefix.'category';
|
||||
$this->add_condition = array('blog_id' => "'".$this->con->escape($this->blog_id)."'");
|
||||
|
||||
//all categories on an array
|
||||
|
||||
$sql = "SELECT
|
||||
cat_id, cat_title, cat_url, cat_desc, cat_lft, cat_rgt
|
||||
FROM ".$this->table."
|
||||
WHERE blog_id='".$this->blog_id."'
|
||||
ORDER BY cat_lft ASC;";
|
||||
|
||||
//The ORDER BY on the left property, make the returned rows are on the good order,
|
||||
//But we still have to calculate their level and position
|
||||
|
||||
$rs = $this->con->select($sql);
|
||||
$cats = array();
|
||||
$catsLftRgt = array();
|
||||
$index = 0;
|
||||
$nbeCatsLevel0 = 0;
|
||||
|
||||
while($rs->fetch()){
|
||||
$betterParentLevel = -1;
|
||||
$betterParentId = -1;
|
||||
$countPrevious = 0;
|
||||
foreach($catsLftRgt as $potentialParent){
|
||||
if(
|
||||
($rs->cat_lft > $potentialParent['cat_lft'])
|
||||
&& ($rs->cat_lft < $potentialParent['cat_rgt'])
|
||||
&& ($betterParentLevel < $potentialParent['cat_level'])
|
||||
)
|
||||
{
|
||||
$betterParentLevel = $potentialParent['cat_level'];
|
||||
$betterParentId = $potentialParent['cat_id'];
|
||||
$betterParentIndex = $countPrevious;
|
||||
}
|
||||
|
||||
$countPrevious++;
|
||||
}
|
||||
|
||||
//Split data on two arrays
|
||||
//the goal is to no expose via api cat_lft and cat_rgt
|
||||
$cats[$index] = array(
|
||||
'cat_id' => (int)$rs->cat_id,
|
||||
'cat_title' => $rs->cat_title,
|
||||
'cat_url' => $rs->cat_url,
|
||||
'cat_desc' => $rs->cat_desc
|
||||
);
|
||||
$catsLftRgt[$index] = array(
|
||||
'cat_lft' => (int)$rs->cat_lft,
|
||||
'cat_rgt' => (int)$rs->cat_rgt,
|
||||
'cat_id' => (int)$rs->cat_id,
|
||||
'cat_level' => (int)$betterParentLevel + 1,
|
||||
'count_childs' => 0
|
||||
);
|
||||
|
||||
$cats[$index]['cat_level'] = (int)$betterParentLevel + 1;
|
||||
if($betterParentId == -1){
|
||||
$catsLftRgt[$index]['cat_parent_id'] = $cats[$index]['cat_parent_id'] = null;
|
||||
$catsLftRgt[$index]['cat_position'] = $cats[$index]['cat_position'] = (int)$nbeCatsLevel0;
|
||||
$nbeCatsLevel0++;
|
||||
}else{
|
||||
$catsLftRgt[$index]['cat_parent_id'] = $cats[$index]['cat_parent_id'] = (int)$betterParentId;
|
||||
$catsLftRgt[$index]['cat_position'] = $cats[$index]['cat_position'] = $catsLftRgt[$betterParentIndex]['count_childs'];
|
||||
|
||||
$catsLftRgt[$betterParentIndex]['count_childs']++;
|
||||
}
|
||||
$index++;
|
||||
}
|
||||
$this->cats = $cats;
|
||||
$this->catsLftRgt = $catsLftRgt;
|
||||
}
|
||||
}
|
|
@ -1,139 +0,0 @@
|
|||
<?php
|
||||
class RestDocumentation extends RestQuery
|
||||
/*
|
||||
* serves the swagger UI page
|
||||
*/
|
||||
{
|
||||
protected $chapter;
|
||||
|
||||
protected function chapterExists(){
|
||||
if($this->chapter == 'all'){
|
||||
return true;
|
||||
}
|
||||
//documentation files must have the pattern /^swagger\-([a-zA-Z]+)\.json$/
|
||||
$files = scandir(path::real(dirname(__FILE__).'/../documentation/'));
|
||||
|
||||
foreach($files as $file){
|
||||
if($file == 'swagger-'.$this->chapter.'.json'){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function __construct($args){
|
||||
global $core;
|
||||
if($args == "documentation"){
|
||||
//il faut concaténer toutes les docs disponibles
|
||||
$this->chapter = 'all';
|
||||
}else{
|
||||
list($osef,$this->chapter) = explode("/",$args);
|
||||
}
|
||||
|
||||
if(!$this->chapterExists()){
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array(
|
||||
'error' => 'Not found'.$this->chapter,
|
||||
'code' => 404
|
||||
);
|
||||
}
|
||||
|
||||
//le documentation demandée par l'user existe.
|
||||
$this->response_code = 200;
|
||||
$this->response_message =
|
||||
'<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Swagger UI</title>
|
||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
|
||||
<link rel="stylesheet" type="text/css" href="index.php?pf=rest/documentation/swagger-ui-dist/swagger-ui.css" >
|
||||
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
|
||||
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" />
|
||||
<style>
|
||||
html
|
||||
{
|
||||
box-sizing: border-box;
|
||||
overflow: -moz-scrollbars-vertical;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
*,
|
||||
*:before,
|
||||
*:after
|
||||
{
|
||||
box-sizing: inherit;
|
||||
}
|
||||
|
||||
body {
|
||||
margin:0;
|
||||
background: #fafafa;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="position:absolute;width:0;height:0">
|
||||
<defs>
|
||||
<symbol viewBox="0 0 20 20" id="unlocked">
|
||||
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V6h2v-.801C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8z"></path>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="locked">
|
||||
<path d="M15.8 8H14V5.6C14 2.703 12.665 1 10 1 7.334 1 6 2.703 6 5.6V8H4c-.553 0-1 .646-1 1.199V17c0 .549.428 1.139.951 1.307l1.197.387C5.672 18.861 6.55 19 7.1 19h5.8c.549 0 1.428-.139 1.951-.307l1.196-.387c.524-.167.953-.757.953-1.306V9.199C17 8.646 16.352 8 15.8 8zM12 8H8V5.199C8 3.754 8.797 3 10 3c1.203 0 2 .754 2 2.199V8z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="close">
|
||||
<path d="M14.348 14.849c-.469.469-1.229.469-1.697 0L10 11.819l-2.651 3.029c-.469.469-1.229.469-1.697 0-.469-.469-.469-1.229 0-1.697l2.758-3.15-2.759-3.152c-.469-.469-.469-1.228 0-1.697.469-.469 1.228-.469 1.697 0L10 8.183l2.651-3.031c.469-.469 1.228-.469 1.697 0 .469.469.469 1.229 0 1.697l-2.758 3.152 2.758 3.15c.469.469.469 1.229 0 1.698z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="large-arrow">
|
||||
<path d="M13.25 10L6.109 2.58c-.268-.27-.268-.707 0-.979.268-.27.701-.27.969 0l7.83 7.908c.268.271.268.709 0 .979l-7.83 7.908c-.268.271-.701.27-.969 0-.268-.269-.268-.707 0-.979L13.25 10z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 20 20" id="large-arrow-down">
|
||||
<path d="M17.418 6.109c.272-.268.709-.268.979 0s.271.701 0 .969l-7.908 7.83c-.27.268-.707.268-.979 0l-7.908-7.83c-.27-.268-.27-.701 0-.969.271-.268.709-.268.979 0L10 13.25l7.418-7.141z"/>
|
||||
</symbol>
|
||||
|
||||
|
||||
<symbol viewBox="0 0 24 24" id="jump-to">
|
||||
<path d="M19 7v4H5.83l3.58-3.59L8 6l-6 6 6 6 1.41-1.41L5.83 13H21V7z"/>
|
||||
</symbol>
|
||||
|
||||
<symbol viewBox="0 0 24 24" id="expand">
|
||||
<path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/>
|
||||
</symbol>
|
||||
|
||||
</defs>
|
||||
</svg>
|
||||
|
||||
<div id="swagger-ui"></div>
|
||||
|
||||
<script src="index.php?pf=rest/documentation/swagger-ui-dist/swagger-ui-bundle.js"> </script>
|
||||
<script src="index.php?pf=rest/documentation/swagger-ui-dist/swagger-ui-standalone-preset.js"> </script>
|
||||
<script>
|
||||
window.onload = function() {
|
||||
// Build a system
|
||||
const ui = SwaggerUIBundle({
|
||||
url: "'.$core->blog->url.$core->url->getBase('rest').'/specs/'.$this->chapter.'",
|
||||
dom_id: \'#swagger-ui\',
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis,
|
||||
SwaggerUIStandalonePreset
|
||||
],
|
||||
plugins: [
|
||||
SwaggerUIBundle.plugins.DownloadUrl
|
||||
],
|
||||
layout: "StandaloneLayout"
|
||||
})
|
||||
|
||||
window.ui = ui
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>';
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
<?php
|
||||
class ApiKey
|
||||
{
|
||||
|
||||
public $key;
|
||||
|
||||
public function __construct(){
|
||||
$this->key = '';
|
||||
}
|
||||
public function new_key($dcUserId)
|
||||
{
|
||||
$this->key = $this->rand_str();
|
||||
$this -> put_dc_setting_user_key($dcUserId);
|
||||
return $this->key;
|
||||
}
|
||||
|
||||
public function set_key($key)
|
||||
{
|
||||
$this->key = $key;
|
||||
}
|
||||
|
||||
public function get_dc_admin_form($dcUserId)
|
||||
{
|
||||
|
||||
global $core;
|
||||
|
||||
//tester si une clef d'API a été générée
|
||||
if($this->dc_is_key_setting_set($dcUserId)){
|
||||
$infoFormApiKey = __('Your api key has already been created.');
|
||||
$buttonFormApiKey = __('Erase existing API key and generate a new one for').' '.$dcUserId;
|
||||
}else{
|
||||
$infoFormApiKey = __('No API key found.');
|
||||
$buttonFormApiKey = __('Generate a API key for').' '.$dcUserId;
|
||||
}
|
||||
|
||||
if($this->key == ''){
|
||||
$infoKey = $infoFormApiKey;
|
||||
}else{
|
||||
$infoKey = '<p class="info">'.__('The api key is').':<input type ="texte" value="'.$this->key.'"/><br/>'.
|
||||
__('Copy and paste it, You will cannot see it again.').'</p>';
|
||||
}
|
||||
|
||||
|
||||
return '<form method="post" action="'.http::getSelfURI().'">'.
|
||||
$infoKey.
|
||||
'<p><input type="submit" name="resetApiKey" value="'.$buttonFormApiKey.'"/></p>'.
|
||||
$core->formNonce().
|
||||
'</form>';
|
||||
}
|
||||
|
||||
private function dc_is_key_setting_set($dcUserId)
|
||||
{
|
||||
global $core;
|
||||
|
||||
$apiKeyName = $this->get_dc_setting_api_name($dcUserId);
|
||||
$currentHashedKey = $core->blog->settings->rest->{$apiKeyName};
|
||||
if(empty($currentHashedKey)){
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private function put_dc_setting_user_key($dcUserId)
|
||||
{
|
||||
global $core;
|
||||
|
||||
if ($this->key == ''){
|
||||
//don't save an empty key
|
||||
return false;
|
||||
}
|
||||
$hashedKey = $core->auth->crypt($this->key);
|
||||
$core->blog->settings->rest->put(
|
||||
$this->get_dc_setting_api_name($dcUserId),
|
||||
$hashedKey,
|
||||
'string'
|
||||
);
|
||||
return $hashedKey;
|
||||
}
|
||||
|
||||
private function get_dc_setting_api_name($dcUserId)
|
||||
{
|
||||
return 'rest_key_'.$dcUserId;
|
||||
}
|
||||
|
||||
private function rand_str($length = 32, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890')
|
||||
{
|
||||
$chars_length = (strlen($chars) - 1);
|
||||
$string = $chars{rand(0, $chars_length)};
|
||||
for ($i = 1; $i < $length; $i = strlen($string)){
|
||||
$r = $chars{rand(0, $chars_length)};
|
||||
if ($r != $string{$i - 1}) $string .= $r;
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
<?php
|
||||
class RestQueryDeleteBlogSettings extends RestQuery
|
||||
{
|
||||
|
||||
public function __construct($args){
|
||||
global $core;
|
||||
$explodedArgs = explode("/",$args);
|
||||
$nameSpace = $explodedArgs[2];
|
||||
$this->blog_id = $explodedArgs[0];
|
||||
|
||||
|
||||
if($core->auth === false){
|
||||
$core->auth = new restAuth($core); //class dcBlog need it
|
||||
$unauth = true;
|
||||
}
|
||||
$this->required_perms = 'admin';
|
||||
|
||||
//Is allowed?
|
||||
if($this->is_allowed() === false){
|
||||
//need To be authentified
|
||||
return;
|
||||
}
|
||||
|
||||
//does the blog exists?
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
$blog_settings = new dcSettings($core,$this->blog_id);
|
||||
|
||||
if(!$core->blog->id){
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Resource '.$this -> blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
|
||||
//Delete namespace or just a setting?
|
||||
$nS = new restDcNameSpace($core, $this->blog_id,$explodedArgs[2]);
|
||||
|
||||
if(isset($explodedArgs[3])){
|
||||
if($nS->settingExists($explodedArgs[3])){
|
||||
$nS->drop($explodedArgs[3]);
|
||||
//OK
|
||||
$this->response_code = 200;
|
||||
$this->response_message = array('code' => 200, 'message' => 'Setting '.$explodedArgs[3].' deleted.');
|
||||
return;
|
||||
}else{
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Setting '.$explodedArgs[3].' not found');
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
//delete nameSpace
|
||||
$core->blog->settings->delNamespace($explodedArgs[2]);
|
||||
$this->response_code = 200;
|
||||
$this->response_message = array('code' => 200, 'message' => 'NameSpace '.$explodedArgs[2].' deleted.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
class ResQueryDeleteBlogs extends RestQuery
|
||||
{
|
||||
|
||||
public function __construct($args){
|
||||
|
||||
global $core;
|
||||
|
||||
$this->blog_id = substr($args,6);
|
||||
|
||||
$this->required_perms = 'admin';
|
||||
|
||||
//Is allowed?
|
||||
if($this->is_allowed() === false){
|
||||
//need To be authentified
|
||||
return;
|
||||
}
|
||||
|
||||
//does the blog exists?
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
$blog_settings = new dcSettings($core,$this->blog_id);
|
||||
|
||||
if(!$core->blog->id){
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Resource '.$this -> blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
try{
|
||||
$core->delBlog($this->blog_id);
|
||||
$this->response_code = 201;
|
||||
$this->response_message = array(
|
||||
'code' => 201,
|
||||
'message' => 'Successfully deleted blog '.$this->blog_id
|
||||
);
|
||||
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->response_code = 500;
|
||||
$this->response_message = array(
|
||||
'code' => 500,
|
||||
'message' => $e->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,121 +0,0 @@
|
|||
<?php
|
||||
class RestQueryDeleteCategories extends RestQuery
|
||||
{
|
||||
|
||||
public function __construct($args,$body){
|
||||
|
||||
global $core;
|
||||
|
||||
$explodedArgs = explode("/",$args);
|
||||
$this->blog_id = $explodedArgs[0];
|
||||
|
||||
$this->required_perms = 'none'; //To do
|
||||
|
||||
if($core->auth === false){
|
||||
$core->auth = new restAuth($core);
|
||||
$unauth = true;
|
||||
}
|
||||
if($this->is_allowed() === false){
|
||||
return;
|
||||
}
|
||||
|
||||
if(!isset($explodedArgs[2])){
|
||||
$this->is404("no category given");
|
||||
return;
|
||||
}else{
|
||||
$cat_id = $explodedArgs[2];
|
||||
}
|
||||
|
||||
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
if(!$core->blog->id){
|
||||
$this->is404('Resource '.$blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
|
||||
$cats = new RestCategories($core);
|
||||
|
||||
if(!$cats->getCatProperties($cat_id)){
|
||||
$this->is404($cat_id.' category not found');
|
||||
return;
|
||||
}
|
||||
|
||||
if(empty($body)){
|
||||
$params = array();
|
||||
}elseif(empty(json_decode($body,true))){
|
||||
$params = array();
|
||||
}else{
|
||||
|
||||
$params = $this->body_to_array($body);
|
||||
if($params === false){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if(!$this->check_for_required_fields(
|
||||
$params,
|
||||
array(), //required fields
|
||||
array("move_childs_on_cat_id","delete_childs") //facultatives fields
|
||||
)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($params["move_childs_on_cat_id"])){
|
||||
if(!$cats->getCatProperties($params["move_childs_on_cat_id"])){
|
||||
$this->is404($params["move_childs_on_cat_id"].' category not found');
|
||||
return;
|
||||
}
|
||||
|
||||
//déplacer les posts
|
||||
$sql = " UPDATE ".$core->prefix."post
|
||||
SET cat_id='".$core->con->escape($params["move_childs_on_cat_id"])."'
|
||||
WHERE blog_id='".$core->con->escape($core->blog->id)."'
|
||||
AND cat_id='".$core->con->escape($cat_id)."';";
|
||||
|
||||
$core->con->execute($sql);
|
||||
|
||||
//déplacer les sous catégories
|
||||
$cats->moveChilds($cat_id,$params["move_childs_on_cat_id"]);
|
||||
}
|
||||
|
||||
if((isset($params["delete_childs"])) && ($params["delete_childs"])){
|
||||
//delete posts
|
||||
$sql = "DELETE
|
||||
post.*
|
||||
FROM
|
||||
".$core->prefix."post AS post,
|
||||
".$core->prefix."category AS category,
|
||||
".$core->prefix."category AS parentcategory
|
||||
WHERE
|
||||
post.cat_id = category.cat_id
|
||||
AND parentcategory.cat_id ='".$core->con->escape($cat_id)."'
|
||||
AND category.cat_lft BETWEEN parentcategory.cat_lft AND parentcategory.cat_rgt
|
||||
AND post.blog_id='".$core->con->escape($core->blog->id)."';";
|
||||
$core->con->execute($sql);
|
||||
$deleteSubs = true;
|
||||
}else{
|
||||
$deletSubs = false;
|
||||
}
|
||||
|
||||
|
||||
//OK to delete cat
|
||||
if($cats->deleteCategory($cat_id,$deleteSubs)) {
|
||||
$this->response_code = 200;
|
||||
$this->response_message = array(
|
||||
"code" => 200,
|
||||
"message" => "Successfully delete Category"
|
||||
);
|
||||
}else{
|
||||
$this->response_code = 500;
|
||||
$this->response_message = array(
|
||||
"code" => 500,
|
||||
"message" => "Something wrong is happened while trying to delete the category."
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
class RestQueryDeleteComments extends RestQuery
|
||||
{
|
||||
public function __construct($args,$body){
|
||||
global $core;
|
||||
|
||||
$explodedArgs = explode("/",$args);
|
||||
$this->blog_id = $explodedArgs[0];
|
||||
|
||||
$this->required_perms = 'none'; //To do
|
||||
|
||||
if($core->auth === false){
|
||||
$core->auth = new restAuth($core);
|
||||
$unauth = true;
|
||||
}
|
||||
if($this->is_allowed() === false){
|
||||
return;
|
||||
}
|
||||
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
if(!$core->blog->id){
|
||||
$this->is404('Resource '.$blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
|
||||
if(isset($explodedArgs[2])){
|
||||
$listToDelete = array(intval($explodedArgs[2]));
|
||||
|
||||
}else{
|
||||
//list To Delete is on the body
|
||||
$list=json_decode($body);
|
||||
}
|
||||
error_log(json_encode($listToDelete,true));
|
||||
foreach($listToDelete as $item){
|
||||
if(!is_int($item)){
|
||||
$this->response_code = 400;
|
||||
$this->response_message = array(
|
||||
"error"=> 400,
|
||||
"message"=> "items ids to delete must be integers values"
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "DELETE comments.*
|
||||
FROM ".$core->prefix."comment AS comments,
|
||||
".$core->prefix."post AS posts
|
||||
WHERE comments.post_id=posts.post_id
|
||||
AND posts.blog_id='".$core->con->escape($core->blog->id)."'
|
||||
AND comments.comment_id IN (".implode(",",$listToDelete).");";
|
||||
$core->con->execute($sql);
|
||||
|
||||
$this->response_code = 201;
|
||||
$this->response_message = array(
|
||||
"code"=> 201,
|
||||
"message" => "delete made"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
class RestQueryDeletePostMeta extends RestQuery
|
||||
{
|
||||
public function __construct($args){
|
||||
global $core;
|
||||
|
||||
$explodedArgs = explode("/",$args);
|
||||
$this->blog_id = $explodedArgs[0];
|
||||
//preg_match('/^(.*)\/(.*)\/meta\/(.*)$/', $args ))
|
||||
$post_id = $explodedArgs[1];
|
||||
|
||||
if(isset($explodedArgs[3])) {
|
||||
$meta_id = $explodedArgs[3];
|
||||
}else {
|
||||
$meta_id = null;
|
||||
}
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
if(!$core->blog->id){
|
||||
//Le blog n'existe pas
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
|
||||
$core->meta->delPostMeta($post_id,null,$meta_id);
|
||||
|
||||
|
||||
|
||||
$this->response_code = 200;
|
||||
$this->response_message = array(
|
||||
'code' => 200,
|
||||
'message' => 'successfully remove meta'
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
*Methode permettant de retourner des informations sur un blog particulier
|
||||
*/
|
||||
class RestQueryGetBlog extends RestQuery
|
||||
{
|
||||
public function __construct($args)
|
||||
{
|
||||
global $core;
|
||||
|
||||
$this->blog_id = substr($args,6);
|
||||
|
||||
$this->required_perms = 'unauth';
|
||||
if($this->is_allowed() === false){
|
||||
return;
|
||||
}
|
||||
//instance
|
||||
if($core->auth === false){
|
||||
$core->auth = new dcAuth($core); //class dcBlog need it
|
||||
$unauth = true;
|
||||
if($core->blog->status == false){
|
||||
//le blog n'est pas publié (et l'user n'est pas authentifié)
|
||||
// on Sort en 404
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
$blog_settings = new dcSettings($core,$this->blog_id);
|
||||
|
||||
if(!$core->blog->id){
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Resource '.$this -> blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
|
||||
$response = array(
|
||||
'blog_id' => $core->blog->id,
|
||||
'blog_status' => $core->blog->status,
|
||||
'blog_name' => $core->blog->name,
|
||||
'blog_desc' => $core->blog->desc,
|
||||
'blog_url' => $core->blog->url
|
||||
);
|
||||
$this->response_code = 200;
|
||||
$this->response_message = $response;
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
class RestQueryGetBlogSettings extends RestQuery
|
||||
{
|
||||
|
||||
public function __construct($args)
|
||||
{
|
||||
global $core;
|
||||
|
||||
$explodedArgs = explode("/",$args);
|
||||
$this->blog_id = $explodedArgs[0];
|
||||
//check if user is allowed
|
||||
$this->required_perms = 'admin';
|
||||
if($this->is_allowed() === false){
|
||||
return;
|
||||
}
|
||||
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
$blog_settings = new dcSettings($core,$this->blog_id);
|
||||
|
||||
if(!$core->blog->id){
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Resource '.$this -> blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
try{
|
||||
$settings = array();
|
||||
foreach ($core->blog->settings->dumpNamespaces() as $ns => $namespace) {
|
||||
foreach ($namespace->dumpSettings() as $k => $v) {
|
||||
$settings[$ns][$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
$this->response_code = 200;
|
||||
|
||||
if(isset($explodedArgs[3])){
|
||||
if(isset($settings[$explodedArgs[2]][$explodedArgs[3]])){
|
||||
$this->response_message = $settings[$explodedArgs[2]][$explodedArgs[3]];
|
||||
}else{
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Namespace or setting not found');
|
||||
}
|
||||
}elseif(isset($explodedArgs[2])){
|
||||
if(isset($settings[$explodedArgs[2]])){
|
||||
$this->response_message = $settings[$explodedArgs[2]];
|
||||
}else{
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Namespace found');
|
||||
}
|
||||
}else{
|
||||
$this->response_message = $settings;
|
||||
}
|
||||
}catch (Exception $e){
|
||||
$this->response_code = 500;
|
||||
$this->response_message = array(
|
||||
'code' => 500,
|
||||
'message' => $e->getMessage()
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
<?php
|
||||
|
||||
class RestQueryGetBlogs extends RestQuery
|
||||
{
|
||||
public function __construct(){
|
||||
|
||||
global $core;
|
||||
$this->blog_id = false; //this method doesn't depend on a blog_id
|
||||
$this->required_perms = 'none'; //I want user have an account
|
||||
|
||||
if($this->is_allowed() === false){
|
||||
return;
|
||||
}
|
||||
//list the blogs the user can access
|
||||
$blgs = $core->auth->getAllPermissions();
|
||||
$ret = array();
|
||||
foreach($blgs as $key=>$value){
|
||||
$ret[] = $key;
|
||||
}
|
||||
$this->response_code = 200;
|
||||
$this->response_message = $ret;
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
<?php
|
||||
class RestQueryGetCategories extends RestQuery
|
||||
{
|
||||
|
||||
public function __construct($args){
|
||||
|
||||
global $core;
|
||||
|
||||
$explodedArgs = explode("/",$args);
|
||||
$this->blog_id = $explodedArgs[0];
|
||||
|
||||
|
||||
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
|
||||
if(!$core->blog->id){
|
||||
//Le blog n'existe pas
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
|
||||
if(isset($_GET['filters'])){
|
||||
$filtersArr = $this->getFilters(
|
||||
$_GET['filters'],
|
||||
array('cat_title','cat_url','cat_desc',
|
||||
'cat_level','cat_parent_id','cat_position')
|
||||
);
|
||||
if($filtersArr === false){
|
||||
return;
|
||||
}
|
||||
}else{
|
||||
$filtersArr = array();
|
||||
}
|
||||
$cats = new RestCategories($core);
|
||||
if(isset($explodedArgs[2])){
|
||||
//une categorie est fournie
|
||||
$this->response_message = $cats -> getCatProperties($explodedArgs[2]);
|
||||
}else{
|
||||
$this->response_message = $cats -> getCats($filtersArr);
|
||||
}
|
||||
$this->response_code = 200;
|
||||
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
<?php
|
||||
class RestQueryGetComments extends RestQuery
|
||||
|
||||
{
|
||||
public function __construct($args){
|
||||
|
||||
global $core;
|
||||
$explodedArgs = explode("/",$args);
|
||||
$this->blog_id = $explodedArgs[0];
|
||||
$this->required_perms = 'none'; //To do
|
||||
|
||||
$post_id = ($explodedArgs[1] == 'comments')? null:$explodedArgs[1];
|
||||
$comment_id = (isset($explodedArgs[2]))? $explodedArgs[2]:null;
|
||||
|
||||
//check if blog exists
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
if(!$core->blog->id){
|
||||
$this->is404('Resource '.$blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
|
||||
if(!is_null($post_id)){
|
||||
//check if post exists
|
||||
$post = $core->blog->getPosts(array('post_id' => $post_id));
|
||||
|
||||
if ($post->isEmpty()) {
|
||||
$this->is404("No post with id: ".$post_id." found");
|
||||
return;
|
||||
}
|
||||
}
|
||||
$givenFilters = array();
|
||||
if(isset($_GET['filters'])){
|
||||
$availableFilters = array(
|
||||
'post_type','post_id','cat_id','comment_id','comment_site','comment_status','comment_trackback','comment_ip','post_url','user_id');
|
||||
|
||||
$givenFilters = $this->getFilters($_GET['filters'],$availableFilters);
|
||||
if($givenFilters === false){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//verifier s'il n'y a pas des incohérences... parceque c'est rigolo
|
||||
// de shooter l'user avec une erreur 409
|
||||
if(
|
||||
((!is_null($post_id)) && (isset($givenFilters["post_id"])))
|
||||
|| ((!is_null($comment_id) && (isset($givenFilters["comment_id"]))))
|
||||
){
|
||||
$this->response_code = 409;
|
||||
$this->response_message = array(
|
||||
"error" => 409,
|
||||
"message" => "Post_id or Comment_id must not be filtered both by URL path AND URL filters var on query string"
|
||||
);
|
||||
}
|
||||
|
||||
if(!is_null($post_id)){
|
||||
$givenFilters["post_id"] = $post_id;
|
||||
}
|
||||
if(!is_null($comment_id)){
|
||||
$givenFilters["comment_id"] = $comment_id;
|
||||
}
|
||||
|
||||
//time to execute the query
|
||||
$commentsRecord = $core->blog->getComments($givenFilters);
|
||||
$this->response_code = 200;
|
||||
$this->response_message = $this->rs_to_array($commentsRecord);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
<?php
|
||||
class RestQueryGetMetas extends RestQuery
|
||||
{
|
||||
public function getMetas($params){
|
||||
global $core;
|
||||
|
||||
$rs = $core->meta->getMetadata($params, false);
|
||||
return $this->rs_to_array($rs);
|
||||
}
|
||||
|
||||
public function __construct($args){
|
||||
global $core;
|
||||
|
||||
$explodedArgs = explode("/",$args);
|
||||
$this->blog_id = $explodedArgs[0];
|
||||
//check if user is allowed
|
||||
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
|
||||
if(!$core->blog->id){
|
||||
//Le blog n'existe pas
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
|
||||
$params = array();
|
||||
if (isset($_GET['post_id']))
|
||||
$params['post_id'] = $_GET['post_id'];
|
||||
if (isset($_GET['meta_id']))
|
||||
$params['meta_id'] = $_GET['meta_id'];
|
||||
if (isset($_GET['meta_type']))
|
||||
$params = $_GET['meta_type'];
|
||||
|
||||
$this -> response_code = 200;
|
||||
$this -> response_message = $this -> getMetas($params);
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
class RestQueryGetPostMetas extends RestQuery
|
||||
{
|
||||
|
||||
public function __construct($args){
|
||||
global $core;
|
||||
|
||||
$explodedArgs = explode("/",$args);
|
||||
$this->blog_id = $explodedArgs[0];
|
||||
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
|
||||
if(!$core->blog->id){
|
||||
//Le blog n'existe pas
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->response_message = RestQueryGetMetas::getMetas(array('post_id'=>$explodedArgs[1]));
|
||||
$this->response_code = 200;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
<?php
|
||||
class RestQueryGetPost extends RestQuery
|
||||
{
|
||||
|
||||
public function __construct($args){
|
||||
global $core;
|
||||
|
||||
$explodedArgs = explode("/",$args);
|
||||
$this->blog_id = $explodedArgs[0];
|
||||
$post_id = $explodedArgs[2];
|
||||
$post = $core->blog->getPosts(array('post_id' => $post_id));
|
||||
|
||||
if ($post->isEmpty()) {
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array(
|
||||
'code' => 404,
|
||||
'error' => 'POST '.$post_id.' does not exists'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$fieldsKeys= $post->columns();
|
||||
|
||||
$postArr = array();
|
||||
foreach($fieldsKeys as $key){
|
||||
$postArr[$key] = $post -> $key;
|
||||
}
|
||||
//les metas
|
||||
|
||||
//getMetadata($params);
|
||||
$metas = array();
|
||||
$rs = $core->meta->getMetadata(array('post_id' => $post_id));
|
||||
//('meta_id' => $meta_id, 'meta_type' => $meta_type, 'post_id' => $post_id);
|
||||
while($rs->fetch()){
|
||||
$metas[] = array(
|
||||
'meta_id' => $rs->meta_id,
|
||||
'meta_type' => $rs->meta_type
|
||||
);
|
||||
}
|
||||
|
||||
$postArr['metas'] = $metas;
|
||||
|
||||
$this -> response_message = $postArr;
|
||||
$this -> response_code = 200;
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1,107 +0,0 @@
|
|||
<?php
|
||||
class RestQueryGetPosts extends RestQuery
|
||||
{
|
||||
|
||||
public function __construct($args)
|
||||
{
|
||||
|
||||
global $core;
|
||||
|
||||
$explodedArgs = explode("/",$args);
|
||||
$this->blog_id = $explodedArgs[0];
|
||||
$this->required_perms = 'unauth'; //les niveaux d'acces aux contenus sont
|
||||
//gérés dans la function $core->blog->getPosts($params)
|
||||
|
||||
if($core->auth === false){
|
||||
$core->auth = new restAuth($core); //class dcBlog need it
|
||||
$unauth = true;
|
||||
}
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
if(!$core->blog->id){
|
||||
//Le blog n'existe pas
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
$blog_settings = new dcSettings($core,$this->blog_id);
|
||||
|
||||
if($this->is_allowed() === false){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$params['where'] = '';
|
||||
if((isset($_GET['limit-start'])) && (isset($_GET['limit-count']))){
|
||||
$params['limit'] = array($_GET['limit-start'],$_GET['limit-count']);
|
||||
}elseif((isset($_GET['limit-start'])) xor (isset($_GET['limit-count']))){
|
||||
$this->response_code = 400;
|
||||
$this->response_message = array(
|
||||
'code' => 400,
|
||||
'message' => 'If you set limits both of limit-start and limit-cout must be setted'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if(isset($_GET['cat_id'])){
|
||||
$params['cat_id'] = $_GET['cat_id'];
|
||||
}
|
||||
|
||||
if(isset($_GET['post_status'])){
|
||||
$params['post_status'] = $_GET['post_status'];
|
||||
}
|
||||
|
||||
if(isset($_GET['password'])){
|
||||
$params['where'] .= ' AND post_password IS '.($_GET['password'] ? 'NOT ' : '').'NULL ';
|
||||
}
|
||||
|
||||
if(isset($_GET['post_selected'])){
|
||||
$params['post_selected'] = $_GET['post_selected']; //to do, vérifier, si c'est pris correctement comment un boolean
|
||||
}
|
||||
|
||||
if(isset($_GET['post_open_comment'])){
|
||||
$params['where'] .= " AND post_open_comment = '".$_GET['post_open_comment']."' ";
|
||||
}
|
||||
|
||||
if(isset($_GET['post_open_tb'])){
|
||||
$params['where'] .= " AND post_open_tb = '".$_GET['post_open_tb']."' ";
|
||||
}
|
||||
|
||||
//date
|
||||
if((isset($_GET['post_month'])) && (isset ($_GET['post_year']))){
|
||||
$params['post_month'] = $_GET['post_month'];
|
||||
$params['post_year'] = $_GET['post_year'];
|
||||
}elseif((isset($_GET['post_month'])) xor (isset ($_GET['post_year']))){
|
||||
$this -> response_code = 400;
|
||||
$this -> response_message = array(
|
||||
'code' => 400,
|
||||
'message' => 'If you set date parameters both of post_month and post_year must be setted'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if(isset($_GET['format'])){
|
||||
$params['where'] .= " AND post_format = '".$_GET['format']."' ";
|
||||
}
|
||||
if(isset($_GET['sortby'])){
|
||||
$params['order'] = $_GET['sortby'];
|
||||
}
|
||||
|
||||
|
||||
$rs = $core->blog->getPosts($params);
|
||||
|
||||
$fieldsKeys= $rs->columns();
|
||||
$response = array();
|
||||
while ($rs->fetch()) {
|
||||
$post = array();
|
||||
foreach($fieldsKeys as $key){
|
||||
$post[$key] = $rs->$key;
|
||||
}
|
||||
$response[] = $post;
|
||||
}
|
||||
|
||||
$this -> response_code = 200;
|
||||
$this -> response_message = $response;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
<?php
|
||||
class RestQueryGetPostsById extends RestQuery
|
||||
{
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
<?php
|
||||
class RestQueryGetSpecs extends RestDocumentation //some common functions betwin this 2 class
|
||||
{
|
||||
|
||||
protected function getSwaggerArray(){
|
||||
/*
|
||||
* need $this -> chapter initied
|
||||
* return the swagger doc (as an array)
|
||||
* with the real basePath and the URL
|
||||
* if chapter is 'all' it will concat all swagger definitions.
|
||||
*/
|
||||
|
||||
global $core;
|
||||
|
||||
if(!ctype_alpha($this->chapter)){
|
||||
return false;
|
||||
}
|
||||
|
||||
if($this->chapter == 'all'){
|
||||
//concat all specs array in one
|
||||
|
||||
$url = parse_url($core->blog->url.$core->url->getBase('rest'));
|
||||
preg_match('/https?:\/\/[^\/]*(\/.*)/',$core->blog->url.$core->url->getBase('rest'),$end);
|
||||
|
||||
$specs = array(
|
||||
"swagger" => "2.0",
|
||||
"info:" => array(
|
||||
"title" => "Dotclear API",
|
||||
"description" => "Manage yours blogs with this API",
|
||||
"version" => "0.1"
|
||||
),
|
||||
"host" => $url['host'],
|
||||
"schemes" => array(
|
||||
$url['scheme']
|
||||
),
|
||||
"basePath" =>$end[1],
|
||||
"produces" => array(
|
||||
"application/json"
|
||||
),
|
||||
"paths" =>array(),
|
||||
"definitions" => array(),
|
||||
|
||||
);
|
||||
|
||||
$files = scandir(path::real(dirname(__FILE__).'/../documentation/'));
|
||||
foreach($files as $file){
|
||||
if (preg_match('/^swagger\-(.*)\.json$/',$file)){
|
||||
$swag = json_decode(
|
||||
file_get_contents(
|
||||
path::real(dirname(__FILE__).'/../documentation/').'/'.$file
|
||||
),true
|
||||
);
|
||||
$specs["paths"] = array_merge($specs["paths"], $swag["paths"]);
|
||||
$specs["definitions"] = array_merge($specs["definitions"], $swag["definitions"]);
|
||||
}
|
||||
}
|
||||
|
||||
return $specs;
|
||||
}
|
||||
|
||||
|
||||
$files = scandir(path::real(dirname(__FILE__).'/../documentation/'));
|
||||
|
||||
foreach($files as $file){
|
||||
if($file == 'swagger-'.$this->chapter.'.json'){
|
||||
//return path::real(dirname(__FILE__).'/../documentation/').'/'.$file;
|
||||
|
||||
$specs = json_decode(
|
||||
file_get_contents(
|
||||
path::real(dirname(__FILE__).'/../documentation/').'/'.$file
|
||||
),true
|
||||
);
|
||||
//change some parameters
|
||||
$url = parse_url($core->blog->url.$core->url->getBase('rest'));
|
||||
$specs['host'] = $url['host'];
|
||||
$specs['schemes'] = $url['scheme'];
|
||||
preg_match('/https?:\/\/[^\/]*(\/.*)/',$core->blog->url.$core->url->getBase('rest'),$end);
|
||||
$specs['basePath'] = $end[1];
|
||||
return $specs;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
public function __construct($args){
|
||||
global $core;
|
||||
$this->response_code = 200;
|
||||
$this->required_perms = 'unauth';
|
||||
if($this->is_allowed() === false){
|
||||
return;
|
||||
}
|
||||
|
||||
if($args == "specs"){
|
||||
$this->chapter = 'all';
|
||||
}else{
|
||||
list($osef,$this->chapter) = explode("/",$args);
|
||||
}
|
||||
|
||||
$specs = $this->getSwaggerArray();
|
||||
if($specs === false){
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array(
|
||||
'error' => 'Not found'.$body,
|
||||
'code' => 404
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->response_message = $specs;
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
<?php
|
||||
class ResQueryPatchBlogs extends RestQuery
|
||||
{
|
||||
|
||||
|
||||
public function __construct($args,$body)
|
||||
{
|
||||
|
||||
global $core;
|
||||
|
||||
$this->blog_id = substr($args,6);
|
||||
$this->required_perms = 'admin';
|
||||
|
||||
//Is allowed?
|
||||
if($this->is_allowed() === false){;
|
||||
return;
|
||||
}
|
||||
|
||||
//Is JSON valid?
|
||||
$inputArray = $this-> body_to_array($body);
|
||||
if ($inputArray === false){
|
||||
return;
|
||||
}
|
||||
|
||||
//is it valid fields?
|
||||
if(!$this->check_for_required_fields( $inputArray, array(),
|
||||
array('blog_id','blog_url','blog_name','blog_desc','lang','blog_timezone','url_scan')) ){
|
||||
return;
|
||||
}
|
||||
|
||||
//does the blog exists?
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
$blog_settings = new dcSettings($core,$this->blog_id);
|
||||
|
||||
if(!$core->blog->id){
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Resource '.$this -> blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
|
||||
$cur = $core->con->openCursor($core->prefix.'blog');
|
||||
|
||||
if(isset($inputArray['blog_id']))
|
||||
$cur->blog_id = $inputArray['blog_id'];
|
||||
else
|
||||
$cur->blog_id = $core->blog->id;
|
||||
|
||||
if(isset($inputArray['blog_url']))
|
||||
$cur->blog_url = preg_replace('/\?+$/','?', $inputArray['blog_url']);
|
||||
else
|
||||
$cur->blog_url = $core->blog->url;
|
||||
|
||||
if(isset($inputArray['blog_name']))
|
||||
$cur->blog_name = $inputArray['blog_name'];
|
||||
if(isset($inputArray['blog_desc']))
|
||||
$cur->blog_desc = $inputArray['blog_desc'];
|
||||
|
||||
$core->updBlog($this->blog_id,$cur);
|
||||
|
||||
//$cur->blog_upddt = date('Y-m-d H:i:s');
|
||||
//$cur->update("WHERE blog_id = '".$core->con->escape($id)."'");
|
||||
|
||||
$this -> response_code = 200;
|
||||
$this -> response_message = array(
|
||||
'code' => 200,
|
||||
'message' => 'blog '.$this->blog_id.' Successfully updated'
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
<?php
|
||||
class RestQueryPatchCategories extends RestQuery
|
||||
{
|
||||
|
||||
public function __construct($args,$body){
|
||||
|
||||
global $core;
|
||||
|
||||
$explodedArgs = explode("/",$args);
|
||||
$this->blog_id = $explodedArgs[0];
|
||||
|
||||
$this->required_perms = 'none'; //To do
|
||||
|
||||
if($core->auth === false){
|
||||
$core->auth = new restAuth($core);
|
||||
$unauth = true;
|
||||
}
|
||||
if($this->is_allowed() === false){
|
||||
return;
|
||||
}
|
||||
|
||||
if(!isset($explodedArgs[2])){
|
||||
$this->is404("no category given");
|
||||
return;
|
||||
}else{
|
||||
$cat_id = $explodedArgs[2];
|
||||
}
|
||||
|
||||
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
if(!$core->blog->id){
|
||||
$this->is404('Resource '.$blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
|
||||
$cats = new RestCategories($core);
|
||||
|
||||
$cat = $cats->getCatProperties($cat_id);
|
||||
|
||||
if($cat === false){
|
||||
$this->is404($cat_id.' category not found');
|
||||
return;
|
||||
}
|
||||
|
||||
//les valeurs envoyées par l'user
|
||||
$queryArr = $this->body_to_array($body);
|
||||
if($queryArr === false){
|
||||
return;
|
||||
}
|
||||
|
||||
if(!$this->check_for_required_fields(
|
||||
$queryArr ,
|
||||
array(), //required fields
|
||||
array('cat_title','cat_url','cat_desc','cat_parent_id','cat_position','temporary', 'permute') //facultatives fields
|
||||
)){
|
||||
return;
|
||||
}
|
||||
$cats->updateCategory($cat_id,$queryArr);
|
||||
$this->response_code = 201;
|
||||
$this->response_message = array(
|
||||
'code' => 201,
|
||||
'message' => 'Successfully update category',
|
||||
'id' => $cat_id
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
<?php
|
||||
|
||||
class ResQueryPatchMeta extends RestQuery
|
||||
{
|
||||
|
||||
public function __construct($args,$body){
|
||||
global $core;
|
||||
|
||||
$explodedArgs = explode("/",$args);
|
||||
$this->blog_id = $explodedArgs[0];
|
||||
$post_id = $explodedArgs[1];
|
||||
$meta_id = $explodedArgs[3];
|
||||
|
||||
$this->required_perms = 'none'; //To do
|
||||
|
||||
if($core->auth === false){
|
||||
$core->auth = new restAuth($core);
|
||||
$unauth = true;
|
||||
}
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
|
||||
if(!$core->blog->id){
|
||||
//Le blog n'existe pas
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
|
||||
return;
|
||||
}do
|
||||
|
||||
$blog_settings = new dcSettings($core,$this->blog_id);
|
||||
|
||||
if($this->is_allowed() === false){
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$clientQueryArr = json_decode($body, true);
|
||||
|
||||
//memorise the old one attributes before delete it
|
||||
$oldMeta = RestQueryGetMetas::getMetas(
|
||||
array(
|
||||
'post_id' => $post_id,
|
||||
'meta_id' => $meta_id
|
||||
)
|
||||
);
|
||||
|
||||
if(count($oldMeta) == 0){
|
||||
//error 404
|
||||
$this -> response_code = 404;
|
||||
$this -> response_message = array(
|
||||
'code' => 404,
|
||||
'message' =>'No existing meta with this post_id and this meta_id'
|
||||
);
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//delete the old meta
|
||||
$r = $core->meta->delPostMeta($post_id,null,$meta_id);
|
||||
|
||||
//create the new one
|
||||
if(isset($clientQueryArr['post_id'])){
|
||||
$new_post_id = $clientQueryArr['post_id'];
|
||||
}else {
|
||||
$new_post_id = $oldMeta[0]['post_id'];
|
||||
}
|
||||
if(isset($clientQueryArr['meta_id'])){
|
||||
$new_post_id = $clientQueryArr['meta_id'];
|
||||
}else {
|
||||
$new_post_id = $oldMeta[0]['meta_id'];
|
||||
}
|
||||
if(isset($clientQueryArr['meta_type'])){
|
||||
$new_post_id = $clientQueryArr['meta_type'];
|
||||
}else {
|
||||
$new_post_id = $oldMeta[0]['meta_type'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,326 +0,0 @@
|
|||
<?php
|
||||
|
||||
class RestQuery{
|
||||
protected $response_code;
|
||||
public $response_message; //array
|
||||
protected $blog_id;
|
||||
protected $required_perms = 'admin'; //must be changed by the childs class
|
||||
/*
|
||||
should be:
|
||||
'admin' administrateur
|
||||
'usage' gérer ses propres billets et commentaires
|
||||
'publish' publier des billets et des commentaires
|
||||
'delete' supprimer des billets et des commentaires
|
||||
'contentadmin' gérer tous les billets et commentaires
|
||||
'categories' gérer les catégories
|
||||
'media' gérer ses propres médias
|
||||
'media_admin' gérer tous les médias
|
||||
'none' //must have an account (without any rights)
|
||||
'unauth' //Open to the world
|
||||
*/
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array(
|
||||
"error" => "Method not found",
|
||||
"code" => 404
|
||||
);
|
||||
}
|
||||
|
||||
protected function is404($customMessage = '')
|
||||
{
|
||||
$this->response_code = 404;
|
||||
if (empty($customMessage))
|
||||
$this->response_message = array('code' => 404, 'error' => 'Resource not found');
|
||||
else
|
||||
$this->response_message = array('code' => 404, 'error' => $customMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if required fields are set
|
||||
* $strict => Go on error if a additionnal field is given
|
||||
*/
|
||||
protected function check_for_required_fields($arrayToCheck,$fieldsRequired,$fieldsOptionals = '')
|
||||
{
|
||||
if ($fieldsOptionals == ''){
|
||||
$fieldsOptionals == array();
|
||||
}
|
||||
|
||||
$fieldsSetted = array_keys($arrayToCheck);
|
||||
|
||||
if($fieldsOptionals == ''){
|
||||
if(empty(array_diff($fieldsSetted,$fieldsRequired))){
|
||||
return true;
|
||||
}else{
|
||||
$this->response_code = 400;
|
||||
$this->response_message = array(
|
||||
"error" => "Only and each of following parameters ".
|
||||
implode(", ",$fieldsRequired)." are required",
|
||||
"code" => 400
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
//check if all required fields are set
|
||||
foreach($fieldsRequired as $key){
|
||||
if(!isset($arrayToCheck[$key])){
|
||||
$this->response_code = 400;
|
||||
$this->response_message = array(
|
||||
"error" => "field ".$key." is needed",
|
||||
"code" => 400
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//check if a field is not in required and in fieldsOptionals
|
||||
foreach($fieldsSetted as $keyToTest){
|
||||
if((!in_array($keyToTest,$fieldsRequired)) && (!in_array($keyToTest,$fieldsOptionals))){
|
||||
$this->response_code = 400;
|
||||
$this->response_message = array(
|
||||
"error" => "Unwanted field '".$keyToTest."'",
|
||||
"code" => 400
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
* IN $RawFilters string urlencoded corresponding to $_GET['filters']
|
||||
* IN $permittedKeys array listing the keys the filter can Used
|
||||
* OUT array ('KeyName' => 'expectedValue')
|
||||
*/
|
||||
protected function getFilters($rawFilters,$permittedKeys)
|
||||
{
|
||||
|
||||
|
||||
$subject = urldecode($rawFilters);
|
||||
$matchExpr = '/(?<=^|\\s)([^=\\s]+)="((?:[^\\\\"]|\\\\.)*)"/';
|
||||
$replaceExpr = '/\\\\./';
|
||||
|
||||
$replaceCallback = function($match) {
|
||||
switch ($match[0][1]) {
|
||||
case 'r': return "\r";
|
||||
case 'n': return "\n";
|
||||
default: return $match[0][1];
|
||||
}
|
||||
};
|
||||
|
||||
preg_match_all($matchExpr, $subject, $matches);
|
||||
|
||||
$result = array();
|
||||
foreach ($matches[1] as $i => $key) {
|
||||
if(!in_array($key,$permittedKeys)){
|
||||
$this->response_code = 400;
|
||||
$this->response_message = array("code" => 400,
|
||||
"message" => "UnAllowed filter ".$key);
|
||||
return false;
|
||||
}
|
||||
$result[$key] = preg_replace_callback($replaceExpr, $replaceCallback, $matches[2][$i]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function body_to_array($body){
|
||||
if($ret = json_decode($body,true)){
|
||||
return $ret;
|
||||
}else{
|
||||
$this->response_code = 400;
|
||||
$this->response_message = array(
|
||||
'error' => 'Can\'t parse input JSON',
|
||||
'code' => 400
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
protected function is_allowed()
|
||||
{
|
||||
global $core;
|
||||
if($core->auth){
|
||||
$perms = $core->auth->getAllPermissions();
|
||||
}
|
||||
|
||||
$is_allowed = false;
|
||||
switch($this->required_perms){
|
||||
|
||||
case 'unauth':
|
||||
//on verifie quand même que l'API est ouverte
|
||||
if(
|
||||
(($core->blog->settings->rest->rest_is_open) && ($core->auth === false))
|
||||
||($core->auth !== false)
|
||||
){
|
||||
$is_allowed = true;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'none':
|
||||
//user must be valid
|
||||
if($core->auth){
|
||||
$is_allowed = true;
|
||||
}
|
||||
break;
|
||||
case 'media_admin':
|
||||
break;
|
||||
case 'media':
|
||||
break;
|
||||
case 'categories':
|
||||
break;
|
||||
case 'contentadmin':
|
||||
break;
|
||||
case 'delete':
|
||||
break;
|
||||
case 'publish':
|
||||
break;
|
||||
case 'usage':
|
||||
break;
|
||||
case 'admin':
|
||||
if (($core->auth !== false) && $core->auth->isSuperAdmin()){
|
||||
$is_allowed = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if($is_allowed){
|
||||
return true;
|
||||
}else{
|
||||
$this->response_code = 403;
|
||||
$this->response_message = array('code' => 403, 'error' => 'Unauthorized');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Quand l'API permet à la fois une structure
|
||||
* {
|
||||
* key1 : value1,
|
||||
* key2 : value2
|
||||
* }
|
||||
*
|
||||
* et une structure avec plusieurs enregistrements
|
||||
* [
|
||||
* {
|
||||
* key1 : value1.1,
|
||||
* key2 : value2.1
|
||||
* },
|
||||
* {
|
||||
* key1 : value1.2,
|
||||
* key2 : value2.2
|
||||
* }
|
||||
*]
|
||||
*
|
||||
* Cette function permet de tester quelle structure a un array, et retourne un array sous la deuxième
|
||||
* structure
|
||||
*
|
||||
* IN: $arr L'array à tester
|
||||
* $keyToTest: string Un nom de clef obligatoire qui servira à tester le type de structrure
|
||||
*/
|
||||
|
||||
public function arrayOfObjetsOrNot($arr,$keyToTest){
|
||||
|
||||
try{
|
||||
if(isset($arr[$keyToTest])){
|
||||
return array($arr);
|
||||
}elseif(isset($arr[0][$keyToTest])){
|
||||
return $arr;
|
||||
}
|
||||
}catch (Exception $e){
|
||||
//parfois ça déconne
|
||||
if(isset($arr[0][$keyToTest])){
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function get_full_code_header($code=''){
|
||||
if($code == ''){
|
||||
$code = $this->response_code;
|
||||
}
|
||||
static $codes = array(
|
||||
100 =>"Continue",
|
||||
101 =>"Switching Protocols",
|
||||
102 =>"Processing",
|
||||
200 =>"OK",
|
||||
201 =>"Created",
|
||||
202 =>"Accepted",
|
||||
203 =>"Non-Authoritative Information",
|
||||
204 =>"No Content",
|
||||
205 =>"Reset Content",
|
||||
206 =>"Partial Content",
|
||||
207 =>"Multi-Status",
|
||||
210 =>"Content Different",
|
||||
226 =>"IM Used",
|
||||
300 =>"Multiple Choices",
|
||||
301 =>"Moved Permanently",
|
||||
302 =>"Moved Temporarily",
|
||||
303 =>"See Other",
|
||||
304 =>"Not Modified",
|
||||
305 =>"Use Proxy",
|
||||
306 =>"(aucun)",
|
||||
307 =>"Temporary Redirect",
|
||||
308 =>"Permanent Redirect",
|
||||
310 =>"Too many Redirects",
|
||||
400 =>"Bad Request",
|
||||
401 =>"Unauthorized",
|
||||
402 =>"Payment Required",
|
||||
403 =>"Forbidden",
|
||||
404 =>"Not Found",
|
||||
405 =>"Method Not Allowed",
|
||||
406 =>"Not Acceptable",
|
||||
407 =>"Proxy Authentication Required",
|
||||
408 =>"Request Time-out",
|
||||
409 =>"Conflict",
|
||||
410 =>"Gone",
|
||||
411 =>"Length Required",
|
||||
412 =>"Precondition Failed",
|
||||
413 =>"Request Entity Too Large",
|
||||
414 =>"Request-URI Too Long",
|
||||
415 =>"Unsupported Media Type",
|
||||
416 =>"Requested range unsatisfiable",
|
||||
417 =>"Expectation failed",
|
||||
418 =>"I’m a teapot",
|
||||
421 =>"Bad mapping / Misdirected Request",
|
||||
422 =>"Unprocessable entity",
|
||||
423 =>"Locked",
|
||||
424 =>"Method failure",
|
||||
425 =>"Unordered Collection",
|
||||
426 =>"Upgrade Required",
|
||||
428 =>"Precondition Required",
|
||||
429 =>"Too Many Requests",
|
||||
431 =>"Request Header Fields Too Large",
|
||||
449 =>"Retry With",
|
||||
450 =>"Blocked by Windows Parental Controls",
|
||||
451 =>"Unavailable For Legal Reasons",
|
||||
456 =>"Unrecoverable Error"
|
||||
);
|
||||
|
||||
if(isset($codes[$code])){
|
||||
return "HTTP/1.0 ".$code." ".$codes[$code];
|
||||
}else{
|
||||
return "HTTP/1.0 ".$code." Something wrong happened";
|
||||
}
|
||||
}
|
||||
|
||||
function rs_to_array($rs){
|
||||
|
||||
$arr = array();
|
||||
|
||||
while($rs->fetch()){
|
||||
$r = array();
|
||||
$columns = $rs->columns();
|
||||
foreach($columns as $key){
|
||||
$r[$key] = $rs->$key;
|
||||
}
|
||||
$arr[] = $r;
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
<?php
|
||||
class RestQueryPostBlogSettings extends RestQuery
|
||||
{
|
||||
private function arrayToSubArray($array){
|
||||
|
||||
return array($array);
|
||||
}
|
||||
|
||||
private function setSetting($nameSpace,$body){
|
||||
global $core;
|
||||
//verifier le JSON
|
||||
|
||||
//permettre à l'user de fournir un ou plusieurs settings à la fois.
|
||||
$querryArr = json_decode($body,true);
|
||||
if(empty($querryArr)){
|
||||
$this->response_code = 400;
|
||||
$this->response_message = array(
|
||||
'error' => 'Can\'t parse input JSON',
|
||||
'code' => 400
|
||||
);
|
||||
return;
|
||||
}
|
||||
if(isset($querryArr['id'])){
|
||||
//l'user n'a envoyé qu'un seul setting sans le mettre dans un objet
|
||||
$querryArr = $this->arrayToSubArray($querryArr);
|
||||
}
|
||||
|
||||
//tester la présence des bonnes clefs
|
||||
foreach($querryArr as $setting){
|
||||
if($this->check_for_required_fields($setting,
|
||||
array('id','value'),
|
||||
array('type','label','value_change','global')
|
||||
) === false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($querryArr as $setting){
|
||||
//set falcutative fields
|
||||
if(!isset($setting['type'])){
|
||||
$setting['type'] = null;
|
||||
}
|
||||
if(!isset($setting['value_change'])){
|
||||
$setting['value_change'] = true;
|
||||
}
|
||||
if(!isset($setting['global'])){
|
||||
$setting['global'] = false;
|
||||
}
|
||||
|
||||
$core->blog->settings->$nameSpace->put($setting['id'],$setting['value'],
|
||||
$setting['type'],$setting['value_change'],
|
||||
$setting['global']);
|
||||
}
|
||||
|
||||
$this -> response_code = 201;
|
||||
$this -> response_message = array(
|
||||
'code' => 201,
|
||||
'message' => 'settings Successfully created'
|
||||
);
|
||||
return;
|
||||
}
|
||||
public function __construct($args,$body){
|
||||
global $core;
|
||||
|
||||
$explodedArgs = explode("/",$args);
|
||||
$nameSpace = $explodedArgs[2];
|
||||
$this->blog_id = $explodedArgs[0];
|
||||
$this->required_perms = 'admin';
|
||||
|
||||
if($core->auth === false){
|
||||
$core->auth = new restAuth($core); //class dcBlog need it
|
||||
$unauth = true;
|
||||
}
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
if(!$core->blog->id){
|
||||
//Le blog n'existe pas
|
||||
$this->is404('Resource '.$blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
$blog_settings = new dcSettings($core,$this->blog_id);
|
||||
|
||||
|
||||
|
||||
if($this->is_allowed() === false){
|
||||
return;
|
||||
}
|
||||
$core->blog->settings->addNamespace($nameSpace);
|
||||
//error_log($body);
|
||||
if(empty($body)){
|
||||
$this -> response_code = 201;
|
||||
$this -> response_message = array(
|
||||
'code' => 201,
|
||||
'message' => 'namespace '.$nameSpace.' Successfully created'
|
||||
);
|
||||
}else{
|
||||
$this-> setSetting($nameSpace,$body);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
<?php
|
||||
class RestQueryPostBlogs extends RestQuery
|
||||
{
|
||||
public function __construct($body)
|
||||
{
|
||||
|
||||
global $core;
|
||||
|
||||
$this->blog_id = false; //this method doesn't depend on a bolg_id
|
||||
$this->required_perms = 'admin'; //I want user have an account
|
||||
|
||||
if($this->is_allowed() === false){
|
||||
return;
|
||||
}
|
||||
|
||||
$inputArray = $this-> body_to_array($body);
|
||||
if ($inputArray === false){
|
||||
return false;
|
||||
}
|
||||
|
||||
//permit optional description
|
||||
if(!isset($inputArray['blog_desc'])){
|
||||
$inputArray["blog_desc"] = '';
|
||||
}
|
||||
//check if parameters are set
|
||||
|
||||
if(!$this->check_for_required_fields( $inputArray, array('blog_id','blog_url','blog_name','blog_desc'),
|
||||
array('lang','blog_timezone','url_scan')) ){
|
||||
return;
|
||||
}
|
||||
//Following lines are same as admin/blog.php
|
||||
|
||||
$cur = $core->con->openCursor($core->prefix.'blog');
|
||||
$blog_id = $cur->blog_id = $inputArray['blog_id'];
|
||||
$blog_url = $cur->blog_url = $inputArray['blog_url'];
|
||||
$blog_name = $cur->blog_name = $inputArray['blog_name'];
|
||||
$blog_desc = $cur->blog_desc = $inputArray['blog_desc'];
|
||||
|
||||
try
|
||||
{
|
||||
# --BEHAVIOR-- adminBeforeBlogCreate
|
||||
$core->callBehavior('adminBeforeBlogCreate',$cur,$blog_id);
|
||||
|
||||
$core->addBlog($cur);
|
||||
|
||||
# Default settings and override some
|
||||
$core->blogDefaults($cur->blog_id);
|
||||
$blog_settings = new dcSettings($core,$cur->blog_id);
|
||||
$blog_settings->addNamespace('system');
|
||||
|
||||
if(isset($inputArray['lang'])){
|
||||
$blog_settings->system->put('lang',$inputArray['lang']);
|
||||
}else{
|
||||
$blog_settings->system->put('lang',$core->auth->getInfo('user_lang'));
|
||||
}
|
||||
|
||||
if(isset($inputArray['blog_timezone'])){
|
||||
$blog_settings->system->put('blog_timezone',$inputArray['blog_timezone']);
|
||||
}else{
|
||||
$blog_settings->system->put('blog_timezone',$core->auth->getInfo('user_tz'));
|
||||
}
|
||||
|
||||
if(isset($inputArray['url_scan'])){
|
||||
$blog_settings->system->put('url_scan',$inputArray['url_scan']);
|
||||
}elseif(substr($blog_url,-1) == '?') {
|
||||
$blog_settings->system->put('url_scan','query_string');
|
||||
} else {
|
||||
$blog_settings->system->put('url_scan','path_info');
|
||||
}
|
||||
|
||||
# --BEHAVIOR-- adminAfterBlogCreate
|
||||
$core->callBehavior('adminAfterBlogCreate',$cur,$blog_id,$blog_settings);
|
||||
|
||||
//cool
|
||||
$this->response_code = 201;
|
||||
$this->response_message = array(
|
||||
'code' => 201,
|
||||
'id' => $blog_id,
|
||||
'message' => 'Successfully created blog'.$blog_id
|
||||
);
|
||||
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
$this->response_code = 500;
|
||||
$this->response_message = array(
|
||||
'code' => 500,
|
||||
'message' => $e->getMessage()
|
||||
);
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
<?php
|
||||
class RestQueryPostCategories extends RestQuery
|
||||
{
|
||||
|
||||
|
||||
public function __construct($args,$body){
|
||||
|
||||
global $core;
|
||||
$explodedArgs = explode("/",$args);
|
||||
$this->blog_id = $explodedArgs[0];
|
||||
$this->required_perms = 'none'; //To do
|
||||
|
||||
if($core->auth === false){
|
||||
$core->auth = new restAuth($core); //class dcBlog need it
|
||||
$unauth = true;
|
||||
}
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
if(!$core->blog->id){
|
||||
//Le blog n'existe pas
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
$blog_settings = new dcSettings($core,$this->blog_id);
|
||||
|
||||
if($this->is_allowed() === false){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$clientQueryArr = json_decode($body, true);
|
||||
if(empty($clientQueryArr)){
|
||||
$this->response_code = 400;
|
||||
$this->response_message = array(
|
||||
'error' => 'Can\'t parse input JSON'.$body,
|
||||
'code' => 400
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if(!$this->check_for_required_fields(
|
||||
$clientQueryArr,
|
||||
array('cat_title'), //required fields
|
||||
array('cat_url','cat_desc','cat_parent_id','cat_position','temporary') //facultatives fields
|
||||
)){
|
||||
return;
|
||||
}
|
||||
|
||||
//$id = $this->createCategory($clientQueryArr);
|
||||
$cats = new RestCategories($core);
|
||||
if($cats->cat_titleExists($clientQueryArr['cat_title'])){
|
||||
$this->response_code = 409;
|
||||
$this->response_message = array(
|
||||
'error' => 409,
|
||||
'message' => 'a cat with the same cat_title allready exists.'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $cats->addCategory($clientQueryArr);
|
||||
|
||||
|
||||
|
||||
if($id === false){
|
||||
$this->response_code = 500;
|
||||
$this->response_message = array(
|
||||
"error" => "Something is wrong",
|
||||
"code" => 500
|
||||
);
|
||||
}else{
|
||||
$this->response_code = 200;
|
||||
$this->response_message = array(
|
||||
"message" => "Successfully create category",
|
||||
"id" => $id
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,95 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
*Methode permettant de créer des métas (dont les tags)
|
||||
*/
|
||||
class RestQueryPostMetas extends RestQuery
|
||||
{
|
||||
|
||||
/*
|
||||
* Add a meta
|
||||
* if already exists, do nothing, does not generate warnings
|
||||
*/
|
||||
public function add_meta($meta_id,$meta_type,$post_id){
|
||||
global $core;
|
||||
//check if meta already exists
|
||||
$params = array('meta_id' => $meta_id, 'meta_type' => $meta_type, 'post_id' => $post_id);
|
||||
|
||||
$rs = $core->meta->getMetadata($params, false);
|
||||
if($rs->fetch()){
|
||||
return $rs->meta_id; //the meta already exists
|
||||
}elseif($core->meta->setPostMeta($post_id,$meta_type,$meta_id) === false){
|
||||
return false;
|
||||
}else{
|
||||
return $meta_id;
|
||||
}
|
||||
}
|
||||
|
||||
public function __construct($args,$body)
|
||||
{
|
||||
global $core;
|
||||
$explodedArgs = explode("/",$args);
|
||||
$this->blog_id = $explodedArgs[0];
|
||||
$this->required_perms = 'none'; //To do
|
||||
|
||||
if($core->auth === false){
|
||||
$core->auth = new restAuth($core);
|
||||
$unauth = true;
|
||||
}
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
if(!$core->blog->id){
|
||||
//Le blog n'existe pas
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
$blog_settings = new dcSettings($core,$this->blog_id);
|
||||
|
||||
if($this->is_allowed() === false){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$clientQueryArr = json_decode($body, true);
|
||||
|
||||
$createdIds = array();
|
||||
$clientQueryArr = $this->arrayOfObjetsOrNot($clientQueryArr,'meta_id');
|
||||
foreach($clientQueryArr as $query){
|
||||
|
||||
//check for needed fields
|
||||
if(!$this->check_for_required_fields($query,
|
||||
array('meta_id','meta_type','post_id'), //required fields
|
||||
array() //facultatives fields
|
||||
)){
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $this -> add_meta($query['meta_id'],$query['meta_type'],$query['post_id']);
|
||||
|
||||
if($id === false){
|
||||
$this->response_code = 500;
|
||||
$this->response_message = array("code" => 500,
|
||||
"message" => "An error occured while setting meta ".$query['meta_id']);
|
||||
return;
|
||||
}
|
||||
$createdIds[] = $id;
|
||||
|
||||
}
|
||||
|
||||
$this->response_code = 201;
|
||||
if(count($createdIds) == 1){
|
||||
$this->response_message = array(
|
||||
"code" => 200,
|
||||
"message" => "Successfully insert meta",
|
||||
"id" => $createdIds[0]
|
||||
);
|
||||
}else{
|
||||
$this->response_message = array(
|
||||
"code" => 200,
|
||||
"message" => "Successfully insert metas",
|
||||
"id" => $createdIds
|
||||
);
|
||||
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
|
@ -1,220 +0,0 @@
|
|||
<?php
|
||||
class RestQueryPostPost extends RestQuery{
|
||||
public function __construct($args,$body){
|
||||
global $core;
|
||||
$explodedArgs = explode("/",$args);
|
||||
$this->blog_id = $explodedArgs[0];
|
||||
$this->required_perms = 'none'; //To do
|
||||
|
||||
if($core->auth === false){
|
||||
$core->auth = new restAuth($core); //class dcBlog need it
|
||||
$unauth = true;
|
||||
}
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
if(!$core->blog->id){
|
||||
//Le blog n'existe pas
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
$blog_settings = new dcSettings($core,$this->blog_id);
|
||||
|
||||
if($this->is_allowed() === false){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$clientQueryArr = json_decode($body, true);
|
||||
if(empty($clientQueryArr)){
|
||||
$this->response_code = 400;
|
||||
$this->response_message = array(
|
||||
'error' => 'Can\'t parse input JSON'.$body,
|
||||
'code' => 400
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
//tester si plusieurs posts
|
||||
$allPosts = $this->arrayOfObjetsOrNot($clientQueryArr,'post_title');
|
||||
|
||||
//is it valid fields?
|
||||
foreach($allPosts as $p){
|
||||
if(!$this->check_for_required_fields(
|
||||
$p,
|
||||
array('post_title','post_format','post_content','post_status'), //required fields
|
||||
array('cat_id','new_cat_title','new_cat_parent_id','new_cat_position','post_dt','post_password',
|
||||
'post_lang','post_excerpt','post_excerpt_xhtml','post_content_xhtml',
|
||||
'post_notes','post_selected','post_open_comment','post_open_tb','post_url','post_tags') //facultatives fields
|
||||
)){
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$createdIds = array();
|
||||
//end of checks; lets submit new posts
|
||||
foreach($allPosts as $p){
|
||||
|
||||
//gestion de la categorie
|
||||
if(isset($p['new_cat_title'])){
|
||||
$params = array();
|
||||
$params['cat_title'] = $p['new_cat_title'];
|
||||
if(isset($p['new_cat_parent_id']))
|
||||
$params['cat_parent_id'] = $p['new_cat_parent_id'];
|
||||
else
|
||||
$params['cat_parent_id'] = null;
|
||||
if(isset($p['new_cat_position']))
|
||||
$params['cat_position'] = $p['new_cat_position'];
|
||||
else
|
||||
$params['cat_position'] = null;
|
||||
if(isset($p['new_cat_url']))
|
||||
$params['cat_url'] = $p['new_cat_url'];
|
||||
if(isset($p['new_cat_desc']))
|
||||
$params['cat_desc'] = $p['new_cat_desc'];
|
||||
|
||||
$cats = new RestCategories($core);
|
||||
|
||||
$cat_id = $cats->addCategory($params);
|
||||
|
||||
|
||||
if($cat_id === false){
|
||||
$this->response_message = 400;
|
||||
$this->response_message = array(
|
||||
"error" => "ERROR when creating the new category.",
|
||||
"code" => 400
|
||||
);
|
||||
return;
|
||||
|
||||
}
|
||||
}elseif(isset($p['cat_id'])){
|
||||
$cat_id = $core->con->escape($p['cat_id']);
|
||||
}else{
|
||||
$cat_id = null;
|
||||
}
|
||||
|
||||
|
||||
$cur = $core->con->openCursor($core->prefix.'post');
|
||||
$cur->post_title = $core->con->escape($p['post_title']);
|
||||
$cur->cat_id = $cat_id;
|
||||
if(isset($p['post_dt']))
|
||||
$cur->post_dt = $core->con->escape($p['post_dt']);
|
||||
else
|
||||
$cur->post_dt = '';
|
||||
$cur->post_format = $core->con->escape($p['post_format']); //mandatory field
|
||||
if(isset($p['post_password']))
|
||||
$cur->post_password = $core->con->escape($p['post_password']);
|
||||
else
|
||||
$cur->post_password = null;
|
||||
|
||||
if(isset($p['post_lang']))
|
||||
$cur->post_lang = $core->con->escape($p['post_lang']);
|
||||
else
|
||||
$cur->post_lang = '';
|
||||
|
||||
$cur->post_title = $core->con->escape($p['post_title']); //mandatory field
|
||||
|
||||
if(isset($p['post_excerpt']))
|
||||
$cur->post_excerpt = $core->con->escape($p['post_excerpt']);
|
||||
else
|
||||
$cur->post_excerpt = '';
|
||||
|
||||
|
||||
if(isset($p['post_excerpt_xhtml'])){
|
||||
|
||||
$cur->post_excerpt_xhtml = $core->con->escape($p['post_excerpt_xhtml']);
|
||||
|
||||
}elseif(($p['post_format'] == 'wiki') && (isset($p['post_excerpt']))) {
|
||||
$cur->post_excerpt_xhtml = $core->wikiTransform($p['post_excerpt']);
|
||||
}elseif(($p['post_format'] <> 'wiki') && (!isset($p['post_excerpt']))){
|
||||
$this->response_message = 400;
|
||||
$this->response_message = array(
|
||||
"error" => "ERROR. If not wiki format, give me post_exerpt_xhtml please.",
|
||||
"code" => 400
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$cur->post_content = $p['post_content']; //mandatory field
|
||||
|
||||
if($p['post_format'] == 'xhtml'){
|
||||
$cur->post_content_xhtml = $core->con->escape($p['post_content']);
|
||||
}elseif(isset($p['post_content_xhtml'])){
|
||||
$cur->post_content_xhtml = $core->con->escape($p['post_content_xhtml']);
|
||||
}elseif($p['post_format'] == 'wiki'){
|
||||
//convertir le format wiki en html
|
||||
$cur->post_content_xhtml = $core->wikiTransform($p['post_content']);
|
||||
}else{
|
||||
//sortir en erreur
|
||||
$this->response_code = 400;
|
||||
$this->response_message = array(
|
||||
"error" => "ERROR. If not wiki format, give me post_content_xhtml please.",
|
||||
"code" => 400
|
||||
);
|
||||
return;
|
||||
|
||||
}
|
||||
//$cur->post_notes = $post_notes; TO DO
|
||||
|
||||
$cur->post_status = $core->con->escape($p['post_status']); //mandatory field
|
||||
|
||||
if(isset($p['post_selected']))
|
||||
$cur->post_selected = (integer) $core->con->escape($p['post_selected']);
|
||||
else
|
||||
$cur->post_selected = 0;
|
||||
|
||||
if(isset($p['post_open_comment']))
|
||||
$cur->post_open_comment = (integer)$core->con->escape($p['post_open_comment']);
|
||||
else
|
||||
$cur->post_open_comment = 0;
|
||||
|
||||
if(isset($p['post_open_tb']))
|
||||
$cur->post_open_tb = (integer) $core->con->escape($p['post_open_tb']);
|
||||
else
|
||||
$cur->post_open_tb = 0;
|
||||
|
||||
if(isset($p['post_notes']))
|
||||
$cur->post_notes = $core->con->escape($p['post_notes']);
|
||||
|
||||
$cur->user_id = $core->auth->userID();
|
||||
|
||||
try {
|
||||
# --BEHAVIOR-- adminBeforePostCreate
|
||||
$core->callBehavior('adminBeforePostCreate',$cur);
|
||||
|
||||
$return_id = $core->blog->addPost($cur);
|
||||
$createdIds[] = $return_id;
|
||||
# --BEHAVIOR-- adminAfterPostCreate
|
||||
$core->callBehavior('adminAfterPostCreate',$cur,$return_id);
|
||||
|
||||
//les eventuels tags
|
||||
if(isset($p['post_tags'])){
|
||||
foreach($p['post_tags'] as $tag){
|
||||
RestQueryPostMetas::add_meta($tag,'tag',$return_id);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
$this->response_code = 500;
|
||||
$this->response_message = array(
|
||||
"code" => 500,
|
||||
"message" => $e->getMessage(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
$this->response_code = 200;
|
||||
if(count($createdIds) == 1){
|
||||
$id = (integer)$createdIds[0];
|
||||
}else{
|
||||
$id = $createdIds;
|
||||
}
|
||||
$this->response_message = array(
|
||||
"message" => "Successfully create post(s)",
|
||||
"id" => $id);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
<?php
|
||||
class ResQueryPutBlogs extends RestQuery
|
||||
{
|
||||
|
||||
|
||||
public function __construct($args,$body)
|
||||
{
|
||||
|
||||
global $core;
|
||||
|
||||
$this->blog_id = substr($args,6);
|
||||
$this->required_perms = 'admin';
|
||||
//Is allowed?
|
||||
if($this->is_allowed() === false){
|
||||
return;
|
||||
}
|
||||
|
||||
//Is JSON valid?
|
||||
$inputArray = $this-> body_to_array($body);
|
||||
if ($inputArray === false){
|
||||
return;
|
||||
}
|
||||
|
||||
//is it valid fields?
|
||||
if(!$this->check_for_required_fields( $inputArray, array('blog_id','blog_url','blog_name','blog_desc'), array())){
|
||||
return;
|
||||
}
|
||||
|
||||
//does the blog exists?
|
||||
$core->blog = new dcBlog($core, $this->blog_id);
|
||||
if(!$core->blog->id){
|
||||
//Le blog n'existe pas
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Resource '.$blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
$blog_settings = new dcSettings($core,$this->blog_id);
|
||||
|
||||
if(!$core->blog->id){
|
||||
$this->response_code = 404;
|
||||
$this->response_message = array('code' => 404, 'error' => 'Resource '.$this -> blog_id.' not found');
|
||||
return;
|
||||
}
|
||||
|
||||
$cur = $core->con->openCursor($core->prefix.'blog');
|
||||
|
||||
if(isset($inputArray['blog_id']))
|
||||
$cur->blog_id = $inputArray['blog_id'];
|
||||
else
|
||||
$cur->blog_id = $core->blog->id;
|
||||
|
||||
if(isset($inputArray['blog_url']))
|
||||
$cur->blog_url = preg_replace('/\?+$/','?', $inputArray['blog_url']);
|
||||
else
|
||||
$cur->blog_url = $core->blog->url;
|
||||
|
||||
if(isset($inputArray['blog_name']))
|
||||
$cur->blog_name = $inputArray['blog_name'];
|
||||
if(isset($inputArray['blog_desc']))
|
||||
$cur->blog_desc = $inputArray['blog_desc'];
|
||||
|
||||
$core->updBlog($this->blog_id,$cur);
|
||||
|
||||
//$cur->blog_upddt = date('Y-m-d H:i:s');
|
||||
//$cur->update("WHERE blog_id = '".$core->con->escape($id)."'");
|
||||
|
||||
$this -> response_code = 200;
|
||||
$this -> response_message = array(
|
||||
'code' => 200,
|
||||
'message' => 'blog '.$this->blog_id.' Successfully updated'
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
126
index.php
126
index.php
|
@ -1,126 +0,0 @@
|
|||
<?php
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')) { return; }
|
||||
|
||||
|
||||
$apiKey = new ApiKey;
|
||||
|
||||
// Setting default parameters if missing configuration
|
||||
$core->blog->settings->addNamespace('rest');
|
||||
if (is_null($core->blog->settings->rest->rest_active)) {
|
||||
try {
|
||||
$core->blog->settings->rest->put('rest_active',false,'boolean',true);
|
||||
$core->blog->settings->rest->put('rest_is_open',false,'boolean',true);
|
||||
$core->blog->settings->rest->put('rest_send_cors_headers',true,'boolean',true);
|
||||
$core->blog->triggerBlog();
|
||||
http::redirect($p_url);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$core->error->add($e->getMessage());
|
||||
}
|
||||
}
|
||||
// Getting current parameters
|
||||
$active = (boolean)$core->blog->settings->rest->rest_active;
|
||||
$openApi = (boolean)$core->blog->settings->rest->rest_is_open;
|
||||
$sendHeaders =(boolean)$core->blog->settings->rest->rest_send_cors_headers;
|
||||
|
||||
//Sousmission Formulaire parametres
|
||||
if ((!empty($_POST['saveconfig'])) && ($core->auth->isSuperAdmin())) {
|
||||
try
|
||||
{
|
||||
$core->blog->settings->addNameSpace('rest');
|
||||
$active = (empty($_POST['active'])) ? false : true;
|
||||
$core->blog->settings->rest->put('rest_active',$active,'boolean');
|
||||
|
||||
$openApi = (empty($_POST['open'])) ? false : true;
|
||||
$core->blog->settings->rest->put('rest_is_open',$openApi,'boolean');
|
||||
|
||||
$sendHeaders = (empty($_POST['sendHeaders'])) ? false : true;
|
||||
$core->blog->settings->rest->put('rest_send_cors_headers',$sendHeaders,'boolean');
|
||||
|
||||
dcPage::addSuccessNotice(__('Configuration successfully updated.'));
|
||||
http::redirect($p_url);
|
||||
}catch (Exception $e)
|
||||
{
|
||||
$core->error->add($e->getMessage());
|
||||
}
|
||||
}
|
||||
//Sousmission Formulaire Reset API Key
|
||||
if(!empty($_POST['resetApiKey'])){
|
||||
$core->blog->settings->addNameSpace('rest');
|
||||
$apiKey -> new_key($core->auth->userID());
|
||||
dcPage::addSuccessNotice(__('Your new key is').' '.$apiKey->key);
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title><?php echo __('REST API configuration'); ?></title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h2><?php echo __('Your API key');?></h2>
|
||||
<?php echo $apiKey-> get_dc_admin_form($core->auth->userID()); ?>
|
||||
|
||||
|
||||
<h2>Documentation</h2>
|
||||
<ul>
|
||||
<li><a href="<?php echo $core->blog->url."rest/documentation" . '" target="_blank" >' . __('Full documentation') .'</a></p>'; ?></li>
|
||||
</ul>
|
||||
|
||||
<h3><?php echo __('System methods'); ?> </h3>
|
||||
<ul>
|
||||
<li><a href="<?php echo $core->blog->url."rest/documentation/blogs" . '" target="_blank" >' . __('Search Create Read Update Replace').' blogs</a></p>'; ?></li>
|
||||
<li><a href="<?php echo $core->blog->url."rest/documentation/settings" . '" target="_blank" >' . __('Search Create Read Update Replace').' settings</a></p>'; ?></li>
|
||||
<li><a href="<?php echo $core->blog->url."rest/documentation/users" . '" target="_blank" >' . __('Search Create Read Update Replace').' users</a></p>'; ?></li> <li><a href="<?php echo $core->blog->url."rest/documentation/plugins" . '" target="_blank" >' . __('Search Create Read Update Replace').' plugins</a></p>'; ?></li>
|
||||
|
||||
</ul>
|
||||
<h3><?php echo __('Content management methods'); ?> </h3>
|
||||
<ul>
|
||||
<li><a href="<?php echo $core->blog->url."rest/documentation/posts" . '" target="_blank" >' . __('Search Create Read Update Replace').' Posts</a></p>'; ?></li>
|
||||
<li><a href="<?php echo $core->blog->url."rest/documentation/metas" . '" target="_blank" >' . __('Search Create Read Update Replace').' Metas</a></p>'; ?></li>
|
||||
<li><a href="<?php echo $core->blog->url."rest/documentation/categories" . '" target="_blank" >' . __('Search Create Read Update Replace').' Categories </a></p>'; ?></li>
|
||||
<li><a href="<?php echo $core->blog->url."rest/documentation/comments" . '" target="_blank" >' . __('Search Create Read Update Replace').' '.__('Comments').'</a></p>'; ?></li>
|
||||
|
||||
</ul>
|
||||
<h3><?php echo __('Public files methods'); ?> </h3>
|
||||
<ul>
|
||||
<li><a href="<?php echo $core->blog->url."rest/documentation/files" . '" target="_blank" >' . __('Search Create Read Update Replace').' '.__('files').'</a></p>'; ?></li>
|
||||
</ul>
|
||||
<h3><?php echo __('This API'); ?></h3>
|
||||
<ul>
|
||||
<li><a href="<?php echo $core->blog->url."rest/documentation/api" . '" target="_blank" >' . __('Methods to get documentation and extend this API').'</a></p>'; ?></li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
<?php
|
||||
//Seulement si administrateur:
|
||||
if($core->auth->isSuperAdmin()):
|
||||
?>
|
||||
<h2><?php echo __('Rest API configuration'); ?></h2>
|
||||
<form method="post" action="<?php http::getSelfURI(); ?>">
|
||||
<p>
|
||||
<?php echo form::checkbox('active', 1, $active); ?>
|
||||
<label class="classic" for="active"> <?php echo __('Enable REST API');?></label>
|
||||
</p>
|
||||
<p>
|
||||
<?php echo form::checkbox('open', 1, $openApi); ?>
|
||||
<label class="classic" for="open"> <?php echo __('API is open without key');?></label>
|
||||
</p>
|
||||
<p class="info"><?php echo __("If checked, few methods as GET will be allowed to externals users without API key. However, they won't be able to request for non public content."); ?></p>
|
||||
<?php echo $core->formNonce(); ?>
|
||||
<p>
|
||||
<?php echo form::checkbox('sendHeaders', 1, $sendHeaders); ?>
|
||||
<label class="classic" for="sendHeaders"> <?php echo __('Send Coors headers');?></label>
|
||||
</p>
|
||||
<p>
|
||||
<input type="submit" name="saveconfig" value="<?php echo __('Save configuration'); ?>" />
|
||||
</p>
|
||||
|
||||
</from>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
</body>
|
||||
</html>
|
|
@ -1,65 +0,0 @@
|
|||
msgid "Enable REST API"
|
||||
msgstr "Activer l'API REST"
|
||||
|
||||
msgid "Your API key"
|
||||
msgstr "Votre clef"
|
||||
|
||||
msgid "Your new key is"
|
||||
msgstr "Votre nouvelle clef est"
|
||||
|
||||
msgid "API is open without key"
|
||||
msgstr "L'API est ouverte sans authentification"
|
||||
|
||||
msgid "Rest API configuration"
|
||||
msgstr "Configuration de l'API"
|
||||
|
||||
msgid "If checked, few methods as GET will be allowed to externals users without API key. However, they won't be able to request for non public content."
|
||||
msgstr "Si coché, Certaines méthodes seront accessibles sans authentification par clef (ni aucune autre authentification). Cependant, seules les actions et informations normalement accessibles sur le blog par les visiteurs non authentifiés sont concernés."
|
||||
|
||||
msgid "Send Coors headers"
|
||||
msgstr "Insérer les Headers autorisant les requêtes cross domaine"
|
||||
|
||||
msgid "Save configuration"
|
||||
msgstr "Enregistrer la configuration"
|
||||
|
||||
msgid "REST API configuration"
|
||||
msgstr "Configurer l'API REST JSON"
|
||||
|
||||
msgid "Documentation and test interface Swagger UI"
|
||||
msgstr "Documentation et interface de test de l'API via Swagger UI"
|
||||
|
||||
msgid "Your api key has already been created."
|
||||
msgstr "Votre clef a déjà été générée"
|
||||
|
||||
msgid "Erase existing API key and generate a new one for"
|
||||
msgstr "Réinitialiser la clef de "
|
||||
|
||||
msgid "No API key found."
|
||||
msgstr "La clef de l'API n'a pas été initialisée"
|
||||
|
||||
msgid "Generate a API key for"
|
||||
msgstr "Créer une clef pour"
|
||||
|
||||
msgid "Copy and paste it, You will cannot see it again."
|
||||
msgstr "Copiez collez la. Cette clef ne pourra pas vous être refournie."
|
||||
|
||||
msgid "Full documentation"
|
||||
msgstr "Documentation complète"
|
||||
|
||||
msgid "System methods"
|
||||
msgstr "Méthodes système"
|
||||
|
||||
msgid "Content management methods"
|
||||
msgstr "Méthodes de gestion du contenu"
|
||||
|
||||
msgid "Public files methods"
|
||||
msgstr "Gestion de la médiathèque"
|
||||
|
||||
msgid "Search Create Read Update Replace"
|
||||
msgstr "Chercher Créer Lire Modifier Supprimer"
|
||||
|
||||
msgid "This API"
|
||||
msgstr "Cette API"
|
||||
|
||||
msgid "Methods to get documentation and extend this API"
|
||||
msgstr "Méthodes pour obtenir la documentation et etendre cette API"
|
BIN
rest_api.png
BIN
rest_api.png
Binary file not shown.
Before Width: | Height: | Size: 675 B |
|
@ -1,11 +0,0 @@
|
|||
#Unit tests
|
||||
|
||||
Change the parameters at the beginning of test-API.php and use it in console mode
|
||||
|
||||
php test-API.php
|
||||
|
||||
This will test all the API methods.
|
||||
Use this tests only on a developpement platform of Dotclear.
|
||||
|
||||
These tests are for the developer (me). I'm tired of systematically retest everything as I progress in development.
|
||||
Incidentally, they also serve as an example on the use of the API.
|
|
@ -1,708 +0,0 @@
|
|||
<?php
|
||||
|
||||
$api_key = 'G3OenlFITbzR5PWvLNWlId9quqsqibuo'; //super admin api_key, change it by your
|
||||
$api_url = 'http://dotclear.localhost/rest'; //my local dev platform, change it by your
|
||||
//testUser key DVsmYPmW6jvfk4kgak1krvbxcl1nGXMJ
|
||||
|
||||
function check_json_content($content,$aKeyToCheck,$responseIsArrayOfObjects){
|
||||
|
||||
$arr=json_decode($content,true);
|
||||
if($responseIsArrayOfObjects){
|
||||
$arr = $arr[0];
|
||||
}
|
||||
if(($aKeyToCheck == '') && (is_array($arr))){
|
||||
return true;
|
||||
}
|
||||
|
||||
if(isset($arr[$aKeyToCheck])){
|
||||
return $arr[$aKeyToCheck];
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function test($url, $method, $body, $expectedCode,$responseIsArrayOfObjects, $expectedKeyOnResponse, $x_dc_key){
|
||||
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
|
||||
if($x_dc_key <> ''){
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('x_dc_key: '.$x_dc_key));
|
||||
}
|
||||
if($body <> ''){
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
|
||||
}
|
||||
$response = curl_exec($ch);
|
||||
$httpCode = curl_getinfo($ch)['http_code'];
|
||||
|
||||
if($httpCode <> $expectedCode){
|
||||
echo "\nQuery type ".$method." on url ".$url." didn't return the expected code.\n".
|
||||
"return: ".$httpCode." Expected: ".$expectedCode."\n".
|
||||
"Response content:\n".$response;
|
||||
//on va pas plus loin, ça pourrait mettre la m... dans la suite
|
||||
die();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$r = check_json_content($response ,$expectedKeyOnResponse,$responseIsArrayOfObjects);
|
||||
if($r === false){
|
||||
echo "\nQuery type ".$method." on url ".$url." JSON parse error or missing property.\n".
|
||||
"return code: ".$httpCode."\n".
|
||||
"Response content:\n".$response;
|
||||
//on va pas plus loin, ça pourrait mettre la m... dans la suite
|
||||
die();
|
||||
return;
|
||||
}
|
||||
curl_close($ch);
|
||||
return $r;
|
||||
}
|
||||
|
||||
|
||||
$allTests = array(
|
||||
array(
|
||||
'title' => 'test 404 page',
|
||||
'url' => $api_url.'/kgdghui',
|
||||
'method' => 'GET',
|
||||
'expectedResponseCode' => '404',
|
||||
'expectedKeyOnResponse' => 'error',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'body' => '',
|
||||
'x_dc_key' => '',
|
||||
'saveAs' => ''
|
||||
|
||||
),
|
||||
array(
|
||||
'title' => 'test specs Method',
|
||||
'url' => $api_url.'/specs',
|
||||
'method' => 'GET',
|
||||
'expectedResponseCode' => '200',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'swagger',
|
||||
'body' => '',
|
||||
'x_dc_key' => '',
|
||||
'saveAs' => ''
|
||||
|
||||
),
|
||||
array(
|
||||
'title' => 'get /blogs without api_key',
|
||||
'url' => $api_url.'/blogs',
|
||||
'method' => 'GET',
|
||||
'expectedResponseCode' => '403',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'error',
|
||||
'body' => '',
|
||||
'x_dc_key' => '',
|
||||
'saveAs' => ''
|
||||
|
||||
),
|
||||
array(
|
||||
'title' => 'get /blogs with wrong api_key',
|
||||
'url' => $api_url.'/blogs',
|
||||
'method' => 'GET',
|
||||
'expectedResponseCode' => '403',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'error',
|
||||
'body' => '',
|
||||
'x_dc_key' => '7777777777777',
|
||||
'saveAs' => ''
|
||||
|
||||
),
|
||||
array(
|
||||
'title' => 'get /blogs with good api_key',
|
||||
'url' => $api_url.'/blogs',
|
||||
'method' => 'GET',
|
||||
'expectedResponseCode' => '200',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => false, //is a single list
|
||||
'body' => '',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
|
||||
),
|
||||
//creer un blog qui servira aux tests suivants
|
||||
array(
|
||||
'title' => 'post /blogs/ with good api_key',
|
||||
'url' => $api_url.'/blogs',
|
||||
'method' => 'POST',
|
||||
'expectedResponseCode' => '201',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'id', //is a single list
|
||||
'body' => json_encode(array(
|
||||
"blog_id" => "test-api",
|
||||
"blog_name" => "Test de l'API",
|
||||
"blog_url" => "http://test.localhost/",
|
||||
"blog_desc"=> "un test"
|
||||
)),
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => 'blog_id'
|
||||
|
||||
),
|
||||
|
||||
//test JSON deffectueux
|
||||
array(
|
||||
'title' => 'post /blogs/ with good api_key and bad JSON',
|
||||
'url' => $api_url.'/blogs',
|
||||
'method' => 'POST',
|
||||
'expectedResponseCode' => '400',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'error',
|
||||
'body' => '{"ce n\'est pas du" => "JSON"}',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
|
||||
),
|
||||
|
||||
//get blog Properties
|
||||
array(
|
||||
'title' => 'Blogs /blogs/%blog_id% with good api_key',
|
||||
'url' => $api_url.'/blogs/%blog_id%',
|
||||
'method' => 'GET',
|
||||
'expectedResponseCode' => '200',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'blog_url',
|
||||
'body' => '',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
|
||||
),
|
||||
|
||||
//Patch blog properties with error ON JSON
|
||||
array(
|
||||
'title' => 'PATCH /blogs/%blog_id% with with error ON JSON',
|
||||
'url' => $api_url.'/blogs/%blog_id%',
|
||||
'method' => 'PATCH',
|
||||
'expectedResponseCode' => '400',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'error',
|
||||
'body' => '{JSON IS FUN}',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => 'PATCH /blogs/%blog_id% with with error ON api_key',
|
||||
'url' => $api_url.'/blogs/%blog_id%',
|
||||
'method' => 'PATCH',
|
||||
'expectedResponseCode' => '403',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'error',
|
||||
'body' => '{"blog_name": "Patched Blog name"}',
|
||||
'x_dc_key' => 'heyHey!',
|
||||
'saveAs' => ''
|
||||
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => 'PATCH /blogs/%blog_id% without error',
|
||||
'url' => $api_url.'/blogs/%blog_id%',
|
||||
'method' => 'PATCH',
|
||||
'expectedResponseCode' => '200',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'message',
|
||||
'body' => '{"blog_name": "Patched Blog name"}',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
|
||||
),
|
||||
|
||||
//PUT
|
||||
//Patch blog properties with error ON JSON
|
||||
array(
|
||||
'title' => 'PUT /blogs/%blog_id% with error ON JSON',
|
||||
'url' => $api_url.'/blogs/%blog_id%',
|
||||
'method' => 'PUT',
|
||||
'expectedResponseCode' => '400',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'error',
|
||||
'body' => '{JSON IS FUN}',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => 'PUT /blogs/%blog_id% with with error ON api_key',
|
||||
'url' => $api_url.'/blogs/%blog_id%',
|
||||
'method' => 'PUT',
|
||||
'expectedResponseCode' => '403',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'error',
|
||||
'body' => '{"blog_id": "%blog_id%","blog_url":"https://plop.local/", "blog_name": "Patched Blog name", "blog_desc": "blahblah"}',
|
||||
'x_dc_key' => 'heyHey!',
|
||||
'saveAs' => ''
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => 'PUT/blogs/%blog_id% without error',
|
||||
'url' => $api_url.'/blogs/%blog_id%',
|
||||
'method' => 'PUT',
|
||||
'expectedResponseCode' => '200',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'message',
|
||||
'body' => '{"blog_id": "%blog_id%","blog_url":"https://plop.local/", "blog_name": "Patched Blog name", "blog_desc": "blahblah"}',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
|
||||
//get settings
|
||||
array(
|
||||
'title' => 'GET /%blog_id%/settings without error',
|
||||
'url' => $api_url.'/%blog_id%/settings',
|
||||
'method' => 'GET',
|
||||
'expectedResponseCode' => '200',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'system',
|
||||
'body' => '',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
//get settings
|
||||
array(
|
||||
'title' => 'GET /%blog_id%/settings/system without error',
|
||||
'url' => $api_url.'/%blog_id%/settings/system',
|
||||
'method' => 'GET',
|
||||
'expectedResponseCode' => '200',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'url_scan',
|
||||
'body' => '',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
array(
|
||||
'title' => 'GET /%blog_id%/settings/system/url_scan without error',
|
||||
'url' => $api_url.'/%blog_id%/settings/system/url_scan',
|
||||
'method' => 'GET',
|
||||
'expectedResponseCode' => '200',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'value',
|
||||
'body' => '',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
array(
|
||||
'title' => 'GET /%blog_id%/settings/HEYHEY/url_scan without error',
|
||||
'url' => $api_url.'/%blog_id%/settings/HEYHEY/url_scan',
|
||||
'method' => 'GET',
|
||||
'expectedResponseCode' => '404',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'code',
|
||||
'body' => '',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => 'POST /%blog_id%/settings/test without error',
|
||||
'url' => $api_url.'/%blog_id%/settings/test',
|
||||
'method' => 'POST',
|
||||
'expectedResponseCode' => '201',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'code',
|
||||
'body' => '[{"id":"test","value":"hey","type":"string"},{"id":"test2","value":"hey","type":"string"}]',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
array(
|
||||
'title' => 'POST /%blog_id%/settings/test without api key',
|
||||
'url' => $api_url.'/%blog_id%/settings/test',
|
||||
'method' => 'POST',
|
||||
'expectedResponseCode' => '403',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'code',
|
||||
'body' => '[{"id":"test2","value":"hey","type":"string"}]',
|
||||
'x_dc_key' => '',
|
||||
'saveAs' => ''
|
||||
),
|
||||
array(
|
||||
'title' => 'POST /%blog_id%/settings/test with fail JSON',
|
||||
'url' => $api_url.'/%blog_id%/settings/test',
|
||||
'method' => 'POST',
|
||||
'expectedResponseCode' => '400',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'code',
|
||||
'body' => '[{"id"=> Hey"test2","value":"hey","type":"string"}]',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
|
||||
//delete the settings
|
||||
array(
|
||||
'title' => 'DELETE /%blog_id%/settings/test/test2 with key error',
|
||||
'url' => $api_url.'/%blog_id%/settings/test/test2',
|
||||
'method' => 'DELETE',
|
||||
'expectedResponseCode' => '403',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'code',
|
||||
'body' => '',
|
||||
'x_dc_key' => 'lkjmlhkjb:b:kjb',
|
||||
'saveAs' => ''
|
||||
),
|
||||
array(
|
||||
'title' => 'DELETE /%blog_id%/settings/test/tsdfLJKt2 with name error',
|
||||
'url' => $api_url.'/%blog_id%/settings/test/tsdfLJKt2',
|
||||
'method' => 'DELETE',
|
||||
'expectedResponseCode' => '404',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'code',
|
||||
'body' => '',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => 'DELETE /%blog_id%/settings/test/test2 without error',
|
||||
'url' => $api_url.'/%blog_id%/settings/test/test2',
|
||||
'method' => 'DELETE',
|
||||
'expectedResponseCode' => '200',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'code',
|
||||
'body' => '',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
|
||||
|
||||
//Categories
|
||||
|
||||
//create an new category
|
||||
array(
|
||||
'title' => 'Create an new Category named cat3',
|
||||
'url' => $api_url.'/%blog_id%/post/categories',
|
||||
'method' => 'POST',
|
||||
'expectedResponseCode' => 200,
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'id',
|
||||
'body' => json_encode(array(
|
||||
"cat_title" => "Cat 3",
|
||||
)),
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => 'cat3'
|
||||
),
|
||||
array(
|
||||
'title' => 'Create an new Category named 2',
|
||||
'url' => $api_url.'/%blog_id%/post/categories',
|
||||
'method' => 'POST',
|
||||
'expectedResponseCode' => 200,
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'id',
|
||||
'body' => json_encode(array(
|
||||
"cat_title" => "Cat 2",
|
||||
)),
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => 'cat2'
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => 'Create an new Category named 1',
|
||||
'url' => $api_url.'/%blog_id%/post/categories',
|
||||
'method' => 'POST',
|
||||
'expectedResponseCode' => 200,
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'id',
|
||||
'body' => json_encode(array(
|
||||
"cat_title" => "Cat 1",
|
||||
)),
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => 'cat1'
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => 'Create an new sub Category named 2.1',
|
||||
'url' => $api_url.'/%blog_id%/post/categories',
|
||||
'method' => 'POST',
|
||||
'expectedResponseCode' => 200,
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'id',
|
||||
'body' => json_encode(array(
|
||||
"cat_title" => "Cat 2.1",
|
||||
"cat_parent_id" => '%cat2%'
|
||||
)),
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => 'cat21'
|
||||
),
|
||||
|
||||
//another cat
|
||||
array(
|
||||
'title' => 'Create an new Category named 3 that allready exists',
|
||||
'url' => $api_url.'/%blog_id%/post/categories',
|
||||
'method' => 'POST',
|
||||
'expectedResponseCode' => 409,
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'error',
|
||||
'body' => json_encode(array(
|
||||
"cat_title" => "Cat 3"
|
||||
)),
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
|
||||
//change the parent of cat 2.1
|
||||
array(
|
||||
'title' => 'Change cat parent',
|
||||
'url' => $api_url.'/%blog_id%/categories/%cat21%',
|
||||
'method' => 'PATCH',
|
||||
'expectedResponseCode' => 201,
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'id',
|
||||
'body' => '{"cat_parent_id": %cat3%}',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
|
||||
//create a POST
|
||||
|
||||
array(
|
||||
'title' => 'Create a post /%blog_id%/post',
|
||||
'url' => $api_url.'/%blog_id%/post',
|
||||
'method' => 'POST',
|
||||
'expectedResponseCode' => '200',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'id',
|
||||
'body' => json_encode(array(
|
||||
"post_title" => "New Post",
|
||||
"post_format"=> "wiki",
|
||||
"post_content"=> "!!!Pouette \n hey",
|
||||
"post_content_xhtml"=> "string",
|
||||
"post_status"=> 0,
|
||||
"post_tags" => array('plip','plap')
|
||||
)),
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => 'post_id'
|
||||
|
||||
),
|
||||
//plusieurs billets d'un coup
|
||||
array(
|
||||
'title' => 'Create many post /%blog_id%/post',
|
||||
'url' => $api_url.'/%blog_id%/post',
|
||||
'method' => 'POST',
|
||||
'expectedResponseCode' => '200',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'message',
|
||||
'body' => json_encode(array(
|
||||
array(
|
||||
"post_title" => "New Post2",
|
||||
"post_format"=> "wiki",
|
||||
"post_content"=> "!!!Pouette \n hey",
|
||||
"post_content_xhtml"=> "string",
|
||||
"post_status"=> 0,
|
||||
),
|
||||
array(
|
||||
"post_title" => "New Post3",
|
||||
"post_format"=> "wiki",
|
||||
"post_content"=> "!!!Pouette \n\n!!hey\n heu...",
|
||||
"post_content_xhtml"=> "string",
|
||||
"post_status"=> 0,
|
||||
)
|
||||
)),
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
|
||||
),
|
||||
|
||||
//create a post with a new category
|
||||
array(
|
||||
'title' => 'Create a post /%blog_id%/post with a new cat',
|
||||
'url' => $api_url.'/%blog_id%/post',
|
||||
'method' => 'POST',
|
||||
'expectedResponseCode' => '200',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'id',
|
||||
'body' => json_encode(array(
|
||||
"post_title" => "New Post4",
|
||||
"post_format"=> "wiki",
|
||||
"post_content"=> "!!!Pouette \n hey",
|
||||
"post_content_xhtml"=> "string",
|
||||
"post_status"=> 0,
|
||||
"new_cat_title"=> "TestingCat",
|
||||
)),
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
|
||||
//create a post with an existing category
|
||||
array(
|
||||
'title' => 'Create a post /%blog_id%/post with an existing cat %cat_id%',
|
||||
'url' => $api_url.'/%blog_id%/post',
|
||||
'method' => 'POST',
|
||||
'expectedResponseCode' => '200',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'message',
|
||||
'body' => json_encode(array(
|
||||
"post_title" => "New Post5",
|
||||
"post_format"=> "wiki",
|
||||
"post_content"=> "!!!Pouette \n hey",
|
||||
"post_content_xhtml"=> "string",
|
||||
"post_status"=> 0,
|
||||
"cat_id"=> '%cat21%',
|
||||
)),
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
|
||||
//create a post with a new sub category
|
||||
array(
|
||||
'title' => 'Create a post /%blog_id%/post',
|
||||
'url' => $api_url.'/%blog_id%/post',
|
||||
'method' => 'POST',
|
||||
'expectedResponseCode' => '200',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'message',
|
||||
'body' => json_encode(array(
|
||||
"post_title" => "New Post6",
|
||||
"post_format"=> "wiki",
|
||||
"post_content"=> "!!!Pouette \n hey",
|
||||
"post_content_xhtml"=> "string",
|
||||
"post_status"=> 0,
|
||||
"new_cat_parent_id" => "%cat3%",
|
||||
"new_cat_title"=> "Testing sub Cat",
|
||||
)),
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
|
||||
array(
|
||||
'title' => 'Create a post /%blog_id%/post with all parameters',
|
||||
'url' => $api_url.'/%blog_id%/post',
|
||||
'method' => 'POST',
|
||||
'expectedResponseCode' => '200',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'message',
|
||||
'body' =>'{
|
||||
"post_title":"New Post6",
|
||||
"post_format":"wiki",
|
||||
"post_content":"!!!Pouette \n hey",
|
||||
"post_content_xhtml":"string",
|
||||
"post_status":0,
|
||||
"new_cat_parent_id":%cat21%,
|
||||
"new_cat_title":"Testing sub Cat 2",
|
||||
"post_dt":"2013-04-19 05:06:07",
|
||||
"post_password":"toto",
|
||||
"post_url":"newPost",
|
||||
"post_lang":"de",
|
||||
"post_excerpt":"blahblah",
|
||||
"post_notes":"heu...",
|
||||
"post_selected":true,
|
||||
"post_open_comment":true,
|
||||
"post_open_tb":true
|
||||
}',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
|
||||
|
||||
//Créer une méta (un tag)
|
||||
array(
|
||||
"title" => 'Create a post meta /%blog_id%/metas',
|
||||
'url' => $api_url.'/%blog_id%/metas',
|
||||
'method' => 'POST',
|
||||
'expectedResponseCode' => '201',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => 'id',
|
||||
'body' => '{ "meta_id": "lol", "meta_type": "tag", "post_id": %post_id% }',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => 'meta_id'
|
||||
),
|
||||
|
||||
//Get metas
|
||||
array(
|
||||
'title' => 'get all meta /%blog_id%/metas',
|
||||
'url' => $api_url.'/%blog_id%/metas',
|
||||
'method' => 'GET',
|
||||
'expectedResponseCode' => '200',
|
||||
'responseIsArrayOfObjects' => true,
|
||||
'expectedKeyOnResponse' => 'meta_id',
|
||||
'body' => '',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
array(
|
||||
'title' => 'get all meta /%blog_id%/metas?meta_type=tag',
|
||||
'url' => $api_url.'/%blog_id%/metas',
|
||||
'method' => 'GET',
|
||||
'expectedResponseCode' => '200',
|
||||
'responseIsArrayOfObjects' => true,
|
||||
'expectedKeyOnResponse' => 'meta_id',
|
||||
'body' => '',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
// delete a meta
|
||||
array(
|
||||
'title' => 'delete q meta /%blog_id%/%post_id%/meta/%meta_id%',
|
||||
'url' => $api_url.'/%blog_id%/%post_id%/meta/%meta_id%',
|
||||
'method' => 'DELETE',
|
||||
'expectedResponseCode' => '200',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => false,
|
||||
'body' => '',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
// delete all metas for a blog
|
||||
array(
|
||||
'title' => 'delete q meta /%blog_id%/%post_id%/metas',
|
||||
'url' => $api_url.'/%blog_id%/%post_id%/metas',
|
||||
'method' => 'DELETE',
|
||||
'expectedResponseCode' => '200',
|
||||
'responseIsArrayOfObjects' => false,
|
||||
'expectedKeyOnResponse' => false,
|
||||
'body' => '',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
),
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
,
|
||||
//remove blog test
|
||||
array(
|
||||
'title' => 'Blogs /blogs/%blog_id% with good api_key',
|
||||
'url' => $api_url.'/blogs/%blog_id%',
|
||||
'method' => 'DELETE',
|
||||
'expectedResponseCode' => '201',
|
||||
'expectedKeyOnResponse' => 'message', //is a single list
|
||||
'body' => '',
|
||||
'x_dc_key' => $api_key,
|
||||
'saveAs' => ''
|
||||
|
||||
),
|
||||
*/
|
||||
);
|
||||
|
||||
$saveIds = array();
|
||||
foreach($allTests as $oneTest){
|
||||
|
||||
//replaces
|
||||
foreach($oneTest as $key => $value){
|
||||
foreach($saveIds as $find => $replace){
|
||||
if(is_string($value)){
|
||||
$value = $oneTest[$key] = str_replace('%'.$find.'%', $replace, (string)$value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
echo "\nTesting ".$oneTest['title']." ".$oneTest['url']." method ". $oneTest['method'];
|
||||
$t = test(
|
||||
$oneTest['url'],
|
||||
$oneTest['method'],
|
||||
$oneTest['body'],
|
||||
$oneTest['expectedResponseCode'],
|
||||
$oneTest['responseIsArrayOfObjects'],
|
||||
$oneTest['expectedKeyOnResponse'],
|
||||
$oneTest['x_dc_key']
|
||||
);
|
||||
echo "\nSUCCESS ".$t;
|
||||
|
||||
if ($oneTest['saveAs'] <> ''){
|
||||
$saveIds[$oneTest['saveAs']] = $t;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user