function diff() { global $argc, $argv; if ($argc != 3) { usage(); } $file = $argv[2]; if (file_exists($file)) { $xml = @simplexml_load_file($file); } else { file_not_found($file); } if ($xml === false) { bad_xml($file); } echo "Analysing {$file}...\n"; // Go through nodes and mark ways that have changed (we can easiky keep it in memory) // rq: use floats or strings but not ints, since PHP_INT_MAX is too small on 32 bits systems $impacted_ways = array(); $nodes = $xml->node; foreach ($nodes as $node) { $nodeid = (string) $node->attributes()->id; $nodeaction = (string) $node->attributes()->action; if ((double) $nodeid < 0 || $nodeaction === 'modify') { $results = $xml->xpath("//way[count(nd[@ref='{$nodeid}'])>0]"); if (count($results)) { foreach ($results as $way) { $wayid = (string) $way->attributes()->id; if (!isset($impacted_ways[$wayid])) { $impacted_ways[$wayid] = 1; } } } } } // we go through ways, but only the ones that have a c2c:id attached // (other are part of a relation) $impacted_relations = array(); $ways = $xml->way; foreach ($ways as $way) { // If only the nodes of a way have been modified or deleted, the way itself is not marked // as changed in josm. Let's check that. $wayid = (string) $way->attributes()->id; $propaged_modification = array_key_exists($wayid, $impacted_ways); $state = state($way); if ($propaged_modification && $state === 'NOCHANGE') { $state = 'MODIFY'; } // check if it has a c2c:id attached // other ways are handled via their parent relation $c2cid = c2cid($way); if ($c2cid) { for ($i = 0; $i < count($c2cid); $i++) { $changes[$c2cid[$i]][$state][] = $wayid; if (!isset($changes[$c2cid[$i]]['name'])) { $changes[$c2cid[$i]]['name'] = c2cname($way, $i); } } } else { // determine if way has changed (either directly or via its nodes) // if so, keep track of the related relations that will be considered modified if ($state === 'MODIFY') { $results = $xml->xpath("//relation[count(member[@ref='{$wayid}'])>0]"); if (count($results)) { foreach ($results as $relation) { $relationid = (string) $relation->attributes()->id; if (!isset($impacted_relations[$relationid])) { $impacted_relations[$relationid] = 1; } } } } } } // we go through the relations $relations = $xml->relation; foreach ($relations as $relation) { $relationid = (string) $relation->attributes()->id; $propaged_modification = array_key_exists($relationid, $impacted_relations); $state = state($relation); if ($propaged_modification && $state === 'NOCHANGE') { $state = 'MODIFY'; } $c2cid = c2cid($relation); if ($c2cid) { for ($i = 0; $i < count($c2cid); $i++) { $changes[$c2cid[$i]][$state][] = $relationid; if (!isset($changes[$c2cid[$i]]['name'])) { $changes[$c2cid[$i]]['name'] = c2cname($relation, $i); } } } else { die("Found a relation without c2c:id. Aborting...\n"); } } // display the changes in a human readable way echo "\n"; foreach ($changes as $id => $change) { $modifycount = isset($change['MODIFY']) ? count($change['MODIFY']) : 0; $deletecount = isset($change['DELETE']) ? count($change['DELETE']) : 0; $newcount = isset($change['NEW']) ? count($change['NEW']) : 0; $nochangecount = isset($change['NOCHANGE']) ? count($change['NOCHANGE']) : 0; // an area has been completely deleted if ($deletecount > 0 && $modifycount == 0 && $newcount == 0 && $nochangecount == 0) { echo $change['name'] . " ({$id}) has been deleted\n"; continue; } // a new area has been created if ($newcount > 0 && $modifycount == 0 && $deletecount == 0 && $nochangecount == 0) { echo $change['name'] . " ({$id}) has been created with {$newcount} polygon(s)\n"; continue; } // modified in various ways if ($newcount > 0 || $modifycount > 0 || $deletecount > 0) { echo $change['name'] . " ({$id}) has been changed\n"; continue; } } }
$query .= " country='{$country}', "; } if ($postal_code) { $query .= " postal_code='{$postal_code}', "; } if ($global_prefs) { $global_prefs = str_replace("\\r\\n", "\n", $global_prefs); $x = bad_xml($global_prefs, "<global_preferences>", "</global_preferences>"); if ($x) { error("Invalid global preferences: {$x}"); } $query .= " global_prefs='{$global_prefs}', "; } if ($project_prefs) { $project_prefs = str_replace("\\r\\n", "\n", $project_prefs); $x = bad_xml($project_prefs, "<project_preferences>", "</project_preferences>"); if ($x) { xml_error(-112, "Invalid project preferences: {$x}"); } $query .= " project_prefs='{$project_prefs}', "; } if ($url) { $query .= " url='{$url}', "; } if ($send_email != null) { $query .= " send_email='{$send_email}', "; } if ($show_hosts != null) { $query .= " show_hosts='{$show_hosts}', "; } if (!is_null($teamid)) {