Reply To: ajax request result versus widget result & foreach error

Author Replies
sitesurety # Posted on November 8, 2014 at 3:30 pm

ok, i’ve gone through the filter code and it will include any match.. I’ve reversed the loop so that it will do an ‘and’ match (1 or more must be true to be added). Any chance this could be added in a future release as a variable to the function? i.e. Exclusive filter

function filterExclusive($args, $case_sensitive = FALSE) {
$filters = array();
$filtered_items = array();

if (!is_array($args)) {
$args = explode(“&”, $args);
}

// extract the arguments

foreach ($this->_items as $set_item) {
$include = true;

foreach ($args as $arg) {

$m = array();

preg_match ( “/^([\w\-]+)(\#?\=|\#?[\>\<\$\^\*\~\!]=|\#?\>|\#?\<)(.*)$/” , $arg, $m );

if ($m && count($m) == 4) {
$fn = $m[1];
$op = $m[2];

if ($case_sensitive) {
$val = $m[3];
} else {
$val = strtolower($m[3]);
}

$f = $set_item->f($fn);

$fields = array();

$fields[] = $f;

foreach ($fields as $f) {

if ($include) {

$nv = 0;
$nval = 0;

if ($case_sensitive) {
$fv = $f->raw();
} else {
$fv = strtolower($f->raw());
}

if (is_numeric($fv)) {
$nv = (float) $fv;
}

if (is_numeric($val)) {
$nval = (float) $val;
}

// Check each item for match individually
// Return true if matches
// If matches all operators, then true (loop for each case)

switch ($op) {
case “>” :
$include = $fv > $val;
break;
case “#>” :
$include = $nv > $nval;
break;
case “<” :
$include = $fv < $val;
break;
case “#<” :
$include = $nv < $nval;
break;
case “>=” :
$include = $fv >= $val;
break;
case “#>=” :
$include = $nv >= $nval;
break;
case “<=” :
$include = $fv <= $val;
break;
case “#<=” :
$include = $nv <= $nval;
break;
case “*=” :
$include = ( strpos($fv, $val) !== FALSE );
break;
case “~=” :
$include = preg_match(“/(\s|^)”.$val.”(\s|$)/”, $fv );
break;
case “!=” :
$include = $val != $fv;
break;
case “#!=” :
$include = $nval != $nv;
break;
case “^=” :
$include = ( $val == substr($fv, 0, strlen($val)) );
break;
case “$=” :
$include = ( $val == substr($fv, 0, -strlen($val)) );
break;
case “#=” :
$include = ( $nval == $nv );
break;
default: // assume =
$include = ( $val == $fv );
}

} // endif $include

} // endforeach

}

}

if ($include) {
$filtered_items[] = $set_item;
}

}
return new MEOW_VirtualFieldSetCollection($filtered_items);

}

Latest From the Blog

MasterPress 1.3.10 is now available

9th November 2023

MasterPress 1.3.10 is a feature and bugfix release. Workaround for fatal error introduced by changes to WordPress’ wpdb class in WordPress 6.4. Added actions to MPC files upload_field & WF image save_image functions.

Plugin Requirements

MasterPress requires a minimum of WordPress version 4.9, MySQL 5.6, and PHP version 5.6.20.

We also recommend that PHP is configured to use a memory limit of 64MB per request (128MB may be required for sites with higher complexity).

This plug-in is not compatible with the WordPress.com hosted service.

Three AM