<?php
require_once('../../settings.php');
function_exists('require_once_path') or require $GLOBALS['library'].'requirepath.php';
require_once_path($GLOBALS['library'].'autoload/');
class_exists('XMLFS') or require $GLOBALS['filesystemsLibrary'].'XMLFS.php';
$GLOBALS['filesystem'] = new XMLFS($GLOBALS['filesystems'].'mocovi.de.xml');
$GLOBALS['definitions'] = $GLOBALS['absolutepath'].'mocovi/definitions/';
$extension = '.rng';
function setOptions(DomNode $root, $control)
{
if(count($options = ControlFactory::createVirtual($control)->getDefaultOptions()) > 0)
{
if(count($options) > 1)
$root->appendChild($container = $root->ownerDocument->createElement('interleave'));
else
$container = $root;
foreach($options as $option => $value)
{
$container->appendChild($optional = $root->ownerDocument->createElement('optional'));
$optional->appendChild($attribute = $root->ownerDocument->createElement('attribute'));
$attribute->setAttribute('name', $option);
$attribute->appendChild($root->ownerDocument->createElement('text')); // Not necessary
}
}
}
foreach(ControlFactory::getAllControls() as $control)
{
$dom = new DomDocument('1.0', 'utf-8');
$dom->formatOutput = true;
$dom->appendChild($root = $dom->createElement('define'));
$root->setAttribute('name', $control);
$root->setAttribute('xmlns', 'http://relaxng.org/ns/structure/1.0');
$root->appendChild($element = $dom->createElement('element'));
$element->setAttribute('name', $control);
$element->setAttribute('ns', $GLOBALS['filesystem']->namespace);
setOptions($element, $control);
$element->appendChild($any = $root->ownerDocument->createElement('ref'));
$any->setAttribute('name', 'any');
file_put_contents($GLOBALS['definitions'].$control.$extension, $dom->saveXML());
chmod($GLOBALS['definitions'].$control.$extension, 0777);
}