Beispiel #1
0
 /**
  * Removes all attributes from element.
  *
  * @param DOMElement $element
  *   The DOMElement to remove attributes from.
  */
 protected function removeAttributes($element)
 {
     $attributes = $element->attributes;
     while ($attributes->length) {
         $element->removeAttribute($attributes->item(0)->name);
     }
 }
Beispiel #2
0
 protected function postProcessDomNode($field, DOMElement $fieldNode, JForm $form)
 {
     $fieldNode->setAttribute('validate', 'url');
     if (!$fieldNode->getAttribute('relative')) {
         $fieldNode->removeAttribute('relative');
     }
     return parent::postProcessDomNode($field, $fieldNode, $form);
 }
 /**
  * Usuń atrybut
  * 
  * @param string $name
  * 
  * @return HtmlElement
  * 
  * @throws \UnexpectedValueException
  */
 public function removeAttr($name)
 {
     if (!is_string($name)) {
         throw new \UnexpectedValueException('attribute name is not string');
     }
     $this->element->removeAttribute($name);
     return $this;
 }
 /**
  * Removes class $class from $element
  *
  * @param DOMElement $element
  * @param string     $class
  */
 public function removeClass($element, $class)
 {
     $newClass = trim(preg_replace("/ *(?:{$class})/i", '', $element->getAttribute('class')));
     if ($newClass != '') {
         $element->setAttribute('class', $newClass);
     } else {
         $element->removeAttribute('class');
     }
 }
Beispiel #5
0
 /**
  * Required by the ArrayAccess interface.
  *
  * @param  string $offset
  * @return boolean
  */
 public function offsetUnset($offset)
 {
     if (strpos($offset, ':') !== false) {
         list($ns, $attr) = explode(':', $offset, 2);
         return $this->_element->removeAttributeNS(Zend_Feed::lookupNamespace($ns), $attr);
     } else {
         return $this->_element->removeAttribute($offset);
     }
 }
Beispiel #6
0
 /**
  * Required by the ArrayAccess interface.
  *
  * @internal
  */
 public function offsetUnset($offset)
 {
     if (strpos($offset, ':') !== false) {
         list($ns, $attr) = explode(':', $offset, 2);
         $result = $this->_element->removeAttributeNS(Horde_Xml_Element::lookupNamespace($ns), $attr);
     } else {
         $result = $this->_element->removeAttribute($offset);
     }
     if ($result) {
         $this->_expireCachedChildren();
         return true;
     } else {
         return false;
     }
 }
Beispiel #7
0
 /**
  * Parses a route and adds it to the RouteCollection.
  *
  * @param RouteCollection $collection RouteCollection instance
  * @param \DOMElement     $node       Element to parse that represents a Route
  * @param string          $path       Full path of the XML file being processed
  *
  * @throws \InvalidArgumentException When the XML is invalid
  */
 protected function parseRoute(RouteCollection $collection, \DOMElement $node, $path)
 {
     if ('' === ($id = $node->getAttribute('id')) || !$node->hasAttribute('pattern') && !$node->hasAttribute('path')) {
         throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must have an "id" and a "path" attribute.', $path));
     }
     if ($node->hasAttribute('pattern')) {
         if ($node->hasAttribute('path')) {
             throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" cannot define both a "path" and a "pattern" attribute. Use only "path".', $path));
         }
         $node->setAttribute('path', $node->getAttribute('pattern'));
         $node->removeAttribute('pattern');
     }
     $schemes = preg_split('/[\\s,\\|]++/', $node->getAttribute('schemes'), -1, PREG_SPLIT_NO_EMPTY);
     $methods = preg_split('/[\\s,\\|]++/', $node->getAttribute('methods'), -1, PREG_SPLIT_NO_EMPTY);
     list($defaults, $requirements, $options) = $this->parseConfigs($node, $path);
     $route = new Route($node->getAttribute('path'), $defaults, $requirements, $options, $node->getAttribute('host'), $schemes, $methods);
     $collection->add($id, $route);
 }
