User:Leucosticte/XmlReader.php

open( $fileName ) ) { die( "Failed to open $fileName" ); } $undesirables = array ( '-', ':', 'T', 'Z' ); $nodeName = ''; $whichMostRecent = 'element'; $array = array(       'timestamp' => 'mbq_timestamp',        'username' => 'mbq_user_text',        'comment' => 'mbq_comment',        'type' => 'mbq_logtype',        'action' => 'mbq_log_action',        'params' => 'mbq_log_params',        'logtitle' => 'mbq_log_title' ); $fields = ''; foreach( $allFields as $key => $allField ) { if ( $fields ) { $fields .= ', '; }   $fields .= $key; }

$dbArray = array; $log_id = 0; while($reader->read) { if( $reader->nodeType == XMLReader::ELEMENT ) { $nodeName = $reader->name; if ( $nodeName == 'contributor' ) { $whichMostRecent = 'contributor'; }       if ( $nodeName == 'logitem' ) { $whichMostRecent = 'logitem'; }   }        if($reader->nodeType == XMLReader::TEXT ) { // ID can be either log_id or log_user if ( $nodeName == 'id' ) { if ( $whichMostRecent == 'contributor' ) { $dbArray[$log_id]['mbrcq_rc_user'] = $reader->value; } else { $log_id = $reader->value; $dbArray[$log_id]['mbrcq_rc_logid'] = $reader->value; }           }            // User ID also should be saved if ( $nodeName == 'params' ) { $data = @unserialize( $reader->value ); if ( isset( $data["4::userid"] ) ) { $dbArray[$log_id]['mbrcq_user'] = $data["4::userid"]; }           }            // Save the data to the array if ( isset( $array[$nodeName] ) ) { $dbArray[$log_id][$array[$nodeName]] = $reader->value; }       }        // Save log entry to mb_rc_queue if($reader->nodeType == XMLReader::END_ELEMENT && $reader->name == 'logitem') { if ( $dbArray[$log_id]['mbrcq_rc_log_action'] == 'create2' ) { if ( substr( $dbArray[$log_id]['mbrcq_user_text'], 0, 5 ) == 'User:' ) { $dbArray[$log_id]['mbrcq_user_text'] = substr( $dbArray[$log_id]['mbrcq_user_text'], 5,                       strlen ( $dbArray[$log_id]['mbrcq_user_text'] ) - 5 ); }           }            $values = ''; $firstOne = true; foreach( $allFields as $key => $allField ) { if ( !$firstOne ) { $values .= ", "; }               $firstOne = false; $value = $defaultFields[$allField]; if ( isset( $dbArray[$log_id][$key] ) ) { $value = ''; $value = $con->real_escape_string( $dbArray[$log_id][$key] ); if ( $key == 'mbrcq_rc_timestamp' ) { $value = str_replace ( $undesirables, '', $value ); }                   $value = "'". $value. "'";               }                $values .= $value; }           #echo $values; $ret = $con->query( "SELECT * FROM mb_rc_queue "               . "WHERE mbrcq_rc_logid=$log_id" ); if ( !$ret || !$ret->num_rows ) { $query = "INSERT INTO mb_rc_queue ($fields) " . " values ($values)"; #echo $query. "\n"; $con->query( $query ); }       }    }    $reader->close;