Initial commit

This commit is contained in:
2020-04-07 13:03:04 +00:00
committed by Gitium
commit 00f842d9bf
1673 changed files with 471161 additions and 0 deletions

View File

@ -0,0 +1,835 @@
.appearance_page_generatepress-site-library #wpcontent,
.appearance_page_generatepress-site-library #wpbody-content .metabox-holder {
padding: 0;
}
.generate-site-library .site-library-header {
background-color: #fff;
box-shadow: 0 1px 0 rgba(200,215,225,0.5), 0 1px 2px #DDD;
margin-bottom: 40px;
padding: 20px;
}
.site-library-container {
max-width: 1200px;
margin: 0 auto;
padding: 0 20px;
box-sizing: border-box;
}
.generate-site-library a {
text-decoration: none;
}
.site-library-header .site-library-container {
display: flex;
}
.library-links {
margin-left: auto;
}
.library-links a {
display: inline-block;
margin: 0 10px;
}
.library-title {
font-size: 20px;
color: #000;
font-weight: 500;
}
.generatepress-admin-block {
transition: opacity 300ms ease-in-out;
}
.generatepress-sites {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
grid-gap: 40px;
margin-bottom: 40px;
}
.generatepress-sites.site-open {
grid-template-columns: 1fr;
}
.generatepress-sites.site-open .site-box {
height: auto;
}
.generatepress-sites:not(.site-open) .site-box h3 {
margin: 0 0 20px;
line-height: 1em;
}
.generatepress-sites .site-screenshot img {
height: auto;
width: 100%;
}
.step-information {
padding: 0 0 0 20px;
grid-area: left;
}
.step-information,
.step-information p {
font-size: 16px;
line-height: 1.5;
text-align: left;
}
.step-information p:first-child {
margin-top: 0;
}
.step-information h3 {
margin-top: 0;
font-size: 17px;
}
.loading {
line-height: 0;
}
.loading svg path,
.loading svg rect {
fill: #0073aa;
}
.step-information li {
list-style-type: disc;
list-style-position: inside;
margin-bottom: 2px;
font-size: 12px;
}
.site-open .steps {
display: grid;
grid-template-rows: initial;
grid-template-columns: 2fr 1fr;
grid-template-areas: "left right";
}
.site-open .site-overview-information {
grid-area: left;
}
.site-box {
position: relative;
}
.generatepress-sites:not(.site-open) .site-box .controls {
display: none;
}
.site-box .controls {
display: flex;
margin-bottom: 10px;
}
.site-box .controls button,
.site-demo .demo-panel button:not(.get-started) {
background: none;
border: none;
font-size: 20px;
cursor: pointer;
padding: 2px;
}
.site-demo .demo-panel button:not(.get-started) {
height: 48px;
line-height: 48px;
padding: 0 10px;
}
.site-box .controls button:hover,
.site-demo .demo-panel button:not(.get-started):hover {
color: #0073aa;
}
.site-box .steps:not(.step-overview) .controls .next,
.site-box .steps:not(.step-overview) .controls .prev {
display: none;
}
.site-box .close:before,
.site-demo .close-demo:before {
content: "\f335";
font-family: dashicons;
}
.site-box .prev:before,
.site-demo .previous-demo:before {
content: "\f341";
font-family: dashicons;
}
.site-box .next:before,
.site-demo .next-demo:before {
content: "\f345";
font-family: dashicons;
}
.step-note {
font-size: 10px;
padding: 5px 10px;
text-transform: uppercase;
background: #eee;
margin-left: 10px;
position: relative;
top: -2px;
}
.site-demo {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 99999;
padding-top: 68px;
}
.site-demo iframe {
background: #fff;
width: 100%;
height: 100%;
height: calc(100% - 68px);
}
.demo-loading {
position: absolute;
top: 50%;
left: 50%;
margin-top: -25px;
margin-left: -25px;
z-index: 3;
}
.demo-loading.loading svg {
height: 50px;
width: 50px;
}
.site-demo .demo-panel {
position: absolute;
top: 0;
left: 0;
right: 0;
padding: 10px;
background: #fff;
box-shadow: 0px 0px 20px 0px rgba(38,50,56,0.25);
text-align: center;
z-index: 3;
}
.demo-panel .left {
float: left;
}
.demo-panel button.get-started {
line-height: 40px;
height: 40px;
padding-left: 20px;
padding-right: 20px;
font-size: 15px;
margin-top: 4px;
}
.automatic-plugins .installing-plugins:first-child:after,
.automatic-plugins .installing-plugins.show-loading:after {
content: "";
opacity: 1;
display: inline-block;
height: 17px;
width: 17px;
background-image: url(loading.svg);
background-size: 17px 17px;
margin: 0;
position: relative;
line-height: 17px;
vertical-align: top;
margin-left: 5px;
}
.automatic-plugins .plugin-installed:after {
font-family: dashicons;
content: "\f147";
color: green;
line-height: 1;
font-size: 13px;
position: relative;
top: 2px;
}
/*
* Start the CSS for the list of site boxes we initially see.
*/
.site-screenshot {
overflow: hidden;
background: #fff;
}
.site-screenshot img {
max-width: 100%;
transition: all 300ms ease-in-out;
vertical-align: middle;
}
.lazyload{
-webkit-transition: opacity 500ms ease-in-out;
-moz-transition: opacity 500ms ease-in-out;
-o-transition: opacity 500ms ease-in-out;
transition: opacity 500ms ease-in-out;
max-width: 100%;
opacity: 0;
}
.lazyload.b-loaded {
opacity: 1;
}
.step-one {
position: relative;
}
.generatepress-sites:not(.site-open) .site-box:not(:hover) .site-screenshot {
box-shadow: 0 0 10px rgba( 0,0,0,0.1 );
}
.site-box:hover .step-one {
box-shadow: 0 0 10px rgba( 0,0,0,0.1 );
}
.step-one .site-info {
background: #fff;
border-top: 1px solid #ddd;
color: #222;
display: block;
opacity: 0;
padding: 20px 40px;
position: absolute;
left: 0;
right: 0;
bottom: 0;
text-align: center;
z-index: 15;
transition: all 0.3s ease-in-out;
}
.site-box:hover .step-one .site-info {
opacity: 1;
}
.steps .site-title {
text-align: center;
padding-top: 15px;
transition: all 0.3s ease-in-out;
}
.site-box:hover .step-one .site-title {
opacity: 0;
}
.step-one .author-name {
opacity: 0.7;
}
.site-description button {
margin: 0 5px !important;
}
.step-one .site-info a,
.step-one .site-description a {
color: initial;
}
.plugin-error {
padding-left: 10px;
color: red;
}
.plugin-error:before {
font-family: dashicons;
content: "\f335";
padding-right: 3px;
line-height: 1;
font-size: 13px;
position: relative;
top: 2px;
}
.generate-sites .notice {
display: none;
}
.refresh-sites {
text-align: center;
margin-bottom: 20px;
}
.generatepress-sites.site-open + .refresh-sites {
display: none;
}
.site-library-tabs-wrapper {
display: flex;
margin-bottom: 40px;
align-items: center;
}
.site-library-tabs-wrapper .generatepress-dashboard-tabs {
margin-bottom: 0;
margin-right: auto;
}
.filter-select {
overflow: hidden;
position: relative;
cursor: pointer;
}
.filter-select:after {
font-family: dashicons;
content: "\f347";
position: absolute;
right: 10px;
top: 10px;
pointer-events: none;
}
.filter-select select {
background: #fff;
border: 1px solid #ccc;
padding: 0 30px 0 10px;
box-shadow: none;
background-image: none;
-webkit-appearance: none;
cursor: pointer;
height: 35px;
line-height: 35px;
}
.filter-select select:focus {
outline: 0;
border: 1px solid #bbb;
}
.page-builder-filter {
align-items: center;
display: flex;
}
.page-builder-filter span {
font-size: 13px;
padding-right: 5px;
}
.page-builder-label {
padding-right: 5px;
}
.site-demo iframe {
position: relative;
z-index: 2;
display: block;
margin: 0 auto;
}
.site-demo.mobile iframe {
width: 500px;
}
.site-demo.tablet iframe {
width: 768px;
}
.site-demo.open:after {
content: "";
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0,0,0,0.8);
position: fixed;
z-index: 1;
}
.site-demo .show-desktop:before {
content: "\f472";
font-family: dashicons;
}
.site-demo .show-tablet:before {
content: "\f471";
font-family: dashicons;
}
.site-demo .show-mobile:before {
content: "\f470";
font-family: dashicons;
}
.site-demo .demo-panel button.close-demo {
border-right: 1px solid #ddd;
margin-right: 10px;
padding-right: 20px;
}
.site-demo .demo-panel button.show-desktop {
border-left: 1px solid #ddd;
margin-left: 10px;
padding-left: 20px;
}
.site-demo .demo-panel button.show-mobile {
border-right: 1px solid #ddd;
margin-right: 20px;
padding-right: 20px;
}
.site-demo .demo-panel button.active {
color: #0073aa;
}
.version-required-message {
font-weight: bold;
}
.disabled-site {
opacity: 0.5;
}
.disabled-site > * {
pointer-events :none;
}
.site-step-details > div {
border-bottom: 1px solid #ddd;
margin: 0 0 30px;
padding: 0 0 30px 60px;
position: relative;
}
.site-step-details > div:last-child {
border: 0;
margin: 0;
padding-bottom: 0;
}
.site-step-details > div p:last-child {
margin-bottom: 0;
}
.number,
.big-loader {
position: absolute;
width: 40px;
height: 40px;
background: #fff;
border-radius: 50%;
line-height: 40px;
text-align: center;
top: 5px;
left: 0;
border: 2px solid #555;
font-size: 20px;
font-weight: 600;
transition: opacity 250ms ease-in-out;
}
.site-step-details > div:nth-child(1) .number:before {
content: "1";
}
.site-step-details > div:nth-child(2) .number:before {
content: "2";
}
.site-step-details > div:nth-child(3) .number:before {
content: "3";
}
.site-step-details > div:nth-child(4) .number:before {
content: "4";
}
.big-loader {
border-color: transparent;
}
.big-loader svg {
height: 50px;
width: 50px;
position: relative;
top: -5px;
left: -5px;
}
.site-step-details > div .number.step-complete:before {
content: "\f147";
font-family: dashicons;
color: #4BB543;
font-size: 20px;
}
.number.step-complete {
border-color: #4BB543;
font-size: 0;
}
.site-step-details h3 {
margin-bottom: 0;
}
.site-step-details p {
margin: 0;
}
.replace-elementor-urls,
.site-step-details .replace-elementor-urls p:not(:first-child) {
margin-top: 1em;
}
.action-area {
margin: 40px 0;
display: flex;
align-items: center;
}
.action-buttons input[type="submit"] {
border-radius: 0;
font-size: 17px;
line-height: 50px;
height: auto;
padding: 0 20px;
}
.big-loader {
opacity: 0;
}
.loading,
.error-message {
font-size: 15px;
line-height: 52px;
}
.loading svg {
width: 20px;
height: 20px;
position: relative;
top: 5px;
}
.checking-for-plugins {
line-height: normal;
}
.action-area {
display: flex;
align-items: center;
}
.important-note {
padding-left: 20px;
width: 75%;
margin-left: auto;
}
.important-note label {
display: flex;
align-items: baseline;
}
.important-note input {
position: relative;
top: 3px;
margin-right: 10px;
}
.site-open .site-box .step-information {
background: #fff;
box-shadow: 0 0 0 1px rgba(200, 215, 225, 0.5), 0 1px 2px #DDD;
padding: 40px;
position: relative;
}
.step-information h1 {
margin-top: 0;
}
.site-open .site-overview-details {
grid-area: right;
margin-left: 20px;
}
.site-open .site-description h3 {
margin-bottom: 0;
text-transform: uppercase;
font-size: 14px;
}
.site-open .site-screenshot {
margin-bottom: 40px;
padding: 5px;
box-shadow: 0 0 0 1px rgba(200, 215, 225, 0.5), 0 1px 2px #DDD;
}
.site-description > div:not(:last-child) {
margin-bottom: 20px;
padding-bottom: 20px;
border-bottom: 1px solid #ddd;
}
.site-description > div > *:last-child {
margin-bottom: 0;
}
.site-step-details ul li {
list-style-type: none;
display: inline-block;
padding: 2px 5px;
background: #f5f5f5;
margin: 2px;
}
.elementor-urls input {
display: block;
width: 100%;
padding: 8px;
}
.elementor-urls label {
font-size: 12px;
font-weight: bold;
}
.elementor-urls {
margin-top: 10px;
}
.site-open .site-box .controls button {
background: #fff;
border: none;
font-size: 20px;
cursor: pointer;
padding: 10px;
line-height: 1;
box-shadow: 0 0 0 1px rgba(200, 215, 225, 0.5), 0 1px 2px #DDD;
margin-right: 5px;
}
.site-open .site-box .controls button:before {
line-height: 0;
position: relative;
top: 2px;
}
.site-open .site-box .controls .preview-site {
font-size: inherit;
color: #000;
padding-left: 20px;
padding-right: 20px;
margin-left: auto;
margin-right: 0;
font-weight: 600;
}
.site-open .site-box .controls .preview-site:hover {
color: #0073aa;
}
.site-box:not(.no-page-builder) {
display: none;
}
.site-card-buttons {
display: flex;
margin-top: 20px;
}
.site-card-buttons button.button,
.site-card-buttons button.button-primary {
width: 50%;
height: 40px;
line-height: 40px;
border-radius: 0;
}
.site-details p {
margin: 0;
}
.plugin-area {
display: none;
margin-top: 1em;
}
.site-plugins {
margin-top: 1em;
}
.skip-content-import {
font-size: 11px;
font-weight: normal;
padding: 2px 5px;
margin-left: 5px;
position: relative;
top: -1px;
}
.no-site-library-results {
text-align: center;
margin-bottom: 2em;
}
.remove-site {
background: #fff;
padding: 40px;
box-shadow: 0 0 10px 10px rgba(0,0,0,0.01);
border: 1px solid #ddd;
margin-bottom: 40px;
}
.remove-site h2 {
margin-top: 0;
font-size: 25px;
margin-bottom: 30px;
}
.remove-site button.button-primary {
font-size: 17px;
line-height: 50px;
height: 50px;
padding: 0 20px;
border-radius: 0;
}
.remove-site .loading {
height: 50px;
}
.close-remove-site,
.skip-remove-site {
display: inline-block;
margin-left: 15px;
font-size: 15px;
}
.remove-site p {
font-size: 16px;
}
.remove-site-actions {
margin-top: 30px;
}
.generatepress-sites.remove-site-needed {
pointer-events: none;
opacity: 0.2;
}

View File

@ -0,0 +1,6 @@
<svg version="1.1" id="loader-1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="40px" height="40px" viewBox="0 0 40 40" enable-background="new 0 0 40 40" xml:space="preserve">
<path opacity="0.2" fill="#000" d="M20.201,5.169c-8.254,0-14.946,6.692-14.946,14.946c0,8.255,6.692,14.946,14.946,14.946s14.946-6.691,14.946-14.946C35.146,11.861,28.455,5.169,20.201,5.169z M20.201,31.749c-6.425,0-11.634-5.208-11.634-11.634c0-6.425,5.209-11.634,11.634-11.634c6.425,0,11.633,5.209,11.633,11.634C31.834,26.541,26.626,31.749,20.201,31.749z"/>
<path fill="#000" d="M26.013,10.047l1.654-2.866c-2.198-1.272-4.743-2.012-7.466-2.012h0v3.312h0C22.32,8.481,24.301,9.057,26.013,10.047z">
<animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 20 20" to="360 20 20" dur="0.5s" repeatCount="indefinite"/>
</path>
</svg>

After

Width:  |  Height:  |  Size: 888 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

View File

