Add upstream

This commit is contained in:
root
2019-10-24 00:12:05 +02:00
parent 85d41e4216
commit ac980f592c
3504 changed files with 1049983 additions and 29971 deletions

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 91.3 91.1" enable-background="new 0 0 91.3 91.1" xml:space="preserve">
<circle cx="45.7" cy="45.7" r="45.7"/>
<circle fill="#FFFFFF" cx="45.7" cy="24.4" r="12.5"/>
</svg>

After

Width:  |  Height:  |  Size: 450 B

View File

@@ -0,0 +1,127 @@
@keyframes spin {
100% {
transform: rotate( 360deg );
}
}
body.udp-modal-is-opened {
overflow: hidden;
}
.udp-modal {
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index: 20000;
}
.udp-modal__overlay {
width: 100%;
height: 100%;
position: absolute;
background: #000;
opacity: 0.8;
z-index: 1;
}
.udp-modal__modal {
position: absolute;
z-index: 2;
left: 0;
top: 32px;
bottom: 0;
right: 0;
background: #FFF;
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.45882);
overflow: auto;
}
.udp-modal__content {
position: relative;
overflow: auto;
}
.udp-modal__content .img {
padding: 0 20px;
box-sizing: border-box;
text-align: center;
}
.udp-modal__content .img img {
max-width: 100%;
}
.udp-modal__content .text {
padding: 40px;
}
.udp-modal.loading {
background-image: url();
}
.udp-modal.loading::before {
height: 1em;
width: 1em;
display: block;
position: absolute;
top: 50%;
left: 50%;
margin-left: -0.5em;
margin-top: -0.5em;
content: '';
animation: spin 1s linear infinite;
background: url('loader.svg') center center;
background-size: cover;
line-height: 1;
text-align: center;
font-size: 2em;
color: #000;
z-index: 3;
opacity: 0.5;
}
.udp-modal.loading .udp-modal__content,
.udp-modal.loading .udp-modal__sidebar,
.iframe-is-opened .udp-modal__content,
.iframe-is-opened .udp-modal__sidebar {
display: none;
}
.udp-modal__iframe {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 3;
background: #FFF;
}
.udp-modal__iframe iframe {
position: absolute;
width: 100%;
height: 100%;
}
@media(min-width: 1200px) {
.udp-modal__modal {
left: 20px;
top: calc(20px + 32px);
bottom: 20px;
right: 20px;
}
}
@media(max-width: 782px) {
.udp-modal__modal {
top: 46px;
}
}

View File

@@ -0,0 +1,81 @@
(function($) {
var checkout_embed = {
loading: false,
init: function() {
var buttons = $('a[data-embed-checkout]');
if (!buttons.length) return;
var that = this;
$(document).on('click', 'a[data-embed-checkout]', function(e) {
e.preventDefault();
that.modal.open($(this));
});
},
modal: {
open: function($target) {
// if first time opening or different product
this.$target = $target;
if (!this.product_url || (this.product_url && this.product_url != $target.data('embed-checkout'))) {
this.product_url = $target.data('embed-checkout');
this.setup();
}
this.show_checkout();
// adds / remove classes
$('body').addClass('udp-modal-is-opened');
this.$el.removeClass('iframe-is-opened');
// Show it.
this.$el.appendTo('body').show();
window.scrollTo(0,0);
},
setup: function() {
if (this.$el) {
this.$el.remove();
this.$el = null;
}
var template = $('#udp-modal-template').html();
this.$el = $(template);
// receives events from iframe
window.addEventListener('message', function(event) {
var response = event.data;
if (response && response.action) {
switch (response.action) {
case 'domready':
this.$el.removeClass('loading');
break;
case 'closemodal':
$(document).trigger('udp/checkout/close', response.data, this.$target);
this.close();
break;
case 'ordercomplete':
console.log('Order complete:', response.data);
$(document).trigger('udp/checkout/done', response.data, this.$target);
break;
}
}
}.bind(this));
},
close: function(event) {
if (event) event.preventDefault();
$('body').removeClass('udp-modal-is-opened');
if (this.$iframe) {
this.$iframe.remove();
this.$iframe_container.remove();
}
this.$el.hide();
},
show_checkout: function() {
this.$el.addClass('loading iframe-is-opened');
this.$iframe = $('<iframe src="' + this.product_url + '"/>');
this.$iframe_container = $('<div class="udp-modal__iframe"/>').appendTo(this.$el.find('.udp-modal__modal')).append(this.$iframe);
}
}
}
$(document).ready(function(e) {
checkout_embed.init();
});
})(jQuery);