Beispiel #8
0
 private function archiveGrp(Application $app, \databox $databox, \DOMDocument $dom, \DOMElement $node, $path, $path_archived, $path_error, array &$nodesToDel, $moveError, $moveArchived, $stat0, $stat1)
 {
     $xpath = new \DOMXPath($dom);
     // grp folders stay in place
     $node->setAttribute('keep', '1');
     $grpFolder = $node->getAttribute('name');
     $groupingFile = $path . '/' . $grpFolder . '/.grouping.xml';
     if ($node->getAttribute('grp') == 'tocreate') {
         $representationFileName = null;
         $representationFileNode = null;
         $captionFileName = null;
         $captionFileNode = null;
         $cid = $node->getAttribute('cid');
         $genericdoc = null;
         $this->log('debug', sprintf('created story \'%s\'', $path . '/' . $grpFolder));
         // if the .grp does not have a representative doc, let's use a generic file
         if (!($rep = $node->getAttribute('grp_representation'))) {
             try {
                 $app['filesystem']->copy($app['root.path'] . '/www/assets/common/images/icons/substitution/regroup_doc.png', $genericdoc = $path . '/group.jpg', true);
             } catch (IOException $e) {
                 $this->log('debug', $e->getMessage());
             }
             $representationFileName = 'group.jpg';
             $this->log('debug', ' (no representation file)');
         } else {
             $dnl = $xpath->query('./file[@name="' . $rep . '"]', $node->parentNode);
             $representationFileNode = $dnl->item(0);
             $representationFileName = $rep;
             $node->removeAttribute('grp_representation');
             $this->log('debug', sprintf('representation from \'%s\'', $representationFileName));
         }
         if (($cap = $node->getAttribute('grp_caption')) != '') {
             $dnl = $xpath->query('./file[@name="' . $cap . '"]', $node->parentNode);
             $captionFileNode = $dnl->item(0);
             $captionFileName = $cap;
             $node->removeAttribute('grp_caption');
             $this->log('debug', sprintf('caption from \'%s\'', $captionFileName));
         }
         try {
             $collection = \collection::get_from_coll_id($app, $databox, (int) $cid);
             if ($captionFileName === null) {
                 $story = $this->createStory($app, $collection, $path . '/' . $representationFileName, null, $stat0, $stat1);
             } else {
                 $story = $this->createStory($app, $collection, $path . '/' . $representationFileName, $path . '/' . $captionFileName, $stat0, $stat1);
             }
             $rid = $story->get_record_id();
             $this->log('debug', sprintf('story %s created', $rid));
             if ($genericdoc) {
                 try {
                     $app['filesystem']->remove($genericdoc);
                 } catch (IOException $e) {
                     $this->log('debug', $e->getMessage());
                 }
             }
             file_put_contents($groupingFile, '<?xml version="1.0" encoding="ISO-8859-1" ?><record grouping="' . $rid . '" />');
             $n = $node->appendChild($dom->createElement('file'));
             $n->setAttribute('name', '.grouping.xml');
             $n->setAttribute('temperature', 'cold');
             $n->setAttribute('grp', '1');
             $n->setAttribute('match', '*');
             if ($moveArchived) {
                 $this->log('debug', sprintf('copy \'%s\' to \'archived\'', $path . '/' . $grpFolder . '/.grouping.xml'));
                 try {
                     $app['filesystem']->mkdir($path_archived . '/' . $grpFolder, 0755);
                 } catch (IOException $e) {
                     $this->log('debug', $e->getMessage());
                 }
                 try {
                     $app['filesystem']->copy($path . '/' . $grpFolder . '/.grouping.xml', $path_archived . '/' . $grpFolder . '/.grouping.xml', true);
                 } catch (IOException $e) {
                     $this->log('debug', $e->getMessage());
                 }
             }
             if ($captionFileNode) {
                 $captionFileNode->setAttribute('archived', '1');
                 if ($moveArchived) {
                     $this->log('debug', sprintf('copy \'%s\' to \'archived\'', $path . '/' . $captionFileName));
                     try {
                         $app['filesystem']->mkdir($path_archived, 0755);
                     } catch (IOException $e) {
                         $this->log('debug', $e->getMessage());
                     }
                     try {
                         $app['filesystem']->copy($path . '/' . $captionFileName, $path_archived . '/' . $captionFileName, true);
                     } catch (IOException $e) {
                         $this->log('debug', $e->getMessage());
                     }
                 }
                 try {
                     $app['filesystem']->remove($path . '/' . $captionFileName);
                 } catch (IOException $e) {
                     $this->log('debug', $e->getMessage());
                 }
                 $nodesToDel[] = $captionFileNode;
             }
             if ($representationFileNode) {
                 $representationFileNode->setAttribute('archived', '1');
                 if ($moveArchived) {
                     $this->log('debug', sprintf('copy \'%s\' to \'archived\'', $path . '/' . $representationFileName));
                     try {
                         $app['filesystem']->mkdir($path_archived, 0755);
                     } catch (IOException $e) {
                         $this->log('debug', $e->getMessage());
                     }
                     try {
                         $app['filesystem']->copy($path . '/' . $representationFileName, $path_archived . '/' . $representationFileName, true);
                     } catch (IOException $e) {
                         $this->log('debug', $e->getMessage());
                     }
                 }
                 try {
                     $app['filesystem']->remove($path . '/' . $representationFileName);
                 } catch (IOException $e) {
                     $this->log('debug', $e->getMessage());
                 }
                 $nodesToDel[] = $representationFileNode;
             }
             $node->setAttribute('grp', 'tocomplete');
         } catch (\Exception $e) {
             $this->log('debug', $e->getMessage());
         }
     }
     // here the .grouping.xml should exists
     if ($app['filesystem']->exists($groupingFile)) {
         // a .grouping.xml must stay in place
         // -- don't do, done in phase4
         $sxGrouping = @simplexml_load_file($groupingFile);
         $grp_rid = $sxGrouping['grouping'];
         $this->archiveFilesToGrp($app, $databox, $dom, $node, $path . '/' . $grpFolder, $path_archived . '/' . $grpFolder, $path_error . '/' . $grpFolder, $grp_rid, $stat0, $stat1, $moveError, $moveArchived);
     }
     return;
 }