@ -0,0 +1,913 @@
jQuery( document ).ready( function($) {
var bLazy = new Blazy({
selector: '.lazyload',
success: function(ele){
$( ele ).parent().addClass( 'image-loaded' );
}
});
/**
* Demo sites
*/
$( '.site-box .preview-site' ).on( 'click', function( e ) {
e.preventDefault();
var _this = $( this );
var site_box = _this.closest( '.site-box' );
if ( ! site_box.find( 'iframe' ).attr( 'src' ) ) {
site_box.find( 'iframe' ).attr( 'src', site_box.data( 'site-data' ).preview_url );
}
site_box.find( 'iframe' ).on( 'load', function () {
site_box.find( '.demo-loading' ).fadeOut().remove();
});
site_box.find( '.site-demo' ).show().addClass( 'open' );
} );
$( '.site-demo .close-demo' ).on( 'click', function( e ) {
$( '.site-demo' ).hide().removeClass( 'open' );
bLazy.revalidate();
} );
$( '.demo-panel .show-desktop' ).on( 'click', function( e ) {
$( this ).addClass( 'active' ).siblings().removeClass( 'active' );
$( '.site-demo' ).removeClass( 'mobile' ).removeClass( 'tablet' );
} );
$( '.demo-panel .show-tablet' ).on( 'click', function( e ) {
$( this ).addClass( 'active' ).siblings().removeClass( 'active' );
$( '.site-demo' ).removeClass( 'mobile' ).addClass( 'tablet' );
} );
$( '.demo-panel .show-mobile' ).on( 'click', function( e ) {
$( this ).addClass( 'active' ).siblings().removeClass( 'active' );
$( '.site-demo' ).addClass( 'mobile' ).removeClass( 'tablet' );
} );
$( '.site-demo .get-started' ).on( 'click', function( e ) {
$( '.site-demo' ).hide().removeClass( 'open' );
if ( ! $( '.generatepress-sites' ).hasClass( 'site-open' ) ) {
var this_site = $( this ).closest( '.site-box' );
$( '.generatepress-sites' ).addClass( 'site-open' );
$( '.library-filters' ).hide();
var screenshot = this_site.find( '.site-card-screenshot img' ).attr( 'src' );
this_site.find( '.site-overview-screenshot img' ).attr( 'src', screenshot );
this_site.siblings().hide();
this_site.find( '.step-one' ).hide().next().show();
}
} );
/**
* Site card controls
*/
$( '.site-box .close' ).on( 'click', function( e ) {
e.preventDefault();
var siteBox = $( '.site-box' ),
page_builder = $( '.generatepress-sites' ).attr( 'data-page-builder' );
siteBox.find( '.steps' ).hide();
siteBox.find( '.step-one' ).fadeIn().css( 'display', '' );
$( '.generatepress-sites' ).removeClass( 'site-open' );
$( '.library-filters' ).show();
siteBox.siblings( page_builder ).fadeIn( 'fast' );
bLazy.revalidate();
if ( $( 'body' ).hasClass( 'site-import-data-exists' ) ) {
$( '.remove-site' ).show();
$( '.remove-site .do-remove-site' ).show();
$( '.remove-site .skip-remove-site' ).show();
$( '.generatepress-sites' ).addClass( 'remove-site-needed' );
window.scrollTo( { top: 0 } );
}
} );
$( '.site-box .next' ).on( 'click', function( e ) {
var page_builder = $( '.generatepress-sites' ).attr( 'data-page-builder' );
var this_site = $( this ).closest( '.site-box' );
var next_site = this_site.nextAll( page_builder ).not( '.disabled-site' ).first();
if ( ! next_site.length ) {
next_site = $( '.generatepress-sites' ).find( '.site-box' + page_builder ).first();
}
var screenshot = next_site.find( '.site-card-screenshot img' ).attr( 'data-src' );
if ( ! screenshot ) {
screenshot = next_site.find( '.site-card-screenshot img' ).attr( 'src' );
}
if ( this_site.parent().hasClass( 'site-open' ) ) {
this_site.hide();
next_site.show().find( '.step-one' ).hide().next().show();
next_site.find( '.site-overview-screenshot img' ).attr( 'src', screenshot );
}
if ( this_site.find( '.site-demo' ).hasClass( 'open' ) ) {
this_site.find( '.site-demo' ).hide().removeClass( 'open' );
if ( ! next_site.find( 'iframe' ).attr( 'src' ) ) {
next_site.find( 'iframe' ).attr( 'src', next_site.data( 'site-data' ).preview_url );
}
next_site.find( 'iframe' ).on( 'load', function () {
next_site.find( '.demo-loading' ).fadeOut().remove();
});
next_site.find( '.site-demo' ).show().addClass( 'open' );
}
if ( $( 'body' ).hasClass( 'site-import-data-exists' ) ) {
$( '.remove-site' ).show();
$( '.remove-site .do-remove-site' ).show();
$( '.remove-site .skip-remove-site' ).show();
$( '.generatepress-sites' ).addClass( 'remove-site-needed' );
}
} );
$( '.site-box .prev' ).on( 'click', function( e ) {
var page_builder = $( '.generatepress-sites' ).attr( 'data-page-builder' );
var this_site = $( this ).closest( '.site-box' );
var prev_site = this_site.prevAll( page_builder ).not( '.disabled-site' ).first();
if ( ! prev_site.length ) {
prev_site = $( '.generatepress-sites' ).find( '.site-box' + page_builder ).last();
}
var screenshot = prev_site.find( '.site-card-screenshot img' ).attr( 'data-src' );
if ( ! screenshot ) {
screenshot = prev_site.find( '.site-card-screenshot img' ).attr( 'src' );
}
if ( this_site.parent().hasClass( 'site-open' ) ) {
this_site.hide();
prev_site.show().find( '.step-one' ).hide().next().show();
prev_site.find( '.site-overview-screenshot img' ).attr( 'src', screenshot );
}
if ( this_site.find( '.site-demo' ).hasClass( 'open' ) ) {
this_site.find( '.site-demo' ).hide().removeClass( 'open' );
if ( ! prev_site.find( 'iframe' ).attr( 'src' ) ) {
prev_site.find( 'iframe' ).attr( 'src', prev_site.data( 'site-data' ).preview_url );
}
prev_site.find( 'iframe' ).on( 'load', function () {
prev_site.find( '.demo-loading' ).fadeOut().remove();
});
prev_site.find( '.site-demo' ).show().addClass( 'open' );
}
if ( $( 'body' ).hasClass( 'site-import-data-exists' ) ) {
$( '.remove-site' ).show();
$( '.remove-site .do-remove-site' ).show();
$( '.remove-site .skip-remove-site' ).show();
$( '.generatepress-sites' ).addClass( 'remove-site-needed' );
}
} );
$( '.site-box .site-details' ).on( 'click', function( e ) {
var _this = $( this ),
siteBox = _this.closest( '.site-box' ),
step = _this.closest( '.steps' ),
screenshot = step.find( '.site-card-screenshot img' ).attr( 'data-src' );
if ( ! screenshot ) {
screenshot = step.find( '.site-card-screenshot img' ).attr( 'src' );
}
$( '.generatepress-sites' ).addClass( 'site-open' );
$( '.library-filters' ).hide();
_this.closest( '.site-box' ).siblings().hide();
step.hide();
step.next().fadeIn( 'fast' );
siteBox.find( '.site-overview-screenshot img' ).attr( 'src', screenshot );
} );
$( '.confirm-content-import' ).on( 'change', function() {
var siteBox = $( this ).closest( '.site-box' );
if ( $( this ).is( ':checked' ) ) {
siteBox.find( 'input.import-content' ).attr( 'disabled', false );
} else {
siteBox.find( 'input.import-content' ).attr( 'disabled', 'disabled' );
}
} );
$( '.confirm-options-import' ).on( 'change', function() {
var siteBox = $( this ).closest( '.site-box' );
if ( $( this ).is( ':checked' ) ) {
siteBox.find( 'input.backup-options' ).attr( 'disabled', false );
siteBox.find( 'input.import-options' ).attr( 'disabled', false );
} else {
siteBox.find( 'input.backup-options' ).attr( 'disabled', 'disabled' );
siteBox.find( 'input.import-options' ).attr( 'disabled', 'disabled' );
}
} );
$( '.page-builder-group' ).on( 'change', function( e ) {
e.preventDefault();
var _this = $( this ),
filter = _this.val();
// _this.siblings().removeClass( 'active' );
// _this.addClass( 'active' );
if ( '' == filter ) {
$( '.site-box' ).show();
$( '.generatepress-sites' ).attr( 'data-page-builder', '' );
} else {
$( '.site-box:not(.' + filter + ')' ).hide();
$( '.site-box.' + filter ).show();
$( '.generatepress-sites' ).attr( 'data-page-builder', '.' + filter );
}
bLazy.revalidate();
} );
var setup_demo_content = function( _this ) {
var site_box = _this.closest( '.site-box' );
var site_data = site_box.data( 'site-data' );
if ( ! site_box.hasClass( 'data-content-loaded' ) ) {
// Prevent duplicate setup.
site_box.addClass( 'data-content-loaded' );
$.ajax({
type: 'POST',
url: generate_sites_params.ajaxurl,
data: {
action: 'generate_setup_demo_content_' + site_data.slug,
nonce: generate_sites_params.nonce,
},
success: function( data ) {
console.log(data);
if ( data.content ) {
if ( data.widgets ) {
site_box.find( '.site-action.import-content' ).attr( 'data-widgets', true );
} else {
site_box.find( '.site-action.import-content' ).attr( 'data-widgets', false );
}
if ( data.plugins ) {
$.ajax( {
type: 'POST',
url: generate_sites_params.ajaxurl,
data: {
action: 'generate_check_plugins_' + site_data.slug,
nonce: generate_sites_params.nonce,
data: site_box.data( 'site-data' ),
},
success: function( data ) {
console.log( data );
site_box.find( '.site-plugins' ).hide();
site_box.find( '.plugin-area' ).show();
site_box.find( '.site-action.import-content' ).attr( 'data-plugins', JSON.stringify( data.plugin_data ) );
$.each( data.plugin_data, function( index, value ) {
var slug = value.slug.substring( 0, value.slug.indexOf( '/' ) );
if ( value.repo && ! value.installed ) {
site_box.find( '.automatic-plugins' ).fadeIn();
site_box.find( '.automatic-plugins ul' ).append( '<li data-slug="' + slug + '">' + value.name + '</li>' );
} else if ( value.installed || value.active ) {
site_box.find( '.installed-plugins' ).fadeIn();
site_box.find( '.installed-plugins ul' ).append( '<li class="plugin-installed" data-slug="' + slug + '">' + value.name + '</li>' );
} else {
site_box.find( '.manual-plugins' ).fadeIn();
site_box.find( '.manual-plugins ul' ).append( '<li>' + value.name + '</li>' );
}
} );
if ( $.isEmptyObject( data.plugin_data ) ) {
site_box.find( '.no-plugins' ).fadeIn();
}
site_box.find( '.loading' ).hide();
site_box.find( '.site-action.import-content' ).show();
site_box.find( '.confirm-content-import-message' ).show();
site_box.find( '.skip-content-import' ).show();
},
error: function( data ) {
console.log( data );
site_box.find( '.site-message' ).hide();
site_box.find( '.error-message' ).html( data.status + ' ' + data.statusText + ' <a href="https://docs.generatepress.com/article/error-codes-importing/" target="_blank" rel="noopener">[?]</a>' ).show();
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '0' );
siteBox.find( '.theme-options .number' ).css( 'opacity', '1' );
}
} );
} else {
site_box.find( '.loading' ).hide();
site_box.find( '.site-action.import-content' ).show();
site_box.find( '.confirm-content-import-message' ).show();
site_box.find( '.skip-content-import' ).show();
}
} else {
site_box.find( '.loading' ).hide();
site_box.find( '.demo-content .big-loader' ).css( 'opacity', '0' );
site_box.find( '.demo-content .number' ).css( 'opacity', '1' ).addClass( 'step-complete' );
_this.next( 'input' ).show();
setTimeout( function() {
site_box.find( '.import-complete .number' ).css( 'opacity', '1' ).addClass( 'step-complete' );
}, 500 );
}
},
error: function( data ) {
console.log( data );
site_box.removeClass( 'data-loaded' );
site_box.find( '.loading' ).hide();
site_box.find( '.error-message' ).html( data.status + ' ' + data.statusText + ' <a href="https://docs.generatepress.com/article/error-codes-importing/" target="_blank" rel="noopener">[?]</a>' ).show();
}
});
}
};
/**
* Backup options.
*/
$( '.site-box .backup-options' ).on( 'click', function(e) {
e.preventDefault();
var _this = $( this ),
siteBox = _this.closest( '.site-box' );
_this.hide();
siteBox.find( '.confirm-backup-options' ).hide();
backup_options( _this );
} );
/**
* Backup and import theme options.
*/
$( '.site-box .import-options' ).on( 'click', function( e ) {
e.preventDefault();
var _this = $( this );
_this.hide();
_this.closest( '.site-box' ).find( '.confirm-backup-options' ).hide();
import_options( _this );
} );
function backup_options( _this ) {
var siteBox = _this.closest( '.site-box' )
data = siteBox.data( 'site-data' );
siteBox.find( '.site-message' ).text( generate_sites_params.backing_up_options );
siteBox.find( '.loading' ).show();
$.ajax( {
type: 'POST',
url: generate_sites_params.ajaxurl,
data: {
action: 'generate_backup_options_' + data.slug,
nonce: generate_sites_params.nonce,
},
success: function( data ) {
download( data, 'generatepress-options-backup.json', 'application/json' );
siteBox.find( '.loading' ).hide();
_this.next( 'input' ).show();
},
error: function( data ) {
console.log( data );
siteBox.find( '.error-message' ).html( data.status + ' ' + data.statusText + ' <a href="https://docs.generatepress.com/article/error-codes-importing/" target="_blank" rel="noopener">[?]</a>' ).show();
}
} );
}
function import_options( _this ) {
var siteBox = _this.closest( '.site-box' ),
data = siteBox.data( 'site-data' );
siteBox.find( '.site-message' ).text( generate_sites_params.importing_options );
siteBox.find( '.loading' ).show();
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '1' );;
siteBox.find( '.theme-options .number' ).css( 'opacity', '0' );
$.ajax( {
type: 'POST',
url: generate_sites_params.ajaxurl,
data: {
action: 'generate_import_options_' + data.slug,
nonce: generate_sites_params.nonce,
},
success: function( data ) {
if ( 'undefined' !== typeof data.success && ! data.success ) {
siteBox.find( '.loading' ).hide();
siteBox.find( '.error-message' ).html( data.data ).show();
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '0' );
siteBox.find( '.theme-options .number' ).css( 'opacity', '1' );
return;
}
console.log( 'Options imported.' );
_this.hide();
siteBox.find( '.loading' ).hide();
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '0' );
siteBox.find( '.theme-options .number' ).css( 'opacity', '1' ).addClass( 'step-complete' );
$( 'body' ).addClass( 'site-import-data-exists' );
siteBox.find( '.site-message' ).text( generate_sites_params.checking_demo_content );
siteBox.find( '.loading' ).show();
setup_demo_content( _this );
},
error: function( data ) {
console.log( data );
siteBox.find( '.loading' ).hide();
siteBox.find( '.error-message' ).html( data.status + ' ' + data.statusText + ' <a href="https://docs.generatepress.com/article/error-codes-importing/" target="_blank" rel="noopener">[?]</a>' ).show();
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '0' );
siteBox.find( '.theme-options .number' ).css( 'opacity', '1' );
}
} );
}
$( '.site-box' ).on( 'click', '.skip-content-import a', function(e) {
e.preventDefault();
var _this = $( this ),
siteBox = _this.closest( '.site-box' );
siteBox.find( '.skip-content-import' ).hide();
siteBox.find( '.demo-content' ).css( 'opacity', '0.5' );
siteBox.find( '.confirm-content-import-message' ).hide();
siteBox.find( '.action-buttons input' ).hide();
siteBox.find( '.action-buttons input.view-site' ).show();
siteBox.find( '.import-complete .number' ).css( 'opacity', '1' ).addClass( 'step-complete' );
} );
/**
* Install and activate plugins.
* Before content, as content may be depedent on plugins.
*/
$( '.site-box' ).on( 'click', '.import-content', function(e) {
e.preventDefault();
var _this = $( this )
siteBox = _this.closest( '.site-box' ),
plugins = _this.data( 'plugins' ),
plugin_text = siteBox.find( '.automatic-plugins li' );
_this.hide();
siteBox.find( '.skip-content-import' ).hide();
siteBox.find( '.loading' ).show();
siteBox.find( '.confirm-content-import-message' ).hide();
siteBox.find( '.demo-content .big-loader' ).css( 'opacity', '1' );
siteBox.find( '.demo-content .number' ).css( 'opacity', '0' );
$( 'body' ).addClass( 'site-import-content-exists' );
siteBox.attr( 'data-plugins', JSON.stringify( plugins ) );
if ( ! $.isEmptyObject( plugins ) ) {
siteBox.find( '.site-message' ).text( generate_sites_params.installing_plugins );
$.each( plugins, function( index, value ) {
var plugin_slug = value.slug.split('/')[0];
var plugin_row = plugin_text.filter( function () {
return $( this ).attr( 'data-slug' ) == plugin_slug;
} );
if ( 'elementor' === plugin_slug ) {
siteBox.find( '.replace-elementor-urls' ).show();
}
if ( ! value.installed ) {
plugin_row.find( '.loading' ).show();
plugin_row.addClass( 'installing-plugins' );
// Install BB Lite if Pro doesn't exist.
if ( 'bb-plugin' == plugin_slug ) {
plugin_slug = 'beaver-builder-lite-version';
}
wp.updates.installPlugin( {
slug: plugin_slug,
success: function( data ) {
console.log( data );
plugin_row.removeClass( 'installing-plugins' ).addClass( 'plugin-installed' );
plugin_row.removeClass( 'show-loading' ).next().addClass( 'show-loading' );
// Remove current plugin from queue
delete plugins[index];
if ( $.isEmptyObject( plugins ) ) {
// Onto the next step
activate_plugins( _this );
}
},
error: function( data ) {
console.log(data);
plugin_row.append( '<span class="plugin-error">' + data.errorMessage + '</span>' );
plugin_row.removeClass( 'installing-plugins' ).addClass( 'plugin-install-failed' );
plugin_row.removeClass( 'show-loading' ).next().addClass( 'show-loading' );
// Remove current plugin from queue
delete plugins[index];
if ( $.isEmptyObject( plugins ) ) {
// Onto the next step
activate_plugins( _this );
}
}
} );
} else {
// Remove current plugin from queue
delete plugins[index];
if ( $.isEmptyObject( plugins ) ) {
// Onto the next step
activate_plugins( _this );
}
}
} );
} else {
download_content( _this );
}
} );
function activate_plugins( _this ) {
var siteBox = _this.closest( '.site-box' ),
data = siteBox.data( 'site-data' );
siteBox.find( '.site-message' ).text( generate_sites_params.activating_plugins );
setTimeout( function() {
$.ajax( {
type: 'POST',
url: generate_sites_params.ajaxurl,
data: {
action: 'generate_activate_plugins_' + data.slug,
nonce: generate_sites_params.nonce,
},
success: function( data ) {
console.log( data );
download_content( _this );
},
error: function( data ) {
console.log( data );
siteBox.find( '.loading' ).hide();
siteBox.find( '.error-message' ).html( data.status + ' ' + data.statusText + ' <a href="https://docs.generatepress.com/article/error-codes-importing/" target="_blank" rel="noopener">[?]</a>' ).show();
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '0' );
siteBox.find( '.theme-options .number' ).css( 'opacity', '1' );
}
} );
}, 250 );
}
function download_content( _this ) {
var siteBox = _this.closest( '.site-box' ),
data = siteBox.data( 'site-data' );
siteBox.find( '.site-message' ).text( generate_sites_params.downloading_content );
$.ajax( {
type: 'POST',
url: generate_sites_params.ajaxurl,
data: {
action: 'generate_download_content_' + data.slug,
nonce: generate_sites_params.nonce,
},
success: function( data ) {
console.log( data );
import_content( _this );
},
error: function( data ) {
console.log( data );
siteBox.find( '.loading' ).hide();
siteBox.find( '.error-message' ).html( data.status + ' ' + data.statusText + ' <a href="https://docs.generatepress.com/article/error-codes-importing/" target="_blank" rel="noopener">[?]</a>' ).show();
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '0' );
siteBox.find( '.theme-options .number' ).css( 'opacity', '1' );
}
} );
}
function import_content( _this ) {
var siteBox = _this.closest( '.site-box' ),
data = siteBox.data( 'site-data' );
siteBox.find( '.site-message' ).text( generate_sites_params.importing_content );
$.ajax( {
type: 'POST',
url: generate_sites_params.ajaxurl,
data: {
action: 'generate_import_content_' + data.slug,
nonce: generate_sites_params.nonce,
},
success: function( data ) {
console.log( data );
import_site_options( _this );
},
error: function( data ) {
console.log( data );
siteBox.find( '.loading' ).hide();
siteBox.find( '.error-message' ).html( data.status + ' ' + data.statusText + ' <a href="https://docs.generatepress.com/article/error-codes-importing/" target="_blank" rel="noopener">[?]</a>' ).show();
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '0' );
siteBox.find( '.theme-options .number' ).css( 'opacity', '1' );
}
} );
}
/**
* Import site options.
* Comes last, as options may be dependent on plugins.
*/
function import_site_options( _this ) {
var siteBox = _this.closest( '.site-box' ),
data = siteBox.data( 'site-data' );
siteBox.find( '.site-message' ).text( generate_sites_params.importing_site_options );
setTimeout( function() {
$.ajax( {
type: 'POST',
url: generate_sites_params.ajaxurl,
data: {
action: 'generate_import_site_options_' + data.slug,
nonce: generate_sites_params.nonce,
},
success: function( data ) {
console.log( data );
if ( '1' == _this.data( 'widgets' ) ) {
import_widgets( _this );
} else {
siteBox.find( '.loading' ).hide();
siteBox.find( '.site-message' ).hide();
siteBox.find( '.demo-content .big-loader' ).css( 'opacity', '0' );
siteBox.find( '.demo-content .number' ).css( 'opacity', '1' ).addClass( 'step-complete' );
_this.next( 'input' ).show();
siteBox.find( '.import-complete .number' ).css( 'opacity', '1' ).addClass( 'step-complete' );
}
},
error: function( data ) {
console.log( data );
siteBox.find( '.loading' ).hide();
siteBox.find( '.error-message' ).html( data.status + ' ' + data.statusText + ' <a href="https://docs.generatepress.com/article/error-codes-importing/" target="_blank" rel="noopener">[?]</a>' ).show();
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '0' );
siteBox.find( '.theme-options .number' ).css( 'opacity', '1' );
}
} );
}, 250 );
}
/**
* Import widgets.
*/
function import_widgets( _this ) {
var siteBox = _this.closest( '.site-box' ),
data = siteBox.data( 'site-data' );
siteBox.find( '.site-message' ).text( generate_sites_params.importing_widgets );
setTimeout( function() {
$.ajax( {
type: 'POST',
url: generate_sites_params.ajaxurl,
data: {
action: 'generate_import_widgets_' + data.slug,
nonce: generate_sites_params.nonce,
},
success: function( data ) {
console.log( data );
siteBox.find( '.loading' ).hide();
siteBox.find( '.site-message' ).hide();
siteBox.find( '.demo-content .big-loader' ).css( 'opacity', '0' );
siteBox.find( '.demo-content .number' ).css( 'opacity', '1' ).addClass( 'step-complete' );
_this.next( 'input' ).show();
siteBox.find( '.import-complete .number' ).css( 'opacity', '1' ).addClass( 'step-complete' );
},
error: function( data ) {
console.log( data );
siteBox.find( '.loading' ).hide();
siteBox.find( '.error-message' ).html( data.status + ' ' + data.statusText + ' <a href="https://docs.generatepress.com/article/error-codes-importing/" target="_blank" rel="noopener">[?]</a>' ).show();
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '0' );
siteBox.find( '.theme-options .number' ).css( 'opacity', '1' );
}
} );
}, 250 );
}
/**
* View our completed site.
*/
$( '.site-box .view-site, .remove-site .view-site' ).on( 'click', function( e ) {
e.preventDefault();
window.location.href = generate_sites_params.home_url;
} );
function restoreThemeOptions() {
var restoreBox = $( '.remove-site' );
restoreBox.find( '.do-remove-site' ).hide()
restoreBox.find( '.skip-remove-site' ).hide();
restoreBox.find( '.loading' ).show();
restoreBox.find( '.remove-site-message' ).text( generate_sites_params.restoreThemeOptions );
$.ajax( {
type: 'POST',
url: generate_sites_params.ajaxurl,
data: {
action: 'generate_restore_theme_options',
nonce: generate_sites_params.nonce,
},
success: function( data ) {
if ( generate_sites_params.hasContentBackup || $( 'body' ).hasClass( 'site-import-content-exists' ) ) {
restoreSiteOptions();
} else {
restoreCSS();
}
console.log( data );
},
error: function( data ) {
console.log( data );
}
} );
}
function restoreSiteOptions() {
var restoreBox = $( '.remove-site' );
restoreBox.find( '.remove-site-message' ).text( generate_sites_params.restoreSiteOptions );
$.ajax( {
type: 'POST',
url: generate_sites_params.ajaxurl,
data: {
action: 'generate_restore_site_options',
nonce: generate_sites_params.nonce,
},
success: function( data ) {
restoreContent();
console.log( data );
},
error: function( data ) {
console.log( data );
}
} );
}
function restoreContent() {
var restoreBox = $( '.remove-site' );
restoreBox.find( '.remove-site-message' ).text( generate_sites_params.restoreContent );
$.ajax( {
type: 'POST',
url: generate_sites_params.ajaxurl,
data: {
action: 'generate_restore_content',
nonce: generate_sites_params.nonce,
},
success: function( data ) {
restorePlugins();
console.log( data );
},
error: function( data ) {
console.log( data );
}
} );
}
function restorePlugins() {
var restoreBox = $( '.remove-site' );
restoreBox.find( '.remove-site-message' ).text( generate_sites_params.restorePlugins );
$.ajax( {
type: 'POST',
url: generate_sites_params.ajaxurl,
data: {
action: 'generate_restore_plugins',
nonce: generate_sites_params.nonce,
},
success: function( data ) {
restoreWidgets();
console.log( data );
},
error: function( data ) {
console.log( data );
}
} );
}
function restoreWidgets() {
var restoreBox = $( '.remove-site' );
restoreBox.find( '.remove-site-message' ).text( generate_sites_params.restoreWidgets );
$.ajax( {
type: 'POST',
url: generate_sites_params.ajaxurl,
data: {
action: 'generate_restore_widgets',
nonce: generate_sites_params.nonce,
},
success: function( data ) {
restoreCSS();
console.log( data );
},
error: function( data ) {
console.log( data );
}
} );
}
function restoreCSS() {
var restoreBox = $( '.remove-site' );
restoreBox.find( '.remove-site-message' ).text( generate_sites_params.restoreCSS );
$.ajax( {
type: 'POST',
url: generate_sites_params.ajaxurl,
data: {
action: 'generate_restore_css',
nonce: generate_sites_params.nonce,
},
success: function( data ) {
cleanUp();
console.log( data );
},
error: function( data ) {
console.log( data );
}
} );
}
function cleanUp() {
var restoreBox = $( '.remove-site' );
restoreBox.find( '.remove-site-message' ).text( generate_sites_params.cleanUp );
$.ajax( {
type: 'POST',
url: generate_sites_params.ajaxurl,
data: {
action: 'generate_restore_site_clean_up',
nonce: generate_sites_params.nonce,
},
success: function( data ) {
restoreBox.find( '.loading' ).hide();
restoreBox.hide();
$( '.generatepress-sites' ).removeClass( 'remove-site-needed' );
$( 'body' ).removeClass( 'site-import-content-exists' );
$( 'body' ).removeClass( 'site-import-data-exists' );
console.log( data );
},
error: function( data ) {
console.log( data );
}
} );
}
$( '.do-remove-site' ).on( 'click', function( e ) {
e.preventDefault();
if ( confirm( generate_sites_params.confirmRemoval ) ) {
restoreThemeOptions();
}
} );
$( '.skip-remove-site' ).on( 'click', function( e ) {
e.preventDefault();
$( '.remove-site' ).hide();
$( '.generatepress-sites' ).removeClass( 'remove-site-needed' );
$( 'body' ).removeClass( 'site-import-content-exists' );
$( 'body' ).removeClass( 'site-import-data-exists' );
} );
} );

