Commit inicial - WordPress Análisis de Precios Unitarios

- WordPress core y plugins
- Tema Twenty Twenty-Four configurado
- Plugin allow-unfiltered-html.php simplificado
- .gitignore configurado para excluir wp-config.php y uploads

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-11-03 21:04:30 -06:00
commit a22573bf0b
24068 changed files with 4993111 additions and 0 deletions

View File

@@ -0,0 +1,198 @@
<?php
/**
* The file contains a class and a set of helper methods to manage licensing.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package onepress-api
*/
add_action('onp_api_320_plugin_created', 'onp_api_320_plugin_created');
function onp_api_320_plugin_created( $plugin ) {
$manager = new OnpApi320_Manager( $plugin );
$plugin->api = $manager;
}
/**
* The API Manager class.
*
* @since 1.0.0
*/
class OnpApi320_Manager {
/**
* A plugin for which the manager was created.
*
* @since 1.0.0
* @var Factory325_Plugin
*/
public $plugin;
/**
* An API server entry point.
*
* @since 1.0.0
* @var string
*/
public $entryPoint;
/**
* Createas a new instance of the license api for a given plugin.
*
* @since 1.0.0
*/
public function __construct( $plugin ) {
$this->plugin = $plugin;
$this->entryPoint = $plugin->options['api'];
add_action('init', array($this, 'verifyRequest'));
add_action('init', array($this, 'actionFromApiSever'));
}
// -------------------------------------------------------------------------------------
// Domain verification
// -------------------------------------------------------------------------------------
/**
* Verifies input requests from the Licensing Server.
*
* @since 1.0.0
* @return void
*/
public function verifyRequest() {
$gateToken = isset( $_GET['onp_gate_token'] ) ? $_GET['onp_gate_token'] : null;
if ( empty($gateToken) ) return;
$expectedToken = get_option('onp_gate_token');
$tokenExpired = (int)get_option('onp_gate_expired');
if ( time() > $tokenExpired ) {
echo "expired";
exit;
}
if ( $expectedToken != $gateToken ) {
echo "invalid_token";
exit;
}
echo $gateToken . '_valid_ok';
exit;
}
/**
* Opens a callback gate to verfy site permissions to manage a domain.
*
* @since 1.0.0
* @return string
*/
public function openVerificationGate() {
$token = md5(rand(0, 10000));
update_option('onp_gate_token', $token);
update_option('onp_gate_expired', time() + (60 * 60));
return $token;
}
/**
* Checks a current api action.
*/
public function actionFromApiSever() {
$action = isset( $_GET['onp_action'] ) ? $_GET['onp_action'] : null;
if ( !in_array($action, array('deactivate-key')) ) return;
$siteSecret = isset( $_GET['onp_site_secret'] ) ? $_GET['onp_site_secret'] : null;
if ( $siteSecret != get_option( 'onp_site_secret', null ) ) return;
do_action('onp_api_action_' . $action );
}
// -------------------------------------------------------------------------------------
// Sending requests
// -------------------------------------------------------------------------------------
/**
* Sends a request to an API Server.
*
* @param string $url Url to send a request
* @param mixed $args Http request arguments
* @param mixed $args Extra options
* @return \WP_Error
*/
private function _request( $url, $args = array(), $options = array() ) {
$response = @wp_remote_request ($url, $args);
if ( is_wp_error($response) ) {
if ( $response->get_error_code() == 'http_request_failed')
return new WP_Error(
'HTTP:' . $response->get_error_code(),
'The Licensing Server is not found or busy at the moment.' );
return new WP_Error( 'HTTP:' . $response->get_error_code(), $response->get_error_message() );
}
$response_code = wp_remote_retrieve_response_code( $response );
$response_message = wp_remote_retrieve_response_message( $response );
if ( $response_code >= 500 && $response_code <= 510 )
return new WP_Error( 'API:InternalError', 'An unexpected error occurred during the request. Please contact OnePress support.' );
// checks http errors
if ( 200 != $response_code && ! empty( $response_message ) )
return new WP_Error( 'HTTP:' . $response_code, $response_message );
elseif ( 200 != $response_code )
return new WP_Error( 'HTTP:' . $response_code, 'Unknown error occurred' );
// check server errors
$data = json_decode( $response['body'], true );
if ( isset( $data['SiteSecret'] ) && !empty( $data['SiteSecret'] ) ) {
update_option('onp_site_secret', $data['SiteSecret']);
}
if ( isset( $data['ErrorCode'] ) )
return new WP_Error( 'API:' . $data['ErrorCode'], $data['ErrorText'] );
return $data;
}
/**
* Sends a post request to an API Server.
*
* @param string $action Action to perform
* @param mixed $args Http request arguments
* @param mixed $args Extra options
* @return \WP_Error
*/
public function request( $action, $args = array(), $options = array() ) {
$url = $this->entryPoint . $action;
if ( !isset($args['method'] ) )$args['method'] = 'POST';
if ( !isset($args['timeout'] ) ) $args['timeout'] = 60;
if ( !isset($args['body']) ) $args['body'] = array();
if ( !isset( $args['skipBody']) || !$args['skipBody'] ) {
if ( !isset( $args['body']['secret'] ) ) $args['body']['secret'] = get_option('onp_site_secret', null);
if ( !isset( $args['body']['site'] ) ) $args['body']['site'] = site_url();
if ( !isset( $args['body']['key'] ) ) $args['body']['key'] = isset( $this->plugin->license ) ? $this->plugin->license->key : null;
if ( !isset( $args['body']['plugin'] ) ) $args['body']['plugin'] = $this->plugin->pluginName;
if ( !isset( $args['body']['assembly'] ) ) $args['body']['assembly'] = $this->plugin->build;
if ( !isset( $args['body']['version'] ) ) $args['body']['version'] = $this->plugin->version;
if ( !isset( $args['body']['tracker'] ) ) $args['body']['tracker'] = $this->plugin->tracker;
if ( !isset( $args['body']['embedded'] ) )
$args['body']['embedded'] = ( isset( $this->plugin->license ) && $this->plugin->license->isEmbedded() ) ? 'true' : 'false';
if ( defined('FACTORY_BETA') && FACTORY_BETA ) $args['body']['beta'] = 'true';
$secretToken = $this->openVerificationGate();
$args['body']['secretToken'] = $secretToken;
}
return $this->_request($url, $args, $options);
}
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* OnePress API
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2014, OnePress Ltd
*
* @package onepress-api
*/
// Checks if the one is already loaded.
// We prevent to load the same version of the module twice.
if (defined('ONP_API_320_LOADED')) return;
define('ONP_API_320_LOADED', true);
// Absolute path for the files and resources of the module.
define('ONP_API_320_DIR', dirname(__FILE__));
include(ONP_API_320_DIR. '/api.php');

View File

@@ -0,0 +1,565 @@
.not-visible-in-manager {
display: none;
}
/**
* Global License Message
*/
.global-license-message {
width: 600px;
margin: auto;
margin-top: 100px;
font-size: 14px;
line-height: 170%;
}
.global-license-message h2, .global-license-message h3 {
padding: 0px;
margin: 5px 0;
}
.onp-page-wrap {
max-width: 720px;
margin: auto;
margin-top: 40px;
font-size: 14px;
line-height: 170%;
}
.onp-container {
border: 0px;
padding: 0px;
border-radius: 5px;
background: rgb(255,255,255) !important;
box-shadow: 0 0 15px rgba(0,0,0,0.2);
-moz-box-sizing: border-box;
box-sizing: border-box;
}
#license-manager .onp-container {
background: -moz-linear-gradient(top, rgba(255,255,255,1) 63%, rgba(246,246,246,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(63%,rgba(255,255,255,1)), color-stop(100%,rgba(246,246,246,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(255,255,255,1) 63%,rgba(246,246,246,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(255,255,255,1) 63%,rgba(246,246,246,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(255,255,255,1) 63%,rgba(246,246,246,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(255,255,255,1) 63%,rgba(246,246,246,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#f6f6f6',GradientType=0 ); /* IE6-9 */
}
.onp-container h2 {
margin: 0px;
padding: 0px;
}
.onp-container p {
margin: 0 0 2px 0;
padding: 0px;
line-height: 170%;
}
.btn-uppercase {
font-size: 12px;
letter-spacing: 1px;
text-transform: uppercase;
text-decoration: none;
}
.btn-uppercase *[class^=icon] {
position: relative;
top: -1px;
left: -1px;
}
.onp-page-wrap .license-message {
margin-bottom: 20px;
overflow: hidden;
}
.onp-page-wrap .license-message .alert {
margin: 0px;
}
.onp-page-wrap .license-message strong {
display: block;
margin-bottom: 0px;
}
.onp-page-wrap .license-message p {
margin: 1px 0 1px 0;
padding: 0px;
}
.onp-page-wrap .license-message a {
font-weight: bold;
}
.license-message .alert-warning-icon {
padding-left: 60px;
background-image: url("../img/warning.png");
background-position: 15px 11px;
background-repeat: no-repeat;
}
#onp-hide-license-manager {
position: absolute;
top: 2px;
right: 15px;
font-size: 12px;
color: #777;
font-weight: bold;
}
#onp-hide-license-manager:hover {
text-decoration: none;
}
#onp-hide-license-manager,
#onp-hide-license-manager:focus,
#onp-hide-license-manager:hover {
outline: none;
border: 0px;
box-shadow: none;
}
#onp-hide-license-manager .fa {
margin-right: 5px;
}
#license-manager .license-details-wrap {
border: 1px solid #e9e9e9;
padding: 0px;
border-radius: 5px;
background: rgb(255,255,255); /* Old browsers */
background: -moz-linear-gradient(top, rgba(255,255,255,1) 63%, rgba(246,246,246,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(63%,rgba(255,255,255,1)), color-stop(100%,rgba(246,246,246,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(255,255,255,1) 63%,rgba(246,246,246,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(255,255,255,1) 63%,rgba(246,246,246,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(255,255,255,1) 63%,rgba(246,246,246,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(255,255,255,1) 63%,rgba(246,246,246,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#f6f6f6',GradientType=0 ); /* IE6-9 */
box-shadow: 0px 2px 1px #c9c9c9;
}
#license-manager .activate-trial-hint {
background-color: #f8f8f8;
padding: 2px 9px;
width: 100%;
position: relative;
margin-left: -9px;
-moz-box-sizing: content-box;
box-sizing: content-box;
}
#license-manager .license-details {
padding: 20px;
padding-bottom: 0px;
-webkit-border-top-left-radius: 5px;
-webkit-border-top-right-radius: 5px;
-moz-border-radius-topleft: 5px;
-moz-border-radius-topright: 5px;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
position: relative;
z-index: 10;
}
#license-manager .licanse-key-identity {
font-style: italic;
position: relative;
top: -14px;
}
#license-manager .licanse-key-description {
font-size: 12px;
}
#license-manager .license-delete-button {
float: right;
text-decoration: none;
position: relative;
top: -7px;
left: 10px;
}
#license-manager .license-details-block {
padding: 28px 35px 15px 35px;
margin-left: -35px;
width: 100%;
position: relative;
margin-top: 20px;
background: #fff;
border: 0px;
box-shadow: 0 2px 8px rgba(0,0,0,0.2);
color: #333;
border-radius: 5px;
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
}
#license-manager .license-details-block p + p {
margin-top: 10px;
}
#license-manager .license-details-block a {
font-weight: bold;
}
#license-manager .license-details-block.trial-details-block {
background: #ffdede;
border: 0;
box-shadow: 0 0 7px #cf4944;
color: #a04342;
text-shadow: 1px 1px 2px #fff2f2;
}
#license-manager .license-details-block.trial-details-block a {
color: #a04342;
}
#license-manager .license-details-block.paid-details-block {
border: 0;
box-shadow: 0 0 7px #b8823b;
color: #8a6d3b;
background: #fcf8e3;
}
#license-manager .license-details-block.paid-details-block a {
color: #7a4c00;
}
#license-manager .license-details-block.gift-details-block {
background: #DFF0D8;
border: 1px solid #D6E9C6;
box-shadow: 0px 0px 5px #D6E9C6;
color: #468847;
}
#license-manager .license-details-block.gift-details-block a {
color: #468847;
}
#license-manager .license-params {
margin-top: 15px;
position: relative;
left: -2px;
}
#license-manager .license-value {
display: block;
font-size: 16px;
font-weight: bold;
}
#license-manager .license-value small {
font-weight: normal;
}
#license-manager .license-value-name {
display: block;
font-size: 12px;
}
#license-manager .license-param {
white-space: nowrap;
line-height: 130%;
padding: 10px 0 10px 35px;
vertical-align: top;
}
#license-manager .license-param-domain {
padding-left: 65px;
background: url('../img/free-license-chip.png') -3px 0px no-repeat;
}
#license-manager .trial-details-block .license-param-domain {
background: url('../img/trial-license-chip.png') -3px 0px no-repeat;
}
#license-manager .paid-details-block .license-param-domain {
background: url('../img/paid-license-chip.png') -3px 0px no-repeat;
}
#license-manager .license-details-block h3 {
margin: 0px;
padding: 0px;
font-size: 22px;
margin-bottom: 10px;
}
#license-manager .license-details-block a {
color: #a04342;
}
#license-manager .license-input {
padding: 20px;
-webkit-border-bottom-right-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
-moz-border-radius-bottomright: 5px;
-moz-border-radius-bottomleft: 5px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px;
}
#license-manager .license-input .btn {
text-decoration: none;
}
#license-manager .license-key-wrap {
padding-right: 110px;
}
#license-key {
width: 100%;
position: relative;
font-size: 18px;
line-height: 20px;
position: relative;
top: -1px;
height: 36px;
color: #000;
}
#license-submit {
float: right;
padding: 7px 14px 6px 14px;
}
#plugin-update-block {
padding-top: 10px;
font-size: 10px;
color: #666;
max-width: 700px;
margin: auto;
}
#plugin-update-block a {
color: #000;
}
#purchase-premium {
float: right;
position: relative;
top: -11px;
left: 8px;
text-decoration: none;
font-weight: bold;
background: #fffaea;
padding: 0px;
border-radius: 4px;
outline: none;
margin-top: 4px;
box-shadow: 0 0 8px #fddf67;
}
#purchase-premium .fa {
position: relative;
margin-right: 3px;
margin-left: 3px;
}
/*
* Manual Trial Activation
*/
#trial-manual .onp-container {
padding: 20px;
overflow: hidden;
}
#trial-manual ul {
margin: 0px;
padding: 0px;
margin-top: 10px;
}
#trial-manual ul li {
margin-bottom: 10px;
}
#trial-manual .license-reponse-code {
width: 100%;
height: 150px;
margin-top: 5px;
}
/*
* Manual Key Activation
*/
#activate-key-manual .onp-container {
padding: 20px;
overflow: hidden;
}
#activate-key-manual ul {
margin: 0px;
padding: 0px;
margin-top: 10px;
}
#activate-key-manual ul li {
margin-bottom: 10px;
}
#activate-key-manual .license-reponse-code {
width: 100%;
height: 150px;
margin-top: 5px;
}
/**
* FAQ
*/
#faq-block {
border-top: 1px solid #d7d7d7;
margin-top: 20px;
width: 100%;
padding: 10px 20px;
position: relative;
}
#faq-block .faq-header {
border-bottom: 1px dotted #333;
display: inline-block;
cursor: pointer;
font-weight: bold;
line-height: 16px;
font-size: 13px;
color: #333;
}
#faq-block .faq-header:hover {
border-bottom: 0px;
}
#faq-block .faq-header:focus, #faq-block .faq-header:active {
outline: 0;
}
#faq-block li > div {
display: none;
}
#faq-block p {
margin: 6px 0 10px 0;
font-size: 13px;
line-height: 170%;
}
#open-faq {
color: #000 !important;
text-decoration: none;
border-bottom: 1px dotted #000;
margin-left: 4px;
}
#open-faq:hover {
border-bottom: 0px;
}
.gray-link, .gray-link a {
color: #666666 !important;
}
/**
* A form to create a customer account
*/
.onp-single-block .onp-header {
text-align: center;
padding: 10px;
}
.onp-single-block .onp-header h4 {
font-size: 26px;
line-height: 130%;
}
.onp-single-block .onp-container {
padding: 50px 60px;
border: 1px solid #bbb;
position: relative;
}
.onp-single-block .onp-container .onp-container-header {
margin-bottom: 20px;
}
.onp-single-block .onp-container .onp-container-header h4 {
color: #000;
margin: 0px;
font-size: 20px;
}
.onp-single-block .onp-container .onp-container-header .onp-key-info {
color: #666;
}
.onp-single-block .onp-container .onp-container-header .onp-key-info .fa {
color: #777;
}
.onp-single-block .onp-container .onp-container-header .onp-icon {
position: absolute;
top: 30px;
right: 30px;
}
.onp-single-block .onp-container p,
.onp-single-block .onp-container li {
color: #333;
font-size: 14px;
}
.onp-single-block .onp-container p + p {
margin-top: 15px;
}
.onp-single-block .onp-container .onp-form {
text-align: left;
padding: 10px 0 0 0;
}
.onp-single-block #email {
font-size: 26px;
line-height: 26px;
height: 50px;
}
.onp-single-block .checkbox {
padding-left: 25px;
color: #999;
font-style: italic;
}
.onp-single-block .checkbox input {
margin-left: -25px;
}
.onp-single-block .onp-actions {
padding-top: 20px;
}
.onp-single-block .onp-actions .btn-primary {
margin-right: 15px;
}
.onp-single-block .onp-actions a.onp-cancel {
text-decoration: none;
color: #111;
}
.onp-single-block .onp-actions a.onp-cancel:hover {
text-decoration: none;
border-bottom: 1px solid #111;
background-color: #f9f9f9;
}
.onp-single-block .onp-benefits {
padding-left: 25px;
margin-top: 15px;
list-style: initial;
}
.onp-single-block .onp-login-details {
}
.onp-single-block .onp-text-seporator {
border-top: 1px solid #eee;
margin: 30px 0;
}
#create-account .onp-container {
background: #fff url("../img/create-account-bg.png") no-repeat 370px 230px !important;
}
#account-created .onp-step {
overflow: hidden;
}
#account-created .onp-steps {
padding: 25px 0 20px 10px;
}
#account-created .onp-step + .onp-step {
margin-top: 20px;
}
#account-created .onp-step .onp-num {
font-size: 25px;
line-height: 40px;
background-color: #f5f5f5;
width: 40px;
height: 40px;
display: inline-block;
border-radius: 7px;
text-align: center;
-moz-box-sizing: border-box;
box-sizing: border-box;
margin-right: 10px;
vertical-align: middle;
font-weight: bolder;
font-family: Arial, sans-serif;
}
#account-created .onp-step .onp-desc {
width: 490px;
display: inline-block;
vertical-align: middle;
line-height: 150%;
}
#finish .onp-container {
background: #fff url("../img/finish.png") no-repeat 0 -90px !important;
padding-left: 260px;
min-height: 250px;
border-bottom: 3px solid #ccc;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@@ -0,0 +1,23 @@
/**
* Factory Licensing Functions
*
* Defines a set of function that are used to check a license during development process.
* When a plugin is compiled, these functions are removed.
*/
function factory_license( license ) {
var current = factory_get_current_license();
return jQuery.isArray(license)
? jQuery.inArray(current, license)
: license == current;
}
/**
* Returns current license type.
* @return string
*/
function factory_get_current_license() {
if ( !window.factory_license_type ) return 'free';
return window.factory_license_type;
}

