Example #1
0
 /**
  * @param callable $rowParseCallback
  * @param callable $cellParseCallback
  * @return void
  */
 public function createMap(\Closure $rowParseCallback = null, \Closure $cellParseCallback = null)
 {
     // First, dos ome basic cleanup
     $this->cleanupTable();
     // Then, get all rows and parse!
     $trs = $this->table->getElementsByTagName('tr');
     if ($trs instanceof \DOMNodeList && $trs->length > 0) {
         for ($tri = 0, $rowGroupi = 0; $tri < $trs->length; $rowGroupi++) {
             /** @var \DOMElement $tr */
             $tr = $trs->item($tri);
             $this->rowOffsets[$rowGroupi] = array('firstRow' => $tri);
             $this->rowCellMap[$rowGroupi] = array();
             $this->rowGroups[$rowGroupi] = array();
             $rowSpan = 1;
             foreach ($tr->childNodes as $child) {
                 /** @var $child \DOMElement */
                 if ($child->hasAttribute('rowspan') && (int) $child->getAttribute('rowspan') > $rowSpan) {
                     $rowSpan = (int) $child->getAttribute('rowspan');
                 }
             }
             $this->parseRowGroup($this->rowCellMap[$rowGroupi], $this->rowGroups[$rowGroupi], $rowSpan, $tr, $rowParseCallback, $cellParseCallback);
             $tri += $rowSpan;
             $this->rowOffsets[$rowGroupi]['lastRow'] = $tri > 0 ? $tri - 1 : $tri;
         }
     }
 }
 /**
  * Creates a new CqOption.
  *
  * @param DOMElement $node
  *   containing the option definition
  * @param CqQuestionInterface $context
  *   CqQuestionInterface The question or other object that the mapping can query for
  *   things like the current answer, draggables, hotspots and the parsing of
  *   html.
  */
 public function __construct(DOMElement $node, $context)
 {
     foreach ($node->getElementsByTagName('choice') as $choice) {
         $this->text .= cq_get_text_content($choice, $context);
     }
     foreach ($node->getElementsByTagName('description') as $description) {
         $this->description .= cq_get_text_content($description, $context);
     }
     foreach ($node->getElementsByTagName('feedback') as $fb) {
         $this->feedback[] = CqFeedback::newCqFeedback($fb, $context);
     }
     foreach ($node->getElementsByTagName('feedbackunselected') as $fb) {
         $this->feedbackUnselected[] = CqFeedback::newCqFeedback($fb, $context);
     }
     $attribs = $node->attributes;
     $item = $attribs->getNamedItem('correct');
     if ($item !== NULL) {
         $this->correct = (int) $item->value;
     }
     $item = $attribs->getNamedItem('identifier');
     if ($item === NULL) {
         $item = $attribs->getNamedItem('id');
     }
     if ($item === NULL) {
         $item = $attribs->getNamedItem('name');
     }
     if ($item !== NULL) {
         $this->identifier = $item->nodeValue;
     }
 }
Example #3
0
 /**
  * getValue
  * @param DOMElement $node
  * @param string $name
  * @return string
  */
 public function getValue($node, $name)
 {
     if (empty($node)) {
         return '';
     }
     $texto = !empty($node->getElementsByTagName($name)->item(0)->nodeValue) ? $node->getElementsByTagName($name)->item(0)->nodeValue : '';
     return html_entity_decode($texto, ENT_QUOTES, 'UTF-8');
 }
 private function getOptionalField($fieldName, $attributeName = null)
 {
     $value = '';
     $tag = $this->currentVideo->getElementsByTagName($fieldName);
     if ($tag->length) {
         $value = is_null($attributeName) ? $tag->item(0)->textContent : $tag->item(0)->getAttribute($attributeName);
     }
     return $value;
 }
Example #5
0
 /**
  * テストデータをダウンロードする
  *
  * @param  DOMElement $item
  * @return string
  **/
 private function _downloadTestData($item)
 {
     $url = $item->getElementsByTagName('link')->item(0)->nodeValue;
     if ($url === '') {
         $url = $item->getElementsByTagName('link')->item(0)->getAttribute('href');
     }
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
     $result = curl_exec($curl);
     curl_close($curl);
     return $result;
 }