View File

@ -0,0 +1,6 @@
/*!
hey, [be]Lazy.js - v1.8.2 - 2016.10.25
A fast, small and dependency free lazy load script (https://github.com/dinbror/blazy)
(c) Bjoern Klinggaard - @bklinggaard - http://dinbror.dk/blazy
*/
(function(q,m){"function"===typeof define&&define.amd?define(m):"object"===typeof exports?module.exports=m():q.Blazy=m()})(this,function(){function q(b){var c=b._util;c.elements=E(b.options);c.count=c.elements.length;c.destroyed&&(c.destroyed=!1,b.options.container&&l(b.options.container,function(a){n(a,"scroll",c.validateT)}),n(window,"resize",c.saveViewportOffsetT),n(window,"resize",c.validateT),n(window,"scroll",c.validateT));m(b)}function m(b){for(var c=b._util,a=0;a<c.count;a++){var d=c.elements[a],e;a:{var g=d;e=b.options;var p=g.getBoundingClientRect();if(e.container&&y&&(g=g.closest(e.containerClass))){g=g.getBoundingClientRect();e=r(g,f)?r(p,{top:g.top-e.offset,right:g.right+e.offset,bottom:g.bottom+e.offset,left:g.left-e.offset}):!1;break a}e=r(p,f)}if(e||t(d,b.options.successClass))b.load(d),c.elements.splice(a,1),c.count--,a--}0===c.count&&b.destroy()}function r(b,c){return b.right>=c.left&&b.bottom>=c.top&&b.left<=c.right&&b.top<=c.bottom}function z(b,c,a){if(!t(b,a.successClass)&&(c||a.loadInvisible||0<b.offsetWidth&&0<b.offsetHeight))if(c=b.getAttribute(u)||b.getAttribute(a.src)){c=c.split(a.separator);var d=c[A&&1<c.length?1:0],e=b.getAttribute(a.srcset),g="img"===b.nodeName.toLowerCase(),p=(c=b.parentNode)&&"picture"===c.nodeName.toLowerCase();if(g||void 0===b.src){var h=new Image,w=function(){a.error&&a.error(b,"invalid");v(b,a.errorClass);k(h,"error",w);k(h,"load",f)},f=function(){g?p||B(b,d,e):b.style.backgroundImage='url("'+d+'")';x(b,a);k(h,"load",f);k(h,"error",w)};p&&(h=b,l(c.getElementsByTagName("source"),function(b){var c=a.srcset,e=b.getAttribute(c);e&&(b.setAttribute("srcset",e),b.removeAttribute(c))}));n(h,"error",w);n(h,"load",f);B(h,d,e)}else b.src=d,x(b,a)}else"video"===b.nodeName.toLowerCase()?(l(b.getElementsByTagName("source"),function(b){var c=a.src,e=b.getAttribute(c);e&&(b.setAttribute("src",e),b.removeAttribute(c))}),b.load(),x(b,a)):(a.error&&a.error(b,"missing"),v(b,a.errorClass))}function x(b,c){v(b,c.successClass);c.success&&c.success(b);b.removeAttribute(c.src);b.removeAttribute(c.srcset);l(c.breakpoints,function(a){b.removeAttribute(a.src)})}function B(b,c,a){a&&b.setAttribute("srcset",a);b.src=c}function t(b,c){return-1!==(" "+b.className+" ").indexOf(" "+c+" ")}function v(b,c){t(b,c)||(b.className+=" "+c)}function E(b){var c=[];b=b.root.querySelectorAll(b.selector);for(var a=b.length;a--;c.unshift(b[a]));return c}function C(b){f.bottom=(window.innerHeight||document.documentElement.clientHeight)+b;f.right=(window.innerWidth||document.documentElement.clientWidth)+b}function n(b,c,a){b.attachEvent?b.attachEvent&&b.attachEvent("on"+c,a):b.addEventListener(c,a,{capture:!1,passive:!0})}function k(b,c,a){b.detachEvent?b.detachEvent&&b.detachEvent("on"+c,a):b.removeEventListener(c,a,{capture:!1,passive:!0})}function l(b,c){if(b&&c)for(var a=b.length,d=0;d<a&&!1!==c(b[d],d);d++);}function D(b,c,a){var d=0;return function(){var e=+new Date;e-d<c||(d=e,b.apply(a,arguments))}}var u,f,A,y;return function(b){if(!document.querySelectorAll){var c=document.createStyleSheet();document.querySelectorAll=function(a,b,d,h,f){f=document.all;b=[];a=a.replace(/\[for\b/gi,"[htmlFor").split(",");for(d=a.length;d--;){c.addRule(a[d],"k:v");for(h=f.length;h--;)f[h].currentStyle.k&&b.push(f[h]);c.removeRule(0)}return b}}var a=this,d=a._util={};d.elements=[];d.destroyed=!0;a.options=b||{};a.options.error=a.options.error||!1;a.options.offset=a.options.offset||100;a.options.root=a.options.root||document;a.options.success=a.options.success||!1;a.options.selector=a.options.selector||".b-lazy";a.options.separator=a.options.separator||"|";a.options.containerClass=a.options.container;a.options.container=a.options.containerClass?document.querySelectorAll(a.options.containerClass):!1;a.options.errorClass=a.options.errorClass||"b-error";a.options.breakpoints=a.options.breakpoints||!1;a.options.loadInvisible=a.options.loadInvisible||!1;a.options.successClass=a.options.successClass||"b-loaded";a.options.validateDelay=a.options.validateDelay||25;a.options.saveViewportOffsetDelay=a.options.saveViewportOffsetDelay||50;a.options.srcset=a.options.srcset||"data-srcset";a.options.src=u=a.options.src||"data-src";y=Element.prototype.closest;A=1<window.devicePixelRatio;f={};f.top=0-a.options.offset;f.left=0-a.options.offset;a.revalidate=function(){q(a)};a.load=function(a,b){var c=this.options;void 0===a.length?z(a,b,c):l(a,function(a){z(a,b,c)})};a.destroy=function(){var a=this._util;this.options.container&&l(this.options.container,function(b){k(b,"scroll",a.validateT)});k(window,"scroll",a.validateT);k(window,"resize",a.validateT);k(window,"resize",a.saveViewportOffsetT);a.count=0;a.elements.length=0;a.destroyed=!0};d.validateT=D(function(){m(a)},a.options.validateDelay,a);d.saveViewportOffsetT=D(function(){C(a.options.offset)},a.options.saveViewportOffsetDelay,a);C(a.options.offset);l(a.options.breakpoints,function(a){if(a.width>=window.screen.width)return u=a.src,!1});setTimeout(function(){q(a)})}});

View File

@ -0,0 +1,167 @@
//download.js v4.2, by dandavis; 2008-2016. [MIT] see http://danml.com/download.html for tests/usage
// v1 landed a FF+Chrome compat way of downloading strings to local un-named files, upgraded to use a hidden frame and optional mime
// v2 added named files via a[download], msSaveBlob, IE (10+) support, and window.URL support for larger+faster saves than dataURLs
// v3 added dataURL and Blob Input, bind-toggle arity, and legacy dataURL fallback was improved with force-download mime and base64 support. 3.1 improved safari handling.
// v4 adds AMD/UMD, commonJS, and plain browser support
// v4.1 adds url download capability via solo URL argument (same domain/CORS only)
// v4.2 adds semantic variable names, long (over 2MB) dataURL support, and hidden by default temp anchors
// https://github.com/rndme/download
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define([], factory);
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
} else {
// Browser globals (root is window)
root.download = factory();
}
}(this, function () {
return function download(data, strFileName, strMimeType) {
var self = window, // this script is only for browsers anyway...
defaultMime = "application/octet-stream", // this default mime also triggers iframe downloads
mimeType = strMimeType || defaultMime,
payload = data,
url = !strFileName && !strMimeType && payload,
anchor = document.createElement("a"),
toString = function(a){return String(a);},
myBlob = (self.Blob || self.MozBlob || self.WebKitBlob || toString),
fileName = strFileName || "download",
blob,
reader;
myBlob= myBlob.call ? myBlob.bind(self) : Blob ;
if(String(this)==="true"){ //reverse arguments, allowing download.bind(true, "text/xml", "export.xml") to act as a callback
payload=[payload, mimeType];
mimeType=payload[0];
payload=payload[1];
}
if(url && url.length< 2048){ // if no filename and no mime, assume a url was passed as the only argument
fileName = url.split("/").pop().split("?")[0];
anchor.href = url; // assign href prop to temp anchor
if(anchor.href.indexOf(url) !== -1){ // if the browser determines that it's a potentially valid url path:
var ajax=new XMLHttpRequest();
ajax.open( "GET", url, true);
ajax.responseType = 'blob';
ajax.onload= function(e){
download(e.target.response, fileName, defaultMime);
};
setTimeout(function(){ ajax.send();}, 0); // allows setting custom ajax headers using the return:
return ajax;
} // end if valid url?
} // end if url?
//go ahead and download dataURLs right away
if(/^data:([\w+-]+\/[\w+.-]+)?[,;]/.test(payload)){
if(payload.length > (1024*1024*1.999) && myBlob !== toString ){
payload=dataUrlToBlob(payload);
mimeType=payload.type || defaultMime;
}else{
return navigator.msSaveBlob ? // IE10 can't do a[download], only Blobs:
navigator.msSaveBlob(dataUrlToBlob(payload), fileName) :
saver(payload) ; // everyone else can save dataURLs un-processed
}
}else{//not data url, is it a string with special needs?
if(/([\x80-\xff])/.test(payload)){
var i=0, tempUiArr= new Uint8Array(payload.length), mx=tempUiArr.length;
for(i;i<mx;++i) tempUiArr[i]= payload.charCodeAt(i);
payload=new myBlob([tempUiArr], {type: mimeType});
}
}
blob = payload instanceof myBlob ?
payload :
new myBlob([payload], {type: mimeType}) ;
function dataUrlToBlob(strUrl) {
var parts= strUrl.split(/[:;,]/),
type= parts[1],
decoder= parts[2] == "base64" ? atob : decodeURIComponent,
binData= decoder( parts.pop() ),
mx= binData.length,
i= 0,
uiArr= new Uint8Array(mx);
for(i;i<mx;++i) uiArr[i]= binData.charCodeAt(i);
return new myBlob([uiArr], {type: type});
}
function saver(url, winMode){
if ('download' in anchor) { //html5 A[download]
anchor.href = url;
anchor.setAttribute("download", fileName);
anchor.className = "download-js-link";
anchor.innerHTML = "downloading...";
anchor.style.display = "none";
document.body.appendChild(anchor);
setTimeout(function() {
anchor.click();
document.body.removeChild(anchor);
if(winMode===true){setTimeout(function(){ self.URL.revokeObjectURL(anchor.href);}, 250 );}
}, 66);
return true;
}
// handle non-a[download] safari as best we can:
if(/(Version)\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//.test(navigator.userAgent)) {
if(/^data:/.test(url)) url="data:"+url.replace(/^data:([\w\/\-\+]+)/, defaultMime);
if(!window.open(url)){ // popup blocked, offer direct download:
if(confirm("Displaying New Document\n\nUse Save As... to download, then click back to return to this page.")){ location.href=url; }
}
return true;
}
//do iframe dataURL download (old ch+FF):
var f = document.createElement("iframe");
document.body.appendChild(f);
if(!winMode && /^data:/.test(url)){ // force a mime that will download:
url="data:"+url.replace(/^data:([\w\/\-\+]+)/, defaultMime);
}
f.src=url;
setTimeout(function(){ document.body.removeChild(f); }, 333);
}//end saver
if (navigator.msSaveBlob) { // IE10+ : (has Blob, but not a[download] or URL)
return navigator.msSaveBlob(blob, fileName);
}
if(self.URL){ // simple fast and modern way using Blob and URL:
saver(self.URL.createObjectURL(blob), true);
}else{
// handle non-Blob()+non-URL browsers:
if(typeof blob === "string" || blob.constructor===toString ){
try{
return saver( "data:" + mimeType + ";base64," + self.btoa(blob) );
}catch(y){
return saver( "data:" + mimeType + "," + encodeURIComponent(blob) );
}
}
// Blob but not URL support:
reader=new FileReader();
reader.onload=function(e){
saver(this.result);
};
reader.readAsDataURL(blob);
}
return true;
}; /* end download() */
}));