View File

@@ -0,0 +1,54 @@
var licenseManager = {};
(function($){
licenseManager = {
init: function() {
this.initLicenseForm();
this.initManualActivationForm();
},
initLicenseForm: function() {
var button = $("#license-submit");
var form = button.parents('form');
button.click(function(){
form.submit();
return false;
});
// faq
$("#faq-block .faq-header").click(function(){
var next = $(this).next();
if ( next.is(":visible") ) next.fadeOut();
else next.fadeIn();
return false;
});
$("#open-faq").click(function(){
$("#how-to-find-the-key").click();
window.location.href = "#how-to-find-the-key";
return false;
});
},
initManualActivationForm: function() {
var button = $("#manual-trial-submit");
var form = button.parents('form');
button.click(function(){
form.submit();
return false;
});
}
}
$(function(){
licenseManager.init();
});
})(jQuery)

View File

@@ -0,0 +1,83 @@
var registrationManager = {};
(function($){
registrationManager = {
init: function() {
this.makeRequest();
},
makeRequest: function() {
var self = this;
$.ajax(licenseServer, {
data: licenseGateData,
type: 'post',
dataType: 'jsonp'
})
.success(function( data ){
if ( data.ErrorCode ) {
self.showRejectedResponse( data );
return;
}
self.saveSecret(data.secret);
})
.error(function(){
self.showFailedResponse();
});
},
saveSecret: function( secret ) {
$.ajax(licenseAdminUrl, {
type: 'post',
data: {
secret: secret,
action: 'save_site_secret'
}
})
.success(function( data ){
if ( data != 'ok' ) {
alert(data);
return;
}
if ( !licenseRedirect || licenseRedirect == '' ) {
window.location.reload();
} else {
window.location.href = licenseRedirect;
}
})
.error(function(){
alert('unknown error');
});
},
showRejectedResponse: function( data ) {
var wrap = $("#license-registration-rejected");
var messageContainer = wrap.find(".error-container");
messageContainer.html( data.ErrorText );
this.hideLoader();
wrap.fadeIn();
},
showFailedResponse: function() {
this.hideLoader();
$("#license-registration-failed").fadeIn();
},
hideLoader: function() {
$(".license-global-loader").hide();
}
}
$(function(){
registrationManager.init();
});
})(jQuery)

