= 4.0.7.1 - 4-30-20 =

* Fixed: JSON decoding issues on specific setups
* Fixed: an issue with incorrect images URL
* Fixed: conflict with the Download Manager plugin
* Fixed: multiple PHP warnings
* Fixed: MySQL query compatibility problems
* Fixed: an issue with saving Wordfence settings
* Fixed: an issue with showing correct post and page creating time
* Fixed: an issue with displaying correct author in reports
* Added: support for WPVivid backups in the reporting system
* Preventative: security improvements
This commit is contained in:
thanghv 2020-05-01 00:05:03 +07:00
parent 4cf9fa51b1
commit 2b360be79e
53 changed files with 7066 additions and 12059 deletions

11
.gitattributes vendored
View file

@ -1,11 +0,0 @@
# Ignore all test and documentation with “export-ignore”
.github export-ignore
bin export-ignore
composer.* export-ignore
tests export-ignore
.gitattributes export-ignore
phpcs.xml export-ignore
.travis.yml export-ignore
LICENSE.md export-ignore
LICENSE.txt export-ignore
README.md export-ignore

View file

@ -1,76 +0,0 @@
# Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at support@mainwp.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

View file

@ -1,78 +0,0 @@
# How to contribute to MainWP Child plugin
Community made patches, localizations, bug reports and contributions are always welcome. Your help making it even more awesome will be greatly appreciated :)
When contributing please ensure you follow the guidelines below to help us keep on top of things.
__Please Note:__
GitHub is for _bug reports and contributions only_ - if you have a support question or a request for a customization this is not the right place to post it. Use [MainWP Support](https://mainwp.com/support/) for customer support and for customizations we recommend one of our MainWP trusted Experts:
[MainWP Experts](https://mainwp.com/mainwp-experts/)
## Contributing To The Core
### Reporting Issues
Reporting issues is a great way to become a contributor as it doesn't require technical skills. In fact you don't even need to know a programming language or to be able to check the code itself, you just need to make sure that everything works as expected and [submit an issue report](https://github.com/mainwp/mainwp/issues/new) if you spot a bug. Sound like something you're up for? Go for it!
#### How To Submit An Issue Report
If something isn't working, congratulations you've found a bug! Help us fix it by submitting an issue report:
* Make sure you have a [GitHub account](https://github.com/signup/free)
* Search the [Existing Issues](https://github.com/mainwp/mainwp/issues) to be sure that the one you've noticed isn't already there
* Submit a report for your issue
* Clearly describe the issue (including steps to reproduce it if it's a bug)
* Make sure you fill in the earliest version that you know has the issue.
### Making Changes
Helping aking changes to the MainWP Dashboard is a key way to help us improve MainWP overall. You will need some technical skills to make a change, like knowing a bit of PHP, CSS, SASS or JavaScript.
If you think something could be improved and you're able to do so, make your changes and submit a Pull Request. We'll be pleased to get it :)
#### How To Submit A PR
* Fork the repository on GitHub
* Make the changes to your forked repository
* **Ensure you stick to the [WordPress Coding Standards](http://make.wordpress.org/core/handbook/coding-standards/php/).**
* Ensure you use LF line endings - no crazy Windows line endings please :)
* When committing, reference your issue number (#1234) and include a note about the fix
* Push the changes to your fork and submit a pull request on the master branch of the MainWP Dashboard repository. Existing maintenance branches will be maintained by MainWP developers
* Please **don't** modify the changelog - this will be maintained by the MainWP developers.
* Please **don't** add your localizations or update the .pot files - these will also be maintained by the MainWP developers. To contribute to the localization of MainWP, please join the [translate.wordpress.org project](https://translate.wordpress.org/projects/wp-plugins/mainwp). This is much needed, if you speak a language that needs translating consider yourself officially invited.
After you follow the step above, the next stage will be waiting on us to merge your Pull Request. We review them all, and make suggestions and changes as and if necessary.
## Contribute To Localizing MainWP
Localization is a very important part of MainWP. We believe in net neutrality and want our platform to be available to everyone, everywhere with equal ease. When you localize MainWP, you are helping hundreds of people in the world, and all the people who speak your language. That's pretty neat.
### Glossary & Style Guide
Please refer to this page on the [Translator Handbook](https://make.wordpress.org/polyglots/handbook/translating/glossary-style-guide/) for information about the glossary and the style guide.
Each translation editor will take care of updating the glossary on GlotPress by editing/adding items when needed.
_**Note**: Only editors can create/import and edit glossaries and glossary items on GlotPress. Anyone can suggest new items to add to the glossary or translate them._
### Translating The Core
We have a [project on translate.wordpress.org](https://translate.wordpress.org/projects/wp-plugins/mainwp). You can join the localization team of your language and help by translating MainWP. [Find more about using joining a language team and using GlotPress](https://make.wordpress.org/polyglots/handbook/tools/glotpress-translate-wordpress-org/).
If MainWP is already 100% translated for your language, join the team anyway! We regularly update our language files and there will definitely be need of your help soon.
# Additional Resources
* [General GitHub documentation](http://help.github.com/)
* [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
* [Translator Handbook](https://make.wordpress.org/polyglots/handbook/)
* [MainWP Docs](http://docs.mainwp.com/)
* [MainWP API / Codex](http://codex.mainwp.com/)
# CONTRIBUTING File Credit
This CONTRIBUTING.md file relies heavily WooCommerce's [CONTRIBUTING.md](https://github.com/woothemes/woocommerce/blob/master/CONTRIBUTING.md) for wording and contribution requirements.

View file

@ -1,38 +0,0 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
**Additional context**
Add any other context about the problem here.

View file

@ -1,20 +0,0 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

View file

@ -1,33 +0,0 @@
### All Submissions:
* [ ] Have you followed the [MainWP Contributing guideline](https://github.com/mainwp/mainwp-child/blob/master/.github/CONTRIBUTING.md)?
* [ ] Does your code follow the [WordPress' coding standards](https://make.wordpress.org/core/handbook/best-practices/coding-standards/)?
* [ ] Have you checked to ensure there aren't other open [Pull Requests](https://github.com/mainwp/mainwp-child/pulls) for the same update/change?
<!-- Mark completed items with an [x] -->
<!-- You can erase any parts of this template not applicable to your Pull Request. -->
### Changes proposed in this Pull Request:
<!-- Describe the changes made to this Pull Request and the reason for such changes. -->
Closes # .
### How to test the changes in this Pull Request:
1.
2.
3.
### Other information:
* [ ] Have you added an explanation of what your changes do and why you'd like us to include them?
* [ ] Have you written new tests for your changes, as applicable?
* [ ] Have you successfully run tests with your changes locally?
<!-- Mark completed items with an [x] -->
### Changelog entry
> Enter a summary of all changes on this Pull Request. This will appear in the changelog if accepted.

4
.github/SECURITY.md vendored
View file

@ -1,4 +0,0 @@
# Security Policy
## Reporting Security Issues
To disclose a security issue to our team, [please submit a report via HackerOne here](https://hackerone.com/mainwp).

View file

@ -1,60 +0,0 @@
sudo: false
dist: xenial
language: php
notifications:
email:
on_success: never
on_failure: change
branches:
only:
- master
cache:
directories:
- $HOME/.composer/cache
matrix:
include:
- php: 7.4
env: WP_TRAVISCI=phpcs WP_VERSION=latest
- php: 7.3
env: WP_VERSION=latest
- php: 7.2
env: WP_VERSION=latest
- php: 7.1
env: WP_VERSION=latest
- php: 7.0
env: WP_VERSION=latest
before_script:
- export PATH="$HOME/.composer/vendor/bin:$PATH"
- |
if [ -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ]; then
phpenv config-rm xdebug.ini
else
echo "xdebug.ini does not exist"
fi
- |
if [[ ! -z "$WP_VERSION" ]] ; then
bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
composer global require "phpunit/phpunit=4.8.*|5.7.*"
fi
- |
if [[ "$WP_TRAVISCI" == "phpcs" ]] ; then
composer global require wp-coding-standards/wpcs
phpcs --config-set installed_paths $HOME/.composer/vendor/wp-coding-standards/wpcs
fi
script:
- |
if [[ ! -z "$WP_VERSION" ]] ; then
phpunit
WP_MULTISITE=1 phpunit
fi
- |
if [[ "$WP_TRAVISCI" == "phpcs" ]] ; then
phpcs
fi

View file

@ -1,674 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://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 <https://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:
<program> Copyright (C) <year> <name of author>
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
<https://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
<https://www.gnu.org/licenses/why-not-lgpl.html>.

View file

@ -1,674 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://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 <https://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:
<program> Copyright (C) <year> <name of author>
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
<https://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
<https://www.gnu.org/licenses/why-not-lgpl.html>.

View file

@ -1,45 +0,0 @@
<p align="center"><a href="https://mainwp.com"><img src="https://mainwp.com/images/mainwp-logo.png" alt="MainWP"></a></p>
<p align="center">
<a href="https://packagist.org/packages/mainwp/mainwp-child"><img src="https://poser.pugx.org/mainwp/mainwp-child/license" alt="license"></a>
<a href="https://packagist.org/packages/mainwp/mainwp-child"><img src="https://poser.pugx.org/mainwp/mainwp-child/v/stable" alt="Latest Stable Version"></a>
<img alt="WordPress Plugin Active Installs" src="https://img.shields.io/wordpress/plugin/installs/mainwp-child?label=MainWP%20Child%20Active%20Installs">
<img alt="WordPress Plugin Rating" src="https://img.shields.io/wordpress/plugin/stars/mainwp-child?label=WP.org%20Rating">
</p>
Welcome to the [MainWP](https://mainwp.com) Child plugin repository on GitHub. Here you can browse the source, look at open issues and keep track of development.
# Not a Developer
If you are not a developer, please use the [MainWP Community](https://meta.mainwp.com) for questions or issues.
# Developer
The MainWP WordPress management system consists of 2 core plugins, the MainWP Dashboard plugin which is [containted in this repository](https://github.com/mainwp/mainwp/). The second plugin is the MainWP Child plugin, which is in this repository.
The [MainWP Child](https://wordpress.org/plugins/mainwp-child/) plugin is installed on the WordPress sites that you want to control from the MainWP Dashboard.
The [MainWP Dashboard](https://wordpress.org/plugins/mainwp/) is a stand-alone plugin that is installed on its own WordPress site; no other plugins should be installed with it, and it should not be installed on an active WordPress site with visitors. The MainWP Dashboard currently has an <img alt="WordPress Plugin Active Installs" src="https://img.shields.io/wordpress/plugin/installs/mainwp?label=active%20install%20count%20of%20">
## Documentation
* [MainWP Help Documentation](https://mainwp.com/help/)
* [MainWP Codex](https://mainwp.com/codex/)
* [MainWP Dev Community](https://meta.mainwp.com/c/dev/15)
## Reporting Security Issues
To disclose a security issue to our team, [please submit a report via HackerOne here](https://hackerone.com/mainwp).
## Support
This repository is not suitable for support. Please don't use our issue tracker for support requests, but for core MainWP issues only. Support can take place through the appropriate channels:
* If you have a problem, you may want to start with the [Help Docs](https://mainwp.com/help/).
* [The MainWP Community](https://meta.mainwp.com/) which is available for all MainWP users.
* You can also [open a support ticket](https://mainwp.com/support/).
* For customizations take a look at our list of [MainWP Exteperts](https://mainwp.com/mainwp-experts/) or [Codeable](https://codeable.io/).
Support requests in issues on this repository will be closed on sight.
## Contributing to MainWP
If you have a patch or have stumbled upon an issue with the MainWP Plugin you can contribute this back to the code. Please read our [contributor guidelines](https://github.com/mainwp/mainwp/blob/master/.github/CONTRIBUTING.md) for more informationon how you can do this.

View file

@ -1,155 +0,0 @@
#!/usr/bin/env bash
if [ $# -lt 3 ]; then
echo "usage: $0 <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]"
exit 1
fi
DB_NAME=$1
DB_USER=$2
DB_PASS=$3
DB_HOST=${4-localhost}
WP_VERSION=${5-latest}
SKIP_DB_CREATE=${6-false}
TMPDIR=${TMPDIR-/tmp}
TMPDIR=$(echo $TMPDIR | sed -e "s/\/$//")
WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib}
WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/}
download() {
if [ `which curl` ]; then
curl -s "$1" > "$2";
elif [ `which wget` ]; then
wget -nv -O "$2" "$1"
fi
}
if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+\-(beta|RC)[0-9]+$ ]]; then
WP_BRANCH=${WP_VERSION%\-*}
WP_TESTS_TAG="branches/$WP_BRANCH"
elif [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then
WP_TESTS_TAG="branches/$WP_VERSION"
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
WP_TESTS_TAG="tags/${WP_VERSION%??}"
else
WP_TESTS_TAG="tags/$WP_VERSION"
fi
elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
WP_TESTS_TAG="trunk"
else
# http serves a single offer, whereas https serves multiple. we only want one
download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json
grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json
LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//')
if [[ -z "$LATEST_VERSION" ]]; then
echo "Latest WordPress version could not be found"
exit 1
fi
WP_TESTS_TAG="tags/$LATEST_VERSION"
fi
set -ex
install_wp() {
if [ -d $WP_CORE_DIR ]; then
return;
fi
mkdir -p $WP_CORE_DIR
if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then
mkdir -p $TMPDIR/wordpress-nightly
download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR/wordpress-nightly/wordpress-nightly.zip
unzip -q $TMPDIR/wordpress-nightly/wordpress-nightly.zip -d $TMPDIR/wordpress-nightly/
mv $TMPDIR/wordpress-nightly/wordpress/* $WP_CORE_DIR
else
if [ $WP_VERSION == 'latest' ]; then
local ARCHIVE_NAME='latest'
elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then
# https serves multiple offers, whereas http serves single.
download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json
if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then
# version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x
LATEST_VERSION=${WP_VERSION%??}
else
# otherwise, scan the releases and get the most up to date minor version of the major release
local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'`
LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1)
fi
if [[ -z "$LATEST_VERSION" ]]; then
local ARCHIVE_NAME="wordpress-$WP_VERSION"
else
local ARCHIVE_NAME="wordpress-$LATEST_VERSION"
fi
else
local ARCHIVE_NAME="wordpress-$WP_VERSION"
fi
download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz
tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR
fi
download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
}
install_test_suite() {
# portable in-place argument for both GNU sed and Mac OSX sed
if [[ $(uname -s) == 'Darwin' ]]; then
local ioption='-i.bak'
else
local ioption='-i'
fi
# set up testing suite if it doesn't yet exist
if [ ! -d $WP_TESTS_DIR ]; then
# set up testing suite
mkdir -p $WP_TESTS_DIR
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes
svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data
fi
if [ ! -f wp-tests-config.php ]; then
download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php
# remove all forward slashes in the end
WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::")
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
fi
}
install_db() {
if [ ${SKIP_DB_CREATE} = "true" ]; then
return 0
fi
# parse DB_HOST for port or socket references
local PARTS=(${DB_HOST//\:/ })
local DB_HOSTNAME=${PARTS[0]};
local DB_SOCK_OR_PORT=${PARTS[1]};
local EXTRA=""
if ! [ -z $DB_HOSTNAME ] ; then
if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then
EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp"
elif ! [ -z $DB_SOCK_OR_PORT ] ; then
EXTRA=" --socket=$DB_SOCK_OR_PORT"
elif ! [ -z $DB_HOSTNAME ] ; then
EXTRA=" --host=$DB_HOSTNAME --protocol=tcp"
fi
fi
# create database
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
}
install_wp
install_test_suite
install_db

View file

@ -43,7 +43,7 @@ class MainWP_Backup {
$pid = trailingslashit( $backupdir ) . 'backup-' . $pid . '.pid'; $pid = trailingslashit( $backupdir ) . 'backup-' . $pid . '.pid';
} }
// Verify if another backup is running, if so, return an error //Verify if another backup is running, if so, return an error
$files = glob( $backupdir . '*.pid' ); $files = glob( $backupdir . '*.pid' );
foreach ( $files as $file ) { foreach ( $files as $file ) {
if ( basename( $file ) == basename( $pid ) ) { if ( basename( $file ) == basename( $pid ) ) {
@ -68,23 +68,38 @@ class MainWP_Backup {
$ext = $this->archiver->getExtension(); $ext = $this->archiver->getExtension();
} }
// throw new Exception('Test 1 2 : ' . print_r($append,1));
if ( ( false !== $fileSuffix ) && ! empty( $fileSuffix ) ) { if ( ( false !== $fileSuffix ) && ! empty( $fileSuffix ) ) {
// Append already contains extension! $file = $fileSuffix . ( true === $append ? '' : $ext ); //Append already contains extension!
$file = $fileSuffix . ( true === $append ? '' : $ext );
} else { } else {
$file = 'backup-' . $filePrefix . $timestamp . $ext; $file = 'backup-' . $filePrefix . $timestamp . $ext;
} }
$filepath = $backupdir . $file; $filepath = $backupdir . $file;
$fileurl = $file; $fileurl = $file;
// if (!$append)
// {
// if ($dh = opendir($backupdir))
// {
// while (($file = readdir($dh)) !== false)
// {
// if ($file != '.' && $file != '..' && preg_match('/(.*).(zip|tar|tar.gz|tar.bz2|pid|done)$/', $file))
// {
// @unlink($backupdir . $file);
// }
// }
// closedir($dh);
// }
// }
if ( ! $addConfig ) { if ( ! $addConfig ) {
if ( ! in_array( str_replace( ABSPATH, '', WP_CONTENT_DIR ), $excludes, true ) && ! in_array( 'wp-admin', $excludes, true ) && ! in_array( WPINC, $excludes, true ) ) { if ( ! in_array( str_replace( ABSPATH, '', WP_CONTENT_DIR ), $excludes ) && ! in_array( 'wp-admin', $excludes ) && ! in_array( WPINC, $excludes ) ) {
$addConfig = true; $addConfig = true;
$includeCoreFiles = true; $includeCoreFiles = true;
} }
} }
$this->timeout = 20 * 60 * 60; $this->timeout = 20 * 60 * 60; /*20 minutes*/
$mem = '512M'; $mem = '512M';
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart
@ini_set( 'memory_limit', $mem ); @ini_set( 'memory_limit', $mem );
@ -94,9 +109,9 @@ class MainWP_Backup {
if ( null !== $this->archiver ) { if ( null !== $this->archiver ) {
$success = $this->archiver->createFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp, $append ); $success = $this->archiver->createFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp, $append );
} elseif ( $this->checkZipSupport() ) { } else if ( $this->checkZipSupport() ) {
$success = $this->createZipFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ); $success = $this->createZipFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp );
} elseif ( $this->checkZipConsole() ) { } else if ( $this->checkZipConsole() ) {
$success = $this->createZipConsoleFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ); $success = $this->createZipConsoleFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp );
} else { } else {
$success = $this->createZipPclFullBackup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ); $success = $this->createZipPclFullBackup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp );
@ -110,7 +125,7 @@ class MainWP_Backup {
} }
public function zipFile( $files, $archive ) { public function zipFile( $files, $archive ) {
$this->timeout = 20 * 60 * 60; $this->timeout = 20 * 60 * 60; /*20 minutes*/
$mem = '512M'; $mem = '512M';
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart
@ini_set( 'memory_limit', $mem ); @ini_set( 'memory_limit', $mem );
@ -118,15 +133,15 @@ class MainWP_Backup {
@ini_set( 'max_execution_time', $this->timeout ); @ini_set( 'max_execution_time', $this->timeout );
// @codingStandardsIgnoreEnd // @codingStandardsIgnoreEnd
if ( ! is_array( $files ) ) { if ( !is_array( $files ) ) {
$files = array( $files ); $files = array ($files );
} }
if ( null !== $this->archiver ) { if ( null !== $this->archiver ) {
$success = $this->archiver->zipFile( $files, $archive ); $success = $this->archiver->zipFile( $files, $archive );
} elseif ( $this->checkZipSupport() ) { } else if ( $this->checkZipSupport() ) {
$success = $this->_zipFile( $files, $archive ); $success = $this->_zipFile( $files, $archive );
} elseif ( $this->checkZipConsole() ) { } else if ( $this->checkZipConsole() ) {
$success = $this->_zipFileConsole( $files, $archive ); $success = $this->_zipFileConsole( $files, $archive );
} else { } else {
$success = $this->_zipFilePcl( $files, $archive ); $success = $this->_zipFilePcl( $files, $archive );
@ -157,8 +172,8 @@ class MainWP_Backup {
} }
public function _zipFilePcl( $files, $archive ) { public function _zipFilePcl( $files, $archive ) {
// Zip this backup folder.. //Zip this backup folder..
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php'; require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
$this->zip = new PclZip( $archive ); $this->zip = new PclZip( $archive );
$error = false; $error = false;
@ -168,7 +183,7 @@ class MainWP_Backup {
} }
} }
return ! $error; return !$error;
} }
/** /**
@ -187,6 +202,7 @@ class MainWP_Backup {
*/ */
public function checkZipConsole() { public function checkZipConsole() {
return false; return false;
// return function_exists('system');
} }
/** /**
@ -232,7 +248,7 @@ class MainWP_Backup {
foreach ( $nodes as $key => $node ) { foreach ( $nodes as $key => $node ) {
if ( MainWP_Helper::startsWith( $node, ABSPATH . WPINC ) ) { if ( MainWP_Helper::startsWith( $node, ABSPATH . WPINC ) ) {
unset( $nodes[ $key ] ); unset( $nodes[ $key ] );
} elseif ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) { } else if ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) {
unset( $nodes[ $key ] ); unset( $nodes[ $key ] );
} else { } else {
foreach ( $coreFiles as $coreFile ) { foreach ( $coreFiles as $coreFile ) {
@ -264,7 +280,7 @@ class MainWP_Backup {
if ( ! MainWP_Helper::inExcludes( $excludes, str_replace( ABSPATH, '', $node ) ) ) { if ( ! MainWP_Helper::inExcludes( $excludes, str_replace( ABSPATH, '', $node ) ) ) {
if ( is_dir( $node ) ) { if ( is_dir( $node ) ) {
$this->zipAddDir( $node, $excludes ); $this->zipAddDir( $node, $excludes );
} elseif ( is_file( $node ) ) { } else if ( is_file( $node ) ) {
$this->addFileToZip( $node, str_replace( ABSPATH, '', $node ) ); $this->addFileToZip( $node, str_replace( ABSPATH, '', $node ) );
} }
} }
@ -336,7 +352,7 @@ class MainWP_Backup {
* @return bool * @return bool
*/ */
public function createZipPclFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles ) { public function createZipPclFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles ) {
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php'; require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
$this->zip = new PclZip( $filepath ); $this->zip = new PclZip( $filepath );
$nodes = glob( ABSPATH . '*' ); $nodes = glob( ABSPATH . '*' );
if ( ! $includeCoreFiles ) { if ( ! $includeCoreFiles ) {
@ -366,7 +382,7 @@ class MainWP_Backup {
foreach ( $nodes as $key => $node ) { foreach ( $nodes as $key => $node ) {
if ( MainWP_Helper::startsWith( $node, ABSPATH . WPINC ) ) { if ( MainWP_Helper::startsWith( $node, ABSPATH . WPINC ) ) {
unset( $nodes[ $key ] ); unset( $nodes[ $key ] );
} elseif ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) { } else if ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) {
unset( $nodes[ $key ] ); unset( $nodes[ $key ] );
} else { } else {
foreach ( $coreFiles as $coreFile ) { foreach ( $coreFiles as $coreFile ) {
@ -380,7 +396,7 @@ class MainWP_Backup {
} }
$db_files = $this->createBackupDB( dirname( $filepath ) . DIRECTORY_SEPARATOR . 'dbBackup' ); $db_files = $this->createBackupDB( dirname( $filepath ) . DIRECTORY_SEPARATOR . 'dbBackup' );
$error = false; $error = false;
foreach ( $db_files as $db_file ) { foreach ( $db_files as $db_file ) {
if ( 0 === ( $rslt = $this->zip->add( $db_file, PCLZIP_OPT_REMOVE_PATH, dirname( $db_file ), PCLZIP_OPT_ADD_PATH, basename( WP_CONTENT_DIR ) ) ) ) { if ( 0 === ( $rslt = $this->zip->add( $db_file, PCLZIP_OPT_REMOVE_PATH, dirname( $db_file ), PCLZIP_OPT_ADD_PATH, basename( WP_CONTENT_DIR ) ) ) ) {
$error = true; $error = true;
@ -392,13 +408,13 @@ class MainWP_Backup {
} }
if ( ! $error ) { if ( ! $error ) {
foreach ( $nodes as $node ) { foreach ( $nodes as $node ) {
if ( null === $excludes || ! in_array( str_replace( ABSPATH, '', $node ), $excludes, true ) ) { if ( null === $excludes || ! in_array( str_replace( ABSPATH, '', $node ), $excludes ) ) {
if ( is_dir( $node ) ) { if ( is_dir( $node ) ) {
if ( ! $this->pclZipAddDir( $node, $excludes ) ) { if ( ! $this->pclZipAddDir( $node, $excludes ) ) {
$error = true; $error = true;
break; break;
} }
} elseif ( is_file( $node ) ) { } else if ( is_file( $node ) ) {
if ( 0 === ( $rslt = $this->zip->add( $node, PCLZIP_OPT_REMOVE_PATH, ABSPATH ) ) ) { if ( 0 === ( $rslt = $this->zip->add( $node, PCLZIP_OPT_REMOVE_PATH, ABSPATH ) ) ) {
$error = true; $error = true;
break; break;
@ -455,7 +471,7 @@ class MainWP_Backup {
$newnodes = glob( $node . DIRECTORY_SEPARATOR . '*' ); $newnodes = glob( $node . DIRECTORY_SEPARATOR . '*' );
$this->copy_dir( $newnodes, $excludes, $backupfolder, $excludenonwp, false ); $this->copy_dir( $newnodes, $excludes, $backupfolder, $excludenonwp, false );
unset( $newnodes ); unset( $newnodes );
} elseif ( is_file( $node ) ) { } else if ( is_file( $node ) ) {
if ( $this->excludeZip && MainWP_Helper::endsWith( $node, '.zip' ) ) { if ( $this->excludeZip && MainWP_Helper::endsWith( $node, '.zip' ) ) {
continue; continue;
} }
@ -469,16 +485,16 @@ class MainWP_Backup {
} }
public function createZipPclFullBackup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ) { public function createZipPclFullBackup2( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ) {
// Create backup folder //Create backup folder
$backupFolder = dirname( $filepath ) . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR; $backupFolder = dirname( $filepath ) . DIRECTORY_SEPARATOR . 'backup' . DIRECTORY_SEPARATOR;
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart
@mkdir( $backupFolder ); @mkdir( $backupFolder );
// @codingStandardsIgnoreEnd // @codingStandardsIgnoreEnd
// Create DB backup //Create DB backup
$db_files = $this->createBackupDB( $backupFolder . 'dbBackup' ); $db_files = $this->createBackupDB( $backupFolder . 'dbBackup' );
// Copy installation to backup folder //Copy installation to backup folder
$nodes = glob( ABSPATH . '*' ); $nodes = glob( ABSPATH . '*' );
if ( ! $includeCoreFiles ) { if ( ! $includeCoreFiles ) {
$coreFiles = array( $coreFiles = array(
@ -507,7 +523,7 @@ class MainWP_Backup {
foreach ( $nodes as $key => $node ) { foreach ( $nodes as $key => $node ) {
if ( MainWP_Helper::startsWith( $node, ABSPATH . WPINC ) ) { if ( MainWP_Helper::startsWith( $node, ABSPATH . WPINC ) ) {
unset( $nodes[ $key ] ); unset( $nodes[ $key ] );
} elseif ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) { } else if ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) {
unset( $nodes[ $key ] ); unset( $nodes[ $key ] );
} else { } else {
foreach ( $coreFiles as $coreFile ) { foreach ( $coreFiles as $coreFile ) {
@ -530,8 +546,8 @@ class MainWP_Backup {
// @codingStandardsIgnoreEnd // @codingStandardsIgnoreEnd
unset( $nodes ); unset( $nodes );
// Zip this backup folder.. //Zip this backup folder..
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php'; require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
$this->zip = new PclZip( $filepath ); $this->zip = new PclZip( $filepath );
$this->zip->create( $backupFolder, PCLZIP_OPT_REMOVE_PATH, $backupFolder ); $this->zip->create( $backupFolder, PCLZIP_OPT_REMOVE_PATH, $backupFolder );
if ( $addConfig ) { if ( $addConfig ) {
@ -546,7 +562,7 @@ class MainWP_Backup {
$this->addFileFromStringToPCLZip( 'clone/config.txt', $string, $filepath ); $this->addFileFromStringToPCLZip( 'clone/config.txt', $string, $filepath );
} }
// Remove backup folder //Remove backup folder
MainWP_Helper::delete_dir( $backupFolder ); MainWP_Helper::delete_dir( $backupFolder );
return true; return true;
@ -583,6 +599,24 @@ class MainWP_Backup {
$iterator = null; $iterator = null;
unset( $iterator ); unset( $iterator );
// $nodes = glob(rtrim($path, '/') . '/*');
// if (empty($nodes)) return true;
//
// foreach ($nodes as $node)
// {
// if (!MainWP_Helper::inExcludes($excludes, str_replace(ABSPATH, '', $node)))
// {
// if (is_dir($node))
// {
// $this->zipAddDir($node, $excludes);
// }
// else if (is_file($node))
// {
// $this->addFileToZip($node, str_replace(ABSPATH, '', $node));
// }
// }
// }
} }
public function pclZipAddDir( $path, $excludes ) { public function pclZipAddDir( $path, $excludes ) {
@ -593,13 +627,13 @@ class MainWP_Backup {
} }
foreach ( $nodes as $node ) { foreach ( $nodes as $node ) {
if ( null === $excludes || ! in_array( str_replace( ABSPATH, '', $node ), $excludes, true ) ) { if ( null === $excludes || ! in_array( str_replace( ABSPATH, '', $node ), $excludes ) ) {
if ( is_dir( $node ) ) { if ( is_dir( $node ) ) {
if ( ! $this->pclZipAddDir( $node, $excludes ) ) { if ( ! $this->pclZipAddDir( $node, $excludes ) ) {
$error = true; $error = true;
break; break;
} }
} elseif ( is_file( $node ) ) { } else if ( is_file( $node ) ) {
if ( 0 === ( $rslt = $this->zip->add( $node, PCLZIP_OPT_REMOVE_PATH, ABSPATH ) ) ) { if ( 0 === ( $rslt = $this->zip->add( $node, PCLZIP_OPT_REMOVE_PATH, ABSPATH ) ) ) {
$error = true; $error = true;
break; break;
@ -623,8 +657,7 @@ class MainWP_Backup {
$this->zip->delete( PCLZIP_OPT_BY_NAME, $file ); $this->zip->delete( PCLZIP_OPT_BY_NAME, $file );
$add = $this->zip->add( $tmpfilename, $add = $this->zip->add( $tmpfilename,
PCLZIP_OPT_REMOVE_PATH, dirname( $filepath ), PCLZIP_OPT_REMOVE_PATH, dirname( $filepath ),
PCLZIP_OPT_ADD_PATH, $localpath PCLZIP_OPT_ADD_PATH, $localpath );
);
unlink( $tmpfilename ); unlink( $tmpfilename );
if ( ! empty( $add ) ) { if ( ! empty( $add ) ) {
return true; return true;
@ -660,7 +693,7 @@ class MainWP_Backup {
$this->zipArchiveSizeCount += filesize( $path ); $this->zipArchiveSizeCount += filesize( $path );
$this->gcCnt ++; $this->gcCnt ++;
// 5 mb limit! //5 mb limit!
if ( ! $this->loadFilesBeforeZip || ( filesize( $path ) > 5 * 1024 * 1024 ) ) { if ( ! $this->loadFilesBeforeZip || ( filesize( $path ) > 5 * 1024 * 1024 ) ) {
$this->zipArchiveFileCount ++; $this->zipArchiveFileCount ++;
$added = $this->zip->addFile( $path, $zipEntryName ); $added = $this->zip->addFile( $path, $zipEntryName );
@ -686,7 +719,7 @@ class MainWP_Backup {
$this->gcCnt = 0; $this->gcCnt = 0;
} }
// Over limits? //Over limits?
if ( ( ( $this->file_descriptors > 0 ) && ( $this->zipArchiveFileCount > $this->file_descriptors ) ) ) { // || $this->zipArchiveSizeCount >= (31457280 * 2)) if ( ( ( $this->file_descriptors > 0 ) && ( $this->zipArchiveFileCount > $this->file_descriptors ) ) ) { // || $this->zipArchiveSizeCount >= (31457280 * 2))
$this->zip->close(); $this->zip->close();
$this->zip = null; $this->zip = null;
@ -709,11 +742,13 @@ class MainWP_Backup {
} }
public function createZipConsoleFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ) { public function createZipConsoleFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp ) {
// @TODO to work with 'zip' from system if PHP Zip library not available
//system('zip');
return false; return false;
} }
public function createBackupDB( $filepath_prefix, $archiveExt = false, &$archiver = null ) { public function createBackupDB( $filepath_prefix, $archiveExt = false, &$archiver = null ) {
$timeout = 20 * 60 * 60; $timeout = 20 * 60 * 60; //20minutes
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart
@set_time_limit( $timeout ); @set_time_limit( $timeout );
@ini_set( 'max_execution_time', $timeout ); @ini_set( 'max_execution_time', $timeout );
@ -725,7 +760,7 @@ class MainWP_Backup {
global $wpdb; global $wpdb;
$db_files = array(); $db_files = array();
// Get all the tables //Get all the tables
$tables_db = $wpdb->get_results( 'SHOW TABLES FROM `' . DB_NAME . '`', ARRAY_N ); $tables_db = $wpdb->get_results( 'SHOW TABLES FROM `' . DB_NAME . '`', ARRAY_N );
foreach ( $tables_db as $curr_table ) { foreach ( $tables_db as $curr_table ) {
if ( null !== $archiver ) { if ( null !== $archiver ) {
@ -735,15 +770,15 @@ class MainWP_Backup {
$table = $curr_table[0]; $table = $curr_table[0];
$currentfile = $filepath_prefix . '-' . MainWP_Helper::sanitize_filename( $table ) . '.sql'; $currentfile = $filepath_prefix . '-' . MainWP_Helper::sanitize_filename( $table ) . '.sql';
$db_files[] = $currentfile; $db_files[] = $currentfile;
if ( file_exists( $currentfile ) ) { if ( file_exists( $currentfile ) ) {
continue; continue;
} }
$fh = fopen( $currentfile . '.tmp', 'w' ); // or error; $fh = fopen( $currentfile . '.tmp', 'w' ); //or error;
fwrite( $fh, "\n\n" . 'DROP TABLE IF EXISTS ' . $table . ';' ); fwrite( $fh, "\n\n" . 'DROP TABLE IF EXISTS ' . $table . ';' );
// todo fix this //todo fix this
// $table_create = $wpdb->get_row( $wpdb->prepare( 'SHOW CREATE TABLE %s', $table ), ARRAY_N ); //$table_create = $wpdb->get_row( $wpdb->prepare( 'SHOW CREATE TABLE %s', $table ), ARRAY_N );
$table_create = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N ); $table_create = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N );
fwrite( $fh, "\n" . $table_create[1] . ";\n\n" ); fwrite( $fh, "\n" . $table_create[1] . ";\n\n" );
@ -804,10 +839,11 @@ class MainWP_Backup {
@unlink( $db_file ); @unlink( $db_file );
} }
} else { } else {
// todo: throw exception! //todo: throw exception!
} }
} }
return ( false !== $archiveExt ? array( 'filepath' => $archivefilePath ) : $db_files ); return ( false !== $archiveExt ? array( 'filepath' => $archivefilePath ) : $db_files );
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -18,24 +18,25 @@
*/ */
class MainWP_Child_Back_Up_Wordpress { class MainWP_Child_Back_Up_Wordpress {
public static $instance = null; public static $instance = null;
public $is_plugin_installed = false; public $is_plugin_installed = false;
static function Instance() { static function Instance() {
if ( null === self::$instance ) { if ( null === MainWP_Child_Back_Up_Wordpress::$instance ) {
self::$instance = new MainWP_Child_Back_Up_Wordpress(); MainWP_Child_Back_Up_Wordpress::$instance = new MainWP_Child_Back_Up_Wordpress();
} }
return self::$instance; return MainWP_Child_Back_Up_Wordpress::$instance;
} }
public function __construct() { public function __construct() {
require_once ABSPATH . 'wp-admin/includes/plugin.php'; require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( is_plugin_active( 'backupwordpress/backupwordpress.php' ) ) { if ( is_plugin_active( 'backupwordpress/backupwordpress.php' ) ) {
$this->is_plugin_installed = true; $this->is_plugin_installed = true;
if ( version_compare( phpversion(), '5.3', '>=' ) ) { if ( version_compare( phpversion(), '5.3', '>=' ) ) {
add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 );
} }
} }
} }
public function init() { public function init() {
@ -43,9 +44,7 @@ class MainWP_Child_Back_Up_Wordpress {
return; return;
} }
if ( ! $this->is_plugin_installed ) { if (!$this->is_plugin_installed) return;
return;
}
add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) ); add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) );
@ -67,7 +66,7 @@ class MainWP_Child_Back_Up_Wordpress {
return $value; return $value;
} }
if ( ! MainWP_Helper::is_screen_with_update() ) { if (! MainWP_Helper::is_screen_with_update()) {
return $value; return $value;
} }
if ( isset( $value->response['backupwordpress/backupwordpress.php'] ) ) { if ( isset( $value->response['backupwordpress/backupwordpress.php'] ) ) {
@ -155,7 +154,7 @@ class MainWP_Child_Back_Up_Wordpress {
if ( isset( $data['syncBackUpWordPress'] ) && $data['syncBackUpWordPress'] ) { if ( isset( $data['syncBackUpWordPress'] ) && $data['syncBackUpWordPress'] ) {
try { try {
$information['syncBackUpWordPress'] = $this->get_sync_data(); $information['syncBackUpWordPress'] = $this->get_sync_data();
} catch ( Exception $e ) { } catch(Exception $e) {
} }
} }
@ -171,7 +170,7 @@ class MainWP_Child_Back_Up_Wordpress {
$schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules(); $schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules();
$backups_time = array(); $backups_time = array();
if ( is_array($schedules) && count($schedules) ) { if (is_array($schedules) && count($schedules)) {
$check = current($schedules); $check = current($schedules);
MainWP_Helper::check_methods($check, array( 'get_backups' ) ); MainWP_Helper::check_methods($check, array( 'get_backups' ) );
@ -194,7 +193,7 @@ class MainWP_Child_Back_Up_Wordpress {
} }
function do_site_stats() { function do_site_stats() {
if ( has_action('mainwp_child_reports_log') ) { if (has_action('mainwp_child_reports_log')) {
do_action( 'mainwp_child_reports_log', 'backupwordpress'); do_action( 'mainwp_child_reports_log', 'backupwordpress');
} else { } else {
$this->do_reports_log('backupwordpress'); $this->do_reports_log('backupwordpress');
@ -202,13 +201,9 @@ class MainWP_Child_Back_Up_Wordpress {
} }
// ok // ok
public function do_reports_log( $ext = '' ) { public function do_reports_log($ext = '') {
if ( $ext !== 'backupwordpress' ) { if ( $ext !== 'backupwordpress' ) return;
return; if (!$this->is_plugin_installed) return;
}
if ( ! $this->is_plugin_installed ) {
return;
}
try { try {
MainWP_Helper::check_classes_exists('HM\BackUpWordPress\Schedules'); MainWP_Helper::check_classes_exists('HM\BackUpWordPress\Schedules');
@ -217,26 +212,26 @@ class MainWP_Child_Back_Up_Wordpress {
// Refresh the schedules from the database to make sure we have the latest changes // Refresh the schedules from the database to make sure we have the latest changes
HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules(); HM\BackUpWordPress\Schedules::get_instance()->refresh_schedules();
$schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules(); $schedules = HM\BackUpWordPress\Schedules::get_instance()->get_schedules();
if ( is_array($schedules) && count($schedules) > 0 ) { if (is_array($schedules) && count($schedules) > 0) {
$check = current($schedules); $check = current($schedules);
MainWP_Helper::check_methods($check, array( 'get_backups', 'get_type' )); MainWP_Helper::check_methods($check, array( 'get_backups', 'get_type' ));
foreach ( $schedules as $schedule ) { foreach($schedules as $schedule) {
foreach ( $schedule->get_backups() as $file ) { foreach ( $schedule->get_backups() as $file ) {
$backup_type = $schedule->get_type(); $backup_type = $schedule->get_type();
$message = 'BackupWordpres backup ' . $backup_type . ' finished'; $message = "BackupWordpres backup " . $backup_type . ' finished';
$destination = 'N/A'; $destination = "N/A";
if ( file_exists( $file ) ) { if ( file_exists( $file ) ) {
$date = @filemtime( $file ); $date = @filemtime( $file );
if ( ! empty( $date ) ) { if ( !empty( $date ) ) {
do_action( 'mainwp_reports_backupwordpress_backup', $destination, $message, 'finished', $backup_type, $date ); do_action( "mainwp_reports_backupwordpress_backup", $destination, $message, 'finished', $backup_type, $date );
MainWP_Helper::update_lasttime_backup('backupwordpress', $date); // to support backup before update feature MainWP_Helper::update_lasttime_backup('backupwordpress', $date); // to support backup before update feature
} }
} }
} }
} }
} }
} catch ( Exception $e ) { } catch(Exception $e) {
} }
} }
@ -267,8 +262,9 @@ class MainWP_Child_Back_Up_Wordpress {
$schedule_id = $this->check_schedule(); $schedule_id = $this->check_schedule();
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) ); $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) );
// Delete the running backup // Delete the running backup
if ( method_exists($schedule, 'get_running_backup_filename' ) ) { if (method_exists($schedule, 'get_running_backup_filename' )) {
if ( $schedule->get_running_backup_filename() && file_exists( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() ) ) { if ( $schedule->get_running_backup_filename() && file_exists( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() ) ) {
unlink( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() ); unlink( trailingslashit( hmbkp_path() ) . $schedule->get_running_backup_filename() );
} }
@ -284,17 +280,18 @@ class MainWP_Child_Back_Up_Wordpress {
if ( file_exists( $status->get_status_filepath() ) ) { if ( file_exists( $status->get_status_filepath() ) ) {
unlink( $status->get_status_filepath() ); unlink( $status->get_status_filepath() );
} }
} }
HM\BackUpWordPress\Path::get_instance()->cleanup(); HM\BackUpWordPress\Path::get_instance()->cleanup();
if ( $status === null ) { if ($status === null) {
$information['scheduleStatus'] = $schedule->get_status(); $information['scheduleStatus'] = $schedule->get_status();
} else { } else {
$information['scheduleStatus'] = $status->get_status(); $information['scheduleStatus'] = $status->get_status();
} }
$information['result'] = 'SUCCESS'; $information['result'] = 'SUCCESS';
return $information; return $information;
} }
@ -303,31 +300,30 @@ class MainWP_Child_Back_Up_Wordpress {
$schedule_id = $this->check_schedule(); $schedule_id = $this->check_schedule();
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) ); $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) );
if ( method_exists($schedule, 'get_running_backup_filename' ) ) { if (method_exists($schedule, 'get_running_backup_filename' )) {
$information['scheduleStatus'] = $schedule->get_status(); $information['scheduleStatus'] = $schedule->get_status();
} else { } else {
$status = $schedule->get_status(); $status = $schedule->get_status();
$information['scheduleStatus'] = $status->get_status(); $information['scheduleStatus'] = $status->get_status();
} }
$information['result'] = 'SUCCESS'; $information['result'] = 'SUCCESS';
return $information; return $information;
} }
function run_schedule() { function run_schedule() {
$schedule_id = $this->check_schedule(); $schedule_id = $this->check_schedule();
if ( function_exists('hmbkp_run_schedule_async') ) { if (function_exists('hmbkp_run_schedule_async')) {
hmbkp_run_schedule_async($schedule_id); hmbkp_run_schedule_async($schedule_id);
} elseif ( function_exists('\HM\BackUpWordPress\run_schedule_async') ) { } else if (function_exists('\HM\BackUpWordPress\run_schedule_async')) {
HM\BackUpWordPress\Path::get_instance()->cleanup(); HM\BackUpWordPress\Path::get_instance()->cleanup();
// Fixes an issue on servers which only allow a single session per client // Fixes an issue on servers which only allow a single session per client
session_write_close(); session_write_close();
$task = new \HM\Backdrop\Task( '\HM\BackUpWordPress\run_schedule_async', $schedule_id ); $task = new \HM\Backdrop\Task( '\HM\BackUpWordPress\run_schedule_async', $schedule_id );
$task->schedule(); $task->schedule();
} else { } else
return array( 'error' => __('Error while trying to trigger the schedule', 'mainwp-child') ); return array( 'error' => __('Error while trying to trigger the schedule', 'mainwp-child') );
}
return array( 'result' => 'SUCCESS' ); return array( 'result' => 'SUCCESS' );
} }
@ -351,19 +347,19 @@ class MainWP_Child_Back_Up_Wordpress {
continue; continue;
} }
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) ); $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) );
$started_ago = method_exists($schedule, 'get_schedule_running_start_time') ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time(); $started_ago = method_exists($schedule, 'get_schedule_running_start_time') ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time();
$out = array( $out = array(
'b' => $this->get_backupslist_html( $schedule ), 'b' => $this->get_backupslist_html( $schedule ),
'count' => count( $schedule->get_backups() ), 'count' => count( $schedule->get_backups() ),
'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ), 'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ),
'started_ago' => human_time_diff( $started_ago ), 'started_ago' => human_time_diff( $started_ago ),
); );
if ( method_exists($schedule, 'get_running_backup_filename' ) ) { if (method_exists($schedule, 'get_running_backup_filename' )) {
$out['scheduleStatus'] = $schedule->get_status(); $out['scheduleStatus'] = $schedule->get_status();
} else { } else {
$status = $schedule->get_status(); $status = $schedule->get_status();
$out['scheduleStatus'] = $status->get_status(); $out['scheduleStatus'] = $status->get_status();
} }
@ -379,7 +375,7 @@ class MainWP_Child_Back_Up_Wordpress {
$current_option = get_option( 'hmbkp_schedule_' . $sch_id ); $current_option = get_option( 'hmbkp_schedule_' . $sch_id );
if ( is_array( $current_option ) ) { if ( is_array( $current_option ) ) {
unset( $current_option['excludes'] ); // not send this value unset( $current_option['excludes'] ); // not send this value
$started_ago = method_exists($schedule, 'get_schedule_running_start_time') ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time(); $started_ago = method_exists($schedule, 'get_schedule_running_start_time') ? $schedule->get_schedule_running_start_time() : $schedule->get_schedule_start_time();
$send_back_schedules[ $sch_id ] = array( $send_back_schedules[ $sch_id ] = array(
'options' => $current_option, 'options' => $current_option,
'b' => $this->get_backupslist_html( $schedule ), 'b' => $this->get_backupslist_html( $schedule ),
@ -388,21 +384,20 @@ class MainWP_Child_Back_Up_Wordpress {
'scheduleStatus' => $schedule->get_status(), 'scheduleStatus' => $schedule->get_status(),
'started_ago' => human_time_diff( $started_ago ), 'started_ago' => human_time_diff( $started_ago ),
); );
if ( method_exists($schedule, 'get_running_backup_filename' ) ) { if (method_exists($schedule, 'get_running_backup_filename' )) {
$send_back_schedules['scheduleStatus'] = $schedule->get_status(); $send_back_schedules['scheduleStatus'] = $schedule->get_status();
} else { } else {
$status = $schedule->get_status(); $status = $schedule->get_status();
$send_back_schedules['scheduleStatus'] = $status->get_status(); $send_back_schedules['scheduleStatus'] = $status->get_status();
} }
} }
} }
} }
if ( function_exists('HM\BackUpWordPress\Backup::get_home_path') ) { if (function_exists('HM\BackUpWordPress\Backup::get_home_path'))
$backups_path = str_replace( HM\BackUpWordPress\Backup::get_home_path(), '', hmbkp_path() ); $backups_path = str_replace( HM\BackUpWordPress\Backup::get_home_path(), '', hmbkp_path() );
} else { else
$backups_path = str_replace( HM\BackUpWordPress\Path::get_home_path(), '', HM\BackUpWordPress\Path::get_path() ); $backups_path = str_replace( HM\BackUpWordPress\Path::get_home_path(), '', HM\BackUpWordPress\Path::get_path() );
}
$information['backups_path'] = $backups_path; $information['backups_path'] = $backups_path;
$information['send_back_schedules'] = $send_back_schedules; $information['send_back_schedules'] = $send_back_schedules;
@ -426,16 +421,16 @@ class MainWP_Child_Back_Up_Wordpress {
return array( 'error' => $deleted->get_error_message() ); return array( 'error' => $deleted->get_error_message() );
} }
$ret = array( $ret = array(
'result' => 'SUCCESS', 'result' => 'SUCCESS',
'b' => $this->get_backupslist_html( $schedule ), 'b' => $this->get_backupslist_html( $schedule ),
'count' => count( $schedule->get_backups() ), 'count' => count( $schedule->get_backups() ),
'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ), 'file_size_text' => $this->hmbkp_get_site_size_text( $schedule ),
); );
if ( method_exists($schedule, 'get_running_backup_filename' ) ) { if (method_exists($schedule, 'get_running_backup_filename' )) {
$ret['scheduleStatus'] = $schedule->get_status(); $ret['scheduleStatus'] = $schedule->get_status();
} else { } else {
$status = $schedule->get_status(); $status = $schedule->get_status();
$ret['scheduleStatus'] = $status->get_status(); $ret['scheduleStatus'] = $status->get_status();
} }
return $ret; return $ret;
@ -450,7 +445,7 @@ class MainWP_Child_Back_Up_Wordpress {
<tr> <tr>
<th scope="col"><?php function_exists('hmbkp_backups_number') ? hmbkp_backups_number( $schedule ) : ( function_exists('backups_number') ? backups_number( $schedule ) : '' ); ?></th> <th scope="col"><?php function_exists('hmbkp_backups_number') ? hmbkp_backups_number( $schedule ) : ( function_exists('backups_number') ? backups_number( $schedule ) : "" ) ; ?></th>
<th scope="col"><?php esc_html_e( 'Size', 'mainwp-backupwordpress-extension' ); ?></th> <th scope="col"><?php esc_html_e( 'Size', 'mainwp-backupwordpress-extension' ); ?></th>
<th scope="col"><?php esc_html_e( 'Type', 'mainwp-backupwordpress-extension' ); ?></th> <th scope="col"><?php esc_html_e( 'Type', 'mainwp-backupwordpress-extension' ); ?></th>
<th scope="col"><?php esc_html_e( 'Actions', 'mainwp-backupwordpress-extension' ); ?></th> <th scope="col"><?php esc_html_e( 'Actions', 'mainwp-backupwordpress-extension' ); ?></th>
@ -461,8 +456,7 @@ class MainWP_Child_Back_Up_Wordpress {
<tbody> <tbody>
<?php <?php if ( $schedule->get_backups() ) {
if ( $schedule->get_backups() ) {
$schedule->delete_old_backups(); $schedule->delete_old_backups();
@ -475,8 +469,7 @@ class MainWP_Child_Back_Up_Wordpress {
$this->hmbkp_get_backup_row( $file, $schedule ); $this->hmbkp_get_backup_row( $file, $schedule );
} }
} else { } else { ?>
?>
<tr> <tr>
<td class="hmbkp-no-backups" <td class="hmbkp-no-backups"
@ -496,7 +489,7 @@ class MainWP_Child_Back_Up_Wordpress {
function hmbkp_get_site_size_text( HM\BackUpWordPress\Scheduled_Backup $schedule ) { function hmbkp_get_site_size_text( HM\BackUpWordPress\Scheduled_Backup $schedule ) {
if ( method_exists($schedule, 'is_site_size_cached') ) { if (method_exists($schedule, 'is_site_size_cached')) {
if ( ( 'database' === $schedule->get_type() ) || $schedule->is_site_size_cached() ) { if ( ( 'database' === $schedule->get_type() ) || $schedule->is_site_size_cached() ) {
return sprintf( '(<code title="' . __( 'Backups will be compressed and should be smaller than this.', 'mainwp-backupwordpress-extension' ) . '">%s</code>)', esc_attr( $schedule->get_formatted_site_size() ) ); return sprintf( '(<code title="' . __( 'Backups will be compressed and should be smaller than this.', 'mainwp-backupwordpress-extension' ) . '">%s</code>)', esc_attr( $schedule->get_formatted_site_size() ) );
} }
@ -508,6 +501,7 @@ class MainWP_Child_Back_Up_Wordpress {
} }
return sprintf( '(<code class="calculating" title="' . __( 'this shouldn\'t take long&hellip;', 'mainwp-backupwordpress-extension' ) . '">' . __( 'calculating the size of your backup&hellip;', 'mainwp-backupwordpress-extension' ) . '</code>)' ); return sprintf( '(<code class="calculating" title="' . __( 'this shouldn\'t take long&hellip;', 'mainwp-backupwordpress-extension' ) . '">' . __( 'calculating the size of your backup&hellip;', 'mainwp-backupwordpress-extension' ) . '</code>)' );
} }
function hmbkp_get_backup_row( $file, HM\BackUpWordPress\Scheduled_Backup $schedule ) { function hmbkp_get_backup_row( $file, HM\BackUpWordPress\Scheduled_Backup $schedule ) {
@ -531,23 +525,20 @@ class MainWP_Child_Back_Up_Wordpress {
<td> <td>
<?php <?php if (function_exists('hmbkp_is_path_accessible')) {
if ( function_exists('hmbkp_is_path_accessible') ) {
if ( hmbkp_is_path_accessible( hmbkp_path() ) ) { if ( hmbkp_is_path_accessible( hmbkp_path() ) ) {
?> ?>
<a href="#" <a href="#"
onclick="event.preventDefault(); mainwp_backupwp_download_backup('<?php echo $encoded_file; ?>', <?php echo esc_attr( $schedule->get_id() ); ?>, this);" onclick="event.preventDefault(); mainwp_backupwp_download_backup('<?php echo $encoded_file; ?>', <?php echo esc_attr( $schedule->get_id() ); ?>, this);"
class="download-action"><?php esc_html_e( 'Download', 'backupwordpress' ); ?></a> | class="download-action"><?php esc_html_e( 'Download', 'backupwordpress' ); ?></a> |
<?php <?php };
}; } else if (function_exists('HM\BackUpWordPress\is_path_accessible') ) {
} elseif ( function_exists('HM\BackUpWordPress\is_path_accessible') ) { if (HM\BackUpWordPress\is_path_accessible(HM\BackUpWordPress\Path::get_path())) {
if ( HM\BackUpWordPress\is_path_accessible(HM\BackUpWordPress\Path::get_path()) ) {
?> ?>
<a href="#" <a href="#"
onclick="event.preventDefault(); mainwp_backupwp_download_backup('<?php echo $encoded_file; ?>', <?php echo esc_attr( $schedule->get_id() ); ?>, this);" onclick="event.preventDefault(); mainwp_backupwp_download_backup('<?php echo $encoded_file; ?>', <?php echo esc_attr( $schedule->get_id() ); ?>, this);"
class="download-action"><?php esc_html_e( 'Download', 'backupwordpress' ); ?></a> | class="download-action"><?php esc_html_e( 'Download', 'backupwordpress' ); ?></a> |
<?php <?php };
};
} }
?> ?>
@ -559,8 +550,7 @@ class MainWP_Child_Back_Up_Wordpress {
</tr> </tr>
<?php <?php }
}
function get_excluded( $browse_dir = null ) { function get_excluded( $browse_dir = null ) {
@ -568,15 +558,15 @@ class MainWP_Child_Back_Up_Wordpress {
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) ); $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( urldecode( $schedule_id ) ) );
$new_version = true; $new_version = true;
if ( method_exists($schedule, 'get_running_backup_filename' ) ) { if (method_exists($schedule, 'get_running_backup_filename' )) {
$new_version = false; $new_version = false;
$user_excludes = array_diff( $schedule->get_excludes(), $schedule->backup->default_excludes() ); $user_excludes = array_diff( $schedule->get_excludes(), $schedule->backup->default_excludes() );
$root_dir = $schedule->backup->get_root(); $root_dir = $schedule->backup->get_root();
$is_size_calculated = $schedule->is_site_size_being_calculated(); $is_size_calculated = $schedule->is_site_size_being_calculated();
} else { } else {
$excludes = $schedule->get_excludes(); $excludes = $schedule->get_excludes();
$user_excludes = $excludes->get_user_excludes(); $user_excludes = $excludes->get_user_excludes();
$root_dir = HM\BackUpWordPress\Path::get_root(); $root_dir = HM\BackUpWordPress\Path::get_root();
$is_size_calculated = HM\BackUpWordPress\Site_Size::is_site_size_being_calculated(); $is_size_calculated = HM\BackUpWordPress\Site_Size::is_site_size_being_calculated();
} }
@ -585,7 +575,7 @@ class MainWP_Child_Back_Up_Wordpress {
?> ?>
<div class="hmbkp-exclude-settings"> <div class="hmbkp-exclude-settings">
<?php // if ( $schedule->get_excludes() ) : ?> <?php //if ( $schedule->get_excludes() ) : ?>
<h3> <h3>
<?php esc_html_e( 'Currently Excluded', 'backupwordpress' ); ?> <?php esc_html_e( 'Currently Excluded', 'backupwordpress' ); ?>
@ -625,14 +615,12 @@ class MainWP_Child_Back_Up_Wordpress {
<td> <td>
<?php <?php
if ( $new_version ) { if ($new_version)
$is_default_rule = ( in_array( $exclude, $excludes->get_default_excludes() ) ) || ( HM\BackUpWordPress\Path::get_path() === trailingslashit( HM\BackUpWordPress\Path::get_root() ) . untrailingslashit( $exclude ) ); $is_default_rule = ( in_array( $exclude, $excludes->get_default_excludes() ) ) || ( HM\BackUpWordPress\Path::get_path() === trailingslashit( HM\BackUpWordPress\Path::get_root() ) . untrailingslashit( $exclude ) );
} else { else
$is_default_rule = ( in_array( $exclude, $schedule->backup->default_excludes() ) ) || ( hmbkp_path() === untrailingslashit( $exclude ) ); $is_default_rule = ( in_array( $exclude, $schedule->backup->default_excludes() ) ) || ( hmbkp_path() === untrailingslashit( $exclude ) ) ;
}
if ( $is_default_rule ) : if ( $is_default_rule ) : ?>
?>
<?php esc_html_e( 'Default rule', 'backupwordpress' ); ?> <?php esc_html_e( 'Default rule', 'backupwordpress' ); ?>
<?php elseif ( defined( 'HMBKP_EXCLUDE' ) && false !== strpos( HMBKP_EXCLUDE, $exclude ) ) : ?> <?php elseif ( defined( 'HMBKP_EXCLUDE' ) && false !== strpos( HMBKP_EXCLUDE, $exclude ) ) : ?>
@ -657,7 +645,7 @@ class MainWP_Child_Back_Up_Wordpress {
</table> </table>
<?php // endif; ?> <?php //endif; ?>
<h3 id="directory-listing"><?php esc_html_e( 'Your Site', 'backupwordpress' ); ?></h3> <h3 id="directory-listing"><?php esc_html_e( 'Your Site', 'backupwordpress' ); ?></h3>
@ -678,22 +666,21 @@ class MainWP_Child_Back_Up_Wordpress {
} }
// Kick off a recursive filesize scan // Kick off a recursive filesize scan
if ( $new_version ) { if ($new_version) {
$site_size = new HM\BackUpWordPress\Site_Size(); $site_size = new HM\BackUpWordPress\Site_Size;
$exclude_string = implode( '|', $excludes->get_excludes_for_regex() ); $exclude_string = implode( '|', $excludes->get_excludes_for_regex() );
if ( function_exists('HM\BackUpWordPress\list_directory_by_total_filesize') ) { if (function_exists('HM\BackUpWordPress\list_directory_by_total_filesize'))
$files = HM\BackUpWordPress\list_directory_by_total_filesize( $directory, $excludes ); $files = HM\BackUpWordPress\list_directory_by_total_filesize( $directory, $excludes );
}
} else { } else {
$files = $schedule->list_directory_by_total_filesize( $directory ); $files = $schedule->list_directory_by_total_filesize( $directory );
$exclude_string = $schedule->backup->exclude_string( 'regex' ); $exclude_string = $schedule->backup->exclude_string( 'regex' );
} }
if ( $files ) { if ( $files ) { ?>
?>
<table class="widefat"> <table class="widefat">
<thead> <thead>
@ -715,19 +702,16 @@ class MainWP_Child_Back_Up_Wordpress {
<th scope="col"> <th scope="col">
<?php <?php if ( $root_dir !== $directory ) {
if ( $root_dir !== $directory ) {
// echo esc_url( remove_query_arg( 'hmbkp_directory_browse' ) ); // echo esc_url( remove_query_arg( 'hmbkp_directory_browse' ) );
?> ?>
<a href="#" <a href="#"
onclick="event.preventDefault(); mainwp_backupwp_directory_browse('', this)"><?php echo esc_html( $root_dir ); ?></a> onclick="event.preventDefault(); mainwp_backupwp_directory_browse('', this)"><?php echo esc_html( $root_dir ); ?></a>
<code>/</code> <code>/</code>
<?php <?php $parents = array_filter( explode( '/', str_replace( trailingslashit( $root_dir ), '', trailingslashit( dirname( $directory ) ) ) ) );
$parents = array_filter( explode( '/', str_replace( trailingslashit( $root_dir ), '', trailingslashit( dirname( $directory ) ) ) ) );
foreach ( $parents as $directory_basename ) { foreach ( $parents as $directory_basename ) { ?>
?>
<a href="#" <a href="#"
onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo urlencode( substr( $directory, 0, strpos( $directory, $directory_basename ) ) . $directory_basename ); ?>', this)"><?php echo esc_html( $directory_basename ); ?></a> onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo urlencode( substr( $directory, 0, strpos( $directory, $directory_basename ) ) . $directory_basename ); ?>', this)"><?php echo esc_html( $directory_basename ); ?></a>
@ -756,7 +740,7 @@ class MainWP_Child_Back_Up_Wordpress {
$root = new SplFileInfo( $root_dir ); $root = new SplFileInfo( $root_dir );
if ( $new_version ) { if ($new_version) {
$size = $site_size->filesize( $root ); $size = $site_size->filesize( $root );
} else { } else {
$size = $schedule->filesize( $root, true ); $size = $schedule->filesize( $root, true );
@ -809,13 +793,12 @@ class MainWP_Child_Back_Up_Wordpress {
<tbody> <tbody>
<?php <?php foreach ( $files as $size => $file ) {
foreach ( $files as $size => $file ) {
$is_excluded = $is_unreadable = false; $is_excluded = $is_unreadable = false;
// Check if the file is excluded // Check if the file is excluded
if ( $new_version ) { if ($new_version) {
if ( $exclude_string && preg_match( '(' . $exclude_string . ')', str_ireplace( trailingslashit( $root_dir ), '', wp_normalize_path( $file->getPathname() ) ) ) ) { if ( $exclude_string && preg_match( '(' . $exclude_string . ')', str_ireplace( trailingslashit( $root_dir ), '', wp_normalize_path( $file->getPathname() ) ) ) ) {
$is_excluded = true; $is_excluded = true;
} }
@ -828,8 +811,7 @@ class MainWP_Child_Back_Up_Wordpress {
// Skip unreadable files // Skip unreadable files
if ( ! @realpath( $file->getPathname() ) || ! $file->isReadable() ) { if ( ! @realpath( $file->getPathname() ) || ! $file->isReadable() ) {
$is_unreadable = true; $is_unreadable = true;
} } ?>
?>
<tr> <tr>
@ -853,9 +835,8 @@ class MainWP_Child_Back_Up_Wordpress {
<td> <td>
<?php <?php
if ( $new_version ) { if ($new_version) {
if ( $is_unreadable ) { if ( $is_unreadable ) { ?>
?>
<code class="strikethrough" <code class="strikethrough"
title="<?php echo esc_attr( wp_normalize_path( $file->getRealPath() ) ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code> title="<?php echo esc_attr( wp_normalize_path( $file->getRealPath() ) ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
@ -871,11 +852,9 @@ class MainWP_Child_Back_Up_Wordpress {
onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo urlencode( wp_normalize_path( $file->getPathname()) ); ?>', this)"><?php echo esc_html( $file->getBasename() ); ?></a></code> onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo urlencode( wp_normalize_path( $file->getPathname()) ); ?>', this)"><?php echo esc_html( $file->getBasename() ); ?></a></code>
<?php <?php }
}
} else { } else {
if ( $is_unreadable ) { if ( $is_unreadable ) { ?>
?>
<code class="strikethrough" <code class="strikethrough"
title="<?php echo esc_attr( $file->getRealPath() ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code> title="<?php echo esc_attr( $file->getRealPath() ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
@ -885,16 +864,14 @@ class MainWP_Child_Back_Up_Wordpress {
<code <code
title="<?php echo esc_attr( $file->getRealPath() ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code> title="<?php echo esc_attr( $file->getRealPath() ); ?>"><?php echo esc_html( $file->getBasename() ); ?></code>
<?php <?php } elseif ( $file->isDir() ) {
} elseif ( $file->isDir() ) { //echo add_query_arg( 'hmbkp_directory_browse', urlencode( $file->getPathname() ) );
// echo add_query_arg( 'hmbkp_directory_browse', urlencode( $file->getPathname() ) );
?> ?>
<code title="<?php echo esc_attr( $file->getRealPath() ); ?>"><a <code title="<?php echo esc_attr( $file->getRealPath() ); ?>"><a
href="#" href="#"
onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo urlencode( $file->getPathname() ); ?>', this)"><?php echo esc_html( $file->getBasename() ); ?></a></code> onclick="event.preventDefault(); mainwp_backupwp_directory_browse('<?php echo urlencode( $file->getPathname() ); ?>', this)"><?php echo esc_html( $file->getBasename() ); ?></a></code>
<?php <?php }
}
} }
?> ?>
@ -908,7 +885,7 @@ class MainWP_Child_Back_Up_Wordpress {
<?php <?php
else : else :
if ( $new_version ) { if ($new_version) {
$size = $site_size->filesize( $file ); $size = $site_size->filesize( $file );
} else { } else {
$size = $schedule->filesize( $file ); $size = $schedule->filesize( $file );
@ -920,8 +897,7 @@ class MainWP_Child_Back_Up_Wordpress {
if ( ! $size ) { if ( ! $size ) {
$size = '0 B'; $size = '0 B';
} } ?>
?>
<code> <code>
@ -942,8 +918,7 @@ class MainWP_Child_Back_Up_Wordpress {
<code>--</code> <code>--</code>
<?php <?php }
}
endif; endif;
?> ?>
@ -960,8 +935,7 @@ class MainWP_Child_Back_Up_Wordpress {
<span <span
title="<?php echo esc_attr( wp_normalize_path( $file->GetRealPath() ) ); ?>"><?php esc_html_e( 'Symlink', 'backupwordpress' ); ?></span> title="<?php echo esc_attr( wp_normalize_path( $file->GetRealPath() ) ); ?>"><?php esc_html_e( 'Symlink', 'backupwordpress' ); ?></span>
<?php <?php elseif ( $file->isDir() ) :
elseif ( $file->isDir() ) :
esc_html_e( 'Folder', 'backupwordpress' ); esc_html_e( 'Folder', 'backupwordpress' );
@ -1025,6 +999,7 @@ class MainWP_Child_Back_Up_Wordpress {
$information['e'] = $output; $information['e'] = $output;
return $information; return $information;
} }
function directory_browse() { function directory_browse() {
@ -1063,6 +1038,7 @@ class MainWP_Child_Back_Up_Wordpress {
$out['current_browse_dir'] = $_POST['browse_dir']; $out['current_browse_dir'] = $_POST['browse_dir'];
return $out; return $out;
} }
function hmbkp_remove_exclude_rule() { function hmbkp_remove_exclude_rule() {
@ -1074,14 +1050,13 @@ class MainWP_Child_Back_Up_Wordpress {
$schedule_id = $this->check_schedule(); $schedule_id = $this->check_schedule();
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $schedule_id ) ); $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $schedule_id ) );
$excludes = $schedule->get_excludes(); $excludes = $schedule->get_excludes();
$exclude_rule_to_remove = stripslashes( sanitize_text_field( $_POST['remove_rule'] ) ); $exclude_rule_to_remove = stripslashes( sanitize_text_field( $_POST['remove_rule'] ) );
if ( method_exists($excludes, 'get_user_excludes') ) { if (method_exists($excludes, 'get_user_excludes')) {
$schedule->set_excludes( array_diff( $excludes->get_user_excludes(), (array) $exclude_rule_to_remove ) ); $schedule->set_excludes( array_diff( $excludes->get_user_excludes(), (array) $exclude_rule_to_remove ) );
} else { } else
$schedule->set_excludes( array_diff( $excludes, $exclude_rule_to_remove ) ); $schedule->set_excludes( array_diff( $excludes, $exclude_rule_to_remove ) );
}
$schedule->save(); $schedule->save();
@ -1102,53 +1077,53 @@ class MainWP_Child_Back_Up_Wordpress {
function general_exclude_add_rule() { function general_exclude_add_rule() {
$sch_id = $this->check_schedule(); $sch_id = $this->check_schedule();
$schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $sch_id ) ); $schedule = new HM\BackUpWordPress\Scheduled_Backup( sanitize_text_field( $sch_id ) );
$exclude_paths = urldecode( $_POST['exclude_paths'] ); $exclude_paths = urldecode( $_POST['exclude_paths'] );
$exclude_paths = explode("\n", $exclude_paths); $exclude_paths = explode("\n", $exclude_paths);
if ( is_array($exclude_paths) && count($exclude_paths) > 0 ) { if (is_array($exclude_paths) && count($exclude_paths) > 0) {
foreach ( $exclude_paths as $excl_rule ) { foreach ( $exclude_paths as $excl_rule ) {
$excl_rule = trim($excl_rule); $excl_rule = trim($excl_rule);
$excl_rule = trim($excl_rule, '/'); $excl_rule = trim($excl_rule, '/');
if ( empty($excl_rule) ) { if (empty($excl_rule))
continue; continue;
}
$exclude_rule = ABSPATH . $excl_rule; $exclude_rule = ABSPATH . $excl_rule;
$path = realpath($exclude_rule); $path = realpath($exclude_rule);
// If it exist // If it exist
if ( $path !== false ) { if($path !== false)
{
$schedule->set_excludes( $exclude_rule, true ); $schedule->set_excludes( $exclude_rule, true );
$schedule->save(); $schedule->save();
} }
} }
} }
$un_exclude_paths = urldecode( $_POST['un_exclude_paths'] ); $un_exclude_paths = urldecode( $_POST['un_exclude_paths'] );
$un_exclude_paths = explode("\n", $un_exclude_paths); $un_exclude_paths = explode("\n", $un_exclude_paths);
if ( is_array($un_exclude_paths) && count(get_user_excludes) > 0 ) { if (is_array($un_exclude_paths) && count(get_user_excludes) > 0) {
foreach ( $un_exclude_paths as $exclude_rule_to_remove ) { foreach ( $un_exclude_paths as $exclude_rule_to_remove ) {
$exclude_rule_to_remove = trim($exclude_rule_to_remove); $exclude_rule_to_remove = trim($exclude_rule_to_remove);
$exclude_rule_to_remove = trim($exclude_rule_to_remove, '/'); $exclude_rule_to_remove = trim($exclude_rule_to_remove, '/');
if ( empty($exclude_rule_to_remove) ) { if (empty($exclude_rule_to_remove))
continue; continue;
}
$excludes = $schedule->get_excludes(); $excludes = $schedule->get_excludes();
if ( method_exists($excludes, 'get_user_excludes') ) { if (method_exists($excludes, 'get_user_excludes')) {
$schedule->set_excludes( array_diff( $excludes->get_user_excludes(), (array) $exclude_rule_to_remove ) ); $schedule->set_excludes( array_diff( $excludes->get_user_excludes(), (array) $exclude_rule_to_remove ) );
} else { } else {
$schedule->set_excludes( array_diff( $excludes, $exclude_rule_to_remove ) ); $schedule->set_excludes( array_diff( $excludes, $exclude_rule_to_remove ) );
} }
$schedule->save(); $schedule->save();
} }
} }
return array( 'result' => 'SUCCESS' ); return array('result' => 'SUCCESS');
} }
@ -1161,11 +1136,11 @@ class MainWP_Child_Back_Up_Wordpress {
return array( 'error' => 'Error: Schedule data' ); return array( 'error' => 'Error: Schedule data' );
} }
// $current_value = get_option( 'hmbkp_schedule_' . $sch_id ); // $current_value = get_option( 'hmbkp_schedule_' . $sch_id );
// if ( is_array( $current_value ) && isset( $current_value['excludes'] ) ) { // if ( is_array( $current_value ) && isset( $current_value['excludes'] ) ) {
// do not update 'excludes' value // // do not update 'excludes' value
// $options['excludes'] = $current_value['excludes']; // $options['excludes'] = $current_value['excludes'];
// } // }
$filter_opts = array( $filter_opts = array(
'type', 'type',
@ -1219,11 +1194,10 @@ class MainWP_Child_Back_Up_Wordpress {
} }
$out = array(); $out = array();
foreach ( $schedules as $sch_id => $sch ) { foreach($schedules as $sch_id => $sch) {
if ( empty($sch_id) || ! isset( $sch['options'] ) || ! is_array( $sch['options'] ) ) { if ( empty($sch_id) || !isset( $sch['options'] ) || ! is_array( $sch['options'] ) )
continue; continue;
} $options = $sch['options'];
$options = $sch['options'];
$filter_opts = array( $filter_opts = array(
'type', 'type',
'email', 'email',

View file

@ -22,11 +22,11 @@ if ( ! defined( 'MAINWP_BACKWPUP_DEVELOPMENT' ) ) {
class MainWP_Child_Back_WP_Up { class MainWP_Child_Back_WP_Up {
public $is_backwpup_installed = false; public $is_backwpup_installed = false;
public $is_backwpup_pro = false; public $is_backwpup_pro = false;
public $plugin_translate = 'mainwp-backwpup-extension'; public $plugin_translate = 'mainwp-backwpup-extension';
public static $instance = null; public static $instance = null;
protected $software_version = '0.1'; protected $software_version = '0.1';
public static $information = array(); public static $information = array();
protected $exclusions = array( protected $exclusions = array(
'cron' => array( 'cron' => array(
@ -58,15 +58,15 @@ class MainWP_Child_Back_WP_Up {
); );
static function Instance() { static function Instance() {
if ( self::$instance == null ) { if ( MainWP_Child_Back_WP_Up::$instance == null ) {
self::$instance = new MainWP_Child_Back_WP_Up(); MainWP_Child_Back_WP_Up::$instance = new MainWP_Child_Back_WP_Up();
} }
return self::$instance; return MainWP_Child_Back_WP_Up::$instance;
} }
public function __construct() { public function __construct() {
require_once ABSPATH . 'wp-admin/includes/plugin.php'; require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
try { try {
@ -80,27 +80,27 @@ class MainWP_Child_Back_WP_Up {
} }
MainWP_Helper::check_files_exists(array( $file_path1, $file_path2 )); MainWP_Helper::check_files_exists(array( $file_path1, $file_path2 ));
require_once $file_path1; require_once( $file_path1 );
require_once $file_path2; require_once( $file_path2 );
$this->is_backwpup_installed = true; $this->is_backwpup_installed = true;
$this->is_backwpup_pro = true; $this->is_backwpup_pro = true;
} elseif ( is_plugin_active( 'backwpup/backwpup.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php' ) ) { } else if ( is_plugin_active( 'backwpup/backwpup.php' ) && file_exists( plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php' ) ) {
$file_path = plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php'; $file_path = plugin_dir_path( __FILE__ ) . '../../backwpup/backwpup.php';
MainWP_Helper::check_files_exists(array( $file_path )); MainWP_Helper::check_files_exists(array( $file_path ));
require_once $file_path; require_once( $file_path );
$this->is_backwpup_installed = true; $this->is_backwpup_installed = true;
} }
if ( $this->is_backwpup_installed ) { if ($this->is_backwpup_installed) {
MainWP_Helper::check_classes_exists('BackWPup'); MainWP_Helper::check_classes_exists('BackWPup');
MainWP_Helper::check_methods('get_instance'); MainWP_Helper::check_methods('get_instance');
BackWPup::get_instance(); BackWPup::get_instance();
// add_action( 'wp_ajax_mainwp_backwpup_download_backup', array( $this, 'download_backup' ) ); //add_action( 'wp_ajax_mainwp_backwpup_download_backup', array( $this, 'download_backup' ) );
add_action( 'admin_init', array( $this, 'init_download_backup' ) ); add_action( 'admin_init', array( $this, 'init_download_backup' ) );
add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 );
} }
} catch ( Exception $e ) { } catch ( Exception $e) {
// do not exit() // do not exit()
$this->is_backwpup_installed = false; $this->is_backwpup_installed = false;
} }
@ -116,11 +116,11 @@ class MainWP_Child_Back_WP_Up {
error_reporting( 0 ); error_reporting( 0 );
function mainwp_backwpup_handle_fatal_error() { function mainwp_backwpup_handle_fatal_error() {
$error = error_get_last(); $error = error_get_last();
$info = self::$information; $info = MainWP_Child_Back_WP_Up::$information;
if ( isset( $error['type'] ) && E_ERROR === $error['type'] && isset( $error['message'] ) ) { if ( isset( $error['type'] ) && E_ERROR === $error['type'] && isset( $error['message'] ) ) {
MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) ); MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) );
} elseif ( ! empty( $info ) ) { } else if ( ! empty( $info ) ) {
MainWP_Helper::write( self::$information ); MainWP_Helper::write( MainWP_Child_Back_WP_Up::$information );
} else { } else {
MainWP_Helper::write( array( 'error' => 'Missing information array inside fatal_error' ) ); MainWP_Helper::write( array( 'error' => 'Missing information array inside fatal_error' ) );
} }
@ -212,15 +212,14 @@ class MainWP_Child_Back_WP_Up {
} }
} }
self::$information = $information; MainWP_Child_Back_WP_Up::$information = $information;
exit(); exit();
} }
public function init() { public function init() {
if ( ! $this->is_backwpup_installed ) { if (!$this->is_backwpup_installed)
return; return;
}
add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) ); add_action( 'mainwp_child_site_stats', array( $this, 'do_site_stats' ) );
@ -231,24 +230,21 @@ class MainWP_Child_Back_WP_Up {
} }
function do_site_stats() { function do_site_stats() {
if ( has_action('mainwp_child_reports_log') ) { if (has_action('mainwp_child_reports_log')) {
do_action( 'mainwp_child_reports_log', 'backwpup'); do_action( 'mainwp_child_reports_log', 'backwpup');
} else { } else {
$this->do_reports_log('backwpup'); $this->do_reports_log('backwpup');
} }
} }
// ok // ok
public function do_reports_log( $ext = '' ) { public function do_reports_log($ext = '') {
if ( $ext !== 'backwpup' ) { if ( $ext !== 'backwpup' ) return;
if (!$this->is_backwpup_installed)
return; return;
}
if ( ! $this->is_backwpup_installed ) {
return;
}
try { try {
MainWP_Helper::check_classes_exists(array( 'BackWPup_File', 'BackWPup_Job' )); MainWP_Helper::check_classes_exists(array('BackWPup_File', 'BackWPup_Job'));
MainWP_Helper::check_methods('BackWPup_File', array( 'get_absolute_path' )); MainWP_Helper::check_methods('BackWPup_File', array( 'get_absolute_path' ));
MainWP_Helper::check_methods('BackWPup_Job', array( 'read_logheader' )); MainWP_Helper::check_methods('BackWPup_Job', array( 'read_logheader' ));
@ -258,12 +254,12 @@ class MainWP_Child_Back_WP_Up {
$log_folder = BackWPup_File::get_absolute_path( $log_folder ); $log_folder = BackWPup_File::get_absolute_path( $log_folder );
$log_folder = untrailingslashit( $log_folder ); $log_folder = untrailingslashit( $log_folder );
// load logs //load logs
$logfiles = array(); $logfiles = array();
if ( is_readable( $log_folder ) && $dir = opendir( $log_folder ) ) { if ( is_readable( $log_folder ) && $dir = opendir( $log_folder ) ) {
while ( ( $file = readdir( $dir ) ) !== false ) { while ( ( $file = readdir( $dir ) ) !== FALSE ) {
$log_file = $log_folder . '/' . $file; $log_file = $log_folder . '/' . $file;
if ( is_file( $log_file ) && is_readable( $log_file ) && false !== strpos( $file, 'backwpup_log_' ) && false !== strpos( $file, '.html' ) ) { if ( is_file( $log_file ) && is_readable( $log_file ) && FALSE !== strpos( $file, 'backwpup_log_' ) && FALSE !== strpos( $file, '.html' ) ) {
$logfiles[] = $file; $logfiles[] = $file;
} }
} }
@ -273,44 +269,43 @@ class MainWP_Child_Back_WP_Up {
$log_items = array(); $log_items = array();
foreach ( $logfiles as $mtime => $logfile ) { foreach ( $logfiles as $mtime => $logfile ) {
$meta = BackWPup_Job::read_logheader( $log_folder . '/' . $logfile ); $meta = BackWPup_Job::read_logheader( $log_folder . '/' . $logfile );
if ( ! isset($meta['logtime']) || $meta['logtime'] < $lasttime_logged ) { if (!isset($meta['logtime']) || $meta['logtime'] < $lasttime_logged)
continue; continue;
}
if ( isset($meta['errors']) && ! empty($meta['errors']) ) { if (isset($meta['errors']) && !empty($meta['errors'])) {
continue; // do not logging backups have errors continue; // do not logging backups have errors
} }
$log_items[ $mtime ] = $meta; $log_items[$mtime] = $meta;
$log_items[ $mtime ]['file'] = $logfile; $log_items[$mtime]['file'] = $logfile;
} }
if ( ! empty( $log_items ) ) { if ( !empty( $log_items ) ) {
$job_types = array( $job_types = array(
'DBDUMP' => __('Database backup', 'mainwp-child'), 'DBDUMP' => __('Database backup', 'mainwp-child'),
'FILE' => __('File backup', 'mainwp-child'), 'FILE' => __('File backup', 'mainwp-child'),
'WPEXP' => __('WordPress XML export', 'mainwp-child'), 'WPEXP' => __('WordPress XML export', 'mainwp-child'),
'WPPLUGIN' => __('Installed plugins list', 'mainwp-child'), 'WPPLUGIN' => __('Installed plugins list', 'mainwp-child'),
'DBCHECK' => __('Check database tables', 'mainwp-child'), 'DBCHECK' => __('Check database tables', 'mainwp-child')
); );
$new_lasttime_logged = $lasttime_logged; $new_lasttime_logged = $lasttime_logged;
foreach ( $log_items as $log ) { foreach ($log_items as $log) {
$backup_time = $log['logtime']; $backup_time = $log[ "logtime" ];
if ( $backup_time < $lasttime_logged ) { if ($backup_time < $lasttime_logged) {
// small than last backup time then skip // small than last backup time then skip
continue; continue;
} }
$job_job_types = explode('+', $log['type']); $job_job_types = explode('+', $log['type']);
$backup_type = ''; $backup_type = '';
foreach ( $job_job_types as $typeid ) { foreach($job_job_types as $typeid) {
if ( isset( $job_types[ $typeid ] ) ) { if (isset( $job_types[$typeid] )) {
$backup_type .= ' + ' . $job_types[ $typeid ]; $backup_type .= ' + ' . $job_types[$typeid];
} }
} }
if ( empty($backup_type) ) { if (empty($backup_type)) {
continue; continue;
} else { } else {
$backup_type = ltrim($backup_type, ' + '); $backup_type = ltrim($backup_type, ' + ');
@ -318,29 +313,28 @@ class MainWP_Child_Back_WP_Up {
$message = 'BackWPup backup finished (' . $backup_type . ')'; $message = 'BackWPup backup finished (' . $backup_type . ')';
do_action( 'mainwp_reports_backwpup_backup', $message, $backup_type, $backup_time ); do_action( 'mainwp_reports_backwpup_backup', $message, $backup_type, $backup_time );
if ( $new_lasttime_logged < $backup_time ) { if ($new_lasttime_logged < $backup_time)
$new_lasttime_logged = $backup_time; $new_lasttime_logged = $backup_time;
}
} }
if ( $new_lasttime_logged > $lasttime_logged ) { if ($new_lasttime_logged > $lasttime_logged ) {
MainWP_Helper::update_lasttime_backup( 'backwpup', $new_lasttime_logged ); // to support backup before update feature MainWP_Helper::update_lasttime_backup( 'backwpup', $new_lasttime_logged ); // to support backup before update feature
} }
} }
} catch ( Exception $ex ) { } catch (Exception $ex) {
} }
} }
// ok // ok
function syncOthersData( $information, $data = array() ) { function syncOthersData( $information, $data = array() ) {
if ( isset( $data['syncBackwpupData'] ) && $data['syncBackwpupData'] ) { if ( isset( $data['syncBackwpupData'] ) && $data['syncBackwpupData'] ) {
try { try{
$lastbackup = MainWP_Helper::get_lasttime_backup('backwpup'); $lastbackup = MainWP_Helper::get_lasttime_backup('backwpup');
$information['syncBackwpupData'] = array( $information['syncBackwpupData'] = array(
'lastbackup' => $lastbackup, 'lastbackup' => $lastbackup
); );
} catch ( Exception $e ) { } catch(Exception $e) {
} }
} }
@ -348,7 +342,7 @@ class MainWP_Child_Back_WP_Up {
} }
function get_destinations_list() { function get_destinations_list() {
MainWP_Helper::check_classes_exists(array( 'BackWPup', 'BackWPup_Option' )); MainWP_Helper::check_classes_exists(array('BackWPup', 'BackWPup_Option'));
MainWP_Helper::check_methods('BackWPup', array( 'get_registered_destinations', 'get_destination' )); MainWP_Helper::check_methods('BackWPup', array( 'get_registered_destinations', 'get_destination' ));
MainWP_Helper::check_methods('BackWPup_Option', array( 'get_job_ids', 'get' )); MainWP_Helper::check_methods('BackWPup_Option', array( 'get_job_ids', 'get' ));
@ -361,15 +355,15 @@ class MainWP_Child_Back_WP_Up {
} }
$dests = BackWPup_Option::get( $jobid, 'destinations' ); $dests = BackWPup_Option::get( $jobid, 'destinations' );
foreach ( $dests as $dest ) { foreach ( $dests as $dest ) {
if ( ! $destinations[ $dest ]['class'] ) { if ( ! $destinations[ $dest ][ 'class' ] ) {
continue; continue;
} }
$dest_class = BackWPup::get_destination( $dest ); $dest_class = BackWPup::get_destination( $dest );
if ( $dest_class && method_exists($dest_class, 'file_get_list') ) { if ($dest_class && method_exists($dest_class, 'file_get_list')) {
$can_do_dest = $dest_class->file_get_list( $jobid . '_' . $dest ); $can_do_dest = $dest_class->file_get_list( $jobid . '_' . $dest );
if ( ! empty( $can_do_dest ) ) { if ( ! empty( $can_do_dest ) ) {
$jobdest[] = $jobid . '_' . $dest; $jobdest[ ] = $jobid . '_' . $dest;
} }
} }
} }
@ -518,7 +512,7 @@ class MainWP_Child_Back_WP_Up {
echo '<tr title="WP_MEMORY_LIMIT"><td>' . __( 'WP memory limit', 'backwpup' ) . '</td><td>' . esc_html( WP_MEMORY_LIMIT ) . '</td></tr>'; echo '<tr title="WP_MEMORY_LIMIT"><td>' . __( 'WP memory limit', 'backwpup' ) . '</td><td>' . esc_html( WP_MEMORY_LIMIT ) . '</td></tr>';
echo '<tr title="WP_MAX_MEMORY_LIMIT"><td>' . __( 'WP maximum memory limit', 'backwpup' ) . '</td><td>' . esc_html( WP_MAX_MEMORY_LIMIT ) . '</td></tr>'; echo '<tr title="WP_MAX_MEMORY_LIMIT"><td>' . __( 'WP maximum memory limit', 'backwpup' ) . '</td><td>' . esc_html( WP_MAX_MEMORY_LIMIT ) . '</td></tr>';
echo '<tr title=""><td>' . __( 'Memory in use', 'backwpup' ) . '</td><td>' . esc_html( size_format( @memory_get_usage( true ), 2 ) ) . '</td></tr>'; echo '<tr title=""><td>' . __( 'Memory in use', 'backwpup' ) . '</td><td>' . esc_html( size_format( @memory_get_usage( true ), 2 ) ) . '</td></tr>';
// disabled PHP functions //disabled PHP functions
$disabled = ini_get( 'disable_functions' ); $disabled = ini_get( 'disable_functions' );
if ( ! empty( $disabled ) ) { if ( ! empty( $disabled ) ) {
$disabledarry = explode( ',', $disabled ); $disabledarry = explode( ',', $disabled );
@ -526,7 +520,7 @@ class MainWP_Child_Back_WP_Up {
echo esc_html( implode( ', ', $disabledarry ) ); echo esc_html( implode( ', ', $disabledarry ) );
echo '</td></tr>'; echo '</td></tr>';
} }
// Loaded PHP Extensions //Loaded PHP Extensions
echo '<tr title=""><td>' . __( 'Loaded PHP Extensions:', 'backwpup' ) . '</td><td>'; echo '<tr title=""><td>' . __( 'Loaded PHP Extensions:', 'backwpup' ) . '</td><td>';
$extensions = get_loaded_extensions(); $extensions = get_loaded_extensions();
sort( $extensions ); sort( $extensions );
@ -538,10 +532,7 @@ class MainWP_Child_Back_WP_Up {
ob_end_clean(); ob_end_clean();
return array( return array( 'success' => 1, 'response' => $output );
'success' => 1,
'response' => $output,
);
} }
protected function delete_log() { protected function delete_log() {
@ -610,17 +601,11 @@ class MainWP_Child_Back_WP_Up {
if ( is_array( $file ) && $file['file'] == $backupfile ) { if ( is_array( $file ) && $file['file'] == $backupfile ) {
$dest_class->file_delete( $dest, $backupfile ); $dest_class->file_delete( $dest, $backupfile );
return array( return array( 'success' => 1, 'response' => 'DELETED' );
'success' => 1,
'response' => 'DELETED',
);
} }
} }
return array( return array( 'success' => 1, 'response' => 'Not found' );
'success' => 1,
'response' => 'Not found',
);
} }
protected function view_log() { protected function view_log() {
@ -630,7 +615,7 @@ class MainWP_Child_Back_WP_Up {
$log_folder = get_site_option( 'backwpup_cfg_logfolder' ); $log_folder = get_site_option( 'backwpup_cfg_logfolder' );
$log_folder = BackWPup_File::get_absolute_path( $log_folder ); $log_folder = BackWPup_File::get_absolute_path( $log_folder );
$log_file = $log_folder . basename( $_POST['settings']['logfile'] ); $log_file = $log_folder . basename( $_POST['settings']['logfile'] );
if ( ! is_readable( $log_file ) && ! is_readable( $log_file . '.gz' ) && ! is_readable( $log_file . '.bz2' ) ) { if ( ! is_readable( $log_file ) && ! is_readable( $log_file . '.gz' ) && ! is_readable( $log_file . '.bz2' ) ) {
$output = __( 'Log file doesn\'t exists', $this->plugin_translate ); $output = __( 'Log file doesn\'t exists', $this->plugin_translate );
@ -650,10 +635,7 @@ class MainWP_Child_Back_WP_Up {
} }
} }
return array( return array( 'success' => 1, 'response' => $output );
'success' => 1,
'response' => $output,
);
} }
protected function tables() { protected function tables() {
@ -679,10 +661,7 @@ class MainWP_Child_Back_WP_Up {
$log_folder = untrailingslashit( $log_folder ); $log_folder = untrailingslashit( $log_folder );
if ( ! is_dir( $log_folder ) ) { if ( ! is_dir( $log_folder ) ) {
return array( return array( 'success' => 1, 'response' => $array );
'success' => 1,
'response' => $array,
);
} }
update_user_option( get_current_user_id(), 'backwpuplogs_per_page', 99999999 ); update_user_option( get_current_user_id(), 'backwpuplogs_per_page', 99999999 );
$output = new BackWPup_Page_Logs(); $output = new BackWPup_Page_Logs();
@ -708,13 +687,13 @@ class MainWP_Child_Back_WP_Up {
if ( is_null($dest_class) ) { if ( is_null($dest_class) ) {
continue; continue;
} }
$items = $dest_class->file_get_list( $jobid . '_' . $dest ); $items = $dest_class->file_get_list( $jobid . '_' . $dest );
if ( ! empty( $items ) ) { if ( ! empty( $items ) ) {
foreach ( $items as $item ) { foreach ( $items as $item ) {
$temp_single_item = $item; $temp_single_item = $item;
$temp_single_item['dest'] = $jobid . '_' . $dest; $temp_single_item['dest'] = $jobid . '_' . $dest;
$temp_single_item['timeloc'] = sprintf( __( '%1$s at %2$s', 'backwpup' ), date_i18n( get_option( 'date_format' ), $temp_single_item['time'], true ), date_i18n( get_option( 'time_format' ), $temp_single_item['time'], true ) ); $temp_single_item['timeloc'] = sprintf( __( '%1$s at %2$s', 'backwpup' ), date_i18n( get_option( 'date_format' ), $temp_single_item[ 'time' ], TRUE ), date_i18n( get_option( 'time_format' ), $temp_single_item[ 'time' ], TRUE ) );
$output->items[] = $temp_single_item; $output->items[] = $temp_single_item;
} }
} }
} }
@ -765,7 +744,7 @@ class MainWP_Child_Back_WP_Up {
$temp_array['website_id'] = $website_id; $temp_array['website_id'] = $website_id;
$array[] = $temp_array; $array[] = $temp_array;
} }
} elseif ( $type == 'backups' ) { } else if ( $type == 'backups' ) {
$without_dupes = array(); $without_dupes = array();
foreach ( $output->items as $key ) { foreach ( $output->items as $key ) {
$temp_array = $key; $temp_array = $key;
@ -778,8 +757,8 @@ class MainWP_Child_Back_WP_Up {
), $temp_array['downloadurl'] . '&_wpnonce=' . $this->create_nonce_without_session( 'mainwp_download_backup' ) ); ), $temp_array['downloadurl'] . '&_wpnonce=' . $this->create_nonce_without_session( 'mainwp_download_backup' ) );
$temp_array['downloadurl_id'] = '/wp-admin/admin.php?page=backwpupbackups'; $temp_array['downloadurl_id'] = '/wp-admin/admin.php?page=backwpupbackups';
if ( preg_match( '/.*&jobid=([^&]+)&.*/is', $temp_array['downloadurl'], $matches ) ) { if ( preg_match( '/.*&jobid=([^&]+)&.*/is', $temp_array['downloadurl'], $matches )) {
if ( ! empty( $matches[1] ) && is_numeric( $matches[1] ) ) { if ( !empty( $matches[1] ) && is_numeric( $matches[1] ) ) {
$temp_array['downloadurl_id'] .= '&download_click_id=' . $matches[1]; $temp_array['downloadurl_id'] .= '&download_click_id=' . $matches[1];
} }
error_log('did match' . print_r($matches, true)); error_log('did match' . print_r($matches, true));
@ -787,7 +766,7 @@ class MainWP_Child_Back_WP_Up {
error_log('not match'); error_log('not match');
} }
$temp_array['website_id'] = $website_id; $temp_array['website_id'] = $website_id;
if ( ! isset( $without_dupes[ $temp_array['file'] ] ) ) { if ( ! isset( $without_dupes[ $temp_array['file'] ] ) ) {
$array[] = $temp_array; $array[] = $temp_array;
@ -801,14 +780,11 @@ class MainWP_Child_Back_WP_Up {
} }
} }
return array( return array( 'success' => 1, 'response' => $array );
'success' => 1,
'response' => $array,
);
} }
public function init_download_backup() { public function init_download_backup() {
if ( ! isset( $_GET['page'] ) || $_GET['page'] !== 'backwpupbackups' || ! isset( $_GET['download_click_id'] ) || empty( $_GET['download_click_id'] ) ) { if ( ! isset( $_GET['page'] ) || $_GET['page'] !== 'backwpupbackups' || !isset( $_GET['download_click_id'] ) || empty( $_GET['download_click_id'] )) {
return; return;
} }
?> ?>
@ -846,10 +822,10 @@ class MainWP_Child_Back_WP_Up {
$dest_class->file_download( (int) $_GET['jobid'], $_GET['file'] ); $dest_class->file_download( (int) $_GET['jobid'], $_GET['file'] );
} else { } else {
die( '-5' ); die( '-5' );
} }
die(); die();
} }
protected function create_nonce_without_session( $action = - 1 ) { protected function create_nonce_without_session( $action = - 1 ) {
$user = wp_get_current_user(); $user = wp_get_current_user();
@ -921,10 +897,7 @@ class MainWP_Child_Back_WP_Up {
ob_end_clean(); ob_end_clean();
return array( return array( 'success' => 1, 'response' => $output );
'success' => 1,
'response' => $output,
);
} }
protected function backup_now() { protected function backup_now() {
@ -960,10 +933,7 @@ class MainWP_Child_Back_WP_Up {
'logfile' => basename( $job_object->logfile ), 'logfile' => basename( $job_object->logfile ),
); );
} else { } else {
return array( return array( 'success' => 1, 'response' => $output['message'] );
'success' => 1,
'response' => $output['message'],
);
} }
} }
} }
@ -985,10 +955,7 @@ class MainWP_Child_Back_WP_Up {
if ( isset( $output['error'] ) ) { if ( isset( $output['error'] ) ) {
return array( 'error' => 'Cannot abort: ' . $output['error'] ); return array( 'error' => 'Cannot abort: ' . $output['error'] );
} else { } else {
return array( return array( 'success' => 1, 'response' => $output['message'] );
'success' => 1,
'response' => $output['message'],
);
} }
} }
@ -1002,11 +969,12 @@ class MainWP_Child_Back_WP_Up {
if ( ! function_exists( 'add_screen_option' ) ) { if ( ! function_exists( 'add_screen_option' ) ) {
function add_screen_option( $option, $args = array() ) { function add_screen_option( $option, $args = array() ) {
} }
} }
if ( ! class_exists( 'WP_List_Table' ) ) { if ( ! class_exists( 'WP_List_Table' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
} }
} }
@ -1021,10 +989,7 @@ class MainWP_Child_Back_WP_Up {
ob_end_clean(); ob_end_clean();
return array( return array( 'success' => 1, 'response' => $output );
'success' => 1,
'response' => $output,
);
} else { } else {
return array( 'error' => 'Missing BackWPup_Pro_Wizard_SystemTest' ); return array( 'error' => 'Missing BackWPup_Pro_Wizard_SystemTest' );
} }
@ -1049,7 +1014,7 @@ class MainWP_Child_Back_WP_Up {
// From BackWPup_Destination_Email::edit_ajax // From BackWPup_Destination_Email::edit_ajax
if ( $emailmethod ) { if ( $emailmethod ) {
// do so if i'm the wp_mail to get the settings //do so if i'm the wp_mail to get the settings
global $phpmailer; global $phpmailer;
// (Re)create it, if it's gone missing // (Re)create it, if it's gone missing
if ( ! is_object( $phpmailer ) || ! $phpmailer instanceof PHPMailer ) { if ( ! is_object( $phpmailer ) || ! $phpmailer instanceof PHPMailer ) {
@ -1057,10 +1022,10 @@ class MainWP_Child_Back_WP_Up {
require_once ABSPATH . WPINC . '/class-smtp.php'; require_once ABSPATH . WPINC . '/class-smtp.php';
$phpmailer = new PHPMailer( true ); $phpmailer = new PHPMailer( true );
} }
// only if PHPMailer really used //only if PHPMailer really used
if ( is_object( $phpmailer ) ) { if ( is_object( $phpmailer ) ) {
do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) ); do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
// get settings from PHPMailer //get settings from PHPMailer
$emailmethod = $phpmailer->Mailer; $emailmethod = $phpmailer->Mailer;
$emailsendmail = $phpmailer->Sendmail; $emailsendmail = $phpmailer->Sendmail;
$emailhost = $phpmailer->Host; $emailhost = $phpmailer->Host;
@ -1071,7 +1036,7 @@ class MainWP_Child_Back_WP_Up {
} }
} }
// Generate mail with Swift Mailer //Generate mail with Swift Mailer
if ( ! class_exists( 'Swift', false ) ) { if ( ! class_exists( 'Swift', false ) ) {
require BackWPup::get_plugin_data( 'plugindir' ) . '/vendor/SwiftMailer/swift_required.php'; require BackWPup::get_plugin_data( 'plugindir' ) . '/vendor/SwiftMailer/swift_required.php';
} }
@ -1123,10 +1088,7 @@ class MainWP_Child_Back_WP_Up {
} }
} }
return array( return array( 'success' => 1, 'message' => $message );
'success' => 1,
'message' => $message,
);
} }
protected function get_job_files() { protected function get_job_files() {
@ -1175,9 +1137,9 @@ class MainWP_Child_Back_WP_Up {
if ( $dir = @opendir( $main_folder_name ) ) { if ( $dir = @opendir( $main_folder_name ) ) {
while ( ( $file = readdir( $dir ) ) !== false ) { while ( ( $file = readdir( $dir ) ) !== false ) {
if ( ! in_array( $file, array( if ( ! in_array( $file, array(
'.', '.',
'..', '..',
) ) && is_dir( $main_folder_name . '/' . $file ) && ! in_array( trailingslashit( $main_folder_name . '/' . $file ), mainwp_backwpup_get_exclude_dirs( $main_folder_name ) ) ) ) && is_dir( $main_folder_name . '/' . $file ) && ! in_array( trailingslashit( $main_folder_name . '/' . $file ), mainwp_backwpup_get_exclude_dirs( $main_folder_name ) )
) { ) {
$folder_size = ' (' . size_format( BackWPup_File::get_folder_size( $main_folder_name . '/' . $file ), 2 ) . ')'; $folder_size = ' (' . size_format( BackWPup_File::get_folder_size( $main_folder_name . '/' . $file ), 2 ) . ')';
@ -1192,18 +1154,11 @@ class MainWP_Child_Back_WP_Up {
@closedir( $dir ); @closedir( $dir );
} }
$return[ $key ] = array( $return[ $key ] = array( 'size' => $main_folder_size, 'name' => $folder, 'folders' => $return_temp );
'size' => $main_folder_size,
'name' => $folder,
'folders' => $return_temp,
);
} }
} }
return array( return array( 'success' => 1, 'folders' => $return );
'success' => 1,
'folders' => $return,
);
} }
protected function get_child_tables() { protected function get_child_tables() {
@ -1255,13 +1210,10 @@ class MainWP_Child_Back_WP_Up {
$return['tables'] = $tables_temp; $return['tables'] = $tables_temp;
} }
if ( isset($settings['job_id']) ) { if (isset($settings['job_id'])) {
$return['dbdumpexclude'] = BackWPup_Option::get( $settings['job_id'], 'dbdumpexclude' ); $return['dbdumpexclude'] = BackWPup_Option::get( $settings['job_id'], 'dbdumpexclude' );
} }
return array( return array( 'success' => 1, 'return' => $return );
'success' => 1,
'return' => $return,
);
} }
protected function insert_or_update_jobs_global() { protected function insert_or_update_jobs_global() {
@ -1335,29 +1287,29 @@ class MainWP_Child_Back_WP_Up {
// From BackWPup_JobType_File::edit_form_post_save with some tweaks // From BackWPup_JobType_File::edit_form_post_save with some tweaks
public function edit_form_post_save( $post_data, $id ) { public function edit_form_post_save( $post_data, $id ) {
// Parse and save files to exclude // Parse and save files to exclude
$exclude_input = $post_data['fileexclude']; $exclude_input = $post_data['fileexclude'];
$to_exclude_list = $exclude_input ? str_replace( array( "\r\n", "\r" ), ',', $exclude_input ) : array(); $to_exclude_list = $exclude_input ? str_replace( array( "\r\n", "\r" ), ',', $exclude_input ) : array();
$to_exclude_list and $to_exclude_list = sanitize_text_field( stripslashes( $to_exclude_list ) ); $to_exclude_list and $to_exclude_list = sanitize_text_field( stripslashes( $to_exclude_list ) );
$to_exclude = $to_exclude_list ? explode( ',', $to_exclude_list ) : array(); $to_exclude = $to_exclude_list ? explode( ',', $to_exclude_list ) : array();
$to_exclude_parsed = array(); $to_exclude_parsed = array();
foreach ( $to_exclude as $key => $value ) { foreach ( $to_exclude as $key => $value ) {
$normalized = wp_normalize_path( trim( $value ) ); $normalized = wp_normalize_path( trim( $value ) );
$normalized and $to_exclude_parsed[ $key ] = $normalized; $normalized and $to_exclude_parsed[$key] = $normalized;
} }
sort( $to_exclude_parsed ); sort( $to_exclude_parsed );
BackWPup_Option::update( $id, 'fileexclude', implode( ',', $to_exclude_parsed ) ); BackWPup_Option::update( $id, 'fileexclude', implode( ',', $to_exclude_parsed ) );
unset( $exclude_input, $to_exclude_list, $to_exclude, $to_exclude_parsed, $normalized ); unset( $exclude_input, $to_exclude_list, $to_exclude, $to_exclude_parsed, $normalized );
// Parse and save folders to include // Parse and save folders to include
$include_input = $post_data['dirinclude']; $include_input = $post_data['dirinclude'];
$include_list = $include_input ? str_replace( array( "\r\n", "\r" ), ',', $include_input ) : array(); $include_list = $include_input ? str_replace( array( "\r\n", "\r" ), ',', $include_input ) : array();
$to_include = $include_list ? explode( ',', $include_list ) : array(); $to_include = $include_list ? explode( ',', $include_list ) : array();
$to_include_parsed = array(); $to_include_parsed = array();
foreach ( $to_include as $key => $value ) { foreach ( $to_include as $key => $value ) {
$normalized = trailingslashit( wp_normalize_path( trim( $value ) ) ); $normalized = trailingslashit( wp_normalize_path( trim( $value ) ) );
$normalized and $normalized = filter_var( $normalized, FILTER_SANITIZE_URL ); $normalized and $normalized = filter_var( $normalized, FILTER_SANITIZE_URL );
$realpath = $normalized && $normalized !== '/' ? realpath( $normalized ) : false; $realpath = $normalized && $normalized !== '/' ? realpath( $normalized ) : false;
$realpath and $to_include_parsed[ $key ] = $realpath; $realpath and $to_include_parsed[$key] = $realpath;
} }
sort( $to_include_parsed ); sort( $to_include_parsed );
BackWPup_Option::update( $id, 'dirinclude', implode( ',', $to_include_parsed ) ); BackWPup_Option::update( $id, 'dirinclude', implode( ',', $to_include_parsed ) );
@ -1375,34 +1327,19 @@ class MainWP_Child_Back_WP_Up {
'backupuploads' => FILTER_VALIDATE_BOOLEAN, 'backupuploads' => FILTER_VALIDATE_BOOLEAN,
); );
foreach ( $boolean_fields_def as $key => $value ) { foreach( $boolean_fields_def as $key => $value ) {
BackWPup_Option::update( $id, $key, ! empty( $post_data[ $key ] ) ); BackWPup_Option::update( $id, $key, ! empty( $post_data[$key] ) );
} }
// Parse and save directories to exclude // Parse and save directories to exclude
$exclude_dirs_def = array( $exclude_dirs_def = array(
'backuprootexcludedirs' => array( 'backuprootexcludedirs' => array( 'filter' => FILTER_SANITIZE_URL, 'flags' => FILTER_FORCE_ARRAY ),
'filter' => FILTER_SANITIZE_URL, 'backuppluginsexcludedirs' => array( 'filter' => FILTER_SANITIZE_URL, 'flags' => FILTER_FORCE_ARRAY ),
'flags' => FILTER_FORCE_ARRAY, 'backupcontentexcludedirs' => array( 'filter' => FILTER_SANITIZE_URL, 'flags' => FILTER_FORCE_ARRAY ),
), 'backupthemesexcludedirs' => array( 'filter' => FILTER_SANITIZE_URL, 'flags' => FILTER_FORCE_ARRAY ),
'backuppluginsexcludedirs' => array( 'backupuploadsexcludedirs' => array( 'filter' => FILTER_SANITIZE_URL, 'flags' => FILTER_FORCE_ARRAY ),
'filter' => FILTER_SANITIZE_URL,
'flags' => FILTER_FORCE_ARRAY,
),
'backupcontentexcludedirs' => array(
'filter' => FILTER_SANITIZE_URL,
'flags' => FILTER_FORCE_ARRAY,
),
'backupthemesexcludedirs' => array(
'filter' => FILTER_SANITIZE_URL,
'flags' => FILTER_FORCE_ARRAY,
),
'backupuploadsexcludedirs' => array(
'filter' => FILTER_SANITIZE_URL,
'flags' => FILTER_FORCE_ARRAY,
),
); );
foreach ( $exclude_dirs_def as $key => $filter ) { foreach( $exclude_dirs_def as $key => $filter ) {
$value = ! empty( $post_data[ $key ] ) && is_array( $post_data[ $key ] ) ? $post_data[ $key ] : array(); $value = ! empty( $post_data[$key] ) && is_array( $post_data[$key] ) ? $post_data[$key] : array();
BackWPup_Option::update( $id, $key, $value ); BackWPup_Option::update( $id, $key, $value );
} }
} }
@ -1430,7 +1367,7 @@ class MainWP_Child_Back_WP_Up {
if ( $settings['job_id'] > 0 ) { if ( $settings['job_id'] > 0 ) {
$job_id = intval( $settings['job_id'] ); $job_id = intval( $settings['job_id'] );
} else { } else {
// generate jobid if not exists //generate jobid if not exists
$newjobid = BackWPup_Option::get_job_ids(); $newjobid = BackWPup_Option::get_job_ids();
sort( $newjobid ); sort( $newjobid );
$job_id = end( $newjobid ) + 1; $job_id = end( $newjobid ) + 1;
@ -1438,9 +1375,9 @@ class MainWP_Child_Back_WP_Up {
update_site_option( 'backwpup_messages', array() ); update_site_option( 'backwpup_messages', array() );
if ( isset($settings['value']['backupdir']) && empty($settings['value']['backupdir']) ) { if (isset($settings['value']['backupdir']) && empty($settings['value']['backupdir'])) {
$backupdir = BackWPup_Option::get( (int) $job_id, 'backupdir' ); $backupdir = BackWPup_Option::get( (int)$job_id, 'backupdir' );
if ( ! empty($backupdir) ) { if (!empty($backupdir)) {
$settings['value']['backupdir'] = $backupdir; $settings['value']['backupdir'] = $backupdir;
} }
} }
@ -1449,16 +1386,16 @@ class MainWP_Child_Back_WP_Up {
$_POST[ $key ] = $val; $_POST[ $key ] = $val;
} }
if ( $settings['tab'] == 'jobtype-FILE' ) { if ($settings['tab'] == 'jobtype-FILE') {
// to fix // to fix
$this->edit_form_post_save($settings['value'], $job_id); $this->edit_form_post_save($settings['value'], $job_id);
// saved message //saved message
$messages = BackWPup_Admin::get_messages(); $messages = BackWPup_Admin::get_messages();
if ( empty( $messages['error'] ) ) { if ( empty( $messages['error'] ) ) {
$url = BackWPup_Job::get_jobrun_url( 'runnowlink', $job_id ); $url = BackWPup_Job::get_jobrun_url( 'runnowlink', $job_id );
BackWPup_Admin::message( sprintf( __( 'Changes for job <i>%s</i> saved.', 'backwpup' ), BackWPup_Option::get( $job_id, 'name' ) ) . ' <a href="' . network_admin_url( 'admin.php' ) . '?page=backwpupjobs">' . __( 'Jobs overview', 'backwpup' ) . '</a> | <a href="' . $url['url'] . '">' . __( 'Run now', 'backwpup' ) . '</a>' ); BackWPup_Admin::message( sprintf( __( 'Changes for job <i>%s</i> saved.', 'backwpup' ), BackWPup_Option::get( $job_id, 'name' ) ) . ' <a href="' . network_admin_url( 'admin.php' ) . '?page=backwpupjobs">' . __( 'Jobs overview', 'backwpup' ) . '</a> | <a href="' . $url['url'] . '">' . __( 'Run now', 'backwpup' ) . '</a>' );
} }
} elseif ( $settings['tab'] == 'dest-DROPBOX' ) { } else if ($settings['tab'] == 'dest-DROPBOX') {
unset($settings['value']); // do not save dropbox settings unset($settings['value']); // do not save dropbox settings
BackWPup_Page_Editjob::save_post_form( $settings['tab'], $job_id ); BackWPup_Page_Editjob::save_post_form( $settings['tab'], $job_id );
} else { } else {
@ -1500,7 +1437,7 @@ class MainWP_Child_Back_WP_Up {
if ( ! in_array( $key, $this->exclusions[ $settings['tab'] ] ) && strcmp( $temp_value, $val ) != 0 ) { if ( ! in_array( $key, $this->exclusions[ $settings['tab'] ] ) && strcmp( $temp_value, $val ) != 0 ) {
$changes_array[ $key ] = $temp_value; $changes_array[ $key ] = $temp_value;
} }
} elseif ( strcmp( $temp_value, $val ) != 0 ) { } else if ( strcmp( $temp_value, $val ) != 0 ) {
$changes_array[ $key ] = $temp_value; $changes_array[ $key ] = $temp_value;
} }
} }
@ -1536,7 +1473,7 @@ class MainWP_Child_Back_WP_Up {
update_site_option( 'backwpup_messages', array() ); update_site_option( 'backwpup_messages', array() );
$settings_views = array(); $settings_views = array();
$settings_updaters = array(); $settings_updaters = array();
$backwpup = new BackWPup_Page_Settings($settings_views, $settings_updaters); $backwpup = new BackWPup_Page_Settings($settings_views, $settings_updaters);
@ -1573,11 +1510,7 @@ class MainWP_Child_Back_WP_Up {
} }
} }
return array( return array( 'success' => 1, 'changes' => $changes_array, 'message' => $return['message'] );
'success' => 1,
'changes' => $changes_array,
'message' => $return['message'],
);
} }
protected function check_backwpup_messages() { protected function check_backwpup_messages() {
@ -1586,11 +1519,12 @@ class MainWP_Child_Back_WP_Up {
if ( isset( $message['error'] ) ) { if ( isset( $message['error'] ) ) {
return array( 'error' => implode( ', ', $message['error'] ) ); return array( 'error' => implode( ', ', $message['error'] ) );
} elseif ( isset( $message['updated'] ) ) { } else if ( isset( $message['updated'] ) ) {
return array( 'message' => $message['updated'] ); return array( 'message' => $message['updated'] );
} else { } else {
return array( 'error' => 'Generic error' ); return array( 'error' => 'Generic error' );
} }
} }
} }

View file

@ -7,10 +7,10 @@ class MainWP_Child_Branding {
public $child_branding_options = null; public $child_branding_options = null;
static function Instance() { static function Instance() {
if ( null === self::$instance ) { if ( null === MainWP_Child_Branding::$instance ) {
self::$instance = new MainWP_Child_Branding(); MainWP_Child_Branding::$instance = new MainWP_Child_Branding();
} }
return self::$instance; return MainWP_Child_Branding::$instance;
} }
public function __construct() { public function __construct() {
@ -20,11 +20,11 @@ class MainWP_Child_Branding {
$this->child_branding_options = $this->init_options(); $this->child_branding_options = $this->init_options();
} }
function init_options() { function init_options(){
$opts = get_option( 'mainwp_child_branding_settings' ); $opts = get_option( 'mainwp_child_branding_settings' );
if ( ! is_array( $opts ) ) { if ( !is_array( $opts ) ) {
// compatible with old code // compatible with old code
$opts = array(); $opts = array();
@ -33,24 +33,24 @@ class MainWP_Child_Branding {
$label = stripslashes( $label ); $label = stripslashes( $label );
} }
$opts['contact_label'] = $label; $opts['contact_label'] = $label;
$opts['extra_settings'] = get_option( 'mainwp_branding_extra_settings' ); $opts['extra_settings'] = get_option( 'mainwp_branding_extra_settings' );
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $opts ); MainWP_Helper::update_option( 'mainwp_child_branding_settings', $opts );
} }
if ( ! isset($opts['contact_label']) || empty($opts['contact_label']) ) { if ( !isset($opts['contact_label']) || empty($opts['contact_label']) ) {
$opts['contact_label'] = 'Contact Support'; $opts['contact_label'] = 'Contact Support';
} }
$disconnected = isset( $opts['branding_disconnected'] ) ? $opts['branding_disconnected'] : ''; $disconnected = isset( $opts['branding_disconnected'] ) ? $opts['branding_disconnected'] : '';
$preserve_branding = isset( $opts['preserve_branding'] ) ? $opts['preserve_branding'] : ''; $preserve_branding = isset( $opts['preserve_branding'] ) ? $opts['preserve_branding'] : '';
$cancelled_branding = ( $disconnected === 'yes' ) && ! $preserve_branding; $cancelled_branding = ( $disconnected === 'yes' ) && ! $preserve_branding;
$opts['cancelled_branding'] = $cancelled_branding; $opts['cancelled_branding'] = $cancelled_branding;
$opts['branding_preserve_title'] = ''; $opts['branding_preserve_title'] = '';
if ( ! $cancelled_branding ) { if ( ! $cancelled_branding ) {
if ( isset($opts['branding_header']) ) { if (isset($opts['branding_header'])) {
$branding_header = $opts['branding_header']; $branding_header = $opts['branding_header'];
if ( is_array( $branding_header ) && isset( $branding_header['name'] ) && ! empty( $branding_header['name'] ) ) { if ( is_array( $branding_header ) && isset( $branding_header['name'] ) && ! empty( $branding_header['name'] ) ) {
$opts['branding_preserve_title'] = stripslashes( $branding_header['name'] ); $opts['branding_preserve_title'] = stripslashes( $branding_header['name'] );
@ -64,11 +64,10 @@ class MainWP_Child_Branding {
function get_extra_options() { function get_extra_options() {
$extra = array(); $extra = array();
if ( is_array($this->child_branding_options) && isset($this->child_branding_options['extra_settings']) ) { if (is_array($this->child_branding_options) && isset($this->child_branding_options['extra_settings'])) {
$extra = $this->child_branding_options['extra_settings']; $extra = $this->child_branding_options['extra_settings'];
if ( ! is_array($extra) ) { if (!is_array($extra))
$extra = array(); $extra = array();
}
} }
return $extra; return $extra;
@ -110,7 +109,7 @@ class MainWP_Child_Branding {
'mainwp_branding_remove_wp_tools', 'mainwp_branding_remove_wp_tools',
'mainwp_branding_remove_wp_setting', 'mainwp_branding_remove_wp_setting',
'mainwp_branding_remove_permalink', 'mainwp_branding_remove_permalink',
// 'mainwp_branding_plugin_header', // don't remove header //'mainwp_branding_plugin_header', // don't remove header
'mainwp_branding_button_contact_label', 'mainwp_branding_button_contact_label',
'mainwp_branding_send_email_message', 'mainwp_branding_send_email_message',
'mainwp_branding_message_return_sender', 'mainwp_branding_message_return_sender',
@ -136,7 +135,7 @@ class MainWP_Child_Branding {
'remove_wp_tools', 'remove_wp_tools',
'remove_wp_setting', 'remove_wp_setting',
'remove_permalink', 'remove_permalink',
// 'branding_header', // don't remove header //'branding_header', // don't remove header
'contact_label', 'contact_label',
'email_message', 'email_message',
'message_return_sender', 'message_return_sender',
@ -145,12 +144,13 @@ class MainWP_Child_Branding {
'branding_ext_enabled', 'branding_ext_enabled',
); );
foreach ( $brandingOptions_empty as $opt ) { foreach($brandingOptions_empty as $opt) {
if ( isset($this->child_branding_options[ $opt ]) ) { if (isset($this->child_branding_options[$opt])) {
$this->child_branding_options[ $opt ] = ''; $this->child_branding_options[$opt] = '';
} }
} }
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $this->child_branding_options ); MainWP_Helper::update_option( 'mainwp_child_branding_settings', $this->child_branding_options );
} }
@ -171,10 +171,10 @@ class MainWP_Child_Branding {
return $information; return $information;
} }
$current_settings = $this->child_branding_options; $current_settings = $this->child_branding_options;
$current_extra_setting = $this->child_branding_options['extra_settings']; $current_extra_setting = $this->child_branding_options['extra_settings'];
// MainWP_Helper::update_option( 'mainwp_branding_ext_enabled', 'Y' ); //MainWP_Helper::update_option( 'mainwp_branding_ext_enabled', 'Y' );
$current_settings['branding_ext_enabled'] = 'Y'; $current_settings['branding_ext_enabled'] = 'Y';
$header = array( $header = array(
@ -187,41 +187,41 @@ class MainWP_Child_Branding {
MainWP_Helper::update_option( 'mainwp_branding_preserve_branding', $settings['child_preserve_branding'], 'yes' ); // to compatible with old version of child report plugin MainWP_Helper::update_option( 'mainwp_branding_preserve_branding', $settings['child_preserve_branding'], 'yes' ); // to compatible with old version of child report plugin
MainWP_Helper::update_option( 'mainwp_branding_plugin_header', $header, 'yes' ); // to compatible MainWP_Helper::update_option( 'mainwp_branding_plugin_header', $header, 'yes' ); // to compatible
// MainWP_Helper::update_option( 'mainwp_branding_support_email', $settings['child_support_email'] ); // MainWP_Helper::update_option( 'mainwp_branding_support_email', $settings['child_support_email'] );
// MainWP_Helper::update_option( 'mainwp_branding_support_message', $settings['child_support_message'] ); // MainWP_Helper::update_option( 'mainwp_branding_support_message', $settings['child_support_message'] );
// MainWP_Helper::update_option( 'mainwp_branding_remove_restore', $settings['child_remove_restore'] ); // MainWP_Helper::update_option( 'mainwp_branding_remove_restore', $settings['child_remove_restore'] );
// MainWP_Helper::update_option( 'mainwp_branding_remove_setting', $settings['child_remove_setting'], 'yes' ); // MainWP_Helper::update_option( 'mainwp_branding_remove_setting', $settings['child_remove_setting'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_remove_server_info', $settings['child_remove_server_info'] ); // MainWP_Helper::update_option( 'mainwp_branding_remove_server_info', $settings['child_remove_server_info'] );
// MainWP_Helper::update_option( 'mainwp_branding_remove_connection_detail', (isset($settings['child_remove_connection_detail']) ? $settings['child_remove_connection_detail'] : 0) ); // MainWP_Helper::update_option( 'mainwp_branding_remove_connection_detail', (isset($settings['child_remove_connection_detail']) ? $settings['child_remove_connection_detail'] : 0) );
// MainWP_Helper::update_option( 'mainwp_branding_remove_wp_tools', $settings['child_remove_wp_tools'], 'yes' ); // MainWP_Helper::update_option( 'mainwp_branding_remove_wp_tools', $settings['child_remove_wp_tools'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_remove_wp_setting', $settings['child_remove_wp_setting'], 'yes' ); // MainWP_Helper::update_option( 'mainwp_branding_remove_wp_setting', $settings['child_remove_wp_setting'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_remove_permalink', $settings['child_remove_permalink'], 'yes' ); // MainWP_Helper::update_option( 'mainwp_branding_remove_permalink', $settings['child_remove_permalink'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_button_contact_label', $settings['child_button_contact_label'], 'yes' ); // MainWP_Helper::update_option( 'mainwp_branding_button_contact_label', $settings['child_button_contact_label'], 'yes' );
// MainWP_Helper::update_option( 'mainwp_branding_send_email_message', $settings['child_send_email_message'] ); // MainWP_Helper::update_option( 'mainwp_branding_send_email_message', $settings['child_send_email_message'] );
// MainWP_Helper::update_option( 'mainwp_branding_message_return_sender', $settings['child_message_return_sender'] ); // MainWP_Helper::update_option( 'mainwp_branding_message_return_sender', $settings['child_message_return_sender'] );
// MainWP_Helper::update_option( 'mainwp_branding_submit_button_title', $settings['child_submit_button_title'] ); // MainWP_Helper::update_option( 'mainwp_branding_submit_button_title', $settings['child_submit_button_title'] );
// if ( isset( $settings['child_disable_wp_branding'] ) && ( 'Y' === $settings['child_disable_wp_branding'] || 'N' === $settings['child_disable_wp_branding'] ) ) { // if ( isset( $settings['child_disable_wp_branding'] ) && ( 'Y' === $settings['child_disable_wp_branding'] || 'N' === $settings['child_disable_wp_branding'] ) ) {
// MainWP_Helper::update_option( 'mainwp_branding_disable_wp_branding', $settings['child_disable_wp_branding'] ); // MainWP_Helper::update_option( 'mainwp_branding_disable_wp_branding', $settings['child_disable_wp_branding'] );
// } // }
$current_settings['preserve_branding'] = $settings['child_preserve_branding']; $current_settings['preserve_branding'] = $settings['child_preserve_branding'];
$current_settings['branding_header'] = $header; $current_settings['branding_header'] = $header;
$current_settings['support_email'] = $settings['child_support_email']; $current_settings['support_email'] = $settings['child_support_email'];
$current_settings['support_message'] = $settings['child_support_message']; $current_settings['support_message'] = $settings['child_support_message'];
$current_settings['remove_restore'] = $settings['child_remove_restore']; $current_settings['remove_restore'] = $settings['child_remove_restore'];
$current_settings['remove_setting'] = $settings['child_remove_setting']; $current_settings['remove_setting'] = $settings['child_remove_setting'];
$current_settings['remove_server_info'] = $settings['child_remove_server_info']; $current_settings['remove_server_info'] = $settings['child_remove_server_info'];
$current_settings['remove_connection_detail'] = isset($settings['child_remove_connection_detail']) ? $settings['child_remove_connection_detail'] : 0; $current_settings['remove_connection_detail'] = isset($settings['child_remove_connection_detail']) ? $settings['child_remove_connection_detail'] : 0 ;
$current_settings['remove_wp_tools'] = $settings['child_remove_wp_tools']; $current_settings['remove_wp_tools'] = $settings['child_remove_wp_tools'];
$current_settings['remove_wp_setting'] = $settings['child_remove_wp_setting']; $current_settings['remove_wp_setting'] = $settings['child_remove_wp_setting'];
$current_settings['remove_permalink'] = $settings['child_remove_permalink']; $current_settings['remove_permalink'] = $settings['child_remove_permalink'];
$current_settings['contact_label'] = $settings['child_button_contact_label']; $current_settings['contact_label'] = $settings['child_button_contact_label'];
$current_settings['email_message'] = $settings['child_send_email_message']; $current_settings['email_message'] = $settings['child_send_email_message'];
$current_settings['return_sender'] = $settings['child_message_return_sender']; $current_settings['return_sender'] = $settings['child_message_return_sender'];
$current_settings['submit_button_title'] = $settings['child_submit_button_title']; $current_settings['submit_button_title'] = $settings['child_submit_button_title'];
if ( isset( $settings['child_disable_wp_branding'] ) && ( 'Y' === $settings['child_disable_wp_branding'] || 'N' === $settings['child_disable_wp_branding'] ) ) { if ( isset( $settings['child_disable_wp_branding'] ) && ( 'Y' === $settings['child_disable_wp_branding'] || 'N' === $settings['child_disable_wp_branding'] ) ) {
$current_settings['disable_wp_branding'] = $settings['child_disable_wp_branding']; $current_settings['disable_wp_branding'] = $settings['child_disable_wp_branding'];
} }
$extra_setting = array( $extra_setting = array(
@ -233,8 +233,8 @@ class MainWP_Child_Branding {
'remove_widget_activity' => $settings['child_remove_widget_activity'], 'remove_widget_activity' => $settings['child_remove_widget_activity'],
'remove_widget_quick' => $settings['child_remove_widget_quick'], 'remove_widget_quick' => $settings['child_remove_widget_quick'],
'remove_widget_news' => $settings['child_remove_widget_news'], 'remove_widget_news' => $settings['child_remove_widget_news'],
'login_image_link' => $settings['child_login_image_link'], 'login_image_link' => $settings['child_login_image_link'],
'login_image_title' => $settings['child_login_image_title'], 'login_image_title' => $settings['child_login_image_title'],
'site_generator' => $settings['child_site_generator'], 'site_generator' => $settings['child_site_generator'],
'generator_link' => $settings['child_generator_link'], 'generator_link' => $settings['child_generator_link'],
'admin_css' => $settings['child_admin_css'], 'admin_css' => $settings['child_admin_css'],
@ -266,12 +266,9 @@ class MainWP_Child_Branding {
$extra_setting['login_image'] = array(); $extra_setting['login_image'] = array();
} else { } else {
try { try {
$upload = $this->uploadImage( $settings['child_login_image_url'] ); // Upload image to WP $upload = $this->uploadImage( $settings['child_login_image_url'] ); //Upload image to WP
if ( null !== $upload ) { if ( null !== $upload ) {
$extra_setting['login_image'] = array( $extra_setting['login_image'] = array( 'path' => $upload['path'], 'url' => $upload['url'] );
'path' => $upload['path'],
'url' => $upload['url'],
);
if ( isset( $current_extra_setting['login_image']['path'] ) ) { if ( isset( $current_extra_setting['login_image']['path'] ) ) {
$old_file = $current_extra_setting['login_image']['path']; $old_file = $current_extra_setting['login_image']['path'];
if ( ! empty( $old_file ) && file_exists( $old_file ) ) { if ( ! empty( $old_file ) && file_exists( $old_file ) ) {
@ -283,7 +280,7 @@ class MainWP_Child_Branding {
$information['error']['login_image'] = $e->getMessage(); $information['error']['login_image'] = $e->getMessage();
} }
} }
} elseif ( isset( $current_extra_setting['login_image'] ) ) { } else if ( isset( $current_extra_setting['login_image'] ) ) {
$extra_setting['login_image'] = $current_extra_setting['login_image']; $extra_setting['login_image'] = $current_extra_setting['login_image'];
} }
@ -292,12 +289,9 @@ class MainWP_Child_Branding {
$extra_setting['favico_image'] = array(); $extra_setting['favico_image'] = array();
} else { } else {
try { try {
$upload = $this->uploadImage( $settings['child_favico_image_url'] ); // Upload image to WP $upload = $this->uploadImage( $settings['child_favico_image_url'] ); //Upload image to WP
if ( null !== $upload ) { if ( null !== $upload ) {
$extra_setting['favico_image'] = array( $extra_setting['favico_image'] = array( 'path' => $upload['path'], 'url' => $upload['url'] );
'path' => $upload['path'],
'url' => $upload['url'],
);
if ( isset( $current_extra_setting['favico_image']['path'] ) ) { if ( isset( $current_extra_setting['favico_image']['path'] ) ) {
$old_file = $current_extra_setting['favico_image']['path']; $old_file = $current_extra_setting['favico_image']['path'];
if ( ! empty( $old_file ) && file_exists( $old_file ) ) { if ( ! empty( $old_file ) && file_exists( $old_file ) ) {
@ -309,11 +303,11 @@ class MainWP_Child_Branding {
$information['error']['favico_image'] = $e->getMessage(); $information['error']['favico_image'] = $e->getMessage();
} }
} }
} elseif ( isset( $current_extra_setting['favico_image'] ) ) { } else if ( isset( $current_extra_setting['favico_image'] ) ) {
$extra_setting['favico_image'] = $current_extra_setting['favico_image']; $extra_setting['favico_image'] = $current_extra_setting['favico_image'];
} }
// MainWP_Helper::update_option( 'mainwp_branding_extra_settings', $extra_setting, 'yes' ); //MainWP_Helper::update_option( 'mainwp_branding_extra_settings', $extra_setting, 'yes' );
$current_settings['extra_settings'] = $extra_setting; $current_settings['extra_settings'] = $extra_setting;
// keep it to compatible with old version of child reports plugin // keep it to compatible with old version of child reports plugin
@ -322,28 +316,28 @@ class MainWP_Child_Branding {
} else { } else {
MainWP_Helper::update_option( 'mainwp_branding_child_hide', '' ); MainWP_Helper::update_option( 'mainwp_branding_child_hide', '' );
} }
// //
// if ( $settings['child_show_support_button'] && ! empty( $settings['child_support_email'] ) ) { // if ( $settings['child_show_support_button'] && ! empty( $settings['child_support_email'] ) ) {
// MainWP_Helper::update_option( 'mainwp_branding_show_support', 'T' ); // MainWP_Helper::update_option( 'mainwp_branding_show_support', 'T' );
// } else { // } else {
// MainWP_Helper::update_option( 'mainwp_branding_show_support', '' ); // MainWP_Helper::update_option( 'mainwp_branding_show_support', '' );
// } // }
// if ( $settings['child_disable_change'] ) { // if ( $settings['child_disable_change'] ) {
// MainWP_Helper::update_option( 'mainwp_branding_disable_change', 'T' ); // MainWP_Helper::update_option( 'mainwp_branding_disable_change', 'T' );
// } else { // } else {
// MainWP_Helper::update_option( 'mainwp_branding_disable_change', '' ); // MainWP_Helper::update_option( 'mainwp_branding_disable_change', '' );
// } // }
// if ( $settings['child_disable_switching_theme'] ) { // if ( $settings['child_disable_switching_theme'] ) {
// MainWP_Helper::update_option( 'mainwp_branding_disable_switching_theme', 'T' ); // MainWP_Helper::update_option( 'mainwp_branding_disable_switching_theme', 'T' );
// } else { // } else {
// MainWP_Helper::update_option( 'mainwp_branding_disable_switching_theme', '' ); // MainWP_Helper::update_option( 'mainwp_branding_disable_switching_theme', '' );
// } // }
$current_settings['hide'] = $settings['child_plugin_hide'] ? 'T' : ''; $current_settings['hide'] = $settings['child_plugin_hide'] ? 'T' : '';
$current_settings['show_support'] = ( $settings['child_show_support_button'] && ! empty($settings['child_support_email']) ) ? 'T' : ''; $current_settings['show_support'] = ( $settings['child_show_support_button'] && !empty($settings['child_support_email']) ) ? 'T' : '';
$current_settings['disable_change'] = $settings['child_disable_change'] ? 'T' : ''; $current_settings['disable_change'] = $settings['child_disable_change'] ? 'T' : '';
$current_settings['disable_switching_theme'] = $settings['child_disable_switching_theme'] ? 'T' : ''; $current_settings['disable_switching_theme'] = $settings['child_disable_switching_theme'] ? 'T' : '';
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $current_settings ); MainWP_Helper::update_option( 'mainwp_child_branding_settings', $current_settings );
@ -354,10 +348,10 @@ class MainWP_Child_Branding {
} }
static function uploadImage( $img_url ) { static function uploadImage( $img_url ) {
include_once ABSPATH . 'wp-admin/includes/file.php'; // Contains download_url include_once( ABSPATH . 'wp-admin/includes/file.php' ); //Contains download_url
global $mainWPChild; global $mainWPChild;
add_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 ); add_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 );
// Download $img_url //Download $img_url
$temporary_file = download_url( $img_url ); $temporary_file = download_url( $img_url );
remove_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 ); remove_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 );
@ -365,15 +359,12 @@ class MainWP_Child_Branding {
throw new Exception( 'Error: ' . $temporary_file->get_error_message() ); throw new Exception( 'Error: ' . $temporary_file->get_error_message() );
} else { } else {
$upload_dir = wp_upload_dir(); $upload_dir = wp_upload_dir();
$local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . basename( $img_url ); // Local name $local_img_path = $upload_dir['path'] . DIRECTORY_SEPARATOR . basename( $img_url ); //Local name
$local_img_path = dirname( $local_img_path ) . '/' . wp_unique_filename( dirname( $local_img_path ), basename( $local_img_path ) ); $local_img_path = dirname( $local_img_path ) . '/' . wp_unique_filename( dirname( $local_img_path ), basename( $local_img_path ) );
$local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path ); $local_img_url = $upload_dir['url'] . '/' . basename( $local_img_path );
$moved = @rename( $temporary_file, $local_img_path ); $moved = @rename( $temporary_file, $local_img_path );
if ( $moved ) { if ( $moved ) {
return array( return array( 'path' => $local_img_path, 'url' => $local_img_url );
'path' => $local_img_path,
'url' => $local_img_url,
);
} }
} }
if ( file_exists( $temporary_file ) ) { if ( file_exists( $temporary_file ) ) {
@ -389,10 +380,10 @@ class MainWP_Child_Branding {
$extra_setting = $this->get_extra_options(); $extra_setting = $this->get_extra_options();
// to hide updates notice // to hide updates notice
if ( is_admin() ) { if (is_admin()) {
// back end // back end
add_action( 'in_admin_footer', array( $this, 'in_admin_footer' ) ); add_action( 'in_admin_footer', array( $this, 'in_admin_footer' ) );
} elseif ( is_user_logged_in() ) { } else if (is_user_logged_in()) {
// front end // front end
add_action( 'wp_after_admin_bar_render', array( $this, 'after_admin_bar_render' )); add_action( 'wp_after_admin_bar_render', array( $this, 'after_admin_bar_render' ));
} }
@ -411,40 +402,37 @@ class MainWP_Child_Branding {
add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) ); add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) );
} }
if ( ! isset($opts['branding_ext_enabled']) || $opts['branding_ext_enabled'] !== 'Y' ) { if ( !isset($opts['branding_ext_enabled']) || $opts['branding_ext_enabled'] !== 'Y' ) {
return; return;
} }
add_filter( 'map_meta_cap', array( $this, 'branding_map_meta_cap' ), 10, 5 ); add_filter( 'map_meta_cap', array( $this, 'branding_map_meta_cap' ), 10, 5 );
if ( 'T' === $opts['disable_change'] ) { if ( 'T' === $opts['disable_change']) {
// Disable the WordPress plugin update notifications // Disable the wordpress plugin update notifications
remove_action('load-update-core.php', 'wp_update_plugins'); remove_action('load-update-core.php', 'wp_update_plugins');
add_filter('pre_site_transient_update_plugins', '__return_null'); add_filter('pre_site_transient_update_plugins', '__return_null');
// Disable the WordPress theme update notifications // Disable the wordpress theme update notifications
remove_action('load-update-core.php', 'wp_update_themes'); remove_action('load-update-core.php', 'wp_update_themes');
add_filter('pre_site_transient_update_themes', ( $func = function( $a ) { add_filter('pre_site_transient_update_themes', ( $func = function($a){ return null;} ));
return null;
} ));
// Disable the WordPress core update notifications // Disable the wordpress core update notifications
add_action('after_setup_theme', 'remove_core_updates'); add_action('after_setup_theme', 'remove_core_updates');
function remove_core_updates() { function remove_core_updates() {
add_action('init', ( $func = function( $a ) { add_action('init', ( $func = function($a){ remove_action( 'wp_version_check', 'wp_version_check' );} ), 2);
remove_action( 'wp_version_check', 'wp_version_check' );
} ), 2);
add_filter('pre_option_update_core', '__return_null'); add_filter('pre_option_update_core', '__return_null');
add_filter('pre_site_transient_update_core', '__return_null'); add_filter('pre_site_transient_update_core', '__return_null');
} }
add_action( 'admin_head', array( &$this, 'admin_head_hide_elements' ), 15 ); add_action( 'admin_head', array( &$this, 'admin_head_hide_elements' ), 15 );
add_action( 'admin_menu', array( $this, 'branding_redirect' ), 9); add_action( 'admin_menu', array($this, 'branding_redirect' ), 9);
} }
// to fix // to fix
add_action( 'admin_menu', array( &$this, 'admin_menu' ) ); if ( ! isset($opts['disable_wp_branding']) || $opts['disable_wp_branding'] !== 'Y' ) { add_action( 'admin_menu', array( &$this, 'admin_menu' ) );//
if ( !isset($opts['disable_wp_branding']) || $opts['disable_wp_branding'] !== 'Y' ) {
add_filter( 'wp_footer', array( &$this, 'branding_global_footer' ), 15 ); add_filter( 'wp_footer', array( &$this, 'branding_global_footer' ), 15 );
add_action( 'wp_dashboard_setup', array( &$this, 'custom_dashboard_widgets' ), 999 ); add_action( 'wp_dashboard_setup', array( &$this, 'custom_dashboard_widgets' ), 999 );
// branding site generator // branding site generator
@ -460,13 +448,13 @@ class MainWP_Child_Branding {
add_filter( 'login_headertext', array( &$this, 'custom_login_headertitle' ) ); add_filter( 'login_headertext', array( &$this, 'custom_login_headertitle' ) );
add_action( 'wp_head', array( &$this, 'custom_favicon_frontend' ) ); add_action( 'wp_head', array( &$this, 'custom_favicon_frontend' ) );
if ( isset( $extra_setting['dashboard_footer'] ) && ! empty( $extra_setting['dashboard_footer'] ) ) { if ( isset( $extra_setting['dashboard_footer'] ) && ! empty( $extra_setting['dashboard_footer'] ) ) {
// remove_filter( 'update_footer', 'core_update_footer' ); //remove_filter( 'update_footer', 'core_update_footer' );
add_filter( 'update_footer', array( &$this, 'core_update_footer' ), 14 ); add_filter( 'update_footer', array( &$this, 'core_update_footer' ), 14 );
add_filter( 'admin_footer_text', array( &$this, 'admin_footer_text' ), 14 ); add_filter( 'admin_footer_text', array( &$this, 'admin_footer_text' ), 14 );
} }
if ( isset( $extra_setting['hide_nag'] ) && ! empty( $extra_setting['hide_nag'] ) ) { if ( isset( $extra_setting['hide_nag'] ) && ! empty( $extra_setting['hide_nag'] ) ) {
add_action( 'admin_init', array( $this, 'admin_init' )); add_action( 'admin_init', array($this, 'admin_init'));
} }
add_action( 'admin_menu', array( &$this, 'remove_default_post_metaboxes' ) ); add_action( 'admin_menu', array( &$this, 'remove_default_post_metaboxes' ) );
@ -482,8 +470,9 @@ class MainWP_Child_Branding {
// to fix conflict with other plugin // to fix conflict with other plugin
function admin_menu() { function admin_menu() {
$allow_contact = apply_filters('mainwp_branding_role_cap_enable_contact_form', false); $allow_contact = apply_filters('mainwp_branding_role_cap_enable_contact_form', false);
if ( $allow_contact ) {; // ok if ( $allow_contact ) {
} elseif ( ! current_user_can( 'administrator' ) ) { ; // ok
} else if ( !current_user_can( 'administrator' ) ) {
return false; return false;
} }
@ -511,6 +500,7 @@ class MainWP_Child_Branding {
add_action( 'admin_bar_menu', array( $this, 'add_support_button_in_top_admin_bar' ), 100 ); add_action( 'admin_bar_menu', array( $this, 'add_support_button_in_top_admin_bar' ), 100 );
} }
} }
} }
function remove_default_post_metaboxes() { function remove_default_post_metaboxes() {
@ -640,8 +630,7 @@ class MainWP_Child_Branding {
el.parentElement.innerHTML = ''; el.parentElement.innerHTML = '';
} }
}); });
</script> </script><?php
<?php
} }
function core_update_footer() { function core_update_footer() {
@ -806,24 +795,24 @@ class MainWP_Child_Branding {
public function send_support_mail() { public function send_support_mail() {
$email = $this->child_branding_options['support_email']; $email = $this->child_branding_options['support_email'];
$sub = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_subject'] ) ) ); $sub = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_subject'] ) ) );
$from = trim($_POST['mainwp_branding_contact_send_from']); $from = trim($_POST['mainwp_branding_contact_send_from']);
$subject = ! empty( $sub ) ? $sub : 'MainWP - Support Contact'; $subject = !empty( $sub ) ? $sub : "MainWP - Support Contact";
$content = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_content'] ) ) ); $content = wp_kses_post( nl2br( stripslashes( $_POST['mainwp_branding_contact_message_content'] ) ) );
$mail = $headers = ''; $mail = $headers = '';
if ( ! empty( $_POST['mainwp_branding_contact_message_content'] ) && ! empty( $email ) ) { if ( ! empty( $_POST['mainwp_branding_contact_message_content'] ) && ! empty( $email ) ) {
global $current_user; global $current_user;
$headers .= "Content-Type: text/html;charset=utf-8\r\n"; $headers .= "Content-Type: text/html;charset=utf-8\r\n";
if ( ! empty($from) ) { if (!empty($from))
$headers .= 'From: "' . $from . '" <' . $from . ">\r\n"; $headers .= "From: \"" . $from . "\" <" . $from . ">\r\n";
}
$mail .= "<p>Support Email from: <a href='" . site_url() . "'>" . site_url() . "</a></p>\r\n\r\n"; $mail .= "<p>Support Email from: <a href='" . site_url() . "'>" . site_url() . "</a></p>\r\n\r\n";
$mail .= '<p>Sent from WordPress page: ' . ( ! empty( $_POST['mainwp_branding_send_from_page'] ) ? "<a href='" . esc_url( $_POST['mainwp_branding_send_from_page'] ) . "'>" . esc_url( $_POST['mainwp_branding_send_from_page'] ) . "</a></p>\r\n\r\n" : '' ); $mail .= "<p>Sent from WordPress page: " . ( ! empty( $_POST["mainwp_branding_send_from_page"] ) ? "<a href='" . esc_url( $_POST["mainwp_branding_send_from_page"] ) . "'>" . esc_url( $_POST["mainwp_branding_send_from_page"] ) . "</a></p>\r\n\r\n" : "" );
$mail .= '<p>Client Email: ' . $current_user->user_email . " </p>\r\n\r\n"; $mail .= "<p>Client Email: " . $current_user->user_email . " </p>\r\n\r\n";
$mail .= "<p>Support Text:</p>\r\n\r\n"; $mail .= "<p>Support Text:</p>\r\n\r\n";
$mail .= '<p>' . $content . "</p>\r\n\r\n"; $mail .= "<p>" . $content . "</p>\r\n\r\n";
if ( @wp_mail( $email, $subject, $mail, $headers ) ) {; if ( @wp_mail( $email, $subject, $mail, $headers ) ) {
;
} }
return true; return true;
@ -871,8 +860,7 @@ class MainWP_Child_Branding {
} }
?> ?>
<div <div
class="mainwp_info-box-yellow"><?php echo esc_html( $send_email_message ) . '&nbsp;&nbsp' . $back_link; ?></div> class="mainwp_info-box-yellow"><?php echo esc_html( $send_email_message ) . "&nbsp;&nbsp" . $back_link; ?></div><?php
<?php
} else { } else {
$from_page = ''; $from_page = '';
if ( isset( $_GET['from_page'] ) ) { if ( isset( $_GET['from_page'] ) ) {
@ -885,7 +873,7 @@ class MainWP_Child_Branding {
$support_message = $opts['support_message']; $support_message = $opts['support_message'];
$support_message = nl2br( stripslashes( $support_message ) ); $support_message = nl2br( stripslashes( $support_message ) );
$from_email = $current_user ? $current_user->user_email : ''; $from_email = $current_user ? $current_user->user_email : '';
?> ?>
<form action="" method="post"> <form action="" method="post">
<div style="width: 99%;"> <div style="width: 99%;">
@ -902,12 +890,12 @@ class MainWP_Child_Branding {
<?php <?php
remove_editor_styles(); // stop custom theme styling interfering with the editor remove_editor_styles(); // stop custom theme styling interfering with the editor
wp_editor( '', 'mainwp_branding_contact_message_content', array( wp_editor( '', 'mainwp_branding_contact_message_content', array(
'textarea_name' => 'mainwp_branding_contact_message_content', 'textarea_name' => 'mainwp_branding_contact_message_content',
'textarea_rows' => 10, 'textarea_rows' => 10,
'teeny' => true, 'teeny' => true,
'wpautop' => true, 'wpautop' => true,
'media_buttons' => false, 'media_buttons' => false,
) )
); );
?> ?>
</div> </div>
@ -925,8 +913,7 @@ class MainWP_Child_Branding {
value="<?php echo esc_url( $from_page ); ?>"/> value="<?php echo esc_url( $from_page ); ?>"/>
<input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( '_contactNonce' ) ); ?>"/> <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( '_contactNonce' ) ); ?>"/>
</form> </form>
<?php <?php }
}
} }
/** /**
@ -934,8 +921,9 @@ class MainWP_Child_Branding {
*/ */
public function add_support_button_in_top_admin_bar( $wp_admin_bar ) { public function add_support_button_in_top_admin_bar( $wp_admin_bar ) {
$allow_contact = apply_filters('mainwp_branding_role_cap_enable_contact_form', false); $allow_contact = apply_filters('mainwp_branding_role_cap_enable_contact_form', false);
if ( $allow_contact ) {; // ok if ( $allow_contact ) {
} elseif ( ! current_user_can( 'administrator' ) ) { ; // ok
} else if ( !current_user_can( 'administrator' ) ) {
return false; return false;
} }
@ -963,13 +951,13 @@ class MainWP_Child_Branding {
public function is_branding() { public function is_branding() {
$opts = $this->child_branding_options; $opts = $this->child_branding_options;
if ( ! isset($opts['branding_ext_enabled']) || $opts['branding_ext_enabled'] !== 'Y' ) { if (!isset($opts['branding_ext_enabled']) || $opts['branding_ext_enabled'] !== 'Y') {
return false; return false;
} }
$is_hide = isset( $opts['hide'] ) ? $opts['hide'] : ''; $is_hide = isset( $opts['hide'] ) ? $opts['hide'] : '';
$cancelled_branding = $opts['cancelled_branding']; $cancelled_branding = $opts['cancelled_branding'];
$branding_header = isset( $opts['branding_header'] ) ? $opts['branding_header'] : ''; $branding_header = isset( $opts['branding_header'] ) ? $opts['branding_header'] : '';
if ( $cancelled_branding ) { if ( $cancelled_branding ) {
return false; return false;
@ -978,7 +966,7 @@ class MainWP_Child_Branding {
if ( 'T' === $is_hide ) { if ( 'T' === $is_hide ) {
return true; return true;
} }
if ( is_array( $branding_header ) && ! empty( $branding_header['name'] ) ) { if ( is_array( $branding_header ) && !empty( $branding_header['name'] ) ) {
return true; return true;
} }
return false; return false;
@ -997,38 +985,37 @@ class MainWP_Child_Branding {
} }
public function save_branding_options( $name, $val ) { public function save_branding_options( $name, $val ) {
$this->child_branding_options[ $name ] = $val; $this->child_branding_options[$name] = $val;
MainWP_Helper::update_option( 'mainwp_child_branding_settings', $this->child_branding_options ); MainWP_Helper::update_option( 'mainwp_child_branding_settings', $this->child_branding_options );
} }
public function after_admin_bar_render() { public function after_admin_bar_render() {
$hide_slugs = apply_filters('mainwp_child_hide_update_notice', array()); $hide_slugs = apply_filters('mainwp_child_hide_update_notice' , array());
if ( ! is_array($hide_slugs) ) { if (!is_array($hide_slugs))
$hide_slugs = array(); $hide_slugs = array();
}
if ( count($hide_slugs) == 0 ) { if (count($hide_slugs) == 0) {
return; return;
} }
if ( ! function_exists('get_plugin_updates') ) { if (!function_exists('get_plugin_updates')) {
include_once ABSPATH . '/wp-admin/includes/update.php'; include_once( ABSPATH . '/wp-admin/includes/update.php' );
} }
$count_hide = 0; $count_hide = 0;
$updates = get_plugin_updates(); $updates = get_plugin_updates();
if ( is_array($updates) ) { if (is_array($updates)) {
foreach ( $updates as $slug => $data ) { foreach($updates as $slug => $data) {
if ( in_array($slug, $hide_slugs) ) { if (in_array($slug, $hide_slugs)) {
$count_hide++; $count_hide++;
} }
} }
} }
if ( $count_hide == 0 ) { if ( $count_hide == 0) {
return; return;
} }
// js for front end // js for front end
@ -1050,30 +1037,29 @@ class MainWP_Child_Branding {
$adminBarUpdates.textContent = itemCount; $adminBarUpdates.textContent = itemCount;
} }
}); });
</script> </script><?php
<?php
} }
public function in_admin_footer() { public function in_admin_footer() {
$hide_slugs = apply_filters('mainwp_child_hide_update_notice', array()); $hide_slugs = apply_filters('mainwp_child_hide_update_notice' , array());
if ( ! is_array($hide_slugs) ) { if (!is_array($hide_slugs))
$hide_slugs = array(); $hide_slugs = array();
}
$count_hide = 0; $count_hide = 0;
$updates = get_plugin_updates(); $updates = get_plugin_updates();
if ( is_array($updates) ) { if (is_array($updates)) {
foreach ( $updates as $slug => $data ) { foreach($updates as $slug => $data) {
if ( in_array($slug, $hide_slugs) ) { if (in_array($slug, $hide_slugs)) {
$count_hide++; $count_hide++;
} }
} }
} }
if ( $count_hide == 0 ) { if ( $count_hide == 0) {
return; return;
} }
@ -1086,7 +1072,7 @@ class MainWP_Child_Branding {
if (typeof(pagenow) !== 'undefined' && pagenow == 'plugins') { if (typeof(pagenow) !== 'undefined' && pagenow == 'plugins') {
<?php <?php
// hide update notice row // hide update notice row
if ( in_array('mainwp-child/mainwp-child.php', $hide_slugs) ) { if (in_array('mainwp-child/mainwp-child.php', $hide_slugs)) {
?> ?>
var el = document.querySelector('tr#mainwp-child-update'); var el = document.querySelector('tr#mainwp-child-update');
if (typeof(el) !== 'undefined' && el !== null) { if (typeof(el) !== 'undefined' && el !== null) {
@ -1095,7 +1081,7 @@ class MainWP_Child_Branding {
<?php <?php
} }
// hide update notice row // hide update notice row
if ( in_array('mainwp-child-reports/mainwp-child-reports.php', $hide_slugs) ) { if (in_array('mainwp-child-reports/mainwp-child-reports.php', $hide_slugs)) {
?> ?>
var el = document.querySelector('tr#mainwp-child-reports-update'); var el = document.querySelector('tr#mainwp-child-reports-update');
if (typeof(el) !== 'undefined' && el !== null) { if (typeof(el) !== 'undefined' && el !== null) {
@ -1129,8 +1115,7 @@ class MainWP_Child_Branding {
}); });
} }
}); });
</script> </script><?php
<?php
} }
public function branding_map_meta_cap( $caps, $cap, $user_id, $args ) { public function branding_map_meta_cap( $caps, $cap, $user_id, $args ) {
@ -1146,9 +1131,9 @@ class MainWP_Child_Branding {
public function modify_plugin_header( $plugins ) { public function modify_plugin_header( $plugins ) {
$opts = $this->child_branding_options; $opts = $this->child_branding_options;
if ( is_array($opts) ) { if ( is_array($opts) ) {
$is_hide = isset( $opts['hide'] ) ? $opts['hide'] : ''; $is_hide = isset( $opts['hide'] ) ? $opts['hide'] : '';
$cancelled_branding = $opts['cancelled_branding']; $cancelled_branding = $opts['cancelled_branding'];
$branding_header = isset( $opts['branding_header'] ) ? $opts['branding_header'] : ''; $branding_header = isset( $opts['branding_header'] ) ? $opts['branding_header'] : '';
if ( $cancelled_branding ) { if ( $cancelled_branding ) {
return $plugins; return $plugins;
@ -1164,7 +1149,7 @@ class MainWP_Child_Branding {
return $plugins; return $plugins;
} }
if ( is_array( $branding_header ) && ! empty( $branding_header['name'] ) ) { if ( is_array( $branding_header ) && ! empty( $branding_header['name'] ) && is_array( $plugins ) ) {
return $this->update_plugin_header( $plugins, $branding_header ); return $this->update_plugin_header( $plugins, $branding_header );
} else { } else {
return $plugins; return $plugins;
@ -1185,7 +1170,7 @@ class MainWP_Child_Branding {
return $value; return $value;
} }
if ( ! MainWP_Helper::is_screen_with_update() ) { if (! MainWP_Helper::is_screen_with_update()) {
return $value; return $value;
} }

View file

@ -1,7 +1,7 @@
<?php <?php
class MainWP_Child_DB { class MainWP_Child_DB {
// Support old & new versions of WordPress (3.9+) //Support old & new versions of wordpress (3.9+)
public static function use_mysqli() { public static function use_mysqli() {
/** @var $wpdb wpdb */ /** @var $wpdb wpdb */
if ( ! function_exists( 'mysqli_connect' ) ) { if ( ! function_exists( 'mysqli_connect' ) ) {
@ -90,9 +90,9 @@ class MainWP_Child_DB {
/** @var $wpdb wpdb */ /** @var $wpdb wpdb */
global $wpdb; global $wpdb;
$rows = self::_query( 'SHOW table STATUS', $wpdb->dbh ); $rows = MainWP_Child_DB::_query( 'SHOW table STATUS', $wpdb->dbh );
$size = 0; $size = 0;
while ( $row = self::fetch_array( $rows ) ) { while ( $row = MainWP_Child_DB::fetch_array( $rows ) ) {
$size += $row['Data_length']; $size += $row['Data_length'];
} }

View file

@ -16,37 +16,36 @@
*/ */
class MainWP_Child_iThemes_Security { class MainWP_Child_iThemes_Security {
public static $instance = null; public static $instance = null;
public $is_plugin_installed = false; public $is_plugin_installed = false;
static function Instance() { static function Instance() {
if ( null === self::$instance ) { if ( null === MainWP_Child_iThemes_Security::$instance ) {
self::$instance = new MainWP_Child_iThemes_Security(); MainWP_Child_iThemes_Security::$instance = new MainWP_Child_iThemes_Security();
} }
return self::$instance; return MainWP_Child_iThemes_Security::$instance;
} }
public function __construct() { public function __construct() {
require_once ABSPATH . 'wp-admin/includes/plugin.php'; require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( is_plugin_active( 'better-wp-security/better-wp-security.php') || is_plugin_active( 'ithemes-security-pro/ithemes-security-pro.php' ) ) { if ( is_plugin_active( 'better-wp-security/better-wp-security.php') || is_plugin_active( 'ithemes-security-pro/ithemes-security-pro.php' ) ) {
$this->is_plugin_installed = true; $this->is_plugin_installed = true;
} }
if ( ! $this->is_plugin_installed ) { if (!$this->is_plugin_installed)
return; return;
}
add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 );
} }
// ok // ok
function syncOthersData( $information, $data = array() ) { function syncOthersData( $information, $data = array() ) {
if ( is_array( $data ) && isset( $data['ithemeExtActivated'] ) && ( 'yes' === $data['ithemeExtActivated'] ) ) { if ( is_array( $data ) && isset( $data['ithemeExtActivated'] ) && ( 'yes' === $data['ithemeExtActivated'] ) ) {
try { try{
$information['syncIThemeData'] = array( $information['syncIThemeData'] = array(
'users_and_roles' => $this->get_available_admin_users_and_roles(), 'users_and_roles' => $this->get_available_admin_users_and_roles()
); );
} catch ( Exception $e ) { } catch(Exception $e) {
error_log($e->getMessage()); error_log($e->getMessage());
} }
} }
@ -55,7 +54,7 @@ class MainWP_Child_iThemes_Security {
public function action() { public function action() {
$information = array(); $information = array();
if ( ! class_exists( 'ITSEC_Core' ) || ! class_exists('ITSEC_Modules') ) { if ( ! class_exists( 'ITSEC_Core' ) || !class_exists('ITSEC_Modules')) {
$information['error'] = 'NO_ITHEME'; $information['error'] = 'NO_ITHEME';
MainWP_Helper::write( $information ); MainWP_Helper::write( $information );
} }
@ -64,6 +63,7 @@ class MainWP_Child_iThemes_Security {
$mainwp_itsec_modules_path = ITSEC_Core::get_core_dir() . '/modules/'; $mainwp_itsec_modules_path = ITSEC_Core::get_core_dir() . '/modules/';
if ( isset( $_POST['mwp_action'] ) ) { if ( isset( $_POST['mwp_action'] ) ) {
switch ( $_POST['mwp_action'] ) { switch ( $_POST['mwp_action'] ) {
case 'set_showhide': case 'set_showhide':
@ -131,16 +131,15 @@ class MainWP_Child_iThemes_Security {
} }
public function ithemes_init() { public function ithemes_init() {
if ( ! $this->is_plugin_installed ) { if (!$this->is_plugin_installed)
return; return;
}
if ( get_option( 'mainwp_ithemes_hide_plugin' ) === 'hide' ) { if ( get_option( 'mainwp_ithemes_hide_plugin' ) === 'hide' ) {
add_filter( 'all_plugins', array( $this, 'all_plugins' ) ); add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
add_action( 'admin_menu', array( $this, 'remove_menu' ) ); add_action( 'admin_menu', array( $this, 'remove_menu' ) );
add_action( 'admin_init', array( $this, 'admin_init' ) ); add_action( 'admin_init', array( $this, 'admin_init' ) );
add_action( 'admin_head', array( &$this, 'custom_admin_css' ) ); add_action( 'admin_head', array( &$this, 'custom_admin_css' ) );
if ( isset($_GET['page']) && ( $_GET['page'] == 'itsec' || $_GET['page'] == 'itsec-security-check' ) ) { if ( isset($_GET['page']) && ($_GET['page'] == 'itsec' || $_GET['page'] == 'itsec-security-check') ) {
wp_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' ); wp_redirect( get_option( 'siteurl' ) . '/wp-admin/index.php' );
exit(); exit();
} }
@ -179,7 +178,7 @@ class MainWP_Child_iThemes_Security {
function save_settings() { function save_settings() {
if ( ! class_exists( 'ITSEC_Lib' ) ) { if ( ! class_exists( 'ITSEC_Lib' ) ) {
require ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php'; require( ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php' );
} }
$_itsec_modules = array( $_itsec_modules = array(
@ -194,192 +193,191 @@ class MainWP_Child_iThemes_Security {
'404-detection', '404-detection',
'network-brute-force', 'network-brute-force',
'ssl', 'ssl',
// 'strong-passwords', //'strong-passwords',
'password-requirements', 'password-requirements',
'system-tweaks', 'system-tweaks',
'wordpress-tweaks', 'wordpress-tweaks',
'multisite-tweaks', 'multisite-tweaks',
'notification-center', 'notification-center',
// 'salts', //'salts',
// 'content-directory', //'content-directory',
); );
$require_permalinks = false; $require_permalinks = false;
$updated = false; $updated = false;
$errors = array(); $errors = array();
$nbf_settings = array(); $nbf_settings = array();
$update_settings = maybe_unserialize( base64_decode( $_POST['settings'] ) ); $update_settings = maybe_unserialize( base64_decode( $_POST['settings'] ) );
foreach ( $update_settings as $module => $settings ) { foreach($update_settings as $module => $settings) {
$do_not_save = false; $do_not_save = false;
if ( in_array($module, $_itsec_modules) ) { if (in_array($module, $_itsec_modules)) {
if ( $module == 'wordpress-salts' ) { if ($module == 'wordpress-salts') {
$settings['last_generated'] = ITSEC_Modules::get_setting( $module, 'last_generated' ); // not update $settings['last_generated'] = ITSEC_Modules::get_setting( $module, 'last_generated' ); // not update
} elseif ( $module == 'global' ) { } else if ($module == 'global') {
$keep_olds = array( 'did_upgrade', 'log_info', 'show_new_dashboard_notice', 'show_security_check', 'nginx_file' ); $keep_olds = array( 'did_upgrade', 'log_info', 'show_new_dashboard_notice', 'show_security_check' , 'nginx_file' );
foreach ( $keep_olds as $key ) { foreach($keep_olds as $key) {
$settings[ $key ] = ITSEC_Modules::get_setting( $module, $key ); // not update $settings[$key] = ITSEC_Modules::get_setting( $module, $key ); // not update
} }
if ( ! isset($settings['log_location']) || empty($settings['log_location']) ) { if (!isset($settings['log_location']) || empty($settings['log_location']) ) {
$settings['log_location'] = ITSEC_Modules::get_setting( $module, 'log_location' ); $settings['log_location'] = ITSEC_Modules::get_setting( $module, 'log_location' );
} else { } else {
$result = $this->validate_directory('log_location', $settings['log_location']); $result = $this->validate_directory('log_location', $settings['log_location']);
if ( $result !== true ) { if ($result !== true) {
$errors[] = $result; $errors[] = $result;
$settings['log_location'] = ITSEC_Modules::get_setting( $module, 'log_location' ); // no change $settings['log_location'] = ITSEC_Modules::get_setting( $module, 'log_location' ); // no change
} }
} }
} elseif ( $module == 'backup' ) {
if ( ! isset($settings['location']) || empty($settings['location']) ) { } else if ($module == 'backup') {
if (!isset($settings['location']) || empty($settings['location']) ) {
$settings['location'] = ITSEC_Modules::get_setting( $module, 'location' ); $settings['location'] = ITSEC_Modules::get_setting( $module, 'location' );
} else { } else {
$result = $this->validate_directory('location', $settings['location']); $result = $this->validate_directory('location', $settings['location']);
if ( $result !== true ) { if ($result !== true) {
$errors[] = $result; $errors[] = $result;
$settings['location'] = ITSEC_Modules::get_setting( $module, 'location' ); // no change $settings['location'] = ITSEC_Modules::get_setting( $module, 'location' ); // no change
} }
} }
if ( ! isset($settings['exclude']) ) { if (!isset($settings['exclude']) ) {
$settings['exclude'] = ITSEC_Modules::get_setting( $module, 'exclude' ); $settings['exclude'] = ITSEC_Modules::get_setting( $module, 'exclude' );;
} }
} elseif ( $module == 'hide-backend' ) { } else if ($module == 'hide-backend') {
if ( isset($settings['enabled']) && ! empty($settings['enabled']) ) { if (isset($settings['enabled']) && !empty($settings['enabled'])) {
$permalink_structure = get_option( 'permalink_structure', false ); $permalink_structure = get_option( 'permalink_structure', false );
if ( empty( $permalink_structure ) && ! is_multisite() ) { if ( empty( $permalink_structure ) && ! is_multisite() ) {
$errors[] = __( 'You must change <strong>WordPress permalinks</strong> to a setting other than "Plain" in order to use "Hide Backend" feature.', 'better-wp-security' ); $errors[] = __( 'You must change <strong>WordPress permalinks</strong> to a setting other than "Plain" in order to use "Hide Backend" feature.', 'better-wp-security' );
$require_permalinks = true; $require_permalinks = true;
$do_not_save = true; $do_not_save = true;
} }
} }
} elseif ( $module == 'network-brute-force' ) { } else if ($module == 'network-brute-force') {
if ( isset( $settings['email'] ) ) { if ( isset( $settings['email'] ) ) {
$result = $this->activate_api_key($settings); $result = $this->activate_api_key($settings);
if ( $result === false ) { if ($result === false) {
$nbf_settings = $settings; $nbf_settings = $settings;
$errors[] = 'Error: Active iThemes Network Brute Force Protection Api Key'; $errors[] = 'Error: Active iThemes Network Brute Force Protection Api Key';
} else { } else {
$nbf_settings = $result; $nbf_settings = $result;
} }
} else { } else {
$previous_settings = ITSEC_Modules::get_settings( $module ); $previous_settings = ITSEC_Modules::get_settings( $module );
// update 'enable_ban' field only // update 'enable_ban' field only
if ( isset($settings['enable_ban']) ) { if (isset($settings['enable_ban'])) {
$previous_settings['enable_ban'] = $settings['enable_ban']; $previous_settings['enable_ban'] = $settings['enable_ban'];
$nbf_settings = $previous_settings; $nbf_settings = $previous_settings;
} else { } else {
$do_not_save = true; $do_not_save = true;
$nbf_settings = $previous_settings; $nbf_settings = $previous_settings;
} }
} }
$settings = $nbf_settings; $settings = $nbf_settings;
} elseif ( $module == 'notification-center' ) { } else if ($module == 'notification-center') {
$current_settings = ITSEC_Modules::get_settings( $module ); $current_settings = ITSEC_Modules::get_settings( $module );
if ( isset($settings['notifications']) ) { if (isset($settings['notifications'])) {
$update_fields = array( 'schedule', 'enabled', 'subject' ); $update_fields = array( 'schedule', 'enabled', 'subject');
if ( isset($_POST['is_individual']) && $_POST['is_individual'] ) { if (isset($_POST['is_individual']) && $_POST['is_individual']) {
$update_fields = array_merge($update_fields, array( 'user_list', 'email_list' )); $update_fields = array_merge($update_fields, array('user_list', 'email_list'));
} }
foreach ( $settings['notifications'] as $key => $val ) { foreach ($settings['notifications'] as $key => $val) {
foreach ( $update_fields as $field ) { foreach ($update_fields as $field) {
if ( isset($val[ $field ]) ) { if(isset($val[$field])) {
$current_settings['notifications'][ $key ][ $field ] = $val[ $field ]; $current_settings['notifications'][$key][$field] = $val[$field];
} }
} }
} }
$updated = true; $updated = true;
ITSEC_Modules::set_settings( $module, $current_settings ); ITSEC_Modules::set_settings( $module, $current_settings );
} }
continue; continue;
} }
if ( ! $do_not_save ) { if ( !$do_not_save ) {
ITSEC_Modules::set_settings( $module, $settings ); ITSEC_Modules::set_settings( $module, $settings );
$updated = true; $updated = true;
} }
} }
} }
if ( isset( $update_settings['itsec_active_modules'] ) ) { if ( isset( $update_settings['itsec_active_modules'] ) ) {
$current_val = get_site_option( 'itsec_active_modules', array() ); $current_val = get_site_option( 'itsec_active_modules', array() );
foreach ( $update_settings['itsec_active_modules'] as $mod => $val ) { foreach ($update_settings['itsec_active_modules'] as $mod => $val) {
$current_val[ $mod ] = $val; $current_val[$mod] = $val;
} }
update_site_option( 'itsec_active_modules', $current_val ); update_site_option( 'itsec_active_modules', $current_val );
} }
require_once ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php'; require_once( ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php' );
$values = array( $values = array(
'permalink_structure' => get_option( 'permalink_structure' ), 'permalink_structure' => get_option( 'permalink_structure' ),
'is_multisite' => is_multisite() ? 1 : 0, 'is_multisite' => is_multisite() ? 1 : 0,
'users_can_register' => get_site_option( 'users_can_register' ) ? 1 : 0, 'users_can_register' => get_site_option( 'users_can_register' ) ? 1 : 0,
'server_nginx' => ( ITSEC_Lib::get_server() === 'nginx' ) ? 1 : 0, 'server_nginx' => ( ITSEC_Lib::get_server() === 'nginx' ) ? 1 : 0,
'has_ssl' => ITSEC_Lib::get_ssl_support_probability(), 'has_ssl' => ITSEC_Lib::get_ssl_support_probability(),
'jquery_version' => ITSEC_Modules::get_setting( 'wordpress-tweaks', 'jquery_version' ), 'jquery_version' => ITSEC_Modules::get_setting( 'wordpress-tweaks', 'jquery_version' ),
'server_rules' => ITSEC_Lib_Config_File::get_server_config(), 'server_rules' => ITSEC_Lib_Config_File::get_server_config(),
'config_rules' => ITSEC_Lib_Config_File::get_wp_config(), 'config_rules' => ITSEC_Lib_Config_File::get_wp_config(),
'lockouts_host' => $this->get_lockouts( 'host', true ), 'lockouts_host' => $this->get_lockouts( 'host', true ),
'lockouts_user' => $this->get_lockouts( 'user', true ), 'lockouts_user' => $this->get_lockouts( 'user', true ),
'lockouts_username' => $this->get_lockouts( 'username', true ), 'lockouts_username' => $this->get_lockouts( 'username', true ),
'default_log_location' => ITSEC_Modules::get_default( 'global', 'log_location' ), 'default_log_location' => ITSEC_Modules::get_default( 'global', 'log_location' ),
'default_location' => ITSEC_Modules::get_default( 'backup', 'location' ), 'default_location' => ITSEC_Modules::get_default( 'backup', 'location' ),
'excludable_tables' => $this->get_excludable_tables(), 'excludable_tables' => $this->get_excludable_tables(),
'users_and_roles' => $this->get_available_admin_users_and_roles(), 'users_and_roles' => $this->get_available_admin_users_and_roles()
); );
$return = array( $return = array(
'site_status' => $values, 'site_status' => $values
); );
if ( $require_permalinks ) { if ($require_permalinks) {
$return['require_permalinks'] = 1; $return['require_permalinks'] = 1;
} }
$return['nbf_settings'] = $nbf_settings; $return['nbf_settings'] = $nbf_settings;
if ( ! empty($errors) ) { if (!empty($errors)) {
$return['extra_message'] = $errors; $return['extra_message'] = $errors;
} }
if ( $updated ) { if ($updated)
$return['result'] = 'success'; $return['result'] = 'success';
} else { else
$return['error'] = __('Not Updated', 'mainwp-child' ); $return['error'] = __('Not Updated', 'mainwp-child' );
}
return $return; return $return;
} }
public static function activate_network_brute_force() { public static function activate_network_brute_force() {
$data = maybe_unserialize( base64_decode( $_POST['data'] ) ); $data = maybe_unserialize( base64_decode( $_POST['data'] ) );
$information = array(); $information = array();
if ( is_array($data) ) { if (is_array($data)) {
$settings = ITSEC_Modules::get_settings( 'network-brute-force' ); $settings = ITSEC_Modules::get_settings( 'network-brute-force' );
$settings['email'] = $data['email']; $settings['email'] = $data['email'];
$settings['updates_optin'] = $data['updates_optin']; $settings['updates_optin'] = $data['updates_optin'];
$settings['api_nag'] = false; $settings['api_nag'] = false;
$results = ITSEC_Modules::set_settings( 'network-brute-force', $settings ); $results = ITSEC_Modules::set_settings( 'network-brute-force', $settings );
if ( is_wp_error( $results ) ) { if ( is_wp_error( $results ) ) {
$information['error'] = 'Error: Active iThemes Network Brute Force Protection Api Key'; $information['error'] = 'Error: Active iThemes Network Brute Force Protection Api Key';
} elseif ( $results['saved'] ) { } else if ( $results['saved'] ) {
ITSEC_Modules::activate( 'network-brute-force' ); ITSEC_Modules::activate( 'network-brute-force' );
$nbf_settings = ITSEC_Modules::get_settings( 'network-brute-force' ); $nbf_settings = ITSEC_Modules::get_settings( 'network-brute-force' );
// ITSEC_Response::set_response( '<p>' . __( 'Your site is now using Network Brute Force Protection.', 'better-wp-security' ) . '</p>' ); // ITSEC_Response::set_response( '<p>' . __( 'Your site is now using Network Brute Force Protection.', 'better-wp-security' ) . '</p>' );
} }
} }
if ( $nbf_settings !== null ) { if ($nbf_settings !== null) {
$information['nbf_settings'] = $nbf_settings; $information['nbf_settings'] = $nbf_settings;
$information['result'] = 'success'; $information['result'] = 'success';
} }
return $information; return $information;
} }
private function validate_directory( $name, $folder ) { private function validate_directory($name, $folder) {
require_once ITSEC_Core::get_core_dir() . 'lib/class-itsec-lib-directory.php'; require_once( ITSEC_Core::get_core_dir() . 'lib/class-itsec-lib-directory.php' );
$error = null; $error = null;
if ( ! ITSEC_Lib_Directory::is_dir( $folder ) ) { if ( ! ITSEC_Lib_Directory::is_dir( $folder ) ) {
$result = ITSEC_Lib_Directory::create( $folder ); $result = ITSEC_Lib_Directory::create( $folder );
@ -401,24 +399,24 @@ class MainWP_Child_iThemes_Security {
} }
} }
private function activate_api_key( $settings ) { private function activate_api_key($settings) {
global $mainwp_itsec_modules_path; global $mainwp_itsec_modules_path;
require_once $mainwp_itsec_modules_path . 'ipcheck/utilities.php'; require_once ( $mainwp_itsec_modules_path . 'ipcheck/utilities.php' );
$key = ITSEC_Network_Brute_Force_Utilities::get_api_key( $settings['email'], $settings['updates_optin'] ); $key = ITSEC_Network_Brute_Force_Utilities::get_api_key( $settings['email'], $settings['updates_optin'] );
if ( is_wp_error( $key ) ) { if ( is_wp_error( $key ) ) {
return false; return false;
// $this->set_can_save( false ); // $this->set_can_save( false );
// $this->add_error( $key ); // $this->add_error( $key );
} else { } else {
$secret = ITSEC_Network_Brute_Force_Utilities::activate_api_key( $key ); $secret = ITSEC_Network_Brute_Force_Utilities::activate_api_key( $key );
if ( is_wp_error( $secret ) ) { if ( is_wp_error( $secret ) ) {
return false; return false;
// $this->set_can_save( false ); // $this->set_can_save( false );
// $this->add_error( $secret ); // $this->add_error( $secret );
} else { } else {
$settings['api_key'] = $key; $settings['api_key'] = $key;
$settings['api_secret'] = $secret; $settings['api_secret'] = $secret;
$settings['api_nag'] = false; $settings['api_nag'] = false;
@ -485,6 +483,7 @@ class MainWP_Child_iThemes_Security {
return $response; return $response;
} }
} }
function whitelist_release() { function whitelist_release() {
@ -497,15 +496,15 @@ class MainWP_Child_iThemes_Security {
global $itsec_backup, $mainwp_itsec_modules_path; global $itsec_backup, $mainwp_itsec_modules_path;
if ( ! isset( $itsec_backup ) ) { if ( ! isset( $itsec_backup ) ) {
require_once $mainwp_itsec_modules_path . 'backup/class-itsec-backup.php'; require_once ( $mainwp_itsec_modules_path . 'backup/class-itsec-backup.php' );
$itsec_backup = new ITSEC_Backup(); $itsec_backup = new ITSEC_Backup();
$itsec_backup->run(); $itsec_backup->run();
} }
$return = array(); $return = array();
$str_error = ''; $str_error = '';
$result = $itsec_backup->do_backup( true ); $result = $itsec_backup->do_backup( true );
if ( is_wp_error( $result ) ) { if ( is_wp_error( $result ) ) {
$errors = ITSEC_Response::get_error_strings( $result ); $errors = ITSEC_Response::get_error_strings( $result );
@ -513,14 +512,14 @@ class MainWP_Child_iThemes_Security {
foreach ( $errors as $error ) { foreach ( $errors as $error ) {
$str_error .= $error . '<br />'; $str_error .= $error . '<br />';
} }
} elseif ( is_string( $result ) ) { } else if ( is_string( $result ) ) {
$return['result'] = 'success'; $return['result'] = 'success';
$return['message'] = $result; $return['message'] = $result;
} else { } else {
$str_error = sprintf( __( 'The backup request returned an unexpected response. It returned a response of type <code>%1$s</code>.', 'better-wp-security' ), gettype( $result ) ); $str_error = sprintf( __( 'The backup request returned an unexpected response. It returned a response of type <code>%1$s</code>.', 'better-wp-security' ), gettype( $result ) ) ;
} }
if ( ! empty($str_error) ) { if (!empty($str_error)) {
$return['error'] = $str_error; $return['error'] = $str_error;
} }
@ -531,9 +530,9 @@ class MainWP_Child_iThemes_Security {
private function wordpress_salts() { private function wordpress_salts() {
global $mainwp_itsec_modules_path; global $mainwp_itsec_modules_path;
if ( ! class_exists( 'ITSEC_WordPress_Salts_Utilities' ) ) { if ( ! class_exists( 'ITSEC_WordPress_Salts_Utilities' ) ) {
require $mainwp_itsec_modules_path . 'salts/utilities.php'; require( $mainwp_itsec_modules_path . 'salts/utilities.php' );
} }
$result = ITSEC_WordPress_Salts_Utilities::generate_new_salts(); $result = ITSEC_WordPress_Salts_Utilities::generate_new_salts();
$str_error = ''; $str_error = '';
if ( is_wp_error( $result ) ) { if ( is_wp_error( $result ) ) {
$errors = ITSEC_Response::get_error_strings( $result ); $errors = ITSEC_Response::get_error_strings( $result );
@ -542,19 +541,19 @@ class MainWP_Child_iThemes_Security {
$str_error .= $error . '<br />'; $str_error .= $error . '<br />';
} }
} else { } else {
$return['result'] = 'success'; $return['result'] = 'success';
$return['message'] = __( 'The WordPress salts were successfully regenerated.', 'better-wp-security' ); $return['message'] = __( 'The WordPress salts were successfully regenerated.', 'better-wp-security' ) ;
$last_generated = ITSEC_Core::get_current_time_gmt(); $last_generated = ITSEC_Core::get_current_time_gmt();
ITSEC_Modules::set_setting( 'wordpress-salts', 'last_generated', $last_generated ); ITSEC_Modules::set_setting( 'wordpress-salts', 'last_generated', $last_generated );
} }
if ( ! empty($str_error) ) { if (!empty($str_error)) {
$return['error'] = $str_error; $return['error'] = $str_error;
} }
return $return; return $return;
} }
private function file_permissions() { private function file_permissions() {
require_once ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php'; require_once( ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php' );
$wp_upload_dir = ITSEC_Core::get_wp_upload_dir(); $wp_upload_dir = ITSEC_Core::get_wp_upload_dir();
@ -585,7 +584,7 @@ class MainWP_Child_iThemes_Security {
), ),
array( array(
WP_PLUGIN_DIR, WP_PLUGIN_DIR,
0755, 0755
), ),
array( array(
$wp_upload_dir['basedir'], $wp_upload_dir['basedir'],
@ -601,6 +600,7 @@ class MainWP_Child_iThemes_Security {
), ),
); );
$rows = array(); $rows = array();
foreach ( $path_data as $path ) { foreach ( $path_data as $path ) {
@ -619,7 +619,7 @@ class MainWP_Child_iThemes_Security {
$row[] = sprintf( '%o', $suggested_permissions ); $row[] = sprintf( '%o', $suggested_permissions );
$permissions = fileperms( $path ) & 0777; $permissions = fileperms( $path ) & 0777;
$row[] = sprintf( '%o', $permissions ); $row[] = sprintf( '%o', $permissions );
if ( ! $permissions || $permissions != $suggested_permissions ) { if ( ! $permissions || $permissions != $suggested_permissions ) {
$row[] = __( 'WARNING', 'better-wp-security' ); $row[] = __( 'WARNING', 'better-wp-security' );
@ -632,9 +632,10 @@ class MainWP_Child_iThemes_Security {
$rows[] = $row; $rows[] = $row;
} }
$class = 'entry-row'; $class = 'entry-row';
ob_start(); ob_start();
?> ?>
<p><input type="button" id="itsec-file-permissions-reload_file_permissions" name="file-permissions[reload_file_permissions]" class="button-primary itsec-reload-module" value="<?php _e('Reload File Permissions Details', 'mainwp-child'); ?>"></p> <p><input type="button" id="itsec-file-permissions-reload_file_permissions" name="file-permissions[reload_file_permissions]" class="button-primary itsec-reload-module" value="<?php _e('Reload File Permissions Details', 'mainwp-child'); ?>"></p>
<table class="widefat"> <table class="widefat">
<thead> <thead>
@ -667,19 +668,19 @@ class MainWP_Child_iThemes_Security {
</tbody> </tbody>
</table> </table>
<br /> <br />
<?php <?php
$html = ob_get_clean(); $html = ob_get_clean();
return array( 'html' => $html ); return array('html' => $html);
} }
public function file_change() { public function file_change() {
global $mainwp_itsec_modules_path; global $mainwp_itsec_modules_path;
if ( ! class_exists( 'ITSEC_File_Change_Scanner' ) ) { if ( ! class_exists( 'ITSEC_File_Change_Scanner' ) ) {
require_once $mainwp_itsec_modules_path . 'file-change/scanner.php'; require_once( $mainwp_itsec_modules_path . 'file-change/scanner.php' );
} }
$result = ITSEC_File_Change_Scanner::run_scan( false ); $result = ITSEC_File_Change_Scanner::run_scan( false );
if ( $result === false || $result === true || $result === -1 ) { if ($result === false || $result === true || $result === -1) {
$return['result'] = 'success'; $return['result'] = 'success';
$return['scan_result'] = $result; $return['scan_result'] = $result;
} }
return $return; return $return;
@ -689,32 +690,33 @@ class MainWP_Child_iThemes_Security {
$settings = $_POST['settings']; $settings = $_POST['settings'];
if ( ! is_array($settings) ) { if (!is_array($settings))
$settings = array(); $settings = array();
}
$new_username = isset( $settings['new_username'] ) ? $settings['new_username'] : ''; $new_username = isset( $settings['new_username'] ) ? $settings['new_username'] : '';
$change_id = isset( $settings['change_id'] ) && $settings['change_id'] ? true : false; $change_id = isset( $settings['change_id'] ) && $settings['change_id'] ? true : false;
// load utility functions
//load utility functions
if ( ! class_exists( 'ITSEC_Lib' ) ) { if ( ! class_exists( 'ITSEC_Lib' ) ) {
global $itsec_globals; global $itsec_globals;
require ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php'; require( ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php' );
} }
$username_exists = username_exists( 'admin' ); $username_exists = username_exists( 'admin' );
$user_id_exists = ITSEC_Lib::user_id_exists( 1 ); $user_id_exists = ITSEC_Lib::user_id_exists( 1 );
$msg = ''; $msg = '';
if ( strlen( $new_username ) >= 1 ) { if ( strlen( $new_username ) >= 1) {
global $current_user; global $current_user;
if ( ! $username_exists ) { if ( ! $username_exists ) {
$msg = __( 'Admin user already changes.', 'mainwp-child' ); $msg = __( 'Admin user already changes.', 'mainwp-child' );
} elseif ( $current_user->user_login == 'admin' ) { } else if ($current_user->user_login == 'admin') {
$return['result'] = 'CHILD_ADMIN'; $return['result'] = 'CHILD_ADMIN';
return $return; return $return;
} }
} }
if ( true === $change_id && ! $user_id_exists ) { if ( true === $change_id && ! $user_id_exists ) {
if ( ! empty( $msg ) ) { if ( ! empty( $msg ) ) {
$msg .= '<br/>'; $msg .= '<br/>';
@ -722,16 +724,16 @@ class MainWP_Child_iThemes_Security {
$msg .= __( 'Admin user ID already changes.', 'mainwp-child' ); $msg .= __( 'Admin user ID already changes.', 'mainwp-child' );
} }
// if ( $change_id ) { // if ( $change_id ) {
// $user = get_user_by( 'login', $new_username ); // $user = get_user_by( 'login', $new_username );
// if ( $user && 1 === (int) $user->ID ) { // if ( $user && 1 === (int) $user->ID ) {
// $return['result'] = 'CHILD_ADMIN'; // $return['result'] = 'CHILD_ADMIN';
// return $return; // return $return;
// } // }
// } // }
$admin_success = true; $admin_success = true;
$return = array(); $return = array();
if ( strlen( $new_username ) >= 1 && $username_exists ) { if ( strlen( $new_username ) >= 1 && $username_exists ) {
$admin_success = $this->change_admin_user( $new_username, $change_id ); $admin_success = $this->change_admin_user( $new_username, $change_id );
@ -754,94 +756,95 @@ class MainWP_Child_iThemes_Security {
$itsec_files = ITSEC_Core::get_itsec_files(); $itsec_files = ITSEC_Core::get_itsec_files();
// do not need to check this // do not need to check this
// if ( $itsec_files->get_file_lock( 'admin_user' ) ) { //make sure it isn't already running //if ( $itsec_files->get_file_lock( 'admin_user' ) ) { //make sure it isn't already running
// sanitize the username //sanitize the username
$new_user = sanitize_text_field( $username ); $new_user = sanitize_text_field( $username );
// Get the full user object //Get the full user object
$user_object = get_user_by( 'id', '1' ); $user_object = get_user_by( 'id', '1' );
if ( null !== $username && validate_username( $new_user ) && false === username_exists( $new_user ) ) { // there is a valid username to change if ( null !== $username && validate_username( $new_user ) && false === username_exists( $new_user ) ) { //there is a valid username to change
if ( true === $id ) { // we're changing the id too so we'll set the username if ( true === $id ) { //we're changing the id too so we'll set the username
$user_login = $new_user; $user_login = $new_user;
} else { // we're only changing the username } else { // we're only changing the username
// query main user table //query main user table
$wpdb->query( 'UPDATE `' . $wpdb->users . "` SET user_login = '" . esc_sql( $new_user ) . "' WHERE user_login='admin';" ); $wpdb->query( "UPDATE `" . $wpdb->users . "` SET user_login = '" . esc_sql( $new_user ) . "' WHERE user_login='admin';" );
if ( is_multisite() ) { // process sitemeta if we're in a multi-site situation if ( is_multisite() ) { //process sitemeta if we're in a multi-site situation
$oldAdmins = $wpdb->get_var( 'SELECT meta_value FROM `' . $wpdb->sitemeta . "` WHERE meta_key = 'site_admins'" );
$newAdmins = str_replace( '5:"admin"', strlen( $new_user ) . ':"' . esc_sql( $new_user ) . '"', $oldAdmins );
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->sitemeta . "` SET meta_value = %s WHERE meta_key = 'site_admins'", $newAdmins ) );
}
wp_clear_auth_cookie();
$itsec_files->release_file_lock( 'admin_user' );
return true;
}
} elseif ( null !== $username ) { //username didn't validate
$itsec_files->release_file_lock( 'admin_user' );
return false;
} else { //only changing the id
$user_login = $user_object->user_login;
}
if ( true === $id ) { //change the user id
$wpdb->query( 'DELETE FROM `' . $wpdb->users . '` WHERE ID = 1;' );
$wpdb->insert( $wpdb->users, array(
'user_login' => $user_login,
'user_pass' => $user_object->user_pass,
'user_nicename' => $user_object->user_nicename,
'user_email' => $user_object->user_email,
'user_url' => $user_object->user_url,
'user_registered' => $user_object->user_registered,
'user_activation_key' => $user_object->user_activation_key,
'user_status' => $user_object->user_status,
'display_name' => $user_object->display_name,
) );
if ( is_multisite() && null !== $username && validate_username( $new_user ) ) { //process sitemeta if we're in a multi-site situation
$oldAdmins = $wpdb->get_var( 'SELECT meta_value FROM `' . $wpdb->sitemeta . "` WHERE meta_key = 'site_admins'" ); $oldAdmins = $wpdb->get_var( 'SELECT meta_value FROM `' . $wpdb->sitemeta . "` WHERE meta_key = 'site_admins'" );
$newAdmins = str_replace( '5:"admin"', strlen( $new_user ) . ':"' . esc_sql( $new_user ) . '"', $oldAdmins ); $newAdmins = str_replace( '5:"admin"', strlen( $new_user ) . ':"' . esc_sql( $new_user ) . '"', $oldAdmins );
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->sitemeta . "` SET meta_value = %s WHERE meta_key = 'site_admins'", $newAdmins ) ); $wpdb->query( 'UPDATE `' . $wpdb->sitemeta . "` SET meta_value = '" . esc_sql( $newAdmins ) . "' WHERE meta_key = 'site_admins'" );
} }
$new_user = $wpdb->insert_id;
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->posts . "` SET post_author = %s WHERE post_author = 1;", $new_user ) );
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->usermeta . "` SET user_id = %s WHERE user_id = 1;", $new_user ) );
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->comments . "` SET user_id = %s WHERE user_id = 1;", $new_user ) );
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->links . "` SET link_owner = %s WHERE link_owner = 1;", $new_user ) );
wp_clear_auth_cookie(); wp_clear_auth_cookie();
$itsec_files->release_file_lock( 'admin_user' ); $itsec_files->release_file_lock( 'admin_user' );
return true; return true;
} }
} elseif ( null !== $username ) { // username didn't validate //}
$itsec_files->release_file_lock( 'admin_user' );
return false;
} else { // only changing the id
$user_login = $user_object->user_login;
}
if ( true === $id ) { // change the user id
$wpdb->query( 'DELETE FROM `' . $wpdb->users . '` WHERE ID = 1;' );
$wpdb->insert( $wpdb->users, array(
'user_login' => $user_login,
'user_pass' => $user_object->user_pass,
'user_nicename' => $user_object->user_nicename,
'user_email' => $user_object->user_email,
'user_url' => $user_object->user_url,
'user_registered' => $user_object->user_registered,
'user_activation_key' => $user_object->user_activation_key,
'user_status' => $user_object->user_status,
'display_name' => $user_object->display_name,
) );
if ( is_multisite() && null !== $username && validate_username( $new_user ) ) { // process sitemeta if we're in a multi-site situation
$oldAdmins = $wpdb->get_var( 'SELECT meta_value FROM `' . $wpdb->sitemeta . "` WHERE meta_key = 'site_admins'" );
$newAdmins = str_replace( '5:"admin"', strlen( $new_user ) . ':"' . esc_sql( $new_user ) . '"', $oldAdmins );
$wpdb->query( 'UPDATE `' . $wpdb->sitemeta . "` SET meta_value = '" . esc_sql( $newAdmins ) . "' WHERE meta_key = 'site_admins'" );
}
$new_user = $wpdb->insert_id;
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->posts . '` SET post_author = %s WHERE post_author = 1;', $new_user ) );
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->usermeta . '` SET user_id = %s WHERE user_id = 1;', $new_user ) );
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->comments . '` SET user_id = %s WHERE user_id = 1;', $new_user ) );
$wpdb->query( $wpdb->prepare( 'UPDATE `' . $wpdb->links . '` SET link_owner = %s WHERE link_owner = 1;', $new_user ) );
wp_clear_auth_cookie();
$itsec_files->release_file_lock( 'admin_user' );
return true;
}
// }
return false; return false;
} }
public function build_wpconfig_rules( $rules_array, $input = null ) { public function build_wpconfig_rules( $rules_array, $input = null ) {
// Get the rules from the database if input wasn't sent //Get the rules from the database if input wasn't sent
if ( null === $input ) { if ( null === $input ) {
return $rules_array; return $rules_array;
} }
@ -866,27 +869,24 @@ class MainWP_Child_iThemes_Security {
'rule' => "define( 'WP_CONTENT_DIR', '" . $new_dir . "' );", 'rule' => "define( 'WP_CONTENT_DIR', '" . $new_dir . "' );",
); );
$rules_array[] = array( $rules_array[] = array( 'type' => 'wpconfig', 'name' => 'Content Directory', 'rules' => $rules );
'type' => 'wpconfig',
'name' => 'Content Directory',
'rules' => $rules,
);
return $rules_array; return $rules_array;
} }
public function change_database_prefix() { public function change_database_prefix() {
global $mainwp_itsec_modules_path; global $mainwp_itsec_modules_path;
require_once $mainwp_itsec_modules_path . 'database-prefix/utility.php'; require_once( $mainwp_itsec_modules_path . 'database-prefix/utility.php' );
$str_error = ''; $str_error = '';
$return = array(); $return = array();
if ( isset( $_POST['change_prefix'] ) && 'yes' === $_POST['change_prefix'] ) { if ( isset( $_POST['change_prefix'] ) && 'yes' === $_POST['change_prefix'] ) {
$result = ITSEC_Database_Prefix_Utility::change_database_prefix(); $result = ITSEC_Database_Prefix_Utility::change_database_prefix();
$return = $result['errors']; $return = $result['errors'];
if ( is_array($result['errors']) ) { if (is_array($result['errors'])) {
foreach ( $result['errors'] as $error ) { foreach ($result['errors'] as $error) {
$arr_errors = ITSEC_Response::get_error_strings( $error ); $arr_errors = ITSEC_Response::get_error_strings( $error );
foreach ( $arr_errors as $er ) { foreach ( $arr_errors as $er ) {
$str_error .= $er . '<br />'; $str_error .= $er . '<br />';
@ -899,7 +899,7 @@ class MainWP_Child_iThemes_Security {
if ( false === $result['new_prefix'] ) { if ( false === $result['new_prefix'] ) {
$return['error'] = $str_error; $return['error'] = $str_error;
} else { } else {
$return['result'] = 'success'; $return['result'] = 'success';
$return['message'] = sprintf( __( 'The database table prefix was successfully changed to <code>%1$s</code>.', 'better-wp-security' ), $result['new_prefix'] ); $return['message'] = sprintf( __( 'The database table prefix was successfully changed to <code>%1$s</code>.', 'better-wp-security' ), $result['new_prefix'] );
} }
@ -913,7 +913,7 @@ class MainWP_Child_iThemes_Security {
$settings = array(); $settings = array();
} }
$settings['reset'] = true; $settings['reset'] = true;
$return = array(); $return = array();
if ( update_site_option( 'itsec_ipcheck', $settings ) ) { if ( update_site_option( 'itsec_ipcheck', $settings ) ) {
$return['result'] = 'success'; $return['result'] = 'success';
} else { } else {
@ -926,7 +926,7 @@ class MainWP_Child_iThemes_Security {
public function reset_api_key() { public function reset_api_key() {
$defaults = ITSEC_Modules::get_defaults( 'network-brute-force' ); $defaults = ITSEC_Modules::get_defaults( 'network-brute-force' );
$results = ITSEC_Modules::set_settings( 'network-brute-force', $defaults ); $results = ITSEC_Modules::set_settings( 'network-brute-force', $defaults );
ITSEC_Response::set_response( $results['saved'] ); ITSEC_Response::set_response( $results['saved'] );
ITSEC_Response::add_errors( $results['errors'] ); ITSEC_Response::add_errors( $results['errors'] );
@ -934,9 +934,9 @@ class MainWP_Child_iThemes_Security {
$information = array(); $information = array();
if ( $results['saved'] ) { if ( $results['saved'] ) {
$information['result'] = 'success'; $information['result'] = 'success';
$information['nbf_settings'] = ITSEC_Modules::get_settings( 'network-brute-force'); $information['nbf_settings'] = ITSEC_Modules::get_settings( 'network-brute-force');
} elseif ( empty( $results['errors'] ) ) { } else if ( empty( $results['errors'] ) ) {
$information['error_reset_api'] = 1; $information['error_reset_api'] = 1;
} }
return $information; return $information;
@ -946,15 +946,15 @@ class MainWP_Child_iThemes_Security {
global $mainwp_itsec_modules_path; global $mainwp_itsec_modules_path;
if ( ! class_exists( 'ITSEC_Malware_Scanner' ) ) { if ( ! class_exists( 'ITSEC_Malware_Scanner' ) ) {
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scanner.php'; require_once( $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scanner.php' );
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scan-results-template.php'; require_once( $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scan-results-template.php' );
} }
$response = array(); $response = array();
if ( ! ITSEC_Core::current_user_can_manage() ) { if ( ! ITSEC_Core::current_user_can_manage() ) {
$response['error'] = 'The currently logged in user does not have sufficient permissions to run this scan.'; $response['error'] = 'The currently logged in user does not have sufficient permissions to run this scan.';
} else { } else {
$results = ITSEC_Malware_Scanner::scan(); $results = ITSEC_Malware_Scanner::scan();
$response['html'] = ITSEC_Malware_Scan_Results_Template::get_html( $results, true ); $response['html'] = ITSEC_Malware_Scan_Results_Template::get_html( $results, true );
} }
@ -965,11 +965,11 @@ class MainWP_Child_iThemes_Security {
global $mainwp_itsec_modules_path; global $mainwp_itsec_modules_path;
if ( ! class_exists( 'ITSEC_Malware_Scanner' ) ) { if ( ! class_exists( 'ITSEC_Malware_Scanner' ) ) {
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scanner.php'; require_once( $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scanner.php' );
require_once $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scan-results-template.php'; require_once( $mainwp_itsec_modules_path . 'malware/class-itsec-malware-scan-results-template.php' );
} }
$response = array(); $response = array();
$results = ITSEC_Malware_Scanner::scan(); $results= ITSEC_Malware_Scanner::scan();
$response['html'] = ITSEC_Malware_Scan_Results_Template::get_html( $results, true ); $response['html'] = ITSEC_Malware_Scan_Results_Template::get_html( $results, true );
return $response; return $response;
} }
@ -1068,7 +1068,7 @@ class MainWP_Child_iThemes_Security {
global $wpdb; global $wpdb;
if ( ! class_exists( 'ITSEC_Lib' ) ) { if ( ! class_exists( 'ITSEC_Lib' ) ) {
require ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php'; require( ITSEC_Core::get_core_dir() . '/core/class-itsec-lib.php' );
} }
$lockout_ids = $_POST['lockout_ids']; $lockout_ids = $_POST['lockout_ids'];
@ -1095,7 +1095,7 @@ class MainWP_Child_iThemes_Security {
if ( ! is_multisite() ) { if ( ! is_multisite() ) {
if ( ! function_exists( 'add_settings_error' ) ) { if ( ! function_exists( 'add_settings_error' ) ) {
require_once ABSPATH . '/wp-admin/includes/template.php'; require_once( ABSPATH . '/wp-admin/includes/template.php' );
} }
add_settings_error( 'itsec', esc_attr( 'settings_updated' ), $message, $type ); add_settings_error( 'itsec', esc_attr( 'settings_updated' ), $message, $type );
@ -1110,30 +1110,30 @@ class MainWP_Child_iThemes_Security {
$active_modules = $_POST['active_modules']; $active_modules = $_POST['active_modules'];
if ( ! is_array($active_modules) ) { if (!is_array($active_modules))
$active_modules = array(); $active_modules = array();
}
$current_val = get_site_option( 'itsec_active_modules', array() ); $current_val = get_site_option( 'itsec_active_modules', array() );
foreach ( $active_modules as $mod => $val ) { foreach ($active_modules as $mod => $val) {
$current_val[ $mod ] = $val; $current_val[$mod] = $val;
} }
update_site_option( 'itsec_active_modules', $current_val ); update_site_option( 'itsec_active_modules', $current_val );
return array( 'result' => 'success' ); return array('result' => 'success');
} }
private function reload_backup_exclude() { private function reload_backup_exclude( ) {
return array( return array(
'exclude' => ITSEC_Modules::get_setting( 'backup', 'exclude' ), 'exclude' => ITSEC_Modules::get_setting( 'backup', 'exclude' ),
'excludable_tables' => $this->get_excludable_tables(), 'excludable_tables' => $this->get_excludable_tables(),
'result' => 'success', 'result' => 'success'
); );
} }
private function get_excludable_tables() { private function get_excludable_tables( ) {
global $wpdb; global $wpdb;
$all_sites = ITSEC_Modules::get_setting( 'backup', 'all_sites' ); $all_sites = ITSEC_Modules::get_setting( 'backup', 'all_sites' );
$ignored_tables = array( $ignored_tables = array(
'commentmeta', 'commentmeta',
'comments', 'comments',
@ -1154,7 +1154,7 @@ class MainWP_Child_iThemes_Security {
$query = $wpdb->prepare( 'SHOW TABLES LIKE %s', "{$wpdb->base_prefix}%" ); $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', "{$wpdb->base_prefix}%" );
} }
$tables = $wpdb->get_results( $query, ARRAY_N ); $tables = $wpdb->get_results( $query, ARRAY_N );
$excludes = array(); $excludes = array();
foreach ( $tables as $table ) { foreach ( $tables as $table ) {
@ -1164,24 +1164,21 @@ class MainWP_Child_iThemes_Security {
continue; continue;
} }
$excludes[ $short_table ] = $table[0]; $excludes[$short_table] = $table[0];
} }
return $excludes; return $excludes ;
} }
private function security_site() { private function security_site() {
global $mainwp_itsec_modules_path; global $mainwp_itsec_modules_path;
require_once $mainwp_itsec_modules_path . 'security-check/scanner.php'; require_once( $mainwp_itsec_modules_path . 'security-check/scanner.php' );
require_once $mainwp_itsec_modules_path . 'security-check/feedback-renderer.php'; require_once( $mainwp_itsec_modules_path . 'security-check/feedback-renderer.php' );
$results = ITSEC_Security_Check_Scanner::get_results(); $results = ITSEC_Security_Check_Scanner::get_results();
ob_start(); ob_start();
ITSEC_Security_Check_Feedback_Renderer::render( $results ); ITSEC_Security_Check_Feedback_Renderer::render( $results );
$response = ob_get_clean(); $response = ob_get_clean();
return array( return array('result' => 'success' , 'response' => $response);
'result' => 'success',
'response' => $response,
);
} }
// source from itheme plugin // source from itheme plugin
@ -1198,7 +1195,7 @@ class MainWP_Child_iThemes_Security {
foreach ( $roles->roles as $role => $details ) { foreach ( $roles->roles as $role => $details ) {
if ( isset( $details['capabilities']['manage_options'] ) && ( true === $details['capabilities']['manage_options'] ) ) { if ( isset( $details['capabilities']['manage_options'] ) && ( true === $details['capabilities']['manage_options'] ) ) {
$available_roles[ "role:$role" ] = translate_user_role( $details['name'] ); $available_roles["role:$role"] = translate_user_role( $details['name'] );
$users = get_users( array( 'role' => $role ) ); $users = get_users( array( 'role' => $role ) );

View file

@ -15,28 +15,28 @@
class MainWP_Child_Links_Checker { class MainWP_Child_Links_Checker {
public static $instance = null; public static $instance = null;
public $is_plugin_installed = false; public $is_plugin_installed = false;
static function Instance() { static function Instance() {
if ( null === self::$instance ) { if ( null === MainWP_Child_Links_Checker::$instance ) {
self::$instance = new MainWP_Child_Links_Checker(); MainWP_Child_Links_Checker::$instance = new MainWP_Child_Links_Checker();
} }
return self::$instance; return MainWP_Child_Links_Checker::$instance;
} }
public function __construct() { public function __construct() {
require_once ABSPATH . 'wp-admin/includes/plugin.php'; require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( is_plugin_active( 'broken-link-checker/broken-link-checker.php' ) ) { if ( is_plugin_active( 'broken-link-checker/broken-link-checker.php' ) ) {
$this->is_plugin_installed = true; $this->is_plugin_installed = true;
} }
if ( ! $this->is_plugin_installed ) { if ( !$this->is_plugin_installed )
return; return;
}
add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 );
} }
public function action() { public function action() {
@ -82,8 +82,8 @@ class MainWP_Child_Links_Checker {
} }
} }
MainWP_Helper::write( $information ); MainWP_Helper::write( $information );
} catch ( Exception $e ) { } catch(Exception $e) {
MainWP_Helper::write( array( 'error' => $e->getMessage() ) ); MainWP_Helper::write( array('error' => $e->getMessage()) );
} }
} }
@ -114,8 +114,8 @@ class MainWP_Child_Links_Checker {
} }
function save_settings() { function save_settings() {
$information = array(); $information = array();
$check_threshold = intval( $_POST['check_threshold'] ); $check_threshold = intval( $_POST['check_threshold'] );
if ( $check_threshold > 0 ) { if ( $check_threshold > 0 ) {
$conf = blc_get_configuration(); $conf = blc_get_configuration();
$conf->options['check_threshold'] = $check_threshold; $conf->options['check_threshold'] = $check_threshold;
@ -137,13 +137,13 @@ class MainWP_Child_Links_Checker {
global $wpdb; global $wpdb;
/** @var wpdb $wpdb */ /** @var wpdb $wpdb */
// Delete all discovered instances //Delete all discovered instances
$wpdb->query( "TRUNCATE {$wpdb->prefix}blc_instances" ); $wpdb->query( "TRUNCATE {$wpdb->prefix}blc_instances" );
// Delete all discovered links //Delete all discovered links
$wpdb->query( "TRUNCATE {$wpdb->prefix}blc_links" ); $wpdb->query( "TRUNCATE {$wpdb->prefix}blc_links" );
// Mark all posts, custom fields and bookmarks for processing. //Mark all posts, custom fields and bookmarks for processing.
blc_resynch( true ); blc_resynch( true );
} }
@ -158,18 +158,18 @@ class MainWP_Child_Links_Checker {
} }
blc_init(); blc_init();
// Get the container type matching the type of the deleted post //Get the container type matching the type of the deleted post
$post = get_post( $post_id ); $post = get_post( $post_id );
if ( ! $post ) { if ( ! $post ) {
return; return;
} }
// Get the associated container object //Get the associated container object
$post_container = blcContainerHelper::get_container( array( $post->post_type, intval( $post_id ) ) ); $post_container = blcContainerHelper::get_container( array( $post->post_type, intval( $post_id ) ) );
if ( $post_container ) { if ( $post_container ) {
// Delete it //Delete it
$post_container->delete(); $post_container->delete();
// Clean up any dangling links //Clean up any dangling links
blc_cleanup_links(); blc_cleanup_links();
} }
} }
@ -210,9 +210,9 @@ class MainWP_Child_Links_Checker {
// ok // ok
public function syncOthersData( $information, $data = array() ) { public function syncOthersData( $information, $data = array() ) {
if ( isset( $data['syncBrokenLinksCheckerData'] ) && $data['syncBrokenLinksCheckerData'] ) { if ( isset( $data['syncBrokenLinksCheckerData'] ) && $data['syncBrokenLinksCheckerData'] ) {
try { try{
$information['syncBrokenLinksCheckerData'] = $this->get_sync_data(); $information['syncBrokenLinksCheckerData'] = $this->get_sync_data();
} catch ( Exception $e ) { } catch(Exception $e) {
} }
} }
@ -223,17 +223,14 @@ class MainWP_Child_Links_Checker {
function get_sync_data( $strategy = '' ) { function get_sync_data( $strategy = '' ) {
$information = array(); $information = array();
$data = $this->get_count_links(); $data = $this->get_count_links();
if ( is_array($data) ) { if (is_array($data))
$information['data'] = $data; $information['data'] = $data;
}
return $information; return $information;
} }
function get_links_data() { function get_links_data() {
if ( ! defined('BLC_DIRECTORY') ) { if (!defined('BLC_DIRECTORY')) return;
return;
}
$file_path1 = BLC_DIRECTORY . '/includes/link-query.php'; $file_path1 = BLC_DIRECTORY . '/includes/link-query.php';
$file_path2 = BLC_DIRECTORY . '/includes/modules.php'; $file_path2 = BLC_DIRECTORY . '/includes/modules.php';
@ -245,21 +242,22 @@ class MainWP_Child_Links_Checker {
MainWP_Helper::check_classes_exists('blcLinkQuery'); MainWP_Helper::check_classes_exists('blcLinkQuery');
MainWP_Helper::check_methods('blcLinkQuery', 'getInstance'); MainWP_Helper::check_methods('blcLinkQuery', 'getInstance');
$blc_link_query = blcLinkQuery::getInstance(); $blc_link_query = blcLinkQuery::getInstance();
MainWP_Helper::check_methods($blc_link_query, 'get_filter_links'); MainWP_Helper::check_methods($blc_link_query, 'get_filter_links');
$total = $blc_link_query->get_filter_links( 'all', array( 'count_only' => true ) ); $total = $blc_link_query->get_filter_links( 'all', array( 'count_only' => true ) );
$max_results = isset($_POST['max_results']) ? intval($_POST['max_results']) : 50; $max_results = isset($_POST['max_results']) ? intval($_POST['max_results']) : 50;
$offset = isset($_POST['offset']) ? intval($_POST['offset']) : 0; $offset = isset($_POST['offset']) ? intval($_POST['offset']) : 0;
$params = array( $params = array(
array( 'load_instances' => true ), array( 'load_instances' => true ),
'max_results' => $max_results, 'max_results' => $max_results
); );
if ( empty($offset) ) { if (empty($offset)) {
$first_sync = true; $first_sync = true;
} else { } else {
$params['offset'] = $offset; $params['offset'] = $offset;
@ -268,23 +266,23 @@ class MainWP_Child_Links_Checker {
$link_data = $this->links_checker_data($params); $link_data = $this->links_checker_data($params);
$total_sync = 0; $total_sync = 0;
if ( $offset ) { if ($offset){
$total_sync = $offset; $total_sync = $offset;
} }
$total_sync += ( is_array($link_data) ? count($link_data) : 0 ); $total_sync += (is_array($link_data) ? count($link_data) : 0);
$information = array( 'links_data' => $link_data ); $information = array('links_data' => $link_data);
if ( $first_sync ) { if ($first_sync) {
$information['data'] = $this->get_count_links(); $information['data'] = $this->get_count_links();
} }
if ( $total > $offset + $max_results ) { if ($total > $offset + $max_results ) {
$information['sync_offset'] = $offset + $max_results; $information['sync_offset'] = $offset + $max_results;
} else { } else {
$information['last_sync'] = 1; $information['last_sync'] = 1;
$information['total_sync'] = $total_sync; $information['total_sync'] = $total_sync;
$information['data'] = $this->get_count_links(); $information['data'] = $this->get_count_links();
} }
$information['result'] = 'success'; $information['result'] = 'success';
@ -292,9 +290,7 @@ class MainWP_Child_Links_Checker {
} }
function get_count_links() { function get_count_links() {
if ( ! defined('BLC_DIRECTORY') ) { if (!defined('BLC_DIRECTORY')) return;
return;
}
$file_path1 = BLC_DIRECTORY . '/includes/link-query.php'; $file_path1 = BLC_DIRECTORY . '/includes/link-query.php';
$file_path2 = BLC_DIRECTORY . '/includes/modules.php'; $file_path2 = BLC_DIRECTORY . '/includes/modules.php';
@ -307,25 +303,25 @@ class MainWP_Child_Links_Checker {
MainWP_Helper::check_classes_exists('blcLinkQuery'); MainWP_Helper::check_classes_exists('blcLinkQuery');
MainWP_Helper::check_methods('blcLinkQuery', 'getInstance'); MainWP_Helper::check_methods('blcLinkQuery', 'getInstance');
$data = array(); $data = array();
$blc_link_query = blcLinkQuery::getInstance(); $blc_link_query = blcLinkQuery::getInstance();
MainWP_Helper::check_methods($blc_link_query, 'get_filter_links'); MainWP_Helper::check_methods($blc_link_query, 'get_filter_links');
$data['broken'] = $blc_link_query->get_filter_links( 'broken', array( 'count_only' => true ) ); $data['broken'] = $blc_link_query->get_filter_links( 'broken', array( 'count_only' => true ) );
$data['redirects'] = $blc_link_query->get_filter_links( 'redirects', array( 'count_only' => true ) ); $data['redirects'] = $blc_link_query->get_filter_links( 'redirects', array( 'count_only' => true ) );
$data['dismissed'] = $blc_link_query->get_filter_links( 'dismissed', array( 'count_only' => true ) ); $data['dismissed'] = $blc_link_query->get_filter_links( 'dismissed', array( 'count_only' => true ) );
$data['warning'] = $blc_link_query->get_filter_links( 'warning', array( 'count_only' => true ) ); $data['warning'] = $blc_link_query->get_filter_links( 'warning', array( 'count_only' => true ) );
$data['all'] = $blc_link_query->get_filter_links( 'all', array( 'count_only' => true ) ); $data['all'] = $blc_link_query->get_filter_links( 'all', array( 'count_only' => true ) );
return $data; return $data;
} }
function links_checker_data( $params ) { function links_checker_data($params) {
MainWP_Helper::check_functions('blc_get_links'); MainWP_Helper::check_functions('blc_get_links');
MainWP_Helper::check_classes_exists('blcLink'); MainWP_Helper::check_classes_exists('blcLink');
$links = blc_get_links( $params ); $links = blc_get_links( $params );
$filter_fields = array( $filter_fields = array(
'link_id', 'link_id',
@ -345,13 +341,13 @@ class MainWP_Child_Links_Checker {
'last_success', 'last_success',
'may_recheck', 'may_recheck',
'false_positive', 'false_positive',
// 'result_hash', //'result_hash',
'dismissed', 'dismissed',
'status_text', 'status_text',
'status_code', 'status_code',
'log', 'log'
); );
$return = array(); $return = array();
$blc_option = get_option( 'wsblc_options' ); $blc_option = get_option( 'wsblc_options' );
@ -374,7 +370,7 @@ class MainWP_Child_Links_Checker {
$days_broken = 0; $days_broken = 0;
if ( $link->broken ) { if ( $link->broken ) {
// Add a highlight to broken links that appear to be permanently broken //Add a highlight to broken links that appear to be permanently broken
$days_broken = intval( ( time() - $link->first_failure ) / ( 3600 * 24 ) ); $days_broken = intval( ( time() - $link->first_failure ) / ( 3600 * 24 ) );
if ( $days_broken >= $blc_option['failure_duration_threshold'] ) { if ( $days_broken >= $blc_option['failure_duration_threshold'] ) {
$extra_info['permanently_broken'] = 1; $extra_info['permanently_broken'] = 1;
@ -384,7 +380,7 @@ class MainWP_Child_Links_Checker {
} }
} }
$extra_info['days_broken'] = $days_broken; $extra_info['days_broken'] = $days_broken;
$instances = false; $instances = false;
$get_link = new blcLink( intval( $link->link_id ) ); $get_link = new blcLink( intval( $link->link_id ) );
if ( $get_link->valid() ) { if ( $get_link->valid() ) {
@ -393,22 +389,22 @@ class MainWP_Child_Links_Checker {
} }
if ( ! empty( $instances ) ) { if ( ! empty( $instances ) ) {
$first_instance = reset( $instances ); $first_instance = reset( $instances );
MainWP_Helper::check_methods($first_instance, array( 'ui_get_link_text', 'get_container', 'is_link_text_editable', 'is_url_editable' ) ); MainWP_Helper::check_methods($first_instance, array( 'ui_get_link_text', 'get_container', 'is_link_text_editable', 'is_url_editable') );
$new_link->link_text = $first_instance->ui_get_link_text(); $new_link->link_text = $first_instance->ui_get_link_text();
$extra_info['count_instance'] = count( $instances ); $extra_info['count_instance'] = count( $instances );
$container = $first_instance->get_container(); $container = $first_instance->get_container();
/** @var blcContainer $container */ /** @var blcContainer $container */
if ( ! empty( $container ) /* && ($container instanceof blcAnyPostContainer) */ ) { if ( ! empty( $container ) /* && ($container instanceof blcAnyPostContainer) */ ) {
if ( true === MainWP_Helper::check_properties($first_instance, array( 'container_field' ), true ) ) { if (true === MainWP_Helper::check_properties($first_instance, array( 'container_field' ), true )) {
if ( true === MainWP_Helper::check_properties($container, array( 'container_type', 'container_id' ), true ) ) { if (true === MainWP_Helper::check_properties($container, array( 'container_type', 'container_id' ), true )) {
$extra_info['container_type'] = $container->container_type; $extra_info['container_type'] = $container->container_type;
$extra_info['container_id'] = $container->container_id; $extra_info['container_id'] = $container->container_id;
$extra_info['source_data'] = $this->ui_get_source( $container, $first_instance->container_field ); $extra_info['source_data'] = $this->ui_get_source( $container, $first_instance->container_field );
} }
} }
} }
@ -433,26 +429,27 @@ class MainWP_Child_Links_Checker {
$link_texts = $can_edit_text ? $editable_link_texts : $non_editable_link_texts; $link_texts = $can_edit_text ? $editable_link_texts : $non_editable_link_texts;
$data_link_text = ''; $data_link_text = '';
if ( count( $link_texts ) === 1 ) { if ( count( $link_texts ) === 1 ) {
// All instances have the same text - use it. //All instances have the same text - use it.
$link_text = key( $link_texts ); $link_text = key( $link_texts );
$data_link_text = esc_attr( $link_text ); $data_link_text = esc_attr( $link_text );
} }
$extra_info['data_link_text'] = $data_link_text; $extra_info['data_link_text'] = $data_link_text;
$extra_info['can_edit_url'] = $can_edit_url; $extra_info['can_edit_url'] = $can_edit_url;
$extra_info['can_edit_text'] = $can_edit_text; $extra_info['can_edit_text'] = $can_edit_text;
} else { } else {
$new_link->link_text = ''; $new_link->link_text = '';
$extra_info['count_instance'] = 0; $extra_info['count_instance'] = 0;
} }
$new_link->extra_info = base64_encode(serialize($extra_info)); $new_link->extra_info = base64_encode(serialize($extra_info));
$new_link->synced = 1; $new_link->synced = 1;
$return[] = $new_link; $return[] = $new_link;
} }
} else { } else {
return array(); return array();
} }
return $return; return $return;
} }
function edit_link() { function edit_link() {
@ -462,14 +459,14 @@ class MainWP_Child_Links_Checker {
return $information; return $information;
} }
// Load the link //Load the link
$link = new blcLink( intval( $_POST['link_id'] ) ); $link = new blcLink( intval( $_POST['link_id'] ) );
if ( ! $link->valid() ) { if ( ! $link->valid() ) {
$information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link $information['error'] = 'NOTFOUNDLINK'; // Oops, I can't find the link
return $information; return $information;
} }
// Validate the new URL. //Validate the new URL.
$new_url = stripslashes( $_POST['new_url'] ); $new_url = stripslashes( $_POST['new_url'] );
$parsed = @parse_url( $new_url ); $parsed = @parse_url( $new_url );
if ( ! $parsed ) { if ( ! $parsed ) {
@ -482,7 +479,7 @@ class MainWP_Child_Links_Checker {
$new_text = null; $new_text = null;
} }
if ( ! empty( $new_text ) && ! current_user_can( 'unfiltered_html' ) ) { if ( ! empty( $new_text ) && ! current_user_can( 'unfiltered_html' ) ) {
$new_text = stripslashes( wp_filter_post_kses( addslashes( $new_text ) ) ); // wp_filter_post_kses expects slashed data. $new_text = stripslashes( wp_filter_post_kses( addslashes( $new_text ) ) ); //wp_filter_post_kses expects slashed data.
} }
$rez = $link->edit( $new_url, $new_text ); $rez = $link->edit( $new_url, $new_text );
@ -515,7 +512,7 @@ class MainWP_Child_Links_Checker {
'ui_link_text' => isset( $new_text ) ? $ui_link_text : null, 'ui_link_text' => isset( $new_text ) ? $ui_link_text : null,
'errors' => array(), 'errors' => array(),
); );
// url, status text, status code, link text, editable link text //url, status text, status code, link text, editable link text
foreach ( $rez['errors'] as $error ) { foreach ( $rez['errors'] as $error ) {
/** @var $error WP_Error */ /** @var $error WP_Error */
@ -535,7 +532,7 @@ class MainWP_Child_Links_Checker {
} }
if ( isset( $_POST['link_id'] ) ) { if ( isset( $_POST['link_id'] ) ) {
// Load the link //Load the link
$link = new blcLink( intval( $_POST['link_id'] ) ); $link = new blcLink( intval( $_POST['link_id'] ) );
if ( ! $link->valid() ) { if ( ! $link->valid() ) {
@ -543,7 +540,7 @@ class MainWP_Child_Links_Checker {
return $information; return $information;
} }
// Try and unlink it //Try and unlink it
$rez = $link->unlink(); $rez = $link->unlink();
if ( false === $rez ) { if ( false === $rez ) {
@ -580,7 +577,7 @@ class MainWP_Child_Links_Checker {
} }
if ( isset( $_POST['link_id'] ) ) { if ( isset( $_POST['link_id'] ) ) {
// Load the link //Load the link
$link = new blcLink( intval( $_POST['link_id'] ) ); $link = new blcLink( intval( $_POST['link_id'] ) );
if ( ! $link->valid() ) { if ( ! $link->valid() ) {
@ -590,7 +587,7 @@ class MainWP_Child_Links_Checker {
$link->dismissed = $dismiss; $link->dismissed = $dismiss;
// Save the changes //Save the changes
if ( $link->save() ) { if ( $link->save() ) {
$information = 'OK'; $information = 'OK';
} else { } else {
@ -613,7 +610,7 @@ class MainWP_Child_Links_Checker {
return $information; return $information;
} }
if ( isset( $_POST['link_id'] ) ) { if ( isset( $_POST['link_id'] ) ) {
// Load the link //Load the link
$link = new blcLink( intval( $_POST['link_id'] ) ); $link = new blcLink( intval( $_POST['link_id'] ) );
if ( ! $link->valid() ) { if ( ! $link->valid() ) {
@ -621,13 +618,13 @@ class MainWP_Child_Links_Checker {
return $information; return $information;
} }
// Make it appear "not broken" //Make it appear "not broken"
$link->broken = false; $link->broken = false;
$link->false_positive = true; $link->false_positive = true;
$link->last_check_attempt = time(); $link->last_check_attempt = time();
$link->log = __( 'This link was manually marked as working by the user.', 'mainwp-child' ); $link->log = __( 'This link was manually marked as working by the user.', 'mainwp-child' );
// Save the changes //Save the changes
if ( $link->save() ) { if ( $link->save() ) {
$information['status'] = 'OK'; $information['status'] = 'OK';
$information['last_check_attempt'] = $link->last_check_attempt; $information['last_check_attempt'] = $link->last_check_attempt;
@ -644,7 +641,7 @@ class MainWP_Child_Links_Checker {
function ui_get_source( $container, $container_field = '' ) { function ui_get_source( $container, $container_field = '' ) {
if ( 'comment' === $container->container_type ) { if ( 'comment' === $container->container_type ) {
return $this->ui_get_source_comment( $container, $container_field ); return $this->ui_get_source_comment( $container, $container_field );
} elseif ( $container instanceof blcAnyPostContainer ) { } else if ( $container instanceof blcAnyPostContainer ) {
return $this->ui_get_source_post( $container, $container_field ); return $this->ui_get_source_post( $container, $container_field );
} }
@ -652,20 +649,19 @@ class MainWP_Child_Links_Checker {
} }
function ui_get_source_comment( $container, $container_field = '' ) { function ui_get_source_comment( $container, $container_field = '' ) {
// Display a comment icon. //Display a comment icon.
if ( 'comment_author_url' === $container_field ) { if ( 'comment_author_url' === $container_field ) {
$image = 'font-awesome/font-awesome-user.png'; $image = 'font-awesome/font-awesome-user.png';
} else { } else {
$image = 'font-awesome/font-awesome-comment-alt.png'; $image = 'font-awesome/font-awesome-comment-alt.png';
} }
if ( true !== MainWP_Helper::check_methods($container, array( 'get_wrapped_object' ), true ) ) { if (true !== MainWP_Helper::check_methods($container, array( 'get_wrapped_object'), true ))
return false; return false;
}
$comment = $container->get_wrapped_object(); $comment = $container->get_wrapped_object();
// Display a small text sample from the comment //Display a small text sample from the comment
$text_sample = strip_tags( $comment->comment_content ); $text_sample = strip_tags( $comment->comment_content );
$text_sample = blcUtility::truncate( $text_sample, 65 ); $text_sample = blcUtility::truncate( $text_sample, 65 );
@ -684,7 +680,7 @@ class MainWP_Child_Links_Checker {
function ui_get_source_post( $container, $container_field = '' ) { function ui_get_source_post( $container, $container_field = '' ) {
return array( return array(
'post_title' => get_the_title( $container->container_id ), 'post_title' => get_the_title( $container->container_id ),
'post_status' => get_post_status($container->container_id), 'post_status' => get_post_status($container->container_id),
'container_anypost' => true, 'container_anypost' => true,
); );
} }

View file

@ -17,26 +17,25 @@
class MainWP_Child_Pagespeed { class MainWP_Child_Pagespeed {
public static $instance = null; public static $instance = null;
public $is_plugin_installed = false; public $is_plugin_installed = false;
static function Instance() { static function Instance() {
if ( null === self::$instance ) { if ( null === MainWP_Child_Pagespeed::$instance ) {
self::$instance = new MainWP_Child_Pagespeed(); MainWP_Child_Pagespeed::$instance = new MainWP_Child_Pagespeed();
} }
return self::$instance; return MainWP_Child_Pagespeed::$instance;
} }
public function __construct() { public function __construct() {
require_once ABSPATH . 'wp-admin/includes/plugin.php'; require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( is_plugin_active( 'google-pagespeed-insights/google-pagespeed-insights.php' ) ) { if ( is_plugin_active( 'google-pagespeed-insights/google-pagespeed-insights.php' ) ) {
$this->is_plugin_installed = true; $this->is_plugin_installed = true;
} }
if ( ! $this->is_plugin_installed ) { if (!$this->is_plugin_installed)
return; return;
}
add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 );
@ -61,7 +60,7 @@ class MainWP_Child_Pagespeed {
case 'sync_data': case 'sync_data':
$information = $this->get_sync_data(); $information = $this->get_sync_data();
break; break;
case 'check_pages': case "check_pages":
$information = $this->check_pages(); $information = $this->check_pages();
break; break;
} }
@ -76,13 +75,12 @@ class MainWP_Child_Pagespeed {
} }
public function init() { public function init() {
if ( ! $this->is_plugin_installed ) { if (!$this->is_plugin_installed)
return; return;
}
if ( get_option( 'mainwp_pagespeed_hide_plugin' ) === 'hide' ) { if ( get_option( 'mainwp_pagespeed_hide_plugin' ) === 'hide' ) {
add_filter( 'all_plugins', array( $this, 'hide_plugin' ) ); add_filter( 'all_plugins', array( $this, 'hide_plugin' ) );
add_action('admin_menu', array( $this, 'hide_menu' ), 999); add_action('admin_menu', array($this, 'hide_menu'), 999);
} }
$this->init_cron(); $this->init_cron();
} }
@ -127,10 +125,10 @@ class MainWP_Child_Pagespeed {
public function hide_menu() { public function hide_menu() {
global $submenu; global $submenu;
if ( isset($submenu['tools.php']) ) { if (isset($submenu['tools.php'])) {
foreach ( $submenu['tools.php'] as $key => $menu ) { foreach($submenu['tools.php'] as $key => $menu) {
if ( $menu[2] == 'google-pagespeed-insights' ) { if ($menu[2] == 'google-pagespeed-insights') {
unset($submenu['tools.php'][ $key ]); unset($submenu['tools.php'][$key]);
break; break;
} }
} }
@ -159,7 +157,7 @@ class MainWP_Child_Pagespeed {
function save_settings() { function save_settings() {
$current_values = get_option( 'gpagespeedi_options' ); $current_values = get_option( 'gpagespeedi_options' );
$checkstatus = apply_filters( 'gpi_check_status', false ); $checkstatus = apply_filters( 'gpi_check_status', false );
if ( $checkstatus ) { if ( $checkstatus ) {
return array( 'result' => 'RUNNING' ); return array( 'result' => 'RUNNING' );
} }
@ -216,9 +214,9 @@ class MainWP_Child_Pagespeed {
if ( isset( $settings['check_report'] ) ) { if ( isset( $settings['check_report'] ) ) {
if ( is_array( $settings['check_report'] ) ) { if ( is_array( $settings['check_report'] ) ) {
$current_values['check_pages'] = in_array( 'page', $settings['check_report'] ) ? true : false; $current_values['check_pages'] = in_array( 'page', $settings['check_report'] ) ? true : false;
$current_values['check_posts'] = in_array( 'post', $settings['check_report'] ) ? true : false; $current_values['check_posts'] = in_array( 'post', $settings['check_report'] ) ? true : false;
$current_values['check_categories'] = in_array( 'category', $settings['check_report'] ) ? true : false; $current_values['check_categories'] = in_array( 'category', $settings['check_report'] ) ? true : false;
$current_values['check_custom_urls'] = in_array( 'custom_urls', $settings['check_report'] ) ? true : false; $current_values['check_custom_urls'] = in_array( 'custom_urls', $settings['check_report'] ) ? true : false;
} else { } else {
$current_values['check_pages'] = $current_values['check_posts'] = $current_values['check_categories'] = $current_values['check_custom_urls'] = false; $current_values['check_pages'] = $current_values['check_posts'] = $current_values['check_categories'] = $current_values['check_custom_urls'] = false;
@ -240,43 +238,43 @@ class MainWP_Child_Pagespeed {
$result = $this->get_sync_data( $strategy ); $result = $this->get_sync_data( $strategy );
// if ( isset( $_POST['doaction'] ) && ( 'check_new_pages' === $_POST['doaction'] || 'recheck_all_pages' === $_POST['doaction'] ) ) { // if ( isset( $_POST['doaction'] ) && ( 'check_new_pages' === $_POST['doaction'] || 'recheck_all_pages' === $_POST['doaction'] ) ) {
// if ( 'recheck_all_pages' === $_POST['doaction'] ) { // if ( 'recheck_all_pages' === $_POST['doaction'] ) {
// $recheck = true; // $recheck = true;
// } else { // } else {
// $recheck = false; // $recheck = false;
// } // }
// //
// //
// if ($this->do_check_pages($recheck)) // if ($this->do_check_pages($recheck))
// $information['checked_pages'] = 1; // $information['checked_pages'] = 1;
// } // }
$information['data'] = $result['data']; $information['data'] = $result['data'];
return $information; return $information;
} }
function check_pages() { function check_pages() {
if ( isset($_POST['force_recheck']) && ! empty($_POST['force_recheck']) ) { if (isset($_POST['force_recheck']) && !empty($_POST['force_recheck'])) {
$recheck = true; $recheck = true;
} else { } else {
$recheck = false; $recheck = false;
} }
$information = $this->do_check_pages($recheck); $information = $this->do_check_pages($recheck);
if ( isset($information['checked_pages']) && $information['checked_pages'] ) { if (isset($information['checked_pages']) && $information['checked_pages']) {
$information['result'] = 'SUCCESS'; $information['result'] = 'SUCCESS';
} }
return $information; return $information;
} }
function do_check_pages( $forceRecheck = false ) { function do_check_pages($forceRecheck = false) {
$information = array(); $information = array();
if ( defined( 'GPI_DIRECTORY' ) ) { if ( defined( 'GPI_DIRECTORY' ) ) {
$checkstatus = apply_filters( 'gpi_check_status', false ); $checkstatus = apply_filters( 'gpi_check_status', false );
if ( $checkstatus ) { if ( $checkstatus ) {
$information['error'] = __( 'The API is busy checking other pages, please try again later.', 'gpagespeedi' ); $information['error'] = __( 'The API is busy checking other pages, please try again later.', 'gpagespeedi' );
} else { } else {
// do_action( 'googlepagespeedinsightsworker', array(), $forceRecheck ); //do_action( 'googlepagespeedinsightsworker', array(), $forceRecheck );
do_action( 'run_gpi', $forceRecheck ); // to fix do_action( 'run_gpi', $forceRecheck ); // to fix
$information['checked_pages'] = 1; $information['checked_pages'] = 1;
} }
@ -286,9 +284,9 @@ class MainWP_Child_Pagespeed {
public function syncOthersData( $information, $data = array() ) { public function syncOthersData( $information, $data = array() ) {
if ( isset( $data['syncPageSpeedData'] ) && $data['syncPageSpeedData'] ) { if ( isset( $data['syncPageSpeedData'] ) && $data['syncPageSpeedData'] ) {
try { try{
$information['syncPageSpeedData'] = $this->get_sync_data(); $information['syncPageSpeedData'] = $this->get_sync_data();
} catch ( Exception $e ) { } catch(Exception $e) {
} }
} }
@ -301,7 +299,7 @@ class MainWP_Child_Pagespeed {
} }
$current_values = get_option( 'gpagespeedi_options' ); $current_values = get_option( 'gpagespeedi_options' );
$checkstatus = apply_filters( 'gpi_check_status', false ); $checkstatus = apply_filters( 'gpi_check_status', false );
if ( $checkstatus ) { if ( $checkstatus ) {
return array( 'result' => 'RUNNING' ); return array( 'result' => 'RUNNING' );
} }
@ -311,16 +309,16 @@ class MainWP_Child_Pagespeed {
$data = array( 'bad_api_key' => $bad_key ); $data = array( 'bad_api_key' => $bad_key );
if ( 'both' === $strategy || 'desktop' === $strategy ) { if ( 'both' === $strategy || 'desktop' === $strategy ) {
$result = self::cal_pagespeed_data( 'desktop' ); $result = self::cal_pagespeed_data( 'desktop' );
if ( ! empty($result) && is_array($result) ) { if ( !empty($result) && is_array($result) ) {
$data['desktop_score'] = $result['average_score']; $data['desktop_score'] = $result['average_score'];
$data['desktop_total_pages'] = $result['total_pages']; $data['desktop_total_pages'] = $result['total_pages'];
$data['desktop_last_modified'] = $result['last_modified']; $data['desktop_last_modified'] = $result['last_modified'];
} }
} }
if ( 'both' === $strategy || 'mobile' === $strategy ) { if ( 'both' === $strategy || 'mobile' === $strategy ) {
$result = self::cal_pagespeed_data( 'mobile' ); $result = self::cal_pagespeed_data( 'mobile' );
if ( ! empty($result) && is_array($result) ) { if ( !empty($result) && is_array($result) ) {
$data['mobile_score'] = $result['average_score']; $data['mobile_score'] = $result['average_score'];
$data['mobile_total_pages'] = $result['total_pages']; $data['mobile_total_pages'] = $result['total_pages'];
$data['mobile_last_modified'] = $result['last_modified']; $data['mobile_last_modified'] = $result['last_modified'];
@ -342,8 +340,9 @@ class MainWP_Child_Pagespeed {
return false; return false;
} }
$score_column = $strategy . '_score'; $score_column = $strategy . '_score';
// $page_stats_column = $strategy . '_page_stats'; //$page_stats_column = $strategy . '_page_stats';
$data_typestocheck = self::get_filter_options( 'all' ); $data_typestocheck = self::get_filter_options( 'all' );
@ -400,9 +399,9 @@ class MainWP_Child_Pagespeed {
// Not Null check for Report List scores // Not Null check for Report List scores
switch ( $strategy ) { switch ( $strategy ) {
// case 'both': // case 'both':
// $nullcheck = 'desktop_score IS NOT NULL AND mobile_score IS NOT NULL'; // $nullcheck = 'desktop_score IS NOT NULL AND mobile_score IS NOT NULL';
// break; // break;
case 'mobile': case 'mobile':
$nullcheck = 'mobile_score IS NOT NULL'; $nullcheck = 'mobile_score IS NOT NULL';
@ -438,59 +437,61 @@ class MainWP_Child_Pagespeed {
); );
} }
static function get_filter_options( $restrict_type = 'all' ) { static function get_filter_options($restrict_type = 'all') {
$types = array(); $types = array();
$gpi_options = get_option('gpagespeedi_options'); $gpi_options = get_option('gpagespeedi_options');
$typestocheck = array(); $typestocheck = array();
if ( $gpi_options['check_pages'] ) { if($gpi_options['check_pages']) {
if ( $restrict_type == 'all' || $restrict_type == 'ignored' || $restrict_type == 'pages' ) { if($restrict_type == 'all' || $restrict_type == 'ignored' || $restrict_type == 'pages') {
$typestocheck[] = 'type = %s'; $typestocheck[] = 'type = %s';
$types[1][] = 'page'; $types[1][] = "page";
} }
} }
if ( $gpi_options['check_posts'] ) { if($gpi_options['check_posts']) {
if ( $restrict_type == 'all' || $restrict_type == 'ignored' || $restrict_type == 'posts' ) { if($restrict_type == 'all' || $restrict_type == 'ignored' || $restrict_type == 'posts') {
$typestocheck[] = 'type = %s'; $typestocheck[] = 'type = %s';
$types[1][] = 'post'; $types[1][] = "post";
} }
} }
if ( $gpi_options['check_categories'] ) { if($gpi_options['check_categories']) {
if ( $restrict_type == 'all' || $restrict_type == 'ignored' || $restrict_type == 'categories' ) { if($restrict_type == 'all' || $restrict_type == 'ignored' || $restrict_type == 'categories') {
$typestocheck[] = 'type = %s'; $typestocheck[] = 'type = %s';
$types[1][] = 'category'; $types[1][] = "category";
} }
} }
if ( $gpi_options['cpt_whitelist'] ) { if($gpi_options['cpt_whitelist']) {
if ( $restrict_type == 'all' || $restrict_type == 'ignored' || stristr($restrict_type, 'gpi_custom_posts') ) { if($restrict_type == 'all' || $restrict_type == 'ignored' || stristr($restrict_type, 'gpi_custom_posts')) {
$cpt_whitelist_arr = false; $cpt_whitelist_arr = false;
if ( ! empty($gpi_options['cpt_whitelist']) ) { if(!empty($gpi_options['cpt_whitelist'])) {
$cpt_whitelist_arr = unserialize($gpi_options['cpt_whitelist']); $cpt_whitelist_arr = unserialize($gpi_options['cpt_whitelist']);
} }
$args = array( $args=array(
'public' => true, 'public' => true,
'_builtin' => false, '_builtin' => false
); );
$custom_post_types = get_post_types($args, 'names', 'and'); $custom_post_types = get_post_types($args,'names','and');
if ( $restrict_type != 'gpi_custom_posts' && $restrict_type != 'all' && $restrict_type != 'ignored' ) { if($restrict_type != 'gpi_custom_posts' && $restrict_type != 'all' && $restrict_type != 'ignored') {
$restrict_type = str_replace('gpi_custom_posts-', '', $restrict_type); $restrict_type = str_replace('gpi_custom_posts-', '', $restrict_type);
foreach ( $custom_post_types as $post_type ) { foreach($custom_post_types as $post_type)
if ( $cpt_whitelist_arr && in_array($post_type, $cpt_whitelist_arr) ) { {
if ( $post_type == $restrict_type ) { if($cpt_whitelist_arr && in_array($post_type, $cpt_whitelist_arr)) {
if($post_type == $restrict_type) {
$typestocheck[] = 'type = %s'; $typestocheck[] = 'type = %s';
$types[1][] = $custom_post_types[ $post_type ]; $types[1][] = $custom_post_types[$post_type];
} }
} }
} }
} else { } else {
foreach ( $custom_post_types as $post_type ) { foreach($custom_post_types as $post_type)
if ( $cpt_whitelist_arr && in_array($post_type, $cpt_whitelist_arr) ) { {
if($cpt_whitelist_arr && in_array($post_type, $cpt_whitelist_arr)) {
$typestocheck[] = 'type = %s'; $typestocheck[] = 'type = %s';
$types[1][] = $custom_post_types[ $post_type ]; $types[1][] = $custom_post_types[$post_type];
} }
} }
} }
@ -500,7 +501,7 @@ class MainWP_Child_Pagespeed {
if ( $gpi_options['check_custom_urls'] ) { if ( $gpi_options['check_custom_urls'] ) {
global $wpdb; global $wpdb;
$gpi_custom_urls = $wpdb->prefix . 'gpi_custom_urls'; $gpi_custom_urls = $wpdb->prefix . 'gpi_custom_urls';
$custom_url_types = $wpdb->get_col( $custom_url_types = $wpdb->get_col(
" "
SELECT DISTINCT type SELECT DISTINCT type
@ -511,19 +512,21 @@ class MainWP_Child_Pagespeed {
if ( ! empty( $custom_url_types ) ) { if ( ! empty( $custom_url_types ) ) {
foreach ( $custom_url_types as $custom_url_type ) { foreach ( $custom_url_types as $custom_url_type ) {
$typestocheck[] = 'type = %s'; $typestocheck[] = 'type = %s';
$types[1][] = $custom_url_type; $types[1][] = $custom_url_type;
} }
} }
} }
if ( ! empty($typestocheck) ) { if(!empty($typestocheck)) {
$types[0] = ''; $types[0] = '';
foreach ( $typestocheck as $type ) { foreach($typestocheck as $type)
if ( ! is_array($type) ) { {
if(!is_array($type)) {
$types[0] .= $type . ' OR '; $types[0] .= $type . ' OR ';
} else { } else {
foreach ( $type as $custom_post_type ) { foreach($type as $custom_post_type)
$types[0] .= 'type = %s OR '; {
$types[0] .= 'type = %s OR ';
$types[1][] = $custom_post_type; $types[1][] = $custom_post_type;
} }
} }

View file

@ -29,11 +29,11 @@ class MainWP_Child_Plugins_Check {
private $option_name_last_daily_run = 'mainwp_child_plugin_last_daily_run'; private $option_name_last_daily_run = 'mainwp_child_plugin_last_daily_run';
public static function Instance() { public static function Instance() {
if ( null === self::$instance ) { if ( null === MainWP_Child_Plugins_Check::$instance ) {
self::$instance = new MainWP_Child_Plugins_Check(); MainWP_Child_Plugins_Check::$instance = new MainWP_Child_Plugins_Check();
} }
return self::$instance; return MainWP_Child_Plugins_Check::$instance;
} }
public function __construct() { public function __construct() {
@ -45,7 +45,7 @@ class MainWP_Child_Plugins_Check {
add_action( $this->cron_name_watcher, array( $this, 'perform_watchdog' ) ); add_action( $this->cron_name_watcher, array( $this, 'perform_watchdog' ) );
// add_filter( 'plugin_row_meta', array( $this, 'change_plugin_row_meta' ), 10, 4 ); //add_filter( 'plugin_row_meta', array( $this, 'change_plugin_row_meta' ), 10, 4 );
add_filter( 'plugins_api_args', array( $this, 'modify_plugin_api_search_query' ), 10, 2 ); add_filter( 'plugins_api_args', array( $this, 'modify_plugin_api_search_query' ), 10, 2 );
@ -97,7 +97,7 @@ class MainWP_Child_Plugins_Check {
$last_run = new \DateTime( '@' . $last_run ); $last_run = new \DateTime( '@' . $last_run );
} }
// Get now //Get now
$now = new \DateTime(); $now = new \DateTime();
if ( false === $last_run || (int) $now->diff( $last_run )->format( '%h' ) >= 24 ) { if ( false === $last_run || (int) $now->diff( $last_run )->format( '%h' ) >= 24 ) {
@ -112,13 +112,14 @@ class MainWP_Child_Plugins_Check {
} }
public function schedule_watchdog() { public function schedule_watchdog() {
// For testing //For testing
// $this->cleanup_deactivation(); //$this->cleanup_deactivation();
// Schedule a global watching cron just in case both other crons get killed //Schedule a global watching cron just in case both other crons get killed
if ( ! wp_next_scheduled( $this->cron_name_watcher ) ) { if ( ! wp_next_scheduled( $this->cron_name_watcher ) ) {
wp_schedule_event( time(), 'hourly', $this->cron_name_watcher ); wp_schedule_event( time(), 'hourly', $this->cron_name_watcher );
} }
} }
public function get_plugins_outdate_info() { public function get_plugins_outdate_info() {
@ -142,38 +143,44 @@ class MainWP_Child_Plugins_Check {
} }
return $plugins_outdate; return $plugins_outdate;
} }
// for testing // for testing
public function change_plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) { public function change_plugin_row_meta( $plugin_meta, $plugin_file, $plugin_data, $status ) {
// Grab our previously stored array of known last modified dates //Grab our previously stored array of known last modified dates
// Requires WP 2.8.0 //Requires WP 2.8.0
$plugin_info = get_transient( $this->tran_name_plugin_timestamps ); $plugin_info = get_transient( $this->tran_name_plugin_timestamps );
// Sanity check the response //Sanity check the response
if ( false === $plugin_info || ! is_array( $plugin_info ) && 0 === count( $plugin_info ) ) { if( false === $plugin_info || ! is_array( $plugin_info ) && 0 === count( $plugin_info ) )
{
return $plugin_meta; return $plugin_meta;
} }
// See if this specific plugin is in the known list //See if this specific plugin is in the known list
if ( array_key_exists( $plugin_file, $plugin_info ) ) { if( array_key_exists( $plugin_file, $plugin_info ) )
// Get now {
$now = new \DateTime(); //Get now
$now = new \DateTime();
$last_updated = $plugin_info[ $plugin_file ]['last_updated']; $last_updated = $plugin_info[ $plugin_file ]['last_updated'];
// Last updated is stored as timestamp, get a real date //Last updated is stored as timestamp, get a real date
$plugin_last_updated_date = new \DateTime( '@' . $last_updated ); $plugin_last_updated_date = new \DateTime( '@' . $last_updated );
// Compute days between now and plugin last updated //Compute days between now and plugin last updated
$diff_in_days = $now->diff( $plugin_last_updated_date )->format( '%a' ); $diff_in_days = $now->diff( $plugin_last_updated_date )->format( '%a' );
// Customizable number of days for tolerance //Customizable number of days for tolerance
$tolerance_in_days = get_option( 'mainwp_child_plugintheme_days_outdate', 365 ); $tolerance_in_days = get_option( 'mainwp_child_plugintheme_days_outdate', 365 );
// If we're outside the window for tolerance show a message //If we're outside the window for tolerance show a message
if ( $diff_in_days > $tolerance_in_days ) { if( $diff_in_days > $tolerance_in_days )
{
$plugin_meta[] = sprintf( '<strong style="color: #f00;">This plugin has not been updated by the author in %1$d days!</strong>', $diff_in_days ); $plugin_meta[] = sprintf( '<strong style="color: #f00;">This plugin has not been updated by the author in %1$d days!</strong>', $diff_in_days );
} else { }
else
{
$plugin_meta[] = sprintf( '<span style="color: #090;">This plugin was last updated by the author in %1$d days ago.</span>', $diff_in_days ); $plugin_meta[] = sprintf( '<span style="color: #090;">This plugin was last updated by the author in %1$d days ago.</span>', $diff_in_days );
} }
} }
@ -186,17 +193,17 @@ class MainWP_Child_Plugins_Check {
require_once ABSPATH . '/wp-admin/includes/plugin.php'; require_once ABSPATH . '/wp-admin/includes/plugin.php';
} }
// Get our previous results //Get our previous results
$responses = get_transient( $this->tran_name_plugin_timestamps ); $responses = get_transient( $this->tran_name_plugin_timestamps );
if ( false === $responses || ! is_array( $responses ) ) { if ( false === $responses || ! is_array( $responses ) ) {
$responses = array(); $responses = array();
} }
// Get our previous cache of plugins for batching //Get our previous cache of plugins for batching
$all_plugins = get_transient( $this->tran_name_plugins_to_batch ); $all_plugins = get_transient( $this->tran_name_plugins_to_batch );
// If there wasn't a previous cache //If there wasn't a previous cache
if ( false === $all_plugins || ! is_array( $all_plugins ) ) { if ( false === $all_plugins || ! is_array( $all_plugins ) ) {
$plugins = get_plugins(); $plugins = get_plugins();
if ( is_array( $plugins ) ) { if ( is_array( $plugins ) ) {
@ -215,29 +222,29 @@ class MainWP_Child_Plugins_Check {
} }
$avoid_plugins = array( 'sitepress-multilingual-cms/sitepress.php' ); $avoid_plugins = array( 'sitepress-multilingual-cms/sitepress.php' );
// Grab a small number of plugins to scan //Grab a small number of plugins to scan
$plugins_to_scan = array_splice( $all_plugins, 0, apply_filters( 'mainwp_child_plugin_health_check_max_plugins_to_batch', 10 ) ); $plugins_to_scan = array_splice( $all_plugins, 0, apply_filters( 'mainwp_child_plugin_health_check_max_plugins_to_batch', 10 ) );
$tolerance_in_days = get_option( 'mainwp_child_plugintheme_days_outdate', 365 ); $tolerance_in_days = get_option( 'mainwp_child_plugintheme_days_outdate', 365 );
// Loop through each known plugin //Loop through each known plugin
foreach ( $plugins_to_scan as $slug => $v ) { foreach ( $plugins_to_scan as $slug => $v ) {
if ( in_array( $slug, $avoid_plugins ) ) { if ( in_array( $slug, $avoid_plugins ) ) {
continue; continue;
} }
// Try to get the raw information for this plugin //Try to get the raw information for this plugin
$body = $this->try_get_response_body( $slug, false ); $body = $this->try_get_response_body( $slug, false );
// We couldn't get any information, skip this plugin //We couldn't get any information, skip this plugin
if ( false === $body ) { if ( false === $body ) {
continue; continue;
} }
// Deserialize the response //Deserialize the response
$obj = maybe_unserialize( $body ); $obj = maybe_unserialize( $body );
$now = new \DateTime(); $now = new \DateTime();
// Sanity check that deserialization worked and that our property exists //Sanity check that deserialization worked and that our property exists
if ( false !== $obj && is_object( $obj ) && property_exists( $obj, 'last_updated' ) ) { if ( false !== $obj && is_object( $obj ) && property_exists( $obj, 'last_updated' ) ) {
if ( version_compare( $v['Version'], $obj->version, '>' ) ) { if ( version_compare( $v['Version'], $obj->version, '>' ) ) {
continue; continue;
@ -259,7 +266,7 @@ class MainWP_Child_Plugins_Check {
define( 'DAY_IN_SECONDS', 24 * 60 * 60 ); define( 'DAY_IN_SECONDS', 24 * 60 * 60 );
} }
// Store the master response for usage in the plugin table //Store the master response for usage in the plugin table
set_transient( $this->tran_name_plugin_timestamps, $responses, DAY_IN_SECONDS ); set_transient( $this->tran_name_plugin_timestamps, $responses, DAY_IN_SECONDS );
if ( 0 === count( $all_plugins ) ) { if ( 0 === count( $all_plugins ) ) {
@ -271,26 +278,26 @@ class MainWP_Child_Plugins_Check {
} }
private function try_get_response_body( $plugin, $second_pass ) { private function try_get_response_body( $plugin, $second_pass ) {
// Some of this code is lifted from class-wp-upgrader //Some of this code is lifted from class-wp-upgrader
// Get the WordPress current version to be polite in the API call //Get the WordPress current version to be polite in the API call
include ABSPATH . WPINC . '/version.php'; include( ABSPATH . WPINC . '/version.php' );
global $wp_version; global $wp_version;
// General options to be passed to wp_remote_get //General options to be passed to wp_remote_get
$options = array( $options = array(
'timeout' => 60 * 60, // HOUR_IN_SECONDS 'timeout' => 60 * 60, //HOUR_IN_SECONDS
'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ), 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ),
); );
// The URL for the endpoint //The URL for the endpoint
$url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/'; $url = $http_url = 'http://api.wordpress.org/plugins/info/1.0/';
// If we support SSL //If we support SSL
// Requires WP 3.2.0 //Requires WP 3.2.0
if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) { if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
// Requires WP 3.4.0 //Requires WP 3.4.0
$url = set_url_scheme( $url, 'https' ); $url = set_url_scheme( $url, 'https' );
} }
@ -299,27 +306,27 @@ class MainWP_Child_Plugins_Check {
$plugin_dir = dirname( $plugin ); $plugin_dir = dirname( $plugin );
} }
// Try to get the response (usually the SSL version) //Try to get the response (usually the SSL version)
// Requires WP 2.7.0 //Requires WP 2.7.0
$raw_response = wp_remote_get( $url . $plugin_dir, $options ); $raw_response = wp_remote_get( $url . $plugin_dir, $options );
// If we don't have an error and we received a valid response code //If we don't have an error and we received a valid response code
// Requires WP 2.7.0 //Requires WP 2.7.0
if ( ! is_wp_error( $raw_response ) && 200 === (int) wp_remote_retrieve_response_code( $raw_response ) ) { if ( ! is_wp_error( $raw_response ) && 200 === (int) wp_remote_retrieve_response_code( $raw_response ) ) {
// Get the actual body //Get the actual body
// Requires WP 2.7.0 //Requires WP 2.7.0
$body = wp_remote_retrieve_body( $raw_response ); $body = wp_remote_retrieve_body( $raw_response );
// Make sure that it isn't empty and also not an empty serialized object //Make sure that it isn't empty and also not an empty serialized object
if ( '' !== $body && 'N;' !== $body ) { if ( '' !== $body && 'N;' !== $body ) {
// If valid, return that //If valid, return that
return $body; return $body;
} }
} }
// The above valid //The above valid
// If we previously tried an SSL version try without SSL //If we previously tried an SSL version try without SSL
// Code below same as above block //Code below same as above block
if ( $ssl ) { if ( $ssl ) {
$raw_response = wp_remote_get( $http_url . $plugin, $options ); $raw_response = wp_remote_get( $http_url . $plugin, $options );
if ( ! is_wp_error( $raw_response ) && 200 === (int) wp_remote_retrieve_response_code( $raw_response ) ) { if ( ! is_wp_error( $raw_response ) && 200 === (int) wp_remote_retrieve_response_code( $raw_response ) ) {
@ -330,22 +337,22 @@ class MainWP_Child_Plugins_Check {
} }
} }
// The above failed //The above failed
// If we're on a second pass already then there's nothing left to do but bail //If we're on a second pass already then there's nothing left to do but bail
if ( true === $second_pass ) { if ( true === $second_pass ) {
return false; return false;
} }
// We're still on the first pass, try to get just the name of the directory of the plugin //We're still on the first pass, try to get just the name of the directory of the plugin
$parts = explode( '/', $plugin ); $parts = explode( '/', $plugin );
// Sanity check that we have two parts, a directory and a file name //Sanity check that we have two parts, a directory and a file name
if ( 2 === count( $parts ) ) { if ( 2 === count( $parts ) ) {
// Try this entire function using just the directory name //Try this entire function using just the directory name
return $this->try_get_response_body( $parts[0], true ); return $this->try_get_response_body( $parts[0], true );
} }
// Everything above failed, bail //Everything above failed, bail
return false; return false;
} }
} }

View file

@ -4,11 +4,11 @@ class MainWP_Child_Robot {
public static $instance = null; public static $instance = null;
static function Instance() { static function Instance() {
if ( null === self::$instance ) { if ( null === MainWP_Child_Robot::$instance ) {
self::$instance = new MainWP_Child_Robot(); MainWP_Child_Robot::$instance = new MainWP_Child_Robot();
} }
return self::$instance; return MainWP_Child_Robot::$instance;
} }
public function wpr_insertcomments( $postid, $comments ) { public function wpr_insertcomments( $postid, $comments ) {
@ -23,12 +23,12 @@ class MainWP_Child_Robot {
$comment_author = $comment['author']; $comment_author = $comment['author'];
$comment_author_url = ''; $comment_author_url = '';
$comment_content = ''; $comment_content = '';
$comment_content .= $comment['content']; $comment_content .= $comment['content'];
$comment_type = ''; $comment_type = '';
$user_ID = ''; $user_ID = '';
$comment_approved = 1; $comment_approved = 1;
$commentdata = compact( 'comment_post_ID', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID', 'comment_approved' ); $commentdata = compact( 'comment_post_ID', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID', 'comment_approved' );
$comment_id = wp_insert_comment( $commentdata ); $comment_id = wp_insert_comment( $commentdata );
} }
} }
} }

View file

@ -2,7 +2,7 @@
class MainWP_Child_Server_Information { class MainWP_Child_Server_Information {
const WARNING = 1; const WARNING = 1;
const ERROR = 2; const ERROR = 2;
public static function init() { public static function init() {
add_action( 'wp_ajax_mainwp-child_dismiss_warnings', array( add_action( 'wp_ajax_mainwp-child_dismiss_warnings', array(
@ -19,11 +19,10 @@ class MainWP_Child_Server_Information {
} }
if ( $_POST['what'] == 'warning' ) { if ( $_POST['what'] == 'warning' ) {
if ( isset($_POST['warnings']) ) { if (isset($_POST['warnings']))
$warnings = intval($_POST['warnings']); $warnings = intval($_POST['warnings']);
} else { else
$warnings = self::getWarnings(); $warnings = self::getWarnings();
}
$dismissWarnings['warnings'] = $warnings; $dismissWarnings['warnings'] = $warnings;
} }
MainWP_Helper::update_option( 'mainwp_child_dismiss_warnings', $dismissWarnings ); MainWP_Helper::update_option( 'mainwp_child_dismiss_warnings', $dismissWarnings );
@ -31,11 +30,11 @@ class MainWP_Child_Server_Information {
} }
public static function showWarnings() { public static function showWarnings() {
if ( stristr( $_SERVER['REQUEST_URI'], 'mainwp_child_tab' ) || stristr( $_SERVER['REQUEST_URI'], 'mainwp-reports-page' ) || stristr( $_SERVER['REQUEST_URI'], 'mainwp-reports-settings' ) ) { if ( stristr( $_SERVER['REQUEST_URI'], 'mainwp_child_tab' ) || stristr( $_SERVER['REQUEST_URI'], 'mainwp-reports-page' ) || stristr( $_SERVER['REQUEST_URI'], 'mainwp-reports-settings' )) {
return; return;
} }
$warnings = self::getWarnings(); $warnings = self::getWarnings();
$dismissWarnings = get_option( 'mainwp_child_dismiss_warnings' ); $dismissWarnings = get_option( 'mainwp_child_dismiss_warnings' );
if ( ! is_array( $dismissWarnings ) ) { if ( ! is_array( $dismissWarnings ) ) {
@ -474,17 +473,12 @@ class MainWP_Child_Server_Information {
</div> </div>
<br/> <br/>
<div class="mwp_server_info_box"> <div class="mwp_server_info_box">
<h2><?php esc_html_e( 'Server Information' ); ?></h2> <h2><?php esc_html_e( 'Server Information' ); ?></h2><?php
<?php MainWP_Child_Server_Information::render();
self::render(); ?><h2><?php esc_html_e( 'Cron Schedules' ); ?></h2><?php
?> MainWP_Child_Server_Information::renderCron();
<h2><?php esc_html_e( 'Cron Schedules' ); ?></h2> ?><h2><?php esc_html_e( 'Error Log' ); ?></h2><?php
<?php MainWP_Child_Server_Information::renderErrorLogPage();
self::renderCron();
?>
<h2><?php esc_html_e( 'Error Log' ); ?></h2>
<?php
self::renderErrorLogPage();
?> ?>
</div> </div>
</div> </div>
@ -515,7 +509,7 @@ class MainWP_Child_Server_Information {
if ( ! self::check( '>=', '10000', 'getOutputBufferSize' ) ) { if ( ! self::check( '>=', '10000', 'getOutputBufferSize' ) ) {
$i ++; $i ++;
} }
// if (!self::check('=', true, 'getSSLSupport')) $i++; // if (!self::check('=', true, 'getSSLSupport')) $i++;
if ( ! self::checkDirectoryMainWPDirectory( false ) ) { if ( ! self::checkDirectoryMainWPDirectory( false ) ) {
$i ++; $i ++;
@ -544,10 +538,10 @@ class MainWP_Child_Server_Information {
public static function render() { public static function render() {
$branding_title = MainWP_Child_Branding::Instance()->get_branding_title(); $branding_title = MainWP_Child_Branding::Instance()->get_branding_title();
$isBranding = true; $isBranding = true;
if ( $branding_title == '' ) { if ( $branding_title == '' ) {
$branding_title = 'MainWP Child'; $branding_title = 'MainWP Child';
$isBranding = false; $isBranding = false;
} }
?> ?>
@ -579,7 +573,7 @@ class MainWP_Child_Server_Information {
</tr> </tr>
<?php <?php
self::checkDirectoryMainWPDirectory(); self::checkDirectoryMainWPDirectory();
$server = get_option( 'mainwp_child_server' ); $server = get_option( 'mainwp_child_server' );
?> ?>
<tr> <tr>
<td></td> <td></td>
@ -589,9 +583,8 @@ class MainWP_Child_Server_Information {
<td></td> <td></td>
</tr> </tr>
<tr> <tr>
<td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'WordPress', 'mainwp-child' ); ?></td> <td style="background: #333; color: #fff;" colspan="5"><?php esc_html_e( 'WORDPRESS', 'mainwp-child' ); ?></td>
</tr> </tr><?php
<?php
self::renderRow( 'WordPress Version', '>=', '3.4', 'getWordpressVersion' ); self::renderRow( 'WordPress Version', '>=', '3.4', 'getWordpressVersion' );
self::renderRow( 'WordPress Memory Limit', '>=', '64M', 'getWordpressMemoryLimit' ); self::renderRow( 'WordPress Memory Limit', '>=', '64M', 'getWordpressMemoryLimit' );
self::renderRow( 'MultiSite Disabled', '=', true, 'checkIfMultisite' ); self::renderRow( 'MultiSite Disabled', '=', true, 'checkIfMultisite' );
@ -606,8 +599,7 @@ class MainWP_Child_Server_Information {
<tr> <tr>
<td style="background: #333; color: #fff;" <td style="background: #333; color: #fff;"
colspan="5"><?php esc_html_e( 'PHP SETTINGS', 'mainwp-child' ); ?></td> colspan="5"><?php esc_html_e( 'PHP SETTINGS', 'mainwp-child' ); ?></td>
</tr> </tr><?php
<?php
self::renderRow( 'PHP Version', '>=', '5.6', 'getPHPVersion' ); self::renderRow( 'PHP Version', '>=', '5.6', 'getPHPVersion' );
?> ?>
<tr> <tr>
@ -637,15 +629,13 @@ class MainWP_Child_Server_Information {
<tr> <tr>
<td style="background: #333; color: #fff;" <td style="background: #333; color: #fff;"
colspan="5"><?php esc_html_e( 'MySQL SETTINGS', 'mainwp-child' ); ?></td> colspan="5"><?php esc_html_e( 'MySQL SETTINGS', 'mainwp-child' ); ?></td>
</tr> </tr><?php
<?php
self::renderRow( 'MySQL Version', '>=', '5.0', 'getMySQLVersion' ); self::renderRow( 'MySQL Version', '>=', '5.0', 'getMySQLVersion' );
?> ?>
<tr> <tr>
<td style="background: #333; color: #fff;" <td style="background: #333; color: #fff;"
colspan="5"><?php esc_html_e( 'BACKUP ARCHIVE INFORMATION', 'mainwp-child' ); ?></td> colspan="5"><?php esc_html_e( 'BACKUP ARCHIVE INFORMATION', 'mainwp-child' ); ?></td>
</tr> </tr><?php
<?php
self::renderRow( 'ZipArchive enabled in PHP', '=', true, 'getZipArchiveEnabled' ); self::renderRow( 'ZipArchive enabled in PHP', '=', true, 'getZipArchiveEnabled' );
self::renderRow( 'Tar GZip supported', '=', true, 'getGZipEnabled' ); self::renderRow( 'Tar GZip supported', '=', true, 'getGZipEnabled' );
self::renderRow( 'Tar BZip2 supported', '=', true, 'getBZipEnabled' ); self::renderRow( 'Tar BZip2 supported', '=', true, 'getBZipEnabled' );
@ -818,16 +808,16 @@ class MainWP_Child_Server_Information {
<td colspan="3"><?php echo esc_html( defined( 'DB_CHARSET' ) ? DB_CHARSET : '' ); ?></td> <td colspan="3"><?php echo esc_html( defined( 'DB_CHARSET' ) ? DB_CHARSET : '' ); ?></td>
</tr> </tr>
<tr> <tr>
<td style="background: #333; color: #fff;" colspan="5"><?php _e( 'WordPress PLUGINS', 'mainwp-child' ); ?></td> <td style="background: #333; color: #fff;" colspan="5"><?php _e( 'WORDPRESS PLUGINS', 'mainwp-child' ); ?></td>
</tr> </tr>
<?php <?php
$all_plugins = get_plugins(); $all_plugins = get_plugins();
foreach ( $all_plugins as $slug => $plugin ) { foreach ( $all_plugins as $slug => $plugin) {
if ( $slug == 'mainwp-child/mainwp-child.php' || $slug == 'mainwp-child-reports/mainwp-child-reports.php' ) { if ( $slug == 'mainwp-child/mainwp-child.php' || $slug == 'mainwp-child-reports/mainwp-child-reports.php' ) {
if ( $isBranding ) { if ( $isBranding ) {
if ( $slug == 'mainwp-child/mainwp-child.php' ) { if ( $slug == 'mainwp-child/mainwp-child.php' ) {
$plugin['Name'] = esc_html( stripslashes( $branding_title ) ); $plugin['Name'] = esc_html( stripslashes( $branding_title ) );
} elseif ( $slug == 'mainwp-child-reports/mainwp-child-reports.php' ) { } else if ($slug == 'mainwp-child-reports/mainwp-child-reports.php') {
$plugin['Name'] = esc_html( stripslashes( $branding_title ) ) . ' reports'; $plugin['Name'] = esc_html( stripslashes( $branding_title ) ) . ' reports';
} }
} }
@ -879,7 +869,7 @@ class MainWP_Child_Server_Information {
} }
public static function mainwpRequiredFunctions() { public static function mainwpRequiredFunctions() {
// error_reporting(E_ALL); //error_reporting(E_ALL);
$disabled_functions = ini_get( 'disable_functions' ); $disabled_functions = ini_get( 'disable_functions' );
if ( '' !== $disabled_functions ) { if ( '' !== $disabled_functions ) {
$arr = explode( ',', $disabled_functions ); $arr = explode( ',', $disabled_functions );
@ -906,7 +896,7 @@ class MainWP_Child_Server_Information {
} }
protected static function getMainwpVersion() { protected static function getMainwpVersion() {
include_once ABSPATH . '/wp-admin/includes/plugin-install.php'; include_once( ABSPATH . '/wp-admin/includes/plugin-install.php' );
$api = plugins_api( 'plugin_information', array( $api = plugins_api( 'plugin_information', array(
'slug' => 'mainwp-child', 'slug' => 'mainwp-child',
'fields' => array( 'sections' => false ), 'fields' => array( 'sections' => false ),
@ -967,9 +957,8 @@ class MainWP_Child_Server_Information {
protected static function checkDirectoryMainWPDirectory( $write = true ) { protected static function checkDirectoryMainWPDirectory( $write = true ) {
$branding_title = MainWP_Child_Branding::Instance()->get_branding_title(); $branding_title = MainWP_Child_Branding::Instance()->get_branding_title();
if ( $branding_title == '' ) { if ($branding_title == '')
$branding_title = 'MainWP'; $branding_title = 'MainWP';
}
$branding_title .= ' Upload Directory'; $branding_title .= ' Upload Directory';
@ -1054,19 +1043,20 @@ class MainWP_Child_Server_Information {
<td><?php echo( $currentVersion === true ? 'true' : $currentVersion ); ?></td> <td><?php echo( $currentVersion === true ? 'true' : $currentVersion ); ?></td>
<?php if ( $whatType == 'filesize' ) { ?> <?php if ( $whatType == 'filesize' ) { ?>
<td><?php echo( self::filesize_compare( $currentVersion, $pVersion, $pCompare ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::getWarningHTML( $errorType ) ); ?></td> <td><?php echo( self::filesize_compare( $currentVersion, $pVersion, $pCompare ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::getWarningHTML( $errorType ) ); ?></td>
<?php } elseif ( $whatType == 'curlssl' ) { ?> <?php } else if ( $whatType == 'curlssl' ) { ?>
<td><?php echo( self::curlssl_compare( $pVersion, $pCompare ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::getWarningHTML( $errorType ) ); ?></td> <td><?php echo( self::curlssl_compare( $pVersion, $pCompare ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::getWarningHTML( $errorType ) ); ?></td>
<?php } elseif ( ( $pGetter == 'getMaxInputTime' || $pGetter == 'getMaxExecutionTime' ) && $currentVersion == -1 ) { ?> <?php } else if (($pGetter == 'getMaxInputTime' || $pGetter == 'getMaxExecutionTime') && $currentVersion == -1) { ?>
<td><?php echo '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>'; ?></td> <td><?php echo '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>'; ?></td>
<?php } else { ?> <?php } else { ?>
<td><?php echo ( version_compare($currentVersion, $pVersion, $pCompare) || ( ( $pExtraCompare != null ) && version_compare($currentVersion, $pExtraVersion, $pExtraCompare) ) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::getWarningHTML( $errorType ) ); ?></td> <td><?php echo (version_compare($currentVersion, $pVersion, $pCompare) || (($pExtraCompare != null) && version_compare($currentVersion, $pExtraVersion, $pExtraCompare)) ? '<span class="mainwp-pass"><i class="fa fa-check-circle"></i> Pass</span>' : self::getWarningHTML( $errorType )); ?></td>
<?php } ?> <?php } ?>
</tr> </tr>
<?php <?php
} }
private static function getWarningHTML( $errorType = self::WARNING ) { private static function getWarningHTML($errorType = self::WARNING)
if ( self::WARNING == $errorType ) { {
if (self::WARNING == $errorType) {
return '<span class="mainwp-warning"><i class="fa fa-exclamation-circle"></i> Warning</span>'; return '<span class="mainwp-warning"><i class="fa fa-exclamation-circle"></i> Warning</span>';
} }
return '<span class="mainwp-fail"><i class="fa fa-exclamation-circle"></i> Fail</span>'; return '<span class="mainwp-fail"><i class="fa fa-exclamation-circle"></i> Fail</span>';
@ -1090,10 +1080,10 @@ class MainWP_Child_Server_Information {
return version_compare( $value1, $value2, $operator ); return version_compare( $value1, $value2, $operator );
} }
protected static function check( $pCompare, $pVersion, $pGetter, $pExtraCompare = null, $pExtraVersion = null, $sizeCompare = false ) { protected static function check( $pCompare, $pVersion, $pGetter, $pExtraCompare = null, $pExtraVersion = null, $sizeCompare = false) {
$currentVersion = call_user_func( array( 'MainWP_Child_Server_Information', $pGetter ) ); $currentVersion = call_user_func( array( 'MainWP_Child_Server_Information', $pGetter ) );
if ( $sizeCompare ) { if ($sizeCompare) {
return self::filesize_compare( $currentVersion, $pVersion, $pCompare ); return self::filesize_compare( $currentVersion, $pVersion, $pCompare );
} else { } else {
return ( version_compare( $currentVersion, $pVersion, $pCompare ) || ( ( null !== $pExtraCompare ) && version_compare( $currentVersion, $pExtraVersion, $pExtraCompare ) ) ); return ( version_compare( $currentVersion, $pVersion, $pCompare ) || ( ( null !== $pExtraCompare ) && version_compare( $currentVersion, $pExtraVersion, $pExtraCompare ) ) );
@ -1134,9 +1124,9 @@ class MainWP_Child_Server_Information {
protected static function getSSLWarning() { protected static function getSSLWarning() {
$conf = array( 'private_key_bits' => 2048 ); $conf = array( 'private_key_bits' => 2048 );
$str = ''; $str = '';
if ( function_exists( 'openssl_pkey_new' ) ) { if ( function_exists( 'openssl_pkey_new' ) ) {
$res = @openssl_pkey_new( $conf ); $res = @openssl_pkey_new( $conf );
@openssl_pkey_export( $res, $privkey ); @openssl_pkey_export( $res, $privkey );
$str = openssl_error_string(); $str = openssl_error_string();
@ -1180,10 +1170,7 @@ class MainWP_Child_Server_Information {
} }
protected static function getArchitecture() { protected static function getArchitecture() {
echo esc_html( PHP_INT_SIZE * 8 ) echo esc_html( PHP_INT_SIZE * 8 ) ?>&nbsp;bit <?php
?>
&nbsp;bit
<?php
} }
protected static function memoryUsage() { protected static function memoryUsage() {
@ -1328,33 +1315,31 @@ class MainWP_Child_Server_Information {
} }
protected static function serverSelfConnect() { protected static function serverSelfConnect() {
$url = site_url( 'wp-cron.php' ); $url = site_url( 'wp-cron.php' );
$query_args = array( 'mainwp_child_run' => 'test' ); $query_args = array('mainwp_child_run' => 'test');
$url = add_query_arg( $query_args, $url ); $url = add_query_arg( $query_args, $url );
$args = array( $args = array( 'blocking' => TRUE,
'blocking' => true, 'sslverify' => apply_filters( 'https_local_ssl_verify', true ),
'sslverify' => apply_filters( 'https_local_ssl_verify', true ), 'timeout' => 15
'timeout' => 15,
); );
$response = wp_remote_post( $url, $args ); $response = wp_remote_post( $url, $args );
$test_result = ''; $test_result = '';
if ( is_wp_error( $response ) ) { if ( is_wp_error( $response ) ) {
$test_result .= sprintf( __( 'The HTTP response test get an error "%s"', 'mainwp-child' ), $response->get_error_message() ); $test_result .= sprintf( __( 'The HTTP response test get an error "%s"','mainwp-child' ), $response->get_error_message() );
} }
$response_code = wp_remote_retrieve_response_code( $response ); $response_code = wp_remote_retrieve_response_code( $response );
if ( $response_code < 200 && $response_code > 204 ) { if ( $response_code < 200 && $response_code > 204 ) {
$test_result .= sprintf( __( 'The HTTP response test get a false http status (%s)', 'mainwp-child' ), wp_remote_retrieve_response_code( $response ) ); $test_result .= sprintf( __( 'The HTTP response test get a false http status (%s)','mainwp-child' ), wp_remote_retrieve_response_code( $response ) );
} else { } else {
$response_body = wp_remote_retrieve_body( $response ); $response_body = wp_remote_retrieve_body( $response );
if ( false === strstr( $response_body, 'MainWP Test' ) ) { if ( FALSE === strstr( $response_body, 'MainWP Test' ) ) {
$test_result .= sprintf( __( 'Not expected HTTP response body: %s', 'mainwp-child' ), esc_attr( strip_tags( $response_body ) ) ); $test_result .= sprintf( __( 'Not expected HTTP response body: %s','mainwp-child' ), esc_attr( strip_tags( $response_body ) ) );
} }
} }
if ( empty( $test_result ) ) { if ( empty( $test_result ) ) {
_e( 'Response Test O.K.', 'mainwp-child' ); _e( 'Response Test O.K.', 'mainwp-child' );
} else { } else
echo $test_result; echo $test_result;
}
} }
@ -1426,6 +1411,7 @@ class MainWP_Child_Server_Information {
} }
return $bytes; return $bytes;
} }
@ -1482,11 +1468,11 @@ class MainWP_Child_Server_Information {
if ( empty( $lines ) ) { if ( empty( $lines ) ) {
$branding_title = MainWP_Child_Branding::Instance()->get_branding_title(); $branding_title = MainWP_Child_Branding::Instance()->get_branding_title();
if ( $branding_title == '' ) { if ($branding_title == '') {
$branding_title = 'MainWP'; $branding_title = 'MainWP';
} }
$msg = esc_html( stripslashes( $branding_title ) ) . ' is unable to find your error logs, please contact your host for server error logs.'; $msg = esc_html( stripslashes( $branding_title ) ) . ' is unable to find your error logs, please contact your host for server error logs.';
echo '<tr><td colspan="2">' . $msg . '</td></tr>'; echo '<tr><td colspan="2">' . $msg . '</td></tr>';
return; return;
} }
@ -1518,6 +1504,7 @@ class MainWP_Child_Server_Information {
echo wp_kses_post( "<tr><td>{$time}</td><td>{$error}</td></tr>" ); echo wp_kses_post( "<tr><td>{$time}</td><td>{$error}</td></tr>" );
} }
} }
} }
static function time_compare( $a, $b ) { static function time_compare( $a, $b ) {
@ -1556,7 +1543,7 @@ class MainWP_Child_Server_Information {
// read them to $data and then move the file pointer // read them to $data and then move the file pointer
// back to where we were. // back to where we were.
fseek( $fh, - $can_read, SEEK_CUR ); fseek( $fh, - $can_read, SEEK_CUR );
$data = fread( $fh, $can_read ); $data = fread( $fh, $can_read );
$data .= $leftover; $data .= $leftover;
fseek( $fh, - $can_read, SEEK_CUR ); fseek( $fh, - $can_read, SEEK_CUR );
@ -1590,7 +1577,7 @@ class MainWP_Child_Server_Information {
if ( file_exists( ABSPATH . 'wp-config.php' ) ) { if ( file_exists( ABSPATH . 'wp-config.php' ) ) {
@show_source( ABSPATH . 'wp-config.php' ); @show_source( ABSPATH . 'wp-config.php' );
} else { } else {
$files = @get_included_files(); $files = @get_included_files();
$configFound = false; $configFound = false;
if ( is_array( $files ) ) { if ( is_array( $files ) ) {
foreach ( $files as $file ) { foreach ( $files as $file ) {
@ -1602,7 +1589,7 @@ class MainWP_Child_Server_Information {
} }
} }
if ( ! $configFound ) { if ( !$configFound ) {
_e( 'wp-config.php not found', 'mainwp' ); _e( 'wp-config.php not found', 'mainwp' );
} }
} }
@ -1626,69 +1613,68 @@ class MainWP_Child_Server_Information {
<?php <?php
} }
public static function renderConnectionDetails() { public static function renderConnectionDetails() {
$branding_title = MainWP_Child_Branding::Instance()->get_branding_title(); $branding_title = MainWP_Child_Branding::Instance()->get_branding_title();
if ( $branding_title == '' ) { if ($branding_title == '')
$branding_title = 'MainWP'; $branding_title = 'MainWP';
}
global $current_user; global $current_user;
$uniqueId = get_option('mainwp_child_uniqueId'); $uniqueId = get_option('mainwp_child_uniqueId');
$details = array( $details = array(
'siteurl' => array( 'siteurl' => array(
'title' => __('Site URL', 'mainwp-child'), 'title' => __('Site URL', 'mainwp-child'),
'value' => get_bloginfo( 'url' ), 'value' => get_bloginfo( 'url' ),
'desc' => get_bloginfo( 'url' ), 'desc' => get_bloginfo( 'url' )
), ),
'adminuser' => array( 'adminuser' => array(
'title' => __('Administrator name', 'mainwp-child'), 'title' => __('Administrator name', 'mainwp-child'),
'value' => $current_user->user_login, 'value' => $current_user->user_login,
'desc' => __('This is your Administrator username, however, you can use any existing Administrator username.', 'mainwp-child'), 'desc' => __('This is your Administrator username, however, you can use any existing Administrator username.', 'mainwp-child')
), ),
'friendly_name' => array( 'friendly_name' => array(
'title' => __('Friendly site name', 'mainwp-child'), 'title' => __('Friendly site name', 'mainwp-child'),
'value' => get_bloginfo( 'name' ), 'value' => get_bloginfo( 'name' ),
'desc' => __('For the friendly site name, you can use any name, this is just a suggestion.', 'mainwp-child'), 'desc' => __('For the friendly site name, you can use any name, this is just a suggestion.', 'mainwp-child')
), ),
'uniqueid' => array( 'uniqueid' => array(
'title' => __('Child unique security id', 'mainwp-child'), 'title' => __('Child unique security id', 'mainwp-child'),
'value' => ! empty($uniqueId) ? $uniqueId : __('Leave the field blank', 'mainwp-child'), 'value' => !empty($uniqueId) ? $uniqueId : __('Leave the field blank', 'mainwp-child'),
'desc' => sprintf(__('Child unique security id is not required, however, since you have enabled it, you need to add it to your %s dashboard.', 'mainwp-child'), stripslashes( $branding_title ) ), 'desc' => sprintf(__('Child unique security id is not required, however, since you have enabled it, you need to add it to your %s dashboard.', 'mainwp-child') , stripslashes( $branding_title ) )
), ),
'verify_ssl' => array( 'verify_ssl' => array(
'title' => __('Verify certificate', 'mainwp-child'), 'title' => __('Verify certificate', 'mainwp-child'),
'value' => __('Yes', 'mainwp-child'), 'value' => __('Yes', 'mainwp-child'),
'desc' => __('If there is an issue with SSL certificate on this site, try to set this option to No.', 'mainwp-child'), 'desc' => __('If there is an issue with SSL certificate on this site, try to set this option to No.', 'mainwp-child')
), ),
'ssl_version' => array( 'ssl_version' => array(
'title' => __('SSL version', 'mainwp-child'), 'title' => __('SSL version', 'mainwp-child'),
'value' => __('Auto Detect', 'mainwp-child'), 'value' => __('Auto Detect', 'mainwp-child'),
'desc' => __('Auto Detect', 'mainwp-child'), 'desc' => __('Auto Detect', 'mainwp-child'),
), ),
); );
?> ?>
<div class="postbox" id="connection_detail"> <div class="postbox" id="connection_detail">
<h3 class="mainwp_box_title"><span><?php _e( 'Connection details', 'mainwp-child' ); ?></span></h3> <h3 class="mainwp_box_title"><span><?php _e( 'Connection details', 'mainwp-child' ); ?></span></h3>
<div class="inside"> <div class="inside">
<div class="mainwp-postbox-actions-top mainwp-padding-5"> <div class="mainwp-postbox-actions-top mainwp-padding-5">
<?php <?php
echo sprintf(__('If you are trying to connect this child site to your %s Dashboard, you can use following details to do that. Please note that these are only suggested values.', 'mainwp-child'), stripslashes( $branding_title )); echo sprintf(__('If you are trying to connect this child site to your %s Dashboard, you can use following details to do that. Please note that these are only suggested values.', 'mainwp-child') , stripslashes( $branding_title ));
?> ?>
</div> </div>
<table id="mainwp-table" class="wp-list-table widefat" cellspacing="0" style="border: 0"> <table id="mainwp-table" class="wp-list-table widefat" cellspacing="0" style="border: 0">
<tbody> <tbody>
<?php <?php
foreach ( $details as $row ) { foreach ($details as $row) {
?> ?>
<tr> <tr>
<th style="width: 20%"><strong><?php echo esc_html($row['title']); ?></strong></th> <th style="width: 20%"><strong><?php echo esc_html($row['title']); ?></strong></th>
<td style="width: 20%"><strong><?php echo esc_html($row['value']); ?></strong></td> <td style="width: 20%"><strong><?php echo esc_html($row['value']); ?></strong></td>
<td><?php echo esc_html($row['desc']); ?></td> <td><?php echo esc_html($row['desc']); ?></td>
</tr> </tr>
<?php <?php
} }
?> ?>
</tbody> </tbody>
</table> </table>
</div> </div>

View file

@ -2,16 +2,16 @@
class MainWP_Child_Skeleton_Key { class MainWP_Child_Skeleton_Key {
public static $instance = null; public static $instance = null;
public static $information = array(); public static $information = array();
public $plugin_translate = 'mainwp-child'; public $plugin_translate = 'mainwp-child';
static function Instance() { static function Instance() {
if ( null === self::$instance ) { if ( null === MainWP_Child_Skeleton_Key::$instance ) {
self::$instance = new MainWP_Child_Skeleton_Key(); MainWP_Child_Skeleton_Key::$instance = new MainWP_Child_Skeleton_Key();
} }
return self::$instance; return MainWP_Child_Skeleton_Key::$instance;
} }
public function action() { public function action() {
@ -19,13 +19,13 @@ class MainWP_Child_Skeleton_Key {
error_reporting( 0 ); error_reporting( 0 );
function mainwp_skeleton_key_handle_fatal_error() { function mainwp_skeleton_key_handle_fatal_error() {
$error = error_get_last(); $error = error_get_last();
if ( isset( $error['type'] ) && in_array($error['type'], array( 1, 4, 16, 64, 256 ) ) && isset( $error['message'] ) ) { if ( isset( $error['type'] ) && in_array($error['type'], array(1, 4, 16, 64, 256) ) && isset( $error['message'] ) ) {
MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) ); MainWP_Helper::write( array( 'error' => 'MainWP_Child fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ) );
} }
// to fix issue double <mainwp></mainwp> header in response // to fix issue double <mainwp></mainwp> header in response
// else { // else {
// MainWP_Helper::write( MainWP_Child_Skeleton_Key::$information ); // MainWP_Helper::write( MainWP_Child_Skeleton_Key::$information );
// } // }
} }
register_shutdown_function( 'mainwp_skeleton_key_handle_fatal_error' ); register_shutdown_function( 'mainwp_skeleton_key_handle_fatal_error' );
@ -42,7 +42,7 @@ class MainWP_Child_Skeleton_Key {
} }
MainWP_Helper::write( $information ); MainWP_Helper::write( $information );
// MainWP_Child_Skeleton_Key::$information = $information; //MainWP_Child_Skeleton_Key::$information = $information;
exit(); exit();
} }
@ -67,31 +67,26 @@ class MainWP_Child_Skeleton_Key {
$manager = WP_Session_Tokens::get_instance( $current_user->ID ); $manager = WP_Session_Tokens::get_instance( $current_user->ID );
$token = $manager->create( $expiration ); $token = $manager->create( $expiration );
$secure = is_ssl(); $secure = is_ssl();
if ( $secure ) { if ( $secure ) {
$auth_cookie_name = SECURE_AUTH_COOKIE; $auth_cookie_name = SECURE_AUTH_COOKIE;
$scheme = 'secure_auth'; $scheme = 'secure_auth';
} else { } else {
$auth_cookie_name = AUTH_COOKIE; $auth_cookie_name = AUTH_COOKIE;
$scheme = 'auth'; $scheme = 'auth';
} }
$auth_cookie = wp_generate_auth_cookie( $current_user->ID, $expiration, $scheme, $token ); $auth_cookie = wp_generate_auth_cookie( $current_user->ID, $expiration, $scheme, $token );
$logged_in_cookie = wp_generate_auth_cookie( $current_user->ID, $expiration, 'logged_in', $token ); $logged_in_cookie = wp_generate_auth_cookie( $current_user->ID, $expiration, 'logged_in', $token );
$_COOKIE[ $auth_cookie_name ] = $auth_cookie; $_COOKIE[ $auth_cookie_name ] = $auth_cookie;
$_COOKIE[ LOGGED_IN_COOKIE ] = $logged_in_cookie; $_COOKIE[ LOGGED_IN_COOKIE ] = $logged_in_cookie;
$post_args = array(); $post_args = array();
$post_args['body'] = array(); $post_args['body'] = array();
$post_args['redirection'] = 5; $post_args['redirection'] = 5;
$post_args['decompress'] = false; // For gzinflate() data error bug $post_args['decompress'] = false; // For gzinflate() data error bug
$post_args['cookies'] = array( $post_args['cookies'] = array(
new WP_Http_Cookie( array( new WP_Http_Cookie( array( 'name' => $auth_cookie_name, 'value' => $auth_cookie ) ),
'name' => $auth_cookie_name, new WP_Http_Cookie( array( 'name' => LOGGED_IN_COOKIE, 'value' => $logged_in_cookie ) ),
'value' => $auth_cookie,
) ),
new WP_Http_Cookie( array(
'name' => LOGGED_IN_COOKIE,
'value' => $logged_in_cookie,
) ),
); );
if ( isset( $args['get'] ) ) { if ( isset( $args['get'] ) ) {
@ -195,33 +190,30 @@ class MainWP_Child_Skeleton_Key {
public function save_settings() { public function save_settings() {
$settings = isset($_POST['settings']) ? $_POST['settings'] : array(); $settings = isset($_POST['settings']) ? $_POST['settings'] : array();
if ( ! is_array($settings) || empty($settings) ) { if (!is_array($settings) || empty($settings))
return array( 'error' => 'Invalid data. Please check and try again.' ); return array('error' => 'Invalid data. Please check and try again.');
}
$whitelist_options = array( $whitelist_options = array(
'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string', 'WPLANG' ), 'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string', 'WPLANG' ),
); );
if ( ! is_multisite() ) { if ( !is_multisite() ) {
if ( ! defined( 'WP_SITEURL' ) ) { if ( !defined( 'WP_SITEURL' ) )
$whitelist_options['general'][] = 'siteurl'; $whitelist_options['general'][] = 'siteurl';
} if ( !defined( 'WP_HOME' ) )
if ( ! defined( 'WP_HOME' ) ) {
$whitelist_options['general'][] = 'home'; $whitelist_options['general'][] = 'home';
}
$whitelist_options['general'][] = 'admin_email'; $whitelist_options['general'][] = 'admin_email';
$whitelist_options['general'][] = 'users_can_register'; $whitelist_options['general'][] = 'users_can_register';
$whitelist_options['general'][] = 'default_role'; $whitelist_options['general'][] = 'default_role';
} }
// $whitelist_options = apply_filters( 'whitelist_options', $whitelist_options ); //$whitelist_options = apply_filters( 'whitelist_options', $whitelist_options );
$whitelist_general = $whitelist_options['general']; $whitelist_general = $whitelist_options[ 'general' ];
// Handle translation install. // Handle translation install.
if ( ! empty( $settings['WPLANG'] ) ) { if ( ! empty( $settings['WPLANG'] ) ) {
require_once ABSPATH . 'wp-admin/includes/translation-install.php'; require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
if ( wp_can_install_language_pack() ) { if ( wp_can_install_language_pack() ) {
$language = wp_download_language_pack( $settings['WPLANG'] ); $language = wp_download_language_pack( $settings['WPLANG'] );
if ( $language ) { if ( $language ) {
@ -231,22 +223,20 @@ class MainWP_Child_Skeleton_Key {
} }
$updated = false; $updated = false;
foreach ( $settings as $option => $value ) { foreach($settings as $option => $value) {
if ( in_array($option, $whitelist_general) ) { if (in_array($option, $whitelist_general)) {
if ( ! is_array( $value ) ) { if ( ! is_array( $value ) )
$value = trim( $value ); $value = trim( $value );
}
$value = wp_unslash( $value ); $value = wp_unslash( $value );
update_option($option, $value); update_option($option, $value);
$updated = true; $updated = true;
} }
} }
if ( ! $updated ) { if (!$updated)
return false; return false;
}
return array( 'result' => 'ok' ); return array('result' => 'ok');
} }
} }

View file

@ -18,40 +18,37 @@
class MainWP_Child_Staging { class MainWP_Child_Staging {
public static $instance = null; public static $instance = null;
public $is_plugin_installed = false; public $is_plugin_installed = false;
static function Instance() { static function Instance() {
if ( null === self::$instance ) { if ( null === MainWP_Child_Staging::$instance ) {
self::$instance = new MainWP_Child_Staging(); MainWP_Child_Staging::$instance = new MainWP_Child_Staging();
} }
return self::$instance; return MainWP_Child_Staging::$instance;
} }
public function __construct() { public function __construct() {
require_once ABSPATH . 'wp-admin/includes/plugin.php'; require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( is_plugin_active( 'wp-staging/wp-staging.php' ) && defined('WPSTG_PLUGIN_DIR') ) { if ( is_plugin_active( 'wp-staging/wp-staging.php' ) && defined('WPSTG_PLUGIN_DIR')) {
$this->is_plugin_installed = true; $this->is_plugin_installed = true;
} elseif ( is_plugin_active( 'wp-staging-pro/wp-staging-pro.php' ) ) { } else if ( is_plugin_active( 'wp-staging-pro/wp-staging-pro.php' ) ) {
$this->is_plugin_installed = true; $this->is_plugin_installed = true;
} }
if ( ! $this->is_plugin_installed ) { if (!$this->is_plugin_installed)
return; return;
}
add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 );
} }
public function init() { public function init() {
if ( get_option( 'mainwp_wp_staging_ext_enabled' ) !== 'Y' ) { if ( get_option( 'mainwp_wp_staging_ext_enabled' ) !== 'Y' )
return; return;
}
if ( ! $this->is_plugin_installed ) { if (!$this->is_plugin_installed)
return; return;
}
if ( get_option( 'mainwp_wp_staging_hide_plugin' ) === 'hide' ) { if ( get_option( 'mainwp_wp_staging_hide_plugin' ) === 'hide' ) {
add_filter( 'all_plugins', array( $this, 'all_plugins' ) ); add_filter( 'all_plugins', array( $this, 'all_plugins' ) );
@ -63,9 +60,9 @@ class MainWP_Child_Staging {
public function syncOthersData( $information, $data = array() ) { public function syncOthersData( $information, $data = array() ) {
if ( isset( $data['syncWPStaging'] ) && $data['syncWPStaging'] ) { if ( isset( $data['syncWPStaging'] ) && $data['syncWPStaging'] ) {
try { try{
$information['syncWPStaging'] = $this->get_sync_data(); $information['syncWPStaging'] = $this->get_sync_data();
} catch ( Exception $e ) { } catch(Exception $e) {
// do not exit // do not exit
} }
} }
@ -77,75 +74,75 @@ class MainWP_Child_Staging {
} }
public function action() { public function action() {
if ( ! $this->is_plugin_installed ) { if (!$this->is_plugin_installed) {
MainWP_Helper::write( array( 'error' => 'Please install WP Staging plugin on child website' ) ); MainWP_Helper::write( array('error' => 'Please install WP Staging plugin on child website') );
} }
if ( ! class_exists( 'WPStaging\WPStaging' ) ) { if (!class_exists( 'WPStaging\WPStaging' )){
require_once WPSTG_PLUGIN_DIR . 'apps/Core/WPStaging.php'; require_once WPSTG_PLUGIN_DIR . "apps/Core/WPStaging.php";
} }
\WPStaging\WPStaging::getInstance(); \WPStaging\WPStaging::getInstance();
$information = array(); $information = array();
if ( get_option( 'mainwp_wp_staging_ext_enabled' ) !== 'Y' ) { if (get_option( 'mainwp_wp_staging_ext_enabled' ) !== 'Y') {
MainWP_Helper::update_option( 'mainwp_wp_staging_ext_enabled', 'Y', 'yes' ); MainWP_Helper::update_option( 'mainwp_wp_staging_ext_enabled', 'Y', 'yes' );
} }
if ( isset( $_POST['mwp_action'] ) ) { if ( isset( $_POST['mwp_action'] ) ) {
switch ( $_POST['mwp_action'] ) { switch ( $_POST['mwp_action'] ) {
case 'set_showhide': case 'set_showhide':
$information = $this->set_showhide(); $information = $this->set_showhide();
break; break;
case 'save_settings': case 'save_settings':
$information = $this->save_settings(); $information = $this->save_settings();
break; break;
case 'get_overview': case 'get_overview':
$information = $this->get_overview(); $information = $this->get_overview();
break; break;
case 'get_scan': case 'get_scan':
$information = $this->get_scan(); $information = $this->get_scan();
break; break;
case 'check_disk_space': case 'check_disk_space':
$information = $this->ajaxCheckFreeSpace(); $information = $this->ajaxCheckFreeSpace();
break; break;
case 'check_clone': case 'check_clone':
$information = $this->ajaxCheckCloneName(); $information = $this->ajaxCheckCloneName();
break; break;
case 'start_clone': case 'start_clone':
$information = $this->ajaxStartClone(); $information = $this->ajaxStartClone();
break; break;
case 'clone_database': case 'clone_database':
$information = $this->ajaxCloneDatabase(); $information = $this->ajaxCloneDatabase();
break; break;
case 'prepare_directories': case 'prepare_directories':
$information = $this->ajaxPrepareDirectories(); $information = $this->ajaxPrepareDirectories();
break; break;
case 'copy_files': case 'copy_files':
$information = $this->ajaxCopyFiles(); $information = $this->ajaxCopyFiles();
break; break;
case 'replace_data': case 'replace_data':
$information = $this->ajaxReplaceData(); $information = $this->ajaxReplaceData();
break; break;
case 'clone_finish': case 'clone_finish':
$information = $this->ajaxFinish(); $information = $this->ajaxFinish();
break; break;
case 'delete_confirmation': case 'delete_confirmation':
$information = $this->ajaxDeleteConfirmation(); $information = $this->ajaxDeleteConfirmation();
break; break;
case 'delete_clone': case 'delete_clone':
$information = $this->ajaxDeleteClone(); $information = $this->ajaxDeleteClone();
break; break;
case 'cancel_clone': case 'cancel_clone':
$information = $this->ajaxCancelClone(); $information = $this->ajaxCancelClone();
break; break;
case 'staging_update': case 'staging_update':
$information = $this->ajaxUpdateProcess(); $information = $this->ajaxUpdateProcess();
break; break;
case 'cancel_update': case 'cancel_update':
$information = $this->ajaxCancelUpdate(); $information = $this->ajaxCancelUpdate();
break; break;
} }
} }
MainWP_Helper::write( $information ); MainWP_Helper::write( $information );
} }
@ -158,7 +155,7 @@ class MainWP_Child_Staging {
function save_settings() { function save_settings() {
$settings = $_POST['settings']; $settings = $_POST['settings'];
$filters = array( $filters = array(
'queryLimit', 'queryLimit',
'fileLimit', 'fileLimit',
'batchSize', 'batchSize',
@ -167,27 +164,27 @@ class MainWP_Child_Staging {
'disableAdminLogin', 'disableAdminLogin',
'querySRLimit', 'querySRLimit',
'maxFileSize', 'maxFileSize',
// 'wpSubDirectory', // removed //'wpSubDirectory', // removed
'debugMode', 'debugMode',
'unInstallOnDelete', 'unInstallOnDelete',
'checkDirectorySize', 'checkDirectorySize',
'optimizer', 'optimizer',
// 'loginSlug' // removed //'loginSlug' // removed
); );
$save_fields = array(); $save_fields = array();
foreach ( $filters as $field ) { foreach($filters as $field) {
if ( isset($settings[ $field ]) ) { if (isset($settings[$field])) {
$save_fields[ $field ] = $settings[ $field ]; $save_fields[$field] = $settings[$field];
} }
} }
update_option('wpstg_settings', $save_fields ); update_option('wpstg_settings', $save_fields );
return array( 'result' => 'success' ); return array('result' => 'success');
} }
public function get_overview() { public function get_overview() {
$return = array( $return = array(
'availableClones' => get_option( 'wpstg_existing_clones_beta', array()), 'availableClones' => get_option( "wpstg_existing_clones_beta", array())
); );
return $return; return $return;
} }
@ -201,195 +198,198 @@ class MainWP_Child_Staging {
$options = $scan->getOptions(); $options = $scan->getOptions();
$return = array( $return = array(
'options' => serialize($options), 'options' => serialize($options),
'directoryListing' => $scan->directoryListing(), 'directoryListing' => $scan->directoryListing(),
'prefix' => WPStaging\WPStaging::getTablePrefix(), 'prefix' => WPStaging\WPStaging::getTablePrefix()
); );
return $return; return $return;
} }
public function ajaxCheckCloneName() { public function ajaxCheckCloneName() {
$cloneName = sanitize_key( $_POST['cloneID'] ); $cloneName = sanitize_key( $_POST["cloneID"] );
$cloneNameLength = strlen( $cloneName ); $cloneNameLength = strlen( $cloneName );
$clones = get_option( 'wpstg_existing_clones_beta', array() ); $clones = get_option( "wpstg_existing_clones_beta", array() );
// Check clone name length // Check clone name length
if ( $cloneNameLength < 1 || $cloneNameLength > 16 ) { if( $cloneNameLength < 1 || $cloneNameLength > 16 ) {
echo array( echo array(
'status' => 'failed', "status" => "failed",
'message' => 'Clone name must be between 1 - 16 characters', "message" => "Clone name must be between 1 - 16 characters"
); );
} elseif ( array_key_exists( $cloneName, $clones ) ) { } elseif( array_key_exists( $cloneName, $clones ) ) {
return array( return array(
'status' => 'failed', "status" => "failed",
'message' => 'Clone name is already in use, please choose an another clone name', "message" => "Clone name is already in use, please choose an another clone name"
); );
} }
return array( 'status' => 'success' ); return array("status" => "success");
} }
public function ajaxStartClone() { public function ajaxStartClone() {
$this->url = ''; // to fix warning $this->url = ''; // to fix warning
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning(); $cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
if ( ! $cloning->save() ) {
return;
}
ob_start(); if( !$cloning->save() ) {
require_once WPSTG_PLUGIN_DIR . 'apps/Backend/views/clone/ajax/start.php'; return;
$result = ob_get_clean(); }
return $result;
} ob_start();
require_once WPSTG_PLUGIN_DIR . "apps/Backend/views/clone/ajax/start.php";
$result = ob_get_clean();
return $result;
}
public function ajaxCloneDatabase() { public function ajaxCloneDatabase() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning(); $cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
return $cloning->start(); return $cloning->start();
} }
/** /**
* Ajax Prepare Directories (get listing of files) * Ajax Prepare Directories (get listing of files)
*/ */
public function ajaxPrepareDirectories() { public function ajaxPrepareDirectories() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning(); $cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
return $cloning->start(); return $cloning->start();
} }
/** /**
* Ajax Clone Files * Ajax Clone Files
*/ */
public function ajaxCopyFiles() { public function ajaxCopyFiles() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning(); $cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
return $cloning->start(); return $cloning->start();
} }
/** /**
* Ajax Replace Data * Ajax Replace Data
*/ */
public function ajaxReplaceData() { public function ajaxReplaceData() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning(); $cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
return $cloning->start(); return $cloning->start();
} }
/** /**
* Ajax Finish * Ajax Finish
*/ */
public function ajaxFinish() { public function ajaxFinish() {
$cloning = new WPStaging\Backend\Modules\Jobs\Cloning(); $cloning = new WPStaging\Backend\Modules\Jobs\Cloning();
$this->url = ''; // to fix warning $this->url = ''; // to fix warning
$return = $cloning->start(); $return = $cloning->start();
$return->blogInfoName = get_bloginfo('name'); $return->blogInfoName = get_bloginfo("name");
return $return; return $return;
} }
/** /**
* Ajax Delete Confirmation * Ajax Delete Confirmation
*/ */
public function ajaxDeleteConfirmation() { public function ajaxDeleteConfirmation() {
$delete = new WPStaging\Backend\Modules\Jobs\Delete(); $delete = new WPStaging\Backend\Modules\Jobs\Delete();
$delete->setData(); $delete->setData();
$clone = $delete->getClone(); $clone = $delete->getClone();
$result = array( $result = array(
'clone' => $clone, 'clone' => $clone,
'deleteTables' => $delete->getTables(), 'deleteTables' => $delete->getTables()
); );
return $result; return $result;
} }
/** /**
* Delete clone * Delete clone
*/ */
public function ajaxDeleteClone() { public function ajaxDeleteClone() {
$delete = new WPStaging\Backend\Modules\Jobs\Delete(); $delete = new WPStaging\Backend\Modules\Jobs\Delete();
return $delete->start(); return $delete->start();
} }
/** /**
* Delete clone * Delete clone
*/ */
public function ajaxCancelClone() { public function ajaxCancelClone() {
$cancel = new WPStaging\Backend\Modules\Jobs\Cancel(); $cancel = new WPStaging\Backend\Modules\Jobs\Cancel();
return $cancel->start(); return $cancel->start();
} }
public function ajaxCancelUpdate() { public function ajaxCancelUpdate() {
$cancel = new WPStaging\Backend\Modules\Jobs\CancelUpdate(); $cancel = new WPStaging\Backend\Modules\Jobs\CancelUpdate();
return $cancel->start(); return $cancel->start();
} }
public function ajaxUpdateProcess() { public function ajaxUpdateProcess() {
$cloning = new WPStaging\Backend\Modules\Jobs\Updating(); $cloning = new WPStaging\Backend\Modules\Jobs\Updating();
if ( ! $cloning->save() ) { if( !$cloning->save() ) {
return; return;
} }
ob_start(); ob_start();
require_once WPSTG_PLUGIN_DIR . 'apps/Backend/views/clone/ajax/update.php'; require_once WPSTG_PLUGIN_DIR . "apps/Backend/views/clone/ajax/update.php";
$result = ob_get_clean(); $result = ob_get_clean();
return $result; return $result;
} }
public function ajaxCheckFreeSpace() { public function ajaxCheckFreeSpace() {
return $this->hasFreeDiskSpace(); return $this->hasFreeDiskSpace();
} }
// from wp-staging plugin // from wp-staging plugin
public function hasFreeDiskSpace() { public function hasFreeDiskSpace() {
if ( ! function_exists( 'disk_free_space' ) ) { if( !function_exists( "disk_free_space" ) ) {
return null; return null;
} }
$freeSpace = @disk_free_space( ABSPATH ); $freeSpace = @disk_free_space( ABSPATH );
if ( false === $freeSpace ) { if( false === $freeSpace ) {
$data = array( $data = array(
'freespace' => false, 'freespace' => false,
'usedspace' => $this->formatSize($this->getDirectorySizeInclSubdirs(ABSPATH)), 'usedspace' => $this->formatSize($this->getDirectorySizeInclSubdirs(ABSPATH))
); );
return $data; return $data;
} }
$data = array( $data = array(
'freespace' => $this->formatSize($freeSpace), 'freespace' => $this->formatSize($freeSpace),
'usedspace' => $this->formatSize($this->getDirectorySizeInclSubdirs(ABSPATH)), 'usedspace' => $this->formatSize($this->getDirectorySizeInclSubdirs(ABSPATH))
); );
return $data; return $data;
} }
// from wp-staging plugin // from wp-staging plugin
function getDirectorySizeInclSubdirs( $dir ) { function getDirectorySizeInclSubdirs( $dir ) {
$size = 0; $size = 0;
foreach ( glob( rtrim( $dir, '/' ) . '/*', GLOB_NOSORT ) as $each ) { foreach ( glob( rtrim( $dir, '/' ) . '/*', GLOB_NOSORT ) as $each ) {
$size += is_file( $each ) ? filesize( $each ) : $this->getDirectorySizeInclSubdirs( $each ); $size += is_file( $each ) ? filesize( $each ) : $this->getDirectorySizeInclSubdirs( $each );
} }
return $size; return $size;
} }
// from wp-staging plugin // from wp-staging plugin
public function formatSize( $bytes, $precision = 2 ) { public function formatSize($bytes, $precision = 2)
if ( (float) $bytes < 1 ) { {
if ((double) $bytes < 1)
{
return ''; return '';
} }
$units = array( 'B', 'KB', 'MB', 'GB', 'TB' ); $units = array('B', "KB", "MB", "GB", "TB");
$bytes = (float) $bytes; $bytes = (double) $bytes;
$base = log($bytes) / log(1000); // 1024 would be for MiB KiB etc $base = log($bytes) / log(1000); // 1024 would be for MiB KiB etc
$pow = pow(1000, $base - floor($base)); // Same rule for 1000 $pow = pow(1000, $base - floor($base)); // Same rule for 1000
return round($pow, $precision) . ' ' . $units[ (int) floor($base) ]; return round($pow, $precision) . ' ' . $units[(int) floor($base)];
} }
@ -423,7 +423,7 @@ class MainWP_Child_Staging {
return $value; return $value;
} }
if ( ! MainWP_Helper::is_screen_with_update() ) { if (! MainWP_Helper::is_screen_with_update()) {
return $value; return $value;
} }

View file

@ -29,11 +29,11 @@ class MainWP_Child_Themes_Check {
private $option_name_last_daily_run = 'mainwp_child_theme_last_daily_run'; private $option_name_last_daily_run = 'mainwp_child_theme_last_daily_run';
public static function Instance() { public static function Instance() {
if ( null === self::$instance ) { if ( null === MainWP_Child_Themes_Check::$instance ) {
self::$instance = new MainWP_Child_Themes_Check(); MainWP_Child_Themes_Check::$instance = new MainWP_Child_Themes_Check();
} }
return self::$instance; return MainWP_Child_Themes_Check::$instance;
} }
public function __construct() { public function __construct() {
@ -49,6 +49,7 @@ class MainWP_Child_Themes_Check {
add_action( 'mainwp_child_deactivation', array( $this, 'cleanup_deactivation' ) ); add_action( 'mainwp_child_deactivation', array( $this, 'cleanup_deactivation' ) );
} }
} }
private function cleanup_basic() { private function cleanup_basic() {
@ -95,7 +96,7 @@ class MainWP_Child_Themes_Check {
$last_run = new \DateTime( '@' . $last_run ); $last_run = new \DateTime( '@' . $last_run );
} }
// Get now //Get now
$now = new \DateTime(); $now = new \DateTime();
if ( false === $last_run || (int) $now->diff( $last_run )->format( '%h' ) >= 24 ) { if ( false === $last_run || (int) $now->diff( $last_run )->format( '%h' ) >= 24 ) {
@ -110,13 +111,14 @@ class MainWP_Child_Themes_Check {
} }
public function schedule_watchdog() { public function schedule_watchdog() {
// For testing //For testing
// $this->cleanup_deactivation(); //$this->cleanup_deactivation();
// Schedule a global watching cron just in case both other crons get killed //Schedule a global watching cron just in case both other crons get killed
if ( ! wp_next_scheduled( $this->cron_name_watcher ) ) { if ( ! wp_next_scheduled( $this->cron_name_watcher ) ) {
wp_schedule_event( time(), 'hourly', $this->cron_name_watcher ); wp_schedule_event( time(), 'hourly', $this->cron_name_watcher );
} }
} }
public function get_themes_outdate_info() { public function get_themes_outdate_info() {
@ -125,7 +127,7 @@ class MainWP_Child_Themes_Check {
$themes_outdate = array(); $themes_outdate = array();
} }
if ( ! function_exists( 'wp_get_themes' ) ) { if ( ! function_exists( 'wp_get_themes' ) ) {
require_once ABSPATH . '/wp-admin/includes/theme.php'; require_once( ABSPATH . '/wp-admin/includes/theme.php' );
} }
$themes = wp_get_themes(); $themes = wp_get_themes();
$update = false; $update = false;
@ -144,10 +146,10 @@ class MainWP_Child_Themes_Check {
public function run_check() { public function run_check() {
if ( ! function_exists( 'wp_get_themes' ) ) { if ( ! function_exists( 'wp_get_themes' ) ) {
require_once ABSPATH . '/wp-admin/includes/theme.php'; require_once( ABSPATH . '/wp-admin/includes/theme.php' );
} }
// Get our previous results //Get our previous results
$responses = get_transient( $this->tran_name_theme_timestamps ); $responses = get_transient( $this->tran_name_theme_timestamps );
if ( false === $responses || ! is_array( $responses ) ) { if ( false === $responses || ! is_array( $responses ) ) {
@ -155,10 +157,10 @@ class MainWP_Child_Themes_Check {
} }
$all_themes = get_transient( $this->tran_name_themes_to_batch ); $all_themes = get_transient( $this->tran_name_themes_to_batch );
// If there wasn't a previous cache //If there wasn't a previous cache
if ( false === $all_themes || ! is_array( $all_themes ) ) { if ( false === $all_themes || ! is_array( $all_themes ) ) {
$all_themes = array(); $all_themes = array();
$themes = wp_get_themes(); $themes = wp_get_themes();
if ( is_array( $themes ) ) { if ( is_array( $themes ) ) {
foreach ( $themes as $theme ) { foreach ( $themes as $theme ) {
$slug = $theme->get_stylesheet(); $slug = $theme->get_stylesheet();
@ -172,14 +174,12 @@ class MainWP_Child_Themes_Check {
$responses = array(); $responses = array();
} }
$avoid_themes = array( 'superstore' ); $avoid_themes = array( 'superstore' );
$themes_to_scan = array_splice( $all_themes, 0, apply_filters( 'mainwp_child_theme_health_check_max_themes_to_batch', 10 ) ); $themes_to_scan = array_splice( $all_themes, 0, apply_filters( 'mainwp_child_theme_health_check_max_themes_to_batch', 10 ) );
$tolerance_in_days = get_option( 'mainwp_child_plugintheme_days_outdate', 365 ); $tolerance_in_days = get_option( 'mainwp_child_plugintheme_days_outdate', 365 );
foreach ( $themes_to_scan as $slug => $v ) { foreach ( $themes_to_scan as $slug => $v ) {
if ( in_array( $slug, $avoid_themes ) ) { if ( in_array( $slug, $avoid_themes ) ) continue;
continue;
}
$body = $this->try_get_response_body( $slug, false ); $body = $this->try_get_response_body( $slug, false );
@ -187,18 +187,19 @@ class MainWP_Child_Themes_Check {
continue; continue;
} }
// Deserialize the response //Deserialize the response
$obj = maybe_unserialize( $body ); $obj = maybe_unserialize( $body );
$now = new \DateTime(); $now = new \DateTime();
// Sanity check that deserialization worked and that our property exists //Sanity check that deserialization worked and that our property exists
if ( false !== $obj && is_object( $obj ) && property_exists( $obj, 'last_updated' ) ) { if ( false !== $obj && is_object( $obj ) && property_exists( $obj, 'last_updated' ) ) {
$last_updated = strtotime( $obj->last_updated ); $last_updated = strtotime( $obj->last_updated );
$theme_last_updated_date = new \DateTime( '@' . $last_updated ); $theme_last_updated_date = new \DateTime( '@' . $last_updated );
$diff_in_days = $now->diff( $theme_last_updated_date )->format( '%a' ); $diff_in_days = $now->diff( $theme_last_updated_date )->format( '%a' );
if ( $diff_in_days < $tolerance_in_days ) { if ( $diff_in_days < $tolerance_in_days ) {
continue; continue;
} }
@ -213,7 +214,7 @@ class MainWP_Child_Themes_Check {
define( 'DAY_IN_SECONDS', 24 * 60 * 60 ); define( 'DAY_IN_SECONDS', 24 * 60 * 60 );
} }
// Store the master response for usage in the plugin table //Store the master response for usage in the plugin table
set_transient( $this->tran_name_theme_timestamps, $responses, DAY_IN_SECONDS ); set_transient( $this->tran_name_theme_timestamps, $responses, DAY_IN_SECONDS );
if ( 0 === count( $all_themes ) ) { if ( 0 === count( $all_themes ) ) {
@ -227,21 +228,15 @@ class MainWP_Child_Themes_Check {
private function try_get_response_body( $theme ) { private function try_get_response_body( $theme ) {
// Get the WordPress current version to be polite in the API call //Get the WordPress current version to be polite in the API call
include ABSPATH . WPINC . '/version.php'; include( ABSPATH . WPINC . '/version.php' );
$url = $http_url = 'http://api.wordpress.org/themes/info/1.0/'; $url = $http_url = 'http://api.wordpress.org/themes/info/1.0/';
if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) { if ( $ssl = wp_http_supports( array( 'ssl' ) ) ) {
$url = set_url_scheme( $url, 'https' ); $url = set_url_scheme( $url, 'https' );
} }
$args = array( $args = array( 'slug' => $theme, 'fields' => array( 'sections' => false, 'tags' => false ) );
'slug' => $theme,
'fields' => array(
'sections' => false,
'tags' => false,
),
);
$args = (object) $args; $args = (object) $args;
$http_args = array( $http_args = array(
@ -254,20 +249,20 @@ class MainWP_Child_Themes_Check {
$raw_response = wp_remote_post( $url, $http_args ); $raw_response = wp_remote_post( $url, $http_args );
if ( ! is_wp_error( $raw_response ) && 200 === (int) wp_remote_retrieve_response_code( $raw_response ) ) { if ( ! is_wp_error( $raw_response ) && 200 === (int) wp_remote_retrieve_response_code( $raw_response ) ) {
// Get the actual body //Get the actual body
// Requires WP 2.7.0 //Requires WP 2.7.0
$body = wp_remote_retrieve_body( $raw_response ); $body = wp_remote_retrieve_body( $raw_response );
// Make sure that it isn't empty and also not an empty serialized object //Make sure that it isn't empty and also not an empty serialized object
if ( '' !== $body && 'N;' !== $body ) { if ( '' !== $body && 'N;' !== $body ) {
// If valid, return that //If valid, return that
return $body; return $body;
} }
} }
// The above valid //The above valid
// If we previously tried an SSL version try without SSL //If we previously tried an SSL version try without SSL
// Code below same as above block //Code below same as above block
if ( $ssl ) { if ( $ssl ) {
$raw_response = wp_remote_post( $http_url, $http_args ); $raw_response = wp_remote_post( $http_url, $http_args );
@ -279,7 +274,7 @@ class MainWP_Child_Themes_Check {
} }
} }
// Everything above failed, bail //Everything above failed, bail
return false; return false;
} }
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,7 @@
<?php <?php
/**
/*
*
* Credits * Credits
* *
* Plugin-Name: Vulnerability Alerts * Plugin-Name: Vulnerability Alerts
@ -16,214 +18,226 @@
class MainWP_Child_Vulnerability_Checker { class MainWP_Child_Vulnerability_Checker {
public static $instance = null; public static $instance = null;
private $wpvulndb_api = 'https://wpvulndb.com/api/v3/'; private $wpvulndb_api = 'https://wpvulndb.com/api/v3/';
private $wpvulndb_token = false; private $wpvulndb_token = false;
public static function Instance() { static function Instance() {
if ( null === self::$instance ) { if ( null === MainWP_Child_Vulnerability_Checker::$instance ) {
self::$instance = new MainWP_Child_Vulnerability_Checker(); MainWP_Child_Vulnerability_Checker::$instance = new MainWP_Child_Vulnerability_Checker();
} }
return self::$instance; return MainWP_Child_Vulnerability_Checker::$instance;
} }
public function __construct() { public function __construct() {
$this->wpvulndb_token = get_option( 'mainwp_child_wpvulndb_token', '' ); $this->wpvulndb_token = get_option('mainwp_child_wpvulndb_token', '');
} }
public function action() { public function action() {
$information = array(); $information = array();
if ( ! empty( $this->wpvulndb_token ) ) {
if ( isset( $_POST['mwp_action'] ) ) { if ( ! empty( $this->wpvulndb_token ) ) {
switch ( $_POST['mwp_action'] ) { if ( isset( $_POST['mwp_action'] ) ) {
case 'vulner_recheck': switch ( $_POST['mwp_action'] ) {
$information = $this->vulner_recheck(); case 'vulner_recheck':
break; $information = $this->vulner_recheck();
break;
}
} }
} }
}
MainWP_Helper::write( $information ); MainWP_Helper::write( $information );
} }
public function vulner_recheck() { function vulner_recheck(){
$result = array(); $result = array();
$force = ( isset( $_POST['force'] ) && ! empty( $_POST['force'] ) ) ? true : false; $force = (isset($_POST['force']) && !empty($_POST['force'])) ? true : false;
$result['plugin'] = $this->check_plugins( $force ); $result['plugin'] = $this->check_plugins($force);
$result['wp'] = $this->check_wp( $force ); $result['wp'] = $this->check_wp($force);
$result['theme'] = $this->check_themes( $force ); $result['theme'] = $this->check_themes($force);
$information = array( $information = array( 'result' => $result, 'ok' => 1);
'result' => $result, return $information;
'ok' => 1, }
);
return $information;
}
public function check_plugins( $force = false ) { function check_plugins($force = false){
$result = array(); $result = array();
$active_plugins = get_option( 'active_plugins' ); $active_plugins = get_option('active_plugins');
if ( ! empty( $active_plugins ) ) { if( !empty($active_plugins) ){
foreach ( $active_plugins as $plug ) { foreach($active_plugins as $plug){
$plugin_file = WP_CONTENT_DIR . '/plugins/' . $plug; $plugin_file = WP_CONTENT_DIR . '/plugins/' . $plug;
$plugin_info = get_plugin_data( $plugin_file ); $plugin_info = get_plugin_data($plugin_file);
$plugin_version = isset( $plugin_info['Version'] ) ? $plugin_info['Version'] : ''; $plugin_version = isset($plugin_info['Version']) ? $plugin_info['Version'] : '';
$string = explode( '/', $plug ); $string = explode('/',$plug);
$plug_vuln = get_transient( 'mainwp_vulnche_trans_plug_' . $string[0] ); $plug_vuln = get_transient('mainwp_vulnche_trans_plug_'.$string[0]);
if ( false === $plug_vuln || $force ) { if(false === $plug_vuln || $force) {
$plug_vuln = $this->vulnche_get_content( $this->wpvulndb_api . 'plugins/' . $string[0] ); $plug_vuln = $this->vulnche_get_content( $this->wpvulndb_api . 'plugins/' . $string[0]);
set_transient( 'mainwp_vulnche_trans_plug_' . $string[0], $plug_vuln, 1 * DAY_IN_SECONDS ); set_transient('mainwp_vulnche_trans_plug_'.$string[0],$plug_vuln, 1 * DAY_IN_SECONDS);
} }
if ( $plug_vuln ) { if ($plug_vuln) {
$plug_vuln = json_decode( $plug_vuln, true ); $plug_vuln = json_decode($plug_vuln, true);
$plug_vuln_filter = $plug_vuln; $plug_vuln_filter = $plug_vuln;
foreach ( $plug_vuln as $slug => $pl_data ) {
if ( isset( $pl_data['vulnerabilities'] ) && count( $pl_data['vulnerabilities'] ) > 0 ) {
$plug_vulner_data = array();
foreach ( $pl_data['vulnerabilities'] as $vuln_data ) {
if ( isset( $vuln_data['fixed_in'] ) && version_compare( $plugin_version, $vuln_data['fixed_in'] ) >= 0 ) {
continue;
}
$plug_vulner_data[] = $vuln_data;
}
if ( 0 == count( $plug_vulner_data ) ) { foreach ($plug_vuln as $slug => $pl_data) {
unset( $plug_vuln_filter[ $slug ] ); if (isset($pl_data['vulnerabilities']) && count($pl_data['vulnerabilities']) > 0) {
} else { $plug_vulner_data = array();
$plug_vuln_filter[ $slug ]['vulnerabilities'] = $plug_vulner_data; foreach($pl_data['vulnerabilities'] as $vuln_data) {
$plug_vuln_filter[ $slug ]['detected_version'] = $plugin_version; if ( isset($vuln_data['fixed_in']) && version_compare( $plugin_version, $vuln_data['fixed_in'] ) >= 0 ) {
$plug_vuln_filter[ $slug ]['plugin_slug'] = $plug; continue;
} }
} else { $plug_vulner_data[] = $vuln_data;
unset( $plug_vuln_filter[ $slug ] ); }
}
}
if ( 0 == count( $plug_vuln_filter ) ) { if(count($plug_vulner_data) == 0) {
continue; unset($plug_vuln_filter[$slug]);
} } else {
$plug_vuln = json_encode( $plug_vuln_filter ); $plug_vuln_filter[$slug]['vulnerabilities'] = $plug_vulner_data;
} else { $plug_vuln_filter[$slug]['detected_version'] = $plugin_version;
continue; $plug_vuln_filter[$slug]['plugin_slug'] = $plug;
} }
$result[ $plug ] = $plug_vuln;
}
}
return $result;
}
public function check_wp( $force = false ) { } else {
$wp_vuln = get_transient( 'mainwp_vulnche_trans_wp_json' ); unset($plug_vuln_filter[$slug]);
$wp_version = str_replace( '.', '', get_bloginfo( 'version' ) ); }
if ( false === $wp_vuln || $force ) {
$wp_vuln = $this->vulnche_get_content( $this->wpvulndb_api . 'wordpresses/' . $wp_version );
set_transient( 'mainwp_vulnche_trans_wp_json', $wp_vuln, 1 * DAY_IN_SECONDS );
}
return $wp_vuln;
}
public function check_themes( $force = false ) { }
require_once ABSPATH . 'wp-admin/includes/misc.php'; if (count($plug_vuln_filter) == 0) {
require_once ABSPATH . 'wp-admin/includes/theme.php'; continue;
}
$plug_vuln = json_encode($plug_vuln_filter);
if ( current_user_can( 'switch_themes' ) ) { } else {
$themes = wp_prepare_themes_for_js(); continue;
} else { }
$themes = wp_prepare_themes_for_js( array( wp_get_theme() ) ); $result[$plug] = $plug_vuln;
} }
wp_reset_vars( array( 'theme', 'search' ) ); }
$result = array(); return $result;
if ( ! empty( $themes ) ) { }
foreach ( $themes as $th ) {
if ( empty( $th['parent'] ) ) {
$th_vuln = get_transient( 'mainwp_vulnche_trans_theme_' . $th['id'] );
if ( false === $th_vuln || $force ) {
$th_vuln = $this->vulnche_get_content( $this->wpvulndb_api . 'themes/' . $th['id'] );
set_transient( 'mainwp_vulnche_trans_theme_' . $th['id'], $th_vuln, 1 * DAY_IN_SECONDS );
}
if ( $th_vuln ) { function check_wp($force = false){
$th_vuln = json_decode( $th_vuln, true ); $wp_vuln = get_transient('mainwp_vulnche_trans_wp_json');
$th_vuln_filter = $th_vuln; $wp_version = str_replace('.', '', get_bloginfo('version'));
foreach ( $th_vuln as $slug => $th_data ) { if(false === $wp_vuln || $force) {
if ( isset( $th_data['vulnerabilities'] ) && count( $th_data['vulnerabilities'] ) > 0 ) { $wp_vuln = $this->vulnche_get_content( $this->wpvulndb_api . 'wordpresses/' . $wp_version);
$th_vulner_data = array(); set_transient('mainwp_vulnche_trans_wp_json', $wp_vuln, 1 * DAY_IN_SECONDS);
foreach ( $th_data['vulnerabilities'] as $vuln_data ) { }
if ( empty( $vuln_data ) ) { return $wp_vuln;
continue; }
}
if ( isset( $vuln_data['fixed_in'] ) && version_compare( $th['version'], $vuln_data['fixed_in'] ) >= 0 ) { function check_themes($force = false){
continue;
} require_once( ABSPATH . 'wp-admin/includes/misc.php' );
$th_vulner_data[] = $vuln_data; require_once( ABSPATH . 'wp-admin/includes/theme.php' );
}
if ( 0 == count( $th_vulner_data ) ) { if ( current_user_can( 'switch_themes' ) ) {
unset( $th_vuln_filter[ $slug ] ); $themes = wp_prepare_themes_for_js();
} else { } else {
$th_vuln_filter[ $slug ]['vulnerabilities'] = $th_vulner_data; $themes = wp_prepare_themes_for_js( array( wp_get_theme() ) );
} }
} else { wp_reset_vars( array( 'theme', 'search' ) );
unset( $th_vuln_filter[ $slug ] ); $result = array();
} if(!empty($themes)){
} foreach($themes as $th){
if ( 0 == count( $th_vuln_filter ) ) { if(empty($th['parent'])) {
continue; $th_vuln = get_transient('mainwp_vulnche_trans_theme_' . $th['id']);
} if (false === $th_vuln || $force) {
$th_vuln = json_encode( $th_vuln_filter ); $th_vuln = $this->vulnche_get_content( $this->wpvulndb_api . 'themes/' . $th['id']);
} else { set_transient('mainwp_vulnche_trans_theme_' . $th['id'], $th_vuln, 1 * DAY_IN_SECONDS);
continue; }
}
$result[ $th['id'] ]['vulner_data'] = $th_vuln; if ($th_vuln) {
$result[ $th['id'] ]['name'] = $th['name']; $th_vuln = json_decode($th_vuln, true);
$result[ $th['id'] ]['author'] = $th['author']; $th_vuln_filter = $th_vuln;
$result[ $th['id'] ]['detected_version'] = $th['version']; foreach ($th_vuln as $slug => $th_data) {
} if (isset($th_data['vulnerabilities']) && count($th_data['vulnerabilities']) > 0) {
}
} $th_vulner_data = array();
return $result; foreach($th_data['vulnerabilities'] as $vuln_data) {
} if (empty($vuln_data))
continue;
if ( isset($vuln_data['fixed_in']) && version_compare( $th['version'], $vuln_data['fixed_in'] ) >= 0 ) {
continue;
}
$th_vulner_data[] = $vuln_data;
}
if(count($th_vulner_data) == 0) {
unset($th_vuln_filter[$slug]);
} else {
$th_vuln_filter[$slug]['vulnerabilities'] = $th_vulner_data;
}
} else {
unset($th_vuln_filter[$slug]);
}
}
if (count($th_vuln_filter) == 0) {
continue;
}
$th_vuln = json_encode($th_vuln_filter);
} else {
continue;
}
$result[$th['id']]['vulner_data'] = $th_vuln;
$result[$th['id']]['name'] = $th['name'];
$result[$th['id']]['author'] = $th['author'];
$result[$th['id']]['detected_version'] = $th['version'];
}
}
}
return $result;
}
public function vulnche_get_content( $url ) { function vulnche_get_content ( $url ) {
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_HEADER, 0 );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'Authorization: Token token=' . $this->wpvulndb_token ) );
curl_setopt( $ch, CURLOPT_USERAGENT, $this->get_random_user_agent() );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch ); $ch = curl_init();
$info = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
curl_close( $ch ); curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Token token=' . $this->wpvulndb_token));
curl_setopt($ch, CURLOPT_USERAGENT, $this->get_random_user_agent());
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
if ( false === $output || 200 != $info ) { $output = curl_exec($ch);
$output = null; $info = curl_getinfo($ch, CURLINFO_HTTP_CODE);
}
return $output;
}
public function get_random_user_agent() { curl_close($ch);
$someUA = array( if ($output === false || $info != 200) {
'Mozilla/5.0 (Windows; U; Windows NT 6.0; fr; rv:1.9.1b1) Gecko/20081007 Firefox/3.1b1', $output = null;
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.0', }
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/0.4.154.18 Safari/525.19', return $output;
'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13', }
'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)',
'Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.40607)',
'Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322)',
'Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.0.3705; Media Center PC 3.1; Alexa Toolbar; .NET CLR 1.1.4322; .NET CLR 2.0.50727)',
'Mozilla/45.0 (compatible; MSIE 6.0; Windows NT 5.1)',
'Mozilla/4.08 (compatible; MSIE 6.0; Windows NT 5.1)',
'Mozilla/4.01 (compatible; MSIE 6.0; Windows NT 5.1)',
);
srand( (float) microtime() * 1000000 );
return $someUA[ rand( 0, count( $someUA ) - 1 ) ]; function get_random_user_agent ( ) {
}
$someUA = array (
"Mozilla/5.0 (Windows; U; Windows NT 6.0; fr; rv:1.9.1b1) Gecko/20081007 Firefox/3.1b1",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.0",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/0.4.154.18 Safari/525.19",
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13",
"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)",
"Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.40607)",
"Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322)",
"Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.0.3705; Media Center PC 3.1; Alexa Toolbar; .NET CLR 1.1.4322; .NET CLR 2.0.50727)",
"Mozilla/45.0 (compatible; MSIE 6.0; Windows NT 5.1)",
"Mozilla/4.08 (compatible; MSIE 6.0; Windows NT 5.1)",
"Mozilla/4.01 (compatible; MSIE 6.0; Windows NT 5.1)"
);
srand((double)microtime()*1000000);
return $someUA[rand(0,count($someUA)-1)];
}
} }

View file

@ -18,23 +18,25 @@ class MainWP_Child_WooCommerce_Status {
public static $instance = null; public static $instance = null;
static function Instance() { static function Instance() {
if ( null === self::$instance ) { if ( null === MainWP_Child_WooCommerce_Status::$instance ) {
self::$instance = new MainWP_Child_WooCommerce_Status(); MainWP_Child_WooCommerce_Status::$instance = new MainWP_Child_WooCommerce_Status();
} }
return self::$instance; return MainWP_Child_WooCommerce_Status::$instance;
} }
public function __construct() { public function __construct() {
add_action( 'mainwp_child_deactivation', array( $this, 'child_deactivation' ) ); add_action( 'mainwp_child_deactivation', array( $this, 'child_deactivation' ) );
} }
public function child_deactivation() { public function child_deactivation() {
} }
public function action() { public function action() {
$information = array(); $information = array();
if ( ! class_exists( 'WooCommerce' ) || ! defined('WC_VERSION')) { if ( ! class_exists( 'WooCommerce' ) || !defined('WC_VERSION')) {
$information['error'] = 'NO_WOOCOMMERCE'; $information['error'] = 'NO_WOOCOMMERCE';
MainWP_Helper::write( $information ); MainWP_Helper::write( $information );
} }
@ -64,7 +66,7 @@ class MainWP_Child_WooCommerce_Status {
global $wpdb; global $wpdb;
$file = WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php'; $file = WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php';
if ( file_exists( $file ) ) { if ( file_exists( $file ) ) {
include_once $file; include_once( $file );
} else { } else {
return false; return false;
} }
@ -81,15 +83,17 @@ class MainWP_Child_WooCommerce_Status {
AND posts.post_status = 'publish' AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status' AND tax.taxonomy = 'shop_order_status'
AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array(
'completed', 'completed',
'processing', 'processing',
'on-hold', 'on-hold',
) ) ) . "' ) ) ) ) . "' )
AND postmeta.meta_key = '_order_total' AND postmeta.meta_key = '_order_total'
AND posts.post_date >= %s AND posts.post_date >= %s
AND posts.post_date <= %s AND posts.post_date <= %s
", date( 'Y-m-01', $start_date ), date( 'Y-m-d H:i:s', $end_date ) ) ); ", date( 'Y-m-01', $start_date ), date( 'Y-m-d H:i:s', $end_date ) ) );
// Get top seller // Get top seller
$top_seller = $wpdb->get_row( $wpdb->prepare( "SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id $top_seller = $wpdb->get_row( $wpdb->prepare( "SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id
FROM {$wpdb->posts} as posts FROM {$wpdb->posts} as posts
@ -103,10 +107,10 @@ class MainWP_Child_WooCommerce_Status {
AND posts.post_status = 'publish' AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status' AND tax.taxonomy = 'shop_order_status'
AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array(
'completed', 'completed',
'processing', 'processing',
'on-hold', 'on-hold',
) ) ) . "' ) ) ) ) . "' )
AND order_item_meta.meta_key = '_qty' AND order_item_meta.meta_key = '_qty'
AND order_item_meta_2.meta_key = '_product_id' AND order_item_meta_2.meta_key = '_product_id'
AND posts.post_date >= %s AND posts.post_date >= %s
@ -114,7 +118,7 @@ class MainWP_Child_WooCommerce_Status {
GROUP BY product_id GROUP BY product_id
ORDER BY qty DESC ORDER BY qty DESC
LIMIT 1 LIMIT 1
", date( 'Y-m-01', $start_date ), date( 'Y-m-d H:i:s', $end_date )) ); ", date( 'Y-m-01', $start_date ), date( 'Y-m-d H:i:s', $end_date )) );
if ( ! empty( $top_seller ) ) { if ( ! empty( $top_seller ) ) {
$top_seller->name = get_the_title( $top_seller->product_id ); $top_seller->name = get_the_title( $top_seller->product_id );
@ -180,7 +184,7 @@ class MainWP_Child_WooCommerce_Status {
global $wpdb; global $wpdb;
$file = WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php'; $file = WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php';
if ( file_exists( $file ) ) { if ( file_exists( $file ) ) {
include_once $file; include_once( $file );
} else { } else {
return false; return false;
} }
@ -190,7 +194,7 @@ class MainWP_Child_WooCommerce_Status {
$end_date = $_POST['end_date']; $end_date = $_POST['end_date'];
$start_date = date( 'Y-m-d H:i:s', $start_date ); $start_date = date( 'Y-m-d H:i:s', $start_date );
$end_date = date( 'Y-m-d H:i:s', $end_date ); $end_date = date( 'Y-m-d H:i:s', $end_date );
// Get sales // Get sales
$sales = $wpdb->get_var( "SELECT SUM( postmeta.meta_value ) FROM {$wpdb->posts} as posts $sales = $wpdb->get_var( "SELECT SUM( postmeta.meta_value ) FROM {$wpdb->posts} as posts
@ -202,15 +206,18 @@ class MainWP_Child_WooCommerce_Status {
AND posts.post_status = 'publish' AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status' AND tax.taxonomy = 'shop_order_status'
AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array(
'completed', 'completed',
'processing', 'processing',
'on-hold', 'on-hold',
) ) ) . "' ) ) ) ) . "' )
AND postmeta.meta_key = '_order_total' AND postmeta.meta_key = '_order_total'
AND posts.post_date >= STR_TO_DATE(" . $wpdb->prepare('%s', $start_date) . ", '%Y-%m-%d %H:%i:%s') AND posts.post_date >= STR_TO_DATE(" . $wpdb->prepare('%s', $start_date) . ", '%Y-%m-%d %H:%i:%s')
AND posts.post_date <= STR_TO_DATE(" . $wpdb->prepare('%s', $end_date) . ", '%Y-%m-%d %H:%i:%s') AND posts.post_date <= STR_TO_DATE(" . $wpdb->prepare('%s', $end_date) . ", '%Y-%m-%d %H:%i:%s')
" ); " );
// Get top seller // Get top seller
$top_seller = $wpdb->get_row( "SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id $top_seller = $wpdb->get_row( "SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id
FROM {$wpdb->posts} as posts FROM {$wpdb->posts} as posts
@ -224,10 +231,10 @@ class MainWP_Child_WooCommerce_Status {
AND posts.post_status = 'publish' AND posts.post_status = 'publish'
AND tax.taxonomy = 'shop_order_status' AND tax.taxonomy = 'shop_order_status'
AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array( AND term.slug IN ( '" . implode( "','", apply_filters( 'woocommerce_reports_order_statuses', array(
'completed', 'completed',
'processing', 'processing',
'on-hold', 'on-hold',
) ) ) . "' ) ) ) ) . "' )
AND order_item_meta.meta_key = '_qty' AND order_item_meta.meta_key = '_qty'
AND order_item_meta_2.meta_key = '_product_id' AND order_item_meta_2.meta_key = '_product_id'
AND posts.post_date >= STR_TO_DATE(" . $wpdb->prepare('%s', $start_date) . ", '%Y-%m-%d %H:%i:%s') AND posts.post_date >= STR_TO_DATE(" . $wpdb->prepare('%s', $start_date) . ", '%Y-%m-%d %H:%i:%s')
@ -300,10 +307,10 @@ class MainWP_Child_WooCommerce_Status {
function sync_data_two() { function sync_data_two() {
// sync data for current month // sync data for current month
$start_date = date( 'Y-m-01 00:00:00', time() ); $start_date = date( 'Y-m-01 00:00:00', time() );
$end_date = date( 'Y-m-d H:i:s', time() ); $end_date = date( 'Y-m-d H:i:s', time() );
$start_date = strtotime( $start_date ); $start_date = strtotime( $start_date );
$end_date = strtotime( $end_date ); $end_date = strtotime( $end_date );
return $this->get_woocom_data( $start_date, $end_date ); return $this->get_woocom_data( $start_date, $end_date );
} }
@ -326,13 +333,13 @@ class MainWP_Child_WooCommerce_Status {
global $wpdb; global $wpdb;
$file = WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php'; $file = WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php';
if ( file_exists( $file ) ) { if ( file_exists( $file ) ) {
include_once $file; include_once( $file );
} else { } else {
return false; return false;
} }
$start_date = date( 'Y-m-d H:i:s', $start_date ); $start_date = date( 'Y-m-d H:i:s', $start_date );
$end_date = date( 'Y-m-d H:i:s', $end_date ); $end_date = date( 'Y-m-d H:i:s', $end_date );
$reports = new WC_Admin_Report(); $reports = new WC_Admin_Report();
// Sales // Sales
@ -341,38 +348,39 @@ class MainWP_Child_WooCommerce_Status {
$query['join'] = "INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id "; $query['join'] = "INNER JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id ";
$query['where'] = "WHERE posts.post_type IN ( '" . implode( "','", wc_get_order_types( 'reports' ) ) . "' ) "; $query['where'] = "WHERE posts.post_type IN ( '" . implode( "','", wc_get_order_types( 'reports' ) ) . "' ) ";
$query['where'] .= "AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array( $query['where'] .= "AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array(
'completed', 'completed',
'processing', 'processing',
'on-hold', 'on-hold',
) ) ) . "' ) "; ) ) ) . "' ) ";
$query['where'] .= "AND postmeta.meta_key = '_order_total' "; $query['where'] .= "AND postmeta.meta_key = '_order_total' ";
$query['where'] .= 'AND posts.post_date >= STR_TO_DATE(' . $wpdb->prepare('%s', $start_date) . ", '%Y-%m-%d %H:%i:%s') "; $query['where'] .= "AND posts.post_date >= STR_TO_DATE(" . $wpdb->prepare('%s', $start_date) . ", '%Y-%m-%d %H:%i:%s') ";
$query['where'] .= 'AND posts.post_date <= STR_TO_DATE(' . $wpdb->prepare('%s', $end_date) . ", '%Y-%m-%d %H:%i:%s') "; $query['where'] .= "AND posts.post_date <= STR_TO_DATE(" . $wpdb->prepare('%s', $end_date) . ", '%Y-%m-%d %H:%i:%s') ";
$sales = $wpdb->get_var( implode( ' ', apply_filters( 'woocommerce_dashboard_status_widget_sales_query', $query ) ) ); $sales = $wpdb->get_var( implode( ' ', apply_filters( 'woocommerce_dashboard_status_widget_sales_query', $query ) ) );
// Get top seller // Get top seller
$query = array(); $query = array();
$query['fields'] = "SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id $query['fields'] = "SELECT SUM( order_item_meta.meta_value ) as qty, order_item_meta_2.meta_value as product_id
FROM {$wpdb->posts} as posts"; FROM {$wpdb->posts} as posts";
$query['join'] = "INNER JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_id "; $query['join'] = "INNER JOIN {$wpdb->prefix}woocommerce_order_items AS order_items ON posts.ID = order_id ";
$query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id "; $query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id ";
$query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id "; $query['join'] .= "INNER JOIN {$wpdb->prefix}woocommerce_order_itemmeta AS order_item_meta_2 ON order_items.order_item_id = order_item_meta_2.order_item_id ";
$query['where'] = "WHERE posts.post_type IN ( '" . implode( "','", wc_get_order_types( 'order-count' ) ) . "' ) "; $query['where'] = "WHERE posts.post_type IN ( '" . implode( "','", wc_get_order_types( 'order-count' ) ) . "' ) ";
$query['where'] .= "AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array( $query['where'] .= "AND posts.post_status IN ( 'wc-" . implode( "','wc-", apply_filters( 'woocommerce_reports_order_statuses', array(
'completed', 'completed',
'processing', 'processing',
'on-hold', 'on-hold',
) ) ) . "' ) "; ) ) ) . "' ) ";
$query['where'] .= "AND order_item_meta.meta_key = '_qty' "; $query['where'] .= "AND order_item_meta.meta_key = '_qty' ";
$query['where'] .= "AND order_item_meta_2.meta_key = '_product_id' "; $query['where'] .= "AND order_item_meta_2.meta_key = '_product_id' ";
$query['where'] .= 'AND posts.post_date >= STR_TO_DATE(' . $wpdb->prepare('%s', $start_date) . ", '%Y-%m-%d %H:%i:%s') "; $query['where'] .= "AND posts.post_date >= STR_TO_DATE(" . $wpdb->prepare('%s', $start_date) . ", '%Y-%m-%d %H:%i:%s') ";
$query['where'] .= 'AND posts.post_date <= STR_TO_DATE(' . $wpdb->prepare('%s', $end_date) . ", '%Y-%m-%d %H:%i:%s') "; $query['where'] .= "AND posts.post_date <= STR_TO_DATE(" . $wpdb->prepare('%s', $end_date) . ", '%Y-%m-%d %H:%i:%s') ";
$query['groupby'] = 'GROUP BY product_id'; $query['groupby'] = 'GROUP BY product_id';
$query['orderby'] = 'ORDER BY qty DESC'; $query['orderby'] = 'ORDER BY qty DESC';
$query['limits'] = 'LIMIT 1'; $query['limits'] = 'LIMIT 1';
$top_seller = $wpdb->get_row( implode( ' ', $query ) ); $top_seller = $wpdb->get_row( implode( ' ', $query ) );
if ( ! empty( $top_seller ) ) { if ( ! empty( $top_seller ) ) {
$top_seller->name = get_the_title( $top_seller->product_id ); $top_seller->name = get_the_title( $top_seller->product_id );
@ -383,8 +391,8 @@ class MainWP_Child_WooCommerce_Status {
$processing_count = 0; $processing_count = 0;
foreach ( wc_get_order_types( 'order-count' ) as $type ) { foreach ( wc_get_order_types( 'order-count' ) as $type ) {
$counts = (array) wp_count_posts( $type ); $counts = (array) wp_count_posts( $type );
$on_hold_count += isset( $counts['wc-on-hold'] ) ? $counts['wc-on-hold'] : 0; $on_hold_count += isset( $counts['wc-on-hold'] ) ? $counts['wc-on-hold'] : 0;
$processing_count += isset( $counts['wc-processing'] ) ? $counts['wc-processing'] : 0; $processing_count += isset( $counts['wc-processing'] ) ? $counts['wc-processing'] : 0;
} }
@ -424,7 +432,7 @@ class MainWP_Child_WooCommerce_Status {
$outofstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) ); $outofstock_count = absint( $wpdb->get_var( "SELECT COUNT( DISTINCT posts.ID ) {$query_from};" ) );
$data = array( $data = array(
'sales' => $sales, 'sales' => $sales,
'formated_sales' => wc_price( $sales ), 'formated_sales' => wc_price( $sales ),
'top_seller' => $top_seller, 'top_seller' => $top_seller,
@ -433,15 +441,15 @@ class MainWP_Child_WooCommerce_Status {
'stock' => $stock, 'stock' => $stock,
'nostock' => $nostock, 'nostock' => $nostock,
'lowstock' => $lowinstock_count, 'lowstock' => $lowinstock_count,
'outstock' => $outofstock_count, 'outstock' => $outofstock_count
); );
$information['data'] = $data; $information['data'] = $data;
$information['need_db_update'] = $this->check_db_update(); $information['need_db_update'] = $this->check_db_update();
return $information; return $information;
} }
private static function update_wc_db() { private static function update_wc_db() {
include_once WC()->plugin_path() . '/includes/class-wc-background-updater.php'; include_once( WC()->plugin_path() . '/includes/class-wc-background-updater.php' );
$background_updater = new WC_Background_Updater(); $background_updater = new WC_Background_Updater();
$current_db_version = get_option( 'woocommerce_db_version' ); $current_db_version = get_option( 'woocommerce_db_version' );
@ -465,7 +473,7 @@ class MainWP_Child_WooCommerce_Status {
$background_updater->save()->dispatch(); $background_updater->save()->dispatch();
} }
return array( 'result' => 'success' ); return array('result' => 'success');
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -16,15 +16,15 @@
*/ */
class MainWP_Child_WP_Rocket { class MainWP_Child_WP_Rocket {
public static $instance = null; public static $instance = null;
public $is_plugin_installed = false; public $is_plugin_installed = false;
public static function Instance() { public static function Instance() {
if ( null === self::$instance ) { if ( null === MainWP_Child_WP_Rocket::$instance ) {
self::$instance = new MainWP_Child_WP_Rocket(); MainWP_Child_WP_Rocket::$instance = new MainWP_Child_WP_Rocket();
} }
return self::$instance; return MainWP_Child_WP_Rocket::$instance;
} }
public function __construct() { public function __construct() {
@ -34,9 +34,9 @@ class MainWP_Child_WP_Rocket {
} }
public function init() { public function init() {
// if ( get_option( 'mainwp_wprocket_ext_enabled' ) !== 'Y' ) { // if ( get_option( 'mainwp_wprocket_ext_enabled' ) !== 'Y' ) {
// return; // return;
// } // }
if ( ! $this->is_plugin_installed ) { if ( ! $this->is_plugin_installed ) {
return; return;
@ -56,91 +56,91 @@ class MainWP_Child_WP_Rocket {
function get_rocket_default_options() { function get_rocket_default_options() {
return array( return array(
'cache_mobile' => 1, 'cache_mobile' => 1,
'do_caching_mobile_files' => 0, 'do_caching_mobile_files' => 0,
'cache_logged_user' => 0, 'cache_logged_user' => 0,
'cache_ssl' => 0, 'cache_ssl' => 0,
'emoji' => 0, 'emoji' => 0,
'embeds' => 1, 'embeds' => 1,
'control_heartbeat' => 0, 'control_heartbeat' => 0,
'heartbeat_site_behavior' => 'reduce_periodicity', 'heartbeat_site_behavior' => 'reduce_periodicity',
'heartbeat_admin_behavior' => 'reduce_periodicity', 'heartbeat_admin_behavior' => 'reduce_periodicity',
'heartbeat_editor_behavior' => 'reduce_periodicity', 'heartbeat_editor_behavior' => 'reduce_periodicity',
'varnish_auto_purge' => 0, 'varnish_auto_purge' => 0,
'manual_preload' => 0, 'manual_preload' => 0,
'automatic_preload' => 0, 'automatic_preload' => 0,
'sitemap_preload' => 0, 'sitemap_preload' => 0,
'sitemap_preload_url_crawl' => 500000, 'sitemap_preload_url_crawl' => 500000,
'sitemaps' => array(), 'sitemaps' => array(),
'database_revisions' => 0, 'database_revisions' => 0,
'database_auto_drafts' => 0, 'database_auto_drafts' => 0,
'database_trashed_posts' => 0, 'database_trashed_posts' => 0,
'database_spam_comments' => 0, 'database_spam_comments' => 0,
'database_trashed_comments' => 0, 'database_trashed_comments' => 0,
'database_expired_transients' => 0, 'database_expired_transients' => 0,
'database_all_transients' => 0, 'database_all_transients' => 0,
'database_optimize_tables' => 0, 'database_optimize_tables' => 0,
'schedule_automatic_cleanup' => 0, 'schedule_automatic_cleanup' => 0,
'automatic_cleanup_frequency' => '', 'automatic_cleanup_frequency' => '',
'cache_reject_uri' => array(), 'cache_reject_uri' => array(),
'cache_reject_cookies' => array(), 'cache_reject_cookies' => array(),
'cache_reject_ua' => array(), 'cache_reject_ua' => array(),
'cache_query_strings' => array(), 'cache_query_strings' => array(),
'cache_purge_pages' => array(), 'cache_purge_pages' => array(),
'purge_cron_interval' => 10, 'purge_cron_interval' => 10,
'purge_cron_unit' => 'HOUR_IN_SECONDS', 'purge_cron_unit' => 'HOUR_IN_SECONDS',
'exclude_css' => array(), 'exclude_css' => array(),
'exclude_js' => array(), 'exclude_js' => array(),
'exclude_inline_js' => array(), 'exclude_inline_js' => array(),
'async_css' => 0, 'async_css' => 0,
'defer_all_js' => 0, 'defer_all_js' => 0,
'defer_all_js_safe' => 1, 'defer_all_js_safe' => 1,
'critical_css' => '', 'critical_css' => '',
'deferred_js_files' => array(), 'deferred_js_files' => array(),
'lazyload' => 0, 'lazyload' => 0,
'lazyload_iframes' => 0, 'lazyload_iframes' => 0,
'lazyload_youtube' => 0, 'lazyload_youtube' =>0,
'minify_css' => 0, 'minify_css' => 0,
// 'minify_css_key' => $minify_css_key, // 'minify_css_key' => $minify_css_key,
'minify_concatenate_css' => 0, 'minify_concatenate_css' => 0,
// 'minify_css_combine_all' => 0, //'minify_css_combine_all' => 0,
'minify_css_legacy' => 0, 'minify_css_legacy' => 0,
'minify_js' => 0, 'minify_js' => 0,
// 'minify_js_key' => $minify_js_key, // 'minify_js_key' => $minify_js_key,
'minify_js_in_footer' => array(), 'minify_js_in_footer' => array(),
'minify_concatenate_js' => 0, 'minify_concatenate_js' => 0,
'minify_js_combine_all' => 0, 'minify_js_combine_all' => 0,
// 'minify_js_legacy' => 0, //'minify_js_legacy' => 0,
'minify_google_fonts' => 0, 'minify_google_fonts' => 0,
'minify_html' => 0, 'minify_html' => 0,
'remove_query_strings' => 0, 'remove_query_strings' => 0,
'dns_prefetch' => 0, 'dns_prefetch' => 0,
'cdn' => 0, 'cdn' => 0,
'cdn_cnames' => array(), 'cdn_cnames' => array(),
'cdn_zone' => array(), 'cdn_zone' => array(),
// 'cdn_ssl' => 0, //'cdn_ssl' => 0,
'cdn_reject_files' => array(), 'cdn_reject_files' => array(),
'do_cloudflare' => 0, 'do_cloudflare' => 0,
'cloudflare_email' => '', 'cloudflare_email' => '',
'cloudflare_api_key' => '', 'cloudflare_api_key' => '',
'cloudflare_domain' => '', 'cloudflare_domain' => '',
// 'cloudflare_zone_id' => '', //'cloudflare_zone_id' => '',
'cloudflare_devmode' => 0, 'cloudflare_devmode' => 0,
'cloudflare_protocol_rewrite' => 0, 'cloudflare_protocol_rewrite' => 0,
'cloudflare_auto_settings' => 0, 'cloudflare_auto_settings' => 0,
'cloudflare_old_settings' => 0, 'cloudflare_old_settings' => 0,
'do_beta' => 0, 'do_beta' => 0,
'analytics_enabled' => 1, 'analytics_enabled' => 1,
); );
} }
// ok // ok
public function syncOthersData( $information, $data = array() ) { public function syncOthersData( $information, $data = array() ) {
if ( isset( $data['syncWPRocketData'] ) && ( 'yes' === $data['syncWPRocketData'] ) ) { if ( isset( $data['syncWPRocketData'] ) && ( 'yes' === $data['syncWPRocketData'] ) ) {
try { try{
$data = array( 'rocket_boxes' => get_user_meta( $GLOBALS['current_user']->ID, 'rocket_boxes', true ) ); $data = array( 'rocket_boxes' => get_user_meta( $GLOBALS['current_user']->ID, 'rocket_boxes', true ));
$information['syncWPRocketData'] = $data; $information['syncWPRocketData'] = $data;
} catch (Exception $e) { } catch(Exception $e) {
} }
} }
return $information; return $information;
@ -192,7 +192,7 @@ class MainWP_Child_WP_Rocket {
return $value; return $value;
} }
if ( ! MainWP_Helper::is_screen_with_update()) { if (! MainWP_Helper::is_screen_with_update()) {
return $value; return $value;
} }
@ -207,9 +207,9 @@ class MainWP_Child_WP_Rocket {
if ( ! $this->is_plugin_installed ) { if ( ! $this->is_plugin_installed ) {
return false; return false;
} }
// if ( ! defined( 'WP_ROCKET_VERSION' ) || ! defined( 'WP_ROCKET_SLUG' ) ) { // if ( ! defined( 'WP_ROCKET_VERSION' ) || ! defined( 'WP_ROCKET_SLUG' ) ) {
// return false; // return false;
// } // }
return true; return true;
} }
@ -251,8 +251,9 @@ class MainWP_Child_WP_Rocket {
$information = array(); $information = array();
if ( isset( $_POST['mwp_action'] ) ) { if ( isset( $_POST['mwp_action'] ) ) {
// MainWP_Helper::update_option( 'mainwp_wprocket_ext_enabled', 'Y' ); // MainWP_Helper::update_option( 'mainwp_wprocket_ext_enabled', 'Y' );
try { try {
switch ( $_POST['mwp_action'] ) { switch ( $_POST['mwp_action'] ) {
case 'set_showhide': case 'set_showhide':
@ -273,7 +274,7 @@ class MainWP_Child_WP_Rocket {
case 'save_settings': case 'save_settings':
$information = $this->save_settings(); $information = $this->save_settings();
break; break;
case 'load_existing_settings': case "load_existing_settings":
$information = $this->load_existing_settings(); $information = $this->load_existing_settings();
break; break;
case 'optimize_database': case 'optimize_database':
@ -286,7 +287,7 @@ class MainWP_Child_WP_Rocket {
$information = $this->do_admin_post_rocket_purge_opcache(); $information = $this->do_admin_post_rocket_purge_opcache();
break; break;
} }
} catch (Exception $e) { } catch(Exception $e) {
$information = array( 'error' => $e->getMessage() ); $information = array( 'error' => $e->getMessage() );
} }
} }
@ -305,9 +306,9 @@ class MainWP_Child_WP_Rocket {
if ( function_exists( 'opcache_reset' ) ) { if ( function_exists( 'opcache_reset' ) ) {
@opcache_reset(); @opcache_reset();
} else { } else {
return array( 'error' => 'The host do not support the function reset opcache.' ); return array('error' => 'The host do not support the function reset opcache.');
} }
return array( 'result' => 'SUCCESS' ); return array('result' => 'SUCCESS');
} }
function purge_cloudflare() { function purge_cloudflare() {
@ -335,12 +336,12 @@ class MainWP_Child_WP_Rocket {
rocket_clean_cache_busting(); rocket_clean_cache_busting();
} }
if ( ! function_exists( 'rocket_dismiss_boxes' ) && defined('WP_ROCKET_ADMIN_PATH')) { if ( !function_exists( 'rocket_dismiss_boxes' ) && defined('WP_ROCKET_ADMIN_PATH')) {
require_once WP_ROCKET_ADMIN_PATH . 'admin.php'; require_once WP_ROCKET_ADMIN_PATH . 'admin.php';
} }
// to fix // to fix
include_once ABSPATH . '/wp-admin/includes/template.php'; include_once( ABSPATH . '/wp-admin/includes/template.php' );
// Generate a new random key for minify cache file // Generate a new random key for minify cache file
$options = get_option( WP_ROCKET_SLUG ); $options = get_option( WP_ROCKET_SLUG );
@ -361,7 +362,7 @@ class MainWP_Child_WP_Rocket {
MainWP_Helper::check_classes_exists('WP_Rocket\Preload\Full_Process'); MainWP_Helper::check_classes_exists('WP_Rocket\Preload\Full_Process');
$preload_process = new WP_Rocket\Preload\Full_Process(); $preload_process = new WP_Rocket\Preload\Full_Process();
MainWP_Helper::check_methods($preload_process, array( 'is_process_running' )); MainWP_Helper::check_methods($preload_process, array( 'is_process_running'));
if ( $preload_process->is_process_running() ) { if ( $preload_process->is_process_running() ) {
return array( 'result' => 'RUNNING' ); return array( 'result' => 'RUNNING' );
@ -374,17 +375,16 @@ class MainWP_Child_WP_Rocket {
} }
function generate_critical_css() { function generate_critical_css() {
MainWP_Helper::check_classes_exists( array( MainWP_Helper::check_classes_exists( array( 'WP_Rocket\Subscriber\Optimization\Critical_CSS_Subscriber',
'WP_Rocket\Subscriber\Optimization\Critical_CSS_Subscriber', 'WP_Rocket\Optimization\CSS\Critical_CSS',
'WP_Rocket\Optimization\CSS\Critical_CSS', 'WP_Rocket\Optimization\CSS\Critical_CSS_Generation',
'WP_Rocket\Optimization\CSS\Critical_CSS_Generation', 'WP_Rocket\Admin\Options',
'WP_Rocket\Admin\Options', 'WP_Rocket\Admin\Options_Data'
'WP_Rocket\Admin\Options_Data', ));
));
$critical_css = new WP_Rocket\Optimization\CSS\Critical_CSS( new WP_Rocket\Optimization\CSS\Critical_CSS_Generation() ); $critical_css = new WP_Rocket\Optimization\CSS\Critical_CSS( new WP_Rocket\Optimization\CSS\Critical_CSS_Generation() );
$options_api = new WP_Rocket\Admin\Options( 'wp_rocket_' ); $options_api = new WP_Rocket\Admin\Options( 'wp_rocket_' );
$options = new WP_Rocket\Admin\Options_Data( $options_api->get( 'settings', array() ) ); $options = new WP_Rocket\Admin\Options_Data( $options_api->get( 'settings', array() ) );
$sitemap_preload = new WP_Rocket\Subscriber\Optimization\Critical_CSS_Subscriber( $critical_css, $options ); $sitemap_preload = new WP_Rocket\Subscriber\Optimization\Critical_CSS_Subscriber( $critical_css, $options );
@ -411,9 +411,10 @@ class MainWP_Child_WP_Rocket {
} }
} }
update_option( WP_ROCKET_SLUG, $options ); update_option( WP_ROCKET_SLUG, $options );
if (isset($_POST['do_database_optimization']) && ! empty($_POST['do_database_optimization'])) { if (isset($_POST['do_database_optimization']) && !empty($_POST['do_database_optimization'])) {
$this->optimize_database(); $this->optimize_database();
} }
@ -422,23 +423,22 @@ class MainWP_Child_WP_Rocket {
function optimize_database() { function optimize_database() {
MainWP_Helper::check_classes_exists( array( MainWP_Helper::check_classes_exists( array( 'WP_Rocket\Admin\Database\Optimization',
'WP_Rocket\Admin\Database\Optimization', 'WP_Rocket\Admin\Database\Optimization_Process',
'WP_Rocket\Admin\Database\Optimization_Process', 'WP_Rocket\Admin\Options',
'WP_Rocket\Admin\Options', 'WP_Rocket\Admin\Options_Data'
'WP_Rocket\Admin\Options_Data', ));
));
$process = new WP_Rocket\Admin\Database\Optimization_Process(); $process = new WP_Rocket\Admin\Database\Optimization_Process();
$optimization = new WP_Rocket\Admin\Database\Optimization( $process ); $optimization = new WP_Rocket\Admin\Database\Optimization( $process );
MainWP_Helper::check_methods( $optimization, array( 'process_handler', 'get_options' ) ); MainWP_Helper::check_methods( $optimization, array( 'process_handler', 'get_options' ) );
$options_api = new WP_Rocket\Admin\Options( 'wp_rocket_' ); $options_api = new WP_Rocket\Admin\Options( 'wp_rocket_' );
$options = new WP_Rocket\Admin\Options_Data( $options_api->get( 'settings', array() ) ); $options = new WP_Rocket\Admin\Options_Data( $options_api->get( 'settings', array() ) );
$items = array_filter( array_keys( $optimization->get_options() ), array( $options, 'get' ) ); $items = array_filter( array_keys( $optimization->get_options() ), [ $options, 'get' ] );
if ( ! empty( $items ) ) { if ( !empty( $items ) ) {
$optimization->process_handler( $items ); $optimization->process_handler( $items );
} }
@ -448,24 +448,23 @@ class MainWP_Child_WP_Rocket {
function get_optimize_info() { function get_optimize_info() {
MainWP_Helper::check_classes_exists( array( MainWP_Helper::check_classes_exists( array( 'WP_Rocket\Admin\Database\Optimization',
'WP_Rocket\Admin\Database\Optimization', 'WP_Rocket\Admin\Database\Optimization_Process'
'WP_Rocket\Admin\Database\Optimization_Process', ));
));
$process = new WP_Rocket\Admin\Database\Optimization_Process(); $process = new WP_Rocket\Admin\Database\Optimization_Process();
$optimization = new WP_Rocket\Admin\Database\Optimization( $process ); $optimization = new WP_Rocket\Admin\Database\Optimization( $process );
MainWP_Helper::check_methods($optimization, 'count_cleanup_items'); MainWP_Helper::check_methods($optimization, 'count_cleanup_items');
$information['optimize_info'] = array( $information['optimize_info'] = array(
'total_revisions' => $optimization->count_cleanup_items( 'database_revisions' ), 'total_revisions' => $optimization->count_cleanup_items( 'database_revisions' ),
'total_auto_draft' => $optimization->count_cleanup_items( 'database_auto_drafts' ), 'total_auto_draft' => $optimization->count_cleanup_items( 'database_auto_drafts' ),
'total_trashed_posts' => $optimization->count_cleanup_items( 'database_trashed_posts' ), 'total_trashed_posts' => $optimization->count_cleanup_items( 'database_trashed_posts' ),
'total_spam_comments' => $optimization->count_cleanup_items( 'database_spam_comments' ), 'total_spam_comments' => $optimization->count_cleanup_items( 'database_spam_comments' ),
'total_trashed_comments' => $optimization->count_cleanup_items( 'database_trashed_comments' ), 'total_trashed_comments' => $optimization->count_cleanup_items( 'database_trashed_comments' ),
'total_expired_transients' => $optimization->count_cleanup_items( 'database_expired_transients' ), 'total_expired_transients' => $optimization->count_cleanup_items( 'database_expired_transients' ),
'total_all_transients' => $optimization->count_cleanup_items( 'database_all_transients' ), 'total_all_transients' => $optimization->count_cleanup_items( 'database_all_transients' ),
'total_optimize_tables' => $optimization->count_cleanup_items( 'database_optimize_tables' ), 'total_optimize_tables' => $optimization->count_cleanup_items( 'database_optimize_tables' )
); );
$information['result'] = 'SUCCESS'; $information['result'] = 'SUCCESS';
@ -474,10 +473,7 @@ class MainWP_Child_WP_Rocket {
function load_existing_settings() { function load_existing_settings() {
$options = get_option( WP_ROCKET_SLUG ); $options = get_option( WP_ROCKET_SLUG );
return array( return array('result' => 'SUCCESS', 'options' => $options);
'result' => 'SUCCESS',
'options' => $options,
);
} }
} }

View file

@ -1,63 +1,74 @@
<?php <?php
class MainWP_Child_WPvivid_BackupRestore { class MainWP_Child_WPvivid_BackupRestore
{
public static $instance = null; public static $instance = null;
public $is_plugin_installed = false; public $is_plugin_installed = false;
public $public_intetface; public $public_intetface;
static function Instance() { static function Instance()
if ( null === self::$instance ) { {
self::$instance = new MainWP_Child_WPvivid_BackupRestore(); if ( null === MainWP_Child_WPvivid_BackupRestore::$instance )
{
MainWP_Child_WPvivid_BackupRestore::$instance = new MainWP_Child_WPvivid_BackupRestore();
} }
return self::$instance; return MainWP_Child_WPvivid_BackupRestore::$instance;
} }
public function __construct() { public function __construct()
require_once ABSPATH . 'wp-admin/includes/plugin.php'; {
if ( is_plugin_active( 'wpvivid-backuprestore/wpvivid-backuprestore.php' ) && defined('WPVIVID_PLUGIN_DIR') ) { require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if ( is_plugin_active( 'wpvivid-backuprestore/wpvivid-backuprestore.php' ) && defined('WPVIVID_PLUGIN_DIR'))
{
$this->is_plugin_installed = true; $this->is_plugin_installed = true;
} }
if ( ! $this->is_plugin_installed ) { if (!$this->is_plugin_installed)
return; return;
}
add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 );
$this->public_intetface = new WPvivid_Public_Interface(); $this->public_intetface = new WPvivid_Public_Interface();
} }
public function init() { public function init()
{
} }
function syncOthersData( $information, $data = array() ) { function syncOthersData( $information, $data = array() )
try { {
try{
if ( isset( $data['syncWPvividData'] ) ) { if ( isset( $data['syncWPvividData'] ))
$information['syncWPvividData'] = 1; {
$data = WPvivid_Setting::get_sync_data(); $information['syncWPvividData']=1;
$information['syncWPvividSettingData'] = $data['setting']; $data = WPvivid_Setting::get_sync_data();
$information['syncWPvividRemoteData'] = $data['remote']; $information['syncWPvividSettingData']=$data['setting'];
$information['syncWPvividScheduleData'] = $data['schedule']; $information['syncWPvividRemoteData']=$data['remote'];
$information['syncWPvividSetting'] = $data; $information['syncWPvividScheduleData']=$data['schedule'];
$information['syncWPvividSetting'] = $data;
} }
} catch ( Exception $e ) {
} catch(Exception $e) {
} }
return $information; return $information;
} }
public function action() { public function action()
{
$information = array(); $information = array();
if ( ! $this->is_plugin_installed ) { if ( ! $this->is_plugin_installed )
{
$information['error'] = 'NO_WPVIVIDBACKUP'; $information['error'] = 'NO_WPVIVIDBACKUP';
MainWP_Helper::write( $information ); MainWP_Helper::write( $information );
} }
if ( isset( $_POST['mwp_action'] ) ) { if ( isset( $_POST['mwp_action'] ) )
{
try { try {
switch ( $_POST['mwp_action'] ) { switch ($_POST['mwp_action']) {
case 'prepare_backup': case 'prepare_backup':
$information = $this->prepare_backup(); $information = $this->prepare_backup();
break; break;
@ -122,155 +133,175 @@ class MainWP_Child_WPvivid_BackupRestore {
$information = $this->post_mainwp_data($_POST); $information = $this->post_mainwp_data($_POST);
break; break;
} }
} catch ( Exception $e ) { } catch (Exception $e) {
$information = array( 'error' => $e->getMessage() ); $information = array('error' => $e->getMessage());
} }
MainWP_Helper::write($information); MainWP_Helper::write($information);
} }
} }
public function post_mainwp_data( $data ) { public function post_mainwp_data($data){
global $wpvivid_plugin; global $wpvivid_plugin;
$ret = $wpvivid_plugin->wpvivid_handle_mainwp_action($data); $ret =$wpvivid_plugin->wpvivid_handle_mainwp_action($data);
return $ret; return $ret;
} }
public function prepare_backup() { public function prepare_backup()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->prepare_backup($_POST['backup']); $ret = $this->public_intetface->prepare_backup($_POST['backup']);
return $ret; return $ret;
} }
public function backup_now() { public function backup_now()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->backup_now($_POST['task_id']); $ret = $this->public_intetface->backup_now($_POST['task_id']);
return $ret; return $ret;
} }
public function get_status() { public function get_status()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->get_status(); $ret = $this->public_intetface->get_status();
return $ret; return $ret;
} }
public function get_backup_schedule() { public function get_backup_schedule()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->get_backup_schedule(); $ret = $this->public_intetface->get_backup_schedule();
return $ret; return $ret;
} }
public function get_backup_list() { public function get_backup_list()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->get_backup_list(); $ret = $this->public_intetface->get_backup_list();
return $ret; return $ret;
} }
public function get_default_remote() { public function get_default_remote()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->get_default_remote(); $ret = $this->public_intetface->get_default_remote();
return $ret; return $ret;
} }
public function delete_backup() { public function delete_backup()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->delete_backup($_POST['backup_id'], $_POST['force']); $ret = $this->public_intetface->delete_backup($_POST['backup_id'], $_POST['force']);
return $ret; return $ret;
} }
public function delete_backup_array() { public function delete_backup_array()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->delete_backup_array($_POST['backup_id']); $ret = $this->public_intetface->delete_backup_array($_POST['backup_id']);
return $ret; return $ret;
} }
public function set_security_lock() { public function set_security_lock()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->set_security_lock($_POST['backup_id'], $_POST['lock']); $ret = $this->public_intetface->set_security_lock($_POST['backup_id'], $_POST['lock']);
return $ret; return $ret;
} }
public function view_log() { public function view_log()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->view_log($_POST['id']); $ret = $this->public_intetface->view_log($_POST['id']);
return $ret; return $ret;
} }
public function read_last_backup_log() { public function read_last_backup_log()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->read_last_backup_log($_POST['log_file_name']); $ret = $this->public_intetface->read_last_backup_log($_POST['log_file_name']);
return $ret; return $ret;
} }
public function view_backup_task_log() { public function view_backup_task_log()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->view_backup_task_log($_POST['id']); $ret = $this->public_intetface->view_backup_task_log($_POST['id']);
return $ret; return $ret;
} }
public function backup_cancel() { public function backup_cancel()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->backup_cancel($_POST['task_id']); $ret = $this->public_intetface->backup_cancel($_POST['task_id']);
return $ret; return $ret;
} }
public function init_download_page() { public function init_download_page()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->init_download_page($_POST['backup_id']); $ret = $this->public_intetface->init_download_page($_POST['backup_id']);
return $ret; return $ret;
} }
public function prepare_download_backup() { public function prepare_download_backup()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->prepare_download_backup($_POST['backup_id'], $_POST['file_name']); $ret = $this->public_intetface->prepare_download_backup($_POST['backup_id'], $_POST['file_name']);
return $ret; return $ret;
} }
public function get_download_task() { public function get_download_task()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->get_download_task($_POST['backup_id']); $ret = $this->public_intetface->get_download_task($_POST['backup_id']);
return $ret; return $ret;
} }
public function download_backup() { public function download_backup()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->download_backup($_POST['backup_id'], $_POST['file_name']); $ret = $this->public_intetface->download_backup($_POST['backup_id'], $_POST['file_name']);
return $ret; return $ret;
} }
public function set_general_setting() { public function set_general_setting()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->set_general_setting($_POST['setting']); $ret = $this->public_intetface->set_general_setting($_POST['setting']);
return $ret; return $ret;
} }
public function set_schedule() { public function set_schedule()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->set_schedule($_POST['schedule']); $ret = $this->public_intetface->set_schedule($_POST['schedule']);
return $ret; return $ret;
} }
public function set_remote() { public function set_remote()
{
global $wpvivid_plugin; global $wpvivid_plugin;
$wpvivid_plugin->ajax_check_security(); $wpvivid_plugin->ajax_check_security();
$ret = $this->public_intetface->set_remote($_POST['remote']); $ret = $this->public_intetface->set_remote($_POST['remote']);

File diff suppressed because it is too large Load diff

View file

@ -5,45 +5,44 @@ class MainWP_Client_Report {
public static $instance = null; public static $instance = null;
static function Instance() { static function Instance() {
if ( null === self::$instance ) { if ( null === MainWP_Client_Report::$instance ) {
self::$instance = new MainWP_Client_Report(); MainWP_Client_Report::$instance = new MainWP_Client_Report();
} }
return self::$instance; return MainWP_Client_Report::$instance;
} }
public function __construct() { public function __construct() {
add_filter( 'wp_mainwp_stream_current_agent', array( $this, 'current_agent' ), 10, 1 ); add_filter( 'wp_mainwp_stream_current_agent', array($this, 'current_agent' ), 10, 1 );
} }
public function init() { public function init() {
add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 ); add_filter( 'mainwp-site-sync-others-data', array( $this, 'syncOthersData' ), 10, 2 );
add_action( 'mainwp_child_log', array( 'MainWP_Client_Report', 'do_reports_log' ) ); add_action( 'mainwp_child_log', array( 'MainWP_Client_Report', 'do_reports_log' ) );
} }
public function current_agent( $agent ) { public function current_agent( $agent ) {
if ( isset( $_POST['function'] ) && isset( $_POST['mainwpsignature'] ) ) { if ( isset( $_POST['function'] ) && isset( $_POST['mainwpsignature'] ) )
$agent = ''; $agent = '';
}
return $agent; return $agent;
} }
// ok // ok
public function syncOthersData( $information, $data = array() ) { public function syncOthersData( $information, $data = array() ) {
if ( isset( $data['syncClientReportData'] ) && $data['syncClientReportData'] ) { if ( isset( $data['syncClientReportData'] ) && $data['syncClientReportData'] ) {
$creport_sync_data = array(); $creport_sync_data = array();
if ( ( $firsttime = get_option( 'mainwp_creport_first_time_activated' ) ) !== false ) { if ( ( $firsttime = get_option( 'mainwp_creport_first_time_activated' ) ) !== false ) {
$creport_sync_data['firsttime_activated'] = $firsttime; $creport_sync_data['firsttime_activated'] = $firsttime;
} }
if ( ! empty( $creport_sync_data ) ) { if ( !empty( $creport_sync_data ) ) {
$information['syncClientReportData'] = $creport_sync_data; $information['syncClientReportData'] = $creport_sync_data;
} }
} }
return $information; return $information;
} }
public static function do_reports_log( $ext = '' ) { public static function do_reports_log( $ext = '' ) {
switch ( $ext ) { switch( $ext ) {
case 'backupbuddy': case 'backupbuddy':
MainWP_Child_Back_Up_Buddy::Instance()->do_reports_log( $ext ); MainWP_Child_Back_Up_Buddy::Instance()->do_reports_log( $ext );
break; break;
@ -56,7 +55,7 @@ class MainWP_Client_Report {
case 'wordfence': case 'wordfence':
MainWP_Child_Wordfence::Instance()->do_reports_log( $ext ); MainWP_Child_Wordfence::Instance()->do_reports_log( $ext );
break; break;
case 'wptimecapsule': case 'wptimecapsule':
MainWP_Child_Timecapsule::Instance()->do_reports_log( $ext ); MainWP_Child_Timecapsule::Instance()->do_reports_log( $ext );
break; break;
} }
@ -64,9 +63,9 @@ class MainWP_Client_Report {
public function action() { public function action() {
$information = array(); $information = array();
if ( ! function_exists( 'wp_mainwp_stream_get_instance' ) ) { if ( !function_exists( 'wp_mainwp_stream_get_instance' ) ) {
$information['error'] = __( 'Error: No MainWP Client Reports plugin installed.' ); $information['error'] = __( 'Error: No MainWP Client Reports plugin installed.' );
MainWP_Helper::write( $information ); MainWP_Helper::write( $information );
} }
@ -91,7 +90,7 @@ class MainWP_Client_Report {
} }
public function save_sucuri_stream() { public function save_sucuri_stream() {
$scan_data = isset($_POST['scan_data']) ? $_POST['scan_data'] : ''; $scan_data = isset($_POST['scan_data']) ? $_POST['scan_data'] : '';
do_action( 'mainwp_reports_sucuri_scan', $_POST['result'], $_POST['scan_status'], $scan_data, isset($_POST['scan_time']) ? $_POST['scan_time'] : 0 ); do_action( 'mainwp_reports_sucuri_scan', $_POST['result'], $_POST['scan_status'], $scan_data, isset($_POST['scan_time']) ? $_POST['scan_time'] : 0 );
return true; return true;
} }
@ -103,36 +102,35 @@ class MainWP_Client_Report {
} }
public function is_backup_action( $action ) { public function is_backup_action( $action ) {
if ( in_array( $action, array( 'mainwp_backup', 'backupbuddy_backup', 'backupwordpress_backup', 'backwpup_backup', 'updraftplus_backup', 'wptimecapsule_backup', 'wpvivid_backup' ) ) ) { if ( in_array( $action, array( 'mainwp_backup', 'backupbuddy_backup', 'backupwordpress_backup', 'backwpup_backup', 'updraftplus_backup', 'wptimecapsule_backup', 'wpvivid_backup' ) ) )
return true; return true;
}
return false; return false;
} }
public function get_compatible_context( $context ) { public function get_compatible_context( $context ) {
// convert context name of tokens to context name saved in child report // convert context name of tokens to context name saved in child report
// some context are not difference // some context are not difference
$mapping_contexts = array( $mapping_contexts = array(
'comment' => 'comments', // actual context values: post,page 'comment' => 'comments', // actual context values: post,page
'plugin' => 'plugins', 'plugin' => 'plugins',
'users' => 'profiles', 'users' => 'profiles',
'user' => 'profiles', 'user' => 'profiles',
'session' => 'sessions', 'session' => 'sessions',
'setting' => 'settings', 'setting' => 'settings',
'theme' => 'themes', 'theme' => 'themes',
'posts' => 'post', 'posts' => 'post',
'pages' => 'page', 'pages' => 'page',
'widgets' => 'widgets', 'widgets' => 'widgets',
'widget' => 'widgets', 'widget' => 'widgets',
'menu' => 'menus', 'menu' => 'menus',
'backups' => 'backups', 'backups' => 'backups',
'backup' => 'backups', 'backup' => 'backups',
'sucuri' => 'sucuri_scan', 'sucuri' => 'sucuri_scan',
'maintenance' => 'mainwp_maintenance', 'maintenance' => 'mainwp_maintenance',
'wordfence' => 'wordfence_scan', 'wordfence' => 'wordfence_scan',
'backups' => 'backups', 'backups' => 'backups',
'backup' => 'backups', 'backup' => 'backups',
'media' => 'media', 'media' => 'media'
); );
$context = isset( $mapping_contexts[ $context ] ) ? $mapping_contexts[ $context ] : $context; $context = isset( $mapping_contexts[ $context ] ) ? $mapping_contexts[ $context ] : $context;
@ -142,35 +140,35 @@ class MainWP_Client_Report {
public function get_connector_by_compatible_context( $context ) { public function get_connector_by_compatible_context( $context ) {
$connector = ''; $connector = "";
if ( $context == 'plugins' || $context == 'themes' || $context == 'WordPress' ) { if ( $context == "plugins" || $context == "themes" || $context == "wordpress" ) {
$connector = 'installer'; $connector = "installer";
} elseif ( $context == 'profiles' ) { } else if ( $context == 'profiles' ) {
$connector = 'users'; $connector = "users";
} elseif ( $context == 'comments' ) { // multi values } else if ( $context == 'comments' ) { // multi values
$connector = 'comments'; $connector = "comments";
} }
// else if ( $context == 'sessions' ) { // else if ( $context == 'sessions' ) {
// $connector = "users"; // $connector = "users";
// } // }
elseif ( $context == 'settings' ) { else if ( $context == 'settings' ) {
$connector = 'settings'; $connector = "settings";
} elseif ( $context == 'post' || $context == 'page' ) { } else if ( $context == 'post' || $context == 'page') {
$connector = 'posts'; $connector = "posts";
} elseif ( $context == 'widgets' ) { } else if ( $context == 'widgets' ) {
$connector = 'widgets'; $connector = "widgets";
} elseif ( $context == 'menus' ) { } else if ( $context == 'menus' ) {
$connector = 'menus'; $connector = "menus";
} elseif ( $context == 'backups' ) { } else if ( $context == 'backups' ) {
$connector = 'mainwp_backups'; $connector = "mainwp_backups";
} elseif ( $context == 'sucuri_scan' ) { } else if ( $context == 'sucuri_scan' ) {
$connector = 'mainwp_sucuri'; $connector = "mainwp_sucuri";
} elseif ( $context == 'mainwp_maintenance' ) { } else if ( $context == 'mainwp_maintenance' ) {
$connector = 'mainwp_maintenance'; $connector = "mainwp_maintenance";
} elseif ( $context == 'wordfence_scan' ) { } else if ( $context == 'wordfence_scan' ) {
$connector = 'mainwp_wordfence'; $connector = "mainwp_wordfence";
} elseif ( $context == 'media' ) { } else if ( $context == 'media' ) {
$connector = 'media'; $connector = "media";
} }
return $connector; return $connector;
@ -183,22 +181,18 @@ class MainWP_Client_Report {
'spam' => 'spammed', 'spam' => 'spammed',
); );
if ( isset($mapping_actions[ $action ]) ) { if (isset($mapping_actions[ $action ]))
return $mapping_actions[ $action ]; return $mapping_actions[ $action ];
}
if ( $context == 'mainwp_maintenance' ) { if ( $context == 'mainwp_maintenance' ) {
if ( $action == 'process' ) { if ( $action == 'process')
$action = 'maintenance'; $action = 'maintenance';
} } else if ( $context == 'sucuri_scan' ) {
} elseif ( $context == 'sucuri_scan' ) { if ( $action == 'checks')
if ( $action == 'checks' ) {
$action = 'sucuri_scan'; $action = 'sucuri_scan';
} } else if ($context == 'wordfence_scan') {
} elseif ( $context == 'wordfence_scan' ) { if ( $action == 'scan')
if ( $action == 'scan' ) {
$action = 'wordfence_scan'; $action = 'wordfence_scan';
}
} }
return $action; return $action;
} }
@ -225,13 +219,13 @@ class MainWP_Client_Report {
if ( ! is_array( $sections ) ) { if ( ! is_array( $sections ) ) {
$sections = array(); $sections = array();
} }
// return $sections; //return $sections;
$other_tokens = isset( $_POST['other_tokens'] ) ? maybe_unserialize( base64_decode( $_POST['other_tokens'] ) ) : array(); $other_tokens = isset( $_POST['other_tokens'] ) ? maybe_unserialize( base64_decode( $_POST['other_tokens'] ) ) : array();
if ( ! is_array( $other_tokens ) ) { if ( ! is_array( $other_tokens ) ) {
$other_tokens = array(); $other_tokens = array();
} }
// return $other_tokens; //return $other_tokens;
unset( $_POST['sections'] ); unset( $_POST['sections'] );
unset( $_POST['other_tokens'] ); unset( $_POST['other_tokens'] );
@ -253,67 +247,66 @@ class MainWP_Client_Report {
// to fix bug // to fix bug
$exclude_connector_posts = true; $exclude_connector_posts = true;
if ( isset( $sections['body'] ) && isset( $sections['body']['section_token'] ) && is_array($sections['body']['section_token']) ) { if ( isset( $sections['body'] ) && isset( $sections['body']['section_token'] ) && is_array($sections['body']['section_token']) ) {
foreach ( $sections['body']['section_token'] as $sec ) { foreach ($sections['body']['section_token'] as $sec) {
if ( strpos($sec, '[section.posts') !== false || strpos($sec, '[section.pages') !== false ) { if (strpos($sec, "[section.posts") !== false || strpos($sec, "[section.pages") !== false) {
$exclude_connector_posts = false; $exclude_connector_posts = false;
break; break;
} }
} }
} }
if ( $exclude_connector_posts ) { if ($exclude_connector_posts) {
if ( isset( $sections['header'] ) && isset( $sections['header']['section_token'] ) && is_array($sections['header']['section_token']) ) { if ( isset( $sections['header'] ) && isset( $sections['header']['section_token'] ) && is_array($sections['header']['section_token']) ) {
foreach ( $sections['header']['section_token'] as $sec ) { foreach ($sections['header']['section_token'] as $sec) {
if ( strpos($sec, '[section.posts') !== false || strpos($sec, '[section.pages') !== false ) { if (strpos($sec, "[section.posts") !== false || strpos($sec, "[section.pages") !== false) {
$exclude_connector_posts = false; $exclude_connector_posts = false;
break; break;
} }
} }
} }
} }
if ( $exclude_connector_posts ) { if ($exclude_connector_posts) {
if ( isset( $sections['footer'] ) && isset( $sections['footer']['section_token'] ) && is_array($sections['footer']['section_token']) ) { if ( isset( $sections['footer'] ) && isset( $sections['footer']['section_token'] ) && is_array($sections['footer']['section_token']) ) {
foreach ( $sections['footer']['section_token'] as $sec ) { foreach ($sections['footer']['section_token'] as $sec) {
if ( strpos($sec, '[section.posts') !== false || strpos($sec, '[section.pages') !== false ) { if (strpos($sec, "[section.posts") !== false || strpos($sec, "[section.pages") !== false) {
$exclude_connector_posts = false; $exclude_connector_posts = false;
break; break;
} }
} }
} }
} }
if ( $exclude_connector_posts ) { if ($exclude_connector_posts) {
if ( isset( $other_tokens['body'] ) && is_array( $other_tokens['body'] ) ) { if ( isset( $other_tokens['body'] ) && is_array( $other_tokens['body'] ) ) {
foreach ( $other_tokens['body'] as $sec ) { foreach ( $other_tokens['body'] as $sec ) {
if ( strpos( $sec, '[post.' ) !== false || strpos($sec, '[page.') !== false ) { if ( strpos( $sec, "[post." ) !== false || strpos($sec, "[page.") !== false) {
$exclude_connector_posts = false; $exclude_connector_posts = false;
break; break;
} }
} }
} }
} }
if ( $exclude_connector_posts ) { if ($exclude_connector_posts) {
if ( isset( $other_tokens['header'] ) && is_array($other_tokens['header']) ) { if ( isset( $other_tokens['header'] ) && is_array($other_tokens['header']) ) {
foreach ( $other_tokens['header'] as $sec ) { foreach ($other_tokens['header'] as $sec) {
if ( strpos($sec, '[post.') !== false || strpos($sec, '[page.') !== false ) { if (strpos($sec, "[post.") !== false || strpos($sec, "[page.") !== false) {
$exclude_connector_posts = false; $exclude_connector_posts = false;
break; break;
} }
} }
} }
} }
if ( $exclude_connector_posts ) { if ($exclude_connector_posts) {
if ( isset( $other_tokens['footer'] ) && is_array($other_tokens['footer']) ) { if ( isset( $other_tokens['footer'] ) && is_array($other_tokens['footer']) ) {
foreach ( $other_tokens['footer'] as $sec ) { foreach ($other_tokens['footer'] as $sec) {
if ( strpos($sec, '[post.') !== false || strpos($sec, '[page.') !== false ) { if (strpos($sec, "[post.") !== false || strpos($sec, "[page.") !== false) {
$exclude_connector_posts = false; $exclude_connector_posts = false;
break; break;
} }
} }
} }
} }
if ( $exclude_connector_posts ) { if ($exclude_connector_posts)
$args['connector__not_in'] = array( 'posts' ); $args['connector__not_in'] = array('posts');
} ///// end fix /////
// end fix /////
$args['action__not_in'] = array( 'login' ); $args['action__not_in'] = array( 'login' );
@ -333,37 +326,38 @@ class MainWP_Client_Report {
$args['records_per_page'] = 9999; $args['records_per_page'] = 9999;
// $records = mainwp_wp_stream_query( $args ); // $records = mainwp_wp_stream_query( $args );
$records = wp_mainwp_stream_get_instance()->db->query( $args ); $records = wp_mainwp_stream_get_instance()->db->query( $args );
if ( ! is_array( $records ) ) { if ( ! is_array( $records ) ) {
$records = array(); $records = array();
} }
// to fix invalid data, or skip records // to fix invalid data, or skip records
$skip_records = array(); $skip_records = array();
// to fix for incorrect posts created logging // to fix for incorrect posts created logging
// query created posts from WP posts data to simulate records logging for created posts // query created posts from WP posts data to simulate records logging for created posts
if ( isset($_POST['direct_posts']) && ! empty($_POST['direct_posts']) ) { if ( isset($_POST['direct_posts']) && !empty($_POST['direct_posts']) ) {
$query_string = array( $query_string = array(
'post_type' => 'post', 'post_type' => 'post',
'date_query' => array( 'date_query' => array(
'column' => 'post_date', 'column' => 'post_date',
'after' => $args['date_from'], 'after' => $args['date_from'],
'before' => $args['date_to'], 'before' => $args['date_to']
), ),
'post_status' => 'publish', 'post_status' => 'publish'
); );
$records_created_posts = query_posts( $query_string ); $records_created_posts = query_posts( $query_string );
if ( $records_created_posts ) { if ($records_created_posts) {
for ( $i = 0; $i < count($records); $i++ ) { for( $i = 0; $i < count($records); $i++ ) {
$record = $records[ $i ]; $record = $records[$i];
if ( $record->connector == 'posts' && $record->context == 'post' && $record->action == 'created' ) { if ($record->connector == 'posts' && $record->context == 'post' && $record->action == 'created') {
if ( ! in_array($record->ID, $skip_records) ) { if (!in_array($record->ID, $skip_records)) {
$skip_records[] = $record->ID; // so avoid this created logging, will use logging query from posts data $skip_records[] = $record->ID; // so avoid this created logging, will use logging query from posts data
} }
} }
@ -371,29 +365,30 @@ class MainWP_Client_Report {
$post_authors = array(); $post_authors = array();
foreach ( $records_created_posts as $_post ) { foreach( $records_created_posts as $_post){
$au_id = $_post->post_author; $au_id = $_post->post_author;
if ( ! isset($post_authors[ $au_id ]) ) { if ( !isset($post_authors[$au_id]) ) {
$au = get_user_by( 'id', $au_id ); $au = get_user_by( 'id', $au_id );
$post_authors[ $au_id ] = $au->display_name; $post_authors[$au_id] = $au->display_name;
} }
$au_name = $post_authors[ $au_id ]; $au_name = $post_authors[$au_id];
// simulate logging created posts record //simulate logging created posts record
$stdObj = new stdClass(); $stdObj = new stdClass;
$stdObj->ID = 0; // simulate ID value $stdObj->ID = 0; // simulate ID value
$stdObj->connector = 'posts'; $stdObj->connector = 'posts';
$stdObj->context = 'post'; $stdObj->context = 'post';
$stdObj->action = 'created'; $stdObj->action = 'created';
$stdObj->created = $_post->post_date; $stdObj->created = $_post->post_date;
$stdObj->meta = array( $stdObj->meta = array(
'post_title' => array( $_post->post_title ), 'post_title' => array( $_post->post_title ),
'user_meta' => array( $au_name ), 'user_meta' => array( $au_name )
); );
$records[] = $stdObj; $records[] = $stdObj;
} }
} }
} }
if ( isset( $other_tokens['header'] ) && is_array( $other_tokens['header'] ) ) { if ( isset( $other_tokens['header'] ) && is_array( $other_tokens['header'] ) ) {
@ -445,12 +440,11 @@ class MainWP_Client_Report {
$tokens = array(); $tokens = array();
} }
$backups_created_time_to_fix = array(); $backups_created_time_to_fix = array();
foreach ( $tokens as $token ) { foreach ( $tokens as $token ) {
if ( isset( $token_values[ $token ] ) ) { if ( isset( $token_values[ $token ] ) )
continue; continue;
}
$str_tmp = str_replace( array( '[', ']' ), '', $token ); $str_tmp = str_replace( array( '[', ']' ), '', $token );
$array_tmp = explode( '.', $str_tmp ); $array_tmp = explode( '.', $str_tmp );
@ -459,7 +453,7 @@ class MainWP_Client_Report {
$context = $action = $data = ''; $context = $action = $data = '';
if ( 2 === count( $array_tmp ) ) { if ( 2 === count( $array_tmp ) ) {
list( $context, $data ) = $array_tmp; list( $context, $data ) = $array_tmp;
} elseif ( 3 === count( $array_tmp ) ) { } else if ( 3 === count( $array_tmp ) ) {
list( $context, $action, $data ) = $array_tmp; list( $context, $action, $data ) = $array_tmp;
} }
@ -477,18 +471,19 @@ class MainWP_Client_Report {
$context = 'users'; // see class-connector-user.php $context = 'users'; // see class-connector-user.php
} }
} }
////
switch ( $data ) { switch ( $data ) {
case 'count': case 'count':
$count = 0; $count = 0;
foreach ( $records as $record ) { foreach ( $records as $record ) {
// check connector // check connector
if ( $record->connector == 'editor' ) { if ( $record->connector == 'editor' ) {
if ( ! in_array( $context, array( 'plugins', 'themes' ) ) || $action !== 'updated' ) { if ( !in_array( $context, array('plugins', 'themes') ) || $action !== 'updated' )
continue; continue;
} } else if ( $connector !== $record->connector ) {
} elseif ( $connector !== $record->connector ) {
continue; continue;
} }
@ -498,43 +493,44 @@ class MainWP_Client_Report {
if ( ! in_array( $record->context, $comment_contexts ) ) { if ( ! in_array( $record->context, $comment_contexts ) ) {
continue; continue;
} }
} elseif ( 'post' === $context && 'created' === $action ) { } else if ( 'post' === $context && 'created' === $action ) {
if ( in_array($record->ID, $skip_records) ) { if ( in_array($record->ID, $skip_records) ) {
continue; continue;
} }
} elseif ( $context == 'menus' ) { } else if ( $context == "menus") {
// ok, pass, don't check context // ok, pass, don't check context
} elseif ( $record->connector == 'editor' ) { } else if ( $record->connector == 'editor' ) {
// ok, pass, checked above // ok, pass, checked above
} elseif ( $connector == 'media' && $record->connector == 'media' ) { } else if ( $connector == 'media' && $record->connector == 'media' ) {
// ok, pass, do not check context // ok, pass, do not check context
} elseif ( $connector == 'widgets' && $record->connector == 'widgets' ) { } else if ( $connector == "widgets" && $record->connector == 'widgets') {
// ok, pass, don't check context // ok, pass, don't check context
} elseif ( $context !== strtolower( $record->context ) ) { } else if ( $context !== strtolower( $record->context )) {
continue; continue;
} }
// custom action value // custom action value
if ( $connector == 'widgets' ) { if ( $connector == "widgets" ) {
if ( $action == 'deleted' ) { if ( $action == "deleted" ) {
$action = 'removed'; // action saved in database $action = "removed"; // action saved in database
} }
} }
////
// check action // check action
if ( 'backups' === $context ) { if ( 'backups' === $context ) {
if ( ! $this->is_backup_action($record->action) ) { if ( ! $this->is_backup_action($record->action) ) {
continue; continue;
} }
$created = strtotime( $record->created ); $created = strtotime( $record->created );
if ( in_array( $created, $backups_created_time_to_fix ) ) { if ( in_array( $created, $backups_created_time_to_fix ) ) {
if ( ! in_array($record->ID, $skip_records) ) { if ( ! in_array($record->ID, $skip_records) ) {
$skip_records[] = $record->ID; $skip_records[] = $record->ID;
} }
continue; continue;
} else { } else {
$backups_created_time_to_fix[] = $created; $backups_created_time_to_fix[] = $created;
} }
} else { } else {
if ( $action !== $record->action ) { if ( $action !== $record->action ) {
continue; continue;
@ -545,20 +541,18 @@ class MainWP_Client_Report {
if ( 'draft' === $new_status ) { // avoid auto save post if ( 'draft' === $new_status ) { // avoid auto save post
continue; continue;
} }
} elseif ( 'updated' === $action && ( 'themes' === $context || 'plugins' === $context ) ) { } else if ( 'updated' === $action && ('themes' === $context || 'plugins' === $context)) {
$name = $this->get_stream_meta_data( $record, 'name' ); $name = $this->get_stream_meta_data( $record, 'name' );
if ( empty($name) ) { // to fix empty value if ( empty($name) ) { // to fix empty value
if ( ! in_array($record->ID, $skip_records) ) { if (!in_array($record->ID, $skip_records))
$skip_records[] = $record->ID; $skip_records[] = $record->ID;
}
continue; continue;
} else { } else {
$old_version = $this->get_stream_meta_data( $record, 'old_version' ); $old_version = $this->get_stream_meta_data( $record, 'old_version' );
$version = $this->get_stream_meta_data( $record, 'version' ); $version = $this->get_stream_meta_data( $record, 'version' );
if ( version_compare($version, $old_version, '<=') ) { // to fix if (version_compare($version, $old_version, '<=')) { // to fix
if ( ! in_array($record->ID, $skip_records) ) { if (!in_array($record->ID, $skip_records))
$skip_records[] = $record->ID; $skip_records[] = $record->ID;
}
continue; continue;
} }
} }
@ -577,16 +571,17 @@ class MainWP_Client_Report {
function get_section_loop_data( $records, $tokens, $section, $skip_records = array() ) { function get_section_loop_data( $records, $tokens, $section, $skip_records = array() ) {
$maintenance_details = array( $maintenance_details = array(
'revisions' => __( 'Delete all post revisions', 'mainwp-child' ), 'revisions' => __( 'Delete all post revisions', 'mainwp-child' ),
'autodraft' => __( 'Delete all auto draft posts', 'mainwp-child' ), 'autodraft' => __( 'Delete all auto draft posts', 'mainwp-child' ),
'trashpost' => __( 'Delete trash posts', 'mainwp-child' ), 'trashpost' => __( 'Delete trash posts', 'mainwp-child' ),
'spam' => __( 'Delete spam comments', 'mainwp-child' ), 'spam' => __( 'Delete spam comments', 'mainwp-child' ),
'pending' => __( 'Delete pending comments', 'mainwp-child' ), 'pending' => __( 'Delete pending comments', 'mainwp-child' ),
'trashcomment' => __( 'Delete trash comments', 'mainwp-child' ), 'trashcomment' => __( 'Delete trash comments', 'mainwp-child' ),
'tags' => __( 'Delete tags with 0 posts associated', 'mainwp-child' ), 'tags' => __( 'Delete tags with 0 posts associated', 'mainwp-child' ),
'categories' => __( 'Delete categories with 0 posts associated', 'mainwp-child' ), 'categories' => __( 'Delete categories with 0 posts associated', 'mainwp-child' ),
'optimize' => __( 'Optimize database tables', 'mainwp-child' ), 'optimize' => __( 'Optimize database tables', 'mainwp-child' )
); );
$context = $action = ''; $context = $action = '';
@ -597,7 +592,7 @@ class MainWP_Client_Report {
if ( is_array( $array_tmp ) ) { if ( is_array( $array_tmp ) ) {
if ( 2 === count( $array_tmp ) ) { if ( 2 === count( $array_tmp ) ) {
list( $str1, $context ) = $array_tmp; list( $str1, $context ) = $array_tmp;
} elseif ( 3 === count( $array_tmp ) ) { } else if ( 3 === count( $array_tmp ) ) {
list( $str1, $context, $action ) = $array_tmp; list( $str1, $context, $action ) = $array_tmp;
} }
} }
@ -628,45 +623,45 @@ class MainWP_Client_Report {
// check connector // check connector
if ( $record->connector == 'editor' ) { if ( $record->connector == 'editor' ) {
if ( ! in_array( $context, array( 'plugins', 'themes' ) ) || $action !== 'updated' ) { if ( !in_array( $context, array('plugins', 'themes') ) || $action !== 'updated' )
continue; continue;
} } else if ( $connector !== $record->connector ) {
} elseif ( $connector !== $record->connector ) {
continue; continue;
} }
// check context // check context
if ( $context == 'comments' ) { // multi values if ( $context == "comments" ) { // multi values
$comment_contexts = array( 'post', 'page' ); $comment_contexts = array('post', 'page');
if ( ! in_array( $record->context, $comment_contexts ) ) { if ( ! in_array( $record->context, $comment_contexts ) ) {
continue; continue;
} }
} elseif ( $context == 'menus' ) { } else if ( $context == "menus") {
// ok, pass, don't check context // ok, pass, don't check context
} elseif ( $record->connector == 'editor' ) { } else if ( $record->connector == 'editor' ) {
// ok, pass, checked above // ok, pass, checked above
} elseif ( $connector == 'media' && $record->connector == 'media' ) { } else if ( $connector == 'media' && $record->connector == 'media' ) {
// ok, pass, do not check context // ok, pass, do not check context
} elseif ( $connector == 'widgets' && $record->connector == 'widgets' ) { } else if ( $connector == "widgets" && $record->connector == 'widgets') {
// ok, pass, don't check context // ok, pass, don't check context
// //
} elseif ( $context !== strtolower( $record->context ) ) { } else if ( $context !== strtolower( $record->context ) ) {
continue; continue;
} }
// custom action value // custom action value
if ( $connector == 'widgets' ) { if ( $connector == "widgets" ) {
if ( $action == 'deleted' ) { if ( $action == "deleted" ) {
$action = 'removed'; // action saved in database $action = "removed"; // action saved in database
} }
} }
////
// check action // check action
if ( $context == 'backups' ) { if ( $context == 'backups' ) {
if ( ! $this->is_backup_action($record->action) ) { if ( ! $this->is_backup_action($record->action) ) {
continue; continue;
} }
} elseif ( $action !== $record->action ) { } else if ( $action !== $record->action ) {
continue; continue;
} }
@ -677,7 +672,7 @@ class MainWP_Client_Report {
} }
} }
// $skip_this_loop = false; //$skip_this_loop = false;
$token_values = array(); $token_values = array();
foreach ( $tokens as $token ) { foreach ( $tokens as $token ) {
@ -691,16 +686,16 @@ class MainWP_Client_Report {
} else { } else {
if ( 1 === count( $array_tmp ) ) { if ( 1 === count( $array_tmp ) ) {
list( $data ) = $array_tmp; list( $data ) = $array_tmp;
} elseif ( 2 === count( $array_tmp ) ) { } else if ( 2 === count( $array_tmp ) ) {
list( $str1, $data ) = $array_tmp; list( $str1, $data ) = $array_tmp;
} elseif ( 3 === count( $array_tmp ) ) { } else if ( 3 === count( $array_tmp ) ) {
list( $str1, $str2, $data ) = $array_tmp; list( $str1, $str2, $data ) = $array_tmp;
} }
if ( 'version' === $data ) { if ( 'version' === $data ) {
if ( 'old' === $str2 ) { if ( 'old' === $str2 ) {
$data = 'old_version'; $data = 'old_version';
} elseif ( 'current' === $str2 && 'WordPress' === $str1 ) { } else if ( 'current' === $str2 && 'wordpress' === $str1 ) {
$data = 'new_version'; $data = 'new_version';
} }
} }
@ -721,7 +716,7 @@ class MainWP_Client_Report {
$tok_value = MainWP_Helper::formatTime( MainWP_Helper::getTimestamp( strtotime( $record->created ) ) ); $tok_value = MainWP_Helper::formatTime( MainWP_Helper::getTimestamp( strtotime( $record->created ) ) );
break; break;
case 'area': case 'area':
$data = 'sidebar_name'; $data = 'sidebar_name';
$tok_value = $this->get_stream_meta_data( $record, $data ); $tok_value = $this->get_stream_meta_data( $record, $data );
break; break;
case 'name': case 'name':
@ -730,11 +725,10 @@ class MainWP_Client_Report {
case 'new_version': case 'new_version':
case 'display_name': case 'display_name':
case 'roles': case 'roles':
if ( $data == 'name' ) { if ( $data == 'name' ) {
if ( $context == 'profiles' ) { if ( $context == 'profiles' )
$data = 'display_name'; $data = 'display_name';
} }
}
$tok_value = $this->get_stream_meta_data( $record, $data ); $tok_value = $this->get_stream_meta_data( $record, $data );
break; break;
case 'title': case 'title':
@ -743,17 +737,17 @@ class MainWP_Client_Report {
} else { } else {
if ( 'page' === $context || 'post' === $context ) { if ( 'page' === $context || 'post' === $context ) {
$data = 'post_title'; $data = 'post_title';
} elseif ( 'menus' === $record->connector ) { } else if ( 'menus' === $record->connector ) {
$data = 'name'; $data = 'name';
} }
$tok_value = $this->get_stream_meta_data( $record, $data ); $tok_value = $this->get_stream_meta_data( $record, $data );
} }
break; break;
case 'author': case 'author':
if ( $connector == 'comment' ) { if ( $connector == "comment" ) {
$data = 'user_name'; $data = 'user_name';
} else { } else {
$data = 'user_meta'; $data = 'user_meta';
} }
$value = $this->get_stream_meta_data( $record, $data ); $value = $this->get_stream_meta_data( $record, $data );
@ -763,7 +757,7 @@ class MainWP_Client_Report {
} }
// to check may compatible with old meta data // to check may compatible with old meta data
if ( empty( $value ) ) { if ( empty( $value )) {
$value = $this->get_stream_meta_data( $record, 'author_meta' ); $value = $this->get_stream_meta_data( $record, 'author_meta' );
} }
@ -772,69 +766,71 @@ class MainWP_Client_Report {
case 'status': // sucuri cases case 'status': // sucuri cases
case 'webtrust': case 'webtrust':
if ( 'sucuri_scan' === $context ) { if ( 'sucuri_scan' === $context ) {
$scan_data = $this->get_stream_meta_data( $record, 'scan_data' ); $scan_data = $this->get_stream_meta_data( $record, 'scan_data' );
if ( ! empty($scan_data) ) { if (!empty($scan_data)) {
$scan_data = maybe_unserialize( base64_decode( $scan_data ) ); $scan_data = maybe_unserialize( base64_decode( $scan_data ) );
if ( is_array( $scan_data ) ) { if ( is_array( $scan_data ) ) {
$blacklisted = $scan_data['blacklisted']; $blacklisted = $scan_data['blacklisted'];
$malware_exists = $scan_data['malware_exists']; $malware_exists = $scan_data['malware_exists'];
$status = array(); $status = array();
if ( $blacklisted ) { if ( $blacklisted ) {
$status[] = __( 'Site Blacklisted', 'mainwp-child' ); } $status[] = __( 'Site Blacklisted', 'mainwp-child' ); }
if ( $malware_exists ) { if ( $malware_exists ) {
$status[] = __( 'Site With Warnings', 'mainwp-child' ); } $status[] = __( 'Site With Warnings', 'mainwp-child' ); }
if ( $data == 'status' ) { if ($data == 'status') {
$tok_value = count( $status ) > 0 ? implode( ', ', $status ) : __( 'Verified Clear', 'mainwp-child' ); $tok_value = count( $status ) > 0 ? implode( ', ', $status ) : __( 'Verified Clear', 'mainwp-child' );
} elseif ( $data == 'webtrust' ) { } else if ($data == 'webtrust') {
$tok_value = $blacklisted ? __( 'Site Blacklisted', 'mainwp-child' ) : __( 'Trusted', 'mainwp-child' ); $tok_value = $blacklisted ? __( 'Site Blacklisted', 'mainwp-child' ) : __( 'Trusted', 'mainwp-child' );
} }
} }
} else {
$tok_value = $this->get_stream_meta_data( $record, $data ); } else {
} $tok_value = $this->get_stream_meta_data( $record, $data );
}
} else { } else {
$tok_value = $value; $tok_value = $value;
} }
break; break;
case 'details': case 'details':
case 'result': case 'result':
if ( 'mainwp_maintenance' === $context && 'details' == $data ) {
$meta_value = $this->get_stream_meta_data( $record, $data ); if ('mainwp_maintenance' === $context && 'details' == $data) {
$meta_value = explode(',', $meta_value);
$meta_value = $this->get_stream_meta_data( $record, $data );
$meta_value = explode(",", $meta_value);
$details = array(); $details = array();
if ( is_array( $meta_value) ) { if ( is_array( $meta_value) ) {
foreach ( $meta_value as $mt ) { foreach($meta_value as $mt) {
if ( isset($maintenance_details[ $mt ]) ) { if ( isset($maintenance_details[$mt]) ) {
$details[] = $maintenance_details[ $mt ]; $details[] = $maintenance_details[$mt];
} }
} }
} }
$tok_value = implode(', ', $details); $tok_value = implode(", ", $details);
} elseif ( 'wordfence_scan' === $context || 'mainwp_maintenance' === $context ) { } else if ( 'wordfence_scan' === $context || 'mainwp_maintenance' === $context ) {
$meta_value = $this->get_stream_meta_data( $record, $data ); $meta_value = $this->get_stream_meta_data( $record, $data );
// to fix // to fix
if ( 'wordfence_scan' === $context && $data == 'result' ) { if ('wordfence_scan' === $context && $data == 'result') {
// SUM_FINAL:Scan complete. You have xxx new issues to fix. See below. // SUM_FINAL:Scan complete. You have xxx new issues to fix. See below.
// SUM_FINAL:Scan complete. Congratulations, no new problems found // SUM_FINAL:Scan complete. Congratulations, no new problems found
if ( stripos($meta_value, 'Congratulations') ) { if (stripos($meta_value, 'Congratulations')) {
$meta_value = 'No issues detected'; $meta_value = 'No issues detected';
} elseif ( stripos($meta_value, 'You have') ) { } else if (stripos($meta_value, 'You have')) {
$meta_value = 'Issues Detected'; $meta_value = 'Issues Detected';
} else { } else {
$meta_value = ''; $meta_value = '';
} }
} }
$tok_value = $meta_value; $tok_value = $meta_value;
} }
break; break;
// case 'destination': // for backup tokens //case 'destination': // for backup tokens
case 'type': case 'type':
if ( 'backups' === $context ) { if ( 'backups' === $context ) {
$tok_value = $this->get_stream_meta_data( $record, $data ); $tok_value = $this->get_stream_meta_data( $record, $data );
@ -850,18 +846,20 @@ class MainWP_Client_Report {
$token_values[ $token ] = $tok_value; $token_values[ $token ] = $tok_value;
if ( empty( $tok_value ) ) { if ( empty( $tok_value ) ) {
// $skip_this_loop = true; //$skip_this_loop = true;
if ( defined( 'MAINWP_CHILD_DEBUG' ) && MAINWP_CHILD_DEBUG === true ) { if ( defined( 'MAINWP_CHILD_DEBUG' ) && MAINWP_CHILD_DEBUG === TRUE ) {
error_log('MainWP Child Report:: skip empty value :: token :: ' . $token . ' :: record :: ' . print_r( $record, true )); error_log("MainWP Child Report:: skip empty value :: token :: " . $token . " :: record :: " . print_r( $record, true ));
} }
// break; //break;
} }
} // foreach $tokens } // foreach $tokens
if ( ! empty( $token_values ) ) { if ( ! empty( $token_values ) ) {
$loops[ $loop_count ] = $token_values; $loops[ $loop_count ] = $token_values;
$loop_count ++; $loop_count ++;
} }
} // foreach $records } // foreach $records
return $loops; return $loops;
} }
@ -887,18 +885,18 @@ class MainWP_Client_Report {
// to compatible with old meta data // to compatible with old meta data
if ( 'author_meta' === $meta_key ) { if ( 'author_meta' === $meta_key ) {
$value = maybe_unserialize( $value ); $value = maybe_unserialize( $value );
if ( is_array($value) ) { if (is_array($value)) {
$value = $value['display_name']; $value = $value['display_name'];
// to fix empty author value // to fix empty author value
if ( empty($value) ) { if ( empty($value) ) {
if ( isset($value['agent']) && ! empty($value['agent']) ) { if (isset($value['agent']) && !empty($value['agent'])) {
$value = $value['agent']; $value = $value['agent'];
} }
} }
} }
if ( ! is_string($value) ) { if (!is_string($value)) {
$value = ''; $value = '';
} }
} }
// end // end
} }
@ -908,52 +906,52 @@ class MainWP_Client_Report {
} }
function set_showhide() { function set_showhide() {
$hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : ''; $hide = isset( $_POST['showhide'] ) && ( 'hide' === $_POST['showhide'] ) ? 'hide' : '';
MainWP_Child_Branding::Instance()->save_branding_options('hide_child_reports', $hide); MainWP_Child_Branding::Instance()->save_branding_options('hide_child_reports', $hide);
// MainWP_Helper::update_option( 'mainwp_creport_branding_stream_hide', $hide, 'yes' ); // to compatible with old child reports //MainWP_Helper::update_option( 'mainwp_creport_branding_stream_hide', $hide, 'yes' ); // to compatible with old child reports
$information['result'] = 'SUCCESS'; $information['result'] = 'SUCCESS';
return $information; return $information;
} }
public function creport_init() { public function creport_init() {
$branding_opts = MainWP_Child_Branding::Instance()->get_branding_options(); $branding_opts = MainWP_Child_Branding::Instance()->get_branding_options();
$hide_nag = false; $hide_nag = false;
// check setting of 'hide_child_reports' // check setting of 'hide_child_reports'
if ( isset($branding_opts['hide_child_reports']) && $branding_opts['hide_child_reports'] == 'hide' ) { if ( isset($branding_opts['hide_child_reports']) && $branding_opts['hide_child_reports'] == 'hide' ) {
add_filter( 'all_plugins', array( $this, 'creport_branding_plugin' ) ); add_filter( 'all_plugins', array( $this, 'creport_branding_plugin' ) );
add_action( 'admin_menu', array( $this, 'creport_remove_menu' ) ); add_action( 'admin_menu', array( $this, 'creport_remove_menu' ) );
$hide_nag = true; $hide_nag = true;
} }
if ( ! $hide_nag ) { if ( ! $hide_nag ) {
// check child branding settings // check child branding settings
if ( MainWP_Child_Branding::Instance()->is_branding() ) { if ( MainWP_Child_Branding::Instance()->is_branding() ) {
$hide_nag = true; $hide_nag = true;
} }
} }
if ( $hide_nag ) { if ($hide_nag) {
add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) ); add_filter( 'site_transient_update_plugins', array( &$this, 'remove_update_nag' ) );
add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) ); add_filter( 'mainwp_child_hide_update_notice', array( &$this, 'hide_update_notice' ) );
} }
} }
function hide_update_notice( $slugs ) { function hide_update_notice( $slugs ) {
$slugs[] = 'mainwp-child-reports/mainwp-child-reports.php'; $slugs[] = 'mainwp-child-reports/mainwp-child-reports.php';
return $slugs; return $slugs;
} }
function remove_update_nag( $value ) { function remove_update_nag( $value ) {
if ( isset( $_POST['mainwpsignature'] ) ) { if ( isset( $_POST['mainwpsignature'] ) ) {
return $value; return $value;
} }
if ( ! MainWP_Helper::is_screen_with_update() ) { if (! MainWP_Helper::is_screen_with_update()) {
return $value; return $value;
} }
if ( isset( $value->response['mainwp-child-reports/mainwp-child-reports.php'] ) ) { if ( isset( $value->response['mainwp-child-reports/mainwp-child-reports.php'] ) ) {
unset( $value->response['mainwp-child-reports/mainwp-child-reports.php'] ); unset( $value->response['mainwp-child-reports/mainwp-child-reports.php'] );

View file

@ -12,16 +12,16 @@ class MainWP_Clone_Install {
* @param string $file The zip backup file path * @param string $file The zip backup file path
*/ */
public function __construct( $file ) { public function __construct( $file ) {
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php'; require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
$this->file = $file; $this->file = $file;
if ( '.zip' === substr( $this->file, - 4 ) ) { if ( '.zip' === substr( $this->file, - 4 ) ) {
$this->archiver = null; $this->archiver = null;
} elseif ( '.tar.gz' === substr( $this->file, - 7 ) ) { } else if ( '.tar.gz' === substr( $this->file, - 7 ) ) {
$this->archiver = new Tar_Archiver( null, 'tar.gz' ); $this->archiver = new Tar_Archiver( null, 'tar.gz' );
} elseif ( '.tar.bz2' === substr( $this->file, - 8 ) ) { } else if ( '.tar.bz2' === substr( $this->file, - 8 ) ) {
$this->archiver = new Tar_Archiver( null, 'tar.bz2' ); $this->archiver = new Tar_Archiver( null, 'tar.bz2' );
} elseif ( '.tar' === substr( $this->file, - 4 ) ) { } else if ( '.tar' === substr( $this->file, - 4 ) ) {
$this->archiver = new Tar_Archiver( null, 'tar' ); $this->archiver = new Tar_Archiver( null, 'tar' );
} }
} }
@ -41,8 +41,8 @@ class MainWP_Clone_Install {
* @return bool * @return bool
*/ */
public function checkZipConsole() { public function checkZipConsole() {
// todo: implement //todo: implement
// return function_exists('system'); // return function_exists('system');
return false; return false;
} }
@ -58,9 +58,9 @@ class MainWP_Clone_Install {
if ( null !== $this->archiver ) { if ( null !== $this->archiver ) {
} elseif ( $this->checkZipConsole() ) { } else if ( $this->checkZipConsole() ) {
// todo: implement //todo: implement
} elseif ( $this->checkZipSupport() ) { } else if ( $this->checkZipSupport() ) {
$zip = new ZipArchive(); $zip = new ZipArchive();
$zipRes = $zip->open( $this->file ); $zipRes = $zip->open( $this->file );
if ( $zipRes ) { if ( $zipRes ) {
@ -73,7 +73,7 @@ class MainWP_Clone_Install {
return false; return false;
} else { } else {
// use pclzip //use pclzip
$zip = new PclZip( $this->file ); $zip = new PclZip( $this->file );
$list = $zip->delete( PCLZIP_OPT_BY_NAME, 'wp-config.php' ); $list = $zip->delete( PCLZIP_OPT_BY_NAME, 'wp-config.php' );
$list2 = $zip->delete( PCLZIP_OPT_BY_NAME, 'clone' ); $list2 = $zip->delete( PCLZIP_OPT_BY_NAME, 'clone' );
@ -114,9 +114,9 @@ class MainWP_Clone_Install {
} }
return $this->archiver->file_exists( $file ); return $this->archiver->file_exists( $file );
} elseif ( $this->checkZipConsole() ) { } else if ( $this->checkZipConsole() ) {
// todo: implement //todo: implement
} elseif ( $this->checkZipSupport() ) { } else if ( $this->checkZipSupport() ) {
$zip = new ZipArchive(); $zip = new ZipArchive();
$zipRes = $zip->open( $this->file ); $zipRes = $zip->open( $this->file );
if ( $zipRes ) { if ( $zipRes ) {
@ -236,7 +236,7 @@ class MainWP_Clone_Install {
$readline = ''; $readline = '';
while ( ( $line = fgets( $handle, 81920 ) ) !== false ) { while ( ( $line = fgets( $handle, 81920 ) ) !== false ) {
if ( time() - $lastRun > 20 ) { if ( time() - $lastRun > 20 ) {
@set_time_limit( 0 ); // reset timer.. @set_time_limit( 0 ); //reset timer..
$lastRun = time(); $lastRun = time();
} }
@ -331,16 +331,16 @@ class MainWP_Clone_Install {
} }
$token = $data[0]; $token = $data[0];
switch ( $token ) { switch ( $token ) {
case 's': case 's' :
if ( '"' !== $data[ $length - 2 ] ) { if ( '"' !== $data[ $length - 2 ] ) {
return false; return false;
} }
case 'a': case 'a' :
case 'O': case 'O' :
return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data ); return (bool) preg_match( "/^{$token}:[0-9]+:/s", $data );
case 'b': case 'b' :
case 'i': case 'i' :
case 'd': case 'd' :
return (bool) preg_match( "/^{$token}:[0-9.E-]+;\$/", $data ); return (bool) preg_match( "/^{$token}:[0-9.E-]+;\$/", $data );
} }
@ -373,14 +373,14 @@ class MainWP_Clone_Install {
return $content; return $content;
} else { } else {
if ( $this->checkZipConsole() ) { if ( $this->checkZipConsole() ) {
// todo: implement //todo: implement
} elseif ( $this->checkZipSupport() ) { } else if ( $this->checkZipSupport() ) {
$zip = new ZipArchive(); $zip = new ZipArchive();
$zipRes = $zip->open( $this->file ); $zipRes = $zip->open( $this->file );
if ( $zipRes ) { if ( $zipRes ) {
$content = $zip->getFromName( 'clone/config.txt' ); $content = $zip->getFromName( 'clone/config.txt' );
// $zip->deleteName('clone/config.txt'); // $zip->deleteName('clone/config.txt');
// $zip->deleteName('clone/'); // $zip->deleteName('clone/');
$zip->close(); $zip->close();
return $content; return $content;
@ -388,7 +388,7 @@ class MainWP_Clone_Install {
return false; return false;
} else { } else {
// use pclzip //use pclzip
$zip = new PclZip( $this->file ); $zip = new PclZip( $this->file );
$content = $zip->extract( PCLZIP_OPT_BY_NAME, 'clone/config.txt', $content = $zip->extract( PCLZIP_OPT_BY_NAME, 'clone/config.txt',
PCLZIP_OPT_EXTRACT_AS_STRING ); PCLZIP_OPT_EXTRACT_AS_STRING );
@ -419,13 +419,13 @@ class MainWP_Clone_Install {
} }
return $this->archiver->extractTo( ABSPATH ); return $this->archiver->extractTo( ABSPATH );
} elseif ( ( filesize( $this->file ) >= 50000000 ) && $this->checkWPZip() ) { } else if ( ( filesize( $this->file ) >= 50000000 ) && $this->checkWPZip() ) {
return $this->extractWPZipBackup(); return $this->extractWPZipBackup();
} elseif ( $this->checkZipConsole() ) { } else if ( $this->checkZipConsole() ) {
return $this->extractZipConsoleBackup(); return $this->extractZipConsoleBackup();
} elseif ( $this->checkZipSupport() ) { } else if ( $this->checkZipSupport() ) {
return $this->extractZipBackup(); return $this->extractZipBackup();
} elseif ( ( filesize( $this->file ) < 50000000 ) && $this->checkWPZip() ) { } else if ( ( filesize( $this->file ) < 50000000 ) && $this->checkWPZip() ) {
return $this->extractWPZipBackup(); return $this->extractWPZipBackup();
} else { } else {
return $this->extractZipPclBackup(); return $this->extractZipPclBackup();
@ -484,8 +484,8 @@ class MainWP_Clone_Install {
* @return bool * @return bool
*/ */
public function extractZipConsoleBackup() { public function extractZipConsoleBackup() {
// todo implement //todo implement
// system('zip'); //system('zip');
return false; return false;
} }
@ -536,10 +536,10 @@ class MainWP_Clone_Install {
* We split large tables into 50,000 row blocks when dealing with them to save * We split large tables into 50,000 row blocks when dealing with them to save
* on memmory consumption. * on memmory consumption.
* *
* @param mysql $connection The db connection object * @param mysql $connection The db connection object
* @param string $search What we want to replace * @param string $search What we want to replace
* @param string $replace What we want to replace it with. * @param string $replace What we want to replace it with.
* @param array $tables The tables we want to look at. * @param array $tables The tables we want to look at.
* *
* @return array Collection of information gathered during the run. * @return array Collection of information gathered during the run.
*/ */
@ -654,7 +654,7 @@ class MainWP_Clone_Install {
// some unseriliased data cannot be re-serialised eg. SimpleXMLElements // some unseriliased data cannot be re-serialised eg. SimpleXMLElements
try { try {
if ( is_string( $data ) && is_serialized( $data ) && ! is_serialized_string( $data ) && ( $unserialized = @unserialize( $data ) ) !== false ) { if ( is_string( $data ) && is_serialized( $data ) && !is_serialized_string( $data ) && ( $unserialized = @unserialize( $data ) ) !== false ) {
$data = $this->recursive_unserialize_replace( $from, $to, $unserialized, true ); $data = $this->recursive_unserialize_replace( $from, $to, $unserialized, true );
} elseif ( is_array( $data ) ) { } elseif ( is_array( $data ) ) {
$_tmp = array(); $_tmp = array();
@ -665,7 +665,7 @@ class MainWP_Clone_Install {
$data = $_tmp; $data = $_tmp;
unset( $_tmp ); unset( $_tmp );
} elseif ( is_object( $data ) ) { } elseif ( is_object( $data ) ) {
$_tmp = $data; $_tmp = $data;
$props = get_object_vars( $data ); $props = get_object_vars( $data );
foreach ( $props as $key => $value ) { foreach ( $props as $key => $value ) {
$_tmp->{$key} = $this->recursive_unserialize_replace( $from, $to, $value, false ); $_tmp->{$key} = $this->recursive_unserialize_replace( $from, $to, $value, false );
@ -673,9 +673,9 @@ class MainWP_Clone_Install {
$data = $_tmp; $data = $_tmp;
unset( $_tmp ); unset( $_tmp );
} elseif (is_serialized_string($data) && is_serialized($data)) { } elseif (is_serialized_string($data) && is_serialized($data)) {
// TODO: apply solution like phpmyadmin project have! // TODO: apply solution like phpmyadmin project have!
if ( ( $data = @unserialize( $data ) ) !== false ) { if ( ($data = @unserialize( $data )) !== false ) {
$data = str_replace( $from, $to, $data ); $data = str_replace( $from, $to, $data );
$data = serialize( $data ); $data = serialize( $data );
} }

View file

@ -18,7 +18,7 @@ class MainWP_Clone {
} }
if ( ! function_exists( 'wp_create_nonce' ) ) { if ( ! function_exists( 'wp_create_nonce' ) ) {
include_once ABSPATH . WPINC . '/pluggable.php'; include_once( ABSPATH . WPINC . '/pluggable.php' );
} }
$this->security_nonces[ $action ] = wp_create_nonce( $action ); $this->security_nonces[ $action ] = wp_create_nonce( $action );
} }
@ -50,7 +50,7 @@ class MainWP_Clone {
$ajaxPosts = array(); $ajaxPosts = array();
} }
// If already processed, just quit! //If already processed, just quit!
if ( isset( $ajaxPosts[ $action ] ) && ( $ajaxPosts[ $action ] == $_POST['dts'] ) ) { if ( isset( $ajaxPosts[ $action ] ) && ( $ajaxPosts[ $action ] == $_POST['dts'] ) ) {
die( json_encode( array( 'error' => __( 'Double request!', 'mainwp-child' ) ) ) ); die( json_encode( array( 'error' => __( 'Double request!', 'mainwp-child' ) ) ) );
} }
@ -112,7 +112,7 @@ class MainWP_Clone {
if ( isset( $_REQUEST['upload'] ) && wp_verify_nonce( $_POST['_nonce'], 'cloneRestore' ) ) { if ( isset( $_REQUEST['upload'] ) && wp_verify_nonce( $_POST['_nonce'], 'cloneRestore' ) ) {
if ( isset( $_FILES['file'] ) ) { if ( isset( $_FILES['file'] ) ) {
if ( ! function_exists( 'wp_handle_upload' ) ) { if ( ! function_exists( 'wp_handle_upload' ) ) {
require_once ABSPATH . 'wp-admin/includes/file.php'; require_once( ABSPATH . 'wp-admin/includes/file.php' );
} }
$uploadedfile = $_FILES['file']; $uploadedfile = $_FILES['file'];
$upload_overrides = array( 'test_form' => false ); $upload_overrides = array( 'test_form' => false );
@ -153,17 +153,13 @@ class MainWP_Clone {
<?php <?php
if ( $uploadFile ) { if ( $uploadFile ) {
esc_html_e( 'Upload successful.', 'mainwp-child' ); esc_html_e( 'Upload successful.', 'mainwp-child' ); ?> <a href="#" id="mainwp-child_uploadclonebutton"
?>
<a href="#" id="mainwp-child_uploadclonebutton"
class="button-primary" class="button-primary"
file="<?php echo esc_attr( $uploadFile ); ?>"><?php esc_html_e( 'Clone/Restore website', 'mainwp-child' ); ?></a> file="<?php echo esc_attr( $uploadFile ); ?>"><?php esc_html_e( 'Clone/Restore website', 'mainwp-child' ); ?></a><?php
<?php
} else { } else {
if ( $uploadError ) { if ( $uploadError ) {
?> ?>
<div class="mainwp-child_info-box-red"><?php echo esc_html( $uploadError ); ?></div> <div class="mainwp-child_info-box-red"><?php echo esc_html( $uploadError ); ?></div><?php
<?php
} }
if ( empty( $sitesToClone ) ) { if ( empty( $sitesToClone ) ) {
@ -254,7 +250,7 @@ class MainWP_Clone {
if ( isset( $_REQUEST['upload'] ) && wp_verify_nonce( $_POST['_nonce'], 'cloneRestore' ) ) { if ( isset( $_REQUEST['upload'] ) && wp_verify_nonce( $_POST['_nonce'], 'cloneRestore' ) ) {
if ( isset( $_FILES['file'] ) ) { if ( isset( $_FILES['file'] ) ) {
if ( ! function_exists( 'wp_handle_upload' ) ) { if ( ! function_exists( 'wp_handle_upload' ) ) {
require_once ABSPATH . 'wp-admin/includes/file.php'; require_once( ABSPATH . 'wp-admin/includes/file.php' );
} }
$uploadedfile = $_FILES['file']; $uploadedfile = $_FILES['file'];
$upload_overrides = array( 'test_form' => false ); $upload_overrides = array( 'test_form' => false );
@ -281,30 +277,27 @@ class MainWP_Clone {
<?php <?php
MainWP_Helper::getWPFilesystem(); MainWP_Helper::getWPFilesystem();
global $wp_filesystem; global $wp_filesystem;
if ( ( ! empty( $wp_filesystem ) && ! $wp_filesystem->is_writable( WP_CONTENT_DIR ) ) || ( empty( $wp_filesystem ) && ! is_writable( WP_CONTENT_DIR ) ) ) { if ( ( ! empty( $wp_filesystem ) && ! $wp_filesystem->is_writable( WP_CONTENT_DIR ) ) || ( empty( $wp_filesystem ) && ! is_writable( WP_CONTENT_DIR ) ) ) {
echo '<div class="mainwp-child_info-box-red"><strong>' . esc_html__( 'Your content directory is not writable. Please set 0755 permission to ', 'mainwp-child' ) . esc_html( basename( WP_CONTENT_DIR ) ) . '. (' . esc_html( WP_CONTENT_DIR ) . ')</strong></div>'; echo '<div class="mainwp-child_info-box-red"><strong>' . esc_html__( 'Your content directory is not writable. Please set 0755 permission to ', 'mainwp-child' ) . esc_html( basename( WP_CONTENT_DIR ) ) . '. (' . esc_html( WP_CONTENT_DIR ) . ')</strong></div>';
$error = true; $error = true;
} }
?> ?>
<div class="mainwp-child_info-box-green" style="display: none;"><?php esc_html_e( 'Restore process completed successfully! You will now need to click ', 'mainwp-child' ); ?> <div class="mainwp-child_info-box-green" style="display: none;"><?php esc_html_e( 'Restore process completed successfully! You will now need to click ', 'mainwp-child' ); ?>
<a href="<?php echo esc_attr( admin_url( 'options-permalink.php' ) ); ?>"><?php esc_html_e( 'here', 'mainwp-child' ); ?></a><?php esc_html_e( ' to re-login to the admin and re-save permalinks.', 'mainwp-child' ); ?> <a href="<?php echo esc_attr( admin_url( 'options-permalink.php' ) ); ?>"><?php esc_html_e( 'here', 'mainwp-child' ); ?></a><?php esc_html_e( ' to re-login to the admin and re-save permalinks.', 'mainwp-child' ); ?>
</div> </div>
<?php <?php
if ( $uploadFile ) { if ( $uploadFile ) {
esc_html_e( 'Upload successful.', 'mainwp-child' ); esc_html_e( 'Upload successful.', 'mainwp-child' ); ?> <a href="#"
?>
<a href="#"
id="mainwp-child_uploadclonebutton" id="mainwp-child_uploadclonebutton"
class="button-primary" class="button-primary"
file="<?php echo esc_attr( $uploadFile ); ?>"><?php esc_html_e( 'Restore Website', 'mainwp-child' ); ?></a> file="<?php echo esc_attr( $uploadFile ); ?>"><?php esc_html_e( 'Restore Website', 'mainwp-child' ); ?></a><?php
<?php
} else { } else {
if ( $uploadError ) { if ( $uploadError ) {
?>
<div class="mainwp-child_info-box-red"><?php echo esc_html( $uploadError ); ?></div>
<?php
}
?> ?>
<div class="mainwp-child_info-box-red"><?php echo esc_html( $uploadError ); ?></div>
<?php
}
?>
<p><?php esc_html_e( 'Upload backup in .zip format (Maximum filesize for your server settings: ', 'mainwp-child' ); ?><?php echo esc_html( $uploadSize ); ?>)</p> <p><?php esc_html_e( 'Upload backup in .zip format (Maximum filesize for your server settings: ', 'mainwp-child' ); ?><?php echo esc_html( $uploadSize ); ?>)</p>
<?php <?php
$branding_title = MainWP_Child_Branding::Instance()->get_branding_title(); $branding_title = MainWP_Child_Branding::Instance()->get_branding_title();
@ -314,7 +307,7 @@ class MainWP_Clone {
$branding_msg = esc_html__( 'If you have a FULL backup created by basic MainWP Backup system you may restore it by uploading here. Backups created by 3rd party plugins will not work.', 'mainwp-child' ); $branding_msg = esc_html__( 'If you have a FULL backup created by basic MainWP Backup system you may restore it by uploading here. Backups created by 3rd party plugins will not work.', 'mainwp-child' );
} }
?> ?>
<em> <?php echo $branding_msg; ?> <br/> <em> <?php echo $branding_msg ; ?> <br/>
<?php esc_html_e( 'A database only backup will not work.', 'mainwp-child' ); ?></em><br/><br/> <?php esc_html_e( 'A database only backup will not work.', 'mainwp-child' ); ?></em><br/><br/>
<form action="<?php echo esc_attr( admin_url( 'options-general.php?page=mainwp_child_tab&tab=restore-clone&upload=yes' ) ); ?>" <form action="<?php echo esc_attr( admin_url( 'options-general.php?page=mainwp_child_tab&tab=restore-clone&upload=yes' ) ); ?>"
method="post" method="post"
@ -333,8 +326,8 @@ class MainWP_Clone {
</div> </div>
<?php <?php
self::renderCloneFromServer(); self::renderCloneFromServer();
self::renderJavaScript(); self::renderJavaScript();
} }
/* /*
@ -409,7 +402,7 @@ class MainWP_Clone {
$quick_links = array(); $quick_links = array();
foreach ( $quick_dirs as $dir ) { foreach ( $quick_dirs as $dir ) {
list( $text, $adir ) = $dir; list( $text, $adir ) = $dir;
$adir = str_replace( '\\', '/', strtolower( $adir ) ); $adir = str_replace( '\\', '/', strtolower( $adir ) );
if ( strlen( $adir ) > 1 ) { if ( strlen( $adir ) > 1 ) {
$adir = ltrim( $adir, '/' ); $adir = ltrim( $adir, '/' );
} }
@ -455,7 +448,7 @@ class MainWP_Clone {
<div class="clonesite_select_site_item"> <div class="clonesite_select_site_item">
<div class="mainwp-child_name_label"> <div class="mainwp-child_name_label">
<a href="<?php echo esc_url( add_query_arg( array( 'dir' => rawurlencode( $parent ) ), $url ) ); ?>" <a href="<?php echo esc_url( add_query_arg( array( 'dir' => rawurlencode( $parent ) ), $url ) ); ?>"
title="<?php echo esc_attr( dirname( $current_dir ) ); ?>"><?php esc_html_e( 'Parent Folder', 'mainwp-child' ); ?></a> title="<?php echo esc_attr( dirname( $current_dir ) ) ?>"><?php esc_html_e( 'Parent Folder', 'mainwp-child' ) ?></a>
</div> </div>
</div> </div>
@ -466,7 +459,7 @@ class MainWP_Clone {
?> ?>
<div class="clonesite_select_site_item"> <div class="clonesite_select_site_item">
<div class="mainwp-child_name_label"> <div class="mainwp-child_name_label">
<a href="<?php echo esc_attr( $folder_url ); ?>"><?php echo esc_html( rtrim( $filename, '/' ) . DIRECTORY_SEPARATOR ); ?></a> <a href="<?php echo esc_attr( $folder_url ) ?>"><?php echo esc_html( rtrim( $filename, '/' ) . DIRECTORY_SEPARATOR ); ?></a>
</div> </div>
</div> </div>
<?php <?php
@ -476,7 +469,7 @@ class MainWP_Clone {
?> ?>
<div class="clonesite_select_site_item"> <div class="clonesite_select_site_item">
<div class="mainwp-child_name_label"> <div class="mainwp-child_name_label">
<span><?php echo esc_html( $file ); ?></span> <span><?php echo esc_html( $file ) ?></span>
</div> </div>
</div> </div>
<?php <?php
@ -486,7 +479,7 @@ class MainWP_Clone {
?> ?>
<div class="mainwp_rejected_files"> <div class="mainwp_rejected_files">
<div class="mainwp-child_name_label"> <div class="mainwp-child_name_label">
<span><?php echo esc_html( $file ); ?></span> <span><?php echo esc_html( $file ) ?></span>
</div> </div>
</div> </div>
<?php <?php
@ -517,10 +510,11 @@ class MainWP_Clone {
<script language="javascript"> <script language="javascript">
var child_security_nonces = []; var child_security_nonces = [];
<?php <?php
$security_nonces = self::get()->getSecurityNonces(); $security_nonces = MainWP_Clone::get()->getSecurityNonces();
foreach ($security_nonces as $k => $v) { foreach ($security_nonces as $k => $v)
echo 'child_security_nonces[' . "'" . $k . "'" . '] = ' . "'" . $v . "';\n"; {
} echo 'child_security_nonces['."'" .$k . "'". '] = ' . "'" . $v . "';\n";
}
?> ?>
mainwpchild_secure_data = function(data, includeDts) mainwpchild_secure_data = function(data, includeDts)
@ -591,8 +585,8 @@ class MainWP_Clone {
var translations = []; var translations = [];
translations['large_site'] = "<?php esc_html_e( 'This is a large site (%dMB), the restore process will more than likely fail.', 'mainwp-child' ); ?>"; translations['large_site'] = "<?php esc_html_e( 'This is a large site (%dMB), the restore process will more than likely fail.', 'mainwp-child' ); ?>";
translations['continue_anyway'] = "<?php esc_html_e( 'Continue Anyway?', 'mainwp-child' ); ?>"; translations['continue_anyway'] = "<?php esc_html_e( 'Continue Anyway?', 'mainwp-child' ); ?>";
translations['creating_backup'] = "<?php esc_html_e( 'Creating backup on %1$s expected size: %2$dMB (estimated time: %3$d seconds)', 'mainwp-child' ); ?>"; translations['creating_backup'] = "<?php esc_html_e( 'Creating backup on %s expected size: %dMB (estimated time: %d seconds)', 'mainwp-child' ); ?>";
translations['backup_created'] = "<?php esc_html_e( 'Backup created on %1$s total size to download: %2$dMB', 'mainwp-child' ); ?>"; translations['backup_created'] = "<?php esc_html_e( 'Backup created on %s total size to download: %dMB', 'mainwp-child' ); ?>";
translations['downloading_backup'] = "<?php esc_html_e( 'Downloading backup', 'mainwp-child' ); ?>"; translations['downloading_backup'] = "<?php esc_html_e( 'Downloading backup', 'mainwp-child' ); ?>";
translations['backup_downloaded'] = "<?php esc_html_e( 'Backup downloaded', 'mainwp-child' ); ?>"; translations['backup_downloaded'] = "<?php esc_html_e( 'Backup downloaded', 'mainwp-child' ); ?>";
translations['extracting_backup'] = "<?php esc_html_e( 'Extracting backup and updating your database, this might take a while. Please be patient.', 'mainwp-child' ); ?>"; translations['extracting_backup'] = "<?php esc_html_e( 'Extracting backup and updating your database, this might take a while. Please be patient.', 'mainwp-child' ); ?>";
@ -1205,16 +1199,16 @@ class MainWP_Clone {
$key = $siteToClone['extauth']; $key = $siteToClone['extauth'];
MainWP_Helper::endSession(); MainWP_Helper::endSession();
// Send request to the childsite! //Send request to the childsite!
global $wp_version; global $wp_version;
$method = ( function_exists( 'gzopen' ) ? 'tar.gz' : 'zip' ); $method = ( function_exists( 'gzopen' ) ? 'tar.gz' : 'zip' );
$result = MainWP_Helper::fetchUrl( $url, array( $result = MainWP_Helper::fetchUrl( $url, array(
'cloneFunc' => 'createCloneBackup', 'cloneFunc' => 'createCloneBackup',
'key' => $key, 'key' => $key,
'f' => $rand, 'f' => $rand,
'wpversion' => $wp_version, 'wpversion' => $wp_version,
'zipmethod' => $method, 'zipmethod' => $method,
'json_result' => true, 'json_result' => true
) ); ) );
if ( ! $result['backup'] ) { if ( ! $result['backup'] ) {
@ -1225,10 +1219,7 @@ class MainWP_Clone {
MainWP_Helper::update_option( 'mainwp_temp_clone_plugins', $result['plugins'] ); MainWP_Helper::update_option( 'mainwp_temp_clone_plugins', $result['plugins'] );
MainWP_Helper::update_option( 'mainwp_temp_clone_themes', $result['themes'] ); MainWP_Helper::update_option( 'mainwp_temp_clone_themes', $result['themes'] );
$output = array( $output = array( 'url' => $result['backup'], 'size' => round( $result['size'] / 1024, 0 ) );
'url' => $result['backup'],
'size' => round( $result['size'] / 1024, 0 ),
);
} catch ( Exception $e ) { } catch ( Exception $e ) {
$output = array( 'error' => $e->getMessage() ); $output = array( 'error' => $e->getMessage() );
} }
@ -1257,12 +1248,12 @@ class MainWP_Clone {
$key = $siteToClone['extauth']; $key = $siteToClone['extauth'];
MainWP_Helper::endSession(); MainWP_Helper::endSession();
// Send request to the childsite! //Send request to the childsite!
$result = MainWP_Helper::fetchUrl( $url, array( $result = MainWP_Helper::fetchUrl( $url, array(
'cloneFunc' => 'createCloneBackupPoll', 'cloneFunc' => 'createCloneBackupPoll',
'key' => $key, 'key' => $key,
'f' => $rand, 'f' => $rand,
'json_result' => true, 'json_result' => true
) ); ) );
if ( ! isset( $result['size'] ) ) { if ( ! isset( $result['size'] ) ) {
@ -1273,7 +1264,7 @@ class MainWP_Clone {
} catch ( Exception $e ) { } catch ( Exception $e ) {
$output = array( 'error' => $e->getMessage() ); $output = array( 'error' => $e->getMessage() );
} }
// Return size in kb //Return size in kb
die( json_encode( $output ) ); die( json_encode( $output ) );
} }
@ -1284,7 +1275,7 @@ class MainWP_Clone {
if ( ! isset( $_POST['file'] ) ) { if ( ! isset( $_POST['file'] ) ) {
throw new Exception( __( 'No download link given', 'mainwp-child' ) ); throw new Exception( __( 'No download link given', 'mainwp-child' ) );
} }
// if (!isset($_POST['siteId'])) throw new Exception(__('No site given','mainwp-child')); // if (!isset($_POST['siteId'])) throw new Exception(__('No site given','mainwp-child'));
$file = $_POST['file']; $file = $_POST['file'];
if ( isset( $_POST['siteId'] ) ) { if ( isset( $_POST['siteId'] ) ) {
@ -1304,7 +1295,7 @@ class MainWP_Clone {
$url = $file; $url = $file;
} }
MainWP_Helper::endSession(); MainWP_Helper::endSession();
// Send request to the childsite! //Send request to the childsite!
$split = explode( '=', $file ); $split = explode( '=', $file );
$file = urldecode( $split[ count( $split ) - 1 ] ); $file = urldecode( $split[ count( $split ) - 1 ] );
$filename = 'download-' . basename( $file ); $filename = 'download-' . basename( $file );
@ -1322,11 +1313,7 @@ class MainWP_Clone {
$filename = $backupdir . $filename; $filename = $backupdir . $filename;
$response = wp_remote_get( $url, array( $response = wp_remote_get( $url, array( 'timeout' => 300000, 'stream' => true, 'filename' => $filename ) );
'timeout' => 300000,
'stream' => true,
'filename' => $filename,
) );
if ( is_wp_error( $response ) ) { if ( is_wp_error( $response ) ) {
unlink( $filename ); unlink( $filename );
@ -1342,7 +1329,7 @@ class MainWP_Clone {
$output = array( 'done' => $filename ); $output = array( 'done' => $filename );
// Delete backup on child //Delete backup on child
try { try {
if ( isset( $_POST['siteId'] ) ) { if ( isset( $_POST['siteId'] ) ) {
$siteId = $_POST['siteId']; $siteId = $_POST['siteId'];
@ -1351,10 +1338,10 @@ class MainWP_Clone {
$siteToClone = $sitesToClone[ $siteId ]; $siteToClone = $sitesToClone[ $siteId ];
MainWP_Helper::fetchUrl( $siteToClone['url'], array( MainWP_Helper::fetchUrl( $siteToClone['url'], array(
'cloneFunc' => 'deleteCloneBackup', 'cloneFunc' => 'deleteCloneBackup',
'key' => $siteToClone['extauth'], 'key' => $siteToClone['extauth'],
'f' => $_POST['file'], 'f' => $_POST['file'],
'json_result' => true, 'json_result' => true
) ); ) );
} }
} }
@ -1392,7 +1379,7 @@ class MainWP_Clone {
} catch ( Exception $e ) { } catch ( Exception $e ) {
$output = array( 'error' => $e->getMessage() ); $output = array( 'error' => $e->getMessage() );
} }
// return size in kb //return size in kb
die( json_encode( $output ) ); die( json_encode( $output ) );
} }
@ -1420,7 +1407,7 @@ class MainWP_Clone {
throw new Exception( __( 'No download file found', 'mainwp-child' ) ); throw new Exception( __( 'No download file found', 'mainwp-child' ) );
} }
$file = $archiveFile; $file = $archiveFile;
} elseif ( file_exists( $file ) ) { } else if ( file_exists( $file ) ) {
$testFull = true; $testFull = true;
} else { } else {
$file = ABSPATH . $file; $file = ABSPATH . $file;
@ -1429,10 +1416,10 @@ class MainWP_Clone {
} }
$testFull = true; $testFull = true;
} }
// return size in kb //return size in kb
$cloneInstall = new MainWP_Clone_Install( $file ); $cloneInstall = new MainWP_Clone_Install( $file );
// todo: RS: refactor to get those plugins after install (after .18 release) //todo: RS: refactor to get those plugins after install (after .18 release)
$cloneInstall->readConfigurationFile(); $cloneInstall->readConfigurationFile();
$plugins = get_option( 'mainwp_temp_clone_plugins' ); $plugins = get_option( 'mainwp_temp_clone_plugins' );
@ -1454,14 +1441,14 @@ class MainWP_Clone {
$cloneInstall->install(); $cloneInstall->install();
// $cloneInstall->update_option('mainwp_child_pubkey', $pubkey); // $cloneInstall->update_option('mainwp_child_pubkey', $pubkey);
// $cloneInstall->update_option('mainwp_child_uniqueId', $uniqueId); // $cloneInstall->update_option('mainwp_child_uniqueId', $uniqueId);
// $cloneInstall->update_option('mainwp_child_server', $server); // $cloneInstall->update_option('mainwp_child_server', $server);
// $cloneInstall->update_option('mainwp_child_nonce', $nonce); // $cloneInstall->update_option('mainwp_child_nonce', $nonce);
// $cloneInstall->update_option('mainwp_child_nossl', $nossl); // $cloneInstall->update_option('mainwp_child_nossl', $nossl);
// $cloneInstall->update_option('mainwp_child_nossl_key', $nossl_key); // $cloneInstall->update_option('mainwp_child_nossl_key', $nossl_key);
// $cloneInstall->update_option('mainwp_child_clone_sites', $sitesToClone); // $cloneInstall->update_option('mainwp_child_clone_sites', $sitesToClone);
// $cloneInstall->update_option('mainwp_child_clone_permalink', true); // $cloneInstall->update_option('mainwp_child_clone_permalink', true);
// to fix update values // to fix update values
delete_option('mainwp_child_pubkey'); delete_option('mainwp_child_pubkey');
@ -1533,14 +1520,14 @@ class MainWP_Clone {
delete_option( 'mainwp_temp_clone_themes' ); delete_option( 'mainwp_temp_clone_themes' );
} }
$output = array( 'result' => 'ok' ); $output = array( 'result' => 'ok' );
// todo: remove old tables if other prefix? //todo: remove old tables if other prefix?
wp_logout(); wp_logout();
wp_set_current_user( 0 ); wp_set_current_user( 0 );
} catch ( Exception $e ) { } catch ( Exception $e ) {
$output = array( 'error' => $e->getMessage() ); $output = array( 'error' => $e->getMessage() );
} }
// return size in kb //return size in kb
die( json_encode( $output ) ); die( json_encode( $output ) );
} }
@ -1571,15 +1558,11 @@ class MainWP_Clone {
clear: both; clear: both;
} }
</style> </style>
<div class="mainwp-child_info-box-green"> <div class="mainwp-child_info-box-green"><?php if ( get_option( 'mainwp_child_restore_permalink' ) ) {
<?php
if ( get_option( 'mainwp_child_restore_permalink' ) ) {
esc_html_e( 'Restore process completed successfully! Check and re-save permalinks ', 'mainwp-child' ); esc_html_e( 'Restore process completed successfully! Check and re-save permalinks ', 'mainwp-child' );
} else { } else {
esc_html_e( 'Cloning process completed successfully! Check and re-save permalinks ', 'mainwp-child' ); esc_html_e( 'Cloning process completed successfully! Check and re-save permalinks ', 'mainwp-child' );
} } ?> <a
?>
<a
href="<?php echo esc_attr( admin_url( 'options-permalink.php' ) ); ?>"><?php esc_html_e( 'here', 'mainwp-child' ); ?></a>. href="<?php echo esc_attr( admin_url( 'options-permalink.php' ) ); ?>"><?php esc_html_e( 'here', 'mainwp-child' ); ?></a>.
</div> </div>
<?php <?php

View file

@ -1,16 +1,16 @@
<?php <?php
class MainWP_Custom_Post_Type { class MainWP_Custom_Post_Type {
public static $instance = null; public static $instance = null;
public static $information = array(); public static $information = array();
public $plugin_translate = 'mainwp-child'; public $plugin_translate = "mainwp-child";
static function Instance() { static function Instance() {
if ( self::$instance == null ) { if ( MainWP_Custom_Post_Type::$instance == null ) {
self::$instance = new MainWP_Custom_Post_Type(); MainWP_Custom_Post_Type::$instance = new MainWP_Custom_Post_Type();
} }
return self::$instance; return MainWP_Custom_Post_Type::$instance;
} }
public function action() { public function action() {
@ -20,10 +20,10 @@ class MainWP_Custom_Post_Type {
$error = error_get_last(); $error = error_get_last();
if ( isset( $error['type'] ) && E_ERROR === $error['type'] && isset( $error['message'] ) ) { if ( isset( $error['type'] ) && E_ERROR === $error['type'] && isset( $error['message'] ) ) {
$data = array( 'error' => 'MainWPChild fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] ); $data = array( 'error' => 'MainWPChild fatal error : ' . $error['message'] . ' Line: ' . $error['line'] . ' File: ' . $error['file'] );
// die( '<mainwp>' . base64_encode( serialize( ) ) . '</mainwp>' ); // die( '<mainwp>' . base64_encode( serialize( ) ) . '</mainwp>' );
} else { } else {
$data = self::$information; $data = MainWP_Custom_Post_Type::$information;
// die( '<mainwp>' . base64_encode( serialize( MainWP_Custom_Post_Type::$information ) ) . '</mainwp>' ); // die( '<mainwp>' . base64_encode( serialize( MainWP_Custom_Post_Type::$information ) ) . '</mainwp>' );
} }
if ( isset( $_REQUEST['json_result'] ) && $_REQUEST['json_result'] ) { if ( isset( $_REQUEST['json_result'] ) && $_REQUEST['json_result'] ) {
@ -35,7 +35,7 @@ class MainWP_Custom_Post_Type {
die('<mainwp>' . base64_encode( $data ) . '</mainwp>'); die('<mainwp>' . base64_encode( $data ) . '</mainwp>');
} }
register_shutdown_function( 'mainwp_custom_post_type_handle_fatal_error' ); register_shutdown_function( "mainwp_custom_post_type_handle_fatal_error" );
$information = array(); $information = array();
switch ( $_POST['action'] ) { switch ( $_POST['action'] ) {
@ -48,7 +48,7 @@ class MainWP_Custom_Post_Type {
} }
self::$information = $information; MainWP_Custom_Post_Type::$information = $information;
exit(); exit();
} }
@ -67,8 +67,8 @@ class MainWP_Custom_Post_Type {
if ( empty( $data ) || ! is_array( $data ) || ! isset( $data['post'] ) ) { if ( empty( $data ) || ! is_array( $data ) || ! isset( $data['post'] ) ) {
return array( 'error' => __( 'Cannot decode data', $this->plugin_translate ) ); return array( 'error' => __( 'Cannot decode data', $this->plugin_translate ) );
} }
$edit_id = ( isset($_POST['post_id']) && ! empty($_POST['post_id']) ) ? $_POST['post_id'] : 0; $edit_id = (isset($_POST['post_id']) && !empty($_POST['post_id'])) ? $_POST['post_id'] : 0;
$return = $this->_insert_post($data, $edit_id, $parent_id = 0); $return = $this->_insert_post($data, $edit_id, $parent_id = 0);
if (isset($return['success']) && $return['success'] == 1) { if (isset($return['success']) && $return['success'] == 1) {
if (isset($data['product_variation']) && is_array($data['product_variation'])) { if (isset($data['product_variation']) && is_array($data['product_variation'])) {
foreach ($data['product_variation'] as $product_variation) { foreach ($data['product_variation'] as $product_variation) {
@ -104,7 +104,7 @@ class MainWP_Custom_Post_Type {
} }
try { try {
$downloadfile = MainWP_Helper::uploadImage( $originalImgUrl, array(), $check_image ); $downloadfile = MainWP_Helper::uploadImage( $originalImgUrl , array(), $check_image );
$localUrl = $downloadfile['url']; $localUrl = $downloadfile['url'];
$linkToReplaceWith = dirname( $localUrl ); $linkToReplaceWith = dirname( $localUrl );
if ( '' !== $hrefLink ) { if ( '' !== $hrefLink ) {
@ -114,7 +114,7 @@ class MainWP_Custom_Post_Type {
$serverHref = 'href="' . $serverHost; $serverHref = 'href="' . $serverHost;
$replaceServerHref = 'href="' . parse_url( $localUrl, PHP_URL_SCHEME ) . '://' . parse_url( $localUrl, PHP_URL_HOST ); $replaceServerHref = 'href="' . parse_url( $localUrl, PHP_URL_SCHEME ) . '://' . parse_url( $localUrl, PHP_URL_HOST );
$post_content = str_replace( $serverHref, $replaceServerHref, $post_content ); $post_content = str_replace( $serverHref, $replaceServerHref, $post_content );
} elseif ( strpos( $hrefLink, 'http' ) !== false ) { } else if ( strpos( $hrefLink, 'http' ) !== false ) {
$lnkToReplace = dirname( $hrefLink ); $lnkToReplace = dirname( $hrefLink );
if ( 'http:' !== $lnkToReplace && 'https:' !== $lnkToReplace ) { if ( 'http:' !== $lnkToReplace && 'https:' !== $lnkToReplace ) {
$post_content = str_replace( $lnkToReplace, $linkToReplaceWith, $post_content ); $post_content = str_replace( $lnkToReplace, $linkToReplaceWith, $post_content );
@ -159,7 +159,7 @@ class MainWP_Custom_Post_Type {
'post_modified_gmt', 'post_modified_gmt',
'post_content_filtered', 'post_content_filtered',
'menu_order', 'menu_order',
'post_type', 'post_type'
); );
foreach ( $data_keys as $key ) { foreach ( $data_keys as $key ) {
@ -174,23 +174,23 @@ class MainWP_Custom_Post_Type {
return array( 'error' => __( 'Please install', $this->plugin_translate ) . ' ' . $data_insert['post_type'] . ' ' . __( 'on child and try again', $this->plugin_translate ) ); return array( 'error' => __( 'Please install', $this->plugin_translate ) . ' ' . $data_insert['post_type'] . ' ' . __( 'on child and try again', $this->plugin_translate ) );
} }
// $data_insert['post_content'] = $this->_search_images( $data_insert['post_content'], $data['extras']['upload_dir'] ); //$data_insert['post_content'] = $this->_search_images( $data_insert['post_content'], $data['extras']['upload_dir'] );
$is_woocomerce = false; $is_woocomerce = false;
if ( ( $data_insert['post_type'] == 'product' || $data_insert['post_type'] == 'product_variation' ) && function_exists( 'wc_product_has_unique_sku' ) ) { if ( ($data_insert['post_type'] == 'product' || $data_insert['post_type'] == 'product_variation' )&& function_exists( 'wc_product_has_unique_sku' ) ) {
$is_woocomerce = true; $is_woocomerce = true;
} }
$check_image_existed = false; $check_image_existed = false;
// Support post_edit // Support post_edit
if ( ! empty( $edit_id ) ) { if ( !empty( $edit_id ) ) {
$old_post_id = (int) $edit_id; $old_post_id = (int) $edit_id;
$old_post = get_post( $old_post_id, ARRAY_A ); $old_post = get_post( $old_post_id, ARRAY_A );
if ( is_null( $old_post ) ) { if ( is_null( $old_post ) ) {
return array( return array(
'delete_connection' => 1, 'delete_connection' => 1,
'error' => __( 'Cannot get old post. Probably is deleted now. Please try again for create new post', $this->plugin_translate ), 'error' => __( 'Cannot get old post. Probably is deleted now. Please try again for create new post', $this->plugin_translate )
); );
} }
@ -215,7 +215,7 @@ class MainWP_Custom_Post_Type {
$data_insert['post_content'] = $this->_search_images( $data_insert['post_content'], $data['extras']['upload_dir'], $check_image_existed ); $data_insert['post_content'] = $this->_search_images( $data_insert['post_content'], $data['extras']['upload_dir'], $check_image_existed );
if ( ! empty($parent_id)) { if (!empty($parent_id)) {
$data_insert['post_parent'] = $parent_id; // for product variation $data_insert['post_parent'] = $parent_id; // for product variation
} }
$post_id = wp_insert_post( $data_insert, true ); $post_id = wp_insert_post( $data_insert, true );
@ -286,7 +286,7 @@ class MainWP_Custom_Post_Type {
// MainWP Categories // MainWP Categories
if ( ! empty( $data['categories'] ) && is_array( $data['categories'] ) ) { if ( ! empty( $data['categories'] ) && is_array( $data['categories'] ) ) {
// Contains wp_create_categories // Contains wp_create_categories
include_once ABSPATH . 'wp-admin/includes/taxonomy.php'; include_once( ABSPATH . 'wp-admin/includes/taxonomy.php' );
$categories = $data['categories']; $categories = $data['categories'];
if ( $data['post_only_existing'] == '0' ) { if ( $data['post_only_existing'] == '0' ) {
$post_category = wp_create_categories( $categories, $post_id ); $post_category = wp_create_categories( $categories, $post_id );
@ -303,7 +303,7 @@ class MainWP_Custom_Post_Type {
} }
} }
// Insert post terms except categories //Insert post terms except categories
if ( ! empty( $data['terms'] ) && is_array( $data['terms'] ) ) { if ( ! empty( $data['terms'] ) && is_array( $data['terms'] ) ) {
foreach ( $data['terms'] as $key ) { foreach ( $data['terms'] as $key ) {
if ( ! taxonomy_exists( $key['taxonomy'] ) ) { if ( ! taxonomy_exists( $key['taxonomy'] ) ) {
@ -313,7 +313,7 @@ class MainWP_Custom_Post_Type {
// @todo missing alias_of which means term_group // @todo missing alias_of which means term_group
$term = wp_insert_term( $key['name'], $key['taxonomy'], array( $term = wp_insert_term( $key['name'], $key['taxonomy'], array(
'description' => $key['description'], 'description' => $key['description'],
'slug' => $key['slug'], 'slug' => $key['slug']
) ); ) );
$term_taxonomy_id = 0; $term_taxonomy_id = 0;
@ -337,9 +337,6 @@ class MainWP_Custom_Post_Type {
} }
} }
return array( return array( 'success' => 1, 'post_id' => $post_id );
'success' => 1,
'post_id' => $post_id,
);
} }
} }

View file

@ -4,7 +4,7 @@ class MainWP_Debug {
/** /**
* @param $mainwpChild MainWP_Child * @param $mainwpChild MainWP_Child
*/ */
public static function process( &$mainwpChild) { public static function process(&$mainwpChild) {
if ( ! isset( $_GET['mainwpdebug'] ) || ! defined( 'MAINWP_DEBUG' ) || ( MAINWP_DEBUG !== true ) ) { if ( ! isset( $_GET['mainwpdebug'] ) || ! defined( 'MAINWP_DEBUG' ) || ( MAINWP_DEBUG !== true ) ) {
return; return;
} }
@ -13,7 +13,7 @@ class MainWP_Debug {
$start = microtime( true ); $start = microtime( true );
if ( 'fullbackup' == $_GET['mainwpdebug'] ) { if ( 'fullbackup' == $_GET['mainwpdebug'] ) {
// Full backup //Full backup
$_POST['type'] = 'full'; $_POST['type'] = 'full';
$_POST['excludebackup'] = '1'; $_POST['excludebackup'] = '1';
$_POST['excludecache'] = '1'; $_POST['excludecache'] = '1';
@ -21,12 +21,13 @@ class MainWP_Debug {
$_POST['excludenonwp'] = '1'; $_POST['excludenonwp'] = '1';
$_POST['ext'] = 'tar.gz'; $_POST['ext'] = 'tar.gz';
print_r( $mainwpChild->backup( false ) ); print_r( $mainwpChild->backup( false ) );
} elseif ( 'test' == $_GET['mainwpdebug'] ) { } else if ( 'test' == $_GET['mainwpdebug'] ) {
print_r( get_included_files() ); print_r( get_included_files() );
} else { } else {
print_r( $mainwpChild->getSiteStats( array(), false ) ); print_r( $mainwpChild->getSiteStats( array(), false ) );
} }
$stop = microtime( true ); $stop = microtime( true );
die( "\n\n\n" . 'duration: ' . ( $stop - $start ) . 's</pre>' ); die( "\n\n\n" . 'duration: ' . ( $stop - $start ) . 's</pre>' );
} }

File diff suppressed because it is too large Load diff

View file

@ -9,15 +9,15 @@ class MainWP_Keyword_Links {
protected $link_temp; protected $link_temp;
protected $link_count_temp; protected $link_count_temp;
protected $link_count_each_temp; protected $link_count_each_temp;
protected $link_exact_match = 1; protected $link_exact_match = 1;
protected $link_case_sensitive = 1; protected $link_case_sensitive = 1;
static function Instance() { static function Instance() {
if ( null === self::$instance ) { if ( null === MainWP_Keyword_Links::$instance ) {
self::$instance = new MainWP_Keyword_Links(); MainWP_Keyword_Links::$instance = new MainWP_Keyword_Links();
} }
return self::$instance; return MainWP_Keyword_Links::$instance;
} }
public function __construct() { public function __construct() {
@ -31,14 +31,14 @@ class MainWP_Keyword_Links {
if ( empty( $this->keyword_links ) ) { if ( empty( $this->keyword_links ) ) {
$this->keyword_links = array(); $this->keyword_links = array();
} }
// print_r($this->keyword_links); //print_r($this->keyword_links);
$this->siteurl = get_option( 'home' ); $this->siteurl = get_option( 'home' );
add_action( 'permalink_structure_changed', array( &$this, 'permalinkChanged' ), 10, 2 ); add_action( 'permalink_structure_changed', array( &$this, 'permalinkChanged' ), 10, 2 );
} }
public function keywordLinksJS() { public function keywordLinksJS() {
if ( ! is_admin() && get_option( 'mainwp_kwl_enable_statistic' ) && ! empty($this->keyword_links) ) { if ( ! is_admin() && get_option( 'mainwp_kwl_enable_statistic' ) && !empty($this->keyword_links) ) {
wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'keywordLinks', plugins_url( '/js/keywordlinks.js', dirname( __FILE__ ) ) ); wp_enqueue_script( 'keywordLinks', plugins_url( '/js/keywordlinks.js', dirname( __FILE__ ) ) );
add_action( 'wp_head', array( $this, 'head_loading' ), 1 ); add_action( 'wp_head', array( $this, 'head_loading' ), 1 );
@ -75,11 +75,11 @@ class MainWP_Keyword_Links {
$home_root = '/'; $home_root = '/';
} }
$rules = "<IfModule mod_rewrite.c>\n"; $rules = "<IfModule mod_rewrite.c>\n";
$rules .= "RewriteEngine On\n"; $rules .= "RewriteEngine On\n";
$rules .= "RewriteBase $home_root\n"; $rules .= "RewriteBase $home_root\n";
// add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all) //add in the rules that don't redirect to WP's index.php (and thus shouldn't be handled by WP at all)
foreach ( $pRules as $match => $query ) { foreach ( $pRules as $match => $query ) {
// Apache 1.3 does not support the reluctant (non-greedy) modifier. // Apache 1.3 does not support the reluctant (non-greedy) modifier.
$match = str_replace( '.+?', '.+', $match ); $match = str_replace( '.+?', '.+', $match );
@ -95,13 +95,13 @@ class MainWP_Keyword_Links {
function update_htaccess( $force_update = false, $force_clear = false ) { function update_htaccess( $force_update = false, $force_clear = false ) {
if ( $force_clear ) { if ( $force_clear ) {
$this->do_update_htaccess( true ); $this->do_update_htaccess( true );
} elseif ( $force_update ) { } else if ( $force_update ) {
return $this->do_update_htaccess(); return $this->do_update_htaccess();
} else { } else {
if ( '' == get_option( 'permalink_structure' ) && 'yes' !== get_option( 'mainwp_keyword_links_htaccess_set' ) ) { if ( '' == get_option( 'permalink_structure' ) && 'yes' !== get_option( 'mainwp_keyword_links_htaccess_set' ) ) {
$this->do_update_htaccess(); $this->do_update_htaccess();
} // need to update } // need to update
elseif ( '' != get_option( 'permalink_structure' ) && 'yes' === get_option( 'mainwp_keyword_links_htaccess_set' ) ) { else if ( '' != get_option( 'permalink_structure' ) && 'yes' === get_option( 'mainwp_keyword_links_htaccess_set' ) ) {
$this->do_update_htaccess(); $this->do_update_htaccess();
} // need to update } // need to update
} }
@ -110,7 +110,7 @@ class MainWP_Keyword_Links {
} }
public static function clear_htaccess() { public static function clear_htaccess() {
include_once ABSPATH . '/wp-admin/includes/misc.php'; include_once( ABSPATH . '/wp-admin/includes/misc.php' );
$home_path = ABSPATH; $home_path = ABSPATH;
$htaccess_file = $home_path . '.htaccess'; $htaccess_file = $home_path . '.htaccess';
if ( function_exists( 'save_mod_rewrite_rules' ) ) { if ( function_exists( 'save_mod_rewrite_rules' ) ) {
@ -125,15 +125,15 @@ class MainWP_Keyword_Links {
self::clear_htaccess(); self::clear_htaccess();
return true; return true;
} elseif ( '' === get_option( 'permalink_structure' ) ) { } else if ( '' === get_option( 'permalink_structure' ) ) {
include_once ABSPATH . '/wp-admin/includes/misc.php'; include_once( ABSPATH . '/wp-admin/includes/misc.php' );
$redirection_folder = $this->get_option( 'redirection_folder', '' ); $redirection_folder = $this->get_option( 'redirection_folder', '' );
if ( empty( $redirection_folder ) ) { if ( empty( $redirection_folder ) ) {
$rules = $this->get_cloak_rules(); $rules = $this->get_cloak_rules();
$rules = $this->mod_rewrite_rules( $rules ); $rules = $this->mod_rewrite_rules( $rules );
// self::clear_htaccess(); //self::clear_htaccess();
} else { } else {
// Create rewrite ruler //Create rewrite ruler
$rules = $this->mod_rewrite_rules( array( $redirection_folder . '/' => 'index.php' ) ); $rules = $this->mod_rewrite_rules( array( $redirection_folder . '/' => 'index.php' ) );
} }
$home_path = ABSPATH; $home_path = ABSPATH;
@ -297,7 +297,7 @@ class MainWP_Keyword_Links {
if ( is_array( $specific_link ) && count( $specific_link ) > 0 ) { if ( is_array( $specific_link ) && count( $specific_link ) > 0 ) {
$specific_link = current( $specific_link ); $specific_link = current( $specific_link );
$specific_link->post_id = $post->ID; $specific_link->post_id = $post->ID;
// update_post_meta($post->ID, '_mainwp_kwl_specific_link_save', array($specific_link->id => $specific_link)); //update_post_meta($post->ID, '_mainwp_kwl_specific_link_save', array($specific_link->id => $specific_link));
update_post_meta( $post->ID, '_mainwp_kwl_specific_link_id', $specific_link->id ); update_post_meta( $post->ID, '_mainwp_kwl_specific_link_id', $specific_link->id );
if ( $this->set_link( $specific_link->id, $specific_link ) ) { if ( $this->set_link( $specific_link->id, $specific_link ) ) {
update_post_meta( $post->ID, '_mainwp_kwl_specific_link', '<saved>' ); update_post_meta( $post->ID, '_mainwp_kwl_specific_link', '<saved>' );
@ -312,11 +312,11 @@ class MainWP_Keyword_Links {
} }
// print_r($this->keyword_links); // print_r($this->keyword_links);
// if ($post->ID == 751) { // if ($post->ID == 751) {
// print_r($links); // //print_r($links);
// $custom = get_post_custom($post->ID); // $custom = get_post_custom($post->ID);
// print_r($custom); // print_r($custom);
// } // }
if ( empty( $links ) ) { if ( empty( $links ) ) {
return $content; return $content;
@ -343,10 +343,10 @@ class MainWP_Keyword_Links {
$this->link_exact_match = $link->exact_match; $this->link_exact_match = $link->exact_match;
$this->link_case_sensitive = $link->case_sensitive; $this->link_case_sensitive = $link->case_sensitive;
$keywords = $this->explode_multi( $link->keyword ); $keywords = $this->explode_multi( $link->keyword );
// usort( $keywords, create_function( '$a,$b', 'return strlen($a)<strlen($b);' ) ); //usort( $keywords, create_function( '$a,$b', 'return strlen($a)<strlen($b);' ) );
usort( $keywords, array( $this, 'usort_callback_func' ) ); usort( $keywords, array($this, 'usort_callback_func') );
$replace_cs = $link->case_sensitive ? 's' : 'is'; $replace_cs = $link->case_sensitive ? 's' : 'is';
// print_r($keywords); //print_r($keywords);
foreach ( $keywords as $keyword ) { foreach ( $keywords as $keyword ) {
$keyword = trim( $keyword ); $keyword = trim( $keyword );
if ( empty( $keyword ) ) { if ( empty( $keyword ) ) {
@ -361,15 +361,15 @@ class MainWP_Keyword_Links {
$keyword = preg_replace( '/([$^\/?+.*\]\[)(}{])/is', '\\\\\1', $keyword ); $keyword = preg_replace( '/([$^\/?+.*\]\[)(}{])/is', '\\\\\1', $keyword );
if ( ( $link->case_sensitive && strpos( $content, $keyword ) !== false ) || ( ! $link->case_sensitive && stripos( $content, $keyword ) !== false ) ) { if ( ( $link->case_sensitive && strpos( $content, $keyword ) !== false ) || ( ! $link->case_sensitive && stripos( $content, $keyword ) !== false ) ) {
// Replace keyword in H tag //Replace keyword in H tag
if ( $this->get_option( 'replace_keyword_in_h_tag' ) ) { if ( $this->get_option( 'replace_keyword_in_h_tag' ) ) {
// $content = preg_replace_callback('/(<a[^>]*>.*?'.$keyword.'.*?<\/a>|<[^>]*'.$keyword.'[^>]*>|\{[^}]*'.$keyword.'[^}]*\}|\w*('.$keyword.')\w*)/is', array(&$this, 'keyword_mark'), $content); //$content = preg_replace_callback('/(<a[^>]*>.*?'.$keyword.'.*?<\/a>|<[^>]*'.$keyword.'[^>]*>|\{[^}]*'.$keyword.'[^}]*\}|\w*('.$keyword.')\w*)/is', array(&$this, 'keyword_mark'), $content);
$content = preg_replace_callback( '/(<a[^>]*>[^<]*?' . $keyword . '[^<]*?<\/a>|<[^>]*' . $keyword . '[^>]*>|\{[^\}]*' . $keyword . '[^\}]*\}|\w*(' . $keyword . ')\w*)/' . $replace_cs, array( $content = preg_replace_callback( '/(<a[^>]*>[^<]*?' . $keyword . '[^<]*?<\/a>|<[^>]*' . $keyword . '[^>]*>|\{[^\}]*' . $keyword . '[^\}]*\}|\w*(' . $keyword . ')\w*)/' . $replace_cs, array(
&$this, &$this,
'keyword_mark', 'keyword_mark',
), $content ); ), $content );
} else { } else {
// $content = preg_replace_callback('/(<h[123456][^>]*>.*?'.$keyword.'.*?<\/h[123456]>|<a[^>]*>.*?'.$keyword.'.*?<\/a>|<[^>]*'.$keyword.'[^>]*>|\{[^}]*'.$keyword.'[^}]*\}|\w*('.$keyword.')\w*)/is', array(&$this, 'keyword_mark'), $content); //$content = preg_replace_callback('/(<h[123456][^>]*>.*?'.$keyword.'.*?<\/h[123456]>|<a[^>]*>.*?'.$keyword.'.*?<\/a>|<[^>]*'.$keyword.'[^>]*>|\{[^}]*'.$keyword.'[^}]*\}|\w*('.$keyword.')\w*)/is', array(&$this, 'keyword_mark'), $content);
$content = preg_replace_callback( '/(<h[123456][^>]*>[^<]*?' . $keyword . '[^<]*?<\/h[123456]>|<a[^>]*>[^<]*?' . $keyword . '[^<]*?<\/a>|<[^>]*' . $keyword . '[^>]*>|\{[^\}]*' . $keyword . '[^\}]*\}|\w*(' . $keyword . ')\w*)/' . $replace_cs, array( $content = preg_replace_callback( '/(<h[123456][^>]*>[^<]*?' . $keyword . '[^<]*?<\/h[123456]>|<a[^>]*>[^<]*?' . $keyword . '[^<]*?<\/a>|<[^>]*' . $keyword . '[^>]*>|\{[^\}]*' . $keyword . '[^\}]*\}|\w*(' . $keyword . ')\w*)/' . $replace_cs, array(
&$this, &$this,
'keyword_mark', 'keyword_mark',
@ -378,7 +378,7 @@ class MainWP_Keyword_Links {
} }
} }
} }
// $content = preg_replace_callback('/\{MAINWP_LINK +HREF="(.*?)" +TARGET="(.*?)" +REL="(.*?)" +LINK-ID="(.*?)" +CLASS="(.*?)" +TEXT="(.*?)" *\}/is', array(&$this, 'keyword_replace'), $content); //$content = preg_replace_callback('/\{MAINWP_LINK +HREF="(.*?)" +TARGET="(.*?)" +REL="(.*?)" +LINK-ID="(.*?)" +CLASS="(.*?)" +TEXT="(.*?)" *\}/is', array(&$this, 'keyword_replace'), $content);
$content = preg_replace_callback( '/\{MAINWP_LINK +HREF="(.*?)" +TARGET="(.*?)" +REL="(.*?)" +LINK-ID="(.*?)" +CLASS="(.*?)" +TEXT="(.*?)" +FULL_TEXT="(.*?)" *\}/is', array( $content = preg_replace_callback( '/\{MAINWP_LINK +HREF="(.*?)" +TARGET="(.*?)" +REL="(.*?)" +LINK-ID="(.*?)" +CLASS="(.*?)" +TEXT="(.*?)" +FULL_TEXT="(.*?)" *\}/is', array(
&$this, &$this,
'keyword_replace', 'keyword_replace',
@ -387,8 +387,8 @@ class MainWP_Keyword_Links {
return $content; return $content;
} }
private function usort_callback_func( $a, $b) { private function usort_callback_func($a, $b) {
return strlen($a) < strlen($b); return strlen($a)<strlen($b);
} }
public function keyword_mark( $matches ) { public function keyword_mark( $matches ) {
@ -415,19 +415,19 @@ class MainWP_Keyword_Links {
$this->link_count_each_temp --; $this->link_count_each_temp --;
} }
// if (isset($this->link_temp->type) && $this->link_temp->type == 'post_type') { // if (isset($this->link_temp->type) && $this->link_temp->type == 'post_type') {
// $post = get_post($this->link_temp->id); //// $post = get_post($this->link_temp->id);
// if ($post) { //// if ($post) {
// $disable_linking = $this->get_option('disable_linking_automatically', array()); //// $disable_linking = $this->get_option('disable_linking_automatically', array());
// if (in_array($post->post_name, $disable_linking[$post->post_type])) //// if (in_array($post->post_name, $disable_linking[$post->post_type]))
// return $matches[1]; // do not link to this post //// return $matches[1]; // do not link to this post
// } //// }
// $link_target = get_post_meta($this->link_temp->id, '_mainwp_kl_link_newtab', true); // $link_target = get_post_meta($this->link_temp->id, '_mainwp_kl_link_newtab', true);
// $this->link_temp->link_target = ( $link_target != -1 && $link_target == 1 ? '_blank' : '' ); // $this->link_temp->link_target = ( $link_target != -1 && $link_target == 1 ? '_blank' : '' );
// $link_rel = get_post_meta($this->link_temp->id, '_mainwp_kl_link_nofollow', true); // $link_rel = get_post_meta($this->link_temp->id, '_mainwp_kl_link_nofollow', true);
// $this->link_temp->link_rel = ( $link_rel != -1 && $link_rel == 1 ? 'nofollow' : '' ); // $this->link_temp->link_rel = ( $link_rel != -1 && $link_rel == 1 ? 'nofollow' : '' );
// $this->link_temp->link_class = get_post_meta($this->link_temp->id, '_mainwp_kl_link_class', true); // $this->link_temp->link_class = get_post_meta($this->link_temp->id, '_mainwp_kl_link_class', true);
// } // }
if ( '-1' !== $this->link_temp->link_target ) { if ( '-1' !== $this->link_temp->link_target ) {
$target = $this->link_temp->link_target; $target = $this->link_temp->link_target;
} else { } else {
@ -453,15 +453,15 @@ class MainWP_Keyword_Links {
$regular_link = false; $regular_link = false;
if ( empty( $this->link_temp->cloak_path ) ) { if ( empty( $this->link_temp->cloak_path ) ) {
$regular_link = true; $regular_link = true;
$class .= ' kwl-regular-link'; $class .= ' kwl-regular-link';
} }
// return '{MAINWP_LINK HREF="' . ( $this->link_temp->cloak_path ? $this->siteurl . $redirection_folder . '/' . $this->link_temp->cloak_path : $this->link_temp->destination_url) . '" TARGET="' . $target . '" REL="' . $rel . '" LINK-ID="' . (isset($this->link_temp->id) ? $this->link_temp->id : 0) . '" CLASS="' . $class . '" TEXT="' . $matches[1] . '"}'; //return '{MAINWP_LINK HREF="' . ( $this->link_temp->cloak_path ? $this->siteurl . $redirection_folder . '/' . $this->link_temp->cloak_path : $this->link_temp->destination_url) . '" TARGET="' . $target . '" REL="' . $rel . '" LINK-ID="' . (isset($this->link_temp->id) ? $this->link_temp->id : 0) . '" CLASS="' . $class . '" TEXT="' . $matches[1] . '"}';
return '{MAINWP_LINK HREF="' . ( $this->link_temp->cloak_path ? $this->siteurl . $redirection_folder . '/' . $this->link_temp->cloak_path : $this->link_temp->destination_url ) . '" TARGET="' . $target . '" REL="' . $rel . '" LINK-ID="' . ( isset( $this->link_temp->id ) ? $this->link_temp->id : 0 ) . '" CLASS="' . $class . '" TEXT="' . $matches[2] . '" FULL_TEXT="' . $matches[1] . '"}'; return '{MAINWP_LINK HREF="' . ( $this->link_temp->cloak_path ? $this->siteurl . $redirection_folder . '/' . $this->link_temp->cloak_path : $this->link_temp->destination_url ) . '" TARGET="' . $target . '" REL="' . $rel . '" LINK-ID="' . ( isset( $this->link_temp->id ) ? $this->link_temp->id : 0 ) . '" CLASS="' . $class . '" TEXT="' . $matches[2] . '" FULL_TEXT="' . $matches[1] . '"}';
} }
public function keyword_replace( $matches ) { public function keyword_replace( $matches ) {
$a = '<a href="' . $matches[1] . '"'; $a = '<a href="' . $matches[1] . '"';
$a .= ( $matches[2] ) ? ' target="' . $matches[2] . '"' : ''; $a .= ( $matches[2] ) ? ' target="' . $matches[2] . '"' : '';
$a .= ( $matches[3] ) ? ' rel="' . $matches[3] . '"' : ''; $a .= ( $matches[3] ) ? ' rel="' . $matches[3] . '"' : '';
$a .= ( $matches[4] ) ? ' link-id="' . $matches[4] . '"' : ''; $a .= ( $matches[4] ) ? ' link-id="' . $matches[4] . '"' : '';
@ -483,16 +483,16 @@ class MainWP_Keyword_Links {
$post = get_post( $post_id ); $post = get_post( $post_id );
} }
$links = array(); $links = array();
// $disable_add_links = $this->get_option('disable_add_links_automatically'); // $disable_add_links = $this->get_option('disable_add_links_automatically');
// if disabled add links automatically in this post, avoid // // if disabled add links automatically in this post, avoid
// if (in_array($post->post_name, (array) $disable_add_links[$post->post_type])) { // if (in_array($post->post_name, (array) $disable_add_links[$post->post_type])) {
// return $links; // return $links;
// } // }
// Check if this post was disabled with this function, come back // Check if this post was disabled with this function, come back
// $disable = get_post_meta($post->ID, '_mainwp_kl_disable', true); // $disable = get_post_meta($post->ID, '_mainwp_kl_disable', true);
// if ($disable == 1) // if ($disable == 1)
// return $links; // return $links;
// count replace max and max keyword allowed. // count replace max and max keyword allowed.
$replace_max = intval( $this->get_option( 'replace_max' ) ); $replace_max = intval( $this->get_option( 'replace_max' ) );
$replace_max_keyword = intval( $this->get_option( 'replace_max_keyword' ) ); $replace_max_keyword = intval( $this->get_option( 'replace_max_keyword' ) );
@ -514,7 +514,7 @@ class MainWP_Keyword_Links {
} else { } else {
$links_post_type = (array) $this->get_post_keywords( $post_type ); $links_post_type = (array) $this->get_post_keywords( $post_type );
} }
// print_r($links_post_type); //print_r($links_post_type);
if ( count( $links_post_type ) > 0 ) { if ( count( $links_post_type ) > 0 ) {
$links = array_merge( $links, $links_post_type ); $links = array_merge( $links, $links_post_type );
} }
@ -534,7 +534,7 @@ class MainWP_Keyword_Links {
} else { } else {
$links[] = $link; $links[] = $link;
} }
} elseif ( $spec_link_id && $spec_link_id === $link->id ) { // type 2 is specific link } else if ( $spec_link_id && $spec_link_id === $link->id ) { // type 2 is specific link
if ( $link->check_post_date ) { if ( $link->check_post_date ) {
if ( $post_timestamp < $link->check_post_date ) { if ( $post_timestamp < $link->check_post_date ) {
$links[] = $link; $links[] = $link;
@ -557,7 +557,7 @@ class MainWP_Keyword_Links {
$join = "JOIN $wpdb->term_relationships tr ON tr.object_id = p.ID"; $join = "JOIN $wpdb->term_relationships tr ON tr.object_id = p.ID";
$where = " AND (tr.term_taxonomy_id = '" . implode( "' OR tr.term_taxonomy_id = '", $cats ) . "')"; $where = " AND (tr.term_taxonomy_id = '" . implode( "' OR tr.term_taxonomy_id = '", $cats ) . "')";
} }
// $results = $wpdb->get_results(sprintf("SELECT * FROM $wpdb->posts as p LEFT JOIN $wpdb->postmeta as pm ON p.ID=pm.post_id $join WHERE p.post_status='publish' AND p.post_type='%s' AND pm.meta_key='_mainwp_kl_post_keyword' $where", $post_type)); //$results = $wpdb->get_results(sprintf("SELECT * FROM $wpdb->posts as p LEFT JOIN $wpdb->postmeta as pm ON p.ID=pm.post_id $join WHERE p.post_status='publish' AND p.post_type='%s' AND pm.meta_key='_mainwp_kl_post_keyword' $where", $post_type));
$results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->posts as p $join WHERE p.post_status='publish' AND p.post_type= %s $where", $post_type ) ); $results = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->posts as p $join WHERE p.post_status='publish' AND p.post_type= %s $where", $post_type ) );
$links = array(); $links = array();
if ( ! is_array( $results ) ) { if ( ! is_array( $results ) ) {
@ -571,14 +571,14 @@ class MainWP_Keyword_Links {
if ( in_array( $result->post_name, (array) $paths_blocked ) ) { if ( in_array( $result->post_name, (array) $paths_blocked ) ) {
continue; continue;
} }
$link = new stdClass(); $link = new stdClass;
// This is on-fly link so have not ID // This is on-fly link so have not ID
// $link->id = $result->ID; //$link->id = $result->ID;
$link->name = $result->post_title; $link->name = $result->post_title;
// if ($result->post_type == 'page') //if ($result->post_type == 'page')
// $link->destination_url = get_permalink($result->ID); // $link->destination_url = get_permalink($result->ID);
// else //else
// $link->destination_url = $result->guid; // $link->destination_url = $result->guid;
$link->destination_url = get_permalink( $result->ID ); $link->destination_url = get_permalink( $result->ID );
$link->cloak_path = ''; $link->cloak_path = '';
$link->keyword = ( 1 === (int) $this->get_option( 'post_match_title' ) ? $result->post_title : '' ); $link->keyword = ( 1 === (int) $this->get_option( 'post_match_title' ) ? $result->post_title : '' );
@ -616,7 +616,7 @@ class MainWP_Keyword_Links {
if ( ! preg_match( '|^[a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]+$|i', $request ) ) { if ( ! preg_match( '|^[a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]+$|i', $request ) ) {
return; return;
} }
// Check to see if WordPress is installed in sub folder // Check to see if Wordpress is installed in sub folder
$siteurl = parse_url( $this->siteurl ); $siteurl = parse_url( $this->siteurl );
$sitepath = ( isset( $siteurl['path'] ) ) ? $siteurl['path'] : ''; $sitepath = ( isset( $siteurl['path'] ) ) ? $siteurl['path'] : '';
$filter_request = preg_replace( '|^' . $sitepath . '/?|i', '', $request ); $filter_request = preg_replace( '|^' . $sitepath . '/?|i', '', $request );
@ -625,7 +625,7 @@ class MainWP_Keyword_Links {
$redirection_folder = $this->get_option( 'redirection_folder', '' ); $redirection_folder = $this->get_option( 'redirection_folder', '' );
if ( ! empty( $redirection_folder ) ) { if ( ! empty( $redirection_folder ) ) {
// if the request doesn't' containt the redirection folder we will return immediately //if the request doesn't' containt the redirection folder we will return immediately
if ( strpos( $filter_request, $redirection_folder . '/' ) === false ) { if ( strpos( $filter_request, $redirection_folder . '/' ) === false ) {
return; return;
} }
@ -677,21 +677,21 @@ class MainWP_Keyword_Links {
} }
} }
// public function get_statistic() { // public function get_statistic() {
// global $wpdb; // global $wpdb;
// $link_id = $_POST['link_id']; // $link_id = $_POST['link_id'];
// if ($link_id) { // if ($link_id) {
// $stat_data = get_option('mainwp_kwl_statistic_data_' . $link_id, array()); // $stat_data = get_option('mainwp_kwl_statistic_data_' . $link_id, array());
// if ($stat_data) { // if ($stat_data) {
// $return['stat_data'] = $stat_data; // $return['stat_data'] = $stat_data;
// $wpdb->query("UPDATE {$wpdb->prefix}options SET option_name = 'mainwp_kwl_statistic_data_done_" . $link_id . "' WHERE option_name = 'mainwp_kwl_statistic_data_" . $link_id . "'"); // //$wpdb->query("UPDATE {$wpdb->prefix}options SET option_name = 'mainwp_kwl_statistic_data_done_" . $link_id . "' WHERE option_name = 'mainwp_kwl_statistic_data_" . $link_id . "'");
// update_option('mainwp_kwl_statistic_data_' . $link_id, ''); // update_option('mainwp_kwl_statistic_data_' . $link_id, '');
// } else // } else
// $return['stat_data'] = 'EMPTY'; // $return['stat_data'] = 'EMPTY';
// $return['status'] = 'SUCCESS'; // $return['status'] = 'SUCCESS';
// } // }
// return $return; // return $return;
// } // }
public function action() { public function action() {
$result = array(); $result = array();
@ -741,7 +741,7 @@ class MainWP_Keyword_Links {
if ( $remove_settings ) { if ( $remove_settings ) {
$this->clear_settings(); $this->clear_settings();
$return['status'] = 'SUCCESS'; $return['status'] = 'SUCCESS';
} elseif ( is_array( $remove_kws ) && is_array( $this->keyword_links ) ) { } else if ( is_array( $remove_kws ) && is_array( $this->keyword_links ) ) {
$new_keyword_links = array(); $new_keyword_links = array();
foreach ( $this->keyword_links as $link_id => $link ) { foreach ( $this->keyword_links as $link_id => $link ) {
$lnk_kws = $link->keyword; $lnk_kws = $link->keyword;
@ -853,7 +853,7 @@ class MainWP_Keyword_Links {
if ( 3 === (int) $clear_link->type ) { if ( 3 === (int) $clear_link->type ) {
$clear_link->type = 2; $clear_link->type = 2;
$cleared = $this->set_link( $clear_link->id, $clear_link ); $cleared = $this->set_link( $clear_link->id, $clear_link );
} elseif ( 1 === (int) $clear_link->type ) { } else if ( 1 === (int) $clear_link->type ) {
$cleared = $this->set_link( $clear_link->id, '' ); // delete link $cleared = $this->set_link( $clear_link->id, '' ); // delete link
} }
$this->update_htaccess_for_change_cloak_links( $clear_link ); $this->update_htaccess_for_change_cloak_links( $clear_link );
@ -885,7 +885,7 @@ class MainWP_Keyword_Links {
} }
$old = $this->get_link( $link_id ); $old = $this->get_link( $link_id );
$link = new stdClass(); $link = new stdClass;
$link->id = intval( $link_id ); $link->id = intval( $link_id );
$link->name = sanitize_text_field( $_POST['name'] ); $link->name = sanitize_text_field( $_POST['name'] );
$link->destination_url = esc_url( $_POST['destination_url'] ); $link->destination_url = esc_url( $_POST['destination_url'] );
@ -901,7 +901,7 @@ class MainWP_Keyword_Links {
if ( 2 === (int) $link->type || 3 === (int) $link->type ) { if ( 2 === (int) $link->type || 3 === (int) $link->type ) {
if ( intval( $_POST['post_id'] ) ) { if ( intval( $_POST['post_id'] ) ) {
$link->post_id = intval( $_POST['post_id'] ); $link->post_id = intval( $_POST['post_id'] );
} elseif ( $old && $old->post_id ) { } else if ( $old && $old->post_id ) {
$link->post_id = $old->post_id; $link->post_id = $old->post_id;
} }
if ( $link->post_id ) { if ( $link->post_id ) {

View file

@ -2,16 +2,16 @@
class MainWP_Security { class MainWP_Security {
public static function fixAll() { public static function fixAll() {
self::remove_wp_version(); MainWP_Security::remove_wp_version();
self::remove_rsd(); MainWP_Security::remove_rsd();
self::remove_wlw(); MainWP_Security::remove_wlw();
// MainWP_Security::remove_core_update(); // MainWP_Security::remove_core_update();
// MainWP_Security::remove_plugin_update(); // MainWP_Security::remove_plugin_update();
// MainWP_Security::remove_theme_update(); // MainWP_Security::remove_theme_update();
self::remove_php_reporting(); MainWP_Security::remove_php_reporting();
self::remove_registered_versions(); MainWP_Security::remove_registered_versions();
self::remove_generator_version(); MainWP_Security::remove_generator_version();
self::remove_readme(); MainWP_Security::remove_readme();
add_filter( 'style_loader_src', array( 'MainWP_Security', 'remove_script_versions' ), PHP_INT_MAX ); add_filter( 'style_loader_src', array( 'MainWP_Security', 'remove_script_versions' ), PHP_INT_MAX );
add_filter( 'style_loader_src', array( 'MainWP_Security', 'remove_theme_versions' ), PHP_INT_MAX ); add_filter( 'style_loader_src', array( 'MainWP_Security', 'remove_theme_versions' ), PHP_INT_MAX );
@ -19,13 +19,13 @@ class MainWP_Security {
add_filter( 'script_loader_src', array( 'MainWP_Security', 'remove_theme_versions' ), PHP_INT_MAX ); add_filter( 'script_loader_src', array( 'MainWP_Security', 'remove_theme_versions' ), PHP_INT_MAX );
} }
// Prevent listing wp-content, wp-content/plugins, wp-content/themes, wp-content/uploads //Prevent listing wp-content, wp-content/plugins, wp-content/themes, wp-content/uploads
private static $listingDirectories = null; private static $listingDirectories = null;
private static function init_listingDirectories() { private static function init_listingDirectories() {
if ( null === self::$listingDirectories ) { if ( null === MainWP_Security::$listingDirectories ) {
$wp_upload_dir = wp_upload_dir(); $wp_upload_dir = wp_upload_dir();
self::$listingDirectories = array( MainWP_Security::$listingDirectories = array(
WP_CONTENT_DIR, WP_CONTENT_DIR,
WP_PLUGIN_DIR, WP_PLUGIN_DIR,
get_theme_root(), get_theme_root(),
@ -35,8 +35,8 @@ class MainWP_Security {
} }
public static function prevent_listing_ok() { public static function prevent_listing_ok() {
self::init_listingDirectories(); MainWP_Security::init_listingDirectories();
foreach ( self::$listingDirectories as $directory ) { foreach ( MainWP_Security::$listingDirectories as $directory ) {
$file = $directory . DIRECTORY_SEPARATOR . 'index.php'; $file = $directory . DIRECTORY_SEPARATOR . 'index.php';
if ( ! file_exists( $file ) ) { if ( ! file_exists( $file ) ) {
return false; return false;
@ -47,8 +47,8 @@ class MainWP_Security {
} }
public static function prevent_listing() { public static function prevent_listing() {
self::init_listingDirectories(); MainWP_Security::init_listingDirectories();
foreach ( self::$listingDirectories as $directory ) { foreach ( MainWP_Security::$listingDirectories as $directory ) {
$file = $directory . DIRECTORY_SEPARATOR . 'index.php'; $file = $directory . DIRECTORY_SEPARATOR . 'index.php';
if ( ! file_exists( $file ) ) { if ( ! file_exists( $file ) ) {
$h = fopen( $file, 'w' ); $h = fopen( $file, 'w' );
@ -66,7 +66,7 @@ class MainWP_Security {
return ! empty( $security ) && isset( $security[ $option ] ) && ( true === $security[ $option ] ); return ! empty( $security ) && isset( $security[ $option ] ) && ( true === $security[ $option ] );
} }
// Removed wp-version //Removed wp-version
public static function remove_wp_version_ok() { public static function remove_wp_version_ok() {
return ! ( has_action( 'wp_head', 'wp_generator' ) || has_filter( 'wp_head', 'wp_generator' ) ); return ! ( has_action( 'wp_head', 'wp_generator' ) || has_filter( 'wp_head', 'wp_generator' ) );
} }
@ -78,7 +78,7 @@ class MainWP_Security {
} }
} }
// Removed Really Simple Discovery meta tag //Removed Really Simple Discovery meta tag
public static function remove_rsd_ok() { public static function remove_rsd_ok() {
return ( ! has_action( 'wp_head', 'rsd_link' ) ); return ( ! has_action( 'wp_head', 'rsd_link' ) );
} }
@ -89,7 +89,7 @@ class MainWP_Security {
} }
} }
// Removed Windows Live Writer meta tag //Removed Windows Live Writer meta tag
public static function remove_wlw_ok() { public static function remove_wlw_ok() {
return ( ! has_action( 'wp_head', 'wlwmanifest_link' ) ); return ( ! has_action( 'wp_head', 'wlwmanifest_link' ) );
} }
@ -100,132 +100,132 @@ class MainWP_Security {
} }
} }
// Removed core update information for non-admins //Removed core update information for non-admins
// public static function remove_core_update_ok() // public static function remove_core_update_ok()
// { // {
// return self::get_security_option('core_updates'); // return self::get_security_option('core_updates');
// } // }
// public static function remove_core_update($force = false) // public static function remove_core_update($force = false)
// { // {
// if ($force || self::get_security_option('core_updates')) // if ($force || self::get_security_option('core_updates'))
// { // {
// if (!current_user_can('update_plugins')) // if (!current_user_can('update_plugins'))
// { // {
// add_action('admin_init', create_function('$a', "remove_action( 'admin_notices', 'maintenance_nag' );")); // add_action('admin_init', create_function('$a', "remove_action( 'admin_notices', 'maintenance_nag' );"));
// add_action('admin_init', create_function('$a', "remove_action( 'admin_notices', 'update_nag', 3 );")); // add_action('admin_init', create_function('$a', "remove_action( 'admin_notices', 'update_nag', 3 );"));
// add_action('admin_init', create_function('$a', "remove_action( 'admin_init', '_maybe_update_core' );")); // add_action('admin_init', create_function('$a', "remove_action( 'admin_init', '_maybe_update_core' );"));
// add_action('init', create_function('$a', "remove_action( 'init', 'wp_version_check' );")); // add_action('init', create_function('$a', "remove_action( 'init', 'wp_version_check' );"));
// add_filter('pre_option_update_core', create_function('$a', "return null;")); // add_filter('pre_option_update_core', create_function('$a', "return null;"));
// remove_action('wp_version_check', 'wp_version_check'); // remove_action('wp_version_check', 'wp_version_check');
// remove_action('admin_init', '_maybe_update_core'); // remove_action('admin_init', '_maybe_update_core');
// add_filter('pre_transient_update_core', create_function('$a', "return null;")); // add_filter('pre_transient_update_core', create_function('$a', "return null;"));
// add_filter('pre_site_transient_update_core', create_function('$a', "return null;")); // add_filter('pre_site_transient_update_core', create_function('$a', "return null;"));
// } // }
// } // }
// } // }
// Removed plugin-update information for non-admins //Removed plugin-update information for non-admins
// public static function remove_plugin_update_ok() // public static function remove_plugin_update_ok()
// { // {
// return self:get_security_option('plugin_updates'); // return self:get_security_option('plugin_updates');
// } // }
// public static function remove_plugin_update($force = false) // public static function remove_plugin_update($force = false)
// { // {
// if ($force || self::get_security_option('plugin_updates')) // if ($force || self::get_security_option('plugin_updates'))
// { // {
// if (!current_user_can('update_plugins')) // if (!current_user_can('update_plugins'))
// { // {
// add_action('admin_init', create_function('$a', "remove_action( 'admin_init', 'wp_plugin_update_rows' );"), 2); // add_action('admin_init', create_function('$a', "remove_action( 'admin_init', 'wp_plugin_update_rows' );"), 2);
// add_action('admin_init', create_function('$a', "remove_action( 'admin_init', '_maybe_update_plugins' );"), 2); // add_action('admin_init', create_function('$a', "remove_action( 'admin_init', '_maybe_update_plugins' );"), 2);
// add_action('admin_menu', create_function('$a', "remove_action( 'load-plugins.php', 'wp_update_plugins' );")); // add_action('admin_menu', create_function('$a', "remove_action( 'load-plugins.php', 'wp_update_plugins' );"));
// add_action('admin_init', create_function('$a', "remove_action( 'admin_init', 'wp_update_plugins' );"), 2); // add_action('admin_init', create_function('$a', "remove_action( 'admin_init', 'wp_update_plugins' );"), 2);
// add_action('init', create_function('$a', "remove_action( 'init', 'wp_update_plugins' );"), 2); // add_action('init', create_function('$a', "remove_action( 'init', 'wp_update_plugins' );"), 2);
// add_filter('pre_option_update_plugins', create_function('$a', "return null;")); // add_filter('pre_option_update_plugins', create_function('$a', "return null;"));
// remove_action('load-plugins.php', 'wp_update_plugins'); // remove_action('load-plugins.php', 'wp_update_plugins');
// remove_action('load-update.php', 'wp_update_plugins'); // remove_action('load-update.php', 'wp_update_plugins');
// remove_action('admin_init', '_maybe_update_plugins'); // remove_action('admin_init', '_maybe_update_plugins');
// remove_action('wp_update_plugins', 'wp_update_plugins'); // remove_action('wp_update_plugins', 'wp_update_plugins');
// remove_action('load-update-core.php', 'wp_update_plugins'); // remove_action('load-update-core.php', 'wp_update_plugins');
// add_filter('pre_transient_update_plugins', create_function('$a', "return null;")); // add_filter('pre_transient_update_plugins', create_function('$a', "return null;"));
// } // }
// } // }
// } // }
// Removed theme-update information for non-admins //Removed theme-update information for non-admins
// public static function remove_theme_update_ok() // public static function remove_theme_update_ok()
// { // {
// return self::get_security_option('theme_updates'); // return self::get_security_option('theme_updates');
// } // }
// public static function remove_theme_update($force = false) // public static function remove_theme_update($force = false)
// { // {
// if ($force || self::get_security_option('theme_updates')) // if ($force || self::get_security_option('theme_updates'))
// { // {
// if (!current_user_can('edit_themes')) // if (!current_user_can('edit_themes'))
// { // {
// remove_action('load-themes.php', 'wp_update_themes'); // remove_action('load-themes.php', 'wp_update_themes');
// remove_action('load-update.php', 'wp_update_themes'); // remove_action('load-update.php', 'wp_update_themes');
// remove_action('admin_init', '_maybe_update_themes'); // remove_action('admin_init', '_maybe_update_themes');
// remove_action('wp_update_themes', 'wp_update_themes'); // remove_action('wp_update_themes', 'wp_update_themes');
// remove_action('load-update-core.php', 'wp_update_themes'); // remove_action('load-update-core.php', 'wp_update_themes');
// add_filter('pre_transient_update_themes', create_function('$a', "return null;")); // add_filter('pre_transient_update_themes', create_function('$a', "return null;"));
// } // }
// } // }
// } // }
// File permissions not secure //File permissions not secure
private static $permission_checks = null; private static $permission_checks = null;
private static function init_permission_checks() { private static function init_permission_checks() {
if ( null === self::$permission_checks ) { if ( null === MainWP_Security::$permission_checks ) {
self::$permission_checks = array( MainWP_Security::$permission_checks = array(
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . '../' => '0755', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . '../' => '0755',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . '../wp-includes' => '0755', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . '../wp-includes' => '0755',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . '../.htaccess' => '0644', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . '../.htaccess' => '0644',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'index.php' => '0644', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'index.php' => '0644',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'js/' => '0755', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'js/' => '0755',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'themes' => '0755', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'themes' => '0755',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'plugins' => '0755', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'plugins' => '0755',
WP_CONTENT_DIR . DIRECTORY_SEPARATOR . '../wp-admin' => '0755', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . '../wp-admin' => '0755',
WP_CONTENT_DIR => '0755', WP_CONTENT_DIR => '0755',
); );
} }
} }
// public static function fix_file_permissions_ok() // public static function fix_file_permissions_ok()
// { // {
// MainWP_Security::init_permission_checks(); // MainWP_Security::init_permission_checks();
// //
// $perms_issues = 0; // $perms_issues = 0;
// //
// foreach (MainWP_Security::$permission_checks as $dir => $needed_perms) // foreach (MainWP_Security::$permission_checks as $dir => $needed_perms)
// { // {
// if (!file_exists($dir)) continue; // if (!file_exists($dir)) continue;
// //
// $perms = substr(sprintf('%o', fileperms($dir)), -4); // $perms = substr(sprintf('%o', fileperms($dir)), -4);
// if ($perms != $needed_perms) // if ($perms != $needed_perms)
// { // {
// $perms_issues++; // $perms_issues++;
// } // }
// } // }
// return ($perms_issues == 0); // return ($perms_issues == 0);
// } // }
// public static function fix_file_permissions() // public static function fix_file_permissions()
// { // {
// MainWP_Security::init_permission_checks(); // MainWP_Security::init_permission_checks();
// $success = true; // $success = true;
// foreach (MainWP_Security::$permission_checks as $dir => $needed_perms) // foreach (MainWP_Security::$permission_checks as $dir => $needed_perms)
// { // {
// if (!file_exists($dir)) continue; // if (!file_exists($dir)) continue;
// $success == $success && chmod($dir, $needed_perms); // $success == $success && chmod($dir, $needed_perms);
// } // }
// return $success; // return $success;
// } // }
// Database error reporting turned on/off //Database error reporting turned on/off
public static function remove_database_reporting_ok() { public static function remove_database_reporting_ok() {
global $wpdb; global $wpdb;
@ -239,7 +239,7 @@ class MainWP_Security {
$wpdb->suppress_errors(); $wpdb->suppress_errors();
} }
// PHP error reporting turned on/off //PHP error reporting turned on/off
public static function remove_php_reporting_ok() { public static function remove_php_reporting_ok() {
return ! ( ( ( 0 != ini_get( 'display_errors' ) ) && ( 'off' != ini_get( 'display_errors' ) ) ) || ( ( 0 != ini_get( 'display_startup_errors' ) ) && ( 'off' != ini_get( 'display_startup_errors' ) ) ) ); return ! ( ( ( 0 != ini_get( 'display_errors' ) ) && ( 'off' != ini_get( 'display_errors' ) ) ) || ( ( 0 != ini_get( 'display_startup_errors' ) ) && ( 'off' != ini_get( 'display_startup_errors' ) ) ) );
} }
@ -252,7 +252,7 @@ class MainWP_Security {
} }
} }
// Removed version information for scripts/stylesheets //Removed version information for scripts/stylesheets
public static function remove_scripts_version_ok() { public static function remove_scripts_version_ok() {
return self::get_security_option( 'scripts_version' ); return self::get_security_option( 'scripts_version' );
} }
@ -275,7 +275,7 @@ class MainWP_Security {
public static function remove_registered_versions() { public static function remove_registered_versions() {
if ( self::get_security_option( 'registered_versions' ) ) { if ( self::get_security_option( 'registered_versions' ) ) {
global $wp_styles; global $wp_styles;
if ( $wp_styles instanceof WP_Styles ) { if ( $wp_styles instanceof WP_Styles ) {
foreach ( $wp_styles->registered as $handle => $style ) { foreach ( $wp_styles->registered as $handle => $style ) {
$wp_styles->registered[ $handle ]->ver = null; $wp_styles->registered[ $handle ]->ver = null;
} }
@ -320,9 +320,8 @@ class MainWP_Security {
public static function remove_readme( $force = false ) { public static function remove_readme( $force = false ) {
// to prevent remove readme.html file on WPE hosts // to prevent remove readme.html file on WPE hosts
if ( MainWP_Helper::is_wp_engine() ) { if ( MainWP_Helper::is_wp_engine() )
return true; return true;
}
if ( $force || self::get_security_option( 'readme' ) ) { if ( $force || self::get_security_option( 'readme' ) ) {
if ( @file_exists( ABSPATH . 'readme.html' ) ) { if ( @file_exists( ABSPATH . 'readme.html' ) ) {
@ -349,12 +348,10 @@ class MainWP_Security {
return self::get_security_option( 'styles_version' ); return self::get_security_option( 'styles_version' );
} }
// Admin user name is not admin //Admin user name is not admin
public static function admin_user_ok() { public static function admin_user_ok() {
$user = get_user_by( 'login', 'admin' ); $user = get_user_by( 'login', 'admin' );
if ( ! $user ) { if ( ! $user ) return true;
return true;
}
if ( 10 !== $user->wp_user_level && ( ! isset( $user->user_level ) || 10 !== $user->user_level ) && ! user_can( $user, 'level_10' ) ) { if ( 10 !== $user->wp_user_level && ( ! isset( $user->user_level ) || 10 !== $user->user_level ) && ! user_can( $user, 'level_10' ) ) {
return true; return true;
@ -365,9 +362,8 @@ class MainWP_Security {
public static function update_security_option( $key, $value ) { public static function update_security_option( $key, $value ) {
$security = get_option( 'mainwp_security' ); $security = get_option( 'mainwp_security' );
if ( ! empty($key) ) { if ( !empty($key) )
$security[ $key ] = $value; $security[$key] = $value;
}
MainWP_Helper::update_option( 'mainwp_security', $security, 'yes' ); MainWP_Helper::update_option( 'mainwp_security', $security, 'yes' );
} }
} }

View file

@ -19,11 +19,11 @@ class MainWP_Wordpress_SEO {
public static $instance = null; public static $instance = null;
static function Instance() { static function Instance() {
if ( null === self::$instance ) { if ( null === MainWP_Wordpress_SEO::$instance ) {
self::$instance = new MainWP_Wordpress_SEO(); MainWP_Wordpress_SEO::$instance = new MainWP_Wordpress_SEO();
} }
return self::$instance; return MainWP_Wordpress_SEO::$instance;
} }
public function __construct() { public function __construct() {
@ -57,9 +57,14 @@ class MainWP_Wordpress_SEO {
if ( isset($_POST['file_url']) ) { if ( isset($_POST['file_url']) ) {
$file_url = base64_decode( $_POST['file_url'] ); $file_url = base64_decode( $_POST['file_url'] );
$temporary_file = ''; $temporary_file = '';
global $mainWPChild;
try { try {
include_once ABSPATH . 'wp-admin/includes/file.php'; // Contains download_url include_once( ABSPATH . 'wp-admin/includes/file.php' ); //Contains download_url
add_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 );
$temporary_file = download_url( $file_url ); $temporary_file = download_url( $file_url );
remove_filter( 'http_request_args', array( $mainWPChild, 'http_request_reject_unsafe_urls' ), 99, 2 );
if ( is_wp_error( $temporary_file ) ) { if ( is_wp_error( $temporary_file ) ) {
throw new Exception( 'Error: ' . $temporary_file->get_error_message() ); throw new Exception( 'Error: ' . $temporary_file->get_error_message() );
@ -78,7 +83,7 @@ class MainWP_Wordpress_SEO {
unlink( $temporary_file ); unlink( $temporary_file );
} }
} elseif ( isset( $_POST['settings'] ) ) { } else if ( isset( $_POST['settings'] ) ) {
try { try {
$settings = base64_decode( $_POST['settings'] ); $settings = base64_decode( $_POST['settings'] );
// @codingStandardsIgnoreLine // @codingStandardsIgnoreLine
@ -86,24 +91,24 @@ class MainWP_Wordpress_SEO {
if ( is_array( $options ) && array() !== $options ) { if ( is_array( $options ) && array() !== $options ) {
$old_wpseo_version = null; $old_wpseo_version = null;
if ( isset( $options['wpseo']['version'] ) && '' !== $options['wpseo']['version'] ) { if ( isset( $options['wpseo']['version'] ) && '' !== $options['wpseo']['version'] ) {
$old_wpseo_version = $options['wpseo']['version']; $old_wpseo_version = $options['wpseo']['version'];
} }
foreach ( $options as $name => $optgroup ) { foreach ( $options as $name => $optgroup ) {
if ( 'wpseo_taxonomy_meta' === $name ) { if ( 'wpseo_taxonomy_meta' === $name ) {
$optgroup = json_decode( urldecode( $optgroup['wpseo_taxonomy_meta'] ), true ); $optgroup = json_decode( urldecode( $optgroup['wpseo_taxonomy_meta'] ), true );
} }
// Make sure that the imported options are cleaned/converted on import // Make sure that the imported options are cleaned/converted on import
$option_instance = WPSEO_Options::get_option_instance( $name ); $option_instance = WPSEO_Options::get_option_instance( $name );
if ( is_object( $option_instance ) && method_exists( $option_instance, 'import' ) ) { if ( is_object( $option_instance ) && method_exists( $option_instance, 'import' ) ) {
$optgroup = $option_instance->import( $optgroup, $old_wpseo_version, $options ); $optgroup = $option_instance->import( $optgroup, $old_wpseo_version, $options );
} }
} }
$information['success'] = true; $information['success'] = true;
} else { } else {
throw new Exception( __( 'Settings could not be imported:', 'wordpress-seo' ) ); throw new Exception( __( 'Settings could not be imported:', 'wordpress-seo' ) );
} }
} catch ( Exception $e ) { } catch ( Exception $e ) {
$information['error'] = $e->getMessage(); $information['error'] = $e->getMessage();
} }
@ -175,10 +180,12 @@ class MainWP_Wordpress_SEO {
$rank = new WPSEO_Rank( WPSEO_Rank::NO_INDEX ); $rank = new WPSEO_Rank( WPSEO_Rank::NO_INDEX );
$title = __( 'Post is set to noindex.', 'wordpress-seo' ); $title = __( 'Post is set to noindex.', 'wordpress-seo' );
WPSEO_Meta::set_value( 'linkdex', 0, $post_id ); WPSEO_Meta::set_value( 'linkdex', 0, $post_id );
} elseif ( '' === WPSEO_Meta::get_value( 'focuskw', $post_id ) ) { }
elseif ( '' === WPSEO_Meta::get_value( 'focuskw', $post_id ) ) {
$rank = new WPSEO_Rank( WPSEO_Rank::NO_FOCUS ); $rank = new WPSEO_Rank( WPSEO_Rank::NO_FOCUS );
$title = __( 'Focus keyword not set.', 'wordpress-seo' ); $title = __( 'Focus keyword not set.', 'wordpress-seo' );
} else { }
else {
$score = (int) WPSEO_Meta::get_value( 'linkdex', $post_id ); $score = (int) WPSEO_Meta::get_value( 'linkdex', $post_id );
$rank = WPSEO_Rank::from_numeric_score( $score ); $rank = WPSEO_Rank::from_numeric_score( $score );
$title = $rank->get_label(); $title = $rank->get_label();
@ -190,7 +197,7 @@ class MainWP_Wordpress_SEO {
// from wordpress-seo plugin // from wordpress-seo plugin
public function parse_column_score_readability( $post_id ) { public function parse_column_score_readability( $post_id ) {
$score = (int) WPSEO_Meta::get_value( 'content_score', $post_id ); $score = (int) WPSEO_Meta::get_value( 'content_score', $post_id );
$rank = WPSEO_Rank::from_numeric_score( $score ); $rank = WPSEO_Rank::from_numeric_score( $score );
return $this->render_score_indicator( $rank ); return $this->render_score_indicator( $rank );
} }

View file

@ -1,9 +1,9 @@
<?php <?php
// todo: BZ2; support fseek! //todo: BZ2; support fseek!
class Tar_Archiver { class Tar_Archiver {
const IDLE = 0; const IDLE = 0;
const APPEND = 1; const APPEND = 1;
const CREATE = 2; const CREATE = 2;
@ -16,16 +16,16 @@ class Tar_Archiver {
protected $debug; protected $debug;
protected $chunk = ''; // 1024 * 1024 * 4 protected $chunk = ''; //1024 * 1024 * 4
protected $chunkSize = 4194304; // 1024 * 1024 * 4 protected $chunkSize = 4194304; //1024 * 1024 * 4
/** @var $backup MainWP_Backup */ /** @var $backup MainWP_Backup */
protected $backup; protected $backup;
protected $type; protected $type;
protected $pidFile; // filepath of pid file protected $pidFile; //filepath of pid file
protected $pidContent; // content of pid file protected $pidContent; //content of pid file
protected $pidUpdated; // last updated pid file protected $pidUpdated; //last updated pid file
protected $mode = self::IDLE; protected $mode = self::IDLE;
@ -127,19 +127,19 @@ class Tar_Archiver {
} }
public function createFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp, $append = false ) { public function createFullBackup( $filepath, $excludes, $addConfig, $includeCoreFiles, $excludezip, $excludenonwp, $append = false ) {
// $this->logHandle = fopen($filepath . ".log", "a+"); //$this->logHandle = fopen($filepath . ".log", "a+");
$this->createPidFile( $filepath ); $this->createPidFile( $filepath );
$this->excludeZip = $excludezip; $this->excludeZip = $excludezip;
$this->archivePath = $filepath; $this->archivePath = $filepath;
// if (!file_exists($filepath)) // if (!file_exists($filepath))
// { // {
// $this->limit = true; // $this->limit = true;
// } // }
if ( $append && @file_exists( $filepath ) ) { // todo: use wpFS if ( $append && @file_exists( $filepath ) ) { //todo: use wpFS
$this->mode = self::APPEND; $this->mode = self::APPEND;
$this->prepareAppend( $filepath ); $this->prepareAppend( $filepath );
} else { } else {
@ -176,7 +176,7 @@ class Tar_Archiver {
foreach ( $nodes as $key => $node ) { foreach ( $nodes as $key => $node ) {
if ( MainWP_Helper::startsWith( $node, ABSPATH . WPINC ) ) { if ( MainWP_Helper::startsWith( $node, ABSPATH . WPINC ) ) {
unset( $nodes[ $key ] ); unset( $nodes[ $key ] );
} elseif ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) { } else if ( MainWP_Helper::startsWith( $node, ABSPATH . basename( admin_url( '' ) ) ) ) {
unset( $nodes[ $key ] ); unset( $nodes[ $key ] );
} else { } else {
foreach ( $coreFiles as $coreFile ) { foreach ( $coreFiles as $coreFile ) {
@ -209,7 +209,7 @@ class Tar_Archiver {
if ( ! MainWP_Helper::inExcludes( $excludes, str_replace( ABSPATH, '', $node ) ) ) { if ( ! MainWP_Helper::inExcludes( $excludes, str_replace( ABSPATH, '', $node ) ) ) {
if ( is_dir( $node ) ) { if ( is_dir( $node ) ) {
$this->addDir( $node, $excludes ); $this->addDir( $node, $excludes );
} elseif ( is_file( $node ) ) { } else if ( is_file( $node ) ) {
$this->addFile( $node, str_replace( ABSPATH, '', $node ) ); $this->addFile( $node, str_replace( ABSPATH, '', $node ) );
} }
} }
@ -250,14 +250,14 @@ class Tar_Archiver {
'home' => get_option( 'home' ), 'home' => get_option( 'home' ),
'abspath' => ABSPATH, 'abspath' => ABSPATH,
'prefix' => $wpdb->prefix, 'prefix' => $wpdb->prefix,
'lang' => get_bloginfo('language'), 'lang' => get_bloginfo("language"),
'plugins' => $plugins, 'plugins' => $plugins,
'themes' => $themes, 'themes' => $themes,
) ) ); ) ) );
// $configFile = dirname($filepath) . DIRECTORY_SEPARATOR . time() . 'config.txt'; // $configFile = dirname($filepath) . DIRECTORY_SEPARATOR . time() . 'config.txt';
// $fh = fopen($filepath, 'w'); //or error; // $fh = fopen($filepath, 'w'); //or error;
// dirname($filepath) . DIRECTORY_SEPARATOR // dirname($filepath) . DIRECTORY_SEPARATOR
$this->addEmptyDirectory( 'clone', 0, 0, 0, time() ); $this->addEmptyDirectory( 'clone', 0, 0, 0, time() );
$this->addFileFromString( 'clone/config.txt', $string ); $this->addFileFromString( 'clone/config.txt', $string );
} }
@ -328,12 +328,12 @@ class Tar_Archiver {
} }
if ( 'tar.gz' == $this->type ) { if ( 'tar.gz' == $this->type ) {
// if (@fwrite($this->archive, $data, strlen($data)) === false) //if (@fwrite($this->archive, $data, strlen($data)) === false)
if ( false === @gzwrite( $this->archive, $data, strlen( $data ) ) ) { if ( false === @gzwrite( $this->archive, $data, strlen( $data ) ) ) {
throw new Exception( 'Could not write to archive' ); throw new Exception( 'Could not write to archive' );
} }
// @fflush($this->archive); //@fflush($this->archive);
} elseif ( 'tar.bz2' == $this->type ) { } else if ( 'tar.bz2' == $this->type ) {
if ( false === @bzwrite( $this->archive, $data, strlen( $data ) ) ) { if ( false === @bzwrite( $this->archive, $data, strlen( $data ) ) ) {
throw new Exception( 'Could not write to archive' ); throw new Exception( 'Could not write to archive' );
} }
@ -351,12 +351,12 @@ class Tar_Archiver {
return; return;
} }
// if ($this->cnt++ > 3) // if ($this->cnt++ > 3)
// { // {
// $this->log('error?'); // $this->log('error?');
// $this->cnt = 0; // $this->cnt = 0;
// throw new Exception('error!'); // throw new Exception('error!');
// } // }
if ( 'tar.gz' == $this->type ) { if ( 'tar.gz' == $this->type ) {
$this->log( 'writing & flushing ' . $len ); $this->log( 'writing & flushing ' . $len );
@ -365,7 +365,7 @@ class Tar_Archiver {
throw new Exception( 'Could not write to archive' ); throw new Exception( 'Could not write to archive' );
} }
@fflush( $this->archive ); @fflush( $this->archive );
} elseif ( 'tar.bz2' == $this->type ) { } else if ( 'tar.bz2' == $this->type ) {
if ( false === @bzwrite( $this->archive, $this->chunk, strlen( $len ) ) ) { if ( false === @bzwrite( $this->archive, $this->chunk, strlen( $len ) ) ) {
throw new Exception( 'Could not write to archive' ); throw new Exception( 'Could not write to archive' );
} }
@ -467,7 +467,7 @@ class Tar_Archiver {
protected $tempContent; protected $tempContent;
protected $gcCnt = 0; protected $gcCnt = 0;
// protected $limit; // protected $limit;
protected $cnt = 0; protected $cnt = 0;
private function addFile( $path, $entryName ) { private function addFile( $path, $entryName ) {
@ -483,12 +483,12 @@ class Tar_Archiver {
$this->log( 'Adding ' . $path ); $this->log( 'Adding ' . $path );
// if ($this->limit) // if ($this->limit)
// { // {
// $this->cnt++; // $this->cnt++;
// //
// if ($this->cnt > 250) throw new Exception('Some error..' . $this->archivePath); // if ($this->cnt > 250) throw new Exception('Some error..' . $this->archivePath);
// } // }
$this->updatePidFile(); $this->updatePidFile();
@ -519,7 +519,7 @@ class Tar_Archiver {
$stat = @stat( $path ); $stat = @stat( $path );
$fp = @fopen( $path, 'rb' ); $fp = @fopen( $path, 'rb' );
if ( ! $fp ) { if ( ! $fp ) {
// todo: add some error feedback! //todo: add some error feedback!
return; return;
} }
@ -616,7 +616,7 @@ class Tar_Archiver {
} }
while ( ! feof( $fp ) ) { while ( ! feof( $fp ) ) {
// 0.1MB = 1024 000 //0.1MB = 1024 000
$this->tempContent = fread( $fp, 1024000 * 5 ); $this->tempContent = fread( $fp, 1024000 * 5 );
$read = strlen( $this->tempContent ); $read = strlen( $this->tempContent );
@ -630,7 +630,7 @@ class Tar_Archiver {
$this->updatePidFile(); $this->updatePidFile();
// if ($this->limit) throw new Exception('Some error..' . $entryName); // if ($this->limit) throw new Exception('Some error..' . $entryName);
} }
@fclose( $fp ); @fclose( $fp );
@ -725,14 +725,14 @@ class Tar_Archiver {
private function checkBeforeAppend( $entryName ) { private function checkBeforeAppend( $entryName ) {
$rslt = $this->isNextFile( $entryName ); $rslt = $this->isNextFile( $entryName );
// Correct file //Correct file
if ( true === $rslt ) { if ( true === $rslt ) {
return true; return true;
} }
$out = false; $out = false;
// close, reopen with append & ftruncate //close, reopen with append & ftruncate
$this->close( false ); $this->close( false );
$this->log( 'Reopen archive to append from here' ); $this->log( 'Reopen archive to append from here' );
$this->append( $this->archivePath ); $this->append( $this->archivePath );
@ -741,19 +741,19 @@ class Tar_Archiver {
$startOffset = $rslt['startOffset']; $startOffset = $rslt['startOffset'];
@fseek( $this->archive, $startOffset ); @fseek( $this->archive, $startOffset );
@ftruncate( $this->archive, $startOffset ); @ftruncate( $this->archive, $startOffset );
} elseif ( 'tar.gz' == $this->type ) { } else if ( 'tar.gz' == $this->type ) {
$readOffset = $rslt['readOffset']; $readOffset = $rslt['readOffset'];
$bytesRead = $rslt['bytesRead']; $bytesRead = $rslt['bytesRead'];
// @fseek($this->archive, $readOffset + $bytesRead); //@fseek($this->archive, $readOffset + $bytesRead);
$out = array( 'bytesRead' => $bytesRead ); $out = array( 'bytesRead' => $bytesRead );
} }
} elseif ( false === $rslt ) { } else if ( false === $rslt ) {
if ( 'tar' == $this->type ) { if ( 'tar' == $this->type ) {
@fseek( $this->archive, 0, SEEK_END ); @fseek( $this->archive, 0, SEEK_END );
} }
} else { } else {
// todo: check for tar.gz & tar! //todo: check for tar.gz & tar!
@fseek( $this->archive, $rslt ); @fseek( $this->archive, $rslt );
@ftruncate( $this->archive, $rslt ); @ftruncate( $this->archive, $rslt );
} }
@ -790,7 +790,7 @@ class Tar_Archiver {
} }
$temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block ); $temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block );
// Check for long file!! //Check for long file!!
if ( 'L' == $temp['type'] ) { if ( 'L' == $temp['type'] ) {
$fname = trim( @fread( $this->archive, 512 ) ); $fname = trim( @fread( $this->archive, 512 ) );
$block = @fread( $this->archive, 512 ); $block = @fread( $this->archive, 512 );
@ -820,7 +820,7 @@ class Tar_Archiver {
} else { } else {
throw new Exception( 'Unexpected directory [' . $file['name'] . ']' ); throw new Exception( 'Unexpected directory [' . $file['name'] . ']' );
} }
} elseif ( 0 == $file['type'] ) { } else if ( 0 == $file['type'] ) {
if ( 0 == strcmp( trim( $file['name'] ), trim( $entryName ) ) ) { if ( 0 == strcmp( trim( $file['name'] ), trim( $entryName ) ) ) {
$previousFtell = @ftell( $this->archive ); $previousFtell = @ftell( $this->archive );
@ -843,14 +843,14 @@ class Tar_Archiver {
break; break;
} }
$bytesRead += $bytesCurrentlyRead; $bytesRead += $bytesCurrentlyRead;
$bytesToRead -= $bytesCurrentlyRead; $bytesToRead -= $bytesCurrentlyRead;
} }
if ( 0 == $bytesToRead ) { if ( 0 == $bytesToRead ) {
$toRead = ( 512 - $file['stat'][7] % 512 ) == 512 ? 0 : ( 512 - $file['stat'][7] % 512 ); $toRead = ( 512 - $file['stat'][7] % 512 ) == 512 ? 0 : ( 512 - $file['stat'][7] % 512 );
if ( $toRead > 0 ) { if ( $toRead > 0 ) {
$read = strlen( fread( $this->archive, $toRead ) ); $read = strlen( fread( $this->archive, $toRead ) );
$bytesRead += $read; $bytesRead += $read;
} }
} }
@ -862,7 +862,7 @@ class Tar_Archiver {
return $rslt; return $rslt;
} }
} elseif ( ( 'tar' == $this->type ) && ( ( false === $ftell ) || ( -1 == $ftell ) ) ) { } else if ( ( 'tar' == $this->type ) && ( ( false === $ftell ) || ( -1 == $ftell ) ) ) {
$this->log( 'Will append this: ' . print_r( $rslt, 1 ) ); $this->log( 'Will append this: ' . print_r( $rslt, 1 ) );
return $rslt; return $rslt;
@ -904,9 +904,9 @@ class Tar_Archiver {
} }
if ( 'tar.gz' == $this->type ) { if ( 'tar.gz' == $this->type ) {
// $this->archive = @fopen('compress.zlib://' . $filepath, 'ab'); //$this->archive = @fopen('compress.zlib://' . $filepath, 'ab');
$this->archive = @gzopen( $filepath, 'wb' ); $this->archive = @gzopen( $filepath, 'wb' );
} elseif ( 'tar.bz2' == $this->type ) { } else if ( 'tar.bz2' == $this->type ) {
$this->archive = @bzopen( $filepath, 'w' ); $this->archive = @bzopen( $filepath, 'w' );
} else { } else {
$this->archive = @fopen( $filepath, 'wb+' ); $this->archive = @fopen( $filepath, 'wb+' );
@ -926,9 +926,9 @@ class Tar_Archiver {
} }
if ( 'tar.gz' == $this->type ) { if ( 'tar.gz' == $this->type ) {
// $this->archive = @fopen('compress.zlib://' . $filepath, 'ab'); //$this->archive = @fopen('compress.zlib://' . $filepath, 'ab');
$this->archive = @gzopen( $filepath, 'ab' ); $this->archive = @gzopen( $filepath, 'ab' );
} elseif ( $this->type == 'tar.bz2' ) { } else if ( $this->type == 'tar.bz2' ) {
$this->archive = @bzopen( $filepath, 'a' ); $this->archive = @bzopen( $filepath, 'a' );
} else { } else {
$this->archive = @fopen( $filepath, 'ab+' ); $this->archive = @fopen( $filepath, 'ab+' );
@ -942,9 +942,9 @@ class Tar_Archiver {
function prepareAppend( $filepath ) { function prepareAppend( $filepath ) {
if ( $this->debug ) { if ( $this->debug ) {
if ( 'tar.gz' == substr( $filepath, - 6 ) ) { if ( 'tar.gz' == substr( $filepath, - 6 ) ) {
$text = chr( 31 ) . chr( 139 ) . chr( 8 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ); // magic header!! $text = chr( 31 ) . chr( 139 ) . chr( 8 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ) . chr( 0 ); //magic header!!
// Check if valid, if not, crop to valid! //Check if valid, if not, crop to valid!
$fh = @fopen( $filepath, 'rb' ); $fh = @fopen( $filepath, 'rb' );
$read = ''; $read = '';
$lastCorrect = 0; $lastCorrect = 0;
@ -961,7 +961,7 @@ class Tar_Archiver {
} }
$lastCorrect += $pos; $lastCorrect += $pos;
$read = substr( $read, $pos ); $read = substr( $read, $pos );
} }
} }
@ -972,7 +972,7 @@ class Tar_Archiver {
@fclose( $fh ); @fclose( $fh );
} catch ( Exception $e ) { } catch ( Exception $e ) {
@fclose( $fh ); @fclose( $fh );
// reopen & truncate //reopen & truncate
$fh = @fopen( $filepath, 'ab+' ); $fh = @fopen( $filepath, 'ab+' );
@fseek( $fh, $lastCorrect ); @fseek( $fh, $lastCorrect );
@ftruncate( $fh, $lastCorrect ); @ftruncate( $fh, $lastCorrect );
@ -990,9 +990,9 @@ class Tar_Archiver {
if ( 'tar.gz' == substr( $filepath, - 6 ) ) { if ( 'tar.gz' == substr( $filepath, - 6 ) ) {
$this->type = 'tar.gz'; $this->type = 'tar.gz';
// $this->archive = @fopen('compress.zlib://' . $filepath, 'rb'); // $this->archive = @fopen('compress.zlib://' . $filepath, 'rb');
$this->archive = @gzopen( $filepath, 'r' ); $this->archive = @gzopen( $filepath, 'r' );
} elseif ( 'tar.bz2' == substr( $filepath, - 7 ) ) { } else if ( 'tar.bz2' == substr( $filepath, - 7 ) ) {
$this->type = 'tar.bz2'; $this->type = 'tar.bz2';
$this->archive = @bzopen( $filepath, 'r' ); $this->archive = @bzopen( $filepath, 'r' );
} else { } else {
@ -1009,7 +1009,7 @@ class Tar_Archiver {
} }
function close( $closeLog = true ) { function close( $closeLog = true ) {
// Write chunk if it's not empty.. //Write chunk if it's not empty..
$this->writeChunk(); $this->writeChunk();
$this->log( 'Closing archive' ); $this->log( 'Closing archive' );
@ -1020,9 +1020,9 @@ class Tar_Archiver {
if ( $this->archive ) { if ( $this->archive ) {
if ( 'tar.gz' == $this->type ) { if ( 'tar.gz' == $this->type ) {
// @fclose($this->archive); //@fclose($this->archive);
@gzclose( $this->archive ); @gzclose( $this->archive );
} elseif ( 'tar.bz2' == $this->type ) { } else if ( 'tar.bz2' == $this->type ) {
@bzclose( $this->archive ); @bzclose( $this->archive );
} else { } else {
@fclose( $this->archive ); @fclose( $this->archive );
@ -1041,7 +1041,7 @@ class Tar_Archiver {
@fseek( $this->archive, 0 ); @fseek( $this->archive, 0 );
while ( $block = @fread( $this->archive, 512 ) ) { while ( $block = @fread( $this->archive, 512 ) ) {
$temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block ); $temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block );
// Check for long file!! //Check for long file!!
if ( 'L' == $temp['type'] ) { if ( 'L' == $temp['type'] ) {
$fname = trim( @fread( $this->archive, 512 ) ); $fname = trim( @fread( $this->archive, 512 ) );
$block = @fread( $this->archive, 512 ); $block = @fread( $this->archive, 512 );
@ -1065,8 +1065,8 @@ class Tar_Archiver {
if ( $file['checksum'] == 0x00000000 ) { if ( $file['checksum'] == 0x00000000 ) {
break; break;
} elseif ( substr( $file['magic'], 0, 5 ) != 'ustar' ) { } else if ( substr( $file['magic'], 0, 5 ) != 'ustar' ) {
// $this->error[] = "This script does not support extracting this type of tar file."; // $this->error[] = "This script does not support extracting this type of tar file.";
break; break;
} }
@ -1075,8 +1075,8 @@ class Tar_Archiver {
for ( $i = 0; $i < 512; $i ++ ) { for ( $i = 0; $i < 512; $i ++ ) {
$checksum += ord( substr( $block, $i, 1 ) ); $checksum += ord( substr( $block, $i, 1 ) );
} }
// if ($file['checksum'] != $checksum) // if ($file['checksum'] != $checksum)
// $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt."; // $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt.";
if ( 0 == $file['type'] ) { if ( 0 == $file['type'] ) {
if ( 0 == strcmp( trim( $file['name'] ), trim( $entryName ) ) ) { if ( 0 == strcmp( trim( $file['name'] ), trim( $entryName ) ) ) {
@ -1110,7 +1110,7 @@ class Tar_Archiver {
@fseek( $this->archive, 0 ); @fseek( $this->archive, 0 );
while ( $block = @fread( $this->archive, 512 ) ) { while ( $block = @fread( $this->archive, 512 ) ) {
$temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block ); $temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block );
// Check for long file!! //Check for long file!!
if ( 'L' == $temp['type'] ) { if ( 'L' == $temp['type'] ) {
$fname = trim( @fread( $this->archive, 512 ) ); $fname = trim( @fread( $this->archive, 512 ) );
$block = @fread( $this->archive, 512 ); $block = @fread( $this->archive, 512 );
@ -1134,8 +1134,8 @@ class Tar_Archiver {
if ( $file['checksum'] == 0x00000000 ) { if ( $file['checksum'] == 0x00000000 ) {
break; break;
} elseif ( 'ustar' != substr( $file['magic'], 0, 5 ) ) { } else if ( 'ustar' != substr( $file['magic'], 0, 5 ) ) {
// $this->error[] = "This script does not support extracting this type of tar file."; // $this->error[] = "This script does not support extracting this type of tar file.";
break; break;
} }
@ -1144,14 +1144,14 @@ class Tar_Archiver {
for ( $i = 0; $i < 512; $i ++ ) { for ( $i = 0; $i < 512; $i ++ ) {
$checksum += ord( substr( $block, $i, 1 ) ); $checksum += ord( substr( $block, $i, 1 ) );
} }
// if ($file['checksum'] != $checksum) // if ($file['checksum'] != $checksum)
// $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt."; // $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt.";
if ( 5 == $file['type'] ) { if ( 5 == $file['type'] ) {
if ( 0 == strcmp( trim( $file['name'] ), trim( $entryName ) ) ) { if ( 0 == strcmp( trim( $file['name'] ), trim( $entryName ) ) ) {
return true; return true;
} }
} elseif ( 0 == $file['type'] ) { } else if ( 0 == $file['type'] ) {
if ( 0 == strcmp( trim( $file['name'] ), trim( $entryName ) ) ) { if ( 0 == strcmp( trim( $file['name'] ), trim( $entryName ) ) ) {
return true; return true;
} else { } else {
@ -1174,7 +1174,7 @@ class Tar_Archiver {
@fseek( $this->archive, 0 ); @fseek( $this->archive, 0 );
while ( $block = fread( $this->archive, 512 ) ) { while ( $block = fread( $this->archive, 512 ) ) {
$temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block ); $temp = unpack( 'a100name/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1type/a100symlink/a6magic/a2temp/a32temp/a32temp/a8temp/a8temp/a155prefix/a12temp', $block );
// Check for long file!! //Check for long file!!
if ( 'L' == $temp['type'] ) { if ( 'L' == $temp['type'] ) {
$fname = trim( @fread( $this->archive, 512 ) ); $fname = trim( @fread( $this->archive, 512 ) );
$block = @fread( $this->archive, 512 ); $block = @fread( $this->archive, 512 );
@ -1198,8 +1198,8 @@ class Tar_Archiver {
if ( $file['checksum'] == 0x00000000 ) { if ( $file['checksum'] == 0x00000000 ) {
break; break;
} elseif ( 'ustar' != substr( $file['magic'], 0, 5 ) ) { } else if ( 'ustar' != substr( $file['magic'], 0, 5 ) ) {
// $this->error[] = "This script does not support extracting this type of tar file."; // $this->error[] = "This script does not support extracting this type of tar file.";
break; break;
} }
$block = substr_replace( $block, ' ', 148, 8 ); $block = substr_replace( $block, ' ', 148, 8 );
@ -1207,8 +1207,8 @@ class Tar_Archiver {
for ( $i = 0; $i < 512; $i ++ ) { for ( $i = 0; $i < 512; $i ++ ) {
$checksum += ord( substr( $block, $i, 1 ) ); $checksum += ord( substr( $block, $i, 1 ) );
} }
// if ($file['checksum'] != $checksum) // if ($file['checksum'] != $checksum)
// $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt."; // $this->error[] = "Could not extract from {$this->options['name']}, it is corrupt.";
if ( 5 == $file['type'] ) { if ( 5 == $file['type'] ) {
if ( ! is_dir( $to . $file['name'] ) ) { if ( ! is_dir( $to . $file['name'] ) ) {
if ( ! empty( $wp_filesystem ) ) { if ( ! empty( $wp_filesystem ) ) {
@ -1217,7 +1217,7 @@ class Tar_Archiver {
mkdir( $to . $file['name'], 0777, true ); mkdir( $to . $file['name'], 0777, true );
} }
} }
} elseif ( 0 == $file['type'] ) { } else if ( 0 == $file['type'] ) {
if ( ! is_dir( dirname( $to . $file['name'] ) ) ) { if ( ! is_dir( dirname( $to . $file['name'] ) ) ) {
if ( ! empty( $wp_filesystem ) ) { if ( ! empty( $wp_filesystem ) ) {
$wp_filesystem->mkdir( dirname( $to . $file['name'] ), FS_CHMOD_DIR ); $wp_filesystem->mkdir( dirname( $to . $file['name'] ), FS_CHMOD_DIR );
@ -1230,8 +1230,8 @@ class Tar_Archiver {
$contents = ''; $contents = '';
$bytesToRead = $file['stat'][7]; $bytesToRead = $file['stat'][7];
while ( $bytesToRead > 0 ) { while ( $bytesToRead > 0 ) {
$readNow = $bytesToRead > 1024 ? 1024 : $bytesToRead; $readNow = $bytesToRead > 1024 ? 1024 : $bytesToRead;
$contents .= fread( $this->archive, $readNow ); $contents .= fread( $this->archive, $readNow );
$bytesToRead -= $readNow; $bytesToRead -= $readNow;
} }
@ -1302,20 +1302,20 @@ if ( class_exists( 'SplHeap' ) ) {
$dirnameA = ( is_file( $pathA ) ? dirname( $pathA ) : $pathA ); $dirnameA = ( is_file( $pathA ) ? dirname( $pathA ) : $pathA );
$dirnameB = ( is_file( $pathB ) ? dirname( $pathB ) : $pathB ); $dirnameB = ( is_file( $pathB ) ? dirname( $pathB ) : $pathB );
// if both are in the same folder, first show the files, then the directories //if both are in the same folder, first show the files, then the directories
if ( dirname( $pathA ) == dirname( $pathB ) ) { if ( dirname( $pathA ) == dirname( $pathB ) ) {
if ( is_file( $pathA ) && ! is_file( $pathB ) ) { if ( is_file( $pathA ) && ! is_file( $pathB ) ) {
return - 1; return - 1;
} elseif ( ! is_file( $pathA ) && is_file( $pathB ) ) { } else if ( ! is_file( $pathA ) && is_file( $pathB ) ) {
return 1; return 1;
} }
return strcmp( $pathA, $pathB ); return strcmp( $pathA, $pathB );
} elseif ( $dirnameA == $dirnameB ) { } else if ( $dirnameA == $dirnameB ) {
return strcmp( $pathA, $pathB ); return strcmp( $pathA, $pathB );
} elseif ( MainWP_Helper::startsWith( $dirnameA, $dirnameB ) ) { } else if ( MainWP_Helper::startsWith( $dirnameA, $dirnameB ) ) {
return 1; return 1;
} elseif ( MainWP_Helper::startsWith( $dirnameB, $dirnameA ) ) { } else if ( MainWP_Helper::startsWith( $dirnameB, $dirnameA ) ) {
return - 1; return - 1;
} else { } else {
$cmp = strcmp( $dirnameA, $dirnameB ); $cmp = strcmp( $dirnameA, $dirnameB );

View file

@ -1,61 +0,0 @@
{
"name": "mainwp/mainwp-child",
"description": "This is the Child plugin for the MainWP Dashboard",
"license": "GPL-3.0-or-later",
"type": "wordpress-plugin",
"prefer-stable": true,
"minimum-stability": "dev",
"readme": "README.md",
"authors": [
{
"name": "MainWP",
"homepage": "https://mainwp.com"
}
],
"support": {
"issues": "https://github.com/mainwp/mainwp-child/issues",
"source": "https://github.com/mainwp/mainwp"
},
"require": {
"composer/installers": "^1.6",
"php": ">=5.6|>=7.0"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.5",
"phpcompatibility/php-compatibility": "^9.0",
"phpunit/phpunit": "^9.0",
"wp-cli/wp-cli": "^2.0"
},
"autoload-dev": {
"classmap": [
"tests"
],
"files": [
"tests/test-sample.php"
]
},
"scripts": {
"test": [
"phpunit --testsuite=plugin --testdox"
],
"test:all": [
"phpunit --testdox"
],
"test-coverage": [
"phpunit --testsuite=plugin --coverage-html=tests/coverage"
]
},
"scripts-descriptions": {
"test": "Run the plugin test suite",
"test:all": "Run all test suites.",
"test-coverage": "Generate test coverage for the plugin"
},
"prefer-stable": true,
"config": {
"platform": {
"php": "7.4"
},
"preferred-install": "dist",
"sort-packages": true
}
}

2479
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -6,11 +6,11 @@
Author: MainWP Author: MainWP
Author URI: https://mainwp.com Author URI: https://mainwp.com
Text Domain: mainwp-child Text Domain: mainwp-child
Version: 4.0.7 Version: 4.0.7.1
*/ */
require_once ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'version.php'; // Version information from WordPress include_once( ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'version.php' ); //Version information from wordpress
define( 'MAINWP_DEBUG', false ); define( 'MAINWP_DEBUG', FALSE );
if ( ! defined( 'MAINWP_CHILD_FILE' ) ) { if ( ! defined( 'MAINWP_CHILD_FILE' ) ) {
define( 'MAINWP_CHILD_FILE', __FILE__ ); define( 'MAINWP_CHILD_FILE', __FILE__ );
@ -25,7 +25,7 @@ function mainwp_child_autoload( $class_name ) {
$autoload_path = sprintf( '%sclass-%s.php', $autoload_dir, strtolower( str_replace( '_', '-', $class_name ) ) ); $autoload_path = sprintf( '%sclass-%s.php', $autoload_dir, strtolower( str_replace( '_', '-', $class_name ) ) );
if ( file_exists( $autoload_path ) ) { if ( file_exists( $autoload_path ) ) {
require_once $autoload_path; require_once( $autoload_path );
} }
} }

View file

@ -1,75 +0,0 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="WordPress Coding Standards" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd">
<description>The Coding standard for the MainWP Child plugin.</description>
<file>.</file>
<arg value="sp"/>
<arg name="extensions" value="php"/>
<arg name="basepath" value="."/>
<arg name="parallel" value="8"/>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/bin/*</exclude-pattern>
<exclude-pattern>*/.github/*</exclude-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>
<rule ref="WordPress">
<exclude name="WordPress.Files.FileName"/>
<exclude name="WordPress.NamingConventions.ValidVariableName"/>
<exclude name="WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition"/>
<!-- Disable Nonce verification due to large number of false positives. -->
<exclude name="WordPress.Security.NonceVerification"/>
<!-- Disable Escaping output check due to large number of false positives. -->
<exclude name="WordPress.Security.EscapeOutput"/>
<!-- Disable Strict comparison check. Not applicable in the mojority of cases. -->
<exclude name="WordPress.PHP.StrictComparisons"/>
<!-- Disable Strict comparison in array check. Not applicable in the mojority of cases. -->
<exclude name="WordPress.PHP.StrictInArray"/>
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent"/>
<exclude name="Squiz.ControlStructures.ControlSignature"/>
<exclude name="WordPress.Arrays.ArrayIndentation"/>
</rule>
<!-- Enforce PSR1 compatible namespaces. -->
<rule ref="PSR1.Classes.ClassDeclaration"/>
<rule ref="WordPress.Arrays.MultipleStatementAlignment">
<properties>
<property name="alignMultilineItems" value="!=100"/>
<property name="exact" value="false" phpcs-only="true"/>
</properties>
</rule>
<rule ref="PSR2.Methods.FunctionClosingBrace"/>
<!-- Check code for cross-version PHP compatibility. -->
<config name="testVersion" value="5.4-"/>
<rule ref="PHPCompatibility">
<!-- Exclude PHP constants back-filled by PHPCS. -->
<exclude name="PHPCompatibility.Constants.NewConstants.t_finallyFound"/>
<exclude name="PHPCompatibility.Constants.NewConstants.t_yieldFound"/>
<exclude name="PHPCompatibility.Constants.NewConstants.t_ellipsisFound"/>
<exclude name="PHPCompatibility.Constants.NewConstants.t_powFound"/>
<exclude name="PHPCompatibility.Constants.NewConstants.t_pow_equalFound"/>
<exclude name="PHPCompatibility.Constants.NewConstants.t_spaceshipFound"/>
<exclude name="PHPCompatibility.Constants.NewConstants.t_coalesceFound"/>
<exclude name="PHPCompatibility.Constants.NewConstants.t_coalesce_equalFound"/>
<exclude name="PHPCompatibility.Constants.NewConstants.t_yield_fromFound"/>
</rule>
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.DeprecatedWhitelistCommentFound">
<!-- False positive for whitelist comment recognition, but no use fixing this now
as the WPCS native whitelist comments are deprecated anyhow. -->
<exclude-pattern>/WordPress/AbstractClassRestrictionsSniff\.php$</exclude-pattern>
</rule>
</ruleset>

View file

@ -5,9 +5,9 @@ Author: mainwp
Author URI: https://mainwp.com Author URI: https://mainwp.com
Plugin URI: https://mainwp.com Plugin URI: https://mainwp.com
Requires at least: 3.6 Requires at least: 3.6
Tested up to: 5.3.2 Tested up to: 5.4.1
Requires PHP: 5.6 Requires PHP: 5.6
Stable tag: 4.0.7 Stable tag: 4.0.7.1
License: GPLv3 or later License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl-3.0.html License URI: https://www.gnu.org/licenses/gpl-3.0.html
@ -71,6 +71,18 @@ To see full documentation and FAQs please visit [MainWP Documentation](https://m
== Changelog == == Changelog ==
= 4.0.7.1 - 4-30-20 =
* Fixed: JSON decoding issues on specific setups
* Fixed: an issue with incorrect images URL
* Fixed: conflict with the Download Manager plugin
* Fixed: multiple PHP warnings
* Fixed: MySQL query compatibility problems
* Fixed: an issue with saving Wordfence settings
* Fixed: an issue with showing correct post and page creating time
* Fixed: an issue with displaying correct author in reports
* Added: support for WPVivid backups in the reporting system
* Preventative: security improvements
= 4.0.7 - 2-25-20 = = 4.0.7 - 2-25-20 =
* Fixed: an issue with saving Bulk Setting Manager keys * Fixed: an issue with saving Bulk Setting Manager keys
* Fixed: an issue with saving Wordfence extension settings * Fixed: an issue with saving Wordfence extension settings

View file

@ -1,31 +0,0 @@
<?php
/**
* PHPUnit bootstrap file
*
* @package Mainwp_Child
*/
$_tests_dir = getenv( 'WP_TESTS_DIR' );
if ( ! $_tests_dir ) {
$_tests_dir = rtrim( sys_get_temp_dir(), '/\\' ) . '/wordpress-tests-lib';
}
if ( ! file_exists( $_tests_dir . '/includes/functions.php' ) ) {
echo "Could not find $_tests_dir/includes/functions.php, have you run bin/install-wp-tests.sh ?" . PHP_EOL; // WPCS: XSS ok.
exit( 1 );
}
// Give access to tests_add_filter() function.
require_once $_tests_dir . '/includes/functions.php';
/**
* Manually load the plugin being tested.
*/
function _manually_load_plugin() {
require dirname( dirname( __FILE__ ) ) . '/mainwp-child.php';
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
// Start up the WP testing environment.
require $_tests_dir . '/includes/bootstrap.php';

View file

@ -1,20 +0,0 @@
<?php
/**
* Class SampleTest
*
* @package Mainwp_Child
*/
/**
* Sample test case.
*/
class SampleTest extends WP_UnitTestCase {
/**
* A single example test.
*/
public function test_sample() {
// Replace this with some actual testing code.
$this->assertTrue( true );
}
}