function _viewfield_get_view_args in Viewfield 6.2
Same name and namespace in other branches
- 6 theme/viewfield.theme.inc \_viewfield_get_view_args()
- 7.3 viewfield.module \_viewfield_get_view_args()
- 7.2 viewfield.module \_viewfield_get_view_args()
Perform argument replacement
1 call to _viewfield_get_view_args()
- theme_viewfield_formatter_default in ./
viewfield.module - Return a themed view avoiding viewfield recursion.
File
- ./
viewfield.module, line 329 - Core functions.
Code
function _viewfield_get_view_args($vargs, $node) {
$args = array();
// Prevent token_replace() from running this function a second time
// before it completes the first time.
static $tokens = TRUE;
if ($tokens && !empty($vargs)) {
$pos = 0;
while ($pos < strlen($vargs)) {
$found = FALSE;
// If string starts with a quote, start after quote and get everything
// before next quote.
if (strpos($vargs, '"', $pos) === $pos) {
if (($quote = strpos($vargs, '"', ++$pos)) !== FALSE) {
// Skip pairs of quotes.
while (!(($ql = strspn($vargs, '"', $quote)) & 1)) {
$quote = strpos($vargs, '"', $quote + $ql);
}
$args[] = str_replace('""', '"', substr($vargs, $pos, $quote + $ql - $pos - 1));
$pos = $quote + $ql + 1;
$found = TRUE;
}
}
elseif (($comma = strpos($vargs, ',', $pos)) !== FALSE) {
// Otherwise, get everything before next comma.
$args[] = substr($vargs, $pos, $comma - $pos);
// Skip to after comma and repeat
$pos = $comma + 1;
$found = TRUE;
}
if (!$found) {
$args[] = substr($vargs, $pos);
$pos = strlen($vargs);
}
}
// Try to replace tokens if $args might contain one.
if (strpos($vargs, '[') !== FALSE && module_exists('token')) {
$tokens = FALSE;
// If the view field is being loaded as a "view field" of "view row",
// instead of a simple "node field", the node object is not fully populated:
// we need a full node to perform a correct replacement.
$node = node_load($node->nid);
foreach ($args as $key => $text) {
$args[$key] = token_replace($text, 'node', $node);
}
$tokens = TRUE;
}
// For backwards compatibility, we scan for %nid, etc.
foreach ($args as $key => $value) {
$args[$key] = strtr($value, array(
'%nid' => $node->nid,
'%author' => isset($node->uid) ? $node->uid : (isset($node_values->uid) ? $node_values->uid : NULL),
'%viewer' => $GLOBALS['user']->uid,
));
}
}
return $args;
}