Skip to content

Instantly share code, notes, and snippets.

@mrjazz
Created September 21, 2017 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrjazz/91623625a9b72e9384d08b6c8f10e955 to your computer and use it in GitHub Desktop.
Save mrjazz/91623625a9b72e9384d08b6c8f10e955 to your computer and use it in GitHub Desktop.
<?php
if (isset($_SERVER['argv']) && count($_SERVER['argv']) > 1) {
$doc = file_get_contents($_SERVER['argv'][1]);
$xml = new SimpleXMLElement($doc);
process($xml, "Missed pages:", 'messagebox_warning');
process($xml, "Questions:", 'help');
markersList($xml, "Won't be implemented in first version:", 'stop-sign');
markersList($xml, "Already implemented:", 'button_ok');
estimate($xml, "Estimate:");
} else {
echo "No mindmaps in parameters passed\n";
exit();
}
function estimate($xml, $title) {
$content = "\n$title\n\n";
$total = 0;
$result = $xml->xpath('//node');
foreach ($result as $key => $value) {
if($value->count() > 0) {
foreach ($value->children() as $child) {
if ($child->getName() == 'attribute' && $child->attributes()["NAME"] == 'estimate') {
$content .= ' - ' . $value->attributes()['TEXT']->__toString() . ', ' . $child->attributes()["VALUE"] . "h\n";
$total += $child->attributes()["VALUE"];
}
}
}
}
echo $content;
echo "\nTotal: {$total}h\n";
}
function markersList($xml, $title, $icon) {
$content = "\n$title\n\n";
$result = $xml->xpath('//node');
foreach ($result as $key => $value) {
if($value->count() > 0) {
foreach ($value->children() as $child) {
if ($child->getName() == 'icon' && $child->attributes()["BUILTIN"] == $icon) {
$content .= ' - ' . $value->attributes()['TEXT']->__toString() . "\n";
}
}
}
}
echo $content;
}
function process($xml, $title, $icon) {
$content = "\n$title\n\n";
$result = $xml->xpath('//node');
$num = 1;
foreach ($result as $key => $value) {
// var_dump(strip_tags($value->html->asXML()));
if($value->count() > 0 && $value->children()[0]->getName() == 'richcontent') {
foreach ($value->children() as $child) {
if ($child->getName() == 'icon' && $child->attributes()["BUILTIN"] == $icon) {
$content .= " $num. " . $value->attributes()['TEXT']->__toString() . ":\n - ";
$text = preg_replace('/\s{2,}/m', "\n", trim(strip_tags($value->children()[0]->asXML())));
$content .= implode("\n - ", explode("\n", $text)) . "\n";
$num++;
}
}
}
}
echo $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment