private function processFields(XMLElement $xml) { // check if xml has child elements if (($elements = $xml->getChildren()) && is_array($elements)) { // handle elements foreach ($elements as $element_index => $element) { // get element handle $element_handle = $element->getName(); // check if element handle is multilingual if (preg_match('/-([a-z]{2})$/', $element_handle, $match)) { // check if language is supported if (in_array($match[1], self::$languages)) { // remove language segment from element handle $element_handle = preg_replace('/-' . $match[1] . '$/', '', $element_handle); $element_mode = $element->getAttribute('mode'); // set new name and language $element->setName($element_handle); $element->setAttribute('lang', $match[1]); $element->setAttribute('translated', 'yes'); // store element $multilingual_elements[$element_handle . ($element_mode ? ':' . $element_mode : '')][$match[1]] = $element; // remove element $xml->removeChildAt($element_index); } } } // check for stored multilingual elements if (is_array($multilingual_elements)) { // handle multilingual elements foreach ($multilingual_elements as $element_handle => $element) { // handle languages foreach (self::$languages as $language) { // check if element exists for each language if (!isset($element[$language]) || !(str_replace('<![CDATA[]]>', '', trim($element[$language]->getValue())) || $element[$language]->getNumberOfChildren())) { // fallback to default language if missing or empty if (isset($element[self::$languages[0]])) { $element[$language] = clone $element[self::$languages[0]]; $element[$language]->setAttribute('lang', $language); $element[$language]->setAttribute('translated', 'no'); } } } // readd elements $xml->appendChildArray($element); } } } return $xml; }
private function getChildrenWithClass(XMLElement &$rootElement, $className, $tagName = null) { if ($rootElement == null) { return null; } // contains the right css class and the right node name (if any) // TODO: Use word bondaries instead of strpos if ((!$className || strpos($rootElement->getAttribute('class'), $className) > -1) && (!$tagName || $rootElement->getName() == $tagName)) { return $rootElement; } // recursive search in child elements foreach ($rootElement->getChildren() as $key => $child) { if (!$child instanceof XMLElement) { continue; } $res = $this->getChildrenWithClass($child, $className, $tagName); if ($res != null) { return $res; } } return null; }