/** * @param DOMNode $node * @param I2CE_Template $template * @param DOMNode $form_node * */ public function processDOMEditable_reportSelect($node, $template, $form_node) { $mf = I2CE_ModuleFactory::instance(); if (!$mf->isEnabled('CustomReports-Selector')) { return false; } $template->addHeaderLink("mootools-more.js"); $template->addHeaderLink("getElementsByClassName-1.0.1.js"); $template->addHeaderLink("I2CE_ClassValues.js"); $template->addHeaderLink("I2CE_Window.js"); $template->addHeaderLink("I2CE_ToggableWindow.js"); $template->addHeaderLink("I2CE_TreeSelect.js"); $template->addHeaderLink('Observer.js'); $template->addHeaderLink('Autocompleter.js'); $template->addHeaderLink('Autocompleter.css'); $template->addHeaderLink('I2CE_TreeSelectAutoCompleter.js'); $template->addHeaderLink("Tree.css"); $style = 'default'; if ($form_node->hasAttribute('show')) { $style = $this->ensureEditStyle($form_node->getAttribute('show')); } $styles = array($style); if ($style != 'default') { $styles[] = 'default'; } foreach ($styles as $style) { $edit_path = "meta/reportSelect/{$style}"; $report_path = "{$edit_path}/reportView"; if (!$this->optionsHasPath($edit_path) || !is_array($options = $this->getOptionsByPath($edit_path))) { continue; } if (!$this->optionsHasPath($report_path) || !is_scalar($reportView = $this->getOptionsByPath($report_path))) { continue; } $report = false; $relationship = false; $form = false; I2CE::getConfig()->setIfIsSet($report, "/modules/CustomReports/reportViews/{$reportView}/report"); if (!$report) { continue; } I2CE::getConfig()->setIfIsSet($relationship, "/modules/CustomReports/reports/{$report}/relationship"); if (!$relationship) { continue; } $form = false; $reportform_path = "meta/reportSelect/{$style}/reportform"; $reportform = 'primary_form'; if ($this->optionsHasPath($reportform_path)) { //we are not using the primary form in the relationship, instead we are using a named form. $reportform = $this->getOptionsByPath($reportform_path); if ($reportform == 'primary_form') { I2CE::getConfig()->setIfIsSet($form, "/modules/CustomReports/relationships/{$relationship}/form"); } else { try { $relObj = new I2CE_FormRelationship($relationship); } catch (Exception $e) { continue; } $form = $relObj->getForm($reportform); } } else { //we use the primary form I2CE::getConfig()->setIfIsSet($form, "/modules/CustomReports/relationships/{$relationship}/form"); } if (!$form) { continue; } if (!$this->canSelectAnyForm()) { $form_path = "meta/form"; if (!$this->optionsHasPath($form_path) || !is_array($forms = $this->getOptionsByPath($form_path))) { continue; } if (!in_array($form, $forms)) { continue; } } $printf_path = "meta/display/{$form}/{$style}/printf"; $printfargs_path = "meta/display/{$form}/{$style}/printf_args"; if (!$this->optionsHasPath($printf_path) || !is_string($printf = $this->getOptionsByPath($printf_path))) { continue; } if (!$this->optionsHasPath($printfargs_path) || !is_array($printfargs = $this->getOptionsByPath($printfargs_path))) { continue; } if (strlen($printf) == 0) { continue; } if (count($printfargs) == 0) { continue; } ksort($printfargs); $disp = $this->_getDisplayValue(null, $style); $node->setAttribute('id', $this->getHTMLName()); $options = array('reportview' => $reportView, 'printf' => $printf, 'printfargs' => $printfargs, 'display' => $disp, 'value' => $this->getDBValue(), 'reportform' => $reportform); $no_limits_path = "meta/display/{$form}/{$style}/no_limits"; if ($this->optionsHasPath($no_limits_path) && $this->getOptionsByPath($no_limits_path)) { $options['contentid'] = 'report_results'; } else { $options['contentid'] = 'report_results_with_limits'; } $options['multi_select'] = 1; if ($template->addReportSelector($node, $options)) { return true; } } return false; }
/** * @param DOMNode $node * @return string of type */ public static function getXsdElementName(DOMNode $node) { if ($node->localName == 'element' || $node->localName == 'attribute') { if ($node->hasAttribute('name')) { return $node->getAttribute('name'); } return null; } // nowhere else to search if (is_null($node->parentNode)) { return null; } return self::getXsdElementName($node->parentNode); }
public function parse(DOMNode $element) { if ($element->hasAttribute('name')) { $this->name = $element->getAttribute('name'); } if ($element->hasAttribute('type')) { $this->type = $element->getAttribute('type'); } for ($i = 0; $i < $element->childNodes->length; $i++) { $childElement = $element->childNodes->item($i); if ($childElement->parentNode !== $element) { continue; } if ($childElement instanceof DOMComment || $childElement instanceof DOMText) { continue; } switch ($childElement->nodeName) { case 'part': $this->parts[] = new Ezer_XmlVariable($childElement); break; default: throw new Ezer_XmlPersistanceElementNotMappedException($childElement->nodeName); } } }
function process(DOMNode $current_node) { global $filter_args, $filter_tags, $filter_mandatory, $bbcode; if ($current_node instanceof DOMElement || $current_node instanceof DOMDocument) { // Recursion. I need iterator_to_array(), because it's likely // that node list will be modified. foreach (iterator_to_array($current_node->childNodes) as $node) { process($node); } // BBCode hack is NOT allowed to exist if ($current_node->tagName === 'bbcodehack') { $value = $current_node->hasAttribute('value') ? $current_node->getAttribute('value') : NULL; $nodes = $current_node->hasAttribute('pre') ? $current_node->getAttribute('pre') : $current_node->childNodes; $nodes = $bbcode[$current_node->getAttribute('name')]['callback']($current_node->ownerDocument, $nodes, $value, array('borked' => $current_node->hasAttribute('borked'))); if (!is_array($nodes)) { $nodes = array($nodes); } foreach ($nodes as $node) { $current_node->parentNode->insertBefore($node, $current_node); } // Remove bbcodehack from DOM $current_node->parentNode->removeChild($current_node); } elseif ($current_node->tagName && !isset($filter_tags[$current_node->tagName])) { while ($current_node->hasChildNodes()) { $current_node->parentNode->insertBefore($current_node->childNodes->item(0), $current_node); } $current_node->parentNode->removeChild($current_node); } else { if ($current_node->hasAttributes()) { // I need iterator_to_array, as I modify attributes // list while iterating. foreach (iterator_to_array($current_node->attributes) as $attr) { $attribute = isset($filter_tags[$current_node->tagName][$attr->name]) ? $filter_tags[$current_node->tagName][$attr->name] : (isset($filter_args[$attr->name]) ? $filter_args[$attr->name] : NULL); if (!$attribute) { $current_node->removeAttribute($attr->name); } elseif (!is_bool($attribute)) { $value = $attribute($attr->value, $current_node); if ($value === NULL) { $current_node->removeAttribute($attr->name); } else { $current_node->setAttribute($attr->name, $value); } } } } if (isset($filter_mandatory[$current_node->tagName])) { foreach ($filter_mandatory[$current_node->tagName] as $attr => $value) { if (!$current_node->hasAttribute($attr)) { $current_node->setAttribute($attr, $value); } } } } } elseif ($current_node instanceof DOMComment) { // Unsafe because of conditional comments $current_node->parentNode->removeChild($current_node); } }
public function sanitize(\DOMNode $node) { if ($this->haveToTrim() && $node->hasAttribute($this->name)) { $node->setAttribute($this->name, trim($node->getAttribute($this->name))); } if ($this->repair && !$node->hasAttribute($this->name)) { $node->setAttribute($this->name, $this->repairValue); } }
private function processDataTag( DOMNode $node ) { if( $node->hasAttribute( DATA_TYPE_ATTRIBUTE_NAME ) ) { switch( $node->getAttribute( DEPENDENCY_TYPE_ATTRIBUTE_NAME ) ) { case DATA_TYPE_STREAM_VALUE: /******* nothing for now $url = $this->buildURL( MODULE_STREAM_PATH . $node->nodeValue ); if( $this->url_exists( $url ) ) { $this->xml->load( $url ); } **********/ break; case DATA_TYPE_PROCESSOR_VALUE: break; case DATA_TYPE_DYNAMICFILE_VALUE: if ( file_exists( MODULE_FILE_PATH . $node->nodeValue ) ) { ob_start(); $file = MODULE_FILE_PATH . $node->nodeValue; include $file; $this->dynamicFileOutput .= ob_get_contents(); ob_end_clean(); } break; case DATA_TYPE_STATICFILE_VALUE: if ( file_exists( MODULE_FILE_PATH . $node->nodeValue ) ) { $this->staticFileOutput .= file_get_contents( MODULE_FILE_PATH . $node->nodeValue ); } else { //echo "loading: " . MODULE_FILE_PATH . $node->nodeValue; } break; } } }
/** * Return the string for generating a new password for the form prompt. * @param DOMNode $form_node The form node that has the generate attribute */ protected function getGenerateText($form_node) { if ($form_node->hasAttribute("generate")) { return $form_node->getAttribute("generate"); } elseif ($this->hasHeader("generate")) { return $this->getHeader("generate"); } return null; }
/** * Determine if node contains HTML signature image data. * * @param DOMNode $node The node to check. * @param boolean $strip Strip attribute from the node? * * @return boolean True if node contains image data. */ public static function isSigImage(DOMNode $node, $strip = false) { if (strcasecmp($node->tagName, 'IMG') === 0 && $node->hasAttribute(self::HTMLSIG_ATTR)) { if ($strip) { $node->removeAttribute(self::HTMLSIG_ATTR); } return true; } return false; }
/** * Check for a list of attributes if current node is valid * * @param DOMNode $node to check if valid * @param array $attrs to test if in $node * * @return boolean true if $node is valid for $attrs, false otherwise */ public static function isValidNodeAttrs($node, $attrs) { foreach ($attrs as $attr) { $val = ''; if (strpos($attr, '=') !== false) { list($attr, $val) = explode('=', $attr); } if (!$node->hasAttribute($attr) || !empty($val) && $node->getAttribute($attr) !== $val) { return false; } } return true; }
public function setNode(DOMNode $node) { if (!$this->parentNode) { throw new Exception('Parent Node must be set before actual Node'); } $this->externalNode = $node; $this->element = $this->doc->createElement($this->getTagName()); if ($this->keepAttributes) { foreach ($this->externalNode->attributes as $attr) { if ($attr->name == 'class') { $this->className = strlen($this->className) ? $this->className . ' ' . $attr->value : $attr->value; } elseif ($attr->name == "data-pxe-attributes") { $attributes = json_decode($attr->value); foreach ($attributes as $name => $value) { $this->element->setAttribute($name, $value); } } elseif (substr($attr->name, 0, 8) != 'data-pxe' && substr($attr->name, 0, 7) !== 'data-ca') { if (!array_key_exists($attr->name, $this->element->attributes)) { $this->element->setAttribute($attr->name, $attr->value); } } } } // Keep attribute explicitly asked for by editor regardless of how smart you think you are. foreach ($this->attributes as $key => $value) { if ($this->element->hasAttribute($key)) { $value = $this->element->getAttribute($key)->value . ' ' . $value; } $this->element->setAttribute($key, $value); } if ($this->className) { $this->element->setAttribute('class', $this->className); } $this->parentNode->appendChild($this->element); return $this; }
/** @inheritDoc */ public function attr($name = null, $fallback = null) { if ($this->is('#element')) { // We consider only regular DOM elements can have attributes. Text nodes, // comments, etc... don't have ones. if (is_null($name)) { // No argument given: return the whole collection. return new AttrCollection($this->source->attributes); } else { if ($this->source->hasAttribute($name)) { return $this->source->getAttribute($name); } else { return $fallback; } } } else { return $fallback; } }
/** * @param \DOMNode $srcNode * @param bool $lineNumbered * @param bool $inP * * @return \DOMNode[] * @throws \Exception */ protected function html2ooNodeInt($srcNode, $lineNumbered, $inP) { switch ($srcNode->nodeType) { case XML_ELEMENT_NODE: /** @var \DOMElement $srcNode */ if ($this->DEBUG) { echo "Element - " . $srcNode->nodeName . " / Children: " . count($srcNode->childNodes) . "<br>"; } $needsIntermediateP = false; switch ($srcNode->nodeName) { case 'span': $dstEl = $this->doc->createElementNS(static::NS_TEXT, 'span'); if ($srcNode->hasAttribute('class')) { $classes = explode(' ', $srcNode->getAttribute('class')); if (in_array('underline', $classes)) { $dstEl->setAttribute('text:style-name', 'AntragsgruenUnderlined'); } if (in_array('strike', $classes)) { $dstEl->setAttribute('text:style-name', 'AntragsgruenStrike'); } if (in_array('ins', $classes)) { $dstEl->setAttribute('text:style-name', 'AntragsgruenIns'); } if (in_array('inserted', $classes)) { $dstEl->setAttribute('text:style-name', 'AntragsgruenIns'); } if (in_array('del', $classes)) { $dstEl->setAttribute('text:style-name', 'AntragsgruenDel'); } if (in_array('deleted', $classes)) { $dstEl->setAttribute('text:style-name', 'AntragsgruenDel'); } if (in_array('superscript', $classes)) { $dstEl->setAttribute('text:style-name', 'AntragsgruenSup'); } if (in_array('subscript', $classes)) { $dstEl->setAttribute('text:style-name', 'AntragsgruenSub'); } } break; case 'b': case 'strong': $dstEl = $this->doc->createElementNS(static::NS_TEXT, 'span'); $dstEl->setAttribute('text:style-name', 'AntragsgruenBold'); break; case 'i': case 'em': $dstEl = $this->doc->createElementNS(static::NS_TEXT, 'span'); $dstEl->setAttribute('text:style-name', 'AntragsgruenItalic'); break; case 's': $dstEl = $this->doc->createElementNS(static::NS_TEXT, 'span'); $dstEl->setAttribute('text:style-name', 'AntragsgruenStrike'); break; case 'u': $dstEl = $this->doc->createElementNS(static::NS_TEXT, 'span'); $dstEl->setAttribute('text:style-name', 'AntragsgruenUnderlined'); break; case 'sub': $dstEl = $this->doc->createElementNS(static::NS_TEXT, 'span'); $dstEl->setAttribute('text:style-name', 'AntragsgruenSub'); break; case 'sup': $dstEl = $this->doc->createElementNS(static::NS_TEXT, 'span'); $dstEl->setAttribute('text:style-name', 'AntragsgruenSup'); break; case 'br': $dstEl = $this->doc->createElementNS(static::NS_TEXT, 'line-break'); break; case 'del': $dstEl = $this->doc->createElementNS(static::NS_TEXT, 'span'); $dstEl->setAttribute('text:style-name', 'AntragsgruenDel'); break; case 'ins': $dstEl = $this->doc->createElementNS(static::NS_TEXT, 'span'); $dstEl->setAttribute('text:style-name', 'AntragsgruenIns'); break; case 'a': $dstEl = $this->doc->createElementNS(static::NS_TEXT, 'a'); try { $attr = $srcNode->getAttribute('href'); if ($attr) { $dstEl->setAttribute('xlink:href', $attr); } } catch (\Exception $e) { } break; case 'p': case 'div': if ($inP) { $dstEl = $this->createNodeWithBaseStyle('span', $lineNumbered); } else { $dstEl = $this->createNodeWithBaseStyle('p', $lineNumbered); } $inP = true; break; case 'blockquote': $dstEl = $this->createNodeWithBaseStyle('p', $lineNumbered); $class = $lineNumbered ? 'Blockquote_Linenumbered' : 'Blockquote'; $dstEl->setAttribute('text:style-name', 'Antragsgrün_20_' . $class); if (count($srcNode->childNodes) == 1) { foreach ($srcNode->childNodes as $child) { if ($child->nodeName == 'p') { $srcNode = $child; } } } $inP = true; break; case 'ul': $dstEl = $this->doc->createElementNS(static::NS_TEXT, 'list'); break; case 'ol': $dstEl = $this->doc->createElementNS(static::NS_TEXT, 'list'); break; case 'li': $dstEl = $this->doc->createElementNS(static::NS_TEXT, 'list-item'); $needsIntermediateP = true; $inP = true; break; case 'h1': $dstEl = $this->createNodeWithBaseStyle('p', $lineNumbered); $dstEl->setAttribute('text:style-name', 'Antragsgrün_20_H1'); $inP = true; break; case 'h2': $dstEl = $this->createNodeWithBaseStyle('p', $lineNumbered); $dstEl->setAttribute('text:style-name', 'Antragsgrün_20_H2'); $inP = true; break; case 'h3': $dstEl = $this->createNodeWithBaseStyle('p', $lineNumbered); $dstEl->setAttribute('text:style-name', 'Antragsgrün_20_H3'); $inP = true; break; case 'h4': case 'h5': case 'h6': $dstEl = $this->createNodeWithBaseStyle('p', $lineNumbered); $dstEl->setAttribute('text:style-name', 'Antragsgrün_20_H4'); $inP = true; break; default: throw new \Exception('Unknown Tag: ' . $srcNode->nodeName); } foreach ($srcNode->childNodes as $child) { /** @var \DOMNode $child */ if ($this->DEBUG) { echo "CHILD<br>" . $child->nodeType . "<br>"; } $dstNodes = $this->html2ooNodeInt($child, $lineNumbered, $inP); foreach ($dstNodes as $dstNode) { $dstEl->appendChild($dstNode); } } if ($needsIntermediateP && count($dstEl->childNodes) > 0) { if (!in_array(strtolower($dstEl->childNodes[0]->nodeName), ['p', 'ul', 'ol'])) { $appendNode = $this->getNextNodeTemplate($lineNumbered); while ($dstEl->firstChild) { $el = $dstEl->firstChild; $dstEl->removeChild($el); $appendNode->appendChild($el); } $dstEl->appendChild($appendNode); } } return [$dstEl]; case XML_TEXT_NODE: /** @var \DOMText $srcNode */ $textnode = new \DOMText(); $textnode->data = $srcNode->data; if ($this->DEBUG) { echo 'Text<br>'; } return [$textnode]; break; case XML_DOCUMENT_TYPE_NODE: if ($this->DEBUG) { echo 'Type Node<br>'; } return []; default: if ($this->DEBUG) { echo 'Unknown Node: ' . $srcNode->nodeType . '<br>'; } } }
/** * Add the given class to the DOM * @param DOMNode $oClassNode * @param string $sModuleName The name of the module in which this class is declared * @throws Exception */ public function AddClass(DOMNode $oClassNode, $sModuleName) { if ($oClassNode->hasAttribute('id')) { $sClassName = $oClassNode->GetAttribute('id'); } else { throw new Exception('ModelFactory::AddClass: Cannot add a class with no name'); } if ($this->ClassNameExists($oClassNode->getAttribute('id'))) { throw new Exception("ModelFactory::AddClass: Cannot add the already existing class {$sClassName}"); } $sParentClass = $oClassNode->GetChildText('parent', ''); $oParentNode = $this->GetClass($sParentClass); if ($oParentNode == null) { throw new Exception("ModelFactory::AddClass: Cannot find the parent class of '{$sClassName}': '{$sParentClass}'"); } else { if ($sModuleName != '') { $oClassNode->SetAttribute('_created_in', $sModuleName); } $oParentNode->AddChildNode($this->oDOMDocument->importNode($oClassNode, true)); if (substr($sParentClass, 0, 1) == '/') { // Remove the leading slash character $oParentNameNode = $oClassNode->GetOptionalElement('parent')->firstChild; // Get the DOMCharacterData node $oParentNameNode->data = substr($sParentClass, 1); } } }
/** * Adds a report selector * @param DOMNode $node The node we are adding the selector on. * @param array $options. Array ofoptions. should include keys: 'printf', 'printfargs', 'reportiew' or they should be set as attributes on the node. 'reportform' the form in the report view we want to select (Defaults to primary_form) * other optional keys are 'updateval' and 'updatedisp' which are names of elements to update the name and id of. If not set, then it is 'updateval'=$id:value and 'updatedisp=$id:display * and 'value' which contains the current db value * and 'display' which contains the current display value */ public function addReportSelector($obj, $node, $options = array()) { if ($obj instanceof I2CE_Page) { $template = $obj->getTemplate(); } else { $template = $obj; } if (!$template instanceof I2CE_Template) { return false; } if (!$node instanceof DOMElement) { return false; } if (!$node->hasAttribute('id') || !($id = $node->getAttribute('id'))) { return false; } if (!is_array($options)) { return false; } if ($node->hasAttribute('reportview')) { $options['reportview'] = $node->getAttribute('reportview'); $node->removeAttribute('reportview'); } if ($node->hasAttribute('reportform')) { $options['reportform'] = $node->getAttribute('reportform'); $node->removeAttribute('reportform'); } if ($node->hasAttribute('printf')) { $options['printf'] = $node->getAttribute('printf'); $node->removeAttribute('printf'); } if ($node->hasAttribute('printfargs')) { $options['printfargs'] = explode(',', $node->getAttribute('printfargs')); $node->removeAttribute('printfargs'); } if ($node->hasAttribute('contentid')) { $options['contentid'] = $node->getAttribute('contentid'); $node->removeAttribute('contentid'); } if (!array_key_exists('reportview', $options) || !($reportview = $options['reportview']) || !I2CE::getConfig()->is_parent("/modules/CustomReports/reportViews/{$reportview}") || !array_key_exists('printf', $options) || !$options['printf'] || !array_key_exists('printfargs', $options) || !is_array($options['printfargs']) || count($options['printfargs']) == 0) { return false; } if (!array_key_exists('value', $options)) { $options['value'] = ''; } if (!array_key_exists('display', $options)) { $options['display'] = ''; } if (!is_string($options['display']) || strlen(trim($options['display'])) == 0) { I2CE::getConfig()->setIfIsSet($display['config'], "/modules/CustomReports/displays/Selector/display_options/select_value"); if (!is_string($options['display']) || strlen(trim($options['display'])) == 0) { $options['display'] = 'Select Value'; } } if (!array_key_exists('value', $options)) { $options['value'] = ''; } if (!($mainNode = $template->loadFile("reportselector.html", "div")) instanceof DOMElement) { return false; } if (!($windowNode = $template->getElementByName("window", 0, $mainNode)) instanceof DOMNode) { return false; } if (!($dispNode = $template->getElementByName("display", 0, $mainNode)) instanceof DOMNode) { return false; } if (!($valNode = $template->getElementByName("value", 0, $mainNode)) instanceof DOMNode) { return false; } if (!($selectNode = $template->getElementByName("selector", 0, $mainNode)) instanceof DOMNode) { return false; } $contentNode = $template->appendFileByName("reportselector_content.html", "div", "content", 0, $mainNode); if (!$contentNode instanceof DOMElement) { return false; } $node->appendChild($mainNode); //we are good to go $windowNode->setAttribute('id', $id . ':window'); $dispNode->setAttribute('id', $id . ':display'); $template->addClass($dispNode, $id . '_toggle'); $template->addTextNode($dispNode, $options['display']); $valNode->setAttribute('id', $id . ':value'); $valNode->setAttribute('value', $options['value']); $valNode->setAttribute('name', $id); $jsSelect = "if (reportselectors && reportselectors['" . addslashes($id) . "']) {reportselectors['" . addslashes($id) . "'].show(); return false;} else { return false;}"; $selectNode->setAttribute('onClick', $jsSelect); if (!array_key_exists('allow_clear', $options)) { $options['allow_clear'] = true; } if (($clearNode = $template->getElementByName("clear_value_button", 0, $mainNode)) instanceof DOMNode) { if ($options['allow_clear']) { $jsClear = "if (reportselectors && reportselectors['" . addslashes($id) . "']) {reportselectors['" . addslashes($id) . "'].clear(); return false;} else { return false;}"; $clearNode->setAttribute('onClick', $jsClear); } else { $template->removeNode($clearNode); } } $contentNode->setAttribute('id', $id . ':content'); $this->selectors[$id] = $options; return true; }
/** * Adds a choice to the current ones. * * This method should only be used internally. * * @param \DOMNode $node A \DOMNode * * @throws \LogicException When choice provided is not multiple nor radio */ public function addChoice(\DOMNode $node) { if (!$this->multiple && 'radio' != $this->type) { throw new \LogicException(sprintf('Unable to add a choice for "%s" as it is not multiple or is not a radio button.', $this->name)); } $this->options[] = $value = $node->hasAttribute('value') ? $node->getAttribute('value') : '1'; if ($node->getAttribute('checked')) { $this->value = $value; } }
private function addDependency( DOMNode $node ) { if( $node->hasAttribute( DEPENDENCY_TYPE_ATTRIBUTE_NAME ) ) { switch( $node->getAttribute( DEPENDENCY_TYPE_ATTRIBUTE_NAME ) ) { case DEPENDENCY_TYPE_CLASS_VALUE: require_once( $node->nodeValue . OBJECT_EXTENSION ); array_push( $this->dependentClass, $node->nodeValue ); break; case DEPENDENCY_TYPE_STYLE_VALUE: array_push( $this->dependentStyle, $node->nodeValue ); break; case DEPENDENCY_TYPE_SCRIPT_VALUE: array_push( $this->dependentScript, $node->nodeValue ); break; case DEPENDENCY_TYPE_PARAMETER_VALUE: array_push( $this->dependentParameter, $node->nodeValue ); break; } } }
private function addField(\DOMNode $node) { if (!$node->hasAttribute('name') || !$node->getAttribute('name')) { return; } $nodeName = $node->nodeName; if ('select' == $nodeName || 'input' == $nodeName && 'checkbox' == strtolower($node->getAttribute('type'))) { $this->set(new Field\ChoiceFormField($node)); } elseif ('input' == $nodeName && 'radio' == strtolower($node->getAttribute('type'))) { // there may be other fields with the same name that are no choice // fields already registered (see https://github.com/symfony/symfony/issues/11689) if ($this->has($node->getAttribute('name')) && $this->get($node->getAttribute('name')) instanceof ChoiceFormField) { $this->get($node->getAttribute('name'))->addChoice($node); } else { $this->set(new Field\ChoiceFormField($node)); } } elseif ('input' == $nodeName && 'file' == strtolower($node->getAttribute('type'))) { $this->set(new Field\FileFormField($node)); } elseif ('input' == $nodeName && !in_array(strtolower($node->getAttribute('type')), array('submit', 'button', 'image'))) { $this->set(new Field\InputFormField($node)); } elseif ('textarea' == $nodeName) { $this->set(new Field\TextareaFormField($node)); } }
public function parse(DOMNode $element) { if ($element->hasAttribute('stepName')) { $this->stepName = $element->getAttribute('stepName'); } }
/** * @param \ReflectionClass $testClass * @param \ReflectionMethod $testMethod * @param \DOMNode $failureOrError */ protected function verifyExtendedFailureElements(\ReflectionClass $testClass, \ReflectionMethod $testMethod, \DOMNode $failureOrError) { $this->assertTrue($failureOrError->hasAttribute('file')); $this->assertTrue($failureOrError->hasAttribute('line')); $this->assertTrue($failureOrError->hasAttribute('message')); $this->assertEquals($testClass->getFileName(), $failureOrError->getAttribute('file')); $this->assertThat($failureOrError->getAttribute('line'), $this->greaterThan($testMethod->getStartLine())); $this->assertThat($failureOrError->getAttribute('line'), $this->lessThan($testMethod->getEndLine())); $this->assertThat(strlen($failureOrError->getAttribute('message')), $this->greaterThan(0)); }
/** * Extract content appropriately from atom text constructs * * Because of different rules applied to the content element and other text * constructs, they are deployed as separate functions, but they share quite * a bit of processing. This method performs the core common process, which is * to apply the rules for different mime types in order to extract the content. * * @param DOMNode $content the text construct node to be parsed * @return String * @author James Stewart **/ protected function parseTextConstruct(DOMNode $content) { if ($content->hasAttribute('type')) { $type = $content->getAttribute('type'); } else { $type = 'text'; } if (strpos($type, 'text/') === 0) { $type = 'text'; } switch ($type) { case 'text': return $content->nodeValue; break; case 'html': return str_replace('<', '<', $content->nodeValue); break; case 'xhtml': $container = $content->getElementsByTagName('div'); if ($container->length == 0) { return false; } $contents = $container->item(0); if ($contents->hasChildNodes()) { /* Iterate through, applying xml:base and store the result */ $result = ''; foreach ($contents->childNodes as $node) { $result .= $this->traverseNode($node); } return utf8_decode($result); } break; case preg_match('@^[a-zA-Z]+/[a-zA-Z+]*xml@i', $type) > 0: return $content; break; case 'application/octet-stream': default: return base64_decode(trim($content->nodeValue)); break; } return false; }
/** * Process DOM node. * * @param DOMDocument $doc Document node. * @param DOMNode $node Node. */ protected function _node($doc, $node) { if (!$node instanceof DOMElement) { return; } switch (Horde_String::lower($node->tagName)) { case 'a': /* Strip whitespace from href links. This is bad HTML, but may * prevent viewing of the link. PHP DOM will already strip this * out for us, but if using tidy it will have URL encoded the * spaces. */ if ($node->hasAttribute('href')) { $node->setAttribute('href', preg_replace('/^(\\%20)+/', '', trim($node->getAttribute('href')))); } break; case 'base': /* Deal with <base> tags in the HTML, since they will screw up our * own relative paths. */ if ($this->_tmp['inline'] && $node->hasAttribute('href')) { $base = $node->getAttribute('href'); if (substr($base, -1) != '/') { $base .= '/'; } $this->_tmp['base'] = $base; $node->removeAttribute('href'); } break; } foreach ($node->attributes as $val) { /* Attempt to fix paths that were relying on a <base> tag. */ if (!is_null($this->_tmp['base']) && in_array($val->name, array('href', 'src'))) { $node->setAttribute($val->name, $this->_tmp['base'] . ltrim($val->value, '/')); } if ($val->name == 'href') { if ($this->_tmp['phish'] && $this->_phishingCheck($val->value, $node->textContent)) { $this->_phishWarn = true; foreach (array_merge(array($node), iterator_to_array($node->childNodes)) as $node2) { if ($node2 instanceof DOMElement) { $node2->removeAttribute('color'); $node2->removeAttribute('style'); } } $node->setAttribute('style', ($node->hasAttribute('style') ? rtrim($node->getAttribute('style'), '; ') . ';' : '') . $this->_phishCss); } if (isset($this->_params['external_callback'])) { /* Try to derefer all external references. */ $node->setAttribute('href', call_user_func($this->_params['external_callback'], $val->value)); } } } }
/** * Given a nodelist, read section, subsection and other data * from that node and store it in self * * @access private * @return void * @param DOMNode $node */ private function readNodeConfiguration($node) { if ($node instanceof DOMNode) { if ($node->hasAttribute('cache')) { $this->cache = $node->getAttribute('cache'); } if ($node->hasAttribute('cacheas')) { $this->cacheas = $node->getAttribute('cacheas'); } $nodelist = $node->childNodes; } else { $nodelist = $node; } foreach ($nodelist as $child) { if ($child instanceof DOMText) { continue; } switch ($child->nodeName) { case 'section': $this->section = $child->nodeValue; break; case 'template': if (!isset($this->template)) { $tpl = array(); $tpl['name'] = $child->nodeValue; $this->template = $tpl; } break; case 'module': // Modules can contain options, which we need to take into account $text = ''; $opts = array(); foreach ($child->childNodes as $option) { if ($option->nodeName == '#text') { $text .= $option->nodeValue; } if ($option->nodeName == 'option') { $opts[$option->getAttribute('name')] = $option->nodeValue; } } // Merge options from all scopes together $options = array_merge($this->options, $opts); $module = array(); //$module = array( $module['name'] = trim($text); $module['options'] = $options; $module['_'] = null; if (!isset($cache)) { if ($child->hasAttribute('cache')) { $module['cache'] = $child->getAttribute('cache'); } if ($child->hasAttribute('cacheas')) { $module['cacheas'] = $child->getAttribute('cacheas'); } } /** * A module could provide itself under a fake name * For example AmobilHeader could be provided as * "header", this object would then be usable * elsewhere in the application */ if ($child->hasAttribute('provides')) { $module['provides'] = trim($child->getAttribute('provides')); } $this->modules[] = $module; break; case 'option': $name = $child->getAttribute('name'); // Support additive options $mode = "overwrite"; if ($child->hasAttribute("mode")) { if (array_key_exists($name, $this->options)) { $mode = $child->getAttribute("mode"); $prev = array_map("trim", explode(";", $this->options[$name])); $opts = array_map("trim", explode(";", $child->nodeValue)); } } switch ($mode) { case 'add': /** * If mode is "add", add to ; separated list * and ensure no duplicates are created? */ // Add everything that doesnt create dupes foreach ($opts as $opt) { if (!in_array($opt, $prev)) { $prev[] = $opt; } } $value = implode(";", $prev); break; case 'del': // If mode is "del", delete from ; list $value = implode(";", array_diff($prev, $opts)); break; default: // Simple string/int value $value = trim($child->nodeValue); break; } $this->options[$name] = $value; break; } } }
public static function getAttribute(\DOMNode $node, $attribute) { if (!$node->hasAttribute($attribute)) { throw new MetadataException('Hydratation error.'); } return $node->getAttribute($attribute); }
/** * Process the DOM for this form. * @param DOMNode $node * @param I2CE_Template $template * @param string $method * @param array $args */ public function processDOM(&$node, &$template, $method, $args) { if (!is_callable(array($this, $method))) { I2CE::raiseError("Method {$method} not callable in {$this->getName()}", E_USER_NOTICE); //do nothing return; } if ($node->hasAttribute("ifset")) { $ifset = $node->getAttribute("ifset"); if ($ifset[0] == "!") { $not = true; $ifset = substr($ifset, 1); } else { $not = false; } if (($ifset == "true" || $ifset == "dateblank") && $method == 'displayField') { //we check a field on the current form. the field name is the argument $if_field = $this->getField($args[0]); } else { $phpfunc = '[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*'; if (preg_match("/^({$phpfunc})\$/", $ifset)) { //we are looking at field of this form $if_field = $this->getField($ifset); } else { //we need to check the validity of a field of a different form $if_field = $template->getField($ifset, $node); } } $is_value = true; if ($node->hasAttribute("ifvalue")) { $ifvalue = $node->getAttribute("ifvalue"); if ($ifvalue[0] == "!") { $val_not = true; $ifvalue = substr($ifvalue, 1); } else { $val_not = false; } $is_value = $if_field instanceof I2CE_FormField && $if_field->getDBValue() == $ifvalue; if ($val_not) { $is_value = !$is_value; } } $is_valid = $if_field instanceof I2CE_FormField && $if_field->isValid(); if ($ifset == "dateblank") { $is_valid = $is_valid && $if_field instanceof I2CE_FormField && $if_field->getValue() instanceof I2CE_Date && $if_field->getValue()->isBlank(); } if (!($is_valid xor $not) || !$is_value) { $node->parentNode->removeChild($node); return; } $node->removeAttribute("ifset"); } elseif ($node->hasAttribute("ifvalue")) { $ifvalue = $node->getAttribute("ifvalue"); $if_field = $this->getField($args[0]); if ($ifvalue[0] == "!") { $val_not = true; $ifvalue = substr($ifvalue, 1); } else { $val_not = false; } $is_value = $if_field instanceof I2CE_FormField && $if_field->getDBValue() == $ifvalue; if ($val_not) { $is_value = !$is_value; } if (!$is_value) { $node->parentNode->removeChild($node); return; } else { if ($node->hasAttribute('display') && strlen($display = $node->getAttribute('display')) > 0) { if ($display[0] == 'f' || !$display) { $node->removeAttribute('type'); return; } } } } $this->{$method}($node, $template, $args); }
/** * 匹配节点,由于采取的倒序查找,所以时间复杂度为n+m*l n为总节点数,m为匹配最后一个规则的个数,l为规则的深度, * @codeCoverageIgnore * @param \DOMNode $search * @param array $selectors * @param int $current * @return boolean|\DOMNode */ private function seek($search, $selectors, $current) { if (!$search instanceof \DOMElement) { return false; } list($tag, $key, $val, $exp, $no_key) = $selectors[$current]; $pass = true; if ($tag === '*' && !$key) { exit('tag为*时,key不能为空'); } if ($tag && $tag != $search->tagName && $tag !== '*') { $pass = false; } if ($pass && $key) { if ($no_key) { if ($search->hasAttribute($key)) { $pass = false; } } else { if ($key != "plaintext" && !$search->hasAttribute($key)) { $pass = false; } } } if ($pass && $key && $val && $val !== '*') { if ($key == "plaintext") { $nodeKeyValue = $this->text($search); } else { $nodeKeyValue = $search->getAttribute($key); } $check = $this->match($exp, $val, $nodeKeyValue); if (!$check && strcasecmp($key, 'class') === 0) { foreach (explode(' ', $search->getAttribute($key)) as $k) { if (!empty($k)) { $check = $this->match($exp, $val, $k); if ($check) { break; } } } } if (!$check) { $pass = false; } } if ($pass) { $current--; if ($current < 0) { return $search; } elseif ($this->seek($this->getParent($search), $selectors, $current)) { return $search; } else { return false; } } else { return false; } }
private function addData( DOMNode $node ) { if( $node->hasAttribute( DATA_TYPE_ATTRIBUTE_NAME ) ) { switch( $node->getAttribute( DEPENDENCY_TYPE_ATTRIBUTE_NAME ) ) { case DATA_TYPE_STREAM_VALUE: $url = $this->buildURL( MODULE_STREAM_PATH . $node->nodeValue ); if( $this->url_exists( $url ) ) { $this->xml->load( $url ); } break; case DATA_TYPE_PROCESSOR_VALUE: break; case DATA_TYPE_DYNAMICFILE_VALUE: if ( file_exists( MODULE_FILE_PATH . $node->nodeValue ) ) { ob_start(); $file = MODULE_FILE_PATH . $node->nodeValue; include $file; $this->output .= ob_get_contents(); ob_end_clean(); } break; case DATA_TYPE_STATICFILE_VALUE: if ( file_exists( MODULE_FILE_PATH . $node->nodeValue ) ) { $this->output .= file_get_contents( MODULE_FILE_PATH . $node->nodeValue ); } break; } } }
private function addField(\DOMNode $node) { if (!$node->hasAttribute('name') || !$node->getAttribute('name')) { return; } $nodeName = $node->nodeName; if ('select' == $nodeName || 'input' == $nodeName && 'checkbox' == $node->getAttribute('type')) { $this->set(new Field\ChoiceFormField($node)); } elseif ('input' == $nodeName && 'radio' == $node->getAttribute('type')) { if ($this->has($node->getAttribute('name'))) { $this->get($node->getAttribute('name'))->addChoice($node); } else { $this->set(new Field\ChoiceFormField($node)); } } elseif ('input' == $nodeName && 'file' == $node->getAttribute('type')) { $this->set(new Field\FileFormField($node)); } elseif ('input' == $nodeName && !in_array($node->getAttribute('type'), array('submit', 'button', 'image'))) { $this->set(new Field\InputFormField($node)); } elseif ('textarea' == $nodeName) { $this->set(new Field\TextareaFormField($node)); } }
/** * Determine the size of an image * * @param DOMNode $imgNode The image already parsed as a DOMNode * @param integer $limit Load first $limit KB of remote image * * @return array Return the dimension of the image of the * format array(width, height) */ protected function getImageSize($imgNode, $limit = 32) { // Hold units (assume standard font with 16px base pixel size) // Calculations based on pixels $units = array('px' => 1, 'pt' => 16 / 12, 'pc' => 16, 'in' => 96, 'mm' => 96 / 25.4, 'cm' => 96 / 2.54, 'm' => 96 / 0.0254, 'ex' => 7, 'em' => 16, 'rem' => 16, '%' => 16 / 100); // Initialize dimensions $width = 0; $height = 0; // Determine image dimensions based on "src" atrribute if ($imgNode->hasAttribute('src')) { $src = $imgNode->getAttribute('src'); // Simple check if the URL is internal i.e. check if path exists $path = $_SERVER['DOCUMENT_ROOT'] . $src; if (realpath($path) && is_file($path)) { $size = @getimagesize($path); } else { // The URL is external; try to load it (default: 32 KB) $size = $this->getRemoteImageSize($src, $limit * 1024); } } // Read out width and height from <img> attributes $width = $imgNode->hasAttribute('width') ? $imgNode->getAttribute('width') : $size[0]; $height = $imgNode->hasAttribute('height') ? $imgNode->getAttribute('height') : $size[1]; // Get width and height from style attribute if ($imgNode->hasAttribute('style')) { $style = $imgNode->getAttribute('style'); // Width if (preg_match('~width:\\s*(\\d+)([a-z]+)~i', $style, $matches)) { $width = $matches[1]; // Convert unit to pixel if (isset($units[$matches[2]])) { $width *= $units[$matches[2]]; } } // Height if (preg_match('~height:\\s*(\\d+)([a-z]+)~i', $style, $matches)) { $height = $matches[1]; // Convert unit to pixel if (isset($units[$matches[2]])) { $height *= $units[$matches[2]]; } } } // Update width and height $size[0] = $width; $size[1] = $height; // Return image dimensions return $size; }
/** * Returns option value with associated disabled flag * * @param \DOMNode $node * * @return array */ private function buildOptionValue($node) { $option = array(); $defaultValue = isset($node->nodeValue) && !empty($node->nodeValue) ? $node->nodeValue : '1'; $option['value'] = $node->hasAttribute('value') ? $node->getAttribute('value') : $defaultValue; $option['disabled'] = $node->hasAttribute('disabled') && $node->getAttribute('disabled') == 'disabled'; return $option; }
/** * Check if the current field is disabled * * @return Boolean */ public function isDisabled() { return $this->node->hasAttribute('disabled'); }