first commit
674
wp-content/plugins/unyson/framework/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>.
|
||||
311
wp-content/plugins/unyson/framework/autoload.php
Normal file
@@ -0,0 +1,311 @@
|
||||
<?php if ( ! defined( 'FW' ) ) {
|
||||
die( 'Forbidden' );
|
||||
}
|
||||
|
||||
spl_autoload_register( '_fw_core_autoload' );
|
||||
function _fw_core_autoload( $class ) {
|
||||
switch ( $class ) {
|
||||
case 'FW_Manifest' :
|
||||
case 'FW_Framework_Manifest' :
|
||||
case 'FW_Theme_Manifest' :
|
||||
case 'FW_Extension_Manifest' :
|
||||
require_once dirname( __FILE__ ) . '/core/class-fw-manifest.php';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spl_autoload_register( '_fw_core_components_autoload' );
|
||||
function _fw_core_components_autoload( $class ) {
|
||||
switch ( $class ) {
|
||||
case '_FW_Component_Backend' :
|
||||
require_once dirname( __FILE__ ) . '/core/components/backend.php';
|
||||
break;
|
||||
case '_FW_Component_Extensions' :
|
||||
require_once dirname( __FILE__ ) . '/core/components/extensions.php';
|
||||
break;
|
||||
case '_FW_Component_Theme' :
|
||||
require_once dirname( __FILE__ ) . '/core/components/theme.php';
|
||||
break;
|
||||
case 'FW_Settings_Form_Theme' :
|
||||
require_once dirname( __FILE__ ) . '/core/components/backend/class-fw-settings-form-theme.php';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spl_autoload_register( '_fw_core_components_extensions_autoload' );
|
||||
function _fw_core_components_extensions_autoload( $class ) {
|
||||
switch ( $class ) {
|
||||
case 'FW_Extension_Default' :
|
||||
require_once dirname( __FILE__ ) . '/core/components/extensions/class-fw-extension-default.php';
|
||||
break;
|
||||
case '_FW_Extensions_Manager' :
|
||||
require_once dirname( __FILE__ ) . '/core/components/extensions/manager/class--fw-extensions-manager.php';
|
||||
break;
|
||||
case '_FW_Extensions_Delete_Upgrader_Skin' :
|
||||
require_once dirname( __FILE__ ) . '/core/components/extensions/manager/includes/class--fw-extensions-delete-upgrader-skin.php';
|
||||
break;
|
||||
case '_FW_Extensions_Install_Upgrader_Skin' :
|
||||
require_once dirname( __FILE__ ) . '/core/components/extensions/manager/includes/class--fw-extensions-install-upgrader-skin.php';
|
||||
break;
|
||||
case 'Parsedown' :
|
||||
require_once dirname( __FILE__ ) . '/core/components/extensions/manager/includes/parsedown/Parsedown.php';
|
||||
break;
|
||||
case 'FW_Ext_Download_Source' :
|
||||
require_once dirname( __FILE__ ) . '/core/components/extensions/manager/includes/download-source/class--fw-ext-download-source.php';
|
||||
break;
|
||||
case '_FW_Ext_Download_Source_Register' :
|
||||
require_once dirname( __FILE__ ) . '/core/components/extensions/manager/includes/download-source/class--fw-ext-download-source-register.php';
|
||||
break;
|
||||
case 'FW_Ext_Download_Source_Github' :
|
||||
require_once dirname( __FILE__ ) . '/core/components/extensions/manager/includes/download-source/types/class-fw-download-source-github.php';
|
||||
break;
|
||||
case 'FW_Ext_Download_Source_Bitbucket' :
|
||||
require_once dirname( __FILE__ ) . '/core/components/extensions/manager/includes/download-source/types/class-fw-download-source-bitbucket.php';
|
||||
break;
|
||||
case 'FW_Ext_Download_Source_Custom' :
|
||||
require_once dirname( __FILE__ ) . '/core/components/extensions/manager/includes/download-source/types/class-fw-download-source-custom.php';
|
||||
break;
|
||||
case '_FW_Available_Extensions_Register' :
|
||||
require_once dirname( __FILE__ ) . '/core/components/extensions/manager/includes/available-ext/class--fw-available-extensions-register.php';
|
||||
break;
|
||||
case 'FW_Available_Extension' :
|
||||
require_once dirname( __FILE__ ) . '/core/components/extensions/manager/includes/available-ext/class-fw-available-extension.php';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spl_autoload_register( '_fw_core_extends_autoload' );
|
||||
function _fw_core_extends_autoload( $class ) {
|
||||
switch ( $class ) {
|
||||
case 'FW_Container_Type' :
|
||||
require_once dirname( __FILE__ ) . '/core/extends/class-fw-container-type.php';
|
||||
break;
|
||||
case 'FW_Option_Type' :
|
||||
require_once dirname( __FILE__ ) . '/core/extends/class-fw-option-type.php';
|
||||
break;
|
||||
case 'FW_Extension' :
|
||||
require_once dirname( __FILE__ ) . '/core/extends/class-fw-extension.php';
|
||||
break;
|
||||
case 'FW_Option_Handler' :
|
||||
require_once dirname( __FILE__ ) . '/core/extends/interface-fw-option-handler.php';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spl_autoload_register( '_fw_code_exceptions_autoload' );
|
||||
function _fw_code_exceptions_autoload( $class ) {
|
||||
switch ( $class ) {
|
||||
case 'FW_Option_Type_Exception' :
|
||||
case 'FW_Option_Type_Exception_Not_Found' :
|
||||
case 'FW_Option_Type_Exception_Invalid_Class' :
|
||||
case 'FW_Option_Type_Exception_Already_Registered' :
|
||||
require_once dirname( __FILE__ ) . '/core/exceptions/class-fw-option-type-exception.php';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Autoload helper classes
|
||||
function _fw_autoload_helper_classes($class) {
|
||||
static $class_to_file = array(
|
||||
'FW_Dumper' => 'class-fw-dumper',
|
||||
'FW_Cache' => 'class-fw-cache',
|
||||
'FW_Callback' => 'class-fw-callback',
|
||||
'FW_Access_Key' => 'class-fw-access-key',
|
||||
'FW_WP_Filesystem' => 'class-fw-wp-filesystem',
|
||||
'FW_Form' => 'class-fw-form',
|
||||
'FW_Form_Not_Found_Exception' => 'exceptions/class-fw-form-not-found-exception',
|
||||
'FW_Form_Invalid_Submission_Exception' => 'exceptions/class-fw-form-invalid-submission-exception',
|
||||
'FW_Settings_Form' => 'class-fw-settings-form',
|
||||
'FW_Request' => 'class-fw-request',
|
||||
'FW_Session' => 'class-fw-session',
|
||||
'FW_WP_Option' => 'class-fw-wp-option',
|
||||
'FW_WP_Meta' => 'class-fw-wp-meta',
|
||||
'FW_Db_Options_Model' => 'class-fw-db-options-model',
|
||||
'FW_Flash_Messages' => 'class-fw-flash-messages',
|
||||
'FW_Resize' => 'class-fw-resize',
|
||||
'FW_WP_List_Table' => 'class-fw-wp-list-table',
|
||||
'FW_Type' => 'type/class-fw-type',
|
||||
'FW_Type_Register' => 'type/class-fw-type-register',
|
||||
);
|
||||
|
||||
if (isset($class_to_file[$class])) {
|
||||
require dirname(__FILE__) .'/helpers/'. $class_to_file[$class] .'.php';
|
||||
}
|
||||
}
|
||||
spl_autoload_register('_fw_autoload_helper_classes');
|
||||
|
||||
spl_autoload_register( '_fw_includes_container_types_autoload' );
|
||||
function _fw_includes_container_types_autoload( $class ) {
|
||||
switch ( $class ) {
|
||||
case 'FW_Container_Type_Undefined' :
|
||||
require_once dirname( __FILE__ ) . '/includes/container-types/class-fw-container-type-undefined.php';
|
||||
break;
|
||||
case 'FW_Container_Type_Group' :
|
||||
require_once dirname( __FILE__ ) . '/includes/container-types/simple.php';
|
||||
break;
|
||||
case 'FW_Container_Type_Box' :
|
||||
require_once dirname( __FILE__ ) . '/includes/container-types/box/class-fw-container-type-box.php';
|
||||
break;
|
||||
case 'FW_Container_Type_Popup' :
|
||||
require_once dirname( __FILE__ ) . '/includes/container-types/popup/class-fw-container-type-popup.php';
|
||||
break;
|
||||
case 'FW_Container_Type_Tab' :
|
||||
require_once dirname( __FILE__ ) . '/includes/container-types/tab/class-fw-container-type-tab.php';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spl_autoload_register( '_fw_includes_customizer_autoload' );
|
||||
function _fw_includes_customizer_autoload( $class ) {
|
||||
switch ( $class ) {
|
||||
case '_FW_Customizer_Control_Option_Wrapper' :
|
||||
require_once dirname( __FILE__ ) . '/includes/customizer/class--fw-customizer-control-option-wrapper.php';
|
||||
break;
|
||||
case '_FW_Customizer_Setting_Option' :
|
||||
require_once dirname( __FILE__ ) . '/includes/customizer/class--fw-customizer-setting-option.php';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spl_autoload_register( '_fw_includes_option_storage_autoload' );
|
||||
function _fw_includes_option_storage_autoload( $class ) {
|
||||
switch ( $class ) {
|
||||
case '_FW_Option_Storage_Type_Register' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-storage/class--fw-option-storage-type-register.php';
|
||||
break;
|
||||
case 'FW_Option_Storage_Type' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-storage/class-fw-option-storage-type.php';
|
||||
break;
|
||||
case 'FW_Option_Storage_Type_Post_Meta' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-storage/type/class-fw-option-storage-type-post-meta.php';
|
||||
break;
|
||||
case 'FW_Option_Storage_Type_Term_Meta' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-storage/type/class-fw-option-storage-type-term-meta.php';
|
||||
break;
|
||||
case 'FW_Option_Storage_Type_WP_Option' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-storage/type/class-fw-option-storage-type-wp-option.php';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
spl_autoload_register( '_fw_includes_option_types_autoload' );
|
||||
function _fw_includes_option_types_autoload( $class ) {
|
||||
switch ( $class ) {
|
||||
case 'FW_Option_Type_Undefined' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/class-fw-option-type-undefined.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Hidden' :
|
||||
case 'FW_Option_Type_Text' :
|
||||
case 'FW_Option_Type_Short_Text' :
|
||||
case 'FW_Option_Type_Number' :
|
||||
case 'FW_Option_Type_Password' :
|
||||
case 'FW_Option_Type_Textarea' :
|
||||
case 'FW_Option_Type_Html' :
|
||||
case 'FW_Option_Type_Html_Fixed' :
|
||||
case 'FW_Option_Type_Html_Full' :
|
||||
case 'FW_Option_Type_Checkbox' :
|
||||
case 'FW_Option_Type_Checkboxes' :
|
||||
case 'FW_Option_Type_Radio' :
|
||||
case 'FW_Option_Type_Select' :
|
||||
case 'FW_Option_Type_Short_Select' :
|
||||
case 'FW_Option_Type_Select_Multiple' :
|
||||
case 'FW_Option_Type_Unique' :
|
||||
case 'FW_Option_Type_GMap_Key' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/simple.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Addable_Box' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/addable-box/class-fw-option-type-addable-box.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Addable_Popup' :
|
||||
case 'FW_Option_Type_Addable_Popup_Full' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/addable-popup/class-fw-option-type-addable-popup.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Addable_Option' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/addable-option/class-fw-option-type-addable-option.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Background_Image' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/background-image/class-fw-option-type-background-image.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Color_Picker' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/color-picker/class-fw-option-type-color-picker.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Date_Picker' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/date-picker/class-fw-option-type-wp-date-picker.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Datetime_Picker' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/datetime-picker/class-fw-option-type-datetime-picker.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Datetime_Range' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/datetime-range/class-fw-option-type-datetime-range.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Gradient' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/gradient/class-fw-option-type-gradient.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Icon' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/icon/class-fw-option-type-icon.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Icon_v2' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/icon-v2/class-fw-option-type-icon-v2.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Image_Picker' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/image-picker/class-fw-option-type-image-picker.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Map' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/map/class-fw-option-type-map.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Multi' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/multi/class-fw-option-type-multi.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Multi_Picker' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/multi-picker/class-fw-option-type-multi-picker.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Multi_Select' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/multi-select/class-fw-option-type-multi-select.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Multi_Upload' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/multi-upload/class-fw-option-type-multi-upload.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Oembed' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/oembed/class-fw-option-type-oembed.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Popup' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/popup/class-fw-option-type-popup.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Radio_Text' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/radio-text/class-fw-option-type-radio-text.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Range_Slider' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/range-slider/class-fw-option-type-range-slider.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Rgba_Color_Picker' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/rgba-color-picker/class-fw-option-type-rgba-color-picker.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Slider' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/slider/class-fw-option-type-slider.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Slider_Short' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/slider/class-fw-option-type-short-slider.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Switch' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/switch/class-fw-option-type-switch.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Typography' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/typography/class-fw-option-type-typography.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Typography_v2' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/typography-v2/class-fw-option-type-typography-v2.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Upload' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/upload/class-fw-option-type-upload.php';
|
||||
break;
|
||||
case 'FW_Option_Type_Wp_Editor' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/wp-editor/class-fw-option-type-wp-editor.php';
|
||||
break;
|
||||
case 'FW_Icon_V2_Favorites_Manager' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/icon-v2/includes/class-fw-icon-v2-favorites.php';
|
||||
break;
|
||||
case 'FW_Icon_V2_Packs_Loader' :
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/icon-v2/includes/class-fw-icon-v2-packs-loader.php';
|
||||
break;
|
||||
}
|
||||
}
|
||||
176
wp-content/plugins/unyson/framework/bin/load-latest-fonts.php
Normal file
@@ -0,0 +1,176 @@
|
||||
#!/usr/bin/env php
|
||||
|
||||
<?php
|
||||
|
||||
if ( php_sapi_name() != 'cli' ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Download latest font packs from their sources.
|
||||
*/
|
||||
|
||||
function get_libs_dir() {
|
||||
return dirname(__FILE__) . '/../static/libs/';
|
||||
}
|
||||
|
||||
$packs = array(
|
||||
array(
|
||||
'name' => 'entypo',
|
||||
'github-repo' => 'danielbruce/entypo',
|
||||
'css-file' => 'font/entypo.css',
|
||||
|
||||
'fonts' => array(
|
||||
'font/entypo.eot',
|
||||
'font/entypo.svg',
|
||||
'font/entypo.ttf',
|
||||
'font/entypo.woff'
|
||||
),
|
||||
|
||||
'replace' => array(
|
||||
array(
|
||||
'from' => "icon-",
|
||||
'to' => "entypo-"
|
||||
),
|
||||
|
||||
array(
|
||||
'from' => "url('entypo",
|
||||
'to' => "url('../fonts/entypo"
|
||||
),
|
||||
)
|
||||
),
|
||||
|
||||
'linearicons' => array(
|
||||
'name' => 'lnr',
|
||||
'css-file' => 'https://cdn.linearicons.com/free/1.0.0/icon-font.min.css',
|
||||
),
|
||||
|
||||
'typicons' => array(
|
||||
'name' => 'typcn',
|
||||
'github-repo' => 'stephenhutchings/typicons.font',
|
||||
|
||||
'css-file' => 'src/font/typicons.css',
|
||||
|
||||
'fonts' => array(
|
||||
'src/font/typicons.eot',
|
||||
'src/font/typicons.svg',
|
||||
'src/font/typicons.ttf',
|
||||
'src/font/typicons.woff'
|
||||
),
|
||||
|
||||
'replace' => array(
|
||||
array(
|
||||
'from' => "url('typicons",
|
||||
'to' => "url('../fonts/typicons"
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
'font-awesome' => array(
|
||||
'name' => 'font-awesome',
|
||||
'github-repo' => 'FortAwesome/Font-Awesome',
|
||||
'css-file' => 'css/font-awesome.min.css',
|
||||
'css-file-output' => 'font-awesome.min.css',
|
||||
'fonts' => array(
|
||||
'fonts/FontAwesome.otf',
|
||||
'fonts/fontawesome-webfont.eot',
|
||||
'fonts/fontawesome-webfont.svg',
|
||||
'fonts/fontawesome-webfont.ttf',
|
||||
'fonts/fontawesome-webfont.woff',
|
||||
'fonts/fontawesome-webfont.woff2'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($packs as $pack) {
|
||||
create_pack_directory($pack);
|
||||
|
||||
download_css($pack);
|
||||
download_fonts($pack);
|
||||
perform_replacements($pack);
|
||||
}
|
||||
|
||||
function create_pack_directory($pack) {
|
||||
if (file_exists(get_libs_dir() . $pack['name'])) return;
|
||||
|
||||
mkdir(get_libs_dir() . $pack['name']);
|
||||
mkdir(get_libs_dir() . $pack['name'] . '/css');
|
||||
mkdir(get_libs_dir() . $pack['name'] . '/fonts');
|
||||
|
||||
echo 'install ' . $pack['name'] . "\n";
|
||||
}
|
||||
|
||||
function download_css($pack) {
|
||||
if (! isset($pack['css-file'])) { return; }
|
||||
|
||||
$url = github_or_network_for($pack['css-file'], $pack);
|
||||
|
||||
$file_name = $pack['name'] . '.css';
|
||||
|
||||
if (isset($pack['css-file-output'])) {
|
||||
$file_name = $pack['css-file-output'];
|
||||
}
|
||||
|
||||
download_file(
|
||||
$url,
|
||||
// __DIR__ . '/static/css/' . $pack['name'] . '.css'
|
||||
get_libs_dir() . $pack['name'] . '/css/' . $file_name
|
||||
);
|
||||
}
|
||||
|
||||
function download_fonts($pack) {
|
||||
if (! isset($pack['fonts'])) { return; }
|
||||
|
||||
foreach ($pack['fonts'] as $font) {
|
||||
download_file(
|
||||
github_or_network_for($font, $pack),
|
||||
// __DIR__ . '/static/fonts/' . basename( $font )
|
||||
get_libs_dir() . $pack['name'] . '/fonts/' . basename( $font )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function perform_replacements($pack) {
|
||||
if (! isset($pack['replace'])) { return; }
|
||||
|
||||
// $file_path = __DIR__ . '/static/css/' . $pack['name'] . '.css';
|
||||
$file_path = get_libs_dir() . $pack['name'] . '/css/' . $pack['name'] . '.css';
|
||||
|
||||
$data = file_get_contents($file_path);
|
||||
|
||||
foreach ($pack['replace'] as $recipe) {
|
||||
$data = str_replace(
|
||||
$recipe['from'],
|
||||
$recipe['to'],
|
||||
$data
|
||||
);
|
||||
}
|
||||
|
||||
file_put_contents($file_path, $data);
|
||||
}
|
||||
|
||||
function github_or_network_for($base_url, $pack) {
|
||||
if (! isset($pack['github-repo'])) { return $base_url; }
|
||||
|
||||
return 'https://raw.githubusercontent.com/' .
|
||||
$pack['github-repo'] .
|
||||
'/master/' . $base_url;
|
||||
}
|
||||
|
||||
function download_file($url, $destination) {
|
||||
echo 'downloading ' . $destination . "\n";
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt( $ch, CURLOPT_ENCODING, "UTF-8" );
|
||||
|
||||
$data = curl_exec ($ch);
|
||||
$error = curl_error($ch);
|
||||
|
||||
curl_close ($ch);
|
||||
|
||||
$file = fopen($destination, "w+");
|
||||
fputs($file, $data);
|
||||
fclose($file);
|
||||
}
|
||||
79
wp-content/plugins/unyson/framework/bootstrap.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php if (!defined('ABSPATH')) die('Forbidden');
|
||||
|
||||
if ( defined( 'WP_CLI' ) && WP_CLI && ! isset( $_SERVER['HTTP_HOST'] ) ) {
|
||||
$_SERVER['HTTP_HOST'] = 'unyson.io';
|
||||
$_SERVER['SERVER_NAME'] = 'unyson';
|
||||
$_SERVER['SERVER_PORT'] = '80';
|
||||
}
|
||||
|
||||
if (defined('FW')) {
|
||||
/**
|
||||
* The framework is already loaded.
|
||||
*/
|
||||
} else {
|
||||
define('FW', true);
|
||||
|
||||
/**
|
||||
* Load the framework on 'after_setup_theme' action when the theme information is available
|
||||
* To prevent `undefined constant TEMPLATEPATH` errors when the framework is used as plugin
|
||||
*/
|
||||
add_action('after_setup_theme', '_action_init_framework');
|
||||
|
||||
function _action_init_framework() {
|
||||
if (did_action('fw_init')) {
|
||||
return;
|
||||
}
|
||||
|
||||
do_action('fw_before_init');
|
||||
|
||||
$dir = dirname(__FILE__);
|
||||
|
||||
require $dir .'/autoload.php';
|
||||
|
||||
// Load helper functions
|
||||
foreach (array('general', 'meta', 'fw-storage', 'database') as $file) {
|
||||
require $dir .'/helpers/'. $file .'.php';
|
||||
}
|
||||
|
||||
// Load core
|
||||
{
|
||||
require $dir .'/core/Fw.php';
|
||||
|
||||
fw();
|
||||
}
|
||||
|
||||
require $dir .'/includes/hooks.php';
|
||||
|
||||
/**
|
||||
* Init components
|
||||
*/
|
||||
{
|
||||
$components = array(
|
||||
/**
|
||||
* Load the theme's hooks.php first, to give users the possibility to add_action()
|
||||
* for `extensions` and `backend` components actions that can happen while their initialization
|
||||
*/
|
||||
'theme',
|
||||
/**
|
||||
* Load extensions before backend, to give extensions the possibility to add_action()
|
||||
* for the `backend` component actions that can happen while its initialization
|
||||
*/
|
||||
'extensions',
|
||||
'backend'
|
||||
);
|
||||
|
||||
foreach ($components as $component) {
|
||||
fw()->{$component}->_init();
|
||||
}
|
||||
|
||||
foreach ($components as $component) {
|
||||
fw()->{$component}->_after_components_init();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The framework is loaded
|
||||
*/
|
||||
do_action('fw_init');
|
||||
}
|
||||
}
|
||||
79
wp-content/plugins/unyson/framework/core/Fw.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* Main framework class that contains everything
|
||||
*
|
||||
* Convention: All public properties should be only instances of the components (except special property: manifest)
|
||||
*/
|
||||
final class _Fw
|
||||
{
|
||||
/** @var bool If already loaded */
|
||||
private static $loaded = false;
|
||||
|
||||
/** @var FW_Framework_Manifest */
|
||||
public $manifest;
|
||||
|
||||
/** @var _FW_Component_Extensions */
|
||||
public $extensions;
|
||||
|
||||
/** @var _FW_Component_Backend */
|
||||
public $backend;
|
||||
|
||||
/** @var _FW_Component_Theme */
|
||||
public $theme;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (self::$loaded) {
|
||||
trigger_error('Framework already loaded', E_USER_ERROR);
|
||||
} else {
|
||||
self::$loaded = true;
|
||||
}
|
||||
|
||||
$fw_dir = fw_get_framework_directory();
|
||||
|
||||
// manifest
|
||||
{
|
||||
require $fw_dir .'/manifest.php';
|
||||
/** @var array $manifest */
|
||||
|
||||
$this->manifest = new FW_Framework_Manifest($manifest);
|
||||
|
||||
add_action('fw_init', array($this, '_check_requirements'), 1);
|
||||
}
|
||||
|
||||
// components
|
||||
{
|
||||
$this->extensions = new _FW_Component_Extensions();
|
||||
$this->backend = new _FW_Component_Backend();
|
||||
$this->theme = new _FW_Component_Theme();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _check_requirements()
|
||||
{
|
||||
if (is_admin() && !$this->manifest->check_requirements()) {
|
||||
FW_Flash_Messages::add(
|
||||
'fw_requirements',
|
||||
__('Framework requirements not met:', 'fw') .' '. $this->manifest->get_not_met_requirement_text(),
|
||||
'warning'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return _FW Framework instance
|
||||
*/
|
||||
function fw() {
|
||||
static $FW = null; // cache
|
||||
|
||||
if ($FW === null) {
|
||||
$FW = new _Fw();
|
||||
}
|
||||
|
||||
return $FW;
|
||||
}
|
||||
572
wp-content/plugins/unyson/framework/core/class-fw-manifest.php
Normal file
@@ -0,0 +1,572 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
abstract class FW_Manifest
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $manifest;
|
||||
|
||||
/**
|
||||
* The first requirement that was not met
|
||||
* (that marks that the requirements are not met)
|
||||
*
|
||||
* @var array
|
||||
* array(
|
||||
* 'requirement' => 'wordpress|framework',
|
||||
* 'requirements' => array('min_version' => '1.2.3', ...)
|
||||
* )
|
||||
* or
|
||||
* array(
|
||||
* 'requirement' => 'extensions',
|
||||
* 'extension' => 'extension_name',
|
||||
* 'requirements' => array('min_version' => '1.2.3', ...)
|
||||
* )
|
||||
*/
|
||||
private $not_met_requirement;
|
||||
|
||||
/**
|
||||
* When an requirement that sure will not change is not met and have no sense to execute check_requirements() again
|
||||
* @var bool
|
||||
*/
|
||||
private $not_met_is_final = false;
|
||||
|
||||
/**
|
||||
* Not met requirement and skipped (not verified) requirements after $this->not_met_requirement was found
|
||||
* @var array
|
||||
*/
|
||||
private $requirements_for_verification;
|
||||
|
||||
private $requirements_verification_never_called = true;
|
||||
|
||||
/**
|
||||
* @param array $manifest
|
||||
*/
|
||||
protected function __construct(array $manifest)
|
||||
{
|
||||
$manifest = array_merge(array(
|
||||
'name' => null, // title
|
||||
'uri' => null,
|
||||
'description' => null,
|
||||
'version' => '0.0.0',
|
||||
'author' => null,
|
||||
'author_uri' => null,
|
||||
|
||||
// Custom fields
|
||||
'requirements' => array(),
|
||||
), $manifest);
|
||||
|
||||
/**
|
||||
* Merge $manifest['requirements']
|
||||
*/
|
||||
{
|
||||
$requirements = $manifest['requirements'];
|
||||
|
||||
$manifest['requirements'] = array();
|
||||
|
||||
foreach ($this->get_default_requirements() as $default_requirement => $default_requirements) {
|
||||
$manifest['requirements'][ $default_requirement ] = isset($requirements[$default_requirement])
|
||||
? array_merge(
|
||||
$default_requirements,
|
||||
$requirements[$default_requirement]
|
||||
)
|
||||
: $default_requirements;
|
||||
}
|
||||
|
||||
unset($requirements);
|
||||
}
|
||||
|
||||
$this->requirements_for_verification = $manifest['requirements'];
|
||||
|
||||
$this->manifest = $manifest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array { 'requirement' => array('min_version' => '..', 'max_version' => '..') }
|
||||
*/
|
||||
abstract protected function get_default_requirements();
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function requirements_met()
|
||||
{
|
||||
if ($this->not_met_is_final) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->requirements_verification_never_called) {
|
||||
$this->requirements_verification_never_called = false;
|
||||
|
||||
$this->check_requirements();
|
||||
}
|
||||
|
||||
return empty($this->requirements_for_verification) && empty($this->not_met_requirement);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function check_requirements()
|
||||
{
|
||||
if ($this->not_met_is_final) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->requirements_met()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->not_met_requirement = array();
|
||||
|
||||
global $wp_version;
|
||||
|
||||
foreach ($this->requirements_for_verification as $requirement => $requirements) {
|
||||
switch ($requirement) {
|
||||
case 'php':
|
||||
if ( ! function_exists( 'phpversion' ) ) {
|
||||
break;
|
||||
}
|
||||
if (
|
||||
isset($requirements['min_version'])
|
||||
&&
|
||||
version_compare(phpversion(), $requirements['min_version'], '<')
|
||||
) {
|
||||
$this->not_met_requirement = array(
|
||||
'requirement' => $requirement,
|
||||
'requirements' => $requirements
|
||||
);
|
||||
$this->not_met_is_final = true;
|
||||
break 2;
|
||||
}
|
||||
|
||||
if (
|
||||
isset($requirements['max_version'])
|
||||
&&
|
||||
version_compare(phpversion(), $requirements['max_version'], '>')
|
||||
) {
|
||||
$this->not_met_requirement = array(
|
||||
'requirement' => $requirement,
|
||||
'requirements' => $requirements
|
||||
);
|
||||
$this->not_met_is_final = true;
|
||||
break 2;
|
||||
}
|
||||
|
||||
// met
|
||||
unset($this->requirements_for_verification[$requirement]);
|
||||
break;
|
||||
case 'wordpress':
|
||||
if (
|
||||
isset($requirements['min_version'])
|
||||
&&
|
||||
version_compare($wp_version, $requirements['min_version'], '<')
|
||||
) {
|
||||
$this->not_met_requirement = array(
|
||||
'requirement' => $requirement,
|
||||
'requirements' => $requirements
|
||||
);
|
||||
$this->not_met_is_final = true;
|
||||
break 2;
|
||||
}
|
||||
|
||||
if (
|
||||
isset($requirements['max_version'])
|
||||
&&
|
||||
version_compare($wp_version, $requirements['max_version'], '>')
|
||||
) {
|
||||
$this->not_met_requirement = array(
|
||||
'requirement' => $requirement,
|
||||
'requirements' => $requirements
|
||||
);
|
||||
$this->not_met_is_final = true;
|
||||
break 2;
|
||||
}
|
||||
|
||||
// met
|
||||
unset($this->requirements_for_verification[$requirement]);
|
||||
break;
|
||||
case 'framework':
|
||||
if (
|
||||
isset($requirements['min_version'])
|
||||
&&
|
||||
version_compare(fw()->manifest->get_version(), $requirements['min_version'], '<')
|
||||
) {
|
||||
$this->not_met_requirement = array(
|
||||
'requirement' => $requirement,
|
||||
'requirements' => $requirements
|
||||
);
|
||||
$this->not_met_is_final = true;
|
||||
break 2;
|
||||
}
|
||||
|
||||
if (
|
||||
isset($requirements['max_version'])
|
||||
&&
|
||||
version_compare(fw()->manifest->get_version(), $requirements['max_version'], '>')
|
||||
) {
|
||||
$this->not_met_requirement = array(
|
||||
'requirement' => $requirement,
|
||||
'requirements' => $requirements
|
||||
);
|
||||
$this->not_met_is_final = true;
|
||||
break 2;
|
||||
}
|
||||
|
||||
// met
|
||||
unset($this->requirements_for_verification[$requirement]);
|
||||
break;
|
||||
case 'extensions':
|
||||
$extensions =& $requirements;
|
||||
|
||||
foreach ($extensions as $extension => $extension_requirements) {
|
||||
$extension_instance = fw()->extensions->get($extension);
|
||||
|
||||
if (!$extension_instance) {
|
||||
/**
|
||||
* extension in requirements does not exists
|
||||
* maybe try call this method later and maybe will exist, or it really does not exists
|
||||
*/
|
||||
$this->not_met_requirement = array(
|
||||
'requirement' => $requirement,
|
||||
'extension' => $extension,
|
||||
'requirements' => $extension_requirements
|
||||
);
|
||||
break 3;
|
||||
}
|
||||
|
||||
if (
|
||||
isset($extension_requirements['min_version'])
|
||||
&&
|
||||
version_compare($extension_instance->manifest->get_version(), $extension_requirements['min_version'], '<')
|
||||
) {
|
||||
$this->not_met_requirement = array(
|
||||
'requirement' => $requirement,
|
||||
'extension' => $extension,
|
||||
'requirements' => $extension_requirements
|
||||
);
|
||||
$this->not_met_is_final = true;
|
||||
break 3;
|
||||
}
|
||||
|
||||
if (
|
||||
isset($extension_requirements['max_version'])
|
||||
&&
|
||||
version_compare($extension_instance->manifest->get_version(), $extension_requirements['max_version'], '>')
|
||||
) {
|
||||
$this->not_met_requirement = array(
|
||||
'requirement' => $requirement,
|
||||
'extension' => $extension,
|
||||
'requirements' => $extension_requirements
|
||||
);
|
||||
$this->not_met_is_final = true;
|
||||
break 3;
|
||||
}
|
||||
|
||||
// met
|
||||
unset($this->requirements_for_verification[$requirement][$extension]);
|
||||
}
|
||||
|
||||
if (empty($this->requirements_for_verification[$requirement])) {
|
||||
// all extensions requirements met
|
||||
unset($this->requirements_for_verification[$requirement]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->requirements_met();
|
||||
}
|
||||
|
||||
public function get_version()
|
||||
{
|
||||
return $this->manifest['version'];
|
||||
}
|
||||
|
||||
public function get_name()
|
||||
{
|
||||
return $this->manifest['name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $multi_key
|
||||
* @param mixed $default_value
|
||||
* @return mixed
|
||||
*/
|
||||
public function get( $multi_key, $default_value = null ) {
|
||||
return fw_akg( $multi_key, $this->manifest, $default_value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get entire manifest.
|
||||
* @return array
|
||||
*/
|
||||
public function get_manifest() {
|
||||
return $this->manifest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this only after check_requirements() failed
|
||||
* @return array
|
||||
*/
|
||||
public function get_not_met_requirement()
|
||||
{
|
||||
return $this->not_met_requirement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return user friendly requirement as text
|
||||
* Call this only after check_requirements() failed
|
||||
* @return string
|
||||
*/
|
||||
public function get_not_met_requirement_text()
|
||||
{
|
||||
if (!$this->not_met_requirement) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$requirement = array();
|
||||
|
||||
foreach ($this->not_met_requirement['requirements'] as $req_key => $req) {
|
||||
switch ($req_key) {
|
||||
case 'min_version':
|
||||
$requirement[] = __('minimum required version is', 'fw') .' '. $req;
|
||||
break;
|
||||
case 'max_version':
|
||||
$requirement[] = __('maximum required version is', 'fw') .' '. $req;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$requirement = implode(' '. __('and', 'fw') .' ', $requirement);
|
||||
|
||||
switch ($this->not_met_requirement['requirement']) {
|
||||
case 'php':
|
||||
if ( ! function_exists( 'phpversion' ) ) {
|
||||
break;
|
||||
}
|
||||
|
||||
$requirement = sprintf(
|
||||
__('Current PHP version is %s, %s', 'fw'),
|
||||
phpversion(), $requirement
|
||||
);
|
||||
break;
|
||||
case 'wordpress':
|
||||
global $wp_version;
|
||||
|
||||
$requirement = sprintf(
|
||||
__('Current WordPress version is %s, %s', 'fw'),
|
||||
$wp_version, $requirement
|
||||
);
|
||||
break;
|
||||
case 'framework':
|
||||
$requirement = sprintf(
|
||||
__('Current Framework version is %s, %s', 'fw'),
|
||||
fw()->manifest->get_version(), $requirement
|
||||
);
|
||||
break;
|
||||
case 'extensions':
|
||||
$extension = fw()->extensions->get($this->not_met_requirement['extension']);
|
||||
|
||||
if ($extension) {
|
||||
$requirement = sprintf(
|
||||
__('Current version of the %s extension is %s, %s', 'fw'),
|
||||
$extension->manifest->get_name(), $extension->manifest->get_version(), $requirement
|
||||
);
|
||||
} else {
|
||||
if (empty($requirement)) {
|
||||
$requirement = sprintf(
|
||||
__('%s extension is required', 'fw'),
|
||||
ucfirst($this->not_met_requirement['extension'])
|
||||
);
|
||||
} else {
|
||||
$requirement = sprintf(
|
||||
__('%s extension is required (%s)', 'fw'),
|
||||
ucfirst($this->not_met_requirement['extension']), $requirement
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$requirement = 'Unknown requirement "'. $this->not_met_requirement['requirement'] .'"';
|
||||
}
|
||||
|
||||
return $requirement;
|
||||
}
|
||||
}
|
||||
|
||||
class FW_Framework_Manifest extends FW_Manifest
|
||||
{
|
||||
public function __construct(array $manifest)
|
||||
{
|
||||
if (empty($manifest['name'])) {
|
||||
$manifest['name'] = __('Framework', 'fw');
|
||||
}
|
||||
|
||||
parent::__construct($manifest);
|
||||
}
|
||||
|
||||
protected function get_default_requirements()
|
||||
{
|
||||
return array(
|
||||
'php' => array(
|
||||
'min_version' => '5.2.4',
|
||||
/*'max_version' => '10000.0.0',*/
|
||||
),
|
||||
'wordpress' => array(
|
||||
'min_version' => '4.0',
|
||||
/*'max_version' => '10000.0.0',*/
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class FW_Theme_Manifest extends FW_Manifest
|
||||
{
|
||||
public function __construct(array $manifest)
|
||||
{
|
||||
$manifest_defaults = array(
|
||||
/**
|
||||
* You can use this in a wp_option id,
|
||||
* so that option value will be different on a theme with different id.
|
||||
*
|
||||
* fixme: default value should be get_option( 'stylesheet' ) but it can't be changed now
|
||||
* because there can be themes that has saved Theme Settings in wp_option: 'fw_theme_settings_options:default'
|
||||
* changing this default value will result in Theme Settings options "reset".
|
||||
*/
|
||||
'id' => 'default',
|
||||
'supported_extensions' => array(
|
||||
/*
|
||||
'extension_name' => array(),
|
||||
*/
|
||||
),
|
||||
);
|
||||
|
||||
$theme = wp_get_theme();
|
||||
|
||||
foreach(array(
|
||||
'name' => 'Name',
|
||||
'uri' => 'ThemeURI',
|
||||
'description' => 'Description',
|
||||
'version' => 'Version',
|
||||
'author' => 'Author',
|
||||
'author_uri' => 'AuthorURI',
|
||||
) as $manifest_key => $stylesheet_header) {
|
||||
$header_value = trim($theme->get($stylesheet_header));
|
||||
|
||||
if ( is_child_theme() && $theme->parent() ) {
|
||||
switch ($manifest_key) {
|
||||
case 'version':
|
||||
case 'uri':
|
||||
case 'author':
|
||||
case 'author_uri':
|
||||
case 'license':
|
||||
// force parent theme value
|
||||
$header_value = $theme->parent()->get($stylesheet_header);
|
||||
break;
|
||||
default:
|
||||
if (!$header_value) {
|
||||
// use parent theme value only if child theme value is empty
|
||||
$header_value = $theme->parent()->get($stylesheet_header);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($header_value) {
|
||||
$manifest_defaults[$manifest_key] = $header_value;
|
||||
}
|
||||
}
|
||||
|
||||
parent::__construct(array_merge($manifest_defaults, $manifest));
|
||||
}
|
||||
|
||||
protected function get_default_requirements()
|
||||
{
|
||||
return array(
|
||||
'php' => array(
|
||||
'min_version' => '5.2.4',
|
||||
/*'max_version' => '10000.0.0',*/
|
||||
),
|
||||
'wordpress' => array(
|
||||
'min_version' => '4.0',
|
||||
/*'max_version' => '10000.0.0',*/
|
||||
),
|
||||
'framework' => array(
|
||||
/*'min_version' => '0.0.0',
|
||||
'max_version' => '1000.0.0'*/
|
||||
),
|
||||
'extensions' => array(
|
||||
/*'extension_name' => array(
|
||||
'min_version' => '0.0.0',
|
||||
'max_version' => '1000.0.0'
|
||||
)*/
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function get_id()
|
||||
{
|
||||
return $this->manifest['id'];
|
||||
}
|
||||
}
|
||||
|
||||
class FW_Extension_Manifest extends FW_Manifest
|
||||
{
|
||||
public function __construct(array $manifest)
|
||||
{
|
||||
parent::__construct($manifest);
|
||||
|
||||
unset($manifest);
|
||||
|
||||
// unset unnecessary keys
|
||||
unset($this->manifest['id']);
|
||||
|
||||
$this->manifest = array_merge(array(
|
||||
/**
|
||||
* @type bool Display on the Extensions page or it's a hidden extension
|
||||
*/
|
||||
'display' => false,
|
||||
/**
|
||||
* @type bool If extension can exist alone
|
||||
* false - There is no sense for it to exist alone, it exists only when is required by some other extension.
|
||||
* true - Can exist alone without bothering about other extensions.
|
||||
*/
|
||||
'standalone' => false,
|
||||
/**
|
||||
* @type string Thumbnail used on the Extensions page
|
||||
* All framework extensions has thumbnails set in the available extensions list
|
||||
* but if your extension is not in that list and id located in the theme, you can set the thumbnail via this parameter
|
||||
*/
|
||||
'thumbnail' => null,
|
||||
), $this->manifest);
|
||||
}
|
||||
|
||||
protected function get_default_requirements()
|
||||
{
|
||||
return array(
|
||||
'php' => array(
|
||||
'min_version' => '5.2.4',
|
||||
/*'max_version' => '10000.0.0',*/
|
||||
),
|
||||
'wordpress' => array(
|
||||
'min_version' => '4.0',
|
||||
/*'max_version' => '10000.0.0',*/
|
||||
),
|
||||
'framework' => array(
|
||||
/*'min_version' => '0.0.0',
|
||||
'max_version' => '1000.0.0'*/
|
||||
),
|
||||
'extensions' => array(
|
||||
/*'extension_name' => array(
|
||||
'min_version' => '0.0.0',
|
||||
'max_version' => '1000.0.0'
|
||||
)*/
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function get_required_extensions()
|
||||
{
|
||||
return $this->manifest['requirements']['extensions'];
|
||||
}
|
||||
}
|
||||
2125
wp-content/plugins/unyson/framework/core/components/backend.php
Normal file
@@ -0,0 +1,222 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* Used in fw()->backend
|
||||
* @internal
|
||||
*/
|
||||
class FW_Settings_Form_Theme extends FW_Settings_Form {
|
||||
protected function _init() {
|
||||
$this
|
||||
->set_is_ajax_submit( fw()->theme->get_config('settings_form_ajax_submit') )
|
||||
->set_is_side_tabs( fw()->theme->get_config('settings_form_side_tabs') )
|
||||
->set_string( 'title', __('Theme Settings', 'fw') );
|
||||
|
||||
{
|
||||
add_action('admin_init', array($this, '_action_get_title_from_menu'));
|
||||
add_action('admin_menu', array($this, '_action_admin_menu'));
|
||||
add_action('admin_enqueue_scripts', array($this, '_action_admin_enqueue_scripts'),
|
||||
/**
|
||||
* In case some custom defined option types are using script/styles registered
|
||||
* in actions with default priority 10 (make sure the enqueue is executed after register)
|
||||
* @see _FW_Component_Backend::add_actions()
|
||||
*/
|
||||
11
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_options() {
|
||||
return fw()->theme->get_settings_options();
|
||||
}
|
||||
|
||||
public function set_values($values) {
|
||||
fw_set_db_settings_option(null, $values);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_values() {
|
||||
return fw_get_db_settings_option();
|
||||
}
|
||||
|
||||
/**
|
||||
* User can overwrite Theme Settings menu, move it and change its title
|
||||
* extract that title from WP menu
|
||||
* @internal
|
||||
*/
|
||||
public function _action_get_title_from_menu() {
|
||||
if ($this->get_is_side_tabs()) {
|
||||
$title = fw()->theme->manifest->get_name();
|
||||
|
||||
if (fw()->theme->manifest->get('author')) {
|
||||
if (fw()->theme->manifest->get('author_uri')) {
|
||||
$title .= ' '. fw_html_tag('a', array(
|
||||
'href' => fw()->theme->manifest->get('author_uri'),
|
||||
'target' => '_blank'
|
||||
), '<small>' . __('by', 'fw') . ' ' . fw()->theme->manifest->get('author') . '</small>');
|
||||
} else {
|
||||
$title .= ' <small>' . fw()->theme->manifest->get('author') . '</small>';
|
||||
}
|
||||
}
|
||||
|
||||
$this->set_string('title', $title);
|
||||
} else {
|
||||
// Extract page title from menu title
|
||||
do {
|
||||
global $menu, $submenu;
|
||||
|
||||
if (is_array($menu)) {
|
||||
foreach ($menu as $_menu) {
|
||||
if ($_menu[2] === fw()->backend->_get_settings_page_slug()) {
|
||||
$title = $_menu[0];
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($submenu)) {
|
||||
foreach ($submenu as $_menu) {
|
||||
foreach ($_menu as $_submenu) {
|
||||
if ($_submenu[2] === fw()->backend->_get_settings_page_slug()) {
|
||||
$title = $_submenu[0];
|
||||
break 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} while(false);
|
||||
|
||||
if (isset($title)) {
|
||||
$this->set_string('title', $title);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _action_admin_menu() {
|
||||
$data = array(
|
||||
'capability' => 'manage_options',
|
||||
'slug' => fw()->backend->_get_settings_page_slug(),
|
||||
'content_callback' => array( $this, 'render' ),
|
||||
);
|
||||
|
||||
if ( ! current_user_can( $data['capability'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (fw()->theme->get_config('disable_theme_settings_page', false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! fw()->theme->locate_path('/options/settings.php') ) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect $hookname that contains $data['slug'] before the action
|
||||
* and skip them in verification after action
|
||||
*/
|
||||
{
|
||||
global $_registered_pages;
|
||||
|
||||
$found_hooknames = array();
|
||||
|
||||
if ( ! empty( $_registered_pages ) ) {
|
||||
foreach ( $_registered_pages as $hookname => $b ) {
|
||||
if ( strpos( $hookname, $data['slug'] ) !== false ) {
|
||||
$found_hooknames[ $hookname ] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this action if you what to add the settings page in a custom place in menu
|
||||
* Usage example http://pastebin.com/gvAjGRm1
|
||||
*/
|
||||
do_action( 'fw_backend_add_custom_settings_menu', $data );
|
||||
|
||||
/**
|
||||
* Check if settings menu was added in the action above
|
||||
*/
|
||||
{
|
||||
$menu_exists = false;
|
||||
|
||||
if ( ! empty( $_registered_pages ) ) {
|
||||
foreach ( $_registered_pages as $hookname => $b ) {
|
||||
if ( isset( $found_hooknames[ $hookname ] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( strpos( $hookname, $data['slug'] ) !== false ) {
|
||||
$menu_exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $menu_exists ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_theme_page(
|
||||
__( 'Theme Settings', 'fw' ),
|
||||
__( 'Theme Settings', 'fw' ),
|
||||
$data['capability'],
|
||||
$data['slug'],
|
||||
$data['content_callback']
|
||||
);
|
||||
|
||||
add_action( 'admin_menu', array( $this, '_action_admin_change_theme_settings_order' ), 9999 );
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _action_admin_change_theme_settings_order() {
|
||||
global $submenu;
|
||||
|
||||
if ( ! isset( $submenu['themes.php'] ) ) {
|
||||
// probably current user doesn't have this item in menu
|
||||
return;
|
||||
}
|
||||
|
||||
$id = fw()->backend->_get_settings_page_slug();
|
||||
$index = null;
|
||||
|
||||
foreach ( $submenu['themes.php'] as $key => $sm ) {
|
||||
if ( $sm[2] == $id ) {
|
||||
$index = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $index ) ) {
|
||||
$item = $submenu['themes.php'][ $index ];
|
||||
unset( $submenu['themes.php'][ $index ] );
|
||||
array_unshift( $submenu['themes.php'], $item );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _action_admin_enqueue_scripts()
|
||||
{
|
||||
global $plugin_page;
|
||||
|
||||
/**
|
||||
* Enqueue settings options static in <head>
|
||||
*/
|
||||
{
|
||||
if (fw()->backend->_get_settings_page_slug() === $plugin_page) {
|
||||
$this->enqueue_static();
|
||||
|
||||
do_action('fw_admin_enqueue_scripts:settings');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,688 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* Extensions component
|
||||
*/
|
||||
final class _FW_Component_Extensions
|
||||
{
|
||||
/**
|
||||
* All existing extensions
|
||||
* @var FW_Extension[] { 'extension_name' => instance }
|
||||
*/
|
||||
private static $all_extensions = array();
|
||||
|
||||
/**
|
||||
* All existing extensions names arranged in hierarchical tree like they are in directories
|
||||
* @var array
|
||||
*/
|
||||
private static $all_extensions_tree = array();
|
||||
|
||||
/**
|
||||
* Active extensions
|
||||
*
|
||||
* On every extension activation, it will be pushed at the end of this array.
|
||||
* The extensions order is important when including files.
|
||||
* If extension A requires extension B, extension B is activated before extension A,
|
||||
* and all files of the extension B (hooks.php, static.php, etc.) must be included before extension A
|
||||
* For e.g. extension A may have in static.php:
|
||||
* wp_enqueue_script( 'ext-A-script', 'script.js', array( 'ext-B-script' ) );
|
||||
* so 'ext-B-script' must be registered before 'ext-A-script'
|
||||
*
|
||||
* @var FW_Extension[] { 'extension_name' => instance }
|
||||
*/
|
||||
private static $active_extensions = array();
|
||||
|
||||
/**
|
||||
* Active extensions names arranged in hierarchical tree like they are in directories
|
||||
* @var array
|
||||
*/
|
||||
private static $active_extensions_tree = array();
|
||||
|
||||
/**
|
||||
* @var array { 'extension_name' => array('required_by', 'required_by') }
|
||||
*/
|
||||
private static $extensions_required_by_extensions = array();
|
||||
|
||||
/**
|
||||
* @var array { 'extension_name' => &array() }
|
||||
*/
|
||||
private static $extension_to_all_tree = array();
|
||||
|
||||
/**
|
||||
* @var array { 'extension_name' => &array() }
|
||||
*/
|
||||
private static $extension_to_active_tree = array();
|
||||
|
||||
/**
|
||||
* @var FW_Access_Key
|
||||
*/
|
||||
private static $access_key;
|
||||
|
||||
/** @var FW_Extension_Manifest[] All extensions manifests */
|
||||
private static $manifests = array();
|
||||
|
||||
/**
|
||||
* @var null|_FW_Extensions_Manager
|
||||
*/
|
||||
public $manager;
|
||||
|
||||
/**
|
||||
* Option name that stores the active extensions array
|
||||
* @internal
|
||||
*/
|
||||
public function _get_active_extensions_db_option_name()
|
||||
{
|
||||
return 'fw_active_extensions';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|string $extension_name Check if an extension is set as active in database
|
||||
* @internal
|
||||
* @return array|bool
|
||||
*/
|
||||
public function _get_db_active_extensions($extension_name = null)
|
||||
{
|
||||
$extensions = get_option($this->_get_active_extensions_db_option_name(), array());
|
||||
|
||||
if ($extension_name) {
|
||||
return isset($extensions[$extension_name]);
|
||||
} else {
|
||||
return $extensions;
|
||||
}
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
$this->manager = new _FW_Extensions_Manager();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $extension_name
|
||||
* @param FW_Access_Key $access_key
|
||||
* @return FW_Extension_Manifest|null
|
||||
* @internal
|
||||
* @since 2.6.9
|
||||
*/
|
||||
public static function _get_manifest($extension_name, FW_Access_Key $access_key) {
|
||||
if ( ! in_array( $access_key->get_key(), array( 'extension', self::$access_key->get_key() ), true ) ) {
|
||||
trigger_error( 'Method call denied', E_USER_ERROR );
|
||||
}
|
||||
|
||||
if (isset(self::$all_extensions[$extension_name])) {
|
||||
if (!isset(self::$manifests[$extension_name])) {
|
||||
$manifest = fw_get_variables_from_file(
|
||||
self::$all_extensions[$extension_name]['path'] .'/manifest.php', array('manifest' => array())
|
||||
);
|
||||
$manifest = $manifest['manifest'];
|
||||
|
||||
if (empty($manifest['name'])) {
|
||||
$manifest['name'] = fw_id_to_title($extension_name);
|
||||
}
|
||||
|
||||
self::$manifests[$extension_name] = new FW_Extension_Manifest($manifest);
|
||||
}
|
||||
|
||||
return self::$manifests[$extension_name];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load extension from directory
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
private static function load_extensions($data)
|
||||
{
|
||||
/**
|
||||
* Do not check all keys
|
||||
* if one not set, then sure others are not set (this is a private method)
|
||||
*/
|
||||
if (!isset($data['all_extensions_tree'])) {
|
||||
$data['all_extensions_tree'] = &self::$all_extensions_tree;
|
||||
$data['all_extensions'] = &self::$all_extensions;
|
||||
$data['current_depth'] = 1;
|
||||
$data['rel_path'] = '';
|
||||
$data['parent'] = null;
|
||||
}
|
||||
|
||||
$dirs = glob($data['path'] .'/*', GLOB_ONLYDIR);
|
||||
|
||||
if (empty($dirs)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($data['current_depth'] > 1) {
|
||||
$customizations_locations = array();
|
||||
|
||||
foreach ($data['customizations_locations'] as $customization_path => $customization_uri) {
|
||||
$customizations_locations[ $customization_path .'/extensions' ] = $customization_uri .'/extensions';
|
||||
}
|
||||
|
||||
$data['customizations_locations'] = $customizations_locations;
|
||||
}
|
||||
|
||||
foreach ($dirs as $extension_dir) {
|
||||
$extension_name = basename($extension_dir);
|
||||
|
||||
{
|
||||
$customizations_locations = array();
|
||||
|
||||
foreach ($data['customizations_locations'] as $customization_path => $customization_uri) {
|
||||
$customizations_locations[ $customization_path .'/'. $extension_name ] = $customization_uri .'/'. $extension_name;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['all_extensions'][$extension_name])) {
|
||||
if ($data['all_extensions'][$extension_name]['parent'] !== $data['parent']) {
|
||||
// extension with the same name exists in another tree
|
||||
trigger_error(
|
||||
'Extension "'. $extension_name .'" is already defined '.
|
||||
'in "'. $data['all_extensions'][$extension_name]['path'] .'" '.
|
||||
'found again in "'. $extension_dir .'"',
|
||||
E_USER_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
// this is a directory with customizations for an extension
|
||||
|
||||
self::load_extensions(array(
|
||||
'rel_path' => $data['rel_path'] .'/'. $extension_name .'/extensions',
|
||||
'path' => $data['path'] .'/'. $extension_name .'/extensions',
|
||||
'uri' => $data['uri'] .'/'. $extension_name .'/extensions',
|
||||
'customizations_locations' => $customizations_locations,
|
||||
|
||||
'all_extensions_tree' => &$data['all_extensions_tree'][$extension_name],
|
||||
'all_extensions' => &$data['all_extensions'],
|
||||
'current_depth' => $data['current_depth'] + 1,
|
||||
'parent' => $extension_name,
|
||||
));
|
||||
} else {
|
||||
if (file_exists($extension_dir .'/manifest.php')) {
|
||||
$data['all_extensions_tree'][$extension_name] = array();
|
||||
|
||||
self::$extension_to_all_tree[$extension_name] = &$data['all_extensions_tree'][$extension_name];
|
||||
|
||||
$data['all_extensions'][$extension_name] = array(
|
||||
'rel_path' => $data['rel_path'] .'/'. $extension_name,
|
||||
'path' => $data['path'] .'/'. $extension_name,
|
||||
'uri' => $data['uri'] .'/'. $extension_name,
|
||||
'parent' => $data['parent'],
|
||||
'depth' => $data['current_depth'],
|
||||
'customizations_locations' => $customizations_locations,
|
||||
'instance' => null, // created on activation
|
||||
);
|
||||
} else {
|
||||
/**
|
||||
* The manifest file does not exist, do not load this extension.
|
||||
* Maybe it's a directory with configurations for a not existing extension.
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
|
||||
self::load_extensions(array(
|
||||
'rel_path' => $data['all_extensions'][$extension_name]['rel_path'] .'/extensions',
|
||||
'path' => $data['all_extensions'][$extension_name]['path'] .'/extensions',
|
||||
'uri' => $data['all_extensions'][$extension_name]['uri'] .'/extensions',
|
||||
'customizations_locations' => $customizations_locations,
|
||||
|
||||
'parent' => $extension_name,
|
||||
'all_extensions_tree' => &$data['all_extensions_tree'][$extension_name],
|
||||
'all_extensions' => &$data['all_extensions'],
|
||||
'current_depth' => $data['current_depth'] + 1,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Include file from all extension's locations: framework, parent, child
|
||||
* @param string|FW_Extension $extension
|
||||
* @param string $file_rel_path
|
||||
* @param bool $themeFirst
|
||||
* false - [framework, parent, child]
|
||||
* true - [child, parent, framework]
|
||||
* @param bool $onlyFirstFound
|
||||
*/
|
||||
private static function include_extension_file_all_locations($extension, $file_rel_path, $themeFirst = false, $onlyFirstFound = false)
|
||||
{
|
||||
if (is_string($extension)) {
|
||||
$extension = fw()->extensions->get($extension);
|
||||
}
|
||||
|
||||
$paths = $extension->get_customizations_locations();
|
||||
$paths[$extension->get_path()] = $extension->get_uri();
|
||||
|
||||
if (!$themeFirst) {
|
||||
$paths = array_reverse($paths);
|
||||
}
|
||||
|
||||
foreach ($paths as $path => $uri) {
|
||||
if (fw_include_file_isolated($path . $file_rel_path)) {
|
||||
if ($onlyFirstFound) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Include all files from directory, from all extension's locations: framework, child, parent
|
||||
* @param string|FW_Extension $extension
|
||||
* @param string $dir_rel_path
|
||||
* @param bool $themeFirst
|
||||
* false - [framework, parent, child]
|
||||
* true - [child, parent, framework]
|
||||
*/
|
||||
private static function include_extension_directory_all_locations($extension, $dir_rel_path, $themeFirst = false)
|
||||
{
|
||||
if (is_string($extension)) {
|
||||
$extension = fw()->extensions->get($extension);
|
||||
}
|
||||
|
||||
$paths = $extension->get_customizations_locations();
|
||||
$paths[$extension->get_path()] = $extension->get_uri();
|
||||
|
||||
if (!$themeFirst) {
|
||||
$paths = array_reverse($paths);
|
||||
}
|
||||
|
||||
foreach ($paths as $path => $uri) {
|
||||
$files = glob($path . $dir_rel_path .'/*.php');
|
||||
|
||||
if ($files) {
|
||||
foreach ($files as $dir_file_path) {
|
||||
fw_include_file_isolated($dir_file_path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get_locations()
|
||||
{
|
||||
$cache_key = 'fw_extensions_locations';
|
||||
|
||||
try {
|
||||
return FW_Cache::get($cache_key);
|
||||
} catch (FW_Cache_Not_Found_Exception $e) {
|
||||
/**
|
||||
* { '/hello/world/extensions' => 'https://hello.com/world/extensions' }
|
||||
*/
|
||||
$custom_locations = apply_filters('fw_extensions_locations', array());
|
||||
|
||||
{
|
||||
$customizations_locations = array();
|
||||
|
||||
if (is_child_theme()) {
|
||||
$customizations_locations[fw_get_stylesheet_customizations_directory('/extensions')]
|
||||
= fw_get_stylesheet_customizations_directory_uri('/extensions');
|
||||
}
|
||||
|
||||
$customizations_locations[fw_get_template_customizations_directory('/extensions')]
|
||||
= fw_get_template_customizations_directory_uri('/extensions');
|
||||
|
||||
$customizations_locations += $custom_locations;
|
||||
}
|
||||
|
||||
$locations = array();
|
||||
|
||||
$locations[ fw_get_framework_directory('/extensions') ] = array(
|
||||
'path' => fw_get_framework_directory('/extensions'),
|
||||
'uri' => fw_get_framework_directory_uri('/extensions'),
|
||||
'customizations_locations' => $customizations_locations,
|
||||
'is' => array(
|
||||
'framework' => true,
|
||||
'custom' => false,
|
||||
'theme' => false,
|
||||
),
|
||||
);
|
||||
|
||||
foreach ($custom_locations as $path => $uri) {
|
||||
unset($customizations_locations[$path]);
|
||||
$locations[ $path ] = array(
|
||||
'path' => $path,
|
||||
'uri' => $uri,
|
||||
'customizations_locations' => $customizations_locations,
|
||||
'is' => array(
|
||||
'framework' => false,
|
||||
'custom' => true,
|
||||
'theme' => false,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
array_pop($customizations_locations);
|
||||
$locations[ fw_get_template_customizations_directory('/extensions') ] = array(
|
||||
'path' => fw_get_template_customizations_directory('/extensions'),
|
||||
'uri' => fw_get_template_customizations_directory_uri('/extensions'),
|
||||
'customizations_locations' => $customizations_locations,
|
||||
'is' => array(
|
||||
'framework' => false,
|
||||
'custom' => false,
|
||||
'theme' => true,
|
||||
),
|
||||
);
|
||||
|
||||
if (is_child_theme()) {
|
||||
array_pop($customizations_locations);
|
||||
$locations[ fw_get_stylesheet_customizations_directory('/extensions') ] = array(
|
||||
'path' => fw_get_stylesheet_customizations_directory('/extensions'),
|
||||
'uri' => fw_get_stylesheet_customizations_directory_uri('/extensions'),
|
||||
'customizations_locations' => $customizations_locations,
|
||||
'is' => array(
|
||||
'framework' => false,
|
||||
'custom' => false,
|
||||
'theme' => true,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.6.9
|
||||
*/
|
||||
$locations = apply_filters('fw_extensions_locations_after', $locations);
|
||||
|
||||
FW_Cache::set($cache_key, $locations);
|
||||
|
||||
return $locations;
|
||||
}
|
||||
}
|
||||
|
||||
private function load_all_extensions()
|
||||
{
|
||||
foreach ($this->get_locations() as $location) {
|
||||
self::load_extensions(array(
|
||||
'path' => $location['path'],
|
||||
'uri' => $location['uri'],
|
||||
'customizations_locations' => $location['customizations_locations'],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate extensions from given tree point
|
||||
*
|
||||
* @param null|string $parent_extension_name
|
||||
*/
|
||||
private function activate_extensions($parent_extension_name = null)
|
||||
{
|
||||
if ($parent_extension_name === null) {
|
||||
$all_tree = &self::$all_extensions_tree;
|
||||
} else {
|
||||
$all_tree = &self::$extension_to_all_tree[$parent_extension_name];
|
||||
}
|
||||
|
||||
foreach ($all_tree as $extension_name => &$sub_extensions) {
|
||||
if (fw()->extensions->get($extension_name)) {
|
||||
continue; // already active
|
||||
}
|
||||
|
||||
$manifest = self::_get_manifest($extension_name, self::$access_key);
|
||||
|
||||
{
|
||||
$class_file_name = 'class-fw-extension-'. $extension_name .'.php';
|
||||
|
||||
if (fw_include_file_isolated(self::$all_extensions[$extension_name]['path'] .'/'. $class_file_name)) {
|
||||
$class_name = 'FW_Extension_'. fw_dirname_to_classname($extension_name);
|
||||
|
||||
} else {
|
||||
|
||||
$parent_class_name = '';
|
||||
if ( self::$all_extensions[ $extension_name ]['parent'] ) {
|
||||
$parent_class_name = get_class( fw()->extensions->get( self::$all_extensions[ $extension_name ]['parent'] ) );
|
||||
}
|
||||
|
||||
// check if parent extension has been defined custom Default class for its child extensions
|
||||
if ( class_exists( $parent_class_name . '_Default' ) ) {
|
||||
$class_name = $parent_class_name . '_Default';
|
||||
} else {
|
||||
$class_name = 'FW_Extension_Default';
|
||||
}
|
||||
}
|
||||
|
||||
if (!is_subclass_of($class_name, 'FW_Extension')) {
|
||||
trigger_error('Extension "'. $extension_name .'" must extend FW_Extension class', E_USER_ERROR);
|
||||
}
|
||||
|
||||
self::$all_extensions[$extension_name]['instance'] = new $class_name(array(
|
||||
'rel_path' => self::$all_extensions[$extension_name]['rel_path'],
|
||||
'path' => self::$all_extensions[$extension_name]['path'],
|
||||
'uri' => self::$all_extensions[$extension_name]['uri'],
|
||||
'parent' => fw()->extensions->get(self::$all_extensions[$extension_name]['parent']),
|
||||
'depth' => self::$all_extensions[$extension_name]['depth'],
|
||||
'customizations_locations' => self::$all_extensions[$extension_name]['customizations_locations'],
|
||||
));
|
||||
}
|
||||
|
||||
$extension = &self::$all_extensions[$extension_name]['instance'];
|
||||
|
||||
if ($manifest->check_requirements()) {
|
||||
if (!$this->_get_db_active_extensions($extension_name)) {
|
||||
// extension is not set as active
|
||||
} elseif (
|
||||
$extension->get_parent()
|
||||
&&
|
||||
!$extension->get_parent()->_child_extension_is_valid($extension)
|
||||
) {
|
||||
// extension does not pass parent extension rules
|
||||
if (is_admin()) {
|
||||
// show warning only in admin side
|
||||
FW_Flash_Messages::add(
|
||||
'fw-invalid-extension',
|
||||
sprintf(__('Extension %s is invalid.', 'fw'), $extension->get_name()),
|
||||
'warning'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// all requirements met, activate extension
|
||||
$this->activate_extension($extension_name);
|
||||
}
|
||||
} else {
|
||||
// requirements not met, tell required extensions that this extension is waiting for them
|
||||
|
||||
foreach ($manifest->get_required_extensions() as $required_extension_name => $requirements) {
|
||||
if (!isset(self::$extensions_required_by_extensions[$required_extension_name])) {
|
||||
self::$extensions_required_by_extensions[$required_extension_name] = array();
|
||||
}
|
||||
|
||||
self::$extensions_required_by_extensions[$required_extension_name][] = $extension_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($sub_extensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $extension_name
|
||||
* @return bool
|
||||
*/
|
||||
private function activate_extension($extension_name)
|
||||
{
|
||||
if (fw()->extensions->get($extension_name)) {
|
||||
return false; // already active
|
||||
}
|
||||
|
||||
if (!self::_get_manifest($extension_name, self::$access_key)->requirements_met()) {
|
||||
trigger_error('Wrong '. __METHOD__ .' call', E_USER_WARNING);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add to active extensions so inside includes/ and extension it will be accessible from fw()->extensions->get(...)
|
||||
* self::$all_extensions[$extension_name]['instance'] is created in $this->activate_extensions()
|
||||
*/
|
||||
self::$active_extensions[$extension_name] = &self::$all_extensions[$extension_name]['instance'];
|
||||
|
||||
$parent = self::$all_extensions[$extension_name]['instance']->get_parent();
|
||||
|
||||
if ($parent) {
|
||||
self::$extension_to_active_tree[ $parent->get_name() ][$extension_name] = array();
|
||||
self::$extension_to_active_tree[$extension_name] = &self::$extension_to_active_tree[ $parent->get_name() ][$extension_name];
|
||||
} else {
|
||||
self::$active_extensions_tree[$extension_name] = array();
|
||||
self::$extension_to_active_tree[$extension_name] = &self::$active_extensions_tree[$extension_name];
|
||||
}
|
||||
|
||||
self::include_extension_directory_all_locations($extension_name, '/includes');
|
||||
self::include_extension_file_all_locations($extension_name, '/helpers.php');
|
||||
self::include_extension_file_all_locations($extension_name, '/hooks.php');
|
||||
|
||||
if (self::$all_extensions[$extension_name]['instance']->_call_init(self::$access_key) !== false) {
|
||||
$this->activate_extensions($extension_name);
|
||||
}
|
||||
|
||||
// check if other extensions are waiting for this extension and try to activate them
|
||||
if (isset(self::$extensions_required_by_extensions[$extension_name])) {
|
||||
foreach (self::$extensions_required_by_extensions[$extension_name] as $waiting_extension_name) {
|
||||
if (self::_get_manifest($waiting_extension_name, self::$access_key)->check_requirements()) {
|
||||
$waiting_extension = self::$all_extensions[$waiting_extension_name]['instance'];
|
||||
|
||||
if (!$this->_get_db_active_extensions($waiting_extension_name)) {
|
||||
// extension is set as active
|
||||
} elseif (
|
||||
$waiting_extension->get_parent()
|
||||
&&
|
||||
!$waiting_extension->get_parent()->_child_extension_is_valid($waiting_extension)
|
||||
) {
|
||||
// extension does not pass parent extension rules
|
||||
if (is_admin()) {
|
||||
// show warning only in admin side
|
||||
FW_Flash_Messages::add(
|
||||
'fw-invalid-extension',
|
||||
sprintf(__('Extension %s is invalid.', 'fw'), $waiting_extension_name),
|
||||
'warning'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
$this->activate_extension($waiting_extension_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset(self::$extensions_required_by_extensions[$extension_name]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function add_actions()
|
||||
{
|
||||
add_action('init', array($this, '_action_init'));
|
||||
add_action('wp_enqueue_scripts', array($this, '_action_enqueue_scripts'));
|
||||
add_action('admin_enqueue_scripts', array($this, '_action_enqueue_scripts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Give extensions possibility to access their active_tree
|
||||
* @internal
|
||||
*
|
||||
* @param FW_Access_Key $access_key
|
||||
* @param $extension_name
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _get_extension_tree(FW_Access_Key $access_key, $extension_name)
|
||||
{
|
||||
if ($access_key->get_key() !== 'extension') {
|
||||
trigger_error('Call denied', E_USER_ERROR);
|
||||
}
|
||||
|
||||
return self::$extension_to_active_tree[$extension_name];
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _init()
|
||||
{
|
||||
self::$access_key = new FW_Access_Key('fw_extensions');
|
||||
|
||||
/**
|
||||
* Extensions are about to activate.
|
||||
* You can add subclasses to FW_Extension at this point.
|
||||
*/
|
||||
do_action('fw_extensions_before_init');
|
||||
|
||||
$this->load_all_extensions();
|
||||
$this->add_actions();
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _after_components_init()
|
||||
{
|
||||
$this->activate_extensions();
|
||||
|
||||
/**
|
||||
* Extensions are activated
|
||||
* Now $this->get_children() inside extensions is available
|
||||
*/
|
||||
do_action('fw_extensions_init');
|
||||
}
|
||||
|
||||
public function _action_init()
|
||||
{
|
||||
foreach (self::$active_extensions as &$extension) {
|
||||
/** register posts and taxonomies */
|
||||
self::include_extension_file_all_locations($extension, '/posts.php');
|
||||
}
|
||||
}
|
||||
|
||||
public function _action_enqueue_scripts()
|
||||
{
|
||||
foreach (self::$active_extensions as &$extension) {
|
||||
/** js and css */
|
||||
self::include_extension_file_all_locations($extension, '/static.php', true, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $extension_name returned by FW_Extension::get_name()
|
||||
* @return FW_Extension|null
|
||||
*/
|
||||
public function get($extension_name)
|
||||
{
|
||||
if (isset(self::$active_extensions[$extension_name])) {
|
||||
return self::$active_extensions[$extension_name];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all active extensions
|
||||
* @return FW_Extension[]
|
||||
*/
|
||||
public function get_all()
|
||||
{
|
||||
return self::$active_extensions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extensions tree (how they are arranged in directories)
|
||||
* @return array
|
||||
*/
|
||||
public function get_tree()
|
||||
{
|
||||
return self::$active_extensions_tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false
|
||||
* @deprecated Use $extension->locate_path()
|
||||
*/
|
||||
public function locate_path()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return false
|
||||
* @deprecated Use $extension->locate_URI()
|
||||
*/
|
||||
public function locate_path_URI()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* Instances of this class will be created for extensions without class
|
||||
*/
|
||||
class FW_Extension_Default extends FW_Extension
|
||||
{
|
||||
protected function _init()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,351 @@
|
||||
<?php if ( ! defined( 'FW' ) ) {
|
||||
die( 'Forbidden' );
|
||||
}
|
||||
|
||||
$thumbnails_uri = fw_get_framework_directory_uri( '/core/components/extensions/manager/static/img/thumbnails' );
|
||||
$github_account = 'ThemeFuse';
|
||||
|
||||
$extensions = array(
|
||||
'page-builder' => array(
|
||||
'display' => true,
|
||||
'parent' => 'shortcodes',
|
||||
'name' => __( 'Page Builder', 'fw' ),
|
||||
'description' => __( "Let's you easily build countless pages with the help of the drag and drop visual page builder that comes with a lot of already created shortcodes.", 'fw' ),
|
||||
'thumbnail' => $thumbnails_uri . '/page-builder.jpg',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-PageBuilder-Extension'
|
||||
)
|
||||
),
|
||||
),
|
||||
|
||||
'brizy' => array(
|
||||
'display' => true,
|
||||
'parent' => null,
|
||||
'name' => __( 'Brizy - Visual Page Builder', 'fw' ),
|
||||
'description' => __( 'Lets you build pages live on the front end. No designer or developer skills required. The only tools you’ll need to master are clicks and drags.', 'fw' ),
|
||||
'thumbnail' => $thumbnails_uri . '/brizy.jpg',
|
||||
'download' => array(
|
||||
'source' => 'custom',
|
||||
'opts' => array(
|
||||
'plugin' => 'brizy/brizy.php',
|
||||
'remote' => 'https://downloads.wordpress.org/plugin/brizy'
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
'wp-shortcodes' => array(
|
||||
'display' => true,
|
||||
'parent' => 'shortcodes',
|
||||
'name' => __( 'WordPress Shortcodes', 'fw' ),
|
||||
'description' => __(
|
||||
'Lets you insert Unyson shortcodes inside any wp-editor',
|
||||
'fw'
|
||||
),
|
||||
'thumbnail' => $thumbnails_uri . '/wp-shortcodes.jpg',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => 'ThemeFuse/Unyson-WP-Shortcodes-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'backups' => array(
|
||||
'display' => true,
|
||||
'parent' => null,
|
||||
'name' => __( 'Backup & Demo Content', 'fw' ),
|
||||
'description' => __( 'This extension lets you create an automated backup schedule, import demo content or even create a demo content archive for migration purposes.', 'fw' ),
|
||||
'thumbnail' => $thumbnails_uri . '/backups.jpg',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-Backups-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'sidebars' => array(
|
||||
'display' => true,
|
||||
'parent' => null,
|
||||
'name' => __( 'Sidebars', 'fw' ),
|
||||
'description' => __( 'Brings a new layer of customization freedom to your website by letting you add more than one sidebar to a page, or different sidebars on different pages.', 'fw' ),
|
||||
'thumbnail' => $thumbnails_uri . '/sidebars.jpg',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-Sidebars-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'slider' => array(
|
||||
'display' => true,
|
||||
'parent' => 'media',
|
||||
'name' => __( 'Sliders', 'fw' ),
|
||||
'description' => __( 'Adds a sliders module to your website from where you\'ll be able to create different built in jQuery sliders for your homepage and rest of the pages.', 'fw' ),
|
||||
'thumbnail' => $thumbnails_uri . '/sliders.jpg',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-Sliders-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'portfolio' => array(
|
||||
'display' => true,
|
||||
'parent' => null,
|
||||
'name' => __( 'Portfolio', 'fw' ),
|
||||
'description' => __( 'This extension will add a fully fledged portfolio module that will let you display your projects using the built in portfolio pages.', 'fw' ),
|
||||
'thumbnail' => $thumbnails_uri . '/portfolio.jpg',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-Portfolio-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'megamenu' => array(
|
||||
'display' => true,
|
||||
'parent' => null,
|
||||
'name' => __( 'Mega Menu', 'fw' ),
|
||||
'description' => __( 'The Mega Menu extension adds a user-friendly drop down menu that will let you easily create highly customized menu configurations.', 'fw' ),
|
||||
'thumbnail' => $thumbnails_uri . '/mega-menu.jpg',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-MegaMenu-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'breadcrumbs' => array(
|
||||
'display' => true,
|
||||
'parent' => null,
|
||||
'name' => __( 'Breadcrumbs', 'fw' ),
|
||||
'description' => __( 'Creates a simplified navigation menu for the pages that can be placed anywhere in the theme. This will make navigating the website much easier.', 'fw' ),
|
||||
'thumbnail' => $thumbnails_uri . '/breadcrumbs.jpg',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-Breadcrumbs-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'seo' => array(
|
||||
'display' => true,
|
||||
'parent' => null,
|
||||
'name' => __( 'SEO', 'fw' ),
|
||||
'description' => __( 'This extension will enable you to have a fully optimized WordPress website by adding optimized meta titles, keywords and descriptions.', 'fw' ),
|
||||
'thumbnail' => $thumbnails_uri . '/seo.jpg',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-SEO-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'events' => array(
|
||||
'display' => true,
|
||||
'parent' => null,
|
||||
'name' => __( 'Events', 'fw' ),
|
||||
'description' => __( 'This extension adds a fully fledged Events module to your theme. It comes with built in pages that contain a calendar where events can be added.', 'fw' ),
|
||||
'thumbnail' => $thumbnails_uri . '/events.jpg',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-Events-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'analytics' => array(
|
||||
'display' => true,
|
||||
'parent' => null,
|
||||
'name' => __( 'Analytics', 'fw' ),
|
||||
'description' => __( 'Enables the possibility to add the Google Analytics tracking code that will let you get all the analytics about visitors, page views and more.', 'fw' ),
|
||||
'thumbnail' => $thumbnails_uri . '/analytics.jpg',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-Analytics-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'feedback' => array(
|
||||
'display' => true,
|
||||
'parent' => null,
|
||||
'name' => __( 'Feedback', 'fw' ),
|
||||
'description' => __( 'Adds the possibility to leave feedback (comments, reviews and rating) about your products, articles, etc. This replaces the default comments system.', 'fw' ),
|
||||
'thumbnail' => $thumbnails_uri . '/feedback.jpg',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-Feedback-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'learning' => array(
|
||||
'display' => true,
|
||||
'parent' => null,
|
||||
'name' => __( 'Learning', 'fw' ),
|
||||
'description' => __( 'This extension adds a Learning module to your theme. Using this extension you can add courses, lessons and tests for your users to take.', 'fw' ),
|
||||
'thumbnail' => $thumbnails_uri . '/learning.jpg',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-Learning-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'shortcodes' => array(
|
||||
'display' => false,
|
||||
'parent' => null,
|
||||
'name' => __( 'Shortcodes', 'fw' ),
|
||||
'description' => '',
|
||||
'thumbnail' => 'about:blank',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-Shortcodes-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'builder' => array(
|
||||
'display' => false,
|
||||
'parent' => null,
|
||||
'name' => __( 'Builder', 'fw' ),
|
||||
'description' => '',
|
||||
'thumbnail' => 'about:blank',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-Builder-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'forms' => array(
|
||||
'display' => false,
|
||||
'parent' => null,
|
||||
'name' => __( 'Forms', 'fw' ),
|
||||
'description' => __( 'This extension adds the possibility to create a contact form. Use the drag & drop form builder to create any contact form you\'ll ever want or need.', 'fw' ),
|
||||
'thumbnail' => $thumbnails_uri . '/forms.jpg',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-Forms-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'mailer' => array(
|
||||
'display' => false,
|
||||
'parent' => null,
|
||||
'name' => __( 'Mailer', 'fw' ),
|
||||
'description' => __( 'This extension will let you set some global email options and it is used by other extensions (like Forms) to send emails.', 'fw' ),
|
||||
'thumbnail' => $thumbnails_uri . '/mailer.jpg',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-Mailer-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'social' => array(
|
||||
'display' => true,
|
||||
'parent' => null,
|
||||
'name' => __( 'Social', 'fw' ),
|
||||
'description' => __( 'Use this extension to configure all your social related APIs. Other extensions will use the Social extension to connect to your social accounts.', 'fw' ),
|
||||
'thumbnail' => $thumbnails_uri . '/social.jpg',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-Social-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'backup' => array(
|
||||
'display' => true,
|
||||
'parent' => null,
|
||||
'name' => __( 'Backup', 'fw' ),
|
||||
'description' => __( 'This extension lets you set up daily, weekly or monthly backup schedule. You can choose between a full backup or a data base only backup.', 'fw' ),
|
||||
'thumbnail' => $thumbnails_uri . '/backup.jpg',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-Backup-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'media' => array(
|
||||
'display' => false,
|
||||
'parent' => null,
|
||||
'name' => __( 'Media', 'fw' ),
|
||||
'description' => '',
|
||||
'thumbnail' => 'about:blank',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-Empty-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'population-method' => array(
|
||||
'display' => false,
|
||||
'parent' => 'media',
|
||||
'name' => __( 'Population method', 'fw' ),
|
||||
'description' => '',
|
||||
'thumbnail' => 'about:blank',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-PopulationMethods-Extension',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'translatepress-multilingual' => array(
|
||||
'display' => true,
|
||||
'parent' => null,
|
||||
'name' => __( 'Translate Press', 'fw' ),
|
||||
'description' => __( 'This extension lets you translate your website in any language or even add multiple languages for your users to change at their will from the front-end.', 'fw' ),
|
||||
'thumbnail' => $thumbnails_uri . '/translation.jpg',
|
||||
'download' => array(
|
||||
'source' => 'custom',
|
||||
'url_set' => 'options-general.php?page=translate-press',
|
||||
'opts' => array(
|
||||
'plugin' => 'translatepress-multilingual/index.php',
|
||||
'remote' => 'https://downloads.wordpress.org/plugin/translatepress-multilingual'
|
||||
)
|
||||
)
|
||||
),
|
||||
|
||||
'styling' => array(
|
||||
'display' => true,
|
||||
'parent' => null,
|
||||
'name' => __( 'Styling', 'fw' ),
|
||||
'description' => __( 'This extension lets you control the website visual style. Starting from predefined styles to changing specific fonts and colors across the website.', 'fw' ),
|
||||
'thumbnail' => $thumbnails_uri . '/styling.jpg',
|
||||
'download' => array(
|
||||
'source' => 'github',
|
||||
'opts' => array(
|
||||
'user_repo' => $github_account . '/Unyson-Styling-Extension',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
class _FW_Available_Extensions_Register extends FW_Type_Register {
|
||||
protected function validate_type( FW_Type $type ) {
|
||||
return $type instanceof FW_Available_Extension;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* Used to define extension in framework Available Extensions list
|
||||
* @since 2.5.12
|
||||
*/
|
||||
class FW_Available_Extension extends FW_Type {
|
||||
/**
|
||||
* Extension (directory) name
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var null|string Parent extension name
|
||||
*/
|
||||
private $parent = null;
|
||||
|
||||
/**
|
||||
* @var bool If visible in extensions list
|
||||
*/
|
||||
private $display = true;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* @var string Image url
|
||||
*/
|
||||
private $thumbnail = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQIW2PUsHf9DwAC8AGtfm5YCAAAAABJRU5ErkJgggAA';
|
||||
|
||||
/**
|
||||
* @var array {source: id, opts: {...}}
|
||||
* @see FW_Ext_Download_Source::get_type() is id
|
||||
* @see FW_Ext_Download_Source
|
||||
*/
|
||||
private $download_source = array();
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @since 2.6.0
|
||||
*/
|
||||
public function is_valid() {
|
||||
return (
|
||||
!empty($this->name) && is_string($this->name)
|
||||
&&
|
||||
!empty($this->title) && is_string($this->title)
|
||||
&&
|
||||
!empty($this->description) && is_string($this->description)
|
||||
&&
|
||||
!empty($this->download_source)
|
||||
&&
|
||||
is_bool($this->display)
|
||||
&&
|
||||
(is_null($this->parent) || is_string($this->parent))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @internal
|
||||
*/
|
||||
final public function get_type() {
|
||||
return $this->get_name();
|
||||
}
|
||||
|
||||
public function get_name() {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function set_name($name) {
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function get_parent() {
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
public function set_parent($parent) {
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
public function get_display() {
|
||||
return $this->display;
|
||||
}
|
||||
|
||||
public function set_display($display) {
|
||||
$this->display = $display;
|
||||
}
|
||||
|
||||
public function get_title() {
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function set_title($title) {
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
public function get_description() {
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function set_description($description) {
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
public function get_thumbnail() {
|
||||
return $this->thumbnail;
|
||||
}
|
||||
|
||||
public function set_thumbnail($thumbnail) {
|
||||
$this->thumbnail = $thumbnail;
|
||||
}
|
||||
|
||||
public function get_download_source() {
|
||||
return $this->download_source;
|
||||
}
|
||||
|
||||
public function set_download_source($id, $data) {
|
||||
$this->download_source = array(
|
||||
'source' => $id,
|
||||
'opts' => $data
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
||||
|
||||
class _FW_Extensions_Delete_Upgrader_Skin extends WP_Upgrader_Skin
|
||||
{
|
||||
public function after($data = array())
|
||||
{
|
||||
$update_actions = array(
|
||||
'extensions_page' => fw_html_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => fw_akg('extensions_page_link', $data, '#'),
|
||||
'title' => __('Go to extensions page', 'fw'),
|
||||
'target' => '_parent',
|
||||
),
|
||||
__('Return to Extensions page', 'fw')
|
||||
)
|
||||
);
|
||||
|
||||
$this->feedback(implode(' | ', (array)$update_actions));
|
||||
|
||||
if ($this->result) {
|
||||
// used for popup ajax form submit result
|
||||
$this->feedback('<span success></span>');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
||||
|
||||
class _FW_Extensions_Install_Upgrader_Skin extends WP_Upgrader_Skin
|
||||
{
|
||||
public function after($data = array())
|
||||
{
|
||||
$update_actions = array(
|
||||
'extensions_page' => fw_html_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => fw_akg('extensions_page_link', $data, '#'),
|
||||
'title' => __('Go to extensions page', 'fw'),
|
||||
'target' => '_parent',
|
||||
),
|
||||
__('Return to Extensions page', 'fw')
|
||||
)
|
||||
);
|
||||
|
||||
$this->feedback(implode(' | ', (array)$update_actions));
|
||||
|
||||
if ($this->result) {
|
||||
// used for popup ajax form submit result
|
||||
$this->feedback('<span success></span>');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php if (! defined('FW')) { die('Forbidden'); }
|
||||
|
||||
class _FW_Ext_Download_Source_Register extends FW_Type_Register
|
||||
{
|
||||
protected function validate_type( FW_Type $type ) {
|
||||
return $type instanceof FW_Ext_Download_Source;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php if (! defined('FW')) { die('Forbidden'); }
|
||||
|
||||
/**
|
||||
* User to specify multiple download sources for an extension.
|
||||
* @since 2.5.12
|
||||
*/
|
||||
abstract class FW_Ext_Download_Source extends FW_Type
|
||||
{
|
||||
/**
|
||||
* Perform the actual download.
|
||||
* It should download, by convention, a zip file which absolute path
|
||||
* is $path.
|
||||
*
|
||||
* @param array $set {extension_name: '...', extension_title: '...', ...}
|
||||
* @param string $zip_path Absolute file of the future ZIP file
|
||||
*
|
||||
* @return null|WP_Error
|
||||
*/
|
||||
abstract public function download(array $set, $zip_path);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php if ( ! defined( 'FW' ) ) {
|
||||
die( 'Forbidden' );
|
||||
}
|
||||
|
||||
class FW_Ext_Download_Source_Bitbucket extends FW_Ext_Download_Source {
|
||||
private $download_timeout = 300;
|
||||
|
||||
public function get_type() {
|
||||
return 'bitbucket';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $set {user_repo: 'ThemeFuse/Unyson'}
|
||||
* @param string $zip_path
|
||||
*
|
||||
* @return WP_Error|boolean
|
||||
*/
|
||||
public function download( array $set, $zip_path ) {
|
||||
$wp_error_id = 'fw_ext_bitbucket_download_source';
|
||||
$theme_ext_requirements = fw()->theme->manifest->get( 'requirements/extensions' );
|
||||
|
||||
/** @var WP_Filesystem_Base $wp_filesystem */
|
||||
global $wp_filesystem;
|
||||
|
||||
$extension_name = $set['extension_name'];
|
||||
$extension_title = $set['extension_title'];
|
||||
|
||||
if ( empty( $set['user_repo'] ) ) {
|
||||
return new WP_Error(
|
||||
$wp_error_id,
|
||||
sprintf( __( '"%s" extension bitbucket source "user_repo" parameter is required', 'fw' ), $extension_title )
|
||||
);
|
||||
}
|
||||
|
||||
if ( isset( $theme_ext_requirements[ $extension_name ] ) && isset( $theme_ext_requirements[ $extension_name ]['max_version'] ) ) {
|
||||
$tag = $theme_ext_requirements[ $extension_name ]['max_version'];
|
||||
} else {
|
||||
$tag = $this->get_version( $set['user_repo'] );
|
||||
}
|
||||
|
||||
$response = wp_remote_get( "https://bitbucket.org/{$set['user_repo']}/get/{$tag}.zip", array( 'timeout' => $this->download_timeout ) );
|
||||
|
||||
if ( ( $response_code = intval( wp_remote_retrieve_response_code( $response ) ) ) !== 200 ) {
|
||||
if ( $response_code ) {
|
||||
return new WP_Error(
|
||||
$wp_error_id,
|
||||
sprintf( __( 'Cannot download the "%s" extension zip. (Response code: %d)', 'fw' ),
|
||||
$extension_title, $response_code
|
||||
)
|
||||
);
|
||||
} elseif ( is_wp_error( $response ) ) {
|
||||
return new WP_Error(
|
||||
$wp_error_id,
|
||||
sprintf( __( 'Cannot download the "%s" extension zip. %s', 'fw' ),
|
||||
$extension_title,
|
||||
$response->get_error_message()
|
||||
)
|
||||
);
|
||||
} else {
|
||||
return new WP_Error(
|
||||
$wp_error_id,
|
||||
sprintf( __( 'Cannot download the "%s" extension zip.', 'fw' ),
|
||||
$extension_title
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// save zip to file
|
||||
if ( ! $wp_filesystem->put_contents( $zip_path, $response['body'] ) ) {
|
||||
return new WP_Error(
|
||||
$wp_error_id,
|
||||
sprintf( __( 'Cannot save the "%s" extension zip.', 'fw' ), $extension_title )
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function get_version( $user_repo, $next_page = '' ) {
|
||||
/**
|
||||
* If at least one request failed, do not do any other requests, to prevent site being blocked on every refresh.
|
||||
* This may happen on localhost when develop your theme and you have no internet connection.
|
||||
* Then this method will return a fake '0.0.0' version, it will be cached by the transient
|
||||
* and will not bother you until the transient will expire, then a new request will be made.
|
||||
* @var bool
|
||||
*/
|
||||
static $no_internet_connection = false;
|
||||
|
||||
if ( $no_internet_connection ) {
|
||||
return '0.0.0';
|
||||
}
|
||||
|
||||
$url = $next_page ? $next_page : "https://api.bitbucket.org/2.0/repositories/{$user_repo}/refs/tags/";
|
||||
$request = wp_remote_get( $url, array( 'timeout' => $this->download_timeout ) );
|
||||
|
||||
if ( is_wp_error( $request ) ) {
|
||||
if ( $request->get_error_code() === 'http_request_failed' ) {
|
||||
$no_internet_connection = true;
|
||||
}
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
if ( ! ( $versions = json_decode( wp_remote_retrieve_body( $request ), true ) ) || is_wp_error( $versions ) ) {
|
||||
return ! $versions ? new WP_Error( sprintf( __( 'Empty version for item: %s', 'fw' ), $user_repo ) ) : $versions;
|
||||
}
|
||||
|
||||
if ( isset( $versions['next'] ) ) {
|
||||
return $this->get_version( $user_repo, $versions['next'] );
|
||||
}
|
||||
|
||||
$data_version = end( $versions['values'] );
|
||||
|
||||
return ! empty( $data_version['name'] ) ? $data_version['name'] : new WP_Error( sprintf( __( 'Wrong Bibucket version for item: %s', 'fw' ), $user_repo ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
<?php defined( 'FW' ) or die();
|
||||
|
||||
class FW_Ext_Download_Source_Custom extends FW_Ext_Download_Source {
|
||||
private $download_timeout = 300;
|
||||
// Used in filter http_request_args when extension is as plugin we use api worpdress Plugin_Upgrader.
|
||||
private $set = array();
|
||||
|
||||
public function get_type() {
|
||||
return 'custom';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $set
|
||||
* @param string $zip_path
|
||||
*
|
||||
* @return WP_Error|bool
|
||||
*/
|
||||
public function download( array $set, $zip_path ) {
|
||||
/** @var WP_Filesystem_Base $wp_filesystem */
|
||||
global $wp_filesystem;
|
||||
|
||||
$wp_error_id = 'fw_ext_custom_download_source';
|
||||
$transient_name = 'fw_ext_mngr_gh_dl';
|
||||
$requirements = fw()->theme->manifest->get( 'requirements/extensions' );
|
||||
$set['type'] = 'extension';
|
||||
|
||||
if ( isset( $requirements[ $set['extension_name'] ] ) && isset( $requirements[ $set['extension_name'] ]['max_version'] ) ) {
|
||||
$set['tag'] = $requirements[ $set['extension_name'] ]['max_version'];
|
||||
} else {
|
||||
$set['tag'] = $this->get_version( $set );
|
||||
|
||||
if ( is_wp_error( $set['tag'] ) ) {
|
||||
return $set['tag'];
|
||||
}
|
||||
}
|
||||
|
||||
$cache = ( $c = get_site_transient( $transient_name ) ) && $c !== false ? $c : array();
|
||||
$cache[ $set['item'] ] = array( 'tag_name' => $set['tag'] );
|
||||
set_site_transient( $transient_name, $cache, HOUR_IN_SECONDS );
|
||||
|
||||
if ( $set['plugin'] ) {
|
||||
return $this->install_plugin( $set, $set['remote'] );
|
||||
}
|
||||
|
||||
$request = wp_remote_post(
|
||||
$set['remote'],
|
||||
array(
|
||||
'timeout' => $this->download_timeout,
|
||||
'body' => json_encode( array_merge( $set, array( 'pull' => 'zip' ) ) )
|
||||
)
|
||||
);
|
||||
|
||||
if ( is_wp_error( $request ) ) {
|
||||
return $request;
|
||||
}
|
||||
|
||||
if ( ! ( $body = wp_remote_retrieve_body( $request ) ) || is_wp_error( $body ) ) {
|
||||
return ! $body ? new WP_Error( $wp_error_id, sprintf( esc_html__( 'Empty zip body for extension: %s', 'fw' ), $set['extension_title'] ) ) : $body;
|
||||
}
|
||||
|
||||
// Try to extract error if server returned json with key error, if not then is an archive zip.
|
||||
if ( ( $error = json_decode( $body, true ) ) && isset( $error['error'] ) ) {
|
||||
return new WP_Error( $wp_error_id, $error['error'] );
|
||||
}
|
||||
|
||||
// save zip to file
|
||||
if ( ! $wp_filesystem->put_contents( $zip_path, $body ) ) {
|
||||
return new WP_Error( $wp_error_id, sprintf( __( 'Cannot save the "%s" extension zip.', 'fw' ), $set['name'] ) );
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function get_version( $set ) {
|
||||
|
||||
if ( $this->is_wp_org( $set['remote'] ) ) {
|
||||
|
||||
include ABSPATH . 'wp-admin/includes/plugin-install.php';
|
||||
|
||||
$wp_org = plugins_api(
|
||||
'plugin_information',
|
||||
array(
|
||||
'slug' => $set['extension_name'],
|
||||
'fields' => array(
|
||||
'downloaded' => false,
|
||||
'versions' => false,
|
||||
'reviews' => false,
|
||||
'banners' => false,
|
||||
'icons' => false,
|
||||
'rating' => false,
|
||||
'active_installs' => false,
|
||||
'group' => false,
|
||||
'contributors' => false,
|
||||
'description' => false,
|
||||
'short_description' => false,
|
||||
'donate_link' => false,
|
||||
'tags' => false,
|
||||
'sections' => false,
|
||||
'homepage' => false,
|
||||
'added' => false,
|
||||
'last_updated' => false,
|
||||
'compatibility' => false,
|
||||
'tested' => false,
|
||||
'requires' => false,
|
||||
'downloadlink' => true,
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
if ( is_wp_error( $wp_org ) ) {
|
||||
return new WP_Error( sprintf( __( 'Cannot get latest versions for extension: %s', 'fw' ), $set['extension_title'] ) );
|
||||
}
|
||||
|
||||
return $wp_org->version;
|
||||
}
|
||||
|
||||
$request = wp_remote_post(
|
||||
$set['remote'],
|
||||
array(
|
||||
'timeout' => $this->download_timeout,
|
||||
'body' => json_encode( array_merge( $set, array( 'pull' => 'version' ) ) )
|
||||
)
|
||||
);
|
||||
|
||||
if ( is_wp_error( $request ) ) {
|
||||
return $request;
|
||||
}
|
||||
|
||||
if ( ! ( $version = wp_remote_retrieve_body( $request ) ) || is_wp_error( $version ) ) {
|
||||
return ! $version ? new WP_Error( sprintf( esc_html__( 'Empty version for extension: %s', 'fw' ), $set['extension_title'] ) ) : $version;
|
||||
}
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
public function install_plugin( $set, $source ) {
|
||||
|
||||
if ( ! function_exists( 'is_plugin_active' ) ) {
|
||||
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
|
||||
}
|
||||
|
||||
if ( is_plugin_active( $set['plugin'] ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ( ! ( $installed = get_plugins() ) || ! isset( $installed[ $set['plugin'] ] ) ) {
|
||||
if ( ! class_exists( 'Plugin_Upgrader', false ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
||||
}
|
||||
|
||||
if ( $this->is_wp_org( $set['remote'] ) ) {
|
||||
$source = esc_url( "{$source}.{$set['tag']}.zip" );
|
||||
}
|
||||
|
||||
$upgrader = new Plugin_Upgrader( new Automatic_Upgrader_Skin() );
|
||||
// To easy access download settings in function http_request_args.
|
||||
$this->set = $set;
|
||||
add_filter( 'http_request_args', array( $this, 'http_request_args' ) );
|
||||
|
||||
$install = $upgrader->install( $source );
|
||||
|
||||
remove_filter( 'http_request_args', array( $this, 'http_request_args' ) );
|
||||
|
||||
if ( ! $install || is_wp_error( $install ) ) {
|
||||
return new WP_Error( sprintf( __( 'Cannot install plugin: %s', 'fw' ), $set['extension_title'] ) );
|
||||
}
|
||||
|
||||
if ( ! ( $installed = get_plugins() ) || ! isset( $installed[ $set['plugin'] ] ) ) {
|
||||
return new WP_Error( sprintf( __( 'Cannot find plugin: %s', 'fw' ), $set['extension_title'] ) );
|
||||
}
|
||||
|
||||
$cache_plugins = ( $c = wp_cache_get( 'plugins', 'plugins' ) ) && ! empty( $c ) ? $c : array();
|
||||
$cache_plugins[''][ $set['plugin'] ] = $installed[ $set['plugin'] ];
|
||||
wp_cache_set( 'plugins', $cache_plugins, 'plugins' );
|
||||
}
|
||||
|
||||
// A small financial support for maintaining the plugin.
|
||||
if ( 'translatepress-multilingual/index.php' === $set['plugin'] ) {
|
||||
update_option( 'translatepress_affiliate_id', 1 );
|
||||
}
|
||||
|
||||
return activate_plugin( $set['plugin'] );
|
||||
}
|
||||
|
||||
public function http_request_args( $r ) {
|
||||
$r['fw_set'] = json_encode( array_merge( $this->set, array( 'type' => 'extension' ) ) );
|
||||
return $r;
|
||||
}
|
||||
|
||||
public function is_wp_org( $url ) {
|
||||
return strpos( $url, 'downloads.wordpress.org' ) !== false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
<?php if ( ! defined( 'FW' ) ) {
|
||||
die( 'Forbidden' );
|
||||
}
|
||||
|
||||
class FW_Ext_Download_Source_Github extends FW_Ext_Download_Source {
|
||||
private $download_timeout = 300;
|
||||
|
||||
public function get_type() {
|
||||
return 'github';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $set {user_repo: 'ThemeFuse/Unyson'}
|
||||
* @param string $zip_path
|
||||
*
|
||||
* @return WP_Error
|
||||
*/
|
||||
public function download( array $set, $zip_path ) {
|
||||
$wp_error_id = 'fw_ext_github_download_source';
|
||||
$theme_ext_requirements = fw()->theme->manifest->get( 'requirements/extensions' );
|
||||
|
||||
/** @var WP_Filesystem_Base $wp_filesystem */
|
||||
global $wp_filesystem;
|
||||
|
||||
$extension_name = $set['extension_name'];
|
||||
$extension_title = $set['extension_title'];
|
||||
|
||||
if ( empty( $set['user_repo'] ) ) {
|
||||
return new WP_Error(
|
||||
$wp_error_id,
|
||||
sprintf( __( '"%s" extension github source "user_repo" parameter is required', 'fw' ), $extension_title )
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
$transient_name = 'fw_ext_mngr_gh_dl';
|
||||
$transient_ttl = HOUR_IN_SECONDS;
|
||||
|
||||
$cache = get_site_transient( $transient_name );
|
||||
|
||||
if ( $cache === false ) {
|
||||
$cache = array();
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $cache[ $set['user_repo'] ] ) ) {
|
||||
$download_link = $cache[ $set['user_repo'] ]['zipball_url'];
|
||||
} else {
|
||||
$http = new WP_Http();
|
||||
|
||||
if (
|
||||
isset( $theme_ext_requirements[ $extension_name ] )
|
||||
&&
|
||||
isset( $theme_ext_requirements[ $extension_name ]['max_version'] )
|
||||
) {
|
||||
$tag = 'tags/v' . $theme_ext_requirements[ $extension_name ]['max_version'];
|
||||
} else {
|
||||
$tag = 'latest';
|
||||
}
|
||||
|
||||
$response = $http->get(
|
||||
apply_filters( 'fw_github_api_url', 'https://api.github.com' )
|
||||
. '/repos/' . $set['user_repo'] . '/releases/' . $tag
|
||||
);
|
||||
|
||||
unset( $http );
|
||||
|
||||
$response_code = intval( wp_remote_retrieve_response_code( $response ) );
|
||||
|
||||
if ( $response_code !== 200 ) {
|
||||
if ( $response_code === 403 ) {
|
||||
if ( $json_response = json_decode( $response['body'], true ) ) {
|
||||
return new WP_Error(
|
||||
$wp_error_id,
|
||||
__( 'Github error:', 'fw' ) . ' ' . $json_response['message']
|
||||
);
|
||||
} else {
|
||||
return new WP_Error(
|
||||
$wp_error_id,
|
||||
sprintf(
|
||||
__( 'Failed to access Github repository "%s" releases. (Response code: %d)', 'fw' ),
|
||||
$set['user_repo'], $response_code
|
||||
)
|
||||
);
|
||||
}
|
||||
} elseif ( $response_code ) {
|
||||
return new WP_Error(
|
||||
$wp_error_id,
|
||||
sprintf(
|
||||
__( 'Failed to access Github repository "%s" releases. (Response code: %d)', 'fw' ),
|
||||
$set['user_repo'], $response_code
|
||||
)
|
||||
);
|
||||
} elseif ( is_wp_error( $response ) ) {
|
||||
return new WP_Error(
|
||||
$wp_error_id,
|
||||
sprintf(
|
||||
__( 'Failed to access Github repository "%s" releases. (%s)', 'fw' ),
|
||||
$set['user_repo'], $response->get_error_message()
|
||||
)
|
||||
);
|
||||
} else {
|
||||
return new WP_Error(
|
||||
$wp_error_id,
|
||||
sprintf(
|
||||
__( 'Failed to access Github repository "%s" releases.', 'fw' ),
|
||||
$set['user_repo']
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$release = json_decode( $response['body'], true );
|
||||
|
||||
unset( $response );
|
||||
|
||||
if ( empty( $release ) ) {
|
||||
return new WP_Error(
|
||||
$wp_error_id,
|
||||
sprintf(
|
||||
__( '"%s" extension github repository "%s" has no releases.', 'fw' ),
|
||||
$extension_title, $set['user_repo']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
$cache[ $set['user_repo'] ] = array(
|
||||
'zipball_url' => 'https://github.com/' . $set['user_repo'] . '/archive/' . $release['tag_name'] . '.zip',
|
||||
'tag_name' => $release['tag_name']
|
||||
);
|
||||
|
||||
set_site_transient( $transient_name, $cache, $transient_ttl );
|
||||
}
|
||||
|
||||
$download_link = $cache[ $set['user_repo'] ]['zipball_url'];
|
||||
|
||||
|
||||
unset( $release );
|
||||
}
|
||||
|
||||
{
|
||||
$http = new WP_Http();
|
||||
|
||||
$response = $http->request( $download_link, array(
|
||||
'timeout' => $this->download_timeout,
|
||||
) );
|
||||
|
||||
unset( $http );
|
||||
|
||||
if ( ( $response_code = intval( wp_remote_retrieve_response_code( $response ) ) ) !== 200 ) {
|
||||
if ( $response_code ) {
|
||||
return new WP_Error(
|
||||
$wp_error_id,
|
||||
sprintf( __( 'Cannot download the "%s" extension zip. (Response code: %d)', 'fw' ),
|
||||
$extension_title, $response_code
|
||||
)
|
||||
);
|
||||
} elseif ( is_wp_error( $response ) ) {
|
||||
return new WP_Error(
|
||||
$wp_error_id,
|
||||
sprintf( __( 'Cannot download the "%s" extension zip. %s', 'fw' ),
|
||||
$extension_title,
|
||||
$response->get_error_message()
|
||||
)
|
||||
);
|
||||
} else {
|
||||
return new WP_Error(
|
||||
$wp_error_id,
|
||||
sprintf( __( 'Cannot download the "%s" extension zip.', 'fw' ),
|
||||
$extension_title
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// save zip to file
|
||||
if ( ! $wp_filesystem->put_contents( $zip_path, $response['body'] ) ) {
|
||||
return new WP_Error(
|
||||
$wp_error_id,
|
||||
sprintf( __( 'Cannot save the "%s" extension zip.', 'fw' ), $extension_title )
|
||||
);
|
||||
}
|
||||
|
||||
unset( $response );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php defined( 'FW' ) or die();
|
||||
|
||||
if ( ! function_exists( '_action_fw_register_ext_download_sources' ) ) {
|
||||
function _action_fw_register_ext_download_sources( _FW_Ext_Download_Source_Register $download_sources ) {
|
||||
$download_sources->register( new FW_Ext_Download_Source_Github() );
|
||||
$download_sources->register( new FW_Ext_Download_Source_Bitbucket() );
|
||||
$download_sources->register( new FW_Ext_Download_Source_Custom() );
|
||||
}
|
||||
}
|
||||
|
||||
add_action( 'fw_register_ext_download_sources', '_action_fw_register_ext_download_sources' );
|
||||
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Emanuil Rusev, erusev.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -0,0 +1,23 @@
|
||||
#fw-extension-page .fw-extension-page-title {
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
#fw-extension-page .fw-extension-page-title .button,
|
||||
#fw-extension-page .fw-extension-page-title .button-primary,
|
||||
#fw-extension-page .fw-extension-page-title .button-primary:active {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
#fw-extension-page .fw-flash-message + br {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
#fw-extension-docs.fw-postbox > .insider {
|
||||
margin-top: 0 !important;
|
||||
}
|
||||
|
||||
#fw-extension-docs hr {
|
||||
margin-left: -27px;
|
||||
margin-right: -27px;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
jQuery(function($){
|
||||
$('#fw-extension-docs a:fw-external').attr('target', '_blank');
|
||||
});
|
||||
@@ -0,0 +1,261 @@
|
||||
.fw-extensions-list a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.fw-extensions-no-active {
|
||||
margin: 75px 0;
|
||||
}
|
||||
|
||||
.fw-extensions-no-active .fw-text-muted {
|
||||
color: #9d9d9d;
|
||||
}
|
||||
|
||||
.fw-extensions-no-active .fw-extensions-title-icon .dashicons {
|
||||
color: #d3d3d3;
|
||||
font-size: 46px;
|
||||
width: auto;
|
||||
height: auto;
|
||||
line-height: 35px;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item {
|
||||
padding: 0 15px 15px 0;
|
||||
vertical-align: top;
|
||||
display: inline-block;
|
||||
float: none;
|
||||
margin: 0 -1px;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item > .inner {
|
||||
padding: 20px;
|
||||
background-color: #ffffff;
|
||||
border: 1px solid #dedede;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item > .inner > p:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extensions-list-item-thumbnail-wrapper {
|
||||
height: 128px;
|
||||
width: 128px;
|
||||
text-align: center;
|
||||
background: url('img/thumbnail-bg.jpg');
|
||||
background-size: 128px;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extensions-list-item-thumbnail-wrapper img.fw-extensions-list-item-thumbnail {
|
||||
display: block;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extensions-list-item-thumbnail-wrapper span.fw-extensions-list-item-thumbnail {
|
||||
display: inline;
|
||||
vertical-align: middle;
|
||||
color: #fff;
|
||||
line-height: 128px;
|
||||
font-size: 42px;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extensions-list-item-thumbnail-wrapper span.fw-extensions-list-item-thumbnail.dashicons {
|
||||
font-size: 48px;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extensions-list-item-title {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extensions-list-item-title:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table {
|
||||
display: table;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table > .fw-extension-list-item-table-row {
|
||||
display: table-row;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table > .fw-extension-list-item-table-row > .fw-extension-list-item-table-cell {
|
||||
display: table-cell;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
/*.fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table > .fw-extension-list-item-table-row > .fw-extension-list-item-table-cell.cell-2,
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table > .fw-extension-list-item-table-row > .fw-extension-list-item-table-cell.cell-3 {
|
||||
vertical-align: middle;
|
||||
}*/
|
||||
|
||||
@media (max-width: 782px) {
|
||||
.fw-extensions-list .fw-extensions-list-item {
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-text-center {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
body.rtl .fw-extensions-list .fw-extensions-list-item .fw-text-center {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extensions-list-item-title {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table,
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table > .fw-extension-list-item-table-row,
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table > .fw-extension-list-item-table-row > .fw-extension-list-item-table-cell {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table > .fw-extension-list-item-table-row > .fw-extension-list-item-table-cell.cell-3 form,
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table > .fw-extension-list-item-table-row > .fw-extension-list-item-table-cell.cell-3 form .button {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 783px) {
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extensions-list-item-title {
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
hr.fw-extensions-lists-separator {
|
||||
margin: 22px 0 30px;
|
||||
margin-right: 15px; /* same as .fw-extensions-list .fw-extensions-list-item padding-right */
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table > .fw-extension-list-item-table-row > .fw-extension-list-item-table-cell:first-child,
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table > .fw-extension-list-item-table-row > .fw-extension-list-item-table-cell:last-child {
|
||||
width: 10px;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table > .fw-extension-list-item-table-row > .fw-extension-list-item-table-cell:not(:first-child):not(:last-child) {
|
||||
padding-left: 20px;
|
||||
}
|
||||
body.rtl .fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table > .fw-extension-list-item-table-row > .fw-extension-list-item-table-cell:not(:first-child):not(:last-child) {
|
||||
padding-left: 0;
|
||||
padding-right: 20px;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table > .fw-extension-list-item-table-row > .fw-extension-list-item-table-cell > p:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table > .fw-extension-list-item-table-row > .fw-extension-list-item-table-cell.cell-3 {
|
||||
display: block;
|
||||
position: absolute;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
width: auto;
|
||||
}
|
||||
body.rtl .fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table > .fw-extension-list-item-table-row > .fw-extension-list-item-table-cell.cell-3 {
|
||||
right: auto;
|
||||
left: 20px;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table > .fw-extension-list-item-table-row > .fw-extension-list-item-table-cell.cell-3 form {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table > .fw-extension-list-item-table-row > .fw-extension-list-item-table-cell.cell-3 form.extension-delete-form {
|
||||
padding: 0 0 4px 15px;
|
||||
vertical-align: bottom;
|
||||
}
|
||||
body.rtl .fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table > .fw-extension-list-item-table-row > .fw-extension-list-item-table-cell.cell-3 form.extension-delete-form {
|
||||
padding: 0 13px 4px 0;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extension-list-item-table > .fw-extension-list-item-table-row > .fw-extension-list-item-table-cell.cell-3 form.extension-delete-form .btn-icon {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* disabled style */
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extension-disabled {
|
||||
display: none;
|
||||
background: rgba(255, 255, 255, 0.5) url("img/disabled-bg.png");
|
||||
border: 1px solid #ffffff;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item.disabled .fw-extension-disabled {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .fw-extension-disabled .fw-extension-disabled-panel {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
background: #ffffff;
|
||||
padding: 20px;
|
||||
line-height: 28px;
|
||||
}
|
||||
|
||||
@media (max-width: 782px) {
|
||||
.fw-extensions-list .fw-extensions-list-item.disabled > .inner {
|
||||
min-height: 320px;
|
||||
}
|
||||
}
|
||||
|
||||
/* end: disabled style */
|
||||
|
||||
|
||||
/* tip content */
|
||||
|
||||
.fw-extension-tip-content {
|
||||
padding: 15px;
|
||||
max-width: 380px;
|
||||
}
|
||||
|
||||
.fw-extension-tip-content ul.fw-extension-requirements {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.fw-extension-tip-content ul.fw-extension-requirements li:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
/* end: tip content */
|
||||
|
||||
|
||||
/* form ajax loading */
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .ajax-form-loading {
|
||||
display: inline-block;
|
||||
margin: -2px 0;
|
||||
padding-left: 7px;
|
||||
}
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item .ajax-form-loading img {
|
||||
vertical-align: middle;
|
||||
display: inline-block;
|
||||
margin-top: -2px;
|
||||
}
|
||||
|
||||
/* end: form ajax loading */
|
||||
|
||||
|
||||
/* anchor */
|
||||
|
||||
.fw-extensions-list .fw-extensions-list-item a.fw-ext-anchor {
|
||||
position: absolute;
|
||||
top: -15px;
|
||||
}
|
||||
|
||||
body.admin-bar .fw-extensions-list .fw-extensions-list-item a.fw-ext-anchor {
|
||||
top: -50px;
|
||||
}
|
||||
|
||||
/* end: anchor */
|
||||
@@ -0,0 +1,108 @@
|
||||
jQuery(function ($) {
|
||||
fw.qtip( $('.fw-extensions-list .fw-extensions-list-item .fw-extension-tip') );
|
||||
});
|
||||
|
||||
/**
|
||||
* Install/Remove/... via popup if has direct filesystem access (no ftp credentials required)
|
||||
*/
|
||||
jQuery(function($){
|
||||
var inst = {
|
||||
isBusy: false,
|
||||
eventNamespace: '.fw-extension',
|
||||
$wrapper: $('.wrap'),
|
||||
listenSubmit: function() {
|
||||
this.$wrapper.on('submit'+ this.eventNamespace, 'form.fw-extension-ajax-form', this.onSubmit);
|
||||
},
|
||||
stopListeningSubmit: function() {
|
||||
this.$wrapper.off('submit'+ this.eventNamespace, 'form.fw-extension-ajax-form');
|
||||
},
|
||||
onSubmit: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (inst.isBusy) {
|
||||
alert('Working... Please try again later');
|
||||
return;
|
||||
}
|
||||
|
||||
var $form = $(this);
|
||||
|
||||
var confirmMessage = $form.attr('data-confirm-message');
|
||||
|
||||
inst.isBusy = true;
|
||||
inst.loading($form, true);
|
||||
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'fw_extensions_check_direct_fs_access'
|
||||
},
|
||||
dataType: 'json'
|
||||
}).done(function(data){
|
||||
if (data.success) {
|
||||
if (confirmMessage) {
|
||||
if (!confirm(confirmMessage)) {
|
||||
inst.isBusy = false;
|
||||
inst.loading($form, false);
|
||||
}
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'fw_extensions_'+ $form.attr('data-extension-action'),
|
||||
extension: $form.attr('data-extension-name')
|
||||
},
|
||||
dataType: 'json'
|
||||
}).done(function(r) {
|
||||
if (r.success) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
var error = r.data ? r.data.pop().message : 'Error';
|
||||
|
||||
fw.soleModal.show(
|
||||
'fw-extension-install-error',
|
||||
'<p class="fw-text-danger">'+ error +'</p>'
|
||||
);
|
||||
}
|
||||
}).fail(function(jqXHR, textStatus, errorThrown){
|
||||
fw.soleModal.show(
|
||||
'fw-extension-install-error',
|
||||
'<p class="fw-text-danger">'+ String(errorThrown) +'</p>'
|
||||
);
|
||||
inst.isBusy = false;
|
||||
inst.loading($form, false);
|
||||
});
|
||||
} else {
|
||||
inst.stopListeningSubmit();
|
||||
$form.submit();
|
||||
}
|
||||
}).fail(function(jqXHR, textStatus, errorThrown){
|
||||
inst.stopListeningSubmit();
|
||||
$form.submit();
|
||||
});
|
||||
},
|
||||
loading: function($form, show) {
|
||||
var $loadingContainer = $form.closest('.fw-extensions-list-item').find('.fw-extensions-list-item-title').first();
|
||||
var $loading = $loadingContainer.find('.ajax-form-loading');
|
||||
|
||||
if (!$loading.length) {
|
||||
$loadingContainer.append(
|
||||
'<span class="ajax-form-loading fw-text-center fw-hidden">'+
|
||||
'<img src="'+ fw.img.loadingSpinner +'" />'+
|
||||
'</span>'
|
||||
);
|
||||
$loading = $loadingContainer.find('.ajax-form-loading');
|
||||
}
|
||||
|
||||
if (show) {
|
||||
$loading.removeClass('fw-hidden');
|
||||
} else {
|
||||
$loading.addClass('fw-hidden');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
inst.listenSubmit();
|
||||
});
|
||||
|
After Width: | Height: | Size: 926 B |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 20 KiB |
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<metadata>Generated by IcoMoon</metadata>
|
||||
<defs>
|
||||
<font id="icomoon" horiz-adv-x="1024">
|
||||
<font-face units-per-em="1024" ascent="960" descent="-64" />
|
||||
<missing-glyph horiz-adv-x="1024" />
|
||||
<glyph unicode=" " d="" horiz-adv-x="512" />
|
||||
<glyph unicode="" d="M402.322 641.307c8.195 177.384 154.668 318.693 334.198 318.693 184.794 0 334.597-149.702 334.597-334.367 0-5.258-0.166-10.476-0.408-15.674 0 0 0.408 0 0.408 0s0-611.265 0-611.265c0 0-156.842-62.693-156.842-62.693s-146.385 62.693-146.385 62.693c0 0 0 568.788 0 568.788s0 115.621 0 115.621c0 0-0.132 0-0.132 0-0.87 37.687-20.304 70.747-49.501 90.476-27.849-18.815-46.846-49.73-49.306-85.253 0 0-0.396 0-0.396 0s0-433.633 0-433.633zM668.399 254.693c-8.192-177.384-154.577-318.693-334-318.693-184.684 0-334.399 149.702-334.399 334.367 0 5.268 0.295 10.463 0.537 15.674 0 0-0.537 0-0.537 0s0 611.265 0 611.265c0 0 156.747 62.693 156.747 62.693s146.3-62.693 146.3-62.693c0 0 0-568.788 0-568.788s0-115.621 0-115.621c0 0 0.132 0 0.132 0 0.87-37.687 20.292-70.747 49.472-90.476 27.83 18.815 47.867 50.192 50.327 85.714 0 0-0.656-0.462-0.656-0.462s0 433.633 0 433.633z" horiz-adv-x="1071" />
|
||||
</font></defs></svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
@@ -0,0 +1,28 @@
|
||||
@font-face {
|
||||
font-family: 'unyson-font-icon';
|
||||
src:url('fonts/icomoon.eot?iganyx');
|
||||
src:url('fonts/icomoon.eot?#iefixiganyx') format('embedded-opentype'),
|
||||
url('fonts/icomoon.woff?iganyx') format('woff'),
|
||||
url('fonts/icomoon.ttf?iganyx') format('truetype'),
|
||||
url('fonts/icomoon.svg?iganyx#icomoon') format('svg');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
.toplevel_page_fw-extensions > .wp-menu-image:before {
|
||||
font-family: 'unyson-font-icon';
|
||||
speak: none;
|
||||
font-style: normal;
|
||||
font-weight: normal;
|
||||
font-variant: normal;
|
||||
text-transform: none;
|
||||
line-height: 1;
|
||||
|
||||
/* Better Font Rendering =========== */
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
|
||||
content: "\e600";
|
||||
font-size: 14px;
|
||||
line-height: 20px;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
/**
|
||||
* @var array $extension_names
|
||||
* @var array $installed_extensions
|
||||
* @var array $list_page_link
|
||||
*/
|
||||
|
||||
$count = count($extension_names);
|
||||
?>
|
||||
|
||||
<p><?php echo _n(
|
||||
'You are about to remove the following extension:',
|
||||
'You are about to remove the following extensions:',
|
||||
$count,
|
||||
'fw'
|
||||
) ?></p>
|
||||
|
||||
<ul class="ul-disc">
|
||||
<?php foreach ($extension_names as $extension_name): ?>
|
||||
<li><strong><?php echo fw()->extensions->manager->get_extension_title($extension_name); ?></strong></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
|
||||
<p><?php
|
||||
echo _n(
|
||||
'Are you sure you wish to delete this extension?',
|
||||
'Are you sure you wish to delete these extensions?',
|
||||
$count,
|
||||
'fw'
|
||||
)
|
||||
?></p>
|
||||
|
||||
<input type="submit" name="submit" id="submit" class="button" value="<?php
|
||||
echo esc_attr( _n(
|
||||
'Yes, Delete this extension',
|
||||
'Yes, Delete these extensions',
|
||||
$count,
|
||||
'fw'
|
||||
) )
|
||||
?>">
|
||||
|
||||
<a class="button" href="<?php echo esc_attr($list_page_link) ?>" ><?php _e('No, Return me to the extension list', 'fw') ?></a>
|
||||
|
||||
<p>
|
||||
<a href="#" onclick="jQuery('#files-list').toggle(); return false;"><?php _e('Click to view entire list of directories which will be deleted', 'fw') ?></a>
|
||||
</p>
|
||||
<div id="files-list" style="display: none;">
|
||||
<ul class="code">
|
||||
<?php $replace_regex = '/^'. preg_quote(fw_get_framework_directory('/extensions'), '/') .'/'; ?>
|
||||
<?php foreach ($extension_names as $extension_name): ?>
|
||||
<?php if (!isset($installed_extensions[$extension_name])) continue; ?>
|
||||
<li><?php echo preg_replace($replace_regex, '', $installed_extensions[$extension_name]['path']) ?>/</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
/**
|
||||
* @var string $extension_name
|
||||
* @var array $extension_data
|
||||
* @var string $extension_title
|
||||
* @var string $link_delete
|
||||
* @var string $link_extension
|
||||
* @var string $tab
|
||||
* @var bool $is_supported
|
||||
*/
|
||||
|
||||
?>
|
||||
<h2 class="fw-extension-page-title">
|
||||
<span class="fw-pull-right">
|
||||
<?php
|
||||
switch ($tab) {
|
||||
case 'settings':
|
||||
if (!file_exists($extension_data['path'] .'/readme.md.php')) {
|
||||
break;
|
||||
}
|
||||
if ($is_supported) {
|
||||
// do not show install instructions for supported extensions
|
||||
break;
|
||||
}
|
||||
?><a href="<?php echo esc_attr($link_extension) ?>&extension=<?php echo esc_attr($extension_name) ?>&tab=docs" class="button-primary"><?php _e('Install Instructions', 'fw') ?></a><?php
|
||||
break;
|
||||
case 'docs':
|
||||
if (!fw()->extensions->get($extension_name) || !fw()->extensions->get($extension_name)->get_settings_options()) {
|
||||
break;
|
||||
}
|
||||
?><a href="<?php echo esc_attr($link_extension) ?>&extension=<?php echo esc_attr($extension_name) ?>" class="button-primary"><?php _e('Settings', 'fw') ?></a><?php
|
||||
break;
|
||||
}
|
||||
?>
|
||||
</span>
|
||||
|
||||
<?php
|
||||
switch ($tab) {
|
||||
case 'settings':
|
||||
echo sprintf(__('%s Settings', 'fw'), $extension_title);
|
||||
break;
|
||||
case 'docs':
|
||||
echo sprintf(__('%s Install Instructions', 'fw'), $extension_title);
|
||||
break;
|
||||
default:
|
||||
echo __('Unknown tab:', 'fw') . ' ' . fw_htmlspecialchars($tab);
|
||||
}
|
||||
?>
|
||||
</h2>
|
||||
<br/>
|
||||
@@ -0,0 +1,246 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
/**
|
||||
* Display extension in list on the extensions page
|
||||
* @var string $name
|
||||
* @var string $title
|
||||
* @var string $description
|
||||
* @var string $link
|
||||
* @var array $lists
|
||||
* @var array $nonces
|
||||
* @var string $default_thumbnail
|
||||
* @var bool $can_install
|
||||
* @var bool $is_active
|
||||
*/
|
||||
|
||||
$ext = fw_ext( $name );
|
||||
$is_active = isset( $lists['active'][ $name ] ) ? true : false;
|
||||
$version = $ext ? $ext->manifest->get_version() : '';
|
||||
$ext_page = $ext ? $ext->_get_link() : '';
|
||||
$url_set = '';
|
||||
|
||||
if ( $ext && $ext->get_settings_options() ) {
|
||||
$url_set = "{$link}&sub-page=extension&extension={$name}";
|
||||
} else {
|
||||
if ( ! empty( $lists['available'][ $name ]['download']['url_set'] ) ) {
|
||||
$url_set = admin_url( $lists['available'][ $name ]['download']['url_set'] );
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($lists['installed'][$name])) {
|
||||
$installed_data = &$lists['installed'][$name];
|
||||
} else {
|
||||
$installed_data = false;
|
||||
}
|
||||
|
||||
if (isset($lists['available'][$name])) {
|
||||
$available_data = &$lists['available'][$name];
|
||||
} else {
|
||||
$available_data = false;
|
||||
}
|
||||
|
||||
{
|
||||
if (isset($lists['available'][$name])) {
|
||||
$thumbnail = $lists['available'][$name]['thumbnail'];
|
||||
} else {
|
||||
$thumbnail = $default_thumbnail;
|
||||
}
|
||||
|
||||
if ( isset( $lists['installed'][ $name ] ) ) {
|
||||
|
||||
$manifest = ! empty( $lists['installed'][ $name ]['thumbnail'] ) ? $lists['installed'][ $name ]['thumbnail'] : $lists['installed'][ $name ]['manifest'];
|
||||
$thumbnail = fw_akg( 'thumbnail', $manifest, $thumbnail );
|
||||
|
||||
// local image
|
||||
if (
|
||||
substr( $thumbnail, 0, 11 ) !== 'data:image/'
|
||||
&&
|
||||
! filter_var( $thumbnail, FILTER_VALIDATE_URL )
|
||||
&&
|
||||
file_exists( $thumbnail_path = $lists['installed'][ $name ]['path'] . '/' . $thumbnail )
|
||||
) {
|
||||
$thumbnail = fw_get_path_url( $thumbnail_path );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$is_compatible =
|
||||
isset($lists['supported'][$name]) // is listed in the supported extensions list in theme manifest
|
||||
||
|
||||
($installed_data && ! empty( $installed_data['is']['theme'] ) ); // is located in the theme
|
||||
|
||||
$wrapper_class = 'fw-col-xs-12 fw-col-lg-6 fw-extensions-list-item';
|
||||
|
||||
if ($installed_data && !$is_active) {
|
||||
$wrapper_class .= ' disabled';
|
||||
}
|
||||
|
||||
if (!$installed_data && !$is_compatible) {
|
||||
$wrapper_class .= ' not-compatible';
|
||||
}
|
||||
?>
|
||||
<div class="<?php echo esc_attr($wrapper_class) ?>" id="fw-ext-<?php echo esc_attr($name) ?>">
|
||||
<a class="fw-ext-anchor" name="ext-<?php echo esc_attr($name) ?>"></a>
|
||||
<div class="inner">
|
||||
<div class="fw-extension-list-item-table">
|
||||
<div class="fw-extension-list-item-table-row">
|
||||
<div class="fw-extension-list-item-table-cell cell-1">
|
||||
<div class="fw-extensions-list-item-thumbnail-wrapper">
|
||||
<?php echo fw_string_to_icon_html($thumbnail, array('class' => 'fw-extensions-list-item-thumbnail')); ?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="fw-extension-list-item-table-cell cell-2">
|
||||
|
||||
<h3 class="fw-extensions-list-item-title"<?php echo( $is_active && $version ? ' title="v' . esc_attr( $version ) . '"' : '' ); ?>>
|
||||
<?php
|
||||
if ( $is_active && $ext_page ) {
|
||||
echo fw_html_tag( 'a', array( 'href' => $ext_page ), $title );
|
||||
} else {
|
||||
echo $title;
|
||||
}
|
||||
?>
|
||||
</h3>
|
||||
|
||||
<?php if ($description): ?>
|
||||
<p class="fw-extensions-list-item-desc"><?php echo esc_html($description); ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php
|
||||
if ( $installed_data ) {
|
||||
$_links = array();
|
||||
|
||||
if ( $is_active && $url_set ) {
|
||||
$_links[] = '<a href="' . esc_url( $url_set ) . '">' . __( 'Settings', 'fw' ) . '</a>';
|
||||
}
|
||||
|
||||
if ( $is_active && isset( $installed_data['path'] ) && file_exists( $installed_data['path'] . '/readme.md.php' ) ) {
|
||||
if ( isset($lists['supported'][$name]) ) {
|
||||
// no sense to teach how to install the extension if theme is already configured and the is extension marked as compatible
|
||||
} else {
|
||||
$_links[] = '<a href="' . esc_attr( $link ) . '&sub-page=extension&extension=' . esc_attr( $name ) . '&tab=docs">' . __( 'Install Instructions', 'fw' ) . '</a>';
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! empty( $_links ) ):
|
||||
?><p class="fw-extensions-list-item-links"><?php echo implode( ' <span class="fw-text-muted">|</span> ', $_links ); ?></p><?php
|
||||
endif;
|
||||
|
||||
unset( $_links );
|
||||
}
|
||||
?>
|
||||
<?php if ($is_compatible): ?>
|
||||
<p><em><strong><span class="dashicons dashicons-yes"></span> <?php _e('Compatible', 'fw') ?></strong> <?php _e('with your current theme', 'fw') ?></em></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="fw-extension-list-item-table-cell cell-3">
|
||||
<?php if ($is_active): ?>
|
||||
<form action="<?php echo esc_attr($link) ?>&sub-page=deactivate&extension=<?php echo esc_attr( $name ) ?>" method="post">
|
||||
<?php wp_nonce_field($nonces['deactivate']['action'], $nonces['deactivate']['name']); ?>
|
||||
<input class="button" type="submit" value="<?php esc_attr_e('Deactivate', 'fw'); ?>"/>
|
||||
</form>
|
||||
<?php elseif ($installed_data): ?>
|
||||
<div class="fw-text-center">
|
||||
<form action="<?php echo esc_attr($link) ?>&sub-page=activate&extension=<?php echo esc_attr($name) ?>"
|
||||
method="post"
|
||||
class="extension-activate-form"
|
||||
>
|
||||
<?php wp_nonce_field($nonces['activate']['action'], $nonces['activate']['name']); ?>
|
||||
<input class="button" type="submit" value="<?php esc_attr_e('Activate', 'fw'); ?>"/>
|
||||
</form>
|
||||
<?php
|
||||
/**
|
||||
* Do not show the "Delete extension" button if the extension is not in the available list.
|
||||
* If you delete such extension you will not be able to install it back.
|
||||
* Most often these will be extensions located in the theme.
|
||||
*/
|
||||
if ($can_install && $available_data):
|
||||
?>
|
||||
<form action="<?php echo esc_attr($link) ?>&sub-page=delete&extension=<?php echo esc_attr($name) ?>"
|
||||
method="post"
|
||||
class="fw-extension-ajax-form extension-delete-form"
|
||||
data-confirm-message="<?php esc_attr_e('Are you sure you want to remove this extension?', 'fw') ?>"
|
||||
data-extension-name="<?php echo esc_attr($name) ?>"
|
||||
data-extension-action="uninstall"
|
||||
>
|
||||
<?php wp_nonce_field($nonces['delete']['action'], $nonces['delete']['name']); ?>
|
||||
<p class="fw-visible-xs-block"></p>
|
||||
<a href="#"
|
||||
onclick="jQuery(this).closest('form').submit(); return false;"
|
||||
data-remove-extension="<?php echo esc_attr($name) ?>"
|
||||
title="<?php esc_attr_e('Remove', 'fw'); ?>"
|
||||
><span class="btn-text fw-visible-xs-inline"><?php _e('Remove', 'fw'); ?></span><span class="btn-icon unycon unycon-trash fw-hidden-xs"></span></a>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php elseif ($can_install && $available_data): ?>
|
||||
<form action="<?php echo esc_attr($link) ?>&sub-page=install&extension=<?php echo esc_attr($name) ?>"
|
||||
method="post"
|
||||
class="fw-extension-ajax-form"
|
||||
data-extension-name="<?php echo esc_attr($name) ?>"
|
||||
data-extension-action="install"
|
||||
>
|
||||
<?php wp_nonce_field($nonces['install']['action'], $nonces['install']['name']); ?>
|
||||
<input type="submit" class="button" value="<?php esc_attr_e('Download', 'fw') ?>">
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ($installed_data): ?>
|
||||
<?php if (!$is_active): ?>
|
||||
<?php if (!fw()->extensions->_get_db_active_extensions($name)): ?>
|
||||
<span><!-- Is not set as active in db --></span>
|
||||
<?php elseif ($installed_data['parent'] && !fw()->extensions->get($installed_data['parent'])): ?>
|
||||
<?php
|
||||
$parent_extension_name = $installed_data['parent'];
|
||||
$parent_extension_title = fw_id_to_title($parent_extension_name);
|
||||
|
||||
if (isset($lists['installed'][$parent_extension_name])) {
|
||||
$parent_extension_title = fw_akg('name', $lists['installed'][$parent_extension_name]['manifest'], $parent_extension_title);
|
||||
} elseif (isset($lists['available'][$parent_extension_name])) {
|
||||
$parent_extension_title = $lists['available'][$parent_extension_name]['name'];
|
||||
}
|
||||
?>
|
||||
<p class="fw-text-muted"><?php echo sprintf(__('Parent extension "%s" is disabled', 'fw'), $parent_extension_title); ?></p>
|
||||
<?php else: ?>
|
||||
<div class="fw-extension-disabled fw-border-box-sizing">
|
||||
<div class="fw-extension-disabled-panel fw-border-box-sizing">
|
||||
<div class="fw-row">
|
||||
<div class="fw-col-xs-12 fw-col-sm-3">
|
||||
<span class="fw-text-danger">! <?php _e('Disabled', 'fw'); ?></span>
|
||||
</div>
|
||||
<div class="fw-col-xs-12 fw-col-sm-9 fw-text-right">
|
||||
<?php
|
||||
|
||||
$requirements = fw()
|
||||
->extensions
|
||||
->manager->collect_extension_requirements(
|
||||
$name
|
||||
);
|
||||
|
||||
?>
|
||||
<a onclick="return false;" href="#" class="fw-extension-tip" title="<?php
|
||||
echo fw_htmlspecialchars(
|
||||
'<div class="fw-extension-tip-content">'.
|
||||
'<ul class="fw-extension-requirements"><li>- '. implode('</li><li>- ', $requirements) .'</li></ul>'.
|
||||
'</div>'
|
||||
);
|
||||
unset($requirements);
|
||||
?>"><?php _e('View Requirements', 'fw') ?></a>
|
||||
<p class="fw-visible-xs-block"></p><?php
|
||||
if ($can_install):
|
||||
?><a href="<?php echo esc_attr($link) ?>&sub-page=delete&extension=<?php echo esc_attr($name) ?>" class="button" ><?php _e('Remove', 'fw'); ?></a><?php
|
||||
endif;
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<?php elseif ($available_data): ?>
|
||||
<!-- -->
|
||||
<?php else: ?>
|
||||
<!-- -->
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,267 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
/**
|
||||
* @var array $lists
|
||||
* @var string $link
|
||||
* @var array $nonces
|
||||
* @var mixed $display_default_value
|
||||
* @var string $default_thumbnail
|
||||
* @var bool $can_install
|
||||
*/
|
||||
|
||||
$installed_plugins = get_plugins();
|
||||
|
||||
foreach ( $lists['available'] as $name => &$_ext ) {
|
||||
if ( empty( $_ext['download']['opts']['plugin'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$slug = $_ext['download']['opts']['plugin'];
|
||||
|
||||
if ( is_plugin_active( $slug ) ) {
|
||||
$lists['active'][ $name ] = $_ext;
|
||||
$lists['installed'][ $name ] = $_ext;
|
||||
} else {
|
||||
if ( isset( $installed_plugins[ $slug ] ) ) {
|
||||
$lists['installed'][ $name ] = $_ext;
|
||||
$lists['disabled'][ $name ] = $_ext;
|
||||
}
|
||||
}
|
||||
|
||||
$lists['supported'][ $name ] = $_ext;
|
||||
}
|
||||
|
||||
// Set extensions order same as in available extensions list
|
||||
{
|
||||
$ordered = array(
|
||||
'active' => array(),
|
||||
'installed' => array(),
|
||||
);
|
||||
|
||||
foreach ( $lists['available'] as $name => &$_ext ) {
|
||||
foreach ( $ordered as $type => &$_exts ) {
|
||||
if ( isset( $lists[ $type ][ $name ] ) ) {
|
||||
$ordered[ $type ][ $name ] = $lists[ $type ][ $name ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $ordered as $type => &$_exts ) {
|
||||
if ( ! empty( $ordered[ $type ] ) ) {
|
||||
$lists[ $type ] = array_merge( $ordered[ $type ], $lists[ $type ] );
|
||||
}
|
||||
}
|
||||
|
||||
unset( $ordered, $name, $_ext, $_exts, $type );
|
||||
}
|
||||
|
||||
$extension_view_path = dirname( __FILE__ ) . '/extension.php';
|
||||
|
||||
$displayed = array();
|
||||
?>
|
||||
|
||||
<h3><?php _e('Active Extensions', 'fw') ?></h3>
|
||||
<?php
|
||||
$display_active_extensions = array();
|
||||
|
||||
foreach ( $lists['active'] as $name => &$data ) {
|
||||
if ( ! empty( $data['display'] ) || true === fw_akg( 'display', $data['manifest'], $display_default_value ) ) {
|
||||
$display_active_extensions[ $name ] = &$data;
|
||||
}
|
||||
}
|
||||
|
||||
unset($data);
|
||||
?>
|
||||
<?php if (empty($display_active_extensions)): ?>
|
||||
<div class="fw-extensions-no-active">
|
||||
<div class="fw-text-center fw-extensions-title-icon"><span class="dashicons dashicons-screenoptions"></span></div>
|
||||
<p class="fw-text-center fw-text-muted"><em><?php _e('No extensions activated yet', 'fw'); ?><br/><?php _e('Check the available extensions below', 'fw'); ?></em></p>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="fw-row fw-extensions-list">
|
||||
<?php
|
||||
foreach ( $display_active_extensions as $name => &$data ) {
|
||||
|
||||
$ext = fw_ext( $name );
|
||||
|
||||
fw_render_view( $extension_view_path, array(
|
||||
'name' => $name,
|
||||
'title' => $ext ? $ext->manifest->get_name() : $data['name'],
|
||||
'description' => $ext ? $ext->manifest->get( 'description' ) : ( isset( $data['description'] ) ? $data['description'] : '' ),
|
||||
'link' => $link,
|
||||
'lists' => &$lists,
|
||||
'nonces' => $nonces,
|
||||
'default_thumbnail' => $default_thumbnail,
|
||||
'can_install' => $can_install,
|
||||
), false );
|
||||
|
||||
$displayed[ $name ] = true;
|
||||
}
|
||||
unset($data);
|
||||
?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div id="fw-extensions-list-available">
|
||||
<hr class="fw-extensions-lists-separator"/>
|
||||
<h3><?php _e('Available Extensions', 'fw') ?></h3><!-- This "available" differs from technical "available" -->
|
||||
<div class="fw-row fw-extensions-list">
|
||||
<?php $something_displayed = false; ?>
|
||||
<?php
|
||||
{
|
||||
$theme_extensions = array();
|
||||
|
||||
foreach ( $lists['disabled'] as $name => &$data ) {
|
||||
if ( empty( $data['is']['theme'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$theme_extensions[ $name ] = array(
|
||||
'name' => fw_akg( 'name', $data['manifest'], fw_id_to_title( $name ) ),
|
||||
'description' => fw_akg( 'description', $data['manifest'], '' )
|
||||
);
|
||||
}
|
||||
unset($data);
|
||||
|
||||
foreach ($theme_extensions + $lists['supported'] as $name => $data) {
|
||||
if (isset($displayed[$name])) {
|
||||
continue;
|
||||
} elseif ( isset( $lists['installed'][ $name ] ) && ! empty( $lists['installed'][$name]['manifest'] ) ) {
|
||||
if (true !== fw_akg('display', $lists['installed'][$name]['manifest'], $display_default_value)) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (isset($lists['available'][$name])) {
|
||||
if (!$can_install) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
//trigger_error(sprintf(__('Supported extension "%s" is not available.', 'fw'), $name));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
fw_render_view($extension_view_path, array(
|
||||
'name' => $name,
|
||||
'title' => $data['name'],
|
||||
'description' => $data['description'],
|
||||
'link' => $link,
|
||||
'lists' => &$lists,
|
||||
'nonces' => $nonces,
|
||||
'default_thumbnail' => $default_thumbnail,
|
||||
'can_install' => $can_install,
|
||||
), false);
|
||||
|
||||
$displayed[$name] = $something_displayed = true;
|
||||
}
|
||||
|
||||
unset($theme_extensions);
|
||||
}
|
||||
|
||||
foreach ( $lists['disabled'] as $name => &$data ) {
|
||||
if ( isset( $displayed[ $name ] ) ) {
|
||||
continue;
|
||||
} elseif ( isset( $data['display'] ) && true !== $data['display'] ) {
|
||||
continue;
|
||||
} elseif ( isset( $data['manifest'] ) && true !== fw_akg( 'display', $data['manifest'], $display_default_value ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fw_render_view( $extension_view_path, array(
|
||||
'name' => $name,
|
||||
'title' => ! empty( $data['manifest']['name'] ) ? $data['manifest']['name'] : ( ! empty( $data['name'] ) ? $data['name'] : 'No name' ),
|
||||
'description' => ! empty( $data['manifest']['description'] ) ? $data['manifest']['description'] : ( ! empty( $data['description'] ) ? $data['description'] : '' ),
|
||||
'link' => $link,
|
||||
'lists' => &$lists,
|
||||
'nonces' => $nonces,
|
||||
'default_thumbnail' => $default_thumbnail,
|
||||
'can_install' => $can_install,
|
||||
), false );
|
||||
|
||||
$displayed[$name] = $something_displayed = true;
|
||||
}
|
||||
unset($data);
|
||||
|
||||
if ($can_install) {
|
||||
foreach ( $lists['available'] as $name => &$data ) {
|
||||
if ( isset( $displayed[ $name ] ) ) {
|
||||
continue;
|
||||
} elseif ( isset( $lists['installed'][ $name ] ) ) {
|
||||
continue;
|
||||
} elseif ( $data['display'] !== true ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* fixme: remove this in the future when this extensions will look good on any theme
|
||||
*/
|
||||
if ( in_array( $name, array( 'styling', 'megamenu' ) ) ) {
|
||||
if ( isset( $lists['supported'][ $name ] ) || ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ) {
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
fw_render_view( $extension_view_path, array(
|
||||
'name' => $name,
|
||||
'title' => $data['name'],
|
||||
'description' => $data['description'],
|
||||
'link' => $link,
|
||||
'lists' => &$lists,
|
||||
'nonces' => $nonces,
|
||||
'default_thumbnail' => $default_thumbnail,
|
||||
'can_install' => $can_install,
|
||||
), false );
|
||||
|
||||
$something_displayed = true;
|
||||
}
|
||||
unset($data);
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
<?php if ($something_displayed && apply_filters('fw_extensions_page_show_other_extensions', true)): ?>
|
||||
<!-- show/hide not compatible extensions -->
|
||||
<p class="fw-text-center toggle-not-compat-ext-btn-wrapper"><?php
|
||||
echo fw_html_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => '#',
|
||||
'onclick' => 'return false;',
|
||||
'class' => 'button toggle-not-compat-ext-btn',
|
||||
'style' => 'box-shadow:none;'
|
||||
),
|
||||
'<span class="the-show-text">'. __('Show other extensions', 'fw') .'</span>'.
|
||||
'<span class="the-hide-text fw-hidden">'. __('Hide other extensions', 'fw') .'</span>'
|
||||
);
|
||||
?></p>
|
||||
<script type="text/javascript">
|
||||
jQuery(function($){
|
||||
if (
|
||||
!$('.fw-extensions-list .fw-extensions-list-item.not-compatible').length
|
||||
||
|
||||
<?php echo empty($lists['supported']) ? 'true' : 'false' ?>
|
||||
) {
|
||||
// disable the show/hide feature
|
||||
$('#fw-extensions-list-wrapper .toggle-not-compat-ext-btn-wrapper').addClass('fw-hidden');
|
||||
} else {
|
||||
$('#fw-extensions-list-wrapper .fw-extensions-list .fw-extensions-list-item.not-compatible').fadeOut('fast');
|
||||
|
||||
$('#fw-extensions-list-wrapper .toggle-not-compat-ext-btn-wrapper').on('click', function(){
|
||||
$('#fw-extensions-list-wrapper .fw-extensions-list .fw-extensions-list-item.not-compatible')[
|
||||
$(this).find('.the-hide-text').hasClass('fw-hidden') ? 'fadeIn' : 'fadeOut'
|
||||
]();
|
||||
|
||||
$(this).find('.the-show-text, .the-hide-text').toggleClass('fw-hidden');
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<!-- end: show/hide not compatible extensions -->
|
||||
<?php else: ?>
|
||||
<script type="text/javascript">
|
||||
jQuery(function($){
|
||||
$('#fw-extensions-list-available').remove();
|
||||
});
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
/**
|
||||
* @var array $extension_titles
|
||||
* @var array $list_page_link
|
||||
* @var bool $supported
|
||||
*/
|
||||
|
||||
$count = count($extension_titles);
|
||||
?>
|
||||
|
||||
<?php if ($supported): ?>
|
||||
<p><?php echo _n(
|
||||
'We\'ve detected that your current theme is compatible with the following extension and it is recommended that you install it to fully benefit from your theme.',
|
||||
'We\'ve detected that your current theme is compatible with the following extensions and it is recommended that you install them to fully benefit from your theme.',
|
||||
$count,
|
||||
'fw'
|
||||
) ?></p>
|
||||
<?php else: ?>
|
||||
<p><?php echo _n(
|
||||
'You are about to install the following extension:',
|
||||
'You are about to install the following extensions:',
|
||||
$count,
|
||||
'fw'
|
||||
) ?></p>
|
||||
<?php endif; ?>
|
||||
|
||||
<ul class="ul-disc">
|
||||
<?php foreach ($extension_titles as $extension_title): ?>
|
||||
<li><strong><?php echo $extension_title; ?></strong></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
|
||||
<p><?php
|
||||
echo _n(
|
||||
'Are you sure you wish to install this extension?',
|
||||
'Are you sure you wish to install these extensions?',
|
||||
$count,
|
||||
'fw'
|
||||
)
|
||||
?></p>
|
||||
|
||||
<input type="submit" name="submit" id="submit" class="button" value="<?php
|
||||
echo esc_attr( _n(
|
||||
'Yes, Install this extension',
|
||||
'Yes, Install these extensions',
|
||||
$count,
|
||||
'fw'
|
||||
) )
|
||||
?>">
|
||||
|
||||
<a class="button" href="<?php echo esc_attr($list_page_link) ?>" ><?php _e('No, Return me to the extension list', 'fw') ?></a>
|
||||
284
wp-content/plugins/unyson/framework/core/components/theme.php
Normal file
@@ -0,0 +1,284 @@
|
||||
<?php defined( 'FW' ) or die();
|
||||
|
||||
/**
|
||||
* Theme Component
|
||||
* Works with framework customizations / theme directory
|
||||
*/
|
||||
final class _FW_Component_Theme {
|
||||
private static $cache_key = 'fw_theme';
|
||||
|
||||
/**
|
||||
* @var FW_Theme_Manifest
|
||||
*/
|
||||
public $manifest;
|
||||
|
||||
public function __construct() {
|
||||
$manifest = array();
|
||||
|
||||
if ( ( $manifest_file = apply_filters( 'fw_framework_manifest_path', fw_get_template_customizations_directory( '/theme/manifest.php' ) ) ) && is_file( $manifest_file ) ) {
|
||||
@include $manifest_file;
|
||||
}
|
||||
|
||||
if ( is_child_theme() && ( $manifest_file = fw_get_stylesheet_customizations_directory( '/theme/manifest.php' ) ) && is_file( $manifest_file ) ) {
|
||||
$extracted = fw_get_variables_from_file( $manifest_file, array( 'manifest' => array() ) );
|
||||
if ( isset( $extracted['manifest'] ) ) {
|
||||
$manifest = array_merge( $manifest, $extracted['manifest'] );
|
||||
}
|
||||
}
|
||||
|
||||
$this->manifest = new FW_Theme_Manifest( $manifest );
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _init() {
|
||||
add_action( 'admin_notices', array( $this, '_action_admin_notices' ) );
|
||||
add_action( 'wp_ajax_fw_brz_dismiss_notice', array( $this, '_action_ajax_brz_dismiss_notice' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _after_components_init() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Search relative path in: child theme -> parent "theme" directory and return full path
|
||||
*
|
||||
* @param string $rel_path
|
||||
*
|
||||
* @return false|string
|
||||
*/
|
||||
public function locate_path( $rel_path ) {
|
||||
if ( is_child_theme() && file_exists( fw_get_stylesheet_customizations_directory( '/theme' . $rel_path ) ) ) {
|
||||
return fw_get_stylesheet_customizations_directory( '/theme' . $rel_path );
|
||||
} elseif ( file_exists( fw_get_template_customizations_directory( '/theme' . $rel_path ) ) ) {
|
||||
return fw_get_template_customizations_directory( '/theme' . $rel_path );
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array with options from specified name/path
|
||||
*
|
||||
* @param string $name '{theme}/framework-customizations/theme/options/{$name}.php'
|
||||
* @param array $variables These will be available in options file (like variables for view)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_options( $name, array $variables = array() ) {
|
||||
$path = $this->locate_path( '/options/' . $name . '.php' );
|
||||
|
||||
if ( ! $path ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$variables = fw_get_variables_from_file( $path, array( 'options' => array() ), $variables );
|
||||
|
||||
return $variables['options'];
|
||||
}
|
||||
|
||||
public function get_settings_options() {
|
||||
$cache_key = self::$cache_key . '/options/settings';
|
||||
|
||||
try {
|
||||
return FW_Cache::get( $cache_key );
|
||||
} catch ( FW_Cache_Not_Found_Exception $e ) {
|
||||
$options = apply_filters( 'fw_settings_options', $this->get_options( 'settings' ) );
|
||||
|
||||
FW_Cache::set( $cache_key, $options );
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_customizer_options() {
|
||||
$cache_key = self::$cache_key . '/options/customizer';
|
||||
|
||||
try {
|
||||
return FW_Cache::get( $cache_key );
|
||||
} catch ( FW_Cache_Not_Found_Exception $e ) {
|
||||
$options = apply_filters( 'fw_customizer_options', $this->get_options( 'customizer' ) );
|
||||
|
||||
FW_Cache::set( $cache_key, $options );
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_post_options( $post_type ) {
|
||||
$cache_key = self::$cache_key . '/options/posts/' . $post_type;
|
||||
|
||||
try {
|
||||
return FW_Cache::get( $cache_key );
|
||||
} catch ( FW_Cache_Not_Found_Exception $e ) {
|
||||
$options = apply_filters(
|
||||
'fw_post_options',
|
||||
apply_filters( "fw_post_options:$post_type", $this->get_options( 'posts/' . $post_type ) ),
|
||||
$post_type
|
||||
);
|
||||
|
||||
FW_Cache::set( $cache_key, $options );
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
||||
public function get_taxonomy_options( $taxonomy ) {
|
||||
$cache_key = self::$cache_key . '/options/taxonomies/' . $taxonomy;
|
||||
|
||||
try {
|
||||
return FW_Cache::get( $cache_key );
|
||||
} catch ( FW_Cache_Not_Found_Exception $e ) {
|
||||
$options = apply_filters(
|
||||
'fw_taxonomy_options',
|
||||
apply_filters( "fw_taxonomy_options:$taxonomy", $this->get_options( 'taxonomies/' . $taxonomy ) ),
|
||||
$taxonomy
|
||||
);
|
||||
|
||||
FW_Cache::set( $cache_key, $options );
|
||||
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return config key value, or entire config array
|
||||
* Config array is merged from child configs
|
||||
*
|
||||
* @param string|null $key Multi key format accepted: 'a/b/c'
|
||||
* @param mixed $default_value
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
final public function get_config( $key = null, $default_value = null ) {
|
||||
$cache_key = self::$cache_key . '/config';
|
||||
|
||||
try {
|
||||
$config = FW_Cache::get( $cache_key );
|
||||
} catch ( FW_Cache_Not_Found_Exception $e ) {
|
||||
// default values
|
||||
$config = array(
|
||||
/** Toggle Theme Settings form ajax submit */
|
||||
'settings_form_ajax_submit' => true,
|
||||
/** Toggle Theme Settings side tabs */
|
||||
'settings_form_side_tabs' => false,
|
||||
/** Toggle Tabs rendered all at once, or initialized only on open/display */
|
||||
'lazy_tabs' => true,
|
||||
);
|
||||
|
||||
if ( file_exists( fw_get_template_customizations_directory( '/theme/config.php' ) ) ) {
|
||||
$variables = fw_get_variables_from_file( fw_get_template_customizations_directory( '/theme/config.php' ), array( 'cfg' => null ) );
|
||||
|
||||
if ( ! empty( $variables['cfg'] ) ) {
|
||||
$config = array_merge( $config, $variables['cfg'] );
|
||||
unset( $variables );
|
||||
}
|
||||
}
|
||||
|
||||
if ( is_child_theme() && file_exists( fw_get_stylesheet_customizations_directory( '/theme/config.php' ) ) ) {
|
||||
$variables = fw_get_variables_from_file( fw_get_stylesheet_customizations_directory( '/theme/config.php' ), array( 'cfg' => null ) );
|
||||
|
||||
if ( ! empty( $variables['cfg'] ) ) {
|
||||
$config = array_merge( $config, $variables['cfg'] );
|
||||
unset( $variables );
|
||||
}
|
||||
}
|
||||
|
||||
unset( $path );
|
||||
|
||||
FW_Cache::set( $cache_key, $config );
|
||||
}
|
||||
|
||||
return $key === null ? $config : fw_akg( $key, $config, $default_value );
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _action_admin_notices() {
|
||||
|
||||
if ( is_admin() && ! fw()->theme->manifest->check_requirements() && current_user_can( 'manage_options' ) ) {
|
||||
echo '<div class="notice notice-warning">
|
||||
<p>' .
|
||||
__( 'Theme requirements not met:', 'fw' ) . ' ' . fw()->theme->manifest->get_not_met_requirement_text() .
|
||||
'</p>
|
||||
</div>';
|
||||
}
|
||||
|
||||
$noPageAbout = ! ( isset( $_GET['page'] ) && 'fw-new' === $_GET['page'] );
|
||||
$noTransient = false === get_transient( 'fw_brz_admin_notice' );
|
||||
$isBrizy = ! defined( 'BRIZY_VERSION' ) && ! get_option( 'brizy' );
|
||||
|
||||
if ( $noTransient && $noPageAbout && $isBrizy && current_user_can( 'install_plugins' ) ) {
|
||||
|
||||
$url_install_plugin = is_multisite() ? network_admin_url( 'plugin-install.php?s=brizy&tab=search&type=term' ) : admin_url( 'plugin-install.php?s=brizy&tab=search&type=term' );
|
||||
|
||||
echo '<div class="notice updated is-dismissible fw-brz-dismiss">
|
||||
<p style="font-size:14px;">' .
|
||||
esc_html__( 'Try Brizy: A Fast & Easy Way of Creating Pages Visually', 'fw' ) .
|
||||
' - <a href="' . admin_url( 'admin.php?page=fw-new' ) . '">' .
|
||||
__( 'More Details', 'fw' ) .
|
||||
'</a>
|
||||
</p>
|
||||
<p>
|
||||
<a href="' . $url_install_plugin . '">' .
|
||||
__( 'Activate Now | for FREE', 'fw' ) .
|
||||
'</a>
|
||||
</p>
|
||||
<style>
|
||||
.fw-brz-dismiss {
|
||||
border-left-color: #d62c64 !important;
|
||||
}
|
||||
.fw-brz-dismiss p:last-of-type a {
|
||||
color: #fff;
|
||||
font-size: 13px;
|
||||
line-height: 1;
|
||||
background-color: #d62c64;
|
||||
box-shadow: 0px 2px 0px 0px #981e46;
|
||||
padding: 11px 27px 12px;
|
||||
border: 1px solid #d62c64;
|
||||
border-bottom: 0;
|
||||
border-radius: 3px;
|
||||
text-shadow: none;
|
||||
height: auto;
|
||||
text-decoration: none;
|
||||
display:inline-block;
|
||||
transition: all 200ms linear;
|
||||
}
|
||||
.fw-brz__btn-install:hover {
|
||||
background-color: #141923;
|
||||
color: #fff;
|
||||
border-color: #141923;
|
||||
box-shadow: 0px 2px 0px 0px #141923;
|
||||
}
|
||||
</style>
|
||||
</div>
|
||||
<script>
|
||||
jQuery(document).ready(function(){
|
||||
jQuery(document).on( "click", ".fw-brz-dismiss .notice-dismiss", function(){
|
||||
jQuery.ajax({
|
||||
url: "' . admin_url( 'admin-ajax.php' ) . '",
|
||||
type: "POST",
|
||||
data: {fw_brz_admin_notice: 1, action: "fw_brz_dismiss_notice"}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _action_ajax_brz_dismiss_notice() {
|
||||
|
||||
$expiration = 10 * ( 60 * 60 * 24 );
|
||||
|
||||
set_transient( 'fw_brz_admin_notice', 1, $expiration );
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php if ( ! defined( 'FW' ) ) {
|
||||
die( 'Forbidden' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Class FW_Option_Type_Exception
|
||||
*
|
||||
* @since 2.6.11
|
||||
*/
|
||||
class FW_Option_Type_Exception extends Exception {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Class FW_Option_Type_Exception_Not_Found
|
||||
*
|
||||
* @since 2.6.11
|
||||
*/
|
||||
class FW_Option_Type_Exception_Not_Found extends FW_Option_Type_Exception {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Class FW_Option_Type_Exception_Invalid_Class
|
||||
*
|
||||
* @since 2.6.11
|
||||
*/
|
||||
class FW_Option_Type_Exception_Invalid_Class extends FW_Option_Type_Exception {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Class FW_Option_Type_Exception_Already_Registered
|
||||
*
|
||||
* @since 2.6.11
|
||||
*/
|
||||
class FW_Option_Type_Exception_Already_Registered extends FW_Option_Type_Exception {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* Backend option container
|
||||
*/
|
||||
abstract class FW_Container_Type
|
||||
{
|
||||
/**
|
||||
* Container's unique type, used in option array in 'type' key
|
||||
* @return string
|
||||
*/
|
||||
abstract public function get_type();
|
||||
|
||||
/**
|
||||
* Overwrite this method to enqueue scripts and styles
|
||||
*
|
||||
* @param string $id
|
||||
* @param array $option
|
||||
* @param array $values Options values (in db format, returned from get_value_from_input())
|
||||
* @param array $data
|
||||
* @param bool Return true to call this method again on the next enqueue,
|
||||
* if you have some functionality in it that depends on option parameters.
|
||||
* By default this method is called only once for performance reasons.
|
||||
*/
|
||||
abstract protected function _enqueue_static($id, $option, $values, $data);
|
||||
|
||||
/**
|
||||
* Generate html
|
||||
* @param array $containers array('option_id' => array(), ...)
|
||||
* - Options arrays are merged with _get_defaults()
|
||||
* - All options are 100% only current container type, no need to check if ($option['type'] === $this->get_type())
|
||||
* - Are sent multiple options instead of one, because tabs (and maybe other feature containers)
|
||||
* can't be rendered separately (only as a collection).
|
||||
* Instead of having render_option() for those that can be rendered separately,
|
||||
* and render_options() for those like tabs, was decided to make a compromise,
|
||||
* only one method that always will receive an array of options,
|
||||
* instead of two methods when things may become confuse and complicated.
|
||||
* @param array $values Options values (in db format, returned from get_value_from_input())
|
||||
* @param array $data {id_prefix => '...', name_prefix => '...'}
|
||||
* @return string HTML
|
||||
* @internal
|
||||
*/
|
||||
abstract protected function _render($containers, $values, $data);
|
||||
|
||||
/**
|
||||
* Default option array
|
||||
*
|
||||
* This makes possible a container option array to have required only two parameters:
|
||||
* array('type' => '...', 'options' => array(...))
|
||||
* Other parameters are merged with the array returned by this method.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* array(
|
||||
* 'type' => '...',
|
||||
* ...
|
||||
* 'options' => array(...),
|
||||
* )
|
||||
* @internal
|
||||
*/
|
||||
abstract protected function _get_defaults();
|
||||
|
||||
/**
|
||||
* Prevent execute enqueue multiple times
|
||||
* @var bool
|
||||
*/
|
||||
private $static_enqueued = false;
|
||||
|
||||
final public function __construct()
|
||||
{
|
||||
// does nothing at the moment, but maybe in the future will do something
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FW_Access_Key $access_key
|
||||
* @internal
|
||||
* This must be called right after an instance of container type has been created
|
||||
* and was added to the registered array
|
||||
*/
|
||||
final public function _call_init($access_key)
|
||||
{
|
||||
if ($access_key->get_key() !== 'fw_backend') {
|
||||
trigger_error('Method call not allowed', E_USER_ERROR);
|
||||
}
|
||||
|
||||
if (method_exists($this, '_init')) {
|
||||
$this->_init();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes and prepare defaults
|
||||
*
|
||||
* @param string $id
|
||||
* @param array $option
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
private function prepare($id, &$option, &$data)
|
||||
{
|
||||
$data = array_merge(
|
||||
array(
|
||||
'id_prefix' => fw()->backend->get_options_id_attr_prefix(), // attribute id prefix
|
||||
'name_prefix' => fw()->backend->get_options_name_attr_prefix(), // attribute name prefix
|
||||
),
|
||||
$data
|
||||
);
|
||||
|
||||
$option = array_merge(
|
||||
$this->get_defaults(),
|
||||
$option,
|
||||
array(
|
||||
'type' => $this->get_type(),
|
||||
)
|
||||
);
|
||||
|
||||
if (!isset($option['attr'])) {
|
||||
$option['attr'] = array();
|
||||
}
|
||||
|
||||
if (!isset($option['title'])) {
|
||||
$option['title'] = fw_id_to_title($id);
|
||||
}
|
||||
|
||||
$option['attr']['class'] = 'fw-container fw-container-type-'. $option['type'] .(
|
||||
isset($option['attr']['class'])
|
||||
? ' '. $option['attr']['class']
|
||||
: ''
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate html
|
||||
* @param array $options array('container_id' => array(...container option...))
|
||||
* @param array $values Options values (in db format, returned from get_value_from_input())
|
||||
* @param array $data {'id_prefix' => '...', 'name_prefix' => '...'}
|
||||
* @return string HTML
|
||||
*/
|
||||
final public function render($options, $values = array(), $data = array())
|
||||
{
|
||||
$containers = array();
|
||||
|
||||
foreach ($options as $id => &$option) {
|
||||
if (
|
||||
!isset($option['options'])
|
||||
||
|
||||
!isset($option['type'])
|
||||
||
|
||||
$option['type'] !== $this->get_type()
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->prepare($id, $option, $data);
|
||||
|
||||
$this->enqueue_static($id, $option, $data);
|
||||
|
||||
$containers[$id] = &$option;
|
||||
}
|
||||
|
||||
return $this->_render($containers, $values, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue container type scripts and styles
|
||||
*
|
||||
* All parameters are optional and will be populated with defaults
|
||||
*
|
||||
* @param string $id
|
||||
* @param array $option
|
||||
* @param array $values Options values (in db format, returned from get_value_from_input())
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
final public function enqueue_static($id = '', $option = array(), $values = array(), $data = array())
|
||||
{
|
||||
if (
|
||||
!doing_action('admin_enqueue_scripts')
|
||||
&&
|
||||
!did_action('admin_enqueue_scripts')
|
||||
) {
|
||||
/**
|
||||
* Do not wp_enqueue/register_...() because at this point not all handles has been registered
|
||||
* and maybe they are used in dependencies in handles that are going to be enqueued.
|
||||
* So as a result some handles will not be equeued because of not registered dependecies.
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->static_enqueued) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->prepare($id, $option, $data);
|
||||
|
||||
$call_next_time = $this->_enqueue_static($id, $option, $values, $data);
|
||||
|
||||
$this->static_enqueued = !$call_next_time;
|
||||
|
||||
return $call_next_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default option array
|
||||
*
|
||||
* @return array
|
||||
* 'type' => '...'
|
||||
* 'title' => '...'
|
||||
* 'attr' => array(...)
|
||||
*/
|
||||
final public function get_defaults()
|
||||
{
|
||||
$option = $this->_get_defaults();
|
||||
|
||||
$option['type'] = $this->get_type();
|
||||
|
||||
return $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to register a new container type
|
||||
* @param string|FW_Container_Type $container_type_class
|
||||
*/
|
||||
final public static function register($container_type_class) {
|
||||
static $registration_access_key = null;
|
||||
|
||||
if ($registration_access_key === null) {
|
||||
$registration_access_key = new FW_Access_Key('fw_container_type');
|
||||
}
|
||||
|
||||
fw()->backend->_register_container_type($registration_access_key, $container_type_class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,515 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* All framework extensions should extend this
|
||||
*/
|
||||
abstract class FW_Extension
|
||||
{
|
||||
/**
|
||||
* Called after all extensions instances was created
|
||||
* @internal
|
||||
*/
|
||||
abstract protected function _init();
|
||||
|
||||
/** @var FW_Extension_Manifest */
|
||||
public $manifest;
|
||||
|
||||
/** @var string Key used in FW_Cache to store data about extensions */
|
||||
private static $cache_key = 'fw_ext';
|
||||
|
||||
/** @var FW_Access_Key */
|
||||
private static $access_key;
|
||||
|
||||
/**
|
||||
* Extension name, equal to directory name
|
||||
* @var string
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* Parent extension instance
|
||||
* @var FW_Extension|null
|
||||
*/
|
||||
private $parent;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $rel_path;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $path;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $uri;
|
||||
|
||||
/**
|
||||
* On what directory depth is the extension
|
||||
*
|
||||
* 1 - Root extension
|
||||
* 2 - Their children
|
||||
* 3 - Sub children
|
||||
* ...
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $depth;
|
||||
|
||||
/**
|
||||
* Locations where the extension can look for customizations (overwrite views, options; extend config)
|
||||
* @var array {'/path' => 'https://uri.to/path'}
|
||||
*/
|
||||
private $customizations_locations;
|
||||
|
||||
final public function __construct($data)
|
||||
{
|
||||
if (!self::$access_key) {
|
||||
self::$access_key = new FW_Access_Key('extension');
|
||||
}
|
||||
|
||||
$this->rel_path = $data['rel_path'];
|
||||
$this->path = $data['path'];
|
||||
$this->uri = $data['uri'];
|
||||
$this->parent = $data['parent'];
|
||||
$this->depth = $data['depth'];
|
||||
$this->customizations_locations = $data['customizations_locations'];
|
||||
$this->manifest = _FW_Component_Extensions::_get_manifest($this->get_name(), self::$access_key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache key for this extension
|
||||
*
|
||||
* Usage:
|
||||
* FW_Cache::get( $this->get_cache_key('/some/key') )
|
||||
*
|
||||
* @param string $sub_key
|
||||
* @return string
|
||||
*/
|
||||
final public function get_cache_key($sub_key = '')
|
||||
{
|
||||
return self::$cache_key .'/'. $this->get_name() . $sub_key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name View file name (without .php) from <extension>/views directory
|
||||
* @param array $view_variables Keys will be variables names within view
|
||||
* @param bool $return In some cases, for memory saving reasons, you can disable the use of output buffering
|
||||
* @return string HTML
|
||||
*/
|
||||
final protected function render_view($name, $view_variables = array(), $return = true)
|
||||
{
|
||||
$full_path = $this->locate_path('/views/'. $name .'.php');
|
||||
|
||||
if (!$full_path) {
|
||||
trigger_error('Extension view not found: '. $name, E_USER_WARNING);
|
||||
return;
|
||||
}
|
||||
|
||||
return fw_render_view($full_path, $view_variables, $return);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @param FW_Access_Key $access_key
|
||||
* @return mixed
|
||||
*/
|
||||
final public function _call_init($access_key)
|
||||
{
|
||||
if ($access_key->get_key() !== 'fw_extensions') {
|
||||
trigger_error(__METHOD__ .' denied', E_USER_ERROR);
|
||||
}
|
||||
|
||||
return $this->_init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tree array with all sub extensions
|
||||
* @return array
|
||||
*/
|
||||
final public function get_tree()
|
||||
{
|
||||
return fw()->extensions->_get_extension_tree(self::$access_key, $this->get_name());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $rel_path '/views/test.php'
|
||||
* @return false|string '/var/www/.../extensions/<extension>/views/test.php'
|
||||
*/
|
||||
final public function locate_path($rel_path)
|
||||
{
|
||||
$locations = $this->customizations_locations;
|
||||
$locations[$this->get_path()] = $this->get_uri();
|
||||
|
||||
foreach ($locations as $path => $uri) {
|
||||
if (file_exists($path . $rel_path)) {
|
||||
return $path . $rel_path;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $rel_path E.g. '/static/js/scripts.js'
|
||||
* @return string URI E.g. 'http: //wordpress.com/.../extensions/<extension>/static/js/scripts.js'
|
||||
*/
|
||||
final public function locate_URI($rel_path)
|
||||
{
|
||||
$locations = $this->customizations_locations;
|
||||
$locations[$this->get_path()] = $this->get_uri();
|
||||
|
||||
foreach ($locations as $path => $uri) {
|
||||
if (file_exists($path . $rel_path)) {
|
||||
return $uri . $rel_path;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FW_Extension|null if has no parent extension
|
||||
*/
|
||||
final public function get_parent()
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
final public function get_name()
|
||||
{
|
||||
if ($this->name === null) {
|
||||
$this->name = basename($this->path);
|
||||
}
|
||||
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @deprecated
|
||||
*/
|
||||
final public function get_declared_source()
|
||||
{
|
||||
return 'deprecated';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $append_rel_path E.g. '/includes/something.php'
|
||||
* @return string
|
||||
* @deprecated
|
||||
*/
|
||||
final public function get_declared_path($append_rel_path = '')
|
||||
{
|
||||
return $this->get_path($append_rel_path);
|
||||
}
|
||||
|
||||
final public function get_path($append_rel_path = '')
|
||||
{
|
||||
return $this->path . $append_rel_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $append_rel_path E.g. '/includes/foo/bar/script.js'
|
||||
* @return string
|
||||
* @deprecated
|
||||
*/
|
||||
final public function get_declared_URI($append_rel_path = '')
|
||||
{
|
||||
return $this->get_uri($append_rel_path);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $append_rel_path E.g. '/includes/foo/bar/script.js'
|
||||
* @return string
|
||||
*/
|
||||
final public function get_uri($append_rel_path = '')
|
||||
{
|
||||
return $this->uri . $append_rel_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $child_extension_name
|
||||
* @return FW_Extension|null
|
||||
*/
|
||||
final public function get_child($child_extension_name)
|
||||
{
|
||||
$active_tree = $this->get_tree();
|
||||
|
||||
if (isset($active_tree[$child_extension_name])) {
|
||||
return fw()->extensions->get($child_extension_name);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all child extensions
|
||||
* Only one level, not all sub levels
|
||||
* @return FW_Extension[]
|
||||
*/
|
||||
final public function get_children()
|
||||
{
|
||||
$active_tree = $this->get_tree();
|
||||
|
||||
$result = array();
|
||||
|
||||
foreach ($active_tree as $extension_name => &$sub_extensions) {
|
||||
$result[$extension_name] = fw()->extensions->get($extension_name);
|
||||
}
|
||||
unset($sub_extensions);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return config key value, or entire config array
|
||||
* Config array is merged from child configs
|
||||
* @param string|null $key Multi key format accepted: 'a/b/c'
|
||||
* @return mixed|null
|
||||
*/
|
||||
final public function get_config($key = null)
|
||||
{
|
||||
$cache_key = $this->get_cache_key() .'/config';
|
||||
|
||||
try {
|
||||
$config = FW_Cache::get($cache_key);
|
||||
} catch (FW_Cache_Not_Found_Exception $e) {
|
||||
$config = array();
|
||||
|
||||
$locations = $this->customizations_locations;
|
||||
$locations[$this->get_path()] = $this->get_uri();
|
||||
|
||||
foreach (array_reverse($locations) as $path => $uri) {
|
||||
$config_path = $path .'/config.php';
|
||||
|
||||
if (file_exists($config_path)) {
|
||||
$variables = fw_get_variables_from_file($config_path, array('cfg' => null));
|
||||
|
||||
if (!empty($variables['cfg'])) {
|
||||
$config = array_merge($config, $variables['cfg']);
|
||||
unset($variables);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FW_Cache::set($cache_key, $config);
|
||||
}
|
||||
|
||||
return $key === null ? $config : fw_call( fw_akg( $key, $config ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return array with options from specified name/path
|
||||
* @param string $name Examples: 'framework', 'posts/portfolio'
|
||||
* @param array $variables These will be available in options file (like variables for view)
|
||||
* @return array
|
||||
*/
|
||||
final public function get_options($name, array $variables = array())
|
||||
{
|
||||
try {
|
||||
return FW_Cache::get($cache_key = $this->get_cache_key('/options/'. $name));
|
||||
} catch (FW_Cache_Not_Found_Exception $e) {
|
||||
if ($path = $this->locate_path('/options/'. $name .'.php')) {
|
||||
$variables = fw_get_variables_from_file($path, array('options' => array()), $variables);
|
||||
} else {
|
||||
$variables = array('options' => array());
|
||||
}
|
||||
|
||||
FW_Cache::set($cache_key, $variables['options']);
|
||||
|
||||
return $variables['options'];
|
||||
}
|
||||
}
|
||||
|
||||
final public function get_settings_options()
|
||||
{
|
||||
try {
|
||||
return FW_Cache::get($cache_key = $this->get_cache_key('/settings_options'));
|
||||
} catch (FW_Cache_Not_Found_Exception $e) {
|
||||
if (file_exists($path = $this->get_path('/settings-options.php'))) {
|
||||
$variables = fw_get_variables_from_file($path, array('options' => array()));
|
||||
} else {
|
||||
$variables = array('options' => array());
|
||||
}
|
||||
|
||||
FW_Cache::set($cache_key, $variables['options']);
|
||||
|
||||
return $variables['options'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.6.9
|
||||
*/
|
||||
final public function get_rendered_docs() {
|
||||
$docs_path = $this->get_path('/readme.md.php');
|
||||
|
||||
if (! file_exists($docs_path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return fw()->backend->get_markdown_parser()->text(
|
||||
/**
|
||||
* TODO: Perhaps send here some values in order to make extension docs
|
||||
* more dynamic???
|
||||
*/
|
||||
fw_render_view($docs_path, array())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extension's settings option value from the database
|
||||
*
|
||||
* @param string|null $option_id
|
||||
* @param null|mixed $default_value If no option found in the database, this value will be returned
|
||||
* @param null|bool $get_original_value REMOVED https://github.com/ThemeFuse/Unyson/issues/1676
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
final public function get_db_settings_option( $option_id = null, $default_value = null, $get_original_value = null ) {
|
||||
|
||||
return fw_get_db_ext_settings_option( $this->get_name(), $option_id, $default_value, $get_original_value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set extension's setting option value in database
|
||||
*
|
||||
* @param string|null $option_id
|
||||
* @param mixed $value
|
||||
*/
|
||||
final public function set_db_settings_option( $option_id = null, $value ) {
|
||||
fw_set_db_ext_settings_option( $this->get_name(), $option_id, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extension's data from the database
|
||||
*
|
||||
* @param string|null $multi_key The key of the data you want to get. null - all data
|
||||
* @param null|mixed $default_value If no option found in the database, this value will be returned
|
||||
* @param null|bool $get_original_value REMOVED https://github.com/ThemeFuse/Unyson/issues/1676
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
final public function get_db_data( $multi_key = null, $default_value = null, $get_original_value = null ) {
|
||||
return fw_get_db_extension_data( $this->get_name(), $multi_key, $default_value, $get_original_value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set some extension's data in database
|
||||
*
|
||||
* @param string|null $multi_key The key of the data you want to set. null - all data
|
||||
* @param mixed $value
|
||||
*/
|
||||
final public function set_db_data( $multi_key = null, $value ) {
|
||||
fw_set_db_extension_data( $this->get_name(), $multi_key, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extension's data from user meta
|
||||
*
|
||||
* @param int $user_id
|
||||
* @param string|null $keys
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
final public function get_user_data( $user_id, $keys = null ) {
|
||||
return fw_get_db_extension_user_data($user_id, $this->get_name(), $keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* et some extension's data in user meta
|
||||
*
|
||||
* @param int $user_id
|
||||
* @param mixed $value
|
||||
* @param string|null $keys
|
||||
*
|
||||
* @return bool|int
|
||||
*/
|
||||
final public function set_user_data( $user_id, $value, $keys = null ) {
|
||||
return fw_set_db_extension_user_data($user_id, $this->get_name(), $value, $keys);
|
||||
}
|
||||
|
||||
final public function get_post_options($post_type)
|
||||
{
|
||||
return $this->get_options('posts/'. $post_type);
|
||||
}
|
||||
|
||||
final public function get_taxonomy_options($taxonomy)
|
||||
{
|
||||
return $this->get_options('taxonomies/'. $taxonomy);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name File name without extension, located in <extension>/static/js/$name.js
|
||||
* @return string URI
|
||||
*/
|
||||
final public function locate_js_URI($name)
|
||||
{
|
||||
return $this->locate_URI('/static/js/'. $name .'.js');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name File name without extension, located in <extension>/static/js/$name.js
|
||||
* @return string URI
|
||||
*/
|
||||
final public function locate_css_URI($name)
|
||||
{
|
||||
return $this->locate_URI('/static/css/'. $name .'.css');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name File name without extension, located in <extension>/views/$name.php
|
||||
* @return false|string
|
||||
*/
|
||||
final public function locate_view_path($name)
|
||||
{
|
||||
return $this->locate_path('/views/'. $name .'.php');
|
||||
}
|
||||
|
||||
final public function get_depth()
|
||||
{
|
||||
return $this->depth;
|
||||
}
|
||||
|
||||
final public function get_customizations_locations()
|
||||
{
|
||||
return $this->customizations_locations;
|
||||
}
|
||||
|
||||
final public function get_rel_path()
|
||||
{
|
||||
return $this->rel_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if child extension is valid
|
||||
*
|
||||
* Used for special cases when an extension requires its child extensions to extend some special class
|
||||
*
|
||||
* @param FW_Extension $child_extension_instance
|
||||
* @return bool
|
||||
* @internal
|
||||
*/
|
||||
public function _child_extension_is_valid($child_extension_instance)
|
||||
{
|
||||
return is_subclass_of($child_extension_instance, 'FW_Extension');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get link to the page created by this extension in dashboard
|
||||
* (Used on the extensions page)
|
||||
* @internal
|
||||
* @return string
|
||||
*/
|
||||
public function _get_link()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,465 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* Backend option
|
||||
*/
|
||||
abstract class FW_Option_Type
|
||||
{
|
||||
/**
|
||||
* @var FW_Access_Key
|
||||
*/
|
||||
private static $access_key;
|
||||
|
||||
/**
|
||||
* Option's unique type, used in option array in 'type' key
|
||||
* @return string
|
||||
*/
|
||||
abstract public function get_type();
|
||||
|
||||
/**
|
||||
* Overwrite this method to enqueue scripts and styles
|
||||
*
|
||||
* This method would be abstract but was added after the framework release,
|
||||
* and to prevent fatal errors from new option types created by users we can't make it abstract.
|
||||
*
|
||||
* @param string $id
|
||||
* @param array $option
|
||||
* @param array $data
|
||||
* @param bool Return true to call this method again on the next enqueue,
|
||||
* if you have some functionality in it that depends on option parameters.
|
||||
* By default this method is called only once for performance reasons.
|
||||
*/
|
||||
protected function _enqueue_static($id, $option, $data) {}
|
||||
|
||||
/**
|
||||
* Generate html
|
||||
* @param string $id
|
||||
* @param array $option Option array merged with _get_defaults()
|
||||
* @param array $data {value => _get_value_from_input(), id_prefix => ..., name_prefix => ...}
|
||||
* @return string HTML
|
||||
* @internal
|
||||
*/
|
||||
abstract protected function _render($id, $option, $data);
|
||||
|
||||
/**
|
||||
* Extract correct value that will be stored in db or $option['value'] from raw form input value
|
||||
* If input value is empty, will be returned $option['value']
|
||||
* This method should be named get_db_value($form_input_value, $option)
|
||||
* @param array $option Option array merged with _get_defaults()
|
||||
* @param array|string|null $input_value
|
||||
* @return string|array|int|bool Correct value
|
||||
* @internal
|
||||
*/
|
||||
abstract protected function _get_value_from_input($option, $input_value);
|
||||
|
||||
/**
|
||||
* Default option array
|
||||
*
|
||||
* This makes possible an option array to have required only one parameter: array('type' => '...')
|
||||
* Other parameters are merged with the array returned by this method.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* array(
|
||||
* 'value' => '',
|
||||
* ...
|
||||
* )
|
||||
* @internal
|
||||
*/
|
||||
abstract protected function _get_defaults();
|
||||
|
||||
/**
|
||||
* Put data for to be accessed in JavaScript for each option type instance
|
||||
*/
|
||||
protected function _get_data_for_js($id, $option, $data = array()) {
|
||||
return array(
|
||||
'option' => $option
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* An option type can decide which design to use by default when rendering
|
||||
* itself.
|
||||
*
|
||||
* @return
|
||||
* null - will use whatever is passed based on the context
|
||||
* string - will use that particular design
|
||||
*/
|
||||
public function get_forced_render_design() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent execute enqueue multiple times
|
||||
* @var bool
|
||||
*/
|
||||
private $static_enqueued = false;
|
||||
|
||||
/**
|
||||
* Used as prefix for attribute id="{prefix}{option-id}"
|
||||
* @return string
|
||||
*/
|
||||
final public static function get_default_id_prefix()
|
||||
{
|
||||
return fw()->backend->get_options_id_attr_prefix();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used as default prefix for attribute name="prefix[name]"
|
||||
* Cannot contain [], it is used for $_POST[ self::get_default_name_prefix() ]
|
||||
* @return string
|
||||
*/
|
||||
final public static function get_default_name_prefix()
|
||||
{
|
||||
return fw()->backend->get_options_name_attr_prefix();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FW_Access_Key $access_key
|
||||
* @internal
|
||||
* This must be called right after an instance of option type has been created
|
||||
* and was added to the registered array, so it is available through
|
||||
* fw()->backend->option_type($this->get_type())
|
||||
*/
|
||||
final public function _call_init($access_key)
|
||||
{
|
||||
if ($access_key->get_key() !== 'fw_backend') {
|
||||
trigger_error('Method call not allowed', E_USER_ERROR);
|
||||
}
|
||||
|
||||
if (method_exists($this, '_init')) {
|
||||
$this->_init();
|
||||
}
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fixes and prepare defaults
|
||||
*
|
||||
* @param string $id
|
||||
* @param array $option
|
||||
* @param array $data
|
||||
* @return array
|
||||
*
|
||||
* @since 2.5.10
|
||||
*/
|
||||
public function prepare(&$id, &$option, &$data)
|
||||
{
|
||||
$data = array_merge(
|
||||
array(
|
||||
'id_prefix' => self::get_default_id_prefix(), // attribute id prefix
|
||||
'name_prefix' => self::get_default_name_prefix(), // attribute name prefix
|
||||
),
|
||||
$data
|
||||
);
|
||||
|
||||
$defaults = $this->get_defaults();
|
||||
$merge_attr = !empty($option['attr']) && !empty($defaults['attr']);
|
||||
|
||||
$option = array_merge($defaults, $option, array(
|
||||
'type' => $this->get_type()
|
||||
));
|
||||
|
||||
if ($merge_attr) {
|
||||
$option['attr'] = array_merge($defaults['attr'], $option['attr']);
|
||||
}
|
||||
|
||||
if (!isset($data['value'])) {
|
||||
// if no input value, use default
|
||||
$data['value'] = $option['value'];
|
||||
}
|
||||
|
||||
if (!isset($option['attr'])) {
|
||||
$option['attr'] = array();
|
||||
}
|
||||
|
||||
$option['attr']['name'] = $data['name_prefix'] .'['. $id .']';
|
||||
$option['attr']['id'] = $data['id_prefix'] . $id;
|
||||
$option['attr']['class'] = 'fw-option fw-option-type-'. $option['type'] .(
|
||||
isset($option['attr']['class'])
|
||||
? ' '. $option['attr']['class']
|
||||
: ''
|
||||
);
|
||||
$option['attr']['value'] = is_array($option['value']) ? '' : $option['value'];
|
||||
|
||||
/**
|
||||
* Remove some blacklisted attributes
|
||||
* They should be added only by the render method
|
||||
*/
|
||||
{
|
||||
unset($option['attr']['type']);
|
||||
unset($option['attr']['checked']);
|
||||
unset($option['attr']['selected']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate option's html from option array
|
||||
* @param string $id
|
||||
* @param array $option
|
||||
* @param array $data {value => $this->get_value_from_input()}
|
||||
* @return string HTML
|
||||
*/
|
||||
final public function render($id, $option, $data = array())
|
||||
{
|
||||
$this->prepare($id, $option, $data);
|
||||
|
||||
$this->enqueue_static($id, $option, $data);
|
||||
|
||||
$html_attributes = array(
|
||||
'class' => 'fw-backend-option-descriptor',
|
||||
'data-fw-option-id' => $id,
|
||||
'data-fw-option-type' => $option['type']
|
||||
);
|
||||
|
||||
$data_for_js = $this->_get_data_for_js($id, $option, $data);
|
||||
|
||||
if ($data_for_js) {
|
||||
$html_attributes['data-fw-for-js'] = json_encode($data_for_js);
|
||||
}
|
||||
|
||||
return fw_html_tag(
|
||||
'div',
|
||||
$html_attributes,
|
||||
$this->_render( $id, $this->load_callbacks( $option ), $data )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue option type scripts and styles
|
||||
*
|
||||
* All parameters are optional and will be populated with defaults
|
||||
* @param string $id
|
||||
* @param array $option
|
||||
* @param array $data
|
||||
* @return bool
|
||||
*/
|
||||
final public function enqueue_static($id = '', $option = array(), $data = array())
|
||||
{
|
||||
if ($this->static_enqueued) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
!doing_action('admin_enqueue_scripts')
|
||||
&&
|
||||
!did_action('admin_enqueue_scripts')
|
||||
) {
|
||||
/**
|
||||
* Do not wp_enqueue/register_...() because at this point not all handles has been registered
|
||||
* and maybe they are used in dependencies in handles that are going to be enqueued.
|
||||
* So as a result some handles will not be equeued because of not registered dependecies.
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
static $option_types_static_enqueued = false;
|
||||
|
||||
if (!$option_types_static_enqueued) {
|
||||
wp_enqueue_style(
|
||||
'fw-option-types',
|
||||
fw_get_framework_directory_uri('/static/css/option-types.css'),
|
||||
array('fw', 'qtip'),
|
||||
fw()->manifest->get_version()
|
||||
);
|
||||
wp_enqueue_script(
|
||||
'fw-option-types',
|
||||
fw_get_framework_directory_uri('/static/js/option-types.js'),
|
||||
array('fw-events', 'qtip', 'fw-reactive-options'),
|
||||
fw()->manifest->get_version(),
|
||||
true
|
||||
);
|
||||
|
||||
$option_types_static_enqueued = true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->prepare($id, $option, $data);
|
||||
|
||||
$call_next_time = $this->_enqueue_static($id, $option, $data);
|
||||
|
||||
$this->static_enqueued = !$call_next_time;
|
||||
|
||||
return $call_next_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract correct value that will be stored in db or $option['value'] from raw form input value
|
||||
* If input value is empty, will be returned $option['value']
|
||||
* This method should be named get_db_value($form_input_value, $option)
|
||||
* @param array $option
|
||||
* @param mixed|null $input_value Option's value from $_POST or elsewhere. If is null, it means it does not exists
|
||||
* @return array|string
|
||||
*/
|
||||
final public function get_value_from_input($option, $input_value)
|
||||
{
|
||||
$option = array_merge(
|
||||
$this->get_defaults(),
|
||||
$option,
|
||||
array(
|
||||
'type' => $this->get_type()
|
||||
)
|
||||
);
|
||||
|
||||
return $this->_get_value_from_input( $this->load_callbacks( $option ), $input_value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default option array
|
||||
*
|
||||
* This makes possible an option array to have required only one parameter: array('type' => '...')
|
||||
* Other parameters are merged with array returned from this method
|
||||
*
|
||||
* @param string Multikey. Since 2.6.9
|
||||
* @return array
|
||||
*/
|
||||
final public function get_defaults($key = null)
|
||||
{
|
||||
$option = $this->_get_defaults();
|
||||
|
||||
$option['type'] = $this->get_type();
|
||||
|
||||
if (!array_key_exists('value', $option)) {
|
||||
FW_Flash_Messages::add(
|
||||
'fw-option-type-no-default-value',
|
||||
sprintf(__('Option type %s has no default value', 'fw'), $this->get_type()),
|
||||
'warning'
|
||||
);
|
||||
|
||||
$option['value'] = array();
|
||||
}
|
||||
|
||||
return is_string($key) ? fw_akg($key, $option) : $option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exist 3 types of options widths:
|
||||
* - auto (float left real width of the option (minimal) )
|
||||
* - fixed (inputs, select, textarea, and others - they have same width)
|
||||
* - full (100% . eg. html option should expand to maximum width)
|
||||
* Options can override this method to return another value
|
||||
* @return bool
|
||||
* @internal
|
||||
*/
|
||||
public function _get_backend_width_type()
|
||||
{
|
||||
return 'fixed';
|
||||
}
|
||||
|
||||
/**
|
||||
* a general purpose 'label' => false | true from options.php
|
||||
* @return bool | string
|
||||
*
|
||||
* @since 2.7.1
|
||||
*/
|
||||
public function _default_label($id, $option) {
|
||||
return fw_id_to_title($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to register a new option type
|
||||
*
|
||||
* @param string|FW_Option_Type $option_type_class
|
||||
*/
|
||||
final public static function register( $option_type_class, $type = null ) {
|
||||
fw()->backend->_register_option_type( self::get_access_key(), $option_type_class, $type );
|
||||
}
|
||||
|
||||
/**
|
||||
* If the option is composed of more options (added by user) which values are stored in database
|
||||
* the option must call fw_db_option_storage_load() for each sub-option
|
||||
* because some of them may have configured the save to be done in separate place (post meta, wp option, etc.)
|
||||
* @param string $id
|
||||
* @param array $option
|
||||
* @param mixed $value
|
||||
* @param array $params
|
||||
* @return mixed
|
||||
* @since 2.5.0
|
||||
*/
|
||||
final public function storage_load($id, array $option, $value, array $params = array()) {
|
||||
if ( // do not check !empty($option['fw-storage']) because this param can be set in option defaults
|
||||
$this->get_type() === $option['type']
|
||||
&&
|
||||
($option = array_merge($this->get_defaults(), $option))
|
||||
) {
|
||||
if (is_null($value)) {
|
||||
$value = fw()->backend->option_type($option['type'])->get_value_from_input($option, $value);
|
||||
}
|
||||
|
||||
return $this->_storage_load($id, $option, $value, $params);
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see storage_load()
|
||||
* @param string $id
|
||||
* @param array $option
|
||||
* @param mixed $value
|
||||
* @param array $params
|
||||
* @return mixed
|
||||
* @since 2.5.0
|
||||
* @internal
|
||||
*/
|
||||
protected function _storage_load($id, array $option, $value, array $params) {
|
||||
return fw_db_option_storage_load($id, $option, $value, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the option is composed of more options (added by user) which values are stored in database
|
||||
* the option must call fw_db_option_storage_save() for each sub-option
|
||||
* because some of them may have configured the save to be done in separate place (post meta, wp option, etc.)
|
||||
* @param string $id
|
||||
* @param array $option
|
||||
* @param mixed $value
|
||||
* @param array $params
|
||||
* @return mixed
|
||||
* @since 2.5.0
|
||||
*/
|
||||
final public function storage_save($id, array $option, $value, array $params = array()) {
|
||||
if ( // do not check !empty($option['fw-storage']) because this param can be set in option defaults
|
||||
$this->get_type() === $option['type']
|
||||
&&
|
||||
($option = array_merge($this->get_defaults(), $option))
|
||||
) {
|
||||
return $this->_storage_save($id, $option, $value, $params);
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see storage_save()
|
||||
* @param string $id
|
||||
* @param array $option
|
||||
* @param mixed $value
|
||||
* @param array $params
|
||||
* @return mixed
|
||||
* @since 2.5.0
|
||||
* @internal
|
||||
*/
|
||||
protected function _storage_save($id, array $option, $value, array $params) {
|
||||
return fw_db_option_storage_save($id, $option, $value, $params);
|
||||
}
|
||||
|
||||
private static function get_access_key() {
|
||||
if ( self::$access_key === null ) {
|
||||
self::$access_key = new FW_Access_Key( 'fw_option_type' );
|
||||
}
|
||||
|
||||
return self::$access_key;
|
||||
}
|
||||
|
||||
protected function load_callbacks( $data ) {
|
||||
if ( ! is_array( $data ) ) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
return array_map( 'fw_call', $data );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* @deprecated since 2.5.0
|
||||
* Will be removed soon https://github.com/ThemeFuse/Unyson/issues/1937
|
||||
*/
|
||||
interface FW_Option_Handler
|
||||
{
|
||||
function get_option_value($option_id, $option, $data = array());
|
||||
|
||||
function save_option_value($option_id, $option, $value, $data = array());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,679 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
class FW_Extension_Backups extends FW_Extension {
|
||||
/**
|
||||
* @var _FW_Ext_Backups_Module_Tasks
|
||||
*/
|
||||
private $tasks;
|
||||
|
||||
/**
|
||||
* @return _FW_Ext_Backups_Module_Tasks
|
||||
*/
|
||||
public function tasks() {
|
||||
return $this->tasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var _FW_Ext_Backups_Module_Schedule
|
||||
*/
|
||||
private $schedule;
|
||||
|
||||
/**
|
||||
* @return _FW_Ext_Backups_Module_Schedule
|
||||
*/
|
||||
public function schedule() {
|
||||
return $this->schedule;
|
||||
}
|
||||
|
||||
private static $wp_ajax_action_status = 'fw:ext:backups:status';
|
||||
private static $wp_ajax_action_backup = 'fw:ext:backups:backup';
|
||||
private static $wp_ajax_action_restore = 'fw:ext:backups:restore';
|
||||
private static $wp_ajax_action_delete = 'fw:ext:backups:delete';
|
||||
private static $wp_ajax_action_cancel = 'fw:ext:backups:cancel';
|
||||
|
||||
private static $wp_ajax_action_test = 'fw:ext:backups:test';
|
||||
|
||||
private static $download_GET_parameter = 'download-archive';
|
||||
|
||||
/**
|
||||
* Also can be used as "is current user allowed to make backups?"
|
||||
* @return string
|
||||
*/
|
||||
public function get_capability() {
|
||||
/**
|
||||
* https://codex.wordpress.org/Roles_and_Capabilities#Capability_vs._Role_Table
|
||||
* Should work on both single and multi-site
|
||||
*/
|
||||
return 'export';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $sum Since 2.0.16
|
||||
* @return int
|
||||
*/
|
||||
public function get_timeout($sum = 0) {
|
||||
$timeout = (int)ini_get('max_execution_time');
|
||||
|
||||
/**
|
||||
* Fix timeout value
|
||||
* For e.g. timeout 0 messes up the tasks execution verification logic
|
||||
*/
|
||||
if ($timeout < 1 || $timeout > $this->get_config('max_timeout')) {
|
||||
$timeout = $this->get_config('max_timeout');
|
||||
}
|
||||
|
||||
return max($timeout + $sum, 1); // Prevent negative or 0 value
|
||||
}
|
||||
|
||||
/**
|
||||
* If a task step execution takes more that this amount of second, then perhaps it is something wrong.
|
||||
* @return int
|
||||
* @since 2.0.14
|
||||
*/
|
||||
public function get_task_step_execution_threshold() {
|
||||
return 30; // http://php.net/manual/en/info.configuration.php#ini.max-execution-time
|
||||
}
|
||||
|
||||
public function get_page_slug() {
|
||||
return 'fw-backups';
|
||||
}
|
||||
|
||||
public function get_page_url() {
|
||||
if ($this->is_disabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rel_path = 'admin.php?page=' . urlencode( $this->get_page_slug() );
|
||||
|
||||
if (is_multisite() && is_network_admin()) {
|
||||
return network_admin_url( $rel_path );
|
||||
} else {
|
||||
return admin_url( $rel_path );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* On some installations the backup actions need to be disabled for security reasons
|
||||
* (for e.g. public testlabs for clients to test your theme and demo content install)
|
||||
* @return bool
|
||||
* @since 2.0.1
|
||||
*/
|
||||
public function is_disabled() {
|
||||
$cache_key = $this->get_cache_key('/disabled');
|
||||
|
||||
try {
|
||||
return FW_Cache::get($cache_key);
|
||||
} catch (FW_Cache_Not_Found_Exception $e) {
|
||||
$is_disabled = (
|
||||
is_multisite() && !current_user_can('manage_network_plugins') &&
|
||||
apply_filters('fw:ext:backups:multisite_disabled', false)
|
||||
);
|
||||
|
||||
FW_Cache::set($cache_key, $is_disabled);
|
||||
|
||||
return $is_disabled;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.22
|
||||
* @return string Error message
|
||||
*/
|
||||
public function server_requirements_not_met() {
|
||||
if (class_exists('ZipArchive')) {
|
||||
return false;
|
||||
} else {
|
||||
return sprintf(
|
||||
__('Oops, %s requires %s but it is not enabled on your server. If you are not familiar with PHP Zip module, please contact your hosting provider.', 'fw'),
|
||||
fw_html_tag('a', array(
|
||||
'href' => function_exists('menu_page_url')
|
||||
? menu_page_url(fw()->extensions->manager->get_page_slug(), false) .'#ext-backups'
|
||||
: '#',
|
||||
), __('Unyson Backup', 'fw')),
|
||||
fw_html_tag('a', array(
|
||||
'href' => 'https://www.google.com/search#q=hosting+enable+php+zip',
|
||||
'target' => '_blank',
|
||||
), __('PHP Zip module', 'fw'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function _init() {
|
||||
|
||||
if ( is_admin() && isset( $_SERVER['SERVER_SOFTWARE'] ) && strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) !== false ) {
|
||||
if ( ! is_file( ABSPATH . '.htaccess' ) || ! preg_match( '/noabort/i', file_get_contents( ABSPATH . '.htaccess' ) ) ) {
|
||||
add_action( 'admin_notices', array( $this, '_action_admin_notices_litespeed' ) );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
if (!$this->is_disabled()) {
|
||||
add_action('admin_menu', array($this, '_action_admin_menu'));
|
||||
add_action('current_screen', array($this, '_action_download'));
|
||||
add_action('admin_enqueue_scripts', array($this, '_action_enqueue_scripts'));
|
||||
|
||||
add_action('wp_ajax_' . self::$wp_ajax_action_status, array($this, '_action_ajax_status'));
|
||||
add_action('wp_ajax_' . self::$wp_ajax_action_backup, array($this, '_action_ajax_backup'));
|
||||
add_action('wp_ajax_' . self::$wp_ajax_action_restore, array($this, '_action_ajax_restore'));
|
||||
add_action('wp_ajax_' . self::$wp_ajax_action_delete, array($this, '_action_ajax_delete'));
|
||||
add_action('wp_ajax_' . self::$wp_ajax_action_cancel, array($this, '_action_ajax_cancel'));
|
||||
}
|
||||
|
||||
add_action('network_admin_menu', array($this, '_action_admin_menu'));
|
||||
add_action('wp_ajax_nopriv_' . self::$wp_ajax_action_test, array($this, '_action_ajax_test'));
|
||||
}
|
||||
|
||||
$dir = dirname(__FILE__);
|
||||
|
||||
// load and init modules/parts
|
||||
{
|
||||
require_once $dir .'/includes/module/class--fw-ext-backups-module.php';
|
||||
|
||||
require_once $dir .'/includes/module/tasks/class--fw-ext-backups-module-tasks.php';
|
||||
$this->tasks = new _FW_Ext_Backups_Module_Tasks(self::get_access_key());
|
||||
|
||||
require_once $dir .'/includes/module/schedule/class--fw-ext-backups-module-schedule.php';
|
||||
$this->schedule = new _FW_Ext_Backups_Module_Schedule(self::get_access_key());
|
||||
|
||||
$this->tasks->_init();
|
||||
$this->schedule->_init();
|
||||
}
|
||||
|
||||
require_once $dir .'/includes/log/init.php';
|
||||
}
|
||||
|
||||
public function _action_admin_notices_litespeed() {
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
if ( ! $this->is_backups_page() && 'tools_page_fw-backups-demo-content' !== $screen->id ) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo
|
||||
'<div class="notice notice-warning">
|
||||
<p><strong>Unyson: </strong>' .
|
||||
sprintf(
|
||||
esc_html__( 'Your website is hosted using the LiteSpeed web server. Please consult this %sarticle%s if you have problems backing up.', 'fw' ),
|
||||
'<a href="http://manual.unyson.io/en/latest/extension/backups/index.html#litespeed-webserver" target="_blank">',
|
||||
'</a>'
|
||||
) .
|
||||
'</p>
|
||||
</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @var FW_Access_Key
|
||||
*/
|
||||
private static $access_key;
|
||||
|
||||
/**
|
||||
* @return FW_Access_Key
|
||||
*/
|
||||
private static function get_access_key() {
|
||||
if (empty(self::$access_key)) {
|
||||
self::$access_key = new FW_Access_Key('fw:ext:backups');
|
||||
}
|
||||
|
||||
return self::$access_key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function is_backups_page() {
|
||||
$current_screen = get_current_screen();
|
||||
|
||||
if (!$current_screen) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$cache_key = $this->get_cache_key('/is_backups_page');
|
||||
|
||||
try {
|
||||
return FW_Cache::get($cache_key);
|
||||
} catch (FW_Cache_Not_Found_Exception $e) {
|
||||
$is = false;
|
||||
|
||||
foreach (array( '_page_'. $this->get_page_slug(), '_page_'. $this->get_page_slug() .'-network' ) as $suffix) {
|
||||
if (substr($current_screen->id, -strlen($suffix)) === $suffix) {
|
||||
$is = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
FW_Cache::set($cache_key, $is);
|
||||
|
||||
return $is;
|
||||
}
|
||||
}
|
||||
|
||||
public function _action_enqueue_scripts() {
|
||||
if ($this->is_backups_page()) {
|
||||
wp_enqueue_style('fw');
|
||||
wp_enqueue_media(); // needed for modal styles
|
||||
|
||||
wp_enqueue_style(
|
||||
'fw-ext-backups',
|
||||
$this->get_uri('/static/style.css'),
|
||||
array('fw'),
|
||||
$this->manifest->get_version()
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'fw-ext-backups',
|
||||
$this->get_uri('/static/scripts.js'),
|
||||
array('fw'),
|
||||
$this->manifest->get_version()
|
||||
);
|
||||
wp_localize_script(
|
||||
'fw-ext-backups',
|
||||
'_fw_ext_backups_localized',
|
||||
array_merge(
|
||||
apply_filters('fw:ext:backups:script_localized_data', array()),
|
||||
array(
|
||||
'ajax_action_status' => self::$wp_ajax_action_status,
|
||||
'ajax_action_backup' => self::$wp_ajax_action_backup,
|
||||
'ajax_action_restore' => self::$wp_ajax_action_restore,
|
||||
'ajax_action_delete' => self::$wp_ajax_action_delete,
|
||||
'ajax_action_cancel' => self::$wp_ajax_action_cancel,
|
||||
'l10n' => array(
|
||||
'abort_confirm' => __('Are you sure?', 'fw'),
|
||||
),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
do_action('fw:ext:backups:enqueue_scripts');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _action_ajax_status() {
|
||||
if (!current_user_can($this->get_capability())) {
|
||||
wp_send_json_error(new WP_Error('denied', 'Access Denied'));
|
||||
}
|
||||
|
||||
// in case the execution chain stopped and there is a pending task
|
||||
$this->tasks()->_request_next_step_execution(self::get_access_key());
|
||||
|
||||
$is_busy = (bool)$this->tasks()->get_active_task_collection();
|
||||
$archives = $this->get_archives();
|
||||
|
||||
$response = array(
|
||||
'is_busy' => $is_busy,
|
||||
'tasks_status' => array(
|
||||
'html' => $this->render_view('tasks-status', array(
|
||||
'active_task_collection' => $this->tasks()->get_active_task_collection(),
|
||||
'executing_task' => $this->tasks()->get_executing_task(),
|
||||
'pending_tasks' => $this->tasks()->get_pending_task(),
|
||||
)),
|
||||
),
|
||||
'archives' => array(
|
||||
'count' => count($archives),
|
||||
'html' => $this->render_view('archives', array(
|
||||
'archives' => $archives,
|
||||
'is_busy' => $is_busy,
|
||||
)),
|
||||
),
|
||||
'ajax_steps' => array(
|
||||
'token' => md5(
|
||||
defined('NONCE_SALT')
|
||||
? NONCE_SALT
|
||||
: $this->manifest->get_version()
|
||||
),
|
||||
'active_tasks_hash' => (($collection = $this->tasks()->get_active_task_collection())
|
||||
? md5(serialize($collection))
|
||||
: ''
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
wp_send_json_success(array_merge(
|
||||
apply_filters('fw_ext_backups_ajax_status_extra_response', array(), array('is_busy' => $is_busy)),
|
||||
$response
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _action_ajax_backup() {
|
||||
if (!current_user_can($this->get_capability())) {
|
||||
wp_send_json_error(new WP_Error('denied', 'Access Denied'));
|
||||
}
|
||||
|
||||
$this->tasks()->do_backup(
|
||||
!empty($_POST['full'])
|
||||
&&
|
||||
fw_ext_backups_current_user_can_full()
|
||||
);
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _action_ajax_restore() {
|
||||
if (!current_user_can($this->get_capability())) {
|
||||
wp_send_json_error(new WP_Error('denied', 'Access Denied'));
|
||||
}
|
||||
|
||||
$archives = $this->get_archives();
|
||||
|
||||
if (
|
||||
empty($_POST['file'])
|
||||
||
|
||||
!isset($archives[ $filename = (string)$_POST['file'] ])
|
||||
) {
|
||||
wp_send_json_error(new WP_Error(
|
||||
'no_file', __('File not specified', 'fw')
|
||||
));
|
||||
}
|
||||
|
||||
$fs_args = array();
|
||||
|
||||
if ($archives[ $filename ]['full'] && !FW_WP_Filesystem::has_direct_access(ABSPATH)) {
|
||||
if (empty($_POST['filesystem_args'])) {
|
||||
wp_send_json_error(array(
|
||||
'message' => esc_html__('Filesystem access required', 'fw'),
|
||||
'request_fs' => true,
|
||||
));
|
||||
} else {
|
||||
$fs_args = $_POST['filesystem_args'];
|
||||
|
||||
if (
|
||||
is_array($_POST['filesystem_args']) &&
|
||||
isset($fs_args['hostname']) && is_string($fs_args['hostname']) &&
|
||||
isset($fs_args['username']) && is_string($fs_args['username']) &&
|
||||
isset($fs_args['password']) && is_string($fs_args['password']) &&
|
||||
isset($fs_args['connection_type']) && is_string($fs_args['connection_type'])
|
||||
) {
|
||||
$fs_args = array(
|
||||
'hostname' => $fs_args['hostname'],
|
||||
'username' => $fs_args['username'],
|
||||
'password' => $fs_args['password'],
|
||||
'connection_type' => $fs_args['connection_type'],
|
||||
);
|
||||
|
||||
if (!WP_Filesystem($fs_args, ABSPATH)) {
|
||||
wp_send_json_error(array(
|
||||
'message' => esc_html__('Invalid filesystem credentials', 'fw')
|
||||
));
|
||||
}
|
||||
} else {
|
||||
wp_send_json_error(array(
|
||||
'message' => esc_html__('Invalid filesystem credentials', 'fw')
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->tasks()->do_restore(
|
||||
$archives[ $filename ]['full'] && fw_ext_backups_current_user_can_full(),
|
||||
$archives[ $filename ]['path'],
|
||||
$fs_args
|
||||
);
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _action_ajax_delete() {
|
||||
if (!current_user_can($this->get_capability())) {
|
||||
wp_send_json_error(new WP_Error('denied', 'Access Denied'));
|
||||
}
|
||||
|
||||
$archives = $this->get_archives();
|
||||
|
||||
if (
|
||||
empty($_POST['file'])
|
||||
||
|
||||
!isset($archives[ $filename = (string)$_POST['file'] ])
|
||||
) {
|
||||
wp_send_json_error(new WP_Error(
|
||||
'no_file', __('File not specified', 'fw')
|
||||
));
|
||||
}
|
||||
|
||||
if (@unlink($archives[ $filename ]['path'])) {
|
||||
wp_send_json_success();
|
||||
} else {
|
||||
wp_send_json_error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _action_ajax_cancel() {
|
||||
if (!current_user_can($this->get_capability())) {
|
||||
wp_send_json_error(new WP_Error('denied', 'Access Denied'));
|
||||
}
|
||||
|
||||
if ($this->tasks()->do_cancel()) {
|
||||
wp_send_json_success();
|
||||
} else {
|
||||
wp_send_json_error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _action_admin_menu() {
|
||||
call_user_func_array(
|
||||
is_multisite() && is_network_admin() ? 'add_menu_page' : 'add_management_page',
|
||||
array(
|
||||
__( 'Backup', 'fw' ),
|
||||
__( 'Backup', 'fw' ),
|
||||
$this->get_capability(),
|
||||
$this->get_page_slug(),
|
||||
array( $this, '_render_page' )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|bool Get only full or content backups
|
||||
* @return array Descending date sorting
|
||||
*/
|
||||
public function get_archives($full = null) {
|
||||
$archives = array();
|
||||
|
||||
if ($this->server_requirements_not_met()) {
|
||||
return $archives;
|
||||
} elseif ($paths = glob($this->get_backups_dir() .'/*.zip')) {
|
||||
foreach ( $paths as $path ) {
|
||||
{
|
||||
$zip = new ZipArchive();
|
||||
|
||||
if ( true === $zip->open( $path ) ) {
|
||||
$is_full = (bool) (
|
||||
$zip->locateName( 'f/themes/index.php' ) !== false
|
||||
||
|
||||
$zip->locateName( 'f/plugins/index.php' ) !== false
|
||||
);
|
||||
|
||||
$zip->close();
|
||||
} else {
|
||||
trigger_error('Cannot open zip: '. $path, E_USER_WARNING);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
!is_null($full)
|
||||
&&
|
||||
$full != $is_full
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$archives[ basename( $path ) ] = array(
|
||||
'path' => $path,
|
||||
'full' => $is_full,
|
||||
'time' => filemtime($path),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
uasort($archives, array($this, '_archive_sort_callback'));
|
||||
|
||||
return $archives;
|
||||
}
|
||||
|
||||
public function _archive_sort_callback($a, $b) {
|
||||
if ($a['time'] == $b['time']) {
|
||||
return 0;
|
||||
} else {
|
||||
return ($a['time'] > $b['time']) ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _render_page() {
|
||||
echo '<div class="wrap">';
|
||||
|
||||
if ($error_message = $this->server_requirements_not_met()) {
|
||||
echo "<div class=\"notice notice-error\"><p>{$error_message}</p></div>";
|
||||
} else {
|
||||
$this->render_view( 'page', array(
|
||||
'archives_html' => $this->render_view( 'archives', array(
|
||||
'archives' => $this->get_archives(),
|
||||
'is_busy' => (bool) $this->tasks()->get_active_task_collection(),
|
||||
) ),
|
||||
), false );
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
echo '<div id="fw-ext-backups-filesystem-form" style="display:none;">';
|
||||
FW_WP_Filesystem::request_access(ABSPATH);
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_tmp_dir() {
|
||||
return $this->get_backups_dir() . '/tmp';
|
||||
}
|
||||
|
||||
/**
|
||||
* All backups (zip) will go in this directory
|
||||
* @return string
|
||||
*/
|
||||
public function get_backups_dir() {
|
||||
return $this->get_config( 'dirs.destination' );
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function _get_link() {
|
||||
if (current_user_can($this->get_capability())) {
|
||||
return $this->get_page_url();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _get_test_ajax_action() {
|
||||
return self::$wp_ajax_action_test;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _action_ajax_test() {
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
public function get_download_link($archive_filename) {
|
||||
return add_query_arg(self::$download_GET_parameter, urlencode($archive_filename), $this->get_page_url());
|
||||
}
|
||||
|
||||
public function _action_download() {
|
||||
if (
|
||||
!isset($_GET[self::$download_GET_parameter])
|
||||
||
|
||||
!is_string($archive_filename = $_GET[self::$download_GET_parameter])
|
||||
||
|
||||
!$this->is_backups_page()
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
$error = __('Unknown error', 'fw');
|
||||
|
||||
do {
|
||||
if (!current_user_can($this->get_capability())) {
|
||||
$error = __('Access Denied', 'fw');
|
||||
break;
|
||||
}
|
||||
|
||||
$archives = $this->get_archives();
|
||||
|
||||
if (!isset($archives[$archive_filename])) {
|
||||
$error = __('Archive not found', 'fw');
|
||||
break;
|
||||
}
|
||||
|
||||
$archive = $archives[$archive_filename];
|
||||
|
||||
if ($archive['full'] && !fw_ext_backups_current_user_can_full()) {
|
||||
$error = __('Access Denied', 'fw');
|
||||
break;
|
||||
}
|
||||
|
||||
if ($f = fopen($archive['path'], 'r')) {
|
||||
// ok
|
||||
} else {
|
||||
$error = __('Failed to open file', 'fw');
|
||||
break;
|
||||
}
|
||||
|
||||
header('Content-Type: application/zip, application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename="'. esc_attr($archive_filename) .'"');
|
||||
header('Content-length: '. filesize($archive['path']));
|
||||
header('Cache-control: private');
|
||||
|
||||
/**
|
||||
* Some files can be huge, do not load entire file in php memory then output, it can cause memory limit error
|
||||
* Read and output parts
|
||||
*/
|
||||
{
|
||||
$output_buffer_size = max(
|
||||
// https://github.com/ThemeFuse/Unyson/issues/2070#issuecomment-258427852
|
||||
(int)ini_get('output_buffering'),
|
||||
// default to this value in case ini_get() will return 0 (some server restrictions)
|
||||
// http://php.net/manual/en/outcontrol.configuration.php#ini.output-buffering
|
||||
4096
|
||||
);
|
||||
|
||||
while (!feof($f)) {
|
||||
echo fread($f, $output_buffer_size);
|
||||
if (ob_get_level()) { ob_flush(); }
|
||||
flush();
|
||||
}
|
||||
}
|
||||
|
||||
fclose($f);
|
||||
|
||||
exit;
|
||||
} while(false);
|
||||
|
||||
wp_die($error, $error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace Unyson\Extension\Backups;
|
||||
|
||||
/**
|
||||
* Unyson Backups Extension CLI Commands.
|
||||
*
|
||||
* @package wp-cli
|
||||
*/
|
||||
class Command extends \Unyson\Extension\Command {
|
||||
|
||||
/**
|
||||
* List all available backups.
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* ## EXAMPLES
|
||||
*
|
||||
* # List all backups files
|
||||
* $ wp unyson ext backups list
|
||||
* +--------------------------------------+--------------------+---------+
|
||||
* | Name | Time | Type |
|
||||
* +--------------------------------------+--------------------+---------+
|
||||
* | fw-backup-2017_03_25-05_58_28-2.0.23 | 25 Mar 2017, 05:58 | Content |
|
||||
* | fw-backup-2017_03_25-05_57_44-2.0.23 | 25 Mar 2017, 05:57 | Content |
|
||||
* | fw-backup-2017_03_25-05_55_58-2.0.23 | 25 Mar 2017, 05:55 | Content |
|
||||
* | fw-backup-2017_03_25-05_24_04-2.0.23 | 25 Mar 2017, 05:24 | Content |
|
||||
* | fw-backup-2017_03_24-18_49_46-2.0.23 | 24 Mar 2017, 18:49 | Content |
|
||||
* | fw-backup-2017_03_24-11_23_29-2.0.23 | 24 Mar 2017, 11:23 | Full |
|
||||
* | fw-backup-2017_03_24-11_23_01-2.0.23 | 24 Mar 2017, 11:23 | Full |
|
||||
* +--------------------------------------+--------------------+---------+
|
||||
*
|
||||
*
|
||||
* @param array $_
|
||||
* @param array $options
|
||||
*
|
||||
* @subcommand list
|
||||
*/
|
||||
public function _list( $_, $options = array() ) {
|
||||
$archives = array_map(
|
||||
array( $this, 'get_backup_file_data' ),
|
||||
$this->get_backups()
|
||||
);
|
||||
|
||||
\WP_CLI\Utils\format_items(
|
||||
'table',
|
||||
$archives,
|
||||
array( 'Name', 'Time', 'Type' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a backup.
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* [--full]
|
||||
* : Specify to create a full backup.
|
||||
*
|
||||
* ## EXAMPLES
|
||||
*
|
||||
* # Create content backup
|
||||
* $ wp unyson ext backups create
|
||||
* Backup successfully created
|
||||
*
|
||||
* # Create full backup
|
||||
* $ wp unyson ext backups create --full
|
||||
* Backup successfully created
|
||||
*
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $options
|
||||
*/
|
||||
public function create( $args, $options = array() ) {
|
||||
$this
|
||||
->get_ext()
|
||||
->tasks()
|
||||
->do_backup( isset( $options['full'] ) );
|
||||
|
||||
$this->message( "Backup successfully created" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore a backup.
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* <backup-id>
|
||||
* : The ID of the backup to restore. The ID is the backup file name without `.zip` extension.
|
||||
*
|
||||
*
|
||||
* ## EXAMPLES
|
||||
*
|
||||
* # Restore backup
|
||||
* $ wp unyson ext backups restore fw-backup-2017_03_25-05_58_28-2.0.23
|
||||
* Backup fw-backup-2017_03_25-05_58_28-2.0.23 was successfully restored
|
||||
*
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $options
|
||||
*/
|
||||
public function restore( $args, $options = array() ) {
|
||||
$id = array_shift( $args );
|
||||
try {
|
||||
$backup = $this->get( $id );
|
||||
} catch ( \Exception $e ) {
|
||||
$this->error( "Backup %g$id%n doesn't seem to exist" );
|
||||
}
|
||||
|
||||
$this->initialize_fs();
|
||||
$this
|
||||
->get_ext()
|
||||
->tasks()
|
||||
->do_restore( $backup['full'], $backup['path'] );
|
||||
|
||||
$this->message( "Backup %g$id%n was successfully restored" );
|
||||
}
|
||||
|
||||
protected function get_backup_file_data( array $backup ) {
|
||||
return array(
|
||||
'Name' => basename( $backup['path'], '.zip' ),
|
||||
'Type' => $backup['full'] ? 'Full' : 'Content',
|
||||
'Time' => date( 'd M Y, H:i', $backup['time'] ),
|
||||
);
|
||||
}
|
||||
|
||||
protected function get_backups() {
|
||||
return $this->get_ext()->get_archives();
|
||||
}
|
||||
|
||||
protected function get( $id ) {
|
||||
$backups = $this->get_backups();
|
||||
|
||||
if ( isset( $backups[ $id . '.zip' ] ) ) {
|
||||
return $backups[ $id . '.zip' ];
|
||||
}
|
||||
|
||||
throw new \Exception( "Backup $id cannot be found" );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
$cfg = array();
|
||||
|
||||
/**
|
||||
* WhiteList hidden files and directories
|
||||
* By default all hidden files and dirs are skipped (like .git/ .idea/)
|
||||
*/
|
||||
$cfg['included_hidden_names'] = array(
|
||||
'.htaccess' => true,
|
||||
);
|
||||
|
||||
global $wpdb; /** @var WPDB $wpdb */
|
||||
|
||||
// Note: Exclude and Keep are for content backup. On Full backup everything is exported and everything is replaced.
|
||||
|
||||
$cfg['db.backup.exclude_options'] = array(
|
||||
$wpdb->prefix .'user_roles' => true,
|
||||
'admin_email' => true,
|
||||
'cron' => true,
|
||||
'mailserver_login' => true,
|
||||
'mailserver_pass' => true,
|
||||
'mailserver_port' => true,
|
||||
'mailserver_url' => true,
|
||||
'ftp_credentials' => true,
|
||||
'use_ssl' => true,
|
||||
'WPLANG' => true,
|
||||
'recently_edited' => true, // contains full paths
|
||||
'current_theme' => true,
|
||||
// 'template' => true, 'stylesheet' => true, // used on restore to replace option names with current child theme
|
||||
);
|
||||
|
||||
$cfg['db.restore.keep_options'] = array_merge(
|
||||
$cfg['db.backup.exclude_options'],
|
||||
array(
|
||||
'home' => true,
|
||||
'siteurl' => true,
|
||||
'date_format' => true,
|
||||
'links_updated_date_format' => true,
|
||||
'time_format' => true,
|
||||
'timezone_string' => true,
|
||||
'gmt_offset' => true,
|
||||
'start_of_week' => true,
|
||||
// 'permalink_structure' => true, // imported links with different structure will be 404 if current structure will be kept
|
||||
'rewrite_rules' => true,
|
||||
'ping_sites' => true,
|
||||
'upload_path' => true,
|
||||
'upload_url_path' => true,
|
||||
'uploads_use_yearmonth_folders' => true,
|
||||
'users_can_register' => true,
|
||||
'use_smilies' => true,
|
||||
'use_trackback' => true,
|
||||
'blogname' => true,
|
||||
'blogdescription' => true,
|
||||
'blog_charset' => true,
|
||||
'active_plugins' => true,
|
||||
'uninstall_plugins' => true,
|
||||
'recently_activated' => true,
|
||||
'moderation_notify' => true,
|
||||
'blacklist_keys' => true,
|
||||
'comment_registration' => true,
|
||||
'default_role' => true,
|
||||
'blog_public' => true,
|
||||
'can_compress_scripts' => true,
|
||||
'template' => true, 'stylesheet' => true, // keep current theme active
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Automatic backups will be scheduled to run at this hour
|
||||
* Format: 0...23
|
||||
*/
|
||||
$cfg['schedule.hour'] = 3;
|
||||
|
||||
/**
|
||||
* The tasks that can't be executed in steps (for e.g. zip)
|
||||
* will use this value to try to increase php's default timeout
|
||||
*/
|
||||
$cfg['max_timeout'] = 60 * 10;
|
||||
|
||||
/**
|
||||
* Destination directory for backups archives
|
||||
*/
|
||||
$cfg['dirs.destination'] = fw_callback( 'fw_ext_backups_destination_directory' );
|
||||
@@ -0,0 +1,522 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
class FW_Extension_Backups_Demo extends FW_Extension {
|
||||
/**
|
||||
* Cache
|
||||
* @var FW_Ext_Backups_Demo[]
|
||||
*/
|
||||
private static $demos;
|
||||
|
||||
private static $wp_ajax_install = 'fw:ext:backups-demo:install';
|
||||
private static $wp_ajax_status = 'fw:ext:backups-demo:status';
|
||||
private static $wp_ajax_cancel = 'fw:ext:backups-demo:cancel';
|
||||
|
||||
private static $task_collection_id = 'demo-content-install';
|
||||
|
||||
private static $wp_option_active_demo = 'fw:ext:backups-demo:active-demo';
|
||||
|
||||
/**
|
||||
* @return FW_Extension_Backups
|
||||
*/
|
||||
public static function backups() {
|
||||
return fw_ext('backups');
|
||||
}
|
||||
|
||||
/**
|
||||
* @var FW_Access_Key
|
||||
*/
|
||||
private static $access_key;
|
||||
|
||||
/**
|
||||
* @return FW_Access_Key
|
||||
*/
|
||||
private static function get_access_key() {
|
||||
if (empty(self::$access_key)) {
|
||||
self::$access_key = new FW_Access_Key('fw:ext:backups-demo');
|
||||
}
|
||||
|
||||
return self::$access_key;
|
||||
}
|
||||
|
||||
public function get_page_slug() {
|
||||
return 'fw-backups-demo-content';
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected function _init() {
|
||||
add_action('admin_menu', array($this, '_admin_action_admin_menu'));
|
||||
add_action('admin_enqueue_scripts', array($this, '_action_admin_enqueue_scripts'));
|
||||
add_action(
|
||||
'fw:ext:backups:tasks:fail:id:'. self::$task_collection_id,
|
||||
array($this, '_action_tasks_fail')
|
||||
);
|
||||
add_action(
|
||||
'fw:ext:backups:tasks:success:id:'. self::$task_collection_id,
|
||||
array($this, '_action_tasks_success')
|
||||
);
|
||||
add_action(
|
||||
'fw:ext:backups:tasks:cancel:id:'. self::$task_collection_id,
|
||||
array($this, '_action_tasks_cancel')
|
||||
);
|
||||
|
||||
add_action(
|
||||
'wp_ajax_'. self::$wp_ajax_status,
|
||||
array($this, '_action_ajax_status')
|
||||
);
|
||||
add_action(
|
||||
'wp_ajax_'. self::$wp_ajax_install,
|
||||
array($this, '_action_ajax_install')
|
||||
);
|
||||
add_action(
|
||||
'wp_ajax_'. self::$wp_ajax_cancel,
|
||||
array($this, '_action_ajax_cancel')
|
||||
);
|
||||
|
||||
add_filter(
|
||||
'fw_ext_backups_db_export_exclude_option',
|
||||
array($this, '_filter_fw_ext_backups_db_export_exclude_option'),
|
||||
10, 3
|
||||
);
|
||||
add_filter(
|
||||
'fw_ext_backups_db_restore_keep_options',
|
||||
array($this, '_filter_fw_ext_backups_db_restore_keep_options')
|
||||
);
|
||||
|
||||
spl_autoload_register(array($this, '_spl_autoload'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _admin_action_admin_menu() {
|
||||
if (
|
||||
!current_user_can(self::backups()->get_capability())
|
||||
||
|
||||
!$this->get_demos()
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_management_page(
|
||||
__('Demo Content Install', 'fw'),
|
||||
__('Demo Content Install', 'fw'),
|
||||
self::backups()->get_capability(),
|
||||
$this->get_page_slug(),
|
||||
array($this, '_display_page')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _display_page() {
|
||||
echo '<div class="wrap">';
|
||||
|
||||
if (function_exists('is_wpe_snapshot') && !is_wpe_snapshot()) {
|
||||
echo '<div class="error"><p>',
|
||||
sprintf(
|
||||
esc_html__('Demo Content Install works only in %s.', 'fw'),
|
||||
'<a href="'. esc_attr(admin_url('admin.php?page=wpengine-staging')) .'">'
|
||||
. esc_html__('Staging', 'fw')
|
||||
. '</a>'
|
||||
),
|
||||
'</p></div>';
|
||||
} elseif ($error_message = $this->get_parent()->server_requirements_not_met()) {
|
||||
echo "<div class=\"notice notice-error\"><p>{$error_message}</p></div>";
|
||||
} else {
|
||||
$this->render_view('page', array(
|
||||
'demos' => $this->get_demos(),
|
||||
), false);
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FW_Ext_Backups_Demo[]
|
||||
* @since 2.0.23
|
||||
*/
|
||||
public function get_demos() {
|
||||
if (is_null(self::$demos)) {
|
||||
$demos = array();
|
||||
|
||||
foreach (apply_filters('fw_ext_backups_demo_dirs', array(
|
||||
fw_fix_path(get_template_directory()) .'/demo-content'
|
||||
=>
|
||||
get_template_directory_uri() .'/demo-content',
|
||||
)) as $dir_path => $dir_uri) {
|
||||
if (
|
||||
!is_dir($dir_path)
|
||||
||
|
||||
!($dirs = glob($dir_path .'/*', GLOB_ONLYDIR))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (array_map('fw_fix_path', $dirs) as $demo_dir) {
|
||||
$demo_dir_name = basename($demo_dir);
|
||||
|
||||
{
|
||||
if (!file_exists($demo_dir .'/manifest.php')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$manifest = fw_get_variables_from_file(
|
||||
$demo_dir .'/manifest.php',
|
||||
array('manifest' => array()),
|
||||
array('uri' => $dir_uri .'/'. $demo_dir_name)
|
||||
);
|
||||
|
||||
$manifest = array_merge(array(
|
||||
'title' => fw_id_to_title($demo_dir_name),
|
||||
'screenshot' => fw_get_framework_directory_uri('/static/img/no-image.png'),
|
||||
'preview_link' => '',
|
||||
'extra' => array(),
|
||||
), $manifest['manifest']);
|
||||
}
|
||||
|
||||
$demo = new FW_Ext_Backups_Demo(
|
||||
'local-'. md5($demo_dir),
|
||||
'local',
|
||||
array('source' => $demo_dir)
|
||||
);
|
||||
$demo->set_title($manifest['title']);
|
||||
$demo->set_screenshot($manifest['screenshot']);
|
||||
$demo->set_preview_link($manifest['preview_link']);
|
||||
$demo->set_extra($manifest['extra']);
|
||||
|
||||
$demos[ $demo->get_id() ] = $demo;
|
||||
|
||||
unset($demo);
|
||||
}
|
||||
}
|
||||
|
||||
self::$demos = array_merge(
|
||||
apply_filters('fw:ext:backups-demo:demos', array()),
|
||||
$demos
|
||||
);
|
||||
}
|
||||
|
||||
return self::$demos;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
*
|
||||
* @return FW_Ext_Backups_Demo|null
|
||||
*/
|
||||
private function get_demo($id) {
|
||||
$demos = $this->get_demos();
|
||||
|
||||
return isset($demos[$id]) ? $demos[$id] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* If currently is displayed the Demo list page
|
||||
* @return bool
|
||||
*/
|
||||
private function is_page() {
|
||||
return (
|
||||
($current_screen = get_current_screen())
|
||||
&&
|
||||
$current_screen->id === 'tools_page_'. $this->get_page_slug()
|
||||
);
|
||||
}
|
||||
|
||||
public function _action_admin_enqueue_scripts() {
|
||||
if ($this->is_page()) {
|
||||
wp_enqueue_media(); // needed for modals
|
||||
wp_enqueue_style(
|
||||
'fw-ext-backups-demo',
|
||||
$this->get_uri('/static/page.css'),
|
||||
array('fw'),
|
||||
$this->manifest->get_version()
|
||||
);
|
||||
wp_enqueue_script(
|
||||
'fw-ext-backups-demo',
|
||||
$this->get_uri('/static/page.js'),
|
||||
array('fw'),
|
||||
$this->manifest->get_version()
|
||||
);
|
||||
wp_localize_script(
|
||||
'fw-ext-backups-demo',
|
||||
'_fw_ext_backups_demo',
|
||||
array(
|
||||
'ajax_action' => array(
|
||||
'install' => self::$wp_ajax_install,
|
||||
'status' => self::$wp_ajax_status,
|
||||
'cancel' => self::$wp_ajax_cancel,
|
||||
),
|
||||
'l10n' => array(
|
||||
'abort_confirm' => __('Are you sure?', 'fw'),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private function install_is_pending() {
|
||||
foreach (self::backups()->tasks()->get_pending_task_collections() as $collection) {
|
||||
if ($collection->get_id() === self::$task_collection_id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function install_is_active() {
|
||||
if ($active_task_collection = self::backups()->tasks()->get_active_task_collection()) {
|
||||
return $active_task_collection->get_id() === self::$task_collection_id;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private function install_is_busy() {
|
||||
return $this->install_is_active() || $this->install_is_pending();
|
||||
}
|
||||
|
||||
private function get_active_demo() {
|
||||
return get_option(self::$wp_option_active_demo, array('id' => '', 'result' => null));
|
||||
}
|
||||
|
||||
private function set_active_demo($data) {
|
||||
$active_demo = $this->get_active_demo();
|
||||
|
||||
update_option(
|
||||
self::$wp_option_active_demo,
|
||||
array_merge(array(
|
||||
'id' => $active_demo['id'],
|
||||
'result' => null, // 'string' - error message, true - success
|
||||
), $data),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
public function _action_ajax_status() {
|
||||
if (!current_user_can(self::backups()->get_capability())) {
|
||||
wp_send_json_error(new WP_Error(
|
||||
'forbidden',
|
||||
__('Forbidden', 'fw')
|
||||
));
|
||||
}
|
||||
|
||||
$install_is_executing = $this->install_is_active();
|
||||
$install_is_pending = $this->install_is_pending();
|
||||
$is_busy = $this->install_is_busy();
|
||||
$active_demo = $this->get_active_demo();
|
||||
|
||||
if (
|
||||
/**
|
||||
* When the tasks are changed via hook, this code is not relevant and must not be executed
|
||||
* so it can be disabled using this filter
|
||||
* @since 2.0.17
|
||||
*/
|
||||
apply_filters('fw_ext_backups_demo_has_to_reset_active_demo', true)
|
||||
) {
|
||||
if ($active_demo['result']) {
|
||||
// if result is finished, reset, to prevent same message on next request
|
||||
$this->set_active_demo(array('id' => '', 'result' => null));
|
||||
}
|
||||
}
|
||||
|
||||
// in case the execution chain stopped and there is a pending task
|
||||
self::backups()->tasks()->_request_next_step_execution(self::get_access_key());
|
||||
|
||||
wp_send_json_success(array(
|
||||
'is_busy' => $is_busy,
|
||||
'active_demo' => $active_demo,
|
||||
'home_url' => home_url(),
|
||||
'html' => $is_busy
|
||||
? $this->render_view('status', array(
|
||||
'install_is_executing' => $install_is_executing,
|
||||
'install_is_pending' => $install_is_pending,
|
||||
'executing_task' => self::backups()->tasks()->get_executing_task(),
|
||||
'pending_task' => self::backups()->tasks()->get_pending_task(),
|
||||
))
|
||||
: '',
|
||||
'ajax_steps' => array(
|
||||
'token' => md5(
|
||||
defined('NONCE_SALT')
|
||||
? NONCE_SALT
|
||||
: self::backups()->manifest->get_version()
|
||||
),
|
||||
'active_tasks_hash' => (($collection = self::backups()->tasks()->get_active_task_collection())
|
||||
? md5(serialize($collection))
|
||||
: ''
|
||||
)
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
public function _action_ajax_install() {
|
||||
if (!current_user_can(self::backups()->get_capability())) {
|
||||
wp_send_json_error(new WP_Error(
|
||||
'forbidden',
|
||||
__('Forbidden', 'fw')
|
||||
));
|
||||
}
|
||||
|
||||
if (
|
||||
!isset($_POST['id'])
|
||||
||
|
||||
!is_string($_POST['id'])
|
||||
||
|
||||
!($demo = $this->get_demo($_POST['id']))
|
||||
) {
|
||||
wp_send_json_error(new WP_Error(
|
||||
'invalid_id',
|
||||
__('Invalid demo', 'fw')
|
||||
));
|
||||
}
|
||||
|
||||
if ($this->install_is_busy()) {
|
||||
wp_send_json_error(new WP_Error(
|
||||
'already_running',
|
||||
__('A content install is currently running', 'fw')
|
||||
));
|
||||
}
|
||||
|
||||
$this->do_install($demo);
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
public function _action_ajax_cancel() {
|
||||
if (!current_user_can(self::backups()->get_capability())) {
|
||||
wp_send_json_error(new WP_Error(
|
||||
'forbidden',
|
||||
__('Forbidden', 'fw')
|
||||
));
|
||||
}
|
||||
|
||||
if (self::backups()->tasks()->do_cancel()) {
|
||||
wp_send_json_success();
|
||||
} else {
|
||||
wp_send_json_error();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FW_Ext_Backups_Demo $demo
|
||||
* @since 2.0.23
|
||||
*/
|
||||
public function do_install(FW_Ext_Backups_Demo $demo) {
|
||||
$tmp_dir = self::backups()->get_tmp_dir();
|
||||
$id_prefix = 'demo:';
|
||||
|
||||
$collection = new FW_Ext_Backups_Task_Collection(self::$task_collection_id);
|
||||
|
||||
if (!self::backups()->is_disabled()) {
|
||||
$collection = self::backups()->tasks()->add_backup_tasks($collection);
|
||||
}
|
||||
|
||||
$collection->set_title(__('Demo Content Install', 'fw'));
|
||||
|
||||
$collection->add_task(new FW_Ext_Backups_Task(
|
||||
$id_prefix .'tmp-dir-clean:before',
|
||||
'dir-clean',
|
||||
array('dir' => $tmp_dir)
|
||||
));
|
||||
$collection->add_task(new FW_Ext_Backups_Task(
|
||||
$id_prefix .'demo-download',
|
||||
'download',
|
||||
array(
|
||||
'type' => $demo->get_source_type(),
|
||||
'type_args' => $demo->get_source_args(),
|
||||
'destination_dir' => $tmp_dir,
|
||||
|
||||
// used only for https://github.com/ThemeFuse/Unyson-Backups-Extension/issues/15
|
||||
'demo_id' => $demo->get_id(),
|
||||
)
|
||||
));
|
||||
|
||||
self::backups()->tasks()->add_restore_tasks($collection);
|
||||
|
||||
/** @since 2.0.16 */
|
||||
do_action('fw:ext:backups-demo:add-install-tasks', $collection, array(
|
||||
'demo' => $demo,
|
||||
'tmp_dir' => $tmp_dir,
|
||||
));
|
||||
|
||||
$this->set_active_demo(array('id' => $demo->get_id(), 'result' => null));
|
||||
|
||||
self::backups()->tasks()->execute_task_collection($collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exclude
|
||||
* @param string $option_name
|
||||
* @param bool $is_full_backup
|
||||
* @return bool
|
||||
*/
|
||||
public function _filter_fw_ext_backups_db_export_exclude_option($exclude, $option_name, $is_full_backup) {
|
||||
if ($option_name === self::$wp_option_active_demo) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $exclude;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $options {option_name: true}
|
||||
* @return array
|
||||
*/
|
||||
public function _filter_fw_ext_backups_db_restore_keep_options($options) {
|
||||
$options[ self::$wp_option_active_demo] = true;
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function _action_tasks_fail(FW_Ext_Backups_Task_Collection $collection) {
|
||||
$error = __('Error', 'fw');
|
||||
|
||||
foreach ($collection->get_tasks() as $task) {
|
||||
if ($task->result_is_fail()) {
|
||||
if (is_wp_error($task->get_result())) {
|
||||
$error = $task->get_result()->get_error_message();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->set_active_demo(array('result' => $error));
|
||||
}
|
||||
|
||||
public function _action_tasks_cancel() {
|
||||
$this->set_active_demo(array(
|
||||
'result' => __('Demo Install has been aborted', 'fw')
|
||||
));
|
||||
}
|
||||
|
||||
public function _action_tasks_success(FW_Ext_Backups_Task_Collection $collection) {
|
||||
$this->set_active_demo(array('result' => true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FW_Access_Key $access_Key
|
||||
* @return int
|
||||
* @internal
|
||||
* @since 2.0.3
|
||||
*/
|
||||
public function _get_demos_count(FW_Access_Key $access_Key) {
|
||||
if ($access_Key->get_key() !== 'fw:ext:backups-demo:helper:count') {
|
||||
trigger_error('Method call denied', E_USER_ERROR);
|
||||
}
|
||||
|
||||
return count($this->get_demos());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @internal
|
||||
*/
|
||||
public function _spl_autoload($class) {
|
||||
if ('FW_Ext_Backups_Demo' === $class) {
|
||||
require_once dirname(__FILE__) .'/includes/entity/class-fw-ext-backups-demo.php';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace Unyson\Extension\BackupsDemo;
|
||||
|
||||
|
||||
/**
|
||||
* Unyson Backups Demo Extension CLI Commands.
|
||||
*
|
||||
* @package wp-cli
|
||||
*/
|
||||
class Command extends \Unyson\Extension\Command {
|
||||
|
||||
/**
|
||||
* List all available demos.
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* ## EXAMPLES
|
||||
*
|
||||
* # List all available demos.
|
||||
* $ wp unyson ext backups-demo list
|
||||
* +---------------+----------------+------------------------------------------+
|
||||
* | Id | Name | Preview |
|
||||
* +---------------+----------------+------------------------------------------+
|
||||
* | creed | Creed | http://demo.themefuse.com/creed/ |
|
||||
* | the-core | The Core | http://demo.themefuse.com/the-core/ |
|
||||
* | hope | Hope | http://demo.themefuse.com/hope/ |
|
||||
* | gourmet | Gourmet | http://demo.themefuse.com/gourmet/ |
|
||||
* | keynote | Keynote | http://demo.themefuse.com/keynote/ |
|
||||
* | wellness | Wellness | http://demo.themefuse.com/wellness/ |
|
||||
* | cribs | Cribs | http://demo.themefuse.com/cribs/ |
|
||||
* | the-college | The College | http://demo.themefuse.com/the-college/ |
|
||||
* +---------------+----------------+------------------------------------------+
|
||||
*
|
||||
* @param array $_
|
||||
* @param array $options
|
||||
*
|
||||
* @subcommand list
|
||||
*/
|
||||
public function _list( $_, $options = array() ) {
|
||||
\WP_CLI\Utils\format_items(
|
||||
'table',
|
||||
array_map(
|
||||
array( $this, 'get_demo_data' ),
|
||||
$this->get_demos()
|
||||
),
|
||||
array( 'Id', 'Name', 'Preview' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Install demo.
|
||||
*
|
||||
* ## OPTIONS
|
||||
*
|
||||
* <demo-id>
|
||||
* : Demo ID to install.
|
||||
*
|
||||
* ## EXAMPLES
|
||||
*
|
||||
* # Install demo
|
||||
* $ wp unyson ext backups-demo install the-core
|
||||
* Demo the-core successfully installed.
|
||||
*/
|
||||
public function install( $args, $options = array() ) {
|
||||
$id = array_shift( $args );
|
||||
|
||||
try {
|
||||
$demo = $this->get( $id );
|
||||
} catch ( \Exception $e ) {
|
||||
$this->error( $e->getMessage() );
|
||||
}
|
||||
|
||||
$this->get_ext()->do_install( $demo );
|
||||
$this->message( "Demo %g{$demo->get_title()}%n successfully installed." );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \FW_Extension_Backups_Demo
|
||||
*/
|
||||
protected function get_ext() {
|
||||
return fw_ext( 'backups-demo' );
|
||||
}
|
||||
|
||||
protected function get( $id ) {
|
||||
$demos = $this->get_demos();
|
||||
|
||||
if ( isset( $demos[ $id ] ) ) {
|
||||
return $demos[ $id ];
|
||||
}
|
||||
|
||||
throw new \Exception( "Demo '$id' cannot be found" );
|
||||
}
|
||||
|
||||
protected function get_demos() {
|
||||
return $this->get_ext()->get_demos();
|
||||
}
|
||||
|
||||
protected function get_demo_data( \FW_Ext_Backups_Demo $demo ) {
|
||||
return array(
|
||||
'Id' => $demo->get_id(),
|
||||
'Name' => $demo->get_title(),
|
||||
'Preview' => $demo->get_preview_link(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @since 2.0.3
|
||||
*/
|
||||
function fw_ext_backups_demo_count() {
|
||||
static $access_key = null;
|
||||
|
||||
if (is_null($access_key)) {
|
||||
$access_key = new FW_Access_Key('fw:ext:backups-demo:helper:count');
|
||||
}
|
||||
|
||||
/**
|
||||
* @var FW_Extension_Backups_Demo $extension
|
||||
*/
|
||||
$extension = fw_ext('backups-demo');
|
||||
|
||||
return $extension->_get_demos_count($access_key);
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
final class FW_Ext_Backups_Demo {
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $screenshot;
|
||||
|
||||
/**
|
||||
* A registered download source
|
||||
* @see FW_Ext_Backups_Task_Type_Download_Type
|
||||
* @var string
|
||||
*/
|
||||
private $source_type;
|
||||
|
||||
/**
|
||||
* Args sent to download type
|
||||
* @var array
|
||||
*/
|
||||
private $source_args = array();
|
||||
|
||||
private $preview_link;
|
||||
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* @since 2.0.16
|
||||
*/
|
||||
private $extra = array();
|
||||
|
||||
public function __construct($id, $source_type = null, $source_args = array()) {
|
||||
$this->id = $id;
|
||||
$this->source_type = $source_type;
|
||||
$this->source_args = $source_args;
|
||||
}
|
||||
|
||||
public function get_id() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function get_screenshot() {
|
||||
return $this->screenshot;
|
||||
}
|
||||
|
||||
public function set_screenshot($screenshot) {
|
||||
$this->screenshot = $screenshot;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_source_type() {
|
||||
return $this->source_type;
|
||||
}
|
||||
|
||||
public function set_source_type($source_type) {
|
||||
$this->source_type = $source_type;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_source_args() {
|
||||
return $this->source_args;
|
||||
}
|
||||
|
||||
public function set_source_args(array $source_args) {
|
||||
$this->source_args = $source_args;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_preview_link() {
|
||||
return $this->preview_link;
|
||||
}
|
||||
|
||||
public function set_preview_link($preview_link) {
|
||||
$this->preview_link = $preview_link;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_title() {
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
public function set_title($title) {
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @since 2.0.16
|
||||
*/
|
||||
public function get_extra() {
|
||||
return $this->extra;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $extra
|
||||
* @return $this
|
||||
* @since 2.0.16
|
||||
*/
|
||||
public function set_extra(array $extra) {
|
||||
$this->extra = $extra;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function from_array(array $data) {
|
||||
$demo = new self($data['id']);
|
||||
$demo->set_screenshot($data['screenshot']);
|
||||
$demo->set_source_type($data['source_type']);
|
||||
$demo->set_source_args($data['source_args']);
|
||||
$demo->set_extra(isset($data['extra']) ? $data['extra'] : array());
|
||||
|
||||
return $demo;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return array(
|
||||
'id' => $this->get_id(),
|
||||
'screenshot' => $this->get_screenshot(),
|
||||
'source_type' => $this->get_source_type(),
|
||||
'source_args' => $this->get_source_args(),
|
||||
'extra' => $this->get_extra(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php if ( ! defined( 'FW' ) ) {
|
||||
die( 'Forbidden' );
|
||||
}
|
||||
|
||||
$manifest = array();
|
||||
|
||||
$manifest['standalone'] = true;
|
||||
@@ -0,0 +1,30 @@
|
||||
#fw-ext-backups-demo-list .theme .theme-actions {
|
||||
opacity: 1;
|
||||
top: auto;
|
||||
bottom: 0;
|
||||
-webkit-transform: translateY(0);
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
#fw-ext-backups-demo-list .theme a.more-details {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#fw-ext-backups-demo-list .fw-ext-backups-demo-item.active .theme-actions {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
/* status modal */
|
||||
|
||||
.fw-ext-backups-demo-status-modal .progress-percent {
|
||||
background: #ddd;
|
||||
margin: 0 30px;
|
||||
}
|
||||
|
||||
.fw-ext-backups-demo-status-modal .progress-percent > div {
|
||||
background: #0085ba;
|
||||
height: 3px;
|
||||
}
|
||||
|
||||
/* end: status modal */
|
||||
@@ -0,0 +1,337 @@
|
||||
/**
|
||||
* Check current status
|
||||
*/
|
||||
jQuery(function ($) {
|
||||
var inst = {
|
||||
localized: _fw_ext_backups_demo,
|
||||
getEventName: function(name) {
|
||||
return 'fw:ext:backups-demo:status:'+ name;
|
||||
},
|
||||
timeoutId: 0,
|
||||
timeoutTime: 3000,
|
||||
/**
|
||||
* 0 - (false) not busy
|
||||
* 1 - (true) busy
|
||||
* 2 - (true) busy and a pending ajax
|
||||
*/
|
||||
isBusy: 0,
|
||||
doAjax: function() {
|
||||
if (this.isBusy) {
|
||||
this.isBusy = 2;
|
||||
return false;
|
||||
}
|
||||
|
||||
clearTimeout(this.timeoutId);
|
||||
|
||||
fwEvents.trigger(this.getEventName('updating'));
|
||||
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
action: this.localized.ajax_action.status
|
||||
}
|
||||
})
|
||||
.done(_.bind(function(r){
|
||||
if (r.success) {
|
||||
fwEvents.trigger(this.getEventName('update'), r.data);
|
||||
} else {
|
||||
fwEvents.trigger(this.getEventName('update-fail'));
|
||||
}
|
||||
}, this))
|
||||
.fail(_.bind(function(jqXHR, textStatus, errorThrown){
|
||||
console.error('Ajax error', jqXHR, textStatus, errorThrown);
|
||||
fwEvents.trigger(this.getEventName('update-fail'));
|
||||
}, this))
|
||||
.always(_.bind(function(data_jqXHR, textStatus, jqXHR_errorThrown){
|
||||
fwEvents.trigger(this.getEventName('updated'));
|
||||
|
||||
if (this.isBusy === 2) {
|
||||
this.isBusy = 0;
|
||||
this.doAjax();
|
||||
} else {
|
||||
this.isBusy = 0;
|
||||
}
|
||||
|
||||
this.timeoutId = setTimeout(_.bind(this.doAjax, this), this.timeoutTime);
|
||||
}, this));
|
||||
|
||||
return true;
|
||||
},
|
||||
onUpdate: function(data) {
|
||||
this.timeoutTime = data.is_busy ? 3000 : 10000;
|
||||
},
|
||||
init: function(){
|
||||
this.init = function(){};
|
||||
|
||||
fwEvents.on(this.getEventName('do-update'), _.bind(function(){ this.doAjax(); }, this));
|
||||
fwEvents.on(this.getEventName('update'), _.bind(function(data){ this.onUpdate(data); }, this));
|
||||
|
||||
this.doAjax();
|
||||
}
|
||||
};
|
||||
|
||||
// let other scripts to listen events
|
||||
setTimeout(function(){ inst.init(); }, 100);
|
||||
});
|
||||
|
||||
/**
|
||||
* Current status
|
||||
*/
|
||||
jQuery(function($){
|
||||
var inst = {
|
||||
failCount: 0,
|
||||
fwSoleModalId: 'fw-ext-backups-demo-status',
|
||||
onUpdating: function(){},
|
||||
onUpdate: function(data) {
|
||||
if (data.is_busy) {
|
||||
fw.soleModal.show(
|
||||
this.fwSoleModalId,
|
||||
data.html,
|
||||
{
|
||||
allowClose: false,
|
||||
updateIfCurrent: true
|
||||
}
|
||||
);
|
||||
} else {
|
||||
fw.soleModal.hide(this.fwSoleModalId);
|
||||
}
|
||||
|
||||
this.failCount = 0;
|
||||
},
|
||||
onUpdateFail: function() {
|
||||
if (this.failCount > 3) {
|
||||
fw.soleModal.show(
|
||||
this.fwSoleModalId,
|
||||
'<span class="fw-text-danger dashicons dashicons-warning"></span>',
|
||||
{
|
||||
allowClose: false,
|
||||
updateIfCurrent: true
|
||||
}
|
||||
);
|
||||
}
|
||||
++this.failCount;
|
||||
},
|
||||
onUpdated: function() {},
|
||||
init: function(){
|
||||
fwEvents.on({
|
||||
'fw:ext:backups-demo:status:updating': _.bind(this.onUpdating, this),
|
||||
'fw:ext:backups-demo:status:update': _.bind(this.onUpdate, this),
|
||||
'fw:ext:backups-demo:status:update-fail': _.bind(this.onUpdateFail, this),
|
||||
'fw:ext:backups-demo:status:updated': _.bind(this.onUpdated, this)
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
inst.init();
|
||||
});
|
||||
|
||||
/**
|
||||
* Install button
|
||||
*/
|
||||
jQuery(function($) {
|
||||
var inst = {
|
||||
localized: _fw_ext_backups_demo,
|
||||
isBusy: false,
|
||||
fwLoadingId: 'fw-ext-backups-demo-install',
|
||||
init: function(){
|
||||
fwEvents.on('fw:ext:backups-demo:status:update', function(data){
|
||||
{
|
||||
$('#fw-ext-backups-demo-list .fw-ext-backups-demo-item').removeClass('active');
|
||||
|
||||
if (data.active_demo.id) {
|
||||
$('#demo-'+ data.active_demo.id).addClass('active');
|
||||
}
|
||||
}
|
||||
|
||||
if (data.active_demo.result) {
|
||||
if (data.active_demo.result === true) {
|
||||
fw.soleModal.hide(inst.fwLoadingId);
|
||||
|
||||
setTimeout(function(){
|
||||
$(document.body).fadeOut();
|
||||
}, 500); // after modal hide animation end
|
||||
|
||||
setTimeout(function(){
|
||||
window.location.assign(data.home_url);
|
||||
}, 1000); // after all animations end
|
||||
} else {
|
||||
fw.soleModal.show(
|
||||
inst.fwLoadingId,
|
||||
'<h3 class="fw-text-danger">'+ data.active_demo.result +'</h3>'
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#fw-ext-backups-demo-list').on('click', '[data-install]', function(){
|
||||
if (inst.isBusy) {
|
||||
console.log('Install is busy');
|
||||
return;
|
||||
}
|
||||
|
||||
var $this = $(this),
|
||||
demoId = $this.attr('data-install'),
|
||||
confirm_message = $this.attr('data-confirm');
|
||||
|
||||
if (confirm_message) {
|
||||
if (!confirm(confirm_message)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
inst.isBusy = true;
|
||||
fw.loading.show(inst.fwLoadingId);
|
||||
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
action: inst.localized.ajax_action.install,
|
||||
id: demoId
|
||||
},
|
||||
type: 'POST',
|
||||
dataType: 'json'
|
||||
})
|
||||
.done(function(r){
|
||||
if (r.success) {
|
||||
fwEvents.trigger('fw:ext:backups-demo:status:do-update');
|
||||
} else {
|
||||
fw.soleModal.show(
|
||||
'fw-ext-backups-demo-install-error',
|
||||
((r.data && r.data.length) ? r.data[0].message : '')
|
||||
);
|
||||
}
|
||||
})
|
||||
.fail(function(jqXHR, textStatus, errorThrown){
|
||||
fw.soleModal.show(
|
||||
'fw-ext-backups-demo-install-error',
|
||||
'<h2>Ajax error</h2>'+ '<p>'+ String(errorThrown) +'</p>'
|
||||
);
|
||||
})
|
||||
.always(function(data_jqXHR, textStatus, jqXHR_errorThrown){
|
||||
inst.isBusy = false;
|
||||
fw.loading.hide(inst.fwLoadingId);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
inst.init();
|
||||
});
|
||||
|
||||
/**
|
||||
* "Cancel" functionality
|
||||
*/
|
||||
jQuery(function($){
|
||||
var inst = {
|
||||
localized: _fw_ext_backups_demo,
|
||||
isBusy: false,
|
||||
fwLoadingId: 'fw-ext-backups-demo-install-cancel',
|
||||
doCancel: function(){
|
||||
if (this.isBusy) {
|
||||
return;
|
||||
} else {
|
||||
if (!confirm(this.localized.l10n.abort_confirm)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.isBusy = true;
|
||||
}
|
||||
|
||||
inst.isBusy = true;
|
||||
fw.loading.show(inst.fwLoadingId);
|
||||
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
action: inst.localized.ajax_action.cancel
|
||||
},
|
||||
type: 'POST',
|
||||
dataType: 'json'
|
||||
})
|
||||
.done(function(r){
|
||||
if (r.success) {
|
||||
fwEvents.trigger('fw:ext:backups-demo:status:do-update');
|
||||
} else {
|
||||
console.warn('Cancel failed');
|
||||
}
|
||||
})
|
||||
.fail(function(jqXHR, textStatus, errorThrown){
|
||||
fw.soleModal.show(
|
||||
'fw-ext-backups-demo-install-error',
|
||||
'<h2>Ajax error</h2>'+ '<p>'+ String(errorThrown) +'</p>'
|
||||
);
|
||||
})
|
||||
.always(function(data_jqXHR, textStatus, jqXHR_errorThrown){
|
||||
inst.isBusy = false;
|
||||
fw.loading.hide(inst.fwLoadingId);
|
||||
});
|
||||
},
|
||||
init: function(){
|
||||
var that = this;
|
||||
|
||||
fwEvents.on('fw:ext:backups-demo:cancel', function(){
|
||||
that.doCancel();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
inst.init();
|
||||
});
|
||||
|
||||
/**
|
||||
* If loopback request failed, execute steps via ajax
|
||||
* @since 2.0.5
|
||||
*/
|
||||
jQuery(function($){
|
||||
if (typeof fw_ext_backups_loopback_failed == 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
var inst = {
|
||||
running: false,
|
||||
isBusy: false,
|
||||
onUpdate: function(data) {
|
||||
this.running = data.is_busy;
|
||||
this.executeNextStep(data.ajax_steps.token, data.ajax_steps.active_tasks_hash);
|
||||
},
|
||||
executeNextStep: function(token, activeTasksHash){
|
||||
if (!this.running || this.isBusy) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.isBusy = true;
|
||||
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
action: 'fw:ext:backups:continue-pending-task',
|
||||
token: token,
|
||||
active_tasks_hash: activeTasksHash
|
||||
},
|
||||
type: 'POST',
|
||||
dataType: 'json'
|
||||
})
|
||||
.done(function(r){ console.log(r);
|
||||
if (r.success) {
|
||||
fwEvents.trigger('fw:ext:backups-demo:status:do-update');
|
||||
} else {
|
||||
console.error('Ajax execution failed');
|
||||
// execution will try to continue on next (auto) update
|
||||
}
|
||||
})
|
||||
.fail(_.bind(function(jqXHR, textStatus, errorThrown){
|
||||
console.error('Ajax error: '+ String(errorThrown));
|
||||
}, this))
|
||||
.always(_.bind(function(data_jqXHR, textStatus, jqXHR_errorThrown){
|
||||
this.isBusy = false;
|
||||
}, this));
|
||||
},
|
||||
init: function(){
|
||||
fwEvents.on('fw:ext:backups-demo:status:update', _.bind(this.onUpdate, this));
|
||||
}
|
||||
};
|
||||
|
||||
inst.init();
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php if ( ! defined( 'FW' ) ) die( 'Forbidden' );
|
||||
/**
|
||||
* @var FW_Ext_Backups_Demo[] $demos
|
||||
*/
|
||||
|
||||
/**
|
||||
* @var FW_Extension_Backups $backups
|
||||
*/
|
||||
$backups = fw_ext('backups');
|
||||
|
||||
if ($backups->is_disabled()) {
|
||||
$confirm = '';
|
||||
} else {
|
||||
$confirm = esc_html__(
|
||||
'IMPORTANT: Installing this demo content will delete the content you currently have on your website.'
|
||||
. ' However, we create a backup of your current content in (Tools > Backup).'
|
||||
. ' You can restore the backup from there at any time in the future.',
|
||||
'fw'
|
||||
);
|
||||
}
|
||||
?>
|
||||
<h2><?php esc_html_e('Demo Content Install', 'fw') ?></h2>
|
||||
|
||||
<div>
|
||||
<?php if ( !class_exists('ZipArchive') ): ?>
|
||||
<div class="error below-h2">
|
||||
<p>
|
||||
<strong><?php _e( 'Important', 'fw' ); ?></strong>:
|
||||
<?php printf(
|
||||
__( 'You need to activate %s.', 'fw' ),
|
||||
'<a href="http://php.net/manual/en/book.zip.php" target="_blank">'. __('zip extension', 'fw') .'</a>'
|
||||
); ?>
|
||||
</p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($http_loopback_warning = fw_ext_backups_loopback_test()) : ?>
|
||||
<div class="error">
|
||||
<p><strong><?php _e( 'Important', 'fw' ); ?>:</strong> <?php echo $http_loopback_warning; ?></p>
|
||||
</div>
|
||||
<script type="text/javascript">var fw_ext_backups_loopback_failed = true;</script>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<p></p>
|
||||
<div class="theme-browser rendered" id="fw-ext-backups-demo-list">
|
||||
<?php foreach ($demos as $demo): ?>
|
||||
<div class="theme fw-ext-backups-demo-item" id="demo-<?php echo esc_attr($demo->get_id()) ?>">
|
||||
<div class="theme-screenshot">
|
||||
<img src="<?php echo esc_attr($demo->get_screenshot()); ?>" alt="Screenshot" />
|
||||
</div>
|
||||
<?php if ($demo->get_preview_link()): ?>
|
||||
<a class="more-details" target="_blank" href="<?php echo esc_attr($demo->get_preview_link()) ?>">
|
||||
<?php esc_html_e('Live Preview', 'fw') ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
<h3 class="theme-name"><?php echo esc_html($demo->get_title()); ?></h3>
|
||||
<div class="theme-actions">
|
||||
<a class="button button-primary"
|
||||
href="#" onclick="return false;"
|
||||
data-confirm="<?php echo esc_attr($confirm); ?>"
|
||||
data-install="<?php echo esc_attr($demo->get_id()) ?>"><?php esc_html_e('Install', 'fw'); ?></a>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
/**
|
||||
* @var bool $install_is_executing
|
||||
* @var bool $install_is_pending
|
||||
* @var null|FW_Ext_Backups_Task $executing_task
|
||||
* @var null|FW_Ext_Backups_Task $pending_task
|
||||
*/
|
||||
|
||||
$backups = fw_ext( 'backups' ); /** @var FW_Extension_Backups $backups */
|
||||
$active_collection = $backups->tasks()->get_active_task_collection();
|
||||
?>
|
||||
<div class="fw-ext-backups-demo-status-modal">
|
||||
<?php if ($install_is_executing): ?>
|
||||
<h2 class="fw-text-muted">
|
||||
<img src="<?php echo get_site_url() ?>/wp-admin/images/spinner.gif" alt="Loading" class="wp-spinner" />
|
||||
<?php esc_html_e('Installing', 'fw') ?>
|
||||
</h2>
|
||||
<p class="fw-text-muted"><em><?php esc_html_e('We are currently installing your content.') ?></em></p>
|
||||
|
||||
<?php
|
||||
$step = 0;
|
||||
foreach ($active_collection->get_tasks() as $_task) {
|
||||
++$step;
|
||||
if (!$_task->result_is_finished()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$percentage = $step / count($active_collection->get_tasks()) * 100;
|
||||
?>
|
||||
<div class="progress-percent"><div style="width: <?php echo $percentage; ?>%;"></div></div>
|
||||
|
||||
<?php if ($executing_task): ?>
|
||||
<p class="fw-text-muted"><em><?php echo esc_html($backups->tasks()->get_task_type_title(
|
||||
$executing_task->get_type(),
|
||||
$executing_task->get_args(),
|
||||
$executing_task->get_result()
|
||||
)); ?></em></p>
|
||||
<?php elseif ($pending_task): ?>
|
||||
<p class="fw-text-muted"><em><?php echo esc_html($backups->tasks()->get_task_type_title(
|
||||
$pending_task->get_type(),
|
||||
$pending_task->get_args(),
|
||||
$pending_task->get_result()
|
||||
)); ?></em></p>
|
||||
<?php endif; ?>
|
||||
<?php elseif ($install_is_pending): ?>
|
||||
<p><img src="<?php echo get_site_url() ?>/wp-admin/images/spinner.gif" alt="Loading"></p>
|
||||
<em class="fw-text-muted"><?php esc_html_e('Pending', 'fw') ?></em>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($active_collection && $active_collection->is_cancelable()): ?>
|
||||
<a href="#" onclick="fwEvents.trigger('fw:ext:backups-demo:cancel'); return false;"><em><?php
|
||||
esc_html_e('Abort', 'fw');
|
||||
?></em></a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
@@ -0,0 +1,307 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* Test if HTTP Loopback Connections are enabled on this server
|
||||
*/
|
||||
function fw_ext_backups_loopback_test() {
|
||||
/** @var FW_Extension_Backups $backups */
|
||||
$backups = fw_ext('backups');
|
||||
|
||||
$url = site_url( 'wp-admin/admin-ajax.php' );
|
||||
|
||||
$response = wp_remote_post($url, array(
|
||||
'blocking' => true,
|
||||
'sslverify' => false,
|
||||
'body' => array(
|
||||
'action' => $backups->_get_test_ajax_action(),
|
||||
),
|
||||
));
|
||||
|
||||
$error = false;
|
||||
|
||||
if (is_wp_error($response)) {
|
||||
$error = $response->get_error_message();
|
||||
} elseif(200 !== ($response_code = intval(wp_remote_retrieve_response_code($response)))) {
|
||||
$error = sprintf(esc_html__('Response code: %d', 'fw'), $response_code);
|
||||
} elseif (
|
||||
isset($response['body'])
|
||||
&&
|
||||
($response_json = json_decode($response['body'], true))
|
||||
&&
|
||||
isset($response_json['success'])
|
||||
&&
|
||||
true === $response_json['success']
|
||||
) {
|
||||
return false;
|
||||
} else {
|
||||
$error = __('Invalid JSON response', 'fw');
|
||||
}
|
||||
|
||||
return str_replace(
|
||||
array('{url}', '{error}'),
|
||||
array($url, $error),
|
||||
__(
|
||||
'HTTP Loopback Connections are not enabled on this server. ' .
|
||||
'If you need to contact your web host, '
|
||||
. 'tell them that when PHP tries to connect back to the site '
|
||||
. 'at the URL `{url}` and it gets the error `{error}`. '
|
||||
. 'There may be a problem with the server configuration (eg local DNS problems, mod_security, etc) '
|
||||
. 'preventing connections from working properly.',
|
||||
'fw'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function fw_ext_backups_rmdir_recursive($dir) {
|
||||
if (is_dir($dir = fw_fix_path($dir))) {
|
||||
if ($files = array_diff(($files = scandir($dir)) ? $files : array(), array('.', '..'))) {
|
||||
foreach ( $files as $file ) {
|
||||
$file = $dir .'/'. $file;
|
||||
|
||||
if ( is_dir( $file ) ) {
|
||||
if ( ! fw_ext_backups_rmdir_recursive( $file ) ) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if ( ! unlink( $file ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! rmdir($dir) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $dir
|
||||
* @return bool|null
|
||||
* http://stackoverflow.com/a/7497848/1794248
|
||||
*/
|
||||
function fw_ext_backups_is_dir_empty($dir) {
|
||||
if (!is_readable($dir)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (false === ($handle = opendir($dir))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
while (false !== ($entry = readdir($handle))) {
|
||||
if ($entry !== '.' && $entry !== '..') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source_dir
|
||||
* @param string $destination_dir
|
||||
* @return bool|WP_Error
|
||||
*/
|
||||
function fw_ext_backups_copy_dir_recursive($source_dir, $destination_dir) {
|
||||
$source_dir = fw_fix_path($source_dir);
|
||||
$destination_dir = fw_fix_path($destination_dir);
|
||||
|
||||
$dir_chmod = 0755;
|
||||
|
||||
if (!file_exists($destination_dir)) {
|
||||
if (!mkdir($destination_dir, $dir_chmod)) {
|
||||
return new WP_Error(
|
||||
'mkdir_fail',
|
||||
sprintf(__('Failed to create dir: %s'), $destination_dir)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
foreach (
|
||||
$iterator = new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($source_dir),
|
||||
RecursiveIteratorIterator::SELF_FIRST
|
||||
) as $item /** @var SplFileInfo $item */
|
||||
) {
|
||||
if (in_array(basename($iterator->getSubPathName()), array('.', '..'), true)) {
|
||||
continue; // We can't use RecursiveDirectoryIterator::SKIP_DOTS, it was added in php 5.3
|
||||
}
|
||||
|
||||
$destination_path = $destination_dir . '/' . $iterator->getSubPathName();
|
||||
|
||||
if ($item->isDir()) {
|
||||
if (!mkdir($destination_path, $dir_chmod)) {
|
||||
return new WP_Error(
|
||||
'mk_sub_dir_fail',
|
||||
sprintf(__('Failed to create dir: %s'), $destination_path)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (!copy($item->getPathname(), $destination_path)) {
|
||||
return new WP_Error(
|
||||
'copy_fail',
|
||||
sprintf(__('Failed to copy: %s'), $destination_path)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (UnexpectedValueException $e) {
|
||||
return new WP_Error(
|
||||
'dir_copy_fail',
|
||||
(string)$e->getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* If current user is allowed to make full backup or restore
|
||||
* This method must be used before calling $backups->tasks()->do_backup|restore()
|
||||
* to not allow simple admins to make full backup|restore on multisite and affect all sites.
|
||||
*
|
||||
* $backups->tasks()->do_backup|restore() Can't do that check
|
||||
* because those methods are also called in cron, when the user is not logged in
|
||||
*/
|
||||
function fw_ext_backups_current_user_can_full() {
|
||||
if ( is_multisite() ) {
|
||||
return is_main_site() &&
|
||||
fw_current_user_can( array( 'manage_network_plugins' ), false ) &&
|
||||
fw_current_user_can( array( 'manage_network_themes' ), false );
|
||||
} else {
|
||||
return fw_current_user_can( array( 'install_plugins' ), false ) &&
|
||||
fw_current_user_can( array( 'install_themes' ), false );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract from zip files one by one and check if timeout wasn't reached
|
||||
* @param string|resource $zip Path or zip_open() result
|
||||
* @param string $destination_dir
|
||||
* @param int $timeout
|
||||
* @param string $last_entry
|
||||
* @return array|WP_Error Done when $result['finished'] === true
|
||||
* @since 2.0.16
|
||||
*/
|
||||
function fw_ext_backups_unzip_partial($zip, $destination_dir, $last_entry = '', $timeout = 0) {
|
||||
if (!function_exists('zip_open')) {
|
||||
return new WP_Error(
|
||||
'zip_ext_missing', __('Zip extension missing', 'fw')
|
||||
);
|
||||
}
|
||||
|
||||
if (!is_resource($zip) && !is_resource($zip = zip_open($zip))) {
|
||||
return new WP_Error(
|
||||
'cannot_open_zip', sprintf(__('Cannot open zip (Error code: %s)', 'fw'), $zip)
|
||||
);
|
||||
}
|
||||
|
||||
if ($timeout <= 0) {
|
||||
/** @var FW_Extension_Backups $ext */
|
||||
$ext = fw_ext('backups');
|
||||
$timeout = $ext->get_timeout(-10);
|
||||
}
|
||||
|
||||
if ($last_entry) {
|
||||
while(
|
||||
($entry = zip_read($zip))
|
||||
&&
|
||||
zip_entry_name($entry) !== $last_entry
|
||||
);
|
||||
|
||||
if (!$entry) {
|
||||
zip_close($zip);
|
||||
return new WP_Error(
|
||||
'entry_restore_fail',
|
||||
sprintf(__('Cannot restore previous zip entry: %s', 'fw'), $last_entry)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$result = array(
|
||||
'finished' => false,
|
||||
'last_entry' => $last_entry,
|
||||
'extracted_files' => 0,
|
||||
);
|
||||
|
||||
$max_time = time() + $timeout;
|
||||
|
||||
while (time() < $max_time) {
|
||||
if (!($entry = zip_read($zip))) {
|
||||
$result['finished'] = true;
|
||||
return $result;
|
||||
}
|
||||
|
||||
$name = zip_entry_name($entry);
|
||||
|
||||
if (substr($name, -1) === '/') {
|
||||
continue; // it is a directory
|
||||
}
|
||||
|
||||
$destination_path = $destination_dir .'/'. $name;
|
||||
|
||||
if (
|
||||
!file_exists($dest_dir = dirname($destination_path))
|
||||
&&
|
||||
!mkdir($dest_dir, 0777, true)
|
||||
) {
|
||||
zip_close($zip);
|
||||
return new WP_Error(
|
||||
'mkdir_fail',
|
||||
sprintf(__('Cannot create directory: %s', 'fw'), $dest_dir)
|
||||
);
|
||||
}
|
||||
|
||||
if (false === ($unzipped = fopen($destination_path, 'wb'))) {
|
||||
zip_close($zip);
|
||||
return new WP_Error(
|
||||
'fopen_fail',
|
||||
sprintf(__('Cannot create file: %s', 'fw'), $destination_path)
|
||||
);
|
||||
}
|
||||
|
||||
$size = zip_entry_filesize($entry);
|
||||
|
||||
while ($size > 0) {
|
||||
$chunk_size = min($size, 10240);
|
||||
$size -= $chunk_size;
|
||||
|
||||
if (false === ($chunk = zip_entry_read($entry, $chunk_size))) {
|
||||
fclose($unzipped);
|
||||
zip_close($zip);
|
||||
return new WP_Error(
|
||||
'zip_entry_read_fail',
|
||||
sprintf(__('Cannot read chunk from zip entry: %s', 'fw'), $name)
|
||||
);
|
||||
} else {
|
||||
fwrite($unzipped, $chunk);
|
||||
}
|
||||
}
|
||||
|
||||
if (false === fclose($unzipped)) {
|
||||
zip_close($zip);
|
||||
return new WP_Error(
|
||||
'fclose_fail',
|
||||
sprintf(__('Cannot close file: %s', 'fw'), $destination_path)
|
||||
);
|
||||
}
|
||||
|
||||
$result['last_entry'] = $name;
|
||||
++$result['extracted_files'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function fw_ext_backups_destination_directory() {
|
||||
$uploads = wp_upload_dir();
|
||||
|
||||
return fw_fix_path( $uploads['basedir'] ) . '/fw-backup';
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* @param bool $exclude
|
||||
* @param string $option_name
|
||||
* @param bool $is_full_backup
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function _filter_fw_ext_backups_db_export_exclude_option($exclude, $option_name, $is_full_backup) {
|
||||
foreach (array(
|
||||
'_site_transient_',
|
||||
'_transient_'
|
||||
) as $option_prefix) {
|
||||
if (substr($option_name, 0, strlen($option_prefix)) === $option_prefix) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return $exclude;
|
||||
}
|
||||
add_filter('fw_ext_backups_db_export_exclude_option', '_filter_fw_ext_backups_db_export_exclude_option', 10, 3);
|
||||
|
||||
/**
|
||||
* Other extensions options
|
||||
*/
|
||||
{
|
||||
function _filter_fw_ext_backups_db_export_exclude_other_extensions_options($exclude, $option_name, $is_full_backup) {
|
||||
if (!$is_full_backup) {
|
||||
if ($option_name === 'fw_ext_settings_options:mailer') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return $exclude;
|
||||
}
|
||||
add_filter('fw_ext_backups_db_export_exclude_option',
|
||||
'_filter_fw_ext_backups_db_export_exclude_other_extensions_options', 10, 3
|
||||
);
|
||||
|
||||
function _filter_fw_ext_backups_db_restore_keep_other_extensions_options($options, $is_full) {
|
||||
if (!$is_full) {
|
||||
$options[ 'fw_ext_settings_options:mailer' ] = true;
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
add_filter('fw_ext_backups_db_restore_keep_options',
|
||||
'_filter_fw_ext_backups_db_restore_keep_other_extensions_options', 10, 2
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* Display extensions with updates on the Update Page
|
||||
*/
|
||||
class _FW_Ext_Backups_List_Table extends FW_WP_List_Table
|
||||
{
|
||||
private $items_pre_page = 1000;
|
||||
|
||||
private $total_items = null;
|
||||
|
||||
private $_archives = array();
|
||||
|
||||
private $_table_columns = array();
|
||||
private $_table_columns_count = 0;
|
||||
|
||||
public function __construct($args)
|
||||
{
|
||||
parent::__construct(array(
|
||||
'screen' => 'fw-ext-backups'
|
||||
));
|
||||
|
||||
$this->_archives = $args['archives'];
|
||||
|
||||
$this->_table_columns = array(
|
||||
'cb' => ' ',
|
||||
'details' => ' ',
|
||||
);
|
||||
$this->_table_columns_count = count($this->_table_columns);
|
||||
}
|
||||
|
||||
public function get_columns()
|
||||
{
|
||||
return $this->_table_columns;
|
||||
}
|
||||
|
||||
public function prepare_items()
|
||||
{
|
||||
if (!is_null($this->total_items)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->total_items = count($this->_archives);
|
||||
|
||||
$this->set_pagination_args(array(
|
||||
'total_items' => $this->total_items,
|
||||
'per_page' => $this->items_pre_page,
|
||||
));
|
||||
|
||||
/**
|
||||
* @var FW_Extension_Backups $backups
|
||||
*/
|
||||
$backups = fw_ext('backups');
|
||||
|
||||
/**
|
||||
* Prepare items for output
|
||||
*/
|
||||
foreach ($this->_archives as $filename => $archive) {
|
||||
$time = get_date_from_gmt(
|
||||
gmdate('Y-m-d H:i:s', $archive['time']),
|
||||
get_option('date_format') . ' ' . get_option('time_format')
|
||||
);
|
||||
|
||||
$filename_hash = md5($filename);
|
||||
|
||||
{
|
||||
$details = array();
|
||||
|
||||
$details[] = $archive['full'] ? __('Full Backup', 'fw') : __('Content Backup', 'fw');
|
||||
|
||||
if (function_exists('fw_human_bytes')) {
|
||||
$details[] = fw_human_bytes(filesize($archive['path']));
|
||||
}
|
||||
|
||||
$details[] = fw_html_tag('a', array(
|
||||
'href' => $backups->get_download_link($filename),
|
||||
'target' => '_blank',
|
||||
'id' => 'download-'. $filename_hash,
|
||||
'data-download-file' => $filename,
|
||||
), esc_html__('Download', 'fw'));
|
||||
|
||||
$details[] = fw_html_tag('a', array(
|
||||
'href' => '#',
|
||||
'onclick' => 'return false;',
|
||||
'id' => 'delete-'. $filename_hash,
|
||||
'data-delete-file' => $filename,
|
||||
'data-confirm' => __(
|
||||
"Warning! \n".
|
||||
"You are about to delete a backup, it will be lost forever. \n".
|
||||
"Are you sure?",
|
||||
'fw'
|
||||
)
|
||||
), esc_html__('Delete', 'fw'));
|
||||
}
|
||||
|
||||
|
||||
$this->items[] = array(
|
||||
'cb' => fw_html_tag('input', array(
|
||||
'type' => 'radio',
|
||||
'name' => 'archive',
|
||||
'value' => $filename,
|
||||
'id' => 'archive-'. $filename_hash,
|
||||
)),
|
||||
'details' =>
|
||||
'<div>'. $time .'</div>'.
|
||||
'<div>'. implode(' | ', $details) .'</div>',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function has_items()
|
||||
{
|
||||
$this->prepare_items();
|
||||
|
||||
return $this->total_items;
|
||||
}
|
||||
|
||||
/**
|
||||
* (override parent)
|
||||
*/
|
||||
function single_row($item)
|
||||
{
|
||||
static $row_class = '';
|
||||
|
||||
$row_class = ( $row_class == '' ? ' class="alternate"' : '' );
|
||||
|
||||
echo '<tr' . $row_class . '>';
|
||||
echo $this->single_row_columns( $item );
|
||||
echo '</tr>';
|
||||
}
|
||||
|
||||
protected function column_cb($item)
|
||||
{
|
||||
echo $item['cb'];
|
||||
}
|
||||
|
||||
protected function column_default($item, $column_name)
|
||||
{
|
||||
echo $item[$column_name];
|
||||
}
|
||||
|
||||
function no_items()
|
||||
{
|
||||
esc_html_e('No archives found', 'fw');
|
||||
}
|
||||
|
||||
function extra_tablenav( $which ) {
|
||||
echo fw_html_tag('button', array(
|
||||
'type' => 'button',
|
||||
'onclick' => 'return false;',
|
||||
'class' => 'button fw-ext-backups-archive-restore-button',
|
||||
'disabled' => 'disabled',
|
||||
'data-confirm' => esc_html__("Warning! \nThe restore will replace all of your content.", 'fw'),
|
||||
), esc_html__('Restore Backup'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class _FW_Ext_Backups_Log {
|
||||
/**
|
||||
* @var FW_Access_Key|null
|
||||
*/
|
||||
private static $access_key;
|
||||
|
||||
/**
|
||||
* @return FW_Access_Key|null
|
||||
*/
|
||||
private static function get_access_key() {
|
||||
if (empty(self::$access_key)) {
|
||||
self::$access_key = new FW_Access_Key('fw:ext:backups:log');
|
||||
}
|
||||
|
||||
return self::$access_key;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FW_Extension_Backups
|
||||
*/
|
||||
private static function backups() {
|
||||
return fw_ext('backups');
|
||||
}
|
||||
|
||||
private static $wp_option = 'fw:ext:backups:log';
|
||||
|
||||
private static $log_limit = 30;
|
||||
|
||||
public function __construct() {
|
||||
add_action('fw:ext:backups:task:fail', array($this, '_action_task_fail'));
|
||||
add_action('fw:ext:backups:tasks:success', array($this, '_action_tasks_success'));
|
||||
add_action('fw_ext_backups_page_footer', array($this, '_action_page_footer'));
|
||||
add_action('fw:ext:backups:enqueue_scripts', array($this, '_action_enqueue_scripts'));
|
||||
|
||||
add_filter(
|
||||
'fw_ext_backups_db_export_exclude_option',
|
||||
array($this, '_filter_fw_ext_backups_db_export_exclude_option'),
|
||||
10, 3
|
||||
);
|
||||
add_filter(
|
||||
'fw_ext_backups_db_restore_keep_options',
|
||||
array($this, '_filter_fw_ext_backups_db_restore_keep_options')
|
||||
);
|
||||
add_filter(
|
||||
'fw_ext_backups_ajax_status_extra_response',
|
||||
array($this, '_filter_fw_ext_backups_ajax_status_extra_response')
|
||||
);
|
||||
}
|
||||
|
||||
private function get_log() {
|
||||
return get_option(self::$wp_option, array());
|
||||
}
|
||||
|
||||
private function set_log($log) {
|
||||
while (count($log) > self::$log_limit) {
|
||||
array_pop($log);
|
||||
}
|
||||
|
||||
return update_option(self::$wp_option, $log, false);
|
||||
}
|
||||
|
||||
private function add_log($type, $title, array $data = array()) {
|
||||
if (!in_array($type, array('success', 'info', 'warning', 'error'))) {
|
||||
trigger_error('Invalid log type: '. $type, E_USER_WARNING);
|
||||
}
|
||||
|
||||
$log = $this->get_log();
|
||||
|
||||
array_unshift($log, array(
|
||||
'type' => $type,
|
||||
'title' => $title,
|
||||
'data' => $data,
|
||||
'time' => time(),
|
||||
));
|
||||
|
||||
$this->set_log($log);
|
||||
}
|
||||
|
||||
private function render_log() {
|
||||
return fw_render_view(dirname(__FILE__) .'/view.php', array(
|
||||
'log' => $this->get_log()
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FW_Ext_Backups_Task $task
|
||||
* @internal
|
||||
*/
|
||||
public function _action_task_fail(FW_Ext_Backups_Task $task) {
|
||||
$this->add_log(
|
||||
'error',
|
||||
self::backups()->tasks()->get_task_type_title($task->get_type())
|
||||
. (is_wp_error($task->get_result()) ? ': '. $task->get_result()->get_error_message() : ''),
|
||||
is_wp_error($task->get_result()) ? (array)$task->get_result()->get_error_data() : array()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FW_Ext_Backups_Task_Collection $tasks
|
||||
* @internal
|
||||
*/
|
||||
public function _action_tasks_success(FW_Ext_Backups_Task_Collection $tasks) {
|
||||
$this->add_log(
|
||||
'success',
|
||||
$tasks->get_title()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $options {option_name: true}
|
||||
* @return array
|
||||
*/
|
||||
public function _filter_fw_ext_backups_db_restore_keep_options($options) {
|
||||
$options[ self::$wp_option] = true;
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exclude
|
||||
* @param string $option_name
|
||||
* @param bool $is_full_backup
|
||||
* @return bool
|
||||
*/
|
||||
public function _filter_fw_ext_backups_db_export_exclude_option($exclude, $option_name, $is_full_backup) {
|
||||
if (!$is_full_backup && $option_name === self::$wp_option) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $exclude;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _action_page_footer() {
|
||||
echo '<div id="fw-ext-backups-log"></div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return mixed
|
||||
* @internal
|
||||
*/
|
||||
public function _filter_fw_ext_backups_ajax_status_extra_response($data) {
|
||||
$data['log'] = array(
|
||||
'html' => $this->render_log(),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _action_enqueue_scripts() {
|
||||
wp_enqueue_style(
|
||||
'fw-ext-backups-log',
|
||||
self::backups()->get_uri('/includes/log/styles.css'),
|
||||
array(),
|
||||
self::backups()->manifest->get_version()
|
||||
);
|
||||
wp_enqueue_script(
|
||||
'fw-ext-backups-log',
|
||||
self::backups()->get_uri('/includes/log/scripts.js'),
|
||||
array('fw'),
|
||||
self::backups()->manifest->get_version()
|
||||
);
|
||||
}
|
||||
}
|
||||
new _FW_Ext_Backups_Log();
|
||||
@@ -0,0 +1,26 @@
|
||||
jQuery(function($){
|
||||
var inst = {
|
||||
localized: _fw_ext_backups_localized,
|
||||
$el: $('#fw-ext-backups-log'),
|
||||
onUpdating: function(){},
|
||||
onUpdate: function(data) {
|
||||
this.$el.html(data.log.html);
|
||||
},
|
||||
onUpdateFail: function() {},
|
||||
onUpdated: function() {},
|
||||
init: function(){
|
||||
fwEvents.on({
|
||||
'fw:ext:backups:status:updating': _.bind(this.onUpdating, this),
|
||||
'fw:ext:backups:status:update': _.bind(this.onUpdate, this),
|
||||
'fw:ext:backups:status:update-fail': _.bind(this.onUpdateFail, this),
|
||||
'fw:ext:backups:status:updated': _.bind(this.onUpdated, this)
|
||||
});
|
||||
|
||||
this.$el.on('click', '#fw-ext-backups-log-show-button a', function() {
|
||||
inst.$el.toggleClass('show-list');
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
inst.init();
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
#fw-ext-backups-log #fw-ext-backups-log-show-button .button-hide,
|
||||
#fw-ext-backups-log #fw-ext-backups-log-list {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#fw-ext-backups-log.show-list #fw-ext-backups-log-show-button .button-view {
|
||||
display: none;
|
||||
}
|
||||
#fw-ext-backups-log.show-list #fw-ext-backups-log-show-button .button-hide {
|
||||
display: inline;
|
||||
}
|
||||
#fw-ext-backups-log.show-list #fw-ext-backups-log-list {
|
||||
display: block;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
/**
|
||||
* @var array $log
|
||||
*/
|
||||
?>
|
||||
|
||||
<?php if ($log): ?>
|
||||
<div id="fw-ext-backups-log-show-button">
|
||||
<a href="#" onclick="return false;" class="button-view"><?php esc_html_e('View Activity Log', 'fw'); ?></a>
|
||||
<a href="#" onclick="return false;" class="button-hide"><?php esc_html_e('Hide Activity Log', 'fw'); ?></a>
|
||||
</div>
|
||||
<div id="fw-ext-backups-log-list">
|
||||
<ul>
|
||||
<?php foreach ($log as $l): ?>
|
||||
<?php
|
||||
switch (isset($l['type']) ? $l['type'] : '') {
|
||||
case 'success': $class = 'fw-text-success'; break;
|
||||
case 'info': $class = 'fw-text-info'; break;
|
||||
case 'warning': $class = 'fw-text-warning'; break;
|
||||
case 'error': $class = 'fw-text-danger'; break;
|
||||
default: $class = ''; break;
|
||||
}
|
||||
?>
|
||||
<li>
|
||||
<em><?php printf(esc_html__('%s ago', 'fw'), human_time_diff($l['time'])); ?></em>
|
||||
<span class="<?php echo esc_attr($class) ?>"><?php echo esc_html($l['title']); ?></span>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
abstract class _FW_Ext_Backups_Module {
|
||||
final public function __construct(FW_Access_Key $access_key) {
|
||||
if ($access_key->get_key() !== 'fw:ext:backups') {
|
||||
// only the Backups extension can create instances
|
||||
trigger_error(__METHOD__ .' denied', E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
abstract public function _init();
|
||||
}
|
||||
@@ -0,0 +1,383 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
class _FW_Ext_Backups_Module_Schedule extends _FW_Ext_Backups_Module {
|
||||
private static $wp_ajax_get_settings = 'fw:ext:backups:schedule:get-settings';
|
||||
private static $wp_ajax_set_settings = 'fw:ext:backups:schedule:set-settings';
|
||||
|
||||
private static $wp_option_settings = 'fw:ext:backups:schedule:settings';
|
||||
|
||||
private static $wp_cron_prefix = 'fw:ext:backups:cron:';
|
||||
|
||||
private static $default_lifetime = 7;
|
||||
|
||||
/**
|
||||
* @return FW_Extension_Backups
|
||||
*/
|
||||
private static function backups() {
|
||||
return fw_ext('backups');
|
||||
}
|
||||
|
||||
public function _init() {
|
||||
{
|
||||
add_action('fw:ext:backups:enqueue_scripts', array($this, '_action_enqueue_backup_scripts'));
|
||||
|
||||
add_action('wp_ajax_' . self::$wp_ajax_get_settings, array($this, '_action_ajax_get_settings'));
|
||||
add_action('wp_ajax_' . self::$wp_ajax_set_settings, array($this, '_action_ajax_set_settings'));
|
||||
|
||||
foreach (array('full', 'content') as $type) {
|
||||
add_action(self::$wp_cron_prefix . $type, array($this, '_action_cron_'. $type));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
add_filter('fw:ext:backups:script_localized_data', array($this, '_filter_script_localized_data'));
|
||||
add_filter('fw_ext_backups_ajax_status_extra_response', array($this, '_filter_ajax_status_response_data'));
|
||||
|
||||
add_filter('fw_ext_backups_db_export_exclude_option', array($this, '_filter_db_exclude_option'), 10, 2);
|
||||
add_filter('fw_ext_backups_db_restore_exclude_option', array($this, '_filter_db_exclude_option'), 10, 2);
|
||||
add_filter('fw_ext_backups_db_restore_keep_options', array($this, '_filter_db_restore_keep_options'));
|
||||
|
||||
add_filter('cron_schedules', array($this, '_filter_cron_schedules'));
|
||||
}
|
||||
|
||||
$this->cleanup();
|
||||
}
|
||||
|
||||
// At this hour the cron will be executed
|
||||
private function get_cron_run_hour() {
|
||||
return self::backups()->get_config('schedule.hour');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $hour 0..24
|
||||
* current_hour=22, hour=3, result=5 hours
|
||||
* current_hour=2, hour=3, result=1 hour
|
||||
* current_hour=5, hour=3, result=22 hours
|
||||
*
|
||||
* Test <?php
|
||||
fw_print(
|
||||
date('H:i:s', time()),
|
||||
date('H:i:s', $this->get_time_until_hour(3)),
|
||||
date('H:i:s', $this->get_time_until_hour(15)),
|
||||
date('H:i:s', $this->get_time_until_hour(21)),
|
||||
date('H:i:s', $this->get_time_until_hour(0)),
|
||||
date('H:i:s', $this->get_time_until_hour(24)),
|
||||
date('H:i:s', $this->get_time_until_hour(25)),
|
||||
date('H:i:s', $this->get_time_until_hour(85))
|
||||
);
|
||||
* ?>
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private function get_time_until_hour($hour) {
|
||||
if ($hour < 0 || $hour > 24) {
|
||||
$hour = 3;
|
||||
}
|
||||
|
||||
$result = $hour - (int)date('H'); // hours until give hour
|
||||
$result += $result < 1 ? 24 : 0; // add one day if hour already passed
|
||||
$result *= HOUR_IN_SECONDS; // transform hours to seconds
|
||||
$result -= ( // remove current minutes and seconds
|
||||
(MINUTE_IN_SECONDS + (int)date('i') * MINUTE_IN_SECONDS)
|
||||
-
|
||||
(MINUTE_IN_SECONDS - (int)date('s'))
|
||||
);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function get_options() {
|
||||
$options = fw_get_variables_from_file(
|
||||
dirname(__FILE__) .'/settings-options.php',
|
||||
array('options' => array())
|
||||
);
|
||||
|
||||
return $options['options'];
|
||||
}
|
||||
|
||||
private function get_settings($type = null) {
|
||||
$settings = get_option(self::$wp_option_settings, array(
|
||||
'full' => array(
|
||||
'interval' => '',
|
||||
'lifetime' => self::$default_lifetime,
|
||||
),
|
||||
'content' => array(
|
||||
'interval' => '',
|
||||
'lifetime' => self::$default_lifetime,
|
||||
),
|
||||
));
|
||||
|
||||
/**
|
||||
* In case wp option value and cron schedule will be different (after full restore or something else)
|
||||
* To be sure, use every time cron schedule value
|
||||
*/
|
||||
foreach ($settings as $_type => &$_settings) {
|
||||
$_settings['interval'] = (string)wp_get_schedule(self::$wp_cron_prefix . $_type);
|
||||
}
|
||||
|
||||
if (is_null($type)) {
|
||||
return $settings;
|
||||
} else {
|
||||
return $settings[$type];
|
||||
}
|
||||
}
|
||||
|
||||
private function set_settings($type, $settings) {
|
||||
if (!in_array($type, array('full', 'content'))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!in_array($settings['interval'], array('monthly', 'weekly', 'daily'))) {
|
||||
$settings['interval'] = '';
|
||||
}
|
||||
|
||||
if (($settings['lifetime'] = (int)$settings['lifetime']) < 1) {
|
||||
$settings['lifetime'] = self::$default_lifetime;
|
||||
}
|
||||
|
||||
$settings = array(
|
||||
'interval' => $settings['interval'],
|
||||
'lifetime' => $settings['lifetime'],
|
||||
);
|
||||
|
||||
$current_settings = $this->get_settings();
|
||||
$all_settings = array_merge(
|
||||
array(
|
||||
'full' => $current_settings['full'],
|
||||
'content' => $current_settings['content'],
|
||||
),
|
||||
array($type => $settings)
|
||||
);
|
||||
|
||||
update_option(
|
||||
self::$wp_option_settings,
|
||||
$all_settings,
|
||||
false
|
||||
);
|
||||
|
||||
// update cron
|
||||
{
|
||||
$hour = $this->get_cron_run_hour();
|
||||
|
||||
foreach ( $all_settings as $type => $settings ) {
|
||||
$hook = self::$wp_cron_prefix . $type;
|
||||
|
||||
wp_clear_scheduled_hook($hook);
|
||||
|
||||
if ( $settings['interval'] ) {
|
||||
wp_schedule_event(
|
||||
time() + $this->get_time_until_hour( $hour ),
|
||||
$settings['interval'],
|
||||
$hook
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function _filter_script_localized_data($data) {
|
||||
$data['schedule'] = array(
|
||||
'ajax_action' => array(
|
||||
'get_settings' => self::$wp_ajax_get_settings,
|
||||
'set_settings' => self::$wp_ajax_set_settings,
|
||||
),
|
||||
'popup_title' => __('Backup Schedule', 'fw'),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function _action_enqueue_backup_scripts() {
|
||||
fw()->backend->enqueue_options_static($this->get_options());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $exclude
|
||||
* @param string $option_name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function _filter_db_exclude_option($exclude, $option_name) {
|
||||
if ($option_name === self::$wp_option_settings) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $exclude;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $options {option_name: true}
|
||||
* @return array
|
||||
*/
|
||||
public function _filter_db_restore_keep_options($options) {
|
||||
$options[ self::$wp_option_settings ] = true;
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
public function _action_ajax_get_settings() {
|
||||
if (!current_user_can(self::backups()->get_capability())) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$settings = $this->get_settings();
|
||||
|
||||
$values = array(
|
||||
'full' => array(
|
||||
'interval' => $settings['full']['interval'],
|
||||
$settings['full']['interval'] => array(
|
||||
'lifetime' => $settings['full']['lifetime'],
|
||||
),
|
||||
),
|
||||
'content' => array(
|
||||
'interval' => $settings['content']['interval'],
|
||||
$settings['content']['interval'] => array(
|
||||
'lifetime' => $settings['content']['lifetime'],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
wp_send_json_success(array(
|
||||
'options' => $this->get_options(),
|
||||
'values' => $values,
|
||||
));
|
||||
}
|
||||
|
||||
public function _action_ajax_set_settings() {
|
||||
if (!current_user_can(self::backups()->get_capability())) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
if (
|
||||
empty($_POST['values'])
|
||||
||
|
||||
!is_array($values = $_POST['values'])
|
||||
) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
foreach (array('full', 'content') as $type) {
|
||||
if ($type === 'full' && !fw_ext_backups_current_user_can_full()) {
|
||||
$this->set_settings( $type, array(
|
||||
'interval' => '',
|
||||
'lifetime' => self::$default_lifetime,
|
||||
));
|
||||
} else {
|
||||
$this->set_settings( $type, array(
|
||||
'interval' => $values[ $type ]['interval'],
|
||||
'lifetime' => isset( $values[ $type ][ $values[ $type ]['interval'] ] )
|
||||
? $values[ $type ][ $values[ $type ]['interval'] ]['lifetime']
|
||||
: self::$default_lifetime,
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
wp_send_json_success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @link https://codex.wordpress.org/Plugin_API/Filter_Reference/cron_schedules
|
||||
* @param array $schedules
|
||||
* @return array
|
||||
*/
|
||||
public function _filter_cron_schedules($schedules) {
|
||||
$schedules['weekly'] = array(
|
||||
'interval' => 604800,
|
||||
'display' => __('Once Weekly')
|
||||
);
|
||||
$schedules['monthly'] = array(
|
||||
'interval' => 2635200,
|
||||
'display' => __('Once a month')
|
||||
);
|
||||
|
||||
return $schedules;
|
||||
}
|
||||
|
||||
public function _action_cron_full() {
|
||||
$this->cleanup();
|
||||
self::backups()->tasks()->do_backup(true);
|
||||
}
|
||||
|
||||
public function _action_cron_content() {
|
||||
$this->cleanup();
|
||||
self::backups()->tasks()->do_backup(false);
|
||||
}
|
||||
|
||||
private function cleanup() {
|
||||
foreach (array('full' => true, 'content' => false) as $type => $full) {
|
||||
$settings = $this->get_settings($type);
|
||||
|
||||
if (empty($settings['interval'])) { // this schedule is disabled
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
$time_step = null;
|
||||
|
||||
switch ($settings['interval']) {
|
||||
case 'monthly': $time_step = WEEK_IN_SECONDS * 4; break;
|
||||
case 'weekly': $time_step = WEEK_IN_SECONDS; break;
|
||||
case 'daily': $time_step = DAY_IN_SECONDS; break;
|
||||
}
|
||||
|
||||
if (is_null($time_step)) { // should not happen, but just in case
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (self::backups()->get_archives($full) as $archive) {
|
||||
if ($archive['time'] < time() - $settings['lifetime'] * $time_step) {
|
||||
unlink($archive['path']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function _filter_ajax_status_response_data($data) {
|
||||
$html = array();
|
||||
|
||||
foreach (array(
|
||||
'full' => esc_html__('Full', 'fw'),
|
||||
'content' => esc_html__('Content', 'fw')
|
||||
) as $type => $title) {
|
||||
$hook = self::$wp_cron_prefix . $type;
|
||||
|
||||
if (false === ($recurrence = wp_get_schedule($hook))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch ($recurrence) {
|
||||
case 'monthly': $recurrence_title = esc_html__('Monthly', 'fw'); break;
|
||||
case 'weekly': $recurrence_title = esc_html__('Weekly', 'fw'); break;
|
||||
case 'daily': $recurrence_title = esc_html__('Daily', 'fw'); break;
|
||||
default: $recurrence_title = $recurrence;
|
||||
}
|
||||
|
||||
$time = get_date_from_gmt(
|
||||
gmdate('Y-m-d H:i:s', wp_next_scheduled($hook)),
|
||||
get_option('date_format') . ' ' . get_option('time_format')
|
||||
);
|
||||
|
||||
$html[] =
|
||||
'<div class="updated"><p>'.
|
||||
/**/'<strong>'. $title .' '. esc_html__('Backup Schedule Active', 'fw') .'</strong>: '.
|
||||
/**/$recurrence_title .' | '. esc_html__('Next backup on', 'fw') .' '. $time .
|
||||
'</p></div>';
|
||||
}
|
||||
|
||||
if (empty($html)) {
|
||||
$html =
|
||||
'<div class="error"><p>' .
|
||||
/**/esc_html__( 'No backup schedule created yet! We advise you to do it asap!', 'fw' ) .
|
||||
'</p></div>';
|
||||
}
|
||||
|
||||
$data['schedule'] = array(
|
||||
'status_html' => $html,
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
$limits = apply_filters('fw_ext_backups_schedule_lifetime_limits', array(
|
||||
'monthly' => 12,
|
||||
'weekly' => 4,
|
||||
'daily' => 7,
|
||||
));
|
||||
|
||||
$sub_options = array(
|
||||
'type' => 'multi-picker',
|
||||
'label' => false,
|
||||
'desc' => false,
|
||||
'show_borders' => true,
|
||||
'picker' => array(
|
||||
'interval' => array(
|
||||
'label' => __('Interval', 'fw'),
|
||||
'type' => 'radio',
|
||||
'inline' => true,
|
||||
'choices' => array(
|
||||
'' => __('Disabled', 'fw'),
|
||||
'monthly' => __('Monthly', 'fw'),
|
||||
'weekly' => __('Weekly', 'fw'),
|
||||
'daily' => __('Daily', 'fw'),
|
||||
),
|
||||
'desc' => __('Select how often do you want to backup your website.', 'fw'),
|
||||
)
|
||||
),
|
||||
'choices' => array(
|
||||
'monthly' => array(
|
||||
'lifetime' => array(
|
||||
'type' => 'short-slider',
|
||||
'label' => __('Age Limit', 'fw'),
|
||||
'desc' => __('Age limit of backups in months', 'fw'),
|
||||
'value' => $limits['monthly'],
|
||||
'properties' => array(
|
||||
'min' => 1,
|
||||
'max' => $limits['monthly'],
|
||||
'grid_snap' => true,
|
||||
),
|
||||
),
|
||||
),
|
||||
'weekly' => array(
|
||||
'lifetime' => array(
|
||||
'type' => 'short-slider',
|
||||
'label' => __('Age Limit', 'fw'),
|
||||
'desc' => __('Age limit of backups in weeks', 'fw'),
|
||||
'value' => $limits['weekly'],
|
||||
'properties' => array(
|
||||
'min' => 1,
|
||||
'max' => $limits['weekly'],
|
||||
'grid_snap' => true,
|
||||
),
|
||||
),
|
||||
),
|
||||
'daily' => array(
|
||||
'lifetime' => array(
|
||||
'type' => 'short-slider',
|
||||
'label' => __('Age Limit', 'fw'),
|
||||
'desc' => __('Age limit of backups in days', 'fw'),
|
||||
'value' => $limits['daily'],
|
||||
'properties' => array(
|
||||
'min' => 1,
|
||||
'max' => $limits['daily'],
|
||||
'grid_snap' => true,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$options = array();
|
||||
|
||||
if (fw_ext_backups_current_user_can_full()) {
|
||||
$options['full'] = array(
|
||||
'type' => 'tab',
|
||||
'title' => __( 'Full Backup', 'fw' ),
|
||||
'options' => array(
|
||||
'full' => $sub_options,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
$options['content'] = array(
|
||||
'type' => 'tab',
|
||||
'title' => __('Content Backup', 'fw'),
|
||||
'options' => array(
|
||||
'content' => $sub_options,
|
||||
),
|
||||
);
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
class _FW_Ext_Backups_Task_Type_Register {
|
||||
/**
|
||||
* @var FW_Ext_Backups_Task_Type[]
|
||||
*/
|
||||
private $task_types = array();
|
||||
|
||||
public function register(FW_Ext_Backups_Task_Type $type) {
|
||||
if (isset($this->task_types[$type->get_type()])) {
|
||||
throw new Exception('Backup Task Type '. $type->get_type() .' already exists');
|
||||
}
|
||||
|
||||
$this->task_types[$type->get_type()] = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FW_Access_Key $access_key
|
||||
*
|
||||
* @return FW_Ext_Backups_Task_Type[]
|
||||
* @internal
|
||||
*/
|
||||
public function _get_task_types(FW_Access_Key $access_key) {
|
||||
if ($access_key->get_key() !== 'fw:ext:backups:tasks') {
|
||||
trigger_error('Method call denied', E_USER_ERROR);
|
||||
}
|
||||
|
||||
return $this->task_types;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
abstract class FW_Ext_Backups_Task_Type {
|
||||
/**
|
||||
* @return string Unique type
|
||||
*/
|
||||
abstract public function get_type();
|
||||
|
||||
/**
|
||||
* @param array $args Same $args sent to $this->execute()
|
||||
* @param array $state Same $state returned by $this->execute()
|
||||
* @return string
|
||||
*/
|
||||
abstract public function get_title(array $args = array(), array $state = array());
|
||||
|
||||
/**
|
||||
* Execute a step
|
||||
*
|
||||
* @param array $args
|
||||
* @param array $state Continue from the last step state
|
||||
*
|
||||
* @return array|true|WP_Error
|
||||
* * array - current state, task is not finished (should continue)
|
||||
* * true - task finished successfully
|
||||
* * WP_Error - task failed
|
||||
*/
|
||||
abstract public function execute(array $args, array $state = array());
|
||||
|
||||
/**
|
||||
* @param array $args
|
||||
* @param array $state
|
||||
* @return int
|
||||
*/
|
||||
public function get_custom_timeout(array $args, array $state = array()) {}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class FW_Ext_Backups_Task_Collection {
|
||||
/**
|
||||
* @var string
|
||||
* @since 2.0.0
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @since 2.0.0
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* @var FW_Ext_Backups_Task[]
|
||||
* @since 2.0.0
|
||||
*/
|
||||
private $tasks = array();
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
*/
|
||||
public function __construct($id = null) {
|
||||
$this->id = (string)(is_null($id) ? fw_rand_md5() : $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param FW_Ext_Backups_Task $task
|
||||
*
|
||||
* @return bool
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function add_task(FW_Ext_Backups_Task $task) {
|
||||
if (in_array($task, $this->tasks, true)) {
|
||||
return false;
|
||||
} else {
|
||||
foreach ($this->tasks as $_task) {
|
||||
if ($_task->get_id() === $task->get_id()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$this->tasks[] = $task;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_id() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function get_title() {
|
||||
if (is_null($this->title)) {
|
||||
return fw_id_to_title($this->id);
|
||||
} else {
|
||||
return $this->title;
|
||||
}
|
||||
}
|
||||
|
||||
public function set_title($title) {
|
||||
$this->title = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return FW_Ext_Backups_Task[]
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_tasks() {
|
||||
return $this->tasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Empty out the collection internal state and return the deleted tasks
|
||||
*
|
||||
* @return FW_Ext_Backups_Task[]
|
||||
* @since 2.0.17
|
||||
*/
|
||||
public function empty_collection() {
|
||||
$tmp = $this->tasks;
|
||||
|
||||
$this->tasks = array();
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
*
|
||||
* @return FW_Ext_Backups_Task|null
|
||||
* @since 2.0.0
|
||||
*
|
||||
* Note: The returned instance will be changed by reference https://3v4l.org/Ps5hs (use `clone $instance`)
|
||||
*/
|
||||
public function get_task($id) {
|
||||
if (empty($this->tasks)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($this->tasks as $task) {
|
||||
if ($task->get_id() === $id) {
|
||||
return $task;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the collection is in a state that can be Cancelled/Aborted
|
||||
* @return bool
|
||||
*/
|
||||
public function is_cancelable() {
|
||||
$tasks = $this->get_tasks();
|
||||
|
||||
if (
|
||||
($first_task = reset($tasks))
|
||||
&&
|
||||
!$first_task->get_last_execution_start_time()
|
||||
) {
|
||||
return true; // The execution haven't started
|
||||
}
|
||||
|
||||
foreach ($tasks as $task) {
|
||||
if ( ! $task->get_last_execution_start_time() ) {
|
||||
return false; // We reached a pending task
|
||||
} elseif ( ! $task->get_last_execution_end_time() ) {
|
||||
/** @var FW_Extension_Backups $ext */
|
||||
$ext = fw_ext('backups');
|
||||
|
||||
if (($task->get_last_execution_start_time() + $ext->get_task_step_execution_threshold()) < time()) {
|
||||
return true; // The task is execution for a too long time
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function to_array() {
|
||||
$tasks = array();
|
||||
foreach ($this->get_tasks() as $task) {
|
||||
$tasks[] = $task->to_array();
|
||||
}
|
||||
|
||||
return array(
|
||||
'id' => $this->get_id(),
|
||||
'title' => $this->title,
|
||||
'tasks' => $tasks,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $c
|
||||
*
|
||||
* @return FW_Ext_Backups_Task_Collection
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public static function from_array(array $c) {
|
||||
if (empty($c)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$collection = new self($c['id']);
|
||||
|
||||
if (isset($c['title'])) {
|
||||
$collection->set_title($c['title']);
|
||||
}
|
||||
|
||||
foreach ($c['tasks'] as $t) {
|
||||
$collection->add_task(
|
||||
FW_Ext_Backups_Task::from_array($t)
|
||||
);
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* @since 2.0.0
|
||||
*/
|
||||
final class FW_Ext_Backups_Task {
|
||||
/**
|
||||
* @var string
|
||||
* @since 2.0.0
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* A registered type that will process this task
|
||||
* @var string
|
||||
* @since 2.0.0
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
* @since 2.0.0
|
||||
*/
|
||||
private $args = array();
|
||||
|
||||
/**
|
||||
* @var int timestamp
|
||||
* @since 2.0.0
|
||||
* @internal
|
||||
*/
|
||||
private $last_execution_start_time;
|
||||
|
||||
/**
|
||||
* @var int timestamp
|
||||
* @since 2.0.0
|
||||
* @internal
|
||||
*/
|
||||
private $last_execution_end_time;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
* // null - in progress, not finished yet
|
||||
* // {...} - step finished successfully. current state. task not finished
|
||||
* // true - task finished successfully
|
||||
* // string - task finished successfully with message
|
||||
* // false - task failed
|
||||
* // WP_Error - task failed with message
|
||||
* @since 2.0.0
|
||||
* @internal
|
||||
*/
|
||||
private $result;
|
||||
|
||||
public function __construct($id, $type, $args = array()) {
|
||||
$this->id = (string)$id;
|
||||
$this->type = (string)$type;
|
||||
$this->set_args($args);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_id() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_type() {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_args() {
|
||||
return $this->args;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $args
|
||||
*
|
||||
* @return $this
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function set_args(array $args) {
|
||||
$this->args = $args;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
* @since 2.0.0
|
||||
* @internal
|
||||
*/
|
||||
public function get_last_execution_start_time() {
|
||||
return $this->last_execution_start_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $last_execution_start_time
|
||||
*
|
||||
* @return $this
|
||||
* @since 2.0.0
|
||||
* @internal
|
||||
*/
|
||||
public function set_last_execution_start_time($last_execution_start_time) {
|
||||
$this->last_execution_start_time = $last_execution_start_time;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null
|
||||
* @since 2.0.0
|
||||
* @internal
|
||||
*/
|
||||
public function get_last_execution_end_time() {
|
||||
return $this->last_execution_end_time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $last_execution_end_time
|
||||
*
|
||||
* @return $this
|
||||
* @since 2.0.0
|
||||
* @internal
|
||||
*/
|
||||
public function set_last_execution_end_time($last_execution_end_time) {
|
||||
$this->last_execution_end_time = $last_execution_end_time;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|array|true|string|false|WP_Error
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function get_result() {
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $result
|
||||
*
|
||||
* @return $this
|
||||
* @since 2.0.0
|
||||
* @internal
|
||||
*/
|
||||
public function set_result($result) {
|
||||
if (
|
||||
in_array($result, array(null, true, false), true)
|
||||
||
|
||||
is_string($result)
|
||||
||
|
||||
is_array($result)
|
||||
||
|
||||
is_wp_error($result)
|
||||
) {} else {
|
||||
throw new LogicException('Not supported result value');
|
||||
}
|
||||
|
||||
$this->result = $result;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool Task execution finished and will never continue/execute
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function result_is_finished() {
|
||||
return !(
|
||||
is_null($this->get_result())
|
||||
||
|
||||
is_array($this->get_result())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function result_is_fail() {
|
||||
return (
|
||||
$this->get_result() === false
|
||||
||
|
||||
is_wp_error($this->get_result())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function result_is_success() {
|
||||
return (
|
||||
$this->get_result() === true
|
||||
||
|
||||
is_string($this->get_result())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @since 2.0.0
|
||||
* @internal
|
||||
*/
|
||||
public function to_array() {
|
||||
return array(
|
||||
'id' => $this->get_id(),
|
||||
'type' => $this->get_type(),
|
||||
'args' => $this->get_args(),
|
||||
'last_execution_start_time' => $this->get_last_execution_start_time(),
|
||||
'last_execution_end_time' => $this->get_last_execution_end_time(),
|
||||
'result' => $this->get_result(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $t
|
||||
*
|
||||
* @return FW_Ext_Backups_Task
|
||||
* @since 2.0.0
|
||||
* @internal
|
||||
*/
|
||||
public static function from_array(array $t) {
|
||||
$task = new self($t['id'], $t['type'], $t['args']);
|
||||
$task->set_last_execution_start_time($t['last_execution_start_time']);
|
||||
$task->set_last_execution_end_time($t['last_execution_end_time']);
|
||||
$task->set_result($t['result']);
|
||||
|
||||
return $task;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,412 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* Exported format: Lines of JSON objects
|
||||
*
|
||||
* {
|
||||
* type: "table",
|
||||
* data: {
|
||||
* name: "table_name", // without wp prefix
|
||||
* opts: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci",
|
||||
* columns: {
|
||||
* 'column_name': 'bigint(20) unsigned NOT NULL AUTO_INCREMENT'
|
||||
* },
|
||||
* indexes: [
|
||||
* 'PRIMARY KEY (`meta_id`)',
|
||||
* 'KEY `comment_id` (`comment_id`)'
|
||||
* ]
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* {
|
||||
* type: "row",
|
||||
* data: {
|
||||
* table: "table_name", // without wp prefix
|
||||
* row: {
|
||||
* "column_name": "column_value",
|
||||
* ...
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
class FW_Ext_Backups_Task_Type_DB_Export extends FW_Ext_Backups_Task_Type {
|
||||
public function get_type() {
|
||||
return 'db-export';
|
||||
}
|
||||
|
||||
public function get_title(array $args = array(), array $state = array()) {
|
||||
return __('Database export', 'fw');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @param array $args
|
||||
* * dir - destination directory in which will be created `database.json.txt`
|
||||
*/
|
||||
public function execute(array $args, array $state = array()) {
|
||||
{
|
||||
if (!isset($args['dir'])) {
|
||||
return new WP_Error(
|
||||
'no_destination_dir', __('Destination dir not specified', 'fw')
|
||||
);
|
||||
}
|
||||
|
||||
$args['full'] = isset($args['full']) ? (bool)$args['full'] : false;
|
||||
}
|
||||
|
||||
$tables = $this->get_tables($args['full']);
|
||||
|
||||
if (empty($state)) {
|
||||
$state = array(
|
||||
'table' => key($tables),
|
||||
'limit' => 0,
|
||||
'params' => false, // if params exported or not
|
||||
);
|
||||
} else {
|
||||
$state['limit'] = (int)$state['limit']; // just to make sure. this will not be escaped in sql
|
||||
}
|
||||
|
||||
if (!isset($tables[$state['table']])) {
|
||||
return new WP_Error(
|
||||
'table_disappeared', __('Database table disappeared', 'fw')
|
||||
);
|
||||
}
|
||||
|
||||
$backups = fw_ext('backups'); /** @var FW_Extension_Backups $backups */
|
||||
$exclude_options = $backups->get_config('db.backup.exclude_options');
|
||||
|
||||
global $wpdb; /** @var WPDB $wpdb */
|
||||
|
||||
$max_time = time() + fw_ext( 'backups' )->get_timeout(-7);
|
||||
|
||||
while (time() < $max_time) {
|
||||
// open file for writing
|
||||
{
|
||||
$file_path = $args['dir'] .'/database.json.txt';
|
||||
|
||||
if (!file_exists($file_path)) {
|
||||
if (!($fp = @fopen($file_path, 'w'))) {
|
||||
return new WP_Error(
|
||||
'cannot_create_file', __('Cannot create file', 'fw') .': '. $file_path
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (!($fp = @fopen($file_path, 'a'))) {
|
||||
return new WP_Error(
|
||||
'cannot_reopen_file', __('Cannot reopen file', 'fw') .': '. $file_path
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$state['params']) {
|
||||
fwrite(
|
||||
$fp,
|
||||
json_encode(array(
|
||||
'type' => 'param',
|
||||
'data' => array(
|
||||
'name' => 'wpdb_prefix',
|
||||
'value' => $wpdb->prefix,
|
||||
),
|
||||
)) . "\n"
|
||||
);
|
||||
|
||||
{
|
||||
$tmp = wp_upload_dir();
|
||||
|
||||
fwrite(
|
||||
$fp,
|
||||
json_encode(array(
|
||||
'type' => 'param',
|
||||
'data' => array(
|
||||
'name' => 'wp_upload_dir_baseurl',
|
||||
'value' => $tmp['baseurl'],
|
||||
),
|
||||
)) . "\n"
|
||||
);
|
||||
|
||||
unset($tmp);
|
||||
}
|
||||
|
||||
$state['params'] = true;
|
||||
}
|
||||
|
||||
if ($state['limit'] == 0) { // create table before data insert
|
||||
$sql = $wpdb->get_col('SHOW CREATE TABLE '. $wpdb->prefix . esc_sql($state['table']), 1);
|
||||
|
||||
if (empty($sql)) {
|
||||
fclose($fp);
|
||||
return new WP_Error(
|
||||
'create_table_sql',
|
||||
sprintf(__('Cannot export CREATE TABLE sql for %s', 'fw'), $state['table'])
|
||||
.( $wpdb->last_error ? '. '. $wpdb->last_error : '' )
|
||||
);
|
||||
} else {
|
||||
$sql = $sql[0];
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'name' => $state['table'],
|
||||
'opts' => '', // 'ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci'
|
||||
'columns' => array(
|
||||
// 'column_name' => 'bigint(20) unsigned NOT NULL AUTO_INCREMENT'
|
||||
),
|
||||
'indexes' => array(
|
||||
// 'PRIMARY KEY (`meta_id`)'
|
||||
// 'KEY `comment_id` (`comment_id`)'
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Remove 'CREATE TABLE `wp_...` ('
|
||||
*/
|
||||
{
|
||||
$sql = explode('(', $sql);
|
||||
array_shift($sql);
|
||||
$sql = implode('(', $sql);
|
||||
}
|
||||
|
||||
{
|
||||
$sql = explode(')', $sql);
|
||||
$data['opts'] = trim(array_pop($sql));
|
||||
$sql = implode(')', $sql);
|
||||
}
|
||||
|
||||
foreach (explode(",\n", trim($sql)) as $column_or_index) {
|
||||
$column_or_index = trim($column_or_index);
|
||||
|
||||
if (empty($column_or_index)) continue; // don't know when this happens, just in case
|
||||
|
||||
if ($column_or_index{0} === '`') { // column
|
||||
$column_or_index = explode(' ', $column_or_index);
|
||||
$column_name = trim(array_shift($column_or_index), '`');
|
||||
$column_or_index = implode(' ', $column_or_index);
|
||||
$column_opts = $column_or_index;
|
||||
|
||||
$data['columns'][ $column_name ] = $column_opts;
|
||||
} else {
|
||||
$data['indexes'][] = $column_or_index;
|
||||
}
|
||||
}
|
||||
|
||||
fwrite(
|
||||
$fp,
|
||||
json_encode(array(
|
||||
'type' => 'table',
|
||||
'data' => $data
|
||||
)) . "\n"
|
||||
);
|
||||
|
||||
unset($sql, $data);
|
||||
}
|
||||
|
||||
if (!($column = $this->get_table_order_by_column($state['table']))) {
|
||||
$state['table'] = $this->get_next_table($state['table'], $args['full']);
|
||||
|
||||
if (is_null($state['table'])) {
|
||||
fclose($fp);
|
||||
return true;
|
||||
} elseif (false === $state['table']) {
|
||||
fclose($fp);
|
||||
return new WP_Error(
|
||||
'no_next_table', __('Cannot get next database table', 'fw')
|
||||
);
|
||||
} else {
|
||||
$state['limit'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$limit = $this->get_table_limit($state['table']);
|
||||
|
||||
$count = 0;
|
||||
|
||||
foreach ($wpdb->get_results(
|
||||
'SELECT * FROM '. $wpdb->prefix . esc_sql($state['table'])
|
||||
.' ORDER BY '. esc_sql($column)
|
||||
.' LIMIT '. $state['limit'] .','. $limit,
|
||||
ARRAY_A
|
||||
) as $row) {
|
||||
$count++;
|
||||
|
||||
if ('options' === $state['table']) {
|
||||
if (
|
||||
(
|
||||
!$args['full'] && isset($exclude_options[ $row['option_name'] ])
|
||||
)
|
||||
||
|
||||
apply_filters('fw_ext_backups_db_export_exclude_option', false,
|
||||
$row['option_name'], $args['full']
|
||||
)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
fwrite(
|
||||
$fp,
|
||||
json_encode(array(
|
||||
'type' => 'row',
|
||||
'data' => array(
|
||||
'table' => $state['table'],
|
||||
'row' => $row,
|
||||
)
|
||||
)) . "\n"
|
||||
);
|
||||
}
|
||||
|
||||
fclose($fp);
|
||||
|
||||
if ($count > 0 && $count == $limit) {
|
||||
$state['limit'] += $limit;
|
||||
} else {
|
||||
$state['table'] = $this->get_next_table($state['table'], $args['full']);
|
||||
|
||||
if (is_null($state['table'])) {
|
||||
return true;
|
||||
} elseif (false === $state['table']) {
|
||||
return new WP_Error(
|
||||
'no_next_table', __('Cannot get next database table', 'fw')
|
||||
);
|
||||
} else {
|
||||
$state['limit'] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache
|
||||
* @var array
|
||||
*/
|
||||
private $tables;
|
||||
|
||||
/**
|
||||
* @param bool $is_full
|
||||
* @return array {'table_name': {}} Note: Table name is without $wpdb->prefix
|
||||
*/
|
||||
private function get_tables($is_full) {
|
||||
if (is_null($this->tables)) {
|
||||
global $wpdb; /** @var WPDB $wpdb */
|
||||
|
||||
$tables = $wpdb->get_col(
|
||||
$wpdb->prepare(
|
||||
'SHOW TABLES LIKE %s',
|
||||
$wpdb->esc_like($wpdb->prefix) .'%'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Use /i in regex because prefix can be mixed case.
|
||||
* Fixes https://github.com/ThemeFuse/Unyson/issues/2068#issuecomment-250196792
|
||||
*/
|
||||
$prefix_regex = '/^'. preg_quote($wpdb->prefix, '/') .'/i';
|
||||
|
||||
foreach ($tables as $i => $table) {
|
||||
$tables[$i] = preg_replace($prefix_regex, '', $table);
|
||||
|
||||
if (is_numeric($tables[$i]{0})) {
|
||||
/**
|
||||
* Skip multisite tables '1_options' (wp_1_options)
|
||||
* This happens when export is done on main site.
|
||||
* So when doing export on main site,
|
||||
* only main site tables will be exported, without sub sites tables.
|
||||
*/
|
||||
unset($tables[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
asort( $tables );
|
||||
|
||||
$this->tables = array_fill_keys( $tables, array() );
|
||||
|
||||
if (!$is_full) {
|
||||
/** @since 2.0.24 */
|
||||
$this->tables = apply_filters( 'fw:ext:backups:db-export:tables', $this->tables );
|
||||
}
|
||||
}
|
||||
|
||||
if ($is_full) {
|
||||
return $this->tables;
|
||||
} else {
|
||||
$tables = $this->tables;
|
||||
|
||||
foreach(array_keys(array(
|
||||
'users' => true,
|
||||
'usermeta' => true,
|
||||
|
||||
'blogs' => true,
|
||||
'blog_versions' => true,
|
||||
'registration_log' => true,
|
||||
'signups' => true,
|
||||
'site' => true,
|
||||
'sitemeta' => true,
|
||||
'sitecategories' => true
|
||||
)) as $excluded_table) {
|
||||
unset($tables[$excluded_table]);
|
||||
}
|
||||
|
||||
return $tables;
|
||||
}
|
||||
}
|
||||
|
||||
private function get_next_table($name, $is_full) {
|
||||
$tables = $this->get_tables($is_full);
|
||||
$keys = array_keys($tables);
|
||||
$index = array_search($name, $keys);
|
||||
|
||||
if ($index === false) {
|
||||
return false;
|
||||
} elseif (isset($keys[$index + 1])) {
|
||||
return $keys[$index + 1];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache
|
||||
* @var array {'table' => 'column'}
|
||||
*/
|
||||
private $table_order_by_columns = array();
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
private function get_table_order_by_column($name) {
|
||||
if (!isset($this->table_order_by_columns[$name])) {
|
||||
global $wpdb; /** @var WPDB $wpdb */
|
||||
|
||||
$columns = $wpdb->get_results( 'SHOW COLUMNS FROM '. $wpdb->prefix . esc_sql($name), ARRAY_A );
|
||||
|
||||
if (empty($columns)) {
|
||||
// table has no columns, not sure when this can happen, but better treat this case
|
||||
$this->table_order_by_columns[$name] = false;
|
||||
} else {
|
||||
foreach ( $columns as $colum ) {
|
||||
if ( $colum['Key'] === 'PRI' ) { // Column is primary key
|
||||
$this->table_order_by_columns[ $name ] = $colum['Field'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If table has no primary key, just use first column
|
||||
$this->table_order_by_columns[ $name ] = $columns[0]['Field'];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->table_order_by_columns[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name Can be tables that can contain a lot of data in a single row, and can have a lower limit
|
||||
*
|
||||
* @return int How much rows to select in one query
|
||||
*/
|
||||
private function get_table_limit($name) {
|
||||
return 100;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
/**
|
||||
* Delete everything from the given directory
|
||||
*/
|
||||
class FW_Ext_Backups_Task_Type_Dir_Clean extends FW_Ext_Backups_Task_Type {
|
||||
public function get_type() {
|
||||
return 'dir-clean';
|
||||
}
|
||||
|
||||
public function get_title(array $args = array(), array $state = array()) {
|
||||
return __('Directory Cleanup', 'fw');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute(array $args, array $state = array()) {
|
||||
if (!isset($args['dir'])) {
|
||||
return new WP_Error(
|
||||
'no_dir', __('Dir not specified', 'fw')
|
||||
);
|
||||
}
|
||||
|
||||
$dir = $args['dir'];
|
||||
|
||||
if (file_exists($dir)) {
|
||||
if (!fw_ext_backups_rmdir_recursive($dir)) {
|
||||
return new WP_Error(
|
||||
'rmdir_fail', __('Cannot remove directory', 'fw') .': '. $dir
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!mkdir($dir, 0777, true)) {
|
||||
return new WP_Error(
|
||||
'mkdir_fail', __('Cannot create directory', 'fw') .': '. $dir
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional backups dir security check
|
||||
*/
|
||||
{
|
||||
$backups_dir = fw_ext('backups')->get_backups_dir();
|
||||
|
||||
if (!file_exists("$backups_dir/index.php")) {
|
||||
$contents = implode("\n", array(
|
||||
'<?php',
|
||||
'header(\'HTTP/1.0 403 Forbidden\');',
|
||||
'die(\'<h1>Forbidden</h1>\');'
|
||||
));
|
||||
if (@file_put_contents("$backups_dir/index.php", $contents) === false) {
|
||||
return new WP_Error(
|
||||
'index_create_fail', sprintf( __('Cannot create file: %s', 'fw'), "$backups_dir/index.php" )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!file_exists("$backups_dir/.htaccess")) {
|
||||
$contents = implode("\n", array(
|
||||
'Deny from all',
|
||||
'<IfModule mod_rewrite.c>',
|
||||
' RewriteEngine On',
|
||||
' RewriteRule . - [R=404,L]',
|
||||
'</IfModule>'
|
||||
));
|
||||
if (@file_put_contents("$backups_dir/.htaccess", $contents) === false) {
|
||||
return new WP_Error(
|
||||
'htaccess_create_fail', sprintf( __('Cannot create file: %s', 'fw'), "$backups_dir/htaccess" )
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
class FW_Ext_Backups_Task_Type_Files_Export extends FW_Ext_Backups_Task_Type {
|
||||
public function get_type() {
|
||||
return 'files-export';
|
||||
}
|
||||
|
||||
public function get_title(array $args = array(), array $state = array()) {
|
||||
return __('Files Export', 'fw');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @param array $args
|
||||
* * source_dirs - {'dir_id': 'dir_path'}
|
||||
* * destination - dir
|
||||
* * [exclude_paths] - {'dir_path': true}
|
||||
*/
|
||||
public function execute(array $args, array $state = array()) {
|
||||
$backups = fw_ext('backups'); /** @var FW_Extension_Backups $backups */
|
||||
|
||||
{
|
||||
if (empty($args['source_dirs'])) {
|
||||
return new WP_Error(
|
||||
'no_source', __('Source dirs not specified', 'fw')
|
||||
);
|
||||
} else {
|
||||
$args['source_dirs'] = array_filter(array_map('fw_fix_path', $args['source_dirs']), 'file_exists');
|
||||
}
|
||||
|
||||
if (empty($args['destination'])) {
|
||||
return new WP_Error(
|
||||
'no_destination', __('Destination not specified', 'fw')
|
||||
);
|
||||
} else {
|
||||
$args['destination'] = fw_fix_path($args['destination']);
|
||||
}
|
||||
|
||||
{
|
||||
if (empty($args['exclude_paths'])) {
|
||||
$args['exclude_paths'] = array(
|
||||
// '/path/to/dir' => true,
|
||||
// '/path/to/file.txt' => true, // NOT WORKING. If you need this feature let us know
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 2.0.18
|
||||
*/
|
||||
$args['exclude_paths'] = apply_filters(
|
||||
'fw:ext:backups:task-type:files-export:exclude-paths',
|
||||
$args['exclude_paths']
|
||||
);
|
||||
|
||||
$wp_upload_dir = wp_upload_dir();
|
||||
|
||||
$args['exclude_paths'] = array_merge($args['exclude_paths'], array(
|
||||
$backups->get_backups_dir() => true,
|
||||
$backups->get_tmp_dir() => true, // by default it's in backups dir, just in case it will be changed
|
||||
fw_fix_path($wp_upload_dir['basedir']) .'/backup' => true, // Backup v1
|
||||
fw_fix_path($wp_upload_dir['basedir']) .'/fw' => true, // created in Unyson 2.6.0 by FW_File_Cache
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($state)) {
|
||||
$state = array(
|
||||
'dir_id' => key($args['source_dirs']),
|
||||
'dirs' => array(
|
||||
// 'parent_dir', 'dir', 'sub_dir' // --> {source_dir}/parent_dir/dir/sub_dir
|
||||
),
|
||||
'file' => '', // --> {source_dir}/parent_dir/dir/sub_dir/{file}
|
||||
);
|
||||
}
|
||||
|
||||
$max_time = time() + fw_ext( 'backups' )->get_timeout(-7);
|
||||
|
||||
while (time() < $max_time) {
|
||||
if (empty($args['source_dirs'][ $state['dir_id'] ])) {
|
||||
return new WP_Error(
|
||||
'source_dir_empty',
|
||||
sprintf(__('Source dir %s is empty', 'fw'), $state['dir_id'])
|
||||
);
|
||||
}
|
||||
|
||||
if (is_wp_error($files = $this->get_next_files(
|
||||
$args['source_dirs'][ $state['dir_id'] ],
|
||||
$state['dirs'],
|
||||
$state['file'],
|
||||
$args['exclude_paths']
|
||||
))) {
|
||||
return $files;
|
||||
} elseif ($files === true) {
|
||||
// move to the next source dir
|
||||
{
|
||||
while (key($args['source_dirs']) !== $state['dir_id']) {
|
||||
next($args['source_dirs']);
|
||||
}
|
||||
|
||||
next($args['source_dirs']);
|
||||
}
|
||||
|
||||
if ($state['dir_id'] = key($args['source_dirs'])) {
|
||||
$state['dirs'] = array();
|
||||
$state['file'] = '';
|
||||
continue;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$rel_dir = empty($state['dirs']) ? '' : '/'. implode('/', $state['dirs']);
|
||||
$source_dir = $args['source_dirs'][ $state['dir_id'] ] . $rel_dir;
|
||||
$destination_dir = $args['destination'] .'/'. $state['dir_id'] . $rel_dir;
|
||||
$created_dirs = array();
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (!isset($created_dirs[$destination_dir])) {
|
||||
if (!is_dir($destination_dir)) {
|
||||
if ($source_dir_chmod = substr(sprintf('%o', fileperms($source_dir)), -4)) {
|
||||
$source_dir_chmod = intval($source_dir_chmod, 8);
|
||||
} else {
|
||||
return new WP_Error(
|
||||
'get_dir_chmod_fail', __('Failed to get dir chmod', 'fw')
|
||||
);
|
||||
}
|
||||
|
||||
if (!mkdir($destination_dir, $source_dir_chmod, true)) {
|
||||
return new WP_Error(
|
||||
'destination_dir_create_fail',
|
||||
__('Failed to create destination dir', 'fw'),
|
||||
array('dir' => $destination_dir,)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$created_dirs[$destination_dir] = true;
|
||||
}
|
||||
|
||||
if (!copy(
|
||||
$source_dir .'/'. $file,
|
||||
$destination_dir .'/'. $file
|
||||
)) {
|
||||
return new WP_Error(
|
||||
'copy_failed', sprintf(__('Failed to copy: %s', 'fw'), $source_dir .'/'. $file)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$state['file'] = $file;
|
||||
}
|
||||
|
||||
return $state;
|
||||
}
|
||||
|
||||
private function get_max_files_per_cycle() {
|
||||
return 33;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $root_dir
|
||||
* @param array $dirs
|
||||
* @param string $previous_file
|
||||
* @param array $exclude_paths
|
||||
* @return array|true|WP_Error ['file.txt', 'file.php', ...]
|
||||
* Important: It will never return an empty array. Only: (array)files, true, WP_Error
|
||||
*/
|
||||
private function get_next_files($root_dir, array &$dirs, $previous_file, array $exclude_paths) {
|
||||
$rel_dir = empty($dirs) ? '' : '/'. implode('/', $dirs);
|
||||
$included_hidden_names = fw_ext('backups')->get_config('included_hidden_names');
|
||||
|
||||
if ($names = array_diff(($names = scandir($dir = $root_dir . $rel_dir)) ? $names : array(), array('.', '..'))) {
|
||||
$files = array(); // result
|
||||
$file_found = empty($previous_file); // find previous file and return next files
|
||||
$count = 0;
|
||||
|
||||
foreach ($names as $file) {
|
||||
$path = $dir .'/'. $file;
|
||||
|
||||
if (!$file_found) {
|
||||
$file_found = ($file === $previous_file);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($file{0} === '.' && !isset($included_hidden_names[$file])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_dir($path)) {
|
||||
if (isset($exclude_paths[ fw_fix_path($path) ])) {
|
||||
continue;
|
||||
} elseif ($files) { // return collected files, will go inside directory on next call
|
||||
return $files;
|
||||
} else {
|
||||
$dirs[] = $file;
|
||||
|
||||
return $this->get_next_files($root_dir, $dirs, '', $exclude_paths);
|
||||
}
|
||||
} else {
|
||||
$files[] = $file;
|
||||
|
||||
if (++$count > $this->get_max_files_per_cycle()) {
|
||||
return $files;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($files)) {
|
||||
if ($file_found) { // reached end of the directory
|
||||
if ($dirs) { // go a directory back
|
||||
$previous_file = array_pop($dirs);
|
||||
return $this->get_next_files($root_dir, $dirs, $previous_file, $exclude_paths);
|
||||
} else { // root directory end reached
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return new WP_Error(
|
||||
'previous_file_not_found',
|
||||
sprintf(__('Failed to restore dir listing from: %s', 'fw'), $root_dir . $rel_dir . '/' . $previous_file)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $files;
|
||||
} else { // directory is empty
|
||||
if ($dirs) { // go a directory back
|
||||
$previous_file = array_pop($dirs);
|
||||
return $this->get_next_files($root_dir, $dirs, $previous_file, $exclude_paths);
|
||||
} else { // root directory end reached
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,439 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
class FW_Ext_Backups_Task_Type_Files_Restore extends FW_Ext_Backups_Task_Type {
|
||||
public function get_type() {
|
||||
return 'files-restore';
|
||||
}
|
||||
|
||||
public function get_title(array $args = array(), array $state = array()) {
|
||||
return __('Files Restore', 'fw');
|
||||
}
|
||||
|
||||
/**
|
||||
* Files restore can't be done in steps,
|
||||
* because the site will not work without all files (half of a theme, or a plugin)
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_custom_timeout(array $args, array $state = array()) {
|
||||
return fw_ext('backups')->get_config('max_timeout');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @param array $args
|
||||
* * source_dir
|
||||
* * destinations - {'dir_id': 'destination_path'}
|
||||
* * [filesystem_args] - {}|{hostname: '', username: '', password: '', connection_type: ''}
|
||||
*/
|
||||
public function execute(array $args, array $state = array()) {
|
||||
$backups = fw_ext('backups'); /** @var FW_Extension_Backups $backups */
|
||||
|
||||
$upload_dir = wp_upload_dir();
|
||||
$upload_dir = fw_fix_path($upload_dir['basedir']);
|
||||
|
||||
{
|
||||
if (empty($args['source_dir'])) {
|
||||
return new WP_Error(
|
||||
'no_source_dir', __('Source dir not specified', 'fw')
|
||||
);
|
||||
} else {
|
||||
$args['source_dir'] = fw_fix_path($args['source_dir']);
|
||||
|
||||
if (empty($args['source_dir']) || !file_exists($args['source_dir'])) {
|
||||
return new WP_Error(
|
||||
'invalid_source_dir',
|
||||
sprintf(__('Invalid source dir: %s', 'fw'), $args['source_dir'])
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($args['destinations'])) {
|
||||
return new WP_Error(
|
||||
'no_source', __('Source dirs not specified', 'fw')
|
||||
);
|
||||
} else {
|
||||
$args['destinations'] = array_map('fw_fix_path', $args['destinations']);
|
||||
}
|
||||
|
||||
{
|
||||
if (empty($args['skip_dirs'])) {
|
||||
$args['skip_dirs'] = array(
|
||||
// '/path/to/dir' => true,
|
||||
// '/path/to/file.txt' => true, // NOT WORKING. If you need this feature let us know
|
||||
);
|
||||
}
|
||||
|
||||
$args['skip_dirs'] = array_merge($args['skip_dirs'], array(
|
||||
$backups->get_tmp_dir() => true,
|
||||
$backups->get_backups_dir() => true,
|
||||
$upload_dir .'/backup' => true, // Backup v1
|
||||
fw_get_framework_directory() => true, // prevent framework delete, it must exist and continue task execution
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($state)) {
|
||||
// prepare destinations
|
||||
{
|
||||
$fs_required = false;
|
||||
$upload_dir_regex = '/^'. preg_quote($upload_dir, '/') .'/';
|
||||
|
||||
$destinations = array(
|
||||
'no_fs' => array(), // file operations are done via mkdir|copy|move|...
|
||||
'fs' => array(), // file operations are done via WP_Filesystem
|
||||
);
|
||||
|
||||
foreach ($args['destinations'] as $dir_id => $dir_path) {
|
||||
$dir_path = fw_fix_path($dir_path);
|
||||
|
||||
if (
|
||||
!file_exists($args['source_dir'] .'/'. $dir_id)
|
||||
||
|
||||
!file_exists($dir_path)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$is_in_uploads = preg_match($upload_dir_regex, $dir_path);
|
||||
|
||||
$destinations[$is_in_uploads ? 'no_fs' : 'fs'][$dir_id] = array(
|
||||
'fs' => !$is_in_uploads,
|
||||
'dir' => $dir_path,
|
||||
);
|
||||
|
||||
if (!$is_in_uploads) {
|
||||
$fs_required = true;
|
||||
}
|
||||
}
|
||||
|
||||
$destinations = array_merge($destinations['no_fs'], $destinations['fs']);
|
||||
|
||||
if (empty($destinations)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
$state = array(
|
||||
'pending_destinations' => $destinations,
|
||||
'current_destination' => array(
|
||||
'id' => null,
|
||||
'data' => null,
|
||||
),
|
||||
'fs_required' => $fs_required,
|
||||
);
|
||||
|
||||
unset($destinations);
|
||||
|
||||
$state['current_destination']['id'] = key($state['pending_destinations']);
|
||||
$state['current_destination']['data'] = array_shift($state['pending_destinations']);
|
||||
}
|
||||
|
||||
if ($state['fs_required']) {
|
||||
if (!FW_WP_Filesystem::has_direct_access(ABSPATH)) {
|
||||
if (empty($args['filesystem_args'])) {
|
||||
return new WP_Error(
|
||||
'fs_no_access', __('No filesystem access, credentials required', 'fw')
|
||||
);
|
||||
} elseif (!WP_Filesystem($args['filesystem_args'])) {
|
||||
return new WP_Error(
|
||||
'invalid_fs_credentials', __('No filesystem access, invalid credentials', 'fw')
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (!WP_Filesystem()) {
|
||||
return new WP_Error(
|
||||
'fs_init_fail', __('Filesystem init failed', 'fw')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
global $wp_filesystem; /** @var WP_Filesystem_Base $wp_filesystem */
|
||||
|
||||
if (!$wp_filesystem || (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code())) {
|
||||
return new WP_Error(
|
||||
'fs_init_fail', __('Filesystem init failed', 'fw')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
while ($state['current_destination']['id']) {
|
||||
if (is_wp_error($result = $this->clear_dir(
|
||||
$state['current_destination']['data']['dir'],
|
||||
$state['current_destination']['data']['fs'],
|
||||
$args['skip_dirs']
|
||||
))) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (is_wp_error($result = $this->copy_dir(
|
||||
$args['source_dir'] .'/'. $state['current_destination']['id'],
|
||||
$state['current_destination']['data']['dir'],
|
||||
$state['current_destination']['data']['fs'],
|
||||
$args['skip_dirs']
|
||||
))) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$state['current_destination']['id'] = key($state['pending_destinations']);
|
||||
$state['current_destination']['data'] = array_shift($state['pending_destinations']);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $dir path
|
||||
* @param bool $fs Use WP_Filesystem or not
|
||||
* @param array $skip_dirs {'path': mixed}
|
||||
*
|
||||
* @return WP_Error|true
|
||||
*/
|
||||
private function clear_dir($dir, $fs, $skip_dirs) {
|
||||
$included_hidden_names = fw_ext('backups')->get_config('included_hidden_names');
|
||||
|
||||
if ($fs) {
|
||||
global $wp_filesystem; /** @var WP_Filesystem_Base $wp_filesystem */
|
||||
|
||||
$fs_dir = fw_fix_path(FW_WP_Filesystem::real_path_to_filesystem_path($dir));
|
||||
|
||||
if (empty($fs_dir)) {
|
||||
return new WP_Error(
|
||||
'dir_to_fs_failed',
|
||||
sprintf(__('Cannot convert Filesystem path: %s', 'fw'), $dir)
|
||||
);
|
||||
} elseif (false === ($list = $wp_filesystem->dirlist($fs_dir, true))) {
|
||||
return new WP_Error(
|
||||
'dir_list_failed',
|
||||
sprintf(__('Failed to list dir: %s', 'fw'), $dir)
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($list as $file) {
|
||||
if ($file['name']{0} === '.' && !isset($included_hidden_names[$file['name']])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$file_path = $dir .'/'. $file['name'];
|
||||
$fs_file_path = $fs_dir .'/'. $file['name'];
|
||||
|
||||
if ($file['type'] === 'd') {
|
||||
if (isset($skip_dirs[$file_path])) {
|
||||
continue;
|
||||
} else {
|
||||
foreach ($skip_dirs as $skip_dir => $skip_dir_data) {
|
||||
if (
|
||||
strlen(preg_replace('/^'. preg_quote($file_path, '/') .'/', '', $skip_dir))
|
||||
!=
|
||||
strlen($skip_dir)
|
||||
) {
|
||||
continue 2; // skip dir if it's inside current dir
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$wp_filesystem->rmdir($fs_file_path, true)) {
|
||||
return new WP_Error(
|
||||
'dir_rm_fail',
|
||||
sprintf(__('Failed to remove dir: %s', 'fw'), $file_path)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (!$wp_filesystem->delete($fs_file_path)) {
|
||||
return new WP_Error(
|
||||
'file_rm_fail',
|
||||
sprintf(__('Failed to remove file: %s', 'fw'), $file_path)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
$files = array_diff(($files = scandir($dir)) ? $files : array(), array('.', '..'));
|
||||
|
||||
foreach ($files as $file_name) {
|
||||
$file_path = $dir .'/'. $file_name;
|
||||
|
||||
if ($file_name{0} === '.' && !isset($included_hidden_names[$file_name])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_dir($file_path)) {
|
||||
if (isset($skip_dirs[ $file_path ])) {
|
||||
continue;
|
||||
} else {
|
||||
foreach ($skip_dirs as $skip_dir => $skip_dir_data) {
|
||||
if (
|
||||
strlen(preg_replace('/^'. preg_quote($file_path, '/') .'/', '', $skip_dir))
|
||||
!=
|
||||
strlen($skip_dir)
|
||||
) {
|
||||
continue 2; // skip dir it's inside current dir
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!fw_ext_backups_rmdir_recursive($file_path)) {
|
||||
return new WP_Error(
|
||||
'dir_rm_fail',
|
||||
sprintf(__('Failed to remove dir: %s', 'fw'), $file_path)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (!unlink($file_path)) {
|
||||
return new WP_Error(
|
||||
'file_rm_fail',
|
||||
sprintf(__('Failed to remove file: %s', 'fw'), $file_path)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $source_dir path
|
||||
* @param string $destination_dir path
|
||||
* @param bool $fs Use WP_Filesystem or not
|
||||
* @param array $skip_dirs {'path': mixed}
|
||||
*
|
||||
* @return WP_Error|true
|
||||
*/
|
||||
private function copy_dir($source_dir, $destination_dir, $fs, $skip_dirs) {
|
||||
$included_hidden_names = fw_ext('backups')->get_config('included_hidden_names');
|
||||
|
||||
if ($fs) {
|
||||
global $wp_filesystem; /** @var WP_Filesystem_Base $wp_filesystem */
|
||||
|
||||
$fs_source_dir = fw_fix_path(FW_WP_Filesystem::real_path_to_filesystem_path($source_dir));
|
||||
|
||||
if (empty($fs_source_dir)) {
|
||||
return new WP_Error(
|
||||
'dir_to_fs_failed',
|
||||
sprintf(__('Cannot convert Filesystem path: %s', 'fw'), $source_dir)
|
||||
);
|
||||
} elseif (false === ($list = $wp_filesystem->dirlist($fs_source_dir, true))) {
|
||||
return new WP_Error(
|
||||
'dir_list_failed',
|
||||
sprintf(__('Failed to list dir: %s', 'fw'), $source_dir)
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($list as $file) {
|
||||
if ($file['name']{0} === '.' && !isset($included_hidden_names[$file['name']])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$file_path = $source_dir .'/'. $file['name'];
|
||||
$fs_file_path = $fs_source_dir .'/'. $file['name'];
|
||||
$destination_file_path = $destination_dir .'/'. $file['name'];
|
||||
$fs_destination_file_path = fw_fix_path(FW_WP_Filesystem::real_path_to_filesystem_path(
|
||||
$destination_file_path
|
||||
));
|
||||
|
||||
if (empty($fs_destination_file_path)) {
|
||||
return new WP_Error(
|
||||
'path_to_fs_failed',
|
||||
sprintf(__('Cannot convert Filesystem path: %s', 'fw'), $destination_file_path)
|
||||
);
|
||||
}
|
||||
|
||||
if ($file['type'] === 'd') {
|
||||
if (isset($skip_dirs[$destination_file_path])) {
|
||||
continue;
|
||||
} else {
|
||||
foreach ($skip_dirs as $skip_dir => $skip_dir_data) {
|
||||
if (
|
||||
strlen(preg_replace('/^'. preg_quote($destination_file_path, '/') .'/', '', $skip_dir))
|
||||
!=
|
||||
strlen($skip_dir)
|
||||
) {
|
||||
continue 2; // skip dir if it's inside current dir
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$wp_filesystem->mkdir($fs_destination_file_path)) {
|
||||
return new WP_Error(
|
||||
'fs_mkdir_fail',
|
||||
sprintf(__('Failed to create dir: %s', 'fw'), $destination_file_path)
|
||||
);
|
||||
}
|
||||
|
||||
if (is_wp_error($result = copy_dir(
|
||||
$fs_file_path, $fs_destination_file_path
|
||||
))) {
|
||||
return $result;
|
||||
}
|
||||
} else {
|
||||
if (!$wp_filesystem->copy($fs_file_path, $fs_destination_file_path)) {
|
||||
return new WP_Error(
|
||||
'file_copy_fail',
|
||||
sprintf(__('Failed to copy file: %s', 'fw'), $file_path)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
$names = array_diff(($names = scandir($source_dir)) ? $names : array(), array('.', '..'));
|
||||
|
||||
foreach ($names as $file_name) {
|
||||
$file_path = $source_dir .'/'. $file_name;
|
||||
$destination_file_path = $destination_dir .'/'. $file_name;
|
||||
|
||||
if ($file_name{0} === '.' && !isset($included_hidden_names[$file_name])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_dir($file_path)) {
|
||||
if (isset($skip_dirs[ $destination_file_path ])) {
|
||||
continue;
|
||||
} else {
|
||||
foreach ($skip_dirs as $skip_dir => $skip_dir_data) {
|
||||
if (
|
||||
strlen(preg_replace('/^'. preg_quote($destination_file_path, '/') .'/', '', $skip_dir))
|
||||
!=
|
||||
strlen($skip_dir)
|
||||
) {
|
||||
continue 2; // skip dir it's inside current dir
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_dir($destination_file_path)) {
|
||||
/**
|
||||
* Some times empty directories are not deleted ( @see fw_ext_backups_rmdir_recursive() )
|
||||
* even if rmdir() returns true, the directory remains (I don't know why),
|
||||
* so a workaround is to check if it exists and do not try to created it
|
||||
* (because create will return false)
|
||||
*/
|
||||
} elseif (!mkdir($destination_file_path)) {
|
||||
return new WP_Error(
|
||||
'dir_mk_fail',
|
||||
sprintf(__('Failed to create dir: %s', 'fw'), $destination_file_path)
|
||||
);
|
||||
}
|
||||
|
||||
if (is_wp_error($result = $this->copy_dir(
|
||||
$file_path, $destination_file_path, $fs, array()
|
||||
))) {
|
||||
return $result;
|
||||
}
|
||||
} else {
|
||||
if (!copy($file_path, $destination_file_path)) {
|
||||
return new WP_Error(
|
||||
'file_copy_fail',
|
||||
sprintf(__('Failed to copy file: %s', 'fw'), $file_path)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
|
||||
class FW_Ext_Backups_Task_Type_Image_Sizes_Remove extends FW_Ext_Backups_Task_Type {
|
||||
public function get_type() {
|
||||
return 'image-sizes-remove';
|
||||
}
|
||||
|
||||
public function get_title(array $args = array(), array $state = array()) {
|
||||
return __('Image Sizes Remove', 'fw');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @param array $args
|
||||
* * uploads_dir - path to exported uploads dir (not the actual WP uploads dir! that remains untouched)
|
||||
*/
|
||||
public function execute(array $args, array $state = array()) {
|
||||
$backups = fw_ext('backups'); /** @var FW_Extension_Backups $backups */
|
||||
|
||||
{
|
||||
if (empty($args['uploads_dir'])) {
|
||||
return new WP_Error(
|
||||
'no_uploads_dir', __('Uploads dir not specified', 'fw')
|
||||
);
|
||||
} else {
|
||||
$args['uploads_dir'] = fw_fix_path($args['uploads_dir']);
|
||||
|
||||
if (!file_exists($args['uploads_dir'])) {
|
||||
/**
|
||||
* The uploads directory was not exported, nothing to do.
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($state)) {
|
||||
$state = array(
|
||||
// The attachment at which the execution stopped and will continue in next request
|
||||
'attachment_id' => 0,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @var WPDB $wpdb
|
||||
*/
|
||||
global $wpdb;
|
||||
|
||||
$sql = implode( array(
|
||||
"SELECT * FROM {$wpdb->posts}",
|
||||
"WHERE post_type = 'attachment' AND post_mime_type LIKE %s AND ID > %d",
|
||||
"ORDER BY ID",
|
||||
"LIMIT 7"
|
||||
), " \n");
|
||||
|
||||
$wp_uploads_dir = wp_upload_dir();
|
||||
$wp_uploads_dir_length = mb_strlen($wp_uploads_dir['basedir']);
|
||||
|
||||
$max_time = time() + fw_ext( 'backups' )->get_timeout(-7);
|
||||
|
||||
while (time() < $max_time) {
|
||||
$attachments = $wpdb->get_results( $wpdb->prepare(
|
||||
$sql, $wpdb->esc_like('image/').'%', $state['attachment_id']
|
||||
), ARRAY_A );
|
||||
|
||||
if (empty($attachments)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($attachments as $attachment) {
|
||||
if (
|
||||
($meta = wp_get_attachment_metadata( $attachment['ID'] ))
|
||||
&&
|
||||
isset( $meta['sizes'] )
|
||||
&&
|
||||
is_array( $meta['sizes'] )
|
||||
) {
|
||||
$attachment_path = get_attached_file( $attachment['ID'] );
|
||||
$filename_length = mb_strlen( basename( $attachment_path ) );
|
||||
|
||||
foreach ( $meta['sizes'] as $size => $sizeinfo ) {
|
||||
// replace wp_uploads_dir path
|
||||
$file_path = $args['uploads_dir'] . mb_substr($attachment_path, $wp_uploads_dir_length);
|
||||
// replace file name with resize name
|
||||
$file_path = mb_substr($file_path, 0, -$filename_length) . $sizeinfo['file'];
|
||||
|
||||
if (file_exists($file_path)) {
|
||||
@unlink( $file_path );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( is_array( $backup_sizes = get_post_meta( $attachment['ID'], '_wp_attachment_backup_sizes', true ) ) ) {
|
||||
foreach ( $backup_sizes as $size ) {
|
||||
$del_file = path_join( dirname( $meta['file'] ), $size['file'] );
|
||||
|
||||
@unlink( path_join($args['uploads_dir'], $del_file) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$state['attachment_id'] = $attachment['ID'];
|
||||
}
|
||||
|
||||
return $state;
|
||||
}
|
||||
}
|
||||