Beispiel #9
0
 /**
  * Renders given DOM element as subtemplate.
  *
  * @param \DOMElement $domElement DOM element to subrender.
  * @param Scope $scope Subtemplate Scope object.
  * @return string Rendered HTML.
  */
 protected function subcompile(\DOMElement $domElement, $scope)
 {
     $template = new Template($this->phCompile);
     /**
      * Remove ng-repeat attribute so we won't fall into infinite loop while parsing.
      */
     $domElement->removeAttribute('ng-repeat');
     /**
      * Tag element with render class, for easy client-side JavaScript manipulation.
      */
     Utils::addClass($domElement, $this->phCompile->getConfig('compile.class'));
     $template->setHTML($domElement->ownerDocument->saveHTML($domElement));
     $template->setScope($scope);
     return $template->compile();
 }
 /**
  * Replaces an element reference with a copy of the element it references.
  * @param DOMElement $elementReference the element reference to replace
  * @param DOMXPath $xpath the xpath object representing the DOM
  * @access private
  */
 private function ReplaceElementReference(DOMElement $elementReference, DOMXPath $xpath)
 {
     $href = $elementReference->getAttribute('href');
     if (version_compare(PHP_VERSION, '5.2.2', '>=') && version_compare(PHP_VERSION, '5.2.4', '<')) {
         // These versions have a bug where href is generated without the # symbol.
         $href = '#' . $href;
     }
     $id = substr($href, 1);
     $referencedElements = $xpath->query('//*[@id="' . $id . '"]');
     if ($referencedElements->length > 0) {
         $referencedElement = $referencedElements->item(0);
         for ($i = 0; $i < $referencedElement->childNodes->length; $i++) {
             $childNode = $referencedElement->childNodes->item($i);
             $elementReference->appendChild($childNode->cloneNode(true));
         }
         $elementReference->removeAttribute('href');
     }
 }