View File

@@ -0,0 +1,2 @@
@keyframes spin{100%{transform:rotate(360deg)}}body.udp-modal-is-opened{overflow:hidden}.udp-modal{position:fixed;top:0;left:0;bottom:0;right:0;z-index:20000}.udp-modal__overlay{width:100%;height:100%;position:absolute;background:#000;opacity:.8;z-index:1}.udp-modal__modal{position:absolute;z-index:2;left:0;top:32px;bottom:0;right:0;background:#FFF;box-shadow:0 4px 10px rgba(0,0,0,0.45882);overflow:auto}.udp-modal__content{position:relative;overflow:auto}.udp-modal__content .img{padding:0 20px;box-sizing:border-box;text-align:center}.udp-modal__content .img img{max-width:100%}.udp-modal__content .text{padding:40px}.udp-modal.loading{background-image:url()}.udp-modal.loading::before{height:1em;width:1em;display:block;position:absolute;top:50%;left:50%;margin-left:-0.5em;margin-top:-0.5em;content:'';animation:spin 1s linear infinite;background:url('loader.svg') center center;background-size:cover;line-height:1;text-align:center;font-size:2em;color:#000;z-index:3;opacity:.5}.udp-modal.loading .udp-modal__content,.udp-modal.loading .udp-modal__sidebar,.iframe-is-opened .udp-modal__content,.iframe-is-opened .udp-modal__sidebar{display:none}.udp-modal__iframe{position:absolute;top:0;left:0;right:0;bottom:0;z-index:3;background:#FFF}.udp-modal__iframe iframe{position:absolute;width:100%;height:100%}@media(min-width:1200px){.udp-modal__modal{left:20px;top:calc(20px + 32px);bottom:20px;right:20px}}@media(max-width:782px){.udp-modal__modal{top:46px}}
/*# sourceMappingURL=udp-checkout-embed.min.css.map */

View File

@@ -0,0 +1 @@
{"version":3,"sources":["includes/checkout-embed/assets/udp-checkout-embed.css"],"names":[],"mappings":"AAAA;;CAEC;EACC,4BAA4B;EAC5B;;CAED;;AAED;CACC,iBAAiB;CACjB;;AAED;CACC,gBAAgB;CAChB,OAAO;CACP,QAAQ;CACR,UAAU;CACV,SAAS;CACT,eAAe;CACf;;AAED;CACC,YAAY;CACZ,aAAa;CACb,mBAAmB;CACnB,iBAAiB;CACjB,aAAa;CACb,WAAW;CACX;;AAED;CACC,mBAAmB;CACnB,WAAW;CACX,QAAQ;CACR,UAAU;CACV,UAAU;CACV,SAAS;CACT,iBAAiB;CACjB,gDAAmC;CACnC,eAAe;CACf;;AAED;CACC,mBAAmB;CACnB,eAAe;CACf;;AAED;CACC,gBAAgB;CAChB,uBAAuB;CACvB,mBAAmB;CACnB;;AAED;CACC,gBAAgB;CAChB;;AAED;CACC,cAAc;CACd;;AAED;CACC,wBAAwB;CACxB;;AAED;CACC,YAAY;CACZ,WAAW;CACX,eAAe;CACf,mBAAmB;CACnB,SAAS;CACT,UAAU;CACV,oBAAoB;CACpB,mBAAmB;CACnB,YAAY;CAEZ,mCAAmC;CACnC,4CAA4C;CAC5C,uBAAuB;CACvB,eAAe;CACf,mBAAmB;CACnB,eAAe;CACf,YAAY;CACZ,WAAW;CACX,aAAa;CACb;;AAED;;;;CAIC,cAAc;CACd;;AAED;CACC,mBAAmB;CACnB,OAAO;CACP,QAAQ;CACR,SAAS;CACT,UAAU;CACV,WAAW;CACX,iBAAiB;CACjB;;AAED;CACC,mBAAmB;CACnB,YAAY;CACZ,aAAa;CACb;;AAED;;CAEC;EACC,WAAW;EACX,uBAAuB;EACvB,aAAa;EACb,YAAY;EACZ;;CAED;;AAED;;CAEC;EACC,UAAU;EACV;;CAED","file":"udp-checkout-embed.min.css","sourcesContent":["@keyframes spin {\n\n\t100% {\n\t\ttransform: rotate( 360deg );\n\t}\n\n}\n\nbody.udp-modal-is-opened {\n\toverflow: hidden;\n}\n\n.udp-modal {\n\tposition: fixed;\n\ttop: 0;\n\tleft: 0;\n\tbottom: 0;\n\tright: 0;\n\tz-index: 20000;\n}\n\n.udp-modal__overlay {\n\twidth: 100%;\n\theight: 100%;\n\tposition: absolute;\n\tbackground: #000;\n\topacity: 0.8;\n\tz-index: 1;\n}\n\n.udp-modal__modal {\n\tposition: absolute;\n\tz-index: 2;\n\tleft: 0;\n\ttop: 32px;\n\tbottom: 0;\n\tright: 0;\n\tbackground: #FFF;\n\tbox-shadow: 0px 4px 10px #00000075;\n\toverflow: auto;\n}\n\n.udp-modal__content {\n\tposition: relative;\n\toverflow: auto;\n}\n\n.udp-modal__content .img {\n\tpadding: 0 20px;\n\tbox-sizing: border-box;\n\ttext-align: center;\n}\n\n.udp-modal__content .img img {\n\tmax-width: 100%;\n}\n\n.udp-modal__content .text {\n\tpadding: 40px;\n}\n\n.udp-modal.loading {\n\tbackground-image: url();\n}\n\n.udp-modal.loading::before {\n\theight: 1em;\n\twidth: 1em;\n\tdisplay: block;\n\tposition: absolute;\n\ttop: 50%;\n\tleft: 50%;\n\tmargin-left: -0.5em;\n\tmargin-top: -0.5em;\n\tcontent: '';\n\t-webkit-animation: spin 1s linear infinite;\n\tanimation: spin 1s linear infinite;\n\tbackground: url('loader.svg') center center;\n\tbackground-size: cover;\n\tline-height: 1;\n\ttext-align: center;\n\tfont-size: 2em;\n\tcolor: #000;\n\tz-index: 3;\n\topacity: 0.5;\n}\n\n.udp-modal.loading .udp-modal__content,\n.udp-modal.loading .udp-modal__sidebar,\n.iframe-is-opened .udp-modal__content,\n.iframe-is-opened .udp-modal__sidebar {\n\tdisplay: none;\n}\n\n.udp-modal__iframe {\n\tposition: absolute;\n\ttop: 0;\n\tleft: 0;\n\tright: 0;\n\tbottom: 0;\n\tz-index: 3;\n\tbackground: #FFF;\n}\n\n.udp-modal__iframe iframe {\n\tposition: absolute;\n\twidth: 100%;\n\theight: 100%;\n}\n\n@media(min-width: 1200px) {\n\n\t.udp-modal__modal {\n\t\tleft: 20px;\n\t\ttop: calc(20px + 32px);\n\t\tbottom: 20px;\n\t\tright: 20px;\n\t}\n\n}\n\n@media(max-width: 782px) {\n\n\t.udp-modal__modal {\n\t\ttop: 46px;\n\t}\n\n}"]}

View File

@@ -0,0 +1 @@
!function(e){var t={loading:!1,init:function(){var t=e("a[data-embed-checkout]");if(t.length){var o=this;e(document).on("click","a[data-embed-checkout]",function(t){t.preventDefault(),o.modal.open(e(this))})}},modal:{open:function(t){this.$target=t,(!this.product_url||this.product_url&&this.product_url!=t.data("embed-checkout"))&&(this.product_url=t.data("embed-checkout"),this.setup()),this.show_checkout(),e("body").addClass("udp-modal-is-opened"),this.$el.removeClass("iframe-is-opened"),this.$el.appendTo("body").show(),window.scrollTo(0,0)},setup:function(){this.$el&&(this.$el.remove(),this.$el=null);var t=e("#udp-modal-template").html();this.$el=e(t),window.addEventListener("message",function(t){var o=t.data;if(o&&o.action)switch(o.action){case"domready":this.$el.removeClass("loading");break;case"closemodal":e(document).trigger("udp/checkout/close",o.data,this.$target),this.close();break;case"ordercomplete":console.log("Order complete:",o.data),e(document).trigger("udp/checkout/done",o.data,this.$target)}}.bind(this))},close:function(t){t&&t.preventDefault(),e("body").removeClass("udp-modal-is-opened"),this.$iframe&&(this.$iframe.remove(),this.$iframe_container.remove()),this.$el.hide()},show_checkout:function(){this.$el.addClass("loading iframe-is-opened"),this.$iframe=e('<iframe src="'+this.product_url+'"/>'),this.$iframe_container=e('<div class="udp-modal__iframe"/>').appendTo(this.$el.find(".udp-modal__modal")).append(this.$iframe)}}};e(document).ready(function(e){t.init()})}(jQuery);

View File

@@ -0,0 +1,124 @@
<?php
if (!defined('ABSPATH')) die('No direct access.');
/**
* Class UDP_Checkout_Embed
*
* Create links to embed an external checkout page
*/
if (!class_exists('Updraft_Checkout_Embed')) {
class Updraft_Checkout_Embed {
/**
* Class version
*
* @var string
*/
private static $version = '1.0.0';
/**
* Products list
*
* @var array
*/
public $products = array();
/**
* Construct
*
* @param string $plugin_name Current plugin using the class
* @param string $return_url The return URL after purchase is complete / canceled. Specially useful with paypal, that forces a redirect.
* @param array $products_list The list of products. Array or object that can be converted to an array
* @param string $base_url The plugin url, to where 'checkout-embed' is located. Used to enqueue scripts and styles.
* @param array $load_in_pages Pages in which the scripts are included. Use to limit the inclusion if necessary. See $this->enqueue_scripts
*/
public function __construct($plugin_name, $return_url, $products_list, $base_url, $load_in_pages = null) {
$this->plugin_name = sanitize_key($plugin_name);
$this->return_url = $return_url;
$this->products_list = $products_list;
$this->load_in_pages = $load_in_pages;
$this->base_url = $base_url;
add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
add_action('admin_footer', array($this, 'print_template'));
}
/**
* Get the product using its slug
*
* @param string $product_slug
* @param string $return_url
* @return string|bool
*/
public function get_product($product_slug, $return_url = '') {
$products = $this->get_products();
if (empty($products)) return false;
if (is_object($products)) $products = get_object_vars($products);
if (is_array($products) && array_key_exists($product_slug, $products)) {
if (!$return_url) $return_url = $this->return_url;
$return_url = add_query_arg($this->plugin_name.'_product', $product_slug, $return_url);
return apply_filters(
$this->plugin_name.'_return_url',
add_query_arg(
array(
$this->plugin_name.'_return_url' => urlencode($return_url),
'checkout_embed_product_slug' => $product_slug
),
$products[$product_slug]
),
$product_slug
);
}
return false;
}
/**
* Get the products on the remote url
* Can return an object, if the products list given to the class is. (eg. json_decode gives an object if not specified otherwise)
*
* @return array|object
*/
private function get_products() {
return apply_filters($this->plugin_name.'_checkout_embed_get_products', $this->products_list ? $this->products_list : array());
}
/**
* Enqueue the required scripts / styles
*
* @param string $hook
*/
public function enqueue_scripts($hook) {
if (is_array($this->load_in_pages)) {
if (!in_array($hook, $this->load_in_pages)) {
return;
}
}
wp_enqueue_script($this->plugin_name.'-checkout-embed', trailingslashit($this->base_url).'checkout-embed/assets/udp-checkout-embed.js', array('jquery'), self::$version, true);
wp_enqueue_style($this->plugin_name.'-checkout-embed', trailingslashit($this->base_url).'checkout-embed/assets/udp-checkout-embed.css', null, self::$version);
}
/**
* Print the template for the modal
*/
public function print_template() {
if (is_array($this->load_in_pages)) {
$screen = get_current_screen();
if (!in_array($screen->base, $this->load_in_pages)) {
return;
}
}
?>
<div style="display: none;" id="udp-modal-template">
<div class="udp-modal">
<div class="udp-modal__overlay"></div>
<div class="udp-modal__modal">
</div>
</div>
</div>
<?php }
}
}

View File

@@ -0,0 +1 @@
{"updraftpremium":"https:\/\/updraftplus.com\/shop\/updraftplus-premium\/?udp_checkout_embed=1&product_id=230&utm_source=updraftplus.com&utm_medium=in-plugin-purchase&utm_campaign=startup&utm_content=updraftpremium","updraftplus-vault-storage-5-gb":"https:\/\/updraftplus.com\/shop\/updraftplus-vault-storage-5-gb\/?udp_checkout_embed=1&product_id=123680&utm_source=updraftplus.com&utm_medium=in-plugin-purchase&utm_campaign=startup&utm_content=updraftplus-vault-storage-5-gb","updraftplus-vault-storage-15-gb":"https:\/\/updraftplus.com\/shop\/updraftplus-vault-storage-15-gb\/?udp_checkout_embed=1&product_id=123688&utm_source=updraftplus.com&utm_medium=in-plugin-purchase&utm_campaign=startup&utm_content=updraftplus-vault-storage-15-gb","updraftplus-vault-storage-50-gb":"https:\/\/updraftplus.com\/shop\/updraftplus-vault-storage-50-gb\/?udp_checkout_embed=1&product_id=123692&utm_source=updraftplus.com&utm_medium=in-plugin-purchase&utm_campaign=startup&utm_content=updraftplus-vault-storage-50-gb","updraftplus-vault-storage-250-gb":"https:\/\/updraftplus.com\/shop\/updraftplus-vault-storage-250-gb\/?udp_checkout_embed=1&product_id=383555&utm_source=updraftplus.com&utm_medium=in-plugin-purchase&utm_campaign=startup&utm_content=updraftplus-vault-storage-250-gb"}

View File

@@ -0,0 +1,49 @@
# Embed the plugin's checkout page
## To use in a new plugin:
- Include and instanciate `Updraft_Checkout_Embed`
```php
if (!class_exists('Updraft_Checkout_Embed')) include_once (UPDRAFTPLUS_DIR.'/includes/checkout-embed/class-udp-checkout-embed.php');
global $udp_checkout_embed;
$udp_checkout_embed = new Updraft_Checkout_Embed(
'updraftplus'
$data_url,
$load_in_pages
);
```
### Params:
- $plugin_name: (string) Current plugin using the class
- $proructs_data_url: (string) url of the merchand website (eg: https://https://updraftplus.com)
- $load_in_pages: (array) pages on which the script + css will be loaded
### Cache:
The products data is cached and expires after 7 days. To force fetching it, add `udp-force-product-list-refresh=1` to the admin page url
## Using in the admin
- Once the php is setup, you can configure the links / buttons in the admin.
Add `data-embed-checkout="{$url}"` to any link. eg:
```php
global $updraftplus_checkout_embed;
$link_data_attr = $updraftplus_checkout_embed->get_product('updraftpremium') ? 'data-embed-checkout="'.apply_filters('updraftplus_com_link', $updraftplus_checkout_embed->get_product('updraftpremium')).'"' : '';
<a target="_blank" title="Upgrade to Updraft Premium" href="<?php echo apply_filters('updraftplus_com_link', "https://updraftplus.com/shop/updraftplus-premium/");?>" <?php echo $link_data_attr; ?>><?php _e('get it here', 'updraftplus');?></a>
```
- On completion (when the order is complete), the event 'udp/checkout/done' is triggered.
- The event 'udp/checkout/close' is triggered when the user closes the modal, regardless of success.
Use this to do something with the data received:
```javascript
$(document).on('udp/checkout/done', function(event, data, $element) {
// ... do something with data, currently data.email and data.order_number
// $element clicked to open the modal.
});
```