Changeset 13895

Show
Ignore:
Timestamp:
12/14/07 11:40:47 (10 months ago)
Author:
bergie
Message:

Clean up element names and contents when importing

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/midcom.helper.filesync/importer/snippet.php

    r13894 r13895  
    9090            if ($encoding != 'UTF-8') 
    9191            { 
    92                 if ($encoding == 'ASCII') 
    93                 { 
    94                     $encoding = 'ISO-8859-1'; 
    95                 } 
    9692                $file_contents = @iconv($encoding, 'UTF-8', $file_contents); 
    9793            } 
  • trunk/midcom/midcom.helper.filesync/importer/style.php

    r13894 r13895  
    6464             
    6565            // Deal with element 
    66             $element_contents = file_get_contents("{$path}/{$entry}"); 
     66             
     67            // Check file type 
     68            $filename_parts = explode('.', $entry); 
     69            if (count($filename_parts) < 2) 
     70            { 
     71                continue; 
     72            } 
     73            $element_name = $filename_parts[0]; 
     74            $field = false; 
     75            switch($filename_parts[count($filename_parts) - 1]) 
     76            { 
     77                case 'php': 
     78                    $field = 'value'; 
     79                    break; 
     80            } 
     81            if (!$field) 
     82            { 
     83                continue; 
     84            } 
     85             
     86            $file_contents = file_get_contents("{$path}/{$entry}"); 
     87            $encoding = mb_detect_encoding($file_contents); 
     88            if ($encoding != 'UTF-8') 
     89            { 
     90                $file_contents = @iconv($encoding, 'UTF-8', $file_contents); 
     91            } 
     92             
    6793            $qb = midcom_db_element::new_query_builder(); 
    6894            $qb->add_constraint('style', '=', $style->id); 
    69             $qb->add_constraint('name', '=', $entry); 
     95            $qb->add_constraint('name', '=', $element_name); 
    7096            if ($qb->count() == 0) 
    7197            { 
     
    7399                $element = new midcom_db_element(); 
    74100                $element->style = $style->id; 
    75                 $element->name = $entry
    76                 $element->value = $element_contents; 
     101                $element->name = $element_name
     102                $element->$field = $file_contents; 
    77103                $element->create(); 
    78104                continue; 
     
    83109             
    84110            // Update existing elements only if they have actually changed 
    85             if ($element->value != $element_contents) 
     111            if ($element->$field != $file_contents) 
    86112            { 
    87                 $element->value = $element_contents; 
     113                $element->$field = $file_contents; 
    88114                $element->update(); 
    89115            }