Skip to content

Commit

Permalink
Merge branch 'develop' into feature/3204-2
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Pollock authored May 24, 2019
2 parents 24ffd39 + 57a7ae6 commit 2887469
Show file tree
Hide file tree
Showing 16 changed files with 377 additions and 151 deletions.
25 changes: 24 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ env:

matrix:
include:
- php: 7.3
env: WP_VERSION=latest TEST_JS=yes
- php: 7.2
env: WP_VERSION=latest TEST_JS=yes
- php: 7.1
env: WP_VERSION=trunk TEST_JS=yes
- php: 7.1
Expand All @@ -43,7 +47,26 @@ before_script:
- |
if [[ ! -z "$WP_VERSION" ]] ; then
bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
composer global require "phpunit/phpunit=4.8.*|5.7.*"
if [[ "$WP_TRAVISCI" == "travis:phpunit" ]]; then
case "$TRAVIS_PHP_VERSION" in
7.4snapshot|7.3|7.2|7.1|nightly)
echo "Using PHPUnit 7.x"
travis_retry composer global require "phpunit/phpunit:^7"
;;
7.0)
echo "Using PHPUnit 6.x"
travis_retry composer global require "phpunit/phpunit:^6"
;;
5.6)
echo "Using PHPUnit 4.x"
travis_retry composer global require "phpunit/phpunit:^4"
;;
*)
echo "No PHPUnit version handling for PHP version $TRAVIS_PHP_VERSION"
exit 1
;;
esac
fi
fi
- |
if [[ "$WP_TRAVISCI" == "phpcs" ]] ; then
Expand Down
12 changes: 9 additions & 3 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ module.exports = function (grunt) {
'!.env',
'!db-error.php',
'!webpack.config.js',
'!docker-compose.yml'
'!docker-compose.yml',
'!wp-content/**',
'!wordpress/**'
];