Example #6
0
 public function applyXMLElement(\DOMElement $element)
 {
     $this->_alpha2 = $element->getAttribute('code');
     $listXMLNode = $element->getElementsByTagName('iso_3166_subset');
     // check if country has sub divisions
     if (!$listXMLNode->length) {
         return;
     }
     // get sub division type
     $this->_subDivisionName = $listXMLNode->item(0)->getAttribute('type');
     foreach ($element->getElementsByTagName('iso_3166_2_entry') as $element) {
         $this->_list[$element->getAttribute('code')] = $element->getAttribute('name');
     }
 }
 /**
  * Converts a DOMElement item to a Zotero_Relation object
  *
  * @param	DOMElement			$xml		Relation data as DOM element
  * @param	Integer				$libraryID
  * @return	Zotero_Relation					Zotero relation object
  */
 public static function convertXMLToRelation(DOMElement $xml, $userLibraryID)
 {
     $relation = new Zotero_Relation();
     $libraryID = $xml->getAttribute('libraryID');
     if ($libraryID) {
         $relation->libraryID = $libraryID;
     } else {
         $relation->libraryID = $userLibraryID;
     }
     $relation->subject = $xml->getElementsByTagName('subject')->item(0)->nodeValue;
     $relation->predicate = $xml->getElementsByTagName('predicate')->item(0)->nodeValue;
     $relation->object = $xml->getElementsByTagName('object')->item(0)->nodeValue;
     return $relation;
 }
 public function appendComment(DOMElement $changeset, array $row)
 {
     $dom_node_list = $changeset->getElementsByTagName('comments');
     $comments_node = $dom_node_list->item(0);
     $this->all_comments[$row['id']] = $comments_node;
     $comments_node->appendChild($this->createCommentNode($row));
 }
Example #9
0
 /**
  *
  * @param DOMElement $dom
  * @return array
  */
 private function handleImages($dom, $url)
 {
     $images = array();
     $parts = parse_url($url);
     $savedImages = array();
     $imgElements = $dom->getElementsByTagName('img');
     foreach ($imgElements as $img) {
         $src = $img->getAttribute("src");
         $is_root = false;
         if (substr($src, 0, 1) == "/") {
             $is_root = true;
         }
         $parsed = parse_url($src);
         if (!isset($parsed["host"])) {
             if ($is_root) {
                 $src = http_build_url($url, $parsed, HTTP_URL_REPLACE);
             } else {
                 $src = http_build_url($url, $parsed, HTTP_URL_JOIN_PATH);
             }
         }
         $img->setAttribute("src", "");
         if (isset($savedImages[$src])) {
             $img->setAttribute("recindex", $savedImages[$src]);
         } else {
             $image = ImageHandler::DownloadImage($src);
             if ($image !== false) {
                 $images[$this->imgCounter] = new FileRecord(new Record($image));
                 $img->setAttribute("recindex", $this->imgCounter);
                 $savedImages[$src] = $this->imgCounter;
                 $this->imgCounter++;
             }
         }
     }
     return $images;
 }
 /**
  * Unserialize contentclass attribute
  *
  * @param eZContentClassAttribute $classAttribute
  * @param DOMElement $attributeNode
  * @param DOMElement $attributeParametersNode
  */
 function unserializeContentClassAttribute($classAttribute, $attributeNode, $attributeParametersNode)
 {
     $defaultZoneLayoutItem = $attributeParametersNode->getElementsByTagName('default-layout')->item(0);
     if ($defaultZoneLayoutItem !== null && $defaultZoneLayoutItem->textContent !== false) {
         $classAttribute->setAttribute(self::DEFAULT_ZONE_LAYOUT_FIELD, $defaultZoneLayoutItem->textContent);
     }
 }
Example #11
0
 /**
  * Extract <img> elements
  *
  * @param \DOMElement $html
  * @param Bag         $bag
  * @param null|string $domain
  */
 protected static function extractImages(\DOMElement $html, Bag $bag, $domain = null)
 {
     foreach ($html->getElementsByTagName('img') as $img) {
         self::addByAttribute($img, 'src', $html, $bag, $domain);
         self::addByAttribute($img, 'data-src', $html, $bag, $domain);
     }
 }
