| 1 |
<?php |
<?php |
| 2 |
// $Id: contemplate.module,v 1.8.4.62.2.2 2009/09/12 03:46:51 jrglasgow Exp $ |
// $Id: contemplate.module,v 1.8.4.62.2.3 2009/11/08 13:28:48 jrglasgow Exp $ |
| 3 |
// by Jeff Robbins - Lullabot - www.lullabot.com |
// by Jeff Robbins - Lullabot - www.lullabot.com |
| 4 |
|
|
| 5 |
define('CONTEMPLATE_TEASER_ENABLED', 0x0001); |
define('CONTEMPLATE_TEASER_ENABLED', 0x0001); |
| 169 |
} |
} |
| 170 |
} |
} |
| 171 |
|
|
|
/** |
|
|
* Implementation of hook_node_build_alter(). |
|
|
*/ |
|
|
function contemplate_node_build_alter(&$node, $build_mode) { |
|
|
if ($template = contemplate_get_template(node_type_get_type($node))) { |
|
|
switch ($build_mode) { |
|
|
case '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); |
|
|
} |
|
|
case 'full': |
|
|
if (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; |
|
|
} |
|
|
} |
|
|
} |
|
| 172 |
|
|
| 173 |
/** |
/** |
| 174 |
* Implementation of hook_node_update_index(). |
* Implementation of hook_node_update_index(). |
| 489 |
* Get all of the current templates |
* Get all of the current templates |
| 490 |
* Only used on admin page |
* Only used on admin page |
| 491 |
* |
* |
| 492 |
* @return unknown |
* @return array of template arrays |
| 493 |
*/ |
*/ |
| 494 |
function contemplate_get_templates() { |
function contemplate_get_templates() { |
| 495 |
foreach (node_type_get_types() AS $r) { |
foreach (node_type_get_types() AS $r) { |
|
/* |
|
|
$templates[$r->type]['teaser'] = $r->teaser; |
|
|
$templates[$r->type]['body'] = $r->body; |
|
|
$templates[$r->type]['rss'] = $r->rss; |
|
|
$templates[$r->type]['enclosure'] = $r->enclosure; |
|
|
*/ |
|
| 496 |
$templates[$r->type] = contemplate_get_template($r); |
$templates[$r->type] = contemplate_get_template($r); |
| 497 |
} |
} |
| 498 |
return $templates; |
return $templates; |
| 794 |
$node = (object)$node; |
$node = (object)$node; |
| 795 |
|
|
| 796 |
$node = node_build_content($node, $build_mode); |
$node = node_build_content($node, $build_mode); |
|
//drupal_set_message('$node = <pre>'. print_r($node, TRUE) .'</pre>'); |
|
| 797 |
|
|
| 798 |
// Set the proper node part, then unset unused $node part so that a bad |
// Set the proper node part, then unset unused $node part so that a bad |
| 799 |
// theme can not open a security hole. |
// theme can not open a security hole. |
| 811 |
return $node; |
return $node; |
| 812 |
} |
} |
| 813 |
|
|
|
|
|
| 814 |
/** |
/** |
| 815 |
* Copy of drupal_eval(), but extracts the node object so that variables are available to the template |
* Copy of drupal_eval(), but extracts the node object so that variables are available to the template |
| 816 |
* |
* |
| 906 |
|
|
| 907 |
return $output; |
return $output; |
| 908 |
} |
} |
| 909 |
|
/** |
| 910 |
|
* Implementation of hook_node_build_alter(). |
| 911 |
|
*/ |
| 912 |
|
function contemplate_node_build_alter(&$node, $build_mode) { |
| 913 |
|
if ($template = contemplate_get_template(node_type_get_type($node))) { |
| 914 |
|
switch ($build_mode) { |
| 915 |
|
case 'teaser': |
| 916 |
|
if (CONTEMPLATE_TEASER_ENABLED & $template['flags'] && trim($template['teaser'])) { // only if there's content in teaser field |
| 917 |
|
$teaser = contemplate_eval($template['teaser'], $node, $xml_elements); |
| 918 |
|
$node->content['teaser']['items'][0]['#item']['value'] = $teaser; |
| 919 |
|
$node->content['teaser']['items'][0]['#item']['safe'] = $teaser; |
| 920 |
|
} |
| 921 |
|
case 'full': |
| 922 |
|
if (CONTEMPLATE_BODY_ENABLED & $template['flags'] && trim($template['body'])) { // only if there's content in the body field |
| 923 |
|
$body = contemplate_eval($template['body'], $node, $xml_elements); |
| 924 |
|
$node->content['body']['items'][0]['#item']['value'] = $body; |
| 925 |
|
$node->content['body']['items'][0]['#item']['safe'] = $body; |
| 926 |
|
} |
| 927 |
|
break; |
| 928 |
|
} |
| 929 |
|
} |
| 930 |
|
} |