Beispiel #11
0
 /**
  * Clean all atttributes but allowed
  * @param \DOMElement|\DOMNode $node
  * @param array $attributes
  */
 private function cleanAttributes(&$node, $attributes = [])
 {
     if (($node instanceof \DOMElement or $node instanceof \DOMNode) and $node->attributes->length) {
         $delAttr = [];
         foreach ($node->attributes as $attr) {
             if (isset($attributes[$attr->name])) {
                 $filter = $attributes[$attr->name];
                 $node->setAttribute($attr->name, $this->{$filter}($attr->value));
             } elseif (isset($this->allowedAttrsForAll[$attr->name])) {
                 $filter = $this->allowedAttrsForAll[$attr->name];
                 $node->setAttribute($attr->name, $this->{$filter}($attr->value));
             } else {
                 $delAttr[] = $attr->name;
             }
         }
         foreach ($delAttr as $da) {
             $node->removeAttribute($da);
         }
     }
 }
 /**
  * Replaces an element reference with a copy of the element it references.
  *
  * @param \DOMElement $elementReference the element reference to replace
  * @param \DOMXPath   $xpath the xpath object representing the DOM
  */
 private function ReplaceElementReference(\DOMElement $elementReference, \DOMXPath $xpath)
 {
     $href = $elementReference->getAttribute('href');
     $id = substr($href, 1);
     $referencedElements = $xpath->query('//*[@id="' . $id . '"]');
     if ($referencedElements->length > 0) {
         $referencedElement = $referencedElements->item(0);
         for ($i = 0; $i < $referencedElement->childNodes->length; $i++) {
             $childNode = $referencedElement->childNodes->item($i);
             $elementReference->appendChild($childNode->cloneNode(true));
         }
         $elementReference->removeAttribute('href');
     }
 }
Beispiel #13
0
 /**
  * publishHandlerEmbed (Publish handler, pass 2 after schema validation)
  * Publish handler for embed element, convert id to [object|node]_id parameter,
  * fixes align=middle value (if embed was image) and tries to map css to attributes
  *
  * @param DOMElement $element
  * @param array $param parameters for xml element
  * @return null|array changes structure if it contains 'result' key
  */
 function publishHandlerEmbed($element, &$params)
 {
     $ID = $element->getAttribute('id');
     if ($ID) {
         $objectID = false;
         $element->removeAttribute('id');
         if (strpos($ID, 'eZObject_') !== false) {
             $objectID = substr($ID, strpos($ID, '_') + 1);
             $element->setAttribute('object_id', $objectID);
             $object = eZContentObject::fetch($objectID);
             if (!$object) {
                 if (!in_array($objectID, $this->deletedEmbeddedObjectIDArray)) {
                     $this->deletedEmbeddedObjectIDArray[] = $objectID;
                 }
             } else {
                 if ($object->attribute('status') == eZContentObject::STATUS_ARCHIVED) {
                     $this->thrashedEmbeddedObjectIDArray[] = $objectID;
                 }
             }
         } else {
             if (strpos($ID, 'eZNode_') !== false) {
                 $nodeID = substr($ID, strpos($ID, '_') + 1);
                 $element->setAttribute('node_id', $nodeID);
                 $node = eZContentObjectTreeNode::fetch($nodeID);
                 if ($node) {
                     $objectID = $node->attribute('contentobject_id');
                 } else {
                     if (!in_array($nodeID, $this->deletedEmbeddedNodeIDArray)) {
                         $this->deletedEmbeddedNodeIDArray[] = $nodeID;
                     }
                 }
             }
         }
         if ($objectID && !in_array($objectID, $this->embeddedObjectIDArray)) {
             $this->embeddedObjectIDArray[] = $objectID;
         }
     }
     $align = $element->getAttribute('align');
     if ($align && $align === 'middle') {
         $element->setAttribute('align', 'center');
     }
     return null;
 }