//Include webpacked clients
Expand Down Expand Up @@ -287,7 +289,7 @@ module.exports = function (grunt) {


exec: {
composerDist: 'composer clearcache && composer update --prefer-dist --no-dev --optimize-autoloader --ignore-platform-reqs'
composerDist: 'composer clearcache && rm -rf vendor && composer update --prefer-dist --no-dev --optimize-autoloader --ignore-platform-reqs'
}

});
Expand All @@ -307,7 +309,11 @@ module.exports = function (grunt) {

grunt.registerTask( 'version_number', [ 'replace' ] );
grunt.registerTask( 'build', [ 'version_number', 'default', 'make' ] );
grunt.registerTask( 'make', [ 'exec:composerDist', 'mkdir:build', 'copy:build' ] );
grunt.registerTask( 'make', [
// 'exec:composerDist',
'mkdir:build',
'copy:build'
] );



Expand Down
2 changes: 1 addition & 1 deletion assets/build/css/caldera-forms-front.min.css

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion assets/css/caldera-forms-front.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion assets/js/caldera-forms-front.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*! GENERATED SOURCE FILE caldera-forms - v1.8.4 - 2019-05-24 */var resBaldrickTriggers;

jQuery(function($){
function fieldErrors(fields, $form, $notice) {
for (var i in fields) {
Expand Down
3 changes: 2 additions & 1 deletion assets/js/entry-viewer-2.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*! GENERATED SOURCE FILE caldera-forms - v1.8.4 - 2019-05-24 *//**
/*! GENERATED SOURCE FILE caldera-forms - v1.8.4 - 2019-05-24 */
/**
* API Client for Caldera Forms API for a single form
*
* @since 1.5.0
Expand Down
103 changes: 54 additions & 49 deletions assets/js/frontend-script-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ var cf_jsfields_init, cf_presubmit;
window.addEventListener("load", function(){
(function( $ ) {
'use strict';
//Catch if window.wp is undefined
var wpUndefined = undefined === typeof window.wp;

window.CALDERA_FORMS = {};

Expand All @@ -362,55 +364,58 @@ window.addEventListener("load", function(){
if ('object' === typeof CFFIELD_CONFIG[instance] ) {
$form = $( document.getElementById( form_id ));

if ( ! protocolChecked ) {
//check for protocol mis-match on submit url
protocolCheck = new CalderaFormsCrossOriginWarning($el, $, CFFIELD_CONFIG[instance].error_strings);
protocolCheck.maybeWarn();

//don't check twice
protocolChecked = true;
}

if ( ! jQueryChecked && CFFIELD_CONFIG[instance].error_strings.hasOwnProperty( 'jquery_old' ) ) {
//check for old jQuery
jQueryCheck = new CalderaFormsJQueryWarning($el, $, CFFIELD_CONFIG[instance].error_strings);
jQueryCheck.maybeWarn();

//don't check twice
jQueryChecked = true;
}

formId = $el.data( 'form-id' );
config = CFFIELD_CONFIG[instance].configs;

var state = new CFState(formId, $ );
state.init( CFFIELD_CONFIG[instance].fields.defaults,CFFIELD_CONFIG[instance].fields.calcDefaults );

if( 'object' !== typeof window.cfstate ){
window.cfstate = {};
}

window.cfstate[ form_id ] = state;

$form.find( '[data-sync]' ).each( function(){
var $field = $( this );
if ( ! $field.data( 'unsync' ) ) {
new CalderaFormsFieldSync($field, $field.data('binds'), $form, $, state);
}
});


config_object = new Caldera_Forms_Field_Config( config, $(document.getElementById(form_id)), $, state );
config_object.init();
$( document ).trigger( 'cf.form.init',{
$form: $form,
idAttr: form_id,
formId: formId,
state: state,
fieldIds: CFFIELD_CONFIG[instance].fields.hasOwnProperty( 'ids' ) ? CFFIELD_CONFIG[instance].fields.ids : [],
nonce: jQuery( '#_cf_verify_' + formId ).val()
});

if( wpUndefined ){
$( $form.data( 'target' ) ).append( '<div class="alert alert-warning">' + CFFIELD_CONFIG[instance].error_strings.wp_not_defined + '</div>' );
}else{
if ( ! protocolChecked ) {
//check for protocol mis-match on submit url
protocolCheck = new CalderaFormsCrossOriginWarning($el, $, CFFIELD_CONFIG[instance].error_strings);
protocolCheck.maybeWarn();

//don't check twice
protocolChecked = true;
}

if ( ! jQueryChecked && CFFIELD_CONFIG[instance].error_strings.hasOwnProperty( 'jquery_old' ) ) {
//check for old jQuery
jQueryCheck = new CalderaFormsJQueryWarning($el, $, CFFIELD_CONFIG[instance].error_strings);
jQueryCheck.maybeWarn();

//don't check twice
jQueryChecked = true;
}

formId = $el.data( 'form-id' );
config = CFFIELD_CONFIG[instance].configs;

var state = new CFState(formId, $ );
state.init( CFFIELD_CONFIG[instance].fields.defaults,CFFIELD_CONFIG[instance].fields.calcDefaults );

if( 'object' !== typeof window.cfstate ){
window.cfstate = {};
}

window.cfstate[ form_id ] = state;

$form.find( '[data-sync]' ).each( function(){
var $field = $( this );
if ( ! $field.data( 'unsync' ) ) {
new CalderaFormsFieldSync($field, $field.data('binds'), $form, $, state);
}
});


config_object = new Caldera_Forms_Field_Config( config, $(document.getElementById(form_id)), $, state );
config_object.init();
$( document ).trigger( 'cf.form.init',{
$form: $form,
idAttr: form_id,
formId: formId,
state: state,
fieldIds: CFFIELD_CONFIG[instance].fields.hasOwnProperty( 'ids' ) ? CFFIELD_CONFIG[instance].fields.ids : [],
nonce: jQuery( '#_cf_verify_' + formId ).val()
});
}

}
});
Expand Down
1 change: 1 addition & 0 deletions assets/js/parsley.min.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*! GENERATED SOURCE FILE caldera-forms - v1.8.4 - 2019-05-24 *//*!
* Parsley.js
* Version 2.8.1 - built Sat, Feb 3rd 2018, 2:27 pm
* http://parsleyjs.org
Expand Down
1 change: 1 addition & 0 deletions assets/js/vue.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*! GENERATED SOURCE FILE caldera-forms - v1.8.4 - 2019-05-24 *//*!
* Vue.js v2.1.6
* (c) 2014-2016 Evan You
* Released under the MIT License.
Expand Down
4 changes: 2 additions & 2 deletions caldera-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin URI: https://CalderaForms.com
Description: Easy to use, grid based responsive form builder for creating simple to complex forms.
Author: Caldera Labs
Version: 1.8.4
Version: 1.8.5-b.1
Author URI: http://CalderaLabs.org
Text Domain: caldera-forms
GitHub Plugin URI: https://github.com/CalderaWP/caldera-forms
Expand Down Expand Up @@ -62,7 +62,7 @@ function caldera_forms_wp_version_nag()
} else {
define('CFCORE_PATH', plugin_dir_path(__FILE__));
define('CFCORE_URL', plugin_dir_url(__FILE__));
define( 'CFCORE_VER', '1.8.4' );
define( 'CFCORE_VER', '1.8.5-b.1' );
define('CFCORE_EXTEND_URL', 'https://api.calderaforms.com/1.0/');
define('CFCORE_BASENAME', plugin_basename(__FILE__));

Expand Down
128 changes: 126 additions & 2 deletions classes/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*
*/

use MathParser\StdMathParser;
use MathParser\Interpreting\Evaluator;

class Caldera_Forms
{

Expand Down Expand Up @@ -1390,6 +1393,92 @@ static public function akismet_scanner($config, $form)

}

/**
* Catch known functions that were supported at https://calderaforms.com/doc/calculation-fields/ and are not sipported by parser https://github.com/denissimon/formula-parser
*
* @since 1.8.5
*
* @param string $formula The string used to evaluate the math formula
*
* @return bool||string of coma seperated deprecated symbol
*/
static public function check_deprecated_math_functions($formula)
{
//List known depracated functions
$deprecated = array( ',', '**', 'pow', 'acos', 'asin', 'atan', 'atan2', 'max', 'min', 'random');
//Look for matching known symbol in formula and push it in a symbols array
foreach ($deprecated as $symbol) {
if (strpos($formula, $symbol) !== FALSE) {
$symbols[] = $symbol;
}
}
//If symbols array is not empty convert it to a string and return the string
if(is_array($symbols) && !empty($symbols)){
$symbols = implode( ',', $symbols);
return $symbols;
} else {
//Else return false
return false;
}

}

/**
* Calculation based on create_function() ( deprecated since PHP 7.2.0 )
*
* @since 1.8.5
*
* @param string $formula that needs to be parsed and processed as a calculation
*
* @return result of calculation
*/
static public function original_calculation_job( $formula )
{
$total_function = create_function(null, 'return ' . $formula . ';');
$total = $total_function();

return $total;
}

/**
* Process when php >= 7.2.0 and deprecated is caught
*
* @since 1.8.5
*
* @param string $formula to be sent to original calculation job
* @param string $deprecated function or symbol caught
*
* @return original process and notice for admin users
*/
static public function calculation_deprecated_caught_process( $formula, $deprecated )
{
if( current_user_can( Caldera_Forms::get_manage_cap('admin') ) ) {

$message = sprintf(
'"%s" %s',
$deprecated,
__('has been deprecated in calculation fields for compatibility with PHP 7.2 or later', 'caldera-forms')
);

/**
* The notice currentl only works whe ajax is enabled
*
* TODO Add notice for non ajax submissions
*/
add_filter('caldera_forms_render_notices', function( $out ) use ( $message ){

//Add an error notice holding the $message
$out[ 'error' ][ 'note' ] = $message;

return $out;

}, 25);

}

return self::original_calculation_job($formula);
}

/**
* Process a calculation field.
*
Expand Down Expand Up @@ -1439,6 +1528,8 @@ static public function run_calculation($value, $field, $form)
if (false !== strpos($formula, $fid)) {
$number = Caldera_Forms_Field_Calculation::get_value($form_field, $form);

$number = '(' . $number . ')';

$formula = str_replace($fid, $number, $formula);
}
}
Expand All @@ -1447,9 +1538,42 @@ static public function run_calculation($value, $field, $form)
return new WP_Error($field['ID'] . '-calculation',
__('Calculation is invalid (division by zero)', 'caldera-forms'));
}

//If PHP version is less than 7.2.0, continue using old function
if(version_compare(PHP_VERSION, '7.2.0', '<')){

$total_function = create_function(null, 'return ' . $formula . ';');
$total = $total_function();
$total = self::original_calculation_job($formula);

} else {
//else avoid using create_function() when using PHP version >= 7.2.0

//Check if the formula use a symbol or function not supported by the parser but declared as supported at https://calderaforms.com/doc/calculation-fields/
$deprecated = self::check_deprecated_math_functions( $formula );

//Use parser if no deprecated caught
if( $deprecated === false ){

try {
//Initiate parser
$parser = new StdMathParser();
// Generate an abstract syntax tree
$AST = $parser->parse($formula);
// Do something with the AST, e.g. evaluate the expression:
$evaluator = new Evaluator();
//Get result
$total = $AST->accept($evaluator);

} catch( Exception $e) {
//Return to old process if an Exception was returned and display a warning for admins
$total = self::calculation_deprecated_caught_process( $formula, __('A symbol in the formula', 'caldera_forms') );
}

} else {
//else add warning for admins and run original process
$total = self::calculation_deprecated_caught_process( $formula, $deprecated );
}

}

if (is_infinite($total) || !is_numeric($total)) {
return new WP_Error($field['ID'] . '-calculation', __('Calculation is invalid', 'caldera-forms'));
Expand Down
Loading

0 comments on commit 2887469

Please sign in to comment.