Example #12
0
 function update(DOMElement $item)
 {
     $title = $item->getElementsByTagName('title');
     $description = $item->getElementsByTagName('description');
     $pubDate = $item->getElementsByTagName('pubDate');
     $link = $item->getElementsByTagName('link');
     $nodeEnclosure = $item->getElementsByTagName('enclosure');
     $this->titre = $title->item(0)->textContent;
     $this->description = $description->item(0)->textContent;
     $this->date = $pubDate->item(0)->textContent;
     $this->url = $link->item(0)->textContent;
     if ($nodeEnclosure != NULL) {
         $this->image = $nodeEnclosure->item(0)->attributes->getNamedItem('url')->nodeValue;
     } else {
         $this->image = "default";
     }
 }
Example #13
0
 /**
  * Generate node configuration from XML representation.
  *
  * @param DOMElement $element
  * @return array
  * @ignore
  */
 public static function configurationFromXML(DOMElement $element)
 {
     $configuration = array();
     foreach ($element->getElementsByTagName('variable') as $variable) {
         $configuration[] = $variable->getAttribute('name');
     }
     return $configuration;
 }
Example #14
0
File: set.php Project: bmdevel/ezc
 /**
  * Generate node configuration from XML representation.
  *
  * @param DOMElement $element
  * @return array
  * @ignore
  */
 public static function configurationFromXML(DOMElement $element)
 {
     $configuration = array();
     foreach ($element->getElementsByTagName('variable') as $variable) {
         $configuration[$variable->getAttribute('name')] = ezcWorkflowDefinitionStorageXml::xmlToVariable(ezcWorkflowUtil::getChildNode($variable));
     }
     return $configuration;
 }
Example #15
0
 /**
  * Returns list of vocations that are allowed to learn this spell.
  * 
  * @return array List of vocation names.
  * @throws DOMException On DOM operation error.
  */
 public function getVocations()
 {
     $vocations = array();
     foreach ($this->element->getElementsByTagName('vocation') as $vocation) {
         $vocations[] = $vocation->getAttribute('name');
     }
     return $vocations;
 }
Example #16
0
 function isSearchWord(DOMElement $element)
 {
     $subElements = $element->getElementsByTagName("b");
     if ($subElements->length > 0) {
         return true;
     }
     return false;
 }
Example #17
0
/**
 * @param DOMElement $element
 * @param string     $name
 *
 * @return string|null
 */
function getDomElementString(DOMElement $element, $name)
{
    foreach ($element->getElementsByTagName($name) as $child) {
        /** @var $child DOMElement */
        return $child->textContent;
    }
    return null;
}
Example #18
0
 /**
  * Devuelve el código XML de un nodo
  *
  * @param $node string El nodo a devolver
  * @return string
  * @throws SPException
  */
 private function getNodeXML($node)
 {
     try {
         $nodeXML = $this->_xml->saveXML($this->_root->getElementsByTagName($node)->item(0));
         return $nodeXML;
     } catch (\DOMException $e) {
         throw new SPException(SPException::SP_WARNING, $e->getMessage(), __FUNCTION__);
     }
 }
Example #19
0
 public function initFromXmlNode(DOMElement $node)
 {
     $this->reset();
     if ($this->isGraded()) {
         $this->awardedPoints = $node->getAttribute('awardedPoints');
     }
     $directionSource = trim($node->getElementsByTagName('direction')->item(0)->textContent);
     $this->direction = str_replace("\n", PHP_EOL, $directionSource);
 }
 public function initFromXmlNode(DOMElement $node)
 {
     $childNodes = $node->getElementsByTagName($this->getWordTagName());
     foreach ($childNodes as $childNode) {
         $word = $this->createWord();
         $word->initFromXmlNode($childNode);
         $this->items[] = $word;
     }
 }
 public function initFromXmlNode(DOMElement $node)
 {
     $childNodes = $node->getElementsByTagName('blank');
     foreach ($childNodes as $childNode) {
         $blank = $this->createBlank();
         $blank->initFromXmlNode($childNode);
         $this->items[] = $blank;
     }
 }
Example #22
0
 protected function getUrlByModuleController($module, $controller)
 {
     $list = $this->ep->getElementsByTagName('url');
     foreach ($list as $item) {
         if ($item->getAttribute('module') == $module && $item->getAttribute('controller') == $controller) {
             return $item;
         }
     }
     return null;
 }
 private function parse()
 {
     switch ($this->messageElement->getAttribute('type')) {
         case 'error':
             $this->message = new Error();
             break;
         case 'warning':
             $this->message = new Warning();
             $this->message->setLevel($this->messageElement->getAttribute('level'));
             break;
         default:
             return false;
     }
     $this->message->setRef($this->messageElement->getAttribute('ref'));
     $contextNode = $this->messageElement->getElementsByTagName('context')->item(0);
     $this->message->setContext($contextNode->nodeValue);
     $this->message->setLineNumber($contextNode->getAttribute('line'));
     $this->message->setMessage(trim($this->messageElement->getElementsByTagName('title')->item(0)->nodeValue));
 }