Beispiel #14
0
 /**
  * Parses a route and adds it to the RouteCollection.
  *
  * @param RouteCollection $collection RouteCollection instance
  * @param \DOMElement     $node       Element to parse that represents a Route
  * @param string          $path       Full path of the XML file being processed
  *
  * @throws \InvalidArgumentException When the XML is invalid
  */
 protected function parseRoute(RouteCollection $collection, \DOMElement $node, $path)
 {
     if ('' === ($id = $node->getAttribute('id')) || !$node->hasAttribute('pattern') && !$node->hasAttribute('path')) {
         throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" must have an "id" and a "path" attribute.', $path));
     }
     if ($node->hasAttribute('pattern')) {
         if ($node->hasAttribute('path')) {
             throw new \InvalidArgumentException(sprintf('The <route> element in file "%s" cannot define both a "path" and a "pattern" attribute. Use only "path".', $path));
         }
         @trigger_error(sprintf('The "pattern" option in file "%s" is deprecated since version 2.2 and will be removed in 3.0. Use the "path" option in the route definition instead.', $path), E_USER_DEPRECATED);
         $node->setAttribute('path', $node->getAttribute('pattern'));
         $node->removeAttribute('pattern');
     }
     $schemes = preg_split('/[\\s,\\|]++/', $node->getAttribute('schemes'), -1, PREG_SPLIT_NO_EMPTY);
     $methods = preg_split('/[\\s,\\|]++/', $node->getAttribute('methods'), -1, PREG_SPLIT_NO_EMPTY);
     list($defaults, $requirements, $options, $condition) = $this->parseConfigs($node, $path);
     if (isset($requirements['_method'])) {
         if (0 === count($methods)) {
             $methods = explode('|', $requirements['_method']);
         }
         unset($requirements['_method']);
         @trigger_error(sprintf('The "_method" requirement of route "%s" in file "%s" is deprecated since version 2.2 and will be removed in 3.0. Use the "methods" attribute instead.', $id, $path), E_USER_DEPRECATED);
     }
     if (isset($requirements['_scheme'])) {
         if (0 === count($schemes)) {
             $schemes = explode('|', $requirements['_scheme']);
         }
         unset($requirements['_scheme']);
         @trigger_error(sprintf('The "_scheme" requirement of route "%s" in file "%s" is deprecated since version 2.2 and will be removed in 3.0. Use the "schemes" attribute instead.', $id, $path), E_USER_DEPRECATED);
     }
     $route = new Route($node->getAttribute('path'), $defaults, $requirements, $options, $node->getAttribute('host'), $schemes, $methods, $condition);
     $collection->add($id, $route);
 }
Beispiel #15
0
 /**
  * Set an attribute on an element
  *
  * @param string $name
  * @return bool
  */
 public function removeAttribute($name)
 {
     list($namespace, $localName) = $this->resolveTagName($name);
     if ($namespace != '') {
         return parent::removeAttributeNS($namespace, $localName);
     } else {
         return parent::removeAttribute($name);
     }
 }
 /**
  * {@inheritDoc}
  */
 protected function parseRoute(RouteCollection $collection, \DOMElement $node, $path)
 {
     // the Symfony Routing component uses a path attribute since Symfony 2.2
     // instead of the deprecated pattern attribute0
     if (!$node->hasAttribute('path')) {
         $node->setAttribute('path', $node->getAttribute('pattern'));
         $node->removeAttribute('pattern');
     }
     if ($this->includeFormat) {
         $path = $node->getAttribute('path');
         // append format placeholder if not present
         if (false === strpos($path, '{_format}')) {
             $node->setAttribute('path', $path . '.{_format}');
         }
         // set format requirement if configured globally
         $requirements = $node->getElementsByTagNameNS(self::NAMESPACE_URI, 'requirement');
         $format = null;
         for ($i = 0; $i < $requirements->length; $i++) {
             $item = $requirements->item($i);
             if ($item instanceof \DOMElement && $item->hasAttribute('_format')) {
                 $format = $item->getAttribute('_format');
                 break;
             }
         }
         if (null === $format && !empty($this->formats)) {
             $requirement = $node->ownerDocument->createElementNs(self::NAMESPACE_URI, 'requirement', implode('|', array_keys($this->formats)));
             $requirement->setAttribute('key', '_format');
             $node->appendChild($requirement);
         }
     }
     // set the default format if configured
     if (null !== $this->defaultFormat) {
         $defaultFormatNode = $node->ownerDocument->createElementNS(self::NAMESPACE_URI, 'default', $this->defaultFormat);
         $defaultFormatNode->setAttribute('key', '_format');
         $node->appendChild($defaultFormatNode);
     }
     $options = $this->getOptions($node);
     foreach ($options as $option) {
         $node->appendChild($option);
     }
     $length = $node->childNodes->length;
     for ($i = 0; $i < $length; $i++) {
         $loopNode = $node->childNodes->item($i);
         if ($loopNode->nodeType == XML_TEXT_NODE) {
             continue;
         }
         $newNode = $node->ownerDocument->createElementNS(self::NAMESPACE_URI, $loopNode->nodeName, $loopNode->nodeValue);
         foreach ($loopNode->attributes as $value) {
             $newNode->setAttribute($value->name, $value->value);
         }
         $node->appendChild($newNode);
     }
     parent::parseRoute($collection, $node, $path);
 }
Beispiel #17
0
 function it_removes_node_attribute(\DOMElement $element)
 {
     $element->removeAttribute('name')->shouldBeCalled();
     $this->removeAttribute('name');
 }
Beispiel #18
0
 function filterHtmlCleanChild(DOMElement $p, $removeTag, $removeAttr)
 {
     if ($p->hasChildNodes()) {
         foreach ($p->childNodes as $c) {
             // on delete ce fils
             if (in_array($c->nodeName, $removeTag)) {
                 $p->removeChild($c);
             } elseif ($c->nodeType == XML_ELEMENT_NODE) {
                 filterHtmlCleanChild($c, $removeTag, $removeAttr);
             }
         }
     }
     foreach ($removeAttr as $ra) {
         $p->removeAttribute($ra);
         /** 		 	test
                  if ( $ra == 'onkeydown' ) {
                  if ( $va = $p->getAttribute('onkeydown') ) {
                  $p->removeAttribute($ra);
                  $rgx = '#*media\{id:([0-9]*)\}*#';
                  preg_match($rgx, $va, $m);
                  $r = array();
                  if ( isset($m[1]) ) { $p->setAttribute($ra,"media{id:".$m[1]."}"); }
                  }
                 */
     }
     return $p;
 }
Beispiel #19
0
 /**
  * Builds/Rebuilds the project xml document.
  *
  * @return void
  * @throws ErrorException If one of the artifact publisher fail.
  */
 public function buildXml()
 {
     // Skip if this project is not dirty
     if ($this->state !== self::STATE_DIRTY) {
         return;
     }
     $this->scheduleElement->setAttribute('interval', $this->interval);
     if (!($this->anthome == null)) {
         $this->toolElement->setAttribute('anthome', $this->anthome);
     }
     if (!($this->antscript === null)) {
         $this->toolElement->removeAttribute('anthome');
         $this->toolElement->setAttribute('antscript', $this->antscript);
     } elseif (!strstr(dirname($this->configFile->documentURI), $this->anthome)) {
         $schedules = $this->element->getElementsByTagName('schedule');
         $tools = $schedules->item(0)->getElementsByTagName('ant');
         $i = $tools->length - 1;
         while ($i > -1) {
             $antTool = $tools->item($i);
             $this->replaceAntTool($antTool);
             $i--;
         }
     }
     foreach ($this->publishers as $publisher) {
         $publisher->buildXml();
     }
     foreach ($this->bootStrappers as $bootStrapper) {
         $bootStrapper->buildXml();
     }
     foreach ($this->buildTriggers as $buildTrigger) {
         $buildTrigger->buildXml();
     }
     $this->state = self::STATE_CLEAN;
 }
Beispiel #20
0
 /**
  * @param string $name
  *
  * @return void
  */
 public function removeAttribute($name)
 {
     $this->domElement->removeAttribute($name);
 }
 private function cleanNode2(DOMElement $node)
 {
     // проверка допустимых свойств
     $j = 0;
     $checkAttribute = array_key_exists($node->nodeName, $this->allowedAttributes);
     while ($j < $node->attributes->length) {
         $attribute = $node->attributes->item($j);
         if ((!$checkAttribute || !in_array($attribute->name, $this->allowedAttributes[$node->nodeName])) && !in_array($attribute->name, $this->allowedAttributes['*'])) {
             $node->removeAttribute($attribute->name);
             $j--;
         }
         if ($attribute->name == 'href' || $attribute->name == 'src') {
             // что-то мне регуляярка эта не нравится
             if (preg_match('/^\\s*javascript\\s*:/', $attribute->value)) {
                 $node->removeAttribute($attribute->name);
                 $j--;
             }
         }
         $j++;
     }
     // проверка допустимых нод
     $i = 0;
     while ($i < $node->childNodes->length) {
         $child = $node->childNodes->item($i);
         if ($child instanceof DOMElement) {
             if (in_array($child->nodeName, $this->allowedTags)) {
                 $this->cleanNode2($child);
             } else {
                 var_dump($child->nodeName);
                 //копируем содержимое запрещённой ноды
                 foreach ($child->childNodes as $childChild) {
                     $node->insertBefore($childChild->cloneNode(true), $child);
                 }
                 // и удаляем её
                 $node->removeChild($child);
                 $i--;
                 $i--;
             }
         } elseif ($child instanceof DOMText) {
             // проверяем текстовые ноды на наличие '\n', заменяем '\n' на '<br>'
             $text = $child->nodeValue;
             $pieces = preg_split('/\\n/', $text);
             if (count($pieces) > 1) {
                 for ($j = 0; $j < count($pieces); $j++) {
                     $pieceTextNode = $node->ownerDocument->createTextNode($pieces[$j]);
                     $node->insertBefore($pieceTextNode, $child);
                     $i++;
                     if ($j + 1 < count($pieces)) {
                         $node->insertBefore($node->ownerDocument->createElement('br'), $child);
                         $i++;
                         /*$node->insertBefore($node->ownerDocument->createElement('br'), $child);
                           $i++;*/
                     }
                 }
                 $node->removeChild($child);
                 $i--;
             }
         }
         $i++;
     }
 }
