public function displayDatasourceFilterPanel(&$wrapper, $data = NULL, $errors = NULL, $fieldnamePrefix = NULL, $fieldnamePostfix = NULL) { if ($data == NULL) { $data = '(if value of (param_or_value_here) is (param_or_value_here))'; } $e = Conditionalizer::parse($data); if (empty($e)) { // Strip all parameters just to see if there was invalid expression there or none at all $e = preg_replace(array('@{(([^}:]+)|[^}]+?:([^}:]+))?}@i', '@{\\$[^}]+}@i', '@{([^}\\$]+)}@i'), array('{$2$3}', 'yes', '$1'), $data); $e = array_map('trim', preg_split('/(?<!\\\\)[,\\+] /', $e, -1, PREG_SPLIT_NO_EMPTY)); if (!empty($e)) { $e = array_diff($e, array('yes', 'no')); // Make array non-empty if all values are either 'yes' or 'no', otherwise make it empty to mark wrong syntax $e = count($e) > 0 ? array() : array('ok'); } } // Copy content generated by parent::displayDatasourceFilterPanel(), so we can wrap it with error if needed $wrapper->appendChild(new XMLElement('header', '<h4>' . $this->get('label') . '</h4> <span>' . $this->name() . '</span>', array('data-name' => $this->get('label') . ' (' . $this->name() . ')'))); $label = Widget::Label(__('Value')); $label->appendChild(Widget::Input('fields[filter]' . ($fieldnamePrefix ? '[' . $fieldnamePrefix . ']' : '') . '[' . $this->get('id') . ']' . ($fieldnamePostfix ? '[' . $fieldnamePostfix . ']' : ''), $data ? General::sanitize($data) : null)); $wrapper->appendChild(empty($e) ? Widget::Error($label, __('Invalid syntax')) : $label); $params = Conditionalizer::listParams(); if (empty($params)) { return; } $optionlist = new XMLElement('ul'); $optionlist->setAttribute('class', 'tags'); $optionlist->appendChild(new XMLElement('li', 'yes', array('title' => 'Exact string value'))); $optionlist->appendChild(new XMLElement('li', 'no', array('title' => 'Exact string value'))); foreach ($params as $param => $value) { $optionlist->appendChild(new XMLElement('li', $param, array('class' => '{' . $param . '}', 'title' => $value ? __('Value of %s returned from another data source', array($value)) : __('Value found in URL path')))); } $wrapper->appendChild($optionlist); }
public function appendConditionalizer(&$context) { /* 'oPage' => &$this->Page */ $callback = Symphony::Engine()->getPageCallback(); if ($callback['driver'] != 'blueprintsdatasources' || !is_array($callback['context']) || empty($callback['context'])) { return; } // Find data source handle. $handle = NULL; if ($callback['context'][0] == 'edit' && !empty($callback['context'][1])) { $handle = $callback['context'][1]; } // Find current Expression values. $data = ''; if (isset($_POST['conditionalizer'])) { $data = $_POST['conditionalizer']; } else { if (!empty($handle)) { $existing = DatasourceManager::create($handle, NULL, false); if (!empty($existing)) { if (isset($existing->dsParamConditionalizer)) { $data = $existing->dsParamConditionalizer; } if (!empty($existing->dsParamROOTELEMENT)) { $handle = $existing->dsParamROOTELEMENT; } } } } $fieldset = new XMLElement('fieldset'); $fieldset->setAttribute('class', 'settings conditionalizer'); $fieldset->appendChild(new XMLElement('legend', __('Conditionalizer'))); $fieldset->appendChild(new XMLElement('script', NULL, array('src' => URL . '/extensions/conditionalizer/assets/conditionalizer.js', 'type' => 'text/javascript'))); $label = Widget::Label(__('Expression')); $label->appendChild(Widget::Textarea('conditionalizer', 6, 50, General::sanitize($data), array('class' => 'code'))); if (!class_exists('Conditionalizer')) { require_once EXTENSIONS . '/conditionalizer/lib/class.conditionalizer.php'; } $e = Conditionalizer::parse($data); if (empty($e)) { // Strip all parameters just to see if there was invalid expression there or none at all $e = preg_replace(array('@{(([^}:]+)|[^}]+?:([^}:]+))?}@i', '@{\\$[^}]+}@i', '@{([^}\\$]+)}@i'), array('{$2$3}', 'yes', '$1'), $data); $e = array_map('trim', preg_split('/(?<!\\\\)[,\\+] /', $e, -1, PREG_SPLIT_NO_EMPTY)); if (!empty($e)) { $e = array_diff($e, array('yes', 'no')); // Make array non-empty if all values are either 'yes' or 'no', otherwise make it empty to mark wrong syntax $e = count($e) > 0 ? array() : array('ok'); } } if (empty($e) && !empty($data)) { $fieldset->appendChild(Widget::Error($label, __('Invalid syntax'))); } else { $fieldset->appendChild($label); } // Add list of parameters that may be available. $params = Conditionalizer::listParams(); if (!empty($params)) { $optionlist = new XMLElement('ul'); $optionlist->setAttribute('class', 'tags'); $optionlist->appendChild(new XMLElement('li', 'yes', array('title' => 'Exact string value'))); $optionlist->appendChild(new XMLElement('li', 'no', array('title' => 'Exact string value'))); foreach ($params as $param => $value) { $optionlist->appendChild(new XMLElement('li', $param, array('class' => '{' . $param . '}', 'title' => $value ? __('Value of %s returned from another data source', array($value)) : __('Value found in URL path')))); } $fieldset->appendChild($optionlist); } $nodes = $context['oPage']->Form->getChildren(); for ($i = count($nodes) - 1; $i >= 0; $i--) { if ($nodes[$i]->getName() == 'div' && preg_match('/(^|\\s)actions(\\s|$)/i', $nodes[$i]->getAttribute('class'))) { $context['oPage']->Form->insertChildAt($i, $fieldset); break; } } }