function contemplate_nodeapi in Content Templates (Contemplate) 6
Same name and namespace in other branches
- 5 contemplate.module \contemplate_nodeapi()
Implementation of hook_nodeapi().
File
- ./
contemplate.module, line 137 - Create templates to customize teaser and body content.
Code
function contemplate_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
// added $xml_elements, this will add the ability to add other
// xml_elements to rss feeds other than just the file enclosure
// in PHP 4 default variables may not be passed by reference so for PHP 4
// compatability we need to make sure this variable exists and is passed
// in for each call to contemplate_eval()
$xml_elements = array();
switch ($op) {
case 'rss item':
if ($template = contemplate_get_template($node->type)) {
if (CONTEMPLATE_RSS_ENABLED & $template['flags'] && trim($template['rss'])) {
// only if there's content in teaser field
$rss = contemplate_eval($template['rss'], $node, $xml_elements);
if (isset($xml_elements)) {
$return = $xml_elements;
}
// set both teaser and body because we don't know how they've set Drupal
$node->teaser = $rss;
$node->body = $rss;
if (trim($template['enclosure'])) {
if ($file = contemplate_eval_enclosure($template['enclosure'], $node, $xml_elements)) {
$return[] = array(
'key' => 'enclosure',
'attributes' => array(
'url' => file_create_url($file->filepath),
'length' => $file->filesize,
'type' => $file->filemime,
),
);
}
}
return $return;
}
}
break;
case 'alter':
if ($template = contemplate_get_template($node->type)) {
if ($teaser) {
if (CONTEMPLATE_TEASER_ENABLED & $template['flags'] && trim($template['teaser'])) {
// only if there's content in teaser field
$node->teaser = contemplate_eval($template['teaser'], $node, $xml_elements);
}
}
elseif (CONTEMPLATE_BODY_ENABLED & $template['flags'] && trim($template['body'])) {
// only if there's content in the body field
$node->body = contemplate_eval($template['body'], $node, $xml_elements);
}
}
break;
case 'update index':
if (variable_get('contemplate_before_search_index', FALSE)) {
contemplate_nodeapi($node, 'alter');
return $node->body;
}
break;
}
}