function smd_if($atts,$thing) { global $thisarticle, $pretext; extract(lAtts(array( 'field' => '', 'operator' => 'eq', 'value' => 'NULL', 'logic' => 'and', 'debug' => '0', ), $atts)); // Special field names that refer to $pretext - everything else is assumed to exist // in $thisarticle so custom fields can be used $allPtxt = array( "id" => $pretext['id'], "section" => $pretext['s'], "category" => $pretext['c'], "query" => $pretext['q'], "pg" => $pretext['pg'], "status" => $pretext['status'], "next_id" => ((isset($pretext['next_id'])) ? $pretext['next_id'] : ''), "next_title" => ((isset($pretext['next_title'])) ? $pretext['next_title'] : ''), "prev_id" => ((isset($pretext['prev_id'])) ? $pretext['prev_id'] : ''), "prev_title" => ((isset($pretext['prev_title'])) ? $pretext['prev_title'] : ''), ); $allOps = array( "eq" => "'FIELD' === 'VALUE'", "not" => "'FIELD' !== 'VALUE'", "gt" => "'FIELD' > 'VALUE'", "ge" => "'FIELD' >= 'VALUE'", "lt" => "'FIELD' < 'VALUE'", "le" => "'FIELD' <= 'VALUE'", "begins" => "strpos('FIELD', 'VALUE') === 0", "contains" => "strpos('FIELD', 'VALUE') !== false", "isnum" => "is_numeric('FIELD')", "isempty" => "'FIELD' == ''", "isused" => "'FIELD' != ''", ); $fields = do_list($field); $ops = do_list($operator); $vals = do_list($value); $out = array(); for ($idx = 0; $idx < count($fields); $idx++) { $fld = $fields[$idx]; $val = $vals[$idx]; $op = $ops[$idx]; // Find the real value of the given variable if (array_key_exists($fld, $allPtxt)) { $fld = $allPtxt[$fld]; } else if (strpos($fld, "urlvar") !== false) { $parts = explode(":", $fld); if (count($parts) == 2) { if (isset($_GET[$parts[1]])) { $fld = $_GET[$parts[1]]; } } } else if (strpos($fld, "svrvar") !== false) { $parts = explode(":", $fld); if (count($parts) == 2) { if (isset($_SERVER[$parts[1]])) { $fld = $_SERVER[$parts[1]]; } } } else if (isset($thisarticle[$fld])) { $fld = $thisarticle[$fld]; } // Get the operator replacement code if (array_key_exists($op, $allOps)) { $op = $allOps[$op]; } else { $op = $allOps["eq"]; } // Find the real value to compare against (may be another field) if (array_key_exists($val, $allPtxt)) { $val = $allPtxt[$fld]; } else if (strpos($val, "urlvar") !== false) { $parts = explode(":", $val); if (count($parts) == 2) { if (isset($_GET[$parts[1]])) { $val = $_GET[$parts[1]]; } } } else if (strpos($val, "svrvar") !== false) { $parts = explode(":", $val); if (count($parts) == 2) { if (isset($_SERVER[$parts[1]])) { $val = $_SERVER[$parts[1]]; } } } else if (isset($thisarticle[$val])) { $val = $thisarticle[$val]; } // Replace the string parts... $cmd = str_replace("FIELD", $fld, $op); $cmd = "\$out[] = (".str_replace("VALUE", (($val=='' && strpos($op, "strpos") !== false) ? ' ' : $val), $cmd).") ? 'true' : 'false';"; if ($debug) { dmp($cmd); } // ... and evaluate the expression eval($cmd); } if ($debug) { dmp($out); } // Check logic $result = true; if (strtolower($logic) == "and" && in_array("false", $out)) { $result = false; } if (strtolower($logic) == "or" && !in_array("true", $out)) { $result = false; } return parse(EvalElse($thing, $result)); }