/[drupal]/contributions/modules/import_html/modules/content.inc
ViewVC logotype

Diff of /contributions/modules/import_html/modules/content.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.3.4.4, Sat May 9 14:16:30 2009 UTC revision 1.3.4.5, Wed Sep 9 06:47:22 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: content.inc,v 1.3.4.3 2009/05/09 12:45:16 dman Exp $  // $Id: content.inc,v 1.3.4.4 2009/05/09 14:16:30 dman Exp $
3  /**  /**
4   * @file helper to import fields provided by CCK (Content Creation Kit)   * @file helper to import fields provided by CCK (Content Creation Kit)
5   */   */
# Line 43  function content_import_html($profile, & Line 43  function content_import_html($profile, &
43      // Loop through possible values on the node      // Loop through possible values on the node
44      foreach (array($field_id, $field_short_id) as $alt_field_id) {      foreach (array($field_id, $field_short_id) as $alt_field_id) {
45        if (! empty($node->$alt_field_id)) {        if (! empty($node->$alt_field_id)) {
46          import_html_debug("Found a value for '$alt_field_id' to save as a CCK field value", 2);          import_html_debug("Found a value for '%alt_field_id' to save as a CCK field value", array('%alt_field_id' => $alt_field_id), 2);
47          // The found value may or may not be an array. Ensure it is, then loop over the list.          // The found value may or may not be an array. Ensure it is, then loop over the list.
48          $field_val = is_array($node->$alt_field_id)? $node->$alt_field_id : array($node->$alt_field_id);          $field_val = is_array($node->$alt_field_id)? $node->$alt_field_id : array($node->$alt_field_id);
49          foreach ($field_val as $val) {          foreach ($field_val as $val) {
# Line 68  function content_import_html($profile, & Line 68  function content_import_html($profile, &
68      if ($field_def['type'] == 'text') {      if ($field_def['type'] == 'text') {
69        continue;        continue;
70      }      }
     /**  
71    
72      // Do my own DOM scanning. Better than the default text absorbing that just happened before.      // TODO support for other CCK field type - other than text!
     // (If any nominee values were found that may have fit in CCK fields,  
     // they will be overwritten by this import.)  
     //  
     // Match any of id='fieldname', class='fieldname', id='fieldname_field', class='fieldname_field',  
     // Construct an xpath (could have been just a string, I know)  
     $match_patterns = array();  
     foreach (array('id', 'class') as $attribute_label) {  
       foreach (array($field_id, $field_short_id) as $alt_field_id) {  
         $match_patterns[] = "@$attribute_label='$alt_field_id'";  
       }  
     }  
     $xpath = ".//*[". join($match_patterns, ' or ') ."]";  
 #dpm("looking for $xpath in ");  
 #debug_code(xml_tostring($datadoc));  
 #debug_code($datadoc);  
   
     $found_elements = xml_query($datadoc, $xpath);  
     if (! $found_elements) {  
       debug("No value for $field_id field found in the doc");  
       continue;  
     }  
   
     // DISCARD the previous value that would have been found.  
     $node->{$field_def['field_name']} = array();  
   
     foreach ($found_elements as $found_element) {  
       // Absorbing data blobs  
       // We grab the CONTENT of the named div, normally not including the wrapper.  
       // Its the difference between xml_tostring and xml_textcontent  
       debug("Found an <b>expected</b> CCK field - '$field_id' , Absorbing it into the right place in the right way", 1);  
       // TODO move this logic into a switch($field_def['type']) ?  
       if ($field_def['text_processing']) {  
         $field = array(  
           'value' => xml_tostring($found_element, TRUE),  
           'format' => import_html_get_preferred_filter()  
           );  
         }  
       else {  
         // Can only be plaintext, no formatted HTML  
         debug("The field '$field_id' is configured as plaintext only. HTML found in here will be stripped out.", 2);  
         $field = array(  
           'value' => xml_textcontent($found_element),  
         );  
   
           //  
          // Special cases for field types INCOMPLETE TODO clean up a general case  
          // for these  
          //  
         if ($field_def['type'] == 'image') {  
           $field = array(  
             'filepath' => xml_textcontent($found_element),  
           );  
         }  
         // ... other special field types? Add here  
   
         // TODO support for other CCK  
       } // has special formatting  
   
       $node->{$field_def['field_name']}[] = $field;  
     }  
     */  
73    }    }
74  }  }
75    

Legend:
Removed from v.1.3.4.4  
changed lines
  Added in v.1.3.4.5

  ViewVC Help
Powered by ViewVC 1.1.2