Beispiel #22
0
 /**
  * Filter attributes on an element by name and value according to a whitelist.
  *
  * @param \DOMElement $element
  *   The element to be processed.
  * @param array $allowed_attributes
  *   The attributes whitelist as an array of names and values.
  */
 protected function filterElementAttributes(\DOMElement $element, array $allowed_attributes)
 {
     $modified_attributes = [];
     foreach ($element->attributes as $name => $attribute) {
         // Remove attributes not in the whitelist.
         $allowed_value = $this->findAllowedValue($allowed_attributes, $name);
         if (empty($allowed_value)) {
             $modified_attributes[$name] = FALSE;
         } elseif ($allowed_value !== TRUE) {
             // Check the attribute values whitelist.
             $attribute_values = preg_split('/\\s+/', $attribute->value, -1, PREG_SPLIT_NO_EMPTY);
             $modified_attributes[$name] = [];
             foreach ($attribute_values as $value) {
                 if ($this->findAllowedValue($allowed_value, $value)) {
                     $modified_attributes[$name][] = $value;
                 }
             }
         }
     }
     // If the $allowed_value was TRUE for an attribute name, it does not
     // appear in this array so the value on the DOM element is left unchanged.
     foreach ($modified_attributes as $name => $values) {
         if ($values) {
             $element->setAttribute($name, implode(' ', $values));
         } else {
             $element->removeAttribute($name);
         }
     }
 }
Beispiel #23
0
 /**
  * Remove node's attribute
  *
  * @param string $name
  * @return boolean
  */
 public function removeAttribute($name)
 {
     return $this->element->removeAttribute($name);
 }
 /**
  * Sets the list of classes.
  *
  * @param DOMElement $element DOM element
  * @param array      $classes List of classes
  *
  * @return void
  */
 private function _setClassMap($element, $classes)
 {
     $element->removeAttribute("class");
     if (count($classes) > 0) {
         $element->setAttribute("class", implode(" ", $classes));
     }
 }
 /**
  * removes all children of element except of key elements, which has to remain
  *
  * @param      \DOMElement  $domNode
  * @param      \DOMNodeList $domNodeChildren
  * @param bool              $leaveKey
  * @param bool              $recursive
  *
  * @return int  number of key elements, that remains
  */
 public function removeChildrenExceptOfKeyElements($domNode, $domNodeChildren, $leaveKey = false, $recursive = false)
 {
     $keyElemIndex = $keyElemsCnt = 0;
     while ($domNodeChildren->length > $keyElemIndex) {
         $isKey = $isCreated = false;
         $child = $domNodeChildren->item($keyElemIndex);
         if ($child->hasAttributes()) {
             foreach ($child->attributes as $attr) {
                 if ($attr->nodeName == "iskey" && $attr->nodeValue == "true") {
                     if ($child->hasAttributes()) {
                         foreach ($child->attributes as $attr) {
                             if ($attr->nodeName !== 'xc:operation') {
                                 $attributesArr[] = $attr->nodeName;
                             }
                         }
                         // remove must be in new foreach, previous deletes only first one
                         foreach ($attributesArr as $attrName) {
                             $child->removeAttribute($attrName);
                         }
                     }
                     if ($leaveKey == true) {
                         $keyElemIndex++;
                         $isKey = true;
                     } else {
                         if (isset($child)) {
                             $nodeName = $child->nodeName;
                             $nodeValue = $child->nodeValue;
                             $domNode->setAttribute("GUIcustom_" . $nodeName, $nodeValue);
                         }
                     }
                     $keyElemsCnt++;
                 } elseif ($attr->nodeName == "xc:operation" && $attr->nodeValue == "create") {
                     $keyElemIndex++;
                     $isCreated = true;
                 }
             }
         }
         if (!$isKey && !$isCreated || $leaveKey == false) {
             try {
                 $childrenRemains = 0;
                 // recursively check all children for their key elements
                 if (sizeof($child->childNodes) && $recursive) {
                     foreach ($child->childNodes as $chnode) {
                         if (sizeof($chnode->childNodes)) {
                             $childrenRemains += $this->removeChildrenExceptOfKeyElements($chnode, $chnode->childNodes, $leaveKey, $recursive);
                         }
                     }
                 }
                 if ($childrenRemains == 0) {
                     $domNode->removeChild($child);
                 } else {
                     $keyElemIndex++;
                 }
             } catch (\DOMException $e) {
             }
         }
     }
     if ($domNode->hasAttributes()) {
         foreach ($domNode->attributes as $attr) {
             if (strpos($attr->nodeName, "GUIcustom_") !== 0) {
                 $attributesArr[] = $attr->nodeName;
             }
         }
         // remove must be in new foreach, previous deletes only first one
         foreach ($attributesArr as $attrName) {
             $domNode->removeAttribute($attrName);
         }
     }
     return $keyElemsCnt;
 }