View File

@ -0,0 +1,156 @@
<?php
/**
* Search Beaver Builder content for images to download.
*
* @since 1.6
*/
class GeneratePress_Sites_Process_Beaver_Builder {
/**
* Constructor
*
* @since 1.6
*/
public function __construct() {
$this->image_importer = new GeneratePress_Sites_Image_Importer();
}
/**
* Import
*
* @since 1.6
* @return void
*/
public function import() {
GeneratePress_Sites_Helper::log( '== Start Processing Beaver Builder Images ==' );
$post_ids = GeneratePress_Sites_Helper::get_all_posts();
if ( is_array( $post_ids ) ) {
foreach ( $post_ids as $post_id ) {
$this->import_single_post( $post_id );
}
}
}
/**
* Update post meta.
*
* @param integer $post_id Post ID.
* @return void
*/
public function import_single_post( $post_id = 0 ) {
if ( ! empty( $post_id ) ) {
// Get page builder data.
$data = get_post_meta( $post_id, '_fl_builder_data', true );
if ( ! empty( $data ) ) {
foreach ( $data as $key => $el ) {
// Import background images.
if ( 'row' === $el->type || 'column' === $el->type ) {
$data[ $key ]->settings = $this->import_background_images( $el->settings );
}
// Import module images.
if ( 'module' === $el->type ) {
$data[ $key ]->settings = $this->import_module_images( $el->settings );
}
}
// Update page builder data.
update_post_meta( $post_id, '_fl_builder_data', $data );
update_post_meta( $post_id, '_fl_builder_draft', $data );
// Clear all cache.
FLBuilderModel::delete_asset_cache_for_all_posts();
}
}
}
/**
* Import Module Images.
*
* @param object $settings Module settings object.
* @return object
*/
public function import_module_images( $settings ) {
/**
* 1) Set photos.
*/
$settings = $this->import_photo( $settings );
/**
* 2) Set `$settings->data` for Only type 'image-icon'
*
* @todo Remove the condition `'image-icon' === $settings->type` if `$settings->data` is used only for the Image Icon.
*/
if ( isset( $settings->data ) && isset( $settings->photo ) && ! empty( $settings->photo ) && 'image-icon' === $settings->type ) {
$settings->data = FLBuilderPhoto::get_attachment_data( $settings->photo );
}
/**
* 3) Set `list item` module images
*/
if ( isset( $settings->add_list_item ) ) {
foreach ( $settings->add_list_item as $key => $value ) {
$settings->add_list_item[ $key ] = $this->import_photo( $value );
}
}
return $settings;
}
/**
* Helper: Import BG Images.
*
* @param object $settings Row settings object.
* @return object
*/
public function import_background_images( $settings ) {
if ( ! empty( $settings->bg_image ) && ! empty( $settings->bg_image_src ) ) {
$image = array(
'url' => $settings->bg_image_src,
'id' => $settings->bg_image,
);
$downloaded_image = $this->image_importer->import( $image );
$settings->bg_image_src = $downloaded_image['url'];
$settings->bg_image = $downloaded_image['id'];
}
return $settings;
}
/**
* Helper: Import Photo.
*
* @param object $settings Row settings object.
* @return object
*/
public function import_photo( $settings ) {
if ( ! empty( $settings->photo ) && ! empty( $settings->photo_src ) ) {
$image = array(
'url' => $settings->photo_src,
'id' => $settings->photo,
);
$downloaded_image = $this->image_importer->import( $image );
$settings->photo_src = $downloaded_image['url'];
$settings->photo = $downloaded_image['id'];
}
return $settings;
}
}

View File

@ -0,0 +1,36 @@
<?php
class GeneratePress_Sites_Content_Importer extends GeneratePress\WPContentImporter2\WXRImporter {
/**
* Constructor method.
*
* @param array $options Importer options.
*/
public function __construct( $options = array() ) {
parent::__construct( $options );
// Set current user to $mapping variable.
// Fixes the [WARNING] Could not find the author for ... log warning messages.
$current_user_obj = wp_get_current_user();
$this->mapping['user_slug'][ $current_user_obj->user_login ] = $current_user_obj->ID;
}
/**
* Get all protected variables from the WXR_Importer needed for continuing the import.
*/
public function get_importer_data() {
return array(
'mapping' => $this->mapping
);
}
/**
* Sets all protected variables from the WXR_Importer needed for continuing the import.
*
* @param array $data with set variables.
*/
public function set_importer_data( $data ) {
//$this->mapping = empty( $data['mapping'] ) ? array() : $data['mapping'];
//$this->requires_remapping = empty( $data['requires_remapping'] ) ? array() : $data['requires_remapping'];
}
}

View File