Example #24
0
 /**
  * Retorna um elemento filho.
  *
  * @param $key
  * @return XMLGetResponse
  */
 public function get($key)
 {
     if (is_null($this->elem)) {
         return new self(null);
     }
     $child = $this->elem->getElementsByTagName($key);
     if ($child->length == 0) {
         return new self(null);
     }
     return new self($child->item(0));
 }
Example #25
0
 /**
  * Creates the ODT cell defintions.
  * 
  * @param DOMElement $docBookTable 
  * @param DOMElement $odtTable 
  * @return void
  */
 protected function createCellDefinition($docBookTable, $odtTable)
 {
     $rows = $docBookTable->getElementsByTagName('tr');
     // No XHTML style rows found, look for old style rows
     if ($rows->length === 0) {
         $rows = $docBookTable->getElementsByTagName('row');
     }
     if ($rows->length !== 0) {
         $firstRow = $rows->item(0);
         foreach ($firstRow->childNodes as $cell) {
             if ($cell->nodeType !== XML_ELEMENT_NODE || $cell->localName !== 'td' && $cell->localName !== 'th' && $cell->localName !== 'entry') {
                 continue;
             }
             $count = $cell->hasAttribute('colspan') ? (int) $cell->getAttribute('colspan') : 1;
             for ($i = 0; $i < $count; ++$i) {
                 $odtCell = $odtTable->appendChild($odtTable->ownerDocument->createElementNS(ezcDocumentOdt::NS_ODT_TABLE, 'table:table-column'));
             }
         }
     }
 }
 /**
  * export matches collection from xml node
  * @param $node DOMElement xml node
  * @return array of Match
  */
 protected function exportMatchesCollection(DOMElement $node)
 {
     $out = array();
     $matchesList = $node->getElementsByTagName('match');
     for ($i = 0; $i < $matchesList->length; ++$i) {
         $matchNode = $matchesList->item($i);
         $match = new Match();
         $match->initFromXmlNode($matchNode);
         $out[] = $match;
     }
     return $out;
 }
Example #27
0
 protected function getNodeValueByTagName(\DOMElement $node, $tagName)
 {
     $results = $node->getElementsByTagName($tagName);
     for ($i = 0; $i < $results->length; $i++) {
         $result = $results->item($i);
         if (!$result->nodeValue) {
             continue;
         }
         return $result->nodeValue;
     }
     return false;
 }
Example #28
0
 /**
  * Parse font family.
  * @param DOMElement $node
  */
 public function parse(DOMElement $node)
 {
     $this->UID = $node->hasAttribute(IdmlAttributes::Self) ? $node->getAttribute(IdmlAttributes::Self) : '';
     $this->name = $node->hasAttribute(IdmlAttributes::Name) ? $node->getAttribute(IdmlAttributes::Name) : '';
     $fontNodes = $node->getElementsByTagName('Font');
     foreach ($fontNodes as $fontNode) {
         $font = new IdmlFont();
         $font->parse($fontNode);
         $font->fontFamily = $this;
         $this->fonts[] = $font;
     }
 }
 private function exportUserAnswer(DOMElement $node)
 {
     $out = array();
     $matchesList = $node->getElementsByTagName('match');
     for ($i = 0; $i < $matchesList->length; ++$i) {
         $matchNode = $matchesList->item($i);
         $match = new LikertScaleMatch();
         $match->initFromXmlNode($matchNode);
         $out[] = $match;
     }
     return $out;
 }
Example #30
0
 /**
  * @param $elem
  * @return array
  */
 public function toArray($elem)
 {
     if (is_null($this->elem)) {
         return [];
     }
     $ret = [];
     $lista = $this->elem->getElementsByTagName($elem);
     for ($i = 0; $i < $lista->length; $i++) {
         $ret[] = XML::createByXml($lista->item($i)->C14N());
     }
     return $ret;
 }