Beispiel #26
0
 /**
  * Clean the hrefs of script and data embeds
  *
  * @param \DOMElement $element
  */
 protected function cleanHrefs(\DOMElement &$element)
 {
     $href = $element->getAttribute('href');
     if (preg_match(self::SCRIPT_REGEX, $href) === 1) {
         $element->removeAttribute('href');
     }
 }
 /**
  * {@inheritDoc}
  */
 protected function parseRoute(RouteCollection $collection, \DOMElement $node, $path)
 {
     // the Symfony Routing component uses a path attribute since Symfony 2.2
     // instead of the deprecated pattern attribute0
     if (!$node->hasAttribute('path')) {
         $node->setAttribute('path', $node->getAttribute('pattern'));
         $node->removeAttribute('pattern');
     }
     if ($this->includeFormat) {
         $path = $node->getAttribute('path');
         // append format placeholder if not present
         if (false === strpos($path, '{_format}')) {
             $node->setAttribute('path', $path . '.{_format}');
         }
         // set format requirement if configured globally
         $requirements = $node->getElementsByTagNameNS(self::NAMESPACE_URI, 'requirement');
         $format = null;
         for ($i = 0; $i < $requirements->length; $i++) {
             $item = $requirements->item($i);
             if ($item instanceof \DOMElement && $item->hasAttribute('_format')) {
                 $format = $item->getAttribute('_format');
                 break;
             }
         }
         if (null === $format && !empty($this->formats)) {
             $requirement = $node->ownerDocument->createElementNs(self::NAMESPACE_URI, 'requirement', implode('|', array_keys($this->formats)));
             $requirement->setAttribute('key', '_format');
             $node->appendChild($requirement);
             /*$doc =new \DOMDocument();
               $doc->appendChild($doc->importNode($node, true));
               echo $doc->saveHTML();*/
         }
     }
     // set the default format if configured
     if (null !== $this->defaultFormat) {
         $config['defaults']['_format'] = $this->defaultFormat;
         $defaultFormatNode = $node->ownerDocument->createElementNS(self::NAMESPACE_URI, 'default', $this->defaultFormat);
         $defaultFormatNode->setAttribute('key', '_format');
         $node->appendChild($defaultFormatNode);
     }
     parent::parseRoute($collection, $node, $path);
 }
Beispiel #28
0
 /**
  * Remove a data attribute from the attached node.
  *
  * @param string $name
  */
 public function __unset($name)
 {
     $this->_node->removeAttribute($this->encodeName($name));
 }
 private function removeElementAttributes(\DOMElement $node, array $attributes = [])
 {
     foreach ($attributes as $attribute) {
         $node->removeAttribute($attribute);
     }
 }