function wikiplugin_trackerif ($data, $params) { global $trklib; $test = null; $values = array(); $dataelse = ''; if (strpos($data, '{ELSE}')) { // Else bloc when test does not pass $dataelse = substr($data, strpos($data, '{ELSE}')+6); $data = substr($data, 0, strpos($data, '{ELSE}')); } if (empty($_REQUEST["trackerId"])) { $trackerId = $trklib->get_tracker_for_item($_REQUEST['itemId']); } else { $trackerId = $_REQUEST["trackerId"]; } if (!$trackerId || !isset($_REQUEST['itemId'])) { // Edit mode if (!isset($params['ignore']) || $params['ignore'] == 'y') { return $data; } return $dataelse; } try { // Parse test $test = LDAPFilter::parse($params['test']); } catch (Exception $e) { return $e->getMessage(); } $xfields = $trklib->list_tracker_fields($trackerId); foreach ($xfields['data'] as $field) { // Retrieve values from the current item $values[$field['fieldId']] = $trklib->get_item_value($trackerId, $_REQUEST['itemId'], $field['fieldId']); } if (!wikiplugin_trackerif_test($test, $values)) { if ($dataelse) { return $dataelse; } return ''; } return $data; }
/** * Parse FILTER into a LDAPFilter object * * This parses an filter string into LDAPFilter objects. * * @param string $FILTER The filter string * * @access static * @return LDAPFilter|Net_LDAP_Error */ function parse($FILTER) { if (preg_match('/^\\((.+?)\\)$/', $FILTER, $matches)) { if (in_array(substr($matches[1], 0, 1), array('!', '|', '&'))) { // extract logical operator and subfilters $log_op = substr($matches[1], 0, 1); $remaining_component = substr($matches[1], 1); // bite off the next filter part and parse $subfilters = array(); while (preg_match('/^(\\(.+?\\))(.*)/', $remaining_component, $matches)) { $remaining_component = $matches[2]; array_push($subfilters, LDAPFilter::parse($matches[1])); } // combine subfilters using the logical operator $filter_o = LDAPFilter::combine($log_op, $subfilters); return $filter_o; } else { // This is one leaf filter component, do some syntax checks, then escape and build filter_o // $matches[1] should be now something like "foo=bar" // detect multiple leaf components if (stristr($matches[1], ')(')) { throw new Exception('Filter parsing error: invalid filter syntax - multiple leaf components detected'); } else { $filter_parts = preg_split('/(?<!\\\\)(=|=~|>|<|>=|<=)/', $matches[1], 2, PREG_SPLIT_DELIM_CAPTURE); if (count($filter_parts) != 3) { throw new Exception('Filter parsing error: invalid filter syntax - unknown matching rule used'); } else { $filter_o = new LDAPFilter(); $value = $filter_parts[2]; $filter_o->_filter = '(' . $filter_parts[0] . $filter_parts[1] . $value . ')'; return $filter_o; } } } } else { throw new Exception('Filter parsing error: invalid filter syntax - filter components must be enclosed in round brackets'); } }