/** * Answer a element that represents the content for this Block * * @return object DOMElement * @access protected * @since 2/12/08 */ protected function getContentElement(DOMElement $mediaElement) { // Content/Description $descElement = $this->sourceXPath->query('./description', $this->sourceElement)->item(0); $descHtml = $this->getStringValue($descElement); $descHtml = $this->rewriteLocalLinks($descHtml); // Content $filename = $this->getStringValue($this->getSingleSourceElement('./filename', $this->sourceElement)); $currentContent = $this->doc->createElement('currentContent'); try { $fileUrlString = $this->attachFile($filename, $mediaElement); $fileUrlString = str_replace('asset_id', 'assetId', $fileUrlString); $fileUrlString = str_replace('record_id', 'recordId', $fileUrlString); // $fileUrlString = str_replace('&', '&', $fileUrlString); $doc = new Harmoni_DOMDocument(); $root = $doc->appendChild($doc->createElement('AudioPlayerPlugin')); $fileNode = $root->appendChild($doc->createElement('File')); $fileNode->setAttribute('show_download_link', 'true'); $idNode = $fileNode->appendChild($doc->createElement('Id', $fileUrlString)); $content = $currentContent->appendChild($this->createCDATAElement('content', $doc->saveXMLWithWhitespace())); } catch (MissingNodeException $e) { $content = $currentContent->appendChild($this->createCDATAElement('content', '')); } catch (Segue1To2_MissingFileException $e) { $content = $currentContent->appendChild($this->createCDATAElement('content', '')); } $rawDesc = $currentContent->appendChild($this->createCDATAElement('rawDescription', $this->cleanHtml($descHtml))); return $currentContent; }
/** * Answer a element that represents the content for this Block * * @return object DOMElement * @access protected * @since 2/12/08 */ protected function getContentElement(DOMElement $mediaElement) { // Content/Description $descElement = $this->sourceXPath->query('./description', $this->sourceElement)->item(0); if ($descElement) { $descHtml = $this->cleanHtml($this->getStringValue($descElement)); } else { $descHtml = ''; } $descHtml = $this->rewriteLocalLinks($descHtml); $title = $this->getDisplayName(); $url = $this->rewriteLocalLinks($this->getStringValue($this->getSingleSourceElement('./url', $this->sourceElement))); // Content $dataDoc = new Harmoni_DOMDocument(); $root = $dataDoc->appendChild($dataDoc->createElement('RssFeedPlugin')); $feed = $root->appendChild($dataDoc->createElement('RssFeed')); $urlElement = $feed->appendChild($dataDoc->createElement('Url', str_replace('&', '&', $url))); $sourceUrlElement = $this->getSingleSourceElement('./url', $this->sourceElement); $this->setAttributes($sourceUrlElement, $feed); $currentContent = $this->doc->createElement('currentContent'); $currentContent->appendChild($this->createCDATAElement('content', $dataDoc->saveXMLWithWhitespace())); $currentContent->appendChild($this->doc->createElement('rawDescription', '')); return $currentContent; }
/** * Dumps the internal XML tree back into a string with added whitespace * (new-lines and tabbing). * * @param optional object DOMNode $node * @param optional int $options * @return string * @access public * @since 1/23/08 */ public function saveXMLWithWhitespace(DOMNode $node = null, $options = null) { $doc = new Harmoni_DOMDocument(); if (is_null($node)) { if ($this->documentElement) { $doc->appendChild($doc->importNode($this->documentElement, true)); } } else { $doc->appendChild($doc->importNode($node, true)); } $doc->addWhitespaceToDocument(); return $doc->saveXML($doc->documentElement, $options); }
/** * Apply a single history entry to the plugin's history. * * @param SeguePluginsAPI $plugin * @param object DOMElement $element * @return void * @access protected * @since 1/23/08 */ protected function addPluginHistoryEntry(SeguePluginsAPI $plugin, DOMElement $element) { foreach ($element->childNodes as $child) { if ($child->nodeType == XML_ELEMENT_NODE && $child->nodeName != 'comment') { $doc = new Harmoni_DOMDocument(); $doc->appendChild($doc->importNode($child, true)); break; } } if (!isset($doc)) { throw new Exception("No version found."); } $comment = $this->getPluginHistoryComment($element); $timestamp = $this->getPluginHistoryTimestamp($element); $agentId = $this->getPluginHistoryAgentId($element); $plugin->importVersion($doc, $agentId, $timestamp, $comment); }
/** * Write an option * * @param string $groupId * @return void * @access protected * @since 2/4/09 */ protected function getOptions() { $doc = new Harmoni_DOMDocument(); $doc->preserveWhiteSpace = false; try { $doc->loadXML($this->getContent()); } catch (DOMException $e) { $doc->appendChild($doc->createElement('options')); } if (!$doc->documentElement->nodeName == 'options') { throw new OperationFailedException('Expection root-node "options", found "' . $doc->documentElement->nodeName . '".'); } return $doc; }
/** * Write an option * * @param string $key * @param string $val * @return void * @access protected * @since 2/4/09 */ protected function writeOption($key, $val) { // The options will look like: /* <options> <targetNodeId>12345</targetNodeId> <defaultSortMethod>alpha</defaultSortMethod> <defaultDisplayType>cloud</defaultDisplayType> </options> */ if (!in_array($key, $this->_allowedOptions)) { throw new InvalidArgumentException("Unknown option, {$key}"); } $doc = new Harmoni_DOMDocument(); $doc->preserveWhiteSpace = false; try { $doc->loadXML($this->getContent()); } catch (DOMException $e) { $doc->appendChild($doc->createElement('options')); } if (!$doc->documentElement->nodeName == 'options') { throw new OperationFailedException('Expection root-node "options", found "' . $doc->documentElement->nodeName . '".'); } // Fetch the existing element or create a new one for this key $xpath = new DOMXPath($doc); $elements = $xpath->query('/options/' . $key); if ($elements->length) { $element = $elements->item(0); } else { $element = $doc->documentElement->appendChild($doc->createElement($key)); } // Set the value and save $element->nodeValue = $val; $this->setContent($doc->saveXMLWithWhitespace()); }