quasibrodo
Forum Replies Created
-
Forum: Plugins
In reply to: [SEO Plugin by Squirrly SEO] When squirrly is activated elements don’t workHello,
I was able to activate the advanced settings, and then activate the late load.
It did not resolve the issue.
I’m going with Yoast. I don’t have any more time to troubleshoot this.
Furthermore the whole advanced settings business was mind-boggingly un-intuitive. I’ve been a word-press developer for 5 years and I needed someone to hold my hand to change a setting.
Forum: Plugins
In reply to: [SEO Plugin by Squirrly SEO] When squirrly is activated elements don’t workUnfortunately the advanced settings tab is not present
Hello @salzano
I’m pretty certain you do in fact have an extra ‘)’.
Unfortunately the calculation field validation isn’t terribly robust. It’ll miss stuff like this.
(
(
.3 +
(
({Vehicle type:21} * MAX(1,{Vehicle count:94}) ) +
({Track License (Price):125.2}*{Track License Quantity:126}) +
({Pit License (Price):127.2} * {Pit License Quantity:128}) +
({Camp License (Price):129.2} * {Camp License Quantity:130}) +
({Extra Chairs: (Price):22.2} * {Extra Chairs: (Quantity):22.3}) +
({Extra Tables: (Price):24.2} * {Extra Tables: (Quantity):24.3}) +
{Extra Power::97} +
({Extra Pit Passes: (Price):95.2} * {Quantity:96}) +
({Tent quantity:104}*{Tent (Price):103.2}) +
{Shared Vehicle Fee (Price):87.2}
)
)
* .035
)
)//this final parenthesis is extraSo I fixed the problem by editing the gravityforms-minmax.js and gravityforms-minmax.min.js
I changed [\d\s\W]+ to [\d\s\W]+[^)] so it wouldn’t match with extra parentheses.
I also put the matching and replacing in a while statement so that it would work with nested MIN and MAX functions, such as MAX(MIN(2,3), MIN(4,5))
Finally instead of indexOf( ‘MIN’ ) I changed it to .indexOf( ‘MIN(‘ ) just so it would be less likely to try to parse incorrectly syntaxed functions.
/**
* Gravity Forms MIN/MAX Calculations
* Version 0.3.1
*
* Add MIN/MAX functions to Gravity Forms calculation
*
* Thanks to @michaeldozark for gravityforms-exponent plugin:
* https://github.com/michaeldozark/gravityforms-exponents
*
*/gform.addFilter( ‘gform_calculation_result’, function( result, formulaField, formId, calcObj ) {
/**
* Only evaluate if the field has MIN/MAX present
* Seaching for MIN(/MAX( to be less likely to try parsing incorrectly syntaxed formulae
*
* Technically we should be able to run any formulas through this without
* breaking them, but this way we save some small amount of processing
*
* @link https://www.w3schools.com/jsref/jsref_indexof.asp
* Description ofindexOf
method
*/if ( formulaField.formula.indexOf( ‘MIN(‘ ) > -1 || formulaField.formula.indexOf( ‘MAX(‘ ) > -1 ) {
/**
* Replace field tags with their associated values
*
* @param int formId The ID of the form in use
* @param string formula The value of the “Formula” field entered in the form admin
*
* We are stripping out anything that is not a number, decimal, space, or simple arithmetical operator.
* We are excluding any extra nested parenthesis that match might find [^)]
*
* @param object formulaField The current calculation field object
* @var string fieldFormula
*/
let fieldFormula = calcObj.replaceFieldTags( formId, formulaField.formula, formulaField ), pattern = /(MIN|MAX)\(([\d\s\W]+[^)])\s*\)/gi;/**
* Sanitize the formula in case we have malicious user inputs. This
* prevents malicious code getting passed to oureval
call later in the
* function
*
* @link https://www.w3schools.com/jsref/jsref_replace.asp
* Description ofreplace
method
*
* while is to facilitate parsing nested MIN and MAX functions
*/
while ( fieldFormula.indexOf( ‘MIN(‘ ) > -1 || fieldFormula.indexOf( ‘MAX(‘ ) > -1 ) {let matches = fieldFormula.match(pattern), replaces = [];
for(let i in matches) {
let components = /(MIN|MAX)\(([\d\s\W]+[^)])\s*\)/gi.exec(matches[i]);
let values = components[2].split(‘,’).map((value,index,array) => {
return parseFloat(eval(value.trim()));
});if (components[1] == “MIN”) replaces.push([matches[i], , Math.min(…values)]);
if (components[1] == “MAX”) replaces.push([matches[i], , Math.max(…values)]);
}for(let i in replaces) {
fieldFormula = fieldFormula.replace(replaces[i][0], replaces[i][2]);
}fieldFormula = fieldFormula.replace( /[^0-9\s\n\r\+\-\*\/\^\(\)\.](MIN|MAX)/g, ” );
}
/**
* Set calculation result equal to evaluated string
*
* @link https://www.w3schools.com/jsref/jsref_eval.asp
* Description ofeval
function
*/result = eval(fieldFormula);
}
return result;
} );
gform.addFilter(‘gform_calculation_result’,function(result,formulaField,formId,calcObj){if(formulaField.formula.indexOf(‘MIN(‘)>-1||formulaField.formula.indexOf(‘MAX(‘)>-1){let fieldFormula=calcObj.replaceFieldTags(formId,formulaField.formula,formulaField),pattern=/(MIN|MAX)\(([\d\s\W]+[^)])\s*\)/gi;while(fieldFormula.indexOf(‘MIN(‘)>-1||fieldFormula.indexOf(‘MAX(‘)>-1){let matches=fieldFormula.match(pattern),replaces=[];for(let i in matches){let components=/(MIN|MAX)\(([\d\s\W]+[^)])\s*\)/gi.exec(matches[i]);let values=components[2].split(‘,’).map((value,index,array)=>{return parseFloat(eval(value.trim()))});if(components[1]==”MIN”)replaces.push([matches[i],,Math.min(…values)]);if(components[1]==”MAX”)replaces.push([matches[i],,Math.max(…values)])}for(let i in replaces){fieldFormula=fieldFormula.replace(replaces[i][0],replaces[i][2])}fieldFormula=fieldFormula.replace(/[^0-9\s\n\r\+\-\*\/\^\(\)\.](MIN|MAX)/g,”)}result=eval(fieldFormula)}return result})