@ -0,0 +1,990 @@
<?php
defined( 'WPINC' ) or die;
class GeneratePress_Sites_Helper {
/**
* Instance.
*
* @access private
* @var object Instance
* @since 1.6
*/
private static $instance;
/**
* Background processing.
*
* @access private
* @var object Instance
* @since 1.6
*/
public static $background_process;
/**
* Initiator.
*
* @since 1.6
* @return object initialized object of class.
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self;
}
return self::$instance;
}
public function __construct() {
add_filter( 'upload_mimes', array( $this, 'mime_types' ) );
add_filter( 'wp_check_filetype_and_ext', array( $this, 'check_real_mime_type' ), 10, 4 );
add_filter( 'wie_widget_settings_array', array( $this, 'fix_custom_menu_widget_ids' ) );
add_filter( 'wp_prepare_attachment_for_js', array( $this, 'add_svg_image_support' ), 10, 3 );
// Batch Processing.
require_once GP_LIBRARY_DIRECTORY . 'batch-processing/wp-async-request.php';
require_once GP_LIBRARY_DIRECTORY . 'batch-processing/wp-background-process.php';
require_once GENERATE_SITES_PATH . 'classes/class-sites-background-process.php';
require_once GENERATE_SITES_PATH . 'classes/class-beaver-builder-batch-processing.php';
require_once GENERATE_SITES_PATH . 'classes/class-site-import-image.php';
self::$background_process = new GeneratePress_Site_Background_Process();
if ( is_admin() ) {
self::includes();
}
}
/**
* Include necessary files.
*
* @since 1.6
*/
public static function includes() {
// Content Importer
if ( ! class_exists( 'WP_Importer' ) ) {
require ABSPATH . '/wp-admin/includes/class-wp-importer.php';
}
require_once GENERATE_SITES_PATH . 'libs/wxr-importer/WXRImporter.php';
require_once GENERATE_SITES_PATH . 'libs/wxr-importer/WPImporterLogger.php';
require_once GENERATE_SITES_PATH . 'libs/wxr-importer/WXRImportInfo.php';
require_once GENERATE_SITES_PATH . 'classes/class-content-importer.php';
}
public static function get_mapped_term_ids() {
return ( array ) get_transient( 'generatepress_sites_mapped_term_ids' );
}
public static function get_mapped_post_ids( $slug ) {
return ( array ) get_option( "generatepress_sites_mapped_ids_{$slug}", array() );
}
/**
* Moves the existing widgets into the inactive area before new widgets are added.
* This prevents sites looking messed up due to existing widgets.
*
* @since 1.6
*/
public static function clear_widgets() {
$data = get_option( 'sidebars_widgets' );
$backup_data = get_option( '_generatepress_site_library_backup', array() );
$backup_data['widgets'] = $data;
// Set our backed up options.
update_option( '_generatepress_site_library_backup', $backup_data );
$all_widgets = array();
foreach ( $data as $sidebar_id => $widgets ) {
// Skip inactive widgets (should not be in export file).
if ( 'wp_inactive_widgets' === $sidebar_id ) {
continue;
}
if ( is_array( $widgets ) ) {
foreach ( $widgets as $widget_instance_id => $widget ) {
$all_widgets[] = $widget;
}
}
}
$results['wp_inactive_widgets'] = $all_widgets;
update_option( 'sidebars_widgets', $results );
}
/**
* Checks to see whether options exist or not.
*
* @since 1.8
*
* @return bool
*/
public static function do_options_exist() {
$theme_mods = self::get_theme_mods();
$settings = self::get_theme_settings();
$has_data = array(
'mods' => array(),
'options' => array()
);
foreach ( $theme_mods as $theme_mod ) {
if ( get_theme_mod( $theme_mod ) ) {
$has_data['mods'][$theme_mod] = get_theme_mod( $theme_mod );
}
}
foreach ( $settings as $setting ) {
if ( get_option( $setting ) ) {
// The blog module runs a migration script on activation for now. This checks if those migrated values have been changed.
if ( 'generate_blog_settings' === $setting && function_exists( 'generate_blog_get_defaults' ) ) {
$defaults = generate_blog_get_defaults();
$options = get_option( $setting );
$diff = array();
foreach ( $options as $option => $value ) {
if ( isset( $defaults[ $option ] ) && $value !== $defaults[ $option ] ) {
$diff[ $option ] = $value;
}
}
if ( empty( $diff ) ) {
continue;
}
}
$has_data['options'][$setting] = get_option( $setting );
}
}
if ( ! array_filter( $has_data ) ) {
return false;
} else {
return true;
}
}
/**
* Imports our content and custom CSS.
*
* @since 1.6
*
* @param string $path
*/
public static function import_xml( $path, $slug ) {
$options = array(
'fetch_attachments' => true,
'default_author' => 0,
);
$current_css = wp_get_custom_css_post();
$logger = new GeneratePress\WPContentImporter2\WPImporterLogger();
$importer = new GeneratePress_Sites_Content_Importer( $options );
$importer->set_logger( $logger );
$result = $importer->import( $path );
// Get all mapped post and term data.
$existing_data = self::get_mapped_post_ids( $slug );
$mapped_data = $importer->get_importer_data();
$mapped_posts = $mapped_data['mapping']['post'];
// Merge exiting mapped posts with any new ones. Existing posts don't get mapped, so we need to preserve them.
$all_data = $mapped_posts + $existing_data;
// Set our site specific mapped posts with all of our data.
update_option( 'generatepress_sites_mapped_ids_' . $slug, $all_data, false );
// Set mapped term IDs.
// These are always the same, even if the site has been imported before. No fancy stuff needed.
$term_mapping = $mapped_data['mapping']['term_id'];
set_transient( 'generatepress_sites_mapped_term_ids', $term_mapping, 0.1 * HOUR_IN_SECONDS );
wp_update_custom_css_post( $current_css->post_content );
// Page builders need so much extra work.
self::update_page_builder_content();
// Log our content
//self::log( $logger );
}
/**
* List plugins that have a pro version.
*
* We want to check to see if these exist before installing or activating
* the free versions.
*
* @since 1.6
*
* @return array
*/
public static function check_for_pro_plugins() {
return apply_filters( 'generate_sites_pro_plugins', array(
'beaver-builder-lite-version/fl-builder.php' => 'bb-plugin/fl-builder.php',
'ultimate-addons-for-beaver-builder-lite/bb-ultimate-addon.php' => 'bb-ultimate-addon/bb-ultimate-addon.php',
'powerpack-addon-for-beaver-builder/bb-powerpack-lite.php' => 'bbpowerpack/bb-powerpack.php',
) );
}
/**
* Check to see if required plugins are active.
*
* @since 1.6
*
* @param string $plugin
*/
public static function is_plugin_installed( $plugin ) {
$pro_plugins = self::check_for_pro_plugins();
// Check to see if this plugin has a pro version.
if ( array_key_exists( $plugin, $pro_plugins ) ) {
if ( file_exists( WP_PLUGIN_DIR . '/' . $pro_plugins[$plugin] ) ) {
return true;
}
}
if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin ) ) {
return true;
}
return false;
}
/**
* Allow SVG images.
*
* @since 1.6
*
* @param array $response Attachment response.
* @param object $attachment Attachment object.
* @param array $meta Attachment meta data.
*/
public static function add_svg_image_support( $response, $attachment, $meta ) {
if ( ! function_exists( 'simplexml_load_file' ) ) {
return $response;
}
if ( ! empty( $response['sizes'] ) ) {
return $response;
}
if ( 'image/svg+xml' !== $response['mime'] ) {
return $response;
}
$svg_path = get_attached_file( $attachment->ID );
$dimensions = self::get_svg_dimensions( $svg_path );
$response['sizes'] = array(
'full' => array(
'url' => $response['url'],
'width' => $dimensions->width,
'height' => $dimensions->height,
'orientation' => $dimensions->width > $dimensions->height ? 'landscape' : 'portrait',
),
);
return $response;
}
/**
* Get the dimensions of the uploaded SVG.
*
* @since 1.6
*
* @param string $svg SVG file path.
* @return array Return SVG file height & width for valid SVG file.
*/
public static function get_svg_dimensions( $svg ) {
$svg = simplexml_load_file( $svg );
if ( false === $svg ) {
$width = '0';
$height = '0';
} else {
$attributes = $svg->attributes();
$width = (string) $attributes->width;
$height = (string) $attributes->height;
}
return (object) array(
'width' => $width,
'height' => $height,
);
}
/**
* Taken from the core media_sideload_image function and
* modified to return an array of data instead of html.
*
* @since 1.6
*
* @param string $file The image file path.
* @return array An array of image data.
*/
public static function sideload_image( $file ) {
$data = new stdClass();
if ( ! function_exists( 'media_handle_sideload' ) ) {
require_once( ABSPATH . 'wp-admin/includes/media.php' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/image.php' );
}
if ( ! empty( $file ) ) {
// Set variables for storage, fix file filename for query strings.
preg_match( '/[^\?]+\.(jpe?g|jpe|svg|gif|png)\b/i', $file, $matches );
$file_array = array();
$file_array['name'] = basename( $matches[0] );
// Download file to temp location.
$file_array['tmp_name'] = download_url( $file );
// If error storing temporarily, return the error.
if ( is_wp_error( $file_array['tmp_name'] ) ) {
return $file_array['tmp_name'];
}
// Do the validation and storage stuff.
$id = media_handle_sideload( $file_array, 0 );
// If error storing permanently, unlink.
if ( is_wp_error( $id ) ) {
@unlink( $file_array['tmp_name'] );
return $id;
}
// Build the object to return.
$meta = wp_get_attachment_metadata( $id );
$data->attachment_id = $id;
$data->url = wp_get_attachment_url( $id );
$data->thumbnail_url = wp_get_attachment_thumb_url( $id );
if ( isset( $meta['height'] ) ) {
$data->height = $meta['height'];
}
if ( isset( $meta['width'] ) ) {
$data->width = $meta['width'];
}
}
return $data;
}
/**
* Re-maps menu locations.
*
* @since 1.6
*
* @param array Incoming locations.
*/
public static function set_nav_menu_locations( $locations = array() ) {
$menu_locations = array();
$term_ids = self::get_mapped_term_ids();
if ( isset( $locations ) ) {
self::log( '== Start mapping menu locations ==' );
foreach ( $locations as $menu => $value ) {
if ( empty( $value ) ) {
continue;
}
$menu_locations[$menu] = $term_ids[$value];
self::log( $value . ' -> ' . $term_ids[$value] );
}
set_theme_mod( 'nav_menu_locations', $menu_locations );
}
}
/**
* Re-maps the global Page Header locations.
*
* @since 1.6
*
* @param array Incoming locations.
*/
public static function set_global_page_header_locations( $locations = array(), $slug ) {
$new_locations = array();
$post_ids = self::get_mapped_post_ids( $slug );
if ( isset( $locations ) && ! empty( $locations ) ) {
self::log( '== Start mapping global page headers ==' );
foreach( $locations as $key => $value ) {
if ( empty( $value ) ) {
continue;
}
$new_locations[$key] = $post_ids[$value];
self::log( $value . ' -> ' . $post_ids[$value] );
}
update_option( 'generate_page_header_global_locations', $new_locations );
}
}
/**
* Re-maps the per-page Page Headers.
*
* @since 1.6
*
* @param array Incoming locations.
*/
public static function set_page_headers( $headers = array(), $slug ) {
$new_headers = array();
$post_ids = self::get_mapped_post_ids( $slug );
if ( isset( $headers ) && ! empty( $headers ) ) {
self::log( '== Start mapping individual page headers ==' );
foreach ( $headers as $post_id => $header_id ) {
update_post_meta( $post_ids[$post_id], '_generate-select-page-header', $post_ids[$header_id] );
self::log( $header_id . ' -> ' . $post_ids[$header_id] );
}
}
}
/**
* Re-maps the front page and posts page.
*
* @since 1.6
*
* @param string Name of the option to update.
* @param string Title of the page.
*/
public static function set_reading_pages( $name, $value, $slug ) {
if ( empty( $value ) ) {
return;
}
self::log( '== Start mapping front and blog pages ==' );
// Get import data, with new menu IDs.
$post_ids = self::get_mapped_post_ids( $slug );
update_option( $name, $post_ids[$value] );
self::log( $value . ' -> ' . $post_ids[$value] );
}
/**
* Re-maps WooCommerce pages.
*
* @since 1.6
*
* @param string Name of the option to update.
* @param string Title of the page.
*/
public static function set_woocommerce_pages( $name, $value, $slug ) {
if ( empty( $value ) ) {
return;
}
self::log( '== Start mapping WooCommerce pages ==' );
$post_ids = self::get_mapped_post_ids( $slug );
update_option( $name, $post_ids[$value] );
self::log( $value . ' -> ' . $post_ids[$value] );
}
/**
* Change the menu IDs in the custom menu widgets in the widget import data.
* This solves the issue with custom menu widgets not having the correct (new) menu ID, because they
* have the old menu ID from the export site.
*
* @param array $widget The widget settings array.
*/
public static function fix_custom_menu_widget_ids( $widget ) {
// Skip (no changes needed), if this is not a custom menu widget.
if ( ! array_key_exists( 'nav_menu', $widget ) || empty( $widget['nav_menu'] ) || ! is_int( $widget['nav_menu'] ) ) {
return $widget;
}
// Get import data, with new menu IDs.
$term_ids = self::get_mapped_term_ids();
if ( ! isset( $term_ids[ $widget['nav_menu'] ] ) ) {
return $widget;
}
self::log( '== Start mapping navigation widgets ==' );
self::log( $widget['nav_menu'] . ' -> ' . $term_ids[ $widget['nav_menu'] ] );
// Set the new menu ID for the widget.
$widget['nav_menu'] = $term_ids[ $widget['nav_menu'] ];
return $widget;
}
/**
* Re-maps the element locations.
*
* @since 1.7
*
* @param array Incoming locations.
*/
public static function set_element_locations( $locations = array(), $slug ) {
$post_ids = self::get_mapped_post_ids( $slug );
if ( isset( $locations ) && ! empty( $locations ) ) {
self::log( '== Start mapping element locations ==' );
foreach( $locations as $key => $value ) {
$new_locations = array();
if ( empty( $value ) ) {
continue;
}
foreach ( ( array ) $value as $data ) {
if ( $data['object'] ) {
self::log( $data['object'] . ' -> ' . $post_ids[$data['object']] );
$data['object'] = $post_ids[$data['object']];
}
$new_locations[] = $data;
}
update_post_meta( $post_ids[$key], '_generate_element_display_conditions', $new_locations );
}
}
}
/**
* Re-maps the element exclusions.
*
* @since 1.7
*
* @param array Incoming locations.
*/
public static function set_element_exclusions( $locations = array(), $slug ) {
$post_ids = self::get_mapped_post_ids( $slug );
if ( isset( $locations ) && ! empty( $locations ) ) {
self::log( '== Start mapping element exclusions ==' );
foreach( $locations as $key => $value ) {
$new_locations = array();
if ( empty( $value ) ) {
continue;
}
foreach ( ( array ) $value as $data ) {
if ( $data['object'] ) {
self::log( $data['object'] . ' -> ' . $post_ids[$data['object']] );
$data['object'] = $post_ids[$data['object']];
}
$new_locations[] = $data;
}
update_post_meta( $post_ids[$key], '_generate_element_exclude_conditions', $new_locations );
}
}
}
/**
* Update menu URLs.
*
* @since 1.7.3
*
* @param string Preview URL
*/
public static function update_menu_urls( $url ) {
$args = array (
'post_type' => 'nav_menu_item',
'fields' => 'ids',
'no_found_rows' => true,
'post_status' => 'any',
'numberposts' => 50,
);
$items = get_posts( $args );
foreach ( $items as $item_id ) {
$item_type = get_post_meta( $item_id, '_menu_item_type', true );
if ( 'custom' === $item_type ) {
$item_url = get_post_meta( $item_id, '_menu_item_url', true );
if ( $item_url && '#' !== $item_url ) {
$item_url = str_replace( $url, site_url(), $item_url );
update_post_meta( $item_id, '_menu_item_url', $item_url );
}
}
}
}
/**
* Allow other files types to be uploaded.
*
* @since 1.6
*
* @param array Existing types.
* @return array Merged types.
*/
public static function mime_types( $mimes ) {
$mimes = array_merge(
$mimes, array(
'xml' => 'text/xml',
'wie' => 'text/plain',
'svg' => 'image/svg+xml',
'svgz' => 'image/svg+xml'
)
);
return $mimes;
}
/**
* Different MIME type of different PHP version
*
* Filters the "real" file type of the given file.
*
* @since 1.8
*
* @param array $wp_check_filetype_and_ext File data array containing 'ext', 'type', and
* 'proper_filename' keys.
* @param string $file Full path to the file.
* @param string $filename The name of the file (may differ from $file due to
* $file being in a tmp directory).
* @param array $mimes Key is the file extension with value as the mime type.
*/
public static function check_real_mime_type( $defaults, $file, $filename, $mimes ) {
if ( 'content.xml' === $filename ) {
$defaults['ext'] = 'xml';
$defaults['type'] = 'text/xml';
}
if ( 'widgets.wie' === $filename ) {
$defaults['ext'] = 'wie';
$defaults['type'] = 'text/plain';
}
return $defaults;
}
/**
* Download a file to WordPress from a URL.
*
* @since 1.6
*
* @param string URL of the file.
* @return array
*/
public static function download_file( $file ) {
// Gives us access to the download_url() and wp_handle_sideload() functions
require_once( ABSPATH . 'wp-admin/includes/file.php' );
// URL to the WordPress logo
$url = $file;
$timeout_seconds = 10;
// Download file to temp dir
$temp_file = download_url( $url, $timeout_seconds );
if ( is_wp_error( $temp_file ) ) {
return array(
'success' => false,
'data' => $temp_file->get_error_message()
);
}
// Array based on $_FILE as seen in PHP file uploads
$file = array(
'name' => basename( $url ),
'tmp_name' => $temp_file,
'error' => 0,
'size' => filesize( $temp_file ),
);
$overrides = array(
'test_form' => false,
'test_size' => true,
);
// Move the temporary file into the uploads directory
$results = wp_handle_sideload( $file, $overrides );
if ( empty( $results['error'] ) ) {
return array(
'success' => true,
'data' => $results,
);
} else {
return array(
'success' => false,
'error' => $results['error'],
);
}
}
/**
* Get data from the options.json file.
*
* @since 1.6
*
* @param string URL of the file.
* @return array
*/
public static function get_options( $url ) {
$url = wp_safe_remote_get( esc_url( $url ) );
if ( is_wp_error( $url ) ) {
return false;
}
return json_decode( wp_remote_retrieve_body( $url ), true );
}
/**
* Check to see if a remote file exists.
*
* @since 1.6
*
* @param string URL of the file.
* @return bool
*/
public static function file_exists( $url ) {
$response = wp_safe_remote_get( esc_url( $url ) );
if ( is_wp_error( $response ) ) {
self::log( $response->get_error_message() );
return false;
}
return strlen( $response['body'] ) > 100 && ( '200' == $response['response']['code'] || '301' == $response['response']['code'] ) ? true : false;
}
/**
* Log events to the debug.log file.
*
* @since 1.6
* @param mixed $log Log data.
* @return void
*/
public static function log( $log ) {
if ( ! WP_DEBUG_LOG ) {
return;
}
if ( is_array( $log ) || is_object( $log ) ) {
error_log( print_r( $log, true ) );
} else {
error_log( $log );
}
}
/**
* Get all posts to run through batch processing.
*
* @since 1.6
*
* @return object All posts.
*/
public static function get_all_posts() {
$args = array(
'post_type' => 'any',
'fields' => 'ids',
'no_found_rows' => true,
'post_status' => 'publish',
'numberposts' => -1,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => '_fl_builder_data',
'compare' => 'EXISTS',
),
array(
'key' => '_elementor_data',
'compare' => 'EXISTS',
)
)
);
$posts = get_posts( $args );
if ( $posts ) {
return $posts;
}
return false;
}
/**
* Searches Elementor and Beaver Builder content for images to download.
*
* @since 1.6
*/
public static function update_page_builder_content() {
// Add "bb-plugin" in import [queue].
// Add "beaver-builder-lite-version" in import [queue].
if ( is_plugin_active( 'beaver-builder-lite-version/fl-builder.php' ) || is_plugin_active( 'bb-plugin/fl-builder.php' ) ) {
if ( class_exists( 'GeneratePress_Sites_Process_Beaver_Builder' ) ) {
$import = new GeneratePress_Sites_Process_Beaver_Builder();
self::$background_process->push_to_queue( $import );
}
}
// Dispatch Queue.
self::$background_process->save()->dispatch();
}
/**
* Clear Elementor & Beaver Builder caches when needed.
*
* @since 1.6
*/
public static function clear_page_builder_cache() {
if ( class_exists( 'FLBuilderModel' ) && method_exists( 'FLBuilderModel', 'delete_asset_cache_for_all_posts' ) ) {
// Clear all cache.
FLBuilderModel::delete_asset_cache_for_all_posts();
self::log( 'Cleared Beaver Builder cache.' );
}
if ( class_exists( 'Elementor\Plugin' ) && method_exists( 'Elementor\Posts_CSS_Manager', 'clear_cache' ) ) {
// !important, Clear the cache after images import.
Elementor\Plugin::instance()->posts_css_manager->clear_cache();
self::log( 'Cleared Elementor cache.' );
}
}
/**
* List out GP option names.
*
* @since 1.6
*
* @return array
*/
public static function get_theme_settings() {
return array(
'generate_settings',
'generate_background_settings',
'generate_blog_settings',
'generate_hooks',
'generate_page_header_settings',
'generate_secondary_nav_settings',
'generate_spacing_settings',
'generate_menu_plus_settings',
'generate_woocommerce_settings',
);
}
/**
* List out GP theme mods.
*
* @since 1.6
*
* @return array
*/
public static function get_theme_mods() {
return array(
'font_body_variants',
'font_body_category',
'font_site_title_variants',
'font_site_title_category',
'font_site_tagline_variants',
'font_site_tagline_category',
'font_navigation_variants',
'font_navigation_category',
'font_secondary_navigation_variants',
'font_secondary_navigation_category',
'font_buttons_variants',
'font_buttons_category',
'font_heading_1_variants',
'font_heading_1_category',
'font_heading_2_variants',
'font_heading_2_category',
'font_heading_3_variants',
'font_heading_3_category',
'font_heading_4_variants',
'font_heading_4_category',
'font_heading_5_variants',
'font_heading_5_category',
'font_heading_6_variants',
'font_heading_6_category',
'font_widget_title_variants',
'font_widget_title_category',
'font_footer_variants',
'font_footer_category',
'generate_copyright',
);
}
/**
* Build the loading icon.
*
* @since 1.6
*/
public static function loading_icon() {
?>
<svg width="44" height="44" viewBox="0 0 44 44" xmlns="http://www.w3.org/2000/svg" stroke="#000">
<g fill="none" fill-rule="evenodd" stroke-width="2">
<circle cx="22" cy="22" r="1">
<animate attributeName="r"
begin="0s" dur="1.8s"
values="1; 20"
calcMode="spline"
keyTimes="0; 1"
keySplines="0.165, 0.84, 0.44, 1"
repeatCount="indefinite" />
<animate attributeName="stroke-opacity"
begin="0s" dur="1.8s"
values="1; 0"
calcMode="spline"
keyTimes="0; 1"
keySplines="0.3, 0.61, 0.355, 1"
repeatCount="indefinite" />
</circle>
<circle cx="22" cy="22" r="1">
<animate attributeName="r"
begin="-0.9s" dur="1.8s"
values="1; 20"
calcMode="spline"
keyTimes="0; 1"
keySplines="0.165, 0.84, 0.44, 1"
repeatCount="indefinite" />
<animate attributeName="stroke-opacity"
begin="-0.9s" dur="1.8s"
values="1; 0"
calcMode="spline"
keyTimes="0; 1"
keySplines="0.3, 0.61, 0.355, 1"
repeatCount="indefinite" />
</circle>
</g>
</svg>
<?php
}
}
GeneratePress_Sites_Helper::get_instance();

