Commit df917ec7 authored by Kevin Stover's avatar Kevin Stover

Merge branch 'release/v.2.2.47'

parents 63e6669f 13eca812
<?php
// uncomment this line for testing
//set_site_transient( 'update_plugins', null );
/**
* Allows plugins to use their own update API.
*
* @author Pippin Williamson
* @version 1.1
*/
class EDD_SL_Plugin_Updater {
private $api_url = '';
private $api_data = array();
private $name = '';
private $slug = '';
/**
* Class constructor.
*
* @uses plugin_basename()
* @uses hook()
*
* @param string $_api_url The URL pointing to the custom API endpoint.
* @param string $_plugin_file Path to the plugin file.
* @param array $_api_data Optional data to send with API calls.
* @return void
*/
function __construct( $_api_url, $_plugin_file, $_api_data = null ) {
$this->api_url = trailingslashit( $_api_url );
$this->api_data = urlencode_deep( $_api_data );
$this->name = plugin_basename( $_plugin_file );
$this->slug = basename( $_plugin_file, '.php');
$this->version = $_api_data['version'];
// Set up hooks.
$this->hook();
}
/**
* Set up Wordpress filters to hook into WP's update process.
*
* @uses add_filter()
*
* @return void
*/
private function hook() {
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'pre_set_site_transient_update_plugins_filter' ) );
add_filter( 'plugins_api', array( $this, 'plugins_api_filter' ), 10, 3 );
}
/**
* Check for Updates at the defined API endpoint and modify the update array.
*
* This function dives into the update api just when Wordpress creates its update array,
* then adds a custom API call and injects the custom plugin data retrieved from the API.
* It is reassembled from parts of the native Wordpress plugin update code.
* See wp-includes/update.php line 121 for the original wp_update_plugins() function.
*
* @uses api_request()
*
* @param array $_transient_data Update array build by Wordpress.
* @return array Modified update array with custom plugin data.
*/
function pre_set_site_transient_update_plugins_filter( $_transient_data ) {
if( empty( $_transient_data ) ) return $_transient_data;
$to_send = array( 'slug' => $this->slug );
$api_response = $this->api_request( 'plugin_latest_version', $to_send );
if( false !== $api_response && is_object( $api_response ) && isset( $api_response->new_version ) ) {
if( version_compare( $this->version, $api_response->new_version, '<' ) )
$_transient_data->response[$this->name] = $api_response;
}
return $_transient_data;
}
/**
* Updates information on the "View version x.x details" page with custom data.
*
* @uses api_request()
*
* @param mixed $_data
* @param string $_action
* @param object $_args
* @return object $_data
*/
function plugins_api_filter( $_data, $_action = '', $_args = null ) {
if ( ( $_action != 'plugin_information' ) || !isset( $_args->slug ) || ( $_args->slug != $this->slug ) ) return $_data;
$to_send = array( 'slug' => $this->slug );
$api_response = $this->api_request( 'plugin_information', $to_send );
if ( false !== $api_response ) $_data = $api_response;
return $_data;
}
/**
* Calls the API and, if successfull, returns the object delivered by the API.
*
* @uses get_bloginfo()
* @uses wp_remote_post()
* @uses is_wp_error()
*
* @param string $_action The requested action.
* @param array $_data Parameters for the API action.
* @return false||object
*/
private function api_request( $_action, $_data ) {
global $wp_version;
$data = array_merge( $this->api_data, $_data );
if( $data['slug'] != $this->slug )
return;
if( empty( $data['license'] ) )
return;
$api_params = array(
'edd_action' => 'get_version',
'license' => $data['license'],
'name' => $data['item_name'],
'slug' => $this->slug,
'author' => $data['author']
);
$request = wp_remote_post( $this->api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
if ( ! is_wp_error( $request ) ):
$request = json_decode( wp_remote_retrieve_body( $request ) );
if( $request && isset( $request->sections ) )
$request->sections = maybe_unserialize( $request->sections );
return $request;
else:
return false;
endif;
}
}
\ No newline at end of file
......@@ -35,7 +35,11 @@ function ninja_forms_preview_link( $form_id = '', $echo = true ) {
//if( '' == $form_data['data']['append_page'] ) {
if(!isset($form_data['data']['append_page']) OR empty($form_data['data']['append_page'])){ // See the comment above about this check. !empty will ensure that it's not either empty quotes or null.
$opt = get_option( 'ninja_forms_settings' );
$page_id = $opt['preview_id'];
if ( isset ( $opt['preview_id'] ) ) {
$page_id = $opt['preview_id'];
} else {
$page_id = '';
}
} else {
$page_id = $form_data['data']['append_page'];
}
......
......@@ -16,7 +16,12 @@ add_action('init', 'ninja_forms_register_general_settings_metabox');
function ninja_forms_register_general_settings_metabox(){
$plugin_settings = get_option( 'ninja_forms_settings' );
$current_version = $plugin_settings['version'];
if ( isset ( $plugin_settings['version'] ) ) {
$current_version = $plugin_settings['version'];
} else {
$current_version = NINJA_FORMS_VERSION;
}
$args = array(
'page' => 'ninja-forms-settings',
'tab' => 'general_settings',
......
<?php
/*
*
* This class handles all the update-related stuff for extensions, including adding a license section to the license tab.
* It accepts two args: Product Name and Version.
*
* @param $product_name string
* @param $version string
* @since 2.2.47
* @return void
*/
class NF_Extension_Updater
{
/*
*
* Define our class variables
*/
public $product_nice_name = '';
public $product_name = '';
public $version = '';
public $store_url = 'http://ninjaforms.com';
public $file = '';
public $author = '';
/*
*
* Constructor function
*
* @since 2.2.47
* @return void
*/
function __construct( $product_name, $version, $author, $file, $slug = '' ) {
$this->product_nice_name = $product_name;
if ( $slug == '' ) {
$this->product_name = strtolower( $product_name );
$this->product_name = preg_replace( "/[^a-zA-Z]+/", "", $this->product_name );
} else {
$this->product_name = $slug;
}
$this->version = $version;
$this->file = $file;
$this->author = $author;
$this->add_license_fields();
$this->license_status();
$this->auto_update();
} // function constructor
/*
*
* Function that adds the license entry fields to the license tab.
*
* @since 2.2.47
* @return void
*/
function add_license_fields() {
$args = array(
'page' => 'ninja-forms-settings',
'tab' => 'license_settings',
'slug' => 'license_settings',
'settings' => array(
array(
'name' => $this->product_name.'_license',
'type' => 'text',
'label' => $this->product_nice_name.' '.__( 'License Key', 'ninja-forms' ),
'desc' => __( 'You will find this included with your purchase email.', 'ninja-forms' ),
'save_function' => array( $this, 'check_license' )
),
),
);
if( function_exists( 'ninja_forms_register_tab_metabox_options' ) ){
ninja_forms_register_tab_metabox_options( $args );
}
} // function add_license_fields
/*
*
* Function that activates the license for this product
*
* @since 2.2.47
* @return void
*/
function check_license( $data ) {
$plugin_settings = get_option( 'ninja_forms_settings' );
if( isset( $plugin_settings[ $this->product_name.'_license_status' ] ) ){
$status = $plugin_settings[ $this->product_name.'_license_status' ];
}else{
$status = 'invalid';
}
if( isset( $plugin_settings[ $this->product_name.'_license' ] ) ){
$old_license = $plugin_settings[ $this->product_name.'_license'];
}else{
$old_license = '';
}
if ( $old_license != '' AND $old_license != $data[ $this->product_name.'_license' ] AND $status == 'valid' ) {
$this->deactivate_license();
}
if( $old_license == '' OR ( $old_license != $data[ $this->product_name.'_license' ] ) OR $status == 'invalid' ){
$this->activate_license( $data );
}
} // function check_license
/*
*
* Function that activates our license
*
* @since 2.2.47
* @return void
*/
function activate_license( $data ) {
$plugin_settings = get_option( 'ninja_forms_settings' );
// retrieve the license from the database
$license = $data[ $this->product_name.'_license' ];
// data to send in our API request
$api_params = array(
'edd_action'=> 'activate_license',
'license' => $license,
'item_name' => urlencode( $this->product_nice_name ) // the name of our product in EDD
);
// Call the custom API.
$response = wp_remote_get( add_query_arg( $api_params, $this->store_url ) );
// make sure the response came back okay
if ( is_wp_error( $response ) )
return false;
// decode the license data
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
// $license_data->license will be either "valid" or "invalid"
$plugin_settings[ $this->product_name.'_license_status' ] = $license_data->license;
update_option( 'ninja_forms_settings', $plugin_settings );
}
/*
*
* Function that deactivates our license if the user clicks the "Deactivate License" button.
*
* @since 2.2.47
* @return void
*/
function deactivate_license() {
$plugin_settings = get_option( 'ninja_forms_settings' );
if( isset( $plugin_settings[ $this->product_name.'_license_status' ] ) ){
$status = $plugin_settings[ $this->product_name.'_license_status' ];
}else{
$status = 'invalid';
}
if( isset( $plugin_settings[ $this->product_name.'_license' ] ) ){
$license = $plugin_settings[ $this->product_name.'_license'];
}else{
$license = '';
}
// data to send in our API request
$api_params = array(
'edd_action'=> 'deactivate_license',
'license' => $license,
'item_name' => urlencode( $this->product_nice_name ) // the name of our product in EDD
);
// Call the custom API.
$response = wp_remote_get( add_query_arg( $api_params, $this->store_url ), array( 'timeout' => 15, 'sslverify' => false ) );
// make sure the response came back okay
if ( is_wp_error( $response ) )
return false;
// decode the license data
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
// $license_data->license will be either "deactivated" or "failed"
if( $license_data->license == 'deactivated' ) {
// $license_data->license will be either "valid" or "invalid"
$plugin_settings[ $this->product_name.'_license_status' ] = 'invalid';
$plugin_settings[ $this->product_name.'_license' ] = '';
update_option( 'ninja_forms_settings', $plugin_settings );
}
}
/*
*
* Function that adds the green checkmark or red X to indicate license status
*
* @since 2.2.46
* @return void
*/
function license_status() {
global $ninja_forms_tabs_metaboxes;
for ($x=0; $x < count( $ninja_forms_tabs_metaboxes['ninja-forms-settings']['license_settings']['license_settings']['settings'] ); $x++) {
if( $ninja_forms_tabs_metaboxes['ninja-forms-settings']['license_settings']['license_settings']['settings'][$x]['name'] == $this->product_name.'_license' ){
$plugin_settings = get_option( 'ninja_forms_settings' );
if( !isset( $plugin_settings[ $this->product_name.'_license_status' ] ) OR $plugin_settings[ $this->product_name.'_license_status' ] == 'invalid' ){
$status = ' <img src="'.NINJA_FORMS_URL.'/images/no.png">';
}else{
$status = ' <img src="'.NINJA_FORMS_URL.'/images/yes.png">';
}
$ninja_forms_tabs_metaboxes['ninja-forms-settings']['license_settings']['license_settings']['settings'][$x]['label'] .= $status;
}
}
} // function license_status
/*
*
* Function that runs all of our auto-update functionality
*
* @since 2.2.47
* @return void
*/
function auto_update() {
$plugin_settings = get_option( 'ninja_forms_settings' );
// retrieve our license key from the DB
if( isset( $plugin_settings[ $this->product_name.'_license' ] ) ){
$license = $plugin_settings[ $this->product_name.'_license' ];
}else{
$license = '';
}
// setup the updater
$edd_updater = new EDD_SL_Plugin_Updater( $this->store_url, $this->file, array(
'version' => $this->version, // current version number
'license' => $license, // license key (used get_option above to retrieve from DB)
'item_name' => $this->product_nice_name, // name of this plugin
'author' => $this->author, // author of this plugin
)
);
} // function auto_update
} // class
\ No newline at end of file
......@@ -381,7 +381,10 @@ function ninja_forms_field_calc_value( $field_id, $field_value = '', $calc_metho
$field = ninja_forms_get_field_by_id( $field_id );
}
$field_data = $field['data'];
//$field_data = $field['data'];
remove_filter( 'ninja_forms_field', 'ninja_forms_field_calc_filter', 2 );
$field_data = apply_filters( 'ninja_forms_field', $field['data'], $field_id );
add_filter( 'ninja_forms_field', 'ninja_forms_field_calc_filter', 11, 2 );
if ( isset ( $field_data['default_value'] ) ) {
$default_value = $field_data['default_value'];
......
......@@ -202,7 +202,7 @@ function ninja_forms_get_field_wrap_class($field_id){
function ninja_forms_get_field_class($field_id){
$field_row = ninja_forms_get_field_by_id($field_id);
$field_data = $field_row['data'];
$field_data = apply_filters( 'ninja_forms_field', $field_data, $field_id );
$field_class = 'ninja-forms-field';
$x = 0;
......
......@@ -92,4 +92,4 @@ function ninja_forms_display_label_inside( $data, $field_id ){
return $data;
}
add_filter( 'ninja_forms_field', 'ninja_forms_display_label_inside', 10, 2 );
\ No newline at end of file
add_filter( 'ninja_forms_field', 'ninja_forms_display_label_inside', 5, 2 );
\ No newline at end of file
......@@ -113,7 +113,7 @@ class Ninja_Forms_Processing {
*
*/
function setup_submitted_vars() {
global $ninja_forms_fields;
global $ninja_forms_fields, $wp;
$form_ID = $this->data['form_ID'];
//Get our plugin settings
......@@ -124,6 +124,7 @@ class Ninja_Forms_Processing {
return '';
$this->data['action'] = 'submit';
$this->data['form']['form_url'] = $this->get_current_url();
$cache = get_transient( $_SESSION['ninja_forms_transient_id'] );
// If we have fields in our $_POST object, then loop through the $_POST'd field values and add them to our global variable.
......@@ -183,7 +184,6 @@ class Ninja_Forms_Processing {
}
$this->data['form']['admin_attachments'] = array();
$this->data['form']['user_attachments'] = array();
$this->data['form']['form_url'] = wp_guess_url();
}
} else if ( $cache !== false ) { // Check to see if we have $_SESSION values from a submission.
......@@ -1122,4 +1122,26 @@ class Ninja_Forms_Processing {
}
}
}
\ No newline at end of file
/**
* Function that gets the current URL of the page, including querystring.
*
* @since 2.2.47
* @return $url string
*/
function get_current_url() {
$protocol = "http";
if($_SERVER["SERVER_PORT"]==443 || (!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"]=="on")) {
$protocol .= "s";
$protocol_port = $_SERVER["SERVER_PORT"];
} else {
$protocol_port = 80;
}
$host = $_SERVER["HTTP_HOST"];
$port = $_SERVER["SERVER_PORT"];
$request_path = $_SERVER["PHP_SELF"];
$querystr = $_SERVER["QUERY_STRING"];
$url = $protocol."://".$host.(($port!=$protocol_port && strpos($host,":")==-1)?":".$port:"").$request_path.(empty($querystr)?"":"?".$querystr);
return $url;
}
}
......@@ -295,7 +295,15 @@ function ninja_forms_field_list_display( $field_id, $data ){
$display_style = '';
}
$label = stripslashes($label);
if ( isset( $option['disabled'] ) AND $option['disabled'] ){
$disabled = 'disabled';
}else{
$disabled = '';
}
$label = htmlentities( $label );
$label = stripslashes( $label );
$field_label = $data['label'];
......@@ -312,7 +320,7 @@ function ninja_forms_field_list_display( $field_id, $data ){
}
?>
<option value="<?php echo $value;?>" <?php echo $selected;?> style="<?php echo $display_style;?>"><?php echo $label;?></option>
<option value="<?php echo $value;?>" <?php echo $selected;?> style="<?php echo $display_style;?>" <?php echo $disabled;?>><?php echo $label;?></option>
<?php
}
?>
......@@ -521,8 +529,8 @@ function ninja_forms_field_list_option_output($field_id, $x, $option = '', $hidd
$hidden = 'display:none';
}
if(is_array($option)){
$label = $option['label'];
$value = $option['value'];
$label = htmlentities( $option['label'] );
$value = htmlentities( $option['value'] );
if ( isset ( $option['calc'] ) ) {
$calc = $option['calc'];
} else {
......@@ -544,6 +552,7 @@ function ninja_forms_field_list_option_output($field_id, $x, $option = '', $hidd
if($selected == 1){
$selected = "checked='checked'";
}
?>
<div id="ninja_forms_field_<?php echo $field_id;?>_list_option_<?php echo $x;?>" class="ninja-forms-field-<?php echo $field_id;?>-list-option ninja-forms-field-list-option" <?php echo $hide;?>>
<table class="list-options">
......@@ -624,4 +633,4 @@ function ninja_forms_field_filter_list_data( $data, $field_id ){
return $data;
}
add_filter( 'ninja_forms_field', 'ninja_forms_field_filter_list_data', 9, 2 );
\ No newline at end of file
add_filter( 'ninja_forms_field', 'ninja_forms_field_filter_list_data', 5, 2 );
\ No newline at end of file
......@@ -425,11 +425,13 @@ jQuery(document).ready(function(jQuery) {
}
// Check for a percentage sign in our f_value. If we find one, then convert it to a decimal.
if ( f_value.indexOf("%") >= 0 ) {
f_value = f_value.replace( "%", "" );
if ( !isNaN( f_value ) ) {
f_value = parseFloat( f_value ) / 100;
}
if ( typeof f_value !== 'undefined' ) {
if ( f_value.indexOf("%") >= 0 ) {
f_value = f_value.replace( "%", "" );
if ( !isNaN( f_value ) ) {
f_value = parseFloat( f_value ) / 100;
}
}
}
if ( isNaN( f_value ) || f_value == '' || !f_value || typeof f_value === 'undefined' ) {
......
This diff is collapsed.
This diff is collapsed.
......@@ -3,7 +3,7 @@ Contributors: kstover, jameslaws, daveshine
Tags: form, forms, contact form, custom form, form builder, form creator, form manager, form creation, contact forms, custom forms, forms builder, forms creator, forms manager, forms creation, form administration,
Requires at least: 3.4
Tested up to: 3.6
Stable tag: 2.2.46
Stable tag: 2.2.47
License: GPLv2 or later
Forms created with a simple drag and drop interface. Contact forms, Email collection forms, or any other form you want on your WordPress site.
......@@ -76,12 +76,16 @@ For help and video tutorials, please visit our website: [Ninja Forms Documentati
== Upgrade Notice ==
= 2.2.46 =
= 2.2.47 =
*Bugs:*
* Fixed a bug that could prevent the ninja_forms_field shortcode from being processed properly.
* Fixed a bug that could prevent the list of fields from being attached to both user and admin emails.
* Fixed several bugs that could prevent calculation fields from working properly.
* Fixed several bugs that could cause calculation fields to show incorrect totals upon page load.
*Changes:*
* Added files to core to make updating extensions easier for developers.
== Requested Features ==
......@@ -89,6 +93,17 @@ If you have any feature requests, please feel free to visit [ninjaforms.com](htt
== Changelog ==
= 2.2.47 =
*Bugs:*
* Fixed several bugs that could prevent calculation fields from working properly.
* Fixed several bugs that could cause calculation fields to show incorrect totals upon page load.
*Changes:*
* Added files to core to make updating extensions easier for developers.
= 2.2.46 =
*Bugs:*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment