require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'CLI.php'; require_once dirname(__FILE__) . '/../lib/I2CE.php'; require_once dirname(__FILE__) . '/../lib/I2CE_FileSearch.php'; require_once dirname(__FILE__) . '/../lib/I2CE_TemplateMeister.php'; require_once dirname(__FILE__) . '/../lib/I2CE_MagicDataTemplate.php'; require_once dirname(__FILE__) . '/../modules/Pages/lib/I2CE_Template.php'; require_once dirname(__FILE__) . '/../modules/MagicDataExport/I2CE_MagicDataExport_Template.php'; if (count($arg_files) != 1) { usage("Please specify list html"); } $in_file = realpath($arg_files[0]); $out_file = dirname($in_file) . '/' . basename($in_file, '.html') . '.xml'; $template = new I2CE_Template(); $template->loadRootFile($in_file); $data = array(); foreach ($template->query('//li/a') as $a) { $li = $a->parentNode; $href = $a->getAttribute('href'); $comp = parse_url($href); if (!is_array($comp) || !array_key_exists('query', $comp) || !$comp['query'] || $li->tagName != 'li') { echo "Skipping(0): " . $a->textContent . " : href=" . $href . "\n"; continue; } $qry = array(); parse_str($comp['query'], $qry); if (!is_array($qry) || !array_key_exists('type', $qry)) { echo "Skipping(1): " . $a->textContent . " : href=" . $href . "\n"; continue; } $type = $qry['type']; unset($qry['type']);
/** * Process this form field as a DOM element to place it in the template at the given node. * * @param DOMNode $node * @param I2CE_Template $template */ public function processDOM($node, $template) { $i2ce_config = I2CE::getConfig()->modules->forms; $ele_name = $this->getHTMLName(); $showForm = $this->withinForm($node); if ($node->hasAttribute("href")) { //This is a link if ($node->hasAttribute("no_value")) { $href_link = $node->getAttribute("href"); } else { $href_link = $node->getAttribute("href") . $this->getDBValue(); } if ($node->hasAttribute("parent") && $this->getContainer() instanceof I2CE_Form) { //needs to be handled better $href_link .= "&parent=" . $this->getContainer()->getParent(); } $href = $template->createElement("a", array("href" => $href_link)); if ($node->attributes instanceof DOMNamedNodeMap) { foreach ($node->attributes as $name => $attrNode) { if ($name == 'href' || !$attrNode instanceof DOMAttr) { continue; } $href->setAttribute($name, $attrNode->value); } } $node->parentNode->replaceChild($href, $node); while ($node->firstChild instanceof DOMNode) { $href->appendChild($node->firstChild); } $node = $href; } elseif ($node->hasAttribute("head") || $node->hasAttribute("showhead")) { if ($node->hasAttribute("head")) { $head = $node->getAttribute("head"); } else { $head_type = $node->getAttribute("showhead"); if ($this->hasHeader($head_type)) { $head = $this->getHeader($head_type); } elseif ($this->hasHeader()) { $head = $this->getHeader(); } else { $head = ucfirst($this->getName()); } } $display = 'default'; if ($node->hasAttribute("display")) { $t_display = $node->getAttribute('display'); if (strtolower($t_display) != 'true' && strtolower($t_display) != 'false') { if (isset($i2ce_config->template_displays->{$t_display})) { $display = $t_display; } } else { $display = strtolower($t_display); } } if ($showForm) { $template_file = 'form_field.html'; $template_file_root = 'p'; $i2ce_config->setIfIsSet($template_file, "template_displays/default/showForm/field"); $i2ce_config->setIfIsSet($template_file, "template_displays/{$display}/showForm/field"); if ($display !== 'default') { $i2ce_config->setIfIsSet($template_file_root, "template_displays/default/showForm/field_root"); $i2ce_config->setIfIsSet($template_file_root, "template_displays/{$display}/showForm/field_root"); } } else { $template_file = 'display_field.html'; $template_file_root = 'tr'; $i2ce_config->setIfIsSet($template_file, "template_displays/default/displayed/field"); $i2ce_config->setIfIsSet($template_file, "template_displays/{$display}/displayed/field"); if ($display !== 'default') { $i2ce_config->setIfIsSet($template_file_root, "template_displays/default/displayed/field_root"); $i2ce_config->setIfIsSet($template_file_root, "template_displays/{$display}/displayed/field_root"); } } $form_node = $template->loadFile($template_file, $template_file_root); $node->parentNode->replaceChild($form_node, $node); foreach (array('class', 'auto_link') as $a) { //I hate having an explicit reference to auto_link here :-( if ($node->hasAttribute($a)) { $form_node->setAttribute($a, $node->getAttribute($a)); } } $title_attr = null; if ($node->hasAttribute("title")) { $title_attr = $node->getAttribute("title"); } elseif ($node->hasAttribute("showtitle")) { $title_type = $node->getAttribute("showtitle"); if ($this->hasHeader($title_type)) { $title_attr = $this->getHeader($title_type); } elseif ($this->hasHeader("title")) { $title_attr = $this->getHeader("title"); } } if ($title_attr !== null) { $form_node->setAttribute("title", $title_attr); } $field_head_class = 'field_head'; $form_field_class = 'form_field'; $i2ce_config->setIfIsSet($field_head_class, "template_displays/default/field_head_class"); $i2ce_config->setIfIsSet($form_field_class, "template_displays/default/form_field_class"); if ($display !== 'default') { $i2ce_config->setIfIsSet($field_head_class, "template_displays/{$display}/field_head_class"); $i2ce_config->setIfIsSet($form_field_class, "template_displays/{$display}/form_field_class"); } $head_node = $template->query("descendant::*[@class='" . $field_head_class . "']", $form_node); if ($head_node->length > 0) { $head_node = $head_node->item(0); } else { $head_node = false; } $field_node = $template->query("descendant::*[@class='" . $form_field_class . "']", $form_node); if ($field_node->length > 0) { $field_node = $field_node->item(0); } else { $field_node = false; } if ($field_node) { $field_name = $this->getContainer()->getName() . '_' . $this->getName(); $template->addClass($field_node, $field_name); while ($node->hasChildNodes()) { $field_node->appendChild($node->childNodes->item(0)); } } if ($head_node) { $head_node->appendChild($template->createElement("label", array("for" => $ele_name), $head)); } if ($head_node && $node->hasAttribute("showhelp")) { $title_type = $node->getAttribute("showhelp"); if ($this->hasHeader($title_type)) { $title_attr = $this->getHeader($title_type); $head_node->appendChild($template->createElement("span", array('title' => $title_attr, 'class' => 'fieldhelp'), " (?) ")); } } if (!$showForm) { if ($field_node) { $field_node->appendChild($this->getDisplayNode($node, $template)); } } elseif ($display == 'true') { if ($field_node) { $field_node->appendChild($this->getDisplayNode($node, $template)); } } elseif ($template->isReview() || $node->hasAttribute("noedit") && $node->getAttribute('noedit') && $this->issetValue() || $node->hasAttribute('noedit') && $node->getAttribute('noedit') == 'strict') { if ($field_node) { $processorNotEditable = 'processDOMNotEditable'; if ($node->hasAttribute('display') && $this->_hasMethod('processDOMNotEditable_' . $node->getAttribute('display'))) { $processorNotEditable = 'processDOMNotEditable_' . $node->getAttribute('display'); } if ($node->hasAttribute('display')) { $field_node->setAttribute('display', $node->getAttribute('display')); } $this->{$processorNotEditable}($field_node, $template, $node); } } else { $this->setElement(false); $this->processHeaderEditable($template, $node, $head_node); if ($field_node) { if ($this->hasInvalid()) { $this->displayInvalid($template, $field_node); } $processorEditable = 'processDOMEditable'; if ($node->hasAttribute('display') && $this->_hasMethod('processDOMEditable_' . $node->getAttribute('display'))) { $processorEditable = 'processDOMEditable_' . $node->getAttribute('display'); } $postprocessorEditable = 'postprocessDOMEditable'; if ($node->hasAttribute('display') && $this->_hasMethod('postprocessDOMEditable_' . $node->getAttribute('display'))) { $postprocessorEditable = 'postprocessDOMEditable_' . $node->getAttribute('display'); } $this->{$processorEditable}($field_node, $template, $node); $this->{$postprocessorEditable}($field_node, $template, $node); } $element = $this->getElement(); if ($element) { if ($this->hasInvalid()) { $class = "error"; if ($element->hasAttribute("class")) { $class .= " " . $element->getAttribute("class"); } $element->setAttribute("class", $class); } if ($node->hasAttribute("onchange")) { $element->setAttribute("onchange", $node->getAttribute("onchange")); } if ($node->hasAttribute("onfocus")) { $element->setAttribute("onfocus", $node->getAttribute("onfocus")); } } } } else { if (!$showForm || $node->hasAttribute("noedit")) { // Just replacing the node text with the value in the database. $node->appendChild($this->getDisplayNode($node, $template)); } else { $options = array("name" => $ele_name, "type" => "hidden", "value" => $this->getDBValue()); if ($node->hasAttribute('alt_name')) { $options['name'] = $node->getAttribute('alt_name'); } $hidden = $template->createElement("input", $options); $node->parentNode->replaceChild($hidden, $node); } } }
/** * Ensure that a node is really a node. If it is not, hopes that it is an ID * and then makes it the corresponding node * @param I2CE_Template $template * @param mixed &$node. Either a DOMNode or a node id. * @param bool $make_doc_on_failure defaults to true. If we can't find the node, make it the document element * If false, we leave $node alone. */ protected function ensureNodeArray($template, $node, $make_doc_on_failure = true) { if ($node instanceof DOMNode) { return array($node); } if ($node instanceof DOMNodeList) { $nodes = array(); for ($i = 0; $i < $node->length; $i++) { $nodes[] = $node->item($i); } return $nodes; } if (is_string($node)) { $nodes = $template->query("//*[@id='{$node}']"); if ($nodes->length > 0) { return $this->ensureNodeArray($template, $nodes, $make_doc_on_failure); } else { if ($make_doc_on_failure) { return array($template->getDoc()->documentElement); } else { return array($node); //node does not exist at this point } } } //we got some garbage if ($make_doc_on_failure) { return array($template->getDoc()->documentElement); } else { return array(); } }