From d526a4d7b56ee968aa2545d0fde493e05914b6e0 Mon Sep 17 00:00:00 2001
From: Andrew Berry <deviantintegral@gmail.com>
Date: Thu, 28 Apr 2011 15:06:37 -0400
Subject: [PATCH] #824574: Only operate on CCK fields if the content module is
 enabled.

---
 skeleton_instance.inc |   30 ++++++++++++++++++------------
 skeleton_template.inc |   16 +++++++++-------
 skeleton_token.inc    |   16 ++++++++++------
 3 files changed, 37 insertions(+), 25 deletions(-)

diff --git a/skeleton_instance.inc b/skeleton_instance.inc
index 2267238..44e53f5 100644
--- a/skeleton_instance.inc
+++ b/skeleton_instance.inc
@@ -709,12 +709,14 @@ function skeleton_create_instance_form_submit($form, &$form_state) {
         $node['values']['title'] = str_replace('[bookpathalias]', '[\skeleton-bookpathalias\]', $node['values']['title']);
         $node['values']['body'] = str_replace('[bookpathalias]', '[\skeleton-bookpathalias\]', $node['values']['body']);
         // Also do any CCK text fields.
-        $content_type = content_types($node['values']['type']);
-        $fields = $content_type['fields'];
-        foreach ($fields as $field) {
-          if ($field['type'] == 'text' && is_array($node['values'][$field['field_name']])) {
-            foreach (array_keys($node['values'][$field['field_name']]) as $delta) {
-              $node['values'][$field['field_name']][$delta]['value'] = str_replace('[bookpathalias]', '[\skeleton-bookpathalias\]', $node['values'][$field['field_name']][$delta]['value']);
+        if (module_exists('content')) {
+          $content_type = content_types($node['values']['type']);
+          $fields = $content_type['fields'];
+          foreach ($fields as $field) {
+            if ($field['type'] == 'text' && is_array($node['values'][$field['field_name']])) {
+              foreach (array_keys($node['values'][$field['field_name']]) as $delta) {
+                $node['values'][$field['field_name']][$delta]['value'] = str_replace('[bookpathalias]', '[\skeleton-bookpathalias\]', $node['values'][$field['field_name']][$delta]['value']);
+              }
             }
           }
         }
@@ -786,15 +788,19 @@ function skeleton_create_instance_form_submit($form, &$form_state) {
       $parent_node->title = str_replace('[\skeleton-bookpathalias\]', drupal_get_path_alias($parent_node->path), $parent_node->title);
       $parent_node->teaser = str_replace('[\skeleton-bookpathalias\]', drupal_get_path_alias($parent_node->path), $parent_node->teaser);
       $parent_node->body = str_replace('[\skeleton-bookpathalias\]', drupal_get_path_alias($parent_node->path), $parent_node->body);
-      $content_type = content_types($parent_node->type);
-      $fields = $content_type['fields'];
-      foreach ($fields as $field) {
-        if ($field['type'] == 'text' && is_array($parent_node->{$field['field_name']})) {
-          foreach (array_keys($parent_node->{$field['field_name']}) as $delta) {
-            $parent_node->{$field['field_name']}[$delta]['value'] = str_replace('[\skeleton-bookpathalias\]', drupal_get_path_alias($parent_node->path), $parent_node->{$field['field_name']}[$delta]['value']);
+
+      if (module_exists('content')) {
+        $content_type = content_types($parent_node->type);
+        $fields = $content_type['fields'];
+        foreach ($fields as $field) {
+          if ($field['type'] == 'text' && is_array($parent_node->{$field['field_name']})) {
+            foreach (array_keys($parent_node->{$field['field_name']}) as $delta) {
+              $parent_node->{$field['field_name']}[$delta]['value'] = str_replace('[\skeleton-bookpathalias\]', drupal_get_path_alias($parent_node->path), $parent_node->{$field['field_name']}[$delta]['value']);
+            }
           }
         }
       }
+
       $parent_node->skeleton_template->keep_connected = TRUE;
       $parent_node = node_submit($parent_node);
       node_save($parent_node);
diff --git a/skeleton_template.inc b/skeleton_template.inc
index fd44128..02ef816 100644
--- a/skeleton_template.inc
+++ b/skeleton_template.inc
@@ -304,14 +304,16 @@ function skeleton_alter_node_form(&$form, $form_state, $form_id) {
 
   // Saving Filefield (or Imagefield) fields as is really breaks things, so
   // find any such fields and remove them.
-  $content_type = content_types($form['#node']->type);
-  foreach ($content_type['fields'] as $data) {
-    if ($data['type'] == 'filefield') {
-      $unset[] = $data['field_name'];
+  if (module_exists('content')) {
+    $content_type = content_types($form['#node']->type);
+    foreach ($content_type['fields'] as $data) {
+      if ($data['type'] == 'filefield') {
+        $unset[] = $data['field_name'];
+      }
+    }
+    foreach ($unset as $item) {
+      unset($form[$item]);
     }
-  }
-  foreach ($unset as $item) {
-    unset($form[$item]);
   }
 
   if (module_exists('nodeaccess') && user_access('grant node permissions')) {
diff --git a/skeleton_token.inc b/skeleton_token.inc
index 6ff30a8..5a4d094 100644
--- a/skeleton_token.inc
+++ b/skeleton_token.inc
@@ -318,16 +318,20 @@ function _skeleton_token_replace_values($node, $type, $tokens, $fix_bookpathalia
   }
   $node->title = token_replace($node->title, $type, $tokens);
   $node->body = token_replace($node->body, $type, $tokens);
+
   // Also do any CCK text fields.
-  $content_type = content_types($node->type);
-  $fields = $content_type['fields'];
-  foreach ($fields as $field) {
-    if ($field['type'] == 'text' && is_array($node->{$field['field_name']})) {
-      foreach (array_keys($node->{$field['field_name']}) as $delta) {
-        $node->{$field['field_name']}[$delta]['value'] = token_replace($node->{$field['field_name']}[$delta]['value'], $type, $tokens);
+  if (module_exists('content')) {
+    $content_type = content_types($node->type);
+    $fields = $content_type['fields'];
+    foreach ($fields as $field) {
+      if ($field['type'] == 'text' && is_array($node->{$field['field_name']})) {
+        foreach (array_keys($node->{$field['field_name']}) as $delta) {
+          $node->{$field['field_name']}[$delta]['value'] = token_replace($node->{$field['field_name']}[$delta]['value'], $type, $tokens);
+        }
       }
     }
   }
+
   return $node;
 }
 
-- 
1.7.4.4