View File

@ -0,0 +1,192 @@
<?php
defined( 'WPINC' ) or die;
/**
* Downloads and updates images.
*
* @since 1.6
*/
class GeneratePress_Sites_Image_Importer {
/**
* Images IDs
*
* @var array The Array of already image IDs.
* @since 1.6
*/
private $already_imported_ids = array();
/**
* Constructor
*
* @since 1.6
*/
public function __construct() {
if ( ! function_exists( 'WP_Filesystem' ) ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
}
WP_Filesystem();
}
/**
* Process Image Download
*
* @since 1.6
* @param array $attachments Attachment array.
* @return array Attachment array.
*/
public function process( $attachments ) {
$downloaded_images = array();
foreach ( $attachments as $key => $attachment ) {
$downloaded_images[] = $this->import( $attachment );
}
return $downloaded_images;
}
/**
* Get Hash Image.
*
* @since 1.6
* @param string $attachment_url Attachment URL.
* @return string Hash string.
*/
private function get_hash_image( $attachment_url ) {
return sha1( $attachment_url );
}
/**
* Get Saved Image.
*
* @since 1.6
* @param string $attachment Attachment Data.
* @return string Hash string.
*/
private function get_saved_image( $attachment ) {
global $wpdb;
// Already imported? Then return!
if ( isset( $this->already_imported_ids[ $attachment['id'] ] ) ) {
GeneratePress_Sites_Helper::log( 'Successfully replaced: ' . $attachment['url'] );
return $this->already_imported_ids[ $attachment['id'] ];
}
// 1. Is already imported in Batch Import Process?
$post_id = $wpdb->get_var(
$wpdb->prepare(
'SELECT `post_id` FROM `' . $wpdb->postmeta . '`
WHERE `meta_key` = \'_generatepress_sites_image_hash\'
AND `meta_value` = %s
;',
$this->get_hash_image( $attachment['url'] )
)
);
// 2. Is image already imported though XML?
if ( empty( $post_id ) ) {
// Get file name without extension.
// To check it exist in attachment.
$filename = preg_replace( '/\\.[^.\\s]{3,4}$/', '', basename( $attachment['url'] ) );
$post_id = $wpdb->get_var(
$wpdb->prepare(
'SELECT `post_id` FROM `' . $wpdb->postmeta . '`
WHERE `meta_key` = \'_wp_attached_file\'
AND `meta_value` LIKE %s
;',
'%' . $filename . '%'
)
);
GeneratePress_Sites_Helper::log( 'Successfully replaced: ' . $attachment['url'] );
}
if ( $post_id ) {
$new_attachment = array(
'id' => $post_id,
'url' => wp_get_attachment_url( $post_id ),
);
$this->already_imported_ids[ $attachment['id'] ] = $new_attachment;
return $new_attachment;
}
return false;
}
/**
* Import Image
*
* @since 1.6
* @param array $attachment Attachment array.
* @return array Attachment array.
*/
public function import( $attachment ) {
$saved_image = $this->get_saved_image( $attachment );
if ( $saved_image ) {
return $saved_image;
}
$file_content = wp_remote_retrieve_body( wp_safe_remote_get( $attachment['url'] ) );
// Empty file content?
if ( empty( $file_content ) ) {
GeneratePress_Sites_Helper::log( 'Failed to replace: ' . $attachment['url'] );
GeneratePress_Sites_Helper::log( 'Error: Failed wp_remote_retrieve_body().' );
return $attachment;
}
// Extract the file name and extension from the URL.
$filename = basename( $attachment['url'] );
$upload = wp_upload_bits(
$filename,
null,
$file_content
);
$post = array(
'post_title' => $filename,
'guid' => $upload['url'],
);
$info = wp_check_filetype( $upload['file'] );
if ( $info ) {
$post['post_mime_type'] = $info['type'];
} else {
// For now just return the origin attachment.
return $attachment;
}
$post_id = wp_insert_attachment( $post, $upload['file'] );
wp_update_attachment_metadata(
$post_id,
wp_generate_attachment_metadata( $post_id, $upload['file'] )
);
update_post_meta( $post_id, '_generatepress_sites_image_hash', $this->get_hash_image( $attachment['url'] ) );
$new_attachment = array(
'id' => $post_id,
'url' => $upload['url'],
);
GeneratePress_Sites_Helper::log( 'Successfully replaced: ' . $attachment['url'] );
$this->already_imported_ids[ $attachment['id'] ] = $new_attachment;
return $new_attachment;
}
}

View File

@ -0,0 +1,246 @@
<?php
defined( 'WPINC' ) or die;
class GeneratePress_Sites_Restore {
/**
* Instance.
*
* @access private
* @var object Instance
* @since 1.9
*/
private static $instance;
/**
* Initiator.
*
* @since 1.9
* @return object initialized object of class.
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self;
}
return self::$instance;
}
public function __construct() {
add_action( 'wp_ajax_generate_restore_theme_options', array( $this, 'theme_options' ) );
add_action( 'wp_ajax_generate_restore_site_options', array( $this, 'site_options' ) );
add_action( 'wp_ajax_generate_restore_content', array( $this, 'content' ) );
add_action( 'wp_ajax_generate_restore_plugins', array( $this, 'plugins' ) );
add_action( 'wp_ajax_generate_restore_widgets', array( $this, 'widgets' ) );
add_action( 'wp_ajax_generate_restore_css', array( $this, 'css' ) );
add_action( 'wp_ajax_generate_restore_site_clean_up', array( $this, 'clean_up' ) );
}
public function theme_options() {
check_ajax_referer( 'generate_sites_nonce', 'nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$backup_data = get_option( '_generatepress_site_library_backup', array() );
if ( ! empty( $backup_data ) ) {
if ( ! empty( $backup_data['theme_options']['mods'] ) ) {
remove_theme_mods();
}
if ( ! empty( $backup_data['theme_options']['options'] ) ) {
$option_keys = array(
'generate_settings',
'generate_background_settings',
'generate_blog_settings',
'generate_hooks',
'generate_page_header_settings',
'generate_secondary_nav_settings',
'generate_spacing_settings',
'generate_menu_plus_settings',
'generate_woocommerce_settings',
);
foreach ( $option_keys as $key ) {
delete_option( $key );
}
}
$modules = generatepress_get_site_premium_modules();
foreach ( $modules as $name => $key ) {
delete_option( $key );
}
if ( ! empty( $backup_data['modules'] ) ) {
foreach ( (array) $backup_data['modules'] as $name => $key ) {
update_option( $key, 'activated' );
}
}
// Theme options.
foreach ( $backup_data['theme_options']['mods'] as $key => $val ) {
// Only allow valid theme mods.
if ( ! in_array( $key, GeneratePress_Sites_Helper::get_theme_mods() ) ) {
GeneratePress_Sites_Helper::log( 'Bad theme mod key: ' . $key );
continue;
}
set_theme_mod( $key, $val );
}
foreach ( $backup_data['theme_options']['options'] as $key => $val ) {
// Only allow valid options.
if ( ! in_array( $key, GeneratePress_Sites_Helper::get_theme_settings() ) ) {
GeneratePress_Sites_Helper::log( 'Bad theme setting key: ' . $key );
continue;
}
update_option( $key, $val );
}
}
wp_send_json( __( 'Theme options restored.', 'gp-premium' ) );
die();
}
public function site_options() {
check_ajax_referer( 'generate_sites_nonce', 'nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$backup_data = get_option( '_generatepress_site_library_backup', array() );
if ( ! empty( $backup_data ) ) {
foreach ( $backup_data['site_options'] as $key => $val ) {
if ( in_array( $key, ( array ) generatepress_sites_disallowed_options() ) ) {
GeneratePress_Sites_Helper::log( 'Disallowed option: ' . $key );
continue;
}
if ( 'nav_menu_locations' === $key || 'custom_logo' === $key ) {
set_theme_mod( $key, $val );
} else {
update_option( $key, $val );
}
}
}
wp_send_json( __( 'Site options restored.', 'gp-premium' ) );
die();
}
public function content() {
check_ajax_referer( 'generate_sites_nonce', 'nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$backup_data = get_option( '_generatepress_site_library_backup', array() );
if ( ! empty( $backup_data ) ) {
global $wpdb;
$post_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_generatepress_sites_imported_post'" );
$term_ids = $wpdb->get_col( "SELECT term_id FROM {$wpdb->termmeta} WHERE meta_key='_generatepress_sites_imported_term'" );
foreach ( $post_ids as $id ) {
wp_delete_post( $id, true );
}
}
wp_send_json( __( 'Content restored.', 'gp-premium' ) );
die();
}
public function plugins() {
check_ajax_referer( 'generate_sites_nonce', 'nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$backup_data = get_option( '_generatepress_site_library_backup', array() );
if ( ! empty( $backup_data['plugins'] ) && ! empty( $backup_data['site_options'] ) ) {
update_option( 'active_plugins', $backup_data['plugins'] );
}
wp_send_json( __( 'Plugins restored.', 'gp-premium' ) );
die();
}
public function widgets() {
check_ajax_referer( 'generate_sites_nonce', 'nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$backup_data = get_option( '_generatepress_site_library_backup', array() );
if ( ! empty( $backup_data['widgets'] ) ) {
update_option( 'sidebars_widgets', $backup_data['widgets'] );
}
wp_send_json( __( 'Widgets restored.', 'gp-premium' ) );
die();
}
public function css() {
check_ajax_referer( 'generate_sites_nonce', 'nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
$backup_data = get_option( '_generatepress_site_library_backup', array() );
if ( ! empty( $backup_data ) ) {
$css = '';
$current_css = wp_get_custom_css_post();
if ( isset( $current_css->post_content ) ) {
// Remove existing library CSS.
$current_css->post_content = preg_replace( '#(/\\* GeneratePress Site CSS \\*/).*?(/\\* End GeneratePress Site CSS \\*/)#s', '', $current_css->post_content );
}
if ( ! empty( $backup_data['css'] ) ) {
$current_css->post_content .= $backup_data['css'];
}
wp_update_custom_css_post( $current_css->post_content );
}
wp_send_json( __( 'CSS restored.', 'gp-premium' ) );
die();
}
public function clean_up() {
check_ajax_referer( 'generate_sites_nonce', 'nonce' );
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
delete_option( 'generate_dynamic_css_output' );
delete_option( 'generate_dynamic_css_cached_version' );
delete_option( '_generatepress_site_library_backup' );
wp_send_json( __( 'Completed clean-up.', 'gp-premium' ) );
die();
}
}
GeneratePress_Sites_Restore::get_instance();

View File

