? calais-446084.patch
Index: calais.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/opencalais/calais.module,v
retrieving revision 1.3.2.16.2.22.2.10
diff -u -p -r1.3.2.16.2.22.2.10 calais.module
--- calais.module	27 Jul 2009 03:04:20 -0000	1.3.2.16.2.22.2.10
+++ calais.module	18 Aug 2009 01:16:49 -0000
@@ -101,7 +101,7 @@ function calais_menu() {
 function calais_preprocess_node(&$variables) {
   $node = $variables['node'];
   $count = rdf_count(NULL, NULL, NULL, calais_rdf_options($node->nid));
-  
+
   // Add an RDF autodiscovery link when the node is displayed by itself as a page:
   if (user_access('access calais rdf') && $count) {
     rdf_add_autodiscovery_link(t('Calais RDF'), url("node/$node->nid/calais/rdf"), 'rdf+xml');
@@ -189,7 +189,7 @@ function calais_process_node(&$node, $pr
     $node->vid = db_result(db_query("SELECT vid FROM {node} WHERE nid=%d", $node->nid));
   }
 
-  $keywords = _calais_use_semanticproxy($node) 
+  $keywords = _calais_use_semanticproxy($node)
                   ? calais_process_with_semanticproxy($node)
                   : calais_process_with_calais($node);
 
@@ -206,7 +206,7 @@ function calais_process_node(&$node, $pr
     if ($vid) { // Only process terms for vocabularies that we care about
       foreach ($metadata->terms as $term) {
         calais_associate_term($vid, $term, $node);
-        if ( ($process_type == CALAIS_PROCESS_AUTO || ($process_type == CALAIS_PROCESS_AUTO_ONCE && $op == "insert")) 
+        if ( ($process_type == CALAIS_PROCESS_AUTO || ($process_type == CALAIS_PROCESS_AUTO_ONCE && $op == "insert"))
             && round($term->relevance * 1000) >= round($threshold * 1000)) {
           calais_apply_to_node($vid, $term, $node);
         }
@@ -234,6 +234,9 @@ function calais_process_with_calais(&$no
   // Allow modification of the content sent to Calais
   drupal_alter("calais_body", $body, $loaded_node);
 
+  // Trim body to be under 100,000 characters
+  $body = array_shift(str_split($body, 99000));
+
   $calais = new Calais($node_settings);
   $keywords = $calais->analyzeXML($node->title, $body, $date);
   $node->calais->service = $calais;
@@ -250,7 +253,7 @@ function calais_process_with_calais(&$no
 function calais_process_with_semanticproxy(&$node) {
   $key = drupal_strtolower($node->type);
   $spfield = variable_get("calais_semanticproxy_field_{$key}", '');
-  
+
   if(!empty($spfield)) {
     if($spfield == 'calais_feedapi_node') {
       // On insert, $node->feedapi_node is available
@@ -262,19 +265,19 @@ function calais_process_with_semanticpro
       }
     }
     else {
-      // Grab URL from link or textfield 
+      // Grab URL from link or textfield
       $field = $node->{$spfield};
       if(isset($field)) {
        $url = isset($field[0]['url']) ? $field[0]['url'] : $field[0]['value'];
       }
     }
-    
+
     drupal_alter('semanticproxy_url', $url);
-    
+
     $sp = new SemanticProxy();
     $keywords = $sp->analyze($url);
     $node->calais->service = $sp;
-    
+
     if($keywords) {
       // Store the document text if configured
       $docfield = variable_get("calais_semanticproxy_document_{$key}", '');
@@ -290,9 +293,9 @@ function calais_process_with_semanticpro
       }
       return $keywords;
     }
-  } 
-  
-  return array(); 
+  }
+
+  return array();
 }
 
 /**
@@ -326,15 +329,15 @@ function calais_associate_term($vid, &$t
   $local_term = calais_get_term($vid, $term);
 
   $calais_term = $local_term ? $local_term : new CalaisTerm($term->guid, $term->name, $term->relevance);
-  // We could array_merge, but defined properties with no value will 
+  // We could array_merge, but defined properties with no value will
   // overwrite the locals (tid, tdid, etc.), so just be explicit for now.
-  $calais_term->vid = $vid; 
+  $calais_term->vid = $vid;
   $calais_term->relevance = $term->relevance;
   $calais_term->resolved_guid = $term->resolved_guid;
   $calais_term->resolved_name = $term->resolved_name;
   $calais_term->resolved_type = $term->resolved_type;
   $calais_term->extra = array_merge($calais_term->extra, $term->extra);
-  
+
   calais_save_term($calais_term);
   calais_assign_term_to_node($node->nid, $calais_term);
   $term = $calais_term;
@@ -347,11 +350,11 @@ function calais_associate_term($vid, &$t
  *    The Vocabulary ID of the calais term
  * @param $term
  *    The CalaisTerm object to lookup, or a term id
- * @return  
+ * @return
  *    The Calais Term object, false is the term is not found.
  */
 function calais_get_term($vid, $term) {
-  
+
   if(is_numeric($term)) {
     $local_term = db_fetch_object(db_query("SELECT * FROM {calais_term} WHERE tid = %d", $term));
   }
@@ -365,31 +368,31 @@ function calais_get_term($vid, $term) {
 
   if ($local_term) {
     calais_load_term_extra($local_term);
-    return $local_term;    
+    return $local_term;
   }
-  
+
   return FALSE;
 }
 
 /**
- * Find the Calais Term by Taxonomy Term Data 
+ * Find the Calais Term by Taxonomy Term Data
  *
  * @param $term_id
  *    The Term Data ID
- * @return  
+ * @return
  *    The Calais Term object, false is the term is not found.
  */
 function calais_get_term_by_taxonomy($term_id) {
   $term = db_fetch_object(db_query("SELECT * FROM {calais_term} WHERE tdid = %d", $term_id));
   if ($term) {
     calais_load_term_extra($term);
-    return $term;    
+    return $term;
   }
   return FALSE;
 }
 
 /**
- * Get the CalaisTerm for the term name and node id. 
+ * Get the CalaisTerm for the term name and node id.
  * NOTE: Columns were renamed here so that this object has the same attributes as CalaisTerm for consistency
  *
  * @param $nid The node id to limit the calais term look up
@@ -412,10 +415,10 @@ function calais_get_node_term_by_name($n
  */
 function calais_save_term(&$term) {
   if(empty($term->tid)) {
-    drupal_write_record('calais_term', $term);        
+    drupal_write_record('calais_term', $term);
   }
   else {
-    drupal_write_record('calais_term', $term, 'tid');        
+    drupal_write_record('calais_term', $term, 'tid');
   }
   calais_save_term_extra($term);
 }
@@ -433,7 +436,7 @@ function calais_load_term_extra(&$term) 
     $term->extra = $data ? $data : array();
   }
   else {
-    $term->extra = array();    
+    $term->extra = array();
   }
 }
 
@@ -447,9 +450,9 @@ function calais_save_term_extra(&$term) 
   if(isset($term->resolved_type) && !empty($term->extra)) {
     $table = 'calais_term_data_' . $term->resolved_type;
     $data = &$term->extra;
-    $data['tid'] = $term->tid;        
+    $data['tid'] = $term->tid;
     if(isset($data['did'])) {
-      drupal_write_record($table, $data, 'did');        
+      drupal_write_record($table, $data, 'did');
     }
     else {
       drupal_write_record($table, $data);
@@ -467,7 +470,7 @@ function calais_save_term_extra(&$term) 
  * @param $node The node for association
  */
 function calais_apply_to_node($vid, &$term, $node) {
-  
+
   if(empty($term->tdid)) {
     $term->tdid = calais_find_taxonomy_term($vid, $term->name);
     if (!$term->tdid) {
@@ -477,7 +480,7 @@ function calais_apply_to_node($vid, &$te
       $term->tdid = $tax_term['tid'];
     }
     calais_save_term($term);
-  }  
+  }
   calais_assign_taxonomyterm_to_node($node->nid, $node->vid, $term->tdid);
 }
 
@@ -488,7 +491,7 @@ function calais_apply_to_node($vid, &$te
  *    The vocabulary id for the term to find.
  * @param $term_name
  *    The Term Name to find a matching taxonomy term
- * @return $tid 
+ * @return $tid
  *    Term id from the {term_data} table, or FALSE is one is not found.
  */
 function calais_find_taxonomy_term($vid, $term_name) {
@@ -526,7 +529,7 @@ function calais_assign_taxonomyterm_to_n
 /**
  * Implementation of hook_taxonomy();
  *
- * Process the delete of taxonomy terms to make sure the proper cleanup 
+ * Process the delete of taxonomy terms to make sure the proper cleanup
  * happens to Calais Terms that reference them.
  */
 function calais_taxonomy($op, $type, $data) {
@@ -582,7 +585,7 @@ function calais_get_node_threshold($node
  *
  * @param $type
  *    A node type, if Entities need to be filtered.
- * @return 
+ * @return
  *    Associative array of [entity_name => vid]'s
  */
 function calais_get_entity_vocabularies($type = NULL) {
@@ -620,10 +623,10 @@ function calais_get_entity_vocabularies(
 function calais_get_vocabularies($type = NULL) {
 
   $vocs = calais_get_entity_vocabularies($type);
-  
+
   if(empty($vocs))
     return array();
-  
+
   $pattern = implode(",", $vocs);
 
   if ($type) {
@@ -670,7 +673,7 @@ function calais_get_vocabularies($type =
  * @param $nid The node id to get the calais keywords
  * @param $type The node type
  * @param $vid Optional, a specific vocabulary id to return terms
- * @param $threshold 
+ * @param $threshold
  *    Optional, A relevance threshold for suggestions. If not specified the default for the node type will be used.
  *
  * @return Array { $vid => array(termObj1, termObj2, termObj3) }
@@ -709,7 +712,7 @@ function calais_get_keywords($nid, $type
  */
 function calais_create_entity_vocabulary($entity) {
     $description = t("Calais Entity Vocabulary: @name", array('@name' => $entity));
-    db_query("INSERT INTO {vocabulary} (name,description,module,tags) 
+    db_query("INSERT INTO {vocabulary} (name,description,module,tags)
               VALUES('%s','%s','calais',1)", $entity, $description);
     return db_last_insert_id('vocabulary', 'vid');
 }
@@ -721,7 +724,7 @@ function calais_create_entity_vocabulary
  */
 function calais_rdf_options($nid) {
   return array(
-    'graph' => "node/$nid/calais/rdf", 
+    'graph' => "node/$nid/calais/rdf",
     'repository' => CALAIS_RDF_REPOSITORY,
   );
 }
@@ -738,7 +741,7 @@ function calais_rdf_options($nid) {
 function calais_store_rdf($node, $triples) {
   if(variable_get('calais_store_rdf', TRUE) && !empty($triples)) {
     calais_remove_rdf($node);
-    rdf_insert_all($triples, calais_rdf_options($node->nid));  
+    rdf_insert_all($triples, calais_rdf_options($node->nid));
   }
 }
 
@@ -760,9 +763,9 @@ function calais_remove_rdf($node) {
 /**
  * Is this node configured to use SemanticProxy?
  *
- * @param $node 
+ * @param $node
  *    The node to examine
- * @return 
+ * @return
  *    TRUE if this node is configured to use SemanticProxy, FALSE otherwise.
  */
 function _calais_use_semanticproxy($node) {
@@ -776,12 +779,12 @@ function _calais_use_semanticproxy($node
  *
  * SemanticProxy obeys robots.txt and as such will not follow redirects, etc. For example,
  * RSS feeds for Google News Search will send you through Google News to redirect to the real source.
- * SemanticProxy will give a <em>Content Permissions Validator Exception</em> and not follow the 
+ * SemanticProxy will give a <em>Content Permissions Validator Exception</em> and not follow the
  * link b/c Google's robots.txt disallows following /news.  We try to strip those out.
  *
  * TODO: Make this URL extraction configurable via admin ui, if possible
  *
- * @param $url 
+ * @param $url
  *    The URL to alter.
  */
 function calais_semanticproxy_url_alter(&$url) {