View File

@@ -0,0 +1,23 @@
<?php
/**
* OnePress Licensing
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package core
* @since 1.0.0
*/
// Checks if the one is already loaded.
// We prevent to load the same version of the module twice.
if (defined('ONP_LICENSING_325_LOADED')) return;
define('ONP_LICENSING_325_LOADED', true);
// Absolute path and URL to the files and resources of the module.
define('ONP_LICENSING_325_DIR', dirname(__FILE__));
define('ONP_LICENSING_325_URL', plugins_url(null, __FILE__ ));
include(ONP_LICENSING_325_DIR. '/licensing.php');
if ( !is_admin() ) return;
include(ONP_LICENSING_325_DIR. '/includes/license-manager.class.php');

View File

@@ -0,0 +1,900 @@
<?php
/**
* The file contains a class and a set of helper methods to manage licensing.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package core
* @since 1.0.0
*/
// creating a license manager for each plugin created via the factory
add_action('onp_licensing_325_plugin_created', 'onp_licensing_325_plugin_created');
function onp_licensing_325_plugin_created( $plugin ) {
$manager = new OnpLicensing325_Manager( $plugin );
$plugin->license = $manager;
}
/**
* The License Manager class.
*
* @since 1.0.0
*/
class OnpLicensing325_Manager {
/**
* A plugin for which the manager was created.
*
* @since 1.0.0
* @var Factory325_Plugin
*/
public $plugin;
/**
* Current license data.
*
* @since 1.0.0
* @var mixed[]
*/
public $data;
/**
* Createas a new instance of the license manager for a given plugin.
*
* @since 1.0.0
*/
public function __construct( $plugin ) {
$this->plugin = $plugin;
// gets a current license data
$this->data = get_option('onp_license_' . $this->plugin->pluginName, array());
$this->default = get_option('onp_default_license_' . $this->plugin->pluginName, array());
// a bit fix if some incorrect data goes from a database
if ( !$this->checkLicenseDataCorrectness($this->data) ) {
delete_option('onp_license_' . $this->plugin->pluginName);
$this->data = array();
}
// sets default license if a license is empty
if ( empty( $this->data) ) $this->data = $this->default;
// sets a license type what is used by the plugin
$this->type = ( !array_key_exists('Category', $this->data) || $this->isExpired() )
? @$this->default['Category']
: $this->data['Category'];
$this->build = isset( $this->data['Build'] ) ? $this->data['Build'] : null;
$this->key = isset( $this->data['Key'] ) ? $this->data['Key'] : null;
$this->word = $this->build ? 'top' : 'bottom';
// checks data returned from the api server
add_action('onp_api_ping_' . $plugin->pluginName, array($this, 'apiPing'));
// dectivates key if we got a request from the api server
//add_action('onp_api_action_deactivate-key', array($this, 'apiActionDeactivateKey'));
if ( is_admin() ) {
add_action('admin_enqueue_scripts', array($this, 'addLicenseInfoIntoSouceCode'));
// adding links below the plugin title on the page plugins.php
add_filter('plugin_action_links_' . $plugin->relativePath, array( $this, 'addLicenseLinks' ) );
// adding messages to the plugin row on the page plugins.php
add_filter('factory_plugin_row_' . $plugin->pluginName, array($this, 'addMessagesToPluginRow'));
// adding notices to display
add_filter('factory_notices_' . $this->plugin->pluginName, array( $this, 'addNotices'), 10, 2);
add_action('admin_enqueue_scripts', array( $this, 'printStylesForNotices'));
// activation and deactivation hooks
add_action('factory_plugin_activation_' . $plugin->pluginName, array($this, 'activationHook'));
}
}
/**
* Checks if the activation.json file exists, read and processes it.
*
* @since 3.0.6
* @return void
*/
public function activationHook() {
$licenseData = get_option('onp_license_' . $this->plugin->pluginName, array());
if ( !empty($licenseData) ) return;
$filepath = $this->plugin->pluginRoot . '/activation.json';
if ( !file_exists( $filepath ) ) return;
$data = json_decode( file_get_contents($filepath), true );
// activate trial if it's needed
if ( isset( $data['activate-trial'] ) && $data['activate-trial'] === true ) {
$args = array(
'fy_page' => 'license-manager',
'fy_action' => 'activateTrial',
'fy_plugin' => $this->plugin->pluginName
);
$urlToRedirect = '?' . http_build_query( $args );
factory_325_set_lazy_redirect($urlToRedirect);
//@unlink( $filepath );
return;
}
// applying an embedded key
if ( isset( $data['embedded-key'] ) && !empty( $data['embedded-key'] ) ) {
$dataToSave = $data['embedded-key'];
$dataToSave['Embedded'] = true;
$this->setLicense( $dataToSave );
}
}
/**
* Sets the active license.
*
* @since 3.0.6
* @param type $data licenase data.
* @return void
*/
public function setLicense( $data ) {
update_option('onp_license_' . $this->plugin->pluginName, $this->normilizeLicenseData( $data ));
$this->data = get_option('onp_license_' . $this->plugin->pluginName, array());
$this->build = isset( $this->data['Build'] ) ? $this->data['Build'] : null;
$this->key = isset( $this->data['Key'] ) ? $this->data['Key'] : null;
}
/**
* Sets the default license.
*
* @since 3.0.6
* @param type $data license data.
* @return void
*/
public function setDefaultLicense( $data ) {
$defaultLicense = get_option('onp_default_license_' . $this->plugin->pluginName, null);
if ( empty($defaultLicense) ) {
update_option('onp_default_license_' . $this->plugin->pluginName, $this->normilizeLicenseData( $data ));
}
}
/**
* Deletes the active license data and applies the default license data.
*
* @return void
*/
public function resetLicense( $resetDefault = false ) {return true;
delete_option('onp_license_' . $this->plugin->pluginName);
if ( $resetDefault ) {
delete_option('onp_default_license_' . $this->plugin->pluginName);
$this->plugin->activationHook();
}
$this->data = get_option('onp_default_license_' . $this->plugin->pluginName, array());
}
/**
* Checks data license correctness.
*
* @since 1.0.0
* @param mixed[] e $data License data to check.
* @return boolean
*/
private function checkLicenseDataCorrectness( $data ) {
if ( !is_array( $data ) ) return false;
if ( !isset($data['Category'])) return false;
if ( !isset($data['Title'])) return false;
if ( !isset($data['Description'])) return false;
return true;
}
/**
* Removes impurities in license data.
*
* @since 3.0.6
* @param mixed $data
* @return mixed
*/
private function normilizeLicenseData( $data ) {
$keys = array('Key', 'KeySecret', 'Category', 'Build', 'Title', 'Description', 'Activated', 'Expired', 'Embedded', 'KeyBound');
$dataToReturn = array();
foreach($data as $itemKey => $itemValue) {
if ( !in_array( $itemKey, $keys )) continue;
$dataToReturn[$itemKey] = $itemValue;
}
if ( !isset( $dataToReturn['Expired'] )) $dataToReturn['Expired'] = 0;
return $dataToReturn;
}
/**
* Adds a license and build name as javascript variables into the source code of pages.
*
* Calls on the hook 'admin_enqueue_scripts'
*
* @since 1.0.0
* @return void
*/
public function addLicenseInfoIntoSouceCode() {
$licenseType = defined('LICENSE_TYPE') ? LICENSE_TYPE : $this->data['Category'];
$buildType = defined('BUILD_TYPE') ? BUILD_TYPE : $this->data['Build'];
?>
<script>
window['<?php echo $this->plugin->pluginName ?>-license'] = '<?php echo $licenseType ?>';
window['<?php echo $this->plugin->pluginName ?>-build'] = '<?php echo $buildType ?>';
</script>
<?php
}
/**
* Processes data returned by an api server.
*
* @since 1.0.0
* @return void
*/
public function apiPing( $data ) {
if ( isset( $data['DeleteLicense'] ) && !empty( $data['DeleteLicense'] ) ) $this->resetLicense();
if ( isset( $data['KeyNotBound'] ) && !empty( $data['KeyNotBound'] ) ) {
update_option('onp_bound_message_' . $this->plugin->pluginName, true );
} else {
update_option('onp_bound_message_' . $this->plugin->pluginName, false );
}
}
/**
* Dectivates key if we got a request from the api server.
*
* @since 1.0.0
* @return void
*/
public function apiActionDeactivateKey() {
$key = isset( $_GET['onp_key'] ) ? $_GET['onp_key'] : null;
if ( $key !== $this->key ) return;
$this->resetLicense();
}
// -------------------------------------------------------------------------------------
// Key managment
// -------------------------------------------------------------------------------------
/**
* Trying to apply a given license key.
*
* @since 1.0.0
* @param string $key License key to apply.
* @param string $server Licensing server to get license data.
* @return mixed
*/
public function activateKey( $key) {
if ( defined('ONP_DEBUG_NETWORK_DISABLED') && ONP_DEBUG_NETWORK_DISABLED )
return new WP_Error('HTTP:NetworkDisabled', 'The network is disabled.');
$data = $this->plugin->api->request(
'ActivateKey',
array(
'body' => array(
'key' => $key
)
),
array(
'verification' => true
)
);
if (is_wp_error($data) ) return $data;
if ( !$this->checkLicenseDataCorrectness($data) )
return new WP_Error('FORM:InvalidLicenseData', 'The server returned invalid license data. If you tried to submit or delete key manually please make sure that you copied and pasted the server response code entirely.');
delete_option('mix_word_' . $this->plugin->pluginName);
$this->setLicense( $data );
if ( $this->plugin->updates ) $this->plugin->updates->checkUpdates();
return true;
}
/**
* Activates a licensing key manually.
*/
public function activateKeyManualy( $response ) {
$response = base64_decode( $response );
$data = array();
parse_str($response, $data);
if ( !$this->checkLicenseDataCorrectness($data) )
return new WP_Error('FORM:InvalidLicenseData', 'The server returned invalid license data. If you tried to submit or delete key manually please make sure that you copied and pasted the server response code entirely.');
$data['Description'] = base64_decode( str_replace( ' ', '+', $data['Description'] ));
$this->setLicense( $data );
if ( $this->plugin->updates ) $this->plugin->updates->checkUpdates();
return true;
}
/**
* Make attampt to activate one of trial license via the Licensing server.
* @param string $server Licensing server to get license data.
*/
public function activateTrial() {
if ( defined('ONP_DEBUG_NETWORK_DISABLED') && ONP_DEBUG_NETWORK_DISABLED )
return new WP_Error('HTTP:NetworkDisabled', 'The network is disabled.');
$data = $this->plugin->api->request(
'ActivateTrial', array(),
array(
'verification' => true
)
);
if (is_wp_error($data) ) return $data;
if ( !$this->checkLicenseDataCorrectness($data) )
return new WP_Error('FORM:InvalidLicenseData', 'The server returned invalid license data. If you tried to submit or delete key manually please make sure that you copied and pasted the server response code entirely.');
update_option('onp_trial_activated_' . $this->plugin->pluginName, true);
$this->setLicense( $data );
if ( $this->plugin->updates ) $this->plugin->updates->checkUpdates();
return true;
}
/**
* Delete current active key for the site.
*/
public function deleteKey() {
if ( defined('ONP_DEBUG_NETWORK_DISABLED') && ONP_DEBUG_NETWORK_DISABLED )
return new WP_Error('HTTP:NetworkDisabled', 'The network is disabled.');
$data = $this->plugin->api->request(
'DeleteKey', array(),
array(
'verification' => true
)
);
if (is_wp_error($data) ) return $data;
$this->resetLicense();
if ( $this->plugin->updates ) $this->plugin->updates->checkUpdates();
return true;
}
public function deleteKeyManualy( $response ) {
$response = base64_decode( $response );
$data = array();
parse_str($response, $data);
if ( $data['SiteSecret'] == get_option('onp_site_secret', null) ) {
delete_option('onp_license_' . $this->plugin->pluginName);
$this->data = get_option('onp_default_license_' . $this->plugin->pluginName, array());
return true;
};
if ( $this->plugin->updates ) $this->plugin->updates->checkUpdates();
return false;
}
public function getLinkToActivateTrial() {
$query = array(
'plugin' => $this->plugin->pluginName,
'site' => site_url(),
'secret' => get_option('onp_site_secret', null),
'assembly' => $this->plugin->build,
'version' => $this->plugin->version,
'tracker' => $this->plugin->tracker
);
$secretToken = $this->plugin->api->openVerificationGate();
$query['secretToken'] = $secretToken;
$request = base64_encode( http_build_query($query) );
return add_query_arg( array( 'request' => $request ), $this->plugin->options['api'] . 'ActivateTrialManualy' );
}
public function getLinkToActivateKey( $key ) {
$query = array(
'key' => $key,
'plugin' => $this->plugin->pluginName,
'site' => site_url(),
'secret' => get_option('onp_site_secret', null),
'assembly' => $this->plugin->build,
'version' => $this->plugin->version,
'tracker' => $this->plugin->tracker
);
$secretToken = $this->plugin->api->openVerificationGate();
$query['secretToken'] = $secretToken;
$request = base64_encode( http_build_query($query) );
return add_query_arg( array('request' => $request), $this->plugin->options['api'] . 'ActivateKeyManualy');
}
public function getLinkToDeleteKey() {
$query = array(
'plugin' => $this->plugin->pluginName,
'site' => site_url(),
'secret' => get_option('onp_site_secret', null),
'assembly' => $this->plugin->build,
'version' => $this->plugin->version,
'tracker' => $this->plugin->tracker
);
$request = base64_encode( http_build_query($query) );
return add_query_arg( array('request' => $request), $this->plugin->options['api'] . 'DeleteKeyManualy');
}
/**
* Creates a customer account and links a licence key.
*
* @since 1.0.0
* @param type $email Email to create an account.
* @return true|WP_Error An error occurred during creating an account or true.
*/
public function createAccount( $email, $subscribe ) {
if ( defined('ONP_DEBUG_NETWORK_DISABLED') && ONP_DEBUG_NETWORK_DISABLED )
return new WP_Error('HTTP:NetworkDisabled', 'The network is disabled.');
$data = $this->plugin->api->request(
'CreateAccount',
array(
'body' => array(
'email' => $email,
'subscribe' => $subscribe ? 'true' : 'false'
)
),
array(
'verification' => true
)
);
update_option('onp_bound_message_' . $this->plugin->pluginName, false );
return $data;
}
/**
* Binds the current key to the specified email.
*
* @since 1.0.0
* @param type $email Email to link the current key.
* @return true|WP_Error An error occurred during creating an account or true.
*/
public function bindKey( $email ) {
if ( defined('ONP_DEBUG_NETWORK_DISABLED') && ONP_DEBUG_NETWORK_DISABLED )
return new WP_Error('HTTP:NetworkDisabled', 'The network is disabled.');
$data = $this->plugin->api->request(
'bindKey',
array(
'body' => array(
'email' => $email
)
),
array(
'verification' => true
)
);
update_option('onp_bound_message_' . $this->plugin->pluginName, false );
return $data;
}
/**
* Cancels the recently created account (which is not activated yet).
*
* @since 1.0.0
*/
public function cancelAccount( $cancelCode, $confirmationId ) {
if ( defined('ONP_DEBUG_NETWORK_DISABLED') && ONP_DEBUG_NETWORK_DISABLED )
return new WP_Error('HTTP:NetworkDisabled', 'The network is disabled.');
$data = $this->plugin->api->request(
'cancelAccount',
array(
'body' => array(
'cancelCode' => $cancelCode,
'confirmationId' => $confirmationId
)
),
array(
'verification' => false
)
);
return $data;
}
// ---------------------------------------------------------------------------------
// Helper methods to work with keys
// ---------------------------------------------------------------------------------
public function hasKey() {
return !empty( $this->data['Key'] );
}
public function needKey() {
return $this->plugin->build == 'premium' && !$this->hasKey();
}
public function hasUpgrade() {
return
in_array($this->data['Category'], array('free', 'trial')) ||
in_array($this->data['Build'], array('free'));
}
public function isExpired() {
if ( !isset( $this->data['Expired'] ) || empty($this->data['Expired']) ) return false;
$expired = (int)$this->data['Expired'];
if ( $expired == 0 ) return false;
return $this->data['Expired'] - time() <= 0;
}
public function isTrial() {
if ( !isset( $this->data['Category'] ) ) return false;
return $this->data['Category'] === 'trial';
}
public function isEmbedded() {
if ( !isset( $this->data['Embedded'] ) ) return false;
return $this->data['Embedded'];
}
public function needToProtect() {
return !$this->isTrial() && !$this->isEmbedded();
}
// -------------------------------------------------------------------------------------
// Links, messages, notices and so on ...
// -------------------------------------------------------------------------------------
/**
* Adds the License link below the plugin title.
*
* Calls on the hook 'plugin_action_links_[plugin_name]'
*
* @since 1.0.0
* @param mixed[] $links
* @return mixed[]
*/
function addLicenseLinks($links) {
$url = onp_licensing_325_get_manager_link( $this->plugin->pluginName );
array_unshift($links, '<a href="' . $url . '" style="font-weight: bold;">'.__('License', 'onp_licensing_325'),'</a>');
unset($links['edit']);
return $links;
}
/**
* Adds messages offering to uprade a plugin into the plugin row on the page plugins.php.
*
* Calls on the hook 'factory_plugin_row_[plugin_name]'
*
* @since 1.0.0
* @param string[] $messages
* @return string[]
*/
function addMessagesToPluginRow($messages) {
if ( $this->plugin->license && !$this->plugin->license->hasKey() ) {
if ( in_array( $this->plugin->license->default['Build'], array( 'premium', 'ultimate' ) ) ) {
$message = __('You use a premium version of the plugin. Please, verify your license key to unlock all its features. <a href="%1$s">Click here</a>.', 'onp_licensing_325');
$message = str_replace("%1\$s", onp_licensing_325_get_manager_link($this->plugin->pluginName), $message);
return array($message);
}
}
return $messages;
}
/**
* Adds notices to display.
*
* Calls on the hook 'factory_notices_[plugin_name]'
*
* @param mixed[] $notices
* @return mixed[]
*/
function addNotices( $notices ) {
// show messages only for administrators
if ( !factory_325_is_administrator() ) return $notices;
$closed = get_option('factory_notices_closed', array());
$time = 0;
if ( isset( $closed[$this->plugin->pluginName . '-key-not-bound'] ) ) {
$time = $closed[$this->plugin->pluginName . '-key-not-bound']['time'];
}
// shows the key binding message only if changing the assembly is not required
$forceBindingMessage = defined('ONP_DEBUG_SHOW_BINDING_MESSAGE') && ONP_DEBUG_SHOW_BINDING_MESSAGE;
if ( ( $time + 60*60*24 <= time() && ( !$this->plugin->updates || !$this->plugin->updates->needChangeAssembly() )) || $forceBindingMessage ) {
$keyBound = get_option('onp_bound_message_' . $this->plugin->pluginName, false);
if ( ( $keyBound && $this->plugin->license && $this->plugin->license->key && $this->needToProtect() ) || $forceBindingMessage ) {
$notices[] = array(
'id' => $this->plugin->pluginName . '-key-not-bound',
// content and color
'class' => 'call-to-action',
'icon' => 'fa fa-frown-o',
'header' => __('Your license key is not protected!', 'onp_licensing_325'),
'message' => sprintf(__('Bind your license key (for %s) to your email address in order to avoid theft (it will take just a couple of seconds).', 'onp_licensing_325'), $this->plugin->options['title']),
'plugin' => $this->plugin->pluginName,
// buttons and links
'buttons' => array(
array(
'class' => 'btn btn-primary',
'title' => '<i class="fa fa-key"></i> ' . sprintf( __('Protect my key: %s', 'onp_licensing_325' ), '<i>' . $this->plugin->license->key . '</i>' ),
'action' => '?' . http_build_query(array(
'fy_page' => 'license-manager',
'fy_action' => 'createAccount',
'fy_plugin' => $this->plugin->pluginName
))
),
array(
'title' => __('Hide this message', 'onp_licensing_325'),
'class' => 'btn btn-default',
'action' => 'x'
)
)
);
}
}
$forceTrialNotices = defined('ONP_DEBUG_TRIAL_EXPIRES') && ONP_DEBUG_TRIAL_EXPIRES !== false;
$exipred = floatval($this->data['Expired']);
if ( $exipred != 0 || $forceTrialNotices ) {
$remained = round( ( $this->data['Expired'] - time() ) / (60 * 60 * 24), 2 );
if ( $forceTrialNotices ) $remained = ONP_DEBUG_TRIAL_EXPIRES;
if ( $remained < 5 && $remained > 0 ) {
$time = 0;
if ( isset( $closed[$this->plugin->pluginName . '-key-estimate'] ) ) {
$time = $closed[$this->plugin->pluginName . '-key-estimate']['time'];
}
if ( $time + 60*60*24 <= time() || $forceTrialNotices ) {
if ( $this->type == 'trial' || $forceTrialNotices ) {
if ( $remained <= 1 ) {
$notices[] = array(
'id' => $this->plugin->pluginName . '-key-estimate',
// content and color
'class' => 'call-to-action',
'icon' => 'fa fa-clock-o',
'header' => sprintf(__('The trial key for the %s will expire during the day!', 'onp_licensing_325'), $this->plugin->pluginTitle),
'message' => __('Don\'t forget to purchase the premium key or delete the trial key to use the free version of the plugin.', 'onp_licensing_325'),
'plugin' => $this->plugin->pluginName,
// buttons and links
'buttons' => array(
array(
'title' => '<i class="fa fa-arrow-circle-o-up"></i> '.__('Buy a premium key now!', 'onp_licensing_325'),
'class' => 'btn btn-primary',
'action' => onp_licensing_325_get_purchase_url( $this->plugin, 'trial-remained-1' )
),
array(
'title' => __('Hide this message', 'onp_licensing_325'),
'class' => 'btn btn-default',
'action' => 'x'
),
)
);
} else {
$notices[] = array(
'id' => $this->plugin->pluginName . '-key-estimate',
// content and color
'class' => 'call-to-action',
'icon' => 'fa fa-clock-o',
'header' => sprintf(__('The trial key for the %s will expire in %s days.', 'onp_licensing_325'),$this->plugin->pluginTitle, $remained),
'message' => __('Please don\'t forget to purchase the premium key or delete the trial key to use the free version of the plugin.', 'onp_licensing_325'),
'plugin' => $this->plugin->pluginName,
// buttons and links
'buttons' => array(
array(
'title' => '<i class="fa fa-arrow-circle-o-up"></i> '.__('Buy a premium key now!', 'onp_licensing_325'),
'class' => 'btn btn-primary',
'action' => onp_licensing_325_get_purchase_url( $this->plugin, 'trial-remained-' . $remained )
),
array(
'title' => __('Hide this message', 'onp_licensing_325'),
'class' => 'btn btn-default',
'action' => 'x'
),
)
);
}
}
}
}
if ( $this->isExpired() || $forceTrialNotices ) {
$notices[] = array(
'id' => $this->plugin->pluginName . '-key-expired',
// content and color
'class' => 'call-to-action',
'icon' => 'fa fa-arrow-circle-o-up',
'header' => sprintf(__('The trial key for the %s has expired.', 'onp_licensing_325'),$this->plugin->pluginTitle),
'message' => __('Please purchase another key or delete the current key to use the free version of the plugin.', 'onp_licensing_325'),
'plugin' => $this->plugin->pluginName,
// buttons and links
'buttons' => array(
array(
'title' => '<i class="fa fa-arrow-circle-o-up"></i> '.__('Buy a premium key now!', 'onp_licensing_325'),
'class' => 'btn btn-primary',
'action' => onp_licensing_325_get_purchase_url( $this->plugin, 'trial-expired' )
),
array(
'title' => __('Visit the license manager', 'onp_licensing_325'),
'class' => 'btn btn-default',
'action' => onp_licensing_325_get_manager_link($this->plugin->pluginName, 'index')
),
)
);
}
}
if ( $this->plugin->license && !$this->plugin->license->hasKey() ) {
if ( in_array( $this->plugin->license->default['Build'], array( 'premium', 'ultimate' ) ) ) {
if ( !isset( $this->plugin->options['support'] ) ) {
$contactUrl = 'http://support.onepress-media.com/create-ticket/';
} else {
$contactUrl = $this->plugin->options['support'];
}
$notices[] = array(
'id' => $this->plugin->pluginName . '-activate-premium-key',
// content and color
'class' => 'factory-hero',
'header' => __('Thank you ', 'onp_licensing_325'),
'message' => sprintf( __(' for purchasing <a target="_blank" href="%s" class="highlighted">%s</a>.', 'onp_licensing_325' ), onp_licensing_325_get_purchase_url( $this->plugin ), $this->plugin->pluginTitle ).
sprintf( __('Please verify your license key you got to unlock all the plugin features. Click the button on the right. Feel free to <a target="_blank" href="%s">contact us</a> if you need help.', 'onp_licensing_325'), $contactUrl ),
'plugin' => $this->plugin->pluginName,
// buttons and links
'buttons' => array(
array(
'title' => __('verify my license key', 'onp_licensing_325'),
'action' => onp_licensing_325_get_manager_link($this->plugin->pluginName, 'index')
)
)
);
}
}
return $notices;
}
public function printStylesForNotices( $hook ) {
if ( $hook !== 'index.php' && $hook !== 'plugins.php' ) return;
?>
<style>
.alert-danger.onp-alert-trial {
background-color: #fafafa !important;
color: #111 !important;
border: 2px solid #0074a2 !important;
}
</style>
<?php
}
}
/**
* Renders link to the license manager.
*
* @since 1.0.0
* @param type $pluginName
* @param type $action
*/
function onp_licensing_325_manager_link( $pluginName, $action = null, $echo = true ) {
$args = array(
'fy_page' => 'license-manager',
'fy_action' => $action,
'fy_plugin' => $pluginName
);
if( $echo )
echo '?' . http_build_query( $args );
else
return '?' . http_build_query( $args );
}
/**
* Gets link to the license manager.
*
* @since 1.0.0
* @param type $pluginName
* @param type $action
*/
function onp_licensing_325_get_manager_link( $pluginName, $action = null ) {
$args = array(
'fy_page' => 'license-manager',
'fy_action' => $action,
'fy_plugin' => $pluginName
);
return '?' . http_build_query( $args );
}
/**
* Prints a purchasing link with a set of tracking query arguments.
*
* @since 3.0.7
* @param Factory325_Plugin $plugin
* @return void
*/
function onp_licensing_325_purchase_url( $plugin ) {
echo onp_licensing_325_get_purchase_url( $plugin );
}
/**
* Returns a purchasing link with a set of tracking query arguments.
*
* @since 3.0.7
* @param Factory325_Plugin $plugin
* @return string
*/
function onp_licensing_325_get_purchase_url( $plugin, $campaign = 'upgrade-to-premium', $content = null ) {
if ( empty( $plugin ) || empty( $plugin->options ) ) return null;
if ( !isset( $plugin->options['premium'] ) ) return null;
$url = $plugin->options['premium'];
$args = array(
'utm_source' => 'plugin-' . $plugin->options['name'],
'utm_medium' => ( $plugin->license && isset( $plugin->license->data['Category'] ) )
? ( $plugin->license->data['Category'] . '-version' )
: 'unknown-version',
'utm_campaign' => $campaign,
'tracker' => isset( $plugin->options['tracker'] ) ? $plugin->options['tracker'] : null
);
if ( $content ) $args['utm_content'] = $content;
return add_query_arg( $args, $url );
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* OnePress Updates
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package core
* @since 1.0.0
*/
// Checks if the one is already loaded.
// We prevent to load the same version of the module twice.
if (defined('ONP_UPDATES_325_LOADED')) return;
define('ONP_UPDATES_325_LOADED', true);
// Absolute path and URL to the files and resources of the module.
define('ONP_UPDATES_325_DIR', dirname(__FILE__));
load_plugin_textdomain('onepress_updates_000', false, dirname( plugin_basename( __FILE__ ) ) . '/langs');
#comp merge
include(ONP_UPDATES_325_DIR. '/includes/transient.functions.php');
include(ONP_UPDATES_325_DIR. '/updates.php');
#endcomp

View File

@@ -0,0 +1,31 @@
<?php
function onp_updates_325_set_site_transient( $transient, $value, $expiration = 0, $actions = false ) {
global $_wp_using_ext_object_cache;
if ( $actions ) {
$value = apply_filters( 'pre_set_site_transient_' . $transient, $value );
}
if ( $_wp_using_ext_object_cache ) {
$result = wp_cache_set( $transient, $value, 'site-transient', $expiration );
} else {
$transient_timeout = '_site_transient_timeout_' . $transient;
$transient = '_site_transient_' . $transient;
if ( false === get_site_option($transient) ) {
if ( $expiration )
add_site_option( $transient_timeout, time() + $expiration );
$result = add_site_option( $transient, $value );
} else {
if ( $expiration )update_site_option( $transient_timeout, time() + $expiration );
delete_site_option($transient);
$result = update_site_option( $transient, $value );
}
}
if ( $result && $actions ) {
do_action( 'set_site_transient_' . $transient );
do_action( 'setted_site_transient', $transient );
}
return $result;
}

View File

@@ -0,0 +1,438 @@
<?php
/**
* The file contains a class and a set of helper methods to manage updates.
*
* @author Paul Kashtanoff <paul@byonepress.com>
* @copyright (c) 2013, OnePress Ltd
*
* @package onepress-updates
* @since 1.0.0
*/
add_action('onp_updates_325_plugin_created', 'onp_updates_325_plugin_created');
function onp_updates_325_plugin_created( $plugin ) {
$manager = new OnpUpdates325_Manager( $plugin );
$plugin->updates = $manager;
}
/**
* The Updates Manager class.
*
* @since 1.0.0
*/
class OnpUpdates325_Manager {
/**
* Current factory plugin.
*
* @since 1.0.0
* @var Factory325_Plugin
*/
public $plugin;
/**
* Data about the last version check.
*
* @since 1.0.0
* @var array
*/
public $lastCheck;
/**
* Creates an instance of the update manager.
* @param type $plugin
*/
public function __construct( $plugin ) {
$this->plugin = $plugin;
$this->lastCheck = get_option('onp_version_check_' . $this->plugin->pluginName, null);
$this->word = $this->lastCheck ? $this->lastCheck : 'never';
// if a plugin is not licensed, or a user has a license key
if ( $this->needCheckUpdates() ) {
// an action that is called by the cron to check updates
add_action('onp_check_upadates_' . $this->plugin->pluginName, array($this, 'checkUpdatesAuto'));
// if a special constant set, then forced to check updates
if ( defined('ONP_DEBUG_CHECK_UPDATES') && ONP_DEBUG_CHECK_UPDATES ) $this->checkUpdates();
}
if ( is_admin() ) {
// if the license build and the plugin build are not equal
if ( $this->needChangeAssembly() ) {
$this->updatePluginTransient();
add_filter('factory_plugin_row_' . $this->plugin->pluginName, array($this, 'showChangeAssemblyPluginRow' ), 10, 3);
add_filter('factory_notices_' . $this->plugin->pluginName, array( $this, 'addNotices'), 10, 2);
}
add_action('admin_notices', array($this, 'clearTransient'));
if ( $this->needCheckUpdates() || $this->needChangeAssembly() ) {
// the method that responses for changin plugin transient when it's saved
add_filter('pre_set_site_transient_update_plugins', array($this, 'changePluginTransient'));
// filter that returns info about available updates
add_filter('plugins_api', array($this, 'getUpdateInfo'), 10, 3);
}
// activation and deactivation hooks
add_action('factory_plugin_activation_or_update_' . $plugin->pluginName, array($this, 'activationOrUpdateHook'));
add_action('factory_plugin_deactivation_' . $plugin->pluginName, array($this, 'deactivationHook'));
}
}
/**
* Need to check updates?
* @return bool
*/
public function needCheckUpdates() {
return !isset( $this->plugin->options['host'] ) || $this->plugin->options['host'] == 'onepress';
}
/**
* Need to change a current assembly?
* @return bool
*/
public function needChangeAssembly() {
if ( $this->plugin->build === 'offline' ) return false;
return isset( $this->plugin->license ) && ( $this->plugin->build !== $this->plugin->license->build );
}
/**
* Returns true if a plugin version has been checked up to the moment.
* @return boolean
*/
public function isVersionChecked() {
return !( empty($this->lastCheck) ) && isset( $this->lastCheck['Version'] );
}
/**
* Returns true if a plugin version is actual.
* @return boolean
*/
public function isActualVersion() {
if ( $this->needChangeAssembly() ) return false;
if ( !$this->needCheckUpdates() ) return true;
if ( !isset($this->lastCheck['Version']) ) return true;
$currentVersion = $this->plugin->version;
$serverVersion = $this->lastCheck['Version'];
if ( empty($serverVersion) || empty($serverVersion) ) return true;
return (version_compare($currentVersion, $serverVersion, '>='));
}
// -------------------------------------------------------------------------------------
// Activation and deactivation
// -------------------------------------------------------------------------------------
/**
* Calls on plugin activation or updating.
*/
public function activationOrUpdateHook() {
// set cron tasks and clear last version check data
if ( !wp_next_scheduled( 'onp_check_upadates_' . $this->plugin->pluginName ) ) {
wp_schedule_event( time(), 'twicedaily', 'onp_check_upadates_' . $this->plugin->pluginName );
}
$this->clearUpdates();
}
/**
* Calls on plugin deactivation .
*/
public function deactivationHook() {
// clear cron tasks and license data
if ( wp_next_scheduled( 'onp_check_upadates_' . $this->plugin->pluginName ) ) {
$timestamp = wp_next_scheduled( 'onp_check_upadates_' . $this->plugin->pluginName );
wp_unschedule_event( $timestamp, 'onp_check_upadates_' . $this->plugin->pluginName );
}
$this->clearUpdates();
}
// -------------------------------------------------------------------------------------
// Checking updates
// -------------------------------------------------------------------------------------
public function checkUpdatesAuto() {
$lastTime = intval( get_option( 'onp_last_check_' . $this->plugin->pluginName ) );
if ( !$lastTime ) $lastTime = 0;
if ( time() > $lastTime + 10800 ) {
$this->checkUpdates();
update_option( 'onp_last_check_' . $this->plugin->pluginName, time() );
}
}
public function checkUpdates() {
$data = $this->sendRequest( 'GetCurrentVersion' );
if ( is_wp_error( $data ) ) {
$result = array();
$result['Checked'] = time();
$result['Error'] = $data->get_error_message();
update_option('onp_version_check_' . $this->plugin->pluginName, $result);
$this->lastCheck = $result;
} else {
$data['Checked'] = time();
update_option('onp_version_check_' . $this->plugin->pluginName, $data);
$this->lastCheck = $data;
do_action('onp_api_ping_' . $this->plugin->pluginName, $data);
}
$this->updatePluginTransient();
return $data;
}
/**
* Clears info about updates for the plugin.
*/
public function clearUpdates() {
delete_option('onp_version_check_' . $this->plugin->pluginName);
$this->lastCheck = null;
$transient = $this->changePluginTransient( get_site_transient('update_plugins') );
if ( !empty( $transient) ) {
unset($transient->response[$this->plugin->relativePath]);
onp_updates_325_set_site_transient('update_plugins', $transient);
}
}
/**
* Fix a bug when the message offering to change assembly appears even if the assemble is correct.
* @return type
*/
public function clearTransient() {
$screen = get_current_screen();
if ( empty($screen) ) return;
if ( in_array( $screen->base, array('plugins', 'update-core') ) ) {
$this->updatePluginTransient();
}
}
/**
* Calls a basic method to get info about updates and saves it into updates transient.
*/
public function updatePluginTransient() {
$transient = $this->changePluginTransient( get_site_transient('update_plugins') );
onp_updates_325_set_site_transient('update_plugins', $transient);
}
/**
* Updates a given transient to add info about updates of a current plugin.
*/
public function changePluginTransient( $transient ) {
if ( empty( $transient ) ) $transient = new stdClass();
// migrating from one assembly to another one
if ( $this->needChangeAssembly() ) {
$obj = new stdClass();
$obj->slug = $this->plugin->pluginSlug;
$obj->new_version = '[ migrate-to-' . $this->plugin->license->build . ' ]';
$obj->plugin = $this->plugin->relativePath;
$queryArgs = array(
'plugin' => $this->plugin->pluginName,
'assembly' => $this->plugin->license->build,
'site' => site_url(),
'secret' => get_option('onp_site_secret', null),
'tracker' => $this->plugin->tracker
);
if ( defined('FACTORY_BETA') && FACTORY_BETA ) $queryArgs['beta'] = true;
$obj->package = $this->plugin->options['api'] . 'GetPackage?' . http_build_query($queryArgs);
$obj->changeAssembly = true;
$transient->response[$this->plugin->relativePath] = $obj;
return $transient;
} else {
if ( isset($transient->response[$this->plugin->relativePath]) ) {
$r = $transient->response[$this->plugin->relativePath];
if ( property_exists($r, 'changeAssembly') ) {
unset($transient->response[$this->plugin->relativePath]);
return $transient;
}
}
}
// if we don't need to check update, return original transient data,
// for example if we use a free version of the plugin that is updated from wordpress.org
if ( !$this->needCheckUpdates() ) return $transient;
// if we have data about the last version check
if ( isset( $this->lastCheck['Version'] ) ) {
// nothing to do if the plugin version is the last one
if (version_compare($this->plugin->version, $this->lastCheck['Version'], '>=')) {
unset($transient->response[$this->plugin->relativePath]);
return $transient;
}
// if the plugin version is less then the remote one
$obj = new stdClass();
$obj->slug = $this->plugin->pluginSlug;
$obj->new_version = $this->lastCheck['Version'];
$obj->url = $this->plugin->options['api'] . 'GetDetails?' . http_build_query(array(
'version' => $this->lastCheck['Id']
));
$queryArgs = array(
'versionId' => $this->lastCheck['Id'],
'site' => site_url(),
'secret' => get_option('onp_site_secret', null),
'tracker' => $this->plugin->tracker
);
if ( defined('FACTORY_BETA') && FACTORY_BETA ) $queryArgs['beta'] = true;
$obj->package = $this->plugin->options['api'] . 'GetPackage?' . http_build_query($queryArgs);
$transient->response[$this->plugin->relativePath] = $obj;
return $transient;
}
unset($transient->response[$this->plugin->relativePath]);
return $transient;
}
/**
* Gets info about update.
*/
public function getUpdateInfo($false, $action, $arg) {
if (!empty($arg) && isset($arg->slug) && $arg->slug === $this->plugin->pluginSlug) {
// if we need to change a current assembly, then nothing to say about the update
if ( $this->needChangeAssembly() ) {
?>
<strong>Migration to another plugin assenbly.</strong>
<?php
return $false;
}
$package = $this->plugin->options['api'] . 'GetPackage?' . http_build_query(array(
'versionId' => $this->lastCheck['Id'],
'site' => site_url(),
'secret' => get_option('onp_site_secret', null)
));
$data = $this->sendRequest( 'GetDetails?' . http_build_query(array(
'version' => $this->lastCheck['Id']
)), array(
'skipBody' => true,
'method' => 'GET'
));
if ( is_wp_error( $data ) ) {
?>
<strong><?php echo $data->get_error_message() ?></strong>
<?php
return $false;
}
$obj = new stdClass();
$obj->slug = $this->plugin->pluginSlug;
$obj->homepage = $data['Homepage'];
$obj->name = $this->plugin->pluginTitle;
$obj->plugin_name = $this->plugin->pluginSlug;
$obj->new_version = $data['Version'];
$obj->requires = $data['Requires'];
$obj->tested = $data['Tested'];
$obj->downloaded = $data['Downloads'];
$obj->last_updated = date('Y-m-d H:i:s', $data['Registered']);
$obj->download_link = $package;
$obj->sections = array(
'Changes' => $data['VersionDescription']
);
return $obj;
}
return $false;
}
public function showChangeAssemblyPluginRow( $messages, $file, $plugin_data ) {
if ( !$this->needChangeAssembly() ) return $messages;
$current = get_site_transient( 'update_plugins' );
if ( !isset( $current->response[ $file ] ) ) return $messages;
$r = $current->response[ $file ];
if ( ! current_user_can('update_plugins') ) {
$message = sprintf(
__('You changed the license type. Please download "%1$s" assembly', 'onepress_updates_000'),
$this->plugin->license->build
);
} else if ( empty($r->package) ) {
$message = sprintf(
__('You changed the license type. Please download "%1$s" assembly. <em>Automatic update is unavailable for this plugin.</em>', 'onepress_updates_000'),
$this->plugin->license->build
);
} else {
$message = sprintf(
__('You successfully changed the license type. Please install another plugin assembly (%1$s). <a href="%2$s">Update it now</a>.', 'onepress_updates_000'),
$this->plugin->license->build,
wp_nonce_url( self_admin_url('update.php?action=upgrade-plugin&plugin=') . $file, 'upgrade-plugin_' . $file)
);
}
return array($message);
}
public function addNotices( $notices ) {
if ( $this->needChangeAssembly() ) {
$notices[] = array(
'id' => $this->plugin->pluginName . '-change-assembly',
'where' => array('dashboard', 'edit', 'post'),
// content and color
'class' => 'alert alert-danger onp-need-change-assembly',
'header' => __('Please update the plugin', 'onepress_updates_000'),
'message' => sprintf(__('You changed a license type for <strong>%s</strong>. But the license you use\'re currently requires another plugin assembly.<br />The plugin won\'t work fully until you download the proper assembly. Don\'t worry it takes only 5 seconds and all your data will be saved.', 'onepress_updates_000'), $this->plugin->pluginTitle),
// buttons and links
'buttons' => array(
array(
'title' => __('Visit the Plugins page', 'onepress_updates_000'),
'class' => 'btn btn-danger',
'action' => "plugins.php"
)
)
);
}
return $notices;
}
// -------------------------------------------------------------------------------------
// Tools
// -------------------------------------------------------------------------------------
/**
* Sends request to the update server.
*/
protected function sendRequest($action, $args = array()) {
$args['timeout'] = 8;
return $this->plugin->api->request( $action, $args );
}
}
?>