Commit 82c7f563 authored by metzlerd's avatar metzlerd
Browse files

Refactor to move getValue inside of FrxData object.

parent b9ae2af2
......@@ -55,6 +55,71 @@ class FrxData {
}
/**
* Get the value from the data.
* This is used by token_replace method to extract the data based on the path provided.
* @param $data
* @param $key
* @return unknown_type
*/
public function getValue($key, $formatter = NULL) {
$retvar = '';
// Default to theo current context
$data = $this->currentContext();
// Determine if we have a . syntax for the id.
$raw_key=$key;
if ($key && strpos($key, '.')) {
@list($id, $path) = explode('.', $key, 2);
if ($this->contextExists($id)) {
$data = $this->getContext($id);
$key = $path;
}
}
if (is_array($data)) {
$retvar = @$data[$key];
}
elseif (is_object($data)) {
if (strpos($key, '=')===0) {
$retvar = $this->simplexml_evaluate($data, ltrim($key, '='));
}
else {
$rows = @$data->xpath($key);
if ($rows === FALSE) {
drupal_set_message(t('Invalid field: "%s"', array('%s' => $key)), 'error', FALSE);
}
$x ='';
if ($rows) $x = $rows[0];
if ($x) $retvar = $x->asXML();
// Check to see if there are child nodes
// If so use asXML otherwise string cast.
if ($retvar && strpos($retvar, '<')!==FALSE) {
// Find the end of the first tag.
$p = strpos($retvar, '>');
$retvar = substr_replace($retvar, '', 0, $p+1);
$p = strrpos($retvar, '<', -1);
$retvar = substr_replace($retvar, '', $p, strlen($retvar) - $p);
}
else {
$retvar = (string)$x;
}
}
}
if (is_object($formatter) && method_exists($formatter, 'format')) {
$retvar = $formatter->format($retvar, $key, $data);
}
if (!is_array($retvar)) $retvar = trim((string)$retvar);
return $retvar;
}
/**
* Allows override of a value for the current context.
* @param String $key
......@@ -139,4 +204,7 @@ class FrxData {
drupal_set_message(filter_xss('cur_context ' . $this->id . '<br/>Stack<br/><pre>' . print_r($this->cur_context, 1) . '</pre>'));
}
}
\ No newline at end of file
......@@ -86,4 +86,6 @@ class FrxFields {
return $value;
}
}
\ No newline at end of file
......@@ -56,61 +56,10 @@ class FrxSyntaxEngine {
* @return unknown_type
*/
protected function get_value( $key, $raw=FALSE) {
$retvar = '';
// Default to theo current context
$data = Frx::Data()->currentContext();
$f=NULL;
if (!$raw) $f = $this->formatter;
$retvar = Frx::Data()->getValue($key, $f );
// Determine if we have a . syntax for the id.
$raw_key=$key;
if ($key && strpos($key, '.')) {
@list($id, $path) = explode('.', $key, 2);
if (Frx::Data()->contextExists($id)) {
$data = Frx::Data()->getContext($id);
$key = $path;
}
}
if (is_array($data)) {
$retvar = @$data[$key];
}
elseif (is_object($data)) {
if (strpos($key, '=')===0) {
$retvar = $this->simplexml_evaluate($data, ltrim($key, '='));
}
else {
$rows = @$data->xpath($key);
if ($rows === FALSE) {
drupal_set_message(t('Invalid field: "%s"', array('%s' => $key)), 'error', FALSE);
}
$x ='';
if ($rows) $x = $rows[0];
if ($x) $retvar = $x->asXML();
// Check to see if there are child nodes
// If so use asXML otherwise string cast.
if ($retvar && strpos($retvar, '<')!==FALSE) {
// Find the end of the first tag.
$p = strpos($retvar, '>');
$retvar = substr_replace($retvar, '', 0, $p+1);
$p = strrpos($retvar, '<', -1);
$retvar = substr_replace($retvar, '', $p, strlen($retvar) - $p);
}
else {
$retvar = (string)$x;
}
}
}
// Call the formatter object if neccessary
$f = $this->formatter;
if (!$raw && is_object($f) && method_exists($f, 'format')) {
$retvar = $f->format($retvar, $raw_key, $data);
}
if (!is_array($retvar)) $retvar = trim((string)$retvar);
return $retvar;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment