} foreach ($xpath->query('//version') as $node) { if ($node instanceof DOMElement) { $node->appendChild($dom->createTextNode('.1')); //hack to trigger an update for 4.1.10 release due translations not being loaded on updates } } $results = $xpath->query('//*[@locale]'); for ($i = 0; $i < $results->length; $i++) { $results->item($i)->setAttribute('locale', $locale); } $out = $dom->saveXML(); if (function_exists('tidy_get_output')) { $tidy = new tidy(); $tidy_config = array('input-xml' => true, 'output-xml' => true, 'indent' => true, 'wrap' => 0); $tidy->isXML(); $tidy->parseString($out, $tidy_config, 'UTF8'); $tidy->cleanRepair(); $out = tidy_get_output($tidy); } if ($booleans['create_archive']) { $cwd = realpath(getcwd()); $c_path = realpath($configs[$module]); if (strpos($c_path, $cwd) !== 0) { I2CE::raiseError("Cannot determine module sub-directory structure for {$module}", E_USER_ERROR); } $target_dir = $archive_dir . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . substr($c_path, strlen($cwd)) . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR; } else { $target_dir = $configs[$module] . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR; } if (!is_dir($target_dir)) {
/** * Returns the displayed page as a (tidy!) string * @returns string */ public function getDisplay() { $out = $this->doc->saveXML(); if (function_exists('tidy_get_output')) { $tidy = new tidy(); $config = array('input-xml' => true, 'output-xml' => true, 'indent' => true, 'wrap' => 0); $tidy->isXML(); $tidy->parseString($out, $config); $tidy->cleanRepair(); $out = tidy_get_output($tidy); } return $out; }
function createConfigFile($module, $results, $config, $dom) { global $storage; $trans = new DOMDocument('1.0', 'UTF-8'); $trans->substituteEntities = false; $trans->encoding = 'UTF-8'; $trans->preserveWhiteSpace = true; $trans->formatOuput = false; $trans->loadXML('<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE I2CEConfiguration SYSTEM "I2CE_Configuration.dtd"> <I2CEConfiguration> </I2CEConfiguration>'); $xpath = new DOMXPath($trans); $dom_xpath = new DOMXPath($dom); $dom_config = $dom_xpath->query('/I2CEConfiguration/configurationGroup'); $i2ceconfig = $xpath->query('/I2CEConfiguration'); if ($i2ceconfig->length != 1) { I2CE::raiseError("Yell at carl"); return false; } $i2ceconfig = $i2ceconfig->item(0); $i2ceconfig->setAttribute('name', $module); if ($dom_config->length == 1) { $dom_config = $dom_config->item(0); foreach (array('path', 'config', 'name') as $attr) { if ($dom_config->hasAttribute($attr)) { $i2ceconfig->setAttribute($attr, $dom_config->getAttribute($attr)); } } } $meta = $trans->createElement('metadata'); $i2ceconfig->appendChild($meta); $version = $trans->createElement('version', $storage->config->data->{$module}->version); $meta->appendChild($version); //$trans->documentElement->appendChild($i2ceconfig); $trans->appendChild($i2ceconfig); $imports = array(); $burned = false; for ($i = 0; $i < $results->length; $i++) { $node = $results->item($i); if ($node->hasAttribute('import_index')) { I2CE::raiseError("weird double import in {$module} config file. " . $node->tagName . ":" . $node->getAttribute('import_index') . "/" . count($import_index)); return false; } $t_node = $node; if ($node->tagName == 'value') { // (for the moment) we only alow the following types to be translatable: // single string // single delimited // many delimited $parent = $node->parentNode; if ($parent->hasAttribute('type')) { $type = $parent->getAttribute('type'); } else { $type = 'string'; } if ($parent->hasAttribute('values') && $parent->getAttribute('values') == 'many') { if ($type != 'delimited') { //skip this node continue; } } else { //values ='single' or is implicitly single if (!($type == 'string' || $type == 'delimited')) { //skip this node continue; } } } $import = $trans->importNode($node, true); //import the <value/description/displayNam/category> node with its attributes and contents if ($import->tagName == 'value') { //just to keep it a bit cleaner -- values inhereit locale and we will set the top level inheritence $import->removeAttribute('locale'); } $locale = false; $t_import = null; $cat = null; $desc = null; while ($t_node instanceof DOMElement) { if (!$locale && $t_node->hasAttribute('locale')) { if ($t_node->getAttribute('locale') != I2CE_Locales::DEFAULT_LOCALE) { //double check that this node is really en_US: //for example we could have done <configurationGroup locale='en_Us'><cofiguration locale='fr_FR'><value>me</value> continue 2; //continue to the next <value/description/displayName/category> node } else { $locale = true; } } if ($t_import instanceof DOMNode) { if ($t_node->hasAttribute('import_index')) { //we already imported this node. $imports[$t_node->getAttribute('import_index')]->appendChild($t_import); break; //out of while } $import->appendChild($t_import); } $t_node->setAttribute('import_index', count($imports)); $imports[] = $import; if ($t_node->parentNode->tagName == 'I2CEConfiguration') { //$import and $t_node are the top-level configurationGroup. this should only happen once $import->setAttribute('locale', I2CE_Locales::DEFAULT_LOCALE); $i2ceconfig->appendChild($import); if ($burned) { I2CE::raiseError("Burned in {$module} "); return false; } $burned = true; break; //out of while } else { if ($t_node->parentNode->tagName == 'metadata') { $import->setAttribute('locale', I2CE_Locales::DEFAULT_LOCALE); switch ($import->tagName) { case 'description': $desc = $import; $meta->insertBefore($desc, $version); break 2; //out of while //out of while case 'category': $cat = $import; if ($desc instanceof DOMElement) { $meta->insertBefore($cat, $desc); } else { $meta->insertBefore($cat, $version); } break 2; //out of while //out of while case 'displayName': $disp = $import; if ($cat instanceof DOMElement) { $meta->insertBefore($disp, $cat); } else { if ($desc instanceof DOMElement) { $meta->insertBefore($disp, $desc); } else { $meta->insertBefore($disp, $version); } } break 2; //out of while //out of while default: I2CE::raiseError("Unexpected tag " . $import->tagName . " in metadata"); return false; } } } $t_node = $t_node->parentNode; if (!$t_node instanceof DOMElement) { I2CE::raiseError("Expected element but not gotten in {$module}. "); return false; } $t_import = $import; $import = $trans->importNode($t_node, false); foreach (array('name', 'path', 'values', 'type', 'config') as $attr) { if ($t_node->hasAttribute($attr)) { $import->setAttribute($attr, $t_node->getAttribute($attr)); } } //check for <status>version:XXXX</status> $statii = $dom_xpath->query('./status', $t_node); for ($j = 0; $j < $statii->length; $j++) { $status = $statii->item($j); if (preg_match('/^version:.+$/', trim($status->textContent), $matches)) { $import->appendChild($trans->createElement('status', trim($status->textContent))); } } } } if (!$trans->documentElement->hasChildNodes()) { //should be exactly one, the top-level configurationGroup I2CE::raiseError("Was not able to extract translatable strings from {$file} for {$module} "); return false; } $results = $xpath->query('/I2CEConfiguration/configurationGroup'); if ($results->length > 0) { $version_node = $trans->createElement('version', $storage->config->data->{$module}->version); $results->item(0)->insertBefore($version_node, $results->item(0)->firstChild); } $out = $trans->saveXML(); if (function_exists('tidy_get_output')) { $tidy = new tidy(); $tidy_config = array('input-xml' => true, 'output-xml' => true, 'indent' => true, 'wrap' => 0); $tidy->isXML(); $tidy->parseString($out, $tidy_config, 'UTF8'); $tidy->cleanRepair(); $out = tidy_get_output($tidy); } I2CE::raiseError("Creating {$config}"); if (!file_put_contents($config, $out)) { I2CE::raiseError("Could not save {$config} for {$module} "); return false; } return true; }
/** * Returns the displayed page as a string * @returns string */ public function getDisplay() { return $this->doc->saveHTML(); if (function_exists('tidy_get_output')) { $this->removeProprietaryAttr(); $out = $this->doc->saveHTML(); //$out = htmlentities($out,ENT_COMPAT,'UTF-8'); $tidy = new tidy(); $config = array('indent' => true, 'wrap' => 0, 'quote-ampersand' => false, 'numeric-entities' => false, 'quote-marks' => false, 'preserve-entities' => false, 'output-html' => false, 'output-xml' => false, 'output-xhtml' => true, 'char-encoding' => 'utf8', 'input-encoding' => 'utf8', 'output-encoding' => 'utf8', 'input-xml' => false); $tidy->isXML(); $tidy->parseString($out, $config, 'UTF8'); $tidy->cleanRepair(); $out = tidy_get_output($tidy); return $out; } else { return $this->doc->saveHTML(); } }
/** * Returns the displayed page as a (tidy!) string * @param boolean $decode_entities Set if you want to decode HTML * entities back to the original * ignoring HTML specialchars * @param int $decode_flags default is ENT_NOQUOTES * @returns string */ public function getDisplay($decode_entities = false, $decode_flags = ENT_NOQUOTES) { $out = $this->doc->saveXML(); if (function_exists('tidy_get_output')) { $tidy = new tidy(); $config = array('input-xml' => true, 'output-xml' => true, 'indent' => true, 'wrap' => 0); $tidy->isXML(); $tidy->parseString($out, $config); $tidy->cleanRepair(); $out = tidy_get_output($tidy); } if ($decode_entities) { foreach (get_html_translation_table(HTML_SPECIALCHARS, $decode_flags) as $code) { $out = str_replace($code, htmlspecialchars($code), $out); } return html_entity_decode($out, $decode_flags); } else { return $out; } }