first commit
This commit is contained in:
674
wp-content/plugins/updraftplus/includes/onedrive/LICENSE
Normal file
674
wp-content/plugins/updraftplus/includes/onedrive/LICENSE
Normal file
@@ -0,0 +1,674 @@
|
||||
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>.
|
||||
959
wp-content/plugins/updraftplus/includes/onedrive/client.php
Normal file
959
wp-content/plugins/updraftplus/includes/onedrive/client.php
Normal file
@@ -0,0 +1,959 @@
|
||||
<?php
|
||||
namespace Onedrive;
|
||||
|
||||
/*
|
||||
* A Client instance allows communication with the OneDrive API and perform
|
||||
* operations programmatically.
|
||||
*
|
||||
* For an overview of the OneDrive protocol flow, see here:
|
||||
* http://msdn.microsoft.com/en-us/library/live/hh243647.aspx
|
||||
*
|
||||
* To manage your Live Connect applications, see here:
|
||||
* https://account.live.com/developers/applications/index
|
||||
* Or here:
|
||||
* https://manage.dev.live.com/ (not working?)
|
||||
*
|
||||
* For an example implementation, see here:
|
||||
* https://github.com/drumaddict/skydrive-api-yii/blob/master/SkyDriveAPI.php
|
||||
*/
|
||||
// TODO: support refresh tokens: http://msdn.microsoft.com/en-us/library/live/hh243647.aspx
|
||||
// TODO: pass parameters in POST request body when obtaining the access token
|
||||
class Client {
|
||||
|
||||
// Client information.
|
||||
private $_clientId;
|
||||
|
||||
// OAuth state (token, etc...).
|
||||
private $_state;
|
||||
|
||||
// The last HTTP status received.
|
||||
private $_httpStatus;
|
||||
|
||||
// The last Content-Type received.
|
||||
private $_contentType;
|
||||
|
||||
// Verify SSL hosts and peers.
|
||||
private $_sslVerify;
|
||||
|
||||
// Over-ride SSL CA path for verification (only relevant when verifying).
|
||||
private $_sslCAPath;
|
||||
|
||||
private $safeMode;
|
||||
|
||||
private $use_msgraph_api;
|
||||
|
||||
private $api_url;
|
||||
|
||||
private $route_prefix;
|
||||
|
||||
// The base URL for authorization requests.
|
||||
private $auth_url;
|
||||
|
||||
// The base URL for token requests.
|
||||
private $token_url;
|
||||
|
||||
/**
|
||||
* Creates a base cURL object which is compatible with the OneDrive API.
|
||||
*
|
||||
* @param (string) $path - The path of the API call (eg. me/skydrive).
|
||||
* @param (array) $options - Further curl options to set.
|
||||
* @return (resource) A compatible cURL object.
|
||||
*/
|
||||
private function _createCurl($path, $options = array()) {
|
||||
$curl = curl_init();
|
||||
$curl_version = curl_version();
|
||||
$curl_version = isset($curl_version['version']) ? $curl_version['version'] : '0';
|
||||
|
||||
$default_options = array(
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
|
||||
CURLOPT_SSL_VERIFYHOST => ($this->_sslVerify ? 2 : false),
|
||||
CURLOPT_SSL_VERIFYPEER => $this->_sslVerify,
|
||||
|
||||
CURLOPT_AUTOREFERER => true,
|
||||
);
|
||||
|
||||
if (version_compare($curl_version, '8.0', '<') && version_compare($curl_version, '7.62', '>=')) $default_options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1;
|
||||
if (defined('UPDRAFTPLUS_ONEDRIVE_CURL_HTTP_VERSION')) $default_options[CURLOPT_HTTP_VERSION] = UPDRAFTPLUS_ONEDRIVE_CURL_HTTP_VERSION;
|
||||
|
||||
if ($this->_sslVerify && $this->_sslCAPath) {
|
||||
$default_options[CURLOPT_CAINFO] = $this->_sslCAPath;
|
||||
}
|
||||
|
||||
// Prevent misleading PHP notice
|
||||
if (!$this->safeMode) $default_options[CURLOPT_FOLLOWLOCATION] = true;
|
||||
|
||||
// See http://php.net/manual/en/function.array-merge.php for a description of the + operator (and why array_merge() would be wrong)
|
||||
$final_options = $options + $default_options;
|
||||
|
||||
curl_setopt_array($curl, $final_options);
|
||||
|
||||
return $curl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes a result returned by the OneDrive API call using a cURL object.
|
||||
*
|
||||
* @param (resource) $curl - The cURL object used to perform the call.
|
||||
* @return (object|string) The content returned, as an object instance if
|
||||
* served a JSON, or as a string if served as anything else.
|
||||
*/
|
||||
private function _processResult($curl) {
|
||||
$result = curl_exec($curl);
|
||||
|
||||
if (false === $result) {
|
||||
throw new \Exception('curl_exec() failed: ' . curl_error($curl)); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Error message to be escaped when caught and printed.
|
||||
}
|
||||
|
||||
$info = curl_getinfo($curl);
|
||||
|
||||
$this->_httpStatus = array_key_exists('http_code', $info) ?
|
||||
(int) $info['http_code'] : null;
|
||||
|
||||
$this->_contentType = array_key_exists('content_type', $info) ?
|
||||
(string) $info['content_type'] : null;
|
||||
|
||||
|
||||
// Parse nothing but JSON.
|
||||
if (1 !== preg_match('|^application/json|', $this->_contentType)) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Empty JSON string is returned as an empty object.
|
||||
if ('' == $result) {
|
||||
return (object) array();
|
||||
}
|
||||
|
||||
$decoded = json_decode($result);
|
||||
$vars = get_object_vars($decoded);
|
||||
|
||||
if (array_key_exists('error', $vars)) {
|
||||
throw new \Exception($decoded->error->message, (int) $decoded->error->code); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Error message to be escaped when caught and printed.
|
||||
}
|
||||
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param (array) $options. The options to use while creating this object.
|
||||
* Valid supported keys are:
|
||||
* 'state': When defined, it should contain a valid OneDrive client
|
||||
* state, as returned by getState(). Default: array().
|
||||
* (boolean)'ssl_verify': whether to verify SSL hosts and peers (default: false)
|
||||
* (boolean|string)'ssl_capath': CA path to use for verifying SSL certificate chain (default: false)
|
||||
*/
|
||||
public function __construct(array $options = array()) {
|
||||
$this->_clientId = array_key_exists('client_id', $options)
|
||||
? (string) $options['client_id'] : null;
|
||||
|
||||
$this->_state = array_key_exists('state', $options)
|
||||
? $options['state'] : (object) array(
|
||||
'redirect_uri' => null,
|
||||
'token' => null
|
||||
);
|
||||
|
||||
$this->_sslVerify = array_key_exists('ssl_verify', $options)
|
||||
? $options['ssl_verify'] : false;
|
||||
|
||||
$this->_sslCAPath = array_key_exists('ssl_capath', $options)
|
||||
? $options['ssl_capath'] : false;
|
||||
|
||||
$this->safeMode = (@ini_get('safe_mode') && strtolower(@ini_get('safe_mode')) != "off") ? 1 : 0;
|
||||
|
||||
$this->use_msgraph_api = array_key_exists('use_msgraph_api', $options) ? $options['use_msgraph_api'] : false;
|
||||
|
||||
if ($this->use_msgraph_api) {
|
||||
$endpoint_tld = (isset($options['endpoint_tld']) && 'de' == $options['endpoint_tld']) ? $options['endpoint_tld'] : 'com';
|
||||
$this->api_url = UpdraftPlus_OneDrive_Account::$types[$endpoint_tld]['api_url'];
|
||||
$this->route_prefix = 'me/';
|
||||
|
||||
// The base URL for authorization requests.
|
||||
$this->auth_url = UpdraftPlus_OneDrive_Account::$types[$endpoint_tld]['auth_url'];
|
||||
// The base URL for token requests.
|
||||
$this->token_url = UpdraftPlus_OneDrive_Account::$types[$endpoint_tld]['token_url'];
|
||||
} else { // Custom App or old live sdk
|
||||
$this->route_prefix = '';
|
||||
$this->api_url = 'https://api.onedrive.com/v1.0/';
|
||||
|
||||
// The base URL for authorization requests.
|
||||
$this->auth_url = 'https://login.live.com/oauth20_authorize.srf';
|
||||
|
||||
// The base URL for token requests.
|
||||
$this->token_url = 'https://login.live.com/oauth20_token.srf';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current state of this Client instance. Typically saved in the
|
||||
* session and passed back to the Client constructor for further requests.
|
||||
*
|
||||
* @return (object) The state of this Client instance.
|
||||
*/
|
||||
public function getState() {
|
||||
return $this->_state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URL of the log in form. After login, the browser is redirected to
|
||||
* the redirect URL, and a code is passed as a GET parameter to this URL.
|
||||
*
|
||||
* The browser is also redirected to this URL if the user is already logged
|
||||
* in.
|
||||
*
|
||||
* @param (array) $scopes - The OneDrive scopes requested by the application.
|
||||
* Supported values: 'wl.signin', 'wl.basic', 'wl.contacts_skydrive',
|
||||
* 'wl.skydrive_update'.
|
||||
* @param (string) $redirectUri - The URI to which to redirect to upon
|
||||
* successful log in.
|
||||
* @param (array) $options. Reserved for future use. Default: array(). TODO:
|
||||
* support it.
|
||||
* @param (string) $instance_id - the id of the instance that we are currently trying to authorise
|
||||
* @param string $callback_uri - the current site url where control should redirect after auth server authenticated
|
||||
* @return (string) The login URL.
|
||||
*/
|
||||
public function getLogInUrl(array $scopes, $redirectUri, array $options = array(), $instance_id = '', $callback_uri = '') {
|
||||
if (null === $this->_clientId) {
|
||||
throw new \Exception('The client ID must be set to call getLoginUrl()');
|
||||
}
|
||||
|
||||
if ($this->use_msgraph_api) {
|
||||
$imploded = implode(' ', $scopes);
|
||||
} else {
|
||||
$imploded = implode(',', $scopes);
|
||||
}
|
||||
$redirectUri = (string) $redirectUri;
|
||||
$this->_state->redirect_uri = $redirectUri;
|
||||
|
||||
$prefixed_instance_id = ':' . $instance_id;
|
||||
if ($this->use_msgraph_api) {
|
||||
$token = 'token'.$prefixed_instance_id.$callback_uri;
|
||||
} else {
|
||||
$token = $prefixed_instance_id;
|
||||
}
|
||||
// When using this URL, the browser will eventually be redirected to the
|
||||
// callback URL with a code passed in the URL query string (the name of the
|
||||
// variable is "code"). This is suitable for PHP.
|
||||
$url = $this->auth_url
|
||||
. '?client_id=' . urlencode($this->_clientId)
|
||||
. '&scope=' . urlencode($imploded)
|
||||
. '&response_type=code'
|
||||
. '&redirect_uri=' . urlencode($redirectUri)
|
||||
. '&state=' . urlencode($token)
|
||||
. '&display=popup'
|
||||
. '&locale=en';
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the access token expiration delay.
|
||||
*
|
||||
* @return (int) The token expiration delay, in seconds.
|
||||
*/
|
||||
public function getTokenExpire() {
|
||||
return $this->_state->token->obtained
|
||||
+ $this->_state->token->data->expires_in - time();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the status of the current access token.
|
||||
*
|
||||
* @return (int) The status of the current access token:
|
||||
* 0 => no access token
|
||||
* -1 => access token will expire soon (1 minute or less)
|
||||
* -2 => access token is expired
|
||||
* 1 => access token is valid
|
||||
*/
|
||||
public function getAccessTokenStatus() {
|
||||
if (null === $this->_state->token) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$remaining = $this->getTokenExpire();
|
||||
|
||||
if (0 >= $remaining) {
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (60 >= $remaining) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains a new access token from OAuth. This token is valid for one hour.
|
||||
*
|
||||
* @param (string) $clientSecret - The OneDrive client secret.
|
||||
* @param (string) $code - The code returned by OneDrive after successful log
|
||||
* in.
|
||||
* @param (string) $redirectUri. Must be the same as the redirect URI passed
|
||||
* to getLoginUrl().
|
||||
*/
|
||||
public function obtainAccessToken($clientSecret, $code) {
|
||||
if (null === $this->_clientId) {
|
||||
throw new \Exception('The client ID must be set to call obtainAccessToken()');
|
||||
}
|
||||
|
||||
if (null === $this->_state->redirect_uri) {
|
||||
throw new \Exception('The state\'s redirect URI must be set to call obtainAccessToken()');
|
||||
}
|
||||
|
||||
$url = $this->token_url;
|
||||
|
||||
$curl = curl_init();
|
||||
$curl_version = curl_version();
|
||||
$curl_version = isset($curl_version['version']) ? $curl_version['version'] : '0';
|
||||
|
||||
$curl_options = array(
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
|
||||
CURLOPT_SSL_VERIFYHOST => ($this->_sslVerify ? 2 : false),
|
||||
CURLOPT_SSL_VERIFYPEER => $this->_sslVerify,
|
||||
|
||||
CURLOPT_URL => $url,
|
||||
|
||||
CURLOPT_AUTOREFERER => true,
|
||||
CURLOPT_POST => 1, // i am sending post data
|
||||
CURLOPT_POSTFIELDS => 'client_id=' . urlencode($this->_clientId)
|
||||
. '&redirect_uri=' . urlencode($this->_state->redirect_uri)
|
||||
. '&client_secret=' . urlencode($clientSecret)
|
||||
. '&grant_type=authorization_code'
|
||||
. '&code=' . urlencode($code),
|
||||
);
|
||||
|
||||
if (version_compare($curl_version, '8.0', '<') && version_compare($curl_version, '7.62', '>=')) $curl_options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1;
|
||||
if (defined('UPDRAFTPLUS_ONEDRIVE_CURL_HTTP_VERSION')) $curl_options[CURLOPT_HTTP_VERSION] = UPDRAFTPLUS_ONEDRIVE_CURL_HTTP_VERSION;
|
||||
|
||||
// Prevent misleading PHP notice
|
||||
if (!$this->safeMode) $curl_options[CURLOPT_FOLLOWLOCATION] = true;
|
||||
|
||||
curl_setopt_array($curl, $curl_options);
|
||||
|
||||
$result = curl_exec($curl);
|
||||
|
||||
if (false === $result) {
|
||||
if (curl_errno($curl)) {
|
||||
throw new \Exception('Curl error: '.curl_error($curl)); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Error message to be escaped when caught and printed.
|
||||
} else {
|
||||
throw new \Exception('Curl error: empty response');
|
||||
}
|
||||
}
|
||||
|
||||
$decoded = json_decode($result);
|
||||
|
||||
if (null === $decoded) {
|
||||
throw new \Exception('json_decode() failed');
|
||||
}
|
||||
|
||||
$this->_state->redirect_uri = null;
|
||||
|
||||
$this->_state->token = (object) array(
|
||||
'obtained' => time(),
|
||||
'data' => $decoded
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renews the access token from OAuth. This token is valid for one hour.
|
||||
*/
|
||||
/*public function renewAccessToken($clientSecret, $redirectUri) {
|
||||
$url = self::TOKEN_URL
|
||||
. '?client_id=' . $this->_clientId
|
||||
. '&redirect_uri=' . (string) $redirectUri
|
||||
. '&client_secret=' . (string) $clientSecret
|
||||
. '&grant_type=' . 'refresh_token'
|
||||
. '&code=' . (string) $code;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Performs a call to the OneDrive API using the GET method.
|
||||
*
|
||||
* @param (string) $path - The path of the API call (eg. me/skydrive).
|
||||
* @param (array) $options - Further curl options to set.
|
||||
* @param (boolean) $use_authorization_header - Whether to include authorisation header in the request (it's true by default)
|
||||
* @return (boolean) Object of result
|
||||
*/
|
||||
public function apiGet($path, $options = array(), $use_authorization_header = true) {
|
||||
$api = $this->api_url;
|
||||
|
||||
$url = (strpos($path, 'https://') === 0) ? $path : $api . $path;
|
||||
|
||||
if (!$this->use_msgraph_api) $url .= '?access_token=' . urlencode($this->_state->token->data->access_token);
|
||||
|
||||
$curl = $this->_createCurl($path, $options);
|
||||
$curl_options = array(
|
||||
CURLOPT_URL => $url,
|
||||
);
|
||||
|
||||
if ($use_authorization_header) {
|
||||
$curl_options[CURLOPT_HTTPHEADER] = array(
|
||||
'Authorization: Bearer ' . $this->_state->token->data->access_token
|
||||
);
|
||||
}
|
||||
|
||||
curl_setopt_array($curl, $curl_options);
|
||||
//curl_setopt($curl, CURLOPT_URL, $url);
|
||||
|
||||
return $this->_processResult($curl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a call to the OneDrive API using the POST method.
|
||||
*
|
||||
* @param (string) $path - The path of the API call (eg. me/skydrive).
|
||||
* @param (array|object) $data - The data to pass in the body of the request.
|
||||
*/
|
||||
public function apiPost($path, $data = null) {
|
||||
$api = $this->api_url;
|
||||
|
||||
$url = (strpos($path, 'https://') === 0) ? $path : $api . $path;
|
||||
|
||||
$curl = $this->_createCurl($path);
|
||||
|
||||
$curl_options = array(
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_POST => true,
|
||||
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
'Content-Type: application/json', // The data is sent as JSON as per OneDrive documentation
|
||||
'Authorization: Bearer ' . $this->_state->token->data->access_token
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
if (null !== $data) {
|
||||
$data = (object) $data;
|
||||
$curl_options[CURLOPT_POSTFIELDS] = json_encode($data);
|
||||
} else {
|
||||
// This doesn't seem to be necessary in my testing, but another user got an error from OneDrive indicating it was needed. Perhaps varies between curl versions?
|
||||
$curl_options[CURLOPT_HTTPHEADER][] = 'Content-Length: 0';
|
||||
}
|
||||
|
||||
curl_setopt_array($curl, $curl_options);
|
||||
|
||||
return $this->_processResult($curl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a call to the OneDrive API using the PUT method.
|
||||
*
|
||||
* @param (string) $path - The path of the API call (eg. me/skydrive).
|
||||
* @param (resource) $stream - The data stream to upload.
|
||||
* @param (string) $contentType - The MIME type of the data stream, or null
|
||||
* if unknown. Default: null.
|
||||
* @param (int) $size - The number of bytes to send. Default: as many as are left in the stream.
|
||||
* @param (array) $headers - Further headers to send
|
||||
* @param (boolean) $use_authorization_header - Whether to include authorisation header in the request (it's true by default)
|
||||
* @return (object|string) The content returned, as an object instance if served a JSON, or as a string if served as anything else.
|
||||
*/
|
||||
public function apiPut($path, $stream, $contentType = null, $size = null, $headers = array(), $use_authorization_header = true) {
|
||||
$api = $this->api_url;
|
||||
|
||||
$url = (strpos($path, 'https://') === 0) ? $path : $api . $path;
|
||||
$curl = $this->_createCurl($path);
|
||||
|
||||
if (null === $size) {
|
||||
$stats = fstat($stream);
|
||||
$size = $stats[7];
|
||||
}
|
||||
|
||||
if ($use_authorization_header) $headers[] = 'Authorization: Bearer ' . $this->_state->token->data->access_token;
|
||||
|
||||
if (null !== $contentType) {
|
||||
$headers[] = 'Content-Type: ' . $contentType;
|
||||
}
|
||||
|
||||
$options = array(
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_HTTPHEADER => $headers,
|
||||
CURLOPT_PUT => true,
|
||||
CURLOPT_INFILE => $stream,
|
||||
CURLOPT_INFILESIZE => $size
|
||||
);
|
||||
|
||||
curl_setopt_array($curl, $options);
|
||||
return $this->_processResult($curl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a call to the OneDrive API using the DELETE method.
|
||||
*
|
||||
* @param (string) $path - The path of the API call (eg. me/skydrive).
|
||||
*/
|
||||
public function apiDelete($path) {
|
||||
$url = $this->api_url . $path;
|
||||
// . '?access_token=' . urlencode($this->_state->token->data->access_token);
|
||||
|
||||
$curl = $this->_createCurl($path);
|
||||
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_CUSTOMREQUEST => 'DELETE',
|
||||
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
'Authorization: Bearer ' . $this->_state->token->data->access_token
|
||||
)
|
||||
));
|
||||
|
||||
return $this->_processResult($curl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a call to the OneDrive API using the DELETE method.
|
||||
*
|
||||
* @param (string) $path - The path of the API call (eg. me/skydrive).
|
||||
* @param (array) $objectIdArray - An array of unique IDs of the objects to delete.
|
||||
*/
|
||||
public function apiDeleteMulti($path, $objectIdArray) {
|
||||
|
||||
$multi_curl = curl_multi_init();
|
||||
$curl_objects = array();
|
||||
|
||||
foreach($objectIdArray as $id) {
|
||||
$current_path = $path . $id;
|
||||
$url = $this->api_url . $current_path;
|
||||
|
||||
$curl = $this->_createCurl($current_path);
|
||||
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_CUSTOMREQUEST => 'DELETE',
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
'Authorization: Bearer ' . $this->_state->token->data->access_token
|
||||
)
|
||||
));
|
||||
curl_multi_add_handle($multi_curl, $curl);
|
||||
$curl_objects[] = $curl;
|
||||
}
|
||||
|
||||
$active = null;
|
||||
|
||||
do {
|
||||
$status = curl_multi_exec($multi_curl, $active);
|
||||
if ($active) {
|
||||
// Wait a short time for more activity
|
||||
curl_multi_select($multi_curl);
|
||||
}
|
||||
} while ($active && $status == CURLM_OK);
|
||||
|
||||
$response_array = array();
|
||||
|
||||
foreach ($curl_objects as $curl_object) {
|
||||
$response = curl_multi_getcontent($curl_object);
|
||||
// If empty then it's a success other wise we have an error array
|
||||
if (empty($response)) {
|
||||
$response_array[] = 'success';
|
||||
} else {
|
||||
$response_array[] = json_decode($response, true);
|
||||
}
|
||||
curl_multi_remove_handle($multi_curl, $curl_object);
|
||||
}
|
||||
|
||||
curl_multi_close($multi_curl);
|
||||
|
||||
return $response_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a call to the OneDrive API using the MOVE method.
|
||||
*
|
||||
* @param (string) $path - The path of the API call (eg. me/skydrive).
|
||||
* @param (array|object) $data - The data to pass in the body of the request.
|
||||
*/
|
||||
public function apiMove($path, $data) {
|
||||
$url = $this->api_url . $path;
|
||||
$data = (object) $data;
|
||||
$curl = $this->_createCurl($path);
|
||||
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_CUSTOMREQUEST => 'MOVE',
|
||||
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
'Content-Type: application/json', // The data is sent as JSON as per OneDrive documentation
|
||||
'Authorization: Bearer ' . $this->_state->token->data->access_token
|
||||
),
|
||||
|
||||
CURLOPT_POSTFIELDS => json_encode($data)
|
||||
));
|
||||
|
||||
return $this->_processResult($curl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a call to the OneDrive API using the COPY method.
|
||||
*
|
||||
* @param (string) $path - The path of the API call (eg. me/skydrive).
|
||||
* @param (array|object) $data - The data to pass in the body of the request.
|
||||
*/
|
||||
public function apiCopy($path, $data) {
|
||||
$url = $this->api_url . $path;
|
||||
$data = (object) $data;
|
||||
$curl = $this->_createCurl($path);
|
||||
|
||||
curl_setopt_array($curl, array(
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_CUSTOMREQUEST => 'COPY',
|
||||
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
'Content-Type: application/json', // The data is sent as JSON as per OneDrive documentation
|
||||
'Authorization: Bearer ' . $this->_state->token->data->access_token
|
||||
),
|
||||
|
||||
CURLOPT_POSTFIELDS => json_encode($data)
|
||||
));
|
||||
|
||||
return $this->_processResult($curl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a folder in the current OneDrive account.
|
||||
*
|
||||
* @param (string) $name - The name of the OneDrive folder to be created.
|
||||
* @param (null|string) $parentId - The ID of the OneDrive folder into which
|
||||
* to create the OneDrive folder, or null to create it in the OneDrive
|
||||
* root folder. Default: null.
|
||||
* @param (null|string) $description - The description of the OneDrive folder to be
|
||||
* created, or null to create it without a description. Default: null.
|
||||
* @return (Folder) The folder created, as a Folder instance referencing to
|
||||
* the OneDrive folder created.
|
||||
*/
|
||||
public function createFolder($name, $parentId = null, $description = null) {
|
||||
if (null === $parentId) {
|
||||
$parent_path = $this->route_prefix.'drive/root/children';
|
||||
} else{
|
||||
$parent_path = $this->route_prefix.'drive/items/'.$parentId.'/children';
|
||||
}
|
||||
|
||||
$properties = array(
|
||||
'name' => (string) $name,
|
||||
'folder' => (object) array()
|
||||
);
|
||||
|
||||
//if (null !== $description) {
|
||||
// $properties['description'] = (string) $description;
|
||||
//}
|
||||
|
||||
$folder_body = (object) $properties;
|
||||
|
||||
$folder = $this->apiPost($parent_path, $folder_body);
|
||||
return new Folder($this, $folder->id, $folder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a file in the current OneDrive account.
|
||||
*
|
||||
* @param (string) $name - The name of the OneDrive file to be created.
|
||||
* @param (null|string) $parentId - The ID of the OneDrive folder into which
|
||||
* to create the OneDrive file, or null to create it in the OneDrive
|
||||
* root folder. Default: null.
|
||||
* @param (string|resource) $content - The content of the OneDrive file to be created.
|
||||
* @return (File) The file created, as File instance referencing to the
|
||||
* OneDrive file created.
|
||||
* @throw (\Exception) Thrown on I/O errors.
|
||||
*/
|
||||
public function createFile($name, $parentId = null, $content = '') {
|
||||
if (null === $parentId) {
|
||||
$parent_path = $this->route_prefix.'drive/root';
|
||||
} else{
|
||||
$parent_path = $this->route_prefix.'drive/items/'.$parentId;
|
||||
}
|
||||
|
||||
if (is_resource($content)) {
|
||||
$stream = $content;
|
||||
} else {
|
||||
$stream = fopen('php://temp', 'rw+b');
|
||||
|
||||
if (false === $stream) {
|
||||
throw new \Exception('fopen() failed');
|
||||
}
|
||||
|
||||
if (false === fwrite($stream, $content)) {
|
||||
fclose($stream);
|
||||
throw new \Exception('fwrite() failed');
|
||||
}
|
||||
|
||||
if (!rewind($stream)) {
|
||||
fclose($stream);
|
||||
throw new \Exception('rewind() failed');
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: some versions of cURL cannot PUT memory streams? See here for a
|
||||
// workaround: https://bugs.php.net/bug.php?id=43468
|
||||
$file = $this->apiPut($parent_path . '/children/' . urlencode($name).'/content/', $stream, null, null, array());
|
||||
if (!is_resource($content)) fclose($stream);
|
||||
return new File($this, $file->id, $file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches an object from the current OneDrive account.
|
||||
*
|
||||
* @param (null|string) The unique ID of the OneDrive object to fetch, or
|
||||
* null to fetch the OneDrive root folder. Default: null.
|
||||
* @return (Object) The object fetched, as an Object instance referencing to
|
||||
* the OneDrive object fetched.
|
||||
*/
|
||||
public function fetchObject($objectId = null) {
|
||||
$objectId = null !== $objectId ? $objectId : $this->route_prefix.'drive/root';
|
||||
$result = $this->apiGet($objectId, array());
|
||||
|
||||
if (property_exists($result, 'folder')) {
|
||||
return new Folder($this, $objectId, $result);
|
||||
}
|
||||
|
||||
return new File($this, $objectId, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the root folder from the current OneDrive account.
|
||||
*
|
||||
* @return (Folder) The root folder, as a Folder instance referencing to the
|
||||
* OneDrive root folder.
|
||||
*/
|
||||
public function fetchRoot() {
|
||||
return $this->fetchObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the "Camera Roll" folder from the current OneDrive account.
|
||||
*
|
||||
* @return (Folder) The "Camera Roll" folder, as a Folder instance referencing
|
||||
* to the OneDrive "Camera Roll" folder.
|
||||
*/
|
||||
public function fetchCameraRoll() {
|
||||
return $this->fetchObject($this->route_prefix.'drive/special/cameraroll');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the "Documents" folder from the current OneDrive account.
|
||||
*
|
||||
* @return (Folder) The "Documents" folder, as a Folder instance referencing
|
||||
* to the OneDrive "Documents" folder.
|
||||
*/
|
||||
public function fetchDocs() {
|
||||
return $this->fetchObject($this->route_prefix.'drive/special/documents');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the "Pictures" folder from the current OneDrive account.
|
||||
*
|
||||
* @return (Folder) The "Pictures" folder, as a Folder instance referencing to
|
||||
* the OneDrive "Pictures" folder.
|
||||
*/
|
||||
public function fetchPics() {
|
||||
return $this->fetchObject($this->route_prefix.'drive/special/photos');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the "Public" folder from the current OneDrive account.
|
||||
*
|
||||
* @return (Folder) The "Public" folder, as a Folder instance referencing to
|
||||
* the OneDrive "Public" folder.
|
||||
*/
|
||||
public function fetchPublicDocs() {
|
||||
return $this->fetchObject($this->route_prefix.'drive/special/public_documents');
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the properties of an object in the current OneDrive account.
|
||||
*
|
||||
* @return (array) The properties of the object fetched.
|
||||
*/
|
||||
public function fetchProperties($objectId) {
|
||||
if (null === $objectId) {
|
||||
$object_path = $this->route_prefix.'drive/root';
|
||||
} else {
|
||||
$object_path = $this->route_prefix.'drive/items/'.$objectId;
|
||||
}
|
||||
|
||||
return $this->apiGet($objectId, array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the objects in a folder in the current OneDrive account.
|
||||
*
|
||||
* @return (array) The objects in the folder fetched, as Object instances
|
||||
* referencing OneDrive objects.
|
||||
*/
|
||||
public function fetchObjects($objectId) {
|
||||
if (null === $objectId) {
|
||||
$object_path = $this->route_prefix.'drive/root';
|
||||
} else{
|
||||
$object_path = $this->route_prefix.'drive/items/'.$objectId;
|
||||
}
|
||||
|
||||
$fetch_url = $object_path . '/children';
|
||||
|
||||
$objects = array();
|
||||
|
||||
while ($fetch_url) {
|
||||
|
||||
$result = $this->apiGet($fetch_url, array());
|
||||
|
||||
foreach ($result->value as $data) {
|
||||
$object = property_exists($data, 'folder') ?
|
||||
new Folder($this, $data->id, $data)
|
||||
: new File($this, $data->id, $data);
|
||||
|
||||
$objects[] = $object;
|
||||
}
|
||||
|
||||
$next_url_key = '@odata.nextLink';
|
||||
|
||||
$fetch_url = !empty($result->$next_url_key) ? $result->$next_url_key : false;
|
||||
}
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the properties of an object in the current OneDrive account.
|
||||
*
|
||||
* @param (string) $objectId - The unique ID of the object to update.
|
||||
* @param (array|object) $properties - The properties to update. Default:
|
||||
* array().
|
||||
* @throw (\Exception) Thrown on I/O errors.
|
||||
*/
|
||||
public function updateObject($objectId, $properties = array()) {
|
||||
$objectId = $objectId;
|
||||
$properties = (object) $properties;
|
||||
$encoded = json_encode($properties);
|
||||
$stream = fopen('php://temp', 'w+b');
|
||||
|
||||
if (false === $stream) {
|
||||
throw new \Exception('fopen() failed');
|
||||
}
|
||||
|
||||
if (false === fwrite($stream, $encoded)) {
|
||||
throw new \Exception('fwrite() failed');
|
||||
}
|
||||
|
||||
if (!rewind($stream)) {
|
||||
throw new \Exception('rewind() failed');
|
||||
}
|
||||
|
||||
$this->apiPut($objectId, $stream, 'application/json', null, array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves an object into another folder.
|
||||
*
|
||||
* @param (string) The unique ID of the object to move.
|
||||
* @param (null|string) The unique ID of the folder into which to move the
|
||||
* object, or null to move it to the OneDrive root folder. Default:
|
||||
* null.
|
||||
*/
|
||||
public function moveObject($objectId, $destinationId = null) {
|
||||
if (null === $destinationId) {
|
||||
$destinationId = $this->route_prefix.'drive/root';
|
||||
}
|
||||
|
||||
$this->apiMove($objectId, array(
|
||||
'destination' => $destinationId
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies a file into another folder. OneDrive does not support copying
|
||||
* folders.
|
||||
*
|
||||
* @param (string) The unique ID of the file to copy.
|
||||
* @param (null|string) The unique ID of the folder into which to copy the
|
||||
* file, or null to copy it to the OneDrive root folder. Default:
|
||||
* null.
|
||||
*/
|
||||
public function copyFile($objectId, $destinationId = null) {
|
||||
if (null === $destinationId) {
|
||||
$destinationId = $this->route_prefix.'drive/root';
|
||||
}
|
||||
|
||||
$this->apiCopy($objectId, array(
|
||||
'destination' => $destinationId
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an object in the current OneDrive account.
|
||||
*
|
||||
* @param (string) $objectId - The unique ID of the object to delete.
|
||||
*/
|
||||
public function deleteObject($objectId) {
|
||||
$objectId = $objectId;
|
||||
$this->apiDelete($this->route_prefix.'drive/items/'.$objectId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an array of objects in the current OneDrive account.
|
||||
*
|
||||
* @param (array) $objectIdArray - An array of unique IDs of the objects to delete.
|
||||
*
|
||||
* @return array - returns an array of responses
|
||||
*/
|
||||
public function deleteObjectMulti($objectIdArray) {
|
||||
if (!is_array($objectIdArray)) return;
|
||||
return $this->apiDeleteMulti($this->route_prefix.'drive/items/', $objectIdArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the quota of the current OneDrive account.
|
||||
*
|
||||
* @return (object) An object with the following properties:
|
||||
* (int) quota - The total space, in bytes.
|
||||
* (int) available - The available space, in bytes.
|
||||
*/
|
||||
public function fetchQuota() {
|
||||
$drive = $this->apiGet($this->route_prefix.'drive', array());
|
||||
return $drive->quota;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the account info of the current OneDrive account.
|
||||
*
|
||||
* @return (object) An object with the following properties:
|
||||
* (string) id - OneDrive account ID.
|
||||
* (string) first_name - account owner's first name.
|
||||
* (string) last_name - account owner's last name.
|
||||
* (string) name - account owner's full name.
|
||||
* (string) gender - account owner's gender.
|
||||
* (string) locale - account owner's locale.
|
||||
*/
|
||||
public function fetchAccountInfo() {
|
||||
//$drive = $this->apiGet('drive', array(), true);
|
||||
$drive = $this->apiGet($this->route_prefix.'drive', array());
|
||||
return $drive->owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the recent documents uploaded to the current OneDrive account.
|
||||
*
|
||||
* @return (object) An object with the following properties:
|
||||
* (array) data - The list of the recent documents uploaded.
|
||||
*/
|
||||
public function fetchRecentDocs() {
|
||||
return $this->apiGet($this->route_prefix.'drive/special/recent_docs', array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the objects shared with the current OneDrive account.
|
||||
*
|
||||
* @return (object) An object with the following properties:
|
||||
* (array) data - The list of the shared objects.
|
||||
*/
|
||||
public function fetchShared() {
|
||||
return $this->apiGet($this->route_prefix.'drive/special/shared', array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Give $use_msgraph_api variable
|
||||
*
|
||||
* @return boolean private $use_msgraph_api var
|
||||
*/
|
||||
public function use_msgraph_api() {
|
||||
return $this->use_msgraph_api;
|
||||
}
|
||||
}
|
||||
60
wp-content/plugins/updraftplus/includes/onedrive/file.php
Normal file
60
wp-content/plugins/updraftplus/includes/onedrive/file.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
namespace Onedrive;
|
||||
|
||||
/*
|
||||
* A File instance is an Object instance referencing a OneDrive file. It may
|
||||
* have content but may not contain other OneDrive objects.
|
||||
*/
|
||||
class File extends Instance {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param (Client) $client - The Client instance owning this Object instance.
|
||||
* @param (null|string) $id - The unique ID of the OneDrive object referenced
|
||||
* by this Object instance.
|
||||
* @param (array|object) $options - An array/object with one or more of the
|
||||
* following keys/properties:
|
||||
* (string) parent_id - The unique ID of the parent OneDrive folder
|
||||
* of this object.
|
||||
* (string) name - The name of this object.
|
||||
* (string) description - The description of this object. May be
|
||||
* empty.
|
||||
* (int) size - The size of this object, in bytes.
|
||||
* (string) created_time - The creation time, as a RFC date/time.
|
||||
* (string) updated_time - The last modification time, as a RFC
|
||||
* date/time.
|
||||
* Default: array().
|
||||
*/
|
||||
public function __construct(Client $client, $id, $options = array()) {
|
||||
parent::__construct($client, $id, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the content of the OneDrive file referenced by this File instance.
|
||||
*
|
||||
* @param (array) - Extra curl options to pass.
|
||||
*
|
||||
* @return (string) The content of the OneDrive file referenced by this File
|
||||
* instance.
|
||||
*/
|
||||
// TODO: should somewhat return the content-type as well; this information is
|
||||
// not disclosed by OneDrive
|
||||
public function fetchContent($options = array()) {
|
||||
if ($this->_client->use_msgraph_api()) {
|
||||
return $this->_client->apiGet('me/drive/items/'.$this->_id . '/content', $options, true);
|
||||
}
|
||||
return $this->_client->apiGet('drive/items/'.$this->_id . '/content', $options, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the OneDrive file referenced by this File instance into another
|
||||
* OneDrive folder.
|
||||
*
|
||||
* @param (null|string) The unique ID of the OneDrive folder into which to
|
||||
* copy the OneDrive file referenced by this File instance, or null to
|
||||
* copy it in the OneDrive root folder. Default: null.
|
||||
*/
|
||||
public function copy($destinationId = null) {
|
||||
$this->_client->copyFile($this->_id, $destinationId);
|
||||
}
|
||||
}
|
||||
68
wp-content/plugins/updraftplus/includes/onedrive/folder.php
Normal file
68
wp-content/plugins/updraftplus/includes/onedrive/folder.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
namespace Onedrive;
|
||||
|
||||
/*
|
||||
* A Folder instance is an Object instance referencing to a OneDrive folder. It
|
||||
* may contain other OneDrive objects but may not have content.
|
||||
*/
|
||||
class Folder extends Instance {
|
||||
/**
|
||||
* Determines whether the OneDrive object referenced by this Object instance
|
||||
* is a folder.
|
||||
*
|
||||
* @return (bool) true if the OneDrive object referenced by this Object
|
||||
* instance is a folder, false otherwise.
|
||||
*/
|
||||
public function isFolder() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param (Client) $client - The Client instance owning this Object instance.
|
||||
* @param (null|string) $id - The unique ID of the OneDrive object referenced
|
||||
* by this Object instance, or null to reference the OneDrive root
|
||||
* folder. Default: null.
|
||||
* @param (array|object) $options.
|
||||
*/
|
||||
public function __construct(Client $client, $id = null, $options = array()) {
|
||||
parent::__construct($client, $id, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the objects in the OneDrive folder referenced by this Folder instance.
|
||||
*
|
||||
* @return (array) The objects in the OneDrive folder referenced by this
|
||||
* Folder instance, as Object instances.
|
||||
*/
|
||||
public function fetchObjects() {
|
||||
return $this->_client->fetchObjects($this->_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a folder in the OneDrive folder referenced by this Folder instance.
|
||||
*
|
||||
* @param (string) $name - The name of the OneDrive folder to be created.
|
||||
* @param (null|string) $description - The description of the OneDrive folder
|
||||
* to be created, or null to create it without a description. Default:
|
||||
* null.
|
||||
* @return (Folder) The folder created, as a Folder instance.
|
||||
*/
|
||||
public function createFolder($name, $description = null) {
|
||||
return $this->_client->createFolder($name, $this->_id, $description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a file in the OneDrive folder referenced by this Folder instance.
|
||||
*
|
||||
* @param (string) $name - The name of the OneDrive file to be created.
|
||||
* @param (string) $content - The content of the OneDrive file to be created.
|
||||
* Default: ''.
|
||||
* @return (File) The file created, as a File instance.
|
||||
* @throw (\Exception) Thrown on I/O errors.
|
||||
*/
|
||||
public function createFile($name, $content = '') {
|
||||
return $this->_client->createFile($name, $this->_id, $content);
|
||||
}
|
||||
}
|
||||
227
wp-content/plugins/updraftplus/includes/onedrive/object.php
Normal file
227
wp-content/plugins/updraftplus/includes/onedrive/object.php
Normal file
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
namespace Onedrive;
|
||||
|
||||
/*
|
||||
* An Object instance is an entity that may be stored in a OneDrive account.
|
||||
* There are two types of objects: file or a folder, each of which being a
|
||||
* subclass of the Object class.
|
||||
*
|
||||
* Note that Object instances are only "proxy" to actual OneDrive objects (eg.
|
||||
* destroying an Object instance will not delete the actual OneDrive object it
|
||||
* is referencing to).
|
||||
*/
|
||||
// Class name changed to Instance from Object because Object reserved keyword in Php 7.2
|
||||
abstract class Instance {
|
||||
// The owning Client instance.
|
||||
protected $_client;
|
||||
|
||||
// The unique ID assigned by OneDrive to this object.
|
||||
protected $_id;
|
||||
|
||||
// The unique ID assigned by OneDrive to the parent folder of this object.
|
||||
private $_parentId;
|
||||
|
||||
// The name of this object.
|
||||
private $_name;
|
||||
|
||||
// The description of this object.
|
||||
private $_description;
|
||||
|
||||
// The size of this object, in bytes.
|
||||
private $_size;
|
||||
|
||||
// The creation time, in seconds since UNIX epoch.
|
||||
private $_createdTime;
|
||||
|
||||
// The last modification time, in seconds since UNIX epoch.
|
||||
private $_updatedTime;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param (Client) $client - The Client instance owning this Object instance.
|
||||
* @param (null|string) $id - The unique ID of the OneDrive object referenced
|
||||
* by this Object instance.
|
||||
* @param (array|object) $options - An array/object with one or more of the
|
||||
* following keys/properties:
|
||||
* (string) parent_id - The unique ID of the parent OneDrive folder
|
||||
* of this object.
|
||||
* (string) name - The name of this object.
|
||||
* (string) description - The description of this object. May be
|
||||
* empty.
|
||||
* (int) size - The size of this object, in bytes.
|
||||
* (string) created_time - The creation time, as a RFC date/time.
|
||||
* (string) updated_time - The last modification time, as a RFC
|
||||
* date/time.
|
||||
* Default: array().
|
||||
*/
|
||||
public function __construct(Client $client, $id, $options = array()) {
|
||||
$options = (object) $options;
|
||||
$this->_client = $client;
|
||||
$this->_id = null !== $id ? (string) $id : null;
|
||||
|
||||
$this->_parentId = property_exists($options, 'parent_id') ?
|
||||
(string) $options->parent_id : null;
|
||||
|
||||
$this->_name = property_exists($options, 'name') ?
|
||||
(string) $options->name : null;
|
||||
|
||||
$this->_description = property_exists($options, 'description') ?
|
||||
(string) $options->description : null;
|
||||
|
||||
$this->_size = property_exists($options, 'size') ?
|
||||
(int) $options->size : null;
|
||||
|
||||
$this->_createdTime = property_exists($options, 'created_time') ?
|
||||
strtotime($options->created_time) : null;
|
||||
|
||||
$this->_updatedTime = property_exists($options, 'updated_time') ?
|
||||
strtotime($options->updated_time) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the OneDrive object referenced by this Object instance
|
||||
* is a folder.
|
||||
*
|
||||
* @return (bool) true if the OneDrive object referenced by this Object
|
||||
* instance is a folder, false otherwise.
|
||||
*/
|
||||
public function isFolder() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the properties of the OneDrive object referenced by this Object
|
||||
* instance. Some properties are cached for faster subsequent access.
|
||||
*
|
||||
* @return (array) The properties of the OneDrive object referenced by this
|
||||
* Object instance.
|
||||
*/
|
||||
public function fetchProperties() {
|
||||
$result = $this->_client->fetchProperties($this->_id);
|
||||
|
||||
$this->_parentId = '' != $result->parentReference['id'] ?
|
||||
(string) $result->parentReference['id'] : null;
|
||||
|
||||
$this->_name = $result->name;
|
||||
|
||||
$this->_description = '' != $result->description ?
|
||||
(string) $result->description : null;
|
||||
|
||||
$this->_size = (int) $result->size;
|
||||
$this->_createdTime = strtotime($result->createdDateTime);
|
||||
$this->_updatedTime = strtotime($result->lastModifiedDateTime);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the unique ID of the OneDrive object referenced by this Object
|
||||
* instance.
|
||||
*
|
||||
* @return (string) The unique ID of the OneDrive object referenced by this
|
||||
* Object instance.
|
||||
*/
|
||||
public function getId() {
|
||||
return $this->_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the unique ID of the parent folder of the OneDrive object referenced
|
||||
* by this Object instance.
|
||||
*
|
||||
* @return (string) The unique ID of the OneDrive folder containing the object
|
||||
* referenced by this Object instance.
|
||||
*/
|
||||
public function getParentId() {
|
||||
if (null === $this->_parentId) {
|
||||
$this->fetchProperties();
|
||||
}
|
||||
|
||||
return $this->_parentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the OneDrive object referenced by this Object instance.
|
||||
*
|
||||
* @return (string) The name of the OneDrive object referenced by this Object
|
||||
* instance.
|
||||
*/
|
||||
public function getName() {
|
||||
if (null === $this->_name) {
|
||||
$this->fetchProperties();
|
||||
}
|
||||
|
||||
return $this->_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the description of the OneDrive object referenced by this Object
|
||||
* instance.
|
||||
*
|
||||
* @return (string) The description of the OneDrive object referenced by this
|
||||
* Object instance.
|
||||
*/
|
||||
public function getDescription() {
|
||||
if (null === $this->_description) {
|
||||
$this->fetchProperties();
|
||||
}
|
||||
|
||||
return $this->_description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of the OneDrive object referenced by this Object instance.
|
||||
*
|
||||
* @return (int) The size of the OneDrive object referenced by this Object
|
||||
* instance.
|
||||
*/
|
||||
public function getSize() {
|
||||
if (null === $this->_size) {
|
||||
$this->fetchProperties();
|
||||
}
|
||||
|
||||
return $this->_size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the creation time of the OneDrive object referenced by this Object
|
||||
* instance.
|
||||
*
|
||||
* @return (int) The creation time of the object referenced by this Object
|
||||
* instance, in seconds since UNIX epoch.
|
||||
*/
|
||||
public function getCreatedTime() {
|
||||
if (null === $this->_createdTime) {
|
||||
$this->fetchProperties();
|
||||
}
|
||||
|
||||
return $this->_createdTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last modification time of the OneDrive object referenced by this
|
||||
* Object instance.
|
||||
*
|
||||
* @return (int) The last modification time of the object referenced by this
|
||||
* Object instance, in seconds since UNIX epoch.
|
||||
*/
|
||||
public function getUpdatedTime() {
|
||||
if (null === $this->_updatedTime) {
|
||||
$this->fetchProperties();
|
||||
}
|
||||
|
||||
return $this->_updatedTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the OneDrive object referenced by this Object instance into another
|
||||
* OneDrive folder.
|
||||
*
|
||||
* @param (null|string) The unique ID of the OneDrive folder into which to
|
||||
* move the OneDrive object referenced by this Object instance, or
|
||||
* null to move it to the OneDrive root folder. Default: null.
|
||||
*/
|
||||
public function move($destinationId = null) {
|
||||
$this->_client->moveObject($this->_id, $destinationId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/client.php';
|
||||
require_once __DIR__ . '/object.php';
|
||||
require_once __DIR__ . '/file.php';
|
||||
require_once __DIR__ . '/folder.php';
|
||||
Reference in New Issue
Block a user