@ -0,0 +1,259 @@
<?php
defined( 'WPINC' ) or die;
class GeneratePress_Sites_Widget_Importer {
/**
* Instance.
*/
private static $_instance = null;
public static function instance() {
if ( ! isset( self::$_instance ) ) {
self::$_instance = new self;
}
return self::$_instance;
}
/**
* Available widgets
*
* Gather site's widgets into array with ID base, name, etc.
* Used by export and import functions.
*
* @since 0.4
* @global array $wp_registered_widget_updates
* @return array Widget information
*/
function wie_available_widgets() {
global $wp_registered_widget_controls;
$widget_controls = $wp_registered_widget_controls;
$available_widgets = array();
foreach ( $widget_controls as $widget ) {
// No duplicates.
if ( ! empty( $widget['id_base'] ) && ! isset( $available_widgets[ $widget['id_base'] ] ) ) {
$available_widgets[ $widget['id_base'] ]['id_base'] = $widget['id_base'];
$available_widgets[ $widget['id_base'] ]['name'] = $widget['name'];
}
}
return apply_filters( 'wie_available_widgets', $available_widgets );
}
/**
* Import widget JSON data
*
* @since 0.4
* @global array $wp_registered_sidebars
* @param object $data JSON widget data from .wie file.
* @return array Results array
*/
function wie_import_data( $data ) {
global $wp_registered_sidebars;
// Have valid data?
// If no data or could not decode.
if ( empty( $data ) || ! is_object( $data ) ) {
wp_die(
esc_html__( 'Import data could not be read. Please try a different file.', 'widget-importer-exporter' ),
'',
array(
'back_link' => true,
)
);
}
// Hook before import.
do_action( 'wie_before_import' );
$data = apply_filters( 'wie_import_data', $data );
// Get all available widgets site supports.
$available_widgets = $this->wie_available_widgets();
// Get all existing widget instances.
$widget_instances = array();
foreach ( $available_widgets as $widget_data ) {
$widget_instances[ $widget_data['id_base'] ] = get_option( 'widget_' . $widget_data['id_base'] );
}
// Begin results.
$results = array();
// Loop import data's sidebars.
foreach ( $data as $sidebar_id => $widgets ) {
// Skip inactive widgets (should not be in export file).
if ( 'wp_inactive_widgets' === $sidebar_id ) {
continue;
}
// Check if sidebar is available on this site.
// Otherwise add widgets to inactive, and say so.
if ( isset( $wp_registered_sidebars[ $sidebar_id ] ) ) {
$sidebar_available = true;
$use_sidebar_id = $sidebar_id;
$sidebar_message_type = 'success';
$sidebar_message = '';
} else {
$sidebar_available = false;
$use_sidebar_id = 'wp_inactive_widgets'; // Add to inactive if sidebar does not exist in theme.
$sidebar_message_type = 'error';
$sidebar_message = esc_html__( 'Widget area does not exist in theme (using Inactive)', 'widget-importer-exporter' );
}
// Result for sidebar
// Sidebar name if theme supports it; otherwise ID.
$results[ $sidebar_id ]['name'] = ! empty( $wp_registered_sidebars[ $sidebar_id ]['name'] ) ? $wp_registered_sidebars[ $sidebar_id ]['name'] : $sidebar_id;
$results[ $sidebar_id ]['message_type'] = $sidebar_message_type;
$results[ $sidebar_id ]['message'] = $sidebar_message;
$results[ $sidebar_id ]['widgets'] = array();
// Loop widgets.
foreach ( $widgets as $widget_instance_id => $widget ) {
$fail = false;
// Get id_base (remove -# from end) and instance ID number.
$id_base = preg_replace( '/-[0-9]+$/', '', $widget_instance_id );
$instance_id_number = str_replace( $id_base . '-', '', $widget_instance_id );
// Does site support this widget?
if ( ! $fail && ! isset( $available_widgets[ $id_base ] ) ) {
$fail = true;
$widget_message_type = 'error';
$widget_message = esc_html__( 'Site does not support widget', 'widget-importer-exporter' ); // Explain why widget not imported.
}
// Filter to modify settings object before conversion to array and import
// Leave this filter here for backwards compatibility with manipulating objects (before conversion to array below)
// Ideally the newer wie_widget_settings_array below will be used instead of this.
$widget = apply_filters( 'wie_widget_settings', $widget );
// Convert multidimensional objects to multidimensional arrays
// Some plugins like Jetpack Widget Visibility store settings as multidimensional arrays
// Without this, they are imported as objects and cause fatal error on Widgets page
// If this creates problems for plugins that do actually intend settings in objects then may need to consider other approach: https://wordpress.org/support/topic/problem-with-array-of-arrays
// It is probably much more likely that arrays are used than objects, however.
$widget = json_decode( wp_json_encode( $widget ), true );
// Filter to modify settings array
// This is preferred over the older wie_widget_settings filter above
// Do before identical check because changes may make it identical to end result (such as URL replacements).
$widget = apply_filters( 'wie_widget_settings_array', $widget );
// Does widget with identical settings already exist in same sidebar?
if ( ! $fail && isset( $widget_instances[ $id_base ] ) ) {
// Get existing widgets in this sidebar.
$sidebars_widgets = get_option( 'sidebars_widgets' );
$sidebar_widgets = isset( $sidebars_widgets[ $use_sidebar_id ] ) ? $sidebars_widgets[ $use_sidebar_id ] : array(); // Check Inactive if that's where will go.
// Loop widgets with ID base.
$single_widget_instances = ! empty( $widget_instances[ $id_base ] ) ? $widget_instances[ $id_base ] : array();
foreach ( $single_widget_instances as $check_id => $check_widget ) {
// Is widget in same sidebar and has identical settings?
if ( in_array( "$id_base-$check_id", $sidebar_widgets, true ) && (array) $widget === $check_widget ) {
$fail = true;
$widget_message_type = 'warning';
// Explain why widget not imported.
$widget_message = esc_html__( 'Widget already exists', 'widget-importer-exporter' );
break;
}
}
}
// No failure.
if ( ! $fail ) {
// Add widget instance
$single_widget_instances = get_option( 'widget_' . $id_base ); // All instances for that widget ID base, get fresh every time.
$single_widget_instances = ! empty( $single_widget_instances ) ? $single_widget_instances : array(
'_multiwidget' => 1, // Start fresh if have to.
);
$single_widget_instances[] = $widget; // Add it.
// Get the key it was given.
end( $single_widget_instances );
$new_instance_id_number = key( $single_widget_instances );
// If key is 0, make it 1
// When 0, an issue can occur where adding a widget causes data from other widget to load,
// and the widget doesn't stick (reload wipes it).
if ( '0' === strval( $new_instance_id_number ) ) {
$new_instance_id_number = 1;
$single_widget_instances[ $new_instance_id_number ] = $single_widget_instances[0];
unset( $single_widget_instances[0] );
}
// Move _multiwidget to end of array for uniformity.
if ( isset( $single_widget_instances['_multiwidget'] ) ) {
$multiwidget = $single_widget_instances['_multiwidget'];
unset( $single_widget_instances['_multiwidget'] );
$single_widget_instances['_multiwidget'] = $multiwidget;
}
// Update option with new widget.
update_option( 'widget_' . $id_base, $single_widget_instances );
// Assign widget instance to sidebar.
// Which sidebars have which widgets, get fresh every time.
$sidebars_widgets = get_option( 'sidebars_widgets' );
// Avoid rarely fatal error when the option is an empty string
// https://github.com/stevengliebe/widget-importer-exporter/pull/11.
if ( ! $sidebars_widgets ) {
$sidebars_widgets = array();
}
// Use ID number from new widget instance.
$new_instance_id = $id_base . '-' . $new_instance_id_number;
// Add new instance to sidebar.
$sidebars_widgets[ $use_sidebar_id ][] = $new_instance_id;
// Save the amended data.
update_option( 'sidebars_widgets', $sidebars_widgets );
// After widget import action.
$after_widget_import = array(
'sidebar' => $use_sidebar_id,
'sidebar_old' => $sidebar_id,
'widget' => $widget,
'widget_type' => $id_base,
'widget_id' => $new_instance_id,
'widget_id_old' => $widget_instance_id,
'widget_id_num' => $new_instance_id_number,
'widget_id_num_old' => $instance_id_number,
);
do_action( 'wie_after_widget_import', $after_widget_import );
// Success message.
if ( $sidebar_available ) {
$widget_message_type = 'success';
$widget_message = esc_html__( 'Imported', 'widget-importer-exporter' );
} else {
$widget_message_type = 'warning';
$widget_message = esc_html__( 'Imported to Inactive', 'widget-importer-exporter' );
}
}
// Result for widget instance
$results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['name'] = isset( $available_widgets[ $id_base ]['name'] ) ? $available_widgets[ $id_base ]['name'] : $id_base; // Widget name or ID if name not available (not supported by site).
$results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['title'] = ! empty( $widget['title'] ) ? $widget['title'] : esc_html__( 'No Title', 'widget-importer-exporter' ); // Show "No Title" if widget instance is untitled.
$results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message_type'] = $widget_message_type;
$results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message'] = $widget_message;
}
}
// Hook after import.
do_action( 'wie_after_import' );
// Return results.
return apply_filters( 'wie_import_results', $results );
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,34 @@
<?php
/**
* Image Background Process
*/
if ( class_exists( 'WP_Background_Process' ) ) {
/**
* Image Background Process
*
* @since 1.0.11
*/
class GeneratePress_Site_Background_Process extends WP_Background_Process {
protected $action = 'image_process';
protected function task( $process ) {
if ( method_exists( $process, 'import' ) ) {
$process->import();
}
return false;
}
protected function complete() {
parent::complete();
}
}
}

View File

@ -0,0 +1,138 @@
<?php
namespace GeneratePress\WPContentImporter2;
/**
* Describes a logger instance
*
* Based on PSR-3: http://www.php-fig.org/psr/psr-3/
*
* The message MUST be a string or object implementing __toString().
*
* The message MAY contain placeholders in the form: {foo} where foo
* will be replaced by the context data in key "foo".
*
* The context array can contain arbitrary data, the only assumption that
* can be made by implementors is that if an Exception instance is given
* to produce a stack trace, it MUST be in a key named "exception".
*
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md
* for the full interface specification.
*/
class WPImporterLogger {
/**
* System is unusable.
*
* @param string $message
* @param array $context
* @return null
*/
public function emergency( $message, array $context = array() ) {
return $this->log( 'emergency', $message, $context );
}
/**
* Action must be taken immediately.
*
* Example: Entire website down, database unavailable, etc. This should
* trigger the SMS alerts and wake you up.
*
* @param string $message
* @param array $context
* @return null
*/
public function alert( $message, array $context = array() ) {
return $this->log( 'alert', $message, $context );
}
/**
* Critical conditions.
*
* Example: Application component unavailable, unexpected exception.
*
* @param string $message
* @param array $context
* @return null
*/
public function critical( $message, array $context = array() ) {
return $this->log( 'critical', $message, $context );
}
/**
* Runtime errors that do not require immediate action but should typically
* be logged and monitored.
*
* @param string $message
* @param array $context
* @return null
*/
public function error( $message, array $context = array()) {
return $this->log( 'error', $message, $context );
}
/**
* Exceptional occurrences that are not errors.
*
* Example: Use of deprecated APIs, poor use of an API, undesirable things
* that are not necessarily wrong.
*
* @param string $message
* @param array $context
* @return null
*/
public function warning( $message, array $context = array() ) {
return $this->log( 'warning', $message, $context );
}
/**
* Normal but significant events.
*
* @param string $message
* @param array $context
* @return null
*/
public function notice( $message, array $context = array() ) {
return $this->log( 'notice', $message, $context );
}
/**
* Interesting events.
*
* Example: User logs in, SQL logs.
*
* @param string $message
* @param array $context
* @return null
*/
public function info( $message, array $context = array() ) {
return $this->log( 'info', $message, $context );
}
/**
* Detailed debug information.
*
* @param string $message
* @param array $context
* @return null
*/
public function debug( $message, array $context = array() ) {
return $this->log( 'debug', $message, $context );
}
/**
* Logs with an arbitrary level.
*
* @param mixed $level
* @param string $message
* @param array $context
* @return null
*/
public function log( $level, $message, array $context = array() ) {
$this->messages[] = array(
'timestamp' => time(),
'level' => $level,
'message' => $message,
'context' => $context,
);
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace GeneratePress\WPContentImporter2;
class WXRImportInfo {
public $home;
public $siteurl;
public $title;
public $users = array();
public $post_count = 0;
public $media_count = 0;
public $comment_count = 0;
public $term_count = 0;
public $generator = '';
public $version;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,750 @@
<?php
defined( 'WPINC' ) or die;
define( 'GENERATE_SITES_PATH', plugin_dir_path( __FILE__ ) );
define( 'GENERATE_SITES_URL', plugin_dir_url( __FILE__ ) );
require_once GENERATE_SITES_PATH . 'classes/class-site.php';
require_once GENERATE_SITES_PATH . 'classes/class-site-helper.php';
require_once GENERATE_SITES_PATH . 'classes/class-site-widget-importer.php';
require_once GENERATE_SITES_PATH . 'classes/class-site-restore.php';
/**
* Checks to see if we're in the Site dashboard.
*
* @since 1.6
*
* @return bool
*/
function generate_is_sites_dashboard() {
$screen = get_current_screen();
if ( ! is_object( $screen ) ) {
return false;
}
if ( 'appearance_page_generatepress-site-library' === $screen->id ) {
return true;
}
return false;
}
add_filter( 'generate_dashboard_tabs', 'generate_sites_dashboard_tab' );
/**
* Add the Sites tab to our Dashboard tabs.
*
* @since 1.6
*
* @param array $tabs Existing tabs.
* @return array New tabs.
*/
function generate_sites_dashboard_tab( $tabs ) {
$tabs['Sites'] = array(
'name' => __( 'Site Library', 'gp-premium' ),
'url' => admin_url( 'themes.php?page=generatepress-site-library' ),
'class' => generate_is_sites_dashboard() ? 'active' : '',
);
return $tabs;
}
add_action( 'admin_menu', 'generate_site_library_register' );
/**
* Register our Site Library page.
*
* @since 1.7
*/
function generate_site_library_register() {
add_submenu_page(
'themes.php',
__( 'Site Library', 'gp-premium' ),
__( 'Site Library', 'gp-premium' ),
'manage_options',
'generatepress-site-library',
'generate_sites_container'
);
}
add_action( 'admin_head', 'generate_site_library_fix_menu' );
/**
* Set our current menu item as the GeneratePress Dashboard.
*
* @since 1.7
*/
function generate_site_library_fix_menu() {
global $parent_file, $submenu_file, $post_type;
if ( generate_is_sites_dashboard() ) {
$parent_file = 'themes.php';
$submenu_file = 'generate-options';
}
remove_submenu_page( 'themes.php', 'generatepress-site-library' );
}
add_action( 'admin_enqueue_scripts', 'generate_sites_do_enqueue_scripts' );
/**
* Add our scripts for the site library.
*
* @since 1.8
*/
function generate_sites_do_enqueue_scripts() {
if ( ! generate_is_sites_dashboard() ) {
return;
}
$backup_data = get_option( '_generatepress_site_library_backup', array() );
wp_enqueue_script(
'generate-sites-admin',
GENERATE_SITES_URL . 'assets/js/admin.js',
array( 'jquery', 'wp-util', 'updates', 'generate-sites-blazy' ),
GP_PREMIUM_VERSION,
true
);
wp_enqueue_script(
'generate-sites-download',
GENERATE_SITES_URL . 'assets/js/download.js',
array( 'jquery', 'generate-sites-admin' ),
GP_PREMIUM_VERSION,
true
);
wp_enqueue_script(
'generate-sites-blazy',
GENERATE_SITES_URL . 'assets/js/blazy.min.js',
array(),
GP_PREMIUM_VERSION,
true
);
wp_localize_script(
'generate-sites-admin',
'generate_sites_params',
array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'generate_sites_nonce' ),
'importing_options' => __( 'Importing options', 'gp-premium' ),
'backing_up_options' => __( 'Backing up options', 'gp-premium' ),
'checking_demo_content' => __( 'Checking demo content', 'gp-premium' ),
'downloading_content' => __( 'Downloading content', 'gp-premium' ),
'importing_content' => __( 'Importing content', 'gp-premium' ),
'importing_site_options' => __( 'Importing site options', 'gp-premium' ),
'importing_widgets' => __( 'Importing widgets', 'gp-premium' ),
'activating_plugins' => __( 'Activating plugins', 'gp-premium' ),
'installing_plugins' => __( 'Installing plugins', 'gp-premium' ),
'automatic_plugins' => __( 'Automatic', 'gp-premium' ),
'manual_plugins' => __( 'Manual', 'gp-premium' ),
'home_url' => home_url(),
'restoreThemeOptions' => __( 'Restoring theme options', 'gp-premium' ),
'restoreSiteOptions' => __( 'Restoring site options', 'gp-premium' ),
'restoreContent' => __( 'Removing imported content', 'gp-premium' ),
'restorePlugins' => __( 'Deactivating imported plugins', 'gp-premium' ),
'restoreWidgets' => __( 'Restoring widgets', 'gp-premium' ),
'restoreCSS' => __( 'Restoring CSS', 'gp-premium' ),
'cleanUp' => __( 'Cleaning up', 'gp-premium' ),
'hasContentBackup' => ! empty( $backup_data['content'] ),
'confirmRemoval' => __( 'This process makes changes to your database. If you have existing data, be sure to create a backup as a precaution.', 'gp-premium' ),
)
);
wp_enqueue_style(
'generate-sites-admin',
GENERATE_SITES_URL . 'assets/css/admin.css',
array(),
GP_PREMIUM_VERSION
);
wp_enqueue_style(
'generate-premium-dashboard',
plugin_dir_url( dirname(__FILE__) ) . 'inc/assets/dashboard.css',
array(),
GP_PREMIUM_VERSION
);
}
add_filter( 'admin_body_class', 'generate_sites_do_admin_body_classes' );
/**
* Add a body class while in the Site Library.
*
* @since 1.8
*
* @param array Current body classes.
* @return array Existing and our new body classes
*/
function generate_sites_do_admin_body_classes( $classes ) {
if ( generate_is_sites_dashboard() ) {
$classes .= ' generate-sites';
}
return $classes;
}
add_action( 'generate_inside_site_library_container', 'generate_sites_add_tabs_wrapper_open', 4 );
/**
* Add an opening wrapper element for our Dashboard tabs and page builder links.
*
* @since 1.8
*/
function generate_sites_add_tabs_wrapper_open() {
echo '<div class="site-library-tabs-wrapper">';
}
/**
* Adds our Site dashboard container.
*
* @since 1.6
*/
function generate_sites_container() {
?>
<div class="generate-site-library">
<div class="site-library-header">
<div class="site-library-container">
<div class="library-title">
<?php _e( 'GeneratePress Site Library', 'gp-premium' ); ?>
</div>
<div class="library-links">
<a href="https://generatepress.com/support" target="_blank"><?php _e( 'Support', 'gp-premium' ); ?></a>
<a href="https://docs.generatepress.com" target="_blank"><?php _e( 'Documentation', 'gp-premium' ); ?></a>
</div>
</div>
</div>
<div class="site-library-container">
<?php
do_action( 'generate_inside_site_library_container' );
$site_data = get_transient( 'generatepress_sites' );
$page_builders = array();
foreach ( (array) $site_data as $data ) {
if ( isset( $data['page_builder'][0] ) ) {
$page_builder = $data['page_builder'][0];
$page_builder_id = str_replace( ' ', '-', strtolower( $page_builder ) );
if ( 'no-page-builder' !== $page_builder_id ) {
$page_builders[ $page_builder_id ] = $page_builder;
}
}
}
echo '<div class="library-filters">';
if ( ! empty( $page_builders ) ) : ?>
<div class="page-builder-filter">
<label for="page-builder" class="page-builder-label"><?php _e( 'Page Builder:', 'gp-premium' ); ?></label>
<div class="filter-select">
<select id="page-builder" class="page-builder-group" data-filter-group="page-builder" data-page-builder=".no-page-builder">
<option value="no-page-builder"><?php _e( 'None', 'gp-premium' ); ?></option>
<?php
foreach( $page_builders as $id => $name ) {
printf(
'<option value="%1$s">%2$s</option>',
$id,
$name
);
}
?>
</select>
</div>
</div>
<?php else : ?>
<div class="page-builder-filter">
<label for="page-builder" class="page-builder-label"><?php _e( 'Page Builder:', 'gp-premium' ); ?></label>
<div class="filter-select">
<select id="page-builder" class="page-builder-group" data-filter-group="page-builder" data-page-builder=".no-page-builder">
<option value="no-page-builder"><?php _e( 'None', 'gp-premium' ); ?></option>
<option value="beaver-builder"><?php _e( 'Beaver Builder', 'gp-premium' ); ?></option>
<option value="elementor"><?php _e( 'Elementor', 'gp-premium' ); ?></option>
</select>
</div>
</div>
<?php endif; ?>
</div>
</div> <!-- .site-library-tabs-wrapper -->
<?php // The opening wrapper for this is in generate_sites_add_tabs_wrapper_open() ?>
<?php
$backup_data = get_option( '_generatepress_site_library_backup', array() );
$show_remove_site = false;
if ( ! empty( $backup_data ) ) {
$show_remove_site = true;
}
?>
<div class="remove-site" style="<?php echo ! $show_remove_site ? 'display: none' : ''; ?>">
<h2><?php _e( 'Existing Site Import Detected', 'gp-premium' ); ?></h2>
<div class="remove-site-content">
<p><?php _e( 'It is highly recommended that you remove the last site you imported before importing a new one.', 'gp-premium' ); ?></p>
<p><?php _e( 'This process restores your previous options, widgets and active plugins. It will also remove your imported content and CSS.', 'gp-premium' ); ?></p>
</div>
<div class="remove-site-actions">
<button class="do-remove-site button-primary"><?php _e( 'Remove Imported Site', 'gp-premium' ); ?></button>
<a class="skip-remove-site" href="#"><?php _e( 'Skip', 'gp-premium' ); ?></a>
<div class="loading" style="display: none;">
<span class="remove-site-message"></span>
<?php GeneratePress_Sites_Helper::loading_icon(); ?>
</div>
</div>
</div>
<div class="generatepress-sites generatepress-admin-block <?php echo $show_remove_site ? 'remove-site-needed' : ''; ?>" id="sites" data-page-builder=".no-page-builder">
<?php do_action( 'generate_inside_sites_container' ); ?>
</div>
<?php
printf(
'<div class="refresh-sites">
<a class="button" href="%1$s">%2$s</a>
</div>',
wp_nonce_url( admin_url( 'themes.php?page=generatepress-site-library' ), 'refresh_sites', 'refresh_sites_nonce' ),
__( 'Refresh Sites', 'gp-premium' )
);
?>
</div>
</div>
<?php
}
add_action( 'admin_init', 'generate_sites_refresh_list', 2 );
/**
* Delete our sites transient if the Refresh sites link is clicked.
*
* @since 1.6
*/
function generate_sites_refresh_list() {
if ( ! isset( $_GET['refresh_sites_nonce'] ) || ! wp_verify_nonce( $_GET['refresh_sites_nonce'], 'refresh_sites' ) ) {
return;
}
delete_transient( 'generatepress_sites' );
}
/**
* Get our page header meta slugs.
*
* @since 1.6
*
* @return array
*/
function generate_sites_export_page_headers() {
$args = array(
'post_type' => get_post_types( array( 'public' => true ) ),
'showposts' => -1,
'meta_query' => array(
array(
'key' => '_generate-select-page-header',
'compare' => 'EXISTS',
)
)
);
$posts = get_posts( $args );
$new_values = array();
foreach ( $posts as $post ) {
$page_header_id = get_post_meta( $post->ID, '_generate-select-page-header', true );
if ( $page_header_id ) {
$new_values[$post->ID] = $page_header_id;
}
}
return $new_values;
}
/**
* Get our Element display locations.
*
* @since 1.7
*
* @return array
*/
function generate_sites_export_elements_location() {
$args = array(
'post_type' => 'gp_elements',
'showposts' => -1,
);
$posts = get_posts( $args );
$new_values = array();
foreach ( $posts as $post ) {
$display_conditions = get_post_meta( $post->ID, '_generate_element_display_conditions', true );
if ( $display_conditions ) {
$new_values[$post->ID] = $display_conditions;
}
}
return $new_values;
}
/**
* Get our Element display locations.
*
* @since 1.7
*
* @return array
*/
function generate_sites_export_elements_exclusion() {
$args = array(
'post_type' => 'gp_elements',
'showposts' => -1,
);
$posts = get_posts( $args );
$new_values = array();
foreach ( $posts as $post ) {
$display_conditions = get_post_meta( $post->ID, '_generate_element_exclude_conditions', true );
if ( $display_conditions ) {
$new_values[$post->ID] = $display_conditions;
}
}
return $new_values;
}
/**
* List out compatible theme modules Sites can activate.
*
* @since 1.6
*
* @return array
*/
function generatepress_get_site_premium_modules() {
return array(
'Backgrounds' => 'generate_package_backgrounds',
'Blog' => 'generate_package_blog',
'Colors' => 'generate_package_colors',
'Copyright' => 'generate_package_copyright',
'Elements' => 'generate_package_elements',
'Disable Elements' => 'generate_package_disable_elements',
'Hooks' => 'generate_package_hooks',
'Menu Plus' => 'generate_package_menu_plus',
'Page Header' => 'generate_package_page_header',
'Secondary Nav' => 'generate_package_secondary_nav',
'Sections' => 'generate_package_sections',
'Spacing' => 'generate_package_spacing',
'Typography' => 'generate_package_typography',
'WooCommerce' => 'generate_package_woocommerce',
);
}
/**
* Don't allow Sites to modify these options.
*
* @since 1.6
*
* @return array
*/
function generatepress_sites_disallowed_options() {
return array(
'admin_email',
'siteurl',
'home',
'blog_charset',
'blog_public',
'current_theme',
'stylesheet',
'template',
'default_role',
'mailserver_login',
'mailserver_pass',
'mailserver_port',
'mailserver_url',
'permalink_structure',
'rewrite_rules',
'users_can_register',
);
}
add_action( 'generate_export_items', 'generatepress_sites_add_export_checkbox' );
/**
* Add our GeneratePress Site export checkbox to the Export module.
*
* @since 1.7
*/
function generatepress_sites_add_export_checkbox() {
?>
<hr style="margin:10px 0;border-bottom:0;" />
<label>
<input type="checkbox" name="module_group[]" value="generatepress-site" />
<?php _ex( 'GeneratePress Site', 'Module name', 'gp-premium' ); ?>
</label>
<?php
}
add_filter( 'generate_export_data', 'generatepress_sites_do_site_options_export', 10, 2 );
/**
* Add to our export .json file.
*
* @since 1.6
*
* @param array $data The current data being exported.
* @return array Existing and extended data.
*/
function generatepress_sites_do_site_options_export( $data ) {
// Bail if we haven't chosen to export the Site.
if ( ! in_array( 'generatepress-site', $_POST['module_group'] ) ) {
return $data;
}
// Modules
$modules = generatepress_get_site_premium_modules();
$data['modules'] = array();
foreach ( $modules as $name => $key ) {
if ( 'activated' == get_option( $key ) ) {
$data['modules'][ $name ] = $key;
}
}
// Site options
$data['site_options']['nav_menu_locations'] = get_theme_mod( 'nav_menu_locations' );
$data['site_options']['custom_logo'] = wp_get_attachment_url( get_theme_mod( 'custom_logo' ) );
$data['site_options']['show_on_front'] = get_option( 'show_on_front' );
$data['site_options']['page_on_front'] = get_option( 'page_on_front' );
$data['site_options']['page_for_posts'] = get_option( 'page_for_posts' );
// Page header
$data['site_options']['page_header_global_locations'] = get_option( 'generate_page_header_global_locations' );
$data['site_options']['page_headers'] = generate_sites_export_page_headers();
// Elements
$data['site_options']['element_locations'] = generate_sites_export_elements_location();
$data['site_options']['element_exclusions'] = generate_sites_export_elements_exclusion();
// Custom CSS.
if ( function_exists( 'wp_get_custom_css_post' ) ) {
$data['custom_css'] = wp_get_custom_css_post()->post_content;
}
// WooCommerce.
if ( is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
$data['site_options']['woocommerce_shop_page_id'] = get_option( 'woocommerce_shop_page_id' );
$data['site_options']['woocommerce_cart_page_id'] = get_option( 'woocommerce_cart_page_id' );
$data['site_options']['woocommerce_checkout_page_id'] = get_option( 'woocommerce_checkout_page_id' );
$data['site_options']['woocommerce_myaccount_page_id'] = get_option( 'woocommerce_myaccount_page_id' );
$data['site_options']['woocommerce_single_image_width'] = get_option( 'woocommerce_single_image_width' );
$data['site_options']['woocommerce_thumbnail_image_width'] = get_option( 'woocommerce_thumbnail_image_width' );
$data['site_options']['woocommerce_thumbnail_cropping'] = get_option( 'woocommerce_thumbnail_cropping' );
$data['site_options']['woocommerce_shop_page_display'] = get_option( 'woocommerce_shop_page_display' );
$data['site_options']['woocommerce_category_archive_display'] = get_option( 'woocommerce_category_archive_display' );
$data['site_options']['woocommerce_default_catalog_orderby'] = get_option( 'woocommerce_default_catalog_orderby' );
}
// Elementor
if ( is_plugin_active( 'elementor/elementor.php' ) ) {
$data['site_options']['elementor_container_width'] = get_option( 'elementor_container_width' );
$data['site_options']['elementor_cpt_support'] = get_option( 'elementor_cpt_support' );
$data['site_options']['elementor_css_print_method'] = get_option( 'elementor_css_print_method' );
$data['site_options']['elementor_default_generic_fonts'] = get_option( 'elementor_default_generic_fonts' );
$data['site_options']['elementor_disable_color_schemes'] = get_option( 'elementor_disable_color_schemes' );
$data['site_options']['elementor_disable_typography_schemes'] = get_option( 'elementor_disable_typography_schemes' );
$data['site_options']['elementor_editor_break_lines'] = get_option( 'elementor_editor_break_lines' );
$data['site_options']['elementor_exclude_user_roles'] = get_option( 'elementor_exclude_user_roles' );
$data['site_options']['elementor_global_image_lightbox'] = get_option( 'elementor_global_image_lightbox' );
$data['site_options']['elementor_page_title_selector'] = get_option( 'elementor_page_title_selector' );
$data['site_options']['elementor_scheme_color'] = get_option( 'elementor_scheme_color' );
$data['site_options']['elementor_scheme_color-picker'] = get_option( 'elementor_scheme_color-picker' );
$data['site_options']['elementor_scheme_typography'] = get_option( 'elementor_scheme_typography' );
$data['site_options']['elementor_space_between_widgets'] = get_option( 'elementor_space_between_widgets' );
$data['site_options']['elementor_stretched_section_container'] = get_option( 'elementor_stretched_section_container' );
}
// Beaver Builder
if ( is_plugin_active( 'beaver-builder-lite-version/fl-builder.php' ) || is_plugin_active( 'bb-plugin/fl-builder.php' ) ) {
$data['site_options']['_fl_builder_enabled_icons'] = get_option( '_fl_builder_enabled_icons' );
$data['site_options']['_fl_builder_enabled_modules'] = get_option( '_fl_builder_enabled_modules' );
$data['site_options']['_fl_builder_post_types'] = get_option( '_fl_builder_post_types' );
$data['site_options']['_fl_builder_color_presets'] = get_option( '_fl_builder_color_presets' );
$data['site_options']['_fl_builder_services'] = get_option( '_fl_builder_services' );
$data['site_options']['_fl_builder_settings'] = get_option( '_fl_builder_settings' );
$data['site_options']['_fl_builder_user_access'] = get_option( '_fl_builder_user_access' );
$data['site_options']['_fl_builder_enabled_templates'] = get_option( '_fl_builder_enabled_templates' );
}
// Menu Icons
if ( is_plugin_active( 'menu-icons/menu-icons.php' ) ) {
$data['site_options']['menu-icons'] = get_option( 'menu-icons' );
}
// Ninja Forms
if ( is_plugin_active( 'ninja-forms/ninja-forms.php' ) ) {
$data['site_options']['ninja_forms_settings'] = get_option( 'ninja_forms_settings' );
}
// Social Warfare
if ( is_plugin_active( 'social-warfare/social-warfare.php' ) ) {
$data['site_options']['socialWarfareOptions'] = get_option( 'socialWarfareOptions' );
}
// Elements Plus
if ( is_plugin_active( 'elements-plus/elements-plus.php' ) ) {
$data['site_options']['elements_plus_settings'] = get_option( 'elements_plus_settings' );
}
// Ank Google Map
if ( is_plugin_active( 'ank-google-map/ank-google-map.php' ) ) {
$data['site_options']['ank_google_map'] = get_option( 'ank_google_map' );
}
// GP Social Share
if ( is_plugin_active( 'gp-social-share-svg/gp-social-share.php' ) ) {
$data['site_options']['gp_social_settings'] = get_option( 'gp_social_settings' );
}
// Active plugins
$active_plugins = get_option( 'active_plugins' );
$all_plugins = get_plugins();
$ignore = apply_filters( 'generate_sites_ignore_plugins', array(
'gp-premium/gp-premium.php',
'widget-importer-exporter/widget-importer-exporter.php'
) );
foreach ( $ignore as $plugin ) {
unset( $all_plugins[ $plugin ] );
}
$activated_plugins = array();
foreach ( $active_plugins as $p ) {
if ( isset( $all_plugins[$p] ) ) {
$activated_plugins[$all_plugins[$p]['Name']] = $p;
}
}
$data['plugins'] = $activated_plugins;
return $data;
}
add_action( 'current_screen', 'generatepress_sites_init', 5 );
/**
* Fetch our sites and trusted authors. Stores them in their own transients.
* We use current_screen instead of admin_init so we can check what admin page we're on.
*
* @since 1.6
*/
function generatepress_sites_init() {
$screen = get_current_screen();
if ( 'appearance_page_generate-options' === $screen->id || 'appearance_page_generatepress-site-library' === $screen->id ) {
$remote_sites = get_transient( 'generatepress_sites' );
$trusted_authors = get_transient( 'generatepress_sites_trusted_providers' );
if ( empty( $remote_sites ) ) {
$sites = array();
$data = wp_safe_remote_get( 'https://gpsites.co/wp-json/wp/v2/sites?per_page=100' );
if ( is_wp_error( $data ) ) {
set_transient( 'generatepress_sites', 'no results', 5 * MINUTE_IN_SECONDS );
return;
}
$data = json_decode( wp_remote_retrieve_body( $data ), true );
if ( ! is_array( $data ) ) {
set_transient( 'generatepress_sites', 'no results', 5 * MINUTE_IN_SECONDS );
return;
}
foreach( ( array ) $data as $site ) {
$sites[$site['name']] = array(
'name' => $site['name'],
'directory' => $site['directory'],
'preview_url' => $site['preview_url'],
'author_name' => $site['author_name'],
'author_url' => $site['author_url'],
'description' => $site['description'],
'page_builder' => $site['page_builder'],
'min_version' => $site['min_version'],
'uploads_url' => $site['uploads_url'],
'plugins' => $site['plugins'],
'documentation' => $site['documentation'],
);
}
$sites = apply_filters( 'generate_add_sites', $sites );
set_transient( 'generatepress_sites', $sites, 24 * HOUR_IN_SECONDS );
}
if ( empty( $trusted_authors ) ) {
$trusted_authors = wp_safe_remote_get( 'https://gpsites.co/wp-json/sites/site' );
if ( is_wp_error( $trusted_authors ) || empty( $trusted_authors ) ) {
set_transient( 'generatepress_sites_trusted_providers', 'no results', 5 * MINUTE_IN_SECONDS );
return;
}
$trusted_authors = json_decode( wp_remote_retrieve_body( $trusted_authors ), true );
$authors = array();
foreach ( ( array ) $trusted_authors['trusted_author'] as $author ) {
$authors[] = $author;
}
set_transient( 'generatepress_sites_trusted_providers', $authors, 24 * HOUR_IN_SECONDS );
}
}
}
add_action( 'plugins_loaded', 'generatepress_sites_output' );
/**
* Initiate our Sites once everything has loaded.
* We use current_screen instead of admin_init so we can check what admin page we're on.
*
* @since 1.6
*/
function generatepress_sites_output() {
if ( ! class_exists( 'GeneratePress_Site' ) ) {
return; // Bail if we don't have the needed class.
}
$sites = get_transient( 'generatepress_sites' );
if ( empty( $sites ) || ! is_array( $sites ) ) {
add_action( 'generate_inside_sites_container', 'generatepress_sites_no_results_error' );
return;
}
if ( apply_filters( 'generate_sites_randomize', true ) ) {
shuffle( $sites );
}
foreach( $sites as $site ) {
new GeneratePress_Site( $site );
}
}
/**
* Show an error message when no sites exist.
*
* @since 1.8.2
*/
function generatepress_sites_no_results_error() {
printf(
'<div class="no-site-library-results">
%1$s <a href="%3$s" target="_blank" rel="noopener noreferrer">%2$s</a>
</div>',
__( 'No sites found.', 'gp-premium' ),
__( 'Why?', 'gp-premium' ),
'https://docs.generatepress.com/article/site-library-unavailable/'
);
}