Beispiel #1
0
}
$objUpgradedDOM = $objUpgrader->getConfigurationDOM();
/**
 * from here on: save the config
 */
// stupid hack; to have a well-formed XML-output from a file-read input, we need to save it twice
$strXML = $objUpgradedDOM->saveXML();
$objXML = new DOMDocument();
$objXML->preserveWhiteSpace = false;
$objXML->formatOutput = true;
$objXML->loadXML($strXML);
// save the resulting XML to its configuration file
$handle = fopen($strConfigFQFilename, "w");
fputs($handle, $objXML->saveXML());
fclose($handle);
exitWithResponse(true, 'configuration was upgraded to version ' . LIBRARY_VERSION);
/**
 * create and send a response.
 * This function will issue an exit command!
 * 
 * @param   boolean $boolSuccess    was the operating successful?
 * @param   string  $strMessage     a message, if any
 */
function exitWithResponse($boolSuccess, $strMessage = '')
{
    if (true === $boolSuccess) {
        print '<b style="color: green;">SUCCESS</b>';
    } else {
        print '<b style="color: red;">ERROR</b>';
    }
    if (false === empty($strMessage)) {
Beispiel #2
0
    /** die alten Mappings und stylings übernehmen */
    $objDOM = new DOMDocument('1.0', 'UTF-8');
    $objDOM->formatOutput = true;
    foreach ($arrData as $arrRootNodeData) {
        $objDOM->appendChild(createDOMFromData($objDOM, $arrRootNodeData));
    }
    $objDOM->preserveWhiteSpace = false;
    $objDOM->formatOutput = true;
    // save the XML to its configuration file
    $handle = fopen($strConfigFQFilename, "w");
    fputs($handle, $objDOM->saveXML());
    fclose($handle);
} catch (Exception $e) {
    exitWithResponse(false, 'error: ' . $e->getMessage());
}
exitWithResponse(true, 'all good, file ' . $strConfigFQFilename . ' saved');
/**
 * create the DOM from a node
 * 
 * @param   object  $objMasterDOM   master-DOM
 * @param   array   $arrConfig      the configuration received from the editor, or a part of it
 * @returns object                  DOM-object
 * @throws  InvalidArgumentException
 */
function createDOMFromData($objMasterDOM, $arrConfig)
{
    if (false === isset($arrConfig['nodeName'])) {
        throw new InvalidArgumentException('node has no name, ' . var_export($arrConfig, true));
    }
    if ($arrConfig['nodeName'] == '#text') {
        // this is a masqueraded text-only node